diff options
author | Joshua Haberman <jhaberman@gmail.com> | 2011-11-23 16:19:22 -0800 |
---|---|---|
committer | Joshua Haberman <jhaberman@gmail.com> | 2011-11-23 16:19:22 -0800 |
commit | b5f5ee867e6c91b77490dc8894236f17a47bde00 (patch) | |
tree | bb11d1e7881d27dfbcb8cef895be53812c57132e /upb/pb/glue.c | |
parent | 99ae0ed39723b9c8f97fbdde070681e2a8b7a20e (diff) |
Refinement of upb_bytesrc interface.
Added a upb_byteregion that tracks a region of
the input buffer; decoders use this instead of
using a upb_bytesrc directly. upb_byteregion
is also used as the way of passing a string to
a upb_handlers callback. This symmetry makes
decoders compose better; if you want to take
a parsed string and decode it as something else,
you can take the string directly from the callback
and feed it as input to another parser.
A commented-out version of a pinning interface
is present; I decline to actually implement it
(and accept its extra complexity) until/unless
it is clear that it is actually a win. But it
is included as a proof-of-concept, to show that
it fits well with the existing interface.
Diffstat (limited to 'upb/pb/glue.c')
-rw-r--r-- | upb/pb/glue.c | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/upb/pb/glue.c b/upb/pb/glue.c index 37b86d9..3176355 100644 --- a/upb/pb/glue.c +++ b/upb/pb/glue.c @@ -23,7 +23,7 @@ void upb_strtomsg(const char *str, size_t len, void *msg, const upb_msgdef *md, upb_accessors_reghandlers(h, md); upb_decoder_init(&d, h); upb_handlers_unref(h); - upb_decoder_reset(&d, upb_stringsrc_bytesrc(&strsrc), 0, UINT64_MAX, msg); + upb_decoder_reset(&d, upb_stringsrc_allbytes(&strsrc), msg); upb_decoder_decode(&d, status); upb_stringsrc_uninit(&strsrc); @@ -84,16 +84,19 @@ upb_def **upb_load_defs_from_descriptor(const char *str, size_t len, int *n, upb_handlers_unref(h); upb_descreader r; upb_descreader_init(&r); - upb_decoder_reset(&d, upb_stringsrc_bytesrc(&strsrc), 0, UINT64_MAX, &r); + upb_decoder_reset(&d, upb_stringsrc_allbytes(&strsrc), &r); upb_decoder_decode(&d, status); + upb_stringsrc_uninit(&strsrc); + upb_decoder_uninit(&d); + if (!upb_ok(status)) { + upb_descreader_uninit(&r); + return NULL; + } upb_def **defs = upb_descreader_getdefs(&r, n); upb_def **defscopy = malloc(sizeof(upb_def*) * (*n)); memcpy(defscopy, defs, sizeof(upb_def*) * (*n)); - upb_descreader_uninit(&r); - upb_stringsrc_uninit(&strsrc); - upb_decoder_uninit(&d); // Set default accessors and layouts on all messages. for(int i = 0; i < *n; i++) { |