Hi,
> and we dont know how large this repeated field is, therefore I define a
> *field-callback* for SampleMessage.val_bytes.
So, something like:
static bool field_callback(pb_istream_t *stream,
const pb_field_t *field, void **arg);
> On the otherhand I defined a *stream-callback* like the following:
> pb_istream_t stream = {&read_callback, (void*)(intptr_t)fd, SIZE_MAX};
You will be given this stream in your field callback (look at the args).
Except for one thing: the bytes_left value will be modified by nanopb
to the length of the field data, i.e. the field callback cannot read
past the end of the field.
> Or is the stream-callback just called to collect some data, then the
> field-callback is called to process this data, then again the
> stream-callback is called to collect more data, then again the
> field-callback and so forth.
It actually will depend on your field callback. It reads the data by
calling pb_read(). If it doesn't read all of it, it will be called again
by nanopb until all data is consumed. But protobuf arrays are not
necessarily contiguous, so it may be called multiple times even if it
does read all the available data.
--
Petteri