libwreport  3.29
bufr.h
1 #ifndef WREPORT_BUFFERS_BUFR_H
2 #define WREPORT_BUFFERS_BUFR_H
3 
4 #include <wreport/error.h>
5 #include <wreport/var.h>
6 #include <string>
7 #include <functional>
8 #include <cstdint>
9 
10 namespace wreport {
11 struct Var;
12 
13 namespace buffers {
14 
18 struct BufrOutput
19 {
21  std::string& out;
22 
24  uint8_t pbyte;
25 
27  int pbyte_len;
28 
35  BufrOutput(std::string& out);
36 
40  void add_bits(uint32_t val, int n);
41 
46  void raw_append(const char* str, int len)
47  {
48  out.append(str, len);
49  }
50 
52  void append_short(unsigned short val)
53  {
54  add_bits(val, 16);
55  }
56 
58  void append_byte(unsigned char val)
59  {
60  add_bits(val, 8);
61  }
62 
64  void append_missing(unsigned len_bits)
65  {
66  add_bits(0xffffffff, len_bits);
67  }
68 
70  void append_string(const Var& var, unsigned len_bits);
71 
73  void append_string(const char* val, unsigned len_bits);
74 
76  void append_binary(const unsigned char* val, unsigned len_bits);
77 
79  void append_var(Varinfo info, const Var& var);
80 
82  void append_missing(Varinfo info);
83 
88  void flush();
89 };
90 
91 
92 }
93 }
94 
95 #endif
wreport::buffers::BufrOutput::BufrOutput
BufrOutput(std::string &out)
Wrap a string into a BufrOutput.
wreport::buffers::BufrOutput::append_var
void append_var(Varinfo info, const Var &var)
Append var encoded according to info.
wreport::buffers::BufrOutput::pbyte
uint8_t pbyte
Byte to which we are appending bits to encode.
Definition: bufr.h:24
wreport::buffers::BufrOutput::pbyte_len
int pbyte_len
Number of bits already encoded in pbyte.
Definition: bufr.h:27
wreport::buffers::BufrOutput::flush
void flush()
Write all bits left to the buffer, padding the last partial byte with zeros if needed to make it even...
wreport::buffers::BufrOutput::add_bits
void add_bits(uint32_t val, int n)
Append n bits from 'val'.
wreport::buffers::BufrOutput
Binary buffer with bit-level append operations.
Definition: bufr.h:19
wreport::buffers::BufrOutput::out
std::string & out
Output buffer to which we append encoded data.
Definition: bufr.h:21
wreport::_Varinfo
Information about a variable.
Definition: varinfo.h:137
error.h
wreport exceptions.
wreport::buffers::BufrOutput::append_string
void append_string(const char *val, unsigned len_bits)
Append a string len_bits bits long.
wreport::Var
A physical variable.
Definition: var.h:25
wreport::buffers::BufrOutput::raw_append
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:46
wreport::buffers::BufrOutput::append_string
void append_string(const Var &var, unsigned len_bits)
Append a string variable.
wreport::buffers::BufrOutput::append_short
void append_short(unsigned short val)
Append a 16 bits integer.
Definition: bufr.h:52
wreport::buffers::BufrOutput::append_binary
void append_binary(const unsigned char *val, unsigned len_bits)
Append a binary value len_bits bits long.
wreport::buffers::BufrOutput::append_missing
void append_missing(Varinfo info)
Append a missing value according to info.
wreport::buffers::BufrOutput::append_missing
void append_missing(unsigned len_bits)
Append a missing value len_bits long.
Definition: bufr.h:64
wreport
String functions.
Definition: benchmark.h:13
wreport::buffers::BufrOutput::append_byte
void append_byte(unsigned char val)
Append an 8 bits integer.
Definition: bufr.h:58