• 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 #ifndef UPB_MINI_TABLE_TAGGED_PTR_H_
9 #define UPB_MINI_TABLE_TAGGED_PTR_H_
10 
11 #include <stdint.h>
12 
13 #include "upb/message/internal/tagged_ptr.h"
14 #include "upb/message/message.h"
15 
16 // Must be last.
17 #include "upb/port/def.inc"
18 
19 // When a upb_Message* is stored in a message, array, or map, it is stored in a
20 // tagged form. If the tag bit is set, the referenced upb_Message is of type
21 // _kUpb_MiniTable_Empty (a sentinel message type with no fields) instead of
22 // that field's true message type. This forms the basis of what we call
23 // "dynamic tree shaking."
24 //
25 // See the documentation for kUpb_DecodeOption_ExperimentalAllowUnlinked for
26 // more information.
27 
28 typedef uintptr_t upb_TaggedMessagePtr;
29 
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33 
34 // Users who enable unlinked sub-messages must use this to test whether a
35 // message is empty before accessing it. If a message is empty, it must be
36 // first promoted using the interfaces in message/promote.h.
upb_TaggedMessagePtr_IsEmpty(upb_TaggedMessagePtr ptr)37 UPB_INLINE bool upb_TaggedMessagePtr_IsEmpty(upb_TaggedMessagePtr ptr) {
38   return UPB_PRIVATE(_upb_TaggedMessagePtr_IsEmpty)(ptr);
39 }
40 
upb_TaggedMessagePtr_GetNonEmptyMessage(upb_TaggedMessagePtr ptr)41 UPB_INLINE upb_Message* upb_TaggedMessagePtr_GetNonEmptyMessage(
42     upb_TaggedMessagePtr ptr) {
43   return UPB_PRIVATE(_upb_TaggedMessagePtr_GetNonEmptyMessage)(ptr);
44 }
45 
46 #ifdef __cplusplus
47 } /* extern "C" */
48 #endif
49 
50 #include "upb/port/undef.inc"
51 
52 #endif /* UPB_MINI_TABLE_TAGGED_PTR_H_ */
53