• 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 #include "upb/mini_table/internal/message.h"
9 
10 #include <stddef.h>
11 
12 #include "upb/message/internal/types.h"
13 
14 // Must be last.
15 #include "upb/port/def.inc"
16 
17 // A MiniTable for an empty message, used for unlinked sub-messages that are
18 // built via MiniDescriptors.  Messages that use this MiniTable may possibly
19 // be linked later, in which case this MiniTable will be replaced with a real
20 // one.  This pattern is known as "dynamic tree shaking", and it introduces
21 // complication because sub-messages may either be the "empty" type or the
22 // "real" type.  A tagged bit indicates the difference.
23 const struct upb_MiniTable UPB_PRIVATE(_kUpb_MiniTable_Empty) = {
24     .UPB_PRIVATE(subs) = NULL,
25     .UPB_PRIVATE(fields) = NULL,
26     .UPB_PRIVATE(size) = sizeof(struct upb_Message),
27     .UPB_PRIVATE(field_count) = 0,
28     .UPB_PRIVATE(ext) = kUpb_ExtMode_NonExtendable,
29     .UPB_PRIVATE(dense_below) = 0,
30     .UPB_PRIVATE(table_mask) = -1,
31     .UPB_PRIVATE(required_count) = 0,
32 };
33 
34 // A MiniTable for a statically tree shaken message.  Messages that use this
35 // MiniTable are guaranteed to remain unlinked; unlike the empty message, this
36 // MiniTable is never replaced, which greatly simplifies everything, because the
37 // type of a sub-message is always known, without consulting a tagged bit.
38 const struct upb_MiniTable UPB_PRIVATE(_kUpb_MiniTable_StaticallyTreeShaken) = {
39     .UPB_PRIVATE(subs) = NULL,
40     .UPB_PRIVATE(fields) = NULL,
41     .UPB_PRIVATE(size) = sizeof(struct upb_Message),
42     .UPB_PRIVATE(field_count) = 0,
43     .UPB_PRIVATE(ext) = kUpb_ExtMode_NonExtendable,
44     .UPB_PRIVATE(dense_below) = 0,
45     .UPB_PRIVATE(table_mask) = -1,
46     .UPB_PRIVATE(required_count) = 0,
47 };
48