From a105c015b106b6be31fc45fdd4c568684815801c Mon Sep 17 00:00:00 2001 From: Josh Haberman Date: Thu, 6 Sep 2018 23:16:58 -0700 Subject: Added support for unknown fields to upb_msg. After this CL, upb passes all existing proto3 conformance tests. However the conformance suite is missing a lot of cases and should be fleshed out. --- upb/encode.c | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'upb/encode.c') diff --git a/upb/encode.c b/upb/encode.c index a9f2c0d..bff8262 100644 --- a/upb/encode.c +++ b/upb/encode.c @@ -331,6 +331,8 @@ bool upb_encode_message(upb_encstate *e, const char *msg, const upb_msglayout *m, size_t *size) { int i; size_t pre_len = e->limit - e->ptr; + const char *unknown; + size_t unknown_size; for (i = m->field_count - 1; i >= 0; i--) { const upb_msglayout_field *f = &m->fields[i]; @@ -357,6 +359,12 @@ bool upb_encode_message(upb_encstate *e, const char *msg, } } + unknown = upb_msg_getunknown(msg, &unknown_size); + + if (unknown) { + upb_put_bytes(e, unknown, unknown_size); + } + *size = (e->limit - e->ptr) - pre_len; return true; } -- cgit v1.2.3