repeated fields in a message

309 views
Skip to first unread message

eman.n...@gmail.com

unread,
Jun 24, 2019, 11:18:57 AM6/24/19
to nanopb
Hello guys,
I am trying to use the NanoProtoBuffer in a project and I need to send over the bus an array of structures (with a known size). Everything goes well until I try to encode such message. The fields of the array are not written into the message by calling the pb_encode function (it returns True and a message length of 5).

What am I missing or doing wrong? Thank you!

simple.proto:
syntax = "proto2";

message repField {
required float x = 1;
required float y = 2;
required float z = 3;
}

message SimpleMessage {
required float lucky_number = 1;
repeated repField vector = 2;
}

simple.options:

SimpleMessage.vector max_count:300


simple.c:
-----
SimpleMessage message = SimpleMessage_init_zero;

pb_ostream_t stream = pb_ostream_from_buffer(buffer, sizeof(buffer));

message.lucky_number = 234.567;
for(i=0;i<300;i++){
message.vector[i].x = i;
message.vector[i].y = i;
message.vector[i].z = i;
}
status = pb_encode(&stream, SimpleMessage_fields, &message);

Petteri Aimonen

unread,
Jun 25, 2019, 2:56:46 AM6/25/19
to nan...@googlegroups.com
Hi,

> SimpleMessage message = SimpleMessage_init_zero;
>
> pb_ostream_t stream = pb_ostream_from_buffer(buffer, sizeof(buffer));
>
> message.lucky_number = 234.567;
> for(i=0;i<300;i++){
> message.vector[i].x = i;
> message.vector[i].y = i;
> message.vector[i].z = i;
> }
> status = pb_encode(&stream, SimpleMessage_fields, &message);

Try adding message.vector_count = 300

--
Petteri
Message has been deleted

eman.n...@gmail.com

unread,
Jun 25, 2019, 5:53:17 AM6/25/19
to nanopb

Thanks! It worked. I also found the fixed_count parameter. The documentation was a bit unclear for me and therefore I got confused.

I am sorry if I annoyed you by posting the same question on stackoverflow (https://stackoverflow.com/q/56739667/2506817) but I have a friend that wanted to help me and posted my message there as well.

I appreciate that you took your time to reply and if you are willing I can ask my friend to delete the other post.

Nicolae.

Reply all
Reply to author
Forward
0 new messages