summaryrefslogtreecommitdiff
path: root/src/upb_glue.c
diff options
context:
space:
mode:
authorJoshua Haberman <joshua@reverberate.org>2011-02-25 18:31:22 -0800
committerJoshua Haberman <joshua@reverberate.org>2011-02-25 18:31:22 -0800
commita75a305c77acd6800b81204f387f7a437a62fe6b (patch)
treedbd83530befface0868b7fdca37769590b61d5ed /src/upb_glue.c
parentabfc897b50532e5ed64f7f5497f80ef56abd3b26 (diff)
Implemented upb_stringsink, upb_msgtotext, and exposed the latter to Lua.
Diffstat (limited to 'src/upb_glue.c')
-rw-r--r--src/upb_glue.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/upb_glue.c b/src/upb_glue.c
index a3d4e7d..86022d8 100644
--- a/src/upb_glue.c
+++ b/src/upb_glue.c
@@ -8,6 +8,7 @@
#include "upb_msg.h"
#include "upb_decoder.h"
#include "upb_strstream.h"
+#include "upb_textprinter.h"
void upb_strtomsg(upb_string *str, upb_msg *msg, upb_msgdef *md,
upb_status *status) {
@@ -37,6 +38,29 @@ void upb_strtomsg(upb_string *str, upb_msg *msg, upb_msgdef *md,
upb_handlers_uninit(&h);
}
+void upb_msgtotext(upb_string *str, upb_msg *msg, upb_msgdef *md,
+ bool single_line) {
+ upb_stringsink strsink;
+ upb_stringsink_init(&strsink);
+ upb_stringsink_reset(&strsink, str);
+
+ upb_textprinter *p = upb_textprinter_new();
+ upb_handlers h;
+ upb_handlers_init(&h);
+ upb_textprinter_reset(p, &h, upb_stringsink_bytesink(&strsink), single_line);
+
+ upb_status status = UPB_STATUS_INIT;
+ upb_msg_runhandlers(msg, md, &h, &status);
+ // None of {upb_msg_runhandlers, upb_textprinter, upb_stringsink} should be
+ // capable of returning an error.
+ assert(upb_ok(&status));
+ upb_status_uninit(&status);
+
+ upb_stringsink_uninit(&strsink);
+ upb_textprinter_free(p);
+ upb_handlers_uninit(&h);
+}
+
void upb_parsedesc(upb_symtab *symtab, upb_string *str, upb_status *status) {
upb_stringsrc strsrc;
upb_stringsrc_init(&strsrc);
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback