messages: Use pb_get_encoded_size

pull/25/head
Saleem Rashid 6 years ago committed by Pavol Rusnak
parent 520cd69f25
commit dbb3e927ec
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D

@ -169,10 +169,8 @@ bool msg_write_common(char type, uint16_t msg_id, const void *msg_ptr)
return false;
}
pb_ostream_t sizestream = {0, 0, SIZE_MAX, 0, 0};
bool status = pb_encode(&sizestream, fields, msg_ptr);
if (!status) {
size_t len;
if (!pb_get_encoded_size(&len, fields, msg_ptr)) {
return false;
}
@ -193,7 +191,6 @@ bool msg_write_common(char type, uint16_t msg_id, const void *msg_ptr)
return false;
}
uint32_t len = sizestream.bytes_written;
append('#');
append('#');
append((msg_id >> 8) & 0xFF);
@ -203,7 +200,7 @@ bool msg_write_common(char type, uint16_t msg_id, const void *msg_ptr)
append((len >> 8) & 0xFF);
append(len & 0xFF);
pb_ostream_t stream = {pb_callback, 0, SIZE_MAX, 0, 0};
status = pb_encode(&stream, fields, msg_ptr);
bool status = pb_encode(&stream, fields, msg_ptr);
if (type == 'n') {
msg_out_pad();
}

Loading…
Cancel
Save