sending the encoded buffer over UART the python func ParseFromString fails

89 views
Skip to first unread message

Yarden Regev

unread,
Mar 20, 2023, 10:24:09 AM3/20/23
to Protocol Buffers
Hello,
I am trying to transfer message from type loggerMessage from C to python over UART:
 
        status = pb_encode(&stream, loggerMessage_fields, &message);
        message_length = stream.bytes_written;
        int i=0;
        printf("\r\n");

        for (i = 0; i <message_length; ++i) {
           printf("%x",buffer[i]);
        }

In python when reading this and converting to binary, ParseFromString throws google.protobuf.message.DecodeError: Error parsing message:

    log = loggerMessage_pb2.loggerMessage()
    binary_str = binascii.unhexlify(answer)
    log.ParseFromString((binary_str))

What is the problem with the way I am sending/receiving?

Message has been deleted

Yarden Regev

unread,
Mar 20, 2023, 12:25:15 PM3/20/23
to Protocol Buffers
Note: after trying to encode the same structure through the python API (SerializeToString),  I noticed there was only a slight difference between the API's output and the output I get from the c file.
C:
a481e100102181201032d496d2053657269616c697a6564
API: 

0a04081e1000100218012010320d496d2053657269616c697a6564
As you can see there are some missing 0's, I would like to know what is wrong with the encoding I am doing on my C file

ב-יום שני, 20 במרץ 2023 בשעה 16:24:09 UTC+2, Yarden Regev כתב/ה:
Reply all
Reply to author
Forward
0 new messages