void stringsink_init(stringsink *sink) { upb_byteshandler_init(&sink->handler); upb_byteshandler_setstartstr(&sink->handler, stringsink_start, NULL); upb_byteshandler_setstring(&sink->handler, stringsink_string, NULL); upb_bytessink_reset(&sink->sink, &sink->handler, sink); sink->size = 32; sink->ptr = malloc(sink->size); sink->len = 0; }
static upb_pbdecodermethod *newmethod(const upb_handlers *dest_handlers, mgroup *group) { static const struct upb_refcounted_vtbl vtbl = {visitmethod, freemethod}; upb_pbdecodermethod *ret = malloc(sizeof(*ret)); upb_refcounted_init(UPB_UPCAST(ret), &vtbl, &ret); upb_byteshandler_init(&ret->input_handler_); // The method references the group and vice-versa, in a circular reference. upb_ref2(ret, group); upb_ref2(group, ret); upb_inttable_insertptr(&group->methods, dest_handlers, upb_value_ptr(ret)); upb_refcounted_unref(UPB_UPCAST(ret), &ret); ret->group = UPB_UPCAST(group); ret->dest_handlers_ = dest_handlers; ret->is_native_ = false; // If we JIT, it will update this later. upb_inttable_init(&ret->dispatch, UPB_CTYPE_UINT64); if (ret->dest_handlers_) { upb_handlers_ref(ret->dest_handlers_, ret); } return ret; }