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/descriptor.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/descriptor.c')
-rw-r--r-- | upb/descriptor.c | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/upb/descriptor.c b/upb/descriptor.c index 39ed6da..0c589f2 100644 --- a/upb/descriptor.c +++ b/upb/descriptor.c @@ -123,7 +123,8 @@ static upb_flow_t upb_descreader_FileDescriptorProto_package(void *_r, upb_value val) { (void)fval; upb_descreader *r = _r; - upb_descreader_setscopename(r, upb_strref_dup(upb_value_getstrref(val))); + upb_descreader_setscopename( + r, upb_byteregion_strdup(upb_value_getbyteregion(val))); return UPB_CONTINUE; } @@ -180,7 +181,7 @@ static upb_flow_t upb_enumdef_EnumValueDescriptorProto_name(void *_r, (void)fval; upb_descreader *r = _r; free(r->name); - r->name = upb_strref_dup(upb_value_getstrref(val)); + r->name = upb_byteregion_strdup(upb_value_getbyteregion(val)); r->saw_name = true; return UPB_CONTINUE; } @@ -259,7 +260,7 @@ static upb_flow_t upb_enumdef_EnumDescriptorProto_name(void *_r, upb_descreader *r = _r; upb_enumdef *e = upb_downcast_enumdef(upb_descreader_last(r)); free(e->base.fqname); - e->base.fqname = upb_strref_dup(upb_value_getstrref(val)); + e->base.fqname = upb_byteregion_strdup(upb_value_getbyteregion(val)); return UPB_CONTINUE; } @@ -423,7 +424,7 @@ static upb_flow_t upb_fielddef_onnumber(void *_r, upb_value fval, upb_value val) static upb_flow_t upb_fielddef_onname(void *_r, upb_value fval, upb_value val) { (void)fval; upb_descreader *r = _r; - char *name = upb_strref_dup(upb_value_getstrref(val)); + char *name = upb_byteregion_strdup(upb_value_getbyteregion(val)); upb_fielddef_setname(r->f, name); free(name); return UPB_CONTINUE; @@ -433,7 +434,7 @@ static upb_flow_t upb_fielddef_ontypename(void *_r, upb_value fval, upb_value val) { (void)fval; upb_descreader *r = _r; - char *name = upb_strref_dup(upb_value_getstrref(val)); + char *name = upb_byteregion_strdup(upb_value_getbyteregion(val)); upb_fielddef_settypename(r->f, name); free(name); return UPB_CONTINUE; @@ -446,7 +447,7 @@ static upb_flow_t upb_fielddef_ondefaultval(void *_r, upb_value fval, // Have to convert from string to the correct type, but we might not know the // type yet. free(r->default_string); - r->default_string = upb_strref_dup(upb_value_getstrref(val)); + r->default_string = upb_byteregion_strdup(upb_value_getbyteregion(val)); return UPB_CONTINUE; } @@ -499,7 +500,7 @@ static upb_flow_t upb_msgdef_onname(void *_r, upb_value fval, upb_value val) { assert(val.type == UPB_TYPE(STRING)); upb_msgdef *m = upb_descreader_top(r); free(m->base.fqname); - m->base.fqname = upb_strref_dup(upb_value_getstrref(val)); + m->base.fqname = upb_byteregion_strdup(upb_value_getbyteregion(val)); upb_descreader_setscopename(r, strdup(m->base.fqname)); return UPB_CONTINUE; } |