From 5a31f694a7cd276c29645bf560160d068f76ce50 Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Sat, 28 Feb 2009 12:15:48 -0800 Subject: Implemented the array part of the fieldnum lookup. --- pbstream.h | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'pbstream.h') diff --git a/pbstream.h b/pbstream.h index b8befc6..cd6fe3a 100644 --- a/pbstream.h +++ b/pbstream.h @@ -91,11 +91,21 @@ struct pbstream_field { /* The set of fields corresponding to a message definition. */ struct pbstream_fieldset { - /* TODO: a hybrid array/hashtable structure. */ int num_fields; - struct pbstream_field fields[]; + struct pbstream_field *fields; + int array_size; + struct pbstream_field **array; + /* TODO: the hashtable part. */ }; +/* Takes an array of num_fields fields and builds an optimized table for fast + * lookup of fields by number. The input fields need not be sorted. This + * fieldset must be freed with pbstream_free_fieldset(). */ +void pbstream_init_fieldset(struct pbstream_fieldset *fieldset, + struct pbstream_field *fields, + int num_fields); +void pbstream_free_fieldset(struct pbstream_fieldset *fieldset); + struct pbstream_parse_stack_frame { struct pbstream_fieldset *fieldset; size_t end_offset; /* unknown for the top frame, so we set to SIZE_MAX */ @@ -134,7 +144,7 @@ typedef enum pbstream_status { // Encountered a "group" on the wire (deprecated and unsupported). PBSTREAM_ERROR_GROUP = -3, - // Input was nested more than 64 deep. + // Input was nested more than PBSTREAM_MAX_STACK deep. PBSTREAM_ERROR_STACK_OVERFLOW = -4, /** NONFATAL ERRORS: the input was invalid, but we can continue if desired. */ -- cgit v1.2.3