I am having an issue unpacking a repeated message. The The below code is only representative, but mimics exactly what i have in the official work. The first callback works just fine, but never gets called a second time, and ends up returning false from the initial pb_decode . I know that the message contains more than one subMessage, and that it is being packed correctly, because the i can decode the entire packet in a python application.
I am not seeing any error messages. Any advice or suggestions would be greatly appreciated.
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Requires libprotoc > 3.0 to compile.
syntax = "proto3";
/// ******************************
///
/// ******************************
message Triangle {
int64_t x = 1;
int64_t y = 1;
int64_t z = 1;
}
/// ******************************
///
/// ******************************
message SubMessage {
/// Indicates if the solution contained in this message is valid.
bool solution_valid = 1;
/// Time of the solution, in nanoseconds since 00:00 January 6, 1980 UTC.
/// Unit: nanoseconds
int64 t_solution_ns = 2;
/// Unique identifier.
int64 id = 3;
///
Triangle a = 4;
///
Triangle b = 5;
}
/// ******************************
/// Collection
/// ******************************
message MyMessage
repeated SubMessage = 1;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
void processMessage()
{
...
uint8_t buffer[MESSAGE_LENGTH];
memcpy(buffer, message.getData(), messageLength);
pb_istream_t stream = pb_istream_from_buffer((const pb_byte_t *)buffer, messageLength);
MyMessage protoMessage = MyMessage_init_zero
protoMessage.SubMessage.funcs.decode = sub_decode;
if (!pb_decode(&stream, MyMessage_fields, &protoMessage))
{
errorCount++
return;
}
...
}
static bool sub_decode(pb_istream_t *stream, const pb_field_t *field, void **arg) {
int x = stream->bytes_left;
SubMessage sMessage = SubMessage_init_zero;
if (stream->bytes_left > sizeof(SubMessage) - 1)
{
return false;
}
bool result = pb_decode(stream, SubMessage_fields, &sMessage);
return result;
}