WPILibC++ 2027.0.0-alpha-3
Loading...
Searching...
No Matches
extension.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_MESSAGE_INTERNAL_EXTENSION_H_
9#define UPB_MESSAGE_INTERNAL_EXTENSION_H_
10
11#include <stddef.h>
12
13#include "upb/mem/arena.h"
17#include "upb/message/value.h"
20
21// Must be last.
22#include "upb/port/def.inc"
23
24// The internal representation of an extension is self-describing: it contains
25// enough information that we can serialize it to binary format without needing
26// to look it up in a upb_ExtensionRegistry.
27//
28// This representation allocates 16 bytes to data on 64-bit platforms.
29// This is rather wasteful for scalars (in the extreme case of bool,
30// it wastes 15 bytes). We accept this because we expect messages to be
31// the most common extension type.
36
37#ifdef __cplusplus
38extern "C" {
39#endif
40
41// Adds the given extension data to the given message.
42// |ext| is copied into the message instance.
43// This logically replaces any previously-added extension with this number.
45 struct upb_Message* msg, const upb_MiniTableExtension* ext,
46 upb_Arena* arena);
47
48// Returns an extension for a message with a given mini table,
49// or NULL if no extension exists with this mini table.
51 const struct upb_Message* msg, const upb_MiniTableExtension* ext);
52
54 switch (
55 UPB_PRIVATE(_upb_MiniTableField_Mode)(&ext->ext->UPB_PRIVATE(field))) {
57 return false;
59 return upb_Array_Size(ext->data.array_val) == 0;
61 return _upb_Map_Size(ext->data.map_val) == 0;
62 }
64}
65
66#ifdef __cplusplus
67} /* extern "C" */
68#endif
69
70#include "upb/port/undef.inc"
71
72#endif /* UPB_MESSAGE_INTERNAL_EXTENSION_H_ */
#define UPB_UNREACHABLE()
Definition def.inc:345
#define UPB_PRIVATE(x)
Definition def.inc:393
#define UPB_INLINE
Definition def.inc:144
UPB_INLINE upb_FieldMode UPB_PRIVATE _upb_MiniTableField_Mode(const struct upb_MiniTableField *f)
Definition field.h:78
@ kUpb_FieldMode_Map
Definition field.h:39
@ kUpb_FieldMode_Array
Definition field.h:40
@ kUpb_FieldMode_Scalar
Definition field.h:41
UPB_INLINE size_t _upb_Map_Size(const struct upb_Map *map)
Definition map.h:205
UPB_INLINE bool UPB_PRIVATE _upb_Extension_IsEmpty(const upb_Extension *ext)
Definition extension.h:53
const upb_Extension *UPB_PRIVATE _upb_Message_Getext(const struct upb_Message *msg, const upb_MiniTableExtension *ext)
upb_Extension *UPB_PRIVATE _upb_Message_GetOrCreateExtension(struct upb_Message *msg, const upb_MiniTableExtension *ext, upb_Arena *arena)
Definition arena.h:29
Definition extension.h:32
const upb_MiniTableExtension * ext
Definition extension.h:33
upb_MessageValue data
Definition extension.h:34
Definition types.h:18
Definition extension.h:21
UPB_API_INLINE size_t upb_Array_Size(const struct upb_Array *arr)
Definition array.h:156
Definition value.h:27