1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-26 09:28:13 +00:00

messages: Use pb_get_encoded_size

This commit is contained in:
Saleem Rashid 2018-06-19 20:06:59 +01:00 committed by Pavol Rusnak
parent 520cd69f25
commit dbb3e927ec
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D

View File

@ -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();
}