static bool checkreturn buf_write(pb_ostream_t *stream, const uint8_t *buf, size_t count)
{
uint8_t *dest = (uint8_t*)stream->state;
- memcpy(dest, buf, count);
stream->state = dest + count;
+
+ while (count--)
+ *dest++ = *buf++;
+
return true;
}
pb_ostream_t pb_ostream_from_buffer(uint8_t *buf, size_t bufsize)
{
pb_ostream_t stream;
+#ifdef PB_BUFFER_ONLY
+ stream.callback = (void*)1; /* Just some marker value */
+#else
stream.callback = &buf_write;
+#endif
stream.state = buf;
stream.max_size = bufsize;
stream.bytes_written = 0;
{
if (stream->bytes_written + count > stream->max_size)
return false;
-
+
+#ifdef PB_BUFFER_ONLY
+ if (!buf_write(stream, buf, count))
+ return false;
+#else
if (!stream->callback(stream, buf, count))
return false;
+#endif
}
stream->bytes_written += count;
pSize = (const char*)pData + field->size_offset;
prev_size = field->data_size;
- if (PB_HTYPE(field->type) == PB_HTYPE_ARRAY)
+ if (PB_HTYPE(field->type) == PB_HTYPE_REPEATED)
prev_size *= field->array_size;
switch (PB_HTYPE(field->type))
}
break;
- case PB_HTYPE_ARRAY:
+ case PB_HTYPE_REPEATED:
if (!encode_array(stream, field, pData, *(const size_t*)pSize, func))
return false;
break;