diff options
Diffstat (limited to 'upb/pb/glue.h')
-rw-r--r-- | upb/pb/glue.h | 52 |
1 files changed, 23 insertions, 29 deletions
diff --git a/upb/pb/glue.h b/upb/pb/glue.h index f65753c..014562b 100644 --- a/upb/pb/glue.h +++ b/upb/pb/glue.h @@ -25,49 +25,43 @@ #include "upb/symtab.h" #ifdef __cplusplus +#include <vector> + extern "C" { #endif -/* Loads all defs from the given protobuf binary descriptor, setting default - * accessors and a default layout on all messages. The caller owns the - * returned array of defs, which will be of length *n. On error NULL is - * returned and status is set (if non-NULL). */ -upb_def **upb_load_defs_from_descriptor(const char *str, size_t len, int *n, - void *owner, upb_status *status); - -/* Like the previous but also adds the loaded defs to the given symtab. */ -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(upb_symtab *symtab, const char *fname, - upb_status *status); - -/* Reads the given filename into a character string, returning NULL if there - * was an error. */ -char *upb_readfile(const char *filename, size_t *len); +/* Loads a binary descriptor and returns a NULL-terminated array of unfrozen + * filedefs. The caller owns the returned array. */ +upb_filedef **upb_loaddescriptor(const char *buf, size_t n, const void *owner, + upb_status *status); #ifdef __cplusplus } /* extern "C" */ namespace upb { -/* All routines that load descriptors expect the descriptor to be a - * FileDescriptorSet. */ -inline bool LoadDescriptorFileIntoSymtab(SymbolTable* s, const char *fname, - Status* status) { - return upb_load_descriptor_file_into_symtab(s, fname, status); -} +inline bool LoadDescriptor(const char* buf, size_t n, Status* status, + std::vector<reffed_ptr<FileDef> >* files) { + FileDef** parsed_files = upb_loaddescriptor(buf, n, &parsed_files, status); -inline bool LoadDescriptorIntoSymtab(SymbolTable* s, const char* str, - size_t len, Status* status) { - return upb_load_descriptor_into_symtab(s, str, len, status); + if (parsed_files) { + FileDef** p = parsed_files; + while (*p) { + files->push_back(reffed_ptr<FileDef>(*p, &parsed_files)); + ++p; + } + free(parsed_files); + return true; + } else { + return false; + } } /* Templated so it can accept both string and std::string. */ template <typename T> -bool LoadDescriptorIntoSymtab(SymbolTable* s, const T& desc, Status* status) { - return upb_load_descriptor_into_symtab(s, desc.c_str(), desc.size(), status); +bool LoadDescriptor(const T& desc, Status* status, + std::vector<reffed_ptr<FileDef> >* files) { + return LoadDescriptor(desc.c_str(), desc.size(), status, files); } } /* namespace upb */ |