libwreport  3.40
decoder.h
1 #ifndef WREPORT_BUFR_DECODER_H
2 #define WREPORT_BUFR_DECODER_H
3 
4 #include <wreport/bufr/input.h>
5 #include <wreport/bulletin.h>
6 #include <wreport/bulletin/interpreter.h>
7 #include <wreport/var.h>
8 
9 namespace wreport {
10 namespace bufr {
11 struct DispatchToSubsets;
12 
13 struct Decoder
14 {
17  /* Output decoded variables */
18  BufrBulletin& out;
22  bool conf_add_undef_attrs = false;
26  FILE* verbose_output = nullptr;
27 
28  Decoder(const std::string& buf, const char* fname, size_t offset,
29  BufrBulletin& out);
30 
31  void read_options(const BufrCodecOptions& opts);
32 
33  void decode_sec1ed3();
34  void decode_sec1ed4();
35 
36  /* Decode the message header only */
37  void decode_header();
38 
39  /* Decode message data section after the header has been decoded */
40  void decode_data();
41 };
42 
44 {
47 
48  DecoderTarget(Input& in) : in(in) {}
49  virtual ~DecoderTarget() {}
50 
58  virtual const Subset& reference_subset() const = 0;
59 
63  virtual Varinfo lookup_info(unsigned pos) const = 0;
64 
72  virtual Var decode_uniform_b_value(Varinfo info) = 0;
73 
78  virtual const Var& decode_and_add_to_all(Varinfo info) = 0;
79 
80  virtual const Var& decode_and_add_bitmap(const Tables& tables, Varcode code,
81  unsigned bitmap_size) = 0;
82 
87  virtual void decode_and_set_attribute(Varinfo info, unsigned pos) = 0;
88 
92  virtual void decode_and_add_b_value(Varinfo info) = 0;
93 
99  Varinfo info, const bulletin::AssociatedField& field) = 0;
100 
105  virtual void decode_and_add_raw_character_data(Varinfo info) = 0;
106 
111  virtual int decode_c03_refval_override(unsigned bits) = 0;
112 
114  virtual void print_last_variable_added(FILE* out) = 0;
115 
118  virtual void print_last_attribute_added(FILE* out, Varcode code,
119  unsigned pos) = 0;
120 };
121 
123 {
126 
128 
129  const Subset& reference_subset() const override;
130  Varinfo lookup_info(unsigned pos) const override;
131  Var decode_uniform_b_value(Varinfo info) override;
132  const Var& decode_and_add_to_all(Varinfo info) override;
133  const Var& decode_and_add_bitmap(const Tables& tables, Varcode code,
134  unsigned bitmap_size) override;
135  void decode_and_set_attribute(Varinfo info, unsigned pos) override;
136  void decode_and_add_b_value(Varinfo info) override;
138  Varinfo info, const bulletin::AssociatedField& field) override;
139  void decode_and_add_raw_character_data(Varinfo info) override;
140  int decode_c03_refval_override(unsigned bits) override;
141 
142  void print_last_variable_added(FILE* out) override;
143  void print_last_attribute_added(FILE* out, Varcode code,
144  unsigned pos) override;
145 };
146 
148 {
151 
153  unsigned subset_count;
154 
156 
157  const Subset& reference_subset() const override;
158  Varinfo lookup_info(unsigned pos) const override;
159  Var decode_uniform_b_value(Varinfo info) override;
160  const Var& decode_and_add_to_all(Varinfo info) override;
161  const Var& decode_and_add_bitmap(const Tables& tables, Varcode code,
162  unsigned bitmap_size) override;
163  void decode_and_set_attribute(Varinfo info, unsigned pos) override;
164  void decode_and_add_b_value(Varinfo info) override;
166  Varinfo info, const bulletin::AssociatedField& field) override;
167  void decode_and_add_raw_character_data(Varinfo info) override;
168  int decode_c03_refval_override(unsigned bits) override;
169 
170  void print_last_variable_added(FILE* out) override;
171  void print_last_attribute_added(FILE* out, Varcode code,
172  unsigned pos) override;
173 
174 protected:
175  void decode_b_value(Varinfo info,
176  std::function<void(unsigned, Var&&)> dest);
177 };
178 
180 {
181  DecoderTarget& target;
182 
183  DataSectionDecoder(Bulletin& bulletin, DecoderTarget& target);
184 
185  unsigned define_delayed_replication_factor(Varinfo info) override;
186  unsigned define_associated_field_significance(Varinfo info) override;
187  unsigned define_bitmap_delayed_replication_factor(Varinfo info) override;
188  void define_c03_refval_override(Varcode code) override;
189  void define_bitmap(unsigned bitmap_size) override;
190  void define_attribute(Varinfo info, unsigned pos) override;
191  void define_substituted_value(unsigned pos) override;
192  void define_variable(Varinfo info) override;
194  void define_raw_character_data(Varcode code) override;
195 };
196 
198 {
199 protected:
206  void print_lead(Varcode code);
207  void print_lead_continued();
208 
209 public:
210  FILE* out;
211 
218  unsigned indent = 0;
219 
221  unsigned indent_step = 2;
222 
224  FILE* out);
225 
226  void b_variable(Varcode code) override;
227  void c_modifier(Varcode code, Opcodes& next) override;
228  void r_replication(Varcode code, Varcode delayed_code,
229  const Opcodes& ops) override;
230  void run_d_expansion(Varcode code) override;
231  unsigned define_delayed_replication_factor(Varinfo info) override;
232  unsigned define_associated_field_significance(Varinfo info) override;
233  unsigned define_bitmap_delayed_replication_factor(Varinfo info) override;
234  void define_c03_refval_override(Varcode code) override;
235  void define_bitmap(unsigned bitmap_size) override;
236  void define_attribute(Varinfo info, unsigned pos) override;
237  void define_substituted_value(unsigned pos) override;
238  void define_variable(Varinfo info) override;
240  void define_raw_character_data(Varcode code) override;
241 };
242 
243 } // namespace bufr
244 } // namespace wreport
245 #endif
virtual const Var & decode_and_add_to_all(Varinfo info)=0
Decode and add the same value to all datasets, return a reference to one of the variables added...
void print_lead(Varcode code)
Print line lead (indentation and formatted code)
void decode_and_set_attribute(Varinfo info, unsigned pos) override
Decode an attribute with the given description, and add it to data at position pos.
Varinfo lookup_info(unsigned pos) const override
Return information about a value previously stored at the given position.
void define_substituted_value(unsigned pos) override
Request processing of a substituted value corresponding to position pos in the list or previous varia...
Varinfo lookup_info(unsigned pos) const override
Return information about a value previously stored at the given position.
Input & in
Input buffer.
Definition: decoder.h:46
void define_variable(Varinfo info) override
Request processing, according to info, of a data variable.
Var decode_uniform_b_value(Varinfo info) override
Decode a value that must always be the same across all datasets.
void print_last_attribute_added(FILE *out, Varcode code, unsigned pos) override
Print the value(s) of the last attributes(s) with the given code added to out.
void define_c03_refval_override(Varcode code) override
Request processing of a new value for the reference value of the given B code.
void c_modifier(Varcode code, Opcodes &next) override
Notify of a C modifier.
void define_raw_character_data(Varcode code) override
Request processing of C05yyy raw character data.
Bulletin & out
Output bulletin.
Definition: decoder.h:150
A physical variable.
Definition: var.h:24
unsigned define_delayed_replication_factor(Varinfo info) override
Request processing, according to info, of a data variabile that is significant for controlling the en...
void decode_and_set_attribute(Varinfo info, unsigned pos) override
Decode an attribute with the given description, and add it to data at position pos.
void decode_and_add_raw_character_data(Varinfo info) override
Decode raw character data described by code and add it to the target subset(s)
virtual const Subset & reference_subset() const =0
Return the reference to a subset that is receiving the data currently decoded.
const Subset & reference_subset() const override
Return the reference to a subset that is receiving the data currently decoded.
void define_attribute(Varinfo info, unsigned pos) override
Request processing of an attribute encoded with info, related to the variable as position pos in the ...
virtual void decode_and_add_raw_character_data(Varinfo info)=0
Decode raw character data described by code and add it to the target subset(s)
Subset & out
Subset where decoded variables go.
Definition: decoder.h:125
Collection of BUFR/CREX tables used to work on a bulletin.
Definition: tables.h:14
int decode_c03_refval_override(unsigned bits) override
Decode the given number of bits a signed integer, to use as a new value for B table reference value...
FILE * verbose_output
If set, be verbose and print a trace of decoding to the given file.
Definition: decoder.h:26
Storage for the decoded data of a BUFR or CREX message.
Definition: bulletin.h:29
virtual void print_last_attribute_added(FILE *out, Varcode code, unsigned pos)=0
Print the value(s) of the last attributes(s) with the given code added to out.
void define_variable_with_associated_field(Varinfo info) override
Request processing, according to info, of a data variable.
void define_attribute(Varinfo info, unsigned pos) override
Request processing of an attribute encoded with info, related to the variable as position pos in the ...
unsigned define_delayed_replication_factor(Varinfo info) override
Request processing, according to info, of a data variabile that is significant for controlling the en...
void decode_and_add_b_value(Varinfo info) override
Decode a B-table value and add its value(s) to the target subset(s)
virtual Varinfo lookup_info(unsigned pos) const =0
Return information about a value previously stored at the given position.
void decode_and_add_b_value_with_associated_field(Varinfo info, const bulletin::AssociatedField &field) override
Decode a B-table value with associated field, and add its value(s) to the target subset(s) ...
Definition: decoder.h:43
virtual void decode_and_add_b_value(Varinfo info)=0
Decode a B-table value and add its value(s) to the target subset(s)
uint16_t Varcode
Holds the WMO variable code of a variable.
Definition: fwd.h:12
const Var & decode_and_add_to_all(Varinfo info) override
Decode and add the same value to all datasets, return a reference to one of the variables added...
virtual void decode_and_add_b_value_with_associated_field(Varinfo info, const bulletin::AssociatedField &field)=0
Decode a B-table value with associated field, and add its value(s) to the target subset(s) ...
void print_last_variable_added(FILE *out) override
Print the value(s) of the last variable(s) added to out.
Information about a variable.
Definition: varinfo.h:139
virtual int decode_c03_refval_override(unsigned bits)=0
Decode the given number of bits a signed integer, to use as a new value for B table reference value...
Binary buffer with bit-level read operations.
Definition: input.h:47
Definition: decoder.h:13
unsigned indent_step
How many spaces in an indentation level.
Definition: decoder.h:221
const Subset & reference_subset() const override
Return the reference to a subset that is receiving the data currently decoded.
void define_raw_character_data(Varcode code) override
Request processing of C05yyy raw character data.
Sequence of opcodes, as a slice of a Varcode vector.
Definition: opcodes.h:19
Var decode_uniform_b_value(Varinfo info) override
Decode a value that must always be the same across all datasets.
unsigned indent
Current indent level.
Definition: decoder.h:218
unsigned optional_section_length
Optional section length decoded from the message.
Definition: decoder.h:24
const Var & decode_and_add_to_all(Varinfo info) override
Decode and add the same value to all datasets, return a reference to one of the variables added...
Options used to configure BUFR decoding.
Definition: bulletin.h:199
void b_variable(Varcode code) override
Notify of a B variable entry.
int decode_c03_refval_override(unsigned bits) override
Decode the given number of bits a signed integer, to use as a new value for B table reference value...
Input in
Input data.
Definition: decoder.h:16
String functions.
Definition: benchmark.h:13
Interpreter for data descriptor sections.
Definition: interpreter.h:25
Definition: associated_fields.h:12
void r_replication(Varcode code, Varcode delayed_code, const Opcodes &ops) override
Handle a replicated section.
unsigned define_associated_field_significance(Varinfo info) override
Request processing of an associated field significance variable (B31021).
void define_bitmap(unsigned bitmap_size) override
Request processing of a data present bitmap.
unsigned subset_count
Number of subsets in data section.
Definition: decoder.h:153
void run_d_expansion(Varcode code) override
Executes the expansion of code, which has been put on top of the opcode stack.
virtual Var decode_uniform_b_value(Varinfo info)=0
Decode a value that must always be the same across all datasets.
void decode_and_add_b_value(Varinfo info) override
Decode a B-table value and add its value(s) to the target subset(s)
void define_variable_with_associated_field(Varinfo info) override
Request processing, according to info, of a data variable.
unsigned define_bitmap_delayed_replication_factor(Varinfo info) override
Request processing of a delayed replication factor variable used to encode the size of a bitmap...
virtual void decode_and_set_attribute(Varinfo info, unsigned pos)=0
Decode an attribute with the given description, and add it to data at position pos.
void decode_and_add_raw_character_data(Varinfo info) override
Decode raw character data described by code and add it to the target subset(s)
size_t expected_subsets
Number of expected subsets (read in decode_header, used in decode_data)
Definition: decoder.h:20
virtual void print_last_variable_added(FILE *out)=0
Print the value(s) of the last variable(s) added to out.
Definition: decoder.h:179
bool conf_add_undef_attrs
True if undefined attributes are added to the output, else false.
Definition: decoder.h:22
void print_last_attribute_added(FILE *out, Varcode code, unsigned pos) override
Print the value(s) of the last attributes(s) with the given code added to out.
Represent a BUFR/CREX data subset as a list of decoded variables.
Definition: subset.h:12
void decode_and_add_b_value_with_associated_field(Varinfo info, const bulletin::AssociatedField &field) override
Decode a B-table value with associated field, and add its value(s) to the target subset(s) ...
void define_substituted_value(unsigned pos) override
Request processing of a substituted value corresponding to position pos in the list or previous varia...
void define_c03_refval_override(Varcode code) override
Request processing of a new value for the reference value of the given B code.
void define_variable(Varinfo info) override
Request processing, according to info, of a data variable.
BUFR bulletin implementation.
Definition: bulletin.h:227
void define_bitmap(unsigned bitmap_size) override
Request processing of a data present bitmap.
unsigned define_bitmap_delayed_replication_factor(Varinfo info) override
Request processing of a delayed replication factor variable used to encode the size of a bitmap...
void print_last_variable_added(FILE *out) override
Print the value(s) of the last variable(s) added to out.
unsigned define_associated_field_significance(Varinfo info) override
Request processing of an associated field significance variable (B31021).