mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-12-27 16:48:09 +00:00
messages: Use pb_get_encoded_size
This commit is contained in:
parent
520cd69f25
commit
dbb3e927ec
@ -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…
Reference in New Issue
Block a user