From 0b7904e18cad70e17a2dbed5f1362ccdc62fd385 Mon Sep 17 00:00:00 2001 From: Bo Yang Date: Tue, 19 Sep 2017 14:23:36 -0700 Subject: Reserve unknown fields in upb 1. For decoding, an unknownfields will be lazily created on message, which contains bytes of unknown fields. 2. For encoding, if the unknownfields is present on message, all bytes contained in it will be serialized. --- upb/pb/encoder.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'upb/pb/encoder.c') diff --git a/upb/pb/encoder.c b/upb/pb/encoder.c index b457867..b8e9191 100644 --- a/upb/pb/encoder.c +++ b/upb/pb/encoder.c @@ -374,6 +374,12 @@ static void *encode_startdelimfield(void *c, const void *hd) { return ok ? c : UPB_BREAK; } +static bool encode_unknown(void *c, const void *hd, const char *buf, + size_t len) { + UPB_UNUSED(hd); + return encode_bytes(c, buf, len) && commit(c); +} + static bool encode_enddelimfield(void *c, const void *hd) { UPB_UNUSED(hd); return end_delim(c); @@ -436,6 +442,7 @@ static void newhandlers_callback(const void *closure, upb_handlers *h) { upb_handlers_setstartmsg(h, startmsg, NULL); upb_handlers_setendmsg(h, endmsg, NULL); + upb_handlers_setunknown(h, encode_unknown, NULL); m = upb_handlers_msgdef(h); for(upb_msg_field_begin(&i, m); @@ -564,3 +571,9 @@ upb_pb_encoder *upb_pb_encoder_create(upb_env *env, const upb_handlers *h, } upb_sink *upb_pb_encoder_input(upb_pb_encoder *e) { return &e->input_; } + +void upb_pb_encoder_encode_unknown(upb_pb_encoder *p, const char *buf, + size_t size) { + encode_bytes(p, buf, size); + commit(p); +} -- cgit v1.2.3 From 69dee545ec95f55f271f5a51ac115deca4b484f9 Mon Sep 17 00:00:00 2001 From: Bo Yang Date: Tue, 19 Sep 2017 17:08:20 -0700 Subject: Remove upb_pb_encoder_encode_unknown --- upb/pb/encoder.c | 9 +-------- upb/pb/encoder.h | 4 ++-- 2 files changed, 3 insertions(+), 10 deletions(-) (limited to 'upb/pb/encoder.c') diff --git a/upb/pb/encoder.c b/upb/pb/encoder.c index b8e9191..3734710 100644 --- a/upb/pb/encoder.c +++ b/upb/pb/encoder.c @@ -374,8 +374,7 @@ static void *encode_startdelimfield(void *c, const void *hd) { return ok ? c : UPB_BREAK; } -static bool encode_unknown(void *c, const void *hd, const char *buf, - size_t len) { +bool encode_unknown(void *c, const void *hd, const char *buf, size_t len) { UPB_UNUSED(hd); return encode_bytes(c, buf, len) && commit(c); } @@ -571,9 +570,3 @@ upb_pb_encoder *upb_pb_encoder_create(upb_env *env, const upb_handlers *h, } upb_sink *upb_pb_encoder_input(upb_pb_encoder *e) { return &e->input_; } - -void upb_pb_encoder_encode_unknown(upb_pb_encoder *p, const char *buf, - size_t size) { - encode_bytes(p, buf, size); - commit(p); -} diff --git a/upb/pb/encoder.h b/upb/pb/encoder.h index 3d8dce1..780dfcb 100644 --- a/upb/pb/encoder.h +++ b/upb/pb/encoder.h @@ -64,8 +64,8 @@ const upb_handlers *upb_pb_encoder_newhandlers(const upb_msgdef *m, upb_sink *upb_pb_encoder_input(upb_pb_encoder *p); upb_pb_encoder* upb_pb_encoder_create(upb_env* e, const upb_handlers* h, upb_bytessink* output); -void upb_pb_encoder_encode_unknown(upb_pb_encoder* p, const char* buf, - size_t size); +bool encode_unknown(upb_pb_encoder* p, const void* hd, const char* buf, + size_t size); UPB_END_EXTERN_C -- cgit v1.2.3 From dd77460c65c6b053e7b2eb42249b988b9c9d7cba Mon Sep 17 00:00:00 2001 From: Bo Yang Date: Wed, 20 Sep 2017 16:14:49 -0700 Subject: Do not expose encode_unknown --- upb/pb/encoder.c | 3 ++- upb/pb/encoder.h | 2 -- 2 files changed, 2 insertions(+), 3 deletions(-) (limited to 'upb/pb/encoder.c') diff --git a/upb/pb/encoder.c b/upb/pb/encoder.c index 3734710..839ede0 100644 --- a/upb/pb/encoder.c +++ b/upb/pb/encoder.c @@ -374,7 +374,8 @@ static void *encode_startdelimfield(void *c, const void *hd) { return ok ? c : UPB_BREAK; } -bool encode_unknown(void *c, const void *hd, const char *buf, size_t len) { +static bool encode_unknown(void *c, const void *hd, const char *buf, + size_t len) { UPB_UNUSED(hd); return encode_bytes(c, buf, len) && commit(c); } diff --git a/upb/pb/encoder.h b/upb/pb/encoder.h index 780dfcb..41b7e7b 100644 --- a/upb/pb/encoder.h +++ b/upb/pb/encoder.h @@ -64,8 +64,6 @@ const upb_handlers *upb_pb_encoder_newhandlers(const upb_msgdef *m, upb_sink *upb_pb_encoder_input(upb_pb_encoder *p); upb_pb_encoder* upb_pb_encoder_create(upb_env* e, const upb_handlers* h, upb_bytessink* output); -bool encode_unknown(upb_pb_encoder* p, const void* hd, const char* buf, - size_t size); UPB_END_EXTERN_C -- cgit v1.2.3