summaryrefslogtreecommitdiff
path: root/src/upb.h
diff options
context:
space:
mode:
authorJoshua Haberman <joshua@reverberate.org>2009-07-29 11:23:17 -0700
committerJoshua Haberman <joshua@reverberate.org>2009-07-29 11:23:17 -0700
commit4f205f3dc372df2f4cdf47aaaee65f04aa3c361d (patch)
treeb5fe508aeb5873a18d347fcbca45ee463e78e80e /src/upb.h
parente373367fb70d4f432db1d3e9c21f5e0d93950e56 (diff)
Header file rearranging/prettifying.
Diffstat (limited to 'src/upb.h')
-rw-r--r--src/upb.h56
1 files changed, 46 insertions, 10 deletions
diff --git a/src/upb.h b/src/upb.h
index f8cbba3..0db5369 100644
--- a/src/upb.h
+++ b/src/upb.h
@@ -37,29 +37,63 @@ extern "C" {
INLINE uint32_t max(uint32_t a, uint32_t b) { return a > b ? a : b; }
-/* Value type as defined in a .proto file. The values of this are defined by
- * google_protobuf_FieldDescriptorProto_Type (from descriptor.proto).
- * Note that descriptor.proto reserves "0" for errors, and we use it to
- * represent exceptional circumstances. */
+/* Fundamental types and type constants. **************************************/
+
+/* A list of types as they are encoded on-the-wire. */
+enum upb_wire_type {
+ UPB_WIRE_TYPE_VARINT = 0,
+ UPB_WIRE_TYPE_64BIT = 1,
+ UPB_WIRE_TYPE_DELIMITED = 2,
+ UPB_WIRE_TYPE_START_GROUP = 3,
+ UPB_WIRE_TYPE_END_GROUP = 4,
+ UPB_WIRE_TYPE_32BIT = 5
+};
+typedef uint8_t upb_wire_type_t;
+
+/* Value type as defined in a .proto file. eg. string, int32, etc.
+ *
+ * The values of this are defined by google_protobuf_FieldDescriptorProto_Type
+ * (from descriptor.proto). Note that descriptor.proto reserves "0" for
+ * errors, and we use it to represent exceptional circumstances. */
typedef uint8_t upb_field_type_t;
+/* Information about a given value type (upb_field_type_t). */
struct upb_type_info {
uint8_t align;
uint8_t size;
- uint8_t expected_wire_type;
+ upb_wire_type_t expected_wire_type;
struct upb_string ctype;
};
/* Contains information for all .proto types. Indexed by upb_field_type_t. */
extern struct upb_type_info upb_type_info[];
+/* The number of a field, eg. "optional string foo = 3". */
+typedef int32_t upb_field_number_t;
+
/* Label (optional, repeated, required) as defined in a .proto file. The values
* of this are defined by google.protobuf.FieldDescriptorProto.Label (from
* descriptor.proto). */
typedef uint8_t upb_label_t;
-/* A pointer to a .proto value. The owner must have an out-of-band way of
- * knowing the type, so it knows which union member to use. */
+/* A value as it is encoded on-the-wire, except delimited, which is handled
+ * separately. */
+union upb_wire_value {
+ uint64_t varint;
+ uint64_t _64bit;
+ uint32_t _32bit;
+};
+
+/* A tag occurs before each value on-the-wire. */
+struct upb_tag {
+ upb_field_number_t field_number;
+ upb_wire_type_t wire_type;
+};
+
+/* Polymorphic values of .proto types *****************************************/
+
+/* A single .proto value. The owner must have an out-of-band way of knowing
+ * the type, so that it knows which union member to use. */
union upb_value {
double _double;
float _float;
@@ -73,6 +107,8 @@ union upb_value {
void *msg;
};
+/* A pointer to a .proto value. The owner must have an out-of-band way of
+ * knowing the type, so it knows which union member to use. */
union upb_value_ptr {
double *_double;
float *_float;
@@ -87,6 +123,9 @@ union upb_value_ptr {
void *_void;
};
+/* Converts upb_value_ptr -> upb_value by "dereferencing" the pointer. We need
+ * to know the field type to perform this operation, because we need to know
+ * how much memory to copy. */
INLINE union upb_value upb_deref(union upb_value_ptr ptr, upb_field_type_t t) {
union upb_value val;
memcpy(&val, ptr._void, upb_type_info[t].size);
@@ -99,9 +138,6 @@ union upb_symbol_ref {
struct upb_svc *svc;
};
-/* The number of a field, eg. "optional string foo = 3". */
-typedef int32_t upb_field_number_t;
-
/* Status codes used as a return value. Codes >0 are not fatal and can be
* resumed. */
typedef enum upb_status {
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback