summaryrefslogtreecommitdiff
path: root/upb/msg.c
diff options
context:
space:
mode:
authorJoshua Haberman <jhaberman@gmail.com>2011-11-23 16:19:22 -0800
committerJoshua Haberman <jhaberman@gmail.com>2011-11-23 16:19:22 -0800
commitb5f5ee867e6c91b77490dc8894236f17a47bde00 (patch)
treebb11d1e7881d27dfbcb8cef895be53812c57132e /upb/msg.c
parent99ae0ed39723b9c8f97fbdde070681e2a8b7a20e (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/msg.c')
-rw-r--r--upb/msg.c11
1 files changed, 6 insertions, 5 deletions
diff --git a/upb/msg.c b/upb/msg.c
index 87bb61b..78309cf 100644
--- a/upb/msg.c
+++ b/upb/msg.c
@@ -151,13 +151,14 @@ static void _upb_stdmsg_setstr(void *_dst, upb_value src) {
*dstp = dst;
}
dst->len = 0;
- const upb_strref *ref = upb_value_getstrref(src);
- if (ref->len > dst->size) {
- dst->size = ref->len;
+ const upb_byteregion *bytes = upb_value_getbyteregion(src);
+ uint32_t len = upb_byteregion_len(bytes);
+ if (len > dst->size) {
+ dst->size = len;
dst->ptr = realloc(dst->ptr, dst->size);
}
- dst->len = ref->len;
- upb_bytesrc_read(ref->bytesrc, ref->stream_offset, ref->len, dst->ptr);
+ dst->len = len;
+ upb_byteregion_copyall(bytes, dst->ptr);
}
upb_flow_t upb_stdmsg_setstr(void *_m, upb_value fval, upb_value val) {
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback