userver
C++ Async Framework
Loading...
Searching...
No Matches
byte_buffer_utils.hpp
Go to the documentation of this file.
1
#
pragma
once
2
3
/// @file userver/ugrpc/byte_buffer_utils.hpp
4
/// @brief Helper functions for working with `grpc::ByteBuffer`
5
6
#
include
<
cstddef
>
7
8
#
include
<
google
/
protobuf
/
message
.
h
>
9
#
include
<
grpcpp
/
support
/
byte_buffer
.
h
>
10
11
USERVER_NAMESPACE_BEGIN
12
13
namespace
ugrpc
{
14
15
/// @see @ref SerializeToByteBuffer
16
inline
constexpr
std::size_t
kDefaultSerializeBlockSize
= 4096;
17
18
/// @brief Serialize a Protobuf message to the wire format.
19
/// @param message the message to serialize
20
/// @param block_size can be used for performance tuning, too small chunk size
21
/// results in extra allocations, too large chunk size results in wasting memory
22
/// @throws std::runtime_error on serialization errors (supposedly only happens
23
/// on extremely rare allocation failures or proto reflection malfunctioning).
24
grpc::ByteBuffer
SerializeToByteBuffer
(
25
const
::google::protobuf::Message& message,
26
std::size_t block_size =
kDefaultSerializeBlockSize
);
27
28
/// @brief Parse a Protobuf message from the wire format.
29
/// @param buffer the buffer that might be tempered with during deserialization
30
/// @param message will contain the parsing result on success
31
/// @returns `true` on success, `false` if @a buffer does not contain a valid
32
/// message, according to the derived type of @a message
33
bool
ParseFromByteBuffer
(grpc::ByteBuffer&& buffer,
34
::google::protobuf::Message& message);
35
36
}
// namespace ugrpc
37
38
USERVER_NAMESPACE_END
userver
ugrpc
byte_buffer_utils.hpp
Generated on Thu Sep 5 2024 11:20:54 for userver by
Doxygen
1.10.0