Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:13:17

0001 // Protocol Buffers - Google's data interchange format
0002 // Copyright 2023 Google LLC.  All rights reserved.
0003 //
0004 // Use of this source code is governed by a BSD-style
0005 // license that can be found in the LICENSE file or at
0006 // https://developers.google.com/open-source/licenses/bsd
0007 
0008 // Functions for linking MiniTables together once they are built from a
0009 // MiniDescriptor.
0010 //
0011 // These functions have names like upb_MiniTable_Link() because they operate on
0012 // MiniTables.  We put them here, rather than in the mini_table/ directory,
0013 // because they are only needed when building MiniTables from MiniDescriptors.
0014 // The interfaces in mini_table/ assume that MiniTables are immutable.
0015 
0016 #ifndef UPB_MINI_DESCRIPTOR_LINK_H_
0017 #define UPB_MINI_DESCRIPTOR_LINK_H_
0018 
0019 #include "upb/base/status.h"
0020 #include "upb/mem/arena.h"
0021 #include "upb/mini_table/enum.h"
0022 #include "upb/mini_table/field.h"
0023 #include "upb/mini_table/message.h"
0024 #include "upb/mini_table/sub.h"
0025 
0026 // Must be last.
0027 #include "upb/port/def.inc"
0028 
0029 #ifdef __cplusplus
0030 extern "C" {
0031 #endif
0032 
0033 // Links a sub-message field to a MiniTable for that sub-message. If a
0034 // sub-message field is not linked, it will be treated as an unknown field
0035 // during parsing, and setting the field will not be allowed. It is possible
0036 // to link the message field later, at which point it will no longer be treated
0037 // as unknown. However there is no synchronization for this operation, which
0038 // means parallel mutation requires external synchronization.
0039 // Returns success/failure.
0040 UPB_API bool upb_MiniTable_SetSubMessage(upb_MiniTable* table,
0041                                          upb_MiniTableField* field,
0042                                          const upb_MiniTable* sub);
0043 
0044 // Links an enum field to a MiniTable for that enum.
0045 // All enum fields must be linked prior to parsing.
0046 // Returns success/failure.
0047 UPB_API bool upb_MiniTable_SetSubEnum(upb_MiniTable* table,
0048                                       upb_MiniTableField* field,
0049                                       const upb_MiniTableEnum* sub);
0050 
0051 // Returns a list of fields that require linking at runtime, to connect the
0052 // MiniTable to its sub-messages and sub-enums.  The list of fields will be
0053 // written to the `subs` array, which must have been allocated by the caller
0054 // and must be large enough to hold a list of all fields in the message.
0055 //
0056 // The order of the fields returned by this function is significant: it matches
0057 // the order expected by upb_MiniTable_Link() below.
0058 //
0059 // The return value packs the sub-message count and sub-enum count into a single
0060 // integer like so:
0061 //  return (msg_count << 16) | enum_count;
0062 UPB_API uint32_t upb_MiniTable_GetSubList(const upb_MiniTable* mt,
0063                                           const upb_MiniTableField** subs);
0064 
0065 // Links a message to its sub-messages and sub-enums.  The caller must pass
0066 // arrays of sub-tables and sub-enums, in the same length and order as is
0067 // returned by upb_MiniTable_GetSubList() above.  However, individual elements
0068 // of the sub_tables may be NULL if those sub-messages were tree shaken.
0069 //
0070 // Returns false if either array is too short, or if any of the tables fails
0071 // to link.
0072 UPB_API bool upb_MiniTable_Link(upb_MiniTable* mt,
0073                                 const upb_MiniTable** sub_tables,
0074                                 size_t sub_table_count,
0075                                 const upb_MiniTableEnum** sub_enums,
0076                                 size_t sub_enum_count);
0077 
0078 #ifdef __cplusplus
0079 } /* extern "C" */
0080 #endif
0081 
0082 #include "upb/port/undef.inc"
0083 
0084 #endif  // UPB_MINI_DESCRIPTOR_LINK_H_