Encoding failed: bytes size exceeded

458 views
Skip to first unread message

tapio.ha...@gmail.com

unread,
Jun 27, 2014, 11:04:06 AM6/27/14
to nan...@googlegroups.com
Now I have managed to resolve all decoding problems what I had and I have moved to encoding part.

I have proto:

message TempInfo
{
optional bytes SensorAddr = 1;
optional float Temp = 2;
optional bytes SensorRawData = 3;
}

and options:
TempInfo.SensorAddr max_size:8
TempInfo.SensorRawData max_size:9

and Code:

TempInfo tempinfo;
uint8_t buffer[128];
pb_ostream_t stream = pb_ostream_from_buffer(buffer, sizeof(buffer));
copyByteArray(addr,tempinfo.SensorAddr.bytes,8);
copyByteArray(data,tempinfo.SensorRawData.bytes,9);
tempinfo.Temp = tempVal;

bool status = pb_encode(&stream, TempInfo_fields, &tempinfo);
size_t message_length = stream.bytes_written;


I tried that I comment out field filling lines and looks that I can fill only one of byte array fields. All other fields cause Encoding failed: bytes size exceeded.
Even that tempinfo.Temp = tempVal; without byte array fills cause this error. tempVal is positive float.

Is this some kind arduino compatibility problem or did I do something wrong?

Petteri Aimonen

unread,
Jun 27, 2014, 12:16:47 PM6/27/14
to nan...@googlegroups.com
Hi,

> copyByteArray(addr,tempinfo.SensorAddr.bytes,8);

You need to set tempinfo.SensorAddr.size also. The options file only
sets the maximum size, the actual size can also be smaller and must be
set at runtime.

--
Petteri

tapio.ha...@gmail.com

unread,
Jun 27, 2014, 1:14:13 PM6/27/14
to nan...@googlegroups.com, tapio.ha...@gmail.com

Looks that I must set tempinfo.SensorAddr.size = 8; manually. with sizeof(tempinfo.SensorAddr) it shows right 8 bytes but tempinfo.SensorAddr.size was something > 300.

Reply all
Reply to author
Forward
0 new messages