WPILibC++ 2027.0.0-alpha-3
Loading...
Searching...
No Matches
extension_registry.h
Go to the documentation of this file.
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_EXTENSION_REGISTRY_H_
9#define UPB_MINI_TABLE_EXTENSION_REGISTRY_H_
10
11#include <stddef.h>
12#include <stdint.h>
13
14#include "upb/mem/arena.h"
17
18// Must be last.
19#include "upb/port/def.inc"
20
21#ifdef __cplusplus
22extern "C" {
23#endif
24
25/* Extension registry: a dynamic data structure that stores a map of:
26 * (upb_MiniTable, number) -> extension info
27 *
28 * upb_decode() uses upb_ExtensionRegistry to look up extensions while parsing
29 * binary format.
30 *
31 * upb_ExtensionRegistry is part of the mini-table (msglayout) family of
32 * objects. Like all mini-table objects, it is suitable for reflection-less
33 * builds that do not want to expose names into the binary.
34 *
35 * Unlike most mini-table types, upb_ExtensionRegistry requires dynamic memory
36 * allocation and dynamic initialization:
37 * * If reflection is being used, then upb_DefPool will construct an appropriate
38 * upb_ExtensionRegistry automatically.
39 * * For a mini-table only build, the user must manually construct the
40 * upb_ExtensionRegistry and populate it with all of the extensions the user
41 * cares about.
42 * * A third alternative is to manually unpack relevant extensions after the
43 * main parse is complete, similar to how Any works. This is perhaps the
44 * nicest solution from the perspective of reducing dependencies, avoiding
45 * dynamic memory allocation, and avoiding the need to parse uninteresting
46 * extensions. The downsides are:
47 * (1) parse errors are not caught during the main parse
48 * (2) the CPU hit of parsing comes during access, which could cause an
49 * undesirable stutter in application performance.
50 *
51 * Users cannot directly get or put into this map. Users can only add the
52 * extensions from a generated module and pass the extension registry to the
53 * binary decoder.
54 *
55 * A upb_DefPool provides a upb_ExtensionRegistry, so any users who use
56 * reflection do not need to populate a upb_ExtensionRegistry directly.
57 */
58
60
67
68// Creates a upb_ExtensionRegistry in the given arena.
69// The arena must outlive any use of the extreg.
71
74
75// Adds the given extension info for the array |e| of size |count| into the
76// registry. If there are any errors, the entire array is backed out.
77// The extensions must outlive the registry.
78// Possible errors include OOM or an extension number that already exists.
80 upb_ExtensionRegistry* r, const upb_MiniTableExtension** e, size_t count);
81
82#ifdef UPB_LINKARR_DECLARE
83
84// Adds all extensions linked into the binary into the registry. The set of
85// linked extensions is assembled by the linker using linker arrays. This
86// will likely not work properly if the extensions are split across multiple
87// shared libraries.
88//
89// Returns true if all extensions were added successfully, false on out of
90// memory or if any extensions were already present.
91//
92// This API is currently not available on MSVC (though it *is* available on
93// Windows using clang-cl).
94UPB_API bool upb_ExtensionRegistry_AddAllLinkedExtensions(
96
97#endif // UPB_LINKARR_DECLARE
98
99// Looks up the extension (if any) defined for message type |t| and field
100// number |num|. Returns the extension if found, otherwise NULL.
102 const upb_ExtensionRegistry* r, const upb_MiniTable* t, uint32_t num);
103
104#ifdef __cplusplus
105} /* extern "C" */
106#endif
107
108#include "upb/port/undef.inc"
109
110#endif /* UPB_MINI_TABLE_EXTENSION_REGISTRY_H_ */
#define UPB_API
Definition def.inc:162
upb_ExtensionRegistryStatus
Definition extension_registry.h:61
@ kUpb_ExtensionRegistryStatus_Ok
Definition extension_registry.h:62
@ kUpb_ExtensionRegistryStatus_InvalidExtension
Definition extension_registry.h:65
@ kUpb_ExtensionRegistryStatus_OutOfMemory
Definition extension_registry.h:64
@ kUpb_ExtensionRegistryStatus_DuplicateEntry
Definition extension_registry.h:63
upb_ExtensionRegistryStatus upb_ExtensionRegistry_AddArray(upb_ExtensionRegistry *r, const upb_MiniTableExtension **e, size_t count)
struct upb_ExtensionRegistry upb_ExtensionRegistry
Definition extension_registry.h:59
UPB_API upb_ExtensionRegistry * upb_ExtensionRegistry_New(upb_Arena *arena)
UPB_API const upb_MiniTableExtension * upb_ExtensionRegistry_Lookup(const upb_ExtensionRegistry *r, const upb_MiniTable *t, uint32_t num)
UPB_API upb_ExtensionRegistryStatus upb_ExtensionRegistry_Add(upb_ExtensionRegistry *r, const upb_MiniTableExtension *e)
Definition arena.h:29
Definition extension.h:21
Definition message.h:54