After this change, `mini_table` only has MiniTable definitions themselves. Everything having to do with the MiniDescriptor wire format is in `mini_descriptor`. Also rearranged some of the files in mini_table to have better structure for `internal/`. This CL contains no functional change. PiperOrigin-RevId: 543529112pull/13171/head
parent
b2e55eecdd
commit
07f6b578ee
69 changed files with 967 additions and 466 deletions
@ -0,0 +1,64 @@ |
||||
/*
|
||||
* Copyright (c) 2009-2021, Google LLC |
||||
* All rights reserved. |
||||
* |
||||
* Redistribution and use in source and binary forms, with or without |
||||
* modification, are permitted provided that the following conditions are met: |
||||
* * Redistributions of source code must retain the above copyright |
||||
* notice, this list of conditions and the following disclaimer. |
||||
* * Redistributions in binary form must reproduce the above copyright |
||||
* notice, this list of conditions and the following disclaimer in the |
||||
* documentation and/or other materials provided with the distribution. |
||||
* * Neither the name of Google LLC nor the |
||||
* names of its contributors may be used to endorse or promote products |
||||
* derived from this software without specific prior written permission. |
||||
* |
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
||||
* ARE DISCLAIMED. IN NO EVENT SHALL Google LLC BE LIABLE FOR ANY DIRECT, |
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
*/ |
||||
|
||||
#ifndef UPB_MINI_TABLE_INTERNAL_MAP_ENTRY_DATA_H_ |
||||
#define UPB_MINI_TABLE_INTERNAL_MAP_ENTRY_DATA_H_ |
||||
|
||||
#include <stdint.h> |
||||
|
||||
#include "upb/base/string_view.h" |
||||
#include "upb/hash/common.h" |
||||
|
||||
// Map entries aren't actually stored for map fields, they are only used during
|
||||
// parsing. For parsing, it helps a lot if all map entry messages have the same
|
||||
// layout. The layout code in mini_table/decode.c will ensure that all map
|
||||
// entries have this layout.
|
||||
//
|
||||
// Note that users can and do create map entries directly, which will also use
|
||||
// this layout.
|
||||
//
|
||||
// NOTE: sync with mini_table/decode.c.
|
||||
typedef struct { |
||||
// We only need 2 hasbits max, but due to alignment we'll use 8 bytes here,
|
||||
// and the uint64_t helps make this clear.
|
||||
uint64_t hasbits; |
||||
union { |
||||
upb_StringView str; // For str/bytes.
|
||||
upb_value val; // For all other types.
|
||||
} k; |
||||
union { |
||||
upb_StringView str; // For str/bytes.
|
||||
upb_value val; // For all other types.
|
||||
} v; |
||||
} upb_MapEntryData; |
||||
|
||||
typedef struct { |
||||
void* internal_data; |
||||
upb_MapEntryData data; |
||||
} upb_MapEntry; |
||||
|
||||
#endif // UPB_MINI_TABLE_INTERNAL_MAP_ENTRY_DATA_H_
|
@ -1,26 +1,120 @@ |
||||
# Copyright (c) 2009-2023, Google LLC |
||||
# All rights reserved. |
||||
# |
||||
# Redistribution and use in source and binary forms, with or without |
||||
# modification, are permitted provided that the following conditions are met: |
||||
# * Redistributions of source code must retain the above copyright |
||||
# notice, this list of conditions and the following disclaimer. |
||||
# * Redistributions in binary form must reproduce the above copyright |
||||
# notice, this list of conditions and the following disclaimer in the |
||||
# documentation and/or other materials provided with the distribution. |
||||
# * Neither the name of Google LLC nor the |
||||
# names of its contributors may be used to endorse or promote products |
||||
# derived from this software without specific prior written permission. |
||||
# |
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
||||
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
||||
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
||||
# DISCLAIMED. IN NO EVENT SHALL Google LLC BE LIABLE FOR ANY |
||||
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
||||
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
||||
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
||||
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||||
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
||||
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
|
||||
# Placeholder for new package. |
||||
load( |
||||
"//bazel:build_defs.bzl", |
||||
"UPB_DEFAULT_COPTS", |
||||
"UPB_DEFAULT_CPPOPTS", |
||||
) |
||||
|
||||
# begin:github_only |
||||
load("@rules_pkg//:mappings.bzl", "pkg_files") |
||||
# end:github_only |
||||
|
||||
cc_library( |
||||
name = "internal", |
||||
srcs = [ |
||||
"internal/base92.c", |
||||
], |
||||
hdrs = [ |
||||
"internal/base92.h", |
||||
"internal/modifiers.h", |
||||
"internal/wire_constants.h", |
||||
], |
||||
copts = UPB_DEFAULT_COPTS, |
||||
visibility = ["//:__subpackages__"], |
||||
deps = [ |
||||
"//:base", |
||||
"//:port", |
||||
], |
||||
) |
||||
|
||||
cc_library( |
||||
name = "mini_descriptor", |
||||
srcs = [ |
||||
"decode.c", |
||||
], |
||||
hdrs = [ |
||||
"decode.h", |
||||
], |
||||
copts = UPB_DEFAULT_COPTS, |
||||
visibility = ["//:friends"], |
||||
deps = [ |
||||
":internal", |
||||
"//:base", |
||||
"//:mem", |
||||
"//:port", |
||||
"//upb/mini_table", |
||||
], |
||||
) |
||||
|
||||
cc_library( |
||||
name = "encode_internal", |
||||
srcs = [ |
||||
"internal/encode.c", |
||||
], |
||||
hdrs = [ |
||||
"internal/encode.h", |
||||
"internal/encode.hpp", |
||||
], |
||||
copts = UPB_DEFAULT_COPTS, |
||||
visibility = ["//:__subpackages__"], |
||||
deps = [ |
||||
":internal", |
||||
"//:base", |
||||
"//:port", |
||||
], |
||||
) |
||||
|
||||
cc_test( |
||||
name = "encode_test", |
||||
srcs = ["internal/encode_test.cc"], |
||||
copts = UPB_DEFAULT_CPPOPTS, |
||||
deps = [ |
||||
":encode_internal", |
||||
":internal", |
||||
":mini_descriptor", |
||||
"@com_google_absl//absl/container:flat_hash_set", |
||||
"//:upb", |
||||
"//:message_accessors_internal", |
||||
"//:mini_table", |
||||
"@com_google_googletest//:gtest_main", |
||||
"@com_google_protobuf//:protobuf", |
||||
], |
||||
) |
||||
|
||||
# begin:github_only |
||||
filegroup( |
||||
name = "cmake_files", |
||||
srcs = glob( |
||||
[ |
||||
"**/*.c", |
||||
"**/*.h", |
||||
], |
||||
), |
||||
visibility = ["//cmake:__pkg__"], |
||||
) |
||||
|
||||
pkg_files( |
||||
name = "source_files", |
||||
srcs = glob( |
||||
[ |
||||
"**/*.c", |
||||
"**/*.h", |
||||
], |
||||
exclude = ["internal/**"], |
||||
), |
||||
prefix = "upb/mini_descriptor", |
||||
visibility = ["//python/dist:__pkg__"], |
||||
) |
||||
|
||||
pkg_files( |
||||
name = "internal_source_files", |
||||
srcs = glob( |
||||
[ |
||||
"internal/*.c", |
||||
"internal/*.h", |
||||
], |
||||
exclude = ["encode_test.cc"], |
||||
), |
||||
prefix = "upb/mini_descriptor/internal", |
||||
visibility = ["//python/dist:__pkg__"], |
||||
) |
||||
# end:github_only |
||||
|
@ -0,0 +1,46 @@ |
||||
/*
|
||||
* Copyright (c) 2009-2021, Google LLC |
||||
* All rights reserved. |
||||
* |
||||
* Redistribution and use in source and binary forms, with or without |
||||
* modification, are permitted provided that the following conditions are met: |
||||
* * Redistributions of source code must retain the above copyright |
||||
* notice, this list of conditions and the following disclaimer. |
||||
* * Redistributions in binary form must reproduce the above copyright |
||||
* notice, this list of conditions and the following disclaimer in the |
||||
* documentation and/or other materials provided with the distribution. |
||||
* * Neither the name of Google LLC nor the |
||||
* names of its contributors may be used to endorse or promote products |
||||
* derived from this software without specific prior written permission. |
||||
* |
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
||||
* ARE DISCLAIMED. IN NO EVENT SHALL Google LLC BE LIABLE FOR ANY DIRECT, |
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
*/ |
||||
|
||||
#include "upb/mini_descriptor/internal/base92.h" |
||||
|
||||
const char _kUpb_ToBase92[] = { |
||||
' ', '!', '#', '$', '%', '&', '(', ')', '*', '+', ',', '-', '.', '/', |
||||
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '<', '=', |
||||
'>', '?', '@', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', |
||||
'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', |
||||
'Z', '[', ']', '^', '_', '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', |
||||
'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', |
||||
'w', 'x', 'y', 'z', '{', '|', '}', '~', |
||||
}; |
||||
|
||||
const int8_t _kUpb_FromBase92[] = { |
||||
0, 1, -1, 2, 3, 4, 5, -1, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, |
||||
17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, |
||||
36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, |
||||
55, 56, 57, -1, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, |
||||
73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, |
||||
}; |
@ -0,0 +1,56 @@ |
||||
/*
|
||||
* Copyright (c) 2009-2022, Google LLC |
||||
* All rights reserved. |
||||
* |
||||
* Redistribution and use in source and binary forms, with or without |
||||
* modification, are permitted provided that the following conditions are met: |
||||
* * Redistributions of source code must retain the above copyright |
||||
* notice, this list of conditions and the following disclaimer. |
||||
* * Redistributions in binary form must reproduce the above copyright |
||||
* notice, this list of conditions and the following disclaimer in the |
||||
* documentation and/or other materials provided with the distribution. |
||||
* * Neither the name of Google LLC nor the |
||||
* names of its contributors may be used to endorse or promote products |
||||
* derived from this software without specific prior written permission. |
||||
* |
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
||||
* ARE DISCLAIMED. IN NO EVENT SHALL Google LLC BE LIABLE FOR ANY DIRECT, |
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
*/ |
||||
|
||||
#ifndef UPB_MINI_DESCRIPTOR_INTERNAL_BASE92_H_ |
||||
#define UPB_MINI_DESCRIPTOR_INTERNAL_BASE92_H_ |
||||
|
||||
// Must be last.
|
||||
#include "upb/port/def.inc" |
||||
|
||||
#ifdef __cplusplus |
||||
extern "C" { |
||||
#endif |
||||
|
||||
UPB_INLINE char _upb_ToBase92(int8_t ch) { |
||||
extern const char _kUpb_ToBase92[]; |
||||
UPB_ASSERT(0 <= ch && ch < 92); |
||||
return _kUpb_ToBase92[ch]; |
||||
} |
||||
|
||||
UPB_INLINE char _upb_FromBase92(uint8_t ch) { |
||||
extern const int8_t _kUpb_FromBase92[]; |
||||
if (' ' > ch || ch > '~') return -1; |
||||
return _kUpb_FromBase92[ch - ' ']; |
||||
} |
||||
|
||||
#ifdef __cplusplus |
||||
} /* extern "C" */ |
||||
#endif |
||||
|
||||
#include "upb/port/undef.inc" |
||||
|
||||
#endif // UPB_MINI_DESCRIPTOR_INTERNAL_BASE92_H_
|
@ -0,0 +1,50 @@ |
||||
/*
|
||||
* Copyright (c) 2009-2022, Google LLC |
||||
* All rights reserved. |
||||
* |
||||
* Redistribution and use in source and binary forms, with or without |
||||
* modification, are permitted provided that the following conditions are met: |
||||
* * Redistributions of source code must retain the above copyright |
||||
* notice, this list of conditions and the following disclaimer. |
||||
* * Redistributions in binary form must reproduce the above copyright |
||||
* notice, this list of conditions and the following disclaimer in the |
||||
* documentation and/or other materials provided with the distribution. |
||||
* * Neither the name of Google LLC nor the |
||||
* names of its contributors may be used to endorse or promote products |
||||
* derived from this software without specific prior written permission. |
||||
* |
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
||||
* ARE DISCLAIMED. IN NO EVENT SHALL Google LLC BE LIABLE FOR ANY DIRECT, |
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
*/ |
||||
|
||||
#ifndef UPB_MINI_DESCRIPTOR_INTERNAL_MODIFIERS_H_ |
||||
#define UPB_MINI_DESCRIPTOR_INTERNAL_MODIFIERS_H_ |
||||
|
||||
// Must be last.
|
||||
#include "upb/port/def.inc" |
||||
|
||||
typedef enum { |
||||
kUpb_FieldModifier_IsRepeated = 1 << 0, |
||||
kUpb_FieldModifier_IsPacked = 1 << 1, |
||||
kUpb_FieldModifier_IsClosedEnum = 1 << 2, |
||||
kUpb_FieldModifier_IsProto3Singular = 1 << 3, |
||||
kUpb_FieldModifier_IsRequired = 1 << 4, |
||||
} kUpb_FieldModifier; |
||||
|
||||
typedef enum { |
||||
kUpb_MessageModifier_ValidateUtf8 = 1 << 0, |
||||
kUpb_MessageModifier_DefaultIsPacked = 1 << 1, |
||||
kUpb_MessageModifier_IsExtendable = 1 << 2, |
||||
} kUpb_MessageModifier; |
||||
|
||||
#include "upb/port/undef.inc" |
||||
|
||||
#endif // UPB_MINI_DESCRIPTOR_INTERNAL_MODIFIERS_H_
|
@ -0,0 +1,50 @@ |
||||
/*
|
||||
* Copyright (c) 2009-2021, Google LLC |
||||
* All rights reserved. |
||||
* |
||||
* Redistribution and use in source and binary forms, with or without |
||||
* modification, are permitted provided that the following conditions are met: |
||||
* * Redistributions of source code must retain the above copyright |
||||
* notice, this list of conditions and the following disclaimer. |
||||
* * Redistributions in binary form must reproduce the above copyright |
||||
* notice, this list of conditions and the following disclaimer in the |
||||
* documentation and/or other materials provided with the distribution. |
||||
* * Neither the name of Google LLC nor the |
||||
* names of its contributors may be used to endorse or promote products |
||||
* derived from this software without specific prior written permission. |
||||
* |
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
||||
* ARE DISCLAIMED. IN NO EVENT SHALL Google LLC BE LIABLE FOR ANY DIRECT, |
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
*/ |
||||
|
||||
#ifndef UPB_MINI_TABLE_ENUM_H_ |
||||
#define UPB_MINI_TABLE_ENUM_H_ |
||||
|
||||
#include "upb/mini_table/internal/enum.h" |
||||
|
||||
// Must be last
|
||||
#include "upb/port/def.inc" |
||||
|
||||
typedef struct upb_MiniTableEnum upb_MiniTableEnum; |
||||
|
||||
// Validates enum value against range defined by enum mini table.
|
||||
UPB_INLINE bool upb_MiniTableEnum_CheckValue(const struct upb_MiniTableEnum* e, |
||||
uint32_t val) { |
||||
_kUpb_FastEnumCheck_Status status = _upb_MiniTable_CheckEnumValueFast(e, val); |
||||
if (UPB_UNLIKELY(status == _kUpb_FastEnumCheck_CannotCheckFast)) { |
||||
return _upb_MiniTable_CheckEnumValueSlow(e, val); |
||||
} |
||||
return status == _kUpb_FastEnumCheck_ValueIsInEnum ? true : false; |
||||
} |
||||
|
||||
#include "upb/port/undef.inc" |
||||
|
||||
#endif /* UPB_MINI_TABLE_ENUM_H_ */ |
@ -0,0 +1,40 @@ |
||||
/*
|
||||
* Copyright (c) 2009-2021, Google LLC |
||||
* All rights reserved. |
||||
* |
||||
* Redistribution and use in source and binary forms, with or without |
||||
* modification, are permitted provided that the following conditions are met: |
||||
* * Redistributions of source code must retain the above copyright |
||||
* notice, this list of conditions and the following disclaimer. |
||||
* * Redistributions in binary form must reproduce the above copyright |
||||
* notice, this list of conditions and the following disclaimer in the |
||||
* documentation and/or other materials provided with the distribution. |
||||
* * Neither the name of Google LLC nor the |
||||
* names of its contributors may be used to endorse or promote products |
||||
* derived from this software without specific prior written permission. |
||||
* |
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
||||
* ARE DISCLAIMED. IN NO EVENT SHALL Google LLC BE LIABLE FOR ANY DIRECT, |
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
*/ |
||||
|
||||
#ifndef UPB_MINI_TABLE_EXTENSION_H_ |
||||
#define UPB_MINI_TABLE_EXTENSION_H_ |
||||
|
||||
#include "upb/mini_table/internal/extension.h" |
||||
|
||||
// Must be last.
|
||||
#include "upb/port/def.inc" |
||||
|
||||
typedef struct upb_MiniTableExtension upb_MiniTableExtension; |
||||
|
||||
#include "upb/port/undef.inc" |
||||
|
||||
#endif /* UPB_MINI_TABLE_EXTENSION_H_ */ |
@ -0,0 +1,118 @@ |
||||
/*
|
||||
* Copyright (c) 2009-2022, Google LLC |
||||
* All rights reserved. |
||||
* |
||||
* Redistribution and use in source and binary forms, with or without |
||||
* modification, are permitted provided that the following conditions are met: |
||||
* * Redistributions of source code must retain the above copyright |
||||
* notice, this list of conditions and the following disclaimer. |
||||
* * Redistributions in binary form must reproduce the above copyright |
||||
* notice, this list of conditions and the following disclaimer in the |
||||
* documentation and/or other materials provided with the distribution. |
||||
* * Neither the name of Google LLC nor the |
||||
* names of its contributors may be used to endorse or promote products |
||||
* derived from this software without specific prior written permission. |
||||
* |
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
||||
* ARE DISCLAIMED. IN NO EVENT SHALL Google LLC BE LIABLE FOR ANY DIRECT, |
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
*/ |
||||
|
||||
#ifndef UPB_MINI_TABLE_FIELD_H_ |
||||
#define UPB_MINI_TABLE_FIELD_H_ |
||||
|
||||
#include "upb/mini_table/internal/field.h" |
||||
#include "upb/mini_table/internal/message.h" |
||||
#include "upb/mini_table/internal/sub.h" |
||||
|
||||
// Must be last.
|
||||
#include "upb/port/def.inc" |
||||
|
||||
#ifdef __cplusplus |
||||
extern "C" { |
||||
#endif |
||||
|
||||
typedef struct upb_MiniTableField upb_MiniTableField; |
||||
|
||||
UPB_API_INLINE upb_FieldType |
||||
upb_MiniTableField_Type(const upb_MiniTableField* field) { |
||||
if (field->mode & kUpb_LabelFlags_IsAlternate) { |
||||
if (field->UPB_PRIVATE(descriptortype) == kUpb_FieldType_Int32) { |
||||
return kUpb_FieldType_Enum; |
||||
} else if (field->UPB_PRIVATE(descriptortype) == kUpb_FieldType_Bytes) { |
||||
return kUpb_FieldType_String; |
||||
} else { |
||||
UPB_ASSERT(false); |
||||
} |
||||
} |
||||
return (upb_FieldType)field->UPB_PRIVATE(descriptortype); |
||||
} |
||||
|
||||
UPB_API_INLINE upb_CType upb_MiniTableField_CType(const upb_MiniTableField* f) { |
||||
switch (upb_MiniTableField_Type(f)) { |
||||
case kUpb_FieldType_Double: |
||||
return kUpb_CType_Double; |
||||
case kUpb_FieldType_Float: |
||||
return kUpb_CType_Float; |
||||
case kUpb_FieldType_Int64: |
||||
case kUpb_FieldType_SInt64: |
||||
case kUpb_FieldType_SFixed64: |
||||
return kUpb_CType_Int64; |
||||
case kUpb_FieldType_Int32: |
||||
case kUpb_FieldType_SFixed32: |
||||
case kUpb_FieldType_SInt32: |
||||
return kUpb_CType_Int32; |
||||
case kUpb_FieldType_UInt64: |
||||
case kUpb_FieldType_Fixed64: |
||||
return kUpb_CType_UInt64; |
||||
case kUpb_FieldType_UInt32: |
||||
case kUpb_FieldType_Fixed32: |
||||
return kUpb_CType_UInt32; |
||||
case kUpb_FieldType_Enum: |
||||
return kUpb_CType_Enum; |
||||
case kUpb_FieldType_Bool: |
||||
return kUpb_CType_Bool; |
||||
case kUpb_FieldType_String: |
||||
return kUpb_CType_String; |
||||
case kUpb_FieldType_Bytes: |
||||
return kUpb_CType_Bytes; |
||||
case kUpb_FieldType_Group: |
||||
case kUpb_FieldType_Message: |
||||
return kUpb_CType_Message; |
||||
} |
||||
UPB_UNREACHABLE(); |
||||
} |
||||
|
||||
UPB_API_INLINE bool upb_MiniTableField_IsExtension( |
||||
const upb_MiniTableField* field) { |
||||
return field->mode & kUpb_LabelFlags_IsExtension; |
||||
} |
||||
|
||||
UPB_API_INLINE bool upb_MiniTableField_IsClosedEnum( |
||||
const upb_MiniTableField* field) { |
||||
return field->UPB_PRIVATE(descriptortype) == kUpb_FieldType_Enum; |
||||
} |
||||
|
||||
UPB_API_INLINE bool upb_MiniTableField_HasPresence( |
||||
const upb_MiniTableField* field) { |
||||
if (upb_MiniTableField_IsExtension(field)) { |
||||
return !upb_IsRepeatedOrMap(field); |
||||
} else { |
||||
return field->presence != 0; |
||||
} |
||||
} |
||||
|
||||
#ifdef __cplusplus |
||||
} /* extern "C" */ |
||||
#endif |
||||
|
||||
#include "upb/port/undef.inc" |
||||
|
||||
#endif /* UPB_MINI_TABLE_FIELD_H_ */ |
@ -0,0 +1,39 @@ |
||||
/*
|
||||
* Copyright (c) 2009-2021, Google LLC |
||||
* All rights reserved. |
||||
* |
||||
* Redistribution and use in source and binary forms, with or without |
||||
* modification, are permitted provided that the following conditions are met: |
||||
* * Redistributions of source code must retain the above copyright |
||||
* notice, this list of conditions and the following disclaimer. |
||||
* * Redistributions in binary form must reproduce the above copyright |
||||
* notice, this list of conditions and the following disclaimer in the |
||||
* documentation and/or other materials provided with the distribution. |
||||
* * Neither the name of Google LLC nor the |
||||
* names of its contributors may be used to endorse or promote products |
||||
* derived from this software without specific prior written permission. |
||||
* |
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
||||
* ARE DISCLAIMED. IN NO EVENT SHALL Google LLC BE LIABLE FOR ANY DIRECT, |
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
*/ |
||||
|
||||
#ifndef UPB_MINI_TABLE_INTERNAL_SUB_H_ |
||||
#define UPB_MINI_TABLE_INTERNAL_SUB_H_ |
||||
|
||||
#include "upb/mini_table/internal/enum.h" |
||||
#include "upb/mini_table/internal/message.h" |
||||
|
||||
union upb_MiniTableSub { |
||||
const struct upb_MiniTable* submsg; |
||||
const struct upb_MiniTableEnum* subenum; |
||||
}; |
||||
|
||||
#endif /* UPB_MINI_TABLE_INTERNAL_SUB_H_ */ |
@ -0,0 +1,35 @@ |
||||
/*
|
||||
* Copyright (c) 2009-2021, Google LLC |
||||
* All rights reserved. |
||||
* |
||||
* Redistribution and use in source and binary forms, with or without |
||||
* modification, are permitted provided that the following conditions are met: |
||||
* * Redistributions of source code must retain the above copyright |
||||
* notice, this list of conditions and the following disclaimer. |
||||
* * Redistributions in binary form must reproduce the above copyright |
||||
* notice, this list of conditions and the following disclaimer in the |
||||
* documentation and/or other materials provided with the distribution. |
||||
* * Neither the name of Google LLC nor the |
||||
* names of its contributors may be used to endorse or promote products |
||||
* derived from this software without specific prior written permission. |
||||
* |
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
||||
* ARE DISCLAIMED. IN NO EVENT SHALL Google LLC BE LIABLE FOR ANY DIRECT, |
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
*/ |
||||
|
||||
#ifndef UPB_MINI_TABLE_SUB_H_ |
||||
#define UPB_MINI_TABLE_SUB_H_ |
||||
|
||||
#include "upb/mini_table/internal/sub.h" |
||||
|
||||
typedef union upb_MiniTableSub upb_MiniTableSub; |
||||
|
||||
#endif /* UPB_MINI_TABLE_INTERNAL_SUB_H_ */ |
Loading…
Reference in new issue