From 559e23c796f973a65d05c76e211835b126ee8ac8 Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Fri, 17 Jun 2011 10:34:29 -0700 Subject: Major refactoring: abandon upb_msg, add upb_accessors. Next on the chopping block is upb_string. --- src/upb_descriptor.h | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 src/upb_descriptor.h (limited to 'src/upb_descriptor.h') diff --git a/src/upb_descriptor.h b/src/upb_descriptor.h new file mode 100644 index 0000000..f74de3b --- /dev/null +++ b/src/upb_descriptor.h @@ -0,0 +1,67 @@ +/* + * upb - a minimalist implementation of protocol buffers. + * + * Copyright (c) 2011 Google Inc. See LICENSE for details. + * Author: Josh Haberman + * + * Routines for building defs by parsing descriptors in descriptor.proto format. + * This only needs to use the public API of upb_symtab. Later we may also + * add routines for dumping a symtab to a descriptor. + */ + +#ifndef UPB_DESCRIPTOR_H +#define UPB_DESCRIPTOR_H + +#include "upb_handlers.h" + +#ifdef __cplusplus +extern "C" { +#endif + + +/* upb_descreader ************************************************************/ + +// upb_descreader reads a descriptor and puts defs in a upb_symtabtxn. + +// We keep a stack of all the messages scopes we are currently in, as well as +// the top-level file scope. This is necessary to correctly qualify the +// definitions that are contained inside. "name" tracks the name of the +// message or package (a bare name -- not qualified by any enclosing scopes). +typedef struct { + upb_string *name; + // Index of the first def that is under this scope. For msgdefs, the + // msgdef itself is at start-1. + int start; +} upb_descreader_frame; + +typedef struct { + upb_deflist defs; + upb_symtabtxn *txn; + upb_descreader_frame stack[UPB_MAX_TYPE_DEPTH]; + int stack_len; + upb_status status; + + uint32_t number; + upb_string *name; + bool saw_number; + bool saw_name; + + upb_string *default_string; + + upb_fielddef *f; +} upb_descreader; + +// Creates a new descriptor builder that will add defs to the given txn. +void upb_descreader_init(upb_descreader *r, upb_symtabtxn *txn); +void upb_descreader_uninit(upb_descreader *r); + +// Registers handlers that will load descriptor data into a symtabtxn. +// Pass the descreader as the closure. The messages will have +// upb_msgdef_layout() called on them before adding to the txn. +upb_mhandlers *upb_descreader_reghandlers(upb_handlers *h); + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif -- cgit v1.2.3