SRS-control 0.1.4
Loading...
Searching...
No Matches
ProtoSerializer.cpp
Go to the documentation of this file.
1#include "ProtoSerializer.hpp"
2#include "srs/data/message.pb.h"
4#include <google/protobuf/io/gzip_stream.h>
5#include <google/protobuf/io/zero_copy_stream_impl_lite.h>
6#include <google/protobuf/util/delimited_message_util.h>
7#include <string>
8
9namespace srs::process
10{
11 auto protobuf_delim_deserializer_converter::operator()(const proto::Data& proto_data, std::string& output_data)
12 -> int
13 {
14 namespace protobuf = google::protobuf;
15 namespace io = protobuf::io;
16 auto output_stream = io::StringOutputStream{ &output_data };
17
18 if constexpr (common::PROTOBUF_ENABLE_GZIP)
19 {
20 auto option = io::GzipOutputStream::Options{};
21 option.compression_level = common::GZIP_DEFAULT_COMPRESSION_LEVEL;
22 auto gzip_output = io::GzipOutputStream{ &output_stream, option };
23 protobuf::util::SerializeDelimitedToZeroCopyStream(proto_data, &gzip_output);
24 gzip_output.Flush();
25 }
26 else
27 {
28 protobuf::util::SerializeDelimitedToZeroCopyStream(proto_data, &output_stream);
29 }
30 return 0;
31 };
32
33 auto protobuf_deserializer_converter::operator()(const proto::Data& proto_data, std::string& output_data) -> int
34 {
35 namespace protobuf = google::protobuf;
36 namespace io = protobuf::io;
37 auto output_stream = io::StringOutputStream{ &output_data };
38 proto_data.SerializeToZeroCopyStream(&output_stream);
39 return 0;
40 };
41} // namespace srs::process
auto operator()(const proto::Data &proto_data, std::string &output_data) -> int
auto operator()(const proto::Data &proto_data, std::string &output_data) -> int
constexpr auto GZIP_DEFAULT_COMPRESSION_LEVEL
constexpr auto PROTOBUF_ENABLE_GZIP