From dbb3e927eccc565bbc767fcd002d3c286fc23e5c Mon Sep 17 00:00:00 2001 From: Saleem Rashid Date: Tue, 19 Jun 2018 20:06:59 +0100 Subject: [PATCH] messages: Use pb_get_encoded_size --- firmware/messages.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/firmware/messages.c b/firmware/messages.c index aa947f3f28..69473ef5d7 100644 --- a/firmware/messages.c +++ b/firmware/messages.c @@ -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(); }