crex.h
#ifndef WREPORT_BUFFERS_CREX_H
#define WREPORT_BUFFERS_CREX_H
#include <wreport/error.h>
#include <wreport/varinfo.h>
#include <string>
namespace wreport {
struct Var;
namespace buffers {
struct CrexInput
{
const char* data;
size_t data_len;
const char* fname;
size_t offset;
unsigned sec[5];
const char* cur;
int has_check_digit;
int expected_check_digit;
CrexInput(const std::string& in, const char* fname, size_t offset);
bool eof() const;
unsigned remaining() const;
void parse_error(const char* fmt, ...) const WREPORT_THROWF_ATTRS(2, 3);
void check_eof(const char* expected) const;
void check_available_data(unsigned datalen, const char* expected) const;
void skip_spaces();
void skip_data_and_spaces(unsigned datalen);
void mark_section_start(unsigned num);
void read_word(char* buf, size_t len);
void parse_value(int len, int is_signed, const char** d_start, const char** d_end);
void debug_dump_next(const char* desc) const;
};
struct CrexOutput
{
std::string& buf;
int has_check_digit;
int expected_check_digit;
CrexOutput(std::string& buf);
void raw_append(const char* str, int len);
void raw_appendf(const char* fmt, ...) __attribute__ ((format(printf, 2, 3)));
void encode_check_digit();
void append_missing(Varinfo info);
void append_var(Varinfo info, const Var& var);
};
}
}
#endif
wreport::Var
A physical variable.
Definition var.h:25
error.h
wreport exceptions.
WREPORT_THROWF_ATTRS
#define WREPORT_THROWF_ATTRS(a, b)
Tell the compiler that a function always throws and expects printf-style arguments.
Definition error.h:56
wreport
String functions.
Definition benchmark.h:13
wreport::Varinfo
const _Varinfo * Varinfo
Varinfo reference.
Definition fwd.h:11
wreport::buffers::CrexInput::mark_section_start
void mark_section_start(unsigned num)
Mark the start of the given section.
wreport::buffers::CrexInput::debug_dump_next
void debug_dump_next(const char *desc) const
Dump to stderr the contents of the next bit of buffer.
wreport::buffers::CrexInput::offset
size_t offset
File offset of the start of the message.
Definition crex.h:40
wreport::buffers::CrexInput::expected_check_digit
int expected_check_digit
Value of the next expected check digit.
Definition crex.h:54
wreport::buffers::CrexInput::check_eof
void void check_eof(const char *expected) const
Check if the decoding cursor has reached the end of buffer, throw error_parse otherwise.
wreport::buffers::CrexInput::parse_error
void parse_error(const char *fmt,...) const WREPORT_THROWF_ATTRS(2
Throw an error_parse at the current decoding location.
wreport::buffers::CrexInput::sec
unsigned sec[5]
Character offsets of the starts of CREX sections.
Definition crex.h:45
wreport::buffers::CrexInput::has_check_digit
int has_check_digit
True if the CREX message uses the check digit feature.
Definition crex.h:51
wreport::buffers::CrexInput::fname
const char * fname
Input file name (optional).
Definition crex.h:31
wreport::buffers::CrexInput::cur
const char * cur
Cursor inside in.data() used for decoding.
Definition crex.h:48
wreport::buffers::CrexInput::parse_value
void parse_value(int len, int is_signed, const char **d_start, const char **d_end)
Parse a data value from the input buffer.
wreport::buffers::CrexInput::read_word
void read_word(char *buf, size_t len)
Read a word into buf.
wreport::buffers::CrexInput::skip_spaces
void skip_spaces()
Move the cursor to the next non-space character.
wreport::buffers::CrexInput::remaining
unsigned remaining() const
Return the number of remaining characters until the end of the buffer.
wreport::buffers::CrexInput::CrexInput
CrexInput(const std::string &in, const char *fname, size_t offset)
Wrap a string into a CrexInput.
wreport::buffers::CrexInput::data_len
size_t data_len
Input buffer size.
Definition crex.h:22
wreport::buffers::CrexInput::skip_data_and_spaces
void skip_data_and_spaces(unsigned datalen)
Skip datalen characters and all spaces after them.
wreport::buffers::CrexInput::check_available_data
void check_available_data(unsigned datalen, const char *expected) const
Check that the input buffer contains at least datalen characters after the cursor,...
wreport::buffers::CrexInput::data
const char * data
Input buffer.
Definition crex.h:19
wreport::buffers::CrexInput::eof
bool eof() const
Return true if the cursor is at the end of the buffer.
wreport::buffers::CrexOutput::encode_check_digit
void void encode_check_digit()
Generate and append a check digit.
wreport::buffers::CrexOutput::raw_appendf
void raw_appendf(const char *fmt,...) __attribute__((format(printf
Append a printf-formatted string.
wreport::buffers::CrexOutput::raw_append
void raw_append(const char *str, int len)
Append a string.
wreport::buffers::CrexOutput::append_missing
void append_missing(Varinfo info)
Append a missing variable encoded according to info.
wreport::buffers::CrexOutput::CrexOutput
CrexOutput(std::string &buf)
Wrap a string with a CrexOutput.
wreport::buffers::CrexOutput::append_var
void append_var(Varinfo info, const Var &var)
Append a variable encoded according to info.
wreport::buffers::CrexOutput::has_check_digit
int has_check_digit
True if the CREX message uses the check digit feature.
Definition crex.h:155
wreport::buffers::CrexOutput::expected_check_digit
int expected_check_digit
Value of the next expected check digit.
Definition crex.h:158
wreport::buffers::CrexOutput::buf
std::string & buf
String we append to.
Definition crex.h:152
varinfo.h
Implement fast access to information about WMO variables.