summaryrefslogtreecommitdiff
path: root/upb.h
blob: 36abcaa2ac7bc11a894c43b1653024ca6fcb412b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/*
 * upb - a minimalist implementation of protocol buffers.
 *
 * Copyright (c) 2009 Joshua Haberman.  See LICENSE for details.
 */

#ifndef UPB_H_
#define UPB_H_

#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>  /* for size_t. */

#ifdef __cplusplus
extern "C" {
#endif

/* Portable inlining strategy: use C99 rules except on GCC.
 *   see: http://www.greenend.org.uk/rjk/2003/03/inline.html. */
#ifndef INLINE
# if __GNUC__ && !__GNUC_STDC_INLINE__
#  define INLINE extern inline
# else
#  define INLINE inline
# endif
#endif

/* The maximum that any submessages can be nested.  Matches proto2's limit. */
#define UPB_MAX_NESTING 64

/* 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;

/* 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;
};

/* 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. */
typedef uint8_t upb_field_type_t;

/* A value as described in a .proto file, except delimited, which is handled
 * separately. */
union upb_value {
  double _double;
  float  _float;
  int32_t int32;
  int64_t int64;
  uint32_t uint32;
  uint64_t uint64;
  bool _bool;
  uint32_t delim_len;
};

/* The number of a field, eg. "optional string foo = 3". */
typedef int32_t upb_field_number_t;

/* A tag occurs before each value on-the-wire. */
struct upb_tag {
  upb_field_number_t field_number;
  upb_wire_type_t wire_type;
};

/* Status codes used as a return value. */
typedef enum upb_status {
  UPB_STATUS_OK = 0,

  // A varint did not terminate before hitting 64 bits.
  UPB_ERROR_UNTERMINATED_VARINT = -1,

  // A submessage or packed array ended in the middle of data.
  UPB_ERROR_BAD_SUBMESSAGE_END = -2,

  // Input was nested more than UPB_MAX_NESTING deep.
  UPB_ERROR_STACK_OVERFLOW = -3,

  // The input data caused the pb's offset (a size_t) to overflow.
  UPB_ERROR_OVERFLOW = -4,

  // An "end group" tag was encountered in an inappropriate place.
  UPB_ERROR_SPURIOUS_END_GROUP = -5
} upb_status_t;

#ifdef __cplusplus
}  /* extern "C" */
#endif

#endif  /* UPB_H_ */
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback