From bda3269a42877ae0a0b2b44b579cba5b13d5b1de Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Mon, 12 Sep 2011 16:41:04 -0700 Subject: Fleshed out fielddef default functionality. Fixes unit test submitted by Hunter Morris (thanks!). --- upb/bytestream.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'upb/bytestream.c') 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); -- cgit v1.2.3