Hi,
> I was wondering how difficult it would be to update nanopb to use this
> intrinsic to pack data into the uint16_t array that I create for the stream?
Easiest way would be to make a custom output stream function.
The stream write function has to copy the data to output array anyway, so
it could pack it in progress.
https://jpa.kapsi.fi/nanopb/docs/concepts.html#streams
Something like this (untested):
pb_ostream_t create_ostream16(uint16_t *buf, size_t bufsize)
{
pb_ostream_t result;
result.callback = write_ostream16;
result.state = buf;
result.max_size = bufsize;
result.bytes_written = 0;
result.errmsg = NULL;
return result;
}
bool write_ostream16(pb_ostream_t *stream, const pb_byte_t *buf, size_t count)
{
uint16_t *dest = stream.state & ~1;
bool odd = stream.state & 1;
/* TODO: Copy "count" bytes from buf into dest, doing whatever is
* needed to handle any odd bytes at beginning and end.
*/
stream->state += count;
return true;
}
--
Petteri