summaryrefslogtreecommitdiff
path: root/upb/pb/encoder.c
diff options
context:
space:
mode:
authorBo Yang <teboring@google.com>2017-09-19 14:23:36 -0700
committerBo Yang <teboring@google.com>2017-09-19 14:23:36 -0700
commit0b7904e18cad70e17a2dbed5f1362ccdc62fd385 (patch)
treee94665631c7437d1bebb62b9a45f0c1be1f21d81 /upb/pb/encoder.c
parentae30b4a816a57a8101ce187245edc3050d515c06 (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/pb/encoder.c')
-rw-r--r--upb/pb/encoder.c13
1 files changed, 13 insertions, 0 deletions
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);
+}
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback