SRS-control 0.1.4
 
Loading...
Searching...
No Matches
ProtoDelimSerializer.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <google/protobuf/io/gzip_stream.h>
4#include <google/protobuf/util/delimited_message_util.h>
6
7namespace srs::process
8{
9 const auto protobuf_delim_deserializer_converter = [](const proto::Data& proto_data,
10 std::string& output_data) -> int
11 {
12 namespace protobuf = google::protobuf;
13 namespace io = protobuf::io;
14 auto output_stream = io::StringOutputStream{ &output_data };
15
16 if constexpr (common::PROTOBUF_ENABLE_GZIP)
17 {
18 auto option = io::GzipOutputStream::Options{};
19 option.compression_level = common::GZIP_DEFAULT_COMPRESSION_LEVEL;
20 auto gzip_output = io::GzipOutputStream{ &output_stream, option };
21 protobuf::util::SerializeDelimitedToZeroCopyStream(proto_data, &gzip_output);
22 gzip_output.Flush();
23 }
24 else
25 {
26 protobuf::util::SerializeDelimitedToZeroCopyStream(proto_data, &output_stream);
27 }
28 return 0;
29 };
30
31 class ProtoDelimSerializer : public ProtoSerializerBase<decltype(protobuf_delim_deserializer_converter)>
32 {
33 public:
34 explicit ProtoDelimSerializer(asio::thread_pool& thread_pool)
35 : ProtoSerializerBase{ thread_pool, "ProtoDelimSerializer", protobuf_delim_deserializer_converter }
36 {
37 }
38 static constexpr auto ConverterOption = std::array{ proto_frame };
39 };
40} // namespace srs
ProtoDelimSerializer(asio::thread_pool &thread_pool)
ProtoSerializerBase(asio::thread_pool &thread_pool, std::string name, decltype(protobuf_delim_deserializer_converter) converter)
constexpr auto GZIP_DEFAULT_COMPRESSION_LEVEL
constexpr auto PROTOBUF_ENABLE_GZIP
const auto protobuf_delim_deserializer_converter