From 0c80c384756a48d5f731eeafa62b6cd5f3861749 Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Mon, 25 May 2009 18:31:27 -0700 Subject: 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. --- upb_fieldmap.h | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 upb_fieldmap.h (limited to 'upb_fieldmap.h') 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 -> }, where + * 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_ */ -- cgit v1.2.3