libwreport  3.40
bulletin.h
1 #ifndef WREPORT_BULLETIN_H
2 #define WREPORT_BULLETIN_H
3 
4 #include <memory>
5 #include <vector>
6 #include <wreport/fwd.h>
7 #include <wreport/opcodes.h>
8 #include <wreport/subset.h>
9 #include <wreport/tables.h>
10 #include <wreport/var.h>
11 
12 namespace wreport {
13 
29 class Bulletin
30 {
31 public:
39  std::string fname;
40 
48  off_t offset = 0;
49 
62  uint8_t master_table_number = 0;
63 
65  uint8_t data_category = 0xff;
66 
68  uint8_t data_subcategory = 0xff;
69 
84  uint8_t data_subcategory_local = 0xff;
85 
90  uint16_t originating_centre = 0xffff;
91 
96  uint16_t originating_subcentre = 0xffff;
97 
103 
105  uint16_t rep_year = 0;
107  uint8_t rep_month = 0;
109  uint8_t rep_day = 0;
111  uint8_t rep_hour = 0;
113  uint8_t rep_minute = 0;
115  uint8_t rep_second = 0;
116 
119 
121  std::vector<Varcode> datadesc;
122 
124  std::vector<Subset> subsets;
125 
126  Bulletin();
127  virtual ~Bulletin();
128 
130  virtual void clear();
131 
133  virtual const char* encoding_name() const throw() = 0;
134 
144  Subset& obtain_subset(unsigned subsection);
145 
154  const Subset& subset(unsigned subsection) const;
155 
157  virtual void load_tables() = 0;
158 
160  virtual std::string encode() const = 0;
161 
163  void print(FILE* out) const;
164 
166  void print_structured(FILE* out) const;
167 
169  virtual void print_details(FILE* out) const;
170 
179  void print_datadesc(FILE* out, unsigned indent = 0) const;
180 
192  virtual unsigned diff(const Bulletin& msg) const;
193 
195  virtual unsigned diff_details(const Bulletin& msg) const;
196 };
197 
200 {
201 public:
211  bool decode_adds_undef_attrs = false;
212 
220  static std::unique_ptr<BufrCodecOptions> create();
221 
222 protected:
224 };
225 
227 class BufrBulletin : public Bulletin
228 {
229 public:
231  uint8_t edition_number = 4;
232 
240  uint8_t master_table_version_number = 19;
241 
250  uint8_t master_table_version_number_local = 0;
251 
253  bool compression = false;
254 
260  std::string optional_section;
261 
267  unsigned section_end[6] = {0, 0, 0, 0, 0, 0};
268 
269  virtual ~BufrBulletin() override;
270 
271  void clear() override;
272  const char* encoding_name() const throw() override { return "BUFR"; }
273  void load_tables() override;
274  std::string encode() const override;
275  void print_details(FILE* out) const override;
276  unsigned diff_details(const Bulletin& msg) const override;
277 
292  static bool read(FILE* in, std::string& buf, const char* fname = 0,
293  off_t* offset = 0);
294 
305  static void write(const std::string& buf, FILE* out, const char* fname = 0);
306 
311  static std::unique_ptr<BufrBulletin> create();
312 
325  static std::unique_ptr<BufrBulletin>
326  decode_header(const std::string& raw, const char* fname = "(memory)",
327  size_t offset = 0);
328 
343  static std::unique_ptr<BufrBulletin>
344  decode_header(const std::string& raw, const BufrCodecOptions& opts,
345  const char* fname = "(memory)", size_t offset = 0);
346 
359  static std::unique_ptr<BufrBulletin> decode(const std::string& raw,
360  const char* fname = "(memory)",
361  size_t offset = 0);
362 
377  static std::unique_ptr<BufrBulletin>
378  decode_verbose(const std::string& raw, FILE* out,
379  const char* fname = "(memory)", size_t offset = 0);
380 
395  static std::unique_ptr<BufrBulletin> decode(const std::string& raw,
396  const BufrCodecOptions& opts,
397  const char* fname = "(memory)",
398  size_t offset = 0);
399 
400 protected:
401  BufrBulletin();
402 };
403 
405 class CrexBulletin : public Bulletin
406 {
407 public:
409  uint8_t edition_number = 2;
410 
417  uint8_t master_table_version_number = 19;
418 
430  uint8_t master_table_version_number_bufr = 19;
431 
440  uint8_t master_table_version_number_local = 0;
441 
443  bool has_check_digit = false;
444 
445  void clear() override;
446  const char* encoding_name() const throw() override { return "CREX"; }
447  void load_tables() override;
448  std::string encode() const override;
449  void print_details(FILE* out) const override;
450  unsigned diff_details(const Bulletin& msg) const override;
451 
466  static bool read(FILE* in, std::string& buf, const char* fname = 0,
467  off_t* offset = 0);
468 
479  static void write(const std::string& buf, FILE* out, const char* fname = 0);
480 
485  static std::unique_ptr<CrexBulletin> create();
486 
499  static std::unique_ptr<CrexBulletin>
500  decode_header(const std::string& raw, const char* fname = "(memory)",
501  size_t offset = 0);
502 
515  static std::unique_ptr<CrexBulletin> decode(const std::string& raw,
516  const char* fname = "(memory)",
517  size_t offset = 0);
518 
533  static std::unique_ptr<CrexBulletin>
534  decode_verbose(const std::string& raw, FILE* out,
535  const char* fname = "(memory)", size_t offset = 0);
536 
537 protected:
538  CrexBulletin();
539 };
540 
550 namespace bulletin {
551 }
552 
553 } // namespace wreport
554 #endif
const char * encoding_name() const override
Type of source/target encoding.
Definition: bulletin.h:446
uint8_t rep_month
Reference month in bulletin header.
Definition: bulletin.h:107
off_t offset
File offset of the start of the message.
Definition: bulletin.h:48
uint8_t data_subcategory_local
Local data sub-category, defined locally by automatic data-processing (ADP) centres.
Definition: bulletin.h:84
std::string fname
Input file name (optional).
Definition: bulletin.h:39
virtual void load_tables()=0
Load a new set of tables to use for encoding this message.
std::string optional_section
Raw optional section of the message.
Definition: bulletin.h:260
uint8_t rep_second
Reference second in bulletin header.
Definition: bulletin.h:115
STL namespace.
void print_structured(FILE *out) const
Dump the contents of this bulletin, in a more structured way.
uint8_t rep_hour
Reference hour in bulletin header.
Definition: bulletin.h:111
uint8_t rep_day
Reference day in bulletin header.
Definition: bulletin.h:109
virtual const char * encoding_name() const =0
Type of source/target encoding.
virtual void print_details(FILE *out) const
Print format-specific details.
Collection of BUFR/CREX tables used to work on a bulletin.
Definition: tables.h:14
Storage for the decoded data of a BUFR or CREX message.
Definition: bulletin.h:29
virtual void clear()
Reset the bulletin.
CREX bulletin implementation.
Definition: bulletin.h:405
void print_datadesc(FILE *out, unsigned indent=0) const
Pretty-print the data descriptor section.
std::vector< Subset > subsets
Decoded variables.
Definition: bulletin.h:124
virtual unsigned diff_details(const Bulletin &msg) const
Diff format-specific details.
std::vector< Varcode > datadesc
Parsed data descriptor section.
Definition: bulletin.h:121
uint8_t master_table_number
BUFR Master table number.
Definition: bulletin.h:62
uint8_t data_category
Data category (BUFR or CREX Table A)
Definition: bulletin.h:65
virtual std::string encode() const =0
Encode the message.
const Subset & subset(unsigned subsection) const
Get a Subset from the message.
Options used to configure BUFR decoding.
Definition: bulletin.h:199
String functions.
Definition: benchmark.h:13
void print(FILE *out) const
Dump the contents of this bulletin.
Tables tables
Varcode and opcode tables used for encoding or decoding.
Definition: bulletin.h:118
virtual unsigned diff(const Bulletin &msg) const
Compute the differences between two bulletins.
const char * encoding_name() const override
Type of source/target encoding.
Definition: bulletin.h:272
uint16_t originating_centre
Identification of originating/generating centre (see Common Code table C-11)
Definition: bulletin.h:90
uint16_t rep_year
Reference year in bulletin header.
Definition: bulletin.h:105
Represent a BUFR/CREX data subset as a list of decoded variables.
Definition: subset.h:12
Subset & obtain_subset(unsigned subsection)
Get a Subset from the message.
BUFR bulletin implementation.
Definition: bulletin.h:227
uint8_t data_subcategory
International data sub-category (see Common Code table C-13)
Definition: bulletin.h:68
uint8_t update_sequence_number
Update sequence number (zero for original messages and for messages containing only delayed reports; ...
Definition: bulletin.h:102
uint8_t rep_minute
Reference minute in bulletin header.
Definition: bulletin.h:113
uint16_t originating_subcentre
Identification of originating/generating sub-centre (allocated by originating/generating centre - see...
Definition: bulletin.h:96