|
|
|||
File indexing completed on 2026-09-18 09:32:13
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 #ifndef UPB_MINI_TABLE_EXTENSION_REGISTRY_H_ 0009 #define UPB_MINI_TABLE_EXTENSION_REGISTRY_H_ 0010 0011 #include <stddef.h> 0012 #include <stdint.h> 0013 0014 #include "upb/mem/arena.h" 0015 #include "upb/mini_table/extension.h" 0016 #include "upb/mini_table/message.h" 0017 0018 // Must be last. 0019 #include "upb/port/def.inc" 0020 0021 #ifdef __cplusplus 0022 extern "C" { 0023 #endif 0024 0025 /* Extension registry: a dynamic data structure that stores a map of: 0026 * (upb_MiniTable, number) -> extension info 0027 * 0028 * upb_decode() uses upb_ExtensionRegistry to look up extensions while parsing 0029 * binary format. 0030 * 0031 * upb_ExtensionRegistry is part of the mini-table (msglayout) family of 0032 * objects. Like all mini-table objects, it is suitable for reflection-less 0033 * builds that do not want to expose names into the binary. 0034 * 0035 * Unlike most mini-table types, upb_ExtensionRegistry requires dynamic memory 0036 * allocation and dynamic initialization: 0037 * * If reflection is being used, then upb_DefPool will construct an appropriate 0038 * upb_ExtensionRegistry automatically. 0039 * * For a mini-table only build, the user must manually construct the 0040 * upb_ExtensionRegistry and populate it with all of the extensions the user 0041 * cares about. 0042 * * A third alternative is to manually unpack relevant extensions after the 0043 * main parse is complete, similar to how Any works. This is perhaps the 0044 * nicest solution from the perspective of reducing dependencies, avoiding 0045 * dynamic memory allocation, and avoiding the need to parse uninteresting 0046 * extensions. The downsides are: 0047 * (1) parse errors are not caught during the main parse 0048 * (2) the CPU hit of parsing comes during access, which could cause an 0049 * undesirable stutter in application performance. 0050 * 0051 * Users cannot directly get or put into this map. Users can only add the 0052 * extensions from a generated module and pass the extension registry to the 0053 * binary decoder. 0054 * 0055 * A upb_DefPool provides a upb_ExtensionRegistry, so any users who use 0056 * reflection do not need to populate a upb_ExtensionRegistry directly. 0057 */ 0058 0059 typedef struct upb_ExtensionRegistry upb_ExtensionRegistry; 0060 0061 typedef enum { 0062 kUpb_ExtensionRegistryStatus_Ok = 0, 0063 kUpb_ExtensionRegistryStatus_DuplicateEntry = 1, 0064 kUpb_ExtensionRegistryStatus_OutOfMemory = 2, 0065 kUpb_ExtensionRegistryStatus_InvalidExtension = 3, 0066 } upb_ExtensionRegistryStatus; 0067 0068 // Creates a upb_ExtensionRegistry in the given arena. 0069 // The arena must outlive any use of the extreg. 0070 UPB_API upb_ExtensionRegistry* upb_ExtensionRegistry_New(upb_Arena* arena); 0071 0072 UPB_API upb_ExtensionRegistryStatus upb_ExtensionRegistry_Add( 0073 upb_ExtensionRegistry* r, const upb_MiniTableExtension* e); 0074 0075 // Adds the given extension info for the array |e| of size |count| into the 0076 // registry. If there are any errors, the entire array is backed out. 0077 // The extensions must outlive the registry. 0078 // Possible errors include OOM or an extension number that already exists. 0079 upb_ExtensionRegistryStatus upb_ExtensionRegistry_AddArray( 0080 upb_ExtensionRegistry* r, const upb_MiniTableExtension** e, size_t count); 0081 0082 #ifdef UPB_LINKARR_DECLARE 0083 0084 // Adds all extensions linked into the binary into the registry. The set of 0085 // linked extensions is assembled by the linker using linker arrays. This 0086 // will likely not work properly if the extensions are split across multiple 0087 // shared libraries. 0088 // 0089 // Returns true if all extensions were added successfully, false on out of 0090 // memory or if any extensions were already present. 0091 // 0092 // This API is currently not available on MSVC (though it *is* available on 0093 // Windows using clang-cl). 0094 UPB_API bool upb_ExtensionRegistry_AddAllLinkedExtensions( 0095 upb_ExtensionRegistry* r); 0096 0097 #endif // UPB_LINKARR_DECLARE 0098 0099 // Looks up the extension (if any) defined for message type |t| and field 0100 // number |num|. Returns the extension if found, otherwise NULL. 0101 UPB_API const upb_MiniTableExtension* upb_ExtensionRegistry_Lookup( 0102 const upb_ExtensionRegistry* r, const upb_MiniTable* t, uint32_t num); 0103 0104 #ifdef __cplusplus 0105 } /* extern "C" */ 0106 #endif 0107 0108 #include "upb/port/undef.inc" 0109 0110 #endif /* UPB_MINI_TABLE_EXTENSION_REGISTRY_H_ */
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|