我目前正在尝试使用 nanopb 序列化字符串并在 python/java 中解码消息。我没有麻烦的整数,我可以序列化和反序列化。但是当涉及到字符串时,我不断收到同样的错误:'utf-8' codec can't decode byte 0xff in position 2: 'utf-8' codec can't decode byte 0xff in position 2: invalid start byte in场地:
我认为这可能是 Python 解码问题,所以我修改
with open('FileSerialized.bin', 'rb') as f:
:
with open('FileSerialized.bin', encode='utf-8') as f:
我尝试使用 Java 中的解析器,但它给出了同样的错误。因此,我认为问题在于我在 C 中编码消息的方式。我正在执行以下操作:
在 nanopb 提供了 .proto 的转换之后:
typedef struct _ProtoExample {
int32_t Value1; //this is deserialized correctly
char Value2[6]; //here is where I have trouble
}
我尝试通过执行以下操作来填充 char 数组:
pb_ostream_t stream = pb_ostream_from_buffer( buffer, BUFFER_SIZE );
ProtoExample Message;
Message.Value1= S_generalConfig_s.EntityType;
Message.Value2[0] = 'a';
pb_encode( &stream, ProtoExample _fields, &Message);
尝试解码后,我在尝试读取 Value2 时发现错误。