diff options
author | Joshua Haberman <jhaberman@gmail.com> | 2011-09-12 18:33:06 -0700 |
---|---|---|
committer | Joshua Haberman <jhaberman@gmail.com> | 2011-09-12 18:33:06 -0700 |
commit | 887abe669f9a71c5fb530f0315e350ba22a150a7 (patch) | |
tree | 0122e0acc30624102e0a82362f50f0e5dcc970ac /upb/pb/glue.c | |
parent | bda3269a42877ae0a0b2b44b579cba5b13d5b1de (diff) |
Added an example, constified some more methods.
Diffstat (limited to 'upb/pb/glue.c')
-rw-r--r-- | upb/pb/glue.c | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/upb/pb/glue.c b/upb/pb/glue.c index b364a6d..37b86d9 100644 --- a/upb/pb/glue.c +++ b/upb/pb/glue.c @@ -30,6 +30,20 @@ void upb_strtomsg(const char *str, size_t len, void *msg, const upb_msgdef *md, upb_decoder_uninit(&d); } +void *upb_filetonewmsg(const char *fname, const upb_msgdef *md, upb_status *s) { + void *msg = upb_stdmsg_new(md); + size_t len; + char *data = upb_readfile(fname, &len); + if (!data) goto err; + upb_strtomsg(data, len, msg, md, s); + if (!upb_ok(s)) goto err; + return msg; + +err: + upb_stdmsg_free(msg, md); + return NULL; +} + #if 0 void upb_msgtotext(upb_string *str, upb_msg *msg, upb_msgdef *md, bool single_line) { |