Deserialization of the UDP binary data
The class srs::reader::ProtoMsg
, with an alias srs::ProtoMsgReader
, is responsible for the deserialization of the UDP binary data, which converts the Protobuf binary data sent by a UDP socket to a C++ data structure. All memory allocation of this class is done in its constructor. If the conversion are repeated many times, the object should be kept alive to reduce the memory allocation.
The full example can be found in this script .
Minimum example:
1#include <srs/srs.hpp>
2
3auto main() -> int
4{
5 auto msg_reader = srs::ProtoMsgReader{};
6
7 std::string_view proto_binary = get_proto_msg();
8
9 const auto& data_struct = msg_reader.convert(proto_binary);
10
11 return 0;
12}
Details of srs::reader::ProtoMsg
Reading delimited binary data from the binary output file
The class srs::reader::RawFrame
, with an alias srs::RawFrameReader
, is used to extract frames of binary data separately and consecutively from a binary file (or a FIFO file). Frames in the binary file are divided by a value in the type RawDelimSizeType
located at the beginning of each frame, which stores the total byte size of the current frame.
This class provides both a public method and a static public method for the users to extract the frames from the binary file. The static public method should be used if the user wants to use the self-provided file handler and data buffer. In such case, the class should be constructed from its default constructor (RawFrame::RawFrame()
) and no memory is allocated internally. On the other hand, the normal public method can be used if the user wants to rely on this class for the file opening and the data buffer. In this case, the constructor with a string input should be used instead and the object should be kept alive throughout the whole reading.
Minimum example:
1#include <srs/srs.hpp>
2#include <string>
3#include <fstream>
4
5auto main() -> int
6{
7 const auto filename = std::string{ "output.bin" };
8
9 // Using external buffer
10 auto raw_frame_reader1 = srs::RawFrameReader{};
11
12 auto input_file = std::ifstream{ filename, std::ios::binary };
13 auto external_buffer = std::vector<char>{};
14
15 raw_rame_reader1.read_one_frame(external_buffer, input_file);
16
17 // Using internal buffer
18 auto raw_frame_reader2 = srs::RawFrameReader{ filename };
19
20 auto binary_data = raw_frame_reader2.read_one_frame();
21
22 return 0;
23}