nng_proto: add comments. fix return statement in serialize_proto_to_nng()
This commit is contained in:
parent
ba54b5ff19
commit
d5f9b87896
2 changed files with 10 additions and 1 deletions
|
@ -7,8 +7,17 @@
|
|||
namespace mesytec::mnode::nng
|
||||
{
|
||||
|
||||
// Format is: [u32 size][protobuf message]
|
||||
|
||||
// Appends size prefix and serialied message contents to the nng msg.
|
||||
// Returns the number of bytes written.
|
||||
size_t serialize_proto_to_nng(const google::protobuf::MessageLite &message, nng_msg *msg);
|
||||
|
||||
// Deserializes a protobuf message from an nng msg.
|
||||
// Returns the number of bytes used (size prefix + message).
|
||||
size_t deserialize_proto_from_nng(google::protobuf::MessageLite &message, nng_msg *msg);
|
||||
|
||||
// Same as above but also trims the message.
|
||||
size_t deserialize_proto_from_nng_trim(google::protobuf::MessageLite &message, nng_msg *msg);
|
||||
|
||||
} // namespace mesytec::mnode::nng
|
||||
|
|
|
@ -10,7 +10,7 @@ size_t serialize_proto_to_nng(const google::protobuf::MessageLite &message, nng_
|
|||
auto messageSize = message.ByteSizeLong();
|
||||
|
||||
if (auto res = nng_msg_realloc(msg, nng_msg_len(msg) + sizeof(u32) + messageSize))
|
||||
return false;
|
||||
return 0;
|
||||
|
||||
*reinterpret_cast<u32 *>(nng_msg_body(msg)) = messageSize;
|
||||
if (!message.SerializeToArray(reinterpret_cast<u8 *>(nng_msg_body(msg)) + sizeof(u32),
|
||||
|
|
Loading…
Reference in a new issue