0

I'm communicating between embedded device that uses nanopb and desktop PC that uses protobuf-c, but get an error when parsing encoded message. Embedded device sends a message, "Response" with an optional field that is of a different message type (ResponseContent). The other message has required fields. Here's the message defenition

syntax = "proto2";

package Message;

message Response
{
    enum RESPONSE_TYPES
    {
        OK = 0;
        ERROR = 1;
        BUSY = 2;
        STATUS = 3;
    }

    required RESPONSE_TYPES type = 1;
    optional ResponseContent response_content = 2;
}

message ResponseContent
{
    enum CONTENT_TYPES
    {
        DIN = 0;
        DOUT = 1;
        AIN = 2;
        AOUT = 3;
    }

    required CONTENT_TYPES type = 1;

    oneof result
    {
        Din din = 21;
        Dout dout = 22;
        Ain ain = 23;
        Aout aout = 24;
    }

}

message Din
{
    required bool state = 1;
}
message Dout
{
    required bool ack = 1;
}
message Ain
{
    required float val = 1;
}
message Aout
{
    required bytes payload = 1;
}

Why does error "missing required fields" pop up when ResponseContent type in Response message is optional, and has_response_content parameter set to false? note: obviously this happens with *bool ParseFromArray(const void * data, int size)* and not with *bool ParsePartialFromArray(const void * data, int size)*

dimipage
  • 1
  • 2
  • 1
    You'll need to include more info, such as hex dump of the data. Alternatively, you can try decoding it yourself with `protoc --decode_raw` or https://protogen.marcgravell.com/decode – jpa Jan 20 '20 at 15:57
  • I've edited the question with more info – dimipage Jan 21 '20 at 13:54
  • 1
    That edit does not really help much. It would be more useful to include the actual data you are trying to decode. After that we can determine whether the problem is on the encoding or on the decoding side, and continue debugging from there. – jpa Jan 21 '20 at 14:02

0 Answers0