1 #ifndef WREPORT_BUFFERS_BUFR_H 2 #define WREPORT_BUFFERS_BUFR_H 5 #include <wreport/var.h> 104 return (
unsigned)data[pos];
108 inline unsigned read_byte(
unsigned section,
unsigned pos)
const 110 return (
unsigned)data[sec[section] + pos];
117 for (
unsigned i = 0; i < byte_len; ++i)
120 res |= data[pos + i];
129 inline unsigned read_number(
unsigned section,
unsigned pos,
unsigned byte_len)
const 142 if (s4_cursor == data_len)
143 parse_error(
"end of buffer while looking for %d bits of bit-packed data", n);
149 for (
unsigned i = 0; i < n; i++)
154 pbyte = data[s4_cursor++];
206 void check_available_data(
unsigned section,
unsigned pos,
size_t datalen,
const char* expected);
232 bool decode_compressed_base(
Varinfo info, uint32_t& base, uint32_t& diffbits);
246 bool missing = decode_compressed_base(info, base, diffbits);
249 for (
unsigned i = 0; i < subsets; ++i)
255 for (
unsigned i = 0; i < subsets; ++i)
261 for (
unsigned i = 0; i < subsets; ++i)
264 dest(i, std::move(var));
269 template<
typename Adder>
270 void decode_string(
Varinfo info,
unsigned subsets, Adder& dest)
273 char str[info->
bit_len / 8 + 2];
275 bool missing = !decode_string(info->
bit_len, str, len);
281 if (missing && diffbits == 0)
282 dest.add_missing(info);
283 else if (diffbits == 0)
286 dest.add_same(
Var(info, str));
289 for (
size_t i = 0; i < len; ++i)
297 error_unimplemented::throwf(
"compressed strings with %zd characters have %d bit deltas (deltas should not be longer than field)", len, diffbits);
299 for (
unsigned i = 0; i < subsets; ++i)
302 if (decode_string(diffbits * 8, str, len))
305 dest.add_var(i,
Var(info, str));
308 dest.add_var(i,
Var(info));
314 template<
typename Adder>
323 bool missing = decode_compressed_base(info, base, diffbits);
325 dest.add_missing(info);
331 for (
unsigned i = 0; i < subsets; ++i)
334 dest.add_var(i, std::move(var));
374 bool decode_string(
unsigned bit_len,
char* str,
size_t& len);
387 void decode_string(
Var& dest);
400 void decode_string(
Var& dest,
unsigned subsets);
406 void decode_string(
Varinfo info,
unsigned subsets, std::function<
void(
unsigned,
Var&&)> dest);
432 for (
unsigned i = 0; i < size; ++i)
435 buf[i] = (val == 0) ?
'+' :
'-';
457 for (
unsigned i = 0; i < size; ++i)
460 buf[i] = (val == 0) ?
'+' :
'-';
469 parse_error(
"bitmap entry %u declares %u difference bits, but we only support 0", i, val);
500 void add_bits(uint32_t val,
int n);
508 out.append(str, len);
526 add_bits(0xffffffff, len_bits);
530 void append_string(
const Var& var,
unsigned len_bits);
533 void append_string(
const char* val,
unsigned len_bits);
536 void append_binary(
const unsigned char* val,
unsigned len_bits);
539 void append_var(
Varinfo info,
const Var& var);
542 void append_missing(
Varinfo info);
void append_byte(unsigned char val)
Append an 8 bits integer.
Definition: bufr.h:518
uint8_t pbyte
Byte to which we are appending bits to encode.
Definition: bufr.h:484
static void throwf(const char *fmt,...) WREPORT_THROWF_ATTRS(1
Throw the exception, building the message printf-style.
A physical variable.
Definition: var.h:23
void append_short(unsigned short val)
Append a 16 bits integer.
Definition: bufr.h:512
Binary buffer with bit-level append operations.
Definition: bufr.h:478
double decode_binary(uint32_t val) const
Decode a double value from a decimal integer value using Varinfo binary encoding informations (bit_re...
void append_missing(unsigned len_bits)
Append a missing value len_bits long.
Definition: bufr.h:524
Information about a variable.
Definition: varinfo.h:135
void raw_append(const char *str, int len)
Append a string len bits long to the output buffer as it is, ignoring partially encoded bits...
Definition: bufr.h:506
unsigned bit_len
Length in bits of the variable when encoded as an unsigned binary value.
Definition: varinfo.h:170
String functions.
Definition: benchmark.h:13
int pbyte_len
Number of bits already encoded in pbyte.
Definition: bufr.h:487
#define WREPORT_THROWF_ATTRS(a, b)
Tell the compiler that a function always throws and expects printf-style arguments.
Definition: error.h:56
std::string & out
Output buffer to which we append encoded data.
Definition: bufr.h:481