mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-02-20 11:32:04 +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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
pb_ostream_t sizestream = {0, 0, SIZE_MAX, 0, 0};
|
size_t len;
|
||||||
bool status = pb_encode(&sizestream, fields, msg_ptr);
|
if (!pb_get_encoded_size(&len, fields, msg_ptr)) {
|
||||||
|
|
||||||
if (!status) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -193,7 +191,6 @@ bool msg_write_common(char type, uint16_t msg_id, const void *msg_ptr)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t len = sizestream.bytes_written;
|
|
||||||
append('#');
|
append('#');
|
||||||
append('#');
|
append('#');
|
||||||
append((msg_id >> 8) & 0xFF);
|
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 >> 8) & 0xFF);
|
||||||
append(len & 0xFF);
|
append(len & 0xFF);
|
||||||
pb_ostream_t stream = {pb_callback, 0, SIZE_MAX, 0, 0};
|
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') {
|
if (type == 'n') {
|
||||||
msg_out_pad();
|
msg_out_pad();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user