libwreport 3.38
bulletin.h
1#ifndef WREPORT_BULLETIN_H
2#define WREPORT_BULLETIN_H
3
4#include <wreport/var.h>
5#include <wreport/subset.h>
6#include <wreport/opcodes.h>
7#include <wreport/tables.h>
8#include <wreport/fwd.h>
9#include <vector>
10#include <memory>
11
12namespace wreport {
13
30{
31public:
39 std::string fname;
40
48 off_t offset = 0;
49
61
63 uint8_t data_category = 0xff;
64
66 uint8_t data_subcategory = 0xff;
67
82 uint8_t data_subcategory_local = 0xff;
83
88 uint16_t originating_centre = 0xffff;
89
94 uint16_t originating_subcentre = 0xffff;
95
101
103 uint16_t rep_year = 0;
105 uint8_t rep_month = 0;
107 uint8_t rep_day = 0;
109 uint8_t rep_hour = 0;
111 uint8_t rep_minute = 0;
113 uint8_t rep_second = 0;
114
117
119 std::vector<Varcode> datadesc;
120
122 std::vector<Subset> subsets;
123
124
125 Bulletin();
126 virtual ~Bulletin();
127
129 virtual void clear();
130
132 virtual const char* encoding_name() const throw () = 0;
133
143 Subset& obtain_subset(unsigned subsection);
144
153 const Subset& subset(unsigned subsection) const;
154
156 virtual void load_tables() = 0;
157
159 virtual std::string encode() const = 0;
160
162 void print(FILE* out) const;
163
165 void print_structured(FILE* out) const;
166
168 virtual void print_details(FILE* out) const;
169
178 void print_datadesc(FILE* out, unsigned indent=0) const;
179
191 virtual unsigned diff(const Bulletin& msg) const;
192
194 virtual unsigned diff_details(const Bulletin& msg) const;
195};
196
197
200{
201public:
211 bool decode_adds_undef_attrs = false;
212
220 static std::unique_ptr<BufrCodecOptions> create();
221
222protected:
224};
225
226
228class BufrBulletin : public Bulletin
229{
230public:
232 uint8_t edition_number = 4;
233
241 uint8_t master_table_version_number = 19;
242
251 uint8_t master_table_version_number_local = 0;
252
255
261 std::string optional_section;
262
268 unsigned section_end[6] = { 0, 0, 0, 0, 0, 0 };
269
270
271 virtual ~BufrBulletin();
272
273 void clear() override;
274 const char* encoding_name() const throw () override { return "BUFR"; }
275 void load_tables() override;
276 std::string encode() const override;
277 void print_details(FILE* out) const override;
278 unsigned diff_details(const Bulletin& msg) const override;
279
294 static bool read(FILE* in, std::string& buf, const char* fname=0, off_t* offset=0);
295
306 static void write(const std::string& buf, FILE* out, const char* fname=0);
307
312 static std::unique_ptr<BufrBulletin> create();
313
326 static std::unique_ptr<BufrBulletin> decode_header(const std::string& raw, const char* fname="(memory)", size_t offset=0);
327
342 static std::unique_ptr<BufrBulletin> decode_header(const std::string& raw, const BufrCodecOptions& opts, const char* fname="(memory)", size_t offset=0);
343
356 static std::unique_ptr<BufrBulletin> decode(const std::string& raw, const char* fname="(memory)", size_t offset=0);
357
372 static std::unique_ptr<BufrBulletin> decode_verbose(const std::string& raw, FILE* out, const char* fname="(memory)", size_t offset=0);
373
388 static std::unique_ptr<BufrBulletin> decode(const std::string& raw, const BufrCodecOptions& opts, const char* fname="(memory)", size_t offset=0);
389
390protected:
391 BufrBulletin();
392};
393
394
396class CrexBulletin : public Bulletin
397{
398public:
400 uint8_t edition_number = 2;
401
408 uint8_t master_table_version_number = 19;
409
421 uint8_t master_table_version_number_bufr = 19;
422
431 uint8_t master_table_version_number_local = 0;
432
434 bool has_check_digit = false;
435
436
437 void clear() override;
438 const char* encoding_name() const throw () override { return "CREX"; }
439 void load_tables() override;
440 std::string encode() const override;
441 void print_details(FILE* out) const override;
442 unsigned diff_details(const Bulletin& msg) const override;
443
458 static bool read(FILE* in, std::string& buf, const char* fname=0, off_t* offset=0);
459
470 static void write(const std::string& buf, FILE* out, const char* fname=0);
471
476 static std::unique_ptr<CrexBulletin> create();
477
490 static std::unique_ptr<CrexBulletin> decode_header(const std::string& raw, const char* fname="(memory)", size_t offset=0);
491
504 static std::unique_ptr<CrexBulletin> decode(const std::string& raw, const char* fname="(memory)", size_t offset=0);
505
520 static std::unique_ptr<CrexBulletin> decode_verbose(const std::string& raw, FILE* out, const char* fname="(memory)", size_t offset=0);
521
522protected:
523 CrexBulletin();
524};
525
526
536namespace bulletin {
537}
538
539}
540#endif
BUFR bulletin implementation.
Definition bulletin.h:229
static void write(const std::string &buf, FILE *out, const char *fname=0)
Write an encoded BUFR message to a stream.
unsigned diff_details(const Bulletin &msg) const override
Diff format-specific details.
static bool read(FILE *in, std::string &buf, const char *fname=0, off_t *offset=0)
Read an encoded BUFR message from a stream.
static std::unique_ptr< BufrBulletin > create()
To prevent breaking ABI if new members are added to bulletins, direct construction is discouraged in ...
bool compression
Whether the message is compressed.
Definition bulletin.h:254
std::string encode() const override
Encode the message.
std::string optional_section
Raw optional section of the message.
Definition bulletin.h:261
static std::unique_ptr< BufrBulletin > decode(const std::string &raw, const char *fname="(memory)", size_t offset=0)
Parse an encoded BUFR message.
void clear() override
Reset the bulletin.
void print_details(FILE *out) const override
Print format-specific details.
static std::unique_ptr< BufrBulletin > decode_header(const std::string &raw, const char *fname="(memory)", size_t offset=0)
Parse only the header of an encoded BUFR message.
void load_tables() override
Load a new set of tables to use for encoding this message.
static std::unique_ptr< BufrBulletin > decode_verbose(const std::string &raw, FILE *out, const char *fname="(memory)", size_t offset=0)
Parse an encoded BUFR message, printing decoding information.
const char * encoding_name() const override
Type of source/target encoding.
Definition bulletin.h:274
static std::unique_ptr< BufrBulletin > decode_header(const std::string &raw, const BufrCodecOptions &opts, const char *fname="(memory)", size_t offset=0)
Parse only the header of an encoded BUFR message.
static std::unique_ptr< BufrBulletin > decode(const std::string &raw, const BufrCodecOptions &opts, const char *fname="(memory)", size_t offset=0)
Parse an encoded BUFR message.
Options used to configure BUFR decoding.
Definition bulletin.h:200
static std::unique_ptr< BufrCodecOptions > create()
Create a BufrCodecOptions.
Storage for the decoded data of a BUFR or CREX message.
Definition bulletin.h:30
virtual void print_details(FILE *out) const
Print format-specific details.
uint16_t originating_centre
Identification of originating/generating centre (see Common Code table C-11)
Definition bulletin.h:88
uint8_t update_sequence_number
Update sequence number (zero for original messages and for messages containing only delayed reports; ...
Definition bulletin.h:100
uint8_t rep_hour
Reference hour in bulletin header.
Definition bulletin.h:109
virtual unsigned diff_details(const Bulletin &msg) const
Diff format-specific details.
std::vector< Subset > subsets
Decoded variables.
Definition bulletin.h:122
uint8_t rep_minute
Reference minute in bulletin header.
Definition bulletin.h:111
virtual void load_tables()=0
Load a new set of tables to use for encoding this message.
uint16_t originating_subcentre
Identification of originating/generating sub-centre (allocated by originating/generating centre - see...
Definition bulletin.h:94
virtual const char * encoding_name() const =0
Type of source/target encoding.
uint8_t rep_month
Reference month in bulletin header.
Definition bulletin.h:105
void print_structured(FILE *out) const
Dump the contents of this bulletin, in a more structured way.
std::vector< Varcode > datadesc
Parsed data descriptor section.
Definition bulletin.h:119
off_t offset
File offset of the start of the message.
Definition bulletin.h:48
uint16_t rep_year
Reference year in bulletin header.
Definition bulletin.h:103
Tables tables
Varcode and opcode tables used for encoding or decoding.
Definition bulletin.h:116
std::string fname
Input file name (optional).
Definition bulletin.h:39
uint8_t rep_second
Reference second in bulletin header.
Definition bulletin.h:113
virtual void clear()
Reset the bulletin.
virtual std::string encode() const =0
Encode the message.
void print_datadesc(FILE *out, unsigned indent=0) const
Pretty-print the data descriptor section.
Subset & obtain_subset(unsigned subsection)
Get a Subset from the message.
void print(FILE *out) const
Dump the contents of this bulletin.
uint8_t rep_day
Reference day in bulletin header.
Definition bulletin.h:107
const Subset & subset(unsigned subsection) const
Get a Subset from the message.
virtual unsigned diff(const Bulletin &msg) const
Compute the differences between two bulletins.
uint8_t data_subcategory_local
Local data sub-category, defined locally by automatic data-processing (ADP) centres.
Definition bulletin.h:82
uint8_t master_table_number
BUFR Master table number.
Definition bulletin.h:60
uint8_t data_category
Data category (BUFR or CREX Table A)
Definition bulletin.h:63
uint8_t data_subcategory
International data sub-category (see Common Code table C-13)
Definition bulletin.h:66
CREX bulletin implementation.
Definition bulletin.h:397
static void write(const std::string &buf, FILE *out, const char *fname=0)
Write an encoded BUFR message to a stream.
void print_details(FILE *out) const override
Print format-specific details.
static std::unique_ptr< CrexBulletin > decode_verbose(const std::string &raw, FILE *out, const char *fname="(memory)", size_t offset=0)
Parse an encoded BUFR message, printing decoding information.
std::string encode() const override
Encode the message.
static bool read(FILE *in, std::string &buf, const char *fname=0, off_t *offset=0)
Read an encoded BUFR message from a stream.
void load_tables() override
Load a new set of tables to use for encoding this message.
unsigned diff_details(const Bulletin &msg) const override
Diff format-specific details.
static std::unique_ptr< CrexBulletin > create()
To prevent breaking ABI if new members are added to bulletins, direct construction is discouraged in ...
const char * encoding_name() const override
Type of source/target encoding.
Definition bulletin.h:438
static std::unique_ptr< CrexBulletin > decode_header(const std::string &raw, const char *fname="(memory)", size_t offset=0)
Parse only the header of an encoded BUFR message.
void clear() override
Reset the bulletin.
static std::unique_ptr< CrexBulletin > decode(const std::string &raw, const char *fname="(memory)", size_t offset=0)
Parse an encoded BUFR message.
Represent a BUFR/CREX data subset as a list of decoded variables.
Definition subset.h:13
String functions.
Definition benchmark.h:13
Collection of BUFR/CREX tables used to work on a bulletin.
Definition tables.h:15