blob: 53270f82eae66fc1964c1a90a30488e46df6e027 [file] [log] [blame]
Adam Cozzette501ecec2023-09-26 14:36:20 -07001// Protocol Buffers - Google's data interchange format
2// Copyright 2023 Google LLC. All rights reserved.
3//
4// Use of this source code is governed by a BSD-style
5// license that can be found in the LICENSE file or at
6// https://developers.google.com/open-source/licenses/bsd
7
8// These are the specialized field parser functions for the fast parser.
9// Generated tables will refer to these by name.
10//
11// The function names are encoded with names like:
12//
13// // 123 4
14// upb_pss_1bt(); // Parse singular string, 1 byte tag.
15//
16// In position 1:
17// - 'p' for parse, most function use this
18// - 'c' for copy, for when we are copying strings instead of aliasing
19//
20// In position 2 (cardinality):
21// - 's' for singular, with or without hasbit
22// - 'o' for oneof
23// - 'r' for non-packed repeated
24// - 'p' for packed repeated
25//
26// In position 3 (type):
27// - 'b1' for bool
28// - 'v4' for 4-byte varint
29// - 'v8' for 8-byte varint
30// - 'z4' for zig-zag-encoded 4-byte varint
31// - 'z8' for zig-zag-encoded 8-byte varint
32// - 'f4' for 4-byte fixed
33// - 'f8' for 8-byte fixed
34// - 'm' for sub-message
35// - 's' for string (validate UTF-8)
36// - 'b' for bytes
37//
38// In position 4 (tag length):
39// - '1' for one-byte tags (field numbers 1-15)
40// - '2' for two-byte tags (field numbers 16-2048)
41
Eric Salo4f1eba82024-01-01 19:50:31 -080042#ifndef UPB_WIRE_INTERNAL_DECODE_FAST_H_
43#define UPB_WIRE_INTERNAL_DECODE_FAST_H_
Adam Cozzette501ecec2023-09-26 14:36:20 -070044
45#include "upb/message/message.h"
46
47// Must be last.
48#include "upb/port/def.inc"
49
50#ifdef __cplusplus
51extern "C" {
52#endif
53
54struct upb_Decoder;
55
56// The fallback, generic parsing function that can handle any field type.
57// This just uses the regular (non-fast) parser to parse a single field.
58const char* _upb_FastDecoder_DecodeGeneric(struct upb_Decoder* d,
59 const char* ptr, upb_Message* msg,
60 intptr_t table, uint64_t hasbits,
61 uint64_t data);
62
63#define UPB_PARSE_PARAMS \
64 struct upb_Decoder *d, const char *ptr, upb_Message *msg, intptr_t table, \
65 uint64_t hasbits, uint64_t data
66
67/* primitive fields ***********************************************************/
68
69#define F(card, type, valbytes, tagbytes) \
70 const char* upb_p##card##type##valbytes##_##tagbytes##bt(UPB_PARSE_PARAMS);
71
72#define TYPES(card, tagbytes) \
73 F(card, b, 1, tagbytes) \
74 F(card, v, 4, tagbytes) \
75 F(card, v, 8, tagbytes) \
76 F(card, z, 4, tagbytes) \
77 F(card, z, 8, tagbytes) \
78 F(card, f, 4, tagbytes) \
79 F(card, f, 8, tagbytes)
80
81#define TAGBYTES(card) \
82 TYPES(card, 1) \
83 TYPES(card, 2)
84
85TAGBYTES(s)
86TAGBYTES(o)
87TAGBYTES(r)
88TAGBYTES(p)
89
90#undef F
91#undef TYPES
92#undef TAGBYTES
93
94/* string fields **************************************************************/
95
96#define F(card, tagbytes, type) \
97 const char* upb_p##card##type##_##tagbytes##bt(UPB_PARSE_PARAMS); \
98 const char* upb_c##card##type##_##tagbytes##bt(UPB_PARSE_PARAMS);
99
100#define UTF8(card, tagbytes) \
101 F(card, tagbytes, s) \
102 F(card, tagbytes, b)
103
104#define TAGBYTES(card) \
105 UTF8(card, 1) \
106 UTF8(card, 2)
107
108TAGBYTES(s)
109TAGBYTES(o)
110TAGBYTES(r)
111
112#undef F
Eric Salo4f1eba82024-01-01 19:50:31 -0800113#undef UTF8
Adam Cozzette501ecec2023-09-26 14:36:20 -0700114#undef TAGBYTES
115
116/* sub-message fields *********************************************************/
117
118#define F(card, tagbytes, size_ceil, ceil_arg) \
119 const char* upb_p##card##m_##tagbytes##bt_max##size_ceil##b(UPB_PARSE_PARAMS);
120
121#define SIZES(card, tagbytes) \
122 F(card, tagbytes, 64, 64) \
123 F(card, tagbytes, 128, 128) \
124 F(card, tagbytes, 192, 192) \
125 F(card, tagbytes, 256, 256) \
126 F(card, tagbytes, max, -1)
127
128#define TAGBYTES(card) \
129 SIZES(card, 1) \
130 SIZES(card, 2)
131
132TAGBYTES(s)
133TAGBYTES(o)
134TAGBYTES(r)
135
Adam Cozzette501ecec2023-09-26 14:36:20 -0700136#undef F
Eric Salo4f1eba82024-01-01 19:50:31 -0800137#undef SIZES
138#undef TAGBYTES
Adam Cozzette501ecec2023-09-26 14:36:20 -0700139
140#undef UPB_PARSE_PARAMS
141
142#ifdef __cplusplus
143} /* extern "C" */
144#endif
145
146#include "upb/port/undef.inc"
147
Eric Salo4f1eba82024-01-01 19:50:31 -0800148#endif /* UPB_WIRE_INTERNAL_DECODE_FAST_H_ */