libwreport 3.38
crex.h
1#ifndef WREPORT_BUFFERS_CREX_H
2#define WREPORT_BUFFERS_CREX_H
3
4#include <wreport/error.h>
5#include <wreport/varinfo.h>
6#include <string>
7
8namespace wreport {
9struct Var;
10
11namespace buffers {
12
17{
19 const char* data;
20
22 size_t data_len;
23
31 const char* fname;
32
40 size_t offset;
41
45 unsigned sec[5];
46
48 const char* cur;
49
52
55
56
63 CrexInput(const std::string& in, const char* fname, size_t offset);
64
66 bool eof() const;
67
69 unsigned remaining() const;
70
72 void parse_error(const char* fmt, ...) const WREPORT_THROWF_ATTRS(2, 3);
73
82 void check_eof(const char* expected) const;
83
94 void check_available_data(unsigned datalen, const char* expected) const;
95
98
100 void skip_data_and_spaces(unsigned datalen);
101
111 void mark_section_start(unsigned num);
112
126 void read_word(char* buf, size_t len);
127
140 void parse_value(int len, int is_signed, const char** d_start, const char** d_end);
141
143 void debug_dump_next(const char* desc) const;
144};
145
150{
152 std::string& buf;
153
156
159
160
167 CrexOutput(std::string& buf);
168
170 void raw_append(const char* str, int len);
171
173 void raw_appendf(const char* fmt, ...) __attribute__ ((format(printf, 2, 3)));
174
176 void encode_check_digit();
177
179 void append_missing(Varinfo info);
180
182 void append_var(Varinfo info, const Var& var);
183};
184
185}
186}
187#endif
A physical variable.
Definition: var.h:25
wreport exceptions.
#define WREPORT_THROWF_ATTRS(a, b)
Tell the compiler that a function always throws and expects printf-style arguments.
Definition: error.h:56
String functions.
Definition: benchmark.h:13
Information about a variable.
Definition: varinfo.h:139
Text input buffer.
Definition: crex.h:17
void mark_section_start(unsigned num)
Mark the start of the given section.
void debug_dump_next(const char *desc) const
Dump to stderr the contents of the next bit of buffer.
size_t offset
File offset of the start of the message.
Definition: crex.h:40
int expected_check_digit
Value of the next expected check digit.
Definition: crex.h:54
void void check_eof(const char *expected) const
Check if the decoding cursor has reached the end of buffer, throw error_parse otherwise.
void parse_error(const char *fmt,...) const WREPORT_THROWF_ATTRS(2
Throw an error_parse at the current decoding location.
unsigned sec[5]
Character offsets of the starts of CREX sections.
Definition: crex.h:45
int has_check_digit
True if the CREX message uses the check digit feature.
Definition: crex.h:51
const char * fname
Input file name (optional).
Definition: crex.h:31
const char * cur
Cursor inside in.data() used for decoding.
Definition: crex.h:48
void parse_value(int len, int is_signed, const char **d_start, const char **d_end)
Parse a data value from the input buffer.
void read_word(char *buf, size_t len)
Read a word into buf.
void skip_spaces()
Move the cursor to the next non-space character.
unsigned remaining() const
Return the number of remaining characters until the end of the buffer.
CrexInput(const std::string &in, const char *fname, size_t offset)
Wrap a string into a CrexInput.
size_t data_len
Input buffer size.
Definition: crex.h:22
void skip_data_and_spaces(unsigned datalen)
Skip datalen characters and all spaces after them.
void check_available_data(unsigned datalen, const char *expected) const
Check that the input buffer contains at least datalen characters after the cursor,...
const char * data
Input buffer.
Definition: crex.h:19
bool eof() const
Return true if the cursor is at the end of the buffer.
Text output buffer.
Definition: crex.h:150
void raw_appendf(const char *fmt,...) __attribute__((format(printf
Append a printf-formatted string.
void raw_append(const char *str, int len)
Append a string.
CrexOutput(std::string &buf)
Wrap a string with a CrexOutput.
int has_check_digit
True if the CREX message uses the check digit feature.
Definition: crex.h:155
int expected_check_digit
Value of the next expected check digit.
Definition: crex.h:158
std::string & buf
String we append to.
Definition: crex.h:152
Implement fast access to information about WMO variables.