libwreport 3.38
decoder.h
1#ifndef WREPORT_BUFR_DECODER_H
2#define WREPORT_BUFR_DECODER_H
3
4#include <wreport/var.h>
5#include <wreport/bulletin.h>
6#include <wreport/bulletin/interpreter.h>
7#include <wreport/bufr/input.h>
8
9namespace wreport {
10namespace bufr {
11struct DispatchToSubsets;
12
13struct Decoder
14{
17 /* Output decoded variables */
18 BufrBulletin& out;
26 FILE* verbose_output = nullptr;
27
28 Decoder(const std::string& buf, const char* fname, size_t offset, BufrBulletin& out);
29
30 void read_options(const BufrCodecOptions& opts);
31
32 void decode_sec1ed3();
33 void decode_sec1ed4();
34
35 /* Decode the message header only */
36 void decode_header();
37
38 /* Decode message data section after the header has been decoded */
39 void decode_data();
40};
41
43{
46
47 DecoderTarget(Input& in) : in(in) {}
48 virtual ~DecoderTarget() {}
49
57 virtual const Subset& reference_subset() const = 0;
58
62 virtual Varinfo lookup_info(unsigned pos) const = 0;
63
72
77 virtual const Var& decode_and_add_to_all(Varinfo info) = 0;
78
79 virtual const Var& decode_and_add_bitmap(const Tables& tables, Varcode code, unsigned bitmap_size) = 0;
80
85 virtual void decode_and_set_attribute(Varinfo info, unsigned pos) = 0;
86
90 virtual void decode_and_add_b_value(Varinfo info) = 0;
91
97
103
108 virtual int decode_c03_refval_override(unsigned bits) = 0;
109
111 virtual void print_last_variable_added(FILE* out) = 0;
112
114 virtual void print_last_attribute_added(FILE* out, Varcode code, unsigned pos) = 0;
115};
116
118{
121
123
124 const Subset& reference_subset() const override;
125 Varinfo lookup_info(unsigned pos) const override;
127 const Var& decode_and_add_to_all(Varinfo info) override;
128 const Var& decode_and_add_bitmap(const Tables& tables, Varcode code, unsigned bitmap_size) override;
129 void decode_and_set_attribute(Varinfo info, unsigned pos) override;
130 void decode_and_add_b_value(Varinfo info) override;
133 int decode_c03_refval_override(unsigned bits) override;
134
135 void print_last_variable_added(FILE* out) override;
136 void print_last_attribute_added(FILE* out, Varcode code, unsigned pos) override;
137};
138
140{
143
145 unsigned subset_count;
146
148
149 const Subset& reference_subset() const override;
150 Varinfo lookup_info(unsigned pos) const override;
152 const Var& decode_and_add_to_all(Varinfo info) override;
153 const Var& decode_and_add_bitmap(const Tables& tables, Varcode code, unsigned bitmap_size) override;
154 void decode_and_set_attribute(Varinfo info, unsigned pos) override;
155 void decode_and_add_b_value(Varinfo info) override;
158 int decode_c03_refval_override(unsigned bits) override;
159
160 void print_last_variable_added(FILE* out) override;
161 void print_last_attribute_added(FILE* out, Varcode code, unsigned pos) override;
162
163protected:
164 void decode_b_value(Varinfo info, std::function<void(unsigned, Var&&)> dest);
165};
166
168{
169 DecoderTarget& target;
170
171 DataSectionDecoder(Bulletin& bulletin, DecoderTarget& target);
172
177 void define_bitmap(unsigned bitmap_size) override;
178 void define_attribute(Varinfo info, unsigned pos) override;
179 void define_substituted_value(unsigned pos) override;
180 void define_variable(Varinfo info) override;
183};
184
186{
187protected:
194 void print_lead(Varcode code);
195 void print_lead_continued();
196
197public:
198 FILE* out;
199
206 unsigned indent = 0;
207
209 unsigned indent_step = 2;
210
211 VerboseDataSectionDecoder(Bulletin& bulletin, DecoderTarget& target, FILE* out);
212
213 void b_variable(Varcode code) override;
214 void c_modifier(Varcode code, Opcodes& next) override;
215 void r_replication(Varcode code, Varcode delayed_code, const Opcodes& ops) override;
216 void run_d_expansion(Varcode code) override;
221 void define_bitmap(unsigned bitmap_size) override;
222 void define_attribute(Varinfo info, unsigned pos) override;
223 void define_substituted_value(unsigned pos) override;
224 void define_variable(Varinfo info) override;
227};
228
229}
230}
231#endif
BUFR bulletin implementation.
Definition: bulletin.h:229
Options used to configure BUFR decoding.
Definition: bulletin.h:200
Storage for the decoded data of a BUFR or CREX message.
Definition: bulletin.h:30
Represent a BUFR/CREX data subset as a list of decoded variables.
Definition: subset.h:13
A physical variable.
Definition: var.h:25
Binary buffer with bit-level read operations.
Definition: input.h:46
String functions.
Definition: benchmark.h:13
uint16_t Varcode
Holds the WMO variable code of a variable.
Definition: fwd.h:12
Sequence of opcodes, as a slice of a Varcode vector.
Definition: opcodes.h:20
Collection of BUFR/CREX tables used to work on a bulletin.
Definition: tables.h:15
Information about a variable.
Definition: varinfo.h:139
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.
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)
Bulletin & out
Output bulletin.
Definition: decoder.h:142
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 decode_and_add_b_value(Varinfo info) override
Decode a B-table value and add its value(s) to the target subset(s)
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.
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.
const Subset & reference_subset() const override
Return the reference to a subset that is receiving the data currently decoded.
Varinfo lookup_info(unsigned pos) const override
Return information about a value previously stored at the given position.
unsigned subset_count
Number of subsets in data section.
Definition: decoder.h:145
void print_last_variable_added(FILE *out) override
Print the value(s) of the last variable(s) added to out.
Var decode_uniform_b_value(Varinfo info) override
Decode a value that must always be the same across all datasets.
Definition: decoder.h:168
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.
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 ...
void define_raw_character_data(Varcode code) override
Request processing of C05yyy raw character data.
unsigned define_associated_field_significance(Varinfo info) override
Request processing of an associated field significance variable (B31021).
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 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 define_variable_with_associated_field(Varinfo info) override
Request processing, according to info, of a data variable.
Definition: decoder.h:43
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.
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)
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)
Input & in
Input buffer.
Definition: decoder.h:45
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)
virtual Varinfo lookup_info(unsigned pos) const =0
Return information about a value previously stored at the given position.
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.
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.
virtual Var decode_uniform_b_value(Varinfo info)=0
Decode a value that must always be the same across all datasets.
virtual void print_last_variable_added(FILE *out)=0
Print the value(s) of the last variable(s) added to out.
virtual const Subset & reference_subset() const =0
Return the reference to a subset that is receiving the data currently decoded.
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.
Definition: decoder.h:14
FILE * verbose_output
If set, be verbose and print a trace of decoding to the given file.
Definition: decoder.h:26
Input in
Input data.
Definition: decoder.h:16
bool conf_add_undef_attrs
True if undefined attributes are added to the output, else false.
Definition: decoder.h:22
size_t expected_subsets
Number of expected subsets (read in decode_header, used in decode_data)
Definition: decoder.h:20
unsigned optional_section_length
Optional section length decoded from the message.
Definition: decoder.h:24
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.
const Subset & reference_subset() const override
Return the reference to a subset that is receiving the data currently decoded.
Subset & out
Subset where decoded variables go.
Definition: decoder.h:120
void decode_and_add_b_value(Varinfo info) override
Decode a B-table value and add its value(s) to the target subset(s)
Varinfo lookup_info(unsigned pos) const override
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)
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 decode_and_set_attribute(Varinfo info, unsigned pos) override
Decode an attribute with the given description, and add it to data at position pos.
Var decode_uniform_b_value(Varinfo info) override
Decode a value that must always be the same across all datasets.
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.
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)
void print_last_variable_added(FILE *out) override
Print the value(s) of the last variable(s) added to out.
void define_variable_with_associated_field(Varinfo info) override
Request processing, according to info, of a data variable.
unsigned indent
Current indent level.
Definition: decoder.h:206
unsigned define_associated_field_significance(Varinfo info) override
Request processing of an associated field significance variable (B31021).
void run_d_expansion(Varcode code) override
Executes the expansion of code, which has been put on top of the opcode stack.
void c_modifier(Varcode code, Opcodes &next) override
Notify of a C modifier.
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_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 r_replication(Varcode code, Varcode delayed_code, const Opcodes &ops) override
Handle a replicated section.
unsigned define_delayed_replication_factor(Varinfo info) override
Request processing, according to info, of a data variabile that is significant for controlling the en...
unsigned indent_step
How many spaces in an indentation level.
Definition: decoder.h:209
void print_lead(Varcode code)
Print line lead (indentation and formatted code)
void b_variable(Varcode code) override
Notify of a B variable entry.
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 ...
void define_raw_character_data(Varcode code) override
Request processing of C05yyy raw character data.
void define_variable(Varinfo info) override
Request processing, according to info, of a data variable.
Definition: associated_fields.h:13
Interpreter for data descriptor sections.
Definition: interpreter.h:26