Split mini_descriptor into its own directory

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: 543529112
pull/13171/head
Joshua Haberman 2 years ago committed by Copybara-Service
parent b2e55eecdd
commit 07f6b578ee
  1. 128
      BUILD
  2. 1
      cmake/BUILD.bazel
  3. 1
      protos/protos.h
  4. 1
      protos/repeated_field.h
  5. 1
      protos/repeated_field_iterator.h
  6. 3
      python/dist/BUILD.bazel
  7. 2
      python/dist/setup.py
  8. 2
      upb/collections/map_sorter_internal.h
  9. 3
      upb/collections/message_value.h
  10. 16
      upb/generated_code_support.h
  11. 2
      upb/message/accessors.c
  12. 5
      upb/message/accessors.h
  13. 59
      upb/message/accessors_internal.h
  14. 7
      upb/message/accessors_test.cc
  15. 1
      upb/message/copy.c
  16. 1
      upb/message/copy.h
  17. 3
      upb/message/copy_test.cc
  18. 2
      upb/message/extension_internal.h
  19. 5
      upb/message/internal.h
  20. 64
      upb/message/internal/map_entry.h
  21. 2
      upb/message/message.h
  22. 2
      upb/message/promote.c
  23. 6
      upb/message/promote_test.cc
  24. 7
      upb/message/tagged_ptr.h
  25. 146
      upb/mini_descriptor/BUILD
  26. 9
      upb/mini_descriptor/decode.c
  27. 5
      upb/mini_descriptor/decode.h
  28. 46
      upb/mini_descriptor/internal/base92.c
  29. 56
      upb/mini_descriptor/internal/base92.h
  30. 7
      upb/mini_descriptor/internal/encode.c
  31. 7
      upb/mini_descriptor/internal/encode.h
  32. 2
      upb/mini_descriptor/internal/encode.hpp
  33. 12
      upb/mini_descriptor/internal/encode_test.cc
  34. 50
      upb/mini_descriptor/internal/modifiers.h
  35. 26
      upb/mini_descriptor/internal/wire_constants.h
  36. 100
      upb/mini_table/BUILD
  37. 50
      upb/mini_table/enum.h
  38. 40
      upb/mini_table/extension.h
  39. 2
      upb/mini_table/extension_registry.c
  40. 3
      upb/mini_table/extension_registry.h
  41. 118
      upb/mini_table/field.h
  42. 13
      upb/mini_table/file.h
  43. 26
      upb/mini_table/internal/enum.h
  44. 16
      upb/mini_table/internal/extension.h
  45. 76
      upb/mini_table/internal/field.h
  46. 10
      upb/mini_table/internal/file.h
  47. 4
      upb/mini_table/internal/message.c
  48. 50
      upb/mini_table/internal/message.h
  49. 39
      upb/mini_table/internal/sub.h
  50. 22
      upb/mini_table/message.c
  51. 96
      upb/mini_table/message.h
  52. 35
      upb/mini_table/sub.h
  53. 2
      upb/reflection/def_pool_internal.h
  54. 2
      upb/reflection/desc_state_internal.h
  55. 2
      upb/reflection/enum_def.c
  56. 3
      upb/reflection/field_def.c
  57. 2
      upb/reflection/message.c
  58. 3
      upb/reflection/message_def.c
  59. 3
      upb/test/BUILD
  60. 4
      upb/test/fuzz_util.cc
  61. 2
      upb/test/fuzz_util.h
  62. 3
      upb/test/test_mini_table_oneof.cc
  63. 2
      upb/upb_so.c
  64. 4
      upb/wire/decode.c
  65. 3
      upb/wire/encode.c
  66. 2
      upbc/BUILD
  67. 2
      upbc/code_generator_request.c
  68. 2
      upbc/file_layout.cc
  69. 2
      upbc/file_layout.h

128
BUILD

