summaryrefslogtreecommitdiff
path: root/upb/pb
diff options
context:
space:
mode:
Diffstat (limited to 'upb/pb')
-rw-r--r--upb/pb/glue.c14
-rw-r--r--upb/pb/glue.h19
2 files changed, 23 insertions, 10 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) {
diff --git a/upb/pb/glue.h b/upb/pb/glue.h
index 7aa4a5f..38e8d8e 100644
--- a/upb/pb/glue.h
+++ b/upb/pb/glue.h
@@ -28,21 +28,20 @@
#include <stdbool.h>
#include "upb/upb.h"
+#include "upb/def.h"
#ifdef __cplusplus
extern "C" {
#endif
-// Forward-declares so we don't have to include everything in this .h file.
-// Clients should use the regular, typedef'd names (eg. upb_string).
-struct _upb_msg;
-struct _upb_msgdef;
-struct _upb_symtab;
-
// Decodes the given string, which must be in protobuf binary format, to the
// given upb_msg with msgdef "md", storing the status of the operation in "s".
void upb_strtomsg(const char *str, size_t len, void *msg,
- const struct _upb_msgdef *md, upb_status *s);
+ const upb_msgdef *md, upb_status *s);
+
+// Parses the given file into a new message of the given type. Caller owns
+// the returned message (or NULL if an error occurred).
+void *upb_filetonewmsg(const char *fname, const upb_msgdef *md, upb_status *s);
//void upb_msgtotext(struct _upb_string *str, void *msg,
// struct _upb_msgdef *md, bool single_line);
@@ -56,12 +55,12 @@ upb_def **upb_load_defs_from_descriptor(const char *str, size_t len, int *n,
upb_status *status);
// Like the previous but also adds the loaded defs to the given symtab.
-bool upb_load_descriptor_into_symtab(struct _upb_symtab *symtab, const char *str,
+bool upb_load_descriptor_into_symtab(upb_symtab *symtab, const char *str,
size_t len, upb_status *status);
// Like the previous but also reads the descriptor from the given filename.
-bool upb_load_descriptor_file_into_symtab(struct _upb_symtab *symtab,
- const char *fname, upb_status *status);
+bool upb_load_descriptor_file_into_symtab(upb_symtab *symtab, const char *fname,
+ upb_status *status);
// Reads the given filename into a character string, returning NULL if there
// was an error.
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback