diff options
author | Joshua Haberman <joshua@reverberate.org> | 2009-05-25 18:31:27 -0700 |
---|---|---|
committer | Joshua Haberman <joshua@reverberate.org> | 2009-05-25 18:31:27 -0700 |
commit | 0c80c384756a48d5f731eeafa62b6cd5f3861749 (patch) | |
tree | c723951c40b0dd7aea5ccd24e9b55fb0167ffb48 /upb_fieldmap.h | |
parent | fdcefd68b17a62c7129e910351f5b323044f835d (diff) |
A flurry of activity. Doesn't compile yet.
- a descriptor.c that describes the data structures in
descriptor.proto using the data structures in descriptor.h.
- everything renamed pbstream -> upb.
- modularization rethought.
- Doesn't compile yet, but should once things settle back down.
Diffstat (limited to 'upb_fieldmap.h')
-rw-r--r-- | upb_fieldmap.h | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/upb_fieldmap.h b/upb_fieldmap.h new file mode 100644 index 0000000..0fb5a3e --- /dev/null +++ b/upb_fieldmap.h @@ -0,0 +1,53 @@ +/* + * upb - a minimalist implementation of protocol buffers. + * + * Copyright (c) 2009 Joshua Haberman. See LICENSE for details. + * + * A fieldmap is a data structure that supports fast lookup of fields by + * number. It is logically a map of {field_number -> <field info>}, where + * <field info> is any struct that begins with the field number. Fast lookup + * is important, because it is in the critical path of parsing. */ + +#ifndef UPB_FIELDMAP_H_ +#define UPB_FIELDMAP_H_ + +#include "upb.h" + +#ifdef __cplusplus +extern "C" { +#endif + +struct upb_fieldmap { + int array_size; + void *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 + * fieldmap must be freed with upb_free_fieldmap(). */ +void upb_init_fieldmap(struct upb_fieldmap *fieldmap, + void *fields, + int num_fields, + int field_size); +void upb_free_fieldmap(struct upb_fieldmap *fieldmap); + +/* Looks the given field number up in the fieldmap, and returns the + * corresponding field definition (or NULL if this field number does not exist + * in this fieldmap). */ +inline void *upb_fieldmap_find(struct upb_fieldmap *fm, + upb_field_number_t num, + size_t info_size) +{ + if (num < array_size) { + return (char*)fs->array + (num*info_size); + } else { + /* TODO: the hashtable part. */ + } +} + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /* UPB_PARSE_H_ */ |