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/handlers.h | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'upb/handlers.h') diff --git a/upb/handlers.h b/upb/handlers.h index 54a3c1c..0f28f19 100644 --- a/upb/handlers.h +++ b/upb/handlers.h @@ -104,7 +104,8 @@ UPB_END_EXTERN_C /* Static selectors for upb::Handlers. */ #define UPB_STARTMSG_SELECTOR 0 #define UPB_ENDMSG_SELECTOR 1 -#define UPB_STATIC_SELECTOR_COUNT 2 +#define UPB_UNKNOWN_SELECTOR 2 +#define UPB_STATIC_SELECTOR_COUNT 3 /* Static selectors for upb::BytesHandler. */ #define UPB_STARTSTR_SELECTOR 0 @@ -633,6 +634,10 @@ UPB_BEGIN_EXTERN_C /* Native C API. */ /* Handler function typedefs. */ +typedef bool upb_addunknown_handlerfunc(void *c, const void *hd, + const char *buf, size_t n); +typedef bool upb_unknown_handlerfunc(void *c, const void *hd, const char *buf, + size_t n); typedef bool upb_startmsg_handlerfunc(void *c, const void*); typedef bool upb_endmsg_handlerfunc(void *c, const void *, upb_status *status); typedef void* upb_startfield_handlerfunc(void *c, const void *hd); @@ -686,6 +691,11 @@ const upb_status *upb_handlers_status(upb_handlers *h); void upb_handlers_clearerr(upb_handlers *h); const upb_msgdef *upb_handlers_msgdef(const upb_handlers *h); bool upb_handlers_addcleanup(upb_handlers *h, void *p, upb_handlerfree *hfree); +bool upb_handlers_setaddunknown(upb_handlers *h, + upb_addunknown_handlerfunc *func, + upb_handlerattr *attr); +bool upb_handlers_setunknown(upb_handlers *h, upb_unknown_handlerfunc *func, + upb_handlerattr *attr); bool upb_handlers_setstartmsg(upb_handlers *h, upb_startmsg_handlerfunc *func, upb_handlerattr *attr); -- cgit v1.2.3 From dc9d15084fa02c69c277cd730862e49ec10cd38e Mon Sep 17 00:00:00 2001 From: Bo Yang Date: Tue, 19 Sep 2017 16:22:32 -0700 Subject: Remove upb_addunknown_handlerfunc and upb_handlers_setaddunknown --- upb/handlers.c | 7 ------- upb/handlers.h | 3 --- upb/pb/decoder.c | 4 ++-- 3 files changed, 2 insertions(+), 12 deletions(-) (limited to 'upb/handlers.h') diff --git a/upb/handlers.c b/upb/handlers.c index b9dc8f3..8799ed0 100644 --- a/upb/handlers.c +++ b/upb/handlers.c @@ -372,13 +372,6 @@ SETTER(endseq, upb_endfield_handlerfunc*, UPB_HANDLER_ENDSEQ) #undef SETTER -bool upb_handlers_setaddunknown(upb_handlers *h, - upb_addunknown_handlerfunc *func, - upb_handlerattr *attr) { - return doset(h, UPB_UNKNOWN_SELECTOR, NULL, UPB_HANDLER_INT32, - (upb_func *)func, attr); -} - bool upb_handlers_setunknown(upb_handlers *h, upb_unknown_handlerfunc *func, upb_handlerattr *attr) { return doset(h, UPB_UNKNOWN_SELECTOR, NULL, UPB_HANDLER_INT32, diff --git a/upb/handlers.h b/upb/handlers.h index 0f28f19..33cdf86 100644 --- a/upb/handlers.h +++ b/upb/handlers.h @@ -691,9 +691,6 @@ const upb_status *upb_handlers_status(upb_handlers *h); void upb_handlers_clearerr(upb_handlers *h); const upb_msgdef *upb_handlers_msgdef(const upb_handlers *h); bool upb_handlers_addcleanup(upb_handlers *h, void *p, upb_handlerfree *hfree); -bool upb_handlers_setaddunknown(upb_handlers *h, - upb_addunknown_handlerfunc *func, - upb_handlerattr *attr); bool upb_handlers_setunknown(upb_handlers *h, upb_unknown_handlerfunc *func, upb_handlerattr *attr); diff --git a/upb/pb/decoder.c b/upb/pb/decoder.c index 79142bf..32509b5 100644 --- a/upb/pb/decoder.c +++ b/upb/pb/decoder.c @@ -543,7 +543,7 @@ UPB_NOINLINE int32_t upb_pbdecoder_checktag_slow(upb_pbdecoder *d, int32_t upb_pbdecoder_skipunknown(upb_pbdecoder *d, int32_t fieldnum, uint8_t wire_type) { - upb_addunknown_handlerfunc *addunknown; + upb_unknown_handlerfunc *addunknown; const void* hd; if (fieldnum >= 0) @@ -599,7 +599,7 @@ have_tag: } if (d->top->groupnum >= 0) { - addunknown = (upb_addunknown_handlerfunc *)upb_handlers_gethandler( + addunknown = (upb_unknown_handlerfunc *)upb_handlers_gethandler( (d->top->sink).handlers, UPB_UNKNOWN_SELECTOR); if (addunknown != NULL) { hd = upb_handlers_gethandlerdata((d->top->sink).handlers, -- cgit v1.2.3 From 6b4e07cc1856f720ab9e5f419d32546c11869bb4 Mon Sep 17 00:00:00 2001 From: Bo Yang Date: Tue, 19 Sep 2017 16:48:23 -0700 Subject: Remove upb_addunknown_handlerfunc --- upb/handlers.h | 2 -- 1 file changed, 2 deletions(-) (limited to 'upb/handlers.h') diff --git a/upb/handlers.h b/upb/handlers.h index 33cdf86..993af13 100644 --- a/upb/handlers.h +++ b/upb/handlers.h @@ -634,8 +634,6 @@ UPB_BEGIN_EXTERN_C /* Native C API. */ /* Handler function typedefs. */ -typedef bool upb_addunknown_handlerfunc(void *c, const void *hd, - const char *buf, size_t n); typedef bool upb_unknown_handlerfunc(void *c, const void *hd, const char *buf, size_t n); typedef bool upb_startmsg_handlerfunc(void *c, const void*); -- cgit v1.2.3