mirror of
https://github.com/protobuf-c/protobuf-c.git
synced 2025-01-14 01:07:57 +08:00
Pack nested messages inline
Signed-off-by: Markus Engel <engel@sero-systems.de>
This commit is contained in:
parent
5af12e4581
commit
2804820230
@ -1618,22 +1618,19 @@ required_field_pack_to_buffer(const ProtobufCFieldDescriptor *field,
|
||||
break;
|
||||
}
|
||||
case PROTOBUF_C_TYPE_MESSAGE: {
|
||||
uint8_t simple_buffer_scratch[256];
|
||||
size_t sublen;
|
||||
const ProtobufCMessage *msg = *(ProtobufCMessage * const *) member;
|
||||
ProtobufCBufferSimple simple_buffer =
|
||||
PROTOBUF_C_BUFFER_SIMPLE_INIT(simple_buffer_scratch);
|
||||
|
||||
|
||||
scratch[0] |= PROTOBUF_C_WIRE_TYPE_LENGTH_PREFIXED;
|
||||
if (msg == NULL)
|
||||
sublen = 0;
|
||||
else
|
||||
sublen = protobuf_c_message_pack_to_buffer(msg, &simple_buffer.base);
|
||||
rv += uint32_pack(sublen, scratch + rv);
|
||||
buffer->append(buffer, rv, scratch);
|
||||
buffer->append(buffer, sublen, simple_buffer.data);
|
||||
rv += sublen;
|
||||
PROTOBUF_C_BUFFER_SIMPLE_CLEAR(&simple_buffer);
|
||||
if (msg == NULL) {
|
||||
rv += uint32_pack(0, scratch + rv);
|
||||
buffer->append(buffer, rv, scratch);
|
||||
} else {
|
||||
size_t sublen = protobuf_c_message_get_packed_size(msg);
|
||||
rv += uint32_pack(sublen, scratch + rv);
|
||||
buffer->append(buffer, rv, scratch);
|
||||
protobuf_c_message_pack_to_buffer(msg, buffer);
|
||||
rv += sublen;
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
|
Loading…
x
Reference in New Issue
Block a user