• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // 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 // Users should include array.h or map.h instead.
9 // IWYU pragma: private, include "upb/message/array.h"
10 
11 #ifndef UPB_MESSAGE_VALUE_H_
12 #define UPB_MESSAGE_VALUE_H_
13 
14 #include <stdint.h>
15 #include <string.h>
16 
17 #include "upb/base/string_view.h"
18 
19 // Must be last.
20 #include "upb/port/def.inc"
21 
22 #ifdef __cplusplus
23 extern "C" {
24 #endif
25 
26 typedef union {
27   bool bool_val;
28   float float_val;
29   double double_val;
30   int32_t int32_val;
31   int64_t int64_val;
32   uint32_t uint32_val;
33   uint64_t uint64_val;
34   const struct upb_Array* array_val;
35   const struct upb_Map* map_val;
36   const struct upb_Message* msg_val;
37   upb_StringView str_val;
38 
39   // EXPERIMENTAL: A tagged upb_Message*.  Users must use this instead of
40   // msg_val if unlinked sub-messages may possibly be in use.  See the
41   // documentation in kUpb_DecodeOption_ExperimentalAllowUnlinked for more
42   // information.
43   uintptr_t tagged_msg_val;  // upb_TaggedMessagePtr
44 } upb_MessageValue;
45 
upb_MessageValue_Zero(void)46 UPB_API_INLINE upb_MessageValue upb_MessageValue_Zero(void) {
47   upb_MessageValue zero;
48   memset(&zero, 0, sizeof(zero));
49   return zero;
50 }
51 
52 typedef union {
53   struct upb_Array* array;
54   struct upb_Map* map;
55   struct upb_Message* msg;
56 } upb_MutableMessageValue;
57 
upb_MutableMessageValue_Zero(void)58 UPB_API_INLINE upb_MutableMessageValue upb_MutableMessageValue_Zero(void) {
59   upb_MutableMessageValue zero;
60   memset(&zero, 0, sizeof(zero));
61   return zero;
62 }
63 
64 #ifdef __cplusplus
65 } /* extern "C" */
66 #endif
67 
68 #include "upb/port/undef.inc"
69 
70 #endif /* UPB_MESSAGE_VALUE_H_ */
71