aboutsummaryrefslogtreecommitdiffstats
path: root/pb_encode.c
diff options
context:
space:
mode:
authorPetteri Aimonen <jpa@npb.mail.kapsi.fi>2011-08-17 19:03:06 +0000
committerPetteri Aimonen <jpa@npb.mail.kapsi.fi>2011-08-17 19:03:06 +0000
commit7f53c3f7484679c1e38607f59542d43be1387650 (patch)
tree396198a24a1661eb7af87d0364a936d8df98a5ae /pb_encode.c
parent2cefaeaf61f38f1566293e53b4708e9ceff2d945 (diff)
Example
git-svn-id: https://svn.kapsi.fi/jpa/nanopb@957 e3a754e5-d11d-0410-8d38-ebb782a927b9
Diffstat (limited to 'pb_encode.c')
-rw-r--r--pb_encode.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/pb_encode.c b/pb_encode.c
index 188d768d..2e740347 100644
--- a/pb_encode.c
+++ b/pb_encode.c
@@ -130,7 +130,10 @@ bool pb_encode(pb_ostream_t *stream, const pb_field_t fields[], const void *src_
{
pData = (const char*)pData + prev_size + field->data_offset;
pSize = (const char*)pData + field->size_offset;
- prev_size = field->data_size * field->array_size;
+
+ prev_size = field->data_size;
+ if (PB_HTYPE(field->type) == PB_HTYPE_ARRAY)
+ prev_size *= field->array_size;
pb_encoder_t func = PB_ENCODERS[PB_LTYPE(field->type)];
@@ -339,7 +342,7 @@ bool pb_enc_submessage(pb_ostream_t *stream, const pb_field_t *field, const void
substream.max_size = size;
substream.bytes_written = 0;
- status = pb_encode(stream, (pb_field_t*)field->ptr, src);
+ status = pb_encode(&substream, (pb_field_t*)field->ptr, src);
stream->bytes_written += substream.bytes_written;