Im trying to implement nanopb on a esp8266 and I'm having a problem accessing the submessage members to assign a decode function
Here is the relevant portion of my proto file
message Payload {
message Metric {
optional string tagname = 1; // Metric name - should only be included on birth
optional uint64 alias = 2; // Metric alias - tied to name on birth and included in all later DATA messages
optional uint64 timestamp = 3; // Timestamp associated with data acquisition time
optional uint32 datatype = 4; // DataType of the metric/tag value
optional bool is_historical = 5; // If this is historical data and should not update real time tag
optional bool is_transient = 6; // Tells consuming clients such as MQTT Engine to not store this as a tag
optional bool is_null = 7; // If this is null - explicitly say so rather than using -1, false, etc for some datatypes.
optional MetaData metadata = 8; // Metadata for the payload
optional PropertySet properties = 9;
oneof value {
uint32 int_value = 10;
uint64 long_value = 11;
float float_value = 12;
double double_value = 13;
bool boolean_value = 14;
string string_value = 15;
bytes bytes_value = 16; // Bytes, File
DataSet dataset_value = 17;
Template template_value = 18;
MetricValueExtension extension_value = 19;
}
.....
repeated Metric metrics = 2
}
So Metric is a submessage of Payload. This is the code where I initialize my message and do the decoding
Payload test_payload = Payload_init_zero;
pb_istream_t stream = pb_istream_from_buffer(payload, length);
test_payload.metrics.funcs.decode = metrics_decode;
test_payload.metrics.tagname.funcs.decode = print_string;
If I attempt to assign the decode function here as Petteri does in his decode examples
Then the arduino compiler gives me the following error
mqtt_esp8266:104:24: error: 'pb_callback_t' has no member named 'tagname'
test_payload.metrics.tagname.funcs.decode = print_string;
However, if I do the same in my metrics_decode callback function I don't get any errors
bool metrics_decode(pb_istream_t *stream, const pb_field_t *field, void** args) {
Serial.println("metrics decode executed");
String tagname;
Payload_Metric payload_metrics = Payload_Metric_init_zero;
payload_metrics.tagname.funcs.decode = print_string;
.
.
.
}
Is this the correct way to decode submessages? Assigning the function pointers inside the callback of the parent message? Based on the example I must be doing something wrong but I'm confused as to why it would recognize that tagname is a field at one level but not another.