diff options
author | Petteri Aimonen <jpa@git.mail.kapsi.fi> | 2015-01-04 19:39:37 +0200 |
---|---|---|
committer | Petteri Aimonen <jpa@git.mail.kapsi.fi> | 2015-01-04 19:39:37 +0200 |
commit | 7713d43bc3d448358a04393c4e44dd12a768bdea (patch) | |
tree | 140573b1d78947739e5f46721d681a580a4d3030 /pb_decode.c | |
parent | a0f0440394ac3b38105dfad09366f95011c5d8d3 (diff) |
Implement support for oneofs (C unions).
Basic test included, should probably add an oneof to the AllTypes test also.
Update issue 131
Status: Started
Diffstat (limited to 'pb_decode.c')
-rw-r--r-- | pb_decode.c | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/pb_decode.c b/pb_decode.c index 5982c8e5..542fdc4c 100644 --- a/pb_decode.c +++ b/pb_decode.c @@ -393,6 +393,10 @@ static bool checkreturn decode_static_field(pb_istream_t *stream, pb_wire_type_t return func(stream, iter->pos, pItem); } + case PB_HTYPE_ONEOF: + *(pb_size_t*)iter->pSize = iter->pos->tag; + return func(stream, iter->pos, iter->pData); + default: PB_RETURN_ERROR(stream, "invalid field type"); } @@ -470,6 +474,7 @@ static bool checkreturn decode_pointer_field(pb_istream_t *stream, pb_wire_type_ { case PB_HTYPE_REQUIRED: case PB_HTYPE_OPTIONAL: + case PB_HTYPE_ONEOF: if (PB_LTYPE(type) == PB_LTYPE_SUBMESSAGE && *(void**)iter->pData != NULL) { @@ -477,6 +482,11 @@ static bool checkreturn decode_pointer_field(pb_istream_t *stream, pb_wire_type_ pb_release_single_field(iter); } + if (PB_HTYPE(type) == PB_HTYPE_ONEOF) + { + *(pb_size_t*)iter->pSize = iter->pos->tag; + } + if (PB_LTYPE(type) == PB_LTYPE_STRING || PB_LTYPE(type) == PB_LTYPE_BYTES) { @@ -562,7 +572,7 @@ static bool checkreturn decode_pointer_field(pb_istream_t *stream, pb_wire_type_ initialize_pointer_field(pItem, iter); return func(stream, iter->pos, pItem); } - + default: PB_RETURN_ERROR(stream, "invalid field type"); } |