I am having an issue with nanopb, unsure if it is a bug or just my incorrect usage.
I have a oneof message, and at the decode step, the decode callback function is not getting called at all for the message inside the oneof, but it is getting called for the same message structure that is present again outside of the oneof statement.
I am using an example proto file setup like this (simple example to reproduce this issue):
syntax = "proto2";
import 'nanopb.proto';
message TestMessage {
message TestType1 {
required int32 test_int = 1;
required string test_str = 2;
}
message TestType2 {
required string test_str = 3;
}
oneof message {
TestType1 test_type_1 = 4;
TestType2 test_type_2 = 5;
};
required TestType1 test_outside = 6;
}
I am setting up the decode callbacks with:
proto_msg.message.test_type_1.test_str.funcs.decode = print_string;
proto_msg.message.test_type_1.test_str.arg = "stringvalue: \"%s\"\n";
proto_msg.message.test_type_2.test_str.funcs.decode = print_string;
proto_msg.message.test_type_2.test_str.arg = "stringvalue: \"%s\"\n";
proto_msg.test_outside.test_str.funcs.decode = print_string;
proto_msg.test_outside.test_str.arg = "stringvalue: \"%s\"\n";
Any my decode step is getting called with:
status = pb_decode(&stream, TestMessage_fields, &proto_msg);
But only the string in test_outside.test_str is getting printed, and print_string is only called once.
However, I know the data is encoded correctly, as the same binary decodes correctly with the nanopb-generated python module.
Is this a usage error or a bug?
A complete test program (which also does bin-to-hex and hex-to-bin conversion, because my real application uses it, but also this lets me copy&paste into python test) is attached, along with the proto file.