• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // These are the specialized field parser functions for the fast parser.
2 // Generated tables will refer to these by name.
3 //
4 // The function names are encoded with names like:
5 //
6 //   //  123 4
7 //   upb_pss_1bt();   // Parse singular string, 1 byte tag.
8 //
9 // In position 1:
10 //   - 'p' for parse, most function use this
11 //   - 'c' for copy, for when we are copying strings instead of aliasing
12 //
13 // In position 2 (cardinality):
14 //   - 's' for singular, with or without hasbit
15 //   - 'o' for oneof
16 //   - 'r' for non-packed repeated
17 //   - 'p' for packed repeated
18 //
19 // In position 3 (type):
20 //   - 'b1' for bool
21 //   - 'v4' for 4-byte varint
22 //   - 'v8' for 8-byte varint
23 //   - 'z4' for zig-zag-encoded 4-byte varint
24 //   - 'z8' for zig-zag-encoded 8-byte varint
25 //   - 'f4' for 4-byte fixed
26 //   - 'f8' for 8-byte fixed
27 //   - 'm' for sub-message
28 //   - 's' for string (validate UTF-8)
29 //   - 'b' for bytes
30 //
31 // In position 4 (tag length):
32 //   - '1' for one-byte tags (field numbers 1-15)
33 //   - '2' for two-byte tags (field numbers 16-2048)
34 
35 #ifndef UPB_DECODE_FAST_H_
36 #define UPB_DECODE_FAST_H_
37 
38 #include "upb/msg.h"
39 
40 struct upb_decstate;
41 
42 // The fallback, generic parsing function that can handle any field type.
43 // This just uses the regular (non-fast) parser to parse a single field.
44 const char *fastdecode_generic(struct upb_decstate *d, const char *ptr,
45                                upb_msg *msg, intptr_t table, uint64_t hasbits,
46                                uint64_t data);
47 
48 #define UPB_PARSE_PARAMS                                                 \
49   struct upb_decstate *d, const char *ptr, upb_msg *msg, intptr_t table, \
50       uint64_t hasbits, uint64_t data
51 
52 /* primitive fields ***********************************************************/
53 
54 #define F(card, type, valbytes, tagbytes) \
55   const char *upb_p##card##type##valbytes##_##tagbytes##bt(UPB_PARSE_PARAMS);
56 
57 #define TYPES(card, tagbytes) \
58   F(card, b, 1, tagbytes)     \
59   F(card, v, 4, tagbytes)     \
60   F(card, v, 8, tagbytes)     \
61   F(card, z, 4, tagbytes)     \
62   F(card, z, 8, tagbytes)     \
63   F(card, f, 4, tagbytes)     \
64   F(card, f, 8, tagbytes)
65 
66 #define TAGBYTES(card) \
67   TYPES(card, 1)       \
68   TYPES(card, 2)
69 
70 TAGBYTES(s)
71 TAGBYTES(o)
72 TAGBYTES(r)
73 TAGBYTES(p)
74 
75 #undef F
76 #undef TYPES
77 #undef TAGBYTES
78 
79 /* string fields **************************************************************/
80 
81 #define F(card, tagbytes, type)                                     \
82   const char *upb_p##card##type##_##tagbytes##bt(UPB_PARSE_PARAMS); \
83   const char *upb_c##card##type##_##tagbytes##bt(UPB_PARSE_PARAMS);
84 
85 #define UTF8(card, tagbytes) \
86   F(card, tagbytes, s)       \
87   F(card, tagbytes, b)
88 
89 #define TAGBYTES(card) \
90   UTF8(card, 1)        \
91   UTF8(card, 2)
92 
93 TAGBYTES(s)
94 TAGBYTES(o)
95 TAGBYTES(r)
96 
97 #undef F
98 #undef TAGBYTES
99 
100 /* sub-message fields *********************************************************/
101 
102 #define F(card, tagbytes, size_ceil, ceil_arg) \
103   const char *upb_p##card##m_##tagbytes##bt_max##size_ceil##b(UPB_PARSE_PARAMS);
104 
105 #define SIZES(card, tagbytes) \
106   F(card, tagbytes, 64, 64) \
107   F(card, tagbytes, 128, 128) \
108   F(card, tagbytes, 192, 192) \
109   F(card, tagbytes, 256, 256) \
110   F(card, tagbytes, max, -1)
111 
112 #define TAGBYTES(card) \
113   SIZES(card, 1) \
114   SIZES(card, 2)
115 
116 TAGBYTES(s)
117 TAGBYTES(o)
118 TAGBYTES(r)
119 
120 #undef TAGBYTES
121 #undef SIZES
122 #undef F
123 
124 #undef UPB_PARSE_PARAMS
125 
126 #endif  /* UPB_DECODE_FAST_H_ */
127