@ -164,7 +164,7 @@ cc_library(
":message_internal",
":port",
":wire",
"//upb/mini_table:mini_table_internal",
"//upb/mini_table",
],
)
@ -207,7 +207,7 @@ alias(
alias(
name = "mini_table_internal",
actual = "//upb/mini_table:mini_table_internal",
actual = "//upb/mini_table:internal",
visibility = ["//:friends"],
)
@ -228,7 +228,17 @@ cc_library(
":hash",
":mem",
":port",
"//upb/mini_table:mini_table_internal",
"//upb/mini_table",
],
)
cc_library(
name = "message_tagged_ptr",
hdrs = ["upb/message/tagged_ptr.h"],
copts = UPB_DEFAULT_COPTS,
visibility = ["//:friends"],
deps = [
":port",
],
)
@ -242,8 +252,8 @@ cc_library(
deps = [
":collections_internal",
":message_internal",
":mini_table_internal",
":port",
"//upb/mini_table:mini_table_internal",
],
)
@ -261,13 +271,13 @@ cc_library(
deps = [
":collections_internal",
":eps_copy_input_stream",
":hash",
":message_internal",
":mini_table",
":port",
":upb",
":wire",
":wire_reader",
"//upb/mini_table:mini_table_internal",
"//upb/mini_table:internal",
],
)
@ -291,7 +301,7 @@ cc_library(
":upb",
":wire",
":wire_reader",
"//upb/mini_table:mini_table_internal",
"//upb/mini_table",
],
)
@ -311,7 +321,7 @@ cc_library(
":message_internal",
":port",
":upb",
"//upb/mini_table:mini_table_internal",
"//upb/mini_table",
],
)
@ -336,7 +346,10 @@ cc_test(
":message_accessors",
":port",
":upb",
"//upb/mini_table:mini_table_internal",
"//upb/mini_descriptor",
"//upb/mini_descriptor:encode_internal",
"//upb/mini_descriptor:internal",
"//upb/mini_table",
"//upb/test:test_messages_proto2_upb_proto",
"//upb/test:test_messages_proto3_upb_proto",
"//upb/test:test_upb_proto",
@ -356,7 +369,9 @@ cc_test(
":message_promote",
":port",
":upb",
"//upb/mini_table:mini_table_internal",
"//upb/mini_descriptor:encode_internal",
"//upb/mini_descriptor:internal",
"//upb/mini_table",
"//upb/test:test_messages_proto2_upb_proto",
"//upb/test:test_messages_proto3_upb_proto",
"//upb/test:test_upb_proto",
@ -374,7 +389,7 @@ cc_test(
":message_accessors",
":message_copy",
":upb",
"//upb/mini_table:mini_table_internal",
"//upb/mini_table",
"//upb/test:test_messages_proto2_upb_proto",
"//upb/test:test_messages_proto3_upb_proto",
"//upb/test:test_upb_proto",
@ -395,7 +410,7 @@ cc_library(
":message_internal",
":port",
":wire",
"//upb/mini_table:mini_table_internal",
"//upb/mini_table",
],
)
@ -421,7 +436,8 @@ cc_library(
":message_internal",
":upb",
":wire_internal",
"//upb/mini_table:mini_table_internal",
"//upb/mini_descriptor",
"//upb/mini_table",
],
)
@ -460,11 +476,8 @@ cc_library(
copts = UPB_DEFAULT_COPTS,
visibility = ["//visibility:public"],
deps = [
":base",
":descriptor_upb_proto",
":hash",
":reflection_internal",
"//upb/mini_table:mini_table_internal",
"//upb/mini_descriptor",
],
)
@ -502,6 +515,18 @@ cc_library(
],
)
cc_library(
name = "message_rep_internal",
hdrs = [
"upb/message/internal/map_entry.h",
],
copts = UPB_DEFAULT_COPTS,
deps = [
":base",
":hash",
],
)
cc_library(
name = "collections_internal",
srcs = [
@ -525,8 +550,10 @@ cc_library(
":hash",
":mem",
":message_internal",
":message_rep_internal",
":message_tagged_ptr",
":port",
"//upb/mini_table:mini_table_internal",
"//upb/mini_table",
],
)
@ -630,7 +657,10 @@ bootstrap_cc_library(
":message_accessors",
":port",
":upb",
"//upb/mini_table:mini_table_internal",
"//upb/mini_descriptor",
"//upb/mini_descriptor:encode_internal",
"//upb/mini_descriptor:internal",
"//upb/mini_table",
],
)
@ -811,7 +841,7 @@ cc_library(
":message_internal",
":port",
":wire_internal",
"//upb/mini_table:mini_table_internal",
"//upb/mini_table",
],
)
@ -837,14 +867,14 @@ cc_library(
":base",
":collections_internal",
":eps_copy_input_stream",
":hash",
":mem_internal",
":message_accessors_internal",
":message_internal",
":message_rep_internal",
":port",
":wire_reader",
":wire_types",
"//upb/mini_table:mini_table_internal",
"//upb/mini_table",
"@utf8_range",
],
)
@ -937,14 +967,15 @@ cc_binary(
linkstatic = 1,
visibility = ["//visibility:public"],
deps = [
"//:collections",
"//:collections_split64",
"//:mem",
"//:message",
"//:message_accessors",
"//:message_split64",
"//:mini_table",
"//:port",
":collections",
":collections_split64",
":mem",
":message",
":message_accessors",
":message_split64",
":mini_table",
":port",
"//upb/mini_descriptor",
],
)
@ -968,16 +999,22 @@ upb_amalgamation(
":hash",
":lex",
":mem_internal",
"//upb/mini_table:mini_table_internal",
":message_accessors",
":message_internal",
":message_rep_internal",
":message_tagged_ptr",
":port",
":reflection",
":reflection_internal",
":reflection",
":upb",
":wire_internal",
":wire_reader",
":wire_types",
"//upb/mini_descriptor:encode_internal",
"//upb/mini_descriptor:internal",
"//upb/mini_descriptor:mini_descriptor",
"//upb/mini_table:internal",
"//upb/mini_table:mini_table",
],
strip_import_prefix = ["src"],
)
@ -999,8 +1036,8 @@ upb_amalgamation(
libs = [
":base",
":collections_internal",
":descriptor_upb_proto",
":descriptor_upb_proto_reflection",
":descriptor_upb_proto",
":eps_copy_input_stream",
":fastdecode",
":generated_code_support__only_for_generated_code_do_not_use__i_give_permission_to_break_me",
@ -1010,14 +1047,20 @@ upb_amalgamation(
":mem_internal",
":message_accessors",
":message_internal",
"//upb/mini_table:mini_table_internal",
":message_rep_internal",
":message_tagged_ptr",
":port",
":reflection",
":reflection_internal",
":reflection",
":upb",
":wire_internal",
":wire_reader",
":wire_types",
"//upb/mini_descriptor:encode_internal",
"//upb/mini_descriptor:internal",
"//upb/mini_descriptor:mini_descriptor",
"//upb/mini_table:internal",
"//upb/mini_table:mini_table",
],
prefix = "php-",
strip_import_prefix = ["src"],
@ -1051,14 +1094,20 @@ upb_amalgamation(
":mem_internal",
":message_accessors",
":message_internal",
"//upb/mini_table:mini_table_internal",
":message_rep_internal",
":message_tagged_ptr",
":port",
":reflection",
":reflection_internal",
":reflection",
":upb",
":wire_internal",
":wire_reader",
":wire_types",
"//upb/mini_descriptor:encode_internal",
"//upb/mini_descriptor:internal",
"//upb/mini_descriptor:mini_descriptor",
"//upb/mini_table:internal",
"//upb/mini_table:mini_table",
],
prefix = "ruby-",
strip_import_prefix = ["src"],
@ -1100,7 +1149,10 @@ pkg_files(
"upb/**/*.hpp",
"upb/**/*.inc",
],
exclude = ["upb/**/conformance_upb.c"],
exclude = [
"upb/**/conformance_upb.c",
"upb/reflection/stage0/**/*",
],
),
strip_prefix = "",
visibility = ["//python/dist:__pkg__"],

@ -100,6 +100,7 @@ sh_test(
":copy_protos",
":gen_cmakelists",
"//:cmake_files",
"//upb/mini_descriptor:cmake_files",
"//upb/mini_table:cmake_files",
"@utf8_range//:utf8_range_srcs",
],

@ -36,7 +36,6 @@
#include "upb/mem/arena.h"
#include "upb/message/copy.h"
#include "upb/message/extension_internal.h"
#include "upb/mini_table/types.h"
#include "upb/upb.hpp"
#include "upb/wire/decode.h"
#include "upb/wire/encode.h"

@ -42,7 +42,6 @@
#include "upb/collections/array_internal.h"
#include "upb/mem/arena.h"
#include "upb/message/copy.h"
#include "upb/mini_table/types.h"
// Must be last:
#include "upb/port/def.inc"

@ -37,7 +37,6 @@
#include "upb/collections/array.h"
#include "upb/mem/arena.h"
#include "upb/message/copy.h"
#include "upb/mini_table/types.h"
// Must be last:
#include "upb/port/def.inc"

@ -214,6 +214,9 @@ pkg_tar(
"//:LICENSE",
"//:upb_source_files",
"//python:message_extension",
"//upb/mini_descriptor:internal_source_files",
"//upb/mini_descriptor:source_files",
"//upb/mini_table:internal_source_files",
"//upb/mini_table:source_files",
"//upb/util:util_source_files",
"@com_google_protobuf//python:python_source_files",

@ -92,7 +92,7 @@ setup(
'google._upb._message',
glob.glob('google/protobuf/*.c')
+ glob.glob('python/*.c')
+ glob.glob('upb/**/*.c')
+ glob.glob('upb/**/*.c', recursive=True)
+ glob.glob('utf8_range/*.c'),
include_dirs=[current_dir, os.path.join(current_dir, 'utf8_range')],
language='c',

@ -34,7 +34,7 @@
#include "upb/collections/map_internal.h"
#include "upb/message/extension_internal.h"
#include "upb/mini_table/message_internal.h"
#include "upb/message/internal/map_entry.h"
// Must be last.
#include "upb/port/def.inc"

@ -32,7 +32,8 @@
#define UPB_MESSAGE_VALUE_H_
#include "upb/base/string_view.h"
#include "upb/mini_table/types.h"
#include "upb/message/tagged_ptr.h"
#include "upb/mini_table/message.h"
// Must be last.
#include "upb/port/def.inc"

@ -39,15 +39,13 @@
#include "upb/message/extension_internal.h"
#include "upb/message/internal.h"
#include "upb/message/message.h"
#include "upb/mini_table/common.h"
#include "upb/mini_table/decode.h"
#include "upb/mini_table/enum_internal.h"
#include "upb/mini_table/extension_internal.h"
#include "upb/mini_table/field_internal.h"
#include "upb/mini_table/file_internal.h"
#include "upb/mini_table/message_internal.h"
#include "upb/mini_table/sub_internal.h"
#include "upb/mini_table/types.h"
#include "upb/mini_descriptor/decode.h"
#include "upb/mini_table/enum.h"
#include "upb/mini_table/extension.h"
#include "upb/mini_table/field.h"
#include "upb/mini_table/file.h"
#include "upb/mini_table/message.h"
#include "upb/mini_table/sub.h"
#include "upb/wire/decode.h"
#include "upb/wire/decode_fast.h"
#include "upb/wire/encode.h"

@ -31,7 +31,7 @@
#include "upb/collections/array_internal.h"
#include "upb/collections/map.h"
#include "upb/message/message.h"
#include "upb/mini_table/field_internal.h"
#include "upb/mini_table/field.h"
#include "upb/wire/common.h"
#include "upb/wire/decode.h"
#include "upb/wire/encode.h"

@ -35,9 +35,8 @@
#include "upb/collections/map_internal.h"
#include "upb/message/accessors_internal.h"
#include "upb/message/internal.h"
#include "upb/mini_table/common.h"
#include "upb/mini_table/enum_internal.h"
#include "upb/mini_table/field_internal.h"
#include "upb/mini_table/enum.h"
#include "upb/mini_table/field.h"
// Must be last.
#include "upb/port/def.inc"

@ -31,8 +31,7 @@
#include "upb/collections/map_internal.h"
#include "upb/message/extension_internal.h"
#include "upb/message/internal.h"
#include "upb/mini_table/common.h"
#include "upb/mini_table/field_internal.h"
#include "upb/mini_table/internal/field.h"
// Must be last.
#include "upb/port/def.inc"
@ -59,6 +58,62 @@
extern "C" {
#endif
// LINT.IfChange(presence_logic)
// Hasbit access ///////////////////////////////////////////////////////////////
UPB_INLINE size_t _upb_hasbit_ofs(size_t idx) { return idx / 8; }
UPB_INLINE char _upb_hasbit_mask(size_t idx) { return 1 << (idx % 8); }
UPB_INLINE bool _upb_hasbit(const upb_Message* msg, size_t idx) {
return (*UPB_PTR_AT(msg, _upb_hasbit_ofs(idx), const char) &
_upb_hasbit_mask(idx)) != 0;
}
UPB_INLINE void _upb_sethas(const upb_Message* msg, size_t idx) {
(*UPB_PTR_AT(msg, _upb_hasbit_ofs(idx), char)) |= _upb_hasbit_mask(idx);
}
UPB_INLINE void _upb_clearhas(const upb_Message* msg, size_t idx) {
(*UPB_PTR_AT(msg, _upb_hasbit_ofs(idx), char)) &= ~_upb_hasbit_mask(idx);
}
UPB_INLINE size_t _upb_Message_Hasidx(const upb_MiniTableField* f) {
UPB_ASSERT(f->presence > 0);
return f->presence;
}
UPB_INLINE bool _upb_hasbit_field(const upb_Message* msg,
const upb_MiniTableField* f) {
return _upb_hasbit(msg, _upb_Message_Hasidx(f));
}
UPB_INLINE void _upb_sethas_field(const upb_Message* msg,
const upb_MiniTableField* f) {
_upb_sethas(msg, _upb_Message_Hasidx(f));
}
// Oneof case access ///////////////////////////////////////////////////////////
UPB_INLINE size_t _upb_oneofcase_ofs(const upb_MiniTableField* f) {
UPB_ASSERT(f->presence < 0);
return ~(ptrdiff_t)f->presence;
}
UPB_INLINE uint32_t* _upb_oneofcase_field(upb_Message* msg,
const upb_MiniTableField* f) {
return UPB_PTR_AT(msg, _upb_oneofcase_ofs(f), uint32_t);
}
UPB_INLINE uint32_t _upb_getoneofcase_field(const upb_Message* msg,
const upb_MiniTableField* f) {
return *_upb_oneofcase_field((upb_Message*)msg, f);
}
// LINT.ThenChange(GoogleInternalName2)
// LINT.ThenChange(//depot/google3/third_party/upb/js/impl/upb_bits/presence.ts:presence_logic)
UPB_INLINE bool _upb_MiniTableField_InOneOf(const upb_MiniTableField* field) {
return field->presence < 0;
}

@ -40,10 +40,9 @@
#include "google/protobuf/test_messages_proto3.upb.h"
#include "upb/base/string_view.h"
#include "upb/collections/array.h"
#include "upb/mini_table/common.h"
#include "upb/mini_table/decode.h"
#include "upb/mini_table/encode_internal.hpp"
#include "upb/mini_table/field_internal.h"
#include "upb/mini_descriptor/decode.h"
#include "upb/mini_descriptor/internal/encode.hpp"
#include "upb/mini_descriptor/internal/modifiers.h"
#include "upb/test/test.upb.h"
#include "upb/upb.h"
#include "upb/wire/common.h"

@ -32,7 +32,6 @@
#include "upb/message/message.h"
// Must be last.
#include "upb/mini_table/common.h"
#include "upb/port/def.inc"
static bool upb_MessageField_IsMap(const upb_MiniTableField* field) {

@ -30,7 +30,6 @@
#include "upb/collections/message_value.h"
#include "upb/message/internal.h"
#include "upb/mini_table/common.h"
// Must be last.
#include "upb/port/def.inc"

@ -44,9 +44,6 @@
#include "upb/collections/map.h"
#include "upb/mem/arena.h"
#include "upb/message/accessors.h"
#include "upb/mini_table/common.h"
#include "upb/mini_table/encode_internal.hpp"
#include "upb/mini_table/field_internal.h"
#include "upb/test/test.upb.h"
#include "upb/upb.h"

@ -32,7 +32,7 @@
#include "upb/base/string_view.h"
#include "upb/mem/arena.h"
#include "upb/message/message.h"
#include "upb/mini_table/extension_internal.h"
#include "upb/mini_table/extension.h"
// Must be last.
#include "upb/port/def.inc"

@ -41,10 +41,9 @@
#include "upb/hash/common.h"
#include "upb/message/extension_internal.h"
#include "upb/message/message.h"
#include "upb/mini_table/extension_internal.h"
#include "upb/mini_table/extension.h"
#include "upb/mini_table/extension_registry.h"
#include "upb/mini_table/file_internal.h"
#include "upb/mini_table/message_internal.h"
#include "upb/mini_table/message.h"
// Must be last.
#include "upb/port/def.inc"

@ -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_

@ -33,7 +33,7 @@
#define UPB_MESSAGE_MESSAGE_H_
#include "upb/mem/arena.h"
#include "upb/mini_table/types.h"
#include "upb/mini_table/message.h"
// Must be last.
#include "upb/port/def.inc"

@ -32,7 +32,7 @@
#include "upb/collections/map.h"
#include "upb/message/accessors.h"
#include "upb/message/message.h"
#include "upb/mini_table/field_internal.h"
#include "upb/mini_table/field.h"
#include "upb/wire/common.h"
#include "upb/wire/decode.h"
#include "upb/wire/encode.h"

@ -42,10 +42,8 @@
#include "upb/collections/array.h"
#include "upb/message/accessors.h"
#include "upb/message/copy.h"
#include "upb/mini_table/common.h"
#include "upb/mini_table/decode.h"
#include "upb/mini_table/encode_internal.hpp"
#include "upb/mini_table/field_internal.h"
#include "upb/mini_descriptor/internal/encode.hpp"
#include "upb/mini_descriptor/internal/modifiers.h"
#include "upb/test/test.upb.h"
#include "upb/upb.h"
#include "upb/upb.hpp"

@ -39,13 +39,6 @@ extern "C" {
typedef void upb_Message;
typedef struct upb_MiniTable upb_MiniTable;
typedef struct upb_MiniTableEnum upb_MiniTableEnum;
typedef struct upb_MiniTableExtension upb_MiniTableExtension;
typedef struct upb_MiniTableField upb_MiniTableField;
typedef struct upb_MiniTableFile upb_MiniTableFile;
typedef union upb_MiniTableSub upb_MiniTableSub;
// When a upb_Message* is stored in a message, array, or map, it is stored in a
// tagged form. If the tag bit is set, the referenced upb_Message is of type
// _kUpb_MiniTable_Empty (a sentinel message type with no fields) instead of

@ -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

@ -25,7 +25,7 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "upb/mini_table/decode.h"
#include "upb/mini_descriptor/decode.h"
#include <inttypes.h>
#include <stdlib.h>
@ -33,10 +33,9 @@
#include "upb/base/log2.h"
#include "upb/base/string_view.h"
#include "upb/mem/arena.h"
#include "upb/mini_table/common.h"
#include "upb/mini_table/common_internal.h"
#include "upb/mini_table/enum_internal.h"
#include "upb/mini_table/extension_internal.h"
#include "upb/mini_descriptor/internal/base92.h"
#include "upb/mini_descriptor/internal/modifiers.h"
#include "upb/mini_descriptor/internal/wire_constants.h"
// Must be last.
#include "upb/port/def.inc"

@ -30,7 +30,10 @@
#include "upb/base/status.h"
#include "upb/mem/arena.h"
#include "upb/mini_table/common.h"
#include "upb/mini_table/extension.h"
#include "upb/mini_table/field.h"
#include "upb/mini_table/message.h"
#include "upb/mini_table/sub.h"
// Must be last.
#include "upb/port/def.inc"

@ -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_

@ -25,11 +25,12 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "upb/mini_descriptor/internal/encode.h"
#include "upb/base/log2.h"
#include "upb/mini_table/common.h"
#include "upb/mini_table/common_internal.h"
#include "upb/mini_table/encode_internal.h"
#include "upb/mini_descriptor/internal/base92.h"
#include "upb/mini_descriptor/internal/modifiers.h"
#include "upb/mini_descriptor/internal/wire_constants.h"
// Must be last.
#include "upb/port/def.inc"

@ -25,11 +25,10 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef UPB_MINI_TABLE_ENCODE_INTERNAL_H_
#define UPB_MINI_TABLE_ENCODE_INTERNAL_H_
#ifndef UPB_MINI_DESCRIPTOR_INTERNAL_ENCODE_H_
#define UPB_MINI_DESCRIPTOR_INTERNAL_ENCODE_H_
#include "upb/base/descriptor_constants.h"
#include "upb/mini_table/common.h"
// Must be last.
#include "upb/port/def.inc"
@ -108,4 +107,4 @@ char* upb_MtDataEncoder_EncodeMessageSet(upb_MtDataEncoder* e, char* ptr);
#include "upb/port/undef.inc"
#endif /* UPB_MINI_TABLE_ENCODE_INTERNAL_H_ */
#endif /* UPB_MINI_DESCRIPTOR_INTERNAL_ENCODE_H_ */

@ -31,7 +31,7 @@
#include <string>
#include "upb/base/log2.h"
#include "upb/mini_table/encode_internal.h"
#include "upb/mini_descriptor/internal/encode.h"
namespace upb {

@ -25,6 +25,8 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "upb/mini_descriptor/internal/encode.hpp"
#include <string_view>
#include <vector>
@ -32,11 +34,11 @@
#include "gtest/gtest.h"
#include "absl/container/flat_hash_set.h"
#include "google/protobuf/descriptor.h"
#include "upb/message/internal.h"
#include "upb/mini_table/common_internal.h"
#include "upb/mini_table/decode.h"
#include "upb/mini_table/encode_internal.hpp"
#include "upb/mini_table/enum_internal.h"
#include "upb/message/accessors_internal.h"
#include "upb/mini_descriptor/decode.h"
#include "upb/mini_descriptor/internal/base92.h"
#include "upb/mini_descriptor/internal/modifiers.h"
#include "upb/mini_table/enum.h"
#include "upb/upb.hpp"
#include "upb/wire/decode.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_

@ -25,8 +25,8 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef UPB_MINI_TABLE_COMMON_INTERNAL_H_
#define UPB_MINI_TABLE_COMMON_INTERNAL_H_
#ifndef UPB_MINI_DESCRIPTOR_INTERNAL_WIRE_CONSTANTS_H_
#define UPB_MINI_DESCRIPTOR_INTERNAL_WIRE_CONSTANTS_H_
#include "upb/base/descriptor_constants.h"
@ -86,26 +86,6 @@ enum {
kUpb_EncodedVersion_MessageSetV1 = '&',
};
#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_TABLE_COMMON_INTERNAL_H_ */
#endif // UPB_MINI_DESCRIPTOR_INTERNAL_WIRE_CONSTANTS_H_

@ -1,3 +1,28 @@
# 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.
load(
"//bazel:build_defs.bzl",
"UPB_DEFAULT_COPTS",
@ -9,70 +34,50 @@ load("@rules_pkg//:mappings.bzl", "pkg_files")
cc_library(
name = "mini_table",
srcs = [
"extension_registry.c",
"message.c",
],
hdrs = [
"decode.h",
"enum.h",
"extension.h",
"extension_registry.h",
"types.h",
"field.h",
"file.h",
"message.h",
"sub.h",
],
copts = UPB_DEFAULT_COPTS,
visibility = ["//visibility:public"],
deps = [
":mini_table_internal",
":internal",
"//:base",
"//:hash",
"//:mem",
"//:port",
],
)
cc_library(
name = "mini_table_internal",
name = "internal",
srcs = [
"common.c",
"decode.c",
"encode.c",
"extension_registry.c",
"message_internal.c",
"internal/message.c",
],
hdrs = [
"common.h",
"common_internal.h",
"decode.h",
"encode_internal.h",
"encode_internal.hpp",
"enum_internal.h",
"extension_internal.h",
"extension_registry.h",
"field_internal.h",
"file_internal.h",
"message_internal.h",
"sub_internal.h",
"types.h",
"internal/enum.h",
"internal/extension.h",
"internal/field.h",
"internal/file.h",
"internal/message.h",
"internal/sub.h",
],
visibility = ["//visibility:public"],
deps = [
"//:base",
"//:hash",
"//:mem",
"//:port",
],
)
cc_test(
name = "encode_test",
srcs = ["encode_test.cc"],
deps = [
":mini_table_internal",
"//:collections_internal",
"//:hash",
"//:message_internal",
"//:port",
"//:upb",
"@com_google_absl//absl/container:flat_hash_set",
"@com_google_googletest//:gtest_main",
"@com_google_protobuf//:protobuf",
],
)
# begin:github_only
filegroup(
name = "cmake_files",
@ -93,9 +98,22 @@ pkg_files(
"**/*.c",
"**/*.h",
],
exclude = ["encode_test.cc"],
exclude = ["internal/**", "encode_test.cc"],
),
prefix = "upb/mini_table",
visibility = ["//python/dist:__pkg__"],
)
pkg_files(
name = "internal_source_files",
srcs = glob(
[
"internal/*.c",
"internal/*.h",
],
exclude = ["encode_test.cc"],
),
prefix = "upb/mini_table/internal",
visibility = ["//python/dist:__pkg__"],
)
# end:github_only

@ -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_ */

@ -28,7 +28,7 @@
#include "upb/mini_table/extension_registry.h"
#include "upb/hash/str_table.h"
#include "upb/mini_table/extension_internal.h"
#include "upb/mini_table/extension.h"
// Must be last.
#include "upb/port/def.inc"

@ -29,7 +29,8 @@
#define UPB_MINI_TABLE_EXTENSION_REGISTRY_H_
#include "upb/mem/arena.h"
#include "upb/mini_table/types.h"
#include "upb/mini_table/extension.h"
#include "upb/mini_table/message.h"
// Must be last.
#include "upb/port/def.inc"

@ -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_ */

@ -25,14 +25,11 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef UPB_MINI_TABLE_SUB_INTERNAL_H_
#define UPB_MINI_TABLE_SUB_INTERNAL_H_
#ifndef UPB_MINI_TABLE_FILE_H_
#define UPB_MINI_TABLE_FILE_H_
#include "upb/mini_table/types.h"
#include "upb/mini_table/internal/file.h"
union upb_MiniTableSub {
const upb_MiniTable* submsg;
const upb_MiniTableEnum* subenum;
};
typedef struct upb_MiniTableFile upb_MiniTableFile;
#endif /* UPB_MINI_TABLE_SUB_INTERNAL_H_ */
#endif /* UPB_MINI_TABLE_FILE_H_ */

@ -25,10 +25,8 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef UPB_MINI_TABLE_ENUM_INTERNAL_H_
#define UPB_MINI_TABLE_ENUM_INTERNAL_H_
#include "upb/mini_table/types.h"
#ifndef UPB_MINI_TABLE_INTERNAL_ENUM_H_
#define UPB_MINI_TABLE_INTERNAL_ENUM_H_
// Must be last.
#include "upb/port/def.inc"
@ -49,16 +47,16 @@ typedef enum {
extern "C" {
#endif
UPB_INLINE _kUpb_FastEnumCheck_Status
_upb_MiniTable_CheckEnumValueFast(const upb_MiniTableEnum* e, uint32_t val) {
UPB_INLINE _kUpb_FastEnumCheck_Status _upb_MiniTable_CheckEnumValueFast(
const struct upb_MiniTableEnum* e, uint32_t val) {
if (UPB_UNLIKELY(val >= 64)) return _kUpb_FastEnumCheck_CannotCheckFast;
uint64_t mask = e->data[0] | ((uint64_t)e->data[1] << 32);
return (mask & (1ULL << val)) ? _kUpb_FastEnumCheck_ValueIsInEnum
: _kUpb_FastEnumCheck_ValueIsNotInEnum;
}
UPB_INLINE bool _upb_MiniTable_CheckEnumValueSlow(const upb_MiniTableEnum* e,
uint32_t val) {
UPB_INLINE bool _upb_MiniTable_CheckEnumValueSlow(
const struct upb_MiniTableEnum* e, uint32_t val) {
if (val < e->mask_limit) return e->data[val / 32] & (1ULL << (val % 32));
// OPT: binary search long lists?
const uint32_t* start = &e->data[e->mask_limit / 32];
@ -69,20 +67,10 @@ UPB_INLINE bool _upb_MiniTable_CheckEnumValueSlow(const upb_MiniTableEnum* e,
return false;
}
// Validates enum value against range defined by enum mini table.
UPB_INLINE bool upb_MiniTableEnum_CheckValue(const 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;
}
#ifdef __cplusplus
} /* extern "C" */
#endif
#include "upb/port/undef.inc"
#endif /* UPB_MINI_TABLE_ENUM_INTERNAL_H_ */
#endif /* UPB_MINI_TABLE_INTERNAL_ENUM_H_ */

@ -25,23 +25,23 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef UPB_MINI_TABLE_EXTENSION_INTERNAL_H_
#define UPB_MINI_TABLE_EXTENSION_INTERNAL_H_
#ifndef UPB_MINI_TABLE_INTERNAL_EXTENSION_H_
#define UPB_MINI_TABLE_INTERNAL_EXTENSION_H_
#include "upb/mini_table/field_internal.h"
#include "upb/mini_table/sub_internal.h"
#include "upb/mini_table/internal/field.h"
#include "upb/mini_table/internal/sub.h"
// Must be last.
#include "upb/port/def.inc"
struct upb_MiniTableExtension {
// Do not move this field. We need to be able to alias pointers.
upb_MiniTableField field;
struct upb_MiniTableField field;
const upb_MiniTable* extendee;
upb_MiniTableSub sub; // NULL unless submessage or proto2 enum
const struct upb_MiniTable* extendee;
union upb_MiniTableSub sub; // NULL unless submessage or proto2 enum
};
#include "upb/port/undef.inc"
#endif /* UPB_MINI_TABLE_EXTENSION_INTERNAL_H_ */
#endif /* UPB_MINI_TABLE_INTERNAL_EXTENSION_H_ */

@ -25,11 +25,10 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef UPB_MINI_TABLE_FIELD_INTERNAL_H_
#define UPB_MINI_TABLE_FIELD_INTERNAL_H_
#ifndef UPB_MINI_TABLE_INTERNAL_FIELD_H_
#define UPB_MINI_TABLE_INTERNAL_FIELD_H_
#include "upb/base/descriptor_constants.h"
#include "upb/mini_table/types.h"
// Must be last.
#include "upb/port/def.inc"
@ -91,7 +90,7 @@ typedef enum {
// LINT.ThenChange(//depot/google3/third_party/upb/js/impl/upb_bits/mini_table_field.ts:mini_table_field_layout)
UPB_INLINE upb_FieldRep
_upb_MiniTableField_GetRep(const upb_MiniTableField* field) {
_upb_MiniTableField_GetRep(const struct upb_MiniTableField* field) {
return (upb_FieldRep)(field->mode >> kUpb_FieldRep_Shift);
}
@ -99,94 +98,39 @@ _upb_MiniTableField_GetRep(const upb_MiniTableField* field) {
extern "C" {
#endif
UPB_INLINE upb_FieldMode upb_FieldMode_Get(const upb_MiniTableField* field) {
UPB_INLINE upb_FieldMode
upb_FieldMode_Get(const struct upb_MiniTableField* field) {
return (upb_FieldMode)(field->mode & 3);
}
UPB_INLINE void _upb_MiniTableField_CheckIsArray(
const upb_MiniTableField* field) {
const struct upb_MiniTableField* field) {
UPB_ASSUME(_upb_MiniTableField_GetRep(field) == kUpb_FieldRep_NativePointer);
UPB_ASSUME(upb_FieldMode_Get(field) == kUpb_FieldMode_Array);
UPB_ASSUME(field->presence == 0);
}
UPB_INLINE void _upb_MiniTableField_CheckIsMap(
const upb_MiniTableField* field) {
const struct upb_MiniTableField* field) {
UPB_ASSUME(_upb_MiniTableField_GetRep(field) == kUpb_FieldRep_NativePointer);
UPB_ASSUME(upb_FieldMode_Get(field) == kUpb_FieldMode_Map);
UPB_ASSUME(field->presence == 0);
}
UPB_INLINE bool upb_IsRepeatedOrMap(const upb_MiniTableField* field) {
UPB_INLINE bool upb_IsRepeatedOrMap(const struct upb_MiniTableField* field) {
// This works because upb_FieldMode has no value 3.
return !(field->mode & kUpb_FieldMode_Scalar);
}
UPB_INLINE bool upb_IsSubMessage(const upb_MiniTableField* field) {
UPB_INLINE bool upb_IsSubMessage(const struct upb_MiniTableField* field) {
return field->UPB_PRIVATE(descriptortype) == kUpb_FieldType_Message ||
field->UPB_PRIVATE(descriptortype) == kUpb_FieldType_Group;
}
// LINT.IfChange(presence_logic)
// Hasbit access ///////////////////////////////////////////////////////////////
UPB_INLINE size_t _upb_hasbit_ofs(size_t idx) { return idx / 8; }
UPB_INLINE char _upb_hasbit_mask(size_t idx) { return 1 << (idx % 8); }
UPB_INLINE bool _upb_hasbit(const upb_Message* msg, size_t idx) {
return (*UPB_PTR_AT(msg, _upb_hasbit_ofs(idx), const char) &
_upb_hasbit_mask(idx)) != 0;
}
UPB_INLINE void _upb_sethas(const upb_Message* msg, size_t idx) {
(*UPB_PTR_AT(msg, _upb_hasbit_ofs(idx), char)) |= _upb_hasbit_mask(idx);
}
UPB_INLINE void _upb_clearhas(const upb_Message* msg, size_t idx) {
(*UPB_PTR_AT(msg, _upb_hasbit_ofs(idx), char)) &= ~_upb_hasbit_mask(idx);
}
UPB_INLINE size_t _upb_Message_Hasidx(const upb_MiniTableField* f) {
UPB_ASSERT(f->presence > 0);
return f->presence;
}
UPB_INLINE bool _upb_hasbit_field(const upb_Message* msg,
const upb_MiniTableField* f) {
return _upb_hasbit(msg, _upb_Message_Hasidx(f));
}
UPB_INLINE void _upb_sethas_field(const upb_Message* msg,
const upb_MiniTableField* f) {
_upb_sethas(msg, _upb_Message_Hasidx(f));
}
// Oneof case access ///////////////////////////////////////////////////////////
UPB_INLINE size_t _upb_oneofcase_ofs(const upb_MiniTableField* f) {
UPB_ASSERT(f->presence < 0);
return ~(ptrdiff_t)f->presence;
}
UPB_INLINE uint32_t* _upb_oneofcase_field(upb_Message* msg,
const upb_MiniTableField* f) {
return UPB_PTR_AT(msg, _upb_oneofcase_ofs(f), uint32_t);
}
UPB_INLINE uint32_t _upb_getoneofcase_field(const upb_Message* msg,
const upb_MiniTableField* f) {
return *_upb_oneofcase_field((upb_Message*)msg, f);
}
// LINT.ThenChange(GoogleInternalName2)
// LINT.ThenChange(//depot/google3/third_party/upb/js/impl/upb_bits/presence.ts:presence_logic)
#ifdef __cplusplus
} /* extern "C" */
#endif
#include "upb/port/undef.inc"
#endif /* UPB_MINI_TABLE_FIELD_INTERNAL_H_ */
#endif /* UPB_MINI_TABLE_INTERNAL_FIELD_H_ */

@ -25,10 +25,12 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef UPB_MINI_TABLE_FILE_INTERNAL_H_
#define UPB_MINI_TABLE_FILE_INTERNAL_H_
#ifndef UPB_MINI_TABLE_INTERNAL_FILE_H_
#define UPB_MINI_TABLE_INTERNAL_FILE_H_
#include "upb/mini_table/types.h"
#include "upb/mini_table/internal/enum.h"
#include "upb/mini_table/internal/extension.h"
#include "upb/mini_table/internal/message.h"
// Must be last.
#include "upb/port/def.inc"
@ -44,4 +46,4 @@ struct upb_MiniTableFile {
#include "upb/port/undef.inc"
#endif /* UPB_MINI_TABLE_FILE_INTERNAL_H_ */
#endif /* UPB_MINI_TABLE_INTERNAL_FILE_H_ */

@ -25,9 +25,9 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "upb/mini_table/message_internal.h"
#include "upb/mini_table/internal/message.h"
const upb_MiniTable _kUpb_MiniTable_Empty = {
const struct upb_MiniTable _kUpb_MiniTable_Empty = {
.subs = NULL,
.fields = NULL,
.size = 0,

@ -25,16 +25,16 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef UPB_MINI_TABLE_MESSAGE_INTERNAL_H_
#define UPB_MINI_TABLE_MESSAGE_INTERNAL_H_
#ifndef UPB_MINI_TABLE_INTERNAL_MESSAGE_H_
#define UPB_MINI_TABLE_INTERNAL_MESSAGE_H_
#include "upb/base/string_view.h"
#include "upb/hash/common.h"
#include "upb/mini_table/types.h"
#include "upb/mini_table/internal/field.h"
// Must be last.
#include "upb/port/def.inc"
typedef void upb_Message;
struct upb_Decoder;
typedef const char* _upb_FieldParser(struct upb_Decoder* d, const char* ptr,
upb_Message* msg, intptr_t table,
@ -58,12 +58,14 @@ typedef enum {
// LINT.IfChange(mini_table_layout)
union upb_MiniTableSub;
// upb_MiniTable represents the memory layout of a given upb_MessageDef.
// The members are public so generated code can initialize them,
// but users MUST NOT directly read or write any of its members.
struct upb_MiniTable {
const upb_MiniTableSub* subs;
const upb_MiniTableField* fields;
const union upb_MiniTableSub* subs;
const struct upb_MiniTableField* fields;
// Must be aligned to sizeof(void*). Doesn't include internal members like
// unknown fields, extension dict, pointer to msglayout, etc.
@ -83,40 +85,12 @@ struct upb_MiniTable {
// LINT.ThenChange(//depot/google3/third_party/upb/js/impl/upb_bits/mini_table.ts:presence_logic)
// 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;
#ifdef __cplusplus
extern "C" {
#endif
// A MiniTable for an empty message, used for unlinked sub-messages.
extern const upb_MiniTable _kUpb_MiniTable_Empty;
extern const struct upb_MiniTable _kUpb_MiniTable_Empty;
// Computes a bitmask in which the |l->required_count| lowest bits are set,
// except that we skip the lowest bit (because upb never uses hasbit 0).
@ -124,7 +98,7 @@ extern const upb_MiniTable _kUpb_MiniTable_Empty;
// Sample output:
// requiredmask(1) => 0b10 (0x2)
// requiredmask(5) => 0b111110 (0x3e)
UPB_INLINE uint64_t upb_MiniTable_requiredmask(const upb_MiniTable* l) {
UPB_INLINE uint64_t upb_MiniTable_requiredmask(const struct upb_MiniTable* l) {
int n = l->required_count;
assert(0 < n && n <= 63);
return ((1ULL << n) - 1) << 1;
@ -136,4 +110,4 @@ UPB_INLINE uint64_t upb_MiniTable_requiredmask(const upb_MiniTable* l) {
#include "upb/port/undef.inc"
#endif /* UPB_MINI_TABLE_MESSAGE_INTERNAL_H_ */
#endif /* UPB_MINI_TABLE_INTERNAL_MESSAGE_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_ */

@ -25,34 +25,16 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "upb/mini_table/common.h"
#include "upb/mini_table/message.h"
#include <inttypes.h>
#include "upb/mem/arena.h"
#include "upb/mini_table/common_internal.h"
#include "upb/mini_table/internal/message.h"
// Must be last.
#include "upb/port/def.inc"
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,
};
const upb_MiniTableField* upb_MiniTable_FindFieldByNumber(
const upb_MiniTable* t, uint32_t number) {
const size_t i = ((size_t)number) - 1; // 0 wraps to SIZE_MAX

@ -25,34 +25,22 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef UPB_MINI_TABLE_COMMON_H_
#define UPB_MINI_TABLE_COMMON_H_
#ifndef UPB_MINI_TABLE_MESSAGE_H_
#define UPB_MINI_TABLE_MESSAGE_H_
#include "upb/mini_table/field_internal.h"
#include "upb/mini_table/message_internal.h"
#include "upb/mini_table/sub_internal.h"
#include "upb/mini_table/enum.h"
#include "upb/mini_table/field.h"
#include "upb/mini_table/internal/message.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;
#ifdef __cplusplus
extern "C" {
#endif
typedef struct upb_MiniTable upb_MiniTable;
UPB_API const upb_MiniTableField* upb_MiniTable_FindFieldByNumber(
const upb_MiniTable* table, uint32_t number);
@ -61,74 +49,6 @@ UPB_API_INLINE const upb_MiniTableField* upb_MiniTable_GetFieldByIndex(
return &t->fields[index];
}
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;
}
}
// Returns the MiniTable for this message field. If the field is unlinked,
// returns NULL.
UPB_API_INLINE const upb_MiniTable* upb_MiniTable_GetSubMessageTable(
@ -182,4 +102,4 @@ bool upb_MiniTable_NextOneofField(const upb_MiniTable* m,
#include "upb/port/undef.inc"
#endif /* UPB_MINI_TABLE_COMMON_H_ */
#endif /* UPB_MINI_TABLE_MESSAGE_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_ */

@ -28,7 +28,7 @@
#ifndef UPB_REFLECTION_DEF_POOL_INTERNAL_H_
#define UPB_REFLECTION_DEF_POOL_INTERNAL_H_
#include "upb/mini_table/decode.h"
#include "upb/mini_descriptor/decode.h"
#include "upb/reflection/def_pool.h"
// Must be last.

@ -29,7 +29,7 @@
#define UPB_REFLECTION_DESC_STATE_INTERNAL_H_
#include "upb/mem/arena.h"
#include "upb/mini_table/encode_internal.h"
#include "upb/mini_descriptor/internal/encode.h"
// Must be last.
#include "upb/port/def.inc"

@ -27,7 +27,7 @@
#include "upb/hash/int_table.h"
#include "upb/hash/str_table.h"
#include "upb/mini_table/decode.h"
#include "upb/mini_descriptor/decode.h"
#include "upb/reflection/def_builder_internal.h"
#include "upb/reflection/def_type.h"
#include "upb/reflection/desc_state_internal.h"

@ -28,7 +28,8 @@
#include <ctype.h>
#include <errno.h>
#include "upb/mini_table/decode.h"
#include "upb/mini_descriptor/decode.h"
#include "upb/mini_descriptor/internal/modifiers.h"
#include "upb/reflection/def.h"
#include "upb/reflection/def_builder_internal.h"
#include "upb/reflection/def_pool.h"

@ -33,7 +33,7 @@
#include "upb/hash/common.h"
#include "upb/message/accessors.h"
#include "upb/message/message.h"
#include "upb/mini_table/field_internal.h"
#include "upb/mini_table/field.h"
#include "upb/reflection/def.h"
#include "upb/reflection/def_pool.h"
#include "upb/reflection/def_type.h"

@ -27,7 +27,8 @@
#include "upb/hash/int_table.h"
#include "upb/hash/str_table.h"
#include "upb/mini_table/decode.h"
#include "upb/mini_descriptor/decode.h"
#include "upb/mini_descriptor/internal/modifiers.h"
#include "upb/reflection/def.h"
#include "upb/reflection/def_builder_internal.h"
#include "upb/reflection/def_type.h"

@ -139,8 +139,10 @@ cc_library(
visibility = ["//:__subpackages__"],
deps = [
"//:upb",
"//:mini_table",
"//:mini_table_internal",
"//:port",
"//upb/mini_descriptor",
],
)
@ -201,6 +203,7 @@ cc_test(
":test_messages_proto3_upb_proto",
":test_upb_proto",
"//:upb",
"//:mini_table",
"//:mini_table_internal",
"//:port",
"@com_google_googletest//:gtest_main",

@ -28,8 +28,8 @@
#include "upb/test/fuzz_util.h"
#include "upb/message/message.h"
#include "upb/mini_table/decode.h"
#include "upb/mini_table/extension_internal.h"
#include "upb/mini_descriptor/decode.h"
#include "upb/mini_table/extension.h"
#include "upb/mini_table/extension_registry.h"
#include "upb/upb.hpp"

@ -32,7 +32,7 @@
#include <vector>
#include "upb/mini_table/extension_registry.h"
#include "upb/mini_table/types.h"
// #include "upb/mini_table/types.h"
namespace upb {
namespace fuzz {

@ -28,7 +28,8 @@
#include "gtest/gtest.h"
#include "google/protobuf/test_messages_proto2.upb.h"
#include "google/protobuf/test_messages_proto3.upb.h"
#include "upb/mini_table/common.h"
#include "upb/mini_table/field.h"
#include "upb/mini_table/message.h"
#include "upb/test/test.upb.h"
#include "upb/upb.hpp"

@ -31,4 +31,4 @@
#include "upb/collections/map.h"
#include "upb/message/accessors_split64.h"
#include "upb/message/message.h"
#include "upb/mini_table/decode.h"
#include "upb/mini_descriptor/decode.h"

@ -34,8 +34,8 @@
#include "upb/collections/map_internal.h"
#include "upb/mem/arena_internal.h"
#include "upb/message/accessors_internal.h"
#include "upb/mini_table/common.h"
#include "upb/mini_table/enum_internal.h"
#include "upb/message/internal/map_entry.h"
#include "upb/mini_table/sub.h"
#include "upb/port/atomic.h"
#include "upb/wire/common.h"
#include "upb/wire/common_internal.h"

@ -33,8 +33,9 @@
#include "upb/collections/array_internal.h"
#include "upb/collections/map_sorter_internal.h"
#include "upb/message/accessors_internal.h"
#include "upb/message/extension_internal.h"
#include "upb/mini_table/sub_internal.h"
#include "upb/mini_table/sub.h"
#include "upb/wire/common.h"
#include "upb/wire/common_internal.h"
#include "upb/wire/swap_internal.h"

@ -132,6 +132,7 @@ bootstrap_cc_library(
"//:mini_table_internal",
"//:port",
"//:upb",
"//upb/mini_descriptor",
"@com_google_absl//absl/container:flat_hash_map",
"@com_google_absl//absl/strings",
],
@ -229,6 +230,7 @@ cc_library(
"//:port",
"//:reflection",
"//upb/json",
"//upb/mini_descriptor",
],
)

@ -30,7 +30,7 @@
#include <inttypes.h>
#include "google/protobuf/compiler/plugin.upb.h"
#include "upb/mini_table/decode.h"
#include "upb/mini_descriptor/decode.h"
#include "upb/reflection/def.h"
// Must be last.

@ -28,7 +28,7 @@
#include <string>
#include <unordered_set>
#include "upb/mini_table/extension_internal.h"
#include "upb/mini_table/internal/extension.h"
#include "upbc/common.h"
namespace upbc {

@ -40,7 +40,7 @@
// end:github_only
#include "absl/container/flat_hash_map.h"
#include "upb/mini_table/decode.h"
#include "upb/mini_descriptor/decode.h"
#include "upb/reflection/def.h"
#include "upb/reflection/def.hpp"
#include "upb/upb.hpp"

Loading…
Cancel
Save