decode.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2009-2021, Google LLC
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  * * Redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer.
9  * * Redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution.
12  * * Neither the name of Google LLC nor the
13  * names of its contributors may be used to endorse or promote products
14  * derived from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  * ARE DISCLAIMED. IN NO EVENT SHALL Google LLC BE LIABLE FOR ANY DIRECT,
20  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
27 
28 /*
29  * upb_decode: parsing into a upb_Message using a upb_MiniTable.
30  */
31 
32 #ifndef UPB_DECODE_H_
33 #define UPB_DECODE_H_
34 
35 #include "upb/msg.h"
36 
37 /* Must be last. */
38 #include "upb/port_def.inc"
39 
40 #ifdef __cplusplus
41 extern "C" {
42 #endif
43 
44 enum {
45  /* If set, strings will alias the input buffer instead of copying into the
46  * arena. */
48 
49  /* If set, the parse will return failure if any message is missing any
50  * required fields when the message data ends. The parse will still continue,
51  * and the failure will only be reported at the end.
52  *
53  * IMPORTANT CAVEATS:
54  *
55  * 1. This can throw a false positive failure if an incomplete message is seen
56  * on the wire but is later completed when the sub-message occurs again.
57  * For this reason, a second pass is required to verify a failure, to be
58  * truly robust.
59  *
60  * 2. This can return a false success if you are decoding into a message that
61  * already has some sub-message fields present. If the sub-message does
62  * not occur in the binary payload, we will never visit it and discover the
63  * incomplete sub-message. For this reason, this check is only useful for
64  * implemting ParseFromString() semantics. For MergeFromString(), a
65  * post-parse validation step will always be necessary. */
67 };
68 
69 #define UPB_DECODE_MAXDEPTH(depth) ((depth) << 16)
70 
71 typedef enum {
73  kUpb_DecodeStatus_Malformed = 1, // Wire format was corrupt
74  kUpb_DecodeStatus_OutOfMemory = 2, // Arena alloc failed
75  kUpb_DecodeStatus_BadUtf8 = 3, // String field had bad UTF-8
76  kUpb_DecodeStatus_MaxDepthExceeded = 4, // Exceeded UPB_DECODE_MAXDEPTH
77 
78  // kUpb_DecodeOption_CheckRequired failed (see above), but the parse otherwise
79  // succeeded.
82 
83 upb_DecodeStatus upb_Decode(const char* buf, size_t size, upb_Message* msg,
84  const upb_MiniTable* l,
85  const upb_ExtensionRegistry* extreg, int options,
86  upb_Arena* arena);
87 
88 #ifdef __cplusplus
89 } /* extern "C" */
90 #endif
91 
92 #include "upb/port_undef.inc"
93 
94 #endif /* UPB_DECODE_H_ */
kUpb_DecodeStatus_MissingRequired
@ kUpb_DecodeStatus_MissingRequired
Definition: decode.h:80
upb_Decode
upb_DecodeStatus upb_Decode(const char *buf, size_t size, upb_Message *msg, const upb_MiniTable *l, const upb_ExtensionRegistry *extreg, int options, upb_Arena *arena)
Definition: decode.c:1076
kUpb_DecodeStatus_BadUtf8
@ kUpb_DecodeStatus_BadUtf8
Definition: decode.h:75
options
double_dict options[]
Definition: capstone_test.c:55
buf
voidpf void * buf
Definition: bloaty/third_party/zlib/contrib/minizip/ioapi.h:136
kUpb_DecodeStatus_Ok
@ kUpb_DecodeStatus_Ok
Definition: decode.h:72
upb_MiniTable
Definition: msg_internal.h:185
kUpb_DecodeStatus_MaxDepthExceeded
@ kUpb_DecodeStatus_MaxDepthExceeded
Definition: decode.h:76
kUpb_DecodeStatus_Malformed
@ kUpb_DecodeStatus_Malformed
Definition: decode.h:73
arena
grpc_core::ScopedArenaPtr arena
Definition: binder_transport_test.cc:237
msg.h
kUpb_DecodeOption_AliasString
@ kUpb_DecodeOption_AliasString
Definition: decode.h:47
upb_Message
void upb_Message
Definition: msg.h:49
msg
std::string msg
Definition: client_interceptors_end2end_test.cc:372
upb_DecodeStatus
upb_DecodeStatus
Definition: decode.h:71
kUpb_DecodeOption_CheckRequired
@ kUpb_DecodeOption_CheckRequired
Definition: decode.h:66
kUpb_DecodeStatus_OutOfMemory
@ kUpb_DecodeStatus_OutOfMemory
Definition: decode.h:74
run_grpclb_interop_tests.l
dictionary l
Definition: run_grpclb_interop_tests.py:410
size
voidpf void uLong size
Definition: bloaty/third_party/zlib/contrib/minizip/ioapi.h:136
upb_Arena
Definition: upb_internal.h:36
upb_ExtensionRegistry
Definition: msg.c:372


grpc
Author(s):
autogenerated on Thu Mar 13 2025 02:59:02