diff options
author | Bo Yang <teboring@google.com> | 2017-09-19 14:23:36 -0700 |
---|---|---|
committer | Bo Yang <teboring@google.com> | 2017-09-19 14:23:36 -0700 |
commit | 0b7904e18cad70e17a2dbed5f1362ccdc62fd385 (patch) | |
tree | e94665631c7437d1bebb62b9a45f0c1be1f21d81 /upb/sink.h | |
parent | ae30b4a816a57a8101ce187245edc3050d515c06 (diff) |
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.
Diffstat (limited to 'upb/sink.h')
-rw-r--r-- | upb/sink.h | 12 |
1 files changed, 12 insertions, 0 deletions
@@ -315,6 +315,18 @@ UPB_INLINE size_t upb_sink_putstring(upb_sink *s, upb_selector_t sel, return handler(s->closure, hd, buf, n, handle); } +UPB_INLINE bool upb_sink_putunknown(upb_sink *s, const char *buf, size_t n) { + typedef upb_unknown_handlerfunc func; + func *handler; + const void *hd; + if (!s->handlers) return true; + handler = (func *)upb_handlers_gethandler(s->handlers, UPB_UNKNOWN_SELECTOR); + + if (!handler) return n; + hd = upb_handlers_gethandlerdata(s->handlers, UPB_UNKNOWN_SELECTOR); + return handler(s->closure, hd, buf, n); +} + UPB_INLINE bool upb_sink_startmsg(upb_sink *s) { typedef upb_startmsg_handlerfunc func; func *startmsg; |