SRS-control 0.1.4
 
Loading...
Searching...
No Matches
RawFrameReader.cpp
Go to the documentation of this file.
1#include <spdlog/spdlog.h>
3#include <zpp_bits.h>
4
5namespace srs::reader
6{
7
8 RawFrame::RawFrame(const std::string& filename)
9 : input_filename_{ filename }
10 , input_file_{ filename, std::ios::binary }
11 {
12 if (input_file_.fail())
13 {
14 throw std::runtime_error{ fmt::format("Cannot open the file {:?}", input_filename_) };
15 }
16 spdlog::debug("Open the binary file {:?}", input_filename_);
17 }
18
19 auto RawFrame::read_one_frame(std::vector<char>& binary_data, std::ifstream& input_file) -> std::size_t
20 {
21 if (not input_file.is_open())
22 {
23 spdlog::critical("The input file is not open!");
24 return 0;
25 }
26 binary_data.reserve(common::LARGE_READ_MSG_BUFFER_SIZE);
27 std::array<char, sizeof(common::RawDelimSizeType)> size_buffer{};
28 auto size = common::RawDelimSizeType{};
29 if (input_file.eof())
30 {
31 spdlog::info("End of the binary file.");
32 return 0;
33 }
34
35 input_file.read(size_buffer.data(), static_cast<int64_t>(size_buffer.size()));
36 auto serialize_to = zpp::bits::in{ size_buffer, zpp::bits::endian::big{} };
37 serialize_to(size).or_throw();
38 binary_data.resize(size, 0);
39 auto read_size = static_cast<std::size_t>(input_file.read(binary_data.data(), size).gcount());
40
41 if (read_size != size)
42 {
43 spdlog::warn("Binary Data is not extracted correctly from the input file");
44 }
45
46 return read_size;
47 }
48
49 auto RawFrame::read_one_frame() -> std::string_view
50 {
52 return std::string_view{ input_buffer_.data(), input_buffer_.size() };
53 }
54} // namespace srs::reader
auto read_one_frame() -> std::string_view
Read one frame of the binary data from a file specified by the constructor RawFrame(conststd::string&...
static auto read_one_frame(std::vector< char > &binary_data, std::ifstream &input_file) -> std::size_t
Read one frame of the bianry data to a vector.
std::string input_filename_
Input binary file name.
std::vector< char > input_buffer_
internal binary data buffer
RawFrame()=default
Default Constructor. No memory allocation.
std::ifstream input_file_
Input binary file handler.
uint32_t RawDelimSizeType
constexpr auto LARGE_READ_MSG_BUFFER_SIZE
size of the data array for reading a UDP package