diff options
author | Joshua Haberman <jhaberman@gmail.com> | 2011-09-12 16:41:04 -0700 |
---|---|---|
committer | Joshua Haberman <jhaberman@gmail.com> | 2011-09-12 16:41:04 -0700 |
commit | bda3269a42877ae0a0b2b44b579cba5b13d5b1de (patch) | |
tree | 60bc46bda5615b93f59cf129bd3089f38be4ba3d /upb/bytestream.c | |
parent | 7175edb10a51e5931efd14cdb8cf62ce3463c85e (diff) |
Fleshed out fielddef default functionality.
Fixes unit test submitted by Hunter Morris (thanks!).
Diffstat (limited to 'upb/bytestream.c')
-rw-r--r-- | upb/bytestream.c | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/upb/bytestream.c b/upb/bytestream.c index 36be4b1..86095f9 100644 --- a/upb/bytestream.c +++ b/upb/bytestream.c @@ -21,6 +21,24 @@ char *upb_strref_dup(const struct _upb_strref *r) { return ret; } +upb_strref *upb_strref_new(const char *str) { + return upb_strref_newl(str, strlen(str)); +} + +upb_strref *upb_strref_newl(const void *str, size_t len) { + upb_strref *s = malloc(sizeof(*s)); + s->bytesrc = NULL; + s->ptr = malloc(len); + memcpy((void*)s->ptr, str, len); + return s; +} + +void upb_strref_free(upb_strref *ref) { + if (!ref) return; + free((char*)ref->ptr); + free(ref); +} + void upb_bytesink_init(upb_bytesink *sink, upb_bytesink_vtbl *vtbl) { sink->vtbl = vtbl; upb_status_init(&sink->status); |