From 7713d43bc3d448358a04393c4e44dd12a768bdea Mon Sep 17 00:00:00 2001 From: Petteri Aimonen Date: Sun, 4 Jan 2015 19:39:37 +0200 Subject: Implement support for oneofs (C unions). Basic test included, should probably add an oneof to the AllTypes test also. Update issue 131 Status: Started --- pb_common.c | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'pb_common.c') diff --git a/pb_common.c b/pb_common.c index a9cade63..98964850 100644 --- a/pb_common.c +++ b/pb_common.c @@ -54,6 +54,13 @@ bool pb_field_iter_next(pb_field_iter_t *iter) * The data_size only applies to the dynamically allocated area. */ prev_size = sizeof(void*); } + else if (PB_HTYPE(prev_field->type) == PB_HTYPE_ONEOF && + PB_HTYPE(iter->pos->type) == PB_HTYPE_ONEOF) + { + /* Don't advance pointers inside unions */ + prev_size = 0; + iter->pData = (char*)iter->pData - prev_field->data_offset; + } if (PB_HTYPE(prev_field->type) == PB_HTYPE_REQUIRED) { -- cgit 1.2.3-korg