diff options
author | Joshua Haberman <joshua@reverberate.org> | 2011-02-13 12:59:54 -0800 |
---|---|---|
committer | Joshua Haberman <joshua@reverberate.org> | 2011-02-13 12:59:54 -0800 |
commit | 6bdbb45e88e7b88b294dfb6e4cb493cbc3c8cf74 (patch) | |
tree | 0e00246fb124ebdf6a2210c816704c1d840e2138 /src/upb_glue.c | |
parent | ee84a7da167d2211066c4a663d41febdf9544438 (diff) |
Merged core/ and stream/ -> src/. The split wasn't worth it.
Diffstat (limited to 'src/upb_glue.c')
-rw-r--r-- | src/upb_glue.c | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/src/upb_glue.c b/src/upb_glue.c new file mode 100644 index 0000000..541827e --- /dev/null +++ b/src/upb_glue.c @@ -0,0 +1,54 @@ +/* + * 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); +} + +void upb_parsedesc(upb_symtab *symtab, upb_string *str, upb_status *status) { + upb_stringsrc strsrc; + upb_stringsrc_init(&strsrc); + upb_stringsrc_reset(&strsrc, str); + + upb_decoder d; + upb_msgdef *fds_msgdef = upb_symtab_fds_def(symtab); + upb_decoder_init(&d, fds_msgdef); + upb_decoder_reset(&d, upb_stringsrc_bytesrc(&strsrc)); + + upb_symtab_addfds(symtab, upb_decoder_src(&d), status); + upb_stringsrc_uninit(&strsrc); + upb_decoder_uninit(&d); + upb_def_unref(UPB_UPCAST(fds_msgdef)); +} |