summaryrefslogtreecommitdiff
path: root/core/upb_glue.c
diff options
context:
space:
mode:
authorJoshua Haberman <joshua@reverberate.org>2011-02-05 18:53:32 -0800
committerJoshua Haberman <joshua@reverberate.org>2011-02-05 18:53:32 -0800
commit3affb319260263efc3cee502896d9f981186c7da (patch)
tree6d519e32a23dc1d3b03c3da0791fd2ea00f154f4 /core/upb_glue.c
parente170259e4ababf39829fa9339fdf0817e38c949e (diff)
Tons of work: we're close to passing test_vs_proto2 again.
Diffstat (limited to 'core/upb_glue.c')
-rw-r--r--core/upb_glue.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/core/upb_glue.c b/core/upb_glue.c
new file mode 100644
index 0000000..7540a3a
--- /dev/null
+++ b/core/upb_glue.c
@@ -0,0 +1,38 @@
+/*
+ * upb - a minimalist implementation of protocol buffers.
+ *
+ * Copyright (c) 2010 Joshua Haberman. See LICENSE for details.
+ */
+
+#include "upb_glue.h"
+#include "upb_msg.h"
+#include "upb_decoder.h"
+#include "upb_strstream.h"
+
+void upb_strtomsg(upb_string *str, upb_msg *msg, upb_msgdef *md,
+ upb_status *status) {
+ upb_stringsrc strsrc;
+ upb_stringsrc_init(&strsrc);
+ upb_stringsrc_reset(&strsrc, str);
+
+ upb_decoder d;
+ upb_decoder_init(&d, md);
+ upb_decoder_reset(&d, upb_stringsrc_bytesrc(&strsrc));
+ upb_src *src = upb_decoder_src(&d);
+
+ upb_msgpopulator p;
+ upb_msgpopulator_init(&p);
+ upb_msgpopulator_reset(&p, msg, md);
+
+ upb_handlers h;
+ upb_handlers_init(&h);
+ upb_msgpopulator_register_handlers(&p, &h);
+ upb_src_sethandlers(src, &h);
+
+ upb_src_run(src, status);
+
+ upb_stringsrc_uninit(&strsrc);
+ upb_decoder_uninit(&d);
+ upb_msgpopulator_uninit(&p);
+ upb_handlers_uninit(&h);
+}
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback