From 5076e6206e327942630e82bcec145826cf380559 Mon Sep 17 00:00:00 2001 From: Charles OuGuo Date: Wed, 13 Dec 2023 01:42:26 -0800 Subject: [PATCH 001/255] In ruby/README.md, correct a target name (#15041) When attempting to run the Ruby tests, I noticed that the README is slightly off; it points to a target that doesn't exist: ``` charles@AlterCation:~/protobuf$ bazel test //ruby/tests/... //ruby:ffi=enabled --test_env=PROTOCOL_BUFFERS_RUBY_IMPLEMENTATION=FFI ERROR: Skipping '//ruby:ffi=enabled': no such target '//ruby:ffi=enabled': target 'ffi=enabled' not declared in package 'ruby' defined by /home/charles/protobuf/ruby/BUILD.bazel (did you mean 'ffi_enabled'? Tip: use `query "//ruby:*"` to see all the targets in that package) ERROR: no such target '//ruby:ffi=enabled': target 'ffi=enabled' not declared in package 'ruby' defined by /home/charles/protobuf/ruby/BUILD.bazel (did you mean 'ffi_enabled'? Tip: use `query "//ruby:*"` to see all the targets in that package) INFO: Elapsed time: 0.679s INFO: 0 processes. ERROR: Build did NOT complete successfully ERROR: Couldn't start the build. Unable to run tests charles@AlterCation:~/protobuf$ ``` Instead, it looks like `//ruby:ffi_enabled` is what you're supposed to use, which sets the flag on: https://github.com/protocolbuffers/protobuf/blob/main/ruby/BUILD.bazel#L28-L30 Closes #15041 COPYBARA_INTEGRATE_REVIEW=https://github.com/protocolbuffers/protobuf/pull/15041 from shaldengeki:ouguoc/fix-ruby-readme-ffi-enabled 245d84942df99984906aea76a547d76dc754c2d5 PiperOrigin-RevId: 590501532 --- ruby/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ruby/README.md b/ruby/README.md index cba3d58f3c7d3..c7c71b733a811 100644 --- a/ruby/README.md +++ b/ruby/README.md @@ -115,7 +115,7 @@ $ bazel test //ruby/tests/... To run tests against the FFI implementation: ``` -$ bazel test //ruby/tests/... //ruby:ffi=enabled --test_env=PROTOCOL_BUFFERS_RUBY_IMPLEMENTATION=FFI +$ bazel test //ruby/tests/... //ruby:ffi_enabled --test_env=PROTOCOL_BUFFERS_RUBY_IMPLEMENTATION=FFI ``` Version Number Scheme From b19deb92751a54b057f1e5aa51327ca1c182bf9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrian=20Sad=C5=82ocha?= Date: Wed, 13 Dec 2023 08:37:04 -0800 Subject: [PATCH 002/255] Remove separate setters for singular scalars PiperOrigin-RevId: 590609323 --- rust/test/cpp/interop/main.rs | 8 +-- rust/test/shared/accessors_proto3_test.rs | 20 ++----- rust/test/shared/accessors_test.rs | 56 +++++++++---------- rust/test/shared/serialization_test.rs | 4 +- .../rust/accessors/singular_scalar.cc | 20 ------- 5 files changed, 40 insertions(+), 68 deletions(-) diff --git a/rust/test/cpp/interop/main.rs b/rust/test/cpp/interop/main.rs index e07e255b1f032..c95ceea03a564 100644 --- a/rust/test/cpp/interop/main.rs +++ b/rust/test/cpp/interop/main.rs @@ -40,9 +40,9 @@ fn mutate_message_in_cpp() { } let mut msg2 = TestAllTypes::new(); - msg2.optional_int64_set(Some(42)); + msg2.optional_int64_mut().set(42); msg2.optional_bytes_mut().set(b"something mysterious"); - msg2.optional_bool_set(Some(false)); + msg2.optional_bool_mut().set(false); proto_assert_eq!(msg1, msg2); } @@ -50,7 +50,7 @@ fn mutate_message_in_cpp() { #[test] fn deserialize_in_rust() { let mut msg1 = TestAllTypes::new(); - msg1.optional_int64_set(Some(-1)); + msg1.optional_int64_mut().set(-1); msg1.optional_bytes_mut().set(b"some cool data I guess"); let serialized = unsafe { SerializeTestAllTypes(msg1.__unstable_cpp_repr_grant_permission_to_break()) }; @@ -63,7 +63,7 @@ fn deserialize_in_rust() { #[test] fn deserialize_in_cpp() { let mut msg1 = TestAllTypes::new(); - msg1.optional_int64_set(Some(-1)); + msg1.optional_int64_mut().set(-1); msg1.optional_bytes_mut().set(b"some cool data I guess"); let data = msg1.serialize(); diff --git a/rust/test/shared/accessors_proto3_test.rs b/rust/test/shared/accessors_proto3_test.rs index 5ae20143ff756..48424433d1e45 100644 --- a/rust/test/shared/accessors_proto3_test.rs +++ b/rust/test/shared/accessors_proto3_test.rs @@ -26,10 +26,6 @@ fn test_fixed32_accessors() { msg.optional_fixed32_mut().set(u32::default()); assert_that!(msg.optional_fixed32(), eq(0)); assert_that!(msg.optional_fixed32_mut().get(), eq(0)); - - msg.optional_fixed32_set(43); - assert_that!(msg.optional_fixed32(), eq(43)); - assert_that!(msg.optional_fixed32_mut().get(), eq(43)); } #[test] @@ -45,10 +41,6 @@ fn test_bool_accessors() { msg.optional_bool_mut().set(bool::default()); assert_that!(msg.optional_bool(), eq(false)); assert_that!(msg.optional_bool_mut().get(), eq(false)); - - msg.optional_bool_set(true); - assert_that!(msg.optional_bool(), eq(true)); - assert_that!(msg.optional_bool_mut().get(), eq(true)); } #[test] @@ -199,11 +191,11 @@ fn test_oneof_accessors() { let mut msg = TestAllTypes::new(); assert_that!(msg.oneof_field(), matches_pattern!(not_set(_))); - msg.oneof_uint32_set(Some(7)); + msg.oneof_uint32_mut().set(7); assert_that!(msg.oneof_uint32_opt(), eq(Optional::Set(7))); assert_that!(msg.oneof_field(), matches_pattern!(OneofUint32(eq(7)))); - msg.oneof_uint32_set(None); + msg.oneof_uint32_mut().clear(); assert_that!(msg.oneof_uint32_opt(), eq(Optional::Unset(0))); assert_that!(msg.oneof_field(), matches_pattern!(not_set(_))); @@ -217,7 +209,7 @@ fn test_oneof_accessors() { // eq(Optional::Unset(_))); assert_that!(msg.oneof_field(), // matches_pattern!(OneofNestedMessage(_))); - msg.oneof_uint32_set(Some(7)); + msg.oneof_uint32_mut().set(7); msg.oneof_bytes_mut().set(b"123"); assert_that!(msg.oneof_uint32_opt(), eq(Optional::Unset(0))); assert_that!(msg.oneof_field(), matches_pattern!(OneofBytes(eq(b"123")))); @@ -233,7 +225,7 @@ fn test_oneof_mut_accessors() { let mut msg = TestAllTypes::new(); assert_that!(msg.oneof_field_mut(), matches_pattern!(not_set(_))); - msg.oneof_uint32_set(Some(7)); + msg.oneof_uint32_mut().set(7); match msg.oneof_field_mut() { OneofUint32(mut v) => { @@ -252,10 +244,10 @@ fn test_oneof_mut_accessors() { matches_pattern!(TestAllTypes_::OneofField::OneofUint32(eq(8))) ); - msg.oneof_uint32_set(None); + msg.oneof_uint32_mut().clear(); assert_that!(msg.oneof_field_mut(), matches_pattern!(not_set(_))); - msg.oneof_uint32_set(Some(7)); + msg.oneof_uint32_mut().set(7); msg.oneof_bytes_mut().set(b"123"); assert_that!(msg.oneof_field_mut(), matches_pattern!(OneofBytes(_))); } diff --git a/rust/test/shared/accessors_test.rs b/rust/test/shared/accessors_test.rs index 0fbb535ee5d96..9f7d75ff53268 100644 --- a/rust/test/shared/accessors_test.rs +++ b/rust/test/shared/accessors_test.rs @@ -43,11 +43,11 @@ fn test_optional_fixed32_accessors() { assert_that!(msg.optional_fixed32_opt(), eq(Optional::Unset(0))); assert_that!(msg.optional_fixed32(), eq(0)); - msg.optional_fixed32_set(Some(99)); + msg.optional_fixed32_mut().set(99); assert_that!(msg.optional_fixed32_opt(), eq(Optional::Set(99))); assert_that!(msg.optional_fixed32(), eq(99)); - msg.optional_fixed32_set(None); + msg.optional_fixed32_mut().clear(); assert_that!(msg.optional_fixed32_opt(), eq(Optional::Unset(0))); assert_that!(msg.optional_fixed32(), eq(0)); } @@ -85,11 +85,11 @@ fn test_optional_fixed64_accessors() { assert_that!(msg.optional_fixed64_opt(), eq(Optional::Unset(0))); assert_that!(msg.optional_fixed64(), eq(0)); - msg.optional_fixed64_set(Some(2000)); + msg.optional_fixed64_mut().set(2000); assert_that!(msg.optional_fixed64_opt(), eq(Optional::Set(2000))); assert_that!(msg.optional_fixed64(), eq(2000)); - msg.optional_fixed64_set(None); + msg.optional_fixed64_mut().clear(); assert_that!(msg.optional_fixed64_opt(), eq(Optional::Unset(0))); assert_that!(msg.optional_fixed64(), eq(0)); } @@ -127,11 +127,11 @@ fn test_optional_int32_accessors() { assert_that!(msg.optional_int32_opt(), eq(Optional::Unset(0))); assert_that!(msg.optional_int32(), eq(0)); - msg.optional_int32_set(Some(1)); + msg.optional_int32_mut().set(1); assert_that!(msg.optional_int32_opt(), eq(Optional::Set(1))); assert_that!(msg.optional_int32(), eq(1)); - msg.optional_int32_set(None); + msg.optional_int32_mut().clear(); assert_that!(msg.optional_int32_opt(), eq(Optional::Unset(0))); assert_that!(msg.optional_int32(), eq(0)); } @@ -169,11 +169,11 @@ fn test_optional_int64_accessors() { assert_that!(msg.optional_int64_opt(), eq(Optional::Unset(0))); assert_that!(msg.optional_int64(), eq(0)); - msg.optional_int64_set(Some(42)); + msg.optional_int64_mut().set(42); assert_that!(msg.optional_int64_opt(), eq(Optional::Set(42))); assert_that!(msg.optional_int64(), eq(42)); - msg.optional_int64_set(None); + msg.optional_int64_mut().clear(); assert_that!(msg.optional_int64_opt(), eq(Optional::Unset(0))); assert_that!(msg.optional_int64(), eq(0)); } @@ -211,11 +211,11 @@ fn test_optional_sint32_accessors() { assert_that!(msg.optional_sint32_opt(), eq(Optional::Unset(0))); assert_that!(msg.optional_sint32(), eq(0)); - msg.optional_sint32_set(Some(-22)); + msg.optional_sint32_mut().set(-22); assert_that!(msg.optional_sint32_opt(), eq(Optional::Set(-22))); assert_that!(msg.optional_sint32(), eq(-22)); - msg.optional_sint32_set(None); + msg.optional_sint32_mut().clear(); assert_that!(msg.optional_sint32_opt(), eq(Optional::Unset(0))); assert_that!(msg.optional_sint32(), eq(0)); } @@ -253,11 +253,11 @@ fn test_optional_sint64_accessors() { assert_that!(msg.optional_sint64_opt(), eq(Optional::Unset(0))); assert_that!(msg.optional_sint64(), eq(0)); - msg.optional_sint64_set(Some(7000)); + msg.optional_sint64_mut().set(7000); assert_that!(msg.optional_sint64_opt(), eq(Optional::Set(7000))); assert_that!(msg.optional_sint64(), eq(7000)); - msg.optional_sint64_set(None); + msg.optional_sint64_mut().clear(); assert_that!(msg.optional_sint64_opt(), eq(Optional::Unset(0))); assert_that!(msg.optional_sint64(), eq(0)); } @@ -295,11 +295,11 @@ fn test_optional_uint32_accessors() { assert_that!(msg.optional_uint32_opt(), eq(Optional::Unset(0))); assert_that!(msg.optional_uint32(), eq(0)); - msg.optional_uint32_set(Some(9001)); + msg.optional_uint32_mut().set(9001); assert_that!(msg.optional_uint32_opt(), eq(Optional::Set(9001))); assert_that!(msg.optional_uint32(), eq(9001)); - msg.optional_uint32_set(None); + msg.optional_uint32_mut().clear(); assert_that!(msg.optional_uint32_opt(), eq(Optional::Unset(0))); assert_that!(msg.optional_uint32(), eq(0)); } @@ -337,11 +337,11 @@ fn test_optional_uint64_accessors() { assert_that!(msg.optional_uint64_opt(), eq(Optional::Unset(0))); assert_that!(msg.optional_uint64(), eq(0)); - msg.optional_uint64_set(Some(42)); + msg.optional_uint64_mut().set(42); assert_that!(msg.optional_uint64_opt(), eq(Optional::Set(42))); assert_that!(msg.optional_uint64(), eq(42)); - msg.optional_uint64_set(None); + msg.optional_uint64_mut().clear(); assert_that!(msg.optional_uint64_opt(), eq(Optional::Unset(0))); assert_that!(msg.optional_uint64(), eq(0)); } @@ -379,11 +379,11 @@ fn test_optional_float_accessors() { assert_that!(msg.optional_float_opt(), eq(Optional::Unset(0.0))); assert_that!(msg.optional_float(), eq(0.0)); - msg.optional_float_set(Some(std::f32::consts::PI)); + msg.optional_float_mut().set(std::f32::consts::PI); assert_that!(msg.optional_float_opt(), eq(Optional::Set(std::f32::consts::PI))); assert_that!(msg.optional_float(), eq(std::f32::consts::PI)); - msg.optional_float_set(None); + msg.optional_float_mut().clear(); assert_that!(msg.optional_float_opt(), eq(Optional::Unset(0.0))); assert_that!(msg.optional_float(), eq(0.0)); } @@ -421,11 +421,11 @@ fn test_optional_double_accessors() { assert_that!(msg.optional_double_opt(), eq(Optional::Unset(0.0))); assert_that!(msg.optional_double(), eq(0.0)); - msg.optional_double_set(Some(-10.99)); + msg.optional_double_mut().set(-10.99); assert_that!(msg.optional_double_opt(), eq(Optional::Set(-10.99))); assert_that!(msg.optional_double(), eq(-10.99)); - msg.optional_double_set(None); + msg.optional_double_mut().clear(); assert_that!(msg.optional_double_opt(), eq(Optional::Unset(0.0))); assert_that!(msg.optional_double(), eq(0.0)); } @@ -462,10 +462,10 @@ fn test_optional_bool_accessors() { let mut msg = TestAllTypes::new(); assert_that!(msg.optional_bool_opt(), eq(Optional::Unset(false))); - msg.optional_bool_set(Some(true)); + msg.optional_bool_mut().set(true); assert_that!(msg.optional_bool_opt(), eq(Optional::Set(true))); - msg.optional_bool_set(None); + msg.optional_bool_mut().clear(); assert_that!(msg.optional_bool_opt(), eq(Optional::Unset(false))); } @@ -687,15 +687,15 @@ fn test_oneof_accessors() { let mut msg = TestAllTypes::new(); assert_that!(msg.oneof_field(), matches_pattern!(not_set(_))); - msg.oneof_uint32_set(Some(7)); + msg.oneof_uint32_mut().set(7); assert_that!(msg.oneof_uint32_opt(), eq(Optional::Set(7))); assert_that!(msg.oneof_field(), matches_pattern!(OneofUint32(eq(7)))); - msg.oneof_uint32_set(None); + msg.oneof_uint32_mut().clear(); assert_that!(msg.oneof_uint32_opt(), eq(Optional::Unset(0))); assert_that!(msg.oneof_field(), matches_pattern!(not_set(_))); - msg.oneof_uint32_set(Some(7)); + msg.oneof_uint32_mut().set(7); msg.oneof_bytes_mut().set(b"123"); assert_that!(msg.oneof_uint32_opt(), eq(Optional::Unset(0))); @@ -709,7 +709,7 @@ fn test_oneof_mut_accessors() { let mut msg = TestAllTypes::new(); assert_that!(msg.oneof_field_mut(), matches_pattern!(not_set(_))); - msg.oneof_uint32_set(Some(7)); + msg.oneof_uint32_mut().set(7); match msg.oneof_field_mut() { OneofUint32(mut v) => { @@ -728,10 +728,10 @@ fn test_oneof_mut_accessors() { matches_pattern!(TestAllTypes_::OneofField::OneofUint32(eq(8))) ); - msg.oneof_uint32_set(None); + msg.oneof_uint32_mut().clear(); assert_that!(msg.oneof_field_mut(), matches_pattern!(not_set(_))); - msg.oneof_uint32_set(Some(7)); + msg.oneof_uint32_mut().set(7); msg.oneof_bytes_mut().set(b"123"); assert_that!(msg.oneof_field_mut(), matches_pattern!(OneofBytes(_))); } diff --git a/rust/test/shared/serialization_test.rs b/rust/test/shared/serialization_test.rs index b5600bbf4c581..0515223fb70d6 100644 --- a/rust/test/shared/serialization_test.rs +++ b/rust/test/shared/serialization_test.rs @@ -11,8 +11,8 @@ use unittest_proto::proto2_unittest::TestAllTypes; #[test] fn serialize_deserialize_message() { let mut msg = TestAllTypes::new(); - msg.optional_int64_set(Some(42)); - msg.optional_bool_set(Some(true)); + msg.optional_int64_mut().set(42); + msg.optional_bool_mut().set(true); msg.optional_bytes_mut().set(b"serialize deserialize test"); let serialized = msg.serialize(); diff --git a/src/google/protobuf/compiler/rust/accessors/singular_scalar.cc b/src/google/protobuf/compiler/rust/accessors/singular_scalar.cc index 98593c79d8f67..d3d65dcada77f 100644 --- a/src/google/protobuf/compiler/rust/accessors/singular_scalar.cc +++ b/src/google/protobuf/compiler/rust/accessors/singular_scalar.cc @@ -50,25 +50,6 @@ void SingularScalar::InMsgImpl(Context field) const { {"getter_thunk", Thunk(field, "get")}, {"setter_thunk", Thunk(field, "set")}, {"clearer_thunk", Thunk(field, "clear")}, - {"field_setter", - [&] { - if (field.desc().has_presence()) { - field.Emit({}, R"rs( - pub fn r#$field$_set(&mut self, val: Option<$Scalar$>) { - match val { - Some(val) => unsafe { $setter_thunk$(self.inner.msg, val) }, - None => unsafe { $clearer_thunk$(self.inner.msg) }, - } - } - )rs"); - } else { - field.Emit({}, R"rs( - pub fn r#$field$_set(&mut self, val: $Scalar$) { - unsafe { $setter_thunk$(self.inner.msg, val) } - } - )rs"); - } - }}, {"field_mutator_getter", [&] { if (field.desc().has_presence()) { @@ -124,7 +105,6 @@ void SingularScalar::InMsgImpl(Context field) const { R"rs( $getter$ $getter_opt$ - $field_setter$ $field_mutator_getter$ )rs"); } From 54d4839ecb33258388887771b43fb62834e7c7e6 Mon Sep 17 00:00:00 2001 From: Hong Shin Date: Wed, 13 Dec 2023 10:04:34 -0800 Subject: [PATCH 003/255] Add submsg support for bytes_mut message.cc:GetterForViewOrMut has been updated to support _mut for byte fields inside submsgs. PiperOrigin-RevId: 590634540 --- rust/test/shared/simple_nested_test.rs | 3 +- src/google/protobuf/compiler/rust/message.cc | 42 ++++++++++++++++---- 2 files changed, 36 insertions(+), 9 deletions(-) diff --git a/rust/test/shared/simple_nested_test.rs b/rust/test/shared/simple_nested_test.rs index 1fe175a8b41b8..c0932d33ee1e5 100644 --- a/rust/test/shared/simple_nested_test.rs +++ b/rust/test/shared/simple_nested_test.rs @@ -81,6 +81,7 @@ fn test_nested_muts() { }) ); assert_that!(inner_msg.string_mut().get(), eq("")); + assert_that!(inner_msg.bytes_mut().get(), eq(b"")); set_and_test_mut!(inner_msg => double_mut, 543.21; @@ -95,8 +96,8 @@ fn test_nested_muts() { fixed64_mut, 999; bool_mut, true; string_mut, "hi"; + bytes_mut, b"bye"; ); - // TODO: add mutation test for bytes } #[test] diff --git a/src/google/protobuf/compiler/rust/message.cc b/src/google/protobuf/compiler/rust/message.cc index 7a73e93101fd0..e55def55f672a 100644 --- a/src/google/protobuf/compiler/rust/message.cc +++ b/src/google/protobuf/compiler/rust/message.cc @@ -258,17 +258,43 @@ void GetterForViewOrMut(Context field, bool is_mut) { $maybe_mutator$ )rs"); } else if (fieldType == FieldDescriptor::TYPE_BYTES) { - field.Emit( - { - {"field", fieldName}, - {"self", self}, - {"getter_thunk", getter_thunk}, - {"RsType", rsType}, - }, - R"rs( + field.Emit({{"field", fieldName}, + {"self", self}, + {"getter_thunk", getter_thunk}, + {"setter_thunk", setter_thunk}, + {"RsType", rsType}, + {"maybe_mutator", + [&] { + if (is_mut) { + field.Emit({}, R"rs( + pub fn r#$field$_mut(&self) -> $pb$::Mut<'_, $RsType$> { + static VTABLE: $pbi$::BytesMutVTable = + $pbi$::BytesMutVTable::new( + $pbi$::Private, + $getter_thunk$, + $setter_thunk$, + ); + + unsafe { + <$pb$::Mut<$RsType$>>::from_inner( + $pbi$::Private, + $pbi$::RawVTableMutator::new( + $pbi$::Private, + self.inner, + &VTABLE, + ) + ) + } + } + )rs"); + } + }}}, + R"rs( pub fn r#$field$(&self) -> $pb$::View<'_, $RsType$> { unsafe { $getter_thunk$($self$).as_ref() } } + + $maybe_mutator$ )rs"); } else { field.Emit({{"field", fieldName}, From 9a50a839700f675a12e3255c0d08dabdb148c5e6 Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Wed, 13 Dec 2023 10:11:53 -0800 Subject: [PATCH 004/255] Move the descriptor message part of ClassData into a subclass and keep a bool on the base. This reduces the cost for Lite messages, while keeping the type the same size of descriptor messages. PiperOrigin-RevId: 590637288 --- src/google/protobuf/compiler/cpp/message.cc | 79 ++-- .../compiler/java/java_features.pb.cc | 13 +- src/google/protobuf/compiler/plugin.pb.cc | 52 ++- src/google/protobuf/cpp_features.pb.cc | 13 +- src/google/protobuf/descriptor.pb.cc | 416 +++++++++++------- src/google/protobuf/dynamic_message.cc | 9 +- .../protobuf/generated_message_bases.cc | 9 +- src/google/protobuf/implicit_weak_message.h | 3 +- src/google/protobuf/map_entry.h | 9 +- src/google/protobuf/message.cc | 4 +- src/google/protobuf/message_lite.cc | 8 +- src/google/protobuf/message_lite.h | 49 ++- 12 files changed, 389 insertions(+), 275 deletions(-) diff --git a/src/google/protobuf/compiler/cpp/message.cc b/src/google/protobuf/compiler/cpp/message.cc index 765935ae8e1c1..2372b36364fa6 100644 --- a/src/google/protobuf/compiler/cpp/message.cc +++ b/src/google/protobuf/compiler/cpp/message.cc @@ -3497,63 +3497,35 @@ void MessageGenerator::GenerateClassData(io::Printer* p) { Formatter format(p); if (HasSimpleBaseClass(descriptor_, options_)) return; - const auto class_data_members = [&] { - p->Emit( - { - {"merge_impl", - [&] { - // TODO: This check is not needed once we migrate - // CheckTypeAndMergeFrom to ClassData fully. - if (HasDescriptorMethods(descriptor_->file(), options_)) { - p->Emit(R"cc( - $classname$::MergeImpl, - )cc"); - } else { - p->Emit(R"cc( - nullptr, // MergeImpl - )cc"); - } - }}, - {"on_demand_register_arena_dtor", - [&] { - if (NeedsArenaDestructor() == ArenaDtorNeeds::kOnDemand) { - p->Emit(R"cc( - $classname$::OnDemandRegisterArenaDtor, - )cc"); - } else { - p->Emit(R"cc( - nullptr, // OnDemandRegisterArenaDtor - )cc"); - } - }}, - {"descriptor_methods", - [&] { - if (HasDescriptorMethods(descriptor_->file(), options_)) { - p->Emit(R"cc( - &::$proto_ns$::Message::kDescriptorMethods, - )cc"); - } else { - p->Emit(R"cc( - nullptr, // DescriptorMethods - )cc"); - } - }}, - }, - R"cc( - $merge_impl$, $on_demand_register_arena_dtor$, $descriptor_methods$, - PROTOBUF_FIELD_OFFSET($classname$, $cached_size$), - )cc"); + const auto on_demand_register_arena_dtor = [&] { + if (NeedsArenaDestructor() == ArenaDtorNeeds::kOnDemand) { + p->Emit(R"cc( + $classname$::OnDemandRegisterArenaDtor, + )cc"); + } else { + p->Emit(R"cc( + nullptr, // OnDemandRegisterArenaDtor + )cc"); + } }; if (HasDescriptorMethods(descriptor_->file(), options_)) { p->Emit( - {{"class_data_members", class_data_members}}, + { + {"on_demand_register_arena_dtor", on_demand_register_arena_dtor}, + }, R"cc( const ::$proto_ns$::MessageLite::ClassData* $classname$::GetClassData() const { - PROTOBUF_CONSTINIT static const ::$proto_ns$::MessageLite::ClassData - _data_ = { - $class_data_members$, + PROTOBUF_CONSTINIT static const ::$proto_ns$::MessageLite:: + ClassDataFull _data_ = { + { + $on_demand_register_arena_dtor$, + PROTOBUF_FIELD_OFFSET($classname$, $cached_size$), + false, + }, + &$classname$::MergeImpl, + &$classname$::kDescriptorMethods, }; return &_data_; } @@ -3561,8 +3533,8 @@ void MessageGenerator::GenerateClassData(io::Printer* p) { } else { p->Emit( { - {"class_data_members", class_data_members}, {"type_size", descriptor_->full_name().size() + 1}, + {"on_demand_register_arena_dtor", on_demand_register_arena_dtor}, }, R"cc( const ::$proto_ns$::MessageLite::ClassData* @@ -3571,9 +3543,12 @@ void MessageGenerator::GenerateClassData(io::Printer* p) { ::$proto_ns$::MessageLite::ClassData header; char type_name[$type_size$]; }; + PROTOBUF_CONSTINIT static const ClassData_ _data_ = { { - $class_data_members$, + $on_demand_register_arena_dtor$, + PROTOBUF_FIELD_OFFSET($classname$, $cached_size$), + true, }, "$full_name$", }; diff --git a/src/google/protobuf/compiler/java/java_features.pb.cc b/src/google/protobuf/compiler/java/java_features.pb.cc index 2a632e7eb4e74..aa2052a891cc2 100644 --- a/src/google/protobuf/compiler/java/java_features.pb.cc +++ b/src/google/protobuf/compiler/java/java_features.pb.cc @@ -190,12 +190,15 @@ inline void JavaFeatures::SharedDtor() { const ::google::protobuf::MessageLite::ClassData* JavaFeatures::GetClassData() const { - PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite::ClassData - _data_ = { - JavaFeatures::MergeImpl, - nullptr, // OnDemandRegisterArenaDtor - &::google::protobuf::Message::kDescriptorMethods, + PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite:: + ClassDataFull _data_ = { + { + nullptr, // OnDemandRegisterArenaDtor PROTOBUF_FIELD_OFFSET(JavaFeatures, _impl_._cached_size_), + false, + }, + &JavaFeatures::MergeImpl, + &JavaFeatures::kDescriptorMethods, }; return &_data_; } diff --git a/src/google/protobuf/compiler/plugin.pb.cc b/src/google/protobuf/compiler/plugin.pb.cc index 3c1ac59a0d52b..788f52fbbe45b 100644 --- a/src/google/protobuf/compiler/plugin.pb.cc +++ b/src/google/protobuf/compiler/plugin.pb.cc @@ -376,12 +376,15 @@ inline void Version::SharedDtor() { const ::google::protobuf::MessageLite::ClassData* Version::GetClassData() const { - PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite::ClassData - _data_ = { - Version::MergeImpl, - nullptr, // OnDemandRegisterArenaDtor - &::google::protobuf::Message::kDescriptorMethods, + PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite:: + ClassDataFull _data_ = { + { + nullptr, // OnDemandRegisterArenaDtor PROTOBUF_FIELD_OFFSET(Version, _impl_._cached_size_), + false, + }, + &Version::MergeImpl, + &Version::kDescriptorMethods, }; return &_data_; } @@ -684,12 +687,15 @@ inline void CodeGeneratorRequest::SharedDtor() { const ::google::protobuf::MessageLite::ClassData* CodeGeneratorRequest::GetClassData() const { - PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite::ClassData - _data_ = { - CodeGeneratorRequest::MergeImpl, - nullptr, // OnDemandRegisterArenaDtor - &::google::protobuf::Message::kDescriptorMethods, + PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite:: + ClassDataFull _data_ = { + { + nullptr, // OnDemandRegisterArenaDtor PROTOBUF_FIELD_OFFSET(CodeGeneratorRequest, _impl_._cached_size_), + false, + }, + &CodeGeneratorRequest::MergeImpl, + &CodeGeneratorRequest::kDescriptorMethods, }; return &_data_; } @@ -1026,12 +1032,15 @@ inline void CodeGeneratorResponse_File::SharedDtor() { const ::google::protobuf::MessageLite::ClassData* CodeGeneratorResponse_File::GetClassData() const { - PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite::ClassData - _data_ = { - CodeGeneratorResponse_File::MergeImpl, - nullptr, // OnDemandRegisterArenaDtor - &::google::protobuf::Message::kDescriptorMethods, + PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite:: + ClassDataFull _data_ = { + { + nullptr, // OnDemandRegisterArenaDtor PROTOBUF_FIELD_OFFSET(CodeGeneratorResponse_File, _impl_._cached_size_), + false, + }, + &CodeGeneratorResponse_File::MergeImpl, + &CodeGeneratorResponse_File::kDescriptorMethods, }; return &_data_; } @@ -1343,12 +1352,15 @@ inline void CodeGeneratorResponse::SharedDtor() { const ::google::protobuf::MessageLite::ClassData* CodeGeneratorResponse::GetClassData() const { - PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite::ClassData - _data_ = { - CodeGeneratorResponse::MergeImpl, - nullptr, // OnDemandRegisterArenaDtor - &::google::protobuf::Message::kDescriptorMethods, + PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite:: + ClassDataFull _data_ = { + { + nullptr, // OnDemandRegisterArenaDtor PROTOBUF_FIELD_OFFSET(CodeGeneratorResponse, _impl_._cached_size_), + false, + }, + &CodeGeneratorResponse::MergeImpl, + &CodeGeneratorResponse::kDescriptorMethods, }; return &_data_; } diff --git a/src/google/protobuf/cpp_features.pb.cc b/src/google/protobuf/cpp_features.pb.cc index 0d38ae0ace728..9ed6b80a99bce 100644 --- a/src/google/protobuf/cpp_features.pb.cc +++ b/src/google/protobuf/cpp_features.pb.cc @@ -157,12 +157,15 @@ inline void CppFeatures::SharedDtor() { const ::google::protobuf::MessageLite::ClassData* CppFeatures::GetClassData() const { - PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite::ClassData - _data_ = { - CppFeatures::MergeImpl, - nullptr, // OnDemandRegisterArenaDtor - &::google::protobuf::Message::kDescriptorMethods, + PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite:: + ClassDataFull _data_ = { + { + nullptr, // OnDemandRegisterArenaDtor PROTOBUF_FIELD_OFFSET(CppFeatures, _impl_._cached_size_), + false, + }, + &CppFeatures::MergeImpl, + &CppFeatures::kDescriptorMethods, }; return &_data_; } diff --git a/src/google/protobuf/descriptor.pb.cc b/src/google/protobuf/descriptor.pb.cc index 269a8dc448ec9..951acb9338524 100644 --- a/src/google/protobuf/descriptor.pb.cc +++ b/src/google/protobuf/descriptor.pb.cc @@ -2400,12 +2400,15 @@ inline void FileDescriptorSet::SharedDtor() { const ::google::protobuf::MessageLite::ClassData* FileDescriptorSet::GetClassData() const { - PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite::ClassData - _data_ = { - FileDescriptorSet::MergeImpl, - nullptr, // OnDemandRegisterArenaDtor - &::google::protobuf::Message::kDescriptorMethods, + PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite:: + ClassDataFull _data_ = { + { + nullptr, // OnDemandRegisterArenaDtor PROTOBUF_FIELD_OFFSET(FileDescriptorSet, _impl_._cached_size_), + false, + }, + &FileDescriptorSet::MergeImpl, + &FileDescriptorSet::kDescriptorMethods, }; return &_data_; } @@ -2629,12 +2632,15 @@ inline void FileDescriptorProto::SharedDtor() { const ::google::protobuf::MessageLite::ClassData* FileDescriptorProto::GetClassData() const { - PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite::ClassData - _data_ = { - FileDescriptorProto::MergeImpl, - nullptr, // OnDemandRegisterArenaDtor - &::google::protobuf::Message::kDescriptorMethods, + PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite:: + ClassDataFull _data_ = { + { + nullptr, // OnDemandRegisterArenaDtor PROTOBUF_FIELD_OFFSET(FileDescriptorProto, _impl_._cached_size_), + false, + }, + &FileDescriptorProto::MergeImpl, + &FileDescriptorProto::kDescriptorMethods, }; return &_data_; } @@ -3196,12 +3202,15 @@ inline void DescriptorProto_ExtensionRange::SharedDtor() { const ::google::protobuf::MessageLite::ClassData* DescriptorProto_ExtensionRange::GetClassData() const { - PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite::ClassData - _data_ = { - DescriptorProto_ExtensionRange::MergeImpl, - nullptr, // OnDemandRegisterArenaDtor - &::google::protobuf::Message::kDescriptorMethods, + PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite:: + ClassDataFull _data_ = { + { + nullptr, // OnDemandRegisterArenaDtor PROTOBUF_FIELD_OFFSET(DescriptorProto_ExtensionRange, _impl_._cached_size_), + false, + }, + &DescriptorProto_ExtensionRange::MergeImpl, + &DescriptorProto_ExtensionRange::kDescriptorMethods, }; return &_data_; } @@ -3455,12 +3464,15 @@ inline void DescriptorProto_ReservedRange::SharedDtor() { const ::google::protobuf::MessageLite::ClassData* DescriptorProto_ReservedRange::GetClassData() const { - PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite::ClassData - _data_ = { - DescriptorProto_ReservedRange::MergeImpl, - nullptr, // OnDemandRegisterArenaDtor - &::google::protobuf::Message::kDescriptorMethods, + PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite:: + ClassDataFull _data_ = { + { + nullptr, // OnDemandRegisterArenaDtor PROTOBUF_FIELD_OFFSET(DescriptorProto_ReservedRange, _impl_._cached_size_), + false, + }, + &DescriptorProto_ReservedRange::MergeImpl, + &DescriptorProto_ReservedRange::kDescriptorMethods, }; return &_data_; } @@ -3710,12 +3722,15 @@ inline void DescriptorProto::SharedDtor() { const ::google::protobuf::MessageLite::ClassData* DescriptorProto::GetClassData() const { - PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite::ClassData - _data_ = { - DescriptorProto::MergeImpl, - nullptr, // OnDemandRegisterArenaDtor - &::google::protobuf::Message::kDescriptorMethods, + PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite:: + ClassDataFull _data_ = { + { + nullptr, // OnDemandRegisterArenaDtor PROTOBUF_FIELD_OFFSET(DescriptorProto, _impl_._cached_size_), + false, + }, + &DescriptorProto::MergeImpl, + &DescriptorProto::kDescriptorMethods, }; return &_data_; } @@ -4191,12 +4206,15 @@ inline void ExtensionRangeOptions_Declaration::SharedDtor() { const ::google::protobuf::MessageLite::ClassData* ExtensionRangeOptions_Declaration::GetClassData() const { - PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite::ClassData - _data_ = { - ExtensionRangeOptions_Declaration::MergeImpl, - nullptr, // OnDemandRegisterArenaDtor - &::google::protobuf::Message::kDescriptorMethods, + PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite:: + ClassDataFull _data_ = { + { + nullptr, // OnDemandRegisterArenaDtor PROTOBUF_FIELD_OFFSET(ExtensionRangeOptions_Declaration, _impl_._cached_size_), + false, + }, + &ExtensionRangeOptions_Declaration::MergeImpl, + &ExtensionRangeOptions_Declaration::kDescriptorMethods, }; return &_data_; } @@ -4521,12 +4539,15 @@ inline void ExtensionRangeOptions::SharedDtor() { const ::google::protobuf::MessageLite::ClassData* ExtensionRangeOptions::GetClassData() const { - PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite::ClassData - _data_ = { - ExtensionRangeOptions::MergeImpl, - nullptr, // OnDemandRegisterArenaDtor - &::google::protobuf::Message::kDescriptorMethods, + PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite:: + ClassDataFull _data_ = { + { + nullptr, // OnDemandRegisterArenaDtor PROTOBUF_FIELD_OFFSET(ExtensionRangeOptions, _impl_._cached_size_), + false, + }, + &ExtensionRangeOptions::MergeImpl, + &ExtensionRangeOptions::kDescriptorMethods, }; return &_data_; } @@ -4866,12 +4887,15 @@ inline void FieldDescriptorProto::SharedDtor() { const ::google::protobuf::MessageLite::ClassData* FieldDescriptorProto::GetClassData() const { - PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite::ClassData - _data_ = { - FieldDescriptorProto::MergeImpl, - nullptr, // OnDemandRegisterArenaDtor - &::google::protobuf::Message::kDescriptorMethods, + PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite:: + ClassDataFull _data_ = { + { + nullptr, // OnDemandRegisterArenaDtor PROTOBUF_FIELD_OFFSET(FieldDescriptorProto, _impl_._cached_size_), + false, + }, + &FieldDescriptorProto::MergeImpl, + &FieldDescriptorProto::kDescriptorMethods, }; return &_data_; } @@ -5365,12 +5389,15 @@ inline void OneofDescriptorProto::SharedDtor() { const ::google::protobuf::MessageLite::ClassData* OneofDescriptorProto::GetClassData() const { - PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite::ClassData - _data_ = { - OneofDescriptorProto::MergeImpl, - nullptr, // OnDemandRegisterArenaDtor - &::google::protobuf::Message::kDescriptorMethods, + PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite:: + ClassDataFull _data_ = { + { + nullptr, // OnDemandRegisterArenaDtor PROTOBUF_FIELD_OFFSET(OneofDescriptorProto, _impl_._cached_size_), + false, + }, + &OneofDescriptorProto::MergeImpl, + &OneofDescriptorProto::kDescriptorMethods, }; return &_data_; } @@ -5603,12 +5630,15 @@ inline void EnumDescriptorProto_EnumReservedRange::SharedDtor() { const ::google::protobuf::MessageLite::ClassData* EnumDescriptorProto_EnumReservedRange::GetClassData() const { - PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite::ClassData - _data_ = { - EnumDescriptorProto_EnumReservedRange::MergeImpl, - nullptr, // OnDemandRegisterArenaDtor - &::google::protobuf::Message::kDescriptorMethods, + PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite:: + ClassDataFull _data_ = { + { + nullptr, // OnDemandRegisterArenaDtor PROTOBUF_FIELD_OFFSET(EnumDescriptorProto_EnumReservedRange, _impl_._cached_size_), + false, + }, + &EnumDescriptorProto_EnumReservedRange::MergeImpl, + &EnumDescriptorProto_EnumReservedRange::kDescriptorMethods, }; return &_data_; } @@ -5848,12 +5878,15 @@ inline void EnumDescriptorProto::SharedDtor() { const ::google::protobuf::MessageLite::ClassData* EnumDescriptorProto::GetClassData() const { - PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite::ClassData - _data_ = { - EnumDescriptorProto::MergeImpl, - nullptr, // OnDemandRegisterArenaDtor - &::google::protobuf::Message::kDescriptorMethods, + PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite:: + ClassDataFull _data_ = { + { + nullptr, // OnDemandRegisterArenaDtor PROTOBUF_FIELD_OFFSET(EnumDescriptorProto, _impl_._cached_size_), + false, + }, + &EnumDescriptorProto::MergeImpl, + &EnumDescriptorProto::kDescriptorMethods, }; return &_data_; } @@ -6187,12 +6220,15 @@ inline void EnumValueDescriptorProto::SharedDtor() { const ::google::protobuf::MessageLite::ClassData* EnumValueDescriptorProto::GetClassData() const { - PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite::ClassData - _data_ = { - EnumValueDescriptorProto::MergeImpl, - nullptr, // OnDemandRegisterArenaDtor - &::google::protobuf::Message::kDescriptorMethods, + PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite:: + ClassDataFull _data_ = { + { + nullptr, // OnDemandRegisterArenaDtor PROTOBUF_FIELD_OFFSET(EnumValueDescriptorProto, _impl_._cached_size_), + false, + }, + &EnumValueDescriptorProto::MergeImpl, + &EnumValueDescriptorProto::kDescriptorMethods, }; return &_data_; } @@ -6472,12 +6508,15 @@ inline void ServiceDescriptorProto::SharedDtor() { const ::google::protobuf::MessageLite::ClassData* ServiceDescriptorProto::GetClassData() const { - PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite::ClassData - _data_ = { - ServiceDescriptorProto::MergeImpl, - nullptr, // OnDemandRegisterArenaDtor - &::google::protobuf::Message::kDescriptorMethods, + PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite:: + ClassDataFull _data_ = { + { + nullptr, // OnDemandRegisterArenaDtor PROTOBUF_FIELD_OFFSET(ServiceDescriptorProto, _impl_._cached_size_), + false, + }, + &ServiceDescriptorProto::MergeImpl, + &ServiceDescriptorProto::kDescriptorMethods, }; return &_data_; } @@ -6772,12 +6811,15 @@ inline void MethodDescriptorProto::SharedDtor() { const ::google::protobuf::MessageLite::ClassData* MethodDescriptorProto::GetClassData() const { - PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite::ClassData - _data_ = { - MethodDescriptorProto::MergeImpl, - nullptr, // OnDemandRegisterArenaDtor - &::google::protobuf::Message::kDescriptorMethods, + PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite:: + ClassDataFull _data_ = { + { + nullptr, // OnDemandRegisterArenaDtor PROTOBUF_FIELD_OFFSET(MethodDescriptorProto, _impl_._cached_size_), + false, + }, + &MethodDescriptorProto::MergeImpl, + &MethodDescriptorProto::kDescriptorMethods, }; return &_data_; } @@ -7180,12 +7222,15 @@ inline void FileOptions::SharedDtor() { const ::google::protobuf::MessageLite::ClassData* FileOptions::GetClassData() const { - PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite::ClassData - _data_ = { - FileOptions::MergeImpl, - nullptr, // OnDemandRegisterArenaDtor - &::google::protobuf::Message::kDescriptorMethods, + PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite:: + ClassDataFull _data_ = { + { + nullptr, // OnDemandRegisterArenaDtor PROTOBUF_FIELD_OFFSET(FileOptions, _impl_._cached_size_), + false, + }, + &FileOptions::MergeImpl, + &FileOptions::kDescriptorMethods, }; return &_data_; } @@ -7982,12 +8027,15 @@ inline void MessageOptions::SharedDtor() { const ::google::protobuf::MessageLite::ClassData* MessageOptions::GetClassData() const { - PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite::ClassData - _data_ = { - MessageOptions::MergeImpl, - nullptr, // OnDemandRegisterArenaDtor - &::google::protobuf::Message::kDescriptorMethods, + PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite:: + ClassDataFull _data_ = { + { + nullptr, // OnDemandRegisterArenaDtor PROTOBUF_FIELD_OFFSET(MessageOptions, _impl_._cached_size_), + false, + }, + &MessageOptions::MergeImpl, + &MessageOptions::kDescriptorMethods, }; return &_data_; } @@ -8350,12 +8398,15 @@ inline void FieldOptions_EditionDefault::SharedDtor() { const ::google::protobuf::MessageLite::ClassData* FieldOptions_EditionDefault::GetClassData() const { - PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite::ClassData - _data_ = { - FieldOptions_EditionDefault::MergeImpl, - nullptr, // OnDemandRegisterArenaDtor - &::google::protobuf::Message::kDescriptorMethods, + PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite:: + ClassDataFull _data_ = { + { + nullptr, // OnDemandRegisterArenaDtor PROTOBUF_FIELD_OFFSET(FieldOptions_EditionDefault, _impl_._cached_size_), + false, + }, + &FieldOptions_EditionDefault::MergeImpl, + &FieldOptions_EditionDefault::kDescriptorMethods, }; return &_data_; } @@ -8608,12 +8659,15 @@ inline void FieldOptions::SharedDtor() { const ::google::protobuf::MessageLite::ClassData* FieldOptions::GetClassData() const { - PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite::ClassData - _data_ = { - FieldOptions::MergeImpl, - nullptr, // OnDemandRegisterArenaDtor - &::google::protobuf::Message::kDescriptorMethods, + PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite:: + ClassDataFull _data_ = { + { + nullptr, // OnDemandRegisterArenaDtor PROTOBUF_FIELD_OFFSET(FieldOptions, _impl_._cached_size_), + false, + }, + &FieldOptions::MergeImpl, + &FieldOptions::kDescriptorMethods, }; return &_data_; } @@ -9136,12 +9190,15 @@ inline void OneofOptions::SharedDtor() { const ::google::protobuf::MessageLite::ClassData* OneofOptions::GetClassData() const { - PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite::ClassData - _data_ = { - OneofOptions::MergeImpl, - nullptr, // OnDemandRegisterArenaDtor - &::google::protobuf::Message::kDescriptorMethods, + PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite:: + ClassDataFull _data_ = { + { + nullptr, // OnDemandRegisterArenaDtor PROTOBUF_FIELD_OFFSET(OneofOptions, _impl_._cached_size_), + false, + }, + &OneofOptions::MergeImpl, + &OneofOptions::kDescriptorMethods, }; return &_data_; } @@ -9408,12 +9465,15 @@ inline void EnumOptions::SharedDtor() { const ::google::protobuf::MessageLite::ClassData* EnumOptions::GetClassData() const { - PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite::ClassData - _data_ = { - EnumOptions::MergeImpl, - nullptr, // OnDemandRegisterArenaDtor - &::google::protobuf::Message::kDescriptorMethods, + PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite:: + ClassDataFull _data_ = { + { + nullptr, // OnDemandRegisterArenaDtor PROTOBUF_FIELD_OFFSET(EnumOptions, _impl_._cached_size_), + false, + }, + &EnumOptions::MergeImpl, + &EnumOptions::kDescriptorMethods, }; return &_data_; } @@ -9754,12 +9814,15 @@ inline void EnumValueOptions::SharedDtor() { const ::google::protobuf::MessageLite::ClassData* EnumValueOptions::GetClassData() const { - PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite::ClassData - _data_ = { - EnumValueOptions::MergeImpl, - nullptr, // OnDemandRegisterArenaDtor - &::google::protobuf::Message::kDescriptorMethods, + PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite:: + ClassDataFull _data_ = { + { + nullptr, // OnDemandRegisterArenaDtor PROTOBUF_FIELD_OFFSET(EnumValueOptions, _impl_._cached_size_), + false, + }, + &EnumValueOptions::MergeImpl, + &EnumValueOptions::kDescriptorMethods, }; return &_data_; } @@ -10076,12 +10139,15 @@ inline void ServiceOptions::SharedDtor() { const ::google::protobuf::MessageLite::ClassData* ServiceOptions::GetClassData() const { - PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite::ClassData - _data_ = { - ServiceOptions::MergeImpl, - nullptr, // OnDemandRegisterArenaDtor - &::google::protobuf::Message::kDescriptorMethods, + PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite:: + ClassDataFull _data_ = { + { + nullptr, // OnDemandRegisterArenaDtor PROTOBUF_FIELD_OFFSET(ServiceOptions, _impl_._cached_size_), + false, + }, + &ServiceOptions::MergeImpl, + &ServiceOptions::kDescriptorMethods, }; return &_data_; } @@ -10379,12 +10445,15 @@ inline void MethodOptions::SharedDtor() { const ::google::protobuf::MessageLite::ClassData* MethodOptions::GetClassData() const { - PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite::ClassData - _data_ = { - MethodOptions::MergeImpl, - nullptr, // OnDemandRegisterArenaDtor - &::google::protobuf::Message::kDescriptorMethods, + PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite:: + ClassDataFull _data_ = { + { + nullptr, // OnDemandRegisterArenaDtor PROTOBUF_FIELD_OFFSET(MethodOptions, _impl_._cached_size_), + false, + }, + &MethodOptions::MergeImpl, + &MethodOptions::kDescriptorMethods, }; return &_data_; } @@ -10697,12 +10766,15 @@ inline void UninterpretedOption_NamePart::SharedDtor() { const ::google::protobuf::MessageLite::ClassData* UninterpretedOption_NamePart::GetClassData() const { - PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite::ClassData - _data_ = { - UninterpretedOption_NamePart::MergeImpl, - nullptr, // OnDemandRegisterArenaDtor - &::google::protobuf::Message::kDescriptorMethods, + PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite:: + ClassDataFull _data_ = { + { + nullptr, // OnDemandRegisterArenaDtor PROTOBUF_FIELD_OFFSET(UninterpretedOption_NamePart, _impl_._cached_size_), + false, + }, + &UninterpretedOption_NamePart::MergeImpl, + &UninterpretedOption_NamePart::kDescriptorMethods, }; return &_data_; } @@ -10954,12 +11026,15 @@ inline void UninterpretedOption::SharedDtor() { const ::google::protobuf::MessageLite::ClassData* UninterpretedOption::GetClassData() const { - PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite::ClassData - _data_ = { - UninterpretedOption::MergeImpl, - nullptr, // OnDemandRegisterArenaDtor - &::google::protobuf::Message::kDescriptorMethods, + PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite:: + ClassDataFull _data_ = { + { + nullptr, // OnDemandRegisterArenaDtor PROTOBUF_FIELD_OFFSET(UninterpretedOption, _impl_._cached_size_), + false, + }, + &UninterpretedOption::MergeImpl, + &UninterpretedOption::kDescriptorMethods, }; return &_data_; } @@ -11335,12 +11410,15 @@ inline void FeatureSet::SharedDtor() { const ::google::protobuf::MessageLite::ClassData* FeatureSet::GetClassData() const { - PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite::ClassData - _data_ = { - FeatureSet::MergeImpl, - nullptr, // OnDemandRegisterArenaDtor - &::google::protobuf::Message::kDescriptorMethods, + PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite:: + ClassDataFull _data_ = { + { + nullptr, // OnDemandRegisterArenaDtor PROTOBUF_FIELD_OFFSET(FeatureSet, _impl_._cached_size_), + false, + }, + &FeatureSet::MergeImpl, + &FeatureSet::kDescriptorMethods, }; return &_data_; } @@ -11683,12 +11761,15 @@ inline void FeatureSetDefaults_FeatureSetEditionDefault::SharedDtor() { const ::google::protobuf::MessageLite::ClassData* FeatureSetDefaults_FeatureSetEditionDefault::GetClassData() const { - PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite::ClassData - _data_ = { - FeatureSetDefaults_FeatureSetEditionDefault::MergeImpl, - nullptr, // OnDemandRegisterArenaDtor - &::google::protobuf::Message::kDescriptorMethods, + PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite:: + ClassDataFull _data_ = { + { + nullptr, // OnDemandRegisterArenaDtor PROTOBUF_FIELD_OFFSET(FeatureSetDefaults_FeatureSetEditionDefault, _impl_._cached_size_), + false, + }, + &FeatureSetDefaults_FeatureSetEditionDefault::MergeImpl, + &FeatureSetDefaults_FeatureSetEditionDefault::kDescriptorMethods, }; return &_data_; } @@ -11938,12 +12019,15 @@ inline void FeatureSetDefaults::SharedDtor() { const ::google::protobuf::MessageLite::ClassData* FeatureSetDefaults::GetClassData() const { - PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite::ClassData - _data_ = { - FeatureSetDefaults::MergeImpl, - nullptr, // OnDemandRegisterArenaDtor - &::google::protobuf::Message::kDescriptorMethods, + PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite:: + ClassDataFull _data_ = { + { + nullptr, // OnDemandRegisterArenaDtor PROTOBUF_FIELD_OFFSET(FeatureSetDefaults, _impl_._cached_size_), + false, + }, + &FeatureSetDefaults::MergeImpl, + &FeatureSetDefaults::kDescriptorMethods, }; return &_data_; } @@ -12209,12 +12293,15 @@ inline void SourceCodeInfo_Location::SharedDtor() { const ::google::protobuf::MessageLite::ClassData* SourceCodeInfo_Location::GetClassData() const { - PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite::ClassData - _data_ = { - SourceCodeInfo_Location::MergeImpl, - nullptr, // OnDemandRegisterArenaDtor - &::google::protobuf::Message::kDescriptorMethods, + PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite:: + ClassDataFull _data_ = { + { + nullptr, // OnDemandRegisterArenaDtor PROTOBUF_FIELD_OFFSET(SourceCodeInfo_Location, _impl_._cached_size_), + false, + }, + &SourceCodeInfo_Location::MergeImpl, + &SourceCodeInfo_Location::kDescriptorMethods, }; return &_data_; } @@ -12533,12 +12620,15 @@ inline void SourceCodeInfo::SharedDtor() { const ::google::protobuf::MessageLite::ClassData* SourceCodeInfo::GetClassData() const { - PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite::ClassData - _data_ = { - SourceCodeInfo::MergeImpl, - nullptr, // OnDemandRegisterArenaDtor - &::google::protobuf::Message::kDescriptorMethods, + PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite:: + ClassDataFull _data_ = { + { + nullptr, // OnDemandRegisterArenaDtor PROTOBUF_FIELD_OFFSET(SourceCodeInfo, _impl_._cached_size_), + false, + }, + &SourceCodeInfo::MergeImpl, + &SourceCodeInfo::kDescriptorMethods, }; return &_data_; } @@ -12741,12 +12831,15 @@ inline void GeneratedCodeInfo_Annotation::SharedDtor() { const ::google::protobuf::MessageLite::ClassData* GeneratedCodeInfo_Annotation::GetClassData() const { - PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite::ClassData - _data_ = { - GeneratedCodeInfo_Annotation::MergeImpl, - nullptr, // OnDemandRegisterArenaDtor - &::google::protobuf::Message::kDescriptorMethods, + PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite:: + ClassDataFull _data_ = { + { + nullptr, // OnDemandRegisterArenaDtor PROTOBUF_FIELD_OFFSET(GeneratedCodeInfo_Annotation, _impl_._cached_size_), + false, + }, + &GeneratedCodeInfo_Annotation::MergeImpl, + &GeneratedCodeInfo_Annotation::kDescriptorMethods, }; return &_data_; } @@ -13057,12 +13150,15 @@ inline void GeneratedCodeInfo::SharedDtor() { const ::google::protobuf::MessageLite::ClassData* GeneratedCodeInfo::GetClassData() const { - PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite::ClassData - _data_ = { - GeneratedCodeInfo::MergeImpl, - nullptr, // OnDemandRegisterArenaDtor - &::google::protobuf::Message::kDescriptorMethods, + PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite:: + ClassDataFull _data_ = { + { + nullptr, // OnDemandRegisterArenaDtor PROTOBUF_FIELD_OFFSET(GeneratedCodeInfo, _impl_._cached_size_), + false, + }, + &GeneratedCodeInfo::MergeImpl, + &GeneratedCodeInfo::kDescriptorMethods, }; return &_data_; } diff --git a/src/google/protobuf/dynamic_message.cc b/src/google/protobuf/dynamic_message.cc index d1f6ca6b7b0f2..0c4ee1b7e0e06 100644 --- a/src/google/protobuf/dynamic_message.cc +++ b/src/google/protobuf/dynamic_message.cc @@ -203,11 +203,14 @@ class DynamicMessage final : public Message { Message* New(Arena* arena) const override; const ClassData* GetClassData() const final { - ABSL_CONST_INIT static const ClassData data = { + ABSL_CONST_INIT static const ClassDataFull data = { + { + nullptr, // on_demand_register_arena_dtor + PROTOBUF_FIELD_OFFSET(DynamicMessage, cached_byte_size_), + false, + }, &MergeImpl, - nullptr, // on_demand_register_arena_dtor &kDescriptorMethods, - PROTOBUF_FIELD_OFFSET(DynamicMessage, cached_byte_size_), }; return &data; } diff --git a/src/google/protobuf/generated_message_bases.cc b/src/google/protobuf/generated_message_bases.cc index 90a7921eb796a..9ebd820c1262b 100644 --- a/src/google/protobuf/generated_message_bases.cc +++ b/src/google/protobuf/generated_message_bases.cc @@ -98,11 +98,14 @@ void ZeroFieldsBase::InternalSwap(ZeroFieldsBase* other) { } const Message::ClassData* ZeroFieldsBase::GetClassData() const { - ABSL_CONST_INIT static const ClassData data = { + ABSL_CONST_INIT static const ClassDataFull data = { + { + nullptr, // on_demand_register_arena_dtor + PROTOBUF_FIELD_OFFSET(ZeroFieldsBase, _cached_size_), + false, + }, &MergeImpl, - nullptr, // on_demand_register_arena_dtor &kDescriptorMethods, - PROTOBUF_FIELD_OFFSET(ZeroFieldsBase, _cached_size_), }; return &data; } diff --git a/src/google/protobuf/implicit_weak_message.h b/src/google/protobuf/implicit_weak_message.h index ebd78f1a560a8..708f73a151c0c 100644 --- a/src/google/protobuf/implicit_weak_message.h +++ b/src/google/protobuf/implicit_weak_message.h @@ -63,10 +63,9 @@ class PROTOBUF_EXPORT ImplicitWeakMessage : public MessageLite { }; static constexpr Data data = { { - nullptr, // merge_impl nullptr, // on_demand_register_arena_dtor - nullptr, // descriptor_methods PROTOBUF_FIELD_OFFSET(ImplicitWeakMessage, cached_size_), + true, }, ""}; return &data.header; diff --git a/src/google/protobuf/map_entry.h b/src/google/protobuf/map_entry.h index dead40ac02377..3a1712bfad42b 100644 --- a/src/google/protobuf/map_entry.h +++ b/src/google/protobuf/map_entry.h @@ -50,11 +50,14 @@ class MapEntryBase : public Message { using Message::Message; const ClassData* GetClassData() const final { - ABSL_CONST_INIT static const ClassData data = { + ABSL_CONST_INIT static const ClassDataFull data = { + { + nullptr, // on_demand_register_arena_dtor + PROTOBUF_FIELD_OFFSET(MapEntryBase, _cached_size_), + false, + }, &MergeImpl, - nullptr, // on_demand_register_arena_dtor &kDescriptorMethods, - PROTOBUF_FIELD_OFFSET(MapEntryBase, _cached_size_), }; return &data; } diff --git a/src/google/protobuf/message.cc b/src/google/protobuf/message.cc index 12ceac1cdcefd..26f6efc283db3 100644 --- a/src/google/protobuf/message.cc +++ b/src/google/protobuf/message.cc @@ -73,7 +73,7 @@ void Message::MergeFrom(const Message& from) { if (class_to == nullptr || class_to != class_from) { ReflectionOps::Merge(from, this); } else { - class_to->merge_to_from(*this, from); + class_to->full().merge_to_from(*this, from); } } @@ -92,7 +92,7 @@ void Message::CopyFrom(const Message& from) { ABSL_DCHECK(!internal::IsDescendant(*this, from)) << "Source of CopyFrom cannot be a descendant of the target."; Clear(); - class_to->merge_to_from(*this, from); + class_to->full().merge_to_from(*this, from); } else { const Descriptor* descriptor = GetDescriptor(); ABSL_CHECK_EQ(from.GetDescriptor(), descriptor) diff --git a/src/google/protobuf/message_lite.cc b/src/google/protobuf/message_lite.cc index 8b5e83c32abc1..468ffc584d767 100644 --- a/src/google/protobuf/message_lite.cc +++ b/src/google/protobuf/message_lite.cc @@ -48,9 +48,9 @@ std::string MessageLite::GetTypeName() const { auto* data = GetClassData(); ABSL_DCHECK(data != nullptr); - if (data->descriptor_methods != nullptr) { + if (!data->is_lite) { // For !LITE messages, we use the descriptor method function. - return data->descriptor_methods->get_type_name(*this); + return data->full().descriptor_methods->get_type_name(*this); } // For LITE messages, the type name is a char[] just beyond ClassData. @@ -71,9 +71,9 @@ std::string MessageLite::InitializationErrorString() const { auto* data = GetClassData(); ABSL_DCHECK(data != nullptr); - if (data->descriptor_methods != nullptr) { + if (!data->is_lite) { // For !LITE messages, we use the descriptor method function. - return data->descriptor_methods->initialization_error_string(*this); + return data->full().descriptor_methods->initialization_error_string(*this); } return "(cannot determine missing fields for lite message)"; diff --git a/src/google/protobuf/message_lite.h b/src/google/protobuf/message_lite.h index 71eb5460448f0..c04cc48b9e252 100644 --- a/src/google/protobuf/message_lite.h +++ b/src/google/protobuf/message_lite.h @@ -523,29 +523,46 @@ class PROTOBUF_EXPORT MessageLite { std::string (*get_type_name)(const MessageLite&); std::string (*initialization_error_string)(const MessageLite&); }; + struct ClassDataFull; + // Note: The order of arguments in the functions is chosen so that it has + // the same ABI as the member function that calls them. Eg the `this` + // pointer becomes the first argument in the free function. struct ClassData { - // Note: The order of arguments in the functions is chosen so that it has - // the same ABI as the member function that calls them. Eg the `this` - // pointer becomes the first argument in the free function. - void (*merge_to_from)(MessageLite& to, const MessageLite& from_msg); void (*on_demand_register_arena_dtor)(MessageLite& msg, Arena& arena); - // LITE objects (ie !descriptor_methods) collocate their name as a - // char[] just beyond the ClassData. - const DescriptorMethods* descriptor_methods; // Offset of the CachedSize member. uint32_t cached_size_offset; + // LITE objects (ie !descriptor_methods) collocate their name as a + // char[] just beyond the ClassData. + bool is_lite; - constexpr ClassData(void (*merge_to_from)(MessageLite& to, - const MessageLite&), - void (*on_demand_register_arena_dtor)(MessageLite&, + constexpr ClassData(void (*on_demand_register_arena_dtor)(MessageLite&, Arena&), - const DescriptorMethods* descriptor_methods, - uint32_t cached_size_offset) - : merge_to_from(merge_to_from), - on_demand_register_arena_dtor(on_demand_register_arena_dtor), - descriptor_methods(descriptor_methods), - cached_size_offset(cached_size_offset) {} + uint32_t cached_size_offset, bool is_lite) + : on_demand_register_arena_dtor(on_demand_register_arena_dtor), + cached_size_offset(cached_size_offset), + is_lite(is_lite) {} + + const ClassDataFull& full() const { + return *static_cast(this); + } + }; + template + struct ClassDataLite { + ClassData header; + const char type_name[N]; + }; + struct ClassDataFull : ClassData { + constexpr ClassDataFull(ClassData base, + void (*merge_to_from)(MessageLite& to, + const MessageLite& from_msg), + const DescriptorMethods* descriptor_methods) + : ClassData(base), + merge_to_from(merge_to_from), + descriptor_methods(descriptor_methods) {} + + void (*merge_to_from)(MessageLite& to, const MessageLite& from_msg); + const DescriptorMethods* descriptor_methods; }; // GetClassData() returns a pointer to a ClassData struct which From 85a134bacd342c88ad6be73a974f4aee4a0fbc91 Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Wed, 13 Dec 2023 18:24:36 +0000 Subject: [PATCH 005/255] Auto-generate files after cl/590637288 --- src/google/protobuf/any.pb.cc | 13 ++- src/google/protobuf/api.pb.cc | 39 +++++--- src/google/protobuf/duration.pb.cc | 13 ++- src/google/protobuf/field_mask.pb.cc | 13 ++- src/google/protobuf/source_context.pb.cc | 13 ++- src/google/protobuf/struct.pb.cc | 39 +++++--- src/google/protobuf/timestamp.pb.cc | 13 ++- src/google/protobuf/type.pb.cc | 65 ++++++++----- src/google/protobuf/wrappers.pb.cc | 117 ++++++++++++++--------- 9 files changed, 200 insertions(+), 125 deletions(-) diff --git a/src/google/protobuf/any.pb.cc b/src/google/protobuf/any.pb.cc index 47ebf5bd435a6..de4a905dc9152 100644 --- a/src/google/protobuf/any.pb.cc +++ b/src/google/protobuf/any.pb.cc @@ -195,12 +195,15 @@ inline void Any::SharedDtor() { const ::google::protobuf::MessageLite::ClassData* Any::GetClassData() const { - PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite::ClassData - _data_ = { - Any::MergeImpl, - nullptr, // OnDemandRegisterArenaDtor - &::google::protobuf::Message::kDescriptorMethods, + PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite:: + ClassDataFull _data_ = { + { + nullptr, // OnDemandRegisterArenaDtor PROTOBUF_FIELD_OFFSET(Any, _impl_._cached_size_), + false, + }, + &Any::MergeImpl, + &Any::kDescriptorMethods, }; return &_data_; } diff --git a/src/google/protobuf/api.pb.cc b/src/google/protobuf/api.pb.cc index 915f05a5ecac7..10ce6495b8314 100644 --- a/src/google/protobuf/api.pb.cc +++ b/src/google/protobuf/api.pb.cc @@ -325,12 +325,15 @@ inline void Api::SharedDtor() { const ::google::protobuf::MessageLite::ClassData* Api::GetClassData() const { - PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite::ClassData - _data_ = { - Api::MergeImpl, - nullptr, // OnDemandRegisterArenaDtor - &::google::protobuf::Message::kDescriptorMethods, + PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite:: + ClassDataFull _data_ = { + { + nullptr, // OnDemandRegisterArenaDtor PROTOBUF_FIELD_OFFSET(Api, _impl_._cached_size_), + false, + }, + &Api::MergeImpl, + &Api::kDescriptorMethods, }; return &_data_; } @@ -714,12 +717,15 @@ inline void Method::SharedDtor() { const ::google::protobuf::MessageLite::ClassData* Method::GetClassData() const { - PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite::ClassData - _data_ = { - Method::MergeImpl, - nullptr, // OnDemandRegisterArenaDtor - &::google::protobuf::Message::kDescriptorMethods, + PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite:: + ClassDataFull _data_ = { + { + nullptr, // OnDemandRegisterArenaDtor PROTOBUF_FIELD_OFFSET(Method, _impl_._cached_size_), + false, + }, + &Method::MergeImpl, + &Method::kDescriptorMethods, }; return &_data_; } @@ -1061,12 +1067,15 @@ inline void Mixin::SharedDtor() { const ::google::protobuf::MessageLite::ClassData* Mixin::GetClassData() const { - PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite::ClassData - _data_ = { - Mixin::MergeImpl, - nullptr, // OnDemandRegisterArenaDtor - &::google::protobuf::Message::kDescriptorMethods, + PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite:: + ClassDataFull _data_ = { + { + nullptr, // OnDemandRegisterArenaDtor PROTOBUF_FIELD_OFFSET(Mixin, _impl_._cached_size_), + false, + }, + &Mixin::MergeImpl, + &Mixin::kDescriptorMethods, }; return &_data_; } diff --git a/src/google/protobuf/duration.pb.cc b/src/google/protobuf/duration.pb.cc index b9e1bf056dc70..0cd69b6eee48a 100644 --- a/src/google/protobuf/duration.pb.cc +++ b/src/google/protobuf/duration.pb.cc @@ -159,12 +159,15 @@ inline void Duration::SharedDtor() { const ::google::protobuf::MessageLite::ClassData* Duration::GetClassData() const { - PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite::ClassData - _data_ = { - Duration::MergeImpl, - nullptr, // OnDemandRegisterArenaDtor - &::google::protobuf::Message::kDescriptorMethods, + PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite:: + ClassDataFull _data_ = { + { + nullptr, // OnDemandRegisterArenaDtor PROTOBUF_FIELD_OFFSET(Duration, _impl_._cached_size_), + false, + }, + &Duration::MergeImpl, + &Duration::kDescriptorMethods, }; return &_data_; } diff --git a/src/google/protobuf/field_mask.pb.cc b/src/google/protobuf/field_mask.pb.cc index 4f7f02f9c4999..d474ff38d5436 100644 --- a/src/google/protobuf/field_mask.pb.cc +++ b/src/google/protobuf/field_mask.pb.cc @@ -165,12 +165,15 @@ inline void FieldMask::SharedDtor() { const ::google::protobuf::MessageLite::ClassData* FieldMask::GetClassData() const { - PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite::ClassData - _data_ = { - FieldMask::MergeImpl, - nullptr, // OnDemandRegisterArenaDtor - &::google::protobuf::Message::kDescriptorMethods, + PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite:: + ClassDataFull _data_ = { + { + nullptr, // OnDemandRegisterArenaDtor PROTOBUF_FIELD_OFFSET(FieldMask, _impl_._cached_size_), + false, + }, + &FieldMask::MergeImpl, + &FieldMask::kDescriptorMethods, }; return &_data_; } diff --git a/src/google/protobuf/source_context.pb.cc b/src/google/protobuf/source_context.pb.cc index 3375db2f2643f..18898f0411fec 100644 --- a/src/google/protobuf/source_context.pb.cc +++ b/src/google/protobuf/source_context.pb.cc @@ -168,12 +168,15 @@ inline void SourceContext::SharedDtor() { const ::google::protobuf::MessageLite::ClassData* SourceContext::GetClassData() const { - PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite::ClassData - _data_ = { - SourceContext::MergeImpl, - nullptr, // OnDemandRegisterArenaDtor - &::google::protobuf::Message::kDescriptorMethods, + PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite:: + ClassDataFull _data_ = { + { + nullptr, // OnDemandRegisterArenaDtor PROTOBUF_FIELD_OFFSET(SourceContext, _impl_._cached_size_), + false, + }, + &SourceContext::MergeImpl, + &SourceContext::kDescriptorMethods, }; return &_data_; } diff --git a/src/google/protobuf/struct.pb.cc b/src/google/protobuf/struct.pb.cc index 429018c61dd22..8fbfe1ada60ef 100644 --- a/src/google/protobuf/struct.pb.cc +++ b/src/google/protobuf/struct.pb.cc @@ -286,12 +286,15 @@ inline void Struct::SharedDtor() { const ::google::protobuf::MessageLite::ClassData* Struct::GetClassData() const { - PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite::ClassData - _data_ = { - Struct::MergeImpl, - nullptr, // OnDemandRegisterArenaDtor - &::google::protobuf::Message::kDescriptorMethods, + PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite:: + ClassDataFull _data_ = { + { + nullptr, // OnDemandRegisterArenaDtor PROTOBUF_FIELD_OFFSET(Struct, _impl_._cached_size_), + false, + }, + &Struct::MergeImpl, + &Struct::kDescriptorMethods, }; return &_data_; } @@ -592,12 +595,15 @@ void Value::clear_kind() { const ::google::protobuf::MessageLite::ClassData* Value::GetClassData() const { - PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite::ClassData - _data_ = { - Value::MergeImpl, - nullptr, // OnDemandRegisterArenaDtor - &::google::protobuf::Message::kDescriptorMethods, + PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite:: + ClassDataFull _data_ = { + { + nullptr, // OnDemandRegisterArenaDtor PROTOBUF_FIELD_OFFSET(Value, _impl_._cached_size_), + false, + }, + &Value::MergeImpl, + &Value::kDescriptorMethods, }; return &_data_; } @@ -912,12 +918,15 @@ inline void ListValue::SharedDtor() { const ::google::protobuf::MessageLite::ClassData* ListValue::GetClassData() const { - PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite::ClassData - _data_ = { - ListValue::MergeImpl, - nullptr, // OnDemandRegisterArenaDtor - &::google::protobuf::Message::kDescriptorMethods, + PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite:: + ClassDataFull _data_ = { + { + nullptr, // OnDemandRegisterArenaDtor PROTOBUF_FIELD_OFFSET(ListValue, _impl_._cached_size_), + false, + }, + &ListValue::MergeImpl, + &ListValue::kDescriptorMethods, }; return &_data_; } diff --git a/src/google/protobuf/timestamp.pb.cc b/src/google/protobuf/timestamp.pb.cc index c8beb68e13a3c..a60d9e7728278 100644 --- a/src/google/protobuf/timestamp.pb.cc +++ b/src/google/protobuf/timestamp.pb.cc @@ -159,12 +159,15 @@ inline void Timestamp::SharedDtor() { const ::google::protobuf::MessageLite::ClassData* Timestamp::GetClassData() const { - PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite::ClassData - _data_ = { - Timestamp::MergeImpl, - nullptr, // OnDemandRegisterArenaDtor - &::google::protobuf::Message::kDescriptorMethods, + PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite:: + ClassDataFull _data_ = { + { + nullptr, // OnDemandRegisterArenaDtor PROTOBUF_FIELD_OFFSET(Timestamp, _impl_._cached_size_), + false, + }, + &Timestamp::MergeImpl, + &Timestamp::kDescriptorMethods, }; return &_data_; } diff --git a/src/google/protobuf/type.pb.cc b/src/google/protobuf/type.pb.cc index feddb6f7392e7..fac84937f16b2 100644 --- a/src/google/protobuf/type.pb.cc +++ b/src/google/protobuf/type.pb.cc @@ -505,12 +505,15 @@ inline void Type::SharedDtor() { const ::google::protobuf::MessageLite::ClassData* Type::GetClassData() const { - PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite::ClassData - _data_ = { - Type::MergeImpl, - nullptr, // OnDemandRegisterArenaDtor - &::google::protobuf::Message::kDescriptorMethods, + PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite:: + ClassDataFull _data_ = { + { + nullptr, // OnDemandRegisterArenaDtor PROTOBUF_FIELD_OFFSET(Type, _impl_._cached_size_), + false, + }, + &Type::MergeImpl, + &Type::kDescriptorMethods, }; return &_data_; } @@ -892,12 +895,15 @@ inline void Field::SharedDtor() { const ::google::protobuf::MessageLite::ClassData* Field::GetClassData() const { - PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite::ClassData - _data_ = { - Field::MergeImpl, - nullptr, // OnDemandRegisterArenaDtor - &::google::protobuf::Message::kDescriptorMethods, + PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite:: + ClassDataFull _data_ = { + { + nullptr, // OnDemandRegisterArenaDtor PROTOBUF_FIELD_OFFSET(Field, _impl_._cached_size_), + false, + }, + &Field::MergeImpl, + &Field::kDescriptorMethods, }; return &_data_; } @@ -1340,12 +1346,15 @@ inline void Enum::SharedDtor() { const ::google::protobuf::MessageLite::ClassData* Enum::GetClassData() const { - PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite::ClassData - _data_ = { - Enum::MergeImpl, - nullptr, // OnDemandRegisterArenaDtor - &::google::protobuf::Message::kDescriptorMethods, + PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite:: + ClassDataFull _data_ = { + { + nullptr, // OnDemandRegisterArenaDtor PROTOBUF_FIELD_OFFSET(Enum, _impl_._cached_size_), + false, + }, + &Enum::MergeImpl, + &Enum::kDescriptorMethods, }; return &_data_; } @@ -1684,12 +1693,15 @@ inline void EnumValue::SharedDtor() { const ::google::protobuf::MessageLite::ClassData* EnumValue::GetClassData() const { - PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite::ClassData - _data_ = { - EnumValue::MergeImpl, - nullptr, // OnDemandRegisterArenaDtor - &::google::protobuf::Message::kDescriptorMethods, + PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite:: + ClassDataFull _data_ = { + { + nullptr, // OnDemandRegisterArenaDtor PROTOBUF_FIELD_OFFSET(EnumValue, _impl_._cached_size_), + false, + }, + &EnumValue::MergeImpl, + &EnumValue::kDescriptorMethods, }; return &_data_; } @@ -1942,12 +1954,15 @@ inline void Option::SharedDtor() { const ::google::protobuf::MessageLite::ClassData* Option::GetClassData() const { - PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite::ClassData - _data_ = { - Option::MergeImpl, - nullptr, // OnDemandRegisterArenaDtor - &::google::protobuf::Message::kDescriptorMethods, + PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite:: + ClassDataFull _data_ = { + { + nullptr, // OnDemandRegisterArenaDtor PROTOBUF_FIELD_OFFSET(Option, _impl_._cached_size_), + false, + }, + &Option::MergeImpl, + &Option::kDescriptorMethods, }; return &_data_; } diff --git a/src/google/protobuf/wrappers.pb.cc b/src/google/protobuf/wrappers.pb.cc index a15d8f57372ed..0ed136b6dd813 100644 --- a/src/google/protobuf/wrappers.pb.cc +++ b/src/google/protobuf/wrappers.pb.cc @@ -402,12 +402,15 @@ inline void DoubleValue::SharedDtor() { const ::google::protobuf::MessageLite::ClassData* DoubleValue::GetClassData() const { - PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite::ClassData - _data_ = { - DoubleValue::MergeImpl, - nullptr, // OnDemandRegisterArenaDtor - &::google::protobuf::Message::kDescriptorMethods, + PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite:: + ClassDataFull _data_ = { + { + nullptr, // OnDemandRegisterArenaDtor PROTOBUF_FIELD_OFFSET(DoubleValue, _impl_._cached_size_), + false, + }, + &DoubleValue::MergeImpl, + &DoubleValue::kDescriptorMethods, }; return &_data_; } @@ -590,12 +593,15 @@ inline void FloatValue::SharedDtor() { const ::google::protobuf::MessageLite::ClassData* FloatValue::GetClassData() const { - PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite::ClassData - _data_ = { - FloatValue::MergeImpl, - nullptr, // OnDemandRegisterArenaDtor - &::google::protobuf::Message::kDescriptorMethods, + PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite:: + ClassDataFull _data_ = { + { + nullptr, // OnDemandRegisterArenaDtor PROTOBUF_FIELD_OFFSET(FloatValue, _impl_._cached_size_), + false, + }, + &FloatValue::MergeImpl, + &FloatValue::kDescriptorMethods, }; return &_data_; } @@ -778,12 +784,15 @@ inline void Int64Value::SharedDtor() { const ::google::protobuf::MessageLite::ClassData* Int64Value::GetClassData() const { - PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite::ClassData - _data_ = { - Int64Value::MergeImpl, - nullptr, // OnDemandRegisterArenaDtor - &::google::protobuf::Message::kDescriptorMethods, + PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite:: + ClassDataFull _data_ = { + { + nullptr, // OnDemandRegisterArenaDtor PROTOBUF_FIELD_OFFSET(Int64Value, _impl_._cached_size_), + false, + }, + &Int64Value::MergeImpl, + &Int64Value::kDescriptorMethods, }; return &_data_; } @@ -952,12 +961,15 @@ inline void UInt64Value::SharedDtor() { const ::google::protobuf::MessageLite::ClassData* UInt64Value::GetClassData() const { - PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite::ClassData - _data_ = { - UInt64Value::MergeImpl, - nullptr, // OnDemandRegisterArenaDtor - &::google::protobuf::Message::kDescriptorMethods, + PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite:: + ClassDataFull _data_ = { + { + nullptr, // OnDemandRegisterArenaDtor PROTOBUF_FIELD_OFFSET(UInt64Value, _impl_._cached_size_), + false, + }, + &UInt64Value::MergeImpl, + &UInt64Value::kDescriptorMethods, }; return &_data_; } @@ -1126,12 +1138,15 @@ inline void Int32Value::SharedDtor() { const ::google::protobuf::MessageLite::ClassData* Int32Value::GetClassData() const { - PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite::ClassData - _data_ = { - Int32Value::MergeImpl, - nullptr, // OnDemandRegisterArenaDtor - &::google::protobuf::Message::kDescriptorMethods, + PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite:: + ClassDataFull _data_ = { + { + nullptr, // OnDemandRegisterArenaDtor PROTOBUF_FIELD_OFFSET(Int32Value, _impl_._cached_size_), + false, + }, + &Int32Value::MergeImpl, + &Int32Value::kDescriptorMethods, }; return &_data_; } @@ -1300,12 +1315,15 @@ inline void UInt32Value::SharedDtor() { const ::google::protobuf::MessageLite::ClassData* UInt32Value::GetClassData() const { - PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite::ClassData - _data_ = { - UInt32Value::MergeImpl, - nullptr, // OnDemandRegisterArenaDtor - &::google::protobuf::Message::kDescriptorMethods, + PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite:: + ClassDataFull _data_ = { + { + nullptr, // OnDemandRegisterArenaDtor PROTOBUF_FIELD_OFFSET(UInt32Value, _impl_._cached_size_), + false, + }, + &UInt32Value::MergeImpl, + &UInt32Value::kDescriptorMethods, }; return &_data_; } @@ -1474,12 +1492,15 @@ inline void BoolValue::SharedDtor() { const ::google::protobuf::MessageLite::ClassData* BoolValue::GetClassData() const { - PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite::ClassData - _data_ = { - BoolValue::MergeImpl, - nullptr, // OnDemandRegisterArenaDtor - &::google::protobuf::Message::kDescriptorMethods, + PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite:: + ClassDataFull _data_ = { + { + nullptr, // OnDemandRegisterArenaDtor PROTOBUF_FIELD_OFFSET(BoolValue, _impl_._cached_size_), + false, + }, + &BoolValue::MergeImpl, + &BoolValue::kDescriptorMethods, }; return &_data_; } @@ -1661,12 +1682,15 @@ inline void StringValue::SharedDtor() { const ::google::protobuf::MessageLite::ClassData* StringValue::GetClassData() const { - PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite::ClassData - _data_ = { - StringValue::MergeImpl, - nullptr, // OnDemandRegisterArenaDtor - &::google::protobuf::Message::kDescriptorMethods, + PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite:: + ClassDataFull _data_ = { + { + nullptr, // OnDemandRegisterArenaDtor PROTOBUF_FIELD_OFFSET(StringValue, _impl_._cached_size_), + false, + }, + &StringValue::MergeImpl, + &StringValue::kDescriptorMethods, }; return &_data_; } @@ -1855,12 +1879,15 @@ inline void BytesValue::SharedDtor() { const ::google::protobuf::MessageLite::ClassData* BytesValue::GetClassData() const { - PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite::ClassData - _data_ = { - BytesValue::MergeImpl, - nullptr, // OnDemandRegisterArenaDtor - &::google::protobuf::Message::kDescriptorMethods, + PROTOBUF_CONSTINIT static const ::google::protobuf::MessageLite:: + ClassDataFull _data_ = { + { + nullptr, // OnDemandRegisterArenaDtor PROTOBUF_FIELD_OFFSET(BytesValue, _impl_._cached_size_), + false, + }, + &BytesValue::MergeImpl, + &BytesValue::kDescriptorMethods, }; return &_data_; } From 7c38dabce33ca2ecfbb1546e2b7bd486dcf7609b Mon Sep 17 00:00:00 2001 From: Mike Kruskal Date: Wed, 13 Dec 2023 10:28:30 -0800 Subject: [PATCH 006/255] Add minimization for enum_type. This won't have much effect over the edition zero migration, since enums in any proto2/proto3 file are either exclusively closed/open, respectively. However, it will prefer enum-level features if there's only a single enum PiperOrigin-RevId: 590642827 --- .../protobuf/editions/golden/editions_transform_proto2.proto | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/google/protobuf/editions/golden/editions_transform_proto2.proto b/src/google/protobuf/editions/golden/editions_transform_proto2.proto index 0b60e80f36bac..c8e9fb2b3eb6f 100644 --- a/src/google/protobuf/editions/golden/editions_transform_proto2.proto +++ b/src/google/protobuf/editions/golden/editions_transform_proto2.proto @@ -18,7 +18,6 @@ import "third_party/java_src/protobuf/current/java/com/google/protobuf/java_feat import "google/protobuf/cpp_features.proto"; import "google/protobuf/editions/proto/editions_transform_proto3.proto"; -option features.enum_type = CLOSED; option features.repeated_field_encoding = EXPANDED; option features.utf8_validation = NONE; option java_multiple_files = true; @@ -110,6 +109,8 @@ message TestMessage { } enum TestEnum { + option features.enum_type = CLOSED; + FOO = 1; // Non-zero default BAR = 2; From c2532d5f17872adeaba8e3cb32e0be41bec507dc Mon Sep 17 00:00:00 2001 From: Alyssa Haroldsen Date: Wed, 13 Dec 2023 13:52:31 -0800 Subject: [PATCH 007/255] Move the info about perfect derive to shared.rs PiperOrigin-RevId: 590702727 --- rust/cpp.rs | 3 --- rust/shared.rs | 5 +++++ 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/rust/cpp.rs b/rust/cpp.rs index 2090a662f9ecd..1d0fbe10c4c88 100644 --- a/rust/cpp.rs +++ b/rust/cpp.rs @@ -229,9 +229,6 @@ impl<'msg, T: ?Sized> RepeatedField<'msg, T> { } } -// These use manual impls instead of derives to avoid unnecessary bounds on `T`. -// This problem is referred to as "perfect derive". -// https://smallcultfollowing.com/babysteps/blog/2022/04/12/implied-bounds-and-perfect-derive/ impl<'msg, T: ?Sized> Copy for RepeatedField<'msg, T> {} impl<'msg, T: ?Sized> Clone for RepeatedField<'msg, T> { fn clone(&self) -> RepeatedField<'msg, T> { diff --git a/rust/shared.rs b/rust/shared.rs index f94f987989da4..620d285061da2 100644 --- a/rust/shared.rs +++ b/rust/shared.rs @@ -13,6 +13,11 @@ use std::fmt; +// There are a number of manual `Debug` and similar impls instead of using their +// derives, in order to to avoid unnecessary bounds on a generic `T`. +// This problem is referred to as "perfect derive". +// https://smallcultfollowing.com/babysteps/blog/2022/04/12/implied-bounds-and-perfect-derive/ + /// Everything in `__public` is re-exported in `protobuf.rs`. /// These are the items protobuf users can access directly. #[doc(hidden)] From 70b1d79574a97fe64edaf22df85148b9820fa9c3 Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Wed, 13 Dec 2023 14:46:30 -0800 Subject: [PATCH 008/255] Use short name for view primitive in the oneof enums (i32 instead of View<'msg, i32>) PiperOrigin-RevId: 590718375 --- src/google/protobuf/compiler/rust/oneof.cc | 93 ++++++++++++++++------ 1 file changed, 68 insertions(+), 25 deletions(-) diff --git a/src/google/protobuf/compiler/rust/oneof.cc b/src/google/protobuf/compiler/rust/oneof.cc index 83350289d666f..d6166ae6d6f73 100644 --- a/src/google/protobuf/compiler/rust/oneof.cc +++ b/src/google/protobuf/compiler/rust/oneof.cc @@ -9,6 +9,7 @@ #include +#include "absl/log/absl_log.h" #include "absl/strings/str_cat.h" #include "absl/strings/string_view.h" #include "google/protobuf/compiler/cpp/helpers.h" @@ -38,7 +39,7 @@ namespace rust { // message SomeMsg { // oneof some_oneof { // int32 field_a = 7; -// uint32 field_b = 9; +// SomeMsg field_b = 9; // } // } // @@ -46,14 +47,14 @@ namespace rust { // pub mod SomeMsg_ { // // The 'view' struct (no suffix on the name) // pub enum SomeOneof<'msg> { -// FieldA(View<'msg, i32>) = 7, -// FieldB(View<'msg, u32>) = 9, -// not_set = 0 +// FieldA(i32) = 7, +// FieldB(View<'msg, SomeMsg>) = 9, +// not_set(std::marker::PhantomData<&'msg ()>) = 0 // } // pub enum SomeOneofMut<'msg> { // FieldA(Mut<'msg, i32>) = 7, -// FieldB(Mut<'msg, u32>) = 9, -// not_set = 0 +// FieldB(Mut<'msg, SomeMsg>) = 9, +// not_set(std::marker::PhantomData<&'msg ()>) = 0 // } // } // impl SomeMsg { @@ -91,37 +92,79 @@ std::string oneofCaseEnumName(const OneofDescriptor& desc) { return ToCamelCase(desc.name()) + "Case"; } -// TODO: Promote up to naming.h once all types can be spelled. -std::string RsTypeName(Context field) { +std::string RsTypeNameView(Context field) { const auto& desc = field.desc(); - // TODO: Fields with a ctype set not supported in v0.6 api. if (desc.options().has_ctype()) { - return ""; + return ""; // TODO: b/308792377 - ctype fields not supported yet. } - switch (desc.type()) { + case FieldDescriptor::TYPE_INT32: + case FieldDescriptor::TYPE_INT64: + case FieldDescriptor::TYPE_FIXED32: + case FieldDescriptor::TYPE_FIXED64: + case FieldDescriptor::TYPE_SFIXED32: + case FieldDescriptor::TYPE_SFIXED64: + case FieldDescriptor::TYPE_SINT32: + case FieldDescriptor::TYPE_SINT64: + case FieldDescriptor::TYPE_UINT32: + case FieldDescriptor::TYPE_UINT64: + case FieldDescriptor::TYPE_FLOAT: + case FieldDescriptor::TYPE_DOUBLE: + case FieldDescriptor::TYPE_BOOL: + return PrimitiveRsTypeName(desc); + case FieldDescriptor::TYPE_BYTES: + return "&'msg [u8]"; + case FieldDescriptor::TYPE_STRING: + return "&'msg ::__pb::ProtoStr"; case FieldDescriptor::TYPE_MESSAGE: - return absl::StrCat("crate::", GetCrateRelativeQualifiedPath( - field.WithDesc(desc.message_type()))); - case FieldDescriptor::TYPE_ENUM: - case FieldDescriptor::TYPE_GROUP: + return absl::StrCat( + "::__pb::View<'msg, crate::", + GetCrateRelativeQualifiedPath(field.WithDesc(desc.message_type())), + ">"); + case FieldDescriptor::TYPE_ENUM: // TODO: b/300257770 - Support enums. + case FieldDescriptor::TYPE_GROUP: // Not supported yet. return ""; - default: - return PrimitiveRsTypeName(desc); } -} -std::string RsTypeNameView(Context field) { - std::string type = RsTypeName(field); - if (type.empty()) return ""; - return absl::StrCat("::__pb::View<'msg, ", type, ">"); + ABSL_LOG(FATAL) << "Unexpected field type: " << desc.type_name(); + return ""; } std::string RsTypeNameMut(Context field) { - std::string type = RsTypeName(field); - if (type.empty()) return ""; - return absl::StrCat("::__pb::Mut<'msg, ", type, ">"); + const auto& desc = field.desc(); + if (desc.options().has_ctype()) { + return ""; // TODO: b/308792377 - ctype fields not supported yet. + } + switch (desc.type()) { + case FieldDescriptor::TYPE_INT32: + case FieldDescriptor::TYPE_INT64: + case FieldDescriptor::TYPE_FIXED32: + case FieldDescriptor::TYPE_FIXED64: + case FieldDescriptor::TYPE_SFIXED32: + case FieldDescriptor::TYPE_SFIXED64: + case FieldDescriptor::TYPE_SINT32: + case FieldDescriptor::TYPE_SINT64: + case FieldDescriptor::TYPE_UINT32: + case FieldDescriptor::TYPE_UINT64: + case FieldDescriptor::TYPE_FLOAT: + case FieldDescriptor::TYPE_DOUBLE: + case FieldDescriptor::TYPE_BOOL: + case FieldDescriptor::TYPE_BYTES: + case FieldDescriptor::TYPE_STRING: + return absl::StrCat("::__pb::Mut<'msg, ", PrimitiveRsTypeName(desc), ">"); + case FieldDescriptor::TYPE_MESSAGE: + return absl::StrCat( + "::__pb::Mut<'msg, crate::", + GetCrateRelativeQualifiedPath(field.WithDesc(desc.message_type())), + ">"); + case FieldDescriptor::TYPE_ENUM: // TODO: b/300257770 - Support enums. + case FieldDescriptor::TYPE_GROUP: // Not supported yet. + return ""; + } + + ABSL_LOG(FATAL) << "Unexpected field type: " << desc.type_name(); + return ""; } } // namespace From 4b2a30c22c89c4f5c7a19d78685715ae8c8ae9f9 Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Wed, 13 Dec 2023 15:57:58 -0800 Subject: [PATCH 009/255] Slightly relax JSON integer parsing tests to handle a wider range of runtime behaviors around parsing floating point values not exactly representable as the destination type. PiperOrigin-RevId: 590739762 --- .../src/Google.Protobuf.Test/JsonParserTest.cs | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/csharp/src/Google.Protobuf.Test/JsonParserTest.cs b/csharp/src/Google.Protobuf.Test/JsonParserTest.cs index 5c4b42c7aac31..4d1cbef1d2ebf 100644 --- a/csharp/src/Google.Protobuf.Test/JsonParserTest.cs +++ b/csharp/src/Google.Protobuf.Test/JsonParserTest.cs @@ -1,4 +1,4 @@ -#region Copyright notice and license +#region Copyright notice and license // Protocol Buffers - Google's data interchange format // Copyright 2008 Google Inc. All rights reserved. // @@ -471,11 +471,11 @@ public void NumberToInt64_Valid(string jsonValue, long expectedParsedValue) // Assume that anything non-bounds-related is covered in the Int32 case [Test] - [TestCase("9223372036854775808")] - // Theoretical bound would be -9223372036854775809, but when that is parsed to a double - // we end up with the exact value of long.MinValue due to lack of precision. The value here - // is the "next double down". - [TestCase("-9223372036854780000")] + // Runtime implementation differences produce different results for values just outside + // (long.MinValue, long.MaxValue) which cannot be exactly represented as a double. Use the + // next values exactly representable as doubles to ensure consistency. + [TestCase("9223372036854777856")] + [TestCase("-9223372036854777856")] public void NumberToInt64_Invalid(string jsonValue) { string json = "{ \"singleInt64\": " + jsonValue + "}"; @@ -498,7 +498,10 @@ public void NumberToUInt64_Valid(string jsonValue, ulong expectedParsedValue) // Assume that anything non-bounds-related is covered in the Int32 case [Test] [TestCase("-1")] - [TestCase("18446744073709551616")] + // Runtime implementation differences produce different results for values just beyond + // ulong.MaxValue which cannot be exactly represented as a double. Use the next value + // exactly representable as a double to ensure consistency. + [TestCase("18446744073709555712")] public void NumberToUInt64_Invalid(string jsonValue) { string json = "{ \"singleUint64\": " + jsonValue + "}"; From 543fbcdbd9496de9d93a6eb4645640cb47a5514b Mon Sep 17 00:00:00 2001 From: Mike Kruskal Date: Wed, 13 Dec 2023 16:01:51 -0800 Subject: [PATCH 010/255] Breaking change: Remove deprecated std::string error collector overrides PiperOrigin-RevId: 590740727 --- src/google/protobuf/compiler/importer.h | 22 ++------------------ src/google/protobuf/descriptor.h | 27 ++----------------------- src/google/protobuf/io/tokenizer.h | 21 ++----------------- src/google/protobuf/retention_test.cc | 17 +++++++++++----- upb/util/def_to_proto_test.h | 6 +++--- 5 files changed, 21 insertions(+), 72 deletions(-) diff --git a/src/google/protobuf/compiler/importer.h b/src/google/protobuf/compiler/importer.h index 539021b8bdd3d..6bb127a776c4c 100644 --- a/src/google/protobuf/compiler/importer.h +++ b/src/google/protobuf/compiler/importer.h @@ -181,30 +181,12 @@ class PROTOBUF_EXPORT MultiFileErrorCollector { // Line and column numbers are zero-based. A line number of -1 indicates // an error with the entire file (e.g. "not found"). virtual void RecordError(absl::string_view filename, int line, int column, - absl::string_view message) { - PROTOBUF_IGNORE_DEPRECATION_START - AddError(std::string(filename), line, column, std::string(message)); - PROTOBUF_IGNORE_DEPRECATION_STOP - } + absl::string_view message) + = 0; virtual void RecordWarning(absl::string_view filename, int line, int column, absl::string_view message) { - PROTOBUF_IGNORE_DEPRECATION_START - AddWarning(std::string(filename), line, column, std::string(message)); - PROTOBUF_IGNORE_DEPRECATION_STOP - } - - private: - // These should never be called directly, but if a legacy class overrides - // them they'll get routed to by the Record* methods. - ABSL_DEPRECATED("Use RecordError") - virtual void AddError(const std::string& filename, int line, int column, - const std::string& message) { - ABSL_LOG(FATAL) << "AddError or RecordError must be implemented."; } - ABSL_DEPRECATED("Use RecordWarning") - virtual void AddWarning(const std::string& filename, int line, int column, - const std::string& message) {} }; // Abstract interface which represents a directory tree containing proto files. diff --git a/src/google/protobuf/descriptor.h b/src/google/protobuf/descriptor.h index dfb71df1f294c..9b24cb1bb9f80 100644 --- a/src/google/protobuf/descriptor.h +++ b/src/google/protobuf/descriptor.h @@ -2156,12 +2156,8 @@ class PROTOBUF_EXPORT DescriptorPool { virtual void RecordError(absl::string_view filename, absl::string_view element_name, const Message* descriptor, ErrorLocation location, - absl::string_view message) { - PROTOBUF_IGNORE_DEPRECATION_START - AddError(std::string(filename), std::string(element_name), descriptor, - location, std::string(message)); - PROTOBUF_IGNORE_DEPRECATION_STOP - } + absl::string_view message) + = 0; // Reports a warning in the FileDescriptorProto. Use this function if the // problem occurred should NOT interrupt building the FileDescriptorProto. @@ -2176,27 +2172,8 @@ class PROTOBUF_EXPORT DescriptorPool { const Message* descriptor, ErrorLocation location, absl::string_view message) { - PROTOBUF_IGNORE_DEPRECATION_START - AddWarning(std::string(filename), std::string(element_name), descriptor, - location, std::string(message)); - PROTOBUF_IGNORE_DEPRECATION_STOP } - private: - // These should never be called directly, but if a legacy class overrides - // them they'll get routed to by the Record* methods. - ABSL_DEPRECATED("Use RecordError") - virtual void AddError(const std::string& filename, - const std::string& element_name, - const Message* descriptor, ErrorLocation location, - const std::string& message) { - ABSL_LOG(FATAL) << "AddError or RecordError must be implemented."; - } - ABSL_DEPRECATED("Use RecordWarning") - virtual void AddWarning(const std::string& filename, - const std::string& element_name, - const Message* descriptor, ErrorLocation location, - const std::string& message) {} }; // Convert the FileDescriptorProto to real descriptors and place them in diff --git a/src/google/protobuf/io/tokenizer.h b/src/google/protobuf/io/tokenizer.h index 0855a17db5b3a..007d09016eb35 100644 --- a/src/google/protobuf/io/tokenizer.h +++ b/src/google/protobuf/io/tokenizer.h @@ -55,33 +55,16 @@ class PROTOBUF_EXPORT ErrorCollector { // column numbers. The numbers are zero-based, so you may want to add // 1 to each before printing them. virtual void RecordError(int line, ColumnNumber column, - absl::string_view message) { - PROTOBUF_IGNORE_DEPRECATION_START - AddError(line, column, std::string(message)); - PROTOBUF_IGNORE_DEPRECATION_STOP - } + absl::string_view message) + = 0; // Indicates that there was a warning in the input at the given line and // column numbers. The numbers are zero-based, so you may want to add // 1 to each before printing them. virtual void RecordWarning(int line, ColumnNumber column, absl::string_view message) { - PROTOBUF_IGNORE_DEPRECATION_START - AddWarning(line, column, std::string(message)); - PROTOBUF_IGNORE_DEPRECATION_STOP } - private: - // These should never be called directly, but if a legacy class overrides - // them they'll get routed to by the Record* methods. - ABSL_DEPRECATED("Use RecordError") - virtual void AddError(int line, ColumnNumber column, - const std::string& message) { - ABSL_LOG(FATAL) << "AddError or RecordError must be implemented."; - } - ABSL_DEPRECATED("Use RecordWarning") - virtual void AddWarning(int line, ColumnNumber column, - const std::string& message) {} }; // This class converts a stream of raw text into a stream of tokens for diff --git a/src/google/protobuf/retention_test.cc b/src/google/protobuf/retention_test.cc index 32b502d197865..8b777699bb7ae 100644 --- a/src/google/protobuf/retention_test.cc +++ b/src/google/protobuf/retention_test.cc @@ -13,6 +13,7 @@ #include "google/protobuf/descriptor.pb.h" #include +#include "absl/strings/string_view.h" #include "absl/strings/substitute.h" #include "google/protobuf/compiler/parser.h" #include "google/protobuf/dynamic_message.h" @@ -160,6 +161,12 @@ TEST(RetentionTest, Method) { .GetExtension(protobuf_unittest::method_option)); } +class SimpleErrorCollector : public io::ErrorCollector { + public: + SimpleErrorCollector() = default; + void RecordError(int line, io::ColumnNumber column, + absl::string_view message) override{}; +}; TEST(RetentionTest, StripSourceRetentionOptionsWithSourceCodeInfo) { // The tests above make assertions against the generated code, but this test @@ -202,7 +209,7 @@ TEST(RetentionTest, StripSourceRetentionOptionsWithSourceCodeInfo) { FileDescriptorSet::descriptor()->file()->name()); io::ArrayInputStream input_stream(proto_file.data(), static_cast(proto_file.size())); - io::ErrorCollector error_collector; + SimpleErrorCollector error_collector; io::Tokenizer tokenizer(&input_stream, &error_collector); compiler::Parser parser; FileDescriptorProto file_descriptor; @@ -242,7 +249,7 @@ TEST(RetentionTest, RemoveEmptyOptions) { FileDescriptorSet::descriptor()->file()->name()); io::ArrayInputStream input_stream(proto_file.data(), static_cast(proto_file.size())); - io::ErrorCollector error_collector; + SimpleErrorCollector error_collector; io::Tokenizer tokenizer(&input_stream, &error_collector); compiler::Parser parser; FileDescriptorProto file_descriptor; @@ -282,7 +289,7 @@ TEST(RetentionTest, InvalidDescriptor) { FileDescriptorSet::descriptor()->file()->name()); io::ArrayInputStream input_stream(proto_file.data(), static_cast(proto_file.size())); - io::ErrorCollector error_collector; + SimpleErrorCollector error_collector; io::Tokenizer tokenizer(&input_stream, &error_collector); compiler::Parser parser; FileDescriptorProto file_descriptor_proto; @@ -331,7 +338,7 @@ TEST(RetentionTest, MissingRequiredField) { FileDescriptorSet::descriptor()->file()->name()); io::ArrayInputStream input_stream(proto_file.data(), static_cast(proto_file.size())); - io::ErrorCollector error_collector; + SimpleErrorCollector error_collector; io::Tokenizer tokenizer(&input_stream, &error_collector); compiler::Parser parser; FileDescriptorProto file_descriptor_proto; @@ -387,7 +394,7 @@ TEST(RetentionTest, InvalidRecursionDepth) { FileDescriptorSet::descriptor()->file()->name()); io::ArrayInputStream input_stream(proto_file.data(), static_cast(proto_file.size())); - io::ErrorCollector error_collector; + SimpleErrorCollector error_collector; io::Tokenizer tokenizer(&input_stream, &error_collector); compiler::Parser parser; FileDescriptorProto file_descriptor_proto; diff --git a/upb/util/def_to_proto_test.h b/upb/util/def_to_proto_test.h index fdd102ad05346..f8e017cead3e0 100644 --- a/upb/util/def_to_proto_test.h +++ b/upb/util/def_to_proto_test.h @@ -46,9 +46,9 @@ MATCHER_P(EqualsProtoTreatNansAsEqual, proto, } class NullErrorCollector : public google::protobuf::DescriptorPool::ErrorCollector { - void AddError(const std::string& filename, const std::string& element_name, - const google::protobuf::Message* descriptor, ErrorLocation location, - const std::string& message) override {} + void RecordError(absl::string_view filename, absl::string_view element_name, + const google::protobuf::Message* descriptor, ErrorLocation location, + absl::string_view message) override {} void RecordWarning(absl::string_view filename, absl::string_view element_name, const google::protobuf::Message* descriptor, ErrorLocation location, absl::string_view message) override {} From 2d7376ea378b14548b1d417df285a0a5c84957ba Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Thu, 14 Dec 2023 02:38:22 -0800 Subject: [PATCH 011/255] Internal change PiperOrigin-RevId: 590871044 --- .../com/google/protobuf/util/Durations.java | 20 +++++------ .../com/google/protobuf/util/Timestamps.java | 36 +++++++++---------- 2 files changed, 27 insertions(+), 29 deletions(-) diff --git a/java/util/src/main/java/com/google/protobuf/util/Durations.java b/java/util/src/main/java/com/google/protobuf/util/Durations.java index a73ab9f0aa38c..05e0e217f4a5a 100644 --- a/java/util/src/main/java/com/google/protobuf/util/Durations.java +++ b/java/util/src/main/java/com/google/protobuf/util/Durations.java @@ -426,13 +426,13 @@ public static long toNanos(Duration duration) { * Add two durations. * * - *

Do not use this method for new code. Instead, convert to {@link java.time.Duration} using - * {@link com.google.protobuf.util.JavaTimeConversions#toJavaDuration}, do the arithmetic there, - * and convert back using {@link com.google.protobuf.util.JavaTimeConversions#toProtoDuration}. - * - *

This method will be deprecated once most uses have been eliminated. + * @deprecated Do not use this method for new code. Instead, convert to {@link java.time.Duration} + * using {@link com.google.protobuf.util.JavaTimeConversions#toJavaDuration}, do the + * arithmetic there, and convert back using {@link + * com.google.protobuf.util.JavaTimeConversions#toProtoDuration}. * */ + @Deprecated // MOE:strip_line public static Duration add(Duration d1, Duration d2) { checkValid(d1); checkValid(d2); @@ -444,13 +444,13 @@ public static Duration add(Duration d1, Duration d2) { * Subtract a duration from another. * * - *

Do not use this method for new code. Instead, convert to {@link java.time.Duration} using - * {@link com.google.protobuf.util.JavaTimeConversions#toJavaDuration}, do the arithmetic there, - * and convert back using {@link com.google.protobuf.util.JavaTimeConversions#toProtoDuration}. - * - *

This method will be deprecated once most uses have been eliminated. + * @deprecated Do not use this method for new code. Instead, convert to {@link java.time.Duration} + * using {@link com.google.protobuf.util.JavaTimeConversions#toJavaDuration}, do the + * arithmetic there, and convert back using {@link + * com.google.protobuf.util.JavaTimeConversions#toProtoDuration}. * */ + @Deprecated // MOE:strip_line public static Duration subtract(Duration d1, Duration d2) { checkValid(d1); checkValid(d2); diff --git a/java/util/src/main/java/com/google/protobuf/util/Timestamps.java b/java/util/src/main/java/com/google/protobuf/util/Timestamps.java index 99daeb32603d1..cdd8027d993d2 100644 --- a/java/util/src/main/java/com/google/protobuf/util/Timestamps.java +++ b/java/util/src/main/java/com/google/protobuf/util/Timestamps.java @@ -431,13 +431,13 @@ public static long toNanos(Timestamp timestamp) { * Calculate the difference between two timestamps. * * - *

Do not use this method for new code. Instead, convert to {@link java.time.Instant} using - * {@link com.google.protobuf.util.JavaTimeConversions#toJavaInstant}, do the arithmetic there, - * and convert back using {@link com.google.protobuf.util.JavaTimeConversions#toProtoDuration}. - * - *

This method will be deprecated once most uses have been eliminated. + * @deprecated Do not use this method for new code. Instead, convert to {@link java.time.Instant} + * using {@link com.google.protobuf.util.JavaTimeConversions#toJavaInstant}, do the arithmetic + * there, and convert back using {@link + * com.google.protobuf.util.JavaTimeConversions#toProtoDuration}. * */ + @Deprecated // MOE:strip_line public static Duration between(Timestamp from, Timestamp to) { checkValid(from); checkValid(to); @@ -450,15 +450,14 @@ public static Duration between(Timestamp from, Timestamp to) { * Add a duration to a timestamp. * * - *

Do not use this method for new code. Instead, convert to {@link java.time.Instant} and - * {@link java.time.Duration} using {@link - * com.google.protobuf.util.JavaTimeConversions#toJavaInstant} and {@link - * com.google.protobuf.util.JavaTimeConversions#toJavaDuration}, do the arithmetic there, and - * convert back using {@link com.google.protobuf.util.JavaTimeConversions#toProtoTimestamp}. - * - *

This method will be deprecated once most uses have been eliminated. + * @deprecated Do not use this method for new code. Instead, convert to {@link java.time.Instant} + * and {@link java.time.Duration} using {@link + * com.google.protobuf.util.JavaTimeConversions#toJavaInstant} and {@link + * com.google.protobuf.util.JavaTimeConversions#toJavaDuration}, do the arithmetic there, and + * convert back using {@link com.google.protobuf.util.JavaTimeConversions#toProtoTimestamp}. * */ + @Deprecated // MOE:strip_line public static Timestamp add(Timestamp start, Duration length) { checkValid(start); Durations.checkValid(length); @@ -471,15 +470,14 @@ public static Timestamp add(Timestamp start, Duration length) { * Subtract a duration from a timestamp. * * - *

Do not use this method for new code. Instead, convert to {@link java.time.Instant} and - * {@link java.time.Duration} using {@link - * com.google.protobuf.util.JavaTimeConversions#toJavaInstant} and {@link - * com.google.protobuf.util.JavaTimeConversions#toJavaDuration}, do the arithmetic there, and - * convert back using {@link com.google.protobuf.util.JavaTimeConversions#toProtoTimestamp}. - * - *

This method will be deprecated once most uses have been eliminated. + * @deprecated Do not use this method for new code. Instead, convert to {@link java.time.Instant} + * and {@link java.time.Duration} using {@link + * com.google.protobuf.util.JavaTimeConversions#toJavaInstant} and {@link + * com.google.protobuf.util.JavaTimeConversions#toJavaDuration}, do the arithmetic there, and + * convert back using {@link com.google.protobuf.util.JavaTimeConversions#toProtoTimestamp}. * */ + @Deprecated // MOE:strip_line public static Timestamp subtract(Timestamp start, Duration length) { checkValid(start); Durations.checkValid(length); From 34908e28983f1db5572e1fdf7c5a89a8b06c5f9a Mon Sep 17 00:00:00 2001 From: Iori IKEDA <8983747+NotFounds@users.noreply.github.com> Date: Thu, 14 Dec 2023 08:02:45 -0800 Subject: [PATCH 012/255] Fix TypeError when passing an instance of a subclass of String to a string field (#13818) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Issue When an object that is an instance of a string-derived class is passed to a string field in a protobuf message in Ruby, it results in a `Google::Protobuf::TypeError`. ### Steps to reproduce ```rb ~/src/github.com/protocolbuffers/protobuf/ruby/tests ❯❯❯ irb -I . irb(main):001:0> require 'basic_test_pb' => true irb(main):002:0> myString = Class.new(String) => # irb(main):003:0> str = myString.new("foo") => "foo" irb(main):004:0> BasicTest::TestMessage.new(optional_string: "foo") => irb(main):005:0> BasicTest::TestMessage.new(optional_string: str) (irb):5:in `initialize': Invalid argument for string field 'optional_string' (given #). (Google::Protobuf::TypeError) irb(main):006:0> ``` ## Fix The issue appears to be caused by the field checking mechanism not properly handling instances of classes that inherit from basic types like String. My proposed solution is to improve the type checking for string fields to consider not just String instances but also instances of subclasses of String. ## Impact The changes will allow instances of classes derived from String to be passed to string fields without any error. This is a backwards-compatible change and will not affect the existing behaviour with standard String instances. Closes #13818 COPYBARA_INTEGRATE_REVIEW=https://github.com/protocolbuffers/protobuf/pull/13818 from NotFounds:support-string-subclass-for-ruby 2d2796c4f96d5a182a269b54e893f436f2211ea2 PiperOrigin-RevId: 590941235 --- ruby/ext/google/protobuf_c/convert.c | 2 +- ruby/tests/basic.rb | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/ruby/ext/google/protobuf_c/convert.c b/ruby/ext/google/protobuf_c/convert.c index c9448cde01d7a..b97c050580b8c 100644 --- a/ruby/ext/google/protobuf_c/convert.c +++ b/ruby/ext/google/protobuf_c/convert.c @@ -141,7 +141,7 @@ upb_MessageValue Convert_RubyToUpb(VALUE value, const char* name, VALUE utf8 = rb_enc_from_encoding(rb_utf8_encoding()); if (rb_obj_class(value) == rb_cSymbol) { value = rb_funcall(value, rb_intern("to_s"), 0); - } else if (rb_obj_class(value) != rb_cString) { + } else if (!rb_obj_is_kind_of(value, rb_cString)) { rb_raise(cTypeError, "Invalid argument for string field '%s' (given %s).", name, rb_class2name(CLASS_OF(value))); diff --git a/ruby/tests/basic.rb b/ruby/tests/basic.rb index fe2119e42fb78..1e5e7a341d176 100755 --- a/ruby/tests/basic.rb +++ b/ruby/tests/basic.rb @@ -787,4 +787,15 @@ def test_oneof_fields_respond_to? # regression test for issue 9202 assert_respond_to msg, :has_d? refute msg.has_d? end + + def test_string_subclass + str = "hello" + myString = Class.new(String) + + m = proto_module::TestMessage.new( + optional_string: myString.new(str), + ) + + assert_equal str, m.optional_string + end end From f0a8c474cc16d4992e3c4a05860339f0ae66e1f4 Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Thu, 14 Dec 2023 08:13:38 -0800 Subject: [PATCH 013/255] Replace the fake ParseMessage/ParseGroup function calls in with ones that accept a lambda. It allows the callers to drop the mock "message" types that only exist to have an _InternalParse function in them. It also gives more freedom to the caller to do things like force inlining when it matters. Do more inlining in certain callers of ParseLoop to avoid the extra stack frame. This reduces the overall cost of maintaining the stack frames in functions like FastMtS1. PiperOrigin-RevId: 590943926 --- .../protobuf/generated_message_tctable_impl.h | 3 + .../generated_message_tctable_lite.cc | 48 +++++++----- src/google/protobuf/parse_context.h | 76 ++++++------------- 3 files changed, 56 insertions(+), 71 deletions(-) diff --git a/src/google/protobuf/generated_message_tctable_impl.h b/src/google/protobuf/generated_message_tctable_impl.h index fb111e34fe73e..285bdd345211e 100644 --- a/src/google/protobuf/generated_message_tctable_impl.h +++ b/src/google/protobuf/generated_message_tctable_impl.h @@ -394,6 +394,9 @@ class PROTOBUF_EXPORT TcParser final { static const char* ParseLoop(MessageLite* msg, const char* ptr, ParseContext* ctx, const TcParseTableBase* table); + static const char* ParseLoopInlined(MessageLite* msg, const char* ptr, + ParseContext* ctx, + const TcParseTableBase* table); // Functions referenced by generated fast tables (numeric types): // F: fixed V: varint Z: zigzag diff --git a/src/google/protobuf/generated_message_tctable_lite.cc b/src/google/protobuf/generated_message_tctable_lite.cc index ed09b87f3ca40..eafa3da238e7e 100644 --- a/src/google/protobuf/generated_message_tctable_lite.cc +++ b/src/google/protobuf/generated_message_tctable_lite.cc @@ -73,7 +73,7 @@ const char* TcParser::GenericFallbackLite(PROTOBUF_TC_PARAM_DECL) { // Core fast parsing implementation: ////////////////////////////////////////////////////////////////////////////// -PROTOBUF_NOINLINE const char* TcParser::ParseLoop( +inline PROTOBUF_ALWAYS_INLINE const char* TcParser::ParseLoopInlined( MessageLite* msg, const char* ptr, ParseContext* ctx, const TcParseTableBase* table) { // Note: TagDispatch uses a dispatch table at "&table->fast_entries". @@ -98,6 +98,12 @@ PROTOBUF_NOINLINE const char* TcParser::ParseLoop( return ptr; } +PROTOBUF_NOINLINE const char* TcParser::ParseLoop( + MessageLite* msg, const char* ptr, ParseContext* ctx, + const TcParseTableBase* table) { + return ParseLoopInlined(msg, ptr, ctx, table); +} + // On the fast path, a (matching) 1-byte tag already has the decoded value. static uint32_t FastDecodeTag(uint8_t coded_tag) { return coded_tag; @@ -387,11 +393,12 @@ inline PROTOBUF_ALWAYS_INLINE const char* TcParser::SingularParseMessageAuxImpl( if (field == nullptr) { field = inner_table->default_instance->New(msg->GetArena()); } - if (group_coding) { - return ctx->ParseGroup(field, ptr, FastDecodeTag(saved_tag), - inner_table); - } - return ctx->ParseMessage(field, ptr, inner_table); + const auto inner_loop = [&](const char* ptr) { + return ParseLoopInlined(field, ptr, ctx, inner_table); + }; + return group_coding ? ctx->ParseGroupInlined(ptr, FastDecodeTag(saved_tag), + inner_loop) + : ctx->ParseLengthDelimitedInlined(ptr, inner_loop); } else { if (field == nullptr) { const MessageLite* default_instance = @@ -474,12 +481,12 @@ inline PROTOBUF_ALWAYS_INLINE const char* TcParser::RepeatedParseMessageAuxImpl( ptr += sizeof(TagType); MessageLite* submsg = field.AddMessage(default_instance); if (aux_is_table) { - if (group_coding) { - ptr = ctx->ParseGroup(submsg, ptr, - FastDecodeTag(expected_tag), aux.table); - } else { - ptr = ctx->ParseMessage(submsg, ptr, aux.table); - } + const auto inner_loop = [&](const char* ptr) { + return ParseLoopInlined(submsg, ptr, ctx, aux.table); + }; + ptr = group_coding ? ctx->ParseGroupInlined( + ptr, FastDecodeTag(expected_tag), inner_loop) + : ctx->ParseLengthDelimitedInlined(ptr, inner_loop); } else { if (group_coding) { ptr = ctx->ParseGroup(submsg, ptr, FastDecodeTag(expected_tag)); @@ -2369,10 +2376,11 @@ PROTOBUF_NOINLINE const char* TcParser::MpMessage(PROTOBUF_TC_PARAM_DECL) { if (need_init || field == nullptr) { field = inner_table->default_instance->New(msg->GetArena()); } - if (is_group) { - return ctx->ParseGroup(field, ptr, decoded_tag, inner_table); - } - return ctx->ParseMessage(field, ptr, inner_table); + const auto inner_loop = [&](const char* ptr) { + return ParseLoop(field, ptr, ctx, inner_table); + }; + return is_group ? ctx->ParseGroupInlined(ptr, decoded_tag, inner_loop) + : ctx->ParseLengthDelimitedInlined(ptr, inner_loop); } else { if (need_init || field == nullptr) { const MessageLite* def; @@ -2428,9 +2436,11 @@ const char* TcParser::MpRepeatedMessageOrGroup(PROTOBUF_TC_PARAM_DECL) { uint32_t next_tag; do { MessageLite* value = field.AddMessage(default_instance); - ptr = is_group ? ctx->ParseGroup(value, ptr2, decoded_tag, - inner_table) - : ctx->ParseMessage(value, ptr2, inner_table); + const auto inner_loop = [&](const char* ptr) { + return ParseLoop(value, ptr, ctx, inner_table); + }; + ptr = is_group ? ctx->ParseGroupInlined(ptr2, decoded_tag, inner_loop) + : ctx->ParseLengthDelimitedInlined(ptr2, inner_loop); if (PROTOBUF_PREDICT_FALSE(ptr == nullptr)) goto error; if (PROTOBUF_PREDICT_FALSE(!ctx->DataAvailable(ptr))) goto parse_loop; ptr2 = ReadTag(ptr, &next_tag); diff --git a/src/google/protobuf/parse_context.h b/src/google/protobuf/parse_context.h index 776773c5cb52a..af48e07e94e03 100644 --- a/src/google/protobuf/parse_context.h +++ b/src/google/protobuf/parse_context.h @@ -494,34 +494,18 @@ class PROTOBUF_EXPORT ParseContext : public EpsCopyInputStream { const char* ParseMessage(MessageLite* msg, const char* ptr); - // This overload supports those few cases where ParseMessage is called - // on a class that is not actually a proto message. - // TODO: Eliminate this use case. - template ::value, - bool>::type = true> - PROTOBUF_NODISCARD const char* ParseMessage(T* msg, const char* ptr); - // Read the length prefix, push the new limit, call the func(ptr), and then - // pop the limit. Useful for situations that don't value an actual message, - // like map entries. + // pop the limit. Useful for situations that don't have an actual message. template PROTOBUF_NODISCARD const char* ParseLengthDelimitedInlined(const char*, const Func& func); - template - PROTOBUF_NODISCARD PROTOBUF_ALWAYS_INLINE const char* ParseMessage( - MessageLite* msg, const char* ptr, const Table* table) { - LimitToken old; - ptr = ReadSizeAndPushLimitAndDepthInlined(ptr, &old); - if (ptr == nullptr) return ptr; - auto old_depth = depth_; - ptr = TcParser::ParseLoop(msg, ptr, this, table); - if (ptr != nullptr) ABSL_DCHECK_EQ(old_depth, depth_); - depth_++; - if (!PopLimit(std::move(old))) return nullptr; - return ptr; - } + // Push the recursion depth, call the func(ptr), and then pop depth. Useful + // for situations that don't have an actual message. + template + PROTOBUF_NODISCARD const char* ParseGroupInlined(const char* ptr, + uint32_t start_tag, + const Func& func); template PROTOBUF_NODISCARD PROTOBUF_NDEBUG_INLINE const char* ParseGroup( @@ -541,24 +525,6 @@ class PROTOBUF_EXPORT ParseContext : public EpsCopyInputStream { return ptr; } - template - PROTOBUF_NODISCARD PROTOBUF_ALWAYS_INLINE const char* ParseGroup( - MessageLite* msg, const char* ptr, uint32_t tag, const Table* table) { - if (--depth_ < 0) return nullptr; - group_depth_++; - auto old_depth = depth_; - auto old_group_depth = group_depth_; - ptr = TcParser::ParseLoop(msg, ptr, this, table); - if (ptr != nullptr) { - ABSL_DCHECK_EQ(old_depth, depth_); - ABSL_DCHECK_EQ(old_group_depth, group_depth_); - } - group_depth_--; - depth_++; - if (PROTOBUF_PREDICT_FALSE(!ConsumeEndGroup(tag))) return nullptr; - return ptr; - } - private: // Out-of-line routine to save space in ParseContext::ParseMessage // LimitToken old; @@ -1105,15 +1071,14 @@ inline int32_t ReadVarintZigZag32(const char** p) { return WireFormatLite::ZigZagDecode32(static_cast(tmp)); } -template ::value, bool>::type> -PROTOBUF_NODISCARD const char* ParseContext::ParseMessage(T* msg, - const char* ptr) { +template +PROTOBUF_NODISCARD PROTOBUF_ALWAYS_INLINE const char* +ParseContext::ParseLengthDelimitedInlined(const char* ptr, const Func& func) { LimitToken old; - ptr = ReadSizeAndPushLimitAndDepth(ptr, &old); + ptr = ReadSizeAndPushLimitAndDepthInlined(ptr, &old); if (ptr == nullptr) return ptr; auto old_depth = depth_; - ptr = msg->_InternalParse(ptr, this); + PROTOBUF_ALWAYS_INLINE_CALL ptr = func(ptr); if (ptr != nullptr) ABSL_DCHECK_EQ(old_depth, depth_); depth_++; if (!PopLimit(std::move(old))) return nullptr; @@ -1122,13 +1087,20 @@ PROTOBUF_NODISCARD const char* ParseContext::ParseMessage(T* msg, template PROTOBUF_NODISCARD PROTOBUF_ALWAYS_INLINE const char* -ParseContext::ParseLengthDelimitedInlined(const char* ptr, const Func& func) { - LimitToken old; - ptr = ReadSizeAndPushLimitAndDepthInlined(ptr, &old); - if (ptr == nullptr) return ptr; +ParseContext::ParseGroupInlined(const char* ptr, uint32_t start_tag, + const Func& func) { + if (--depth_ < 0) return nullptr; + group_depth_++; + auto old_depth = depth_; + auto old_group_depth = group_depth_; PROTOBUF_ALWAYS_INLINE_CALL ptr = func(ptr); + if (ptr != nullptr) { + ABSL_DCHECK_EQ(old_depth, depth_); + ABSL_DCHECK_EQ(old_group_depth, group_depth_); + } + group_depth_--; depth_++; - if (!PopLimit(std::move(old))) return nullptr; + if (PROTOBUF_PREDICT_FALSE(!ConsumeEndGroup(start_tag))) return nullptr; return ptr; } From 1db8ed47c29fa04b51df373ce5bbb7e7f95cbd56 Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Thu, 14 Dec 2023 08:15:15 -0800 Subject: [PATCH 014/255] RepeatedPtrField clears elements lazily. This allows to reduce binary bloat (all calls to Clear are now defined out of line) and eliminate redundant calls to clear (since we only call it when it is needed). PiperOrigin-RevId: 590944438 --- .../protobuf/generated_message_reflection.cc | 15 +- src/google/protobuf/implicit_weak_message.h | 2 +- .../protobuf/repeated_field_unittest.cc | 1 - src/google/protobuf/repeated_ptr_field.cc | 50 +++-- src/google/protobuf/repeated_ptr_field.h | 207 +++++++++--------- 5 files changed, 140 insertions(+), 135 deletions(-) diff --git a/src/google/protobuf/generated_message_reflection.cc b/src/google/protobuf/generated_message_reflection.cc index 647b4cc747b80..0c914e832e734 100644 --- a/src/google/protobuf/generated_message_reflection.cc +++ b/src/google/protobuf/generated_message_reflection.cc @@ -1431,7 +1431,7 @@ void Reflection::ClearField(Message* message, switch (field->options().ctype()) { default: // TODO: Support other string reps. case FieldOptions::STRING: - MutableRaw >(message, field)->Clear(); + MutableRaw(message, field)->Clear(); break; } break; @@ -1441,10 +1441,7 @@ void Reflection::ClearField(Message* message, if (IsMapFieldInApi(field)) { MutableRaw(message, field)->Clear(); } else { - // We don't know which subclass of RepeatedPtrFieldBase the type is, - // so we use RepeatedPtrFieldBase directly. - MutableRaw(message, field) - ->Clear >(); + MutableRaw(message, field)->Clear(); } break; } @@ -1481,8 +1478,7 @@ void Reflection::RemoveLast(Message* message, switch (field->options().ctype()) { default: // TODO: Support other string reps. case FieldOptions::STRING: - MutableRaw >(message, field) - ->RemoveLast(); + MutableRaw(message, field)->RemoveLast(); break; } break; @@ -1491,10 +1487,9 @@ void Reflection::RemoveLast(Message* message, if (IsMapFieldInApi(field)) { MutableRaw(message, field) ->MutableRepeatedField() - ->RemoveLast >(); + ->RemoveLast(); } else { - MutableRaw(message, field) - ->RemoveLast >(); + MutableRaw(message, field)->RemoveLast(); } break; } diff --git a/src/google/protobuf/implicit_weak_message.h b/src/google/protobuf/implicit_weak_message.h index 708f73a151c0c..7856c2212d4f1 100644 --- a/src/google/protobuf/implicit_weak_message.h +++ b/src/google/protobuf/implicit_weak_message.h @@ -201,7 +201,7 @@ struct WeakRepeatedPtrField { } T* Add() { return weak.Add(); } - void Clear() { base().template Clear(); } + void Clear() { base().Clear(); } void MergeFrom(const WeakRepeatedPtrField& other) { if (other.empty()) return; base().template MergeFrom(other.base()); diff --git a/src/google/protobuf/repeated_field_unittest.cc b/src/google/protobuf/repeated_field_unittest.cc index d99aae6f525fe..e2c3294bd1bf8 100644 --- a/src/google/protobuf/repeated_field_unittest.cc +++ b/src/google/protobuf/repeated_field_unittest.cc @@ -1658,7 +1658,6 @@ TEST(RepeatedPtrField, ClearedElements) { EXPECT_EQ(field.ClearedCount(), 0); field.RemoveLast(); - EXPECT_TRUE(original->empty()); EXPECT_EQ(field.ClearedCount(), 1); EXPECT_EQ(field.Add(), diff --git a/src/google/protobuf/repeated_ptr_field.cc b/src/google/protobuf/repeated_ptr_field.cc index 49c29fe433d6a..4d929376eefac 100644 --- a/src/google/protobuf/repeated_ptr_field.cc +++ b/src/google/protobuf/repeated_ptr_field.cc @@ -54,7 +54,7 @@ void** RepeatedPtrFieldBase::InternalExtend(int extend_amount) { new_rep = reinterpret_cast(Arena::CreateArray(arena, bytes)); } - if (using_sso()) { + if (using_element()) { new_rep->allocated_size = tagged_rep_or_elem_ != nullptr ? 1 : 0; new_rep->elements[0] = tagged_rep_or_elem_; } else { @@ -75,7 +75,7 @@ void** RepeatedPtrFieldBase::InternalExtend(int extend_amount) { tagged_rep_or_elem_ = reinterpret_cast(reinterpret_cast(new_rep) + 1); - capacity_proxy_ = new_capacity - kSSOCapacity; + capacity_proxy_ = new_capacity - kInlinedCapacity; return &new_rep->elements[current_size_]; } @@ -94,18 +94,31 @@ void RepeatedPtrFieldBase::DestroyProtos() { tagged_rep_or_elem_ = nullptr; } -template -auto* RepeatedPtrFieldBase::AddInternal(F factory) { +namespace { +template +struct ElementRecycler { + static void clear(void* p) { static_cast(p)->Clear(); } +}; + +template <> +struct ElementRecycler { + static void clear(void* str) { static_cast(str)->clear(); } +}; + +} // namespace + +template +void* RepeatedPtrFieldBase::AddInternal(Factory factory) { Arena* const arena = GetArena(); - using Result = decltype(factory(arena)); if (tagged_rep_or_elem_ == nullptr) { ExchangeCurrentSize(1); tagged_rep_or_elem_ = factory(arena); - return static_cast(tagged_rep_or_elem_); + return tagged_rep_or_elem_; } - if (using_sso()) { + if (using_element()) { if (ExchangeCurrentSize(1) == 0) { - return static_cast(tagged_rep_or_elem_); + Recycler::clear(tagged_rep_or_elem_); + return tagged_rep_or_elem_; } } else { absl::PrefetchToLocalCache(rep()); @@ -115,23 +128,28 @@ auto* RepeatedPtrFieldBase::AddInternal(F factory) { } else { Rep* r = rep(); if (current_size_ != r->allocated_size) { - return static_cast( - r->elements[ExchangeCurrentSize(current_size_ + 1)]); + void* cached = r->elements[ExchangeCurrentSize(current_size_ + 1)]; + Recycler::clear(cached); + return cached; } } Rep* r = rep(); ++r->allocated_size; void*& result = r->elements[ExchangeCurrentSize(current_size_ + 1)]; result = factory(arena); - return static_cast(result); + return result; +} + +void* RepeatedPtrFieldBase::AddMessageLite(ElementFactory factory) { + return AddInternal>(factory); } -void* RepeatedPtrFieldBase::AddOutOfLineHelper(ElementFactory factory) { - return AddInternal(factory); +void* RepeatedPtrFieldBase::AddString() { + return AddInternal>(NewStringElement); } void RepeatedPtrFieldBase::CloseGap(int start, int num) { - if (using_sso()) { + if (using_element()) { if (start == 0 && num == 1) { tagged_rep_or_elem_ = nullptr; } @@ -146,7 +164,8 @@ void RepeatedPtrFieldBase::CloseGap(int start, int num) { } MessageLite* RepeatedPtrFieldBase::AddMessage(const MessageLite* prototype) { - return AddInternal([prototype](Arena* a) { return prototype->New(a); }); + return static_cast(AddInternal>( + [prototype](Arena* a) { return prototype->New(a); })); } void InternalOutOfLineDeleteMessageLite(MessageLite* message) { @@ -197,6 +216,7 @@ int RepeatedPtrFieldBase::MergeIntoClearedMessages( ABSL_DCHECK(typeid(*src[i]) == typeid(*src[0])) << typeid(*src[i]).name() << " vs " << typeid(*src[0]).name(); #endif + dst[i]->Clear(); dst[i]->CheckTypeAndMergeFrom(*src[i]); } return count; diff --git a/src/google/protobuf/repeated_ptr_field.h b/src/google/protobuf/repeated_ptr_field.h index 644bdb47574b6..05bb7897e6993 100644 --- a/src/google/protobuf/repeated_ptr_field.h +++ b/src/google/protobuf/repeated_ptr_field.h @@ -116,7 +116,7 @@ class PROTOBUF_EXPORT RepeatedPtrFieldBase { template using Value = typename Handler::Type; - static constexpr int kSSOCapacity = 1; + static constexpr int kInlinedCapacity = 1; using ElementFactory = void* (*)(Arena*); @@ -158,7 +158,7 @@ class PROTOBUF_EXPORT RepeatedPtrFieldBase { // // * prefer `SizeAtCapacity()` to `size() == Capacity()`; // * prefer `AllocatedSizeAtCapacity()` to `allocated_size() == Capacity()`. - int Capacity() const { return capacity_proxy_ + kSSOCapacity; } + int Capacity() const { return capacity_proxy_ + kInlinedCapacity; } template const Value& at(int index) const { @@ -183,7 +183,10 @@ class PROTOBUF_EXPORT RepeatedPtrFieldBase { template Value* Add() { - return cast(AddOutOfLineHelper(Handler::GetNewFunc())); + if (std::is_same, std::string>{}) { + return cast(AddString()); + } + return cast(AddMessageLite(Handler::GetNewFunc())); } template < @@ -196,7 +199,7 @@ class PROTOBUF_EXPORT RepeatedPtrFieldBase { return; } MaybeExtend(); - if (!using_sso()) ++rep()->allocated_size; + if (!using_element()) ++rep()->allocated_size; auto* result = TypeHandler::New(arena_, std::move(value)); element_at(ExchangeCurrentSize(current_size_ + 1)) = result; } @@ -218,15 +221,14 @@ class PROTOBUF_EXPORT RepeatedPtrFieldBase { for (int i = 0; i < n; i++) { Delete(elems[i], nullptr); } - if (!using_sso()) { + if (!using_element()) { internal::SizedDelete(rep(), Capacity() * sizeof(elems[0]) + kRepHeaderSize); } } inline bool NeedsDestroy() const { - // Either there is an allocated element in SSO buffer or there is an - // allocated Rep. + // tagged_rep_or_elem_ contains either allocated element or allocated `Rep`. return tagged_rep_or_elem_ != nullptr; } void DestroyProtos(); @@ -249,15 +251,7 @@ class PROTOBUF_EXPORT RepeatedPtrFieldBase { // Pre-condition: prototype must not be nullptr. MessageLite* AddMessage(const MessageLite* prototype); - template - void Clear() { - const int n = current_size_; - ABSL_DCHECK_GE(n, 0); - if (n > 0) { - using H = CommonHandler; - ClearNonEmpty(); - } - } + void Clear() { ExchangeCurrentSize(0); } // Appends all message values from `from` to this instance. template @@ -294,24 +288,21 @@ class PROTOBUF_EXPORT RepeatedPtrFieldBase { ABSL_DCHECK_EQ(current_size_, allocated_size()); MaybeExtend(); element_at(current_size_++) = value; - if (!using_sso()) ++rep()->allocated_size; + if (!using_element()) ++rep()->allocated_size; } protected: - template void RemoveLast() { ABSL_DCHECK_GT(current_size_, 0); ExchangeCurrentSize(current_size_ - 1); - using H = CommonHandler; - H::Clear(cast(element_at(current_size_))); } template void CopyFrom(const RepeatedPtrFieldBase& other) { if (&other == this) return; - RepeatedPtrFieldBase::Clear(); + RepeatedPtrFieldBase::Clear(); if (other.empty()) return; - RepeatedPtrFieldBase::MergeFrom(other); + RepeatedPtrFieldBase::MergeFrom>(other); } void CloseGap(int start, int num); @@ -366,7 +357,7 @@ class PROTOBUF_EXPORT RepeatedPtrFieldBase { template PROTOBUF_NOINLINE size_t SpaceUsedExcludingSelfLong() const { size_t allocated_bytes = - using_sso() + using_element() ? 0 : static_cast(Capacity()) * sizeof(void*) + kRepHeaderSize; const int n = allocated_size(); @@ -380,15 +371,15 @@ class PROTOBUF_EXPORT RepeatedPtrFieldBase { // Advanced memory management -------------------------------------- - // Like Add(), but if there are no cleared objects to use, returns nullptr. + // Returns a pointer to a cleared object ready to reuse if there is a spare + // allocated object or nullptr otherwise. template Value* AddFromCleared() { - if (current_size_ < allocated_size()) { - return cast( - element_at(ExchangeCurrentSize(current_size_ + 1))); - } else { - return nullptr; - } + if (ClearedCount() == 0) return nullptr; + auto* value = + cast(element_at(ExchangeCurrentSize(current_size_ + 1))); + CommonHandler::Clear(value); + return value; } template @@ -410,7 +401,7 @@ class PROTOBUF_EXPORT RepeatedPtrFieldBase { elems[allocated_size()] = elems[current_size_]; } elems[ExchangeCurrentSize(current_size_ + 1)] = value; - if (!using_sso()) ++rep()->allocated_size; + if (!using_element()) ++rep()->allocated_size; } template @@ -418,24 +409,24 @@ class PROTOBUF_EXPORT RepeatedPtrFieldBase { ABSL_DCHECK_NE(value, nullptr); // Make room for the new pointer. if (SizeAtCapacity()) { - // The array is completely full with no cleared objects, so grow it. + // The array is completely full, so grow it. InternalExtend(1); ++rep()->allocated_size; } else if (AllocatedSizeAtCapacity()) { // There is no more space in the pointer array because it contains some - // cleared objects awaiting reuse. We don't want to grow the array in + // objects awaiting reuse. We don't want to grow the array in // this case because otherwise a loop calling AddAllocated() followed by // Clear() would leak memory. using H = CommonHandler; Delete(element_at(current_size_), arena_); } else if (current_size_ < allocated_size()) { - // We have some cleared objects. We don't care about their order, so we - // can just move the first one to the end to make space. + // We have some unused allocated objects. Their order is not important, + // so we move the first one to the end to make room for the pointer. element_at(allocated_size()) = element_at(current_size_); ++rep()->allocated_size; } else { - // There are no cleared objects. - if (!using_sso()) ++rep()->allocated_size; + // There are no unused allocated objects. + if (!using_element()) ++rep()->allocated_size; } element_at(ExchangeCurrentSize(current_size_ + 1)) = value; @@ -464,13 +455,13 @@ class PROTOBUF_EXPORT RepeatedPtrFieldBase { ABSL_DCHECK_GT(current_size_, 0); ExchangeCurrentSize(current_size_ - 1); auto* result = cast(element_at(current_size_)); - if (using_sso()) { + if (using_element()) { tagged_rep_or_elem_ = nullptr; } else { --rep()->allocated_size; if (current_size_ < allocated_size()) { - // There are cleared elements on the end; replace the removed element - // with the last allocated element. + // There are unused allocated elements on the end; replace the removed + // element with the last allocated element. element_at(current_size_) = element_at(allocated_size()); } } @@ -486,7 +477,7 @@ class PROTOBUF_EXPORT RepeatedPtrFieldBase { ABSL_DCHECK(TypeHandler::GetArena(value) == nullptr) << "AddCleared() can only accept values not on an arena."; MaybeExtend(); - if (using_sso()) { + if (using_element()) { tagged_rep_or_elem_ = value; } else { element_at(rep()->allocated_size++) = value; @@ -500,13 +491,14 @@ class PROTOBUF_EXPORT RepeatedPtrFieldBase { << "an arena."; ABSL_DCHECK(tagged_rep_or_elem_ != nullptr); ABSL_DCHECK_GT(allocated_size(), current_size_); - if (using_sso()) { - auto* result = cast(tagged_rep_or_elem_); - tagged_rep_or_elem_ = nullptr; - return result; + void* result; + if (using_element()) { + result = std::exchange(tagged_rep_or_elem_, nullptr); } else { - return cast(element_at(--rep()->allocated_size)); + result = element_at(--rep()->allocated_size); } + TypeHandler::Clear(cast(result)); + return cast(result); } // Slowpath handles all cases, copying if necessary. @@ -544,7 +536,7 @@ class PROTOBUF_EXPORT RepeatedPtrFieldBase { // than three times. RepeatedPtrFieldBase temp(other->GetArena()); if (!this->empty()) { - temp.MergeFrom(*this); + temp.MergeFrom>(*this); } this->CopyFrom(*other); other->InternalSwap(&temp); @@ -625,30 +617,29 @@ class PROTOBUF_EXPORT RepeatedPtrFieldBase { ABSL_DCHECK_LE(size(), allocated_size()); ABSL_DCHECK_LE(allocated_size(), Capacity()); // This is equivalent to `current_size_ == Capacity()`. - // Assuming `Capacity()` function is inlined, compiler is likely to optimize - // away "+ kSSOCapacity" and reduce it to "current_size_ > capacity_proxy_" - // which is an instruction less than "current_size_ == capacity_proxy_ + 1". + // + // Using less than instead of equality gives compiler an opportunity to + // generate less instructions. return current_size_ >= Capacity(); } inline bool AllocatedSizeAtCapacity() const { // Harden invariant size() <= allocated_size() <= Capacity(). ABSL_DCHECK_LE(size(), allocated_size()); ABSL_DCHECK_LE(allocated_size(), Capacity()); - // This combines optimization mentioned in `SizeAtCapacity()` and simplifies - // `allocated_size()` in sso case. - return using_sso() ? (tagged_rep_or_elem_ != nullptr) - : rep()->allocated_size >= Capacity(); + // See comment in SizeAtCapacity(). + return using_element() ? (tagged_rep_or_elem_ != nullptr) + : rep()->allocated_size >= Capacity(); } void* const* elements() const { - return using_sso() ? &tagged_rep_or_elem_ : +rep()->elements; + return using_element() ? &tagged_rep_or_elem_ : +rep()->elements; } void** elements() { - return using_sso() ? &tagged_rep_or_elem_ : +rep()->elements; + return using_element() ? &tagged_rep_or_elem_ : +rep()->elements; } void*& element_at(int index) { - if (using_sso()) { + if (using_element()) { ABSL_DCHECK_EQ(index, 0); return tagged_rep_or_elem_; } @@ -659,11 +650,11 @@ class PROTOBUF_EXPORT RepeatedPtrFieldBase { } int allocated_size() const { - return using_sso() ? (tagged_rep_or_elem_ != nullptr ? 1 : 0) - : rep()->allocated_size; + return using_element() ? (tagged_rep_or_elem_ != nullptr ? 1 : 0) + : rep()->allocated_size; } Rep* rep() { - ABSL_DCHECK(!using_sso()); + ABSL_DCHECK(!using_element()); return reinterpret_cast( reinterpret_cast(tagged_rep_or_elem_) - 1); } @@ -671,7 +662,7 @@ class PROTOBUF_EXPORT RepeatedPtrFieldBase { return const_cast(this)->rep(); } - bool using_sso() const { + bool using_element() const { return (reinterpret_cast(tagged_rep_or_elem_) & 1) == 0; } @@ -688,28 +679,13 @@ class PROTOBUF_EXPORT RepeatedPtrFieldBase { TypeHandler::Delete(cast(obj), arena); } - // Out-of-line helper routine for Clear() once the inlined check has - // determined the container is non-empty - template - PROTOBUF_NOINLINE void ClearNonEmpty() { - const int n = current_size_; - void* const* elems = elements(); - int i = 0; - ABSL_DCHECK_GT(n, 0); - // do/while loop to avoid initial test because we know n > 0 - do { - TypeHandler::Clear(cast(elems[i++])); - } while (i < n); - ExchangeCurrentSize(0); - } - - // Merges messages from `from` into available, cleared messages sitting in the - // range `[size(), allocated_size())`. Returns the number of message merged - // which is `ClearedCount(), from.size())`. - // Note that this function does explicitly NOT update `current_size_`. - // This function is out of line as it should be the slow path: this scenario - // only happens when a caller constructs and fills a repeated field, then - // shrinks it, and then merges additional messages into it. + // Merges messages from `from` into available, allocated messages sitting in + // the range `[size(), allocated_size())`. Returns the number of message + // merged which is `ClearedCount(), from.size())`. + // Note that this function does explicitly NOT update `current_size_`. This + // function is out of line as it should be the slow path: this scenario only + // happens when a caller constructs and fills a repeated field, then shrinks + // it, and then merges additional messages into it. int MergeIntoClearedMessages(const RepeatedPtrFieldBase& from); // Appends all messages from `from` to this instance, using the @@ -736,40 +712,55 @@ class PROTOBUF_EXPORT RepeatedPtrFieldBase { // Returns a pointer to the element directly beyond the last element. inline void** InternalReserve(int n) { if (n <= Capacity()) { - void** elements = using_sso() ? &tagged_rep_or_elem_ : rep()->elements; - return elements + current_size_; + return elements() + current_size_; } return InternalExtend(n - Capacity()); } - // Internal helper for Add that keeps definition out-of-line. - void* AddOutOfLineHelper(ElementFactory factory); + // Internal helpers for Add that keep definition out-of-line. + void* AddMessageLite(ElementFactory factory); + void* AddString(); // Common implementation used by various Add* methods. `factory` is an object - // used to construct a new element unless there are spare cleared elements + // used to construct a new element unless there are spare allocated elements // ready for reuse. Returns pointer to the new element. // // Note: avoid inlining this function in methods such as `Add()` as this would // drastically increase binary size due to template instantiation and implicit - // inlining. Instead, use wrapper functions with out-of-line definition - // similar to `AddOutOfLineHelper`. - template - auto* AddInternal(F factory); + // inlining. + template + void* AddInternal(Factory factory); // A few notes on internal representation: // - // We use an indirected approach, with struct Rep, to keep - // sizeof(RepeatedPtrFieldBase) equivalent to what it was before arena support - // was added; namely, 3 8-byte machine words on x86-64. An instance of Rep is - // allocated only when the repeated field is non-empty, and it is a - // dynamically-sized struct (the header is directly followed by elements[]). - // We place arena_ and current_size_ directly in the object to avoid cache - // misses due to the indirection, because these fields are checked frequently. - // Placing all fields directly in the RepeatedPtrFieldBase instance would cost - // significant performance for memory-sensitive workloads. + // * Class layout is optimized to minimize the size: 24 bytes on x86-64. + // * The elements can be stored in one of the two ways and `using_element()` + // tells which one is currently used. + // + // In case of using_element(): + // + // tagged_rep_or_elem_ is a storage for at most one pointer. + // Number of allocated objects (0 or 1) is determined whether + // tagged_rep_or_elem_ is nullptr. + // + // Otherwise, + // + // tagged_rep_or_elem_ is tagged (LSB is 1) pointer to `Rep`, where + // `Rep` contains number of allocated objects as well as the buffer with + // pointers to allocated elements. Rep allows to (a) keep the sizeof small + // (b) allocate both buffer for elements and an integer with allocated + // objects count in one shot. + // + // In both cases, RepeatedPtrFieldBase may own allocated but unused objects: + // + // 1. Their count is determined by `ClearedCount()`. + // 2. Pointers to them are stored directly after pointers to used objects. + // 3. They can be reused in order to avoid extra allocation (note that in + // some cases these objects need to be cleared with `TypeHandler::Clear` + // before they can be reused). void* tagged_rep_or_elem_; int current_size_; - int capacity_proxy_; // we store `capacity - kSSOCapacity` as an optimization + int capacity_proxy_; // See `Capacity()` Arena* arena_; }; @@ -984,7 +975,7 @@ class RepeatedPtrField final : private internal::RepeatedPtrFieldBase { pointer Mutable(int index) ABSL_ATTRIBUTE_LIFETIME_BOUND; // Unlike std::vector, adding an element to a RepeatedPtrField doesn't always - // make a new element; it might re-use an element left over from when the + // make a new element; it might reuse an element left over from when the // field was Clear()'d or resize()'d smaller. For this reason, Add() is the // fastest API for adding a new element. pointer Add() ABSL_ATTRIBUTE_LIFETIME_BOUND; @@ -1166,9 +1157,9 @@ class RepeatedPtrField final : private internal::RepeatedPtrFieldBase { void UnsafeArenaExtractSubrange(int start, int num, Element** elements); // When elements are removed by calls to RemoveLast() or Clear(), they - // are not actually freed. Instead, they are cleared and kept so that - // they can be reused later. This can save lots of CPU time when - // repeatedly reusing a protocol message for similar purposes. + // are not actually freed. Instead, they are kept so that they can be reused + // later. This can save lots of CPU time when repeatedly reusing a protocol + // message for similar purposes. // // Hardcore programs may choose to manipulate these cleared objects // to better optimize memory management using the following routines. @@ -1384,7 +1375,7 @@ inline void RepeatedPtrField::Add(Iter begin, Iter end) { template inline void RepeatedPtrField::RemoveLast() { - RepeatedPtrFieldBase::RemoveLast(); + RepeatedPtrFieldBase::RemoveLast(); } template @@ -1459,7 +1450,7 @@ inline void RepeatedPtrField::UnsafeArenaExtractSubrange( template inline void RepeatedPtrField::Clear() { - RepeatedPtrFieldBase::Clear(); + RepeatedPtrFieldBase::Clear(); } template From 9c7d2b9d83e0ad4e8ffeb8535d8c0a31a0a6a0b8 Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Thu, 14 Dec 2023 09:19:05 -0800 Subject: [PATCH 015/255] Make the utf8_range implementation just in C PiperOrigin-RevId: 590961088 --- php/ext/google/protobuf/config.m4 | 2 +- python/convert.c | 2 +- ruby/.gitignore | 4 +- ruby/Rakefile | 2 +- ruby/ext/google/protobuf_c/extconf.rb | 2 +- ruby/lib/google/tasks/ffi.rake | 4 +- third_party/utf8_range/BUILD.bazel | 15 +- third_party/utf8_range/CMakeLists.txt | 6 +- third_party/utf8_range/utf8_range.c | 467 ++++++++++++++++++++++++ third_party/utf8_range/utf8_range.h | 17 +- third_party/utf8_range/utf8_validity.cc | 432 +--------------------- third_party/utf8_range/utf8_validity.h | 2 + upb/wire/internal/decode.h | 21 +- 13 files changed, 499 insertions(+), 477 deletions(-) create mode 100644 third_party/utf8_range/utf8_range.c diff --git a/php/ext/google/protobuf/config.m4 b/php/ext/google/protobuf/config.m4 index c5a665b467704..5e5fbf6c083ff 100644 --- a/php/ext/google/protobuf/config.m4 +++ b/php/ext/google/protobuf/config.m4 @@ -4,7 +4,7 @@ if test "$PHP_PROTOBUF" != "no"; then PHP_NEW_EXTENSION( protobuf, - arena.c array.c convert.c def.c map.c message.c names.c php-upb.c protobuf.c third_party/utf8_range/naive.c third_party/utf8_range/range2-neon.c third_party/utf8_range/range2-sse.c, + arena.c array.c convert.c def.c map.c message.c names.c php-upb.c protobuf.c third_party/utf8_range/utf8_range.c, $ext_shared, , -std=gnu99 -I@ext_srcdir@/third_party/utf8_range) PHP_ADD_BUILD_DIR($ext_builddir/third_party/utf8_range) diff --git a/python/convert.c b/python/convert.c index 2105c98a634b9..0b26bdcabf570 100644 --- a/python/convert.c +++ b/python/convert.c @@ -241,7 +241,7 @@ bool PyUpb_PyToUpb(PyObject* obj, const upb_FieldDef* f, upb_MessageValue* val, // Use the object's bytes if they are valid UTF-8. char* ptr; if (PyBytes_AsStringAndSize(obj, &ptr, &size) < 0) return false; - if (utf8_range2((const unsigned char*)ptr, size) != 0) { + if (!utf8_range_IsValid(ptr, size)) { // Invalid UTF-8. Try to convert the message to a Python Unicode // object, even though we know this will fail, just to get the // idiomatic Python error message. diff --git a/ruby/.gitignore b/ruby/.gitignore index 143b48e92c87b..555af6ccb08b7 100644 --- a/ruby/.gitignore +++ b/ruby/.gitignore @@ -8,8 +8,6 @@ pkg/ tmp/ tests/google/ ext/google/protobuf_c/third_party/utf8_range/utf8_range.h -ext/google/protobuf_c/third_party/utf8_range/range2-sse.c -ext/google/protobuf_c/third_party/utf8_range/range2-neon.c -ext/google/protobuf_c/third_party/utf8_range/naive.c +ext/google/protobuf_c/third_party/utf8_range/utf8_range.c ext/google/protobuf_c/third_party/utf8_range/LICENSE lib/google/protobuf/*_pb.rb \ No newline at end of file diff --git a/ruby/Rakefile b/ruby/Rakefile index 860bbc35feb33..9b50e6cb65ef2 100644 --- a/ruby/Rakefile +++ b/ruby/Rakefile @@ -75,7 +75,7 @@ task :copy_third_party do # We need utf8_range in-tree. utf8_root = '../third_party/utf8_range' %w[ - utf8_range.h naive.c range2-neon.c range2-neon.c range2-sse.c LICENSE + utf8_range.h utf8_range.c LICENSE ].each do |file| FileUtils.cp File.join(utf8_root, file), "ext/google/protobuf_c/third_party/utf8_range" diff --git a/ruby/ext/google/protobuf_c/extconf.rb b/ruby/ext/google/protobuf_c/extconf.rb index 4bb49bb21570d..ed812c9549454 100755 --- a/ruby/ext/google/protobuf_c/extconf.rb +++ b/ruby/ext/google/protobuf_c/extconf.rb @@ -22,7 +22,7 @@ $srcs = ["protobuf.c", "convert.c", "defs.c", "message.c", "repeated_field.c", "map.c", "ruby-upb.c", "wrap_memcpy.c", - "naive.c", "range2-neon.c", "range2-sse.c", "shared_convert.c", + "utf8_range.c", "shared_convert.c", "shared_message.c"] create_makefile(ext_name) diff --git a/ruby/lib/google/tasks/ffi.rake b/ruby/lib/google/tasks/ffi.rake index c7b2a8e5470dd..5de10a7532b1b 100644 --- a/ruby/lib/google/tasks/ffi.rake +++ b/ruby/lib/google/tasks/ffi.rake @@ -74,9 +74,7 @@ begin FFI::Compiler::CompileTask.new 'protobuf_c_ffi' do |c| configure_common_compile_task c # Ruby UPB was already compiled with different flags. - c.exclude << "/range2-neon.c" - c.exclude << "/range2-sse.c" - c.exclude << "/naive.c" + c.exclude << "/utf8_range.c" c.exclude << "/ruby-upb.c" end diff --git a/third_party/utf8_range/BUILD.bazel b/third_party/utf8_range/BUILD.bazel index 439faaa2564e5..d24e8a14314cd 100644 --- a/third_party/utf8_range/BUILD.bazel +++ b/third_party/utf8_range/BUILD.bazel @@ -23,9 +23,7 @@ exports_files([ filegroup( name = "utf8_range_srcs", srcs = [ - "naive.c", - "range2-neon.c", - "range2-sse.c", + "utf8_range.c", "utf8_range.h", ], visibility = ["//:__subpackages__"], @@ -34,9 +32,7 @@ filegroup( cc_library( name = "utf8_range", srcs = [ - "naive.c", - "range2-neon.c", - "range2-sse.c", + "utf8_range.c", ], hdrs = ["utf8_range.h"], strip_include_prefix = "/third_party/utf8_range", @@ -48,14 +44,19 @@ cc_library( hdrs = ["utf8_validity.h"], strip_include_prefix = "/third_party/utf8_range", deps = [ + ":utf8_range", "@com_google_absl//absl/strings", ], ) cc_test( name = "utf8_validity_test", - srcs = ["utf8_validity_test.cc"], + srcs = [ + "utf8_range.c", + "utf8_validity_test.cc", + ], deps = [ + ":utf8_range", ":utf8_validity", "@com_google_absl//absl/strings", "@com_google_googletest//:gtest_main", diff --git a/third_party/utf8_range/CMakeLists.txt b/third_party/utf8_range/CMakeLists.txt index 344952d38cf59..8d7a6e15c6c09 100644 --- a/third_party/utf8_range/CMakeLists.txt +++ b/third_party/utf8_range/CMakeLists.txt @@ -12,14 +12,12 @@ option (utf8_range_ENABLE_INSTALL "Configure installation" ON) ## # Create the lightweight C library add_library (utf8_range STATIC - naive.c - range2-neon.c - range2-sse.c + utf8_range.c ) ## # A heavier-weight C++ wrapper that supports Abseil. -add_library (utf8_validity STATIC utf8_validity.cc) +add_library (utf8_validity STATIC utf8_validity.cc utf8_range.c) # Load Abseil dependency. if (NOT TARGET absl::strings) diff --git a/third_party/utf8_range/utf8_range.c b/third_party/utf8_range/utf8_range.c new file mode 100644 index 0000000000000..9564b07e03335 --- /dev/null +++ b/third_party/utf8_range/utf8_range.c @@ -0,0 +1,467 @@ +// Copyright 2023 Google LLC +// +// Use of this source code is governed by an MIT-style +// license that can be found in the LICENSE file or at +// https://opensource.org/licenses/MIT. + +/* This is a wrapper for the Google range-sse.cc algorithm which checks whether + * a sequence of bytes is a valid UTF-8 sequence and finds the longest valid + * prefix of the UTF-8 sequence. + * + * The key difference is that it checks for as much ASCII symbols as possible + * and then falls back to the range-sse.cc algorithm. The changes to the + * algorithm are cosmetic, mostly to trick the clang compiler to produce optimal + * code. + * + * For API see the utf8_validity.h header. + */ +#include "utf8_range.h" + +#include +#include +#include + +#ifdef __SSE4_1__ +#include +#include +#include +#endif + +#if defined(__GNUC__) +#define FORCE_INLINE_ATTR __attribute__((always_inline)) +#elif defined(_MSC_VER) +#define FORCE_INLINE_ATTR __forceinline +#else +#define FORCE_INLINE_ATTR +#endif + +static FORCE_INLINE_ATTR inline uint64_t utf8_range_UnalignedLoad64( + const void* p) { + uint64_t t; + memcpy(&t, p, sizeof t); + return t; +} + +static FORCE_INLINE_ATTR inline int utf8_range_AsciiIsAscii(unsigned char c) { + return c < 128; +} + +static FORCE_INLINE_ATTR inline int utf8_range_IsTrailByteOk(const char c) { + return (int8_t)(c) <= (int8_t)(0xBF); +} + +/* If return_position is false then it returns 1 if |data| is a valid utf8 + * sequence, otherwise returns 0. + * If return_position is set to true, returns the length in bytes of the prefix + of |data| that is all structurally valid UTF-8. + */ +static size_t utf8_range_ValidateUTF8Naive(const char* data, const char* end, + int return_position) { + /* We return err_pos in the loop which is always 0 if !return_position */ + size_t err_pos = 0; + size_t codepoint_bytes = 0; + /* The early check is done because of early continue's on codepoints of all + * sizes, i.e. we first check for ascii and if it is, we call continue, then + * for 2 byte codepoints, etc. This is done in order to reduce indentation and + * improve readability of the codepoint validity check. + */ + while (data + codepoint_bytes < end) { + if (return_position) { + err_pos += codepoint_bytes; + } + data += codepoint_bytes; + const size_t len = end - data; + const unsigned char byte1 = data[0]; + + /* We do not skip many ascii bytes at the same time as this function is + used for tail checking (< 16 bytes) and for non x86 platforms. We also + don't think that cases where non-ASCII codepoints are followed by ascii + happen often. For small strings it also introduces some penalty. For + purely ascii UTF8 strings (which is the overwhelming case) we call + SkipAscii function which is multiplatform and extremely fast. + */ + /* [00..7F] ASCII -> 1 byte */ + if (utf8_range_AsciiIsAscii(byte1)) { + codepoint_bytes = 1; + continue; + } + /* [C2..DF], [80..BF] -> 2 bytes */ + if (len >= 2 && byte1 >= 0xC2 && byte1 <= 0xDF && + utf8_range_IsTrailByteOk(data[1])) { + codepoint_bytes = 2; + continue; + } + if (len >= 3) { + const unsigned char byte2 = data[1]; + const unsigned char byte3 = data[2]; + + /* Is byte2, byte3 between [0x80, 0xBF] + * Check for 0x80 was done above. + */ + if (!utf8_range_IsTrailByteOk(byte2) || + !utf8_range_IsTrailByteOk(byte3)) { + return err_pos; + } + + if (/* E0, A0..BF, 80..BF */ + ((byte1 == 0xE0 && byte2 >= 0xA0) || + /* E1..EC, 80..BF, 80..BF */ + (byte1 >= 0xE1 && byte1 <= 0xEC) || + /* ED, 80..9F, 80..BF */ + (byte1 == 0xED && byte2 <= 0x9F) || + /* EE..EF, 80..BF, 80..BF */ + (byte1 >= 0xEE && byte1 <= 0xEF))) { + codepoint_bytes = 3; + continue; + } + if (len >= 4) { + const unsigned char byte4 = data[3]; + /* Is byte4 between 0x80 ~ 0xBF */ + if (!utf8_range_IsTrailByteOk(byte4)) { + return err_pos; + } + + if (/* F0, 90..BF, 80..BF, 80..BF */ + ((byte1 == 0xF0 && byte2 >= 0x90) || + /* F1..F3, 80..BF, 80..BF, 80..BF */ + (byte1 >= 0xF1 && byte1 <= 0xF3) || + /* F4, 80..8F, 80..BF, 80..BF */ + (byte1 == 0xF4 && byte2 <= 0x8F))) { + codepoint_bytes = 4; + continue; + } + } + } + return err_pos; + } + if (return_position) { + err_pos += codepoint_bytes; + } + /* if return_position is false, this returns 1. + * if return_position is true, this returns err_pos. + */ + return err_pos + (1 - return_position); +} + +#ifdef __SSE4_1__ +/* Returns the number of bytes needed to skip backwards to get to the first + byte of codepoint. + */ +static inline int utf8_range_CodepointSkipBackwards(int32_t codepoint_word) { + const int8_t* const codepoint = (const int8_t*)(&codepoint_word); + if (!utf8_range_IsTrailByteOk(codepoint[3])) { + return 1; + } else if (!utf8_range_IsTrailByteOk(codepoint[2])) { + return 2; + } else if (!utf8_range_IsTrailByteOk(codepoint[1])) { + return 3; + } + return 0; +} +#endif // __SSE4_1__ + +/* Skipping over ASCII as much as possible, per 8 bytes. It is intentional + as most strings to check for validity consist only of 1 byte codepoints. + */ +static inline const char* utf8_range_SkipAscii(const char* data, + const char* end) { + while (8 <= end - data && + (utf8_range_UnalignedLoad64(data) & 0x8080808080808080) == 0) { + data += 8; + } + while (data < end && utf8_range_AsciiIsAscii(*data)) { + ++data; + } + return data; +} + +static FORCE_INLINE_ATTR inline size_t utf8_range_Validate( + const char* data, size_t len, int return_position) { + if (len == 0) return 1 - return_position; + const char* const end = data + len; + data = utf8_range_SkipAscii(data, end); + /* SIMD algorithm always outperforms the naive version for any data of + length >=16. + */ + if (end - data < 16) { + return (return_position ? (data - (end - len)) : 0) + + utf8_range_ValidateUTF8Naive(data, end, return_position); + } +#ifndef __SSE4_1__ + return (return_position ? (data - (end - len)) : 0) + + utf8_range_ValidateUTF8Naive(data, end, return_position); +#else + /* This code checks that utf-8 ranges are structurally valid 16 bytes at once + * using superscalar instructions. + * The mapping between ranges of codepoint and their corresponding utf-8 + * sequences is below. + */ + + /* + * U+0000...U+007F 00...7F + * U+0080...U+07FF C2...DF 80...BF + * U+0800...U+0FFF E0 A0...BF 80...BF + * U+1000...U+CFFF E1...EC 80...BF 80...BF + * U+D000...U+D7FF ED 80...9F 80...BF + * U+E000...U+FFFF EE...EF 80...BF 80...BF + * U+10000...U+3FFFF F0 90...BF 80...BF 80...BF + * U+40000...U+FFFFF F1...F3 80...BF 80...BF 80...BF + * U+100000...U+10FFFF F4 80...8F 80...BF 80...BF + */ + + /* First we compute the type for each byte, as given by the table below. + * This type will be used as an index later on. + */ + + /* + * Index Min Max Byte Type + * 0 00 7F Single byte sequence + * 1,2,3 80 BF Second, third and fourth byte for many of the sequences. + * 4 A0 BF Second byte after E0 + * 5 80 9F Second byte after ED + * 6 90 BF Second byte after F0 + * 7 80 8F Second byte after F4 + * 8 C2 F4 First non ASCII byte + * 9..15 7F 80 Invalid byte + */ + + /* After the first step we compute the index for all bytes, then we permute + the bytes according to their indices to check the ranges from the range + table. + * The range for a given type can be found in the range_min_table and + range_max_table, the range for type/index X is in range_min_table[X] ... + range_max_table[X]. + */ + + /* Algorithm: + * Put index zero to all bytes. + * Find all non ASCII characters, give them index 8. + * For each tail byte in a codepoint sequence, give it an index corresponding + to the 1 based index from the end. + * If the first byte of the codepoint is in the [C0...DF] range, we write + index 1 in the following byte. + * If the first byte of the codepoint is in the range [E0...EF], we write + indices 2 and 1 in the next two bytes. + * If the first byte of the codepoint is in the range [F0...FF] we write + indices 3,2,1 into the next three bytes. + * For finding the number of bytes we need to look at high nibbles (4 bits) + and do the lookup from the table, it can be done with shift by 4 + shuffle + instructions. We call it `first_len`. + * Then we shift first_len by 8 bits to get the indices of the 2nd bytes. + * Saturating sub 1 and shift by 8 bits to get the indices of the 3rd bytes. + * Again to get the indices of the 4th bytes. + * Take OR of all that 4 values and check within range. + */ + /* For example: + * input C3 80 68 E2 80 20 A6 F0 A0 80 AC 20 F0 93 80 80 + * first_len 1 0 0 2 0 0 0 3 0 0 0 0 3 0 0 0 + * 1st byte 8 0 0 8 0 0 0 8 0 0 0 0 8 0 0 0 + * 2nd byte 0 1 0 0 2 0 0 0 3 0 0 0 0 3 0 0 // Shift + sub + * 3rd byte 0 0 0 0 0 1 0 0 0 2 0 0 0 0 2 0 // Shift + sub + * 4th byte 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 1 // Shift + sub + * Index 8 1 0 8 2 1 0 8 3 2 1 0 8 3 2 1 // OR of results + */ + + /* Checking for errors: + * Error checking is done by looking up the high nibble (4 bits) of each byte + against an error checking table. + * Because the lookup value for the second byte depends of the value of the + first byte in codepoint, we use saturated operations to adjust the index. + * Specifically we need to add 2 for E0, 3 for ED, 3 for F0 and 4 for F4 to + match the correct index. + * If we subtract from all bytes EF then EO -> 241, ED -> 254, F0 -> 1, + F4 -> 5 + * Do saturating sub 240, then E0 -> 1, ED -> 14 and we can do lookup to + match the adjustment + * Add saturating 112, then F0 -> 113, F4 -> 117, all that were > 16 will + be more 128 and lookup in ef_fe_table will return 0 but for F0 + and F4 it will be 4 and 5 accordingly + */ + /* + * Then just check the appropriate ranges with greater/smaller equal + instructions. Check tail with a naive algorithm. + * To save from previous 16 byte checks we just align previous_first_len to + get correct continuations of the codepoints. + */ + + /* + * Map high nibble of "First Byte" to legal character length minus 1 + * 0x00 ~ 0xBF --> 0 + * 0xC0 ~ 0xDF --> 1 + * 0xE0 ~ 0xEF --> 2 + * 0xF0 ~ 0xFF --> 3 + */ + const __m128i first_len_table = + _mm_setr_epi8(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 2, 3); + + /* Map "First Byte" to 8-th item of range table (0xC2 ~ 0xF4) */ + const __m128i first_range_table = + _mm_setr_epi8(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 8, 8, 8); + + /* + * Range table, map range index to min and max values + */ + const __m128i range_min_table = + _mm_setr_epi8(0x00, 0x80, 0x80, 0x80, 0xA0, 0x80, 0x90, 0x80, 0xC2, 0x7F, + 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F); + + const __m128i range_max_table = + _mm_setr_epi8(0x7F, 0xBF, 0xBF, 0xBF, 0xBF, 0x9F, 0xBF, 0x8F, 0xF4, 0x80, + 0x80, 0x80, 0x80, 0x80, 0x80, 0x80); + + /* + * Tables for fast handling of four special First Bytes(E0,ED,F0,F4), after + * which the Second Byte are not 80~BF. It contains "range index adjustment". + * +------------+---------------+------------------+----------------+ + * | First Byte | original range| range adjustment | adjusted range | + * +------------+---------------+------------------+----------------+ + * | E0 | 2 | 2 | 4 | + * +------------+---------------+------------------+----------------+ + * | ED | 2 | 3 | 5 | + * +------------+---------------+------------------+----------------+ + * | F0 | 3 | 3 | 6 | + * +------------+---------------+------------------+----------------+ + * | F4 | 4 | 4 | 8 | + * +------------+---------------+------------------+----------------+ + */ + + /* df_ee_table[1] -> E0, df_ee_table[14] -> ED as ED - E0 = 13 */ + // The values represent the adjustment in the Range Index table for a correct + // index. + const __m128i df_ee_table = + _mm_setr_epi8(0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0); + + /* ef_fe_table[1] -> F0, ef_fe_table[5] -> F4, F4 - F0 = 4 */ + // The values represent the adjustment in the Range Index table for a correct + // index. + const __m128i ef_fe_table = + _mm_setr_epi8(0, 3, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); + + __m128i prev_input = _mm_set1_epi8(0); + __m128i prev_first_len = _mm_set1_epi8(0); + __m128i error = _mm_set1_epi8(0); + while (end - data >= 16) { + const __m128i input = + _mm_loadu_si128((const __m128i*)(data)); + + /* high_nibbles = input >> 4 */ + const __m128i high_nibbles = + _mm_and_si128(_mm_srli_epi16(input, 4), _mm_set1_epi8(0x0F)); + + /* first_len = legal character length minus 1 */ + /* 0 for 00~7F, 1 for C0~DF, 2 for E0~EF, 3 for F0~FF */ + /* first_len = first_len_table[high_nibbles] */ + __m128i first_len = _mm_shuffle_epi8(first_len_table, high_nibbles); + + /* First Byte: set range index to 8 for bytes within 0xC0 ~ 0xFF */ + /* range = first_range_table[high_nibbles] */ + __m128i range = _mm_shuffle_epi8(first_range_table, high_nibbles); + + /* Second Byte: set range index to first_len */ + /* 0 for 00~7F, 1 for C0~DF, 2 for E0~EF, 3 for F0~FF */ + /* range |= (first_len, prev_first_len) << 1 byte */ + range = _mm_or_si128(range, _mm_alignr_epi8(first_len, prev_first_len, 15)); + + /* Third Byte: set range index to saturate_sub(first_len, 1) */ + /* 0 for 00~7F, 0 for C0~DF, 1 for E0~EF, 2 for F0~FF */ + __m128i tmp1; + __m128i tmp2; + /* tmp1 = saturate_sub(first_len, 1) */ + tmp1 = _mm_subs_epu8(first_len, _mm_set1_epi8(1)); + /* tmp2 = saturate_sub(prev_first_len, 1) */ + tmp2 = _mm_subs_epu8(prev_first_len, _mm_set1_epi8(1)); + /* range |= (tmp1, tmp2) << 2 bytes */ + range = _mm_or_si128(range, _mm_alignr_epi8(tmp1, tmp2, 14)); + + /* Fourth Byte: set range index to saturate_sub(first_len, 2) */ + /* 0 for 00~7F, 0 for C0~DF, 0 for E0~EF, 1 for F0~FF */ + /* tmp1 = saturate_sub(first_len, 2) */ + tmp1 = _mm_subs_epu8(first_len, _mm_set1_epi8(2)); + /* tmp2 = saturate_sub(prev_first_len, 2) */ + tmp2 = _mm_subs_epu8(prev_first_len, _mm_set1_epi8(2)); + /* range |= (tmp1, tmp2) << 3 bytes */ + range = _mm_or_si128(range, _mm_alignr_epi8(tmp1, tmp2, 13)); + + /* + * Now we have below range indices calculated + * Correct cases: + * - 8 for C0~FF + * - 3 for 1st byte after F0~FF + * - 2 for 1st byte after E0~EF or 2nd byte after F0~FF + * - 1 for 1st byte after C0~DF or 2nd byte after E0~EF or + * 3rd byte after F0~FF + * - 0 for others + * Error cases: + * >9 for non ascii First Byte overlapping + * E.g., F1 80 C2 90 --> 8 3 10 2, where 10 indicates error + */ + + /* Adjust Second Byte range for special First Bytes(E0,ED,F0,F4) */ + /* Overlaps lead to index 9~15, which are illegal in range table */ + __m128i shift1; + __m128i pos; + __m128i range2; + /* shift1 = (input, prev_input) << 1 byte */ + shift1 = _mm_alignr_epi8(input, prev_input, 15); + pos = _mm_sub_epi8(shift1, _mm_set1_epi8(0xEF)); + /* + * shift1: | EF F0 ... FE | FF 00 ... ... DE | DF E0 ... EE | + * pos: | 0 1 15 | 16 17 239| 240 241 255| + * pos-240: | 0 0 0 | 0 0 0 | 0 1 15 | + * pos+112: | 112 113 127| >= 128 | >= 128 | + */ + tmp1 = _mm_subs_epu8(pos, _mm_set1_epi8(-16)); + range2 = _mm_shuffle_epi8(df_ee_table, tmp1); + tmp2 = _mm_adds_epu8(pos, _mm_set1_epi8(112)); + range2 = _mm_add_epi8(range2, _mm_shuffle_epi8(ef_fe_table, tmp2)); + + range = _mm_add_epi8(range, range2); + + /* Load min and max values per calculated range index */ + __m128i min_range = _mm_shuffle_epi8(range_min_table, range); + __m128i max_range = _mm_shuffle_epi8(range_max_table, range); + + /* Check value range */ + if (return_position) { + error = _mm_cmplt_epi8(input, min_range); + error = _mm_or_si128(error, _mm_cmpgt_epi8(input, max_range)); + /* 5% performance drop from this conditional branch */ + if (!_mm_testz_si128(error, error)) { + break; + } + } else { + error = _mm_or_si128(error, _mm_cmplt_epi8(input, min_range)); + error = _mm_or_si128(error, _mm_cmpgt_epi8(input, max_range)); + } + + prev_input = input; + prev_first_len = first_len; + + data += 16; + } + /* If we got to the end, we don't need to skip any bytes backwards */ + if (return_position && (data - (end - len)) == 0) { + return utf8_range_ValidateUTF8Naive(data, end, return_position); + } + /* Find previous codepoint (not 80~BF) */ + data -= utf8_range_CodepointSkipBackwards(_mm_extract_epi32(prev_input, 3)); + if (return_position) { + return (data - (end - len)) + + utf8_range_ValidateUTF8Naive(data, end, return_position); + } + /* Test if there was any error */ + if (!_mm_testz_si128(error, error)) { + return 0; + } + /* Check the tail */ + return utf8_range_ValidateUTF8Naive(data, end, return_position); +#endif +} + +int utf8_range_IsValid(const char* data, size_t len) { + return utf8_range_Validate(data, len, /*return_position=*/0) != 0; +} + +size_t utf8_range_ValidPrefix(const char* data, size_t len) { + return utf8_range_Validate(data, len, /*return_position=*/1); +} diff --git a/third_party/utf8_range/utf8_range.h b/third_party/utf8_range/utf8_range.h index 24d5c77d2fdc2..d7c232616022b 100644 --- a/third_party/utf8_range/utf8_range.h +++ b/third_party/utf8_range/utf8_range.h @@ -1,18 +1,19 @@ #ifndef THIRD_PARTY_UTF8_RANGE_UTF8_RANGE_H_ #define THIRD_PARTY_UTF8_RANGE_UTF8_RANGE_H_ +#include + #ifdef __cplusplus extern "C" { #endif -#if (defined(__ARM_NEON) && defined(__aarch64__)) || defined(__SSE4_1__) -int utf8_range2(const unsigned char* data, int len); -#else -int utf8_naive(const unsigned char* data, int len); -static inline int utf8_range2(const unsigned char* data, int len) { - return utf8_naive(data, len); -} -#endif +// Returns 1 if the sequence of characters is a valid UTF-8 sequence, otherwise +// 0. +int utf8_range_IsValid(const char* data, size_t len); + +// Returns the length in bytes of the prefix of str that is all +// structurally valid UTF-8. +size_t utf8_range_ValidPrefix(const char* data, size_t len); #ifdef __cplusplus } // extern "C" diff --git a/third_party/utf8_range/utf8_validity.cc b/third_party/utf8_range/utf8_validity.cc index 9e945766732d7..4f4574e3f698a 100644 --- a/third_party/utf8_range/utf8_validity.cc +++ b/third_party/utf8_range/utf8_validity.cc @@ -15,446 +15,22 @@ * * For API see the utf8_validity.h header. */ + #include "utf8_validity.h" #include -#include -#include "absl/strings/ascii.h" #include "absl/strings/string_view.h" - -#ifdef __SSE4_1__ -#include -#include -#include -#endif +#include "utf8_range.h" namespace utf8_range { -namespace { - -inline uint64_t UNALIGNED_LOAD64(const void* p) { - uint64_t t; - memcpy(&t, p, sizeof t); - return t; -} - -inline bool TrailByteOk(const char c) { - return static_cast(c) <= static_cast(0xBF); -} - -/* If ReturnPosition is false then it returns 1 if |data| is a valid utf8 - * sequence, otherwise returns 0. - * If ReturnPosition is set to true, returns the length in bytes of the prefix - of |data| that is all structurally valid UTF-8. - */ -template -size_t ValidUTF8Span(const char* data, const char* end) { - /* We return err_pos in the loop which is always 0 if !ReturnPosition */ - size_t err_pos = 0; - size_t codepoint_bytes = 0; - /* The early check is done because of early continue's on codepoints of all - * sizes, i.e. we first check for ascii and if it is, we call continue, then - * for 2 byte codepoints, etc. This is done in order to reduce indentation and - * improve readability of the codepoint validity check. - */ - while (data + codepoint_bytes < end) { - if (ReturnPosition) { - err_pos += codepoint_bytes; - } - data += codepoint_bytes; - const size_t len = end - data; - const unsigned char byte1 = data[0]; - - /* We do not skip many ascii bytes at the same time as this function is - used for tail checking (< 16 bytes) and for non x86 platforms. We also - don't think that cases where non-ASCII codepoints are followed by ascii - happen often. For small strings it also introduces some penalty. For - purely ascii UTF8 strings (which is the overwhelming case) we call - SkipAscii function which is multiplatform and extremely fast. - */ - /* [00..7F] ASCII -> 1 byte */ - if (absl::ascii_isascii(byte1)) { - codepoint_bytes = 1; - continue; - } - /* [C2..DF], [80..BF] -> 2 bytes */ - if (len >= 2 && byte1 >= 0xC2 && byte1 <= 0xDF && TrailByteOk(data[1])) { - codepoint_bytes = 2; - continue; - } - if (len >= 3) { - const unsigned char byte2 = data[1]; - const unsigned char byte3 = data[2]; - - /* Is byte2, byte3 between [0x80, 0xBF] - * Check for 0x80 was done above. - */ - if (!TrailByteOk(byte2) || !TrailByteOk(byte3)) { - return err_pos; - } - - if (/* E0, A0..BF, 80..BF */ - ((byte1 == 0xE0 && byte2 >= 0xA0) || - /* E1..EC, 80..BF, 80..BF */ - (byte1 >= 0xE1 && byte1 <= 0xEC) || - /* ED, 80..9F, 80..BF */ - (byte1 == 0xED && byte2 <= 0x9F) || - /* EE..EF, 80..BF, 80..BF */ - (byte1 >= 0xEE && byte1 <= 0xEF))) { - codepoint_bytes = 3; - continue; - } - if (len >= 4) { - const unsigned char byte4 = data[3]; - /* Is byte4 between 0x80 ~ 0xBF */ - if (!TrailByteOk(byte4)) { - return err_pos; - } - - if (/* F0, 90..BF, 80..BF, 80..BF */ - ((byte1 == 0xF0 && byte2 >= 0x90) || - /* F1..F3, 80..BF, 80..BF, 80..BF */ - (byte1 >= 0xF1 && byte1 <= 0xF3) || - /* F4, 80..8F, 80..BF, 80..BF */ - (byte1 == 0xF4 && byte2 <= 0x8F))) { - codepoint_bytes = 4; - continue; - } - } - } - return err_pos; - } - if (ReturnPosition) { - err_pos += codepoint_bytes; - } - /* if ReturnPosition is false, this returns 1. - * if ReturnPosition is true, this returns err_pos. - */ - return err_pos + (1 - ReturnPosition); -} - -#ifdef __SSE4_1__ -/* Returns the number of bytes needed to skip backwards to get to the first - byte of codepoint. - */ -inline int CodepointSkipBackwards(int32_t codepoint_word) { - const int8_t* const codepoint = - reinterpret_cast(&codepoint_word); - if (!TrailByteOk(codepoint[3])) { - return 1; - } else if (!TrailByteOk(codepoint[2])) { - return 2; - } else if (!TrailByteOk(codepoint[1])) { - return 3; - } - return 0; -} -#endif // __SSE4_1__ - -/* Skipping over ASCII as much as possible, per 8 bytes. It is intentional - as most strings to check for validity consist only of 1 byte codepoints. - */ -inline const char* SkipAscii(const char* data, const char* end) { - while (8 <= end - data && - (UNALIGNED_LOAD64(data) & 0x8080808080808080) == 0) { - data += 8; - } - while (data < end && absl::ascii_isascii(*data)) { - ++data; - } - return data; -} - -template -size_t ValidUTF8(const char* data, size_t len) { - if (len == 0) return 1 - ReturnPosition; - const char* const end = data + len; - data = SkipAscii(data, end); - /* SIMD algorithm always outperforms the naive version for any data of - length >=16. - */ - if (end - data < 16) { - return (ReturnPosition ? (data - (end - len)) : 0) + - ValidUTF8Span(data, end); - } -#ifndef __SSE4_1__ - return (ReturnPosition ? (data - (end - len)) : 0) + - ValidUTF8Span(data, end); -#else - /* This code checks that utf-8 ranges are structurally valid 16 bytes at once - * using superscalar instructions. - * The mapping between ranges of codepoint and their corresponding utf-8 - * sequences is below. - */ - - /* - * U+0000...U+007F 00...7F - * U+0080...U+07FF C2...DF 80...BF - * U+0800...U+0FFF E0 A0...BF 80...BF - * U+1000...U+CFFF E1...EC 80...BF 80...BF - * U+D000...U+D7FF ED 80...9F 80...BF - * U+E000...U+FFFF EE...EF 80...BF 80...BF - * U+10000...U+3FFFF F0 90...BF 80...BF 80...BF - * U+40000...U+FFFFF F1...F3 80...BF 80...BF 80...BF - * U+100000...U+10FFFF F4 80...8F 80...BF 80...BF - */ - - /* First we compute the type for each byte, as given by the table below. - * This type will be used as an index later on. - */ - - /* - * Index Min Max Byte Type - * 0 00 7F Single byte sequence - * 1,2,3 80 BF Second, third and fourth byte for many of the sequences. - * 4 A0 BF Second byte after E0 - * 5 80 9F Second byte after ED - * 6 90 BF Second byte after F0 - * 7 80 8F Second byte after F4 - * 8 C2 F4 First non ASCII byte - * 9..15 7F 80 Invalid byte - */ - - /* After the first step we compute the index for all bytes, then we permute - the bytes according to their indices to check the ranges from the range - table. - * The range for a given type can be found in the range_min_table and - range_max_table, the range for type/index X is in range_min_table[X] ... - range_max_table[X]. - */ - - /* Algorithm: - * Put index zero to all bytes. - * Find all non ASCII characters, give them index 8. - * For each tail byte in a codepoint sequence, give it an index corresponding - to the 1 based index from the end. - * If the first byte of the codepoint is in the [C0...DF] range, we write - index 1 in the following byte. - * If the first byte of the codepoint is in the range [E0...EF], we write - indices 2 and 1 in the next two bytes. - * If the first byte of the codepoint is in the range [F0...FF] we write - indices 3,2,1 into the next three bytes. - * For finding the number of bytes we need to look at high nibbles (4 bits) - and do the lookup from the table, it can be done with shift by 4 + shuffle - instructions. We call it `first_len`. - * Then we shift first_len by 8 bits to get the indices of the 2nd bytes. - * Saturating sub 1 and shift by 8 bits to get the indices of the 3rd bytes. - * Again to get the indices of the 4th bytes. - * Take OR of all that 4 values and check within range. - */ - /* For example: - * input C3 80 68 E2 80 20 A6 F0 A0 80 AC 20 F0 93 80 80 - * first_len 1 0 0 2 0 0 0 3 0 0 0 0 3 0 0 0 - * 1st byte 8 0 0 8 0 0 0 8 0 0 0 0 8 0 0 0 - * 2nd byte 0 1 0 0 2 0 0 0 3 0 0 0 0 3 0 0 // Shift + sub - * 3rd byte 0 0 0 0 0 1 0 0 0 2 0 0 0 0 2 0 // Shift + sub - * 4th byte 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 1 // Shift + sub - * Index 8 1 0 8 2 1 0 8 3 2 1 0 8 3 2 1 // OR of results - */ - - /* Checking for errors: - * Error checking is done by looking up the high nibble (4 bits) of each byte - against an error checking table. - * Because the lookup value for the second byte depends of the value of the - first byte in codepoint, we use saturated operations to adjust the index. - * Specifically we need to add 2 for E0, 3 for ED, 3 for F0 and 4 for F4 to - match the correct index. - * If we subtract from all bytes EF then EO -> 241, ED -> 254, F0 -> 1, - F4 -> 5 - * Do saturating sub 240, then E0 -> 1, ED -> 14 and we can do lookup to - match the adjustment - * Add saturating 112, then F0 -> 113, F4 -> 117, all that were > 16 will - be more 128 and lookup in ef_fe_table will return 0 but for F0 - and F4 it will be 4 and 5 accordingly - */ - /* - * Then just check the appropriate ranges with greater/smaller equal - instructions. Check tail with a naive algorithm. - * To save from previous 16 byte checks we just align previous_first_len to - get correct continuations of the codepoints. - */ - - /* - * Map high nibble of "First Byte" to legal character length minus 1 - * 0x00 ~ 0xBF --> 0 - * 0xC0 ~ 0xDF --> 1 - * 0xE0 ~ 0xEF --> 2 - * 0xF0 ~ 0xFF --> 3 - */ - const __m128i first_len_table = - _mm_setr_epi8(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 2, 3); - - /* Map "First Byte" to 8-th item of range table (0xC2 ~ 0xF4) */ - const __m128i first_range_table = - _mm_setr_epi8(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 8, 8, 8); - - /* - * Range table, map range index to min and max values - */ - const __m128i range_min_table = - _mm_setr_epi8(0x00, 0x80, 0x80, 0x80, 0xA0, 0x80, 0x90, 0x80, 0xC2, 0x7F, - 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F); - - const __m128i range_max_table = - _mm_setr_epi8(0x7F, 0xBF, 0xBF, 0xBF, 0xBF, 0x9F, 0xBF, 0x8F, 0xF4, 0x80, - 0x80, 0x80, 0x80, 0x80, 0x80, 0x80); - - /* - * Tables for fast handling of four special First Bytes(E0,ED,F0,F4), after - * which the Second Byte are not 80~BF. It contains "range index adjustment". - * +------------+---------------+------------------+----------------+ - * | First Byte | original range| range adjustment | adjusted range | - * +------------+---------------+------------------+----------------+ - * | E0 | 2 | 2 | 4 | - * +------------+---------------+------------------+----------------+ - * | ED | 2 | 3 | 5 | - * +------------+---------------+------------------+----------------+ - * | F0 | 3 | 3 | 6 | - * +------------+---------------+------------------+----------------+ - * | F4 | 4 | 4 | 8 | - * +------------+---------------+------------------+----------------+ - */ - - /* df_ee_table[1] -> E0, df_ee_table[14] -> ED as ED - E0 = 13 */ - // The values represent the adjustment in the Range Index table for a correct - // index. - const __m128i df_ee_table = - _mm_setr_epi8(0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0); - - /* ef_fe_table[1] -> F0, ef_fe_table[5] -> F4, F4 - F0 = 4 */ - // The values represent the adjustment in the Range Index table for a correct - // index. - const __m128i ef_fe_table = - _mm_setr_epi8(0, 3, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); - - __m128i prev_input = _mm_set1_epi8(0); - __m128i prev_first_len = _mm_set1_epi8(0); - __m128i error = _mm_set1_epi8(0); - while (end - data >= 16) { - const __m128i input = - _mm_loadu_si128(reinterpret_cast(data)); - - /* high_nibbles = input >> 4 */ - const __m128i high_nibbles = - _mm_and_si128(_mm_srli_epi16(input, 4), _mm_set1_epi8(0x0F)); - - /* first_len = legal character length minus 1 */ - /* 0 for 00~7F, 1 for C0~DF, 2 for E0~EF, 3 for F0~FF */ - /* first_len = first_len_table[high_nibbles] */ - __m128i first_len = _mm_shuffle_epi8(first_len_table, high_nibbles); - - /* First Byte: set range index to 8 for bytes within 0xC0 ~ 0xFF */ - /* range = first_range_table[high_nibbles] */ - __m128i range = _mm_shuffle_epi8(first_range_table, high_nibbles); - - /* Second Byte: set range index to first_len */ - /* 0 for 00~7F, 1 for C0~DF, 2 for E0~EF, 3 for F0~FF */ - /* range |= (first_len, prev_first_len) << 1 byte */ - range = _mm_or_si128(range, _mm_alignr_epi8(first_len, prev_first_len, 15)); - - /* Third Byte: set range index to saturate_sub(first_len, 1) */ - /* 0 for 00~7F, 0 for C0~DF, 1 for E0~EF, 2 for F0~FF */ - __m128i tmp1; - __m128i tmp2; - /* tmp1 = saturate_sub(first_len, 1) */ - tmp1 = _mm_subs_epu8(first_len, _mm_set1_epi8(1)); - /* tmp2 = saturate_sub(prev_first_len, 1) */ - tmp2 = _mm_subs_epu8(prev_first_len, _mm_set1_epi8(1)); - /* range |= (tmp1, tmp2) << 2 bytes */ - range = _mm_or_si128(range, _mm_alignr_epi8(tmp1, tmp2, 14)); - - /* Fourth Byte: set range index to saturate_sub(first_len, 2) */ - /* 0 for 00~7F, 0 for C0~DF, 0 for E0~EF, 1 for F0~FF */ - /* tmp1 = saturate_sub(first_len, 2) */ - tmp1 = _mm_subs_epu8(first_len, _mm_set1_epi8(2)); - /* tmp2 = saturate_sub(prev_first_len, 2) */ - tmp2 = _mm_subs_epu8(prev_first_len, _mm_set1_epi8(2)); - /* range |= (tmp1, tmp2) << 3 bytes */ - range = _mm_or_si128(range, _mm_alignr_epi8(tmp1, tmp2, 13)); - - /* - * Now we have below range indices calculated - * Correct cases: - * - 8 for C0~FF - * - 3 for 1st byte after F0~FF - * - 2 for 1st byte after E0~EF or 2nd byte after F0~FF - * - 1 for 1st byte after C0~DF or 2nd byte after E0~EF or - * 3rd byte after F0~FF - * - 0 for others - * Error cases: - * >9 for non ascii First Byte overlapping - * E.g., F1 80 C2 90 --> 8 3 10 2, where 10 indicates error - */ - - /* Adjust Second Byte range for special First Bytes(E0,ED,F0,F4) */ - /* Overlaps lead to index 9~15, which are illegal in range table */ - __m128i shift1; - __m128i pos; - __m128i range2; - /* shift1 = (input, prev_input) << 1 byte */ - shift1 = _mm_alignr_epi8(input, prev_input, 15); - pos = _mm_sub_epi8(shift1, _mm_set1_epi8(0xEF)); - /* - * shift1: | EF F0 ... FE | FF 00 ... ... DE | DF E0 ... EE | - * pos: | 0 1 15 | 16 17 239| 240 241 255| - * pos-240: | 0 0 0 | 0 0 0 | 0 1 15 | - * pos+112: | 112 113 127| >= 128 | >= 128 | - */ - tmp1 = _mm_subs_epu8(pos, _mm_set1_epi8(-16)); - range2 = _mm_shuffle_epi8(df_ee_table, tmp1); - tmp2 = _mm_adds_epu8(pos, _mm_set1_epi8(112)); - range2 = _mm_add_epi8(range2, _mm_shuffle_epi8(ef_fe_table, tmp2)); - - range = _mm_add_epi8(range, range2); - - /* Load min and max values per calculated range index */ - __m128i min_range = _mm_shuffle_epi8(range_min_table, range); - __m128i max_range = _mm_shuffle_epi8(range_max_table, range); - - /* Check value range */ - if (ReturnPosition) { - error = _mm_cmplt_epi8(input, min_range); - error = _mm_or_si128(error, _mm_cmpgt_epi8(input, max_range)); - /* 5% performance drop from this conditional branch */ - if (!_mm_testz_si128(error, error)) { - break; - } - } else { - error = _mm_or_si128(error, _mm_cmplt_epi8(input, min_range)); - error = _mm_or_si128(error, _mm_cmpgt_epi8(input, max_range)); - } - - prev_input = input; - prev_first_len = first_len; - - data += 16; - } - /* If we got to the end, we don't need to skip any bytes backwards */ - if (ReturnPosition && (data - (end - len)) == 0) { - return ValidUTF8Span(data, end); - } - /* Find previous codepoint (not 80~BF) */ - data -= CodepointSkipBackwards(_mm_extract_epi32(prev_input, 3)); - if (ReturnPosition) { - return (data - (end - len)) + ValidUTF8Span(data, end); - } - /* Test if there was any error */ - if (!_mm_testz_si128(error, error)) { - return 0; - } - /* Check the tail */ - return ValidUTF8Span(data, end); -#endif -} - -} // namespace bool IsStructurallyValid(absl::string_view str) { - return ValidUTF8(str.data(), str.size()); + return utf8_range_IsValid(str.data(), str.size()); } size_t SpanStructurallyValid(absl::string_view str) { - return ValidUTF8(str.data(), str.size()); + return utf8_range_ValidPrefix(str.data(), str.size()); } } // namespace utf8_range diff --git a/third_party/utf8_range/utf8_validity.h b/third_party/utf8_range/utf8_validity.h index 4a8d75b3b46d5..1f251d0fec0a2 100644 --- a/third_party/utf8_range/utf8_validity.h +++ b/third_party/utf8_range/utf8_validity.h @@ -7,6 +7,8 @@ #ifndef THIRD_PARTY_UTF8_RANGE_UTF8_VALIDITY_H_ #define THIRD_PARTY_UTF8_RANGE_UTF8_VALIDITY_H_ +#include + #include "absl/strings/string_view.h" namespace utf8_range { diff --git a/upb/wire/internal/decode.h b/upb/wire/internal/decode.h index 23648cd072660..f36b2b7e97d37 100644 --- a/upb/wire/internal/decode.h +++ b/upb/wire/internal/decode.h @@ -56,26 +56,7 @@ extern const uint8_t upb_utf8_offsets[]; UPB_INLINE bool _upb_Decoder_VerifyUtf8Inline(const char* ptr, int len) { - const char* end = ptr + len; - - // Check 8 bytes at a time for any non-ASCII char. - while (end - ptr >= 8) { - uint64_t data; - memcpy(&data, ptr, 8); - if (data & 0x8080808080808080) goto non_ascii; - ptr += 8; - } - - // Check one byte at a time for non-ASCII. - while (ptr < end) { - if (*ptr & 0x80) goto non_ascii; - ptr++; - } - - return true; - -non_ascii: - return utf8_range2((const unsigned char*)ptr, end - ptr) == 0; + return utf8_range_IsValid(ptr, len); } const char* _upb_Decoder_CheckRequired(upb_Decoder* d, const char* ptr, From e02fbdadbf44177f932c41907324ffece54dbe98 Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Thu, 14 Dec 2023 17:35:34 +0000 Subject: [PATCH 016/255] Auto-generate files after cl/590961088 --- php/ext/google/protobuf/php-upb.h | 21 +-------------------- ruby/ext/google/protobuf_c/ruby-upb.h | 21 +-------------------- 2 files changed, 2 insertions(+), 40 deletions(-) diff --git a/php/ext/google/protobuf/php-upb.h b/php/ext/google/protobuf/php-upb.h index a485705d7c1b0..41900b70f5951 100644 --- a/php/ext/google/protobuf/php-upb.h +++ b/php/ext/google/protobuf/php-upb.h @@ -13497,26 +13497,7 @@ extern const uint8_t upb_utf8_offsets[]; UPB_INLINE bool _upb_Decoder_VerifyUtf8Inline(const char* ptr, int len) { - const char* end = ptr + len; - - // Check 8 bytes at a time for any non-ASCII char. - while (end - ptr >= 8) { - uint64_t data; - memcpy(&data, ptr, 8); - if (data & 0x8080808080808080) goto non_ascii; - ptr += 8; - } - - // Check one byte at a time for non-ASCII. - while (ptr < end) { - if (*ptr & 0x80) goto non_ascii; - ptr++; - } - - return true; - -non_ascii: - return utf8_range2((const unsigned char*)ptr, end - ptr) == 0; + return utf8_range_IsValid(ptr, len); } const char* _upb_Decoder_CheckRequired(upb_Decoder* d, const char* ptr, diff --git a/ruby/ext/google/protobuf_c/ruby-upb.h b/ruby/ext/google/protobuf_c/ruby-upb.h index d7540dac439a4..d92ecc0dfe68e 100755 --- a/ruby/ext/google/protobuf_c/ruby-upb.h +++ b/ruby/ext/google/protobuf_c/ruby-upb.h @@ -13316,26 +13316,7 @@ extern const uint8_t upb_utf8_offsets[]; UPB_INLINE bool _upb_Decoder_VerifyUtf8Inline(const char* ptr, int len) { - const char* end = ptr + len; - - // Check 8 bytes at a time for any non-ASCII char. - while (end - ptr >= 8) { - uint64_t data; - memcpy(&data, ptr, 8); - if (data & 0x8080808080808080) goto non_ascii; - ptr += 8; - } - - // Check one byte at a time for non-ASCII. - while (ptr < end) { - if (*ptr & 0x80) goto non_ascii; - ptr++; - } - - return true; - -non_ascii: - return utf8_range2((const unsigned char*)ptr, end - ptr) == 0; + return utf8_range_IsValid(ptr, len); } const char* _upb_Decoder_CheckRequired(upb_Decoder* d, const char* ptr, From c8f619501f2695e78d609766f186e8ad5f925e24 Mon Sep 17 00:00:00 2001 From: Adam Cozzette Date: Thu, 14 Dec 2023 11:14:26 -0800 Subject: [PATCH 017/255] Internal change PiperOrigin-RevId: 590998510 --- src/google/protobuf/descriptor.proto | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/google/protobuf/descriptor.proto b/src/google/protobuf/descriptor.proto index ebb92c660effb..1d9876e6660a3 100644 --- a/src/google/protobuf/descriptor.proto +++ b/src/google/protobuf/descriptor.proto @@ -576,10 +576,6 @@ message MessageOptions { reserved 4, 5, 6; - // NOTE: Do not set the option in .proto files. Always use the maps syntax - // instead. The option should only be implicitly set by the proto compiler - // parser. - // // Whether the message is an automatically generated map entry type for the // maps field. // @@ -597,6 +593,10 @@ message MessageOptions { // use a native map in the target language to hold the keys and values. // The reflection APIs in such implementations still need to work as // if the field is a repeated message field. + // + // NOTE: Do not set the option in .proto files. Always use the maps syntax + // instead. The option should only be implicitly set by the proto compiler + // parser. optional bool map_entry = 7; reserved 8; // javalite_serializable @@ -1104,7 +1104,7 @@ message SourceCodeInfo { // location. // // Each element is a field number or an index. They form a path from - // the root FileDescriptorProto to the place where the definition occurs. + // the root FileDescriptorProto to the place where the definition appears. // For example, this path: // [ 4, 3, 2, 7, 1 ] // refers to: From 9afd752ce6bbe937a4d9dd716323a8d8da1bc203 Mon Sep 17 00:00:00 2001 From: Mike Kruskal Date: Thu, 14 Dec 2023 11:15:29 -0800 Subject: [PATCH 018/255] Allow legacy_closed_enum feature on enum map fields. PiperOrigin-RevId: 590998931 --- src/google/protobuf/compiler/cpp/generator.cc | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/google/protobuf/compiler/cpp/generator.cc b/src/google/protobuf/compiler/cpp/generator.cc index ac0f9828d9dd0..bd9ea7d1fb71a 100644 --- a/src/google/protobuf/compiler/cpp/generator.cc +++ b/src/google/protobuf/compiler/cpp/generator.cc @@ -336,6 +336,16 @@ bool CppGenerator::Generate(const FileDescriptor* file, return true; } +static bool IsEnumMapType(const FieldDescriptor& field) { + if (!field.is_map()) return false; + for (int i = 0; i < field.message_type()->field_count(); ++i) { + if (field.message_type()->field(i)->type() == FieldDescriptor::TYPE_ENUM) { + return true; + } + } + return false; +} + absl::Status CppGenerator::ValidateFeatures(const FileDescriptor* file) const { absl::Status status = absl::OkStatus(); google::protobuf::internal::VisitDescriptors(*file, [&](const FieldDescriptor& field) { @@ -357,7 +367,8 @@ absl::Status CppGenerator::ValidateFeatures(const FileDescriptor* file) const { // a lot of these conditions. Note: we do still validate the // user-specified map field. if (unresolved_features.has_legacy_closed_enum() && - field.cpp_type() != FieldDescriptor::CPPTYPE_ENUM) { + field.cpp_type() != FieldDescriptor::CPPTYPE_ENUM && + !IsEnumMapType(field)) { status = absl::FailedPreconditionError( absl::StrCat("Field ", field.full_name(), " specifies the legacy_closed_enum feature but has " From d159913c0daec98dc1c162f36b947683865303f0 Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Thu, 14 Dec 2023 19:29:17 +0000 Subject: [PATCH 019/255] Auto-generate files after cl/590998510 --- csharp/src/Google.Protobuf.Test/testprotos.pb | Bin 363135 -> 363136 bytes .../Reflection/Descriptor.pb.cs | 10 +++++----- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/csharp/src/Google.Protobuf.Test/testprotos.pb b/csharp/src/Google.Protobuf.Test/testprotos.pb index 360fad3e660f7c0133f608bef3338272da34fea2..0360804e5a3c39ec5f713563b7659c4c93bf7c4e 100644 GIT binary patch delta 88 zcmexAMXX_}*oJkx8GAOb-`%Lo*tOa4rBU|w{~?T}Ow*G>80Ty+31>VUA=Jgr#l|Aa r%)rDT#PXDbMMvuAbk7Zp*I5$_3Q`l>RW>pLF%u9oZ&%sK5`7Z@6)+&K delta 87 zcmZpeD)xVh*oJkx8M`;H-`%Lo*tyy8rBU|un_-NzwVUA=Jsv#l|Aa q%)rDT#PXDbMMvt#bk7Zp*IDwDlS|uGH!=b-6A&|RSKY`GeG>rds~{`@ diff --git a/csharp/src/Google.Protobuf/Reflection/Descriptor.pb.cs b/csharp/src/Google.Protobuf/Reflection/Descriptor.pb.cs index 4a8def666e4cb..90542eecfa230 100644 --- a/csharp/src/Google.Protobuf/Reflection/Descriptor.pb.cs +++ b/csharp/src/Google.Protobuf/Reflection/Descriptor.pb.cs @@ -7426,10 +7426,6 @@ public void ClearDeprecated() { private bool mapEntry_; ///

- /// NOTE: Do not set the option in .proto files. Always use the maps syntax - /// instead. The option should only be implicitly set by the proto compiler - /// parser. - /// /// Whether the message is an automatically generated map entry type for the /// maps field. /// @@ -7447,6 +7443,10 @@ public void ClearDeprecated() { /// use a native map in the target language to hold the keys and values. /// The reflection APIs in such implementations still need to work as /// if the field is a repeated message field. + /// + /// NOTE: Do not set the option in .proto files. Always use the maps syntax + /// instead. The option should only be implicitly set by the proto compiler + /// parser. /// [global::System.Diagnostics.DebuggerNonUserCodeAttribute] [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] @@ -13139,7 +13139,7 @@ public Location Clone() { /// location. /// /// Each element is a field number or an index. They form a path from - /// the root FileDescriptorProto to the place where the definition occurs. + /// the root FileDescriptorProto to the place where the definition appears. /// For example, this path: /// [ 4, 3, 2, 7, 1 ] /// refers to: From 6ae76fd6ed6507ccab284ed16a430ae42fa64239 Mon Sep 17 00:00:00 2001 From: Alyssa Haroldsen Date: Thu, 14 Dec 2023 11:44:00 -0800 Subject: [PATCH 020/255] Rework Repeated and primitives with traits for use by out-of-crate items PiperOrigin-RevId: 591007327 --- rust/cpp.rs | 187 +++---- rust/internal.rs | 2 +- rust/primitive.rs | 169 +++---- rust/proxied.rs | 26 +- rust/repeated.rs | 473 +++++++++++++----- rust/shared.rs | 2 +- rust/upb.rs | 198 +++----- rust/vtable.rs | 152 +++--- .../rust/accessors/repeated_scalar.cc | 66 +-- .../rust/accessors/singular_scalar.cc | 17 +- src/google/protobuf/compiler/rust/message.cc | 17 +- 11 files changed, 736 insertions(+), 573 deletions(-) diff --git a/rust/cpp.rs b/rust/cpp.rs index 1d0fbe10c4c88..80f6e8e944eb4 100644 --- a/rust/cpp.rs +++ b/rust/cpp.rs @@ -9,6 +9,7 @@ use crate::ProtoStr; use crate::__internal::{Private, PtrAndLen, RawArena, RawMap, RawMessage, RawRepeatedField}; +use crate::{Mut, ProxiedInRepeated, Repeated, View}; use core::fmt::Debug; use paste::paste; use std::alloc::Layout; @@ -195,130 +196,85 @@ pub fn copy_bytes_in_arena_if_needed_by_runtime<'msg>( val } -/// RepeatedField impls delegate out to `extern "C"` functions exposed by -/// `cpp_api.h` and store either a RepeatedField* or a RepeatedPtrField* -/// depending on the type. +/// The raw type-erased pointer version of `RepeatedMut`. /// -/// Note: even though this type is `Copy`, it should only be copied by -/// protobuf internals that can maintain mutation invariants: -/// -/// - No concurrent mutation for any two fields in a message: this means -/// mutators cannot be `Send` but are `Sync`. -/// - If there are multiple accessible `Mut` to a single message at a time, they -/// must be different fields, and not be in the same oneof. As such, a `Mut` -/// cannot be `Clone` but *can* reborrow itself with `.as_mut()`, which -/// converts `&'b mut Mut<'a, T>` to `Mut<'b, T>`. -#[derive(Debug)] -pub struct RepeatedField<'msg, T: ?Sized> { - inner: RepeatedFieldInner<'msg>, - _phantom: PhantomData<&'msg mut T>, -} - -/// CPP runtime-specific arguments for initializing a RepeatedField. -/// See RepeatedField comment about mutation invariants for when this type can -/// be copied. +/// Contains a `proto2::RepeatedField*` or `proto2::RepeatedPtrField*`. #[derive(Clone, Copy, Debug)] -pub struct RepeatedFieldInner<'msg> { - pub raw: RawRepeatedField, - pub _phantom: PhantomData<&'msg ()>, +pub struct InnerRepeatedMut<'msg> { + pub(crate) raw: RawRepeatedField, + _phantom: PhantomData<&'msg ()>, } -impl<'msg, T: ?Sized> RepeatedField<'msg, T> { - pub fn from_inner(_private: Private, inner: RepeatedFieldInner<'msg>) -> Self { - RepeatedField { inner, _phantom: PhantomData } +impl<'msg> InnerRepeatedMut<'msg> { + #[doc(hidden)] + pub fn new(_private: Private, raw: RawRepeatedField) -> Self { + InnerRepeatedMut { raw, _phantom: PhantomData } } } -impl<'msg, T: ?Sized> Copy for RepeatedField<'msg, T> {} -impl<'msg, T: ?Sized> Clone for RepeatedField<'msg, T> { - fn clone(&self) -> RepeatedField<'msg, T> { - *self - } -} - -pub trait RepeatedScalarOps { - fn new_repeated_field() -> RawRepeatedField; - fn push(f: RawRepeatedField, v: Self); - fn len(f: RawRepeatedField) -> usize; - fn get(f: RawRepeatedField, i: usize) -> Self; - fn set(f: RawRepeatedField, i: usize, v: Self); - fn copy_from(src: RawRepeatedField, dst: RawRepeatedField); -} - -macro_rules! impl_repeated_scalar_ops { - ($($t: ty),*) => { - paste! { $( +macro_rules! impl_repeated_primitives { + (@impl $($t:ty => [ + $new_thunk:ident, + $add_thunk:ident, + $size_thunk:ident, + $get_thunk:ident, + $set_thunk:ident, + $copy_from_thunk:ident $(,)? + ]),* $(,)?) => { + $( + // TODO: Add clear, free extern "C" { - fn [< __pb_rust_RepeatedField_ $t _new >]() -> RawRepeatedField; - fn [< __pb_rust_RepeatedField_ $t _add >](f: RawRepeatedField, v: $t); - fn [< __pb_rust_RepeatedField_ $t _size >](f: RawRepeatedField) -> usize; - fn [< __pb_rust_RepeatedField_ $t _get >](f: RawRepeatedField, i: usize) -> $t; - fn [< __pb_rust_RepeatedField_ $t _set >](f: RawRepeatedField, i: usize, v: $t); - fn [< __pb_rust_RepeatedField_ $t _copy_from >](src: RawRepeatedField, dst: RawRepeatedField); + fn $new_thunk() -> RawRepeatedField; + fn $add_thunk(f: RawRepeatedField, v: $t); + fn $size_thunk(f: RawRepeatedField) -> usize; + fn $get_thunk(f: RawRepeatedField, i: usize) -> $t; + fn $set_thunk(f: RawRepeatedField, i: usize, v: $t); + fn $copy_from_thunk(src: RawRepeatedField, dst: RawRepeatedField); } - impl RepeatedScalarOps for $t { - fn new_repeated_field() -> RawRepeatedField { - unsafe { [< __pb_rust_RepeatedField_ $t _new >]() } + + unsafe impl ProxiedInRepeated for $t { + #[allow(dead_code)] + fn repeated_new(_: Private) -> Repeated<$t> { + unsafe { + Repeated::from_inner(InnerRepeatedMut::new(Private, $new_thunk())) + } } - fn push(f: RawRepeatedField, v: Self) { - unsafe { [< __pb_rust_RepeatedField_ $t _add >](f, v) } + fn repeated_len(f: View>) -> usize { + unsafe { $size_thunk(f.as_raw(Private)) } } - fn len(f: RawRepeatedField) -> usize { - unsafe { [< __pb_rust_RepeatedField_ $t _size >](f) } + fn repeated_push(mut f: Mut>, v: View<$t>) { + unsafe { $add_thunk(f.as_raw(Private), v) } } - fn get(f: RawRepeatedField, i: usize) -> Self { - unsafe { [< __pb_rust_RepeatedField_ $t _get >](f, i) } + unsafe fn repeated_get_unchecked(f: View>, i: usize) -> View<$t> { + unsafe { $get_thunk(f.as_raw(Private), i) } } - fn set(f: RawRepeatedField, i: usize, v: Self) { - unsafe { [< __pb_rust_RepeatedField_ $t _set >](f, i, v) } + unsafe fn repeated_set_unchecked(mut f: Mut>, i: usize, v: View<$t>) { + unsafe { $set_thunk(f.as_raw(Private), i, v) } } - fn copy_from(src: RawRepeatedField, dst: RawRepeatedField) { - unsafe { [< __pb_rust_RepeatedField_ $t _copy_from >](src, dst) } + fn repeated_copy_from(src: View>, mut dest: Mut>) { + unsafe { $copy_from_thunk(src.as_raw(Private), dest.as_raw(Private)) } } } - )* } + )* }; -} - -impl_repeated_scalar_ops!(i32, u32, i64, u64, f32, f64, bool); - -impl<'msg, T: RepeatedScalarOps> RepeatedField<'msg, T> { - #[allow(clippy::new_without_default, dead_code)] - /// new() is not currently used in our normal pathways, it is only used - /// for testing. Existing `RepeatedField<>`s are owned by, and retrieved - /// from, the containing `Message`. - pub fn new() -> Self { - Self::from_inner( - Private, - RepeatedFieldInner::<'msg> { raw: T::new_repeated_field(), _phantom: PhantomData }, - ) - } - pub fn push(&mut self, val: T) { - T::push(self.inner.raw, val) - } - pub fn len(&self) -> usize { - T::len(self.inner.raw) - } - pub fn is_empty(&self) -> bool { - self.len() == 0 - } - pub fn get(&self, index: usize) -> Option { - if index >= self.len() { - return None; + ($($t:ty),* $(,)?) => { + paste!{ + impl_repeated_primitives!(@impl $( + $t => [ + [< __pb_rust_RepeatedField_ $t _new >], + [< __pb_rust_RepeatedField_ $t _add >], + [< __pb_rust_RepeatedField_ $t _size >], + [< __pb_rust_RepeatedField_ $t _get >], + [< __pb_rust_RepeatedField_ $t _set >], + [< __pb_rust_RepeatedField_ $t _copy_from >], + ], + )*); } - Some(T::get(self.inner.raw, index)) - } - pub fn set(&mut self, index: usize, val: T) { - if index >= self.len() { - return; - } - T::set(self.inner.raw, index, val) - } - pub fn copy_from(&mut self, src: &RepeatedField<'_, T>) { - T::copy_from(src.inner.raw, self.inner.raw) - } + }; } +impl_repeated_primitives!(i32, u32, i64, u64, f32, f64, bool); + #[derive(Debug)] pub struct MapInner<'msg, K: ?Sized, V: ?Sized> { pub raw: RawMap, @@ -514,29 +470,6 @@ mod tests { assert_that!(&*serialized_data, eq(b"Hello world")); } - #[test] - fn repeated_field() { - let mut r = RepeatedField::::new(); - assert_that!(r.len(), eq(0)); - r.push(32); - assert_that!(r.get(0), eq(Some(32))); - - let mut r = RepeatedField::::new(); - assert_that!(r.len(), eq(0)); - r.push(32); - assert_that!(r.get(0), eq(Some(32))); - - let mut r = RepeatedField::::new(); - assert_that!(r.len(), eq(0)); - r.push(0.1234f64); - assert_that!(r.get(0), eq(Some(0.1234))); - - let mut r = RepeatedField::::new(); - assert_that!(r.len(), eq(0)); - r.push(true); - assert_that!(r.get(0), eq(Some(true))); - } - #[test] fn i32_i32_map() { let mut map: MapInner<'_, i32, i32> = Default::default(); diff --git a/rust/internal.rs b/rust/internal.rs index be9ddb2203625..2b7676b2d3fca 100644 --- a/rust/internal.rs +++ b/rust/internal.rs @@ -11,7 +11,7 @@ pub use crate::vtable::{ new_vtable_field_entry, BytesMutVTable, BytesOptionalMutVTable, PrimitiveOptionalMutVTable, - PrimitiveVTable, RawVTableMutator, + PrimitiveVTable, PrimitiveWithRawVTable, RawVTableMutator, }; use std::ptr::NonNull; use std::slice; diff --git a/rust/primitive.rs b/rust/primitive.rs index bf4d63268b458..539ddf293f19e 100644 --- a/rust/primitive.rs +++ b/rust/primitive.rs @@ -5,105 +5,109 @@ // license that can be found in the LICENSE file or at // https://developers.google.com/open-source/licenses/bsd +use std::fmt::Debug; + use crate::__internal::Private; use crate::__runtime::InnerPrimitiveMut; -use crate::vtable::{ - PrimitiveOptionalMutVTable, PrimitiveVTable, ProxiedWithRawOptionalVTable, - ProxiedWithRawVTable, RawVTableOptionalMutatorData, -}; +use crate::vtable::{PrimitiveWithRawVTable, ProxiedWithRawVTable, RawVTableOptionalMutatorData}; use crate::{Mut, MutProxy, Proxied, ProxiedWithPresence, SettableValue, View, ViewProxy}; -#[derive(Debug)] +/// A mutator for a primitive (numeric or enum) value of `T`. +/// +/// This type is `protobuf::Mut<'msg, T>`. pub struct PrimitiveMut<'msg, T: ProxiedWithRawVTable> { inner: InnerPrimitiveMut<'msg, T>, } +impl<'msg, T: ProxiedWithRawVTable> Debug for PrimitiveMut<'msg, T> { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("PrimitiveMut").field("inner", &self.inner).finish() + } +} + impl<'msg, T: ProxiedWithRawVTable> PrimitiveMut<'msg, T> { + /// # Safety + /// `inner` must be valid and non-aliased for `T` for `'msg` #[doc(hidden)] - pub fn from_inner(_private: Private, inner: InnerPrimitiveMut<'msg, T>) -> Self { + pub unsafe fn from_inner(_private: Private, inner: InnerPrimitiveMut<'msg, T>) -> Self { Self { inner } } } unsafe impl<'msg, T: ProxiedWithRawVTable> Sync for PrimitiveMut<'msg, T> {} +impl<'msg, T> PrimitiveMut<'msg, T> +where + T: PrimitiveWithRawVTable, +{ + pub fn get(&self) -> View<'_, T> { + T::make_view(Private, self.inner) + } + + pub fn set(&mut self, val: impl SettableValue) { + MutProxy::set(self, val) + } +} + +impl<'msg, T> ViewProxy<'msg> for PrimitiveMut<'msg, T> +where + T: PrimitiveWithRawVTable, +{ + type Proxied = T; + + fn as_view(&self) -> View<'_, Self::Proxied> { + self.get() + } + + fn into_view<'shorter>(self) -> View<'shorter, Self::Proxied> { + self.get() + } +} + +impl<'msg, T> MutProxy<'msg> for PrimitiveMut<'msg, T> +where + T: PrimitiveWithRawVTable, +{ + fn as_mut(&mut self) -> Mut<'_, Self::Proxied> { + PrimitiveMut { inner: self.inner } + } + + fn into_mut<'shorter>(self) -> Mut<'shorter, Self::Proxied> + where + 'msg: 'shorter, + { + self + } +} + macro_rules! impl_singular_primitives { ($($t:ty),*) => { $( - impl Proxied for $t { - type View<'msg> = $t; - type Mut<'msg> = PrimitiveMut<'msg, $t>; - } - - impl<'msg> ViewProxy<'msg> for $t { - type Proxied = $t; - - fn as_view(&self) -> View<'_, Self::Proxied> { - *self - } - - fn into_view<'shorter>(self) -> View<'shorter, Self::Proxied> { - self - } - } - - impl<'msg> PrimitiveMut<'msg, $t> { - pub fn get(&self) -> View<'_, $t> { - self.inner.get() - } - - pub fn set(&mut self, val: impl SettableValue<$t>) { - val.set_on(Private, self.as_mut()); - } - } - - impl<'msg> ViewProxy<'msg> for PrimitiveMut<'msg, $t> { - type Proxied = $t; - - fn as_view(&self) -> View<'_, Self::Proxied> { - self.get() - } - - fn into_view<'shorter>(self) -> View<'shorter, Self::Proxied> { - self.get() - } - } - - impl<'msg> MutProxy<'msg> for PrimitiveMut<'msg, $t> { - fn as_mut(&mut self) -> Mut<'_, Self::Proxied> { - PrimitiveMut { inner: self.inner } - } - - fn into_mut<'shorter>(self) -> Mut<'shorter, Self::Proxied> - where 'msg: 'shorter, - { - self - } - } - - impl SettableValue<$t> for $t { - fn set_on<'msg>(self, _private: Private, mutator: Mut<'msg, $t>) where $t: 'msg { - // SAFETY: the raw mutator is valid for `'msg` as enforced by `Mut` - unsafe { mutator.inner.set(self) } - } - } - - impl ProxiedWithRawVTable for $t { - type VTable = PrimitiveVTable<$t>; - - fn make_view( - _private: Private, - mut_inner: InnerPrimitiveMut<'_, Self> - ) -> View<'_, Self> { - mut_inner.get() + impl Proxied for $t { + type View<'msg> = $t; + type Mut<'msg> = PrimitiveMut<'msg, $t>; + } + + impl<'msg> ViewProxy<'msg> for $t { + type Proxied = $t; + + fn as_view(&self) -> View<'_, Self::Proxied> { + *self } - fn make_mut(_private: Private, inner: InnerPrimitiveMut<'_, Self>) -> Mut<'_, Self> { - PrimitiveMut::from_inner(Private, inner) + fn into_view<'shorter>(self) -> View<'shorter, Self::Proxied> { + self } - } + } - impl ProxiedWithPresence for $t { + impl SettableValue<$t> for $t { + fn set_on<'msg>(self, _private: Private, mutator: Mut<'msg, $t>) where $t: 'msg { + // SAFETY: the raw mutator is valid for `'msg` as enforced by `Mut` + unsafe { mutator.inner.set(self) } + } + } + + impl ProxiedWithPresence for $t { type PresentMutData<'msg> = RawVTableOptionalMutatorData<'msg, $t>; type AbsentMutData<'msg> = RawVTableOptionalMutatorData<'msg, $t>; @@ -118,18 +122,11 @@ macro_rules! impl_singular_primitives { ) -> Self::PresentMutData<'_> { absent_mutator.set_absent_to_default() } - } + } - impl ProxiedWithRawOptionalVTable for $t { - type OptionalVTable = PrimitiveOptionalMutVTable<$t>; + impl PrimitiveWithRawVTable for $t {} - fn upcast_vtable( - _private: Private, - optional_vtable: &'static Self::OptionalVTable, - ) -> &'static Self::VTable { - &optional_vtable.base - } - } + // ProxiedInRepeated is implemented in {cpp,upb}.rs )* } } diff --git a/rust/proxied.rs b/rust/proxied.rs index 44bb3e18a015e..896aba6fe6b79 100644 --- a/rust/proxied.rs +++ b/rust/proxied.rs @@ -44,7 +44,9 @@ //! implemented the concept of "proxy" types. Proxy types are a reference-like //! indirection between the user and the internal memory representation. +use crate::RepeatedMut; use crate::__internal::Private; +use crate::repeated::ProxiedInRepeated; use std::fmt::Debug; use std::marker::{Send, Sync}; @@ -205,6 +207,7 @@ pub trait MutProxy<'msg>: ViewProxy<'msg> { 'msg: 'shorter; } +// TODO: move this to `optional.rs` as it's only used for optionals /// `Proxied` types that can be optionally set or unset. /// /// All scalar and message types implement `ProxiedWithPresence`, while repeated @@ -233,14 +236,14 @@ pub trait SettableValue: Sized where T: Proxied + ?Sized, { - /// Consumes `self` to set the given mutator to its value. + /// Consumes `self` to set the given mutator to the value of `self`. #[doc(hidden)] fn set_on<'msg>(self, _private: Private, mutator: Mut<'msg, T>) where T: 'msg; /// Consumes `self` and `absent_mutator` to set the given empty field to - /// a value. + /// the value of `self`. #[doc(hidden)] fn set_on_absent( self, @@ -256,7 +259,7 @@ where } /// Consumes `self` and `present_mutator` to set the given present field - /// to a value. + /// to the value of `self`. #[doc(hidden)] fn set_on_present(self, _private: Private, mut present_mutator: T::PresentMutData<'_>) where @@ -264,6 +267,23 @@ where { self.set_on(Private, present_mutator.as_mut()) } + + /// Consumes `self` and `repeated_mutator` to set the value at the + /// given index to the value of `self`. + /// + /// # Safety + /// `index` must be less than `repeated_mutator.len()` + #[doc(hidden)] + unsafe fn set_on_repeated_unchecked( + self, + _private: Private, + mut _repeated_mutator: RepeatedMut, + _index: usize, + ) where + T: ProxiedInRepeated, + { + unimplemented!() + } } #[cfg(test)] diff --git a/rust/repeated.rs b/rust/repeated.rs index af0f513408082..a5b452229a951 100644 --- a/rust/repeated.rs +++ b/rust/repeated.rs @@ -5,190 +5,397 @@ // license that can be found in the LICENSE file or at // https://developers.google.com/open-source/licenses/bsd +use std::fmt::{self, Debug}; +use std::iter; /// Repeated scalar fields are implemented around the runtime-specific /// `RepeatedField` struct. `RepeatedField` stores an opaque pointer to the /// runtime-specific representation of a repeated scalar (`upb_Array*` on upb, /// and `RepeatedField*` on cpp). use std::marker::PhantomData; +use std::ops::Deref; use crate::{ Mut, MutProxy, Proxied, SettableValue, View, ViewProxy, __internal::{Private, RawRepeatedField}, - __runtime::{RepeatedField, RepeatedFieldInner}, - vtable::ProxiedWithRawVTable, + __runtime::InnerRepeatedMut, }; -#[derive(Clone, Copy)] -pub struct RepeatedFieldRef<'msg> { - pub repeated_field: RawRepeatedField, - pub _phantom: PhantomData<&'msg mut ()>, -} - -unsafe impl<'msg> Send for RepeatedFieldRef<'msg> {} -unsafe impl<'msg> Sync for RepeatedFieldRef<'msg> {} - -#[derive(Clone, Copy)] +/// Views the elements in a `repeated` field of `T`. #[repr(transparent)] pub struct RepeatedView<'msg, T: ?Sized> { - inner: RepeatedField<'msg, T>, + // This does not need to carry an arena in upb, so it can be just the raw repeated field + raw: RawRepeatedField, + _phantom: PhantomData<&'msg T>, } -unsafe impl<'msg, T: ProxiedWithRawVTable> Sync for RepeatedView<'msg, T> {} -unsafe impl<'msg, T: ProxiedWithRawVTable> Send for RepeatedView<'msg, T> {} - -impl<'msg, T: ?Sized> RepeatedView<'msg, T> { - pub fn from_inner(_private: Private, inner: RepeatedFieldInner<'msg>) -> Self { - Self { inner: RepeatedField::<'msg>::from_inner(_private, inner) } +impl<'msg, T: ?Sized> Copy for RepeatedView<'msg, T> {} +impl<'msg, T: ?Sized> Clone for RepeatedView<'msg, T> { + fn clone(&self) -> Self { + *self } } -pub struct RepeatedFieldIter<'msg, T> { - inner: RepeatedField<'msg, T>, - current_index: usize, -} +unsafe impl<'msg, T: ?Sized> Sync for RepeatedView<'msg, T> {} +unsafe impl<'msg, T: ?Sized> Send for RepeatedView<'msg, T> {} -impl<'msg, T> std::fmt::Debug for RepeatedView<'msg, T> { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - f.debug_tuple("RepeatedView").finish() +impl<'msg, T: ?Sized> Debug for RepeatedView<'msg, T> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_struct("RepeatedView").field("raw", &self.raw).finish() } } +/// Mutates the elements in a `repeated` field of `T`. #[repr(transparent)] -#[derive(Debug)] pub struct RepeatedMut<'msg, T: ?Sized> { - inner: RepeatedField<'msg, T>, + pub(crate) inner: InnerRepeatedMut<'msg>, + _phantom: PhantomData<&'msg mut T>, } -unsafe impl<'msg, T: ProxiedWithRawVTable> Sync for RepeatedMut<'msg, T> {} +unsafe impl<'msg, T: ?Sized> Sync for RepeatedMut<'msg, T> {} -impl<'msg, T: ?Sized> RepeatedMut<'msg, T> { - pub fn from_inner(_private: Private, inner: RepeatedFieldInner<'msg>) -> Self { - Self { inner: RepeatedField::from_inner(_private, inner) } - } - pub fn as_mut(&self) -> RepeatedMut<'_, T> { - Self { inner: self.inner } - } -} - -impl<'msg, T> std::ops::Deref for RepeatedMut<'msg, T> { +impl<'msg, T: ?Sized> Deref for RepeatedMut<'msg, T> { type Target = RepeatedView<'msg, T>; fn deref(&self) -> &Self::Target { // SAFETY: // - `Repeated{View,Mut}<'msg, T>` are both `#[repr(transparent)]` over // `RepeatedField<'msg, T>`. + // - `Repeated{View,Mut}<'msg, T>` are both `#[repr(transparent)]` over + // `RepeatedField<'msg, T>`. // - `RepeatedField` is a type alias for `NonNull`. unsafe { &*(self as *const Self as *const RepeatedView<'msg, T>) } } } -pub struct Repeated(PhantomData); +impl<'msg, T: ?Sized> Debug for RepeatedMut<'msg, T> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_struct("RepeatedMut").field("raw", &self.raw).finish() + } +} -macro_rules! impl_repeated_primitives { - ($($t:ty),*) => { - $( - impl Proxied for Repeated<$t> { - type View<'msg> = RepeatedView<'msg, $t>; - type Mut<'msg> = RepeatedMut<'msg, $t>; - } +impl<'msg, T> RepeatedView<'msg, T> +where + T: ProxiedInRepeated + ?Sized + 'msg, +{ + #[doc(hidden)] + pub fn as_raw(&self, _private: Private) -> RawRepeatedField { + self.raw + } - impl<'msg> ViewProxy<'msg> for RepeatedView<'msg, $t> { - type Proxied = Repeated<$t>; + /// # Safety + /// - `inner` must be valid to read from for `'msg` + #[doc(hidden)] + pub unsafe fn from_raw(_private: Private, raw: RawRepeatedField) -> Self { + Self { raw, _phantom: PhantomData } + } + + pub fn len(&self) -> usize { + T::repeated_len(*self) + } + pub fn is_empty(&self) -> bool { + self.len() == 0 + } + pub fn get(self, index: usize) -> Option> { + if index >= self.len() { + return None; + } + // SAFETY: `index` has been checked to be in-bounds + Some(unsafe { T::repeated_get_unchecked(self, index) }) + } + pub fn iter(self) -> RepeatedIter<'msg, T> { + self.into_iter() + } +} - fn as_view(&self) -> View<'_, Self::Proxied> { - *self - } +impl<'msg, T> RepeatedMut<'msg, T> +where + T: ProxiedInRepeated + ?Sized + 'msg, +{ + // TODO: Add clear, free - fn into_view<'shorter>(self) -> View<'shorter, Self::Proxied> - where 'msg: 'shorter, - { - RepeatedView { inner: self.inner } - } - } + /// # Safety + /// - `inner` must be valid to read and write from for `'msg` + /// - There must be no aliasing references or mutations on the same + /// underlying object. + #[doc(hidden)] + pub unsafe fn from_inner(_private: Private, inner: InnerRepeatedMut<'msg>) -> Self { + Self { inner, _phantom: PhantomData } + } - impl<'msg> ViewProxy<'msg> for RepeatedMut<'msg, $t> { - type Proxied = Repeated<$t>; + #[doc(hidden)] + pub fn as_raw(&mut self, _private: Private) -> RawRepeatedField { + self.inner.raw + } - fn as_view(&self) -> View<'_, Self::Proxied> { - **self - } + /// Appends `val` to the end of the repeated field. + pub fn push(&mut self, val: View) { + T::repeated_push(self.as_mut(), val); + } - fn into_view<'shorter>(self) -> View<'shorter, Self::Proxied> - where 'msg: 'shorter, - { - *self.into_mut::<'shorter>() - } - } + /// Sets the value at `index` to the value `val`. + /// + /// # Panics + /// Panics if `index >= len` + pub fn set(&mut self, index: usize, val: View) { + let len = self.len(); + if index >= len { + panic!("index {index} >= repeated len {len}"); + } + // SAFETY: `index` has been checked to be in-bounds. + unsafe { T::repeated_set_unchecked(self.as_mut(), index, val) } + } - impl<'msg> MutProxy<'msg> for RepeatedMut<'msg, $t> { - fn as_mut(&mut self) -> Mut<'_, Self::Proxied> { - RepeatedMut { inner: self.inner } - } + /// Returns the value at `index`. + // This is defined as an inherent function to prevent `MutProxy::get` from being + // preferred over `RepeatedView::get`. The former gets priority as it does + // not require a deref. + pub fn get(&self, index: usize) -> Option> { + self.as_view().get(index) + } - fn into_mut<'shorter>(self) -> Mut<'shorter, Self::Proxied> - where 'msg: 'shorter, - { - RepeatedMut { inner: self.inner } - } - } + /// Copies from the `src` repeated field into this one. + /// + /// Also provided by [`MutProxy::set`]. + pub fn copy_from(&mut self, src: RepeatedView<'_, T>) { + T::repeated_copy_from(src, self.as_mut()) + } +} - impl <'msg> SettableValue> for RepeatedView<'msg, $t> { - fn set_on<'b> (self, _private: Private, mut mutator: Mut<'b, Repeated<$t>>) - where - Repeated<$t>: 'b { - mutator.copy_from(self); - } - } +/// Types that can appear in a `Repeated`. +/// +/// This trait is implemented by generated code to communicate how the proxied +/// type can be manipulated for a repeated field. +/// +/// Scalars and messages implement `ProxiedInRepeated`. +/// +/// # Safety +/// - It must be sound to call `*_unchecked*(x)` with an `index` less than +/// `repeated_len(x)`. +pub unsafe trait ProxiedInRepeated: Proxied { + // TODO: Add clear, free + /// Constructs a new owned `Repeated` field. + #[doc(hidden)] + fn repeated_new(_private: Private) -> Repeated { + unimplemented!("not required") + } - impl<'msg> RepeatedView<'msg, $t> { - pub fn len(&self) -> usize { - self.inner.len() - } - pub fn is_empty(&self) -> bool { - self.len() == 0 - } - pub fn get(&self, index: usize) -> Option<$t> { - self.inner.get(index) - } - pub fn iter(&self) -> RepeatedFieldIter<'_, $t> { - (*self).into_iter() - } - } + /// Gets the length of the repeated field. + fn repeated_len(repeated: View>) -> usize; - impl<'msg> RepeatedMut<'msg, $t> { - pub fn push(&mut self, val: $t) { - self.inner.push(val) - } - pub fn set(&mut self, index: usize, val: $t) { - self.inner.set(index, val) - } - pub fn iter(&self) -> RepeatedFieldIter<'_, $t> { - self.as_view().into_iter() - } - pub fn copy_from(&mut self, src: RepeatedView<'_, $t>) { - self.inner.copy_from(&src.inner); - } - } + /// Appends a new element to the end of the repeated field. + fn repeated_push(repeated: Mut>, val: View); - impl<'msg> std::iter::Iterator for RepeatedFieldIter<'msg, $t> { - type Item = $t; - fn next(&mut self) -> Option { - let val = self.inner.get(self.current_index); - if val.is_some() { - self.current_index += 1; - } - val - } - } + /// # Safety + /// `index` must be less than `Self::repeated_len(repeated)` + unsafe fn repeated_get_unchecked(repeated: View>, index: usize) -> View; - impl<'msg> std::iter::IntoIterator for RepeatedView<'msg, $t> { - type Item = $t; - type IntoIter = RepeatedFieldIter<'msg, $t>; - fn into_iter(self) -> Self::IntoIter { - RepeatedFieldIter { inner: self.inner, current_index: 0 } - } - } - )* + /// # Safety + /// `index` must be less than `Self::repeated_len(repeated)` + unsafe fn repeated_set_unchecked(repeated: Mut>, index: usize, val: View); + + /// Copies the values in the `src` repeated field into `dest`. + fn repeated_copy_from(src: View>, dest: Mut>); +} + +/// An iterator over the values inside of a [`View>`](RepeatedView). +pub struct RepeatedIter<'msg, T: ?Sized> { + view: RepeatedView<'msg, T>, + current_index: usize, +} + +impl<'msg, T: ?Sized> Debug for RepeatedIter<'msg, T> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_struct("RepeatedIter") + .field("view", &self.view) + .field("current_index", &self.current_index) + .finish() } } -impl_repeated_primitives!(i32, u32, bool, f32, f64, i64, u64); +/// An iterator over the mutators inside of a [`Mut>`](RepeatedMut). +pub struct RepeatedIterMut<'msg, T: ?Sized> { + mutator: RepeatedMut<'msg, T>, + current_index: usize, +} + +impl<'msg, T: ?Sized> Debug for RepeatedIterMut<'msg, T> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_struct("RepeatedIterMut") + .field("mutator", &self.mutator) + .field("current_index", &self.current_index) + .finish() + } +} + +/// A `repeated` field of `T`, used as the owned target for `Proxied`. +/// +/// Users will generally write [`View>`](RepeatedView) or +/// [`Mut>`](RepeatedMut) to access the repeated elements +pub struct Repeated { + inner: InnerRepeatedMut<'static>, + _phantom: PhantomData, +} + +#[allow(dead_code)] +impl Repeated { + pub(crate) fn new() -> Self { + T::repeated_new(Private) + } + + pub(crate) unsafe fn from_inner(inner: InnerRepeatedMut<'static>) -> Self { + Self { inner, _phantom: PhantomData } + } + + pub(crate) fn inner(&mut self) -> InnerRepeatedMut<'static> { + self.inner + } + + pub(crate) fn as_mut(&mut self) -> RepeatedMut<'_, T> { + RepeatedMut { inner: self.inner, _phantom: PhantomData } + } +} + +// SAFETY: `Repeated` does not allow for shared mutability. +unsafe impl Sync for Repeated {} + +impl Proxied for Repeated +where + T: ProxiedInRepeated + ?Sized, +{ + type View<'msg> = RepeatedView<'msg, T> where Repeated: 'msg; + type Mut<'msg> = RepeatedMut<'msg, T> where Repeated: 'msg; +} + +impl<'msg, T> ViewProxy<'msg> for RepeatedView<'msg, T> +where + T: ProxiedInRepeated + ?Sized + 'msg, +{ + type Proxied = Repeated; + + fn as_view(&self) -> View<'_, Self::Proxied> { + *self + } + + fn into_view<'shorter>(self) -> View<'shorter, Self::Proxied> + where + 'msg: 'shorter, + { + RepeatedView { raw: self.raw, _phantom: PhantomData } + } +} + +impl<'msg, T> ViewProxy<'msg> for RepeatedMut<'msg, T> +where + T: ProxiedInRepeated + ?Sized + 'msg, +{ + type Proxied = Repeated; + + fn as_view(&self) -> View<'_, Self::Proxied> { + **self + } + + fn into_view<'shorter>(self) -> View<'shorter, Self::Proxied> + where + 'msg: 'shorter, + { + *self.into_mut::<'shorter>() + } +} + +impl<'msg, T> MutProxy<'msg> for RepeatedMut<'msg, T> +where + T: ProxiedInRepeated + ?Sized + 'msg, +{ + fn as_mut(&mut self) -> Mut<'_, Self::Proxied> { + RepeatedMut { inner: self.inner, _phantom: PhantomData } + } + + fn into_mut<'shorter>(self) -> Mut<'shorter, Self::Proxied> + where + 'msg: 'shorter, + { + RepeatedMut { inner: self.inner, _phantom: PhantomData } + } +} + +impl<'msg, T> SettableValue> for RepeatedView<'msg, T> +where + T: ProxiedInRepeated + ?Sized + 'msg, +{ + fn set_on<'b>(self, _private: Private, mutator: Mut<'b, Repeated>) + where + Repeated: 'b, + { + T::repeated_copy_from(self, mutator) + } +} + +// TODO: impl ExactSizeIterator +impl<'msg, T> iter::Iterator for RepeatedIter<'msg, T> +where + T: ProxiedInRepeated + ?Sized + 'msg, +{ + type Item = View<'msg, T>; + + fn next(&mut self) -> Option { + let val = self.view.get(self.current_index); + if val.is_some() { + self.current_index += 1; + } + val + } +} + +impl<'msg, T> iter::IntoIterator for RepeatedView<'msg, T> +where + T: ProxiedInRepeated + ?Sized + 'msg, +{ + type Item = View<'msg, T>; + type IntoIter = RepeatedIter<'msg, T>; + + fn into_iter(self) -> Self::IntoIter { + RepeatedIter { view: self, current_index: 0 } + } +} + +#[cfg(test)] +mod tests { + use super::*; + use googletest::prelude::*; + + #[test] + fn test_primitive_repeated() { + macro_rules! primitive_repeated_tests { + ($($t:ty => [$($vals:expr),* $(,)?]),* $(,)?) => { + $({ + // Constructs a new, owned, `Repeated`, only used for tests. + let mut r = Repeated::<$t>::new(); + let mut r = r.as_mut(); + assert_that!(r.len(), eq(0)); + assert!(r.iter().next().is_none(), "starts with empty iter"); + assert!(r.iter().next().is_none(), "starts with empty mut iter"); + assert!(r.is_empty(), "starts is_empty"); + + let mut expected_len = 0usize; + $( + let val: View<$t> = $vals; + r.push(val); + assert_that!(r.get(expected_len), eq(Some(val))); + expected_len += 1; + assert_that!(r.len(), eq(expected_len)); + + )* + assert_that!( + r.iter().collect::>(), elements_are![$(eq($vals)),*]); + r.set(0, <$t as Default>::default()); + assert_that!(r.get(0).expect("elem 0"), eq(<$t as Default>::default())); + })* + } + } + primitive_repeated_tests!( + u32 => [1,2,3], + i32 => [1,2], + f64 => [10.0, 0.1234f64], + bool => [false, true, true, false], + ); + } +} diff --git a/rust/shared.rs b/rust/shared.rs index 620d285061da2..21fd9d385202b 100644 --- a/rust/shared.rs +++ b/rust/shared.rs @@ -28,7 +28,7 @@ pub mod __public { pub use crate::proxied::{ Mut, MutProxy, Proxied, ProxiedWithPresence, SettableValue, View, ViewProxy, }; - pub use crate::repeated::{RepeatedFieldRef, RepeatedMut, RepeatedView}; + pub use crate::repeated::{ProxiedInRepeated, Repeated, RepeatedMut, RepeatedView}; pub use crate::string::{BytesMut, ProtoStr, ProtoStrMut}; } pub use __public::*; diff --git a/rust/upb.rs b/rust/upb.rs index f618406467158..406572a0b870f 100644 --- a/rust/upb.rs +++ b/rust/upb.rs @@ -9,18 +9,20 @@ use crate::ProtoStr; use crate::__internal::{Private, PtrAndLen, RawArena, RawMap, RawMessage, RawRepeatedField}; +use crate::{Mut, ProxiedInRepeated, Repeated, RepeatedMut, RepeatedView, View, ViewProxy}; use core::fmt::Debug; use paste::paste; use std::alloc; use std::alloc::Layout; use std::cell::UnsafeCell; +use std::ffi::c_int; use std::fmt; use std::marker::PhantomData; use std::mem::{size_of, MaybeUninit}; use std::ops::Deref; use std::ptr::{self, NonNull}; use std::slice; -use std::sync::Once; +use std::sync::{Once, OnceLock}; /// See `upb/port/def.inc`. const UPB_MALLOC_ALIGN: usize = 8; @@ -295,40 +297,28 @@ pub fn copy_bytes_in_arena_if_needed_by_runtime<'msg>( } } -/// RepeatedFieldInner contains a `upb_Array*` as well as a reference to an -/// `Arena`, most likely that of the containing `Message`. upb requires an Arena -/// to perform mutations on a repeated field. +/// The raw type-erased pointer version of `RepeatedMut`. +/// +/// Contains a `upb_Array*` as well as `RawArena`, most likely that of the +/// containing message. upb requires a `RawArena` to perform mutations on +/// a repeated field. +/// +/// An owned `Repeated` stores a `InnerRepeatedMut<'static>` and manages the +/// contained `RawArena`. #[derive(Clone, Copy, Debug)] -pub struct RepeatedFieldInner<'msg> { - pub raw: RawRepeatedField, - pub arena: &'msg Arena, -} - -#[derive(Debug)] -pub struct RepeatedField<'msg, T: ?Sized> { - inner: RepeatedFieldInner<'msg>, - _phantom: PhantomData<&'msg mut T>, +pub struct InnerRepeatedMut<'msg> { + pub(crate) raw: RawRepeatedField, + // Storing a `RawArena` instead of `&Arena` allows this to be used for + // both `RepeatedMut` and `Repeated`. + arena: RawArena, + _phantom: PhantomData<&'msg Arena>, } -// These use manual impls instead of derives to avoid unnecessary bounds on `T`. -// This problem is referred to as "perfect derive". -// https://smallcultfollowing.com/babysteps/blog/2022/04/12/implied-bounds-and-perfect-derive/ -impl<'msg, T: ?Sized> Copy for RepeatedField<'msg, T> {} -impl<'msg, T: ?Sized> Clone for RepeatedField<'msg, T> { - fn clone(&self) -> RepeatedField<'msg, T> { - *self - } -} - -impl<'msg, T: ?Sized> RepeatedField<'msg, T> { - pub fn len(&self) -> usize { - unsafe { upb_Array_Size(self.inner.raw) } - } - pub fn is_empty(&self) -> bool { - self.len() == 0 - } - pub fn from_inner(_private: Private, inner: RepeatedFieldInner<'msg>) -> Self { - Self { inner, _phantom: PhantomData } +impl<'msg> InnerRepeatedMut<'msg> { + #[doc(hidden)] + #[allow(clippy::needless_pass_by_ref_mut)] // Sound construction requires mutable access. + pub fn new(_private: Private, raw: RawRepeatedField, arena: &'msg Arena) -> Self { + InnerRepeatedMut { raw, arena: arena.raw(), _phantom: PhantomData } } } @@ -367,7 +357,6 @@ pub enum UpbCType { } extern "C" { - #[allow(dead_code)] fn upb_Array_New(a: RawArena, r#type: std::ffi::c_int) -> RawRepeatedField; fn upb_Array_Size(arr: RawRepeatedField) -> usize; fn upb_Array_Set(arr: RawRepeatedField, i: usize, val: upb_MessageValue); @@ -379,56 +368,53 @@ extern "C" { } macro_rules! impl_repeated_primitives { - ($(($rs_type:ty, $ufield:ident, $upb_tag:expr)),*) => { + ($(($t:ty, $ufield:ident, $upb_tag:expr)),* $(,)?) => { $( - impl<'msg> RepeatedField<'msg, $rs_type> { + // TODO: Add clear, free + unsafe impl ProxiedInRepeated for $t { #[allow(dead_code)] - fn new(arena: &'msg Arena) -> Self { - Self { - inner: RepeatedFieldInner { - raw: unsafe { upb_Array_New(arena.raw, $upb_tag as std::ffi::c_int) }, - arena, - }, - _phantom: PhantomData, + fn repeated_new(_: Private) -> Repeated<$t> { + let arena = Arena::new(); + let raw_arena = arena.raw(); + std::mem::forget(arena); + unsafe { + Repeated::from_inner(InnerRepeatedMut { + raw: upb_Array_New(raw_arena, $upb_tag as c_int), + arena: raw_arena, + _phantom: PhantomData, + }) } } - pub fn push(&mut self, val: $rs_type) { - unsafe { upb_Array_Append( - self.inner.raw, - upb_MessageValue { $ufield: val }, - self.inner.arena.raw(), - ) } + fn repeated_len(f: View>) -> usize { + unsafe { upb_Array_Size(f.as_raw(Private)) } } - pub fn get(&self, i: usize) -> Option<$rs_type> { - if i >= self.len() { - None - } else { - unsafe { Some(upb_Array_Get(self.inner.raw, i).$ufield) } + fn repeated_push(mut f: Mut>, v: View<$t>) { + unsafe { + upb_Array_Append( + f.as_raw(Private), + upb_MessageValue { $ufield: v }, + f.raw_arena(Private)) } } - pub fn set(&self, i: usize, val: $rs_type) { - if i >= self.len() { - return; - } - unsafe { upb_Array_Set( - self.inner.raw, - i, - upb_MessageValue { $ufield: val }, - ) } + unsafe fn repeated_get_unchecked(f: View>, i: usize) -> View<$t> { + unsafe { upb_Array_Get(f.as_raw(Private), i).$ufield } } - pub fn copy_from(&mut self, src: &RepeatedField<'_, $rs_type>) { + unsafe fn repeated_set_unchecked(mut f: Mut>, i: usize, v: View<$t>) { + unsafe { upb_Array_Set(f.as_raw(Private), i, upb_MessageValue { $ufield: v }) } + } + fn repeated_copy_from(src: View>, mut dest: Mut>) { // SAFETY: // - `upb_Array_Resize` is unsafe but assumed to be always sound to call. // - `copy_nonoverlapping` is unsafe but here we guarantee that both pointers // are valid, the pointers are `#[repr(u8)]`, and the size is correct. unsafe { - if (!upb_Array_Resize(self.inner.raw, src.len(), self.inner.arena.raw())) { + if (!upb_Array_Resize(dest.as_raw(Private), src.len(), dest.inner.arena)) { panic!("upb_Array_Resize failed."); } ptr::copy_nonoverlapping( - upb_Array_DataPtr(src.inner.raw).cast::(), - upb_Array_MutableDataPtr(self.inner.raw).cast::(), - size_of::<$rs_type>() * src.len()); + upb_Array_DataPtr(src.as_raw(Private)).cast::(), + upb_Array_MutableDataPtr(dest.as_raw(Private)).cast::(), + size_of::<$t>() * src.len()); } } } @@ -436,6 +422,14 @@ macro_rules! impl_repeated_primitives { } } +impl<'msg, T: ?Sized> RepeatedMut<'msg, T> { + // Returns a `RawArena` which is live for at least `'msg` + #[doc(hidden)] + pub fn raw_arena(&self, _private: Private) -> RawArena { + self.inner.arena + } +} + impl_repeated_primitives!( (bool, bool_val, UpbCType::Bool), (f32, float_val, UpbCType::Float), @@ -443,29 +437,28 @@ impl_repeated_primitives!( (i32, int32_val, UpbCType::Int32), (u32, uint32_val, UpbCType::UInt32), (i64, int64_val, UpbCType::Int64), - (u64, uint64_val, UpbCType::UInt64) + (u64, uint64_val, UpbCType::UInt64), ); -/// Returns a static thread-local empty RepeatedFieldInner for use in a -/// RepeatedView. -/// -/// # Safety -/// The returned array must never be mutated. -/// -/// TODO: Split RepeatedFieldInner into mut and const variants to -/// enforce safety. The returned array must never be mutated. -pub unsafe fn empty_array() -> RepeatedFieldInner<'static> { - // TODO: Consider creating empty array in C. - fn new_repeated_field_inner() -> RepeatedFieldInner<'static> { - let arena = Box::leak::<'static>(Box::new(Arena::new())); - // Provide `i32` as a placeholder type. - RepeatedField::<'static, i32>::new(arena).inner - } - thread_local! { - static REPEATED_FIELD: RepeatedFieldInner<'static> = new_repeated_field_inner(); - } +/// Returns a static empty RepeatedView. +pub fn empty_array() -> RepeatedView<'static, T> { + // TODO: Consider creating a static empty array in C. - REPEATED_FIELD.with(|inner| *inner) + // Use `i32` for a shared empty repeated for all repeated types on a thread. + static EMPTY_REPEATED_VIEW: OnceLock> = OnceLock::new(); + + // SAFETY: + // - Because the repeated is never mutated, the repeated type is unused and + // therefore valid for `T`. + // - The view is leaked for `'static`. + unsafe { + RepeatedView::from_raw( + Private, + EMPTY_REPEATED_VIEW + .get_or_init(|| Box::leak(Box::new(Repeated::new())).as_mut().into_view()) + .as_raw(Private), + ) + } } /// Returns a static thread-local empty MapInner for use in a @@ -722,37 +715,6 @@ mod tests { assert_that!(&*serialized_data, eq(b"Hello world")); } - #[test] - fn i32_array() { - let arena = Arena::new(); - let mut arr = RepeatedField::::new(&arena); - assert_that!(arr.len(), eq(0)); - arr.push(1); - assert_that!(arr.get(0), eq(Some(1))); - assert_that!(arr.len(), eq(1)); - arr.set(0, 3); - assert_that!(arr.get(0), eq(Some(3))); - for i in 0..2048 { - arr.push(i); - assert_that!(arr.get(arr.len() - 1), eq(Some(i))); - } - } - #[test] - fn u32_array() { - let mut arena = Arena::new(); - let mut arr = RepeatedField::::new(&mut arena); - assert_that!(arr.len(), eq(0)); - arr.push(1); - assert_that!(arr.get(0), eq(Some(1))); - assert_that!(arr.len(), eq(1)); - arr.set(0, 3); - assert_that!(arr.get(0), eq(Some(3))); - for i in 0..2048 { - arr.push(i); - assert_that!(arr.get(arr.len() - 1), eq(Some(i))); - } - } - #[test] fn i32_i32_map() { let mut arena = Arena::new(); diff --git a/rust/vtable.rs b/rust/vtable.rs index 2327e56b69986..f0128dbf937ed 100644 --- a/rust/vtable.rs +++ b/rust/vtable.rs @@ -6,10 +6,12 @@ // https://developers.google.com/open-source/licenses/bsd use crate::__internal::{Private, PtrAndLen, RawMessage}; -use crate::__runtime::{copy_bytes_in_arena_if_needed_by_runtime, MutatorMessageRef}; +use crate::__runtime::{ + copy_bytes_in_arena_if_needed_by_runtime, InnerPrimitiveMut, MutatorMessageRef, +}; use crate::{ - AbsentField, FieldEntry, Mut, MutProxy, Optional, PresentField, Proxied, ProxiedWithPresence, - View, ViewProxy, + AbsentField, FieldEntry, Mut, MutProxy, Optional, PresentField, PrimitiveMut, Proxied, + ProxiedWithPresence, View, ViewProxy, }; use std::fmt::{self, Debug}; @@ -291,32 +293,6 @@ impl PrimitiveOptionalMutVTable { } } -macro_rules! impl_raw_vtable_mutator_get_set { - ($($t:ty),*) => { - $( - impl RawVTableMutator<'_, $t> { - pub(crate) fn get(self) -> $t { - // SAFETY: - // - `msg_ref` is valid for the lifetime of `RawVTableMutator` as promised by the - // caller of `new`. - unsafe { (self.vtable.getter)(self.msg_ref.msg()) } - } - - /// # Safety - /// - `msg_ref` must be valid for the lifetime of `RawVTableMutator`. - pub(crate) unsafe fn set(self, val: $t) { - // SAFETY: - // - `msg_ref` is valid for the lifetime of `RawVTableMutator` as promised by the - // caller of `new`. - unsafe { (self.vtable.setter)(self.msg_ref.msg(), val) } - } - } - )* - } -} - -impl_raw_vtable_mutator_get_set!(bool, f32, f64, i32, i64, u32, u64); - /// A generic thunk vtable for mutating a present `bytes` or `string` field. #[doc(hidden)] #[derive(Debug)] @@ -421,35 +397,89 @@ impl<'msg> RawVTableOptionalMutatorData<'msg, [u8]> { } } -macro_rules! impl_raw_vtable_optional_mutator_data { - ($($t:ty),*) => { - $( - impl<'msg> RawVTableOptionalMutatorData<'msg, $t> { - pub(crate) fn set_absent_to_default(self) -> Self { - // SAFETY: - // - `msg_ref` is valid for the lifetime of `RawVTableOptionalMutatorData` as - // promised by the caller of `new`. - self.set(self.vtable.default) - } - - pub(crate) fn set(self, val: $t) -> Self { - // SAFETY: - // - `msg_ref` is valid for the lifetime of `RawVTableOptionalMutatorData` as - // promised by the caller of `new`. - unsafe { (self.vtable.base.setter)(self.msg_ref.msg(), val.into()) } - self - } - - pub(crate) fn clear(self) -> Self { - // SAFETY: - // - `msg_ref` is valid for the lifetime of `RawVTableOptionalMutatorData` as - // promised by the caller of `new`. - unsafe { (self.vtable.clearer)(self.msg_ref.msg()) } - self - } - } - )* - } -} - -impl_raw_vtable_optional_mutator_data!(bool, f32, f64, i32, i64, u32, u64); +/// Primitive types using a vtable for message access that are trivial to copy +/// and have a `'static` lifetime. +/// +/// Implementing this trait automatically implements `ProxiedWithRawVTable`, +/// `ProxiedWithRawOptionalVTable`, and get/set/clear methods on +/// `RawVTableMutator` and `RawVTableOptionalMutatorData` that use the vtable. +/// +/// It doesn't implement `Proxied`, `ViewProxy`, `SettableValue` or +/// `ProxiedWithPresence` for `Self` to avoid future conflicting blanket impls +/// on those traits. +pub trait PrimitiveWithRawVTable: + Copy + + Debug + + 'static + + ProxiedWithPresence + + for<'msg> Proxied = Self, Mut<'msg> = PrimitiveMut<'msg, Self>> +{ +} + +impl ProxiedWithRawVTable for T { + type VTable = PrimitiveVTable; + + fn make_view(_private: Private, mut_inner: InnerPrimitiveMut<'_, Self>) -> Self { + mut_inner.get() + } + + fn make_mut(_private: Private, inner: InnerPrimitiveMut<'_, Self>) -> PrimitiveMut<'_, Self> { + // SAFETY: `inner` is valid for the necessary lifetime and `T` as promised by + // the caller of `InnerPrimitiveMut::new`. + unsafe { PrimitiveMut::from_inner(Private, inner) } + } +} + +impl ProxiedWithRawOptionalVTable for T { + type OptionalVTable = PrimitiveOptionalMutVTable; + + fn upcast_vtable( + _private: Private, + optional_vtable: &'static Self::OptionalVTable, + ) -> &'static Self::VTable { + &optional_vtable.base + } +} + +impl RawVTableMutator<'_, T> { + pub(crate) fn get(self) -> T { + // SAFETY: + // - `msg_ref` is valid for the lifetime of `RawVTableMutator` as promised by + // the caller of `new`. + unsafe { (self.vtable.getter)(self.msg_ref.msg()) } + } + + /// # Safety + /// - `msg_ref` must be valid for the lifetime of `RawVTableMutator`. + pub(crate) unsafe fn set(self, val: T) { + // SAFETY: + // - `msg_ref` is valid for the lifetime of `RawVTableMutator` as promised by + // the caller of `new`. + unsafe { (self.vtable.setter)(self.msg_ref.msg(), val) } + } +} + +impl<'msg, T: PrimitiveWithRawVTable> RawVTableOptionalMutatorData<'msg, T> { + pub(crate) fn set_absent_to_default(self) -> Self { + // SAFETY: + // - `msg_ref` is valid for the lifetime of `RawVTableOptionalMutatorData` as + // promised by the caller of `new`. + self.set(self.vtable.default) + } + + pub(crate) fn set(self, val: T) -> Self { + // SAFETY: + // - `msg_ref` is valid for the lifetime of `RawVTableOptionalMutatorData` as + // promised by the caller of `new`. + unsafe { (self.vtable.base.setter)(self.msg_ref.msg(), val) } + self + } + + pub(crate) fn clear(self) -> Self { + // SAFETY: + // - `msg_ref` is valid for the lifetime of `RawVTableOptionalMutatorData` as + // promised by the caller of `new`. + unsafe { (self.vtable.clearer)(self.msg_ref.msg()) } + self + } +} diff --git a/src/google/protobuf/compiler/rust/accessors/repeated_scalar.cc b/src/google/protobuf/compiler/rust/accessors/repeated_scalar.cc index 8f0a7625b3a0e..72f1d790b81b2 100644 --- a/src/google/protobuf/compiler/rust/accessors/repeated_scalar.cc +++ b/src/google/protobuf/compiler/rust/accessors/repeated_scalar.cc @@ -27,27 +27,28 @@ void RepeatedScalar::InMsgImpl(Context field) const { if (field.is_upb()) { field.Emit({}, R"rs( pub fn r#$field$(&self) -> $pb$::RepeatedView<'_, $Scalar$> { - let inner = unsafe { + unsafe { $getter_thunk$( self.inner.msg, /* optional size pointer */ std::ptr::null(), ) } - .map_or_else(|| unsafe {$pbr$::empty_array()}, |raw| { - $pbr$::RepeatedFieldInner{ raw, arena: &self.inner.arena } - }); - $pb$::RepeatedView::from_inner($pbi$::Private, inner) + .map_or_else( + $pbr$::empty_array::<$Scalar$>, + |raw| unsafe { + $pb$::RepeatedView::from_raw($pbi$::Private, raw) + } + ) } )rs"); } else { field.Emit({}, R"rs( pub fn r#$field$(&self) -> $pb$::RepeatedView<'_, $Scalar$> { - $pb$::RepeatedView::from_inner( - $pbi$::Private, - $pbr$::RepeatedFieldInner{ - raw: unsafe { $getter_thunk$(self.inner.msg) }, - _phantom: std::marker::PhantomData, - }, - ) + unsafe { + $pb$::RepeatedView::from_raw( + $pbi$::Private, + unsafe { $getter_thunk$(self.inner.msg) }, + ) + } } )rs"); } @@ -58,29 +59,34 @@ void RepeatedScalar::InMsgImpl(Context field) const { if (field.is_upb()) { field.Emit({}, R"rs( pub fn r#$field$_mut(&mut self) -> $pb$::RepeatedMut<'_, $Scalar$> { - $pb$::RepeatedMut::from_inner( - $pbi$::Private, - $pbr$::RepeatedFieldInner{ - raw: unsafe { $getter_mut_thunk$( - self.inner.msg, - /* optional size pointer */ std::ptr::null(), - self.inner.arena.raw(), - ) }, - arena: &self.inner.arena, - }, - ) + unsafe { + $pb$::RepeatedMut::from_inner( + $pbi$::Private, + $pbr$::InnerRepeatedMut::new( + $pbi$::Private, + $getter_mut_thunk$( + self.inner.msg, + /* optional size pointer */ std::ptr::null(), + self.inner.arena.raw(), + ), + &self.inner.arena, + ), + ) + } } )rs"); } else { field.Emit({}, R"rs( pub fn r#$field$_mut(&mut self) -> $pb$::RepeatedMut<'_, $Scalar$> { - $pb$::RepeatedMut::from_inner( - $pbi$::Private, - $pbr$::RepeatedFieldInner{ - raw: unsafe { $getter_mut_thunk$(self.inner.msg)}, - _phantom: std::marker::PhantomData, - }, - ) + unsafe { + $pb$::RepeatedMut::from_inner( + $pbi$::Private, + $pbr$::InnerRepeatedMut::new( + $pbi$::Private, + $getter_mut_thunk$(self.inner.msg), + ), + ) + } } )rs"); } diff --git a/src/google/protobuf/compiler/rust/accessors/singular_scalar.cc b/src/google/protobuf/compiler/rust/accessors/singular_scalar.cc index d3d65dcada77f..db28e7e1ec4c1 100644 --- a/src/google/protobuf/compiler/rust/accessors/singular_scalar.cc +++ b/src/google/protobuf/compiler/rust/accessors/singular_scalar.cc @@ -85,18 +85,23 @@ void SingularScalar::InMsgImpl(Context field) const { $setter_thunk$, ); - $pb$::PrimitiveMut::from_inner( - $pbi$::Private, - unsafe { + // SAFETY: + // - The message is valid for the output lifetime. + // - The vtable is valid for the field. + // - There is no way to mutate the element for the output + // lifetime except through this mutator. + unsafe { + $pb$::PrimitiveMut::from_inner( + $pbi$::Private, $pbi$::RawVTableMutator::new( $pbi$::Private, $pbr$::MutatorMessageRef::new( $pbi$::Private, &mut self.inner ), &VTABLE, - ) - }, - ) + ), + ) + } } )rs"); } diff --git a/src/google/protobuf/compiler/rust/message.cc b/src/google/protobuf/compiler/rust/message.cc index e55def55f672a..d9f52082e2623 100644 --- a/src/google/protobuf/compiler/rust/message.cc +++ b/src/google/protobuf/compiler/rust/message.cc @@ -316,13 +316,16 @@ void GetterForViewOrMut(Context field, bool is_mut) { $pbi$::Private, $getter_thunk$, $setter_thunk$); - $pb$::PrimitiveMut::from_inner( - $pbi$::Private, - unsafe { - $pbi$::RawVTableMutator::new($pbi$::Private, - self.inner, - &VTABLE) - }) + unsafe { + $pb$::PrimitiveMut::from_inner( + $pbi$::Private, + $pbi$::RawVTableMutator::new( + $pbi$::Private, + self.inner, + &VTABLE + ), + ) + } } )rs"); } From b976dd8585c813820c229e61beb7435057840b8e Mon Sep 17 00:00:00 2001 From: Hong Shin Date: Thu, 14 Dec 2023 13:41:44 -0800 Subject: [PATCH 021/255] refactor: collapse submsg accessors for bytes and strings Now that we've finished with our expansionary phase, it's time for some contraction with the `big crunch`! PiperOrigin-RevId: 591039509 --- src/google/protobuf/compiler/rust/message.cc | 44 ++------------------ 1 file changed, 3 insertions(+), 41 deletions(-) diff --git a/src/google/protobuf/compiler/rust/message.cc b/src/google/protobuf/compiler/rust/message.cc index d9f52082e2623..256cf81ffd5d9 100644 --- a/src/google/protobuf/compiler/rust/message.cc +++ b/src/google/protobuf/compiler/rust/message.cc @@ -217,7 +217,8 @@ void GetterForViewOrMut(Context field, bool is_mut) { } auto rsType = PrimitiveRsTypeName(field.desc()); - if (fieldType == FieldDescriptor::TYPE_STRING) { + if (fieldType == FieldDescriptor::TYPE_STRING || + fieldType == FieldDescriptor::TYPE_BYTES) { field.Emit({{"field", fieldName}, {"self", self}, {"getter_thunk", getter_thunk}, @@ -252,46 +253,7 @@ void GetterForViewOrMut(Context field, bool is_mut) { R"rs( pub fn r#$field$(&self) -> $pb$::View<'_, $RsType$> { let s = unsafe { $getter_thunk$($self$).as_ref() }; - unsafe { __pb::ProtoStr::from_utf8_unchecked(s) } - } - - $maybe_mutator$ - )rs"); - } else if (fieldType == FieldDescriptor::TYPE_BYTES) { - field.Emit({{"field", fieldName}, - {"self", self}, - {"getter_thunk", getter_thunk}, - {"setter_thunk", setter_thunk}, - {"RsType", rsType}, - {"maybe_mutator", - [&] { - if (is_mut) { - field.Emit({}, R"rs( - pub fn r#$field$_mut(&self) -> $pb$::Mut<'_, $RsType$> { - static VTABLE: $pbi$::BytesMutVTable = - $pbi$::BytesMutVTable::new( - $pbi$::Private, - $getter_thunk$, - $setter_thunk$, - ); - - unsafe { - <$pb$::Mut<$RsType$>>::from_inner( - $pbi$::Private, - $pbi$::RawVTableMutator::new( - $pbi$::Private, - self.inner, - &VTABLE, - ) - ) - } - } - )rs"); - } - }}}, - R"rs( - pub fn r#$field$(&self) -> $pb$::View<'_, $RsType$> { - unsafe { $getter_thunk$($self$).as_ref() } + unsafe { __pb::ProtoStr::from_utf8_unchecked(s).into() } } $maybe_mutator$ From 7e7037db27aeaa3b9a3e7623e525da6b67150c38 Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Thu, 14 Dec 2023 14:03:09 -0800 Subject: [PATCH 022/255] Automated rollback of commit 1db8ed47c29fa04b51df373ce5bbb7e7f95cbd56. PiperOrigin-RevId: 591045566 --- .../protobuf/generated_message_reflection.cc | 15 +- src/google/protobuf/implicit_weak_message.h | 2 +- .../protobuf/repeated_field_unittest.cc | 1 + src/google/protobuf/repeated_ptr_field.cc | 50 ++--- src/google/protobuf/repeated_ptr_field.h | 207 +++++++++--------- 5 files changed, 135 insertions(+), 140 deletions(-) diff --git a/src/google/protobuf/generated_message_reflection.cc b/src/google/protobuf/generated_message_reflection.cc index 0c914e832e734..647b4cc747b80 100644 --- a/src/google/protobuf/generated_message_reflection.cc +++ b/src/google/protobuf/generated_message_reflection.cc @@ -1431,7 +1431,7 @@ void Reflection::ClearField(Message* message, switch (field->options().ctype()) { default: // TODO: Support other string reps. case FieldOptions::STRING: - MutableRaw(message, field)->Clear(); + MutableRaw >(message, field)->Clear(); break; } break; @@ -1441,7 +1441,10 @@ void Reflection::ClearField(Message* message, if (IsMapFieldInApi(field)) { MutableRaw(message, field)->Clear(); } else { - MutableRaw(message, field)->Clear(); + // We don't know which subclass of RepeatedPtrFieldBase the type is, + // so we use RepeatedPtrFieldBase directly. + MutableRaw(message, field) + ->Clear >(); } break; } @@ -1478,7 +1481,8 @@ void Reflection::RemoveLast(Message* message, switch (field->options().ctype()) { default: // TODO: Support other string reps. case FieldOptions::STRING: - MutableRaw(message, field)->RemoveLast(); + MutableRaw >(message, field) + ->RemoveLast(); break; } break; @@ -1487,9 +1491,10 @@ void Reflection::RemoveLast(Message* message, if (IsMapFieldInApi(field)) { MutableRaw(message, field) ->MutableRepeatedField() - ->RemoveLast(); + ->RemoveLast >(); } else { - MutableRaw(message, field)->RemoveLast(); + MutableRaw(message, field) + ->RemoveLast >(); } break; } diff --git a/src/google/protobuf/implicit_weak_message.h b/src/google/protobuf/implicit_weak_message.h index 7856c2212d4f1..708f73a151c0c 100644 --- a/src/google/protobuf/implicit_weak_message.h +++ b/src/google/protobuf/implicit_weak_message.h @@ -201,7 +201,7 @@ struct WeakRepeatedPtrField { } T* Add() { return weak.Add(); } - void Clear() { base().Clear(); } + void Clear() { base().template Clear(); } void MergeFrom(const WeakRepeatedPtrField& other) { if (other.empty()) return; base().template MergeFrom(other.base()); diff --git a/src/google/protobuf/repeated_field_unittest.cc b/src/google/protobuf/repeated_field_unittest.cc index e2c3294bd1bf8..d99aae6f525fe 100644 --- a/src/google/protobuf/repeated_field_unittest.cc +++ b/src/google/protobuf/repeated_field_unittest.cc @@ -1658,6 +1658,7 @@ TEST(RepeatedPtrField, ClearedElements) { EXPECT_EQ(field.ClearedCount(), 0); field.RemoveLast(); + EXPECT_TRUE(original->empty()); EXPECT_EQ(field.ClearedCount(), 1); EXPECT_EQ(field.Add(), diff --git a/src/google/protobuf/repeated_ptr_field.cc b/src/google/protobuf/repeated_ptr_field.cc index 4d929376eefac..49c29fe433d6a 100644 --- a/src/google/protobuf/repeated_ptr_field.cc +++ b/src/google/protobuf/repeated_ptr_field.cc @@ -54,7 +54,7 @@ void** RepeatedPtrFieldBase::InternalExtend(int extend_amount) { new_rep = reinterpret_cast(Arena::CreateArray(arena, bytes)); } - if (using_element()) { + if (using_sso()) { new_rep->allocated_size = tagged_rep_or_elem_ != nullptr ? 1 : 0; new_rep->elements[0] = tagged_rep_or_elem_; } else { @@ -75,7 +75,7 @@ void** RepeatedPtrFieldBase::InternalExtend(int extend_amount) { tagged_rep_or_elem_ = reinterpret_cast(reinterpret_cast(new_rep) + 1); - capacity_proxy_ = new_capacity - kInlinedCapacity; + capacity_proxy_ = new_capacity - kSSOCapacity; return &new_rep->elements[current_size_]; } @@ -94,31 +94,18 @@ void RepeatedPtrFieldBase::DestroyProtos() { tagged_rep_or_elem_ = nullptr; } -namespace { -template -struct ElementRecycler { - static void clear(void* p) { static_cast(p)->Clear(); } -}; - -template <> -struct ElementRecycler { - static void clear(void* str) { static_cast(str)->clear(); } -}; - -} // namespace - -template -void* RepeatedPtrFieldBase::AddInternal(Factory factory) { +template +auto* RepeatedPtrFieldBase::AddInternal(F factory) { Arena* const arena = GetArena(); + using Result = decltype(factory(arena)); if (tagged_rep_or_elem_ == nullptr) { ExchangeCurrentSize(1); tagged_rep_or_elem_ = factory(arena); - return tagged_rep_or_elem_; + return static_cast(tagged_rep_or_elem_); } - if (using_element()) { + if (using_sso()) { if (ExchangeCurrentSize(1) == 0) { - Recycler::clear(tagged_rep_or_elem_); - return tagged_rep_or_elem_; + return static_cast(tagged_rep_or_elem_); } } else { absl::PrefetchToLocalCache(rep()); @@ -128,28 +115,23 @@ void* RepeatedPtrFieldBase::AddInternal(Factory factory) { } else { Rep* r = rep(); if (current_size_ != r->allocated_size) { - void* cached = r->elements[ExchangeCurrentSize(current_size_ + 1)]; - Recycler::clear(cached); - return cached; + return static_cast( + r->elements[ExchangeCurrentSize(current_size_ + 1)]); } } Rep* r = rep(); ++r->allocated_size; void*& result = r->elements[ExchangeCurrentSize(current_size_ + 1)]; result = factory(arena); - return result; -} - -void* RepeatedPtrFieldBase::AddMessageLite(ElementFactory factory) { - return AddInternal>(factory); + return static_cast(result); } -void* RepeatedPtrFieldBase::AddString() { - return AddInternal>(NewStringElement); +void* RepeatedPtrFieldBase::AddOutOfLineHelper(ElementFactory factory) { + return AddInternal(factory); } void RepeatedPtrFieldBase::CloseGap(int start, int num) { - if (using_element()) { + if (using_sso()) { if (start == 0 && num == 1) { tagged_rep_or_elem_ = nullptr; } @@ -164,8 +146,7 @@ void RepeatedPtrFieldBase::CloseGap(int start, int num) { } MessageLite* RepeatedPtrFieldBase::AddMessage(const MessageLite* prototype) { - return static_cast(AddInternal>( - [prototype](Arena* a) { return prototype->New(a); })); + return AddInternal([prototype](Arena* a) { return prototype->New(a); }); } void InternalOutOfLineDeleteMessageLite(MessageLite* message) { @@ -216,7 +197,6 @@ int RepeatedPtrFieldBase::MergeIntoClearedMessages( ABSL_DCHECK(typeid(*src[i]) == typeid(*src[0])) << typeid(*src[i]).name() << " vs " << typeid(*src[0]).name(); #endif - dst[i]->Clear(); dst[i]->CheckTypeAndMergeFrom(*src[i]); } return count; diff --git a/src/google/protobuf/repeated_ptr_field.h b/src/google/protobuf/repeated_ptr_field.h index 05bb7897e6993..644bdb47574b6 100644 --- a/src/google/protobuf/repeated_ptr_field.h +++ b/src/google/protobuf/repeated_ptr_field.h @@ -116,7 +116,7 @@ class PROTOBUF_EXPORT RepeatedPtrFieldBase { template using Value = typename Handler::Type; - static constexpr int kInlinedCapacity = 1; + static constexpr int kSSOCapacity = 1; using ElementFactory = void* (*)(Arena*); @@ -158,7 +158,7 @@ class PROTOBUF_EXPORT RepeatedPtrFieldBase { // // * prefer `SizeAtCapacity()` to `size() == Capacity()`; // * prefer `AllocatedSizeAtCapacity()` to `allocated_size() == Capacity()`. - int Capacity() const { return capacity_proxy_ + kInlinedCapacity; } + int Capacity() const { return capacity_proxy_ + kSSOCapacity; } template const Value& at(int index) const { @@ -183,10 +183,7 @@ class PROTOBUF_EXPORT RepeatedPtrFieldBase { template Value* Add() { - if (std::is_same, std::string>{}) { - return cast(AddString()); - } - return cast(AddMessageLite(Handler::GetNewFunc())); + return cast(AddOutOfLineHelper(Handler::GetNewFunc())); } template < @@ -199,7 +196,7 @@ class PROTOBUF_EXPORT RepeatedPtrFieldBase { return; } MaybeExtend(); - if (!using_element()) ++rep()->allocated_size; + if (!using_sso()) ++rep()->allocated_size; auto* result = TypeHandler::New(arena_, std::move(value)); element_at(ExchangeCurrentSize(current_size_ + 1)) = result; } @@ -221,14 +218,15 @@ class PROTOBUF_EXPORT RepeatedPtrFieldBase { for (int i = 0; i < n; i++) { Delete(elems[i], nullptr); } - if (!using_element()) { + if (!using_sso()) { internal::SizedDelete(rep(), Capacity() * sizeof(elems[0]) + kRepHeaderSize); } } inline bool NeedsDestroy() const { - // tagged_rep_or_elem_ contains either allocated element or allocated `Rep`. + // Either there is an allocated element in SSO buffer or there is an + // allocated Rep. return tagged_rep_or_elem_ != nullptr; } void DestroyProtos(); @@ -251,7 +249,15 @@ class PROTOBUF_EXPORT RepeatedPtrFieldBase { // Pre-condition: prototype must not be nullptr. MessageLite* AddMessage(const MessageLite* prototype); - void Clear() { ExchangeCurrentSize(0); } + template + void Clear() { + const int n = current_size_; + ABSL_DCHECK_GE(n, 0); + if (n > 0) { + using H = CommonHandler; + ClearNonEmpty(); + } + } // Appends all message values from `from` to this instance. template @@ -288,21 +294,24 @@ class PROTOBUF_EXPORT RepeatedPtrFieldBase { ABSL_DCHECK_EQ(current_size_, allocated_size()); MaybeExtend(); element_at(current_size_++) = value; - if (!using_element()) ++rep()->allocated_size; + if (!using_sso()) ++rep()->allocated_size; } protected: + template void RemoveLast() { ABSL_DCHECK_GT(current_size_, 0); ExchangeCurrentSize(current_size_ - 1); + using H = CommonHandler; + H::Clear(cast(element_at(current_size_))); } template void CopyFrom(const RepeatedPtrFieldBase& other) { if (&other == this) return; - RepeatedPtrFieldBase::Clear(); + RepeatedPtrFieldBase::Clear(); if (other.empty()) return; - RepeatedPtrFieldBase::MergeFrom>(other); + RepeatedPtrFieldBase::MergeFrom(other); } void CloseGap(int start, int num); @@ -357,7 +366,7 @@ class PROTOBUF_EXPORT RepeatedPtrFieldBase { template PROTOBUF_NOINLINE size_t SpaceUsedExcludingSelfLong() const { size_t allocated_bytes = - using_element() + using_sso() ? 0 : static_cast(Capacity()) * sizeof(void*) + kRepHeaderSize; const int n = allocated_size(); @@ -371,15 +380,15 @@ class PROTOBUF_EXPORT RepeatedPtrFieldBase { // Advanced memory management -------------------------------------- - // Returns a pointer to a cleared object ready to reuse if there is a spare - // allocated object or nullptr otherwise. + // Like Add(), but if there are no cleared objects to use, returns nullptr. template Value* AddFromCleared() { - if (ClearedCount() == 0) return nullptr; - auto* value = - cast(element_at(ExchangeCurrentSize(current_size_ + 1))); - CommonHandler::Clear(value); - return value; + if (current_size_ < allocated_size()) { + return cast( + element_at(ExchangeCurrentSize(current_size_ + 1))); + } else { + return nullptr; + } } template @@ -401,7 +410,7 @@ class PROTOBUF_EXPORT RepeatedPtrFieldBase { elems[allocated_size()] = elems[current_size_]; } elems[ExchangeCurrentSize(current_size_ + 1)] = value; - if (!using_element()) ++rep()->allocated_size; + if (!using_sso()) ++rep()->allocated_size; } template @@ -409,24 +418,24 @@ class PROTOBUF_EXPORT RepeatedPtrFieldBase { ABSL_DCHECK_NE(value, nullptr); // Make room for the new pointer. if (SizeAtCapacity()) { - // The array is completely full, so grow it. + // The array is completely full with no cleared objects, so grow it. InternalExtend(1); ++rep()->allocated_size; } else if (AllocatedSizeAtCapacity()) { // There is no more space in the pointer array because it contains some - // objects awaiting reuse. We don't want to grow the array in + // cleared objects awaiting reuse. We don't want to grow the array in // this case because otherwise a loop calling AddAllocated() followed by // Clear() would leak memory. using H = CommonHandler; Delete(element_at(current_size_), arena_); } else if (current_size_ < allocated_size()) { - // We have some unused allocated objects. Their order is not important, - // so we move the first one to the end to make room for the pointer. + // We have some cleared objects. We don't care about their order, so we + // can just move the first one to the end to make space. element_at(allocated_size()) = element_at(current_size_); ++rep()->allocated_size; } else { - // There are no unused allocated objects. - if (!using_element()) ++rep()->allocated_size; + // There are no cleared objects. + if (!using_sso()) ++rep()->allocated_size; } element_at(ExchangeCurrentSize(current_size_ + 1)) = value; @@ -455,13 +464,13 @@ class PROTOBUF_EXPORT RepeatedPtrFieldBase { ABSL_DCHECK_GT(current_size_, 0); ExchangeCurrentSize(current_size_ - 1); auto* result = cast(element_at(current_size_)); - if (using_element()) { + if (using_sso()) { tagged_rep_or_elem_ = nullptr; } else { --rep()->allocated_size; if (current_size_ < allocated_size()) { - // There are unused allocated elements on the end; replace the removed - // element with the last allocated element. + // There are cleared elements on the end; replace the removed element + // with the last allocated element. element_at(current_size_) = element_at(allocated_size()); } } @@ -477,7 +486,7 @@ class PROTOBUF_EXPORT RepeatedPtrFieldBase { ABSL_DCHECK(TypeHandler::GetArena(value) == nullptr) << "AddCleared() can only accept values not on an arena."; MaybeExtend(); - if (using_element()) { + if (using_sso()) { tagged_rep_or_elem_ = value; } else { element_at(rep()->allocated_size++) = value; @@ -491,14 +500,13 @@ class PROTOBUF_EXPORT RepeatedPtrFieldBase { << "an arena."; ABSL_DCHECK(tagged_rep_or_elem_ != nullptr); ABSL_DCHECK_GT(allocated_size(), current_size_); - void* result; - if (using_element()) { - result = std::exchange(tagged_rep_or_elem_, nullptr); + if (using_sso()) { + auto* result = cast(tagged_rep_or_elem_); + tagged_rep_or_elem_ = nullptr; + return result; } else { - result = element_at(--rep()->allocated_size); + return cast(element_at(--rep()->allocated_size)); } - TypeHandler::Clear(cast(result)); - return cast(result); } // Slowpath handles all cases, copying if necessary. @@ -536,7 +544,7 @@ class PROTOBUF_EXPORT RepeatedPtrFieldBase { // than three times. RepeatedPtrFieldBase temp(other->GetArena()); if (!this->empty()) { - temp.MergeFrom>(*this); + temp.MergeFrom(*this); } this->CopyFrom(*other); other->InternalSwap(&temp); @@ -617,29 +625,30 @@ class PROTOBUF_EXPORT RepeatedPtrFieldBase { ABSL_DCHECK_LE(size(), allocated_size()); ABSL_DCHECK_LE(allocated_size(), Capacity()); // This is equivalent to `current_size_ == Capacity()`. - // - // Using less than instead of equality gives compiler an opportunity to - // generate less instructions. + // Assuming `Capacity()` function is inlined, compiler is likely to optimize + // away "+ kSSOCapacity" and reduce it to "current_size_ > capacity_proxy_" + // which is an instruction less than "current_size_ == capacity_proxy_ + 1". return current_size_ >= Capacity(); } inline bool AllocatedSizeAtCapacity() const { // Harden invariant size() <= allocated_size() <= Capacity(). ABSL_DCHECK_LE(size(), allocated_size()); ABSL_DCHECK_LE(allocated_size(), Capacity()); - // See comment in SizeAtCapacity(). - return using_element() ? (tagged_rep_or_elem_ != nullptr) - : rep()->allocated_size >= Capacity(); + // This combines optimization mentioned in `SizeAtCapacity()` and simplifies + // `allocated_size()` in sso case. + return using_sso() ? (tagged_rep_or_elem_ != nullptr) + : rep()->allocated_size >= Capacity(); } void* const* elements() const { - return using_element() ? &tagged_rep_or_elem_ : +rep()->elements; + return using_sso() ? &tagged_rep_or_elem_ : +rep()->elements; } void** elements() { - return using_element() ? &tagged_rep_or_elem_ : +rep()->elements; + return using_sso() ? &tagged_rep_or_elem_ : +rep()->elements; } void*& element_at(int index) { - if (using_element()) { + if (using_sso()) { ABSL_DCHECK_EQ(index, 0); return tagged_rep_or_elem_; } @@ -650,11 +659,11 @@ class PROTOBUF_EXPORT RepeatedPtrFieldBase { } int allocated_size() const { - return using_element() ? (tagged_rep_or_elem_ != nullptr ? 1 : 0) - : rep()->allocated_size; + return using_sso() ? (tagged_rep_or_elem_ != nullptr ? 1 : 0) + : rep()->allocated_size; } Rep* rep() { - ABSL_DCHECK(!using_element()); + ABSL_DCHECK(!using_sso()); return reinterpret_cast( reinterpret_cast(tagged_rep_or_elem_) - 1); } @@ -662,7 +671,7 @@ class PROTOBUF_EXPORT RepeatedPtrFieldBase { return const_cast(this)->rep(); } - bool using_element() const { + bool using_sso() const { return (reinterpret_cast(tagged_rep_or_elem_) & 1) == 0; } @@ -679,13 +688,28 @@ class PROTOBUF_EXPORT RepeatedPtrFieldBase { TypeHandler::Delete(cast(obj), arena); } - // Merges messages from `from` into available, allocated messages sitting in - // the range `[size(), allocated_size())`. Returns the number of message - // merged which is `ClearedCount(), from.size())`. - // Note that this function does explicitly NOT update `current_size_`. This - // function is out of line as it should be the slow path: this scenario only - // happens when a caller constructs and fills a repeated field, then shrinks - // it, and then merges additional messages into it. + // Out-of-line helper routine for Clear() once the inlined check has + // determined the container is non-empty + template + PROTOBUF_NOINLINE void ClearNonEmpty() { + const int n = current_size_; + void* const* elems = elements(); + int i = 0; + ABSL_DCHECK_GT(n, 0); + // do/while loop to avoid initial test because we know n > 0 + do { + TypeHandler::Clear(cast(elems[i++])); + } while (i < n); + ExchangeCurrentSize(0); + } + + // Merges messages from `from` into available, cleared messages sitting in the + // range `[size(), allocated_size())`. Returns the number of message merged + // which is `ClearedCount(), from.size())`. + // Note that this function does explicitly NOT update `current_size_`. + // This function is out of line as it should be the slow path: this scenario + // only happens when a caller constructs and fills a repeated field, then + // shrinks it, and then merges additional messages into it. int MergeIntoClearedMessages(const RepeatedPtrFieldBase& from); // Appends all messages from `from` to this instance, using the @@ -712,55 +736,40 @@ class PROTOBUF_EXPORT RepeatedPtrFieldBase { // Returns a pointer to the element directly beyond the last element. inline void** InternalReserve(int n) { if (n <= Capacity()) { - return elements() + current_size_; + void** elements = using_sso() ? &tagged_rep_or_elem_ : rep()->elements; + return elements + current_size_; } return InternalExtend(n - Capacity()); } - // Internal helpers for Add that keep definition out-of-line. - void* AddMessageLite(ElementFactory factory); - void* AddString(); + // Internal helper for Add that keeps definition out-of-line. + void* AddOutOfLineHelper(ElementFactory factory); // Common implementation used by various Add* methods. `factory` is an object - // used to construct a new element unless there are spare allocated elements + // used to construct a new element unless there are spare cleared elements // ready for reuse. Returns pointer to the new element. // // Note: avoid inlining this function in methods such as `Add()` as this would // drastically increase binary size due to template instantiation and implicit - // inlining. - template - void* AddInternal(Factory factory); + // inlining. Instead, use wrapper functions with out-of-line definition + // similar to `AddOutOfLineHelper`. + template + auto* AddInternal(F factory); // A few notes on internal representation: // - // * Class layout is optimized to minimize the size: 24 bytes on x86-64. - // * The elements can be stored in one of the two ways and `using_element()` - // tells which one is currently used. - // - // In case of using_element(): - // - // tagged_rep_or_elem_ is a storage for at most one pointer. - // Number of allocated objects (0 or 1) is determined whether - // tagged_rep_or_elem_ is nullptr. - // - // Otherwise, - // - // tagged_rep_or_elem_ is tagged (LSB is 1) pointer to `Rep`, where - // `Rep` contains number of allocated objects as well as the buffer with - // pointers to allocated elements. Rep allows to (a) keep the sizeof small - // (b) allocate both buffer for elements and an integer with allocated - // objects count in one shot. - // - // In both cases, RepeatedPtrFieldBase may own allocated but unused objects: - // - // 1. Their count is determined by `ClearedCount()`. - // 2. Pointers to them are stored directly after pointers to used objects. - // 3. They can be reused in order to avoid extra allocation (note that in - // some cases these objects need to be cleared with `TypeHandler::Clear` - // before they can be reused). + // We use an indirected approach, with struct Rep, to keep + // sizeof(RepeatedPtrFieldBase) equivalent to what it was before arena support + // was added; namely, 3 8-byte machine words on x86-64. An instance of Rep is + // allocated only when the repeated field is non-empty, and it is a + // dynamically-sized struct (the header is directly followed by elements[]). + // We place arena_ and current_size_ directly in the object to avoid cache + // misses due to the indirection, because these fields are checked frequently. + // Placing all fields directly in the RepeatedPtrFieldBase instance would cost + // significant performance for memory-sensitive workloads. void* tagged_rep_or_elem_; int current_size_; - int capacity_proxy_; // See `Capacity()` + int capacity_proxy_; // we store `capacity - kSSOCapacity` as an optimization Arena* arena_; }; @@ -975,7 +984,7 @@ class RepeatedPtrField final : private internal::RepeatedPtrFieldBase { pointer Mutable(int index) ABSL_ATTRIBUTE_LIFETIME_BOUND; // Unlike std::vector, adding an element to a RepeatedPtrField doesn't always - // make a new element; it might reuse an element left over from when the + // make a new element; it might re-use an element left over from when the // field was Clear()'d or resize()'d smaller. For this reason, Add() is the // fastest API for adding a new element. pointer Add() ABSL_ATTRIBUTE_LIFETIME_BOUND; @@ -1157,9 +1166,9 @@ class RepeatedPtrField final : private internal::RepeatedPtrFieldBase { void UnsafeArenaExtractSubrange(int start, int num, Element** elements); // When elements are removed by calls to RemoveLast() or Clear(), they - // are not actually freed. Instead, they are kept so that they can be reused - // later. This can save lots of CPU time when repeatedly reusing a protocol - // message for similar purposes. + // are not actually freed. Instead, they are cleared and kept so that + // they can be reused later. This can save lots of CPU time when + // repeatedly reusing a protocol message for similar purposes. // // Hardcore programs may choose to manipulate these cleared objects // to better optimize memory management using the following routines. @@ -1375,7 +1384,7 @@ inline void RepeatedPtrField::Add(Iter begin, Iter end) { template inline void RepeatedPtrField::RemoveLast() { - RepeatedPtrFieldBase::RemoveLast(); + RepeatedPtrFieldBase::RemoveLast(); } template @@ -1450,7 +1459,7 @@ inline void RepeatedPtrField::UnsafeArenaExtractSubrange( template inline void RepeatedPtrField::Clear() { - RepeatedPtrFieldBase::Clear(); + RepeatedPtrFieldBase::Clear(); } template From 162908d05f36b9449342da81263fd67bbc2fc792 Mon Sep 17 00:00:00 2001 From: Alyssa Haroldsen Date: Thu, 14 Dec 2023 14:06:06 -0800 Subject: [PATCH 023/255] Simplify the type bounds on PrimitiveMut via type erasure PiperOrigin-RevId: 591046477 --- rust/primitive.rs | 11 +++--- rust/vtable.rs | 86 +++++++++++++++++++++++++++++------------------ 2 files changed, 60 insertions(+), 37 deletions(-) diff --git a/rust/primitive.rs b/rust/primitive.rs index 539ddf293f19e..ea742181bf9f6 100644 --- a/rust/primitive.rs +++ b/rust/primitive.rs @@ -15,17 +15,20 @@ use crate::{Mut, MutProxy, Proxied, ProxiedWithPresence, SettableValue, View, Vi /// A mutator for a primitive (numeric or enum) value of `T`. /// /// This type is `protobuf::Mut<'msg, T>`. -pub struct PrimitiveMut<'msg, T: ProxiedWithRawVTable> { +pub struct PrimitiveMut<'msg, T> { inner: InnerPrimitiveMut<'msg, T>, } -impl<'msg, T: ProxiedWithRawVTable> Debug for PrimitiveMut<'msg, T> { +impl<'msg, T> Debug for PrimitiveMut<'msg, T> +where + T: PrimitiveWithRawVTable, +{ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { f.debug_struct("PrimitiveMut").field("inner", &self.inner).finish() } } -impl<'msg, T: ProxiedWithRawVTable> PrimitiveMut<'msg, T> { +impl<'msg, T> PrimitiveMut<'msg, T> { /// # Safety /// `inner` must be valid and non-aliased for `T` for `'msg` #[doc(hidden)] @@ -34,7 +37,7 @@ impl<'msg, T: ProxiedWithRawVTable> PrimitiveMut<'msg, T> { } } -unsafe impl<'msg, T: ProxiedWithRawVTable> Sync for PrimitiveMut<'msg, T> {} +unsafe impl<'msg, T> Sync for PrimitiveMut<'msg, T> {} impl<'msg, T> PrimitiveMut<'msg, T> where diff --git a/rust/vtable.rs b/rust/vtable.rs index f0128dbf937ed..2691125b46cd2 100644 --- a/rust/vtable.rs +++ b/rust/vtable.rs @@ -14,6 +14,8 @@ use crate::{ ProxiedWithPresence, View, ViewProxy, }; use std::fmt::{self, Debug}; +use std::marker::PhantomData; +use std::ptr::NonNull; /// A proxied type that can use a vtable to provide get/set access for a /// present field. @@ -67,7 +69,8 @@ where AbsentMutData<'msg> = RawVTableOptionalMutatorData<'msg, T>, >, { - let data = RawVTableOptionalMutatorData { msg_ref, vtable: optional_vtable }; + // SAFETY: safe as promised by the caller of the function + let data = unsafe { RawVTableOptionalMutatorData::new(Private, msg_ref, optional_vtable) }; if is_set { Optional::Set(PresentField::from_inner(Private, data)) } else { @@ -89,26 +92,29 @@ where /// /// [`RawVTableOptionalMutatorData`] is similar, but also includes the /// capability to has/clear. -pub struct RawVTableMutator<'msg, T: ProxiedWithRawVTable + ?Sized> { +pub struct RawVTableMutator<'msg, T: ?Sized> { msg_ref: MutatorMessageRef<'msg>, - vtable: &'static T::VTable, + /// Stores `&'static ::Vtable` + /// as a type-erased pointer to avoid a bound on the struct. + vtable: NonNull<()>, + _phantom: PhantomData<&'msg T>, } // These use manual impls instead of derives to avoid unnecessary bounds on `T`. // This problem is referred to as "perfect derive". // https://smallcultfollowing.com/babysteps/blog/2022/04/12/implied-bounds-and-perfect-derive/ -impl<'msg, T: ProxiedWithRawVTable + ?Sized> Clone for RawVTableMutator<'msg, T> { +impl<'msg, T: ?Sized> Clone for RawVTableMutator<'msg, T> { fn clone(&self) -> Self { *self } } -impl<'msg, T: ProxiedWithRawVTable + ?Sized> Copy for RawVTableMutator<'msg, T> {} +impl<'msg, T: ?Sized> Copy for RawVTableMutator<'msg, T> {} impl<'msg, T: ProxiedWithRawVTable + ?Sized> Debug for RawVTableMutator<'msg, T> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("RawVTableMutator") .field("msg_ref", &self.msg_ref) - .field("vtable", &self.vtable) + .field("vtable", self.vtable()) .finish() } } @@ -125,7 +131,12 @@ impl<'msg, T: ProxiedWithRawVTable + ?Sized> RawVTableMutator<'msg, T> { msg_ref: MutatorMessageRef<'msg>, vtable: &'static T::VTable, ) -> Self { - RawVTableMutator { msg_ref, vtable } + RawVTableMutator { msg_ref, vtable: NonNull::from(vtable).cast(), _phantom: PhantomData } + } + + fn vtable(self) -> &'static T::VTable { + // SAFETY: This was cast from `&'static T::VTable`. + unsafe { self.vtable.cast().as_ref() } } } @@ -138,30 +149,27 @@ impl<'msg, T: ProxiedWithRawVTable + ?Sized> RawVTableMutator<'msg, T> { /// /// This has the same representation for "present" and "absent" data; /// differences like default values are obviated by the vtable. -pub struct RawVTableOptionalMutatorData<'msg, T: ProxiedWithRawOptionalVTable + ?Sized> { +pub struct RawVTableOptionalMutatorData<'msg, T: ?Sized> { msg_ref: MutatorMessageRef<'msg>, - vtable: &'static T::OptionalVTable, + /// Stores `&'static ::Vtable` + /// as a type-erased pointer to avoid a bound on the struct. + optional_vtable: NonNull<()>, + _phantom: PhantomData<&'msg T>, } -unsafe impl<'msg, T: ProxiedWithRawOptionalVTable + ?Sized> Sync - for RawVTableOptionalMutatorData<'msg, T> -{ -} +// SAFETY: all `T` that can perform mutations don't mutate through a shared +// reference. +unsafe impl<'msg, T: ?Sized> Sync for RawVTableOptionalMutatorData<'msg, T> {} // These use manual impls instead of derives to avoid unnecessary bounds on `T`. // This problem is referred to as "perfect derive". // https://smallcultfollowing.com/babysteps/blog/2022/04/12/implied-bounds-and-perfect-derive/ -impl<'msg, T: ProxiedWithRawOptionalVTable + ?Sized> Clone - for RawVTableOptionalMutatorData<'msg, T> -{ +impl<'msg, T: ?Sized> Clone for RawVTableOptionalMutatorData<'msg, T> { fn clone(&self) -> Self { *self } } -impl<'msg, T: ProxiedWithRawOptionalVTable + ?Sized> Copy - for RawVTableOptionalMutatorData<'msg, T> -{ -} +impl<'msg, T: ?Sized> Copy for RawVTableOptionalMutatorData<'msg, T> {} impl<'msg, T: ProxiedWithRawOptionalVTable + ?Sized> Debug for RawVTableOptionalMutatorData<'msg, T> @@ -169,7 +177,7 @@ impl<'msg, T: ProxiedWithRawOptionalVTable + ?Sized> Debug fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("RawVTableOptionalMutatorData") .field("msg_ref", &self.msg_ref) - .field("vtable", &self.vtable) + .field("vtable", self.optional_vtable()) .finish() } } @@ -186,11 +194,23 @@ impl<'msg, T: ProxiedWithRawOptionalVTable + ?Sized> RawVTableOptionalMutatorDat msg_ref: MutatorMessageRef<'msg>, vtable: &'static T::OptionalVTable, ) -> Self { - Self { msg_ref, vtable } + Self { msg_ref, optional_vtable: NonNull::from(vtable).cast(), _phantom: PhantomData } + } + + fn optional_vtable(self) -> &'static T::OptionalVTable { + // SAFETY: This was cast from `&'static T::OptionalVTable` in `new`. + unsafe { self.optional_vtable.cast().as_ref() } } fn into_raw_mut(self) -> RawVTableMutator<'msg, T> { - RawVTableMutator { msg_ref: self.msg_ref, vtable: T::upcast_vtable(Private, self.vtable) } + // SAFETY: the safety requirements have been met by the caller of `new`. + unsafe { + RawVTableMutator::new( + Private, + self.msg_ref, + T::upcast_vtable(Private, self.optional_vtable()), + ) + } } } @@ -342,7 +362,7 @@ impl<'msg> RawVTableMutator<'msg, [u8]> { // - `msg_ref` is valid for `'msg` as promised by the caller of `new`. // - The caller of `BytesMutVTable` promised that the returned `PtrAndLen` is // valid for `'msg`. - unsafe { (self.vtable.getter)(self.msg_ref.msg()).as_ref() } + unsafe { (self.vtable().getter)(self.msg_ref.msg()).as_ref() } } /// # Safety @@ -353,7 +373,7 @@ impl<'msg> RawVTableMutator<'msg, [u8]> { let val = copy_bytes_in_arena_if_needed_by_runtime(self.msg_ref, val); // SAFETY: // - `msg_ref` is valid for `'msg` as promised by the caller of `new`. - unsafe { (self.vtable.setter)(self.msg_ref.msg(), val.into()) } + unsafe { (self.vtable().setter)(self.msg_ref.msg(), val.into()) } } pub(crate) fn truncate(&self, len: usize) { @@ -373,7 +393,7 @@ impl<'msg> RawVTableOptionalMutatorData<'msg, [u8]> { pub(crate) fn set_absent_to_default(self) -> Self { // SAFETY: The default value is UTF-8 if required by the // runtime as promised by the caller of `BytesOptionalMutVTable::new`. - unsafe { self.set(self.vtable.default) } + unsafe { self.set(self.optional_vtable().default) } } /// # Safety @@ -383,7 +403,7 @@ impl<'msg> RawVTableOptionalMutatorData<'msg, [u8]> { let val = copy_bytes_in_arena_if_needed_by_runtime(self.msg_ref, val); // SAFETY: // - `msg_ref` is valid for `'msg` as promised by the caller. - unsafe { (self.vtable.base.setter)(self.msg_ref.msg(), val.into()) } + unsafe { (self.optional_vtable().base.setter)(self.msg_ref.msg(), val.into()) } self } @@ -392,7 +412,7 @@ impl<'msg> RawVTableOptionalMutatorData<'msg, [u8]> { // - `msg_ref` is valid for `'msg` as promised by the caller. // - The caller of `new` promised that the returned `PtrAndLen` is valid for // `'msg`. - unsafe { (self.vtable.clearer)(self.msg_ref.msg()) } + unsafe { (self.optional_vtable().clearer)(self.msg_ref.msg()) } self } } @@ -446,7 +466,7 @@ impl RawVTableMutator<'_, T> { // SAFETY: // - `msg_ref` is valid for the lifetime of `RawVTableMutator` as promised by // the caller of `new`. - unsafe { (self.vtable.getter)(self.msg_ref.msg()) } + unsafe { (self.vtable().getter)(self.msg_ref.msg()) } } /// # Safety @@ -455,7 +475,7 @@ impl RawVTableMutator<'_, T> { // SAFETY: // - `msg_ref` is valid for the lifetime of `RawVTableMutator` as promised by // the caller of `new`. - unsafe { (self.vtable.setter)(self.msg_ref.msg(), val) } + unsafe { (self.vtable().setter)(self.msg_ref.msg(), val) } } } @@ -464,14 +484,14 @@ impl<'msg, T: PrimitiveWithRawVTable> RawVTableOptionalMutatorData<'msg, T> { // SAFETY: // - `msg_ref` is valid for the lifetime of `RawVTableOptionalMutatorData` as // promised by the caller of `new`. - self.set(self.vtable.default) + self.set(self.optional_vtable().default) } pub(crate) fn set(self, val: T) -> Self { // SAFETY: // - `msg_ref` is valid for the lifetime of `RawVTableOptionalMutatorData` as // promised by the caller of `new`. - unsafe { (self.vtable.base.setter)(self.msg_ref.msg(), val) } + unsafe { (self.optional_vtable().base.setter)(self.msg_ref.msg(), val) } self } @@ -479,7 +499,7 @@ impl<'msg, T: PrimitiveWithRawVTable> RawVTableOptionalMutatorData<'msg, T> { // SAFETY: // - `msg_ref` is valid for the lifetime of `RawVTableOptionalMutatorData` as // promised by the caller of `new`. - unsafe { (self.vtable.clearer)(self.msg_ref.msg()) } + unsafe { (self.optional_vtable().clearer)(self.msg_ref.msg()) } self } } From f51182b54311a08955f1282ee818d8fae9e3c216 Mon Sep 17 00:00:00 2001 From: Alyssa Haroldsen Date: Thu, 14 Dec 2023 14:07:40 -0800 Subject: [PATCH 024/255] Add RepeatedMut::clear, free for owned Repeated PiperOrigin-RevId: 591046913 --- rust/cpp.rs | 14 +++++++++++++- rust/cpp_kernel/cpp_api.cc | 8 ++++++++ rust/repeated.rs | 35 +++++++++++++++++++++++++++++++---- rust/upb.rs | 14 +++++++++++++- 4 files changed, 65 insertions(+), 6 deletions(-) diff --git a/rust/cpp.rs b/rust/cpp.rs index 80f6e8e944eb4..2f43225359012 100644 --- a/rust/cpp.rs +++ b/rust/cpp.rs @@ -215,20 +215,23 @@ impl<'msg> InnerRepeatedMut<'msg> { macro_rules! impl_repeated_primitives { (@impl $($t:ty => [ $new_thunk:ident, + $free_thunk:ident, $add_thunk:ident, $size_thunk:ident, $get_thunk:ident, $set_thunk:ident, + $clear_thunk:ident, $copy_from_thunk:ident $(,)? ]),* $(,)?) => { $( - // TODO: Add clear, free extern "C" { fn $new_thunk() -> RawRepeatedField; + fn $free_thunk(f: RawRepeatedField); fn $add_thunk(f: RawRepeatedField, v: $t); fn $size_thunk(f: RawRepeatedField) -> usize; fn $get_thunk(f: RawRepeatedField, i: usize) -> $t; fn $set_thunk(f: RawRepeatedField, i: usize, v: $t); + fn $clear_thunk(f: RawRepeatedField); fn $copy_from_thunk(src: RawRepeatedField, dst: RawRepeatedField); } @@ -239,12 +242,19 @@ macro_rules! impl_repeated_primitives { Repeated::from_inner(InnerRepeatedMut::new(Private, $new_thunk())) } } + #[allow(dead_code)] + unsafe fn repeated_free(_: Private, f: &mut Repeated<$t>) { + unsafe { $free_thunk(f.as_mut().as_raw(Private)) } + } fn repeated_len(f: View>) -> usize { unsafe { $size_thunk(f.as_raw(Private)) } } fn repeated_push(mut f: Mut>, v: View<$t>) { unsafe { $add_thunk(f.as_raw(Private), v) } } + fn repeated_clear(mut f: Mut>) { + unsafe { $clear_thunk(f.as_raw(Private)) } + } unsafe fn repeated_get_unchecked(f: View>, i: usize) -> View<$t> { unsafe { $get_thunk(f.as_raw(Private), i) } } @@ -262,10 +272,12 @@ macro_rules! impl_repeated_primitives { impl_repeated_primitives!(@impl $( $t => [ [< __pb_rust_RepeatedField_ $t _new >], + [< __pb_rust_RepeatedField_ $t _free >], [< __pb_rust_RepeatedField_ $t _add >], [< __pb_rust_RepeatedField_ $t _size >], [< __pb_rust_RepeatedField_ $t _get >], [< __pb_rust_RepeatedField_ $t _set >], + [< __pb_rust_RepeatedField_ $t _clear >], [< __pb_rust_RepeatedField_ $t _copy_from >], ], )*); diff --git a/rust/cpp_kernel/cpp_api.cc b/rust/cpp_kernel/cpp_api.cc index 05aec1f0aedf8..0536b9356bf83 100644 --- a/rust/cpp_kernel/cpp_api.cc +++ b/rust/cpp_kernel/cpp_api.cc @@ -12,6 +12,10 @@ extern "C" { google::protobuf::RepeatedField* __pb_rust_RepeatedField_##rust_ty##_new() { \ return new google::protobuf::RepeatedField(); \ } \ + void __pb_rust_RepeatedField_##rust_ty##_free( \ + google::protobuf::RepeatedField* r) { \ + delete r; \ + } \ void __pb_rust_RepeatedField_##rust_ty##_add(google::protobuf::RepeatedField* r, \ ty val) { \ r->Add(val); \ @@ -31,6 +35,10 @@ extern "C" { void __pb_rust_RepeatedField_##rust_ty##_copy_from( \ google::protobuf::RepeatedField const& src, google::protobuf::RepeatedField& dst) { \ dst.CopyFrom(src); \ + } \ + void __pb_rust_RepeatedField_##rust_ty##_clear( \ + google::protobuf::RepeatedField* r) { \ + r->Clear(); \ } expose_repeated_field_methods(int32_t, i32); diff --git a/rust/repeated.rs b/rust/repeated.rs index a5b452229a951..22d6fb98d909c 100644 --- a/rust/repeated.rs +++ b/rust/repeated.rs @@ -110,8 +110,6 @@ impl<'msg, T> RepeatedMut<'msg, T> where T: ProxiedInRepeated + ?Sized + 'msg, { - // TODO: Add clear, free - /// # Safety /// - `inner` must be valid to read and write from for `'msg` /// - There must be no aliasing references or mutations on the same @@ -158,6 +156,11 @@ where pub fn copy_from(&mut self, src: RepeatedView<'_, T>) { T::repeated_copy_from(src, self.as_mut()) } + + /// Clears the repeated field. + pub fn clear(&mut self) { + T::repeated_clear(self.as_mut()) + } } /// Types that can appear in a `Repeated`. @@ -171,19 +174,30 @@ where /// - It must be sound to call `*_unchecked*(x)` with an `index` less than /// `repeated_len(x)`. pub unsafe trait ProxiedInRepeated: Proxied { - // TODO: Add clear, free /// Constructs a new owned `Repeated` field. #[doc(hidden)] fn repeated_new(_private: Private) -> Repeated { unimplemented!("not required") } + /// Frees the repeated field in-place, for use in `Drop`. + /// + /// # Safety + /// - After `repeated_free`, no other methods on the input are safe to call. + #[doc(hidden)] + unsafe fn repeated_free(_private: Private, _repeated: &mut Repeated) { + unimplemented!("not required") + } + /// Gets the length of the repeated field. fn repeated_len(repeated: View>) -> usize; /// Appends a new element to the end of the repeated field. fn repeated_push(repeated: Mut>, val: View); + /// Clears the repeated field of elements. + fn repeated_clear(repeated: Mut>); + /// # Safety /// `index` must be less than `Self::repeated_len(repeated)` unsafe fn repeated_get_unchecked(repeated: View>, index: usize) -> View; @@ -235,8 +249,8 @@ pub struct Repeated { _phantom: PhantomData, } -#[allow(dead_code)] impl Repeated { + #[allow(dead_code)] pub(crate) fn new() -> Self { T::repeated_new(Private) } @@ -245,6 +259,7 @@ impl Repeated { Self { inner, _phantom: PhantomData } } + #[allow(dead_code)] pub(crate) fn inner(&mut self) -> InnerRepeatedMut<'static> { self.inner } @@ -254,6 +269,13 @@ impl Repeated { } } +impl Drop for Repeated { + fn drop(&mut self) { + // SAFETY: only called once + unsafe { T::repeated_free(Private, self) } + } +} + // SAFETY: `Repeated` does not allow for shared mutability. unsafe impl Sync for Repeated {} @@ -388,6 +410,11 @@ mod tests { r.iter().collect::>(), elements_are![$(eq($vals)),*]); r.set(0, <$t as Default>::default()); assert_that!(r.get(0).expect("elem 0"), eq(<$t as Default>::default())); + + r.clear(); + assert!(r.is_empty(), "is_empty after clear"); + assert!(r.iter().next().is_none(), "iter empty after clear"); + assert!(r.into_iter().next().is_none(), "mut iter empty after clear"); })* } } diff --git a/rust/upb.rs b/rust/upb.rs index 406572a0b870f..cef685c3a98f4 100644 --- a/rust/upb.rs +++ b/rust/upb.rs @@ -370,7 +370,6 @@ extern "C" { macro_rules! impl_repeated_primitives { ($(($t:ty, $ufield:ident, $upb_tag:expr)),* $(,)?) => { $( - // TODO: Add clear, free unsafe impl ProxiedInRepeated for $t { #[allow(dead_code)] fn repeated_new(_: Private) -> Repeated<$t> { @@ -385,6 +384,16 @@ macro_rules! impl_repeated_primitives { }) } } + #[allow(dead_code)] + unsafe fn repeated_free(_: Private, f: &mut Repeated<$t>) { + // Freeing the array itself is handled by `Arena::Drop` + // SAFETY: + // - `f.raw_arena()` is a live `upb_Arena*` as + // - This function is only called once for `f` + unsafe { + upb_Arena_Free(f.inner().arena); + } + } fn repeated_len(f: View>) -> usize { unsafe { upb_Array_Size(f.as_raw(Private)) } } @@ -396,6 +405,9 @@ macro_rules! impl_repeated_primitives { f.raw_arena(Private)) } } + fn repeated_clear(mut f: Mut>) { + unsafe { upb_Array_Resize(f.as_raw(Private), 0, f.raw_arena(Private)); } + } unsafe fn repeated_get_unchecked(f: View>, i: usize) -> View<$t> { unsafe { upb_Array_Get(f.as_raw(Private), i).$ufield } } From 8505082f168eb44407352dd14d591918af86d3a2 Mon Sep 17 00:00:00 2001 From: Alyssa Haroldsen Date: Thu, 14 Dec 2023 14:09:17 -0800 Subject: [PATCH 025/255] Improve thread safety docs/bounds for PrimitiveMut PiperOrigin-RevId: 591047379 --- rust/primitive.rs | 2 ++ rust/vtable.rs | 2 ++ 2 files changed, 4 insertions(+) diff --git a/rust/primitive.rs b/rust/primitive.rs index ea742181bf9f6..193901bb4b443 100644 --- a/rust/primitive.rs +++ b/rust/primitive.rs @@ -37,6 +37,8 @@ impl<'msg, T> PrimitiveMut<'msg, T> { } } +// SAFETY: all `T` that can perform mutations don't mutate through a shared +// reference. unsafe impl<'msg, T> Sync for PrimitiveMut<'msg, T> {} impl<'msg, T> PrimitiveMut<'msg, T> diff --git a/rust/vtable.rs b/rust/vtable.rs index 2691125b46cd2..311809608369b 100644 --- a/rust/vtable.rs +++ b/rust/vtable.rs @@ -432,6 +432,8 @@ pub trait PrimitiveWithRawVTable: + Debug + 'static + ProxiedWithPresence + + Sync + + Send + for<'msg> Proxied = Self, Mut<'msg> = PrimitiveMut<'msg, Self>> { } From eea39d6f53b2e9ae9432c038d3754fcc00ba9228 Mon Sep 17 00:00:00 2001 From: Mike Kruskal Date: Thu, 14 Dec 2023 14:41:15 -0800 Subject: [PATCH 026/255] Add Bazel 7 test points. This adds tests for C++ under linux, and windows, and upb on linux. PiperOrigin-RevId: 591056302 --- .github/workflows/test_cpp.yml | 23 +++++++++++++++++++---- .github/workflows/test_upb.yml | 5 ++++- ci/common.bazelrc | 5 ++++- 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/.github/workflows/test_cpp.yml b/.github/workflows/test_cpp.yml index 0aef03db08ced..a6dd8b8c028f5 100644 --- a/.github/workflows/test_cpp.yml +++ b/.github/workflows/test_cpp.yml @@ -30,6 +30,9 @@ jobs: - targets: //pkg/... //src/... @com_google_protobuf_examples//... //third_party/utf8_range/... # Override cases with custom images + - config: { name: "Bazel7" } + image: "us-docker.pkg.dev/protobuf-build/containers/common/linux/bazel:7.0.0-a04396cc76704d4b7c722789e9c08df18f47df53" + targets: "//src/... //third_party/utf8_range/..." - config: { name: "TCMalloc" } image: "us-docker.pkg.dev/protobuf-build/containers/test/linux/tcmalloc@sha256:bd39119d74b8a3fad4ae335d4cf5294e70384676331b7e19949459fc7a8d8328" targets: "//src/... //third_party/utf8_range/..." @@ -313,21 +316,32 @@ jobs: fail-fast: false # Don't cancel all jobs if one fails. matrix: include: - - name: MacOS + - name: MacOS Bazel os: macos-12 cache_key: macos-12 bazel: test //src/... //third_party/utf8_range/... - - name: MacOS Apple Silicon (build only) + # TODO Enable these once mac setup is working for Bazel 7 + #- name: MacOS Bazel 7 + # os: macos-12 + # cache_key: macos-12-bazel7 + # bazel: test //src/... //third_party/utf8_range/... + # bazel_version: '7.0.0' + - name: MacOS Apple Silicon (build only) Bazel os: macos-12 cache_key: macos-12-arm # Current github runners are all Intel based, so just build/compile # for Apple Silicon to detect issues there. bazel: build --cpu=darwin_arm64 //src/... //third_party/utf8_range/... - - name: Windows + - name: Windows Bazel os: windows-2022 cache_key: windows-2022 bazel: test //src/... @com_google_protobuf_examples//... --test_tag_filters=-conformance --build_tag_filters=-conformance - name: ${{ matrix.name }} Bazel + - name: Windows Bazel 7 + os: windows-2022 + cache_key: windows-2022-bazel7 + bazel: test //src/... @com_google_protobuf_examples//... --test_tag_filters=-conformance --build_tag_filters=-conformance + bazel_version: '7.0.0' + name: ${{ matrix.name }} runs-on: ${{ matrix.os }} steps: - name: Checkout pending changes @@ -340,6 +354,7 @@ jobs: credentials: ${{ secrets.GAR_SERVICE_ACCOUNT }} bazel: ${{ matrix.bazel }} bazel-cache: cpp_${{ matrix.cache_key }} + version: ${{ matrix.bazel_version || '6.3.0' }} non-linux-cmake: strategy: diff --git a/.github/workflows/test_upb.yml b/.github/workflows/test_upb.yml index e819c377c3cc4..a6d7f194189bb 100644 --- a/.github/workflows/test_upb.yml +++ b/.github/workflows/test_upb.yml @@ -17,6 +17,7 @@ jobs: fail-fast: false # Don't cancel all jobs if one fails. matrix: config: + - { name: "Bazel 7", bazel_version: "7.0.0" } - { name: "Fastbuild" } - { name: "Optimized", flags: "-c opt" } - { name: "FastTable", flags: "--//upb:fasttable_enabled=true" } @@ -37,7 +38,7 @@ jobs: - name: Run tests uses: protocolbuffers/protobuf-ci/bazel-docker@v2 with: - image: us-docker.pkg.dev/protobuf-build/containers/test/linux/sanitize@sha256:04cd765285bc52cbbf51d66c8c66d8603579cf0f19cc42df26b09d2c270541fb + image: us-docker.pkg.dev/protobuf-build/containers/test/linux/sanitize:${{ matrix.config.bazel_version || '6.3.0' }}-d07b7d649401d147e71e7182d2832cc8344f1f35 credentials: ${{ secrets.GAR_SERVICE_ACCOUNT }} bazel-cache: upb-bazel bazel: test --cxxopt=-std=c++17 --host_cxxopt=-std=c++17 //bazel/... //benchmarks/... //lua/... //protos/... //protos_generator/... //python/... //upb/... //upb_generator/... ${{ matrix.config.flags }} @@ -81,6 +82,7 @@ jobs: credentials: ${{ secrets.GAR_SERVICE_ACCOUNT }} bazel-cache: "upb-bazel-windows" bazel: test --cxxopt=/std:c++17 --host_cxxopt=/std:c++17 //upb/... //upb_generator/... //python/... //protos/... //protos_generator/... + version: 6.3.0 exclude-targets: -//python:conformance_test -//upb/reflection:def_builder_test macos: @@ -107,6 +109,7 @@ jobs: credentials: ${{ secrets.GAR_SERVICE_ACCOUNT }} bazel-cache: "upb-bazel-macos" bazel: ${{ matrix.config.bazel-command }} --cxxopt=-std=c++17 --host_cxxopt=-std=c++17 ${{ matrix.config.flags }} //bazel/... //benchmarks/... //lua/... //protos/... //protos_generator/... //python/... //upb/... //upb_generator/... + version: 6.3.0 no-python: strategy: diff --git a/ci/common.bazelrc b/ci/common.bazelrc index 12445ba717762..fd24b0a3c1f9e 100644 --- a/ci/common.bazelrc +++ b/ci/common.bazelrc @@ -35,7 +35,6 @@ build:ubsan --copt=-fno-sanitize=function --copt=-fno-sanitize=vptr build --incompatible_check_sharding_support build --incompatible_default_to_explicit_init_py build --incompatible_disable_native_android_rules -build --incompatible_disable_runtimes_filegroups build --incompatible_disable_target_provider_fields build --incompatible_disallow_empty_glob build --incompatible_dont_use_javasourceinfoprovider @@ -66,3 +65,7 @@ build --incompatible_use_host_features # --incompatible_disable_objc_library_transition # --incompatible_fail_on_unknown_attributes # --incompatible_merge_fixed_and_default_shell_env + +# TODO: migrate all dependencies from WORKSPACE to MODULE.bazel +# https://github.com/protocolbuffers/protobuf/issues/14313 +common --noenable_bzlmod \ No newline at end of file From 0a2f7757e38b07c2e40c5c885a7100e8c16eb40f Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Thu, 14 Dec 2023 18:54:05 -0800 Subject: [PATCH 027/255] Branch-free varint size calculation. On android art, compiles to: ``` int com.google.android.test.Outer.computeUInt32SizeNoTag(int) [24 bytes] 0x000024d0 mov w0, #0x160 0x000024d4 clz w1, w1 0x000024d8 add w1, w1, w1, lsl #3 0x000024dc sub w0, w0, w1 0x000024e0 lsr w0, w0, #6 0x000024e4 ret ``` versus existing: ``` int com.google.android.test.Outer.computeUInt32SizeNoTag(int) [72 bytes] 0x000022a0 and w0, w1, #0xffffff80 0x000022a4 cbnz w0, #+0xc (addr 0x22b0) 0x000022a8 mov w0, #0x1 0x000022ac b #+0x38 (addr 0x22e4) 0x000022b0 and w0, w1, #0xffffc000 0x000022b4 cbnz w0, #+0xc (addr 0x22c0) 0x000022b8 mov w0, #0x2 0x000022bc b #+0x28 (addr 0x22e4) 0x000022c0 and w0, w1, #0xffe00000 0x000022c4 cbnz w0, #+0xc (addr 0x22d0) 0x000022c8 mov w0, #0x3 0x000022cc b #+0x18 (addr 0x22e4) 0x000022d0 mov w2, #0x5 0x000022d4 mov w0, #0x4 0x000022d8 and w1, w1, #0xf0000000 0x000022dc cmp w1, #0x0 (0) 0x000022e0 csel w0, w2, w0, ne 0x000022e4 ret ``` PiperOrigin-RevId: 591113652 --- .../google/protobuf/CodedOutputStream.java | 94 ++++++++++--------- .../protobuf/CodedOutputStreamTest.java | 75 +++++++++++++++ 2 files changed, 125 insertions(+), 44 deletions(-) diff --git a/java/core/src/main/java/com/google/protobuf/CodedOutputStream.java b/java/core/src/main/java/com/google/protobuf/CodedOutputStream.java index 37bb44a057804..cd8127bd63f4a 100644 --- a/java/core/src/main/java/com/google/protobuf/CodedOutputStream.java +++ b/java/core/src/main/java/com/google/protobuf/CodedOutputStream.java @@ -40,7 +40,9 @@ public abstract class CodedOutputStream extends ByteOutput { /** Used to adapt to the experimental {@link Writer} interface. */ CodedOutputStreamWriter wrapper; - /** @deprecated Use {@link #computeFixed32SizeNoTag(int)} instead. */ + /** + * @deprecated Use {@link #computeFixed32SizeNoTag(int)} instead. + */ @Deprecated public static final int LITTLE_ENDIAN_32_SIZE = FIXED32_SIZE; /** The buffer size used in {@link #newInstance(OutputStream)}. */ @@ -669,9 +671,8 @@ public static int computeRawMessageSetExtensionSize( } /** - * Compute the number of bytes that would be needed to encode a lazily parsed MessageSet - * extension field to the stream. For historical reasons, the wire format differs from normal - * fields. + * Compute the number of bytes that would be needed to encode a lazily parsed MessageSet extension + * field to the stream. For historical reasons, the wire format differs from normal fields. */ public static int computeLazyFieldMessageSetExtensionSize( final int fieldNumber, final LazyFieldLite value) { @@ -692,29 +693,52 @@ public static int computeTagSize(final int fieldNumber) { * tag. */ public static int computeInt32SizeNoTag(final int value) { - if (value >= 0) { - return computeUInt32SizeNoTag(value); - } else { - // Must sign-extend. - return MAX_VARINT_SIZE; - } + return computeUInt64SizeNoTag((long) value); } /** Compute the number of bytes that would be needed to encode a {@code uint32} field. */ public static int computeUInt32SizeNoTag(final int value) { - if ((value & (~0 << 7)) == 0) { - return 1; - } - if ((value & (~0 << 14)) == 0) { - return 2; - } - if ((value & (~0 << 21)) == 0) { - return 3; - } - if ((value & (~0 << 28)) == 0) { - return 4; - } - return 5; + /* + This code is ported from the C++ varint implementation. + Implementation notes: + + To calcuate varint size, we want to count the number of 7 bit chunks required. Rather than using + division by 7 to accomplish this, we use multiplication by 9/64. This has a number of important + properties: + * It's roughly 1/7.111111. This makes the 0 bits set case have the same value as the 7 bits set + case, so offsetting by 1 gives us the correct value we want for integers up to 448 bits. + * Multiplying by 9 is special. x * 9 = x << 3 + x, and so this multiplication can be done by a + single shifted add on arm (add w0, w0, w0, lsl #3), or a single lea instruction + (leal (%rax,%rax,8), %eax)) on x86. + * Dividing by 64 is a 6 bit right shift. + + An explicit non-sign-extended right shift is used instead of the more obvious '/ 64' because + that actually produces worse code on android arm64 at time of authoring because of sign + extension. Rather than + lsr w0, w0, #6 + It would emit: + add w16, w0, #0x3f (63) + cmp w0, #0x0 (0) + csel w0, w16, w0, lt + asr w0, w0, #6 + + Summarized: + floor(((Integer.SIZE - clz) / 7.1111) + 1 + ((Integer.SIZE - clz) * 9) / 64 + 1 + (((Integer.SIZE - clz) * 9) >>> 6) + 1 + ((Integer.SIZE - clz) * 9 + (1 << 6)) >>> 6 + (Integer.SIZE * 9 + (1 << 6) - clz * 9) >>> 6 + (352 - clz * 9) >>> 6 + on arm: + (352 - clz - (clz << 3)) >>> 6 + on x86: + (352 - lea(clz, clz, 8)) >>> 6 + + If you make changes here, please validate their compiled output on different architectures and + runtimes. + */ + int clz = Integer.numberOfLeadingZeros(value); + return ((Integer.SIZE * 9 + (1 << 6)) - (clz * 9)) >>> 6; } /** Compute the number of bytes that would be needed to encode an {@code sint32} field. */ @@ -745,27 +769,9 @@ public static int computeInt64SizeNoTag(final long value) { * tag. */ public static int computeUInt64SizeNoTag(long value) { - // handle two popular special cases up front ... - if ((value & (~0L << 7)) == 0L) { - return 1; - } - if (value < 0L) { - return 10; - } - // ... leaving us with 8 remaining, which we can divide and conquer - int n = 2; - if ((value & (~0L << 35)) != 0L) { - n += 4; - value >>>= 28; - } - if ((value & (~0L << 21)) != 0L) { - n += 2; - value >>>= 14; - } - if ((value & (~0L << 14)) != 0L) { - n += 1; - } - return n; + int clz = Long.numberOfLeadingZeros(value); + // See computeUInt32SizeNoTag for explanation + return ((Long.SIZE * 9 + (1 << 6)) - (clz * 9)) >>> 6; } /** Compute the number of bytes that would be needed to encode an {@code sint64} field. */ diff --git a/java/core/src/test/java/com/google/protobuf/CodedOutputStreamTest.java b/java/core/src/test/java/com/google/protobuf/CodedOutputStreamTest.java index 3007c83a1f99d..51e66b9759ff4 100644 --- a/java/core/src/test/java/com/google/protobuf/CodedOutputStreamTest.java +++ b/java/core/src/test/java/com/google/protobuf/CodedOutputStreamTest.java @@ -327,6 +327,81 @@ public void testEncodeZigZag() throws Exception { .isEqualTo(-75123905439571256L); } + @Test + public void computeIntSize() { + assertThat(CodedOutputStream.computeUInt32SizeNoTag(0)).isEqualTo(1); + assertThat(CodedOutputStream.computeUInt64SizeNoTag(0)).isEqualTo(1); + int i; + for (i = 0; i < 7; i++) { + assertThat(CodedOutputStream.computeInt32SizeNoTag(1 << i)).isEqualTo(1); + assertThat(CodedOutputStream.computeUInt32SizeNoTag(1 << i)).isEqualTo(1); + assertThat(CodedOutputStream.computeUInt64SizeNoTag(1L << i)).isEqualTo(1); + } + for (; i < 14; i++) { + assertThat(CodedOutputStream.computeInt32SizeNoTag(1 << i)).isEqualTo(2); + assertThat(CodedOutputStream.computeUInt32SizeNoTag(1 << i)).isEqualTo(2); + assertThat(CodedOutputStream.computeUInt64SizeNoTag(1L << i)).isEqualTo(2); + } + for (; i < 21; i++) { + assertThat(CodedOutputStream.computeInt32SizeNoTag(1 << i)).isEqualTo(3); + assertThat(CodedOutputStream.computeUInt32SizeNoTag(1 << i)).isEqualTo(3); + assertThat(CodedOutputStream.computeUInt64SizeNoTag(1L << i)).isEqualTo(3); + } + for (; i < 28; i++) { + assertThat(CodedOutputStream.computeInt32SizeNoTag(1 << i)).isEqualTo(4); + assertThat(CodedOutputStream.computeUInt32SizeNoTag(1 << i)).isEqualTo(4); + assertThat(CodedOutputStream.computeUInt64SizeNoTag(1L << i)).isEqualTo(4); + } + for (; i < 31; i++) { + assertThat(CodedOutputStream.computeInt32SizeNoTag(1 << i)).isEqualTo(5); + assertThat(CodedOutputStream.computeUInt32SizeNoTag(1 << i)).isEqualTo(5); + assertThat(CodedOutputStream.computeUInt64SizeNoTag(1L << i)).isEqualTo(5); + } + for (; i < 32; i++) { + assertThat(CodedOutputStream.computeInt32SizeNoTag(1 << i)).isEqualTo(10); + assertThat(CodedOutputStream.computeUInt32SizeNoTag(1 << i)).isEqualTo(5); + assertThat(CodedOutputStream.computeUInt64SizeNoTag(1L << i)).isEqualTo(5); + } + for (; i < 35; i++) { + assertThat(CodedOutputStream.computeUInt64SizeNoTag(1L << i)).isEqualTo(5); + } + for (; i < 42; i++) { + assertThat(CodedOutputStream.computeUInt64SizeNoTag(1L << i)).isEqualTo(6); + } + for (; i < 49; i++) { + assertThat(CodedOutputStream.computeUInt64SizeNoTag(1L << i)).isEqualTo(7); + } + for (; i < 56; i++) { + assertThat(CodedOutputStream.computeUInt64SizeNoTag(1L << i)).isEqualTo(8); + } + for (; i < 63; i++) { + assertThat(CodedOutputStream.computeUInt64SizeNoTag(1L << i)).isEqualTo(9); + } + } + + @Test + public void computeTagSize() { + assertThat(CodedOutputStream.computeTagSize(0)).isEqualTo(1); + int i; + for (i = 0; i < 4; i++) { + assertThat(CodedOutputStream.computeTagSize(1 << i)).isEqualTo(1); + } + for (; i < 11; i++) { + assertThat(CodedOutputStream.computeTagSize(1 << i)).isEqualTo(2); + } + for (; i < 18; i++) { + assertThat(CodedOutputStream.computeTagSize(1 << i)).isEqualTo(3); + } + for (; i < 25; i++) { + assertThat(CodedOutputStream.computeTagSize(1 << i)).isEqualTo(4); + } + for (; i < 29; i++) { + assertThat(CodedOutputStream.computeTagSize(1 << i)).isEqualTo(5); + } + // Invalid tags + assertThat(CodedOutputStream.computeTagSize((1 << 30) + 1)).isEqualTo(1); + } + /** Tests writing a whole message with every field type. */ @Test public void testWriteWholeMessage() throws Exception { From 220415ddfb59d16c9309e5bae37bed3be0943a25 Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Thu, 14 Dec 2023 19:17:14 -0800 Subject: [PATCH 028/255] Swap order of masks when assigning bytes to byte[] elements. Masking a byte by 0xFF does nothing, and the optimizer can see that. I don't think these 0xFF masks do anything in java... but they're in a lot of places so if we remove them entirely it'll be in another CL. Before (android): ``` ldr w3, [x1, #12] and w4, w2, #0x7f orr w4, w4, #0x80 add w5, w3, #0x1 (1) sxtb w4, w4 ``` after: ``` ldr w3, [x1, #12] orr w4, w2, #0x80 add w5, w3, #0x1 (1) sxtb w4, w4 ``` PiperOrigin-RevId: 591117756 --- .../google/protobuf/CodedOutputStream.java | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/java/core/src/main/java/com/google/protobuf/CodedOutputStream.java b/java/core/src/main/java/com/google/protobuf/CodedOutputStream.java index cd8127bd63f4a..2c28536f47ea9 100644 --- a/java/core/src/main/java/com/google/protobuf/CodedOutputStream.java +++ b/java/core/src/main/java/com/google/protobuf/CodedOutputStream.java @@ -1332,7 +1332,7 @@ public final void writeUInt32NoTag(int value) throws IOException { buffer[position++] = (byte) value; return; } else { - buffer[position++] = (byte) ((value & 0x7F) | 0x80); + buffer[position++] = (byte) ((value | 0x80) & 0xFF); value >>>= 7; } } @@ -1363,7 +1363,7 @@ public final void writeUInt64NoTag(long value) throws IOException { UnsafeUtil.putByte(buffer, position++, (byte) value); return; } else { - UnsafeUtil.putByte(buffer, position++, (byte) (((int) value & 0x7F) | 0x80)); + UnsafeUtil.putByte(buffer, position++, (byte) (((int) value | 0x80) & 0xFF)); value >>>= 7; } } @@ -1374,7 +1374,7 @@ public final void writeUInt64NoTag(long value) throws IOException { buffer[position++] = (byte) value; return; } else { - buffer[position++] = (byte) (((int) value & 0x7F) | 0x80); + buffer[position++] = (byte) (((int) value | 0x80) & 0xFF); value >>>= 7; } } @@ -1690,7 +1690,7 @@ public void writeUInt32NoTag(int value) throws IOException { buffer.put((byte) value); return; } else { - buffer.put((byte) ((value & 0x7F) | 0x80)); + buffer.put((byte) ((value | 0x80) & 0xFF)); value >>>= 7; } } @@ -1716,7 +1716,7 @@ public void writeUInt64NoTag(long value) throws IOException { buffer.put((byte) value); return; } else { - buffer.put((byte) (((int) value & 0x7F) | 0x80)); + buffer.put((byte) (((int) value | 0x80) & 0xFF)); value >>>= 7; } } @@ -2021,7 +2021,7 @@ public void writeUInt32NoTag(int value) throws IOException { UnsafeUtil.putByte(position++, (byte) value); return; } else { - UnsafeUtil.putByte(position++, (byte) ((value & 0x7F) | 0x80)); + UnsafeUtil.putByte(position++, (byte) ((value | 0x80) & 0xFF)); value >>>= 7; } } @@ -2031,7 +2031,7 @@ public void writeUInt32NoTag(int value) throws IOException { UnsafeUtil.putByte(position++, (byte) value); return; } else { - UnsafeUtil.putByte(position++, (byte) ((value & 0x7F) | 0x80)); + UnsafeUtil.putByte(position++, (byte) ((value | 0x80) & 0xFF)); value >>>= 7; } } @@ -2055,7 +2055,7 @@ public void writeUInt64NoTag(long value) throws IOException { UnsafeUtil.putByte(position++, (byte) value); return; } else { - UnsafeUtil.putByte(position++, (byte) (((int) value & 0x7F) | 0x80)); + UnsafeUtil.putByte(position++, (byte) (((int) value | 0x80) & 0xFF)); value >>>= 7; } } @@ -2065,7 +2065,7 @@ public void writeUInt64NoTag(long value) throws IOException { UnsafeUtil.putByte(position++, (byte) value); return; } else { - UnsafeUtil.putByte(position++, (byte) (((int) value & 0x7F) | 0x80)); + UnsafeUtil.putByte(position++, (byte) (((int) value | 0x80) & 0xFF)); value >>>= 7; } } @@ -2265,7 +2265,7 @@ final void bufferUInt32NoTag(int value) { UnsafeUtil.putByte(buffer, position++, (byte) value); break; } else { - UnsafeUtil.putByte(buffer, position++, (byte) ((value & 0x7F) | 0x80)); + UnsafeUtil.putByte(buffer, position++, (byte) ((value | 0x80) & 0xFF)); value >>>= 7; } } @@ -2278,7 +2278,7 @@ final void bufferUInt32NoTag(int value) { totalBytesWritten++; return; } else { - buffer[position++] = (byte) ((value & 0x7F) | 0x80); + buffer[position++] = (byte) ((value | 0x80) & 0xFF); totalBytesWritten++; value >>>= 7; } @@ -2298,7 +2298,7 @@ final void bufferUInt64NoTag(long value) { UnsafeUtil.putByte(buffer, position++, (byte) value); break; } else { - UnsafeUtil.putByte(buffer, position++, (byte) (((int) value & 0x7F) | 0x80)); + UnsafeUtil.putByte(buffer, position++, (byte) (((int) value | 0x80) & 0xFF)); value >>>= 7; } } @@ -2311,7 +2311,7 @@ final void bufferUInt64NoTag(long value) { totalBytesWritten++; return; } else { - buffer[position++] = (byte) (((int) value & 0x7F) | 0x80); + buffer[position++] = (byte) (((int) value | 0x80) & 0xFF); totalBytesWritten++; value >>>= 7; } From b10d3f93b689a0b39fbc861d8d367491b4442a4f Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Thu, 14 Dec 2023 22:16:21 -0800 Subject: [PATCH 029/255] Avoid interface calls in hot loop Before, every charAt would emit (on android): ``` 0x00002104 adrp x17, #+0x1000 (addr 0x3000) 0x00002108 ldr w17, [x17, #20] 0x0000210c ldr x0, [x0, #128] 0x00002110 ldr x0, [x0, #328] 0x00002114 ldr lr, [x0, #24] 0x00002118 blr lr <-- Call into String.charAt(int) ``` Now, it emits the inlined implementation of charAt (branch is for possibly compressed strings): ``` 0x000020b4 ldur w16, [x4, #-8] 0x000020b8 tbnz w16, #0, #+0xc (addr 0x20c4) 0x000020bc ldrb w4, [x4, x0] 0x000020c0 b #+0x8 (addr 0x20c8) 0x000020c4 ldrh w4, [x4, x0, lsl #1] ``` PiperOrigin-RevId: 591147406 --- .../main/java/com/google/protobuf/Utf8.java | 40 +++++++++---------- .../java/com/google/protobuf/Utf8Test.java | 2 +- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/java/core/src/main/java/com/google/protobuf/Utf8.java b/java/core/src/main/java/com/google/protobuf/Utf8.java index f71820ef9f172..2eace98471789 100644 --- a/java/core/src/main/java/com/google/protobuf/Utf8.java +++ b/java/core/src/main/java/com/google/protobuf/Utf8.java @@ -214,24 +214,24 @@ static class UnpairedSurrogateException extends IllegalArgumentException { * @throws IllegalArgumentException if {@code sequence} contains ill-formed UTF-16 (unpaired * surrogates) */ - static int encodedLength(CharSequence sequence) { + static int encodedLength(String string) { // Warning to maintainers: this implementation is highly optimized. - int utf16Length = sequence.length(); + int utf16Length = string.length(); int utf8Length = utf16Length; int i = 0; // This loop optimizes for pure ASCII. - while (i < utf16Length && sequence.charAt(i) < 0x80) { + while (i < utf16Length && string.charAt(i) < 0x80) { i++; } // This loop optimizes for chars less than 0x800. for (; i < utf16Length; i++) { - char c = sequence.charAt(i); + char c = string.charAt(i); if (c < 0x800) { utf8Length += ((0x7f - c) >>> 31); // branch free! } else { - utf8Length += encodedLengthGeneral(sequence, i); + utf8Length += encodedLengthGeneral(string, i); break; } } @@ -244,11 +244,11 @@ static int encodedLength(CharSequence sequence) { return utf8Length; } - private static int encodedLengthGeneral(CharSequence sequence, int start) { - int utf16Length = sequence.length(); + private static int encodedLengthGeneral(String string, int start) { + int utf16Length = string.length(); int utf8Length = 0; for (int i = start; i < utf16Length; i++) { - char c = sequence.charAt(i); + char c = string.charAt(i); if (c < 0x800) { utf8Length += (0x7f - c) >>> 31; // branch free! } else { @@ -256,7 +256,7 @@ private static int encodedLengthGeneral(CharSequence sequence, int start) { // jdk7+: if (Character.isSurrogate(c)) { if (Character.MIN_SURROGATE <= c && c <= Character.MAX_SURROGATE) { // Check that we have a well-formed surrogate pair. - int cp = Character.codePointAt(sequence, i); + int cp = Character.codePointAt(string, i); if (cp < MIN_SUPPLEMENTARY_CODE_POINT) { throw new UnpairedSurrogateException(i, utf16Length); } @@ -267,7 +267,7 @@ private static int encodedLengthGeneral(CharSequence sequence, int start) { return utf8Length; } - static int encode(CharSequence in, byte[] out, int offset, int length) { + static int encode(String in, byte[] out, int offset, int length) { return processor.encodeUtf8(in, out, offset, length); } // End Guava UTF-8 methods. @@ -326,9 +326,9 @@ static String decodeUtf8(byte[] bytes, int index, int size) * * @param in the source string to be encoded * @param out the target buffer to receive the encoded string. - * @see Utf8#encode(CharSequence, byte[], int, int) + * @see Utf8#encode(String, byte[], int, int) */ - static void encodeUtf8(CharSequence in, ByteBuffer out) { + static void encodeUtf8(String in, ByteBuffer out) { processor.encodeUtf8(in, out); } @@ -724,7 +724,7 @@ final String decodeUtf8Default(ByteBuffer buffer, int index, int size) * {@code bytes.length - offset} * @return the new offset, equivalent to {@code offset + Utf8.encodedLength(sequence)} */ - abstract int encodeUtf8(CharSequence in, byte[] out, int offset, int length); + abstract int encodeUtf8(String in, byte[] out, int offset, int length); /** * Encodes an input character sequence ({@code in}) to UTF-8 in the target buffer ({@code out}). @@ -743,7 +743,7 @@ final String decodeUtf8Default(ByteBuffer buffer, int index, int size) * @throws ArrayIndexOutOfBoundsException if {@code in} encoded in UTF-8 is longer than {@code * out.remaining()} */ - final void encodeUtf8(CharSequence in, ByteBuffer out) { + final void encodeUtf8(String in, ByteBuffer out) { if (out.hasArray()) { final int offset = out.arrayOffset(); int endIndex = Utf8.encode(in, out.array(), offset + out.position(), out.remaining()); @@ -756,13 +756,13 @@ final void encodeUtf8(CharSequence in, ByteBuffer out) { } /** Encodes the input character sequence to a direct {@link ByteBuffer} instance. */ - abstract void encodeUtf8Direct(CharSequence in, ByteBuffer out); + abstract void encodeUtf8Direct(String in, ByteBuffer out); /** * Encodes the input character sequence to a {@link ByteBuffer} instance using the {@link * ByteBuffer} API, rather than potentially faster approaches. */ - final void encodeUtf8Default(CharSequence in, ByteBuffer out) { + final void encodeUtf8Default(String in, ByteBuffer out) { final int inLength = in.length(); int outIx = out.position(); int inIx = 0; @@ -1013,7 +1013,7 @@ String decodeUtf8Direct(ByteBuffer buffer, int index, int size) } @Override - int encodeUtf8(CharSequence in, byte[] out, int offset, int length) { + int encodeUtf8(String in, byte[] out, int offset, int length) { int utf16Length = in.length(); int j = offset; int i = 0; @@ -1065,7 +1065,7 @@ int encodeUtf8(CharSequence in, byte[] out, int offset, int length) { } @Override - void encodeUtf8Direct(CharSequence in, ByteBuffer out) { + void encodeUtf8Direct(String in, ByteBuffer out) { // For safe processing, we have to use the ByteBuffer API. encodeUtf8Default(in, out); } @@ -1442,7 +1442,7 @@ String decodeUtf8Direct(ByteBuffer buffer, int index, int size) } @Override - int encodeUtf8(final CharSequence in, final byte[] out, final int offset, final int length) { + int encodeUtf8(final String in, final byte[] out, final int offset, final int length) { long outIx = offset; final long outLimit = outIx + length; final int inLimit = in.length(); @@ -1503,7 +1503,7 @@ int encodeUtf8(final CharSequence in, final byte[] out, final int offset, final } @Override - void encodeUtf8Direct(CharSequence in, ByteBuffer out) { + void encodeUtf8Direct(String in, ByteBuffer out) { final long address = addressOffset(out); long outIx = address + out.position(); final long outLimit = address + out.limit(); diff --git a/java/core/src/test/java/com/google/protobuf/Utf8Test.java b/java/core/src/test/java/com/google/protobuf/Utf8Test.java index 986702de431ae..2a53e8204fd54 100644 --- a/java/core/src/test/java/com/google/protobuf/Utf8Test.java +++ b/java/core/src/test/java/com/google/protobuf/Utf8Test.java @@ -194,7 +194,7 @@ private void assertEncoding_insufficientSpace(String message) { private static byte[] encodeToByteArray(String message, int length, Utf8.Processor processor) { byte[] output = new byte[length]; - processor.encodeUtf8(message, output, 0, output.length); + int unused = processor.encodeUtf8(message, output, 0, output.length); return output; } From 9f96118e1e06fd9bfce4c0e48ee0704f4fd83f23 Mon Sep 17 00:00:00 2001 From: Sandy Zhang Date: Fri, 15 Dec 2023 10:07:43 -0800 Subject: [PATCH 030/255] Pin bundler version to 2.4.22 for Ruby 2.7 support. Latest bundler 2.5.0 release results in the following error: `The last version of bundler (>= 0) to support your Ruby & RubyGems was 2.4.22. Try installing it with gem install bundler -v 2.4.22 bundler requires Ruby version >= 3.0.0. The current ruby version is 2.7.3.183.` PiperOrigin-RevId: 591288515 --- .github/workflows/test_ruby.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test_ruby.yml b/.github/workflows/test_ruby.yml index 4f3707b08a54b..80b4db9c9a0bd 100644 --- a/.github/workflows/test_ruby.yml +++ b/.github/workflows/test_ruby.yml @@ -67,9 +67,10 @@ jobs: with: image: i386/ruby:2.7.3-buster credentials: ${{ secrets.GAR_SERVICE_ACCOUNT }} + # Pin to Ruby 2.7 compatible bundler version. command: >- /bin/bash -cex ' - gem install bundler; + gem install bundler -v 2.4.22; cd /workspace/ruby; bundle; PROTOC=/workspace/${{ steps.cross-compile.outputs.protoc }} rake; @@ -98,9 +99,10 @@ jobs: with: image: arm64v8/ruby:2.7.3-buster credentials: ${{ secrets.GAR_SERVICE_ACCOUNT }} + # Pin to Ruby 2.7 compatible bundler version. command: >- /bin/bash -cex ' - gem install bundler; + gem install bundler -v 2.4.22; cd /workspace/ruby; bundle; PROTOC=/workspace/${{ steps.cross-compile.outputs.protoc }} rake; From fa62c920716804a576ce388e6894fa15209df41a Mon Sep 17 00:00:00 2001 From: Eric Salo Date: Fri, 15 Dec 2023 10:42:15 -0800 Subject: [PATCH 031/255] upb: stop generating hazzers for repeated fields PiperOrigin-RevId: 591299107 --- .../stage0/google/protobuf/descriptor.upb.h | 200 ------------------ upb_generator/protoc-gen-upb.cc | 13 -- .../google/protobuf/compiler/plugin.upb.h | 20 -- 3 files changed, 233 deletions(-) diff --git a/upb/reflection/stage0/google/protobuf/descriptor.upb.h b/upb/reflection/stage0/google/protobuf/descriptor.upb.h index 9e3bc66d1ddf6..76ac5db89a456 100644 --- a/upb/reflection/stage0/google/protobuf/descriptor.upb.h +++ b/upb/reflection/stage0/google/protobuf/descriptor.upb.h @@ -300,11 +300,6 @@ UPB_INLINE upb_Array* _google_protobuf_FileDescriptorSet_file_mutable_upb_array( } return arr; } -UPB_INLINE bool google_protobuf_FileDescriptorSet_has_file(const google_protobuf_FileDescriptorSet* msg) { - size_t size; - google_protobuf_FileDescriptorSet_file(msg, &size); - return size != 0; -} UPB_INLINE google_protobuf_FileDescriptorProto** google_protobuf_FileDescriptorSet_mutable_file(google_protobuf_FileDescriptorSet* msg, size_t* size) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorSet_msg_init(), 1); @@ -430,11 +425,6 @@ UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_dependency_mutable_up } return arr; } -UPB_INLINE bool google_protobuf_FileDescriptorProto_has_dependency(const google_protobuf_FileDescriptorProto* msg) { - size_t size; - google_protobuf_FileDescriptorProto_dependency(msg, &size); - return size != 0; -} UPB_INLINE void google_protobuf_FileDescriptorProto_clear_message_type(google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 4); _upb_Message_ClearNonExtensionField(msg, &field); @@ -467,11 +457,6 @@ UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_message_type_mutable_ } return arr; } -UPB_INLINE bool google_protobuf_FileDescriptorProto_has_message_type(const google_protobuf_FileDescriptorProto* msg) { - size_t size; - google_protobuf_FileDescriptorProto_message_type(msg, &size); - return size != 0; -} UPB_INLINE void google_protobuf_FileDescriptorProto_clear_enum_type(google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 5); _upb_Message_ClearNonExtensionField(msg, &field); @@ -504,11 +489,6 @@ UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_enum_type_mutable_upb } return arr; } -UPB_INLINE bool google_protobuf_FileDescriptorProto_has_enum_type(const google_protobuf_FileDescriptorProto* msg) { - size_t size; - google_protobuf_FileDescriptorProto_enum_type(msg, &size); - return size != 0; -} UPB_INLINE void google_protobuf_FileDescriptorProto_clear_service(google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 6); _upb_Message_ClearNonExtensionField(msg, &field); @@ -541,11 +521,6 @@ UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_service_mutable_upb_a } return arr; } -UPB_INLINE bool google_protobuf_FileDescriptorProto_has_service(const google_protobuf_FileDescriptorProto* msg) { - size_t size; - google_protobuf_FileDescriptorProto_service(msg, &size); - return size != 0; -} UPB_INLINE void google_protobuf_FileDescriptorProto_clear_extension(google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 7); _upb_Message_ClearNonExtensionField(msg, &field); @@ -578,11 +553,6 @@ UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_extension_mutable_upb } return arr; } -UPB_INLINE bool google_protobuf_FileDescriptorProto_has_extension(const google_protobuf_FileDescriptorProto* msg) { - size_t size; - google_protobuf_FileDescriptorProto_extension(msg, &size); - return size != 0; -} UPB_INLINE void google_protobuf_FileDescriptorProto_clear_options(google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 8); _upb_Message_ClearNonExtensionField(msg, &field); @@ -645,11 +615,6 @@ UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_public_dependency_mut } return arr; } -UPB_INLINE bool google_protobuf_FileDescriptorProto_has_public_dependency(const google_protobuf_FileDescriptorProto* msg) { - size_t size; - google_protobuf_FileDescriptorProto_public_dependency(msg, &size); - return size != 0; -} UPB_INLINE void google_protobuf_FileDescriptorProto_clear_weak_dependency(google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 11); _upb_Message_ClearNonExtensionField(msg, &field); @@ -682,11 +647,6 @@ UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_weak_dependency_mutab } return arr; } -UPB_INLINE bool google_protobuf_FileDescriptorProto_has_weak_dependency(const google_protobuf_FileDescriptorProto* msg) { - size_t size; - google_protobuf_FileDescriptorProto_weak_dependency(msg, &size); - return size != 0; -} UPB_INLINE void google_protobuf_FileDescriptorProto_clear_syntax(google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 12); _upb_Message_ClearNonExtensionField(msg, &field); @@ -1017,11 +977,6 @@ UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_field_mutable_upb_array(c } return arr; } -UPB_INLINE bool google_protobuf_DescriptorProto_has_field(const google_protobuf_DescriptorProto* msg) { - size_t size; - google_protobuf_DescriptorProto_field(msg, &size); - return size != 0; -} UPB_INLINE void google_protobuf_DescriptorProto_clear_nested_type(google_protobuf_DescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 3); _upb_Message_ClearNonExtensionField(msg, &field); @@ -1054,11 +1009,6 @@ UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_nested_type_mutable_upb_a } return arr; } -UPB_INLINE bool google_protobuf_DescriptorProto_has_nested_type(const google_protobuf_DescriptorProto* msg) { - size_t size; - google_protobuf_DescriptorProto_nested_type(msg, &size); - return size != 0; -} UPB_INLINE void google_protobuf_DescriptorProto_clear_enum_type(google_protobuf_DescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 4); _upb_Message_ClearNonExtensionField(msg, &field); @@ -1091,11 +1041,6 @@ UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_enum_type_mutable_upb_arr } return arr; } -UPB_INLINE bool google_protobuf_DescriptorProto_has_enum_type(const google_protobuf_DescriptorProto* msg) { - size_t size; - google_protobuf_DescriptorProto_enum_type(msg, &size); - return size != 0; -} UPB_INLINE void google_protobuf_DescriptorProto_clear_extension_range(google_protobuf_DescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 5); _upb_Message_ClearNonExtensionField(msg, &field); @@ -1128,11 +1073,6 @@ UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_extension_range_mutable_u } return arr; } -UPB_INLINE bool google_protobuf_DescriptorProto_has_extension_range(const google_protobuf_DescriptorProto* msg) { - size_t size; - google_protobuf_DescriptorProto_extension_range(msg, &size); - return size != 0; -} UPB_INLINE void google_protobuf_DescriptorProto_clear_extension(google_protobuf_DescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 6); _upb_Message_ClearNonExtensionField(msg, &field); @@ -1165,11 +1105,6 @@ UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_extension_mutable_upb_arr } return arr; } -UPB_INLINE bool google_protobuf_DescriptorProto_has_extension(const google_protobuf_DescriptorProto* msg) { - size_t size; - google_protobuf_DescriptorProto_extension(msg, &size); - return size != 0; -} UPB_INLINE void google_protobuf_DescriptorProto_clear_options(google_protobuf_DescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 7); _upb_Message_ClearNonExtensionField(msg, &field); @@ -1217,11 +1152,6 @@ UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_oneof_decl_mutable_upb_ar } return arr; } -UPB_INLINE bool google_protobuf_DescriptorProto_has_oneof_decl(const google_protobuf_DescriptorProto* msg) { - size_t size; - google_protobuf_DescriptorProto_oneof_decl(msg, &size); - return size != 0; -} UPB_INLINE void google_protobuf_DescriptorProto_clear_reserved_range(google_protobuf_DescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 9); _upb_Message_ClearNonExtensionField(msg, &field); @@ -1254,11 +1184,6 @@ UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_reserved_range_mutable_up } return arr; } -UPB_INLINE bool google_protobuf_DescriptorProto_has_reserved_range(const google_protobuf_DescriptorProto* msg) { - size_t size; - google_protobuf_DescriptorProto_reserved_range(msg, &size); - return size != 0; -} UPB_INLINE void google_protobuf_DescriptorProto_clear_reserved_name(google_protobuf_DescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 10); _upb_Message_ClearNonExtensionField(msg, &field); @@ -1291,11 +1216,6 @@ UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_reserved_name_mutable_upb } return arr; } -UPB_INLINE bool google_protobuf_DescriptorProto_has_reserved_name(const google_protobuf_DescriptorProto* msg) { - size_t size; - google_protobuf_DescriptorProto_reserved_name(msg, &size); - return size != 0; -} UPB_INLINE void google_protobuf_DescriptorProto_set_name(google_protobuf_DescriptorProto *msg, upb_StringView value) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 1); @@ -1764,11 +1684,6 @@ UPB_INLINE upb_Array* _google_protobuf_ExtensionRangeOptions_declaration_mutable } return arr; } -UPB_INLINE bool google_protobuf_ExtensionRangeOptions_has_declaration(const google_protobuf_ExtensionRangeOptions* msg) { - size_t size; - google_protobuf_ExtensionRangeOptions_declaration(msg, &size); - return size != 0; -} UPB_INLINE void google_protobuf_ExtensionRangeOptions_clear_verification(google_protobuf_ExtensionRangeOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ExtensionRangeOptions_msg_init(), 3); _upb_Message_ClearNonExtensionField(msg, &field); @@ -1831,11 +1746,6 @@ UPB_INLINE upb_Array* _google_protobuf_ExtensionRangeOptions_uninterpreted_optio } return arr; } -UPB_INLINE bool google_protobuf_ExtensionRangeOptions_has_uninterpreted_option(const google_protobuf_ExtensionRangeOptions* msg) { - size_t size; - google_protobuf_ExtensionRangeOptions_uninterpreted_option(msg, &size); - return size != 0; -} UPB_INLINE google_protobuf_ExtensionRangeOptions_Declaration** google_protobuf_ExtensionRangeOptions_mutable_declaration(google_protobuf_ExtensionRangeOptions* msg, size_t* size) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ExtensionRangeOptions_msg_init(), 2); @@ -2457,11 +2367,6 @@ UPB_INLINE upb_Array* _google_protobuf_EnumDescriptorProto_value_mutable_upb_arr } return arr; } -UPB_INLINE bool google_protobuf_EnumDescriptorProto_has_value(const google_protobuf_EnumDescriptorProto* msg) { - size_t size; - google_protobuf_EnumDescriptorProto_value(msg, &size); - return size != 0; -} UPB_INLINE void google_protobuf_EnumDescriptorProto_clear_options(google_protobuf_EnumDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumDescriptorProto_msg_init(), 3); _upb_Message_ClearNonExtensionField(msg, &field); @@ -2509,11 +2414,6 @@ UPB_INLINE upb_Array* _google_protobuf_EnumDescriptorProto_reserved_range_mutabl } return arr; } -UPB_INLINE bool google_protobuf_EnumDescriptorProto_has_reserved_range(const google_protobuf_EnumDescriptorProto* msg) { - size_t size; - google_protobuf_EnumDescriptorProto_reserved_range(msg, &size); - return size != 0; -} UPB_INLINE void google_protobuf_EnumDescriptorProto_clear_reserved_name(google_protobuf_EnumDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumDescriptorProto_msg_init(), 5); _upb_Message_ClearNonExtensionField(msg, &field); @@ -2546,11 +2446,6 @@ UPB_INLINE upb_Array* _google_protobuf_EnumDescriptorProto_reserved_name_mutable } return arr; } -UPB_INLINE bool google_protobuf_EnumDescriptorProto_has_reserved_name(const google_protobuf_EnumDescriptorProto* msg) { - size_t size; - google_protobuf_EnumDescriptorProto_reserved_name(msg, &size); - return size != 0; -} UPB_INLINE void google_protobuf_EnumDescriptorProto_set_name(google_protobuf_EnumDescriptorProto *msg, upb_StringView value) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumDescriptorProto_msg_init(), 1); @@ -2904,11 +2799,6 @@ UPB_INLINE upb_Array* _google_protobuf_ServiceDescriptorProto_method_mutable_upb } return arr; } -UPB_INLINE bool google_protobuf_ServiceDescriptorProto_has_method(const google_protobuf_ServiceDescriptorProto* msg) { - size_t size; - google_protobuf_ServiceDescriptorProto_method(msg, &size); - return size != 0; -} UPB_INLINE void google_protobuf_ServiceDescriptorProto_clear_options(google_protobuf_ServiceDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ServiceDescriptorProto_msg_init(), 3); _upb_Message_ClearNonExtensionField(msg, &field); @@ -3509,11 +3399,6 @@ UPB_INLINE upb_Array* _google_protobuf_FileOptions_uninterpreted_option_mutable_ } return arr; } -UPB_INLINE bool google_protobuf_FileOptions_has_uninterpreted_option(const google_protobuf_FileOptions* msg) { - size_t size; - google_protobuf_FileOptions_uninterpreted_option(msg, &size); - return size != 0; -} UPB_INLINE void google_protobuf_FileOptions_set_java_package(google_protobuf_FileOptions *msg, upb_StringView value) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 1); @@ -3791,11 +3676,6 @@ UPB_INLINE upb_Array* _google_protobuf_MessageOptions_uninterpreted_option_mutab } return arr; } -UPB_INLINE bool google_protobuf_MessageOptions_has_uninterpreted_option(const google_protobuf_MessageOptions* msg) { - size_t size; - google_protobuf_MessageOptions_uninterpreted_option(msg, &size); - return size != 0; -} UPB_INLINE void google_protobuf_MessageOptions_set_message_set_wire_format(google_protobuf_MessageOptions *msg, bool value) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MessageOptions_msg_init(), 1); @@ -4058,11 +3938,6 @@ UPB_INLINE upb_Array* _google_protobuf_FieldOptions_targets_mutable_upb_array(co } return arr; } -UPB_INLINE bool google_protobuf_FieldOptions_has_targets(const google_protobuf_FieldOptions* msg) { - size_t size; - google_protobuf_FieldOptions_targets(msg, &size); - return size != 0; -} UPB_INLINE void google_protobuf_FieldOptions_clear_edition_defaults(google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 20); _upb_Message_ClearNonExtensionField(msg, &field); @@ -4095,11 +3970,6 @@ UPB_INLINE upb_Array* _google_protobuf_FieldOptions_edition_defaults_mutable_upb } return arr; } -UPB_INLINE bool google_protobuf_FieldOptions_has_edition_defaults(const google_protobuf_FieldOptions* msg) { - size_t size; - google_protobuf_FieldOptions_edition_defaults(msg, &size); - return size != 0; -} UPB_INLINE void google_protobuf_FieldOptions_clear_features(google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 21); _upb_Message_ClearNonExtensionField(msg, &field); @@ -4147,11 +4017,6 @@ UPB_INLINE upb_Array* _google_protobuf_FieldOptions_uninterpreted_option_mutable } return arr; } -UPB_INLINE bool google_protobuf_FieldOptions_has_uninterpreted_option(const google_protobuf_FieldOptions* msg) { - size_t size; - google_protobuf_FieldOptions_uninterpreted_option(msg, &size); - return size != 0; -} UPB_INLINE void google_protobuf_FieldOptions_set_ctype(google_protobuf_FieldOptions *msg, int32_t value) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 1); @@ -4435,11 +4300,6 @@ UPB_INLINE upb_Array* _google_protobuf_OneofOptions_uninterpreted_option_mutable } return arr; } -UPB_INLINE bool google_protobuf_OneofOptions_has_uninterpreted_option(const google_protobuf_OneofOptions* msg) { - size_t size; - google_protobuf_OneofOptions_uninterpreted_option(msg, &size); - return size != 0; -} UPB_INLINE void google_protobuf_OneofOptions_set_features(google_protobuf_OneofOptions *msg, google_protobuf_FeatureSet* value) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__OneofOptions_msg_init(), 1); @@ -4607,11 +4467,6 @@ UPB_INLINE upb_Array* _google_protobuf_EnumOptions_uninterpreted_option_mutable_ } return arr; } -UPB_INLINE bool google_protobuf_EnumOptions_has_uninterpreted_option(const google_protobuf_EnumOptions* msg) { - size_t size; - google_protobuf_EnumOptions_uninterpreted_option(msg, &size); - return size != 0; -} UPB_INLINE void google_protobuf_EnumOptions_set_allow_alias(google_protobuf_EnumOptions *msg, bool value) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumOptions_msg_init(), 2); @@ -4776,11 +4631,6 @@ UPB_INLINE upb_Array* _google_protobuf_EnumValueOptions_uninterpreted_option_mut } return arr; } -UPB_INLINE bool google_protobuf_EnumValueOptions_has_uninterpreted_option(const google_protobuf_EnumValueOptions* msg) { - size_t size; - google_protobuf_EnumValueOptions_uninterpreted_option(msg, &size); - return size != 0; -} UPB_INLINE void google_protobuf_EnumValueOptions_set_deprecated(google_protobuf_EnumValueOptions *msg, bool value) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumValueOptions_msg_init(), 1); @@ -4926,11 +4776,6 @@ UPB_INLINE upb_Array* _google_protobuf_ServiceOptions_uninterpreted_option_mutab } return arr; } -UPB_INLINE bool google_protobuf_ServiceOptions_has_uninterpreted_option(const google_protobuf_ServiceOptions* msg) { - size_t size; - google_protobuf_ServiceOptions_uninterpreted_option(msg, &size); - return size != 0; -} UPB_INLINE void google_protobuf_ServiceOptions_set_deprecated(google_protobuf_ServiceOptions *msg, bool value) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ServiceOptions_msg_init(), 33); @@ -5087,11 +4932,6 @@ UPB_INLINE upb_Array* _google_protobuf_MethodOptions_uninterpreted_option_mutabl } return arr; } -UPB_INLINE bool google_protobuf_MethodOptions_has_uninterpreted_option(const google_protobuf_MethodOptions* msg) { - size_t size; - google_protobuf_MethodOptions_uninterpreted_option(msg, &size); - return size != 0; -} UPB_INLINE void google_protobuf_MethodOptions_set_deprecated(google_protobuf_MethodOptions *msg, bool value) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MethodOptions_msg_init(), 33); @@ -5207,11 +5047,6 @@ UPB_INLINE upb_Array* _google_protobuf_UninterpretedOption_name_mutable_upb_arra } return arr; } -UPB_INLINE bool google_protobuf_UninterpretedOption_has_name(const google_protobuf_UninterpretedOption* msg) { - size_t size; - google_protobuf_UninterpretedOption_name(msg, &size); - return size != 0; -} UPB_INLINE void google_protobuf_UninterpretedOption_clear_identifier_value(google_protobuf_UninterpretedOption* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__UninterpretedOption_msg_init(), 3); _upb_Message_ClearNonExtensionField(msg, &field); @@ -5647,11 +5482,6 @@ UPB_INLINE upb_Array* _google_protobuf_FeatureSetDefaults_defaults_mutable_upb_a } return arr; } -UPB_INLINE bool google_protobuf_FeatureSetDefaults_has_defaults(const google_protobuf_FeatureSetDefaults* msg) { - size_t size; - google_protobuf_FeatureSetDefaults_defaults(msg, &size); - return size != 0; -} UPB_INLINE void google_protobuf_FeatureSetDefaults_clear_minimum_edition(google_protobuf_FeatureSetDefaults* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FeatureSetDefaults_msg_init(), 4); _upb_Message_ClearNonExtensionField(msg, &field); @@ -5868,11 +5698,6 @@ UPB_INLINE upb_Array* _google_protobuf_SourceCodeInfo_location_mutable_upb_array } return arr; } -UPB_INLINE bool google_protobuf_SourceCodeInfo_has_location(const google_protobuf_SourceCodeInfo* msg) { - size_t size; - google_protobuf_SourceCodeInfo_location(msg, &size); - return size != 0; -} UPB_INLINE google_protobuf_SourceCodeInfo_Location** google_protobuf_SourceCodeInfo_mutable_location(google_protobuf_SourceCodeInfo* msg, size_t* size) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__SourceCodeInfo_msg_init(), 1); @@ -5968,11 +5793,6 @@ UPB_INLINE upb_Array* _google_protobuf_SourceCodeInfo_Location_path_mutable_upb_ } return arr; } -UPB_INLINE bool google_protobuf_SourceCodeInfo_Location_has_path(const google_protobuf_SourceCodeInfo_Location* msg) { - size_t size; - google_protobuf_SourceCodeInfo_Location_path(msg, &size); - return size != 0; -} UPB_INLINE void google_protobuf_SourceCodeInfo_Location_clear_span(google_protobuf_SourceCodeInfo_Location* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__SourceCodeInfo__Location_msg_init(), 2); _upb_Message_ClearNonExtensionField(msg, &field); @@ -6005,11 +5825,6 @@ UPB_INLINE upb_Array* _google_protobuf_SourceCodeInfo_Location_span_mutable_upb_ } return arr; } -UPB_INLINE bool google_protobuf_SourceCodeInfo_Location_has_span(const google_protobuf_SourceCodeInfo_Location* msg) { - size_t size; - google_protobuf_SourceCodeInfo_Location_span(msg, &size); - return size != 0; -} UPB_INLINE void google_protobuf_SourceCodeInfo_Location_clear_leading_comments(google_protobuf_SourceCodeInfo_Location* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__SourceCodeInfo__Location_msg_init(), 3); _upb_Message_ClearNonExtensionField(msg, &field); @@ -6072,11 +5887,6 @@ UPB_INLINE upb_Array* _google_protobuf_SourceCodeInfo_Location_leading_detached_ } return arr; } -UPB_INLINE bool google_protobuf_SourceCodeInfo_Location_has_leading_detached_comments(const google_protobuf_SourceCodeInfo_Location* msg) { - size_t size; - google_protobuf_SourceCodeInfo_Location_leading_detached_comments(msg, &size); - return size != 0; -} UPB_INLINE int32_t* google_protobuf_SourceCodeInfo_Location_mutable_path(google_protobuf_SourceCodeInfo_Location* msg, size_t* size) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__SourceCodeInfo__Location_msg_init(), 1); @@ -6226,11 +6036,6 @@ UPB_INLINE upb_Array* _google_protobuf_GeneratedCodeInfo_annotation_mutable_upb_ } return arr; } -UPB_INLINE bool google_protobuf_GeneratedCodeInfo_has_annotation(const google_protobuf_GeneratedCodeInfo* msg) { - size_t size; - google_protobuf_GeneratedCodeInfo_annotation(msg, &size); - return size != 0; -} UPB_INLINE google_protobuf_GeneratedCodeInfo_Annotation** google_protobuf_GeneratedCodeInfo_mutable_annotation(google_protobuf_GeneratedCodeInfo* msg, size_t* size) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__GeneratedCodeInfo_msg_init(), 1); @@ -6326,11 +6131,6 @@ UPB_INLINE upb_Array* _google_protobuf_GeneratedCodeInfo_Annotation_path_mutable } return arr; } -UPB_INLINE bool google_protobuf_GeneratedCodeInfo_Annotation_has_path(const google_protobuf_GeneratedCodeInfo_Annotation* msg) { - size_t size; - google_protobuf_GeneratedCodeInfo_Annotation_path(msg, &size); - return size != 0; -} UPB_INLINE void google_protobuf_GeneratedCodeInfo_Annotation_clear_source_file(google_protobuf_GeneratedCodeInfo_Annotation* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__GeneratedCodeInfo__Annotation_msg_init(), 2); _upb_Message_ClearNonExtensionField(msg, &field); diff --git a/upb_generator/protoc-gen-upb.cc b/upb_generator/protoc-gen-upb.cc index 4fcfdabc81771..2d84796561885 100644 --- a/upb_generator/protoc-gen-upb.cc +++ b/upb_generator/protoc-gen-upb.cc @@ -392,19 +392,6 @@ void GenerateHazzer(upb::FieldDefPtr field, const DefPoolPair& pools, } )cc", msg_name, resolved_name, FieldInitializer(pools, field, options)); - } else if (field.IsMap()) { - // Do nothing. - } else if (field.IsSequence()) { - // TODO: remove. - output( - R"cc( - UPB_INLINE bool $0_has_$1(const $0* msg) { - size_t size; - $0_$1(msg, &size); - return size != 0; - } - )cc", - msg_name, resolved_name); } } diff --git a/upb_generator/stage0/google/protobuf/compiler/plugin.upb.h b/upb_generator/stage0/google/protobuf/compiler/plugin.upb.h index 6fef25fe1d44e..27de0bc0e9517 100644 --- a/upb_generator/stage0/google/protobuf/compiler/plugin.upb.h +++ b/upb_generator/stage0/google/protobuf/compiler/plugin.upb.h @@ -220,11 +220,6 @@ UPB_INLINE upb_Array* _google_protobuf_compiler_CodeGeneratorRequest_file_to_gen } return arr; } -UPB_INLINE bool google_protobuf_compiler_CodeGeneratorRequest_has_file_to_generate(const google_protobuf_compiler_CodeGeneratorRequest* msg) { - size_t size; - google_protobuf_compiler_CodeGeneratorRequest_file_to_generate(msg, &size); - return size != 0; -} UPB_INLINE void google_protobuf_compiler_CodeGeneratorRequest_clear_parameter(google_protobuf_compiler_CodeGeneratorRequest* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorRequest_msg_init(), 2); _upb_Message_ClearNonExtensionField(msg, &field); @@ -287,11 +282,6 @@ UPB_INLINE upb_Array* _google_protobuf_compiler_CodeGeneratorRequest_proto_file_ } return arr; } -UPB_INLINE bool google_protobuf_compiler_CodeGeneratorRequest_has_proto_file(const google_protobuf_compiler_CodeGeneratorRequest* msg) { - size_t size; - google_protobuf_compiler_CodeGeneratorRequest_proto_file(msg, &size); - return size != 0; -} UPB_INLINE void google_protobuf_compiler_CodeGeneratorRequest_clear_source_file_descriptors(google_protobuf_compiler_CodeGeneratorRequest* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorRequest_msg_init(), 17); _upb_Message_ClearNonExtensionField(msg, &field); @@ -324,11 +314,6 @@ UPB_INLINE upb_Array* _google_protobuf_compiler_CodeGeneratorRequest_source_file } return arr; } -UPB_INLINE bool google_protobuf_compiler_CodeGeneratorRequest_has_source_file_descriptors(const google_protobuf_compiler_CodeGeneratorRequest* msg) { - size_t size; - google_protobuf_compiler_CodeGeneratorRequest_source_file_descriptors(msg, &size); - return size != 0; -} UPB_INLINE upb_StringView* google_protobuf_compiler_CodeGeneratorRequest_mutable_file_to_generate(google_protobuf_compiler_CodeGeneratorRequest* msg, size_t* size) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorRequest_msg_init(), 1); @@ -550,11 +535,6 @@ UPB_INLINE upb_Array* _google_protobuf_compiler_CodeGeneratorResponse_file_mutab } return arr; } -UPB_INLINE bool google_protobuf_compiler_CodeGeneratorResponse_has_file(const google_protobuf_compiler_CodeGeneratorResponse* msg) { - size_t size; - google_protobuf_compiler_CodeGeneratorResponse_file(msg, &size); - return size != 0; -} UPB_INLINE void google_protobuf_compiler_CodeGeneratorResponse_set_error(google_protobuf_compiler_CodeGeneratorResponse *msg, upb_StringView value) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorResponse_msg_init(), 1); From 2be44b99cbab638be1eee6ff79dc9b1c840dbc2b Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Fri, 15 Dec 2023 18:55:08 +0000 Subject: [PATCH 032/255] Auto-generate files after cl/591299107 --- php/ext/google/protobuf/php-upb.h | 200 --------------------- ruby/ext/google/protobuf_c/ruby-upb.h | 200 --------------------- upb/cmake/google/protobuf/descriptor.upb.h | 200 --------------------- 3 files changed, 600 deletions(-) diff --git a/php/ext/google/protobuf/php-upb.h b/php/ext/google/protobuf/php-upb.h index 41900b70f5951..786ca7de775a1 100644 --- a/php/ext/google/protobuf/php-upb.h +++ b/php/ext/google/protobuf/php-upb.h @@ -4474,11 +4474,6 @@ UPB_INLINE upb_Array* _google_protobuf_FileDescriptorSet_file_mutable_upb_array( } return arr; } -UPB_INLINE bool google_protobuf_FileDescriptorSet_has_file(const google_protobuf_FileDescriptorSet* msg) { - size_t size; - google_protobuf_FileDescriptorSet_file(msg, &size); - return size != 0; -} UPB_INLINE google_protobuf_FileDescriptorProto** google_protobuf_FileDescriptorSet_mutable_file(google_protobuf_FileDescriptorSet* msg, size_t* size) { upb_MiniTableField field = {1, 0, 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -4604,11 +4599,6 @@ UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_dependency_mutable_up } return arr; } -UPB_INLINE bool google_protobuf_FileDescriptorProto_has_dependency(const google_protobuf_FileDescriptorProto* msg) { - size_t size; - google_protobuf_FileDescriptorProto_dependency(msg, &size); - return size != 0; -} UPB_INLINE void google_protobuf_FileDescriptorProto_clear_message_type(google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = {4, UPB_SIZE(8, 48), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; _upb_Message_ClearNonExtensionField(msg, &field); @@ -4641,11 +4631,6 @@ UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_message_type_mutable_ } return arr; } -UPB_INLINE bool google_protobuf_FileDescriptorProto_has_message_type(const google_protobuf_FileDescriptorProto* msg) { - size_t size; - google_protobuf_FileDescriptorProto_message_type(msg, &size); - return size != 0; -} UPB_INLINE void google_protobuf_FileDescriptorProto_clear_enum_type(google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = {5, UPB_SIZE(12, 56), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; _upb_Message_ClearNonExtensionField(msg, &field); @@ -4678,11 +4663,6 @@ UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_enum_type_mutable_upb } return arr; } -UPB_INLINE bool google_protobuf_FileDescriptorProto_has_enum_type(const google_protobuf_FileDescriptorProto* msg) { - size_t size; - google_protobuf_FileDescriptorProto_enum_type(msg, &size); - return size != 0; -} UPB_INLINE void google_protobuf_FileDescriptorProto_clear_service(google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = {6, UPB_SIZE(16, 64), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; _upb_Message_ClearNonExtensionField(msg, &field); @@ -4715,11 +4695,6 @@ UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_service_mutable_upb_a } return arr; } -UPB_INLINE bool google_protobuf_FileDescriptorProto_has_service(const google_protobuf_FileDescriptorProto* msg) { - size_t size; - google_protobuf_FileDescriptorProto_service(msg, &size); - return size != 0; -} UPB_INLINE void google_protobuf_FileDescriptorProto_clear_extension(google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = {7, UPB_SIZE(20, 72), 0, 3, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; _upb_Message_ClearNonExtensionField(msg, &field); @@ -4752,11 +4727,6 @@ UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_extension_mutable_upb } return arr; } -UPB_INLINE bool google_protobuf_FileDescriptorProto_has_extension(const google_protobuf_FileDescriptorProto* msg) { - size_t size; - google_protobuf_FileDescriptorProto_extension(msg, &size); - return size != 0; -} UPB_INLINE void google_protobuf_FileDescriptorProto_clear_options(google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = {8, UPB_SIZE(24, 80), 3, 4, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; _upb_Message_ClearNonExtensionField(msg, &field); @@ -4819,11 +4789,6 @@ UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_public_dependency_mut } return arr; } -UPB_INLINE bool google_protobuf_FileDescriptorProto_has_public_dependency(const google_protobuf_FileDescriptorProto* msg) { - size_t size; - google_protobuf_FileDescriptorProto_public_dependency(msg, &size); - return size != 0; -} UPB_INLINE void google_protobuf_FileDescriptorProto_clear_weak_dependency(google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = {11, UPB_SIZE(36, 104), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; _upb_Message_ClearNonExtensionField(msg, &field); @@ -4856,11 +4821,6 @@ UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_weak_dependency_mutab } return arr; } -UPB_INLINE bool google_protobuf_FileDescriptorProto_has_weak_dependency(const google_protobuf_FileDescriptorProto* msg) { - size_t size; - google_protobuf_FileDescriptorProto_weak_dependency(msg, &size); - return size != 0; -} UPB_INLINE void google_protobuf_FileDescriptorProto_clear_syntax(google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = {12, UPB_SIZE(60, 112), 5, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; _upb_Message_ClearNonExtensionField(msg, &field); @@ -5191,11 +5151,6 @@ UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_field_mutable_upb_array(c } return arr; } -UPB_INLINE bool google_protobuf_DescriptorProto_has_field(const google_protobuf_DescriptorProto* msg) { - size_t size; - google_protobuf_DescriptorProto_field(msg, &size); - return size != 0; -} UPB_INLINE void google_protobuf_DescriptorProto_clear_nested_type(google_protobuf_DescriptorProto* msg) { const upb_MiniTableField field = {3, UPB_SIZE(8, 32), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; _upb_Message_ClearNonExtensionField(msg, &field); @@ -5228,11 +5183,6 @@ UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_nested_type_mutable_upb_a } return arr; } -UPB_INLINE bool google_protobuf_DescriptorProto_has_nested_type(const google_protobuf_DescriptorProto* msg) { - size_t size; - google_protobuf_DescriptorProto_nested_type(msg, &size); - return size != 0; -} UPB_INLINE void google_protobuf_DescriptorProto_clear_enum_type(google_protobuf_DescriptorProto* msg) { const upb_MiniTableField field = {4, UPB_SIZE(12, 40), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; _upb_Message_ClearNonExtensionField(msg, &field); @@ -5265,11 +5215,6 @@ UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_enum_type_mutable_upb_arr } return arr; } -UPB_INLINE bool google_protobuf_DescriptorProto_has_enum_type(const google_protobuf_DescriptorProto* msg) { - size_t size; - google_protobuf_DescriptorProto_enum_type(msg, &size); - return size != 0; -} UPB_INLINE void google_protobuf_DescriptorProto_clear_extension_range(google_protobuf_DescriptorProto* msg) { const upb_MiniTableField field = {5, UPB_SIZE(16, 48), 0, 3, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; _upb_Message_ClearNonExtensionField(msg, &field); @@ -5302,11 +5247,6 @@ UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_extension_range_mutable_u } return arr; } -UPB_INLINE bool google_protobuf_DescriptorProto_has_extension_range(const google_protobuf_DescriptorProto* msg) { - size_t size; - google_protobuf_DescriptorProto_extension_range(msg, &size); - return size != 0; -} UPB_INLINE void google_protobuf_DescriptorProto_clear_extension(google_protobuf_DescriptorProto* msg) { const upb_MiniTableField field = {6, UPB_SIZE(20, 56), 0, 4, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; _upb_Message_ClearNonExtensionField(msg, &field); @@ -5339,11 +5279,6 @@ UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_extension_mutable_upb_arr } return arr; } -UPB_INLINE bool google_protobuf_DescriptorProto_has_extension(const google_protobuf_DescriptorProto* msg) { - size_t size; - google_protobuf_DescriptorProto_extension(msg, &size); - return size != 0; -} UPB_INLINE void google_protobuf_DescriptorProto_clear_options(google_protobuf_DescriptorProto* msg) { const upb_MiniTableField field = {7, UPB_SIZE(24, 64), 2, 5, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; _upb_Message_ClearNonExtensionField(msg, &field); @@ -5391,11 +5326,6 @@ UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_oneof_decl_mutable_upb_ar } return arr; } -UPB_INLINE bool google_protobuf_DescriptorProto_has_oneof_decl(const google_protobuf_DescriptorProto* msg) { - size_t size; - google_protobuf_DescriptorProto_oneof_decl(msg, &size); - return size != 0; -} UPB_INLINE void google_protobuf_DescriptorProto_clear_reserved_range(google_protobuf_DescriptorProto* msg) { const upb_MiniTableField field = {9, UPB_SIZE(32, 80), 0, 7, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; _upb_Message_ClearNonExtensionField(msg, &field); @@ -5428,11 +5358,6 @@ UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_reserved_range_mutable_up } return arr; } -UPB_INLINE bool google_protobuf_DescriptorProto_has_reserved_range(const google_protobuf_DescriptorProto* msg) { - size_t size; - google_protobuf_DescriptorProto_reserved_range(msg, &size); - return size != 0; -} UPB_INLINE void google_protobuf_DescriptorProto_clear_reserved_name(google_protobuf_DescriptorProto* msg) { const upb_MiniTableField field = {10, UPB_SIZE(36, 88), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; _upb_Message_ClearNonExtensionField(msg, &field); @@ -5465,11 +5390,6 @@ UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_reserved_name_mutable_upb } return arr; } -UPB_INLINE bool google_protobuf_DescriptorProto_has_reserved_name(const google_protobuf_DescriptorProto* msg) { - size_t size; - google_protobuf_DescriptorProto_reserved_name(msg, &size); - return size != 0; -} UPB_INLINE void google_protobuf_DescriptorProto_set_name(google_protobuf_DescriptorProto *msg, upb_StringView value) { const upb_MiniTableField field = {1, UPB_SIZE(40, 8), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; @@ -5938,11 +5858,6 @@ UPB_INLINE upb_Array* _google_protobuf_ExtensionRangeOptions_declaration_mutable } return arr; } -UPB_INLINE bool google_protobuf_ExtensionRangeOptions_has_declaration(const google_protobuf_ExtensionRangeOptions* msg) { - size_t size; - google_protobuf_ExtensionRangeOptions_declaration(msg, &size); - return size != 0; -} UPB_INLINE void google_protobuf_ExtensionRangeOptions_clear_verification(google_protobuf_ExtensionRangeOptions* msg) { const upb_MiniTableField field = {3, UPB_SIZE(8, 4), 1, 3, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; _upb_Message_ClearNonExtensionField(msg, &field); @@ -6005,11 +5920,6 @@ UPB_INLINE upb_Array* _google_protobuf_ExtensionRangeOptions_uninterpreted_optio } return arr; } -UPB_INLINE bool google_protobuf_ExtensionRangeOptions_has_uninterpreted_option(const google_protobuf_ExtensionRangeOptions* msg) { - size_t size; - google_protobuf_ExtensionRangeOptions_uninterpreted_option(msg, &size); - return size != 0; -} UPB_INLINE google_protobuf_ExtensionRangeOptions_Declaration** google_protobuf_ExtensionRangeOptions_mutable_declaration(google_protobuf_ExtensionRangeOptions* msg, size_t* size) { upb_MiniTableField field = {2, UPB_SIZE(4, 8), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -6631,11 +6541,6 @@ UPB_INLINE upb_Array* _google_protobuf_EnumDescriptorProto_value_mutable_upb_arr } return arr; } -UPB_INLINE bool google_protobuf_EnumDescriptorProto_has_value(const google_protobuf_EnumDescriptorProto* msg) { - size_t size; - google_protobuf_EnumDescriptorProto_value(msg, &size); - return size != 0; -} UPB_INLINE void google_protobuf_EnumDescriptorProto_clear_options(google_protobuf_EnumDescriptorProto* msg) { const upb_MiniTableField field = {3, UPB_SIZE(8, 32), 2, 1, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; _upb_Message_ClearNonExtensionField(msg, &field); @@ -6683,11 +6588,6 @@ UPB_INLINE upb_Array* _google_protobuf_EnumDescriptorProto_reserved_range_mutabl } return arr; } -UPB_INLINE bool google_protobuf_EnumDescriptorProto_has_reserved_range(const google_protobuf_EnumDescriptorProto* msg) { - size_t size; - google_protobuf_EnumDescriptorProto_reserved_range(msg, &size); - return size != 0; -} UPB_INLINE void google_protobuf_EnumDescriptorProto_clear_reserved_name(google_protobuf_EnumDescriptorProto* msg) { const upb_MiniTableField field = {5, UPB_SIZE(16, 48), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; _upb_Message_ClearNonExtensionField(msg, &field); @@ -6720,11 +6620,6 @@ UPB_INLINE upb_Array* _google_protobuf_EnumDescriptorProto_reserved_name_mutable } return arr; } -UPB_INLINE bool google_protobuf_EnumDescriptorProto_has_reserved_name(const google_protobuf_EnumDescriptorProto* msg) { - size_t size; - google_protobuf_EnumDescriptorProto_reserved_name(msg, &size); - return size != 0; -} UPB_INLINE void google_protobuf_EnumDescriptorProto_set_name(google_protobuf_EnumDescriptorProto *msg, upb_StringView value) { const upb_MiniTableField field = {1, UPB_SIZE(20, 8), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; @@ -7078,11 +6973,6 @@ UPB_INLINE upb_Array* _google_protobuf_ServiceDescriptorProto_method_mutable_upb } return arr; } -UPB_INLINE bool google_protobuf_ServiceDescriptorProto_has_method(const google_protobuf_ServiceDescriptorProto* msg) { - size_t size; - google_protobuf_ServiceDescriptorProto_method(msg, &size); - return size != 0; -} UPB_INLINE void google_protobuf_ServiceDescriptorProto_clear_options(google_protobuf_ServiceDescriptorProto* msg) { const upb_MiniTableField field = {3, UPB_SIZE(8, 32), 2, 1, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; _upb_Message_ClearNonExtensionField(msg, &field); @@ -7683,11 +7573,6 @@ UPB_INLINE upb_Array* _google_protobuf_FileOptions_uninterpreted_option_mutable_ } return arr; } -UPB_INLINE bool google_protobuf_FileOptions_has_uninterpreted_option(const google_protobuf_FileOptions* msg) { - size_t size; - google_protobuf_FileOptions_uninterpreted_option(msg, &size); - return size != 0; -} UPB_INLINE void google_protobuf_FileOptions_set_java_package(google_protobuf_FileOptions *msg, upb_StringView value) { const upb_MiniTableField field = {1, UPB_SIZE(28, 24), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; @@ -7965,11 +7850,6 @@ UPB_INLINE upb_Array* _google_protobuf_MessageOptions_uninterpreted_option_mutab } return arr; } -UPB_INLINE bool google_protobuf_MessageOptions_has_uninterpreted_option(const google_protobuf_MessageOptions* msg) { - size_t size; - google_protobuf_MessageOptions_uninterpreted_option(msg, &size); - return size != 0; -} UPB_INLINE void google_protobuf_MessageOptions_set_message_set_wire_format(google_protobuf_MessageOptions *msg, bool value) { const upb_MiniTableField field = {1, 1, 1, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; @@ -8232,11 +8112,6 @@ UPB_INLINE upb_Array* _google_protobuf_FieldOptions_targets_mutable_upb_array(co } return arr; } -UPB_INLINE bool google_protobuf_FieldOptions_has_targets(const google_protobuf_FieldOptions* msg) { - size_t size; - google_protobuf_FieldOptions_targets(msg, &size); - return size != 0; -} UPB_INLINE void google_protobuf_FieldOptions_clear_edition_defaults(google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {20, UPB_SIZE(28, 32), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; _upb_Message_ClearNonExtensionField(msg, &field); @@ -8269,11 +8144,6 @@ UPB_INLINE upb_Array* _google_protobuf_FieldOptions_edition_defaults_mutable_upb } return arr; } -UPB_INLINE bool google_protobuf_FieldOptions_has_edition_defaults(const google_protobuf_FieldOptions* msg) { - size_t size; - google_protobuf_FieldOptions_edition_defaults(msg, &size); - return size != 0; -} UPB_INLINE void google_protobuf_FieldOptions_clear_features(google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {21, UPB_SIZE(32, 40), 10, 1, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; _upb_Message_ClearNonExtensionField(msg, &field); @@ -8321,11 +8191,6 @@ UPB_INLINE upb_Array* _google_protobuf_FieldOptions_uninterpreted_option_mutable } return arr; } -UPB_INLINE bool google_protobuf_FieldOptions_has_uninterpreted_option(const google_protobuf_FieldOptions* msg) { - size_t size; - google_protobuf_FieldOptions_uninterpreted_option(msg, &size); - return size != 0; -} UPB_INLINE void google_protobuf_FieldOptions_set_ctype(google_protobuf_FieldOptions *msg, int32_t value) { const upb_MiniTableField field = {1, 4, 1, 3, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; @@ -8609,11 +8474,6 @@ UPB_INLINE upb_Array* _google_protobuf_OneofOptions_uninterpreted_option_mutable } return arr; } -UPB_INLINE bool google_protobuf_OneofOptions_has_uninterpreted_option(const google_protobuf_OneofOptions* msg) { - size_t size; - google_protobuf_OneofOptions_uninterpreted_option(msg, &size); - return size != 0; -} UPB_INLINE void google_protobuf_OneofOptions_set_features(google_protobuf_OneofOptions *msg, google_protobuf_FeatureSet* value) { const upb_MiniTableField field = {1, UPB_SIZE(4, 8), 1, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -8781,11 +8641,6 @@ UPB_INLINE upb_Array* _google_protobuf_EnumOptions_uninterpreted_option_mutable_ } return arr; } -UPB_INLINE bool google_protobuf_EnumOptions_has_uninterpreted_option(const google_protobuf_EnumOptions* msg) { - size_t size; - google_protobuf_EnumOptions_uninterpreted_option(msg, &size); - return size != 0; -} UPB_INLINE void google_protobuf_EnumOptions_set_allow_alias(google_protobuf_EnumOptions *msg, bool value) { const upb_MiniTableField field = {2, 1, 1, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; @@ -8950,11 +8805,6 @@ UPB_INLINE upb_Array* _google_protobuf_EnumValueOptions_uninterpreted_option_mut } return arr; } -UPB_INLINE bool google_protobuf_EnumValueOptions_has_uninterpreted_option(const google_protobuf_EnumValueOptions* msg) { - size_t size; - google_protobuf_EnumValueOptions_uninterpreted_option(msg, &size); - return size != 0; -} UPB_INLINE void google_protobuf_EnumValueOptions_set_deprecated(google_protobuf_EnumValueOptions *msg, bool value) { const upb_MiniTableField field = {1, 1, 1, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; @@ -9100,11 +8950,6 @@ UPB_INLINE upb_Array* _google_protobuf_ServiceOptions_uninterpreted_option_mutab } return arr; } -UPB_INLINE bool google_protobuf_ServiceOptions_has_uninterpreted_option(const google_protobuf_ServiceOptions* msg) { - size_t size; - google_protobuf_ServiceOptions_uninterpreted_option(msg, &size); - return size != 0; -} UPB_INLINE void google_protobuf_ServiceOptions_set_deprecated(google_protobuf_ServiceOptions *msg, bool value) { const upb_MiniTableField field = {33, 1, 1, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; @@ -9261,11 +9106,6 @@ UPB_INLINE upb_Array* _google_protobuf_MethodOptions_uninterpreted_option_mutabl } return arr; } -UPB_INLINE bool google_protobuf_MethodOptions_has_uninterpreted_option(const google_protobuf_MethodOptions* msg) { - size_t size; - google_protobuf_MethodOptions_uninterpreted_option(msg, &size); - return size != 0; -} UPB_INLINE void google_protobuf_MethodOptions_set_deprecated(google_protobuf_MethodOptions *msg, bool value) { const upb_MiniTableField field = {33, 1, 1, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; @@ -9381,11 +9221,6 @@ UPB_INLINE upb_Array* _google_protobuf_UninterpretedOption_name_mutable_upb_arra } return arr; } -UPB_INLINE bool google_protobuf_UninterpretedOption_has_name(const google_protobuf_UninterpretedOption* msg) { - size_t size; - google_protobuf_UninterpretedOption_name(msg, &size); - return size != 0; -} UPB_INLINE void google_protobuf_UninterpretedOption_clear_identifier_value(google_protobuf_UninterpretedOption* msg) { const upb_MiniTableField field = {3, UPB_SIZE(8, 16), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; _upb_Message_ClearNonExtensionField(msg, &field); @@ -9821,11 +9656,6 @@ UPB_INLINE upb_Array* _google_protobuf_FeatureSetDefaults_defaults_mutable_upb_a } return arr; } -UPB_INLINE bool google_protobuf_FeatureSetDefaults_has_defaults(const google_protobuf_FeatureSetDefaults* msg) { - size_t size; - google_protobuf_FeatureSetDefaults_defaults(msg, &size); - return size != 0; -} UPB_INLINE void google_protobuf_FeatureSetDefaults_clear_minimum_edition(google_protobuf_FeatureSetDefaults* msg) { const upb_MiniTableField field = {4, UPB_SIZE(8, 4), 1, 1, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; _upb_Message_ClearNonExtensionField(msg, &field); @@ -10042,11 +9872,6 @@ UPB_INLINE upb_Array* _google_protobuf_SourceCodeInfo_location_mutable_upb_array } return arr; } -UPB_INLINE bool google_protobuf_SourceCodeInfo_has_location(const google_protobuf_SourceCodeInfo* msg) { - size_t size; - google_protobuf_SourceCodeInfo_location(msg, &size); - return size != 0; -} UPB_INLINE google_protobuf_SourceCodeInfo_Location** google_protobuf_SourceCodeInfo_mutable_location(google_protobuf_SourceCodeInfo* msg, size_t* size) { upb_MiniTableField field = {1, 0, 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -10142,11 +9967,6 @@ UPB_INLINE upb_Array* _google_protobuf_SourceCodeInfo_Location_path_mutable_upb_ } return arr; } -UPB_INLINE bool google_protobuf_SourceCodeInfo_Location_has_path(const google_protobuf_SourceCodeInfo_Location* msg) { - size_t size; - google_protobuf_SourceCodeInfo_Location_path(msg, &size); - return size != 0; -} UPB_INLINE void google_protobuf_SourceCodeInfo_Location_clear_span(google_protobuf_SourceCodeInfo_Location* msg) { const upb_MiniTableField field = {2, UPB_SIZE(8, 16), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsPacked | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; _upb_Message_ClearNonExtensionField(msg, &field); @@ -10179,11 +9999,6 @@ UPB_INLINE upb_Array* _google_protobuf_SourceCodeInfo_Location_span_mutable_upb_ } return arr; } -UPB_INLINE bool google_protobuf_SourceCodeInfo_Location_has_span(const google_protobuf_SourceCodeInfo_Location* msg) { - size_t size; - google_protobuf_SourceCodeInfo_Location_span(msg, &size); - return size != 0; -} UPB_INLINE void google_protobuf_SourceCodeInfo_Location_clear_leading_comments(google_protobuf_SourceCodeInfo_Location* msg) { const upb_MiniTableField field = {3, UPB_SIZE(16, 24), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; _upb_Message_ClearNonExtensionField(msg, &field); @@ -10246,11 +10061,6 @@ UPB_INLINE upb_Array* _google_protobuf_SourceCodeInfo_Location_leading_detached_ } return arr; } -UPB_INLINE bool google_protobuf_SourceCodeInfo_Location_has_leading_detached_comments(const google_protobuf_SourceCodeInfo_Location* msg) { - size_t size; - google_protobuf_SourceCodeInfo_Location_leading_detached_comments(msg, &size); - return size != 0; -} UPB_INLINE int32_t* google_protobuf_SourceCodeInfo_Location_mutable_path(google_protobuf_SourceCodeInfo_Location* msg, size_t* size) { upb_MiniTableField field = {1, UPB_SIZE(4, 8), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsPacked | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -10400,11 +10210,6 @@ UPB_INLINE upb_Array* _google_protobuf_GeneratedCodeInfo_annotation_mutable_upb_ } return arr; } -UPB_INLINE bool google_protobuf_GeneratedCodeInfo_has_annotation(const google_protobuf_GeneratedCodeInfo* msg) { - size_t size; - google_protobuf_GeneratedCodeInfo_annotation(msg, &size); - return size != 0; -} UPB_INLINE google_protobuf_GeneratedCodeInfo_Annotation** google_protobuf_GeneratedCodeInfo_mutable_annotation(google_protobuf_GeneratedCodeInfo* msg, size_t* size) { upb_MiniTableField field = {1, 0, 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -10500,11 +10305,6 @@ UPB_INLINE upb_Array* _google_protobuf_GeneratedCodeInfo_Annotation_path_mutable } return arr; } -UPB_INLINE bool google_protobuf_GeneratedCodeInfo_Annotation_has_path(const google_protobuf_GeneratedCodeInfo_Annotation* msg) { - size_t size; - google_protobuf_GeneratedCodeInfo_Annotation_path(msg, &size); - return size != 0; -} UPB_INLINE void google_protobuf_GeneratedCodeInfo_Annotation_clear_source_file(google_protobuf_GeneratedCodeInfo_Annotation* msg) { const upb_MiniTableField field = {2, UPB_SIZE(20, 24), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; _upb_Message_ClearNonExtensionField(msg, &field); diff --git a/ruby/ext/google/protobuf_c/ruby-upb.h b/ruby/ext/google/protobuf_c/ruby-upb.h index d92ecc0dfe68e..903a3eb49d69b 100755 --- a/ruby/ext/google/protobuf_c/ruby-upb.h +++ b/ruby/ext/google/protobuf_c/ruby-upb.h @@ -4978,11 +4978,6 @@ UPB_INLINE upb_Array* _google_protobuf_FileDescriptorSet_file_mutable_upb_array( } return arr; } -UPB_INLINE bool google_protobuf_FileDescriptorSet_has_file(const google_protobuf_FileDescriptorSet* msg) { - size_t size; - google_protobuf_FileDescriptorSet_file(msg, &size); - return size != 0; -} UPB_INLINE google_protobuf_FileDescriptorProto** google_protobuf_FileDescriptorSet_mutable_file(google_protobuf_FileDescriptorSet* msg, size_t* size) { upb_MiniTableField field = {1, 0, 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -5108,11 +5103,6 @@ UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_dependency_mutable_up } return arr; } -UPB_INLINE bool google_protobuf_FileDescriptorProto_has_dependency(const google_protobuf_FileDescriptorProto* msg) { - size_t size; - google_protobuf_FileDescriptorProto_dependency(msg, &size); - return size != 0; -} UPB_INLINE void google_protobuf_FileDescriptorProto_clear_message_type(google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = {4, UPB_SIZE(8, 48), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; _upb_Message_ClearNonExtensionField(msg, &field); @@ -5145,11 +5135,6 @@ UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_message_type_mutable_ } return arr; } -UPB_INLINE bool google_protobuf_FileDescriptorProto_has_message_type(const google_protobuf_FileDescriptorProto* msg) { - size_t size; - google_protobuf_FileDescriptorProto_message_type(msg, &size); - return size != 0; -} UPB_INLINE void google_protobuf_FileDescriptorProto_clear_enum_type(google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = {5, UPB_SIZE(12, 56), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; _upb_Message_ClearNonExtensionField(msg, &field); @@ -5182,11 +5167,6 @@ UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_enum_type_mutable_upb } return arr; } -UPB_INLINE bool google_protobuf_FileDescriptorProto_has_enum_type(const google_protobuf_FileDescriptorProto* msg) { - size_t size; - google_protobuf_FileDescriptorProto_enum_type(msg, &size); - return size != 0; -} UPB_INLINE void google_protobuf_FileDescriptorProto_clear_service(google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = {6, UPB_SIZE(16, 64), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; _upb_Message_ClearNonExtensionField(msg, &field); @@ -5219,11 +5199,6 @@ UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_service_mutable_upb_a } return arr; } -UPB_INLINE bool google_protobuf_FileDescriptorProto_has_service(const google_protobuf_FileDescriptorProto* msg) { - size_t size; - google_protobuf_FileDescriptorProto_service(msg, &size); - return size != 0; -} UPB_INLINE void google_protobuf_FileDescriptorProto_clear_extension(google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = {7, UPB_SIZE(20, 72), 0, 3, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; _upb_Message_ClearNonExtensionField(msg, &field); @@ -5256,11 +5231,6 @@ UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_extension_mutable_upb } return arr; } -UPB_INLINE bool google_protobuf_FileDescriptorProto_has_extension(const google_protobuf_FileDescriptorProto* msg) { - size_t size; - google_protobuf_FileDescriptorProto_extension(msg, &size); - return size != 0; -} UPB_INLINE void google_protobuf_FileDescriptorProto_clear_options(google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = {8, UPB_SIZE(24, 80), 3, 4, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; _upb_Message_ClearNonExtensionField(msg, &field); @@ -5323,11 +5293,6 @@ UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_public_dependency_mut } return arr; } -UPB_INLINE bool google_protobuf_FileDescriptorProto_has_public_dependency(const google_protobuf_FileDescriptorProto* msg) { - size_t size; - google_protobuf_FileDescriptorProto_public_dependency(msg, &size); - return size != 0; -} UPB_INLINE void google_protobuf_FileDescriptorProto_clear_weak_dependency(google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = {11, UPB_SIZE(36, 104), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; _upb_Message_ClearNonExtensionField(msg, &field); @@ -5360,11 +5325,6 @@ UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_weak_dependency_mutab } return arr; } -UPB_INLINE bool google_protobuf_FileDescriptorProto_has_weak_dependency(const google_protobuf_FileDescriptorProto* msg) { - size_t size; - google_protobuf_FileDescriptorProto_weak_dependency(msg, &size); - return size != 0; -} UPB_INLINE void google_protobuf_FileDescriptorProto_clear_syntax(google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = {12, UPB_SIZE(60, 112), 5, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; _upb_Message_ClearNonExtensionField(msg, &field); @@ -5695,11 +5655,6 @@ UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_field_mutable_upb_array(c } return arr; } -UPB_INLINE bool google_protobuf_DescriptorProto_has_field(const google_protobuf_DescriptorProto* msg) { - size_t size; - google_protobuf_DescriptorProto_field(msg, &size); - return size != 0; -} UPB_INLINE void google_protobuf_DescriptorProto_clear_nested_type(google_protobuf_DescriptorProto* msg) { const upb_MiniTableField field = {3, UPB_SIZE(8, 32), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; _upb_Message_ClearNonExtensionField(msg, &field); @@ -5732,11 +5687,6 @@ UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_nested_type_mutable_upb_a } return arr; } -UPB_INLINE bool google_protobuf_DescriptorProto_has_nested_type(const google_protobuf_DescriptorProto* msg) { - size_t size; - google_protobuf_DescriptorProto_nested_type(msg, &size); - return size != 0; -} UPB_INLINE void google_protobuf_DescriptorProto_clear_enum_type(google_protobuf_DescriptorProto* msg) { const upb_MiniTableField field = {4, UPB_SIZE(12, 40), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; _upb_Message_ClearNonExtensionField(msg, &field); @@ -5769,11 +5719,6 @@ UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_enum_type_mutable_upb_arr } return arr; } -UPB_INLINE bool google_protobuf_DescriptorProto_has_enum_type(const google_protobuf_DescriptorProto* msg) { - size_t size; - google_protobuf_DescriptorProto_enum_type(msg, &size); - return size != 0; -} UPB_INLINE void google_protobuf_DescriptorProto_clear_extension_range(google_protobuf_DescriptorProto* msg) { const upb_MiniTableField field = {5, UPB_SIZE(16, 48), 0, 3, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; _upb_Message_ClearNonExtensionField(msg, &field); @@ -5806,11 +5751,6 @@ UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_extension_range_mutable_u } return arr; } -UPB_INLINE bool google_protobuf_DescriptorProto_has_extension_range(const google_protobuf_DescriptorProto* msg) { - size_t size; - google_protobuf_DescriptorProto_extension_range(msg, &size); - return size != 0; -} UPB_INLINE void google_protobuf_DescriptorProto_clear_extension(google_protobuf_DescriptorProto* msg) { const upb_MiniTableField field = {6, UPB_SIZE(20, 56), 0, 4, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; _upb_Message_ClearNonExtensionField(msg, &field); @@ -5843,11 +5783,6 @@ UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_extension_mutable_upb_arr } return arr; } -UPB_INLINE bool google_protobuf_DescriptorProto_has_extension(const google_protobuf_DescriptorProto* msg) { - size_t size; - google_protobuf_DescriptorProto_extension(msg, &size); - return size != 0; -} UPB_INLINE void google_protobuf_DescriptorProto_clear_options(google_protobuf_DescriptorProto* msg) { const upb_MiniTableField field = {7, UPB_SIZE(24, 64), 2, 5, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; _upb_Message_ClearNonExtensionField(msg, &field); @@ -5895,11 +5830,6 @@ UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_oneof_decl_mutable_upb_ar } return arr; } -UPB_INLINE bool google_protobuf_DescriptorProto_has_oneof_decl(const google_protobuf_DescriptorProto* msg) { - size_t size; - google_protobuf_DescriptorProto_oneof_decl(msg, &size); - return size != 0; -} UPB_INLINE void google_protobuf_DescriptorProto_clear_reserved_range(google_protobuf_DescriptorProto* msg) { const upb_MiniTableField field = {9, UPB_SIZE(32, 80), 0, 7, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; _upb_Message_ClearNonExtensionField(msg, &field); @@ -5932,11 +5862,6 @@ UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_reserved_range_mutable_up } return arr; } -UPB_INLINE bool google_protobuf_DescriptorProto_has_reserved_range(const google_protobuf_DescriptorProto* msg) { - size_t size; - google_protobuf_DescriptorProto_reserved_range(msg, &size); - return size != 0; -} UPB_INLINE void google_protobuf_DescriptorProto_clear_reserved_name(google_protobuf_DescriptorProto* msg) { const upb_MiniTableField field = {10, UPB_SIZE(36, 88), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; _upb_Message_ClearNonExtensionField(msg, &field); @@ -5969,11 +5894,6 @@ UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_reserved_name_mutable_upb } return arr; } -UPB_INLINE bool google_protobuf_DescriptorProto_has_reserved_name(const google_protobuf_DescriptorProto* msg) { - size_t size; - google_protobuf_DescriptorProto_reserved_name(msg, &size); - return size != 0; -} UPB_INLINE void google_protobuf_DescriptorProto_set_name(google_protobuf_DescriptorProto *msg, upb_StringView value) { const upb_MiniTableField field = {1, UPB_SIZE(40, 8), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; @@ -6442,11 +6362,6 @@ UPB_INLINE upb_Array* _google_protobuf_ExtensionRangeOptions_declaration_mutable } return arr; } -UPB_INLINE bool google_protobuf_ExtensionRangeOptions_has_declaration(const google_protobuf_ExtensionRangeOptions* msg) { - size_t size; - google_protobuf_ExtensionRangeOptions_declaration(msg, &size); - return size != 0; -} UPB_INLINE void google_protobuf_ExtensionRangeOptions_clear_verification(google_protobuf_ExtensionRangeOptions* msg) { const upb_MiniTableField field = {3, UPB_SIZE(8, 4), 1, 3, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; _upb_Message_ClearNonExtensionField(msg, &field); @@ -6509,11 +6424,6 @@ UPB_INLINE upb_Array* _google_protobuf_ExtensionRangeOptions_uninterpreted_optio } return arr; } -UPB_INLINE bool google_protobuf_ExtensionRangeOptions_has_uninterpreted_option(const google_protobuf_ExtensionRangeOptions* msg) { - size_t size; - google_protobuf_ExtensionRangeOptions_uninterpreted_option(msg, &size); - return size != 0; -} UPB_INLINE google_protobuf_ExtensionRangeOptions_Declaration** google_protobuf_ExtensionRangeOptions_mutable_declaration(google_protobuf_ExtensionRangeOptions* msg, size_t* size) { upb_MiniTableField field = {2, UPB_SIZE(4, 8), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -7135,11 +7045,6 @@ UPB_INLINE upb_Array* _google_protobuf_EnumDescriptorProto_value_mutable_upb_arr } return arr; } -UPB_INLINE bool google_protobuf_EnumDescriptorProto_has_value(const google_protobuf_EnumDescriptorProto* msg) { - size_t size; - google_protobuf_EnumDescriptorProto_value(msg, &size); - return size != 0; -} UPB_INLINE void google_protobuf_EnumDescriptorProto_clear_options(google_protobuf_EnumDescriptorProto* msg) { const upb_MiniTableField field = {3, UPB_SIZE(8, 32), 2, 1, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; _upb_Message_ClearNonExtensionField(msg, &field); @@ -7187,11 +7092,6 @@ UPB_INLINE upb_Array* _google_protobuf_EnumDescriptorProto_reserved_range_mutabl } return arr; } -UPB_INLINE bool google_protobuf_EnumDescriptorProto_has_reserved_range(const google_protobuf_EnumDescriptorProto* msg) { - size_t size; - google_protobuf_EnumDescriptorProto_reserved_range(msg, &size); - return size != 0; -} UPB_INLINE void google_protobuf_EnumDescriptorProto_clear_reserved_name(google_protobuf_EnumDescriptorProto* msg) { const upb_MiniTableField field = {5, UPB_SIZE(16, 48), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; _upb_Message_ClearNonExtensionField(msg, &field); @@ -7224,11 +7124,6 @@ UPB_INLINE upb_Array* _google_protobuf_EnumDescriptorProto_reserved_name_mutable } return arr; } -UPB_INLINE bool google_protobuf_EnumDescriptorProto_has_reserved_name(const google_protobuf_EnumDescriptorProto* msg) { - size_t size; - google_protobuf_EnumDescriptorProto_reserved_name(msg, &size); - return size != 0; -} UPB_INLINE void google_protobuf_EnumDescriptorProto_set_name(google_protobuf_EnumDescriptorProto *msg, upb_StringView value) { const upb_MiniTableField field = {1, UPB_SIZE(20, 8), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; @@ -7582,11 +7477,6 @@ UPB_INLINE upb_Array* _google_protobuf_ServiceDescriptorProto_method_mutable_upb } return arr; } -UPB_INLINE bool google_protobuf_ServiceDescriptorProto_has_method(const google_protobuf_ServiceDescriptorProto* msg) { - size_t size; - google_protobuf_ServiceDescriptorProto_method(msg, &size); - return size != 0; -} UPB_INLINE void google_protobuf_ServiceDescriptorProto_clear_options(google_protobuf_ServiceDescriptorProto* msg) { const upb_MiniTableField field = {3, UPB_SIZE(8, 32), 2, 1, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; _upb_Message_ClearNonExtensionField(msg, &field); @@ -8187,11 +8077,6 @@ UPB_INLINE upb_Array* _google_protobuf_FileOptions_uninterpreted_option_mutable_ } return arr; } -UPB_INLINE bool google_protobuf_FileOptions_has_uninterpreted_option(const google_protobuf_FileOptions* msg) { - size_t size; - google_protobuf_FileOptions_uninterpreted_option(msg, &size); - return size != 0; -} UPB_INLINE void google_protobuf_FileOptions_set_java_package(google_protobuf_FileOptions *msg, upb_StringView value) { const upb_MiniTableField field = {1, UPB_SIZE(28, 24), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; @@ -8469,11 +8354,6 @@ UPB_INLINE upb_Array* _google_protobuf_MessageOptions_uninterpreted_option_mutab } return arr; } -UPB_INLINE bool google_protobuf_MessageOptions_has_uninterpreted_option(const google_protobuf_MessageOptions* msg) { - size_t size; - google_protobuf_MessageOptions_uninterpreted_option(msg, &size); - return size != 0; -} UPB_INLINE void google_protobuf_MessageOptions_set_message_set_wire_format(google_protobuf_MessageOptions *msg, bool value) { const upb_MiniTableField field = {1, 1, 1, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; @@ -8736,11 +8616,6 @@ UPB_INLINE upb_Array* _google_protobuf_FieldOptions_targets_mutable_upb_array(co } return arr; } -UPB_INLINE bool google_protobuf_FieldOptions_has_targets(const google_protobuf_FieldOptions* msg) { - size_t size; - google_protobuf_FieldOptions_targets(msg, &size); - return size != 0; -} UPB_INLINE void google_protobuf_FieldOptions_clear_edition_defaults(google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {20, UPB_SIZE(28, 32), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; _upb_Message_ClearNonExtensionField(msg, &field); @@ -8773,11 +8648,6 @@ UPB_INLINE upb_Array* _google_protobuf_FieldOptions_edition_defaults_mutable_upb } return arr; } -UPB_INLINE bool google_protobuf_FieldOptions_has_edition_defaults(const google_protobuf_FieldOptions* msg) { - size_t size; - google_protobuf_FieldOptions_edition_defaults(msg, &size); - return size != 0; -} UPB_INLINE void google_protobuf_FieldOptions_clear_features(google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {21, UPB_SIZE(32, 40), 10, 1, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; _upb_Message_ClearNonExtensionField(msg, &field); @@ -8825,11 +8695,6 @@ UPB_INLINE upb_Array* _google_protobuf_FieldOptions_uninterpreted_option_mutable } return arr; } -UPB_INLINE bool google_protobuf_FieldOptions_has_uninterpreted_option(const google_protobuf_FieldOptions* msg) { - size_t size; - google_protobuf_FieldOptions_uninterpreted_option(msg, &size); - return size != 0; -} UPB_INLINE void google_protobuf_FieldOptions_set_ctype(google_protobuf_FieldOptions *msg, int32_t value) { const upb_MiniTableField field = {1, 4, 1, 3, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; @@ -9113,11 +8978,6 @@ UPB_INLINE upb_Array* _google_protobuf_OneofOptions_uninterpreted_option_mutable } return arr; } -UPB_INLINE bool google_protobuf_OneofOptions_has_uninterpreted_option(const google_protobuf_OneofOptions* msg) { - size_t size; - google_protobuf_OneofOptions_uninterpreted_option(msg, &size); - return size != 0; -} UPB_INLINE void google_protobuf_OneofOptions_set_features(google_protobuf_OneofOptions *msg, google_protobuf_FeatureSet* value) { const upb_MiniTableField field = {1, UPB_SIZE(4, 8), 1, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -9285,11 +9145,6 @@ UPB_INLINE upb_Array* _google_protobuf_EnumOptions_uninterpreted_option_mutable_ } return arr; } -UPB_INLINE bool google_protobuf_EnumOptions_has_uninterpreted_option(const google_protobuf_EnumOptions* msg) { - size_t size; - google_protobuf_EnumOptions_uninterpreted_option(msg, &size); - return size != 0; -} UPB_INLINE void google_protobuf_EnumOptions_set_allow_alias(google_protobuf_EnumOptions *msg, bool value) { const upb_MiniTableField field = {2, 1, 1, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; @@ -9454,11 +9309,6 @@ UPB_INLINE upb_Array* _google_protobuf_EnumValueOptions_uninterpreted_option_mut } return arr; } -UPB_INLINE bool google_protobuf_EnumValueOptions_has_uninterpreted_option(const google_protobuf_EnumValueOptions* msg) { - size_t size; - google_protobuf_EnumValueOptions_uninterpreted_option(msg, &size); - return size != 0; -} UPB_INLINE void google_protobuf_EnumValueOptions_set_deprecated(google_protobuf_EnumValueOptions *msg, bool value) { const upb_MiniTableField field = {1, 1, 1, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; @@ -9604,11 +9454,6 @@ UPB_INLINE upb_Array* _google_protobuf_ServiceOptions_uninterpreted_option_mutab } return arr; } -UPB_INLINE bool google_protobuf_ServiceOptions_has_uninterpreted_option(const google_protobuf_ServiceOptions* msg) { - size_t size; - google_protobuf_ServiceOptions_uninterpreted_option(msg, &size); - return size != 0; -} UPB_INLINE void google_protobuf_ServiceOptions_set_deprecated(google_protobuf_ServiceOptions *msg, bool value) { const upb_MiniTableField field = {33, 1, 1, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; @@ -9765,11 +9610,6 @@ UPB_INLINE upb_Array* _google_protobuf_MethodOptions_uninterpreted_option_mutabl } return arr; } -UPB_INLINE bool google_protobuf_MethodOptions_has_uninterpreted_option(const google_protobuf_MethodOptions* msg) { - size_t size; - google_protobuf_MethodOptions_uninterpreted_option(msg, &size); - return size != 0; -} UPB_INLINE void google_protobuf_MethodOptions_set_deprecated(google_protobuf_MethodOptions *msg, bool value) { const upb_MiniTableField field = {33, 1, 1, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; @@ -9885,11 +9725,6 @@ UPB_INLINE upb_Array* _google_protobuf_UninterpretedOption_name_mutable_upb_arra } return arr; } -UPB_INLINE bool google_protobuf_UninterpretedOption_has_name(const google_protobuf_UninterpretedOption* msg) { - size_t size; - google_protobuf_UninterpretedOption_name(msg, &size); - return size != 0; -} UPB_INLINE void google_protobuf_UninterpretedOption_clear_identifier_value(google_protobuf_UninterpretedOption* msg) { const upb_MiniTableField field = {3, UPB_SIZE(8, 16), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; _upb_Message_ClearNonExtensionField(msg, &field); @@ -10325,11 +10160,6 @@ UPB_INLINE upb_Array* _google_protobuf_FeatureSetDefaults_defaults_mutable_upb_a } return arr; } -UPB_INLINE bool google_protobuf_FeatureSetDefaults_has_defaults(const google_protobuf_FeatureSetDefaults* msg) { - size_t size; - google_protobuf_FeatureSetDefaults_defaults(msg, &size); - return size != 0; -} UPB_INLINE void google_protobuf_FeatureSetDefaults_clear_minimum_edition(google_protobuf_FeatureSetDefaults* msg) { const upb_MiniTableField field = {4, UPB_SIZE(8, 4), 1, 1, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; _upb_Message_ClearNonExtensionField(msg, &field); @@ -10546,11 +10376,6 @@ UPB_INLINE upb_Array* _google_protobuf_SourceCodeInfo_location_mutable_upb_array } return arr; } -UPB_INLINE bool google_protobuf_SourceCodeInfo_has_location(const google_protobuf_SourceCodeInfo* msg) { - size_t size; - google_protobuf_SourceCodeInfo_location(msg, &size); - return size != 0; -} UPB_INLINE google_protobuf_SourceCodeInfo_Location** google_protobuf_SourceCodeInfo_mutable_location(google_protobuf_SourceCodeInfo* msg, size_t* size) { upb_MiniTableField field = {1, 0, 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -10646,11 +10471,6 @@ UPB_INLINE upb_Array* _google_protobuf_SourceCodeInfo_Location_path_mutable_upb_ } return arr; } -UPB_INLINE bool google_protobuf_SourceCodeInfo_Location_has_path(const google_protobuf_SourceCodeInfo_Location* msg) { - size_t size; - google_protobuf_SourceCodeInfo_Location_path(msg, &size); - return size != 0; -} UPB_INLINE void google_protobuf_SourceCodeInfo_Location_clear_span(google_protobuf_SourceCodeInfo_Location* msg) { const upb_MiniTableField field = {2, UPB_SIZE(8, 16), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsPacked | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; _upb_Message_ClearNonExtensionField(msg, &field); @@ -10683,11 +10503,6 @@ UPB_INLINE upb_Array* _google_protobuf_SourceCodeInfo_Location_span_mutable_upb_ } return arr; } -UPB_INLINE bool google_protobuf_SourceCodeInfo_Location_has_span(const google_protobuf_SourceCodeInfo_Location* msg) { - size_t size; - google_protobuf_SourceCodeInfo_Location_span(msg, &size); - return size != 0; -} UPB_INLINE void google_protobuf_SourceCodeInfo_Location_clear_leading_comments(google_protobuf_SourceCodeInfo_Location* msg) { const upb_MiniTableField field = {3, UPB_SIZE(16, 24), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; _upb_Message_ClearNonExtensionField(msg, &field); @@ -10750,11 +10565,6 @@ UPB_INLINE upb_Array* _google_protobuf_SourceCodeInfo_Location_leading_detached_ } return arr; } -UPB_INLINE bool google_protobuf_SourceCodeInfo_Location_has_leading_detached_comments(const google_protobuf_SourceCodeInfo_Location* msg) { - size_t size; - google_protobuf_SourceCodeInfo_Location_leading_detached_comments(msg, &size); - return size != 0; -} UPB_INLINE int32_t* google_protobuf_SourceCodeInfo_Location_mutable_path(google_protobuf_SourceCodeInfo_Location* msg, size_t* size) { upb_MiniTableField field = {1, UPB_SIZE(4, 8), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsPacked | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -10904,11 +10714,6 @@ UPB_INLINE upb_Array* _google_protobuf_GeneratedCodeInfo_annotation_mutable_upb_ } return arr; } -UPB_INLINE bool google_protobuf_GeneratedCodeInfo_has_annotation(const google_protobuf_GeneratedCodeInfo* msg) { - size_t size; - google_protobuf_GeneratedCodeInfo_annotation(msg, &size); - return size != 0; -} UPB_INLINE google_protobuf_GeneratedCodeInfo_Annotation** google_protobuf_GeneratedCodeInfo_mutable_annotation(google_protobuf_GeneratedCodeInfo* msg, size_t* size) { upb_MiniTableField field = {1, 0, 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -11004,11 +10809,6 @@ UPB_INLINE upb_Array* _google_protobuf_GeneratedCodeInfo_Annotation_path_mutable } return arr; } -UPB_INLINE bool google_protobuf_GeneratedCodeInfo_Annotation_has_path(const google_protobuf_GeneratedCodeInfo_Annotation* msg) { - size_t size; - google_protobuf_GeneratedCodeInfo_Annotation_path(msg, &size); - return size != 0; -} UPB_INLINE void google_protobuf_GeneratedCodeInfo_Annotation_clear_source_file(google_protobuf_GeneratedCodeInfo_Annotation* msg) { const upb_MiniTableField field = {2, UPB_SIZE(20, 24), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; _upb_Message_ClearNonExtensionField(msg, &field); diff --git a/upb/cmake/google/protobuf/descriptor.upb.h b/upb/cmake/google/protobuf/descriptor.upb.h index ecbab6561aebf..2b27131489017 100644 --- a/upb/cmake/google/protobuf/descriptor.upb.h +++ b/upb/cmake/google/protobuf/descriptor.upb.h @@ -252,11 +252,6 @@ UPB_INLINE upb_Array* _google_protobuf_FileDescriptorSet_file_mutable_upb_array( } return arr; } -UPB_INLINE bool google_protobuf_FileDescriptorSet_has_file(const google_protobuf_FileDescriptorSet* msg) { - size_t size; - google_protobuf_FileDescriptorSet_file(msg, &size); - return size != 0; -} UPB_INLINE google_protobuf_FileDescriptorProto** google_protobuf_FileDescriptorSet_mutable_file(google_protobuf_FileDescriptorSet* msg, size_t* size) { upb_MiniTableField field = {1, 0, 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -382,11 +377,6 @@ UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_dependency_mutable_up } return arr; } -UPB_INLINE bool google_protobuf_FileDescriptorProto_has_dependency(const google_protobuf_FileDescriptorProto* msg) { - size_t size; - google_protobuf_FileDescriptorProto_dependency(msg, &size); - return size != 0; -} UPB_INLINE void google_protobuf_FileDescriptorProto_clear_message_type(google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = {4, UPB_SIZE(8, 48), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; _upb_Message_ClearNonExtensionField(msg, &field); @@ -419,11 +409,6 @@ UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_message_type_mutable_ } return arr; } -UPB_INLINE bool google_protobuf_FileDescriptorProto_has_message_type(const google_protobuf_FileDescriptorProto* msg) { - size_t size; - google_protobuf_FileDescriptorProto_message_type(msg, &size); - return size != 0; -} UPB_INLINE void google_protobuf_FileDescriptorProto_clear_enum_type(google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = {5, UPB_SIZE(12, 56), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; _upb_Message_ClearNonExtensionField(msg, &field); @@ -456,11 +441,6 @@ UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_enum_type_mutable_upb } return arr; } -UPB_INLINE bool google_protobuf_FileDescriptorProto_has_enum_type(const google_protobuf_FileDescriptorProto* msg) { - size_t size; - google_protobuf_FileDescriptorProto_enum_type(msg, &size); - return size != 0; -} UPB_INLINE void google_protobuf_FileDescriptorProto_clear_service(google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = {6, UPB_SIZE(16, 64), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; _upb_Message_ClearNonExtensionField(msg, &field); @@ -493,11 +473,6 @@ UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_service_mutable_upb_a } return arr; } -UPB_INLINE bool google_protobuf_FileDescriptorProto_has_service(const google_protobuf_FileDescriptorProto* msg) { - size_t size; - google_protobuf_FileDescriptorProto_service(msg, &size); - return size != 0; -} UPB_INLINE void google_protobuf_FileDescriptorProto_clear_extension(google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = {7, UPB_SIZE(20, 72), 0, 3, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; _upb_Message_ClearNonExtensionField(msg, &field); @@ -530,11 +505,6 @@ UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_extension_mutable_upb } return arr; } -UPB_INLINE bool google_protobuf_FileDescriptorProto_has_extension(const google_protobuf_FileDescriptorProto* msg) { - size_t size; - google_protobuf_FileDescriptorProto_extension(msg, &size); - return size != 0; -} UPB_INLINE void google_protobuf_FileDescriptorProto_clear_options(google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = {8, UPB_SIZE(24, 80), 3, 4, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; _upb_Message_ClearNonExtensionField(msg, &field); @@ -597,11 +567,6 @@ UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_public_dependency_mut } return arr; } -UPB_INLINE bool google_protobuf_FileDescriptorProto_has_public_dependency(const google_protobuf_FileDescriptorProto* msg) { - size_t size; - google_protobuf_FileDescriptorProto_public_dependency(msg, &size); - return size != 0; -} UPB_INLINE void google_protobuf_FileDescriptorProto_clear_weak_dependency(google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = {11, UPB_SIZE(36, 104), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; _upb_Message_ClearNonExtensionField(msg, &field); @@ -634,11 +599,6 @@ UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_weak_dependency_mutab } return arr; } -UPB_INLINE bool google_protobuf_FileDescriptorProto_has_weak_dependency(const google_protobuf_FileDescriptorProto* msg) { - size_t size; - google_protobuf_FileDescriptorProto_weak_dependency(msg, &size); - return size != 0; -} UPB_INLINE void google_protobuf_FileDescriptorProto_clear_syntax(google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = {12, UPB_SIZE(60, 112), 5, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; _upb_Message_ClearNonExtensionField(msg, &field); @@ -969,11 +929,6 @@ UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_field_mutable_upb_array(c } return arr; } -UPB_INLINE bool google_protobuf_DescriptorProto_has_field(const google_protobuf_DescriptorProto* msg) { - size_t size; - google_protobuf_DescriptorProto_field(msg, &size); - return size != 0; -} UPB_INLINE void google_protobuf_DescriptorProto_clear_nested_type(google_protobuf_DescriptorProto* msg) { const upb_MiniTableField field = {3, UPB_SIZE(8, 32), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; _upb_Message_ClearNonExtensionField(msg, &field); @@ -1006,11 +961,6 @@ UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_nested_type_mutable_upb_a } return arr; } -UPB_INLINE bool google_protobuf_DescriptorProto_has_nested_type(const google_protobuf_DescriptorProto* msg) { - size_t size; - google_protobuf_DescriptorProto_nested_type(msg, &size); - return size != 0; -} UPB_INLINE void google_protobuf_DescriptorProto_clear_enum_type(google_protobuf_DescriptorProto* msg) { const upb_MiniTableField field = {4, UPB_SIZE(12, 40), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; _upb_Message_ClearNonExtensionField(msg, &field); @@ -1043,11 +993,6 @@ UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_enum_type_mutable_upb_arr } return arr; } -UPB_INLINE bool google_protobuf_DescriptorProto_has_enum_type(const google_protobuf_DescriptorProto* msg) { - size_t size; - google_protobuf_DescriptorProto_enum_type(msg, &size); - return size != 0; -} UPB_INLINE void google_protobuf_DescriptorProto_clear_extension_range(google_protobuf_DescriptorProto* msg) { const upb_MiniTableField field = {5, UPB_SIZE(16, 48), 0, 3, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; _upb_Message_ClearNonExtensionField(msg, &field); @@ -1080,11 +1025,6 @@ UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_extension_range_mutable_u } return arr; } -UPB_INLINE bool google_protobuf_DescriptorProto_has_extension_range(const google_protobuf_DescriptorProto* msg) { - size_t size; - google_protobuf_DescriptorProto_extension_range(msg, &size); - return size != 0; -} UPB_INLINE void google_protobuf_DescriptorProto_clear_extension(google_protobuf_DescriptorProto* msg) { const upb_MiniTableField field = {6, UPB_SIZE(20, 56), 0, 4, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; _upb_Message_ClearNonExtensionField(msg, &field); @@ -1117,11 +1057,6 @@ UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_extension_mutable_upb_arr } return arr; } -UPB_INLINE bool google_protobuf_DescriptorProto_has_extension(const google_protobuf_DescriptorProto* msg) { - size_t size; - google_protobuf_DescriptorProto_extension(msg, &size); - return size != 0; -} UPB_INLINE void google_protobuf_DescriptorProto_clear_options(google_protobuf_DescriptorProto* msg) { const upb_MiniTableField field = {7, UPB_SIZE(24, 64), 2, 5, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; _upb_Message_ClearNonExtensionField(msg, &field); @@ -1169,11 +1104,6 @@ UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_oneof_decl_mutable_upb_ar } return arr; } -UPB_INLINE bool google_protobuf_DescriptorProto_has_oneof_decl(const google_protobuf_DescriptorProto* msg) { - size_t size; - google_protobuf_DescriptorProto_oneof_decl(msg, &size); - return size != 0; -} UPB_INLINE void google_protobuf_DescriptorProto_clear_reserved_range(google_protobuf_DescriptorProto* msg) { const upb_MiniTableField field = {9, UPB_SIZE(32, 80), 0, 7, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; _upb_Message_ClearNonExtensionField(msg, &field); @@ -1206,11 +1136,6 @@ UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_reserved_range_mutable_up } return arr; } -UPB_INLINE bool google_protobuf_DescriptorProto_has_reserved_range(const google_protobuf_DescriptorProto* msg) { - size_t size; - google_protobuf_DescriptorProto_reserved_range(msg, &size); - return size != 0; -} UPB_INLINE void google_protobuf_DescriptorProto_clear_reserved_name(google_protobuf_DescriptorProto* msg) { const upb_MiniTableField field = {10, UPB_SIZE(36, 88), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; _upb_Message_ClearNonExtensionField(msg, &field); @@ -1243,11 +1168,6 @@ UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_reserved_name_mutable_upb } return arr; } -UPB_INLINE bool google_protobuf_DescriptorProto_has_reserved_name(const google_protobuf_DescriptorProto* msg) { - size_t size; - google_protobuf_DescriptorProto_reserved_name(msg, &size); - return size != 0; -} UPB_INLINE void google_protobuf_DescriptorProto_set_name(google_protobuf_DescriptorProto *msg, upb_StringView value) { const upb_MiniTableField field = {1, UPB_SIZE(40, 8), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; @@ -1716,11 +1636,6 @@ UPB_INLINE upb_Array* _google_protobuf_ExtensionRangeOptions_declaration_mutable } return arr; } -UPB_INLINE bool google_protobuf_ExtensionRangeOptions_has_declaration(const google_protobuf_ExtensionRangeOptions* msg) { - size_t size; - google_protobuf_ExtensionRangeOptions_declaration(msg, &size); - return size != 0; -} UPB_INLINE void google_protobuf_ExtensionRangeOptions_clear_verification(google_protobuf_ExtensionRangeOptions* msg) { const upb_MiniTableField field = {3, UPB_SIZE(8, 4), 1, 3, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; _upb_Message_ClearNonExtensionField(msg, &field); @@ -1783,11 +1698,6 @@ UPB_INLINE upb_Array* _google_protobuf_ExtensionRangeOptions_uninterpreted_optio } return arr; } -UPB_INLINE bool google_protobuf_ExtensionRangeOptions_has_uninterpreted_option(const google_protobuf_ExtensionRangeOptions* msg) { - size_t size; - google_protobuf_ExtensionRangeOptions_uninterpreted_option(msg, &size); - return size != 0; -} UPB_INLINE google_protobuf_ExtensionRangeOptions_Declaration** google_protobuf_ExtensionRangeOptions_mutable_declaration(google_protobuf_ExtensionRangeOptions* msg, size_t* size) { upb_MiniTableField field = {2, UPB_SIZE(4, 8), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -2409,11 +2319,6 @@ UPB_INLINE upb_Array* _google_protobuf_EnumDescriptorProto_value_mutable_upb_arr } return arr; } -UPB_INLINE bool google_protobuf_EnumDescriptorProto_has_value(const google_protobuf_EnumDescriptorProto* msg) { - size_t size; - google_protobuf_EnumDescriptorProto_value(msg, &size); - return size != 0; -} UPB_INLINE void google_protobuf_EnumDescriptorProto_clear_options(google_protobuf_EnumDescriptorProto* msg) { const upb_MiniTableField field = {3, UPB_SIZE(8, 32), 2, 1, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; _upb_Message_ClearNonExtensionField(msg, &field); @@ -2461,11 +2366,6 @@ UPB_INLINE upb_Array* _google_protobuf_EnumDescriptorProto_reserved_range_mutabl } return arr; } -UPB_INLINE bool google_protobuf_EnumDescriptorProto_has_reserved_range(const google_protobuf_EnumDescriptorProto* msg) { - size_t size; - google_protobuf_EnumDescriptorProto_reserved_range(msg, &size); - return size != 0; -} UPB_INLINE void google_protobuf_EnumDescriptorProto_clear_reserved_name(google_protobuf_EnumDescriptorProto* msg) { const upb_MiniTableField field = {5, UPB_SIZE(16, 48), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; _upb_Message_ClearNonExtensionField(msg, &field); @@ -2498,11 +2398,6 @@ UPB_INLINE upb_Array* _google_protobuf_EnumDescriptorProto_reserved_name_mutable } return arr; } -UPB_INLINE bool google_protobuf_EnumDescriptorProto_has_reserved_name(const google_protobuf_EnumDescriptorProto* msg) { - size_t size; - google_protobuf_EnumDescriptorProto_reserved_name(msg, &size); - return size != 0; -} UPB_INLINE void google_protobuf_EnumDescriptorProto_set_name(google_protobuf_EnumDescriptorProto *msg, upb_StringView value) { const upb_MiniTableField field = {1, UPB_SIZE(20, 8), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; @@ -2856,11 +2751,6 @@ UPB_INLINE upb_Array* _google_protobuf_ServiceDescriptorProto_method_mutable_upb } return arr; } -UPB_INLINE bool google_protobuf_ServiceDescriptorProto_has_method(const google_protobuf_ServiceDescriptorProto* msg) { - size_t size; - google_protobuf_ServiceDescriptorProto_method(msg, &size); - return size != 0; -} UPB_INLINE void google_protobuf_ServiceDescriptorProto_clear_options(google_protobuf_ServiceDescriptorProto* msg) { const upb_MiniTableField field = {3, UPB_SIZE(8, 32), 2, 1, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; _upb_Message_ClearNonExtensionField(msg, &field); @@ -3461,11 +3351,6 @@ UPB_INLINE upb_Array* _google_protobuf_FileOptions_uninterpreted_option_mutable_ } return arr; } -UPB_INLINE bool google_protobuf_FileOptions_has_uninterpreted_option(const google_protobuf_FileOptions* msg) { - size_t size; - google_protobuf_FileOptions_uninterpreted_option(msg, &size); - return size != 0; -} UPB_INLINE void google_protobuf_FileOptions_set_java_package(google_protobuf_FileOptions *msg, upb_StringView value) { const upb_MiniTableField field = {1, UPB_SIZE(28, 24), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; @@ -3743,11 +3628,6 @@ UPB_INLINE upb_Array* _google_protobuf_MessageOptions_uninterpreted_option_mutab } return arr; } -UPB_INLINE bool google_protobuf_MessageOptions_has_uninterpreted_option(const google_protobuf_MessageOptions* msg) { - size_t size; - google_protobuf_MessageOptions_uninterpreted_option(msg, &size); - return size != 0; -} UPB_INLINE void google_protobuf_MessageOptions_set_message_set_wire_format(google_protobuf_MessageOptions *msg, bool value) { const upb_MiniTableField field = {1, 1, 1, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; @@ -4010,11 +3890,6 @@ UPB_INLINE upb_Array* _google_protobuf_FieldOptions_targets_mutable_upb_array(co } return arr; } -UPB_INLINE bool google_protobuf_FieldOptions_has_targets(const google_protobuf_FieldOptions* msg) { - size_t size; - google_protobuf_FieldOptions_targets(msg, &size); - return size != 0; -} UPB_INLINE void google_protobuf_FieldOptions_clear_edition_defaults(google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {20, UPB_SIZE(28, 32), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; _upb_Message_ClearNonExtensionField(msg, &field); @@ -4047,11 +3922,6 @@ UPB_INLINE upb_Array* _google_protobuf_FieldOptions_edition_defaults_mutable_upb } return arr; } -UPB_INLINE bool google_protobuf_FieldOptions_has_edition_defaults(const google_protobuf_FieldOptions* msg) { - size_t size; - google_protobuf_FieldOptions_edition_defaults(msg, &size); - return size != 0; -} UPB_INLINE void google_protobuf_FieldOptions_clear_features(google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {21, UPB_SIZE(32, 40), 10, 1, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; _upb_Message_ClearNonExtensionField(msg, &field); @@ -4099,11 +3969,6 @@ UPB_INLINE upb_Array* _google_protobuf_FieldOptions_uninterpreted_option_mutable } return arr; } -UPB_INLINE bool google_protobuf_FieldOptions_has_uninterpreted_option(const google_protobuf_FieldOptions* msg) { - size_t size; - google_protobuf_FieldOptions_uninterpreted_option(msg, &size); - return size != 0; -} UPB_INLINE void google_protobuf_FieldOptions_set_ctype(google_protobuf_FieldOptions *msg, int32_t value) { const upb_MiniTableField field = {1, 4, 1, 3, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; @@ -4387,11 +4252,6 @@ UPB_INLINE upb_Array* _google_protobuf_OneofOptions_uninterpreted_option_mutable } return arr; } -UPB_INLINE bool google_protobuf_OneofOptions_has_uninterpreted_option(const google_protobuf_OneofOptions* msg) { - size_t size; - google_protobuf_OneofOptions_uninterpreted_option(msg, &size); - return size != 0; -} UPB_INLINE void google_protobuf_OneofOptions_set_features(google_protobuf_OneofOptions *msg, google_protobuf_FeatureSet* value) { const upb_MiniTableField field = {1, UPB_SIZE(4, 8), 1, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -4559,11 +4419,6 @@ UPB_INLINE upb_Array* _google_protobuf_EnumOptions_uninterpreted_option_mutable_ } return arr; } -UPB_INLINE bool google_protobuf_EnumOptions_has_uninterpreted_option(const google_protobuf_EnumOptions* msg) { - size_t size; - google_protobuf_EnumOptions_uninterpreted_option(msg, &size); - return size != 0; -} UPB_INLINE void google_protobuf_EnumOptions_set_allow_alias(google_protobuf_EnumOptions *msg, bool value) { const upb_MiniTableField field = {2, 1, 1, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; @@ -4728,11 +4583,6 @@ UPB_INLINE upb_Array* _google_protobuf_EnumValueOptions_uninterpreted_option_mut } return arr; } -UPB_INLINE bool google_protobuf_EnumValueOptions_has_uninterpreted_option(const google_protobuf_EnumValueOptions* msg) { - size_t size; - google_protobuf_EnumValueOptions_uninterpreted_option(msg, &size); - return size != 0; -} UPB_INLINE void google_protobuf_EnumValueOptions_set_deprecated(google_protobuf_EnumValueOptions *msg, bool value) { const upb_MiniTableField field = {1, 1, 1, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; @@ -4878,11 +4728,6 @@ UPB_INLINE upb_Array* _google_protobuf_ServiceOptions_uninterpreted_option_mutab } return arr; } -UPB_INLINE bool google_protobuf_ServiceOptions_has_uninterpreted_option(const google_protobuf_ServiceOptions* msg) { - size_t size; - google_protobuf_ServiceOptions_uninterpreted_option(msg, &size); - return size != 0; -} UPB_INLINE void google_protobuf_ServiceOptions_set_deprecated(google_protobuf_ServiceOptions *msg, bool value) { const upb_MiniTableField field = {33, 1, 1, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; @@ -5039,11 +4884,6 @@ UPB_INLINE upb_Array* _google_protobuf_MethodOptions_uninterpreted_option_mutabl } return arr; } -UPB_INLINE bool google_protobuf_MethodOptions_has_uninterpreted_option(const google_protobuf_MethodOptions* msg) { - size_t size; - google_protobuf_MethodOptions_uninterpreted_option(msg, &size); - return size != 0; -} UPB_INLINE void google_protobuf_MethodOptions_set_deprecated(google_protobuf_MethodOptions *msg, bool value) { const upb_MiniTableField field = {33, 1, 1, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; @@ -5159,11 +4999,6 @@ UPB_INLINE upb_Array* _google_protobuf_UninterpretedOption_name_mutable_upb_arra } return arr; } -UPB_INLINE bool google_protobuf_UninterpretedOption_has_name(const google_protobuf_UninterpretedOption* msg) { - size_t size; - google_protobuf_UninterpretedOption_name(msg, &size); - return size != 0; -} UPB_INLINE void google_protobuf_UninterpretedOption_clear_identifier_value(google_protobuf_UninterpretedOption* msg) { const upb_MiniTableField field = {3, UPB_SIZE(8, 16), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; _upb_Message_ClearNonExtensionField(msg, &field); @@ -5599,11 +5434,6 @@ UPB_INLINE upb_Array* _google_protobuf_FeatureSetDefaults_defaults_mutable_upb_a } return arr; } -UPB_INLINE bool google_protobuf_FeatureSetDefaults_has_defaults(const google_protobuf_FeatureSetDefaults* msg) { - size_t size; - google_protobuf_FeatureSetDefaults_defaults(msg, &size); - return size != 0; -} UPB_INLINE void google_protobuf_FeatureSetDefaults_clear_minimum_edition(google_protobuf_FeatureSetDefaults* msg) { const upb_MiniTableField field = {4, UPB_SIZE(8, 4), 1, 1, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; _upb_Message_ClearNonExtensionField(msg, &field); @@ -5820,11 +5650,6 @@ UPB_INLINE upb_Array* _google_protobuf_SourceCodeInfo_location_mutable_upb_array } return arr; } -UPB_INLINE bool google_protobuf_SourceCodeInfo_has_location(const google_protobuf_SourceCodeInfo* msg) { - size_t size; - google_protobuf_SourceCodeInfo_location(msg, &size); - return size != 0; -} UPB_INLINE google_protobuf_SourceCodeInfo_Location** google_protobuf_SourceCodeInfo_mutable_location(google_protobuf_SourceCodeInfo* msg, size_t* size) { upb_MiniTableField field = {1, 0, 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -5920,11 +5745,6 @@ UPB_INLINE upb_Array* _google_protobuf_SourceCodeInfo_Location_path_mutable_upb_ } return arr; } -UPB_INLINE bool google_protobuf_SourceCodeInfo_Location_has_path(const google_protobuf_SourceCodeInfo_Location* msg) { - size_t size; - google_protobuf_SourceCodeInfo_Location_path(msg, &size); - return size != 0; -} UPB_INLINE void google_protobuf_SourceCodeInfo_Location_clear_span(google_protobuf_SourceCodeInfo_Location* msg) { const upb_MiniTableField field = {2, UPB_SIZE(8, 16), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsPacked | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; _upb_Message_ClearNonExtensionField(msg, &field); @@ -5957,11 +5777,6 @@ UPB_INLINE upb_Array* _google_protobuf_SourceCodeInfo_Location_span_mutable_upb_ } return arr; } -UPB_INLINE bool google_protobuf_SourceCodeInfo_Location_has_span(const google_protobuf_SourceCodeInfo_Location* msg) { - size_t size; - google_protobuf_SourceCodeInfo_Location_span(msg, &size); - return size != 0; -} UPB_INLINE void google_protobuf_SourceCodeInfo_Location_clear_leading_comments(google_protobuf_SourceCodeInfo_Location* msg) { const upb_MiniTableField field = {3, UPB_SIZE(16, 24), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; _upb_Message_ClearNonExtensionField(msg, &field); @@ -6024,11 +5839,6 @@ UPB_INLINE upb_Array* _google_protobuf_SourceCodeInfo_Location_leading_detached_ } return arr; } -UPB_INLINE bool google_protobuf_SourceCodeInfo_Location_has_leading_detached_comments(const google_protobuf_SourceCodeInfo_Location* msg) { - size_t size; - google_protobuf_SourceCodeInfo_Location_leading_detached_comments(msg, &size); - return size != 0; -} UPB_INLINE int32_t* google_protobuf_SourceCodeInfo_Location_mutable_path(google_protobuf_SourceCodeInfo_Location* msg, size_t* size) { upb_MiniTableField field = {1, UPB_SIZE(4, 8), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsPacked | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -6178,11 +5988,6 @@ UPB_INLINE upb_Array* _google_protobuf_GeneratedCodeInfo_annotation_mutable_upb_ } return arr; } -UPB_INLINE bool google_protobuf_GeneratedCodeInfo_has_annotation(const google_protobuf_GeneratedCodeInfo* msg) { - size_t size; - google_protobuf_GeneratedCodeInfo_annotation(msg, &size); - return size != 0; -} UPB_INLINE google_protobuf_GeneratedCodeInfo_Annotation** google_protobuf_GeneratedCodeInfo_mutable_annotation(google_protobuf_GeneratedCodeInfo* msg, size_t* size) { upb_MiniTableField field = {1, 0, 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -6278,11 +6083,6 @@ UPB_INLINE upb_Array* _google_protobuf_GeneratedCodeInfo_Annotation_path_mutable } return arr; } -UPB_INLINE bool google_protobuf_GeneratedCodeInfo_Annotation_has_path(const google_protobuf_GeneratedCodeInfo_Annotation* msg) { - size_t size; - google_protobuf_GeneratedCodeInfo_Annotation_path(msg, &size); - return size != 0; -} UPB_INLINE void google_protobuf_GeneratedCodeInfo_Annotation_clear_source_file(google_protobuf_GeneratedCodeInfo_Annotation* msg) { const upb_MiniTableField field = {2, UPB_SIZE(20, 24), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; _upb_Message_ClearNonExtensionField(msg, &field); From 14dd8e9ee04f84ab82f534a235ce8e542864b5ec Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Fri, 15 Dec 2023 11:05:56 -0800 Subject: [PATCH 033/255] Implement ExactSizeIterator and FusedIterator for repeated fields. PiperOrigin-RevId: 591306340 --- rust/repeated.rs | 9 +++++++++ rust/test/shared/accessors_repeated_test.rs | 1 + 2 files changed, 10 insertions(+) diff --git a/rust/repeated.rs b/rust/repeated.rs index 22d6fb98d909c..2753fcee2dde1 100644 --- a/rust/repeated.rs +++ b/rust/repeated.rs @@ -7,6 +7,7 @@ use std::fmt::{self, Debug}; use std::iter; +use std::iter::FusedIterator; /// Repeated scalar fields are implemented around the runtime-specific /// `RepeatedField` struct. `RepeatedField` stores an opaque pointer to the /// runtime-specific representation of a repeated scalar (`upb_Array*` on upb, @@ -367,6 +368,14 @@ where } } +impl<'msg, T: ?Sized + ProxiedInRepeated> ExactSizeIterator for RepeatedIter<'msg, T> { + fn len(&self) -> usize { + self.view.len() + } +} + +impl<'msg, T: ?Sized + ProxiedInRepeated> FusedIterator for RepeatedIter<'msg, T> {} + impl<'msg, T> iter::IntoIterator for RepeatedView<'msg, T> where T: ProxiedInRepeated + ?Sized + 'msg, diff --git a/rust/test/shared/accessors_repeated_test.rs b/rust/test/shared/accessors_repeated_test.rs index d0b9a3bc42968..1f44a52ac43ff 100644 --- a/rust/test/shared/accessors_repeated_test.rs +++ b/rust/test/shared/accessors_repeated_test.rs @@ -21,6 +21,7 @@ macro_rules! generate_repeated_numeric_test { let mut mutator = msg.[](); mutator.push(1 as $t); assert_that!(mutator.len(), eq(1)); + assert_that!(mutator.iter().len(), eq(1)); assert_that!(mutator.get(0), some(eq(1 as $t))); mutator.set(0, 2 as $t); assert_that!(mutator.get(0), some(eq(2 as $t))); From 481c4fede513a606f3cb061cc0ad0a839f21f781 Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Fri, 15 Dec 2023 12:34:37 -0800 Subject: [PATCH 034/255] Allow friendly use of Reflection::MutableRaw(), Reflection::MutableRawNonOneof(). PiperOrigin-RevId: 591330894 --- .../protobuf/generated_message_reflection.cc | 60 +++++++--------- src/google/protobuf/message.h | 71 ++++++++++++++----- 2 files changed, 79 insertions(+), 52 deletions(-) diff --git a/src/google/protobuf/generated_message_reflection.cc b/src/google/protobuf/generated_message_reflection.cc index 647b4cc747b80..164669cabe811 100644 --- a/src/google/protobuf/generated_message_reflection.cc +++ b/src/google/protobuf/generated_message_reflection.cc @@ -2659,20 +2659,6 @@ const FieldDescriptor* Reflection::FindKnownExtensionByNumber( // These simple template accessors obtain pointers (or references) to // the given field. -template -const Type& Reflection::GetRawNonOneof(const Message& message, - const FieldDescriptor* field) const { - const uint32_t field_offset = schema_.GetFieldOffsetNonOneof(field); - if (!schema_.IsSplit(field)) { - return GetConstRefAtOffset(message, field_offset); - } - const void* split = GetSplitField(&message); - if (SplitFieldHasExtraIndirection(field)) { - return **GetConstPointerAtOffset(split, field_offset); - } - return *GetConstPointerAtOffset(split, field_offset); -} - void Reflection::PrepareSplitMessageForWrite(Message* message) const { ABSL_DCHECK_NE(message, schema_.default_instance_); void** split = MutableSplitField(message); @@ -2705,38 +2691,42 @@ static Type* AllocIfDefault(const FieldDescriptor* field, Type*& ptr, return ptr; } -template -Type* Reflection::MutableRawNonOneof(Message* message, - const FieldDescriptor* field) const { +void* Reflection::MutableRawSplitImpl(Message* message, + const FieldDescriptor* field) const { + ABSL_DCHECK(!schema_.InRealOneof(field)) << "Field = " << field->full_name(); + const uint32_t field_offset = schema_.GetFieldOffsetNonOneof(field); - if (!schema_.IsSplit(field)) { - return GetPointerAtOffset(message, field_offset); - } PrepareSplitMessageForWrite(message); void** split = MutableSplitField(message); if (SplitFieldHasExtraIndirection(field)) { return AllocIfDefault(field, - *GetPointerAtOffset(*split, field_offset), + *GetPointerAtOffset(*split, field_offset), message->GetArena()); } - return GetPointerAtOffset(*split, field_offset); + return GetPointerAtOffset(*split, field_offset); } -template -Type* Reflection::MutableRaw(Message* message, - const FieldDescriptor* field) const { - const uint32_t field_offset = schema_.GetFieldOffset(field); - if (!schema_.IsSplit(field)) { - return GetPointerAtOffset(message, field_offset); +void* Reflection::MutableRawNonOneofImpl(Message* message, + const FieldDescriptor* field) const { + if (PROTOBUF_PREDICT_FALSE(schema_.IsSplit(field))) { + return MutableRawSplitImpl(message, field); } - PrepareSplitMessageForWrite(message); - void** split = MutableSplitField(message); - if (SplitFieldHasExtraIndirection(field)) { - return AllocIfDefault(field, - *GetPointerAtOffset(*split, field_offset), - message->GetArena()); + + const uint32_t field_offset = schema_.GetFieldOffsetNonOneof(field); + return GetPointerAtOffset(message, field_offset); +} + +void* Reflection::MutableRawImpl(Message* message, + const FieldDescriptor* field) const { + if (PROTOBUF_PREDICT_TRUE(!schema_.InRealOneof(field))) { + return MutableRawNonOneofImpl(message, field); } - return GetPointerAtOffset(*split, field_offset); + + // Oneof fields are not split. + ABSL_DCHECK(!schema_.IsSplit(field)); + + const uint32_t field_offset = schema_.GetFieldOffset(field); + return GetPointerAtOffset(message, field_offset); } const uint32_t* Reflection::GetHasBits(const Message& message) const { diff --git a/src/google/protobuf/message.h b/src/google/protobuf/message.h index d25c2d7815e22..f9e88d79d14f1 100644 --- a/src/google/protobuf/message.h +++ b/src/google/protobuf/message.h @@ -1105,19 +1105,34 @@ class PROTOBUF_EXPORT Reflection final { const T& GetRawNonOneof(const Message& message, const FieldDescriptor* field) const; template - T* MutableRawNonOneof(Message* message, const FieldDescriptor* field) const; - + const T& GetRawSplit(const Message& message, + const FieldDescriptor* field) const; template const Type& GetRaw(const Message& message, const FieldDescriptor* field) const; + + void* MutableRawNonOneofImpl(Message* message, + const FieldDescriptor* field) const; + void* MutableRawSplitImpl(Message* message, + const FieldDescriptor* field) const; + void* MutableRawImpl(Message* message, const FieldDescriptor* field) const; + template - inline Type* MutableRaw(Message* message, const FieldDescriptor* field) const; + Type* MutableRawNonOneof(Message* message, + const FieldDescriptor* field) const { + return reinterpret_cast(MutableRawNonOneofImpl(message, field)); + } + template + Type* MutableRaw(Message* message, const FieldDescriptor* field) const { + return reinterpret_cast(MutableRawImpl(message, field)); + } + template const Type& DefaultRaw(const FieldDescriptor* field) const; const Message* GetDefaultMessageInstance(const FieldDescriptor* field) const; - inline const uint32_t* GetHasBits(const Message& message) const; + const uint32_t* GetHasBits(const Message& message) const; inline uint32_t* MutableHasBits(Message* message) const; uint32_t GetOneofCase(const Message& message, const OneofDescriptor* oneof_descriptor) const; @@ -1136,9 +1151,8 @@ class PROTOBUF_EXPORT Reflection final { inline bool IsInlined(const FieldDescriptor* field) const; - inline bool HasBit(const Message& message, - const FieldDescriptor* field) const; - inline void SetBit(Message* message, const FieldDescriptor* field) const; + bool HasBit(const Message& message, const FieldDescriptor* field) const; + void SetBit(Message* message, const FieldDescriptor* field) const; inline void ClearBit(Message* message, const FieldDescriptor* field) const; inline void SwapBit(Message* message1, Message* message2, const FieldDescriptor* field) const; @@ -1188,8 +1202,7 @@ class PROTOBUF_EXPORT Reflection final { const FieldDescriptor* field) const; inline void SetOneofCase(Message* message, const FieldDescriptor* field) const; - inline void ClearOneofField(Message* message, - const FieldDescriptor* field) const; + void ClearOneofField(Message* message, const FieldDescriptor* field) const; template inline const Type& GetField(const Message& message, @@ -1546,21 +1559,45 @@ class RawMessageBase : public Message { } // namespace internal template -const Type& Reflection::GetRaw(const Message& message, - const FieldDescriptor* field) const { - ABSL_DCHECK(!schema_.InRealOneof(field) || HasOneofField(message, field)) - << "Field = " << field->full_name(); - const uint32_t field_offset = schema_.GetFieldOffset(field); - if (!schema_.IsSplit(field)) { - return internal::GetConstRefAtOffset(message, field_offset); - } +const Type& Reflection::GetRawSplit(const Message& message, + const FieldDescriptor* field) const { + ABSL_DCHECK(!schema_.InRealOneof(field)) << "Field = " << field->full_name(); + const void* split = GetSplitField(&message); + const uint32_t field_offset = schema_.GetFieldOffsetNonOneof(field); if (internal::SplitFieldHasExtraIndirectionStatic(field)) { return **internal::GetConstPointerAtOffset(split, field_offset); } return *internal::GetConstPointerAtOffset(split, field_offset); } +template +const Type& Reflection::GetRawNonOneof(const Message& message, + const FieldDescriptor* field) const { + if (PROTOBUF_PREDICT_FALSE(schema_.IsSplit(field))) { + return GetRawSplit(message, field); + } + const uint32_t field_offset = schema_.GetFieldOffsetNonOneof(field); + return internal::GetConstRefAtOffset(message, field_offset); +} + +template +const Type& Reflection::GetRaw(const Message& message, + const FieldDescriptor* field) const { + ABSL_DCHECK(!schema_.InRealOneof(field) || HasOneofField(message, field)) + << "Field = " << field->full_name(); + + if (PROTOBUF_PREDICT_TRUE(!schema_.InRealOneof(field))) { + return GetRawNonOneof(message, field); + } + + // Oneof fields are not split. + ABSL_DCHECK(!schema_.IsSplit(field)); + + const uint32_t field_offset = schema_.GetFieldOffset(field); + return internal::GetConstRefAtOffset(message, field_offset); +} + template RepeatedFieldRef Reflection::GetRepeatedFieldRef( const Message& message, const FieldDescriptor* field) const { From dc9d387d1d0751cbc736e7dfaef520176dbe74a8 Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Fri, 15 Dec 2023 23:30:01 -0800 Subject: [PATCH 035/255] Automated rollback of commit 481c4fede513a606f3cb061cc0ad0a839f21f781. PiperOrigin-RevId: 591451121 --- .../protobuf/generated_message_reflection.cc | 60 +++++++++------- src/google/protobuf/message.h | 71 +++++-------------- 2 files changed, 52 insertions(+), 79 deletions(-) diff --git a/src/google/protobuf/generated_message_reflection.cc b/src/google/protobuf/generated_message_reflection.cc index 164669cabe811..647b4cc747b80 100644 --- a/src/google/protobuf/generated_message_reflection.cc +++ b/src/google/protobuf/generated_message_reflection.cc @@ -2659,6 +2659,20 @@ const FieldDescriptor* Reflection::FindKnownExtensionByNumber( // These simple template accessors obtain pointers (or references) to // the given field. +template +const Type& Reflection::GetRawNonOneof(const Message& message, + const FieldDescriptor* field) const { + const uint32_t field_offset = schema_.GetFieldOffsetNonOneof(field); + if (!schema_.IsSplit(field)) { + return GetConstRefAtOffset(message, field_offset); + } + const void* split = GetSplitField(&message); + if (SplitFieldHasExtraIndirection(field)) { + return **GetConstPointerAtOffset(split, field_offset); + } + return *GetConstPointerAtOffset(split, field_offset); +} + void Reflection::PrepareSplitMessageForWrite(Message* message) const { ABSL_DCHECK_NE(message, schema_.default_instance_); void** split = MutableSplitField(message); @@ -2691,42 +2705,38 @@ static Type* AllocIfDefault(const FieldDescriptor* field, Type*& ptr, return ptr; } -void* Reflection::MutableRawSplitImpl(Message* message, - const FieldDescriptor* field) const { - ABSL_DCHECK(!schema_.InRealOneof(field)) << "Field = " << field->full_name(); - +template +Type* Reflection::MutableRawNonOneof(Message* message, + const FieldDescriptor* field) const { const uint32_t field_offset = schema_.GetFieldOffsetNonOneof(field); + if (!schema_.IsSplit(field)) { + return GetPointerAtOffset(message, field_offset); + } PrepareSplitMessageForWrite(message); void** split = MutableSplitField(message); if (SplitFieldHasExtraIndirection(field)) { return AllocIfDefault(field, - *GetPointerAtOffset(*split, field_offset), + *GetPointerAtOffset(*split, field_offset), message->GetArena()); } - return GetPointerAtOffset(*split, field_offset); + return GetPointerAtOffset(*split, field_offset); } -void* Reflection::MutableRawNonOneofImpl(Message* message, - const FieldDescriptor* field) const { - if (PROTOBUF_PREDICT_FALSE(schema_.IsSplit(field))) { - return MutableRawSplitImpl(message, field); +template +Type* Reflection::MutableRaw(Message* message, + const FieldDescriptor* field) const { + const uint32_t field_offset = schema_.GetFieldOffset(field); + if (!schema_.IsSplit(field)) { + return GetPointerAtOffset(message, field_offset); } - - const uint32_t field_offset = schema_.GetFieldOffsetNonOneof(field); - return GetPointerAtOffset(message, field_offset); -} - -void* Reflection::MutableRawImpl(Message* message, - const FieldDescriptor* field) const { - if (PROTOBUF_PREDICT_TRUE(!schema_.InRealOneof(field))) { - return MutableRawNonOneofImpl(message, field); + PrepareSplitMessageForWrite(message); + void** split = MutableSplitField(message); + if (SplitFieldHasExtraIndirection(field)) { + return AllocIfDefault(field, + *GetPointerAtOffset(*split, field_offset), + message->GetArena()); } - - // Oneof fields are not split. - ABSL_DCHECK(!schema_.IsSplit(field)); - - const uint32_t field_offset = schema_.GetFieldOffset(field); - return GetPointerAtOffset(message, field_offset); + return GetPointerAtOffset(*split, field_offset); } const uint32_t* Reflection::GetHasBits(const Message& message) const { diff --git a/src/google/protobuf/message.h b/src/google/protobuf/message.h index f9e88d79d14f1..d25c2d7815e22 100644 --- a/src/google/protobuf/message.h +++ b/src/google/protobuf/message.h @@ -1105,34 +1105,19 @@ class PROTOBUF_EXPORT Reflection final { const T& GetRawNonOneof(const Message& message, const FieldDescriptor* field) const; template - const T& GetRawSplit(const Message& message, - const FieldDescriptor* field) const; + T* MutableRawNonOneof(Message* message, const FieldDescriptor* field) const; + template const Type& GetRaw(const Message& message, const FieldDescriptor* field) const; - - void* MutableRawNonOneofImpl(Message* message, - const FieldDescriptor* field) const; - void* MutableRawSplitImpl(Message* message, - const FieldDescriptor* field) const; - void* MutableRawImpl(Message* message, const FieldDescriptor* field) const; - template - Type* MutableRawNonOneof(Message* message, - const FieldDescriptor* field) const { - return reinterpret_cast(MutableRawNonOneofImpl(message, field)); - } - template - Type* MutableRaw(Message* message, const FieldDescriptor* field) const { - return reinterpret_cast(MutableRawImpl(message, field)); - } - + inline Type* MutableRaw(Message* message, const FieldDescriptor* field) const; template const Type& DefaultRaw(const FieldDescriptor* field) const; const Message* GetDefaultMessageInstance(const FieldDescriptor* field) const; - const uint32_t* GetHasBits(const Message& message) const; + inline const uint32_t* GetHasBits(const Message& message) const; inline uint32_t* MutableHasBits(Message* message) const; uint32_t GetOneofCase(const Message& message, const OneofDescriptor* oneof_descriptor) const; @@ -1151,8 +1136,9 @@ class PROTOBUF_EXPORT Reflection final { inline bool IsInlined(const FieldDescriptor* field) const; - bool HasBit(const Message& message, const FieldDescriptor* field) const; - void SetBit(Message* message, const FieldDescriptor* field) const; + inline bool HasBit(const Message& message, + const FieldDescriptor* field) const; + inline void SetBit(Message* message, const FieldDescriptor* field) const; inline void ClearBit(Message* message, const FieldDescriptor* field) const; inline void SwapBit(Message* message1, Message* message2, const FieldDescriptor* field) const; @@ -1202,7 +1188,8 @@ class PROTOBUF_EXPORT Reflection final { const FieldDescriptor* field) const; inline void SetOneofCase(Message* message, const FieldDescriptor* field) const; - void ClearOneofField(Message* message, const FieldDescriptor* field) const; + inline void ClearOneofField(Message* message, + const FieldDescriptor* field) const; template inline const Type& GetField(const Message& message, @@ -1558,44 +1545,20 @@ class RawMessageBase : public Message { } // namespace internal -template -const Type& Reflection::GetRawSplit(const Message& message, - const FieldDescriptor* field) const { - ABSL_DCHECK(!schema_.InRealOneof(field)) << "Field = " << field->full_name(); - - const void* split = GetSplitField(&message); - const uint32_t field_offset = schema_.GetFieldOffsetNonOneof(field); - if (internal::SplitFieldHasExtraIndirectionStatic(field)) { - return **internal::GetConstPointerAtOffset(split, field_offset); - } - return *internal::GetConstPointerAtOffset(split, field_offset); -} - -template -const Type& Reflection::GetRawNonOneof(const Message& message, - const FieldDescriptor* field) const { - if (PROTOBUF_PREDICT_FALSE(schema_.IsSplit(field))) { - return GetRawSplit(message, field); - } - const uint32_t field_offset = schema_.GetFieldOffsetNonOneof(field); - return internal::GetConstRefAtOffset(message, field_offset); -} - template const Type& Reflection::GetRaw(const Message& message, const FieldDescriptor* field) const { ABSL_DCHECK(!schema_.InRealOneof(field) || HasOneofField(message, field)) << "Field = " << field->full_name(); - - if (PROTOBUF_PREDICT_TRUE(!schema_.InRealOneof(field))) { - return GetRawNonOneof(message, field); - } - - // Oneof fields are not split. - ABSL_DCHECK(!schema_.IsSplit(field)); - const uint32_t field_offset = schema_.GetFieldOffset(field); - return internal::GetConstRefAtOffset(message, field_offset); + if (!schema_.IsSplit(field)) { + return internal::GetConstRefAtOffset(message, field_offset); + } + const void* split = GetSplitField(&message); + if (internal::SplitFieldHasExtraIndirectionStatic(field)) { + return **internal::GetConstPointerAtOffset(split, field_offset); + } + return *internal::GetConstPointerAtOffset(split, field_offset); } template From bacf61a3ef03a23d00abec06bc0357408ed16ef6 Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Mon, 18 Dec 2023 05:37:12 -0800 Subject: [PATCH 036/255] Remove unnecessary duplicative +Sized PiperOrigin-RevId: 591868644 --- rust/proxied.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust/proxied.rs b/rust/proxied.rs index 896aba6fe6b79..2b839fa2fb5b3 100644 --- a/rust/proxied.rs +++ b/rust/proxied.rs @@ -90,7 +90,7 @@ pub type Mut<'msg, T> = ::Mut<'msg>; /// /// This trait is intentionally made non-object-safe to prevent a potential /// future incompatible change. -pub trait ViewProxy<'msg>: 'msg + Sized + Sync + Unpin + Sized + Debug { +pub trait ViewProxy<'msg>: 'msg + Sync + Unpin + Sized + Debug { type Proxied: 'msg + Proxied + ?Sized; /// Converts a borrow into a `View` with the lifetime of that borrow. From 9e9c727881e723f13b382aa7e976243c745813cc Mon Sep 17 00:00:00 2001 From: Alyssa Haroldsen Date: Mon, 18 Dec 2023 10:09:29 -0800 Subject: [PATCH 037/255] Expose primitive internals just enough for enums PiperOrigin-RevId: 591933966 --- rust/internal.rs | 2 +- rust/primitive.rs | 28 ++++++++++++++++++++++------ rust/vtable.rs | 8 ++++---- 3 files changed, 27 insertions(+), 11 deletions(-) diff --git a/rust/internal.rs b/rust/internal.rs index 2b7676b2d3fca..6a6ca3007a05c 100644 --- a/rust/internal.rs +++ b/rust/internal.rs @@ -11,7 +11,7 @@ pub use crate::vtable::{ new_vtable_field_entry, BytesMutVTable, BytesOptionalMutVTable, PrimitiveOptionalMutVTable, - PrimitiveVTable, PrimitiveWithRawVTable, RawVTableMutator, + PrimitiveVTable, PrimitiveWithRawVTable, RawVTableMutator, RawVTableOptionalMutatorData, }; use std::ptr::NonNull; use std::slice; diff --git a/rust/primitive.rs b/rust/primitive.rs index 193901bb4b443..7c34795c9a608 100644 --- a/rust/primitive.rs +++ b/rust/primitive.rs @@ -45,12 +45,20 @@ impl<'msg, T> PrimitiveMut<'msg, T> where T: PrimitiveWithRawVTable, { + /// Gets the current value of the field. pub fn get(&self) -> View<'_, T> { T::make_view(Private, self.inner) } + /// Sets a new value for the field. pub fn set(&mut self, val: impl SettableValue) { - MutProxy::set(self, val) + val.set_on(Private, self.as_mut()) + } + + #[doc(hidden)] + pub fn set_primitive(&mut self, _private: Private, value: T) { + // SAFETY: the raw mutator is valid for `'msg` as enforced by `Mut` + unsafe { self.inner.set(value) } } } @@ -106,9 +114,17 @@ macro_rules! impl_singular_primitives { } impl SettableValue<$t> for $t { - fn set_on<'msg>(self, _private: Private, mutator: Mut<'msg, $t>) where $t: 'msg { - // SAFETY: the raw mutator is valid for `'msg` as enforced by `Mut` - unsafe { mutator.inner.set(self) } + fn set_on<'msg>(self, private: Private, mut mutator: Mut<'msg, $t>) where $t: 'msg { + mutator.set_primitive(private, self) + } + + fn set_on_absent( + self, + _private: Private, + absent_mutator: <$t as ProxiedWithPresence>::PresentMutData<'_>, + ) -> <$t as ProxiedWithPresence>::AbsentMutData<'_> + { + absent_mutator.set(Private, self) } } @@ -119,13 +135,13 @@ macro_rules! impl_singular_primitives { fn clear_present_field( present_mutator: Self::PresentMutData<'_>, ) -> Self::AbsentMutData<'_> { - present_mutator.clear() + present_mutator.clear(Private) } fn set_absent_to_default( absent_mutator: Self::AbsentMutData<'_>, ) -> Self::PresentMutData<'_> { - absent_mutator.set_absent_to_default() + absent_mutator.set_absent_to_default(Private) } } diff --git a/rust/vtable.rs b/rust/vtable.rs index 311809608369b..5adca11799def 100644 --- a/rust/vtable.rs +++ b/rust/vtable.rs @@ -482,14 +482,14 @@ impl RawVTableMutator<'_, T> { } impl<'msg, T: PrimitiveWithRawVTable> RawVTableOptionalMutatorData<'msg, T> { - pub(crate) fn set_absent_to_default(self) -> Self { + pub fn set_absent_to_default(self, private: Private) -> Self { // SAFETY: // - `msg_ref` is valid for the lifetime of `RawVTableOptionalMutatorData` as // promised by the caller of `new`. - self.set(self.optional_vtable().default) + self.set(private, self.optional_vtable().default) } - pub(crate) fn set(self, val: T) -> Self { + pub fn set(self, _private: Private, val: T) -> Self { // SAFETY: // - `msg_ref` is valid for the lifetime of `RawVTableOptionalMutatorData` as // promised by the caller of `new`. @@ -497,7 +497,7 @@ impl<'msg, T: PrimitiveWithRawVTable> RawVTableOptionalMutatorData<'msg, T> { self } - pub(crate) fn clear(self) -> Self { + pub fn clear(self, _private: Private) -> Self { // SAFETY: // - `msg_ref` is valid for the lifetime of `RawVTableOptionalMutatorData` as // promised by the caller of `new`. From fcf0d01694af8d0628ea9d750476c4915f41e9cf Mon Sep 17 00:00:00 2001 From: Alyssa Haroldsen Date: Mon, 18 Dec 2023 10:13:01 -0800 Subject: [PATCH 038/255] Expose repeated _unchecked accessors, interior accessor These are both used by the enum implementation. PiperOrigin-RevId: 591935057 --- rust/repeated.rs | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/rust/repeated.rs b/rust/repeated.rs index 2753fcee2dde1..91ef0ae2d485d 100644 --- a/rust/repeated.rs +++ b/rust/repeated.rs @@ -89,19 +89,37 @@ where Self { raw, _phantom: PhantomData } } + /// Gets the length of the repeated field. pub fn len(&self) -> usize { T::repeated_len(*self) } + + /// Returns true if the repeated field has no values. pub fn is_empty(&self) -> bool { self.len() == 0 } + + /// Gets the value at `index`. + /// + /// Returns `None` if `index > len`. pub fn get(self, index: usize) -> Option> { if index >= self.len() { return None; } // SAFETY: `index` has been checked to be in-bounds - Some(unsafe { T::repeated_get_unchecked(self, index) }) + Some(unsafe { self.get_unchecked(index) }) + } + + /// Gets the value at `index` without bounds-checking. + /// + /// # Safety + /// Undefined behavior if `index >= len` + pub unsafe fn get_unchecked(self, index: usize) -> View<'msg, T> { + // SAFETY: in-bounds as promised + unsafe { T::repeated_get_unchecked(self, index) } } + + /// Iterates over the values in the repeated field. pub fn iter(self) -> RepeatedIter<'msg, T> { self.into_iter() } @@ -120,6 +138,13 @@ where Self { inner, _phantom: PhantomData } } + /// # Safety + /// - The return value must not be mutated through without synchronization. + #[allow(dead_code)] + pub(crate) unsafe fn into_inner(self) -> InnerRepeatedMut<'msg> { + self.inner + } + #[doc(hidden)] pub fn as_raw(&mut self, _private: Private) -> RawRepeatedField { self.inner.raw @@ -140,6 +165,15 @@ where panic!("index {index} >= repeated len {len}"); } // SAFETY: `index` has been checked to be in-bounds. + unsafe { self.set_unchecked(index, val) } + } + + /// Sets the value at `index` to the value `val`. + /// + /// # Safety + /// Undefined behavior if `index >= len` + pub unsafe fn set_unchecked(&mut self, index: usize, val: View) { + // SAFETY: `index` is in-bounds as promised by the caller. unsafe { T::repeated_set_unchecked(self.as_mut(), index, val) } } From e0e88dea640da3710bd9fd2c3d8ad7b284dd7d9d Mon Sep 17 00:00:00 2001 From: John Cater Date: Mon, 18 Dec 2023 10:29:13 -0800 Subject: [PATCH 039/255] Remove uses of `incompatible_use_toolchain_transition`. Now that Bazel 7.0 has been released, it's time to remove this tech debt. This has been a no-op since Bazel 5.0, I've been waiting to remove the code for two years, it's time. Part of https://github.com/bazelbuild/bazel/issues/14127. PiperOrigin-RevId: 591940644 --- protobuf_release.bzl | 64 +++++++++++++++++++++----------------------- rust/aspects.bzl | 1 - 2 files changed, 31 insertions(+), 34 deletions(-) diff --git a/protobuf_release.bzl b/protobuf_release.bzl index 327ae9a0a094e..a79a303b20ea2 100644 --- a/protobuf_release.bzl +++ b/protobuf_release.bzl @@ -7,44 +7,42 @@ load("@bazel_tools//tools/cpp:toolchain_utils.bzl", "find_cpp_toolchain") load(":protobuf_version.bzl", "PROTOC_VERSION") def _package_naming_impl(ctx): - values = {} - values["version"] = PROTOC_VERSION - - # infer from the current cpp toolchain. - toolchain = find_cpp_toolchain(ctx) - cpu = toolchain.cpu - system_name = toolchain.target_gnu_system_name - - # rename cpus to match what we want artifacts to be - if cpu == "systemz": - cpu = "s390_64" - elif cpu == "aarch64": - cpu = "aarch_64" - elif cpu == "ppc64": - cpu = "ppcle_64" - - # use the system name to determine the os and then create platform names - if "apple" in system_name: - values["platform"] = "osx-" + cpu - elif "linux" in system_name: - values["platform"] = "linux-" + cpu - elif "mingw" in system_name: - if cpu == "x86_64": - values["platform"] = "win64" + values = {} + values["version"] = PROTOC_VERSION + + # infer from the current cpp toolchain. + toolchain = find_cpp_toolchain(ctx) + cpu = toolchain.cpu + system_name = toolchain.target_gnu_system_name + + # rename cpus to match what we want artifacts to be + if cpu == "systemz": + cpu = "s390_64" + elif cpu == "aarch64": + cpu = "aarch_64" + elif cpu == "ppc64": + cpu = "ppcle_64" + + # use the system name to determine the os and then create platform names + if "apple" in system_name: + values["platform"] = "osx-" + cpu + elif "linux" in system_name: + values["platform"] = "linux-" + cpu + elif "mingw" in system_name: + if cpu == "x86_64": + values["platform"] = "win64" + else: + values["platform"] = "win32" else: - values["platform"] = "win32" - else: - values["platform"] = "unknown" - - return PackageVariablesInfo(values = values) + values["platform"] = "unknown" + return PackageVariablesInfo(values = values) package_naming = rule( - implementation = _package_naming_impl, + implementation = _package_naming_impl, attrs = { - # Necessary data dependency for find_cpp_toolchain. - "_cc_toolchain": attr.label(default = Label("@bazel_tools//tools/cpp:current_cc_toolchain")), + # Necessary data dependency for find_cpp_toolchain. + "_cc_toolchain": attr.label(default = Label("@bazel_tools//tools/cpp:current_cc_toolchain")), }, toolchains = ["@bazel_tools//tools/cpp:toolchain_type"], - incompatible_use_toolchain_transition = True, ) diff --git a/rust/aspects.bzl b/rust/aspects.bzl index a91cede87f7c1..0399c12c6d7b1 100644 --- a/rust/aspects.bzl +++ b/rust/aspects.bzl @@ -327,7 +327,6 @@ def _make_proto_library_aspect(is_upb): "@rules_rust//rust:toolchain_type", "@bazel_tools//tools/cpp:toolchain_type", ], - incompatible_use_toolchain_transition = True, ) rust_upb_proto_library_aspect = _make_proto_library_aspect(is_upb = True) From cdcb6e7b56649941129943a322355bfb1f961b5d Mon Sep 17 00:00:00 2001 From: Hong Shin Date: Mon, 18 Dec 2023 10:38:22 -0800 Subject: [PATCH 040/255] Remove warning about unused thunk in singular_scalar Only emit clearer when the field has presence, lest we get a warning about an unused thunk PiperOrigin-RevId: 591943572 --- .../rust/accessors/singular_scalar.cc | 39 ++++++++++--------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/src/google/protobuf/compiler/rust/accessors/singular_scalar.cc b/src/google/protobuf/compiler/rust/accessors/singular_scalar.cc index db28e7e1ec4c1..bf4d2c2d6a825 100644 --- a/src/google/protobuf/compiler/rust/accessors/singular_scalar.cc +++ b/src/google/protobuf/compiler/rust/accessors/singular_scalar.cc @@ -115,24 +115,25 @@ void SingularScalar::InMsgImpl(Context field) const { } void SingularScalar::InExternC(Context field) const { - field.Emit( - {{"Scalar", PrimitiveRsTypeName(field.desc())}, - {"hazzer_thunk", Thunk(field, "has")}, - {"getter_thunk", Thunk(field, "get")}, - {"setter_thunk", Thunk(field, "set")}, - {"clearer_thunk", Thunk(field, "clear")}, - {"hazzer", - [&] { - if (field.desc().has_presence()) { - field.Emit( - R"rs(fn $hazzer_thunk$(raw_msg: $pbi$::RawMessage) -> bool;)rs"); - } - }}}, - R"rs( - $hazzer$ + field.Emit({{"Scalar", PrimitiveRsTypeName(field.desc())}, + {"hazzer_thunk", Thunk(field, "has")}, + {"getter_thunk", Thunk(field, "get")}, + {"setter_thunk", Thunk(field, "set")}, + {"clearer_thunk", Thunk(field, "clear")}, + {"hazzer_and_clearer", + [&] { + if (field.desc().has_presence()) { + field.Emit( + R"rs( + fn $hazzer_thunk$(raw_msg: $pbi$::RawMessage) -> bool; + fn $clearer_thunk$(raw_msg: $pbi$::RawMessage); + )rs"); + } + }}}, + R"rs( + $hazzer_and_clearer$ fn $getter_thunk$(raw_msg: $pbi$::RawMessage) -> $Scalar$; fn $setter_thunk$(raw_msg: $pbi$::RawMessage, val: $Scalar$); - fn $clearer_thunk$(raw_msg: $pbi$::RawMessage); )rs"); } @@ -145,23 +146,23 @@ void SingularScalar::InThunkCc(Context field) const { {"getter_thunk", Thunk(field, "get")}, {"setter_thunk", Thunk(field, "set")}, {"clearer_thunk", Thunk(field, "clear")}, - {"hazzer", + {"hazzer_and_clearer", [&] { if (field.desc().has_presence()) { field.Emit(R"cc( bool $hazzer_thunk$($QualifiedMsg$* msg) { return msg->has_$field$(); } + void $clearer_thunk$($QualifiedMsg$* msg) { msg->clear_$field$(); } )cc"); } }}}, R"cc( - $hazzer$; + $hazzer_and_clearer$; $Scalar$ $getter_thunk$($QualifiedMsg$* msg) { return msg->$field$(); } void $setter_thunk$($QualifiedMsg$* msg, $Scalar$ val) { msg->set_$field$(val); } - void $clearer_thunk$($QualifiedMsg$* msg) { msg->clear_$field$(); } )cc"); } From 52ee6197339b71e209029a3ee0ae3166bb7a2fd4 Mon Sep 17 00:00:00 2001 From: Hong Shin Date: Mon, 18 Dec 2023 15:11:57 -0800 Subject: [PATCH 041/255] Migrate all remaining instances of assert_eq! to googletest-rust sans strings PiperOrigin-RevId: 592022421 --- rust/proxied.rs | 13 +++++++------ rust/test/cpp/interop/BUILD | 1 + rust/test/cpp/interop/main.rs | 7 ++++--- rust/test/shared/accessors_proto3_test.rs | 4 ++-- rust/test/shared/accessors_test.rs | 4 ++-- rust/utf8.rs | 5 +++-- 6 files changed, 19 insertions(+), 15 deletions(-) diff --git a/rust/proxied.rs b/rust/proxied.rs index 2b839fa2fb5b3..3d1031528e453 100644 --- a/rust/proxied.rs +++ b/rust/proxied.rs @@ -289,6 +289,7 @@ where #[cfg(test)] mod tests { use super::*; + use googletest::prelude::*; use std::borrow::Cow; #[derive(Debug, Default, PartialEq)] @@ -414,7 +415,7 @@ mod tests { let my_view = my_proxied.as_view(); - assert_eq!(my_view.val(), my_proxied.val); + assert_that!(my_view.val(), eq(&my_proxied.val)); } #[test] @@ -425,8 +426,8 @@ mod tests { my_mut.set("Hello indeed".to_string()); let val_after_set = my_mut.as_view().val().to_string(); - assert_eq!(my_proxied.val, val_after_set); - assert_eq!(my_proxied.val, "Hello indeed"); + assert_that!(my_proxied.val, eq(val_after_set)); + assert_that!(my_proxied.val, eq("Hello indeed")); } fn reborrow_mut_into_view<'msg>(x: Mut<'msg, MyProxied>) -> View<'msg, MyProxied> { @@ -557,12 +558,12 @@ mod tests { fn test_set() { let mut my_proxied = MyProxied::default(); my_proxied.as_mut().set("hello"); - assert_eq!(my_proxied.as_view().val(), "hello"); + assert_that!(my_proxied.as_view().val(), eq("hello")); my_proxied.as_mut().set(String::from("hello2")); - assert_eq!(my_proxied.as_view().val(), "hello2"); + assert_that!(my_proxied.as_view().val(), eq("hello2")); my_proxied.as_mut().set(Cow::Borrowed("hello3")); - assert_eq!(my_proxied.as_view().val(), "hello3"); + assert_that!(my_proxied.as_view().val(), eq("hello3")); } } diff --git a/rust/test/cpp/interop/BUILD b/rust/test/cpp/interop/BUILD index 1a4d88d640f9a..bacd078cf0d3f 100644 --- a/rust/test/cpp/interop/BUILD +++ b/rust/test/cpp/interop/BUILD @@ -21,6 +21,7 @@ rust_test( ], deps = [ ":test_utils", + "@crate_index//:googletest", "//rust:protobuf_cpp", "//rust/test:unittest_cc_rust_proto", ], diff --git a/rust/test/cpp/interop/main.rs b/rust/test/cpp/interop/main.rs index c95ceea03a564..f8c4a521f7b85 100644 --- a/rust/test/cpp/interop/main.rs +++ b/rust/test/cpp/interop/main.rs @@ -5,6 +5,7 @@ // license that can be found in the LICENSE file or at // https://developers.google.com/open-source/licenses/bsd +use googletest::prelude::*; use protobuf_cpp::__internal::PtrAndLen; use protobuf_cpp::__internal::RawMessage; use unittest_proto::proto2_unittest::TestAllExtensions; @@ -15,9 +16,9 @@ macro_rules! proto_assert_eq { let lhs = &$lhs; let rhs = &$rhs; - assert_eq!(lhs.optional_int64(), rhs.optional_int64()); - assert_eq!(lhs.optional_bytes(), rhs.optional_bytes()); - assert_eq!(lhs.optional_bool(), rhs.optional_bool()); + assert_that!(lhs.optional_int64(), eq(rhs.optional_int64())); + assert_that!(lhs.optional_bytes(), eq(rhs.optional_bytes())); + assert_that!(lhs.optional_bool(), eq(rhs.optional_bool())); }}; } diff --git a/rust/test/shared/accessors_proto3_test.rs b/rust/test/shared/accessors_proto3_test.rs index 48424433d1e45..4369ae2903126 100644 --- a/rust/test/shared/accessors_proto3_test.rs +++ b/rust/test/shared/accessors_proto3_test.rs @@ -229,9 +229,9 @@ fn test_oneof_mut_accessors() { match msg.oneof_field_mut() { OneofUint32(mut v) => { - assert_eq!(v.get(), 7); + assert_that!(v.get(), eq(7)); v.set(8); - assert_eq!(v.get(), 8); + assert_that!(v.get(), eq(8)); } f => panic!("unexpected field_mut type! {:?}", f), } diff --git a/rust/test/shared/accessors_test.rs b/rust/test/shared/accessors_test.rs index 9f7d75ff53268..15758a1f2436a 100644 --- a/rust/test/shared/accessors_test.rs +++ b/rust/test/shared/accessors_test.rs @@ -713,9 +713,9 @@ fn test_oneof_mut_accessors() { match msg.oneof_field_mut() { OneofUint32(mut v) => { - assert_eq!(v.get(), 7); + assert_that!(v.get(), eq(7)); v.set(8); - assert_eq!(v.get(), 8); + assert_that!(v.get(), eq(8)); } f => panic!("unexpected field_mut type! {:?}", f), } diff --git a/rust/utf8.rs b/rust/utf8.rs index 56a1c20b93e07..a452e8f916264 100644 --- a/rust/utf8.rs +++ b/rust/utf8.rs @@ -31,6 +31,7 @@ use std::str::from_utf8_unchecked; /// # Examples /// /// ``` +/// use googletest::prelude::*; /// use utf8::Utf8Chunks; /// /// // An invalid UTF-8 string @@ -40,10 +41,10 @@ use std::str::from_utf8_unchecked; /// let chunk = Utf8Chunks::new(bytes).next().unwrap(); /// /// // The first three characters are valid UTF-8 -/// assert_eq!("foo", chunk.valid()); +/// assert_that!("foo", eq(chunk.valid())); /// /// // The fourth character is broken -/// assert_eq!(b"\xF1\x80", chunk.invalid()); +/// assert_that!(b"\xF1\x80", eq(chunk.invalid())); /// ``` #[derive(Clone, Debug, PartialEq, Eq)] pub struct Utf8Chunk<'a> { From 542ca772fad96ca085adbca2d1d45d7a11a839cc Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Mon, 18 Dec 2023 15:39:46 -0800 Subject: [PATCH 042/255] Decouple Context from the Descriptor PiperOrigin-RevId: 592029759 --- .../rust/accessors/accessor_generator.h | 63 ++-- .../compiler/rust/accessors/accessors.cc | 35 +- .../compiler/rust/accessors/accessors.h | 6 +- .../compiler/rust/accessors/helpers.cc | 42 ++- .../compiler/rust/accessors/helpers.h | 3 +- .../protobuf/compiler/rust/accessors/map.cc | 87 +++-- .../rust/accessors/repeated_scalar.cc | 124 +++---- .../rust/accessors/singular_message.cc | 85 ++--- .../rust/accessors/singular_scalar.cc | 112 +++--- .../rust/accessors/singular_string.cc | 139 ++++---- .../rust/accessors/unsupported_field.cc | 7 +- src/google/protobuf/compiler/rust/context.cc | 9 +- src/google/protobuf/compiler/rust/context.h | 42 +-- .../protobuf/compiler/rust/generator.cc | 165 +++++---- src/google/protobuf/compiler/rust/message.cc | 337 +++++++++--------- src/google/protobuf/compiler/rust/message.h | 4 +- src/google/protobuf/compiler/rust/naming.cc | 120 +++---- src/google/protobuf/compiler/rust/naming.h | 26 +- src/google/protobuf/compiler/rust/oneof.cc | 156 ++++---- src/google/protobuf/compiler/rust/oneof.h | 8 +- 20 files changed, 768 insertions(+), 802 deletions(-) diff --git a/src/google/protobuf/compiler/rust/accessors/accessor_generator.h b/src/google/protobuf/compiler/rust/accessors/accessor_generator.h index 442de3c7cca5e..6aad7bba23f99 100644 --- a/src/google/protobuf/compiler/rust/accessors/accessor_generator.h +++ b/src/google/protobuf/compiler/rust/accessors/accessor_generator.h @@ -26,25 +26,26 @@ class AccessorGenerator { AccessorGenerator() = default; virtual ~AccessorGenerator() = default; - AccessorGenerator(const AccessorGenerator &) = delete; - AccessorGenerator(AccessorGenerator &&) = delete; - AccessorGenerator &operator=(const AccessorGenerator &) = delete; - AccessorGenerator &operator=(AccessorGenerator &&) = delete; + AccessorGenerator(const AccessorGenerator&) = delete; + AccessorGenerator(AccessorGenerator&&) = delete; + AccessorGenerator& operator=(const AccessorGenerator&) = delete; + AccessorGenerator& operator=(AccessorGenerator&&) = delete; // Constructs a generator for the given field. // // Returns `nullptr` if there is no known generator for this field. - static std::unique_ptr For(Context field); + static std::unique_ptr For(Context& ctx, + const FieldDescriptor& field); - void GenerateMsgImpl(Context field) const { - InMsgImpl(field); + void GenerateMsgImpl(Context& ctx, const FieldDescriptor& field) const { + InMsgImpl(ctx, field); } - void GenerateExternC(Context field) const { - InExternC(field); + void GenerateExternC(Context& ctx, const FieldDescriptor& field) const { + InExternC(ctx, field); } - void GenerateThunkCc(Context field) const { - ABSL_CHECK(field.is_cpp()); - InThunkCc(field); + void GenerateThunkCc(Context& ctx, const FieldDescriptor& field) const { + ABSL_CHECK(ctx.is_cpp()); + InThunkCc(ctx, field); } private: @@ -54,53 +55,53 @@ class AccessorGenerator { // prologue to inject variables automatically. // Called inside the main inherent `impl Msg {}` block. - virtual void InMsgImpl(Context field) const {} + virtual void InMsgImpl(Context& ctx, const FieldDescriptor& field) const {} // Called inside of a message's `extern "C" {}` block. - virtual void InExternC(Context field) const {} + virtual void InExternC(Context& ctx, const FieldDescriptor& field) const {} // Called inside of an `extern "C" {}` block in the `.thunk.cc` file, if such // a file is being generated. - virtual void InThunkCc(Context field) const {} + virtual void InThunkCc(Context& ctx, const FieldDescriptor& field) const {} }; class SingularScalar final : public AccessorGenerator { public: ~SingularScalar() override = default; - void InMsgImpl(Context field) const override; - void InExternC(Context field) const override; - void InThunkCc(Context field) const override; + void InMsgImpl(Context& ctx, const FieldDescriptor& field) const override; + void InExternC(Context& ctx, const FieldDescriptor& field) const override; + void InThunkCc(Context& ctx, const FieldDescriptor& field) const override; }; class SingularString final : public AccessorGenerator { public: ~SingularString() override = default; - void InMsgImpl(Context field) const override; - void InExternC(Context field) const override; - void InThunkCc(Context field) const override; + void InMsgImpl(Context& ctx, const FieldDescriptor& field) const override; + void InExternC(Context& ctx, const FieldDescriptor& field) const override; + void InThunkCc(Context& ctx, const FieldDescriptor& field) const override; }; class SingularMessage final : public AccessorGenerator { public: ~SingularMessage() override = default; - void InMsgImpl(Context field) const override; - void InExternC(Context field) const override; - void InThunkCc(Context field) const override; + void InMsgImpl(Context& ctx, const FieldDescriptor& field) const override; + void InExternC(Context& ctx, const FieldDescriptor& field) const override; + void InThunkCc(Context& ctx, const FieldDescriptor& field) const override; }; class RepeatedScalar final : public AccessorGenerator { public: ~RepeatedScalar() override = default; - void InMsgImpl(Context field) const override; - void InExternC(Context field) const override; - void InThunkCc(Context field) const override; + void InMsgImpl(Context& ctx, const FieldDescriptor& field) const override; + void InExternC(Context& ctx, const FieldDescriptor& field) const override; + void InThunkCc(Context& ctx, const FieldDescriptor& field) const override; }; class UnsupportedField final : public AccessorGenerator { public: explicit UnsupportedField(std::string reason) : reason_(std::move(reason)) {} ~UnsupportedField() override = default; - void InMsgImpl(Context field) const override; + void InMsgImpl(Context& ctx, const FieldDescriptor& field) const override; private: std::string reason_; @@ -109,9 +110,9 @@ class UnsupportedField final : public AccessorGenerator { class Map final : public AccessorGenerator { public: ~Map() override = default; - void InMsgImpl(Context field) const override; - void InExternC(Context field) const override; - void InThunkCc(Context field) const override; + void InMsgImpl(Context& ctx, const FieldDescriptor& field) const override; + void InExternC(Context& ctx, const FieldDescriptor& field) const override; + void InThunkCc(Context& ctx, const FieldDescriptor& field) const override; }; } // namespace rust diff --git a/src/google/protobuf/compiler/rust/accessors/accessors.cc b/src/google/protobuf/compiler/rust/accessors/accessors.cc index c25fbc207f975..d4c93f00bac45 100644 --- a/src/google/protobuf/compiler/rust/accessors/accessors.cc +++ b/src/google/protobuf/compiler/rust/accessors/accessors.cc @@ -23,17 +23,16 @@ namespace rust { namespace { std::unique_ptr AccessorGeneratorFor( - Context field) { - const FieldDescriptor& desc = field.desc(); + Context& ctx, const FieldDescriptor& field) { // TODO: We do not support [ctype=FOO] (used to set the field // type in C++ to cord or string_piece) in V0.6 API. - if (desc.options().has_ctype()) { + if (field.options().has_ctype()) { return std::make_unique( "fields with ctype not supported"); } - if (desc.is_map()) { - auto value_type = desc.message_type()->map_value()->type(); + if (field.is_map()) { + auto value_type = field.message_type()->map_value()->type(); switch (value_type) { case FieldDescriptor::TYPE_BYTES: case FieldDescriptor::TYPE_ENUM: @@ -46,7 +45,7 @@ std::unique_ptr AccessorGeneratorFor( } } - switch (desc.type()) { + switch (field.type()) { case FieldDescriptor::TYPE_INT32: case FieldDescriptor::TYPE_INT64: case FieldDescriptor::TYPE_FIXED32: @@ -60,22 +59,22 @@ std::unique_ptr AccessorGeneratorFor( case FieldDescriptor::TYPE_FLOAT: case FieldDescriptor::TYPE_DOUBLE: case FieldDescriptor::TYPE_BOOL: - if (desc.is_repeated()) { + if (field.is_repeated()) { return std::make_unique(); } return std::make_unique(); case FieldDescriptor::TYPE_BYTES: case FieldDescriptor::TYPE_STRING: - if (desc.is_repeated()) { + if (field.is_repeated()) { return std::make_unique("repeated str not supported"); } return std::make_unique(); case FieldDescriptor::TYPE_MESSAGE: - if (desc.is_repeated()) { + if (field.is_repeated()) { return std::make_unique("repeated msg not supported"); } - if (!field.generator_context().is_file_in_current_crate( - desc.message_type()->file())) { + if (!ctx.generator_context().is_file_in_current_crate( + *field.message_type()->file())) { return std::make_unique( "message fields that are imported from another proto_library" " (defined in a separate Rust crate) are not supported"); @@ -89,21 +88,21 @@ std::unique_ptr AccessorGeneratorFor( return std::make_unique("group not supported"); } - ABSL_LOG(FATAL) << "Unexpected field type: " << desc.type(); + ABSL_LOG(FATAL) << "Unexpected field type: " << field.type(); } } // namespace -void GenerateAccessorMsgImpl(Context field) { - AccessorGeneratorFor(field)->GenerateMsgImpl(field); +void GenerateAccessorMsgImpl(Context& ctx, const FieldDescriptor& field) { + AccessorGeneratorFor(ctx, field)->GenerateMsgImpl(ctx, field); } -void GenerateAccessorExternC(Context field) { - AccessorGeneratorFor(field)->GenerateExternC(field); +void GenerateAccessorExternC(Context& ctx, const FieldDescriptor& field) { + AccessorGeneratorFor(ctx, field)->GenerateExternC(ctx, field); } -void GenerateAccessorThunkCc(Context field) { - AccessorGeneratorFor(field)->GenerateThunkCc(field); +void GenerateAccessorThunkCc(Context& ctx, const FieldDescriptor& field) { + AccessorGeneratorFor(ctx, field)->GenerateThunkCc(ctx, field); } } // namespace rust diff --git a/src/google/protobuf/compiler/rust/accessors/accessors.h b/src/google/protobuf/compiler/rust/accessors/accessors.h index 05687e5477715..801bff2057646 100644 --- a/src/google/protobuf/compiler/rust/accessors/accessors.h +++ b/src/google/protobuf/compiler/rust/accessors/accessors.h @@ -16,9 +16,9 @@ namespace protobuf { namespace compiler { namespace rust { -void GenerateAccessorMsgImpl(Context field); -void GenerateAccessorExternC(Context field); -void GenerateAccessorThunkCc(Context field); +void GenerateAccessorMsgImpl(Context& ctx, const FieldDescriptor& field); +void GenerateAccessorExternC(Context& ctx, const FieldDescriptor& field); +void GenerateAccessorThunkCc(Context& ctx, const FieldDescriptor& field); } // namespace rust } // namespace compiler diff --git a/src/google/protobuf/compiler/rust/accessors/helpers.cc b/src/google/protobuf/compiler/rust/accessors/helpers.cc index b2d2a1bed8ff5..ba41abd9b5bb4 100644 --- a/src/google/protobuf/compiler/rust/accessors/helpers.cc +++ b/src/google/protobuf/compiler/rust/accessors/helpers.cc @@ -15,7 +15,6 @@ #include "absl/strings/escaping.h" #include "absl/strings/str_cat.h" #include "absl/strings/str_format.h" -#include "google/protobuf/compiler/rust/context.h" #include "google/protobuf/descriptor.h" #include "google/protobuf/io/strtod.h" @@ -24,33 +23,32 @@ namespace protobuf { namespace compiler { namespace rust { -std::string DefaultValue(Context field) { - switch (field.desc().type()) { +std::string DefaultValue(const FieldDescriptor& field) { + switch (field.type()) { case FieldDescriptor::TYPE_DOUBLE: - if (std::isfinite(field.desc().default_value_double())) { - return absl::StrCat(io::SimpleDtoa(field.desc().default_value_double()), + if (std::isfinite(field.default_value_double())) { + return absl::StrCat(io::SimpleDtoa(field.default_value_double()), "f64"); - } else if (std::isnan(field.desc().default_value_double())) { + } else if (std::isnan(field.default_value_double())) { return std::string("f64::NAN"); - } else if (field.desc().default_value_double() == + } else if (field.default_value_double() == std::numeric_limits::infinity()) { return std::string("f64::INFINITY"); - } else if (field.desc().default_value_double() == + } else if (field.default_value_double() == -std::numeric_limits::infinity()) { return std::string("f64::NEG_INFINITY"); } else { ABSL_LOG(FATAL) << "unreachable"; } case FieldDescriptor::TYPE_FLOAT: - if (std::isfinite(field.desc().default_value_float())) { - return absl::StrCat(io::SimpleFtoa(field.desc().default_value_float()), - "f32"); - } else if (std::isnan(field.desc().default_value_float())) { + if (std::isfinite(field.default_value_float())) { + return absl::StrCat(io::SimpleFtoa(field.default_value_float()), "f32"); + } else if (std::isnan(field.default_value_float())) { return std::string("f32::NAN"); - } else if (field.desc().default_value_float() == + } else if (field.default_value_float() == std::numeric_limits::infinity()) { return std::string("f32::INFINITY"); - } else if (field.desc().default_value_float() == + } else if (field.default_value_float() == -std::numeric_limits::infinity()) { return std::string("f32::NEG_INFINITY"); } else { @@ -59,27 +57,27 @@ std::string DefaultValue(Context field) { case FieldDescriptor::TYPE_INT32: case FieldDescriptor::TYPE_SFIXED32: case FieldDescriptor::TYPE_SINT32: - return absl::StrFormat("%d", field.desc().default_value_int32()); + return absl::StrFormat("%d", field.default_value_int32()); case FieldDescriptor::TYPE_INT64: case FieldDescriptor::TYPE_SFIXED64: case FieldDescriptor::TYPE_SINT64: - return absl::StrFormat("%d", field.desc().default_value_int64()); + return absl::StrFormat("%d", field.default_value_int64()); case FieldDescriptor::TYPE_FIXED64: case FieldDescriptor::TYPE_UINT64: - return absl::StrFormat("%u", field.desc().default_value_uint64()); + return absl::StrFormat("%u", field.default_value_uint64()); case FieldDescriptor::TYPE_FIXED32: case FieldDescriptor::TYPE_UINT32: - return absl::StrFormat("%u", field.desc().default_value_uint32()); + return absl::StrFormat("%u", field.default_value_uint32()); case FieldDescriptor::TYPE_BOOL: - return absl::StrFormat("%v", field.desc().default_value_bool()); + return absl::StrFormat("%v", field.default_value_bool()); case FieldDescriptor::TYPE_STRING: case FieldDescriptor::TYPE_BYTES: - return absl::StrFormat( - "b\"%s\"", absl::CHexEscape(field.desc().default_value_string())); + return absl::StrFormat("b\"%s\"", + absl::CHexEscape(field.default_value_string())); case FieldDescriptor::TYPE_GROUP: case FieldDescriptor::TYPE_MESSAGE: case FieldDescriptor::TYPE_ENUM: - ABSL_LOG(FATAL) << "Unsupported field type: " << field.desc().type_name(); + ABSL_LOG(FATAL) << "Unsupported field type: " << field.type_name(); } ABSL_LOG(FATAL) << "unreachable"; } diff --git a/src/google/protobuf/compiler/rust/accessors/helpers.h b/src/google/protobuf/compiler/rust/accessors/helpers.h index 45c7f3afa210b..ee2c429e3ba43 100644 --- a/src/google/protobuf/compiler/rust/accessors/helpers.h +++ b/src/google/protobuf/compiler/rust/accessors/helpers.h @@ -10,7 +10,6 @@ #include -#include "google/protobuf/compiler/rust/context.h" #include "google/protobuf/descriptor.h" namespace google { @@ -23,7 +22,7 @@ namespace rust { // Both strings and bytes are represented as a byte string literal, i.e. in the // format `b"default value here"`. It is the caller's responsibility to convert // the byte literal to an actual string, if needed. -std::string DefaultValue(Context field); +std::string DefaultValue(const FieldDescriptor& field); } // namespace rust } // namespace compiler diff --git a/src/google/protobuf/compiler/rust/accessors/map.cc b/src/google/protobuf/compiler/rust/accessors/map.cc index 0c2c1eb29da8a..89535d40e27d2 100644 --- a/src/google/protobuf/compiler/rust/accessors/map.cc +++ b/src/google/protobuf/compiler/rust/accessors/map.cc @@ -17,19 +17,19 @@ namespace protobuf { namespace compiler { namespace rust { -void Map::InMsgImpl(Context field) const { - auto& key_type = *field.desc().message_type()->map_key(); - auto& value_type = *field.desc().message_type()->map_value(); +void Map::InMsgImpl(Context& ctx, const FieldDescriptor& field) const { + auto& key_type = *field.message_type()->map_key(); + auto& value_type = *field.message_type()->map_value(); - field.Emit({{"field", field.desc().name()}, - {"Key", PrimitiveRsTypeName(key_type)}, - {"Value", PrimitiveRsTypeName(value_type)}, - {"getter_thunk", Thunk(field, "get")}, - {"getter_mut_thunk", Thunk(field, "get_mut")}, - {"getter", - [&] { - if (field.is_upb()) { - field.Emit({}, R"rs( + ctx.Emit({{"field", field.name()}, + {"Key", PrimitiveRsTypeName(key_type)}, + {"Value", PrimitiveRsTypeName(value_type)}, + {"getter_thunk", Thunk(ctx, field, "get")}, + {"getter_mut_thunk", Thunk(ctx, field, "get_mut")}, + {"getter", + [&] { + if (ctx.is_upb()) { + ctx.Emit({}, R"rs( pub fn r#$field$(&self) -> $pb$::View<'_, $pb$::Map<$Key$, $Value$>> { let inner = unsafe { @@ -44,8 +44,8 @@ void Map::InMsgImpl(Context field) const { }); $pb$::MapView::from_inner($pbi$::Private, inner) })rs"); - } else { - field.Emit({}, R"rs( + } else { + ctx.Emit({}, R"rs( pub fn r#$field$(&self) -> $pb$::View<'_, $pb$::Map<$Key$, $Value$>> { let inner = $pbr$::MapInner { @@ -55,12 +55,12 @@ void Map::InMsgImpl(Context field) const { }; $pb$::MapView::from_inner($pbi$::Private, inner) })rs"); - } - }}, - {"getter_mut", - [&] { - if (field.is_upb()) { - field.Emit({}, R"rs( + } + }}, + {"getter_mut", + [&] { + if (ctx.is_upb()) { + ctx.Emit({}, R"rs( pub fn r#$field$_mut(&mut self) -> $pb$::Mut<'_, $pb$::Map<$Key$, $Value$>> { let raw = unsafe { @@ -75,8 +75,8 @@ void Map::InMsgImpl(Context field) const { }; $pb$::MapMut::from_inner($pbi$::Private, inner) })rs"); - } else { - field.Emit({}, R"rs( + } else { + ctx.Emit({}, R"rs( pub fn r#$field$_mut(&mut self) -> $pb$::Mut<'_, $pb$::Map<$Key$, $Value$>> { let inner = $pbr$::MapInner { @@ -86,30 +86,30 @@ void Map::InMsgImpl(Context field) const { }; $pb$::MapMut::from_inner($pbi$::Private, inner) })rs"); - } - }}}, - R"rs( + } + }}}, + R"rs( $getter$ $getter_mut$ )rs"); } -void Map::InExternC(Context field) const { - field.Emit( +void Map::InExternC(Context& ctx, const FieldDescriptor& field) const { + ctx.Emit( { - {"getter_thunk", Thunk(field, "get")}, - {"getter_mut_thunk", Thunk(field, "get_mut")}, + {"getter_thunk", Thunk(ctx, field, "get")}, + {"getter_mut_thunk", Thunk(ctx, field, "get_mut")}, {"getter", [&] { - if (field.is_upb()) { - field.Emit({}, R"rs( + if (ctx.is_upb()) { + ctx.Emit({}, R"rs( fn $getter_thunk$(raw_msg: $pbi$::RawMessage) -> Option<$pbi$::RawMap>; fn $getter_mut_thunk$(raw_msg: $pbi$::RawMessage, arena: $pbi$::RawArena) -> $pbi$::RawMap; )rs"); } else { - field.Emit({}, R"rs( + ctx.Emit({}, R"rs( fn $getter_thunk$(msg: $pbi$::RawMessage) -> $pbi$::RawMap; fn $getter_mut_thunk$(msg: $pbi$::RawMessage,) -> $pbi$::RawMap; )rs"); @@ -121,20 +121,19 @@ void Map::InExternC(Context field) const { )rs"); } -void Map::InThunkCc(Context field) const { - field.Emit( - {{"field", cpp::FieldName(&field.desc())}, - {"Key", cpp::PrimitiveTypeName( - field.desc().message_type()->map_key()->cpp_type())}, - {"Value", cpp::PrimitiveTypeName( - field.desc().message_type()->map_value()->cpp_type())}, - {"QualifiedMsg", - cpp::QualifiedClassName(field.desc().containing_type())}, - {"getter_thunk", Thunk(field, "get")}, - {"getter_mut_thunk", Thunk(field, "get_mut")}, +void Map::InThunkCc(Context& ctx, const FieldDescriptor& field) const { + ctx.Emit( + {{"field", cpp::FieldName(&field)}, + {"Key", + cpp::PrimitiveTypeName(field.message_type()->map_key()->cpp_type())}, + {"Value", + cpp::PrimitiveTypeName(field.message_type()->map_value()->cpp_type())}, + {"QualifiedMsg", cpp::QualifiedClassName(field.containing_type())}, + {"getter_thunk", Thunk(ctx, field, "get")}, + {"getter_mut_thunk", Thunk(ctx, field, "get_mut")}, {"impls", [&] { - field.Emit( + ctx.Emit( R"cc( const void* $getter_thunk$($QualifiedMsg$& msg) { return &msg.$field$(); diff --git a/src/google/protobuf/compiler/rust/accessors/repeated_scalar.cc b/src/google/protobuf/compiler/rust/accessors/repeated_scalar.cc index 72f1d790b81b2..e0e1c6cffc208 100644 --- a/src/google/protobuf/compiler/rust/accessors/repeated_scalar.cc +++ b/src/google/protobuf/compiler/rust/accessors/repeated_scalar.cc @@ -17,15 +17,16 @@ namespace protobuf { namespace compiler { namespace rust { -void RepeatedScalar::InMsgImpl(Context field) const { - field.Emit({{"field", field.desc().name()}, - {"Scalar", PrimitiveRsTypeName(field.desc())}, - {"getter_thunk", Thunk(field, "get")}, - {"getter_mut_thunk", Thunk(field, "get_mut")}, - {"getter", - [&] { - if (field.is_upb()) { - field.Emit({}, R"rs( +void RepeatedScalar::InMsgImpl(Context& ctx, + const FieldDescriptor& field) const { + ctx.Emit({{"field", field.name()}, + {"Scalar", PrimitiveRsTypeName(field)}, + {"getter_thunk", Thunk(ctx, field, "get")}, + {"getter_mut_thunk", Thunk(ctx, field, "get_mut")}, + {"getter", + [&] { + if (ctx.is_upb()) { + ctx.Emit({}, R"rs( pub fn r#$field$(&self) -> $pb$::RepeatedView<'_, $Scalar$> { unsafe { $getter_thunk$( @@ -40,8 +41,8 @@ void RepeatedScalar::InMsgImpl(Context field) const { ) } )rs"); - } else { - field.Emit({}, R"rs( + } else { + ctx.Emit({}, R"rs( pub fn r#$field$(&self) -> $pb$::RepeatedView<'_, $Scalar$> { unsafe { $pb$::RepeatedView::from_raw( @@ -51,13 +52,13 @@ void RepeatedScalar::InMsgImpl(Context field) const { } } )rs"); - } - }}, - {"clearer_thunk", Thunk(field, "clear")}, - {"field_mutator_getter", - [&] { - if (field.is_upb()) { - field.Emit({}, R"rs( + } + }}, + {"clearer_thunk", Thunk(ctx, field, "clear")}, + {"field_mutator_getter", + [&] { + if (ctx.is_upb()) { + ctx.Emit({}, R"rs( pub fn r#$field$_mut(&mut self) -> $pb$::RepeatedMut<'_, $Scalar$> { unsafe { $pb$::RepeatedMut::from_inner( @@ -75,8 +76,8 @@ void RepeatedScalar::InMsgImpl(Context field) const { } } )rs"); - } else { - field.Emit({}, R"rs( + } else { + ctx.Emit({}, R"rs( pub fn r#$field$_mut(&mut self) -> $pb$::RepeatedMut<'_, $Scalar$> { unsafe { $pb$::RepeatedMut::from_inner( @@ -89,22 +90,23 @@ void RepeatedScalar::InMsgImpl(Context field) const { } } )rs"); - } - }}}, - R"rs( + } + }}}, + R"rs( $getter$ $field_mutator_getter$ )rs"); } -void RepeatedScalar::InExternC(Context field) const { - field.Emit({{"Scalar", PrimitiveRsTypeName(field.desc())}, - {"getter_thunk", Thunk(field, "get")}, - {"getter_mut_thunk", Thunk(field, "get_mut")}, - {"getter", - [&] { - if (field.is_upb()) { - field.Emit(R"rs( +void RepeatedScalar::InExternC(Context& ctx, + const FieldDescriptor& field) const { + ctx.Emit({{"Scalar", PrimitiveRsTypeName(field)}, + {"getter_thunk", Thunk(ctx, field, "get")}, + {"getter_mut_thunk", Thunk(ctx, field, "get_mut")}, + {"getter", + [&] { + if (ctx.is_upb()) { + ctx.Emit(R"rs( fn $getter_mut_thunk$( raw_msg: $pbi$::RawMessage, size: *const usize, @@ -116,44 +118,44 @@ void RepeatedScalar::InExternC(Context field) const { size: *const usize, ) -> Option<$pbi$::RawRepeatedField>; )rs"); - } else { - field.Emit(R"rs( + } else { + ctx.Emit(R"rs( fn $getter_mut_thunk$(raw_msg: $pbi$::RawMessage) -> $pbi$::RawRepeatedField; fn $getter_thunk$(raw_msg: $pbi$::RawMessage) -> $pbi$::RawRepeatedField; )rs"); - } - }}, - {"clearer_thunk", Thunk(field, "clear")}}, - R"rs( + } + }}, + {"clearer_thunk", Thunk(ctx, field, "clear")}}, + R"rs( fn $clearer_thunk$(raw_msg: $pbi$::RawMessage); $getter$ )rs"); } -void RepeatedScalar::InThunkCc(Context field) const { - field.Emit({{"field", cpp::FieldName(&field.desc())}, - {"Scalar", cpp::PrimitiveTypeName(field.desc().cpp_type())}, - {"QualifiedMsg", - cpp::QualifiedClassName(field.desc().containing_type())}, - {"clearer_thunk", Thunk(field, "clear")}, - {"getter_thunk", Thunk(field, "get")}, - {"getter_mut_thunk", Thunk(field, "get_mut")}, - {"impls", - [&] { - field.Emit( - R"cc( - void $clearer_thunk$($QualifiedMsg$* msg) { - msg->clear_$field$(); - } - google::protobuf::RepeatedField<$Scalar$>* $getter_mut_thunk$($QualifiedMsg$* msg) { - return msg->mutable_$field$(); - } - const google::protobuf::RepeatedField<$Scalar$>& $getter_thunk$($QualifiedMsg$& msg) { - return msg.$field$(); - } - )cc"); - }}}, - "$impls$"); +void RepeatedScalar::InThunkCc(Context& ctx, + const FieldDescriptor& field) const { + ctx.Emit({{"field", cpp::FieldName(&field)}, + {"Scalar", cpp::PrimitiveTypeName(field.cpp_type())}, + {"QualifiedMsg", cpp::QualifiedClassName(field.containing_type())}, + {"clearer_thunk", Thunk(ctx, field, "clear")}, + {"getter_thunk", Thunk(ctx, field, "get")}, + {"getter_mut_thunk", Thunk(ctx, field, "get_mut")}, + {"impls", + [&] { + ctx.Emit( + R"cc( + void $clearer_thunk$($QualifiedMsg$* msg) { + msg->clear_$field$(); + } + google::protobuf::RepeatedField<$Scalar$>* $getter_mut_thunk$($QualifiedMsg$* msg) { + return msg->mutable_$field$(); + } + const google::protobuf::RepeatedField<$Scalar$>& $getter_thunk$($QualifiedMsg$& msg) { + return msg.$field$(); + } + )cc"); + }}}, + "$impls$"); } } // namespace rust diff --git a/src/google/protobuf/compiler/rust/accessors/singular_message.cc b/src/google/protobuf/compiler/rust/accessors/singular_message.cc index 210512a7eb305..ca5dce246ae7d 100644 --- a/src/google/protobuf/compiler/rust/accessors/singular_message.cc +++ b/src/google/protobuf/compiler/rust/accessors/singular_message.cc @@ -17,23 +17,23 @@ namespace protobuf { namespace compiler { namespace rust { -void SingularMessage::InMsgImpl(Context field) const { - Context d = field.WithDesc(field.desc().message_type()); +void SingularMessage::InMsgImpl(Context& ctx, + const FieldDescriptor& field) const { + auto& msg = *field.message_type(); + auto prefix = "crate::" + GetCrateRelativeQualifiedPath(ctx, msg); - auto prefix = "crate::" + GetCrateRelativeQualifiedPath(d); - - field.Emit( + ctx.Emit( { {"prefix", prefix}, - {"field", field.desc().name()}, - {"getter_thunk", Thunk(field, "get")}, - {"getter_mut_thunk", Thunk(field, "get_mut")}, - {"clearer_thunk", Thunk(field, "clear")}, + {"field", field.name()}, + {"getter_thunk", Thunk(ctx, field, "get")}, + {"getter_mut_thunk", Thunk(ctx, field, "get_mut")}, + {"clearer_thunk", Thunk(ctx, field, "clear")}, { "view_body", [&] { - if (field.is_upb()) { - field.Emit({}, R"rs( + if (ctx.is_upb()) { + ctx.Emit({}, R"rs( let submsg = unsafe { $getter_thunk$(self.inner.msg) }; // For upb, getters return null if the field is unset, so we need // to check for null and return the default instance manually. @@ -46,7 +46,7 @@ void SingularMessage::InMsgImpl(Context field) const { } )rs"); } else { - field.Emit({}, R"rs( + ctx.Emit({}, R"rs( // For C++ kernel, getters automatically return the // default_instance if the field is unset. let submsg = unsafe { $getter_thunk$(self.inner.msg) }; @@ -57,15 +57,15 @@ void SingularMessage::InMsgImpl(Context field) const { }, {"submessage_mut", [&] { - if (field.is_upb()) { - field.Emit({}, R"rs( + if (ctx.is_upb()) { + ctx.Emit({}, R"rs( let submsg = unsafe { $getter_mut_thunk$(self.inner.msg, self.inner.arena.raw()) }; $prefix$Mut::new($pbi$::Private, &mut self.inner, submsg) )rs"); } else { - field.Emit({}, R"rs( + ctx.Emit({}, R"rs( let submsg = unsafe { $getter_mut_thunk$(self.inner.msg) }; $prefix$Mut::new($pbi$::Private, &mut self.inner, submsg) )rs"); @@ -87,21 +87,22 @@ void SingularMessage::InMsgImpl(Context field) const { )rs"); } -void SingularMessage::InExternC(Context field) const { - field.Emit( +void SingularMessage::InExternC(Context& ctx, + const FieldDescriptor& field) const { + ctx.Emit( { - {"getter_thunk", Thunk(field, "get")}, - {"getter_mut_thunk", Thunk(field, "get_mut")}, - {"clearer_thunk", Thunk(field, "clear")}, + {"getter_thunk", Thunk(ctx, field, "get")}, + {"getter_mut_thunk", Thunk(ctx, field, "get_mut")}, + {"clearer_thunk", Thunk(ctx, field, "clear")}, {"getter_mut", [&] { - if (field.is_cpp()) { - field.Emit( + if (ctx.is_cpp()) { + ctx.Emit( R"rs( fn $getter_mut_thunk$(raw_msg: $pbi$::RawMessage) -> $pbi$::RawMessage;)rs"); } else { - field.Emit( + ctx.Emit( R"rs(fn $getter_mut_thunk$(raw_msg: $pbi$::RawMessage, arena: $pbi$::RawArena) -> $pbi$::RawMessage;)rs"); @@ -109,13 +110,13 @@ void SingularMessage::InExternC(Context field) const { }}, {"ReturnType", [&] { - if (field.is_cpp()) { + if (ctx.is_cpp()) { // guaranteed to have a nonnull submsg for the cpp kernel - field.Emit({}, "$pbi$::RawMessage;"); + ctx.Emit({}, "$pbi$::RawMessage;"); } else { // upb kernel may return NULL for a submsg, we can detect this // in terra rust if the option returned is None - field.Emit({}, "Option<$pbi$::RawMessage>;"); + ctx.Emit({}, "Option<$pbi$::RawMessage>;"); } }}, }, @@ -126,22 +127,22 @@ void SingularMessage::InExternC(Context field) const { )rs"); } -void SingularMessage::InThunkCc(Context field) const { - field.Emit({{"QualifiedMsg", - cpp::QualifiedClassName(field.desc().containing_type())}, - {"getter_thunk", Thunk(field, "get")}, - {"getter_mut_thunk", Thunk(field, "get_mut")}, - {"clearer_thunk", Thunk(field, "clear")}, - {"field", cpp::FieldName(&field.desc())}}, - R"cc( - const void* $getter_thunk$($QualifiedMsg$* msg) { - return static_cast(&msg->$field$()); - } - void* $getter_mut_thunk$($QualifiedMsg$* msg) { - return static_cast(msg->mutable_$field$()); - } - void $clearer_thunk$($QualifiedMsg$* msg) { msg->clear_$field$(); } - )cc"); +void SingularMessage::InThunkCc(Context& ctx, + const FieldDescriptor& field) const { + ctx.Emit({{"QualifiedMsg", cpp::QualifiedClassName(field.containing_type())}, + {"getter_thunk", Thunk(ctx, field, "get")}, + {"getter_mut_thunk", Thunk(ctx, field, "get_mut")}, + {"clearer_thunk", Thunk(ctx, field, "clear")}, + {"field", cpp::FieldName(&field)}}, + R"cc( + const void* $getter_thunk$($QualifiedMsg$* msg) { + return static_cast(&msg->$field$()); + } + void* $getter_mut_thunk$($QualifiedMsg$* msg) { + return static_cast(msg->mutable_$field$()); + } + void $clearer_thunk$($QualifiedMsg$* msg) { msg->clear_$field$(); } + )cc"); } } // namespace rust diff --git a/src/google/protobuf/compiler/rust/accessors/singular_scalar.cc b/src/google/protobuf/compiler/rust/accessors/singular_scalar.cc index bf4d2c2d6a825..48aa4dbfca645 100644 --- a/src/google/protobuf/compiler/rust/accessors/singular_scalar.cc +++ b/src/google/protobuf/compiler/rust/accessors/singular_scalar.cc @@ -18,16 +18,17 @@ namespace protobuf { namespace compiler { namespace rust { -void SingularScalar::InMsgImpl(Context field) const { - field.Emit( +void SingularScalar::InMsgImpl(Context& ctx, + const FieldDescriptor& field) const { + ctx.Emit( { - {"field", field.desc().name()}, - {"Scalar", PrimitiveRsTypeName(field.desc())}, - {"hazzer_thunk", Thunk(field, "has")}, + {"field", field.name()}, + {"Scalar", PrimitiveRsTypeName(field)}, + {"hazzer_thunk", Thunk(ctx, field, "has")}, {"default_value", DefaultValue(field)}, {"getter", [&] { - field.Emit({}, R"rs( + ctx.Emit({}, R"rs( pub fn r#$field$(&self) -> $Scalar$ { unsafe { $getter_thunk$(self.inner.msg) } } @@ -35,9 +36,9 @@ void SingularScalar::InMsgImpl(Context field) const { }}, {"getter_opt", [&] { - if (!field.desc().is_optional()) return; - if (!field.desc().has_presence()) return; - field.Emit({}, R"rs( + if (!field.is_optional()) return; + if (!field.has_presence()) return; + ctx.Emit({}, R"rs( pub fn r#$field$_opt(&self) -> $pb$::Optional<$Scalar$> { if !unsafe { $hazzer_thunk$(self.inner.msg) } { return $pb$::Optional::Unset($default_value$); @@ -47,13 +48,13 @@ void SingularScalar::InMsgImpl(Context field) const { } )rs"); }}, - {"getter_thunk", Thunk(field, "get")}, - {"setter_thunk", Thunk(field, "set")}, - {"clearer_thunk", Thunk(field, "clear")}, + {"getter_thunk", Thunk(ctx, field, "get")}, + {"setter_thunk", Thunk(ctx, field, "set")}, + {"clearer_thunk", Thunk(ctx, field, "clear")}, {"field_mutator_getter", [&] { - if (field.desc().has_presence()) { - field.Emit({}, R"rs( + if (field.has_presence()) { + ctx.Emit({}, R"rs( pub fn r#$field$_mut(&mut self) -> $pb$::FieldEntry<'_, $Scalar$> { static VTABLE: $pbi$::PrimitiveOptionalMutVTable<$Scalar$> = $pbi$::PrimitiveOptionalMutVTable::new( @@ -76,7 +77,7 @@ void SingularScalar::InMsgImpl(Context field) const { } )rs"); } else { - field.Emit({}, R"rs( + ctx.Emit({}, R"rs( pub fn r#$field$_mut(&mut self) -> $pb$::Mut<'_, $Scalar$> { static VTABLE: $pbi$::PrimitiveVTable<$Scalar$> = $pbi$::PrimitiveVTable::new( @@ -114,56 +115,57 @@ void SingularScalar::InMsgImpl(Context field) const { )rs"); } -void SingularScalar::InExternC(Context field) const { - field.Emit({{"Scalar", PrimitiveRsTypeName(field.desc())}, - {"hazzer_thunk", Thunk(field, "has")}, - {"getter_thunk", Thunk(field, "get")}, - {"setter_thunk", Thunk(field, "set")}, - {"clearer_thunk", Thunk(field, "clear")}, - {"hazzer_and_clearer", - [&] { - if (field.desc().has_presence()) { - field.Emit( - R"rs( +void SingularScalar::InExternC(Context& ctx, + const FieldDescriptor& field) const { + ctx.Emit({{"Scalar", PrimitiveRsTypeName(field)}, + {"hazzer_thunk", Thunk(ctx, field, "has")}, + {"getter_thunk", Thunk(ctx, field, "get")}, + {"setter_thunk", Thunk(ctx, field, "set")}, + {"clearer_thunk", Thunk(ctx, field, "clear")}, + {"hazzer_and_clearer", + [&] { + if (field.has_presence()) { + ctx.Emit( + R"rs( fn $hazzer_thunk$(raw_msg: $pbi$::RawMessage) -> bool; fn $clearer_thunk$(raw_msg: $pbi$::RawMessage); )rs"); - } - }}}, - R"rs( + } + }}}, + R"rs( $hazzer_and_clearer$ fn $getter_thunk$(raw_msg: $pbi$::RawMessage) -> $Scalar$; fn $setter_thunk$(raw_msg: $pbi$::RawMessage, val: $Scalar$); )rs"); } -void SingularScalar::InThunkCc(Context field) const { - field.Emit({{"field", cpp::FieldName(&field.desc())}, - {"Scalar", cpp::PrimitiveTypeName(field.desc().cpp_type())}, - {"QualifiedMsg", - cpp::QualifiedClassName(field.desc().containing_type())}, - {"hazzer_thunk", Thunk(field, "has")}, - {"getter_thunk", Thunk(field, "get")}, - {"setter_thunk", Thunk(field, "set")}, - {"clearer_thunk", Thunk(field, "clear")}, - {"hazzer_and_clearer", - [&] { - if (field.desc().has_presence()) { - field.Emit(R"cc( - bool $hazzer_thunk$($QualifiedMsg$* msg) { - return msg->has_$field$(); - } - void $clearer_thunk$($QualifiedMsg$* msg) { msg->clear_$field$(); } - )cc"); - } - }}}, - R"cc( - $hazzer_and_clearer$; - $Scalar$ $getter_thunk$($QualifiedMsg$* msg) { return msg->$field$(); } - void $setter_thunk$($QualifiedMsg$* msg, $Scalar$ val) { - msg->set_$field$(val); +void SingularScalar::InThunkCc(Context& ctx, + const FieldDescriptor& field) const { + ctx.Emit({{"field", cpp::FieldName(&field)}, + {"Scalar", cpp::PrimitiveTypeName(field.cpp_type())}, + {"QualifiedMsg", cpp::QualifiedClassName(field.containing_type())}, + {"hazzer_thunk", Thunk(ctx, field, "has")}, + {"getter_thunk", Thunk(ctx, field, "get")}, + {"setter_thunk", Thunk(ctx, field, "set")}, + {"clearer_thunk", Thunk(ctx, field, "clear")}, + {"hazzer_and_clearer", + [&] { + if (field.has_presence()) { + ctx.Emit(R"cc( + bool $hazzer_thunk$($QualifiedMsg$* msg) { + return msg->has_$field$(); + } + void $clearer_thunk$($QualifiedMsg$* msg) { msg->clear_$field$(); } + )cc"); } - )cc"); + }}}, + R"cc( + $hazzer_and_clearer$; + $Scalar$ $getter_thunk$($QualifiedMsg$* msg) { return msg->$field$(); } + void $setter_thunk$($QualifiedMsg$* msg, $Scalar$ val) { + msg->set_$field$(val); + } + )cc"); } } // namespace rust diff --git a/src/google/protobuf/compiler/rust/accessors/singular_string.cc b/src/google/protobuf/compiler/rust/accessors/singular_string.cc index f3ae1e2f491a6..c70380c67c825 100644 --- a/src/google/protobuf/compiler/rust/accessors/singular_string.cc +++ b/src/google/protobuf/compiler/rust/accessors/singular_string.cc @@ -20,24 +20,25 @@ namespace protobuf { namespace compiler { namespace rust { -void SingularString::InMsgImpl(Context field) const { - std::string hazzer_thunk = Thunk(field, "has"); - std::string getter_thunk = Thunk(field, "get"); - std::string setter_thunk = Thunk(field, "set"); - std::string proxied_type = PrimitiveRsTypeName(field.desc()); +void SingularString::InMsgImpl(Context& ctx, + const FieldDescriptor& field) const { + std::string hazzer_thunk = Thunk(ctx, field, "has"); + std::string getter_thunk = Thunk(ctx, field, "get"); + std::string setter_thunk = Thunk(ctx, field, "set"); + std::string proxied_type = PrimitiveRsTypeName(field); auto transform_view = [&] { - if (field.desc().type() == FieldDescriptor::TYPE_STRING) { - field.Emit(R"rs( + if (field.type() == FieldDescriptor::TYPE_STRING) { + ctx.Emit(R"rs( // SAFETY: The runtime doesn't require ProtoStr to be UTF-8. unsafe { $pb$::ProtoStr::from_utf8_unchecked(view) } )rs"); } else { - field.Emit("view"); + ctx.Emit("view"); } }; - field.Emit( + ctx.Emit( { - {"field", field.desc().name()}, + {"field", field.name()}, {"hazzer_thunk", hazzer_thunk}, {"getter_thunk", getter_thunk}, {"setter_thunk", setter_thunk}, @@ -45,12 +46,12 @@ void SingularString::InMsgImpl(Context field) const { {"transform_view", transform_view}, {"field_optional_getter", [&] { - if (!field.desc().is_optional()) return; - if (!field.desc().has_presence()) return; - field.Emit({{"hazzer_thunk", hazzer_thunk}, - {"getter_thunk", getter_thunk}, - {"transform_view", transform_view}}, - R"rs( + if (!field.is_optional()) return; + if (!field.has_presence()) return; + ctx.Emit({{"hazzer_thunk", hazzer_thunk}, + {"getter_thunk", getter_thunk}, + {"transform_view", transform_view}}, + R"rs( pub fn $field$_opt(&self) -> $pb$::Optional<&$proxied_type$> { let view = unsafe { $getter_thunk$(self.inner.msg).as_ref() }; $pb$::Optional::new( @@ -62,30 +63,29 @@ void SingularString::InMsgImpl(Context field) const { }}, {"field_mutator_getter", [&] { - if (field.desc().has_presence()) { - field.Emit( + if (field.has_presence()) { + ctx.Emit( { - {"field", field.desc().name()}, + {"field", field.name()}, {"proxied_type", proxied_type}, {"default_val", DefaultValue(field)}, {"view_type", proxied_type}, {"transform_field_entry", [&] { - if (field.desc().type() == - FieldDescriptor::TYPE_STRING) { - field.Emit(R"rs( + if (field.type() == FieldDescriptor::TYPE_STRING) { + ctx.Emit(R"rs( $pb$::ProtoStrMut::field_entry_from_bytes( $pbi$::Private, out ) )rs"); } else { - field.Emit("out"); + ctx.Emit("out"); } }}, {"hazzer_thunk", hazzer_thunk}, {"getter_thunk", getter_thunk}, {"setter_thunk", setter_thunk}, - {"clearer_thunk", Thunk(field, "clear")}, + {"clearer_thunk", Thunk(ctx, field, "clear")}, }, R"rs( pub fn $field$_mut(&mut self) -> $pb$::FieldEntry<'_, $proxied_type$> { @@ -112,11 +112,11 @@ void SingularString::InMsgImpl(Context field) const { } )rs"); } else { - field.Emit({{"field", field.desc().name()}, - {"proxied_type", proxied_type}, - {"getter_thunk", getter_thunk}, - {"setter_thunk", setter_thunk}}, - R"rs( + ctx.Emit({{"field", field.name()}, + {"proxied_type", proxied_type}, + {"getter_thunk", getter_thunk}, + {"setter_thunk", setter_thunk}}, + R"rs( pub fn $field$_mut(&mut self) -> $pb$::Mut<'_, $proxied_type$> { static VTABLE: $pbi$::BytesMutVTable = unsafe { $pbi$::BytesMutVTable::new( @@ -152,20 +152,21 @@ void SingularString::InMsgImpl(Context field) const { )rs"); } -void SingularString::InExternC(Context field) const { - field.Emit({{"hazzer_thunk", Thunk(field, "has")}, - {"getter_thunk", Thunk(field, "get")}, - {"setter_thunk", Thunk(field, "set")}, - {"clearer_thunk", Thunk(field, "clear")}, - {"hazzer", - [&] { - if (field.desc().has_presence()) { - field.Emit(R"rs( +void SingularString::InExternC(Context& ctx, + const FieldDescriptor& field) const { + ctx.Emit({{"hazzer_thunk", Thunk(ctx, field, "has")}, + {"getter_thunk", Thunk(ctx, field, "get")}, + {"setter_thunk", Thunk(ctx, field, "set")}, + {"clearer_thunk", Thunk(ctx, field, "clear")}, + {"hazzer", + [&] { + if (field.has_presence()) { + ctx.Emit(R"rs( fn $hazzer_thunk$(raw_msg: $pbi$::RawMessage) -> bool; )rs"); - } - }}}, - R"rs( + } + }}}, + R"rs( $hazzer$ fn $getter_thunk$(raw_msg: $pbi$::RawMessage) -> $pbi$::PtrAndLen; fn $setter_thunk$(raw_msg: $pbi$::RawMessage, val: $pbi$::PtrAndLen); @@ -173,35 +174,35 @@ void SingularString::InExternC(Context field) const { )rs"); } -void SingularString::InThunkCc(Context field) const { - field.Emit({{"field", cpp::FieldName(&field.desc())}, - {"QualifiedMsg", - cpp::QualifiedClassName(field.desc().containing_type())}, - {"hazzer_thunk", Thunk(field, "has")}, - {"getter_thunk", Thunk(field, "get")}, - {"setter_thunk", Thunk(field, "set")}, - {"clearer_thunk", Thunk(field, "clear")}, - {"hazzer", - [&] { - if (field.desc().has_presence()) { - field.Emit(R"cc( - bool $hazzer_thunk$($QualifiedMsg$* msg) { - return msg->has_$field$(); - } - void $clearer_thunk$($QualifiedMsg$* msg) { msg->clear_$field$(); } - )cc"); - } - }}}, - R"cc( - $hazzer$; - ::google::protobuf::rust_internal::PtrAndLen $getter_thunk$($QualifiedMsg$* msg) { - absl::string_view val = msg->$field$(); - return ::google::protobuf::rust_internal::PtrAndLen(val.data(), val.size()); - } - void $setter_thunk$($QualifiedMsg$* msg, ::google::protobuf::rust_internal::PtrAndLen s) { - msg->set_$field$(absl::string_view(s.ptr, s.len)); +void SingularString::InThunkCc(Context& ctx, + const FieldDescriptor& field) const { + ctx.Emit({{"field", cpp::FieldName(&field)}, + {"QualifiedMsg", cpp::QualifiedClassName(field.containing_type())}, + {"hazzer_thunk", Thunk(ctx, field, "has")}, + {"getter_thunk", Thunk(ctx, field, "get")}, + {"setter_thunk", Thunk(ctx, field, "set")}, + {"clearer_thunk", Thunk(ctx, field, "clear")}, + {"hazzer", + [&] { + if (field.has_presence()) { + ctx.Emit(R"cc( + bool $hazzer_thunk$($QualifiedMsg$* msg) { + return msg->has_$field$(); + } + void $clearer_thunk$($QualifiedMsg$* msg) { msg->clear_$field$(); } + )cc"); } - )cc"); + }}}, + R"cc( + $hazzer$; + ::google::protobuf::rust_internal::PtrAndLen $getter_thunk$($QualifiedMsg$* msg) { + absl::string_view val = msg->$field$(); + return ::google::protobuf::rust_internal::PtrAndLen(val.data(), val.size()); + } + void $setter_thunk$($QualifiedMsg$* msg, ::google::protobuf::rust_internal::PtrAndLen s) { + msg->set_$field$(absl::string_view(s.ptr, s.len)); + } + )cc"); } } // namespace rust diff --git a/src/google/protobuf/compiler/rust/accessors/unsupported_field.cc b/src/google/protobuf/compiler/rust/accessors/unsupported_field.cc index e6bce02171bf9..591298a2bc5e8 100644 --- a/src/google/protobuf/compiler/rust/accessors/unsupported_field.cc +++ b/src/google/protobuf/compiler/rust/accessors/unsupported_field.cc @@ -15,11 +15,12 @@ namespace protobuf { namespace compiler { namespace rust { -void UnsupportedField::InMsgImpl(Context field) const { - field.Emit({{"reason", reason_}}, R"rs( +void UnsupportedField::InMsgImpl(Context& ctx, + const FieldDescriptor& field) const { + ctx.Emit({{"reason", reason_}}, R"rs( // Unsupported! :( Reason: $reason$ )rs"); - field.printer().PrintRaw("\n"); + ctx.printer().PrintRaw("\n"); } } // namespace rust diff --git a/src/google/protobuf/compiler/rust/context.cc b/src/google/protobuf/compiler/rust/context.cc index 68d4c9fb2a0d4..f64e88aab0f45 100644 --- a/src/google/protobuf/compiler/rust/context.cc +++ b/src/google/protobuf/compiler/rust/context.cc @@ -68,13 +68,12 @@ absl::StatusOr Options::Parse(absl::string_view param) { return opts; } -bool IsInCurrentlyGeneratingCrate(Context file) { - return file.generator_context().is_file_in_current_crate(&file.desc()); +bool IsInCurrentlyGeneratingCrate(Context& ctx, const FileDescriptor& file) { + return ctx.generator_context().is_file_in_current_crate(file); } -bool IsInCurrentlyGeneratingCrate(Context message) { - return message.generator_context().is_file_in_current_crate( - message.desc().file()); +bool IsInCurrentlyGeneratingCrate(Context& ctx, const Descriptor& message) { + return IsInCurrentlyGeneratingCrate(ctx, *message.file()); } } // namespace rust diff --git a/src/google/protobuf/compiler/rust/context.h b/src/google/protobuf/compiler/rust/context.h index affe8aee1be0b..1539e2e8f6fed 100644 --- a/src/google/protobuf/compiler/rust/context.h +++ b/src/google/protobuf/compiler/rust/context.h @@ -53,14 +53,14 @@ class RustGeneratorContext { const std::vector* files_in_current_crate) : files_in_current_crate_(*files_in_current_crate) {} - const FileDescriptor* primary_file() const { - return files_in_current_crate_.front(); + const FileDescriptor& primary_file() const { + return *files_in_current_crate_.front(); } - bool is_file_in_current_crate(const FileDescriptor* f) const { + bool is_file_in_current_crate(const FileDescriptor& f) const { return std::find(files_in_current_crate_.begin(), files_in_current_crate_.end(), - f) != files_in_current_crate_.end(); + &f) != files_in_current_crate_.end(); } private: @@ -68,26 +68,20 @@ class RustGeneratorContext { }; // A context for generating a particular kind of definition. -// This type acts as an options struct (as in go/totw/173) for most of the -// generator. -// -// `Descriptor` is the type of a descriptor.h class relevant for the current -// context. -template class Context { public: - Context(const Options* opts, const Descriptor* desc, + Context(const Options* opts, const RustGeneratorContext* rust_generator_context, io::Printer* printer) : opts_(opts), - desc_(desc), rust_generator_context_(rust_generator_context), printer_(printer) {} - Context(const Context&) = default; - Context& operator=(const Context&) = default; + Context(const Context&) = delete; + Context& operator=(const Context&) = delete; + Context(Context&&) = default; + Context& operator=(Context&&) = default; - const Descriptor& desc() const { return *desc_; } const Options& opts() const { return *opts_; } const RustGeneratorContext& generator_context() const { return *rust_generator_context_; @@ -99,19 +93,8 @@ class Context { // NOTE: prefer ctx.Emit() over ctx.printer().Emit(); io::Printer& printer() const { return *printer_; } - // Creates a new context over a different descriptor. - template - Context WithDesc(const D& desc) const { - return Context(opts_, &desc, rust_generator_context_, printer_); - } - - template - Context WithDesc(const D* desc) const { - return Context(opts_, desc, rust_generator_context_, printer_); - } - Context WithPrinter(io::Printer* printer) const { - return Context(opts_, desc_, rust_generator_context_, printer); + return Context(opts_, rust_generator_context_, printer); } // Forwards to Emit(), which will likely be called all the time. @@ -128,13 +111,12 @@ class Context { private: const Options* opts_; - const Descriptor* desc_; const RustGeneratorContext* rust_generator_context_; io::Printer* printer_; }; -bool IsInCurrentlyGeneratingCrate(Context file); -bool IsInCurrentlyGeneratingCrate(Context message); +bool IsInCurrentlyGeneratingCrate(Context& ctx, const FileDescriptor& file); +bool IsInCurrentlyGeneratingCrate(Context& ctx, const Descriptor& message); } // namespace rust } // namespace compiler diff --git a/src/google/protobuf/compiler/rust/generator.cc b/src/google/protobuf/compiler/rust/generator.cc index 3465672232575..04d5ff6f32105 100644 --- a/src/google/protobuf/compiler/rust/generator.cc +++ b/src/google/protobuf/compiler/rust/generator.cc @@ -48,12 +48,11 @@ namespace { // pub mod submodule { // pub mod separator { // ``` -void EmitOpeningOfPackageModules(absl::string_view pkg, - Context file) { +void EmitOpeningOfPackageModules(Context& ctx, absl::string_view pkg) { if (pkg.empty()) return; for (absl::string_view segment : absl::StrSplit(pkg, '.')) { - file.Emit({{"segment", segment}}, - R"rs( + ctx.Emit({{"segment", segment}}, + R"rs( pub mod $segment$ { )rs"); } @@ -70,14 +69,13 @@ void EmitOpeningOfPackageModules(absl::string_view pkg, // } // mod uses // } // mod package // ``` -void EmitClosingOfPackageModules(absl::string_view pkg, - Context file) { +void EmitClosingOfPackageModules(Context& ctx, absl::string_view pkg) { if (pkg.empty()) return; std::vector segments = absl::StrSplit(pkg, '.'); absl::c_reverse(segments); for (absl::string_view segment : segments) { - file.Emit({{"segment", segment}}, R"rs( + ctx.Emit({{"segment", segment}}, R"rs( } // mod $segment$ )rs"); } @@ -87,14 +85,13 @@ void EmitClosingOfPackageModules(absl::string_view pkg, // `non_primary_src` into the `primary_file`. // // `non_primary_src` has to be a non-primary src of the current `proto_library`. -void EmitPubUseOfOwnMessages(Context& primary_file, - const Context& non_primary_src) { - for (int i = 0; i < non_primary_src.desc().message_type_count(); ++i) { - auto msg = primary_file.WithDesc(non_primary_src.desc().message_type(i)); - auto mod = RustInternalModuleName(non_primary_src); - auto name = msg.desc().name(); - primary_file.Emit({{"mod", mod}, {"Msg", name}}, - R"rs( +void EmitPubUseOfOwnMessages(Context& ctx, const FileDescriptor& primary_file, + const FileDescriptor& non_primary_src) { + for (int i = 0; i < non_primary_src.message_type_count(); ++i) { + auto& msg = *non_primary_src.message_type(i); + auto mod = RustInternalModuleName(ctx, non_primary_src); + ctx.Emit({{"mod", mod}, {"Msg", msg.name()}}, + R"rs( pub use crate::$mod$::$Msg$; // TODO Address use for imported crates pub use crate::$mod$::$Msg$View; @@ -109,14 +106,15 @@ void EmitPubUseOfOwnMessages(Context& primary_file, // // `dep` is a primary src of a dependency of the current `proto_library`. // TODO: Add support for public import of non-primary srcs of deps. -void EmitPubUseForImportedMessages(Context& primary_file, - const Context& dep) { - std::string crate_name = GetCrateName(dep); - for (int i = 0; i < dep.desc().message_type_count(); ++i) { - auto msg = primary_file.WithDesc(dep.desc().message_type(i)); - auto path = GetCrateRelativeQualifiedPath(msg); - primary_file.Emit({{"crate", crate_name}, {"pkg::Msg", path}}, - R"rs( +void EmitPubUseForImportedMessages(Context& ctx, + const FileDescriptor& primary_file, + const FileDescriptor& dep) { + std::string crate_name = GetCrateName(ctx, dep); + for (int i = 0; i < dep.message_type_count(); ++i) { + auto& msg = *dep.message_type(i); + auto path = GetCrateRelativeQualifiedPath(ctx, msg); + ctx.Emit({{"crate", crate_name}, {"pkg::Msg", path}}, + R"rs( pub use $crate$::$pkg::Msg$; pub use $crate$::$pkg::Msg$View; )rs"); @@ -124,9 +122,9 @@ void EmitPubUseForImportedMessages(Context& primary_file, } // Emits all public imports of the current file -void EmitPublicImports(Context& primary_file) { - for (int i = 0; i < primary_file.desc().public_dependency_count(); ++i) { - auto dep_file = primary_file.desc().public_dependency(i); +void EmitPublicImports(Context& ctx, const FileDescriptor& primary_file) { + for (int i = 0; i < primary_file.public_dependency_count(); ++i) { + auto& dep_file = *primary_file.public_dependency(i); // If the publicly imported file is a src of the current `proto_library` // we don't need to emit `pub use` here, we already do it for all srcs in // RustGenerator::Generate. In other words, all srcs are implicitly publicly @@ -134,30 +132,29 @@ void EmitPublicImports(Context& primary_file) { // TODO: Handle the case where a non-primary src with the same // declared package as the primary src publicly imports a file that the // primary doesn't. - auto dep = primary_file.WithDesc(dep_file); - if (IsInCurrentlyGeneratingCrate(dep)) { + if (IsInCurrentlyGeneratingCrate(ctx, dep_file)) { return; } - EmitPubUseForImportedMessages(primary_file, dep); + EmitPubUseForImportedMessages(ctx, primary_file, dep_file); } } // Emits submodule declarations so `rustc` can find non primary sources from the // primary file. void DeclareSubmodulesForNonPrimarySrcs( - Context& primary_file, - absl::Span> non_primary_srcs) { - std::string primary_file_path = GetRsFile(primary_file); + Context& ctx, const FileDescriptor& primary_file, + absl::Span non_primary_srcs) { + std::string primary_file_path = GetRsFile(ctx, primary_file); RelativePath primary_relpath(primary_file_path); - for (const auto& non_primary_src : non_primary_srcs) { - std::string non_primary_file_path = GetRsFile(non_primary_src); + for (const FileDescriptor* non_primary_src : non_primary_srcs) { + std::string non_primary_file_path = GetRsFile(ctx, *non_primary_src); std::string relative_mod_path = primary_relpath.Relative(RelativePath(non_primary_file_path)); - primary_file.Emit({{"file_path", relative_mod_path}, - {"foo", primary_file_path}, - {"bar", non_primary_file_path}, - {"mod_name", RustInternalModuleName(non_primary_src)}}, - R"rs( + ctx.Emit({{"file_path", relative_mod_path}, + {"foo", primary_file_path}, + {"bar", non_primary_file_path}, + {"mod_name", RustInternalModuleName(ctx, *non_primary_src)}}, + R"rs( #[path="$file_path$"] pub mod $mod_name$; )rs"); @@ -169,33 +166,32 @@ void DeclareSubmodulesForNonPrimarySrcs( // // Returns the non-primary sources that should be reexported from the package of // the primary file. -std::vector*> ReexportMessagesFromSubmodules( - Context& primary_file, - absl::Span> non_primary_srcs) { - absl::btree_map*>> +std::vector ReexportMessagesFromSubmodules( + Context& ctx, const FileDescriptor& primary_file, + absl::Span non_primary_srcs) { + absl::btree_map> packages; - for (const Context& ctx : non_primary_srcs) { - packages[ctx.desc().package()].push_back(&ctx); + for (const FileDescriptor* file : non_primary_srcs) { + packages[file->package()].push_back(file); } for (const auto& pair : packages) { // We will deal with messages for the package of the primary file later. auto fds = pair.second; - absl::string_view package = fds[0]->desc().package(); - if (package == primary_file.desc().package()) continue; + absl::string_view package = fds[0]->package(); + if (package == primary_file.package()) continue; - EmitOpeningOfPackageModules(package, primary_file); - for (const Context* c : fds) { - EmitPubUseOfOwnMessages(primary_file, *c); + EmitOpeningOfPackageModules(ctx, package); + for (const FileDescriptor* c : fds) { + EmitPubUseOfOwnMessages(ctx, primary_file, *c); } - EmitClosingOfPackageModules(package, primary_file); + EmitClosingOfPackageModules(ctx, package); } - return packages[primary_file.desc().package()]; + return packages[primary_file.package()]; } } // namespace -bool RustGenerator::Generate(const FileDescriptor* file_desc, +bool RustGenerator::Generate(const FileDescriptor* file, const std::string& parameter, GeneratorContext* generator_context, std::string* error) const { @@ -210,15 +206,15 @@ bool RustGenerator::Generate(const FileDescriptor* file_desc, RustGeneratorContext rust_generator_context(&files_in_current_crate); - Context file(&*opts, file_desc, &rust_generator_context, - nullptr); + Context ctx_without_printer(&*opts, &rust_generator_context, nullptr); - auto outfile = absl::WrapUnique(generator_context->Open(GetRsFile(file))); + auto outfile = absl::WrapUnique( + generator_context->Open(GetRsFile(ctx_without_printer, *file))); io::Printer printer(outfile.get()); - file = file.WithPrinter(&printer); + Context ctx = ctx_without_printer.WithPrinter(&printer); // Convenience shorthands for common symbols. - auto v = file.printer().WithVars({ + auto v = ctx.printer().WithVars({ {"std", "::__std"}, {"pb", "::__pb"}, {"pbi", "::__pb::__internal"}, @@ -227,67 +223,66 @@ bool RustGenerator::Generate(const FileDescriptor* file_desc, {"Phantom", "::__std::marker::PhantomData"}, }); - file.Emit({{"kernel", KernelRsName(file.opts().kernel)}}, R"rs( + ctx.Emit({{"kernel", KernelRsName(ctx.opts().kernel)}}, R"rs( extern crate protobuf_$kernel$ as __pb; extern crate std as __std; )rs"); - std::vector> file_contexts; + std::vector file_contexts; for (const FileDescriptor* f : files_in_current_crate) { - file_contexts.push_back(file.WithDesc(*f)); + file_contexts.push_back(f); } // Generating the primary file? - if (file_desc == rust_generator_context.primary_file()) { + if (file == &rust_generator_context.primary_file()) { auto non_primary_srcs = absl::MakeConstSpan(file_contexts).subspan(1); - DeclareSubmodulesForNonPrimarySrcs(file, non_primary_srcs); + DeclareSubmodulesForNonPrimarySrcs(ctx, *file, non_primary_srcs); - std::vector*> - non_primary_srcs_in_primary_package = - ReexportMessagesFromSubmodules(file, non_primary_srcs); + std::vector non_primary_srcs_in_primary_package = + ReexportMessagesFromSubmodules(ctx, *file, non_primary_srcs); - EmitOpeningOfPackageModules(file.desc().package(), file); + EmitOpeningOfPackageModules(ctx, file->package()); - for (const Context* non_primary_file : + for (const FileDescriptor* non_primary_file : non_primary_srcs_in_primary_package) { - EmitPubUseOfOwnMessages(file, *non_primary_file); + EmitPubUseOfOwnMessages(ctx, *file, *non_primary_file); } } - EmitPublicImports(file); + EmitPublicImports(ctx, *file); std::unique_ptr thunks_cc; std::unique_ptr thunks_printer; - if (file.is_cpp()) { - thunks_cc.reset(generator_context->Open(GetThunkCcFile(file))); + if (ctx.is_cpp()) { + thunks_cc.reset(generator_context->Open(GetThunkCcFile(ctx, *file))); thunks_printer = std::make_unique(thunks_cc.get()); - thunks_printer->Emit({{"proto_h", GetHeaderFile(file)}}, + thunks_printer->Emit({{"proto_h", GetHeaderFile(ctx, *file)}}, R"cc( #include "$proto_h$" #include "google/protobuf/rust/cpp_kernel/cpp_api.h" )cc"); } - for (int i = 0; i < file.desc().message_type_count(); ++i) { - auto msg = file.WithDesc(file.desc().message_type(i)); + for (int i = 0; i < file->message_type_count(); ++i) { + auto& msg = *file->message_type(i); - GenerateRs(msg); - msg.printer().PrintRaw("\n"); + GenerateRs(ctx, msg); + ctx.printer().PrintRaw("\n"); - if (file.is_cpp()) { - auto thunks_msg = msg.WithPrinter(thunks_printer.get()); + if (ctx.is_cpp()) { + auto thunks_ctx = ctx.WithPrinter(thunks_printer.get()); - thunks_msg.Emit({{"Msg", msg.desc().full_name()}}, R"cc( + thunks_ctx.Emit({{"Msg", msg.full_name()}}, R"cc( // $Msg$ )cc"); - GenerateThunksCc(thunks_msg); - thunks_msg.printer().PrintRaw("\n"); + GenerateThunksCc(thunks_ctx, msg); + thunks_ctx.printer().PrintRaw("\n"); } } - if (file_desc == files_in_current_crate.front()) { - EmitClosingOfPackageModules(file.desc().package(), file); + if (file == files_in_current_crate.front()) { + EmitClosingOfPackageModules(ctx, file->package()); } return true; } diff --git a/src/google/protobuf/compiler/rust/message.cc b/src/google/protobuf/compiler/rust/message.cc index 256cf81ffd5d9..6f5454d1a5de9 100644 --- a/src/google/protobuf/compiler/rust/message.cc +++ b/src/google/protobuf/compiler/rust/message.cc @@ -24,16 +24,16 @@ namespace compiler { namespace rust { namespace { -void MessageNew(Context msg) { - switch (msg.opts().kernel) { +void MessageNew(Context& ctx, const Descriptor& msg) { + switch (ctx.opts().kernel) { case Kernel::kCpp: - msg.Emit({{"new_thunk", Thunk(msg, "new")}}, R"rs( + ctx.Emit({{"new_thunk", Thunk(ctx, msg, "new")}}, R"rs( Self { inner: $pbr$::MessageInner { msg: unsafe { $new_thunk$() } } } )rs"); return; case Kernel::kUpb: - msg.Emit({{"new_thunk", Thunk(msg, "new")}}, R"rs( + ctx.Emit({{"new_thunk", Thunk(ctx, msg, "new")}}, R"rs( let arena = $pbr$::Arena::new(); Self { inner: $pbr$::MessageInner { @@ -48,16 +48,16 @@ void MessageNew(Context msg) { ABSL_LOG(FATAL) << "unreachable"; } -void MessageSerialize(Context msg) { - switch (msg.opts().kernel) { +void MessageSerialize(Context& ctx, const Descriptor& msg) { + switch (ctx.opts().kernel) { case Kernel::kCpp: - msg.Emit({{"serialize_thunk", Thunk(msg, "serialize")}}, R"rs( + ctx.Emit({{"serialize_thunk", Thunk(ctx, msg, "serialize")}}, R"rs( unsafe { $serialize_thunk$(self.inner.msg) } )rs"); return; case Kernel::kUpb: - msg.Emit({{"serialize_thunk", Thunk(msg, "serialize")}}, R"rs( + ctx.Emit({{"serialize_thunk", Thunk(ctx, msg, "serialize")}}, R"rs( let arena = $pbr$::Arena::new(); let mut len = 0; unsafe { @@ -71,12 +71,12 @@ void MessageSerialize(Context msg) { ABSL_LOG(FATAL) << "unreachable"; } -void MessageDeserialize(Context msg) { - switch (msg.opts().kernel) { +void MessageDeserialize(Context& ctx, const Descriptor& msg) { + switch (ctx.opts().kernel) { case Kernel::kCpp: - msg.Emit( + ctx.Emit( { - {"deserialize_thunk", Thunk(msg, "deserialize")}, + {"deserialize_thunk", Thunk(ctx, msg, "deserialize")}, }, R"rs( let success = unsafe { @@ -92,7 +92,7 @@ void MessageDeserialize(Context msg) { return; case Kernel::kUpb: - msg.Emit({{"deserialize_thunk", Thunk(msg, "parse")}}, R"rs( + ctx.Emit({{"deserialize_thunk", Thunk(ctx, msg, "parse")}}, R"rs( let arena = $pbr$::Arena::new(); let msg = unsafe { $deserialize_thunk$(data.as_ptr(), data.len(), arena.raw()) @@ -115,15 +115,15 @@ void MessageDeserialize(Context msg) { ABSL_LOG(FATAL) << "unreachable"; } -void MessageExterns(Context msg) { - switch (msg.opts().kernel) { +void MessageExterns(Context& ctx, const Descriptor& msg) { + switch (ctx.opts().kernel) { case Kernel::kCpp: - msg.Emit( + ctx.Emit( { - {"new_thunk", Thunk(msg, "new")}, - {"delete_thunk", Thunk(msg, "delete")}, - {"serialize_thunk", Thunk(msg, "serialize")}, - {"deserialize_thunk", Thunk(msg, "deserialize")}, + {"new_thunk", Thunk(ctx, msg, "new")}, + {"delete_thunk", Thunk(ctx, msg, "delete")}, + {"serialize_thunk", Thunk(ctx, msg, "serialize")}, + {"deserialize_thunk", Thunk(ctx, msg, "deserialize")}, }, R"rs( fn $new_thunk$() -> $pbi$::RawMessage; @@ -134,11 +134,11 @@ void MessageExterns(Context msg) { return; case Kernel::kUpb: - msg.Emit( + ctx.Emit( { - {"new_thunk", Thunk(msg, "new")}, - {"serialize_thunk", Thunk(msg, "serialize")}, - {"deserialize_thunk", Thunk(msg, "parse")}, + {"new_thunk", Thunk(ctx, msg, "new")}, + {"serialize_thunk", Thunk(ctx, msg, "serialize")}, + {"deserialize_thunk", Thunk(ctx, msg, "parse")}, }, R"rs( fn $new_thunk$(arena: $pbi$::RawArena) -> $pbi$::RawMessage; @@ -151,36 +151,37 @@ void MessageExterns(Context msg) { ABSL_LOG(FATAL) << "unreachable"; } -void MessageDrop(Context msg) { - if (msg.is_upb()) { +void MessageDrop(Context& ctx, const Descriptor& msg) { + if (ctx.is_upb()) { // Nothing to do here; drop glue (which will run drop(self.arena) // automatically) is sufficient. return; } - msg.Emit({{"delete_thunk", Thunk(msg, "delete")}}, R"rs( + ctx.Emit({{"delete_thunk", Thunk(ctx, msg, "delete")}}, R"rs( unsafe { $delete_thunk$(self.inner.msg); } )rs"); } -void GetterForViewOrMut(Context field, bool is_mut) { - auto fieldName = field.desc().name(); - auto fieldType = field.desc().type(); - auto getter_thunk = Thunk(field, "get"); - auto setter_thunk = Thunk(field, "set"); - auto clearer_thunk = Thunk(field, "clear"); +void GetterForViewOrMut(Context& ctx, const FieldDescriptor& field, + bool is_mut) { + auto fieldName = field.name(); + auto fieldType = field.type(); + auto getter_thunk = Thunk(ctx, field, "get"); + auto setter_thunk = Thunk(ctx, field, "set"); + auto clearer_thunk = Thunk(ctx, field, "clear"); // If we're dealing with a Mut, the getter must be supplied // self.inner.msg() whereas a View has to be supplied self.msg auto self = is_mut ? "self.inner.msg()" : "self.msg"; if (fieldType == FieldDescriptor::TYPE_MESSAGE) { - Context d = field.WithDesc(field.desc().message_type()); + const Descriptor& msg = *field.message_type(); // TODO: support messages which are defined in other crates. - if (!IsInCurrentlyGeneratingCrate(d)) { + if (!IsInCurrentlyGeneratingCrate(ctx, msg)) { return; } - auto prefix = "crate::" + GetCrateRelativeQualifiedPath(d); - field.Emit( + auto prefix = "crate::" + GetCrateRelativeQualifiedPath(ctx, msg); + ctx.Emit( { {"prefix", prefix}, {"field", fieldName}, @@ -190,8 +191,8 @@ void GetterForViewOrMut(Context field, bool is_mut) { { "view_body", [&] { - if (field.is_upb()) { - field.Emit({}, R"rs( + if (ctx.is_upb()) { + ctx.Emit({}, R"rs( let submsg = unsafe { $getter_thunk$($self$) }; match submsg { None => $prefix$View::new($pbi$::Private, @@ -200,7 +201,7 @@ void GetterForViewOrMut(Context field, bool is_mut) { } )rs"); } else { - field.Emit({}, R"rs( + ctx.Emit({}, R"rs( let submsg = unsafe { $getter_thunk$($self$) }; $prefix$View::new($pbi$::Private, submsg) )rs"); @@ -216,18 +217,18 @@ void GetterForViewOrMut(Context field, bool is_mut) { return; } - auto rsType = PrimitiveRsTypeName(field.desc()); + auto rsType = PrimitiveRsTypeName(field); if (fieldType == FieldDescriptor::TYPE_STRING || fieldType == FieldDescriptor::TYPE_BYTES) { - field.Emit({{"field", fieldName}, - {"self", self}, - {"getter_thunk", getter_thunk}, - {"setter_thunk", setter_thunk}, - {"RsType", rsType}, - {"maybe_mutator", - [&] { - if (is_mut) { - field.Emit({}, R"rs( + ctx.Emit({{"field", fieldName}, + {"self", self}, + {"getter_thunk", getter_thunk}, + {"setter_thunk", setter_thunk}, + {"RsType", rsType}, + {"maybe_mutator", + [&] { + if (is_mut) { + ctx.Emit({}, R"rs( pub fn r#$field$_mut(&self) -> $pb$::Mut<'_, $RsType$> { static VTABLE: $pbi$::BytesMutVTable = $pbi$::BytesMutVTable::new( @@ -248,9 +249,9 @@ void GetterForViewOrMut(Context field, bool is_mut) { } } )rs"); - } - }}}, - R"rs( + } + }}}, + R"rs( pub fn r#$field$(&self) -> $pb$::View<'_, $RsType$> { let s = unsafe { $getter_thunk$($self$).as_ref() }; unsafe { __pb::ProtoStr::from_utf8_unchecked(s).into() } @@ -259,19 +260,19 @@ void GetterForViewOrMut(Context field, bool is_mut) { $maybe_mutator$ )rs"); } else { - field.Emit({{"field", fieldName}, - {"getter_thunk", getter_thunk}, - {"setter_thunk", setter_thunk}, - {"clearer_thunk", clearer_thunk}, - {"self", self}, - {"RsType", rsType}, - {"maybe_mutator", - [&] { - // TODO: once the rust public api is accessible, - // by tooling, ensure that this only appears for the - // mutational pathway - if (is_mut && fieldType) { - field.Emit({}, R"rs( + ctx.Emit({{"field", fieldName}, + {"getter_thunk", getter_thunk}, + {"setter_thunk", setter_thunk}, + {"clearer_thunk", clearer_thunk}, + {"self", self}, + {"RsType", rsType}, + {"maybe_mutator", + [&] { + // TODO: once the rust public api is accessible, + // by tooling, ensure that this only appears for the + // mutational pathway + if (is_mut && fieldType) { + ctx.Emit({}, R"rs( pub fn r#$field$_mut(&self) -> $pb$::Mut<'_, $RsType$> { static VTABLE: $pbi$::PrimitiveVTable<$RsType$> = $pbi$::PrimitiveVTable::new( @@ -290,9 +291,9 @@ void GetterForViewOrMut(Context field, bool is_mut) { } } )rs"); - } - }}}, - R"rs( + } + }}}, + R"rs( pub fn r#$field$(&self) -> $pb$::View<'_, $RsType$> { unsafe { $getter_thunk$($self$) } } @@ -302,93 +303,89 @@ void GetterForViewOrMut(Context field, bool is_mut) { } } -void AccessorsForViewOrMut(Context msg, bool is_mut) { - for (int i = 0; i < msg.desc().field_count(); ++i) { - auto field = msg.WithDesc(*msg.desc().field(i)); - if (field.desc().is_repeated()) continue; +void AccessorsForViewOrMut(Context& ctx, const Descriptor& msg, bool is_mut) { + for (int i = 0; i < msg.field_count(); ++i) { + const FieldDescriptor& field = *msg.field(i); + if (field.is_repeated()) continue; // TODO - add cord support - if (field.desc().options().has_ctype()) continue; + if (field.options().has_ctype()) continue; // TODO - if (field.desc().type() == FieldDescriptor::TYPE_ENUM || - field.desc().type() == FieldDescriptor::TYPE_GROUP) + if (field.type() == FieldDescriptor::TYPE_ENUM || + field.type() == FieldDescriptor::TYPE_GROUP) continue; - GetterForViewOrMut(field, is_mut); - msg.printer().PrintRaw("\n"); + GetterForViewOrMut(ctx, field, is_mut); + ctx.printer().PrintRaw("\n"); } } } // namespace -void GenerateRs(Context msg) { - if (msg.desc().map_key() != nullptr) { - ABSL_LOG(WARNING) << "unsupported map field: " << msg.desc().full_name(); +void GenerateRs(Context& ctx, const Descriptor& msg) { + if (msg.map_key() != nullptr) { + ABSL_LOG(WARNING) << "unsupported map field: " << msg.full_name(); return; } - msg.Emit( - {{"Msg", msg.desc().name()}, - {"Msg::new", [&] { MessageNew(msg); }}, - {"Msg::serialize", [&] { MessageSerialize(msg); }}, - {"Msg::deserialize", [&] { MessageDeserialize(msg); }}, - {"Msg::drop", [&] { MessageDrop(msg); }}, - {"Msg_externs", [&] { MessageExterns(msg); }}, - {"accessor_fns", - [&] { - for (int i = 0; i < msg.desc().field_count(); ++i) { - auto field = msg.WithDesc(*msg.desc().field(i)); - msg.Emit({{"comment", FieldInfoComment(field)}}, R"rs( + ctx.Emit({{"Msg", msg.name()}, + {"Msg::new", [&] { MessageNew(ctx, msg); }}, + {"Msg::serialize", [&] { MessageSerialize(ctx, msg); }}, + {"Msg::deserialize", [&] { MessageDeserialize(ctx, msg); }}, + {"Msg::drop", [&] { MessageDrop(ctx, msg); }}, + {"Msg_externs", [&] { MessageExterns(ctx, msg); }}, + {"accessor_fns", + [&] { + for (int i = 0; i < msg.field_count(); ++i) { + auto& field = *msg.field(i); + ctx.Emit({{"comment", FieldInfoComment(ctx, field)}}, R"rs( // $comment$ )rs"); - GenerateAccessorMsgImpl(field); - msg.printer().PrintRaw("\n"); - } - }}, - {"oneof_accessor_fns", - [&] { - for (int i = 0; i < msg.desc().real_oneof_decl_count(); ++i) { - GenerateOneofAccessors( - msg.WithDesc(*msg.desc().real_oneof_decl(i))); - msg.printer().PrintRaw("\n"); - } - }}, - {"accessor_externs", - [&] { - for (int i = 0; i < msg.desc().field_count(); ++i) { - GenerateAccessorExternC(msg.WithDesc(*msg.desc().field(i))); - msg.printer().PrintRaw("\n"); - } - }}, - {"oneof_externs", - [&] { - for (int i = 0; i < msg.desc().real_oneof_decl_count(); ++i) { - GenerateOneofExternC(msg.WithDesc(*msg.desc().real_oneof_decl(i))); - msg.printer().PrintRaw("\n"); - } - }}, - {"nested_msgs", - [&] { - // If we have no nested types or oneofs, bail out without emitting - // an empty mod SomeMsg_. - if (msg.desc().nested_type_count() == 0 && - msg.desc().real_oneof_decl_count() == 0) { - return; - } - msg.Emit( - {{"Msg", msg.desc().name()}, - {"nested_msgs", - [&] { - for (int i = 0; i < msg.desc().nested_type_count(); ++i) { - auto nested_msg = msg.WithDesc(msg.desc().nested_type(i)); - GenerateRs(nested_msg); - } - }}, - {"oneofs", - [&] { - for (int i = 0; i < msg.desc().real_oneof_decl_count(); ++i) { - GenerateOneofDefinition( - msg.WithDesc(*msg.desc().real_oneof_decl(i))); - } - }}}, - R"rs( + GenerateAccessorMsgImpl(ctx, field); + ctx.printer().PrintRaw("\n"); + } + }}, + {"oneof_accessor_fns", + [&] { + for (int i = 0; i < msg.real_oneof_decl_count(); ++i) { + GenerateOneofAccessors(ctx, *msg.real_oneof_decl(i)); + ctx.printer().PrintRaw("\n"); + } + }}, + {"accessor_externs", + [&] { + for (int i = 0; i < msg.field_count(); ++i) { + GenerateAccessorExternC(ctx, *msg.field(i)); + ctx.printer().PrintRaw("\n"); + } + }}, + {"oneof_externs", + [&] { + for (int i = 0; i < msg.real_oneof_decl_count(); ++i) { + GenerateOneofExternC(ctx, *msg.real_oneof_decl(i)); + ctx.printer().PrintRaw("\n"); + } + }}, + {"nested_msgs", + [&] { + // If we have no nested types or oneofs, bail out without + // emitting an empty mod SomeMsg_. + if (msg.nested_type_count() == 0 && + msg.real_oneof_decl_count() == 0) { + return; + } + ctx.Emit( + {{"Msg", msg.name()}, + {"nested_msgs", + [&] { + for (int i = 0; i < msg.nested_type_count(); ++i) { + GenerateRs(ctx, *msg.nested_type(i)); + } + }}, + {"oneofs", + [&] { + for (int i = 0; i < msg.real_oneof_decl_count(); ++i) { + GenerateOneofDefinition(ctx, *msg.real_oneof_decl(i)); + } + }}}, + R"rs( #[allow(non_snake_case)] pub mod $Msg$_ { $nested_msgs$ @@ -396,10 +393,12 @@ void GenerateRs(Context msg) { $oneofs$ } // mod $Msg$_ )rs"); - }}, - {"accessor_fns_for_views", [&] { AccessorsForViewOrMut(msg, false); }}, - {"accessor_fns_for_muts", [&] { AccessorsForViewOrMut(msg, true); }}}, - R"rs( + }}, + {"accessor_fns_for_views", + [&] { AccessorsForViewOrMut(ctx, msg, false); }}, + {"accessor_fns_for_muts", + [&] { AccessorsForViewOrMut(ctx, msg, true); }}}, + R"rs( #[allow(non_camel_case_types)] // TODO: Implement support for debug redaction #[derive(Debug)] @@ -542,9 +541,9 @@ void GenerateRs(Context msg) { $nested_msgs$ )rs"); - if (msg.is_cpp()) { - msg.printer().PrintRaw("\n"); - msg.Emit({{"Msg", msg.desc().name()}}, R"rs( + if (ctx.is_cpp()) { + ctx.printer().PrintRaw("\n"); + ctx.Emit({{"Msg", msg.name()}}, R"rs( impl $Msg$ { pub fn __unstable_wrap_cpp_grant_permission_to_break(msg: $pbi$::RawMessage) -> Self { Self { inner: $pbr$::MessageInner { msg } } @@ -558,39 +557,37 @@ void GenerateRs(Context msg) { } // Generates code for a particular message in `.pb.thunk.cc`. -void GenerateThunksCc(Context msg) { - ABSL_CHECK(msg.is_cpp()); - if (msg.desc().map_key() != nullptr) { - ABSL_LOG(WARNING) << "unsupported map field: " << msg.desc().full_name(); +void GenerateThunksCc(Context& ctx, const Descriptor& msg) { + ABSL_CHECK(ctx.is_cpp()); + if (msg.map_key() != nullptr) { + ABSL_LOG(WARNING) << "unsupported map field: " << msg.full_name(); return; } - msg.Emit( + ctx.Emit( {{"abi", "\"C\""}, // Workaround for syntax highlight bug in VSCode. - {"Msg", msg.desc().name()}, - {"QualifiedMsg", cpp::QualifiedClassName(&msg.desc())}, - {"new_thunk", Thunk(msg, "new")}, - {"delete_thunk", Thunk(msg, "delete")}, - {"serialize_thunk", Thunk(msg, "serialize")}, - {"deserialize_thunk", Thunk(msg, "deserialize")}, + {"Msg", msg.name()}, + {"QualifiedMsg", cpp::QualifiedClassName(&msg)}, + {"new_thunk", Thunk(ctx, msg, "new")}, + {"delete_thunk", Thunk(ctx, msg, "delete")}, + {"serialize_thunk", Thunk(ctx, msg, "serialize")}, + {"deserialize_thunk", Thunk(ctx, msg, "deserialize")}, {"nested_msg_thunks", [&] { - for (int i = 0; i < msg.desc().nested_type_count(); ++i) { - Context nested_msg = - msg.WithDesc(msg.desc().nested_type(i)); - GenerateThunksCc(nested_msg); + for (int i = 0; i < msg.nested_type_count(); ++i) { + GenerateThunksCc(ctx, *msg.nested_type(i)); } }}, {"accessor_thunks", [&] { - for (int i = 0; i < msg.desc().field_count(); ++i) { - GenerateAccessorThunkCc(msg.WithDesc(*msg.desc().field(i))); + for (int i = 0; i < msg.field_count(); ++i) { + GenerateAccessorThunkCc(ctx, *msg.field(i)); } }}, {"oneof_thunks", [&] { - for (int i = 0; i < msg.desc().real_oneof_decl_count(); ++i) { - GenerateOneofThunkCc(msg.WithDesc(*msg.desc().real_oneof_decl(i))); + for (int i = 0; i < msg.real_oneof_decl_count(); ++i) { + GenerateOneofThunkCc(ctx, *msg.real_oneof_decl(i)); } }}}, R"cc( diff --git a/src/google/protobuf/compiler/rust/message.h b/src/google/protobuf/compiler/rust/message.h index 4d1c392f70e3c..e2734eb88c4c0 100644 --- a/src/google/protobuf/compiler/rust/message.h +++ b/src/google/protobuf/compiler/rust/message.h @@ -21,10 +21,10 @@ namespace compiler { namespace rust { // Generates code for a particular message in `.pb.rs`. -void GenerateRs(Context msg); +void GenerateRs(Context& ctx, const Descriptor& msg); // Generates code for a particular message in `.pb.thunk.cc`. -void GenerateThunksCc(Context msg); +void GenerateThunksCc(Context& ctx, const Descriptor& msg); } // namespace rust } // namespace compiler diff --git a/src/google/protobuf/compiler/rust/naming.cc b/src/google/protobuf/compiler/rust/naming.cc index 6685493c04757..12fb0891a4ab1 100644 --- a/src/google/protobuf/compiler/rust/naming.cc +++ b/src/google/protobuf/compiler/rust/naming.cc @@ -26,22 +26,23 @@ namespace protobuf { namespace compiler { namespace rust { namespace { -std::string GetUnderscoreDelimitedFullName(Context msg) { - std::string result = msg.desc().full_name(); +std::string GetUnderscoreDelimitedFullName(Context& ctx, + const Descriptor& msg) { + std::string result = msg.full_name(); absl::StrReplaceAll({{".", "_"}}, &result); return result; } } // namespace -std::string GetCrateName(Context dep) { - absl::string_view path = dep.desc().name(); +std::string GetCrateName(Context& ctx, const FileDescriptor& dep) { + absl::string_view path = dep.name(); auto basename = path.substr(path.rfind('/') + 1); return absl::StrReplaceAll(basename, {{".", "_"}, {"-", "_"}}); } -std::string GetRsFile(Context file) { - auto basename = StripProto(file.desc().name()); - switch (auto k = file.opts().kernel) { +std::string GetRsFile(Context& ctx, const FileDescriptor& file) { + auto basename = StripProto(file.name()); + switch (auto k = ctx.opts().kernel) { case Kernel::kUpb: return absl::StrCat(basename, ".u.pb.rs"); case Kernel::kCpp: @@ -52,42 +53,41 @@ std::string GetRsFile(Context file) { } } -std::string GetThunkCcFile(Context file) { - auto basename = StripProto(file.desc().name()); +std::string GetThunkCcFile(Context& ctx, const FileDescriptor& file) { + auto basename = StripProto(file.name()); return absl::StrCat(basename, ".pb.thunks.cc"); } -std::string GetHeaderFile(Context file) { - auto basename = StripProto(file.desc().name()); +std::string GetHeaderFile(Context& ctx, const FileDescriptor& file) { + auto basename = StripProto(file.name()); return absl::StrCat(basename, ".proto.h"); } namespace { template -std::string FieldPrefix(Context field) { - // NOTE: When field.is_upb(), this functions outputs must match the symbols +std::string FieldPrefix(Context& ctx, const T& field) { + // NOTE: When ctx.is_upb(), this functions outputs must match the symbols // that the upbc plugin generates exactly. Failure to do so correctly results // in a link-time failure. - absl::string_view prefix = field.is_cpp() ? "__rust_proto_thunk__" : ""; - std::string thunk_prefix = - absl::StrCat(prefix, GetUnderscoreDelimitedFullName( - field.WithDesc(field.desc().containing_type()))); + absl::string_view prefix = ctx.is_cpp() ? "__rust_proto_thunk__" : ""; + std::string thunk_prefix = absl::StrCat( + prefix, GetUnderscoreDelimitedFullName(ctx, *field.containing_type())); return thunk_prefix; } template -std::string Thunk(Context field, absl::string_view op) { - std::string thunk = FieldPrefix(field); +std::string Thunk(Context& ctx, const T& field, absl::string_view op) { + std::string thunk = FieldPrefix(ctx, field); absl::string_view format; - if (field.is_upb() && op == "get") { + if (ctx.is_upb() && op == "get") { // upb getter is simply the field name (no "get" in the name). format = "_$1"; - } else if (field.is_upb() && op == "get_mut") { + } else if (ctx.is_upb() && op == "get_mut") { // same as above, with with `mutable` prefix format = "_mutable_$1"; - } else if (field.is_upb() && op == "case") { + } else if (ctx.is_upb() && op == "case") { // some upb functions are in the order x_op compared to has/set/clear which // are in the other order e.g. op_x. format = "_$1_$0"; @@ -95,51 +95,53 @@ std::string Thunk(Context field, absl::string_view op) { format = "_$0_$1"; } - absl::SubstituteAndAppend(&thunk, format, op, field.desc().name()); + absl::SubstituteAndAppend(&thunk, format, op, field.name()); return thunk; } -std::string ThunkMapOrRepeated(Context field, +std::string ThunkMapOrRepeated(Context& ctx, const FieldDescriptor& field, absl::string_view op) { - if (!field.is_upb()) { - return Thunk(field, op); + if (!ctx.is_upb()) { + return Thunk(ctx, field, op); } - std::string thunk = absl::StrCat("_", FieldPrefix(field)); + std::string thunk = absl::StrCat("_", FieldPrefix(ctx, field)); absl::string_view format; if (op == "get") { - format = field.desc().is_map() ? "_$1_upb_map" : "_$1_upb_array"; + format = field.is_map() ? "_$1_upb_map" : "_$1_upb_array"; } else if (op == "get_mut") { - format = - field.desc().is_map() ? "_$1_mutable_upb_map" : "_$1_mutable_upb_array"; + format = field.is_map() ? "_$1_mutable_upb_map" : "_$1_mutable_upb_array"; } else { - return Thunk(field, op); + return Thunk(ctx, field, op); } - absl::SubstituteAndAppend(&thunk, format, op, field.desc().name()); + absl::SubstituteAndAppend(&thunk, format, op, field.name()); return thunk; } } // namespace -std::string Thunk(Context field, absl::string_view op) { - if (field.desc().is_map() || field.desc().is_repeated()) { - return ThunkMapOrRepeated(field, op); +std::string Thunk(Context& ctx, const FieldDescriptor& field, + absl::string_view op) { + if (field.is_map() || field.is_repeated()) { + return ThunkMapOrRepeated(ctx, field, op); } - return Thunk(field, op); + return Thunk(ctx, field, op); } -std::string Thunk(Context field, absl::string_view op) { - return Thunk(field, op); +std::string Thunk(Context& ctx, const OneofDescriptor& field, + absl::string_view op) { + return Thunk(ctx, field, op); } -std::string Thunk(Context msg, absl::string_view op) { - absl::string_view prefix = msg.is_cpp() ? "__rust_proto_thunk__" : ""; - return absl::StrCat(prefix, GetUnderscoreDelimitedFullName(msg), "_", op); +std::string Thunk(Context& ctx, const Descriptor& msg, absl::string_view op) { + absl::string_view prefix = ctx.is_cpp() ? "__rust_proto_thunk__" : ""; + return absl::StrCat(prefix, GetUnderscoreDelimitedFullName(ctx, msg), "_", + op); } -std::string PrimitiveRsTypeName(const FieldDescriptor& desc) { - switch (desc.type()) { +std::string PrimitiveRsTypeName(const FieldDescriptor& field) { + switch (field.type()) { case FieldDescriptor::TYPE_BOOL: return "bool"; case FieldDescriptor::TYPE_INT32: @@ -167,7 +169,7 @@ std::string PrimitiveRsTypeName(const FieldDescriptor& desc) { default: break; } - ABSL_LOG(FATAL) << "Unsupported field type: " << desc.type_name(); + ABSL_LOG(FATAL) << "Unsupported field type: " << field.type_name(); return ""; } @@ -180,20 +182,18 @@ std::string PrimitiveRsTypeName(const FieldDescriptor& desc) { // // If the message has no package and no containing messages then this returns // empty string. -std::string RustModule(Context msg) { - const Descriptor& desc = msg.desc(); - +std::string RustModule(Context& ctx, const Descriptor& msg) { std::vector modules; std::vector package_modules = - absl::StrSplit(desc.file()->package(), '.', absl::SkipEmpty()); + absl::StrSplit(msg.file()->package(), '.', absl::SkipEmpty()); modules.insert(modules.begin(), package_modules.begin(), package_modules.end()); // Innermost to outermost order. std::vector modules_from_containing_types; - const Descriptor* parent = desc.containing_type(); + const Descriptor* parent = msg.containing_type(); while (parent != nullptr) { modules_from_containing_types.push_back(absl::StrCat(parent->name(), "_")); parent = parent->containing_type(); @@ -213,27 +213,25 @@ std::string RustModule(Context msg) { return absl::StrJoin(modules, "::"); } -std::string RustInternalModuleName(Context file) { +std::string RustInternalModuleName(Context& ctx, const FileDescriptor& file) { // TODO: Introduce a more robust mangling here to avoid conflicts // between `foo/bar/baz.proto` and `foo_bar/baz.proto`. - return absl::StrReplaceAll(StripProto(file.desc().name()), {{"/", "_"}}); + return absl::StrReplaceAll(StripProto(file.name()), {{"/", "_"}}); } -std::string GetCrateRelativeQualifiedPath(Context msg) { - return absl::StrCat(RustModule(msg), msg.desc().name()); +std::string GetCrateRelativeQualifiedPath(Context& ctx, const Descriptor& msg) { + return absl::StrCat(RustModule(ctx, msg), msg.name()); } -std::string FieldInfoComment(Context field) { - absl::string_view label = - field.desc().is_repeated() ? "repeated" : "optional"; - std::string comment = - absl::StrCat(field.desc().name(), ": ", label, " ", - FieldDescriptor::TypeName(field.desc().type())); +std::string FieldInfoComment(Context& ctx, const FieldDescriptor& field) { + absl::string_view label = field.is_repeated() ? "repeated" : "optional"; + std::string comment = absl::StrCat(field.name(), ": ", label, " ", + FieldDescriptor::TypeName(field.type())); - if (auto* m = field.desc().message_type()) { + if (auto* m = field.message_type()) { absl::StrAppend(&comment, " ", m->full_name()); } - if (auto* m = field.desc().enum_type()) { + if (auto* m = field.enum_type()) { absl::StrAppend(&comment, " ", m->full_name()); } diff --git a/src/google/protobuf/compiler/rust/naming.h b/src/google/protobuf/compiler/rust/naming.h index 2bb5cc539c2c1..e6f7b7f970ae9 100644 --- a/src/google/protobuf/compiler/rust/naming.h +++ b/src/google/protobuf/compiler/rust/naming.h @@ -19,25 +19,27 @@ namespace google { namespace protobuf { namespace compiler { namespace rust { -std::string GetCrateName(Context dep); +std::string GetCrateName(Context& ctx, const FileDescriptor& dep); -std::string GetRsFile(Context file); -std::string GetThunkCcFile(Context file); -std::string GetHeaderFile(Context file); +std::string GetRsFile(Context& ctx, const FileDescriptor& file); +std::string GetThunkCcFile(Context& ctx, const FileDescriptor& file); +std::string GetHeaderFile(Context& ctx, const FileDescriptor& file); -std::string Thunk(Context field, absl::string_view op); -std::string Thunk(Context field, absl::string_view op); +std::string Thunk(Context& ctx, const FieldDescriptor& field, + absl::string_view op); +std::string Thunk(Context& ctx, const OneofDescriptor& field, + absl::string_view op); -std::string Thunk(Context msg, absl::string_view op); +std::string Thunk(Context& ctx, const Descriptor& msg, absl::string_view op); -std::string PrimitiveRsTypeName(const FieldDescriptor& desc); +std::string PrimitiveRsTypeName(const FieldDescriptor& field); -std::string FieldInfoComment(Context field); +std::string FieldInfoComment(Context& ctx, const FieldDescriptor& field); -std::string RustModule(Context msg); -std::string RustInternalModuleName(Context file); +std::string RustModule(Context& ctx, const Descriptor& msg); +std::string RustInternalModuleName(Context& ctx, const FileDescriptor& file); -std::string GetCrateRelativeQualifiedPath(Context msg); +std::string GetCrateRelativeQualifiedPath(Context& ctx, const Descriptor& msg); } // namespace rust } // namespace compiler diff --git a/src/google/protobuf/compiler/rust/oneof.cc b/src/google/protobuf/compiler/rust/oneof.cc index d6166ae6d6f73..ce6e3af3c523a 100644 --- a/src/google/protobuf/compiler/rust/oneof.cc +++ b/src/google/protobuf/compiler/rust/oneof.cc @@ -78,27 +78,25 @@ std::string ToCamelCase(absl::string_view name) { return cpp::UnderscoresToCamelCase(name, /* upper initial letter */ true); } -std::string oneofViewEnumRsName(const OneofDescriptor& desc) { - return ToCamelCase(desc.name()); +std::string oneofViewEnumRsName(const OneofDescriptor& oneof) { + return ToCamelCase(oneof.name()); } -std::string oneofMutEnumRsName(const OneofDescriptor& desc) { - return ToCamelCase(desc.name()) + "Mut"; +std::string oneofMutEnumRsName(const OneofDescriptor& oneof) { + return ToCamelCase(oneof.name()) + "Mut"; } -std::string oneofCaseEnumName(const OneofDescriptor& desc) { +std::string oneofCaseEnumName(const OneofDescriptor& oneof) { // Note: This is the name used for the cpp Case enum, we use it for both // the Rust Case enum as well as for the cpp case enum in the cpp thunk. - return ToCamelCase(desc.name()) + "Case"; + return ToCamelCase(oneof.name()) + "Case"; } -std::string RsTypeNameView(Context field) { - const auto& desc = field.desc(); - - if (desc.options().has_ctype()) { +std::string RsTypeNameView(Context& ctx, const FieldDescriptor& field) { + if (field.options().has_ctype()) { return ""; // TODO: b/308792377 - ctype fields not supported yet. } - switch (desc.type()) { + switch (field.type()) { case FieldDescriptor::TYPE_INT32: case FieldDescriptor::TYPE_INT64: case FieldDescriptor::TYPE_FIXED32: @@ -112,7 +110,7 @@ std::string RsTypeNameView(Context field) { case FieldDescriptor::TYPE_FLOAT: case FieldDescriptor::TYPE_DOUBLE: case FieldDescriptor::TYPE_BOOL: - return PrimitiveRsTypeName(desc); + return PrimitiveRsTypeName(field); case FieldDescriptor::TYPE_BYTES: return "&'msg [u8]"; case FieldDescriptor::TYPE_STRING: @@ -120,23 +118,21 @@ std::string RsTypeNameView(Context field) { case FieldDescriptor::TYPE_MESSAGE: return absl::StrCat( "::__pb::View<'msg, crate::", - GetCrateRelativeQualifiedPath(field.WithDesc(desc.message_type())), - ">"); + GetCrateRelativeQualifiedPath(ctx, *field.message_type()), ">"); case FieldDescriptor::TYPE_ENUM: // TODO: b/300257770 - Support enums. case FieldDescriptor::TYPE_GROUP: // Not supported yet. return ""; } - ABSL_LOG(FATAL) << "Unexpected field type: " << desc.type_name(); + ABSL_LOG(FATAL) << "Unexpected field type: " << field.type_name(); return ""; } -std::string RsTypeNameMut(Context field) { - const auto& desc = field.desc(); - if (desc.options().has_ctype()) { +std::string RsTypeNameMut(Context& ctx, const FieldDescriptor& field) { + if (field.options().has_ctype()) { return ""; // TODO: b/308792377 - ctype fields not supported yet. } - switch (desc.type()) { + switch (field.type()) { case FieldDescriptor::TYPE_INT32: case FieldDescriptor::TYPE_INT64: case FieldDescriptor::TYPE_FIXED32: @@ -152,56 +148,54 @@ std::string RsTypeNameMut(Context field) { case FieldDescriptor::TYPE_BOOL: case FieldDescriptor::TYPE_BYTES: case FieldDescriptor::TYPE_STRING: - return absl::StrCat("::__pb::Mut<'msg, ", PrimitiveRsTypeName(desc), ">"); + return absl::StrCat("::__pb::Mut<'msg, ", PrimitiveRsTypeName(field), + ">"); case FieldDescriptor::TYPE_MESSAGE: return absl::StrCat( "::__pb::Mut<'msg, crate::", - GetCrateRelativeQualifiedPath(field.WithDesc(desc.message_type())), - ">"); + GetCrateRelativeQualifiedPath(ctx, *field.message_type()), ">"); case FieldDescriptor::TYPE_ENUM: // TODO: b/300257770 - Support enums. case FieldDescriptor::TYPE_GROUP: // Not supported yet. return ""; } - ABSL_LOG(FATAL) << "Unexpected field type: " << desc.type_name(); + ABSL_LOG(FATAL) << "Unexpected field type: " << field.type_name(); return ""; } } // namespace -void GenerateOneofDefinition(Context oneof) { - const auto& desc = oneof.desc(); - - oneof.Emit( - {{"view_enum_name", oneofViewEnumRsName(desc)}, - {"mut_enum_name", oneofMutEnumRsName(desc)}, +void GenerateOneofDefinition(Context& ctx, const OneofDescriptor& oneof) { + ctx.Emit( + {{"view_enum_name", oneofViewEnumRsName(oneof)}, + {"mut_enum_name", oneofMutEnumRsName(oneof)}, {"view_fields", [&] { - for (int i = 0; i < desc.field_count(); ++i) { - const auto& field = *desc.field(i); - std::string rs_type = RsTypeNameView(oneof.WithDesc(field)); + for (int i = 0; i < oneof.field_count(); ++i) { + auto& field = *oneof.field(i); + std::string rs_type = RsTypeNameView(ctx, field); if (rs_type.empty()) { continue; } - oneof.Emit({{"name", ToCamelCase(field.name())}, - {"type", rs_type}, - {"number", std::to_string(field.number())}}, - R"rs($name$($type$) = $number$, + ctx.Emit({{"name", ToCamelCase(field.name())}, + {"type", rs_type}, + {"number", std::to_string(field.number())}}, + R"rs($name$($type$) = $number$, )rs"); } }}, {"mut_fields", [&] { - for (int i = 0; i < desc.field_count(); ++i) { - const auto& field = *desc.field(i); - std::string rs_type = RsTypeNameMut(oneof.WithDesc(field)); + for (int i = 0; i < oneof.field_count(); ++i) { + auto& field = *oneof.field(i); + std::string rs_type = RsTypeNameMut(ctx, field); if (rs_type.empty()) { continue; } - oneof.Emit({{"name", ToCamelCase(field.name())}, - {"type", rs_type}, - {"number", std::to_string(field.number())}}, - R"rs($name$($type$) = $number$, + ctx.Emit({{"name", ToCamelCase(field.name())}, + {"type", rs_type}, + {"number", std::to_string(field.number())}}, + R"rs($name$($type$) = $number$, )rs"); } }}}, @@ -236,18 +230,18 @@ void GenerateOneofDefinition(Context oneof) { // Note: This enum is used as the Thunk return type for getting which case is // used: it exactly matches the generate case enum that both cpp and upb use. - oneof.Emit({{"case_enum_name", oneofCaseEnumName(desc)}, - {"cases", - [&] { - for (int i = 0; i < desc.field_count(); ++i) { - const auto& field = desc.field(i); - oneof.Emit({{"name", ToCamelCase(field->name())}, - {"number", std::to_string(field->number())}}, - R"rs($name$ = $number$, + ctx.Emit({{"case_enum_name", oneofCaseEnumName(oneof)}, + {"cases", + [&] { + for (int i = 0; i < oneof.field_count(); ++i) { + auto& field = *oneof.field(i); + ctx.Emit({{"name", ToCamelCase(field.name())}, + {"number", std::to_string(field.number())}}, + R"rs($name$ = $number$, )rs"); - } - }}}, - R"rs( + } + }}}, + R"rs( #[repr(C)] #[derive(Debug, Copy, Clone, PartialEq, Eq)] pub(super) enum $case_enum_name$ { @@ -260,23 +254,21 @@ void GenerateOneofDefinition(Context oneof) { )rs"); } -void GenerateOneofAccessors(Context oneof) { - const auto& desc = oneof.desc(); - - oneof.Emit( - {{"oneof_name", desc.name()}, - {"view_enum_name", oneofViewEnumRsName(desc)}, - {"mut_enum_name", oneofMutEnumRsName(desc)}, - {"case_enum_name", oneofCaseEnumName(desc)}, +void GenerateOneofAccessors(Context& ctx, const OneofDescriptor& oneof) { + ctx.Emit( + {{"oneof_name", oneof.name()}, + {"view_enum_name", oneofViewEnumRsName(oneof)}, + {"mut_enum_name", oneofMutEnumRsName(oneof)}, + {"case_enum_name", oneofCaseEnumName(oneof)}, {"view_cases", [&] { - for (int i = 0; i < desc.field_count(); ++i) { - const auto& field = *desc.field(i); - std::string rs_type = RsTypeNameView(oneof.WithDesc(field)); + for (int i = 0; i < oneof.field_count(); ++i) { + auto& field = *oneof.field(i); + std::string rs_type = RsTypeNameView(ctx, field); if (rs_type.empty()) { continue; } - oneof.Emit( + ctx.Emit( { {"case", ToCamelCase(field.name())}, {"rs_getter", field.name()}, @@ -288,13 +280,13 @@ void GenerateOneofAccessors(Context oneof) { }}, {"mut_cases", [&] { - for (int i = 0; i < desc.field_count(); ++i) { - const auto& field = *desc.field(i); - std::string rs_type = RsTypeNameMut(oneof.WithDesc(field)); + for (int i = 0; i < oneof.field_count(); ++i) { + auto& field = *oneof.field(i); + std::string rs_type = RsTypeNameMut(ctx, field); if (rs_type.empty()) { continue; } - oneof.Emit( + ctx.Emit( {{"case", ToCamelCase(field.name())}, {"rs_mut_getter", field.name() + "_mut"}, {"type", rs_type}, @@ -321,7 +313,7 @@ void GenerateOneofAccessors(Context oneof) { $Msg$_::$mut_enum_name$::$case$(self.$rs_mut_getter$()$into_mut_transform$), )rs"); } }}, - {"case_thunk", Thunk(oneof, "case")}}, + {"case_thunk", Thunk(ctx, oneof, "case")}}, R"rs( pub fn r#$oneof_name$(&self) -> $Msg$_::$view_enum_name$ { match unsafe { $case_thunk$(self.inner.msg) } { @@ -340,26 +332,24 @@ void GenerateOneofAccessors(Context oneof) { )rs"); } -void GenerateOneofExternC(Context oneof) { - const auto& desc = oneof.desc(); - oneof.Emit( +void GenerateOneofExternC(Context& ctx, const OneofDescriptor& oneof) { + ctx.Emit( { - {"case_enum_rs_name", oneofCaseEnumName(desc)}, - {"case_thunk", Thunk(oneof, "case")}, + {"case_enum_rs_name", oneofCaseEnumName(oneof)}, + {"case_thunk", Thunk(ctx, oneof, "case")}, }, R"rs( fn $case_thunk$(raw_msg: $pbi$::RawMessage) -> $Msg$_::$case_enum_rs_name$; )rs"); } -void GenerateOneofThunkCc(Context oneof) { - const auto& desc = oneof.desc(); - oneof.Emit( +void GenerateOneofThunkCc(Context& ctx, const OneofDescriptor& oneof) { + ctx.Emit( { - {"oneof_name", desc.name()}, - {"case_enum_name", oneofCaseEnumName(desc)}, - {"case_thunk", Thunk(oneof, "case")}, - {"QualifiedMsg", cpp::QualifiedClassName(desc.containing_type())}, + {"oneof_name", oneof.name()}, + {"case_enum_name", oneofCaseEnumName(oneof)}, + {"case_thunk", Thunk(ctx, oneof, "case")}, + {"QualifiedMsg", cpp::QualifiedClassName(oneof.containing_type())}, }, R"cc( $QualifiedMsg$::$case_enum_name$ $case_thunk$($QualifiedMsg$* msg) { diff --git a/src/google/protobuf/compiler/rust/oneof.h b/src/google/protobuf/compiler/rust/oneof.h index 98e2bc99f6fdc..7ad2143f83a72 100644 --- a/src/google/protobuf/compiler/rust/oneof.h +++ b/src/google/protobuf/compiler/rust/oneof.h @@ -16,10 +16,10 @@ namespace protobuf { namespace compiler { namespace rust { -void GenerateOneofDefinition(Context oneof); -void GenerateOneofAccessors(Context oneof); -void GenerateOneofExternC(Context oneof); -void GenerateOneofThunkCc(Context oneof); +void GenerateOneofDefinition(Context& ctx, const OneofDescriptor& oneof); +void GenerateOneofAccessors(Context& ctx, const OneofDescriptor& oneof); +void GenerateOneofExternC(Context& ctx, const OneofDescriptor& oneof); +void GenerateOneofThunkCc(Context& ctx, const OneofDescriptor& oneof); } // namespace rust } // namespace compiler From ba57a4e71500231c5834ea322f4ce1b8b530fac4 Mon Sep 17 00:00:00 2001 From: Thomas Van Lenten Date: Mon, 18 Dec 2023 15:42:12 -0800 Subject: [PATCH 043/255] Add optional fields also to the testing PiperOrigin-RevId: 592030444 --- src/google/protobuf/json/json_test.cc | 8 +++++++- src/google/protobuf/util/json_format_proto3.proto | 12 ++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/google/protobuf/json/json_test.cc b/src/google/protobuf/json/json_test.cc index 2ff1e87a90fe6..aac3ed7dd024f 100644 --- a/src/google/protobuf/json/json_test.cc +++ b/src/google/protobuf/json/json_test.cc @@ -204,6 +204,9 @@ TEST_P(JsonTest, TestDefaultValues) { m.set_string_value("i am a test string value"); m.set_bytes_value("i am a test bytes value"); + m.set_optional_bool_value(false); + m.set_optional_string_value(""); + m.set_optional_bytes_value(""); EXPECT_THAT( ToJson(m, options), IsOkAndHolds("{\"boolValue\":false," @@ -226,7 +229,10 @@ TEST_P(JsonTest, TestDefaultValues) { "\"repeatedStringValue\":[]," "\"repeatedBytesValue\":[]," "\"repeatedEnumValue\":[]," - "\"repeatedMessageValue\":[]" + "\"repeatedMessageValue\":[]," + "\"optionalBoolValue\":false," + "\"optionalStringValue\":\"\"," + "\"optionalBytesValue\":\"\"" "}")); EXPECT_THAT( diff --git a/src/google/protobuf/util/json_format_proto3.proto b/src/google/protobuf/util/json_format_proto3.proto index 8818adc6ea1b8..e631c2a1935dc 100644 --- a/src/google/protobuf/util/json_format_proto3.proto +++ b/src/google/protobuf/util/json_format_proto3.proto @@ -54,6 +54,18 @@ message TestMessage { repeated bytes repeated_bytes_value = 29; repeated EnumType repeated_enum_value = 30; repeated MessageType repeated_message_value = 31; + + optional bool optional_bool_value = 41; + optional int32 optional_int32_value = 42; + optional int64 optional_int64_value = 43; + optional uint32 optional_uint32_value = 44; + optional uint64 optional_uint64_value = 45; + optional float optional_float_value = 46; + optional double optional_double_value = 47; + optional string optional_string_value = 48; + optional bytes optional_bytes_value = 49; + optional EnumType optional_enum_value = 50; + optional MessageType optional_message_value = 51; } message TestOneof { From a4a98bdcc05d939f54ff2573dabc77da28d21b73 Mon Sep 17 00:00:00 2001 From: Eric Salo Date: Mon, 18 Dec 2023 16:01:38 -0800 Subject: [PATCH 044/255] upb: tag upb_Array.size as UPB_ONLYBITS() PiperOrigin-RevId: 592035282 --- upb/message/array.c | 29 +- upb/message/copy.c | 2 +- upb/message/internal/array.h | 11 +- upb/message/promote.c | 2 +- .../stage0/google/protobuf/descriptor.upb.h | 560 ++++++++++-------- upb/wire/decode.c | 44 +- upb/wire/decode_fast.c | 6 +- upb/wire/encode.c | 12 +- upb_generator/protoc-gen-upb.cc | 20 +- .../google/protobuf/compiler/plugin.upb.h | 56 +- 10 files changed, 421 insertions(+), 321 deletions(-) diff --git a/upb/message/array.c b/upb/message/array.c index ba3f7430103a6..d7858d3b22a06 100644 --- a/upb/message/array.c +++ b/upb/message/array.c @@ -28,13 +28,13 @@ const void* upb_Array_DataPtr(const upb_Array* arr) { void* upb_Array_MutableDataPtr(upb_Array* arr) { return _upb_array_ptr(arr); } -size_t upb_Array_Size(const upb_Array* arr) { return arr->size; } +size_t upb_Array_Size(const upb_Array* arr) { return arr->UPB_PRIVATE(size); } upb_MessageValue upb_Array_Get(const upb_Array* arr, size_t i) { upb_MessageValue ret; const char* data = _upb_array_constptr(arr); const int lg2 = UPB_PRIVATE(_upb_Array_ElemSizeLg2)(arr); - UPB_ASSERT(i < arr->size); + UPB_ASSERT(i < arr->UPB_PRIVATE(size)); memcpy(&ret, data + (i << lg2), 1 << lg2); return ret; } @@ -42,16 +42,16 @@ upb_MessageValue upb_Array_Get(const upb_Array* arr, size_t i) { void upb_Array_Set(upb_Array* arr, size_t i, upb_MessageValue val) { char* data = _upb_array_ptr(arr); const int lg2 = UPB_PRIVATE(_upb_Array_ElemSizeLg2)(arr); - UPB_ASSERT(i < arr->size); + UPB_ASSERT(i < arr->UPB_PRIVATE(size)); memcpy(data + (i << lg2), &val, 1 << lg2); } bool upb_Array_Append(upb_Array* arr, upb_MessageValue val, upb_Arena* arena) { UPB_ASSERT(arena); - if (!_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { + if (!_upb_Array_ResizeUninitialized(arr, arr->UPB_PRIVATE(size) + 1, arena)) { return false; } - upb_Array_Set(arr, arr->size - 1, val); + upb_Array_Set(arr, arr->UPB_PRIVATE(size) - 1, val); return true; } @@ -65,10 +65,11 @@ void upb_Array_Move(upb_Array* arr, size_t dst_idx, size_t src_idx, bool upb_Array_Insert(upb_Array* arr, size_t i, size_t count, upb_Arena* arena) { UPB_ASSERT(arena); - UPB_ASSERT(i <= arr->size); - UPB_ASSERT(count + arr->size >= count); - const size_t oldsize = arr->size; - if (!_upb_Array_ResizeUninitialized(arr, arr->size + count, arena)) { + UPB_ASSERT(i <= arr->UPB_PRIVATE(size)); + UPB_ASSERT(count + arr->UPB_PRIVATE(size) >= count); + const size_t oldsize = arr->UPB_PRIVATE(size); + if (!_upb_Array_ResizeUninitialized(arr, arr->UPB_PRIVATE(size) + count, + arena)) { return false; } upb_Array_Move(arr, i + count, i, oldsize - i); @@ -82,17 +83,17 @@ bool upb_Array_Insert(upb_Array* arr, size_t i, size_t count, void upb_Array_Delete(upb_Array* arr, size_t i, size_t count) { const size_t end = i + count; UPB_ASSERT(i <= end); - UPB_ASSERT(end <= arr->size); - upb_Array_Move(arr, i, end, arr->size - end); - arr->size -= count; + UPB_ASSERT(end <= arr->UPB_PRIVATE(size)); + upb_Array_Move(arr, i, end, arr->UPB_PRIVATE(size) - end); + arr->UPB_PRIVATE(size) -= count; } bool upb_Array_Resize(upb_Array* arr, size_t size, upb_Arena* arena) { - const size_t oldsize = arr->size; + const size_t oldsize = arr->UPB_PRIVATE(size); if (UPB_UNLIKELY(!_upb_Array_ResizeUninitialized(arr, size, arena))) { return false; } - const size_t newsize = arr->size; + const size_t newsize = arr->UPB_PRIVATE(size); if (newsize > oldsize) { const int lg2 = UPB_PRIVATE(_upb_Array_ElemSizeLg2)(arr); char* data = _upb_array_ptr(arr); diff --git a/upb/message/copy.c b/upb/message/copy.c index b5a634df6c888..7ad30ccc027dd 100644 --- a/upb/message/copy.c +++ b/upb/message/copy.c @@ -142,7 +142,7 @@ static upb_Map* upb_Message_Map_DeepClone(const upb_Map* map, upb_Array* upb_Array_DeepClone(const upb_Array* array, upb_CType value_type, const upb_MiniTable* sub, upb_Arena* arena) { - size_t size = array->size; + size_t size = array->UPB_PRIVATE(size); upb_Array* cloned_array = UPB_PRIVATE(_upb_Array_New)(arena, size, upb_CType_SizeLg2(value_type)); if (!cloned_array) { diff --git a/upb/message/internal/array.h b/upb/message/internal/array.h index 68aedf337773e..4d03e4b97854f 100644 --- a/upb/message/internal/array.h +++ b/upb/message/internal/array.h @@ -35,7 +35,7 @@ struct upb_Array { // Bit #2 contains the frozen/immutable flag (currently unimplemented). uintptr_t data; - size_t size; // The number of elements in the array. + size_t UPB_ONLYBITS(size); // The number of elements in the array. size_t UPB_PRIVATE(capacity); // Allocated storage. Measured in elements. }; @@ -73,7 +73,7 @@ UPB_INLINE upb_Array* UPB_PRIVATE(_upb_Array_New)(upb_Arena* arena, if (!array) return NULL; UPB_PRIVATE(_upb_Array_SetTaggedPtr) (array, UPB_PTR_AT(array, array_size, void), elem_size_lg2); - array->size = 0; + array->UPB_ONLYBITS(size) = 0; array->UPB_PRIVATE(capacity) = init_capacity; return array; } @@ -92,9 +92,10 @@ UPB_INLINE bool UPB_PRIVATE(_upb_Array_Reserve)(upb_Array* array, size_t size, // Resize without initializing new elements. UPB_INLINE bool _upb_Array_ResizeUninitialized(upb_Array* array, size_t size, upb_Arena* arena) { - UPB_ASSERT(size <= array->size || arena); // Allow NULL arena when shrinking. + UPB_ASSERT(size <= array->UPB_ONLYBITS(size) || + arena); // Allow NULL arena when shrinking. if (!UPB_PRIVATE(_upb_Array_Reserve)(array, size, arena)) return false; - array->size = size; + array->UPB_ONLYBITS(size) = size; return true; } @@ -104,7 +105,7 @@ UPB_INLINE bool _upb_Array_ResizeUninitialized(upb_Array* array, size_t size, UPB_INLINE void UPB_PRIVATE(_upb_Array_Set)(upb_Array* array, size_t i, const void* data, size_t elem_size) { - UPB_ASSERT(i < array->size); + UPB_ASSERT(i < array->UPB_ONLYBITS(size)); UPB_ASSERT(elem_size == 1U << UPB_PRIVATE(_upb_Array_ElemSizeLg2)(array)); char* arr_data = (char*)_upb_array_ptr(array); memcpy(arr_data + (i * elem_size), data, elem_size); diff --git a/upb/message/promote.c b/upb/message/promote.c index e33af5bec60eb..4fd9e676a32b7 100644 --- a/upb/message/promote.c +++ b/upb/message/promote.c @@ -196,7 +196,7 @@ upb_DecodeStatus upb_Array_PromoteMessages(upb_Array* arr, int decode_options, upb_Arena* arena) { void** data = _upb_array_ptr(arr); - size_t size = arr->size; + size_t size = arr->UPB_PRIVATE(size); for (size_t i = 0; i < size; i++) { upb_TaggedMessagePtr tagged; memcpy(&tagged, &data[i], sizeof(tagged)); diff --git a/upb/reflection/stage0/google/protobuf/descriptor.upb.h b/upb/reflection/stage0/google/protobuf/descriptor.upb.h index 76ac5db89a456..2ac29d6610a11 100644 --- a/upb/reflection/stage0/google/protobuf/descriptor.upb.h +++ b/upb/reflection/stage0/google/protobuf/descriptor.upb.h @@ -276,7 +276,7 @@ UPB_INLINE const google_protobuf_FileDescriptorProto* const* google_protobuf_Fil const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorSet_msg_init(), 1); const upb_Array* arr = upb_Message_GetArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_FileDescriptorProto* const*)_upb_array_constptr(arr); } else { if (size) *size = 0; @@ -287,7 +287,7 @@ UPB_INLINE const upb_Array* _google_protobuf_FileDescriptorSet_file_upb_array(co const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorSet_msg_init(), 1); const upb_Array* arr = upb_Message_GetArray(msg, &field); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -296,7 +296,7 @@ UPB_INLINE upb_Array* _google_protobuf_FileDescriptorSet_file_mutable_upb_array( upb_Array* arr = upb_Message_GetOrCreateMutableArray( (upb_Message*)msg, &field, arena); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -305,7 +305,7 @@ UPB_INLINE google_protobuf_FileDescriptorProto** google_protobuf_FileDescriptorS upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorSet_msg_init(), 1); upb_Array* arr = upb_Message_GetMutableArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_FileDescriptorProto**)_upb_array_ptr(arr); } else { if (size) *size = 0; @@ -319,12 +319,14 @@ UPB_INLINE google_protobuf_FileDescriptorProto** google_protobuf_FileDescriptorS UPB_INLINE struct google_protobuf_FileDescriptorProto* google_protobuf_FileDescriptorSet_add_file(google_protobuf_FileDescriptorSet* msg, upb_Arena* arena) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorSet_msg_init(), 1); upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); - if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { + if (!arr || !_upb_Array_ResizeUninitialized( + arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; } struct google_protobuf_FileDescriptorProto* sub = (struct google_protobuf_FileDescriptorProto*)_upb_Message_New(google__protobuf__FileDescriptorProto_msg_init(), arena); if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &sub, sizeof(sub)); + UPB_PRIVATE(_upb_Array_Set) + (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); return sub; } @@ -401,7 +403,7 @@ UPB_INLINE upb_StringView const* google_protobuf_FileDescriptorProto_dependency( const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 3); const upb_Array* arr = upb_Message_GetArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (upb_StringView const*)_upb_array_constptr(arr); } else { if (size) *size = 0; @@ -412,7 +414,7 @@ UPB_INLINE const upb_Array* _google_protobuf_FileDescriptorProto_dependency_upb_ const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 3); const upb_Array* arr = upb_Message_GetArray(msg, &field); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -421,7 +423,7 @@ UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_dependency_mutable_up upb_Array* arr = upb_Message_GetOrCreateMutableArray( (upb_Message*)msg, &field, arena); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -433,7 +435,7 @@ UPB_INLINE const google_protobuf_DescriptorProto* const* google_protobuf_FileDes const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 4); const upb_Array* arr = upb_Message_GetArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_DescriptorProto* const*)_upb_array_constptr(arr); } else { if (size) *size = 0; @@ -444,7 +446,7 @@ UPB_INLINE const upb_Array* _google_protobuf_FileDescriptorProto_message_type_up const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 4); const upb_Array* arr = upb_Message_GetArray(msg, &field); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -453,7 +455,7 @@ UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_message_type_mutable_ upb_Array* arr = upb_Message_GetOrCreateMutableArray( (upb_Message*)msg, &field, arena); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -465,7 +467,7 @@ UPB_INLINE const google_protobuf_EnumDescriptorProto* const* google_protobuf_Fil const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 5); const upb_Array* arr = upb_Message_GetArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_EnumDescriptorProto* const*)_upb_array_constptr(arr); } else { if (size) *size = 0; @@ -476,7 +478,7 @@ UPB_INLINE const upb_Array* _google_protobuf_FileDescriptorProto_enum_type_upb_a const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 5); const upb_Array* arr = upb_Message_GetArray(msg, &field); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -485,7 +487,7 @@ UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_enum_type_mutable_upb upb_Array* arr = upb_Message_GetOrCreateMutableArray( (upb_Message*)msg, &field, arena); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -497,7 +499,7 @@ UPB_INLINE const google_protobuf_ServiceDescriptorProto* const* google_protobuf_ const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 6); const upb_Array* arr = upb_Message_GetArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_ServiceDescriptorProto* const*)_upb_array_constptr(arr); } else { if (size) *size = 0; @@ -508,7 +510,7 @@ UPB_INLINE const upb_Array* _google_protobuf_FileDescriptorProto_service_upb_arr const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 6); const upb_Array* arr = upb_Message_GetArray(msg, &field); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -517,7 +519,7 @@ UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_service_mutable_upb_a upb_Array* arr = upb_Message_GetOrCreateMutableArray( (upb_Message*)msg, &field, arena); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -529,7 +531,7 @@ UPB_INLINE const google_protobuf_FieldDescriptorProto* const* google_protobuf_Fi const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 7); const upb_Array* arr = upb_Message_GetArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_FieldDescriptorProto* const*)_upb_array_constptr(arr); } else { if (size) *size = 0; @@ -540,7 +542,7 @@ UPB_INLINE const upb_Array* _google_protobuf_FileDescriptorProto_extension_upb_a const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 7); const upb_Array* arr = upb_Message_GetArray(msg, &field); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -549,7 +551,7 @@ UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_extension_mutable_upb upb_Array* arr = upb_Message_GetOrCreateMutableArray( (upb_Message*)msg, &field, arena); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -591,7 +593,7 @@ UPB_INLINE int32_t const* google_protobuf_FileDescriptorProto_public_dependency( const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 10); const upb_Array* arr = upb_Message_GetArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (int32_t const*)_upb_array_constptr(arr); } else { if (size) *size = 0; @@ -602,7 +604,7 @@ UPB_INLINE const upb_Array* _google_protobuf_FileDescriptorProto_public_dependen const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 10); const upb_Array* arr = upb_Message_GetArray(msg, &field); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -611,7 +613,7 @@ UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_public_dependency_mut upb_Array* arr = upb_Message_GetOrCreateMutableArray( (upb_Message*)msg, &field, arena); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -623,7 +625,7 @@ UPB_INLINE int32_t const* google_protobuf_FileDescriptorProto_weak_dependency(co const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 11); const upb_Array* arr = upb_Message_GetArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (int32_t const*)_upb_array_constptr(arr); } else { if (size) *size = 0; @@ -634,7 +636,7 @@ UPB_INLINE const upb_Array* _google_protobuf_FileDescriptorProto_weak_dependency const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 11); const upb_Array* arr = upb_Message_GetArray(msg, &field); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -643,7 +645,7 @@ UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_weak_dependency_mutab upb_Array* arr = upb_Message_GetOrCreateMutableArray( (upb_Message*)msg, &field, arena); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -690,7 +692,7 @@ UPB_INLINE upb_StringView* google_protobuf_FileDescriptorProto_mutable_dependenc upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 3); upb_Array* arr = upb_Message_GetMutableArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (upb_StringView*)_upb_array_ptr(arr); } else { if (size) *size = 0; @@ -704,17 +706,19 @@ UPB_INLINE upb_StringView* google_protobuf_FileDescriptorProto_resize_dependency UPB_INLINE bool google_protobuf_FileDescriptorProto_add_dependency(google_protobuf_FileDescriptorProto* msg, upb_StringView val, upb_Arena* arena) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 3); upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); - if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { + if (!arr || !_upb_Array_ResizeUninitialized( + arr, arr->UPB_PRIVATE(size) + 1, arena)) { return false; } - UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &val, sizeof(val)); + UPB_PRIVATE(_upb_Array_Set) + (arr, arr->UPB_PRIVATE(size) - 1, &val, sizeof(val)); return true; } UPB_INLINE google_protobuf_DescriptorProto** google_protobuf_FileDescriptorProto_mutable_message_type(google_protobuf_FileDescriptorProto* msg, size_t* size) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 4); upb_Array* arr = upb_Message_GetMutableArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_DescriptorProto**)_upb_array_ptr(arr); } else { if (size) *size = 0; @@ -728,19 +732,21 @@ UPB_INLINE google_protobuf_DescriptorProto** google_protobuf_FileDescriptorProto UPB_INLINE struct google_protobuf_DescriptorProto* google_protobuf_FileDescriptorProto_add_message_type(google_protobuf_FileDescriptorProto* msg, upb_Arena* arena) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 4); upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); - if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { + if (!arr || !_upb_Array_ResizeUninitialized( + arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; } struct google_protobuf_DescriptorProto* sub = (struct google_protobuf_DescriptorProto*)_upb_Message_New(google__protobuf__DescriptorProto_msg_init(), arena); if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &sub, sizeof(sub)); + UPB_PRIVATE(_upb_Array_Set) + (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); return sub; } UPB_INLINE google_protobuf_EnumDescriptorProto** google_protobuf_FileDescriptorProto_mutable_enum_type(google_protobuf_FileDescriptorProto* msg, size_t* size) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 5); upb_Array* arr = upb_Message_GetMutableArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_EnumDescriptorProto**)_upb_array_ptr(arr); } else { if (size) *size = 0; @@ -754,19 +760,21 @@ UPB_INLINE google_protobuf_EnumDescriptorProto** google_protobuf_FileDescriptorP UPB_INLINE struct google_protobuf_EnumDescriptorProto* google_protobuf_FileDescriptorProto_add_enum_type(google_protobuf_FileDescriptorProto* msg, upb_Arena* arena) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 5); upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); - if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { + if (!arr || !_upb_Array_ResizeUninitialized( + arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; } struct google_protobuf_EnumDescriptorProto* sub = (struct google_protobuf_EnumDescriptorProto*)_upb_Message_New(google__protobuf__EnumDescriptorProto_msg_init(), arena); if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &sub, sizeof(sub)); + UPB_PRIVATE(_upb_Array_Set) + (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); return sub; } UPB_INLINE google_protobuf_ServiceDescriptorProto** google_protobuf_FileDescriptorProto_mutable_service(google_protobuf_FileDescriptorProto* msg, size_t* size) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 6); upb_Array* arr = upb_Message_GetMutableArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_ServiceDescriptorProto**)_upb_array_ptr(arr); } else { if (size) *size = 0; @@ -780,19 +788,21 @@ UPB_INLINE google_protobuf_ServiceDescriptorProto** google_protobuf_FileDescript UPB_INLINE struct google_protobuf_ServiceDescriptorProto* google_protobuf_FileDescriptorProto_add_service(google_protobuf_FileDescriptorProto* msg, upb_Arena* arena) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 6); upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); - if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { + if (!arr || !_upb_Array_ResizeUninitialized( + arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; } struct google_protobuf_ServiceDescriptorProto* sub = (struct google_protobuf_ServiceDescriptorProto*)_upb_Message_New(google__protobuf__ServiceDescriptorProto_msg_init(), arena); if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &sub, sizeof(sub)); + UPB_PRIVATE(_upb_Array_Set) + (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); return sub; } UPB_INLINE google_protobuf_FieldDescriptorProto** google_protobuf_FileDescriptorProto_mutable_extension(google_protobuf_FileDescriptorProto* msg, size_t* size) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 7); upb_Array* arr = upb_Message_GetMutableArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_FieldDescriptorProto**)_upb_array_ptr(arr); } else { if (size) *size = 0; @@ -806,12 +816,14 @@ UPB_INLINE google_protobuf_FieldDescriptorProto** google_protobuf_FileDescriptor UPB_INLINE struct google_protobuf_FieldDescriptorProto* google_protobuf_FileDescriptorProto_add_extension(google_protobuf_FileDescriptorProto* msg, upb_Arena* arena) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 7); upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); - if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { + if (!arr || !_upb_Array_ResizeUninitialized( + arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; } struct google_protobuf_FieldDescriptorProto* sub = (struct google_protobuf_FieldDescriptorProto*)_upb_Message_New(google__protobuf__FieldDescriptorProto_msg_init(), arena); if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &sub, sizeof(sub)); + UPB_PRIVATE(_upb_Array_Set) + (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); return sub; } UPB_INLINE void google_protobuf_FileDescriptorProto_set_options(google_protobuf_FileDescriptorProto *msg, google_protobuf_FileOptions* value) { @@ -842,7 +854,7 @@ UPB_INLINE int32_t* google_protobuf_FileDescriptorProto_mutable_public_dependenc upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 10); upb_Array* arr = upb_Message_GetMutableArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (int32_t*)_upb_array_ptr(arr); } else { if (size) *size = 0; @@ -856,17 +868,19 @@ UPB_INLINE int32_t* google_protobuf_FileDescriptorProto_resize_public_dependency UPB_INLINE bool google_protobuf_FileDescriptorProto_add_public_dependency(google_protobuf_FileDescriptorProto* msg, int32_t val, upb_Arena* arena) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 10); upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); - if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { + if (!arr || !_upb_Array_ResizeUninitialized( + arr, arr->UPB_PRIVATE(size) + 1, arena)) { return false; } - UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &val, sizeof(val)); + UPB_PRIVATE(_upb_Array_Set) + (arr, arr->UPB_PRIVATE(size) - 1, &val, sizeof(val)); return true; } UPB_INLINE int32_t* google_protobuf_FileDescriptorProto_mutable_weak_dependency(google_protobuf_FileDescriptorProto* msg, size_t* size) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 11); upb_Array* arr = upb_Message_GetMutableArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (int32_t*)_upb_array_ptr(arr); } else { if (size) *size = 0; @@ -880,10 +894,12 @@ UPB_INLINE int32_t* google_protobuf_FileDescriptorProto_resize_weak_dependency(g UPB_INLINE bool google_protobuf_FileDescriptorProto_add_weak_dependency(google_protobuf_FileDescriptorProto* msg, int32_t val, upb_Arena* arena) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 11); upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); - if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { + if (!arr || !_upb_Array_ResizeUninitialized( + arr, arr->UPB_PRIVATE(size) + 1, arena)) { return false; } - UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &val, sizeof(val)); + UPB_PRIVATE(_upb_Array_Set) + (arr, arr->UPB_PRIVATE(size) - 1, &val, sizeof(val)); return true; } UPB_INLINE void google_protobuf_FileDescriptorProto_set_syntax(google_protobuf_FileDescriptorProto *msg, upb_StringView value) { @@ -953,7 +969,7 @@ UPB_INLINE const google_protobuf_FieldDescriptorProto* const* google_protobuf_De const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 2); const upb_Array* arr = upb_Message_GetArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_FieldDescriptorProto* const*)_upb_array_constptr(arr); } else { if (size) *size = 0; @@ -964,7 +980,7 @@ UPB_INLINE const upb_Array* _google_protobuf_DescriptorProto_field_upb_array(con const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 2); const upb_Array* arr = upb_Message_GetArray(msg, &field); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -973,7 +989,7 @@ UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_field_mutable_upb_array(c upb_Array* arr = upb_Message_GetOrCreateMutableArray( (upb_Message*)msg, &field, arena); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -985,7 +1001,7 @@ UPB_INLINE const google_protobuf_DescriptorProto* const* google_protobuf_Descrip const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 3); const upb_Array* arr = upb_Message_GetArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_DescriptorProto* const*)_upb_array_constptr(arr); } else { if (size) *size = 0; @@ -996,7 +1012,7 @@ UPB_INLINE const upb_Array* _google_protobuf_DescriptorProto_nested_type_upb_arr const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 3); const upb_Array* arr = upb_Message_GetArray(msg, &field); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -1005,7 +1021,7 @@ UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_nested_type_mutable_upb_a upb_Array* arr = upb_Message_GetOrCreateMutableArray( (upb_Message*)msg, &field, arena); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -1017,7 +1033,7 @@ UPB_INLINE const google_protobuf_EnumDescriptorProto* const* google_protobuf_Des const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 4); const upb_Array* arr = upb_Message_GetArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_EnumDescriptorProto* const*)_upb_array_constptr(arr); } else { if (size) *size = 0; @@ -1028,7 +1044,7 @@ UPB_INLINE const upb_Array* _google_protobuf_DescriptorProto_enum_type_upb_array const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 4); const upb_Array* arr = upb_Message_GetArray(msg, &field); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -1037,7 +1053,7 @@ UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_enum_type_mutable_upb_arr upb_Array* arr = upb_Message_GetOrCreateMutableArray( (upb_Message*)msg, &field, arena); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -1049,7 +1065,7 @@ UPB_INLINE const google_protobuf_DescriptorProto_ExtensionRange* const* google_p const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 5); const upb_Array* arr = upb_Message_GetArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_DescriptorProto_ExtensionRange* const*)_upb_array_constptr(arr); } else { if (size) *size = 0; @@ -1060,7 +1076,7 @@ UPB_INLINE const upb_Array* _google_protobuf_DescriptorProto_extension_range_upb const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 5); const upb_Array* arr = upb_Message_GetArray(msg, &field); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -1069,7 +1085,7 @@ UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_extension_range_mutable_u upb_Array* arr = upb_Message_GetOrCreateMutableArray( (upb_Message*)msg, &field, arena); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -1081,7 +1097,7 @@ UPB_INLINE const google_protobuf_FieldDescriptorProto* const* google_protobuf_De const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 6); const upb_Array* arr = upb_Message_GetArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_FieldDescriptorProto* const*)_upb_array_constptr(arr); } else { if (size) *size = 0; @@ -1092,7 +1108,7 @@ UPB_INLINE const upb_Array* _google_protobuf_DescriptorProto_extension_upb_array const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 6); const upb_Array* arr = upb_Message_GetArray(msg, &field); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -1101,7 +1117,7 @@ UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_extension_mutable_upb_arr upb_Array* arr = upb_Message_GetOrCreateMutableArray( (upb_Message*)msg, &field, arena); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -1128,7 +1144,7 @@ UPB_INLINE const google_protobuf_OneofDescriptorProto* const* google_protobuf_De const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 8); const upb_Array* arr = upb_Message_GetArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_OneofDescriptorProto* const*)_upb_array_constptr(arr); } else { if (size) *size = 0; @@ -1139,7 +1155,7 @@ UPB_INLINE const upb_Array* _google_protobuf_DescriptorProto_oneof_decl_upb_arra const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 8); const upb_Array* arr = upb_Message_GetArray(msg, &field); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -1148,7 +1164,7 @@ UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_oneof_decl_mutable_upb_ar upb_Array* arr = upb_Message_GetOrCreateMutableArray( (upb_Message*)msg, &field, arena); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -1160,7 +1176,7 @@ UPB_INLINE const google_protobuf_DescriptorProto_ReservedRange* const* google_pr const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 9); const upb_Array* arr = upb_Message_GetArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_DescriptorProto_ReservedRange* const*)_upb_array_constptr(arr); } else { if (size) *size = 0; @@ -1171,7 +1187,7 @@ UPB_INLINE const upb_Array* _google_protobuf_DescriptorProto_reserved_range_upb_ const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 9); const upb_Array* arr = upb_Message_GetArray(msg, &field); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -1180,7 +1196,7 @@ UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_reserved_range_mutable_up upb_Array* arr = upb_Message_GetOrCreateMutableArray( (upb_Message*)msg, &field, arena); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -1192,7 +1208,7 @@ UPB_INLINE upb_StringView const* google_protobuf_DescriptorProto_reserved_name(c const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 10); const upb_Array* arr = upb_Message_GetArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (upb_StringView const*)_upb_array_constptr(arr); } else { if (size) *size = 0; @@ -1203,7 +1219,7 @@ UPB_INLINE const upb_Array* _google_protobuf_DescriptorProto_reserved_name_upb_a const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 10); const upb_Array* arr = upb_Message_GetArray(msg, &field); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -1212,7 +1228,7 @@ UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_reserved_name_mutable_upb upb_Array* arr = upb_Message_GetOrCreateMutableArray( (upb_Message*)msg, &field, arena); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -1225,7 +1241,7 @@ UPB_INLINE google_protobuf_FieldDescriptorProto** google_protobuf_DescriptorProt upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 2); upb_Array* arr = upb_Message_GetMutableArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_FieldDescriptorProto**)_upb_array_ptr(arr); } else { if (size) *size = 0; @@ -1239,19 +1255,21 @@ UPB_INLINE google_protobuf_FieldDescriptorProto** google_protobuf_DescriptorProt UPB_INLINE struct google_protobuf_FieldDescriptorProto* google_protobuf_DescriptorProto_add_field(google_protobuf_DescriptorProto* msg, upb_Arena* arena) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 2); upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); - if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { + if (!arr || !_upb_Array_ResizeUninitialized( + arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; } struct google_protobuf_FieldDescriptorProto* sub = (struct google_protobuf_FieldDescriptorProto*)_upb_Message_New(google__protobuf__FieldDescriptorProto_msg_init(), arena); if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &sub, sizeof(sub)); + UPB_PRIVATE(_upb_Array_Set) + (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); return sub; } UPB_INLINE google_protobuf_DescriptorProto** google_protobuf_DescriptorProto_mutable_nested_type(google_protobuf_DescriptorProto* msg, size_t* size) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 3); upb_Array* arr = upb_Message_GetMutableArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_DescriptorProto**)_upb_array_ptr(arr); } else { if (size) *size = 0; @@ -1265,19 +1283,21 @@ UPB_INLINE google_protobuf_DescriptorProto** google_protobuf_DescriptorProto_res UPB_INLINE struct google_protobuf_DescriptorProto* google_protobuf_DescriptorProto_add_nested_type(google_protobuf_DescriptorProto* msg, upb_Arena* arena) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 3); upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); - if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { + if (!arr || !_upb_Array_ResizeUninitialized( + arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; } struct google_protobuf_DescriptorProto* sub = (struct google_protobuf_DescriptorProto*)_upb_Message_New(google__protobuf__DescriptorProto_msg_init(), arena); if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &sub, sizeof(sub)); + UPB_PRIVATE(_upb_Array_Set) + (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); return sub; } UPB_INLINE google_protobuf_EnumDescriptorProto** google_protobuf_DescriptorProto_mutable_enum_type(google_protobuf_DescriptorProto* msg, size_t* size) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 4); upb_Array* arr = upb_Message_GetMutableArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_EnumDescriptorProto**)_upb_array_ptr(arr); } else { if (size) *size = 0; @@ -1291,19 +1311,21 @@ UPB_INLINE google_protobuf_EnumDescriptorProto** google_protobuf_DescriptorProto UPB_INLINE struct google_protobuf_EnumDescriptorProto* google_protobuf_DescriptorProto_add_enum_type(google_protobuf_DescriptorProto* msg, upb_Arena* arena) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 4); upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); - if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { + if (!arr || !_upb_Array_ResizeUninitialized( + arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; } struct google_protobuf_EnumDescriptorProto* sub = (struct google_protobuf_EnumDescriptorProto*)_upb_Message_New(google__protobuf__EnumDescriptorProto_msg_init(), arena); if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &sub, sizeof(sub)); + UPB_PRIVATE(_upb_Array_Set) + (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); return sub; } UPB_INLINE google_protobuf_DescriptorProto_ExtensionRange** google_protobuf_DescriptorProto_mutable_extension_range(google_protobuf_DescriptorProto* msg, size_t* size) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 5); upb_Array* arr = upb_Message_GetMutableArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_DescriptorProto_ExtensionRange**)_upb_array_ptr(arr); } else { if (size) *size = 0; @@ -1317,19 +1339,21 @@ UPB_INLINE google_protobuf_DescriptorProto_ExtensionRange** google_protobuf_Desc UPB_INLINE struct google_protobuf_DescriptorProto_ExtensionRange* google_protobuf_DescriptorProto_add_extension_range(google_protobuf_DescriptorProto* msg, upb_Arena* arena) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 5); upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); - if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { + if (!arr || !_upb_Array_ResizeUninitialized( + arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; } struct google_protobuf_DescriptorProto_ExtensionRange* sub = (struct google_protobuf_DescriptorProto_ExtensionRange*)_upb_Message_New(google__protobuf__DescriptorProto__ExtensionRange_msg_init(), arena); if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &sub, sizeof(sub)); + UPB_PRIVATE(_upb_Array_Set) + (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); return sub; } UPB_INLINE google_protobuf_FieldDescriptorProto** google_protobuf_DescriptorProto_mutable_extension(google_protobuf_DescriptorProto* msg, size_t* size) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 6); upb_Array* arr = upb_Message_GetMutableArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_FieldDescriptorProto**)_upb_array_ptr(arr); } else { if (size) *size = 0; @@ -1343,12 +1367,14 @@ UPB_INLINE google_protobuf_FieldDescriptorProto** google_protobuf_DescriptorProt UPB_INLINE struct google_protobuf_FieldDescriptorProto* google_protobuf_DescriptorProto_add_extension(google_protobuf_DescriptorProto* msg, upb_Arena* arena) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 6); upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); - if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { + if (!arr || !_upb_Array_ResizeUninitialized( + arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; } struct google_protobuf_FieldDescriptorProto* sub = (struct google_protobuf_FieldDescriptorProto*)_upb_Message_New(google__protobuf__FieldDescriptorProto_msg_init(), arena); if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &sub, sizeof(sub)); + UPB_PRIVATE(_upb_Array_Set) + (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); return sub; } UPB_INLINE void google_protobuf_DescriptorProto_set_options(google_protobuf_DescriptorProto *msg, google_protobuf_MessageOptions* value) { @@ -1367,7 +1393,7 @@ UPB_INLINE google_protobuf_OneofDescriptorProto** google_protobuf_DescriptorProt upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 8); upb_Array* arr = upb_Message_GetMutableArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_OneofDescriptorProto**)_upb_array_ptr(arr); } else { if (size) *size = 0; @@ -1381,19 +1407,21 @@ UPB_INLINE google_protobuf_OneofDescriptorProto** google_protobuf_DescriptorProt UPB_INLINE struct google_protobuf_OneofDescriptorProto* google_protobuf_DescriptorProto_add_oneof_decl(google_protobuf_DescriptorProto* msg, upb_Arena* arena) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 8); upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); - if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { + if (!arr || !_upb_Array_ResizeUninitialized( + arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; } struct google_protobuf_OneofDescriptorProto* sub = (struct google_protobuf_OneofDescriptorProto*)_upb_Message_New(google__protobuf__OneofDescriptorProto_msg_init(), arena); if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &sub, sizeof(sub)); + UPB_PRIVATE(_upb_Array_Set) + (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); return sub; } UPB_INLINE google_protobuf_DescriptorProto_ReservedRange** google_protobuf_DescriptorProto_mutable_reserved_range(google_protobuf_DescriptorProto* msg, size_t* size) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 9); upb_Array* arr = upb_Message_GetMutableArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_DescriptorProto_ReservedRange**)_upb_array_ptr(arr); } else { if (size) *size = 0; @@ -1407,19 +1435,21 @@ UPB_INLINE google_protobuf_DescriptorProto_ReservedRange** google_protobuf_Descr UPB_INLINE struct google_protobuf_DescriptorProto_ReservedRange* google_protobuf_DescriptorProto_add_reserved_range(google_protobuf_DescriptorProto* msg, upb_Arena* arena) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 9); upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); - if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { + if (!arr || !_upb_Array_ResizeUninitialized( + arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; } struct google_protobuf_DescriptorProto_ReservedRange* sub = (struct google_protobuf_DescriptorProto_ReservedRange*)_upb_Message_New(google__protobuf__DescriptorProto__ReservedRange_msg_init(), arena); if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &sub, sizeof(sub)); + UPB_PRIVATE(_upb_Array_Set) + (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); return sub; } UPB_INLINE upb_StringView* google_protobuf_DescriptorProto_mutable_reserved_name(google_protobuf_DescriptorProto* msg, size_t* size) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 10); upb_Array* arr = upb_Message_GetMutableArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (upb_StringView*)_upb_array_ptr(arr); } else { if (size) *size = 0; @@ -1433,10 +1463,12 @@ UPB_INLINE upb_StringView* google_protobuf_DescriptorProto_resize_reserved_name( UPB_INLINE bool google_protobuf_DescriptorProto_add_reserved_name(google_protobuf_DescriptorProto* msg, upb_StringView val, upb_Arena* arena) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 10); upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); - if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { + if (!arr || !_upb_Array_ResizeUninitialized( + arr, arr->UPB_PRIVATE(size) + 1, arena)) { return false; } - UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &val, sizeof(val)); + UPB_PRIVATE(_upb_Array_Set) + (arr, arr->UPB_PRIVATE(size) - 1, &val, sizeof(val)); return true; } @@ -1660,7 +1692,7 @@ UPB_INLINE const google_protobuf_ExtensionRangeOptions_Declaration* const* googl const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ExtensionRangeOptions_msg_init(), 2); const upb_Array* arr = upb_Message_GetArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_ExtensionRangeOptions_Declaration* const*)_upb_array_constptr(arr); } else { if (size) *size = 0; @@ -1671,7 +1703,7 @@ UPB_INLINE const upb_Array* _google_protobuf_ExtensionRangeOptions_declaration_u const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ExtensionRangeOptions_msg_init(), 2); const upb_Array* arr = upb_Message_GetArray(msg, &field); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -1680,7 +1712,7 @@ UPB_INLINE upb_Array* _google_protobuf_ExtensionRangeOptions_declaration_mutable upb_Array* arr = upb_Message_GetOrCreateMutableArray( (upb_Message*)msg, &field, arena); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -1722,7 +1754,7 @@ UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_Ext const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ExtensionRangeOptions_msg_init(), 999); const upb_Array* arr = upb_Message_GetArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_UninterpretedOption* const*)_upb_array_constptr(arr); } else { if (size) *size = 0; @@ -1733,7 +1765,7 @@ UPB_INLINE const upb_Array* _google_protobuf_ExtensionRangeOptions_uninterpreted const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ExtensionRangeOptions_msg_init(), 999); const upb_Array* arr = upb_Message_GetArray(msg, &field); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -1742,7 +1774,7 @@ UPB_INLINE upb_Array* _google_protobuf_ExtensionRangeOptions_uninterpreted_optio upb_Array* arr = upb_Message_GetOrCreateMutableArray( (upb_Message*)msg, &field, arena); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -1751,7 +1783,7 @@ UPB_INLINE google_protobuf_ExtensionRangeOptions_Declaration** google_protobuf_E upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ExtensionRangeOptions_msg_init(), 2); upb_Array* arr = upb_Message_GetMutableArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_ExtensionRangeOptions_Declaration**)_upb_array_ptr(arr); } else { if (size) *size = 0; @@ -1765,12 +1797,14 @@ UPB_INLINE google_protobuf_ExtensionRangeOptions_Declaration** google_protobuf_E UPB_INLINE struct google_protobuf_ExtensionRangeOptions_Declaration* google_protobuf_ExtensionRangeOptions_add_declaration(google_protobuf_ExtensionRangeOptions* msg, upb_Arena* arena) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ExtensionRangeOptions_msg_init(), 2); upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); - if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { + if (!arr || !_upb_Array_ResizeUninitialized( + arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; } struct google_protobuf_ExtensionRangeOptions_Declaration* sub = (struct google_protobuf_ExtensionRangeOptions_Declaration*)_upb_Message_New(google__protobuf__ExtensionRangeOptions__Declaration_msg_init(), arena); if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &sub, sizeof(sub)); + UPB_PRIVATE(_upb_Array_Set) + (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); return sub; } UPB_INLINE void google_protobuf_ExtensionRangeOptions_set_verification(google_protobuf_ExtensionRangeOptions *msg, int32_t value) { @@ -1793,7 +1827,7 @@ UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_ExtensionRangeO upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ExtensionRangeOptions_msg_init(), 999); upb_Array* arr = upb_Message_GetMutableArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_UninterpretedOption**)_upb_array_ptr(arr); } else { if (size) *size = 0; @@ -1807,12 +1841,14 @@ UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_ExtensionRangeO UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_ExtensionRangeOptions_add_uninterpreted_option(google_protobuf_ExtensionRangeOptions* msg, upb_Arena* arena) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ExtensionRangeOptions_msg_init(), 999); upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); - if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { + if (!arr || !_upb_Array_ResizeUninitialized( + arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; } struct google_protobuf_UninterpretedOption* sub = (struct google_protobuf_UninterpretedOption*)_upb_Message_New(google__protobuf__UninterpretedOption_msg_init(), arena); if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &sub, sizeof(sub)); + UPB_PRIVATE(_upb_Array_Set) + (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); return sub; } @@ -2343,7 +2379,7 @@ UPB_INLINE const google_protobuf_EnumValueDescriptorProto* const* google_protobu const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumDescriptorProto_msg_init(), 2); const upb_Array* arr = upb_Message_GetArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_EnumValueDescriptorProto* const*)_upb_array_constptr(arr); } else { if (size) *size = 0; @@ -2354,7 +2390,7 @@ UPB_INLINE const upb_Array* _google_protobuf_EnumDescriptorProto_value_upb_array const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumDescriptorProto_msg_init(), 2); const upb_Array* arr = upb_Message_GetArray(msg, &field); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -2363,7 +2399,7 @@ UPB_INLINE upb_Array* _google_protobuf_EnumDescriptorProto_value_mutable_upb_arr upb_Array* arr = upb_Message_GetOrCreateMutableArray( (upb_Message*)msg, &field, arena); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -2390,7 +2426,7 @@ UPB_INLINE const google_protobuf_EnumDescriptorProto_EnumReservedRange* const* g const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumDescriptorProto_msg_init(), 4); const upb_Array* arr = upb_Message_GetArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_EnumDescriptorProto_EnumReservedRange* const*)_upb_array_constptr(arr); } else { if (size) *size = 0; @@ -2401,7 +2437,7 @@ UPB_INLINE const upb_Array* _google_protobuf_EnumDescriptorProto_reserved_range_ const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumDescriptorProto_msg_init(), 4); const upb_Array* arr = upb_Message_GetArray(msg, &field); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -2410,7 +2446,7 @@ UPB_INLINE upb_Array* _google_protobuf_EnumDescriptorProto_reserved_range_mutabl upb_Array* arr = upb_Message_GetOrCreateMutableArray( (upb_Message*)msg, &field, arena); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -2422,7 +2458,7 @@ UPB_INLINE upb_StringView const* google_protobuf_EnumDescriptorProto_reserved_na const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumDescriptorProto_msg_init(), 5); const upb_Array* arr = upb_Message_GetArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (upb_StringView const*)_upb_array_constptr(arr); } else { if (size) *size = 0; @@ -2433,7 +2469,7 @@ UPB_INLINE const upb_Array* _google_protobuf_EnumDescriptorProto_reserved_name_u const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumDescriptorProto_msg_init(), 5); const upb_Array* arr = upb_Message_GetArray(msg, &field); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -2442,7 +2478,7 @@ UPB_INLINE upb_Array* _google_protobuf_EnumDescriptorProto_reserved_name_mutable upb_Array* arr = upb_Message_GetOrCreateMutableArray( (upb_Message*)msg, &field, arena); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -2455,7 +2491,7 @@ UPB_INLINE google_protobuf_EnumValueDescriptorProto** google_protobuf_EnumDescri upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumDescriptorProto_msg_init(), 2); upb_Array* arr = upb_Message_GetMutableArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_EnumValueDescriptorProto**)_upb_array_ptr(arr); } else { if (size) *size = 0; @@ -2469,12 +2505,14 @@ UPB_INLINE google_protobuf_EnumValueDescriptorProto** google_protobuf_EnumDescri UPB_INLINE struct google_protobuf_EnumValueDescriptorProto* google_protobuf_EnumDescriptorProto_add_value(google_protobuf_EnumDescriptorProto* msg, upb_Arena* arena) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumDescriptorProto_msg_init(), 2); upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); - if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { + if (!arr || !_upb_Array_ResizeUninitialized( + arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; } struct google_protobuf_EnumValueDescriptorProto* sub = (struct google_protobuf_EnumValueDescriptorProto*)_upb_Message_New(google__protobuf__EnumValueDescriptorProto_msg_init(), arena); if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &sub, sizeof(sub)); + UPB_PRIVATE(_upb_Array_Set) + (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); return sub; } UPB_INLINE void google_protobuf_EnumDescriptorProto_set_options(google_protobuf_EnumDescriptorProto *msg, google_protobuf_EnumOptions* value) { @@ -2493,7 +2531,7 @@ UPB_INLINE google_protobuf_EnumDescriptorProto_EnumReservedRange** google_protob upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumDescriptorProto_msg_init(), 4); upb_Array* arr = upb_Message_GetMutableArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_EnumDescriptorProto_EnumReservedRange**)_upb_array_ptr(arr); } else { if (size) *size = 0; @@ -2507,19 +2545,21 @@ UPB_INLINE google_protobuf_EnumDescriptorProto_EnumReservedRange** google_protob UPB_INLINE struct google_protobuf_EnumDescriptorProto_EnumReservedRange* google_protobuf_EnumDescriptorProto_add_reserved_range(google_protobuf_EnumDescriptorProto* msg, upb_Arena* arena) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumDescriptorProto_msg_init(), 4); upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); - if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { + if (!arr || !_upb_Array_ResizeUninitialized( + arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; } struct google_protobuf_EnumDescriptorProto_EnumReservedRange* sub = (struct google_protobuf_EnumDescriptorProto_EnumReservedRange*)_upb_Message_New(google__protobuf__EnumDescriptorProto__EnumReservedRange_msg_init(), arena); if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &sub, sizeof(sub)); + UPB_PRIVATE(_upb_Array_Set) + (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); return sub; } UPB_INLINE upb_StringView* google_protobuf_EnumDescriptorProto_mutable_reserved_name(google_protobuf_EnumDescriptorProto* msg, size_t* size) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumDescriptorProto_msg_init(), 5); upb_Array* arr = upb_Message_GetMutableArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (upb_StringView*)_upb_array_ptr(arr); } else { if (size) *size = 0; @@ -2533,10 +2573,12 @@ UPB_INLINE upb_StringView* google_protobuf_EnumDescriptorProto_resize_reserved_n UPB_INLINE bool google_protobuf_EnumDescriptorProto_add_reserved_name(google_protobuf_EnumDescriptorProto* msg, upb_StringView val, upb_Arena* arena) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumDescriptorProto_msg_init(), 5); upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); - if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { + if (!arr || !_upb_Array_ResizeUninitialized( + arr, arr->UPB_PRIVATE(size) + 1, arena)) { return false; } - UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &val, sizeof(val)); + UPB_PRIVATE(_upb_Array_Set) + (arr, arr->UPB_PRIVATE(size) - 1, &val, sizeof(val)); return true; } @@ -2775,7 +2817,7 @@ UPB_INLINE const google_protobuf_MethodDescriptorProto* const* google_protobuf_S const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ServiceDescriptorProto_msg_init(), 2); const upb_Array* arr = upb_Message_GetArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_MethodDescriptorProto* const*)_upb_array_constptr(arr); } else { if (size) *size = 0; @@ -2786,7 +2828,7 @@ UPB_INLINE const upb_Array* _google_protobuf_ServiceDescriptorProto_method_upb_a const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ServiceDescriptorProto_msg_init(), 2); const upb_Array* arr = upb_Message_GetArray(msg, &field); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -2795,7 +2837,7 @@ UPB_INLINE upb_Array* _google_protobuf_ServiceDescriptorProto_method_mutable_upb upb_Array* arr = upb_Message_GetOrCreateMutableArray( (upb_Message*)msg, &field, arena); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -2823,7 +2865,7 @@ UPB_INLINE google_protobuf_MethodDescriptorProto** google_protobuf_ServiceDescri upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ServiceDescriptorProto_msg_init(), 2); upb_Array* arr = upb_Message_GetMutableArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_MethodDescriptorProto**)_upb_array_ptr(arr); } else { if (size) *size = 0; @@ -2837,12 +2879,14 @@ UPB_INLINE google_protobuf_MethodDescriptorProto** google_protobuf_ServiceDescri UPB_INLINE struct google_protobuf_MethodDescriptorProto* google_protobuf_ServiceDescriptorProto_add_method(google_protobuf_ServiceDescriptorProto* msg, upb_Arena* arena) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ServiceDescriptorProto_msg_init(), 2); upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); - if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { + if (!arr || !_upb_Array_ResizeUninitialized( + arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; } struct google_protobuf_MethodDescriptorProto* sub = (struct google_protobuf_MethodDescriptorProto*)_upb_Message_New(google__protobuf__MethodDescriptorProto_msg_init(), arena); if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &sub, sizeof(sub)); + UPB_PRIVATE(_upb_Array_Set) + (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); return sub; } UPB_INLINE void google_protobuf_ServiceDescriptorProto_set_options(google_protobuf_ServiceDescriptorProto *msg, google_protobuf_ServiceOptions* value) { @@ -3375,7 +3419,7 @@ UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_Fil const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 999); const upb_Array* arr = upb_Message_GetArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_UninterpretedOption* const*)_upb_array_constptr(arr); } else { if (size) *size = 0; @@ -3386,7 +3430,7 @@ UPB_INLINE const upb_Array* _google_protobuf_FileOptions_uninterpreted_option_up const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 999); const upb_Array* arr = upb_Message_GetArray(msg, &field); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -3395,7 +3439,7 @@ UPB_INLINE upb_Array* _google_protobuf_FileOptions_uninterpreted_option_mutable_ upb_Array* arr = upb_Message_GetOrCreateMutableArray( (upb_Message*)msg, &field, arena); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -3496,7 +3540,7 @@ UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_FileOptions_mut upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 999); upb_Array* arr = upb_Message_GetMutableArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_UninterpretedOption**)_upb_array_ptr(arr); } else { if (size) *size = 0; @@ -3510,12 +3554,14 @@ UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_FileOptions_res UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_FileOptions_add_uninterpreted_option(google_protobuf_FileOptions* msg, upb_Arena* arena) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 999); upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); - if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { + if (!arr || !_upb_Array_ResizeUninitialized( + arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; } struct google_protobuf_UninterpretedOption* sub = (struct google_protobuf_UninterpretedOption*)_upb_Message_New(google__protobuf__UninterpretedOption_msg_init(), arena); if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &sub, sizeof(sub)); + UPB_PRIVATE(_upb_Array_Set) + (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); return sub; } @@ -3652,7 +3698,7 @@ UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_Mes const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MessageOptions_msg_init(), 999); const upb_Array* arr = upb_Message_GetArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_UninterpretedOption* const*)_upb_array_constptr(arr); } else { if (size) *size = 0; @@ -3663,7 +3709,7 @@ UPB_INLINE const upb_Array* _google_protobuf_MessageOptions_uninterpreted_option const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MessageOptions_msg_init(), 999); const upb_Array* arr = upb_Message_GetArray(msg, &field); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -3672,7 +3718,7 @@ UPB_INLINE upb_Array* _google_protobuf_MessageOptions_uninterpreted_option_mutab upb_Array* arr = upb_Message_GetOrCreateMutableArray( (upb_Message*)msg, &field, arena); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -3713,7 +3759,7 @@ UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_MessageOptions_ upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MessageOptions_msg_init(), 999); upb_Array* arr = upb_Message_GetMutableArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_UninterpretedOption**)_upb_array_ptr(arr); } else { if (size) *size = 0; @@ -3727,12 +3773,14 @@ UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_MessageOptions_ UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_MessageOptions_add_uninterpreted_option(google_protobuf_MessageOptions* msg, upb_Arena* arena) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MessageOptions_msg_init(), 999); upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); - if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { + if (!arr || !_upb_Array_ResizeUninitialized( + arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; } struct google_protobuf_UninterpretedOption* sub = (struct google_protobuf_UninterpretedOption*)_upb_Message_New(google__protobuf__UninterpretedOption_msg_init(), arena); if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &sub, sizeof(sub)); + UPB_PRIVATE(_upb_Array_Set) + (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); return sub; } @@ -3914,7 +3962,7 @@ UPB_INLINE int32_t const* google_protobuf_FieldOptions_targets(const google_prot const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 19); const upb_Array* arr = upb_Message_GetArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (int32_t const*)_upb_array_constptr(arr); } else { if (size) *size = 0; @@ -3925,7 +3973,7 @@ UPB_INLINE const upb_Array* _google_protobuf_FieldOptions_targets_upb_array(cons const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 19); const upb_Array* arr = upb_Message_GetArray(msg, &field); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -3934,7 +3982,7 @@ UPB_INLINE upb_Array* _google_protobuf_FieldOptions_targets_mutable_upb_array(co upb_Array* arr = upb_Message_GetOrCreateMutableArray( (upb_Message*)msg, &field, arena); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -3946,7 +3994,7 @@ UPB_INLINE const google_protobuf_FieldOptions_EditionDefault* const* google_prot const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 20); const upb_Array* arr = upb_Message_GetArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_FieldOptions_EditionDefault* const*)_upb_array_constptr(arr); } else { if (size) *size = 0; @@ -3957,7 +4005,7 @@ UPB_INLINE const upb_Array* _google_protobuf_FieldOptions_edition_defaults_upb_a const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 20); const upb_Array* arr = upb_Message_GetArray(msg, &field); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -3966,7 +4014,7 @@ UPB_INLINE upb_Array* _google_protobuf_FieldOptions_edition_defaults_mutable_upb upb_Array* arr = upb_Message_GetOrCreateMutableArray( (upb_Message*)msg, &field, arena); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -3993,7 +4041,7 @@ UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_Fie const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 999); const upb_Array* arr = upb_Message_GetArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_UninterpretedOption* const*)_upb_array_constptr(arr); } else { if (size) *size = 0; @@ -4004,7 +4052,7 @@ UPB_INLINE const upb_Array* _google_protobuf_FieldOptions_uninterpreted_option_u const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 999); const upb_Array* arr = upb_Message_GetArray(msg, &field); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -4013,7 +4061,7 @@ UPB_INLINE upb_Array* _google_protobuf_FieldOptions_uninterpreted_option_mutable upb_Array* arr = upb_Message_GetOrCreateMutableArray( (upb_Message*)msg, &field, arena); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -4058,7 +4106,7 @@ UPB_INLINE int32_t* google_protobuf_FieldOptions_mutable_targets(google_protobuf upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 19); upb_Array* arr = upb_Message_GetMutableArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (int32_t*)_upb_array_ptr(arr); } else { if (size) *size = 0; @@ -4072,17 +4120,19 @@ UPB_INLINE int32_t* google_protobuf_FieldOptions_resize_targets(google_protobuf_ UPB_INLINE bool google_protobuf_FieldOptions_add_targets(google_protobuf_FieldOptions* msg, int32_t val, upb_Arena* arena) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 19); upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); - if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { + if (!arr || !_upb_Array_ResizeUninitialized( + arr, arr->UPB_PRIVATE(size) + 1, arena)) { return false; } - UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &val, sizeof(val)); + UPB_PRIVATE(_upb_Array_Set) + (arr, arr->UPB_PRIVATE(size) - 1, &val, sizeof(val)); return true; } UPB_INLINE google_protobuf_FieldOptions_EditionDefault** google_protobuf_FieldOptions_mutable_edition_defaults(google_protobuf_FieldOptions* msg, size_t* size) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 20); upb_Array* arr = upb_Message_GetMutableArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_FieldOptions_EditionDefault**)_upb_array_ptr(arr); } else { if (size) *size = 0; @@ -4096,12 +4146,14 @@ UPB_INLINE google_protobuf_FieldOptions_EditionDefault** google_protobuf_FieldOp UPB_INLINE struct google_protobuf_FieldOptions_EditionDefault* google_protobuf_FieldOptions_add_edition_defaults(google_protobuf_FieldOptions* msg, upb_Arena* arena) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 20); upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); - if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { + if (!arr || !_upb_Array_ResizeUninitialized( + arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; } struct google_protobuf_FieldOptions_EditionDefault* sub = (struct google_protobuf_FieldOptions_EditionDefault*)_upb_Message_New(google__protobuf__FieldOptions__EditionDefault_msg_init(), arena); if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &sub, sizeof(sub)); + UPB_PRIVATE(_upb_Array_Set) + (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); return sub; } UPB_INLINE void google_protobuf_FieldOptions_set_features(google_protobuf_FieldOptions *msg, google_protobuf_FeatureSet* value) { @@ -4120,7 +4172,7 @@ UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_FieldOptions_mu upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 999); upb_Array* arr = upb_Message_GetMutableArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_UninterpretedOption**)_upb_array_ptr(arr); } else { if (size) *size = 0; @@ -4134,12 +4186,14 @@ UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_FieldOptions_re UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_FieldOptions_add_uninterpreted_option(google_protobuf_FieldOptions* msg, upb_Arena* arena) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 999); upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); - if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { + if (!arr || !_upb_Array_ResizeUninitialized( + arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; } struct google_protobuf_UninterpretedOption* sub = (struct google_protobuf_UninterpretedOption*)_upb_Message_New(google__protobuf__UninterpretedOption_msg_init(), arena); if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &sub, sizeof(sub)); + UPB_PRIVATE(_upb_Array_Set) + (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); return sub; } @@ -4276,7 +4330,7 @@ UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_One const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__OneofOptions_msg_init(), 999); const upb_Array* arr = upb_Message_GetArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_UninterpretedOption* const*)_upb_array_constptr(arr); } else { if (size) *size = 0; @@ -4287,7 +4341,7 @@ UPB_INLINE const upb_Array* _google_protobuf_OneofOptions_uninterpreted_option_u const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__OneofOptions_msg_init(), 999); const upb_Array* arr = upb_Message_GetArray(msg, &field); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -4296,7 +4350,7 @@ UPB_INLINE upb_Array* _google_protobuf_OneofOptions_uninterpreted_option_mutable upb_Array* arr = upb_Message_GetOrCreateMutableArray( (upb_Message*)msg, &field, arena); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -4317,7 +4371,7 @@ UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_OneofOptions_mu upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__OneofOptions_msg_init(), 999); upb_Array* arr = upb_Message_GetMutableArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_UninterpretedOption**)_upb_array_ptr(arr); } else { if (size) *size = 0; @@ -4331,12 +4385,14 @@ UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_OneofOptions_re UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_OneofOptions_add_uninterpreted_option(google_protobuf_OneofOptions* msg, upb_Arena* arena) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__OneofOptions_msg_init(), 999); upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); - if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { + if (!arr || !_upb_Array_ResizeUninitialized( + arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; } struct google_protobuf_UninterpretedOption* sub = (struct google_protobuf_UninterpretedOption*)_upb_Message_New(google__protobuf__UninterpretedOption_msg_init(), arena); if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &sub, sizeof(sub)); + UPB_PRIVATE(_upb_Array_Set) + (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); return sub; } @@ -4443,7 +4499,7 @@ UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_Enu const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumOptions_msg_init(), 999); const upb_Array* arr = upb_Message_GetArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_UninterpretedOption* const*)_upb_array_constptr(arr); } else { if (size) *size = 0; @@ -4454,7 +4510,7 @@ UPB_INLINE const upb_Array* _google_protobuf_EnumOptions_uninterpreted_option_up const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumOptions_msg_init(), 999); const upb_Array* arr = upb_Message_GetArray(msg, &field); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -4463,7 +4519,7 @@ UPB_INLINE upb_Array* _google_protobuf_EnumOptions_uninterpreted_option_mutable_ upb_Array* arr = upb_Message_GetOrCreateMutableArray( (upb_Message*)msg, &field, arena); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -4496,7 +4552,7 @@ UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_EnumOptions_mut upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumOptions_msg_init(), 999); upb_Array* arr = upb_Message_GetMutableArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_UninterpretedOption**)_upb_array_ptr(arr); } else { if (size) *size = 0; @@ -4510,12 +4566,14 @@ UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_EnumOptions_res UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_EnumOptions_add_uninterpreted_option(google_protobuf_EnumOptions* msg, upb_Arena* arena) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumOptions_msg_init(), 999); upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); - if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { + if (!arr || !_upb_Array_ResizeUninitialized( + arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; } struct google_protobuf_UninterpretedOption* sub = (struct google_protobuf_UninterpretedOption*)_upb_Message_New(google__protobuf__UninterpretedOption_msg_init(), arena); if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &sub, sizeof(sub)); + UPB_PRIVATE(_upb_Array_Set) + (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); return sub; } @@ -4607,7 +4665,7 @@ UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_Enu const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumValueOptions_msg_init(), 999); const upb_Array* arr = upb_Message_GetArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_UninterpretedOption* const*)_upb_array_constptr(arr); } else { if (size) *size = 0; @@ -4618,7 +4676,7 @@ UPB_INLINE const upb_Array* _google_protobuf_EnumValueOptions_uninterpreted_opti const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumValueOptions_msg_init(), 999); const upb_Array* arr = upb_Message_GetArray(msg, &field); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -4627,7 +4685,7 @@ UPB_INLINE upb_Array* _google_protobuf_EnumValueOptions_uninterpreted_option_mut upb_Array* arr = upb_Message_GetOrCreateMutableArray( (upb_Message*)msg, &field, arena); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -4656,7 +4714,7 @@ UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_EnumValueOption upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumValueOptions_msg_init(), 999); upb_Array* arr = upb_Message_GetMutableArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_UninterpretedOption**)_upb_array_ptr(arr); } else { if (size) *size = 0; @@ -4670,12 +4728,14 @@ UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_EnumValueOption UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_EnumValueOptions_add_uninterpreted_option(google_protobuf_EnumValueOptions* msg, upb_Arena* arena) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumValueOptions_msg_init(), 999); upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); - if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { + if (!arr || !_upb_Array_ResizeUninitialized( + arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; } struct google_protobuf_UninterpretedOption* sub = (struct google_protobuf_UninterpretedOption*)_upb_Message_New(google__protobuf__UninterpretedOption_msg_init(), arena); if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &sub, sizeof(sub)); + UPB_PRIVATE(_upb_Array_Set) + (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); return sub; } @@ -4752,7 +4812,7 @@ UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_Ser const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ServiceOptions_msg_init(), 999); const upb_Array* arr = upb_Message_GetArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_UninterpretedOption* const*)_upb_array_constptr(arr); } else { if (size) *size = 0; @@ -4763,7 +4823,7 @@ UPB_INLINE const upb_Array* _google_protobuf_ServiceOptions_uninterpreted_option const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ServiceOptions_msg_init(), 999); const upb_Array* arr = upb_Message_GetArray(msg, &field); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -4772,7 +4832,7 @@ UPB_INLINE upb_Array* _google_protobuf_ServiceOptions_uninterpreted_option_mutab upb_Array* arr = upb_Message_GetOrCreateMutableArray( (upb_Message*)msg, &field, arena); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -4797,7 +4857,7 @@ UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_ServiceOptions_ upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ServiceOptions_msg_init(), 999); upb_Array* arr = upb_Message_GetMutableArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_UninterpretedOption**)_upb_array_ptr(arr); } else { if (size) *size = 0; @@ -4811,12 +4871,14 @@ UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_ServiceOptions_ UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_ServiceOptions_add_uninterpreted_option(google_protobuf_ServiceOptions* msg, upb_Arena* arena) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ServiceOptions_msg_init(), 999); upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); - if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { + if (!arr || !_upb_Array_ResizeUninitialized( + arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; } struct google_protobuf_UninterpretedOption* sub = (struct google_protobuf_UninterpretedOption*)_upb_Message_New(google__protobuf__UninterpretedOption_msg_init(), arena); if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &sub, sizeof(sub)); + UPB_PRIVATE(_upb_Array_Set) + (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); return sub; } @@ -4908,7 +4970,7 @@ UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_Met const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MethodOptions_msg_init(), 999); const upb_Array* arr = upb_Message_GetArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_UninterpretedOption* const*)_upb_array_constptr(arr); } else { if (size) *size = 0; @@ -4919,7 +4981,7 @@ UPB_INLINE const upb_Array* _google_protobuf_MethodOptions_uninterpreted_option_ const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MethodOptions_msg_init(), 999); const upb_Array* arr = upb_Message_GetArray(msg, &field); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -4928,7 +4990,7 @@ UPB_INLINE upb_Array* _google_protobuf_MethodOptions_uninterpreted_option_mutabl upb_Array* arr = upb_Message_GetOrCreateMutableArray( (upb_Message*)msg, &field, arena); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -4957,7 +5019,7 @@ UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_MethodOptions_m upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MethodOptions_msg_init(), 999); upb_Array* arr = upb_Message_GetMutableArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_UninterpretedOption**)_upb_array_ptr(arr); } else { if (size) *size = 0; @@ -4971,12 +5033,14 @@ UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_MethodOptions_r UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_MethodOptions_add_uninterpreted_option(google_protobuf_MethodOptions* msg, upb_Arena* arena) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MethodOptions_msg_init(), 999); upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); - if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { + if (!arr || !_upb_Array_ResizeUninitialized( + arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; } struct google_protobuf_UninterpretedOption* sub = (struct google_protobuf_UninterpretedOption*)_upb_Message_New(google__protobuf__UninterpretedOption_msg_init(), arena); if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &sub, sizeof(sub)); + UPB_PRIVATE(_upb_Array_Set) + (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); return sub; } @@ -5023,7 +5087,7 @@ UPB_INLINE const google_protobuf_UninterpretedOption_NamePart* const* google_pro const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__UninterpretedOption_msg_init(), 2); const upb_Array* arr = upb_Message_GetArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_UninterpretedOption_NamePart* const*)_upb_array_constptr(arr); } else { if (size) *size = 0; @@ -5034,7 +5098,7 @@ UPB_INLINE const upb_Array* _google_protobuf_UninterpretedOption_name_upb_array( const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__UninterpretedOption_msg_init(), 2); const upb_Array* arr = upb_Message_GetArray(msg, &field); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -5043,7 +5107,7 @@ UPB_INLINE upb_Array* _google_protobuf_UninterpretedOption_name_mutable_upb_arra upb_Array* arr = upb_Message_GetOrCreateMutableArray( (upb_Message*)msg, &field, arena); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -5142,7 +5206,7 @@ UPB_INLINE google_protobuf_UninterpretedOption_NamePart** google_protobuf_Uninte upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__UninterpretedOption_msg_init(), 2); upb_Array* arr = upb_Message_GetMutableArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_UninterpretedOption_NamePart**)_upb_array_ptr(arr); } else { if (size) *size = 0; @@ -5156,12 +5220,14 @@ UPB_INLINE google_protobuf_UninterpretedOption_NamePart** google_protobuf_Uninte UPB_INLINE struct google_protobuf_UninterpretedOption_NamePart* google_protobuf_UninterpretedOption_add_name(google_protobuf_UninterpretedOption* msg, upb_Arena* arena) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__UninterpretedOption_msg_init(), 2); upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); - if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { + if (!arr || !_upb_Array_ResizeUninitialized( + arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; } struct google_protobuf_UninterpretedOption_NamePart* sub = (struct google_protobuf_UninterpretedOption_NamePart*)_upb_Message_New(google__protobuf__UninterpretedOption__NamePart_msg_init(), arena); if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &sub, sizeof(sub)); + UPB_PRIVATE(_upb_Array_Set) + (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); return sub; } UPB_INLINE void google_protobuf_UninterpretedOption_set_identifier_value(google_protobuf_UninterpretedOption *msg, upb_StringView value) { @@ -5458,7 +5524,7 @@ UPB_INLINE const google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* co const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FeatureSetDefaults_msg_init(), 1); const upb_Array* arr = upb_Message_GetArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* const*)_upb_array_constptr(arr); } else { if (size) *size = 0; @@ -5469,7 +5535,7 @@ UPB_INLINE const upb_Array* _google_protobuf_FeatureSetDefaults_defaults_upb_arr const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FeatureSetDefaults_msg_init(), 1); const upb_Array* arr = upb_Message_GetArray(msg, &field); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -5478,7 +5544,7 @@ UPB_INLINE upb_Array* _google_protobuf_FeatureSetDefaults_defaults_mutable_upb_a upb_Array* arr = upb_Message_GetOrCreateMutableArray( (upb_Message*)msg, &field, arena); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -5517,7 +5583,7 @@ UPB_INLINE google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault** google_ upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FeatureSetDefaults_msg_init(), 1); upb_Array* arr = upb_Message_GetMutableArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault**)_upb_array_ptr(arr); } else { if (size) *size = 0; @@ -5531,12 +5597,14 @@ UPB_INLINE google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault** google_ UPB_INLINE struct google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* google_protobuf_FeatureSetDefaults_add_defaults(google_protobuf_FeatureSetDefaults* msg, upb_Arena* arena) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FeatureSetDefaults_msg_init(), 1); upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); - if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { + if (!arr || !_upb_Array_ResizeUninitialized( + arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; } struct google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* sub = (struct google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault*)_upb_Message_New(google__protobuf__FeatureSetDefaults__FeatureSetEditionDefault_msg_init(), arena); if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &sub, sizeof(sub)); + UPB_PRIVATE(_upb_Array_Set) + (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); return sub; } UPB_INLINE void google_protobuf_FeatureSetDefaults_set_minimum_edition(google_protobuf_FeatureSetDefaults *msg, int32_t value) { @@ -5674,7 +5742,7 @@ UPB_INLINE const google_protobuf_SourceCodeInfo_Location* const* google_protobuf const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__SourceCodeInfo_msg_init(), 1); const upb_Array* arr = upb_Message_GetArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_SourceCodeInfo_Location* const*)_upb_array_constptr(arr); } else { if (size) *size = 0; @@ -5685,7 +5753,7 @@ UPB_INLINE const upb_Array* _google_protobuf_SourceCodeInfo_location_upb_array(c const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__SourceCodeInfo_msg_init(), 1); const upb_Array* arr = upb_Message_GetArray(msg, &field); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -5694,7 +5762,7 @@ UPB_INLINE upb_Array* _google_protobuf_SourceCodeInfo_location_mutable_upb_array upb_Array* arr = upb_Message_GetOrCreateMutableArray( (upb_Message*)msg, &field, arena); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -5703,7 +5771,7 @@ UPB_INLINE google_protobuf_SourceCodeInfo_Location** google_protobuf_SourceCodeI upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__SourceCodeInfo_msg_init(), 1); upb_Array* arr = upb_Message_GetMutableArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_SourceCodeInfo_Location**)_upb_array_ptr(arr); } else { if (size) *size = 0; @@ -5717,12 +5785,14 @@ UPB_INLINE google_protobuf_SourceCodeInfo_Location** google_protobuf_SourceCodeI UPB_INLINE struct google_protobuf_SourceCodeInfo_Location* google_protobuf_SourceCodeInfo_add_location(google_protobuf_SourceCodeInfo* msg, upb_Arena* arena) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__SourceCodeInfo_msg_init(), 1); upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); - if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { + if (!arr || !_upb_Array_ResizeUninitialized( + arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; } struct google_protobuf_SourceCodeInfo_Location* sub = (struct google_protobuf_SourceCodeInfo_Location*)_upb_Message_New(google__protobuf__SourceCodeInfo__Location_msg_init(), arena); if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &sub, sizeof(sub)); + UPB_PRIVATE(_upb_Array_Set) + (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); return sub; } @@ -5769,7 +5839,7 @@ UPB_INLINE int32_t const* google_protobuf_SourceCodeInfo_Location_path(const goo const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__SourceCodeInfo__Location_msg_init(), 1); const upb_Array* arr = upb_Message_GetArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (int32_t const*)_upb_array_constptr(arr); } else { if (size) *size = 0; @@ -5780,7 +5850,7 @@ UPB_INLINE const upb_Array* _google_protobuf_SourceCodeInfo_Location_path_upb_ar const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__SourceCodeInfo__Location_msg_init(), 1); const upb_Array* arr = upb_Message_GetArray(msg, &field); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -5789,7 +5859,7 @@ UPB_INLINE upb_Array* _google_protobuf_SourceCodeInfo_Location_path_mutable_upb_ upb_Array* arr = upb_Message_GetOrCreateMutableArray( (upb_Message*)msg, &field, arena); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -5801,7 +5871,7 @@ UPB_INLINE int32_t const* google_protobuf_SourceCodeInfo_Location_span(const goo const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__SourceCodeInfo__Location_msg_init(), 2); const upb_Array* arr = upb_Message_GetArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (int32_t const*)_upb_array_constptr(arr); } else { if (size) *size = 0; @@ -5812,7 +5882,7 @@ UPB_INLINE const upb_Array* _google_protobuf_SourceCodeInfo_Location_span_upb_ar const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__SourceCodeInfo__Location_msg_init(), 2); const upb_Array* arr = upb_Message_GetArray(msg, &field); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -5821,7 +5891,7 @@ UPB_INLINE upb_Array* _google_protobuf_SourceCodeInfo_Location_span_mutable_upb_ upb_Array* arr = upb_Message_GetOrCreateMutableArray( (upb_Message*)msg, &field, arena); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -5863,7 +5933,7 @@ UPB_INLINE upb_StringView const* google_protobuf_SourceCodeInfo_Location_leading const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__SourceCodeInfo__Location_msg_init(), 6); const upb_Array* arr = upb_Message_GetArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (upb_StringView const*)_upb_array_constptr(arr); } else { if (size) *size = 0; @@ -5874,7 +5944,7 @@ UPB_INLINE const upb_Array* _google_protobuf_SourceCodeInfo_Location_leading_det const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__SourceCodeInfo__Location_msg_init(), 6); const upb_Array* arr = upb_Message_GetArray(msg, &field); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -5883,7 +5953,7 @@ UPB_INLINE upb_Array* _google_protobuf_SourceCodeInfo_Location_leading_detached_ upb_Array* arr = upb_Message_GetOrCreateMutableArray( (upb_Message*)msg, &field, arena); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -5892,7 +5962,7 @@ UPB_INLINE int32_t* google_protobuf_SourceCodeInfo_Location_mutable_path(google_ upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__SourceCodeInfo__Location_msg_init(), 1); upb_Array* arr = upb_Message_GetMutableArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (int32_t*)_upb_array_ptr(arr); } else { if (size) *size = 0; @@ -5906,17 +5976,19 @@ UPB_INLINE int32_t* google_protobuf_SourceCodeInfo_Location_resize_path(google_p UPB_INLINE bool google_protobuf_SourceCodeInfo_Location_add_path(google_protobuf_SourceCodeInfo_Location* msg, int32_t val, upb_Arena* arena) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__SourceCodeInfo__Location_msg_init(), 1); upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); - if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { + if (!arr || !_upb_Array_ResizeUninitialized( + arr, arr->UPB_PRIVATE(size) + 1, arena)) { return false; } - UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &val, sizeof(val)); + UPB_PRIVATE(_upb_Array_Set) + (arr, arr->UPB_PRIVATE(size) - 1, &val, sizeof(val)); return true; } UPB_INLINE int32_t* google_protobuf_SourceCodeInfo_Location_mutable_span(google_protobuf_SourceCodeInfo_Location* msg, size_t* size) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__SourceCodeInfo__Location_msg_init(), 2); upb_Array* arr = upb_Message_GetMutableArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (int32_t*)_upb_array_ptr(arr); } else { if (size) *size = 0; @@ -5930,10 +6002,12 @@ UPB_INLINE int32_t* google_protobuf_SourceCodeInfo_Location_resize_span(google_p UPB_INLINE bool google_protobuf_SourceCodeInfo_Location_add_span(google_protobuf_SourceCodeInfo_Location* msg, int32_t val, upb_Arena* arena) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__SourceCodeInfo__Location_msg_init(), 2); upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); - if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { + if (!arr || !_upb_Array_ResizeUninitialized( + arr, arr->UPB_PRIVATE(size) + 1, arena)) { return false; } - UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &val, sizeof(val)); + UPB_PRIVATE(_upb_Array_Set) + (arr, arr->UPB_PRIVATE(size) - 1, &val, sizeof(val)); return true; } UPB_INLINE void google_protobuf_SourceCodeInfo_Location_set_leading_comments(google_protobuf_SourceCodeInfo_Location *msg, upb_StringView value) { @@ -5948,7 +6022,7 @@ UPB_INLINE upb_StringView* google_protobuf_SourceCodeInfo_Location_mutable_leadi upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__SourceCodeInfo__Location_msg_init(), 6); upb_Array* arr = upb_Message_GetMutableArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (upb_StringView*)_upb_array_ptr(arr); } else { if (size) *size = 0; @@ -5962,10 +6036,12 @@ UPB_INLINE upb_StringView* google_protobuf_SourceCodeInfo_Location_resize_leadin UPB_INLINE bool google_protobuf_SourceCodeInfo_Location_add_leading_detached_comments(google_protobuf_SourceCodeInfo_Location* msg, upb_StringView val, upb_Arena* arena) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__SourceCodeInfo__Location_msg_init(), 6); upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); - if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { + if (!arr || !_upb_Array_ResizeUninitialized( + arr, arr->UPB_PRIVATE(size) + 1, arena)) { return false; } - UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &val, sizeof(val)); + UPB_PRIVATE(_upb_Array_Set) + (arr, arr->UPB_PRIVATE(size) - 1, &val, sizeof(val)); return true; } @@ -6012,7 +6088,7 @@ UPB_INLINE const google_protobuf_GeneratedCodeInfo_Annotation* const* google_pro const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__GeneratedCodeInfo_msg_init(), 1); const upb_Array* arr = upb_Message_GetArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_GeneratedCodeInfo_Annotation* const*)_upb_array_constptr(arr); } else { if (size) *size = 0; @@ -6023,7 +6099,7 @@ UPB_INLINE const upb_Array* _google_protobuf_GeneratedCodeInfo_annotation_upb_ar const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__GeneratedCodeInfo_msg_init(), 1); const upb_Array* arr = upb_Message_GetArray(msg, &field); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -6032,7 +6108,7 @@ UPB_INLINE upb_Array* _google_protobuf_GeneratedCodeInfo_annotation_mutable_upb_ upb_Array* arr = upb_Message_GetOrCreateMutableArray( (upb_Message*)msg, &field, arena); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -6041,7 +6117,7 @@ UPB_INLINE google_protobuf_GeneratedCodeInfo_Annotation** google_protobuf_Genera upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__GeneratedCodeInfo_msg_init(), 1); upb_Array* arr = upb_Message_GetMutableArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_GeneratedCodeInfo_Annotation**)_upb_array_ptr(arr); } else { if (size) *size = 0; @@ -6055,12 +6131,14 @@ UPB_INLINE google_protobuf_GeneratedCodeInfo_Annotation** google_protobuf_Genera UPB_INLINE struct google_protobuf_GeneratedCodeInfo_Annotation* google_protobuf_GeneratedCodeInfo_add_annotation(google_protobuf_GeneratedCodeInfo* msg, upb_Arena* arena) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__GeneratedCodeInfo_msg_init(), 1); upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); - if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { + if (!arr || !_upb_Array_ResizeUninitialized( + arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; } struct google_protobuf_GeneratedCodeInfo_Annotation* sub = (struct google_protobuf_GeneratedCodeInfo_Annotation*)_upb_Message_New(google__protobuf__GeneratedCodeInfo__Annotation_msg_init(), arena); if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &sub, sizeof(sub)); + UPB_PRIVATE(_upb_Array_Set) + (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); return sub; } @@ -6107,7 +6185,7 @@ UPB_INLINE int32_t const* google_protobuf_GeneratedCodeInfo_Annotation_path(cons const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__GeneratedCodeInfo__Annotation_msg_init(), 1); const upb_Array* arr = upb_Message_GetArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (int32_t const*)_upb_array_constptr(arr); } else { if (size) *size = 0; @@ -6118,7 +6196,7 @@ UPB_INLINE const upb_Array* _google_protobuf_GeneratedCodeInfo_Annotation_path_u const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__GeneratedCodeInfo__Annotation_msg_init(), 1); const upb_Array* arr = upb_Message_GetArray(msg, &field); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -6127,7 +6205,7 @@ UPB_INLINE upb_Array* _google_protobuf_GeneratedCodeInfo_Annotation_path_mutable upb_Array* arr = upb_Message_GetOrCreateMutableArray( (upb_Message*)msg, &field, arena); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -6196,7 +6274,7 @@ UPB_INLINE int32_t* google_protobuf_GeneratedCodeInfo_Annotation_mutable_path(go upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__GeneratedCodeInfo__Annotation_msg_init(), 1); upb_Array* arr = upb_Message_GetMutableArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (int32_t*)_upb_array_ptr(arr); } else { if (size) *size = 0; @@ -6210,10 +6288,12 @@ UPB_INLINE int32_t* google_protobuf_GeneratedCodeInfo_Annotation_resize_path(goo UPB_INLINE bool google_protobuf_GeneratedCodeInfo_Annotation_add_path(google_protobuf_GeneratedCodeInfo_Annotation* msg, int32_t val, upb_Arena* arena) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__GeneratedCodeInfo__Annotation_msg_init(), 1); upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); - if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { + if (!arr || !_upb_Array_ResizeUninitialized( + arr, arr->UPB_PRIVATE(size) + 1, arena)) { return false; } - UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &val, sizeof(val)); + UPB_PRIVATE(_upb_Array_Set) + (arr, arr->UPB_PRIVATE(size) - 1, &val, sizeof(val)); return true; } UPB_INLINE void google_protobuf_GeneratedCodeInfo_Annotation_set_source_file(google_protobuf_GeneratedCodeInfo_Annotation *msg, upb_StringView value) { diff --git a/upb/wire/decode.c b/upb/wire/decode.c index fdd780e1981c4..214fca07989dc 100644 --- a/upb/wire/decode.c +++ b/upb/wire/decode.c @@ -133,9 +133,10 @@ static void _upb_Decoder_VerifyUtf8(upb_Decoder* d, const char* buf, int len) { } static bool _upb_Decoder_Reserve(upb_Decoder* d, upb_Array* arr, size_t elem) { - bool need_realloc = arr->UPB_PRIVATE(capacity) - arr->size < elem; - if (need_realloc && - !UPB_PRIVATE(_upb_Array_Realloc)(arr, arr->size + elem, &d->arena)) { + bool need_realloc = + arr->UPB_PRIVATE(capacity) - arr->UPB_PRIVATE(size) < elem; + if (need_realloc && !UPB_PRIVATE(_upb_Array_Realloc)( + arr, arr->UPB_PRIVATE(size) + elem, &d->arena)) { _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_OutOfMemory); } return need_realloc; @@ -409,8 +410,8 @@ static const char* _upb_Decoder_DecodeEnumArray(upb_Decoder* d, const char* ptr, wireval* val) { const upb_MiniTableEnum* e = _upb_MiniTableSubs_EnumByField(subs, field); if (!_upb_Decoder_CheckEnum(d, ptr, msg, e, field, val)) return ptr; - void* mem = UPB_PTR_AT(_upb_array_ptr(arr), arr->size * 4, void); - arr->size++; + void* mem = UPB_PTR_AT(_upb_array_ptr(arr), arr->UPB_PRIVATE(size) * 4, void); + arr->UPB_PRIVATE(size)++; memcpy(mem, val, 4); return ptr; } @@ -426,8 +427,9 @@ static const char* _upb_Decoder_DecodeFixedPacked( _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_Malformed); } _upb_Decoder_Reserve(d, arr, count); - void* mem = UPB_PTR_AT(_upb_array_ptr(arr), arr->size << lg2, void); - arr->size += count; + void* mem = + UPB_PTR_AT(_upb_array_ptr(arr), arr->UPB_PRIVATE(size) << lg2, void); + arr->UPB_PRIVATE(size) += count; // Note: if/when the decoder supports multi-buffer input, we will need to // handle buffer seams here. if (_upb_IsLittleEndian()) { @@ -457,15 +459,17 @@ static const char* _upb_Decoder_DecodeVarintPacked( const upb_MiniTableField* field, int lg2) { int scale = 1 << lg2; int saved_limit = upb_EpsCopyInputStream_PushLimit(&d->input, ptr, val->size); - char* out = UPB_PTR_AT(_upb_array_ptr(arr), arr->size << lg2, void); + char* out = + UPB_PTR_AT(_upb_array_ptr(arr), arr->UPB_PRIVATE(size) << lg2, void); while (!_upb_Decoder_IsDone(d, &ptr)) { wireval elem; ptr = _upb_Decoder_DecodeVarint(d, ptr, &elem.uint64_val); _upb_Decoder_Munge(field->UPB_PRIVATE(descriptortype), &elem); if (_upb_Decoder_Reserve(d, arr, 1)) { - out = UPB_PTR_AT(_upb_array_ptr(arr), arr->size << lg2, void); + out = + UPB_PTR_AT(_upb_array_ptr(arr), arr->UPB_PRIVATE(size) << lg2, void); } - arr->size++; + arr->UPB_PRIVATE(size)++; memcpy(out, &elem, scale); out += scale; } @@ -480,7 +484,7 @@ static const char* _upb_Decoder_DecodeEnumPacked( wireval* val) { const upb_MiniTableEnum* e = _upb_MiniTableSubs_EnumByField(subs, field); int saved_limit = upb_EpsCopyInputStream_PushLimit(&d->input, ptr, val->size); - char* out = UPB_PTR_AT(_upb_array_ptr(arr), arr->size * 4, void); + char* out = UPB_PTR_AT(_upb_array_ptr(arr), arr->UPB_PRIVATE(size) * 4, void); while (!_upb_Decoder_IsDone(d, &ptr)) { wireval elem; ptr = _upb_Decoder_DecodeVarint(d, ptr, &elem.uint64_val); @@ -489,9 +493,9 @@ static const char* _upb_Decoder_DecodeEnumPacked( continue; } if (_upb_Decoder_Reserve(d, arr, 1)) { - out = UPB_PTR_AT(_upb_array_ptr(arr), arr->size * 4, void); + out = UPB_PTR_AT(_upb_array_ptr(arr), arr->UPB_PRIVATE(size) * 4, void); } - arr->size++; + arr->UPB_PRIVATE(size)++; memcpy(out, &elem, 4); out += 4; } @@ -529,8 +533,8 @@ static const char* _upb_Decoder_DecodeToArray(upb_Decoder* d, const char* ptr, case kUpb_DecodeOp_Scalar4Byte: case kUpb_DecodeOp_Scalar8Byte: /* Append scalar value. */ - mem = UPB_PTR_AT(_upb_array_ptr(arr), arr->size << op, void); - arr->size++; + mem = UPB_PTR_AT(_upb_array_ptr(arr), arr->UPB_PRIVATE(size) << op, void); + arr->UPB_PRIVATE(size)++; memcpy(mem, val, 1 << op); return ptr; case kUpb_DecodeOp_String: @@ -538,16 +542,18 @@ static const char* _upb_Decoder_DecodeToArray(upb_Decoder* d, const char* ptr, /* Fallthrough. */ case kUpb_DecodeOp_Bytes: { /* Append bytes. */ - upb_StringView* str = (upb_StringView*)_upb_array_ptr(arr) + arr->size; - arr->size++; + upb_StringView* str = + (upb_StringView*)_upb_array_ptr(arr) + arr->UPB_PRIVATE(size); + arr->UPB_PRIVATE(size)++; return _upb_Decoder_ReadString(d, ptr, val->size, str); } case kUpb_DecodeOp_SubMessage: { /* Append submessage / group. */ upb_TaggedMessagePtr* target = UPB_PTR_AT( - _upb_array_ptr(arr), arr->size * sizeof(void*), upb_TaggedMessagePtr); + _upb_array_ptr(arr), arr->UPB_PRIVATE(size) * sizeof(void*), + upb_TaggedMessagePtr); upb_Message* submsg = _upb_Decoder_NewSubMessage(d, subs, field, target); - arr->size++; + arr->UPB_PRIVATE(size)++; if (UPB_UNLIKELY(field->UPB_PRIVATE(descriptortype) == kUpb_FieldType_Group)) { return _upb_Decoder_DecodeKnownGroup(d, ptr, submsg, subs, field); diff --git a/upb/wire/decode_fast.c b/upb/wire/decode_fast.c index 4aebbf1c8d6a7..889bb6432dcd3 100644 --- a/upb/wire/decode_fast.c +++ b/upb/wire/decode_fast.c @@ -193,7 +193,7 @@ static bool fastdecode_tagmatch(uint32_t tag, uint64_t data, int tagbytes) { UPB_FORCEINLINE static void fastdecode_commitarr(void* dst, fastdecode_arr* farr, int valbytes) { - farr->arr->size = + farr->arr->UPB_PRIVATE(size) = (size_t)((char*)dst - (char*)_upb_array_ptr(farr->arr)) / valbytes; } @@ -264,7 +264,7 @@ static void* fastdecode_getfield(upb_Decoder* d, const char* ptr, begin = _upb_array_ptr(farr->arr); farr->end = begin + (farr->arr->UPB_PRIVATE(capacity) * valbytes); *data = _upb_FastDecoder_LoadTag(ptr); - return begin + (farr->arr->size * valbytes); + return begin + (farr->arr->UPB_PRIVATE(size) * valbytes); } default: UPB_UNREACHABLE(); @@ -552,7 +552,7 @@ TAGBYTES(p) \ char* dst = _upb_array_ptr(arr); \ memcpy(dst, ptr, size); \ - arr->size = elems; \ + arr->UPB_PRIVATE(size) = elems; \ \ ptr += size; \ UPB_MUSTTAIL return fastdecode_dispatch(UPB_PARSE_ARGS); diff --git a/upb/wire/encode.c b/upb/wire/encode.c index 672f612012315..bcc0b6edaeb6f 100644 --- a/upb/wire/encode.c +++ b/upb/wire/encode.c @@ -181,7 +181,7 @@ static void encode_tag(upb_encstate* e, uint32_t field_number, static void encode_fixedarray(upb_encstate* e, const upb_Array* arr, size_t elem_size, uint32_t tag) { - size_t bytes = arr->size * elem_size; + size_t bytes = arr->UPB_PRIVATE(size) * elem_size; const char* data = _upb_array_constptr(arr); const char* ptr = data + bytes - elem_size; @@ -313,14 +313,14 @@ static void encode_array(upb_encstate* e, const upb_Message* msg, bool packed = upb_MiniTableField_IsPacked(f); size_t pre_len = e->limit - e->ptr; - if (arr == NULL || arr->size == 0) { + if (arr == NULL || arr->UPB_PRIVATE(size) == 0) { return; } #define VARINT_CASE(ctype, encode) \ { \ const ctype* start = _upb_array_constptr(arr); \ - const ctype* ptr = start + arr->size; \ + const ctype* ptr = start + arr->UPB_PRIVATE(size); \ uint32_t tag = \ packed ? 0 : (f->UPB_PRIVATE(number) << 3) | kUpb_WireType_Varint; \ do { \ @@ -365,7 +365,7 @@ static void encode_array(upb_encstate* e, const upb_Message* msg, case kUpb_FieldType_String: case kUpb_FieldType_Bytes: { const upb_StringView* start = _upb_array_constptr(arr); - const upb_StringView* ptr = start + arr->size; + const upb_StringView* ptr = start + arr->UPB_PRIVATE(size); do { ptr--; encode_bytes(e, ptr->data, ptr->size); @@ -376,7 +376,7 @@ static void encode_array(upb_encstate* e, const upb_Message* msg, } case kUpb_FieldType_Group: { const upb_TaggedMessagePtr* start = _upb_array_constptr(arr); - const upb_TaggedMessagePtr* ptr = start + arr->size; + const upb_TaggedMessagePtr* ptr = start + arr->UPB_PRIVATE(size); const upb_MiniTable* subm = upb_MiniTableSub_Message(subs[f->UPB_PRIVATE(submsg_index)]); if (--e->depth == 0) encode_err(e, kUpb_EncodeStatus_MaxDepthExceeded); @@ -392,7 +392,7 @@ static void encode_array(upb_encstate* e, const upb_Message* msg, } case kUpb_FieldType_Message: { const upb_TaggedMessagePtr* start = _upb_array_constptr(arr); - const upb_TaggedMessagePtr* ptr = start + arr->size; + const upb_TaggedMessagePtr* ptr = start + arr->UPB_PRIVATE(size); const upb_MiniTable* subm = upb_MiniTableSub_Message(subs[f->UPB_PRIVATE(submsg_index)]); if (--e->depth == 0) encode_err(e, kUpb_EncodeStatus_MaxDepthExceeded); diff --git a/upb_generator/protoc-gen-upb.cc b/upb_generator/protoc-gen-upb.cc index 2d84796561885..8a7e213f54042 100644 --- a/upb_generator/protoc-gen-upb.cc +++ b/upb_generator/protoc-gen-upb.cc @@ -503,7 +503,7 @@ void GenerateRepeatedGetters(upb::FieldDefPtr field, const DefPoolPair& pools, const upb_MiniTableField field = $3; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return ($0 const*)_upb_array_constptr(arr); } else { if (size) *size = 0; @@ -528,7 +528,7 @@ void GenerateRepeatedGetters(upb::FieldDefPtr field, const DefPoolPair& pools, const upb_MiniTableField field = $3; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -537,7 +537,7 @@ void GenerateRepeatedGetters(upb::FieldDefPtr field, const DefPoolPair& pools, upb_Array* arr = upb_Message_GetOrCreateMutableArray( (upb_Message*)msg, &field, arena); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -649,7 +649,7 @@ void GenerateRepeatedSetters(upb::FieldDefPtr field, const DefPoolPair& pools, upb_MiniTableField field = $3; upb_Array* arr = upb_Message_GetMutableArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return ($0*)_upb_array_ptr(arr); } else { if (size) *size = 0; @@ -674,12 +674,14 @@ void GenerateRepeatedSetters(upb::FieldDefPtr field, const DefPoolPair& pools, UPB_INLINE struct $0* $1_add_$2($1* msg, upb_Arena* arena) { upb_MiniTableField field = $4; upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); - if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { + if (!arr || !_upb_Array_ResizeUninitialized( + arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; } struct $0* sub = (struct $0*)_upb_Message_New($3, arena); if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &sub, sizeof(sub)); + UPB_PRIVATE(_upb_Array_Set) + (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); return sub; } )cc", @@ -692,10 +694,12 @@ void GenerateRepeatedSetters(upb::FieldDefPtr field, const DefPoolPair& pools, UPB_INLINE bool $1_add_$2($1* msg, $0 val, upb_Arena* arena) { upb_MiniTableField field = $3; upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); - if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { + if (!arr || !_upb_Array_ResizeUninitialized( + arr, arr->UPB_PRIVATE(size) + 1, arena)) { return false; } - UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &val, sizeof(val)); + UPB_PRIVATE(_upb_Array_Set) + (arr, arr->UPB_PRIVATE(size) - 1, &val, sizeof(val)); return true; } )cc", diff --git a/upb_generator/stage0/google/protobuf/compiler/plugin.upb.h b/upb_generator/stage0/google/protobuf/compiler/plugin.upb.h index 27de0bc0e9517..b354a86aab843 100644 --- a/upb_generator/stage0/google/protobuf/compiler/plugin.upb.h +++ b/upb_generator/stage0/google/protobuf/compiler/plugin.upb.h @@ -196,7 +196,7 @@ UPB_INLINE upb_StringView const* google_protobuf_compiler_CodeGeneratorRequest_f const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorRequest_msg_init(), 1); const upb_Array* arr = upb_Message_GetArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (upb_StringView const*)_upb_array_constptr(arr); } else { if (size) *size = 0; @@ -207,7 +207,7 @@ UPB_INLINE const upb_Array* _google_protobuf_compiler_CodeGeneratorRequest_file_ const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorRequest_msg_init(), 1); const upb_Array* arr = upb_Message_GetArray(msg, &field); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -216,7 +216,7 @@ UPB_INLINE upb_Array* _google_protobuf_compiler_CodeGeneratorRequest_file_to_gen upb_Array* arr = upb_Message_GetOrCreateMutableArray( (upb_Message*)msg, &field, arena); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -258,7 +258,7 @@ UPB_INLINE const struct google_protobuf_FileDescriptorProto* const* google_proto const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorRequest_msg_init(), 15); const upb_Array* arr = upb_Message_GetArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (const struct google_protobuf_FileDescriptorProto* const*)_upb_array_constptr(arr); } else { if (size) *size = 0; @@ -269,7 +269,7 @@ UPB_INLINE const upb_Array* _google_protobuf_compiler_CodeGeneratorRequest_proto const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorRequest_msg_init(), 15); const upb_Array* arr = upb_Message_GetArray(msg, &field); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -278,7 +278,7 @@ UPB_INLINE upb_Array* _google_protobuf_compiler_CodeGeneratorRequest_proto_file_ upb_Array* arr = upb_Message_GetOrCreateMutableArray( (upb_Message*)msg, &field, arena); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -290,7 +290,7 @@ UPB_INLINE const struct google_protobuf_FileDescriptorProto* const* google_proto const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorRequest_msg_init(), 17); const upb_Array* arr = upb_Message_GetArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (const struct google_protobuf_FileDescriptorProto* const*)_upb_array_constptr(arr); } else { if (size) *size = 0; @@ -301,7 +301,7 @@ UPB_INLINE const upb_Array* _google_protobuf_compiler_CodeGeneratorRequest_sourc const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorRequest_msg_init(), 17); const upb_Array* arr = upb_Message_GetArray(msg, &field); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -310,7 +310,7 @@ UPB_INLINE upb_Array* _google_protobuf_compiler_CodeGeneratorRequest_source_file upb_Array* arr = upb_Message_GetOrCreateMutableArray( (upb_Message*)msg, &field, arena); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -319,7 +319,7 @@ UPB_INLINE upb_StringView* google_protobuf_compiler_CodeGeneratorRequest_mutable upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorRequest_msg_init(), 1); upb_Array* arr = upb_Message_GetMutableArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (upb_StringView*)_upb_array_ptr(arr); } else { if (size) *size = 0; @@ -333,10 +333,12 @@ UPB_INLINE upb_StringView* google_protobuf_compiler_CodeGeneratorRequest_resize_ UPB_INLINE bool google_protobuf_compiler_CodeGeneratorRequest_add_file_to_generate(google_protobuf_compiler_CodeGeneratorRequest* msg, upb_StringView val, upb_Arena* arena) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorRequest_msg_init(), 1); upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); - if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { + if (!arr || !_upb_Array_ResizeUninitialized( + arr, arr->UPB_PRIVATE(size) + 1, arena)) { return false; } - UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &val, sizeof(val)); + UPB_PRIVATE(_upb_Array_Set) + (arr, arr->UPB_PRIVATE(size) - 1, &val, sizeof(val)); return true; } UPB_INLINE void google_protobuf_compiler_CodeGeneratorRequest_set_parameter(google_protobuf_compiler_CodeGeneratorRequest *msg, upb_StringView value) { @@ -359,7 +361,7 @@ UPB_INLINE struct google_protobuf_FileDescriptorProto** google_protobuf_compiler upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorRequest_msg_init(), 15); upb_Array* arr = upb_Message_GetMutableArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (struct google_protobuf_FileDescriptorProto**)_upb_array_ptr(arr); } else { if (size) *size = 0; @@ -373,19 +375,21 @@ UPB_INLINE struct google_protobuf_FileDescriptorProto** google_protobuf_compiler UPB_INLINE struct google_protobuf_FileDescriptorProto* google_protobuf_compiler_CodeGeneratorRequest_add_proto_file(google_protobuf_compiler_CodeGeneratorRequest* msg, upb_Arena* arena) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorRequest_msg_init(), 15); upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); - if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { + if (!arr || !_upb_Array_ResizeUninitialized( + arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; } struct google_protobuf_FileDescriptorProto* sub = (struct google_protobuf_FileDescriptorProto*)_upb_Message_New(google__protobuf__FileDescriptorProto_msg_init(), arena); if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &sub, sizeof(sub)); + UPB_PRIVATE(_upb_Array_Set) + (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); return sub; } UPB_INLINE struct google_protobuf_FileDescriptorProto** google_protobuf_compiler_CodeGeneratorRequest_mutable_source_file_descriptors(google_protobuf_compiler_CodeGeneratorRequest* msg, size_t* size) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorRequest_msg_init(), 17); upb_Array* arr = upb_Message_GetMutableArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (struct google_protobuf_FileDescriptorProto**)_upb_array_ptr(arr); } else { if (size) *size = 0; @@ -399,12 +403,14 @@ UPB_INLINE struct google_protobuf_FileDescriptorProto** google_protobuf_compiler UPB_INLINE struct google_protobuf_FileDescriptorProto* google_protobuf_compiler_CodeGeneratorRequest_add_source_file_descriptors(google_protobuf_compiler_CodeGeneratorRequest* msg, upb_Arena* arena) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorRequest_msg_init(), 17); upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); - if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { + if (!arr || !_upb_Array_ResizeUninitialized( + arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; } struct google_protobuf_FileDescriptorProto* sub = (struct google_protobuf_FileDescriptorProto*)_upb_Message_New(google__protobuf__FileDescriptorProto_msg_init(), arena); if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &sub, sizeof(sub)); + UPB_PRIVATE(_upb_Array_Set) + (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); return sub; } @@ -511,7 +517,7 @@ UPB_INLINE const google_protobuf_compiler_CodeGeneratorResponse_File* const* goo const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorResponse_msg_init(), 15); const upb_Array* arr = upb_Message_GetArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_compiler_CodeGeneratorResponse_File* const*)_upb_array_constptr(arr); } else { if (size) *size = 0; @@ -522,7 +528,7 @@ UPB_INLINE const upb_Array* _google_protobuf_compiler_CodeGeneratorResponse_file const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorResponse_msg_init(), 15); const upb_Array* arr = upb_Message_GetArray(msg, &field); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -531,7 +537,7 @@ UPB_INLINE upb_Array* _google_protobuf_compiler_CodeGeneratorResponse_file_mutab upb_Array* arr = upb_Message_GetOrCreateMutableArray( (upb_Message*)msg, &field, arena); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -556,7 +562,7 @@ UPB_INLINE google_protobuf_compiler_CodeGeneratorResponse_File** google_protobuf upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorResponse_msg_init(), 15); upb_Array* arr = upb_Message_GetMutableArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_compiler_CodeGeneratorResponse_File**)_upb_array_ptr(arr); } else { if (size) *size = 0; @@ -570,12 +576,14 @@ UPB_INLINE google_protobuf_compiler_CodeGeneratorResponse_File** google_protobuf UPB_INLINE struct google_protobuf_compiler_CodeGeneratorResponse_File* google_protobuf_compiler_CodeGeneratorResponse_add_file(google_protobuf_compiler_CodeGeneratorResponse* msg, upb_Arena* arena) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorResponse_msg_init(), 15); upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); - if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { + if (!arr || !_upb_Array_ResizeUninitialized( + arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; } struct google_protobuf_compiler_CodeGeneratorResponse_File* sub = (struct google_protobuf_compiler_CodeGeneratorResponse_File*)_upb_Message_New(google__protobuf__compiler__CodeGeneratorResponse__File_msg_init(), arena); if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &sub, sizeof(sub)); + UPB_PRIVATE(_upb_Array_Set) + (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); return sub; } From f73985a9f93c116254e5f1103f0590a55554a115 Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Tue, 19 Dec 2023 00:14:19 +0000 Subject: [PATCH 045/255] Auto-generate files after cl/592035282 --- php/ext/google/protobuf/php-upb.c | 93 ++-- php/ext/google/protobuf/php-upb.h | 571 ++++++++++++--------- ruby/ext/google/protobuf_c/ruby-upb.c | 93 ++-- ruby/ext/google/protobuf_c/ruby-upb.h | 571 ++++++++++++--------- upb/cmake/google/protobuf/descriptor.upb.h | 560 +++++++++++--------- 5 files changed, 1072 insertions(+), 816 deletions(-) diff --git a/php/ext/google/protobuf/php-upb.c b/php/ext/google/protobuf/php-upb.c index 0d052088d7bda..06794093f5662 100644 --- a/php/ext/google/protobuf/php-upb.c +++ b/php/ext/google/protobuf/php-upb.c @@ -6116,7 +6116,7 @@ static upb_Map* upb_Message_Map_DeepClone(const upb_Map* map, upb_Array* upb_Array_DeepClone(const upb_Array* array, upb_CType value_type, const upb_MiniTable* sub, upb_Arena* arena) { - size_t size = array->size; + size_t size = array->UPB_PRIVATE(size); upb_Array* cloned_array = UPB_PRIVATE(_upb_Array_New)(arena, size, upb_CType_SizeLg2(value_type)); if (!cloned_array) { @@ -6316,13 +6316,13 @@ const void* upb_Array_DataPtr(const upb_Array* arr) { void* upb_Array_MutableDataPtr(upb_Array* arr) { return _upb_array_ptr(arr); } -size_t upb_Array_Size(const upb_Array* arr) { return arr->size; } +size_t upb_Array_Size(const upb_Array* arr) { return arr->UPB_PRIVATE(size); } upb_MessageValue upb_Array_Get(const upb_Array* arr, size_t i) { upb_MessageValue ret; const char* data = _upb_array_constptr(arr); const int lg2 = UPB_PRIVATE(_upb_Array_ElemSizeLg2)(arr); - UPB_ASSERT(i < arr->size); + UPB_ASSERT(i < arr->UPB_PRIVATE(size)); memcpy(&ret, data + (i << lg2), 1 << lg2); return ret; } @@ -6330,16 +6330,16 @@ upb_MessageValue upb_Array_Get(const upb_Array* arr, size_t i) { void upb_Array_Set(upb_Array* arr, size_t i, upb_MessageValue val) { char* data = _upb_array_ptr(arr); const int lg2 = UPB_PRIVATE(_upb_Array_ElemSizeLg2)(arr); - UPB_ASSERT(i < arr->size); + UPB_ASSERT(i < arr->UPB_PRIVATE(size)); memcpy(data + (i << lg2), &val, 1 << lg2); } bool upb_Array_Append(upb_Array* arr, upb_MessageValue val, upb_Arena* arena) { UPB_ASSERT(arena); - if (!_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { + if (!_upb_Array_ResizeUninitialized(arr, arr->UPB_PRIVATE(size) + 1, arena)) { return false; } - upb_Array_Set(arr, arr->size - 1, val); + upb_Array_Set(arr, arr->UPB_PRIVATE(size) - 1, val); return true; } @@ -6353,10 +6353,11 @@ void upb_Array_Move(upb_Array* arr, size_t dst_idx, size_t src_idx, bool upb_Array_Insert(upb_Array* arr, size_t i, size_t count, upb_Arena* arena) { UPB_ASSERT(arena); - UPB_ASSERT(i <= arr->size); - UPB_ASSERT(count + arr->size >= count); - const size_t oldsize = arr->size; - if (!_upb_Array_ResizeUninitialized(arr, arr->size + count, arena)) { + UPB_ASSERT(i <= arr->UPB_PRIVATE(size)); + UPB_ASSERT(count + arr->UPB_PRIVATE(size) >= count); + const size_t oldsize = arr->UPB_PRIVATE(size); + if (!_upb_Array_ResizeUninitialized(arr, arr->UPB_PRIVATE(size) + count, + arena)) { return false; } upb_Array_Move(arr, i + count, i, oldsize - i); @@ -6370,17 +6371,17 @@ bool upb_Array_Insert(upb_Array* arr, size_t i, size_t count, void upb_Array_Delete(upb_Array* arr, size_t i, size_t count) { const size_t end = i + count; UPB_ASSERT(i <= end); - UPB_ASSERT(end <= arr->size); - upb_Array_Move(arr, i, end, arr->size - end); - arr->size -= count; + UPB_ASSERT(end <= arr->UPB_PRIVATE(size)); + upb_Array_Move(arr, i, end, arr->UPB_PRIVATE(size) - end); + arr->UPB_PRIVATE(size) -= count; } bool upb_Array_Resize(upb_Array* arr, size_t size, upb_Arena* arena) { - const size_t oldsize = arr->size; + const size_t oldsize = arr->UPB_PRIVATE(size); if (UPB_UNLIKELY(!_upb_Array_ResizeUninitialized(arr, size, arena))) { return false; } - const size_t newsize = arr->size; + const size_t newsize = arr->UPB_PRIVATE(size); if (newsize > oldsize) { const int lg2 = UPB_PRIVATE(_upb_Array_ElemSizeLg2)(arr); char* data = _upb_array_ptr(arr); @@ -12803,9 +12804,10 @@ static void _upb_Decoder_VerifyUtf8(upb_Decoder* d, const char* buf, int len) { } static bool _upb_Decoder_Reserve(upb_Decoder* d, upb_Array* arr, size_t elem) { - bool need_realloc = arr->UPB_PRIVATE(capacity) - arr->size < elem; - if (need_realloc && - !UPB_PRIVATE(_upb_Array_Realloc)(arr, arr->size + elem, &d->arena)) { + bool need_realloc = + arr->UPB_PRIVATE(capacity) - arr->UPB_PRIVATE(size) < elem; + if (need_realloc && !UPB_PRIVATE(_upb_Array_Realloc)( + arr, arr->UPB_PRIVATE(size) + elem, &d->arena)) { _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_OutOfMemory); } return need_realloc; @@ -13079,8 +13081,8 @@ static const char* _upb_Decoder_DecodeEnumArray(upb_Decoder* d, const char* ptr, wireval* val) { const upb_MiniTableEnum* e = _upb_MiniTableSubs_EnumByField(subs, field); if (!_upb_Decoder_CheckEnum(d, ptr, msg, e, field, val)) return ptr; - void* mem = UPB_PTR_AT(_upb_array_ptr(arr), arr->size * 4, void); - arr->size++; + void* mem = UPB_PTR_AT(_upb_array_ptr(arr), arr->UPB_PRIVATE(size) * 4, void); + arr->UPB_PRIVATE(size)++; memcpy(mem, val, 4); return ptr; } @@ -13096,8 +13098,9 @@ static const char* _upb_Decoder_DecodeFixedPacked( _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_Malformed); } _upb_Decoder_Reserve(d, arr, count); - void* mem = UPB_PTR_AT(_upb_array_ptr(arr), arr->size << lg2, void); - arr->size += count; + void* mem = + UPB_PTR_AT(_upb_array_ptr(arr), arr->UPB_PRIVATE(size) << lg2, void); + arr->UPB_PRIVATE(size) += count; // Note: if/when the decoder supports multi-buffer input, we will need to // handle buffer seams here. if (_upb_IsLittleEndian()) { @@ -13127,15 +13130,17 @@ static const char* _upb_Decoder_DecodeVarintPacked( const upb_MiniTableField* field, int lg2) { int scale = 1 << lg2; int saved_limit = upb_EpsCopyInputStream_PushLimit(&d->input, ptr, val->size); - char* out = UPB_PTR_AT(_upb_array_ptr(arr), arr->size << lg2, void); + char* out = + UPB_PTR_AT(_upb_array_ptr(arr), arr->UPB_PRIVATE(size) << lg2, void); while (!_upb_Decoder_IsDone(d, &ptr)) { wireval elem; ptr = _upb_Decoder_DecodeVarint(d, ptr, &elem.uint64_val); _upb_Decoder_Munge(field->UPB_PRIVATE(descriptortype), &elem); if (_upb_Decoder_Reserve(d, arr, 1)) { - out = UPB_PTR_AT(_upb_array_ptr(arr), arr->size << lg2, void); + out = + UPB_PTR_AT(_upb_array_ptr(arr), arr->UPB_PRIVATE(size) << lg2, void); } - arr->size++; + arr->UPB_PRIVATE(size)++; memcpy(out, &elem, scale); out += scale; } @@ -13150,7 +13155,7 @@ static const char* _upb_Decoder_DecodeEnumPacked( wireval* val) { const upb_MiniTableEnum* e = _upb_MiniTableSubs_EnumByField(subs, field); int saved_limit = upb_EpsCopyInputStream_PushLimit(&d->input, ptr, val->size); - char* out = UPB_PTR_AT(_upb_array_ptr(arr), arr->size * 4, void); + char* out = UPB_PTR_AT(_upb_array_ptr(arr), arr->UPB_PRIVATE(size) * 4, void); while (!_upb_Decoder_IsDone(d, &ptr)) { wireval elem; ptr = _upb_Decoder_DecodeVarint(d, ptr, &elem.uint64_val); @@ -13159,9 +13164,9 @@ static const char* _upb_Decoder_DecodeEnumPacked( continue; } if (_upb_Decoder_Reserve(d, arr, 1)) { - out = UPB_PTR_AT(_upb_array_ptr(arr), arr->size * 4, void); + out = UPB_PTR_AT(_upb_array_ptr(arr), arr->UPB_PRIVATE(size) * 4, void); } - arr->size++; + arr->UPB_PRIVATE(size)++; memcpy(out, &elem, 4); out += 4; } @@ -13199,8 +13204,8 @@ static const char* _upb_Decoder_DecodeToArray(upb_Decoder* d, const char* ptr, case kUpb_DecodeOp_Scalar4Byte: case kUpb_DecodeOp_Scalar8Byte: /* Append scalar value. */ - mem = UPB_PTR_AT(_upb_array_ptr(arr), arr->size << op, void); - arr->size++; + mem = UPB_PTR_AT(_upb_array_ptr(arr), arr->UPB_PRIVATE(size) << op, void); + arr->UPB_PRIVATE(size)++; memcpy(mem, val, 1 << op); return ptr; case kUpb_DecodeOp_String: @@ -13208,16 +13213,18 @@ static const char* _upb_Decoder_DecodeToArray(upb_Decoder* d, const char* ptr, /* Fallthrough. */ case kUpb_DecodeOp_Bytes: { /* Append bytes. */ - upb_StringView* str = (upb_StringView*)_upb_array_ptr(arr) + arr->size; - arr->size++; + upb_StringView* str = + (upb_StringView*)_upb_array_ptr(arr) + arr->UPB_PRIVATE(size); + arr->UPB_PRIVATE(size)++; return _upb_Decoder_ReadString(d, ptr, val->size, str); } case kUpb_DecodeOp_SubMessage: { /* Append submessage / group. */ upb_TaggedMessagePtr* target = UPB_PTR_AT( - _upb_array_ptr(arr), arr->size * sizeof(void*), upb_TaggedMessagePtr); + _upb_array_ptr(arr), arr->UPB_PRIVATE(size) * sizeof(void*), + upb_TaggedMessagePtr); upb_Message* submsg = _upb_Decoder_NewSubMessage(d, subs, field, target); - arr->size++; + arr->UPB_PRIVATE(size)++; if (UPB_UNLIKELY(field->UPB_PRIVATE(descriptortype) == kUpb_FieldType_Group)) { return _upb_Decoder_DecodeKnownGroup(d, ptr, submsg, subs, field); @@ -14235,7 +14242,7 @@ static bool fastdecode_tagmatch(uint32_t tag, uint64_t data, int tagbytes) { UPB_FORCEINLINE static void fastdecode_commitarr(void* dst, fastdecode_arr* farr, int valbytes) { - farr->arr->size = + farr->arr->UPB_PRIVATE(size) = (size_t)((char*)dst - (char*)_upb_array_ptr(farr->arr)) / valbytes; } @@ -14306,7 +14313,7 @@ static void* fastdecode_getfield(upb_Decoder* d, const char* ptr, begin = _upb_array_ptr(farr->arr); farr->end = begin + (farr->arr->UPB_PRIVATE(capacity) * valbytes); *data = _upb_FastDecoder_LoadTag(ptr); - return begin + (farr->arr->size * valbytes); + return begin + (farr->arr->UPB_PRIVATE(size) * valbytes); } default: UPB_UNREACHABLE(); @@ -14594,7 +14601,7 @@ TAGBYTES(p) \ char* dst = _upb_array_ptr(arr); \ memcpy(dst, ptr, size); \ - arr->size = elems; \ + arr->UPB_PRIVATE(size) = elems; \ \ ptr += size; \ UPB_MUSTTAIL return fastdecode_dispatch(UPB_PARSE_ARGS); @@ -15192,7 +15199,7 @@ static void encode_tag(upb_encstate* e, uint32_t field_number, static void encode_fixedarray(upb_encstate* e, const upb_Array* arr, size_t elem_size, uint32_t tag) { - size_t bytes = arr->size * elem_size; + size_t bytes = arr->UPB_PRIVATE(size) * elem_size; const char* data = _upb_array_constptr(arr); const char* ptr = data + bytes - elem_size; @@ -15324,14 +15331,14 @@ static void encode_array(upb_encstate* e, const upb_Message* msg, bool packed = upb_MiniTableField_IsPacked(f); size_t pre_len = e->limit - e->ptr; - if (arr == NULL || arr->size == 0) { + if (arr == NULL || arr->UPB_PRIVATE(size) == 0) { return; } #define VARINT_CASE(ctype, encode) \ { \ const ctype* start = _upb_array_constptr(arr); \ - const ctype* ptr = start + arr->size; \ + const ctype* ptr = start + arr->UPB_PRIVATE(size); \ uint32_t tag = \ packed ? 0 : (f->UPB_PRIVATE(number) << 3) | kUpb_WireType_Varint; \ do { \ @@ -15376,7 +15383,7 @@ static void encode_array(upb_encstate* e, const upb_Message* msg, case kUpb_FieldType_String: case kUpb_FieldType_Bytes: { const upb_StringView* start = _upb_array_constptr(arr); - const upb_StringView* ptr = start + arr->size; + const upb_StringView* ptr = start + arr->UPB_PRIVATE(size); do { ptr--; encode_bytes(e, ptr->data, ptr->size); @@ -15387,7 +15394,7 @@ static void encode_array(upb_encstate* e, const upb_Message* msg, } case kUpb_FieldType_Group: { const upb_TaggedMessagePtr* start = _upb_array_constptr(arr); - const upb_TaggedMessagePtr* ptr = start + arr->size; + const upb_TaggedMessagePtr* ptr = start + arr->UPB_PRIVATE(size); const upb_MiniTable* subm = upb_MiniTableSub_Message(subs[f->UPB_PRIVATE(submsg_index)]); if (--e->depth == 0) encode_err(e, kUpb_EncodeStatus_MaxDepthExceeded); @@ -15403,7 +15410,7 @@ static void encode_array(upb_encstate* e, const upb_Message* msg, } case kUpb_FieldType_Message: { const upb_TaggedMessagePtr* start = _upb_array_constptr(arr); - const upb_TaggedMessagePtr* ptr = start + arr->size; + const upb_TaggedMessagePtr* ptr = start + arr->UPB_PRIVATE(size); const upb_MiniTable* subm = upb_MiniTableSub_Message(subs[f->UPB_PRIVATE(submsg_index)]); if (--e->depth == 0) encode_err(e, kUpb_EncodeStatus_MaxDepthExceeded); diff --git a/php/ext/google/protobuf/php-upb.h b/php/ext/google/protobuf/php-upb.h index 786ca7de775a1..ac765cebd96c7 100644 --- a/php/ext/google/protobuf/php-upb.h +++ b/php/ext/google/protobuf/php-upb.h @@ -2798,7 +2798,7 @@ struct upb_Array { // Bit #2 contains the frozen/immutable flag (currently unimplemented). uintptr_t data; - size_t size; // The number of elements in the array. + size_t UPB_ONLYBITS(size); // The number of elements in the array. size_t UPB_PRIVATE(capacity); // Allocated storage. Measured in elements. }; @@ -2836,7 +2836,7 @@ UPB_INLINE upb_Array* UPB_PRIVATE(_upb_Array_New)(upb_Arena* arena, if (!array) return NULL; UPB_PRIVATE(_upb_Array_SetTaggedPtr) (array, UPB_PTR_AT(array, array_size, void), elem_size_lg2); - array->size = 0; + array->UPB_ONLYBITS(size) = 0; array->UPB_PRIVATE(capacity) = init_capacity; return array; } @@ -2855,9 +2855,10 @@ UPB_INLINE bool UPB_PRIVATE(_upb_Array_Reserve)(upb_Array* array, size_t size, // Resize without initializing new elements. UPB_INLINE bool _upb_Array_ResizeUninitialized(upb_Array* array, size_t size, upb_Arena* arena) { - UPB_ASSERT(size <= array->size || arena); // Allow NULL arena when shrinking. + UPB_ASSERT(size <= array->UPB_ONLYBITS(size) || + arena); // Allow NULL arena when shrinking. if (!UPB_PRIVATE(_upb_Array_Reserve)(array, size, arena)) return false; - array->size = size; + array->UPB_ONLYBITS(size) = size; return true; } @@ -2867,7 +2868,7 @@ UPB_INLINE bool _upb_Array_ResizeUninitialized(upb_Array* array, size_t size, UPB_INLINE void UPB_PRIVATE(_upb_Array_Set)(upb_Array* array, size_t i, const void* data, size_t elem_size) { - UPB_ASSERT(i < array->size); + UPB_ASSERT(i < array->UPB_ONLYBITS(size)); UPB_ASSERT(elem_size == 1U << UPB_PRIVATE(_upb_Array_ElemSizeLg2)(array)); char* arr_data = (char*)_upb_array_ptr(array); memcpy(arr_data + (i * elem_size), data, elem_size); @@ -4450,7 +4451,7 @@ UPB_INLINE const google_protobuf_FileDescriptorProto* const* google_protobuf_Fil const upb_MiniTableField field = {1, 0, 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_FileDescriptorProto* const*)_upb_array_constptr(arr); } else { if (size) *size = 0; @@ -4461,7 +4462,7 @@ UPB_INLINE const upb_Array* _google_protobuf_FileDescriptorSet_file_upb_array(co const upb_MiniTableField field = {1, 0, 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -4470,7 +4471,7 @@ UPB_INLINE upb_Array* _google_protobuf_FileDescriptorSet_file_mutable_upb_array( upb_Array* arr = upb_Message_GetOrCreateMutableArray( (upb_Message*)msg, &field, arena); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -4479,7 +4480,7 @@ UPB_INLINE google_protobuf_FileDescriptorProto** google_protobuf_FileDescriptorS upb_MiniTableField field = {1, 0, 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetMutableArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_FileDescriptorProto**)_upb_array_ptr(arr); } else { if (size) *size = 0; @@ -4493,12 +4494,14 @@ UPB_INLINE google_protobuf_FileDescriptorProto** google_protobuf_FileDescriptorS UPB_INLINE struct google_protobuf_FileDescriptorProto* google_protobuf_FileDescriptorSet_add_file(google_protobuf_FileDescriptorSet* msg, upb_Arena* arena) { upb_MiniTableField field = {1, 0, 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); - if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { + if (!arr || !_upb_Array_ResizeUninitialized( + arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; } struct google_protobuf_FileDescriptorProto* sub = (struct google_protobuf_FileDescriptorProto*)_upb_Message_New(&google__protobuf__FileDescriptorProto_msg_init, arena); if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &sub, sizeof(sub)); + UPB_PRIVATE(_upb_Array_Set) + (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); return sub; } @@ -4575,7 +4578,7 @@ UPB_INLINE upb_StringView const* google_protobuf_FileDescriptorProto_dependency( const upb_MiniTableField field = {3, UPB_SIZE(4, 40), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (upb_StringView const*)_upb_array_constptr(arr); } else { if (size) *size = 0; @@ -4586,7 +4589,7 @@ UPB_INLINE const upb_Array* _google_protobuf_FileDescriptorProto_dependency_upb_ const upb_MiniTableField field = {3, UPB_SIZE(4, 40), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -4595,7 +4598,7 @@ UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_dependency_mutable_up upb_Array* arr = upb_Message_GetOrCreateMutableArray( (upb_Message*)msg, &field, arena); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -4607,7 +4610,7 @@ UPB_INLINE const google_protobuf_DescriptorProto* const* google_protobuf_FileDes const upb_MiniTableField field = {4, UPB_SIZE(8, 48), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_DescriptorProto* const*)_upb_array_constptr(arr); } else { if (size) *size = 0; @@ -4618,7 +4621,7 @@ UPB_INLINE const upb_Array* _google_protobuf_FileDescriptorProto_message_type_up const upb_MiniTableField field = {4, UPB_SIZE(8, 48), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -4627,7 +4630,7 @@ UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_message_type_mutable_ upb_Array* arr = upb_Message_GetOrCreateMutableArray( (upb_Message*)msg, &field, arena); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -4639,7 +4642,7 @@ UPB_INLINE const google_protobuf_EnumDescriptorProto* const* google_protobuf_Fil const upb_MiniTableField field = {5, UPB_SIZE(12, 56), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_EnumDescriptorProto* const*)_upb_array_constptr(arr); } else { if (size) *size = 0; @@ -4650,7 +4653,7 @@ UPB_INLINE const upb_Array* _google_protobuf_FileDescriptorProto_enum_type_upb_a const upb_MiniTableField field = {5, UPB_SIZE(12, 56), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -4659,7 +4662,7 @@ UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_enum_type_mutable_upb upb_Array* arr = upb_Message_GetOrCreateMutableArray( (upb_Message*)msg, &field, arena); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -4671,7 +4674,7 @@ UPB_INLINE const google_protobuf_ServiceDescriptorProto* const* google_protobuf_ const upb_MiniTableField field = {6, UPB_SIZE(16, 64), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_ServiceDescriptorProto* const*)_upb_array_constptr(arr); } else { if (size) *size = 0; @@ -4682,7 +4685,7 @@ UPB_INLINE const upb_Array* _google_protobuf_FileDescriptorProto_service_upb_arr const upb_MiniTableField field = {6, UPB_SIZE(16, 64), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -4691,7 +4694,7 @@ UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_service_mutable_upb_a upb_Array* arr = upb_Message_GetOrCreateMutableArray( (upb_Message*)msg, &field, arena); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -4703,7 +4706,7 @@ UPB_INLINE const google_protobuf_FieldDescriptorProto* const* google_protobuf_Fi const upb_MiniTableField field = {7, UPB_SIZE(20, 72), 0, 3, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_FieldDescriptorProto* const*)_upb_array_constptr(arr); } else { if (size) *size = 0; @@ -4714,7 +4717,7 @@ UPB_INLINE const upb_Array* _google_protobuf_FileDescriptorProto_extension_upb_a const upb_MiniTableField field = {7, UPB_SIZE(20, 72), 0, 3, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -4723,7 +4726,7 @@ UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_extension_mutable_upb upb_Array* arr = upb_Message_GetOrCreateMutableArray( (upb_Message*)msg, &field, arena); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -4765,7 +4768,7 @@ UPB_INLINE int32_t const* google_protobuf_FileDescriptorProto_public_dependency( const upb_MiniTableField field = {10, UPB_SIZE(32, 96), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (int32_t const*)_upb_array_constptr(arr); } else { if (size) *size = 0; @@ -4776,7 +4779,7 @@ UPB_INLINE const upb_Array* _google_protobuf_FileDescriptorProto_public_dependen const upb_MiniTableField field = {10, UPB_SIZE(32, 96), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -4785,7 +4788,7 @@ UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_public_dependency_mut upb_Array* arr = upb_Message_GetOrCreateMutableArray( (upb_Message*)msg, &field, arena); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -4797,7 +4800,7 @@ UPB_INLINE int32_t const* google_protobuf_FileDescriptorProto_weak_dependency(co const upb_MiniTableField field = {11, UPB_SIZE(36, 104), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (int32_t const*)_upb_array_constptr(arr); } else { if (size) *size = 0; @@ -4808,7 +4811,7 @@ UPB_INLINE const upb_Array* _google_protobuf_FileDescriptorProto_weak_dependency const upb_MiniTableField field = {11, UPB_SIZE(36, 104), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -4817,7 +4820,7 @@ UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_weak_dependency_mutab upb_Array* arr = upb_Message_GetOrCreateMutableArray( (upb_Message*)msg, &field, arena); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -4864,7 +4867,7 @@ UPB_INLINE upb_StringView* google_protobuf_FileDescriptorProto_mutable_dependenc upb_MiniTableField field = {3, UPB_SIZE(4, 40), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetMutableArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (upb_StringView*)_upb_array_ptr(arr); } else { if (size) *size = 0; @@ -4878,17 +4881,19 @@ UPB_INLINE upb_StringView* google_protobuf_FileDescriptorProto_resize_dependency UPB_INLINE bool google_protobuf_FileDescriptorProto_add_dependency(google_protobuf_FileDescriptorProto* msg, upb_StringView val, upb_Arena* arena) { upb_MiniTableField field = {3, UPB_SIZE(4, 40), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); - if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { + if (!arr || !_upb_Array_ResizeUninitialized( + arr, arr->UPB_PRIVATE(size) + 1, arena)) { return false; } - UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &val, sizeof(val)); + UPB_PRIVATE(_upb_Array_Set) + (arr, arr->UPB_PRIVATE(size) - 1, &val, sizeof(val)); return true; } UPB_INLINE google_protobuf_DescriptorProto** google_protobuf_FileDescriptorProto_mutable_message_type(google_protobuf_FileDescriptorProto* msg, size_t* size) { upb_MiniTableField field = {4, UPB_SIZE(8, 48), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetMutableArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_DescriptorProto**)_upb_array_ptr(arr); } else { if (size) *size = 0; @@ -4902,19 +4907,21 @@ UPB_INLINE google_protobuf_DescriptorProto** google_protobuf_FileDescriptorProto UPB_INLINE struct google_protobuf_DescriptorProto* google_protobuf_FileDescriptorProto_add_message_type(google_protobuf_FileDescriptorProto* msg, upb_Arena* arena) { upb_MiniTableField field = {4, UPB_SIZE(8, 48), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); - if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { + if (!arr || !_upb_Array_ResizeUninitialized( + arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; } struct google_protobuf_DescriptorProto* sub = (struct google_protobuf_DescriptorProto*)_upb_Message_New(&google__protobuf__DescriptorProto_msg_init, arena); if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &sub, sizeof(sub)); + UPB_PRIVATE(_upb_Array_Set) + (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); return sub; } UPB_INLINE google_protobuf_EnumDescriptorProto** google_protobuf_FileDescriptorProto_mutable_enum_type(google_protobuf_FileDescriptorProto* msg, size_t* size) { upb_MiniTableField field = {5, UPB_SIZE(12, 56), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetMutableArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_EnumDescriptorProto**)_upb_array_ptr(arr); } else { if (size) *size = 0; @@ -4928,19 +4935,21 @@ UPB_INLINE google_protobuf_EnumDescriptorProto** google_protobuf_FileDescriptorP UPB_INLINE struct google_protobuf_EnumDescriptorProto* google_protobuf_FileDescriptorProto_add_enum_type(google_protobuf_FileDescriptorProto* msg, upb_Arena* arena) { upb_MiniTableField field = {5, UPB_SIZE(12, 56), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); - if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { + if (!arr || !_upb_Array_ResizeUninitialized( + arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; } struct google_protobuf_EnumDescriptorProto* sub = (struct google_protobuf_EnumDescriptorProto*)_upb_Message_New(&google__protobuf__EnumDescriptorProto_msg_init, arena); if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &sub, sizeof(sub)); + UPB_PRIVATE(_upb_Array_Set) + (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); return sub; } UPB_INLINE google_protobuf_ServiceDescriptorProto** google_protobuf_FileDescriptorProto_mutable_service(google_protobuf_FileDescriptorProto* msg, size_t* size) { upb_MiniTableField field = {6, UPB_SIZE(16, 64), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetMutableArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_ServiceDescriptorProto**)_upb_array_ptr(arr); } else { if (size) *size = 0; @@ -4954,19 +4963,21 @@ UPB_INLINE google_protobuf_ServiceDescriptorProto** google_protobuf_FileDescript UPB_INLINE struct google_protobuf_ServiceDescriptorProto* google_protobuf_FileDescriptorProto_add_service(google_protobuf_FileDescriptorProto* msg, upb_Arena* arena) { upb_MiniTableField field = {6, UPB_SIZE(16, 64), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); - if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { + if (!arr || !_upb_Array_ResizeUninitialized( + arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; } struct google_protobuf_ServiceDescriptorProto* sub = (struct google_protobuf_ServiceDescriptorProto*)_upb_Message_New(&google__protobuf__ServiceDescriptorProto_msg_init, arena); if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &sub, sizeof(sub)); + UPB_PRIVATE(_upb_Array_Set) + (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); return sub; } UPB_INLINE google_protobuf_FieldDescriptorProto** google_protobuf_FileDescriptorProto_mutable_extension(google_protobuf_FileDescriptorProto* msg, size_t* size) { upb_MiniTableField field = {7, UPB_SIZE(20, 72), 0, 3, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetMutableArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_FieldDescriptorProto**)_upb_array_ptr(arr); } else { if (size) *size = 0; @@ -4980,12 +4991,14 @@ UPB_INLINE google_protobuf_FieldDescriptorProto** google_protobuf_FileDescriptor UPB_INLINE struct google_protobuf_FieldDescriptorProto* google_protobuf_FileDescriptorProto_add_extension(google_protobuf_FileDescriptorProto* msg, upb_Arena* arena) { upb_MiniTableField field = {7, UPB_SIZE(20, 72), 0, 3, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); - if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { + if (!arr || !_upb_Array_ResizeUninitialized( + arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; } struct google_protobuf_FieldDescriptorProto* sub = (struct google_protobuf_FieldDescriptorProto*)_upb_Message_New(&google__protobuf__FieldDescriptorProto_msg_init, arena); if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &sub, sizeof(sub)); + UPB_PRIVATE(_upb_Array_Set) + (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); return sub; } UPB_INLINE void google_protobuf_FileDescriptorProto_set_options(google_protobuf_FileDescriptorProto *msg, google_protobuf_FileOptions* value) { @@ -5016,7 +5029,7 @@ UPB_INLINE int32_t* google_protobuf_FileDescriptorProto_mutable_public_dependenc upb_MiniTableField field = {10, UPB_SIZE(32, 96), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetMutableArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (int32_t*)_upb_array_ptr(arr); } else { if (size) *size = 0; @@ -5030,17 +5043,19 @@ UPB_INLINE int32_t* google_protobuf_FileDescriptorProto_resize_public_dependency UPB_INLINE bool google_protobuf_FileDescriptorProto_add_public_dependency(google_protobuf_FileDescriptorProto* msg, int32_t val, upb_Arena* arena) { upb_MiniTableField field = {10, UPB_SIZE(32, 96), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); - if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { + if (!arr || !_upb_Array_ResizeUninitialized( + arr, arr->UPB_PRIVATE(size) + 1, arena)) { return false; } - UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &val, sizeof(val)); + UPB_PRIVATE(_upb_Array_Set) + (arr, arr->UPB_PRIVATE(size) - 1, &val, sizeof(val)); return true; } UPB_INLINE int32_t* google_protobuf_FileDescriptorProto_mutable_weak_dependency(google_protobuf_FileDescriptorProto* msg, size_t* size) { upb_MiniTableField field = {11, UPB_SIZE(36, 104), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetMutableArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (int32_t*)_upb_array_ptr(arr); } else { if (size) *size = 0; @@ -5054,10 +5069,12 @@ UPB_INLINE int32_t* google_protobuf_FileDescriptorProto_resize_weak_dependency(g UPB_INLINE bool google_protobuf_FileDescriptorProto_add_weak_dependency(google_protobuf_FileDescriptorProto* msg, int32_t val, upb_Arena* arena) { upb_MiniTableField field = {11, UPB_SIZE(36, 104), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); - if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { + if (!arr || !_upb_Array_ResizeUninitialized( + arr, arr->UPB_PRIVATE(size) + 1, arena)) { return false; } - UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &val, sizeof(val)); + UPB_PRIVATE(_upb_Array_Set) + (arr, arr->UPB_PRIVATE(size) - 1, &val, sizeof(val)); return true; } UPB_INLINE void google_protobuf_FileDescriptorProto_set_syntax(google_protobuf_FileDescriptorProto *msg, upb_StringView value) { @@ -5127,7 +5144,7 @@ UPB_INLINE const google_protobuf_FieldDescriptorProto* const* google_protobuf_De const upb_MiniTableField field = {2, UPB_SIZE(4, 24), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_FieldDescriptorProto* const*)_upb_array_constptr(arr); } else { if (size) *size = 0; @@ -5138,7 +5155,7 @@ UPB_INLINE const upb_Array* _google_protobuf_DescriptorProto_field_upb_array(con const upb_MiniTableField field = {2, UPB_SIZE(4, 24), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -5147,7 +5164,7 @@ UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_field_mutable_upb_array(c upb_Array* arr = upb_Message_GetOrCreateMutableArray( (upb_Message*)msg, &field, arena); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -5159,7 +5176,7 @@ UPB_INLINE const google_protobuf_DescriptorProto* const* google_protobuf_Descrip const upb_MiniTableField field = {3, UPB_SIZE(8, 32), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_DescriptorProto* const*)_upb_array_constptr(arr); } else { if (size) *size = 0; @@ -5170,7 +5187,7 @@ UPB_INLINE const upb_Array* _google_protobuf_DescriptorProto_nested_type_upb_arr const upb_MiniTableField field = {3, UPB_SIZE(8, 32), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -5179,7 +5196,7 @@ UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_nested_type_mutable_upb_a upb_Array* arr = upb_Message_GetOrCreateMutableArray( (upb_Message*)msg, &field, arena); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -5191,7 +5208,7 @@ UPB_INLINE const google_protobuf_EnumDescriptorProto* const* google_protobuf_Des const upb_MiniTableField field = {4, UPB_SIZE(12, 40), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_EnumDescriptorProto* const*)_upb_array_constptr(arr); } else { if (size) *size = 0; @@ -5202,7 +5219,7 @@ UPB_INLINE const upb_Array* _google_protobuf_DescriptorProto_enum_type_upb_array const upb_MiniTableField field = {4, UPB_SIZE(12, 40), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -5211,7 +5228,7 @@ UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_enum_type_mutable_upb_arr upb_Array* arr = upb_Message_GetOrCreateMutableArray( (upb_Message*)msg, &field, arena); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -5223,7 +5240,7 @@ UPB_INLINE const google_protobuf_DescriptorProto_ExtensionRange* const* google_p const upb_MiniTableField field = {5, UPB_SIZE(16, 48), 0, 3, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_DescriptorProto_ExtensionRange* const*)_upb_array_constptr(arr); } else { if (size) *size = 0; @@ -5234,7 +5251,7 @@ UPB_INLINE const upb_Array* _google_protobuf_DescriptorProto_extension_range_upb const upb_MiniTableField field = {5, UPB_SIZE(16, 48), 0, 3, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -5243,7 +5260,7 @@ UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_extension_range_mutable_u upb_Array* arr = upb_Message_GetOrCreateMutableArray( (upb_Message*)msg, &field, arena); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -5255,7 +5272,7 @@ UPB_INLINE const google_protobuf_FieldDescriptorProto* const* google_protobuf_De const upb_MiniTableField field = {6, UPB_SIZE(20, 56), 0, 4, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_FieldDescriptorProto* const*)_upb_array_constptr(arr); } else { if (size) *size = 0; @@ -5266,7 +5283,7 @@ UPB_INLINE const upb_Array* _google_protobuf_DescriptorProto_extension_upb_array const upb_MiniTableField field = {6, UPB_SIZE(20, 56), 0, 4, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -5275,7 +5292,7 @@ UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_extension_mutable_upb_arr upb_Array* arr = upb_Message_GetOrCreateMutableArray( (upb_Message*)msg, &field, arena); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -5302,7 +5319,7 @@ UPB_INLINE const google_protobuf_OneofDescriptorProto* const* google_protobuf_De const upb_MiniTableField field = {8, UPB_SIZE(28, 72), 0, 6, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_OneofDescriptorProto* const*)_upb_array_constptr(arr); } else { if (size) *size = 0; @@ -5313,7 +5330,7 @@ UPB_INLINE const upb_Array* _google_protobuf_DescriptorProto_oneof_decl_upb_arra const upb_MiniTableField field = {8, UPB_SIZE(28, 72), 0, 6, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -5322,7 +5339,7 @@ UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_oneof_decl_mutable_upb_ar upb_Array* arr = upb_Message_GetOrCreateMutableArray( (upb_Message*)msg, &field, arena); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -5334,7 +5351,7 @@ UPB_INLINE const google_protobuf_DescriptorProto_ReservedRange* const* google_pr const upb_MiniTableField field = {9, UPB_SIZE(32, 80), 0, 7, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_DescriptorProto_ReservedRange* const*)_upb_array_constptr(arr); } else { if (size) *size = 0; @@ -5345,7 +5362,7 @@ UPB_INLINE const upb_Array* _google_protobuf_DescriptorProto_reserved_range_upb_ const upb_MiniTableField field = {9, UPB_SIZE(32, 80), 0, 7, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -5354,7 +5371,7 @@ UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_reserved_range_mutable_up upb_Array* arr = upb_Message_GetOrCreateMutableArray( (upb_Message*)msg, &field, arena); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -5366,7 +5383,7 @@ UPB_INLINE upb_StringView const* google_protobuf_DescriptorProto_reserved_name(c const upb_MiniTableField field = {10, UPB_SIZE(36, 88), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (upb_StringView const*)_upb_array_constptr(arr); } else { if (size) *size = 0; @@ -5377,7 +5394,7 @@ UPB_INLINE const upb_Array* _google_protobuf_DescriptorProto_reserved_name_upb_a const upb_MiniTableField field = {10, UPB_SIZE(36, 88), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -5386,7 +5403,7 @@ UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_reserved_name_mutable_upb upb_Array* arr = upb_Message_GetOrCreateMutableArray( (upb_Message*)msg, &field, arena); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -5399,7 +5416,7 @@ UPB_INLINE google_protobuf_FieldDescriptorProto** google_protobuf_DescriptorProt upb_MiniTableField field = {2, UPB_SIZE(4, 24), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetMutableArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_FieldDescriptorProto**)_upb_array_ptr(arr); } else { if (size) *size = 0; @@ -5413,19 +5430,21 @@ UPB_INLINE google_protobuf_FieldDescriptorProto** google_protobuf_DescriptorProt UPB_INLINE struct google_protobuf_FieldDescriptorProto* google_protobuf_DescriptorProto_add_field(google_protobuf_DescriptorProto* msg, upb_Arena* arena) { upb_MiniTableField field = {2, UPB_SIZE(4, 24), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); - if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { + if (!arr || !_upb_Array_ResizeUninitialized( + arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; } struct google_protobuf_FieldDescriptorProto* sub = (struct google_protobuf_FieldDescriptorProto*)_upb_Message_New(&google__protobuf__FieldDescriptorProto_msg_init, arena); if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &sub, sizeof(sub)); + UPB_PRIVATE(_upb_Array_Set) + (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); return sub; } UPB_INLINE google_protobuf_DescriptorProto** google_protobuf_DescriptorProto_mutable_nested_type(google_protobuf_DescriptorProto* msg, size_t* size) { upb_MiniTableField field = {3, UPB_SIZE(8, 32), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetMutableArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_DescriptorProto**)_upb_array_ptr(arr); } else { if (size) *size = 0; @@ -5439,19 +5458,21 @@ UPB_INLINE google_protobuf_DescriptorProto** google_protobuf_DescriptorProto_res UPB_INLINE struct google_protobuf_DescriptorProto* google_protobuf_DescriptorProto_add_nested_type(google_protobuf_DescriptorProto* msg, upb_Arena* arena) { upb_MiniTableField field = {3, UPB_SIZE(8, 32), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); - if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { + if (!arr || !_upb_Array_ResizeUninitialized( + arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; } struct google_protobuf_DescriptorProto* sub = (struct google_protobuf_DescriptorProto*)_upb_Message_New(&google__protobuf__DescriptorProto_msg_init, arena); if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &sub, sizeof(sub)); + UPB_PRIVATE(_upb_Array_Set) + (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); return sub; } UPB_INLINE google_protobuf_EnumDescriptorProto** google_protobuf_DescriptorProto_mutable_enum_type(google_protobuf_DescriptorProto* msg, size_t* size) { upb_MiniTableField field = {4, UPB_SIZE(12, 40), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetMutableArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_EnumDescriptorProto**)_upb_array_ptr(arr); } else { if (size) *size = 0; @@ -5465,19 +5486,21 @@ UPB_INLINE google_protobuf_EnumDescriptorProto** google_protobuf_DescriptorProto UPB_INLINE struct google_protobuf_EnumDescriptorProto* google_protobuf_DescriptorProto_add_enum_type(google_protobuf_DescriptorProto* msg, upb_Arena* arena) { upb_MiniTableField field = {4, UPB_SIZE(12, 40), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); - if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { + if (!arr || !_upb_Array_ResizeUninitialized( + arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; } struct google_protobuf_EnumDescriptorProto* sub = (struct google_protobuf_EnumDescriptorProto*)_upb_Message_New(&google__protobuf__EnumDescriptorProto_msg_init, arena); if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &sub, sizeof(sub)); + UPB_PRIVATE(_upb_Array_Set) + (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); return sub; } UPB_INLINE google_protobuf_DescriptorProto_ExtensionRange** google_protobuf_DescriptorProto_mutable_extension_range(google_protobuf_DescriptorProto* msg, size_t* size) { upb_MiniTableField field = {5, UPB_SIZE(16, 48), 0, 3, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetMutableArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_DescriptorProto_ExtensionRange**)_upb_array_ptr(arr); } else { if (size) *size = 0; @@ -5491,19 +5514,21 @@ UPB_INLINE google_protobuf_DescriptorProto_ExtensionRange** google_protobuf_Desc UPB_INLINE struct google_protobuf_DescriptorProto_ExtensionRange* google_protobuf_DescriptorProto_add_extension_range(google_protobuf_DescriptorProto* msg, upb_Arena* arena) { upb_MiniTableField field = {5, UPB_SIZE(16, 48), 0, 3, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); - if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { + if (!arr || !_upb_Array_ResizeUninitialized( + arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; } struct google_protobuf_DescriptorProto_ExtensionRange* sub = (struct google_protobuf_DescriptorProto_ExtensionRange*)_upb_Message_New(&google__protobuf__DescriptorProto__ExtensionRange_msg_init, arena); if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &sub, sizeof(sub)); + UPB_PRIVATE(_upb_Array_Set) + (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); return sub; } UPB_INLINE google_protobuf_FieldDescriptorProto** google_protobuf_DescriptorProto_mutable_extension(google_protobuf_DescriptorProto* msg, size_t* size) { upb_MiniTableField field = {6, UPB_SIZE(20, 56), 0, 4, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetMutableArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_FieldDescriptorProto**)_upb_array_ptr(arr); } else { if (size) *size = 0; @@ -5517,12 +5542,14 @@ UPB_INLINE google_protobuf_FieldDescriptorProto** google_protobuf_DescriptorProt UPB_INLINE struct google_protobuf_FieldDescriptorProto* google_protobuf_DescriptorProto_add_extension(google_protobuf_DescriptorProto* msg, upb_Arena* arena) { upb_MiniTableField field = {6, UPB_SIZE(20, 56), 0, 4, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); - if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { + if (!arr || !_upb_Array_ResizeUninitialized( + arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; } struct google_protobuf_FieldDescriptorProto* sub = (struct google_protobuf_FieldDescriptorProto*)_upb_Message_New(&google__protobuf__FieldDescriptorProto_msg_init, arena); if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &sub, sizeof(sub)); + UPB_PRIVATE(_upb_Array_Set) + (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); return sub; } UPB_INLINE void google_protobuf_DescriptorProto_set_options(google_protobuf_DescriptorProto *msg, google_protobuf_MessageOptions* value) { @@ -5541,7 +5568,7 @@ UPB_INLINE google_protobuf_OneofDescriptorProto** google_protobuf_DescriptorProt upb_MiniTableField field = {8, UPB_SIZE(28, 72), 0, 6, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetMutableArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_OneofDescriptorProto**)_upb_array_ptr(arr); } else { if (size) *size = 0; @@ -5555,19 +5582,21 @@ UPB_INLINE google_protobuf_OneofDescriptorProto** google_protobuf_DescriptorProt UPB_INLINE struct google_protobuf_OneofDescriptorProto* google_protobuf_DescriptorProto_add_oneof_decl(google_protobuf_DescriptorProto* msg, upb_Arena* arena) { upb_MiniTableField field = {8, UPB_SIZE(28, 72), 0, 6, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); - if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { + if (!arr || !_upb_Array_ResizeUninitialized( + arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; } struct google_protobuf_OneofDescriptorProto* sub = (struct google_protobuf_OneofDescriptorProto*)_upb_Message_New(&google__protobuf__OneofDescriptorProto_msg_init, arena); if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &sub, sizeof(sub)); + UPB_PRIVATE(_upb_Array_Set) + (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); return sub; } UPB_INLINE google_protobuf_DescriptorProto_ReservedRange** google_protobuf_DescriptorProto_mutable_reserved_range(google_protobuf_DescriptorProto* msg, size_t* size) { upb_MiniTableField field = {9, UPB_SIZE(32, 80), 0, 7, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetMutableArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_DescriptorProto_ReservedRange**)_upb_array_ptr(arr); } else { if (size) *size = 0; @@ -5581,19 +5610,21 @@ UPB_INLINE google_protobuf_DescriptorProto_ReservedRange** google_protobuf_Descr UPB_INLINE struct google_protobuf_DescriptorProto_ReservedRange* google_protobuf_DescriptorProto_add_reserved_range(google_protobuf_DescriptorProto* msg, upb_Arena* arena) { upb_MiniTableField field = {9, UPB_SIZE(32, 80), 0, 7, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); - if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { + if (!arr || !_upb_Array_ResizeUninitialized( + arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; } struct google_protobuf_DescriptorProto_ReservedRange* sub = (struct google_protobuf_DescriptorProto_ReservedRange*)_upb_Message_New(&google__protobuf__DescriptorProto__ReservedRange_msg_init, arena); if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &sub, sizeof(sub)); + UPB_PRIVATE(_upb_Array_Set) + (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); return sub; } UPB_INLINE upb_StringView* google_protobuf_DescriptorProto_mutable_reserved_name(google_protobuf_DescriptorProto* msg, size_t* size) { upb_MiniTableField field = {10, UPB_SIZE(36, 88), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetMutableArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (upb_StringView*)_upb_array_ptr(arr); } else { if (size) *size = 0; @@ -5607,10 +5638,12 @@ UPB_INLINE upb_StringView* google_protobuf_DescriptorProto_resize_reserved_name( UPB_INLINE bool google_protobuf_DescriptorProto_add_reserved_name(google_protobuf_DescriptorProto* msg, upb_StringView val, upb_Arena* arena) { upb_MiniTableField field = {10, UPB_SIZE(36, 88), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); - if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { + if (!arr || !_upb_Array_ResizeUninitialized( + arr, arr->UPB_PRIVATE(size) + 1, arena)) { return false; } - UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &val, sizeof(val)); + UPB_PRIVATE(_upb_Array_Set) + (arr, arr->UPB_PRIVATE(size) - 1, &val, sizeof(val)); return true; } @@ -5834,7 +5867,7 @@ UPB_INLINE const google_protobuf_ExtensionRangeOptions_Declaration* const* googl const upb_MiniTableField field = {2, UPB_SIZE(4, 8), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_ExtensionRangeOptions_Declaration* const*)_upb_array_constptr(arr); } else { if (size) *size = 0; @@ -5845,7 +5878,7 @@ UPB_INLINE const upb_Array* _google_protobuf_ExtensionRangeOptions_declaration_u const upb_MiniTableField field = {2, UPB_SIZE(4, 8), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -5854,7 +5887,7 @@ UPB_INLINE upb_Array* _google_protobuf_ExtensionRangeOptions_declaration_mutable upb_Array* arr = upb_Message_GetOrCreateMutableArray( (upb_Message*)msg, &field, arena); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -5896,7 +5929,7 @@ UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_Ext const upb_MiniTableField field = {999, UPB_SIZE(16, 24), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_UninterpretedOption* const*)_upb_array_constptr(arr); } else { if (size) *size = 0; @@ -5907,7 +5940,7 @@ UPB_INLINE const upb_Array* _google_protobuf_ExtensionRangeOptions_uninterpreted const upb_MiniTableField field = {999, UPB_SIZE(16, 24), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -5916,7 +5949,7 @@ UPB_INLINE upb_Array* _google_protobuf_ExtensionRangeOptions_uninterpreted_optio upb_Array* arr = upb_Message_GetOrCreateMutableArray( (upb_Message*)msg, &field, arena); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -5925,7 +5958,7 @@ UPB_INLINE google_protobuf_ExtensionRangeOptions_Declaration** google_protobuf_E upb_MiniTableField field = {2, UPB_SIZE(4, 8), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetMutableArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_ExtensionRangeOptions_Declaration**)_upb_array_ptr(arr); } else { if (size) *size = 0; @@ -5939,12 +5972,14 @@ UPB_INLINE google_protobuf_ExtensionRangeOptions_Declaration** google_protobuf_E UPB_INLINE struct google_protobuf_ExtensionRangeOptions_Declaration* google_protobuf_ExtensionRangeOptions_add_declaration(google_protobuf_ExtensionRangeOptions* msg, upb_Arena* arena) { upb_MiniTableField field = {2, UPB_SIZE(4, 8), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); - if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { + if (!arr || !_upb_Array_ResizeUninitialized( + arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; } struct google_protobuf_ExtensionRangeOptions_Declaration* sub = (struct google_protobuf_ExtensionRangeOptions_Declaration*)_upb_Message_New(&google__protobuf__ExtensionRangeOptions__Declaration_msg_init, arena); if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &sub, sizeof(sub)); + UPB_PRIVATE(_upb_Array_Set) + (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); return sub; } UPB_INLINE void google_protobuf_ExtensionRangeOptions_set_verification(google_protobuf_ExtensionRangeOptions *msg, int32_t value) { @@ -5967,7 +6002,7 @@ UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_ExtensionRangeO upb_MiniTableField field = {999, UPB_SIZE(16, 24), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetMutableArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_UninterpretedOption**)_upb_array_ptr(arr); } else { if (size) *size = 0; @@ -5981,12 +6016,14 @@ UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_ExtensionRangeO UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_ExtensionRangeOptions_add_uninterpreted_option(google_protobuf_ExtensionRangeOptions* msg, upb_Arena* arena) { upb_MiniTableField field = {999, UPB_SIZE(16, 24), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); - if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { + if (!arr || !_upb_Array_ResizeUninitialized( + arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; } struct google_protobuf_UninterpretedOption* sub = (struct google_protobuf_UninterpretedOption*)_upb_Message_New(&google__protobuf__UninterpretedOption_msg_init, arena); if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &sub, sizeof(sub)); + UPB_PRIVATE(_upb_Array_Set) + (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); return sub; } @@ -6517,7 +6554,7 @@ UPB_INLINE const google_protobuf_EnumValueDescriptorProto* const* google_protobu const upb_MiniTableField field = {2, UPB_SIZE(4, 24), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_EnumValueDescriptorProto* const*)_upb_array_constptr(arr); } else { if (size) *size = 0; @@ -6528,7 +6565,7 @@ UPB_INLINE const upb_Array* _google_protobuf_EnumDescriptorProto_value_upb_array const upb_MiniTableField field = {2, UPB_SIZE(4, 24), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -6537,7 +6574,7 @@ UPB_INLINE upb_Array* _google_protobuf_EnumDescriptorProto_value_mutable_upb_arr upb_Array* arr = upb_Message_GetOrCreateMutableArray( (upb_Message*)msg, &field, arena); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -6564,7 +6601,7 @@ UPB_INLINE const google_protobuf_EnumDescriptorProto_EnumReservedRange* const* g const upb_MiniTableField field = {4, UPB_SIZE(12, 40), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_EnumDescriptorProto_EnumReservedRange* const*)_upb_array_constptr(arr); } else { if (size) *size = 0; @@ -6575,7 +6612,7 @@ UPB_INLINE const upb_Array* _google_protobuf_EnumDescriptorProto_reserved_range_ const upb_MiniTableField field = {4, UPB_SIZE(12, 40), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -6584,7 +6621,7 @@ UPB_INLINE upb_Array* _google_protobuf_EnumDescriptorProto_reserved_range_mutabl upb_Array* arr = upb_Message_GetOrCreateMutableArray( (upb_Message*)msg, &field, arena); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -6596,7 +6633,7 @@ UPB_INLINE upb_StringView const* google_protobuf_EnumDescriptorProto_reserved_na const upb_MiniTableField field = {5, UPB_SIZE(16, 48), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (upb_StringView const*)_upb_array_constptr(arr); } else { if (size) *size = 0; @@ -6607,7 +6644,7 @@ UPB_INLINE const upb_Array* _google_protobuf_EnumDescriptorProto_reserved_name_u const upb_MiniTableField field = {5, UPB_SIZE(16, 48), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -6616,7 +6653,7 @@ UPB_INLINE upb_Array* _google_protobuf_EnumDescriptorProto_reserved_name_mutable upb_Array* arr = upb_Message_GetOrCreateMutableArray( (upb_Message*)msg, &field, arena); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -6629,7 +6666,7 @@ UPB_INLINE google_protobuf_EnumValueDescriptorProto** google_protobuf_EnumDescri upb_MiniTableField field = {2, UPB_SIZE(4, 24), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetMutableArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_EnumValueDescriptorProto**)_upb_array_ptr(arr); } else { if (size) *size = 0; @@ -6643,12 +6680,14 @@ UPB_INLINE google_protobuf_EnumValueDescriptorProto** google_protobuf_EnumDescri UPB_INLINE struct google_protobuf_EnumValueDescriptorProto* google_protobuf_EnumDescriptorProto_add_value(google_protobuf_EnumDescriptorProto* msg, upb_Arena* arena) { upb_MiniTableField field = {2, UPB_SIZE(4, 24), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); - if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { + if (!arr || !_upb_Array_ResizeUninitialized( + arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; } struct google_protobuf_EnumValueDescriptorProto* sub = (struct google_protobuf_EnumValueDescriptorProto*)_upb_Message_New(&google__protobuf__EnumValueDescriptorProto_msg_init, arena); if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &sub, sizeof(sub)); + UPB_PRIVATE(_upb_Array_Set) + (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); return sub; } UPB_INLINE void google_protobuf_EnumDescriptorProto_set_options(google_protobuf_EnumDescriptorProto *msg, google_protobuf_EnumOptions* value) { @@ -6667,7 +6706,7 @@ UPB_INLINE google_protobuf_EnumDescriptorProto_EnumReservedRange** google_protob upb_MiniTableField field = {4, UPB_SIZE(12, 40), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetMutableArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_EnumDescriptorProto_EnumReservedRange**)_upb_array_ptr(arr); } else { if (size) *size = 0; @@ -6681,19 +6720,21 @@ UPB_INLINE google_protobuf_EnumDescriptorProto_EnumReservedRange** google_protob UPB_INLINE struct google_protobuf_EnumDescriptorProto_EnumReservedRange* google_protobuf_EnumDescriptorProto_add_reserved_range(google_protobuf_EnumDescriptorProto* msg, upb_Arena* arena) { upb_MiniTableField field = {4, UPB_SIZE(12, 40), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); - if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { + if (!arr || !_upb_Array_ResizeUninitialized( + arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; } struct google_protobuf_EnumDescriptorProto_EnumReservedRange* sub = (struct google_protobuf_EnumDescriptorProto_EnumReservedRange*)_upb_Message_New(&google__protobuf__EnumDescriptorProto__EnumReservedRange_msg_init, arena); if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &sub, sizeof(sub)); + UPB_PRIVATE(_upb_Array_Set) + (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); return sub; } UPB_INLINE upb_StringView* google_protobuf_EnumDescriptorProto_mutable_reserved_name(google_protobuf_EnumDescriptorProto* msg, size_t* size) { upb_MiniTableField field = {5, UPB_SIZE(16, 48), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetMutableArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (upb_StringView*)_upb_array_ptr(arr); } else { if (size) *size = 0; @@ -6707,10 +6748,12 @@ UPB_INLINE upb_StringView* google_protobuf_EnumDescriptorProto_resize_reserved_n UPB_INLINE bool google_protobuf_EnumDescriptorProto_add_reserved_name(google_protobuf_EnumDescriptorProto* msg, upb_StringView val, upb_Arena* arena) { upb_MiniTableField field = {5, UPB_SIZE(16, 48), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); - if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { + if (!arr || !_upb_Array_ResizeUninitialized( + arr, arr->UPB_PRIVATE(size) + 1, arena)) { return false; } - UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &val, sizeof(val)); + UPB_PRIVATE(_upb_Array_Set) + (arr, arr->UPB_PRIVATE(size) - 1, &val, sizeof(val)); return true; } @@ -6949,7 +6992,7 @@ UPB_INLINE const google_protobuf_MethodDescriptorProto* const* google_protobuf_S const upb_MiniTableField field = {2, UPB_SIZE(4, 24), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_MethodDescriptorProto* const*)_upb_array_constptr(arr); } else { if (size) *size = 0; @@ -6960,7 +7003,7 @@ UPB_INLINE const upb_Array* _google_protobuf_ServiceDescriptorProto_method_upb_a const upb_MiniTableField field = {2, UPB_SIZE(4, 24), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -6969,7 +7012,7 @@ UPB_INLINE upb_Array* _google_protobuf_ServiceDescriptorProto_method_mutable_upb upb_Array* arr = upb_Message_GetOrCreateMutableArray( (upb_Message*)msg, &field, arena); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -6997,7 +7040,7 @@ UPB_INLINE google_protobuf_MethodDescriptorProto** google_protobuf_ServiceDescri upb_MiniTableField field = {2, UPB_SIZE(4, 24), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetMutableArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_MethodDescriptorProto**)_upb_array_ptr(arr); } else { if (size) *size = 0; @@ -7011,12 +7054,14 @@ UPB_INLINE google_protobuf_MethodDescriptorProto** google_protobuf_ServiceDescri UPB_INLINE struct google_protobuf_MethodDescriptorProto* google_protobuf_ServiceDescriptorProto_add_method(google_protobuf_ServiceDescriptorProto* msg, upb_Arena* arena) { upb_MiniTableField field = {2, UPB_SIZE(4, 24), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); - if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { + if (!arr || !_upb_Array_ResizeUninitialized( + arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; } struct google_protobuf_MethodDescriptorProto* sub = (struct google_protobuf_MethodDescriptorProto*)_upb_Message_New(&google__protobuf__MethodDescriptorProto_msg_init, arena); if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &sub, sizeof(sub)); + UPB_PRIVATE(_upb_Array_Set) + (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); return sub; } UPB_INLINE void google_protobuf_ServiceDescriptorProto_set_options(google_protobuf_ServiceDescriptorProto *msg, google_protobuf_ServiceOptions* value) { @@ -7549,7 +7594,7 @@ UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_Fil const upb_MiniTableField field = {999, UPB_SIZE(24, 192), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_UninterpretedOption* const*)_upb_array_constptr(arr); } else { if (size) *size = 0; @@ -7560,7 +7605,7 @@ UPB_INLINE const upb_Array* _google_protobuf_FileOptions_uninterpreted_option_up const upb_MiniTableField field = {999, UPB_SIZE(24, 192), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -7569,7 +7614,7 @@ UPB_INLINE upb_Array* _google_protobuf_FileOptions_uninterpreted_option_mutable_ upb_Array* arr = upb_Message_GetOrCreateMutableArray( (upb_Message*)msg, &field, arena); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -7670,7 +7715,7 @@ UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_FileOptions_mut upb_MiniTableField field = {999, UPB_SIZE(24, 192), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetMutableArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_UninterpretedOption**)_upb_array_ptr(arr); } else { if (size) *size = 0; @@ -7684,12 +7729,14 @@ UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_FileOptions_res UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_FileOptions_add_uninterpreted_option(google_protobuf_FileOptions* msg, upb_Arena* arena) { upb_MiniTableField field = {999, UPB_SIZE(24, 192), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); - if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { + if (!arr || !_upb_Array_ResizeUninitialized( + arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; } struct google_protobuf_UninterpretedOption* sub = (struct google_protobuf_UninterpretedOption*)_upb_Message_New(&google__protobuf__UninterpretedOption_msg_init, arena); if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &sub, sizeof(sub)); + UPB_PRIVATE(_upb_Array_Set) + (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); return sub; } @@ -7826,7 +7873,7 @@ UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_Mes const upb_MiniTableField field = {999, UPB_SIZE(12, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_UninterpretedOption* const*)_upb_array_constptr(arr); } else { if (size) *size = 0; @@ -7837,7 +7884,7 @@ UPB_INLINE const upb_Array* _google_protobuf_MessageOptions_uninterpreted_option const upb_MiniTableField field = {999, UPB_SIZE(12, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -7846,7 +7893,7 @@ UPB_INLINE upb_Array* _google_protobuf_MessageOptions_uninterpreted_option_mutab upb_Array* arr = upb_Message_GetOrCreateMutableArray( (upb_Message*)msg, &field, arena); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -7887,7 +7934,7 @@ UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_MessageOptions_ upb_MiniTableField field = {999, UPB_SIZE(12, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetMutableArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_UninterpretedOption**)_upb_array_ptr(arr); } else { if (size) *size = 0; @@ -7901,12 +7948,14 @@ UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_MessageOptions_ UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_MessageOptions_add_uninterpreted_option(google_protobuf_MessageOptions* msg, upb_Arena* arena) { upb_MiniTableField field = {999, UPB_SIZE(12, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); - if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { + if (!arr || !_upb_Array_ResizeUninitialized( + arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; } struct google_protobuf_UninterpretedOption* sub = (struct google_protobuf_UninterpretedOption*)_upb_Message_New(&google__protobuf__UninterpretedOption_msg_init, arena); if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &sub, sizeof(sub)); + UPB_PRIVATE(_upb_Array_Set) + (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); return sub; } @@ -8088,7 +8137,7 @@ UPB_INLINE int32_t const* google_protobuf_FieldOptions_targets(const google_prot const upb_MiniTableField field = {19, 24, 0, 6, 14, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (int32_t const*)_upb_array_constptr(arr); } else { if (size) *size = 0; @@ -8099,7 +8148,7 @@ UPB_INLINE const upb_Array* _google_protobuf_FieldOptions_targets_upb_array(cons const upb_MiniTableField field = {19, 24, 0, 6, 14, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -8108,7 +8157,7 @@ UPB_INLINE upb_Array* _google_protobuf_FieldOptions_targets_mutable_upb_array(co upb_Array* arr = upb_Message_GetOrCreateMutableArray( (upb_Message*)msg, &field, arena); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -8120,7 +8169,7 @@ UPB_INLINE const google_protobuf_FieldOptions_EditionDefault* const* google_prot const upb_MiniTableField field = {20, UPB_SIZE(28, 32), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_FieldOptions_EditionDefault* const*)_upb_array_constptr(arr); } else { if (size) *size = 0; @@ -8131,7 +8180,7 @@ UPB_INLINE const upb_Array* _google_protobuf_FieldOptions_edition_defaults_upb_a const upb_MiniTableField field = {20, UPB_SIZE(28, 32), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -8140,7 +8189,7 @@ UPB_INLINE upb_Array* _google_protobuf_FieldOptions_edition_defaults_mutable_upb upb_Array* arr = upb_Message_GetOrCreateMutableArray( (upb_Message*)msg, &field, arena); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -8167,7 +8216,7 @@ UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_Fie const upb_MiniTableField field = {999, UPB_SIZE(36, 48), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_UninterpretedOption* const*)_upb_array_constptr(arr); } else { if (size) *size = 0; @@ -8178,7 +8227,7 @@ UPB_INLINE const upb_Array* _google_protobuf_FieldOptions_uninterpreted_option_u const upb_MiniTableField field = {999, UPB_SIZE(36, 48), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -8187,7 +8236,7 @@ UPB_INLINE upb_Array* _google_protobuf_FieldOptions_uninterpreted_option_mutable upb_Array* arr = upb_Message_GetOrCreateMutableArray( (upb_Message*)msg, &field, arena); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -8232,7 +8281,7 @@ UPB_INLINE int32_t* google_protobuf_FieldOptions_mutable_targets(google_protobuf upb_MiniTableField field = {19, 24, 0, 6, 14, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetMutableArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (int32_t*)_upb_array_ptr(arr); } else { if (size) *size = 0; @@ -8246,17 +8295,19 @@ UPB_INLINE int32_t* google_protobuf_FieldOptions_resize_targets(google_protobuf_ UPB_INLINE bool google_protobuf_FieldOptions_add_targets(google_protobuf_FieldOptions* msg, int32_t val, upb_Arena* arena) { upb_MiniTableField field = {19, 24, 0, 6, 14, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); - if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { + if (!arr || !_upb_Array_ResizeUninitialized( + arr, arr->UPB_PRIVATE(size) + 1, arena)) { return false; } - UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &val, sizeof(val)); + UPB_PRIVATE(_upb_Array_Set) + (arr, arr->UPB_PRIVATE(size) - 1, &val, sizeof(val)); return true; } UPB_INLINE google_protobuf_FieldOptions_EditionDefault** google_protobuf_FieldOptions_mutable_edition_defaults(google_protobuf_FieldOptions* msg, size_t* size) { upb_MiniTableField field = {20, UPB_SIZE(28, 32), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetMutableArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_FieldOptions_EditionDefault**)_upb_array_ptr(arr); } else { if (size) *size = 0; @@ -8270,12 +8321,14 @@ UPB_INLINE google_protobuf_FieldOptions_EditionDefault** google_protobuf_FieldOp UPB_INLINE struct google_protobuf_FieldOptions_EditionDefault* google_protobuf_FieldOptions_add_edition_defaults(google_protobuf_FieldOptions* msg, upb_Arena* arena) { upb_MiniTableField field = {20, UPB_SIZE(28, 32), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); - if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { + if (!arr || !_upb_Array_ResizeUninitialized( + arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; } struct google_protobuf_FieldOptions_EditionDefault* sub = (struct google_protobuf_FieldOptions_EditionDefault*)_upb_Message_New(&google__protobuf__FieldOptions__EditionDefault_msg_init, arena); if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &sub, sizeof(sub)); + UPB_PRIVATE(_upb_Array_Set) + (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); return sub; } UPB_INLINE void google_protobuf_FieldOptions_set_features(google_protobuf_FieldOptions *msg, google_protobuf_FeatureSet* value) { @@ -8294,7 +8347,7 @@ UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_FieldOptions_mu upb_MiniTableField field = {999, UPB_SIZE(36, 48), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetMutableArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_UninterpretedOption**)_upb_array_ptr(arr); } else { if (size) *size = 0; @@ -8308,12 +8361,14 @@ UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_FieldOptions_re UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_FieldOptions_add_uninterpreted_option(google_protobuf_FieldOptions* msg, upb_Arena* arena) { upb_MiniTableField field = {999, UPB_SIZE(36, 48), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); - if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { + if (!arr || !_upb_Array_ResizeUninitialized( + arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; } struct google_protobuf_UninterpretedOption* sub = (struct google_protobuf_UninterpretedOption*)_upb_Message_New(&google__protobuf__UninterpretedOption_msg_init, arena); if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &sub, sizeof(sub)); + UPB_PRIVATE(_upb_Array_Set) + (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); return sub; } @@ -8450,7 +8505,7 @@ UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_One const upb_MiniTableField field = {999, UPB_SIZE(8, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_UninterpretedOption* const*)_upb_array_constptr(arr); } else { if (size) *size = 0; @@ -8461,7 +8516,7 @@ UPB_INLINE const upb_Array* _google_protobuf_OneofOptions_uninterpreted_option_u const upb_MiniTableField field = {999, UPB_SIZE(8, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -8470,7 +8525,7 @@ UPB_INLINE upb_Array* _google_protobuf_OneofOptions_uninterpreted_option_mutable upb_Array* arr = upb_Message_GetOrCreateMutableArray( (upb_Message*)msg, &field, arena); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -8491,7 +8546,7 @@ UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_OneofOptions_mu upb_MiniTableField field = {999, UPB_SIZE(8, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetMutableArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_UninterpretedOption**)_upb_array_ptr(arr); } else { if (size) *size = 0; @@ -8505,12 +8560,14 @@ UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_OneofOptions_re UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_OneofOptions_add_uninterpreted_option(google_protobuf_OneofOptions* msg, upb_Arena* arena) { upb_MiniTableField field = {999, UPB_SIZE(8, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); - if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { + if (!arr || !_upb_Array_ResizeUninitialized( + arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; } struct google_protobuf_UninterpretedOption* sub = (struct google_protobuf_UninterpretedOption*)_upb_Message_New(&google__protobuf__UninterpretedOption_msg_init, arena); if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &sub, sizeof(sub)); + UPB_PRIVATE(_upb_Array_Set) + (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); return sub; } @@ -8617,7 +8674,7 @@ UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_Enu const upb_MiniTableField field = {999, UPB_SIZE(8, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_UninterpretedOption* const*)_upb_array_constptr(arr); } else { if (size) *size = 0; @@ -8628,7 +8685,7 @@ UPB_INLINE const upb_Array* _google_protobuf_EnumOptions_uninterpreted_option_up const upb_MiniTableField field = {999, UPB_SIZE(8, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -8637,7 +8694,7 @@ UPB_INLINE upb_Array* _google_protobuf_EnumOptions_uninterpreted_option_mutable_ upb_Array* arr = upb_Message_GetOrCreateMutableArray( (upb_Message*)msg, &field, arena); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -8670,7 +8727,7 @@ UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_EnumOptions_mut upb_MiniTableField field = {999, UPB_SIZE(8, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetMutableArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_UninterpretedOption**)_upb_array_ptr(arr); } else { if (size) *size = 0; @@ -8684,12 +8741,14 @@ UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_EnumOptions_res UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_EnumOptions_add_uninterpreted_option(google_protobuf_EnumOptions* msg, upb_Arena* arena) { upb_MiniTableField field = {999, UPB_SIZE(8, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); - if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { + if (!arr || !_upb_Array_ResizeUninitialized( + arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; } struct google_protobuf_UninterpretedOption* sub = (struct google_protobuf_UninterpretedOption*)_upb_Message_New(&google__protobuf__UninterpretedOption_msg_init, arena); if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &sub, sizeof(sub)); + UPB_PRIVATE(_upb_Array_Set) + (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); return sub; } @@ -8781,7 +8840,7 @@ UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_Enu const upb_MiniTableField field = {999, UPB_SIZE(12, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_UninterpretedOption* const*)_upb_array_constptr(arr); } else { if (size) *size = 0; @@ -8792,7 +8851,7 @@ UPB_INLINE const upb_Array* _google_protobuf_EnumValueOptions_uninterpreted_opti const upb_MiniTableField field = {999, UPB_SIZE(12, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -8801,7 +8860,7 @@ UPB_INLINE upb_Array* _google_protobuf_EnumValueOptions_uninterpreted_option_mut upb_Array* arr = upb_Message_GetOrCreateMutableArray( (upb_Message*)msg, &field, arena); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -8830,7 +8889,7 @@ UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_EnumValueOption upb_MiniTableField field = {999, UPB_SIZE(12, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetMutableArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_UninterpretedOption**)_upb_array_ptr(arr); } else { if (size) *size = 0; @@ -8844,12 +8903,14 @@ UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_EnumValueOption UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_EnumValueOptions_add_uninterpreted_option(google_protobuf_EnumValueOptions* msg, upb_Arena* arena) { upb_MiniTableField field = {999, UPB_SIZE(12, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); - if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { + if (!arr || !_upb_Array_ResizeUninitialized( + arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; } struct google_protobuf_UninterpretedOption* sub = (struct google_protobuf_UninterpretedOption*)_upb_Message_New(&google__protobuf__UninterpretedOption_msg_init, arena); if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &sub, sizeof(sub)); + UPB_PRIVATE(_upb_Array_Set) + (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); return sub; } @@ -8926,7 +8987,7 @@ UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_Ser const upb_MiniTableField field = {999, UPB_SIZE(8, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_UninterpretedOption* const*)_upb_array_constptr(arr); } else { if (size) *size = 0; @@ -8937,7 +8998,7 @@ UPB_INLINE const upb_Array* _google_protobuf_ServiceOptions_uninterpreted_option const upb_MiniTableField field = {999, UPB_SIZE(8, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -8946,7 +9007,7 @@ UPB_INLINE upb_Array* _google_protobuf_ServiceOptions_uninterpreted_option_mutab upb_Array* arr = upb_Message_GetOrCreateMutableArray( (upb_Message*)msg, &field, arena); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -8971,7 +9032,7 @@ UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_ServiceOptions_ upb_MiniTableField field = {999, UPB_SIZE(8, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetMutableArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_UninterpretedOption**)_upb_array_ptr(arr); } else { if (size) *size = 0; @@ -8985,12 +9046,14 @@ UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_ServiceOptions_ UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_ServiceOptions_add_uninterpreted_option(google_protobuf_ServiceOptions* msg, upb_Arena* arena) { upb_MiniTableField field = {999, UPB_SIZE(8, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); - if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { + if (!arr || !_upb_Array_ResizeUninitialized( + arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; } struct google_protobuf_UninterpretedOption* sub = (struct google_protobuf_UninterpretedOption*)_upb_Message_New(&google__protobuf__UninterpretedOption_msg_init, arena); if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &sub, sizeof(sub)); + UPB_PRIVATE(_upb_Array_Set) + (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); return sub; } @@ -9082,7 +9145,7 @@ UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_Met const upb_MiniTableField field = {999, UPB_SIZE(12, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_UninterpretedOption* const*)_upb_array_constptr(arr); } else { if (size) *size = 0; @@ -9093,7 +9156,7 @@ UPB_INLINE const upb_Array* _google_protobuf_MethodOptions_uninterpreted_option_ const upb_MiniTableField field = {999, UPB_SIZE(12, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -9102,7 +9165,7 @@ UPB_INLINE upb_Array* _google_protobuf_MethodOptions_uninterpreted_option_mutabl upb_Array* arr = upb_Message_GetOrCreateMutableArray( (upb_Message*)msg, &field, arena); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -9131,7 +9194,7 @@ UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_MethodOptions_m upb_MiniTableField field = {999, UPB_SIZE(12, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetMutableArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_UninterpretedOption**)_upb_array_ptr(arr); } else { if (size) *size = 0; @@ -9145,12 +9208,14 @@ UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_MethodOptions_r UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_MethodOptions_add_uninterpreted_option(google_protobuf_MethodOptions* msg, upb_Arena* arena) { upb_MiniTableField field = {999, UPB_SIZE(12, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); - if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { + if (!arr || !_upb_Array_ResizeUninitialized( + arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; } struct google_protobuf_UninterpretedOption* sub = (struct google_protobuf_UninterpretedOption*)_upb_Message_New(&google__protobuf__UninterpretedOption_msg_init, arena); if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &sub, sizeof(sub)); + UPB_PRIVATE(_upb_Array_Set) + (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); return sub; } @@ -9197,7 +9262,7 @@ UPB_INLINE const google_protobuf_UninterpretedOption_NamePart* const* google_pro const upb_MiniTableField field = {2, UPB_SIZE(4, 8), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_UninterpretedOption_NamePart* const*)_upb_array_constptr(arr); } else { if (size) *size = 0; @@ -9208,7 +9273,7 @@ UPB_INLINE const upb_Array* _google_protobuf_UninterpretedOption_name_upb_array( const upb_MiniTableField field = {2, UPB_SIZE(4, 8), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -9217,7 +9282,7 @@ UPB_INLINE upb_Array* _google_protobuf_UninterpretedOption_name_mutable_upb_arra upb_Array* arr = upb_Message_GetOrCreateMutableArray( (upb_Message*)msg, &field, arena); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -9316,7 +9381,7 @@ UPB_INLINE google_protobuf_UninterpretedOption_NamePart** google_protobuf_Uninte upb_MiniTableField field = {2, UPB_SIZE(4, 8), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetMutableArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_UninterpretedOption_NamePart**)_upb_array_ptr(arr); } else { if (size) *size = 0; @@ -9330,12 +9395,14 @@ UPB_INLINE google_protobuf_UninterpretedOption_NamePart** google_protobuf_Uninte UPB_INLINE struct google_protobuf_UninterpretedOption_NamePart* google_protobuf_UninterpretedOption_add_name(google_protobuf_UninterpretedOption* msg, upb_Arena* arena) { upb_MiniTableField field = {2, UPB_SIZE(4, 8), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); - if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { + if (!arr || !_upb_Array_ResizeUninitialized( + arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; } struct google_protobuf_UninterpretedOption_NamePart* sub = (struct google_protobuf_UninterpretedOption_NamePart*)_upb_Message_New(&google__protobuf__UninterpretedOption__NamePart_msg_init, arena); if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &sub, sizeof(sub)); + UPB_PRIVATE(_upb_Array_Set) + (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); return sub; } UPB_INLINE void google_protobuf_UninterpretedOption_set_identifier_value(google_protobuf_UninterpretedOption *msg, upb_StringView value) { @@ -9632,7 +9699,7 @@ UPB_INLINE const google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* co const upb_MiniTableField field = {1, UPB_SIZE(4, 16), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* const*)_upb_array_constptr(arr); } else { if (size) *size = 0; @@ -9643,7 +9710,7 @@ UPB_INLINE const upb_Array* _google_protobuf_FeatureSetDefaults_defaults_upb_arr const upb_MiniTableField field = {1, UPB_SIZE(4, 16), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -9652,7 +9719,7 @@ UPB_INLINE upb_Array* _google_protobuf_FeatureSetDefaults_defaults_mutable_upb_a upb_Array* arr = upb_Message_GetOrCreateMutableArray( (upb_Message*)msg, &field, arena); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -9691,7 +9758,7 @@ UPB_INLINE google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault** google_ upb_MiniTableField field = {1, UPB_SIZE(4, 16), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetMutableArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault**)_upb_array_ptr(arr); } else { if (size) *size = 0; @@ -9705,12 +9772,14 @@ UPB_INLINE google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault** google_ UPB_INLINE struct google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* google_protobuf_FeatureSetDefaults_add_defaults(google_protobuf_FeatureSetDefaults* msg, upb_Arena* arena) { upb_MiniTableField field = {1, UPB_SIZE(4, 16), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); - if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { + if (!arr || !_upb_Array_ResizeUninitialized( + arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; } struct google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* sub = (struct google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault*)_upb_Message_New(&google__protobuf__FeatureSetDefaults__FeatureSetEditionDefault_msg_init, arena); if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &sub, sizeof(sub)); + UPB_PRIVATE(_upb_Array_Set) + (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); return sub; } UPB_INLINE void google_protobuf_FeatureSetDefaults_set_minimum_edition(google_protobuf_FeatureSetDefaults *msg, int32_t value) { @@ -9848,7 +9917,7 @@ UPB_INLINE const google_protobuf_SourceCodeInfo_Location* const* google_protobuf const upb_MiniTableField field = {1, 0, 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_SourceCodeInfo_Location* const*)_upb_array_constptr(arr); } else { if (size) *size = 0; @@ -9859,7 +9928,7 @@ UPB_INLINE const upb_Array* _google_protobuf_SourceCodeInfo_location_upb_array(c const upb_MiniTableField field = {1, 0, 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -9868,7 +9937,7 @@ UPB_INLINE upb_Array* _google_protobuf_SourceCodeInfo_location_mutable_upb_array upb_Array* arr = upb_Message_GetOrCreateMutableArray( (upb_Message*)msg, &field, arena); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -9877,7 +9946,7 @@ UPB_INLINE google_protobuf_SourceCodeInfo_Location** google_protobuf_SourceCodeI upb_MiniTableField field = {1, 0, 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetMutableArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_SourceCodeInfo_Location**)_upb_array_ptr(arr); } else { if (size) *size = 0; @@ -9891,12 +9960,14 @@ UPB_INLINE google_protobuf_SourceCodeInfo_Location** google_protobuf_SourceCodeI UPB_INLINE struct google_protobuf_SourceCodeInfo_Location* google_protobuf_SourceCodeInfo_add_location(google_protobuf_SourceCodeInfo* msg, upb_Arena* arena) { upb_MiniTableField field = {1, 0, 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); - if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { + if (!arr || !_upb_Array_ResizeUninitialized( + arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; } struct google_protobuf_SourceCodeInfo_Location* sub = (struct google_protobuf_SourceCodeInfo_Location*)_upb_Message_New(&google__protobuf__SourceCodeInfo__Location_msg_init, arena); if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &sub, sizeof(sub)); + UPB_PRIVATE(_upb_Array_Set) + (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); return sub; } @@ -9943,7 +10014,7 @@ UPB_INLINE int32_t const* google_protobuf_SourceCodeInfo_Location_path(const goo const upb_MiniTableField field = {1, UPB_SIZE(4, 8), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsPacked | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (int32_t const*)_upb_array_constptr(arr); } else { if (size) *size = 0; @@ -9954,7 +10025,7 @@ UPB_INLINE const upb_Array* _google_protobuf_SourceCodeInfo_Location_path_upb_ar const upb_MiniTableField field = {1, UPB_SIZE(4, 8), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsPacked | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -9963,7 +10034,7 @@ UPB_INLINE upb_Array* _google_protobuf_SourceCodeInfo_Location_path_mutable_upb_ upb_Array* arr = upb_Message_GetOrCreateMutableArray( (upb_Message*)msg, &field, arena); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -9975,7 +10046,7 @@ UPB_INLINE int32_t const* google_protobuf_SourceCodeInfo_Location_span(const goo const upb_MiniTableField field = {2, UPB_SIZE(8, 16), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsPacked | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (int32_t const*)_upb_array_constptr(arr); } else { if (size) *size = 0; @@ -9986,7 +10057,7 @@ UPB_INLINE const upb_Array* _google_protobuf_SourceCodeInfo_Location_span_upb_ar const upb_MiniTableField field = {2, UPB_SIZE(8, 16), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsPacked | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -9995,7 +10066,7 @@ UPB_INLINE upb_Array* _google_protobuf_SourceCodeInfo_Location_span_mutable_upb_ upb_Array* arr = upb_Message_GetOrCreateMutableArray( (upb_Message*)msg, &field, arena); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -10037,7 +10108,7 @@ UPB_INLINE upb_StringView const* google_protobuf_SourceCodeInfo_Location_leading const upb_MiniTableField field = {6, UPB_SIZE(12, 56), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (upb_StringView const*)_upb_array_constptr(arr); } else { if (size) *size = 0; @@ -10048,7 +10119,7 @@ UPB_INLINE const upb_Array* _google_protobuf_SourceCodeInfo_Location_leading_det const upb_MiniTableField field = {6, UPB_SIZE(12, 56), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -10057,7 +10128,7 @@ UPB_INLINE upb_Array* _google_protobuf_SourceCodeInfo_Location_leading_detached_ upb_Array* arr = upb_Message_GetOrCreateMutableArray( (upb_Message*)msg, &field, arena); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -10066,7 +10137,7 @@ UPB_INLINE int32_t* google_protobuf_SourceCodeInfo_Location_mutable_path(google_ upb_MiniTableField field = {1, UPB_SIZE(4, 8), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsPacked | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetMutableArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (int32_t*)_upb_array_ptr(arr); } else { if (size) *size = 0; @@ -10080,17 +10151,19 @@ UPB_INLINE int32_t* google_protobuf_SourceCodeInfo_Location_resize_path(google_p UPB_INLINE bool google_protobuf_SourceCodeInfo_Location_add_path(google_protobuf_SourceCodeInfo_Location* msg, int32_t val, upb_Arena* arena) { upb_MiniTableField field = {1, UPB_SIZE(4, 8), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsPacked | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); - if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { + if (!arr || !_upb_Array_ResizeUninitialized( + arr, arr->UPB_PRIVATE(size) + 1, arena)) { return false; } - UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &val, sizeof(val)); + UPB_PRIVATE(_upb_Array_Set) + (arr, arr->UPB_PRIVATE(size) - 1, &val, sizeof(val)); return true; } UPB_INLINE int32_t* google_protobuf_SourceCodeInfo_Location_mutable_span(google_protobuf_SourceCodeInfo_Location* msg, size_t* size) { upb_MiniTableField field = {2, UPB_SIZE(8, 16), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsPacked | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetMutableArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (int32_t*)_upb_array_ptr(arr); } else { if (size) *size = 0; @@ -10104,10 +10177,12 @@ UPB_INLINE int32_t* google_protobuf_SourceCodeInfo_Location_resize_span(google_p UPB_INLINE bool google_protobuf_SourceCodeInfo_Location_add_span(google_protobuf_SourceCodeInfo_Location* msg, int32_t val, upb_Arena* arena) { upb_MiniTableField field = {2, UPB_SIZE(8, 16), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsPacked | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); - if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { + if (!arr || !_upb_Array_ResizeUninitialized( + arr, arr->UPB_PRIVATE(size) + 1, arena)) { return false; } - UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &val, sizeof(val)); + UPB_PRIVATE(_upb_Array_Set) + (arr, arr->UPB_PRIVATE(size) - 1, &val, sizeof(val)); return true; } UPB_INLINE void google_protobuf_SourceCodeInfo_Location_set_leading_comments(google_protobuf_SourceCodeInfo_Location *msg, upb_StringView value) { @@ -10122,7 +10197,7 @@ UPB_INLINE upb_StringView* google_protobuf_SourceCodeInfo_Location_mutable_leadi upb_MiniTableField field = {6, UPB_SIZE(12, 56), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetMutableArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (upb_StringView*)_upb_array_ptr(arr); } else { if (size) *size = 0; @@ -10136,10 +10211,12 @@ UPB_INLINE upb_StringView* google_protobuf_SourceCodeInfo_Location_resize_leadin UPB_INLINE bool google_protobuf_SourceCodeInfo_Location_add_leading_detached_comments(google_protobuf_SourceCodeInfo_Location* msg, upb_StringView val, upb_Arena* arena) { upb_MiniTableField field = {6, UPB_SIZE(12, 56), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); - if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { + if (!arr || !_upb_Array_ResizeUninitialized( + arr, arr->UPB_PRIVATE(size) + 1, arena)) { return false; } - UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &val, sizeof(val)); + UPB_PRIVATE(_upb_Array_Set) + (arr, arr->UPB_PRIVATE(size) - 1, &val, sizeof(val)); return true; } @@ -10186,7 +10263,7 @@ UPB_INLINE const google_protobuf_GeneratedCodeInfo_Annotation* const* google_pro const upb_MiniTableField field = {1, 0, 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_GeneratedCodeInfo_Annotation* const*)_upb_array_constptr(arr); } else { if (size) *size = 0; @@ -10197,7 +10274,7 @@ UPB_INLINE const upb_Array* _google_protobuf_GeneratedCodeInfo_annotation_upb_ar const upb_MiniTableField field = {1, 0, 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -10206,7 +10283,7 @@ UPB_INLINE upb_Array* _google_protobuf_GeneratedCodeInfo_annotation_mutable_upb_ upb_Array* arr = upb_Message_GetOrCreateMutableArray( (upb_Message*)msg, &field, arena); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -10215,7 +10292,7 @@ UPB_INLINE google_protobuf_GeneratedCodeInfo_Annotation** google_protobuf_Genera upb_MiniTableField field = {1, 0, 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetMutableArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_GeneratedCodeInfo_Annotation**)_upb_array_ptr(arr); } else { if (size) *size = 0; @@ -10229,12 +10306,14 @@ UPB_INLINE google_protobuf_GeneratedCodeInfo_Annotation** google_protobuf_Genera UPB_INLINE struct google_protobuf_GeneratedCodeInfo_Annotation* google_protobuf_GeneratedCodeInfo_add_annotation(google_protobuf_GeneratedCodeInfo* msg, upb_Arena* arena) { upb_MiniTableField field = {1, 0, 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); - if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { + if (!arr || !_upb_Array_ResizeUninitialized( + arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; } struct google_protobuf_GeneratedCodeInfo_Annotation* sub = (struct google_protobuf_GeneratedCodeInfo_Annotation*)_upb_Message_New(&google__protobuf__GeneratedCodeInfo__Annotation_msg_init, arena); if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &sub, sizeof(sub)); + UPB_PRIVATE(_upb_Array_Set) + (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); return sub; } @@ -10281,7 +10360,7 @@ UPB_INLINE int32_t const* google_protobuf_GeneratedCodeInfo_Annotation_path(cons const upb_MiniTableField field = {1, UPB_SIZE(4, 16), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsPacked | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (int32_t const*)_upb_array_constptr(arr); } else { if (size) *size = 0; @@ -10292,7 +10371,7 @@ UPB_INLINE const upb_Array* _google_protobuf_GeneratedCodeInfo_Annotation_path_u const upb_MiniTableField field = {1, UPB_SIZE(4, 16), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsPacked | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -10301,7 +10380,7 @@ UPB_INLINE upb_Array* _google_protobuf_GeneratedCodeInfo_Annotation_path_mutable upb_Array* arr = upb_Message_GetOrCreateMutableArray( (upb_Message*)msg, &field, arena); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -10370,7 +10449,7 @@ UPB_INLINE int32_t* google_protobuf_GeneratedCodeInfo_Annotation_mutable_path(go upb_MiniTableField field = {1, UPB_SIZE(4, 16), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsPacked | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetMutableArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (int32_t*)_upb_array_ptr(arr); } else { if (size) *size = 0; @@ -10384,10 +10463,12 @@ UPB_INLINE int32_t* google_protobuf_GeneratedCodeInfo_Annotation_resize_path(goo UPB_INLINE bool google_protobuf_GeneratedCodeInfo_Annotation_add_path(google_protobuf_GeneratedCodeInfo_Annotation* msg, int32_t val, upb_Arena* arena) { upb_MiniTableField field = {1, UPB_SIZE(4, 16), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsPacked | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); - if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { + if (!arr || !_upb_Array_ResizeUninitialized( + arr, arr->UPB_PRIVATE(size) + 1, arena)) { return false; } - UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &val, sizeof(val)); + UPB_PRIVATE(_upb_Array_Set) + (arr, arr->UPB_PRIVATE(size) - 1, &val, sizeof(val)); return true; } UPB_INLINE void google_protobuf_GeneratedCodeInfo_Annotation_set_source_file(google_protobuf_GeneratedCodeInfo_Annotation *msg, upb_StringView value) { diff --git a/ruby/ext/google/protobuf_c/ruby-upb.c b/ruby/ext/google/protobuf_c/ruby-upb.c index af198bf1964ad..6d5de37d6b84c 100644 --- a/ruby/ext/google/protobuf_c/ruby-upb.c +++ b/ruby/ext/google/protobuf_c/ruby-upb.c @@ -5630,7 +5630,7 @@ static upb_Map* upb_Message_Map_DeepClone(const upb_Map* map, upb_Array* upb_Array_DeepClone(const upb_Array* array, upb_CType value_type, const upb_MiniTable* sub, upb_Arena* arena) { - size_t size = array->size; + size_t size = array->UPB_PRIVATE(size); upb_Array* cloned_array = UPB_PRIVATE(_upb_Array_New)(arena, size, upb_CType_SizeLg2(value_type)); if (!cloned_array) { @@ -5830,13 +5830,13 @@ const void* upb_Array_DataPtr(const upb_Array* arr) { void* upb_Array_MutableDataPtr(upb_Array* arr) { return _upb_array_ptr(arr); } -size_t upb_Array_Size(const upb_Array* arr) { return arr->size; } +size_t upb_Array_Size(const upb_Array* arr) { return arr->UPB_PRIVATE(size); } upb_MessageValue upb_Array_Get(const upb_Array* arr, size_t i) { upb_MessageValue ret; const char* data = _upb_array_constptr(arr); const int lg2 = UPB_PRIVATE(_upb_Array_ElemSizeLg2)(arr); - UPB_ASSERT(i < arr->size); + UPB_ASSERT(i < arr->UPB_PRIVATE(size)); memcpy(&ret, data + (i << lg2), 1 << lg2); return ret; } @@ -5844,16 +5844,16 @@ upb_MessageValue upb_Array_Get(const upb_Array* arr, size_t i) { void upb_Array_Set(upb_Array* arr, size_t i, upb_MessageValue val) { char* data = _upb_array_ptr(arr); const int lg2 = UPB_PRIVATE(_upb_Array_ElemSizeLg2)(arr); - UPB_ASSERT(i < arr->size); + UPB_ASSERT(i < arr->UPB_PRIVATE(size)); memcpy(data + (i << lg2), &val, 1 << lg2); } bool upb_Array_Append(upb_Array* arr, upb_MessageValue val, upb_Arena* arena) { UPB_ASSERT(arena); - if (!_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { + if (!_upb_Array_ResizeUninitialized(arr, arr->UPB_PRIVATE(size) + 1, arena)) { return false; } - upb_Array_Set(arr, arr->size - 1, val); + upb_Array_Set(arr, arr->UPB_PRIVATE(size) - 1, val); return true; } @@ -5867,10 +5867,11 @@ void upb_Array_Move(upb_Array* arr, size_t dst_idx, size_t src_idx, bool upb_Array_Insert(upb_Array* arr, size_t i, size_t count, upb_Arena* arena) { UPB_ASSERT(arena); - UPB_ASSERT(i <= arr->size); - UPB_ASSERT(count + arr->size >= count); - const size_t oldsize = arr->size; - if (!_upb_Array_ResizeUninitialized(arr, arr->size + count, arena)) { + UPB_ASSERT(i <= arr->UPB_PRIVATE(size)); + UPB_ASSERT(count + arr->UPB_PRIVATE(size) >= count); + const size_t oldsize = arr->UPB_PRIVATE(size); + if (!_upb_Array_ResizeUninitialized(arr, arr->UPB_PRIVATE(size) + count, + arena)) { return false; } upb_Array_Move(arr, i + count, i, oldsize - i); @@ -5884,17 +5885,17 @@ bool upb_Array_Insert(upb_Array* arr, size_t i, size_t count, void upb_Array_Delete(upb_Array* arr, size_t i, size_t count) { const size_t end = i + count; UPB_ASSERT(i <= end); - UPB_ASSERT(end <= arr->size); - upb_Array_Move(arr, i, end, arr->size - end); - arr->size -= count; + UPB_ASSERT(end <= arr->UPB_PRIVATE(size)); + upb_Array_Move(arr, i, end, arr->UPB_PRIVATE(size) - end); + arr->UPB_PRIVATE(size) -= count; } bool upb_Array_Resize(upb_Array* arr, size_t size, upb_Arena* arena) { - const size_t oldsize = arr->size; + const size_t oldsize = arr->UPB_PRIVATE(size); if (UPB_UNLIKELY(!_upb_Array_ResizeUninitialized(arr, size, arena))) { return false; } - const size_t newsize = arr->size; + const size_t newsize = arr->UPB_PRIVATE(size); if (newsize > oldsize) { const int lg2 = UPB_PRIVATE(_upb_Array_ElemSizeLg2)(arr); char* data = _upb_array_ptr(arr); @@ -12317,9 +12318,10 @@ static void _upb_Decoder_VerifyUtf8(upb_Decoder* d, const char* buf, int len) { } static bool _upb_Decoder_Reserve(upb_Decoder* d, upb_Array* arr, size_t elem) { - bool need_realloc = arr->UPB_PRIVATE(capacity) - arr->size < elem; - if (need_realloc && - !UPB_PRIVATE(_upb_Array_Realloc)(arr, arr->size + elem, &d->arena)) { + bool need_realloc = + arr->UPB_PRIVATE(capacity) - arr->UPB_PRIVATE(size) < elem; + if (need_realloc && !UPB_PRIVATE(_upb_Array_Realloc)( + arr, arr->UPB_PRIVATE(size) + elem, &d->arena)) { _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_OutOfMemory); } return need_realloc; @@ -12593,8 +12595,8 @@ static const char* _upb_Decoder_DecodeEnumArray(upb_Decoder* d, const char* ptr, wireval* val) { const upb_MiniTableEnum* e = _upb_MiniTableSubs_EnumByField(subs, field); if (!_upb_Decoder_CheckEnum(d, ptr, msg, e, field, val)) return ptr; - void* mem = UPB_PTR_AT(_upb_array_ptr(arr), arr->size * 4, void); - arr->size++; + void* mem = UPB_PTR_AT(_upb_array_ptr(arr), arr->UPB_PRIVATE(size) * 4, void); + arr->UPB_PRIVATE(size)++; memcpy(mem, val, 4); return ptr; } @@ -12610,8 +12612,9 @@ static const char* _upb_Decoder_DecodeFixedPacked( _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_Malformed); } _upb_Decoder_Reserve(d, arr, count); - void* mem = UPB_PTR_AT(_upb_array_ptr(arr), arr->size << lg2, void); - arr->size += count; + void* mem = + UPB_PTR_AT(_upb_array_ptr(arr), arr->UPB_PRIVATE(size) << lg2, void); + arr->UPB_PRIVATE(size) += count; // Note: if/when the decoder supports multi-buffer input, we will need to // handle buffer seams here. if (_upb_IsLittleEndian()) { @@ -12641,15 +12644,17 @@ static const char* _upb_Decoder_DecodeVarintPacked( const upb_MiniTableField* field, int lg2) { int scale = 1 << lg2; int saved_limit = upb_EpsCopyInputStream_PushLimit(&d->input, ptr, val->size); - char* out = UPB_PTR_AT(_upb_array_ptr(arr), arr->size << lg2, void); + char* out = + UPB_PTR_AT(_upb_array_ptr(arr), arr->UPB_PRIVATE(size) << lg2, void); while (!_upb_Decoder_IsDone(d, &ptr)) { wireval elem; ptr = _upb_Decoder_DecodeVarint(d, ptr, &elem.uint64_val); _upb_Decoder_Munge(field->UPB_PRIVATE(descriptortype), &elem); if (_upb_Decoder_Reserve(d, arr, 1)) { - out = UPB_PTR_AT(_upb_array_ptr(arr), arr->size << lg2, void); + out = + UPB_PTR_AT(_upb_array_ptr(arr), arr->UPB_PRIVATE(size) << lg2, void); } - arr->size++; + arr->UPB_PRIVATE(size)++; memcpy(out, &elem, scale); out += scale; } @@ -12664,7 +12669,7 @@ static const char* _upb_Decoder_DecodeEnumPacked( wireval* val) { const upb_MiniTableEnum* e = _upb_MiniTableSubs_EnumByField(subs, field); int saved_limit = upb_EpsCopyInputStream_PushLimit(&d->input, ptr, val->size); - char* out = UPB_PTR_AT(_upb_array_ptr(arr), arr->size * 4, void); + char* out = UPB_PTR_AT(_upb_array_ptr(arr), arr->UPB_PRIVATE(size) * 4, void); while (!_upb_Decoder_IsDone(d, &ptr)) { wireval elem; ptr = _upb_Decoder_DecodeVarint(d, ptr, &elem.uint64_val); @@ -12673,9 +12678,9 @@ static const char* _upb_Decoder_DecodeEnumPacked( continue; } if (_upb_Decoder_Reserve(d, arr, 1)) { - out = UPB_PTR_AT(_upb_array_ptr(arr), arr->size * 4, void); + out = UPB_PTR_AT(_upb_array_ptr(arr), arr->UPB_PRIVATE(size) * 4, void); } - arr->size++; + arr->UPB_PRIVATE(size)++; memcpy(out, &elem, 4); out += 4; } @@ -12713,8 +12718,8 @@ static const char* _upb_Decoder_DecodeToArray(upb_Decoder* d, const char* ptr, case kUpb_DecodeOp_Scalar4Byte: case kUpb_DecodeOp_Scalar8Byte: /* Append scalar value. */ - mem = UPB_PTR_AT(_upb_array_ptr(arr), arr->size << op, void); - arr->size++; + mem = UPB_PTR_AT(_upb_array_ptr(arr), arr->UPB_PRIVATE(size) << op, void); + arr->UPB_PRIVATE(size)++; memcpy(mem, val, 1 << op); return ptr; case kUpb_DecodeOp_String: @@ -12722,16 +12727,18 @@ static const char* _upb_Decoder_DecodeToArray(upb_Decoder* d, const char* ptr, /* Fallthrough. */ case kUpb_DecodeOp_Bytes: { /* Append bytes. */ - upb_StringView* str = (upb_StringView*)_upb_array_ptr(arr) + arr->size; - arr->size++; + upb_StringView* str = + (upb_StringView*)_upb_array_ptr(arr) + arr->UPB_PRIVATE(size); + arr->UPB_PRIVATE(size)++; return _upb_Decoder_ReadString(d, ptr, val->size, str); } case kUpb_DecodeOp_SubMessage: { /* Append submessage / group. */ upb_TaggedMessagePtr* target = UPB_PTR_AT( - _upb_array_ptr(arr), arr->size * sizeof(void*), upb_TaggedMessagePtr); + _upb_array_ptr(arr), arr->UPB_PRIVATE(size) * sizeof(void*), + upb_TaggedMessagePtr); upb_Message* submsg = _upb_Decoder_NewSubMessage(d, subs, field, target); - arr->size++; + arr->UPB_PRIVATE(size)++; if (UPB_UNLIKELY(field->UPB_PRIVATE(descriptortype) == kUpb_FieldType_Group)) { return _upb_Decoder_DecodeKnownGroup(d, ptr, submsg, subs, field); @@ -13749,7 +13756,7 @@ static bool fastdecode_tagmatch(uint32_t tag, uint64_t data, int tagbytes) { UPB_FORCEINLINE static void fastdecode_commitarr(void* dst, fastdecode_arr* farr, int valbytes) { - farr->arr->size = + farr->arr->UPB_PRIVATE(size) = (size_t)((char*)dst - (char*)_upb_array_ptr(farr->arr)) / valbytes; } @@ -13820,7 +13827,7 @@ static void* fastdecode_getfield(upb_Decoder* d, const char* ptr, begin = _upb_array_ptr(farr->arr); farr->end = begin + (farr->arr->UPB_PRIVATE(capacity) * valbytes); *data = _upb_FastDecoder_LoadTag(ptr); - return begin + (farr->arr->size * valbytes); + return begin + (farr->arr->UPB_PRIVATE(size) * valbytes); } default: UPB_UNREACHABLE(); @@ -14108,7 +14115,7 @@ TAGBYTES(p) \ char* dst = _upb_array_ptr(arr); \ memcpy(dst, ptr, size); \ - arr->size = elems; \ + arr->UPB_PRIVATE(size) = elems; \ \ ptr += size; \ UPB_MUSTTAIL return fastdecode_dispatch(UPB_PARSE_ARGS); @@ -14706,7 +14713,7 @@ static void encode_tag(upb_encstate* e, uint32_t field_number, static void encode_fixedarray(upb_encstate* e, const upb_Array* arr, size_t elem_size, uint32_t tag) { - size_t bytes = arr->size * elem_size; + size_t bytes = arr->UPB_PRIVATE(size) * elem_size; const char* data = _upb_array_constptr(arr); const char* ptr = data + bytes - elem_size; @@ -14838,14 +14845,14 @@ static void encode_array(upb_encstate* e, const upb_Message* msg, bool packed = upb_MiniTableField_IsPacked(f); size_t pre_len = e->limit - e->ptr; - if (arr == NULL || arr->size == 0) { + if (arr == NULL || arr->UPB_PRIVATE(size) == 0) { return; } #define VARINT_CASE(ctype, encode) \ { \ const ctype* start = _upb_array_constptr(arr); \ - const ctype* ptr = start + arr->size; \ + const ctype* ptr = start + arr->UPB_PRIVATE(size); \ uint32_t tag = \ packed ? 0 : (f->UPB_PRIVATE(number) << 3) | kUpb_WireType_Varint; \ do { \ @@ -14890,7 +14897,7 @@ static void encode_array(upb_encstate* e, const upb_Message* msg, case kUpb_FieldType_String: case kUpb_FieldType_Bytes: { const upb_StringView* start = _upb_array_constptr(arr); - const upb_StringView* ptr = start + arr->size; + const upb_StringView* ptr = start + arr->UPB_PRIVATE(size); do { ptr--; encode_bytes(e, ptr->data, ptr->size); @@ -14901,7 +14908,7 @@ static void encode_array(upb_encstate* e, const upb_Message* msg, } case kUpb_FieldType_Group: { const upb_TaggedMessagePtr* start = _upb_array_constptr(arr); - const upb_TaggedMessagePtr* ptr = start + arr->size; + const upb_TaggedMessagePtr* ptr = start + arr->UPB_PRIVATE(size); const upb_MiniTable* subm = upb_MiniTableSub_Message(subs[f->UPB_PRIVATE(submsg_index)]); if (--e->depth == 0) encode_err(e, kUpb_EncodeStatus_MaxDepthExceeded); @@ -14917,7 +14924,7 @@ static void encode_array(upb_encstate* e, const upb_Message* msg, } case kUpb_FieldType_Message: { const upb_TaggedMessagePtr* start = _upb_array_constptr(arr); - const upb_TaggedMessagePtr* ptr = start + arr->size; + const upb_TaggedMessagePtr* ptr = start + arr->UPB_PRIVATE(size); const upb_MiniTable* subm = upb_MiniTableSub_Message(subs[f->UPB_PRIVATE(submsg_index)]); if (--e->depth == 0) encode_err(e, kUpb_EncodeStatus_MaxDepthExceeded); diff --git a/ruby/ext/google/protobuf_c/ruby-upb.h b/ruby/ext/google/protobuf_c/ruby-upb.h index 903a3eb49d69b..79a49a0c0336c 100755 --- a/ruby/ext/google/protobuf_c/ruby-upb.h +++ b/ruby/ext/google/protobuf_c/ruby-upb.h @@ -2800,7 +2800,7 @@ struct upb_Array { // Bit #2 contains the frozen/immutable flag (currently unimplemented). uintptr_t data; - size_t size; // The number of elements in the array. + size_t UPB_ONLYBITS(size); // The number of elements in the array. size_t UPB_PRIVATE(capacity); // Allocated storage. Measured in elements. }; @@ -2838,7 +2838,7 @@ UPB_INLINE upb_Array* UPB_PRIVATE(_upb_Array_New)(upb_Arena* arena, if (!array) return NULL; UPB_PRIVATE(_upb_Array_SetTaggedPtr) (array, UPB_PTR_AT(array, array_size, void), elem_size_lg2); - array->size = 0; + array->UPB_ONLYBITS(size) = 0; array->UPB_PRIVATE(capacity) = init_capacity; return array; } @@ -2857,9 +2857,10 @@ UPB_INLINE bool UPB_PRIVATE(_upb_Array_Reserve)(upb_Array* array, size_t size, // Resize without initializing new elements. UPB_INLINE bool _upb_Array_ResizeUninitialized(upb_Array* array, size_t size, upb_Arena* arena) { - UPB_ASSERT(size <= array->size || arena); // Allow NULL arena when shrinking. + UPB_ASSERT(size <= array->UPB_ONLYBITS(size) || + arena); // Allow NULL arena when shrinking. if (!UPB_PRIVATE(_upb_Array_Reserve)(array, size, arena)) return false; - array->size = size; + array->UPB_ONLYBITS(size) = size; return true; } @@ -2869,7 +2870,7 @@ UPB_INLINE bool _upb_Array_ResizeUninitialized(upb_Array* array, size_t size, UPB_INLINE void UPB_PRIVATE(_upb_Array_Set)(upb_Array* array, size_t i, const void* data, size_t elem_size) { - UPB_ASSERT(i < array->size); + UPB_ASSERT(i < array->UPB_ONLYBITS(size)); UPB_ASSERT(elem_size == 1U << UPB_PRIVATE(_upb_Array_ElemSizeLg2)(array)); char* arr_data = (char*)_upb_array_ptr(array); memcpy(arr_data + (i * elem_size), data, elem_size); @@ -4954,7 +4955,7 @@ UPB_INLINE const google_protobuf_FileDescriptorProto* const* google_protobuf_Fil const upb_MiniTableField field = {1, 0, 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_FileDescriptorProto* const*)_upb_array_constptr(arr); } else { if (size) *size = 0; @@ -4965,7 +4966,7 @@ UPB_INLINE const upb_Array* _google_protobuf_FileDescriptorSet_file_upb_array(co const upb_MiniTableField field = {1, 0, 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -4974,7 +4975,7 @@ UPB_INLINE upb_Array* _google_protobuf_FileDescriptorSet_file_mutable_upb_array( upb_Array* arr = upb_Message_GetOrCreateMutableArray( (upb_Message*)msg, &field, arena); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -4983,7 +4984,7 @@ UPB_INLINE google_protobuf_FileDescriptorProto** google_protobuf_FileDescriptorS upb_MiniTableField field = {1, 0, 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetMutableArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_FileDescriptorProto**)_upb_array_ptr(arr); } else { if (size) *size = 0; @@ -4997,12 +4998,14 @@ UPB_INLINE google_protobuf_FileDescriptorProto** google_protobuf_FileDescriptorS UPB_INLINE struct google_protobuf_FileDescriptorProto* google_protobuf_FileDescriptorSet_add_file(google_protobuf_FileDescriptorSet* msg, upb_Arena* arena) { upb_MiniTableField field = {1, 0, 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); - if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { + if (!arr || !_upb_Array_ResizeUninitialized( + arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; } struct google_protobuf_FileDescriptorProto* sub = (struct google_protobuf_FileDescriptorProto*)_upb_Message_New(&google__protobuf__FileDescriptorProto_msg_init, arena); if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &sub, sizeof(sub)); + UPB_PRIVATE(_upb_Array_Set) + (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); return sub; } @@ -5079,7 +5082,7 @@ UPB_INLINE upb_StringView const* google_protobuf_FileDescriptorProto_dependency( const upb_MiniTableField field = {3, UPB_SIZE(4, 40), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (upb_StringView const*)_upb_array_constptr(arr); } else { if (size) *size = 0; @@ -5090,7 +5093,7 @@ UPB_INLINE const upb_Array* _google_protobuf_FileDescriptorProto_dependency_upb_ const upb_MiniTableField field = {3, UPB_SIZE(4, 40), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -5099,7 +5102,7 @@ UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_dependency_mutable_up upb_Array* arr = upb_Message_GetOrCreateMutableArray( (upb_Message*)msg, &field, arena); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -5111,7 +5114,7 @@ UPB_INLINE const google_protobuf_DescriptorProto* const* google_protobuf_FileDes const upb_MiniTableField field = {4, UPB_SIZE(8, 48), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_DescriptorProto* const*)_upb_array_constptr(arr); } else { if (size) *size = 0; @@ -5122,7 +5125,7 @@ UPB_INLINE const upb_Array* _google_protobuf_FileDescriptorProto_message_type_up const upb_MiniTableField field = {4, UPB_SIZE(8, 48), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -5131,7 +5134,7 @@ UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_message_type_mutable_ upb_Array* arr = upb_Message_GetOrCreateMutableArray( (upb_Message*)msg, &field, arena); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -5143,7 +5146,7 @@ UPB_INLINE const google_protobuf_EnumDescriptorProto* const* google_protobuf_Fil const upb_MiniTableField field = {5, UPB_SIZE(12, 56), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_EnumDescriptorProto* const*)_upb_array_constptr(arr); } else { if (size) *size = 0; @@ -5154,7 +5157,7 @@ UPB_INLINE const upb_Array* _google_protobuf_FileDescriptorProto_enum_type_upb_a const upb_MiniTableField field = {5, UPB_SIZE(12, 56), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -5163,7 +5166,7 @@ UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_enum_type_mutable_upb upb_Array* arr = upb_Message_GetOrCreateMutableArray( (upb_Message*)msg, &field, arena); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -5175,7 +5178,7 @@ UPB_INLINE const google_protobuf_ServiceDescriptorProto* const* google_protobuf_ const upb_MiniTableField field = {6, UPB_SIZE(16, 64), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_ServiceDescriptorProto* const*)_upb_array_constptr(arr); } else { if (size) *size = 0; @@ -5186,7 +5189,7 @@ UPB_INLINE const upb_Array* _google_protobuf_FileDescriptorProto_service_upb_arr const upb_MiniTableField field = {6, UPB_SIZE(16, 64), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -5195,7 +5198,7 @@ UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_service_mutable_upb_a upb_Array* arr = upb_Message_GetOrCreateMutableArray( (upb_Message*)msg, &field, arena); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -5207,7 +5210,7 @@ UPB_INLINE const google_protobuf_FieldDescriptorProto* const* google_protobuf_Fi const upb_MiniTableField field = {7, UPB_SIZE(20, 72), 0, 3, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_FieldDescriptorProto* const*)_upb_array_constptr(arr); } else { if (size) *size = 0; @@ -5218,7 +5221,7 @@ UPB_INLINE const upb_Array* _google_protobuf_FileDescriptorProto_extension_upb_a const upb_MiniTableField field = {7, UPB_SIZE(20, 72), 0, 3, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -5227,7 +5230,7 @@ UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_extension_mutable_upb upb_Array* arr = upb_Message_GetOrCreateMutableArray( (upb_Message*)msg, &field, arena); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -5269,7 +5272,7 @@ UPB_INLINE int32_t const* google_protobuf_FileDescriptorProto_public_dependency( const upb_MiniTableField field = {10, UPB_SIZE(32, 96), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (int32_t const*)_upb_array_constptr(arr); } else { if (size) *size = 0; @@ -5280,7 +5283,7 @@ UPB_INLINE const upb_Array* _google_protobuf_FileDescriptorProto_public_dependen const upb_MiniTableField field = {10, UPB_SIZE(32, 96), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -5289,7 +5292,7 @@ UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_public_dependency_mut upb_Array* arr = upb_Message_GetOrCreateMutableArray( (upb_Message*)msg, &field, arena); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -5301,7 +5304,7 @@ UPB_INLINE int32_t const* google_protobuf_FileDescriptorProto_weak_dependency(co const upb_MiniTableField field = {11, UPB_SIZE(36, 104), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (int32_t const*)_upb_array_constptr(arr); } else { if (size) *size = 0; @@ -5312,7 +5315,7 @@ UPB_INLINE const upb_Array* _google_protobuf_FileDescriptorProto_weak_dependency const upb_MiniTableField field = {11, UPB_SIZE(36, 104), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -5321,7 +5324,7 @@ UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_weak_dependency_mutab upb_Array* arr = upb_Message_GetOrCreateMutableArray( (upb_Message*)msg, &field, arena); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -5368,7 +5371,7 @@ UPB_INLINE upb_StringView* google_protobuf_FileDescriptorProto_mutable_dependenc upb_MiniTableField field = {3, UPB_SIZE(4, 40), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetMutableArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (upb_StringView*)_upb_array_ptr(arr); } else { if (size) *size = 0; @@ -5382,17 +5385,19 @@ UPB_INLINE upb_StringView* google_protobuf_FileDescriptorProto_resize_dependency UPB_INLINE bool google_protobuf_FileDescriptorProto_add_dependency(google_protobuf_FileDescriptorProto* msg, upb_StringView val, upb_Arena* arena) { upb_MiniTableField field = {3, UPB_SIZE(4, 40), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); - if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { + if (!arr || !_upb_Array_ResizeUninitialized( + arr, arr->UPB_PRIVATE(size) + 1, arena)) { return false; } - UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &val, sizeof(val)); + UPB_PRIVATE(_upb_Array_Set) + (arr, arr->UPB_PRIVATE(size) - 1, &val, sizeof(val)); return true; } UPB_INLINE google_protobuf_DescriptorProto** google_protobuf_FileDescriptorProto_mutable_message_type(google_protobuf_FileDescriptorProto* msg, size_t* size) { upb_MiniTableField field = {4, UPB_SIZE(8, 48), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetMutableArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_DescriptorProto**)_upb_array_ptr(arr); } else { if (size) *size = 0; @@ -5406,19 +5411,21 @@ UPB_INLINE google_protobuf_DescriptorProto** google_protobuf_FileDescriptorProto UPB_INLINE struct google_protobuf_DescriptorProto* google_protobuf_FileDescriptorProto_add_message_type(google_protobuf_FileDescriptorProto* msg, upb_Arena* arena) { upb_MiniTableField field = {4, UPB_SIZE(8, 48), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); - if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { + if (!arr || !_upb_Array_ResizeUninitialized( + arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; } struct google_protobuf_DescriptorProto* sub = (struct google_protobuf_DescriptorProto*)_upb_Message_New(&google__protobuf__DescriptorProto_msg_init, arena); if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &sub, sizeof(sub)); + UPB_PRIVATE(_upb_Array_Set) + (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); return sub; } UPB_INLINE google_protobuf_EnumDescriptorProto** google_protobuf_FileDescriptorProto_mutable_enum_type(google_protobuf_FileDescriptorProto* msg, size_t* size) { upb_MiniTableField field = {5, UPB_SIZE(12, 56), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetMutableArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_EnumDescriptorProto**)_upb_array_ptr(arr); } else { if (size) *size = 0; @@ -5432,19 +5439,21 @@ UPB_INLINE google_protobuf_EnumDescriptorProto** google_protobuf_FileDescriptorP UPB_INLINE struct google_protobuf_EnumDescriptorProto* google_protobuf_FileDescriptorProto_add_enum_type(google_protobuf_FileDescriptorProto* msg, upb_Arena* arena) { upb_MiniTableField field = {5, UPB_SIZE(12, 56), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); - if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { + if (!arr || !_upb_Array_ResizeUninitialized( + arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; } struct google_protobuf_EnumDescriptorProto* sub = (struct google_protobuf_EnumDescriptorProto*)_upb_Message_New(&google__protobuf__EnumDescriptorProto_msg_init, arena); if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &sub, sizeof(sub)); + UPB_PRIVATE(_upb_Array_Set) + (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); return sub; } UPB_INLINE google_protobuf_ServiceDescriptorProto** google_protobuf_FileDescriptorProto_mutable_service(google_protobuf_FileDescriptorProto* msg, size_t* size) { upb_MiniTableField field = {6, UPB_SIZE(16, 64), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetMutableArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_ServiceDescriptorProto**)_upb_array_ptr(arr); } else { if (size) *size = 0; @@ -5458,19 +5467,21 @@ UPB_INLINE google_protobuf_ServiceDescriptorProto** google_protobuf_FileDescript UPB_INLINE struct google_protobuf_ServiceDescriptorProto* google_protobuf_FileDescriptorProto_add_service(google_protobuf_FileDescriptorProto* msg, upb_Arena* arena) { upb_MiniTableField field = {6, UPB_SIZE(16, 64), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); - if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { + if (!arr || !_upb_Array_ResizeUninitialized( + arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; } struct google_protobuf_ServiceDescriptorProto* sub = (struct google_protobuf_ServiceDescriptorProto*)_upb_Message_New(&google__protobuf__ServiceDescriptorProto_msg_init, arena); if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &sub, sizeof(sub)); + UPB_PRIVATE(_upb_Array_Set) + (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); return sub; } UPB_INLINE google_protobuf_FieldDescriptorProto** google_protobuf_FileDescriptorProto_mutable_extension(google_protobuf_FileDescriptorProto* msg, size_t* size) { upb_MiniTableField field = {7, UPB_SIZE(20, 72), 0, 3, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetMutableArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_FieldDescriptorProto**)_upb_array_ptr(arr); } else { if (size) *size = 0; @@ -5484,12 +5495,14 @@ UPB_INLINE google_protobuf_FieldDescriptorProto** google_protobuf_FileDescriptor UPB_INLINE struct google_protobuf_FieldDescriptorProto* google_protobuf_FileDescriptorProto_add_extension(google_protobuf_FileDescriptorProto* msg, upb_Arena* arena) { upb_MiniTableField field = {7, UPB_SIZE(20, 72), 0, 3, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); - if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { + if (!arr || !_upb_Array_ResizeUninitialized( + arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; } struct google_protobuf_FieldDescriptorProto* sub = (struct google_protobuf_FieldDescriptorProto*)_upb_Message_New(&google__protobuf__FieldDescriptorProto_msg_init, arena); if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &sub, sizeof(sub)); + UPB_PRIVATE(_upb_Array_Set) + (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); return sub; } UPB_INLINE void google_protobuf_FileDescriptorProto_set_options(google_protobuf_FileDescriptorProto *msg, google_protobuf_FileOptions* value) { @@ -5520,7 +5533,7 @@ UPB_INLINE int32_t* google_protobuf_FileDescriptorProto_mutable_public_dependenc upb_MiniTableField field = {10, UPB_SIZE(32, 96), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetMutableArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (int32_t*)_upb_array_ptr(arr); } else { if (size) *size = 0; @@ -5534,17 +5547,19 @@ UPB_INLINE int32_t* google_protobuf_FileDescriptorProto_resize_public_dependency UPB_INLINE bool google_protobuf_FileDescriptorProto_add_public_dependency(google_protobuf_FileDescriptorProto* msg, int32_t val, upb_Arena* arena) { upb_MiniTableField field = {10, UPB_SIZE(32, 96), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); - if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { + if (!arr || !_upb_Array_ResizeUninitialized( + arr, arr->UPB_PRIVATE(size) + 1, arena)) { return false; } - UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &val, sizeof(val)); + UPB_PRIVATE(_upb_Array_Set) + (arr, arr->UPB_PRIVATE(size) - 1, &val, sizeof(val)); return true; } UPB_INLINE int32_t* google_protobuf_FileDescriptorProto_mutable_weak_dependency(google_protobuf_FileDescriptorProto* msg, size_t* size) { upb_MiniTableField field = {11, UPB_SIZE(36, 104), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetMutableArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (int32_t*)_upb_array_ptr(arr); } else { if (size) *size = 0; @@ -5558,10 +5573,12 @@ UPB_INLINE int32_t* google_protobuf_FileDescriptorProto_resize_weak_dependency(g UPB_INLINE bool google_protobuf_FileDescriptorProto_add_weak_dependency(google_protobuf_FileDescriptorProto* msg, int32_t val, upb_Arena* arena) { upb_MiniTableField field = {11, UPB_SIZE(36, 104), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); - if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { + if (!arr || !_upb_Array_ResizeUninitialized( + arr, arr->UPB_PRIVATE(size) + 1, arena)) { return false; } - UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &val, sizeof(val)); + UPB_PRIVATE(_upb_Array_Set) + (arr, arr->UPB_PRIVATE(size) - 1, &val, sizeof(val)); return true; } UPB_INLINE void google_protobuf_FileDescriptorProto_set_syntax(google_protobuf_FileDescriptorProto *msg, upb_StringView value) { @@ -5631,7 +5648,7 @@ UPB_INLINE const google_protobuf_FieldDescriptorProto* const* google_protobuf_De const upb_MiniTableField field = {2, UPB_SIZE(4, 24), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_FieldDescriptorProto* const*)_upb_array_constptr(arr); } else { if (size) *size = 0; @@ -5642,7 +5659,7 @@ UPB_INLINE const upb_Array* _google_protobuf_DescriptorProto_field_upb_array(con const upb_MiniTableField field = {2, UPB_SIZE(4, 24), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -5651,7 +5668,7 @@ UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_field_mutable_upb_array(c upb_Array* arr = upb_Message_GetOrCreateMutableArray( (upb_Message*)msg, &field, arena); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -5663,7 +5680,7 @@ UPB_INLINE const google_protobuf_DescriptorProto* const* google_protobuf_Descrip const upb_MiniTableField field = {3, UPB_SIZE(8, 32), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_DescriptorProto* const*)_upb_array_constptr(arr); } else { if (size) *size = 0; @@ -5674,7 +5691,7 @@ UPB_INLINE const upb_Array* _google_protobuf_DescriptorProto_nested_type_upb_arr const upb_MiniTableField field = {3, UPB_SIZE(8, 32), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -5683,7 +5700,7 @@ UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_nested_type_mutable_upb_a upb_Array* arr = upb_Message_GetOrCreateMutableArray( (upb_Message*)msg, &field, arena); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -5695,7 +5712,7 @@ UPB_INLINE const google_protobuf_EnumDescriptorProto* const* google_protobuf_Des const upb_MiniTableField field = {4, UPB_SIZE(12, 40), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_EnumDescriptorProto* const*)_upb_array_constptr(arr); } else { if (size) *size = 0; @@ -5706,7 +5723,7 @@ UPB_INLINE const upb_Array* _google_protobuf_DescriptorProto_enum_type_upb_array const upb_MiniTableField field = {4, UPB_SIZE(12, 40), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -5715,7 +5732,7 @@ UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_enum_type_mutable_upb_arr upb_Array* arr = upb_Message_GetOrCreateMutableArray( (upb_Message*)msg, &field, arena); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -5727,7 +5744,7 @@ UPB_INLINE const google_protobuf_DescriptorProto_ExtensionRange* const* google_p const upb_MiniTableField field = {5, UPB_SIZE(16, 48), 0, 3, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_DescriptorProto_ExtensionRange* const*)_upb_array_constptr(arr); } else { if (size) *size = 0; @@ -5738,7 +5755,7 @@ UPB_INLINE const upb_Array* _google_protobuf_DescriptorProto_extension_range_upb const upb_MiniTableField field = {5, UPB_SIZE(16, 48), 0, 3, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -5747,7 +5764,7 @@ UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_extension_range_mutable_u upb_Array* arr = upb_Message_GetOrCreateMutableArray( (upb_Message*)msg, &field, arena); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -5759,7 +5776,7 @@ UPB_INLINE const google_protobuf_FieldDescriptorProto* const* google_protobuf_De const upb_MiniTableField field = {6, UPB_SIZE(20, 56), 0, 4, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_FieldDescriptorProto* const*)_upb_array_constptr(arr); } else { if (size) *size = 0; @@ -5770,7 +5787,7 @@ UPB_INLINE const upb_Array* _google_protobuf_DescriptorProto_extension_upb_array const upb_MiniTableField field = {6, UPB_SIZE(20, 56), 0, 4, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -5779,7 +5796,7 @@ UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_extension_mutable_upb_arr upb_Array* arr = upb_Message_GetOrCreateMutableArray( (upb_Message*)msg, &field, arena); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -5806,7 +5823,7 @@ UPB_INLINE const google_protobuf_OneofDescriptorProto* const* google_protobuf_De const upb_MiniTableField field = {8, UPB_SIZE(28, 72), 0, 6, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_OneofDescriptorProto* const*)_upb_array_constptr(arr); } else { if (size) *size = 0; @@ -5817,7 +5834,7 @@ UPB_INLINE const upb_Array* _google_protobuf_DescriptorProto_oneof_decl_upb_arra const upb_MiniTableField field = {8, UPB_SIZE(28, 72), 0, 6, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -5826,7 +5843,7 @@ UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_oneof_decl_mutable_upb_ar upb_Array* arr = upb_Message_GetOrCreateMutableArray( (upb_Message*)msg, &field, arena); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -5838,7 +5855,7 @@ UPB_INLINE const google_protobuf_DescriptorProto_ReservedRange* const* google_pr const upb_MiniTableField field = {9, UPB_SIZE(32, 80), 0, 7, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_DescriptorProto_ReservedRange* const*)_upb_array_constptr(arr); } else { if (size) *size = 0; @@ -5849,7 +5866,7 @@ UPB_INLINE const upb_Array* _google_protobuf_DescriptorProto_reserved_range_upb_ const upb_MiniTableField field = {9, UPB_SIZE(32, 80), 0, 7, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -5858,7 +5875,7 @@ UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_reserved_range_mutable_up upb_Array* arr = upb_Message_GetOrCreateMutableArray( (upb_Message*)msg, &field, arena); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -5870,7 +5887,7 @@ UPB_INLINE upb_StringView const* google_protobuf_DescriptorProto_reserved_name(c const upb_MiniTableField field = {10, UPB_SIZE(36, 88), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (upb_StringView const*)_upb_array_constptr(arr); } else { if (size) *size = 0; @@ -5881,7 +5898,7 @@ UPB_INLINE const upb_Array* _google_protobuf_DescriptorProto_reserved_name_upb_a const upb_MiniTableField field = {10, UPB_SIZE(36, 88), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -5890,7 +5907,7 @@ UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_reserved_name_mutable_upb upb_Array* arr = upb_Message_GetOrCreateMutableArray( (upb_Message*)msg, &field, arena); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -5903,7 +5920,7 @@ UPB_INLINE google_protobuf_FieldDescriptorProto** google_protobuf_DescriptorProt upb_MiniTableField field = {2, UPB_SIZE(4, 24), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetMutableArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_FieldDescriptorProto**)_upb_array_ptr(arr); } else { if (size) *size = 0; @@ -5917,19 +5934,21 @@ UPB_INLINE google_protobuf_FieldDescriptorProto** google_protobuf_DescriptorProt UPB_INLINE struct google_protobuf_FieldDescriptorProto* google_protobuf_DescriptorProto_add_field(google_protobuf_DescriptorProto* msg, upb_Arena* arena) { upb_MiniTableField field = {2, UPB_SIZE(4, 24), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); - if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { + if (!arr || !_upb_Array_ResizeUninitialized( + arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; } struct google_protobuf_FieldDescriptorProto* sub = (struct google_protobuf_FieldDescriptorProto*)_upb_Message_New(&google__protobuf__FieldDescriptorProto_msg_init, arena); if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &sub, sizeof(sub)); + UPB_PRIVATE(_upb_Array_Set) + (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); return sub; } UPB_INLINE google_protobuf_DescriptorProto** google_protobuf_DescriptorProto_mutable_nested_type(google_protobuf_DescriptorProto* msg, size_t* size) { upb_MiniTableField field = {3, UPB_SIZE(8, 32), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetMutableArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_DescriptorProto**)_upb_array_ptr(arr); } else { if (size) *size = 0; @@ -5943,19 +5962,21 @@ UPB_INLINE google_protobuf_DescriptorProto** google_protobuf_DescriptorProto_res UPB_INLINE struct google_protobuf_DescriptorProto* google_protobuf_DescriptorProto_add_nested_type(google_protobuf_DescriptorProto* msg, upb_Arena* arena) { upb_MiniTableField field = {3, UPB_SIZE(8, 32), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); - if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { + if (!arr || !_upb_Array_ResizeUninitialized( + arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; } struct google_protobuf_DescriptorProto* sub = (struct google_protobuf_DescriptorProto*)_upb_Message_New(&google__protobuf__DescriptorProto_msg_init, arena); if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &sub, sizeof(sub)); + UPB_PRIVATE(_upb_Array_Set) + (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); return sub; } UPB_INLINE google_protobuf_EnumDescriptorProto** google_protobuf_DescriptorProto_mutable_enum_type(google_protobuf_DescriptorProto* msg, size_t* size) { upb_MiniTableField field = {4, UPB_SIZE(12, 40), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetMutableArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_EnumDescriptorProto**)_upb_array_ptr(arr); } else { if (size) *size = 0; @@ -5969,19 +5990,21 @@ UPB_INLINE google_protobuf_EnumDescriptorProto** google_protobuf_DescriptorProto UPB_INLINE struct google_protobuf_EnumDescriptorProto* google_protobuf_DescriptorProto_add_enum_type(google_protobuf_DescriptorProto* msg, upb_Arena* arena) { upb_MiniTableField field = {4, UPB_SIZE(12, 40), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); - if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { + if (!arr || !_upb_Array_ResizeUninitialized( + arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; } struct google_protobuf_EnumDescriptorProto* sub = (struct google_protobuf_EnumDescriptorProto*)_upb_Message_New(&google__protobuf__EnumDescriptorProto_msg_init, arena); if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &sub, sizeof(sub)); + UPB_PRIVATE(_upb_Array_Set) + (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); return sub; } UPB_INLINE google_protobuf_DescriptorProto_ExtensionRange** google_protobuf_DescriptorProto_mutable_extension_range(google_protobuf_DescriptorProto* msg, size_t* size) { upb_MiniTableField field = {5, UPB_SIZE(16, 48), 0, 3, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetMutableArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_DescriptorProto_ExtensionRange**)_upb_array_ptr(arr); } else { if (size) *size = 0; @@ -5995,19 +6018,21 @@ UPB_INLINE google_protobuf_DescriptorProto_ExtensionRange** google_protobuf_Desc UPB_INLINE struct google_protobuf_DescriptorProto_ExtensionRange* google_protobuf_DescriptorProto_add_extension_range(google_protobuf_DescriptorProto* msg, upb_Arena* arena) { upb_MiniTableField field = {5, UPB_SIZE(16, 48), 0, 3, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); - if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { + if (!arr || !_upb_Array_ResizeUninitialized( + arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; } struct google_protobuf_DescriptorProto_ExtensionRange* sub = (struct google_protobuf_DescriptorProto_ExtensionRange*)_upb_Message_New(&google__protobuf__DescriptorProto__ExtensionRange_msg_init, arena); if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &sub, sizeof(sub)); + UPB_PRIVATE(_upb_Array_Set) + (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); return sub; } UPB_INLINE google_protobuf_FieldDescriptorProto** google_protobuf_DescriptorProto_mutable_extension(google_protobuf_DescriptorProto* msg, size_t* size) { upb_MiniTableField field = {6, UPB_SIZE(20, 56), 0, 4, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetMutableArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_FieldDescriptorProto**)_upb_array_ptr(arr); } else { if (size) *size = 0; @@ -6021,12 +6046,14 @@ UPB_INLINE google_protobuf_FieldDescriptorProto** google_protobuf_DescriptorProt UPB_INLINE struct google_protobuf_FieldDescriptorProto* google_protobuf_DescriptorProto_add_extension(google_protobuf_DescriptorProto* msg, upb_Arena* arena) { upb_MiniTableField field = {6, UPB_SIZE(20, 56), 0, 4, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); - if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { + if (!arr || !_upb_Array_ResizeUninitialized( + arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; } struct google_protobuf_FieldDescriptorProto* sub = (struct google_protobuf_FieldDescriptorProto*)_upb_Message_New(&google__protobuf__FieldDescriptorProto_msg_init, arena); if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &sub, sizeof(sub)); + UPB_PRIVATE(_upb_Array_Set) + (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); return sub; } UPB_INLINE void google_protobuf_DescriptorProto_set_options(google_protobuf_DescriptorProto *msg, google_protobuf_MessageOptions* value) { @@ -6045,7 +6072,7 @@ UPB_INLINE google_protobuf_OneofDescriptorProto** google_protobuf_DescriptorProt upb_MiniTableField field = {8, UPB_SIZE(28, 72), 0, 6, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetMutableArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_OneofDescriptorProto**)_upb_array_ptr(arr); } else { if (size) *size = 0; @@ -6059,19 +6086,21 @@ UPB_INLINE google_protobuf_OneofDescriptorProto** google_protobuf_DescriptorProt UPB_INLINE struct google_protobuf_OneofDescriptorProto* google_protobuf_DescriptorProto_add_oneof_decl(google_protobuf_DescriptorProto* msg, upb_Arena* arena) { upb_MiniTableField field = {8, UPB_SIZE(28, 72), 0, 6, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); - if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { + if (!arr || !_upb_Array_ResizeUninitialized( + arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; } struct google_protobuf_OneofDescriptorProto* sub = (struct google_protobuf_OneofDescriptorProto*)_upb_Message_New(&google__protobuf__OneofDescriptorProto_msg_init, arena); if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &sub, sizeof(sub)); + UPB_PRIVATE(_upb_Array_Set) + (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); return sub; } UPB_INLINE google_protobuf_DescriptorProto_ReservedRange** google_protobuf_DescriptorProto_mutable_reserved_range(google_protobuf_DescriptorProto* msg, size_t* size) { upb_MiniTableField field = {9, UPB_SIZE(32, 80), 0, 7, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetMutableArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_DescriptorProto_ReservedRange**)_upb_array_ptr(arr); } else { if (size) *size = 0; @@ -6085,19 +6114,21 @@ UPB_INLINE google_protobuf_DescriptorProto_ReservedRange** google_protobuf_Descr UPB_INLINE struct google_protobuf_DescriptorProto_ReservedRange* google_protobuf_DescriptorProto_add_reserved_range(google_protobuf_DescriptorProto* msg, upb_Arena* arena) { upb_MiniTableField field = {9, UPB_SIZE(32, 80), 0, 7, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); - if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { + if (!arr || !_upb_Array_ResizeUninitialized( + arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; } struct google_protobuf_DescriptorProto_ReservedRange* sub = (struct google_protobuf_DescriptorProto_ReservedRange*)_upb_Message_New(&google__protobuf__DescriptorProto__ReservedRange_msg_init, arena); if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &sub, sizeof(sub)); + UPB_PRIVATE(_upb_Array_Set) + (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); return sub; } UPB_INLINE upb_StringView* google_protobuf_DescriptorProto_mutable_reserved_name(google_protobuf_DescriptorProto* msg, size_t* size) { upb_MiniTableField field = {10, UPB_SIZE(36, 88), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetMutableArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (upb_StringView*)_upb_array_ptr(arr); } else { if (size) *size = 0; @@ -6111,10 +6142,12 @@ UPB_INLINE upb_StringView* google_protobuf_DescriptorProto_resize_reserved_name( UPB_INLINE bool google_protobuf_DescriptorProto_add_reserved_name(google_protobuf_DescriptorProto* msg, upb_StringView val, upb_Arena* arena) { upb_MiniTableField field = {10, UPB_SIZE(36, 88), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); - if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { + if (!arr || !_upb_Array_ResizeUninitialized( + arr, arr->UPB_PRIVATE(size) + 1, arena)) { return false; } - UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &val, sizeof(val)); + UPB_PRIVATE(_upb_Array_Set) + (arr, arr->UPB_PRIVATE(size) - 1, &val, sizeof(val)); return true; } @@ -6338,7 +6371,7 @@ UPB_INLINE const google_protobuf_ExtensionRangeOptions_Declaration* const* googl const upb_MiniTableField field = {2, UPB_SIZE(4, 8), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_ExtensionRangeOptions_Declaration* const*)_upb_array_constptr(arr); } else { if (size) *size = 0; @@ -6349,7 +6382,7 @@ UPB_INLINE const upb_Array* _google_protobuf_ExtensionRangeOptions_declaration_u const upb_MiniTableField field = {2, UPB_SIZE(4, 8), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -6358,7 +6391,7 @@ UPB_INLINE upb_Array* _google_protobuf_ExtensionRangeOptions_declaration_mutable upb_Array* arr = upb_Message_GetOrCreateMutableArray( (upb_Message*)msg, &field, arena); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -6400,7 +6433,7 @@ UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_Ext const upb_MiniTableField field = {999, UPB_SIZE(16, 24), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_UninterpretedOption* const*)_upb_array_constptr(arr); } else { if (size) *size = 0; @@ -6411,7 +6444,7 @@ UPB_INLINE const upb_Array* _google_protobuf_ExtensionRangeOptions_uninterpreted const upb_MiniTableField field = {999, UPB_SIZE(16, 24), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -6420,7 +6453,7 @@ UPB_INLINE upb_Array* _google_protobuf_ExtensionRangeOptions_uninterpreted_optio upb_Array* arr = upb_Message_GetOrCreateMutableArray( (upb_Message*)msg, &field, arena); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -6429,7 +6462,7 @@ UPB_INLINE google_protobuf_ExtensionRangeOptions_Declaration** google_protobuf_E upb_MiniTableField field = {2, UPB_SIZE(4, 8), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetMutableArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_ExtensionRangeOptions_Declaration**)_upb_array_ptr(arr); } else { if (size) *size = 0; @@ -6443,12 +6476,14 @@ UPB_INLINE google_protobuf_ExtensionRangeOptions_Declaration** google_protobuf_E UPB_INLINE struct google_protobuf_ExtensionRangeOptions_Declaration* google_protobuf_ExtensionRangeOptions_add_declaration(google_protobuf_ExtensionRangeOptions* msg, upb_Arena* arena) { upb_MiniTableField field = {2, UPB_SIZE(4, 8), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); - if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { + if (!arr || !_upb_Array_ResizeUninitialized( + arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; } struct google_protobuf_ExtensionRangeOptions_Declaration* sub = (struct google_protobuf_ExtensionRangeOptions_Declaration*)_upb_Message_New(&google__protobuf__ExtensionRangeOptions__Declaration_msg_init, arena); if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &sub, sizeof(sub)); + UPB_PRIVATE(_upb_Array_Set) + (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); return sub; } UPB_INLINE void google_protobuf_ExtensionRangeOptions_set_verification(google_protobuf_ExtensionRangeOptions *msg, int32_t value) { @@ -6471,7 +6506,7 @@ UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_ExtensionRangeO upb_MiniTableField field = {999, UPB_SIZE(16, 24), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetMutableArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_UninterpretedOption**)_upb_array_ptr(arr); } else { if (size) *size = 0; @@ -6485,12 +6520,14 @@ UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_ExtensionRangeO UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_ExtensionRangeOptions_add_uninterpreted_option(google_protobuf_ExtensionRangeOptions* msg, upb_Arena* arena) { upb_MiniTableField field = {999, UPB_SIZE(16, 24), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); - if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { + if (!arr || !_upb_Array_ResizeUninitialized( + arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; } struct google_protobuf_UninterpretedOption* sub = (struct google_protobuf_UninterpretedOption*)_upb_Message_New(&google__protobuf__UninterpretedOption_msg_init, arena); if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &sub, sizeof(sub)); + UPB_PRIVATE(_upb_Array_Set) + (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); return sub; } @@ -7021,7 +7058,7 @@ UPB_INLINE const google_protobuf_EnumValueDescriptorProto* const* google_protobu const upb_MiniTableField field = {2, UPB_SIZE(4, 24), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_EnumValueDescriptorProto* const*)_upb_array_constptr(arr); } else { if (size) *size = 0; @@ -7032,7 +7069,7 @@ UPB_INLINE const upb_Array* _google_protobuf_EnumDescriptorProto_value_upb_array const upb_MiniTableField field = {2, UPB_SIZE(4, 24), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -7041,7 +7078,7 @@ UPB_INLINE upb_Array* _google_protobuf_EnumDescriptorProto_value_mutable_upb_arr upb_Array* arr = upb_Message_GetOrCreateMutableArray( (upb_Message*)msg, &field, arena); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -7068,7 +7105,7 @@ UPB_INLINE const google_protobuf_EnumDescriptorProto_EnumReservedRange* const* g const upb_MiniTableField field = {4, UPB_SIZE(12, 40), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_EnumDescriptorProto_EnumReservedRange* const*)_upb_array_constptr(arr); } else { if (size) *size = 0; @@ -7079,7 +7116,7 @@ UPB_INLINE const upb_Array* _google_protobuf_EnumDescriptorProto_reserved_range_ const upb_MiniTableField field = {4, UPB_SIZE(12, 40), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -7088,7 +7125,7 @@ UPB_INLINE upb_Array* _google_protobuf_EnumDescriptorProto_reserved_range_mutabl upb_Array* arr = upb_Message_GetOrCreateMutableArray( (upb_Message*)msg, &field, arena); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -7100,7 +7137,7 @@ UPB_INLINE upb_StringView const* google_protobuf_EnumDescriptorProto_reserved_na const upb_MiniTableField field = {5, UPB_SIZE(16, 48), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (upb_StringView const*)_upb_array_constptr(arr); } else { if (size) *size = 0; @@ -7111,7 +7148,7 @@ UPB_INLINE const upb_Array* _google_protobuf_EnumDescriptorProto_reserved_name_u const upb_MiniTableField field = {5, UPB_SIZE(16, 48), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -7120,7 +7157,7 @@ UPB_INLINE upb_Array* _google_protobuf_EnumDescriptorProto_reserved_name_mutable upb_Array* arr = upb_Message_GetOrCreateMutableArray( (upb_Message*)msg, &field, arena); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -7133,7 +7170,7 @@ UPB_INLINE google_protobuf_EnumValueDescriptorProto** google_protobuf_EnumDescri upb_MiniTableField field = {2, UPB_SIZE(4, 24), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetMutableArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_EnumValueDescriptorProto**)_upb_array_ptr(arr); } else { if (size) *size = 0; @@ -7147,12 +7184,14 @@ UPB_INLINE google_protobuf_EnumValueDescriptorProto** google_protobuf_EnumDescri UPB_INLINE struct google_protobuf_EnumValueDescriptorProto* google_protobuf_EnumDescriptorProto_add_value(google_protobuf_EnumDescriptorProto* msg, upb_Arena* arena) { upb_MiniTableField field = {2, UPB_SIZE(4, 24), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); - if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { + if (!arr || !_upb_Array_ResizeUninitialized( + arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; } struct google_protobuf_EnumValueDescriptorProto* sub = (struct google_protobuf_EnumValueDescriptorProto*)_upb_Message_New(&google__protobuf__EnumValueDescriptorProto_msg_init, arena); if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &sub, sizeof(sub)); + UPB_PRIVATE(_upb_Array_Set) + (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); return sub; } UPB_INLINE void google_protobuf_EnumDescriptorProto_set_options(google_protobuf_EnumDescriptorProto *msg, google_protobuf_EnumOptions* value) { @@ -7171,7 +7210,7 @@ UPB_INLINE google_protobuf_EnumDescriptorProto_EnumReservedRange** google_protob upb_MiniTableField field = {4, UPB_SIZE(12, 40), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetMutableArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_EnumDescriptorProto_EnumReservedRange**)_upb_array_ptr(arr); } else { if (size) *size = 0; @@ -7185,19 +7224,21 @@ UPB_INLINE google_protobuf_EnumDescriptorProto_EnumReservedRange** google_protob UPB_INLINE struct google_protobuf_EnumDescriptorProto_EnumReservedRange* google_protobuf_EnumDescriptorProto_add_reserved_range(google_protobuf_EnumDescriptorProto* msg, upb_Arena* arena) { upb_MiniTableField field = {4, UPB_SIZE(12, 40), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); - if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { + if (!arr || !_upb_Array_ResizeUninitialized( + arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; } struct google_protobuf_EnumDescriptorProto_EnumReservedRange* sub = (struct google_protobuf_EnumDescriptorProto_EnumReservedRange*)_upb_Message_New(&google__protobuf__EnumDescriptorProto__EnumReservedRange_msg_init, arena); if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &sub, sizeof(sub)); + UPB_PRIVATE(_upb_Array_Set) + (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); return sub; } UPB_INLINE upb_StringView* google_protobuf_EnumDescriptorProto_mutable_reserved_name(google_protobuf_EnumDescriptorProto* msg, size_t* size) { upb_MiniTableField field = {5, UPB_SIZE(16, 48), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetMutableArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (upb_StringView*)_upb_array_ptr(arr); } else { if (size) *size = 0; @@ -7211,10 +7252,12 @@ UPB_INLINE upb_StringView* google_protobuf_EnumDescriptorProto_resize_reserved_n UPB_INLINE bool google_protobuf_EnumDescriptorProto_add_reserved_name(google_protobuf_EnumDescriptorProto* msg, upb_StringView val, upb_Arena* arena) { upb_MiniTableField field = {5, UPB_SIZE(16, 48), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); - if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { + if (!arr || !_upb_Array_ResizeUninitialized( + arr, arr->UPB_PRIVATE(size) + 1, arena)) { return false; } - UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &val, sizeof(val)); + UPB_PRIVATE(_upb_Array_Set) + (arr, arr->UPB_PRIVATE(size) - 1, &val, sizeof(val)); return true; } @@ -7453,7 +7496,7 @@ UPB_INLINE const google_protobuf_MethodDescriptorProto* const* google_protobuf_S const upb_MiniTableField field = {2, UPB_SIZE(4, 24), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_MethodDescriptorProto* const*)_upb_array_constptr(arr); } else { if (size) *size = 0; @@ -7464,7 +7507,7 @@ UPB_INLINE const upb_Array* _google_protobuf_ServiceDescriptorProto_method_upb_a const upb_MiniTableField field = {2, UPB_SIZE(4, 24), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -7473,7 +7516,7 @@ UPB_INLINE upb_Array* _google_protobuf_ServiceDescriptorProto_method_mutable_upb upb_Array* arr = upb_Message_GetOrCreateMutableArray( (upb_Message*)msg, &field, arena); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -7501,7 +7544,7 @@ UPB_INLINE google_protobuf_MethodDescriptorProto** google_protobuf_ServiceDescri upb_MiniTableField field = {2, UPB_SIZE(4, 24), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetMutableArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_MethodDescriptorProto**)_upb_array_ptr(arr); } else { if (size) *size = 0; @@ -7515,12 +7558,14 @@ UPB_INLINE google_protobuf_MethodDescriptorProto** google_protobuf_ServiceDescri UPB_INLINE struct google_protobuf_MethodDescriptorProto* google_protobuf_ServiceDescriptorProto_add_method(google_protobuf_ServiceDescriptorProto* msg, upb_Arena* arena) { upb_MiniTableField field = {2, UPB_SIZE(4, 24), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); - if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { + if (!arr || !_upb_Array_ResizeUninitialized( + arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; } struct google_protobuf_MethodDescriptorProto* sub = (struct google_protobuf_MethodDescriptorProto*)_upb_Message_New(&google__protobuf__MethodDescriptorProto_msg_init, arena); if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &sub, sizeof(sub)); + UPB_PRIVATE(_upb_Array_Set) + (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); return sub; } UPB_INLINE void google_protobuf_ServiceDescriptorProto_set_options(google_protobuf_ServiceDescriptorProto *msg, google_protobuf_ServiceOptions* value) { @@ -8053,7 +8098,7 @@ UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_Fil const upb_MiniTableField field = {999, UPB_SIZE(24, 192), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_UninterpretedOption* const*)_upb_array_constptr(arr); } else { if (size) *size = 0; @@ -8064,7 +8109,7 @@ UPB_INLINE const upb_Array* _google_protobuf_FileOptions_uninterpreted_option_up const upb_MiniTableField field = {999, UPB_SIZE(24, 192), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -8073,7 +8118,7 @@ UPB_INLINE upb_Array* _google_protobuf_FileOptions_uninterpreted_option_mutable_ upb_Array* arr = upb_Message_GetOrCreateMutableArray( (upb_Message*)msg, &field, arena); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -8174,7 +8219,7 @@ UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_FileOptions_mut upb_MiniTableField field = {999, UPB_SIZE(24, 192), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetMutableArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_UninterpretedOption**)_upb_array_ptr(arr); } else { if (size) *size = 0; @@ -8188,12 +8233,14 @@ UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_FileOptions_res UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_FileOptions_add_uninterpreted_option(google_protobuf_FileOptions* msg, upb_Arena* arena) { upb_MiniTableField field = {999, UPB_SIZE(24, 192), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); - if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { + if (!arr || !_upb_Array_ResizeUninitialized( + arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; } struct google_protobuf_UninterpretedOption* sub = (struct google_protobuf_UninterpretedOption*)_upb_Message_New(&google__protobuf__UninterpretedOption_msg_init, arena); if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &sub, sizeof(sub)); + UPB_PRIVATE(_upb_Array_Set) + (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); return sub; } @@ -8330,7 +8377,7 @@ UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_Mes const upb_MiniTableField field = {999, UPB_SIZE(12, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_UninterpretedOption* const*)_upb_array_constptr(arr); } else { if (size) *size = 0; @@ -8341,7 +8388,7 @@ UPB_INLINE const upb_Array* _google_protobuf_MessageOptions_uninterpreted_option const upb_MiniTableField field = {999, UPB_SIZE(12, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -8350,7 +8397,7 @@ UPB_INLINE upb_Array* _google_protobuf_MessageOptions_uninterpreted_option_mutab upb_Array* arr = upb_Message_GetOrCreateMutableArray( (upb_Message*)msg, &field, arena); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -8391,7 +8438,7 @@ UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_MessageOptions_ upb_MiniTableField field = {999, UPB_SIZE(12, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetMutableArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_UninterpretedOption**)_upb_array_ptr(arr); } else { if (size) *size = 0; @@ -8405,12 +8452,14 @@ UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_MessageOptions_ UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_MessageOptions_add_uninterpreted_option(google_protobuf_MessageOptions* msg, upb_Arena* arena) { upb_MiniTableField field = {999, UPB_SIZE(12, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); - if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { + if (!arr || !_upb_Array_ResizeUninitialized( + arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; } struct google_protobuf_UninterpretedOption* sub = (struct google_protobuf_UninterpretedOption*)_upb_Message_New(&google__protobuf__UninterpretedOption_msg_init, arena); if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &sub, sizeof(sub)); + UPB_PRIVATE(_upb_Array_Set) + (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); return sub; } @@ -8592,7 +8641,7 @@ UPB_INLINE int32_t const* google_protobuf_FieldOptions_targets(const google_prot const upb_MiniTableField field = {19, 24, 0, 6, 14, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (int32_t const*)_upb_array_constptr(arr); } else { if (size) *size = 0; @@ -8603,7 +8652,7 @@ UPB_INLINE const upb_Array* _google_protobuf_FieldOptions_targets_upb_array(cons const upb_MiniTableField field = {19, 24, 0, 6, 14, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -8612,7 +8661,7 @@ UPB_INLINE upb_Array* _google_protobuf_FieldOptions_targets_mutable_upb_array(co upb_Array* arr = upb_Message_GetOrCreateMutableArray( (upb_Message*)msg, &field, arena); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -8624,7 +8673,7 @@ UPB_INLINE const google_protobuf_FieldOptions_EditionDefault* const* google_prot const upb_MiniTableField field = {20, UPB_SIZE(28, 32), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_FieldOptions_EditionDefault* const*)_upb_array_constptr(arr); } else { if (size) *size = 0; @@ -8635,7 +8684,7 @@ UPB_INLINE const upb_Array* _google_protobuf_FieldOptions_edition_defaults_upb_a const upb_MiniTableField field = {20, UPB_SIZE(28, 32), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -8644,7 +8693,7 @@ UPB_INLINE upb_Array* _google_protobuf_FieldOptions_edition_defaults_mutable_upb upb_Array* arr = upb_Message_GetOrCreateMutableArray( (upb_Message*)msg, &field, arena); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -8671,7 +8720,7 @@ UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_Fie const upb_MiniTableField field = {999, UPB_SIZE(36, 48), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_UninterpretedOption* const*)_upb_array_constptr(arr); } else { if (size) *size = 0; @@ -8682,7 +8731,7 @@ UPB_INLINE const upb_Array* _google_protobuf_FieldOptions_uninterpreted_option_u const upb_MiniTableField field = {999, UPB_SIZE(36, 48), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -8691,7 +8740,7 @@ UPB_INLINE upb_Array* _google_protobuf_FieldOptions_uninterpreted_option_mutable upb_Array* arr = upb_Message_GetOrCreateMutableArray( (upb_Message*)msg, &field, arena); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -8736,7 +8785,7 @@ UPB_INLINE int32_t* google_protobuf_FieldOptions_mutable_targets(google_protobuf upb_MiniTableField field = {19, 24, 0, 6, 14, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetMutableArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (int32_t*)_upb_array_ptr(arr); } else { if (size) *size = 0; @@ -8750,17 +8799,19 @@ UPB_INLINE int32_t* google_protobuf_FieldOptions_resize_targets(google_protobuf_ UPB_INLINE bool google_protobuf_FieldOptions_add_targets(google_protobuf_FieldOptions* msg, int32_t val, upb_Arena* arena) { upb_MiniTableField field = {19, 24, 0, 6, 14, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); - if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { + if (!arr || !_upb_Array_ResizeUninitialized( + arr, arr->UPB_PRIVATE(size) + 1, arena)) { return false; } - UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &val, sizeof(val)); + UPB_PRIVATE(_upb_Array_Set) + (arr, arr->UPB_PRIVATE(size) - 1, &val, sizeof(val)); return true; } UPB_INLINE google_protobuf_FieldOptions_EditionDefault** google_protobuf_FieldOptions_mutable_edition_defaults(google_protobuf_FieldOptions* msg, size_t* size) { upb_MiniTableField field = {20, UPB_SIZE(28, 32), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetMutableArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_FieldOptions_EditionDefault**)_upb_array_ptr(arr); } else { if (size) *size = 0; @@ -8774,12 +8825,14 @@ UPB_INLINE google_protobuf_FieldOptions_EditionDefault** google_protobuf_FieldOp UPB_INLINE struct google_protobuf_FieldOptions_EditionDefault* google_protobuf_FieldOptions_add_edition_defaults(google_protobuf_FieldOptions* msg, upb_Arena* arena) { upb_MiniTableField field = {20, UPB_SIZE(28, 32), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); - if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { + if (!arr || !_upb_Array_ResizeUninitialized( + arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; } struct google_protobuf_FieldOptions_EditionDefault* sub = (struct google_protobuf_FieldOptions_EditionDefault*)_upb_Message_New(&google__protobuf__FieldOptions__EditionDefault_msg_init, arena); if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &sub, sizeof(sub)); + UPB_PRIVATE(_upb_Array_Set) + (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); return sub; } UPB_INLINE void google_protobuf_FieldOptions_set_features(google_protobuf_FieldOptions *msg, google_protobuf_FeatureSet* value) { @@ -8798,7 +8851,7 @@ UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_FieldOptions_mu upb_MiniTableField field = {999, UPB_SIZE(36, 48), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetMutableArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_UninterpretedOption**)_upb_array_ptr(arr); } else { if (size) *size = 0; @@ -8812,12 +8865,14 @@ UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_FieldOptions_re UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_FieldOptions_add_uninterpreted_option(google_protobuf_FieldOptions* msg, upb_Arena* arena) { upb_MiniTableField field = {999, UPB_SIZE(36, 48), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); - if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { + if (!arr || !_upb_Array_ResizeUninitialized( + arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; } struct google_protobuf_UninterpretedOption* sub = (struct google_protobuf_UninterpretedOption*)_upb_Message_New(&google__protobuf__UninterpretedOption_msg_init, arena); if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &sub, sizeof(sub)); + UPB_PRIVATE(_upb_Array_Set) + (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); return sub; } @@ -8954,7 +9009,7 @@ UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_One const upb_MiniTableField field = {999, UPB_SIZE(8, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_UninterpretedOption* const*)_upb_array_constptr(arr); } else { if (size) *size = 0; @@ -8965,7 +9020,7 @@ UPB_INLINE const upb_Array* _google_protobuf_OneofOptions_uninterpreted_option_u const upb_MiniTableField field = {999, UPB_SIZE(8, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -8974,7 +9029,7 @@ UPB_INLINE upb_Array* _google_protobuf_OneofOptions_uninterpreted_option_mutable upb_Array* arr = upb_Message_GetOrCreateMutableArray( (upb_Message*)msg, &field, arena); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -8995,7 +9050,7 @@ UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_OneofOptions_mu upb_MiniTableField field = {999, UPB_SIZE(8, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetMutableArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_UninterpretedOption**)_upb_array_ptr(arr); } else { if (size) *size = 0; @@ -9009,12 +9064,14 @@ UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_OneofOptions_re UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_OneofOptions_add_uninterpreted_option(google_protobuf_OneofOptions* msg, upb_Arena* arena) { upb_MiniTableField field = {999, UPB_SIZE(8, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); - if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { + if (!arr || !_upb_Array_ResizeUninitialized( + arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; } struct google_protobuf_UninterpretedOption* sub = (struct google_protobuf_UninterpretedOption*)_upb_Message_New(&google__protobuf__UninterpretedOption_msg_init, arena); if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &sub, sizeof(sub)); + UPB_PRIVATE(_upb_Array_Set) + (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); return sub; } @@ -9121,7 +9178,7 @@ UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_Enu const upb_MiniTableField field = {999, UPB_SIZE(8, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_UninterpretedOption* const*)_upb_array_constptr(arr); } else { if (size) *size = 0; @@ -9132,7 +9189,7 @@ UPB_INLINE const upb_Array* _google_protobuf_EnumOptions_uninterpreted_option_up const upb_MiniTableField field = {999, UPB_SIZE(8, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -9141,7 +9198,7 @@ UPB_INLINE upb_Array* _google_protobuf_EnumOptions_uninterpreted_option_mutable_ upb_Array* arr = upb_Message_GetOrCreateMutableArray( (upb_Message*)msg, &field, arena); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -9174,7 +9231,7 @@ UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_EnumOptions_mut upb_MiniTableField field = {999, UPB_SIZE(8, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetMutableArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_UninterpretedOption**)_upb_array_ptr(arr); } else { if (size) *size = 0; @@ -9188,12 +9245,14 @@ UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_EnumOptions_res UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_EnumOptions_add_uninterpreted_option(google_protobuf_EnumOptions* msg, upb_Arena* arena) { upb_MiniTableField field = {999, UPB_SIZE(8, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); - if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { + if (!arr || !_upb_Array_ResizeUninitialized( + arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; } struct google_protobuf_UninterpretedOption* sub = (struct google_protobuf_UninterpretedOption*)_upb_Message_New(&google__protobuf__UninterpretedOption_msg_init, arena); if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &sub, sizeof(sub)); + UPB_PRIVATE(_upb_Array_Set) + (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); return sub; } @@ -9285,7 +9344,7 @@ UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_Enu const upb_MiniTableField field = {999, UPB_SIZE(12, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_UninterpretedOption* const*)_upb_array_constptr(arr); } else { if (size) *size = 0; @@ -9296,7 +9355,7 @@ UPB_INLINE const upb_Array* _google_protobuf_EnumValueOptions_uninterpreted_opti const upb_MiniTableField field = {999, UPB_SIZE(12, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -9305,7 +9364,7 @@ UPB_INLINE upb_Array* _google_protobuf_EnumValueOptions_uninterpreted_option_mut upb_Array* arr = upb_Message_GetOrCreateMutableArray( (upb_Message*)msg, &field, arena); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -9334,7 +9393,7 @@ UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_EnumValueOption upb_MiniTableField field = {999, UPB_SIZE(12, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetMutableArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_UninterpretedOption**)_upb_array_ptr(arr); } else { if (size) *size = 0; @@ -9348,12 +9407,14 @@ UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_EnumValueOption UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_EnumValueOptions_add_uninterpreted_option(google_protobuf_EnumValueOptions* msg, upb_Arena* arena) { upb_MiniTableField field = {999, UPB_SIZE(12, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); - if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { + if (!arr || !_upb_Array_ResizeUninitialized( + arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; } struct google_protobuf_UninterpretedOption* sub = (struct google_protobuf_UninterpretedOption*)_upb_Message_New(&google__protobuf__UninterpretedOption_msg_init, arena); if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &sub, sizeof(sub)); + UPB_PRIVATE(_upb_Array_Set) + (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); return sub; } @@ -9430,7 +9491,7 @@ UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_Ser const upb_MiniTableField field = {999, UPB_SIZE(8, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_UninterpretedOption* const*)_upb_array_constptr(arr); } else { if (size) *size = 0; @@ -9441,7 +9502,7 @@ UPB_INLINE const upb_Array* _google_protobuf_ServiceOptions_uninterpreted_option const upb_MiniTableField field = {999, UPB_SIZE(8, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -9450,7 +9511,7 @@ UPB_INLINE upb_Array* _google_protobuf_ServiceOptions_uninterpreted_option_mutab upb_Array* arr = upb_Message_GetOrCreateMutableArray( (upb_Message*)msg, &field, arena); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -9475,7 +9536,7 @@ UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_ServiceOptions_ upb_MiniTableField field = {999, UPB_SIZE(8, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetMutableArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_UninterpretedOption**)_upb_array_ptr(arr); } else { if (size) *size = 0; @@ -9489,12 +9550,14 @@ UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_ServiceOptions_ UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_ServiceOptions_add_uninterpreted_option(google_protobuf_ServiceOptions* msg, upb_Arena* arena) { upb_MiniTableField field = {999, UPB_SIZE(8, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); - if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { + if (!arr || !_upb_Array_ResizeUninitialized( + arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; } struct google_protobuf_UninterpretedOption* sub = (struct google_protobuf_UninterpretedOption*)_upb_Message_New(&google__protobuf__UninterpretedOption_msg_init, arena); if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &sub, sizeof(sub)); + UPB_PRIVATE(_upb_Array_Set) + (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); return sub; } @@ -9586,7 +9649,7 @@ UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_Met const upb_MiniTableField field = {999, UPB_SIZE(12, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_UninterpretedOption* const*)_upb_array_constptr(arr); } else { if (size) *size = 0; @@ -9597,7 +9660,7 @@ UPB_INLINE const upb_Array* _google_protobuf_MethodOptions_uninterpreted_option_ const upb_MiniTableField field = {999, UPB_SIZE(12, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -9606,7 +9669,7 @@ UPB_INLINE upb_Array* _google_protobuf_MethodOptions_uninterpreted_option_mutabl upb_Array* arr = upb_Message_GetOrCreateMutableArray( (upb_Message*)msg, &field, arena); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -9635,7 +9698,7 @@ UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_MethodOptions_m upb_MiniTableField field = {999, UPB_SIZE(12, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetMutableArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_UninterpretedOption**)_upb_array_ptr(arr); } else { if (size) *size = 0; @@ -9649,12 +9712,14 @@ UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_MethodOptions_r UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_MethodOptions_add_uninterpreted_option(google_protobuf_MethodOptions* msg, upb_Arena* arena) { upb_MiniTableField field = {999, UPB_SIZE(12, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); - if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { + if (!arr || !_upb_Array_ResizeUninitialized( + arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; } struct google_protobuf_UninterpretedOption* sub = (struct google_protobuf_UninterpretedOption*)_upb_Message_New(&google__protobuf__UninterpretedOption_msg_init, arena); if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &sub, sizeof(sub)); + UPB_PRIVATE(_upb_Array_Set) + (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); return sub; } @@ -9701,7 +9766,7 @@ UPB_INLINE const google_protobuf_UninterpretedOption_NamePart* const* google_pro const upb_MiniTableField field = {2, UPB_SIZE(4, 8), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_UninterpretedOption_NamePart* const*)_upb_array_constptr(arr); } else { if (size) *size = 0; @@ -9712,7 +9777,7 @@ UPB_INLINE const upb_Array* _google_protobuf_UninterpretedOption_name_upb_array( const upb_MiniTableField field = {2, UPB_SIZE(4, 8), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -9721,7 +9786,7 @@ UPB_INLINE upb_Array* _google_protobuf_UninterpretedOption_name_mutable_upb_arra upb_Array* arr = upb_Message_GetOrCreateMutableArray( (upb_Message*)msg, &field, arena); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -9820,7 +9885,7 @@ UPB_INLINE google_protobuf_UninterpretedOption_NamePart** google_protobuf_Uninte upb_MiniTableField field = {2, UPB_SIZE(4, 8), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetMutableArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_UninterpretedOption_NamePart**)_upb_array_ptr(arr); } else { if (size) *size = 0; @@ -9834,12 +9899,14 @@ UPB_INLINE google_protobuf_UninterpretedOption_NamePart** google_protobuf_Uninte UPB_INLINE struct google_protobuf_UninterpretedOption_NamePart* google_protobuf_UninterpretedOption_add_name(google_protobuf_UninterpretedOption* msg, upb_Arena* arena) { upb_MiniTableField field = {2, UPB_SIZE(4, 8), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); - if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { + if (!arr || !_upb_Array_ResizeUninitialized( + arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; } struct google_protobuf_UninterpretedOption_NamePart* sub = (struct google_protobuf_UninterpretedOption_NamePart*)_upb_Message_New(&google__protobuf__UninterpretedOption__NamePart_msg_init, arena); if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &sub, sizeof(sub)); + UPB_PRIVATE(_upb_Array_Set) + (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); return sub; } UPB_INLINE void google_protobuf_UninterpretedOption_set_identifier_value(google_protobuf_UninterpretedOption *msg, upb_StringView value) { @@ -10136,7 +10203,7 @@ UPB_INLINE const google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* co const upb_MiniTableField field = {1, UPB_SIZE(4, 16), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* const*)_upb_array_constptr(arr); } else { if (size) *size = 0; @@ -10147,7 +10214,7 @@ UPB_INLINE const upb_Array* _google_protobuf_FeatureSetDefaults_defaults_upb_arr const upb_MiniTableField field = {1, UPB_SIZE(4, 16), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -10156,7 +10223,7 @@ UPB_INLINE upb_Array* _google_protobuf_FeatureSetDefaults_defaults_mutable_upb_a upb_Array* arr = upb_Message_GetOrCreateMutableArray( (upb_Message*)msg, &field, arena); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -10195,7 +10262,7 @@ UPB_INLINE google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault** google_ upb_MiniTableField field = {1, UPB_SIZE(4, 16), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetMutableArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault**)_upb_array_ptr(arr); } else { if (size) *size = 0; @@ -10209,12 +10276,14 @@ UPB_INLINE google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault** google_ UPB_INLINE struct google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* google_protobuf_FeatureSetDefaults_add_defaults(google_protobuf_FeatureSetDefaults* msg, upb_Arena* arena) { upb_MiniTableField field = {1, UPB_SIZE(4, 16), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); - if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { + if (!arr || !_upb_Array_ResizeUninitialized( + arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; } struct google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* sub = (struct google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault*)_upb_Message_New(&google__protobuf__FeatureSetDefaults__FeatureSetEditionDefault_msg_init, arena); if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &sub, sizeof(sub)); + UPB_PRIVATE(_upb_Array_Set) + (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); return sub; } UPB_INLINE void google_protobuf_FeatureSetDefaults_set_minimum_edition(google_protobuf_FeatureSetDefaults *msg, int32_t value) { @@ -10352,7 +10421,7 @@ UPB_INLINE const google_protobuf_SourceCodeInfo_Location* const* google_protobuf const upb_MiniTableField field = {1, 0, 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_SourceCodeInfo_Location* const*)_upb_array_constptr(arr); } else { if (size) *size = 0; @@ -10363,7 +10432,7 @@ UPB_INLINE const upb_Array* _google_protobuf_SourceCodeInfo_location_upb_array(c const upb_MiniTableField field = {1, 0, 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -10372,7 +10441,7 @@ UPB_INLINE upb_Array* _google_protobuf_SourceCodeInfo_location_mutable_upb_array upb_Array* arr = upb_Message_GetOrCreateMutableArray( (upb_Message*)msg, &field, arena); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -10381,7 +10450,7 @@ UPB_INLINE google_protobuf_SourceCodeInfo_Location** google_protobuf_SourceCodeI upb_MiniTableField field = {1, 0, 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetMutableArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_SourceCodeInfo_Location**)_upb_array_ptr(arr); } else { if (size) *size = 0; @@ -10395,12 +10464,14 @@ UPB_INLINE google_protobuf_SourceCodeInfo_Location** google_protobuf_SourceCodeI UPB_INLINE struct google_protobuf_SourceCodeInfo_Location* google_protobuf_SourceCodeInfo_add_location(google_protobuf_SourceCodeInfo* msg, upb_Arena* arena) { upb_MiniTableField field = {1, 0, 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); - if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { + if (!arr || !_upb_Array_ResizeUninitialized( + arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; } struct google_protobuf_SourceCodeInfo_Location* sub = (struct google_protobuf_SourceCodeInfo_Location*)_upb_Message_New(&google__protobuf__SourceCodeInfo__Location_msg_init, arena); if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &sub, sizeof(sub)); + UPB_PRIVATE(_upb_Array_Set) + (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); return sub; } @@ -10447,7 +10518,7 @@ UPB_INLINE int32_t const* google_protobuf_SourceCodeInfo_Location_path(const goo const upb_MiniTableField field = {1, UPB_SIZE(4, 8), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsPacked | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (int32_t const*)_upb_array_constptr(arr); } else { if (size) *size = 0; @@ -10458,7 +10529,7 @@ UPB_INLINE const upb_Array* _google_protobuf_SourceCodeInfo_Location_path_upb_ar const upb_MiniTableField field = {1, UPB_SIZE(4, 8), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsPacked | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -10467,7 +10538,7 @@ UPB_INLINE upb_Array* _google_protobuf_SourceCodeInfo_Location_path_mutable_upb_ upb_Array* arr = upb_Message_GetOrCreateMutableArray( (upb_Message*)msg, &field, arena); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -10479,7 +10550,7 @@ UPB_INLINE int32_t const* google_protobuf_SourceCodeInfo_Location_span(const goo const upb_MiniTableField field = {2, UPB_SIZE(8, 16), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsPacked | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (int32_t const*)_upb_array_constptr(arr); } else { if (size) *size = 0; @@ -10490,7 +10561,7 @@ UPB_INLINE const upb_Array* _google_protobuf_SourceCodeInfo_Location_span_upb_ar const upb_MiniTableField field = {2, UPB_SIZE(8, 16), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsPacked | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -10499,7 +10570,7 @@ UPB_INLINE upb_Array* _google_protobuf_SourceCodeInfo_Location_span_mutable_upb_ upb_Array* arr = upb_Message_GetOrCreateMutableArray( (upb_Message*)msg, &field, arena); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -10541,7 +10612,7 @@ UPB_INLINE upb_StringView const* google_protobuf_SourceCodeInfo_Location_leading const upb_MiniTableField field = {6, UPB_SIZE(12, 56), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (upb_StringView const*)_upb_array_constptr(arr); } else { if (size) *size = 0; @@ -10552,7 +10623,7 @@ UPB_INLINE const upb_Array* _google_protobuf_SourceCodeInfo_Location_leading_det const upb_MiniTableField field = {6, UPB_SIZE(12, 56), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -10561,7 +10632,7 @@ UPB_INLINE upb_Array* _google_protobuf_SourceCodeInfo_Location_leading_detached_ upb_Array* arr = upb_Message_GetOrCreateMutableArray( (upb_Message*)msg, &field, arena); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -10570,7 +10641,7 @@ UPB_INLINE int32_t* google_protobuf_SourceCodeInfo_Location_mutable_path(google_ upb_MiniTableField field = {1, UPB_SIZE(4, 8), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsPacked | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetMutableArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (int32_t*)_upb_array_ptr(arr); } else { if (size) *size = 0; @@ -10584,17 +10655,19 @@ UPB_INLINE int32_t* google_protobuf_SourceCodeInfo_Location_resize_path(google_p UPB_INLINE bool google_protobuf_SourceCodeInfo_Location_add_path(google_protobuf_SourceCodeInfo_Location* msg, int32_t val, upb_Arena* arena) { upb_MiniTableField field = {1, UPB_SIZE(4, 8), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsPacked | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); - if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { + if (!arr || !_upb_Array_ResizeUninitialized( + arr, arr->UPB_PRIVATE(size) + 1, arena)) { return false; } - UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &val, sizeof(val)); + UPB_PRIVATE(_upb_Array_Set) + (arr, arr->UPB_PRIVATE(size) - 1, &val, sizeof(val)); return true; } UPB_INLINE int32_t* google_protobuf_SourceCodeInfo_Location_mutable_span(google_protobuf_SourceCodeInfo_Location* msg, size_t* size) { upb_MiniTableField field = {2, UPB_SIZE(8, 16), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsPacked | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetMutableArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (int32_t*)_upb_array_ptr(arr); } else { if (size) *size = 0; @@ -10608,10 +10681,12 @@ UPB_INLINE int32_t* google_protobuf_SourceCodeInfo_Location_resize_span(google_p UPB_INLINE bool google_protobuf_SourceCodeInfo_Location_add_span(google_protobuf_SourceCodeInfo_Location* msg, int32_t val, upb_Arena* arena) { upb_MiniTableField field = {2, UPB_SIZE(8, 16), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsPacked | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); - if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { + if (!arr || !_upb_Array_ResizeUninitialized( + arr, arr->UPB_PRIVATE(size) + 1, arena)) { return false; } - UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &val, sizeof(val)); + UPB_PRIVATE(_upb_Array_Set) + (arr, arr->UPB_PRIVATE(size) - 1, &val, sizeof(val)); return true; } UPB_INLINE void google_protobuf_SourceCodeInfo_Location_set_leading_comments(google_protobuf_SourceCodeInfo_Location *msg, upb_StringView value) { @@ -10626,7 +10701,7 @@ UPB_INLINE upb_StringView* google_protobuf_SourceCodeInfo_Location_mutable_leadi upb_MiniTableField field = {6, UPB_SIZE(12, 56), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetMutableArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (upb_StringView*)_upb_array_ptr(arr); } else { if (size) *size = 0; @@ -10640,10 +10715,12 @@ UPB_INLINE upb_StringView* google_protobuf_SourceCodeInfo_Location_resize_leadin UPB_INLINE bool google_protobuf_SourceCodeInfo_Location_add_leading_detached_comments(google_protobuf_SourceCodeInfo_Location* msg, upb_StringView val, upb_Arena* arena) { upb_MiniTableField field = {6, UPB_SIZE(12, 56), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); - if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { + if (!arr || !_upb_Array_ResizeUninitialized( + arr, arr->UPB_PRIVATE(size) + 1, arena)) { return false; } - UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &val, sizeof(val)); + UPB_PRIVATE(_upb_Array_Set) + (arr, arr->UPB_PRIVATE(size) - 1, &val, sizeof(val)); return true; } @@ -10690,7 +10767,7 @@ UPB_INLINE const google_protobuf_GeneratedCodeInfo_Annotation* const* google_pro const upb_MiniTableField field = {1, 0, 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_GeneratedCodeInfo_Annotation* const*)_upb_array_constptr(arr); } else { if (size) *size = 0; @@ -10701,7 +10778,7 @@ UPB_INLINE const upb_Array* _google_protobuf_GeneratedCodeInfo_annotation_upb_ar const upb_MiniTableField field = {1, 0, 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -10710,7 +10787,7 @@ UPB_INLINE upb_Array* _google_protobuf_GeneratedCodeInfo_annotation_mutable_upb_ upb_Array* arr = upb_Message_GetOrCreateMutableArray( (upb_Message*)msg, &field, arena); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -10719,7 +10796,7 @@ UPB_INLINE google_protobuf_GeneratedCodeInfo_Annotation** google_protobuf_Genera upb_MiniTableField field = {1, 0, 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetMutableArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_GeneratedCodeInfo_Annotation**)_upb_array_ptr(arr); } else { if (size) *size = 0; @@ -10733,12 +10810,14 @@ UPB_INLINE google_protobuf_GeneratedCodeInfo_Annotation** google_protobuf_Genera UPB_INLINE struct google_protobuf_GeneratedCodeInfo_Annotation* google_protobuf_GeneratedCodeInfo_add_annotation(google_protobuf_GeneratedCodeInfo* msg, upb_Arena* arena) { upb_MiniTableField field = {1, 0, 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); - if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { + if (!arr || !_upb_Array_ResizeUninitialized( + arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; } struct google_protobuf_GeneratedCodeInfo_Annotation* sub = (struct google_protobuf_GeneratedCodeInfo_Annotation*)_upb_Message_New(&google__protobuf__GeneratedCodeInfo__Annotation_msg_init, arena); if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &sub, sizeof(sub)); + UPB_PRIVATE(_upb_Array_Set) + (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); return sub; } @@ -10785,7 +10864,7 @@ UPB_INLINE int32_t const* google_protobuf_GeneratedCodeInfo_Annotation_path(cons const upb_MiniTableField field = {1, UPB_SIZE(4, 16), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsPacked | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (int32_t const*)_upb_array_constptr(arr); } else { if (size) *size = 0; @@ -10796,7 +10875,7 @@ UPB_INLINE const upb_Array* _google_protobuf_GeneratedCodeInfo_Annotation_path_u const upb_MiniTableField field = {1, UPB_SIZE(4, 16), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsPacked | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -10805,7 +10884,7 @@ UPB_INLINE upb_Array* _google_protobuf_GeneratedCodeInfo_Annotation_path_mutable upb_Array* arr = upb_Message_GetOrCreateMutableArray( (upb_Message*)msg, &field, arena); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -10874,7 +10953,7 @@ UPB_INLINE int32_t* google_protobuf_GeneratedCodeInfo_Annotation_mutable_path(go upb_MiniTableField field = {1, UPB_SIZE(4, 16), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsPacked | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetMutableArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (int32_t*)_upb_array_ptr(arr); } else { if (size) *size = 0; @@ -10888,10 +10967,12 @@ UPB_INLINE int32_t* google_protobuf_GeneratedCodeInfo_Annotation_resize_path(goo UPB_INLINE bool google_protobuf_GeneratedCodeInfo_Annotation_add_path(google_protobuf_GeneratedCodeInfo_Annotation* msg, int32_t val, upb_Arena* arena) { upb_MiniTableField field = {1, UPB_SIZE(4, 16), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsPacked | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); - if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { + if (!arr || !_upb_Array_ResizeUninitialized( + arr, arr->UPB_PRIVATE(size) + 1, arena)) { return false; } - UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &val, sizeof(val)); + UPB_PRIVATE(_upb_Array_Set) + (arr, arr->UPB_PRIVATE(size) - 1, &val, sizeof(val)); return true; } UPB_INLINE void google_protobuf_GeneratedCodeInfo_Annotation_set_source_file(google_protobuf_GeneratedCodeInfo_Annotation *msg, upb_StringView value) { diff --git a/upb/cmake/google/protobuf/descriptor.upb.h b/upb/cmake/google/protobuf/descriptor.upb.h index 2b27131489017..26c80b854fabd 100644 --- a/upb/cmake/google/protobuf/descriptor.upb.h +++ b/upb/cmake/google/protobuf/descriptor.upb.h @@ -228,7 +228,7 @@ UPB_INLINE const google_protobuf_FileDescriptorProto* const* google_protobuf_Fil const upb_MiniTableField field = {1, 0, 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_FileDescriptorProto* const*)_upb_array_constptr(arr); } else { if (size) *size = 0; @@ -239,7 +239,7 @@ UPB_INLINE const upb_Array* _google_protobuf_FileDescriptorSet_file_upb_array(co const upb_MiniTableField field = {1, 0, 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -248,7 +248,7 @@ UPB_INLINE upb_Array* _google_protobuf_FileDescriptorSet_file_mutable_upb_array( upb_Array* arr = upb_Message_GetOrCreateMutableArray( (upb_Message*)msg, &field, arena); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -257,7 +257,7 @@ UPB_INLINE google_protobuf_FileDescriptorProto** google_protobuf_FileDescriptorS upb_MiniTableField field = {1, 0, 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetMutableArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_FileDescriptorProto**)_upb_array_ptr(arr); } else { if (size) *size = 0; @@ -271,12 +271,14 @@ UPB_INLINE google_protobuf_FileDescriptorProto** google_protobuf_FileDescriptorS UPB_INLINE struct google_protobuf_FileDescriptorProto* google_protobuf_FileDescriptorSet_add_file(google_protobuf_FileDescriptorSet* msg, upb_Arena* arena) { upb_MiniTableField field = {1, 0, 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); - if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { + if (!arr || !_upb_Array_ResizeUninitialized( + arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; } struct google_protobuf_FileDescriptorProto* sub = (struct google_protobuf_FileDescriptorProto*)_upb_Message_New(&google__protobuf__FileDescriptorProto_msg_init, arena); if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &sub, sizeof(sub)); + UPB_PRIVATE(_upb_Array_Set) + (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); return sub; } @@ -353,7 +355,7 @@ UPB_INLINE upb_StringView const* google_protobuf_FileDescriptorProto_dependency( const upb_MiniTableField field = {3, UPB_SIZE(4, 40), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (upb_StringView const*)_upb_array_constptr(arr); } else { if (size) *size = 0; @@ -364,7 +366,7 @@ UPB_INLINE const upb_Array* _google_protobuf_FileDescriptorProto_dependency_upb_ const upb_MiniTableField field = {3, UPB_SIZE(4, 40), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -373,7 +375,7 @@ UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_dependency_mutable_up upb_Array* arr = upb_Message_GetOrCreateMutableArray( (upb_Message*)msg, &field, arena); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -385,7 +387,7 @@ UPB_INLINE const google_protobuf_DescriptorProto* const* google_protobuf_FileDes const upb_MiniTableField field = {4, UPB_SIZE(8, 48), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_DescriptorProto* const*)_upb_array_constptr(arr); } else { if (size) *size = 0; @@ -396,7 +398,7 @@ UPB_INLINE const upb_Array* _google_protobuf_FileDescriptorProto_message_type_up const upb_MiniTableField field = {4, UPB_SIZE(8, 48), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -405,7 +407,7 @@ UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_message_type_mutable_ upb_Array* arr = upb_Message_GetOrCreateMutableArray( (upb_Message*)msg, &field, arena); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -417,7 +419,7 @@ UPB_INLINE const google_protobuf_EnumDescriptorProto* const* google_protobuf_Fil const upb_MiniTableField field = {5, UPB_SIZE(12, 56), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_EnumDescriptorProto* const*)_upb_array_constptr(arr); } else { if (size) *size = 0; @@ -428,7 +430,7 @@ UPB_INLINE const upb_Array* _google_protobuf_FileDescriptorProto_enum_type_upb_a const upb_MiniTableField field = {5, UPB_SIZE(12, 56), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -437,7 +439,7 @@ UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_enum_type_mutable_upb upb_Array* arr = upb_Message_GetOrCreateMutableArray( (upb_Message*)msg, &field, arena); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -449,7 +451,7 @@ UPB_INLINE const google_protobuf_ServiceDescriptorProto* const* google_protobuf_ const upb_MiniTableField field = {6, UPB_SIZE(16, 64), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_ServiceDescriptorProto* const*)_upb_array_constptr(arr); } else { if (size) *size = 0; @@ -460,7 +462,7 @@ UPB_INLINE const upb_Array* _google_protobuf_FileDescriptorProto_service_upb_arr const upb_MiniTableField field = {6, UPB_SIZE(16, 64), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -469,7 +471,7 @@ UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_service_mutable_upb_a upb_Array* arr = upb_Message_GetOrCreateMutableArray( (upb_Message*)msg, &field, arena); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -481,7 +483,7 @@ UPB_INLINE const google_protobuf_FieldDescriptorProto* const* google_protobuf_Fi const upb_MiniTableField field = {7, UPB_SIZE(20, 72), 0, 3, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_FieldDescriptorProto* const*)_upb_array_constptr(arr); } else { if (size) *size = 0; @@ -492,7 +494,7 @@ UPB_INLINE const upb_Array* _google_protobuf_FileDescriptorProto_extension_upb_a const upb_MiniTableField field = {7, UPB_SIZE(20, 72), 0, 3, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -501,7 +503,7 @@ UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_extension_mutable_upb upb_Array* arr = upb_Message_GetOrCreateMutableArray( (upb_Message*)msg, &field, arena); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -543,7 +545,7 @@ UPB_INLINE int32_t const* google_protobuf_FileDescriptorProto_public_dependency( const upb_MiniTableField field = {10, UPB_SIZE(32, 96), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (int32_t const*)_upb_array_constptr(arr); } else { if (size) *size = 0; @@ -554,7 +556,7 @@ UPB_INLINE const upb_Array* _google_protobuf_FileDescriptorProto_public_dependen const upb_MiniTableField field = {10, UPB_SIZE(32, 96), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -563,7 +565,7 @@ UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_public_dependency_mut upb_Array* arr = upb_Message_GetOrCreateMutableArray( (upb_Message*)msg, &field, arena); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -575,7 +577,7 @@ UPB_INLINE int32_t const* google_protobuf_FileDescriptorProto_weak_dependency(co const upb_MiniTableField field = {11, UPB_SIZE(36, 104), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (int32_t const*)_upb_array_constptr(arr); } else { if (size) *size = 0; @@ -586,7 +588,7 @@ UPB_INLINE const upb_Array* _google_protobuf_FileDescriptorProto_weak_dependency const upb_MiniTableField field = {11, UPB_SIZE(36, 104), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -595,7 +597,7 @@ UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_weak_dependency_mutab upb_Array* arr = upb_Message_GetOrCreateMutableArray( (upb_Message*)msg, &field, arena); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -642,7 +644,7 @@ UPB_INLINE upb_StringView* google_protobuf_FileDescriptorProto_mutable_dependenc upb_MiniTableField field = {3, UPB_SIZE(4, 40), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetMutableArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (upb_StringView*)_upb_array_ptr(arr); } else { if (size) *size = 0; @@ -656,17 +658,19 @@ UPB_INLINE upb_StringView* google_protobuf_FileDescriptorProto_resize_dependency UPB_INLINE bool google_protobuf_FileDescriptorProto_add_dependency(google_protobuf_FileDescriptorProto* msg, upb_StringView val, upb_Arena* arena) { upb_MiniTableField field = {3, UPB_SIZE(4, 40), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); - if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { + if (!arr || !_upb_Array_ResizeUninitialized( + arr, arr->UPB_PRIVATE(size) + 1, arena)) { return false; } - UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &val, sizeof(val)); + UPB_PRIVATE(_upb_Array_Set) + (arr, arr->UPB_PRIVATE(size) - 1, &val, sizeof(val)); return true; } UPB_INLINE google_protobuf_DescriptorProto** google_protobuf_FileDescriptorProto_mutable_message_type(google_protobuf_FileDescriptorProto* msg, size_t* size) { upb_MiniTableField field = {4, UPB_SIZE(8, 48), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetMutableArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_DescriptorProto**)_upb_array_ptr(arr); } else { if (size) *size = 0; @@ -680,19 +684,21 @@ UPB_INLINE google_protobuf_DescriptorProto** google_protobuf_FileDescriptorProto UPB_INLINE struct google_protobuf_DescriptorProto* google_protobuf_FileDescriptorProto_add_message_type(google_protobuf_FileDescriptorProto* msg, upb_Arena* arena) { upb_MiniTableField field = {4, UPB_SIZE(8, 48), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); - if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { + if (!arr || !_upb_Array_ResizeUninitialized( + arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; } struct google_protobuf_DescriptorProto* sub = (struct google_protobuf_DescriptorProto*)_upb_Message_New(&google__protobuf__DescriptorProto_msg_init, arena); if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &sub, sizeof(sub)); + UPB_PRIVATE(_upb_Array_Set) + (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); return sub; } UPB_INLINE google_protobuf_EnumDescriptorProto** google_protobuf_FileDescriptorProto_mutable_enum_type(google_protobuf_FileDescriptorProto* msg, size_t* size) { upb_MiniTableField field = {5, UPB_SIZE(12, 56), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetMutableArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_EnumDescriptorProto**)_upb_array_ptr(arr); } else { if (size) *size = 0; @@ -706,19 +712,21 @@ UPB_INLINE google_protobuf_EnumDescriptorProto** google_protobuf_FileDescriptorP UPB_INLINE struct google_protobuf_EnumDescriptorProto* google_protobuf_FileDescriptorProto_add_enum_type(google_protobuf_FileDescriptorProto* msg, upb_Arena* arena) { upb_MiniTableField field = {5, UPB_SIZE(12, 56), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); - if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { + if (!arr || !_upb_Array_ResizeUninitialized( + arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; } struct google_protobuf_EnumDescriptorProto* sub = (struct google_protobuf_EnumDescriptorProto*)_upb_Message_New(&google__protobuf__EnumDescriptorProto_msg_init, arena); if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &sub, sizeof(sub)); + UPB_PRIVATE(_upb_Array_Set) + (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); return sub; } UPB_INLINE google_protobuf_ServiceDescriptorProto** google_protobuf_FileDescriptorProto_mutable_service(google_protobuf_FileDescriptorProto* msg, size_t* size) { upb_MiniTableField field = {6, UPB_SIZE(16, 64), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetMutableArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_ServiceDescriptorProto**)_upb_array_ptr(arr); } else { if (size) *size = 0; @@ -732,19 +740,21 @@ UPB_INLINE google_protobuf_ServiceDescriptorProto** google_protobuf_FileDescript UPB_INLINE struct google_protobuf_ServiceDescriptorProto* google_protobuf_FileDescriptorProto_add_service(google_protobuf_FileDescriptorProto* msg, upb_Arena* arena) { upb_MiniTableField field = {6, UPB_SIZE(16, 64), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); - if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { + if (!arr || !_upb_Array_ResizeUninitialized( + arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; } struct google_protobuf_ServiceDescriptorProto* sub = (struct google_protobuf_ServiceDescriptorProto*)_upb_Message_New(&google__protobuf__ServiceDescriptorProto_msg_init, arena); if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &sub, sizeof(sub)); + UPB_PRIVATE(_upb_Array_Set) + (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); return sub; } UPB_INLINE google_protobuf_FieldDescriptorProto** google_protobuf_FileDescriptorProto_mutable_extension(google_protobuf_FileDescriptorProto* msg, size_t* size) { upb_MiniTableField field = {7, UPB_SIZE(20, 72), 0, 3, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetMutableArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_FieldDescriptorProto**)_upb_array_ptr(arr); } else { if (size) *size = 0; @@ -758,12 +768,14 @@ UPB_INLINE google_protobuf_FieldDescriptorProto** google_protobuf_FileDescriptor UPB_INLINE struct google_protobuf_FieldDescriptorProto* google_protobuf_FileDescriptorProto_add_extension(google_protobuf_FileDescriptorProto* msg, upb_Arena* arena) { upb_MiniTableField field = {7, UPB_SIZE(20, 72), 0, 3, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); - if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { + if (!arr || !_upb_Array_ResizeUninitialized( + arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; } struct google_protobuf_FieldDescriptorProto* sub = (struct google_protobuf_FieldDescriptorProto*)_upb_Message_New(&google__protobuf__FieldDescriptorProto_msg_init, arena); if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &sub, sizeof(sub)); + UPB_PRIVATE(_upb_Array_Set) + (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); return sub; } UPB_INLINE void google_protobuf_FileDescriptorProto_set_options(google_protobuf_FileDescriptorProto *msg, google_protobuf_FileOptions* value) { @@ -794,7 +806,7 @@ UPB_INLINE int32_t* google_protobuf_FileDescriptorProto_mutable_public_dependenc upb_MiniTableField field = {10, UPB_SIZE(32, 96), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetMutableArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (int32_t*)_upb_array_ptr(arr); } else { if (size) *size = 0; @@ -808,17 +820,19 @@ UPB_INLINE int32_t* google_protobuf_FileDescriptorProto_resize_public_dependency UPB_INLINE bool google_protobuf_FileDescriptorProto_add_public_dependency(google_protobuf_FileDescriptorProto* msg, int32_t val, upb_Arena* arena) { upb_MiniTableField field = {10, UPB_SIZE(32, 96), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); - if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { + if (!arr || !_upb_Array_ResizeUninitialized( + arr, arr->UPB_PRIVATE(size) + 1, arena)) { return false; } - UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &val, sizeof(val)); + UPB_PRIVATE(_upb_Array_Set) + (arr, arr->UPB_PRIVATE(size) - 1, &val, sizeof(val)); return true; } UPB_INLINE int32_t* google_protobuf_FileDescriptorProto_mutable_weak_dependency(google_protobuf_FileDescriptorProto* msg, size_t* size) { upb_MiniTableField field = {11, UPB_SIZE(36, 104), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetMutableArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (int32_t*)_upb_array_ptr(arr); } else { if (size) *size = 0; @@ -832,10 +846,12 @@ UPB_INLINE int32_t* google_protobuf_FileDescriptorProto_resize_weak_dependency(g UPB_INLINE bool google_protobuf_FileDescriptorProto_add_weak_dependency(google_protobuf_FileDescriptorProto* msg, int32_t val, upb_Arena* arena) { upb_MiniTableField field = {11, UPB_SIZE(36, 104), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); - if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { + if (!arr || !_upb_Array_ResizeUninitialized( + arr, arr->UPB_PRIVATE(size) + 1, arena)) { return false; } - UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &val, sizeof(val)); + UPB_PRIVATE(_upb_Array_Set) + (arr, arr->UPB_PRIVATE(size) - 1, &val, sizeof(val)); return true; } UPB_INLINE void google_protobuf_FileDescriptorProto_set_syntax(google_protobuf_FileDescriptorProto *msg, upb_StringView value) { @@ -905,7 +921,7 @@ UPB_INLINE const google_protobuf_FieldDescriptorProto* const* google_protobuf_De const upb_MiniTableField field = {2, UPB_SIZE(4, 24), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_FieldDescriptorProto* const*)_upb_array_constptr(arr); } else { if (size) *size = 0; @@ -916,7 +932,7 @@ UPB_INLINE const upb_Array* _google_protobuf_DescriptorProto_field_upb_array(con const upb_MiniTableField field = {2, UPB_SIZE(4, 24), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -925,7 +941,7 @@ UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_field_mutable_upb_array(c upb_Array* arr = upb_Message_GetOrCreateMutableArray( (upb_Message*)msg, &field, arena); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -937,7 +953,7 @@ UPB_INLINE const google_protobuf_DescriptorProto* const* google_protobuf_Descrip const upb_MiniTableField field = {3, UPB_SIZE(8, 32), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_DescriptorProto* const*)_upb_array_constptr(arr); } else { if (size) *size = 0; @@ -948,7 +964,7 @@ UPB_INLINE const upb_Array* _google_protobuf_DescriptorProto_nested_type_upb_arr const upb_MiniTableField field = {3, UPB_SIZE(8, 32), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -957,7 +973,7 @@ UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_nested_type_mutable_upb_a upb_Array* arr = upb_Message_GetOrCreateMutableArray( (upb_Message*)msg, &field, arena); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -969,7 +985,7 @@ UPB_INLINE const google_protobuf_EnumDescriptorProto* const* google_protobuf_Des const upb_MiniTableField field = {4, UPB_SIZE(12, 40), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_EnumDescriptorProto* const*)_upb_array_constptr(arr); } else { if (size) *size = 0; @@ -980,7 +996,7 @@ UPB_INLINE const upb_Array* _google_protobuf_DescriptorProto_enum_type_upb_array const upb_MiniTableField field = {4, UPB_SIZE(12, 40), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -989,7 +1005,7 @@ UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_enum_type_mutable_upb_arr upb_Array* arr = upb_Message_GetOrCreateMutableArray( (upb_Message*)msg, &field, arena); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -1001,7 +1017,7 @@ UPB_INLINE const google_protobuf_DescriptorProto_ExtensionRange* const* google_p const upb_MiniTableField field = {5, UPB_SIZE(16, 48), 0, 3, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_DescriptorProto_ExtensionRange* const*)_upb_array_constptr(arr); } else { if (size) *size = 0; @@ -1012,7 +1028,7 @@ UPB_INLINE const upb_Array* _google_protobuf_DescriptorProto_extension_range_upb const upb_MiniTableField field = {5, UPB_SIZE(16, 48), 0, 3, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -1021,7 +1037,7 @@ UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_extension_range_mutable_u upb_Array* arr = upb_Message_GetOrCreateMutableArray( (upb_Message*)msg, &field, arena); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -1033,7 +1049,7 @@ UPB_INLINE const google_protobuf_FieldDescriptorProto* const* google_protobuf_De const upb_MiniTableField field = {6, UPB_SIZE(20, 56), 0, 4, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_FieldDescriptorProto* const*)_upb_array_constptr(arr); } else { if (size) *size = 0; @@ -1044,7 +1060,7 @@ UPB_INLINE const upb_Array* _google_protobuf_DescriptorProto_extension_upb_array const upb_MiniTableField field = {6, UPB_SIZE(20, 56), 0, 4, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -1053,7 +1069,7 @@ UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_extension_mutable_upb_arr upb_Array* arr = upb_Message_GetOrCreateMutableArray( (upb_Message*)msg, &field, arena); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -1080,7 +1096,7 @@ UPB_INLINE const google_protobuf_OneofDescriptorProto* const* google_protobuf_De const upb_MiniTableField field = {8, UPB_SIZE(28, 72), 0, 6, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_OneofDescriptorProto* const*)_upb_array_constptr(arr); } else { if (size) *size = 0; @@ -1091,7 +1107,7 @@ UPB_INLINE const upb_Array* _google_protobuf_DescriptorProto_oneof_decl_upb_arra const upb_MiniTableField field = {8, UPB_SIZE(28, 72), 0, 6, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -1100,7 +1116,7 @@ UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_oneof_decl_mutable_upb_ar upb_Array* arr = upb_Message_GetOrCreateMutableArray( (upb_Message*)msg, &field, arena); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -1112,7 +1128,7 @@ UPB_INLINE const google_protobuf_DescriptorProto_ReservedRange* const* google_pr const upb_MiniTableField field = {9, UPB_SIZE(32, 80), 0, 7, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_DescriptorProto_ReservedRange* const*)_upb_array_constptr(arr); } else { if (size) *size = 0; @@ -1123,7 +1139,7 @@ UPB_INLINE const upb_Array* _google_protobuf_DescriptorProto_reserved_range_upb_ const upb_MiniTableField field = {9, UPB_SIZE(32, 80), 0, 7, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -1132,7 +1148,7 @@ UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_reserved_range_mutable_up upb_Array* arr = upb_Message_GetOrCreateMutableArray( (upb_Message*)msg, &field, arena); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -1144,7 +1160,7 @@ UPB_INLINE upb_StringView const* google_protobuf_DescriptorProto_reserved_name(c const upb_MiniTableField field = {10, UPB_SIZE(36, 88), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (upb_StringView const*)_upb_array_constptr(arr); } else { if (size) *size = 0; @@ -1155,7 +1171,7 @@ UPB_INLINE const upb_Array* _google_protobuf_DescriptorProto_reserved_name_upb_a const upb_MiniTableField field = {10, UPB_SIZE(36, 88), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -1164,7 +1180,7 @@ UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_reserved_name_mutable_upb upb_Array* arr = upb_Message_GetOrCreateMutableArray( (upb_Message*)msg, &field, arena); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -1177,7 +1193,7 @@ UPB_INLINE google_protobuf_FieldDescriptorProto** google_protobuf_DescriptorProt upb_MiniTableField field = {2, UPB_SIZE(4, 24), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetMutableArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_FieldDescriptorProto**)_upb_array_ptr(arr); } else { if (size) *size = 0; @@ -1191,19 +1207,21 @@ UPB_INLINE google_protobuf_FieldDescriptorProto** google_protobuf_DescriptorProt UPB_INLINE struct google_protobuf_FieldDescriptorProto* google_protobuf_DescriptorProto_add_field(google_protobuf_DescriptorProto* msg, upb_Arena* arena) { upb_MiniTableField field = {2, UPB_SIZE(4, 24), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); - if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { + if (!arr || !_upb_Array_ResizeUninitialized( + arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; } struct google_protobuf_FieldDescriptorProto* sub = (struct google_protobuf_FieldDescriptorProto*)_upb_Message_New(&google__protobuf__FieldDescriptorProto_msg_init, arena); if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &sub, sizeof(sub)); + UPB_PRIVATE(_upb_Array_Set) + (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); return sub; } UPB_INLINE google_protobuf_DescriptorProto** google_protobuf_DescriptorProto_mutable_nested_type(google_protobuf_DescriptorProto* msg, size_t* size) { upb_MiniTableField field = {3, UPB_SIZE(8, 32), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetMutableArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_DescriptorProto**)_upb_array_ptr(arr); } else { if (size) *size = 0; @@ -1217,19 +1235,21 @@ UPB_INLINE google_protobuf_DescriptorProto** google_protobuf_DescriptorProto_res UPB_INLINE struct google_protobuf_DescriptorProto* google_protobuf_DescriptorProto_add_nested_type(google_protobuf_DescriptorProto* msg, upb_Arena* arena) { upb_MiniTableField field = {3, UPB_SIZE(8, 32), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); - if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { + if (!arr || !_upb_Array_ResizeUninitialized( + arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; } struct google_protobuf_DescriptorProto* sub = (struct google_protobuf_DescriptorProto*)_upb_Message_New(&google__protobuf__DescriptorProto_msg_init, arena); if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &sub, sizeof(sub)); + UPB_PRIVATE(_upb_Array_Set) + (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); return sub; } UPB_INLINE google_protobuf_EnumDescriptorProto** google_protobuf_DescriptorProto_mutable_enum_type(google_protobuf_DescriptorProto* msg, size_t* size) { upb_MiniTableField field = {4, UPB_SIZE(12, 40), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetMutableArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_EnumDescriptorProto**)_upb_array_ptr(arr); } else { if (size) *size = 0; @@ -1243,19 +1263,21 @@ UPB_INLINE google_protobuf_EnumDescriptorProto** google_protobuf_DescriptorProto UPB_INLINE struct google_protobuf_EnumDescriptorProto* google_protobuf_DescriptorProto_add_enum_type(google_protobuf_DescriptorProto* msg, upb_Arena* arena) { upb_MiniTableField field = {4, UPB_SIZE(12, 40), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); - if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { + if (!arr || !_upb_Array_ResizeUninitialized( + arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; } struct google_protobuf_EnumDescriptorProto* sub = (struct google_protobuf_EnumDescriptorProto*)_upb_Message_New(&google__protobuf__EnumDescriptorProto_msg_init, arena); if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &sub, sizeof(sub)); + UPB_PRIVATE(_upb_Array_Set) + (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); return sub; } UPB_INLINE google_protobuf_DescriptorProto_ExtensionRange** google_protobuf_DescriptorProto_mutable_extension_range(google_protobuf_DescriptorProto* msg, size_t* size) { upb_MiniTableField field = {5, UPB_SIZE(16, 48), 0, 3, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetMutableArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_DescriptorProto_ExtensionRange**)_upb_array_ptr(arr); } else { if (size) *size = 0; @@ -1269,19 +1291,21 @@ UPB_INLINE google_protobuf_DescriptorProto_ExtensionRange** google_protobuf_Desc UPB_INLINE struct google_protobuf_DescriptorProto_ExtensionRange* google_protobuf_DescriptorProto_add_extension_range(google_protobuf_DescriptorProto* msg, upb_Arena* arena) { upb_MiniTableField field = {5, UPB_SIZE(16, 48), 0, 3, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); - if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { + if (!arr || !_upb_Array_ResizeUninitialized( + arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; } struct google_protobuf_DescriptorProto_ExtensionRange* sub = (struct google_protobuf_DescriptorProto_ExtensionRange*)_upb_Message_New(&google__protobuf__DescriptorProto__ExtensionRange_msg_init, arena); if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &sub, sizeof(sub)); + UPB_PRIVATE(_upb_Array_Set) + (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); return sub; } UPB_INLINE google_protobuf_FieldDescriptorProto** google_protobuf_DescriptorProto_mutable_extension(google_protobuf_DescriptorProto* msg, size_t* size) { upb_MiniTableField field = {6, UPB_SIZE(20, 56), 0, 4, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetMutableArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_FieldDescriptorProto**)_upb_array_ptr(arr); } else { if (size) *size = 0; @@ -1295,12 +1319,14 @@ UPB_INLINE google_protobuf_FieldDescriptorProto** google_protobuf_DescriptorProt UPB_INLINE struct google_protobuf_FieldDescriptorProto* google_protobuf_DescriptorProto_add_extension(google_protobuf_DescriptorProto* msg, upb_Arena* arena) { upb_MiniTableField field = {6, UPB_SIZE(20, 56), 0, 4, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); - if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { + if (!arr || !_upb_Array_ResizeUninitialized( + arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; } struct google_protobuf_FieldDescriptorProto* sub = (struct google_protobuf_FieldDescriptorProto*)_upb_Message_New(&google__protobuf__FieldDescriptorProto_msg_init, arena); if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &sub, sizeof(sub)); + UPB_PRIVATE(_upb_Array_Set) + (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); return sub; } UPB_INLINE void google_protobuf_DescriptorProto_set_options(google_protobuf_DescriptorProto *msg, google_protobuf_MessageOptions* value) { @@ -1319,7 +1345,7 @@ UPB_INLINE google_protobuf_OneofDescriptorProto** google_protobuf_DescriptorProt upb_MiniTableField field = {8, UPB_SIZE(28, 72), 0, 6, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetMutableArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_OneofDescriptorProto**)_upb_array_ptr(arr); } else { if (size) *size = 0; @@ -1333,19 +1359,21 @@ UPB_INLINE google_protobuf_OneofDescriptorProto** google_protobuf_DescriptorProt UPB_INLINE struct google_protobuf_OneofDescriptorProto* google_protobuf_DescriptorProto_add_oneof_decl(google_protobuf_DescriptorProto* msg, upb_Arena* arena) { upb_MiniTableField field = {8, UPB_SIZE(28, 72), 0, 6, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); - if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { + if (!arr || !_upb_Array_ResizeUninitialized( + arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; } struct google_protobuf_OneofDescriptorProto* sub = (struct google_protobuf_OneofDescriptorProto*)_upb_Message_New(&google__protobuf__OneofDescriptorProto_msg_init, arena); if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &sub, sizeof(sub)); + UPB_PRIVATE(_upb_Array_Set) + (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); return sub; } UPB_INLINE google_protobuf_DescriptorProto_ReservedRange** google_protobuf_DescriptorProto_mutable_reserved_range(google_protobuf_DescriptorProto* msg, size_t* size) { upb_MiniTableField field = {9, UPB_SIZE(32, 80), 0, 7, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetMutableArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_DescriptorProto_ReservedRange**)_upb_array_ptr(arr); } else { if (size) *size = 0; @@ -1359,19 +1387,21 @@ UPB_INLINE google_protobuf_DescriptorProto_ReservedRange** google_protobuf_Descr UPB_INLINE struct google_protobuf_DescriptorProto_ReservedRange* google_protobuf_DescriptorProto_add_reserved_range(google_protobuf_DescriptorProto* msg, upb_Arena* arena) { upb_MiniTableField field = {9, UPB_SIZE(32, 80), 0, 7, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); - if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { + if (!arr || !_upb_Array_ResizeUninitialized( + arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; } struct google_protobuf_DescriptorProto_ReservedRange* sub = (struct google_protobuf_DescriptorProto_ReservedRange*)_upb_Message_New(&google__protobuf__DescriptorProto__ReservedRange_msg_init, arena); if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &sub, sizeof(sub)); + UPB_PRIVATE(_upb_Array_Set) + (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); return sub; } UPB_INLINE upb_StringView* google_protobuf_DescriptorProto_mutable_reserved_name(google_protobuf_DescriptorProto* msg, size_t* size) { upb_MiniTableField field = {10, UPB_SIZE(36, 88), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetMutableArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (upb_StringView*)_upb_array_ptr(arr); } else { if (size) *size = 0; @@ -1385,10 +1415,12 @@ UPB_INLINE upb_StringView* google_protobuf_DescriptorProto_resize_reserved_name( UPB_INLINE bool google_protobuf_DescriptorProto_add_reserved_name(google_protobuf_DescriptorProto* msg, upb_StringView val, upb_Arena* arena) { upb_MiniTableField field = {10, UPB_SIZE(36, 88), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); - if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { + if (!arr || !_upb_Array_ResizeUninitialized( + arr, arr->UPB_PRIVATE(size) + 1, arena)) { return false; } - UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &val, sizeof(val)); + UPB_PRIVATE(_upb_Array_Set) + (arr, arr->UPB_PRIVATE(size) - 1, &val, sizeof(val)); return true; } @@ -1612,7 +1644,7 @@ UPB_INLINE const google_protobuf_ExtensionRangeOptions_Declaration* const* googl const upb_MiniTableField field = {2, UPB_SIZE(4, 8), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_ExtensionRangeOptions_Declaration* const*)_upb_array_constptr(arr); } else { if (size) *size = 0; @@ -1623,7 +1655,7 @@ UPB_INLINE const upb_Array* _google_protobuf_ExtensionRangeOptions_declaration_u const upb_MiniTableField field = {2, UPB_SIZE(4, 8), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -1632,7 +1664,7 @@ UPB_INLINE upb_Array* _google_protobuf_ExtensionRangeOptions_declaration_mutable upb_Array* arr = upb_Message_GetOrCreateMutableArray( (upb_Message*)msg, &field, arena); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -1674,7 +1706,7 @@ UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_Ext const upb_MiniTableField field = {999, UPB_SIZE(16, 24), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_UninterpretedOption* const*)_upb_array_constptr(arr); } else { if (size) *size = 0; @@ -1685,7 +1717,7 @@ UPB_INLINE const upb_Array* _google_protobuf_ExtensionRangeOptions_uninterpreted const upb_MiniTableField field = {999, UPB_SIZE(16, 24), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -1694,7 +1726,7 @@ UPB_INLINE upb_Array* _google_protobuf_ExtensionRangeOptions_uninterpreted_optio upb_Array* arr = upb_Message_GetOrCreateMutableArray( (upb_Message*)msg, &field, arena); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -1703,7 +1735,7 @@ UPB_INLINE google_protobuf_ExtensionRangeOptions_Declaration** google_protobuf_E upb_MiniTableField field = {2, UPB_SIZE(4, 8), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetMutableArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_ExtensionRangeOptions_Declaration**)_upb_array_ptr(arr); } else { if (size) *size = 0; @@ -1717,12 +1749,14 @@ UPB_INLINE google_protobuf_ExtensionRangeOptions_Declaration** google_protobuf_E UPB_INLINE struct google_protobuf_ExtensionRangeOptions_Declaration* google_protobuf_ExtensionRangeOptions_add_declaration(google_protobuf_ExtensionRangeOptions* msg, upb_Arena* arena) { upb_MiniTableField field = {2, UPB_SIZE(4, 8), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); - if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { + if (!arr || !_upb_Array_ResizeUninitialized( + arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; } struct google_protobuf_ExtensionRangeOptions_Declaration* sub = (struct google_protobuf_ExtensionRangeOptions_Declaration*)_upb_Message_New(&google__protobuf__ExtensionRangeOptions__Declaration_msg_init, arena); if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &sub, sizeof(sub)); + UPB_PRIVATE(_upb_Array_Set) + (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); return sub; } UPB_INLINE void google_protobuf_ExtensionRangeOptions_set_verification(google_protobuf_ExtensionRangeOptions *msg, int32_t value) { @@ -1745,7 +1779,7 @@ UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_ExtensionRangeO upb_MiniTableField field = {999, UPB_SIZE(16, 24), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetMutableArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_UninterpretedOption**)_upb_array_ptr(arr); } else { if (size) *size = 0; @@ -1759,12 +1793,14 @@ UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_ExtensionRangeO UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_ExtensionRangeOptions_add_uninterpreted_option(google_protobuf_ExtensionRangeOptions* msg, upb_Arena* arena) { upb_MiniTableField field = {999, UPB_SIZE(16, 24), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); - if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { + if (!arr || !_upb_Array_ResizeUninitialized( + arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; } struct google_protobuf_UninterpretedOption* sub = (struct google_protobuf_UninterpretedOption*)_upb_Message_New(&google__protobuf__UninterpretedOption_msg_init, arena); if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &sub, sizeof(sub)); + UPB_PRIVATE(_upb_Array_Set) + (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); return sub; } @@ -2295,7 +2331,7 @@ UPB_INLINE const google_protobuf_EnumValueDescriptorProto* const* google_protobu const upb_MiniTableField field = {2, UPB_SIZE(4, 24), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_EnumValueDescriptorProto* const*)_upb_array_constptr(arr); } else { if (size) *size = 0; @@ -2306,7 +2342,7 @@ UPB_INLINE const upb_Array* _google_protobuf_EnumDescriptorProto_value_upb_array const upb_MiniTableField field = {2, UPB_SIZE(4, 24), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -2315,7 +2351,7 @@ UPB_INLINE upb_Array* _google_protobuf_EnumDescriptorProto_value_mutable_upb_arr upb_Array* arr = upb_Message_GetOrCreateMutableArray( (upb_Message*)msg, &field, arena); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -2342,7 +2378,7 @@ UPB_INLINE const google_protobuf_EnumDescriptorProto_EnumReservedRange* const* g const upb_MiniTableField field = {4, UPB_SIZE(12, 40), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_EnumDescriptorProto_EnumReservedRange* const*)_upb_array_constptr(arr); } else { if (size) *size = 0; @@ -2353,7 +2389,7 @@ UPB_INLINE const upb_Array* _google_protobuf_EnumDescriptorProto_reserved_range_ const upb_MiniTableField field = {4, UPB_SIZE(12, 40), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -2362,7 +2398,7 @@ UPB_INLINE upb_Array* _google_protobuf_EnumDescriptorProto_reserved_range_mutabl upb_Array* arr = upb_Message_GetOrCreateMutableArray( (upb_Message*)msg, &field, arena); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -2374,7 +2410,7 @@ UPB_INLINE upb_StringView const* google_protobuf_EnumDescriptorProto_reserved_na const upb_MiniTableField field = {5, UPB_SIZE(16, 48), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (upb_StringView const*)_upb_array_constptr(arr); } else { if (size) *size = 0; @@ -2385,7 +2421,7 @@ UPB_INLINE const upb_Array* _google_protobuf_EnumDescriptorProto_reserved_name_u const upb_MiniTableField field = {5, UPB_SIZE(16, 48), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -2394,7 +2430,7 @@ UPB_INLINE upb_Array* _google_protobuf_EnumDescriptorProto_reserved_name_mutable upb_Array* arr = upb_Message_GetOrCreateMutableArray( (upb_Message*)msg, &field, arena); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -2407,7 +2443,7 @@ UPB_INLINE google_protobuf_EnumValueDescriptorProto** google_protobuf_EnumDescri upb_MiniTableField field = {2, UPB_SIZE(4, 24), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetMutableArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_EnumValueDescriptorProto**)_upb_array_ptr(arr); } else { if (size) *size = 0; @@ -2421,12 +2457,14 @@ UPB_INLINE google_protobuf_EnumValueDescriptorProto** google_protobuf_EnumDescri UPB_INLINE struct google_protobuf_EnumValueDescriptorProto* google_protobuf_EnumDescriptorProto_add_value(google_protobuf_EnumDescriptorProto* msg, upb_Arena* arena) { upb_MiniTableField field = {2, UPB_SIZE(4, 24), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); - if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { + if (!arr || !_upb_Array_ResizeUninitialized( + arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; } struct google_protobuf_EnumValueDescriptorProto* sub = (struct google_protobuf_EnumValueDescriptorProto*)_upb_Message_New(&google__protobuf__EnumValueDescriptorProto_msg_init, arena); if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &sub, sizeof(sub)); + UPB_PRIVATE(_upb_Array_Set) + (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); return sub; } UPB_INLINE void google_protobuf_EnumDescriptorProto_set_options(google_protobuf_EnumDescriptorProto *msg, google_protobuf_EnumOptions* value) { @@ -2445,7 +2483,7 @@ UPB_INLINE google_protobuf_EnumDescriptorProto_EnumReservedRange** google_protob upb_MiniTableField field = {4, UPB_SIZE(12, 40), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetMutableArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_EnumDescriptorProto_EnumReservedRange**)_upb_array_ptr(arr); } else { if (size) *size = 0; @@ -2459,19 +2497,21 @@ UPB_INLINE google_protobuf_EnumDescriptorProto_EnumReservedRange** google_protob UPB_INLINE struct google_protobuf_EnumDescriptorProto_EnumReservedRange* google_protobuf_EnumDescriptorProto_add_reserved_range(google_protobuf_EnumDescriptorProto* msg, upb_Arena* arena) { upb_MiniTableField field = {4, UPB_SIZE(12, 40), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); - if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { + if (!arr || !_upb_Array_ResizeUninitialized( + arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; } struct google_protobuf_EnumDescriptorProto_EnumReservedRange* sub = (struct google_protobuf_EnumDescriptorProto_EnumReservedRange*)_upb_Message_New(&google__protobuf__EnumDescriptorProto__EnumReservedRange_msg_init, arena); if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &sub, sizeof(sub)); + UPB_PRIVATE(_upb_Array_Set) + (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); return sub; } UPB_INLINE upb_StringView* google_protobuf_EnumDescriptorProto_mutable_reserved_name(google_protobuf_EnumDescriptorProto* msg, size_t* size) { upb_MiniTableField field = {5, UPB_SIZE(16, 48), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetMutableArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (upb_StringView*)_upb_array_ptr(arr); } else { if (size) *size = 0; @@ -2485,10 +2525,12 @@ UPB_INLINE upb_StringView* google_protobuf_EnumDescriptorProto_resize_reserved_n UPB_INLINE bool google_protobuf_EnumDescriptorProto_add_reserved_name(google_protobuf_EnumDescriptorProto* msg, upb_StringView val, upb_Arena* arena) { upb_MiniTableField field = {5, UPB_SIZE(16, 48), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); - if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { + if (!arr || !_upb_Array_ResizeUninitialized( + arr, arr->UPB_PRIVATE(size) + 1, arena)) { return false; } - UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &val, sizeof(val)); + UPB_PRIVATE(_upb_Array_Set) + (arr, arr->UPB_PRIVATE(size) - 1, &val, sizeof(val)); return true; } @@ -2727,7 +2769,7 @@ UPB_INLINE const google_protobuf_MethodDescriptorProto* const* google_protobuf_S const upb_MiniTableField field = {2, UPB_SIZE(4, 24), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_MethodDescriptorProto* const*)_upb_array_constptr(arr); } else { if (size) *size = 0; @@ -2738,7 +2780,7 @@ UPB_INLINE const upb_Array* _google_protobuf_ServiceDescriptorProto_method_upb_a const upb_MiniTableField field = {2, UPB_SIZE(4, 24), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -2747,7 +2789,7 @@ UPB_INLINE upb_Array* _google_protobuf_ServiceDescriptorProto_method_mutable_upb upb_Array* arr = upb_Message_GetOrCreateMutableArray( (upb_Message*)msg, &field, arena); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -2775,7 +2817,7 @@ UPB_INLINE google_protobuf_MethodDescriptorProto** google_protobuf_ServiceDescri upb_MiniTableField field = {2, UPB_SIZE(4, 24), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetMutableArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_MethodDescriptorProto**)_upb_array_ptr(arr); } else { if (size) *size = 0; @@ -2789,12 +2831,14 @@ UPB_INLINE google_protobuf_MethodDescriptorProto** google_protobuf_ServiceDescri UPB_INLINE struct google_protobuf_MethodDescriptorProto* google_protobuf_ServiceDescriptorProto_add_method(google_protobuf_ServiceDescriptorProto* msg, upb_Arena* arena) { upb_MiniTableField field = {2, UPB_SIZE(4, 24), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); - if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { + if (!arr || !_upb_Array_ResizeUninitialized( + arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; } struct google_protobuf_MethodDescriptorProto* sub = (struct google_protobuf_MethodDescriptorProto*)_upb_Message_New(&google__protobuf__MethodDescriptorProto_msg_init, arena); if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &sub, sizeof(sub)); + UPB_PRIVATE(_upb_Array_Set) + (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); return sub; } UPB_INLINE void google_protobuf_ServiceDescriptorProto_set_options(google_protobuf_ServiceDescriptorProto *msg, google_protobuf_ServiceOptions* value) { @@ -3327,7 +3371,7 @@ UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_Fil const upb_MiniTableField field = {999, UPB_SIZE(24, 192), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_UninterpretedOption* const*)_upb_array_constptr(arr); } else { if (size) *size = 0; @@ -3338,7 +3382,7 @@ UPB_INLINE const upb_Array* _google_protobuf_FileOptions_uninterpreted_option_up const upb_MiniTableField field = {999, UPB_SIZE(24, 192), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -3347,7 +3391,7 @@ UPB_INLINE upb_Array* _google_protobuf_FileOptions_uninterpreted_option_mutable_ upb_Array* arr = upb_Message_GetOrCreateMutableArray( (upb_Message*)msg, &field, arena); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -3448,7 +3492,7 @@ UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_FileOptions_mut upb_MiniTableField field = {999, UPB_SIZE(24, 192), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetMutableArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_UninterpretedOption**)_upb_array_ptr(arr); } else { if (size) *size = 0; @@ -3462,12 +3506,14 @@ UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_FileOptions_res UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_FileOptions_add_uninterpreted_option(google_protobuf_FileOptions* msg, upb_Arena* arena) { upb_MiniTableField field = {999, UPB_SIZE(24, 192), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); - if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { + if (!arr || !_upb_Array_ResizeUninitialized( + arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; } struct google_protobuf_UninterpretedOption* sub = (struct google_protobuf_UninterpretedOption*)_upb_Message_New(&google__protobuf__UninterpretedOption_msg_init, arena); if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &sub, sizeof(sub)); + UPB_PRIVATE(_upb_Array_Set) + (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); return sub; } @@ -3604,7 +3650,7 @@ UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_Mes const upb_MiniTableField field = {999, UPB_SIZE(12, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_UninterpretedOption* const*)_upb_array_constptr(arr); } else { if (size) *size = 0; @@ -3615,7 +3661,7 @@ UPB_INLINE const upb_Array* _google_protobuf_MessageOptions_uninterpreted_option const upb_MiniTableField field = {999, UPB_SIZE(12, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -3624,7 +3670,7 @@ UPB_INLINE upb_Array* _google_protobuf_MessageOptions_uninterpreted_option_mutab upb_Array* arr = upb_Message_GetOrCreateMutableArray( (upb_Message*)msg, &field, arena); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -3665,7 +3711,7 @@ UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_MessageOptions_ upb_MiniTableField field = {999, UPB_SIZE(12, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetMutableArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_UninterpretedOption**)_upb_array_ptr(arr); } else { if (size) *size = 0; @@ -3679,12 +3725,14 @@ UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_MessageOptions_ UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_MessageOptions_add_uninterpreted_option(google_protobuf_MessageOptions* msg, upb_Arena* arena) { upb_MiniTableField field = {999, UPB_SIZE(12, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); - if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { + if (!arr || !_upb_Array_ResizeUninitialized( + arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; } struct google_protobuf_UninterpretedOption* sub = (struct google_protobuf_UninterpretedOption*)_upb_Message_New(&google__protobuf__UninterpretedOption_msg_init, arena); if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &sub, sizeof(sub)); + UPB_PRIVATE(_upb_Array_Set) + (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); return sub; } @@ -3866,7 +3914,7 @@ UPB_INLINE int32_t const* google_protobuf_FieldOptions_targets(const google_prot const upb_MiniTableField field = {19, 24, 0, 6, 14, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (int32_t const*)_upb_array_constptr(arr); } else { if (size) *size = 0; @@ -3877,7 +3925,7 @@ UPB_INLINE const upb_Array* _google_protobuf_FieldOptions_targets_upb_array(cons const upb_MiniTableField field = {19, 24, 0, 6, 14, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -3886,7 +3934,7 @@ UPB_INLINE upb_Array* _google_protobuf_FieldOptions_targets_mutable_upb_array(co upb_Array* arr = upb_Message_GetOrCreateMutableArray( (upb_Message*)msg, &field, arena); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -3898,7 +3946,7 @@ UPB_INLINE const google_protobuf_FieldOptions_EditionDefault* const* google_prot const upb_MiniTableField field = {20, UPB_SIZE(28, 32), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_FieldOptions_EditionDefault* const*)_upb_array_constptr(arr); } else { if (size) *size = 0; @@ -3909,7 +3957,7 @@ UPB_INLINE const upb_Array* _google_protobuf_FieldOptions_edition_defaults_upb_a const upb_MiniTableField field = {20, UPB_SIZE(28, 32), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -3918,7 +3966,7 @@ UPB_INLINE upb_Array* _google_protobuf_FieldOptions_edition_defaults_mutable_upb upb_Array* arr = upb_Message_GetOrCreateMutableArray( (upb_Message*)msg, &field, arena); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -3945,7 +3993,7 @@ UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_Fie const upb_MiniTableField field = {999, UPB_SIZE(36, 48), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_UninterpretedOption* const*)_upb_array_constptr(arr); } else { if (size) *size = 0; @@ -3956,7 +4004,7 @@ UPB_INLINE const upb_Array* _google_protobuf_FieldOptions_uninterpreted_option_u const upb_MiniTableField field = {999, UPB_SIZE(36, 48), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -3965,7 +4013,7 @@ UPB_INLINE upb_Array* _google_protobuf_FieldOptions_uninterpreted_option_mutable upb_Array* arr = upb_Message_GetOrCreateMutableArray( (upb_Message*)msg, &field, arena); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -4010,7 +4058,7 @@ UPB_INLINE int32_t* google_protobuf_FieldOptions_mutable_targets(google_protobuf upb_MiniTableField field = {19, 24, 0, 6, 14, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetMutableArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (int32_t*)_upb_array_ptr(arr); } else { if (size) *size = 0; @@ -4024,17 +4072,19 @@ UPB_INLINE int32_t* google_protobuf_FieldOptions_resize_targets(google_protobuf_ UPB_INLINE bool google_protobuf_FieldOptions_add_targets(google_protobuf_FieldOptions* msg, int32_t val, upb_Arena* arena) { upb_MiniTableField field = {19, 24, 0, 6, 14, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); - if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { + if (!arr || !_upb_Array_ResizeUninitialized( + arr, arr->UPB_PRIVATE(size) + 1, arena)) { return false; } - UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &val, sizeof(val)); + UPB_PRIVATE(_upb_Array_Set) + (arr, arr->UPB_PRIVATE(size) - 1, &val, sizeof(val)); return true; } UPB_INLINE google_protobuf_FieldOptions_EditionDefault** google_protobuf_FieldOptions_mutable_edition_defaults(google_protobuf_FieldOptions* msg, size_t* size) { upb_MiniTableField field = {20, UPB_SIZE(28, 32), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetMutableArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_FieldOptions_EditionDefault**)_upb_array_ptr(arr); } else { if (size) *size = 0; @@ -4048,12 +4098,14 @@ UPB_INLINE google_protobuf_FieldOptions_EditionDefault** google_protobuf_FieldOp UPB_INLINE struct google_protobuf_FieldOptions_EditionDefault* google_protobuf_FieldOptions_add_edition_defaults(google_protobuf_FieldOptions* msg, upb_Arena* arena) { upb_MiniTableField field = {20, UPB_SIZE(28, 32), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); - if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { + if (!arr || !_upb_Array_ResizeUninitialized( + arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; } struct google_protobuf_FieldOptions_EditionDefault* sub = (struct google_protobuf_FieldOptions_EditionDefault*)_upb_Message_New(&google__protobuf__FieldOptions__EditionDefault_msg_init, arena); if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &sub, sizeof(sub)); + UPB_PRIVATE(_upb_Array_Set) + (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); return sub; } UPB_INLINE void google_protobuf_FieldOptions_set_features(google_protobuf_FieldOptions *msg, google_protobuf_FeatureSet* value) { @@ -4072,7 +4124,7 @@ UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_FieldOptions_mu upb_MiniTableField field = {999, UPB_SIZE(36, 48), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetMutableArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_UninterpretedOption**)_upb_array_ptr(arr); } else { if (size) *size = 0; @@ -4086,12 +4138,14 @@ UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_FieldOptions_re UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_FieldOptions_add_uninterpreted_option(google_protobuf_FieldOptions* msg, upb_Arena* arena) { upb_MiniTableField field = {999, UPB_SIZE(36, 48), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); - if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { + if (!arr || !_upb_Array_ResizeUninitialized( + arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; } struct google_protobuf_UninterpretedOption* sub = (struct google_protobuf_UninterpretedOption*)_upb_Message_New(&google__protobuf__UninterpretedOption_msg_init, arena); if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &sub, sizeof(sub)); + UPB_PRIVATE(_upb_Array_Set) + (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); return sub; } @@ -4228,7 +4282,7 @@ UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_One const upb_MiniTableField field = {999, UPB_SIZE(8, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_UninterpretedOption* const*)_upb_array_constptr(arr); } else { if (size) *size = 0; @@ -4239,7 +4293,7 @@ UPB_INLINE const upb_Array* _google_protobuf_OneofOptions_uninterpreted_option_u const upb_MiniTableField field = {999, UPB_SIZE(8, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -4248,7 +4302,7 @@ UPB_INLINE upb_Array* _google_protobuf_OneofOptions_uninterpreted_option_mutable upb_Array* arr = upb_Message_GetOrCreateMutableArray( (upb_Message*)msg, &field, arena); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -4269,7 +4323,7 @@ UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_OneofOptions_mu upb_MiniTableField field = {999, UPB_SIZE(8, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetMutableArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_UninterpretedOption**)_upb_array_ptr(arr); } else { if (size) *size = 0; @@ -4283,12 +4337,14 @@ UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_OneofOptions_re UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_OneofOptions_add_uninterpreted_option(google_protobuf_OneofOptions* msg, upb_Arena* arena) { upb_MiniTableField field = {999, UPB_SIZE(8, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); - if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { + if (!arr || !_upb_Array_ResizeUninitialized( + arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; } struct google_protobuf_UninterpretedOption* sub = (struct google_protobuf_UninterpretedOption*)_upb_Message_New(&google__protobuf__UninterpretedOption_msg_init, arena); if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &sub, sizeof(sub)); + UPB_PRIVATE(_upb_Array_Set) + (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); return sub; } @@ -4395,7 +4451,7 @@ UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_Enu const upb_MiniTableField field = {999, UPB_SIZE(8, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_UninterpretedOption* const*)_upb_array_constptr(arr); } else { if (size) *size = 0; @@ -4406,7 +4462,7 @@ UPB_INLINE const upb_Array* _google_protobuf_EnumOptions_uninterpreted_option_up const upb_MiniTableField field = {999, UPB_SIZE(8, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -4415,7 +4471,7 @@ UPB_INLINE upb_Array* _google_protobuf_EnumOptions_uninterpreted_option_mutable_ upb_Array* arr = upb_Message_GetOrCreateMutableArray( (upb_Message*)msg, &field, arena); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -4448,7 +4504,7 @@ UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_EnumOptions_mut upb_MiniTableField field = {999, UPB_SIZE(8, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetMutableArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_UninterpretedOption**)_upb_array_ptr(arr); } else { if (size) *size = 0; @@ -4462,12 +4518,14 @@ UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_EnumOptions_res UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_EnumOptions_add_uninterpreted_option(google_protobuf_EnumOptions* msg, upb_Arena* arena) { upb_MiniTableField field = {999, UPB_SIZE(8, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); - if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { + if (!arr || !_upb_Array_ResizeUninitialized( + arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; } struct google_protobuf_UninterpretedOption* sub = (struct google_protobuf_UninterpretedOption*)_upb_Message_New(&google__protobuf__UninterpretedOption_msg_init, arena); if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &sub, sizeof(sub)); + UPB_PRIVATE(_upb_Array_Set) + (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); return sub; } @@ -4559,7 +4617,7 @@ UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_Enu const upb_MiniTableField field = {999, UPB_SIZE(12, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_UninterpretedOption* const*)_upb_array_constptr(arr); } else { if (size) *size = 0; @@ -4570,7 +4628,7 @@ UPB_INLINE const upb_Array* _google_protobuf_EnumValueOptions_uninterpreted_opti const upb_MiniTableField field = {999, UPB_SIZE(12, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -4579,7 +4637,7 @@ UPB_INLINE upb_Array* _google_protobuf_EnumValueOptions_uninterpreted_option_mut upb_Array* arr = upb_Message_GetOrCreateMutableArray( (upb_Message*)msg, &field, arena); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -4608,7 +4666,7 @@ UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_EnumValueOption upb_MiniTableField field = {999, UPB_SIZE(12, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetMutableArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_UninterpretedOption**)_upb_array_ptr(arr); } else { if (size) *size = 0; @@ -4622,12 +4680,14 @@ UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_EnumValueOption UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_EnumValueOptions_add_uninterpreted_option(google_protobuf_EnumValueOptions* msg, upb_Arena* arena) { upb_MiniTableField field = {999, UPB_SIZE(12, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); - if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { + if (!arr || !_upb_Array_ResizeUninitialized( + arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; } struct google_protobuf_UninterpretedOption* sub = (struct google_protobuf_UninterpretedOption*)_upb_Message_New(&google__protobuf__UninterpretedOption_msg_init, arena); if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &sub, sizeof(sub)); + UPB_PRIVATE(_upb_Array_Set) + (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); return sub; } @@ -4704,7 +4764,7 @@ UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_Ser const upb_MiniTableField field = {999, UPB_SIZE(8, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_UninterpretedOption* const*)_upb_array_constptr(arr); } else { if (size) *size = 0; @@ -4715,7 +4775,7 @@ UPB_INLINE const upb_Array* _google_protobuf_ServiceOptions_uninterpreted_option const upb_MiniTableField field = {999, UPB_SIZE(8, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -4724,7 +4784,7 @@ UPB_INLINE upb_Array* _google_protobuf_ServiceOptions_uninterpreted_option_mutab upb_Array* arr = upb_Message_GetOrCreateMutableArray( (upb_Message*)msg, &field, arena); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -4749,7 +4809,7 @@ UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_ServiceOptions_ upb_MiniTableField field = {999, UPB_SIZE(8, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetMutableArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_UninterpretedOption**)_upb_array_ptr(arr); } else { if (size) *size = 0; @@ -4763,12 +4823,14 @@ UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_ServiceOptions_ UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_ServiceOptions_add_uninterpreted_option(google_protobuf_ServiceOptions* msg, upb_Arena* arena) { upb_MiniTableField field = {999, UPB_SIZE(8, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); - if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { + if (!arr || !_upb_Array_ResizeUninitialized( + arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; } struct google_protobuf_UninterpretedOption* sub = (struct google_protobuf_UninterpretedOption*)_upb_Message_New(&google__protobuf__UninterpretedOption_msg_init, arena); if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &sub, sizeof(sub)); + UPB_PRIVATE(_upb_Array_Set) + (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); return sub; } @@ -4860,7 +4922,7 @@ UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_Met const upb_MiniTableField field = {999, UPB_SIZE(12, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_UninterpretedOption* const*)_upb_array_constptr(arr); } else { if (size) *size = 0; @@ -4871,7 +4933,7 @@ UPB_INLINE const upb_Array* _google_protobuf_MethodOptions_uninterpreted_option_ const upb_MiniTableField field = {999, UPB_SIZE(12, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -4880,7 +4942,7 @@ UPB_INLINE upb_Array* _google_protobuf_MethodOptions_uninterpreted_option_mutabl upb_Array* arr = upb_Message_GetOrCreateMutableArray( (upb_Message*)msg, &field, arena); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -4909,7 +4971,7 @@ UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_MethodOptions_m upb_MiniTableField field = {999, UPB_SIZE(12, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetMutableArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_UninterpretedOption**)_upb_array_ptr(arr); } else { if (size) *size = 0; @@ -4923,12 +4985,14 @@ UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_MethodOptions_r UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_MethodOptions_add_uninterpreted_option(google_protobuf_MethodOptions* msg, upb_Arena* arena) { upb_MiniTableField field = {999, UPB_SIZE(12, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); - if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { + if (!arr || !_upb_Array_ResizeUninitialized( + arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; } struct google_protobuf_UninterpretedOption* sub = (struct google_protobuf_UninterpretedOption*)_upb_Message_New(&google__protobuf__UninterpretedOption_msg_init, arena); if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &sub, sizeof(sub)); + UPB_PRIVATE(_upb_Array_Set) + (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); return sub; } @@ -4975,7 +5039,7 @@ UPB_INLINE const google_protobuf_UninterpretedOption_NamePart* const* google_pro const upb_MiniTableField field = {2, UPB_SIZE(4, 8), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_UninterpretedOption_NamePart* const*)_upb_array_constptr(arr); } else { if (size) *size = 0; @@ -4986,7 +5050,7 @@ UPB_INLINE const upb_Array* _google_protobuf_UninterpretedOption_name_upb_array( const upb_MiniTableField field = {2, UPB_SIZE(4, 8), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -4995,7 +5059,7 @@ UPB_INLINE upb_Array* _google_protobuf_UninterpretedOption_name_mutable_upb_arra upb_Array* arr = upb_Message_GetOrCreateMutableArray( (upb_Message*)msg, &field, arena); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -5094,7 +5158,7 @@ UPB_INLINE google_protobuf_UninterpretedOption_NamePart** google_protobuf_Uninte upb_MiniTableField field = {2, UPB_SIZE(4, 8), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetMutableArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_UninterpretedOption_NamePart**)_upb_array_ptr(arr); } else { if (size) *size = 0; @@ -5108,12 +5172,14 @@ UPB_INLINE google_protobuf_UninterpretedOption_NamePart** google_protobuf_Uninte UPB_INLINE struct google_protobuf_UninterpretedOption_NamePart* google_protobuf_UninterpretedOption_add_name(google_protobuf_UninterpretedOption* msg, upb_Arena* arena) { upb_MiniTableField field = {2, UPB_SIZE(4, 8), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); - if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { + if (!arr || !_upb_Array_ResizeUninitialized( + arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; } struct google_protobuf_UninterpretedOption_NamePart* sub = (struct google_protobuf_UninterpretedOption_NamePart*)_upb_Message_New(&google__protobuf__UninterpretedOption__NamePart_msg_init, arena); if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &sub, sizeof(sub)); + UPB_PRIVATE(_upb_Array_Set) + (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); return sub; } UPB_INLINE void google_protobuf_UninterpretedOption_set_identifier_value(google_protobuf_UninterpretedOption *msg, upb_StringView value) { @@ -5410,7 +5476,7 @@ UPB_INLINE const google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* co const upb_MiniTableField field = {1, UPB_SIZE(4, 16), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* const*)_upb_array_constptr(arr); } else { if (size) *size = 0; @@ -5421,7 +5487,7 @@ UPB_INLINE const upb_Array* _google_protobuf_FeatureSetDefaults_defaults_upb_arr const upb_MiniTableField field = {1, UPB_SIZE(4, 16), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -5430,7 +5496,7 @@ UPB_INLINE upb_Array* _google_protobuf_FeatureSetDefaults_defaults_mutable_upb_a upb_Array* arr = upb_Message_GetOrCreateMutableArray( (upb_Message*)msg, &field, arena); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -5469,7 +5535,7 @@ UPB_INLINE google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault** google_ upb_MiniTableField field = {1, UPB_SIZE(4, 16), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetMutableArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault**)_upb_array_ptr(arr); } else { if (size) *size = 0; @@ -5483,12 +5549,14 @@ UPB_INLINE google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault** google_ UPB_INLINE struct google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* google_protobuf_FeatureSetDefaults_add_defaults(google_protobuf_FeatureSetDefaults* msg, upb_Arena* arena) { upb_MiniTableField field = {1, UPB_SIZE(4, 16), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); - if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { + if (!arr || !_upb_Array_ResizeUninitialized( + arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; } struct google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* sub = (struct google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault*)_upb_Message_New(&google__protobuf__FeatureSetDefaults__FeatureSetEditionDefault_msg_init, arena); if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &sub, sizeof(sub)); + UPB_PRIVATE(_upb_Array_Set) + (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); return sub; } UPB_INLINE void google_protobuf_FeatureSetDefaults_set_minimum_edition(google_protobuf_FeatureSetDefaults *msg, int32_t value) { @@ -5626,7 +5694,7 @@ UPB_INLINE const google_protobuf_SourceCodeInfo_Location* const* google_protobuf const upb_MiniTableField field = {1, 0, 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_SourceCodeInfo_Location* const*)_upb_array_constptr(arr); } else { if (size) *size = 0; @@ -5637,7 +5705,7 @@ UPB_INLINE const upb_Array* _google_protobuf_SourceCodeInfo_location_upb_array(c const upb_MiniTableField field = {1, 0, 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -5646,7 +5714,7 @@ UPB_INLINE upb_Array* _google_protobuf_SourceCodeInfo_location_mutable_upb_array upb_Array* arr = upb_Message_GetOrCreateMutableArray( (upb_Message*)msg, &field, arena); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -5655,7 +5723,7 @@ UPB_INLINE google_protobuf_SourceCodeInfo_Location** google_protobuf_SourceCodeI upb_MiniTableField field = {1, 0, 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetMutableArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_SourceCodeInfo_Location**)_upb_array_ptr(arr); } else { if (size) *size = 0; @@ -5669,12 +5737,14 @@ UPB_INLINE google_protobuf_SourceCodeInfo_Location** google_protobuf_SourceCodeI UPB_INLINE struct google_protobuf_SourceCodeInfo_Location* google_protobuf_SourceCodeInfo_add_location(google_protobuf_SourceCodeInfo* msg, upb_Arena* arena) { upb_MiniTableField field = {1, 0, 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); - if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { + if (!arr || !_upb_Array_ResizeUninitialized( + arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; } struct google_protobuf_SourceCodeInfo_Location* sub = (struct google_protobuf_SourceCodeInfo_Location*)_upb_Message_New(&google__protobuf__SourceCodeInfo__Location_msg_init, arena); if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &sub, sizeof(sub)); + UPB_PRIVATE(_upb_Array_Set) + (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); return sub; } @@ -5721,7 +5791,7 @@ UPB_INLINE int32_t const* google_protobuf_SourceCodeInfo_Location_path(const goo const upb_MiniTableField field = {1, UPB_SIZE(4, 8), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsPacked | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (int32_t const*)_upb_array_constptr(arr); } else { if (size) *size = 0; @@ -5732,7 +5802,7 @@ UPB_INLINE const upb_Array* _google_protobuf_SourceCodeInfo_Location_path_upb_ar const upb_MiniTableField field = {1, UPB_SIZE(4, 8), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsPacked | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -5741,7 +5811,7 @@ UPB_INLINE upb_Array* _google_protobuf_SourceCodeInfo_Location_path_mutable_upb_ upb_Array* arr = upb_Message_GetOrCreateMutableArray( (upb_Message*)msg, &field, arena); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -5753,7 +5823,7 @@ UPB_INLINE int32_t const* google_protobuf_SourceCodeInfo_Location_span(const goo const upb_MiniTableField field = {2, UPB_SIZE(8, 16), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsPacked | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (int32_t const*)_upb_array_constptr(arr); } else { if (size) *size = 0; @@ -5764,7 +5834,7 @@ UPB_INLINE const upb_Array* _google_protobuf_SourceCodeInfo_Location_span_upb_ar const upb_MiniTableField field = {2, UPB_SIZE(8, 16), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsPacked | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -5773,7 +5843,7 @@ UPB_INLINE upb_Array* _google_protobuf_SourceCodeInfo_Location_span_mutable_upb_ upb_Array* arr = upb_Message_GetOrCreateMutableArray( (upb_Message*)msg, &field, arena); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -5815,7 +5885,7 @@ UPB_INLINE upb_StringView const* google_protobuf_SourceCodeInfo_Location_leading const upb_MiniTableField field = {6, UPB_SIZE(12, 56), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (upb_StringView const*)_upb_array_constptr(arr); } else { if (size) *size = 0; @@ -5826,7 +5896,7 @@ UPB_INLINE const upb_Array* _google_protobuf_SourceCodeInfo_Location_leading_det const upb_MiniTableField field = {6, UPB_SIZE(12, 56), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -5835,7 +5905,7 @@ UPB_INLINE upb_Array* _google_protobuf_SourceCodeInfo_Location_leading_detached_ upb_Array* arr = upb_Message_GetOrCreateMutableArray( (upb_Message*)msg, &field, arena); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -5844,7 +5914,7 @@ UPB_INLINE int32_t* google_protobuf_SourceCodeInfo_Location_mutable_path(google_ upb_MiniTableField field = {1, UPB_SIZE(4, 8), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsPacked | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetMutableArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (int32_t*)_upb_array_ptr(arr); } else { if (size) *size = 0; @@ -5858,17 +5928,19 @@ UPB_INLINE int32_t* google_protobuf_SourceCodeInfo_Location_resize_path(google_p UPB_INLINE bool google_protobuf_SourceCodeInfo_Location_add_path(google_protobuf_SourceCodeInfo_Location* msg, int32_t val, upb_Arena* arena) { upb_MiniTableField field = {1, UPB_SIZE(4, 8), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsPacked | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); - if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { + if (!arr || !_upb_Array_ResizeUninitialized( + arr, arr->UPB_PRIVATE(size) + 1, arena)) { return false; } - UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &val, sizeof(val)); + UPB_PRIVATE(_upb_Array_Set) + (arr, arr->UPB_PRIVATE(size) - 1, &val, sizeof(val)); return true; } UPB_INLINE int32_t* google_protobuf_SourceCodeInfo_Location_mutable_span(google_protobuf_SourceCodeInfo_Location* msg, size_t* size) { upb_MiniTableField field = {2, UPB_SIZE(8, 16), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsPacked | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetMutableArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (int32_t*)_upb_array_ptr(arr); } else { if (size) *size = 0; @@ -5882,10 +5954,12 @@ UPB_INLINE int32_t* google_protobuf_SourceCodeInfo_Location_resize_span(google_p UPB_INLINE bool google_protobuf_SourceCodeInfo_Location_add_span(google_protobuf_SourceCodeInfo_Location* msg, int32_t val, upb_Arena* arena) { upb_MiniTableField field = {2, UPB_SIZE(8, 16), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsPacked | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); - if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { + if (!arr || !_upb_Array_ResizeUninitialized( + arr, arr->UPB_PRIVATE(size) + 1, arena)) { return false; } - UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &val, sizeof(val)); + UPB_PRIVATE(_upb_Array_Set) + (arr, arr->UPB_PRIVATE(size) - 1, &val, sizeof(val)); return true; } UPB_INLINE void google_protobuf_SourceCodeInfo_Location_set_leading_comments(google_protobuf_SourceCodeInfo_Location *msg, upb_StringView value) { @@ -5900,7 +5974,7 @@ UPB_INLINE upb_StringView* google_protobuf_SourceCodeInfo_Location_mutable_leadi upb_MiniTableField field = {6, UPB_SIZE(12, 56), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetMutableArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (upb_StringView*)_upb_array_ptr(arr); } else { if (size) *size = 0; @@ -5914,10 +5988,12 @@ UPB_INLINE upb_StringView* google_protobuf_SourceCodeInfo_Location_resize_leadin UPB_INLINE bool google_protobuf_SourceCodeInfo_Location_add_leading_detached_comments(google_protobuf_SourceCodeInfo_Location* msg, upb_StringView val, upb_Arena* arena) { upb_MiniTableField field = {6, UPB_SIZE(12, 56), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); - if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { + if (!arr || !_upb_Array_ResizeUninitialized( + arr, arr->UPB_PRIVATE(size) + 1, arena)) { return false; } - UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &val, sizeof(val)); + UPB_PRIVATE(_upb_Array_Set) + (arr, arr->UPB_PRIVATE(size) - 1, &val, sizeof(val)); return true; } @@ -5964,7 +6040,7 @@ UPB_INLINE const google_protobuf_GeneratedCodeInfo_Annotation* const* google_pro const upb_MiniTableField field = {1, 0, 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_GeneratedCodeInfo_Annotation* const*)_upb_array_constptr(arr); } else { if (size) *size = 0; @@ -5975,7 +6051,7 @@ UPB_INLINE const upb_Array* _google_protobuf_GeneratedCodeInfo_annotation_upb_ar const upb_MiniTableField field = {1, 0, 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -5984,7 +6060,7 @@ UPB_INLINE upb_Array* _google_protobuf_GeneratedCodeInfo_annotation_mutable_upb_ upb_Array* arr = upb_Message_GetOrCreateMutableArray( (upb_Message*)msg, &field, arena); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -5993,7 +6069,7 @@ UPB_INLINE google_protobuf_GeneratedCodeInfo_Annotation** google_protobuf_Genera upb_MiniTableField field = {1, 0, 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetMutableArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_GeneratedCodeInfo_Annotation**)_upb_array_ptr(arr); } else { if (size) *size = 0; @@ -6007,12 +6083,14 @@ UPB_INLINE google_protobuf_GeneratedCodeInfo_Annotation** google_protobuf_Genera UPB_INLINE struct google_protobuf_GeneratedCodeInfo_Annotation* google_protobuf_GeneratedCodeInfo_add_annotation(google_protobuf_GeneratedCodeInfo* msg, upb_Arena* arena) { upb_MiniTableField field = {1, 0, 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); - if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { + if (!arr || !_upb_Array_ResizeUninitialized( + arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; } struct google_protobuf_GeneratedCodeInfo_Annotation* sub = (struct google_protobuf_GeneratedCodeInfo_Annotation*)_upb_Message_New(&google__protobuf__GeneratedCodeInfo__Annotation_msg_init, arena); if (!arr || !sub) return NULL; - UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &sub, sizeof(sub)); + UPB_PRIVATE(_upb_Array_Set) + (arr, arr->UPB_PRIVATE(size) - 1, &sub, sizeof(sub)); return sub; } @@ -6059,7 +6137,7 @@ UPB_INLINE int32_t const* google_protobuf_GeneratedCodeInfo_Annotation_path(cons const upb_MiniTableField field = {1, UPB_SIZE(4, 16), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsPacked | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (int32_t const*)_upb_array_constptr(arr); } else { if (size) *size = 0; @@ -6070,7 +6148,7 @@ UPB_INLINE const upb_Array* _google_protobuf_GeneratedCodeInfo_Annotation_path_u const upb_MiniTableField field = {1, UPB_SIZE(4, 16), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsPacked | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -6079,7 +6157,7 @@ UPB_INLINE upb_Array* _google_protobuf_GeneratedCodeInfo_Annotation_path_mutable upb_Array* arr = upb_Message_GetOrCreateMutableArray( (upb_Message*)msg, &field, arena); if (size) { - *size = arr ? arr->size : 0; + *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } @@ -6148,7 +6226,7 @@ UPB_INLINE int32_t* google_protobuf_GeneratedCodeInfo_Annotation_mutable_path(go upb_MiniTableField field = {1, UPB_SIZE(4, 16), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsPacked | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetMutableArray(msg, &field); if (arr) { - if (size) *size = arr->size; + if (size) *size = arr->UPB_PRIVATE(size); return (int32_t*)_upb_array_ptr(arr); } else { if (size) *size = 0; @@ -6162,10 +6240,12 @@ UPB_INLINE int32_t* google_protobuf_GeneratedCodeInfo_Annotation_resize_path(goo UPB_INLINE bool google_protobuf_GeneratedCodeInfo_Annotation_add_path(google_protobuf_GeneratedCodeInfo_Annotation* msg, int32_t val, upb_Arena* arena) { upb_MiniTableField field = {1, UPB_SIZE(4, 16), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsPacked | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); - if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { + if (!arr || !_upb_Array_ResizeUninitialized( + arr, arr->UPB_PRIVATE(size) + 1, arena)) { return false; } - UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &val, sizeof(val)); + UPB_PRIVATE(_upb_Array_Set) + (arr, arr->UPB_PRIVATE(size) - 1, &val, sizeof(val)); return true; } UPB_INLINE void google_protobuf_GeneratedCodeInfo_Annotation_set_source_file(google_protobuf_GeneratedCodeInfo_Annotation *msg, upb_StringView value) { From 7315f6d398d2d18443b26c513cbdcdbffaeebaa3 Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Mon, 18 Dec 2023 17:56:29 -0800 Subject: [PATCH 046/255] lzcnt enabled varint size calculation for proto The x86 microbenchmark speedups here are only representative for packed repeated primitive fields, as they benefit from some improved vectorization. For normal cases like non-repeated fields, the util/coding microbenchmarks showed roughly 18% for arm and 2-3% for 32 bit x86, 10% for 64 bit x86 (including loop overhead) PiperOrigin-RevId: 592061508 --- src/google/protobuf/io/coded_stream.h | 67 ++++++++++++++++++++------- 1 file changed, 49 insertions(+), 18 deletions(-) diff --git a/src/google/protobuf/io/coded_stream.h b/src/google/protobuf/io/coded_stream.h index 97d62e49001b9..7e4f6a57e81e5 100644 --- a/src/google/protobuf/io/coded_stream.h +++ b/src/google/protobuf/io/coded_stream.h @@ -1704,38 +1704,68 @@ inline uint8_t* CodedOutputStream::WriteTagToArray(uint32_t value, return WriteVarint32ToArray(value, target); } +#if (defined(__x86__) || defined(__x86_64__) || defined(_M_IX86) || \ + defined(_M_X64)) && \ + !(defined(__LZCNT__) || defined(__AVX2__)) +// X86 CPUs lacking the lzcnt instruction are faster with the bsr-based +// implementation. MSVC does not define __LZCNT__, the nearest option that +// it interprets as lzcnt availability is __AVX2__. +#define PROTOBUF_CODED_STREAM_H_PREFER_BSR 1 +#else +#define PROTOBUF_CODED_STREAM_H_PREFER_BSR 0 +#endif inline size_t CodedOutputStream::VarintSize32(uint32_t value) { - // This computes value == 0 ? 1 : floor(log2(value)) / 7 + 1 - // Use an explicit multiplication to implement the divide of - // a number in the 1..31 range. - // +#if PROTOBUF_CODED_STREAM_H_PREFER_BSR // Explicit OR 0x1 to avoid calling absl::countl_zero(0), which - // requires a branch to check for on many platforms. - uint32_t log2value = 31 - absl::countl_zero(value | 0x1); - return static_cast((log2value * 9 + 73) / 64); + // requires a branch to check for on platforms without a clz instruction. + uint32_t log2value = (std::numeric_limits::digits - 1) - + absl::countl_zero(value | 0x1); + return static_cast((log2value * 9 + (64 + 9)) / 64); +#else + uint32_t clz = absl::countl_zero(value); + return static_cast( + ((std::numeric_limits::digits * 9 + 64) - (clz * 9)) / 64); +#endif } inline size_t CodedOutputStream::VarintSize32PlusOne(uint32_t value) { // Same as above, but one more. - uint32_t log2value = 31 - absl::countl_zero(value | 0x1); - return static_cast((log2value * 9 + 73 + 64) / 64); +#if PROTOBUF_CODED_STREAM_H_PREFER_BSR + uint32_t log2value = (std::numeric_limits::digits - 1) - + absl::countl_zero(value | 0x1); + return static_cast((log2value * 9 + (64 + 9) + 64) / 64); +#else + uint32_t clz = absl::countl_zero(value); + return static_cast( + ((std::numeric_limits::digits * 9 + 64 + 64) - (clz * 9)) / 64); +#endif } inline size_t CodedOutputStream::VarintSize64(uint64_t value) { - // This computes value == 0 ? 1 : floor(log2(value)) / 7 + 1 - // Use an explicit multiplication to implement the divide of - // a number in the 1..63 range. - // +#if PROTOBUF_CODED_STREAM_H_PREFER_BSR // Explicit OR 0x1 to avoid calling absl::countl_zero(0), which - // requires a branch to check for on many platforms. - uint32_t log2value = 63 - absl::countl_zero(value | 0x1); - return static_cast((log2value * 9 + 73) / 64); + // requires a branch to check for on platforms without a clz instruction. + uint32_t log2value = (std::numeric_limits::digits - 1) - + absl::countl_zero(value | 0x1); + return static_cast((log2value * 9 + (64 + 9)) / 64); +#else + uint32_t clz = absl::countl_zero(value); + return static_cast( + ((std::numeric_limits::digits * 9 + 64) - (clz * 9)) / 64); +#endif } inline size_t CodedOutputStream::VarintSize64PlusOne(uint64_t value) { // Same as above, but one more. - uint32_t log2value = 63 - absl::countl_zero(value | 0x1); - return static_cast((log2value * 9 + 73 + 64) / 64); +#if PROTOBUF_CODED_STREAM_H_PREFER_BSR + uint32_t log2value = (std::numeric_limits::digits - 1) - + absl::countl_zero(value | 0x1); + return static_cast((log2value * 9 + (64 + 9) + 64) / 64); +#else + uint32_t clz = absl::countl_zero(value); + return static_cast( + ((std::numeric_limits::digits * 9 + 64 + 64) - (clz * 9)) / 64); +#endif } inline size_t CodedOutputStream::VarintSize32SignExtended(int32_t value) { @@ -1746,6 +1776,7 @@ inline size_t CodedOutputStream::VarintSize32SignExtendedPlusOne( int32_t value) { return VarintSize64PlusOne(static_cast(int64_t{value})); } +#undef PROTOBUF_CODED_STREAM_H_PREFER_BSR inline void CodedOutputStream::WriteString(const std::string& str) { WriteRaw(str.data(), static_cast(str.size())); From 5b7bafc60e4bdee9126519e6b16cd6aabb72cb61 Mon Sep 17 00:00:00 2001 From: Eric Salo Date: Mon, 18 Dec 2023 19:21:31 -0800 Subject: [PATCH 047/255] upb: upb_Message_Extension -> upb_Extension PiperOrigin-RevId: 592075816 --- protos/protos.cc | 11 ++++++----- protos/protos.h | 7 ++++--- upb/message/compat.c | 6 +++--- upb/message/compat.h | 4 ++-- upb/message/copy.c | 11 +++++------ upb/message/internal/accessors.h | 14 ++++++-------- upb/message/internal/extension.c | 26 +++++++++++++------------- upb/message/internal/extension.h | 12 ++++++------ upb/message/internal/map_sorter.h | 9 ++++----- upb/message/internal/message.h | 2 +- upb/message/map_sorter.c | 10 +++++----- upb/message/message.h | 2 +- upb/message/promote.c | 6 ++---- upb/message/promote.h | 3 +-- upb/message/promote_test.cc | 2 +- upb/reflection/message.c | 2 +- upb/wire/decode.c | 4 ++-- upb/wire/encode.c | 9 ++++----- 18 files changed, 67 insertions(+), 73 deletions(-) diff --git a/protos/protos.cc b/protos/protos.cc index 888bbb4bbdf1d..57570e4039af5 100644 --- a/protos/protos.cc +++ b/protos/protos.cc @@ -119,10 +119,11 @@ bool HasExtensionOrUnknown(const upb_Message* msg, .status == kUpb_FindUnknown_Ok; } -const upb_Message_Extension* GetOrPromoteExtension( - upb_Message* msg, const upb_MiniTableExtension* eid, upb_Arena* arena) { +const upb_Extension* GetOrPromoteExtension(upb_Message* msg, + const upb_MiniTableExtension* eid, + upb_Arena* arena) { MessageLock msg_lock(msg); - const upb_Message_Extension* ext = _upb_Message_Getext(msg, eid); + const upb_Extension* ext = _upb_Message_Getext(msg, eid); if (ext == nullptr) { upb_GetExtension_Status ext_status = upb_MiniTable_GetOrPromoteExtension( (upb_Message*)msg, eid, 0, arena, &ext); @@ -162,7 +163,7 @@ upb_Message* DeepClone(const upb_Message* source, absl::Status MoveExtension(upb_Message* message, upb_Arena* message_arena, const upb_MiniTableExtension* ext, upb_Message* extension, upb_Arena* extension_arena) { - upb_Message_Extension* msg_ext = + upb_Extension* msg_ext = _upb_Message_GetOrCreateExtension(message, ext, message_arena); if (!msg_ext) { return MessageAllocationError(); @@ -183,7 +184,7 @@ absl::Status MoveExtension(upb_Message* message, upb_Arena* message_arena, absl::Status SetExtension(upb_Message* message, upb_Arena* message_arena, const upb_MiniTableExtension* ext, const upb_Message* extension) { - upb_Message_Extension* msg_ext = + upb_Extension* msg_ext = _upb_Message_GetOrCreateExtension(message, ext, message_arena); if (!msg_ext) { return MessageAllocationError(); diff --git a/protos/protos.h b/protos/protos.h index 27d8c4eb43d00..a06c9e4815876 100644 --- a/protos/protos.h +++ b/protos/protos.h @@ -223,8 +223,9 @@ absl::StatusOr Serialize(const upb_Message* message, bool HasExtensionOrUnknown(const upb_Message* msg, const upb_MiniTableExtension* eid); -const upb_Message_Extension* GetOrPromoteExtension( - upb_Message* msg, const upb_MiniTableExtension* eid, upb_Arena* arena); +const upb_Extension* GetOrPromoteExtension(upb_Message* msg, + const upb_MiniTableExtension* eid, + upb_Arena* arena); void DeepCopy(upb_Message* target, const upb_Message* source, const upb_MiniTable* mini_table, upb_Arena* arena); @@ -409,7 +410,7 @@ absl::StatusOr> GetExtension( Ptr message, const ::protos::internal::ExtensionIdentifier& id) { // TODO: Fix const correctness issues. - const upb_Message_Extension* ext = ::protos::internal::GetOrPromoteExtension( + const upb_Extension* ext = ::protos::internal::GetOrPromoteExtension( const_cast(internal::GetInternalMsg(message)), id.mini_table_ext(), ::protos::internal::GetArena(message)); if (!ext) { diff --git a/upb/message/compat.c b/upb/message/compat.c index 26c06db8e4942..1341bcacd3a85 100644 --- a/upb/message/compat.c +++ b/upb/message/compat.c @@ -17,10 +17,10 @@ // Must be last. #include "upb/port/def.inc" -const upb_Message_Extension* upb_Message_FindExtensionByNumber( - const upb_Message* msg, uint32_t field_number) { +const upb_Extension* upb_Message_FindExtensionByNumber(const upb_Message* msg, + uint32_t field_number) { size_t count = 0; - const upb_Message_Extension* ext = _upb_Message_Getexts(msg, &count); + const upb_Extension* ext = _upb_Message_Getexts(msg, &count); while (count--) { if (upb_MiniTableExtension_Number(ext->ext) == field_number) return ext; diff --git a/upb/message/compat.h b/upb/message/compat.h index 8197c3c52e7fa..2bbd47eb4fc44 100644 --- a/upb/message/compat.h +++ b/upb/message/compat.h @@ -25,8 +25,8 @@ extern "C" { #endif // Returns the extension with the given field number, or NULL on failure. -const upb_Message_Extension* upb_Message_FindExtensionByNumber( - const upb_Message* msg, uint32_t field_number); +const upb_Extension* upb_Message_FindExtensionByNumber(const upb_Message* msg, + uint32_t field_number); #ifdef __cplusplus } /* extern "C" */ diff --git a/upb/message/copy.c b/upb/message/copy.c index 7ad30ccc027dd..43a8982a64055 100644 --- a/upb/message/copy.c +++ b/upb/message/copy.c @@ -180,9 +180,8 @@ static bool upb_Message_Array_DeepClone(const upb_Array* array, } static bool upb_Clone_ExtensionValue( - const upb_MiniTableExtension* mini_table_ext, - const upb_Message_Extension* source, upb_Message_Extension* dest, - upb_Arena* arena) { + const upb_MiniTableExtension* mini_table_ext, const upb_Extension* source, + upb_Extension* dest, upb_Arena* arena) { dest->data = source->data; return upb_Clone_MessageValue( &dest->data, @@ -258,11 +257,11 @@ upb_Message* _upb_Message_Copy(upb_Message* dst, const upb_Message* src, } // Clone extensions. size_t ext_count; - const upb_Message_Extension* ext = _upb_Message_Getexts(src, &ext_count); + const upb_Extension* ext = _upb_Message_Getexts(src, &ext_count); for (size_t i = 0; i < ext_count; ++i) { - const upb_Message_Extension* msg_ext = &ext[i]; + const upb_Extension* msg_ext = &ext[i]; const upb_MiniTableField* field = &msg_ext->ext->UPB_PRIVATE(field); - upb_Message_Extension* dst_ext = + upb_Extension* dst_ext = _upb_Message_GetOrCreateExtension(dst, msg_ext->ext, arena); if (!dst_ext) return NULL; if (upb_MiniTableField_IsScalar(field)) { diff --git a/upb/message/internal/accessors.h b/upb/message/internal/accessors.h index e2cf6e3c6f875..1dccea1881f07 100644 --- a/upb/message/internal/accessors.h +++ b/upb/message/internal/accessors.h @@ -229,7 +229,7 @@ static UPB_FORCEINLINE void _upb_Message_GetNonExtensionField( UPB_INLINE void _upb_Message_GetExtensionField( const upb_Message* msg, const upb_MiniTableExtension* mt_ext, const void* default_val, void* val) { - const upb_Message_Extension* ext = _upb_Message_Getext(msg, mt_ext); + const upb_Extension* ext = _upb_Message_Getext(msg, mt_ext); const upb_MiniTableField* f = &mt_ext->UPB_PRIVATE(field); UPB_ASSUME(upb_MiniTableField_IsExtension(f)); @@ -279,8 +279,7 @@ UPB_INLINE bool _upb_Message_SetExtensionField( upb_Message* msg, const upb_MiniTableExtension* mt_ext, const void* val, upb_Arena* a) { UPB_ASSERT(a); - upb_Message_Extension* ext = - _upb_Message_GetOrCreateExtension(msg, mt_ext, a); + upb_Extension* ext = _upb_Message_GetOrCreateExtension(msg, mt_ext, a); if (!ext) return false; UPB_PRIVATE(_upb_MiniTableField_DataCopy) (&mt_ext->UPB_PRIVATE(field), &ext->data, val); @@ -291,13 +290,12 @@ UPB_INLINE void _upb_Message_ClearExtensionField( upb_Message* msg, const upb_MiniTableExtension* ext_l) { upb_Message_Internal* in = upb_Message_Getinternal(msg); if (!in->internal) return; - const upb_Message_Extension* base = - UPB_PTR_AT(in->internal, in->internal->ext_begin, upb_Message_Extension); - upb_Message_Extension* ext = - (upb_Message_Extension*)_upb_Message_Getext(msg, ext_l); + const upb_Extension* base = + UPB_PTR_AT(in->internal, in->internal->ext_begin, upb_Extension); + upb_Extension* ext = (upb_Extension*)_upb_Message_Getext(msg, ext_l); if (ext) { *ext = *base; - in->internal->ext_begin += sizeof(upb_Message_Extension); + in->internal->ext_begin += sizeof(upb_Extension); } } diff --git a/upb/message/internal/extension.c b/upb/message/internal/extension.c index 6998f26f9fb06..ae8f58dbce606 100644 --- a/upb/message/internal/extension.c +++ b/upb/message/internal/extension.c @@ -18,10 +18,10 @@ // Must be last. #include "upb/port/def.inc" -const upb_Message_Extension* _upb_Message_Getext( - const upb_Message* msg, const upb_MiniTableExtension* e) { +const upb_Extension* _upb_Message_Getext(const upb_Message* msg, + const upb_MiniTableExtension* e) { size_t n; - const upb_Message_Extension* ext = _upb_Message_Getexts(msg, &n); + const upb_Extension* ext = _upb_Message_Getexts(msg, &n); // For now we use linear search exclusively to find extensions. // If this becomes an issue due to messages with lots of extensions, @@ -35,12 +35,12 @@ const upb_Message_Extension* _upb_Message_Getext( return NULL; } -const upb_Message_Extension* _upb_Message_Getexts(const upb_Message* msg, - size_t* count) { +const upb_Extension* _upb_Message_Getexts(const upb_Message* msg, + size_t* count) { const upb_Message_Internal* in = upb_Message_Getinternal(msg); if (in->internal) { - *count = (in->internal->size - in->internal->ext_begin) / - sizeof(upb_Message_Extension); + *count = + (in->internal->size - in->internal->ext_begin) / sizeof(upb_Extension); return UPB_PTR_AT(in->internal, in->internal->ext_begin, void); } else { *count = 0; @@ -48,16 +48,16 @@ const upb_Message_Extension* _upb_Message_Getexts(const upb_Message* msg, } } -upb_Message_Extension* _upb_Message_GetOrCreateExtension( +upb_Extension* _upb_Message_GetOrCreateExtension( upb_Message* msg, const upb_MiniTableExtension* e, upb_Arena* arena) { - upb_Message_Extension* ext = - (upb_Message_Extension*)_upb_Message_Getext(msg, e); + upb_Extension* ext = (upb_Extension*)_upb_Message_Getext(msg, e); if (ext) return ext; - if (!UPB_PRIVATE(_upb_Message_Realloc)(msg, sizeof(upb_Message_Extension), arena)) return NULL; + if (!UPB_PRIVATE(_upb_Message_Realloc)(msg, sizeof(upb_Extension), arena)) + return NULL; upb_Message_Internal* in = upb_Message_Getinternal(msg); - in->internal->ext_begin -= sizeof(upb_Message_Extension); + in->internal->ext_begin -= sizeof(upb_Extension); ext = UPB_PTR_AT(in->internal, in->internal->ext_begin, void); - memset(ext, 0, sizeof(upb_Message_Extension)); + memset(ext, 0, sizeof(upb_Extension)); ext->ext = e; return ext; } diff --git a/upb/message/internal/extension.h b/upb/message/internal/extension.h index 205ecb157d098..8d2a3a5e04d54 100644 --- a/upb/message/internal/extension.h +++ b/upb/message/internal/extension.h @@ -24,7 +24,7 @@ // This is rather wasteful for scalars (in the extreme case of bool, // it wastes 15 bytes). We accept this because we expect messages to be // the most common extension type. -struct upb_Message_Extension { +struct upb_Extension { const upb_MiniTableExtension* ext; union { upb_StringView str; @@ -40,18 +40,18 @@ extern "C" { // Adds the given extension data to the given message. // |ext| is copied into the message instance. // This logically replaces any previously-added extension with this number. -upb_Message_Extension* _upb_Message_GetOrCreateExtension( +upb_Extension* _upb_Message_GetOrCreateExtension( upb_Message* msg, const upb_MiniTableExtension* ext, upb_Arena* arena); // Returns an array of extensions for this message. // Note: the array is ordered in reverse relative to the order of creation. -const upb_Message_Extension* _upb_Message_Getexts(const upb_Message* msg, - size_t* count); +const upb_Extension* _upb_Message_Getexts(const upb_Message* msg, + size_t* count); // Returns an extension for the given field number, or NULL if no extension // exists for this field number. -const upb_Message_Extension* _upb_Message_Getext( - const upb_Message* msg, const upb_MiniTableExtension* ext); +const upb_Extension* _upb_Message_Getext(const upb_Message* msg, + const upb_MiniTableExtension* ext); #ifdef __cplusplus } /* extern "C" */ diff --git a/upb/message/internal/map_sorter.h b/upb/message/internal/map_sorter.h index 64d6d14d44b7d..a47d7a57df311 100644 --- a/upb/message/internal/map_sorter.h +++ b/upb/message/internal/map_sorter.h @@ -63,9 +63,9 @@ UPB_INLINE bool _upb_sortedmap_next(_upb_mapsorter* s, const upb_Map* map, UPB_INLINE bool _upb_sortedmap_nextext(_upb_mapsorter* s, _upb_sortedmap* sorted, - const upb_Message_Extension** ext) { + const upb_Extension** ext) { if (sorted->pos == sorted->end) return false; - *ext = (const upb_Message_Extension*)s->entries[sorted->pos++]; + *ext = (const upb_Extension*)s->entries[sorted->pos++]; return true; } @@ -77,9 +77,8 @@ UPB_INLINE void _upb_mapsorter_popmap(_upb_mapsorter* s, bool _upb_mapsorter_pushmap(_upb_mapsorter* s, upb_FieldType key_type, const upb_Map* map, _upb_sortedmap* sorted); -bool _upb_mapsorter_pushexts(_upb_mapsorter* s, - const upb_Message_Extension* exts, size_t count, - _upb_sortedmap* sorted); +bool _upb_mapsorter_pushexts(_upb_mapsorter* s, const upb_Extension* exts, + size_t count, _upb_sortedmap* sorted); #ifdef __cplusplus } /* extern "C" */ diff --git a/upb/message/internal/message.h b/upb/message/internal/message.h index 87fc8535d3729..5cbc652a5e62b 100644 --- a/upb/message/internal/message.h +++ b/upb/message/internal/message.h @@ -41,7 +41,7 @@ extern const double kUpb_NaN; struct upb_Message_InternalData { /* Total size of this structure, including the data that follows. - * Must be aligned to 8, which is alignof(upb_Message_Extension) */ + * Must be aligned to 8, which is alignof(upb_Extension) */ uint32_t size; /* Offsets relative to the beginning of this structure. diff --git a/upb/message/map_sorter.c b/upb/message/map_sorter.c index 3536e35f66f6f..5c06cd3162501 100644 --- a/upb/message/map_sorter.c +++ b/upb/message/map_sorter.c @@ -15,6 +15,7 @@ #include "upb/base/string_view.h" #include "upb/mem/alloc.h" #include "upb/message/map.h" +#include "upb/message/message.h" #include "upb/mini_table/extension.h" // Must be last. @@ -134,17 +135,16 @@ bool _upb_mapsorter_pushmap(_upb_mapsorter* s, upb_FieldType key_type, } static int _upb_mapsorter_cmpext(const void* _a, const void* _b) { - const upb_Message_Extension* const* a = _a; - const upb_Message_Extension* const* b = _b; + const upb_Extension* const* a = _a; + const upb_Extension* const* b = _b; uint32_t a_num = upb_MiniTableExtension_Number((*a)->ext); uint32_t b_num = upb_MiniTableExtension_Number((*b)->ext); assert(a_num != b_num); return a_num < b_num ? -1 : 1; } -bool _upb_mapsorter_pushexts(_upb_mapsorter* s, - const upb_Message_Extension* exts, size_t count, - _upb_sortedmap* sorted) { +bool _upb_mapsorter_pushexts(_upb_mapsorter* s, const upb_Extension* exts, + size_t count, _upb_sortedmap* sorted) { if (!_upb_mapsorter_resize(s, sorted, count)) return false; for (size_t i = 0; i < count; i++) { diff --git a/upb/message/message.h b/upb/message/message.h index 6491481745520..bf04f6f9c64fb 100644 --- a/upb/message/message.h +++ b/upb/message/message.h @@ -21,7 +21,7 @@ // Must be last. #include "upb/port/def.inc" -typedef struct upb_Message_Extension upb_Message_Extension; +typedef struct upb_Extension upb_Extension; #ifdef __cplusplus extern "C" { diff --git a/upb/message/promote.c b/upb/message/promote.c index 4fd9e676a32b7..329019e73eba1 100644 --- a/upb/message/promote.c +++ b/upb/message/promote.c @@ -67,8 +67,7 @@ static upb_UnknownToMessageRet upb_MiniTable_ParseUnknownMessage( upb_GetExtension_Status upb_MiniTable_GetOrPromoteExtension( upb_Message* msg, const upb_MiniTableExtension* ext_table, - int decode_options, upb_Arena* arena, - const upb_Message_Extension** extension) { + int decode_options, upb_Arena* arena, const upb_Extension** extension) { UPB_ASSERT(upb_MiniTableField_CType(upb_MiniTableExtension_AsField( ext_table)) == kUpb_CType_Message); *extension = _upb_Message_Getext(msg, ext_table); @@ -102,8 +101,7 @@ upb_GetExtension_Status upb_MiniTable_GetOrPromoteExtension( } upb_Message* extension_msg = parse_result.message; // Add to extensions. - upb_Message_Extension* ext = - _upb_Message_GetOrCreateExtension(msg, ext_table, arena); + upb_Extension* ext = _upb_Message_GetOrCreateExtension(msg, ext_table, arena); if (!ext) { return kUpb_GetExtension_OutOfMemory; } diff --git a/upb/message/promote.h b/upb/message/promote.h index 11cf623877239..0a43f6bf708c5 100644 --- a/upb/message/promote.h +++ b/upb/message/promote.h @@ -40,8 +40,7 @@ typedef enum { // expand support to include non-message types. upb_GetExtension_Status upb_MiniTable_GetOrPromoteExtension( upb_Message* msg, const upb_MiniTableExtension* ext_table, - int decode_options, upb_Arena* arena, - const upb_Message_Extension** extension); + int decode_options, upb_Arena* arena, const upb_Extension** extension); typedef enum { kUpb_FindUnknown_Ok, diff --git a/upb/message/promote_test.cc b/upb/message/promote_test.cc index ee4750db47487..fa9bb90090c40 100644 --- a/upb/message/promote_test.cc +++ b/upb/message/promote_test.cc @@ -122,7 +122,7 @@ TEST(GeneratedCode, Extensions) { char* serialized = upb_test_ModelWithExtensions_serialize(msg, arena, &serialized_size); - const upb_Message_Extension* upb_ext2; + const upb_Extension* upb_ext2; upb_test_ModelExtension1* ext1; upb_test_ModelExtension2* ext2; upb_GetExtension_Status promote_status; diff --git a/upb/reflection/message.c b/upb/reflection/message.c index 6e138ae90b4b3..bff9c469a1daf 100644 --- a/upb/reflection/message.c +++ b/upb/reflection/message.c @@ -146,7 +146,7 @@ bool upb_Message_Next(const upb_Message* msg, const upb_MessageDef* m, if (ext_pool) { // Return any extensions that are set. size_t count; - const upb_Message_Extension* ext = _upb_Message_Getexts(msg, &count); + const upb_Extension* ext = _upb_Message_Getexts(msg, &count); if (i - n < count) { ext += count - 1 - (i - n); memcpy(out_val, &ext->data, sizeof(*out_val)); diff --git a/upb/wire/decode.c b/upb/wire/decode.c index 214fca07989dc..f298290334975 100644 --- a/upb/wire/decode.c +++ b/upb/wire/decode.c @@ -813,7 +813,7 @@ enum { static void upb_Decoder_AddKnownMessageSetItem( upb_Decoder* d, upb_Message* msg, const upb_MiniTableExtension* item_mt, const char* data, uint32_t size) { - upb_Message_Extension* ext = + upb_Extension* ext = _upb_Message_GetOrCreateExtension(msg, item_mt, &d->arena); if (UPB_UNLIKELY(!ext)) { _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_OutOfMemory); @@ -1157,7 +1157,7 @@ static const char* _upb_Decoder_DecodeKnownField( if (UPB_UNLIKELY(mode & kUpb_LabelFlags_IsExtension)) { const upb_MiniTableExtension* ext_layout = (const upb_MiniTableExtension*)field; - upb_Message_Extension* ext = + upb_Extension* ext = _upb_Message_GetOrCreateExtension(msg, ext_layout, &d->arena); if (UPB_UNLIKELY(!ext)) { _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_OutOfMemory); diff --git a/upb/wire/encode.c b/upb/wire/encode.c index bcc0b6edaeb6f..5ec9edc8e1809 100644 --- a/upb/wire/encode.c +++ b/upb/wire/encode.c @@ -519,8 +519,7 @@ static void encode_field(upb_encstate* e, const upb_Message* msg, } } -static void encode_msgset_item(upb_encstate* e, - const upb_Message_Extension* ext) { +static void encode_msgset_item(upb_encstate* e, const upb_Extension* ext) { size_t size; encode_tag(e, kUpb_MsgSet_Item, kUpb_WireType_EndGroup); encode_message(e, ext->data.ptr, @@ -532,7 +531,7 @@ static void encode_msgset_item(upb_encstate* e, encode_tag(e, kUpb_MsgSet_Item, kUpb_WireType_StartGroup); } -static void encode_ext(upb_encstate* e, const upb_Message_Extension* ext, +static void encode_ext(upb_encstate* e, const upb_Extension* ext, bool is_message_set) { if (UPB_UNLIKELY(is_message_set)) { encode_msgset_item(e, ext); @@ -570,7 +569,7 @@ static void encode_message(upb_encstate* e, const upb_Message* msg, * these in field number order relative to normal fields or even to each * other. */ size_t ext_count; - const upb_Message_Extension* ext = _upb_Message_Getexts(msg, &ext_count); + const upb_Extension* ext = _upb_Message_Getexts(msg, &ext_count); if (ext_count) { if (e->options & kUpb_EncodeOption_Deterministic) { _upb_sortedmap sorted; @@ -580,7 +579,7 @@ static void encode_message(upb_encstate* e, const upb_Message* msg, } _upb_mapsorter_popmap(&e->sorter, &sorted); } else { - const upb_Message_Extension* end = ext + ext_count; + const upb_Extension* end = ext + ext_count; for (; ext != end; ext++) { encode_ext(e, ext, m->UPB_PRIVATE(ext) == kUpb_ExtMode_IsMessageSet); } From 212067d6a298f5e0f165631ac7d43236a7d20c4d Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Tue, 19 Dec 2023 03:34:00 +0000 Subject: [PATCH 048/255] Auto-generate files after cl/592075816 --- php/ext/google/protobuf/php-upb.c | 67 +++++++++++++-------------- php/ext/google/protobuf/php-upb.h | 43 ++++++++--------- ruby/ext/google/protobuf_c/ruby-upb.c | 67 +++++++++++++-------------- ruby/ext/google/protobuf_c/ruby-upb.h | 43 ++++++++--------- 4 files changed, 104 insertions(+), 116 deletions(-) diff --git a/php/ext/google/protobuf/php-upb.c b/php/ext/google/protobuf/php-upb.c index 06794093f5662..dc579c9730c7e 100644 --- a/php/ext/google/protobuf/php-upb.c +++ b/php/ext/google/protobuf/php-upb.c @@ -5934,10 +5934,10 @@ void upb_Arena_DecRefFor(upb_Arena* arena, const void* owner) { // Must be last. -const upb_Message_Extension* upb_Message_FindExtensionByNumber( - const upb_Message* msg, uint32_t field_number) { +const upb_Extension* upb_Message_FindExtensionByNumber(const upb_Message* msg, + uint32_t field_number) { size_t count = 0; - const upb_Message_Extension* ext = _upb_Message_Getexts(msg, &count); + const upb_Extension* ext = _upb_Message_Getexts(msg, &count); while (count--) { if (upb_MiniTableExtension_Number(ext->ext) == field_number) return ext; @@ -6154,9 +6154,8 @@ static bool upb_Message_Array_DeepClone(const upb_Array* array, } static bool upb_Clone_ExtensionValue( - const upb_MiniTableExtension* mini_table_ext, - const upb_Message_Extension* source, upb_Message_Extension* dest, - upb_Arena* arena) { + const upb_MiniTableExtension* mini_table_ext, const upb_Extension* source, + upb_Extension* dest, upb_Arena* arena) { dest->data = source->data; return upb_Clone_MessageValue( &dest->data, @@ -6232,11 +6231,11 @@ upb_Message* _upb_Message_Copy(upb_Message* dst, const upb_Message* src, } // Clone extensions. size_t ext_count; - const upb_Message_Extension* ext = _upb_Message_Getexts(src, &ext_count); + const upb_Extension* ext = _upb_Message_Getexts(src, &ext_count); for (size_t i = 0; i < ext_count; ++i) { - const upb_Message_Extension* msg_ext = &ext[i]; + const upb_Extension* msg_ext = &ext[i]; const upb_MiniTableField* field = &msg_ext->ext->UPB_PRIVATE(field); - upb_Message_Extension* dst_ext = + upb_Extension* dst_ext = _upb_Message_GetOrCreateExtension(dst, msg_ext->ext, arena); if (!dst_ext) return NULL; if (upb_MiniTableField_IsScalar(field)) { @@ -6415,10 +6414,10 @@ bool UPB_PRIVATE(_upb_Array_Realloc)(upb_Array* array, size_t min_capacity, // Must be last. -const upb_Message_Extension* _upb_Message_Getext( - const upb_Message* msg, const upb_MiniTableExtension* e) { +const upb_Extension* _upb_Message_Getext(const upb_Message* msg, + const upb_MiniTableExtension* e) { size_t n; - const upb_Message_Extension* ext = _upb_Message_Getexts(msg, &n); + const upb_Extension* ext = _upb_Message_Getexts(msg, &n); // For now we use linear search exclusively to find extensions. // If this becomes an issue due to messages with lots of extensions, @@ -6432,12 +6431,12 @@ const upb_Message_Extension* _upb_Message_Getext( return NULL; } -const upb_Message_Extension* _upb_Message_Getexts(const upb_Message* msg, - size_t* count) { +const upb_Extension* _upb_Message_Getexts(const upb_Message* msg, + size_t* count) { const upb_Message_Internal* in = upb_Message_Getinternal(msg); if (in->internal) { - *count = (in->internal->size - in->internal->ext_begin) / - sizeof(upb_Message_Extension); + *count = + (in->internal->size - in->internal->ext_begin) / sizeof(upb_Extension); return UPB_PTR_AT(in->internal, in->internal->ext_begin, void); } else { *count = 0; @@ -6445,16 +6444,16 @@ const upb_Message_Extension* _upb_Message_Getexts(const upb_Message* msg, } } -upb_Message_Extension* _upb_Message_GetOrCreateExtension( +upb_Extension* _upb_Message_GetOrCreateExtension( upb_Message* msg, const upb_MiniTableExtension* e, upb_Arena* arena) { - upb_Message_Extension* ext = - (upb_Message_Extension*)_upb_Message_Getext(msg, e); + upb_Extension* ext = (upb_Extension*)_upb_Message_Getext(msg, e); if (ext) return ext; - if (!UPB_PRIVATE(_upb_Message_Realloc)(msg, sizeof(upb_Message_Extension), arena)) return NULL; + if (!UPB_PRIVATE(_upb_Message_Realloc)(msg, sizeof(upb_Extension), arena)) + return NULL; upb_Message_Internal* in = upb_Message_Getinternal(msg); - in->internal->ext_begin -= sizeof(upb_Message_Extension); + in->internal->ext_begin -= sizeof(upb_Extension); ext = UPB_PTR_AT(in->internal, in->internal->ext_begin, void); - memset(ext, 0, sizeof(upb_Message_Extension)); + memset(ext, 0, sizeof(upb_Extension)); ext->ext = e; return ext; } @@ -6738,17 +6737,16 @@ bool _upb_mapsorter_pushmap(_upb_mapsorter* s, upb_FieldType key_type, } static int _upb_mapsorter_cmpext(const void* _a, const void* _b) { - const upb_Message_Extension* const* a = _a; - const upb_Message_Extension* const* b = _b; + const upb_Extension* const* a = _a; + const upb_Extension* const* b = _b; uint32_t a_num = upb_MiniTableExtension_Number((*a)->ext); uint32_t b_num = upb_MiniTableExtension_Number((*b)->ext); assert(a_num != b_num); return a_num < b_num ? -1 : 1; } -bool _upb_mapsorter_pushexts(_upb_mapsorter* s, - const upb_Message_Extension* exts, size_t count, - _upb_sortedmap* sorted) { +bool _upb_mapsorter_pushexts(_upb_mapsorter* s, const upb_Extension* exts, + size_t count, _upb_sortedmap* sorted) { if (!_upb_mapsorter_resize(s, sorted, count)) return false; for (size_t i = 0; i < count; i++) { @@ -11438,7 +11436,7 @@ bool upb_Message_Next(const upb_Message* msg, const upb_MessageDef* m, if (ext_pool) { // Return any extensions that are set. size_t count; - const upb_Message_Extension* ext = _upb_Message_Getexts(msg, &count); + const upb_Extension* ext = _upb_Message_Getexts(msg, &count); if (i - n < count) { ext += count - 1 - (i - n); memcpy(out_val, &ext->data, sizeof(*out_val)); @@ -13484,7 +13482,7 @@ enum { static void upb_Decoder_AddKnownMessageSetItem( upb_Decoder* d, upb_Message* msg, const upb_MiniTableExtension* item_mt, const char* data, uint32_t size) { - upb_Message_Extension* ext = + upb_Extension* ext = _upb_Message_GetOrCreateExtension(msg, item_mt, &d->arena); if (UPB_UNLIKELY(!ext)) { _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_OutOfMemory); @@ -13828,7 +13826,7 @@ static const char* _upb_Decoder_DecodeKnownField( if (UPB_UNLIKELY(mode & kUpb_LabelFlags_IsExtension)) { const upb_MiniTableExtension* ext_layout = (const upb_MiniTableExtension*)field; - upb_Message_Extension* ext = + upb_Extension* ext = _upb_Message_GetOrCreateExtension(msg, ext_layout, &d->arena); if (UPB_UNLIKELY(!ext)) { _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_OutOfMemory); @@ -15537,8 +15535,7 @@ static void encode_field(upb_encstate* e, const upb_Message* msg, } } -static void encode_msgset_item(upb_encstate* e, - const upb_Message_Extension* ext) { +static void encode_msgset_item(upb_encstate* e, const upb_Extension* ext) { size_t size; encode_tag(e, kUpb_MsgSet_Item, kUpb_WireType_EndGroup); encode_message(e, ext->data.ptr, @@ -15550,7 +15547,7 @@ static void encode_msgset_item(upb_encstate* e, encode_tag(e, kUpb_MsgSet_Item, kUpb_WireType_StartGroup); } -static void encode_ext(upb_encstate* e, const upb_Message_Extension* ext, +static void encode_ext(upb_encstate* e, const upb_Extension* ext, bool is_message_set) { if (UPB_UNLIKELY(is_message_set)) { encode_msgset_item(e, ext); @@ -15588,7 +15585,7 @@ static void encode_message(upb_encstate* e, const upb_Message* msg, * these in field number order relative to normal fields or even to each * other. */ size_t ext_count; - const upb_Message_Extension* ext = _upb_Message_Getexts(msg, &ext_count); + const upb_Extension* ext = _upb_Message_Getexts(msg, &ext_count); if (ext_count) { if (e->options & kUpb_EncodeOption_Deterministic) { _upb_sortedmap sorted; @@ -15598,7 +15595,7 @@ static void encode_message(upb_encstate* e, const upb_Message* msg, } _upb_mapsorter_popmap(&e->sorter, &sorted); } else { - const upb_Message_Extension* end = ext + ext_count; + const upb_Extension* end = ext + ext_count; for (; ext != end; ext++) { encode_ext(e, ext, m->UPB_PRIVATE(ext) == kUpb_ExtMode_IsMessageSet); } diff --git a/php/ext/google/protobuf/php-upb.h b/php/ext/google/protobuf/php-upb.h index ac765cebd96c7..2a4f19b9d6209 100644 --- a/php/ext/google/protobuf/php-upb.h +++ b/php/ext/google/protobuf/php-upb.h @@ -1625,7 +1625,7 @@ bool upb_MiniTable_NextOneofField(const upb_MiniTable* m, // Must be last. -typedef struct upb_Message_Extension upb_Message_Extension; +typedef struct upb_Extension upb_Extension; #ifdef __cplusplus extern "C" { @@ -1749,7 +1749,7 @@ UPB_API_INLINE void upb_MiniTableExtension_SetSubMessage( // This is rather wasteful for scalars (in the extreme case of bool, // it wastes 15 bytes). We accept this because we expect messages to be // the most common extension type. -struct upb_Message_Extension { +struct upb_Extension { const upb_MiniTableExtension* ext; union { upb_StringView str; @@ -1765,18 +1765,18 @@ extern "C" { // Adds the given extension data to the given message. // |ext| is copied into the message instance. // This logically replaces any previously-added extension with this number. -upb_Message_Extension* _upb_Message_GetOrCreateExtension( +upb_Extension* _upb_Message_GetOrCreateExtension( upb_Message* msg, const upb_MiniTableExtension* ext, upb_Arena* arena); // Returns an array of extensions for this message. // Note: the array is ordered in reverse relative to the order of creation. -const upb_Message_Extension* _upb_Message_Getexts(const upb_Message* msg, - size_t* count); +const upb_Extension* _upb_Message_Getexts(const upb_Message* msg, + size_t* count); // Returns an extension for the given field number, or NULL if no extension // exists for this field number. -const upb_Message_Extension* _upb_Message_Getext( - const upb_Message* msg, const upb_MiniTableExtension* ext); +const upb_Extension* _upb_Message_Getext(const upb_Message* msg, + const upb_MiniTableExtension* ext); #ifdef __cplusplus } /* extern "C" */ @@ -2381,7 +2381,7 @@ extern const double kUpb_NaN; struct upb_Message_InternalData { /* Total size of this structure, including the data that follows. - * Must be aligned to 8, which is alignof(upb_Message_Extension) */ + * Must be aligned to 8, which is alignof(upb_Extension) */ uint32_t size; /* Offsets relative to the beginning of this structure. @@ -2644,7 +2644,7 @@ static UPB_FORCEINLINE void _upb_Message_GetNonExtensionField( UPB_INLINE void _upb_Message_GetExtensionField( const upb_Message* msg, const upb_MiniTableExtension* mt_ext, const void* default_val, void* val) { - const upb_Message_Extension* ext = _upb_Message_Getext(msg, mt_ext); + const upb_Extension* ext = _upb_Message_Getext(msg, mt_ext); const upb_MiniTableField* f = &mt_ext->UPB_PRIVATE(field); UPB_ASSUME(upb_MiniTableField_IsExtension(f)); @@ -2694,8 +2694,7 @@ UPB_INLINE bool _upb_Message_SetExtensionField( upb_Message* msg, const upb_MiniTableExtension* mt_ext, const void* val, upb_Arena* a) { UPB_ASSERT(a); - upb_Message_Extension* ext = - _upb_Message_GetOrCreateExtension(msg, mt_ext, a); + upb_Extension* ext = _upb_Message_GetOrCreateExtension(msg, mt_ext, a); if (!ext) return false; UPB_PRIVATE(_upb_MiniTableField_DataCopy) (&mt_ext->UPB_PRIVATE(field), &ext->data, val); @@ -2706,13 +2705,12 @@ UPB_INLINE void _upb_Message_ClearExtensionField( upb_Message* msg, const upb_MiniTableExtension* ext_l) { upb_Message_Internal* in = upb_Message_Getinternal(msg); if (!in->internal) return; - const upb_Message_Extension* base = - UPB_PTR_AT(in->internal, in->internal->ext_begin, upb_Message_Extension); - upb_Message_Extension* ext = - (upb_Message_Extension*)_upb_Message_Getext(msg, ext_l); + const upb_Extension* base = + UPB_PTR_AT(in->internal, in->internal->ext_begin, upb_Extension); + upb_Extension* ext = (upb_Extension*)_upb_Message_Getext(msg, ext_l); if (ext) { *ext = *base; - in->internal->ext_begin += sizeof(upb_Message_Extension); + in->internal->ext_begin += sizeof(upb_Extension); } } @@ -12284,8 +12282,8 @@ extern "C" { #endif // Returns the extension with the given field number, or NULL on failure. -const upb_Message_Extension* upb_Message_FindExtensionByNumber( - const upb_Message* msg, uint32_t field_number); +const upb_Extension* upb_Message_FindExtensionByNumber(const upb_Message* msg, + uint32_t field_number); #ifdef __cplusplus } /* extern "C" */ @@ -12424,9 +12422,9 @@ UPB_INLINE bool _upb_sortedmap_next(_upb_mapsorter* s, const upb_Map* map, UPB_INLINE bool _upb_sortedmap_nextext(_upb_mapsorter* s, _upb_sortedmap* sorted, - const upb_Message_Extension** ext) { + const upb_Extension** ext) { if (sorted->pos == sorted->end) return false; - *ext = (const upb_Message_Extension*)s->entries[sorted->pos++]; + *ext = (const upb_Extension*)s->entries[sorted->pos++]; return true; } @@ -12438,9 +12436,8 @@ UPB_INLINE void _upb_mapsorter_popmap(_upb_mapsorter* s, bool _upb_mapsorter_pushmap(_upb_mapsorter* s, upb_FieldType key_type, const upb_Map* map, _upb_sortedmap* sorted); -bool _upb_mapsorter_pushexts(_upb_mapsorter* s, - const upb_Message_Extension* exts, size_t count, - _upb_sortedmap* sorted); +bool _upb_mapsorter_pushexts(_upb_mapsorter* s, const upb_Extension* exts, + size_t count, _upb_sortedmap* sorted); #ifdef __cplusplus } /* extern "C" */ diff --git a/ruby/ext/google/protobuf_c/ruby-upb.c b/ruby/ext/google/protobuf_c/ruby-upb.c index 6d5de37d6b84c..9c4c8931eb516 100644 --- a/ruby/ext/google/protobuf_c/ruby-upb.c +++ b/ruby/ext/google/protobuf_c/ruby-upb.c @@ -5448,10 +5448,10 @@ void upb_Arena_DecRefFor(upb_Arena* arena, const void* owner) { // Must be last. -const upb_Message_Extension* upb_Message_FindExtensionByNumber( - const upb_Message* msg, uint32_t field_number) { +const upb_Extension* upb_Message_FindExtensionByNumber(const upb_Message* msg, + uint32_t field_number) { size_t count = 0; - const upb_Message_Extension* ext = _upb_Message_Getexts(msg, &count); + const upb_Extension* ext = _upb_Message_Getexts(msg, &count); while (count--) { if (upb_MiniTableExtension_Number(ext->ext) == field_number) return ext; @@ -5668,9 +5668,8 @@ static bool upb_Message_Array_DeepClone(const upb_Array* array, } static bool upb_Clone_ExtensionValue( - const upb_MiniTableExtension* mini_table_ext, - const upb_Message_Extension* source, upb_Message_Extension* dest, - upb_Arena* arena) { + const upb_MiniTableExtension* mini_table_ext, const upb_Extension* source, + upb_Extension* dest, upb_Arena* arena) { dest->data = source->data; return upb_Clone_MessageValue( &dest->data, @@ -5746,11 +5745,11 @@ upb_Message* _upb_Message_Copy(upb_Message* dst, const upb_Message* src, } // Clone extensions. size_t ext_count; - const upb_Message_Extension* ext = _upb_Message_Getexts(src, &ext_count); + const upb_Extension* ext = _upb_Message_Getexts(src, &ext_count); for (size_t i = 0; i < ext_count; ++i) { - const upb_Message_Extension* msg_ext = &ext[i]; + const upb_Extension* msg_ext = &ext[i]; const upb_MiniTableField* field = &msg_ext->ext->UPB_PRIVATE(field); - upb_Message_Extension* dst_ext = + upb_Extension* dst_ext = _upb_Message_GetOrCreateExtension(dst, msg_ext->ext, arena); if (!dst_ext) return NULL; if (upb_MiniTableField_IsScalar(field)) { @@ -5929,10 +5928,10 @@ bool UPB_PRIVATE(_upb_Array_Realloc)(upb_Array* array, size_t min_capacity, // Must be last. -const upb_Message_Extension* _upb_Message_Getext( - const upb_Message* msg, const upb_MiniTableExtension* e) { +const upb_Extension* _upb_Message_Getext(const upb_Message* msg, + const upb_MiniTableExtension* e) { size_t n; - const upb_Message_Extension* ext = _upb_Message_Getexts(msg, &n); + const upb_Extension* ext = _upb_Message_Getexts(msg, &n); // For now we use linear search exclusively to find extensions. // If this becomes an issue due to messages with lots of extensions, @@ -5946,12 +5945,12 @@ const upb_Message_Extension* _upb_Message_Getext( return NULL; } -const upb_Message_Extension* _upb_Message_Getexts(const upb_Message* msg, - size_t* count) { +const upb_Extension* _upb_Message_Getexts(const upb_Message* msg, + size_t* count) { const upb_Message_Internal* in = upb_Message_Getinternal(msg); if (in->internal) { - *count = (in->internal->size - in->internal->ext_begin) / - sizeof(upb_Message_Extension); + *count = + (in->internal->size - in->internal->ext_begin) / sizeof(upb_Extension); return UPB_PTR_AT(in->internal, in->internal->ext_begin, void); } else { *count = 0; @@ -5959,16 +5958,16 @@ const upb_Message_Extension* _upb_Message_Getexts(const upb_Message* msg, } } -upb_Message_Extension* _upb_Message_GetOrCreateExtension( +upb_Extension* _upb_Message_GetOrCreateExtension( upb_Message* msg, const upb_MiniTableExtension* e, upb_Arena* arena) { - upb_Message_Extension* ext = - (upb_Message_Extension*)_upb_Message_Getext(msg, e); + upb_Extension* ext = (upb_Extension*)_upb_Message_Getext(msg, e); if (ext) return ext; - if (!UPB_PRIVATE(_upb_Message_Realloc)(msg, sizeof(upb_Message_Extension), arena)) return NULL; + if (!UPB_PRIVATE(_upb_Message_Realloc)(msg, sizeof(upb_Extension), arena)) + return NULL; upb_Message_Internal* in = upb_Message_Getinternal(msg); - in->internal->ext_begin -= sizeof(upb_Message_Extension); + in->internal->ext_begin -= sizeof(upb_Extension); ext = UPB_PTR_AT(in->internal, in->internal->ext_begin, void); - memset(ext, 0, sizeof(upb_Message_Extension)); + memset(ext, 0, sizeof(upb_Extension)); ext->ext = e; return ext; } @@ -6252,17 +6251,16 @@ bool _upb_mapsorter_pushmap(_upb_mapsorter* s, upb_FieldType key_type, } static int _upb_mapsorter_cmpext(const void* _a, const void* _b) { - const upb_Message_Extension* const* a = _a; - const upb_Message_Extension* const* b = _b; + const upb_Extension* const* a = _a; + const upb_Extension* const* b = _b; uint32_t a_num = upb_MiniTableExtension_Number((*a)->ext); uint32_t b_num = upb_MiniTableExtension_Number((*b)->ext); assert(a_num != b_num); return a_num < b_num ? -1 : 1; } -bool _upb_mapsorter_pushexts(_upb_mapsorter* s, - const upb_Message_Extension* exts, size_t count, - _upb_sortedmap* sorted) { +bool _upb_mapsorter_pushexts(_upb_mapsorter* s, const upb_Extension* exts, + size_t count, _upb_sortedmap* sorted) { if (!_upb_mapsorter_resize(s, sorted, count)) return false; for (size_t i = 0; i < count; i++) { @@ -10952,7 +10950,7 @@ bool upb_Message_Next(const upb_Message* msg, const upb_MessageDef* m, if (ext_pool) { // Return any extensions that are set. size_t count; - const upb_Message_Extension* ext = _upb_Message_Getexts(msg, &count); + const upb_Extension* ext = _upb_Message_Getexts(msg, &count); if (i - n < count) { ext += count - 1 - (i - n); memcpy(out_val, &ext->data, sizeof(*out_val)); @@ -12998,7 +12996,7 @@ enum { static void upb_Decoder_AddKnownMessageSetItem( upb_Decoder* d, upb_Message* msg, const upb_MiniTableExtension* item_mt, const char* data, uint32_t size) { - upb_Message_Extension* ext = + upb_Extension* ext = _upb_Message_GetOrCreateExtension(msg, item_mt, &d->arena); if (UPB_UNLIKELY(!ext)) { _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_OutOfMemory); @@ -13342,7 +13340,7 @@ static const char* _upb_Decoder_DecodeKnownField( if (UPB_UNLIKELY(mode & kUpb_LabelFlags_IsExtension)) { const upb_MiniTableExtension* ext_layout = (const upb_MiniTableExtension*)field; - upb_Message_Extension* ext = + upb_Extension* ext = _upb_Message_GetOrCreateExtension(msg, ext_layout, &d->arena); if (UPB_UNLIKELY(!ext)) { _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_OutOfMemory); @@ -15051,8 +15049,7 @@ static void encode_field(upb_encstate* e, const upb_Message* msg, } } -static void encode_msgset_item(upb_encstate* e, - const upb_Message_Extension* ext) { +static void encode_msgset_item(upb_encstate* e, const upb_Extension* ext) { size_t size; encode_tag(e, kUpb_MsgSet_Item, kUpb_WireType_EndGroup); encode_message(e, ext->data.ptr, @@ -15064,7 +15061,7 @@ static void encode_msgset_item(upb_encstate* e, encode_tag(e, kUpb_MsgSet_Item, kUpb_WireType_StartGroup); } -static void encode_ext(upb_encstate* e, const upb_Message_Extension* ext, +static void encode_ext(upb_encstate* e, const upb_Extension* ext, bool is_message_set) { if (UPB_UNLIKELY(is_message_set)) { encode_msgset_item(e, ext); @@ -15102,7 +15099,7 @@ static void encode_message(upb_encstate* e, const upb_Message* msg, * these in field number order relative to normal fields or even to each * other. */ size_t ext_count; - const upb_Message_Extension* ext = _upb_Message_Getexts(msg, &ext_count); + const upb_Extension* ext = _upb_Message_Getexts(msg, &ext_count); if (ext_count) { if (e->options & kUpb_EncodeOption_Deterministic) { _upb_sortedmap sorted; @@ -15112,7 +15109,7 @@ static void encode_message(upb_encstate* e, const upb_Message* msg, } _upb_mapsorter_popmap(&e->sorter, &sorted); } else { - const upb_Message_Extension* end = ext + ext_count; + const upb_Extension* end = ext + ext_count; for (; ext != end; ext++) { encode_ext(e, ext, m->UPB_PRIVATE(ext) == kUpb_ExtMode_IsMessageSet); } diff --git a/ruby/ext/google/protobuf_c/ruby-upb.h b/ruby/ext/google/protobuf_c/ruby-upb.h index 79a49a0c0336c..a73d8955bc56d 100755 --- a/ruby/ext/google/protobuf_c/ruby-upb.h +++ b/ruby/ext/google/protobuf_c/ruby-upb.h @@ -1627,7 +1627,7 @@ bool upb_MiniTable_NextOneofField(const upb_MiniTable* m, // Must be last. -typedef struct upb_Message_Extension upb_Message_Extension; +typedef struct upb_Extension upb_Extension; #ifdef __cplusplus extern "C" { @@ -1751,7 +1751,7 @@ UPB_API_INLINE void upb_MiniTableExtension_SetSubMessage( // This is rather wasteful for scalars (in the extreme case of bool, // it wastes 15 bytes). We accept this because we expect messages to be // the most common extension type. -struct upb_Message_Extension { +struct upb_Extension { const upb_MiniTableExtension* ext; union { upb_StringView str; @@ -1767,18 +1767,18 @@ extern "C" { // Adds the given extension data to the given message. // |ext| is copied into the message instance. // This logically replaces any previously-added extension with this number. -upb_Message_Extension* _upb_Message_GetOrCreateExtension( +upb_Extension* _upb_Message_GetOrCreateExtension( upb_Message* msg, const upb_MiniTableExtension* ext, upb_Arena* arena); // Returns an array of extensions for this message. // Note: the array is ordered in reverse relative to the order of creation. -const upb_Message_Extension* _upb_Message_Getexts(const upb_Message* msg, - size_t* count); +const upb_Extension* _upb_Message_Getexts(const upb_Message* msg, + size_t* count); // Returns an extension for the given field number, or NULL if no extension // exists for this field number. -const upb_Message_Extension* _upb_Message_Getext( - const upb_Message* msg, const upb_MiniTableExtension* ext); +const upb_Extension* _upb_Message_Getext(const upb_Message* msg, + const upb_MiniTableExtension* ext); #ifdef __cplusplus } /* extern "C" */ @@ -2383,7 +2383,7 @@ extern const double kUpb_NaN; struct upb_Message_InternalData { /* Total size of this structure, including the data that follows. - * Must be aligned to 8, which is alignof(upb_Message_Extension) */ + * Must be aligned to 8, which is alignof(upb_Extension) */ uint32_t size; /* Offsets relative to the beginning of this structure. @@ -2646,7 +2646,7 @@ static UPB_FORCEINLINE void _upb_Message_GetNonExtensionField( UPB_INLINE void _upb_Message_GetExtensionField( const upb_Message* msg, const upb_MiniTableExtension* mt_ext, const void* default_val, void* val) { - const upb_Message_Extension* ext = _upb_Message_Getext(msg, mt_ext); + const upb_Extension* ext = _upb_Message_Getext(msg, mt_ext); const upb_MiniTableField* f = &mt_ext->UPB_PRIVATE(field); UPB_ASSUME(upb_MiniTableField_IsExtension(f)); @@ -2696,8 +2696,7 @@ UPB_INLINE bool _upb_Message_SetExtensionField( upb_Message* msg, const upb_MiniTableExtension* mt_ext, const void* val, upb_Arena* a) { UPB_ASSERT(a); - upb_Message_Extension* ext = - _upb_Message_GetOrCreateExtension(msg, mt_ext, a); + upb_Extension* ext = _upb_Message_GetOrCreateExtension(msg, mt_ext, a); if (!ext) return false; UPB_PRIVATE(_upb_MiniTableField_DataCopy) (&mt_ext->UPB_PRIVATE(field), &ext->data, val); @@ -2708,13 +2707,12 @@ UPB_INLINE void _upb_Message_ClearExtensionField( upb_Message* msg, const upb_MiniTableExtension* ext_l) { upb_Message_Internal* in = upb_Message_Getinternal(msg); if (!in->internal) return; - const upb_Message_Extension* base = - UPB_PTR_AT(in->internal, in->internal->ext_begin, upb_Message_Extension); - upb_Message_Extension* ext = - (upb_Message_Extension*)_upb_Message_Getext(msg, ext_l); + const upb_Extension* base = + UPB_PTR_AT(in->internal, in->internal->ext_begin, upb_Extension); + upb_Extension* ext = (upb_Extension*)_upb_Message_Getext(msg, ext_l); if (ext) { *ext = *base; - in->internal->ext_begin += sizeof(upb_Message_Extension); + in->internal->ext_begin += sizeof(upb_Extension); } } @@ -12056,8 +12054,8 @@ extern "C" { #endif // Returns the extension with the given field number, or NULL on failure. -const upb_Message_Extension* upb_Message_FindExtensionByNumber( - const upb_Message* msg, uint32_t field_number); +const upb_Extension* upb_Message_FindExtensionByNumber(const upb_Message* msg, + uint32_t field_number); #ifdef __cplusplus } /* extern "C" */ @@ -12196,9 +12194,9 @@ UPB_INLINE bool _upb_sortedmap_next(_upb_mapsorter* s, const upb_Map* map, UPB_INLINE bool _upb_sortedmap_nextext(_upb_mapsorter* s, _upb_sortedmap* sorted, - const upb_Message_Extension** ext) { + const upb_Extension** ext) { if (sorted->pos == sorted->end) return false; - *ext = (const upb_Message_Extension*)s->entries[sorted->pos++]; + *ext = (const upb_Extension*)s->entries[sorted->pos++]; return true; } @@ -12210,9 +12208,8 @@ UPB_INLINE void _upb_mapsorter_popmap(_upb_mapsorter* s, bool _upb_mapsorter_pushmap(_upb_mapsorter* s, upb_FieldType key_type, const upb_Map* map, _upb_sortedmap* sorted); -bool _upb_mapsorter_pushexts(_upb_mapsorter* s, - const upb_Message_Extension* exts, size_t count, - _upb_sortedmap* sorted); +bool _upb_mapsorter_pushexts(_upb_mapsorter* s, const upb_Extension* exts, + size_t count, _upb_sortedmap* sorted); #ifdef __cplusplus } /* extern "C" */ From 1f67b8dfe16e1f915f185e605b8bde541f0420b0 Mon Sep 17 00:00:00 2001 From: Eric Salo Date: Mon, 18 Dec 2023 19:58:43 -0800 Subject: [PATCH 049/255] upb: tag upb_MiniTableField:offset as UPB_ONLYBITS() PiperOrigin-RevId: 592081461 --- upb/message/accessors.h | 5 ++- upb/message/internal/accessors.h | 4 +- upb/mini_descriptor/decode.c | 41 +++++++++++---------- upb/mini_descriptor/internal/encode_test.cc | 19 +++++----- upb/mini_table/compat.c | 3 +- upb/mini_table/internal/field.h | 7 +++- upb/wire/decode.c | 10 ++--- upb/wire/encode.c | 9 +++-- upb_generator/common.cc | 3 +- upb_generator/protoc-gen-upb_minitable.cc | 3 +- 10 files changed, 58 insertions(+), 46 deletions(-) diff --git a/upb/message/accessors.h b/upb/message/accessors.h index 4d4ee3651685d..55ce69889a6fc 100644 --- a/upb/message/accessors.h +++ b/upb/message/accessors.h @@ -364,13 +364,14 @@ UPB_API_INLINE upb_Message* upb_Message_GetOrCreateMutableMessage( const upb_MiniTableField* field, upb_Arena* arena) { UPB_ASSERT(arena); UPB_ASSUME(upb_MiniTableField_CType(field) == kUpb_CType_Message); - upb_Message* sub_message = *UPB_PTR_AT(msg, field->offset, upb_Message*); + upb_Message* sub_message = + *UPB_PTR_AT(msg, field->UPB_ONLYBITS(offset), upb_Message*); if (!sub_message) { const upb_MiniTable* sub_mini_table = upb_MiniTableSub_Message( mini_table->UPB_PRIVATE(subs)[field->UPB_PRIVATE(submsg_index)]); UPB_ASSERT(sub_mini_table); sub_message = _upb_Message_New(sub_mini_table, arena); - *UPB_PTR_AT(msg, field->offset, upb_Message*) = sub_message; + *UPB_PTR_AT(msg, field->UPB_ONLYBITS(offset), upb_Message*) = sub_message; UPB_PRIVATE(_upb_Message_SetPresence)(msg, field); } return sub_message; diff --git a/upb/message/internal/accessors.h b/upb/message/internal/accessors.h index 1dccea1881f07..fd6bd2f72478c 100644 --- a/upb/message/internal/accessors.h +++ b/upb/message/internal/accessors.h @@ -100,12 +100,12 @@ UPB_INLINE void UPB_PRIVATE(_upb_Message_SetOneofCase)( UPB_INLINE void* _upb_MiniTableField_GetPtr(upb_Message* msg, const upb_MiniTableField* field) { - return (char*)msg + field->offset; + return (char*)msg + field->UPB_ONLYBITS(offset); } UPB_INLINE const void* _upb_MiniTableField_GetConstPtr( const upb_Message* msg, const upb_MiniTableField* field) { - return (char*)msg + field->offset; + return (char*)msg + field->UPB_ONLYBITS(offset); } UPB_INLINE void UPB_PRIVATE(_upb_Message_SetPresence)( diff --git a/upb/mini_descriptor/decode.c b/upb/mini_descriptor/decode.c index 1dafe0de1e8b1..dfd0413b291b7 100644 --- a/upb/mini_descriptor/decode.c +++ b/upb/mini_descriptor/decode.c @@ -174,10 +174,10 @@ static void upb_MiniTable_SetField(upb_MtDecoder* d, uint8_t ch, type -= kUpb_EncodedType_RepeatedBase; field->UPB_PRIVATE(mode) = kUpb_FieldMode_Array; field->UPB_PRIVATE(mode) |= pointer_rep << kUpb_FieldRep_Shift; - field->offset = kNoPresence; + field->UPB_PRIVATE(offset) = kNoPresence; } else { field->UPB_PRIVATE(mode) = kUpb_FieldMode_Scalar; - field->offset = kHasbitPresence; + field->UPB_PRIVATE(offset) = kHasbitPresence; if (type == kUpb_EncodedType_Group || type == kUpb_EncodedType_Message) { field->UPB_PRIVATE(mode) |= pointer_rep << kUpb_FieldRep_Shift; } else if ((unsigned long)type >= sizeof(kUpb_EncodedToFieldRep)) { @@ -225,7 +225,7 @@ static void upb_MtDecoder_ModifyField(upb_MtDecoder* d, bool required = field_modifiers & kUpb_EncodedFieldModifier_IsRequired; // Validate. - if ((singular || required) && field->offset != kHasbitPresence) { + if ((singular || required) && field->UPB_PRIVATE(offset) != kHasbitPresence) { upb_MdDecoder_ErrorJmp(&d->base, "Invalid modifier(s) for repeated field %" PRIu32, upb_MiniTableField_Number(field)); @@ -236,9 +236,9 @@ static void upb_MtDecoder_ModifyField(upb_MtDecoder* d, upb_MiniTableField_Number(field)); } - if (singular) field->offset = kNoPresence; + if (singular) field->UPB_PRIVATE(offset) = kNoPresence; if (required) { - field->offset = kRequiredPresence; + field->UPB_PRIVATE(offset) = kRequiredPresence; } } @@ -325,7 +325,7 @@ static const char* upb_MtDecoder_DecodeOneofField(upb_MtDecoder* d, " to oneof, no such field number.", field_num); } - if (f->offset != kHasbitPresence) { + if (f->UPB_PRIVATE(offset) != kHasbitPresence) { upb_MdDecoder_ErrorJmp( &d->base, "Cannot add repeated, required, or singular field %" PRIu32 @@ -340,7 +340,7 @@ static const char* upb_MtDecoder_DecodeOneofField(upb_MtDecoder* d, item->rep = rep; } // Prepend this field to the linked list. - f->offset = item->field_index; + f->UPB_PRIVATE(offset) = item->field_index; item->field_index = (f - d->fields) + kOneofBase; return ptr; } @@ -517,7 +517,7 @@ static bool upb_MtDecoder_SortLayoutItems(upb_MtDecoder* d) { int n = d->table->UPB_PRIVATE(field_count); for (int i = 0; i < n; i++) { upb_MiniTableField* f = &d->fields[i]; - if (f->offset >= kOneofBase) continue; + if (f->UPB_PRIVATE(offset) >= kOneofBase) continue; upb_LayoutItem item = {.field_index = i, .rep = f->UPB_PRIVATE(mode) >> kUpb_FieldRep_Shift, .type = kUpb_LayoutItemType_Field}; @@ -545,9 +545,9 @@ static void upb_MtDecoder_AssignHasbits(upb_MtDecoder* d) { for (int i = 0; i < n; i++) { upb_MiniTableField* field = (upb_MiniTableField*)&ret->UPB_PRIVATE(fields)[i]; - if (field->offset == kRequiredPresence) { + if (field->UPB_PRIVATE(offset) == kRequiredPresence) { field->presence = ++last_hasbit; - } else if (field->offset == kNoPresence) { + } else if (field->UPB_PRIVATE(offset) == kNoPresence) { field->presence = 0; } } @@ -561,7 +561,7 @@ static void upb_MtDecoder_AssignHasbits(upb_MtDecoder* d) { for (int i = 0; i < n; i++) { upb_MiniTableField* field = (upb_MiniTableField*)&ret->UPB_PRIVATE(fields)[i]; - if (field->offset == kHasbitPresence) { + if (field->UPB_PRIVATE(offset) == kHasbitPresence) { field->presence = ++last_hasbit; } } @@ -599,9 +599,10 @@ static void upb_MtDecoder_AssignOffsets(upb_MtDecoder* d) { upb_MiniTableField* f = &d->fields[item->field_index]; while (true) { f->presence = ~item->offset; - if (f->offset == kUpb_LayoutItem_IndexSentinel) break; - UPB_ASSERT(f->offset - kOneofBase < d->table->UPB_PRIVATE(field_count)); - f = &d->fields[f->offset - kOneofBase]; + if (f->UPB_PRIVATE(offset) == kUpb_LayoutItem_IndexSentinel) break; + UPB_ASSERT(f->UPB_PRIVATE(offset) - kOneofBase < + d->table->UPB_PRIVATE(field_count)); + f = &d->fields[f->UPB_PRIVATE(offset) - kOneofBase]; } } @@ -611,14 +612,14 @@ static void upb_MtDecoder_AssignOffsets(upb_MtDecoder* d) { switch (item->type) { case kUpb_LayoutItemType_OneofField: while (true) { - uint16_t next_offset = f->offset; - f->offset = item->offset; + uint16_t next_offset = f->UPB_PRIVATE(offset); + f->UPB_PRIVATE(offset) = item->offset; if (next_offset == kUpb_LayoutItem_IndexSentinel) break; f = &d->fields[next_offset - kOneofBase]; } break; case kUpb_LayoutItemType_Field: - f->offset = item->offset; + f->UPB_PRIVATE(offset) = item->offset; break; default: break; @@ -689,8 +690,8 @@ static void upb_MtDecoder_ParseMap(upb_MtDecoder* d, const char* data, // NOTE: sync with mini_table/message_internal.h. const size_t kv_size = d->platform == kUpb_MiniTablePlatform_32Bit ? 8 : 16; const size_t hasbit_size = 8; - d->fields[0].offset = hasbit_size; - d->fields[1].offset = hasbit_size + kv_size; + d->fields[0].UPB_PRIVATE(offset) = hasbit_size; + d->fields[1].UPB_PRIVATE(offset) = hasbit_size + kv_size; d->table->UPB_PRIVATE(size) = UPB_ALIGN_UP(hasbit_size + kv_size + kv_size, 8); @@ -815,7 +816,7 @@ static const char* upb_MtDecoder_DoBuildMiniTableExtension( upb_MiniTableField* f = &ext->UPB_PRIVATE(field); f->UPB_PRIVATE(mode) |= kUpb_LabelFlags_IsExtension; - f->offset = 0; + f->UPB_PRIVATE(offset) = 0; f->presence = 0; if (extendee->UPB_PRIVATE(ext) & kUpb_ExtMode_IsMessageSet) { diff --git a/upb/mini_descriptor/internal/encode_test.cc b/upb/mini_descriptor/internal/encode_test.cc index 498464106073d..aa9979db3c270 100644 --- a/upb/mini_descriptor/internal/encode_test.cc +++ b/upb/mini_descriptor/internal/encode_test.cc @@ -70,8 +70,8 @@ TEST_P(MiniTableTest, AllScalarTypes) { const upb_MiniTableField* f = &table->UPB_PRIVATE(fields)[i]; EXPECT_EQ(i + 1, upb_MiniTableField_Number(f)); EXPECT_TRUE(upb_MiniTableField_IsScalar(f)); - EXPECT_TRUE(offsets.insert(f->offset).second); - EXPECT_TRUE(f->offset < table->UPB_PRIVATE(size)); + EXPECT_TRUE(offsets.insert(f->UPB_PRIVATE(offset)).second); + EXPECT_TRUE(f->UPB_PRIVATE(offset) < table->UPB_PRIVATE(size)); } EXPECT_EQ(0, table->UPB_PRIVATE(required_count)); } @@ -96,8 +96,8 @@ TEST_P(MiniTableTest, AllRepeatedTypes) { const upb_MiniTableField* f = &table->UPB_PRIVATE(fields)[i]; EXPECT_EQ(i + 1, upb_MiniTableField_Number(f)); EXPECT_TRUE(upb_MiniTableField_IsArray(f)); - EXPECT_TRUE(offsets.insert(f->offset).second); - EXPECT_TRUE(f->offset < table->UPB_PRIVATE(size)); + EXPECT_TRUE(offsets.insert(f->UPB_PRIVATE(offset)).second); + EXPECT_TRUE(f->UPB_PRIVATE(offset) < table->UPB_PRIVATE(size)); } EXPECT_EQ(0, table->UPB_PRIVATE(required_count)); } @@ -125,8 +125,8 @@ TEST_P(MiniTableTest, Skips) { EXPECT_EQ(field_numbers[i], upb_MiniTableField_Number(f)); EXPECT_EQ(kUpb_FieldType_Float, upb_MiniTableField_Type(f)); EXPECT_TRUE(upb_MiniTableField_IsScalar(f)); - EXPECT_TRUE(offsets.insert(f->offset).second); - EXPECT_TRUE(f->offset < table->UPB_PRIVATE(size)); + EXPECT_TRUE(offsets.insert(f->UPB_PRIVATE(offset)).second); + EXPECT_TRUE(f->UPB_PRIVATE(offset) < table->UPB_PRIVATE(size)); } EXPECT_EQ(0, table->UPB_PRIVATE(required_count)); } @@ -155,13 +155,14 @@ TEST_P(MiniTableTest, AllScalarTypesOneof) { EXPECT_EQ(i + 1, upb_MiniTableField_Number(f)); EXPECT_TRUE(upb_MiniTableField_IsScalar(f)); // For a oneof all fields have the same offset. - EXPECT_EQ(table->UPB_PRIVATE(fields)[0].offset, f->offset); + EXPECT_EQ(table->UPB_PRIVATE(fields)[0].UPB_PRIVATE(offset), + f->UPB_PRIVATE(offset)); // All presence fields should point to the same oneof case offset. size_t case_ofs = _upb_MiniTableField_OneofOffset(f); EXPECT_EQ(table->UPB_PRIVATE(fields)[0].presence, f->presence); - EXPECT_TRUE(f->offset < table->UPB_PRIVATE(size)); + EXPECT_TRUE(f->UPB_PRIVATE(offset) < table->UPB_PRIVATE(size)); EXPECT_TRUE(case_ofs < table->UPB_PRIVATE(size)); - EXPECT_TRUE(case_ofs != f->offset); + EXPECT_TRUE(case_ofs != f->UPB_PRIVATE(offset)); } EXPECT_EQ(0, table->UPB_PRIVATE(required_count)); } diff --git a/upb/mini_table/compat.c b/upb/mini_table/compat.c index 23e13cef346c7..e834c4f09f62a 100644 --- a/upb/mini_table/compat.c +++ b/upb/mini_table/compat.c @@ -45,7 +45,8 @@ static upb_MiniTableEquals_Status upb_deep_check(const upb_MiniTable* src, return false; if (src_field->UPB_PRIVATE(mode) != dst_field->UPB_PRIVATE(mode)) return false; - if (src_field->offset != dst_field->offset) return false; + if (src_field->UPB_PRIVATE(offset) != dst_field->UPB_PRIVATE(offset)) + return false; if (src_field->presence != dst_field->presence) return false; if (src_field->UPB_PRIVATE(submsg_index) != dst_field->UPB_PRIVATE(submsg_index)) diff --git a/upb/mini_table/internal/field.h b/upb/mini_table/internal/field.h index cc0974c737b4b..8d7c5e7308908 100644 --- a/upb/mini_table/internal/field.h +++ b/upb/mini_table/internal/field.h @@ -20,7 +20,7 @@ // LINT.IfChange(struct_definition) struct upb_MiniTableField { uint32_t UPB_ONLYBITS(number); - uint16_t offset; + uint16_t UPB_ONLYBITS(offset); int16_t presence; // If >0, hasbit_index. If <0, ~oneof_index // Indexes into `upb_MiniTable.subs` @@ -174,6 +174,11 @@ UPB_PRIVATE(_upb_MiniTableField_Number)(const struct upb_MiniTableField* f) { return f->UPB_ONLYBITS(number); } +UPB_INLINE uint16_t +UPB_PRIVATE(_upb_MiniTableField_Offset)(const struct upb_MiniTableField* f) { + return f->UPB_ONLYBITS(offset); +} + UPB_INLINE size_t _upb_MiniTableField_OneofOffset(const struct upb_MiniTableField* f) { UPB_ASSERT(UPB_PRIVATE(_upb_MiniTableField_IsInOneof)(f)); diff --git a/upb/wire/decode.c b/upb/wire/decode.c index f298290334975..f5ad1cfa46cdf 100644 --- a/upb/wire/decode.c +++ b/upb/wire/decode.c @@ -517,7 +517,7 @@ static const char* _upb_Decoder_DecodeToArray(upb_Decoder* d, const char* ptr, const upb_MiniTableSub* subs, const upb_MiniTableField* field, wireval* val, int op) { - upb_Array** arrp = UPB_PTR_AT(msg, field->offset, void); + upb_Array** arrp = UPB_PTR_AT(msg, field->UPB_PRIVATE(offset), void); upb_Array* arr = *arrp; void* mem; @@ -608,8 +608,8 @@ upb_Map* _upb_Decoder_CreateMap(upb_Decoder* d, const upb_MiniTable* entry) { const upb_MiniTableField* val_field = &entry->UPB_PRIVATE(fields)[1]; char key_size = kSizeInMap[key_field->UPB_PRIVATE(descriptortype)]; char val_size = kSizeInMap[val_field->UPB_PRIVATE(descriptortype)]; - UPB_ASSERT(key_field->offset == offsetof(upb_MapEntryData, k)); - UPB_ASSERT(val_field->offset == offsetof(upb_MapEntryData, v)); + UPB_ASSERT(key_field->UPB_PRIVATE(offset) == offsetof(upb_MapEntryData, k)); + UPB_ASSERT(val_field->UPB_PRIVATE(offset) == offsetof(upb_MapEntryData, v)); upb_Map* ret = _upb_Map_New(&d->arena, key_size, val_size); if (!ret) _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_OutOfMemory); return ret; @@ -620,7 +620,7 @@ static const char* _upb_Decoder_DecodeToMap(upb_Decoder* d, const char* ptr, const upb_MiniTableSub* subs, const upb_MiniTableField* field, wireval* val) { - upb_Map** map_p = UPB_PTR_AT(msg, field->offset, upb_Map*); + upb_Map** map_p = UPB_PTR_AT(msg, field->UPB_PRIVATE(offset), upb_Map*); upb_Map* map = *map_p; upb_MapEntry ent; UPB_ASSERT(upb_MiniTableField_Type(field) == kUpb_FieldType_Message); @@ -683,7 +683,7 @@ static const char* _upb_Decoder_DecodeToSubMessage( upb_Decoder* d, const char* ptr, upb_Message* msg, const upb_MiniTableSub* subs, const upb_MiniTableField* field, wireval* val, int op) { - void* mem = UPB_PTR_AT(msg, field->offset, void); + void* mem = UPB_PTR_AT(msg, field->UPB_PRIVATE(offset), void); int type = field->UPB_PRIVATE(descriptortype); if (UPB_UNLIKELY(op == kUpb_DecodeOp_Enum) && diff --git a/upb/wire/encode.c b/upb/wire/encode.c index 5ec9edc8e1809..4f923e9c3994c 100644 --- a/upb/wire/encode.c +++ b/upb/wire/encode.c @@ -309,7 +309,7 @@ static void encode_scalar(upb_encstate* e, const void* _field_mem, static void encode_array(upb_encstate* e, const upb_Message* msg, const upb_MiniTableSub* subs, const upb_MiniTableField* f) { - const upb_Array* arr = *UPB_PTR_AT(msg, f->offset, upb_Array*); + const upb_Array* arr = *UPB_PTR_AT(msg, f->UPB_PRIVATE(offset), upb_Array*); bool packed = upb_MiniTableField_IsPacked(f); size_t pre_len = e->limit - e->ptr; @@ -432,7 +432,7 @@ static void encode_mapentry(upb_encstate* e, uint32_t number, static void encode_map(upb_encstate* e, const upb_Message* msg, const upb_MiniTableSub* subs, const upb_MiniTableField* f) { - const upb_Map* map = *UPB_PTR_AT(msg, f->offset, const upb_Map*); + const upb_Map* map = *UPB_PTR_AT(msg, f->UPB_PRIVATE(offset), const upb_Map*); const upb_MiniTable* layout = upb_MiniTableSub_Message(subs[f->UPB_PRIVATE(submsg_index)]); UPB_ASSERT(layout->UPB_PRIVATE(field_count) == 2); @@ -467,7 +467,7 @@ static bool encode_shouldencode(upb_encstate* e, const upb_Message* msg, const upb_MiniTableField* f) { if (f->presence == 0) { // Proto3 presence or map/array. - const void* mem = UPB_PTR_AT(msg, f->offset, void); + const void* mem = UPB_PTR_AT(msg, f->UPB_PRIVATE(offset), void); switch (UPB_PRIVATE(_upb_MiniTableField_GetRep)(f)) { case kUpb_FieldRep_1Byte: { char ch; @@ -512,7 +512,8 @@ static void encode_field(upb_encstate* e, const upb_Message* msg, encode_map(e, msg, subs, field); break; case kUpb_FieldMode_Scalar: - encode_scalar(e, UPB_PTR_AT(msg, field->offset, void), subs, field); + encode_scalar(e, UPB_PTR_AT(msg, field->UPB_PRIVATE(offset), void), subs, + field); break; default: UPB_UNREACHABLE(); diff --git a/upb_generator/common.cc b/upb_generator/common.cc index 554c02e6cc64b..9c60a7edf0c18 100644 --- a/upb_generator/common.cc +++ b/upb_generator/common.cc @@ -85,7 +85,8 @@ std::string FieldInitializer(upb::FieldDefPtr field, const upb_MiniTableField* field32) { return absl::Substitute( "{$0, $1, $2, $3, $4, $5}", upb_MiniTableField_Number(field64), - ArchDependentSize(field32->offset, field64->offset), + ArchDependentSize(field32->UPB_PRIVATE(offset), + field64->UPB_PRIVATE(offset)), ArchDependentSize(field32->presence, field64->presence), field64->UPB_PRIVATE(submsg_index) == kUpb_NoSub ? "kUpb_NoSub" diff --git a/upb_generator/protoc-gen-upb_minitable.cc b/upb_generator/protoc-gen-upb_minitable.cc index 1c5d636f2d869..d58af3a89bd1d 100644 --- a/upb_generator/protoc-gen-upb_minitable.cc +++ b/upb_generator/protoc-gen-upb_minitable.cc @@ -286,7 +286,8 @@ bool TryFillTableEntry(const DefPoolPair& pools, upb::FieldDefPtr field, // // - |presence| is either hasbit index or field number for oneofs. - uint64_t data = static_cast(mt_f->offset) << 48 | expected_tag; + uint64_t data = + static_cast(mt_f->UPB_PRIVATE(offset)) << 48 | expected_tag; if (field.IsSequence()) { // No hasbit/oneof-related fields. From a9a40067404db05a730b6286b03fbe81ec74eb42 Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Tue, 19 Dec 2023 04:10:41 +0000 Subject: [PATCH 050/255] Auto-generate files after cl/592081461 --- php/ext/google/protobuf/php-upb.c | 60 ++++++++++++++------------- php/ext/google/protobuf/php-upb.h | 16 ++++--- ruby/ext/google/protobuf_c/ruby-upb.c | 60 ++++++++++++++------------- ruby/ext/google/protobuf_c/ruby-upb.h | 16 ++++--- 4 files changed, 84 insertions(+), 68 deletions(-) diff --git a/php/ext/google/protobuf/php-upb.c b/php/ext/google/protobuf/php-upb.c index dc579c9730c7e..bb221bad4604c 100644 --- a/php/ext/google/protobuf/php-upb.c +++ b/php/ext/google/protobuf/php-upb.c @@ -7099,10 +7099,10 @@ static void upb_MiniTable_SetField(upb_MtDecoder* d, uint8_t ch, type -= kUpb_EncodedType_RepeatedBase; field->UPB_PRIVATE(mode) = kUpb_FieldMode_Array; field->UPB_PRIVATE(mode) |= pointer_rep << kUpb_FieldRep_Shift; - field->offset = kNoPresence; + field->UPB_PRIVATE(offset) = kNoPresence; } else { field->UPB_PRIVATE(mode) = kUpb_FieldMode_Scalar; - field->offset = kHasbitPresence; + field->UPB_PRIVATE(offset) = kHasbitPresence; if (type == kUpb_EncodedType_Group || type == kUpb_EncodedType_Message) { field->UPB_PRIVATE(mode) |= pointer_rep << kUpb_FieldRep_Shift; } else if ((unsigned long)type >= sizeof(kUpb_EncodedToFieldRep)) { @@ -7150,7 +7150,7 @@ static void upb_MtDecoder_ModifyField(upb_MtDecoder* d, bool required = field_modifiers & kUpb_EncodedFieldModifier_IsRequired; // Validate. - if ((singular || required) && field->offset != kHasbitPresence) { + if ((singular || required) && field->UPB_PRIVATE(offset) != kHasbitPresence) { upb_MdDecoder_ErrorJmp(&d->base, "Invalid modifier(s) for repeated field %" PRIu32, upb_MiniTableField_Number(field)); @@ -7161,9 +7161,9 @@ static void upb_MtDecoder_ModifyField(upb_MtDecoder* d, upb_MiniTableField_Number(field)); } - if (singular) field->offset = kNoPresence; + if (singular) field->UPB_PRIVATE(offset) = kNoPresence; if (required) { - field->offset = kRequiredPresence; + field->UPB_PRIVATE(offset) = kRequiredPresence; } } @@ -7250,7 +7250,7 @@ static const char* upb_MtDecoder_DecodeOneofField(upb_MtDecoder* d, " to oneof, no such field number.", field_num); } - if (f->offset != kHasbitPresence) { + if (f->UPB_PRIVATE(offset) != kHasbitPresence) { upb_MdDecoder_ErrorJmp( &d->base, "Cannot add repeated, required, or singular field %" PRIu32 @@ -7265,7 +7265,7 @@ static const char* upb_MtDecoder_DecodeOneofField(upb_MtDecoder* d, item->rep = rep; } // Prepend this field to the linked list. - f->offset = item->field_index; + f->UPB_PRIVATE(offset) = item->field_index; item->field_index = (f - d->fields) + kOneofBase; return ptr; } @@ -7442,7 +7442,7 @@ static bool upb_MtDecoder_SortLayoutItems(upb_MtDecoder* d) { int n = d->table->UPB_PRIVATE(field_count); for (int i = 0; i < n; i++) { upb_MiniTableField* f = &d->fields[i]; - if (f->offset >= kOneofBase) continue; + if (f->UPB_PRIVATE(offset) >= kOneofBase) continue; upb_LayoutItem item = {.field_index = i, .rep = f->UPB_PRIVATE(mode) >> kUpb_FieldRep_Shift, .type = kUpb_LayoutItemType_Field}; @@ -7470,9 +7470,9 @@ static void upb_MtDecoder_AssignHasbits(upb_MtDecoder* d) { for (int i = 0; i < n; i++) { upb_MiniTableField* field = (upb_MiniTableField*)&ret->UPB_PRIVATE(fields)[i]; - if (field->offset == kRequiredPresence) { + if (field->UPB_PRIVATE(offset) == kRequiredPresence) { field->presence = ++last_hasbit; - } else if (field->offset == kNoPresence) { + } else if (field->UPB_PRIVATE(offset) == kNoPresence) { field->presence = 0; } } @@ -7486,7 +7486,7 @@ static void upb_MtDecoder_AssignHasbits(upb_MtDecoder* d) { for (int i = 0; i < n; i++) { upb_MiniTableField* field = (upb_MiniTableField*)&ret->UPB_PRIVATE(fields)[i]; - if (field->offset == kHasbitPresence) { + if (field->UPB_PRIVATE(offset) == kHasbitPresence) { field->presence = ++last_hasbit; } } @@ -7524,9 +7524,10 @@ static void upb_MtDecoder_AssignOffsets(upb_MtDecoder* d) { upb_MiniTableField* f = &d->fields[item->field_index]; while (true) { f->presence = ~item->offset; - if (f->offset == kUpb_LayoutItem_IndexSentinel) break; - UPB_ASSERT(f->offset - kOneofBase < d->table->UPB_PRIVATE(field_count)); - f = &d->fields[f->offset - kOneofBase]; + if (f->UPB_PRIVATE(offset) == kUpb_LayoutItem_IndexSentinel) break; + UPB_ASSERT(f->UPB_PRIVATE(offset) - kOneofBase < + d->table->UPB_PRIVATE(field_count)); + f = &d->fields[f->UPB_PRIVATE(offset) - kOneofBase]; } } @@ -7536,14 +7537,14 @@ static void upb_MtDecoder_AssignOffsets(upb_MtDecoder* d) { switch (item->type) { case kUpb_LayoutItemType_OneofField: while (true) { - uint16_t next_offset = f->offset; - f->offset = item->offset; + uint16_t next_offset = f->UPB_PRIVATE(offset); + f->UPB_PRIVATE(offset) = item->offset; if (next_offset == kUpb_LayoutItem_IndexSentinel) break; f = &d->fields[next_offset - kOneofBase]; } break; case kUpb_LayoutItemType_Field: - f->offset = item->offset; + f->UPB_PRIVATE(offset) = item->offset; break; default: break; @@ -7614,8 +7615,8 @@ static void upb_MtDecoder_ParseMap(upb_MtDecoder* d, const char* data, // NOTE: sync with mini_table/message_internal.h. const size_t kv_size = d->platform == kUpb_MiniTablePlatform_32Bit ? 8 : 16; const size_t hasbit_size = 8; - d->fields[0].offset = hasbit_size; - d->fields[1].offset = hasbit_size + kv_size; + d->fields[0].UPB_PRIVATE(offset) = hasbit_size; + d->fields[1].UPB_PRIVATE(offset) = hasbit_size + kv_size; d->table->UPB_PRIVATE(size) = UPB_ALIGN_UP(hasbit_size + kv_size + kv_size, 8); @@ -7740,7 +7741,7 @@ static const char* upb_MtDecoder_DoBuildMiniTableExtension( upb_MiniTableField* f = &ext->UPB_PRIVATE(field); f->UPB_PRIVATE(mode) |= kUpb_LabelFlags_IsExtension; - f->offset = 0; + f->UPB_PRIVATE(offset) = 0; f->presence = 0; if (extendee->UPB_PRIVATE(ext) & kUpb_ExtMode_IsMessageSet) { @@ -13186,7 +13187,7 @@ static const char* _upb_Decoder_DecodeToArray(upb_Decoder* d, const char* ptr, const upb_MiniTableSub* subs, const upb_MiniTableField* field, wireval* val, int op) { - upb_Array** arrp = UPB_PTR_AT(msg, field->offset, void); + upb_Array** arrp = UPB_PTR_AT(msg, field->UPB_PRIVATE(offset), void); upb_Array* arr = *arrp; void* mem; @@ -13277,8 +13278,8 @@ upb_Map* _upb_Decoder_CreateMap(upb_Decoder* d, const upb_MiniTable* entry) { const upb_MiniTableField* val_field = &entry->UPB_PRIVATE(fields)[1]; char key_size = kSizeInMap[key_field->UPB_PRIVATE(descriptortype)]; char val_size = kSizeInMap[val_field->UPB_PRIVATE(descriptortype)]; - UPB_ASSERT(key_field->offset == offsetof(upb_MapEntryData, k)); - UPB_ASSERT(val_field->offset == offsetof(upb_MapEntryData, v)); + UPB_ASSERT(key_field->UPB_PRIVATE(offset) == offsetof(upb_MapEntryData, k)); + UPB_ASSERT(val_field->UPB_PRIVATE(offset) == offsetof(upb_MapEntryData, v)); upb_Map* ret = _upb_Map_New(&d->arena, key_size, val_size); if (!ret) _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_OutOfMemory); return ret; @@ -13289,7 +13290,7 @@ static const char* _upb_Decoder_DecodeToMap(upb_Decoder* d, const char* ptr, const upb_MiniTableSub* subs, const upb_MiniTableField* field, wireval* val) { - upb_Map** map_p = UPB_PTR_AT(msg, field->offset, upb_Map*); + upb_Map** map_p = UPB_PTR_AT(msg, field->UPB_PRIVATE(offset), upb_Map*); upb_Map* map = *map_p; upb_MapEntry ent; UPB_ASSERT(upb_MiniTableField_Type(field) == kUpb_FieldType_Message); @@ -13352,7 +13353,7 @@ static const char* _upb_Decoder_DecodeToSubMessage( upb_Decoder* d, const char* ptr, upb_Message* msg, const upb_MiniTableSub* subs, const upb_MiniTableField* field, wireval* val, int op) { - void* mem = UPB_PTR_AT(msg, field->offset, void); + void* mem = UPB_PTR_AT(msg, field->UPB_PRIVATE(offset), void); int type = field->UPB_PRIVATE(descriptortype); if (UPB_UNLIKELY(op == kUpb_DecodeOp_Enum) && @@ -15325,7 +15326,7 @@ static void encode_scalar(upb_encstate* e, const void* _field_mem, static void encode_array(upb_encstate* e, const upb_Message* msg, const upb_MiniTableSub* subs, const upb_MiniTableField* f) { - const upb_Array* arr = *UPB_PTR_AT(msg, f->offset, upb_Array*); + const upb_Array* arr = *UPB_PTR_AT(msg, f->UPB_PRIVATE(offset), upb_Array*); bool packed = upb_MiniTableField_IsPacked(f); size_t pre_len = e->limit - e->ptr; @@ -15448,7 +15449,7 @@ static void encode_mapentry(upb_encstate* e, uint32_t number, static void encode_map(upb_encstate* e, const upb_Message* msg, const upb_MiniTableSub* subs, const upb_MiniTableField* f) { - const upb_Map* map = *UPB_PTR_AT(msg, f->offset, const upb_Map*); + const upb_Map* map = *UPB_PTR_AT(msg, f->UPB_PRIVATE(offset), const upb_Map*); const upb_MiniTable* layout = upb_MiniTableSub_Message(subs[f->UPB_PRIVATE(submsg_index)]); UPB_ASSERT(layout->UPB_PRIVATE(field_count) == 2); @@ -15483,7 +15484,7 @@ static bool encode_shouldencode(upb_encstate* e, const upb_Message* msg, const upb_MiniTableField* f) { if (f->presence == 0) { // Proto3 presence or map/array. - const void* mem = UPB_PTR_AT(msg, f->offset, void); + const void* mem = UPB_PTR_AT(msg, f->UPB_PRIVATE(offset), void); switch (UPB_PRIVATE(_upb_MiniTableField_GetRep)(f)) { case kUpb_FieldRep_1Byte: { char ch; @@ -15528,7 +15529,8 @@ static void encode_field(upb_encstate* e, const upb_Message* msg, encode_map(e, msg, subs, field); break; case kUpb_FieldMode_Scalar: - encode_scalar(e, UPB_PTR_AT(msg, field->offset, void), subs, field); + encode_scalar(e, UPB_PTR_AT(msg, field->UPB_PRIVATE(offset), void), subs, + field); break; default: UPB_UNREACHABLE(); diff --git a/php/ext/google/protobuf/php-upb.h b/php/ext/google/protobuf/php-upb.h index 2a4f19b9d6209..3c0570cb1efc9 100644 --- a/php/ext/google/protobuf/php-upb.h +++ b/php/ext/google/protobuf/php-upb.h @@ -1095,7 +1095,7 @@ UPB_INLINE int upb_FieldType_SizeLg2(upb_FieldType field_type) { // LINT.IfChange(struct_definition) struct upb_MiniTableField { uint32_t UPB_ONLYBITS(number); - uint16_t offset; + uint16_t UPB_ONLYBITS(offset); int16_t presence; // If >0, hasbit_index. If <0, ~oneof_index // Indexes into `upb_MiniTable.subs` @@ -1249,6 +1249,11 @@ UPB_PRIVATE(_upb_MiniTableField_Number)(const struct upb_MiniTableField* f) { return f->UPB_ONLYBITS(number); } +UPB_INLINE uint16_t +UPB_PRIVATE(_upb_MiniTableField_Offset)(const struct upb_MiniTableField* f) { + return f->UPB_ONLYBITS(offset); +} + UPB_INLINE size_t _upb_MiniTableField_OneofOffset(const struct upb_MiniTableField* f) { UPB_ASSERT(UPB_PRIVATE(_upb_MiniTableField_IsInOneof)(f)); @@ -2515,12 +2520,12 @@ UPB_INLINE void UPB_PRIVATE(_upb_Message_SetOneofCase)( UPB_INLINE void* _upb_MiniTableField_GetPtr(upb_Message* msg, const upb_MiniTableField* field) { - return (char*)msg + field->offset; + return (char*)msg + field->UPB_ONLYBITS(offset); } UPB_INLINE const void* _upb_MiniTableField_GetConstPtr( const upb_Message* msg, const upb_MiniTableField* field) { - return (char*)msg + field->offset; + return (char*)msg + field->UPB_ONLYBITS(offset); } UPB_INLINE void UPB_PRIVATE(_upb_Message_SetPresence)( @@ -3262,13 +3267,14 @@ UPB_API_INLINE upb_Message* upb_Message_GetOrCreateMutableMessage( const upb_MiniTableField* field, upb_Arena* arena) { UPB_ASSERT(arena); UPB_ASSUME(upb_MiniTableField_CType(field) == kUpb_CType_Message); - upb_Message* sub_message = *UPB_PTR_AT(msg, field->offset, upb_Message*); + upb_Message* sub_message = + *UPB_PTR_AT(msg, field->UPB_ONLYBITS(offset), upb_Message*); if (!sub_message) { const upb_MiniTable* sub_mini_table = upb_MiniTableSub_Message( mini_table->UPB_PRIVATE(subs)[field->UPB_PRIVATE(submsg_index)]); UPB_ASSERT(sub_mini_table); sub_message = _upb_Message_New(sub_mini_table, arena); - *UPB_PTR_AT(msg, field->offset, upb_Message*) = sub_message; + *UPB_PTR_AT(msg, field->UPB_ONLYBITS(offset), upb_Message*) = sub_message; UPB_PRIVATE(_upb_Message_SetPresence)(msg, field); } return sub_message; diff --git a/ruby/ext/google/protobuf_c/ruby-upb.c b/ruby/ext/google/protobuf_c/ruby-upb.c index 9c4c8931eb516..73b1af4887e1b 100644 --- a/ruby/ext/google/protobuf_c/ruby-upb.c +++ b/ruby/ext/google/protobuf_c/ruby-upb.c @@ -6613,10 +6613,10 @@ static void upb_MiniTable_SetField(upb_MtDecoder* d, uint8_t ch, type -= kUpb_EncodedType_RepeatedBase; field->UPB_PRIVATE(mode) = kUpb_FieldMode_Array; field->UPB_PRIVATE(mode) |= pointer_rep << kUpb_FieldRep_Shift; - field->offset = kNoPresence; + field->UPB_PRIVATE(offset) = kNoPresence; } else { field->UPB_PRIVATE(mode) = kUpb_FieldMode_Scalar; - field->offset = kHasbitPresence; + field->UPB_PRIVATE(offset) = kHasbitPresence; if (type == kUpb_EncodedType_Group || type == kUpb_EncodedType_Message) { field->UPB_PRIVATE(mode) |= pointer_rep << kUpb_FieldRep_Shift; } else if ((unsigned long)type >= sizeof(kUpb_EncodedToFieldRep)) { @@ -6664,7 +6664,7 @@ static void upb_MtDecoder_ModifyField(upb_MtDecoder* d, bool required = field_modifiers & kUpb_EncodedFieldModifier_IsRequired; // Validate. - if ((singular || required) && field->offset != kHasbitPresence) { + if ((singular || required) && field->UPB_PRIVATE(offset) != kHasbitPresence) { upb_MdDecoder_ErrorJmp(&d->base, "Invalid modifier(s) for repeated field %" PRIu32, upb_MiniTableField_Number(field)); @@ -6675,9 +6675,9 @@ static void upb_MtDecoder_ModifyField(upb_MtDecoder* d, upb_MiniTableField_Number(field)); } - if (singular) field->offset = kNoPresence; + if (singular) field->UPB_PRIVATE(offset) = kNoPresence; if (required) { - field->offset = kRequiredPresence; + field->UPB_PRIVATE(offset) = kRequiredPresence; } } @@ -6764,7 +6764,7 @@ static const char* upb_MtDecoder_DecodeOneofField(upb_MtDecoder* d, " to oneof, no such field number.", field_num); } - if (f->offset != kHasbitPresence) { + if (f->UPB_PRIVATE(offset) != kHasbitPresence) { upb_MdDecoder_ErrorJmp( &d->base, "Cannot add repeated, required, or singular field %" PRIu32 @@ -6779,7 +6779,7 @@ static const char* upb_MtDecoder_DecodeOneofField(upb_MtDecoder* d, item->rep = rep; } // Prepend this field to the linked list. - f->offset = item->field_index; + f->UPB_PRIVATE(offset) = item->field_index; item->field_index = (f - d->fields) + kOneofBase; return ptr; } @@ -6956,7 +6956,7 @@ static bool upb_MtDecoder_SortLayoutItems(upb_MtDecoder* d) { int n = d->table->UPB_PRIVATE(field_count); for (int i = 0; i < n; i++) { upb_MiniTableField* f = &d->fields[i]; - if (f->offset >= kOneofBase) continue; + if (f->UPB_PRIVATE(offset) >= kOneofBase) continue; upb_LayoutItem item = {.field_index = i, .rep = f->UPB_PRIVATE(mode) >> kUpb_FieldRep_Shift, .type = kUpb_LayoutItemType_Field}; @@ -6984,9 +6984,9 @@ static void upb_MtDecoder_AssignHasbits(upb_MtDecoder* d) { for (int i = 0; i < n; i++) { upb_MiniTableField* field = (upb_MiniTableField*)&ret->UPB_PRIVATE(fields)[i]; - if (field->offset == kRequiredPresence) { + if (field->UPB_PRIVATE(offset) == kRequiredPresence) { field->presence = ++last_hasbit; - } else if (field->offset == kNoPresence) { + } else if (field->UPB_PRIVATE(offset) == kNoPresence) { field->presence = 0; } } @@ -7000,7 +7000,7 @@ static void upb_MtDecoder_AssignHasbits(upb_MtDecoder* d) { for (int i = 0; i < n; i++) { upb_MiniTableField* field = (upb_MiniTableField*)&ret->UPB_PRIVATE(fields)[i]; - if (field->offset == kHasbitPresence) { + if (field->UPB_PRIVATE(offset) == kHasbitPresence) { field->presence = ++last_hasbit; } } @@ -7038,9 +7038,10 @@ static void upb_MtDecoder_AssignOffsets(upb_MtDecoder* d) { upb_MiniTableField* f = &d->fields[item->field_index]; while (true) { f->presence = ~item->offset; - if (f->offset == kUpb_LayoutItem_IndexSentinel) break; - UPB_ASSERT(f->offset - kOneofBase < d->table->UPB_PRIVATE(field_count)); - f = &d->fields[f->offset - kOneofBase]; + if (f->UPB_PRIVATE(offset) == kUpb_LayoutItem_IndexSentinel) break; + UPB_ASSERT(f->UPB_PRIVATE(offset) - kOneofBase < + d->table->UPB_PRIVATE(field_count)); + f = &d->fields[f->UPB_PRIVATE(offset) - kOneofBase]; } } @@ -7050,14 +7051,14 @@ static void upb_MtDecoder_AssignOffsets(upb_MtDecoder* d) { switch (item->type) { case kUpb_LayoutItemType_OneofField: while (true) { - uint16_t next_offset = f->offset; - f->offset = item->offset; + uint16_t next_offset = f->UPB_PRIVATE(offset); + f->UPB_PRIVATE(offset) = item->offset; if (next_offset == kUpb_LayoutItem_IndexSentinel) break; f = &d->fields[next_offset - kOneofBase]; } break; case kUpb_LayoutItemType_Field: - f->offset = item->offset; + f->UPB_PRIVATE(offset) = item->offset; break; default: break; @@ -7128,8 +7129,8 @@ static void upb_MtDecoder_ParseMap(upb_MtDecoder* d, const char* data, // NOTE: sync with mini_table/message_internal.h. const size_t kv_size = d->platform == kUpb_MiniTablePlatform_32Bit ? 8 : 16; const size_t hasbit_size = 8; - d->fields[0].offset = hasbit_size; - d->fields[1].offset = hasbit_size + kv_size; + d->fields[0].UPB_PRIVATE(offset) = hasbit_size; + d->fields[1].UPB_PRIVATE(offset) = hasbit_size + kv_size; d->table->UPB_PRIVATE(size) = UPB_ALIGN_UP(hasbit_size + kv_size + kv_size, 8); @@ -7254,7 +7255,7 @@ static const char* upb_MtDecoder_DoBuildMiniTableExtension( upb_MiniTableField* f = &ext->UPB_PRIVATE(field); f->UPB_PRIVATE(mode) |= kUpb_LabelFlags_IsExtension; - f->offset = 0; + f->UPB_PRIVATE(offset) = 0; f->presence = 0; if (extendee->UPB_PRIVATE(ext) & kUpb_ExtMode_IsMessageSet) { @@ -12700,7 +12701,7 @@ static const char* _upb_Decoder_DecodeToArray(upb_Decoder* d, const char* ptr, const upb_MiniTableSub* subs, const upb_MiniTableField* field, wireval* val, int op) { - upb_Array** arrp = UPB_PTR_AT(msg, field->offset, void); + upb_Array** arrp = UPB_PTR_AT(msg, field->UPB_PRIVATE(offset), void); upb_Array* arr = *arrp; void* mem; @@ -12791,8 +12792,8 @@ upb_Map* _upb_Decoder_CreateMap(upb_Decoder* d, const upb_MiniTable* entry) { const upb_MiniTableField* val_field = &entry->UPB_PRIVATE(fields)[1]; char key_size = kSizeInMap[key_field->UPB_PRIVATE(descriptortype)]; char val_size = kSizeInMap[val_field->UPB_PRIVATE(descriptortype)]; - UPB_ASSERT(key_field->offset == offsetof(upb_MapEntryData, k)); - UPB_ASSERT(val_field->offset == offsetof(upb_MapEntryData, v)); + UPB_ASSERT(key_field->UPB_PRIVATE(offset) == offsetof(upb_MapEntryData, k)); + UPB_ASSERT(val_field->UPB_PRIVATE(offset) == offsetof(upb_MapEntryData, v)); upb_Map* ret = _upb_Map_New(&d->arena, key_size, val_size); if (!ret) _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_OutOfMemory); return ret; @@ -12803,7 +12804,7 @@ static const char* _upb_Decoder_DecodeToMap(upb_Decoder* d, const char* ptr, const upb_MiniTableSub* subs, const upb_MiniTableField* field, wireval* val) { - upb_Map** map_p = UPB_PTR_AT(msg, field->offset, upb_Map*); + upb_Map** map_p = UPB_PTR_AT(msg, field->UPB_PRIVATE(offset), upb_Map*); upb_Map* map = *map_p; upb_MapEntry ent; UPB_ASSERT(upb_MiniTableField_Type(field) == kUpb_FieldType_Message); @@ -12866,7 +12867,7 @@ static const char* _upb_Decoder_DecodeToSubMessage( upb_Decoder* d, const char* ptr, upb_Message* msg, const upb_MiniTableSub* subs, const upb_MiniTableField* field, wireval* val, int op) { - void* mem = UPB_PTR_AT(msg, field->offset, void); + void* mem = UPB_PTR_AT(msg, field->UPB_PRIVATE(offset), void); int type = field->UPB_PRIVATE(descriptortype); if (UPB_UNLIKELY(op == kUpb_DecodeOp_Enum) && @@ -14839,7 +14840,7 @@ static void encode_scalar(upb_encstate* e, const void* _field_mem, static void encode_array(upb_encstate* e, const upb_Message* msg, const upb_MiniTableSub* subs, const upb_MiniTableField* f) { - const upb_Array* arr = *UPB_PTR_AT(msg, f->offset, upb_Array*); + const upb_Array* arr = *UPB_PTR_AT(msg, f->UPB_PRIVATE(offset), upb_Array*); bool packed = upb_MiniTableField_IsPacked(f); size_t pre_len = e->limit - e->ptr; @@ -14962,7 +14963,7 @@ static void encode_mapentry(upb_encstate* e, uint32_t number, static void encode_map(upb_encstate* e, const upb_Message* msg, const upb_MiniTableSub* subs, const upb_MiniTableField* f) { - const upb_Map* map = *UPB_PTR_AT(msg, f->offset, const upb_Map*); + const upb_Map* map = *UPB_PTR_AT(msg, f->UPB_PRIVATE(offset), const upb_Map*); const upb_MiniTable* layout = upb_MiniTableSub_Message(subs[f->UPB_PRIVATE(submsg_index)]); UPB_ASSERT(layout->UPB_PRIVATE(field_count) == 2); @@ -14997,7 +14998,7 @@ static bool encode_shouldencode(upb_encstate* e, const upb_Message* msg, const upb_MiniTableField* f) { if (f->presence == 0) { // Proto3 presence or map/array. - const void* mem = UPB_PTR_AT(msg, f->offset, void); + const void* mem = UPB_PTR_AT(msg, f->UPB_PRIVATE(offset), void); switch (UPB_PRIVATE(_upb_MiniTableField_GetRep)(f)) { case kUpb_FieldRep_1Byte: { char ch; @@ -15042,7 +15043,8 @@ static void encode_field(upb_encstate* e, const upb_Message* msg, encode_map(e, msg, subs, field); break; case kUpb_FieldMode_Scalar: - encode_scalar(e, UPB_PTR_AT(msg, field->offset, void), subs, field); + encode_scalar(e, UPB_PTR_AT(msg, field->UPB_PRIVATE(offset), void), subs, + field); break; default: UPB_UNREACHABLE(); diff --git a/ruby/ext/google/protobuf_c/ruby-upb.h b/ruby/ext/google/protobuf_c/ruby-upb.h index a73d8955bc56d..3f6da09e85847 100755 --- a/ruby/ext/google/protobuf_c/ruby-upb.h +++ b/ruby/ext/google/protobuf_c/ruby-upb.h @@ -1097,7 +1097,7 @@ UPB_INLINE int upb_FieldType_SizeLg2(upb_FieldType field_type) { // LINT.IfChange(struct_definition) struct upb_MiniTableField { uint32_t UPB_ONLYBITS(number); - uint16_t offset; + uint16_t UPB_ONLYBITS(offset); int16_t presence; // If >0, hasbit_index. If <0, ~oneof_index // Indexes into `upb_MiniTable.subs` @@ -1251,6 +1251,11 @@ UPB_PRIVATE(_upb_MiniTableField_Number)(const struct upb_MiniTableField* f) { return f->UPB_ONLYBITS(number); } +UPB_INLINE uint16_t +UPB_PRIVATE(_upb_MiniTableField_Offset)(const struct upb_MiniTableField* f) { + return f->UPB_ONLYBITS(offset); +} + UPB_INLINE size_t _upb_MiniTableField_OneofOffset(const struct upb_MiniTableField* f) { UPB_ASSERT(UPB_PRIVATE(_upb_MiniTableField_IsInOneof)(f)); @@ -2517,12 +2522,12 @@ UPB_INLINE void UPB_PRIVATE(_upb_Message_SetOneofCase)( UPB_INLINE void* _upb_MiniTableField_GetPtr(upb_Message* msg, const upb_MiniTableField* field) { - return (char*)msg + field->offset; + return (char*)msg + field->UPB_ONLYBITS(offset); } UPB_INLINE const void* _upb_MiniTableField_GetConstPtr( const upb_Message* msg, const upb_MiniTableField* field) { - return (char*)msg + field->offset; + return (char*)msg + field->UPB_ONLYBITS(offset); } UPB_INLINE void UPB_PRIVATE(_upb_Message_SetPresence)( @@ -3264,13 +3269,14 @@ UPB_API_INLINE upb_Message* upb_Message_GetOrCreateMutableMessage( const upb_MiniTableField* field, upb_Arena* arena) { UPB_ASSERT(arena); UPB_ASSUME(upb_MiniTableField_CType(field) == kUpb_CType_Message); - upb_Message* sub_message = *UPB_PTR_AT(msg, field->offset, upb_Message*); + upb_Message* sub_message = + *UPB_PTR_AT(msg, field->UPB_ONLYBITS(offset), upb_Message*); if (!sub_message) { const upb_MiniTable* sub_mini_table = upb_MiniTableSub_Message( mini_table->UPB_PRIVATE(subs)[field->UPB_PRIVATE(submsg_index)]); UPB_ASSERT(sub_mini_table); sub_message = _upb_Message_New(sub_mini_table, arena); - *UPB_PTR_AT(msg, field->offset, upb_Message*) = sub_message; + *UPB_PTR_AT(msg, field->UPB_ONLYBITS(offset), upb_Message*) = sub_message; UPB_PRIVATE(_upb_Message_SetPresence)(msg, field); } return sub_message; From 121896da15d036675ff30f153f0e6de0486ea3b1 Mon Sep 17 00:00:00 2001 From: Eric Salo Date: Mon, 18 Dec 2023 20:45:10 -0800 Subject: [PATCH 051/255] upb: add upb_Message_ExtensionByIndex() PiperOrigin-RevId: 592091162 --- upb/message/compat.c | 13 +++++++++++-- upb/message/compat.h | 3 +++ upb/message/copy.c | 4 +--- upb/message/internal/extension.c | 26 ++++++++++++++------------ upb/message/internal/extension.h | 8 ++++---- upb/message/message.c | 2 +- upb/reflection/message.c | 2 +- upb/wire/encode.c | 3 ++- 8 files changed, 37 insertions(+), 24 deletions(-) diff --git a/upb/message/compat.c b/upb/message/compat.c index 1341bcacd3a85..55ca51e5e0649 100644 --- a/upb/message/compat.c +++ b/upb/message/compat.c @@ -17,10 +17,19 @@ // Must be last. #include "upb/port/def.inc" +const upb_Extension* upb_Message_ExtensionByIndex(const upb_Message* msg, + size_t index) { + size_t count; + const upb_Extension* ext = UPB_PRIVATE(_upb_Message_Getexts)(msg, &count); + + UPB_ASSERT(index < count); + return &ext[index]; +} + const upb_Extension* upb_Message_FindExtensionByNumber(const upb_Message* msg, uint32_t field_number) { - size_t count = 0; - const upb_Extension* ext = _upb_Message_Getexts(msg, &count); + size_t count; + const upb_Extension* ext = UPB_PRIVATE(_upb_Message_Getexts)(msg, &count); while (count--) { if (upb_MiniTableExtension_Number(ext->ext) == field_number) return ext; diff --git a/upb/message/compat.h b/upb/message/compat.h index 2bbd47eb4fc44..566376f5cdada 100644 --- a/upb/message/compat.h +++ b/upb/message/compat.h @@ -24,6 +24,9 @@ extern "C" { #endif +const upb_Extension* upb_Message_ExtensionByIndex(const upb_Message* msg, + size_t index); + // Returns the extension with the given field number, or NULL on failure. const upb_Extension* upb_Message_FindExtensionByNumber(const upb_Message* msg, uint32_t field_number); diff --git a/upb/message/copy.c b/upb/message/copy.c index 43a8982a64055..912be5b3304a9 100644 --- a/upb/message/copy.c +++ b/upb/message/copy.c @@ -19,14 +19,12 @@ #include "upb/message/internal/array.h" #include "upb/message/internal/extension.h" #include "upb/message/internal/map.h" -#include "upb/message/internal/message.h" #include "upb/message/map.h" #include "upb/message/message.h" #include "upb/message/tagged_ptr.h" #include "upb/mini_table/extension.h" #include "upb/mini_table/field.h" #include "upb/mini_table/internal/field.h" -#include "upb/mini_table/internal/message.h" #include "upb/mini_table/internal/size_log2.h" #include "upb/mini_table/message.h" #include "upb/mini_table/sub.h" @@ -257,7 +255,7 @@ upb_Message* _upb_Message_Copy(upb_Message* dst, const upb_Message* src, } // Clone extensions. size_t ext_count; - const upb_Extension* ext = _upb_Message_Getexts(src, &ext_count); + const upb_Extension* ext = UPB_PRIVATE(_upb_Message_Getexts)(src, &ext_count); for (size_t i = 0; i < ext_count; ++i) { const upb_Extension* msg_ext = &ext[i]; const upb_MiniTableField* field = &msg_ext->ext->UPB_PRIVATE(field); diff --git a/upb/message/internal/extension.c b/upb/message/internal/extension.c index ae8f58dbce606..81cfa0f519025 100644 --- a/upb/message/internal/extension.c +++ b/upb/message/internal/extension.c @@ -18,10 +18,10 @@ // Must be last. #include "upb/port/def.inc" -const upb_Extension* _upb_Message_Getext(const upb_Message* msg, - const upb_MiniTableExtension* e) { +const struct upb_Extension* _upb_Message_Getext( + const upb_Message* msg, const upb_MiniTableExtension* e) { size_t n; - const upb_Extension* ext = _upb_Message_Getexts(msg, &n); + const struct upb_Extension* ext = UPB_PRIVATE(_upb_Message_Getexts)(msg, &n); // For now we use linear search exclusively to find extensions. // If this becomes an issue due to messages with lots of extensions, @@ -35,12 +35,12 @@ const upb_Extension* _upb_Message_Getext(const upb_Message* msg, return NULL; } -const upb_Extension* _upb_Message_Getexts(const upb_Message* msg, - size_t* count) { +const struct upb_Extension* UPB_PRIVATE(_upb_Message_Getexts)( + const upb_Message* msg, size_t* count) { const upb_Message_Internal* in = upb_Message_Getinternal(msg); if (in->internal) { - *count = - (in->internal->size - in->internal->ext_begin) / sizeof(upb_Extension); + *count = (in->internal->size - in->internal->ext_begin) / + sizeof(struct upb_Extension); return UPB_PTR_AT(in->internal, in->internal->ext_begin, void); } else { *count = 0; @@ -48,16 +48,18 @@ const upb_Extension* _upb_Message_Getexts(const upb_Message* msg, } } -upb_Extension* _upb_Message_GetOrCreateExtension( +struct upb_Extension* _upb_Message_GetOrCreateExtension( upb_Message* msg, const upb_MiniTableExtension* e, upb_Arena* arena) { - upb_Extension* ext = (upb_Extension*)_upb_Message_Getext(msg, e); + struct upb_Extension* ext = + (struct upb_Extension*)_upb_Message_Getext(msg, e); if (ext) return ext; - if (!UPB_PRIVATE(_upb_Message_Realloc)(msg, sizeof(upb_Extension), arena)) + if (!UPB_PRIVATE(_upb_Message_Realloc)(msg, sizeof(struct upb_Extension), + arena)) return NULL; upb_Message_Internal* in = upb_Message_Getinternal(msg); - in->internal->ext_begin -= sizeof(upb_Extension); + in->internal->ext_begin -= sizeof(struct upb_Extension); ext = UPB_PTR_AT(in->internal, in->internal->ext_begin, void); - memset(ext, 0, sizeof(upb_Extension)); + memset(ext, 0, sizeof(struct upb_Extension)); ext->ext = e; return ext; } diff --git a/upb/message/internal/extension.h b/upb/message/internal/extension.h index 8d2a3a5e04d54..86b1e6f2beb38 100644 --- a/upb/message/internal/extension.h +++ b/upb/message/internal/extension.h @@ -45,11 +45,11 @@ upb_Extension* _upb_Message_GetOrCreateExtension( // Returns an array of extensions for this message. // Note: the array is ordered in reverse relative to the order of creation. -const upb_Extension* _upb_Message_Getexts(const upb_Message* msg, - size_t* count); +const upb_Extension* UPB_PRIVATE(_upb_Message_Getexts)(const upb_Message* msg, + size_t* count); -// Returns an extension for the given field number, or NULL if no extension -// exists for this field number. +// Returns an extension for a message with a given mini table, +// or NULL if no extension exists with this mini table. const upb_Extension* _upb_Message_Getext(const upb_Message* msg, const upb_MiniTableExtension* ext); diff --git a/upb/message/message.c b/upb/message/message.c index 67cb309181139..4f0fee1ad341c 100644 --- a/upb/message/message.c +++ b/upb/message/message.c @@ -72,6 +72,6 @@ void upb_Message_DeleteUnknown(upb_Message* msg, const char* data, size_t len) { size_t upb_Message_ExtensionCount(const upb_Message* msg) { size_t count; - _upb_Message_Getexts(msg, &count); + UPB_PRIVATE(_upb_Message_Getexts)(msg, &count); return count; } diff --git a/upb/reflection/message.c b/upb/reflection/message.c index bff9c469a1daf..977bf33cc8744 100644 --- a/upb/reflection/message.c +++ b/upb/reflection/message.c @@ -146,7 +146,7 @@ bool upb_Message_Next(const upb_Message* msg, const upb_MessageDef* m, if (ext_pool) { // Return any extensions that are set. size_t count; - const upb_Extension* ext = _upb_Message_Getexts(msg, &count); + const upb_Extension* ext = UPB_PRIVATE(_upb_Message_Getexts)(msg, &count); if (i - n < count) { ext += count - 1 - (i - n); memcpy(out_val, &ext->data, sizeof(*out_val)); diff --git a/upb/wire/encode.c b/upb/wire/encode.c index 4f923e9c3994c..8618921c3e7b5 100644 --- a/upb/wire/encode.c +++ b/upb/wire/encode.c @@ -570,7 +570,8 @@ static void encode_message(upb_encstate* e, const upb_Message* msg, * these in field number order relative to normal fields or even to each * other. */ size_t ext_count; - const upb_Extension* ext = _upb_Message_Getexts(msg, &ext_count); + const upb_Extension* ext = + UPB_PRIVATE(_upb_Message_Getexts)(msg, &ext_count); if (ext_count) { if (e->options & kUpb_EncodeOption_Deterministic) { _upb_sortedmap sorted; From f284522c4be739f9830985ce8e2d87cdfd46a58d Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Tue, 19 Dec 2023 04:57:32 +0000 Subject: [PATCH 052/255] Auto-generate files after cl/592091162 --- php/ext/google/protobuf/php-upb.c | 48 +++++++++++++++++---------- php/ext/google/protobuf/php-upb.h | 11 +++--- ruby/ext/google/protobuf_c/ruby-upb.c | 48 +++++++++++++++++---------- ruby/ext/google/protobuf_c/ruby-upb.h | 11 +++--- 4 files changed, 74 insertions(+), 44 deletions(-) diff --git a/php/ext/google/protobuf/php-upb.c b/php/ext/google/protobuf/php-upb.c index bb221bad4604c..62c9f654abacf 100644 --- a/php/ext/google/protobuf/php-upb.c +++ b/php/ext/google/protobuf/php-upb.c @@ -5934,10 +5934,19 @@ void upb_Arena_DecRefFor(upb_Arena* arena, const void* owner) { // Must be last. +const upb_Extension* upb_Message_ExtensionByIndex(const upb_Message* msg, + size_t index) { + size_t count; + const upb_Extension* ext = UPB_PRIVATE(_upb_Message_Getexts)(msg, &count); + + UPB_ASSERT(index < count); + return &ext[index]; +} + const upb_Extension* upb_Message_FindExtensionByNumber(const upb_Message* msg, uint32_t field_number) { - size_t count = 0; - const upb_Extension* ext = _upb_Message_Getexts(msg, &count); + size_t count; + const upb_Extension* ext = UPB_PRIVATE(_upb_Message_Getexts)(msg, &count); while (count--) { if (upb_MiniTableExtension_Number(ext->ext) == field_number) return ext; @@ -6231,7 +6240,7 @@ upb_Message* _upb_Message_Copy(upb_Message* dst, const upb_Message* src, } // Clone extensions. size_t ext_count; - const upb_Extension* ext = _upb_Message_Getexts(src, &ext_count); + const upb_Extension* ext = UPB_PRIVATE(_upb_Message_Getexts)(src, &ext_count); for (size_t i = 0; i < ext_count; ++i) { const upb_Extension* msg_ext = &ext[i]; const upb_MiniTableField* field = &msg_ext->ext->UPB_PRIVATE(field); @@ -6414,10 +6423,10 @@ bool UPB_PRIVATE(_upb_Array_Realloc)(upb_Array* array, size_t min_capacity, // Must be last. -const upb_Extension* _upb_Message_Getext(const upb_Message* msg, - const upb_MiniTableExtension* e) { +const struct upb_Extension* _upb_Message_Getext( + const upb_Message* msg, const upb_MiniTableExtension* e) { size_t n; - const upb_Extension* ext = _upb_Message_Getexts(msg, &n); + const struct upb_Extension* ext = UPB_PRIVATE(_upb_Message_Getexts)(msg, &n); // For now we use linear search exclusively to find extensions. // If this becomes an issue due to messages with lots of extensions, @@ -6431,12 +6440,12 @@ const upb_Extension* _upb_Message_Getext(const upb_Message* msg, return NULL; } -const upb_Extension* _upb_Message_Getexts(const upb_Message* msg, - size_t* count) { +const struct upb_Extension* UPB_PRIVATE(_upb_Message_Getexts)( + const upb_Message* msg, size_t* count) { const upb_Message_Internal* in = upb_Message_Getinternal(msg); if (in->internal) { - *count = - (in->internal->size - in->internal->ext_begin) / sizeof(upb_Extension); + *count = (in->internal->size - in->internal->ext_begin) / + sizeof(struct upb_Extension); return UPB_PTR_AT(in->internal, in->internal->ext_begin, void); } else { *count = 0; @@ -6444,16 +6453,18 @@ const upb_Extension* _upb_Message_Getexts(const upb_Message* msg, } } -upb_Extension* _upb_Message_GetOrCreateExtension( +struct upb_Extension* _upb_Message_GetOrCreateExtension( upb_Message* msg, const upb_MiniTableExtension* e, upb_Arena* arena) { - upb_Extension* ext = (upb_Extension*)_upb_Message_Getext(msg, e); + struct upb_Extension* ext = + (struct upb_Extension*)_upb_Message_Getext(msg, e); if (ext) return ext; - if (!UPB_PRIVATE(_upb_Message_Realloc)(msg, sizeof(upb_Extension), arena)) + if (!UPB_PRIVATE(_upb_Message_Realloc)(msg, sizeof(struct upb_Extension), + arena)) return NULL; upb_Message_Internal* in = upb_Message_Getinternal(msg); - in->internal->ext_begin -= sizeof(upb_Extension); + in->internal->ext_begin -= sizeof(struct upb_Extension); ext = UPB_PTR_AT(in->internal, in->internal->ext_begin, void); - memset(ext, 0, sizeof(upb_Extension)); + memset(ext, 0, sizeof(struct upb_Extension)); ext->ext = e; return ext; } @@ -6819,7 +6830,7 @@ void upb_Message_DeleteUnknown(upb_Message* msg, const char* data, size_t len) { size_t upb_Message_ExtensionCount(const upb_Message* msg) { size_t count; - _upb_Message_Getexts(msg, &count); + UPB_PRIVATE(_upb_Message_Getexts)(msg, &count); return count; } @@ -11437,7 +11448,7 @@ bool upb_Message_Next(const upb_Message* msg, const upb_MessageDef* m, if (ext_pool) { // Return any extensions that are set. size_t count; - const upb_Extension* ext = _upb_Message_Getexts(msg, &count); + const upb_Extension* ext = UPB_PRIVATE(_upb_Message_Getexts)(msg, &count); if (i - n < count) { ext += count - 1 - (i - n); memcpy(out_val, &ext->data, sizeof(*out_val)); @@ -15587,7 +15598,8 @@ static void encode_message(upb_encstate* e, const upb_Message* msg, * these in field number order relative to normal fields or even to each * other. */ size_t ext_count; - const upb_Extension* ext = _upb_Message_Getexts(msg, &ext_count); + const upb_Extension* ext = + UPB_PRIVATE(_upb_Message_Getexts)(msg, &ext_count); if (ext_count) { if (e->options & kUpb_EncodeOption_Deterministic) { _upb_sortedmap sorted; diff --git a/php/ext/google/protobuf/php-upb.h b/php/ext/google/protobuf/php-upb.h index 3c0570cb1efc9..95e64b9759f34 100644 --- a/php/ext/google/protobuf/php-upb.h +++ b/php/ext/google/protobuf/php-upb.h @@ -1775,11 +1775,11 @@ upb_Extension* _upb_Message_GetOrCreateExtension( // Returns an array of extensions for this message. // Note: the array is ordered in reverse relative to the order of creation. -const upb_Extension* _upb_Message_Getexts(const upb_Message* msg, - size_t* count); +const upb_Extension* UPB_PRIVATE(_upb_Message_Getexts)(const upb_Message* msg, + size_t* count); -// Returns an extension for the given field number, or NULL if no extension -// exists for this field number. +// Returns an extension for a message with a given mini table, +// or NULL if no extension exists with this mini table. const upb_Extension* _upb_Message_Getext(const upb_Message* msg, const upb_MiniTableExtension* ext); @@ -12287,6 +12287,9 @@ UPB_INLINE bool _upb_NonAtomic_CompareExchangeStrongP(void* addr, extern "C" { #endif +const upb_Extension* upb_Message_ExtensionByIndex(const upb_Message* msg, + size_t index); + // Returns the extension with the given field number, or NULL on failure. const upb_Extension* upb_Message_FindExtensionByNumber(const upb_Message* msg, uint32_t field_number); diff --git a/ruby/ext/google/protobuf_c/ruby-upb.c b/ruby/ext/google/protobuf_c/ruby-upb.c index 73b1af4887e1b..89431e8a714d4 100644 --- a/ruby/ext/google/protobuf_c/ruby-upb.c +++ b/ruby/ext/google/protobuf_c/ruby-upb.c @@ -5448,10 +5448,19 @@ void upb_Arena_DecRefFor(upb_Arena* arena, const void* owner) { // Must be last. +const upb_Extension* upb_Message_ExtensionByIndex(const upb_Message* msg, + size_t index) { + size_t count; + const upb_Extension* ext = UPB_PRIVATE(_upb_Message_Getexts)(msg, &count); + + UPB_ASSERT(index < count); + return &ext[index]; +} + const upb_Extension* upb_Message_FindExtensionByNumber(const upb_Message* msg, uint32_t field_number) { - size_t count = 0; - const upb_Extension* ext = _upb_Message_Getexts(msg, &count); + size_t count; + const upb_Extension* ext = UPB_PRIVATE(_upb_Message_Getexts)(msg, &count); while (count--) { if (upb_MiniTableExtension_Number(ext->ext) == field_number) return ext; @@ -5745,7 +5754,7 @@ upb_Message* _upb_Message_Copy(upb_Message* dst, const upb_Message* src, } // Clone extensions. size_t ext_count; - const upb_Extension* ext = _upb_Message_Getexts(src, &ext_count); + const upb_Extension* ext = UPB_PRIVATE(_upb_Message_Getexts)(src, &ext_count); for (size_t i = 0; i < ext_count; ++i) { const upb_Extension* msg_ext = &ext[i]; const upb_MiniTableField* field = &msg_ext->ext->UPB_PRIVATE(field); @@ -5928,10 +5937,10 @@ bool UPB_PRIVATE(_upb_Array_Realloc)(upb_Array* array, size_t min_capacity, // Must be last. -const upb_Extension* _upb_Message_Getext(const upb_Message* msg, - const upb_MiniTableExtension* e) { +const struct upb_Extension* _upb_Message_Getext( + const upb_Message* msg, const upb_MiniTableExtension* e) { size_t n; - const upb_Extension* ext = _upb_Message_Getexts(msg, &n); + const struct upb_Extension* ext = UPB_PRIVATE(_upb_Message_Getexts)(msg, &n); // For now we use linear search exclusively to find extensions. // If this becomes an issue due to messages with lots of extensions, @@ -5945,12 +5954,12 @@ const upb_Extension* _upb_Message_Getext(const upb_Message* msg, return NULL; } -const upb_Extension* _upb_Message_Getexts(const upb_Message* msg, - size_t* count) { +const struct upb_Extension* UPB_PRIVATE(_upb_Message_Getexts)( + const upb_Message* msg, size_t* count) { const upb_Message_Internal* in = upb_Message_Getinternal(msg); if (in->internal) { - *count = - (in->internal->size - in->internal->ext_begin) / sizeof(upb_Extension); + *count = (in->internal->size - in->internal->ext_begin) / + sizeof(struct upb_Extension); return UPB_PTR_AT(in->internal, in->internal->ext_begin, void); } else { *count = 0; @@ -5958,16 +5967,18 @@ const upb_Extension* _upb_Message_Getexts(const upb_Message* msg, } } -upb_Extension* _upb_Message_GetOrCreateExtension( +struct upb_Extension* _upb_Message_GetOrCreateExtension( upb_Message* msg, const upb_MiniTableExtension* e, upb_Arena* arena) { - upb_Extension* ext = (upb_Extension*)_upb_Message_Getext(msg, e); + struct upb_Extension* ext = + (struct upb_Extension*)_upb_Message_Getext(msg, e); if (ext) return ext; - if (!UPB_PRIVATE(_upb_Message_Realloc)(msg, sizeof(upb_Extension), arena)) + if (!UPB_PRIVATE(_upb_Message_Realloc)(msg, sizeof(struct upb_Extension), + arena)) return NULL; upb_Message_Internal* in = upb_Message_Getinternal(msg); - in->internal->ext_begin -= sizeof(upb_Extension); + in->internal->ext_begin -= sizeof(struct upb_Extension); ext = UPB_PTR_AT(in->internal, in->internal->ext_begin, void); - memset(ext, 0, sizeof(upb_Extension)); + memset(ext, 0, sizeof(struct upb_Extension)); ext->ext = e; return ext; } @@ -6333,7 +6344,7 @@ void upb_Message_DeleteUnknown(upb_Message* msg, const char* data, size_t len) { size_t upb_Message_ExtensionCount(const upb_Message* msg) { size_t count; - _upb_Message_Getexts(msg, &count); + UPB_PRIVATE(_upb_Message_Getexts)(msg, &count); return count; } @@ -10951,7 +10962,7 @@ bool upb_Message_Next(const upb_Message* msg, const upb_MessageDef* m, if (ext_pool) { // Return any extensions that are set. size_t count; - const upb_Extension* ext = _upb_Message_Getexts(msg, &count); + const upb_Extension* ext = UPB_PRIVATE(_upb_Message_Getexts)(msg, &count); if (i - n < count) { ext += count - 1 - (i - n); memcpy(out_val, &ext->data, sizeof(*out_val)); @@ -15101,7 +15112,8 @@ static void encode_message(upb_encstate* e, const upb_Message* msg, * these in field number order relative to normal fields or even to each * other. */ size_t ext_count; - const upb_Extension* ext = _upb_Message_Getexts(msg, &ext_count); + const upb_Extension* ext = + UPB_PRIVATE(_upb_Message_Getexts)(msg, &ext_count); if (ext_count) { if (e->options & kUpb_EncodeOption_Deterministic) { _upb_sortedmap sorted; diff --git a/ruby/ext/google/protobuf_c/ruby-upb.h b/ruby/ext/google/protobuf_c/ruby-upb.h index 3f6da09e85847..9b92b33700367 100755 --- a/ruby/ext/google/protobuf_c/ruby-upb.h +++ b/ruby/ext/google/protobuf_c/ruby-upb.h @@ -1777,11 +1777,11 @@ upb_Extension* _upb_Message_GetOrCreateExtension( // Returns an array of extensions for this message. // Note: the array is ordered in reverse relative to the order of creation. -const upb_Extension* _upb_Message_Getexts(const upb_Message* msg, - size_t* count); +const upb_Extension* UPB_PRIVATE(_upb_Message_Getexts)(const upb_Message* msg, + size_t* count); -// Returns an extension for the given field number, or NULL if no extension -// exists for this field number. +// Returns an extension for a message with a given mini table, +// or NULL if no extension exists with this mini table. const upb_Extension* _upb_Message_Getext(const upb_Message* msg, const upb_MiniTableExtension* ext); @@ -12059,6 +12059,9 @@ UPB_INLINE bool _upb_NonAtomic_CompareExchangeStrongP(void* addr, extern "C" { #endif +const upb_Extension* upb_Message_ExtensionByIndex(const upb_Message* msg, + size_t index); + // Returns the extension with the given field number, or NULL on failure. const upb_Extension* upb_Message_FindExtensionByNumber(const upb_Message* msg, uint32_t field_number); From 1587fefee7791b589a7f24359d9e5e2b69de8d10 Mon Sep 17 00:00:00 2001 From: Eric Salo Date: Mon, 18 Dec 2023 22:05:51 -0800 Subject: [PATCH 053/255] upb: simplify upb_Map_Insert() down to upb_Map_Set() where possible PiperOrigin-RevId: 592107014 --- upb/message/accessors.c | 10 ++++------ upb/message/accessors.h | 8 +++----- upb/message/copy.c | 3 +-- upb/message/internal/map.h | 10 +++++++--- upb/message/internal/map_entry.h | 8 +++++--- upb/message/internal/map_sorter.h | 6 +++--- upb/message/promote.c | 11 +++-------- 7 files changed, 26 insertions(+), 30 deletions(-) diff --git a/upb/message/accessors.c b/upb/message/accessors.c index edc63bc2dce60..0153956f12d22 100644 --- a/upb/message/accessors.c +++ b/upb/message/accessors.c @@ -21,11 +21,9 @@ // Must be last. #include "upb/port/def.inc" -upb_MapInsertStatus upb_Message_InsertMapEntry(upb_Map* map, - const upb_MiniTable* mini_table, - const upb_MiniTableField* f, - upb_Message* map_entry_message, - upb_Arena* arena) { +bool upb_Message_SetMapEntry(upb_Map* map, const upb_MiniTable* mini_table, + const upb_MiniTableField* f, + upb_Message* map_entry_message, upb_Arena* arena) { // TODO: use a variant of upb_MiniTable_GetSubMessageTable() here. const upb_MiniTable* map_entry_mini_table = upb_MiniTableSub_Message( mini_table->UPB_PRIVATE(subs)[f->UPB_PRIVATE(submsg_index)]); @@ -43,7 +41,7 @@ upb_MapInsertStatus upb_Message_InsertMapEntry(upb_Map* map, upb_Message_GetField(map_entry_message, map_entry_key_field, default_val); upb_MessageValue map_entry_value = upb_Message_GetField( map_entry_message, map_entry_value_field, default_val); - return upb_Map_Insert(map, map_entry_key, map_entry_value, arena); + return upb_Map_Set(map, map_entry_key, map_entry_value, arena); } bool upb_Message_IsExactlyEqual(const upb_Message* m1, const upb_Message* m2, diff --git a/upb/message/accessors.h b/upb/message/accessors.h index 55ce69889a6fc..74d145c8843a9 100644 --- a/upb/message/accessors.h +++ b/upb/message/accessors.h @@ -449,11 +449,9 @@ UPB_API_INLINE upb_Map* upb_Message_GetOrCreateMutableMap( } // Updates a map entry given an entry message. -upb_MapInsertStatus upb_Message_InsertMapEntry(upb_Map* map, - const upb_MiniTable* mini_table, - const upb_MiniTableField* field, - upb_Message* map_entry_message, - upb_Arena* arena); +bool upb_Message_SetMapEntry(upb_Map* map, const upb_MiniTable* mini_table, + const upb_MiniTableField* field, + upb_Message* map_entry_message, upb_Arena* arena); // Compares two messages by serializing them and calling memcmp(). bool upb_Message_IsExactlyEqual(const upb_Message* m1, const upb_Message* m2, diff --git a/upb/message/copy.c b/upb/message/copy.c index 912be5b3304a9..c6def53d12b95 100644 --- a/upb/message/copy.c +++ b/upb/message/copy.c @@ -105,8 +105,7 @@ upb_Map* upb_Map_DeepClone(const upb_Map* map, upb_CType key_type, if (!upb_Clone_MessageValue(&val, value_field_type, value_sub, arena)) { return NULL; } - if (upb_Map_Insert(cloned_map, key, val, arena) == - kUpb_MapInsertStatus_OutOfMemory) { + if (!upb_Map_Set(cloned_map, key, val, arena)) { return NULL; } } diff --git a/upb/message/internal/map.h b/upb/message/internal/map.h index dc4beae690764..51bc16be12f82 100644 --- a/upb/message/internal/map.h +++ b/upb/message/internal/map.h @@ -7,9 +7,13 @@ // EVERYTHING BELOW THIS LINE IS INTERNAL - DO NOT USE ///////////////////////// -#ifndef UPB_COLLECTIONS_INTERNAL_MAP_H_ -#define UPB_COLLECTIONS_INTERNAL_MAP_H_ +#ifndef UPB_MESSAGE_INTERNAL_MAP_H_ +#define UPB_MESSAGE_INTERNAL_MAP_H_ +#include +#include + +#include "upb/base/descriptor_constants.h" #include "upb/base/string_view.h" #include "upb/hash/str_table.h" #include "upb/mem/arena.h" @@ -147,4 +151,4 @@ upb_Map* _upb_Map_New(upb_Arena* a, size_t key_size, size_t value_size); #include "upb/port/undef.inc" -#endif /* UPB_COLLECTIONS_INTERNAL_MAP_H_ */ +#endif /* UPB_MESSAGE_INTERNAL_MAP_H_ */ diff --git a/upb/message/internal/map_entry.h b/upb/message/internal/map_entry.h index 956f00ab42a07..0c5c25e919b75 100644 --- a/upb/message/internal/map_entry.h +++ b/upb/message/internal/map_entry.h @@ -5,8 +5,10 @@ // license that can be found in the LICENSE file or at // https://developers.google.com/open-source/licenses/bsd -#ifndef UPB_COLLECTIONS_INTERNAL_MAP_ENTRY_H_ -#define UPB_COLLECTIONS_INTERNAL_MAP_ENTRY_H_ +#ifndef UPB_MESSAGE_INTERNAL_MAP_ENTRY_H_ +#define UPB_MESSAGE_INTERNAL_MAP_ENTRY_H_ + +#include #include "upb/base/string_view.h" #include "upb/hash/common.h" @@ -40,4 +42,4 @@ typedef struct { upb_MapEntryData data; } upb_MapEntry; -#endif // UPB_COLLECTIONS_INTERNAL_MAP_ENTRY_H_ +#endif // UPB_MESSAGE_INTERNAL_MAP_ENTRY_H_ diff --git a/upb/message/internal/map_sorter.h b/upb/message/internal/map_sorter.h index a47d7a57df311..93be85ec363a6 100644 --- a/upb/message/internal/map_sorter.h +++ b/upb/message/internal/map_sorter.h @@ -7,8 +7,8 @@ // EVERYTHING BELOW THIS LINE IS INTERNAL - DO NOT USE ///////////////////////// -#ifndef UPB_COLLECTIONS_INTERNAL_MAP_SORTER_H_ -#define UPB_COLLECTIONS_INTERNAL_MAP_SORTER_H_ +#ifndef UPB_MESSAGE_INTERNAL_MAP_SORTER_H_ +#define UPB_MESSAGE_INTERNAL_MAP_SORTER_H_ #include @@ -86,4 +86,4 @@ bool _upb_mapsorter_pushexts(_upb_mapsorter* s, const upb_Extension* exts, #include "upb/port/undef.inc" -#endif /* UPB_COLLECTIONS_INTERNAL_MAP_SORTER_H_ */ +#endif /* UPB_MESSAGE_INTERNAL_MAP_SORTER_H_ */ diff --git a/upb/message/promote.c b/upb/message/promote.c index 329019e73eba1..4801c86247624 100644 --- a/upb/message/promote.c +++ b/upb/message/promote.c @@ -15,7 +15,6 @@ #include "upb/mem/arena.h" #include "upb/message/accessors.h" #include "upb/message/array.h" -#include "upb/message/internal/accessors.h" #include "upb/message/internal/array.h" #include "upb/message/internal/extension.h" #include "upb/message/internal/message.h" @@ -347,13 +346,9 @@ upb_UnknownToMessage_Status upb_MiniTable_PromoteUnknownToMap( upb_Map* map = upb_Message_GetOrCreateMutableMap(msg, map_entry_mini_table, field, arena); upb_Message* map_entry_message = ret.message; - upb_MapInsertStatus insert_status = upb_Message_InsertMapEntry( - map, mini_table, field, map_entry_message, arena); - if (insert_status == kUpb_MapInsertStatus_OutOfMemory) { - return kUpb_UnknownToMessage_OutOfMemory; - } - UPB_ASSUME(insert_status == kUpb_MapInsertStatus_Inserted || - insert_status == kUpb_MapInsertStatus_Replaced); + bool insert_success = upb_Message_SetMapEntry(map, mini_table, field, + map_entry_message, arena); + if (!insert_success) return kUpb_UnknownToMessage_OutOfMemory; upb_Message_DeleteUnknown(msg, unknown.ptr, unknown.len); } return kUpb_UnknownToMessage_Ok; From 5b343374e754efa8a2e9d8c6f59077ce7e5156c8 Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Tue, 19 Dec 2023 06:18:53 +0000 Subject: [PATCH 054/255] Auto-generate files after cl/592107014 --- php/ext/google/protobuf/php-upb.c | 13 +++++------ php/ext/google/protobuf/php-upb.h | 31 +++++++++++++++------------ ruby/ext/google/protobuf_c/ruby-upb.c | 13 +++++------ ruby/ext/google/protobuf_c/ruby-upb.h | 31 +++++++++++++++------------ 4 files changed, 44 insertions(+), 44 deletions(-) diff --git a/php/ext/google/protobuf/php-upb.c b/php/ext/google/protobuf/php-upb.c index 62c9f654abacf..b919c5c24fee9 100644 --- a/php/ext/google/protobuf/php-upb.c +++ b/php/ext/google/protobuf/php-upb.c @@ -5961,11 +5961,9 @@ const upb_Extension* upb_Message_FindExtensionByNumber(const upb_Message* msg, // Must be last. -upb_MapInsertStatus upb_Message_InsertMapEntry(upb_Map* map, - const upb_MiniTable* mini_table, - const upb_MiniTableField* f, - upb_Message* map_entry_message, - upb_Arena* arena) { +bool upb_Message_SetMapEntry(upb_Map* map, const upb_MiniTable* mini_table, + const upb_MiniTableField* f, + upb_Message* map_entry_message, upb_Arena* arena) { // TODO: use a variant of upb_MiniTable_GetSubMessageTable() here. const upb_MiniTable* map_entry_mini_table = upb_MiniTableSub_Message( mini_table->UPB_PRIVATE(subs)[f->UPB_PRIVATE(submsg_index)]); @@ -5983,7 +5981,7 @@ upb_MapInsertStatus upb_Message_InsertMapEntry(upb_Map* map, upb_Message_GetField(map_entry_message, map_entry_key_field, default_val); upb_MessageValue map_entry_value = upb_Message_GetField( map_entry_message, map_entry_value_field, default_val); - return upb_Map_Insert(map, map_entry_key, map_entry_value, arena); + return upb_Map_Set(map, map_entry_key, map_entry_value, arena); } bool upb_Message_IsExactlyEqual(const upb_Message* m1, const upb_Message* m2, @@ -6090,8 +6088,7 @@ upb_Map* upb_Map_DeepClone(const upb_Map* map, upb_CType key_type, if (!upb_Clone_MessageValue(&val, value_field_type, value_sub, arena)) { return NULL; } - if (upb_Map_Insert(cloned_map, key, val, arena) == - kUpb_MapInsertStatus_OutOfMemory) { + if (!upb_Map_Set(cloned_map, key, val, arena)) { return NULL; } } diff --git a/php/ext/google/protobuf/php-upb.h b/php/ext/google/protobuf/php-upb.h index 95e64b9759f34..70a48ae1045f4 100644 --- a/php/ext/google/protobuf/php-upb.h +++ b/php/ext/google/protobuf/php-upb.h @@ -1792,8 +1792,11 @@ const upb_Extension* _upb_Message_Getext(const upb_Message* msg, // EVERYTHING BELOW THIS LINE IS INTERNAL - DO NOT USE ///////////////////////// -#ifndef UPB_COLLECTIONS_INTERNAL_MAP_H_ -#define UPB_COLLECTIONS_INTERNAL_MAP_H_ +#ifndef UPB_MESSAGE_INTERNAL_MAP_H_ +#define UPB_MESSAGE_INTERNAL_MAP_H_ + +#include +#include #ifndef UPB_HASH_STR_TABLE_H_ @@ -2336,7 +2339,7 @@ upb_Map* _upb_Map_New(upb_Arena* a, size_t key_size, size_t value_size); #endif -#endif /* UPB_COLLECTIONS_INTERNAL_MAP_H_ */ +#endif /* UPB_MESSAGE_INTERNAL_MAP_H_ */ /* ** Our memory representation for parsing tables and messages themselves. @@ -3352,11 +3355,9 @@ UPB_API_INLINE upb_Map* upb_Message_GetOrCreateMutableMap( } // Updates a map entry given an entry message. -upb_MapInsertStatus upb_Message_InsertMapEntry(upb_Map* map, - const upb_MiniTable* mini_table, - const upb_MiniTableField* field, - upb_Message* map_entry_message, - upb_Arena* arena); +bool upb_Message_SetMapEntry(upb_Map* map, const upb_MiniTable* mini_table, + const upb_MiniTableField* field, + upb_Message* map_entry_message, upb_Arena* arena); // Compares two messages by serializing them and calling memcmp(). bool upb_Message_IsExactlyEqual(const upb_Message* m1, const upb_Message* m2, @@ -12346,14 +12347,16 @@ void upb_Message_ShallowCopy(upb_Message* dst, const upb_Message* src, // EVERYTHING BELOW THIS LINE IS INTERNAL - DO NOT USE ///////////////////////// -#ifndef UPB_COLLECTIONS_INTERNAL_MAP_SORTER_H_ -#define UPB_COLLECTIONS_INTERNAL_MAP_SORTER_H_ +#ifndef UPB_MESSAGE_INTERNAL_MAP_SORTER_H_ +#define UPB_MESSAGE_INTERNAL_MAP_SORTER_H_ #include -#ifndef UPB_COLLECTIONS_INTERNAL_MAP_ENTRY_H_ -#define UPB_COLLECTIONS_INTERNAL_MAP_ENTRY_H_ +#ifndef UPB_MESSAGE_INTERNAL_MAP_ENTRY_H_ +#define UPB_MESSAGE_INTERNAL_MAP_ENTRY_H_ + +#include // Map entries aren't actually stored for map fields, they are only used during @@ -12384,7 +12387,7 @@ typedef struct { upb_MapEntryData data; } upb_MapEntry; -#endif // UPB_COLLECTIONS_INTERNAL_MAP_ENTRY_H_ +#endif // UPB_MESSAGE_INTERNAL_MAP_ENTRY_H_ // Must be last. @@ -12453,7 +12456,7 @@ bool _upb_mapsorter_pushexts(_upb_mapsorter* s, const upb_Extension* exts, #endif -#endif /* UPB_COLLECTIONS_INTERNAL_MAP_SORTER_H_ */ +#endif /* UPB_MESSAGE_INTERNAL_MAP_SORTER_H_ */ #ifndef UPB_MINI_DESCRIPTOR_INTERNAL_BASE92_H_ #define UPB_MINI_DESCRIPTOR_INTERNAL_BASE92_H_ diff --git a/ruby/ext/google/protobuf_c/ruby-upb.c b/ruby/ext/google/protobuf_c/ruby-upb.c index 89431e8a714d4..50732bf20c9d4 100644 --- a/ruby/ext/google/protobuf_c/ruby-upb.c +++ b/ruby/ext/google/protobuf_c/ruby-upb.c @@ -5475,11 +5475,9 @@ const upb_Extension* upb_Message_FindExtensionByNumber(const upb_Message* msg, // Must be last. -upb_MapInsertStatus upb_Message_InsertMapEntry(upb_Map* map, - const upb_MiniTable* mini_table, - const upb_MiniTableField* f, - upb_Message* map_entry_message, - upb_Arena* arena) { +bool upb_Message_SetMapEntry(upb_Map* map, const upb_MiniTable* mini_table, + const upb_MiniTableField* f, + upb_Message* map_entry_message, upb_Arena* arena) { // TODO: use a variant of upb_MiniTable_GetSubMessageTable() here. const upb_MiniTable* map_entry_mini_table = upb_MiniTableSub_Message( mini_table->UPB_PRIVATE(subs)[f->UPB_PRIVATE(submsg_index)]); @@ -5497,7 +5495,7 @@ upb_MapInsertStatus upb_Message_InsertMapEntry(upb_Map* map, upb_Message_GetField(map_entry_message, map_entry_key_field, default_val); upb_MessageValue map_entry_value = upb_Message_GetField( map_entry_message, map_entry_value_field, default_val); - return upb_Map_Insert(map, map_entry_key, map_entry_value, arena); + return upb_Map_Set(map, map_entry_key, map_entry_value, arena); } bool upb_Message_IsExactlyEqual(const upb_Message* m1, const upb_Message* m2, @@ -5604,8 +5602,7 @@ upb_Map* upb_Map_DeepClone(const upb_Map* map, upb_CType key_type, if (!upb_Clone_MessageValue(&val, value_field_type, value_sub, arena)) { return NULL; } - if (upb_Map_Insert(cloned_map, key, val, arena) == - kUpb_MapInsertStatus_OutOfMemory) { + if (!upb_Map_Set(cloned_map, key, val, arena)) { return NULL; } } diff --git a/ruby/ext/google/protobuf_c/ruby-upb.h b/ruby/ext/google/protobuf_c/ruby-upb.h index 9b92b33700367..5e3b140168915 100755 --- a/ruby/ext/google/protobuf_c/ruby-upb.h +++ b/ruby/ext/google/protobuf_c/ruby-upb.h @@ -1794,8 +1794,11 @@ const upb_Extension* _upb_Message_Getext(const upb_Message* msg, // EVERYTHING BELOW THIS LINE IS INTERNAL - DO NOT USE ///////////////////////// -#ifndef UPB_COLLECTIONS_INTERNAL_MAP_H_ -#define UPB_COLLECTIONS_INTERNAL_MAP_H_ +#ifndef UPB_MESSAGE_INTERNAL_MAP_H_ +#define UPB_MESSAGE_INTERNAL_MAP_H_ + +#include +#include #ifndef UPB_HASH_STR_TABLE_H_ @@ -2338,7 +2341,7 @@ upb_Map* _upb_Map_New(upb_Arena* a, size_t key_size, size_t value_size); #endif -#endif /* UPB_COLLECTIONS_INTERNAL_MAP_H_ */ +#endif /* UPB_MESSAGE_INTERNAL_MAP_H_ */ /* ** Our memory representation for parsing tables and messages themselves. @@ -3354,11 +3357,9 @@ UPB_API_INLINE upb_Map* upb_Message_GetOrCreateMutableMap( } // Updates a map entry given an entry message. -upb_MapInsertStatus upb_Message_InsertMapEntry(upb_Map* map, - const upb_MiniTable* mini_table, - const upb_MiniTableField* field, - upb_Message* map_entry_message, - upb_Arena* arena); +bool upb_Message_SetMapEntry(upb_Map* map, const upb_MiniTable* mini_table, + const upb_MiniTableField* field, + upb_Message* map_entry_message, upb_Arena* arena); // Compares two messages by serializing them and calling memcmp(). bool upb_Message_IsExactlyEqual(const upb_Message* m1, const upb_Message* m2, @@ -12118,14 +12119,16 @@ void upb_Message_ShallowCopy(upb_Message* dst, const upb_Message* src, // EVERYTHING BELOW THIS LINE IS INTERNAL - DO NOT USE ///////////////////////// -#ifndef UPB_COLLECTIONS_INTERNAL_MAP_SORTER_H_ -#define UPB_COLLECTIONS_INTERNAL_MAP_SORTER_H_ +#ifndef UPB_MESSAGE_INTERNAL_MAP_SORTER_H_ +#define UPB_MESSAGE_INTERNAL_MAP_SORTER_H_ #include -#ifndef UPB_COLLECTIONS_INTERNAL_MAP_ENTRY_H_ -#define UPB_COLLECTIONS_INTERNAL_MAP_ENTRY_H_ +#ifndef UPB_MESSAGE_INTERNAL_MAP_ENTRY_H_ +#define UPB_MESSAGE_INTERNAL_MAP_ENTRY_H_ + +#include // Map entries aren't actually stored for map fields, they are only used during @@ -12156,7 +12159,7 @@ typedef struct { upb_MapEntryData data; } upb_MapEntry; -#endif // UPB_COLLECTIONS_INTERNAL_MAP_ENTRY_H_ +#endif // UPB_MESSAGE_INTERNAL_MAP_ENTRY_H_ // Must be last. @@ -12225,7 +12228,7 @@ bool _upb_mapsorter_pushexts(_upb_mapsorter* s, const upb_Extension* exts, #endif -#endif /* UPB_COLLECTIONS_INTERNAL_MAP_SORTER_H_ */ +#endif /* UPB_MESSAGE_INTERNAL_MAP_SORTER_H_ */ #ifndef UPB_MINI_DESCRIPTOR_INTERNAL_BASE92_H_ #define UPB_MINI_DESCRIPTOR_INTERNAL_BASE92_H_ From c763f3a3a3b119c564b191682c440668e17d464f Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Tue, 19 Dec 2023 05:54:40 -0800 Subject: [PATCH 055/255] Add allow dead_code to the oneof case enum. Without this it shows up as a spurious warning of dead code from never constructed enum cases (rustc can't 'see' that the value can come across from C++) PiperOrigin-RevId: 592209619 --- src/google/protobuf/compiler/rust/oneof.cc | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/google/protobuf/compiler/rust/oneof.cc b/src/google/protobuf/compiler/rust/oneof.cc index ce6e3af3c523a..8d269ae29e612 100644 --- a/src/google/protobuf/compiler/rust/oneof.cc +++ b/src/google/protobuf/compiler/rust/oneof.cc @@ -244,6 +244,7 @@ void GenerateOneofDefinition(Context& ctx, const OneofDescriptor& oneof) { R"rs( #[repr(C)] #[derive(Debug, Copy, Clone, PartialEq, Eq)] + #[allow(dead_code)] pub(super) enum $case_enum_name$ { $cases$ @@ -274,7 +275,9 @@ void GenerateOneofAccessors(Context& ctx, const OneofDescriptor& oneof) { {"rs_getter", field.name()}, {"type", rs_type}, }, - R"rs($Msg$_::$case_enum_name$::$case$ => $Msg$_::$view_enum_name$::$case$(self.$rs_getter$()), + R"rs( + $Msg$_::$case_enum_name$::$case$ => + $Msg$_::$view_enum_name$::$case$(self.$rs_getter$()), )rs"); } }}, @@ -309,8 +312,11 @@ void GenerateOneofAccessors(Context& ctx, const OneofDescriptor& oneof) { field.type() == FieldDescriptor::TYPE_MESSAGE ? "" : ".try_into_mut().unwrap()"}}, - R"rs($Msg$_::$case_enum_name$::$case$ => - $Msg$_::$mut_enum_name$::$case$(self.$rs_mut_getter$()$into_mut_transform$), )rs"); + R"rs( + $Msg$_::$case_enum_name$::$case$ => + $Msg$_::$mut_enum_name$::$case$( + self.$rs_mut_getter$()$into_mut_transform$), + )rs"); } }}, {"case_thunk", Thunk(ctx, oneof, "case")}}, From 8033709662850c08440762d7ffa4014d25d3f164 Mon Sep 17 00:00:00 2001 From: John Cater Date: Tue, 19 Dec 2023 06:35:32 -0800 Subject: [PATCH 056/255] Remove uses of `incompatible_use_toolchain_transition`. Now that Bazel 7.0 has been released, it's time to remove this tech debt. This has been a no-op since Bazel 5.0, I've been waiting to remove the code for two years, it's time. Part of https://github.com/bazelbuild/bazel/issues/14127. PiperOrigin-RevId: 592219242 --- protos/bazel/upb_cc_proto_library.bzl | 1 - 1 file changed, 1 deletion(-) diff --git a/protos/bazel/upb_cc_proto_library.bzl b/protos/bazel/upb_cc_proto_library.bzl index b59ae65e573e6..ad193b4a8a8fa 100644 --- a/protos/bazel/upb_cc_proto_library.bzl +++ b/protos/bazel/upb_cc_proto_library.bzl @@ -267,7 +267,6 @@ _upb_cc_proto_library_aspect = aspect( attr_aspects = ["deps"], fragments = ["cpp"], toolchains = use_cpp_toolchain(), - incompatible_use_toolchain_transition = True, ) upb_cc_proto_library = rule( From 1427a855b1bbe3aeae3fb453851d6ad8b46cbdbc Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Tue, 19 Dec 2023 08:13:54 -0800 Subject: [PATCH 057/255] Allow NewStringElement inlining. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ``` name old INSTRUCTIONS/op new INSTRUCTIONS/op delta BM_RepeatedPtrField_Ctor 251 ± 0% 251 ± 0% ~ (all samples are equal) BM_RepeatedPtrField_Add_Sso 84.8 ± 2% 76.7 ± 2% -9.51% (p=0.000 n=100+100) BM_RepeatedPtrField_Add_FallbackToRep 215 ± 5% 199 ± 5% -7.26% (p=0.000 n=100+99) BM_RepeatedPtrField_Add_Small 163 ± 1% 157 ± 1% -3.96% (p=0.000 n=100+100) BM_RepeatedPtrField_Add_Large 96.7 ± 1% 90.7 ± 1% -6.13% (p=0.000 n=100+100) BM_RepeatedPtrField_Add_HasCleared 36.5 ± 0% 36.5 ± 0% ~ (p=0.314 n=76+79) BM_RepeatedPtrField_AddAllocated 30.5 ± 0% 30.6 ± 1% ~ (p=0.109 n=78+93) BM_RepeatedPtrField_Sort 49.5k ± 0% 49.5k ± 0% +0.12% (p=0.000 n=80+95) BM_RepeatedPtrField_SortIndirect 559 ± 0% 561 ± 6% ~ (p=0.203 n=76+81) ``` PiperOrigin-RevId: 592241056 --- src/google/protobuf/repeated_ptr_field.cc | 37 ++++++++++++++--------- src/google/protobuf/repeated_ptr_field.h | 17 ++++++----- 2 files changed, 33 insertions(+), 21 deletions(-) diff --git a/src/google/protobuf/repeated_ptr_field.cc b/src/google/protobuf/repeated_ptr_field.cc index 49c29fe433d6a..6fe9f9af723ba 100644 --- a/src/google/protobuf/repeated_ptr_field.cc +++ b/src/google/protobuf/repeated_ptr_field.cc @@ -95,41 +95,49 @@ void RepeatedPtrFieldBase::DestroyProtos() { } template -auto* RepeatedPtrFieldBase::AddInternal(F factory) { +void* RepeatedPtrFieldBase::AddInternal(F factory) { Arena* const arena = GetArena(); - using Result = decltype(factory(arena)); + absl::PrefetchToLocalCache(tagged_rep_or_elem_); if (tagged_rep_or_elem_ == nullptr) { ExchangeCurrentSize(1); tagged_rep_or_elem_ = factory(arena); - return static_cast(tagged_rep_or_elem_); + return tagged_rep_or_elem_; } if (using_sso()) { - if (ExchangeCurrentSize(1) == 0) { - return static_cast(tagged_rep_or_elem_); + if (current_size_ == 0) { + ExchangeCurrentSize(1); + return tagged_rep_or_elem_; } - } else { - absl::PrefetchToLocalCache(rep()); + void*& result = *InternalExtend(1); + result = factory(arena); + Rep* r = rep(); + r->allocated_size = 2; + ExchangeCurrentSize(2); + return result; } + Rep* r = rep(); if (PROTOBUF_PREDICT_FALSE(SizeAtCapacity())) { InternalExtend(1); + r = rep(); } else { - Rep* r = rep(); if (current_size_ != r->allocated_size) { - return static_cast( - r->elements[ExchangeCurrentSize(current_size_ + 1)]); + return r->elements[ExchangeCurrentSize(current_size_ + 1)]; } } - Rep* r = rep(); ++r->allocated_size; void*& result = r->elements[ExchangeCurrentSize(current_size_ + 1)]; result = factory(arena); - return static_cast(result); + return result; } -void* RepeatedPtrFieldBase::AddOutOfLineHelper(ElementFactory factory) { +void* RepeatedPtrFieldBase::AddMessageLite(ElementFactory factory) { return AddInternal(factory); } +void* RepeatedPtrFieldBase::AddString() { + return AddInternal([](Arena* arena) { return NewStringElement(arena); }); +} + void RepeatedPtrFieldBase::CloseGap(int start, int num) { if (using_sso()) { if (start == 0 && num == 1) { @@ -146,7 +154,8 @@ void RepeatedPtrFieldBase::CloseGap(int start, int num) { } MessageLite* RepeatedPtrFieldBase::AddMessage(const MessageLite* prototype) { - return AddInternal([prototype](Arena* a) { return prototype->New(a); }); + return static_cast( + AddInternal([prototype](Arena* a) { return prototype->New(a); })); } void InternalOutOfLineDeleteMessageLite(MessageLite* message) { diff --git a/src/google/protobuf/repeated_ptr_field.h b/src/google/protobuf/repeated_ptr_field.h index 644bdb47574b6..cf2d667eec33f 100644 --- a/src/google/protobuf/repeated_ptr_field.h +++ b/src/google/protobuf/repeated_ptr_field.h @@ -183,7 +183,10 @@ class PROTOBUF_EXPORT RepeatedPtrFieldBase { template Value* Add() { - return cast(AddOutOfLineHelper(Handler::GetNewFunc())); + if (std::is_same, std::string>{}) { + return cast(AddString()); + } + return cast(AddMessageLite(Handler::GetNewFunc())); } template < @@ -742,8 +745,9 @@ class PROTOBUF_EXPORT RepeatedPtrFieldBase { return InternalExtend(n - Capacity()); } - // Internal helper for Add that keeps definition out-of-line. - void* AddOutOfLineHelper(ElementFactory factory); + // Internal helpers for Add that keep definition out-of-line. + void* AddMessageLite(ElementFactory factory); + void* AddString(); // Common implementation used by various Add* methods. `factory` is an object // used to construct a new element unless there are spare cleared elements @@ -751,10 +755,9 @@ class PROTOBUF_EXPORT RepeatedPtrFieldBase { // // Note: avoid inlining this function in methods such as `Add()` as this would // drastically increase binary size due to template instantiation and implicit - // inlining. Instead, use wrapper functions with out-of-line definition - // similar to `AddOutOfLineHelper`. - template - auto* AddInternal(F factory); + // inlining. + template + void* AddInternal(Factory factory); // A few notes on internal representation: // From ec1fd2700e3648c2da286c3b5e53680abad818c3 Mon Sep 17 00:00:00 2001 From: James Newton-King Date: Tue, 19 Dec 2023 12:08:40 -0800 Subject: [PATCH 058/255] [C#] Fix trimming warning in JSON formatter enum handling (#14789) There is a new trimming/AOT warning in JSON formatter enum handling. I have fixed it by suppressing the value. I also tested the solution with the .NET 8 SDK and suppressed some other warnings that came up (they're already handled). It would be great to include this fix in a 25.x release. Closes #14789 COPYBARA_INTEGRATE_REVIEW=https://github.com/protocolbuffers/protobuf/pull/14789 from JamesNK:jamesnk/enum-trimming-warning d64dda15f0aa94319a3b29edcfe27260c1bd58b4 PiperOrigin-RevId: 592306588 --- .../Google.Protobuf/Google.Protobuf.csproj | 5 +- csharp/src/Google.Protobuf/JsonFormatter.cs | 1742 ++++++++--------- .../Reflection/ReflectionUtil.cs | 671 ++++--- 3 files changed, 1162 insertions(+), 1256 deletions(-) diff --git a/csharp/src/Google.Protobuf/Google.Protobuf.csproj b/csharp/src/Google.Protobuf/Google.Protobuf.csproj index b5731cdebbdd0..88a9874889e7d 100644 --- a/csharp/src/Google.Protobuf/Google.Protobuf.csproj +++ b/csharp/src/Google.Protobuf/Google.Protobuf.csproj @@ -1,4 +1,4 @@ - + @@ -23,6 +23,9 @@ $(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb true + + $(NoWarn);NETSDK1195;NETSDK1210 diff --git a/csharp/src/Google.Protobuf/JsonFormatter.cs b/csharp/src/Google.Protobuf/JsonFormatter.cs index 48d3ab4c3d2c5..ff2f09b2545ce 100644 --- a/csharp/src/Google.Protobuf/JsonFormatter.cs +++ b/csharp/src/Google.Protobuf/JsonFormatter.cs @@ -20,979 +20,897 @@ using Google.Protobuf.Reflection; using Google.Protobuf.WellKnownTypes; -namespace Google.Protobuf -{ +namespace Google.Protobuf { + /// + /// Reflection-based converter from messages to JSON. + /// + /// + /// + /// Instances of this class are thread-safe, with no mutable state. + /// + /// + /// This is a simple start to get JSON formatting working. As it's reflection-based, + /// it's not as quick as baking calls into generated messages - but is a simpler implementation. + /// (This code is generally not heavily optimized.) + /// + /// + public sealed class JsonFormatter { + internal const string AnyTypeUrlField = "@type"; + internal const string AnyDiagnosticValueField = "@value"; + internal const string AnyWellKnownTypeValueField = "value"; + private const string NameValueSeparator = ": "; + private const string ValueSeparator = ", "; + private const string MultilineValueSeparator = ","; + private const char ObjectOpenBracket = '{'; + private const char ObjectCloseBracket = '}'; + private const char ListBracketOpen = '['; + private const char ListBracketClose = ']'; + /// - /// Reflection-based converter from messages to JSON. + /// Returns a formatter using the default settings. /// - /// - /// - /// Instances of this class are thread-safe, with no mutable state. - /// - /// - /// This is a simple start to get JSON formatting working. As it's reflection-based, - /// it's not as quick as baking calls into generated messages - but is a simpler implementation. - /// (This code is generally not heavily optimized.) - /// - /// - public sealed class JsonFormatter - { - internal const string AnyTypeUrlField = "@type"; - internal const string AnyDiagnosticValueField = "@value"; - internal const string AnyWellKnownTypeValueField = "value"; - private const string NameValueSeparator = ": "; - private const string ValueSeparator = ", "; - private const string MultilineValueSeparator = ","; - private const char ObjectOpenBracket = '{'; - private const char ObjectCloseBracket = '}'; - private const char ListBracketOpen = '['; - private const char ListBracketClose = ']'; - - /// - /// Returns a formatter using the default settings. - /// - public static JsonFormatter Default { get; } = new JsonFormatter(Settings.Default); - - // A JSON formatter which *only* exists - private static readonly JsonFormatter diagnosticFormatter = new JsonFormatter(Settings.Default); - - /// - /// The JSON representation of the first 160 characters of Unicode. - /// Empty strings are replaced by the static constructor. - /// - private static readonly string[] CommonRepresentations = { - // C0 (ASCII and derivatives) control characters - "\\u0000", "\\u0001", "\\u0002", "\\u0003", // 0x00 - "\\u0004", "\\u0005", "\\u0006", "\\u0007", - "\\b", "\\t", "\\n", "\\u000b", - "\\f", "\\r", "\\u000e", "\\u000f", - "\\u0010", "\\u0011", "\\u0012", "\\u0013", // 0x10 - "\\u0014", "\\u0015", "\\u0016", "\\u0017", - "\\u0018", "\\u0019", "\\u001a", "\\u001b", - "\\u001c", "\\u001d", "\\u001e", "\\u001f", - // Escaping of " and \ are required by www.json.org string definition. - // Escaping of < and > are required for HTML security. - "", "", "\\\"", "", "", "", "", "", // 0x20 - "", "", "", "", "", "", "", "", - "", "", "", "", "", "", "", "", // 0x30 - "", "", "", "", "\\u003c", "", "\\u003e", "", - "", "", "", "", "", "", "", "", // 0x40 - "", "", "", "", "", "", "", "", - "", "", "", "", "", "", "", "", // 0x50 - "", "", "", "", "\\\\", "", "", "", - "", "", "", "", "", "", "", "", // 0x60 - "", "", "", "", "", "", "", "", - "", "", "", "", "", "", "", "", // 0x70 - "", "", "", "", "", "", "", "\\u007f", - // C1 (ISO 8859 and Unicode) extended control characters - "\\u0080", "\\u0081", "\\u0082", "\\u0083", // 0x80 - "\\u0084", "\\u0085", "\\u0086", "\\u0087", - "\\u0088", "\\u0089", "\\u008a", "\\u008b", - "\\u008c", "\\u008d", "\\u008e", "\\u008f", - "\\u0090", "\\u0091", "\\u0092", "\\u0093", // 0x90 - "\\u0094", "\\u0095", "\\u0096", "\\u0097", - "\\u0098", "\\u0099", "\\u009a", "\\u009b", - "\\u009c", "\\u009d", "\\u009e", "\\u009f" - }; - - static JsonFormatter() - { - for (int i = 0; i < CommonRepresentations.Length; i++) - { - if (CommonRepresentations[i] == "") - { - CommonRepresentations[i] = ((char) i).ToString(); - } - } + public static JsonFormatter Default { get; } = new JsonFormatter(Settings.Default); + + // A JSON formatter which *only* exists + private static readonly JsonFormatter diagnosticFormatter = new JsonFormatter(Settings.Default); + + /// + /// The JSON representation of the first 160 characters of Unicode. + /// Empty strings are replaced by the static constructor. + /// + private static readonly string[] CommonRepresentations = { + // C0 (ASCII and derivatives) control characters + "\\u0000", "\\u0001", "\\u0002", "\\u0003", // 0x00 + "\\u0004", "\\u0005", "\\u0006", "\\u0007", "\\b", "\\t", "\\n", "\\u000b", "\\f", "\\r", + "\\u000e", "\\u000f", "\\u0010", "\\u0011", "\\u0012", "\\u0013", // 0x10 + "\\u0014", "\\u0015", "\\u0016", "\\u0017", "\\u0018", "\\u0019", "\\u001a", "\\u001b", + "\\u001c", "\\u001d", "\\u001e", "\\u001f", + // Escaping of " and \ are required by www.json.org string definition. + // Escaping of < and > are required for HTML security. + "", "", "\\\"", "", "", "", "", "", // 0x20 + "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", // 0x30 + "", "", "", "", "\\u003c", "", "\\u003e", "", "", "", "", "", "", "", "", "", // 0x40 + "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", // 0x50 + "", "", "", "", "\\\\", "", "", "", "", "", "", "", "", "", "", "", // 0x60 + "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", // 0x70 + "", "", "", "", "", "", "", "\\u007f", + // C1 (ISO 8859 and Unicode) extended control characters + "\\u0080", "\\u0081", "\\u0082", "\\u0083", // 0x80 + "\\u0084", "\\u0085", "\\u0086", "\\u0087", "\\u0088", "\\u0089", "\\u008a", "\\u008b", + "\\u008c", "\\u008d", "\\u008e", "\\u008f", "\\u0090", "\\u0091", "\\u0092", + "\\u0093", // 0x90 + "\\u0094", "\\u0095", "\\u0096", "\\u0097", "\\u0098", "\\u0099", "\\u009a", "\\u009b", + "\\u009c", "\\u009d", "\\u009e", "\\u009f" + }; + + static JsonFormatter() { + for (int i = 0; i < CommonRepresentations.Length; i++) { + if (CommonRepresentations[i] == "") { + CommonRepresentations[i] = ((char)i).ToString(); } + } + } - private readonly Settings settings; + private readonly Settings settings; - private bool DiagnosticOnly => ReferenceEquals(this, diagnosticFormatter); + private bool DiagnosticOnly => ReferenceEquals(this, diagnosticFormatter); - /// - /// Creates a new formatted with the given settings. - /// - /// The settings. - public JsonFormatter(Settings settings) - { - this.settings = ProtoPreconditions.CheckNotNull(settings, nameof(settings)); - } + /// + /// Creates a new formatted with the given settings. + /// + /// The settings. + public JsonFormatter(Settings settings) { + this.settings = ProtoPreconditions.CheckNotNull(settings, nameof(settings)); + } - /// - /// Formats the specified message as JSON. - /// - /// The message to format. - /// This method delegates to Format(IMessage, int) with indentationLevel = 0. - /// The formatted message. - public string Format(IMessage message) => Format(message, indentationLevel: 0); - - /// - /// Formats the specified message as JSON. - /// - /// The message to format. - /// Indentation level to start at. - /// To keep consistent indentation when embedding a message inside another JSON string, set . E.g: - /// - /// var response = $@"{{ - /// ""data"": { Format(message, indentationLevel: 1) } - /// }}" - /// - /// The formatted message. - public string Format(IMessage message, int indentationLevel) - { - var writer = new StringWriter(); - Format(message, writer, indentationLevel); - return writer.ToString(); - } + /// + /// Formats the specified message as JSON. + /// + /// The message to format. + /// This method delegates to Format(IMessage, int) with indentationLevel = + /// 0. The formatted message. + public string Format(IMessage message) => Format(message, indentationLevel: 0); - /// - /// Formats the specified message as JSON. - /// - /// The message to format. - /// The TextWriter to write the formatted message to. - /// This method delegates to Format(IMessage, TextWriter, int) with indentationLevel = 0. - /// The formatted message. - public void Format(IMessage message, TextWriter writer) => Format(message, writer, indentationLevel: 0); - - /// - /// Formats the specified message as JSON. When is not null, start indenting at the specified . - /// - /// The message to format. - /// The TextWriter to write the formatted message to. - /// Indentation level to start at. - /// To keep consistent indentation when embedding a message inside another JSON string, set . - public void Format(IMessage message, TextWriter writer, int indentationLevel) - { - ProtoPreconditions.CheckNotNull(message, nameof(message)); - ProtoPreconditions.CheckNotNull(writer, nameof(writer)); - - if (message.Descriptor.IsWellKnownType) - { - WriteWellKnownTypeValue(writer, message.Descriptor, message, indentationLevel); - } - else - { - WriteMessage(writer, message, indentationLevel); - } - } + /// + /// Formats the specified message as JSON. + /// + /// The message to format. + /// Indentation level to start at. + /// To keep consistent indentation when embedding a message inside another JSON string, + /// set . E.g: var response = $@"{{ + /// ""data"": { Format(message, indentationLevel: 1) } + /// }}" + /// + /// The formatted message. + public string Format(IMessage message, int indentationLevel) { + var writer = new StringWriter(); + Format(message, writer, indentationLevel); + return writer.ToString(); + } - /// - /// Converts a message to JSON for diagnostic purposes with no extra context. - /// - /// - /// - /// This differs from calling on the default JSON - /// formatter in its handling of . As no type registry is available - /// in calls, the normal way of resolving the type of - /// an Any message cannot be applied. Instead, a JSON property named @value - /// is included with the base64 data from the property of the message. - /// - /// The value returned by this method is only designed to be used for diagnostic - /// purposes. It may not be parsable by , and may not be parsable - /// by other Protocol Buffer implementations. - /// - /// The message to format for diagnostic purposes. - /// The diagnostic-only JSON representation of the message - public static string ToDiagnosticString(IMessage message) - { - ProtoPreconditions.CheckNotNull(message, nameof(message)); - return diagnosticFormatter.Format(message); - } + /// + /// Formats the specified message as JSON. + /// + /// The message to format. + /// The TextWriter to write the formatted message to. + /// This method delegates to Format(IMessage, TextWriter, int) with + /// indentationLevel = 0. The formatted message. + public void Format(IMessage message, TextWriter writer) => Format(message, writer, + indentationLevel: 0); - private void WriteMessage(TextWriter writer, IMessage message, int indentationLevel) - { - if (message == null) - { - WriteNull(writer); - return; - } - if (DiagnosticOnly) - { - if (message is ICustomDiagnosticMessage customDiagnosticMessage) - { - writer.Write(customDiagnosticMessage.ToDiagnosticString()); - return; - } - } + /// + /// Formats the specified message as JSON. When is not null, + /// start indenting at the specified . + /// + /// The message to format. + /// The TextWriter to write the formatted message to. + /// Indentation level to start at. + /// To keep consistent indentation when embedding a message inside another JSON string, + /// set . + public void Format(IMessage message, TextWriter writer, int indentationLevel) { + ProtoPreconditions.CheckNotNull(message, nameof(message)); + ProtoPreconditions.CheckNotNull(writer, nameof(writer)); + + if (message.Descriptor.IsWellKnownType) { + WriteWellKnownTypeValue(writer, message.Descriptor, message, indentationLevel); + } else { + WriteMessage(writer, message, indentationLevel); + } + } + + /// + /// Converts a message to JSON for diagnostic purposes with no extra context. + /// + /// + /// + /// This differs from calling on the default JSON + /// formatter in its handling of . As no type registry is available + /// in calls, the normal way of resolving the type of + /// an Any message cannot be applied. Instead, a JSON property named @value + /// is included with the base64 data from the property of the message. + /// + /// The value returned by this method is only designed to be used for diagnostic + /// purposes. It may not be parsable by , and may not be parsable + /// by other Protocol Buffer implementations. + /// + /// The message to format for diagnostic purposes. + /// The diagnostic-only JSON representation of the message + public static string ToDiagnosticString(IMessage message) { + ProtoPreconditions.CheckNotNull(message, nameof(message)); + return diagnosticFormatter.Format(message); + } - WriteBracketOpen(writer, ObjectOpenBracket); - bool writtenFields = WriteMessageFields(writer, message, false, indentationLevel + 1); - WriteBracketClose(writer, ObjectCloseBracket, writtenFields, indentationLevel); + private void WriteMessage(TextWriter writer, IMessage message, int indentationLevel) { + if (message == null) { + WriteNull(writer); + return; + } + if (DiagnosticOnly) { + if (message is ICustomDiagnosticMessage customDiagnosticMessage) { + writer.Write(customDiagnosticMessage.ToDiagnosticString()); + return; } + } - private bool WriteMessageFields(TextWriter writer, IMessage message, bool assumeFirstFieldWritten, int indentationLevel) - { - var fields = message.Descriptor.Fields; - bool first = !assumeFirstFieldWritten; - // First non-oneof fields - foreach (var field in fields.InFieldNumberOrder()) - { - var accessor = field.Accessor; - var value = accessor.GetValue(message); - if (!ShouldFormatFieldValue(message, field, value)) - { - continue; - } - - MaybeWriteValueSeparator(writer, first); - MaybeWriteValueWhitespace(writer, indentationLevel); - - if (settings.PreserveProtoFieldNames) - { - WriteString(writer, accessor.Descriptor.Name); - } - else - { - WriteString(writer, accessor.Descriptor.JsonName); - } - writer.Write(NameValueSeparator); - WriteValue(writer, value, indentationLevel); - - first = false; - } - return !first; + WriteBracketOpen(writer, ObjectOpenBracket); + bool writtenFields = WriteMessageFields(writer, message, false, indentationLevel + 1); + WriteBracketClose(writer, ObjectCloseBracket, writtenFields, indentationLevel); + } + + private bool WriteMessageFields(TextWriter writer, IMessage message, + bool assumeFirstFieldWritten, int indentationLevel) { + var fields = message.Descriptor.Fields; + bool first = !assumeFirstFieldWritten; + // First non-oneof fields + foreach (var field in fields.InFieldNumberOrder()) { + var accessor = field.Accessor; + var value = accessor.GetValue(message); + if (!ShouldFormatFieldValue(message, field, value)) { + continue; } - private void MaybeWriteValueSeparator(TextWriter writer, bool first) - { - if (first) - { - return; - } + MaybeWriteValueSeparator(writer, first); + MaybeWriteValueWhitespace(writer, indentationLevel); - writer.Write(settings.Indentation == null ? ValueSeparator : MultilineValueSeparator); + if (settings.PreserveProtoFieldNames) { + WriteString(writer, accessor.Descriptor.Name); + } else { + WriteString(writer, accessor.Descriptor.JsonName); } + writer.Write(NameValueSeparator); + WriteValue(writer, value, indentationLevel); - /// - /// Determines whether or not a field value should be serialized according to the field, - /// its value in the message, and the settings of this formatter. - /// - private bool ShouldFormatFieldValue(IMessage message, FieldDescriptor field, object value) => - field.HasPresence + first = false; + } + return !first; + } + + private void MaybeWriteValueSeparator(TextWriter writer, bool first) { + if (first) { + return; + } + + writer.Write(settings.Indentation == null ? ValueSeparator : MultilineValueSeparator); + } + + /// + /// Determines whether or not a field value should be serialized according to the field, + /// its value in the message, and the settings of this formatter. + /// + private bool ShouldFormatFieldValue(IMessage message, FieldDescriptor field, object value) => + field.HasPresence // Fields that support presence *just* use that ? field.Accessor.HasValue(message) // Otherwise, format if either we've been asked to format default values, or if it's // not a default value anyway. : settings.FormatDefaultValues || !IsDefaultValue(field, value); - // Converted from java/core/src/main/java/com/google/protobuf/Descriptors.java - internal static string ToJsonName(string name) - { - StringBuilder result = new StringBuilder(name.Length); - bool isNextUpperCase = false; - foreach (char ch in name) - { - if (ch == '_') - { - isNextUpperCase = true; - } - else if (isNextUpperCase) - { - result.Append(char.ToUpperInvariant(ch)); - isNextUpperCase = false; - } - else - { - result.Append(ch); - } - } - return result.ToString(); - } - - internal static string FromJsonName(string name) - { - StringBuilder result = new StringBuilder(name.Length); - foreach (char ch in name) - { - if (char.IsUpper(ch)) - { - result.Append('_'); - result.Append(char.ToLowerInvariant(ch)); - } - else - { - result.Append(ch); - } - } - return result.ToString(); + // Converted from java/core/src/main/java/com/google/protobuf/Descriptors.java + internal static string ToJsonName(string name) { + StringBuilder result = new StringBuilder(name.Length); + bool isNextUpperCase = false; + foreach (char ch in name) { + if (ch == '_') { + isNextUpperCase = true; + } else if (isNextUpperCase) { + result.Append(char.ToUpperInvariant(ch)); + isNextUpperCase = false; + } else { + result.Append(ch); } + } + return result.ToString(); + } - private static void WriteNull(TextWriter writer) - { - writer.Write("null"); + internal static string FromJsonName(string name) { + StringBuilder result = new StringBuilder(name.Length); + foreach (char ch in name) { + if (char.IsUpper(ch)) { + result.Append('_'); + result.Append(char.ToLowerInvariant(ch)); + } else { + result.Append(ch); } + } + return result.ToString(); + } - private static bool IsDefaultValue(FieldDescriptor descriptor, object value) - { - if (descriptor.IsMap) - { - IDictionary dictionary = (IDictionary) value; - return dictionary.Count == 0; - } - if (descriptor.IsRepeated) - { - IList list = (IList) value; - return list.Count == 0; - } - return descriptor.FieldType switch - { - FieldType.Bool => (bool) value == false, - FieldType.Bytes => (ByteString) value == ByteString.Empty, - FieldType.String => (string) value == "", - FieldType.Double => (double) value == 0.0, - FieldType.SInt32 or FieldType.Int32 or FieldType.SFixed32 or FieldType.Enum => (int) value == 0, - FieldType.Fixed32 or FieldType.UInt32 => (uint) value == 0, - FieldType.Fixed64 or FieldType.UInt64 => (ulong) value == 0, - FieldType.SFixed64 or FieldType.Int64 or FieldType.SInt64 => (long) value == 0, - FieldType.Float => (float) value == 0f, - FieldType.Message or FieldType.Group => value == null, - _ => throw new ArgumentException("Invalid field type"), - }; - } + private static void WriteNull(TextWriter writer) { + writer.Write("null"); + } - /// - /// Writes a single value to the given writer as JSON. Only types understood by - /// Protocol Buffers can be written in this way. This method is only exposed for - /// advanced use cases; most users should be using - /// or . - /// - /// The writer to write the value to. Must not be null. - /// The value to write. May be null. - /// Delegates to WriteValue(TextWriter, object, int) with indentationLevel = 0. - public void WriteValue(TextWriter writer, object value) => WriteValue(writer, value, 0); - - /// - /// Writes a single value to the given writer as JSON. Only types understood by - /// Protocol Buffers can be written in this way. This method is only exposed for - /// advanced use cases; most users should be using - /// or . - /// - /// The writer to write the value to. Must not be null. - /// The value to write. May be null. - /// The current indentationLevel. Not used when is null. - public void WriteValue(TextWriter writer, object value, int indentationLevel) - { - if (value == null || value is NullValue) - { - WriteNull(writer); - } - else if (value is bool b) - { - writer.Write(b ? "true" : "false"); - } - else if (value is ByteString byteString) - { - // Nothing in Base64 needs escaping - writer.Write('"'); - writer.Write(byteString.ToBase64()); - writer.Write('"'); - } - else if (value is string str) - { - WriteString(writer, str); - } - else if (value is IDictionary dictionary) - { - WriteDictionary(writer, dictionary, indentationLevel); - } - else if (value is IList list) - { - WriteList(writer, list, indentationLevel); - } - else if (value is int || value is uint) - { - IFormattable formattable = (IFormattable) value; - writer.Write(formattable.ToString("d", CultureInfo.InvariantCulture)); - } - else if (value is long || value is ulong) - { - writer.Write('"'); - IFormattable formattable = (IFormattable) value; - writer.Write(formattable.ToString("d", CultureInfo.InvariantCulture)); - writer.Write('"'); - } - else if (value is System.Enum) - { - if (settings.FormatEnumsAsIntegers) - { - WriteValue(writer, (int)value); - } - else - { - string name = OriginalEnumValueHelper.GetOriginalName(value); - if (name != null) - { - WriteString(writer, name); - } - else - { - WriteValue(writer, (int)value); - } - } - } - else if (value is float || value is double) - { - string text = ((IFormattable) value).ToString("r", CultureInfo.InvariantCulture); - if (text == "NaN" || text == "Infinity" || text == "-Infinity") - { - writer.Write('"'); - writer.Write(text); - writer.Write('"'); - } - else - { - writer.Write(text); - } - } - else if (value is IMessage message) - { - Format(message, writer, indentationLevel); - } - else - { - throw new ArgumentException("Unable to format value of type " + value.GetType()); - } - } + private static bool IsDefaultValue(FieldDescriptor descriptor, object value) { + if (descriptor.IsMap) { + IDictionary dictionary = (IDictionary)value; + return dictionary.Count == 0; + } + if (descriptor.IsRepeated) { + IList list = (IList)value; + return list.Count == 0; + } + return descriptor.FieldType switch { + FieldType.Bool => (bool)value == false, + FieldType.Bytes => (ByteString)value == ByteString.Empty, + FieldType.String => (string)value == "", + FieldType.Double => (double)value == 0.0, + FieldType.SInt32 or FieldType.Int32 or FieldType.SFixed32 or FieldType.Enum => + (int)value == 0, + FieldType.Fixed32 or FieldType.UInt32 => (uint)value == 0, + FieldType.Fixed64 or FieldType.UInt64 => (ulong)value == 0, + FieldType.SFixed64 or FieldType.Int64 or FieldType.SInt64 => (long)value == 0, + FieldType.Float => (float)value == 0f, + FieldType.Message or FieldType.Group => value == null, + _ => throw new ArgumentException("Invalid field type"), + }; + } - /// - /// Central interception point for well-known type formatting. Any well-known types which - /// don't need special handling can fall back to WriteMessage. We avoid assuming that the - /// values are using the embedded well-known types, in order to allow for dynamic messages - /// in the future. - /// - private void WriteWellKnownTypeValue(TextWriter writer, MessageDescriptor descriptor, object value, int indentationLevel) - { - // Currently, we can never actually get here, because null values are always handled by the caller. But if we *could*, - // this would do the right thing. - if (value == null) - { - WriteNull(writer); - return; - } - // For wrapper types, the value will either be the (possibly boxed) "native" value, - // or the message itself if we're formatting it at the top level (e.g. just calling ToString on the object itself). - // If it's the message form, we can extract the value first, which *will* be the (possibly boxed) native value, - // and then proceed, writing it as if we were definitely in a field. (We never need to wrap it in an extra string... - // WriteValue will do the right thing.) - if (descriptor.IsWrapperType) - { - if (value is IMessage message) - { - value = message.Descriptor.Fields[WrappersReflection.WrapperValueFieldNumber].Accessor.GetValue(message); - } - WriteValue(writer, value); - return; - } - if (descriptor.FullName == Timestamp.Descriptor.FullName) - { - WriteTimestamp(writer, (IMessage)value); - return; - } - if (descriptor.FullName == Duration.Descriptor.FullName) - { - WriteDuration(writer, (IMessage)value); - return; - } - if (descriptor.FullName == FieldMask.Descriptor.FullName) - { - WriteFieldMask(writer, (IMessage)value); - return; - } - if (descriptor.FullName == Struct.Descriptor.FullName) - { - WriteStruct(writer, (IMessage)value, indentationLevel); - return; - } - if (descriptor.FullName == ListValue.Descriptor.FullName) - { - var fieldAccessor = descriptor.Fields[ListValue.ValuesFieldNumber].Accessor; - WriteList(writer, (IList)fieldAccessor.GetValue((IMessage)value), indentationLevel); - return; - } - if (descriptor.FullName == Value.Descriptor.FullName) - { - WriteStructFieldValue(writer, (IMessage)value, indentationLevel); - return; - } - if (descriptor.FullName == Any.Descriptor.FullName) - { - WriteAny(writer, (IMessage)value, indentationLevel); - return; - } - WriteMessage(writer, (IMessage)value, indentationLevel); - } + /// + /// Writes a single value to the given writer as JSON. Only types understood by + /// Protocol Buffers can be written in this way. This method is only exposed for + /// advanced use cases; most users should be using + /// or . + /// + /// The writer to write the value to. Must not be null. + /// The value to write. May be null. + /// Delegates to WriteValue(TextWriter, object, int) with indentationLevel = + /// 0. + public void WriteValue(TextWriter writer, object value) => WriteValue(writer, value, 0); - private void WriteTimestamp(TextWriter writer, IMessage value) - { - // TODO: In the common case where this *is* using the built-in Timestamp type, we could - // avoid all the reflection at this point, by casting to Timestamp. In the interests of - // avoiding subtle bugs, don't do that until we've implemented DynamicMessage so that we can prove - // it still works in that case. - int nanos = (int) value.Descriptor.Fields[Timestamp.NanosFieldNumber].Accessor.GetValue(value); - long seconds = (long) value.Descriptor.Fields[Timestamp.SecondsFieldNumber].Accessor.GetValue(value); - writer.Write(Timestamp.ToJson(seconds, nanos, DiagnosticOnly)); + /// + /// Writes a single value to the given writer as JSON. Only types understood by + /// Protocol Buffers can be written in this way. This method is only exposed for + /// advanced use cases; most users should be using + /// or . + /// + /// The writer to write the value to. Must not be null. + /// The value to write. May be null. + /// The current indentationLevel. Not used when is null. + public void WriteValue(TextWriter writer, object value, int indentationLevel) { + if (value == null || value is NullValue) { + WriteNull(writer); + } else if (value is bool b) { + writer.Write(b ? "true" : "false"); + } else if (value is ByteString byteString) { + // Nothing in Base64 needs escaping + writer.Write('"'); + writer.Write(byteString.ToBase64()); + writer.Write('"'); + } else if (value is string str) { + WriteString(writer, str); + } else if (value is IDictionary dictionary) { + WriteDictionary(writer, dictionary, indentationLevel); + } else if (value is IList list) { + WriteList(writer, list, indentationLevel); + } else if (value is int || value is uint) { + IFormattable formattable = (IFormattable)value; + writer.Write(formattable.ToString("d", CultureInfo.InvariantCulture)); + } else if (value is long || value is ulong) { + writer.Write('"'); + IFormattable formattable = (IFormattable)value; + writer.Write(formattable.ToString("d", CultureInfo.InvariantCulture)); + writer.Write('"'); + } else if (value is System.Enum) { + if (settings.FormatEnumsAsIntegers) { + WriteValue(writer, (int)value); + } else { + string name = OriginalEnumValueHelper.GetOriginalName(value); + if (name != null) { + WriteString(writer, name); + } else { + WriteValue(writer, (int)value); + } } - - private void WriteDuration(TextWriter writer, IMessage value) - { - // TODO: Same as for WriteTimestamp - int nanos = (int) value.Descriptor.Fields[Duration.NanosFieldNumber].Accessor.GetValue(value); - long seconds = (long) value.Descriptor.Fields[Duration.SecondsFieldNumber].Accessor.GetValue(value); - writer.Write(Duration.ToJson(seconds, nanos, DiagnosticOnly)); + } else if (value is float || value is double) { + string text = ((IFormattable)value).ToString("r", CultureInfo.InvariantCulture); + if (text == "NaN" || text == "Infinity" || text == "-Infinity") { + writer.Write('"'); + writer.Write(text); + writer.Write('"'); + } else { + writer.Write(text); } + } else if (value is IMessage message) { + Format(message, writer, indentationLevel); + } else { + throw new ArgumentException("Unable to format value of type " + value.GetType()); + } + } - private void WriteFieldMask(TextWriter writer, IMessage value) - { - var paths = (IList) value.Descriptor.Fields[FieldMask.PathsFieldNumber].Accessor.GetValue(value); - writer.Write(FieldMask.ToJson(paths, DiagnosticOnly)); + /// + /// Central interception point for well-known type formatting. Any well-known types which + /// don't need special handling can fall back to WriteMessage. We avoid assuming that the + /// values are using the embedded well-known types, in order to allow for dynamic messages + /// in the future. + /// + private void WriteWellKnownTypeValue(TextWriter writer, MessageDescriptor descriptor, + object value, int indentationLevel) { + // Currently, we can never actually get here, because null values are always handled by the + // caller. But if we *could*, this would do the right thing. + if (value == null) { + WriteNull(writer); + return; + } + // For wrapper types, the value will either be the (possibly boxed) "native" value, + // or the message itself if we're formatting it at the top level (e.g. just calling ToString + // on the object itself). If it's the message form, we can extract the value first, which + // *will* be the (possibly boxed) native value, and then proceed, writing it as if we were + // definitely in a field. (We never need to wrap it in an extra string... WriteValue will do + // the right thing.) + if (descriptor.IsWrapperType) { + if (value is IMessage message) { + value = message.Descriptor.Fields[WrappersReflection.WrapperValueFieldNumber] + .Accessor.GetValue(message); } + WriteValue(writer, value); + return; + } + if (descriptor.FullName == Timestamp.Descriptor.FullName) { + WriteTimestamp(writer, (IMessage)value); + return; + } + if (descriptor.FullName == Duration.Descriptor.FullName) { + WriteDuration(writer, (IMessage)value); + return; + } + if (descriptor.FullName == FieldMask.Descriptor.FullName) { + WriteFieldMask(writer, (IMessage)value); + return; + } + if (descriptor.FullName == Struct.Descriptor.FullName) { + WriteStruct(writer, (IMessage)value, indentationLevel); + return; + } + if (descriptor.FullName == ListValue.Descriptor.FullName) { + var fieldAccessor = descriptor.Fields[ListValue.ValuesFieldNumber].Accessor; + WriteList(writer, (IList)fieldAccessor.GetValue((IMessage)value), indentationLevel); + return; + } + if (descriptor.FullName == Value.Descriptor.FullName) { + WriteStructFieldValue(writer, (IMessage)value, indentationLevel); + return; + } + if (descriptor.FullName == Any.Descriptor.FullName) { + WriteAny(writer, (IMessage)value, indentationLevel); + return; + } + WriteMessage(writer, (IMessage)value, indentationLevel); + } - private void WriteAny(TextWriter writer, IMessage value, int indentationLevel) - { - if (DiagnosticOnly) - { - WriteDiagnosticOnlyAny(writer, value); - return; - } + private void WriteTimestamp(TextWriter writer, IMessage value) { + // TODO: In the common case where this *is* using the built-in Timestamp type, we could + // avoid all the reflection at this point, by casting to Timestamp. In the interests of + // avoiding subtle bugs, don't do that until we've implemented DynamicMessage so that we can + // prove it still works in that case. + int nanos = (int)value.Descriptor.Fields[Timestamp.NanosFieldNumber].Accessor.GetValue(value); + long seconds = + (long)value.Descriptor.Fields[Timestamp.SecondsFieldNumber].Accessor.GetValue(value); + writer.Write(Timestamp.ToJson(seconds, nanos, DiagnosticOnly)); + } - string typeUrl = (string) value.Descriptor.Fields[Any.TypeUrlFieldNumber].Accessor.GetValue(value); - ByteString data = (ByteString) value.Descriptor.Fields[Any.ValueFieldNumber].Accessor.GetValue(value); - string typeName = Any.GetTypeName(typeUrl); - MessageDescriptor descriptor = settings.TypeRegistry.Find(typeName); - if (descriptor == null) - { - throw new InvalidOperationException($"Type registry has no descriptor for type name '{typeName}'"); - } - IMessage message = descriptor.Parser.ParseFrom(data); - WriteBracketOpen(writer, ObjectOpenBracket); - WriteString(writer, AnyTypeUrlField); - writer.Write(NameValueSeparator); - WriteString(writer, typeUrl); - - if (descriptor.IsWellKnownType) - { - writer.Write(ValueSeparator); - WriteString(writer, AnyWellKnownTypeValueField); - writer.Write(NameValueSeparator); - WriteWellKnownTypeValue(writer, descriptor, message, indentationLevel); - } - else - { - WriteMessageFields(writer, message, true, indentationLevel); - } - WriteBracketClose(writer, ObjectCloseBracket, true, indentationLevel); - } + private void WriteDuration(TextWriter writer, IMessage value) { + // TODO: Same as for WriteTimestamp + int nanos = (int)value.Descriptor.Fields[Duration.NanosFieldNumber].Accessor.GetValue(value); + long seconds = + (long)value.Descriptor.Fields[Duration.SecondsFieldNumber].Accessor.GetValue(value); + writer.Write(Duration.ToJson(seconds, nanos, DiagnosticOnly)); + } - private void WriteDiagnosticOnlyAny(TextWriter writer, IMessage value) - { - string typeUrl = (string) value.Descriptor.Fields[Any.TypeUrlFieldNumber].Accessor.GetValue(value); - ByteString data = (ByteString) value.Descriptor.Fields[Any.ValueFieldNumber].Accessor.GetValue(value); - writer.Write("{ "); - WriteString(writer, AnyTypeUrlField); - writer.Write(NameValueSeparator); - WriteString(writer, typeUrl); - writer.Write(ValueSeparator); - WriteString(writer, AnyDiagnosticValueField); - writer.Write(NameValueSeparator); - writer.Write('"'); - writer.Write(data.ToBase64()); - writer.Write('"'); - writer.Write(" }"); - } + private void WriteFieldMask(TextWriter writer, IMessage value) { + var paths = + (IList)value.Descriptor.Fields[FieldMask.PathsFieldNumber].Accessor.GetValue( + value); + writer.Write(FieldMask.ToJson(paths, DiagnosticOnly)); + } - private void WriteStruct(TextWriter writer, IMessage message, int indentationLevel) - { - WriteBracketOpen(writer, ObjectOpenBracket); - IDictionary fields = (IDictionary) message.Descriptor.Fields[Struct.FieldsFieldNumber].Accessor.GetValue(message); - bool first = true; - foreach (DictionaryEntry entry in fields) - { - string key = (string) entry.Key; - IMessage value = (IMessage) entry.Value; - if (string.IsNullOrEmpty(key) || value == null) - { - throw new InvalidOperationException("Struct fields cannot have an empty key or a null value."); - } - - MaybeWriteValueSeparator(writer, first); - MaybeWriteValueWhitespace(writer, indentationLevel + 1); - WriteString(writer, key); - writer.Write(NameValueSeparator); - WriteStructFieldValue(writer, value, indentationLevel + 1); - first = false; - } - WriteBracketClose(writer, ObjectCloseBracket, !first, indentationLevel); - } + private void WriteAny(TextWriter writer, IMessage value, int indentationLevel) { + if (DiagnosticOnly) { + WriteDiagnosticOnlyAny(writer, value); + return; + } + + string typeUrl = + (string)value.Descriptor.Fields[Any.TypeUrlFieldNumber].Accessor.GetValue(value); + ByteString data = + (ByteString)value.Descriptor.Fields[Any.ValueFieldNumber].Accessor.GetValue(value); + string typeName = Any.GetTypeName(typeUrl); + MessageDescriptor descriptor = settings.TypeRegistry.Find(typeName); + if (descriptor == null) { + throw new InvalidOperationException( + $"Type registry has no descriptor for type name '{typeName}'"); + } + IMessage message = descriptor.Parser.ParseFrom(data); + WriteBracketOpen(writer, ObjectOpenBracket); + WriteString(writer, AnyTypeUrlField); + writer.Write(NameValueSeparator); + WriteString(writer, typeUrl); + + if (descriptor.IsWellKnownType) { + writer.Write(ValueSeparator); + WriteString(writer, AnyWellKnownTypeValueField); + writer.Write(NameValueSeparator); + WriteWellKnownTypeValue(writer, descriptor, message, indentationLevel); + } else { + WriteMessageFields(writer, message, true, indentationLevel); + } + WriteBracketClose(writer, ObjectCloseBracket, true, indentationLevel); + } - private void WriteStructFieldValue(TextWriter writer, IMessage message, int indentationLevel) - { - var specifiedField = message.Descriptor.Oneofs[0].Accessor.GetCaseFieldDescriptor(message); - if (specifiedField == null) - { - throw new InvalidOperationException("Value message must contain a value for the oneof."); - } + private void WriteDiagnosticOnlyAny(TextWriter writer, IMessage value) { + string typeUrl = + (string)value.Descriptor.Fields[Any.TypeUrlFieldNumber].Accessor.GetValue(value); + ByteString data = + (ByteString)value.Descriptor.Fields[Any.ValueFieldNumber].Accessor.GetValue(value); + writer.Write("{ "); + WriteString(writer, AnyTypeUrlField); + writer.Write(NameValueSeparator); + WriteString(writer, typeUrl); + writer.Write(ValueSeparator); + WriteString(writer, AnyDiagnosticValueField); + writer.Write(NameValueSeparator); + writer.Write('"'); + writer.Write(data.ToBase64()); + writer.Write('"'); + writer.Write(" }"); + } - object value = specifiedField.Accessor.GetValue(message); - - switch (specifiedField.FieldNumber) - { - case Value.BoolValueFieldNumber: - case Value.StringValueFieldNumber: - case Value.NumberValueFieldNumber: - WriteValue(writer, value); - return; - case Value.StructValueFieldNumber: - case Value.ListValueFieldNumber: - // Structs and ListValues are nested messages, and already well-known types. - var nestedMessage = (IMessage) specifiedField.Accessor.GetValue(message); - WriteWellKnownTypeValue(writer, nestedMessage.Descriptor, nestedMessage, indentationLevel); - return; - case Value.NullValueFieldNumber: - WriteNull(writer); - return; - default: - throw new InvalidOperationException("Unexpected case in struct field: " + specifiedField.FieldNumber); - } + private void WriteStruct(TextWriter writer, IMessage message, int indentationLevel) { + WriteBracketOpen(writer, ObjectOpenBracket); + IDictionary fields = + (IDictionary)message.Descriptor.Fields[Struct.FieldsFieldNumber].Accessor.GetValue( + message); + bool first = true; + foreach (DictionaryEntry entry in fields) { + string key = (string)entry.Key; + IMessage value = (IMessage)entry.Value; + if (string.IsNullOrEmpty(key) || value == null) { + throw new InvalidOperationException( + "Struct fields cannot have an empty key or a null value."); } - internal void WriteList(TextWriter writer, IList list, int indentationLevel = 0) - { - WriteBracketOpen(writer, ListBracketOpen); - - bool first = true; - foreach (var value in list) - { - MaybeWriteValueSeparator(writer, first); - MaybeWriteValueWhitespace(writer, indentationLevel + 1); - WriteValue(writer, value, indentationLevel + 1); - first = false; - } + MaybeWriteValueSeparator(writer, first); + MaybeWriteValueWhitespace(writer, indentationLevel + 1); + WriteString(writer, key); + writer.Write(NameValueSeparator); + WriteStructFieldValue(writer, value, indentationLevel + 1); + first = false; + } + WriteBracketClose(writer, ObjectCloseBracket, !first, indentationLevel); + } - WriteBracketClose(writer, ListBracketClose, !first, indentationLevel); - } + private void WriteStructFieldValue(TextWriter writer, IMessage message, int indentationLevel) { + var specifiedField = message.Descriptor.Oneofs[0].Accessor.GetCaseFieldDescriptor(message); + if (specifiedField == null) { + throw new InvalidOperationException("Value message must contain a value for the oneof."); + } + + object value = specifiedField.Accessor.GetValue(message); + + switch (specifiedField.FieldNumber) { + case Value.BoolValueFieldNumber: + case Value.StringValueFieldNumber: + case Value.NumberValueFieldNumber: + WriteValue(writer, value); + return; + case Value.StructValueFieldNumber: + case Value.ListValueFieldNumber: + // Structs and ListValues are nested messages, and already well-known types. + var nestedMessage = (IMessage)specifiedField.Accessor.GetValue(message); + WriteWellKnownTypeValue(writer, nestedMessage.Descriptor, nestedMessage, + indentationLevel); + return; + case Value.NullValueFieldNumber: + WriteNull(writer); + return; + default: + throw new InvalidOperationException("Unexpected case in struct field: " + + specifiedField.FieldNumber); + } + } - internal void WriteDictionary(TextWriter writer, IDictionary dictionary, int indentationLevel = 0) - { - WriteBracketOpen(writer, ObjectOpenBracket); - - bool first = true; - // This will box each pair. Could use IDictionaryEnumerator, but that's ugly in terms of disposal. - foreach (DictionaryEntry pair in dictionary) - { - string keyText; - if (pair.Key is string s) - { - keyText = s; - } - else if (pair.Key is bool b) - { - keyText = b ? "true" : "false"; - } - else if (pair.Key is int || pair.Key is uint || pair.Key is long || pair.Key is ulong) - { - keyText = ((IFormattable) pair.Key).ToString("d", CultureInfo.InvariantCulture); - } - else - { - if (pair.Key == null) - { - throw new ArgumentException("Dictionary has entry with null key"); - } - throw new ArgumentException("Unhandled dictionary key type: " + pair.Key.GetType()); - } - - MaybeWriteValueSeparator(writer, first); - MaybeWriteValueWhitespace(writer, indentationLevel + 1); - WriteString(writer, keyText); - writer.Write(NameValueSeparator); - WriteValue(writer, pair.Value); - first = false; - } + internal void WriteList(TextWriter writer, IList list, int indentationLevel = 0) { + WriteBracketOpen(writer, ListBracketOpen); - WriteBracketClose(writer, ObjectCloseBracket, !first, indentationLevel); - } + bool first = true; + foreach (var value in list) { + MaybeWriteValueSeparator(writer, first); + MaybeWriteValueWhitespace(writer, indentationLevel + 1); + WriteValue(writer, value, indentationLevel + 1); + first = false; + } - /// - /// Writes a string (including leading and trailing double quotes) to a builder, escaping as required. - /// - /// - /// Other than surrogate pair handling, this code is mostly taken from src/google/protobuf/util/internal/json_escaping.cc. - /// - internal static void WriteString(TextWriter writer, string text) - { - writer.Write('"'); - for (int i = 0; i < text.Length; i++) - { - char c = text[i]; - if (c < 0xa0) - { - writer.Write(CommonRepresentations[c]); - continue; - } - if (char.IsHighSurrogate(c)) - { - // Encountered first part of a surrogate pair. - // Check that we have the whole pair, and encode both parts as hex. - i++; - if (i == text.Length || !char.IsLowSurrogate(text[i])) - { - throw new ArgumentException("String contains low surrogate not followed by high surrogate"); - } - HexEncodeUtf16CodeUnit(writer, c); - HexEncodeUtf16CodeUnit(writer, text[i]); - continue; - } - else if (char.IsLowSurrogate(c)) - { - throw new ArgumentException("String contains high surrogate not preceded by low surrogate"); - } - switch ((uint) c) - { - // These are not required by json spec - // but used to prevent security bugs in javascript. - case 0xfeff: // Zero width no-break space - case 0xfff9: // Interlinear annotation anchor - case 0xfffa: // Interlinear annotation separator - case 0xfffb: // Interlinear annotation terminator - - case 0x00ad: // Soft-hyphen - case 0x06dd: // Arabic end of ayah - case 0x070f: // Syriac abbreviation mark - case 0x17b4: // Khmer vowel inherent Aq - case 0x17b5: // Khmer vowel inherent Aa - HexEncodeUtf16CodeUnit(writer, c); - break; - - default: - if ((c >= 0x0600 && c <= 0x0603) || // Arabic signs - (c >= 0x200b && c <= 0x200f) || // Zero width etc. - (c >= 0x2028 && c <= 0x202e) || // Separators etc. - (c >= 0x2060 && c <= 0x2064) || // Invisible etc. - (c >= 0x206a && c <= 0x206f)) - { - HexEncodeUtf16CodeUnit(writer, c); - } - else - { - // No handling of surrogates here - that's done earlier - writer.Write(c); - } - break; - } - } - writer.Write('"'); - } + WriteBracketClose(writer, ListBracketClose, !first, indentationLevel); + } - private const string Hex = "0123456789abcdef"; - private static void HexEncodeUtf16CodeUnit(TextWriter writer, char c) - { - writer.Write("\\u"); - writer.Write(Hex[(c >> 12) & 0xf]); - writer.Write(Hex[(c >> 8) & 0xf]); - writer.Write(Hex[(c >> 4) & 0xf]); - writer.Write(Hex[(c >> 0) & 0xf]); + internal void WriteDictionary(TextWriter writer, IDictionary dictionary, + int indentationLevel = 0) { + WriteBracketOpen(writer, ObjectOpenBracket); + + bool first = true; + // This will box each pair. Could use IDictionaryEnumerator, but that's ugly in terms of + // disposal. + foreach (DictionaryEntry pair in dictionary) { + string keyText; + if (pair.Key is string s) { + keyText = s; + } else if (pair.Key is bool b) { + keyText = b ? "true" : "false"; + } else if (pair.Key is int || pair.Key is uint || pair.Key is long || pair.Key is ulong) { + keyText = ((IFormattable)pair.Key).ToString("d", CultureInfo.InvariantCulture); + } else { + if (pair.Key == null) { + throw new ArgumentException("Dictionary has entry with null key"); + } + throw new ArgumentException("Unhandled dictionary key type: " + pair.Key.GetType()); } - private void WriteBracketOpen(TextWriter writer, char openChar) - { - writer.Write(openChar); - if (settings.Indentation == null) - { - writer.Write(' '); - } - } + MaybeWriteValueSeparator(writer, first); + MaybeWriteValueWhitespace(writer, indentationLevel + 1); + WriteString(writer, keyText); + writer.Write(NameValueSeparator); + WriteValue(writer, pair.Value); + first = false; + } - private void WriteBracketClose(TextWriter writer, char closeChar, bool hasFields, int indentationLevel) - { - if (hasFields) - { - if (settings.Indentation != null) - { - writer.WriteLine(); - WriteIndentation(writer, indentationLevel); - } - else - { - writer.Write(" "); - } - } + WriteBracketClose(writer, ObjectCloseBracket, !first, indentationLevel); + } - writer.Write(closeChar); + /// + /// Writes a string (including leading and trailing double quotes) to a builder, escaping as + /// required. + /// + /// + /// Other than surrogate pair handling, this code is mostly taken from + /// src/google/protobuf/util/internal/json_escaping.cc. + /// + internal static void WriteString(TextWriter writer, string text) { + writer.Write('"'); + for (int i = 0; i < text.Length; i++) { + char c = text[i]; + if (c < 0xa0) { + writer.Write(CommonRepresentations[c]); + continue; } - - private void MaybeWriteValueWhitespace(TextWriter writer, int indentationLevel) - { - if (settings.Indentation != null) { - writer.WriteLine(); - WriteIndentation(writer, indentationLevel); - } + if (char.IsHighSurrogate(c)) { + // Encountered first part of a surrogate pair. + // Check that we have the whole pair, and encode both parts as hex. + i++; + if (i == text.Length || !char.IsLowSurrogate(text[i])) { + throw new ArgumentException( + "String contains low surrogate not followed by high surrogate"); + } + HexEncodeUtf16CodeUnit(writer, c); + HexEncodeUtf16CodeUnit(writer, text[i]); + continue; + } else if (char.IsLowSurrogate(c)) { + throw new ArgumentException( + "String contains high surrogate not preceded by low surrogate"); } - - private void WriteIndentation(TextWriter writer, int indentationLevel) - { - for (int i = 0; i < indentationLevel; i++) - { - writer.Write(settings.Indentation); - } + switch ((uint)c) { + // These are not required by json spec + // but used to prevent security bugs in javascript. + case 0xfeff: // Zero width no-break space + case 0xfff9: // Interlinear annotation anchor + case 0xfffa: // Interlinear annotation separator + case 0xfffb: // Interlinear annotation terminator + + case 0x00ad: // Soft-hyphen + case 0x06dd: // Arabic end of ayah + case 0x070f: // Syriac abbreviation mark + case 0x17b4: // Khmer vowel inherent Aq + case 0x17b5: // Khmer vowel inherent Aa + HexEncodeUtf16CodeUnit(writer, c); + break; + + default: + if ((c >= 0x0600 && c <= 0x0603) || // Arabic signs + (c >= 0x200b && c <= 0x200f) || // Zero width etc. + (c >= 0x2028 && c <= 0x202e) || // Separators etc. + (c >= 0x2060 && c <= 0x2064) || // Invisible etc. + (c >= 0x206a && c <= 0x206f)) { + HexEncodeUtf16CodeUnit(writer, c); + } else { + // No handling of surrogates here - that's done earlier + writer.Write(c); + } + break; } + } + writer.Write('"'); + } - /// - /// Settings controlling JSON formatting. - /// - public sealed class Settings - { - /// - /// Default settings, as used by - /// - public static Settings Default { get; } - - // Workaround for the Mono compiler complaining about XML comments not being on - // valid language elements. - static Settings() - { - Default = new Settings(false); - } + private const string Hex = "0123456789abcdef"; + private static void HexEncodeUtf16CodeUnit(TextWriter writer, char c) { + writer.Write("\\u"); + writer.Write(Hex[(c >> 12) & 0xf]); + writer.Write(Hex[(c >> 8) & 0xf]); + writer.Write(Hex[(c >> 4) & 0xf]); + writer.Write(Hex[(c >> 0) & 0xf]); + } - /// - /// Whether fields which would otherwise not be included in the formatted data - /// should be formatted even when the value is not present, or has the default value. - /// This option only affects fields which don't support "presence" (e.g. - /// singular non-optional proto3 primitive fields). - /// - public bool FormatDefaultValues { get; } - - /// - /// The type registry used to format messages. - /// - public TypeRegistry TypeRegistry { get; } - - /// - /// Whether to format enums as ints. Defaults to false. - /// - public bool FormatEnumsAsIntegers { get; } - - /// - /// Whether to use the original proto field names as defined in the .proto file. Defaults to false. - /// - public bool PreserveProtoFieldNames { get; } - - /// - /// Indentation string, used for formatting. Setting null disables indentation. - /// - public string Indentation { get; } - - /// - /// Creates a new object with the specified formatting of default values - /// and an empty type registry. - /// - /// true if default values (0, empty strings etc) should be formatted; false otherwise. - public Settings(bool formatDefaultValues) : this(formatDefaultValues, TypeRegistry.Empty) - { - } + private void WriteBracketOpen(TextWriter writer, char openChar) { + writer.Write(openChar); + if (settings.Indentation == null) { + writer.Write(' '); + } + } - /// - /// Creates a new object with the specified formatting of default values - /// and type registry. - /// - /// true if default values (0, empty strings etc) should be formatted; false otherwise. - /// The to use when formatting messages. - public Settings(bool formatDefaultValues, TypeRegistry typeRegistry) : this(formatDefaultValues, typeRegistry, false, false) - { - } + private void WriteBracketClose(TextWriter writer, char closeChar, bool hasFields, + int indentationLevel) { + if (hasFields) { + if (settings.Indentation != null) { + writer.WriteLine(); + WriteIndentation(writer, indentationLevel); + } else { + writer.Write(" "); + } + } - /// - /// Creates a new object with the specified parameters. - /// - /// true if default values (0, empty strings etc) should be formatted; false otherwise. - /// The to use when formatting messages. TypeRegistry.Empty will be used if it is null. - /// true to format the enums as integers; false to format enums as enum names. - /// true to preserve proto field names; false to convert them to lowerCamelCase. - /// The indentation string to use for multi-line formatting. null to disable multi-line format. - private Settings(bool formatDefaultValues, - TypeRegistry typeRegistry, - bool formatEnumsAsIntegers, - bool preserveProtoFieldNames, - string indentation = null) - { - FormatDefaultValues = formatDefaultValues; - TypeRegistry = typeRegistry ?? TypeRegistry.Empty; - FormatEnumsAsIntegers = formatEnumsAsIntegers; - PreserveProtoFieldNames = preserveProtoFieldNames; - Indentation = indentation; - } + writer.Write(closeChar); + } - /// - /// Creates a new object with the specified formatting of default values and the current settings. - /// - /// true if default values (0, empty strings etc) should be formatted; false otherwise. - public Settings WithFormatDefaultValues(bool formatDefaultValues) => new Settings(formatDefaultValues, TypeRegistry, FormatEnumsAsIntegers, PreserveProtoFieldNames, Indentation); - - /// - /// Creates a new object with the specified type registry and the current settings. - /// - /// The to use when formatting messages. - public Settings WithTypeRegistry(TypeRegistry typeRegistry) => new Settings(FormatDefaultValues, typeRegistry, FormatEnumsAsIntegers, PreserveProtoFieldNames, Indentation); - - /// - /// Creates a new object with the specified enums formatting option and the current settings. - /// - /// true to format the enums as integers; false to format enums as enum names. - public Settings WithFormatEnumsAsIntegers(bool formatEnumsAsIntegers) => new Settings(FormatDefaultValues, TypeRegistry, formatEnumsAsIntegers, PreserveProtoFieldNames, Indentation); - - /// - /// Creates a new object with the specified field name formatting option and the current settings. - /// - /// true to preserve proto field names; false to convert them to lowerCamelCase. - public Settings WithPreserveProtoFieldNames(bool preserveProtoFieldNames) => new Settings(FormatDefaultValues, TypeRegistry, FormatEnumsAsIntegers, preserveProtoFieldNames, Indentation); - - /// - /// Creates a new object with the specified indentation and the current settings. - /// - /// The string to output for each level of indentation (nesting). The default is two spaces per level. Use null to disable indentation entirely. - /// A non-null value for will insert additional line-breaks to the JSON output. - /// Each line will contain either a single value, or braces. The default line-break is determined by , - /// which is "\n" on Unix platforms, and "\r\n" on Windows. If seems to produce empty lines, - /// you need to pass a that uses a "\n" newline. See . - /// - public Settings WithIndentation(string indentation = " ") => new Settings(FormatDefaultValues, TypeRegistry, FormatEnumsAsIntegers, PreserveProtoFieldNames, indentation); - } + private void MaybeWriteValueWhitespace(TextWriter writer, int indentationLevel) { + if (settings.Indentation != null) { + writer.WriteLine(); + WriteIndentation(writer, indentationLevel); + } + } - // Effectively a cache of mapping from enum values to the original name as specified in the proto file, - // fetched by reflection. - // The need for this is unfortunate, as is its unbounded size, but realistically it shouldn't cause issues. - private static class OriginalEnumValueHelper - { - private static readonly ConcurrentDictionary> dictionaries - = new ConcurrentDictionary>(); - - [UnconditionalSuppressMessage("Trimming", "IL2072", - Justification = "The field for the value must still be present. It will be returned by reflection, will be in this collection, and its name can be resolved.")] - internal static string GetOriginalName(object value) - { - Dictionary nameMapping = dictionaries.GetOrAdd(value.GetType(), static t => GetNameMapping(t)); - - // If this returns false, originalName will be null, which is what we want. - nameMapping.TryGetValue(value, out string originalName); - return originalName; - } + private void WriteIndentation(TextWriter writer, int indentationLevel) { + for (int i = 0; i < indentationLevel; i++) { + writer.Write(settings.Indentation); + } + } - private static Dictionary GetNameMapping( - [DynamicallyAccessedMembers( - DynamicallyAccessedMemberTypes.PublicFields | - DynamicallyAccessedMemberTypes.NonPublicFields)] - System.Type enumType) - { - return enumType.GetTypeInfo().DeclaredFields - .Where(f => f.IsStatic) - .Where(f => f.GetCustomAttributes() - .FirstOrDefault()?.PreferredAlias ?? true) - .ToDictionary(f => f.GetValue(null), - f => f.GetCustomAttributes() - .FirstOrDefault() - // If the attribute hasn't been applied, fall back to the name of the field. - ?.Name ?? f.Name); - } - } + /// + /// Settings controlling JSON formatting. + /// + public sealed class Settings { + /// + /// Default settings, as used by + /// + public static Settings Default { get; } + + // Workaround for the Mono compiler complaining about XML comments not being on + // valid language elements. + static Settings() { + Default = new Settings(false); + } + + /// + /// Whether fields which would otherwise not be included in the formatted data + /// should be formatted even when the value is not present, or has the default value. + /// This option only affects fields which don't support "presence" (e.g. + /// singular non-optional proto3 primitive fields). + /// + public bool FormatDefaultValues { get; } + + /// + /// The type registry used to format messages. + /// + public TypeRegistry TypeRegistry { get; } + + /// + /// Whether to format enums as ints. Defaults to false. + /// + public bool FormatEnumsAsIntegers { get; } + + /// + /// Whether to use the original proto field names as defined in the .proto file. Defaults to + /// false. + /// + public bool PreserveProtoFieldNames { get; } + + /// + /// Indentation string, used for formatting. Setting null disables indentation. + /// + public string Indentation { get; } + + /// + /// Creates a new object with the specified formatting of default + /// values and an empty type registry. + /// + /// true if default values (0, empty strings etc) + /// should be formatted; false otherwise. + public Settings(bool formatDefaultValues) : this(formatDefaultValues, TypeRegistry.Empty) {} + + /// + /// Creates a new object with the specified formatting of default + /// values and type registry. + /// + /// true if default values (0, empty strings etc) + /// should be formatted; false otherwise. The to use when formatting messages. + public Settings(bool formatDefaultValues, TypeRegistry typeRegistry) + : this(formatDefaultValues, typeRegistry, false, false) {} + + /// + /// Creates a new object with the specified parameters. + /// + /// true if default values (0, empty strings etc) + /// should be formatted; false otherwise. The to use when formatting messages. + /// TypeRegistry.Empty will be used if it is null. true to format the enums as integers; false to + /// format enums as enum names. true to + /// preserve proto field names; false to convert them to lowerCamelCase. The indentation string to use for multi-line formatting. null to + /// disable multi-line format. + private Settings(bool formatDefaultValues, TypeRegistry typeRegistry, + bool formatEnumsAsIntegers, bool preserveProtoFieldNames, + string indentation = null) { + FormatDefaultValues = formatDefaultValues; + TypeRegistry = typeRegistry ?? TypeRegistry.Empty; + FormatEnumsAsIntegers = formatEnumsAsIntegers; + PreserveProtoFieldNames = preserveProtoFieldNames; + Indentation = indentation; + } + + /// + /// Creates a new object with the specified formatting of default + /// values and the current settings. + /// + /// true if default values (0, empty strings etc) + /// should be formatted; false otherwise. + public Settings WithFormatDefaultValues(bool formatDefaultValues) => + new Settings(formatDefaultValues, TypeRegistry, FormatEnumsAsIntegers, + PreserveProtoFieldNames, Indentation); + + /// + /// Creates a new object with the specified type registry and the + /// current settings. + /// + /// The to use when formatting messages. + public Settings WithTypeRegistry(TypeRegistry typeRegistry) => + new Settings(FormatDefaultValues, typeRegistry, FormatEnumsAsIntegers, + PreserveProtoFieldNames, Indentation); + + /// + /// Creates a new object with the specified enums formatting option and + /// the current settings. + /// + /// true to format the enums as integers; + /// false to format enums as enum names. + public Settings WithFormatEnumsAsIntegers(bool formatEnumsAsIntegers) => + new Settings(FormatDefaultValues, TypeRegistry, formatEnumsAsIntegers, + PreserveProtoFieldNames, Indentation); + + /// + /// Creates a new object with the specified field name formatting + /// option and the current settings. + /// + /// true to preserve proto field names; + /// false to convert them to lowerCamelCase. + public Settings WithPreserveProtoFieldNames(bool preserveProtoFieldNames) => + new Settings(FormatDefaultValues, TypeRegistry, FormatEnumsAsIntegers, + preserveProtoFieldNames, Indentation); + + /// + /// Creates a new object with the specified indentation and the current + /// settings. + /// + /// The string to output for each level of indentation (nesting). + /// The default is two spaces per level. Use null to disable indentation entirely. + /// A non-null value for will insert additional line-breaks + /// to the JSON output. Each line will contain either a single value, or braces. The default + /// line-break is determined by , which is "\n" on + /// Unix platforms, and "\r\n" on Windows. If seems to + /// produce empty lines, you need to pass a that uses a "\n" + /// newline. See . + /// + public Settings WithIndentation(string indentation = " ") => + new Settings(FormatDefaultValues, TypeRegistry, FormatEnumsAsIntegers, + PreserveProtoFieldNames, indentation); + } + + // Effectively a cache of mapping from enum values to the original name as specified in the + // proto file, fetched by reflection. The need for this is unfortunate, as is its unbounded + // size, but realistically it shouldn't cause issues. + private static class OriginalEnumValueHelper { + private static readonly ConcurrentDictionary> + dictionaries = new ConcurrentDictionary>(); + + [UnconditionalSuppressMessage( + "Trimming", "IL2072", + Justification = + "The field for the value must still be present. It will be returned by reflection, will be in this collection, and its name can be resolved.")] + [UnconditionalSuppressMessage( + "Trimming", "IL2067", + Justification = + "The field for the value must still be present. It will be returned by reflection, will be in this collection, and its name can be resolved.")] + internal static string GetOriginalName(object value) { + // Warnings are suppressed on this method. However, this code has been tested in an AOT app + // and verified that it works. Issue + // https://github.com/protocolbuffers/protobuf/issues/14788 discusses changes to guarantee + // that enum fields are never trimmed. + Dictionary nameMapping = + dictionaries.GetOrAdd(value.GetType(), static t => GetNameMapping(t)); + + // If this returns false, originalName will be null, which is what we want. + nameMapping.TryGetValue(value, out string originalName); + return originalName; + } + + private static Dictionary GetNameMapping([ + DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields | + DynamicallyAccessedMemberTypes.NonPublicFields) + ] System.Type enumType) { + return enumType.GetTypeInfo() + .DeclaredFields.Where(f => f.IsStatic) + .Where(f => f.GetCustomAttributes() + .FirstOrDefault() + ?.PreferredAlias ?? + true) + .ToDictionary( + f => f.GetValue(null), + f => + f.GetCustomAttributes() + .FirstOrDefault() + // If the attribute hasn't been applied, fall back to the name of the field. + ?.Name ?? + f.Name); + } } + } } diff --git a/csharp/src/Google.Protobuf/Reflection/ReflectionUtil.cs b/csharp/src/Google.Protobuf/Reflection/ReflectionUtil.cs index 387f158583ea5..0815d5f1f16f4 100644 --- a/csharp/src/Google.Protobuf/Reflection/ReflectionUtil.cs +++ b/csharp/src/Google.Protobuf/Reflection/ReflectionUtil.cs @@ -13,378 +13,363 @@ using System.Runtime.CompilerServices; using Google.Protobuf.Compatibility; -namespace Google.Protobuf.Reflection -{ +namespace Google.Protobuf.Reflection { + /// + /// The methods in this class are somewhat evil, and should not be tampered with lightly. + /// Basically they allow the creation of relatively weakly typed delegates from MethodInfos + /// which are more strongly typed. They do this by creating an appropriate strongly typed + /// delegate from the MethodInfo, and then calling that within an anonymous method. + /// Mind-bending stuff (at least to your humble narrator) but the resulting delegates are + /// very fast compared with calling Invoke later on. + /// + internal static class ReflectionUtil { + static ReflectionUtil() { + ForceInitialize(); // Handles all reference types + ForceInitialize(); + ForceInitialize(); + ForceInitialize(); + ForceInitialize(); + ForceInitialize(); + ForceInitialize(); + ForceInitialize(); + ForceInitialize < int ? > (); + ForceInitialize < long ? > (); + ForceInitialize < uint ? > (); + ForceInitialize < ulong ? > (); + ForceInitialize < float ? > (); + ForceInitialize < double ? > (); + ForceInitialize < bool ? > (); + ForceInitialize(); + SampleEnumMethod(); + } + + internal static void ForceInitialize() => new ReflectionHelper(); + /// - /// The methods in this class are somewhat evil, and should not be tampered with lightly. - /// Basically they allow the creation of relatively weakly typed delegates from MethodInfos - /// which are more strongly typed. They do this by creating an appropriate strongly typed - /// delegate from the MethodInfo, and then calling that within an anonymous method. - /// Mind-bending stuff (at least to your humble narrator) but the resulting delegates are - /// very fast compared with calling Invoke later on. + /// Empty Type[] used when calling GetProperty to force property instead of indexer fetching. /// - internal static class ReflectionUtil - { - static ReflectionUtil() - { - ForceInitialize(); // Handles all reference types - ForceInitialize(); - ForceInitialize(); - ForceInitialize(); - ForceInitialize(); - ForceInitialize(); - ForceInitialize(); - ForceInitialize(); - ForceInitialize(); - ForceInitialize(); - ForceInitialize(); - ForceInitialize(); - ForceInitialize(); - ForceInitialize(); - ForceInitialize(); - ForceInitialize(); - SampleEnumMethod(); - } + internal static readonly Type[] EmptyTypes = new Type[0]; + + /// + /// Creates a delegate which will cast the argument to the type that declares the method, + /// call the method on it, then convert the result to object. + /// + /// The method to create a delegate for, which must be declared in an + /// IMessage implementation. + internal static Func CreateFuncIMessageObject(MethodInfo method) => + GetReflectionHelper(method.DeclaringType, method.ReturnType) + .CreateFuncIMessageObject(method); + + /// + /// Creates a delegate which will cast the argument to the type that declares the method, + /// call the method on it, then convert the result to the specified type. The method is expected + /// to actually return an enum (because of where we're calling it - for oneof cases). Sometimes + /// that means we need some extra work to perform conversions. + /// + /// The method to create a delegate for, which must be declared in an + /// IMessage implementation. + internal static Func CreateFuncIMessageInt32(MethodInfo method) => + GetReflectionHelper(method.DeclaringType, method.ReturnType) + .CreateFuncIMessageInt32(method); + + /// + /// Creates a delegate which will execute the given method after casting the first argument to + /// the type that declares the method, and the second argument to the first parameter type of + /// the method. + /// + /// The method to create a delegate for, which must be declared in an + /// IMessage implementation. + internal static Action CreateActionIMessageObject(MethodInfo method) => + GetReflectionHelper(method.DeclaringType, method.GetParameters()[0].ParameterType) + .CreateActionIMessageObject(method); - internal static void ForceInitialize() => new ReflectionHelper(); - - /// - /// Empty Type[] used when calling GetProperty to force property instead of indexer fetching. - /// - internal static readonly Type[] EmptyTypes = new Type[0]; - - /// - /// Creates a delegate which will cast the argument to the type that declares the method, - /// call the method on it, then convert the result to object. - /// - /// The method to create a delegate for, which must be declared in an IMessage - /// implementation. - internal static Func CreateFuncIMessageObject(MethodInfo method) => - GetReflectionHelper(method.DeclaringType, method.ReturnType).CreateFuncIMessageObject(method); - - /// - /// Creates a delegate which will cast the argument to the type that declares the method, - /// call the method on it, then convert the result to the specified type. The method is expected - /// to actually return an enum (because of where we're calling it - for oneof cases). Sometimes that - /// means we need some extra work to perform conversions. - /// - /// The method to create a delegate for, which must be declared in an IMessage - /// implementation. - internal static Func CreateFuncIMessageInt32(MethodInfo method) => - GetReflectionHelper(method.DeclaringType, method.ReturnType).CreateFuncIMessageInt32(method); - - /// - /// Creates a delegate which will execute the given method after casting the first argument to - /// the type that declares the method, and the second argument to the first parameter type of the method. - /// - /// The method to create a delegate for, which must be declared in an IMessage - /// implementation. - internal static Action CreateActionIMessageObject(MethodInfo method) => - GetReflectionHelper(method.DeclaringType, method.GetParameters()[0].ParameterType).CreateActionIMessageObject(method); - - /// - /// Creates a delegate which will execute the given method after casting the first argument to - /// type that declares the method. - /// - /// The method to create a delegate for, which must be declared in an IMessage - /// implementation. - internal static Action CreateActionIMessage(MethodInfo method) => - GetReflectionHelper(method.DeclaringType, typeof(object)).CreateActionIMessage(method); - - internal static Func CreateFuncIMessageBool(MethodInfo method) => - GetReflectionHelper(method.DeclaringType, method.ReturnType).CreateFuncIMessageBool(method); - - [UnconditionalSuppressMessage("Trimming", "IL2026", Justification = "Type parameter members are preserved with DynamicallyAccessedMembers on GeneratedClrTypeInfo.ctor clrType parameter.")] - [UnconditionalSuppressMessage("AotAnalysis", "IL3050:RequiresDynamicCode", Justification = "Type definition is explicitly specified and type argument is always a message type.")] - internal static Func CreateIsInitializedCaller([DynamicallyAccessedMembers(GeneratedClrTypeInfo.MessageAccessibility)]Type msg) => - ((IExtensionSetReflector)Activator.CreateInstance(typeof(ExtensionSetReflector<>).MakeGenericType(msg))).CreateIsInitializedCaller(); - - /// - /// Creates a delegate which will execute the given method after casting the first argument to - /// the type that declares the method, and the second argument to the first parameter type of the method. - /// - [UnconditionalSuppressMessage("Trimming", "IL2026", Justification = "Type parameter members are preserved with DynamicallyAccessedMembers on GeneratedClrTypeInfo.ctor clrType parameter.")] - internal static IExtensionReflectionHelper CreateExtensionHelper(Extension extension) - { + /// + /// Creates a delegate which will execute the given method after casting the first argument to + /// type that declares the method. + /// + /// The method to create a delegate for, which must be declared in an + /// IMessage implementation. + internal static Action CreateActionIMessage(MethodInfo method) => + GetReflectionHelper(method.DeclaringType, typeof(object)).CreateActionIMessage(method); + + internal static Func CreateFuncIMessageBool(MethodInfo method) => + GetReflectionHelper(method.DeclaringType, method.ReturnType).CreateFuncIMessageBool(method); + + [UnconditionalSuppressMessage( + "Trimming", "IL2026", + Justification = + "Type parameter members are preserved with DynamicallyAccessedMembers on GeneratedClrTypeInfo.ctor clrType parameter.")] + [UnconditionalSuppressMessage( + "AotAnalysis", "IL3050:RequiresDynamicCode", + Justification = + "Type definition is explicitly specified and type argument is always a message type.")] + internal static Func CreateIsInitializedCaller([ + DynamicallyAccessedMembers(GeneratedClrTypeInfo.MessageAccessibility) + ] Type msg) => ((IExtensionSetReflector)Activator + .CreateInstance(typeof(ExtensionSetReflector<>).MakeGenericType(msg))) + .CreateIsInitializedCaller(); + + /// + /// Creates a delegate which will execute the given method after casting the first argument to + /// the type that declares the method, and the second argument to the first parameter type of + /// the method. + /// + [UnconditionalSuppressMessage( + "Trimming", "IL2026", + Justification = + "Type parameter members are preserved with DynamicallyAccessedMembers on GeneratedClrTypeInfo.ctor clrType parameter.")] + [UnconditionalSuppressMessage("AOT", "IL3050", + Justification = "Dynamic code won't call Type.MakeGenericType.")] + internal static IExtensionReflectionHelper CreateExtensionHelper(Extension extension) { #if NET5_0_OR_GREATER - if (!RuntimeFeature.IsDynamicCodeSupported) - { - // Using extensions with reflection is not supported with AOT. - // This helper is created when descriptors are populated. Delay throwing error until an app - // uses IFieldAccessor with an extension field. - return new AotExtensionReflectionHelper(); - } + if (!RuntimeFeature.IsDynamicCodeSupported) { + // Using extensions with reflection is not supported with AOT. + // This helper is created when descriptors are populated. Delay throwing error until an app + // uses IFieldAccessor with an extension field. + return new AotExtensionReflectionHelper(); + } #endif - var t1 = extension.TargetType; - var t3 = extension.GetType().GenericTypeArguments[1]; - return (IExtensionReflectionHelper) Activator.CreateInstance(typeof(ExtensionReflectionHelper<,>).MakeGenericType(t1, t3), extension); - } + var t1 = extension.TargetType; + var t3 = extension.GetType().GenericTypeArguments[1]; + return (IExtensionReflectionHelper)Activator.CreateInstance( + typeof(ExtensionReflectionHelper<, >).MakeGenericType(t1, t3), extension); + } - /// - /// Creates a reflection helper for the given type arguments. Currently these are created on demand - /// rather than cached; this will be "busy" when initially loading a message's descriptor, but after that - /// they can be garbage collected. We could cache them by type if that proves to be important, but creating - /// an object is pretty cheap. - /// - [UnconditionalSuppressMessage("Trimming", "IL2026", Justification = "Type parameter members are preserved with DynamicallyAccessedMembers on GeneratedClrTypeInfo.ctor clrType parameter.")] - private static IReflectionHelper GetReflectionHelper(Type t1, Type t2) - { + /// + /// Creates a reflection helper for the given type arguments. Currently these are created on + /// demand rather than cached; this will be "busy" when initially loading a message's + /// descriptor, but after that they can be garbage collected. We could cache them by type if + /// that proves to be important, but creating an object is pretty cheap. + /// + [UnconditionalSuppressMessage( + "Trimming", "IL2026", + Justification = + "Type parameter members are preserved with DynamicallyAccessedMembers on GeneratedClrTypeInfo.ctor clrType parameter.")] + [UnconditionalSuppressMessage("AOT", "IL3050", + Justification = "Dynamic code won't call Type.MakeGenericType.")] + private static IReflectionHelper GetReflectionHelper(Type t1, Type t2) { #if NET5_0_OR_GREATER - if (!RuntimeFeature.IsDynamicCodeSupported) - { - return new AotReflectionHelper(); - } + if (!RuntimeFeature.IsDynamicCodeSupported) { + return new AotReflectionHelper(); + } #endif - return (IReflectionHelper) Activator.CreateInstance(typeof(ReflectionHelper<,>).MakeGenericType(t1, t2)); - } + return (IReflectionHelper)Activator.CreateInstance( + typeof(ReflectionHelper<, >).MakeGenericType(t1, t2)); + } - // Non-generic interface allowing us to use an instance of ReflectionHelper without statically - // knowing the types involved. - private interface IReflectionHelper - { - Func CreateFuncIMessageInt32(MethodInfo method); - Action CreateActionIMessage(MethodInfo method); - Func CreateFuncIMessageObject(MethodInfo method); - Action CreateActionIMessageObject(MethodInfo method); - Func CreateFuncIMessageBool(MethodInfo method); - } + // Non-generic interface allowing us to use an instance of ReflectionHelper without + // statically knowing the types involved. + private interface IReflectionHelper { + Func CreateFuncIMessageInt32(MethodInfo method); + Action CreateActionIMessage(MethodInfo method); + Func CreateFuncIMessageObject(MethodInfo method); + Action CreateActionIMessageObject(MethodInfo method); + Func CreateFuncIMessageBool(MethodInfo method); + } + + internal interface IExtensionReflectionHelper { + object GetExtension(IMessage message); + void SetExtension(IMessage message, object value); + bool HasExtension(IMessage message); + void ClearExtension(IMessage message); + } - internal interface IExtensionReflectionHelper - { - object GetExtension(IMessage message); - void SetExtension(IMessage message, object value); - bool HasExtension(IMessage message); - void ClearExtension(IMessage message); + private interface IExtensionSetReflector { + Func CreateIsInitializedCaller(); + } + + private sealed class ReflectionHelper : IReflectionHelper { + public Func CreateFuncIMessageInt32(MethodInfo method) { + // On pleasant runtimes, we can create a Func from a method returning + // an enum based on an int. That's the fast path. + if (CanConvertEnumFuncToInt32Func) { + var del = (Func)method.CreateDelegate(typeof(Func)); + return message => del((T1)message); + } else { + // On some runtimes (e.g. old Mono) the return type has to be exactly correct, + // so we go via boxing. Reflection is already fairly inefficient, and this is + // only used for one-of case checking, fortunately. + var del = (Func)method.CreateDelegate(typeof(Func)); + return message => (int)(object)del((T1)message); } + } + + public Action CreateActionIMessage(MethodInfo method) { + var del = (Action)method.CreateDelegate(typeof(Action)); + return message => del((T1)message); + } + + public Func CreateFuncIMessageObject(MethodInfo method) { + var del = (Func)method.CreateDelegate(typeof(Func)); + return message => del((T1)message); + } + + public Action CreateActionIMessageObject(MethodInfo method) { + var del = (Action)method.CreateDelegate(typeof(Action)); + return (message, arg) => del((T1)message, (T2)arg); + } + + public Func CreateFuncIMessageBool(MethodInfo method) { + var del = (Func)method.CreateDelegate(typeof(Func)); + return message => del((T1)message); + } + } + + private sealed class ExtensionReflectionHelper : IExtensionReflectionHelper + where T1 : IExtendableMessage { + private readonly Extension extension; - private interface IExtensionSetReflector - { - Func CreateIsInitializedCaller(); + public ExtensionReflectionHelper(Extension extension) { + this.extension = extension; + } + + public object GetExtension(IMessage message) { + if (message is not T1 extensionMessage) { + throw new InvalidCastException( + "Cannot access extension on message that isn't IExtensionMessage"); } - private sealed class ReflectionHelper : IReflectionHelper - { - public Func CreateFuncIMessageInt32(MethodInfo method) - { - // On pleasant runtimes, we can create a Func from a method returning - // an enum based on an int. That's the fast path. - if (CanConvertEnumFuncToInt32Func) - { - var del = (Func) method.CreateDelegate(typeof(Func)); - return message => del((T1) message); - } - else - { - // On some runtimes (e.g. old Mono) the return type has to be exactly correct, - // so we go via boxing. Reflection is already fairly inefficient, and this is - // only used for one-of case checking, fortunately. - var del = (Func) method.CreateDelegate(typeof(Func)); - return message => (int) (object) del((T1) message); - } - } - - public Action CreateActionIMessage(MethodInfo method) - { - var del = (Action) method.CreateDelegate(typeof(Action)); - return message => del((T1) message); - } - - public Func CreateFuncIMessageObject(MethodInfo method) - { - var del = (Func) method.CreateDelegate(typeof(Func)); - return message => del((T1) message); - } - - public Action CreateActionIMessageObject(MethodInfo method) - { - var del = (Action) method.CreateDelegate(typeof(Action)); - return (message, arg) => del((T1) message, (T2) arg); - } - - public Func CreateFuncIMessageBool(MethodInfo method) - { - var del = (Func)method.CreateDelegate(typeof(Func)); - return message => del((T1)message); - } + if (extension is Extension ext13) { + return extensionMessage.GetExtension(ext13); + } else if (extension is RepeatedExtension repeatedExt13) { + return extensionMessage.GetOrInitializeExtension(repeatedExt13); + } else { + throw new InvalidCastException( + "The provided extension is not a valid extension identifier type"); } + } - private sealed class ExtensionReflectionHelper : IExtensionReflectionHelper - where T1 : IExtendableMessage - { - private readonly Extension extension; - - public ExtensionReflectionHelper(Extension extension) - { - this.extension = extension; - } - - public object GetExtension(IMessage message) - { - if (message is not T1 extensionMessage) - { - throw new InvalidCastException("Cannot access extension on message that isn't IExtensionMessage"); - } - - if (extension is Extension ext13) - { - return extensionMessage.GetExtension(ext13); - } - else if (extension is RepeatedExtension repeatedExt13) - { - return extensionMessage.GetOrInitializeExtension(repeatedExt13); - } - else - { - throw new InvalidCastException("The provided extension is not a valid extension identifier type"); - } - } - - public bool HasExtension(IMessage message) - { - if (message is not T1 extensionMessage) - { - throw new InvalidCastException("Cannot access extension on message that isn't IExtensionMessage"); - } - - if (extension is Extension ext13) - { - return extensionMessage.HasExtension(ext13); - } - else if (extension is RepeatedExtension) - { - throw new InvalidOperationException("HasValue is not implemented for repeated extensions"); - } - else - { - throw new InvalidCastException("The provided extension is not a valid extension identifier type"); - } - } - - public void SetExtension(IMessage message, object value) - { - if (message is not T1 extensionMessage) - { - throw new InvalidCastException("Cannot access extension on message that isn't IExtensionMessage"); - } - - if (extension is Extension ext13) - { - extensionMessage.SetExtension(ext13, (T3)value); - } - else if (extension is RepeatedExtension) - { - throw new InvalidOperationException("SetValue is not implemented for repeated extensions"); - } - else - { - throw new InvalidCastException("The provided extension is not a valid extension identifier type"); - } - } - - public void ClearExtension(IMessage message) - { - if (message is not T1 extensionMessage) - { - throw new InvalidCastException("Cannot access extension on message that isn't IExtensionMessage"); - } - - if (extension is Extension ext13) - { - extensionMessage.ClearExtension(ext13); - } - else if (extension is RepeatedExtension repeatedExt13) - { - extensionMessage.GetExtension(repeatedExt13).Clear(); - } - else - { - throw new InvalidCastException("The provided extension is not a valid extension identifier type"); - } - } + public bool HasExtension(IMessage message) { + if (message is not T1 extensionMessage) { + throw new InvalidCastException( + "Cannot access extension on message that isn't IExtensionMessage"); } -#if NET5_0_OR_GREATER - /// - /// This helper is compatible with .NET Native AOT. - /// MakeGenericType doesn't work when a type argument is a value type in AOT. - /// MethodInfo.Invoke is used instead of compiled expressions because it's faster in AOT. - /// - private sealed class AotReflectionHelper : IReflectionHelper - { - private static readonly object[] EmptyObjectArray = new object[0]; - public Action CreateActionIMessage(MethodInfo method) => message => method.Invoke(message, EmptyObjectArray); - public Action CreateActionIMessageObject(MethodInfo method) => (message, arg) => method.Invoke(message, new object[] { arg }); - public Func CreateFuncIMessageBool(MethodInfo method) => message => (bool) method.Invoke(message, EmptyObjectArray); - public Func CreateFuncIMessageInt32(MethodInfo method) => message => (int) method.Invoke(message, EmptyObjectArray); - public Func CreateFuncIMessageObject(MethodInfo method) => message => method.Invoke(message, EmptyObjectArray); + if (extension is Extension ext13) { + return extensionMessage.HasExtension(ext13); + } else if (extension is RepeatedExtension) { + throw new InvalidOperationException( + "HasValue is not implemented for repeated extensions"); + } else { + throw new InvalidCastException( + "The provided extension is not a valid extension identifier type"); } + } - /// - /// Reflection with extensions isn't supported because IExtendableMessage members are used to get values. - /// Can't use reflection to invoke those methods because they have a generic argument. - /// MakeGenericMethod can't be used because it will break whenever the extension type is a value type. - /// This could be made to work if there were non-generic methods available for getting and setting extension values. - /// - private sealed class AotExtensionReflectionHelper : IExtensionReflectionHelper - { - private const string Message = "Extensions reflection is not supported with AOT."; - public object GetExtension(IMessage message) => throw new NotSupportedException(Message); - public bool HasExtension(IMessage message) => throw new NotSupportedException(Message); - public void SetExtension(IMessage message, object value) => throw new NotSupportedException(Message); - public void ClearExtension(IMessage message) => throw new NotSupportedException(Message); + public void SetExtension(IMessage message, object value) { + if (message is not T1 extensionMessage) { + throw new InvalidCastException( + "Cannot access extension on message that isn't IExtensionMessage"); } -#endif - private sealed class ExtensionSetReflector< - [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicProperties | DynamicallyAccessedMemberTypes.NonPublicProperties)] - T1> : IExtensionSetReflector where T1 : IExtendableMessage - { - public Func CreateIsInitializedCaller() - { - var prop = typeof(T1).GetTypeInfo().GetDeclaredProperty("_Extensions"); - var getFunc = (Func>)prop.GetMethod.CreateDelegate(typeof(Func>)); - var initializedFunc = (Func, bool>) - typeof(ExtensionSet) - .GetTypeInfo() - .GetDeclaredMethod("IsInitialized") - .CreateDelegate(typeof(Func, bool>)); - return (m) => { - var set = getFunc((T1)m); - return set == null || initializedFunc(set); - }; - } + if (extension is Extension ext13) { + extensionMessage.SetExtension(ext13, (T3)value); + } else if (extension is RepeatedExtension) { + throw new InvalidOperationException( + "SetValue is not implemented for repeated extensions"); + } else { + throw new InvalidCastException( + "The provided extension is not a valid extension identifier type"); } + } - // Runtime compatibility checking code - see ReflectionHelper.CreateFuncIMessageInt32 for - // details about why we're doing this. - - // Deliberately not inside the generic type. We only want to check this once. - private static bool CanConvertEnumFuncToInt32Func { get; } = CheckCanConvertEnumFuncToInt32Func(); - - private static bool CheckCanConvertEnumFuncToInt32Func() - { - try - { - // Try to do the conversion using reflection, so we can see whether it's supported. - MethodInfo method = typeof(ReflectionUtil).GetMethod(nameof(SampleEnumMethod)); - // If this passes, we're in a reasonable runtime. - method.CreateDelegate(typeof(Func)); - return true; - } - catch (ArgumentException) - { - return false; - } + public void ClearExtension(IMessage message) { + if (message is not T1 extensionMessage) { + throw new InvalidCastException( + "Cannot access extension on message that isn't IExtensionMessage"); } - public enum SampleEnum - { - X + if (extension is Extension ext13) { + extensionMessage.ClearExtension(ext13); + } else if (extension is RepeatedExtension repeatedExt13) { + extensionMessage.GetExtension(repeatedExt13).Clear(); + } else { + throw new InvalidCastException( + "The provided extension is not a valid extension identifier type"); } + } + } - // Public to make the reflection simpler. - public static SampleEnum SampleEnumMethod() => SampleEnum.X; +#if NET5_0_OR_GREATER + /// + /// This helper is compatible with .NET Native AOT. + /// MakeGenericType doesn't work when a type argument is a value type in AOT. + /// MethodInfo.Invoke is used instead of compiled expressions because it's faster in AOT. + /// + private sealed class AotReflectionHelper : IReflectionHelper { + private static readonly object[] EmptyObjectArray = new object[0]; + public Action CreateActionIMessage(MethodInfo method) => message => + method.Invoke(message, EmptyObjectArray); + public Action CreateActionIMessageObject(MethodInfo method) => + (message, arg) => method.Invoke(message, new object[] { arg }); + public Func CreateFuncIMessageBool(MethodInfo method) => message => + (bool)method.Invoke(message, EmptyObjectArray); + public Func CreateFuncIMessageInt32(MethodInfo method) => message => + (int)method.Invoke(message, EmptyObjectArray); + public Func CreateFuncIMessageObject(MethodInfo method) => message => + method.Invoke(message, EmptyObjectArray); + } + + /// + /// Reflection with extensions isn't supported because IExtendableMessage members are used to + /// get values. Can't use reflection to invoke those methods because they have a generic + /// argument. MakeGenericMethod can't be used because it will break whenever the extension type + /// is a value type. This could be made to work if there were non-generic methods available for + /// getting and setting extension values. + /// + private sealed class AotExtensionReflectionHelper : IExtensionReflectionHelper { + private const string Message = "Extensions reflection is not supported with AOT."; + public object GetExtension(IMessage message) => throw new NotSupportedException(Message); + public bool HasExtension(IMessage message) => throw new NotSupportedException(Message); + public void SetExtension(IMessage message, + object value) => throw new NotSupportedException(Message); + public void ClearExtension(IMessage message) => throw new NotSupportedException(Message); + } +#endif + + private sealed class ExtensionSetReflector<[DynamicallyAccessedMembers( + DynamicallyAccessedMemberTypes.PublicProperties | + DynamicallyAccessedMemberTypes.NonPublicProperties)] T1> : IExtensionSetReflector + where T1 : IExtendableMessage { + public Func CreateIsInitializedCaller() { + var prop = typeof(T1).GetTypeInfo().GetDeclaredProperty("_Extensions"); + var getFunc = (Func>)prop.GetMethod.CreateDelegate( + typeof(Func>)); + var initializedFunc = (Func, bool>)typeof(ExtensionSet) + .GetTypeInfo() + .GetDeclaredMethod("IsInitialized") + .CreateDelegate(typeof(Func, bool>)); + return (m) => { + var set = getFunc((T1)m); + return set == null || initializedFunc(set); + }; + } + } + + // Runtime compatibility checking code - see ReflectionHelper.CreateFuncIMessageInt32 + // for details about why we're doing this. + + // Deliberately not inside the generic type. We only want to check this once. + private static bool CanConvertEnumFuncToInt32Func { get; } = + CheckCanConvertEnumFuncToInt32Func(); + + private static bool CheckCanConvertEnumFuncToInt32Func() { + try { + // Try to do the conversion using reflection, so we can see whether it's supported. + MethodInfo method = typeof(ReflectionUtil).GetMethod(nameof(SampleEnumMethod)); + // If this passes, we're in a reasonable runtime. + method.CreateDelegate(typeof(Func)); + return true; + } catch (ArgumentException) { + return false; + } } + + public enum SampleEnum { X } + + // Public to make the reflection simpler. + public static SampleEnum SampleEnumMethod() => SampleEnum.X; + } } From b9ad33cdffd7a6abfacde0580c430e184f62549c Mon Sep 17 00:00:00 2001 From: Hong Shin Date: Tue, 19 Dec 2023 13:28:11 -0800 Subject: [PATCH 059/255] Reify our unifying dreams This CL collapses (strings, bytes) into primitives for message.cc::GetterForViewOrMut. Strings, bytes, and all primitives have been unified, properly parameterized based on RsType. Returning $pb$::Mut<$RsType$> and $pb$::View<$RsType$> made this possible. Note that the vtables for primitives take in an additional type arg, so we've added that. In addition, strings / bytes (aka stringlikes) require a transform, so that'll be invoked on an as-needed basis. PiperOrigin-RevId: 592328216 --- src/google/protobuf/compiler/rust/message.cc | 138 ++++++++----------- 1 file changed, 58 insertions(+), 80 deletions(-) diff --git a/src/google/protobuf/compiler/rust/message.cc b/src/google/protobuf/compiler/rust/message.cc index 6f5454d1a5de9..02f85d0ab6458 100644 --- a/src/google/protobuf/compiler/rust/message.cc +++ b/src/google/protobuf/compiler/rust/message.cc @@ -9,6 +9,7 @@ #include "absl/log/absl_check.h" #include "absl/log/absl_log.h" +#include "absl/strings/str_format.h" #include "absl/strings/string_view.h" #include "google/protobuf/compiler/cpp/helpers.h" #include "google/protobuf/compiler/cpp/names.h" @@ -163,6 +164,10 @@ void MessageDrop(Context& ctx, const Descriptor& msg) { )rs"); } +bool IsStringOrBytes(FieldDescriptor::Type t) { + return t == FieldDescriptor::TYPE_STRING || t == FieldDescriptor::TYPE_BYTES; +} + void GetterForViewOrMut(Context& ctx, const FieldDescriptor& field, bool is_mut) { auto fieldName = field.name(); @@ -218,89 +223,62 @@ void GetterForViewOrMut(Context& ctx, const FieldDescriptor& field, } auto rsType = PrimitiveRsTypeName(field); - if (fieldType == FieldDescriptor::TYPE_STRING || - fieldType == FieldDescriptor::TYPE_BYTES) { - ctx.Emit({{"field", fieldName}, - {"self", self}, - {"getter_thunk", getter_thunk}, - {"setter_thunk", setter_thunk}, - {"RsType", rsType}, - {"maybe_mutator", - [&] { - if (is_mut) { - ctx.Emit({}, R"rs( - pub fn r#$field$_mut(&self) -> $pb$::Mut<'_, $RsType$> { - static VTABLE: $pbi$::BytesMutVTable = - $pbi$::BytesMutVTable::new( - $pbi$::Private, - $getter_thunk$, - $setter_thunk$, - ); - - unsafe { - <$pb$::Mut<$RsType$>>::from_inner( - $pbi$::Private, - $pbi$::RawVTableMutator::new( - $pbi$::Private, - self.inner, - &VTABLE, - ) - ) - } - } - )rs"); - } - }}}, - R"rs( - pub fn r#$field$(&self) -> $pb$::View<'_, $RsType$> { - let s = unsafe { $getter_thunk$($self$).as_ref() }; - unsafe { __pb::ProtoStr::from_utf8_unchecked(s).into() } - } - - $maybe_mutator$ - )rs"); - } else { - ctx.Emit({{"field", fieldName}, - {"getter_thunk", getter_thunk}, - {"setter_thunk", setter_thunk}, - {"clearer_thunk", clearer_thunk}, - {"self", self}, - {"RsType", rsType}, - {"maybe_mutator", - [&] { - // TODO: once the rust public api is accessible, - // by tooling, ensure that this only appears for the - // mutational pathway - if (is_mut && fieldType) { - ctx.Emit({}, R"rs( - pub fn r#$field$_mut(&self) -> $pb$::Mut<'_, $RsType$> { - static VTABLE: $pbi$::PrimitiveVTable<$RsType$> = - $pbi$::PrimitiveVTable::new( - $pbi$::Private, - $getter_thunk$, - $setter_thunk$); - unsafe { - $pb$::PrimitiveMut::from_inner( + auto asRef = IsStringOrBytes(fieldType) ? ".as_ref()" : ""; + auto vtable = + IsStringOrBytes(fieldType) ? "BytesMutVTable" : "PrimitiveVTable"; + // PrimitiveVtable is parameterized based on the underlying primitive, like + // u32 so we need to provide this additional type arg + auto optionalTypeArgs = + IsStringOrBytes(fieldType) ? "" : absl::StrFormat("<%s>", rsType); + // need to stuff ProtoStr and [u8] behind a reference since they are DSTs + auto stringTransform = + IsStringOrBytes(fieldType) + ? "unsafe { __pb::ProtoStr::from_utf8_unchecked(res).into() }" + : "res"; + + ctx.Emit({{"field", fieldName}, + {"getter_thunk", getter_thunk}, + {"setter_thunk", setter_thunk}, + {"clearer_thunk", clearer_thunk}, + {"self", self}, + {"RsType", rsType}, + {"as_ref", asRef}, + {"vtable", vtable}, + {"optional_type_args", optionalTypeArgs}, + {"string_transform", stringTransform}, + {"maybe_mutator", + [&] { + // TODO: check mutational pathway genn'd correctly + if (is_mut) { + ctx.Emit({}, R"rs( + pub fn r#$field$_mut(&self) -> $pb$::Mut<'_, $RsType$> { + static VTABLE: $pbi$::$vtable$$optional_type_args$ = + $pbi$::$vtable$::new( + $pbi$::Private, + $getter_thunk$, + $setter_thunk$); + unsafe { + <$pb$::Mut<$RsType$>>::from_inner( + $pbi$::Private, + $pbi$::RawVTableMutator::new( $pbi$::Private, - $pbi$::RawVTableMutator::new( - $pbi$::Private, - self.inner, - &VTABLE - ), - ) - } + self.inner, + &VTABLE + ), + ) } - )rs"); - } - }}}, - R"rs( - pub fn r#$field$(&self) -> $pb$::View<'_, $RsType$> { - unsafe { $getter_thunk$($self$) } - } + } + )rs"); + } + }}}, + R"rs( + pub fn r#$field$(&self) -> $pb$::View<'_, $RsType$> { + let res = unsafe { $getter_thunk$($self$)$as_ref$ }; + $string_transform$ + } - $maybe_mutator$ - )rs"); - } + $maybe_mutator$ + )rs"); } void AccessorsForViewOrMut(Context& ctx, const Descriptor& msg, bool is_mut) { From e3ed59102cc56e3ec2febb59db11dc97749733ea Mon Sep 17 00:00:00 2001 From: Eric Salo Date: Tue, 19 Dec 2023 14:29:12 -0800 Subject: [PATCH 060/255] upb: replumb upb_Arena to be substantially more opaque PiperOrigin-RevId: 592345066 --- upb/BUILD | 9 -- upb/mem/BUILD | 25 +--- upb/mem/arena.c | 258 ++++++++++++++++++++++++------------- upb/mem/arena.h | 78 ++--------- upb/mem/internal/arena.h | 111 ++++++++++++---- upb/wire/BUILD | 1 - upb/wire/decode.c | 12 +- upb/wire/decode_fast.c | 8 +- upb/wire/internal/decode.h | 5 +- 9 files changed, 278 insertions(+), 229 deletions(-) diff --git a/upb/BUILD b/upb/BUILD index cc55caa65f6c0..180cc778bb718 100644 --- a/upb/BUILD +++ b/upb/BUILD @@ -201,12 +201,6 @@ alias( visibility = ["//visibility:public"], ) -alias( - name = "mem_internal", - actual = "//upb/mem:internal", - visibility = ["//visibility:public"], -) - alias( name = "message", actual = "//upb/message", @@ -403,7 +397,6 @@ upb_amalgamation( ":hash", ":lex", ":mem", - ":mem_internal", ":message", ":message_accessors", ":message_copy", @@ -454,7 +447,6 @@ upb_amalgamation( ":json", ":lex", ":mem", - ":mem_internal", ":message", ":message_accessors", ":message_copy", @@ -505,7 +497,6 @@ upb_amalgamation( ":json", ":lex", ":mem", - ":mem_internal", ":message", ":message_accessors", ":message_copy", diff --git a/upb/mem/BUILD b/upb/mem/BUILD index f6bc19e7f1022..f4b3226e50bdd 100644 --- a/upb/mem/BUILD +++ b/upb/mem/BUILD @@ -9,32 +9,18 @@ load("//bazel:build_defs.bzl", "UPB_DEFAULT_COPTS") cc_library( name = "mem", - hdrs = [ - "alloc.h", - "arena.h", - "arena.hpp", - ], - copts = UPB_DEFAULT_COPTS, - visibility = ["//visibility:public"], - deps = [ - ":internal", - "//upb:port", - ], -) - -cc_library( - name = "internal", srcs = [ "alloc.c", - "alloc.h", "arena.c", - "arena.h", ], hdrs = [ + "alloc.h", + "arena.h", + "arena.hpp", "internal/arena.h", ], copts = UPB_DEFAULT_COPTS, - visibility = ["//upb:__pkg__"], + visibility = ["//visibility:public"], deps = [ "//upb:port", ], @@ -44,9 +30,8 @@ cc_test( name = "arena_test", srcs = ["arena_test.cc"], deps = [ + ":mem", "@com_google_googletest//:gtest_main", - "//upb:mem", - "//upb:mem_internal", "//upb:port", "@com_google_absl//absl/random", "@com_google_absl//absl/random:distributions", diff --git a/upb/mem/arena.c b/upb/mem/arena.c index 1bb1b01db314e..a01421e0d72dd 100644 --- a/upb/mem/arena.c +++ b/upb/mem/arena.c @@ -17,21 +17,61 @@ // Must be last. #include "upb/port/def.inc" -struct _upb_MemBlock { +typedef struct upb_MemBlock { // Atomic only for the benefit of SpaceAllocated(). - UPB_ATOMIC(_upb_MemBlock*) next; + UPB_ATOMIC(struct upb_MemBlock*) next; uint32_t size; // Data follows. -}; - -static const size_t kUpb_MemblockReserve = - UPB_ALIGN_UP(sizeof(_upb_MemBlock), UPB_MALLOC_ALIGN); +} upb_MemBlock; + +typedef struct upb_ArenaInternal { + // upb_alloc* together with a low bit which signals if there is an initial + // block. + uintptr_t block_alloc; + + // When multiple arenas are fused together, each arena points to a parent + // arena (root points to itself). The root tracks how many live arenas + // reference it. + + // The low bit is tagged: + // 0: pointer to parent + // 1: count, left shifted by one + UPB_ATOMIC(uintptr_t) parent_or_count; + + // All nodes that are fused together are in a singly-linked list. + // == NULL at end of list. + UPB_ATOMIC(struct upb_ArenaInternal*) next; + + // The last element of the linked list. This is present only as an + // optimization, so that we do not have to iterate over all members for every + // fuse. Only significant for an arena root. In other cases it is ignored. + // == self when no other list members. + UPB_ATOMIC(struct upb_ArenaInternal*) tail; + + // Linked list of blocks to free/cleanup. Atomic only for the benefit of + // upb_Arena_SpaceAllocated(). + UPB_ATOMIC(upb_MemBlock*) blocks; +} upb_ArenaInternal; + +// All public + private state for an arena. +typedef struct { + upb_Arena head; + upb_ArenaInternal body; +} upb_ArenaState; typedef struct { - upb_Arena* root; + upb_ArenaInternal* root; uintptr_t tagged_count; } upb_ArenaRoot; +static const size_t kUpb_MemblockReserve = + UPB_ALIGN_UP(sizeof(upb_MemBlock), UPB_MALLOC_ALIGN); + +// Extracts the (upb_ArenaInternal*) from a (upb_Arena*) +static upb_ArenaInternal* upb_Arena_Internal(const upb_Arena* a) { + return &((upb_ArenaState*)a)->body; +} + static bool _upb_Arena_IsTaggedRefcount(uintptr_t parent_or_count) { return (parent_or_count & 1) == 1; } @@ -51,19 +91,20 @@ static uintptr_t _upb_Arena_TaggedFromRefcount(uintptr_t refcount) { return parent_or_count; } -static upb_Arena* _upb_Arena_PointerFromTagged(uintptr_t parent_or_count) { +static upb_ArenaInternal* _upb_Arena_PointerFromTagged( + uintptr_t parent_or_count) { UPB_ASSERT(_upb_Arena_IsTaggedPointer(parent_or_count)); - return (upb_Arena*)parent_or_count; + return (upb_ArenaInternal*)parent_or_count; } -static uintptr_t _upb_Arena_TaggedFromPointer(upb_Arena* a) { - uintptr_t parent_or_count = (uintptr_t)a; +static uintptr_t _upb_Arena_TaggedFromPointer(upb_ArenaInternal* ai) { + uintptr_t parent_or_count = (uintptr_t)ai; UPB_ASSERT(_upb_Arena_IsTaggedPointer(parent_or_count)); return parent_or_count; } -static upb_alloc* _upb_Arena_BlockAlloc(upb_Arena* arena) { - return (upb_alloc*)(arena->block_alloc & ~0x1); +static upb_alloc* _upb_ArenaInternal_BlockAlloc(upb_ArenaInternal* ai) { + return (upb_alloc*)(ai->block_alloc & ~0x1); } static uintptr_t _upb_Arena_MakeBlockAlloc(upb_alloc* alloc, bool has_initial) { @@ -72,15 +113,16 @@ static uintptr_t _upb_Arena_MakeBlockAlloc(upb_alloc* alloc, bool has_initial) { return alloc_uint | (has_initial ? 1 : 0); } -static bool _upb_Arena_HasInitialBlock(upb_Arena* arena) { - return arena->block_alloc & 0x1; +static bool _upb_ArenaInternal_HasInitialBlock(upb_ArenaInternal* ai) { + return ai->block_alloc & 0x1; } static upb_ArenaRoot _upb_Arena_FindRoot(upb_Arena* a) { - uintptr_t poc = upb_Atomic_Load(&a->parent_or_count, memory_order_acquire); + upb_ArenaInternal* ai = upb_Arena_Internal(a); + uintptr_t poc = upb_Atomic_Load(&ai->parent_or_count, memory_order_acquire); while (_upb_Arena_IsTaggedPointer(poc)) { - upb_Arena* next = _upb_Arena_PointerFromTagged(poc); - UPB_ASSERT(a != next); + upb_ArenaInternal* next = _upb_Arena_PointerFromTagged(poc); + UPB_ASSERT(ai != next); uintptr_t next_poc = upb_Atomic_Load(&next->parent_or_count, memory_order_acquire); @@ -104,64 +146,67 @@ static upb_ArenaRoot _upb_Arena_FindRoot(upb_Arena* a) { // further away over time, but the path towards that root will continue to // be valid and the creation of the path carries all the memory orderings // required. - UPB_ASSERT(a != _upb_Arena_PointerFromTagged(next_poc)); - upb_Atomic_Store(&a->parent_or_count, next_poc, memory_order_relaxed); + UPB_ASSERT(ai != _upb_Arena_PointerFromTagged(next_poc)); + upb_Atomic_Store(&ai->parent_or_count, next_poc, memory_order_relaxed); } - a = next; + ai = next; poc = next_poc; } - return (upb_ArenaRoot){.root = a, .tagged_count = poc}; + return (upb_ArenaRoot){.root = ai, .tagged_count = poc}; } size_t upb_Arena_SpaceAllocated(upb_Arena* arena) { - arena = _upb_Arena_FindRoot(arena).root; + upb_ArenaInternal* ai = _upb_Arena_FindRoot(arena).root; size_t memsize = 0; - while (arena != NULL) { - _upb_MemBlock* block = - upb_Atomic_Load(&arena->blocks, memory_order_relaxed); + while (ai != NULL) { + upb_MemBlock* block = upb_Atomic_Load(&ai->blocks, memory_order_relaxed); while (block != NULL) { - memsize += sizeof(_upb_MemBlock) + block->size; + memsize += sizeof(upb_MemBlock) + block->size; block = upb_Atomic_Load(&block->next, memory_order_relaxed); } - arena = upb_Atomic_Load(&arena->next, memory_order_relaxed); + ai = upb_Atomic_Load(&ai->next, memory_order_relaxed); } return memsize; } uint32_t upb_Arena_DebugRefCount(upb_Arena* a) { + upb_ArenaInternal* ai = upb_Arena_Internal(a); // These loads could probably be relaxed, but given that this is debug-only, // it's not worth introducing a new variant for it. - uintptr_t poc = upb_Atomic_Load(&a->parent_or_count, memory_order_acquire); + uintptr_t poc = upb_Atomic_Load(&ai->parent_or_count, memory_order_acquire); while (_upb_Arena_IsTaggedPointer(poc)) { - a = _upb_Arena_PointerFromTagged(poc); - poc = upb_Atomic_Load(&a->parent_or_count, memory_order_acquire); + ai = _upb_Arena_PointerFromTagged(poc); + poc = upb_Atomic_Load(&ai->parent_or_count, memory_order_acquire); } return _upb_Arena_RefCountFromTagged(poc); } static void _upb_Arena_AddBlock(upb_Arena* a, void* ptr, size_t size) { - _upb_MemBlock* block = ptr; + upb_ArenaInternal* ai = upb_Arena_Internal(a); + upb_MemBlock* block = ptr; // Insert into linked list. block->size = (uint32_t)size; - upb_Atomic_Init(&block->next, a->blocks); - upb_Atomic_Store(&a->blocks, block, memory_order_release); + upb_Atomic_Init(&block->next, ai->blocks); + upb_Atomic_Store(&ai->blocks, block, memory_order_release); - a->head.UPB_PRIVATE(ptr) = UPB_PTR_AT(block, kUpb_MemblockReserve, char); - a->head.UPB_PRIVATE(end) = UPB_PTR_AT(block, size, char); + a->UPB_PRIVATE(ptr) = UPB_PTR_AT(block, kUpb_MemblockReserve, char); + a->UPB_PRIVATE(end) = UPB_PTR_AT(block, size, char); - UPB_POISON_MEMORY_REGION(a->head.UPB_PRIVATE(ptr), - a->head.UPB_PRIVATE(end) - a->head.UPB_PRIVATE(ptr)); + UPB_POISON_MEMORY_REGION(a->UPB_PRIVATE(ptr), + a->UPB_PRIVATE(end) - a->UPB_PRIVATE(ptr)); } static bool _upb_Arena_AllocBlock(upb_Arena* a, size_t size) { - if (!a->block_alloc) return false; - _upb_MemBlock* last_block = upb_Atomic_Load(&a->blocks, memory_order_acquire); + upb_ArenaInternal* ai = upb_Arena_Internal(a); + if (!ai->block_alloc) return false; + upb_MemBlock* last_block = upb_Atomic_Load(&ai->blocks, memory_order_acquire); size_t last_size = last_block != NULL ? last_block->size : 128; size_t block_size = UPB_MAX(size, last_size * 2) + kUpb_MemblockReserve; - _upb_MemBlock* block = upb_malloc(_upb_Arena_BlockAlloc(a), block_size); + upb_MemBlock* block = + upb_malloc(_upb_ArenaInternal_BlockAlloc(ai), block_size); if (!block) return false; _upb_Arena_AddBlock(a, block, block_size); @@ -175,8 +220,9 @@ void* UPB_PRIVATE(_upb_Arena_SlowMalloc)(upb_Arena* a, size_t size) { } static upb_Arena* _upb_Arena_InitSlow(upb_alloc* alloc) { - const size_t first_block_overhead = sizeof(upb_Arena) + kUpb_MemblockReserve; - upb_Arena* a; + const size_t first_block_overhead = + sizeof(upb_ArenaState) + kUpb_MemblockReserve; + upb_ArenaState* a; // We need to malloc the initial block. char* mem; @@ -185,22 +231,23 @@ static upb_Arena* _upb_Arena_InitSlow(upb_alloc* alloc) { return NULL; } - a = UPB_PTR_AT(mem, n - sizeof(*a), upb_Arena); - n -= sizeof(*a); + a = UPB_PTR_AT(mem, n - sizeof(upb_ArenaState), upb_ArenaState); + n -= sizeof(upb_ArenaState); - a->block_alloc = _upb_Arena_MakeBlockAlloc(alloc, 0); - upb_Atomic_Init(&a->parent_or_count, _upb_Arena_TaggedFromRefcount(1)); - upb_Atomic_Init(&a->next, NULL); - upb_Atomic_Init(&a->tail, a); - upb_Atomic_Init(&a->blocks, NULL); + a->body.block_alloc = _upb_Arena_MakeBlockAlloc(alloc, 0); + upb_Atomic_Init(&a->body.parent_or_count, _upb_Arena_TaggedFromRefcount(1)); + upb_Atomic_Init(&a->body.next, NULL); + upb_Atomic_Init(&a->body.tail, &a->body); + upb_Atomic_Init(&a->body.blocks, NULL); - _upb_Arena_AddBlock(a, mem, n); + _upb_Arena_AddBlock(&a->head, mem, n); - return a; + return &a->head; } upb_Arena* upb_Arena_Init(void* mem, size_t n, upb_alloc* alloc) { - upb_Arena* a; + UPB_ASSERT(sizeof(void*) * UPB_ARENA_SIZE_HACK >= sizeof(upb_ArenaState)); + upb_ArenaState* a; if (n) { /* Align initial pointer up so that we return properly-aligned pointers. */ @@ -212,63 +259,65 @@ upb_Arena* upb_Arena_Init(void* mem, size_t n, upb_alloc* alloc) { /* Round block size down to alignof(*a) since we will allocate the arena * itself at the end. */ - n = UPB_ALIGN_DOWN(n, UPB_ALIGN_OF(upb_Arena)); + n = UPB_ALIGN_DOWN(n, UPB_ALIGN_OF(upb_ArenaState)); - if (UPB_UNLIKELY(n < sizeof(upb_Arena))) { + if (UPB_UNLIKELY(n < sizeof(upb_ArenaState))) { return _upb_Arena_InitSlow(alloc); } - a = UPB_PTR_AT(mem, n - sizeof(*a), upb_Arena); + a = UPB_PTR_AT(mem, n - sizeof(upb_ArenaState), upb_ArenaState); + + upb_Atomic_Init(&a->body.parent_or_count, _upb_Arena_TaggedFromRefcount(1)); + upb_Atomic_Init(&a->body.next, NULL); + upb_Atomic_Init(&a->body.tail, &a->body); + upb_Atomic_Init(&a->body.blocks, NULL); - upb_Atomic_Init(&a->parent_or_count, _upb_Arena_TaggedFromRefcount(1)); - upb_Atomic_Init(&a->next, NULL); - upb_Atomic_Init(&a->tail, a); - upb_Atomic_Init(&a->blocks, NULL); - a->block_alloc = _upb_Arena_MakeBlockAlloc(alloc, 1); + a->body.block_alloc = _upb_Arena_MakeBlockAlloc(alloc, 1); a->head.UPB_PRIVATE(ptr) = mem; - a->head.UPB_PRIVATE(end) = UPB_PTR_AT(mem, n - sizeof(*a), char); + a->head.UPB_PRIVATE(end) = UPB_PTR_AT(mem, n - sizeof(upb_ArenaState), char); - return a; + return &a->head; } -static void _upb_Arena_DoFree(upb_Arena* a) { - UPB_ASSERT(_upb_Arena_RefCountFromTagged(a->parent_or_count) == 1); +static void _upb_Arena_DoFree(upb_ArenaInternal* ai) { + UPB_ASSERT(_upb_Arena_RefCountFromTagged(ai->parent_or_count) == 1); - while (a != NULL) { + while (ai != NULL) { // Load first since arena itself is likely from one of its blocks. - upb_Arena* next_arena = - (upb_Arena*)upb_Atomic_Load(&a->next, memory_order_acquire); - upb_alloc* block_alloc = _upb_Arena_BlockAlloc(a); - _upb_MemBlock* block = upb_Atomic_Load(&a->blocks, memory_order_acquire); + upb_ArenaInternal* next_arena = + (upb_ArenaInternal*)upb_Atomic_Load(&ai->next, memory_order_acquire); + upb_alloc* block_alloc = _upb_ArenaInternal_BlockAlloc(ai); + upb_MemBlock* block = upb_Atomic_Load(&ai->blocks, memory_order_acquire); while (block != NULL) { // Load first since we are deleting block. - _upb_MemBlock* next_block = + upb_MemBlock* next_block = upb_Atomic_Load(&block->next, memory_order_acquire); upb_free(block_alloc, block); block = next_block; } - a = next_arena; + ai = next_arena; } } void upb_Arena_Free(upb_Arena* a) { - uintptr_t poc = upb_Atomic_Load(&a->parent_or_count, memory_order_acquire); + upb_ArenaInternal* ai = upb_Arena_Internal(a); + uintptr_t poc = upb_Atomic_Load(&ai->parent_or_count, memory_order_acquire); retry: while (_upb_Arena_IsTaggedPointer(poc)) { - a = _upb_Arena_PointerFromTagged(poc); - poc = upb_Atomic_Load(&a->parent_or_count, memory_order_acquire); + ai = _upb_Arena_PointerFromTagged(poc); + poc = upb_Atomic_Load(&ai->parent_or_count, memory_order_acquire); } // compare_exchange or fetch_sub are RMW operations, which are more // expensive then direct loads. As an optimization, we only do RMW ops // when we need to update things for other threads to see. if (poc == _upb_Arena_TaggedFromRefcount(1)) { - _upb_Arena_DoFree(a); + _upb_Arena_DoFree(ai); return; } if (upb_Atomic_CompareExchangeWeak( - &a->parent_or_count, &poc, + &ai->parent_or_count, &poc, _upb_Arena_TaggedFromRefcount(_upb_Arena_RefCountFromTagged(poc) - 1), memory_order_release, memory_order_acquire)) { // We were >1 and we decremented it successfully, so we are done. @@ -280,12 +329,14 @@ void upb_Arena_Free(upb_Arena* a) { goto retry; } -static void _upb_Arena_DoFuseArenaLists(upb_Arena* const parent, - upb_Arena* child) { - upb_Arena* parent_tail = upb_Atomic_Load(&parent->tail, memory_order_relaxed); +static void _upb_Arena_DoFuseArenaLists(upb_ArenaInternal* const parent, + upb_ArenaInternal* child) { + upb_ArenaInternal* parent_tail = + upb_Atomic_Load(&parent->tail, memory_order_relaxed); + do { // Our tail might be stale, but it will always converge to the true tail. - upb_Arena* parent_tail_next = + upb_ArenaInternal* parent_tail_next = upb_Atomic_Load(&parent_tail->next, memory_order_relaxed); while (parent_tail_next != NULL) { parent_tail = parent_tail_next; @@ -293,7 +344,7 @@ static void _upb_Arena_DoFuseArenaLists(upb_Arena* const parent, upb_Atomic_Load(&parent_tail->next, memory_order_relaxed); } - upb_Arena* displaced = + upb_ArenaInternal* displaced = upb_Atomic_Exchange(&parent_tail->next, child, memory_order_relaxed); parent_tail = upb_Atomic_Load(&child->tail, memory_order_relaxed); @@ -305,8 +356,8 @@ static void _upb_Arena_DoFuseArenaLists(upb_Arena* const parent, upb_Atomic_Store(&parent->tail, parent_tail, memory_order_relaxed); } -static upb_Arena* _upb_Arena_DoFuse(upb_Arena* a1, upb_Arena* a2, - uintptr_t* ref_delta) { +static upb_ArenaInternal* _upb_Arena_DoFuse(upb_Arena* a1, upb_Arena* a2, + uintptr_t* ref_delta) { // `parent_or_count` has two disctint modes // - parent pointer mode // - refcount mode @@ -364,7 +415,8 @@ static upb_Arena* _upb_Arena_DoFuse(upb_Arena* a1, upb_Arena* a2, return r1.root; } -static bool _upb_Arena_FixupRefs(upb_Arena* new_root, uintptr_t ref_delta) { +static bool _upb_Arena_FixupRefs(upb_ArenaInternal* new_root, + uintptr_t ref_delta) { if (ref_delta == 0) return true; // No fixup required. uintptr_t poc = upb_Atomic_Load(&new_root->parent_or_count, memory_order_relaxed); @@ -379,28 +431,33 @@ static bool _upb_Arena_FixupRefs(upb_Arena* new_root, uintptr_t ref_delta) { bool upb_Arena_Fuse(upb_Arena* a1, upb_Arena* a2) { if (a1 == a2) return true; // trivial fuse + upb_ArenaInternal* ai1 = upb_Arena_Internal(a1); + upb_ArenaInternal* ai2 = upb_Arena_Internal(a2); + // Do not fuse initial blocks since we cannot lifetime extend them. // Any other fuse scenario is allowed. - if (_upb_Arena_HasInitialBlock(a1) || _upb_Arena_HasInitialBlock(a2)) { + if (_upb_ArenaInternal_HasInitialBlock(ai1) || + _upb_ArenaInternal_HasInitialBlock(ai2)) { return false; } // The number of refs we ultimately need to transfer to the new root. uintptr_t ref_delta = 0; while (true) { - upb_Arena* new_root = _upb_Arena_DoFuse(a1, a2, &ref_delta); + upb_ArenaInternal* new_root = _upb_Arena_DoFuse(a1, a2, &ref_delta); if (new_root != NULL && _upb_Arena_FixupRefs(new_root, ref_delta)) { return true; } } } -bool upb_Arena_IncRefFor(upb_Arena* arena, const void* owner) { +bool upb_Arena_IncRefFor(upb_Arena* a, const void* owner) { + upb_ArenaInternal* ai = upb_Arena_Internal(a); + if (_upb_ArenaInternal_HasInitialBlock(ai)) return false; upb_ArenaRoot r; - if (_upb_Arena_HasInitialBlock(arena)) return false; retry: - r = _upb_Arena_FindRoot(arena); + r = _upb_Arena_FindRoot(a); if (upb_Atomic_CompareExchangeWeak( &r.root->parent_or_count, &r.tagged_count, _upb_Arena_TaggedFromRefcount( @@ -413,6 +470,23 @@ bool upb_Arena_IncRefFor(upb_Arena* arena, const void* owner) { goto retry; } -void upb_Arena_DecRefFor(upb_Arena* arena, const void* owner) { - upb_Arena_Free(arena); +void upb_Arena_DecRefFor(upb_Arena* a, const void* owner) { upb_Arena_Free(a); } + +void UPB_PRIVATE(_upb_Arena_SwapIn)(upb_Arena* des, const upb_Arena* src) { + upb_ArenaInternal* desi = upb_Arena_Internal(des); + upb_ArenaInternal* srci = upb_Arena_Internal(src); + + *des = *src; + desi->block_alloc = srci->block_alloc; + upb_MemBlock* blocks = upb_Atomic_Load(&srci->blocks, memory_order_relaxed); + upb_Atomic_Init(&desi->blocks, blocks); +} + +void UPB_PRIVATE(_upb_Arena_SwapOut)(upb_Arena* des, const upb_Arena* src) { + upb_ArenaInternal* desi = upb_Arena_Internal(des); + upb_ArenaInternal* srci = upb_Arena_Internal(src); + + *des = *src; + upb_MemBlock* blocks = upb_Atomic_Load(&srci->blocks, memory_order_relaxed); + upb_Atomic_Store(&desi->blocks, blocks, memory_order_relaxed); } diff --git a/upb/mem/arena.h b/upb/mem/arena.h index 1e1f87f1630c8..385b14e5bfa23 100644 --- a/upb/mem/arena.h +++ b/upb/mem/arena.h @@ -22,22 +22,15 @@ #include #include -#include #include "upb/mem/alloc.h" +#include "upb/mem/internal/arena.h" // Must be last. #include "upb/port/def.inc" typedef struct upb_Arena upb_Arena; -// LINT.IfChange(struct_definition) -typedef struct { - char* UPB_ONLYBITS(ptr); - char* UPB_ONLYBITS(end); -} _upb_ArenaHead; -// LINT.ThenChange(//depot/google3/third_party/upb/bits/typescript/arena.ts) - #ifdef __cplusplus extern "C" { #endif @@ -53,33 +46,20 @@ UPB_API bool upb_Arena_Fuse(upb_Arena* a, upb_Arena* b); bool upb_Arena_IncRefFor(upb_Arena* a, const void* owner); void upb_Arena_DecRefFor(upb_Arena* a, const void* owner); -void* UPB_PRIVATE(_upb_Arena_SlowMalloc)(upb_Arena* a, size_t size); - size_t upb_Arena_SpaceAllocated(upb_Arena* a); uint32_t upb_Arena_DebugRefCount(upb_Arena* a); -UPB_INLINE size_t UPB_PRIVATE(_upb_ArenaHas)(upb_Arena* a) { - const _upb_ArenaHead* h = (_upb_ArenaHead*)a; - return (size_t)(h->UPB_ONLYBITS(end) - h->UPB_ONLYBITS(ptr)); +UPB_API_INLINE upb_Arena* upb_Arena_New(void) { + return upb_Arena_Init(NULL, 0, &upb_alloc_global); } -UPB_API_INLINE void* upb_Arena_Malloc(upb_Arena* a, size_t size) { - size = UPB_ALIGN_MALLOC(size); - const size_t span = size + UPB_ASAN_GUARD_SIZE; - if (UPB_UNLIKELY(UPB_PRIVATE(_upb_ArenaHas)(a) < span)) { - return UPB_PRIVATE(_upb_Arena_SlowMalloc)(a, span); - } - - // We have enough space to do a fast malloc. - _upb_ArenaHead* h = (_upb_ArenaHead*)a; - void* ret = h->UPB_ONLYBITS(ptr); - UPB_ASSERT(UPB_ALIGN_MALLOC((uintptr_t)ret) == (uintptr_t)ret); - UPB_ASSERT(UPB_ALIGN_MALLOC(size) == size); - UPB_UNPOISON_MEMORY_REGION(ret, size); - - h->UPB_ONLYBITS(ptr) += span; +UPB_API_INLINE void* upb_Arena_Malloc(struct upb_Arena* a, size_t size) { + return UPB_PRIVATE(_upb_Arena_Malloc)(a, size); +} - return ret; +UPB_API_INLINE void* upb_Arena_Realloc(upb_Arena* a, void* ptr, size_t oldsize, + size_t size) { + return UPB_PRIVATE(_upb_Arena_Realloc)(a, ptr, oldsize, size); } // Shrinks the last alloc from arena. @@ -88,45 +68,7 @@ UPB_API_INLINE void* upb_Arena_Malloc(upb_Arena* a, size_t size) { // this was not the last alloc. UPB_API_INLINE void upb_Arena_ShrinkLast(upb_Arena* a, void* ptr, size_t oldsize, size_t size) { - _upb_ArenaHead* h = (_upb_ArenaHead*)a; - oldsize = UPB_ALIGN_MALLOC(oldsize); - size = UPB_ALIGN_MALLOC(size); - // Must be the last alloc. - UPB_ASSERT((char*)ptr + oldsize == - h->UPB_ONLYBITS(ptr) - UPB_ASAN_GUARD_SIZE); - UPB_ASSERT(size <= oldsize); - h->UPB_ONLYBITS(ptr) = (char*)ptr + size; -} - -UPB_API_INLINE void* upb_Arena_Realloc(upb_Arena* a, void* ptr, size_t oldsize, - size_t size) { - _upb_ArenaHead* h = (_upb_ArenaHead*)a; - oldsize = UPB_ALIGN_MALLOC(oldsize); - size = UPB_ALIGN_MALLOC(size); - bool is_most_recent_alloc = - (uintptr_t)ptr + oldsize == (uintptr_t)h->UPB_ONLYBITS(ptr); - - if (is_most_recent_alloc) { - ptrdiff_t diff = size - oldsize; - if ((ptrdiff_t)UPB_PRIVATE(_upb_ArenaHas)(a) >= diff) { - h->UPB_ONLYBITS(ptr) += diff; - return ptr; - } - } else if (size <= oldsize) { - return ptr; - } - - void* ret = upb_Arena_Malloc(a, size); - - if (ret && oldsize > 0) { - memcpy(ret, ptr, UPB_MIN(oldsize, size)); - } - - return ret; -} - -UPB_API_INLINE upb_Arena* upb_Arena_New(void) { - return upb_Arena_Init(NULL, 0, &upb_alloc_global); + return UPB_PRIVATE(_upb_Arena_ShrinkLast)(a, ptr, oldsize, size); } #ifdef __cplusplus diff --git a/upb/mem/internal/arena.h b/upb/mem/internal/arena.h index 168957382c5df..421988e63fdd9 100644 --- a/upb/mem/internal/arena.h +++ b/upb/mem/internal/arena.h @@ -8,43 +8,104 @@ #ifndef UPB_MEM_INTERNAL_ARENA_H_ #define UPB_MEM_INTERNAL_ARENA_H_ -#include "upb/mem/arena.h" +#include +#include +#include // Must be last. #include "upb/port/def.inc" -typedef struct _upb_MemBlock _upb_MemBlock; +// This is QUITE an ugly hack, which specifies the number of pointers needed +// to equal (or exceed) the storage required for one upb_Arena. +// +// We need this because the decoder inlines a upb_Arena for performance but +// the full struct is not visible outside of arena.c. Yes, I know, it's awful. +#define UPB_ARENA_SIZE_HACK 7 + +// LINT.IfChange(upb_Array) -// LINT.IfChange(struct_definition) struct upb_Arena { - _upb_ArenaHead head; + char* UPB_ONLYBITS(ptr); + char* UPB_ONLYBITS(end); +}; - // upb_alloc* together with a low bit which signals if there is an initial - // block. - uintptr_t block_alloc; +// LINT.ThenChange(//depot/google3/third_party/upb/bits/typescript/arena.ts:upb_Array) - // When multiple arenas are fused together, each arena points to a parent - // arena (root points to itself). The root tracks how many live arenas - // reference it. +#ifdef __cplusplus +extern "C" { +#endif - // The low bit is tagged: - // 0: pointer to parent - // 1: count, left shifted by one - UPB_ATOMIC(uintptr_t) parent_or_count; +void UPB_PRIVATE(_upb_Arena_SwapIn)(struct upb_Arena* des, + const struct upb_Arena* src); +void UPB_PRIVATE(_upb_Arena_SwapOut)(struct upb_Arena* des, + const struct upb_Arena* src); - // All nodes that are fused together are in a singly-linked list. - UPB_ATOMIC(upb_Arena*) next; // NULL at end of list. +UPB_INLINE size_t UPB_PRIVATE(_upb_ArenaHas)(const struct upb_Arena* a) { + return (size_t)(a->UPB_ONLYBITS(end) - a->UPB_ONLYBITS(ptr)); +} - // The last element of the linked list. This is present only as an - // optimization, so that we do not have to iterate over all members for every - // fuse. Only significant for an arena root. In other cases it is ignored. - UPB_ATOMIC(upb_Arena*) tail; // == self when no other list members. +UPB_INLINE void* UPB_PRIVATE(_upb_Arena_Malloc)(struct upb_Arena* a, + size_t size) { + void* UPB_PRIVATE(_upb_Arena_SlowMalloc)(struct upb_Arena * a, size_t size); - // Linked list of blocks to free/cleanup. Atomic only for the benefit of - // upb_Arena_SpaceAllocated(). - UPB_ATOMIC(_upb_MemBlock*) blocks; -}; -// LINT.ThenChange(//depot/google3/third_party/upb/bits/typescript/arena.ts) + size = UPB_ALIGN_MALLOC(size); + const size_t span = size + UPB_ASAN_GUARD_SIZE; + if (UPB_UNLIKELY(UPB_PRIVATE(_upb_ArenaHas)(a) < span)) { + return UPB_PRIVATE(_upb_Arena_SlowMalloc)(a, span); + } + + // We have enough space to do a fast malloc. + void* ret = a->UPB_ONLYBITS(ptr); + UPB_ASSERT(UPB_ALIGN_MALLOC((uintptr_t)ret) == (uintptr_t)ret); + UPB_ASSERT(UPB_ALIGN_MALLOC(size) == size); + UPB_UNPOISON_MEMORY_REGION(ret, size); + + a->UPB_ONLYBITS(ptr) += span; + + return ret; +} + +UPB_INLINE void* UPB_PRIVATE(_upb_Arena_Realloc)(struct upb_Arena* a, void* ptr, + size_t oldsize, size_t size) { + oldsize = UPB_ALIGN_MALLOC(oldsize); + size = UPB_ALIGN_MALLOC(size); + bool is_most_recent_alloc = + (uintptr_t)ptr + oldsize == (uintptr_t)a->UPB_ONLYBITS(ptr); + + if (is_most_recent_alloc) { + ptrdiff_t diff = size - oldsize; + if ((ptrdiff_t)UPB_PRIVATE(_upb_ArenaHas)(a) >= diff) { + a->UPB_ONLYBITS(ptr) += diff; + return ptr; + } + } else if (size <= oldsize) { + return ptr; + } + + void* ret = UPB_PRIVATE(_upb_Arena_Malloc)(a, size); + + if (ret && oldsize > 0) { + memcpy(ret, ptr, UPB_MIN(oldsize, size)); + } + + return ret; +} + +UPB_INLINE void UPB_PRIVATE(_upb_Arena_ShrinkLast)(struct upb_Arena* a, + void* ptr, size_t oldsize, + size_t size) { + oldsize = UPB_ALIGN_MALLOC(oldsize); + size = UPB_ALIGN_MALLOC(size); + // Must be the last alloc. + UPB_ASSERT((char*)ptr + oldsize == + a->UPB_ONLYBITS(ptr) - UPB_ASAN_GUARD_SIZE); + UPB_ASSERT(size <= oldsize); + a->UPB_ONLYBITS(ptr) = (char*)ptr + size; +} + +#ifdef __cplusplus +} /* extern "C" */ +#endif #include "upb/port/undef.inc" diff --git a/upb/wire/BUILD b/upb/wire/BUILD index 6115b868fb07e..fab4e540002cf 100644 --- a/upb/wire/BUILD +++ b/upb/wire/BUILD @@ -51,7 +51,6 @@ cc_library( "//upb:base", "//upb:hash", "//upb:mem", - "//upb:mem_internal", "//upb:message", "//upb:message_accessors_internal", "//upb:message_internal", diff --git a/upb/wire/decode.c b/upb/wire/decode.c index f5ad1cfa46cdf..7fd5e084990fd 100644 --- a/upb/wire/decode.c +++ b/upb/wire/decode.c @@ -17,7 +17,6 @@ #include "upb/base/string_view.h" #include "upb/hash/common.h" #include "upb/mem/arena.h" -#include "upb/mem/internal/arena.h" #include "upb/message/array.h" #include "upb/message/internal/accessors.h" #include "upb/message/internal/array.h" @@ -1349,10 +1348,8 @@ static upb_DecodeStatus upb_Decoder_Decode(upb_Decoder* const decoder, UPB_ASSERT(decoder->status != kUpb_DecodeStatus_Ok); } - _upb_MemBlock* blocks = - upb_Atomic_Load(&decoder->arena.blocks, memory_order_relaxed); - arena->head = decoder->arena.head; - upb_Atomic_Store(&arena->blocks, blocks, memory_order_relaxed); + UPB_PRIVATE(_upb_Arena_SwapOut)(arena, &decoder->arena); + return decoder->status; } @@ -1379,10 +1376,7 @@ upb_DecodeStatus upb_Decode(const char* buf, size_t size, void* msg, // done. The temporary arena only needs to be able to handle allocation, // not fuse or free, so it does not need many of the members to be initialized // (particularly parent_or_count). - _upb_MemBlock* blocks = upb_Atomic_Load(&arena->blocks, memory_order_relaxed); - decoder.arena.head = arena->head; - decoder.arena.block_alloc = arena->block_alloc; - upb_Atomic_Init(&decoder.arena.blocks, blocks); + UPB_PRIVATE(_upb_Arena_SwapIn)(&decoder.arena, arena); return upb_Decoder_Decode(&decoder, buf, msg, l, arena); } diff --git a/upb/wire/decode_fast.c b/upb/wire/decode_fast.c index 889bb6432dcd3..4062e2b619c93 100644 --- a/upb/wire/decode_fast.c +++ b/upb/wire/decode_fast.c @@ -662,7 +662,7 @@ UPB_FORCEINLINE static void fastdecode_docopy(upb_Decoder* d, const char* ptr, uint32_t size, int copy, char* data, size_t data_offset, upb_StringView* dst) { - d->arena.head.UPB_PRIVATE(ptr) += copy; + d->arena.UPB_PRIVATE(ptr) += copy; dst->data = data + data_offset; UPB_UNPOISON_MEMORY_REGION(data, copy); memcpy(data, ptr, copy); @@ -694,7 +694,7 @@ static void fastdecode_docopy(upb_Decoder* d, const char* ptr, uint32_t size, ptr += tagbytes + 1; \ dst->size = size; \ \ - buf = d->arena.head.UPB_PRIVATE(ptr); \ + buf = d->arena.UPB_PRIVATE(ptr); \ arena_has = UPB_PRIVATE(_upb_ArenaHas)(&d->arena); \ common_has = UPB_MIN(arena_has, \ upb_EpsCopyInputStream_BytesAvailable(&d->input, ptr)); \ @@ -874,8 +874,8 @@ upb_Message* decode_newmsg_ceil(upb_Decoder* d, const upb_MiniTable* m, if (UPB_LIKELY(msg_ceil_bytes > 0 && UPB_PRIVATE(_upb_ArenaHas)(&d->arena) >= msg_ceil_bytes)) { UPB_ASSERT(size <= (size_t)msg_ceil_bytes); - msg_data = d->arena.head.UPB_PRIVATE(ptr); - d->arena.head.UPB_PRIVATE(ptr) += size; + msg_data = d->arena.UPB_PRIVATE(ptr); + d->arena.UPB_PRIVATE(ptr) += size; UPB_UNPOISON_MEMORY_REGION(msg_data, msg_ceil_bytes); memset(msg_data, 0, msg_ceil_bytes); UPB_POISON_MEMORY_REGION(msg_data + size, msg_ceil_bytes - size); diff --git a/upb/wire/internal/decode.h b/upb/wire/internal/decode.h index f36b2b7e97d37..fcc04cfaa1231 100644 --- a/upb/wire/internal/decode.h +++ b/upb/wire/internal/decode.h @@ -33,7 +33,10 @@ typedef struct upb_Decoder { uint32_t end_group; // field number of END_GROUP tag, else DECODE_NOGROUP. uint16_t options; bool missing_required; - upb_Arena arena; + union { + upb_Arena arena; + void* foo[UPB_ARENA_SIZE_HACK]; + }; upb_DecodeStatus status; jmp_buf err; From f75fe9e5f5e4606c8731d4230937db9fd2db6fa6 Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Tue, 19 Dec 2023 22:41:49 +0000 Subject: [PATCH 061/255] Auto-generate files after cl/592345066 --- php/ext/google/protobuf/php-upb.c | 277 ++++++++++++++++---------- php/ext/google/protobuf/php-upb.h | 192 +++++++++--------- ruby/ext/google/protobuf_c/ruby-upb.c | 277 ++++++++++++++++---------- ruby/ext/google/protobuf_c/ruby-upb.h | 192 +++++++++--------- 4 files changed, 544 insertions(+), 394 deletions(-) diff --git a/php/ext/google/protobuf/php-upb.c b/php/ext/google/protobuf/php-upb.c index b919c5c24fee9..1a4db4a89392f 100644 --- a/php/ext/google/protobuf/php-upb.c +++ b/php/ext/google/protobuf/php-upb.c @@ -5527,21 +5527,61 @@ upb_alloc upb_alloc_global = {&upb_global_allocfunc}; // Must be last. -struct _upb_MemBlock { +typedef struct upb_MemBlock { // Atomic only for the benefit of SpaceAllocated(). - UPB_ATOMIC(_upb_MemBlock*) next; + UPB_ATOMIC(struct upb_MemBlock*) next; uint32_t size; // Data follows. -}; - -static const size_t kUpb_MemblockReserve = - UPB_ALIGN_UP(sizeof(_upb_MemBlock), UPB_MALLOC_ALIGN); +} upb_MemBlock; + +typedef struct upb_ArenaInternal { + // upb_alloc* together with a low bit which signals if there is an initial + // block. + uintptr_t block_alloc; + + // When multiple arenas are fused together, each arena points to a parent + // arena (root points to itself). The root tracks how many live arenas + // reference it. + + // The low bit is tagged: + // 0: pointer to parent + // 1: count, left shifted by one + UPB_ATOMIC(uintptr_t) parent_or_count; + + // All nodes that are fused together are in a singly-linked list. + // == NULL at end of list. + UPB_ATOMIC(struct upb_ArenaInternal*) next; + + // The last element of the linked list. This is present only as an + // optimization, so that we do not have to iterate over all members for every + // fuse. Only significant for an arena root. In other cases it is ignored. + // == self when no other list members. + UPB_ATOMIC(struct upb_ArenaInternal*) tail; + + // Linked list of blocks to free/cleanup. Atomic only for the benefit of + // upb_Arena_SpaceAllocated(). + UPB_ATOMIC(upb_MemBlock*) blocks; +} upb_ArenaInternal; + +// All public + private state for an arena. +typedef struct { + upb_Arena head; + upb_ArenaInternal body; +} upb_ArenaState; typedef struct { - upb_Arena* root; + upb_ArenaInternal* root; uintptr_t tagged_count; } upb_ArenaRoot; +static const size_t kUpb_MemblockReserve = + UPB_ALIGN_UP(sizeof(upb_MemBlock), UPB_MALLOC_ALIGN); + +// Extracts the (upb_ArenaInternal*) from a (upb_Arena*) +static upb_ArenaInternal* upb_Arena_Internal(const upb_Arena* a) { + return &((upb_ArenaState*)a)->body; +} + static bool _upb_Arena_IsTaggedRefcount(uintptr_t parent_or_count) { return (parent_or_count & 1) == 1; } @@ -5561,19 +5601,20 @@ static uintptr_t _upb_Arena_TaggedFromRefcount(uintptr_t refcount) { return parent_or_count; } -static upb_Arena* _upb_Arena_PointerFromTagged(uintptr_t parent_or_count) { +static upb_ArenaInternal* _upb_Arena_PointerFromTagged( + uintptr_t parent_or_count) { UPB_ASSERT(_upb_Arena_IsTaggedPointer(parent_or_count)); - return (upb_Arena*)parent_or_count; + return (upb_ArenaInternal*)parent_or_count; } -static uintptr_t _upb_Arena_TaggedFromPointer(upb_Arena* a) { - uintptr_t parent_or_count = (uintptr_t)a; +static uintptr_t _upb_Arena_TaggedFromPointer(upb_ArenaInternal* ai) { + uintptr_t parent_or_count = (uintptr_t)ai; UPB_ASSERT(_upb_Arena_IsTaggedPointer(parent_or_count)); return parent_or_count; } -static upb_alloc* _upb_Arena_BlockAlloc(upb_Arena* arena) { - return (upb_alloc*)(arena->block_alloc & ~0x1); +static upb_alloc* _upb_ArenaInternal_BlockAlloc(upb_ArenaInternal* ai) { + return (upb_alloc*)(ai->block_alloc & ~0x1); } static uintptr_t _upb_Arena_MakeBlockAlloc(upb_alloc* alloc, bool has_initial) { @@ -5582,15 +5623,16 @@ static uintptr_t _upb_Arena_MakeBlockAlloc(upb_alloc* alloc, bool has_initial) { return alloc_uint | (has_initial ? 1 : 0); } -static bool _upb_Arena_HasInitialBlock(upb_Arena* arena) { - return arena->block_alloc & 0x1; +static bool _upb_ArenaInternal_HasInitialBlock(upb_ArenaInternal* ai) { + return ai->block_alloc & 0x1; } static upb_ArenaRoot _upb_Arena_FindRoot(upb_Arena* a) { - uintptr_t poc = upb_Atomic_Load(&a->parent_or_count, memory_order_acquire); + upb_ArenaInternal* ai = upb_Arena_Internal(a); + uintptr_t poc = upb_Atomic_Load(&ai->parent_or_count, memory_order_acquire); while (_upb_Arena_IsTaggedPointer(poc)) { - upb_Arena* next = _upb_Arena_PointerFromTagged(poc); - UPB_ASSERT(a != next); + upb_ArenaInternal* next = _upb_Arena_PointerFromTagged(poc); + UPB_ASSERT(ai != next); uintptr_t next_poc = upb_Atomic_Load(&next->parent_or_count, memory_order_acquire); @@ -5614,64 +5656,67 @@ static upb_ArenaRoot _upb_Arena_FindRoot(upb_Arena* a) { // further away over time, but the path towards that root will continue to // be valid and the creation of the path carries all the memory orderings // required. - UPB_ASSERT(a != _upb_Arena_PointerFromTagged(next_poc)); - upb_Atomic_Store(&a->parent_or_count, next_poc, memory_order_relaxed); + UPB_ASSERT(ai != _upb_Arena_PointerFromTagged(next_poc)); + upb_Atomic_Store(&ai->parent_or_count, next_poc, memory_order_relaxed); } - a = next; + ai = next; poc = next_poc; } - return (upb_ArenaRoot){.root = a, .tagged_count = poc}; + return (upb_ArenaRoot){.root = ai, .tagged_count = poc}; } size_t upb_Arena_SpaceAllocated(upb_Arena* arena) { - arena = _upb_Arena_FindRoot(arena).root; + upb_ArenaInternal* ai = _upb_Arena_FindRoot(arena).root; size_t memsize = 0; - while (arena != NULL) { - _upb_MemBlock* block = - upb_Atomic_Load(&arena->blocks, memory_order_relaxed); + while (ai != NULL) { + upb_MemBlock* block = upb_Atomic_Load(&ai->blocks, memory_order_relaxed); while (block != NULL) { - memsize += sizeof(_upb_MemBlock) + block->size; + memsize += sizeof(upb_MemBlock) + block->size; block = upb_Atomic_Load(&block->next, memory_order_relaxed); } - arena = upb_Atomic_Load(&arena->next, memory_order_relaxed); + ai = upb_Atomic_Load(&ai->next, memory_order_relaxed); } return memsize; } uint32_t upb_Arena_DebugRefCount(upb_Arena* a) { + upb_ArenaInternal* ai = upb_Arena_Internal(a); // These loads could probably be relaxed, but given that this is debug-only, // it's not worth introducing a new variant for it. - uintptr_t poc = upb_Atomic_Load(&a->parent_or_count, memory_order_acquire); + uintptr_t poc = upb_Atomic_Load(&ai->parent_or_count, memory_order_acquire); while (_upb_Arena_IsTaggedPointer(poc)) { - a = _upb_Arena_PointerFromTagged(poc); - poc = upb_Atomic_Load(&a->parent_or_count, memory_order_acquire); + ai = _upb_Arena_PointerFromTagged(poc); + poc = upb_Atomic_Load(&ai->parent_or_count, memory_order_acquire); } return _upb_Arena_RefCountFromTagged(poc); } static void _upb_Arena_AddBlock(upb_Arena* a, void* ptr, size_t size) { - _upb_MemBlock* block = ptr; + upb_ArenaInternal* ai = upb_Arena_Internal(a); + upb_MemBlock* block = ptr; // Insert into linked list. block->size = (uint32_t)size; - upb_Atomic_Init(&block->next, a->blocks); - upb_Atomic_Store(&a->blocks, block, memory_order_release); + upb_Atomic_Init(&block->next, ai->blocks); + upb_Atomic_Store(&ai->blocks, block, memory_order_release); - a->head.UPB_PRIVATE(ptr) = UPB_PTR_AT(block, kUpb_MemblockReserve, char); - a->head.UPB_PRIVATE(end) = UPB_PTR_AT(block, size, char); + a->UPB_PRIVATE(ptr) = UPB_PTR_AT(block, kUpb_MemblockReserve, char); + a->UPB_PRIVATE(end) = UPB_PTR_AT(block, size, char); - UPB_POISON_MEMORY_REGION(a->head.UPB_PRIVATE(ptr), - a->head.UPB_PRIVATE(end) - a->head.UPB_PRIVATE(ptr)); + UPB_POISON_MEMORY_REGION(a->UPB_PRIVATE(ptr), + a->UPB_PRIVATE(end) - a->UPB_PRIVATE(ptr)); } static bool _upb_Arena_AllocBlock(upb_Arena* a, size_t size) { - if (!a->block_alloc) return false; - _upb_MemBlock* last_block = upb_Atomic_Load(&a->blocks, memory_order_acquire); + upb_ArenaInternal* ai = upb_Arena_Internal(a); + if (!ai->block_alloc) return false; + upb_MemBlock* last_block = upb_Atomic_Load(&ai->blocks, memory_order_acquire); size_t last_size = last_block != NULL ? last_block->size : 128; size_t block_size = UPB_MAX(size, last_size * 2) + kUpb_MemblockReserve; - _upb_MemBlock* block = upb_malloc(_upb_Arena_BlockAlloc(a), block_size); + upb_MemBlock* block = + upb_malloc(_upb_ArenaInternal_BlockAlloc(ai), block_size); if (!block) return false; _upb_Arena_AddBlock(a, block, block_size); @@ -5685,8 +5730,9 @@ void* UPB_PRIVATE(_upb_Arena_SlowMalloc)(upb_Arena* a, size_t size) { } static upb_Arena* _upb_Arena_InitSlow(upb_alloc* alloc) { - const size_t first_block_overhead = sizeof(upb_Arena) + kUpb_MemblockReserve; - upb_Arena* a; + const size_t first_block_overhead = + sizeof(upb_ArenaState) + kUpb_MemblockReserve; + upb_ArenaState* a; // We need to malloc the initial block. char* mem; @@ -5695,22 +5741,23 @@ static upb_Arena* _upb_Arena_InitSlow(upb_alloc* alloc) { return NULL; } - a = UPB_PTR_AT(mem, n - sizeof(*a), upb_Arena); - n -= sizeof(*a); + a = UPB_PTR_AT(mem, n - sizeof(upb_ArenaState), upb_ArenaState); + n -= sizeof(upb_ArenaState); - a->block_alloc = _upb_Arena_MakeBlockAlloc(alloc, 0); - upb_Atomic_Init(&a->parent_or_count, _upb_Arena_TaggedFromRefcount(1)); - upb_Atomic_Init(&a->next, NULL); - upb_Atomic_Init(&a->tail, a); - upb_Atomic_Init(&a->blocks, NULL); + a->body.block_alloc = _upb_Arena_MakeBlockAlloc(alloc, 0); + upb_Atomic_Init(&a->body.parent_or_count, _upb_Arena_TaggedFromRefcount(1)); + upb_Atomic_Init(&a->body.next, NULL); + upb_Atomic_Init(&a->body.tail, &a->body); + upb_Atomic_Init(&a->body.blocks, NULL); - _upb_Arena_AddBlock(a, mem, n); + _upb_Arena_AddBlock(&a->head, mem, n); - return a; + return &a->head; } upb_Arena* upb_Arena_Init(void* mem, size_t n, upb_alloc* alloc) { - upb_Arena* a; + UPB_ASSERT(sizeof(void*) * UPB_ARENA_SIZE_HACK >= sizeof(upb_ArenaState)); + upb_ArenaState* a; if (n) { /* Align initial pointer up so that we return properly-aligned pointers. */ @@ -5722,63 +5769,65 @@ upb_Arena* upb_Arena_Init(void* mem, size_t n, upb_alloc* alloc) { /* Round block size down to alignof(*a) since we will allocate the arena * itself at the end. */ - n = UPB_ALIGN_DOWN(n, UPB_ALIGN_OF(upb_Arena)); + n = UPB_ALIGN_DOWN(n, UPB_ALIGN_OF(upb_ArenaState)); - if (UPB_UNLIKELY(n < sizeof(upb_Arena))) { + if (UPB_UNLIKELY(n < sizeof(upb_ArenaState))) { return _upb_Arena_InitSlow(alloc); } - a = UPB_PTR_AT(mem, n - sizeof(*a), upb_Arena); + a = UPB_PTR_AT(mem, n - sizeof(upb_ArenaState), upb_ArenaState); + + upb_Atomic_Init(&a->body.parent_or_count, _upb_Arena_TaggedFromRefcount(1)); + upb_Atomic_Init(&a->body.next, NULL); + upb_Atomic_Init(&a->body.tail, &a->body); + upb_Atomic_Init(&a->body.blocks, NULL); - upb_Atomic_Init(&a->parent_or_count, _upb_Arena_TaggedFromRefcount(1)); - upb_Atomic_Init(&a->next, NULL); - upb_Atomic_Init(&a->tail, a); - upb_Atomic_Init(&a->blocks, NULL); - a->block_alloc = _upb_Arena_MakeBlockAlloc(alloc, 1); + a->body.block_alloc = _upb_Arena_MakeBlockAlloc(alloc, 1); a->head.UPB_PRIVATE(ptr) = mem; - a->head.UPB_PRIVATE(end) = UPB_PTR_AT(mem, n - sizeof(*a), char); + a->head.UPB_PRIVATE(end) = UPB_PTR_AT(mem, n - sizeof(upb_ArenaState), char); - return a; + return &a->head; } -static void _upb_Arena_DoFree(upb_Arena* a) { - UPB_ASSERT(_upb_Arena_RefCountFromTagged(a->parent_or_count) == 1); +static void _upb_Arena_DoFree(upb_ArenaInternal* ai) { + UPB_ASSERT(_upb_Arena_RefCountFromTagged(ai->parent_or_count) == 1); - while (a != NULL) { + while (ai != NULL) { // Load first since arena itself is likely from one of its blocks. - upb_Arena* next_arena = - (upb_Arena*)upb_Atomic_Load(&a->next, memory_order_acquire); - upb_alloc* block_alloc = _upb_Arena_BlockAlloc(a); - _upb_MemBlock* block = upb_Atomic_Load(&a->blocks, memory_order_acquire); + upb_ArenaInternal* next_arena = + (upb_ArenaInternal*)upb_Atomic_Load(&ai->next, memory_order_acquire); + upb_alloc* block_alloc = _upb_ArenaInternal_BlockAlloc(ai); + upb_MemBlock* block = upb_Atomic_Load(&ai->blocks, memory_order_acquire); while (block != NULL) { // Load first since we are deleting block. - _upb_MemBlock* next_block = + upb_MemBlock* next_block = upb_Atomic_Load(&block->next, memory_order_acquire); upb_free(block_alloc, block); block = next_block; } - a = next_arena; + ai = next_arena; } } void upb_Arena_Free(upb_Arena* a) { - uintptr_t poc = upb_Atomic_Load(&a->parent_or_count, memory_order_acquire); + upb_ArenaInternal* ai = upb_Arena_Internal(a); + uintptr_t poc = upb_Atomic_Load(&ai->parent_or_count, memory_order_acquire); retry: while (_upb_Arena_IsTaggedPointer(poc)) { - a = _upb_Arena_PointerFromTagged(poc); - poc = upb_Atomic_Load(&a->parent_or_count, memory_order_acquire); + ai = _upb_Arena_PointerFromTagged(poc); + poc = upb_Atomic_Load(&ai->parent_or_count, memory_order_acquire); } // compare_exchange or fetch_sub are RMW operations, which are more // expensive then direct loads. As an optimization, we only do RMW ops // when we need to update things for other threads to see. if (poc == _upb_Arena_TaggedFromRefcount(1)) { - _upb_Arena_DoFree(a); + _upb_Arena_DoFree(ai); return; } if (upb_Atomic_CompareExchangeWeak( - &a->parent_or_count, &poc, + &ai->parent_or_count, &poc, _upb_Arena_TaggedFromRefcount(_upb_Arena_RefCountFromTagged(poc) - 1), memory_order_release, memory_order_acquire)) { // We were >1 and we decremented it successfully, so we are done. @@ -5790,12 +5839,14 @@ void upb_Arena_Free(upb_Arena* a) { goto retry; } -static void _upb_Arena_DoFuseArenaLists(upb_Arena* const parent, - upb_Arena* child) { - upb_Arena* parent_tail = upb_Atomic_Load(&parent->tail, memory_order_relaxed); +static void _upb_Arena_DoFuseArenaLists(upb_ArenaInternal* const parent, + upb_ArenaInternal* child) { + upb_ArenaInternal* parent_tail = + upb_Atomic_Load(&parent->tail, memory_order_relaxed); + do { // Our tail might be stale, but it will always converge to the true tail. - upb_Arena* parent_tail_next = + upb_ArenaInternal* parent_tail_next = upb_Atomic_Load(&parent_tail->next, memory_order_relaxed); while (parent_tail_next != NULL) { parent_tail = parent_tail_next; @@ -5803,7 +5854,7 @@ static void _upb_Arena_DoFuseArenaLists(upb_Arena* const parent, upb_Atomic_Load(&parent_tail->next, memory_order_relaxed); } - upb_Arena* displaced = + upb_ArenaInternal* displaced = upb_Atomic_Exchange(&parent_tail->next, child, memory_order_relaxed); parent_tail = upb_Atomic_Load(&child->tail, memory_order_relaxed); @@ -5815,8 +5866,8 @@ static void _upb_Arena_DoFuseArenaLists(upb_Arena* const parent, upb_Atomic_Store(&parent->tail, parent_tail, memory_order_relaxed); } -static upb_Arena* _upb_Arena_DoFuse(upb_Arena* a1, upb_Arena* a2, - uintptr_t* ref_delta) { +static upb_ArenaInternal* _upb_Arena_DoFuse(upb_Arena* a1, upb_Arena* a2, + uintptr_t* ref_delta) { // `parent_or_count` has two disctint modes // - parent pointer mode // - refcount mode @@ -5874,7 +5925,8 @@ static upb_Arena* _upb_Arena_DoFuse(upb_Arena* a1, upb_Arena* a2, return r1.root; } -static bool _upb_Arena_FixupRefs(upb_Arena* new_root, uintptr_t ref_delta) { +static bool _upb_Arena_FixupRefs(upb_ArenaInternal* new_root, + uintptr_t ref_delta) { if (ref_delta == 0) return true; // No fixup required. uintptr_t poc = upb_Atomic_Load(&new_root->parent_or_count, memory_order_relaxed); @@ -5889,28 +5941,33 @@ static bool _upb_Arena_FixupRefs(upb_Arena* new_root, uintptr_t ref_delta) { bool upb_Arena_Fuse(upb_Arena* a1, upb_Arena* a2) { if (a1 == a2) return true; // trivial fuse + upb_ArenaInternal* ai1 = upb_Arena_Internal(a1); + upb_ArenaInternal* ai2 = upb_Arena_Internal(a2); + // Do not fuse initial blocks since we cannot lifetime extend them. // Any other fuse scenario is allowed. - if (_upb_Arena_HasInitialBlock(a1) || _upb_Arena_HasInitialBlock(a2)) { + if (_upb_ArenaInternal_HasInitialBlock(ai1) || + _upb_ArenaInternal_HasInitialBlock(ai2)) { return false; } // The number of refs we ultimately need to transfer to the new root. uintptr_t ref_delta = 0; while (true) { - upb_Arena* new_root = _upb_Arena_DoFuse(a1, a2, &ref_delta); + upb_ArenaInternal* new_root = _upb_Arena_DoFuse(a1, a2, &ref_delta); if (new_root != NULL && _upb_Arena_FixupRefs(new_root, ref_delta)) { return true; } } } -bool upb_Arena_IncRefFor(upb_Arena* arena, const void* owner) { +bool upb_Arena_IncRefFor(upb_Arena* a, const void* owner) { + upb_ArenaInternal* ai = upb_Arena_Internal(a); + if (_upb_ArenaInternal_HasInitialBlock(ai)) return false; upb_ArenaRoot r; - if (_upb_Arena_HasInitialBlock(arena)) return false; retry: - r = _upb_Arena_FindRoot(arena); + r = _upb_Arena_FindRoot(a); if (upb_Atomic_CompareExchangeWeak( &r.root->parent_or_count, &r.tagged_count, _upb_Arena_TaggedFromRefcount( @@ -5923,8 +5980,25 @@ bool upb_Arena_IncRefFor(upb_Arena* arena, const void* owner) { goto retry; } -void upb_Arena_DecRefFor(upb_Arena* arena, const void* owner) { - upb_Arena_Free(arena); +void upb_Arena_DecRefFor(upb_Arena* a, const void* owner) { upb_Arena_Free(a); } + +void UPB_PRIVATE(_upb_Arena_SwapIn)(upb_Arena* des, const upb_Arena* src) { + upb_ArenaInternal* desi = upb_Arena_Internal(des); + upb_ArenaInternal* srci = upb_Arena_Internal(src); + + *des = *src; + desi->block_alloc = srci->block_alloc; + upb_MemBlock* blocks = upb_Atomic_Load(&srci->blocks, memory_order_relaxed); + upb_Atomic_Init(&desi->blocks, blocks); +} + +void UPB_PRIVATE(_upb_Arena_SwapOut)(upb_Arena* des, const upb_Arena* src) { + upb_ArenaInternal* desi = upb_Arena_Internal(des); + upb_ArenaInternal* srci = upb_Arena_Internal(src); + + *des = *src; + upb_MemBlock* blocks = upb_Atomic_Load(&srci->blocks, memory_order_relaxed); + upb_Atomic_Store(&desi->blocks, blocks, memory_order_relaxed); } @@ -14027,10 +14101,8 @@ static upb_DecodeStatus upb_Decoder_Decode(upb_Decoder* const decoder, UPB_ASSERT(decoder->status != kUpb_DecodeStatus_Ok); } - _upb_MemBlock* blocks = - upb_Atomic_Load(&decoder->arena.blocks, memory_order_relaxed); - arena->head = decoder->arena.head; - upb_Atomic_Store(&arena->blocks, blocks, memory_order_relaxed); + UPB_PRIVATE(_upb_Arena_SwapOut)(arena, &decoder->arena); + return decoder->status; } @@ -14057,10 +14129,7 @@ upb_DecodeStatus upb_Decode(const char* buf, size_t size, void* msg, // done. The temporary arena only needs to be able to handle allocation, // not fuse or free, so it does not need many of the members to be initialized // (particularly parent_or_count). - _upb_MemBlock* blocks = upb_Atomic_Load(&arena->blocks, memory_order_relaxed); - decoder.arena.head = arena->head; - decoder.arena.block_alloc = arena->block_alloc; - upb_Atomic_Init(&decoder.arena.blocks, blocks); + UPB_PRIVATE(_upb_Arena_SwapIn)(&decoder.arena, arena); return upb_Decoder_Decode(&decoder, buf, msg, l, arena); } @@ -14718,7 +14787,7 @@ UPB_FORCEINLINE static void fastdecode_docopy(upb_Decoder* d, const char* ptr, uint32_t size, int copy, char* data, size_t data_offset, upb_StringView* dst) { - d->arena.head.UPB_PRIVATE(ptr) += copy; + d->arena.UPB_PRIVATE(ptr) += copy; dst->data = data + data_offset; UPB_UNPOISON_MEMORY_REGION(data, copy); memcpy(data, ptr, copy); @@ -14750,7 +14819,7 @@ static void fastdecode_docopy(upb_Decoder* d, const char* ptr, uint32_t size, ptr += tagbytes + 1; \ dst->size = size; \ \ - buf = d->arena.head.UPB_PRIVATE(ptr); \ + buf = d->arena.UPB_PRIVATE(ptr); \ arena_has = UPB_PRIVATE(_upb_ArenaHas)(&d->arena); \ common_has = UPB_MIN(arena_has, \ upb_EpsCopyInputStream_BytesAvailable(&d->input, ptr)); \ @@ -14930,8 +14999,8 @@ upb_Message* decode_newmsg_ceil(upb_Decoder* d, const upb_MiniTable* m, if (UPB_LIKELY(msg_ceil_bytes > 0 && UPB_PRIVATE(_upb_ArenaHas)(&d->arena) >= msg_ceil_bytes)) { UPB_ASSERT(size <= (size_t)msg_ceil_bytes); - msg_data = d->arena.head.UPB_PRIVATE(ptr); - d->arena.head.UPB_PRIVATE(ptr) += size; + msg_data = d->arena.UPB_PRIVATE(ptr); + d->arena.UPB_PRIVATE(ptr) += size; UPB_UNPOISON_MEMORY_REGION(msg_data, msg_ceil_bytes); memset(msg_data, 0, msg_ceil_bytes); UPB_POISON_MEMORY_REGION(msg_data + size, msg_ceil_bytes - size); diff --git a/php/ext/google/protobuf/php-upb.h b/php/ext/google/protobuf/php-upb.h index 70a48ae1045f4..0df6c4fd9c4e3 100644 --- a/php/ext/google/protobuf/php-upb.h +++ b/php/ext/google/protobuf/php-upb.h @@ -555,7 +555,6 @@ UPB_INLINE bool upb_StringView_IsEqual(upb_StringView a, upb_StringView b) { #include #include -#include #ifndef UPB_MEM_ALLOC_H_ @@ -628,43 +627,48 @@ UPB_INLINE void upb_gfree(void* ptr) { upb_free(&upb_alloc_global, ptr); } #endif /* UPB_MEM_ALLOC_H_ */ +#ifndef UPB_MEM_INTERNAL_ARENA_H_ +#define UPB_MEM_INTERNAL_ARENA_H_ + +#include +#include +#include + // Must be last. -typedef struct upb_Arena upb_Arena; +// This is QUITE an ugly hack, which specifies the number of pointers needed +// to equal (or exceed) the storage required for one upb_Arena. +// +// We need this because the decoder inlines a upb_Arena for performance but +// the full struct is not visible outside of arena.c. Yes, I know, it's awful. +#define UPB_ARENA_SIZE_HACK 7 -// LINT.IfChange(struct_definition) -typedef struct { +// LINT.IfChange(upb_Array) + +struct upb_Arena { char* UPB_ONLYBITS(ptr); char* UPB_ONLYBITS(end); -} _upb_ArenaHead; -// LINT.ThenChange(//depot/google3/third_party/upb/bits/typescript/arena.ts) +}; + +// LINT.ThenChange(//depot/google3/third_party/upb/bits/typescript/arena.ts:upb_Array) #ifdef __cplusplus extern "C" { #endif -// Creates an arena from the given initial block (if any -- n may be 0). -// Additional blocks will be allocated from |alloc|. If |alloc| is NULL, this -// is a fixed-size arena and cannot grow. -UPB_API upb_Arena* upb_Arena_Init(void* mem, size_t n, upb_alloc* alloc); - -UPB_API void upb_Arena_Free(upb_Arena* a); -UPB_API bool upb_Arena_Fuse(upb_Arena* a, upb_Arena* b); - -bool upb_Arena_IncRefFor(upb_Arena* a, const void* owner); -void upb_Arena_DecRefFor(upb_Arena* a, const void* owner); - -void* UPB_PRIVATE(_upb_Arena_SlowMalloc)(upb_Arena* a, size_t size); - -size_t upb_Arena_SpaceAllocated(upb_Arena* a); -uint32_t upb_Arena_DebugRefCount(upb_Arena* a); +void UPB_PRIVATE(_upb_Arena_SwapIn)(struct upb_Arena* des, + const struct upb_Arena* src); +void UPB_PRIVATE(_upb_Arena_SwapOut)(struct upb_Arena* des, + const struct upb_Arena* src); -UPB_INLINE size_t UPB_PRIVATE(_upb_ArenaHas)(upb_Arena* a) { - const _upb_ArenaHead* h = (_upb_ArenaHead*)a; - return (size_t)(h->UPB_ONLYBITS(end) - h->UPB_ONLYBITS(ptr)); +UPB_INLINE size_t UPB_PRIVATE(_upb_ArenaHas)(const struct upb_Arena* a) { + return (size_t)(a->UPB_ONLYBITS(end) - a->UPB_ONLYBITS(ptr)); } -UPB_API_INLINE void* upb_Arena_Malloc(upb_Arena* a, size_t size) { +UPB_INLINE void* UPB_PRIVATE(_upb_Arena_Malloc)(struct upb_Arena* a, + size_t size) { + void* UPB_PRIVATE(_upb_Arena_SlowMalloc)(struct upb_Arena * a, size_t size); + size = UPB_ALIGN_MALLOC(size); const size_t span = size + UPB_ASAN_GUARD_SIZE; if (UPB_UNLIKELY(UPB_PRIVATE(_upb_ArenaHas)(a) < span)) { @@ -672,52 +676,34 @@ UPB_API_INLINE void* upb_Arena_Malloc(upb_Arena* a, size_t size) { } // We have enough space to do a fast malloc. - _upb_ArenaHead* h = (_upb_ArenaHead*)a; - void* ret = h->UPB_ONLYBITS(ptr); + void* ret = a->UPB_ONLYBITS(ptr); UPB_ASSERT(UPB_ALIGN_MALLOC((uintptr_t)ret) == (uintptr_t)ret); UPB_ASSERT(UPB_ALIGN_MALLOC(size) == size); UPB_UNPOISON_MEMORY_REGION(ret, size); - h->UPB_ONLYBITS(ptr) += span; + a->UPB_ONLYBITS(ptr) += span; return ret; } -// Shrinks the last alloc from arena. -// REQUIRES: (ptr, oldsize) was the last malloc/realloc from this arena. -// We could also add a upb_Arena_TryShrinkLast() which is simply a no-op if -// this was not the last alloc. -UPB_API_INLINE void upb_Arena_ShrinkLast(upb_Arena* a, void* ptr, - size_t oldsize, size_t size) { - _upb_ArenaHead* h = (_upb_ArenaHead*)a; - oldsize = UPB_ALIGN_MALLOC(oldsize); - size = UPB_ALIGN_MALLOC(size); - // Must be the last alloc. - UPB_ASSERT((char*)ptr + oldsize == - h->UPB_ONLYBITS(ptr) - UPB_ASAN_GUARD_SIZE); - UPB_ASSERT(size <= oldsize); - h->UPB_ONLYBITS(ptr) = (char*)ptr + size; -} - -UPB_API_INLINE void* upb_Arena_Realloc(upb_Arena* a, void* ptr, size_t oldsize, - size_t size) { - _upb_ArenaHead* h = (_upb_ArenaHead*)a; +UPB_INLINE void* UPB_PRIVATE(_upb_Arena_Realloc)(struct upb_Arena* a, void* ptr, + size_t oldsize, size_t size) { oldsize = UPB_ALIGN_MALLOC(oldsize); size = UPB_ALIGN_MALLOC(size); bool is_most_recent_alloc = - (uintptr_t)ptr + oldsize == (uintptr_t)h->UPB_ONLYBITS(ptr); + (uintptr_t)ptr + oldsize == (uintptr_t)a->UPB_ONLYBITS(ptr); if (is_most_recent_alloc) { ptrdiff_t diff = size - oldsize; if ((ptrdiff_t)UPB_PRIVATE(_upb_ArenaHas)(a) >= diff) { - h->UPB_ONLYBITS(ptr) += diff; + a->UPB_ONLYBITS(ptr) += diff; return ptr; } } else if (size <= oldsize) { return ptr; } - void* ret = upb_Arena_Malloc(a, size); + void* ret = UPB_PRIVATE(_upb_Arena_Malloc)(a, size); if (ret && oldsize > 0) { memcpy(ret, ptr, UPB_MIN(oldsize, size)); @@ -726,10 +712,69 @@ UPB_API_INLINE void* upb_Arena_Realloc(upb_Arena* a, void* ptr, size_t oldsize, return ret; } +UPB_INLINE void UPB_PRIVATE(_upb_Arena_ShrinkLast)(struct upb_Arena* a, + void* ptr, size_t oldsize, + size_t size) { + oldsize = UPB_ALIGN_MALLOC(oldsize); + size = UPB_ALIGN_MALLOC(size); + // Must be the last alloc. + UPB_ASSERT((char*)ptr + oldsize == + a->UPB_ONLYBITS(ptr) - UPB_ASAN_GUARD_SIZE); + UPB_ASSERT(size <= oldsize); + a->UPB_ONLYBITS(ptr) = (char*)ptr + size; +} + +#ifdef __cplusplus +} /* extern "C" */ +#endif + + +#endif /* UPB_MEM_INTERNAL_ARENA_H_ */ + +// Must be last. + +typedef struct upb_Arena upb_Arena; + +#ifdef __cplusplus +extern "C" { +#endif + +// Creates an arena from the given initial block (if any -- n may be 0). +// Additional blocks will be allocated from |alloc|. If |alloc| is NULL, this +// is a fixed-size arena and cannot grow. +UPB_API upb_Arena* upb_Arena_Init(void* mem, size_t n, upb_alloc* alloc); + +UPB_API void upb_Arena_Free(upb_Arena* a); +UPB_API bool upb_Arena_Fuse(upb_Arena* a, upb_Arena* b); + +bool upb_Arena_IncRefFor(upb_Arena* a, const void* owner); +void upb_Arena_DecRefFor(upb_Arena* a, const void* owner); + +size_t upb_Arena_SpaceAllocated(upb_Arena* a); +uint32_t upb_Arena_DebugRefCount(upb_Arena* a); + UPB_API_INLINE upb_Arena* upb_Arena_New(void) { return upb_Arena_Init(NULL, 0, &upb_alloc_global); } +UPB_API_INLINE void* upb_Arena_Malloc(struct upb_Arena* a, size_t size) { + return UPB_PRIVATE(_upb_Arena_Malloc)(a, size); +} + +UPB_API_INLINE void* upb_Arena_Realloc(upb_Arena* a, void* ptr, size_t oldsize, + size_t size) { + return UPB_PRIVATE(_upb_Arena_Realloc)(a, ptr, oldsize, size); +} + +// Shrinks the last alloc from arena. +// REQUIRES: (ptr, oldsize) was the last malloc/realloc from this arena. +// We could also add a upb_Arena_TryShrinkLast() which is simply a no-op if +// this was not the last alloc. +UPB_API_INLINE void upb_Arena_ShrinkLast(upb_Arena* a, void* ptr, + size_t oldsize, size_t size) { + return UPB_PRIVATE(_upb_Arena_ShrinkLast)(a, ptr, oldsize, size); +} + #ifdef __cplusplus } /* extern "C" */ #endif @@ -12154,48 +12199,6 @@ double _upb_NoLocaleStrtod(const char *str, char **endptr); #endif /* UPB_LEX_STRTOD_H_ */ -#ifndef UPB_MEM_INTERNAL_ARENA_H_ -#define UPB_MEM_INTERNAL_ARENA_H_ - - -// Must be last. - -typedef struct _upb_MemBlock _upb_MemBlock; - -// LINT.IfChange(struct_definition) -struct upb_Arena { - _upb_ArenaHead head; - - // upb_alloc* together with a low bit which signals if there is an initial - // block. - uintptr_t block_alloc; - - // When multiple arenas are fused together, each arena points to a parent - // arena (root points to itself). The root tracks how many live arenas - // reference it. - - // The low bit is tagged: - // 0: pointer to parent - // 1: count, left shifted by one - UPB_ATOMIC(uintptr_t) parent_or_count; - - // All nodes that are fused together are in a singly-linked list. - UPB_ATOMIC(upb_Arena*) next; // NULL at end of list. - - // The last element of the linked list. This is present only as an - // optimization, so that we do not have to iterate over all members for every - // fuse. Only significant for an arena root. In other cases it is ignored. - UPB_ATOMIC(upb_Arena*) tail; // == self when no other list members. - - // Linked list of blocks to free/cleanup. Atomic only for the benefit of - // upb_Arena_SpaceAllocated(). - UPB_ATOMIC(_upb_MemBlock*) blocks; -}; -// LINT.ThenChange(//depot/google3/third_party/upb/bits/typescript/arena.ts) - - -#endif /* UPB_MEM_INTERNAL_ARENA_H_ */ - #ifndef UPB_PORT_ATOMIC_H_ #define UPB_PORT_ATOMIC_H_ @@ -13364,7 +13367,10 @@ typedef struct upb_Decoder { uint32_t end_group; // field number of END_GROUP tag, else DECODE_NOGROUP. uint16_t options; bool missing_required; - upb_Arena arena; + union { + upb_Arena arena; + void* foo[UPB_ARENA_SIZE_HACK]; + }; upb_DecodeStatus status; jmp_buf err; diff --git a/ruby/ext/google/protobuf_c/ruby-upb.c b/ruby/ext/google/protobuf_c/ruby-upb.c index 50732bf20c9d4..7492b92102b3e 100644 --- a/ruby/ext/google/protobuf_c/ruby-upb.c +++ b/ruby/ext/google/protobuf_c/ruby-upb.c @@ -5041,21 +5041,61 @@ upb_alloc upb_alloc_global = {&upb_global_allocfunc}; // Must be last. -struct _upb_MemBlock { +typedef struct upb_MemBlock { // Atomic only for the benefit of SpaceAllocated(). - UPB_ATOMIC(_upb_MemBlock*) next; + UPB_ATOMIC(struct upb_MemBlock*) next; uint32_t size; // Data follows. -}; - -static const size_t kUpb_MemblockReserve = - UPB_ALIGN_UP(sizeof(_upb_MemBlock), UPB_MALLOC_ALIGN); +} upb_MemBlock; + +typedef struct upb_ArenaInternal { + // upb_alloc* together with a low bit which signals if there is an initial + // block. + uintptr_t block_alloc; + + // When multiple arenas are fused together, each arena points to a parent + // arena (root points to itself). The root tracks how many live arenas + // reference it. + + // The low bit is tagged: + // 0: pointer to parent + // 1: count, left shifted by one + UPB_ATOMIC(uintptr_t) parent_or_count; + + // All nodes that are fused together are in a singly-linked list. + // == NULL at end of list. + UPB_ATOMIC(struct upb_ArenaInternal*) next; + + // The last element of the linked list. This is present only as an + // optimization, so that we do not have to iterate over all members for every + // fuse. Only significant for an arena root. In other cases it is ignored. + // == self when no other list members. + UPB_ATOMIC(struct upb_ArenaInternal*) tail; + + // Linked list of blocks to free/cleanup. Atomic only for the benefit of + // upb_Arena_SpaceAllocated(). + UPB_ATOMIC(upb_MemBlock*) blocks; +} upb_ArenaInternal; + +// All public + private state for an arena. +typedef struct { + upb_Arena head; + upb_ArenaInternal body; +} upb_ArenaState; typedef struct { - upb_Arena* root; + upb_ArenaInternal* root; uintptr_t tagged_count; } upb_ArenaRoot; +static const size_t kUpb_MemblockReserve = + UPB_ALIGN_UP(sizeof(upb_MemBlock), UPB_MALLOC_ALIGN); + +// Extracts the (upb_ArenaInternal*) from a (upb_Arena*) +static upb_ArenaInternal* upb_Arena_Internal(const upb_Arena* a) { + return &((upb_ArenaState*)a)->body; +} + static bool _upb_Arena_IsTaggedRefcount(uintptr_t parent_or_count) { return (parent_or_count & 1) == 1; } @@ -5075,19 +5115,20 @@ static uintptr_t _upb_Arena_TaggedFromRefcount(uintptr_t refcount) { return parent_or_count; } -static upb_Arena* _upb_Arena_PointerFromTagged(uintptr_t parent_or_count) { +static upb_ArenaInternal* _upb_Arena_PointerFromTagged( + uintptr_t parent_or_count) { UPB_ASSERT(_upb_Arena_IsTaggedPointer(parent_or_count)); - return (upb_Arena*)parent_or_count; + return (upb_ArenaInternal*)parent_or_count; } -static uintptr_t _upb_Arena_TaggedFromPointer(upb_Arena* a) { - uintptr_t parent_or_count = (uintptr_t)a; +static uintptr_t _upb_Arena_TaggedFromPointer(upb_ArenaInternal* ai) { + uintptr_t parent_or_count = (uintptr_t)ai; UPB_ASSERT(_upb_Arena_IsTaggedPointer(parent_or_count)); return parent_or_count; } -static upb_alloc* _upb_Arena_BlockAlloc(upb_Arena* arena) { - return (upb_alloc*)(arena->block_alloc & ~0x1); +static upb_alloc* _upb_ArenaInternal_BlockAlloc(upb_ArenaInternal* ai) { + return (upb_alloc*)(ai->block_alloc & ~0x1); } static uintptr_t _upb_Arena_MakeBlockAlloc(upb_alloc* alloc, bool has_initial) { @@ -5096,15 +5137,16 @@ static uintptr_t _upb_Arena_MakeBlockAlloc(upb_alloc* alloc, bool has_initial) { return alloc_uint | (has_initial ? 1 : 0); } -static bool _upb_Arena_HasInitialBlock(upb_Arena* arena) { - return arena->block_alloc & 0x1; +static bool _upb_ArenaInternal_HasInitialBlock(upb_ArenaInternal* ai) { + return ai->block_alloc & 0x1; } static upb_ArenaRoot _upb_Arena_FindRoot(upb_Arena* a) { - uintptr_t poc = upb_Atomic_Load(&a->parent_or_count, memory_order_acquire); + upb_ArenaInternal* ai = upb_Arena_Internal(a); + uintptr_t poc = upb_Atomic_Load(&ai->parent_or_count, memory_order_acquire); while (_upb_Arena_IsTaggedPointer(poc)) { - upb_Arena* next = _upb_Arena_PointerFromTagged(poc); - UPB_ASSERT(a != next); + upb_ArenaInternal* next = _upb_Arena_PointerFromTagged(poc); + UPB_ASSERT(ai != next); uintptr_t next_poc = upb_Atomic_Load(&next->parent_or_count, memory_order_acquire); @@ -5128,64 +5170,67 @@ static upb_ArenaRoot _upb_Arena_FindRoot(upb_Arena* a) { // further away over time, but the path towards that root will continue to // be valid and the creation of the path carries all the memory orderings // required. - UPB_ASSERT(a != _upb_Arena_PointerFromTagged(next_poc)); - upb_Atomic_Store(&a->parent_or_count, next_poc, memory_order_relaxed); + UPB_ASSERT(ai != _upb_Arena_PointerFromTagged(next_poc)); + upb_Atomic_Store(&ai->parent_or_count, next_poc, memory_order_relaxed); } - a = next; + ai = next; poc = next_poc; } - return (upb_ArenaRoot){.root = a, .tagged_count = poc}; + return (upb_ArenaRoot){.root = ai, .tagged_count = poc}; } size_t upb_Arena_SpaceAllocated(upb_Arena* arena) { - arena = _upb_Arena_FindRoot(arena).root; + upb_ArenaInternal* ai = _upb_Arena_FindRoot(arena).root; size_t memsize = 0; - while (arena != NULL) { - _upb_MemBlock* block = - upb_Atomic_Load(&arena->blocks, memory_order_relaxed); + while (ai != NULL) { + upb_MemBlock* block = upb_Atomic_Load(&ai->blocks, memory_order_relaxed); while (block != NULL) { - memsize += sizeof(_upb_MemBlock) + block->size; + memsize += sizeof(upb_MemBlock) + block->size; block = upb_Atomic_Load(&block->next, memory_order_relaxed); } - arena = upb_Atomic_Load(&arena->next, memory_order_relaxed); + ai = upb_Atomic_Load(&ai->next, memory_order_relaxed); } return memsize; } uint32_t upb_Arena_DebugRefCount(upb_Arena* a) { + upb_ArenaInternal* ai = upb_Arena_Internal(a); // These loads could probably be relaxed, but given that this is debug-only, // it's not worth introducing a new variant for it. - uintptr_t poc = upb_Atomic_Load(&a->parent_or_count, memory_order_acquire); + uintptr_t poc = upb_Atomic_Load(&ai->parent_or_count, memory_order_acquire); while (_upb_Arena_IsTaggedPointer(poc)) { - a = _upb_Arena_PointerFromTagged(poc); - poc = upb_Atomic_Load(&a->parent_or_count, memory_order_acquire); + ai = _upb_Arena_PointerFromTagged(poc); + poc = upb_Atomic_Load(&ai->parent_or_count, memory_order_acquire); } return _upb_Arena_RefCountFromTagged(poc); } static void _upb_Arena_AddBlock(upb_Arena* a, void* ptr, size_t size) { - _upb_MemBlock* block = ptr; + upb_ArenaInternal* ai = upb_Arena_Internal(a); + upb_MemBlock* block = ptr; // Insert into linked list. block->size = (uint32_t)size; - upb_Atomic_Init(&block->next, a->blocks); - upb_Atomic_Store(&a->blocks, block, memory_order_release); + upb_Atomic_Init(&block->next, ai->blocks); + upb_Atomic_Store(&ai->blocks, block, memory_order_release); - a->head.UPB_PRIVATE(ptr) = UPB_PTR_AT(block, kUpb_MemblockReserve, char); - a->head.UPB_PRIVATE(end) = UPB_PTR_AT(block, size, char); + a->UPB_PRIVATE(ptr) = UPB_PTR_AT(block, kUpb_MemblockReserve, char); + a->UPB_PRIVATE(end) = UPB_PTR_AT(block, size, char); - UPB_POISON_MEMORY_REGION(a->head.UPB_PRIVATE(ptr), - a->head.UPB_PRIVATE(end) - a->head.UPB_PRIVATE(ptr)); + UPB_POISON_MEMORY_REGION(a->UPB_PRIVATE(ptr), + a->UPB_PRIVATE(end) - a->UPB_PRIVATE(ptr)); } static bool _upb_Arena_AllocBlock(upb_Arena* a, size_t size) { - if (!a->block_alloc) return false; - _upb_MemBlock* last_block = upb_Atomic_Load(&a->blocks, memory_order_acquire); + upb_ArenaInternal* ai = upb_Arena_Internal(a); + if (!ai->block_alloc) return false; + upb_MemBlock* last_block = upb_Atomic_Load(&ai->blocks, memory_order_acquire); size_t last_size = last_block != NULL ? last_block->size : 128; size_t block_size = UPB_MAX(size, last_size * 2) + kUpb_MemblockReserve; - _upb_MemBlock* block = upb_malloc(_upb_Arena_BlockAlloc(a), block_size); + upb_MemBlock* block = + upb_malloc(_upb_ArenaInternal_BlockAlloc(ai), block_size); if (!block) return false; _upb_Arena_AddBlock(a, block, block_size); @@ -5199,8 +5244,9 @@ void* UPB_PRIVATE(_upb_Arena_SlowMalloc)(upb_Arena* a, size_t size) { } static upb_Arena* _upb_Arena_InitSlow(upb_alloc* alloc) { - const size_t first_block_overhead = sizeof(upb_Arena) + kUpb_MemblockReserve; - upb_Arena* a; + const size_t first_block_overhead = + sizeof(upb_ArenaState) + kUpb_MemblockReserve; + upb_ArenaState* a; // We need to malloc the initial block. char* mem; @@ -5209,22 +5255,23 @@ static upb_Arena* _upb_Arena_InitSlow(upb_alloc* alloc) { return NULL; } - a = UPB_PTR_AT(mem, n - sizeof(*a), upb_Arena); - n -= sizeof(*a); + a = UPB_PTR_AT(mem, n - sizeof(upb_ArenaState), upb_ArenaState); + n -= sizeof(upb_ArenaState); - a->block_alloc = _upb_Arena_MakeBlockAlloc(alloc, 0); - upb_Atomic_Init(&a->parent_or_count, _upb_Arena_TaggedFromRefcount(1)); - upb_Atomic_Init(&a->next, NULL); - upb_Atomic_Init(&a->tail, a); - upb_Atomic_Init(&a->blocks, NULL); + a->body.block_alloc = _upb_Arena_MakeBlockAlloc(alloc, 0); + upb_Atomic_Init(&a->body.parent_or_count, _upb_Arena_TaggedFromRefcount(1)); + upb_Atomic_Init(&a->body.next, NULL); + upb_Atomic_Init(&a->body.tail, &a->body); + upb_Atomic_Init(&a->body.blocks, NULL); - _upb_Arena_AddBlock(a, mem, n); + _upb_Arena_AddBlock(&a->head, mem, n); - return a; + return &a->head; } upb_Arena* upb_Arena_Init(void* mem, size_t n, upb_alloc* alloc) { - upb_Arena* a; + UPB_ASSERT(sizeof(void*) * UPB_ARENA_SIZE_HACK >= sizeof(upb_ArenaState)); + upb_ArenaState* a; if (n) { /* Align initial pointer up so that we return properly-aligned pointers. */ @@ -5236,63 +5283,65 @@ upb_Arena* upb_Arena_Init(void* mem, size_t n, upb_alloc* alloc) { /* Round block size down to alignof(*a) since we will allocate the arena * itself at the end. */ - n = UPB_ALIGN_DOWN(n, UPB_ALIGN_OF(upb_Arena)); + n = UPB_ALIGN_DOWN(n, UPB_ALIGN_OF(upb_ArenaState)); - if (UPB_UNLIKELY(n < sizeof(upb_Arena))) { + if (UPB_UNLIKELY(n < sizeof(upb_ArenaState))) { return _upb_Arena_InitSlow(alloc); } - a = UPB_PTR_AT(mem, n - sizeof(*a), upb_Arena); + a = UPB_PTR_AT(mem, n - sizeof(upb_ArenaState), upb_ArenaState); + + upb_Atomic_Init(&a->body.parent_or_count, _upb_Arena_TaggedFromRefcount(1)); + upb_Atomic_Init(&a->body.next, NULL); + upb_Atomic_Init(&a->body.tail, &a->body); + upb_Atomic_Init(&a->body.blocks, NULL); - upb_Atomic_Init(&a->parent_or_count, _upb_Arena_TaggedFromRefcount(1)); - upb_Atomic_Init(&a->next, NULL); - upb_Atomic_Init(&a->tail, a); - upb_Atomic_Init(&a->blocks, NULL); - a->block_alloc = _upb_Arena_MakeBlockAlloc(alloc, 1); + a->body.block_alloc = _upb_Arena_MakeBlockAlloc(alloc, 1); a->head.UPB_PRIVATE(ptr) = mem; - a->head.UPB_PRIVATE(end) = UPB_PTR_AT(mem, n - sizeof(*a), char); + a->head.UPB_PRIVATE(end) = UPB_PTR_AT(mem, n - sizeof(upb_ArenaState), char); - return a; + return &a->head; } -static void _upb_Arena_DoFree(upb_Arena* a) { - UPB_ASSERT(_upb_Arena_RefCountFromTagged(a->parent_or_count) == 1); +static void _upb_Arena_DoFree(upb_ArenaInternal* ai) { + UPB_ASSERT(_upb_Arena_RefCountFromTagged(ai->parent_or_count) == 1); - while (a != NULL) { + while (ai != NULL) { // Load first since arena itself is likely from one of its blocks. - upb_Arena* next_arena = - (upb_Arena*)upb_Atomic_Load(&a->next, memory_order_acquire); - upb_alloc* block_alloc = _upb_Arena_BlockAlloc(a); - _upb_MemBlock* block = upb_Atomic_Load(&a->blocks, memory_order_acquire); + upb_ArenaInternal* next_arena = + (upb_ArenaInternal*)upb_Atomic_Load(&ai->next, memory_order_acquire); + upb_alloc* block_alloc = _upb_ArenaInternal_BlockAlloc(ai); + upb_MemBlock* block = upb_Atomic_Load(&ai->blocks, memory_order_acquire); while (block != NULL) { // Load first since we are deleting block. - _upb_MemBlock* next_block = + upb_MemBlock* next_block = upb_Atomic_Load(&block->next, memory_order_acquire); upb_free(block_alloc, block); block = next_block; } - a = next_arena; + ai = next_arena; } } void upb_Arena_Free(upb_Arena* a) { - uintptr_t poc = upb_Atomic_Load(&a->parent_or_count, memory_order_acquire); + upb_ArenaInternal* ai = upb_Arena_Internal(a); + uintptr_t poc = upb_Atomic_Load(&ai->parent_or_count, memory_order_acquire); retry: while (_upb_Arena_IsTaggedPointer(poc)) { - a = _upb_Arena_PointerFromTagged(poc); - poc = upb_Atomic_Load(&a->parent_or_count, memory_order_acquire); + ai = _upb_Arena_PointerFromTagged(poc); + poc = upb_Atomic_Load(&ai->parent_or_count, memory_order_acquire); } // compare_exchange or fetch_sub are RMW operations, which are more // expensive then direct loads. As an optimization, we only do RMW ops // when we need to update things for other threads to see. if (poc == _upb_Arena_TaggedFromRefcount(1)) { - _upb_Arena_DoFree(a); + _upb_Arena_DoFree(ai); return; } if (upb_Atomic_CompareExchangeWeak( - &a->parent_or_count, &poc, + &ai->parent_or_count, &poc, _upb_Arena_TaggedFromRefcount(_upb_Arena_RefCountFromTagged(poc) - 1), memory_order_release, memory_order_acquire)) { // We were >1 and we decremented it successfully, so we are done. @@ -5304,12 +5353,14 @@ void upb_Arena_Free(upb_Arena* a) { goto retry; } -static void _upb_Arena_DoFuseArenaLists(upb_Arena* const parent, - upb_Arena* child) { - upb_Arena* parent_tail = upb_Atomic_Load(&parent->tail, memory_order_relaxed); +static void _upb_Arena_DoFuseArenaLists(upb_ArenaInternal* const parent, + upb_ArenaInternal* child) { + upb_ArenaInternal* parent_tail = + upb_Atomic_Load(&parent->tail, memory_order_relaxed); + do { // Our tail might be stale, but it will always converge to the true tail. - upb_Arena* parent_tail_next = + upb_ArenaInternal* parent_tail_next = upb_Atomic_Load(&parent_tail->next, memory_order_relaxed); while (parent_tail_next != NULL) { parent_tail = parent_tail_next; @@ -5317,7 +5368,7 @@ static void _upb_Arena_DoFuseArenaLists(upb_Arena* const parent, upb_Atomic_Load(&parent_tail->next, memory_order_relaxed); } - upb_Arena* displaced = + upb_ArenaInternal* displaced = upb_Atomic_Exchange(&parent_tail->next, child, memory_order_relaxed); parent_tail = upb_Atomic_Load(&child->tail, memory_order_relaxed); @@ -5329,8 +5380,8 @@ static void _upb_Arena_DoFuseArenaLists(upb_Arena* const parent, upb_Atomic_Store(&parent->tail, parent_tail, memory_order_relaxed); } -static upb_Arena* _upb_Arena_DoFuse(upb_Arena* a1, upb_Arena* a2, - uintptr_t* ref_delta) { +static upb_ArenaInternal* _upb_Arena_DoFuse(upb_Arena* a1, upb_Arena* a2, + uintptr_t* ref_delta) { // `parent_or_count` has two disctint modes // - parent pointer mode // - refcount mode @@ -5388,7 +5439,8 @@ static upb_Arena* _upb_Arena_DoFuse(upb_Arena* a1, upb_Arena* a2, return r1.root; } -static bool _upb_Arena_FixupRefs(upb_Arena* new_root, uintptr_t ref_delta) { +static bool _upb_Arena_FixupRefs(upb_ArenaInternal* new_root, + uintptr_t ref_delta) { if (ref_delta == 0) return true; // No fixup required. uintptr_t poc = upb_Atomic_Load(&new_root->parent_or_count, memory_order_relaxed); @@ -5403,28 +5455,33 @@ static bool _upb_Arena_FixupRefs(upb_Arena* new_root, uintptr_t ref_delta) { bool upb_Arena_Fuse(upb_Arena* a1, upb_Arena* a2) { if (a1 == a2) return true; // trivial fuse + upb_ArenaInternal* ai1 = upb_Arena_Internal(a1); + upb_ArenaInternal* ai2 = upb_Arena_Internal(a2); + // Do not fuse initial blocks since we cannot lifetime extend them. // Any other fuse scenario is allowed. - if (_upb_Arena_HasInitialBlock(a1) || _upb_Arena_HasInitialBlock(a2)) { + if (_upb_ArenaInternal_HasInitialBlock(ai1) || + _upb_ArenaInternal_HasInitialBlock(ai2)) { return false; } // The number of refs we ultimately need to transfer to the new root. uintptr_t ref_delta = 0; while (true) { - upb_Arena* new_root = _upb_Arena_DoFuse(a1, a2, &ref_delta); + upb_ArenaInternal* new_root = _upb_Arena_DoFuse(a1, a2, &ref_delta); if (new_root != NULL && _upb_Arena_FixupRefs(new_root, ref_delta)) { return true; } } } -bool upb_Arena_IncRefFor(upb_Arena* arena, const void* owner) { +bool upb_Arena_IncRefFor(upb_Arena* a, const void* owner) { + upb_ArenaInternal* ai = upb_Arena_Internal(a); + if (_upb_ArenaInternal_HasInitialBlock(ai)) return false; upb_ArenaRoot r; - if (_upb_Arena_HasInitialBlock(arena)) return false; retry: - r = _upb_Arena_FindRoot(arena); + r = _upb_Arena_FindRoot(a); if (upb_Atomic_CompareExchangeWeak( &r.root->parent_or_count, &r.tagged_count, _upb_Arena_TaggedFromRefcount( @@ -5437,8 +5494,25 @@ bool upb_Arena_IncRefFor(upb_Arena* arena, const void* owner) { goto retry; } -void upb_Arena_DecRefFor(upb_Arena* arena, const void* owner) { - upb_Arena_Free(arena); +void upb_Arena_DecRefFor(upb_Arena* a, const void* owner) { upb_Arena_Free(a); } + +void UPB_PRIVATE(_upb_Arena_SwapIn)(upb_Arena* des, const upb_Arena* src) { + upb_ArenaInternal* desi = upb_Arena_Internal(des); + upb_ArenaInternal* srci = upb_Arena_Internal(src); + + *des = *src; + desi->block_alloc = srci->block_alloc; + upb_MemBlock* blocks = upb_Atomic_Load(&srci->blocks, memory_order_relaxed); + upb_Atomic_Init(&desi->blocks, blocks); +} + +void UPB_PRIVATE(_upb_Arena_SwapOut)(upb_Arena* des, const upb_Arena* src) { + upb_ArenaInternal* desi = upb_Arena_Internal(des); + upb_ArenaInternal* srci = upb_Arena_Internal(src); + + *des = *src; + upb_MemBlock* blocks = upb_Atomic_Load(&srci->blocks, memory_order_relaxed); + upb_Atomic_Store(&desi->blocks, blocks, memory_order_relaxed); } @@ -13541,10 +13615,8 @@ static upb_DecodeStatus upb_Decoder_Decode(upb_Decoder* const decoder, UPB_ASSERT(decoder->status != kUpb_DecodeStatus_Ok); } - _upb_MemBlock* blocks = - upb_Atomic_Load(&decoder->arena.blocks, memory_order_relaxed); - arena->head = decoder->arena.head; - upb_Atomic_Store(&arena->blocks, blocks, memory_order_relaxed); + UPB_PRIVATE(_upb_Arena_SwapOut)(arena, &decoder->arena); + return decoder->status; } @@ -13571,10 +13643,7 @@ upb_DecodeStatus upb_Decode(const char* buf, size_t size, void* msg, // done. The temporary arena only needs to be able to handle allocation, // not fuse or free, so it does not need many of the members to be initialized // (particularly parent_or_count). - _upb_MemBlock* blocks = upb_Atomic_Load(&arena->blocks, memory_order_relaxed); - decoder.arena.head = arena->head; - decoder.arena.block_alloc = arena->block_alloc; - upb_Atomic_Init(&decoder.arena.blocks, blocks); + UPB_PRIVATE(_upb_Arena_SwapIn)(&decoder.arena, arena); return upb_Decoder_Decode(&decoder, buf, msg, l, arena); } @@ -14232,7 +14301,7 @@ UPB_FORCEINLINE static void fastdecode_docopy(upb_Decoder* d, const char* ptr, uint32_t size, int copy, char* data, size_t data_offset, upb_StringView* dst) { - d->arena.head.UPB_PRIVATE(ptr) += copy; + d->arena.UPB_PRIVATE(ptr) += copy; dst->data = data + data_offset; UPB_UNPOISON_MEMORY_REGION(data, copy); memcpy(data, ptr, copy); @@ -14264,7 +14333,7 @@ static void fastdecode_docopy(upb_Decoder* d, const char* ptr, uint32_t size, ptr += tagbytes + 1; \ dst->size = size; \ \ - buf = d->arena.head.UPB_PRIVATE(ptr); \ + buf = d->arena.UPB_PRIVATE(ptr); \ arena_has = UPB_PRIVATE(_upb_ArenaHas)(&d->arena); \ common_has = UPB_MIN(arena_has, \ upb_EpsCopyInputStream_BytesAvailable(&d->input, ptr)); \ @@ -14444,8 +14513,8 @@ upb_Message* decode_newmsg_ceil(upb_Decoder* d, const upb_MiniTable* m, if (UPB_LIKELY(msg_ceil_bytes > 0 && UPB_PRIVATE(_upb_ArenaHas)(&d->arena) >= msg_ceil_bytes)) { UPB_ASSERT(size <= (size_t)msg_ceil_bytes); - msg_data = d->arena.head.UPB_PRIVATE(ptr); - d->arena.head.UPB_PRIVATE(ptr) += size; + msg_data = d->arena.UPB_PRIVATE(ptr); + d->arena.UPB_PRIVATE(ptr) += size; UPB_UNPOISON_MEMORY_REGION(msg_data, msg_ceil_bytes); memset(msg_data, 0, msg_ceil_bytes); UPB_POISON_MEMORY_REGION(msg_data + size, msg_ceil_bytes - size); diff --git a/ruby/ext/google/protobuf_c/ruby-upb.h b/ruby/ext/google/protobuf_c/ruby-upb.h index 5e3b140168915..d67f23518d9cf 100755 --- a/ruby/ext/google/protobuf_c/ruby-upb.h +++ b/ruby/ext/google/protobuf_c/ruby-upb.h @@ -557,7 +557,6 @@ UPB_INLINE bool upb_StringView_IsEqual(upb_StringView a, upb_StringView b) { #include #include -#include #ifndef UPB_MEM_ALLOC_H_ @@ -630,43 +629,48 @@ UPB_INLINE void upb_gfree(void* ptr) { upb_free(&upb_alloc_global, ptr); } #endif /* UPB_MEM_ALLOC_H_ */ +#ifndef UPB_MEM_INTERNAL_ARENA_H_ +#define UPB_MEM_INTERNAL_ARENA_H_ + +#include +#include +#include + // Must be last. -typedef struct upb_Arena upb_Arena; +// This is QUITE an ugly hack, which specifies the number of pointers needed +// to equal (or exceed) the storage required for one upb_Arena. +// +// We need this because the decoder inlines a upb_Arena for performance but +// the full struct is not visible outside of arena.c. Yes, I know, it's awful. +#define UPB_ARENA_SIZE_HACK 7 -// LINT.IfChange(struct_definition) -typedef struct { +// LINT.IfChange(upb_Array) + +struct upb_Arena { char* UPB_ONLYBITS(ptr); char* UPB_ONLYBITS(end); -} _upb_ArenaHead; -// LINT.ThenChange(//depot/google3/third_party/upb/bits/typescript/arena.ts) +}; + +// LINT.ThenChange(//depot/google3/third_party/upb/bits/typescript/arena.ts:upb_Array) #ifdef __cplusplus extern "C" { #endif -// Creates an arena from the given initial block (if any -- n may be 0). -// Additional blocks will be allocated from |alloc|. If |alloc| is NULL, this -// is a fixed-size arena and cannot grow. -UPB_API upb_Arena* upb_Arena_Init(void* mem, size_t n, upb_alloc* alloc); - -UPB_API void upb_Arena_Free(upb_Arena* a); -UPB_API bool upb_Arena_Fuse(upb_Arena* a, upb_Arena* b); - -bool upb_Arena_IncRefFor(upb_Arena* a, const void* owner); -void upb_Arena_DecRefFor(upb_Arena* a, const void* owner); - -void* UPB_PRIVATE(_upb_Arena_SlowMalloc)(upb_Arena* a, size_t size); - -size_t upb_Arena_SpaceAllocated(upb_Arena* a); -uint32_t upb_Arena_DebugRefCount(upb_Arena* a); +void UPB_PRIVATE(_upb_Arena_SwapIn)(struct upb_Arena* des, + const struct upb_Arena* src); +void UPB_PRIVATE(_upb_Arena_SwapOut)(struct upb_Arena* des, + const struct upb_Arena* src); -UPB_INLINE size_t UPB_PRIVATE(_upb_ArenaHas)(upb_Arena* a) { - const _upb_ArenaHead* h = (_upb_ArenaHead*)a; - return (size_t)(h->UPB_ONLYBITS(end) - h->UPB_ONLYBITS(ptr)); +UPB_INLINE size_t UPB_PRIVATE(_upb_ArenaHas)(const struct upb_Arena* a) { + return (size_t)(a->UPB_ONLYBITS(end) - a->UPB_ONLYBITS(ptr)); } -UPB_API_INLINE void* upb_Arena_Malloc(upb_Arena* a, size_t size) { +UPB_INLINE void* UPB_PRIVATE(_upb_Arena_Malloc)(struct upb_Arena* a, + size_t size) { + void* UPB_PRIVATE(_upb_Arena_SlowMalloc)(struct upb_Arena * a, size_t size); + size = UPB_ALIGN_MALLOC(size); const size_t span = size + UPB_ASAN_GUARD_SIZE; if (UPB_UNLIKELY(UPB_PRIVATE(_upb_ArenaHas)(a) < span)) { @@ -674,52 +678,34 @@ UPB_API_INLINE void* upb_Arena_Malloc(upb_Arena* a, size_t size) { } // We have enough space to do a fast malloc. - _upb_ArenaHead* h = (_upb_ArenaHead*)a; - void* ret = h->UPB_ONLYBITS(ptr); + void* ret = a->UPB_ONLYBITS(ptr); UPB_ASSERT(UPB_ALIGN_MALLOC((uintptr_t)ret) == (uintptr_t)ret); UPB_ASSERT(UPB_ALIGN_MALLOC(size) == size); UPB_UNPOISON_MEMORY_REGION(ret, size); - h->UPB_ONLYBITS(ptr) += span; + a->UPB_ONLYBITS(ptr) += span; return ret; } -// Shrinks the last alloc from arena. -// REQUIRES: (ptr, oldsize) was the last malloc/realloc from this arena. -// We could also add a upb_Arena_TryShrinkLast() which is simply a no-op if -// this was not the last alloc. -UPB_API_INLINE void upb_Arena_ShrinkLast(upb_Arena* a, void* ptr, - size_t oldsize, size_t size) { - _upb_ArenaHead* h = (_upb_ArenaHead*)a; - oldsize = UPB_ALIGN_MALLOC(oldsize); - size = UPB_ALIGN_MALLOC(size); - // Must be the last alloc. - UPB_ASSERT((char*)ptr + oldsize == - h->UPB_ONLYBITS(ptr) - UPB_ASAN_GUARD_SIZE); - UPB_ASSERT(size <= oldsize); - h->UPB_ONLYBITS(ptr) = (char*)ptr + size; -} - -UPB_API_INLINE void* upb_Arena_Realloc(upb_Arena* a, void* ptr, size_t oldsize, - size_t size) { - _upb_ArenaHead* h = (_upb_ArenaHead*)a; +UPB_INLINE void* UPB_PRIVATE(_upb_Arena_Realloc)(struct upb_Arena* a, void* ptr, + size_t oldsize, size_t size) { oldsize = UPB_ALIGN_MALLOC(oldsize); size = UPB_ALIGN_MALLOC(size); bool is_most_recent_alloc = - (uintptr_t)ptr + oldsize == (uintptr_t)h->UPB_ONLYBITS(ptr); + (uintptr_t)ptr + oldsize == (uintptr_t)a->UPB_ONLYBITS(ptr); if (is_most_recent_alloc) { ptrdiff_t diff = size - oldsize; if ((ptrdiff_t)UPB_PRIVATE(_upb_ArenaHas)(a) >= diff) { - h->UPB_ONLYBITS(ptr) += diff; + a->UPB_ONLYBITS(ptr) += diff; return ptr; } } else if (size <= oldsize) { return ptr; } - void* ret = upb_Arena_Malloc(a, size); + void* ret = UPB_PRIVATE(_upb_Arena_Malloc)(a, size); if (ret && oldsize > 0) { memcpy(ret, ptr, UPB_MIN(oldsize, size)); @@ -728,10 +714,69 @@ UPB_API_INLINE void* upb_Arena_Realloc(upb_Arena* a, void* ptr, size_t oldsize, return ret; } +UPB_INLINE void UPB_PRIVATE(_upb_Arena_ShrinkLast)(struct upb_Arena* a, + void* ptr, size_t oldsize, + size_t size) { + oldsize = UPB_ALIGN_MALLOC(oldsize); + size = UPB_ALIGN_MALLOC(size); + // Must be the last alloc. + UPB_ASSERT((char*)ptr + oldsize == + a->UPB_ONLYBITS(ptr) - UPB_ASAN_GUARD_SIZE); + UPB_ASSERT(size <= oldsize); + a->UPB_ONLYBITS(ptr) = (char*)ptr + size; +} + +#ifdef __cplusplus +} /* extern "C" */ +#endif + + +#endif /* UPB_MEM_INTERNAL_ARENA_H_ */ + +// Must be last. + +typedef struct upb_Arena upb_Arena; + +#ifdef __cplusplus +extern "C" { +#endif + +// Creates an arena from the given initial block (if any -- n may be 0). +// Additional blocks will be allocated from |alloc|. If |alloc| is NULL, this +// is a fixed-size arena and cannot grow. +UPB_API upb_Arena* upb_Arena_Init(void* mem, size_t n, upb_alloc* alloc); + +UPB_API void upb_Arena_Free(upb_Arena* a); +UPB_API bool upb_Arena_Fuse(upb_Arena* a, upb_Arena* b); + +bool upb_Arena_IncRefFor(upb_Arena* a, const void* owner); +void upb_Arena_DecRefFor(upb_Arena* a, const void* owner); + +size_t upb_Arena_SpaceAllocated(upb_Arena* a); +uint32_t upb_Arena_DebugRefCount(upb_Arena* a); + UPB_API_INLINE upb_Arena* upb_Arena_New(void) { return upb_Arena_Init(NULL, 0, &upb_alloc_global); } +UPB_API_INLINE void* upb_Arena_Malloc(struct upb_Arena* a, size_t size) { + return UPB_PRIVATE(_upb_Arena_Malloc)(a, size); +} + +UPB_API_INLINE void* upb_Arena_Realloc(upb_Arena* a, void* ptr, size_t oldsize, + size_t size) { + return UPB_PRIVATE(_upb_Arena_Realloc)(a, ptr, oldsize, size); +} + +// Shrinks the last alloc from arena. +// REQUIRES: (ptr, oldsize) was the last malloc/realloc from this arena. +// We could also add a upb_Arena_TryShrinkLast() which is simply a no-op if +// this was not the last alloc. +UPB_API_INLINE void upb_Arena_ShrinkLast(upb_Arena* a, void* ptr, + size_t oldsize, size_t size) { + return UPB_PRIVATE(_upb_Arena_ShrinkLast)(a, ptr, oldsize, size); +} + #ifdef __cplusplus } /* extern "C" */ #endif @@ -11926,48 +11971,6 @@ double _upb_NoLocaleStrtod(const char *str, char **endptr); #endif /* UPB_LEX_STRTOD_H_ */ -#ifndef UPB_MEM_INTERNAL_ARENA_H_ -#define UPB_MEM_INTERNAL_ARENA_H_ - - -// Must be last. - -typedef struct _upb_MemBlock _upb_MemBlock; - -// LINT.IfChange(struct_definition) -struct upb_Arena { - _upb_ArenaHead head; - - // upb_alloc* together with a low bit which signals if there is an initial - // block. - uintptr_t block_alloc; - - // When multiple arenas are fused together, each arena points to a parent - // arena (root points to itself). The root tracks how many live arenas - // reference it. - - // The low bit is tagged: - // 0: pointer to parent - // 1: count, left shifted by one - UPB_ATOMIC(uintptr_t) parent_or_count; - - // All nodes that are fused together are in a singly-linked list. - UPB_ATOMIC(upb_Arena*) next; // NULL at end of list. - - // The last element of the linked list. This is present only as an - // optimization, so that we do not have to iterate over all members for every - // fuse. Only significant for an arena root. In other cases it is ignored. - UPB_ATOMIC(upb_Arena*) tail; // == self when no other list members. - - // Linked list of blocks to free/cleanup. Atomic only for the benefit of - // upb_Arena_SpaceAllocated(). - UPB_ATOMIC(_upb_MemBlock*) blocks; -}; -// LINT.ThenChange(//depot/google3/third_party/upb/bits/typescript/arena.ts) - - -#endif /* UPB_MEM_INTERNAL_ARENA_H_ */ - #ifndef UPB_PORT_ATOMIC_H_ #define UPB_PORT_ATOMIC_H_ @@ -13183,7 +13186,10 @@ typedef struct upb_Decoder { uint32_t end_group; // field number of END_GROUP tag, else DECODE_NOGROUP. uint16_t options; bool missing_required; - upb_Arena arena; + union { + upb_Arena arena; + void* foo[UPB_ARENA_SIZE_HACK]; + }; upb_DecodeStatus status; jmp_buf err; From 1250d5f6cccb0a45f959c7219980a0aad5060ee5 Mon Sep 17 00:00:00 2001 From: Jie Luo Date: Tue, 19 Dec 2023 15:46:35 -0800 Subject: [PATCH 062/255] BREAKING CHANGE in v26: check if Timestamp is valid. Seconds should be in range [-62135596800, 253402300799] Nanos should be in range [0, 999999999] PiperOrigin-RevId: 592365636 --- .../protobuf/internal/json_format_test.py | 9 ++- .../protobuf/internal/well_known_types.py | 56 +++++++++++++++---- .../internal/well_known_types_test.py | 24 +++----- 3 files changed, 59 insertions(+), 30 deletions(-) diff --git a/python/google/protobuf/internal/json_format_test.py b/python/google/protobuf/internal/json_format_test.py index 15b376c181d93..6c4d2dac0b9ca 100644 --- a/python/google/protobuf/internal/json_format_test.py +++ b/python/google/protobuf/internal/json_format_test.py @@ -1060,7 +1060,14 @@ def testInvalidTimestamp(self): json_format.Parse, text, message) # Time bigger than maximum time. message.value.seconds = 253402300800 - self.assertRaisesRegex(OverflowError, 'date value out of range', + self.assertRaisesRegex(json_format.SerializeToJsonError, + 'Timestamp is not valid', + json_format.MessageToJson, message) + # Nanos smaller than 0 + message.value.seconds = 0 + message.value.nanos = -1 + self.assertRaisesRegex(json_format.SerializeToJsonError, + 'Timestamp is not valid', json_format.MessageToJson, message) # Lower case t does not accept. text = '{"value": "0001-01-01t00:00:00Z"}' diff --git a/python/google/protobuf/internal/well_known_types.py b/python/google/protobuf/internal/well_known_types.py index 5727bc98c2c06..835e443eff764 100644 --- a/python/google/protobuf/internal/well_known_types.py +++ b/python/google/protobuf/internal/well_known_types.py @@ -33,6 +33,8 @@ _MICROS_PER_SECOND = 1000000 _SECONDS_PER_DAY = 24 * 3600 _DURATION_SECONDS_MAX = 315576000000 +_TIMESTAMP_SECONDS_MIN = -62135596800 +_TIMESTAMP_SECONDS_MAX = 253402300799 _EPOCH_DATETIME_NAIVE = datetime.datetime(1970, 1, 1, tzinfo=None) _EPOCH_DATETIME_AWARE = _EPOCH_DATETIME_NAIVE.replace( @@ -85,10 +87,10 @@ def ToJsonString(self): and uses 3, 6 or 9 fractional digits as required to represent the exact time. Example of the return format: '1972-01-01T10:00:20.021Z' """ - nanos = self.nanos % _NANOS_PER_SECOND - total_sec = self.seconds + (self.nanos - nanos) // _NANOS_PER_SECOND - seconds = total_sec % _SECONDS_PER_DAY - days = (total_sec - seconds) // _SECONDS_PER_DAY + _CheckTimestampValid(self.seconds, self.nanos) + nanos = self.nanos + seconds = self.seconds % _SECONDS_PER_DAY + days = (self.seconds - seconds) // _SECONDS_PER_DAY dt = datetime.datetime(1970, 1, 1) + datetime.timedelta(days, seconds) result = dt.isoformat() @@ -166,6 +168,7 @@ def FromJsonString(self, value): else: seconds += (int(timezone[1:pos])*60+int(timezone[pos+1:]))*60 # Set seconds and nanos + _CheckTimestampValid(seconds, nanos) self.seconds = int(seconds) self.nanos = int(nanos) @@ -175,39 +178,53 @@ def GetCurrentTime(self): def ToNanoseconds(self): """Converts Timestamp to nanoseconds since epoch.""" + _CheckTimestampValid(self.seconds, self.nanos) return self.seconds * _NANOS_PER_SECOND + self.nanos def ToMicroseconds(self): """Converts Timestamp to microseconds since epoch.""" + _CheckTimestampValid(self.seconds, self.nanos) return (self.seconds * _MICROS_PER_SECOND + self.nanos // _NANOS_PER_MICROSECOND) def ToMilliseconds(self): """Converts Timestamp to milliseconds since epoch.""" + _CheckTimestampValid(self.seconds, self.nanos) return (self.seconds * _MILLIS_PER_SECOND + self.nanos // _NANOS_PER_MILLISECOND) def ToSeconds(self): """Converts Timestamp to seconds since epoch.""" + _CheckTimestampValid(self.seconds, self.nanos) return self.seconds def FromNanoseconds(self, nanos): """Converts nanoseconds since epoch to Timestamp.""" - self.seconds = nanos // _NANOS_PER_SECOND - self.nanos = nanos % _NANOS_PER_SECOND + seconds = nanos // _NANOS_PER_SECOND + nanos = nanos % _NANOS_PER_SECOND + _CheckTimestampValid(seconds, nanos) + self.seconds = seconds + self.nanos = nanos def FromMicroseconds(self, micros): """Converts microseconds since epoch to Timestamp.""" - self.seconds = micros // _MICROS_PER_SECOND - self.nanos = (micros % _MICROS_PER_SECOND) * _NANOS_PER_MICROSECOND + seconds = micros // _MICROS_PER_SECOND + nanos = (micros % _MICROS_PER_SECOND) * _NANOS_PER_MICROSECOND + _CheckTimestampValid(seconds, nanos) + self.seconds = seconds + self.nanos = nanos def FromMilliseconds(self, millis): """Converts milliseconds since epoch to Timestamp.""" - self.seconds = millis // _MILLIS_PER_SECOND - self.nanos = (millis % _MILLIS_PER_SECOND) * _NANOS_PER_MILLISECOND + seconds = millis // _MILLIS_PER_SECOND + nanos = (millis % _MILLIS_PER_SECOND) * _NANOS_PER_MILLISECOND + _CheckTimestampValid(seconds, nanos) + self.seconds = seconds + self.nanos = nanos def FromSeconds(self, seconds): """Converts seconds since epoch to Timestamp.""" + _CheckTimestampValid(seconds, 0) self.seconds = seconds self.nanos = 0 @@ -229,6 +246,7 @@ def ToDatetime(self, tzinfo=None): # https://github.com/python/cpython/issues/109849) or full range (on some # platforms, see https://github.com/python/cpython/issues/110042) of # datetime. + _CheckTimestampValid(self.seconds, self.nanos) delta = datetime.timedelta( seconds=self.seconds, microseconds=_RoundTowardZero(self.nanos, _NANOS_PER_MICROSECOND), @@ -252,8 +270,22 @@ def FromDatetime(self, dt): # manipulated into a long value of seconds. During the conversion from # struct_time to long, the source date in UTC, and so it follows that the # correct transformation is calendar.timegm() - self.seconds = calendar.timegm(dt.utctimetuple()) - self.nanos = dt.microsecond * _NANOS_PER_MICROSECOND + seconds = calendar.timegm(dt.utctimetuple()) + nanos = dt.microsecond * _NANOS_PER_MICROSECOND + _CheckTimestampValid(seconds, nanos) + self.seconds = seconds + self.nanos = nanos + + +def _CheckTimestampValid(seconds, nanos): + if seconds < _TIMESTAMP_SECONDS_MIN or seconds > _TIMESTAMP_SECONDS_MAX: + raise ValueError( + 'Timestamp is not valid: Seconds {0} must be in range ' + '[-62135596800, 253402300799].'.format(seconds)) + if nanos < 0 or nanos >= _NANOS_PER_SECOND: + raise ValueError( + 'Timestamp is not valid: Nanos {} must be in a range ' + '[0, 999999].'.format(nanos)) class Duration(object): diff --git a/python/google/protobuf/internal/well_known_types_test.py b/python/google/protobuf/internal/well_known_types_test.py index 37d20491735f1..da273166eb970 100644 --- a/python/google/protobuf/internal/well_known_types_test.py +++ b/python/google/protobuf/internal/well_known_types_test.py @@ -352,27 +352,15 @@ def testTimezoneAwareMinDatetimeConversion(self): ) def testNanosOneSecond(self): - # TODO: b/301980950 - Test error behavior instead once ToDatetime validates - # that nanos are in expected range. tz = _TZ_PACIFIC ts = timestamp_pb2.Timestamp(nanos=1_000_000_000) - self.assertEqual(ts.ToDatetime(), datetime.datetime(1970, 1, 1, 0, 0, 1)) - self.assertEqual( - ts.ToDatetime(tz), datetime.datetime(1969, 12, 31, 16, 0, 1, tzinfo=tz) - ) + self.assertRaisesRegex(ValueError, 'Timestamp is not valid', + ts.ToDatetime) def testNanosNegativeOneSecond(self): - # TODO: b/301980950 - Test error behavior instead once ToDatetime validates - # that nanos are in expected range. - tz = _TZ_PACIFIC ts = timestamp_pb2.Timestamp(nanos=-1_000_000_000) - self.assertEqual( - ts.ToDatetime(), datetime.datetime(1969, 12, 31, 23, 59, 59) - ) - self.assertEqual( - ts.ToDatetime(tz), - datetime.datetime(1969, 12, 31, 15, 59, 59, tzinfo=tz), - ) + self.assertRaisesRegex(ValueError, 'Timestamp is not valid', + ts.ToDatetime) def testTimedeltaConversion(self): message = duration_pb2.Duration() @@ -421,8 +409,10 @@ def testInvalidTimestamp(self): self.assertRaisesRegex(ValueError, 'year (0 )?is out of range', message.FromJsonString, '0000-01-01T00:00:00Z') message.seconds = 253402300800 - self.assertRaisesRegex(OverflowError, 'date value out of range', + self.assertRaisesRegex(ValueError, 'Timestamp is not valid', message.ToJsonString) + self.assertRaisesRegex(ValueError, 'Timestamp is not valid', + message.FromSeconds, -62135596801) def testInvalidDuration(self): message = duration_pb2.Duration() From bc66a1804021f97d08ab1bc192cdfbafc0bbf5ab Mon Sep 17 00:00:00 2001 From: Adam Cozzette Date: Tue, 19 Dec 2023 15:49:11 -0800 Subject: [PATCH 063/255] Update lite_unittest to pad varints before calling `internal::VarintParse()` The `VarintParse()` function is ordinarily called only by the proto parser, which always provides 16 bytes of "slop" space at the end of the buffer. The ARM-specific optimized path takes advantage of this by always reading at least 8 bytes. However, this caused some test failures in msan due to unit tests not providing a sufficient amount of initialized padding. This CL fixes the problem by making sure the unit tests initialize the full 10-byte buffer and adding a comment stating that this is a precondition of the function. PiperOrigin-RevId: 592366291 --- src/google/protobuf/lite_unittest.cc | 5 +++-- src/google/protobuf/parse_context.h | 1 + 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/google/protobuf/lite_unittest.cc b/src/google/protobuf/lite_unittest.cc index 09f5ec60ccb1b..90235827d114c 100644 --- a/src/google/protobuf/lite_unittest.cc +++ b/src/google/protobuf/lite_unittest.cc @@ -8,6 +8,7 @@ // Author: kenton@google.com (Kenton Varda) #include +#include #include #include #include @@ -104,7 +105,7 @@ void SetSomeTypesInEmptyMessageUnknownFields( TEST(ParseVarintTest, Varint32) { auto test_value = [](uint32_t value, int varint_length) { - uint8_t buffer[10]; + uint8_t buffer[10] = {0}; uint8_t* p = io::CodedOutputStream::WriteVarint32ToArray(value, buffer); ASSERT_EQ(p - buffer, varint_length) << "Value = " << value; @@ -131,7 +132,7 @@ TEST(ParseVarintTest, Varint32) { TEST(ParseVarintTest, Varint64) { auto test_value = [](uint64_t value, int varint_length) { - uint8_t buffer[10]; + uint8_t buffer[10] = {0}; uint8_t* p = io::CodedOutputStream::WriteVarint64ToArray(value, buffer); ASSERT_EQ(p - buffer, varint_length) << "Value = " << value; diff --git a/src/google/protobuf/parse_context.h b/src/google/protobuf/parse_context.h index af48e07e94e03..9292d517feebf 100644 --- a/src/google/protobuf/parse_context.h +++ b/src/google/protobuf/parse_context.h @@ -847,6 +847,7 @@ static const char* VarintParseSlowArm(const char* p, uint64_t* out, } #endif +// The caller must ensure that p points to at least 10 valid bytes. template PROTOBUF_NODISCARD const char* VarintParse(const char* p, T* out) { #if defined(__aarch64__) && defined(ABSL_IS_LITTLE_ENDIAN) From 33cb42e33b70290327c5bacdd775446e6cf39e50 Mon Sep 17 00:00:00 2001 From: Eric Salo Date: Tue, 19 Dec 2023 17:48:33 -0800 Subject: [PATCH 064/255] upb: add 'static' to several Python map functions PiperOrigin-RevId: 592391399 --- python/map.c | 25 +++++++++++++------------ python/map.h | 4 ---- 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/python/map.c b/python/map.c index c4cd95eb7d117..4330aae1f4e0d 100644 --- a/python/map.c +++ b/python/map.c @@ -62,7 +62,7 @@ static void PyUpb_MapContainer_Dealloc(void* _self) { PyUpb_Dealloc(_self); } -PyTypeObject* PyUpb_MapContainer_GetClass(const upb_FieldDef* f) { +static PyTypeObject* PyUpb_MapContainer_GetClass(const upb_FieldDef* f) { assert(upb_FieldDef_IsMap(f)); PyUpb_ModuleState* state = PyUpb_ModuleState_Get(); const upb_FieldDef* val = @@ -130,9 +130,9 @@ upb_Map* PyUpb_MapContainer_EnsureReified(PyObject* _self) { return map; } -bool PyUpb_MapContainer_Set(PyUpb_MapContainer* self, upb_Map* map, - upb_MessageValue key, upb_MessageValue val, - upb_Arena* arena) { +static bool PyUpb_MapContainer_Set(PyUpb_MapContainer* self, upb_Map* map, + upb_MessageValue key, upb_MessageValue val, + upb_Arena* arena) { switch (upb_Map_Insert(map, key, val, arena)) { case kUpb_MapInsertStatus_Inserted: return true; @@ -146,8 +146,9 @@ bool PyUpb_MapContainer_Set(PyUpb_MapContainer* self, upb_Map* map, return false; // Unreachable, silence compiler warning. } -int PyUpb_MapContainer_AssignSubscript(PyObject* _self, PyObject* key, - PyObject* val) { +// Assigns `self[key] = val` for the map `self`. +static int PyUpb_MapContainer_AssignSubscript(PyObject* _self, PyObject* key, + PyObject* val) { PyUpb_MapContainer* self = (PyUpb_MapContainer*)_self; upb_Map* map = PyUpb_MapContainer_EnsureReified(_self); const upb_FieldDef* f = PyUpb_MapContainer_GetField(self); @@ -170,7 +171,7 @@ int PyUpb_MapContainer_AssignSubscript(PyObject* _self, PyObject* key, return 0; } -PyObject* PyUpb_MapContainer_Subscript(PyObject* _self, PyObject* key) { +static PyObject* PyUpb_MapContainer_Subscript(PyObject* _self, PyObject* key) { PyUpb_MapContainer* self = (PyUpb_MapContainer*)_self; upb_Map* map = PyUpb_MapContainer_GetIfReified(self); const upb_FieldDef* f = PyUpb_MapContainer_GetField(self); @@ -194,7 +195,7 @@ PyObject* PyUpb_MapContainer_Subscript(PyObject* _self, PyObject* key) { return PyUpb_UpbToPy(u_val, val_f, self->arena); } -PyObject* PyUpb_MapContainer_Contains(PyObject* _self, PyObject* key) { +static PyObject* PyUpb_MapContainer_Contains(PyObject* _self, PyObject* key) { PyUpb_MapContainer* self = (PyUpb_MapContainer*)_self; upb_Map* map = PyUpb_MapContainer_GetIfReified(self); if (!map) Py_RETURN_FALSE; @@ -210,7 +211,7 @@ PyObject* PyUpb_MapContainer_Contains(PyObject* _self, PyObject* key) { } } -PyObject* PyUpb_MapContainer_Clear(PyObject* _self, PyObject* key) { +static PyObject* PyUpb_MapContainer_Clear(PyObject* _self, PyObject* key) { upb_Map* map = PyUpb_MapContainer_EnsureReified(_self); upb_Map_Clear(map); Py_RETURN_NONE; @@ -252,13 +253,13 @@ static PyObject* PyUpb_MapContainer_GetEntryClass(PyObject* _self, return PyUpb_Descriptor_GetClass(entry_m); } -Py_ssize_t PyUpb_MapContainer_Length(PyObject* _self) { +static Py_ssize_t PyUpb_MapContainer_Length(PyObject* _self) { PyUpb_MapContainer* self = (PyUpb_MapContainer*)_self; upb_Map* map = PyUpb_MapContainer_GetIfReified(self); return map ? upb_Map_Size(map) : 0; } -PyUpb_MapContainer* PyUpb_MapContainer_Check(PyObject* _self) { +static PyUpb_MapContainer* PyUpb_MapContainer_Check(PyObject* _self) { PyUpb_ModuleState* state = PyUpb_ModuleState_Get(); if (!PyObject_TypeCheck(_self, state->message_map_container_type) && !PyObject_TypeCheck(_self, state->scalar_map_container_type)) { @@ -444,7 +445,7 @@ static void PyUpb_MapIterator_Dealloc(void* _self) { PyUpb_Dealloc(_self); } -PyObject* PyUpb_MapIterator_IterNext(PyObject* _self) { +static PyObject* PyUpb_MapIterator_IterNext(PyObject* _self) { PyUpb_MapIterator* self = (PyUpb_MapIterator*)_self; if (self->version != self->map->version) { return PyErr_Format(PyExc_RuntimeError, "Map modified during iteration."); diff --git a/python/map.h b/python/map.h index 7c982fff77dc9..2e1298e6291e3 100644 --- a/python/map.h +++ b/python/map.h @@ -33,10 +33,6 @@ void PyUpb_MapContainer_Reify(PyObject* self, upb_Map* map); // Reifies this map object if it is not already reified. upb_Map* PyUpb_MapContainer_EnsureReified(PyObject* self); -// Assigns `self[key] = val` for the map `self`. -int PyUpb_MapContainer_AssignSubscript(PyObject* self, PyObject* key, - PyObject* val); - // Invalidates any existing iterators for the map `obj`. void PyUpb_MapContainer_Invalidate(PyObject* obj); From de7f589d44818044016f8c931dfa9fee6c37dbb7 Mon Sep 17 00:00:00 2001 From: Eric Salo Date: Tue, 19 Dec 2023 17:56:31 -0800 Subject: [PATCH 065/255] upb: eliminate :mini_table_internal PiperOrigin-RevId: 592392732 --- upb/BUILD | 9 ---- upb/message/BUILD | 5 --- upb/message/accessors.h | 5 --- upb/message/array.c | 3 +- upb/message/copy.c | 7 ++- upb/message/internal/accessors.h | 1 - upb/mini_descriptor/BUILD | 2 - upb/mini_descriptor/decode.h | 3 -- upb/mini_descriptor/internal/encode_test.cc | 2 - upb/mini_descriptor/link.c | 2 - upb/mini_descriptor/link.h | 5 +-- upb/mini_table/BUILD | 47 ++++++++------------- upb/mini_table/enum.h | 3 +- upb/mini_table/extension.h | 9 ++-- upb/mini_table/field.h | 3 +- upb/mini_table/file.h | 9 ++-- upb/mini_table/internal/enum.h | 4 +- upb/mini_table/internal/extension.h | 29 ++++++------- upb/mini_table/internal/field.h | 40 +++++++++--------- upb/mini_table/internal/file.h | 26 ++++++------ upb/mini_table/internal/message.c | 4 +- upb/mini_table/internal/message.h | 44 +++++++++---------- upb/mini_table/internal/size_log2.h | 4 +- upb/mini_table/internal/sub.h | 26 ++++++------ upb/mini_table/message.c | 1 - upb/mini_table/message.h | 6 +-- upb/mini_table/sub.h | 11 +++-- upb/mini_table/types.h | 21 +++++++++ upb/reflection/BUILD | 3 +- upb/reflection/message.c | 1 - upb/test/BUILD | 1 - upb/wire/BUILD | 1 - upb/wire/decode.c | 4 +- upb/wire/encode.c | 2 - upb_generator/BUILD | 4 -- upb_generator/common.cc | 1 - upb_generator/file_layout.cc | 1 - upb_generator/protoc-gen-upb_minitable.cc | 1 - 38 files changed, 154 insertions(+), 196 deletions(-) create mode 100644 upb/mini_table/types.h diff --git a/upb/BUILD b/upb/BUILD index 180cc778bb718..fe3374bc78a74 100644 --- a/upb/BUILD +++ b/upb/BUILD @@ -291,12 +291,6 @@ alias( visibility = ["//upb:friends"], ) -alias( - name = "mini_table_internal", - actual = "//upb/mini_table:internal", - visibility = ["//visibility:public"], -) - alias( name = "port", actual = "//upb/port", @@ -409,7 +403,6 @@ upb_amalgamation( ":mini_descriptor_internal", ":mini_table", ":mini_table_compat", - ":mini_table_internal", ":port", ":reflection", ":reflection_internal", @@ -458,7 +451,6 @@ upb_amalgamation( ":mini_descriptor", ":mini_descriptor_internal", ":mini_table", - ":mini_table_internal", ":port", ":reflection", ":reflection_internal", @@ -508,7 +500,6 @@ upb_amalgamation( ":mini_descriptor", ":mini_descriptor_internal", ":mini_table", - ":mini_table_internal", ":port", ":reflection", ":reflection_internal", diff --git a/upb/message/BUILD b/upb/message/BUILD index 5ace2f586cafb..ac2e3583cec38 100644 --- a/upb/message/BUILD +++ b/upb/message/BUILD @@ -37,7 +37,6 @@ cc_library( "//upb:mem", "//upb:message_types", "//upb:mini_table", - "//upb:mini_table_internal", "//upb:port", "//upb:wire", "//upb:wire_reader", @@ -59,7 +58,6 @@ cc_library( "//upb:base", "//upb:mem", "//upb:mini_table", - "//upb:mini_table_internal", "//upb:port", ], ) @@ -84,7 +82,6 @@ cc_library( "//upb:base", "//upb:mem", "//upb:mini_table", - "//upb:mini_table_internal", "//upb:port", ], ) @@ -122,7 +119,6 @@ cc_library( "//upb:hash", "//upb:mem", "//upb:mini_table", - "//upb:mini_table_internal", "//upb:port", ], ) @@ -183,7 +179,6 @@ cc_library( "//upb:eps_copy_input_stream", "//upb:mem", "//upb:mini_table", - "//upb:mini_table_internal", "//upb:port", "//upb:wire", "//upb:wire_internal", diff --git a/upb/message/accessors.h b/upb/message/accessors.h index 74d145c8843a9..b7f553808d7d0 100644 --- a/upb/message/accessors.h +++ b/upb/message/accessors.h @@ -25,11 +25,6 @@ #include "upb/message/tagged_ptr.h" #include "upb/message/types.h" #include "upb/mini_table/enum.h" -#include "upb/mini_table/extension.h" -#include "upb/mini_table/field.h" -#include "upb/mini_table/internal/field.h" -#include "upb/mini_table/message.h" -#include "upb/mini_table/sub.h" // Must be last. #include "upb/port/def.inc" diff --git a/upb/message/array.c b/upb/message/array.c index d7858d3b22a06..45ce299dd0685 100644 --- a/upb/message/array.c +++ b/upb/message/array.c @@ -19,7 +19,8 @@ #include "upb/port/def.inc" upb_Array* upb_Array_New(upb_Arena* a, upb_CType type) { - return UPB_PRIVATE(_upb_Array_New)(a, 4, upb_CType_SizeLg2(type)); + const int lg2 = UPB_PRIVATE(_upb_CType_SizeLg2)(type); + return UPB_PRIVATE(_upb_Array_New)(a, 4, lg2); } const void* upb_Array_DataPtr(const upb_Array* arr) { diff --git a/upb/message/copy.c b/upb/message/copy.c index c6def53d12b95..9ee6be71c37a1 100644 --- a/upb/message/copy.c +++ b/upb/message/copy.c @@ -24,7 +24,6 @@ #include "upb/message/tagged_ptr.h" #include "upb/mini_table/extension.h" #include "upb/mini_table/field.h" -#include "upb/mini_table/internal/field.h" #include "upb/mini_table/internal/size_log2.h" #include "upb/mini_table/message.h" #include "upb/mini_table/sub.h" @@ -139,9 +138,9 @@ static upb_Map* upb_Message_Map_DeepClone(const upb_Map* map, upb_Array* upb_Array_DeepClone(const upb_Array* array, upb_CType value_type, const upb_MiniTable* sub, upb_Arena* arena) { - size_t size = array->UPB_PRIVATE(size); - upb_Array* cloned_array = - UPB_PRIVATE(_upb_Array_New)(arena, size, upb_CType_SizeLg2(value_type)); + const size_t size = array->UPB_PRIVATE(size); + const int lg2 = UPB_PRIVATE(_upb_CType_SizeLg2)(value_type); + upb_Array* cloned_array = UPB_PRIVATE(_upb_Array_New)(arena, size, lg2); if (!cloned_array) { return NULL; } diff --git a/upb/message/internal/accessors.h b/upb/message/internal/accessors.h index fd6bd2f72478c..023f47c00b2fb 100644 --- a/upb/message/internal/accessors.h +++ b/upb/message/internal/accessors.h @@ -24,7 +24,6 @@ #include "upb/message/tagged_ptr.h" #include "upb/mini_table/extension.h" #include "upb/mini_table/field.h" -#include "upb/mini_table/internal/field.h" // Must be last. #include "upb/port/def.inc" diff --git a/upb/mini_descriptor/BUILD b/upb/mini_descriptor/BUILD index aa3f652e01a36..f8292601ddc09 100644 --- a/upb/mini_descriptor/BUILD +++ b/upb/mini_descriptor/BUILD @@ -24,7 +24,6 @@ cc_library( "//upb:base_internal", "//upb:mem", "//upb:mini_table", - "//upb:mini_table_internal", "//upb:port", ], ) @@ -65,7 +64,6 @@ cc_test( "//upb:mem", "//upb:message_accessors_internal", "//upb:mini_table", - "//upb:mini_table_internal", "//upb:port", "//upb:wire", "@com_google_absl//absl/container:flat_hash_set", diff --git a/upb/mini_descriptor/decode.h b/upb/mini_descriptor/decode.h index dedf24f28737d..c73a44a5a0c26 100644 --- a/upb/mini_descriptor/decode.h +++ b/upb/mini_descriptor/decode.h @@ -10,9 +10,6 @@ #include "upb/base/status.h" #include "upb/mem/arena.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" // Export the newer headers, for legacy users. New users should include the diff --git a/upb/mini_descriptor/internal/encode_test.cc b/upb/mini_descriptor/internal/encode_test.cc index aa9979db3c270..80c2a205bd480 100644 --- a/upb/mini_descriptor/internal/encode_test.cc +++ b/upb/mini_descriptor/internal/encode_test.cc @@ -25,8 +25,6 @@ #include "upb/mini_descriptor/internal/modifiers.h" #include "upb/mini_table/enum.h" #include "upb/mini_table/field.h" -#include "upb/mini_table/internal/field.h" -#include "upb/mini_table/internal/message.h" #include "upb/mini_table/message.h" #include "upb/mini_table/sub.h" diff --git a/upb/mini_descriptor/link.c b/upb/mini_descriptor/link.c index 7ea135e6ca69b..37497795caa16 100644 --- a/upb/mini_descriptor/link.c +++ b/upb/mini_descriptor/link.c @@ -13,8 +13,6 @@ #include "upb/base/descriptor_constants.h" #include "upb/mini_table/enum.h" #include "upb/mini_table/field.h" -#include "upb/mini_table/internal/field.h" -#include "upb/mini_table/internal/message.h" #include "upb/mini_table/message.h" #include "upb/mini_table/sub.h" diff --git a/upb/mini_descriptor/link.h b/upb/mini_descriptor/link.h index db3aac16271c4..3326e06fc38c0 100644 --- a/upb/mini_descriptor/link.h +++ b/upb/mini_descriptor/link.h @@ -18,10 +18,7 @@ #include "upb/base/status.h" #include "upb/mem/arena.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" +#include "upb/mini_table/types.h" // Must be last. #include "upb/port/def.inc" diff --git a/upb/mini_table/BUILD b/upb/mini_table/BUILD index 58c4b2372950d..ba4b63ab2bea3 100644 --- a/upb/mini_table/BUILD +++ b/upb/mini_table/BUILD @@ -10,29 +10,11 @@ load( "UPB_DEFAULT_COPTS", ) -cc_library( - name = "compat", - srcs = [ - "compat.c", - ], - hdrs = [ - "compat.h", - ], - copts = UPB_DEFAULT_COPTS, - visibility = ["//visibility:public"], - deps = [ - ":mini_table", - "//upb:base", - "//upb:hash", - "//upb:mem", - "//upb:port", - ], -) - cc_library( name = "mini_table", srcs = [ "extension_registry.c", + "internal/message.c", "message.c", ], hdrs = [ @@ -41,38 +23,43 @@ cc_library( "extension_registry.h", "field.h", "file.h", + "internal/enum.h", + "internal/extension.h", + "internal/field.h", + "internal/file.h", + "internal/message.h", + "internal/size_log2.h", + "internal/sub.h", "message.h", "sub.h", + "types.h", ], copts = UPB_DEFAULT_COPTS, visibility = ["//visibility:public"], deps = [ - ":internal", "//upb:base", "//upb:hash", "//upb:mem", + "//upb:message_types", "//upb:port", ], ) cc_library( - name = "internal", + name = "compat", srcs = [ - "internal/message.c", + "compat.c", ], hdrs = [ - "internal/enum.h", - "internal/extension.h", - "internal/field.h", - "internal/file.h", - "internal/message.h", - "internal/size_log2.h", - "internal/sub.h", + "compat.h", ], + copts = UPB_DEFAULT_COPTS, visibility = ["//visibility:public"], deps = [ + ":mini_table", "//upb:base", - "//upb:message_types", + "//upb:hash", + "//upb:mem", "//upb:port", ], ) diff --git a/upb/mini_table/enum.h b/upb/mini_table/enum.h index cad31ec253c70..34656d07061b5 100644 --- a/upb/mini_table/enum.h +++ b/upb/mini_table/enum.h @@ -11,12 +11,11 @@ #include #include "upb/mini_table/internal/enum.h" +#include "upb/mini_table/types.h" // IWYU pragma: export // Must be last #include "upb/port/def.inc" -typedef struct upb_MiniTableEnum upb_MiniTableEnum; - #ifdef __cplusplus extern "C" { #endif diff --git a/upb/mini_table/extension.h b/upb/mini_table/extension.h index 0f3075278a2ff..67b55ec5bb2b9 100644 --- a/upb/mini_table/extension.h +++ b/upb/mini_table/extension.h @@ -11,17 +11,16 @@ #include #include "upb/mini_table/internal/extension.h" +#include "upb/mini_table/types.h" // IWYU pragma: export // Must be last. #include "upb/port/def.inc" -typedef struct upb_MiniTableExtension upb_MiniTableExtension; - #ifdef __cplusplus extern "C" { #endif -UPB_API_INLINE const struct upb_MiniTableField* upb_MiniTableExtension_AsField( +UPB_API_INLINE const upb_MiniTableField* upb_MiniTableExtension_AsField( const upb_MiniTableExtension* e) { return UPB_PRIVATE(_upb_MiniTableExtension_AsField)(e); } @@ -31,13 +30,13 @@ upb_MiniTableExtension_Number(const upb_MiniTableExtension* e) { return UPB_PRIVATE(_upb_MiniTableExtension_Number)(e); } -UPB_API_INLINE const struct upb_MiniTable* upb_MiniTableExtension_GetSubMessage( +UPB_API_INLINE const upb_MiniTable* upb_MiniTableExtension_GetSubMessage( const upb_MiniTableExtension* e) { return UPB_PRIVATE(_upb_MiniTableExtension_GetSubMessage)(e); } UPB_API_INLINE void upb_MiniTableExtension_SetSubMessage( - upb_MiniTableExtension* e, const struct upb_MiniTable* m) { + upb_MiniTableExtension* e, const upb_MiniTable* m) { return UPB_PRIVATE(_upb_MiniTableExtension_SetSubMessage)(e, m); } diff --git a/upb/mini_table/field.h b/upb/mini_table/field.h index 1df96cecc3838..c764164f401f8 100644 --- a/upb/mini_table/field.h +++ b/upb/mini_table/field.h @@ -12,12 +12,11 @@ #include "upb/base/descriptor_constants.h" #include "upb/mini_table/internal/field.h" +#include "upb/mini_table/types.h" // IWYU pragma: export // Must be last. #include "upb/port/def.inc" -typedef struct upb_MiniTableField upb_MiniTableField; - #ifdef __cplusplus extern "C" { #endif diff --git a/upb/mini_table/file.h b/upb/mini_table/file.h index db8d22cf76db9..bae16ba340570 100644 --- a/upb/mini_table/file.h +++ b/upb/mini_table/file.h @@ -9,8 +9,7 @@ #define UPB_MINI_TABLE_FILE_H_ #include "upb/mini_table/internal/file.h" - -typedef struct upb_MiniTableFile upb_MiniTableFile; +#include "upb/mini_table/types.h" // IWYU pragma: export // Must be last. #include "upb/port/def.inc" @@ -19,7 +18,7 @@ typedef struct upb_MiniTableFile upb_MiniTableFile; extern "C" { #endif -UPB_API_INLINE const struct upb_MiniTableEnum* upb_MiniTableFile_Enum( +UPB_API_INLINE const upb_MiniTableEnum* upb_MiniTableFile_Enum( const upb_MiniTableFile* f, int i) { return UPB_PRIVATE(_upb_MiniTableFile_Enum)(f, i); } @@ -28,7 +27,7 @@ UPB_API_INLINE int upb_MiniTableFile_EnumCount(const upb_MiniTableFile* f) { return UPB_PRIVATE(_upb_MiniTableFile_EnumCount)(f); } -UPB_API_INLINE const struct upb_MiniTableExtension* upb_MiniTableFile_Extension( +UPB_API_INLINE const upb_MiniTableExtension* upb_MiniTableFile_Extension( const upb_MiniTableFile* f, int i) { return UPB_PRIVATE(_upb_MiniTableFile_Extension)(f, i); } @@ -38,7 +37,7 @@ UPB_API_INLINE int upb_MiniTableFile_ExtensionCount( return UPB_PRIVATE(_upb_MiniTableFile_ExtensionCount)(f); } -UPB_API_INLINE const struct upb_MiniTable* upb_MiniTableFile_Message( +UPB_API_INLINE const upb_MiniTable* upb_MiniTableFile_Message( const upb_MiniTableFile* f, int i) { return UPB_PRIVATE(_upb_MiniTableFile_Message)(f, i); } diff --git a/upb/mini_table/internal/enum.h b/upb/mini_table/internal/enum.h index 6f8bec8d1e559..85ca9b3282d1f 100644 --- a/upb/mini_table/internal/enum.h +++ b/upb/mini_table/internal/enum.h @@ -10,6 +10,8 @@ #include +#include "upb/mini_table/types.h" + // Must be last. #include "upb/port/def.inc" @@ -24,7 +26,7 @@ extern "C" { #endif UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableEnum_CheckValue)( - const struct upb_MiniTableEnum* e, uint32_t val) { + const upb_MiniTableEnum* e, uint32_t val) { if (UPB_LIKELY(val < 64)) { const uint64_t mask = e->UPB_PRIVATE(data)[0] | ((uint64_t)e->UPB_PRIVATE(data)[1] << 32); diff --git a/upb/mini_table/internal/extension.h b/upb/mini_table/internal/extension.h index 0ae410e1c654f..e28a9fad265ee 100644 --- a/upb/mini_table/internal/extension.h +++ b/upb/mini_table/internal/extension.h @@ -10,42 +10,41 @@ #include -#include "upb/mini_table/internal/field.h" -#include "upb/mini_table/internal/sub.h" +#include "upb/mini_table/field.h" +#include "upb/mini_table/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. - struct upb_MiniTableField UPB_PRIVATE(field); + upb_MiniTableField UPB_PRIVATE(field); - const struct upb_MiniTable* UPB_PRIVATE(extendee); - union upb_MiniTableSub UPB_PRIVATE(sub); // NULL unless submsg or proto2 enum + const upb_MiniTable* UPB_PRIVATE(extendee); + upb_MiniTableSub UPB_PRIVATE(sub); // NULL unless submsg or proto2 enum }; #ifdef __cplusplus extern "C" { #endif -UPB_INLINE const struct upb_MiniTableField* UPB_PRIVATE( - _upb_MiniTableExtension_AsField)(const struct upb_MiniTableExtension* e) { - return (const struct upb_MiniTableField*)&e->UPB_PRIVATE(field); +UPB_INLINE const upb_MiniTableField* UPB_PRIVATE( + _upb_MiniTableExtension_AsField)(const upb_MiniTableExtension* e) { + return (const upb_MiniTableField*)&e->UPB_PRIVATE(field); } -UPB_INLINE uint32_t UPB_PRIVATE(_upb_MiniTableExtension_Number)( - const struct upb_MiniTableExtension* e) { +UPB_INLINE uint32_t +UPB_PRIVATE(_upb_MiniTableExtension_Number)(const upb_MiniTableExtension* e) { return e->UPB_PRIVATE(field).UPB_ONLYBITS(number); } -UPB_INLINE const struct upb_MiniTable* UPB_PRIVATE( - _upb_MiniTableExtension_GetSubMessage)( - const struct upb_MiniTableExtension* e) { - return e->UPB_PRIVATE(sub).UPB_PRIVATE(submsg); +UPB_INLINE const upb_MiniTable* UPB_PRIVATE( + _upb_MiniTableExtension_GetSubMessage)(const upb_MiniTableExtension* e) { + return upb_MiniTableSub_Message(e->UPB_PRIVATE(sub)); } UPB_INLINE void UPB_PRIVATE(_upb_MiniTableExtension_SetSubMessage)( - struct upb_MiniTableExtension* e, const struct upb_MiniTable* m) { + upb_MiniTableExtension* e, const upb_MiniTable* m) { e->UPB_PRIVATE(sub).UPB_PRIVATE(submsg) = m; } diff --git a/upb/mini_table/internal/field.h b/upb/mini_table/internal/field.h index 8d7c5e7308908..4d760549c3406 100644 --- a/upb/mini_table/internal/field.h +++ b/upb/mini_table/internal/field.h @@ -13,6 +13,7 @@ #include "upb/base/descriptor_constants.h" #include "upb/mini_table/internal/size_log2.h" +#include "upb/mini_table/types.h" // Must be last. #include "upb/port/def.inc" @@ -75,47 +76,47 @@ extern "C" { #endif UPB_INLINE upb_FieldMode -UPB_PRIVATE(_upb_MiniTableField_Mode)(const struct upb_MiniTableField* f) { +UPB_PRIVATE(_upb_MiniTableField_Mode)(const upb_MiniTableField* f) { return (upb_FieldMode)(f->UPB_ONLYBITS(mode) & kUpb_FieldMode_Mask); } UPB_INLINE upb_FieldRep -UPB_PRIVATE(_upb_MiniTableField_GetRep)(const struct upb_MiniTableField* f) { +UPB_PRIVATE(_upb_MiniTableField_GetRep)(const upb_MiniTableField* f) { return (upb_FieldRep)(f->UPB_ONLYBITS(mode) >> kUpb_FieldRep_Shift); } UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsArray)( - const struct upb_MiniTableField* f) { + const upb_MiniTableField* f) { return UPB_PRIVATE(_upb_MiniTableField_Mode)(f) == kUpb_FieldMode_Array; } UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsMap)( - const struct upb_MiniTableField* f) { + const upb_MiniTableField* f) { return UPB_PRIVATE(_upb_MiniTableField_Mode)(f) == kUpb_FieldMode_Map; } UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsScalar)( - const struct upb_MiniTableField* f) { + const upb_MiniTableField* f) { return UPB_PRIVATE(_upb_MiniTableField_Mode)(f) == kUpb_FieldMode_Scalar; } UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsAlternate)( - const struct upb_MiniTableField* f) { + const upb_MiniTableField* f) { return (f->UPB_ONLYBITS(mode) & kUpb_LabelFlags_IsAlternate) != 0; } UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsExtension)( - const struct upb_MiniTableField* f) { + const upb_MiniTableField* f) { return (f->UPB_ONLYBITS(mode) & kUpb_LabelFlags_IsExtension) != 0; } UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsPacked)( - const struct upb_MiniTableField* f) { + const upb_MiniTableField* f) { return (f->UPB_ONLYBITS(mode) & kUpb_LabelFlags_IsPacked) != 0; } UPB_INLINE upb_FieldType -UPB_PRIVATE(_upb_MiniTableField_Type)(const struct upb_MiniTableField* f) { +UPB_PRIVATE(_upb_MiniTableField_Type)(const upb_MiniTableField* f) { const upb_FieldType type = (upb_FieldType)f->UPB_PRIVATE(descriptortype); if (UPB_PRIVATE(_upb_MiniTableField_IsAlternate)(f)) { if (type == kUpb_FieldType_Int32) return kUpb_FieldType_Enum; @@ -126,7 +127,7 @@ UPB_PRIVATE(_upb_MiniTableField_Type)(const struct upb_MiniTableField* f) { } UPB_INLINE upb_CType -UPB_PRIVATE(_upb_MiniTableField_CType)(const struct upb_MiniTableField* f) { +UPB_PRIVATE(_upb_MiniTableField_CType)(const upb_MiniTableField* f) { return upb_FieldType_CType(UPB_PRIVATE(_upb_MiniTableField_Type)(f)); } @@ -145,23 +146,23 @@ _upb_MiniTableField_HasbitOffset(const struct upb_MiniTableField* f) { } UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsClosedEnum)( - const struct upb_MiniTableField* f) { + const upb_MiniTableField* f) { return f->UPB_PRIVATE(descriptortype) == kUpb_FieldType_Enum; } UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsInOneof)( - const struct upb_MiniTableField* f) { + const upb_MiniTableField* f) { return f->presence < 0; } UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsSubMessage)( - const struct upb_MiniTableField* f) { + const upb_MiniTableField* f) { return f->UPB_PRIVATE(descriptortype) == kUpb_FieldType_Message || f->UPB_PRIVATE(descriptortype) == kUpb_FieldType_Group; } UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_HasPresence)( - const struct upb_MiniTableField* f) { + const upb_MiniTableField* f) { if (UPB_PRIVATE(_upb_MiniTableField_IsExtension)(f)) { return UPB_PRIVATE(_upb_MiniTableField_IsScalar)(f); } else { @@ -186,7 +187,7 @@ _upb_MiniTableField_OneofOffset(const struct upb_MiniTableField* f) { } UPB_INLINE void UPB_PRIVATE(_upb_MiniTableField_CheckIsArray)( - const struct upb_MiniTableField* f) { + const upb_MiniTableField* f) { UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_NativePointer); UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_IsArray)(f)); @@ -194,16 +195,17 @@ UPB_INLINE void UPB_PRIVATE(_upb_MiniTableField_CheckIsArray)( } UPB_INLINE void UPB_PRIVATE(_upb_MiniTableField_CheckIsMap)( - const struct upb_MiniTableField* f) { + const upb_MiniTableField* f) { UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_NativePointer); UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_IsMap)(f)); UPB_ASSUME(f->presence == 0); } -UPB_INLINE size_t UPB_PRIVATE(_upb_MiniTableField_ElemSizeLg2)( - const struct upb_MiniTableField* f) { - return upb_FieldType_SizeLg2((upb_FieldType)f->UPB_PRIVATE(descriptortype)); +UPB_INLINE size_t +UPB_PRIVATE(_upb_MiniTableField_ElemSizeLg2)(const upb_MiniTableField* f) { + const upb_FieldType field_type = UPB_PRIVATE(_upb_MiniTableField_Type)(f); + return UPB_PRIVATE(_upb_FieldType_SizeLg2)(field_type); } // LINT.ThenChange(//depot/google3/third_party/upb/bits/typescript/mini_table_field.ts) diff --git a/upb/mini_table/internal/file.h b/upb/mini_table/internal/file.h index 0afabcf1b3824..6c1406ec81685 100644 --- a/upb/mini_table/internal/file.h +++ b/upb/mini_table/internal/file.h @@ -8,13 +8,15 @@ #ifndef UPB_MINI_TABLE_INTERNAL_FILE_H_ #define UPB_MINI_TABLE_INTERNAL_FILE_H_ +#include "upb/mini_table/types.h" + // Must be last. #include "upb/port/def.inc" struct upb_MiniTableFile { - const struct upb_MiniTable** UPB_PRIVATE(msgs); - const struct upb_MiniTableEnum** UPB_PRIVATE(enums); - const struct upb_MiniTableExtension** UPB_PRIVATE(exts); + const upb_MiniTable** UPB_PRIVATE(msgs); + const upb_MiniTableEnum** UPB_PRIVATE(enums); + const upb_MiniTableExtension** UPB_PRIVATE(exts); int UPB_PRIVATE(msg_count); int UPB_PRIVATE(enum_count); int UPB_PRIVATE(ext_count); @@ -25,34 +27,34 @@ extern "C" { #endif UPB_INLINE int UPB_PRIVATE(_upb_MiniTableFile_EnumCount)( - const struct upb_MiniTableFile* f) { + const upb_MiniTableFile* f) { return f->UPB_PRIVATE(enum_count); } UPB_INLINE int UPB_PRIVATE(_upb_MiniTableFile_ExtensionCount)( - const struct upb_MiniTableFile* f) { + const upb_MiniTableFile* f) { return f->UPB_PRIVATE(ext_count); } UPB_INLINE int UPB_PRIVATE(_upb_MiniTableFile_MessageCount)( - const struct upb_MiniTableFile* f) { + const upb_MiniTableFile* f) { return f->UPB_PRIVATE(msg_count); } -UPB_INLINE const struct upb_MiniTableEnum* UPB_PRIVATE(_upb_MiniTableFile_Enum)( - const struct upb_MiniTableFile* f, int i) { +UPB_INLINE const upb_MiniTableEnum* UPB_PRIVATE(_upb_MiniTableFile_Enum)( + const upb_MiniTableFile* f, int i) { UPB_ASSERT(i < f->UPB_PRIVATE(enum_count)); return f->UPB_PRIVATE(enums)[i]; } -UPB_INLINE const struct upb_MiniTableExtension* UPB_PRIVATE( - _upb_MiniTableFile_Extension)(const struct upb_MiniTableFile* f, int i) { +UPB_INLINE const upb_MiniTableExtension* UPB_PRIVATE( + _upb_MiniTableFile_Extension)(const upb_MiniTableFile* f, int i) { UPB_ASSERT(i < f->UPB_PRIVATE(ext_count)); return f->UPB_PRIVATE(exts)[i]; } -UPB_INLINE const struct upb_MiniTable* UPB_PRIVATE(_upb_MiniTableFile_Message)( - const struct upb_MiniTableFile* f, int i) { +UPB_INLINE const upb_MiniTable* UPB_PRIVATE(_upb_MiniTableFile_Message)( + const upb_MiniTableFile* f, int i) { UPB_ASSERT(i < f->UPB_PRIVATE(msg_count)); return f->UPB_PRIVATE(msgs)[i]; } diff --git a/upb/mini_table/internal/message.c b/upb/mini_table/internal/message.c index a1d736aa32f39..ff0884963fbb1 100644 --- a/upb/mini_table/internal/message.c +++ b/upb/mini_table/internal/message.c @@ -5,7 +5,7 @@ // license that can be found in the LICENSE file or at // https://developers.google.com/open-source/licenses/bsd -#include "upb/mini_table/internal/message.h" +#include "upb/mini_table/message.h" #include @@ -13,7 +13,7 @@ #include "upb/port/def.inc" // A MiniTable for an empty message, used for unlinked sub-messages. -const struct upb_MiniTable UPB_PRIVATE(_kUpb_MiniTable_Empty) = { +const upb_MiniTable UPB_PRIVATE(_kUpb_MiniTable_Empty) = { .UPB_PRIVATE(subs) = NULL, .UPB_PRIVATE(fields) = NULL, .UPB_PRIVATE(size) = 0, diff --git a/upb/mini_table/internal/message.h b/upb/mini_table/internal/message.h index caa8f8732711e..d894a0bd177c0 100644 --- a/upb/mini_table/internal/message.h +++ b/upb/mini_table/internal/message.h @@ -8,9 +8,12 @@ #ifndef UPB_MINI_TABLE_INTERNAL_MESSAGE_H_ #define UPB_MINI_TABLE_INTERNAL_MESSAGE_H_ +#include + #include "upb/message/types.h" #include "upb/mini_table/internal/field.h" #include "upb/mini_table/internal/sub.h" +#include "upb/mini_table/types.h" // Must be last. #include "upb/port/def.inc" @@ -39,10 +42,11 @@ typedef enum { // 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. + // LINT.IfChange(minitable_struct_definition) struct upb_MiniTable { - const union upb_MiniTableSub* UPB_PRIVATE(subs); - const struct upb_MiniTableField* UPB_ONLYBITS(fields); + const upb_MiniTableSub* UPB_PRIVATE(subs); + const upb_MiniTableField* UPB_ONLYBITS(fields); // Must be aligned to sizeof(void*). Doesn't include internal members like // unknown fields, extension dict, pointer to msglayout, etc. @@ -66,47 +70,43 @@ struct upb_MiniTable { extern "C" { #endif -UPB_INLINE const struct upb_MiniTable* UPB_PRIVATE(_upb_MiniTable_Empty)(void) { - extern const struct upb_MiniTable UPB_PRIVATE(_kUpb_MiniTable_Empty); +UPB_INLINE const upb_MiniTable* UPB_PRIVATE(_upb_MiniTable_Empty)(void) { + extern const upb_MiniTable UPB_PRIVATE(_kUpb_MiniTable_Empty); return &UPB_PRIVATE(_kUpb_MiniTable_Empty); } -UPB_INLINE int UPB_PRIVATE(_upb_MiniTable_FieldCount)( - const struct upb_MiniTable* m) { +UPB_INLINE int UPB_PRIVATE(_upb_MiniTable_FieldCount)(const upb_MiniTable* m) { return m->UPB_ONLYBITS(field_count); } -UPB_INLINE bool UPB_PRIVATE(_upb_MiniTable_IsEmpty)( - const struct upb_MiniTable* m) { - extern const struct upb_MiniTable UPB_PRIVATE(_kUpb_MiniTable_Empty); +UPB_INLINE bool UPB_PRIVATE(_upb_MiniTable_IsEmpty)(const upb_MiniTable* m) { + extern const upb_MiniTable UPB_PRIVATE(_kUpb_MiniTable_Empty); return m == &UPB_PRIVATE(_kUpb_MiniTable_Empty); } -UPB_INLINE const struct upb_MiniTableField* UPB_PRIVATE( - _upb_MiniTable_GetFieldByIndex)(const struct upb_MiniTable* m, uint32_t i) { +UPB_INLINE const upb_MiniTableField* UPB_PRIVATE( + _upb_MiniTable_GetFieldByIndex)(const upb_MiniTable* m, uint32_t i) { return &m->UPB_ONLYBITS(fields)[i]; } -UPB_INLINE const union upb_MiniTableSub* UPB_PRIVATE( - _upb_MiniTable_GetSubByIndex)(const struct upb_MiniTable* m, uint32_t i) { +UPB_INLINE const upb_MiniTableSub* UPB_PRIVATE(_upb_MiniTable_GetSubByIndex)( + const upb_MiniTable* m, uint32_t i) { return &m->UPB_PRIVATE(subs)[i]; } -UPB_INLINE const struct upb_MiniTable* UPB_PRIVATE( - _upb_MiniTable_GetSubMessageTable)(const struct upb_MiniTable* m, - const struct upb_MiniTableField* f) { +UPB_INLINE const upb_MiniTable* UPB_PRIVATE(_upb_MiniTable_GetSubMessageTable)( + const upb_MiniTable* m, const upb_MiniTableField* f) { UPB_ASSERT(UPB_PRIVATE(_upb_MiniTableField_CType)(f) == kUpb_CType_Message); - const struct upb_MiniTable* ret = UPB_PRIVATE(_upb_MiniTableSub_Message)( + const upb_MiniTable* ret = UPB_PRIVATE(_upb_MiniTableSub_Message)( m->UPB_PRIVATE(subs)[f->UPB_PRIVATE(submsg_index)]); UPB_ASSUME(ret); return UPB_PRIVATE(_upb_MiniTable_IsEmpty)(ret) ? NULL : ret; } -UPB_INLINE const struct upb_MiniTableEnum* UPB_PRIVATE( - _upb_MiniTable_GetSubEnumTable)(const struct upb_MiniTable* m, - const struct upb_MiniTableField* f) { +UPB_INLINE const upb_MiniTableEnum* UPB_PRIVATE(_upb_MiniTable_GetSubEnumTable)( + const upb_MiniTable* m, const upb_MiniTableField* f) { UPB_ASSERT(UPB_PRIVATE(_upb_MiniTableField_CType)(f) == kUpb_CType_Enum); return UPB_PRIVATE(_upb_MiniTableSub_Enum)( m->UPB_PRIVATE(subs)[f->UPB_PRIVATE(submsg_index)]); @@ -131,7 +131,7 @@ UPB_INLINE const struct upb_MiniTableField* UPB_PRIVATE( } UPB_INLINE bool UPB_PRIVATE(_upb_MiniTable_MessageFieldIsLinked)( - const struct upb_MiniTable* m, const struct upb_MiniTableField* f) { + const upb_MiniTable* m, const upb_MiniTableField* f) { return UPB_PRIVATE(_upb_MiniTable_GetSubMessageTable)(m, f) != NULL; } @@ -142,7 +142,7 @@ UPB_INLINE bool UPB_PRIVATE(_upb_MiniTable_MessageFieldIsLinked)( // RequiredMask(1) => 0b10 (0x2) // RequiredMask(5) => 0b111110 (0x3e) UPB_INLINE uint64_t -UPB_PRIVATE(_upb_MiniTable_RequiredMask)(const struct upb_MiniTable* m) { +UPB_PRIVATE(_upb_MiniTable_RequiredMask)(const upb_MiniTable* m) { int n = m->UPB_PRIVATE(required_count); UPB_ASSERT(0 < n && n <= 63); return ((1ULL << n) - 1) << 1; diff --git a/upb/mini_table/internal/size_log2.h b/upb/mini_table/internal/size_log2.h index f8fcea8e49a24..291ead037f83a 100644 --- a/upb/mini_table/internal/size_log2.h +++ b/upb/mini_table/internal/size_log2.h @@ -22,7 +22,7 @@ extern "C" { #endif // Return the log2 of the storage size in bytes for a upb_CType -UPB_INLINE int upb_CType_SizeLg2(upb_CType c_type) { +UPB_INLINE int UPB_PRIVATE(_upb_CType_SizeLg2)(upb_CType c_type) { static const int8_t size[] = { 0, // kUpb_CType_Bool 2, // kUpb_CType_Float @@ -42,7 +42,7 @@ UPB_INLINE int upb_CType_SizeLg2(upb_CType c_type) { } // Return the log2 of the storage size in bytes for a upb_FieldType -UPB_INLINE int upb_FieldType_SizeLg2(upb_FieldType field_type) { +UPB_INLINE int UPB_PRIVATE(_upb_FieldType_SizeLg2)(upb_FieldType field_type) { static const int8_t size[] = { 3, // kUpb_FieldType_Double 2, // kUpb_FieldType_Float diff --git a/upb/mini_table/internal/sub.h b/upb/mini_table/internal/sub.h index 99e35bd33c107..ad25d68933121 100644 --- a/upb/mini_table/internal/sub.h +++ b/upb/mini_table/internal/sub.h @@ -8,39 +8,41 @@ #ifndef UPB_MINI_TABLE_INTERNAL_SUB_H_ #define UPB_MINI_TABLE_INTERNAL_SUB_H_ +#include "upb/mini_table/types.h" + // Must be last. #include "upb/port/def.inc" union upb_MiniTableSub { - const struct upb_MiniTable* UPB_PRIVATE(submsg); - const struct upb_MiniTableEnum* UPB_PRIVATE(subenum); + const upb_MiniTable* UPB_PRIVATE(submsg); + const upb_MiniTableEnum* UPB_PRIVATE(subenum); }; #ifdef __cplusplus extern "C" { #endif -UPB_INLINE union upb_MiniTableSub UPB_PRIVATE(_upb_MiniTableSub_FromEnum)( - const struct upb_MiniTableEnum* subenum) { - union upb_MiniTableSub out; +UPB_INLINE upb_MiniTableSub +UPB_PRIVATE(_upb_MiniTableSub_FromEnum)(const upb_MiniTableEnum* subenum) { + upb_MiniTableSub out; out.UPB_PRIVATE(subenum) = subenum; return out; } -UPB_INLINE union upb_MiniTableSub UPB_PRIVATE(_upb_MiniTableSub_FromMessage)( - const struct upb_MiniTable* submsg) { - union upb_MiniTableSub out; +UPB_INLINE upb_MiniTableSub +UPB_PRIVATE(_upb_MiniTableSub_FromMessage)(const upb_MiniTable* submsg) { + upb_MiniTableSub out; out.UPB_PRIVATE(submsg) = submsg; return out; } -UPB_INLINE const struct upb_MiniTableEnum* UPB_PRIVATE(_upb_MiniTableSub_Enum)( - const union upb_MiniTableSub sub) { +UPB_INLINE const upb_MiniTableEnum* UPB_PRIVATE(_upb_MiniTableSub_Enum)( + const upb_MiniTableSub sub) { return sub.UPB_PRIVATE(subenum); } -UPB_INLINE const struct upb_MiniTable* UPB_PRIVATE(_upb_MiniTableSub_Message)( - const union upb_MiniTableSub sub) { +UPB_INLINE const upb_MiniTable* UPB_PRIVATE(_upb_MiniTableSub_Message)( + const upb_MiniTableSub sub) { return sub.UPB_PRIVATE(submsg); } diff --git a/upb/mini_table/message.c b/upb/mini_table/message.c index 05d2a78bc849f..5984a6c45de01 100644 --- a/upb/mini_table/message.c +++ b/upb/mini_table/message.c @@ -12,7 +12,6 @@ #include #include "upb/mini_table/field.h" -#include "upb/mini_table/internal/message.h" // Must be last. #include "upb/port/def.inc" diff --git a/upb/mini_table/message.h b/upb/mini_table/message.h index 89818fe10f859..986e429dcdc37 100644 --- a/upb/mini_table/message.h +++ b/upb/mini_table/message.h @@ -8,16 +8,12 @@ #ifndef UPB_MINI_TABLE_MESSAGE_H_ #define UPB_MINI_TABLE_MESSAGE_H_ -#include "upb/mini_table/enum.h" -#include "upb/mini_table/field.h" #include "upb/mini_table/internal/message.h" -#include "upb/mini_table/internal/sub.h" +#include "upb/mini_table/types.h" // IWYU pragma: export // Must be last. #include "upb/port/def.inc" -typedef struct upb_MiniTable upb_MiniTable; - #ifdef __cplusplus extern "C" { #endif diff --git a/upb/mini_table/sub.h b/upb/mini_table/sub.h index cd2253a35740a..e5cd522583613 100644 --- a/upb/mini_table/sub.h +++ b/upb/mini_table/sub.h @@ -9,12 +9,11 @@ #define UPB_MINI_TABLE_SUB_H_ #include "upb/mini_table/internal/sub.h" +#include "upb/mini_table/types.h" // IWYU pragma: export // Must be last. #include "upb/port/def.inc" -typedef union upb_MiniTableSub upb_MiniTableSub; - #ifdef __cplusplus extern "C" { #endif @@ -22,23 +21,23 @@ extern "C" { // Constructors UPB_API_INLINE upb_MiniTableSub -upb_MiniTableSub_FromEnum(const struct upb_MiniTableEnum* subenum) { +upb_MiniTableSub_FromEnum(const upb_MiniTableEnum* subenum) { return UPB_PRIVATE(_upb_MiniTableSub_FromEnum)(subenum); } UPB_API_INLINE upb_MiniTableSub -upb_MiniTableSub_FromMessage(const struct upb_MiniTable* submsg) { +upb_MiniTableSub_FromMessage(const upb_MiniTable* submsg) { return UPB_PRIVATE(_upb_MiniTableSub_FromMessage)(submsg); } // Getters -UPB_API_INLINE const struct upb_MiniTableEnum* upb_MiniTableSub_Enum( +UPB_API_INLINE const upb_MiniTableEnum* upb_MiniTableSub_Enum( upb_MiniTableSub sub) { return UPB_PRIVATE(_upb_MiniTableSub_Enum)(sub); } -UPB_API_INLINE const struct upb_MiniTable* upb_MiniTableSub_Message( +UPB_API_INLINE const upb_MiniTable* upb_MiniTableSub_Message( upb_MiniTableSub sub) { return UPB_PRIVATE(_upb_MiniTableSub_Message)(sub); } diff --git a/upb/mini_table/types.h b/upb/mini_table/types.h new file mode 100644 index 0000000000000..ec82342c17cfa --- /dev/null +++ b/upb/mini_table/types.h @@ -0,0 +1,21 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2023 Google LLC. All rights reserved. +// +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file or at +// https://developers.google.com/open-source/licenses/bsd + +#ifndef UPB_MINI_TABLE_TYPES_H_ +#define UPB_MINI_TABLE_TYPES_H_ + +// Minitable types are recursively defined so declare them all together here. + +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; + +#endif /* UPB_MINI_TABLE_TYPES_H_ */ diff --git a/upb/reflection/BUILD b/upb/reflection/BUILD index f12e705b65340..fdd20ee1f7502 100644 --- a/upb/reflection/BUILD +++ b/upb/reflection/BUILD @@ -133,6 +133,7 @@ bootstrap_cc_library( visibility = ["//visibility:public"], deps = [ "//upb:base", + "//upb:base_internal", "//upb:hash", "//upb:mem", "//upb:message", @@ -144,9 +145,7 @@ bootstrap_cc_library( "//upb:mini_descriptor", "//upb:mini_descriptor_internal", "//upb:mini_table", - "//upb:mini_table_internal", "//upb:port", - "//upb/base:internal", ], ) diff --git a/upb/reflection/message.c b/upb/reflection/message.c index 977bf33cc8744..471e6db50c447 100644 --- a/upb/reflection/message.c +++ b/upb/reflection/message.c @@ -19,7 +19,6 @@ #include "upb/message/map.h" #include "upb/message/message.h" #include "upb/mini_table/field.h" -#include "upb/mini_table/internal/field.h" #include "upb/reflection/def.h" #include "upb/reflection/def_pool.h" #include "upb/reflection/message_def.h" diff --git a/upb/test/BUILD b/upb/test/BUILD index 4c2308960211c..726dd6bdef043 100644 --- a/upb/test/BUILD +++ b/upb/test/BUILD @@ -168,7 +168,6 @@ cc_library( "//upb:message", "//upb:mini_descriptor", "//upb:mini_table", - "//upb:mini_table_internal", "//upb:port", ], ) diff --git a/upb/wire/BUILD b/upb/wire/BUILD index fab4e540002cf..d644af7f4c6ac 100644 --- a/upb/wire/BUILD +++ b/upb/wire/BUILD @@ -57,7 +57,6 @@ cc_library( "//upb:message_internal_types", "//upb:message_tagged_ptr", "//upb:mini_table", - "//upb:mini_table_internal", "//upb:port", "//third_party/utf8_range", ], diff --git a/upb/wire/decode.c b/upb/wire/decode.c index 7fd5e084990fd..044cae261e2aa 100644 --- a/upb/wire/decode.c +++ b/upb/wire/decode.c @@ -31,8 +31,6 @@ #include "upb/mini_table/extension.h" #include "upb/mini_table/extension_registry.h" #include "upb/mini_table/field.h" -#include "upb/mini_table/internal/field.h" -#include "upb/mini_table/internal/message.h" #include "upb/mini_table/internal/size_log2.h" #include "upb/mini_table/message.h" #include "upb/mini_table/sub.h" @@ -505,7 +503,7 @@ static const char* _upb_Decoder_DecodeEnumPacked( upb_Array* _upb_Decoder_CreateArray(upb_Decoder* d, const upb_MiniTableField* field) { const upb_FieldType field_type = field->UPB_PRIVATE(descriptortype); - const size_t lg2 = upb_FieldType_SizeLg2(field_type); + const size_t lg2 = UPB_PRIVATE(_upb_FieldType_SizeLg2)(field_type); upb_Array* ret = UPB_PRIVATE(_upb_Array_New)(&d->arena, 4, lg2); if (!ret) _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_OutOfMemory); return ret; diff --git a/upb/wire/encode.c b/upb/wire/encode.c index 8618921c3e7b5..2e4f2e4812808 100644 --- a/upb/wire/encode.c +++ b/upb/wire/encode.c @@ -31,8 +31,6 @@ #include "upb/message/tagged_ptr.h" #include "upb/mini_table/extension.h" #include "upb/mini_table/field.h" -#include "upb/mini_table/internal/field.h" -#include "upb/mini_table/internal/message.h" #include "upb/mini_table/message.h" #include "upb/mini_table/sub.h" #include "upb/wire/internal/constants.h" diff --git a/upb_generator/BUILD b/upb_generator/BUILD index 860ca10dd03f2..63bd0ac188786 100644 --- a/upb_generator/BUILD +++ b/upb_generator/BUILD @@ -104,7 +104,6 @@ bootstrap_cc_library( deps = [ ":mangle", "//upb:mini_table", - "//upb:mini_table_internal", "//upb:port", "@com_google_absl//absl/strings", ], @@ -129,7 +128,6 @@ bootstrap_cc_library( "//upb:base", "//upb:mini_descriptor", "//upb:mini_table", - "//upb:mini_table_internal", "//upb:port", "@com_google_absl//absl/container:flat_hash_map", "@com_google_absl//absl/strings", @@ -267,7 +265,6 @@ bootstrap_cc_binary( deps = [ "//upb:base", "//upb:mem", - "//upb:mini_table_internal", "//upb:port", "//upb:wire_types", "@com_google_absl//absl/container:flat_hash_map", @@ -307,7 +304,6 @@ bootstrap_cc_binary( "//upb:base", "//upb:mem", "//upb:mini_table", - "//upb:mini_table_internal", "//upb:port", "//upb:wire_types", "@com_google_absl//absl/container:flat_hash_map", diff --git a/upb_generator/common.cc b/upb_generator/common.cc index 9c60a7edf0c18..3bda1a3cabb2a 100644 --- a/upb_generator/common.cc +++ b/upb_generator/common.cc @@ -19,7 +19,6 @@ #include "absl/strings/string_view.h" #include "absl/strings/substitute.h" #include "upb/mini_table/field.h" -#include "upb/mini_table/internal/field.h" #include "upb/reflection/def.hpp" #include "upb_generator/mangle.h" diff --git a/upb_generator/file_layout.cc b/upb_generator/file_layout.cc index e2660e9d505f1..ad3d8fde82a8d 100644 --- a/upb_generator/file_layout.cc +++ b/upb_generator/file_layout.cc @@ -11,7 +11,6 @@ #include #include -#include "upb/mini_table/internal/extension.h" #include "upb/reflection/def.hpp" #include "upb_generator/common.h" diff --git a/upb_generator/protoc-gen-upb_minitable.cc b/upb_generator/protoc-gen-upb_minitable.cc index d58af3a89bd1d..6f73d2b8692c2 100644 --- a/upb_generator/protoc-gen-upb_minitable.cc +++ b/upb_generator/protoc-gen-upb_minitable.cc @@ -27,7 +27,6 @@ #include "upb/base/string_view.h" #include "upb/mini_table/enum.h" #include "upb/mini_table/field.h" -#include "upb/mini_table/internal/field.h" #include "upb/mini_table/message.h" #include "upb/reflection/def.hpp" #include "upb/wire/types.h" From 1db9465104d0a0338d5ce9df1485fd3980f78c16 Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Wed, 20 Dec 2023 02:08:18 +0000 Subject: [PATCH 066/255] Auto-generate files after cl/592392732 --- php/ext/google/protobuf/php-upb.c | 45 +-- php/ext/google/protobuf/php-upb.h | 529 +++++++++++++------------- ruby/ext/google/protobuf_c/ruby-upb.c | 45 +-- ruby/ext/google/protobuf_c/ruby-upb.h | 529 +++++++++++++------------- 4 files changed, 580 insertions(+), 568 deletions(-) diff --git a/php/ext/google/protobuf/php-upb.c b/php/ext/google/protobuf/php-upb.c index 1a4db4a89392f..c3d968c2f2694 100644 --- a/php/ext/google/protobuf/php-upb.c +++ b/php/ext/google/protobuf/php-upb.c @@ -6196,9 +6196,9 @@ static upb_Map* upb_Message_Map_DeepClone(const upb_Map* map, upb_Array* upb_Array_DeepClone(const upb_Array* array, upb_CType value_type, const upb_MiniTable* sub, upb_Arena* arena) { - size_t size = array->UPB_PRIVATE(size); - upb_Array* cloned_array = - UPB_PRIVATE(_upb_Array_New)(arena, size, upb_CType_SizeLg2(value_type)); + const size_t size = array->UPB_PRIVATE(size); + const int lg2 = UPB_PRIVATE(_upb_CType_SizeLg2)(value_type); + upb_Array* cloned_array = UPB_PRIVATE(_upb_Array_New)(arena, size, lg2); if (!cloned_array) { return NULL; } @@ -6386,7 +6386,8 @@ upb_Message* upb_Message_ShallowClone(const upb_Message* msg, // Must be last. upb_Array* upb_Array_New(upb_Arena* a, upb_CType type) { - return UPB_PRIVATE(_upb_Array_New)(a, 4, upb_CType_SizeLg2(type)); + const int lg2 = UPB_PRIVATE(_upb_CType_SizeLg2)(type); + return UPB_PRIVATE(_upb_Array_New)(a, 4, lg2); } const void* upb_Array_DataPtr(const upb_Array* arr) { @@ -8415,6 +8416,23 @@ const upb_MiniTableExtension* upb_ExtensionRegistry_Lookup( } +#include + +// Must be last. + +// A MiniTable for an empty message, used for unlinked sub-messages. +const upb_MiniTable UPB_PRIVATE(_kUpb_MiniTable_Empty) = { + .UPB_PRIVATE(subs) = NULL, + .UPB_PRIVATE(fields) = NULL, + .UPB_PRIVATE(size) = 0, + .UPB_PRIVATE(field_count) = 0, + .UPB_PRIVATE(ext) = kUpb_ExtMode_NonExtendable, + .UPB_PRIVATE(dense_below) = 0, + .UPB_PRIVATE(table_mask) = -1, + .UPB_PRIVATE(required_count) = 0, +}; + + #include #include #include @@ -8482,23 +8500,6 @@ bool upb_MiniTable_NextOneofField(const upb_MiniTable* m, } -#include - -// Must be last. - -// A MiniTable for an empty message, used for unlinked sub-messages. -const struct upb_MiniTable UPB_PRIVATE(_kUpb_MiniTable_Empty) = { - .UPB_PRIVATE(subs) = NULL, - .UPB_PRIVATE(fields) = NULL, - .UPB_PRIVATE(size) = 0, - .UPB_PRIVATE(field_count) = 0, - .UPB_PRIVATE(ext) = kUpb_ExtMode_NonExtendable, - .UPB_PRIVATE(dense_below) = 0, - .UPB_PRIVATE(table_mask) = -1, - .UPB_PRIVATE(required_count) = 0, -}; - - // Must be last. @@ -13258,7 +13259,7 @@ static const char* _upb_Decoder_DecodeEnumPacked( upb_Array* _upb_Decoder_CreateArray(upb_Decoder* d, const upb_MiniTableField* field) { const upb_FieldType field_type = field->UPB_PRIVATE(descriptortype); - const size_t lg2 = upb_FieldType_SizeLg2(field_type); + const size_t lg2 = UPB_PRIVATE(_upb_FieldType_SizeLg2)(field_type); upb_Array* ret = UPB_PRIVATE(_upb_Array_New)(&d->arena, 4, lg2); if (!ret) _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_OutOfMemory); return ret; diff --git a/php/ext/google/protobuf/php-upb.h b/php/ext/google/protobuf/php-upb.h index 0df6c4fd9c4e3..60e333a53bc80 100644 --- a/php/ext/google/protobuf/php-upb.h +++ b/php/ext/google/protobuf/php-upb.h @@ -979,84 +979,8 @@ UPB_API void* upb_Array_MutableDataPtr(upb_Array* arr); #define UPB_MINI_TABLE_MESSAGE_H_ -#ifndef UPB_MINI_TABLE_ENUM_H_ -#define UPB_MINI_TABLE_ENUM_H_ - -#include - - -#ifndef UPB_MINI_TABLE_INTERNAL_ENUM_H_ -#define UPB_MINI_TABLE_INTERNAL_ENUM_H_ - -#include - -// Must be last. - -struct upb_MiniTableEnum { - uint32_t UPB_PRIVATE(mask_limit); // Highest that can be tested with mask. - uint32_t UPB_PRIVATE(value_count); // Number of values after the bitfield. - uint32_t UPB_PRIVATE(data)[]; // Bitmask + enumerated values follow. -}; - -#ifdef __cplusplus -extern "C" { -#endif - -UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableEnum_CheckValue)( - const struct upb_MiniTableEnum* e, uint32_t val) { - if (UPB_LIKELY(val < 64)) { - const uint64_t mask = - e->UPB_PRIVATE(data)[0] | ((uint64_t)e->UPB_PRIVATE(data)[1] << 32); - const uint64_t bit = 1ULL << val; - return (mask & bit) != 0; - } - if (UPB_LIKELY(val < e->UPB_PRIVATE(mask_limit))) { - const uint32_t mask = e->UPB_PRIVATE(data)[val / 32]; - const uint32_t bit = 1ULL << (val % 32); - return (mask & bit) != 0; - } - - // OPT: binary search long lists? - const uint32_t* start = - &e->UPB_PRIVATE(data)[e->UPB_PRIVATE(mask_limit) / 32]; - const uint32_t* limit = &e->UPB_PRIVATE( - data)[e->UPB_PRIVATE(mask_limit) / 32 + e->UPB_PRIVATE(value_count)]; - for (const uint32_t* p = start; p < limit; p++) { - if (*p == val) return true; - } - return false; -} - -#ifdef __cplusplus -} /* extern "C" */ -#endif - - -#endif /* UPB_MINI_TABLE_INTERNAL_ENUM_H_ */ - -// Must be last - -typedef struct upb_MiniTableEnum upb_MiniTableEnum; - -#ifdef __cplusplus -extern "C" { -#endif - -// Validates enum value against range defined by enum mini table. -UPB_INLINE bool upb_MiniTableEnum_CheckValue(const upb_MiniTableEnum* e, - uint32_t val) { - return UPB_PRIVATE(_upb_MiniTableEnum_CheckValue)(e, val); -} - -#ifdef __cplusplus -} /* extern "C" */ -#endif - - -#endif /* UPB_MINI_TABLE_ENUM_H_ */ - -#ifndef UPB_MINI_TABLE_FIELD_H_ -#define UPB_MINI_TABLE_FIELD_H_ +#ifndef UPB_MINI_TABLE_INTERNAL_MESSAGE_H_ +#define UPB_MINI_TABLE_INTERNAL_MESSAGE_H_ #include @@ -1082,7 +1006,7 @@ extern "C" { #endif // Return the log2 of the storage size in bytes for a upb_CType -UPB_INLINE int upb_CType_SizeLg2(upb_CType c_type) { +UPB_INLINE int UPB_PRIVATE(_upb_CType_SizeLg2)(upb_CType c_type) { static const int8_t size[] = { 0, // kUpb_CType_Bool 2, // kUpb_CType_Float @@ -1102,7 +1026,7 @@ UPB_INLINE int upb_CType_SizeLg2(upb_CType c_type) { } // Return the log2 of the storage size in bytes for a upb_FieldType -UPB_INLINE int upb_FieldType_SizeLg2(upb_FieldType field_type) { +UPB_INLINE int UPB_PRIVATE(_upb_FieldType_SizeLg2)(upb_FieldType field_type) { static const int8_t size[] = { 3, // kUpb_FieldType_Double 2, // kUpb_FieldType_Float @@ -1135,6 +1059,21 @@ UPB_INLINE int upb_FieldType_SizeLg2(upb_FieldType field_type) { #endif /* UPB_MINI_TABLE_INTERNAL_SIZE_LOG2_H_ */ +#ifndef UPB_MINI_TABLE_TYPES_H_ +#define UPB_MINI_TABLE_TYPES_H_ + +// Minitable types are recursively defined so declare them all together here. + +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; + +#endif /* UPB_MINI_TABLE_TYPES_H_ */ + // Must be last. // LINT.IfChange(struct_definition) @@ -1195,47 +1134,47 @@ extern "C" { #endif UPB_INLINE upb_FieldMode -UPB_PRIVATE(_upb_MiniTableField_Mode)(const struct upb_MiniTableField* f) { +UPB_PRIVATE(_upb_MiniTableField_Mode)(const upb_MiniTableField* f) { return (upb_FieldMode)(f->UPB_ONLYBITS(mode) & kUpb_FieldMode_Mask); } UPB_INLINE upb_FieldRep -UPB_PRIVATE(_upb_MiniTableField_GetRep)(const struct upb_MiniTableField* f) { +UPB_PRIVATE(_upb_MiniTableField_GetRep)(const upb_MiniTableField* f) { return (upb_FieldRep)(f->UPB_ONLYBITS(mode) >> kUpb_FieldRep_Shift); } UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsArray)( - const struct upb_MiniTableField* f) { + const upb_MiniTableField* f) { return UPB_PRIVATE(_upb_MiniTableField_Mode)(f) == kUpb_FieldMode_Array; } UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsMap)( - const struct upb_MiniTableField* f) { + const upb_MiniTableField* f) { return UPB_PRIVATE(_upb_MiniTableField_Mode)(f) == kUpb_FieldMode_Map; } UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsScalar)( - const struct upb_MiniTableField* f) { + const upb_MiniTableField* f) { return UPB_PRIVATE(_upb_MiniTableField_Mode)(f) == kUpb_FieldMode_Scalar; } UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsAlternate)( - const struct upb_MiniTableField* f) { + const upb_MiniTableField* f) { return (f->UPB_ONLYBITS(mode) & kUpb_LabelFlags_IsAlternate) != 0; } UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsExtension)( - const struct upb_MiniTableField* f) { + const upb_MiniTableField* f) { return (f->UPB_ONLYBITS(mode) & kUpb_LabelFlags_IsExtension) != 0; } UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsPacked)( - const struct upb_MiniTableField* f) { + const upb_MiniTableField* f) { return (f->UPB_ONLYBITS(mode) & kUpb_LabelFlags_IsPacked) != 0; } UPB_INLINE upb_FieldType -UPB_PRIVATE(_upb_MiniTableField_Type)(const struct upb_MiniTableField* f) { +UPB_PRIVATE(_upb_MiniTableField_Type)(const upb_MiniTableField* f) { const upb_FieldType type = (upb_FieldType)f->UPB_PRIVATE(descriptortype); if (UPB_PRIVATE(_upb_MiniTableField_IsAlternate)(f)) { if (type == kUpb_FieldType_Int32) return kUpb_FieldType_Enum; @@ -1246,7 +1185,7 @@ UPB_PRIVATE(_upb_MiniTableField_Type)(const struct upb_MiniTableField* f) { } UPB_INLINE upb_CType -UPB_PRIVATE(_upb_MiniTableField_CType)(const struct upb_MiniTableField* f) { +UPB_PRIVATE(_upb_MiniTableField_CType)(const upb_MiniTableField* f) { return upb_FieldType_CType(UPB_PRIVATE(_upb_MiniTableField_Type)(f)); } @@ -1265,23 +1204,23 @@ _upb_MiniTableField_HasbitOffset(const struct upb_MiniTableField* f) { } UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsClosedEnum)( - const struct upb_MiniTableField* f) { + const upb_MiniTableField* f) { return f->UPB_PRIVATE(descriptortype) == kUpb_FieldType_Enum; } UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsInOneof)( - const struct upb_MiniTableField* f) { + const upb_MiniTableField* f) { return f->presence < 0; } UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsSubMessage)( - const struct upb_MiniTableField* f) { + const upb_MiniTableField* f) { return f->UPB_PRIVATE(descriptortype) == kUpb_FieldType_Message || f->UPB_PRIVATE(descriptortype) == kUpb_FieldType_Group; } UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_HasPresence)( - const struct upb_MiniTableField* f) { + const upb_MiniTableField* f) { if (UPB_PRIVATE(_upb_MiniTableField_IsExtension)(f)) { return UPB_PRIVATE(_upb_MiniTableField_IsScalar)(f); } else { @@ -1306,7 +1245,7 @@ _upb_MiniTableField_OneofOffset(const struct upb_MiniTableField* f) { } UPB_INLINE void UPB_PRIVATE(_upb_MiniTableField_CheckIsArray)( - const struct upb_MiniTableField* f) { + const upb_MiniTableField* f) { UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_NativePointer); UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_IsArray)(f)); @@ -1314,16 +1253,17 @@ UPB_INLINE void UPB_PRIVATE(_upb_MiniTableField_CheckIsArray)( } UPB_INLINE void UPB_PRIVATE(_upb_MiniTableField_CheckIsMap)( - const struct upb_MiniTableField* f) { + const upb_MiniTableField* f) { UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_NativePointer); UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_IsMap)(f)); UPB_ASSUME(f->presence == 0); } -UPB_INLINE size_t UPB_PRIVATE(_upb_MiniTableField_ElemSizeLg2)( - const struct upb_MiniTableField* f) { - return upb_FieldType_SizeLg2((upb_FieldType)f->UPB_PRIVATE(descriptortype)); +UPB_INLINE size_t +UPB_PRIVATE(_upb_MiniTableField_ElemSizeLg2)(const upb_MiniTableField* f) { + const upb_FieldType field_type = UPB_PRIVATE(_upb_MiniTableField_Type)(f); + return UPB_PRIVATE(_upb_FieldType_SizeLg2)(field_type); } // LINT.ThenChange(//depot/google3/third_party/upb/bits/typescript/mini_table_field.ts) @@ -1335,113 +1275,42 @@ UPB_INLINE size_t UPB_PRIVATE(_upb_MiniTableField_ElemSizeLg2)( #endif /* UPB_MINI_TABLE_INTERNAL_FIELD_H_ */ -// Must be last. - -typedef struct upb_MiniTableField upb_MiniTableField; - -#ifdef __cplusplus -extern "C" { -#endif - -UPB_API_INLINE upb_CType upb_MiniTableField_CType(const upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTableField_CType)(f); -} - -UPB_API_INLINE bool upb_MiniTableField_HasPresence( - const upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTableField_HasPresence)(f); -} - -UPB_API_INLINE bool upb_MiniTableField_IsArray(const upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTableField_IsArray)(f); -} - -UPB_API_INLINE bool upb_MiniTableField_IsClosedEnum( - const upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTableField_IsClosedEnum)(f); -} - -UPB_API_INLINE bool upb_MiniTableField_IsExtension( - const upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTableField_IsExtension)(f); -} - -UPB_API_INLINE bool upb_MiniTableField_IsInOneof(const upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTableField_IsInOneof)(f); -} - -UPB_API_INLINE bool upb_MiniTableField_IsMap(const upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTableField_IsMap)(f); -} - -UPB_API_INLINE bool upb_MiniTableField_IsPacked(const upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTableField_IsPacked)(f); -} - -UPB_API_INLINE bool upb_MiniTableField_IsScalar(const upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTableField_IsScalar)(f); -} - -UPB_API_INLINE bool upb_MiniTableField_IsSubMessage( - const upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTableField_IsSubMessage)(f); -} - -UPB_API_INLINE uint32_t upb_MiniTableField_Number(const upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTableField_Number)(f); -} - -UPB_API_INLINE upb_FieldType -upb_MiniTableField_Type(const upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTableField_Type)(f); -} - -#ifdef __cplusplus -} /* extern "C" */ -#endif - - -#endif /* UPB_MINI_TABLE_FIELD_H_ */ - -#ifndef UPB_MINI_TABLE_INTERNAL_MESSAGE_H_ -#define UPB_MINI_TABLE_INTERNAL_MESSAGE_H_ - - #ifndef UPB_MINI_TABLE_INTERNAL_SUB_H_ #define UPB_MINI_TABLE_INTERNAL_SUB_H_ + // Must be last. union upb_MiniTableSub { - const struct upb_MiniTable* UPB_PRIVATE(submsg); - const struct upb_MiniTableEnum* UPB_PRIVATE(subenum); + const upb_MiniTable* UPB_PRIVATE(submsg); + const upb_MiniTableEnum* UPB_PRIVATE(subenum); }; #ifdef __cplusplus extern "C" { #endif -UPB_INLINE union upb_MiniTableSub UPB_PRIVATE(_upb_MiniTableSub_FromEnum)( - const struct upb_MiniTableEnum* subenum) { - union upb_MiniTableSub out; +UPB_INLINE upb_MiniTableSub +UPB_PRIVATE(_upb_MiniTableSub_FromEnum)(const upb_MiniTableEnum* subenum) { + upb_MiniTableSub out; out.UPB_PRIVATE(subenum) = subenum; return out; } -UPB_INLINE union upb_MiniTableSub UPB_PRIVATE(_upb_MiniTableSub_FromMessage)( - const struct upb_MiniTable* submsg) { - union upb_MiniTableSub out; +UPB_INLINE upb_MiniTableSub +UPB_PRIVATE(_upb_MiniTableSub_FromMessage)(const upb_MiniTable* submsg) { + upb_MiniTableSub out; out.UPB_PRIVATE(submsg) = submsg; return out; } -UPB_INLINE const struct upb_MiniTableEnum* UPB_PRIVATE(_upb_MiniTableSub_Enum)( - const union upb_MiniTableSub sub) { +UPB_INLINE const upb_MiniTableEnum* UPB_PRIVATE(_upb_MiniTableSub_Enum)( + const upb_MiniTableSub sub) { return sub.UPB_PRIVATE(subenum); } -UPB_INLINE const struct upb_MiniTable* UPB_PRIVATE(_upb_MiniTableSub_Message)( - const union upb_MiniTableSub sub) { +UPB_INLINE const upb_MiniTable* UPB_PRIVATE(_upb_MiniTableSub_Message)( + const upb_MiniTableSub sub) { return sub.UPB_PRIVATE(submsg); } @@ -1478,10 +1347,11 @@ typedef enum { // 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. + // LINT.IfChange(minitable_struct_definition) struct upb_MiniTable { - const union upb_MiniTableSub* UPB_PRIVATE(subs); - const struct upb_MiniTableField* UPB_ONLYBITS(fields); + const upb_MiniTableSub* UPB_PRIVATE(subs); + const upb_MiniTableField* UPB_ONLYBITS(fields); // Must be aligned to sizeof(void*). Doesn't include internal members like // unknown fields, extension dict, pointer to msglayout, etc. @@ -1505,47 +1375,43 @@ struct upb_MiniTable { extern "C" { #endif -UPB_INLINE const struct upb_MiniTable* UPB_PRIVATE(_upb_MiniTable_Empty)(void) { - extern const struct upb_MiniTable UPB_PRIVATE(_kUpb_MiniTable_Empty); +UPB_INLINE const upb_MiniTable* UPB_PRIVATE(_upb_MiniTable_Empty)(void) { + extern const upb_MiniTable UPB_PRIVATE(_kUpb_MiniTable_Empty); return &UPB_PRIVATE(_kUpb_MiniTable_Empty); } -UPB_INLINE int UPB_PRIVATE(_upb_MiniTable_FieldCount)( - const struct upb_MiniTable* m) { +UPB_INLINE int UPB_PRIVATE(_upb_MiniTable_FieldCount)(const upb_MiniTable* m) { return m->UPB_ONLYBITS(field_count); } -UPB_INLINE bool UPB_PRIVATE(_upb_MiniTable_IsEmpty)( - const struct upb_MiniTable* m) { - extern const struct upb_MiniTable UPB_PRIVATE(_kUpb_MiniTable_Empty); +UPB_INLINE bool UPB_PRIVATE(_upb_MiniTable_IsEmpty)(const upb_MiniTable* m) { + extern const upb_MiniTable UPB_PRIVATE(_kUpb_MiniTable_Empty); return m == &UPB_PRIVATE(_kUpb_MiniTable_Empty); } -UPB_INLINE const struct upb_MiniTableField* UPB_PRIVATE( - _upb_MiniTable_GetFieldByIndex)(const struct upb_MiniTable* m, uint32_t i) { +UPB_INLINE const upb_MiniTableField* UPB_PRIVATE( + _upb_MiniTable_GetFieldByIndex)(const upb_MiniTable* m, uint32_t i) { return &m->UPB_ONLYBITS(fields)[i]; } -UPB_INLINE const union upb_MiniTableSub* UPB_PRIVATE( - _upb_MiniTable_GetSubByIndex)(const struct upb_MiniTable* m, uint32_t i) { +UPB_INLINE const upb_MiniTableSub* UPB_PRIVATE(_upb_MiniTable_GetSubByIndex)( + const upb_MiniTable* m, uint32_t i) { return &m->UPB_PRIVATE(subs)[i]; } -UPB_INLINE const struct upb_MiniTable* UPB_PRIVATE( - _upb_MiniTable_GetSubMessageTable)(const struct upb_MiniTable* m, - const struct upb_MiniTableField* f) { +UPB_INLINE const upb_MiniTable* UPB_PRIVATE(_upb_MiniTable_GetSubMessageTable)( + const upb_MiniTable* m, const upb_MiniTableField* f) { UPB_ASSERT(UPB_PRIVATE(_upb_MiniTableField_CType)(f) == kUpb_CType_Message); - const struct upb_MiniTable* ret = UPB_PRIVATE(_upb_MiniTableSub_Message)( + const upb_MiniTable* ret = UPB_PRIVATE(_upb_MiniTableSub_Message)( m->UPB_PRIVATE(subs)[f->UPB_PRIVATE(submsg_index)]); UPB_ASSUME(ret); return UPB_PRIVATE(_upb_MiniTable_IsEmpty)(ret) ? NULL : ret; } -UPB_INLINE const struct upb_MiniTableEnum* UPB_PRIVATE( - _upb_MiniTable_GetSubEnumTable)(const struct upb_MiniTable* m, - const struct upb_MiniTableField* f) { +UPB_INLINE const upb_MiniTableEnum* UPB_PRIVATE(_upb_MiniTable_GetSubEnumTable)( + const upb_MiniTable* m, const upb_MiniTableField* f) { UPB_ASSERT(UPB_PRIVATE(_upb_MiniTableField_CType)(f) == kUpb_CType_Enum); return UPB_PRIVATE(_upb_MiniTableSub_Enum)( m->UPB_PRIVATE(subs)[f->UPB_PRIVATE(submsg_index)]); @@ -1570,7 +1436,7 @@ UPB_INLINE const struct upb_MiniTableField* UPB_PRIVATE( } UPB_INLINE bool UPB_PRIVATE(_upb_MiniTable_MessageFieldIsLinked)( - const struct upb_MiniTable* m, const struct upb_MiniTableField* f) { + const upb_MiniTable* m, const upb_MiniTableField* f) { return UPB_PRIVATE(_upb_MiniTable_GetSubMessageTable)(m, f) != NULL; } @@ -1581,7 +1447,7 @@ UPB_INLINE bool UPB_PRIVATE(_upb_MiniTable_MessageFieldIsLinked)( // RequiredMask(1) => 0b10 (0x2) // RequiredMask(5) => 0b111110 (0x3e) UPB_INLINE uint64_t -UPB_PRIVATE(_upb_MiniTable_RequiredMask)(const struct upb_MiniTable* m) { +UPB_PRIVATE(_upb_MiniTable_RequiredMask)(const upb_MiniTable* m) { int n = m->UPB_PRIVATE(required_count); UPB_ASSERT(0 < n && n <= 63); return ((1ULL << n) - 1) << 1; @@ -1596,8 +1462,6 @@ UPB_PRIVATE(_upb_MiniTable_RequiredMask)(const struct upb_MiniTable* m) { // Must be last. -typedef struct upb_MiniTable upb_MiniTable; - #ifdef __cplusplus extern "C" { #endif @@ -1712,38 +1576,150 @@ size_t upb_Message_ExtensionCount(const upb_Message* msg); #include +#ifndef UPB_MINI_TABLE_FIELD_H_ +#define UPB_MINI_TABLE_FIELD_H_ + +#include + + +// Must be last. + +#ifdef __cplusplus +extern "C" { +#endif + +UPB_API_INLINE upb_CType upb_MiniTableField_CType(const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_CType)(f); +} + +UPB_API_INLINE bool upb_MiniTableField_HasPresence( + const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_HasPresence)(f); +} + +UPB_API_INLINE bool upb_MiniTableField_IsArray(const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_IsArray)(f); +} + +UPB_API_INLINE bool upb_MiniTableField_IsClosedEnum( + const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_IsClosedEnum)(f); +} + +UPB_API_INLINE bool upb_MiniTableField_IsExtension( + const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_IsExtension)(f); +} + +UPB_API_INLINE bool upb_MiniTableField_IsInOneof(const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_IsInOneof)(f); +} + +UPB_API_INLINE bool upb_MiniTableField_IsMap(const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_IsMap)(f); +} + +UPB_API_INLINE bool upb_MiniTableField_IsPacked(const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_IsPacked)(f); +} + +UPB_API_INLINE bool upb_MiniTableField_IsScalar(const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_IsScalar)(f); +} + +UPB_API_INLINE bool upb_MiniTableField_IsSubMessage( + const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_IsSubMessage)(f); +} + +UPB_API_INLINE uint32_t upb_MiniTableField_Number(const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_Number)(f); +} + +UPB_API_INLINE upb_FieldType +upb_MiniTableField_Type(const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_Type)(f); +} + +#ifdef __cplusplus +} /* extern "C" */ +#endif + + +#endif /* UPB_MINI_TABLE_FIELD_H_ */ + +#ifndef UPB_MINI_TABLE_SUB_H_ +#define UPB_MINI_TABLE_SUB_H_ + + +// Must be last. + +#ifdef __cplusplus +extern "C" { +#endif + +// Constructors + +UPB_API_INLINE upb_MiniTableSub +upb_MiniTableSub_FromEnum(const upb_MiniTableEnum* subenum) { + return UPB_PRIVATE(_upb_MiniTableSub_FromEnum)(subenum); +} + +UPB_API_INLINE upb_MiniTableSub +upb_MiniTableSub_FromMessage(const upb_MiniTable* submsg) { + return UPB_PRIVATE(_upb_MiniTableSub_FromMessage)(submsg); +} + +// Getters + +UPB_API_INLINE const upb_MiniTableEnum* upb_MiniTableSub_Enum( + upb_MiniTableSub sub) { + return UPB_PRIVATE(_upb_MiniTableSub_Enum)(sub); +} + +UPB_API_INLINE const upb_MiniTable* upb_MiniTableSub_Message( + upb_MiniTableSub sub) { + return UPB_PRIVATE(_upb_MiniTableSub_Message)(sub); +} + +#ifdef __cplusplus +} /* extern "C" */ +#endif + + +#endif /* UPB_MINI_TABLE_SUB_H_ */ + // Must be last. struct upb_MiniTableExtension { // Do not move this field. We need to be able to alias pointers. - struct upb_MiniTableField UPB_PRIVATE(field); + upb_MiniTableField UPB_PRIVATE(field); - const struct upb_MiniTable* UPB_PRIVATE(extendee); - union upb_MiniTableSub UPB_PRIVATE(sub); // NULL unless submsg or proto2 enum + const upb_MiniTable* UPB_PRIVATE(extendee); + upb_MiniTableSub UPB_PRIVATE(sub); // NULL unless submsg or proto2 enum }; #ifdef __cplusplus extern "C" { #endif -UPB_INLINE const struct upb_MiniTableField* UPB_PRIVATE( - _upb_MiniTableExtension_AsField)(const struct upb_MiniTableExtension* e) { - return (const struct upb_MiniTableField*)&e->UPB_PRIVATE(field); +UPB_INLINE const upb_MiniTableField* UPB_PRIVATE( + _upb_MiniTableExtension_AsField)(const upb_MiniTableExtension* e) { + return (const upb_MiniTableField*)&e->UPB_PRIVATE(field); } -UPB_INLINE uint32_t UPB_PRIVATE(_upb_MiniTableExtension_Number)( - const struct upb_MiniTableExtension* e) { +UPB_INLINE uint32_t +UPB_PRIVATE(_upb_MiniTableExtension_Number)(const upb_MiniTableExtension* e) { return e->UPB_PRIVATE(field).UPB_ONLYBITS(number); } -UPB_INLINE const struct upb_MiniTable* UPB_PRIVATE( - _upb_MiniTableExtension_GetSubMessage)( - const struct upb_MiniTableExtension* e) { - return e->UPB_PRIVATE(sub).UPB_PRIVATE(submsg); +UPB_INLINE const upb_MiniTable* UPB_PRIVATE( + _upb_MiniTableExtension_GetSubMessage)(const upb_MiniTableExtension* e) { + return upb_MiniTableSub_Message(e->UPB_PRIVATE(sub)); } UPB_INLINE void UPB_PRIVATE(_upb_MiniTableExtension_SetSubMessage)( - struct upb_MiniTableExtension* e, const struct upb_MiniTable* m) { + upb_MiniTableExtension* e, const upb_MiniTable* m) { e->UPB_PRIVATE(sub).UPB_PRIVATE(submsg) = m; } @@ -1756,13 +1732,11 @@ UPB_INLINE void UPB_PRIVATE(_upb_MiniTableExtension_SetSubMessage)( // Must be last. -typedef struct upb_MiniTableExtension upb_MiniTableExtension; - #ifdef __cplusplus extern "C" { #endif -UPB_API_INLINE const struct upb_MiniTableField* upb_MiniTableExtension_AsField( +UPB_API_INLINE const upb_MiniTableField* upb_MiniTableExtension_AsField( const upb_MiniTableExtension* e) { return UPB_PRIVATE(_upb_MiniTableExtension_AsField)(e); } @@ -1772,13 +1746,13 @@ upb_MiniTableExtension_Number(const upb_MiniTableExtension* e) { return UPB_PRIVATE(_upb_MiniTableExtension_Number)(e); } -UPB_API_INLINE const struct upb_MiniTable* upb_MiniTableExtension_GetSubMessage( +UPB_API_INLINE const upb_MiniTable* upb_MiniTableExtension_GetSubMessage( const upb_MiniTableExtension* e) { return UPB_PRIVATE(_upb_MiniTableExtension_GetSubMessage)(e); } UPB_API_INLINE void upb_MiniTableExtension_SetSubMessage( - upb_MiniTableExtension* e, const struct upb_MiniTable* m) { + upb_MiniTableExtension* e, const upb_MiniTable* m) { return UPB_PRIVATE(_upb_MiniTableExtension_SetSubMessage)(e, m); } @@ -2940,40 +2914,72 @@ UPB_INLINE void UPB_PRIVATE(_upb_Array_Set)(upb_Array* array, size_t i, #endif /* UPB_MESSAGE_INTERNAL_ARRAY_H_ */ -#ifndef UPB_MINI_TABLE_SUB_H_ -#define UPB_MINI_TABLE_SUB_H_ +#ifndef UPB_MINI_TABLE_ENUM_H_ +#define UPB_MINI_TABLE_ENUM_H_ + +#include + + +#ifndef UPB_MINI_TABLE_INTERNAL_ENUM_H_ +#define UPB_MINI_TABLE_INTERNAL_ENUM_H_ + +#include // Must be last. -typedef union upb_MiniTableSub upb_MiniTableSub; +struct upb_MiniTableEnum { + uint32_t UPB_PRIVATE(mask_limit); // Highest that can be tested with mask. + uint32_t UPB_PRIVATE(value_count); // Number of values after the bitfield. + uint32_t UPB_PRIVATE(data)[]; // Bitmask + enumerated values follow. +}; #ifdef __cplusplus extern "C" { #endif -// Constructors +UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableEnum_CheckValue)( + const upb_MiniTableEnum* e, uint32_t val) { + if (UPB_LIKELY(val < 64)) { + const uint64_t mask = + e->UPB_PRIVATE(data)[0] | ((uint64_t)e->UPB_PRIVATE(data)[1] << 32); + const uint64_t bit = 1ULL << val; + return (mask & bit) != 0; + } + if (UPB_LIKELY(val < e->UPB_PRIVATE(mask_limit))) { + const uint32_t mask = e->UPB_PRIVATE(data)[val / 32]; + const uint32_t bit = 1ULL << (val % 32); + return (mask & bit) != 0; + } -UPB_API_INLINE upb_MiniTableSub -upb_MiniTableSub_FromEnum(const struct upb_MiniTableEnum* subenum) { - return UPB_PRIVATE(_upb_MiniTableSub_FromEnum)(subenum); + // OPT: binary search long lists? + const uint32_t* start = + &e->UPB_PRIVATE(data)[e->UPB_PRIVATE(mask_limit) / 32]; + const uint32_t* limit = &e->UPB_PRIVATE( + data)[e->UPB_PRIVATE(mask_limit) / 32 + e->UPB_PRIVATE(value_count)]; + for (const uint32_t* p = start; p < limit; p++) { + if (*p == val) return true; + } + return false; } -UPB_API_INLINE upb_MiniTableSub -upb_MiniTableSub_FromMessage(const struct upb_MiniTable* submsg) { - return UPB_PRIVATE(_upb_MiniTableSub_FromMessage)(submsg); -} +#ifdef __cplusplus +} /* extern "C" */ +#endif -// Getters -UPB_API_INLINE const struct upb_MiniTableEnum* upb_MiniTableSub_Enum( - upb_MiniTableSub sub) { - return UPB_PRIVATE(_upb_MiniTableSub_Enum)(sub); -} +#endif /* UPB_MINI_TABLE_INTERNAL_ENUM_H_ */ -UPB_API_INLINE const struct upb_MiniTable* upb_MiniTableSub_Message( - upb_MiniTableSub sub) { - return UPB_PRIVATE(_upb_MiniTableSub_Message)(sub); +// Must be last + +#ifdef __cplusplus +extern "C" { +#endif + +// Validates enum value against range defined by enum mini table. +UPB_INLINE bool upb_MiniTableEnum_CheckValue(const upb_MiniTableEnum* e, + uint32_t val) { + return UPB_PRIVATE(_upb_MiniTableEnum_CheckValue)(e, val); } #ifdef __cplusplus @@ -2981,7 +2987,7 @@ UPB_API_INLINE const struct upb_MiniTable* upb_MiniTableSub_Message( #endif -#endif /* UPB_MINI_TABLE_SUB_H_ */ +#endif /* UPB_MINI_TABLE_ENUM_H_ */ // Must be last. @@ -3747,12 +3753,13 @@ UPB_API const upb_MiniTableExtension* upb_ExtensionRegistry_Lookup( #ifndef UPB_MINI_TABLE_INTERNAL_FILE_H_ #define UPB_MINI_TABLE_INTERNAL_FILE_H_ + // Must be last. struct upb_MiniTableFile { - const struct upb_MiniTable** UPB_PRIVATE(msgs); - const struct upb_MiniTableEnum** UPB_PRIVATE(enums); - const struct upb_MiniTableExtension** UPB_PRIVATE(exts); + const upb_MiniTable** UPB_PRIVATE(msgs); + const upb_MiniTableEnum** UPB_PRIVATE(enums); + const upb_MiniTableExtension** UPB_PRIVATE(exts); int UPB_PRIVATE(msg_count); int UPB_PRIVATE(enum_count); int UPB_PRIVATE(ext_count); @@ -3763,34 +3770,34 @@ extern "C" { #endif UPB_INLINE int UPB_PRIVATE(_upb_MiniTableFile_EnumCount)( - const struct upb_MiniTableFile* f) { + const upb_MiniTableFile* f) { return f->UPB_PRIVATE(enum_count); } UPB_INLINE int UPB_PRIVATE(_upb_MiniTableFile_ExtensionCount)( - const struct upb_MiniTableFile* f) { + const upb_MiniTableFile* f) { return f->UPB_PRIVATE(ext_count); } UPB_INLINE int UPB_PRIVATE(_upb_MiniTableFile_MessageCount)( - const struct upb_MiniTableFile* f) { + const upb_MiniTableFile* f) { return f->UPB_PRIVATE(msg_count); } -UPB_INLINE const struct upb_MiniTableEnum* UPB_PRIVATE(_upb_MiniTableFile_Enum)( - const struct upb_MiniTableFile* f, int i) { +UPB_INLINE const upb_MiniTableEnum* UPB_PRIVATE(_upb_MiniTableFile_Enum)( + const upb_MiniTableFile* f, int i) { UPB_ASSERT(i < f->UPB_PRIVATE(enum_count)); return f->UPB_PRIVATE(enums)[i]; } -UPB_INLINE const struct upb_MiniTableExtension* UPB_PRIVATE( - _upb_MiniTableFile_Extension)(const struct upb_MiniTableFile* f, int i) { +UPB_INLINE const upb_MiniTableExtension* UPB_PRIVATE( + _upb_MiniTableFile_Extension)(const upb_MiniTableFile* f, int i) { UPB_ASSERT(i < f->UPB_PRIVATE(ext_count)); return f->UPB_PRIVATE(exts)[i]; } -UPB_INLINE const struct upb_MiniTable* UPB_PRIVATE(_upb_MiniTableFile_Message)( - const struct upb_MiniTableFile* f, int i) { +UPB_INLINE const upb_MiniTable* UPB_PRIVATE(_upb_MiniTableFile_Message)( + const upb_MiniTableFile* f, int i) { UPB_ASSERT(i < f->UPB_PRIVATE(msg_count)); return f->UPB_PRIVATE(msgs)[i]; } @@ -3802,15 +3809,13 @@ UPB_INLINE const struct upb_MiniTable* UPB_PRIVATE(_upb_MiniTableFile_Message)( #endif /* UPB_MINI_TABLE_INTERNAL_FILE_H_ */ -typedef struct upb_MiniTableFile upb_MiniTableFile; - // Must be last. #ifdef __cplusplus extern "C" { #endif -UPB_API_INLINE const struct upb_MiniTableEnum* upb_MiniTableFile_Enum( +UPB_API_INLINE const upb_MiniTableEnum* upb_MiniTableFile_Enum( const upb_MiniTableFile* f, int i) { return UPB_PRIVATE(_upb_MiniTableFile_Enum)(f, i); } @@ -3819,7 +3824,7 @@ UPB_API_INLINE int upb_MiniTableFile_EnumCount(const upb_MiniTableFile* f) { return UPB_PRIVATE(_upb_MiniTableFile_EnumCount)(f); } -UPB_API_INLINE const struct upb_MiniTableExtension* upb_MiniTableFile_Extension( +UPB_API_INLINE const upb_MiniTableExtension* upb_MiniTableFile_Extension( const upb_MiniTableFile* f, int i) { return UPB_PRIVATE(_upb_MiniTableFile_Extension)(f, i); } @@ -3829,7 +3834,7 @@ UPB_API_INLINE int upb_MiniTableFile_ExtensionCount( return UPB_PRIVATE(_upb_MiniTableFile_ExtensionCount)(f); } -UPB_API_INLINE const struct upb_MiniTable* upb_MiniTableFile_Message( +UPB_API_INLINE const upb_MiniTable* upb_MiniTableFile_Message( const upb_MiniTableFile* f, int i) { return UPB_PRIVATE(_upb_MiniTableFile_Message)(f, i); } diff --git a/ruby/ext/google/protobuf_c/ruby-upb.c b/ruby/ext/google/protobuf_c/ruby-upb.c index 7492b92102b3e..6bff74c010044 100644 --- a/ruby/ext/google/protobuf_c/ruby-upb.c +++ b/ruby/ext/google/protobuf_c/ruby-upb.c @@ -5710,9 +5710,9 @@ static upb_Map* upb_Message_Map_DeepClone(const upb_Map* map, upb_Array* upb_Array_DeepClone(const upb_Array* array, upb_CType value_type, const upb_MiniTable* sub, upb_Arena* arena) { - size_t size = array->UPB_PRIVATE(size); - upb_Array* cloned_array = - UPB_PRIVATE(_upb_Array_New)(arena, size, upb_CType_SizeLg2(value_type)); + const size_t size = array->UPB_PRIVATE(size); + const int lg2 = UPB_PRIVATE(_upb_CType_SizeLg2)(value_type); + upb_Array* cloned_array = UPB_PRIVATE(_upb_Array_New)(arena, size, lg2); if (!cloned_array) { return NULL; } @@ -5900,7 +5900,8 @@ upb_Message* upb_Message_ShallowClone(const upb_Message* msg, // Must be last. upb_Array* upb_Array_New(upb_Arena* a, upb_CType type) { - return UPB_PRIVATE(_upb_Array_New)(a, 4, upb_CType_SizeLg2(type)); + const int lg2 = UPB_PRIVATE(_upb_CType_SizeLg2)(type); + return UPB_PRIVATE(_upb_Array_New)(a, 4, lg2); } const void* upb_Array_DataPtr(const upb_Array* arr) { @@ -7929,6 +7930,23 @@ const upb_MiniTableExtension* upb_ExtensionRegistry_Lookup( } +#include + +// Must be last. + +// A MiniTable for an empty message, used for unlinked sub-messages. +const upb_MiniTable UPB_PRIVATE(_kUpb_MiniTable_Empty) = { + .UPB_PRIVATE(subs) = NULL, + .UPB_PRIVATE(fields) = NULL, + .UPB_PRIVATE(size) = 0, + .UPB_PRIVATE(field_count) = 0, + .UPB_PRIVATE(ext) = kUpb_ExtMode_NonExtendable, + .UPB_PRIVATE(dense_below) = 0, + .UPB_PRIVATE(table_mask) = -1, + .UPB_PRIVATE(required_count) = 0, +}; + + #include #include #include @@ -7996,23 +8014,6 @@ bool upb_MiniTable_NextOneofField(const upb_MiniTable* m, } -#include - -// Must be last. - -// A MiniTable for an empty message, used for unlinked sub-messages. -const struct upb_MiniTable UPB_PRIVATE(_kUpb_MiniTable_Empty) = { - .UPB_PRIVATE(subs) = NULL, - .UPB_PRIVATE(fields) = NULL, - .UPB_PRIVATE(size) = 0, - .UPB_PRIVATE(field_count) = 0, - .UPB_PRIVATE(ext) = kUpb_ExtMode_NonExtendable, - .UPB_PRIVATE(dense_below) = 0, - .UPB_PRIVATE(table_mask) = -1, - .UPB_PRIVATE(required_count) = 0, -}; - - // Must be last. @@ -12772,7 +12773,7 @@ static const char* _upb_Decoder_DecodeEnumPacked( upb_Array* _upb_Decoder_CreateArray(upb_Decoder* d, const upb_MiniTableField* field) { const upb_FieldType field_type = field->UPB_PRIVATE(descriptortype); - const size_t lg2 = upb_FieldType_SizeLg2(field_type); + const size_t lg2 = UPB_PRIVATE(_upb_FieldType_SizeLg2)(field_type); upb_Array* ret = UPB_PRIVATE(_upb_Array_New)(&d->arena, 4, lg2); if (!ret) _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_OutOfMemory); return ret; diff --git a/ruby/ext/google/protobuf_c/ruby-upb.h b/ruby/ext/google/protobuf_c/ruby-upb.h index d67f23518d9cf..7ef7460eae5c3 100755 --- a/ruby/ext/google/protobuf_c/ruby-upb.h +++ b/ruby/ext/google/protobuf_c/ruby-upb.h @@ -981,84 +981,8 @@ UPB_API void* upb_Array_MutableDataPtr(upb_Array* arr); #define UPB_MINI_TABLE_MESSAGE_H_ -#ifndef UPB_MINI_TABLE_ENUM_H_ -#define UPB_MINI_TABLE_ENUM_H_ - -#include - - -#ifndef UPB_MINI_TABLE_INTERNAL_ENUM_H_ -#define UPB_MINI_TABLE_INTERNAL_ENUM_H_ - -#include - -// Must be last. - -struct upb_MiniTableEnum { - uint32_t UPB_PRIVATE(mask_limit); // Highest that can be tested with mask. - uint32_t UPB_PRIVATE(value_count); // Number of values after the bitfield. - uint32_t UPB_PRIVATE(data)[]; // Bitmask + enumerated values follow. -}; - -#ifdef __cplusplus -extern "C" { -#endif - -UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableEnum_CheckValue)( - const struct upb_MiniTableEnum* e, uint32_t val) { - if (UPB_LIKELY(val < 64)) { - const uint64_t mask = - e->UPB_PRIVATE(data)[0] | ((uint64_t)e->UPB_PRIVATE(data)[1] << 32); - const uint64_t bit = 1ULL << val; - return (mask & bit) != 0; - } - if (UPB_LIKELY(val < e->UPB_PRIVATE(mask_limit))) { - const uint32_t mask = e->UPB_PRIVATE(data)[val / 32]; - const uint32_t bit = 1ULL << (val % 32); - return (mask & bit) != 0; - } - - // OPT: binary search long lists? - const uint32_t* start = - &e->UPB_PRIVATE(data)[e->UPB_PRIVATE(mask_limit) / 32]; - const uint32_t* limit = &e->UPB_PRIVATE( - data)[e->UPB_PRIVATE(mask_limit) / 32 + e->UPB_PRIVATE(value_count)]; - for (const uint32_t* p = start; p < limit; p++) { - if (*p == val) return true; - } - return false; -} - -#ifdef __cplusplus -} /* extern "C" */ -#endif - - -#endif /* UPB_MINI_TABLE_INTERNAL_ENUM_H_ */ - -// Must be last - -typedef struct upb_MiniTableEnum upb_MiniTableEnum; - -#ifdef __cplusplus -extern "C" { -#endif - -// Validates enum value against range defined by enum mini table. -UPB_INLINE bool upb_MiniTableEnum_CheckValue(const upb_MiniTableEnum* e, - uint32_t val) { - return UPB_PRIVATE(_upb_MiniTableEnum_CheckValue)(e, val); -} - -#ifdef __cplusplus -} /* extern "C" */ -#endif - - -#endif /* UPB_MINI_TABLE_ENUM_H_ */ - -#ifndef UPB_MINI_TABLE_FIELD_H_ -#define UPB_MINI_TABLE_FIELD_H_ +#ifndef UPB_MINI_TABLE_INTERNAL_MESSAGE_H_ +#define UPB_MINI_TABLE_INTERNAL_MESSAGE_H_ #include @@ -1084,7 +1008,7 @@ extern "C" { #endif // Return the log2 of the storage size in bytes for a upb_CType -UPB_INLINE int upb_CType_SizeLg2(upb_CType c_type) { +UPB_INLINE int UPB_PRIVATE(_upb_CType_SizeLg2)(upb_CType c_type) { static const int8_t size[] = { 0, // kUpb_CType_Bool 2, // kUpb_CType_Float @@ -1104,7 +1028,7 @@ UPB_INLINE int upb_CType_SizeLg2(upb_CType c_type) { } // Return the log2 of the storage size in bytes for a upb_FieldType -UPB_INLINE int upb_FieldType_SizeLg2(upb_FieldType field_type) { +UPB_INLINE int UPB_PRIVATE(_upb_FieldType_SizeLg2)(upb_FieldType field_type) { static const int8_t size[] = { 3, // kUpb_FieldType_Double 2, // kUpb_FieldType_Float @@ -1137,6 +1061,21 @@ UPB_INLINE int upb_FieldType_SizeLg2(upb_FieldType field_type) { #endif /* UPB_MINI_TABLE_INTERNAL_SIZE_LOG2_H_ */ +#ifndef UPB_MINI_TABLE_TYPES_H_ +#define UPB_MINI_TABLE_TYPES_H_ + +// Minitable types are recursively defined so declare them all together here. + +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; + +#endif /* UPB_MINI_TABLE_TYPES_H_ */ + // Must be last. // LINT.IfChange(struct_definition) @@ -1197,47 +1136,47 @@ extern "C" { #endif UPB_INLINE upb_FieldMode -UPB_PRIVATE(_upb_MiniTableField_Mode)(const struct upb_MiniTableField* f) { +UPB_PRIVATE(_upb_MiniTableField_Mode)(const upb_MiniTableField* f) { return (upb_FieldMode)(f->UPB_ONLYBITS(mode) & kUpb_FieldMode_Mask); } UPB_INLINE upb_FieldRep -UPB_PRIVATE(_upb_MiniTableField_GetRep)(const struct upb_MiniTableField* f) { +UPB_PRIVATE(_upb_MiniTableField_GetRep)(const upb_MiniTableField* f) { return (upb_FieldRep)(f->UPB_ONLYBITS(mode) >> kUpb_FieldRep_Shift); } UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsArray)( - const struct upb_MiniTableField* f) { + const upb_MiniTableField* f) { return UPB_PRIVATE(_upb_MiniTableField_Mode)(f) == kUpb_FieldMode_Array; } UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsMap)( - const struct upb_MiniTableField* f) { + const upb_MiniTableField* f) { return UPB_PRIVATE(_upb_MiniTableField_Mode)(f) == kUpb_FieldMode_Map; } UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsScalar)( - const struct upb_MiniTableField* f) { + const upb_MiniTableField* f) { return UPB_PRIVATE(_upb_MiniTableField_Mode)(f) == kUpb_FieldMode_Scalar; } UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsAlternate)( - const struct upb_MiniTableField* f) { + const upb_MiniTableField* f) { return (f->UPB_ONLYBITS(mode) & kUpb_LabelFlags_IsAlternate) != 0; } UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsExtension)( - const struct upb_MiniTableField* f) { + const upb_MiniTableField* f) { return (f->UPB_ONLYBITS(mode) & kUpb_LabelFlags_IsExtension) != 0; } UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsPacked)( - const struct upb_MiniTableField* f) { + const upb_MiniTableField* f) { return (f->UPB_ONLYBITS(mode) & kUpb_LabelFlags_IsPacked) != 0; } UPB_INLINE upb_FieldType -UPB_PRIVATE(_upb_MiniTableField_Type)(const struct upb_MiniTableField* f) { +UPB_PRIVATE(_upb_MiniTableField_Type)(const upb_MiniTableField* f) { const upb_FieldType type = (upb_FieldType)f->UPB_PRIVATE(descriptortype); if (UPB_PRIVATE(_upb_MiniTableField_IsAlternate)(f)) { if (type == kUpb_FieldType_Int32) return kUpb_FieldType_Enum; @@ -1248,7 +1187,7 @@ UPB_PRIVATE(_upb_MiniTableField_Type)(const struct upb_MiniTableField* f) { } UPB_INLINE upb_CType -UPB_PRIVATE(_upb_MiniTableField_CType)(const struct upb_MiniTableField* f) { +UPB_PRIVATE(_upb_MiniTableField_CType)(const upb_MiniTableField* f) { return upb_FieldType_CType(UPB_PRIVATE(_upb_MiniTableField_Type)(f)); } @@ -1267,23 +1206,23 @@ _upb_MiniTableField_HasbitOffset(const struct upb_MiniTableField* f) { } UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsClosedEnum)( - const struct upb_MiniTableField* f) { + const upb_MiniTableField* f) { return f->UPB_PRIVATE(descriptortype) == kUpb_FieldType_Enum; } UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsInOneof)( - const struct upb_MiniTableField* f) { + const upb_MiniTableField* f) { return f->presence < 0; } UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsSubMessage)( - const struct upb_MiniTableField* f) { + const upb_MiniTableField* f) { return f->UPB_PRIVATE(descriptortype) == kUpb_FieldType_Message || f->UPB_PRIVATE(descriptortype) == kUpb_FieldType_Group; } UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_HasPresence)( - const struct upb_MiniTableField* f) { + const upb_MiniTableField* f) { if (UPB_PRIVATE(_upb_MiniTableField_IsExtension)(f)) { return UPB_PRIVATE(_upb_MiniTableField_IsScalar)(f); } else { @@ -1308,7 +1247,7 @@ _upb_MiniTableField_OneofOffset(const struct upb_MiniTableField* f) { } UPB_INLINE void UPB_PRIVATE(_upb_MiniTableField_CheckIsArray)( - const struct upb_MiniTableField* f) { + const upb_MiniTableField* f) { UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_NativePointer); UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_IsArray)(f)); @@ -1316,16 +1255,17 @@ UPB_INLINE void UPB_PRIVATE(_upb_MiniTableField_CheckIsArray)( } UPB_INLINE void UPB_PRIVATE(_upb_MiniTableField_CheckIsMap)( - const struct upb_MiniTableField* f) { + const upb_MiniTableField* f) { UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_NativePointer); UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_IsMap)(f)); UPB_ASSUME(f->presence == 0); } -UPB_INLINE size_t UPB_PRIVATE(_upb_MiniTableField_ElemSizeLg2)( - const struct upb_MiniTableField* f) { - return upb_FieldType_SizeLg2((upb_FieldType)f->UPB_PRIVATE(descriptortype)); +UPB_INLINE size_t +UPB_PRIVATE(_upb_MiniTableField_ElemSizeLg2)(const upb_MiniTableField* f) { + const upb_FieldType field_type = UPB_PRIVATE(_upb_MiniTableField_Type)(f); + return UPB_PRIVATE(_upb_FieldType_SizeLg2)(field_type); } // LINT.ThenChange(//depot/google3/third_party/upb/bits/typescript/mini_table_field.ts) @@ -1337,113 +1277,42 @@ UPB_INLINE size_t UPB_PRIVATE(_upb_MiniTableField_ElemSizeLg2)( #endif /* UPB_MINI_TABLE_INTERNAL_FIELD_H_ */ -// Must be last. - -typedef struct upb_MiniTableField upb_MiniTableField; - -#ifdef __cplusplus -extern "C" { -#endif - -UPB_API_INLINE upb_CType upb_MiniTableField_CType(const upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTableField_CType)(f); -} - -UPB_API_INLINE bool upb_MiniTableField_HasPresence( - const upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTableField_HasPresence)(f); -} - -UPB_API_INLINE bool upb_MiniTableField_IsArray(const upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTableField_IsArray)(f); -} - -UPB_API_INLINE bool upb_MiniTableField_IsClosedEnum( - const upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTableField_IsClosedEnum)(f); -} - -UPB_API_INLINE bool upb_MiniTableField_IsExtension( - const upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTableField_IsExtension)(f); -} - -UPB_API_INLINE bool upb_MiniTableField_IsInOneof(const upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTableField_IsInOneof)(f); -} - -UPB_API_INLINE bool upb_MiniTableField_IsMap(const upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTableField_IsMap)(f); -} - -UPB_API_INLINE bool upb_MiniTableField_IsPacked(const upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTableField_IsPacked)(f); -} - -UPB_API_INLINE bool upb_MiniTableField_IsScalar(const upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTableField_IsScalar)(f); -} - -UPB_API_INLINE bool upb_MiniTableField_IsSubMessage( - const upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTableField_IsSubMessage)(f); -} - -UPB_API_INLINE uint32_t upb_MiniTableField_Number(const upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTableField_Number)(f); -} - -UPB_API_INLINE upb_FieldType -upb_MiniTableField_Type(const upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTableField_Type)(f); -} - -#ifdef __cplusplus -} /* extern "C" */ -#endif - - -#endif /* UPB_MINI_TABLE_FIELD_H_ */ - -#ifndef UPB_MINI_TABLE_INTERNAL_MESSAGE_H_ -#define UPB_MINI_TABLE_INTERNAL_MESSAGE_H_ - - #ifndef UPB_MINI_TABLE_INTERNAL_SUB_H_ #define UPB_MINI_TABLE_INTERNAL_SUB_H_ + // Must be last. union upb_MiniTableSub { - const struct upb_MiniTable* UPB_PRIVATE(submsg); - const struct upb_MiniTableEnum* UPB_PRIVATE(subenum); + const upb_MiniTable* UPB_PRIVATE(submsg); + const upb_MiniTableEnum* UPB_PRIVATE(subenum); }; #ifdef __cplusplus extern "C" { #endif -UPB_INLINE union upb_MiniTableSub UPB_PRIVATE(_upb_MiniTableSub_FromEnum)( - const struct upb_MiniTableEnum* subenum) { - union upb_MiniTableSub out; +UPB_INLINE upb_MiniTableSub +UPB_PRIVATE(_upb_MiniTableSub_FromEnum)(const upb_MiniTableEnum* subenum) { + upb_MiniTableSub out; out.UPB_PRIVATE(subenum) = subenum; return out; } -UPB_INLINE union upb_MiniTableSub UPB_PRIVATE(_upb_MiniTableSub_FromMessage)( - const struct upb_MiniTable* submsg) { - union upb_MiniTableSub out; +UPB_INLINE upb_MiniTableSub +UPB_PRIVATE(_upb_MiniTableSub_FromMessage)(const upb_MiniTable* submsg) { + upb_MiniTableSub out; out.UPB_PRIVATE(submsg) = submsg; return out; } -UPB_INLINE const struct upb_MiniTableEnum* UPB_PRIVATE(_upb_MiniTableSub_Enum)( - const union upb_MiniTableSub sub) { +UPB_INLINE const upb_MiniTableEnum* UPB_PRIVATE(_upb_MiniTableSub_Enum)( + const upb_MiniTableSub sub) { return sub.UPB_PRIVATE(subenum); } -UPB_INLINE const struct upb_MiniTable* UPB_PRIVATE(_upb_MiniTableSub_Message)( - const union upb_MiniTableSub sub) { +UPB_INLINE const upb_MiniTable* UPB_PRIVATE(_upb_MiniTableSub_Message)( + const upb_MiniTableSub sub) { return sub.UPB_PRIVATE(submsg); } @@ -1480,10 +1349,11 @@ typedef enum { // 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. + // LINT.IfChange(minitable_struct_definition) struct upb_MiniTable { - const union upb_MiniTableSub* UPB_PRIVATE(subs); - const struct upb_MiniTableField* UPB_ONLYBITS(fields); + const upb_MiniTableSub* UPB_PRIVATE(subs); + const upb_MiniTableField* UPB_ONLYBITS(fields); // Must be aligned to sizeof(void*). Doesn't include internal members like // unknown fields, extension dict, pointer to msglayout, etc. @@ -1507,47 +1377,43 @@ struct upb_MiniTable { extern "C" { #endif -UPB_INLINE const struct upb_MiniTable* UPB_PRIVATE(_upb_MiniTable_Empty)(void) { - extern const struct upb_MiniTable UPB_PRIVATE(_kUpb_MiniTable_Empty); +UPB_INLINE const upb_MiniTable* UPB_PRIVATE(_upb_MiniTable_Empty)(void) { + extern const upb_MiniTable UPB_PRIVATE(_kUpb_MiniTable_Empty); return &UPB_PRIVATE(_kUpb_MiniTable_Empty); } -UPB_INLINE int UPB_PRIVATE(_upb_MiniTable_FieldCount)( - const struct upb_MiniTable* m) { +UPB_INLINE int UPB_PRIVATE(_upb_MiniTable_FieldCount)(const upb_MiniTable* m) { return m->UPB_ONLYBITS(field_count); } -UPB_INLINE bool UPB_PRIVATE(_upb_MiniTable_IsEmpty)( - const struct upb_MiniTable* m) { - extern const struct upb_MiniTable UPB_PRIVATE(_kUpb_MiniTable_Empty); +UPB_INLINE bool UPB_PRIVATE(_upb_MiniTable_IsEmpty)(const upb_MiniTable* m) { + extern const upb_MiniTable UPB_PRIVATE(_kUpb_MiniTable_Empty); return m == &UPB_PRIVATE(_kUpb_MiniTable_Empty); } -UPB_INLINE const struct upb_MiniTableField* UPB_PRIVATE( - _upb_MiniTable_GetFieldByIndex)(const struct upb_MiniTable* m, uint32_t i) { +UPB_INLINE const upb_MiniTableField* UPB_PRIVATE( + _upb_MiniTable_GetFieldByIndex)(const upb_MiniTable* m, uint32_t i) { return &m->UPB_ONLYBITS(fields)[i]; } -UPB_INLINE const union upb_MiniTableSub* UPB_PRIVATE( - _upb_MiniTable_GetSubByIndex)(const struct upb_MiniTable* m, uint32_t i) { +UPB_INLINE const upb_MiniTableSub* UPB_PRIVATE(_upb_MiniTable_GetSubByIndex)( + const upb_MiniTable* m, uint32_t i) { return &m->UPB_PRIVATE(subs)[i]; } -UPB_INLINE const struct upb_MiniTable* UPB_PRIVATE( - _upb_MiniTable_GetSubMessageTable)(const struct upb_MiniTable* m, - const struct upb_MiniTableField* f) { +UPB_INLINE const upb_MiniTable* UPB_PRIVATE(_upb_MiniTable_GetSubMessageTable)( + const upb_MiniTable* m, const upb_MiniTableField* f) { UPB_ASSERT(UPB_PRIVATE(_upb_MiniTableField_CType)(f) == kUpb_CType_Message); - const struct upb_MiniTable* ret = UPB_PRIVATE(_upb_MiniTableSub_Message)( + const upb_MiniTable* ret = UPB_PRIVATE(_upb_MiniTableSub_Message)( m->UPB_PRIVATE(subs)[f->UPB_PRIVATE(submsg_index)]); UPB_ASSUME(ret); return UPB_PRIVATE(_upb_MiniTable_IsEmpty)(ret) ? NULL : ret; } -UPB_INLINE const struct upb_MiniTableEnum* UPB_PRIVATE( - _upb_MiniTable_GetSubEnumTable)(const struct upb_MiniTable* m, - const struct upb_MiniTableField* f) { +UPB_INLINE const upb_MiniTableEnum* UPB_PRIVATE(_upb_MiniTable_GetSubEnumTable)( + const upb_MiniTable* m, const upb_MiniTableField* f) { UPB_ASSERT(UPB_PRIVATE(_upb_MiniTableField_CType)(f) == kUpb_CType_Enum); return UPB_PRIVATE(_upb_MiniTableSub_Enum)( m->UPB_PRIVATE(subs)[f->UPB_PRIVATE(submsg_index)]); @@ -1572,7 +1438,7 @@ UPB_INLINE const struct upb_MiniTableField* UPB_PRIVATE( } UPB_INLINE bool UPB_PRIVATE(_upb_MiniTable_MessageFieldIsLinked)( - const struct upb_MiniTable* m, const struct upb_MiniTableField* f) { + const upb_MiniTable* m, const upb_MiniTableField* f) { return UPB_PRIVATE(_upb_MiniTable_GetSubMessageTable)(m, f) != NULL; } @@ -1583,7 +1449,7 @@ UPB_INLINE bool UPB_PRIVATE(_upb_MiniTable_MessageFieldIsLinked)( // RequiredMask(1) => 0b10 (0x2) // RequiredMask(5) => 0b111110 (0x3e) UPB_INLINE uint64_t -UPB_PRIVATE(_upb_MiniTable_RequiredMask)(const struct upb_MiniTable* m) { +UPB_PRIVATE(_upb_MiniTable_RequiredMask)(const upb_MiniTable* m) { int n = m->UPB_PRIVATE(required_count); UPB_ASSERT(0 < n && n <= 63); return ((1ULL << n) - 1) << 1; @@ -1598,8 +1464,6 @@ UPB_PRIVATE(_upb_MiniTable_RequiredMask)(const struct upb_MiniTable* m) { // Must be last. -typedef struct upb_MiniTable upb_MiniTable; - #ifdef __cplusplus extern "C" { #endif @@ -1714,38 +1578,150 @@ size_t upb_Message_ExtensionCount(const upb_Message* msg); #include +#ifndef UPB_MINI_TABLE_FIELD_H_ +#define UPB_MINI_TABLE_FIELD_H_ + +#include + + +// Must be last. + +#ifdef __cplusplus +extern "C" { +#endif + +UPB_API_INLINE upb_CType upb_MiniTableField_CType(const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_CType)(f); +} + +UPB_API_INLINE bool upb_MiniTableField_HasPresence( + const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_HasPresence)(f); +} + +UPB_API_INLINE bool upb_MiniTableField_IsArray(const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_IsArray)(f); +} + +UPB_API_INLINE bool upb_MiniTableField_IsClosedEnum( + const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_IsClosedEnum)(f); +} + +UPB_API_INLINE bool upb_MiniTableField_IsExtension( + const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_IsExtension)(f); +} + +UPB_API_INLINE bool upb_MiniTableField_IsInOneof(const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_IsInOneof)(f); +} + +UPB_API_INLINE bool upb_MiniTableField_IsMap(const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_IsMap)(f); +} + +UPB_API_INLINE bool upb_MiniTableField_IsPacked(const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_IsPacked)(f); +} + +UPB_API_INLINE bool upb_MiniTableField_IsScalar(const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_IsScalar)(f); +} + +UPB_API_INLINE bool upb_MiniTableField_IsSubMessage( + const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_IsSubMessage)(f); +} + +UPB_API_INLINE uint32_t upb_MiniTableField_Number(const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_Number)(f); +} + +UPB_API_INLINE upb_FieldType +upb_MiniTableField_Type(const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_Type)(f); +} + +#ifdef __cplusplus +} /* extern "C" */ +#endif + + +#endif /* UPB_MINI_TABLE_FIELD_H_ */ + +#ifndef UPB_MINI_TABLE_SUB_H_ +#define UPB_MINI_TABLE_SUB_H_ + + +// Must be last. + +#ifdef __cplusplus +extern "C" { +#endif + +// Constructors + +UPB_API_INLINE upb_MiniTableSub +upb_MiniTableSub_FromEnum(const upb_MiniTableEnum* subenum) { + return UPB_PRIVATE(_upb_MiniTableSub_FromEnum)(subenum); +} + +UPB_API_INLINE upb_MiniTableSub +upb_MiniTableSub_FromMessage(const upb_MiniTable* submsg) { + return UPB_PRIVATE(_upb_MiniTableSub_FromMessage)(submsg); +} + +// Getters + +UPB_API_INLINE const upb_MiniTableEnum* upb_MiniTableSub_Enum( + upb_MiniTableSub sub) { + return UPB_PRIVATE(_upb_MiniTableSub_Enum)(sub); +} + +UPB_API_INLINE const upb_MiniTable* upb_MiniTableSub_Message( + upb_MiniTableSub sub) { + return UPB_PRIVATE(_upb_MiniTableSub_Message)(sub); +} + +#ifdef __cplusplus +} /* extern "C" */ +#endif + + +#endif /* UPB_MINI_TABLE_SUB_H_ */ + // Must be last. struct upb_MiniTableExtension { // Do not move this field. We need to be able to alias pointers. - struct upb_MiniTableField UPB_PRIVATE(field); + upb_MiniTableField UPB_PRIVATE(field); - const struct upb_MiniTable* UPB_PRIVATE(extendee); - union upb_MiniTableSub UPB_PRIVATE(sub); // NULL unless submsg or proto2 enum + const upb_MiniTable* UPB_PRIVATE(extendee); + upb_MiniTableSub UPB_PRIVATE(sub); // NULL unless submsg or proto2 enum }; #ifdef __cplusplus extern "C" { #endif -UPB_INLINE const struct upb_MiniTableField* UPB_PRIVATE( - _upb_MiniTableExtension_AsField)(const struct upb_MiniTableExtension* e) { - return (const struct upb_MiniTableField*)&e->UPB_PRIVATE(field); +UPB_INLINE const upb_MiniTableField* UPB_PRIVATE( + _upb_MiniTableExtension_AsField)(const upb_MiniTableExtension* e) { + return (const upb_MiniTableField*)&e->UPB_PRIVATE(field); } -UPB_INLINE uint32_t UPB_PRIVATE(_upb_MiniTableExtension_Number)( - const struct upb_MiniTableExtension* e) { +UPB_INLINE uint32_t +UPB_PRIVATE(_upb_MiniTableExtension_Number)(const upb_MiniTableExtension* e) { return e->UPB_PRIVATE(field).UPB_ONLYBITS(number); } -UPB_INLINE const struct upb_MiniTable* UPB_PRIVATE( - _upb_MiniTableExtension_GetSubMessage)( - const struct upb_MiniTableExtension* e) { - return e->UPB_PRIVATE(sub).UPB_PRIVATE(submsg); +UPB_INLINE const upb_MiniTable* UPB_PRIVATE( + _upb_MiniTableExtension_GetSubMessage)(const upb_MiniTableExtension* e) { + return upb_MiniTableSub_Message(e->UPB_PRIVATE(sub)); } UPB_INLINE void UPB_PRIVATE(_upb_MiniTableExtension_SetSubMessage)( - struct upb_MiniTableExtension* e, const struct upb_MiniTable* m) { + upb_MiniTableExtension* e, const upb_MiniTable* m) { e->UPB_PRIVATE(sub).UPB_PRIVATE(submsg) = m; } @@ -1758,13 +1734,11 @@ UPB_INLINE void UPB_PRIVATE(_upb_MiniTableExtension_SetSubMessage)( // Must be last. -typedef struct upb_MiniTableExtension upb_MiniTableExtension; - #ifdef __cplusplus extern "C" { #endif -UPB_API_INLINE const struct upb_MiniTableField* upb_MiniTableExtension_AsField( +UPB_API_INLINE const upb_MiniTableField* upb_MiniTableExtension_AsField( const upb_MiniTableExtension* e) { return UPB_PRIVATE(_upb_MiniTableExtension_AsField)(e); } @@ -1774,13 +1748,13 @@ upb_MiniTableExtension_Number(const upb_MiniTableExtension* e) { return UPB_PRIVATE(_upb_MiniTableExtension_Number)(e); } -UPB_API_INLINE const struct upb_MiniTable* upb_MiniTableExtension_GetSubMessage( +UPB_API_INLINE const upb_MiniTable* upb_MiniTableExtension_GetSubMessage( const upb_MiniTableExtension* e) { return UPB_PRIVATE(_upb_MiniTableExtension_GetSubMessage)(e); } UPB_API_INLINE void upb_MiniTableExtension_SetSubMessage( - upb_MiniTableExtension* e, const struct upb_MiniTable* m) { + upb_MiniTableExtension* e, const upb_MiniTable* m) { return UPB_PRIVATE(_upb_MiniTableExtension_SetSubMessage)(e, m); } @@ -2942,40 +2916,72 @@ UPB_INLINE void UPB_PRIVATE(_upb_Array_Set)(upb_Array* array, size_t i, #endif /* UPB_MESSAGE_INTERNAL_ARRAY_H_ */ -#ifndef UPB_MINI_TABLE_SUB_H_ -#define UPB_MINI_TABLE_SUB_H_ +#ifndef UPB_MINI_TABLE_ENUM_H_ +#define UPB_MINI_TABLE_ENUM_H_ + +#include + + +#ifndef UPB_MINI_TABLE_INTERNAL_ENUM_H_ +#define UPB_MINI_TABLE_INTERNAL_ENUM_H_ + +#include // Must be last. -typedef union upb_MiniTableSub upb_MiniTableSub; +struct upb_MiniTableEnum { + uint32_t UPB_PRIVATE(mask_limit); // Highest that can be tested with mask. + uint32_t UPB_PRIVATE(value_count); // Number of values after the bitfield. + uint32_t UPB_PRIVATE(data)[]; // Bitmask + enumerated values follow. +}; #ifdef __cplusplus extern "C" { #endif -// Constructors +UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableEnum_CheckValue)( + const upb_MiniTableEnum* e, uint32_t val) { + if (UPB_LIKELY(val < 64)) { + const uint64_t mask = + e->UPB_PRIVATE(data)[0] | ((uint64_t)e->UPB_PRIVATE(data)[1] << 32); + const uint64_t bit = 1ULL << val; + return (mask & bit) != 0; + } + if (UPB_LIKELY(val < e->UPB_PRIVATE(mask_limit))) { + const uint32_t mask = e->UPB_PRIVATE(data)[val / 32]; + const uint32_t bit = 1ULL << (val % 32); + return (mask & bit) != 0; + } -UPB_API_INLINE upb_MiniTableSub -upb_MiniTableSub_FromEnum(const struct upb_MiniTableEnum* subenum) { - return UPB_PRIVATE(_upb_MiniTableSub_FromEnum)(subenum); + // OPT: binary search long lists? + const uint32_t* start = + &e->UPB_PRIVATE(data)[e->UPB_PRIVATE(mask_limit) / 32]; + const uint32_t* limit = &e->UPB_PRIVATE( + data)[e->UPB_PRIVATE(mask_limit) / 32 + e->UPB_PRIVATE(value_count)]; + for (const uint32_t* p = start; p < limit; p++) { + if (*p == val) return true; + } + return false; } -UPB_API_INLINE upb_MiniTableSub -upb_MiniTableSub_FromMessage(const struct upb_MiniTable* submsg) { - return UPB_PRIVATE(_upb_MiniTableSub_FromMessage)(submsg); -} +#ifdef __cplusplus +} /* extern "C" */ +#endif -// Getters -UPB_API_INLINE const struct upb_MiniTableEnum* upb_MiniTableSub_Enum( - upb_MiniTableSub sub) { - return UPB_PRIVATE(_upb_MiniTableSub_Enum)(sub); -} +#endif /* UPB_MINI_TABLE_INTERNAL_ENUM_H_ */ -UPB_API_INLINE const struct upb_MiniTable* upb_MiniTableSub_Message( - upb_MiniTableSub sub) { - return UPB_PRIVATE(_upb_MiniTableSub_Message)(sub); +// Must be last + +#ifdef __cplusplus +extern "C" { +#endif + +// Validates enum value against range defined by enum mini table. +UPB_INLINE bool upb_MiniTableEnum_CheckValue(const upb_MiniTableEnum* e, + uint32_t val) { + return UPB_PRIVATE(_upb_MiniTableEnum_CheckValue)(e, val); } #ifdef __cplusplus @@ -2983,7 +2989,7 @@ UPB_API_INLINE const struct upb_MiniTable* upb_MiniTableSub_Message( #endif -#endif /* UPB_MINI_TABLE_SUB_H_ */ +#endif /* UPB_MINI_TABLE_ENUM_H_ */ // Must be last. @@ -3749,12 +3755,13 @@ UPB_API const upb_MiniTableExtension* upb_ExtensionRegistry_Lookup( #ifndef UPB_MINI_TABLE_INTERNAL_FILE_H_ #define UPB_MINI_TABLE_INTERNAL_FILE_H_ + // Must be last. struct upb_MiniTableFile { - const struct upb_MiniTable** UPB_PRIVATE(msgs); - const struct upb_MiniTableEnum** UPB_PRIVATE(enums); - const struct upb_MiniTableExtension** UPB_PRIVATE(exts); + const upb_MiniTable** UPB_PRIVATE(msgs); + const upb_MiniTableEnum** UPB_PRIVATE(enums); + const upb_MiniTableExtension** UPB_PRIVATE(exts); int UPB_PRIVATE(msg_count); int UPB_PRIVATE(enum_count); int UPB_PRIVATE(ext_count); @@ -3765,34 +3772,34 @@ extern "C" { #endif UPB_INLINE int UPB_PRIVATE(_upb_MiniTableFile_EnumCount)( - const struct upb_MiniTableFile* f) { + const upb_MiniTableFile* f) { return f->UPB_PRIVATE(enum_count); } UPB_INLINE int UPB_PRIVATE(_upb_MiniTableFile_ExtensionCount)( - const struct upb_MiniTableFile* f) { + const upb_MiniTableFile* f) { return f->UPB_PRIVATE(ext_count); } UPB_INLINE int UPB_PRIVATE(_upb_MiniTableFile_MessageCount)( - const struct upb_MiniTableFile* f) { + const upb_MiniTableFile* f) { return f->UPB_PRIVATE(msg_count); } -UPB_INLINE const struct upb_MiniTableEnum* UPB_PRIVATE(_upb_MiniTableFile_Enum)( - const struct upb_MiniTableFile* f, int i) { +UPB_INLINE const upb_MiniTableEnum* UPB_PRIVATE(_upb_MiniTableFile_Enum)( + const upb_MiniTableFile* f, int i) { UPB_ASSERT(i < f->UPB_PRIVATE(enum_count)); return f->UPB_PRIVATE(enums)[i]; } -UPB_INLINE const struct upb_MiniTableExtension* UPB_PRIVATE( - _upb_MiniTableFile_Extension)(const struct upb_MiniTableFile* f, int i) { +UPB_INLINE const upb_MiniTableExtension* UPB_PRIVATE( + _upb_MiniTableFile_Extension)(const upb_MiniTableFile* f, int i) { UPB_ASSERT(i < f->UPB_PRIVATE(ext_count)); return f->UPB_PRIVATE(exts)[i]; } -UPB_INLINE const struct upb_MiniTable* UPB_PRIVATE(_upb_MiniTableFile_Message)( - const struct upb_MiniTableFile* f, int i) { +UPB_INLINE const upb_MiniTable* UPB_PRIVATE(_upb_MiniTableFile_Message)( + const upb_MiniTableFile* f, int i) { UPB_ASSERT(i < f->UPB_PRIVATE(msg_count)); return f->UPB_PRIVATE(msgs)[i]; } @@ -3804,15 +3811,13 @@ UPB_INLINE const struct upb_MiniTable* UPB_PRIVATE(_upb_MiniTableFile_Message)( #endif /* UPB_MINI_TABLE_INTERNAL_FILE_H_ */ -typedef struct upb_MiniTableFile upb_MiniTableFile; - // Must be last. #ifdef __cplusplus extern "C" { #endif -UPB_API_INLINE const struct upb_MiniTableEnum* upb_MiniTableFile_Enum( +UPB_API_INLINE const upb_MiniTableEnum* upb_MiniTableFile_Enum( const upb_MiniTableFile* f, int i) { return UPB_PRIVATE(_upb_MiniTableFile_Enum)(f, i); } @@ -3821,7 +3826,7 @@ UPB_API_INLINE int upb_MiniTableFile_EnumCount(const upb_MiniTableFile* f) { return UPB_PRIVATE(_upb_MiniTableFile_EnumCount)(f); } -UPB_API_INLINE const struct upb_MiniTableExtension* upb_MiniTableFile_Extension( +UPB_API_INLINE const upb_MiniTableExtension* upb_MiniTableFile_Extension( const upb_MiniTableFile* f, int i) { return UPB_PRIVATE(_upb_MiniTableFile_Extension)(f, i); } @@ -3831,7 +3836,7 @@ UPB_API_INLINE int upb_MiniTableFile_ExtensionCount( return UPB_PRIVATE(_upb_MiniTableFile_ExtensionCount)(f); } -UPB_API_INLINE const struct upb_MiniTable* upb_MiniTableFile_Message( +UPB_API_INLINE const upb_MiniTable* upb_MiniTableFile_Message( const upb_MiniTableFile* f, int i) { return UPB_PRIVATE(_upb_MiniTableFile_Message)(f, i); } From 6bfd632d5bde56cf16e2308b85d5602026a6ce09 Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Tue, 19 Dec 2023 23:24:24 -0800 Subject: [PATCH 067/255] Test force_split for repeated_field_reflection_unittest. PiperOrigin-RevId: 592453467 --- src/google/protobuf/BUILD.bazel | 6 +- .../repeated_field_reflection_unittest.cc | 693 +----------------- .../repeated_field_reflection_unittest.inc | 692 +++++++++++++++++ 3 files changed, 709 insertions(+), 682 deletions(-) create mode 100644 src/google/protobuf/repeated_field_reflection_unittest.inc diff --git a/src/google/protobuf/BUILD.bazel b/src/google/protobuf/BUILD.bazel index 1177d9e99d1a7..5e7f5479c58e5 100644 --- a/src/google/protobuf/BUILD.bazel +++ b/src/google/protobuf/BUILD.bazel @@ -897,6 +897,7 @@ cc_library( "map_test_util.inc", "message_unittest.inc", "reflection_tester.h", + "repeated_field_reflection_unittest.inc", "test_util.h", "test_util.inc", "test_util_lite.h", @@ -1377,7 +1378,10 @@ cc_test( cc_test( name = "repeated_field_reflection_unittest", - srcs = ["repeated_field_reflection_unittest.cc"], + srcs = [ + "repeated_field_reflection_unittest.cc", + "repeated_field_reflection_unittest.inc", + ], copts = COPTS + select({ "//build_defs:config_msvc": [], "//conditions:default": [ diff --git a/src/google/protobuf/repeated_field_reflection_unittest.cc b/src/google/protobuf/repeated_field_reflection_unittest.cc index 716df41c6008e..d24efa7693f9d 100644 --- a/src/google/protobuf/repeated_field_reflection_unittest.cc +++ b/src/google/protobuf/repeated_field_reflection_unittest.cc @@ -10,684 +10,15 @@ // Test reflection methods for aggregate access to Repeated[Ptr]Fields. // This test proto2 methods on a proto2 layout. -#include -#include "absl/base/casts.h" -#include "absl/strings/cord.h" -#include "google/protobuf/dynamic_message.h" -#include "google/protobuf/port.h" -#include "google/protobuf/reflection.h" -#include "google/protobuf/test_util.h" -#include "google/protobuf/unittest.pb.h" - -namespace google { -namespace protobuf { -namespace { - -using internal::DownCast; -using unittest::ForeignMessage; -using unittest::TestAllExtensions; -using unittest::TestAllTypes; - -static int Func(int i, int j) { return i * j; } - -static std::string StrFunc(int i, int j) { return absl::StrCat(Func(i, 4)); } - -TEST(RepeatedFieldReflectionTest, RegularFields) { - TestAllTypes message; - const Reflection* refl = message.GetReflection(); - const Descriptor* desc = message.GetDescriptor(); - - for (int i = 0; i < 10; ++i) { - message.add_repeated_int32(Func(i, 1)); - message.add_repeated_double(Func(i, 2)); - message.add_repeated_string(StrFunc(i, 5)); - message.add_repeated_foreign_message()->set_c(Func(i, 6)); - } - - // Get FieldDescriptors for all the fields of interest. - const FieldDescriptor* fd_repeated_int32 = - desc->FindFieldByName("repeated_int32"); - const FieldDescriptor* fd_repeated_double = - desc->FindFieldByName("repeated_double"); - const FieldDescriptor* fd_repeated_string = - desc->FindFieldByName("repeated_string"); - const FieldDescriptor* fd_repeated_foreign_message = - desc->FindFieldByName("repeated_foreign_message"); - - // Get RepeatedField objects for all fields of interest. - const RepeatedField& rf_int32 = - refl->GetRepeatedField(message, fd_repeated_int32); - const RepeatedField& rf_double = - refl->GetRepeatedField(message, fd_repeated_double); - - // Get mutable RepeatedField objects for all fields of interest. - RepeatedField* mrf_int32 = - refl->MutableRepeatedField(&message, fd_repeated_int32); - RepeatedField* mrf_double = - refl->MutableRepeatedField(&message, fd_repeated_double); - - // Get RepeatedPtrField objects for all fields of interest. - const RepeatedPtrField& rpf_string = - refl->GetRepeatedPtrField(message, fd_repeated_string); - const RepeatedPtrField& rpf_foreign_message = - refl->GetRepeatedPtrField(message, - fd_repeated_foreign_message); - const RepeatedPtrField& rpf_message = - refl->GetRepeatedPtrField(message, fd_repeated_foreign_message); - - // Get mutable RepeatedPtrField objects for all fields of interest. - RepeatedPtrField* mrpf_string = - refl->MutableRepeatedPtrField(&message, fd_repeated_string); - RepeatedPtrField* mrpf_foreign_message = - refl->MutableRepeatedPtrField( - &message, fd_repeated_foreign_message); - RepeatedPtrField* mrpf_message = - refl->MutableRepeatedPtrField(&message, - fd_repeated_foreign_message); - - // Make sure we can do gets and sets through the Repeated[Ptr]Field objects. - for (int i = 0; i < 10; ++i) { - // Check gets through const objects. - EXPECT_EQ(rf_int32.Get(i), Func(i, 1)); - EXPECT_EQ(rf_double.Get(i), Func(i, 2)); - EXPECT_EQ(rpf_string.Get(i), StrFunc(i, 5)); - EXPECT_EQ(rpf_foreign_message.Get(i).c(), Func(i, 6)); - EXPECT_EQ(DownCast(&rpf_message.Get(i))->c(), - Func(i, 6)); - - // Check gets through mutable objects. - EXPECT_EQ(mrf_int32->Get(i), Func(i, 1)); - EXPECT_EQ(mrf_double->Get(i), Func(i, 2)); - EXPECT_EQ(mrpf_string->Get(i), StrFunc(i, 5)); - EXPECT_EQ(mrpf_foreign_message->Get(i).c(), Func(i, 6)); - EXPECT_EQ(DownCast(&mrpf_message->Get(i))->c(), - Func(i, 6)); - - // Check sets through mutable objects. - mrf_int32->Set(i, Func(i, -1)); - mrf_double->Set(i, Func(i, -2)); - mrpf_string->Mutable(i)->assign(StrFunc(i, -5)); - mrpf_foreign_message->Mutable(i)->set_c(Func(i, -6)); - EXPECT_EQ(message.repeated_int32(i), Func(i, -1)); - EXPECT_EQ(message.repeated_double(i), Func(i, -2)); - EXPECT_EQ(message.repeated_string(i), StrFunc(i, -5)); - EXPECT_EQ(message.repeated_foreign_message(i).c(), Func(i, -6)); - DownCast(mrpf_message->Mutable(i))->set_c(Func(i, 7)); - EXPECT_EQ(message.repeated_foreign_message(i).c(), Func(i, 7)); - } - -#if GTEST_HAS_DEATH_TEST - // Make sure types are checked correctly at runtime. - const FieldDescriptor* fd_optional_int32 = - desc->FindFieldByName("optional_int32"); - EXPECT_DEATH(refl->GetRepeatedField(message, fd_optional_int32), - "requires a repeated field"); - EXPECT_DEATH(refl->GetRepeatedField(message, fd_repeated_int32), - "not the right type"); - EXPECT_DEATH(refl->GetRepeatedPtrField( - message, fd_repeated_foreign_message), - "wrong submessage type"); -#endif // GTEST_HAS_DEATH_TEST -} - - -TEST(RepeatedFieldReflectionTest, ExtensionFields) { - TestAllExtensions extended_message; - const Reflection* refl = extended_message.GetReflection(); - const Descriptor* desc = extended_message.GetDescriptor(); - - for (int i = 0; i < 10; ++i) { - extended_message.AddExtension(unittest::repeated_int64_extension, - Func(i, 1)); - } - - const FieldDescriptor* fd_repeated_int64_extension = - desc->file()->FindExtensionByName("repeated_int64_extension"); - ABSL_CHECK(fd_repeated_int64_extension != nullptr); - - const RepeatedField& rf_int64_extension = - refl->GetRepeatedField(extended_message, - fd_repeated_int64_extension); - - RepeatedField* mrf_int64_extension = - refl->MutableRepeatedField(&extended_message, - fd_repeated_int64_extension); - - for (int i = 0; i < 10; ++i) { - EXPECT_EQ(Func(i, 1), rf_int64_extension.Get(i)); - mrf_int64_extension->Set(i, Func(i, -1)); - EXPECT_EQ(Func(i, -1), extended_message.GetExtension( - unittest::repeated_int64_extension, i)); - } -} - -template -void TestRepeatedFieldRefIteratorForPrimitive( - const Ref& handle, const MessageType& message, - ValueType (MessageType::*GetFunc)(int) const) { - int index = 0; - for (typename Ref::const_iterator it = handle.begin(); it != handle.end(); - ++it) { - EXPECT_EQ((message.*GetFunc)(index), *it); - ++index; - } - EXPECT_EQ(handle.size(), index); -} - -template -void TestRepeatedFieldRefIteratorForString( - const RepeatedFieldRef& handle, const MessageType& message, - ValueType (MessageType::*GetFunc)(int) const) { - int index = 0; - for (typename RepeatedFieldRef::const_iterator it = - handle.begin(); - it != handle.end(); ++it) { - // Test both operator* and operator-> - EXPECT_EQ((message.*GetFunc)(index), *it); - EXPECT_EQ((message.*GetFunc)(index).size(), it->size()); - ++index; - } - EXPECT_EQ(handle.size(), index); -} - -TEST(RepeatedFieldReflectionTest, RepeatedFieldRefForRegularFields) { - TestAllTypes message; - const Reflection* refl = message.GetReflection(); - const Descriptor* desc = message.GetDescriptor(); - - for (int i = 0; i < 10; ++i) { - message.add_repeated_int32(Func(i, 1)); - message.add_repeated_double(Func(i, 2)); - message.add_repeated_string(StrFunc(i, 5)); - message.add_repeated_foreign_message()->set_c(Func(i, 6)); - } - - // Get FieldDescriptors for all the fields of interest. - const FieldDescriptor* fd_repeated_int32 = - desc->FindFieldByName("repeated_int32"); - const FieldDescriptor* fd_repeated_double = - desc->FindFieldByName("repeated_double"); - const FieldDescriptor* fd_repeated_string = - desc->FindFieldByName("repeated_string"); - const FieldDescriptor* fd_repeated_foreign_message = - desc->FindFieldByName("repeated_foreign_message"); - - // Get RepeatedFieldRef objects for all fields of interest. - const RepeatedFieldRef rf_int32 = - refl->GetRepeatedFieldRef(message, fd_repeated_int32); - const RepeatedFieldRef rf_double = - refl->GetRepeatedFieldRef(message, fd_repeated_double); - const RepeatedFieldRef rf_string = - refl->GetRepeatedFieldRef(message, fd_repeated_string); - const RepeatedFieldRef rf_foreign_message = - refl->GetRepeatedFieldRef(message, - fd_repeated_foreign_message); - const RepeatedFieldRef rf_message = - refl->GetRepeatedFieldRef(message, fd_repeated_foreign_message); - - // Get MutableRepeatedFieldRef objects for all fields of interest. - const MutableRepeatedFieldRef mrf_int32 = - refl->GetMutableRepeatedFieldRef(&message, fd_repeated_int32); - const MutableRepeatedFieldRef mrf_double = - refl->GetMutableRepeatedFieldRef(&message, fd_repeated_double); - const MutableRepeatedFieldRef mrf_string = - refl->GetMutableRepeatedFieldRef(&message, - fd_repeated_string); - const MutableRepeatedFieldRef mrf_foreign_message = - refl->GetMutableRepeatedFieldRef( - &message, fd_repeated_foreign_message); - const MutableRepeatedFieldRef mrf_message = - refl->GetMutableRepeatedFieldRef(&message, - fd_repeated_foreign_message); - - EXPECT_EQ(message.repeated_int32_size(), rf_int32.size()); - EXPECT_EQ(message.repeated_int32_size(), mrf_int32.size()); - EXPECT_EQ(message.repeated_double_size(), rf_double.size()); - EXPECT_EQ(message.repeated_double_size(), mrf_double.size()); - EXPECT_EQ(message.repeated_string_size(), rf_string.size()); - EXPECT_EQ(message.repeated_string_size(), mrf_string.size()); - EXPECT_EQ(message.repeated_foreign_message_size(), rf_foreign_message.size()); - EXPECT_EQ(message.repeated_foreign_message_size(), - mrf_foreign_message.size()); - EXPECT_EQ(message.repeated_foreign_message_size(), rf_message.size()); - EXPECT_EQ(message.repeated_foreign_message_size(), mrf_message.size()); - - EXPECT_FALSE(rf_int32.empty()); - EXPECT_FALSE(mrf_int32.empty()); - EXPECT_FALSE(rf_double.empty()); - EXPECT_FALSE(mrf_double.empty()); - EXPECT_FALSE(rf_string.empty()); - EXPECT_FALSE(mrf_string.empty()); - EXPECT_FALSE(rf_foreign_message.empty()); - EXPECT_FALSE(mrf_foreign_message.empty()); - EXPECT_FALSE(rf_message.empty()); - EXPECT_FALSE(mrf_message.empty()); - - // Make sure we can do gets and sets through the RepeatedFieldRef objects. - for (int i = 0; i < 10; ++i) { - // Check gets through const objects. - EXPECT_EQ(rf_int32.Get(i), Func(i, 1)); - EXPECT_EQ(rf_double.Get(i), Func(i, 2)); - EXPECT_EQ(rf_string.Get(i), StrFunc(i, 5)); - ForeignMessage scratch_space; - EXPECT_EQ(rf_foreign_message.Get(i, &scratch_space).c(), Func(i, 6)); - EXPECT_EQ( - DownCast(rf_message.Get(i, &scratch_space)).c(), - Func(i, 6)); - - // Check gets through mutable objects. - EXPECT_EQ(mrf_int32.Get(i), Func(i, 1)); - EXPECT_EQ(mrf_double.Get(i), Func(i, 2)); - EXPECT_EQ(mrf_string.Get(i), StrFunc(i, 5)); - EXPECT_EQ(mrf_foreign_message.Get(i, &scratch_space).c(), Func(i, 6)); - EXPECT_EQ( - DownCast(mrf_message.Get(i, &scratch_space)).c(), - Func(i, 6)); - - // Check sets through mutable objects. - mrf_int32.Set(i, Func(i, -1)); - mrf_double.Set(i, Func(i, -2)); - mrf_string.Set(i, StrFunc(i, -5)); - ForeignMessage foreign_message; - foreign_message.set_c(Func(i, -6)); - mrf_foreign_message.Set(i, foreign_message); - EXPECT_EQ(message.repeated_int32(i), Func(i, -1)); - EXPECT_EQ(message.repeated_double(i), Func(i, -2)); - EXPECT_EQ(message.repeated_string(i), StrFunc(i, -5)); - EXPECT_EQ(message.repeated_foreign_message(i).c(), Func(i, -6)); - foreign_message.set_c(Func(i, 7)); - mrf_message.Set(i, foreign_message); - EXPECT_EQ(message.repeated_foreign_message(i).c(), Func(i, 7)); - } - - // Test iterators. - TestRepeatedFieldRefIteratorForPrimitive(rf_int32, message, - &TestAllTypes::repeated_int32); - TestRepeatedFieldRefIteratorForPrimitive(rf_double, message, - &TestAllTypes::repeated_double); - TestRepeatedFieldRefIteratorForString(rf_string, message, - &TestAllTypes::repeated_string); - - // Test iterators for message fields. - typedef RepeatedFieldRef::iterator MessageIterator; - int index = 0; - for (MessageIterator it = rf_foreign_message.begin(); - it != rf_foreign_message.end(); ++it) { - EXPECT_EQ(message.repeated_foreign_message(index).c(), it->c()); - ++index; - } - EXPECT_EQ(10, index); - - // Test iterator operators that are not usually used in regular for-loops. - // Including: post increment, assign, ==. - MessageIterator old_it = rf_foreign_message.begin(); - MessageIterator new_it = old_it++; - EXPECT_FALSE(old_it == new_it); - // Check that old_it++ increments old_it once. - for (index = 1; old_it != rf_foreign_message.end(); ++old_it, ++index) { - EXPECT_EQ(message.repeated_foreign_message(index).c(), old_it->c()); - } - EXPECT_EQ(10, index); - // Test assign operator. - old_it = new_it; - for (index = 0; old_it != rf_foreign_message.end(); ++old_it, ++index) { - EXPECT_EQ(message.repeated_foreign_message(index).c(), old_it->c()); - } - EXPECT_EQ(10, index); - // Check that the returned value of old_it++ is the one before increment. - for (index = 0; new_it != rf_foreign_message.end(); ++new_it, ++index) { - EXPECT_EQ(message.repeated_foreign_message(index).c(), new_it->c()); - } - EXPECT_EQ(10, index); - - // Test MutableRepeatedFieldRef::Reserve() - mrf_int32.Reserve(mrf_int32.size() + 1); - mrf_double.Reserve(mrf_double.size() + 1); - mrf_string.Reserve(mrf_string.size() + 1); - mrf_foreign_message.Reserve(mrf_foreign_message.size() + 1); - - // Test MutableRepeatedFieldRef::Add() - mrf_int32.Add(1234); - mrf_double.Add(1234.0); - mrf_string.Add("1234"); - ForeignMessage foreign_message; - foreign_message.set_c(1234); - mrf_foreign_message.Add(foreign_message); - EXPECT_EQ(1234, message.repeated_int32(10)); - EXPECT_EQ(1234.0, message.repeated_double(10)); - EXPECT_EQ("1234", message.repeated_string(10)); - EXPECT_EQ(1234, message.repeated_foreign_message(10).c()); - - // Test MutableRepeatedFieldRef::RemoveLast() - mrf_int32.RemoveLast(); - mrf_double.RemoveLast(); - mrf_string.RemoveLast(); - mrf_foreign_message.RemoveLast(); - EXPECT_EQ(10, message.repeated_int32_size()); - EXPECT_EQ(10, message.repeated_double_size()); - EXPECT_EQ(10, message.repeated_string_size()); - EXPECT_EQ(10, message.repeated_foreign_message_size()); - - // Test MutableRepeatedFieldRef::SwapElements() - mrf_int32.SwapElements(0, 9); - mrf_double.SwapElements(0, 9); - mrf_string.SwapElements(0, 9); - mrf_foreign_message.SwapElements(0, 9); - EXPECT_EQ(Func(9, -1), message.repeated_int32(0)); - EXPECT_EQ(Func(0, -1), message.repeated_int32(9)); - EXPECT_EQ(Func(9, -2), message.repeated_double(0)); - EXPECT_EQ(Func(0, -2), message.repeated_double(9)); - EXPECT_EQ(StrFunc(9, -5), message.repeated_string(0)); - EXPECT_EQ(StrFunc(0, -5), message.repeated_string(9)); - EXPECT_EQ(Func(9, 7), message.repeated_foreign_message(0).c()); - EXPECT_EQ(Func(0, 7), message.repeated_foreign_message(9).c()); - - // Test MutableRepeatedFieldRef::Clear() - mrf_int32.Clear(); - mrf_double.Clear(); - mrf_string.Clear(); - mrf_foreign_message.Clear(); - EXPECT_EQ(0, message.repeated_int32_size()); - EXPECT_EQ(0, message.repeated_double_size()); - EXPECT_EQ(0, message.repeated_string_size()); - EXPECT_EQ(0, message.repeated_foreign_message_size()); - - // Test (Mutable)RepeatedFieldRef::empty() - EXPECT_TRUE(rf_int32.empty()); - EXPECT_TRUE(mrf_int32.empty()); - EXPECT_TRUE(rf_double.empty()); - EXPECT_TRUE(mrf_double.empty()); - EXPECT_TRUE(rf_string.empty()); - EXPECT_TRUE(mrf_string.empty()); - EXPECT_TRUE(rf_foreign_message.empty()); - EXPECT_TRUE(mrf_foreign_message.empty()); - EXPECT_TRUE(rf_message.empty()); - EXPECT_TRUE(mrf_message.empty()); - -#if GTEST_HAS_DEATH_TEST - - // Make sure types are checked correctly at runtime. - const FieldDescriptor* fd_optional_int32 = - desc->FindFieldByName("optional_int32"); - EXPECT_DEATH(refl->GetRepeatedFieldRef(message, fd_optional_int32), - ""); - EXPECT_DEATH(refl->GetRepeatedFieldRef(message, fd_repeated_int32), - ""); - EXPECT_DEATH(refl->GetRepeatedFieldRef( - message, fd_repeated_foreign_message), - ""); - -#endif // GTEST_HAS_DEATH_TEST -} - -TEST(RepeatedFieldReflectionTest, RepeatedFieldRefForEnums) { - TestAllTypes message; - const Reflection* refl = message.GetReflection(); - const Descriptor* desc = message.GetDescriptor(); - - for (int i = 0; i < 10; ++i) { - message.add_repeated_nested_enum(TestAllTypes::BAR); - } - - const FieldDescriptor* fd_repeated_nested_enum = - desc->FindFieldByName("repeated_nested_enum"); - const RepeatedFieldRef enum_ref = - refl->GetRepeatedFieldRef( - message, fd_repeated_nested_enum); - const MutableRepeatedFieldRef mutable_enum_ref = - refl->GetMutableRepeatedFieldRef( - &message, fd_repeated_nested_enum); - const RepeatedFieldRef int32_ref = - refl->GetRepeatedFieldRef(message, fd_repeated_nested_enum); - const MutableRepeatedFieldRef mutable_int32_ref = - refl->GetMutableRepeatedFieldRef(&message, - fd_repeated_nested_enum); - - EXPECT_EQ(message.repeated_nested_enum_size(), enum_ref.size()); - EXPECT_EQ(message.repeated_nested_enum_size(), mutable_enum_ref.size()); - EXPECT_EQ(message.repeated_nested_enum_size(), int32_ref.size()); - EXPECT_EQ(message.repeated_nested_enum_size(), mutable_int32_ref.size()); - - EXPECT_FALSE(enum_ref.empty()); - EXPECT_FALSE(mutable_enum_ref.empty()); - EXPECT_FALSE(int32_ref.empty()); - EXPECT_FALSE(mutable_int32_ref.empty()); - - for (int i = 0; i < 10; ++i) { - EXPECT_EQ(TestAllTypes::BAR, enum_ref.Get(i)); - EXPECT_EQ(TestAllTypes::BAR, mutable_enum_ref.Get(i)); - mutable_enum_ref.Set(i, TestAllTypes::BAZ); - EXPECT_EQ(TestAllTypes::BAZ, enum_ref.Get(i)); - EXPECT_EQ(TestAllTypes::BAZ, message.repeated_nested_enum(i)); - - message.set_repeated_nested_enum(i, TestAllTypes::BAR); - EXPECT_EQ(TestAllTypes::BAR, int32_ref.Get(i)); - EXPECT_EQ(TestAllTypes::BAR, mutable_int32_ref.Get(i)); - mutable_int32_ref.Set(i, TestAllTypes::BAZ); - EXPECT_EQ(TestAllTypes::BAZ, int32_ref.Get(i)); - EXPECT_EQ(TestAllTypes::BAZ, message.repeated_nested_enum(i)); - } - - TestRepeatedFieldRefIteratorForPrimitive(enum_ref, message, - &TestAllTypes::repeated_nested_enum); - TestRepeatedFieldRefIteratorForPrimitive(int32_ref, message, - &TestAllTypes::repeated_nested_enum); - - // Test Add() - mutable_enum_ref.Add(TestAllTypes::FOO); - EXPECT_EQ(TestAllTypes::FOO, message.repeated_nested_enum(10)); - mutable_int32_ref.Add(TestAllTypes::BAR); - EXPECT_EQ(TestAllTypes::BAR, message.repeated_nested_enum(11)); - - // Test RemoveLast() - mutable_enum_ref.RemoveLast(); - EXPECT_EQ(11, message.repeated_nested_enum_size()); - mutable_int32_ref.RemoveLast(); - EXPECT_EQ(10, message.repeated_nested_enum_size()); - - // Test SwapElements() - mutable_enum_ref.Set(0, TestAllTypes::BAR); - mutable_enum_ref.Set(9, TestAllTypes::BAZ); - mutable_enum_ref.SwapElements(0, 9); - EXPECT_EQ(TestAllTypes::BAZ, enum_ref.Get(0)); - EXPECT_EQ(TestAllTypes::BAR, enum_ref.Get(9)); - mutable_int32_ref.SwapElements(0, 9); - EXPECT_EQ(TestAllTypes::BAR, enum_ref.Get(0)); - EXPECT_EQ(TestAllTypes::BAZ, enum_ref.Get(9)); - - // Test Clear() - mutable_enum_ref.Clear(); - EXPECT_EQ(0, message.repeated_nested_enum_size()); - mutable_enum_ref.Add(TestAllTypes::FOO); - EXPECT_EQ(1, message.repeated_nested_enum_size()); - mutable_int32_ref.Clear(); - EXPECT_EQ(0, message.repeated_nested_enum_size()); - - // Test empty() - EXPECT_TRUE(enum_ref.empty()); - EXPECT_TRUE(mutable_enum_ref.empty()); - EXPECT_TRUE(int32_ref.empty()); - EXPECT_TRUE(mutable_int32_ref.empty()); -} - -TEST(RepeatedFieldReflectionTest, RepeatedFieldRefForExtensionFields) { - TestAllExtensions extended_message; - const Reflection* refl = extended_message.GetReflection(); - const Descriptor* desc = extended_message.GetDescriptor(); - - for (int i = 0; i < 10; ++i) { - extended_message.AddExtension(unittest::repeated_int64_extension, - Func(i, 1)); - } - - const FieldDescriptor* fd_repeated_int64_extension = - desc->file()->FindExtensionByName("repeated_int64_extension"); - ABSL_CHECK(fd_repeated_int64_extension != nullptr); - - const RepeatedFieldRef rf_int64_extension = - refl->GetRepeatedFieldRef(extended_message, - fd_repeated_int64_extension); - - const MutableRepeatedFieldRef mrf_int64_extension = - refl->GetMutableRepeatedFieldRef(&extended_message, - fd_repeated_int64_extension); - - for (int i = 0; i < 10; ++i) { - EXPECT_EQ(Func(i, 1), rf_int64_extension.Get(i)); - mrf_int64_extension.Set(i, Func(i, -1)); - EXPECT_EQ(Func(i, -1), extended_message.GetExtension( - unittest::repeated_int64_extension, i)); - } -} - - -TEST(RepeatedFieldReflectionTest, RepeatedFieldRefMergeFromAndSwap) { - // Set-up message content. - TestAllTypes m0, m1, m2; - for (int i = 0; i < 10; ++i) { - m0.add_repeated_int32(Func(i, 1)); - m0.add_repeated_double(Func(i, 2)); - m0.add_repeated_string(StrFunc(i, 5)); - m0.add_repeated_foreign_message()->set_c(Func(i, 6)); - m0.add_repeated_nested_enum(TestAllTypes::FOO); - m1.add_repeated_int32(Func(i, 11)); - m1.add_repeated_double(Func(i, 12)); - m1.add_repeated_string(StrFunc(i, 15)); - m1.add_repeated_foreign_message()->set_c(Func(i, 16)); - m1.add_repeated_nested_enum(TestAllTypes::BAR); - m2.add_repeated_int32(Func(i, 21)); - m2.add_repeated_double(Func(i, 22)); - m2.add_repeated_string(StrFunc(i, 25)); - m2.add_repeated_foreign_message()->set_c(Func(i, 26)); - m2.add_repeated_nested_enum(TestAllTypes::BAZ); - } - - const Reflection* refl = m0.GetReflection(); - const Descriptor* desc = m0.GetDescriptor(); - - // Get FieldDescriptors for all the fields of interest. - const FieldDescriptor* fd_repeated_int32 = - desc->FindFieldByName("repeated_int32"); - const FieldDescriptor* fd_repeated_double = - desc->FindFieldByName("repeated_double"); - const FieldDescriptor* fd_repeated_string = - desc->FindFieldByName("repeated_string"); - const FieldDescriptor* fd_repeated_foreign_message = - desc->FindFieldByName("repeated_foreign_message"); - const FieldDescriptor* fd_repeated_nested_enum = - desc->FindFieldByName("repeated_nested_enum"); - - // Get MutableRepeatedFieldRef objects for all fields of interest. - const MutableRepeatedFieldRef mrf_int32 = - refl->GetMutableRepeatedFieldRef(&m0, fd_repeated_int32); - const MutableRepeatedFieldRef mrf_double = - refl->GetMutableRepeatedFieldRef(&m0, fd_repeated_double); - const MutableRepeatedFieldRef mrf_string = - refl->GetMutableRepeatedFieldRef(&m0, fd_repeated_string); - const MutableRepeatedFieldRef mrf_foreign_message = - refl->GetMutableRepeatedFieldRef( - &m0, fd_repeated_foreign_message); - const MutableRepeatedFieldRef mrf_nested_enum = - refl->GetMutableRepeatedFieldRef( - &m0, fd_repeated_nested_enum); - - // Test MutableRepeatedRef::CopyFrom - mrf_int32.CopyFrom(refl->GetRepeatedFieldRef(m1, fd_repeated_int32)); - mrf_double.CopyFrom( - refl->GetRepeatedFieldRef(m1, fd_repeated_double)); - mrf_string.CopyFrom( - refl->GetRepeatedFieldRef(m1, fd_repeated_string)); - mrf_foreign_message.CopyFrom(refl->GetRepeatedFieldRef( - m1, fd_repeated_foreign_message)); - mrf_nested_enum.CopyFrom(refl->GetRepeatedFieldRef( - m1, fd_repeated_nested_enum)); - for (int i = 0; i < 10; ++i) { - EXPECT_EQ(Func(i, 11), m0.repeated_int32(i)); - EXPECT_EQ(Func(i, 12), m0.repeated_double(i)); - EXPECT_EQ(StrFunc(i, 15), m0.repeated_string(i)); - EXPECT_EQ(Func(i, 16), m0.repeated_foreign_message(i).c()); - EXPECT_EQ(TestAllTypes::BAR, m0.repeated_nested_enum(i)); - } - - // Test MutableRepeatedRef::MergeFrom - mrf_int32.MergeFrom( - refl->GetRepeatedFieldRef(m2, fd_repeated_int32)); - mrf_double.MergeFrom( - refl->GetRepeatedFieldRef(m2, fd_repeated_double)); - mrf_string.MergeFrom( - refl->GetRepeatedFieldRef(m2, fd_repeated_string)); - mrf_foreign_message.MergeFrom(refl->GetRepeatedFieldRef( - m2, fd_repeated_foreign_message)); - mrf_nested_enum.MergeFrom(refl->GetRepeatedFieldRef( - m2, fd_repeated_nested_enum)); - for (int i = 0; i < 10; ++i) { - EXPECT_EQ(Func(i, 21), m0.repeated_int32(i + 10)); - EXPECT_EQ(Func(i, 22), m0.repeated_double(i + 10)); - EXPECT_EQ(StrFunc(i, 25), m0.repeated_string(i + 10)); - EXPECT_EQ(Func(i, 26), m0.repeated_foreign_message(i + 10).c()); - EXPECT_EQ(TestAllTypes::BAZ, m0.repeated_nested_enum(i + 10)); - } - - // Test MutableRepeatedRef::Swap - // Swap between m0 and m2. - mrf_int32.Swap( - refl->GetMutableRepeatedFieldRef(&m2, fd_repeated_int32)); - mrf_double.Swap( - refl->GetMutableRepeatedFieldRef(&m2, fd_repeated_double)); - mrf_string.Swap( - refl->GetMutableRepeatedFieldRef(&m2, fd_repeated_string)); - mrf_foreign_message.Swap(refl->GetMutableRepeatedFieldRef( - &m2, fd_repeated_foreign_message)); - mrf_nested_enum.Swap( - refl->GetMutableRepeatedFieldRef( - &m2, fd_repeated_nested_enum)); - for (int i = 0; i < 10; ++i) { - // Check the content of m0. - EXPECT_EQ(Func(i, 21), m0.repeated_int32(i)); - EXPECT_EQ(Func(i, 22), m0.repeated_double(i)); - EXPECT_EQ(StrFunc(i, 25), m0.repeated_string(i)); - EXPECT_EQ(Func(i, 26), m0.repeated_foreign_message(i).c()); - EXPECT_EQ(TestAllTypes::BAZ, m0.repeated_nested_enum(i)); - - // Check the content of m2. - EXPECT_EQ(Func(i, 11), m2.repeated_int32(i)); - EXPECT_EQ(Func(i, 12), m2.repeated_double(i)); - EXPECT_EQ(StrFunc(i, 15), m2.repeated_string(i)); - EXPECT_EQ(Func(i, 16), m2.repeated_foreign_message(i).c()); - EXPECT_EQ(TestAllTypes::BAR, m2.repeated_nested_enum(i)); - EXPECT_EQ(Func(i, 21), m2.repeated_int32(i + 10)); - EXPECT_EQ(Func(i, 22), m2.repeated_double(i + 10)); - EXPECT_EQ(StrFunc(i, 25), m2.repeated_string(i + 10)); - EXPECT_EQ(Func(i, 26), m2.repeated_foreign_message(i + 10).c()); - EXPECT_EQ(TestAllTypes::BAZ, m2.repeated_nested_enum(i + 10)); - } -} - -// Test that GetRepeatedFieldRef/MutableRepeatedFieldRef works with -// DynamicMessage. -TEST(RepeatedFieldReflectionTest, RepeatedFieldRefDynamicMessage) { - // DynamicMessage shares the same memory layout as generated message - // and use the same GeneratedMessageReflection code for reflection. - // All code paths should already be covered by the other tests for - // generated messages. Here we just test one field. - - const Descriptor* desc = TestAllTypes::descriptor(); - const FieldDescriptor* fd_repeated_int32 = - desc->FindFieldByName("repeated_int32"); - - DynamicMessageFactory factory; - std::unique_ptr dynamic_message(factory.GetPrototype(desc)->New()); - const Reflection* refl = dynamic_message->GetReflection(); - - MutableRepeatedFieldRef rf_int32 = - refl->GetMutableRepeatedFieldRef(dynamic_message.get(), - fd_repeated_int32); - rf_int32.Add(1234); - EXPECT_EQ(1, refl->FieldSize(*dynamic_message, fd_repeated_int32)); - EXPECT_EQ(1234, - refl->GetRepeatedInt32(*dynamic_message, fd_repeated_int32, 0)); -} - -} // namespace -} // namespace protobuf -} // namespace google +#include "google/protobuf/unittest.pb.h" // IWYU pragma: keep, used in UNITTEST + +#define REFLECTION_TEST RepeatedFieldReflectionTest +#define UNITTEST_PACKAGE_NAME "protobuf_unittest" +#define UNITTEST ::protobuf_unittest +#define UNITTEST_IMPORT ::protobuf_unittest_import + +// Must include after the above macros. +// clang-format off +#include "google/protobuf/test_util.inc" +#include "google/protobuf/repeated_field_reflection_unittest.inc" +// clang-format on diff --git a/src/google/protobuf/repeated_field_reflection_unittest.inc b/src/google/protobuf/repeated_field_reflection_unittest.inc new file mode 100644 index 0000000000000..97d5c4128eaec --- /dev/null +++ b/src/google/protobuf/repeated_field_reflection_unittest.inc @@ -0,0 +1,692 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file or at +// https://developers.google.com/open-source/licenses/bsd + +// Author: tgs@google.com (Tom Szymanski) +// +// Test reflection methods for aggregate access to Repeated[Ptr]Fields. +// This test proto2 methods on a proto2 layout. + +#include +#include "absl/base/casts.h" +#include "absl/strings/cord.h" +#include "google/protobuf/dynamic_message.h" +#include "google/protobuf/port.h" +#include "google/protobuf/reflection.h" + +namespace google { +namespace protobuf { +namespace { + + +using internal::DownCast; +using UNITTEST::ForeignMessage; +using UNITTEST::TestAllExtensions; +using UNITTEST::TestAllTypes; + +static int Func(int i, int j) { return i * j; } + +static std::string StrFunc(int i, int j) { return absl::StrCat(Func(i, 4)); } + +TEST(REFLECTION_TEST, RegularFields) { + TestAllTypes message; + const Reflection* refl = message.GetReflection(); + const Descriptor* desc = message.GetDescriptor(); + + for (int i = 0; i < 10; ++i) { + message.add_repeated_int32(Func(i, 1)); + message.add_repeated_double(Func(i, 2)); + message.add_repeated_string(StrFunc(i, 5)); + message.add_repeated_foreign_message()->set_c(Func(i, 6)); + } + + // Get FieldDescriptors for all the fields of interest. + const FieldDescriptor* fd_repeated_int32 = + desc->FindFieldByName("repeated_int32"); + const FieldDescriptor* fd_repeated_double = + desc->FindFieldByName("repeated_double"); + const FieldDescriptor* fd_repeated_string = + desc->FindFieldByName("repeated_string"); + const FieldDescriptor* fd_repeated_foreign_message = + desc->FindFieldByName("repeated_foreign_message"); + + // Get RepeatedField objects for all fields of interest. + const RepeatedField& rf_int32 = + refl->GetRepeatedField(message, fd_repeated_int32); + const RepeatedField& rf_double = + refl->GetRepeatedField(message, fd_repeated_double); + + // Get mutable RepeatedField objects for all fields of interest. + RepeatedField* mrf_int32 = + refl->MutableRepeatedField(&message, fd_repeated_int32); + RepeatedField* mrf_double = + refl->MutableRepeatedField(&message, fd_repeated_double); + + // Get RepeatedPtrField objects for all fields of interest. + const RepeatedPtrField& rpf_string = + refl->GetRepeatedPtrField(message, fd_repeated_string); + const RepeatedPtrField& rpf_foreign_message = + refl->GetRepeatedPtrField(message, + fd_repeated_foreign_message); + const RepeatedPtrField& rpf_message = + refl->GetRepeatedPtrField(message, fd_repeated_foreign_message); + + // Get mutable RepeatedPtrField objects for all fields of interest. + RepeatedPtrField* mrpf_string = + refl->MutableRepeatedPtrField(&message, fd_repeated_string); + RepeatedPtrField* mrpf_foreign_message = + refl->MutableRepeatedPtrField( + &message, fd_repeated_foreign_message); + RepeatedPtrField* mrpf_message = + refl->MutableRepeatedPtrField(&message, + fd_repeated_foreign_message); + + // Make sure we can do gets and sets through the Repeated[Ptr]Field objects. + for (int i = 0; i < 10; ++i) { + // Check gets through const objects. + EXPECT_EQ(rf_int32.Get(i), Func(i, 1)); + EXPECT_EQ(rf_double.Get(i), Func(i, 2)); + EXPECT_EQ(rpf_string.Get(i), StrFunc(i, 5)); + EXPECT_EQ(rpf_foreign_message.Get(i).c(), Func(i, 6)); + EXPECT_EQ(DownCast(&rpf_message.Get(i))->c(), + Func(i, 6)); + + // Check gets through mutable objects. + EXPECT_EQ(mrf_int32->Get(i), Func(i, 1)); + EXPECT_EQ(mrf_double->Get(i), Func(i, 2)); + EXPECT_EQ(mrpf_string->Get(i), StrFunc(i, 5)); + EXPECT_EQ(mrpf_foreign_message->Get(i).c(), Func(i, 6)); + EXPECT_EQ(DownCast(&mrpf_message->Get(i))->c(), + Func(i, 6)); + + // Check sets through mutable objects. + mrf_int32->Set(i, Func(i, -1)); + mrf_double->Set(i, Func(i, -2)); + mrpf_string->Mutable(i)->assign(StrFunc(i, -5)); + mrpf_foreign_message->Mutable(i)->set_c(Func(i, -6)); + EXPECT_EQ(message.repeated_int32(i), Func(i, -1)); + EXPECT_EQ(message.repeated_double(i), Func(i, -2)); + EXPECT_EQ(message.repeated_string(i), StrFunc(i, -5)); + EXPECT_EQ(message.repeated_foreign_message(i).c(), Func(i, -6)); + DownCast(mrpf_message->Mutable(i))->set_c(Func(i, 7)); + EXPECT_EQ(message.repeated_foreign_message(i).c(), Func(i, 7)); + } + +#if GTEST_HAS_DEATH_TEST + // Make sure types are checked correctly at runtime. + const FieldDescriptor* fd_optional_int32 = + desc->FindFieldByName("optional_int32"); + EXPECT_DEATH(refl->GetRepeatedField(message, fd_optional_int32), + "requires a repeated field"); + EXPECT_DEATH(refl->GetRepeatedField(message, fd_repeated_int32), + "not the right type"); + EXPECT_DEATH(refl->GetRepeatedPtrField( + message, fd_repeated_foreign_message), + "wrong submessage type"); +#endif // GTEST_HAS_DEATH_TEST +} + + +TEST(REFLECTION_TEST, ExtensionFields) { + TestAllExtensions extended_message; + const Reflection* refl = extended_message.GetReflection(); + const Descriptor* desc = extended_message.GetDescriptor(); + + for (int i = 0; i < 10; ++i) { + extended_message.AddExtension(UNITTEST::repeated_int64_extension, + Func(i, 1)); + } + + const FieldDescriptor* fd_repeated_int64_extension = + desc->file()->FindExtensionByName("repeated_int64_extension"); + ABSL_CHECK(fd_repeated_int64_extension != nullptr); + + const RepeatedField& rf_int64_extension = + refl->GetRepeatedField(extended_message, + fd_repeated_int64_extension); + + RepeatedField* mrf_int64_extension = + refl->MutableRepeatedField(&extended_message, + fd_repeated_int64_extension); + + for (int i = 0; i < 10; ++i) { + EXPECT_EQ(Func(i, 1), rf_int64_extension.Get(i)); + mrf_int64_extension->Set(i, Func(i, -1)); + EXPECT_EQ(Func(i, -1), extended_message.GetExtension( + UNITTEST::repeated_int64_extension, i)); + } +} + +template +void TestRepeatedFieldRefIteratorForPrimitive( + const Ref& handle, const MessageType& message, + ValueType (MessageType::*GetFunc)(int) const) { + int index = 0; + for (typename Ref::const_iterator it = handle.begin(); it != handle.end(); + ++it) { + EXPECT_EQ((message.*GetFunc)(index), *it); + ++index; + } + EXPECT_EQ(handle.size(), index); +} + +template +void TestRepeatedFieldRefIteratorForString( + const RepeatedFieldRef& handle, const MessageType& message, + ValueType (MessageType::*GetFunc)(int) const) { + int index = 0; + for (typename RepeatedFieldRef::const_iterator it = + handle.begin(); + it != handle.end(); ++it) { + // Test both operator* and operator-> + EXPECT_EQ((message.*GetFunc)(index), *it); + EXPECT_EQ((message.*GetFunc)(index).size(), it->size()); + ++index; + } + EXPECT_EQ(handle.size(), index); +} + +TEST(REFLECTION_TEST, RepeatedFieldRefForRegularFields) { + TestAllTypes message; + const Reflection* refl = message.GetReflection(); + const Descriptor* desc = message.GetDescriptor(); + + for (int i = 0; i < 10; ++i) { + message.add_repeated_int32(Func(i, 1)); + message.add_repeated_double(Func(i, 2)); + message.add_repeated_string(StrFunc(i, 5)); + message.add_repeated_foreign_message()->set_c(Func(i, 6)); + } + + // Get FieldDescriptors for all the fields of interest. + const FieldDescriptor* fd_repeated_int32 = + desc->FindFieldByName("repeated_int32"); + const FieldDescriptor* fd_repeated_double = + desc->FindFieldByName("repeated_double"); + const FieldDescriptor* fd_repeated_string = + desc->FindFieldByName("repeated_string"); + const FieldDescriptor* fd_repeated_foreign_message = + desc->FindFieldByName("repeated_foreign_message"); + + // Get RepeatedFieldRef objects for all fields of interest. + const RepeatedFieldRef rf_int32 = + refl->GetRepeatedFieldRef(message, fd_repeated_int32); + const RepeatedFieldRef rf_double = + refl->GetRepeatedFieldRef(message, fd_repeated_double); + const RepeatedFieldRef rf_string = + refl->GetRepeatedFieldRef(message, fd_repeated_string); + const RepeatedFieldRef rf_foreign_message = + refl->GetRepeatedFieldRef(message, + fd_repeated_foreign_message); + const RepeatedFieldRef rf_message = + refl->GetRepeatedFieldRef(message, fd_repeated_foreign_message); + + // Get MutableRepeatedFieldRef objects for all fields of interest. + const MutableRepeatedFieldRef mrf_int32 = + refl->GetMutableRepeatedFieldRef(&message, fd_repeated_int32); + const MutableRepeatedFieldRef mrf_double = + refl->GetMutableRepeatedFieldRef(&message, fd_repeated_double); + const MutableRepeatedFieldRef mrf_string = + refl->GetMutableRepeatedFieldRef(&message, + fd_repeated_string); + const MutableRepeatedFieldRef mrf_foreign_message = + refl->GetMutableRepeatedFieldRef( + &message, fd_repeated_foreign_message); + const MutableRepeatedFieldRef mrf_message = + refl->GetMutableRepeatedFieldRef(&message, + fd_repeated_foreign_message); + + EXPECT_EQ(message.repeated_int32_size(), rf_int32.size()); + EXPECT_EQ(message.repeated_int32_size(), mrf_int32.size()); + EXPECT_EQ(message.repeated_double_size(), rf_double.size()); + EXPECT_EQ(message.repeated_double_size(), mrf_double.size()); + EXPECT_EQ(message.repeated_string_size(), rf_string.size()); + EXPECT_EQ(message.repeated_string_size(), mrf_string.size()); + EXPECT_EQ(message.repeated_foreign_message_size(), rf_foreign_message.size()); + EXPECT_EQ(message.repeated_foreign_message_size(), + mrf_foreign_message.size()); + EXPECT_EQ(message.repeated_foreign_message_size(), rf_message.size()); + EXPECT_EQ(message.repeated_foreign_message_size(), mrf_message.size()); + + EXPECT_FALSE(rf_int32.empty()); + EXPECT_FALSE(mrf_int32.empty()); + EXPECT_FALSE(rf_double.empty()); + EXPECT_FALSE(mrf_double.empty()); + EXPECT_FALSE(rf_string.empty()); + EXPECT_FALSE(mrf_string.empty()); + EXPECT_FALSE(rf_foreign_message.empty()); + EXPECT_FALSE(mrf_foreign_message.empty()); + EXPECT_FALSE(rf_message.empty()); + EXPECT_FALSE(mrf_message.empty()); + + // Make sure we can do gets and sets through the RepeatedFieldRef objects. + for (int i = 0; i < 10; ++i) { + // Check gets through const objects. + EXPECT_EQ(rf_int32.Get(i), Func(i, 1)); + EXPECT_EQ(rf_double.Get(i), Func(i, 2)); + EXPECT_EQ(rf_string.Get(i), StrFunc(i, 5)); + ForeignMessage scratch_space; + EXPECT_EQ(rf_foreign_message.Get(i, &scratch_space).c(), Func(i, 6)); + EXPECT_EQ( + DownCast(rf_message.Get(i, &scratch_space)).c(), + Func(i, 6)); + + // Check gets through mutable objects. + EXPECT_EQ(mrf_int32.Get(i), Func(i, 1)); + EXPECT_EQ(mrf_double.Get(i), Func(i, 2)); + EXPECT_EQ(mrf_string.Get(i), StrFunc(i, 5)); + EXPECT_EQ(mrf_foreign_message.Get(i, &scratch_space).c(), Func(i, 6)); + EXPECT_EQ( + DownCast(mrf_message.Get(i, &scratch_space)).c(), + Func(i, 6)); + + // Check sets through mutable objects. + mrf_int32.Set(i, Func(i, -1)); + mrf_double.Set(i, Func(i, -2)); + mrf_string.Set(i, StrFunc(i, -5)); + ForeignMessage foreign_message; + foreign_message.set_c(Func(i, -6)); + mrf_foreign_message.Set(i, foreign_message); + EXPECT_EQ(message.repeated_int32(i), Func(i, -1)); + EXPECT_EQ(message.repeated_double(i), Func(i, -2)); + EXPECT_EQ(message.repeated_string(i), StrFunc(i, -5)); + EXPECT_EQ(message.repeated_foreign_message(i).c(), Func(i, -6)); + foreign_message.set_c(Func(i, 7)); + mrf_message.Set(i, foreign_message); + EXPECT_EQ(message.repeated_foreign_message(i).c(), Func(i, 7)); + } + + // Test iterators. + TestRepeatedFieldRefIteratorForPrimitive(rf_int32, message, + &TestAllTypes::repeated_int32); + TestRepeatedFieldRefIteratorForPrimitive(rf_double, message, + &TestAllTypes::repeated_double); + TestRepeatedFieldRefIteratorForString(rf_string, message, + &TestAllTypes::repeated_string); + + // Test iterators for message fields. + typedef RepeatedFieldRef::iterator MessageIterator; + int index = 0; + for (MessageIterator it = rf_foreign_message.begin(); + it != rf_foreign_message.end(); ++it) { + EXPECT_EQ(message.repeated_foreign_message(index).c(), it->c()); + ++index; + } + EXPECT_EQ(10, index); + + // Test iterator operators that are not usually used in regular for-loops. + // Including: post increment, assign, ==. + MessageIterator old_it = rf_foreign_message.begin(); + MessageIterator new_it = old_it++; + EXPECT_FALSE(old_it == new_it); + // Check that old_it++ increments old_it once. + for (index = 1; old_it != rf_foreign_message.end(); ++old_it, ++index) { + EXPECT_EQ(message.repeated_foreign_message(index).c(), old_it->c()); + } + EXPECT_EQ(10, index); + // Test assign operator. + old_it = new_it; + for (index = 0; old_it != rf_foreign_message.end(); ++old_it, ++index) { + EXPECT_EQ(message.repeated_foreign_message(index).c(), old_it->c()); + } + EXPECT_EQ(10, index); + // Check that the returned value of old_it++ is the one before increment. + for (index = 0; new_it != rf_foreign_message.end(); ++new_it, ++index) { + EXPECT_EQ(message.repeated_foreign_message(index).c(), new_it->c()); + } + EXPECT_EQ(10, index); + + // Test MutableRepeatedFieldRef::Reserve() + mrf_int32.Reserve(mrf_int32.size() + 1); + mrf_double.Reserve(mrf_double.size() + 1); + mrf_string.Reserve(mrf_string.size() + 1); + mrf_foreign_message.Reserve(mrf_foreign_message.size() + 1); + + // Test MutableRepeatedFieldRef::Add() + mrf_int32.Add(1234); + mrf_double.Add(1234.0); + mrf_string.Add("1234"); + ForeignMessage foreign_message; + foreign_message.set_c(1234); + mrf_foreign_message.Add(foreign_message); + EXPECT_EQ(1234, message.repeated_int32(10)); + EXPECT_EQ(1234.0, message.repeated_double(10)); + EXPECT_EQ("1234", message.repeated_string(10)); + EXPECT_EQ(1234, message.repeated_foreign_message(10).c()); + + // Test MutableRepeatedFieldRef::RemoveLast() + mrf_int32.RemoveLast(); + mrf_double.RemoveLast(); + mrf_string.RemoveLast(); + mrf_foreign_message.RemoveLast(); + EXPECT_EQ(10, message.repeated_int32_size()); + EXPECT_EQ(10, message.repeated_double_size()); + EXPECT_EQ(10, message.repeated_string_size()); + EXPECT_EQ(10, message.repeated_foreign_message_size()); + + // Test MutableRepeatedFieldRef::SwapElements() + mrf_int32.SwapElements(0, 9); + mrf_double.SwapElements(0, 9); + mrf_string.SwapElements(0, 9); + mrf_foreign_message.SwapElements(0, 9); + EXPECT_EQ(Func(9, -1), message.repeated_int32(0)); + EXPECT_EQ(Func(0, -1), message.repeated_int32(9)); + EXPECT_EQ(Func(9, -2), message.repeated_double(0)); + EXPECT_EQ(Func(0, -2), message.repeated_double(9)); + EXPECT_EQ(StrFunc(9, -5), message.repeated_string(0)); + EXPECT_EQ(StrFunc(0, -5), message.repeated_string(9)); + EXPECT_EQ(Func(9, 7), message.repeated_foreign_message(0).c()); + EXPECT_EQ(Func(0, 7), message.repeated_foreign_message(9).c()); + + // Test MutableRepeatedFieldRef::Clear() + mrf_int32.Clear(); + mrf_double.Clear(); + mrf_string.Clear(); + mrf_foreign_message.Clear(); + EXPECT_EQ(0, message.repeated_int32_size()); + EXPECT_EQ(0, message.repeated_double_size()); + EXPECT_EQ(0, message.repeated_string_size()); + EXPECT_EQ(0, message.repeated_foreign_message_size()); + + // Test (Mutable)RepeatedFieldRef::empty() + EXPECT_TRUE(rf_int32.empty()); + EXPECT_TRUE(mrf_int32.empty()); + EXPECT_TRUE(rf_double.empty()); + EXPECT_TRUE(mrf_double.empty()); + EXPECT_TRUE(rf_string.empty()); + EXPECT_TRUE(mrf_string.empty()); + EXPECT_TRUE(rf_foreign_message.empty()); + EXPECT_TRUE(mrf_foreign_message.empty()); + EXPECT_TRUE(rf_message.empty()); + EXPECT_TRUE(mrf_message.empty()); + +#if GTEST_HAS_DEATH_TEST + + // Make sure types are checked correctly at runtime. + const FieldDescriptor* fd_optional_int32 = + desc->FindFieldByName("optional_int32"); + EXPECT_DEATH(refl->GetRepeatedFieldRef(message, fd_optional_int32), + ""); + EXPECT_DEATH(refl->GetRepeatedFieldRef(message, fd_repeated_int32), + ""); + EXPECT_DEATH(refl->GetRepeatedFieldRef( + message, fd_repeated_foreign_message), + ""); + +#endif // GTEST_HAS_DEATH_TEST +} + +TEST(REFLECTION_TEST, RepeatedFieldRefForEnums) { + TestAllTypes message; + const Reflection* refl = message.GetReflection(); + const Descriptor* desc = message.GetDescriptor(); + + for (int i = 0; i < 10; ++i) { + message.add_repeated_nested_enum(TestAllTypes::BAR); + } + + const FieldDescriptor* fd_repeated_nested_enum = + desc->FindFieldByName("repeated_nested_enum"); + const RepeatedFieldRef enum_ref = + refl->GetRepeatedFieldRef( + message, fd_repeated_nested_enum); + const MutableRepeatedFieldRef mutable_enum_ref = + refl->GetMutableRepeatedFieldRef( + &message, fd_repeated_nested_enum); + const RepeatedFieldRef int32_ref = + refl->GetRepeatedFieldRef(message, fd_repeated_nested_enum); + const MutableRepeatedFieldRef mutable_int32_ref = + refl->GetMutableRepeatedFieldRef(&message, + fd_repeated_nested_enum); + + EXPECT_EQ(message.repeated_nested_enum_size(), enum_ref.size()); + EXPECT_EQ(message.repeated_nested_enum_size(), mutable_enum_ref.size()); + EXPECT_EQ(message.repeated_nested_enum_size(), int32_ref.size()); + EXPECT_EQ(message.repeated_nested_enum_size(), mutable_int32_ref.size()); + + EXPECT_FALSE(enum_ref.empty()); + EXPECT_FALSE(mutable_enum_ref.empty()); + EXPECT_FALSE(int32_ref.empty()); + EXPECT_FALSE(mutable_int32_ref.empty()); + + for (int i = 0; i < 10; ++i) { + EXPECT_EQ(TestAllTypes::BAR, enum_ref.Get(i)); + EXPECT_EQ(TestAllTypes::BAR, mutable_enum_ref.Get(i)); + mutable_enum_ref.Set(i, TestAllTypes::BAZ); + EXPECT_EQ(TestAllTypes::BAZ, enum_ref.Get(i)); + EXPECT_EQ(TestAllTypes::BAZ, message.repeated_nested_enum(i)); + + message.set_repeated_nested_enum(i, TestAllTypes::BAR); + EXPECT_EQ(TestAllTypes::BAR, int32_ref.Get(i)); + EXPECT_EQ(TestAllTypes::BAR, mutable_int32_ref.Get(i)); + mutable_int32_ref.Set(i, TestAllTypes::BAZ); + EXPECT_EQ(TestAllTypes::BAZ, int32_ref.Get(i)); + EXPECT_EQ(TestAllTypes::BAZ, message.repeated_nested_enum(i)); + } + + TestRepeatedFieldRefIteratorForPrimitive(enum_ref, message, + &TestAllTypes::repeated_nested_enum); + TestRepeatedFieldRefIteratorForPrimitive(int32_ref, message, + &TestAllTypes::repeated_nested_enum); + + // Test Add() + mutable_enum_ref.Add(TestAllTypes::FOO); + EXPECT_EQ(TestAllTypes::FOO, message.repeated_nested_enum(10)); + mutable_int32_ref.Add(TestAllTypes::BAR); + EXPECT_EQ(TestAllTypes::BAR, message.repeated_nested_enum(11)); + + // Test RemoveLast() + mutable_enum_ref.RemoveLast(); + EXPECT_EQ(11, message.repeated_nested_enum_size()); + mutable_int32_ref.RemoveLast(); + EXPECT_EQ(10, message.repeated_nested_enum_size()); + + // Test SwapElements() + mutable_enum_ref.Set(0, TestAllTypes::BAR); + mutable_enum_ref.Set(9, TestAllTypes::BAZ); + mutable_enum_ref.SwapElements(0, 9); + EXPECT_EQ(TestAllTypes::BAZ, enum_ref.Get(0)); + EXPECT_EQ(TestAllTypes::BAR, enum_ref.Get(9)); + mutable_int32_ref.SwapElements(0, 9); + EXPECT_EQ(TestAllTypes::BAR, enum_ref.Get(0)); + EXPECT_EQ(TestAllTypes::BAZ, enum_ref.Get(9)); + + // Test Clear() + mutable_enum_ref.Clear(); + EXPECT_EQ(0, message.repeated_nested_enum_size()); + mutable_enum_ref.Add(TestAllTypes::FOO); + EXPECT_EQ(1, message.repeated_nested_enum_size()); + mutable_int32_ref.Clear(); + EXPECT_EQ(0, message.repeated_nested_enum_size()); + + // Test empty() + EXPECT_TRUE(enum_ref.empty()); + EXPECT_TRUE(mutable_enum_ref.empty()); + EXPECT_TRUE(int32_ref.empty()); + EXPECT_TRUE(mutable_int32_ref.empty()); +} + +TEST(REFLECTION_TEST, RepeatedFieldRefForExtensionFields) { + TestAllExtensions extended_message; + const Reflection* refl = extended_message.GetReflection(); + const Descriptor* desc = extended_message.GetDescriptor(); + + for (int i = 0; i < 10; ++i) { + extended_message.AddExtension(UNITTEST::repeated_int64_extension, + Func(i, 1)); + } + + const FieldDescriptor* fd_repeated_int64_extension = + desc->file()->FindExtensionByName("repeated_int64_extension"); + ABSL_CHECK(fd_repeated_int64_extension != nullptr); + + const RepeatedFieldRef rf_int64_extension = + refl->GetRepeatedFieldRef(extended_message, + fd_repeated_int64_extension); + + const MutableRepeatedFieldRef mrf_int64_extension = + refl->GetMutableRepeatedFieldRef(&extended_message, + fd_repeated_int64_extension); + + for (int i = 0; i < 10; ++i) { + EXPECT_EQ(Func(i, 1), rf_int64_extension.Get(i)); + mrf_int64_extension.Set(i, Func(i, -1)); + EXPECT_EQ(Func(i, -1), extended_message.GetExtension( + UNITTEST::repeated_int64_extension, i)); + } +} + + +TEST(REFLECTION_TEST, RepeatedFieldRefMergeFromAndSwap) { + // Set-up message content. + TestAllTypes m0, m1, m2; + for (int i = 0; i < 10; ++i) { + m0.add_repeated_int32(Func(i, 1)); + m0.add_repeated_double(Func(i, 2)); + m0.add_repeated_string(StrFunc(i, 5)); + m0.add_repeated_foreign_message()->set_c(Func(i, 6)); + m0.add_repeated_nested_enum(TestAllTypes::FOO); + m1.add_repeated_int32(Func(i, 11)); + m1.add_repeated_double(Func(i, 12)); + m1.add_repeated_string(StrFunc(i, 15)); + m1.add_repeated_foreign_message()->set_c(Func(i, 16)); + m1.add_repeated_nested_enum(TestAllTypes::BAR); + m2.add_repeated_int32(Func(i, 21)); + m2.add_repeated_double(Func(i, 22)); + m2.add_repeated_string(StrFunc(i, 25)); + m2.add_repeated_foreign_message()->set_c(Func(i, 26)); + m2.add_repeated_nested_enum(TestAllTypes::BAZ); + } + + const Reflection* refl = m0.GetReflection(); + const Descriptor* desc = m0.GetDescriptor(); + + // Get FieldDescriptors for all the fields of interest. + const FieldDescriptor* fd_repeated_int32 = + desc->FindFieldByName("repeated_int32"); + const FieldDescriptor* fd_repeated_double = + desc->FindFieldByName("repeated_double"); + const FieldDescriptor* fd_repeated_string = + desc->FindFieldByName("repeated_string"); + const FieldDescriptor* fd_repeated_foreign_message = + desc->FindFieldByName("repeated_foreign_message"); + const FieldDescriptor* fd_repeated_nested_enum = + desc->FindFieldByName("repeated_nested_enum"); + + // Get MutableRepeatedFieldRef objects for all fields of interest. + const MutableRepeatedFieldRef mrf_int32 = + refl->GetMutableRepeatedFieldRef(&m0, fd_repeated_int32); + const MutableRepeatedFieldRef mrf_double = + refl->GetMutableRepeatedFieldRef(&m0, fd_repeated_double); + const MutableRepeatedFieldRef mrf_string = + refl->GetMutableRepeatedFieldRef(&m0, fd_repeated_string); + const MutableRepeatedFieldRef mrf_foreign_message = + refl->GetMutableRepeatedFieldRef( + &m0, fd_repeated_foreign_message); + const MutableRepeatedFieldRef mrf_nested_enum = + refl->GetMutableRepeatedFieldRef( + &m0, fd_repeated_nested_enum); + + // Test MutableRepeatedRef::CopyFrom + mrf_int32.CopyFrom(refl->GetRepeatedFieldRef(m1, fd_repeated_int32)); + mrf_double.CopyFrom( + refl->GetRepeatedFieldRef(m1, fd_repeated_double)); + mrf_string.CopyFrom( + refl->GetRepeatedFieldRef(m1, fd_repeated_string)); + mrf_foreign_message.CopyFrom(refl->GetRepeatedFieldRef( + m1, fd_repeated_foreign_message)); + mrf_nested_enum.CopyFrom(refl->GetRepeatedFieldRef( + m1, fd_repeated_nested_enum)); + for (int i = 0; i < 10; ++i) { + EXPECT_EQ(Func(i, 11), m0.repeated_int32(i)); + EXPECT_EQ(Func(i, 12), m0.repeated_double(i)); + EXPECT_EQ(StrFunc(i, 15), m0.repeated_string(i)); + EXPECT_EQ(Func(i, 16), m0.repeated_foreign_message(i).c()); + EXPECT_EQ(TestAllTypes::BAR, m0.repeated_nested_enum(i)); + } + + // Test MutableRepeatedRef::MergeFrom + mrf_int32.MergeFrom( + refl->GetRepeatedFieldRef(m2, fd_repeated_int32)); + mrf_double.MergeFrom( + refl->GetRepeatedFieldRef(m2, fd_repeated_double)); + mrf_string.MergeFrom( + refl->GetRepeatedFieldRef(m2, fd_repeated_string)); + mrf_foreign_message.MergeFrom(refl->GetRepeatedFieldRef( + m2, fd_repeated_foreign_message)); + mrf_nested_enum.MergeFrom(refl->GetRepeatedFieldRef( + m2, fd_repeated_nested_enum)); + for (int i = 0; i < 10; ++i) { + EXPECT_EQ(Func(i, 21), m0.repeated_int32(i + 10)); + EXPECT_EQ(Func(i, 22), m0.repeated_double(i + 10)); + EXPECT_EQ(StrFunc(i, 25), m0.repeated_string(i + 10)); + EXPECT_EQ(Func(i, 26), m0.repeated_foreign_message(i + 10).c()); + EXPECT_EQ(TestAllTypes::BAZ, m0.repeated_nested_enum(i + 10)); + } + + // Test MutableRepeatedRef::Swap + // Swap between m0 and m2. + mrf_int32.Swap( + refl->GetMutableRepeatedFieldRef(&m2, fd_repeated_int32)); + mrf_double.Swap( + refl->GetMutableRepeatedFieldRef(&m2, fd_repeated_double)); + mrf_string.Swap( + refl->GetMutableRepeatedFieldRef(&m2, fd_repeated_string)); + mrf_foreign_message.Swap(refl->GetMutableRepeatedFieldRef( + &m2, fd_repeated_foreign_message)); + mrf_nested_enum.Swap( + refl->GetMutableRepeatedFieldRef( + &m2, fd_repeated_nested_enum)); + for (int i = 0; i < 10; ++i) { + // Check the content of m0. + EXPECT_EQ(Func(i, 21), m0.repeated_int32(i)); + EXPECT_EQ(Func(i, 22), m0.repeated_double(i)); + EXPECT_EQ(StrFunc(i, 25), m0.repeated_string(i)); + EXPECT_EQ(Func(i, 26), m0.repeated_foreign_message(i).c()); + EXPECT_EQ(TestAllTypes::BAZ, m0.repeated_nested_enum(i)); + + // Check the content of m2. + EXPECT_EQ(Func(i, 11), m2.repeated_int32(i)); + EXPECT_EQ(Func(i, 12), m2.repeated_double(i)); + EXPECT_EQ(StrFunc(i, 15), m2.repeated_string(i)); + EXPECT_EQ(Func(i, 16), m2.repeated_foreign_message(i).c()); + EXPECT_EQ(TestAllTypes::BAR, m2.repeated_nested_enum(i)); + EXPECT_EQ(Func(i, 21), m2.repeated_int32(i + 10)); + EXPECT_EQ(Func(i, 22), m2.repeated_double(i + 10)); + EXPECT_EQ(StrFunc(i, 25), m2.repeated_string(i + 10)); + EXPECT_EQ(Func(i, 26), m2.repeated_foreign_message(i + 10).c()); + EXPECT_EQ(TestAllTypes::BAZ, m2.repeated_nested_enum(i + 10)); + } +} + +// Test that GetRepeatedFieldRef/MutableRepeatedFieldRef works with +// DynamicMessage. +TEST(REFLECTION_TEST, RepeatedFieldRefDynamicMessage) { + // DynamicMessage shares the same memory layout as generated message + // and use the same GeneratedMessageReflection code for reflection. + // All code paths should already be covered by the other tests for + // generated messages. Here we just test one field. + + const Descriptor* desc = TestAllTypes::descriptor(); + const FieldDescriptor* fd_repeated_int32 = + desc->FindFieldByName("repeated_int32"); + + DynamicMessageFactory factory; + std::unique_ptr dynamic_message(factory.GetPrototype(desc)->New()); + const Reflection* refl = dynamic_message->GetReflection(); + + MutableRepeatedFieldRef rf_int32 = + refl->GetMutableRepeatedFieldRef(dynamic_message.get(), + fd_repeated_int32); + rf_int32.Add(1234); + EXPECT_EQ(1, refl->FieldSize(*dynamic_message, fd_repeated_int32)); + EXPECT_EQ(1234, + refl->GetRepeatedInt32(*dynamic_message, fd_repeated_int32, 0)); +} + +} // namespace +} // namespace protobuf +} // namespace google From 9d0a30d2e5a3c7067ab7102671754b3e898f32e0 Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Wed, 20 Dec 2023 07:40:10 +0000 Subject: [PATCH 068/255] Auto-generate files after cl/592453467 --- src/file_lists.cmake | 1 + 1 file changed, 1 insertion(+) diff --git a/src/file_lists.cmake b/src/file_lists.cmake index 679cb83df05c3..460600efead72 100644 --- a/src/file_lists.cmake +++ b/src/file_lists.cmake @@ -663,6 +663,7 @@ set(test_util_hdrs ${protobuf_SOURCE_DIR}/src/google/protobuf/map_test_util.inc ${protobuf_SOURCE_DIR}/src/google/protobuf/message_unittest.inc ${protobuf_SOURCE_DIR}/src/google/protobuf/reflection_tester.h + ${protobuf_SOURCE_DIR}/src/google/protobuf/repeated_field_reflection_unittest.inc ${protobuf_SOURCE_DIR}/src/google/protobuf/test_util.h ${protobuf_SOURCE_DIR}/src/google/protobuf/test_util.inc ${protobuf_SOURCE_DIR}/src/google/protobuf/unredacted_debug_format_for_test.h From b539fa9c050e399ffa970aa3910610480753239a Mon Sep 17 00:00:00 2001 From: Jakob Buchgraber Date: Wed, 20 Dec 2023 02:41:41 -0800 Subject: [PATCH 069/255] #cleanup Drop MapWithKeyOps::Value type in favor of Proxied::View. PiperOrigin-RevId: 592497727 --- rust/cpp.rs | 38 +++++++++++++++++--------------------- rust/map.rs | 8 ++++---- rust/upb.rs | 40 +++++++++++++++++++--------------------- 3 files changed, 40 insertions(+), 46 deletions(-) diff --git a/rust/cpp.rs b/rust/cpp.rs index 2f43225359012..aafb799dba882 100644 --- a/rust/cpp.rs +++ b/rust/cpp.rs @@ -9,7 +9,7 @@ use crate::ProtoStr; use crate::__internal::{Private, PtrAndLen, RawArena, RawMap, RawMessage, RawRepeatedField}; -use crate::{Mut, ProxiedInRepeated, Repeated, View}; +use crate::{Mut, Proxied, ProxiedInRepeated, Repeated, View}; use core::fmt::Debug; use paste::paste; use std::alloc::Layout; @@ -305,14 +305,12 @@ macro_rules! generate_map_with_key_ops_traits { ($($t:ty, $sized_t:ty;)*) => { paste! { $( - pub trait [< MapWith $t:camel KeyOps >] { - type Value<'msg>: Sized; - + pub trait [< MapWith $t:camel KeyOps >] : Proxied { fn new_map() -> RawMap; fn clear(m: RawMap); fn size(m: RawMap) -> usize; - fn insert(m: RawMap, key: $sized_t, value: Self::Value<'_>) -> bool; - fn get<'msg>(m: RawMap, key: $sized_t) -> Option>; + fn insert(m: RawMap, key: $sized_t, value: View<'_, Self>) -> bool; + fn get<'msg>(m: RawMap, key: $sized_t) -> Option>; fn remove(m: RawMap, key: $sized_t) -> bool; } @@ -335,7 +333,7 @@ macro_rules! generate_map_with_key_ops_traits { V::clear(self.raw) } - pub fn get<'a>(&self, key: $sized_t) -> Option> { + pub fn get<'a>(&self, key: $sized_t) -> Option> { V::get(self.raw, key) } @@ -343,7 +341,7 @@ macro_rules! generate_map_with_key_ops_traits { V::remove(self.raw, key) } - pub fn insert(&mut self, key: $sized_t, value: V::Value<'_>) -> bool { + pub fn insert(&mut self, key: $sized_t, value: View<'_, V>) -> bool { V::insert(self.raw, key, value); true } @@ -363,7 +361,7 @@ generate_map_with_key_ops_traits!( ); macro_rules! impl_scalar_map_with_key_op_for_scalar_values { - ($key_t:ty, $sized_key_t:ty, $ffi_key_t:ty, $to_ffi_key:expr, $trait:ident for $($t:ty, $sized_t:ty, $ffi_t:ty, $to_ffi_value:expr, $from_ffi_value:expr, $zero_val:literal;)*) => { + ($key_t:ty, $sized_key_t:ty, $ffi_key_t:ty, $to_ffi_key:expr, $trait:ident for $($t:ty, $ffi_t:ty, $to_ffi_value:expr, $from_ffi_value:expr, $zero_val:literal;)*) => { paste! { $( extern "C" { fn [< __pb_rust_Map_ $key_t _ $t _new >]() -> RawMap; @@ -374,8 +372,6 @@ macro_rules! impl_scalar_map_with_key_op_for_scalar_values { fn [< __pb_rust_Map_ $key_t _ $t _remove >](m: RawMap, key: $ffi_key_t, value: *mut $ffi_t) -> bool; } impl $trait for $t { - type Value<'msg> = $sized_t; - fn new_map() -> RawMap { unsafe { [< __pb_rust_Map_ $key_t _ $t _new >]() } } @@ -388,14 +384,14 @@ macro_rules! impl_scalar_map_with_key_op_for_scalar_values { unsafe { [< __pb_rust_Map_ $key_t _ $t _size >](m) } } - fn insert(m: RawMap, key: $sized_key_t, value: Self::Value<'_>) -> bool { + fn insert(m: RawMap, key: $sized_key_t, value: View<'_, Self>) -> bool { let ffi_key = $to_ffi_key(key); let ffi_value = $to_ffi_value(value); unsafe { [< __pb_rust_Map_ $key_t _ $t _insert >](m, ffi_key, ffi_value) } true } - fn get<'msg>(m: RawMap, key: $sized_key_t) -> Option> { + fn get<'msg>(m: RawMap, key: $sized_key_t) -> Option> { let ffi_key = $to_ffi_key(key); let mut ffi_value = $to_ffi_value($zero_val); let found = unsafe { [< __pb_rust_Map_ $key_t _ $t _get >](m, ffi_key, &mut ffi_value) }; @@ -428,14 +424,14 @@ macro_rules! impl_map_with_key_ops_for_scalar_values { paste! { $( impl_scalar_map_with_key_op_for_scalar_values!($t, $t_sized, $ffi_t, $to_ffi_key, [< MapWith $t:camel KeyOps >] for - f32, f32, f32, identity, identity, 0f32; - f64, f64, f64, identity, identity, 0f64; - i32, i32, i32, identity, identity, 0i32; - u32, u32, u32, identity, identity, 0u32; - i64, i64, i64, identity, identity, 0i64; - u64, u64, u64, identity, identity, 0u64; - bool, bool, bool, identity, identity, false; - ProtoStr, &'msg ProtoStr, PtrAndLen, str_to_ptrlen, ptrlen_to_str, ""; + f32, f32, identity, identity, 0f32; + f64, f64, identity, identity, 0f64; + i32, i32, identity, identity, 0i32; + u32, u32, identity, identity, 0u32; + i64, i64, identity, identity, 0i64; + u64, u64, identity, identity, 0u64; + bool, bool, identity, identity, false; + ProtoStr, PtrAndLen, str_to_ptrlen, ptrlen_to_str, ""; ); )* } diff --git a/rust/map.rs b/rust/map.rs index 795c107571d63..2819648170c4e 100644 --- a/rust/map.rs +++ b/rust/map.rs @@ -155,7 +155,7 @@ macro_rules! impl_scalar_map_keys { ($(key_type $t:ty;)*) => { paste! { $( impl<'msg, V: [< MapWith $t:camel KeyOps >] + Proxied + ?Sized + 'msg> MapView<'msg, $t, V> { - pub fn get<'b>(&self, key: $t) -> Option> { + pub fn get<'b>(&self, key: $t) -> Option> { self.inner.get(key) } @@ -169,7 +169,7 @@ macro_rules! impl_scalar_map_keys { } impl<'msg, V: [< MapWith $t:camel KeyOps >] + Proxied + ?Sized + 'msg> MapMut<'msg, $t, V> { - pub fn insert(&mut self, key: $t, value: V::Value<'_>) -> bool { + pub fn insert(&mut self, key: $t, value: View<'_, V>) -> bool { self.inner.insert(key, value) } @@ -198,7 +198,7 @@ impl_scalar_map_keys!( ); impl<'msg, V: MapWithProtoStrKeyOps + Proxied + ?Sized + 'msg> MapView<'msg, ProtoStr, V> { - pub fn get(&self, key: impl Into<&'msg ProtoStr>) -> Option> { + pub fn get(&self, key: impl Into<&'msg ProtoStr>) -> Option> { self.inner.get(key.into()) } @@ -212,7 +212,7 @@ impl<'msg, V: MapWithProtoStrKeyOps + Proxied + ?Sized + 'msg> MapView<'msg, Pro } impl<'msg, V: MapWithProtoStrKeyOps + Proxied + ?Sized + 'msg> MapMut<'msg, ProtoStr, V> { - pub fn insert(&mut self, key: impl Into<&'msg ProtoStr>, value: V::Value<'_>) -> bool { + pub fn insert(&mut self, key: impl Into<&'msg ProtoStr>, value: View<'_, V>) -> bool { self.inner.insert(key.into(), value) } diff --git a/rust/upb.rs b/rust/upb.rs index cef685c3a98f4..8a3e0b905fc40 100644 --- a/rust/upb.rs +++ b/rust/upb.rs @@ -9,7 +9,9 @@ use crate::ProtoStr; use crate::__internal::{Private, PtrAndLen, RawArena, RawMap, RawMessage, RawRepeatedField}; -use crate::{Mut, ProxiedInRepeated, Repeated, RepeatedMut, RepeatedView, View, ViewProxy}; +use crate::{ + Mut, Proxied, ProxiedInRepeated, Repeated, RepeatedMut, RepeatedView, View, ViewProxy, +}; use core::fmt::Debug; use paste::paste; use std::alloc; @@ -519,9 +521,7 @@ macro_rules! generate_map_key_ops_traits { ($($t:ty, $sized_t:ty;)*) => { paste! { $( - pub trait [< MapWith $t:camel KeyOps >] { - type Value<'msg>: Sized; - + pub trait [< MapWith $t:camel KeyOps >] : Proxied { fn new_map(a: RawArena) -> RawMap; fn clear(m: RawMap) { unsafe { upb_Map_Clear(m) } @@ -529,8 +529,8 @@ macro_rules! generate_map_key_ops_traits { fn size(m: RawMap) -> usize { unsafe { upb_Map_Size(m) } } - fn insert(m: RawMap, a: RawArena, key: $sized_t, value: Self::Value<'_>) -> bool; - fn get<'msg>(m: RawMap, key: $sized_t) -> Option>; + fn insert(m: RawMap, a: RawArena, key: $sized_t, value: View<'_, Self>) -> bool; + fn get<'msg>(m: RawMap, key: $sized_t) -> Option>; fn remove(m: RawMap, key: $sized_t) -> bool; } @@ -553,7 +553,7 @@ macro_rules! generate_map_key_ops_traits { V::clear(self.raw) } - pub fn get<'a>(&self, key: $sized_t) -> Option> { + pub fn get<'a>(&self, key: $sized_t) -> Option> { V::get(self.raw, key) } @@ -561,7 +561,7 @@ macro_rules! generate_map_key_ops_traits { V::remove(self.raw, key) } - pub fn insert(&mut self, key: $sized_t, value: V::Value<'_>) -> bool { + pub fn insert(&mut self, key: $sized_t, value: View<'_, V>) -> bool { V::insert(self.raw, self.arena.raw(), key, value) } } @@ -580,16 +580,14 @@ generate_map_key_ops_traits!( ); macro_rules! impl_scalar_map_key_op_for_scalar_values { - ($key_t:ty, $key_msg_val:expr, $key_upb_tag:expr, $trait:ident for $($t:ty, $sized_t:ty, $msg_val:expr, $from_msg_val:expr, $upb_tag:expr, $zero_val:literal;)*) => { + ($key_t:ty, $key_msg_val:expr, $key_upb_tag:expr, $trait:ident for $($t:ty, $msg_val:expr, $from_msg_val:expr, $upb_tag:expr, $zero_val:literal;)*) => { $( impl $trait for $t { - type Value<'msg> = $sized_t; - fn new_map(a: RawArena) -> RawMap { unsafe { upb_Map_New(a, $key_upb_tag, $upb_tag) } } - fn insert(m: RawMap, a: RawArena, key: $key_t, value: Self::Value<'_>) -> bool { + fn insert(m: RawMap, a: RawArena, key: $key_t, value: View<'_, Self>) -> bool { unsafe { upb_Map_Set( m, @@ -600,7 +598,7 @@ macro_rules! impl_scalar_map_key_op_for_scalar_values { } } - fn get<'msg>(m: RawMap, key: $key_t) -> Option> { + fn get<'msg>(m: RawMap, key: $key_t) -> Option> { let mut val = $msg_val($zero_val); let found = unsafe { upb_Map_Get(m, $key_msg_val(key), &mut val) @@ -647,14 +645,14 @@ macro_rules! impl_map_key_ops_for_scalar_values { paste! { $( impl_scalar_map_key_op_for_scalar_values!($t_sized, $key_msg_val, $upb_tag, [< MapWith $t:camel KeyOps >] for - f32, f32, scalar_to_msg!(float_val), scalar_from_msg!(float_val), UpbCType::Float, 0f32; - f64, f64, scalar_to_msg!(double_val), scalar_from_msg!(double_val), UpbCType::Double, 0f64; - i32, i32, scalar_to_msg!(int32_val), scalar_from_msg!(int32_val), UpbCType::Int32, 0i32; - u32, u32, scalar_to_msg!(uint32_val), scalar_from_msg!(uint32_val), UpbCType::UInt32, 0u32; - i64, i64, scalar_to_msg!(int64_val), scalar_from_msg!(int64_val), UpbCType::Int64, 0i64; - u64, u64, scalar_to_msg!(uint64_val), scalar_from_msg!(uint64_val), UpbCType::UInt64, 0u64; - bool, bool, scalar_to_msg!(bool_val), scalar_from_msg!(bool_val), UpbCType::Bool, false; - ProtoStr, &'msg ProtoStr, str_to_msg, msg_to_str, UpbCType::String, ""; + f32, scalar_to_msg!(float_val), scalar_from_msg!(float_val), UpbCType::Float, 0f32; + f64, scalar_to_msg!(double_val), scalar_from_msg!(double_val), UpbCType::Double, 0f64; + i32, scalar_to_msg!(int32_val), scalar_from_msg!(int32_val), UpbCType::Int32, 0i32; + u32, scalar_to_msg!(uint32_val), scalar_from_msg!(uint32_val), UpbCType::UInt32, 0u32; + i64, scalar_to_msg!(int64_val), scalar_from_msg!(int64_val), UpbCType::Int64, 0i64; + u64, scalar_to_msg!(uint64_val), scalar_from_msg!(uint64_val), UpbCType::UInt64, 0u64; + bool, scalar_to_msg!(bool_val), scalar_from_msg!(bool_val), UpbCType::Bool, false; + ProtoStr, str_to_msg, msg_to_str, UpbCType::String, ""; ); )* } From 9d749cd5b0fe5fe35132d12773a0cecfd2c320ae Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Wed, 20 Dec 2023 05:00:09 -0800 Subject: [PATCH 070/255] Change Thunks that take by ref to take by pointer. PiperOrigin-RevId: 592525870 --- rust/cpp_kernel/cpp_api.cc | 10 ++++++---- src/google/protobuf/compiler/rust/accessors/map.cc | 4 ++-- .../compiler/rust/accessors/repeated_scalar.cc | 5 +++-- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/rust/cpp_kernel/cpp_api.cc b/rust/cpp_kernel/cpp_api.cc index 0536b9356bf83..a71db58e65b6c 100644 --- a/rust/cpp_kernel/cpp_api.cc +++ b/rust/cpp_kernel/cpp_api.cc @@ -1,5 +1,6 @@ #include "rust/cpp_kernel/cpp_api.h" +#include #include #include @@ -33,8 +34,8 @@ extern "C" { return r->Set(index, val); \ } \ void __pb_rust_RepeatedField_##rust_ty##_copy_from( \ - google::protobuf::RepeatedField const& src, google::protobuf::RepeatedField& dst) { \ - dst.CopyFrom(src); \ + const google::protobuf::RepeatedField* src, google::protobuf::RepeatedField* dst) { \ + dst->CopyFrom(*src); \ } \ void __pb_rust_RepeatedField_##rust_ty##_clear( \ google::protobuf::RepeatedField* r) { \ @@ -63,7 +64,7 @@ expose_repeated_field_methods(int64_t, i64); m->clear(); \ } \ size_t __pb_rust_Map_##rust_key_ty##_##rust_value_ty##_size( \ - google::protobuf::Map* m) { \ + const google::protobuf::Map* m) { \ return m->size(); \ } \ void __pb_rust_Map_##rust_key_ty##_##rust_value_ty##_insert( \ @@ -73,7 +74,8 @@ expose_repeated_field_methods(int64_t, i64); (*m)[cpp_key] = cpp_value; \ } \ bool __pb_rust_Map_##rust_key_ty##_##rust_value_ty##_get( \ - google::protobuf::Map* m, ffi_key_ty key, ffi_value_ty* value) { \ + const google::protobuf::Map* m, ffi_key_ty key, \ + ffi_value_ty* value) { \ auto cpp_key = to_cpp_key; \ auto it = m->find(cpp_key); \ if (it == m->end()) { \ diff --git a/src/google/protobuf/compiler/rust/accessors/map.cc b/src/google/protobuf/compiler/rust/accessors/map.cc index 89535d40e27d2..633e21cfda6a1 100644 --- a/src/google/protobuf/compiler/rust/accessors/map.cc +++ b/src/google/protobuf/compiler/rust/accessors/map.cc @@ -135,8 +135,8 @@ void Map::InThunkCc(Context& ctx, const FieldDescriptor& field) const { [&] { ctx.Emit( R"cc( - const void* $getter_thunk$($QualifiedMsg$& msg) { - return &msg.$field$(); + const void* $getter_thunk$(const $QualifiedMsg$* msg) { + return &msg->$field$(); } void* $getter_mut_thunk$($QualifiedMsg$* msg) { return msg->mutable_$field$(); } )cc"); diff --git a/src/google/protobuf/compiler/rust/accessors/repeated_scalar.cc b/src/google/protobuf/compiler/rust/accessors/repeated_scalar.cc index e0e1c6cffc208..9b26784384278 100644 --- a/src/google/protobuf/compiler/rust/accessors/repeated_scalar.cc +++ b/src/google/protobuf/compiler/rust/accessors/repeated_scalar.cc @@ -150,8 +150,9 @@ void RepeatedScalar::InThunkCc(Context& ctx, google::protobuf::RepeatedField<$Scalar$>* $getter_mut_thunk$($QualifiedMsg$* msg) { return msg->mutable_$field$(); } - const google::protobuf::RepeatedField<$Scalar$>& $getter_thunk$($QualifiedMsg$& msg) { - return msg.$field$(); + const google::protobuf::RepeatedField<$Scalar$>* $getter_thunk$( + const $QualifiedMsg$* msg) { + return &msg->$field$(); } )cc"); }}}, From 95ff734d6bbcdaf0722649558f59f30939c1d89a Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Wed, 20 Dec 2023 05:45:11 -0800 Subject: [PATCH 071/255] Remove dead code. PiperOrigin-RevId: 592534243 --- src/google/protobuf/repeated_ptr_field.h | 30 ------------------------ 1 file changed, 30 deletions(-) diff --git a/src/google/protobuf/repeated_ptr_field.h b/src/google/protobuf/repeated_ptr_field.h index cf2d667eec33f..3722fe0750995 100644 --- a/src/google/protobuf/repeated_ptr_field.h +++ b/src/google/protobuf/repeated_ptr_field.h @@ -482,36 +482,6 @@ class PROTOBUF_EXPORT RepeatedPtrFieldBase { int ClearedCount() const { return allocated_size() - current_size_; } - template - void AddCleared(Value* value) { - ABSL_DCHECK(GetArena() == nullptr) << "AddCleared() can only be used on a " - "RepeatedPtrField not on an arena."; - ABSL_DCHECK(TypeHandler::GetArena(value) == nullptr) - << "AddCleared() can only accept values not on an arena."; - MaybeExtend(); - if (using_sso()) { - tagged_rep_or_elem_ = value; - } else { - element_at(rep()->allocated_size++) = value; - } - } - - template - PROTOBUF_NODISCARD Value* ReleaseCleared() { - ABSL_DCHECK(GetArena() == nullptr) - << "ReleaseCleared() can only be used on a RepeatedPtrField not on " - << "an arena."; - ABSL_DCHECK(tagged_rep_or_elem_ != nullptr); - ABSL_DCHECK_GT(allocated_size(), current_size_); - if (using_sso()) { - auto* result = cast(tagged_rep_or_elem_); - tagged_rep_or_elem_ = nullptr; - return result; - } else { - return cast(element_at(--rep()->allocated_size)); - } - } - // Slowpath handles all cases, copying if necessary. template PROTOBUF_NOINLINE void AddAllocatedSlowWithCopy( From c288343d01a85a14de698edd234a7be0ec930a41 Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Wed, 20 Dec 2023 06:52:48 -0800 Subject: [PATCH 072/255] Implement SettableValue[u8] for SerializedData PiperOrigin-RevId: 592547207 --- rust/cpp.rs | 11 ++++++++++- rust/test/shared/serialization_test.rs | 10 ++++++++++ rust/upb.rs | 13 +++++++++++-- 3 files changed, 31 insertions(+), 3 deletions(-) diff --git a/rust/cpp.rs b/rust/cpp.rs index aafb799dba882..8c1e04c8a98cd 100644 --- a/rust/cpp.rs +++ b/rust/cpp.rs @@ -9,7 +9,7 @@ use crate::ProtoStr; use crate::__internal::{Private, PtrAndLen, RawArena, RawMap, RawMessage, RawRepeatedField}; -use crate::{Mut, Proxied, ProxiedInRepeated, Repeated, View}; +use crate::{Mut, Proxied, ProxiedInRepeated, Repeated, SettableValue, View}; use core::fmt::Debug; use paste::paste; use std::alloc::Layout; @@ -139,6 +139,15 @@ impl fmt::Debug for SerializedData { } } +impl SettableValue<[u8]> for SerializedData { + fn set_on<'msg>(self, _private: Private, mut mutator: Mut<'msg, [u8]>) + where + [u8]: 'msg, + { + mutator.set(self.as_ref()) + } +} + pub type BytesPresentMutData<'msg> = crate::vtable::RawVTableOptionalMutatorData<'msg, [u8]>; pub type BytesAbsentMutData<'msg> = crate::vtable::RawVTableOptionalMutatorData<'msg, [u8]>; pub type InnerBytesMut<'msg> = crate::vtable::RawVTableMutator<'msg, [u8]>; diff --git a/rust/test/shared/serialization_test.rs b/rust/test/shared/serialization_test.rs index 0515223fb70d6..2ac49b923d543 100644 --- a/rust/test/shared/serialization_test.rs +++ b/rust/test/shared/serialization_test.rs @@ -37,3 +37,13 @@ fn deserialize_error() { let data = b"not a serialized proto"; assert!(msg.deserialize(&*data).is_err()); } + +#[test] +fn set_bytes_with_serialized_data() { + let mut msg = TestAllTypes::new(); + msg.optional_int64_mut().set(42); + msg.optional_bool_mut().set(true); + let mut msg2 = TestAllTypes::new(); + msg2.optional_bytes_mut().set(msg.serialize()); + assert_that!(msg2.optional_bytes(), eq(msg.serialize().as_ref())); +} diff --git a/rust/upb.rs b/rust/upb.rs index 8a3e0b905fc40..7895bee95c5a3 100644 --- a/rust/upb.rs +++ b/rust/upb.rs @@ -7,10 +7,10 @@ //! UPB FFI wrapper code for use by Rust Protobuf. -use crate::ProtoStr; use crate::__internal::{Private, PtrAndLen, RawArena, RawMap, RawMessage, RawRepeatedField}; use crate::{ - Mut, Proxied, ProxiedInRepeated, Repeated, RepeatedMut, RepeatedView, View, ViewProxy, + Mut, ProtoStr, Proxied, ProxiedInRepeated, Repeated, RepeatedMut, RepeatedView, SettableValue, + View, ViewProxy, }; use core::fmt::Debug; use paste::paste; @@ -217,6 +217,15 @@ impl fmt::Debug for SerializedData { } } +impl SettableValue<[u8]> for SerializedData { + fn set_on<'msg>(self, _private: Private, mut mutator: Mut<'msg, [u8]>) + where + [u8]: 'msg, + { + mutator.set(self.as_ref()) + } +} + // TODO: Investigate replacing this with direct access to UPB bits. pub type BytesPresentMutData<'msg> = crate::vtable::RawVTableOptionalMutatorData<'msg, [u8]>; pub type BytesAbsentMutData<'msg> = crate::vtable::RawVTableOptionalMutatorData<'msg, [u8]>; From 35b564845c60282e32fe0704115fa7f243b20a25 Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Wed, 20 Dec 2023 09:00:04 -0800 Subject: [PATCH 073/255] Do not define a `const` static variable as `constexpr`. While this is legal it is not supported in all toolchains. Should fix https://github.com/protocolbuffers/protobuf/issues/15030 PiperOrigin-RevId: 592574780 --- src/google/protobuf/message.cc | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/google/protobuf/message.cc b/src/google/protobuf/message.cc index 26f6efc283db3..16f0862309afb 100644 --- a/src/google/protobuf/message.cc +++ b/src/google/protobuf/message.cc @@ -192,9 +192,10 @@ static std::string InitializationErrorStringImpl(const MessageLite& msg) { return DownCast(msg).InitializationErrorString(); } -constexpr MessageLite::DescriptorMethods Message::kDescriptorMethods = { - GetTypeNameImpl, - InitializationErrorStringImpl, +PROTOBUF_CONSTINIT const MessageLite::DescriptorMethods + Message::kDescriptorMethods = { + GetTypeNameImpl, + InitializationErrorStringImpl, }; namespace internal { From 0ce51da37730aa5c5bac85b1aa5cdc773589c90b Mon Sep 17 00:00:00 2001 From: Alyssa Haroldsen Date: Wed, 20 Dec 2023 10:08:11 -0800 Subject: [PATCH 074/255] Implement v0.6 enum definitions This does not implement accessors, just the enum definitions themselves. PiperOrigin-RevId: 592591476 --- rust/BUILD | 1 + rust/cpp.rs | 35 +- rust/enum.rs | 51 +++ rust/internal.rs | 1 + rust/shared.rs | 3 + rust/test/BUILD | 27 ++ rust/test/enums.proto | 61 +++ rust/test/shared/BUILD | 36 ++ rust/test/shared/enum_test.rs | 213 ++++++++++ rust/upb.rs | 30 +- src/google/protobuf/compiler/rust/BUILD.bazel | 30 ++ src/google/protobuf/compiler/rust/enum.cc | 365 ++++++++++++++++++ src/google/protobuf/compiler/rust/enum.h | 56 +++ .../protobuf/compiler/rust/enum_test.cc | 84 ++++ .../protobuf/compiler/rust/generator.cc | 7 + src/google/protobuf/compiler/rust/message.cc | 12 +- 16 files changed, 1006 insertions(+), 6 deletions(-) create mode 100644 rust/enum.rs create mode 100644 rust/test/enums.proto create mode 100644 rust/test/shared/enum_test.rs create mode 100644 src/google/protobuf/compiler/rust/enum.cc create mode 100644 src/google/protobuf/compiler/rust/enum.h create mode 100644 src/google/protobuf/compiler/rust/enum_test.cc diff --git a/rust/BUILD b/rust/BUILD index bc6a5cc9f4720..b3374f434fe53 100644 --- a/rust/BUILD +++ b/rust/BUILD @@ -47,6 +47,7 @@ rust_library( # # shared.rs is the root of the crate and has public items re-exported in protobuf.rs for user use. PROTOBUF_SHARED = [ + "enum.rs", "internal.rs", "macros.rs", "optional.rs", diff --git a/rust/cpp.rs b/rust/cpp.rs index 8c1e04c8a98cd..fab875316e4c1 100644 --- a/rust/cpp.rs +++ b/rust/cpp.rs @@ -8,13 +8,16 @@ // Rust Protobuf runtime using the C++ kernel. use crate::ProtoStr; -use crate::__internal::{Private, PtrAndLen, RawArena, RawMap, RawMessage, RawRepeatedField}; -use crate::{Mut, Proxied, ProxiedInRepeated, Repeated, SettableValue, View}; +use crate::__internal::{Enum, Private, PtrAndLen, RawArena, RawMap, RawMessage, RawRepeatedField}; +use crate::{ + Mut, Proxied, ProxiedInRepeated, Repeated, RepeatedMut, RepeatedView, SettableValue, View, +}; use core::fmt::Debug; use paste::paste; use std::alloc::Layout; use std::cell::UnsafeCell; use std::convert::identity; +use std::ffi::c_int; use std::fmt; use std::marker::PhantomData; use std::mem::MaybeUninit; @@ -296,6 +299,34 @@ macro_rules! impl_repeated_primitives { impl_repeated_primitives!(i32, u32, i64, u64, f32, f64, bool); +/// Cast a `RepeatedView` to `RepeatedView`. +pub fn cast_enum_repeated_view( + private: Private, + repeated: RepeatedView, +) -> RepeatedView { + // SAFETY: the implementer of `Enum` has promised that this + // raw repeated is a type-erased `proto2::RepeatedField*`. + unsafe { RepeatedView::from_raw(private, repeated.as_raw(Private)) } +} + +/// Cast a `RepeatedMut` to `RepeatedMut`. +/// +/// Writing an unknown value is sound because all enums +/// are representationally open. +pub fn cast_enum_repeated_mut( + private: Private, + mut repeated: RepeatedMut, +) -> RepeatedMut { + // SAFETY: the implementer of `Enum` has promised that this + // raw repeated is a type-erased `proto2::RepeatedField*`. + unsafe { + RepeatedMut::from_inner( + private, + InnerRepeatedMut { raw: repeated.as_raw(Private), _phantom: PhantomData }, + ) + } +} + #[derive(Debug)] pub struct MapInner<'msg, K: ?Sized, V: ?Sized> { pub raw: RawMap, diff --git a/rust/enum.rs b/rust/enum.rs new file mode 100644 index 0000000000000..847ef41df5370 --- /dev/null +++ b/rust/enum.rs @@ -0,0 +1,51 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2023 Google LLC. All rights reserved. +// +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file or at +// https://developers.google.com/open-source/licenses/bsd + +use crate::__internal::Private; +use std::{ + error::Error, + fmt::{Debug, Display}, + marker::PhantomData, +}; + +/// Implemented by all generated enum types. +/// +/// # Safety +/// - A `RepeatedView` or `RepeatedMut` must have the same internal +/// representation as erased enums in the runtime. +/// - For C++, this is `proto2::RepeatedField` +/// - For UPB, this is an array compatible with `int32` +pub unsafe trait Enum { + /// The name of the enum. + const NAME: &'static str; +} + +/// An integer value wasn't known for an enum while converting. +pub struct UnknownEnumValue(i32, PhantomData); + +impl UnknownEnumValue { + #[doc(hidden)] + pub fn new(_private: Private, unknown_value: i32) -> Self { + Self(unknown_value, PhantomData) + } +} + +impl Debug for UnknownEnumValue { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_tuple("UnknownEnumValue").field(&self.0).finish() + } +} + +impl Display for UnknownEnumValue { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + let val = self.0; + let enum_name = T::NAME; + write!(f, "{val} is not a known value for {enum_name}") + } +} + +impl Error for UnknownEnumValue {} diff --git a/rust/internal.rs b/rust/internal.rs index 6a6ca3007a05c..551dd79bc2acd 100644 --- a/rust/internal.rs +++ b/rust/internal.rs @@ -9,6 +9,7 @@ //! exposed to through the `protobuf` path but must be public for use by //! generated code. +pub use crate::r#enum::Enum; pub use crate::vtable::{ new_vtable_field_entry, BytesMutVTable, BytesOptionalMutVTable, PrimitiveOptionalMutVTable, PrimitiveVTable, PrimitiveWithRawVTable, RawVTableMutator, RawVTableOptionalMutatorData, diff --git a/rust/shared.rs b/rust/shared.rs index 21fd9d385202b..67ece90872c7c 100644 --- a/rust/shared.rs +++ b/rust/shared.rs @@ -22,6 +22,7 @@ use std::fmt; /// These are the items protobuf users can access directly. #[doc(hidden)] pub mod __public { + pub use crate::r#enum::UnknownEnumValue; pub use crate::map::{Map, MapMut, MapView}; pub use crate::optional::{AbsentField, FieldEntry, Optional, PresentField}; pub use crate::primitive::PrimitiveMut; @@ -49,6 +50,8 @@ pub mod __runtime; #[path = "upb.rs"] pub mod __runtime; +#[path = "enum.rs"] +mod r#enum; mod macros; mod map; mod optional; diff --git a/rust/test/BUILD b/rust/test/BUILD index decb41a187c81..186374fb9c399 100644 --- a/rust/test/BUILD +++ b/rust/test/BUILD @@ -200,6 +200,33 @@ rust_upb_proto_library( deps = [":edition2023_proto"], ) +proto_library( + name = "enums_proto", + testonly = True, + srcs = ["enums.proto"], + deps = ["//devtools/staticanalysis/pipeline/analyzers/proto_best_practices/proto:optouts_proto"], +) + +cc_proto_library( + name = "enums_cc_proto", + testonly = True, + deps = [":enums_proto"], +) + +rust_cc_proto_library( + name = "enums_cc_rust_proto", + testonly = True, + visibility = ["//rust/test/shared:__subpackages__"], + deps = [":enums_cc_proto"], +) + +rust_upb_proto_library( + name = "enums_upb_rust_proto", + testonly = True, + visibility = ["//rust/test/shared:__subpackages__"], + deps = [":enums_proto"], +) + proto_library( name = "no_package_import_proto", testonly = True, diff --git a/rust/test/enums.proto b/rust/test/enums.proto new file mode 100644 index 0000000000000..21182bc175822 --- /dev/null +++ b/rust/test/enums.proto @@ -0,0 +1,61 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2023 Google LLC. All rights reserved. +// +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file or at +// https://developers.google.com/open-source/licenses/bsd +// LINT: LEGACY_NAMES + +// The names in this file are meant to test edge cases. +syntax = "proto3"; + +package enums; + +import "devtools/staticanalysis/pipeline/analyzers/proto_best_practices/proto/optouts.proto"; + +option (proto_best_practices.file_optouts) = { + categories: ENUM_DEFAULT_VALUE_NAME_CONFLICT + categories: ENUM_VALUE_NAMES +}; + +// This should result in an enum with these accessible values: +// - Unknown = 0 +// - Unrecognized = 0 +// - Foo = 1 +// - Bar = 2 +// - DifferentNameAlias = 2 +enum TestEnumWithDuplicateStrippedPrefixNames { + option allow_alias = true; + + UNKNOWN = 0; + TestEnumWithDuplicateStrippedPrefixNamesUNRECOGNIZED = 0; + + TestEnumWithDuplicateStrippedPrefixNames_FOO = 1; + TEST_ENUM_WITH_DUPLICATE_STRIPPED_PREFIX_NAMES_FOO = 1; + FOO = 1; + + TestEnumWithDuplicateStrippedPrefixNamesBAR = 2; + TEST_ENUM_WITH_DUPLICATE_STRIPPED_PREFIX_NAMESBar = 2; + BAR = 2; + TEST_ENUM_WITH_DUPLICATE_STRIPPED_PREFIX_NAMES_DIFFERENT_NAME_ALIAS = 2; +} + +// This should result in an enum with these accessible values: +// - Unknown = 0 +// - _2020 = 1 +// - _2021 = 2 +// - _2022 = 3 +enum TestEnumWithNumericNames { + TestEnumWithNumericNamesUNKNOWN = 0; + TestEnumWithNumericNames_2020 = 1; + TEST_ENUM_WITH_NUMERIC_NAMES_2021 = 2; + TEST_ENUM_WITH_NUMERIC_NAMES2022 = 3; +} + +// This should result in an enum with these accessible values: +// - Unknown = 0 +// - TestEnumValueNameSameAsEnum = 1 +enum TestEnumValueNameSameAsEnum { + TEST_ENUM_VALUE_NAME_SAME_AS_ENUM_UNKNOWN = 0; + TEST_ENUM_VALUE_NAME_SAME_AS_ENUM = 1; +} diff --git a/rust/test/shared/BUILD b/rust/test/shared/BUILD index 3541f06d97b45..3a61c4d1439ce 100644 --- a/rust/test/shared/BUILD +++ b/rust/test/shared/BUILD @@ -94,6 +94,42 @@ rust_test( ], ) +rust_test( + name = "enum_cpp_test", + srcs = ["enum_test.rs"], + aliases = { + "//rust:protobuf_cpp": "protobuf", + }, + tags = [ + # TODO: Enable testing on arm once we support sanitizers for Rust on Arm. + "not_build:arm", + ], + deps = [ + "@crate_index//:googletest", + "//rust:protobuf_cpp", + "//rust/test:enums_cc_rust_proto", + "//rust/test:unittest_cc_rust_proto", + ], +) + +rust_test( + name = "enum_upb_test", + srcs = ["enum_test.rs"], + aliases = { + "//rust:protobuf_upb": "protobuf", + }, + tags = [ + # TODO: Enable testing on arm once we support sanitizers for Rust on Arm. + "not_build:arm", + ], + deps = [ + "@crate_index//:googletest", + "//rust:protobuf_upb", + "//rust/test:enums_upb_rust_proto", + "//rust/test:unittest_upb_rust_proto", + ], +) + rust_test( name = "package_cpp_test", srcs = ["package_test.rs"], diff --git a/rust/test/shared/enum_test.rs b/rust/test/shared/enum_test.rs new file mode 100644 index 0000000000000..ced4c6c4eb04a --- /dev/null +++ b/rust/test/shared/enum_test.rs @@ -0,0 +1,213 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2023 Google LLC. All rights reserved. +// +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file or at +// https://developers.google.com/open-source/licenses/bsd + +//! Tests covering enum type generation. + +use enums_proto::enums; +use googletest::prelude::*; +use unittest_proto::proto2_unittest; + +#[test] +fn test_nested_enum_values() { + assert_that!(i32::from(proto2_unittest::TestAllTypes_::NestedEnum::Foo), eq(1)); + assert_that!(i32::from(proto2_unittest::TestAllTypes_::NestedEnum::Bar), eq(2)); + assert_that!(i32::from(proto2_unittest::TestAllTypes_::NestedEnum::Baz), eq(3)); + assert_that!(i32::from(proto2_unittest::TestAllTypes_::NestedEnum::Neg), eq(-1)); +} + +#[test] +fn test_enum_value_name_same_as_enum() { + assert_that!(i32::from(enums::TestEnumValueNameSameAsEnum::TestEnumValueNameSameAsEnum), eq(1)); +} + +#[test] +fn test_enum_defaults() { + assert_that!( + proto2_unittest::TestSparseEnum::default(), + eq(proto2_unittest::TestSparseEnum::SparseA) + ); + assert_that!( + proto2_unittest::TestEnumWithDupValue::default(), + eq(proto2_unittest::TestEnumWithDupValue::Foo1) + ); + assert_that!( + proto2_unittest::TestEnumWithDupValue::default(), + eq(proto2_unittest::TestEnumWithDupValue::Foo2) + ); + assert_that!( + enums::TestEnumWithDuplicateStrippedPrefixNames::default(), + eq(enums::TestEnumWithDuplicateStrippedPrefixNames::Unknown) + ); + assert_that!( + proto2_unittest::TestAllTypes_::NestedEnum::default(), + eq(proto2_unittest::TestAllTypes_::NestedEnum::Foo) + ); +} + +#[test] +#[deny(unreachable_patterns)] +#[allow(clippy::let_unit_value)] +fn test_closed_enum_is_nonexhaustive() { + let val = proto2_unittest::ForeignEnum::ForeignFoo; + let _it_compiles: () = match val { + proto2_unittest::ForeignEnum::ForeignFoo => (), + proto2_unittest::ForeignEnum::ForeignBar => (), + proto2_unittest::ForeignEnum::ForeignBaz => (), + proto2_unittest::ForeignEnum::ForeignBax => (), + _ => unreachable!(), + }; +} + +#[test] +fn test_closed_enum_conversion() { + assert_that!(i32::from(proto2_unittest::TestSparseEnum::SparseA), eq(123)); + assert_that!( + proto2_unittest::TestSparseEnum::try_from(123), + ok(eq(proto2_unittest::TestSparseEnum::SparseA)) + ); + + assert_that!(i32::from(proto2_unittest::TestSparseEnum::SparseD), eq(-15)); + assert_that!( + proto2_unittest::TestSparseEnum::try_from(-15), + ok(eq(proto2_unittest::TestSparseEnum::SparseD)) + ); + + assert_that!( + proto2_unittest::TestSparseEnum::try_from(0), + ok(eq(proto2_unittest::TestSparseEnum::SparseF)) + ); + assert_that!(proto2_unittest::TestSparseEnum::try_from(1), err(anything())); +} + +#[test] +fn test_closed_aliased_enum_conversion() { + assert_that!(i32::from(proto2_unittest::TestEnumWithDupValue::Foo1), eq(1)); + assert_that!(i32::from(proto2_unittest::TestEnumWithDupValue::Foo2), eq(1)); + assert_that!(i32::from(proto2_unittest::TestEnumWithDupValue::Bar1), eq(2)); + assert_that!(i32::from(proto2_unittest::TestEnumWithDupValue::Bar2), eq(2)); + assert_that!(i32::from(proto2_unittest::TestEnumWithDupValue::Baz), eq(3)); + + assert_that!( + proto2_unittest::TestEnumWithDupValue::try_from(1), + ok(eq(proto2_unittest::TestEnumWithDupValue::Foo1)) + ); + assert_that!( + proto2_unittest::TestEnumWithDupValue::try_from(2), + ok(eq(proto2_unittest::TestEnumWithDupValue::Bar1)) + ); + assert_that!( + proto2_unittest::TestEnumWithDupValue::try_from(3), + ok(eq(proto2_unittest::TestEnumWithDupValue::Baz)) + ); + assert_that!(proto2_unittest::TestEnumWithDupValue::try_from(0), err(anything())); + assert_that!(proto2_unittest::TestEnumWithDupValue::try_from(4), err(anything())); + + assert_that!( + proto2_unittest::TestEnumWithDupValue::Foo1, + eq(proto2_unittest::TestEnumWithDupValue::Foo2) + ); + assert_that!( + proto2_unittest::TestEnumWithDupValue::Bar1, + eq(proto2_unittest::TestEnumWithDupValue::Bar2) + ); +} + +#[test] +#[deny(unreachable_patterns)] +#[allow(clippy::let_unit_value)] +fn test_open_enum_is_nonexhaustive() { + let val = enums::TestEnumValueNameSameAsEnum::Unknown; + let _it_compiles: () = match val { + enums::TestEnumValueNameSameAsEnum::Unknown => (), + enums::TestEnumValueNameSameAsEnum::TestEnumValueNameSameAsEnum => (), + _ => unreachable!(), + }; +} + +#[test] +fn test_open_enum_conversion() { + assert_that!(i32::from(enums::TestEnumWithNumericNames::Unknown), eq(0)); + assert_that!(i32::from(enums::TestEnumWithNumericNames::_2020), eq(1)); + assert_that!(i32::from(enums::TestEnumWithNumericNames::_2021), eq(2)); + assert_that!(i32::from(enums::TestEnumWithNumericNames::_2022), eq(3)); + + assert_that!( + enums::TestEnumWithNumericNames::from(0), + eq(enums::TestEnumWithNumericNames::Unknown) + ); + assert_that!( + enums::TestEnumWithNumericNames::from(1), + eq(enums::TestEnumWithNumericNames::_2020) + ); + assert_that!( + enums::TestEnumWithNumericNames::from(2), + eq(enums::TestEnumWithNumericNames::_2021) + ); + assert_that!( + enums::TestEnumWithNumericNames::from(3), + eq(enums::TestEnumWithNumericNames::_2022) + ); + assert_that!( + enums::TestEnumWithNumericNames::from(4), + not(any![ + eq(enums::TestEnumWithNumericNames::Unknown), + eq(enums::TestEnumWithNumericNames::_2020), + eq(enums::TestEnumWithNumericNames::_2021), + eq(enums::TestEnumWithNumericNames::_2022), + ]) + ); + assert_that!(i32::from(enums::TestEnumWithNumericNames::from(-1)), eq(-1)); +} + +#[test] +fn test_open_aliased_enum_conversion() { + assert_that!(i32::from(enums::TestEnumWithDuplicateStrippedPrefixNames::Unknown), eq(0)); + assert_that!(i32::from(enums::TestEnumWithDuplicateStrippedPrefixNames::Foo), eq(1)); + assert_that!(i32::from(enums::TestEnumWithDuplicateStrippedPrefixNames::Bar), eq(2)); + assert_that!( + i32::from(enums::TestEnumWithDuplicateStrippedPrefixNames::DifferentNameAlias), + eq(2) + ); + + assert_that!( + enums::TestEnumWithDuplicateStrippedPrefixNames::from(0), + eq(enums::TestEnumWithDuplicateStrippedPrefixNames::Unknown) + ); + assert_that!( + enums::TestEnumWithDuplicateStrippedPrefixNames::from(1), + eq(enums::TestEnumWithDuplicateStrippedPrefixNames::Foo) + ); + assert_that!( + enums::TestEnumWithDuplicateStrippedPrefixNames::from(2), + eq(enums::TestEnumWithDuplicateStrippedPrefixNames::Bar) + ); + assert_that!( + enums::TestEnumWithDuplicateStrippedPrefixNames::from(2), + eq(enums::TestEnumWithDuplicateStrippedPrefixNames::DifferentNameAlias) + ); + assert_that!( + enums::TestEnumWithDuplicateStrippedPrefixNames::from(3), + not(any![ + eq(enums::TestEnumWithDuplicateStrippedPrefixNames::Unknown), + eq(enums::TestEnumWithDuplicateStrippedPrefixNames::Foo), + eq(enums::TestEnumWithDuplicateStrippedPrefixNames::Bar), + ]) + ); + assert_that!(i32::from(enums::TestEnumWithDuplicateStrippedPrefixNames::from(5)), eq(5)); +} + +#[test] +fn test_enum_conversion_failure_display() { + let err = proto2_unittest::TestSparseEnum::try_from(1).unwrap_err(); + assert_that!(format!("{err}"), eq("1 is not a known value for TestSparseEnum")); +} + +#[test] +fn test_enum_conversion_failure_impls_std_error() { + let err = proto2_unittest::TestSparseEnum::try_from(1).unwrap_err(); + let _test_compiles: &dyn std::error::Error = &err; +} diff --git a/rust/upb.rs b/rust/upb.rs index 7895bee95c5a3..2fe4fda87c16d 100644 --- a/rust/upb.rs +++ b/rust/upb.rs @@ -7,7 +7,7 @@ //! UPB FFI wrapper code for use by Rust Protobuf. -use crate::__internal::{Private, PtrAndLen, RawArena, RawMap, RawMessage, RawRepeatedField}; +use crate::__internal::{Enum, Private, PtrAndLen, RawArena, RawMap, RawMessage, RawRepeatedField}; use crate::{ Mut, ProtoStr, Proxied, ProxiedInRepeated, Repeated, RepeatedMut, RepeatedView, SettableValue, View, ViewProxy, @@ -423,7 +423,7 @@ macro_rules! impl_repeated_primitives { unsafe { upb_Array_Get(f.as_raw(Private), i).$ufield } } unsafe fn repeated_set_unchecked(mut f: Mut>, i: usize, v: View<$t>) { - unsafe { upb_Array_Set(f.as_raw(Private), i, upb_MessageValue { $ufield: v }) } + unsafe { upb_Array_Set(f.as_raw(Private), i, upb_MessageValue { $ufield: v.into() }) } } fn repeated_copy_from(src: View>, mut dest: Mut>) { // SAFETY: @@ -463,6 +463,32 @@ impl_repeated_primitives!( (u64, uint64_val, UpbCType::UInt64), ); +/// Cast a `RepeatedView` to `RepeatedView`. +pub fn cast_enum_repeated_view( + private: Private, + repeated: RepeatedView, +) -> RepeatedView { + // SAFETY: Reading an enum array as an i32 array is sound. + unsafe { RepeatedView::from_raw(private, repeated.as_raw(Private)) } +} + +/// Cast a `RepeatedMut` to `RepeatedMut`. +/// +/// Writing an unknown value is sound because all enums +/// are representationally open. +pub fn cast_enum_repeated_mut( + private: Private, + repeated: RepeatedMut, +) -> RepeatedMut { + // SAFETY: + // - Reading an enum array as an i32 array is sound. + // - No shared mutation is possible through the output. + unsafe { + let InnerRepeatedMut { arena, raw, .. } = repeated.into_inner(); + RepeatedMut::from_inner(private, InnerRepeatedMut { arena, raw, _phantom: PhantomData }) + } +} + /// Returns a static empty RepeatedView. pub fn empty_array() -> RepeatedView<'static, T> { // TODO: Consider creating a static empty array in C. diff --git a/src/google/protobuf/compiler/rust/BUILD.bazel b/src/google/protobuf/compiler/rust/BUILD.bazel index e9639700a1db8..03212d1bae1f4 100644 --- a/src/google/protobuf/compiler/rust/BUILD.bazel +++ b/src/google/protobuf/compiler/rust/BUILD.bazel @@ -17,6 +17,7 @@ cc_library( ], deps = [ ":context", + ":enum", ":message", ":naming", ":relative_path", @@ -38,6 +39,7 @@ cc_library( deps = [ ":accessors", ":context", + ":enum", ":naming", ":oneof", "//src/google/protobuf:protobuf_nowkt", @@ -93,6 +95,34 @@ cc_library( ], ) +cc_library( + name = "enum", + srcs = ["enum.cc"], + hdrs = ["enum.h"], + copts = COPTS, + strip_include_prefix = "/src", + deps = [ + ":context", + "//src/google/protobuf:protobuf_nowkt", + "//src/google/protobuf/compiler/cpp:names_internal", + "@com_google_absl//absl/container:flat_hash_map", + "@com_google_absl//absl/container:flat_hash_set", + "@com_google_absl//absl/log:absl_check", + "@com_google_absl//absl/strings", + ], +) + +cc_test( + name = "enum_test", + srcs = ["enum_test.cc"], + deps = [ + ":enum", + "@com_google_absl//absl/strings", + "@com_google_googletest//:gtest", + "@com_google_googletest//:gtest_main", + ], +) + cc_library( name = "naming", srcs = ["naming.cc"], diff --git a/src/google/protobuf/compiler/rust/enum.cc b/src/google/protobuf/compiler/rust/enum.cc new file mode 100644 index 0000000000000..4871a34f46bf0 --- /dev/null +++ b/src/google/protobuf/compiler/rust/enum.cc @@ -0,0 +1,365 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2023 Google LLC. All rights reserved. +// +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file or at +// https://developers.google.com/open-source/licenses/bsd + +#include "google/protobuf/compiler/rust/enum.h" + +#include +#include +#include +#include +#include +#include + +#include "absl/container/flat_hash_map.h" +#include "absl/container/flat_hash_set.h" +#include "absl/log/absl_check.h" +#include "absl/strings/ascii.h" +#include "absl/strings/match.h" +#include "absl/strings/str_cat.h" +#include "absl/strings/str_join.h" +#include "absl/strings/string_view.h" +#include "absl/strings/strip.h" +#include "absl/types/span.h" +#include "google/protobuf/compiler/cpp/helpers.h" +#include "google/protobuf/compiler/rust/context.h" +#include "google/protobuf/descriptor.h" + +namespace google { +namespace protobuf { +namespace compiler { +namespace rust { + +namespace { + +std::string enumName(const EnumDescriptor& desc) { + return cpp::UnderscoresToCamelCase(desc.name(), /*cap first letter=*/true); +} + +// Constructs input for `EnumValues` from an enum descriptor. +std::vector> enumValuesInput( + const EnumDescriptor& desc) { + std::vector> result; + result.reserve(static_cast(desc.value_count())); + + for (int i = 0; i < desc.value_count(); ++i) { + result.emplace_back(desc.value(i)->name(), desc.value(i)->number()); + } + + return result; +} + +} // namespace + +std::vector EnumValues( + absl::string_view enum_name, + absl::Span> values) { + // Enum values may have a prefix of the name of the enum stripped from the + // value names in the gencode. This prefix is flexible: + // - It can be the original enum name, the name as UpperCamel, or snake_case. + // - The stripped prefix may also end in an underscore. + + // The set of prefixes that will be stripped. + std::initializer_list prefixes = { + std::string(enum_name), + ScreamingSnakeToUpperCamelCase(enum_name), + CamelToSnakeCase(enum_name), + }; + + absl::flat_hash_set seen_by_name; + absl::flat_hash_map seen_by_number; + std::vector result; + // The below code depends on pointer stability of elements in `result`; + // this reserve must not be too low. + result.reserve(values.size()); + seen_by_name.reserve(values.size()); + seen_by_number.reserve(values.size()); + + for (const auto& name_and_number : values) { + absl::string_view base_value_name = name_and_number.first; + for (absl::string_view prefix : prefixes) { + if (absl::StartsWithIgnoreCase(base_value_name, prefix)) { + base_value_name.remove_prefix(prefix.size()); + + // Also strip a joining underscore, if present. + absl::ConsumePrefix(&base_value_name, "_"); + + // Only strip one prefix. + break; + } + } + + if (base_value_name.empty()) { + // The enum value name has a similar name to the enum - don't strip. + base_value_name = name_and_number.first; + } + + int32_t number = name_and_number.second; + std::string rust_value_name = + ScreamingSnakeToUpperCamelCase(base_value_name); + + // Invalid identifiers are prefixed with `_`. + if (absl::ascii_isdigit(rust_value_name[0])) { + rust_value_name = absl::StrCat("_", rust_value_name); + } + + if (seen_by_name.contains(rust_value_name)) { + // Don't add an alias with the same normalized name. + continue; + } + + auto it_and_inserted = seen_by_number.try_emplace(number); + if (it_and_inserted.second) { + // This is the first value with this number; this name is canonical. + result.push_back(RustEnumValue{rust_value_name, number}); + it_and_inserted.first->second = &result.back(); + } else { + // This number has been seen before; this name is an alias. + it_and_inserted.first->second->aliases.push_back(rust_value_name); + } + + seen_by_name.insert(std::move(rust_value_name)); + } + return result; +} + +std::string CamelToSnakeCase(absl::string_view input) { + std::string result; + result.reserve(input.size() + 4); // No reallocation for 4 _ + bool is_first_character = true; + bool last_char_was_underscore = false; + for (const char c : input) { + if (!is_first_character && absl::ascii_isupper(c) && + !last_char_was_underscore) { + result += '_'; + } + last_char_was_underscore = c == '_'; + result += absl::ascii_tolower(c); + is_first_character = false; + } + return result; +} + +std::string ScreamingSnakeToUpperCamelCase(absl::string_view input) { + std::string result; + bool cap_next_letter = true; + for (const char c : input) { + if (absl::ascii_isalpha(c)) { + if (cap_next_letter) { + result += absl::ascii_toupper(c); + } else { + result += absl::ascii_tolower(c); + } + cap_next_letter = false; + } else if (absl::ascii_isdigit(c)) { + result += c; + cap_next_letter = true; + } else { + cap_next_letter = true; + } + } + return result; +} + +void GenerateEnumDefinition(Context& ctx, const EnumDescriptor& desc) { + std::string name = enumName(desc); + ABSL_CHECK(desc.value_count() > 0); + std::vector values = + EnumValues(desc.name(), enumValuesInput(desc)); + ABSL_CHECK(!values.empty()); + + ctx.Emit( + { + {"name", name}, + {"variants", + [&] { + for (const auto& value : values) { + std::string number_str = absl::StrCat(value.number); + // TODO: Replace with open enum variants when stable + ctx.Emit({{"variant_name", value.name}, {"number", number_str}}, + R"rs( + pub const $variant_name$: $name$ = $name$($number$); + )rs"); + for (const auto& alias : value.aliases) { + ctx.Emit({{"alias_name", alias}, {"number", number_str}}, + R"rs( + pub const $alias_name$: $name$ = $name$($number$); + )rs"); + } + } + }}, + // The default value of an enum is the first listed value. + // The compiler checks that this is equal to 0 for open enums. + {"default_int_value", absl::StrCat(desc.value(0)->number())}, + {"impl_from_i32", + [&] { + if (desc.is_closed()) { + ctx.Emit({{"name", name}, + {"known_values_pattern", + // TODO: Check validity in UPB/C++. + absl::StrJoin( + values, "|", + [](std::string* o, const RustEnumValue& val) { + absl::StrAppend(o, val.number); + })}}, + R"rs( + impl $std$::convert::TryFrom for $name$ { + type Error = $pb$::UnknownEnumValue; + + fn try_from(val: i32) -> Result<$name$, Self::Error> { + if matches!(val, $known_values_pattern$) { + Ok(Self(val)) + } else { + Err($pb$::UnknownEnumValue::new($pbi$::Private, val)) + } + } + } + )rs"); + } else { + ctx.Emit({{"name", name}}, R"rs( + impl $std$::convert::From for $name$ { + fn from(val: i32) -> $name$ { + Self(val) + } + } + )rs"); + } + }}, + }, + R"rs( + #[repr(transparent)] + #[derive(Clone, Copy, PartialEq, Eq)] + pub struct $name$(i32); + + #[allow(non_upper_case_globals)] + impl $name$ { + $variants$ + } + + impl $std$::convert::From<$name$> for i32 { + fn from(val: $name$) -> i32 { + val.0 + } + } + + $impl_from_i32$ + + impl $std$::default::Default for $name$ { + fn default() -> Self { + Self($default_int_value$) + } + } + + impl $std$::fmt::Debug for $name$ { + fn fmt(&self, f: &mut $std$::fmt::Formatter<'_>) -> $std$::fmt::Result { + f.debug_tuple(stringify!($name$)).field(&self.0).finish() + } + } + + impl $pb$::Proxied for $name$ { + type View<'a> = $name$; + type Mut<'a> = $pb$::PrimitiveMut<'a, $name$>; + } + + impl $pb$::ViewProxy<'_> for $name$ { + type Proxied = $name$; + + fn as_view(&self) -> $name$ { + *self + } + + fn into_view<'shorter>(self) -> $pb$::View<'shorter, $name$> { + self + } + } + + impl $pb$::SettableValue<$name$> for $name$ { + fn set_on<'msg>( + self, + private: $pbi$::Private, + mut mutator: $pb$::Mut<'msg, $name$> + ) where $name$: 'msg { + mutator.set_primitive(private, self) + } + } + + impl $pb$::ProxiedWithPresence for $name$ { + type PresentMutData<'a> = $pbi$::RawVTableOptionalMutatorData<'a, $name$>; + type AbsentMutData<'a> = $pbi$::RawVTableOptionalMutatorData<'a, $name$>; + + fn clear_present_field( + present_mutator: Self::PresentMutData<'_>, + ) -> Self::AbsentMutData<'_> { + present_mutator.clear($pbi$::Private) + } + + fn set_absent_to_default( + absent_mutator: Self::AbsentMutData<'_>, + ) -> Self::PresentMutData<'_> { + absent_mutator.set_absent_to_default($pbi$::Private) + } + } + + unsafe impl $pb$::ProxiedInRepeated for $name$ { + fn repeated_len(r: $pb$::View<$pb$::Repeated>) -> usize { + $pbr$::cast_enum_repeated_view($pbi$::Private, r).len() + } + + fn repeated_push(r: $pb$::Mut<$pb$::Repeated>, val: $name$) { + $pbr$::cast_enum_repeated_mut($pbi$::Private, r).push(val.into()) + } + + fn repeated_clear(r: $pb$::Mut<$pb$::Repeated>) { + $pbr$::cast_enum_repeated_mut($pbi$::Private, r).clear() + } + + unsafe fn repeated_get_unchecked( + r: $pb$::View<$pb$::Repeated>, + index: usize, + ) -> $pb$::View<$name$> { + // SAFETY: In-bounds as promised by the caller. + unsafe { + $pbr$::cast_enum_repeated_view($pbi$::Private, r) + .get_unchecked(index) + .try_into() + .unwrap_unchecked() + } + } + + unsafe fn repeated_set_unchecked( + r: $pb$::Mut<$pb$::Repeated>, + index: usize, + val: $name$, + ) { + // SAFETY: In-bounds as promised by the caller. + unsafe { + $pbr$::cast_enum_repeated_mut($pbi$::Private, r) + .set_unchecked(index, val.into()) + } + } + + fn repeated_copy_from( + src: $pb$::View<$pb$::Repeated>, + dest: $pb$::Mut<$pb$::Repeated>, + ) { + $pbr$::cast_enum_repeated_mut($pbi$::Private, dest) + .copy_from($pbr$::cast_enum_repeated_view($pbi$::Private, src)) + } + } + + impl $pbi$::PrimitiveWithRawVTable for $name$ {} + + // SAFETY: this is an enum type + unsafe impl $pbi$::Enum for $name$ { + const NAME: &'static str = "$name$"; + } + )rs"); +} + +} // namespace rust +} // namespace compiler +} // namespace protobuf +} // namespace google diff --git a/src/google/protobuf/compiler/rust/enum.h b/src/google/protobuf/compiler/rust/enum.h new file mode 100644 index 0000000000000..0ef2d689f7ff4 --- /dev/null +++ b/src/google/protobuf/compiler/rust/enum.h @@ -0,0 +1,56 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2023 Google LLC. All rights reserved. +// +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file or at +// https://developers.google.com/open-source/licenses/bsd + +#ifndef GOOGLE_PROTOBUF_COMPILER_RUST_ENUM_H__ +#define GOOGLE_PROTOBUF_COMPILER_RUST_ENUM_H__ + +#include +#include +#include +#include + +#include "absl/strings/string_view.h" +#include "absl/types/span.h" +#include "google/protobuf/compiler/rust/context.h" +#include "google/protobuf/descriptor.h" + +namespace google { +namespace protobuf { +namespace compiler { +namespace rust { + +void GenerateEnumDefinition(Context& ctx, const EnumDescriptor& desc); + +// An enum value with a unique number and any aliases for it. +struct RustEnumValue { + // The canonical CamelCase name in Rust. + std::string name; + int32_t number; + std::vector aliases; +}; + +// Returns the list of rust enum variants to produce, along with their aliases. +// Performs name normalization, deduplication, and alias determination. +// The `number` and `name` of every returned `RustEnumValue` is unique. +std::vector EnumValues( + absl::string_view enum_name, + absl::Span> values); + +// TODO: Unify these with other case-conversion functions. + +// Converts an UpperCamel or lowerCamel string to a snake_case string. +std::string CamelToSnakeCase(absl::string_view input); + +// Converts a SCREAMING_SNAKE_CASE string to an UpperCamelCase string. +std::string ScreamingSnakeToUpperCamelCase(absl::string_view input); + +} // namespace rust +} // namespace compiler +} // namespace protobuf +} // namespace google + +#endif // GOOGLE_PROTOBUF_COMPILER_RUST_ENUM_H__ diff --git a/src/google/protobuf/compiler/rust/enum_test.cc b/src/google/protobuf/compiler/rust/enum_test.cc new file mode 100644 index 0000000000000..e481c1854d013 --- /dev/null +++ b/src/google/protobuf/compiler/rust/enum_test.cc @@ -0,0 +1,84 @@ +#include "google/protobuf/compiler/rust/enum.h" + +#include + +#include +#include +#include "absl/strings/string_view.h" + +namespace { + +using ::google::protobuf::compiler::rust::CamelToSnakeCase; +using ::google::protobuf::compiler::rust::EnumValues; +using ::google::protobuf::compiler::rust::RustEnumValue; +using ::google::protobuf::compiler::rust::ScreamingSnakeToUpperCamelCase; +using ::testing::AllOf; +using ::testing::ElementsAre; +using ::testing::Eq; +using ::testing::Field; +using ::testing::IsEmpty; + +TEST(EnumTest, CamelToSnakeCase) { + // TODO: Review this behavior. + EXPECT_EQ(CamelToSnakeCase("CamelCase"), "camel_case"); + EXPECT_EQ(CamelToSnakeCase("_CamelCase"), "_camel_case"); + EXPECT_EQ(CamelToSnakeCase("camelCase"), "camel_case"); + EXPECT_EQ(CamelToSnakeCase("Number2020"), "number2020"); + EXPECT_EQ(CamelToSnakeCase("Number_2020"), "number_2020"); + EXPECT_EQ(CamelToSnakeCase("camelCase_"), "camel_case_"); + EXPECT_EQ(CamelToSnakeCase("CamelCaseTrio"), "camel_case_trio"); + EXPECT_EQ(CamelToSnakeCase("UnderIn_Middle"), "under_in_middle"); + EXPECT_EQ(CamelToSnakeCase("Camel_Case"), "camel_case"); + EXPECT_EQ(CamelToSnakeCase("Camel__Case"), "camel__case"); + EXPECT_EQ(CamelToSnakeCase("CAMEL_CASE"), "c_a_m_e_l_c_a_s_e"); +} + +TEST(EnumTest, ScreamingSnakeToUpperCamelCase) { + // TODO: Review this behavior. + EXPECT_EQ(ScreamingSnakeToUpperCamelCase("CAMEL_CASE"), "CamelCase"); + EXPECT_EQ(ScreamingSnakeToUpperCamelCase("NUMBER2020"), "Number2020"); + EXPECT_EQ(ScreamingSnakeToUpperCamelCase("NUMBER_2020"), "Number2020"); + EXPECT_EQ(ScreamingSnakeToUpperCamelCase("FOO_4040_BAR"), "Foo4040Bar"); + EXPECT_EQ(ScreamingSnakeToUpperCamelCase("FOO_4040bar"), "Foo4040Bar"); + EXPECT_EQ(ScreamingSnakeToUpperCamelCase("_CAMEL_CASE"), "CamelCase"); + + // This function doesn't currently preserve prefix/suffix underscore, + // while CamelToSnakeCase does. + EXPECT_EQ(ScreamingSnakeToUpperCamelCase("CAMEL_CASE_"), "CamelCase"); + EXPECT_EQ(ScreamingSnakeToUpperCamelCase("camel_case"), "CamelCase"); + EXPECT_EQ(ScreamingSnakeToUpperCamelCase("CAMEL_CASE_TRIO"), "CamelCaseTrio"); + EXPECT_EQ(ScreamingSnakeToUpperCamelCase("UNDER_IN__MIDDLE"), + "UnderInMiddle"); +} + +template +auto EnumValue(absl::string_view name, int32_t number, Aliases aliases) { + return AllOf(Field("name", &RustEnumValue::name, Eq(name)), + Field("number", &RustEnumValue::number, Eq(number)), + Field("aliases", &RustEnumValue::aliases, aliases)); +} + +auto EnumValue(absl::string_view name, int32_t number) { + return EnumValue(name, number, IsEmpty()); +} + +TEST(EnumTest, EnumValues) { + EXPECT_THAT(EnumValues("Enum", {{"ENUM_FOO", 1}, {"ENUM_BAR", 2}}), + ElementsAre(EnumValue("Foo", 1), EnumValue("Bar", 2))); + EXPECT_THAT(EnumValues("Enum", {{"FOO", 1}, {"ENUM_BAR", 2}}), + ElementsAre(EnumValue("Foo", 1), EnumValue("Bar", 2))); + EXPECT_THAT(EnumValues("Enum", {{"enumFOO", 1}, {"eNuM_BaR", 2}}), + ElementsAre(EnumValue("Foo", 1), EnumValue("Bar", 2))); + EXPECT_THAT(EnumValues("Enum", {{"ENUM_ENUM_UNKNOWN", 1}, {"ENUM_ENUM", 2}}), + ElementsAre(EnumValue("EnumUnknown", 1), EnumValue("Enum", 2))); + EXPECT_THAT(EnumValues("Enum", {{"ENUM_VAL", 1}, {"ENUM_ALIAS", 1}}), + ElementsAre(EnumValue("Val", 1, ElementsAre("Alias")))); + EXPECT_THAT( + EnumValues("Enum", + {{"ENUM_VAL", 1}, {"ENUM_ALIAS", 1}, {"ENUM_ALIAS2", 1}}), + ElementsAre(EnumValue("Val", 1, ElementsAre("Alias", "Alias2")))); + EXPECT_THAT(EnumValues("Enum", {{"ENUM_ENUM", 1}, {"ENUM", 1}}), + ElementsAre(EnumValue("Enum", 1, IsEmpty()))); +} + +} // namespace diff --git a/src/google/protobuf/compiler/rust/generator.cc b/src/google/protobuf/compiler/rust/generator.cc index 04d5ff6f32105..bc23a120216ea 100644 --- a/src/google/protobuf/compiler/rust/generator.cc +++ b/src/google/protobuf/compiler/rust/generator.cc @@ -23,6 +23,7 @@ #include "google/protobuf/compiler/code_generator.h" #include "google/protobuf/compiler/cpp/names.h" #include "google/protobuf/compiler/rust/context.h" +#include "google/protobuf/compiler/rust/enum.h" #include "google/protobuf/compiler/rust/message.h" #include "google/protobuf/compiler/rust/naming.h" #include "google/protobuf/compiler/rust/relative_path.h" @@ -281,6 +282,12 @@ bool RustGenerator::Generate(const FileDescriptor* file, thunks_ctx.printer().PrintRaw("\n"); } } + + for (int i = 0; i < file->enum_type_count(); ++i) { + GenerateEnumDefinition(ctx, *file->enum_type(i)); + ctx.printer().PrintRaw("\n"); + } + if (file == files_in_current_crate.front()) { EmitClosingOfPackageModules(ctx, file->package()); } diff --git a/src/google/protobuf/compiler/rust/message.cc b/src/google/protobuf/compiler/rust/message.cc index 02f85d0ab6458..21151e3cc7790 100644 --- a/src/google/protobuf/compiler/rust/message.cc +++ b/src/google/protobuf/compiler/rust/message.cc @@ -15,6 +15,7 @@ #include "google/protobuf/compiler/cpp/names.h" #include "google/protobuf/compiler/rust/accessors/accessors.h" #include "google/protobuf/compiler/rust/context.h" +#include "google/protobuf/compiler/rust/enum.h" #include "google/protobuf/compiler/rust/naming.h" #include "google/protobuf/compiler/rust/oneof.h" #include "google/protobuf/descriptor.h" @@ -341,7 +342,7 @@ void GenerateRs(Context& ctx, const Descriptor& msg) { ctx.printer().PrintRaw("\n"); } }}, - {"nested_msgs", + {"nested_in_msg", [&] { // If we have no nested types or oneofs, bail out without // emitting an empty mod SomeMsg_. @@ -357,6 +358,12 @@ void GenerateRs(Context& ctx, const Descriptor& msg) { GenerateRs(ctx, *msg.nested_type(i)); } }}, + {"nested_enums", + [&] { + for (int i = 0; i < msg.enum_type_count(); ++i) { + GenerateEnumDefinition(ctx, *msg.enum_type(i)); + } + }}, {"oneofs", [&] { for (int i = 0; i < msg.real_oneof_decl_count(); ++i) { @@ -367,6 +374,7 @@ void GenerateRs(Context& ctx, const Descriptor& msg) { #[allow(non_snake_case)] pub mod $Msg$_ { $nested_msgs$ + $nested_enums$ $oneofs$ } // mod $Msg$_ @@ -516,7 +524,7 @@ void GenerateRs(Context& ctx, const Descriptor& msg) { $oneof_externs$ } // extern "C" for $Msg$ - $nested_msgs$ + $nested_in_msg$ )rs"); if (ctx.is_cpp()) { From 1ff12eff6a2c442e131f4c898cc1eaee18affbb3 Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Wed, 20 Dec 2023 18:20:44 +0000 Subject: [PATCH 075/255] Auto-generate files after cl/592591476 --- src/file_lists.cmake | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/file_lists.cmake b/src/file_lists.cmake index 460600efead72..2abb20ffc6897 100644 --- a/src/file_lists.cmake +++ b/src/file_lists.cmake @@ -390,6 +390,7 @@ set(libprotoc_srcs ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/rust/accessors/singular_string.cc ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/rust/accessors/unsupported_field.cc ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/rust/context.cc + ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/rust/enum.cc ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/rust/generator.cc ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/rust/message.cc ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/rust/naming.cc @@ -503,6 +504,7 @@ set(libprotoc_hdrs ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/rust/accessors/accessors.h ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/rust/accessors/helpers.h ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/rust/context.h + ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/rust/enum.h ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/rust/generator.h ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/rust/message.h ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/rust/naming.h From 40ad3fac603ba3c96e52a1266cd785a7adb8e3e4 Mon Sep 17 00:00:00 2001 From: Adam Cozzette Date: Wed, 20 Dec 2023 15:49:21 -0800 Subject: [PATCH 076/255] Breaking change: remove support for PHP generic services Generic services have been deprecated for about 14 years. This is technically a breaking change, but fortunately the `php_generic_services` option appears to have little or no usage. I could not find any examples of open source code using it. PiperOrigin-RevId: 592677762 --- php/tests/GeneratedServiceTest.php | 127 ------ php/tests/proto/test_service.proto | 18 - php/tests/proto/test_service_namespace.proto | 13 - .../protobuf/compiler/php/php_generator.cc | 110 ----- src/google/protobuf/descriptor.pb.cc | 404 ++++++++---------- src/google/protobuf/descriptor.pb.h | 61 +-- src/google/protobuf/descriptor.proto | 2 +- .../stage0/google/protobuf/descriptor.upb.c | 2 +- .../stage0/google/protobuf/descriptor.upb.h | 21 +- 9 files changed, 203 insertions(+), 555 deletions(-) delete mode 100644 php/tests/GeneratedServiceTest.php delete mode 100644 php/tests/proto/test_service.proto delete mode 100644 php/tests/proto/test_service_namespace.proto diff --git a/php/tests/GeneratedServiceTest.php b/php/tests/GeneratedServiceTest.php deleted file mode 100644 index be9234c1ab0d2..0000000000000 --- a/php/tests/GeneratedServiceTest.php +++ /dev/null @@ -1,127 +0,0 @@ -serviceClass = new ReflectionClass('Foo\GreeterInterface'); - - $this->namespacedServiceClass = new ReflectionClass('Bar\OtherGreeterInterface'); - } - - public function testIsInterface() - { - $this->assertTrue($this->serviceClass->isInterface()); - } - - public function testPhpDocForClass() - { - $this->assertStringContains( - 'foo.Greeter', $this->serviceClass->getDocComment()); - } - - public function testPhpDocForNamespacedClass() - { - $this->assertStringContains( - 'foo.OtherGreeter', $this->namespacedServiceClass->getDocComment()); - } - - public function testServiceMethodsAreGenerated() - { - $this->assertCount( - count($this->methodNames), $this->serviceClass->getMethods()); - foreach ($this->methodNames as $methodName) { - $this->assertTrue($this->serviceClass->hasMethod($methodName)); - } - } - - public function testPhpDocForServiceMethod() - { - foreach ($this->methodNames as $methodName) { - $docComment = - $this->serviceClass->getMethod($methodName)->getDocComment(); - $this->assertStringContains($methodName, $docComment); - $this->assertStringContains( - '@param \Foo\HelloRequest $request', $docComment); - $this->assertStringContains( - '@return \Foo\HelloReply', $docComment); - } - } - - public function testPhpDocForServiceMethodInNamespacedClass() - { - foreach ($this->methodNames as $methodName) { - $docComment = - $this->namespacedServiceClass->getMethod( - $methodName)->getDocComment(); - $this->assertStringContains($methodName, $docComment); - $this->assertStringContains( - '@param \Foo\HelloRequest $request', $docComment); - $this->assertStringContains( - '@return \Foo\HelloReply', $docComment); - } - } - - public function testParamForServiceMethod() - { - foreach ($this->methodNames as $methodName) { - $method = $this->serviceClass->getMethod($methodName); - $this->assertCount(1, $method->getParameters()); - $param = $method->getParameters()[0]; - $this->assertFalse($param->isOptional()); - $this->assertSame('request', $param->getName()); - // ReflectionParameter::getType only exists in PHP 7+, so get the - // type from __toString - $this->assertStringContains( - 'Foo\HelloRequest $request', (string) $param); - } - } - - public function testParamForServiceMethodInNamespacedClass() - { - foreach ($this->methodNames as $methodName) { - $method = $this->serviceClass->getMethod($methodName); - $this->assertCount(1, $method->getParameters()); - $param = $method->getParameters()[0]; - $this->assertFalse($param->isOptional()); - $this->assertSame('request', $param->getName()); - // ReflectionParameter::getType only exists in PHP 7+, so get the - // type from __toString - $this->assertStringContains( - 'Foo\HelloRequest $request', (string) $param); - } - } -} diff --git a/php/tests/proto/test_service.proto b/php/tests/proto/test_service.proto deleted file mode 100644 index a03dbc46d7c7e..0000000000000 --- a/php/tests/proto/test_service.proto +++ /dev/null @@ -1,18 +0,0 @@ -syntax = "proto3"; - -package foo; - -option php_generic_services = true; - -service Greeter { - rpc SayHello (HelloRequest) returns (HelloReply) {} - rpc SayHelloAgain (HelloRequest) returns (HelloReply) {} -} - -message HelloRequest { - string name = 1; -} - -message HelloReply { - string message = 1; -} diff --git a/php/tests/proto/test_service_namespace.proto b/php/tests/proto/test_service_namespace.proto deleted file mode 100644 index 719aa484efa14..0000000000000 --- a/php/tests/proto/test_service_namespace.proto +++ /dev/null @@ -1,13 +0,0 @@ -syntax = "proto3"; - -import "proto/test_service.proto"; - -package foo; - -option php_generic_services = true; -option php_namespace = "Bar"; - -service OtherGreeter { - rpc SayHello (HelloRequest) returns (HelloReply) {} - rpc SayHelloAgain (HelloRequest) returns (HelloReply) {} -} diff --git a/src/google/protobuf/compiler/php/php_generator.cc b/src/google/protobuf/compiler/php/php_generator.cc index 62498abc6f1dd..0ef09ecb23267 100644 --- a/src/google/protobuf/compiler/php/php_generator.cc +++ b/src/google/protobuf/compiler/php/php_generator.cc @@ -87,10 +87,6 @@ void GenerateEnumDocComment(io::Printer* printer, const EnumDescriptor* enum_, const Options& options); void GenerateEnumValueDocComment(io::Printer* printer, const EnumValueDescriptor* value); -void GenerateServiceDocComment(io::Printer* printer, - const ServiceDescriptor* service); -void GenerateServiceMethodDocComment(io::Printer* printer, - const MethodDescriptor* method); template std::string DescriptorFullName(const DescriptorType* desc, bool is_internal) { @@ -345,17 +341,6 @@ std::string LegacyReadOnlyGeneratedClassFileName(std::string php_namespace, return absl::StrCat(desc->name(), ".php"); } -std::string GeneratedServiceFileName(const ServiceDescriptor* service, - const Options& options) { - std::string result = FullClassName(service, options); - for (int i = 0; i < result.size(); i++) { - if (result[i] == '\\') { - result[i] = '/'; - } - } - return absl::StrCat(result, "Interface", ".php"); -} - std::string IntToString(int32_t value) { std::ostringstream os; os << value; @@ -796,16 +781,6 @@ void GenerateEnumToPool(const EnumDescriptor* en, io::Printer* printer) { Outdent(printer); } -void GenerateServiceMethod(const MethodDescriptor* method, - io::Printer* printer) { - printer->Print( - "public function ^camel_name^(\\^request_name^ $request);\n\n", - "camel_name", UnderscoresToCamelCase(method->name(), false), - "request_name", FullClassName( - method->input_type(), false) - ); -} - void GenerateMessageToPool(absl::string_view name_prefix, const Descriptor* message, io::Printer* printer) { // Don't generate MapEntry messages -- we use the PHP extension's native @@ -1573,53 +1548,6 @@ bool GenerateMessageFile(const FileDescriptor* file, const Descriptor* message, return true; } -void GenerateServiceFile( - const FileDescriptor* file, const ServiceDescriptor* service, - const Options& options, GeneratorContext* generator_context) { - std::string filename = GeneratedServiceFileName(service, options); - std::unique_ptr output( - generator_context->Open(filename)); - io::Printer printer(output.get(), '^'); - - GenerateHead(file, &printer); - - std::string fullname = FilenameToClassname(filename); - int lastindex = fullname.find_last_of('\\'); - - if (!file->options().php_namespace().empty() || - (!file->options().has_php_namespace() && !file->package().empty()) || - lastindex != std::string::npos) { - printer.Print( - "namespace ^name^;\n\n", - "name", fullname.substr(0, lastindex)); - } - - GenerateServiceDocComment(&printer, service); - - if (lastindex != std::string::npos) { - printer.Print( - "interface ^name^\n" - "{\n", - "name", fullname.substr(lastindex + 1)); - } else { - printer.Print( - "interface ^name^\n" - "{\n", - "name", fullname); - } - - Indent(&printer); - - for (int i = 0; i < service->method_count(); i++) { - const MethodDescriptor* method = service->method(i); - GenerateServiceMethodDocComment(&printer, method); - GenerateServiceMethod(method, &printer); - } - - Outdent(&printer); - printer.Print("}\n\n"); -} - bool GenerateFile(const FileDescriptor* file, const Options& options, GeneratorContext* generator_context, std::string* error) { GenerateMetadataFile(file, options, generator_context); @@ -1636,11 +1564,6 @@ bool GenerateFile(const FileDescriptor* file, const Options& options, return false; } } - if (file->options().php_generic_services()) { - for (int i = 0; i < file->service_count(); i++) { - GenerateServiceFile(file, file->service(i), options, generator_context); - } - } return true; } @@ -1791,19 +1714,6 @@ void GenerateMessageConstructorDocComment(io::Printer* printer, printer->Print(" */\n"); } -void GenerateServiceDocComment(io::Printer* printer, - const ServiceDescriptor* service) { - printer->Print("/**\n"); - if (service->options().deprecated()) { - printer->Print(" * @deprecated\n"); - } - GenerateDocCommentBody(printer, service); - printer->Print( - " * Protobuf type ^fullname^\n" - " */\n", - "fullname", EscapePhpdoc(service->full_name())); -} - void GenerateFieldDocComment(io::Printer* printer, const FieldDescriptor* field, const Options& options, int function_type) { // In theory we should have slightly different comments for setters, getters, @@ -1894,26 +1804,6 @@ void GenerateEnumValueDocComment(io::Printer* printer, "def", EscapePhpdoc(FirstLineOf(value->DebugString()))); } -void GenerateServiceMethodDocComment(io::Printer* printer, - const MethodDescriptor* method) { - printer->Print("/**\n"); - GenerateDocCommentBody(printer, method); - if (method->options().deprecated()) { - printer->Print(" * @deprecated\n"); - } - printer->Print( - " * Method ^method_name^\n" - " *\n", - "method_name", EscapePhpdoc(UnderscoresToCamelCase(method->name(), false))); - printer->Print( - " * @param \\^input_type^ $request\n", - "input_type", EscapePhpdoc(FullClassName(method->input_type(), false))); - printer->Print( - " * @return \\^return_type^\n" - " */\n", - "return_type", EscapePhpdoc(FullClassName(method->output_type(), false))); -} - std::string FilenameCName(const FileDescriptor* file) { return absl::StrReplaceAll(file->name(), {{".", "_"}, {"/", "_"}}); } diff --git a/src/google/protobuf/descriptor.pb.cc b/src/google/protobuf/descriptor.pb.cc index 951acb9338524..4d80cf16612c9 100644 --- a/src/google/protobuf/descriptor.pb.cc +++ b/src/google/protobuf/descriptor.pb.cc @@ -512,7 +512,6 @@ inline constexpr FileOptions::Impl_::Impl_( cc_generic_services_{false}, java_generic_services_{false}, py_generic_services_{false}, - php_generic_services_{false}, deprecated_{false}, optimize_for_{static_cast< ::google::protobuf::FileOptions_OptimizeMode >(1)}, cc_enable_arenas_{true} {} @@ -1276,7 +1275,6 @@ const ::uint32_t PROTOBUF_FIELD_OFFSET(::google::protobuf::FileOptions, _impl_.cc_generic_services_), PROTOBUF_FIELD_OFFSET(::google::protobuf::FileOptions, _impl_.java_generic_services_), PROTOBUF_FIELD_OFFSET(::google::protobuf::FileOptions, _impl_.py_generic_services_), - PROTOBUF_FIELD_OFFSET(::google::protobuf::FileOptions, _impl_.php_generic_services_), PROTOBUF_FIELD_OFFSET(::google::protobuf::FileOptions, _impl_.deprecated_), PROTOBUF_FIELD_OFFSET(::google::protobuf::FileOptions, _impl_.cc_enable_arenas_), PROTOBUF_FIELD_OFFSET(::google::protobuf::FileOptions, _impl_.objc_class_prefix_), @@ -1293,14 +1291,13 @@ const ::uint32_t 11, 12, 13, - 19, + 18, 2, 14, 15, 16, 17, - 18, - 20, + 19, 3, 4, 5, @@ -1606,24 +1603,24 @@ static const ::_pbi::MigrationSchema {203, 214, -1, sizeof(::google::protobuf::EnumValueDescriptorProto)}, {217, 228, -1, sizeof(::google::protobuf::ServiceDescriptorProto)}, {231, 245, -1, sizeof(::google::protobuf::MethodDescriptorProto)}, - {251, 281, -1, sizeof(::google::protobuf::FileOptions)}, - {303, 318, -1, sizeof(::google::protobuf::MessageOptions)}, - {325, 335, -1, sizeof(::google::protobuf::FieldOptions_EditionDefault)}, - {337, 358, -1, sizeof(::google::protobuf::FieldOptions)}, - {371, 381, -1, sizeof(::google::protobuf::OneofOptions)}, - {383, 396, -1, sizeof(::google::protobuf::EnumOptions)}, - {401, 413, -1, sizeof(::google::protobuf::EnumValueOptions)}, - {417, 428, -1, sizeof(::google::protobuf::ServiceOptions)}, - {431, 443, -1, sizeof(::google::protobuf::MethodOptions)}, - {447, 457, -1, sizeof(::google::protobuf::UninterpretedOption_NamePart)}, - {459, 474, -1, sizeof(::google::protobuf::UninterpretedOption)}, - {481, 495, -1, sizeof(::google::protobuf::FeatureSet)}, - {501, 511, -1, sizeof(::google::protobuf::FeatureSetDefaults_FeatureSetEditionDefault)}, - {513, 524, -1, sizeof(::google::protobuf::FeatureSetDefaults)}, - {527, 540, -1, sizeof(::google::protobuf::SourceCodeInfo_Location)}, - {545, -1, -1, sizeof(::google::protobuf::SourceCodeInfo)}, - {554, 567, -1, sizeof(::google::protobuf::GeneratedCodeInfo_Annotation)}, - {572, -1, -1, sizeof(::google::protobuf::GeneratedCodeInfo)}, + {251, 280, -1, sizeof(::google::protobuf::FileOptions)}, + {301, 316, -1, sizeof(::google::protobuf::MessageOptions)}, + {323, 333, -1, sizeof(::google::protobuf::FieldOptions_EditionDefault)}, + {335, 356, -1, sizeof(::google::protobuf::FieldOptions)}, + {369, 379, -1, sizeof(::google::protobuf::OneofOptions)}, + {381, 394, -1, sizeof(::google::protobuf::EnumOptions)}, + {399, 411, -1, sizeof(::google::protobuf::EnumValueOptions)}, + {415, 426, -1, sizeof(::google::protobuf::ServiceOptions)}, + {429, 441, -1, sizeof(::google::protobuf::MethodOptions)}, + {445, 455, -1, sizeof(::google::protobuf::UninterpretedOption_NamePart)}, + {457, 472, -1, sizeof(::google::protobuf::UninterpretedOption)}, + {479, 493, -1, sizeof(::google::protobuf::FeatureSet)}, + {499, 509, -1, sizeof(::google::protobuf::FeatureSetDefaults_FeatureSetEditionDefault)}, + {511, 522, -1, sizeof(::google::protobuf::FeatureSetDefaults)}, + {525, 538, -1, sizeof(::google::protobuf::SourceCodeInfo_Location)}, + {543, -1, -1, sizeof(::google::protobuf::SourceCodeInfo)}, + {552, 565, -1, sizeof(::google::protobuf::GeneratedCodeInfo_Annotation)}, + {570, -1, -1, sizeof(::google::protobuf::GeneratedCodeInfo)}, }; static const ::_pb::Message* const file_default_instances[] = { @@ -1746,7 +1743,7 @@ const char descriptor_table_protodef_google_2fprotobuf_2fdescriptor_2eproto[] AB "\001(\t\022\023\n\013output_type\030\003 \001(\t\022/\n\007options\030\004 \001(" "\0132\036.google.protobuf.MethodOptions\022\037\n\020cli" "ent_streaming\030\005 \001(\010:\005false\022\037\n\020server_str" - "eaming\030\006 \001(\010:\005false\"\324\006\n\013FileOptions\022\024\n\014j" + "eaming\030\006 \001(\010:\005false\"\265\006\n\013FileOptions\022\024\n\014j" "ava_package\030\001 \001(\t\022\034\n\024java_outer_classnam" "e\030\010 \001(\t\022\"\n\023java_multiple_files\030\n \001(\010:\005fa" "lse\022)\n\035java_generate_equals_and_hash\030\024 \001" @@ -1756,158 +1753,157 @@ const char descriptor_table_protodef_google_2fprotobuf_2fdescriptor_2eproto[] AB "\ngo_package\030\013 \001(\t\022\"\n\023cc_generic_services" "\030\020 \001(\010:\005false\022$\n\025java_generic_services\030\021" " \001(\010:\005false\022\"\n\023py_generic_services\030\022 \001(\010" - ":\005false\022#\n\024php_generic_services\030* \001(\010:\005f" - "alse\022\031\n\ndeprecated\030\027 \001(\010:\005false\022\036\n\020cc_en" - "able_arenas\030\037 \001(\010:\004true\022\031\n\021objc_class_pr" - "efix\030$ \001(\t\022\030\n\020csharp_namespace\030% \001(\t\022\024\n\014" - "swift_prefix\030\' \001(\t\022\030\n\020php_class_prefix\030(" - " \001(\t\022\025\n\rphp_namespace\030) \001(\t\022\036\n\026php_metad" - "ata_namespace\030, \001(\t\022\024\n\014ruby_package\030- \001(" - "\t\022-\n\010features\0302 \001(\0132\033.google.protobuf.Fe" - "atureSet\022C\n\024uninterpreted_option\030\347\007 \003(\0132" - "$.google.protobuf.UninterpretedOption\":\n" - "\014OptimizeMode\022\t\n\005SPEED\020\001\022\r\n\tCODE_SIZE\020\002\022" - "\020\n\014LITE_RUNTIME\020\003*\t\010\350\007\020\200\200\200\200\002J\004\010&\020\'\"\347\002\n\016M" - "essageOptions\022&\n\027message_set_wire_format" - "\030\001 \001(\010:\005false\022.\n\037no_standard_descriptor_" - "accessor\030\002 \001(\010:\005false\022\031\n\ndeprecated\030\003 \001(" - "\010:\005false\022\021\n\tmap_entry\030\007 \001(\010\0222\n&deprecate" - "d_legacy_json_field_conflicts\030\013 \001(\010B\002\030\001\022" - "-\n\010features\030\014 \001(\0132\033.google.protobuf.Feat" - "ureSet\022C\n\024uninterpreted_option\030\347\007 \003(\0132$." - "google.protobuf.UninterpretedOption*\t\010\350\007" - "\020\200\200\200\200\002J\004\010\004\020\005J\004\010\005\020\006J\004\010\006\020\007J\004\010\010\020\tJ\004\010\t\020\n\"\215\t\n" - "\014FieldOptions\022:\n\005ctype\030\001 \001(\0162#.google.pr" - "otobuf.FieldOptions.CType:\006STRING\022\016\n\006pac" - "ked\030\002 \001(\010\022\?\n\006jstype\030\006 \001(\0162$.google.proto" - "buf.FieldOptions.JSType:\tJS_NORMAL\022\023\n\004la" - "zy\030\005 \001(\010:\005false\022\036\n\017unverified_lazy\030\017 \001(\010" - ":\005false\022\031\n\ndeprecated\030\003 \001(\010:\005false\022\023\n\004we" - "ak\030\n \001(\010:\005false\022\033\n\014debug_redact\030\020 \001(\010:\005f" - "alse\022@\n\tretention\030\021 \001(\0162-.google.protobu" - "f.FieldOptions.OptionRetention\022\?\n\007target" - "s\030\023 \003(\0162..google.protobuf.FieldOptions.O" - "ptionTargetType\022F\n\020edition_defaults\030\024 \003(" - "\0132,.google.protobuf.FieldOptions.Edition" - "Default\022-\n\010features\030\025 \001(\0132\033.google.proto" - "buf.FeatureSet\022C\n\024uninterpreted_option\030\347" - "\007 \003(\0132$.google.protobuf.UninterpretedOpt" - "ion\032J\n\016EditionDefault\022)\n\007edition\030\003 \001(\0162\030" - ".google.protobuf.Edition\022\r\n\005value\030\002 \001(\t\"" - "/\n\005CType\022\n\n\006STRING\020\000\022\010\n\004CORD\020\001\022\020\n\014STRING" - "_PIECE\020\002\"5\n\006JSType\022\r\n\tJS_NORMAL\020\000\022\r\n\tJS_" - "STRING\020\001\022\r\n\tJS_NUMBER\020\002\"U\n\017OptionRetenti" - "on\022\025\n\021RETENTION_UNKNOWN\020\000\022\025\n\021RETENTION_R" - "UNTIME\020\001\022\024\n\020RETENTION_SOURCE\020\002\"\214\002\n\020Optio" - "nTargetType\022\027\n\023TARGET_TYPE_UNKNOWN\020\000\022\024\n\020" - "TARGET_TYPE_FILE\020\001\022\037\n\033TARGET_TYPE_EXTENS" - "ION_RANGE\020\002\022\027\n\023TARGET_TYPE_MESSAGE\020\003\022\025\n\021" - "TARGET_TYPE_FIELD\020\004\022\025\n\021TARGET_TYPE_ONEOF" - "\020\005\022\024\n\020TARGET_TYPE_ENUM\020\006\022\032\n\026TARGET_TYPE_" - "ENUM_ENTRY\020\007\022\027\n\023TARGET_TYPE_SERVICE\020\010\022\026\n" - "\022TARGET_TYPE_METHOD\020\t*\t\010\350\007\020\200\200\200\200\002J\004\010\004\020\005J\004" - "\010\022\020\023\"\215\001\n\014OneofOptions\022-\n\010features\030\001 \001(\0132" - "\033.google.protobuf.FeatureSet\022C\n\024uninterp" - "reted_option\030\347\007 \003(\0132$.google.protobuf.Un" - "interpretedOption*\t\010\350\007\020\200\200\200\200\002\"\366\001\n\013EnumOpt" - "ions\022\023\n\013allow_alias\030\002 \001(\010\022\031\n\ndeprecated\030" - "\003 \001(\010:\005false\0222\n&deprecated_legacy_json_f" - "ield_conflicts\030\006 \001(\010B\002\030\001\022-\n\010features\030\007 \001" - "(\0132\033.google.protobuf.FeatureSet\022C\n\024unint" - "erpreted_option\030\347\007 \003(\0132$.google.protobuf" - ".UninterpretedOption*\t\010\350\007\020\200\200\200\200\002J\004\010\005\020\006\"\311\001" - "\n\020EnumValueOptions\022\031\n\ndeprecated\030\001 \001(\010:\005" - "false\022-\n\010features\030\002 \001(\0132\033.google.protobu" - "f.FeatureSet\022\033\n\014debug_redact\030\003 \001(\010:\005fals" - "e\022C\n\024uninterpreted_option\030\347\007 \003(\0132$.googl" - "e.protobuf.UninterpretedOption*\t\010\350\007\020\200\200\200\200" - "\002\"\252\001\n\016ServiceOptions\022-\n\010features\030\" \001(\0132\033" - ".google.protobuf.FeatureSet\022\031\n\ndeprecate" - "d\030! \001(\010:\005false\022C\n\024uninterpreted_option\030\347" - "\007 \003(\0132$.google.protobuf.UninterpretedOpt" - "ion*\t\010\350\007\020\200\200\200\200\002\"\334\002\n\rMethodOptions\022\031\n\ndepr" - "ecated\030! \001(\010:\005false\022_\n\021idempotency_level" - "\030\" \001(\0162/.google.protobuf.MethodOptions.I" - "dempotencyLevel:\023IDEMPOTENCY_UNKNOWN\022-\n\010" - "features\030# \001(\0132\033.google.protobuf.Feature" - "Set\022C\n\024uninterpreted_option\030\347\007 \003(\0132$.goo" - "gle.protobuf.UninterpretedOption\"P\n\020Idem" - "potencyLevel\022\027\n\023IDEMPOTENCY_UNKNOWN\020\000\022\023\n" - "\017NO_SIDE_EFFECTS\020\001\022\016\n\nIDEMPOTENT\020\002*\t\010\350\007\020" - "\200\200\200\200\002\"\236\002\n\023UninterpretedOption\022;\n\004name\030\002 " - "\003(\0132-.google.protobuf.UninterpretedOptio" - "n.NamePart\022\030\n\020identifier_value\030\003 \001(\t\022\032\n\022" - "positive_int_value\030\004 \001(\004\022\032\n\022negative_int" - "_value\030\005 \001(\003\022\024\n\014double_value\030\006 \001(\001\022\024\n\014st" - "ring_value\030\007 \001(\014\022\027\n\017aggregate_value\030\010 \001(" - "\t\0323\n\010NamePart\022\021\n\tname_part\030\001 \002(\t\022\024\n\014is_e" - "xtension\030\002 \002(\010\"\235\t\n\nFeatureSet\022|\n\016field_p" - "resence\030\001 \001(\0162).google.protobuf.FeatureS" - "et.FieldPresenceB9\210\001\001\230\001\004\230\001\001\242\001\r\022\010EXPLICIT" - "\030\346\007\242\001\r\022\010IMPLICIT\030\347\007\242\001\r\022\010EXPLICIT\030\350\007\022\\\n\te" - "num_type\030\002 \001(\0162$.google.protobuf.Feature" - "Set.EnumTypeB#\210\001\001\230\001\006\230\001\001\242\001\013\022\006CLOSED\030\346\007\242\001\t" - "\022\004OPEN\030\347\007\022{\n\027repeated_field_encoding\030\003 \001" - "(\01621.google.protobuf.FeatureSet.Repeated" - "FieldEncodingB\'\210\001\001\230\001\004\230\001\001\242\001\r\022\010EXPANDED\030\346\007" - "\242\001\013\022\006PACKED\030\347\007\022h\n\017utf8_validation\030\004 \001(\0162" - "*.google.protobuf.FeatureSet.Utf8Validat" - "ionB#\210\001\001\230\001\004\230\001\001\242\001\t\022\004NONE\030\346\007\242\001\013\022\006VERIFY\030\347\007" - "\022g\n\020message_encoding\030\005 \001(\0162+.google.prot" - "obuf.FeatureSet.MessageEncodingB \210\001\001\230\001\004\230" - "\001\001\242\001\024\022\017LENGTH_PREFIXED\030\346\007\022p\n\013json_format" - "\030\006 \001(\0162&.google.protobuf.FeatureSet.Json" - "FormatB3\210\001\001\230\001\003\230\001\006\230\001\001\242\001\027\022\022LEGACY_BEST_EFF" - "ORT\030\346\007\242\001\n\022\005ALLOW\030\347\007\"\\\n\rFieldPresence\022\032\n\026" - "FIELD_PRESENCE_UNKNOWN\020\000\022\014\n\010EXPLICIT\020\001\022\014" - "\n\010IMPLICIT\020\002\022\023\n\017LEGACY_REQUIRED\020\003\"7\n\010Enu" - "mType\022\025\n\021ENUM_TYPE_UNKNOWN\020\000\022\010\n\004OPEN\020\001\022\n" - "\n\006CLOSED\020\002\"V\n\025RepeatedFieldEncoding\022#\n\037R" - "EPEATED_FIELD_ENCODING_UNKNOWN\020\000\022\n\n\006PACK" - "ED\020\001\022\014\n\010EXPANDED\020\002\"C\n\016Utf8Validation\022\033\n\027" - "UTF8_VALIDATION_UNKNOWN\020\000\022\n\n\006VERIFY\020\002\022\010\n" - "\004NONE\020\003\"S\n\017MessageEncoding\022\034\n\030MESSAGE_EN" - "CODING_UNKNOWN\020\000\022\023\n\017LENGTH_PREFIXED\020\001\022\r\n" - "\tDELIMITED\020\002\"H\n\nJsonFormat\022\027\n\023JSON_FORMA" - "T_UNKNOWN\020\000\022\t\n\005ALLOW\020\001\022\026\n\022LEGACY_BEST_EF" - "FORT\020\002*\006\010\350\007\020\351\007*\006\010\351\007\020\352\007*\006\010\213N\020\220NJ\006\010\347\007\020\350\007\"\300" - "\002\n\022FeatureSetDefaults\022N\n\010defaults\030\001 \003(\0132" - "<.google.protobuf.FeatureSetDefaults.Fea" - "tureSetEditionDefault\0221\n\017minimum_edition" - "\030\004 \001(\0162\030.google.protobuf.Edition\0221\n\017maxi" - "mum_edition\030\005 \001(\0162\030.google.protobuf.Edit" - "ion\032t\n\030FeatureSetEditionDefault\022)\n\007editi" - "on\030\003 \001(\0162\030.google.protobuf.Edition\022-\n\010fe" - "atures\030\002 \001(\0132\033.google.protobuf.FeatureSe" - "t\"\325\001\n\016SourceCodeInfo\022:\n\010location\030\001 \003(\0132(" - ".google.protobuf.SourceCodeInfo.Location" - "\032\206\001\n\010Location\022\020\n\004path\030\001 \003(\005B\002\020\001\022\020\n\004span\030" - "\002 \003(\005B\002\020\001\022\030\n\020leading_comments\030\003 \001(\t\022\031\n\021t" - "railing_comments\030\004 \001(\t\022!\n\031leading_detach" - "ed_comments\030\006 \003(\t\"\234\002\n\021GeneratedCodeInfo\022" - "A\n\nannotation\030\001 \003(\0132-.google.protobuf.Ge" - "neratedCodeInfo.Annotation\032\303\001\n\nAnnotatio" - "n\022\020\n\004path\030\001 \003(\005B\002\020\001\022\023\n\013source_file\030\002 \001(\t" - "\022\r\n\005begin\030\003 \001(\005\022\013\n\003end\030\004 \001(\005\022H\n\010semantic" - "\030\005 \001(\01626.google.protobuf.GeneratedCodeIn" - "fo.Annotation.Semantic\"(\n\010Semantic\022\010\n\004NO" - "NE\020\000\022\007\n\003SET\020\001\022\t\n\005ALIAS\020\002*\377\001\n\007Edition\022\023\n\017" - "EDITION_UNKNOWN\020\000\022\023\n\016EDITION_PROTO2\020\346\007\022\023" - "\n\016EDITION_PROTO3\020\347\007\022\021\n\014EDITION_2023\020\350\007\022\027" - "\n\023EDITION_1_TEST_ONLY\020\001\022\027\n\023EDITION_2_TES" - "T_ONLY\020\002\022\035\n\027EDITION_99997_TEST_ONLY\020\235\215\006\022" - "\035\n\027EDITION_99998_TEST_ONLY\020\236\215\006\022\035\n\027EDITIO" - "N_99999_TEST_ONLY\020\237\215\006\022\023\n\013EDITION_MAX\020\377\377\377" - "\377\007B~\n\023com.google.protobufB\020DescriptorPro" - "tosH\001Z-google.golang.org/protobuf/types/" - "descriptorpb\370\001\001\242\002\003GPB\252\002\032Google.Protobuf." - "Reflection" + ":\005false\022\031\n\ndeprecated\030\027 \001(\010:\005false\022\036\n\020cc" + "_enable_arenas\030\037 \001(\010:\004true\022\031\n\021objc_class" + "_prefix\030$ \001(\t\022\030\n\020csharp_namespace\030% \001(\t\022" + "\024\n\014swift_prefix\030\' \001(\t\022\030\n\020php_class_prefi" + "x\030( \001(\t\022\025\n\rphp_namespace\030) \001(\t\022\036\n\026php_me" + "tadata_namespace\030, \001(\t\022\024\n\014ruby_package\030-" + " \001(\t\022-\n\010features\0302 \001(\0132\033.google.protobuf" + ".FeatureSet\022C\n\024uninterpreted_option\030\347\007 \003" + "(\0132$.google.protobuf.UninterpretedOption" + "\":\n\014OptimizeMode\022\t\n\005SPEED\020\001\022\r\n\tCODE_SIZE" + "\020\002\022\020\n\014LITE_RUNTIME\020\003*\t\010\350\007\020\200\200\200\200\002J\004\010*\020+J\004\010" + "&\020\'\"\347\002\n\016MessageOptions\022&\n\027message_set_wi" + "re_format\030\001 \001(\010:\005false\022.\n\037no_standard_de" + "scriptor_accessor\030\002 \001(\010:\005false\022\031\n\ndeprec" + "ated\030\003 \001(\010:\005false\022\021\n\tmap_entry\030\007 \001(\010\0222\n&" + "deprecated_legacy_json_field_conflicts\030\013" + " \001(\010B\002\030\001\022-\n\010features\030\014 \001(\0132\033.google.prot" + "obuf.FeatureSet\022C\n\024uninterpreted_option\030" + "\347\007 \003(\0132$.google.protobuf.UninterpretedOp" + "tion*\t\010\350\007\020\200\200\200\200\002J\004\010\004\020\005J\004\010\005\020\006J\004\010\006\020\007J\004\010\010\020\tJ" + "\004\010\t\020\n\"\215\t\n\014FieldOptions\022:\n\005ctype\030\001 \001(\0162#." + "google.protobuf.FieldOptions.CType:\006STRI" + "NG\022\016\n\006packed\030\002 \001(\010\022\?\n\006jstype\030\006 \001(\0162$.goo" + "gle.protobuf.FieldOptions.JSType:\tJS_NOR" + "MAL\022\023\n\004lazy\030\005 \001(\010:\005false\022\036\n\017unverified_l" + "azy\030\017 \001(\010:\005false\022\031\n\ndeprecated\030\003 \001(\010:\005fa" + "lse\022\023\n\004weak\030\n \001(\010:\005false\022\033\n\014debug_redact" + "\030\020 \001(\010:\005false\022@\n\tretention\030\021 \001(\0162-.googl" + "e.protobuf.FieldOptions.OptionRetention\022" + "\?\n\007targets\030\023 \003(\0162..google.protobuf.Field" + "Options.OptionTargetType\022F\n\020edition_defa" + "ults\030\024 \003(\0132,.google.protobuf.FieldOption" + "s.EditionDefault\022-\n\010features\030\025 \001(\0132\033.goo" + "gle.protobuf.FeatureSet\022C\n\024uninterpreted" + "_option\030\347\007 \003(\0132$.google.protobuf.Uninter" + "pretedOption\032J\n\016EditionDefault\022)\n\007editio" + "n\030\003 \001(\0162\030.google.protobuf.Edition\022\r\n\005val" + "ue\030\002 \001(\t\"/\n\005CType\022\n\n\006STRING\020\000\022\010\n\004CORD\020\001\022" + "\020\n\014STRING_PIECE\020\002\"5\n\006JSType\022\r\n\tJS_NORMAL" + "\020\000\022\r\n\tJS_STRING\020\001\022\r\n\tJS_NUMBER\020\002\"U\n\017Opti" + "onRetention\022\025\n\021RETENTION_UNKNOWN\020\000\022\025\n\021RE" + "TENTION_RUNTIME\020\001\022\024\n\020RETENTION_SOURCE\020\002\"" + "\214\002\n\020OptionTargetType\022\027\n\023TARGET_TYPE_UNKN" + "OWN\020\000\022\024\n\020TARGET_TYPE_FILE\020\001\022\037\n\033TARGET_TY" + "PE_EXTENSION_RANGE\020\002\022\027\n\023TARGET_TYPE_MESS" + "AGE\020\003\022\025\n\021TARGET_TYPE_FIELD\020\004\022\025\n\021TARGET_T" + "YPE_ONEOF\020\005\022\024\n\020TARGET_TYPE_ENUM\020\006\022\032\n\026TAR" + "GET_TYPE_ENUM_ENTRY\020\007\022\027\n\023TARGET_TYPE_SER" + "VICE\020\010\022\026\n\022TARGET_TYPE_METHOD\020\t*\t\010\350\007\020\200\200\200\200" + "\002J\004\010\004\020\005J\004\010\022\020\023\"\215\001\n\014OneofOptions\022-\n\010featur" + "es\030\001 \001(\0132\033.google.protobuf.FeatureSet\022C\n" + "\024uninterpreted_option\030\347\007 \003(\0132$.google.pr" + "otobuf.UninterpretedOption*\t\010\350\007\020\200\200\200\200\002\"\366\001" + "\n\013EnumOptions\022\023\n\013allow_alias\030\002 \001(\010\022\031\n\nde" + "precated\030\003 \001(\010:\005false\0222\n&deprecated_lega" + "cy_json_field_conflicts\030\006 \001(\010B\002\030\001\022-\n\010fea" + "tures\030\007 \001(\0132\033.google.protobuf.FeatureSet" + "\022C\n\024uninterpreted_option\030\347\007 \003(\0132$.google" + ".protobuf.UninterpretedOption*\t\010\350\007\020\200\200\200\200\002" + "J\004\010\005\020\006\"\311\001\n\020EnumValueOptions\022\031\n\ndeprecate" + "d\030\001 \001(\010:\005false\022-\n\010features\030\002 \001(\0132\033.googl" + "e.protobuf.FeatureSet\022\033\n\014debug_redact\030\003 " + "\001(\010:\005false\022C\n\024uninterpreted_option\030\347\007 \003(" + "\0132$.google.protobuf.UninterpretedOption*" + "\t\010\350\007\020\200\200\200\200\002\"\252\001\n\016ServiceOptions\022-\n\010feature" + "s\030\" \001(\0132\033.google.protobuf.FeatureSet\022\031\n\n" + "deprecated\030! \001(\010:\005false\022C\n\024uninterpreted" + "_option\030\347\007 \003(\0132$.google.protobuf.Uninter" + "pretedOption*\t\010\350\007\020\200\200\200\200\002\"\334\002\n\rMethodOption" + "s\022\031\n\ndeprecated\030! \001(\010:\005false\022_\n\021idempote" + "ncy_level\030\" \001(\0162/.google.protobuf.Method" + "Options.IdempotencyLevel:\023IDEMPOTENCY_UN" + "KNOWN\022-\n\010features\030# \001(\0132\033.google.protobu" + "f.FeatureSet\022C\n\024uninterpreted_option\030\347\007 " + "\003(\0132$.google.protobuf.UninterpretedOptio" + "n\"P\n\020IdempotencyLevel\022\027\n\023IDEMPOTENCY_UNK" + "NOWN\020\000\022\023\n\017NO_SIDE_EFFECTS\020\001\022\016\n\nIDEMPOTEN" + "T\020\002*\t\010\350\007\020\200\200\200\200\002\"\236\002\n\023UninterpretedOption\022;" + "\n\004name\030\002 \003(\0132-.google.protobuf.Uninterpr" + "etedOption.NamePart\022\030\n\020identifier_value\030" + "\003 \001(\t\022\032\n\022positive_int_value\030\004 \001(\004\022\032\n\022neg" + "ative_int_value\030\005 \001(\003\022\024\n\014double_value\030\006 " + "\001(\001\022\024\n\014string_value\030\007 \001(\014\022\027\n\017aggregate_v" + "alue\030\010 \001(\t\0323\n\010NamePart\022\021\n\tname_part\030\001 \002(" + "\t\022\024\n\014is_extension\030\002 \002(\010\"\235\t\n\nFeatureSet\022|" + "\n\016field_presence\030\001 \001(\0162).google.protobuf" + ".FeatureSet.FieldPresenceB9\210\001\001\230\001\004\230\001\001\242\001\r\022" + "\010EXPLICIT\030\346\007\242\001\r\022\010IMPLICIT\030\347\007\242\001\r\022\010EXPLICI" + "T\030\350\007\022\\\n\tenum_type\030\002 \001(\0162$.google.protobu" + "f.FeatureSet.EnumTypeB#\210\001\001\230\001\006\230\001\001\242\001\013\022\006CLO" + "SED\030\346\007\242\001\t\022\004OPEN\030\347\007\022{\n\027repeated_field_enc" + "oding\030\003 \001(\01621.google.protobuf.FeatureSet" + ".RepeatedFieldEncodingB\'\210\001\001\230\001\004\230\001\001\242\001\r\022\010EX" + "PANDED\030\346\007\242\001\013\022\006PACKED\030\347\007\022h\n\017utf8_validati" + "on\030\004 \001(\0162*.google.protobuf.FeatureSet.Ut" + "f8ValidationB#\210\001\001\230\001\004\230\001\001\242\001\t\022\004NONE\030\346\007\242\001\013\022\006" + "VERIFY\030\347\007\022g\n\020message_encoding\030\005 \001(\0162+.go" + "ogle.protobuf.FeatureSet.MessageEncoding" + "B \210\001\001\230\001\004\230\001\001\242\001\024\022\017LENGTH_PREFIXED\030\346\007\022p\n\013js" + "on_format\030\006 \001(\0162&.google.protobuf.Featur" + "eSet.JsonFormatB3\210\001\001\230\001\003\230\001\006\230\001\001\242\001\027\022\022LEGACY" + "_BEST_EFFORT\030\346\007\242\001\n\022\005ALLOW\030\347\007\"\\\n\rFieldPre" + "sence\022\032\n\026FIELD_PRESENCE_UNKNOWN\020\000\022\014\n\010EXP" + "LICIT\020\001\022\014\n\010IMPLICIT\020\002\022\023\n\017LEGACY_REQUIRED" + "\020\003\"7\n\010EnumType\022\025\n\021ENUM_TYPE_UNKNOWN\020\000\022\010\n" + "\004OPEN\020\001\022\n\n\006CLOSED\020\002\"V\n\025RepeatedFieldEnco" + "ding\022#\n\037REPEATED_FIELD_ENCODING_UNKNOWN\020" + "\000\022\n\n\006PACKED\020\001\022\014\n\010EXPANDED\020\002\"C\n\016Utf8Valid" + "ation\022\033\n\027UTF8_VALIDATION_UNKNOWN\020\000\022\n\n\006VE" + "RIFY\020\002\022\010\n\004NONE\020\003\"S\n\017MessageEncoding\022\034\n\030M" + "ESSAGE_ENCODING_UNKNOWN\020\000\022\023\n\017LENGTH_PREF" + "IXED\020\001\022\r\n\tDELIMITED\020\002\"H\n\nJsonFormat\022\027\n\023J" + "SON_FORMAT_UNKNOWN\020\000\022\t\n\005ALLOW\020\001\022\026\n\022LEGAC" + "Y_BEST_EFFORT\020\002*\006\010\350\007\020\351\007*\006\010\351\007\020\352\007*\006\010\213N\020\220NJ" + "\006\010\347\007\020\350\007\"\300\002\n\022FeatureSetDefaults\022N\n\010defaul" + "ts\030\001 \003(\0132<.google.protobuf.FeatureSetDef" + "aults.FeatureSetEditionDefault\0221\n\017minimu" + "m_edition\030\004 \001(\0162\030.google.protobuf.Editio" + "n\0221\n\017maximum_edition\030\005 \001(\0162\030.google.prot" + "obuf.Edition\032t\n\030FeatureSetEditionDefault" + "\022)\n\007edition\030\003 \001(\0162\030.google.protobuf.Edit" + "ion\022-\n\010features\030\002 \001(\0132\033.google.protobuf." + "FeatureSet\"\325\001\n\016SourceCodeInfo\022:\n\010locatio" + "n\030\001 \003(\0132(.google.protobuf.SourceCodeInfo" + ".Location\032\206\001\n\010Location\022\020\n\004path\030\001 \003(\005B\002\020\001" + "\022\020\n\004span\030\002 \003(\005B\002\020\001\022\030\n\020leading_comments\030\003" + " \001(\t\022\031\n\021trailing_comments\030\004 \001(\t\022!\n\031leadi" + "ng_detached_comments\030\006 \003(\t\"\234\002\n\021Generated" + "CodeInfo\022A\n\nannotation\030\001 \003(\0132-.google.pr" + "otobuf.GeneratedCodeInfo.Annotation\032\303\001\n\n" + "Annotation\022\020\n\004path\030\001 \003(\005B\002\020\001\022\023\n\013source_f" + "ile\030\002 \001(\t\022\r\n\005begin\030\003 \001(\005\022\013\n\003end\030\004 \001(\005\022H\n" + "\010semantic\030\005 \001(\01626.google.protobuf.Genera" + "tedCodeInfo.Annotation.Semantic\"(\n\010Seman" + "tic\022\010\n\004NONE\020\000\022\007\n\003SET\020\001\022\t\n\005ALIAS\020\002*\377\001\n\007Ed" + "ition\022\023\n\017EDITION_UNKNOWN\020\000\022\023\n\016EDITION_PR" + "OTO2\020\346\007\022\023\n\016EDITION_PROTO3\020\347\007\022\021\n\014EDITION_" + "2023\020\350\007\022\027\n\023EDITION_1_TEST_ONLY\020\001\022\027\n\023EDIT" + "ION_2_TEST_ONLY\020\002\022\035\n\027EDITION_99997_TEST_" + "ONLY\020\235\215\006\022\035\n\027EDITION_99998_TEST_ONLY\020\236\215\006\022" + "\035\n\027EDITION_99999_TEST_ONLY\020\237\215\006\022\023\n\013EDITIO" + "N_MAX\020\377\377\377\377\007B~\n\023com.google.protobufB\020Desc" + "riptorProtosH\001Z-google.golang.org/protob" + "uf/types/descriptorpb\370\001\001\242\002\003GPB\252\002\032Google." + "Protobuf.Reflection" }; static ::absl::once_flag descriptor_table_google_2fprotobuf_2fdescriptor_2eproto_once; const ::_pbi::DescriptorTable descriptor_table_google_2fprotobuf_2fdescriptor_2eproto = { false, false, - 9570, + 9539, descriptor_table_protodef_google_2fprotobuf_2fdescriptor_2eproto, "google/protobuf/descriptor.proto", &descriptor_table_google_2fprotobuf_2fdescriptor_2eproto_once, @@ -7287,7 +7283,7 @@ PROTOBUF_NOINLINE void FileOptions::Clear() { reinterpret_cast(&_impl_.java_generic_services_) - reinterpret_cast(&_impl_.java_multiple_files_)) + sizeof(_impl_.java_generic_services_)); } - if (cached_has_bits & 0x001f0000u) { + if (cached_has_bits & 0x000f0000u) { ::memset(&_impl_.py_generic_services_, 0, static_cast<::size_t>( reinterpret_cast(&_impl_.deprecated_) - reinterpret_cast(&_impl_.py_generic_services_)) + sizeof(_impl_.deprecated_)); @@ -7305,7 +7301,7 @@ const char* FileOptions::_InternalParse( } -constexpr ::_pbi::TcParseTable<5, 22, 3, 202, 12> FileOptions::_table_ = { +constexpr ::_pbi::TcParseTable<5, 21, 3, 202, 12> FileOptions::_table_ = { { PROTOBUF_FIELD_OFFSET(FileOptions, _impl_._has_bits_), PROTOBUF_FIELD_OFFSET(FileOptions, _impl_._extensions_), @@ -7313,7 +7309,7 @@ constexpr ::_pbi::TcParseTable<5, 22, 3, 202, 12> FileOptions::_table_ = { offsetof(decltype(_table_), field_lookup_table), 3149166718, // skipmap offsetof(decltype(_table_), field_entries), - 22, // num_field_entries + 21, // num_field_entries 3, // num_aux_entries offsetof(decltype(_table_), aux_entries), &_FileOptions_default_instance_._instance, @@ -7337,7 +7333,7 @@ constexpr ::_pbi::TcParseTable<5, 22, 3, 202, 12> FileOptions::_table_ = { {66, 1, 0, PROTOBUF_FIELD_OFFSET(FileOptions, _impl_.java_outer_classname_)}}, // optional .google.protobuf.FileOptions.OptimizeMode optimize_for = 9 [default = SPEED]; {::_pbi::TcParser::FastEr1S1, - {72, 19, 3, PROTOBUF_FIELD_OFFSET(FileOptions, _impl_.optimize_for_)}}, + {72, 18, 3, PROTOBUF_FIELD_OFFSET(FileOptions, _impl_.optimize_for_)}}, // optional bool java_multiple_files = 10 [default = false]; {::_pbi::TcParser::SingularVarintNoZag1(), {80, 11, 0, PROTOBUF_FIELD_OFFSET(FileOptions, _impl_.java_multiple_files_)}}, @@ -7367,16 +7363,14 @@ constexpr ::_pbi::TcParseTable<5, 22, 3, 202, 12> FileOptions::_table_ = { {::_pbi::TcParser::MiniParse, {}}, // optional bool deprecated = 23 [default = false]; {::_pbi::TcParser::FastV8S2, - {440, 18, 0, PROTOBUF_FIELD_OFFSET(FileOptions, _impl_.deprecated_)}}, + {440, 17, 0, PROTOBUF_FIELD_OFFSET(FileOptions, _impl_.deprecated_)}}, // optional string php_class_prefix = 40; {::_pbi::TcParser::FastSS2, {706, 6, 0, PROTOBUF_FIELD_OFFSET(FileOptions, _impl_.php_class_prefix_)}}, // optional string php_namespace = 41; {::_pbi::TcParser::FastSS2, {714, 7, 0, PROTOBUF_FIELD_OFFSET(FileOptions, _impl_.php_namespace_)}}, - // optional bool php_generic_services = 42 [default = false]; - {::_pbi::TcParser::FastV8S2, - {720, 17, 0, PROTOBUF_FIELD_OFFSET(FileOptions, _impl_.php_generic_services_)}}, + {::_pbi::TcParser::MiniParse, {}}, // optional bool java_string_check_utf8 = 27 [default = false]; {::_pbi::TcParser::FastV8S2, {472, 13, 0, PROTOBUF_FIELD_OFFSET(FileOptions, _impl_.java_string_check_utf8_)}}, @@ -7389,11 +7383,11 @@ constexpr ::_pbi::TcParseTable<5, 22, 3, 202, 12> FileOptions::_table_ = { {::_pbi::TcParser::MiniParse, {}}, // optional bool cc_enable_arenas = 31 [default = true]; {::_pbi::TcParser::FastV8S2, - {504, 20, 0, PROTOBUF_FIELD_OFFSET(FileOptions, _impl_.cc_enable_arenas_)}}, + {504, 19, 0, PROTOBUF_FIELD_OFFSET(FileOptions, _impl_.cc_enable_arenas_)}}, }}, {{ 36, 0, 1, - 48260, 12,999, 0, 1, - 65534, 21, + 48324, 12,999, 0, 1, + 65534, 20, 65535, 65535 }}, {{ // optional string java_package = 1; @@ -7403,7 +7397,7 @@ constexpr ::_pbi::TcParseTable<5, 22, 3, 202, 12> FileOptions::_table_ = { {PROTOBUF_FIELD_OFFSET(FileOptions, _impl_.java_outer_classname_), _Internal::kHasBitsOffset + 1, 0, (0 | ::_fl::kFcOptional | ::_fl::kRawString | ::_fl::kRepAString)}, // optional .google.protobuf.FileOptions.OptimizeMode optimize_for = 9 [default = SPEED]; - {PROTOBUF_FIELD_OFFSET(FileOptions, _impl_.optimize_for_), _Internal::kHasBitsOffset + 19, 0, + {PROTOBUF_FIELD_OFFSET(FileOptions, _impl_.optimize_for_), _Internal::kHasBitsOffset + 18, 0, (0 | ::_fl::kFcOptional | ::_fl::kEnumRange)}, // optional bool java_multiple_files = 10 [default = false]; {PROTOBUF_FIELD_OFFSET(FileOptions, _impl_.java_multiple_files_), _Internal::kHasBitsOffset + 11, 0, @@ -7424,13 +7418,13 @@ constexpr ::_pbi::TcParseTable<5, 22, 3, 202, 12> FileOptions::_table_ = { {PROTOBUF_FIELD_OFFSET(FileOptions, _impl_.java_generate_equals_and_hash_), _Internal::kHasBitsOffset + 12, 0, (0 | ::_fl::kFcOptional | ::_fl::kBool)}, // optional bool deprecated = 23 [default = false]; - {PROTOBUF_FIELD_OFFSET(FileOptions, _impl_.deprecated_), _Internal::kHasBitsOffset + 18, 0, + {PROTOBUF_FIELD_OFFSET(FileOptions, _impl_.deprecated_), _Internal::kHasBitsOffset + 17, 0, (0 | ::_fl::kFcOptional | ::_fl::kBool)}, // optional bool java_string_check_utf8 = 27 [default = false]; {PROTOBUF_FIELD_OFFSET(FileOptions, _impl_.java_string_check_utf8_), _Internal::kHasBitsOffset + 13, 0, (0 | ::_fl::kFcOptional | ::_fl::kBool)}, // optional bool cc_enable_arenas = 31 [default = true]; - {PROTOBUF_FIELD_OFFSET(FileOptions, _impl_.cc_enable_arenas_), _Internal::kHasBitsOffset + 20, 0, + {PROTOBUF_FIELD_OFFSET(FileOptions, _impl_.cc_enable_arenas_), _Internal::kHasBitsOffset + 19, 0, (0 | ::_fl::kFcOptional | ::_fl::kBool)}, // optional string objc_class_prefix = 36; {PROTOBUF_FIELD_OFFSET(FileOptions, _impl_.objc_class_prefix_), _Internal::kHasBitsOffset + 3, 0, @@ -7447,9 +7441,6 @@ constexpr ::_pbi::TcParseTable<5, 22, 3, 202, 12> FileOptions::_table_ = { // optional string php_namespace = 41; {PROTOBUF_FIELD_OFFSET(FileOptions, _impl_.php_namespace_), _Internal::kHasBitsOffset + 7, 0, (0 | ::_fl::kFcOptional | ::_fl::kRawString | ::_fl::kRepAString)}, - // optional bool php_generic_services = 42 [default = false]; - {PROTOBUF_FIELD_OFFSET(FileOptions, _impl_.php_generic_services_), _Internal::kHasBitsOffset + 17, 0, - (0 | ::_fl::kFcOptional | ::_fl::kBool)}, // optional string php_metadata_namespace = 44; {PROTOBUF_FIELD_OFFSET(FileOptions, _impl_.php_metadata_namespace_), _Internal::kHasBitsOffset + 8, 0, (0 | ::_fl::kFcOptional | ::_fl::kRawString | ::_fl::kRepAString)}, @@ -7467,7 +7458,7 @@ constexpr ::_pbi::TcParseTable<5, 22, 3, 202, 12> FileOptions::_table_ = { {::_pbi::TcParser::GetTable<::google::protobuf::FeatureSet>()}, {::_pbi::TcParser::GetTable<::google::protobuf::UninterpretedOption>()}, }}, {{ - "\33\14\24\0\0\12\0\0\0\0\0\0\0\21\20\14\20\15\0\26\14\0\0\0" + "\33\14\24\0\0\12\0\0\0\0\0\0\0\21\20\14\20\15\26\14\0\0\0\0" "google.protobuf.FileOptions" "java_package" "java_outer_classname" @@ -7507,7 +7498,7 @@ ::uint8_t* FileOptions::_InternalSerialize( } // optional .google.protobuf.FileOptions.OptimizeMode optimize_for = 9 [default = SPEED]; - if (cached_has_bits & 0x00080000u) { + if (cached_has_bits & 0x00040000u) { target = stream->EnsureSpace(target); target = ::_pbi::WireFormatLite::WriteEnumToArray( 9, this->_internal_optimize_for(), target); @@ -7557,7 +7548,7 @@ ::uint8_t* FileOptions::_InternalSerialize( } // optional bool deprecated = 23 [default = false]; - if (cached_has_bits & 0x00040000u) { + if (cached_has_bits & 0x00020000u) { target = stream->EnsureSpace(target); target = ::_pbi::WireFormatLite::WriteBoolToArray( 23, this->_internal_deprecated(), target); @@ -7571,7 +7562,7 @@ ::uint8_t* FileOptions::_InternalSerialize( } // optional bool cc_enable_arenas = 31 [default = true]; - if (cached_has_bits & 0x00100000u) { + if (cached_has_bits & 0x00080000u) { target = stream->EnsureSpace(target); target = ::_pbi::WireFormatLite::WriteBoolToArray( 31, this->_internal_cc_enable_arenas(), target); @@ -7617,13 +7608,6 @@ ::uint8_t* FileOptions::_InternalSerialize( target = stream->WriteStringMaybeAliased(41, _s, target); } - // optional bool php_generic_services = 42 [default = false]; - if (cached_has_bits & 0x00020000u) { - target = stream->EnsureSpace(target); - target = ::_pbi::WireFormatLite::WriteBoolToArray( - 42, this->_internal_php_generic_services(), target); - } - // optional string php_metadata_namespace = 44; if (cached_has_bits & 0x00000100u) { const std::string& _s = this->_internal_php_metadata_namespace(); @@ -7778,30 +7762,25 @@ ::size_t FileOptions::ByteSizeLong() const { } } - if (cached_has_bits & 0x001f0000u) { + if (cached_has_bits & 0x000f0000u) { // optional bool py_generic_services = 18 [default = false]; if (cached_has_bits & 0x00010000u) { total_size += 3; } - // optional bool php_generic_services = 42 [default = false]; - if (cached_has_bits & 0x00020000u) { - total_size += 3; - } - // optional bool deprecated = 23 [default = false]; - if (cached_has_bits & 0x00040000u) { + if (cached_has_bits & 0x00020000u) { total_size += 3; } // optional .google.protobuf.FileOptions.OptimizeMode optimize_for = 9 [default = SPEED]; - if (cached_has_bits & 0x00080000u) { + if (cached_has_bits & 0x00040000u) { total_size += 1 + ::_pbi::WireFormatLite::EnumSize(this->_internal_optimize_for()); } // optional bool cc_enable_arenas = 31 [default = true]; - if (cached_has_bits & 0x00100000u) { + if (cached_has_bits & 0x00080000u) { total_size += 3; } @@ -7880,20 +7859,17 @@ void FileOptions::MergeImpl(::google::protobuf::MessageLite& to_msg, const ::goo _this->_impl_.java_generic_services_ = from._impl_.java_generic_services_; } } - if (cached_has_bits & 0x001f0000u) { + if (cached_has_bits & 0x000f0000u) { if (cached_has_bits & 0x00010000u) { _this->_impl_.py_generic_services_ = from._impl_.py_generic_services_; } if (cached_has_bits & 0x00020000u) { - _this->_impl_.php_generic_services_ = from._impl_.php_generic_services_; - } - if (cached_has_bits & 0x00040000u) { _this->_impl_.deprecated_ = from._impl_.deprecated_; } - if (cached_has_bits & 0x00080000u) { + if (cached_has_bits & 0x00040000u) { _this->_impl_.optimize_for_ = from._impl_.optimize_for_; } - if (cached_has_bits & 0x00100000u) { + if (cached_has_bits & 0x00080000u) { _this->_impl_.cc_enable_arenas_ = from._impl_.cc_enable_arenas_; } } diff --git a/src/google/protobuf/descriptor.pb.h b/src/google/protobuf/descriptor.pb.h index 4e7aec590f6a7..765de53a7674d 100644 --- a/src/google/protobuf/descriptor.pb.h +++ b/src/google/protobuf/descriptor.pb.h @@ -5298,7 +5298,6 @@ class PROTOBUF_EXPORT FileOptions final : public ::google::protobuf::Message kCcGenericServicesFieldNumber = 16, kJavaGenericServicesFieldNumber = 17, kPyGenericServicesFieldNumber = 18, - kPhpGenericServicesFieldNumber = 42, kDeprecatedFieldNumber = 23, kOptimizeForFieldNumber = 9, kCcEnableArenasFieldNumber = 31, @@ -5570,17 +5569,6 @@ class PROTOBUF_EXPORT FileOptions final : public ::google::protobuf::Message bool _internal_py_generic_services() const; void _internal_set_py_generic_services(bool value); - public: - // optional bool php_generic_services = 42 [default = false]; - bool has_php_generic_services() const; - void clear_php_generic_services() ; - bool php_generic_services() const; - void set_php_generic_services(bool value); - - private: - bool _internal_php_generic_services() const; - void _internal_set_php_generic_services(bool value); - public: // optional bool deprecated = 23 [default = false]; bool has_deprecated() const; @@ -5797,7 +5785,7 @@ class PROTOBUF_EXPORT FileOptions final : public ::google::protobuf::Message class _Internal; friend class ::google::protobuf::internal::TcParser; static const ::google::protobuf::internal::TcParseTable< - 5, 22, 3, + 5, 21, 3, 202, 12> _table_; friend class ::google::protobuf::MessageLite; @@ -5834,7 +5822,6 @@ class PROTOBUF_EXPORT FileOptions final : public ::google::protobuf::Message bool cc_generic_services_; bool java_generic_services_; bool py_generic_services_; - bool php_generic_services_; bool deprecated_; int optimize_for_; bool cc_enable_arenas_; @@ -14933,13 +14920,13 @@ inline void FileOptions::_internal_set_java_string_check_utf8(bool value) { // optional .google.protobuf.FileOptions.OptimizeMode optimize_for = 9 [default = SPEED]; inline bool FileOptions::has_optimize_for() const { - bool value = (_impl_._has_bits_[0] & 0x00080000u) != 0; + bool value = (_impl_._has_bits_[0] & 0x00040000u) != 0; return value; } inline void FileOptions::clear_optimize_for() { PROTOBUF_TSAN_WRITE(&_impl_._tsan_detect_race); _impl_.optimize_for_ = 1; - _impl_._has_bits_[0] &= ~0x00080000u; + _impl_._has_bits_[0] &= ~0x00040000u; } inline ::google::protobuf::FileOptions_OptimizeMode FileOptions::optimize_for() const { // @@protoc_insertion_point(field_get:google.protobuf.FileOptions.optimize_for) @@ -14947,7 +14934,7 @@ inline ::google::protobuf::FileOptions_OptimizeMode FileOptions::optimize_for() } inline void FileOptions::set_optimize_for(::google::protobuf::FileOptions_OptimizeMode value) { _internal_set_optimize_for(value); - _impl_._has_bits_[0] |= 0x00080000u; + _impl_._has_bits_[0] |= 0x00040000u; // @@protoc_insertion_point(field_set:google.protobuf.FileOptions.optimize_for) } inline ::google::protobuf::FileOptions_OptimizeMode FileOptions::_internal_optimize_for() const { @@ -15115,43 +15102,15 @@ inline void FileOptions::_internal_set_py_generic_services(bool value) { _impl_.py_generic_services_ = value; } -// optional bool php_generic_services = 42 [default = false]; -inline bool FileOptions::has_php_generic_services() const { - bool value = (_impl_._has_bits_[0] & 0x00020000u) != 0; - return value; -} -inline void FileOptions::clear_php_generic_services() { - PROTOBUF_TSAN_WRITE(&_impl_._tsan_detect_race); - _impl_.php_generic_services_ = false; - _impl_._has_bits_[0] &= ~0x00020000u; -} -inline bool FileOptions::php_generic_services() const { - // @@protoc_insertion_point(field_get:google.protobuf.FileOptions.php_generic_services) - return _internal_php_generic_services(); -} -inline void FileOptions::set_php_generic_services(bool value) { - _internal_set_php_generic_services(value); - _impl_._has_bits_[0] |= 0x00020000u; - // @@protoc_insertion_point(field_set:google.protobuf.FileOptions.php_generic_services) -} -inline bool FileOptions::_internal_php_generic_services() const { - PROTOBUF_TSAN_READ(&_impl_._tsan_detect_race); - return _impl_.php_generic_services_; -} -inline void FileOptions::_internal_set_php_generic_services(bool value) { - PROTOBUF_TSAN_WRITE(&_impl_._tsan_detect_race); - _impl_.php_generic_services_ = value; -} - // optional bool deprecated = 23 [default = false]; inline bool FileOptions::has_deprecated() const { - bool value = (_impl_._has_bits_[0] & 0x00040000u) != 0; + bool value = (_impl_._has_bits_[0] & 0x00020000u) != 0; return value; } inline void FileOptions::clear_deprecated() { PROTOBUF_TSAN_WRITE(&_impl_._tsan_detect_race); _impl_.deprecated_ = false; - _impl_._has_bits_[0] &= ~0x00040000u; + _impl_._has_bits_[0] &= ~0x00020000u; } inline bool FileOptions::deprecated() const { // @@protoc_insertion_point(field_get:google.protobuf.FileOptions.deprecated) @@ -15159,7 +15118,7 @@ inline bool FileOptions::deprecated() const { } inline void FileOptions::set_deprecated(bool value) { _internal_set_deprecated(value); - _impl_._has_bits_[0] |= 0x00040000u; + _impl_._has_bits_[0] |= 0x00020000u; // @@protoc_insertion_point(field_set:google.protobuf.FileOptions.deprecated) } inline bool FileOptions::_internal_deprecated() const { @@ -15173,13 +15132,13 @@ inline void FileOptions::_internal_set_deprecated(bool value) { // optional bool cc_enable_arenas = 31 [default = true]; inline bool FileOptions::has_cc_enable_arenas() const { - bool value = (_impl_._has_bits_[0] & 0x00100000u) != 0; + bool value = (_impl_._has_bits_[0] & 0x00080000u) != 0; return value; } inline void FileOptions::clear_cc_enable_arenas() { PROTOBUF_TSAN_WRITE(&_impl_._tsan_detect_race); _impl_.cc_enable_arenas_ = true; - _impl_._has_bits_[0] &= ~0x00100000u; + _impl_._has_bits_[0] &= ~0x00080000u; } inline bool FileOptions::cc_enable_arenas() const { // @@protoc_insertion_point(field_get:google.protobuf.FileOptions.cc_enable_arenas) @@ -15187,7 +15146,7 @@ inline bool FileOptions::cc_enable_arenas() const { } inline void FileOptions::set_cc_enable_arenas(bool value) { _internal_set_cc_enable_arenas(value); - _impl_._has_bits_[0] |= 0x00100000u; + _impl_._has_bits_[0] |= 0x00080000u; // @@protoc_insertion_point(field_set:google.protobuf.FileOptions.cc_enable_arenas) } inline bool FileOptions::_internal_cc_enable_arenas() const { diff --git a/src/google/protobuf/descriptor.proto b/src/google/protobuf/descriptor.proto index 1d9876e6660a3..45220bda00821 100644 --- a/src/google/protobuf/descriptor.proto +++ b/src/google/protobuf/descriptor.proto @@ -484,7 +484,7 @@ message FileOptions { optional bool cc_generic_services = 16 [default = false]; optional bool java_generic_services = 17 [default = false]; optional bool py_generic_services = 18 [default = false]; - optional bool php_generic_services = 42 [default = false]; + reserved 42; // removed php_generic_services // Is this file deprecated? // Depending on the target platform, this can emit Deprecated annotations diff --git a/upb/reflection/stage0/google/protobuf/descriptor.upb.c b/upb/reflection/stage0/google/protobuf/descriptor.upb.c index c4f7a2f02b519..46c1e47ef52e6 100644 --- a/upb/reflection/stage0/google/protobuf/descriptor.upb.c +++ b/upb/reflection/stage0/google/protobuf/descriptor.upb.c @@ -182,7 +182,7 @@ const upb_MiniTable* google__protobuf__MethodDescriptorProto_msg_init() { const upb_MiniTable* google__protobuf__FileOptions_msg_init() { static upb_MiniTable* mini_table = NULL; - static const char* mini_descriptor = "$P1f14/1d///a/b/c/c/d11a111/a11d3t|G"; + static const char* mini_descriptor = "$P1f14/1d///a/b/c/c/d11a111b11d3t|G"; if (mini_table) return mini_table; mini_table = upb_MiniTable_Build(mini_descriptor, strlen(mini_descriptor), diff --git a/upb/reflection/stage0/google/protobuf/descriptor.upb.h b/upb/reflection/stage0/google/protobuf/descriptor.upb.h index 2ac29d6610a11..99caf55dc0842 100644 --- a/upb/reflection/stage0/google/protobuf/descriptor.upb.h +++ b/upb/reflection/stage0/google/protobuf/descriptor.upb.h @@ -3351,21 +3351,6 @@ UPB_INLINE bool google_protobuf_FileOptions_has_php_namespace(const google_proto const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 41); return _upb_Message_HasNonExtensionField(msg, &field); } -UPB_INLINE void google_protobuf_FileOptions_clear_php_generic_services(google_protobuf_FileOptions* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 42); - _upb_Message_ClearNonExtensionField(msg, &field); -} -UPB_INLINE bool google_protobuf_FileOptions_php_generic_services(const google_protobuf_FileOptions* msg) { - bool default_val = false; - bool ret; - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 42); - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_FileOptions_has_php_generic_services(const google_protobuf_FileOptions* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 42); - return _upb_Message_HasNonExtensionField(msg, &field); -} UPB_INLINE void google_protobuf_FileOptions_clear_php_metadata_namespace(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 44); _upb_Message_ClearNonExtensionField(msg, &field); @@ -3512,10 +3497,6 @@ UPB_INLINE void google_protobuf_FileOptions_set_php_namespace(google_protobuf_Fi const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 41); _upb_Message_SetNonExtensionField(msg, &field, &value); } -UPB_INLINE void google_protobuf_FileOptions_set_php_generic_services(google_protobuf_FileOptions *msg, bool value) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 42); - _upb_Message_SetNonExtensionField(msg, &field, &value); -} UPB_INLINE void google_protobuf_FileOptions_set_php_metadata_namespace(google_protobuf_FileOptions *msg, upb_StringView value) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 44); _upb_Message_SetNonExtensionField(msg, &field, &value); @@ -6315,7 +6296,7 @@ UPB_INLINE void google_protobuf_GeneratedCodeInfo_Annotation_set_semantic(google /* Max size 32 is google.protobuf.FileOptions */ /* Max size 64 is google.protobuf.FileOptions */ -#define _UPB_MAXOPT_SIZE UPB_SIZE(112, 200) +#define _UPB_MAXOPT_SIZE UPB_SIZE(104, 192) #ifdef __cplusplus } /* extern "C" */ From 1ddf0337113b4ac34bc9b2f4f1b099017261bd67 Mon Sep 17 00:00:00 2001 From: Alyssa Haroldsen Date: Wed, 20 Dec 2023 15:57:34 -0800 Subject: [PATCH 077/255] Clarify error language for prefix-conflicting enum values PiperOrigin-RevId: 592679725 --- src/google/protobuf/descriptor.cc | 2 +- src/google/protobuf/descriptor_unittest.cc | 39 +++++++++++----------- 2 files changed, 20 insertions(+), 21 deletions(-) diff --git a/src/google/protobuf/descriptor.cc b/src/google/protobuf/descriptor.cc index 004be51c3bdc1..ff373708b6d3d 100644 --- a/src/google/protobuf/descriptor.cc +++ b/src/google/protobuf/descriptor.cc @@ -6710,7 +6710,7 @@ void DescriptorBuilder::CheckEnumValueUniqueness( return absl::StrFormat( "Enum name %s has the same name as %s if you ignore case and strip " "out the enum name prefix (if any). (If you are using allow_alias, " - "please assign the same numeric value to both enums.)", + "please assign the same number to each enum value name.)", value->name(), insert_result.first->second->name()); }; // There are proto2 enums out there with conflicting names, so to preserve diff --git a/src/google/protobuf/descriptor_unittest.cc b/src/google/protobuf/descriptor_unittest.cc index 703fb77861f5a..7745313ff6065 100644 --- a/src/google/protobuf/descriptor_unittest.cc +++ b/src/google/protobuf/descriptor_unittest.cc @@ -6653,8 +6653,8 @@ TEST_F(ValidationErrorTest, Proto3EnumValuesConflictWithDifferentCasing) { "}", "foo.proto: bar: NAME: Enum name bar has the same name as BAR " "if you ignore case and strip out the enum name prefix (if any). " - "(If you are using allow_alias, please assign the same numeric " - "value to both enums.)\n"); + "(If you are using allow_alias, please assign the same number " + "to each enum value name.)\n"); BuildFileWithErrors( "syntax: 'proto2'" @@ -6666,8 +6666,8 @@ TEST_F(ValidationErrorTest, Proto3EnumValuesConflictWithDifferentCasing) { "}", "foo.proto: bar: NAME: Enum name bar has the same name as BAR " "if you ignore case and strip out the enum name prefix (if any). " - "(If you are using allow_alias, please assign the same numeric " - "value to both enums.)\n"); + "(If you are using allow_alias, please assign the same number " + "to each enum value name.)\n"); // Not an error because both enums are mapped to the same value. BuildFile( @@ -6693,8 +6693,8 @@ TEST_F(ValidationErrorTest, EnumValuesConflictWhenPrefixesStripped) { "}", "foo.proto: BAZ: NAME: Enum name BAZ has the same name as FOO_ENUM_BAZ " "if you ignore case and strip out the enum name prefix (if any). " - "(If you are using allow_alias, please assign the same numeric value " - "to both enums.)\n"); + "(If you are using allow_alias, please assign the same number " + "to each enum value name.)\n"); BuildFileWithErrors( "syntax: 'proto3'" @@ -6706,8 +6706,8 @@ TEST_F(ValidationErrorTest, EnumValuesConflictWhenPrefixesStripped) { "}", "foo.proto: BAZ: NAME: Enum name BAZ has the same name as FOOENUM_BAZ " "if you ignore case and strip out the enum name prefix (if any). " - "(If you are using allow_alias, please assign the same numeric value " - "to both enums.)\n"); + "(If you are using allow_alias, please assign the same number " + "to each enum value name.)\n"); BuildFileWithErrors( "syntax: 'proto3'" @@ -6719,8 +6719,8 @@ TEST_F(ValidationErrorTest, EnumValuesConflictWhenPrefixesStripped) { "}", "foo.proto: BAR__BAZ: NAME: Enum name BAR__BAZ has the same name as " "FOO_ENUM_BAR_BAZ if you ignore case and strip out the enum name prefix " - "(if any). (If you are using allow_alias, please assign the same numeric " - "value to both enums.)\n"); + "(if any). (If you are using allow_alias, please assign the same number " + "to each enum value name.)\n"); BuildFileWithErrors( "syntax: 'proto3'" @@ -6732,8 +6732,8 @@ TEST_F(ValidationErrorTest, EnumValuesConflictWhenPrefixesStripped) { "}", "foo.proto: BAR_BAZ: NAME: Enum name BAR_BAZ has the same name as " "FOO_ENUM__BAR_BAZ if you ignore case and strip out the enum name prefix " - "(if any). (If you are using allow_alias, please assign the same numeric " - "value to both enums.)\n"); + "(if any). (If you are using allow_alias, please assign the same number " + "to each enum value name.)\n"); BuildFileWithErrors( "syntax: 'proto2'" @@ -6745,8 +6745,8 @@ TEST_F(ValidationErrorTest, EnumValuesConflictWhenPrefixesStripped) { "}", "foo.proto: BAR_BAZ: NAME: Enum name BAR_BAZ has the same name as " "FOO_ENUM__BAR_BAZ if you ignore case and strip out the enum name prefix " - "(if any). (If you are using allow_alias, please assign the same numeric " - "value to both enums.)\n"); + "(if any). (If you are using allow_alias, please assign the same number " + "to each enum value name.)\n"); // This isn't an error because the underscore will cause the PascalCase to // differ by case (BarBaz vs. Barbaz). @@ -6772,8 +6772,8 @@ TEST_F(ValidationErrorTest, EnumValuesConflictLegacyBehavior) { "}", "foo.proto: bar: NAME: Enum name bar has the same name as BAR " "if you ignore case and strip out the enum name prefix (if any). " - "(If you are using allow_alias, please assign the same numeric " - "value to both enums.)\n"); + "(If you are using allow_alias, please assign the same number " + "to each enum value name.)\n"); BuildFileWithErrors( "syntax: 'proto3'" @@ -6788,8 +6788,7 @@ TEST_F(ValidationErrorTest, EnumValuesConflictLegacyBehavior) { "FOO_ENUM__BAR_BAZ if you ignore case and strip out the enum name " "prefix " "(if any). (If you are using allow_alias, please assign the same " - "numeric " - "value to both enums.)\n"); + "number to each enum value name.)\n"); BuildFileWithWarnings( "syntax: 'proto2'" @@ -6802,8 +6801,8 @@ TEST_F(ValidationErrorTest, EnumValuesConflictLegacyBehavior) { "}", "foo.proto: bar: NAME: Enum name bar has the same name as BAR " "if you ignore case and strip out the enum name prefix (if any). " - "(If you are using allow_alias, please assign the same numeric " - "value to both enums.)\n"); + "(If you are using allow_alias, please assign the same number " + "to each enum value name.)\n"); } TEST_F(ValidationErrorTest, MapEntryConflictsWithOneof) { From 8981fe5cabd7479e6dcc08aeb3d2cf80541ce0e5 Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Thu, 21 Dec 2023 00:04:37 +0000 Subject: [PATCH 078/255] Auto-generate files after cl/592677762 --- csharp/src/Google.Protobuf.Test/testprotos.pb | Bin 363136 -> 363070 bytes .../Reflection/Descriptor.pb.cs | 313 ++++----- php/ext/google/protobuf/php-upb.c | 601 +++++++++--------- php/ext/google/protobuf/php-upb.h | 123 ++-- ruby/ext/google/protobuf_c/ruby-upb.c | 47 +- ruby/ext/google/protobuf_c/ruby-upb.h | 123 ++-- upb/cmake/google/protobuf/descriptor.upb.h | 123 ++-- .../protobuf/descriptor.upb_minitable.c | 47 +- 8 files changed, 631 insertions(+), 746 deletions(-) diff --git a/csharp/src/Google.Protobuf.Test/testprotos.pb b/csharp/src/Google.Protobuf.Test/testprotos.pb index 0360804e5a3c39ec5f713563b7659c4c93bf7c4e..9b7e77f2abbf2902ff7a92adfff3044a74994921 100644 GIT binary patch delta 990 zcmZA0&1(}u7zS`>XX3|f_G=P@3Z^k>V=*XJ(Sw>?)M{&cR1gbA>Y_!|l0pxnwz)(k zmuQqZdG#WcLXd!kS`;rWh#vYc6oeiYjN~8zpWWwo-3N~r z+&h`Mdvnuw-G^>@c4m6sEicT@xbvLHIm6~%{%+mi29NoP{2R3}{v!TnjmyGC(!Rx+ zU^`Ufy+az0`BAr`2xEuZhoVURcz7U+d;ORhiQ*nV7EbcTpg@<8FOj7w9R;2$&{5#2 z0v!b&wKE~1qrjuNp(vujqxrK@M1e;~&hS^gC&cBA%cN0^qoJ)D;%I17-3brH(a@$M z7ezF*X?~cG1(!5rew2)t3=kbf7$7=|FhF#u$cBUgqCB65hEY|94Wr6L^a*VkRhAv(8$H93tueA$a$wYy;lQXV!+}v_VmN$?1Ea{fv`BD@x>dFu>>dFu>>a0Hw0i(_^j$$y5gj~NyO2q_-h9VNX{iyE`dlMiU zEEP>O0ixj(PXZz-&rgu2Cz2qfB9b5^)1xy<5Rwg?4#lM0o*+Nc`0*|4|BuLj@%h#y Q!P2lO7He%y#@=7}3q^sFHUIzs delta 1072 zcmYk)%WD%s00!{R&P3~MlHE*_QVO=Q?*|sERHbc#6svvMi#JgyQlc#sDUFB+ZJSGc z#6xP7Ie8N=f)oN)2vn%IictTDDjsqO7>OQ&e!JPpc$mXC%>KT4?Cy(}&6h3P?~2B= zt-^NkmqqpqZ$6J11Lt^Tb!m0scJfYgZFzAam0Y{GyqHY24#r4-^O*0}&6QO0s=$)M z!Iz{_7(du+HJ-jN{QdFd+J>Jq#tkmmcWO-V0QWhGxsj{rbE0XfNStVQt4N*LH=ts( z69>mtJnF>JG5(XdMW$dSYMgF6B(a%P?Cz5MJxRV@H&KXbRcNBHqzg?HmZ;t4ktPaD z^mvDgC@j&~h>9pI(VTMqM%HB z&#H)mG94M^&+8`&$jB7Q#{+1n=!O6qD%1>l9|h1*p`uGgG*oDBKc8_o8I*@pWHu25 zQPo5cL{$?(5LGHVJt7FAN_+bF7M=@lX6>w8B7(#%AT^CxKx!JXfYhjH_Yez6jh^V@ z>#kwT;$^atutB6*<27s$Y1TN34I<4N`>;Wz8TPSTzmAZ+KTST$3$uhxW;7B4lF>*A zNQMdZh9Mvs*4fSX>xd96%Z%Z+qTHM&JJC;(=e==TmL0A|_H zNxoMH!*YF=e2Rx*5D#1;D*w!phr>}2QWH@Sl9}q8C`fwl@j(ikX4>Field number for the "php_generic_services" field. - public const int PhpGenericServicesFieldNumber = 42; - private readonly static bool PhpGenericServicesDefaultValue = false; - - private bool phpGenericServices_; - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public bool PhpGenericServices { - get { if ((_hasBits0 & 512) != 0) { return phpGenericServices_; } else { return PhpGenericServicesDefaultValue; } } - set { - _hasBits0 |= 512; - phpGenericServices_ = value; - } - } - /// Gets whether the "php_generic_services" field is set - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public bool HasPhpGenericServices { - get { return (_hasBits0 & 512) != 0; } - } - /// Clears the value of the "php_generic_services" field - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public void ClearPhpGenericServices() { - _hasBits0 &= ~512; - } - /// Field number for the "deprecated" field. public const int DeprecatedFieldNumber = 23; private readonly static bool DeprecatedDefaultValue = false; @@ -6573,7 +6544,6 @@ public bool Equals(FileOptions other) { if (CcGenericServices != other.CcGenericServices) return false; if (JavaGenericServices != other.JavaGenericServices) return false; if (PyGenericServices != other.PyGenericServices) return false; - if (PhpGenericServices != other.PhpGenericServices) return false; if (Deprecated != other.Deprecated) return false; if (CcEnableArenas != other.CcEnableArenas) return false; if (ObjcClassPrefix != other.ObjcClassPrefix) return false; @@ -6605,7 +6575,6 @@ public override int GetHashCode() { if (HasCcGenericServices) hash ^= CcGenericServices.GetHashCode(); if (HasJavaGenericServices) hash ^= JavaGenericServices.GetHashCode(); if (HasPyGenericServices) hash ^= PyGenericServices.GetHashCode(); - if (HasPhpGenericServices) hash ^= PhpGenericServices.GetHashCode(); if (HasDeprecated) hash ^= Deprecated.GetHashCode(); if (HasCcEnableArenas) hash ^= CcEnableArenas.GetHashCode(); if (HasObjcClassPrefix) hash ^= ObjcClassPrefix.GetHashCode(); @@ -6706,10 +6675,6 @@ public void WriteTo(pb::CodedOutputStream output) { output.WriteRawTag(202, 2); output.WriteString(PhpNamespace); } - if (HasPhpGenericServices) { - output.WriteRawTag(208, 2); - output.WriteBool(PhpGenericServices); - } if (HasPhpMetadataNamespace) { output.WriteRawTag(226, 2); output.WriteString(PhpMetadataNamespace); @@ -6804,10 +6769,6 @@ public void WriteTo(pb::CodedOutputStream output) { output.WriteRawTag(202, 2); output.WriteString(PhpNamespace); } - if (HasPhpGenericServices) { - output.WriteRawTag(208, 2); - output.WriteBool(PhpGenericServices); - } if (HasPhpMetadataNamespace) { output.WriteRawTag(226, 2); output.WriteString(PhpMetadataNamespace); @@ -6864,9 +6825,6 @@ public int CalculateSize() { if (HasPyGenericServices) { size += 2 + 1; } - if (HasPhpGenericServices) { - size += 2 + 1; - } if (HasDeprecated) { size += 2 + 1; } @@ -6943,9 +6901,6 @@ public void MergeFrom(FileOptions other) { if (other.HasPyGenericServices) { PyGenericServices = other.PyGenericServices; } - if (other.HasPhpGenericServices) { - PhpGenericServices = other.PhpGenericServices; - } if (other.HasDeprecated) { Deprecated = other.Deprecated; } @@ -7066,10 +7021,6 @@ public void MergeFrom(pb::CodedInputStream input) { PhpNamespace = input.ReadString(); break; } - case 336: { - PhpGenericServices = input.ReadBool(); - break; - } case 354: { PhpMetadataNamespace = input.ReadString(); break; @@ -7174,10 +7125,6 @@ public void MergeFrom(pb::CodedInputStream input) { PhpNamespace = input.ReadString(); break; } - case 336: { - PhpGenericServices = input.ReadBool(); - break; - } case 354: { PhpMetadataNamespace = input.ReadString(); break; diff --git a/php/ext/google/protobuf/php-upb.c b/php/ext/google/protobuf/php-upb.c index c3d968c2f2694..4a269cc05df36 100644 --- a/php/ext/google/protobuf/php-upb.c +++ b/php/ext/google/protobuf/php-upb.c @@ -838,12 +838,12 @@ static const upb_MiniTableSub google_protobuf_FileOptions_submsgs[3] = { {.UPB_PRIVATE(subenum) = &google_protobuf_FileOptions_OptimizeMode_enum_init}, }; -static const upb_MiniTableField google_protobuf_FileOptions__fields[22] = { - {1, UPB_SIZE(28, 24), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, - {8, UPB_SIZE(36, 40), 2, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, +static const upb_MiniTableField google_protobuf_FileOptions__fields[21] = { + {1, UPB_SIZE(24, 16), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, + {8, 32, 2, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, {9, 4, 3, 2, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}, {10, 8, 4, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}, - {11, UPB_SIZE(44, 56), 5, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, + {11, UPB_SIZE(40, 48), 5, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, {16, 9, 6, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}, {17, 10, 7, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}, {18, 11, 8, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}, @@ -851,35 +851,34 @@ static const upb_MiniTableField google_protobuf_FileOptions__fields[22] = { {23, 13, 10, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}, {27, 14, 11, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}, {31, 15, 12, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}, - {36, UPB_SIZE(52, 72), 13, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, - {37, UPB_SIZE(60, 88), 14, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, - {39, UPB_SIZE(68, 104), 15, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, - {40, UPB_SIZE(76, 120), 16, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, - {41, UPB_SIZE(84, 136), 17, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, - {42, 16, 18, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}, - {44, UPB_SIZE(92, 152), 19, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, - {45, UPB_SIZE(100, 168), 20, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, - {50, UPB_SIZE(20, 184), 21, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, - {999, UPB_SIZE(24, 192), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, + {36, UPB_SIZE(48, 64), 13, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, + {37, UPB_SIZE(56, 80), 14, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, + {39, UPB_SIZE(64, 96), 15, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, + {40, UPB_SIZE(72, 112), 16, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, + {41, UPB_SIZE(80, 128), 17, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, + {44, UPB_SIZE(88, 144), 18, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, + {45, UPB_SIZE(96, 160), 19, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, + {50, UPB_SIZE(16, 176), 20, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, + {999, UPB_SIZE(20, 184), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, }; const upb_MiniTable google__protobuf__FileOptions_msg_init = { &google_protobuf_FileOptions_submsgs[0], &google_protobuf_FileOptions__fields[0], - UPB_SIZE(112, 200), 22, kUpb_ExtMode_Extendable, 1, UPB_FASTTABLE_MASK(248), 0, + UPB_SIZE(104, 192), 21, kUpb_ExtMode_Extendable, 1, UPB_FASTTABLE_MASK(248), 0, UPB_FASTTABLE_INIT({ {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x001800000100000a, &upb_pss_1bt}, + {0x001000000100000a, &upb_pss_1bt}, {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0028000002000042, &upb_pss_1bt}, + {0x0020000002000042, &upb_pss_1bt}, {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, {0x0008000004000050, &upb_psb1_1bt}, - {0x003800000500005a, &upb_pss_1bt}, + {0x003000000500005a, &upb_pss_1bt}, {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, @@ -889,15 +888,15 @@ const upb_MiniTable google__protobuf__FileOptions_msg_init = { {0x000b000008000190, &upb_psb1_2bt}, {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, {0x000c0000090001a0, &upb_psb1_2bt}, - {0x005800000e0002aa, &upb_pss_2bt}, + {0x005000000e0002aa, &upb_pss_2bt}, {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, {0x000d00000a0001b8, &upb_psb1_2bt}, - {0x00780000100002c2, &upb_pss_2bt}, - {0x00880000110002ca, &upb_pss_2bt}, - {0x00100000120002d0, &upb_psb1_2bt}, + {0x00700000100002c2, &upb_pss_2bt}, + {0x00800000110002ca, &upb_pss_2bt}, + {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, {0x000e00000b0001d8, &upb_psb1_2bt}, - {0x00980000130002e2, &upb_pss_2bt}, - {0x00a80000140002ea, &upb_pss_2bt}, + {0x00900000120002e2, &upb_pss_2bt}, + {0x00a00000130002ea, &upb_pss_2bt}, {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, {0x000f00000c0001f8, &upb_psb1_2bt}, }) @@ -1748,7 +1747,7 @@ const upb_MiniTableFile google_protobuf_descriptor_proto_upb_file_layout = { * regenerated. */ -static const char descriptor[11646] = {'\n', ' ', 'g', 'o', 'o', 'g', 'l', 'e', '/', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '/', 'd', 'e', 's', 'c', 'r', 'i', 'p', +static const char descriptor[11595] = {'\n', ' ', 'g', 'o', 'o', 'g', 'l', 'e', '/', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '/', 'd', 'e', 's', 'c', 'r', 'i', 'p', 't', 'o', 'r', '.', 'p', 'r', 'o', 't', 'o', '\022', '\017', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '\"', 'M', '\n', '\021', 'F', 'i', 'l', 'e', 'D', 'e', 's', 'c', 'r', 'i', 'p', 't', 'o', 'r', 'S', 'e', 't', '\022', '8', '\n', '\004', 'f', 'i', 'l', 'e', '\030', '\001', ' ', '\003', '(', '\013', '2', '$', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', @@ -1911,7 +1910,7 @@ static const char descriptor[11646] = {'\n', ' ', 'g', 'o', 'o', 'g', 'l', 'e', 'i', 'n', 'g', '\030', '\005', ' ', '\001', '(', '\010', ':', '\005', 'f', 'a', 'l', 's', 'e', 'R', '\017', 'c', 'l', 'i', 'e', 'n', 't', 'S', 't', 'r', 'e', 'a', 'm', 'i', 'n', 'g', '\022', '0', '\n', '\020', 's', 'e', 'r', 'v', 'e', 'r', '_', 's', 't', 'r', 'e', 'a', 'm', 'i', 'n', 'g', '\030', '\006', ' ', '\001', '(', '\010', ':', '\005', 'f', 'a', 'l', 's', 'e', 'R', '\017', 's', 'e', 'r', 'v', 'e', 'r', 'S', -'t', 'r', 'e', 'a', 'm', 'i', 'n', 'g', '\"', '\312', '\t', '\n', '\013', 'F', 'i', 'l', 'e', 'O', 'p', 't', 'i', 'o', 'n', 's', '\022', +'t', 'r', 'e', 'a', 'm', 'i', 'n', 'g', '\"', '\227', '\t', '\n', '\013', 'F', 'i', 'l', 'e', 'O', 'p', 't', 'i', 'o', 'n', 's', '\022', '!', '\n', '\014', 'j', 'a', 'v', 'a', '_', 'p', 'a', 'c', 'k', 'a', 'g', 'e', '\030', '\001', ' ', '\001', '(', '\t', 'R', '\013', 'j', 'a', 'v', 'a', 'P', 'a', 'c', 'k', 'a', 'g', 'e', '\022', '0', '\n', '\024', 'j', 'a', 'v', 'a', '_', 'o', 'u', 't', 'e', 'r', '_', 'c', 'l', 'a', 's', 's', 'n', 'a', 'm', 'e', '\030', '\010', ' ', '\001', '(', '\t', 'R', '\022', 'j', 'a', 'v', 'a', 'O', 'u', 't', 'e', 'r', @@ -1934,286 +1933,284 @@ static const char descriptor[11646] = {'\n', ' ', 'g', 'o', 'o', 'g', 'l', 'e', 'l', 's', 'e', 'R', '\023', 'j', 'a', 'v', 'a', 'G', 'e', 'n', 'e', 'r', 'i', 'c', 'S', 'e', 'r', 'v', 'i', 'c', 'e', 's', '\022', '5', '\n', '\023', 'p', 'y', '_', 'g', 'e', 'n', 'e', 'r', 'i', 'c', '_', 's', 'e', 'r', 'v', 'i', 'c', 'e', 's', '\030', '\022', ' ', '\001', '(', '\010', ':', '\005', 'f', 'a', 'l', 's', 'e', 'R', '\021', 'p', 'y', 'G', 'e', 'n', 'e', 'r', 'i', 'c', 'S', 'e', 'r', 'v', -'i', 'c', 'e', 's', '\022', '7', '\n', '\024', 'p', 'h', 'p', '_', 'g', 'e', 'n', 'e', 'r', 'i', 'c', '_', 's', 'e', 'r', 'v', 'i', -'c', 'e', 's', '\030', '*', ' ', '\001', '(', '\010', ':', '\005', 'f', 'a', 'l', 's', 'e', 'R', '\022', 'p', 'h', 'p', 'G', 'e', 'n', 'e', -'r', 'i', 'c', 'S', 'e', 'r', 'v', 'i', 'c', 'e', 's', '\022', '%', '\n', '\n', 'd', 'e', 'p', 'r', 'e', 'c', 'a', 't', 'e', 'd', -'\030', '\027', ' ', '\001', '(', '\010', ':', '\005', 'f', 'a', 'l', 's', 'e', 'R', '\n', 'd', 'e', 'p', 'r', 'e', 'c', 'a', 't', 'e', 'd', -'\022', '.', '\n', '\020', 'c', 'c', '_', 'e', 'n', 'a', 'b', 'l', 'e', '_', 'a', 'r', 'e', 'n', 'a', 's', '\030', '\037', ' ', '\001', '(', -'\010', ':', '\004', 't', 'r', 'u', 'e', 'R', '\016', 'c', 'c', 'E', 'n', 'a', 'b', 'l', 'e', 'A', 'r', 'e', 'n', 'a', 's', '\022', '*', -'\n', '\021', 'o', 'b', 'j', 'c', '_', 'c', 'l', 'a', 's', 's', '_', 'p', 'r', 'e', 'f', 'i', 'x', '\030', '$', ' ', '\001', '(', '\t', -'R', '\017', 'o', 'b', 'j', 'c', 'C', 'l', 'a', 's', 's', 'P', 'r', 'e', 'f', 'i', 'x', '\022', ')', '\n', '\020', 'c', 's', 'h', 'a', -'r', 'p', '_', 'n', 'a', 'm', 'e', 's', 'p', 'a', 'c', 'e', '\030', '%', ' ', '\001', '(', '\t', 'R', '\017', 'c', 's', 'h', 'a', 'r', -'p', 'N', 'a', 'm', 'e', 's', 'p', 'a', 'c', 'e', '\022', '!', '\n', '\014', 's', 'w', 'i', 'f', 't', '_', 'p', 'r', 'e', 'f', 'i', -'x', '\030', '\'', ' ', '\001', '(', '\t', 'R', '\013', 's', 'w', 'i', 'f', 't', 'P', 'r', 'e', 'f', 'i', 'x', '\022', '(', '\n', '\020', 'p', -'h', 'p', '_', 'c', 'l', 'a', 's', 's', '_', 'p', 'r', 'e', 'f', 'i', 'x', '\030', '(', ' ', '\001', '(', '\t', 'R', '\016', 'p', 'h', -'p', 'C', 'l', 'a', 's', 's', 'P', 'r', 'e', 'f', 'i', 'x', '\022', '#', '\n', '\r', 'p', 'h', 'p', '_', 'n', 'a', 'm', 'e', 's', -'p', 'a', 'c', 'e', '\030', ')', ' ', '\001', '(', '\t', 'R', '\014', 'p', 'h', 'p', 'N', 'a', 'm', 'e', 's', 'p', 'a', 'c', 'e', '\022', -'4', '\n', '\026', 'p', 'h', 'p', '_', 'm', 'e', 't', 'a', 'd', 'a', 't', 'a', '_', 'n', 'a', 'm', 'e', 's', 'p', 'a', 'c', 'e', -'\030', ',', ' ', '\001', '(', '\t', 'R', '\024', 'p', 'h', 'p', 'M', 'e', 't', 'a', 'd', 'a', 't', 'a', 'N', 'a', 'm', 'e', 's', 'p', -'a', 'c', 'e', '\022', '!', '\n', '\014', 'r', 'u', 'b', 'y', '_', 'p', 'a', 'c', 'k', 'a', 'g', 'e', '\030', '-', ' ', '\001', '(', '\t', -'R', '\013', 'r', 'u', 'b', 'y', 'P', 'a', 'c', 'k', 'a', 'g', 'e', '\022', '7', '\n', '\010', 'f', 'e', 'a', 't', 'u', 'r', 'e', 's', -'\030', '2', ' ', '\001', '(', '\013', '2', '\033', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', -'F', 'e', 'a', 't', 'u', 'r', 'e', 'S', 'e', 't', 'R', '\010', 'f', 'e', 'a', 't', 'u', 'r', 'e', 's', '\022', 'X', '\n', '\024', 'u', -'n', 'i', 'n', 't', 'e', 'r', 'p', 'r', 'e', 't', 'e', 'd', '_', 'o', 'p', 't', 'i', 'o', 'n', '\030', '\347', '\007', ' ', '\003', '(', -'\013', '2', '$', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'U', 'n', 'i', 'n', 't', -'e', 'r', 'p', 'r', 'e', 't', 'e', 'd', 'O', 'p', 't', 'i', 'o', 'n', 'R', '\023', 'u', 'n', 'i', 'n', 't', 'e', 'r', 'p', 'r', -'e', 't', 'e', 'd', 'O', 'p', 't', 'i', 'o', 'n', '\"', ':', '\n', '\014', 'O', 'p', 't', 'i', 'm', 'i', 'z', 'e', 'M', 'o', 'd', -'e', '\022', '\t', '\n', '\005', 'S', 'P', 'E', 'E', 'D', '\020', '\001', '\022', '\r', '\n', '\t', 'C', 'O', 'D', 'E', '_', 'S', 'I', 'Z', 'E', -'\020', '\002', '\022', '\020', '\n', '\014', 'L', 'I', 'T', 'E', '_', 'R', 'U', 'N', 'T', 'I', 'M', 'E', '\020', '\003', '*', '\t', '\010', '\350', '\007', -'\020', '\200', '\200', '\200', '\200', '\002', 'J', '\004', '\010', '&', '\020', '\'', '\"', '\364', '\003', '\n', '\016', 'M', 'e', 's', 's', 'a', 'g', 'e', 'O', -'p', 't', 'i', 'o', 'n', 's', '\022', '<', '\n', '\027', 'm', 'e', 's', 's', 'a', 'g', 'e', '_', 's', 'e', 't', '_', 'w', 'i', 'r', -'e', '_', 'f', 'o', 'r', 'm', 'a', 't', '\030', '\001', ' ', '\001', '(', '\010', ':', '\005', 'f', 'a', 'l', 's', 'e', 'R', '\024', 'm', 'e', -'s', 's', 'a', 'g', 'e', 'S', 'e', 't', 'W', 'i', 'r', 'e', 'F', 'o', 'r', 'm', 'a', 't', '\022', 'L', '\n', '\037', 'n', 'o', '_', -'s', 't', 'a', 'n', 'd', 'a', 'r', 'd', '_', 'd', 'e', 's', 'c', 'r', 'i', 'p', 't', 'o', 'r', '_', 'a', 'c', 'c', 'e', 's', -'s', 'o', 'r', '\030', '\002', ' ', '\001', '(', '\010', ':', '\005', 'f', 'a', 'l', 's', 'e', 'R', '\034', 'n', 'o', 'S', 't', 'a', 'n', 'd', -'a', 'r', 'd', 'D', 'e', 's', 'c', 'r', 'i', 'p', 't', 'o', 'r', 'A', 'c', 'c', 'e', 's', 's', 'o', 'r', '\022', '%', '\n', '\n', -'d', 'e', 'p', 'r', 'e', 'c', 'a', 't', 'e', 'd', '\030', '\003', ' ', '\001', '(', '\010', ':', '\005', 'f', 'a', 'l', 's', 'e', 'R', '\n', -'d', 'e', 'p', 'r', 'e', 'c', 'a', 't', 'e', 'd', '\022', '\033', '\n', '\t', 'm', 'a', 'p', '_', 'e', 'n', 't', 'r', 'y', '\030', '\007', -' ', '\001', '(', '\010', 'R', '\010', 'm', 'a', 'p', 'E', 'n', 't', 'r', 'y', '\022', 'V', '\n', '&', 'd', 'e', 'p', 'r', 'e', 'c', 'a', -'t', 'e', 'd', '_', 'l', 'e', 'g', 'a', 'c', 'y', '_', 'j', 's', 'o', 'n', '_', 'f', 'i', 'e', 'l', 'd', '_', 'c', 'o', 'n', -'f', 'l', 'i', 'c', 't', 's', '\030', '\013', ' ', '\001', '(', '\010', 'B', '\002', '\030', '\001', 'R', '\"', 'd', 'e', 'p', 'r', 'e', 'c', 'a', -'t', 'e', 'd', 'L', 'e', 'g', 'a', 'c', 'y', 'J', 's', 'o', 'n', 'F', 'i', 'e', 'l', 'd', 'C', 'o', 'n', 'f', 'l', 'i', 'c', -'t', 's', '\022', '7', '\n', '\010', 'f', 'e', 'a', 't', 'u', 'r', 'e', 's', '\030', '\014', ' ', '\001', '(', '\013', '2', '\033', '.', 'g', 'o', -'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'F', 'e', 'a', 't', 'u', 'r', 'e', 'S', 'e', 't', 'R', -'\010', 'f', 'e', 'a', 't', 'u', 'r', 'e', 's', '\022', 'X', '\n', '\024', 'u', 'n', 'i', 'n', 't', 'e', 'r', 'p', 'r', 'e', 't', 'e', -'d', '_', 'o', 'p', 't', 'i', 'o', 'n', '\030', '\347', '\007', ' ', '\003', '(', '\013', '2', '$', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', -'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'U', 'n', 'i', 'n', 't', 'e', 'r', 'p', 'r', 'e', 't', 'e', 'd', 'O', 'p', 't', -'i', 'o', 'n', 'R', '\023', 'u', 'n', 'i', 'n', 't', 'e', 'r', 'p', 'r', 'e', 't', 'e', 'd', 'O', 'p', 't', 'i', 'o', 'n', '*', -'\t', '\010', '\350', '\007', '\020', '\200', '\200', '\200', '\200', '\002', 'J', '\004', '\010', '\004', '\020', '\005', 'J', '\004', '\010', '\005', '\020', '\006', 'J', '\004', '\010', -'\006', '\020', '\007', 'J', '\004', '\010', '\010', '\020', '\t', 'J', '\004', '\010', '\t', '\020', '\n', '\"', '\255', '\n', '\n', '\014', 'F', 'i', 'e', 'l', 'd', -'O', 'p', 't', 'i', 'o', 'n', 's', '\022', 'A', '\n', '\005', 'c', 't', 'y', 'p', 'e', '\030', '\001', ' ', '\001', '(', '\016', '2', '#', '.', -'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'F', 'i', 'e', 'l', 'd', 'O', 'p', 't', 'i', -'o', 'n', 's', '.', 'C', 'T', 'y', 'p', 'e', ':', '\006', 'S', 'T', 'R', 'I', 'N', 'G', 'R', '\005', 'c', 't', 'y', 'p', 'e', '\022', -'\026', '\n', '\006', 'p', 'a', 'c', 'k', 'e', 'd', '\030', '\002', ' ', '\001', '(', '\010', 'R', '\006', 'p', 'a', 'c', 'k', 'e', 'd', '\022', 'G', -'\n', '\006', 'j', 's', 't', 'y', 'p', 'e', '\030', '\006', ' ', '\001', '(', '\016', '2', '$', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', -'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'F', 'i', 'e', 'l', 'd', 'O', 'p', 't', 'i', 'o', 'n', 's', '.', 'J', 'S', 'T', 'y', -'p', 'e', ':', '\t', 'J', 'S', '_', 'N', 'O', 'R', 'M', 'A', 'L', 'R', '\006', 'j', 's', 't', 'y', 'p', 'e', '\022', '\031', '\n', '\004', -'l', 'a', 'z', 'y', '\030', '\005', ' ', '\001', '(', '\010', ':', '\005', 'f', 'a', 'l', 's', 'e', 'R', '\004', 'l', 'a', 'z', 'y', '\022', '.', -'\n', '\017', 'u', 'n', 'v', 'e', 'r', 'i', 'f', 'i', 'e', 'd', '_', 'l', 'a', 'z', 'y', '\030', '\017', ' ', '\001', '(', '\010', ':', '\005', -'f', 'a', 'l', 's', 'e', 'R', '\016', 'u', 'n', 'v', 'e', 'r', 'i', 'f', 'i', 'e', 'd', 'L', 'a', 'z', 'y', '\022', '%', '\n', '\n', -'d', 'e', 'p', 'r', 'e', 'c', 'a', 't', 'e', 'd', '\030', '\003', ' ', '\001', '(', '\010', ':', '\005', 'f', 'a', 'l', 's', 'e', 'R', '\n', -'d', 'e', 'p', 'r', 'e', 'c', 'a', 't', 'e', 'd', '\022', '\031', '\n', '\004', 'w', 'e', 'a', 'k', '\030', '\n', ' ', '\001', '(', '\010', ':', -'\005', 'f', 'a', 'l', 's', 'e', 'R', '\004', 'w', 'e', 'a', 'k', '\022', '(', '\n', '\014', 'd', 'e', 'b', 'u', 'g', '_', 'r', 'e', 'd', -'a', 'c', 't', '\030', '\020', ' ', '\001', '(', '\010', ':', '\005', 'f', 'a', 'l', 's', 'e', 'R', '\013', 'd', 'e', 'b', 'u', 'g', 'R', 'e', -'d', 'a', 'c', 't', '\022', 'K', '\n', '\t', 'r', 'e', 't', 'e', 'n', 't', 'i', 'o', 'n', '\030', '\021', ' ', '\001', '(', '\016', '2', '-', -'.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'F', 'i', 'e', 'l', 'd', 'O', 'p', 't', -'i', 'o', 'n', 's', '.', 'O', 'p', 't', 'i', 'o', 'n', 'R', 'e', 't', 'e', 'n', 't', 'i', 'o', 'n', 'R', '\t', 'r', 'e', 't', -'e', 'n', 't', 'i', 'o', 'n', '\022', 'H', '\n', '\007', 't', 'a', 'r', 'g', 'e', 't', 's', '\030', '\023', ' ', '\003', '(', '\016', '2', '.', -'.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'F', 'i', 'e', 'l', 'd', 'O', 'p', 't', -'i', 'o', 'n', 's', '.', 'O', 'p', 't', 'i', 'o', 'n', 'T', 'a', 'r', 'g', 'e', 't', 'T', 'y', 'p', 'e', 'R', '\007', 't', 'a', -'r', 'g', 'e', 't', 's', '\022', 'W', '\n', '\020', 'e', 'd', 'i', 't', 'i', 'o', 'n', '_', 'd', 'e', 'f', 'a', 'u', 'l', 't', 's', -'\030', '\024', ' ', '\003', '(', '\013', '2', ',', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', -'F', 'i', 'e', 'l', 'd', 'O', 'p', 't', 'i', 'o', 'n', 's', '.', 'E', 'd', 'i', 't', 'i', 'o', 'n', 'D', 'e', 'f', 'a', 'u', -'l', 't', 'R', '\017', 'e', 'd', 'i', 't', 'i', 'o', 'n', 'D', 'e', 'f', 'a', 'u', 'l', 't', 's', '\022', '7', '\n', '\010', 'f', 'e', -'a', 't', 'u', 'r', 'e', 's', '\030', '\025', ' ', '\001', '(', '\013', '2', '\033', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', -'t', 'o', 'b', 'u', 'f', '.', 'F', 'e', 'a', 't', 'u', 'r', 'e', 'S', 'e', 't', 'R', '\010', 'f', 'e', 'a', 't', 'u', 'r', 'e', -'s', '\022', 'X', '\n', '\024', 'u', 'n', 'i', 'n', 't', 'e', 'r', 'p', 'r', 'e', 't', 'e', 'd', '_', 'o', 'p', 't', 'i', 'o', 'n', -'\030', '\347', '\007', ' ', '\003', '(', '\013', '2', '$', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', -'.', 'U', 'n', 'i', 'n', 't', 'e', 'r', 'p', 'r', 'e', 't', 'e', 'd', 'O', 'p', 't', 'i', 'o', 'n', 'R', '\023', 'u', 'n', 'i', -'n', 't', 'e', 'r', 'p', 'r', 'e', 't', 'e', 'd', 'O', 'p', 't', 'i', 'o', 'n', '\032', 'Z', '\n', '\016', 'E', 'd', 'i', 't', 'i', -'o', 'n', 'D', 'e', 'f', 'a', 'u', 'l', 't', '\022', '2', '\n', '\007', 'e', 'd', 'i', 't', 'i', 'o', 'n', '\030', '\003', ' ', '\001', '(', -'\016', '2', '\030', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'E', 'd', 'i', 't', 'i', -'o', 'n', 'R', '\007', 'e', 'd', 'i', 't', 'i', 'o', 'n', '\022', '\024', '\n', '\005', 'v', 'a', 'l', 'u', 'e', '\030', '\002', ' ', '\001', '(', -'\t', 'R', '\005', 'v', 'a', 'l', 'u', 'e', '\"', '/', '\n', '\005', 'C', 'T', 'y', 'p', 'e', '\022', '\n', '\n', '\006', 'S', 'T', 'R', 'I', -'N', 'G', '\020', '\000', '\022', '\010', '\n', '\004', 'C', 'O', 'R', 'D', '\020', '\001', '\022', '\020', '\n', '\014', 'S', 'T', 'R', 'I', 'N', 'G', '_', -'P', 'I', 'E', 'C', 'E', '\020', '\002', '\"', '5', '\n', '\006', 'J', 'S', 'T', 'y', 'p', 'e', '\022', '\r', '\n', '\t', 'J', 'S', '_', 'N', -'O', 'R', 'M', 'A', 'L', '\020', '\000', '\022', '\r', '\n', '\t', 'J', 'S', '_', 'S', 'T', 'R', 'I', 'N', 'G', '\020', '\001', '\022', '\r', '\n', -'\t', 'J', 'S', '_', 'N', 'U', 'M', 'B', 'E', 'R', '\020', '\002', '\"', 'U', '\n', '\017', 'O', 'p', 't', 'i', 'o', 'n', 'R', 'e', 't', -'e', 'n', 't', 'i', 'o', 'n', '\022', '\025', '\n', '\021', 'R', 'E', 'T', 'E', 'N', 'T', 'I', 'O', 'N', '_', 'U', 'N', 'K', 'N', 'O', -'W', 'N', '\020', '\000', '\022', '\025', '\n', '\021', 'R', 'E', 'T', 'E', 'N', 'T', 'I', 'O', 'N', '_', 'R', 'U', 'N', 'T', 'I', 'M', 'E', -'\020', '\001', '\022', '\024', '\n', '\020', 'R', 'E', 'T', 'E', 'N', 'T', 'I', 'O', 'N', '_', 'S', 'O', 'U', 'R', 'C', 'E', '\020', '\002', '\"', -'\214', '\002', '\n', '\020', 'O', 'p', 't', 'i', 'o', 'n', 'T', 'a', 'r', 'g', 'e', 't', 'T', 'y', 'p', 'e', '\022', '\027', '\n', '\023', 'T', -'A', 'R', 'G', 'E', 'T', '_', 'T', 'Y', 'P', 'E', '_', 'U', 'N', 'K', 'N', 'O', 'W', 'N', '\020', '\000', '\022', '\024', '\n', '\020', 'T', -'A', 'R', 'G', 'E', 'T', '_', 'T', 'Y', 'P', 'E', '_', 'F', 'I', 'L', 'E', '\020', '\001', '\022', '\037', '\n', '\033', 'T', 'A', 'R', 'G', -'E', 'T', '_', 'T', 'Y', 'P', 'E', '_', 'E', 'X', 'T', 'E', 'N', 'S', 'I', 'O', 'N', '_', 'R', 'A', 'N', 'G', 'E', '\020', '\002', -'\022', '\027', '\n', '\023', 'T', 'A', 'R', 'G', 'E', 'T', '_', 'T', 'Y', 'P', 'E', '_', 'M', 'E', 'S', 'S', 'A', 'G', 'E', '\020', '\003', -'\022', '\025', '\n', '\021', 'T', 'A', 'R', 'G', 'E', 'T', '_', 'T', 'Y', 'P', 'E', '_', 'F', 'I', 'E', 'L', 'D', '\020', '\004', '\022', '\025', -'\n', '\021', 'T', 'A', 'R', 'G', 'E', 'T', '_', 'T', 'Y', 'P', 'E', '_', 'O', 'N', 'E', 'O', 'F', '\020', '\005', '\022', '\024', '\n', '\020', -'T', 'A', 'R', 'G', 'E', 'T', '_', 'T', 'Y', 'P', 'E', '_', 'E', 'N', 'U', 'M', '\020', '\006', '\022', '\032', '\n', '\026', 'T', 'A', 'R', -'G', 'E', 'T', '_', 'T', 'Y', 'P', 'E', '_', 'E', 'N', 'U', 'M', '_', 'E', 'N', 'T', 'R', 'Y', '\020', '\007', '\022', '\027', '\n', '\023', -'T', 'A', 'R', 'G', 'E', 'T', '_', 'T', 'Y', 'P', 'E', '_', 'S', 'E', 'R', 'V', 'I', 'C', 'E', '\020', '\010', '\022', '\026', '\n', '\022', -'T', 'A', 'R', 'G', 'E', 'T', '_', 'T', 'Y', 'P', 'E', '_', 'M', 'E', 'T', 'H', 'O', 'D', '\020', '\t', '*', '\t', '\010', '\350', '\007', -'\020', '\200', '\200', '\200', '\200', '\002', 'J', '\004', '\010', '\004', '\020', '\005', 'J', '\004', '\010', '\022', '\020', '\023', '\"', '\254', '\001', '\n', '\014', 'O', 'n', -'e', 'o', 'f', 'O', 'p', 't', 'i', 'o', 'n', 's', '\022', '7', '\n', '\010', 'f', 'e', 'a', 't', 'u', 'r', 'e', 's', '\030', '\001', ' ', -'\001', '(', '\013', '2', '\033', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'F', 'e', 'a', -'t', 'u', 'r', 'e', 'S', 'e', 't', 'R', '\010', 'f', 'e', 'a', 't', 'u', 'r', 'e', 's', '\022', 'X', '\n', '\024', 'u', 'n', 'i', 'n', -'t', 'e', 'r', 'p', 'r', 'e', 't', 'e', 'd', '_', 'o', 'p', 't', 'i', 'o', 'n', '\030', '\347', '\007', ' ', '\003', '(', '\013', '2', '$', -'.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'U', 'n', 'i', 'n', 't', 'e', 'r', 'p', -'r', 'e', 't', 'e', 'd', 'O', 'p', 't', 'i', 'o', 'n', 'R', '\023', 'u', 'n', 'i', 'n', 't', 'e', 'r', 'p', 'r', 'e', 't', 'e', -'d', 'O', 'p', 't', 'i', 'o', 'n', '*', '\t', '\010', '\350', '\007', '\020', '\200', '\200', '\200', '\200', '\002', '\"', '\321', '\002', '\n', '\013', 'E', 'n', -'u', 'm', 'O', 'p', 't', 'i', 'o', 'n', 's', '\022', '\037', '\n', '\013', 'a', 'l', 'l', 'o', 'w', '_', 'a', 'l', 'i', 'a', 's', '\030', -'\002', ' ', '\001', '(', '\010', 'R', '\n', 'a', 'l', 'l', 'o', 'w', 'A', 'l', 'i', 'a', 's', '\022', '%', '\n', '\n', 'd', 'e', 'p', 'r', -'e', 'c', 'a', 't', 'e', 'd', '\030', '\003', ' ', '\001', '(', '\010', ':', '\005', 'f', 'a', 'l', 's', 'e', 'R', '\n', 'd', 'e', 'p', 'r', -'e', 'c', 'a', 't', 'e', 'd', '\022', 'V', '\n', '&', 'd', 'e', 'p', 'r', 'e', 'c', 'a', 't', 'e', 'd', '_', 'l', 'e', 'g', 'a', -'c', 'y', '_', 'j', 's', 'o', 'n', '_', 'f', 'i', 'e', 'l', 'd', '_', 'c', 'o', 'n', 'f', 'l', 'i', 'c', 't', 's', '\030', '\006', -' ', '\001', '(', '\010', 'B', '\002', '\030', '\001', 'R', '\"', 'd', 'e', 'p', 'r', 'e', 'c', 'a', 't', 'e', 'd', 'L', 'e', 'g', 'a', 'c', -'y', 'J', 's', 'o', 'n', 'F', 'i', 'e', 'l', 'd', 'C', 'o', 'n', 'f', 'l', 'i', 'c', 't', 's', '\022', '7', '\n', '\010', 'f', 'e', -'a', 't', 'u', 'r', 'e', 's', '\030', '\007', ' ', '\001', '(', '\013', '2', '\033', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', -'t', 'o', 'b', 'u', 'f', '.', 'F', 'e', 'a', 't', 'u', 'r', 'e', 'S', 'e', 't', 'R', '\010', 'f', 'e', 'a', 't', 'u', 'r', 'e', -'s', '\022', 'X', '\n', '\024', 'u', 'n', 'i', 'n', 't', 'e', 'r', 'p', 'r', 'e', 't', 'e', 'd', '_', 'o', 'p', 't', 'i', 'o', 'n', -'\030', '\347', '\007', ' ', '\003', '(', '\013', '2', '$', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', -'.', 'U', 'n', 'i', 'n', 't', 'e', 'r', 'p', 'r', 'e', 't', 'e', 'd', 'O', 'p', 't', 'i', 'o', 'n', 'R', '\023', 'u', 'n', 'i', -'n', 't', 'e', 'r', 'p', 'r', 'e', 't', 'e', 'd', 'O', 'p', 't', 'i', 'o', 'n', '*', '\t', '\010', '\350', '\007', '\020', '\200', '\200', '\200', -'\200', '\002', 'J', '\004', '\010', '\005', '\020', '\006', '\"', '\201', '\002', '\n', '\020', 'E', 'n', 'u', 'm', 'V', 'a', 'l', 'u', 'e', 'O', 'p', 't', -'i', 'o', 'n', 's', '\022', '%', '\n', '\n', 'd', 'e', 'p', 'r', 'e', 'c', 'a', 't', 'e', 'd', '\030', '\001', ' ', '\001', '(', '\010', ':', -'\005', 'f', 'a', 'l', 's', 'e', 'R', '\n', 'd', 'e', 'p', 'r', 'e', 'c', 'a', 't', 'e', 'd', '\022', '7', '\n', '\010', 'f', 'e', 'a', -'t', 'u', 'r', 'e', 's', '\030', '\002', ' ', '\001', '(', '\013', '2', '\033', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', -'o', 'b', 'u', 'f', '.', 'F', 'e', 'a', 't', 'u', 'r', 'e', 'S', 'e', 't', 'R', '\010', 'f', 'e', 'a', 't', 'u', 'r', 'e', 's', -'\022', '(', '\n', '\014', 'd', 'e', 'b', 'u', 'g', '_', 'r', 'e', 'd', 'a', 'c', 't', '\030', '\003', ' ', '\001', '(', '\010', ':', '\005', 'f', -'a', 'l', 's', 'e', 'R', '\013', 'd', 'e', 'b', 'u', 'g', 'R', 'e', 'd', 'a', 'c', 't', '\022', 'X', '\n', '\024', 'u', 'n', 'i', 'n', -'t', 'e', 'r', 'p', 'r', 'e', 't', 'e', 'd', '_', 'o', 'p', 't', 'i', 'o', 'n', '\030', '\347', '\007', ' ', '\003', '(', '\013', '2', '$', -'.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'U', 'n', 'i', 'n', 't', 'e', 'r', 'p', -'r', 'e', 't', 'e', 'd', 'O', 'p', 't', 'i', 'o', 'n', 'R', '\023', 'u', 'n', 'i', 'n', 't', 'e', 'r', 'p', 'r', 'e', 't', 'e', -'d', 'O', 'p', 't', 'i', 'o', 'n', '*', '\t', '\010', '\350', '\007', '\020', '\200', '\200', '\200', '\200', '\002', '\"', '\325', '\001', '\n', '\016', 'S', 'e', -'r', 'v', 'i', 'c', 'e', 'O', 'p', 't', 'i', 'o', 'n', 's', '\022', '7', '\n', '\010', 'f', 'e', 'a', 't', 'u', 'r', 'e', 's', '\030', -'\"', ' ', '\001', '(', '\013', '2', '\033', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'F', -'e', 'a', 't', 'u', 'r', 'e', 'S', 'e', 't', 'R', '\010', 'f', 'e', 'a', 't', 'u', 'r', 'e', 's', '\022', '%', '\n', '\n', 'd', 'e', -'p', 'r', 'e', 'c', 'a', 't', 'e', 'd', '\030', '!', ' ', '\001', '(', '\010', ':', '\005', 'f', 'a', 'l', 's', 'e', 'R', '\n', 'd', 'e', -'p', 'r', 'e', 'c', 'a', 't', 'e', 'd', '\022', 'X', '\n', '\024', 'u', 'n', 'i', 'n', 't', 'e', 'r', 'p', 'r', 'e', 't', 'e', 'd', -'_', 'o', 'p', 't', 'i', 'o', 'n', '\030', '\347', '\007', ' ', '\003', '(', '\013', '2', '$', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', -'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'U', 'n', 'i', 'n', 't', 'e', 'r', 'p', 'r', 'e', 't', 'e', 'd', 'O', 'p', 't', 'i', -'o', 'n', 'R', '\023', 'u', 'n', 'i', 'n', 't', 'e', 'r', 'p', 'r', 'e', 't', 'e', 'd', 'O', 'p', 't', 'i', 'o', 'n', '*', '\t', -'\010', '\350', '\007', '\020', '\200', '\200', '\200', '\200', '\002', '\"', '\231', '\003', '\n', '\r', 'M', 'e', 't', 'h', 'o', 'd', 'O', 'p', 't', 'i', 'o', -'n', 's', '\022', '%', '\n', '\n', 'd', 'e', 'p', 'r', 'e', 'c', 'a', 't', 'e', 'd', '\030', '!', ' ', '\001', '(', '\010', ':', '\005', 'f', -'a', 'l', 's', 'e', 'R', '\n', 'd', 'e', 'p', 'r', 'e', 'c', 'a', 't', 'e', 'd', '\022', 'q', '\n', '\021', 'i', 'd', 'e', 'm', 'p', -'o', 't', 'e', 'n', 'c', 'y', '_', 'l', 'e', 'v', 'e', 'l', '\030', '\"', ' ', '\001', '(', '\016', '2', '/', '.', 'g', 'o', 'o', 'g', -'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'M', 'e', 't', 'h', 'o', 'd', 'O', 'p', 't', 'i', 'o', 'n', 's', -'.', 'I', 'd', 'e', 'm', 'p', 'o', 't', 'e', 'n', 'c', 'y', 'L', 'e', 'v', 'e', 'l', ':', '\023', 'I', 'D', 'E', 'M', 'P', 'O', -'T', 'E', 'N', 'C', 'Y', '_', 'U', 'N', 'K', 'N', 'O', 'W', 'N', 'R', '\020', 'i', 'd', 'e', 'm', 'p', 'o', 't', 'e', 'n', 'c', -'y', 'L', 'e', 'v', 'e', 'l', '\022', '7', '\n', '\010', 'f', 'e', 'a', 't', 'u', 'r', 'e', 's', '\030', '#', ' ', '\001', '(', '\013', '2', +'i', 'c', 'e', 's', '\022', '%', '\n', '\n', 'd', 'e', 'p', 'r', 'e', 'c', 'a', 't', 'e', 'd', '\030', '\027', ' ', '\001', '(', '\010', ':', +'\005', 'f', 'a', 'l', 's', 'e', 'R', '\n', 'd', 'e', 'p', 'r', 'e', 'c', 'a', 't', 'e', 'd', '\022', '.', '\n', '\020', 'c', 'c', '_', +'e', 'n', 'a', 'b', 'l', 'e', '_', 'a', 'r', 'e', 'n', 'a', 's', '\030', '\037', ' ', '\001', '(', '\010', ':', '\004', 't', 'r', 'u', 'e', +'R', '\016', 'c', 'c', 'E', 'n', 'a', 'b', 'l', 'e', 'A', 'r', 'e', 'n', 'a', 's', '\022', '*', '\n', '\021', 'o', 'b', 'j', 'c', '_', +'c', 'l', 'a', 's', 's', '_', 'p', 'r', 'e', 'f', 'i', 'x', '\030', '$', ' ', '\001', '(', '\t', 'R', '\017', 'o', 'b', 'j', 'c', 'C', +'l', 'a', 's', 's', 'P', 'r', 'e', 'f', 'i', 'x', '\022', ')', '\n', '\020', 'c', 's', 'h', 'a', 'r', 'p', '_', 'n', 'a', 'm', 'e', +'s', 'p', 'a', 'c', 'e', '\030', '%', ' ', '\001', '(', '\t', 'R', '\017', 'c', 's', 'h', 'a', 'r', 'p', 'N', 'a', 'm', 'e', 's', 'p', +'a', 'c', 'e', '\022', '!', '\n', '\014', 's', 'w', 'i', 'f', 't', '_', 'p', 'r', 'e', 'f', 'i', 'x', '\030', '\'', ' ', '\001', '(', '\t', +'R', '\013', 's', 'w', 'i', 'f', 't', 'P', 'r', 'e', 'f', 'i', 'x', '\022', '(', '\n', '\020', 'p', 'h', 'p', '_', 'c', 'l', 'a', 's', +'s', '_', 'p', 'r', 'e', 'f', 'i', 'x', '\030', '(', ' ', '\001', '(', '\t', 'R', '\016', 'p', 'h', 'p', 'C', 'l', 'a', 's', 's', 'P', +'r', 'e', 'f', 'i', 'x', '\022', '#', '\n', '\r', 'p', 'h', 'p', '_', 'n', 'a', 'm', 'e', 's', 'p', 'a', 'c', 'e', '\030', ')', ' ', +'\001', '(', '\t', 'R', '\014', 'p', 'h', 'p', 'N', 'a', 'm', 'e', 's', 'p', 'a', 'c', 'e', '\022', '4', '\n', '\026', 'p', 'h', 'p', '_', +'m', 'e', 't', 'a', 'd', 'a', 't', 'a', '_', 'n', 'a', 'm', 'e', 's', 'p', 'a', 'c', 'e', '\030', ',', ' ', '\001', '(', '\t', 'R', +'\024', 'p', 'h', 'p', 'M', 'e', 't', 'a', 'd', 'a', 't', 'a', 'N', 'a', 'm', 'e', 's', 'p', 'a', 'c', 'e', '\022', '!', '\n', '\014', +'r', 'u', 'b', 'y', '_', 'p', 'a', 'c', 'k', 'a', 'g', 'e', '\030', '-', ' ', '\001', '(', '\t', 'R', '\013', 'r', 'u', 'b', 'y', 'P', +'a', 'c', 'k', 'a', 'g', 'e', '\022', '7', '\n', '\010', 'f', 'e', 'a', 't', 'u', 'r', 'e', 's', '\030', '2', ' ', '\001', '(', '\013', '2', '\033', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'F', 'e', 'a', 't', 'u', 'r', 'e', 'S', 'e', 't', 'R', '\010', 'f', 'e', 'a', 't', 'u', 'r', 'e', 's', '\022', 'X', '\n', '\024', 'u', 'n', 'i', 'n', 't', 'e', 'r', 'p', 'r', 'e', 't', 'e', 'd', '_', 'o', 'p', 't', 'i', 'o', 'n', '\030', '\347', '\007', ' ', '\003', '(', '\013', '2', '$', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'U', 'n', 'i', 'n', 't', 'e', 'r', 'p', 'r', 'e', 't', 'e', 'd', 'O', 'p', 't', 'i', 'o', 'n', 'R', '\023', 'u', 'n', 'i', 'n', 't', 'e', 'r', 'p', 'r', 'e', 't', 'e', 'd', 'O', 'p', 't', -'i', 'o', 'n', '\"', 'P', '\n', '\020', 'I', 'd', 'e', 'm', 'p', 'o', 't', 'e', 'n', 'c', 'y', 'L', 'e', 'v', 'e', 'l', '\022', '\027', -'\n', '\023', 'I', 'D', 'E', 'M', 'P', 'O', 'T', 'E', 'N', 'C', 'Y', '_', 'U', 'N', 'K', 'N', 'O', 'W', 'N', '\020', '\000', '\022', '\023', -'\n', '\017', 'N', 'O', '_', 'S', 'I', 'D', 'E', '_', 'E', 'F', 'F', 'E', 'C', 'T', 'S', '\020', '\001', '\022', '\016', '\n', '\n', 'I', 'D', -'E', 'M', 'P', 'O', 'T', 'E', 'N', 'T', '\020', '\002', '*', '\t', '\010', '\350', '\007', '\020', '\200', '\200', '\200', '\200', '\002', '\"', '\232', '\003', '\n', -'\023', 'U', 'n', 'i', 'n', 't', 'e', 'r', 'p', 'r', 'e', 't', 'e', 'd', 'O', 'p', 't', 'i', 'o', 'n', '\022', 'A', '\n', '\004', 'n', -'a', 'm', 'e', '\030', '\002', ' ', '\003', '(', '\013', '2', '-', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', -'u', 'f', '.', 'U', 'n', 'i', 'n', 't', 'e', 'r', 'p', 'r', 'e', 't', 'e', 'd', 'O', 'p', 't', 'i', 'o', 'n', '.', 'N', 'a', -'m', 'e', 'P', 'a', 'r', 't', 'R', '\004', 'n', 'a', 'm', 'e', '\022', ')', '\n', '\020', 'i', 'd', 'e', 'n', 't', 'i', 'f', 'i', 'e', -'r', '_', 'v', 'a', 'l', 'u', 'e', '\030', '\003', ' ', '\001', '(', '\t', 'R', '\017', 'i', 'd', 'e', 'n', 't', 'i', 'f', 'i', 'e', 'r', -'V', 'a', 'l', 'u', 'e', '\022', ',', '\n', '\022', 'p', 'o', 's', 'i', 't', 'i', 'v', 'e', '_', 'i', 'n', 't', '_', 'v', 'a', 'l', -'u', 'e', '\030', '\004', ' ', '\001', '(', '\004', 'R', '\020', 'p', 'o', 's', 'i', 't', 'i', 'v', 'e', 'I', 'n', 't', 'V', 'a', 'l', 'u', -'e', '\022', ',', '\n', '\022', 'n', 'e', 'g', 'a', 't', 'i', 'v', 'e', '_', 'i', 'n', 't', '_', 'v', 'a', 'l', 'u', 'e', '\030', '\005', -' ', '\001', '(', '\003', 'R', '\020', 'n', 'e', 'g', 'a', 't', 'i', 'v', 'e', 'I', 'n', 't', 'V', 'a', 'l', 'u', 'e', '\022', '!', '\n', -'\014', 'd', 'o', 'u', 'b', 'l', 'e', '_', 'v', 'a', 'l', 'u', 'e', '\030', '\006', ' ', '\001', '(', '\001', 'R', '\013', 'd', 'o', 'u', 'b', -'l', 'e', 'V', 'a', 'l', 'u', 'e', '\022', '!', '\n', '\014', 's', 't', 'r', 'i', 'n', 'g', '_', 'v', 'a', 'l', 'u', 'e', '\030', '\007', -' ', '\001', '(', '\014', 'R', '\013', 's', 't', 'r', 'i', 'n', 'g', 'V', 'a', 'l', 'u', 'e', '\022', '\'', '\n', '\017', 'a', 'g', 'g', 'r', -'e', 'g', 'a', 't', 'e', '_', 'v', 'a', 'l', 'u', 'e', '\030', '\010', ' ', '\001', '(', '\t', 'R', '\016', 'a', 'g', 'g', 'r', 'e', 'g', -'a', 't', 'e', 'V', 'a', 'l', 'u', 'e', '\032', 'J', '\n', '\010', 'N', 'a', 'm', 'e', 'P', 'a', 'r', 't', '\022', '\033', '\n', '\t', 'n', -'a', 'm', 'e', '_', 'p', 'a', 'r', 't', '\030', '\001', ' ', '\002', '(', '\t', 'R', '\010', 'n', 'a', 'm', 'e', 'P', 'a', 'r', 't', '\022', -'!', '\n', '\014', 'i', 's', '_', 'e', 'x', 't', 'e', 'n', 's', 'i', 'o', 'n', '\030', '\002', ' ', '\002', '(', '\010', 'R', '\013', 'i', 's', -'E', 'x', 't', 'e', 'n', 's', 'i', 'o', 'n', '\"', '\374', '\t', '\n', '\n', 'F', 'e', 'a', 't', 'u', 'r', 'e', 'S', 'e', 't', '\022', -'\213', '\001', '\n', '\016', 'f', 'i', 'e', 'l', 'd', '_', 'p', 'r', 'e', 's', 'e', 'n', 'c', 'e', '\030', '\001', ' ', '\001', '(', '\016', '2', -')', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'F', 'e', 'a', 't', 'u', 'r', 'e', -'S', 'e', 't', '.', 'F', 'i', 'e', 'l', 'd', 'P', 'r', 'e', 's', 'e', 'n', 'c', 'e', 'B', '9', '\210', '\001', '\001', '\230', '\001', '\004', -'\230', '\001', '\001', '\242', '\001', '\r', '\022', '\010', 'E', 'X', 'P', 'L', 'I', 'C', 'I', 'T', '\030', '\346', '\007', '\242', '\001', '\r', '\022', '\010', 'I', -'M', 'P', 'L', 'I', 'C', 'I', 'T', '\030', '\347', '\007', '\242', '\001', '\r', '\022', '\010', 'E', 'X', 'P', 'L', 'I', 'C', 'I', 'T', '\030', '\350', -'\007', 'R', '\r', 'f', 'i', 'e', 'l', 'd', 'P', 'r', 'e', 's', 'e', 'n', 'c', 'e', '\022', 'f', '\n', '\t', 'e', 'n', 'u', 'm', '_', -'t', 'y', 'p', 'e', '\030', '\002', ' ', '\001', '(', '\016', '2', '$', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', -'b', 'u', 'f', '.', 'F', 'e', 'a', 't', 'u', 'r', 'e', 'S', 'e', 't', '.', 'E', 'n', 'u', 'm', 'T', 'y', 'p', 'e', 'B', '#', -'\210', '\001', '\001', '\230', '\001', '\006', '\230', '\001', '\001', '\242', '\001', '\013', '\022', '\006', 'C', 'L', 'O', 'S', 'E', 'D', '\030', '\346', '\007', '\242', '\001', -'\t', '\022', '\004', 'O', 'P', 'E', 'N', '\030', '\347', '\007', 'R', '\010', 'e', 'n', 'u', 'm', 'T', 'y', 'p', 'e', '\022', '\222', '\001', '\n', '\027', -'r', 'e', 'p', 'e', 'a', 't', 'e', 'd', '_', 'f', 'i', 'e', 'l', 'd', '_', 'e', 'n', 'c', 'o', 'd', 'i', 'n', 'g', '\030', '\003', -' ', '\001', '(', '\016', '2', '1', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'F', 'e', -'a', 't', 'u', 'r', 'e', 'S', 'e', 't', '.', 'R', 'e', 'p', 'e', 'a', 't', 'e', 'd', 'F', 'i', 'e', 'l', 'd', 'E', 'n', 'c', -'o', 'd', 'i', 'n', 'g', 'B', '\'', '\210', '\001', '\001', '\230', '\001', '\004', '\230', '\001', '\001', '\242', '\001', '\r', '\022', '\010', 'E', 'X', 'P', 'A', -'N', 'D', 'E', 'D', '\030', '\346', '\007', '\242', '\001', '\013', '\022', '\006', 'P', 'A', 'C', 'K', 'E', 'D', '\030', '\347', '\007', 'R', '\025', 'r', 'e', -'p', 'e', 'a', 't', 'e', 'd', 'F', 'i', 'e', 'l', 'd', 'E', 'n', 'c', 'o', 'd', 'i', 'n', 'g', '\022', 'x', '\n', '\017', 'u', 't', -'f', '8', '_', 'v', 'a', 'l', 'i', 'd', 'a', 't', 'i', 'o', 'n', '\030', '\004', ' ', '\001', '(', '\016', '2', '*', '.', 'g', 'o', 'o', -'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'F', 'e', 'a', 't', 'u', 'r', 'e', 'S', 'e', 't', '.', 'U', -'t', 'f', '8', 'V', 'a', 'l', 'i', 'd', 'a', 't', 'i', 'o', 'n', 'B', '#', '\210', '\001', '\001', '\230', '\001', '\004', '\230', '\001', '\001', '\242', -'\001', '\t', '\022', '\004', 'N', 'O', 'N', 'E', '\030', '\346', '\007', '\242', '\001', '\013', '\022', '\006', 'V', 'E', 'R', 'I', 'F', 'Y', '\030', '\347', '\007', -'R', '\016', 'u', 't', 'f', '8', 'V', 'a', 'l', 'i', 'd', 'a', 't', 'i', 'o', 'n', '\022', 'x', '\n', '\020', 'm', 'e', 's', 's', 'a', -'g', 'e', '_', 'e', 'n', 'c', 'o', 'd', 'i', 'n', 'g', '\030', '\005', ' ', '\001', '(', '\016', '2', '+', '.', 'g', 'o', 'o', 'g', 'l', -'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'F', 'e', 'a', 't', 'u', 'r', 'e', 'S', 'e', 't', '.', 'M', 'e', 's', -'s', 'a', 'g', 'e', 'E', 'n', 'c', 'o', 'd', 'i', 'n', 'g', 'B', ' ', '\210', '\001', '\001', '\230', '\001', '\004', '\230', '\001', '\001', '\242', '\001', -'\024', '\022', '\017', 'L', 'E', 'N', 'G', 'T', 'H', '_', 'P', 'R', 'E', 'F', 'I', 'X', 'E', 'D', '\030', '\346', '\007', 'R', '\017', 'm', 'e', -'s', 's', 'a', 'g', 'e', 'E', 'n', 'c', 'o', 'd', 'i', 'n', 'g', '\022', '|', '\n', '\013', 'j', 's', 'o', 'n', '_', 'f', 'o', 'r', -'m', 'a', 't', '\030', '\006', ' ', '\001', '(', '\016', '2', '&', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', -'u', 'f', '.', 'F', 'e', 'a', 't', 'u', 'r', 'e', 'S', 'e', 't', '.', 'J', 's', 'o', 'n', 'F', 'o', 'r', 'm', 'a', 't', 'B', -'3', '\210', '\001', '\001', '\230', '\001', '\003', '\230', '\001', '\006', '\230', '\001', '\001', '\242', '\001', '\027', '\022', '\022', 'L', 'E', 'G', 'A', 'C', 'Y', '_', -'B', 'E', 'S', 'T', '_', 'E', 'F', 'F', 'O', 'R', 'T', '\030', '\346', '\007', '\242', '\001', '\n', '\022', '\005', 'A', 'L', 'L', 'O', 'W', '\030', -'\347', '\007', 'R', '\n', 'j', 's', 'o', 'n', 'F', 'o', 'r', 'm', 'a', 't', '\"', '\\', '\n', '\r', 'F', 'i', 'e', 'l', 'd', 'P', 'r', -'e', 's', 'e', 'n', 'c', 'e', '\022', '\032', '\n', '\026', 'F', 'I', 'E', 'L', 'D', '_', 'P', 'R', 'E', 'S', 'E', 'N', 'C', 'E', '_', -'U', 'N', 'K', 'N', 'O', 'W', 'N', '\020', '\000', '\022', '\014', '\n', '\010', 'E', 'X', 'P', 'L', 'I', 'C', 'I', 'T', '\020', '\001', '\022', '\014', -'\n', '\010', 'I', 'M', 'P', 'L', 'I', 'C', 'I', 'T', '\020', '\002', '\022', '\023', '\n', '\017', 'L', 'E', 'G', 'A', 'C', 'Y', '_', 'R', 'E', -'Q', 'U', 'I', 'R', 'E', 'D', '\020', '\003', '\"', '7', '\n', '\010', 'E', 'n', 'u', 'm', 'T', 'y', 'p', 'e', '\022', '\025', '\n', '\021', 'E', -'N', 'U', 'M', '_', 'T', 'Y', 'P', 'E', '_', 'U', 'N', 'K', 'N', 'O', 'W', 'N', '\020', '\000', '\022', '\010', '\n', '\004', 'O', 'P', 'E', -'N', '\020', '\001', '\022', '\n', '\n', '\006', 'C', 'L', 'O', 'S', 'E', 'D', '\020', '\002', '\"', 'V', '\n', '\025', 'R', 'e', 'p', 'e', 'a', 't', -'e', 'd', 'F', 'i', 'e', 'l', 'd', 'E', 'n', 'c', 'o', 'd', 'i', 'n', 'g', '\022', '#', '\n', '\037', 'R', 'E', 'P', 'E', 'A', 'T', -'E', 'D', '_', 'F', 'I', 'E', 'L', 'D', '_', 'E', 'N', 'C', 'O', 'D', 'I', 'N', 'G', '_', 'U', 'N', 'K', 'N', 'O', 'W', 'N', -'\020', '\000', '\022', '\n', '\n', '\006', 'P', 'A', 'C', 'K', 'E', 'D', '\020', '\001', '\022', '\014', '\n', '\010', 'E', 'X', 'P', 'A', 'N', 'D', 'E', -'D', '\020', '\002', '\"', 'C', '\n', '\016', 'U', 't', 'f', '8', 'V', 'a', 'l', 'i', 'd', 'a', 't', 'i', 'o', 'n', '\022', '\033', '\n', '\027', -'U', 'T', 'F', '8', '_', 'V', 'A', 'L', 'I', 'D', 'A', 'T', 'I', 'O', 'N', '_', 'U', 'N', 'K', 'N', 'O', 'W', 'N', '\020', '\000', -'\022', '\n', '\n', '\006', 'V', 'E', 'R', 'I', 'F', 'Y', '\020', '\002', '\022', '\010', '\n', '\004', 'N', 'O', 'N', 'E', '\020', '\003', '\"', 'S', '\n', -'\017', 'M', 'e', 's', 's', 'a', 'g', 'e', 'E', 'n', 'c', 'o', 'd', 'i', 'n', 'g', '\022', '\034', '\n', '\030', 'M', 'E', 'S', 'S', 'A', -'G', 'E', '_', 'E', 'N', 'C', 'O', 'D', 'I', 'N', 'G', '_', 'U', 'N', 'K', 'N', 'O', 'W', 'N', '\020', '\000', '\022', '\023', '\n', '\017', -'L', 'E', 'N', 'G', 'T', 'H', '_', 'P', 'R', 'E', 'F', 'I', 'X', 'E', 'D', '\020', '\001', '\022', '\r', '\n', '\t', 'D', 'E', 'L', 'I', -'M', 'I', 'T', 'E', 'D', '\020', '\002', '\"', 'H', '\n', '\n', 'J', 's', 'o', 'n', 'F', 'o', 'r', 'm', 'a', 't', '\022', '\027', '\n', '\023', -'J', 'S', 'O', 'N', '_', 'F', 'O', 'R', 'M', 'A', 'T', '_', 'U', 'N', 'K', 'N', 'O', 'W', 'N', '\020', '\000', '\022', '\t', '\n', '\005', -'A', 'L', 'L', 'O', 'W', '\020', '\001', '\022', '\026', '\n', '\022', 'L', 'E', 'G', 'A', 'C', 'Y', '_', 'B', 'E', 'S', 'T', '_', 'E', 'F', -'F', 'O', 'R', 'T', '\020', '\002', '*', '\006', '\010', '\350', '\007', '\020', '\351', '\007', '*', '\006', '\010', '\351', '\007', '\020', '\352', '\007', '*', '\006', '\010', -'\213', 'N', '\020', '\220', 'N', 'J', '\006', '\010', '\347', '\007', '\020', '\350', '\007', '\"', '\376', '\002', '\n', '\022', 'F', 'e', 'a', 't', 'u', 'r', 'e', -'S', 'e', 't', 'D', 'e', 'f', 'a', 'u', 'l', 't', 's', '\022', 'X', '\n', '\010', 'd', 'e', 'f', 'a', 'u', 'l', 't', 's', '\030', '\001', -' ', '\003', '(', '\013', '2', '<', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'F', 'e', -'a', 't', 'u', 'r', 'e', 'S', 'e', 't', 'D', 'e', 'f', 'a', 'u', 'l', 't', 's', '.', 'F', 'e', 'a', 't', 'u', 'r', 'e', 'S', -'e', 't', 'E', 'd', 'i', 't', 'i', 'o', 'n', 'D', 'e', 'f', 'a', 'u', 'l', 't', 'R', '\010', 'd', 'e', 'f', 'a', 'u', 'l', 't', -'s', '\022', 'A', '\n', '\017', 'm', 'i', 'n', 'i', 'm', 'u', 'm', '_', 'e', 'd', 'i', 't', 'i', 'o', 'n', '\030', '\004', ' ', '\001', '(', -'\016', '2', '\030', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'E', 'd', 'i', 't', 'i', -'o', 'n', 'R', '\016', 'm', 'i', 'n', 'i', 'm', 'u', 'm', 'E', 'd', 'i', 't', 'i', 'o', 'n', '\022', 'A', '\n', '\017', 'm', 'a', 'x', -'i', 'm', 'u', 'm', '_', 'e', 'd', 'i', 't', 'i', 'o', 'n', '\030', '\005', ' ', '\001', '(', '\016', '2', '\030', '.', 'g', 'o', 'o', 'g', -'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'E', 'd', 'i', 't', 'i', 'o', 'n', 'R', '\016', 'm', 'a', 'x', 'i', -'m', 'u', 'm', 'E', 'd', 'i', 't', 'i', 'o', 'n', '\032', '\207', '\001', '\n', '\030', 'F', 'e', 'a', 't', 'u', 'r', 'e', 'S', 'e', 't', -'E', 'd', 'i', 't', 'i', 'o', 'n', 'D', 'e', 'f', 'a', 'u', 'l', 't', '\022', '2', '\n', '\007', 'e', 'd', 'i', 't', 'i', 'o', 'n', -'\030', '\003', ' ', '\001', '(', '\016', '2', '\030', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', -'E', 'd', 'i', 't', 'i', 'o', 'n', 'R', '\007', 'e', 'd', 'i', 't', 'i', 'o', 'n', '\022', '7', '\n', '\010', 'f', 'e', 'a', 't', 'u', -'r', 'e', 's', '\030', '\002', ' ', '\001', '(', '\013', '2', '\033', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', -'u', 'f', '.', 'F', 'e', 'a', 't', 'u', 'r', 'e', 'S', 'e', 't', 'R', '\010', 'f', 'e', 'a', 't', 'u', 'r', 'e', 's', '\"', '\247', -'\002', '\n', '\016', 'S', 'o', 'u', 'r', 'c', 'e', 'C', 'o', 'd', 'e', 'I', 'n', 'f', 'o', '\022', 'D', '\n', '\010', 'l', 'o', 'c', 'a', -'t', 'i', 'o', 'n', '\030', '\001', ' ', '\003', '(', '\013', '2', '(', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', -'b', 'u', 'f', '.', 'S', 'o', 'u', 'r', 'c', 'e', 'C', 'o', 'd', 'e', 'I', 'n', 'f', 'o', '.', 'L', 'o', 'c', 'a', 't', 'i', -'o', 'n', 'R', '\010', 'l', 'o', 'c', 'a', 't', 'i', 'o', 'n', '\032', '\316', '\001', '\n', '\010', 'L', 'o', 'c', 'a', 't', 'i', 'o', 'n', -'\022', '\026', '\n', '\004', 'p', 'a', 't', 'h', '\030', '\001', ' ', '\003', '(', '\005', 'B', '\002', '\020', '\001', 'R', '\004', 'p', 'a', 't', 'h', '\022', -'\026', '\n', '\004', 's', 'p', 'a', 'n', '\030', '\002', ' ', '\003', '(', '\005', 'B', '\002', '\020', '\001', 'R', '\004', 's', 'p', 'a', 'n', '\022', ')', -'\n', '\020', 'l', 'e', 'a', 'd', 'i', 'n', 'g', '_', 'c', 'o', 'm', 'm', 'e', 'n', 't', 's', '\030', '\003', ' ', '\001', '(', '\t', 'R', -'\017', 'l', 'e', 'a', 'd', 'i', 'n', 'g', 'C', 'o', 'm', 'm', 'e', 'n', 't', 's', '\022', '+', '\n', '\021', 't', 'r', 'a', 'i', 'l', -'i', 'n', 'g', '_', 'c', 'o', 'm', 'm', 'e', 'n', 't', 's', '\030', '\004', ' ', '\001', '(', '\t', 'R', '\020', 't', 'r', 'a', 'i', 'l', -'i', 'n', 'g', 'C', 'o', 'm', 'm', 'e', 'n', 't', 's', '\022', ':', '\n', '\031', 'l', 'e', 'a', 'd', 'i', 'n', 'g', '_', 'd', 'e', -'t', 'a', 'c', 'h', 'e', 'd', '_', 'c', 'o', 'm', 'm', 'e', 'n', 't', 's', '\030', '\006', ' ', '\003', '(', '\t', 'R', '\027', 'l', 'e', -'a', 'd', 'i', 'n', 'g', 'D', 'e', 't', 'a', 'c', 'h', 'e', 'd', 'C', 'o', 'm', 'm', 'e', 'n', 't', 's', '\"', '\320', '\002', '\n', -'\021', 'G', 'e', 'n', 'e', 'r', 'a', 't', 'e', 'd', 'C', 'o', 'd', 'e', 'I', 'n', 'f', 'o', '\022', 'M', '\n', '\n', 'a', 'n', 'n', -'o', 't', 'a', 't', 'i', 'o', 'n', '\030', '\001', ' ', '\003', '(', '\013', '2', '-', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', -'o', 't', 'o', 'b', 'u', 'f', '.', 'G', 'e', 'n', 'e', 'r', 'a', 't', 'e', 'd', 'C', 'o', 'd', 'e', 'I', 'n', 'f', 'o', '.', -'A', 'n', 'n', 'o', 't', 'a', 't', 'i', 'o', 'n', 'R', '\n', 'a', 'n', 'n', 'o', 't', 'a', 't', 'i', 'o', 'n', '\032', '\353', '\001', -'\n', '\n', 'A', 'n', 'n', 'o', 't', 'a', 't', 'i', 'o', 'n', '\022', '\026', '\n', '\004', 'p', 'a', 't', 'h', '\030', '\001', ' ', '\003', '(', -'\005', 'B', '\002', '\020', '\001', 'R', '\004', 'p', 'a', 't', 'h', '\022', '\037', '\n', '\013', 's', 'o', 'u', 'r', 'c', 'e', '_', 'f', 'i', 'l', -'e', '\030', '\002', ' ', '\001', '(', '\t', 'R', '\n', 's', 'o', 'u', 'r', 'c', 'e', 'F', 'i', 'l', 'e', '\022', '\024', '\n', '\005', 'b', 'e', -'g', 'i', 'n', '\030', '\003', ' ', '\001', '(', '\005', 'R', '\005', 'b', 'e', 'g', 'i', 'n', '\022', '\020', '\n', '\003', 'e', 'n', 'd', '\030', '\004', -' ', '\001', '(', '\005', 'R', '\003', 'e', 'n', 'd', '\022', 'R', '\n', '\010', 's', 'e', 'm', 'a', 'n', 't', 'i', 'c', '\030', '\005', ' ', '\001', -'(', '\016', '2', '6', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'G', 'e', 'n', 'e', -'r', 'a', 't', 'e', 'd', 'C', 'o', 'd', 'e', 'I', 'n', 'f', 'o', '.', 'A', 'n', 'n', 'o', 't', 'a', 't', 'i', 'o', 'n', '.', -'S', 'e', 'm', 'a', 'n', 't', 'i', 'c', 'R', '\010', 's', 'e', 'm', 'a', 'n', 't', 'i', 'c', '\"', '(', '\n', '\010', 'S', 'e', 'm', -'a', 'n', 't', 'i', 'c', '\022', '\010', '\n', '\004', 'N', 'O', 'N', 'E', '\020', '\000', '\022', '\007', '\n', '\003', 'S', 'E', 'T', '\020', '\001', '\022', -'\t', '\n', '\005', 'A', 'L', 'I', 'A', 'S', '\020', '\002', '*', '\377', '\001', '\n', '\007', 'E', 'd', 'i', 't', 'i', 'o', 'n', '\022', '\023', '\n', -'\017', 'E', 'D', 'I', 'T', 'I', 'O', 'N', '_', 'U', 'N', 'K', 'N', 'O', 'W', 'N', '\020', '\000', '\022', '\023', '\n', '\016', 'E', 'D', 'I', -'T', 'I', 'O', 'N', '_', 'P', 'R', 'O', 'T', 'O', '2', '\020', '\346', '\007', '\022', '\023', '\n', '\016', 'E', 'D', 'I', 'T', 'I', 'O', 'N', -'_', 'P', 'R', 'O', 'T', 'O', '3', '\020', '\347', '\007', '\022', '\021', '\n', '\014', 'E', 'D', 'I', 'T', 'I', 'O', 'N', '_', '2', '0', '2', -'3', '\020', '\350', '\007', '\022', '\027', '\n', '\023', 'E', 'D', 'I', 'T', 'I', 'O', 'N', '_', '1', '_', 'T', 'E', 'S', 'T', '_', 'O', 'N', -'L', 'Y', '\020', '\001', '\022', '\027', '\n', '\023', 'E', 'D', 'I', 'T', 'I', 'O', 'N', '_', '2', '_', 'T', 'E', 'S', 'T', '_', 'O', 'N', -'L', 'Y', '\020', '\002', '\022', '\035', '\n', '\027', 'E', 'D', 'I', 'T', 'I', 'O', 'N', '_', '9', '9', '9', '9', '7', '_', 'T', 'E', 'S', -'T', '_', 'O', 'N', 'L', 'Y', '\020', '\235', '\215', '\006', '\022', '\035', '\n', '\027', 'E', 'D', 'I', 'T', 'I', 'O', 'N', '_', '9', '9', '9', -'9', '8', '_', 'T', 'E', 'S', 'T', '_', 'O', 'N', 'L', 'Y', '\020', '\236', '\215', '\006', '\022', '\035', '\n', '\027', 'E', 'D', 'I', 'T', 'I', -'O', 'N', '_', '9', '9', '9', '9', '9', '_', 'T', 'E', 'S', 'T', '_', 'O', 'N', 'L', 'Y', '\020', '\237', '\215', '\006', '\022', '\023', '\n', -'\013', 'E', 'D', 'I', 'T', 'I', 'O', 'N', '_', 'M', 'A', 'X', '\020', '\377', '\377', '\377', '\377', '\007', 'B', '~', '\n', '\023', 'c', 'o', 'm', -'.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', 'B', '\020', 'D', 'e', 's', 'c', 'r', 'i', 'p', -'t', 'o', 'r', 'P', 'r', 'o', 't', 'o', 's', 'H', '\001', 'Z', '-', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'g', 'o', 'l', 'a', 'n', -'g', '.', 'o', 'r', 'g', '/', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '/', 't', 'y', 'p', 'e', 's', '/', 'd', 'e', 's', 'c', -'r', 'i', 'p', 't', 'o', 'r', 'p', 'b', '\370', '\001', '\001', '\242', '\002', '\003', 'G', 'P', 'B', '\252', '\002', '\032', 'G', 'o', 'o', 'g', 'l', -'e', '.', 'P', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'R', 'e', 'f', 'l', 'e', 'c', 't', 'i', 'o', 'n', +'i', 'o', 'n', '\"', ':', '\n', '\014', 'O', 'p', 't', 'i', 'm', 'i', 'z', 'e', 'M', 'o', 'd', 'e', '\022', '\t', '\n', '\005', 'S', 'P', +'E', 'E', 'D', '\020', '\001', '\022', '\r', '\n', '\t', 'C', 'O', 'D', 'E', '_', 'S', 'I', 'Z', 'E', '\020', '\002', '\022', '\020', '\n', '\014', 'L', +'I', 'T', 'E', '_', 'R', 'U', 'N', 'T', 'I', 'M', 'E', '\020', '\003', '*', '\t', '\010', '\350', '\007', '\020', '\200', '\200', '\200', '\200', '\002', 'J', +'\004', '\010', '*', '\020', '+', 'J', '\004', '\010', '&', '\020', '\'', '\"', '\364', '\003', '\n', '\016', 'M', 'e', 's', 's', 'a', 'g', 'e', 'O', 'p', +'t', 'i', 'o', 'n', 's', '\022', '<', '\n', '\027', 'm', 'e', 's', 's', 'a', 'g', 'e', '_', 's', 'e', 't', '_', 'w', 'i', 'r', 'e', +'_', 'f', 'o', 'r', 'm', 'a', 't', '\030', '\001', ' ', '\001', '(', '\010', ':', '\005', 'f', 'a', 'l', 's', 'e', 'R', '\024', 'm', 'e', 's', +'s', 'a', 'g', 'e', 'S', 'e', 't', 'W', 'i', 'r', 'e', 'F', 'o', 'r', 'm', 'a', 't', '\022', 'L', '\n', '\037', 'n', 'o', '_', 's', +'t', 'a', 'n', 'd', 'a', 'r', 'd', '_', 'd', 'e', 's', 'c', 'r', 'i', 'p', 't', 'o', 'r', '_', 'a', 'c', 'c', 'e', 's', 's', +'o', 'r', '\030', '\002', ' ', '\001', '(', '\010', ':', '\005', 'f', 'a', 'l', 's', 'e', 'R', '\034', 'n', 'o', 'S', 't', 'a', 'n', 'd', 'a', +'r', 'd', 'D', 'e', 's', 'c', 'r', 'i', 'p', 't', 'o', 'r', 'A', 'c', 'c', 'e', 's', 's', 'o', 'r', '\022', '%', '\n', '\n', 'd', +'e', 'p', 'r', 'e', 'c', 'a', 't', 'e', 'd', '\030', '\003', ' ', '\001', '(', '\010', ':', '\005', 'f', 'a', 'l', 's', 'e', 'R', '\n', 'd', +'e', 'p', 'r', 'e', 'c', 'a', 't', 'e', 'd', '\022', '\033', '\n', '\t', 'm', 'a', 'p', '_', 'e', 'n', 't', 'r', 'y', '\030', '\007', ' ', +'\001', '(', '\010', 'R', '\010', 'm', 'a', 'p', 'E', 'n', 't', 'r', 'y', '\022', 'V', '\n', '&', 'd', 'e', 'p', 'r', 'e', 'c', 'a', 't', +'e', 'd', '_', 'l', 'e', 'g', 'a', 'c', 'y', '_', 'j', 's', 'o', 'n', '_', 'f', 'i', 'e', 'l', 'd', '_', 'c', 'o', 'n', 'f', +'l', 'i', 'c', 't', 's', '\030', '\013', ' ', '\001', '(', '\010', 'B', '\002', '\030', '\001', 'R', '\"', 'd', 'e', 'p', 'r', 'e', 'c', 'a', 't', +'e', 'd', 'L', 'e', 'g', 'a', 'c', 'y', 'J', 's', 'o', 'n', 'F', 'i', 'e', 'l', 'd', 'C', 'o', 'n', 'f', 'l', 'i', 'c', 't', +'s', '\022', '7', '\n', '\010', 'f', 'e', 'a', 't', 'u', 'r', 'e', 's', '\030', '\014', ' ', '\001', '(', '\013', '2', '\033', '.', 'g', 'o', 'o', +'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'F', 'e', 'a', 't', 'u', 'r', 'e', 'S', 'e', 't', 'R', '\010', +'f', 'e', 'a', 't', 'u', 'r', 'e', 's', '\022', 'X', '\n', '\024', 'u', 'n', 'i', 'n', 't', 'e', 'r', 'p', 'r', 'e', 't', 'e', 'd', +'_', 'o', 'p', 't', 'i', 'o', 'n', '\030', '\347', '\007', ' ', '\003', '(', '\013', '2', '$', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', +'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'U', 'n', 'i', 'n', 't', 'e', 'r', 'p', 'r', 'e', 't', 'e', 'd', 'O', 'p', 't', 'i', +'o', 'n', 'R', '\023', 'u', 'n', 'i', 'n', 't', 'e', 'r', 'p', 'r', 'e', 't', 'e', 'd', 'O', 'p', 't', 'i', 'o', 'n', '*', '\t', +'\010', '\350', '\007', '\020', '\200', '\200', '\200', '\200', '\002', 'J', '\004', '\010', '\004', '\020', '\005', 'J', '\004', '\010', '\005', '\020', '\006', 'J', '\004', '\010', '\006', +'\020', '\007', 'J', '\004', '\010', '\010', '\020', '\t', 'J', '\004', '\010', '\t', '\020', '\n', '\"', '\255', '\n', '\n', '\014', 'F', 'i', 'e', 'l', 'd', 'O', +'p', 't', 'i', 'o', 'n', 's', '\022', 'A', '\n', '\005', 'c', 't', 'y', 'p', 'e', '\030', '\001', ' ', '\001', '(', '\016', '2', '#', '.', 'g', +'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'F', 'i', 'e', 'l', 'd', 'O', 'p', 't', 'i', 'o', +'n', 's', '.', 'C', 'T', 'y', 'p', 'e', ':', '\006', 'S', 'T', 'R', 'I', 'N', 'G', 'R', '\005', 'c', 't', 'y', 'p', 'e', '\022', '\026', +'\n', '\006', 'p', 'a', 'c', 'k', 'e', 'd', '\030', '\002', ' ', '\001', '(', '\010', 'R', '\006', 'p', 'a', 'c', 'k', 'e', 'd', '\022', 'G', '\n', +'\006', 'j', 's', 't', 'y', 'p', 'e', '\030', '\006', ' ', '\001', '(', '\016', '2', '$', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', +'o', 't', 'o', 'b', 'u', 'f', '.', 'F', 'i', 'e', 'l', 'd', 'O', 'p', 't', 'i', 'o', 'n', 's', '.', 'J', 'S', 'T', 'y', 'p', +'e', ':', '\t', 'J', 'S', '_', 'N', 'O', 'R', 'M', 'A', 'L', 'R', '\006', 'j', 's', 't', 'y', 'p', 'e', '\022', '\031', '\n', '\004', 'l', +'a', 'z', 'y', '\030', '\005', ' ', '\001', '(', '\010', ':', '\005', 'f', 'a', 'l', 's', 'e', 'R', '\004', 'l', 'a', 'z', 'y', '\022', '.', '\n', +'\017', 'u', 'n', 'v', 'e', 'r', 'i', 'f', 'i', 'e', 'd', '_', 'l', 'a', 'z', 'y', '\030', '\017', ' ', '\001', '(', '\010', ':', '\005', 'f', +'a', 'l', 's', 'e', 'R', '\016', 'u', 'n', 'v', 'e', 'r', 'i', 'f', 'i', 'e', 'd', 'L', 'a', 'z', 'y', '\022', '%', '\n', '\n', 'd', +'e', 'p', 'r', 'e', 'c', 'a', 't', 'e', 'd', '\030', '\003', ' ', '\001', '(', '\010', ':', '\005', 'f', 'a', 'l', 's', 'e', 'R', '\n', 'd', +'e', 'p', 'r', 'e', 'c', 'a', 't', 'e', 'd', '\022', '\031', '\n', '\004', 'w', 'e', 'a', 'k', '\030', '\n', ' ', '\001', '(', '\010', ':', '\005', +'f', 'a', 'l', 's', 'e', 'R', '\004', 'w', 'e', 'a', 'k', '\022', '(', '\n', '\014', 'd', 'e', 'b', 'u', 'g', '_', 'r', 'e', 'd', 'a', +'c', 't', '\030', '\020', ' ', '\001', '(', '\010', ':', '\005', 'f', 'a', 'l', 's', 'e', 'R', '\013', 'd', 'e', 'b', 'u', 'g', 'R', 'e', 'd', +'a', 'c', 't', '\022', 'K', '\n', '\t', 'r', 'e', 't', 'e', 'n', 't', 'i', 'o', 'n', '\030', '\021', ' ', '\001', '(', '\016', '2', '-', '.', +'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'F', 'i', 'e', 'l', 'd', 'O', 'p', 't', 'i', +'o', 'n', 's', '.', 'O', 'p', 't', 'i', 'o', 'n', 'R', 'e', 't', 'e', 'n', 't', 'i', 'o', 'n', 'R', '\t', 'r', 'e', 't', 'e', +'n', 't', 'i', 'o', 'n', '\022', 'H', '\n', '\007', 't', 'a', 'r', 'g', 'e', 't', 's', '\030', '\023', ' ', '\003', '(', '\016', '2', '.', '.', +'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'F', 'i', 'e', 'l', 'd', 'O', 'p', 't', 'i', +'o', 'n', 's', '.', 'O', 'p', 't', 'i', 'o', 'n', 'T', 'a', 'r', 'g', 'e', 't', 'T', 'y', 'p', 'e', 'R', '\007', 't', 'a', 'r', +'g', 'e', 't', 's', '\022', 'W', '\n', '\020', 'e', 'd', 'i', 't', 'i', 'o', 'n', '_', 'd', 'e', 'f', 'a', 'u', 'l', 't', 's', '\030', +'\024', ' ', '\003', '(', '\013', '2', ',', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'F', +'i', 'e', 'l', 'd', 'O', 'p', 't', 'i', 'o', 'n', 's', '.', 'E', 'd', 'i', 't', 'i', 'o', 'n', 'D', 'e', 'f', 'a', 'u', 'l', +'t', 'R', '\017', 'e', 'd', 'i', 't', 'i', 'o', 'n', 'D', 'e', 'f', 'a', 'u', 'l', 't', 's', '\022', '7', '\n', '\010', 'f', 'e', 'a', +'t', 'u', 'r', 'e', 's', '\030', '\025', ' ', '\001', '(', '\013', '2', '\033', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', +'o', 'b', 'u', 'f', '.', 'F', 'e', 'a', 't', 'u', 'r', 'e', 'S', 'e', 't', 'R', '\010', 'f', 'e', 'a', 't', 'u', 'r', 'e', 's', +'\022', 'X', '\n', '\024', 'u', 'n', 'i', 'n', 't', 'e', 'r', 'p', 'r', 'e', 't', 'e', 'd', '_', 'o', 'p', 't', 'i', 'o', 'n', '\030', +'\347', '\007', ' ', '\003', '(', '\013', '2', '$', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', +'U', 'n', 'i', 'n', 't', 'e', 'r', 'p', 'r', 'e', 't', 'e', 'd', 'O', 'p', 't', 'i', 'o', 'n', 'R', '\023', 'u', 'n', 'i', 'n', +'t', 'e', 'r', 'p', 'r', 'e', 't', 'e', 'd', 'O', 'p', 't', 'i', 'o', 'n', '\032', 'Z', '\n', '\016', 'E', 'd', 'i', 't', 'i', 'o', +'n', 'D', 'e', 'f', 'a', 'u', 'l', 't', '\022', '2', '\n', '\007', 'e', 'd', 'i', 't', 'i', 'o', 'n', '\030', '\003', ' ', '\001', '(', '\016', +'2', '\030', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'E', 'd', 'i', 't', 'i', 'o', +'n', 'R', '\007', 'e', 'd', 'i', 't', 'i', 'o', 'n', '\022', '\024', '\n', '\005', 'v', 'a', 'l', 'u', 'e', '\030', '\002', ' ', '\001', '(', '\t', +'R', '\005', 'v', 'a', 'l', 'u', 'e', '\"', '/', '\n', '\005', 'C', 'T', 'y', 'p', 'e', '\022', '\n', '\n', '\006', 'S', 'T', 'R', 'I', 'N', +'G', '\020', '\000', '\022', '\010', '\n', '\004', 'C', 'O', 'R', 'D', '\020', '\001', '\022', '\020', '\n', '\014', 'S', 'T', 'R', 'I', 'N', 'G', '_', 'P', +'I', 'E', 'C', 'E', '\020', '\002', '\"', '5', '\n', '\006', 'J', 'S', 'T', 'y', 'p', 'e', '\022', '\r', '\n', '\t', 'J', 'S', '_', 'N', 'O', +'R', 'M', 'A', 'L', '\020', '\000', '\022', '\r', '\n', '\t', 'J', 'S', '_', 'S', 'T', 'R', 'I', 'N', 'G', '\020', '\001', '\022', '\r', '\n', '\t', +'J', 'S', '_', 'N', 'U', 'M', 'B', 'E', 'R', '\020', '\002', '\"', 'U', '\n', '\017', 'O', 'p', 't', 'i', 'o', 'n', 'R', 'e', 't', 'e', +'n', 't', 'i', 'o', 'n', '\022', '\025', '\n', '\021', 'R', 'E', 'T', 'E', 'N', 'T', 'I', 'O', 'N', '_', 'U', 'N', 'K', 'N', 'O', 'W', +'N', '\020', '\000', '\022', '\025', '\n', '\021', 'R', 'E', 'T', 'E', 'N', 'T', 'I', 'O', 'N', '_', 'R', 'U', 'N', 'T', 'I', 'M', 'E', '\020', +'\001', '\022', '\024', '\n', '\020', 'R', 'E', 'T', 'E', 'N', 'T', 'I', 'O', 'N', '_', 'S', 'O', 'U', 'R', 'C', 'E', '\020', '\002', '\"', '\214', +'\002', '\n', '\020', 'O', 'p', 't', 'i', 'o', 'n', 'T', 'a', 'r', 'g', 'e', 't', 'T', 'y', 'p', 'e', '\022', '\027', '\n', '\023', 'T', 'A', +'R', 'G', 'E', 'T', '_', 'T', 'Y', 'P', 'E', '_', 'U', 'N', 'K', 'N', 'O', 'W', 'N', '\020', '\000', '\022', '\024', '\n', '\020', 'T', 'A', +'R', 'G', 'E', 'T', '_', 'T', 'Y', 'P', 'E', '_', 'F', 'I', 'L', 'E', '\020', '\001', '\022', '\037', '\n', '\033', 'T', 'A', 'R', 'G', 'E', +'T', '_', 'T', 'Y', 'P', 'E', '_', 'E', 'X', 'T', 'E', 'N', 'S', 'I', 'O', 'N', '_', 'R', 'A', 'N', 'G', 'E', '\020', '\002', '\022', +'\027', '\n', '\023', 'T', 'A', 'R', 'G', 'E', 'T', '_', 'T', 'Y', 'P', 'E', '_', 'M', 'E', 'S', 'S', 'A', 'G', 'E', '\020', '\003', '\022', +'\025', '\n', '\021', 'T', 'A', 'R', 'G', 'E', 'T', '_', 'T', 'Y', 'P', 'E', '_', 'F', 'I', 'E', 'L', 'D', '\020', '\004', '\022', '\025', '\n', +'\021', 'T', 'A', 'R', 'G', 'E', 'T', '_', 'T', 'Y', 'P', 'E', '_', 'O', 'N', 'E', 'O', 'F', '\020', '\005', '\022', '\024', '\n', '\020', 'T', +'A', 'R', 'G', 'E', 'T', '_', 'T', 'Y', 'P', 'E', '_', 'E', 'N', 'U', 'M', '\020', '\006', '\022', '\032', '\n', '\026', 'T', 'A', 'R', 'G', +'E', 'T', '_', 'T', 'Y', 'P', 'E', '_', 'E', 'N', 'U', 'M', '_', 'E', 'N', 'T', 'R', 'Y', '\020', '\007', '\022', '\027', '\n', '\023', 'T', +'A', 'R', 'G', 'E', 'T', '_', 'T', 'Y', 'P', 'E', '_', 'S', 'E', 'R', 'V', 'I', 'C', 'E', '\020', '\010', '\022', '\026', '\n', '\022', 'T', +'A', 'R', 'G', 'E', 'T', '_', 'T', 'Y', 'P', 'E', '_', 'M', 'E', 'T', 'H', 'O', 'D', '\020', '\t', '*', '\t', '\010', '\350', '\007', '\020', +'\200', '\200', '\200', '\200', '\002', 'J', '\004', '\010', '\004', '\020', '\005', 'J', '\004', '\010', '\022', '\020', '\023', '\"', '\254', '\001', '\n', '\014', 'O', 'n', 'e', +'o', 'f', 'O', 'p', 't', 'i', 'o', 'n', 's', '\022', '7', '\n', '\010', 'f', 'e', 'a', 't', 'u', 'r', 'e', 's', '\030', '\001', ' ', '\001', +'(', '\013', '2', '\033', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'F', 'e', 'a', 't', +'u', 'r', 'e', 'S', 'e', 't', 'R', '\010', 'f', 'e', 'a', 't', 'u', 'r', 'e', 's', '\022', 'X', '\n', '\024', 'u', 'n', 'i', 'n', 't', +'e', 'r', 'p', 'r', 'e', 't', 'e', 'd', '_', 'o', 'p', 't', 'i', 'o', 'n', '\030', '\347', '\007', ' ', '\003', '(', '\013', '2', '$', '.', +'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'U', 'n', 'i', 'n', 't', 'e', 'r', 'p', 'r', +'e', 't', 'e', 'd', 'O', 'p', 't', 'i', 'o', 'n', 'R', '\023', 'u', 'n', 'i', 'n', 't', 'e', 'r', 'p', 'r', 'e', 't', 'e', 'd', +'O', 'p', 't', 'i', 'o', 'n', '*', '\t', '\010', '\350', '\007', '\020', '\200', '\200', '\200', '\200', '\002', '\"', '\321', '\002', '\n', '\013', 'E', 'n', 'u', +'m', 'O', 'p', 't', 'i', 'o', 'n', 's', '\022', '\037', '\n', '\013', 'a', 'l', 'l', 'o', 'w', '_', 'a', 'l', 'i', 'a', 's', '\030', '\002', +' ', '\001', '(', '\010', 'R', '\n', 'a', 'l', 'l', 'o', 'w', 'A', 'l', 'i', 'a', 's', '\022', '%', '\n', '\n', 'd', 'e', 'p', 'r', 'e', +'c', 'a', 't', 'e', 'd', '\030', '\003', ' ', '\001', '(', '\010', ':', '\005', 'f', 'a', 'l', 's', 'e', 'R', '\n', 'd', 'e', 'p', 'r', 'e', +'c', 'a', 't', 'e', 'd', '\022', 'V', '\n', '&', 'd', 'e', 'p', 'r', 'e', 'c', 'a', 't', 'e', 'd', '_', 'l', 'e', 'g', 'a', 'c', +'y', '_', 'j', 's', 'o', 'n', '_', 'f', 'i', 'e', 'l', 'd', '_', 'c', 'o', 'n', 'f', 'l', 'i', 'c', 't', 's', '\030', '\006', ' ', +'\001', '(', '\010', 'B', '\002', '\030', '\001', 'R', '\"', 'd', 'e', 'p', 'r', 'e', 'c', 'a', 't', 'e', 'd', 'L', 'e', 'g', 'a', 'c', 'y', +'J', 's', 'o', 'n', 'F', 'i', 'e', 'l', 'd', 'C', 'o', 'n', 'f', 'l', 'i', 'c', 't', 's', '\022', '7', '\n', '\010', 'f', 'e', 'a', +'t', 'u', 'r', 'e', 's', '\030', '\007', ' ', '\001', '(', '\013', '2', '\033', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', +'o', 'b', 'u', 'f', '.', 'F', 'e', 'a', 't', 'u', 'r', 'e', 'S', 'e', 't', 'R', '\010', 'f', 'e', 'a', 't', 'u', 'r', 'e', 's', +'\022', 'X', '\n', '\024', 'u', 'n', 'i', 'n', 't', 'e', 'r', 'p', 'r', 'e', 't', 'e', 'd', '_', 'o', 'p', 't', 'i', 'o', 'n', '\030', +'\347', '\007', ' ', '\003', '(', '\013', '2', '$', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', +'U', 'n', 'i', 'n', 't', 'e', 'r', 'p', 'r', 'e', 't', 'e', 'd', 'O', 'p', 't', 'i', 'o', 'n', 'R', '\023', 'u', 'n', 'i', 'n', +'t', 'e', 'r', 'p', 'r', 'e', 't', 'e', 'd', 'O', 'p', 't', 'i', 'o', 'n', '*', '\t', '\010', '\350', '\007', '\020', '\200', '\200', '\200', '\200', +'\002', 'J', '\004', '\010', '\005', '\020', '\006', '\"', '\201', '\002', '\n', '\020', 'E', 'n', 'u', 'm', 'V', 'a', 'l', 'u', 'e', 'O', 'p', 't', 'i', +'o', 'n', 's', '\022', '%', '\n', '\n', 'd', 'e', 'p', 'r', 'e', 'c', 'a', 't', 'e', 'd', '\030', '\001', ' ', '\001', '(', '\010', ':', '\005', +'f', 'a', 'l', 's', 'e', 'R', '\n', 'd', 'e', 'p', 'r', 'e', 'c', 'a', 't', 'e', 'd', '\022', '7', '\n', '\010', 'f', 'e', 'a', 't', +'u', 'r', 'e', 's', '\030', '\002', ' ', '\001', '(', '\013', '2', '\033', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', +'b', 'u', 'f', '.', 'F', 'e', 'a', 't', 'u', 'r', 'e', 'S', 'e', 't', 'R', '\010', 'f', 'e', 'a', 't', 'u', 'r', 'e', 's', '\022', +'(', '\n', '\014', 'd', 'e', 'b', 'u', 'g', '_', 'r', 'e', 'd', 'a', 'c', 't', '\030', '\003', ' ', '\001', '(', '\010', ':', '\005', 'f', 'a', +'l', 's', 'e', 'R', '\013', 'd', 'e', 'b', 'u', 'g', 'R', 'e', 'd', 'a', 'c', 't', '\022', 'X', '\n', '\024', 'u', 'n', 'i', 'n', 't', +'e', 'r', 'p', 'r', 'e', 't', 'e', 'd', '_', 'o', 'p', 't', 'i', 'o', 'n', '\030', '\347', '\007', ' ', '\003', '(', '\013', '2', '$', '.', +'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'U', 'n', 'i', 'n', 't', 'e', 'r', 'p', 'r', +'e', 't', 'e', 'd', 'O', 'p', 't', 'i', 'o', 'n', 'R', '\023', 'u', 'n', 'i', 'n', 't', 'e', 'r', 'p', 'r', 'e', 't', 'e', 'd', +'O', 'p', 't', 'i', 'o', 'n', '*', '\t', '\010', '\350', '\007', '\020', '\200', '\200', '\200', '\200', '\002', '\"', '\325', '\001', '\n', '\016', 'S', 'e', 'r', +'v', 'i', 'c', 'e', 'O', 'p', 't', 'i', 'o', 'n', 's', '\022', '7', '\n', '\010', 'f', 'e', 'a', 't', 'u', 'r', 'e', 's', '\030', '\"', +' ', '\001', '(', '\013', '2', '\033', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'F', 'e', +'a', 't', 'u', 'r', 'e', 'S', 'e', 't', 'R', '\010', 'f', 'e', 'a', 't', 'u', 'r', 'e', 's', '\022', '%', '\n', '\n', 'd', 'e', 'p', +'r', 'e', 'c', 'a', 't', 'e', 'd', '\030', '!', ' ', '\001', '(', '\010', ':', '\005', 'f', 'a', 'l', 's', 'e', 'R', '\n', 'd', 'e', 'p', +'r', 'e', 'c', 'a', 't', 'e', 'd', '\022', 'X', '\n', '\024', 'u', 'n', 'i', 'n', 't', 'e', 'r', 'p', 'r', 'e', 't', 'e', 'd', '_', +'o', 'p', 't', 'i', 'o', 'n', '\030', '\347', '\007', ' ', '\003', '(', '\013', '2', '$', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', +'o', 't', 'o', 'b', 'u', 'f', '.', 'U', 'n', 'i', 'n', 't', 'e', 'r', 'p', 'r', 'e', 't', 'e', 'd', 'O', 'p', 't', 'i', 'o', +'n', 'R', '\023', 'u', 'n', 'i', 'n', 't', 'e', 'r', 'p', 'r', 'e', 't', 'e', 'd', 'O', 'p', 't', 'i', 'o', 'n', '*', '\t', '\010', +'\350', '\007', '\020', '\200', '\200', '\200', '\200', '\002', '\"', '\231', '\003', '\n', '\r', 'M', 'e', 't', 'h', 'o', 'd', 'O', 'p', 't', 'i', 'o', 'n', +'s', '\022', '%', '\n', '\n', 'd', 'e', 'p', 'r', 'e', 'c', 'a', 't', 'e', 'd', '\030', '!', ' ', '\001', '(', '\010', ':', '\005', 'f', 'a', +'l', 's', 'e', 'R', '\n', 'd', 'e', 'p', 'r', 'e', 'c', 'a', 't', 'e', 'd', '\022', 'q', '\n', '\021', 'i', 'd', 'e', 'm', 'p', 'o', +'t', 'e', 'n', 'c', 'y', '_', 'l', 'e', 'v', 'e', 'l', '\030', '\"', ' ', '\001', '(', '\016', '2', '/', '.', 'g', 'o', 'o', 'g', 'l', +'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'M', 'e', 't', 'h', 'o', 'd', 'O', 'p', 't', 'i', 'o', 'n', 's', '.', +'I', 'd', 'e', 'm', 'p', 'o', 't', 'e', 'n', 'c', 'y', 'L', 'e', 'v', 'e', 'l', ':', '\023', 'I', 'D', 'E', 'M', 'P', 'O', 'T', +'E', 'N', 'C', 'Y', '_', 'U', 'N', 'K', 'N', 'O', 'W', 'N', 'R', '\020', 'i', 'd', 'e', 'm', 'p', 'o', 't', 'e', 'n', 'c', 'y', +'L', 'e', 'v', 'e', 'l', '\022', '7', '\n', '\010', 'f', 'e', 'a', 't', 'u', 'r', 'e', 's', '\030', '#', ' ', '\001', '(', '\013', '2', '\033', +'.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'F', 'e', 'a', 't', 'u', 'r', 'e', 'S', +'e', 't', 'R', '\010', 'f', 'e', 'a', 't', 'u', 'r', 'e', 's', '\022', 'X', '\n', '\024', 'u', 'n', 'i', 'n', 't', 'e', 'r', 'p', 'r', +'e', 't', 'e', 'd', '_', 'o', 'p', 't', 'i', 'o', 'n', '\030', '\347', '\007', ' ', '\003', '(', '\013', '2', '$', '.', 'g', 'o', 'o', 'g', +'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'U', 'n', 'i', 'n', 't', 'e', 'r', 'p', 'r', 'e', 't', 'e', 'd', +'O', 'p', 't', 'i', 'o', 'n', 'R', '\023', 'u', 'n', 'i', 'n', 't', 'e', 'r', 'p', 'r', 'e', 't', 'e', 'd', 'O', 'p', 't', 'i', +'o', 'n', '\"', 'P', '\n', '\020', 'I', 'd', 'e', 'm', 'p', 'o', 't', 'e', 'n', 'c', 'y', 'L', 'e', 'v', 'e', 'l', '\022', '\027', '\n', +'\023', 'I', 'D', 'E', 'M', 'P', 'O', 'T', 'E', 'N', 'C', 'Y', '_', 'U', 'N', 'K', 'N', 'O', 'W', 'N', '\020', '\000', '\022', '\023', '\n', +'\017', 'N', 'O', '_', 'S', 'I', 'D', 'E', '_', 'E', 'F', 'F', 'E', 'C', 'T', 'S', '\020', '\001', '\022', '\016', '\n', '\n', 'I', 'D', 'E', +'M', 'P', 'O', 'T', 'E', 'N', 'T', '\020', '\002', '*', '\t', '\010', '\350', '\007', '\020', '\200', '\200', '\200', '\200', '\002', '\"', '\232', '\003', '\n', '\023', +'U', 'n', 'i', 'n', 't', 'e', 'r', 'p', 'r', 'e', 't', 'e', 'd', 'O', 'p', 't', 'i', 'o', 'n', '\022', 'A', '\n', '\004', 'n', 'a', +'m', 'e', '\030', '\002', ' ', '\003', '(', '\013', '2', '-', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', +'f', '.', 'U', 'n', 'i', 'n', 't', 'e', 'r', 'p', 'r', 'e', 't', 'e', 'd', 'O', 'p', 't', 'i', 'o', 'n', '.', 'N', 'a', 'm', +'e', 'P', 'a', 'r', 't', 'R', '\004', 'n', 'a', 'm', 'e', '\022', ')', '\n', '\020', 'i', 'd', 'e', 'n', 't', 'i', 'f', 'i', 'e', 'r', +'_', 'v', 'a', 'l', 'u', 'e', '\030', '\003', ' ', '\001', '(', '\t', 'R', '\017', 'i', 'd', 'e', 'n', 't', 'i', 'f', 'i', 'e', 'r', 'V', +'a', 'l', 'u', 'e', '\022', ',', '\n', '\022', 'p', 'o', 's', 'i', 't', 'i', 'v', 'e', '_', 'i', 'n', 't', '_', 'v', 'a', 'l', 'u', +'e', '\030', '\004', ' ', '\001', '(', '\004', 'R', '\020', 'p', 'o', 's', 'i', 't', 'i', 'v', 'e', 'I', 'n', 't', 'V', 'a', 'l', 'u', 'e', +'\022', ',', '\n', '\022', 'n', 'e', 'g', 'a', 't', 'i', 'v', 'e', '_', 'i', 'n', 't', '_', 'v', 'a', 'l', 'u', 'e', '\030', '\005', ' ', +'\001', '(', '\003', 'R', '\020', 'n', 'e', 'g', 'a', 't', 'i', 'v', 'e', 'I', 'n', 't', 'V', 'a', 'l', 'u', 'e', '\022', '!', '\n', '\014', +'d', 'o', 'u', 'b', 'l', 'e', '_', 'v', 'a', 'l', 'u', 'e', '\030', '\006', ' ', '\001', '(', '\001', 'R', '\013', 'd', 'o', 'u', 'b', 'l', +'e', 'V', 'a', 'l', 'u', 'e', '\022', '!', '\n', '\014', 's', 't', 'r', 'i', 'n', 'g', '_', 'v', 'a', 'l', 'u', 'e', '\030', '\007', ' ', +'\001', '(', '\014', 'R', '\013', 's', 't', 'r', 'i', 'n', 'g', 'V', 'a', 'l', 'u', 'e', '\022', '\'', '\n', '\017', 'a', 'g', 'g', 'r', 'e', +'g', 'a', 't', 'e', '_', 'v', 'a', 'l', 'u', 'e', '\030', '\010', ' ', '\001', '(', '\t', 'R', '\016', 'a', 'g', 'g', 'r', 'e', 'g', 'a', +'t', 'e', 'V', 'a', 'l', 'u', 'e', '\032', 'J', '\n', '\010', 'N', 'a', 'm', 'e', 'P', 'a', 'r', 't', '\022', '\033', '\n', '\t', 'n', 'a', +'m', 'e', '_', 'p', 'a', 'r', 't', '\030', '\001', ' ', '\002', '(', '\t', 'R', '\010', 'n', 'a', 'm', 'e', 'P', 'a', 'r', 't', '\022', '!', +'\n', '\014', 'i', 's', '_', 'e', 'x', 't', 'e', 'n', 's', 'i', 'o', 'n', '\030', '\002', ' ', '\002', '(', '\010', 'R', '\013', 'i', 's', 'E', +'x', 't', 'e', 'n', 's', 'i', 'o', 'n', '\"', '\374', '\t', '\n', '\n', 'F', 'e', 'a', 't', 'u', 'r', 'e', 'S', 'e', 't', '\022', '\213', +'\001', '\n', '\016', 'f', 'i', 'e', 'l', 'd', '_', 'p', 'r', 'e', 's', 'e', 'n', 'c', 'e', '\030', '\001', ' ', '\001', '(', '\016', '2', ')', +'.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'F', 'e', 'a', 't', 'u', 'r', 'e', 'S', +'e', 't', '.', 'F', 'i', 'e', 'l', 'd', 'P', 'r', 'e', 's', 'e', 'n', 'c', 'e', 'B', '9', '\210', '\001', '\001', '\230', '\001', '\004', '\230', +'\001', '\001', '\242', '\001', '\r', '\022', '\010', 'E', 'X', 'P', 'L', 'I', 'C', 'I', 'T', '\030', '\346', '\007', '\242', '\001', '\r', '\022', '\010', 'I', 'M', +'P', 'L', 'I', 'C', 'I', 'T', '\030', '\347', '\007', '\242', '\001', '\r', '\022', '\010', 'E', 'X', 'P', 'L', 'I', 'C', 'I', 'T', '\030', '\350', '\007', +'R', '\r', 'f', 'i', 'e', 'l', 'd', 'P', 'r', 'e', 's', 'e', 'n', 'c', 'e', '\022', 'f', '\n', '\t', 'e', 'n', 'u', 'm', '_', 't', +'y', 'p', 'e', '\030', '\002', ' ', '\001', '(', '\016', '2', '$', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', +'u', 'f', '.', 'F', 'e', 'a', 't', 'u', 'r', 'e', 'S', 'e', 't', '.', 'E', 'n', 'u', 'm', 'T', 'y', 'p', 'e', 'B', '#', '\210', +'\001', '\001', '\230', '\001', '\006', '\230', '\001', '\001', '\242', '\001', '\013', '\022', '\006', 'C', 'L', 'O', 'S', 'E', 'D', '\030', '\346', '\007', '\242', '\001', '\t', +'\022', '\004', 'O', 'P', 'E', 'N', '\030', '\347', '\007', 'R', '\010', 'e', 'n', 'u', 'm', 'T', 'y', 'p', 'e', '\022', '\222', '\001', '\n', '\027', 'r', +'e', 'p', 'e', 'a', 't', 'e', 'd', '_', 'f', 'i', 'e', 'l', 'd', '_', 'e', 'n', 'c', 'o', 'd', 'i', 'n', 'g', '\030', '\003', ' ', +'\001', '(', '\016', '2', '1', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'F', 'e', 'a', +'t', 'u', 'r', 'e', 'S', 'e', 't', '.', 'R', 'e', 'p', 'e', 'a', 't', 'e', 'd', 'F', 'i', 'e', 'l', 'd', 'E', 'n', 'c', 'o', +'d', 'i', 'n', 'g', 'B', '\'', '\210', '\001', '\001', '\230', '\001', '\004', '\230', '\001', '\001', '\242', '\001', '\r', '\022', '\010', 'E', 'X', 'P', 'A', 'N', +'D', 'E', 'D', '\030', '\346', '\007', '\242', '\001', '\013', '\022', '\006', 'P', 'A', 'C', 'K', 'E', 'D', '\030', '\347', '\007', 'R', '\025', 'r', 'e', 'p', +'e', 'a', 't', 'e', 'd', 'F', 'i', 'e', 'l', 'd', 'E', 'n', 'c', 'o', 'd', 'i', 'n', 'g', '\022', 'x', '\n', '\017', 'u', 't', 'f', +'8', '_', 'v', 'a', 'l', 'i', 'd', 'a', 't', 'i', 'o', 'n', '\030', '\004', ' ', '\001', '(', '\016', '2', '*', '.', 'g', 'o', 'o', 'g', +'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'F', 'e', 'a', 't', 'u', 'r', 'e', 'S', 'e', 't', '.', 'U', 't', +'f', '8', 'V', 'a', 'l', 'i', 'd', 'a', 't', 'i', 'o', 'n', 'B', '#', '\210', '\001', '\001', '\230', '\001', '\004', '\230', '\001', '\001', '\242', '\001', +'\t', '\022', '\004', 'N', 'O', 'N', 'E', '\030', '\346', '\007', '\242', '\001', '\013', '\022', '\006', 'V', 'E', 'R', 'I', 'F', 'Y', '\030', '\347', '\007', 'R', +'\016', 'u', 't', 'f', '8', 'V', 'a', 'l', 'i', 'd', 'a', 't', 'i', 'o', 'n', '\022', 'x', '\n', '\020', 'm', 'e', 's', 's', 'a', 'g', +'e', '_', 'e', 'n', 'c', 'o', 'd', 'i', 'n', 'g', '\030', '\005', ' ', '\001', '(', '\016', '2', '+', '.', 'g', 'o', 'o', 'g', 'l', 'e', +'.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'F', 'e', 'a', 't', 'u', 'r', 'e', 'S', 'e', 't', '.', 'M', 'e', 's', 's', +'a', 'g', 'e', 'E', 'n', 'c', 'o', 'd', 'i', 'n', 'g', 'B', ' ', '\210', '\001', '\001', '\230', '\001', '\004', '\230', '\001', '\001', '\242', '\001', '\024', +'\022', '\017', 'L', 'E', 'N', 'G', 'T', 'H', '_', 'P', 'R', 'E', 'F', 'I', 'X', 'E', 'D', '\030', '\346', '\007', 'R', '\017', 'm', 'e', 's', +'s', 'a', 'g', 'e', 'E', 'n', 'c', 'o', 'd', 'i', 'n', 'g', '\022', '|', '\n', '\013', 'j', 's', 'o', 'n', '_', 'f', 'o', 'r', 'm', +'a', 't', '\030', '\006', ' ', '\001', '(', '\016', '2', '&', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', +'f', '.', 'F', 'e', 'a', 't', 'u', 'r', 'e', 'S', 'e', 't', '.', 'J', 's', 'o', 'n', 'F', 'o', 'r', 'm', 'a', 't', 'B', '3', +'\210', '\001', '\001', '\230', '\001', '\003', '\230', '\001', '\006', '\230', '\001', '\001', '\242', '\001', '\027', '\022', '\022', 'L', 'E', 'G', 'A', 'C', 'Y', '_', 'B', +'E', 'S', 'T', '_', 'E', 'F', 'F', 'O', 'R', 'T', '\030', '\346', '\007', '\242', '\001', '\n', '\022', '\005', 'A', 'L', 'L', 'O', 'W', '\030', '\347', +'\007', 'R', '\n', 'j', 's', 'o', 'n', 'F', 'o', 'r', 'm', 'a', 't', '\"', '\\', '\n', '\r', 'F', 'i', 'e', 'l', 'd', 'P', 'r', 'e', +'s', 'e', 'n', 'c', 'e', '\022', '\032', '\n', '\026', 'F', 'I', 'E', 'L', 'D', '_', 'P', 'R', 'E', 'S', 'E', 'N', 'C', 'E', '_', 'U', +'N', 'K', 'N', 'O', 'W', 'N', '\020', '\000', '\022', '\014', '\n', '\010', 'E', 'X', 'P', 'L', 'I', 'C', 'I', 'T', '\020', '\001', '\022', '\014', '\n', +'\010', 'I', 'M', 'P', 'L', 'I', 'C', 'I', 'T', '\020', '\002', '\022', '\023', '\n', '\017', 'L', 'E', 'G', 'A', 'C', 'Y', '_', 'R', 'E', 'Q', +'U', 'I', 'R', 'E', 'D', '\020', '\003', '\"', '7', '\n', '\010', 'E', 'n', 'u', 'm', 'T', 'y', 'p', 'e', '\022', '\025', '\n', '\021', 'E', 'N', +'U', 'M', '_', 'T', 'Y', 'P', 'E', '_', 'U', 'N', 'K', 'N', 'O', 'W', 'N', '\020', '\000', '\022', '\010', '\n', '\004', 'O', 'P', 'E', 'N', +'\020', '\001', '\022', '\n', '\n', '\006', 'C', 'L', 'O', 'S', 'E', 'D', '\020', '\002', '\"', 'V', '\n', '\025', 'R', 'e', 'p', 'e', 'a', 't', 'e', +'d', 'F', 'i', 'e', 'l', 'd', 'E', 'n', 'c', 'o', 'd', 'i', 'n', 'g', '\022', '#', '\n', '\037', 'R', 'E', 'P', 'E', 'A', 'T', 'E', +'D', '_', 'F', 'I', 'E', 'L', 'D', '_', 'E', 'N', 'C', 'O', 'D', 'I', 'N', 'G', '_', 'U', 'N', 'K', 'N', 'O', 'W', 'N', '\020', +'\000', '\022', '\n', '\n', '\006', 'P', 'A', 'C', 'K', 'E', 'D', '\020', '\001', '\022', '\014', '\n', '\010', 'E', 'X', 'P', 'A', 'N', 'D', 'E', 'D', +'\020', '\002', '\"', 'C', '\n', '\016', 'U', 't', 'f', '8', 'V', 'a', 'l', 'i', 'd', 'a', 't', 'i', 'o', 'n', '\022', '\033', '\n', '\027', 'U', +'T', 'F', '8', '_', 'V', 'A', 'L', 'I', 'D', 'A', 'T', 'I', 'O', 'N', '_', 'U', 'N', 'K', 'N', 'O', 'W', 'N', '\020', '\000', '\022', +'\n', '\n', '\006', 'V', 'E', 'R', 'I', 'F', 'Y', '\020', '\002', '\022', '\010', '\n', '\004', 'N', 'O', 'N', 'E', '\020', '\003', '\"', 'S', '\n', '\017', +'M', 'e', 's', 's', 'a', 'g', 'e', 'E', 'n', 'c', 'o', 'd', 'i', 'n', 'g', '\022', '\034', '\n', '\030', 'M', 'E', 'S', 'S', 'A', 'G', +'E', '_', 'E', 'N', 'C', 'O', 'D', 'I', 'N', 'G', '_', 'U', 'N', 'K', 'N', 'O', 'W', 'N', '\020', '\000', '\022', '\023', '\n', '\017', 'L', +'E', 'N', 'G', 'T', 'H', '_', 'P', 'R', 'E', 'F', 'I', 'X', 'E', 'D', '\020', '\001', '\022', '\r', '\n', '\t', 'D', 'E', 'L', 'I', 'M', +'I', 'T', 'E', 'D', '\020', '\002', '\"', 'H', '\n', '\n', 'J', 's', 'o', 'n', 'F', 'o', 'r', 'm', 'a', 't', '\022', '\027', '\n', '\023', 'J', +'S', 'O', 'N', '_', 'F', 'O', 'R', 'M', 'A', 'T', '_', 'U', 'N', 'K', 'N', 'O', 'W', 'N', '\020', '\000', '\022', '\t', '\n', '\005', 'A', +'L', 'L', 'O', 'W', '\020', '\001', '\022', '\026', '\n', '\022', 'L', 'E', 'G', 'A', 'C', 'Y', '_', 'B', 'E', 'S', 'T', '_', 'E', 'F', 'F', +'O', 'R', 'T', '\020', '\002', '*', '\006', '\010', '\350', '\007', '\020', '\351', '\007', '*', '\006', '\010', '\351', '\007', '\020', '\352', '\007', '*', '\006', '\010', '\213', +'N', '\020', '\220', 'N', 'J', '\006', '\010', '\347', '\007', '\020', '\350', '\007', '\"', '\376', '\002', '\n', '\022', 'F', 'e', 'a', 't', 'u', 'r', 'e', 'S', +'e', 't', 'D', 'e', 'f', 'a', 'u', 'l', 't', 's', '\022', 'X', '\n', '\010', 'd', 'e', 'f', 'a', 'u', 'l', 't', 's', '\030', '\001', ' ', +'\003', '(', '\013', '2', '<', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'F', 'e', 'a', +'t', 'u', 'r', 'e', 'S', 'e', 't', 'D', 'e', 'f', 'a', 'u', 'l', 't', 's', '.', 'F', 'e', 'a', 't', 'u', 'r', 'e', 'S', 'e', +'t', 'E', 'd', 'i', 't', 'i', 'o', 'n', 'D', 'e', 'f', 'a', 'u', 'l', 't', 'R', '\010', 'd', 'e', 'f', 'a', 'u', 'l', 't', 's', +'\022', 'A', '\n', '\017', 'm', 'i', 'n', 'i', 'm', 'u', 'm', '_', 'e', 'd', 'i', 't', 'i', 'o', 'n', '\030', '\004', ' ', '\001', '(', '\016', +'2', '\030', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'E', 'd', 'i', 't', 'i', 'o', +'n', 'R', '\016', 'm', 'i', 'n', 'i', 'm', 'u', 'm', 'E', 'd', 'i', 't', 'i', 'o', 'n', '\022', 'A', '\n', '\017', 'm', 'a', 'x', 'i', +'m', 'u', 'm', '_', 'e', 'd', 'i', 't', 'i', 'o', 'n', '\030', '\005', ' ', '\001', '(', '\016', '2', '\030', '.', 'g', 'o', 'o', 'g', 'l', +'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'E', 'd', 'i', 't', 'i', 'o', 'n', 'R', '\016', 'm', 'a', 'x', 'i', 'm', +'u', 'm', 'E', 'd', 'i', 't', 'i', 'o', 'n', '\032', '\207', '\001', '\n', '\030', 'F', 'e', 'a', 't', 'u', 'r', 'e', 'S', 'e', 't', 'E', +'d', 'i', 't', 'i', 'o', 'n', 'D', 'e', 'f', 'a', 'u', 'l', 't', '\022', '2', '\n', '\007', 'e', 'd', 'i', 't', 'i', 'o', 'n', '\030', +'\003', ' ', '\001', '(', '\016', '2', '\030', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'E', +'d', 'i', 't', 'i', 'o', 'n', 'R', '\007', 'e', 'd', 'i', 't', 'i', 'o', 'n', '\022', '7', '\n', '\010', 'f', 'e', 'a', 't', 'u', 'r', +'e', 's', '\030', '\002', ' ', '\001', '(', '\013', '2', '\033', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', +'f', '.', 'F', 'e', 'a', 't', 'u', 'r', 'e', 'S', 'e', 't', 'R', '\010', 'f', 'e', 'a', 't', 'u', 'r', 'e', 's', '\"', '\247', '\002', +'\n', '\016', 'S', 'o', 'u', 'r', 'c', 'e', 'C', 'o', 'd', 'e', 'I', 'n', 'f', 'o', '\022', 'D', '\n', '\010', 'l', 'o', 'c', 'a', 't', +'i', 'o', 'n', '\030', '\001', ' ', '\003', '(', '\013', '2', '(', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', +'u', 'f', '.', 'S', 'o', 'u', 'r', 'c', 'e', 'C', 'o', 'd', 'e', 'I', 'n', 'f', 'o', '.', 'L', 'o', 'c', 'a', 't', 'i', 'o', +'n', 'R', '\010', 'l', 'o', 'c', 'a', 't', 'i', 'o', 'n', '\032', '\316', '\001', '\n', '\010', 'L', 'o', 'c', 'a', 't', 'i', 'o', 'n', '\022', +'\026', '\n', '\004', 'p', 'a', 't', 'h', '\030', '\001', ' ', '\003', '(', '\005', 'B', '\002', '\020', '\001', 'R', '\004', 'p', 'a', 't', 'h', '\022', '\026', +'\n', '\004', 's', 'p', 'a', 'n', '\030', '\002', ' ', '\003', '(', '\005', 'B', '\002', '\020', '\001', 'R', '\004', 's', 'p', 'a', 'n', '\022', ')', '\n', +'\020', 'l', 'e', 'a', 'd', 'i', 'n', 'g', '_', 'c', 'o', 'm', 'm', 'e', 'n', 't', 's', '\030', '\003', ' ', '\001', '(', '\t', 'R', '\017', +'l', 'e', 'a', 'd', 'i', 'n', 'g', 'C', 'o', 'm', 'm', 'e', 'n', 't', 's', '\022', '+', '\n', '\021', 't', 'r', 'a', 'i', 'l', 'i', +'n', 'g', '_', 'c', 'o', 'm', 'm', 'e', 'n', 't', 's', '\030', '\004', ' ', '\001', '(', '\t', 'R', '\020', 't', 'r', 'a', 'i', 'l', 'i', +'n', 'g', 'C', 'o', 'm', 'm', 'e', 'n', 't', 's', '\022', ':', '\n', '\031', 'l', 'e', 'a', 'd', 'i', 'n', 'g', '_', 'd', 'e', 't', +'a', 'c', 'h', 'e', 'd', '_', 'c', 'o', 'm', 'm', 'e', 'n', 't', 's', '\030', '\006', ' ', '\003', '(', '\t', 'R', '\027', 'l', 'e', 'a', +'d', 'i', 'n', 'g', 'D', 'e', 't', 'a', 'c', 'h', 'e', 'd', 'C', 'o', 'm', 'm', 'e', 'n', 't', 's', '\"', '\320', '\002', '\n', '\021', +'G', 'e', 'n', 'e', 'r', 'a', 't', 'e', 'd', 'C', 'o', 'd', 'e', 'I', 'n', 'f', 'o', '\022', 'M', '\n', '\n', 'a', 'n', 'n', 'o', +'t', 'a', 't', 'i', 'o', 'n', '\030', '\001', ' ', '\003', '(', '\013', '2', '-', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', +'t', 'o', 'b', 'u', 'f', '.', 'G', 'e', 'n', 'e', 'r', 'a', 't', 'e', 'd', 'C', 'o', 'd', 'e', 'I', 'n', 'f', 'o', '.', 'A', +'n', 'n', 'o', 't', 'a', 't', 'i', 'o', 'n', 'R', '\n', 'a', 'n', 'n', 'o', 't', 'a', 't', 'i', 'o', 'n', '\032', '\353', '\001', '\n', +'\n', 'A', 'n', 'n', 'o', 't', 'a', 't', 'i', 'o', 'n', '\022', '\026', '\n', '\004', 'p', 'a', 't', 'h', '\030', '\001', ' ', '\003', '(', '\005', +'B', '\002', '\020', '\001', 'R', '\004', 'p', 'a', 't', 'h', '\022', '\037', '\n', '\013', 's', 'o', 'u', 'r', 'c', 'e', '_', 'f', 'i', 'l', 'e', +'\030', '\002', ' ', '\001', '(', '\t', 'R', '\n', 's', 'o', 'u', 'r', 'c', 'e', 'F', 'i', 'l', 'e', '\022', '\024', '\n', '\005', 'b', 'e', 'g', +'i', 'n', '\030', '\003', ' ', '\001', '(', '\005', 'R', '\005', 'b', 'e', 'g', 'i', 'n', '\022', '\020', '\n', '\003', 'e', 'n', 'd', '\030', '\004', ' ', +'\001', '(', '\005', 'R', '\003', 'e', 'n', 'd', '\022', 'R', '\n', '\010', 's', 'e', 'm', 'a', 'n', 't', 'i', 'c', '\030', '\005', ' ', '\001', '(', +'\016', '2', '6', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'G', 'e', 'n', 'e', 'r', +'a', 't', 'e', 'd', 'C', 'o', 'd', 'e', 'I', 'n', 'f', 'o', '.', 'A', 'n', 'n', 'o', 't', 'a', 't', 'i', 'o', 'n', '.', 'S', +'e', 'm', 'a', 'n', 't', 'i', 'c', 'R', '\010', 's', 'e', 'm', 'a', 'n', 't', 'i', 'c', '\"', '(', '\n', '\010', 'S', 'e', 'm', 'a', +'n', 't', 'i', 'c', '\022', '\010', '\n', '\004', 'N', 'O', 'N', 'E', '\020', '\000', '\022', '\007', '\n', '\003', 'S', 'E', 'T', '\020', '\001', '\022', '\t', +'\n', '\005', 'A', 'L', 'I', 'A', 'S', '\020', '\002', '*', '\377', '\001', '\n', '\007', 'E', 'd', 'i', 't', 'i', 'o', 'n', '\022', '\023', '\n', '\017', +'E', 'D', 'I', 'T', 'I', 'O', 'N', '_', 'U', 'N', 'K', 'N', 'O', 'W', 'N', '\020', '\000', '\022', '\023', '\n', '\016', 'E', 'D', 'I', 'T', +'I', 'O', 'N', '_', 'P', 'R', 'O', 'T', 'O', '2', '\020', '\346', '\007', '\022', '\023', '\n', '\016', 'E', 'D', 'I', 'T', 'I', 'O', 'N', '_', +'P', 'R', 'O', 'T', 'O', '3', '\020', '\347', '\007', '\022', '\021', '\n', '\014', 'E', 'D', 'I', 'T', 'I', 'O', 'N', '_', '2', '0', '2', '3', +'\020', '\350', '\007', '\022', '\027', '\n', '\023', 'E', 'D', 'I', 'T', 'I', 'O', 'N', '_', '1', '_', 'T', 'E', 'S', 'T', '_', 'O', 'N', 'L', +'Y', '\020', '\001', '\022', '\027', '\n', '\023', 'E', 'D', 'I', 'T', 'I', 'O', 'N', '_', '2', '_', 'T', 'E', 'S', 'T', '_', 'O', 'N', 'L', +'Y', '\020', '\002', '\022', '\035', '\n', '\027', 'E', 'D', 'I', 'T', 'I', 'O', 'N', '_', '9', '9', '9', '9', '7', '_', 'T', 'E', 'S', 'T', +'_', 'O', 'N', 'L', 'Y', '\020', '\235', '\215', '\006', '\022', '\035', '\n', '\027', 'E', 'D', 'I', 'T', 'I', 'O', 'N', '_', '9', '9', '9', '9', +'8', '_', 'T', 'E', 'S', 'T', '_', 'O', 'N', 'L', 'Y', '\020', '\236', '\215', '\006', '\022', '\035', '\n', '\027', 'E', 'D', 'I', 'T', 'I', 'O', +'N', '_', '9', '9', '9', '9', '9', '_', 'T', 'E', 'S', 'T', '_', 'O', 'N', 'L', 'Y', '\020', '\237', '\215', '\006', '\022', '\023', '\n', '\013', +'E', 'D', 'I', 'T', 'I', 'O', 'N', '_', 'M', 'A', 'X', '\020', '\377', '\377', '\377', '\377', '\007', 'B', '~', '\n', '\023', 'c', 'o', 'm', '.', +'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', 'B', '\020', 'D', 'e', 's', 'c', 'r', 'i', 'p', 't', +'o', 'r', 'P', 'r', 'o', 't', 'o', 's', 'H', '\001', 'Z', '-', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'g', 'o', 'l', 'a', 'n', 'g', +'.', 'o', 'r', 'g', '/', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '/', 't', 'y', 'p', 'e', 's', '/', 'd', 'e', 's', 'c', 'r', +'i', 'p', 't', 'o', 'r', 'p', 'b', '\370', '\001', '\001', '\242', '\002', '\003', 'G', 'P', 'B', '\252', '\002', '\032', 'G', 'o', 'o', 'g', 'l', 'e', +'.', 'P', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'R', 'e', 'f', 'l', 'e', 'c', 't', 'i', 'o', 'n', }; static _upb_DefPool_Init *deps[1] = { @@ -2224,7 +2221,7 @@ _upb_DefPool_Init google_protobuf_descriptor_proto_upbdefinit = { deps, &google_protobuf_descriptor_proto_upb_file_layout, "google/protobuf/descriptor.proto", - UPB_STRINGVIEW_INIT(descriptor, 11646) + UPB_STRINGVIEW_INIT(descriptor, 11595) }; diff --git a/php/ext/google/protobuf/php-upb.h b/php/ext/google/protobuf/php-upb.h index 60e333a53bc80..e2c35bb45e153 100644 --- a/php/ext/google/protobuf/php-upb.h +++ b/php/ext/google/protobuf/php-upb.h @@ -7327,33 +7327,33 @@ UPB_INLINE char* google_protobuf_FileOptions_serialize_ex(const google_protobuf_ return ptr; } UPB_INLINE void google_protobuf_FileOptions_clear_java_package(google_protobuf_FileOptions* msg) { - const upb_MiniTableField field = {1, UPB_SIZE(28, 24), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; + const upb_MiniTableField field = {1, UPB_SIZE(24, 16), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; _upb_Message_ClearNonExtensionField(msg, &field); } UPB_INLINE upb_StringView google_protobuf_FileOptions_java_package(const google_protobuf_FileOptions* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; - const upb_MiniTableField field = {1, UPB_SIZE(28, 24), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; + const upb_MiniTableField field = {1, UPB_SIZE(24, 16), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FileOptions_has_java_package(const google_protobuf_FileOptions* msg) { - const upb_MiniTableField field = {1, UPB_SIZE(28, 24), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; + const upb_MiniTableField field = {1, UPB_SIZE(24, 16), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; return _upb_Message_HasNonExtensionField(msg, &field); } UPB_INLINE void google_protobuf_FileOptions_clear_java_outer_classname(google_protobuf_FileOptions* msg) { - const upb_MiniTableField field = {8, UPB_SIZE(36, 40), 2, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; + const upb_MiniTableField field = {8, 32, 2, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; _upb_Message_ClearNonExtensionField(msg, &field); } UPB_INLINE upb_StringView google_protobuf_FileOptions_java_outer_classname(const google_protobuf_FileOptions* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; - const upb_MiniTableField field = {8, UPB_SIZE(36, 40), 2, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; + const upb_MiniTableField field = {8, 32, 2, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FileOptions_has_java_outer_classname(const google_protobuf_FileOptions* msg) { - const upb_MiniTableField field = {8, UPB_SIZE(36, 40), 2, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; + const upb_MiniTableField field = {8, 32, 2, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; return _upb_Message_HasNonExtensionField(msg, &field); } UPB_INLINE void google_protobuf_FileOptions_clear_optimize_for(google_protobuf_FileOptions* msg) { @@ -7387,18 +7387,18 @@ UPB_INLINE bool google_protobuf_FileOptions_has_java_multiple_files(const google return _upb_Message_HasNonExtensionField(msg, &field); } UPB_INLINE void google_protobuf_FileOptions_clear_go_package(google_protobuf_FileOptions* msg) { - const upb_MiniTableField field = {11, UPB_SIZE(44, 56), 5, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; + const upb_MiniTableField field = {11, UPB_SIZE(40, 48), 5, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; _upb_Message_ClearNonExtensionField(msg, &field); } UPB_INLINE upb_StringView google_protobuf_FileOptions_go_package(const google_protobuf_FileOptions* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; - const upb_MiniTableField field = {11, UPB_SIZE(44, 56), 5, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; + const upb_MiniTableField field = {11, UPB_SIZE(40, 48), 5, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FileOptions_has_go_package(const google_protobuf_FileOptions* msg) { - const upb_MiniTableField field = {11, UPB_SIZE(44, 56), 5, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; + const upb_MiniTableField field = {11, UPB_SIZE(40, 48), 5, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; return _upb_Message_HasNonExtensionField(msg, &field); } UPB_INLINE void google_protobuf_FileOptions_clear_cc_generic_services(google_protobuf_FileOptions* msg) { @@ -7507,146 +7507,131 @@ UPB_INLINE bool google_protobuf_FileOptions_has_cc_enable_arenas(const google_pr return _upb_Message_HasNonExtensionField(msg, &field); } UPB_INLINE void google_protobuf_FileOptions_clear_objc_class_prefix(google_protobuf_FileOptions* msg) { - const upb_MiniTableField field = {36, UPB_SIZE(52, 72), 13, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; + const upb_MiniTableField field = {36, UPB_SIZE(48, 64), 13, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; _upb_Message_ClearNonExtensionField(msg, &field); } UPB_INLINE upb_StringView google_protobuf_FileOptions_objc_class_prefix(const google_protobuf_FileOptions* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; - const upb_MiniTableField field = {36, UPB_SIZE(52, 72), 13, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; + const upb_MiniTableField field = {36, UPB_SIZE(48, 64), 13, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FileOptions_has_objc_class_prefix(const google_protobuf_FileOptions* msg) { - const upb_MiniTableField field = {36, UPB_SIZE(52, 72), 13, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; + const upb_MiniTableField field = {36, UPB_SIZE(48, 64), 13, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; return _upb_Message_HasNonExtensionField(msg, &field); } UPB_INLINE void google_protobuf_FileOptions_clear_csharp_namespace(google_protobuf_FileOptions* msg) { - const upb_MiniTableField field = {37, UPB_SIZE(60, 88), 14, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; + const upb_MiniTableField field = {37, UPB_SIZE(56, 80), 14, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; _upb_Message_ClearNonExtensionField(msg, &field); } UPB_INLINE upb_StringView google_protobuf_FileOptions_csharp_namespace(const google_protobuf_FileOptions* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; - const upb_MiniTableField field = {37, UPB_SIZE(60, 88), 14, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; + const upb_MiniTableField field = {37, UPB_SIZE(56, 80), 14, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FileOptions_has_csharp_namespace(const google_protobuf_FileOptions* msg) { - const upb_MiniTableField field = {37, UPB_SIZE(60, 88), 14, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; + const upb_MiniTableField field = {37, UPB_SIZE(56, 80), 14, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; return _upb_Message_HasNonExtensionField(msg, &field); } UPB_INLINE void google_protobuf_FileOptions_clear_swift_prefix(google_protobuf_FileOptions* msg) { - const upb_MiniTableField field = {39, UPB_SIZE(68, 104), 15, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; + const upb_MiniTableField field = {39, UPB_SIZE(64, 96), 15, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; _upb_Message_ClearNonExtensionField(msg, &field); } UPB_INLINE upb_StringView google_protobuf_FileOptions_swift_prefix(const google_protobuf_FileOptions* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; - const upb_MiniTableField field = {39, UPB_SIZE(68, 104), 15, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; + const upb_MiniTableField field = {39, UPB_SIZE(64, 96), 15, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FileOptions_has_swift_prefix(const google_protobuf_FileOptions* msg) { - const upb_MiniTableField field = {39, UPB_SIZE(68, 104), 15, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; + const upb_MiniTableField field = {39, UPB_SIZE(64, 96), 15, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; return _upb_Message_HasNonExtensionField(msg, &field); } UPB_INLINE void google_protobuf_FileOptions_clear_php_class_prefix(google_protobuf_FileOptions* msg) { - const upb_MiniTableField field = {40, UPB_SIZE(76, 120), 16, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; + const upb_MiniTableField field = {40, UPB_SIZE(72, 112), 16, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; _upb_Message_ClearNonExtensionField(msg, &field); } UPB_INLINE upb_StringView google_protobuf_FileOptions_php_class_prefix(const google_protobuf_FileOptions* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; - const upb_MiniTableField field = {40, UPB_SIZE(76, 120), 16, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; + const upb_MiniTableField field = {40, UPB_SIZE(72, 112), 16, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FileOptions_has_php_class_prefix(const google_protobuf_FileOptions* msg) { - const upb_MiniTableField field = {40, UPB_SIZE(76, 120), 16, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; + const upb_MiniTableField field = {40, UPB_SIZE(72, 112), 16, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; return _upb_Message_HasNonExtensionField(msg, &field); } UPB_INLINE void google_protobuf_FileOptions_clear_php_namespace(google_protobuf_FileOptions* msg) { - const upb_MiniTableField field = {41, UPB_SIZE(84, 136), 17, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; + const upb_MiniTableField field = {41, UPB_SIZE(80, 128), 17, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; _upb_Message_ClearNonExtensionField(msg, &field); } UPB_INLINE upb_StringView google_protobuf_FileOptions_php_namespace(const google_protobuf_FileOptions* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; - const upb_MiniTableField field = {41, UPB_SIZE(84, 136), 17, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; + const upb_MiniTableField field = {41, UPB_SIZE(80, 128), 17, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FileOptions_has_php_namespace(const google_protobuf_FileOptions* msg) { - const upb_MiniTableField field = {41, UPB_SIZE(84, 136), 17, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); -} -UPB_INLINE void google_protobuf_FileOptions_clear_php_generic_services(google_protobuf_FileOptions* msg) { - const upb_MiniTableField field = {42, 16, 18, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); -} -UPB_INLINE bool google_protobuf_FileOptions_php_generic_services(const google_protobuf_FileOptions* msg) { - bool default_val = false; - bool ret; - const upb_MiniTableField field = {42, 16, 18, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_FileOptions_has_php_generic_services(const google_protobuf_FileOptions* msg) { - const upb_MiniTableField field = {42, 16, 18, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; + const upb_MiniTableField field = {41, UPB_SIZE(80, 128), 17, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; return _upb_Message_HasNonExtensionField(msg, &field); } UPB_INLINE void google_protobuf_FileOptions_clear_php_metadata_namespace(google_protobuf_FileOptions* msg) { - const upb_MiniTableField field = {44, UPB_SIZE(92, 152), 19, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; + const upb_MiniTableField field = {44, UPB_SIZE(88, 144), 18, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; _upb_Message_ClearNonExtensionField(msg, &field); } UPB_INLINE upb_StringView google_protobuf_FileOptions_php_metadata_namespace(const google_protobuf_FileOptions* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; - const upb_MiniTableField field = {44, UPB_SIZE(92, 152), 19, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; + const upb_MiniTableField field = {44, UPB_SIZE(88, 144), 18, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FileOptions_has_php_metadata_namespace(const google_protobuf_FileOptions* msg) { - const upb_MiniTableField field = {44, UPB_SIZE(92, 152), 19, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; + const upb_MiniTableField field = {44, UPB_SIZE(88, 144), 18, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; return _upb_Message_HasNonExtensionField(msg, &field); } UPB_INLINE void google_protobuf_FileOptions_clear_ruby_package(google_protobuf_FileOptions* msg) { - const upb_MiniTableField field = {45, UPB_SIZE(100, 168), 20, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; + const upb_MiniTableField field = {45, UPB_SIZE(96, 160), 19, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; _upb_Message_ClearNonExtensionField(msg, &field); } UPB_INLINE upb_StringView google_protobuf_FileOptions_ruby_package(const google_protobuf_FileOptions* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; - const upb_MiniTableField field = {45, UPB_SIZE(100, 168), 20, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; + const upb_MiniTableField field = {45, UPB_SIZE(96, 160), 19, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FileOptions_has_ruby_package(const google_protobuf_FileOptions* msg) { - const upb_MiniTableField field = {45, UPB_SIZE(100, 168), 20, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; + const upb_MiniTableField field = {45, UPB_SIZE(96, 160), 19, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; return _upb_Message_HasNonExtensionField(msg, &field); } UPB_INLINE void google_protobuf_FileOptions_clear_features(google_protobuf_FileOptions* msg) { - const upb_MiniTableField field = {50, UPB_SIZE(20, 184), 21, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; + const upb_MiniTableField field = {50, UPB_SIZE(16, 176), 20, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; _upb_Message_ClearNonExtensionField(msg, &field); } UPB_INLINE const google_protobuf_FeatureSet* google_protobuf_FileOptions_features(const google_protobuf_FileOptions* msg) { const google_protobuf_FeatureSet* default_val = NULL; const google_protobuf_FeatureSet* ret; - const upb_MiniTableField field = {50, UPB_SIZE(20, 184), 21, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; + const upb_MiniTableField field = {50, UPB_SIZE(16, 176), 20, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FileOptions_has_features(const google_protobuf_FileOptions* msg) { - const upb_MiniTableField field = {50, UPB_SIZE(20, 184), 21, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; + const upb_MiniTableField field = {50, UPB_SIZE(16, 176), 20, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; return _upb_Message_HasNonExtensionField(msg, &field); } UPB_INLINE void google_protobuf_FileOptions_clear_uninterpreted_option(google_protobuf_FileOptions* msg) { - const upb_MiniTableField field = {999, UPB_SIZE(24, 192), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; + const upb_MiniTableField field = {999, UPB_SIZE(20, 184), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; _upb_Message_ClearNonExtensionField(msg, &field); } UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_FileOptions_uninterpreted_option(const google_protobuf_FileOptions* msg, size_t* size) { - const upb_MiniTableField field = {999, UPB_SIZE(24, 192), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; + const upb_MiniTableField field = {999, UPB_SIZE(20, 184), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); @@ -7657,7 +7642,7 @@ UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_Fil } } UPB_INLINE const upb_Array* _google_protobuf_FileOptions_uninterpreted_option_upb_array(const google_protobuf_FileOptions* msg, size_t* size) { - const upb_MiniTableField field = {999, UPB_SIZE(24, 192), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; + const upb_MiniTableField field = {999, UPB_SIZE(20, 184), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; @@ -7665,7 +7650,7 @@ UPB_INLINE const upb_Array* _google_protobuf_FileOptions_uninterpreted_option_up return arr; } UPB_INLINE upb_Array* _google_protobuf_FileOptions_uninterpreted_option_mutable_upb_array(const google_protobuf_FileOptions* msg, size_t* size, upb_Arena* arena) { - const upb_MiniTableField field = {999, UPB_SIZE(24, 192), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; + const upb_MiniTableField field = {999, UPB_SIZE(20, 184), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetOrCreateMutableArray( (upb_Message*)msg, &field, arena); if (size) { @@ -7675,11 +7660,11 @@ UPB_INLINE upb_Array* _google_protobuf_FileOptions_uninterpreted_option_mutable_ } UPB_INLINE void google_protobuf_FileOptions_set_java_package(google_protobuf_FileOptions *msg, upb_StringView value) { - const upb_MiniTableField field = {1, UPB_SIZE(28, 24), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; + const upb_MiniTableField field = {1, UPB_SIZE(24, 16), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; _upb_Message_SetNonExtensionField(msg, &field, &value); } UPB_INLINE void google_protobuf_FileOptions_set_java_outer_classname(google_protobuf_FileOptions *msg, upb_StringView value) { - const upb_MiniTableField field = {8, UPB_SIZE(36, 40), 2, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; + const upb_MiniTableField field = {8, 32, 2, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; _upb_Message_SetNonExtensionField(msg, &field, &value); } UPB_INLINE void google_protobuf_FileOptions_set_optimize_for(google_protobuf_FileOptions *msg, int32_t value) { @@ -7691,7 +7676,7 @@ UPB_INLINE void google_protobuf_FileOptions_set_java_multiple_files(google_proto _upb_Message_SetNonExtensionField(msg, &field, &value); } UPB_INLINE void google_protobuf_FileOptions_set_go_package(google_protobuf_FileOptions *msg, upb_StringView value) { - const upb_MiniTableField field = {11, UPB_SIZE(44, 56), 5, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; + const upb_MiniTableField field = {11, UPB_SIZE(40, 48), 5, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; _upb_Message_SetNonExtensionField(msg, &field, &value); } UPB_INLINE void google_protobuf_FileOptions_set_cc_generic_services(google_protobuf_FileOptions *msg, bool value) { @@ -7723,39 +7708,35 @@ UPB_INLINE void google_protobuf_FileOptions_set_cc_enable_arenas(google_protobuf _upb_Message_SetNonExtensionField(msg, &field, &value); } UPB_INLINE void google_protobuf_FileOptions_set_objc_class_prefix(google_protobuf_FileOptions *msg, upb_StringView value) { - const upb_MiniTableField field = {36, UPB_SIZE(52, 72), 13, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; + const upb_MiniTableField field = {36, UPB_SIZE(48, 64), 13, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; _upb_Message_SetNonExtensionField(msg, &field, &value); } UPB_INLINE void google_protobuf_FileOptions_set_csharp_namespace(google_protobuf_FileOptions *msg, upb_StringView value) { - const upb_MiniTableField field = {37, UPB_SIZE(60, 88), 14, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; + const upb_MiniTableField field = {37, UPB_SIZE(56, 80), 14, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; _upb_Message_SetNonExtensionField(msg, &field, &value); } UPB_INLINE void google_protobuf_FileOptions_set_swift_prefix(google_protobuf_FileOptions *msg, upb_StringView value) { - const upb_MiniTableField field = {39, UPB_SIZE(68, 104), 15, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; + const upb_MiniTableField field = {39, UPB_SIZE(64, 96), 15, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; _upb_Message_SetNonExtensionField(msg, &field, &value); } UPB_INLINE void google_protobuf_FileOptions_set_php_class_prefix(google_protobuf_FileOptions *msg, upb_StringView value) { - const upb_MiniTableField field = {40, UPB_SIZE(76, 120), 16, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; + const upb_MiniTableField field = {40, UPB_SIZE(72, 112), 16, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; _upb_Message_SetNonExtensionField(msg, &field, &value); } UPB_INLINE void google_protobuf_FileOptions_set_php_namespace(google_protobuf_FileOptions *msg, upb_StringView value) { - const upb_MiniTableField field = {41, UPB_SIZE(84, 136), 17, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); -} -UPB_INLINE void google_protobuf_FileOptions_set_php_generic_services(google_protobuf_FileOptions *msg, bool value) { - const upb_MiniTableField field = {42, 16, 18, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; + const upb_MiniTableField field = {41, UPB_SIZE(80, 128), 17, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; _upb_Message_SetNonExtensionField(msg, &field, &value); } UPB_INLINE void google_protobuf_FileOptions_set_php_metadata_namespace(google_protobuf_FileOptions *msg, upb_StringView value) { - const upb_MiniTableField field = {44, UPB_SIZE(92, 152), 19, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; + const upb_MiniTableField field = {44, UPB_SIZE(88, 144), 18, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; _upb_Message_SetNonExtensionField(msg, &field, &value); } UPB_INLINE void google_protobuf_FileOptions_set_ruby_package(google_protobuf_FileOptions *msg, upb_StringView value) { - const upb_MiniTableField field = {45, UPB_SIZE(100, 168), 20, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; + const upb_MiniTableField field = {45, UPB_SIZE(96, 160), 19, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; _upb_Message_SetNonExtensionField(msg, &field, &value); } UPB_INLINE void google_protobuf_FileOptions_set_features(google_protobuf_FileOptions *msg, google_protobuf_FeatureSet* value) { - const upb_MiniTableField field = {50, UPB_SIZE(20, 184), 21, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; + const upb_MiniTableField field = {50, UPB_SIZE(16, 176), 20, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; _upb_Message_SetNonExtensionField(msg, &field, &value); } UPB_INLINE struct google_protobuf_FeatureSet* google_protobuf_FileOptions_mutable_features(google_protobuf_FileOptions* msg, upb_Arena* arena) { @@ -7767,7 +7748,7 @@ UPB_INLINE struct google_protobuf_FeatureSet* google_protobuf_FileOptions_mutabl return sub; } UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_FileOptions_mutable_uninterpreted_option(google_protobuf_FileOptions* msg, size_t* size) { - upb_MiniTableField field = {999, UPB_SIZE(24, 192), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; + upb_MiniTableField field = {999, UPB_SIZE(20, 184), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetMutableArray(msg, &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); @@ -7778,11 +7759,11 @@ UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_FileOptions_mut } } UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_FileOptions_resize_uninterpreted_option(google_protobuf_FileOptions* msg, size_t size, upb_Arena* arena) { - upb_MiniTableField field = {999, UPB_SIZE(24, 192), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; + upb_MiniTableField field = {999, UPB_SIZE(20, 184), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; return (google_protobuf_UninterpretedOption**)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); } UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_FileOptions_add_uninterpreted_option(google_protobuf_FileOptions* msg, upb_Arena* arena) { - upb_MiniTableField field = {999, UPB_SIZE(24, 192), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; + upb_MiniTableField field = {999, UPB_SIZE(20, 184), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); if (!arr || !_upb_Array_ResizeUninitialized( arr, arr->UPB_PRIVATE(size) + 1, arena)) { @@ -10545,7 +10526,7 @@ UPB_INLINE void google_protobuf_GeneratedCodeInfo_Annotation_set_semantic(google /* Max size 32 is google.protobuf.FileOptions */ /* Max size 64 is google.protobuf.FileOptions */ -#define _UPB_MAXOPT_SIZE UPB_SIZE(112, 200) +#define _UPB_MAXOPT_SIZE UPB_SIZE(104, 192) #ifdef __cplusplus } /* extern "C" */ diff --git a/ruby/ext/google/protobuf_c/ruby-upb.c b/ruby/ext/google/protobuf_c/ruby-upb.c index 6bff74c010044..ecc7cedc714b9 100644 --- a/ruby/ext/google/protobuf_c/ruby-upb.c +++ b/ruby/ext/google/protobuf_c/ruby-upb.c @@ -838,12 +838,12 @@ static const upb_MiniTableSub google_protobuf_FileOptions_submsgs[3] = { {.UPB_PRIVATE(subenum) = &google_protobuf_FileOptions_OptimizeMode_enum_init}, }; -static const upb_MiniTableField google_protobuf_FileOptions__fields[22] = { - {1, UPB_SIZE(28, 24), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, - {8, UPB_SIZE(36, 40), 2, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, +static const upb_MiniTableField google_protobuf_FileOptions__fields[21] = { + {1, UPB_SIZE(24, 16), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, + {8, 32, 2, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, {9, 4, 3, 2, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}, {10, 8, 4, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}, - {11, UPB_SIZE(44, 56), 5, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, + {11, UPB_SIZE(40, 48), 5, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, {16, 9, 6, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}, {17, 10, 7, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}, {18, 11, 8, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}, @@ -851,35 +851,34 @@ static const upb_MiniTableField google_protobuf_FileOptions__fields[22] = { {23, 13, 10, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}, {27, 14, 11, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}, {31, 15, 12, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}, - {36, UPB_SIZE(52, 72), 13, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, - {37, UPB_SIZE(60, 88), 14, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, - {39, UPB_SIZE(68, 104), 15, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, - {40, UPB_SIZE(76, 120), 16, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, - {41, UPB_SIZE(84, 136), 17, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, - {42, 16, 18, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}, - {44, UPB_SIZE(92, 152), 19, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, - {45, UPB_SIZE(100, 168), 20, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, - {50, UPB_SIZE(20, 184), 21, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, - {999, UPB_SIZE(24, 192), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, + {36, UPB_SIZE(48, 64), 13, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, + {37, UPB_SIZE(56, 80), 14, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, + {39, UPB_SIZE(64, 96), 15, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, + {40, UPB_SIZE(72, 112), 16, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, + {41, UPB_SIZE(80, 128), 17, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, + {44, UPB_SIZE(88, 144), 18, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, + {45, UPB_SIZE(96, 160), 19, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, + {50, UPB_SIZE(16, 176), 20, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, + {999, UPB_SIZE(20, 184), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, }; const upb_MiniTable google__protobuf__FileOptions_msg_init = { &google_protobuf_FileOptions_submsgs[0], &google_protobuf_FileOptions__fields[0], - UPB_SIZE(112, 200), 22, kUpb_ExtMode_Extendable, 1, UPB_FASTTABLE_MASK(248), 0, + UPB_SIZE(104, 192), 21, kUpb_ExtMode_Extendable, 1, UPB_FASTTABLE_MASK(248), 0, UPB_FASTTABLE_INIT({ {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x001800000100000a, &upb_pss_1bt}, + {0x001000000100000a, &upb_pss_1bt}, {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0028000002000042, &upb_pss_1bt}, + {0x0020000002000042, &upb_pss_1bt}, {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, {0x0008000004000050, &upb_psb1_1bt}, - {0x003800000500005a, &upb_pss_1bt}, + {0x003000000500005a, &upb_pss_1bt}, {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, @@ -889,15 +888,15 @@ const upb_MiniTable google__protobuf__FileOptions_msg_init = { {0x000b000008000190, &upb_psb1_2bt}, {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, {0x000c0000090001a0, &upb_psb1_2bt}, - {0x005800000e0002aa, &upb_pss_2bt}, + {0x005000000e0002aa, &upb_pss_2bt}, {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, {0x000d00000a0001b8, &upb_psb1_2bt}, - {0x00780000100002c2, &upb_pss_2bt}, - {0x00880000110002ca, &upb_pss_2bt}, - {0x00100000120002d0, &upb_psb1_2bt}, + {0x00700000100002c2, &upb_pss_2bt}, + {0x00800000110002ca, &upb_pss_2bt}, + {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, {0x000e00000b0001d8, &upb_psb1_2bt}, - {0x00980000130002e2, &upb_pss_2bt}, - {0x00a80000140002ea, &upb_pss_2bt}, + {0x00900000120002e2, &upb_pss_2bt}, + {0x00a00000130002ea, &upb_pss_2bt}, {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, {0x000f00000c0001f8, &upb_psb1_2bt}, }) diff --git a/ruby/ext/google/protobuf_c/ruby-upb.h b/ruby/ext/google/protobuf_c/ruby-upb.h index 7ef7460eae5c3..0bc527b44c9c1 100755 --- a/ruby/ext/google/protobuf_c/ruby-upb.h +++ b/ruby/ext/google/protobuf_c/ruby-upb.h @@ -7831,33 +7831,33 @@ UPB_INLINE char* google_protobuf_FileOptions_serialize_ex(const google_protobuf_ return ptr; } UPB_INLINE void google_protobuf_FileOptions_clear_java_package(google_protobuf_FileOptions* msg) { - const upb_MiniTableField field = {1, UPB_SIZE(28, 24), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; + const upb_MiniTableField field = {1, UPB_SIZE(24, 16), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; _upb_Message_ClearNonExtensionField(msg, &field); } UPB_INLINE upb_StringView google_protobuf_FileOptions_java_package(const google_protobuf_FileOptions* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; - const upb_MiniTableField field = {1, UPB_SIZE(28, 24), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; + const upb_MiniTableField field = {1, UPB_SIZE(24, 16), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FileOptions_has_java_package(const google_protobuf_FileOptions* msg) { - const upb_MiniTableField field = {1, UPB_SIZE(28, 24), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; + const upb_MiniTableField field = {1, UPB_SIZE(24, 16), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; return _upb_Message_HasNonExtensionField(msg, &field); } UPB_INLINE void google_protobuf_FileOptions_clear_java_outer_classname(google_protobuf_FileOptions* msg) { - const upb_MiniTableField field = {8, UPB_SIZE(36, 40), 2, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; + const upb_MiniTableField field = {8, 32, 2, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; _upb_Message_ClearNonExtensionField(msg, &field); } UPB_INLINE upb_StringView google_protobuf_FileOptions_java_outer_classname(const google_protobuf_FileOptions* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; - const upb_MiniTableField field = {8, UPB_SIZE(36, 40), 2, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; + const upb_MiniTableField field = {8, 32, 2, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FileOptions_has_java_outer_classname(const google_protobuf_FileOptions* msg) { - const upb_MiniTableField field = {8, UPB_SIZE(36, 40), 2, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; + const upb_MiniTableField field = {8, 32, 2, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; return _upb_Message_HasNonExtensionField(msg, &field); } UPB_INLINE void google_protobuf_FileOptions_clear_optimize_for(google_protobuf_FileOptions* msg) { @@ -7891,18 +7891,18 @@ UPB_INLINE bool google_protobuf_FileOptions_has_java_multiple_files(const google return _upb_Message_HasNonExtensionField(msg, &field); } UPB_INLINE void google_protobuf_FileOptions_clear_go_package(google_protobuf_FileOptions* msg) { - const upb_MiniTableField field = {11, UPB_SIZE(44, 56), 5, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; + const upb_MiniTableField field = {11, UPB_SIZE(40, 48), 5, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; _upb_Message_ClearNonExtensionField(msg, &field); } UPB_INLINE upb_StringView google_protobuf_FileOptions_go_package(const google_protobuf_FileOptions* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; - const upb_MiniTableField field = {11, UPB_SIZE(44, 56), 5, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; + const upb_MiniTableField field = {11, UPB_SIZE(40, 48), 5, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FileOptions_has_go_package(const google_protobuf_FileOptions* msg) { - const upb_MiniTableField field = {11, UPB_SIZE(44, 56), 5, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; + const upb_MiniTableField field = {11, UPB_SIZE(40, 48), 5, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; return _upb_Message_HasNonExtensionField(msg, &field); } UPB_INLINE void google_protobuf_FileOptions_clear_cc_generic_services(google_protobuf_FileOptions* msg) { @@ -8011,146 +8011,131 @@ UPB_INLINE bool google_protobuf_FileOptions_has_cc_enable_arenas(const google_pr return _upb_Message_HasNonExtensionField(msg, &field); } UPB_INLINE void google_protobuf_FileOptions_clear_objc_class_prefix(google_protobuf_FileOptions* msg) { - const upb_MiniTableField field = {36, UPB_SIZE(52, 72), 13, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; + const upb_MiniTableField field = {36, UPB_SIZE(48, 64), 13, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; _upb_Message_ClearNonExtensionField(msg, &field); } UPB_INLINE upb_StringView google_protobuf_FileOptions_objc_class_prefix(const google_protobuf_FileOptions* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; - const upb_MiniTableField field = {36, UPB_SIZE(52, 72), 13, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; + const upb_MiniTableField field = {36, UPB_SIZE(48, 64), 13, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FileOptions_has_objc_class_prefix(const google_protobuf_FileOptions* msg) { - const upb_MiniTableField field = {36, UPB_SIZE(52, 72), 13, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; + const upb_MiniTableField field = {36, UPB_SIZE(48, 64), 13, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; return _upb_Message_HasNonExtensionField(msg, &field); } UPB_INLINE void google_protobuf_FileOptions_clear_csharp_namespace(google_protobuf_FileOptions* msg) { - const upb_MiniTableField field = {37, UPB_SIZE(60, 88), 14, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; + const upb_MiniTableField field = {37, UPB_SIZE(56, 80), 14, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; _upb_Message_ClearNonExtensionField(msg, &field); } UPB_INLINE upb_StringView google_protobuf_FileOptions_csharp_namespace(const google_protobuf_FileOptions* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; - const upb_MiniTableField field = {37, UPB_SIZE(60, 88), 14, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; + const upb_MiniTableField field = {37, UPB_SIZE(56, 80), 14, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FileOptions_has_csharp_namespace(const google_protobuf_FileOptions* msg) { - const upb_MiniTableField field = {37, UPB_SIZE(60, 88), 14, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; + const upb_MiniTableField field = {37, UPB_SIZE(56, 80), 14, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; return _upb_Message_HasNonExtensionField(msg, &field); } UPB_INLINE void google_protobuf_FileOptions_clear_swift_prefix(google_protobuf_FileOptions* msg) { - const upb_MiniTableField field = {39, UPB_SIZE(68, 104), 15, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; + const upb_MiniTableField field = {39, UPB_SIZE(64, 96), 15, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; _upb_Message_ClearNonExtensionField(msg, &field); } UPB_INLINE upb_StringView google_protobuf_FileOptions_swift_prefix(const google_protobuf_FileOptions* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; - const upb_MiniTableField field = {39, UPB_SIZE(68, 104), 15, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; + const upb_MiniTableField field = {39, UPB_SIZE(64, 96), 15, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FileOptions_has_swift_prefix(const google_protobuf_FileOptions* msg) { - const upb_MiniTableField field = {39, UPB_SIZE(68, 104), 15, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; + const upb_MiniTableField field = {39, UPB_SIZE(64, 96), 15, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; return _upb_Message_HasNonExtensionField(msg, &field); } UPB_INLINE void google_protobuf_FileOptions_clear_php_class_prefix(google_protobuf_FileOptions* msg) { - const upb_MiniTableField field = {40, UPB_SIZE(76, 120), 16, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; + const upb_MiniTableField field = {40, UPB_SIZE(72, 112), 16, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; _upb_Message_ClearNonExtensionField(msg, &field); } UPB_INLINE upb_StringView google_protobuf_FileOptions_php_class_prefix(const google_protobuf_FileOptions* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; - const upb_MiniTableField field = {40, UPB_SIZE(76, 120), 16, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; + const upb_MiniTableField field = {40, UPB_SIZE(72, 112), 16, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FileOptions_has_php_class_prefix(const google_protobuf_FileOptions* msg) { - const upb_MiniTableField field = {40, UPB_SIZE(76, 120), 16, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; + const upb_MiniTableField field = {40, UPB_SIZE(72, 112), 16, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; return _upb_Message_HasNonExtensionField(msg, &field); } UPB_INLINE void google_protobuf_FileOptions_clear_php_namespace(google_protobuf_FileOptions* msg) { - const upb_MiniTableField field = {41, UPB_SIZE(84, 136), 17, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; + const upb_MiniTableField field = {41, UPB_SIZE(80, 128), 17, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; _upb_Message_ClearNonExtensionField(msg, &field); } UPB_INLINE upb_StringView google_protobuf_FileOptions_php_namespace(const google_protobuf_FileOptions* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; - const upb_MiniTableField field = {41, UPB_SIZE(84, 136), 17, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; + const upb_MiniTableField field = {41, UPB_SIZE(80, 128), 17, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FileOptions_has_php_namespace(const google_protobuf_FileOptions* msg) { - const upb_MiniTableField field = {41, UPB_SIZE(84, 136), 17, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); -} -UPB_INLINE void google_protobuf_FileOptions_clear_php_generic_services(google_protobuf_FileOptions* msg) { - const upb_MiniTableField field = {42, 16, 18, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); -} -UPB_INLINE bool google_protobuf_FileOptions_php_generic_services(const google_protobuf_FileOptions* msg) { - bool default_val = false; - bool ret; - const upb_MiniTableField field = {42, 16, 18, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_FileOptions_has_php_generic_services(const google_protobuf_FileOptions* msg) { - const upb_MiniTableField field = {42, 16, 18, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; + const upb_MiniTableField field = {41, UPB_SIZE(80, 128), 17, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; return _upb_Message_HasNonExtensionField(msg, &field); } UPB_INLINE void google_protobuf_FileOptions_clear_php_metadata_namespace(google_protobuf_FileOptions* msg) { - const upb_MiniTableField field = {44, UPB_SIZE(92, 152), 19, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; + const upb_MiniTableField field = {44, UPB_SIZE(88, 144), 18, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; _upb_Message_ClearNonExtensionField(msg, &field); } UPB_INLINE upb_StringView google_protobuf_FileOptions_php_metadata_namespace(const google_protobuf_FileOptions* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; - const upb_MiniTableField field = {44, UPB_SIZE(92, 152), 19, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; + const upb_MiniTableField field = {44, UPB_SIZE(88, 144), 18, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FileOptions_has_php_metadata_namespace(const google_protobuf_FileOptions* msg) { - const upb_MiniTableField field = {44, UPB_SIZE(92, 152), 19, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; + const upb_MiniTableField field = {44, UPB_SIZE(88, 144), 18, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; return _upb_Message_HasNonExtensionField(msg, &field); } UPB_INLINE void google_protobuf_FileOptions_clear_ruby_package(google_protobuf_FileOptions* msg) { - const upb_MiniTableField field = {45, UPB_SIZE(100, 168), 20, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; + const upb_MiniTableField field = {45, UPB_SIZE(96, 160), 19, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; _upb_Message_ClearNonExtensionField(msg, &field); } UPB_INLINE upb_StringView google_protobuf_FileOptions_ruby_package(const google_protobuf_FileOptions* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; - const upb_MiniTableField field = {45, UPB_SIZE(100, 168), 20, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; + const upb_MiniTableField field = {45, UPB_SIZE(96, 160), 19, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FileOptions_has_ruby_package(const google_protobuf_FileOptions* msg) { - const upb_MiniTableField field = {45, UPB_SIZE(100, 168), 20, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; + const upb_MiniTableField field = {45, UPB_SIZE(96, 160), 19, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; return _upb_Message_HasNonExtensionField(msg, &field); } UPB_INLINE void google_protobuf_FileOptions_clear_features(google_protobuf_FileOptions* msg) { - const upb_MiniTableField field = {50, UPB_SIZE(20, 184), 21, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; + const upb_MiniTableField field = {50, UPB_SIZE(16, 176), 20, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; _upb_Message_ClearNonExtensionField(msg, &field); } UPB_INLINE const google_protobuf_FeatureSet* google_protobuf_FileOptions_features(const google_protobuf_FileOptions* msg) { const google_protobuf_FeatureSet* default_val = NULL; const google_protobuf_FeatureSet* ret; - const upb_MiniTableField field = {50, UPB_SIZE(20, 184), 21, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; + const upb_MiniTableField field = {50, UPB_SIZE(16, 176), 20, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FileOptions_has_features(const google_protobuf_FileOptions* msg) { - const upb_MiniTableField field = {50, UPB_SIZE(20, 184), 21, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; + const upb_MiniTableField field = {50, UPB_SIZE(16, 176), 20, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; return _upb_Message_HasNonExtensionField(msg, &field); } UPB_INLINE void google_protobuf_FileOptions_clear_uninterpreted_option(google_protobuf_FileOptions* msg) { - const upb_MiniTableField field = {999, UPB_SIZE(24, 192), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; + const upb_MiniTableField field = {999, UPB_SIZE(20, 184), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; _upb_Message_ClearNonExtensionField(msg, &field); } UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_FileOptions_uninterpreted_option(const google_protobuf_FileOptions* msg, size_t* size) { - const upb_MiniTableField field = {999, UPB_SIZE(24, 192), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; + const upb_MiniTableField field = {999, UPB_SIZE(20, 184), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); @@ -8161,7 +8146,7 @@ UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_Fil } } UPB_INLINE const upb_Array* _google_protobuf_FileOptions_uninterpreted_option_upb_array(const google_protobuf_FileOptions* msg, size_t* size) { - const upb_MiniTableField field = {999, UPB_SIZE(24, 192), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; + const upb_MiniTableField field = {999, UPB_SIZE(20, 184), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; @@ -8169,7 +8154,7 @@ UPB_INLINE const upb_Array* _google_protobuf_FileOptions_uninterpreted_option_up return arr; } UPB_INLINE upb_Array* _google_protobuf_FileOptions_uninterpreted_option_mutable_upb_array(const google_protobuf_FileOptions* msg, size_t* size, upb_Arena* arena) { - const upb_MiniTableField field = {999, UPB_SIZE(24, 192), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; + const upb_MiniTableField field = {999, UPB_SIZE(20, 184), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetOrCreateMutableArray( (upb_Message*)msg, &field, arena); if (size) { @@ -8179,11 +8164,11 @@ UPB_INLINE upb_Array* _google_protobuf_FileOptions_uninterpreted_option_mutable_ } UPB_INLINE void google_protobuf_FileOptions_set_java_package(google_protobuf_FileOptions *msg, upb_StringView value) { - const upb_MiniTableField field = {1, UPB_SIZE(28, 24), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; + const upb_MiniTableField field = {1, UPB_SIZE(24, 16), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; _upb_Message_SetNonExtensionField(msg, &field, &value); } UPB_INLINE void google_protobuf_FileOptions_set_java_outer_classname(google_protobuf_FileOptions *msg, upb_StringView value) { - const upb_MiniTableField field = {8, UPB_SIZE(36, 40), 2, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; + const upb_MiniTableField field = {8, 32, 2, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; _upb_Message_SetNonExtensionField(msg, &field, &value); } UPB_INLINE void google_protobuf_FileOptions_set_optimize_for(google_protobuf_FileOptions *msg, int32_t value) { @@ -8195,7 +8180,7 @@ UPB_INLINE void google_protobuf_FileOptions_set_java_multiple_files(google_proto _upb_Message_SetNonExtensionField(msg, &field, &value); } UPB_INLINE void google_protobuf_FileOptions_set_go_package(google_protobuf_FileOptions *msg, upb_StringView value) { - const upb_MiniTableField field = {11, UPB_SIZE(44, 56), 5, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; + const upb_MiniTableField field = {11, UPB_SIZE(40, 48), 5, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; _upb_Message_SetNonExtensionField(msg, &field, &value); } UPB_INLINE void google_protobuf_FileOptions_set_cc_generic_services(google_protobuf_FileOptions *msg, bool value) { @@ -8227,39 +8212,35 @@ UPB_INLINE void google_protobuf_FileOptions_set_cc_enable_arenas(google_protobuf _upb_Message_SetNonExtensionField(msg, &field, &value); } UPB_INLINE void google_protobuf_FileOptions_set_objc_class_prefix(google_protobuf_FileOptions *msg, upb_StringView value) { - const upb_MiniTableField field = {36, UPB_SIZE(52, 72), 13, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; + const upb_MiniTableField field = {36, UPB_SIZE(48, 64), 13, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; _upb_Message_SetNonExtensionField(msg, &field, &value); } UPB_INLINE void google_protobuf_FileOptions_set_csharp_namespace(google_protobuf_FileOptions *msg, upb_StringView value) { - const upb_MiniTableField field = {37, UPB_SIZE(60, 88), 14, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; + const upb_MiniTableField field = {37, UPB_SIZE(56, 80), 14, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; _upb_Message_SetNonExtensionField(msg, &field, &value); } UPB_INLINE void google_protobuf_FileOptions_set_swift_prefix(google_protobuf_FileOptions *msg, upb_StringView value) { - const upb_MiniTableField field = {39, UPB_SIZE(68, 104), 15, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; + const upb_MiniTableField field = {39, UPB_SIZE(64, 96), 15, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; _upb_Message_SetNonExtensionField(msg, &field, &value); } UPB_INLINE void google_protobuf_FileOptions_set_php_class_prefix(google_protobuf_FileOptions *msg, upb_StringView value) { - const upb_MiniTableField field = {40, UPB_SIZE(76, 120), 16, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; + const upb_MiniTableField field = {40, UPB_SIZE(72, 112), 16, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; _upb_Message_SetNonExtensionField(msg, &field, &value); } UPB_INLINE void google_protobuf_FileOptions_set_php_namespace(google_protobuf_FileOptions *msg, upb_StringView value) { - const upb_MiniTableField field = {41, UPB_SIZE(84, 136), 17, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); -} -UPB_INLINE void google_protobuf_FileOptions_set_php_generic_services(google_protobuf_FileOptions *msg, bool value) { - const upb_MiniTableField field = {42, 16, 18, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; + const upb_MiniTableField field = {41, UPB_SIZE(80, 128), 17, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; _upb_Message_SetNonExtensionField(msg, &field, &value); } UPB_INLINE void google_protobuf_FileOptions_set_php_metadata_namespace(google_protobuf_FileOptions *msg, upb_StringView value) { - const upb_MiniTableField field = {44, UPB_SIZE(92, 152), 19, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; + const upb_MiniTableField field = {44, UPB_SIZE(88, 144), 18, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; _upb_Message_SetNonExtensionField(msg, &field, &value); } UPB_INLINE void google_protobuf_FileOptions_set_ruby_package(google_protobuf_FileOptions *msg, upb_StringView value) { - const upb_MiniTableField field = {45, UPB_SIZE(100, 168), 20, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; + const upb_MiniTableField field = {45, UPB_SIZE(96, 160), 19, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; _upb_Message_SetNonExtensionField(msg, &field, &value); } UPB_INLINE void google_protobuf_FileOptions_set_features(google_protobuf_FileOptions *msg, google_protobuf_FeatureSet* value) { - const upb_MiniTableField field = {50, UPB_SIZE(20, 184), 21, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; + const upb_MiniTableField field = {50, UPB_SIZE(16, 176), 20, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; _upb_Message_SetNonExtensionField(msg, &field, &value); } UPB_INLINE struct google_protobuf_FeatureSet* google_protobuf_FileOptions_mutable_features(google_protobuf_FileOptions* msg, upb_Arena* arena) { @@ -8271,7 +8252,7 @@ UPB_INLINE struct google_protobuf_FeatureSet* google_protobuf_FileOptions_mutabl return sub; } UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_FileOptions_mutable_uninterpreted_option(google_protobuf_FileOptions* msg, size_t* size) { - upb_MiniTableField field = {999, UPB_SIZE(24, 192), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; + upb_MiniTableField field = {999, UPB_SIZE(20, 184), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetMutableArray(msg, &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); @@ -8282,11 +8263,11 @@ UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_FileOptions_mut } } UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_FileOptions_resize_uninterpreted_option(google_protobuf_FileOptions* msg, size_t size, upb_Arena* arena) { - upb_MiniTableField field = {999, UPB_SIZE(24, 192), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; + upb_MiniTableField field = {999, UPB_SIZE(20, 184), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; return (google_protobuf_UninterpretedOption**)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); } UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_FileOptions_add_uninterpreted_option(google_protobuf_FileOptions* msg, upb_Arena* arena) { - upb_MiniTableField field = {999, UPB_SIZE(24, 192), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; + upb_MiniTableField field = {999, UPB_SIZE(20, 184), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); if (!arr || !_upb_Array_ResizeUninitialized( arr, arr->UPB_PRIVATE(size) + 1, arena)) { @@ -11049,7 +11030,7 @@ UPB_INLINE void google_protobuf_GeneratedCodeInfo_Annotation_set_semantic(google /* Max size 32 is google.protobuf.FileOptions */ /* Max size 64 is google.protobuf.FileOptions */ -#define _UPB_MAXOPT_SIZE UPB_SIZE(112, 200) +#define _UPB_MAXOPT_SIZE UPB_SIZE(104, 192) #ifdef __cplusplus } /* extern "C" */ diff --git a/upb/cmake/google/protobuf/descriptor.upb.h b/upb/cmake/google/protobuf/descriptor.upb.h index 26c80b854fabd..e1e8359d04b85 100644 --- a/upb/cmake/google/protobuf/descriptor.upb.h +++ b/upb/cmake/google/protobuf/descriptor.upb.h @@ -3049,33 +3049,33 @@ UPB_INLINE char* google_protobuf_FileOptions_serialize_ex(const google_protobuf_ return ptr; } UPB_INLINE void google_protobuf_FileOptions_clear_java_package(google_protobuf_FileOptions* msg) { - const upb_MiniTableField field = {1, UPB_SIZE(28, 24), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; + const upb_MiniTableField field = {1, UPB_SIZE(24, 16), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; _upb_Message_ClearNonExtensionField(msg, &field); } UPB_INLINE upb_StringView google_protobuf_FileOptions_java_package(const google_protobuf_FileOptions* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; - const upb_MiniTableField field = {1, UPB_SIZE(28, 24), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; + const upb_MiniTableField field = {1, UPB_SIZE(24, 16), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FileOptions_has_java_package(const google_protobuf_FileOptions* msg) { - const upb_MiniTableField field = {1, UPB_SIZE(28, 24), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; + const upb_MiniTableField field = {1, UPB_SIZE(24, 16), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; return _upb_Message_HasNonExtensionField(msg, &field); } UPB_INLINE void google_protobuf_FileOptions_clear_java_outer_classname(google_protobuf_FileOptions* msg) { - const upb_MiniTableField field = {8, UPB_SIZE(36, 40), 2, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; + const upb_MiniTableField field = {8, 32, 2, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; _upb_Message_ClearNonExtensionField(msg, &field); } UPB_INLINE upb_StringView google_protobuf_FileOptions_java_outer_classname(const google_protobuf_FileOptions* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; - const upb_MiniTableField field = {8, UPB_SIZE(36, 40), 2, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; + const upb_MiniTableField field = {8, 32, 2, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FileOptions_has_java_outer_classname(const google_protobuf_FileOptions* msg) { - const upb_MiniTableField field = {8, UPB_SIZE(36, 40), 2, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; + const upb_MiniTableField field = {8, 32, 2, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; return _upb_Message_HasNonExtensionField(msg, &field); } UPB_INLINE void google_protobuf_FileOptions_clear_optimize_for(google_protobuf_FileOptions* msg) { @@ -3109,18 +3109,18 @@ UPB_INLINE bool google_protobuf_FileOptions_has_java_multiple_files(const google return _upb_Message_HasNonExtensionField(msg, &field); } UPB_INLINE void google_protobuf_FileOptions_clear_go_package(google_protobuf_FileOptions* msg) { - const upb_MiniTableField field = {11, UPB_SIZE(44, 56), 5, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; + const upb_MiniTableField field = {11, UPB_SIZE(40, 48), 5, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; _upb_Message_ClearNonExtensionField(msg, &field); } UPB_INLINE upb_StringView google_protobuf_FileOptions_go_package(const google_protobuf_FileOptions* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; - const upb_MiniTableField field = {11, UPB_SIZE(44, 56), 5, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; + const upb_MiniTableField field = {11, UPB_SIZE(40, 48), 5, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FileOptions_has_go_package(const google_protobuf_FileOptions* msg) { - const upb_MiniTableField field = {11, UPB_SIZE(44, 56), 5, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; + const upb_MiniTableField field = {11, UPB_SIZE(40, 48), 5, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; return _upb_Message_HasNonExtensionField(msg, &field); } UPB_INLINE void google_protobuf_FileOptions_clear_cc_generic_services(google_protobuf_FileOptions* msg) { @@ -3229,146 +3229,131 @@ UPB_INLINE bool google_protobuf_FileOptions_has_cc_enable_arenas(const google_pr return _upb_Message_HasNonExtensionField(msg, &field); } UPB_INLINE void google_protobuf_FileOptions_clear_objc_class_prefix(google_protobuf_FileOptions* msg) { - const upb_MiniTableField field = {36, UPB_SIZE(52, 72), 13, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; + const upb_MiniTableField field = {36, UPB_SIZE(48, 64), 13, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; _upb_Message_ClearNonExtensionField(msg, &field); } UPB_INLINE upb_StringView google_protobuf_FileOptions_objc_class_prefix(const google_protobuf_FileOptions* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; - const upb_MiniTableField field = {36, UPB_SIZE(52, 72), 13, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; + const upb_MiniTableField field = {36, UPB_SIZE(48, 64), 13, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FileOptions_has_objc_class_prefix(const google_protobuf_FileOptions* msg) { - const upb_MiniTableField field = {36, UPB_SIZE(52, 72), 13, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; + const upb_MiniTableField field = {36, UPB_SIZE(48, 64), 13, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; return _upb_Message_HasNonExtensionField(msg, &field); } UPB_INLINE void google_protobuf_FileOptions_clear_csharp_namespace(google_protobuf_FileOptions* msg) { - const upb_MiniTableField field = {37, UPB_SIZE(60, 88), 14, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; + const upb_MiniTableField field = {37, UPB_SIZE(56, 80), 14, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; _upb_Message_ClearNonExtensionField(msg, &field); } UPB_INLINE upb_StringView google_protobuf_FileOptions_csharp_namespace(const google_protobuf_FileOptions* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; - const upb_MiniTableField field = {37, UPB_SIZE(60, 88), 14, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; + const upb_MiniTableField field = {37, UPB_SIZE(56, 80), 14, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FileOptions_has_csharp_namespace(const google_protobuf_FileOptions* msg) { - const upb_MiniTableField field = {37, UPB_SIZE(60, 88), 14, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; + const upb_MiniTableField field = {37, UPB_SIZE(56, 80), 14, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; return _upb_Message_HasNonExtensionField(msg, &field); } UPB_INLINE void google_protobuf_FileOptions_clear_swift_prefix(google_protobuf_FileOptions* msg) { - const upb_MiniTableField field = {39, UPB_SIZE(68, 104), 15, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; + const upb_MiniTableField field = {39, UPB_SIZE(64, 96), 15, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; _upb_Message_ClearNonExtensionField(msg, &field); } UPB_INLINE upb_StringView google_protobuf_FileOptions_swift_prefix(const google_protobuf_FileOptions* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; - const upb_MiniTableField field = {39, UPB_SIZE(68, 104), 15, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; + const upb_MiniTableField field = {39, UPB_SIZE(64, 96), 15, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FileOptions_has_swift_prefix(const google_protobuf_FileOptions* msg) { - const upb_MiniTableField field = {39, UPB_SIZE(68, 104), 15, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; + const upb_MiniTableField field = {39, UPB_SIZE(64, 96), 15, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; return _upb_Message_HasNonExtensionField(msg, &field); } UPB_INLINE void google_protobuf_FileOptions_clear_php_class_prefix(google_protobuf_FileOptions* msg) { - const upb_MiniTableField field = {40, UPB_SIZE(76, 120), 16, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; + const upb_MiniTableField field = {40, UPB_SIZE(72, 112), 16, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; _upb_Message_ClearNonExtensionField(msg, &field); } UPB_INLINE upb_StringView google_protobuf_FileOptions_php_class_prefix(const google_protobuf_FileOptions* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; - const upb_MiniTableField field = {40, UPB_SIZE(76, 120), 16, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; + const upb_MiniTableField field = {40, UPB_SIZE(72, 112), 16, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FileOptions_has_php_class_prefix(const google_protobuf_FileOptions* msg) { - const upb_MiniTableField field = {40, UPB_SIZE(76, 120), 16, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; + const upb_MiniTableField field = {40, UPB_SIZE(72, 112), 16, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; return _upb_Message_HasNonExtensionField(msg, &field); } UPB_INLINE void google_protobuf_FileOptions_clear_php_namespace(google_protobuf_FileOptions* msg) { - const upb_MiniTableField field = {41, UPB_SIZE(84, 136), 17, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; + const upb_MiniTableField field = {41, UPB_SIZE(80, 128), 17, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; _upb_Message_ClearNonExtensionField(msg, &field); } UPB_INLINE upb_StringView google_protobuf_FileOptions_php_namespace(const google_protobuf_FileOptions* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; - const upb_MiniTableField field = {41, UPB_SIZE(84, 136), 17, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; + const upb_MiniTableField field = {41, UPB_SIZE(80, 128), 17, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FileOptions_has_php_namespace(const google_protobuf_FileOptions* msg) { - const upb_MiniTableField field = {41, UPB_SIZE(84, 136), 17, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); -} -UPB_INLINE void google_protobuf_FileOptions_clear_php_generic_services(google_protobuf_FileOptions* msg) { - const upb_MiniTableField field = {42, 16, 18, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); -} -UPB_INLINE bool google_protobuf_FileOptions_php_generic_services(const google_protobuf_FileOptions* msg) { - bool default_val = false; - bool ret; - const upb_MiniTableField field = {42, 16, 18, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_FileOptions_has_php_generic_services(const google_protobuf_FileOptions* msg) { - const upb_MiniTableField field = {42, 16, 18, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; + const upb_MiniTableField field = {41, UPB_SIZE(80, 128), 17, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; return _upb_Message_HasNonExtensionField(msg, &field); } UPB_INLINE void google_protobuf_FileOptions_clear_php_metadata_namespace(google_protobuf_FileOptions* msg) { - const upb_MiniTableField field = {44, UPB_SIZE(92, 152), 19, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; + const upb_MiniTableField field = {44, UPB_SIZE(88, 144), 18, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; _upb_Message_ClearNonExtensionField(msg, &field); } UPB_INLINE upb_StringView google_protobuf_FileOptions_php_metadata_namespace(const google_protobuf_FileOptions* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; - const upb_MiniTableField field = {44, UPB_SIZE(92, 152), 19, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; + const upb_MiniTableField field = {44, UPB_SIZE(88, 144), 18, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FileOptions_has_php_metadata_namespace(const google_protobuf_FileOptions* msg) { - const upb_MiniTableField field = {44, UPB_SIZE(92, 152), 19, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; + const upb_MiniTableField field = {44, UPB_SIZE(88, 144), 18, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; return _upb_Message_HasNonExtensionField(msg, &field); } UPB_INLINE void google_protobuf_FileOptions_clear_ruby_package(google_protobuf_FileOptions* msg) { - const upb_MiniTableField field = {45, UPB_SIZE(100, 168), 20, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; + const upb_MiniTableField field = {45, UPB_SIZE(96, 160), 19, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; _upb_Message_ClearNonExtensionField(msg, &field); } UPB_INLINE upb_StringView google_protobuf_FileOptions_ruby_package(const google_protobuf_FileOptions* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; - const upb_MiniTableField field = {45, UPB_SIZE(100, 168), 20, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; + const upb_MiniTableField field = {45, UPB_SIZE(96, 160), 19, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FileOptions_has_ruby_package(const google_protobuf_FileOptions* msg) { - const upb_MiniTableField field = {45, UPB_SIZE(100, 168), 20, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; + const upb_MiniTableField field = {45, UPB_SIZE(96, 160), 19, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; return _upb_Message_HasNonExtensionField(msg, &field); } UPB_INLINE void google_protobuf_FileOptions_clear_features(google_protobuf_FileOptions* msg) { - const upb_MiniTableField field = {50, UPB_SIZE(20, 184), 21, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; + const upb_MiniTableField field = {50, UPB_SIZE(16, 176), 20, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; _upb_Message_ClearNonExtensionField(msg, &field); } UPB_INLINE const google_protobuf_FeatureSet* google_protobuf_FileOptions_features(const google_protobuf_FileOptions* msg) { const google_protobuf_FeatureSet* default_val = NULL; const google_protobuf_FeatureSet* ret; - const upb_MiniTableField field = {50, UPB_SIZE(20, 184), 21, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; + const upb_MiniTableField field = {50, UPB_SIZE(16, 176), 20, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FileOptions_has_features(const google_protobuf_FileOptions* msg) { - const upb_MiniTableField field = {50, UPB_SIZE(20, 184), 21, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; + const upb_MiniTableField field = {50, UPB_SIZE(16, 176), 20, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; return _upb_Message_HasNonExtensionField(msg, &field); } UPB_INLINE void google_protobuf_FileOptions_clear_uninterpreted_option(google_protobuf_FileOptions* msg) { - const upb_MiniTableField field = {999, UPB_SIZE(24, 192), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; + const upb_MiniTableField field = {999, UPB_SIZE(20, 184), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; _upb_Message_ClearNonExtensionField(msg, &field); } UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_FileOptions_uninterpreted_option(const google_protobuf_FileOptions* msg, size_t* size) { - const upb_MiniTableField field = {999, UPB_SIZE(24, 192), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; + const upb_MiniTableField field = {999, UPB_SIZE(20, 184), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); @@ -3379,7 +3364,7 @@ UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_Fil } } UPB_INLINE const upb_Array* _google_protobuf_FileOptions_uninterpreted_option_upb_array(const google_protobuf_FileOptions* msg, size_t* size) { - const upb_MiniTableField field = {999, UPB_SIZE(24, 192), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; + const upb_MiniTableField field = {999, UPB_SIZE(20, 184), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; const upb_Array* arr = upb_Message_GetArray(msg, &field); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; @@ -3387,7 +3372,7 @@ UPB_INLINE const upb_Array* _google_protobuf_FileOptions_uninterpreted_option_up return arr; } UPB_INLINE upb_Array* _google_protobuf_FileOptions_uninterpreted_option_mutable_upb_array(const google_protobuf_FileOptions* msg, size_t* size, upb_Arena* arena) { - const upb_MiniTableField field = {999, UPB_SIZE(24, 192), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; + const upb_MiniTableField field = {999, UPB_SIZE(20, 184), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetOrCreateMutableArray( (upb_Message*)msg, &field, arena); if (size) { @@ -3397,11 +3382,11 @@ UPB_INLINE upb_Array* _google_protobuf_FileOptions_uninterpreted_option_mutable_ } UPB_INLINE void google_protobuf_FileOptions_set_java_package(google_protobuf_FileOptions *msg, upb_StringView value) { - const upb_MiniTableField field = {1, UPB_SIZE(28, 24), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; + const upb_MiniTableField field = {1, UPB_SIZE(24, 16), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; _upb_Message_SetNonExtensionField(msg, &field, &value); } UPB_INLINE void google_protobuf_FileOptions_set_java_outer_classname(google_protobuf_FileOptions *msg, upb_StringView value) { - const upb_MiniTableField field = {8, UPB_SIZE(36, 40), 2, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; + const upb_MiniTableField field = {8, 32, 2, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; _upb_Message_SetNonExtensionField(msg, &field, &value); } UPB_INLINE void google_protobuf_FileOptions_set_optimize_for(google_protobuf_FileOptions *msg, int32_t value) { @@ -3413,7 +3398,7 @@ UPB_INLINE void google_protobuf_FileOptions_set_java_multiple_files(google_proto _upb_Message_SetNonExtensionField(msg, &field, &value); } UPB_INLINE void google_protobuf_FileOptions_set_go_package(google_protobuf_FileOptions *msg, upb_StringView value) { - const upb_MiniTableField field = {11, UPB_SIZE(44, 56), 5, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; + const upb_MiniTableField field = {11, UPB_SIZE(40, 48), 5, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; _upb_Message_SetNonExtensionField(msg, &field, &value); } UPB_INLINE void google_protobuf_FileOptions_set_cc_generic_services(google_protobuf_FileOptions *msg, bool value) { @@ -3445,39 +3430,35 @@ UPB_INLINE void google_protobuf_FileOptions_set_cc_enable_arenas(google_protobuf _upb_Message_SetNonExtensionField(msg, &field, &value); } UPB_INLINE void google_protobuf_FileOptions_set_objc_class_prefix(google_protobuf_FileOptions *msg, upb_StringView value) { - const upb_MiniTableField field = {36, UPB_SIZE(52, 72), 13, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; + const upb_MiniTableField field = {36, UPB_SIZE(48, 64), 13, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; _upb_Message_SetNonExtensionField(msg, &field, &value); } UPB_INLINE void google_protobuf_FileOptions_set_csharp_namespace(google_protobuf_FileOptions *msg, upb_StringView value) { - const upb_MiniTableField field = {37, UPB_SIZE(60, 88), 14, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; + const upb_MiniTableField field = {37, UPB_SIZE(56, 80), 14, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; _upb_Message_SetNonExtensionField(msg, &field, &value); } UPB_INLINE void google_protobuf_FileOptions_set_swift_prefix(google_protobuf_FileOptions *msg, upb_StringView value) { - const upb_MiniTableField field = {39, UPB_SIZE(68, 104), 15, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; + const upb_MiniTableField field = {39, UPB_SIZE(64, 96), 15, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; _upb_Message_SetNonExtensionField(msg, &field, &value); } UPB_INLINE void google_protobuf_FileOptions_set_php_class_prefix(google_protobuf_FileOptions *msg, upb_StringView value) { - const upb_MiniTableField field = {40, UPB_SIZE(76, 120), 16, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; + const upb_MiniTableField field = {40, UPB_SIZE(72, 112), 16, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; _upb_Message_SetNonExtensionField(msg, &field, &value); } UPB_INLINE void google_protobuf_FileOptions_set_php_namespace(google_protobuf_FileOptions *msg, upb_StringView value) { - const upb_MiniTableField field = {41, UPB_SIZE(84, 136), 17, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); -} -UPB_INLINE void google_protobuf_FileOptions_set_php_generic_services(google_protobuf_FileOptions *msg, bool value) { - const upb_MiniTableField field = {42, 16, 18, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; + const upb_MiniTableField field = {41, UPB_SIZE(80, 128), 17, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; _upb_Message_SetNonExtensionField(msg, &field, &value); } UPB_INLINE void google_protobuf_FileOptions_set_php_metadata_namespace(google_protobuf_FileOptions *msg, upb_StringView value) { - const upb_MiniTableField field = {44, UPB_SIZE(92, 152), 19, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; + const upb_MiniTableField field = {44, UPB_SIZE(88, 144), 18, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; _upb_Message_SetNonExtensionField(msg, &field, &value); } UPB_INLINE void google_protobuf_FileOptions_set_ruby_package(google_protobuf_FileOptions *msg, upb_StringView value) { - const upb_MiniTableField field = {45, UPB_SIZE(100, 168), 20, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; + const upb_MiniTableField field = {45, UPB_SIZE(96, 160), 19, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; _upb_Message_SetNonExtensionField(msg, &field, &value); } UPB_INLINE void google_protobuf_FileOptions_set_features(google_protobuf_FileOptions *msg, google_protobuf_FeatureSet* value) { - const upb_MiniTableField field = {50, UPB_SIZE(20, 184), 21, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; + const upb_MiniTableField field = {50, UPB_SIZE(16, 176), 20, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; _upb_Message_SetNonExtensionField(msg, &field, &value); } UPB_INLINE struct google_protobuf_FeatureSet* google_protobuf_FileOptions_mutable_features(google_protobuf_FileOptions* msg, upb_Arena* arena) { @@ -3489,7 +3470,7 @@ UPB_INLINE struct google_protobuf_FeatureSet* google_protobuf_FileOptions_mutabl return sub; } UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_FileOptions_mutable_uninterpreted_option(google_protobuf_FileOptions* msg, size_t* size) { - upb_MiniTableField field = {999, UPB_SIZE(24, 192), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; + upb_MiniTableField field = {999, UPB_SIZE(20, 184), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetMutableArray(msg, &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); @@ -3500,11 +3481,11 @@ UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_FileOptions_mut } } UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_FileOptions_resize_uninterpreted_option(google_protobuf_FileOptions* msg, size_t size, upb_Arena* arena) { - upb_MiniTableField field = {999, UPB_SIZE(24, 192), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; + upb_MiniTableField field = {999, UPB_SIZE(20, 184), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; return (google_protobuf_UninterpretedOption**)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); } UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_FileOptions_add_uninterpreted_option(google_protobuf_FileOptions* msg, upb_Arena* arena) { - upb_MiniTableField field = {999, UPB_SIZE(24, 192), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; + upb_MiniTableField field = {999, UPB_SIZE(20, 184), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); if (!arr || !_upb_Array_ResizeUninitialized( arr, arr->UPB_PRIVATE(size) + 1, arena)) { @@ -6267,7 +6248,7 @@ UPB_INLINE void google_protobuf_GeneratedCodeInfo_Annotation_set_semantic(google /* Max size 32 is google.protobuf.FileOptions */ /* Max size 64 is google.protobuf.FileOptions */ -#define _UPB_MAXOPT_SIZE UPB_SIZE(112, 200) +#define _UPB_MAXOPT_SIZE UPB_SIZE(104, 192) #ifdef __cplusplus } /* extern "C" */ diff --git a/upb/cmake/google/protobuf/descriptor.upb_minitable.c b/upb/cmake/google/protobuf/descriptor.upb_minitable.c index 24b9f1c6de48b..15ce57c0e03c1 100644 --- a/upb/cmake/google/protobuf/descriptor.upb_minitable.c +++ b/upb/cmake/google/protobuf/descriptor.upb_minitable.c @@ -453,12 +453,12 @@ static const upb_MiniTableSub google_protobuf_FileOptions_submsgs[3] = { {.UPB_PRIVATE(subenum) = &google_protobuf_FileOptions_OptimizeMode_enum_init}, }; -static const upb_MiniTableField google_protobuf_FileOptions__fields[22] = { - {1, UPB_SIZE(28, 24), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, - {8, UPB_SIZE(36, 40), 2, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, +static const upb_MiniTableField google_protobuf_FileOptions__fields[21] = { + {1, UPB_SIZE(24, 16), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, + {8, 32, 2, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, {9, 4, 3, 2, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}, {10, 8, 4, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}, - {11, UPB_SIZE(44, 56), 5, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, + {11, UPB_SIZE(40, 48), 5, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, {16, 9, 6, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}, {17, 10, 7, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}, {18, 11, 8, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}, @@ -466,35 +466,34 @@ static const upb_MiniTableField google_protobuf_FileOptions__fields[22] = { {23, 13, 10, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}, {27, 14, 11, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}, {31, 15, 12, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}, - {36, UPB_SIZE(52, 72), 13, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, - {37, UPB_SIZE(60, 88), 14, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, - {39, UPB_SIZE(68, 104), 15, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, - {40, UPB_SIZE(76, 120), 16, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, - {41, UPB_SIZE(84, 136), 17, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, - {42, 16, 18, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}, - {44, UPB_SIZE(92, 152), 19, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, - {45, UPB_SIZE(100, 168), 20, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, - {50, UPB_SIZE(20, 184), 21, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, - {999, UPB_SIZE(24, 192), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, + {36, UPB_SIZE(48, 64), 13, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, + {37, UPB_SIZE(56, 80), 14, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, + {39, UPB_SIZE(64, 96), 15, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, + {40, UPB_SIZE(72, 112), 16, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, + {41, UPB_SIZE(80, 128), 17, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, + {44, UPB_SIZE(88, 144), 18, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, + {45, UPB_SIZE(96, 160), 19, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}, + {50, UPB_SIZE(16, 176), 20, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, + {999, UPB_SIZE(20, 184), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}, }; const upb_MiniTable google__protobuf__FileOptions_msg_init = { &google_protobuf_FileOptions_submsgs[0], &google_protobuf_FileOptions__fields[0], - UPB_SIZE(112, 200), 22, kUpb_ExtMode_Extendable, 1, UPB_FASTTABLE_MASK(248), 0, + UPB_SIZE(104, 192), 21, kUpb_ExtMode_Extendable, 1, UPB_FASTTABLE_MASK(248), 0, UPB_FASTTABLE_INIT({ {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x001800000100000a, &upb_pss_1bt}, + {0x001000000100000a, &upb_pss_1bt}, {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, - {0x0028000002000042, &upb_pss_1bt}, + {0x0020000002000042, &upb_pss_1bt}, {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, {0x0008000004000050, &upb_psb1_1bt}, - {0x003800000500005a, &upb_pss_1bt}, + {0x003000000500005a, &upb_pss_1bt}, {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, @@ -504,15 +503,15 @@ const upb_MiniTable google__protobuf__FileOptions_msg_init = { {0x000b000008000190, &upb_psb1_2bt}, {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, {0x000c0000090001a0, &upb_psb1_2bt}, - {0x005800000e0002aa, &upb_pss_2bt}, + {0x005000000e0002aa, &upb_pss_2bt}, {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, {0x000d00000a0001b8, &upb_psb1_2bt}, - {0x00780000100002c2, &upb_pss_2bt}, - {0x00880000110002ca, &upb_pss_2bt}, - {0x00100000120002d0, &upb_psb1_2bt}, + {0x00700000100002c2, &upb_pss_2bt}, + {0x00800000110002ca, &upb_pss_2bt}, + {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, {0x000e00000b0001d8, &upb_psb1_2bt}, - {0x00980000130002e2, &upb_pss_2bt}, - {0x00a80000140002ea, &upb_pss_2bt}, + {0x00900000120002e2, &upb_pss_2bt}, + {0x00a00000130002ea, &upb_pss_2bt}, {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric}, {0x000f00000c0001f8, &upb_psb1_2bt}, }) From 706c0d03f87fc343e210947832c130c06171f261 Mon Sep 17 00:00:00 2001 From: Jie Luo Date: Wed, 20 Dec 2023 18:19:23 -0800 Subject: [PATCH 079/255] Automated rollback of commit 1250d5f6cccb0a45f959c7219980a0aad5060ee5. PiperOrigin-RevId: 592707509 --- .../protobuf/internal/json_format_test.py | 9 +-- .../protobuf/internal/well_known_types.py | 56 ++++--------------- .../internal/well_known_types_test.py | 24 +++++--- 3 files changed, 30 insertions(+), 59 deletions(-) diff --git a/python/google/protobuf/internal/json_format_test.py b/python/google/protobuf/internal/json_format_test.py index 6c4d2dac0b9ca..15b376c181d93 100644 --- a/python/google/protobuf/internal/json_format_test.py +++ b/python/google/protobuf/internal/json_format_test.py @@ -1060,14 +1060,7 @@ def testInvalidTimestamp(self): json_format.Parse, text, message) # Time bigger than maximum time. message.value.seconds = 253402300800 - self.assertRaisesRegex(json_format.SerializeToJsonError, - 'Timestamp is not valid', - json_format.MessageToJson, message) - # Nanos smaller than 0 - message.value.seconds = 0 - message.value.nanos = -1 - self.assertRaisesRegex(json_format.SerializeToJsonError, - 'Timestamp is not valid', + self.assertRaisesRegex(OverflowError, 'date value out of range', json_format.MessageToJson, message) # Lower case t does not accept. text = '{"value": "0001-01-01t00:00:00Z"}' diff --git a/python/google/protobuf/internal/well_known_types.py b/python/google/protobuf/internal/well_known_types.py index 835e443eff764..5727bc98c2c06 100644 --- a/python/google/protobuf/internal/well_known_types.py +++ b/python/google/protobuf/internal/well_known_types.py @@ -33,8 +33,6 @@ _MICROS_PER_SECOND = 1000000 _SECONDS_PER_DAY = 24 * 3600 _DURATION_SECONDS_MAX = 315576000000 -_TIMESTAMP_SECONDS_MIN = -62135596800 -_TIMESTAMP_SECONDS_MAX = 253402300799 _EPOCH_DATETIME_NAIVE = datetime.datetime(1970, 1, 1, tzinfo=None) _EPOCH_DATETIME_AWARE = _EPOCH_DATETIME_NAIVE.replace( @@ -87,10 +85,10 @@ def ToJsonString(self): and uses 3, 6 or 9 fractional digits as required to represent the exact time. Example of the return format: '1972-01-01T10:00:20.021Z' """ - _CheckTimestampValid(self.seconds, self.nanos) - nanos = self.nanos - seconds = self.seconds % _SECONDS_PER_DAY - days = (self.seconds - seconds) // _SECONDS_PER_DAY + nanos = self.nanos % _NANOS_PER_SECOND + total_sec = self.seconds + (self.nanos - nanos) // _NANOS_PER_SECOND + seconds = total_sec % _SECONDS_PER_DAY + days = (total_sec - seconds) // _SECONDS_PER_DAY dt = datetime.datetime(1970, 1, 1) + datetime.timedelta(days, seconds) result = dt.isoformat() @@ -168,7 +166,6 @@ def FromJsonString(self, value): else: seconds += (int(timezone[1:pos])*60+int(timezone[pos+1:]))*60 # Set seconds and nanos - _CheckTimestampValid(seconds, nanos) self.seconds = int(seconds) self.nanos = int(nanos) @@ -178,53 +175,39 @@ def GetCurrentTime(self): def ToNanoseconds(self): """Converts Timestamp to nanoseconds since epoch.""" - _CheckTimestampValid(self.seconds, self.nanos) return self.seconds * _NANOS_PER_SECOND + self.nanos def ToMicroseconds(self): """Converts Timestamp to microseconds since epoch.""" - _CheckTimestampValid(self.seconds, self.nanos) return (self.seconds * _MICROS_PER_SECOND + self.nanos // _NANOS_PER_MICROSECOND) def ToMilliseconds(self): """Converts Timestamp to milliseconds since epoch.""" - _CheckTimestampValid(self.seconds, self.nanos) return (self.seconds * _MILLIS_PER_SECOND + self.nanos // _NANOS_PER_MILLISECOND) def ToSeconds(self): """Converts Timestamp to seconds since epoch.""" - _CheckTimestampValid(self.seconds, self.nanos) return self.seconds def FromNanoseconds(self, nanos): """Converts nanoseconds since epoch to Timestamp.""" - seconds = nanos // _NANOS_PER_SECOND - nanos = nanos % _NANOS_PER_SECOND - _CheckTimestampValid(seconds, nanos) - self.seconds = seconds - self.nanos = nanos + self.seconds = nanos // _NANOS_PER_SECOND + self.nanos = nanos % _NANOS_PER_SECOND def FromMicroseconds(self, micros): """Converts microseconds since epoch to Timestamp.""" - seconds = micros // _MICROS_PER_SECOND - nanos = (micros % _MICROS_PER_SECOND) * _NANOS_PER_MICROSECOND - _CheckTimestampValid(seconds, nanos) - self.seconds = seconds - self.nanos = nanos + self.seconds = micros // _MICROS_PER_SECOND + self.nanos = (micros % _MICROS_PER_SECOND) * _NANOS_PER_MICROSECOND def FromMilliseconds(self, millis): """Converts milliseconds since epoch to Timestamp.""" - seconds = millis // _MILLIS_PER_SECOND - nanos = (millis % _MILLIS_PER_SECOND) * _NANOS_PER_MILLISECOND - _CheckTimestampValid(seconds, nanos) - self.seconds = seconds - self.nanos = nanos + self.seconds = millis // _MILLIS_PER_SECOND + self.nanos = (millis % _MILLIS_PER_SECOND) * _NANOS_PER_MILLISECOND def FromSeconds(self, seconds): """Converts seconds since epoch to Timestamp.""" - _CheckTimestampValid(seconds, 0) self.seconds = seconds self.nanos = 0 @@ -246,7 +229,6 @@ def ToDatetime(self, tzinfo=None): # https://github.com/python/cpython/issues/109849) or full range (on some # platforms, see https://github.com/python/cpython/issues/110042) of # datetime. - _CheckTimestampValid(self.seconds, self.nanos) delta = datetime.timedelta( seconds=self.seconds, microseconds=_RoundTowardZero(self.nanos, _NANOS_PER_MICROSECOND), @@ -270,22 +252,8 @@ def FromDatetime(self, dt): # manipulated into a long value of seconds. During the conversion from # struct_time to long, the source date in UTC, and so it follows that the # correct transformation is calendar.timegm() - seconds = calendar.timegm(dt.utctimetuple()) - nanos = dt.microsecond * _NANOS_PER_MICROSECOND - _CheckTimestampValid(seconds, nanos) - self.seconds = seconds - self.nanos = nanos - - -def _CheckTimestampValid(seconds, nanos): - if seconds < _TIMESTAMP_SECONDS_MIN or seconds > _TIMESTAMP_SECONDS_MAX: - raise ValueError( - 'Timestamp is not valid: Seconds {0} must be in range ' - '[-62135596800, 253402300799].'.format(seconds)) - if nanos < 0 or nanos >= _NANOS_PER_SECOND: - raise ValueError( - 'Timestamp is not valid: Nanos {} must be in a range ' - '[0, 999999].'.format(nanos)) + self.seconds = calendar.timegm(dt.utctimetuple()) + self.nanos = dt.microsecond * _NANOS_PER_MICROSECOND class Duration(object): diff --git a/python/google/protobuf/internal/well_known_types_test.py b/python/google/protobuf/internal/well_known_types_test.py index da273166eb970..37d20491735f1 100644 --- a/python/google/protobuf/internal/well_known_types_test.py +++ b/python/google/protobuf/internal/well_known_types_test.py @@ -352,15 +352,27 @@ def testTimezoneAwareMinDatetimeConversion(self): ) def testNanosOneSecond(self): + # TODO: b/301980950 - Test error behavior instead once ToDatetime validates + # that nanos are in expected range. tz = _TZ_PACIFIC ts = timestamp_pb2.Timestamp(nanos=1_000_000_000) - self.assertRaisesRegex(ValueError, 'Timestamp is not valid', - ts.ToDatetime) + self.assertEqual(ts.ToDatetime(), datetime.datetime(1970, 1, 1, 0, 0, 1)) + self.assertEqual( + ts.ToDatetime(tz), datetime.datetime(1969, 12, 31, 16, 0, 1, tzinfo=tz) + ) def testNanosNegativeOneSecond(self): + # TODO: b/301980950 - Test error behavior instead once ToDatetime validates + # that nanos are in expected range. + tz = _TZ_PACIFIC ts = timestamp_pb2.Timestamp(nanos=-1_000_000_000) - self.assertRaisesRegex(ValueError, 'Timestamp is not valid', - ts.ToDatetime) + self.assertEqual( + ts.ToDatetime(), datetime.datetime(1969, 12, 31, 23, 59, 59) + ) + self.assertEqual( + ts.ToDatetime(tz), + datetime.datetime(1969, 12, 31, 15, 59, 59, tzinfo=tz), + ) def testTimedeltaConversion(self): message = duration_pb2.Duration() @@ -409,10 +421,8 @@ def testInvalidTimestamp(self): self.assertRaisesRegex(ValueError, 'year (0 )?is out of range', message.FromJsonString, '0000-01-01T00:00:00Z') message.seconds = 253402300800 - self.assertRaisesRegex(ValueError, 'Timestamp is not valid', + self.assertRaisesRegex(OverflowError, 'date value out of range', message.ToJsonString) - self.assertRaisesRegex(ValueError, 'Timestamp is not valid', - message.FromSeconds, -62135596801) def testInvalidDuration(self): message = duration_pb2.Duration() From 68f5ffb3a92401b4a88da9e8e302106716870d0e Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Thu, 21 Dec 2023 02:49:00 -0800 Subject: [PATCH 080/255] Small improvements: - remove a branch from InternalExtend - remove redundant Destroy call - dedup UnsafeArenaAddAllocated - fix test PiperOrigin-RevId: 592804776 --- src/google/protobuf/repeated_field_unittest.cc | 12 +++++++----- src/google/protobuf/repeated_ptr_field.cc | 9 ++++----- src/google/protobuf/repeated_ptr_field.h | 6 +++--- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/src/google/protobuf/repeated_field_unittest.cc b/src/google/protobuf/repeated_field_unittest.cc index d99aae6f525fe..7dac43d7fcec3 100644 --- a/src/google/protobuf/repeated_field_unittest.cc +++ b/src/google/protobuf/repeated_field_unittest.cc @@ -1035,7 +1035,7 @@ TEST(Movable, Works) { EXPECT_FALSE(internal::IsMovable::value); } -TEST(RepeatedField, MoveAdd) { +TEST(RepeatedPtrField, MoveAdd) { RepeatedPtrField field; TestAllTypes test_all_types; auto* optional_nested_message = @@ -1911,9 +1911,12 @@ TEST(RepeatedPtrField, SmallOptimization) { // Verify the string is where we think it is. EXPECT_EQ(&*array->begin(), &str); EXPECT_EQ(array->pointer_begin()[0], &str); + auto is_inlined = [array]() { + return std::less_equal{}(array, &*array->pointer_begin()) && + std::less{}(&*array->pointer_begin(), array + 1); + }; // The T** in pointer_begin points into the sso in the object. - EXPECT_TRUE(std::less_equal{}(array, &*array->pointer_begin())); - EXPECT_TRUE(std::less_equal{}(&*array->pointer_begin(), array + 1)); + EXPECT_TRUE(is_inlined()); // Adding a second object stops sso. std::string str2; @@ -1925,8 +1928,7 @@ TEST(RepeatedPtrField, SmallOptimization) { // We used some arena space now. EXPECT_LT(usage_before, arena.SpaceUsed()); // And the pointer_begin is not in the sso anymore. - EXPECT_FALSE(std::less_equal{}(array, &*array->pointer_begin()) && - std::less_equal{}(&*array->pointer_begin(), array + 1)); + EXPECT_FALSE(is_inlined()); } TEST(RepeatedPtrField, CopyAssign) { diff --git a/src/google/protobuf/repeated_ptr_field.cc b/src/google/protobuf/repeated_ptr_field.cc index 6fe9f9af723ba..c716be5abd48e 100644 --- a/src/google/protobuf/repeated_ptr_field.cc +++ b/src/google/protobuf/repeated_ptr_field.cc @@ -9,6 +9,8 @@ // Based on original Protocol Buffers design by // Sanjay Ghemawat, Jeff Dean, and others. +#include "google/protobuf/repeated_ptr_field.h" + #include #include #include @@ -59,11 +61,8 @@ void** RepeatedPtrFieldBase::InternalExtend(int extend_amount) { new_rep->elements[0] = tagged_rep_or_elem_; } else { Rep* old_rep = rep(); - if (old_rep->allocated_size > 0) { - memcpy(new_rep->elements, old_rep->elements, - old_rep->allocated_size * ptr_size); - } - new_rep->allocated_size = old_rep->allocated_size; + memcpy(new_rep, old_rep, + old_rep->allocated_size * ptr_size + kRepHeaderSize); size_t old_size = capacity * ptr_size + kRepHeaderSize; if (arena == nullptr) { diff --git a/src/google/protobuf/repeated_ptr_field.h b/src/google/protobuf/repeated_ptr_field.h index 3722fe0750995..1f41a83f17274 100644 --- a/src/google/protobuf/repeated_ptr_field.h +++ b/src/google/protobuf/repeated_ptr_field.h @@ -488,20 +488,20 @@ class PROTOBUF_EXPORT RepeatedPtrFieldBase { // Pass value_arena and my_arena to avoid duplicate virtual call (value) // or load (mine). Value* value, Arena* value_arena, Arena* my_arena) { + using H = CommonHandler; // Ensure that either the value is in the same arena, or if not, we do the // appropriate thing: Own() it (if it's on heap and we're in an arena) or // copy it to our arena/heap (otherwise). if (my_arena != nullptr && value_arena == nullptr) { my_arena->Own(value); } else if (my_arena != value_arena) { + ABSL_DCHECK(value_arena != nullptr); auto* new_value = TypeHandler::NewFromPrototype(value, my_arena); - using H = CommonHandler; H::Merge(*value, new_value); - H::Delete(value, value_arena); value = new_value; } - UnsafeArenaAddAllocated(value); + UnsafeArenaAddAllocated(value); } template From fd6f83576fdc39d99f3bbdd9bb21a9223eb89e19 Mon Sep 17 00:00:00 2001 From: Eric Salo Date: Thu, 21 Dec 2023 06:24:18 -0800 Subject: [PATCH 081/255] upb: stop returning void from void functions PiperOrigin-RevId: 592844285 --- upb/mem/arena.h | 2 +- upb/mini_table/extension.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/upb/mem/arena.h b/upb/mem/arena.h index 385b14e5bfa23..319707ec29434 100644 --- a/upb/mem/arena.h +++ b/upb/mem/arena.h @@ -68,7 +68,7 @@ UPB_API_INLINE void* upb_Arena_Realloc(upb_Arena* a, void* ptr, size_t oldsize, // this was not the last alloc. UPB_API_INLINE void upb_Arena_ShrinkLast(upb_Arena* a, void* ptr, size_t oldsize, size_t size) { - return UPB_PRIVATE(_upb_Arena_ShrinkLast)(a, ptr, oldsize, size); + UPB_PRIVATE(_upb_Arena_ShrinkLast)(a, ptr, oldsize, size); } #ifdef __cplusplus diff --git a/upb/mini_table/extension.h b/upb/mini_table/extension.h index 67b55ec5bb2b9..341dff64d1b88 100644 --- a/upb/mini_table/extension.h +++ b/upb/mini_table/extension.h @@ -37,7 +37,7 @@ UPB_API_INLINE const upb_MiniTable* upb_MiniTableExtension_GetSubMessage( UPB_API_INLINE void upb_MiniTableExtension_SetSubMessage( upb_MiniTableExtension* e, const upb_MiniTable* m) { - return UPB_PRIVATE(_upb_MiniTableExtension_SetSubMessage)(e, m); + UPB_PRIVATE(_upb_MiniTableExtension_SetSubMessage)(e, m); } #ifdef __cplusplus From df7e74b1d4e2656454cfeaf651c39126765a3291 Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Thu, 21 Dec 2023 14:37:31 +0000 Subject: [PATCH 082/255] Auto-generate files after cl/592844285 --- php/ext/google/protobuf/php-upb.h | 4 ++-- ruby/ext/google/protobuf_c/ruby-upb.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/php/ext/google/protobuf/php-upb.h b/php/ext/google/protobuf/php-upb.h index e2c35bb45e153..88cacad5f14da 100644 --- a/php/ext/google/protobuf/php-upb.h +++ b/php/ext/google/protobuf/php-upb.h @@ -772,7 +772,7 @@ UPB_API_INLINE void* upb_Arena_Realloc(upb_Arena* a, void* ptr, size_t oldsize, // this was not the last alloc. UPB_API_INLINE void upb_Arena_ShrinkLast(upb_Arena* a, void* ptr, size_t oldsize, size_t size) { - return UPB_PRIVATE(_upb_Arena_ShrinkLast)(a, ptr, oldsize, size); + UPB_PRIVATE(_upb_Arena_ShrinkLast)(a, ptr, oldsize, size); } #ifdef __cplusplus @@ -1753,7 +1753,7 @@ UPB_API_INLINE const upb_MiniTable* upb_MiniTableExtension_GetSubMessage( UPB_API_INLINE void upb_MiniTableExtension_SetSubMessage( upb_MiniTableExtension* e, const upb_MiniTable* m) { - return UPB_PRIVATE(_upb_MiniTableExtension_SetSubMessage)(e, m); + UPB_PRIVATE(_upb_MiniTableExtension_SetSubMessage)(e, m); } #ifdef __cplusplus diff --git a/ruby/ext/google/protobuf_c/ruby-upb.h b/ruby/ext/google/protobuf_c/ruby-upb.h index 0bc527b44c9c1..f7525163fa3f1 100755 --- a/ruby/ext/google/protobuf_c/ruby-upb.h +++ b/ruby/ext/google/protobuf_c/ruby-upb.h @@ -774,7 +774,7 @@ UPB_API_INLINE void* upb_Arena_Realloc(upb_Arena* a, void* ptr, size_t oldsize, // this was not the last alloc. UPB_API_INLINE void upb_Arena_ShrinkLast(upb_Arena* a, void* ptr, size_t oldsize, size_t size) { - return UPB_PRIVATE(_upb_Arena_ShrinkLast)(a, ptr, oldsize, size); + UPB_PRIVATE(_upb_Arena_ShrinkLast)(a, ptr, oldsize, size); } #ifdef __cplusplus @@ -1755,7 +1755,7 @@ UPB_API_INLINE const upb_MiniTable* upb_MiniTableExtension_GetSubMessage( UPB_API_INLINE void upb_MiniTableExtension_SetSubMessage( upb_MiniTableExtension* e, const upb_MiniTable* m) { - return UPB_PRIVATE(_upb_MiniTableExtension_SetSubMessage)(e, m); + UPB_PRIVATE(_upb_MiniTableExtension_SetSubMessage)(e, m); } #ifdef __cplusplus From cdb078275da8f5b4094e00316c0ad9041d2c5fed Mon Sep 17 00:00:00 2001 From: Eric Salo Date: Thu, 21 Dec 2023 06:41:57 -0800 Subject: [PATCH 083/255] upb: add more functions to bits/mini_table_field.h PiperOrigin-RevId: 592847506 --- upb/message/internal/accessors.h | 18 +++++++++++------- upb/mini_descriptor/internal/encode_test.cc | 2 +- upb/mini_table/internal/field.h | 10 +++++----- 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/upb/message/internal/accessors.h b/upb/message/internal/accessors.h index 023f47c00b2fb..089fb64d9094d 100644 --- a/upb/message/internal/accessors.h +++ b/upb/message/internal/accessors.h @@ -56,22 +56,25 @@ extern "C" { UPB_INLINE bool UPB_PRIVATE(_upb_Message_GetHasbit)( const upb_Message* msg, const upb_MiniTableField* f) { - const size_t offset = _upb_MiniTableField_HasbitOffset(f); - const char mask = _upb_MiniTableField_HasbitMask(f); + const size_t offset = UPB_PRIVATE(_upb_MiniTableField_HasbitOffset)(f); + const char mask = UPB_PRIVATE(_upb_MiniTableField_HasbitMask)(f); + return (*UPB_PTR_AT(msg, offset, const char) & mask) != 0; } UPB_INLINE void UPB_PRIVATE(_upb_Message_SetHasbit)( const upb_Message* msg, const upb_MiniTableField* f) { - const size_t offset = _upb_MiniTableField_HasbitOffset(f); - const char mask = _upb_MiniTableField_HasbitMask(f); + const size_t offset = UPB_PRIVATE(_upb_MiniTableField_HasbitOffset)(f); + const char mask = UPB_PRIVATE(_upb_MiniTableField_HasbitMask)(f); + (*UPB_PTR_AT(msg, offset, char)) |= mask; } UPB_INLINE void UPB_PRIVATE(_upb_Message_ClearHasbit)( const upb_Message* msg, const upb_MiniTableField* f) { - const size_t offset = _upb_MiniTableField_HasbitOffset(f); - const char mask = _upb_MiniTableField_HasbitMask(f); + const size_t offset = UPB_PRIVATE(_upb_MiniTableField_HasbitOffset)(f); + const char mask = UPB_PRIVATE(_upb_MiniTableField_HasbitMask)(f); + (*UPB_PTR_AT(msg, offset, char)) &= ~mask; } @@ -79,7 +82,8 @@ UPB_INLINE void UPB_PRIVATE(_upb_Message_ClearHasbit)( UPB_INLINE uint32_t* UPB_PRIVATE(_upb_Message_OneofCasePtr)( upb_Message* msg, const upb_MiniTableField* f) { - return UPB_PTR_AT(msg, _upb_MiniTableField_OneofOffset(f), uint32_t); + return UPB_PTR_AT(msg, UPB_PRIVATE(_upb_MiniTableField_OneofOffset)(f), + uint32_t); } UPB_INLINE uint32_t UPB_PRIVATE(_upb_Message_GetOneofCase)( diff --git a/upb/mini_descriptor/internal/encode_test.cc b/upb/mini_descriptor/internal/encode_test.cc index 80c2a205bd480..3ae2f6f56c85d 100644 --- a/upb/mini_descriptor/internal/encode_test.cc +++ b/upb/mini_descriptor/internal/encode_test.cc @@ -156,7 +156,7 @@ TEST_P(MiniTableTest, AllScalarTypesOneof) { EXPECT_EQ(table->UPB_PRIVATE(fields)[0].UPB_PRIVATE(offset), f->UPB_PRIVATE(offset)); // All presence fields should point to the same oneof case offset. - size_t case_ofs = _upb_MiniTableField_OneofOffset(f); + size_t case_ofs = UPB_PRIVATE(_upb_MiniTableField_OneofOffset)(f); EXPECT_EQ(table->UPB_PRIVATE(fields)[0].presence, f->presence); EXPECT_TRUE(f->UPB_PRIVATE(offset) < table->UPB_PRIVATE(size)); EXPECT_TRUE(case_ofs < table->UPB_PRIVATE(size)); diff --git a/upb/mini_table/internal/field.h b/upb/mini_table/internal/field.h index 4d760549c3406..a450f0521afb2 100644 --- a/upb/mini_table/internal/field.h +++ b/upb/mini_table/internal/field.h @@ -131,15 +131,15 @@ UPB_PRIVATE(_upb_MiniTableField_CType)(const upb_MiniTableField* f) { return upb_FieldType_CType(UPB_PRIVATE(_upb_MiniTableField_Type)(f)); } -UPB_INLINE char _upb_MiniTableField_HasbitMask( +UPB_INLINE char UPB_PRIVATE(_upb_MiniTableField_HasbitMask)( const struct upb_MiniTableField* f) { UPB_ASSERT(f->presence > 0); const size_t index = f->presence; return 1 << (index % 8); } -UPB_INLINE size_t -_upb_MiniTableField_HasbitOffset(const struct upb_MiniTableField* f) { +UPB_INLINE size_t UPB_PRIVATE(_upb_MiniTableField_HasbitOffset)( + const struct upb_MiniTableField* f) { UPB_ASSERT(f->presence > 0); const size_t index = f->presence; return index / 8; @@ -180,8 +180,8 @@ UPB_PRIVATE(_upb_MiniTableField_Offset)(const struct upb_MiniTableField* f) { return f->UPB_ONLYBITS(offset); } -UPB_INLINE size_t -_upb_MiniTableField_OneofOffset(const struct upb_MiniTableField* f) { +UPB_INLINE size_t UPB_PRIVATE(_upb_MiniTableField_OneofOffset)( + const struct upb_MiniTableField* f) { UPB_ASSERT(UPB_PRIVATE(_upb_MiniTableField_IsInOneof)(f)); return ~(ptrdiff_t)f->presence; } From a0e8195490882224d5525200461e9f34f20f32e6 Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Thu, 21 Dec 2023 14:54:29 +0000 Subject: [PATCH 084/255] Auto-generate files after cl/592847506 --- php/ext/google/protobuf/php-upb.h | 28 +++++++++++++++------------ ruby/ext/google/protobuf_c/ruby-upb.h | 28 +++++++++++++++------------ 2 files changed, 32 insertions(+), 24 deletions(-) diff --git a/php/ext/google/protobuf/php-upb.h b/php/ext/google/protobuf/php-upb.h index 88cacad5f14da..97cf339ed709f 100644 --- a/php/ext/google/protobuf/php-upb.h +++ b/php/ext/google/protobuf/php-upb.h @@ -1189,15 +1189,15 @@ UPB_PRIVATE(_upb_MiniTableField_CType)(const upb_MiniTableField* f) { return upb_FieldType_CType(UPB_PRIVATE(_upb_MiniTableField_Type)(f)); } -UPB_INLINE char _upb_MiniTableField_HasbitMask( +UPB_INLINE char UPB_PRIVATE(_upb_MiniTableField_HasbitMask)( const struct upb_MiniTableField* f) { UPB_ASSERT(f->presence > 0); const size_t index = f->presence; return 1 << (index % 8); } -UPB_INLINE size_t -_upb_MiniTableField_HasbitOffset(const struct upb_MiniTableField* f) { +UPB_INLINE size_t UPB_PRIVATE(_upb_MiniTableField_HasbitOffset)( + const struct upb_MiniTableField* f) { UPB_ASSERT(f->presence > 0); const size_t index = f->presence; return index / 8; @@ -1238,8 +1238,8 @@ UPB_PRIVATE(_upb_MiniTableField_Offset)(const struct upb_MiniTableField* f) { return f->UPB_ONLYBITS(offset); } -UPB_INLINE size_t -_upb_MiniTableField_OneofOffset(const struct upb_MiniTableField* f) { +UPB_INLINE size_t UPB_PRIVATE(_upb_MiniTableField_OneofOffset)( + const struct upb_MiniTableField* f) { UPB_ASSERT(UPB_PRIVATE(_upb_MiniTableField_IsInOneof)(f)); return ~(ptrdiff_t)f->presence; } @@ -2499,22 +2499,25 @@ extern "C" { UPB_INLINE bool UPB_PRIVATE(_upb_Message_GetHasbit)( const upb_Message* msg, const upb_MiniTableField* f) { - const size_t offset = _upb_MiniTableField_HasbitOffset(f); - const char mask = _upb_MiniTableField_HasbitMask(f); + const size_t offset = UPB_PRIVATE(_upb_MiniTableField_HasbitOffset)(f); + const char mask = UPB_PRIVATE(_upb_MiniTableField_HasbitMask)(f); + return (*UPB_PTR_AT(msg, offset, const char) & mask) != 0; } UPB_INLINE void UPB_PRIVATE(_upb_Message_SetHasbit)( const upb_Message* msg, const upb_MiniTableField* f) { - const size_t offset = _upb_MiniTableField_HasbitOffset(f); - const char mask = _upb_MiniTableField_HasbitMask(f); + const size_t offset = UPB_PRIVATE(_upb_MiniTableField_HasbitOffset)(f); + const char mask = UPB_PRIVATE(_upb_MiniTableField_HasbitMask)(f); + (*UPB_PTR_AT(msg, offset, char)) |= mask; } UPB_INLINE void UPB_PRIVATE(_upb_Message_ClearHasbit)( const upb_Message* msg, const upb_MiniTableField* f) { - const size_t offset = _upb_MiniTableField_HasbitOffset(f); - const char mask = _upb_MiniTableField_HasbitMask(f); + const size_t offset = UPB_PRIVATE(_upb_MiniTableField_HasbitOffset)(f); + const char mask = UPB_PRIVATE(_upb_MiniTableField_HasbitMask)(f); + (*UPB_PTR_AT(msg, offset, char)) &= ~mask; } @@ -2522,7 +2525,8 @@ UPB_INLINE void UPB_PRIVATE(_upb_Message_ClearHasbit)( UPB_INLINE uint32_t* UPB_PRIVATE(_upb_Message_OneofCasePtr)( upb_Message* msg, const upb_MiniTableField* f) { - return UPB_PTR_AT(msg, _upb_MiniTableField_OneofOffset(f), uint32_t); + return UPB_PTR_AT(msg, UPB_PRIVATE(_upb_MiniTableField_OneofOffset)(f), + uint32_t); } UPB_INLINE uint32_t UPB_PRIVATE(_upb_Message_GetOneofCase)( diff --git a/ruby/ext/google/protobuf_c/ruby-upb.h b/ruby/ext/google/protobuf_c/ruby-upb.h index f7525163fa3f1..add6f095fc7a6 100755 --- a/ruby/ext/google/protobuf_c/ruby-upb.h +++ b/ruby/ext/google/protobuf_c/ruby-upb.h @@ -1191,15 +1191,15 @@ UPB_PRIVATE(_upb_MiniTableField_CType)(const upb_MiniTableField* f) { return upb_FieldType_CType(UPB_PRIVATE(_upb_MiniTableField_Type)(f)); } -UPB_INLINE char _upb_MiniTableField_HasbitMask( +UPB_INLINE char UPB_PRIVATE(_upb_MiniTableField_HasbitMask)( const struct upb_MiniTableField* f) { UPB_ASSERT(f->presence > 0); const size_t index = f->presence; return 1 << (index % 8); } -UPB_INLINE size_t -_upb_MiniTableField_HasbitOffset(const struct upb_MiniTableField* f) { +UPB_INLINE size_t UPB_PRIVATE(_upb_MiniTableField_HasbitOffset)( + const struct upb_MiniTableField* f) { UPB_ASSERT(f->presence > 0); const size_t index = f->presence; return index / 8; @@ -1240,8 +1240,8 @@ UPB_PRIVATE(_upb_MiniTableField_Offset)(const struct upb_MiniTableField* f) { return f->UPB_ONLYBITS(offset); } -UPB_INLINE size_t -_upb_MiniTableField_OneofOffset(const struct upb_MiniTableField* f) { +UPB_INLINE size_t UPB_PRIVATE(_upb_MiniTableField_OneofOffset)( + const struct upb_MiniTableField* f) { UPB_ASSERT(UPB_PRIVATE(_upb_MiniTableField_IsInOneof)(f)); return ~(ptrdiff_t)f->presence; } @@ -2501,22 +2501,25 @@ extern "C" { UPB_INLINE bool UPB_PRIVATE(_upb_Message_GetHasbit)( const upb_Message* msg, const upb_MiniTableField* f) { - const size_t offset = _upb_MiniTableField_HasbitOffset(f); - const char mask = _upb_MiniTableField_HasbitMask(f); + const size_t offset = UPB_PRIVATE(_upb_MiniTableField_HasbitOffset)(f); + const char mask = UPB_PRIVATE(_upb_MiniTableField_HasbitMask)(f); + return (*UPB_PTR_AT(msg, offset, const char) & mask) != 0; } UPB_INLINE void UPB_PRIVATE(_upb_Message_SetHasbit)( const upb_Message* msg, const upb_MiniTableField* f) { - const size_t offset = _upb_MiniTableField_HasbitOffset(f); - const char mask = _upb_MiniTableField_HasbitMask(f); + const size_t offset = UPB_PRIVATE(_upb_MiniTableField_HasbitOffset)(f); + const char mask = UPB_PRIVATE(_upb_MiniTableField_HasbitMask)(f); + (*UPB_PTR_AT(msg, offset, char)) |= mask; } UPB_INLINE void UPB_PRIVATE(_upb_Message_ClearHasbit)( const upb_Message* msg, const upb_MiniTableField* f) { - const size_t offset = _upb_MiniTableField_HasbitOffset(f); - const char mask = _upb_MiniTableField_HasbitMask(f); + const size_t offset = UPB_PRIVATE(_upb_MiniTableField_HasbitOffset)(f); + const char mask = UPB_PRIVATE(_upb_MiniTableField_HasbitMask)(f); + (*UPB_PTR_AT(msg, offset, char)) &= ~mask; } @@ -2524,7 +2527,8 @@ UPB_INLINE void UPB_PRIVATE(_upb_Message_ClearHasbit)( UPB_INLINE uint32_t* UPB_PRIVATE(_upb_Message_OneofCasePtr)( upb_Message* msg, const upb_MiniTableField* f) { - return UPB_PTR_AT(msg, _upb_MiniTableField_OneofOffset(f), uint32_t); + return UPB_PTR_AT(msg, UPB_PRIVATE(_upb_MiniTableField_OneofOffset)(f), + uint32_t); } UPB_INLINE uint32_t UPB_PRIVATE(_upb_Message_GetOneofCase)( From 4d9c76b4cde982e14a73e93821daf1d8d2e1b6a9 Mon Sep 17 00:00:00 2001 From: Eric Salo Date: Thu, 21 Dec 2023 07:29:29 -0800 Subject: [PATCH 085/255] upb: fix typo in IFTTT block name PiperOrigin-RevId: 592856106 --- upb/mem/internal/arena.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/upb/mem/internal/arena.h b/upb/mem/internal/arena.h index 421988e63fdd9..bff2b602ddeb1 100644 --- a/upb/mem/internal/arena.h +++ b/upb/mem/internal/arena.h @@ -22,14 +22,14 @@ // the full struct is not visible outside of arena.c. Yes, I know, it's awful. #define UPB_ARENA_SIZE_HACK 7 -// LINT.IfChange(upb_Array) +// LINT.IfChange(upb_Arena) struct upb_Arena { char* UPB_ONLYBITS(ptr); char* UPB_ONLYBITS(end); }; -// LINT.ThenChange(//depot/google3/third_party/upb/bits/typescript/arena.ts:upb_Array) +// LINT.ThenChange(//depot/google3/third_party/upb/bits/typescript/arena.ts:upb_Arena) #ifdef __cplusplus extern "C" { From 6964e2c9d40667162b0d94e05f702d255f6bd3b2 Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Thu, 21 Dec 2023 15:42:16 +0000 Subject: [PATCH 086/255] Auto-generate files after cl/592856106 --- php/ext/google/protobuf/php-upb.h | 4 ++-- ruby/ext/google/protobuf_c/ruby-upb.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/php/ext/google/protobuf/php-upb.h b/php/ext/google/protobuf/php-upb.h index 97cf339ed709f..b8bd2044d90bf 100644 --- a/php/ext/google/protobuf/php-upb.h +++ b/php/ext/google/protobuf/php-upb.h @@ -643,14 +643,14 @@ UPB_INLINE void upb_gfree(void* ptr) { upb_free(&upb_alloc_global, ptr); } // the full struct is not visible outside of arena.c. Yes, I know, it's awful. #define UPB_ARENA_SIZE_HACK 7 -// LINT.IfChange(upb_Array) +// LINT.IfChange(upb_Arena) struct upb_Arena { char* UPB_ONLYBITS(ptr); char* UPB_ONLYBITS(end); }; -// LINT.ThenChange(//depot/google3/third_party/upb/bits/typescript/arena.ts:upb_Array) +// LINT.ThenChange(//depot/google3/third_party/upb/bits/typescript/arena.ts:upb_Arena) #ifdef __cplusplus extern "C" { diff --git a/ruby/ext/google/protobuf_c/ruby-upb.h b/ruby/ext/google/protobuf_c/ruby-upb.h index add6f095fc7a6..6f8c22bb881fb 100755 --- a/ruby/ext/google/protobuf_c/ruby-upb.h +++ b/ruby/ext/google/protobuf_c/ruby-upb.h @@ -645,14 +645,14 @@ UPB_INLINE void upb_gfree(void* ptr) { upb_free(&upb_alloc_global, ptr); } // the full struct is not visible outside of arena.c. Yes, I know, it's awful. #define UPB_ARENA_SIZE_HACK 7 -// LINT.IfChange(upb_Array) +// LINT.IfChange(upb_Arena) struct upb_Arena { char* UPB_ONLYBITS(ptr); char* UPB_ONLYBITS(end); }; -// LINT.ThenChange(//depot/google3/third_party/upb/bits/typescript/arena.ts:upb_Array) +// LINT.ThenChange(//depot/google3/third_party/upb/bits/typescript/arena.ts:upb_Arena) #ifdef __cplusplus extern "C" { From 588d5aa0dbee01c6caf51add7c7ed74edbe0c794 Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Thu, 21 Dec 2023 07:49:15 -0800 Subject: [PATCH 087/255] Optimized binary/JSON parsing to no longer copy input data into a temp buffer. These decoders have copied by default for a long time. There is no longer any need to copy anything. This should reduce CPU and memory usage. PiperOrigin-RevId: 592859621 --- php/ext/google/protobuf/message.c | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/php/ext/google/protobuf/message.c b/php/ext/google/protobuf/message.c index 979f226fc9ced..15461bf98811c 100644 --- a/php/ext/google/protobuf/message.c +++ b/php/ext/google/protobuf/message.c @@ -682,7 +682,6 @@ PHP_METHOD(Message, mergeFrom) { PHP_METHOD(Message, mergeFromString) { Message* intern = (Message*)Z_OBJ_P(getThis()); char* data = NULL; - char* data_copy = NULL; zend_long data_len; const upb_MiniTable* l = upb_MessageDef_MiniTable(intern->desc->msgdef); upb_Arena* arena = Arena_Get(&intern->arena); @@ -692,11 +691,7 @@ PHP_METHOD(Message, mergeFromString) { return; } - // TODO: avoid this copy when we can make the decoder copy. - data_copy = upb_Arena_Malloc(arena, data_len); - memcpy(data_copy, data, data_len); - - if (upb_Decode(data_copy, data_len, intern->msg, l, NULL, 0, arena) != + if (upb_Decode(data, data_len, intern->msg, l, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { zend_throw_exception_ex(NULL, 0, "Error occurred during parsing"); return; @@ -739,7 +734,6 @@ PHP_METHOD(Message, serializeToString) { PHP_METHOD(Message, mergeFromJsonString) { Message* intern = (Message*)Z_OBJ_P(getThis()); char* data = NULL; - char* data_copy = NULL; zend_long data_len; upb_Arena* arena = Arena_Get(&intern->arena); upb_Status status; @@ -751,17 +745,12 @@ PHP_METHOD(Message, mergeFromJsonString) { return; } - // TODO: avoid this copy when we can make the decoder copy. - data_copy = upb_Arena_Malloc(arena, data_len + 1); - memcpy(data_copy, data, data_len); - data_copy[data_len] = '\0'; - if (ignore_json_unknown) { options |= upb_JsonDecode_IgnoreUnknown; } upb_Status_Clear(&status); - if (!upb_JsonDecode(data_copy, data_len, intern->msg, intern->desc->msgdef, + if (!upb_JsonDecode(data, data_len, intern->msg, intern->desc->msgdef, DescriptorPool_GetSymbolTable(), options, arena, &status)) { zend_throw_exception_ex(NULL, 0, "Error occurred during parsing: %s", From b997cb6d8d08750a1e92ef099a39bce56f93788c Mon Sep 17 00:00:00 2001 From: Eric Salo Date: Thu, 21 Dec 2023 08:09:54 -0800 Subject: [PATCH 088/255] upb: add a non-void typedef for upb_Message PiperOrigin-RevId: 592863926 --- protos/protos.h | 10 +- protos/protos_internal_test.cc | 4 +- protos_generator/gen_accessors.cc | 2 +- protos_generator/gen_messages.cc | 17 +- python/BUILD.bazel | 1 + python/descriptor.c | 42 +- python/descriptor_pool.c | 9 +- python/map.c | 2 +- upb/base/BUILD | 1 + upb/base/upcast.h | 29 + upb/conformance/BUILD | 2 + upb/conformance/conformance_upb.c | 5 +- upb/generated_code_support.h | 1 + upb/json/decode_test.cc | 5 +- upb/json/encode_test.cc | 9 +- upb/json/fuzz_test.cc | 13 +- upb/message/accessors_test.cc | 153 +- upb/message/copy_test.cc | 51 +- upb/message/promote_test.cc | 70 +- upb/message/test.cc | 55 +- upb/message/types.h | 4 +- upb/message/utf8_test.cc | 18 +- upb/reflection/BUILD | 2 + upb/reflection/field_def.c | 4 +- upb/reflection/internal/def_builder.c | 8 +- .../stage0/google/protobuf/descriptor.upb.h | 2263 +++++++++-------- upb/test/BUILD | 1 + upb/test/test_cpp.cc | 12 +- upb/util/def_to_proto_test.cc | 4 +- upb/util/required_fields_test.cc | 17 +- upb/wire/decode.c | 12 +- upb/wire/encode.c | 6 +- upb/wire/encode.h | 6 +- upb_generator/protoc-gen-upb.cc | 74 +- .../google/protobuf/compiler/plugin.upb.h | 250 +- upb_generator/upbdev.c | 10 +- 36 files changed, 1793 insertions(+), 1379 deletions(-) create mode 100644 upb/base/upcast.h diff --git a/protos/protos.h b/protos/protos.h index a06c9e4815876..0521e33c374ed 100644 --- a/protos/protos.h +++ b/protos/protos.h @@ -72,7 +72,7 @@ class Ptr final { #endif private: - Ptr(void* msg, upb_Arena* arena) : p_(msg, arena) {} // NOLINT + Ptr(upb_Message* msg, upb_Arena* arena) : p_(msg, arena) {} // NOLINT friend class Ptr; friend typename T::Access; @@ -132,11 +132,11 @@ struct PrivateAccess { return message->msg(); } template - static auto Proxy(void* p, upb_Arena* arena) { + static auto Proxy(upb_Message* p, upb_Arena* arena) { return typename T::Proxy(p, arena); } template - static auto CProxy(const void* p, upb_Arena* arena) { + static auto CProxy(const upb_Message* p, upb_Arena* arena) { return typename T::CProxy(p, arena); } }; @@ -152,7 +152,7 @@ T CreateMessage() { } template -typename T::Proxy CreateMessageProxy(void* msg, upb_Arena* arena) { +typename T::Proxy CreateMessageProxy(upb_Message* msg, upb_Arena* arena) { return typename T::Proxy(msg, arena); } @@ -418,7 +418,7 @@ absl::StatusOr> GetExtension( upb_MiniTableExtension_Number(id.mini_table_ext())); } return Ptr(::protos::internal::CreateMessage( - ext->data.ptr, ::protos::internal::GetArena(message))); + (upb_Message*)ext->data.ptr, ::protos::internal::GetArena(message))); } template (message, source_arena); + TestModel model = protos::internal::MoveMessage( + (upb_Message*)message, source_arena); // Now that we have moved ownership, free original arena. upb_Arena_Free(source_arena); EXPECT_EQ(model.int_value_with_default(), 123); diff --git a/protos_generator/gen_accessors.cc b/protos_generator/gen_accessors.cc index 5a121c82bd819..44a0cc64f78b4 100644 --- a/protos_generator/gen_accessors.cc +++ b/protos_generator/gen_accessors.cc @@ -325,7 +325,7 @@ void WriteMapAccessorDefinitions(const protobuf::Descriptor* message, $5* msg_value; $7bool success = $4_$9_get(msg_, $8, &msg_value); if (success) { - return ::protos::internal::CreateMessage<$6>(msg_value, arena_); + return ::protos::internal::CreateMessage<$6>(UPB_UPCAST(msg_value), arena_); } return absl::NotFoundError(""); } diff --git a/protos_generator/gen_messages.cc b/protos_generator/gen_messages.cc index 89ca8611e688f..03c48ea2ba3d1 100644 --- a/protos_generator/gen_messages.cc +++ b/protos_generator/gen_messages.cc @@ -181,8 +181,8 @@ void WriteModelPublicDeclaration( output( R"cc( private: - const void* msg() const { return msg_; } - void* msg() { return msg_; } + const upb_Message* msg() const { return UPB_UPCAST(msg_); } + upb_Message* msg() { return UPB_UPCAST(msg_); } $0(upb_Message* msg, upb_Arena* arena) : $0Access() { msg_ = ($1*)msg; @@ -242,9 +242,10 @@ void WriteModelProxyDeclaration(const protobuf::Descriptor* descriptor, output( R"cc( private: - void* msg() const { return msg_; } + upb_Message* msg() const { return UPB_UPCAST(msg_); } - $0Proxy(void* msg, upb_Arena* arena) : internal::$0Access(($1*)msg, arena) {} + $0Proxy(upb_Message* msg, upb_Arena* arena) + : internal::$0Access(($1*)msg, arena) {} friend $0::Proxy(::protos::CreateMessage<$0>(::protos::Arena& arena)); friend $0::Proxy(::protos::internal::CreateMessageProxy<$0>( upb_Message*, upb_Arena*)); @@ -295,9 +296,9 @@ void WriteModelCProxyDeclaration(const protobuf::Descriptor* descriptor, R"cc( private: using AsNonConst = $0Proxy; - const void* msg() const { return msg_; } + const upb_Message* msg() const { return UPB_UPCAST(msg_); } - $0CProxy(const void* msg, upb_Arena* arena) + $0CProxy(const upb_Message* msg, upb_Arena* arena) : internal::$0Access(($1*)msg, arena){}; friend struct ::protos::internal::PrivateAccess; friend class RepeatedFieldProxy; @@ -340,7 +341,7 @@ void WriteMessageImplementation( } $0::$0(const $0& from) : $0Access() { arena_ = owned_arena_.ptr(); - msg_ = ($1*)::protos::internal::DeepClone(from.msg_, &$2, arena_); + msg_ = ($1*)::protos::internal::DeepClone(UPB_UPCAST(from.msg_), &$2, arena_); } $0::$0(const CProxy& from) : $0Access() { arena_ = owned_arena_.ptr(); @@ -354,7 +355,7 @@ void WriteMessageImplementation( } $0& $0::operator=(const $3& from) { arena_ = owned_arena_.ptr(); - msg_ = ($1*)::protos::internal::DeepClone(from.msg_, &$2, arena_); + msg_ = ($1*)::protos::internal::DeepClone(UPB_UPCAST(from.msg_), &$2, arena_); return *this; } $0& $0::operator=(const CProxy& from) { diff --git a/python/BUILD.bazel b/python/BUILD.bazel index f604badcf6080..7f2b24711524c 100644 --- a/python/BUILD.bazel +++ b/python/BUILD.bazel @@ -190,6 +190,7 @@ py_extension( ], target_compatible_with = select(_message_target_compatible_with), deps = [ + "//upb:base", "//upb:descriptor_upb_proto_reflection", "//upb:eps_copy_input_stream", "//upb:hash", diff --git a/python/descriptor.c b/python/descriptor.c index ea4c028152948..c5af6dd90e1e4 100644 --- a/python/descriptor.c +++ b/python/descriptor.c @@ -12,6 +12,7 @@ #include "python/descriptor_pool.h" #include "python/message.h" #include "python/protobuf.h" +#include "upb/base/upcast.h" #include "upb/reflection/def.h" #include "upb/util/def_to_proto.h" @@ -391,7 +392,7 @@ static PyObject* PyUpb_Descriptor_GetOneofs(PyObject* _self, void* closure) { static PyObject* PyUpb_Descriptor_GetOptions(PyObject* _self, PyObject* args) { PyUpb_DescriptorBase* self = (void*)_self; return PyUpb_DescriptorBase_GetOptions( - &self->options, upb_MessageDef_Options(self->def), + &self->options, UPB_UPCAST(upb_MessageDef_Options(self->def)), &google__protobuf__MessageOptions_msg_init, PYUPB_DESCRIPTOR_PROTO_PACKAGE ".MessageOptions"); } @@ -399,7 +400,7 @@ static PyObject* PyUpb_Descriptor_GetOptions(PyObject* _self, PyObject* args) { static PyObject* PyUpb_Descriptor_GetFeatures(PyObject* _self, PyObject* args) { PyUpb_DescriptorBase* self = (void*)_self; return PyUpb_DescriptorBase_GetFeatures( - &self->features, upb_MessageDef_ResolvedFeatures(self->def)); + &self->features, UPB_UPCAST(upb_MessageDef_ResolvedFeatures(self->def))); } static PyObject* PyUpb_Descriptor_CopyToProto(PyObject* _self, @@ -700,10 +701,10 @@ static PyType_Slot PyUpb_Descriptor_Slots[] = { {0, NULL}}; static PyType_Spec PyUpb_Descriptor_Spec = { - PYUPB_MODULE_NAME ".Descriptor", // tp_name - sizeof(PyUpb_DescriptorBase), // tp_basicsize - 0, // tp_itemsize - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, // tp_flags + PYUPB_MODULE_NAME ".Descriptor", // tp_name + sizeof(PyUpb_DescriptorBase), // tp_basicsize + 0, // tp_itemsize + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, // tp_flags PyUpb_Descriptor_Slots, }; @@ -809,7 +810,7 @@ static PyObject* PyUpb_EnumDescriptor_GetOptions(PyObject* _self, PyObject* args) { PyUpb_DescriptorBase* self = (void*)_self; return PyUpb_DescriptorBase_GetOptions( - &self->options, upb_EnumDef_Options(self->def), + &self->options, UPB_UPCAST(upb_EnumDef_Options(self->def)), &google__protobuf__EnumOptions_msg_init, PYUPB_DESCRIPTOR_PROTO_PACKAGE ".EnumOptions"); } @@ -818,7 +819,7 @@ static PyObject* PyUpb_EnumDescriptor_GetFeatures(PyObject* _self, PyObject* args) { PyUpb_DescriptorBase* self = (void*)_self; return PyUpb_DescriptorBase_GetFeatures( - &self->features, upb_EnumDef_ResolvedFeatures(self->def)); + &self->features, UPB_UPCAST(upb_EnumDef_ResolvedFeatures(self->def))); } static PyObject* PyUpb_EnumDescriptor_CopyToProto(PyObject* _self, @@ -908,7 +909,7 @@ static PyObject* PyUpb_EnumValueDescriptor_GetOptions(PyObject* _self, PyObject* args) { PyUpb_DescriptorBase* self = (void*)_self; return PyUpb_DescriptorBase_GetOptions( - &self->options, upb_EnumValueDef_Options(self->def), + &self->options, UPB_UPCAST(upb_EnumValueDef_Options(self->def)), &google__protobuf__EnumValueOptions_msg_init, PYUPB_DESCRIPTOR_PROTO_PACKAGE ".EnumValueOptions"); } @@ -917,7 +918,8 @@ static PyObject* PyUpb_EnumValueDescriptor_GetFeatures(PyObject* _self, PyObject* args) { PyUpb_DescriptorBase* self = (void*)_self; return PyUpb_DescriptorBase_GetFeatures( - &self->features, upb_EnumValueDef_ResolvedFeatures(self->def)); + &self->features, + UPB_UPCAST(upb_EnumValueDef_ResolvedFeatures(self->def))); } static PyGetSetDef PyUpb_EnumValueDescriptor_Getters[] = { @@ -1121,7 +1123,7 @@ static PyObject* PyUpb_FieldDescriptor_GetOptions(PyObject* _self, PyObject* args) { PyUpb_DescriptorBase* self = (void*)_self; return PyUpb_DescriptorBase_GetOptions( - &self->options, upb_FieldDef_Options(self->def), + &self->options, UPB_UPCAST(upb_FieldDef_Options(self->def)), &google__protobuf__FieldOptions_msg_init, PYUPB_DESCRIPTOR_PROTO_PACKAGE ".FieldOptions"); } @@ -1130,7 +1132,7 @@ static PyObject* PyUpb_FieldDescriptor_GetFeatures(PyObject* _self, PyObject* args) { PyUpb_DescriptorBase* self = (void*)_self; return PyUpb_DescriptorBase_GetFeatures( - &self->features, upb_FieldDef_ResolvedFeatures(self->def)); + &self->features, UPB_UPCAST(upb_FieldDef_ResolvedFeatures(self->def))); } static PyGetSetDef PyUpb_FieldDescriptor_Getters[] = { @@ -1381,7 +1383,7 @@ static PyObject* PyUpb_FileDescriptor_GetOptions(PyObject* _self, PyObject* args) { PyUpb_DescriptorBase* self = (void*)_self; return PyUpb_DescriptorBase_GetOptions( - &self->options, upb_FileDef_Options(self->def), + &self->options, UPB_UPCAST(upb_FileDef_Options(self->def)), &google__protobuf__FileOptions_msg_init, PYUPB_DESCRIPTOR_PROTO_PACKAGE ".FileOptions"); } @@ -1390,7 +1392,7 @@ static PyObject* PyUpb_FileDescriptor_GetFeatures(PyObject* _self, PyObject* args) { PyUpb_DescriptorBase* self = (void*)_self; return PyUpb_DescriptorBase_GetFeatures( - &self->features, upb_FileDef_ResolvedFeatures(self->def)); + &self->features, UPB_UPCAST(upb_FileDef_ResolvedFeatures(self->def))); } static PyObject* PyUpb_FileDescriptor_CopyToProto(PyObject* _self, @@ -1515,7 +1517,7 @@ static PyObject* PyUpb_MethodDescriptor_GetOptions(PyObject* _self, PyObject* args) { PyUpb_DescriptorBase* self = (void*)_self; return PyUpb_DescriptorBase_GetOptions( - &self->options, upb_MethodDef_Options(self->def), + &self->options, UPB_UPCAST(upb_MethodDef_Options(self->def)), &google__protobuf__MethodOptions_msg_init, PYUPB_DESCRIPTOR_PROTO_PACKAGE ".MethodOptions"); } @@ -1524,7 +1526,7 @@ static PyObject* PyUpb_MethodDescriptor_GetFeatures(PyObject* _self, PyObject* args) { PyUpb_DescriptorBase* self = (void*)_self; return PyUpb_DescriptorBase_GetFeatures( - &self->features, upb_MethodDef_ResolvedFeatures(self->def)); + &self->features, UPB_UPCAST(upb_MethodDef_ResolvedFeatures(self->def))); } static PyObject* PyUpb_MethodDescriptor_CopyToProto(PyObject* _self, @@ -1632,7 +1634,7 @@ static PyObject* PyUpb_OneofDescriptor_GetOptions(PyObject* _self, PyObject* args) { PyUpb_DescriptorBase* self = (void*)_self; return PyUpb_DescriptorBase_GetOptions( - &self->options, upb_OneofDef_Options(self->def), + &self->options, UPB_UPCAST(upb_OneofDef_Options(self->def)), &google__protobuf__OneofOptions_msg_init, PYUPB_DESCRIPTOR_PROTO_PACKAGE ".OneofOptions"); } @@ -1641,7 +1643,7 @@ static PyObject* PyUpb_OneofDescriptor_GetFeatures(PyObject* _self, PyObject* args) { PyUpb_DescriptorBase* self = (void*)_self; return PyUpb_DescriptorBase_GetFeatures( - &self->features, upb_OneofDef_ResolvedFeatures(self->def)); + &self->features, UPB_UPCAST(upb_OneofDef_ResolvedFeatures(self->def))); } static PyGetSetDef PyUpb_OneofDescriptor_Getters[] = { @@ -1742,7 +1744,7 @@ static PyObject* PyUpb_ServiceDescriptor_GetOptions(PyObject* _self, PyObject* args) { PyUpb_DescriptorBase* self = (void*)_self; return PyUpb_DescriptorBase_GetOptions( - &self->options, upb_ServiceDef_Options(self->def), + &self->options, UPB_UPCAST(upb_ServiceDef_Options(self->def)), &google__protobuf__ServiceOptions_msg_init, PYUPB_DESCRIPTOR_PROTO_PACKAGE ".ServiceOptions"); } @@ -1751,7 +1753,7 @@ static PyObject* PyUpb_ServiceDescriptor_GetFeatures(PyObject* _self, PyObject* args) { PyUpb_DescriptorBase* self = (void*)_self; return PyUpb_DescriptorBase_GetFeatures( - &self->features, upb_ServiceDef_ResolvedFeatures(self->def)); + &self->features, UPB_UPCAST(upb_ServiceDef_ResolvedFeatures(self->def))); } static PyObject* PyUpb_ServiceDescriptor_CopyToProto(PyObject* _self, diff --git a/python/descriptor_pool.c b/python/descriptor_pool.c index 09efbda5fce8f..089d31b1a6d4c 100644 --- a/python/descriptor_pool.c +++ b/python/descriptor_pool.c @@ -12,6 +12,7 @@ #include "python/descriptor.h" #include "python/message.h" #include "python/protobuf.h" +#include "upb/base/upcast.h" #include "upb/reflection/def.h" #include "upb/util/def_to_proto.h" @@ -147,8 +148,7 @@ bool PyUpb_DescriptorPool_CheckNoDatabase(PyObject* _self) { return true; } static bool PyUpb_DescriptorPool_LoadDependentFiles( PyUpb_DescriptorPool* self, google_protobuf_FileDescriptorProto* proto) { size_t n; - const upb_StringView* deps = - google_protobuf_FileDescriptorProto_dependency(proto, &n); + const upb_StringView* deps = google_protobuf_FileDescriptorProto_dependency(proto, &n); for (size_t i = 0; i < n; i++) { const upb_FileDef* dep = upb_DefPool_FindFileByNameWithSize( self->symtab, deps[i].data, deps[i].size); @@ -191,14 +191,13 @@ static PyObject* PyUpb_DescriptorPool_DoAddSerializedFile( if (file) { // If the existing file is equal to the new file, then silently ignore the // duplicate add. - google_protobuf_FileDescriptorProto* existing = - upb_FileDef_ToProto(file, arena); + google_protobuf_FileDescriptorProto* existing = upb_FileDef_ToProto(file, arena); if (!existing) { PyErr_SetNone(PyExc_MemoryError); goto done; } const upb_MessageDef* m = PyUpb_DescriptorPool_GetFileProtoDef(); - if (upb_Message_IsEqual(proto, existing, m)) { + if (upb_Message_IsEqual(UPB_UPCAST(proto), UPB_UPCAST(existing), m)) { result = PyUpb_FileDescriptor_Get(file); goto done; } diff --git a/python/map.c b/python/map.c index 4330aae1f4e0d..bbbd63611852c 100644 --- a/python/map.c +++ b/python/map.c @@ -184,7 +184,7 @@ static PyObject* PyUpb_MapContainer_Subscript(PyObject* _self, PyObject* key) { map = PyUpb_MapContainer_EnsureReified(_self); upb_Arena* arena = PyUpb_Arena_Get(self->arena); if (upb_FieldDef_IsSubMessage(val_f)) { - const upb_Message* m = upb_FieldDef_MessageSubDef(val_f); + const upb_MessageDef* m = upb_FieldDef_MessageSubDef(val_f); const upb_MiniTable* layout = upb_MessageDef_MiniTable(m); u_val.msg_val = upb_Message_New(layout, arena); } else { diff --git a/upb/base/BUILD b/upb/base/BUILD index 54ef6d1867997..1a025c295da7b 100644 --- a/upb/base/BUILD +++ b/upb/base/BUILD @@ -17,6 +17,7 @@ cc_library( "status.h", "status.hpp", "string_view.h", + "upcast.h", ], copts = UPB_DEFAULT_COPTS, visibility = ["//visibility:public"], diff --git a/upb/base/upcast.h b/upb/base/upcast.h new file mode 100644 index 0000000000000..92d699dd21edc --- /dev/null +++ b/upb/base/upcast.h @@ -0,0 +1,29 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2023 Google LLC. All rights reserved. +// +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file or at +// https://developers.google.com/open-source/licenses/bsd + +#ifndef UPB_BASE_UPCAST_H_ +#define UPB_BASE_UPCAST_H_ + +// Must be last. +#include "upb/port/def.inc" + +// This macro provides a way to upcast message pointers in a way that is +// somewhat more bulletproof than blindly casting a pointer. Example: +// +// typedef struct { +// upb_Message UPB_PRIVATE(base); +// } pkg_FooMessage; +// +// void f(pkg_FooMessage* msg) { +// upb_Decode(UPB_UPCAST(msg), ...); +// } + +#define UPB_UPCAST(x) (&(x)->base##_dont_copy_me__upb_internal_use_only) + +#include "upb/port/undef.inc" + +#endif /* UPB_BASE_UPCAST_H_ */ diff --git a/upb/conformance/BUILD b/upb/conformance/BUILD index 94d18bac3a070..8cdd3f7a7b47f 100644 --- a/upb/conformance/BUILD +++ b/upb/conformance/BUILD @@ -75,6 +75,7 @@ cc_binary( ":test_messages_proto3_upbdefs", "//src/google/protobuf/editions:test_messages_proto2_editions_upbdefs", "//src/google/protobuf/editions:test_messages_proto3_editions_upbdefs", + "//upb:base", "//upb:json", "//upb:port", "//upb:reflection", @@ -128,6 +129,7 @@ cc_binary( ":test_messages_proto3_upbdefs", "//src/google/protobuf/editions:test_messages_proto2_editions_upbdefs", "//src/google/protobuf/editions:test_messages_proto3_editions_upbdefs", + "//upb:base", "//upb:json", "//upb:port", "//upb:reflection", diff --git a/upb/conformance/conformance_upb.c b/upb/conformance/conformance_upb.c index 4efe32c17dce0..78cce522f28a3 100644 --- a/upb/conformance/conformance_upb.c +++ b/upb/conformance/conformance_upb.c @@ -20,6 +20,7 @@ #include "google/protobuf/editions/golden/test_messages_proto3_editions.upbdefs.h" #include "google/protobuf/test_messages_proto2.upbdefs.h" #include "google/protobuf/test_messages_proto3.upbdefs.h" +#include "upb/base/upcast.h" #include "upb/json/decode.h" #include "upb/json/encode.h" #include "upb/reflection/message.h" @@ -291,9 +292,9 @@ bool DoTestIo(upb_DefPool* symtab) { test_count++; if (verbose) { - debug_print("Request", c.request, + debug_print("Request", UPB_UPCAST(c.request), conformance_ConformanceRequest_getmsgdef(symtab), &c); - debug_print("Response", c.response, + debug_print("Response", UPB_UPCAST(c.response), conformance_ConformanceResponse_getmsgdef(symtab), &c); fprintf(stderr, "\n"); } diff --git a/upb/generated_code_support.h b/upb/generated_code_support.h index cbc72945b9ca3..025ff0eedaf6e 100644 --- a/upb/generated_code_support.h +++ b/upb/generated_code_support.h @@ -9,6 +9,7 @@ #define UPB_GENERATED_CODE_SUPPORT_H_ // IWYU pragma: begin_exports +#include "upb/base/upcast.h" #include "upb/message/accessors.h" #include "upb/message/array.h" #include "upb/message/internal/accessors.h" diff --git a/upb/json/decode_test.cc b/upb/json/decode_test.cc index e3005c32a41d0..e8a6e3d4114e3 100644 --- a/upb/json/decode_test.cc +++ b/upb/json/decode_test.cc @@ -13,6 +13,7 @@ #include "google/protobuf/struct.upb.h" #include #include "upb/base/status.hpp" +#include "upb/base/upcast.h" #include "upb/json/test.upb.h" #include "upb/json/test.upbdefs.h" #include "upb/mem/arena.h" @@ -27,8 +28,8 @@ static upb_test_Box* JsonDecode(const char* json, upb_Arena* a) { upb_test_Box* box = upb_test_Box_new(a); int options = 0; - bool ok = upb_JsonDecode(json, strlen(json), box, m.ptr(), defpool.ptr(), - options, a, status.ptr()); + bool ok = upb_JsonDecode(json, strlen(json), UPB_UPCAST(box), m.ptr(), + defpool.ptr(), options, a, status.ptr()); return ok ? box : nullptr; } diff --git a/upb/json/encode_test.cc b/upb/json/encode_test.cc index a5fc792e47cd0..42ce6dde4d4bc 100644 --- a/upb/json/encode_test.cc +++ b/upb/json/encode_test.cc @@ -13,6 +13,7 @@ #include "google/protobuf/struct.upb.h" #include #include "upb/base/status.hpp" +#include "upb/base/upcast.h" #include "upb/json/test.upb.h" #include "upb/json/test.upbdefs.h" #include "upb/mem/arena.h" @@ -26,12 +27,12 @@ static std::string JsonEncode(const upb_test_Box* msg, int options) { upb::MessageDefPtr m(upb_test_Box_getmsgdef(defpool.ptr())); EXPECT_TRUE(m.ptr() != nullptr); - size_t json_size = upb_JsonEncode(msg, m.ptr(), defpool.ptr(), options, - nullptr, 0, status.ptr()); + size_t json_size = upb_JsonEncode(UPB_UPCAST(msg), m.ptr(), defpool.ptr(), + options, nullptr, 0, status.ptr()); char* json_buf = (char*)upb_Arena_Malloc(a.ptr(), json_size + 1); - size_t size = upb_JsonEncode(msg, m.ptr(), defpool.ptr(), options, json_buf, - json_size + 1, status.ptr()); + size_t size = upb_JsonEncode(UPB_UPCAST(msg), m.ptr(), defpool.ptr(), options, + json_buf, json_size + 1, status.ptr()); EXPECT_EQ(size, json_size); return std::string(json_buf, json_size); } diff --git a/upb/json/fuzz_test.cc b/upb/json/fuzz_test.cc index 381c8ebad39bb..d430d15f40b4c 100644 --- a/upb/json/fuzz_test.cc +++ b/upb/json/fuzz_test.cc @@ -12,6 +12,7 @@ #include #include "testing/fuzzing/fuzztest.h" #include "upb/base/status.hpp" +#include "upb/base/upcast.h" #include "upb/json/decode.h" #include "upb/json/encode.h" #include "upb/json/test.upb.h" @@ -37,17 +38,17 @@ void DecodeEncodeArbitraryJson(std::string_view json) { upb_test_Box* box = upb_test_Box_new(arena.ptr()); int options = 0; - bool ok = upb_JsonDecode(json_heap, json.size(), box, m.ptr(), defpool.ptr(), - options, arena.ptr(), status.ptr()); + bool ok = upb_JsonDecode(json_heap, json.size(), UPB_UPCAST(box), m.ptr(), + defpool.ptr(), options, arena.ptr(), status.ptr()); delete[] json_heap; if (!ok) return; - size_t size = upb_JsonEncode(box, m.ptr(), defpool.ptr(), options, nullptr, 0, - status.ptr()); + size_t size = upb_JsonEncode(UPB_UPCAST(box), m.ptr(), defpool.ptr(), options, + nullptr, 0, status.ptr()); char* json_buf = (char*)upb_Arena_Malloc(arena.ptr(), size + 1); - size_t written = upb_JsonEncode(box, m.ptr(), defpool.ptr(), options, - json_buf, size + 1, status.ptr()); + size_t written = upb_JsonEncode(UPB_UPCAST(box), m.ptr(), defpool.ptr(), + options, json_buf, size + 1, status.ptr()); EXPECT_EQ(written, size); } FUZZ_TEST(FuzzTest, DecodeEncodeArbitraryJson); diff --git a/upb/message/accessors_test.cc b/upb/message/accessors_test.cc index 15de392b6de69..9d8aa0e7ccf17 100644 --- a/upb/message/accessors_test.cc +++ b/upb/message/accessors_test.cc @@ -27,6 +27,7 @@ #include "upb/base/descriptor_constants.h" #include "upb/base/status.h" #include "upb/base/string_view.h" +#include "upb/base/upcast.h" #include "upb/mem/arena.h" #include "upb/message/array.h" #include "upb/message/message.h" @@ -81,11 +82,11 @@ TEST(GeneratedCode, HazzersProto2) { // Scalar/Boolean. const upb_MiniTableField* optional_bool_field = find_proto2_field(kFieldOptionalBool); - EXPECT_EQ(false, upb_Message_HasField(msg, optional_bool_field)); + EXPECT_EQ(false, upb_Message_HasField(UPB_UPCAST(msg), optional_bool_field)); protobuf_test_messages_proto2_TestAllTypesProto2_set_optional_bool(msg, true); - EXPECT_EQ(true, upb_Message_HasField(msg, optional_bool_field)); - upb_Message_ClearField(msg, optional_bool_field); - EXPECT_EQ(false, upb_Message_HasField(msg, optional_bool_field)); + EXPECT_EQ(true, upb_Message_HasField(UPB_UPCAST(msg), optional_bool_field)); + upb_Message_ClearField(UPB_UPCAST(msg), optional_bool_field); + EXPECT_EQ(false, upb_Message_HasField(UPB_UPCAST(msg), optional_bool_field)); EXPECT_EQ( false, protobuf_test_messages_proto2_TestAllTypesProto2_optional_bool(msg)); @@ -93,16 +94,18 @@ TEST(GeneratedCode, HazzersProto2) { // String. const upb_MiniTableField* optional_string_field = find_proto2_field(kFieldOptionalString); - EXPECT_EQ(false, upb_Message_HasField(msg, optional_string_field)); + EXPECT_EQ(false, + upb_Message_HasField(UPB_UPCAST(msg), optional_string_field)); protobuf_test_messages_proto2_TestAllTypesProto2_set_optional_string( msg, upb_StringView_FromString(kTestStr1)); - EXPECT_EQ(true, upb_Message_HasField(msg, optional_string_field)); + EXPECT_EQ(true, upb_Message_HasField(UPB_UPCAST(msg), optional_string_field)); EXPECT_EQ( strlen(kTestStr1), protobuf_test_messages_proto2_TestAllTypesProto2_optional_string(msg) .size); - upb_Message_ClearField(msg, optional_string_field); - EXPECT_EQ(false, upb_Message_HasField(msg, optional_string_field)); + upb_Message_ClearField(UPB_UPCAST(msg), optional_string_field); + EXPECT_EQ(false, + upb_Message_HasField(UPB_UPCAST(msg), optional_string_field)); EXPECT_EQ( 0, protobuf_test_messages_proto2_TestAllTypesProto2_optional_string(msg) .size); @@ -110,12 +113,15 @@ TEST(GeneratedCode, HazzersProto2) { // Message. const upb_MiniTableField* optional_message_field = find_proto2_field(kFieldOptionalNestedMessage); - EXPECT_EQ(false, upb_Message_HasField(msg, optional_message_field)); + EXPECT_EQ(false, + upb_Message_HasField(UPB_UPCAST(msg), optional_message_field)); protobuf_test_messages_proto2_TestAllTypesProto2_mutable_optional_nested_message( msg, arena); - EXPECT_EQ(true, upb_Message_HasField(msg, optional_message_field)); - upb_Message_ClearField(msg, optional_message_field); - EXPECT_EQ(false, upb_Message_HasField(msg, optional_message_field)); + EXPECT_EQ(true, + upb_Message_HasField(UPB_UPCAST(msg), optional_message_field)); + upb_Message_ClearField(UPB_UPCAST(msg), optional_message_field); + EXPECT_EQ(false, + upb_Message_HasField(UPB_UPCAST(msg), optional_message_field)); EXPECT_EQ( true, protobuf_test_messages_proto2_TestAllTypesProto2_optional_nested_message( @@ -127,21 +133,31 @@ TEST(GeneratedCode, HazzersProto2) { const upb_MiniTableField* optional_oneof_string_field = find_proto2_field(kFieldOptionalOneOfString); - EXPECT_EQ(false, upb_Message_HasField(msg, optional_oneof_uint32_field)); - EXPECT_EQ(false, upb_Message_HasField(msg, optional_oneof_string_field)); + EXPECT_EQ(false, + upb_Message_HasField(UPB_UPCAST(msg), optional_oneof_uint32_field)); + EXPECT_EQ(false, + upb_Message_HasField(UPB_UPCAST(msg), optional_oneof_string_field)); protobuf_test_messages_proto2_TestAllTypesProto2_set_oneof_uint32(msg, 123); - EXPECT_EQ(true, upb_Message_HasField(msg, optional_oneof_uint32_field)); - EXPECT_EQ(false, upb_Message_HasField(msg, optional_oneof_string_field)); + EXPECT_EQ(true, + upb_Message_HasField(UPB_UPCAST(msg), optional_oneof_uint32_field)); + EXPECT_EQ(false, + upb_Message_HasField(UPB_UPCAST(msg), optional_oneof_string_field)); protobuf_test_messages_proto2_TestAllTypesProto2_set_oneof_string( msg, upb_StringView_FromString(kTestStr1)); - EXPECT_EQ(false, upb_Message_HasField(msg, optional_oneof_uint32_field)); - EXPECT_EQ(true, upb_Message_HasField(msg, optional_oneof_string_field)); - upb_Message_ClearField(msg, optional_oneof_uint32_field); - EXPECT_EQ(false, upb_Message_HasField(msg, optional_oneof_uint32_field)); - EXPECT_EQ(true, upb_Message_HasField(msg, optional_oneof_string_field)); - upb_Message_ClearField(msg, optional_oneof_string_field); - EXPECT_EQ(false, upb_Message_HasField(msg, optional_oneof_uint32_field)); - EXPECT_EQ(false, upb_Message_HasField(msg, optional_oneof_string_field)); + EXPECT_EQ(false, + upb_Message_HasField(UPB_UPCAST(msg), optional_oneof_uint32_field)); + EXPECT_EQ(true, + upb_Message_HasField(UPB_UPCAST(msg), optional_oneof_string_field)); + upb_Message_ClearField(UPB_UPCAST(msg), optional_oneof_uint32_field); + EXPECT_EQ(false, + upb_Message_HasField(UPB_UPCAST(msg), optional_oneof_uint32_field)); + EXPECT_EQ(true, + upb_Message_HasField(UPB_UPCAST(msg), optional_oneof_string_field)); + upb_Message_ClearField(UPB_UPCAST(msg), optional_oneof_string_field); + EXPECT_EQ(false, + upb_Message_HasField(UPB_UPCAST(msg), optional_oneof_uint32_field)); + EXPECT_EQ(false, + upb_Message_HasField(UPB_UPCAST(msg), optional_oneof_string_field)); upb_Arena_Free(arena); } @@ -157,10 +173,12 @@ TEST(GeneratedCode, ScalarsProto2) { EXPECT_EQ( 0, protobuf_test_messages_proto2_TestAllTypesProto2_optional_int32(msg)); - EXPECT_EQ(0, upb_Message_GetInt32(msg, optional_int32_field, 0)); - upb_Message_SetInt32(msg, optional_int32_field, kTestInt32, nullptr); - EXPECT_EQ(true, upb_Message_HasField(msg, optional_int32_field)); - EXPECT_EQ(kTestInt32, upb_Message_GetInt32(msg, optional_int32_field, 0)); + EXPECT_EQ(0, upb_Message_GetInt32(UPB_UPCAST(msg), optional_int32_field, 0)); + upb_Message_SetInt32(UPB_UPCAST(msg), optional_int32_field, kTestInt32, + nullptr); + EXPECT_EQ(true, upb_Message_HasField(UPB_UPCAST(msg), optional_int32_field)); + EXPECT_EQ(kTestInt32, + upb_Message_GetInt32(UPB_UPCAST(msg), optional_int32_field, 0)); EXPECT_EQ( kTestInt32, protobuf_test_messages_proto2_TestAllTypesProto2_optional_int32(msg)); @@ -170,9 +188,12 @@ TEST(GeneratedCode, ScalarsProto2) { EXPECT_EQ( 0, protobuf_test_messages_proto2_TestAllTypesProto2_optional_uint32(msg)); - EXPECT_EQ(0, upb_Message_GetUInt32(msg, optional_uint32_field, 0)); - upb_Message_SetUInt32(msg, optional_uint32_field, kTestUInt32, nullptr); - EXPECT_EQ(kTestUInt32, upb_Message_GetUInt32(msg, optional_uint32_field, 0)); + EXPECT_EQ(0, + upb_Message_GetUInt32(UPB_UPCAST(msg), optional_uint32_field, 0)); + upb_Message_SetUInt32(UPB_UPCAST(msg), optional_uint32_field, kTestUInt32, + nullptr); + EXPECT_EQ(kTestUInt32, + upb_Message_GetUInt32(UPB_UPCAST(msg), optional_uint32_field, 0)); EXPECT_EQ( kTestUInt32, protobuf_test_messages_proto2_TestAllTypesProto2_optional_uint32(msg)); @@ -192,18 +213,20 @@ TEST(GeneratedCode, ScalarProto3) { EXPECT_EQ( 0, protobuf_test_messages_proto3_TestAllTypesProto3_optional_int64(msg)); - upb_Message_SetInt64(msg, optional_int64_field, -1, nullptr); + upb_Message_SetInt64(UPB_UPCAST(msg), optional_int64_field, -1, nullptr); EXPECT_EQ( -1, protobuf_test_messages_proto3_TestAllTypesProto3_optional_int64(msg)); - EXPECT_EQ(-1, upb_Message_GetInt64(msg, optional_int64_field, 0)); + EXPECT_EQ(-1, upb_Message_GetInt64(UPB_UPCAST(msg), optional_int64_field, 0)); EXPECT_EQ( 0, protobuf_test_messages_proto3_TestAllTypesProto3_optional_uint64(msg)); - upb_Message_SetUInt64(msg, optional_uint64_field, kTestUInt64, nullptr); + upb_Message_SetUInt64(UPB_UPCAST(msg), optional_uint64_field, kTestUInt64, + nullptr); EXPECT_EQ( kTestUInt64, protobuf_test_messages_proto3_TestAllTypesProto3_optional_uint64(msg)); - EXPECT_EQ(kTestUInt64, upb_Message_GetUInt64(msg, optional_uint64_field, 0)); + EXPECT_EQ(kTestUInt64, + upb_Message_GetUInt64(UPB_UPCAST(msg), optional_uint64_field, 0)); upb_Arena_Free(arena); } @@ -217,25 +240,27 @@ TEST(GeneratedCode, Strings) { find_proto2_field(kFieldOptionalString); // Test default. - EXPECT_EQ(false, upb_Message_HasField(msg, optional_string_field)); + EXPECT_EQ(false, + upb_Message_HasField(UPB_UPCAST(msg), optional_string_field)); // Test read after write using C. protobuf_test_messages_proto2_TestAllTypesProto2_set_optional_string( msg, upb_StringView_FromString(kTestStr1)); - EXPECT_EQ(true, upb_Message_HasField(msg, optional_string_field)); - upb_StringView value = upb_Message_GetString(msg, optional_string_field, - upb_StringView{nullptr, 0}); + EXPECT_EQ(true, upb_Message_HasField(UPB_UPCAST(msg), optional_string_field)); + upb_StringView value = upb_Message_GetString( + UPB_UPCAST(msg), optional_string_field, upb_StringView{nullptr, 0}); std::string read_value = std::string(value.data, value.size); EXPECT_EQ(kTestStr1, read_value); // Clear. - upb_Message_ClearField(msg, optional_string_field); - EXPECT_EQ(false, upb_Message_HasField(msg, optional_string_field)); + upb_Message_ClearField(UPB_UPCAST(msg), optional_string_field); + EXPECT_EQ(false, + upb_Message_HasField(UPB_UPCAST(msg), optional_string_field)); EXPECT_EQ( false, protobuf_test_messages_proto2_TestAllTypesProto2_has_optional_string( msg)); - upb_Message_SetString(msg, optional_string_field, + upb_Message_SetString(UPB_UPCAST(msg), optional_string_field, upb_StringView_FromString(kTestStr2), nullptr); - EXPECT_EQ(true, upb_Message_HasField(msg, optional_string_field)); + EXPECT_EQ(true, upb_Message_HasField(UPB_UPCAST(msg), optional_string_field)); EXPECT_EQ( true, protobuf_test_messages_proto2_TestAllTypesProto2_has_optional_string( @@ -256,23 +281,25 @@ TEST(GeneratedCode, SubMessage) { find_proto2_field(kFieldOptionalNestedMessage); const upb_Message* test_message = - upb_Message_GetMessage(msg, optional_message_field, nullptr); + upb_Message_GetMessage(UPB_UPCAST(msg), optional_message_field, nullptr); EXPECT_EQ(nullptr, test_message); - EXPECT_EQ(false, upb_Message_HasField(msg, optional_message_field)); + EXPECT_EQ(false, + upb_Message_HasField(UPB_UPCAST(msg), optional_message_field)); // Get mutable using C API. protobuf_test_messages_proto2_TestAllTypesProto2_NestedMessage* nested_message = protobuf_test_messages_proto2_TestAllTypesProto2_mutable_optional_nested_message( msg, arena); EXPECT_EQ(true, nested_message != nullptr); - EXPECT_EQ(true, upb_Message_HasField(msg, optional_message_field)); + EXPECT_EQ(true, + upb_Message_HasField(UPB_UPCAST(msg), optional_message_field)); protobuf_test_messages_proto2_TestAllTypesProto2_NestedMessage_set_a( nested_message, 5); // Read back using mini table API. const upb_Message* sub_message = - upb_Message_GetMessage(msg, optional_message_field, nullptr); + upb_Message_GetMessage(UPB_UPCAST(msg), optional_message_field, nullptr); EXPECT_EQ(true, sub_message != nullptr); const upb_MiniTableField* nested_message_a_field = @@ -281,29 +308,34 @@ TEST(GeneratedCode, SubMessage) { kFieldOptionalNestedMessageA); EXPECT_EQ(5, upb_Message_GetInt32(sub_message, nested_message_a_field, 0)); - upb_Message_ClearField(msg, optional_message_field); + upb_Message_ClearField(UPB_UPCAST(msg), optional_message_field); EXPECT_EQ( nullptr, protobuf_test_messages_proto2_TestAllTypesProto2_optional_nested_message( msg)); - EXPECT_EQ(false, upb_Message_HasField(msg, optional_message_field)); + EXPECT_EQ(false, + upb_Message_HasField(UPB_UPCAST(msg), optional_message_field)); - upb_Message* new_nested_message = - protobuf_test_messages_proto2_TestAllTypesProto2_NestedMessage_new(arena); + upb_Message* new_nested_message = UPB_UPCAST( + protobuf_test_messages_proto2_TestAllTypesProto2_NestedMessage_new( + arena)); upb_Message_SetInt32(new_nested_message, nested_message_a_field, 123, nullptr); upb_Message_SetMessage( - msg, &protobuf_0test_0messages__proto2__TestAllTypesProto2_msg_init, + UPB_UPCAST(msg), + &protobuf_0test_0messages__proto2__TestAllTypesProto2_msg_init, optional_message_field, new_nested_message); upb_Message* mutable_message = upb_Message_GetOrCreateMutableMessage( - msg, &protobuf_0test_0messages__proto2__TestAllTypesProto2_msg_init, + UPB_UPCAST(msg), + &protobuf_0test_0messages__proto2__TestAllTypesProto2_msg_init, optional_message_field, arena); EXPECT_EQ( true, protobuf_test_messages_proto2_TestAllTypesProto2_optional_nested_message( msg) != nullptr); - EXPECT_EQ(true, upb_Message_HasField(msg, optional_message_field)); + EXPECT_EQ(true, + upb_Message_HasField(UPB_UPCAST(msg), optional_message_field)); EXPECT_EQ(123, upb_Message_GetInt32(mutable_message, nested_message_a_field, 0)); @@ -325,7 +357,8 @@ TEST(GeneratedCode, RepeatedScalar) { // Test Get/Set Array values, validate with C API. EXPECT_EQ(0, len); EXPECT_EQ(nullptr, arr); - EXPECT_EQ(nullptr, upb_Message_GetArray(msg, repeated_int32_field)); + EXPECT_EQ(nullptr, + upb_Message_GetArray(UPB_UPCAST(msg), repeated_int32_field)); protobuf_test_messages_proto2_TestAllTypesProto2_resize_repeated_int32( msg, 10, arena); int32_t* mutable_values = @@ -333,13 +366,13 @@ TEST(GeneratedCode, RepeatedScalar) { msg, &len); mutable_values[5] = 123; const upb_Array* readonly_arr = - upb_Message_GetArray(msg, repeated_int32_field); + upb_Message_GetArray(UPB_UPCAST(msg), repeated_int32_field); EXPECT_EQ(123, upb_Array_Get(readonly_arr, 5).int32_val); upb_MessageValue new_value; new_value.int32_val = 567; upb_Array* mutable_array = - upb_Message_GetMutableArray(msg, repeated_int32_field); + upb_Message_GetMutableArray(UPB_UPCAST(msg), repeated_int32_field); upb_Array_Set(mutable_array, 5, new_value); EXPECT_EQ(new_value.int32_val, protobuf_test_messages_proto2_TestAllTypesProto2_repeated_int32( @@ -370,10 +403,12 @@ TEST(GeneratedCode, GetMutableMessage) { const upb_MiniTableField* optional_message_field = find_proto2_field(kFieldOptionalNestedMessage); upb_Message* msg1 = upb_Message_GetOrCreateMutableMessage( - msg, &protobuf_0test_0messages__proto2__TestAllTypesProto2_msg_init, + UPB_UPCAST(msg), + &protobuf_0test_0messages__proto2__TestAllTypesProto2_msg_init, optional_message_field, arena); upb_Message* msg2 = upb_Message_GetOrCreateMutableMessage( - msg, &protobuf_0test_0messages__proto2__TestAllTypesProto2_msg_init, + UPB_UPCAST(msg), + &protobuf_0test_0messages__proto2__TestAllTypesProto2_msg_init, optional_message_field, arena); // Verify that newly constructed sub message is stored in msg. EXPECT_EQ(msg1, msg2); diff --git a/upb/message/copy_test.cc b/upb/message/copy_test.cc index 3a40bc3b117ff..727b352e00c38 100644 --- a/upb/message/copy_test.cc +++ b/upb/message/copy_test.cc @@ -23,6 +23,7 @@ #include "google/protobuf/test_messages_proto2.upb.h" #include "google/protobuf/test_messages_proto2.upb_minitable.h" #include "upb/base/string_view.h" +#include "upb/base/upcast.h" #include "upb/mem/arena.h" #include "upb/message/accessors.h" #include "upb/message/internal/message.h" @@ -61,31 +62,34 @@ TEST(GeneratedCode, DeepCloneMessageScalarAndString) { find_proto2_field(kFieldOptionalInt32); const upb_MiniTableField* optional_string_field = find_proto2_field(kFieldOptionalString); - upb_Message_SetInt32(msg, optional_int32_field, kTestInt32, nullptr); + upb_Message_SetInt32(UPB_UPCAST(msg), optional_int32_field, kTestInt32, + nullptr); char* string_in_arena = (char*)upb_Arena_Malloc(source_arena, sizeof(kTestStr1)); memcpy(string_in_arena, kTestStr1, sizeof(kTestStr1)); upb_Message_SetString( - msg, optional_string_field, + UPB_UPCAST(msg), optional_string_field, upb_StringView_FromDataAndSize(string_in_arena, sizeof(kTestStr1) - 1), source_arena); upb_Arena* arena = upb_Arena_New(); protobuf_test_messages_proto2_TestAllTypesProto2* clone = (protobuf_test_messages_proto2_TestAllTypesProto2*)upb_Message_DeepClone( - msg, &protobuf_0test_0messages__proto2__TestAllTypesProto2_msg_init, + UPB_UPCAST(msg), + &protobuf_0test_0messages__proto2__TestAllTypesProto2_msg_init, arena); // After cloning overwrite values and destroy source arena for MSAN. memset(string_in_arena, 0, sizeof(kTestStr1)); upb_Arena_Free(source_arena); - EXPECT_TRUE(upb_Message_HasField(clone, optional_int32_field)); - EXPECT_EQ(upb_Message_GetInt32(clone, optional_int32_field, 0), kTestInt32); - EXPECT_TRUE(upb_Message_HasField(clone, optional_string_field)); - EXPECT_EQ(upb_Message_GetString(clone, optional_string_field, + EXPECT_TRUE(upb_Message_HasField(UPB_UPCAST(clone), optional_int32_field)); + EXPECT_EQ(upb_Message_GetInt32(UPB_UPCAST(clone), optional_int32_field, 0), + kTestInt32); + EXPECT_TRUE(upb_Message_HasField(UPB_UPCAST(clone), optional_string_field)); + EXPECT_EQ(upb_Message_GetString(UPB_UPCAST(clone), optional_string_field, upb_StringView_FromDataAndSize(nullptr, 0)) .size, sizeof(kTestStr1) - 1); EXPECT_TRUE(upb_StringView_IsEqual( - upb_Message_GetString(clone, optional_string_field, + upb_Message_GetString(UPB_UPCAST(clone), optional_string_field, upb_StringView_FromDataAndSize(nullptr, 0)), upb_StringView_FromString(kTestStr1))); upb_Arena_Free(arena); @@ -103,22 +107,25 @@ TEST(GeneratedCode, DeepCloneMessageSubMessage) { protobuf_test_messages_proto2_TestAllTypesProto2_NestedMessage_set_a( nested, kTestNestedInt32); upb_Message_SetMessage( - msg, &protobuf_0test_0messages__proto2__TestAllTypesProto2_msg_init, - nested_message_field, nested); + UPB_UPCAST(msg), + &protobuf_0test_0messages__proto2__TestAllTypesProto2_msg_init, + nested_message_field, UPB_UPCAST(nested)); upb_Arena* arena = upb_Arena_New(); protobuf_test_messages_proto2_TestAllTypesProto2* clone = (protobuf_test_messages_proto2_TestAllTypesProto2*)upb_Message_DeepClone( - msg, &protobuf_0test_0messages__proto2__TestAllTypesProto2_msg_init, + UPB_UPCAST(msg), + &protobuf_0test_0messages__proto2__TestAllTypesProto2_msg_init, arena); // After cloning overwrite values and destroy source arena for MSAN. protobuf_test_messages_proto2_TestAllTypesProto2_NestedMessage_set_a(nested, 0); upb_Arena_Free(source_arena); - EXPECT_TRUE(upb_Message_HasField(clone, nested_message_field)); + EXPECT_TRUE(upb_Message_HasField(UPB_UPCAST(clone), nested_message_field)); protobuf_test_messages_proto2_TestAllTypesProto2_NestedMessage* cloned_nested = (protobuf_test_messages_proto2_TestAllTypesProto2_NestedMessage*) - upb_Message_GetMessage(clone, nested_message_field, nullptr); + upb_Message_GetMessage(UPB_UPCAST(clone), nested_message_field, + nullptr); EXPECT_EQ(protobuf_test_messages_proto2_TestAllTypesProto2_NestedMessage_a( cloned_nested), kTestNestedInt32); @@ -138,7 +145,8 @@ TEST(GeneratedCode, DeepCloneMessageArrayField) { upb_Arena* arena = upb_Arena_New(); protobuf_test_messages_proto2_TestAllTypesProto2* clone = (protobuf_test_messages_proto2_TestAllTypesProto2*)upb_Message_DeepClone( - msg, &protobuf_0test_0messages__proto2__TestAllTypesProto2_msg_init, + UPB_UPCAST(msg), + &protobuf_0test_0messages__proto2__TestAllTypesProto2_msg_init, arena); protobuf_test_messages_proto2_TestAllTypesProto2_clear_repeated_sint32(msg); upb_Arena_Free(source_arena); @@ -177,7 +185,8 @@ TEST(GeneratedCode, DeepCloneMessageMapField) { upb_Arena* arena = upb_Arena_New(); protobuf_test_messages_proto2_TestAllTypesProto2* clone = (protobuf_test_messages_proto2_TestAllTypesProto2*)upb_Message_DeepClone( - msg, &protobuf_0test_0messages__proto2__TestAllTypesProto2_msg_init, + UPB_UPCAST(msg), + &protobuf_0test_0messages__proto2__TestAllTypesProto2_msg_init, arena); protobuf_test_messages_proto2_TestAllTypesProto2_NestedMessage_set_a(nested, 0); @@ -253,7 +262,7 @@ TEST(GeneratedCode, DeepCloneMessageExtensions) { protobuf_test_messages_proto2_TestAllTypesProto2_MessageSetCorrect* clone = (protobuf_test_messages_proto2_TestAllTypesProto2_MessageSetCorrect*) upb_Message_DeepClone( - msg, + UPB_UPCAST(msg), &protobuf_0test_0messages__proto2__TestAllTypesProto2__MessageSetCorrect_msg_init, arena); @@ -298,18 +307,20 @@ TEST(GeneratedCode, DeepCloneMessageWithUnknowns) { char* data; upb_Arena* encode_arena = upb_Arena_New(); upb_EncodeStatus status = upb_Encode( - unknown_source, + UPB_UPCAST(unknown_source), &protobuf_0test_0messages__proto2__UnknownToTestAllTypes_msg_init, kUpb_EncodeOption_CheckRequired, encode_arena, &data, &len); ASSERT_EQ(status, kUpb_EncodeStatus_Ok); std::string unknown_data(data, len); // Add unknown data. - UPB_PRIVATE(_upb_Message_AddUnknown)(msg, data, len, source_arena); + UPB_PRIVATE(_upb_Message_AddUnknown) + (UPB_UPCAST(msg), data, len, source_arena); // Create clone. upb_Arena* clone_arena = upb_Arena_New(); protobuf_test_messages_proto2_TestAllTypesProto2* clone = (protobuf_test_messages_proto2_TestAllTypesProto2*)upb_Message_DeepClone( - msg, &protobuf_0test_0messages__proto2__TestAllTypesProto2_msg_init, + UPB_UPCAST(msg), + &protobuf_0test_0messages__proto2__TestAllTypesProto2_msg_init, clone_arena); upb_Arena_Free(source_arena); upb_Arena_Free(unknown_arena); @@ -317,7 +328,7 @@ TEST(GeneratedCode, DeepCloneMessageWithUnknowns) { // Read unknown data from clone and verify. size_t cloned_length; const char* cloned_unknown_data = - upb_Message_GetUnknown(clone, &cloned_length); + upb_Message_GetUnknown(UPB_UPCAST(clone), &cloned_length); EXPECT_EQ(cloned_length, len); EXPECT_EQ(memcmp(cloned_unknown_data, unknown_data.c_str(), cloned_length), 0); diff --git a/upb/message/promote_test.cc b/upb/message/promote_test.cc index fa9bb90090c40..59593652e1293 100644 --- a/upb/message/promote_test.cc +++ b/upb/message/promote_test.cc @@ -23,6 +23,7 @@ #include "upb/base/descriptor_constants.h" #include "upb/base/status.h" #include "upb/base/string_view.h" +#include "upb/base/upcast.h" #include "upb/mem/arena.h" #include "upb/mem/arena.hpp" #include "upb/message/accessors.h" @@ -69,13 +70,13 @@ TEST(GeneratedCode, FindUnknown) { arena); upb_FindUnknownRet result = upb_Message_FindUnknown( - base_msg, + UPB_UPCAST(base_msg), upb_MiniTableExtension_Number(&upb_test_ModelExtension1_model_ext_ext), 0); EXPECT_EQ(kUpb_FindUnknown_Ok, result.status); result = upb_Message_FindUnknown( - base_msg, + UPB_UPCAST(base_msg), upb_MiniTableExtension_Number(&upb_test_ModelExtension2_model_ext_ext), 0); EXPECT_EQ(kUpb_FindUnknown_NotPresent, result.status); @@ -129,7 +130,8 @@ TEST(GeneratedCode, Extensions) { // Test known GetExtension 1 promote_status = upb_MiniTable_GetOrPromoteExtension( - msg, &upb_test_ModelExtension1_model_ext_ext, 0, arena, &upb_ext2); + UPB_UPCAST(msg), &upb_test_ModelExtension1_model_ext_ext, 0, arena, + &upb_ext2); ext1 = (upb_test_ModelExtension1*)upb_ext2->data.ptr; EXPECT_EQ(kUpb_GetExtension_Ok, promote_status); EXPECT_TRUE(upb_StringView_IsEqual(upb_StringView_FromString("World"), @@ -137,35 +139,40 @@ TEST(GeneratedCode, Extensions) { // Test known GetExtension 2 promote_status = upb_MiniTable_GetOrPromoteExtension( - msg, &upb_test_ModelExtension2_model_ext_ext, 0, arena, &upb_ext2); + UPB_UPCAST(msg), &upb_test_ModelExtension2_model_ext_ext, 0, arena, + &upb_ext2); ext2 = (upb_test_ModelExtension2*)upb_ext2->data.ptr; EXPECT_EQ(kUpb_GetExtension_Ok, promote_status); EXPECT_EQ(5, upb_test_ModelExtension2_i(ext2)); // Test known GetExtension 3 promote_status = upb_MiniTable_GetOrPromoteExtension( - msg, &upb_test_ModelExtension2_model_ext_2_ext, 0, arena, &upb_ext2); + UPB_UPCAST(msg), &upb_test_ModelExtension2_model_ext_2_ext, 0, arena, + &upb_ext2); ext2 = (upb_test_ModelExtension2*)upb_ext2->data.ptr; EXPECT_EQ(kUpb_GetExtension_Ok, promote_status); EXPECT_EQ(6, upb_test_ModelExtension2_i(ext2)); // Test known GetExtension 4 promote_status = upb_MiniTable_GetOrPromoteExtension( - msg, &upb_test_ModelExtension2_model_ext_3_ext, 0, arena, &upb_ext2); + UPB_UPCAST(msg), &upb_test_ModelExtension2_model_ext_3_ext, 0, arena, + &upb_ext2); ext2 = (upb_test_ModelExtension2*)upb_ext2->data.ptr; EXPECT_EQ(kUpb_GetExtension_Ok, promote_status); EXPECT_EQ(7, upb_test_ModelExtension2_i(ext2)); // Test known GetExtension 5 promote_status = upb_MiniTable_GetOrPromoteExtension( - msg, &upb_test_ModelExtension2_model_ext_4_ext, 0, arena, &upb_ext2); + UPB_UPCAST(msg), &upb_test_ModelExtension2_model_ext_4_ext, 0, arena, + &upb_ext2); ext2 = (upb_test_ModelExtension2*)upb_ext2->data.ptr; EXPECT_EQ(kUpb_GetExtension_Ok, promote_status); EXPECT_EQ(8, upb_test_ModelExtension2_i(ext2)); // Test known GetExtension 6 promote_status = upb_MiniTable_GetOrPromoteExtension( - msg, &upb_test_ModelExtension2_model_ext_5_ext, 0, arena, &upb_ext2); + UPB_UPCAST(msg), &upb_test_ModelExtension2_model_ext_5_ext, 0, arena, + &upb_ext2); ext2 = (upb_test_ModelExtension2*)upb_ext2->data.ptr; EXPECT_EQ(kUpb_GetExtension_Ok, promote_status); EXPECT_EQ(9, upb_test_ModelExtension2_i(ext2)); @@ -176,13 +183,14 @@ TEST(GeneratedCode, Extensions) { // Get unknown extension bytes before promotion. size_t start_len; - upb_Message_GetUnknown(base_msg, &start_len); + upb_Message_GetUnknown(UPB_UPCAST(base_msg), &start_len); EXPECT_GT(start_len, 0); - EXPECT_EQ(0, upb_Message_ExtensionCount(base_msg)); + EXPECT_EQ(0, upb_Message_ExtensionCount(UPB_UPCAST(base_msg))); // Test unknown GetExtension. promote_status = upb_MiniTable_GetOrPromoteExtension( - base_msg, &upb_test_ModelExtension1_model_ext_ext, 0, arena, &upb_ext2); + UPB_UPCAST(base_msg), &upb_test_ModelExtension1_model_ext_ext, 0, arena, + &upb_ext2); ext1 = (upb_test_ModelExtension1*)upb_ext2->data.ptr; EXPECT_EQ(kUpb_GetExtension_Ok, promote_status); EXPECT_TRUE(upb_StringView_IsEqual(upb_StringView_FromString("World"), @@ -190,43 +198,48 @@ TEST(GeneratedCode, Extensions) { // Test unknown GetExtension. promote_status = upb_MiniTable_GetOrPromoteExtension( - base_msg, &upb_test_ModelExtension2_model_ext_ext, 0, arena, &upb_ext2); + UPB_UPCAST(base_msg), &upb_test_ModelExtension2_model_ext_ext, 0, arena, + &upb_ext2); ext2 = (upb_test_ModelExtension2*)upb_ext2->data.ptr; EXPECT_EQ(kUpb_GetExtension_Ok, promote_status); EXPECT_EQ(5, upb_test_ModelExtension2_i(ext2)); // Test unknown GetExtension. promote_status = upb_MiniTable_GetOrPromoteExtension( - base_msg, &upb_test_ModelExtension2_model_ext_2_ext, 0, arena, &upb_ext2); + UPB_UPCAST(base_msg), &upb_test_ModelExtension2_model_ext_2_ext, 0, arena, + &upb_ext2); ext2 = (upb_test_ModelExtension2*)upb_ext2->data.ptr; EXPECT_EQ(kUpb_GetExtension_Ok, promote_status); EXPECT_EQ(6, upb_test_ModelExtension2_i(ext2)); // Test unknown GetExtension. promote_status = upb_MiniTable_GetOrPromoteExtension( - base_msg, &upb_test_ModelExtension2_model_ext_3_ext, 0, arena, &upb_ext2); + UPB_UPCAST(base_msg), &upb_test_ModelExtension2_model_ext_3_ext, 0, arena, + &upb_ext2); ext2 = (upb_test_ModelExtension2*)upb_ext2->data.ptr; EXPECT_EQ(kUpb_GetExtension_Ok, promote_status); EXPECT_EQ(7, upb_test_ModelExtension2_i(ext2)); // Test unknown GetExtension. promote_status = upb_MiniTable_GetOrPromoteExtension( - base_msg, &upb_test_ModelExtension2_model_ext_4_ext, 0, arena, &upb_ext2); + UPB_UPCAST(base_msg), &upb_test_ModelExtension2_model_ext_4_ext, 0, arena, + &upb_ext2); ext2 = (upb_test_ModelExtension2*)upb_ext2->data.ptr; EXPECT_EQ(kUpb_GetExtension_Ok, promote_status); EXPECT_EQ(8, upb_test_ModelExtension2_i(ext2)); // Test unknown GetExtension. promote_status = upb_MiniTable_GetOrPromoteExtension( - base_msg, &upb_test_ModelExtension2_model_ext_5_ext, 0, arena, &upb_ext2); + UPB_UPCAST(base_msg), &upb_test_ModelExtension2_model_ext_5_ext, 0, arena, + &upb_ext2); ext2 = (upb_test_ModelExtension2*)upb_ext2->data.ptr; EXPECT_EQ(kUpb_GetExtension_Ok, promote_status); EXPECT_EQ(9, upb_test_ModelExtension2_i(ext2)); size_t end_len; - upb_Message_GetUnknown(base_msg, &end_len); + upb_Message_GetUnknown(UPB_UPCAST(base_msg), &end_len); EXPECT_LT(end_len, start_len); - EXPECT_EQ(6, upb_Message_ExtensionCount(base_msg)); + EXPECT_EQ(6, upb_Message_ExtensionCount(UPB_UPCAST(base_msg))); upb_Arena_Free(arena); } @@ -377,7 +390,8 @@ TEST(GeneratedCode, PromoteUnknownMessage) { arena.ptr(), (upb_Message**)&promoted); EXPECT_EQ(promote_result, kUpb_DecodeStatus_Ok); EXPECT_NE(nullptr, promoted); - EXPECT_EQ(promoted, upb_Message_GetMessage(msg, submsg_field, nullptr)); + EXPECT_EQ(UPB_UPCAST(promoted), + upb_Message_GetMessage(msg, submsg_field, nullptr)); EXPECT_EQ(upb_test_ModelWithExtensions_random_int32(promoted), 12); } @@ -425,7 +439,8 @@ TEST(GeneratedCode, ReparseUnlinked) { arena.ptr(), (upb_Message**)&promoted); EXPECT_EQ(promote_result, kUpb_DecodeStatus_Ok); EXPECT_NE(nullptr, promoted); - EXPECT_EQ(promoted, upb_Message_GetMessage(msg, submsg_field, nullptr)); + EXPECT_EQ(UPB_UPCAST(promoted), + upb_Message_GetMessage(msg, submsg_field, nullptr)); // The repeated field should have two entries for the two parses. size_t repeated_size; @@ -478,7 +493,8 @@ TEST(GeneratedCode, PromoteInParser) { nullptr); EXPECT_NE(nullptr, promoted); - EXPECT_EQ(promoted, upb_Message_GetMessage(msg, submsg_field, nullptr)); + EXPECT_EQ(UPB_UPCAST(promoted), + upb_Message_GetMessage(msg, submsg_field, nullptr)); // The repeated field should have two entries for the two parses. size_t repeated_size; @@ -624,15 +640,15 @@ TEST(GeneratedCode, PromoteUnknownToMap) { upb_MessageValue val; key.int32_val = 111; EXPECT_TRUE(upb_Map_Get(map, key, &val)); - EXPECT_EQ(123, - upb_test_ModelWithExtensions_random_int32( - static_cast(val.msg_val))); + EXPECT_EQ(123, upb_test_ModelWithExtensions_random_int32( + static_cast( + (void*)(val.msg_val)))); key.int32_val = 222; EXPECT_TRUE(upb_Map_Get(map, key, &val)); - EXPECT_EQ(456, - upb_test_ModelWithExtensions_random_int32( - static_cast(val.msg_val))); + EXPECT_EQ(456, upb_test_ModelWithExtensions_random_int32( + static_cast( + (void*)(val.msg_val)))); } } // namespace diff --git a/upb/message/test.cc b/upb/message/test.cc index 97ebef04145fd..2bb46bdaab87b 100644 --- a/upb/message/test.cc +++ b/upb/message/test.cc @@ -16,6 +16,7 @@ #include "google/protobuf/test_messages_proto3.upb.h" #include "upb/base/status.hpp" #include "upb/base/string_view.h" +#include "upb/base/upcast.h" #include "upb/json/decode.h" #include "upb/json/encode.h" #include "upb/mem/arena.h" @@ -72,8 +73,9 @@ TEST(MessageTest, Extensions) { } )json"; upb::Status status; - EXPECT_TRUE(upb_JsonDecode(json.data(), json.size(), ext_msg, m.ptr(), - defpool.ptr(), 0, arena.ptr(), status.ptr())) + EXPECT_TRUE(upb_JsonDecode(json.data(), json.size(), UPB_UPCAST(ext_msg), + m.ptr(), defpool.ptr(), 0, arena.ptr(), + status.ptr())) << status.error_message(); VerifyMessage(ext_msg); @@ -91,14 +93,14 @@ TEST(MessageTest, Extensions) { VerifyMessage(ext_msg2); // Test round-trip through JSON format. - size_t json_size = upb_JsonEncode(ext_msg, m.ptr(), defpool.ptr(), 0, nullptr, - 0, status.ptr()); + size_t json_size = upb_JsonEncode(UPB_UPCAST(ext_msg), m.ptr(), defpool.ptr(), + 0, nullptr, 0, status.ptr()); char* json_buf = static_cast(upb_Arena_Malloc(arena.ptr(), json_size + 1)); - upb_JsonEncode(ext_msg, m.ptr(), defpool.ptr(), 0, json_buf, json_size + 1, - status.ptr()); + upb_JsonEncode(UPB_UPCAST(ext_msg), m.ptr(), defpool.ptr(), 0, json_buf, + json_size + 1, status.ptr()); upb_test_TestExtensions* ext_msg3 = upb_test_TestExtensions_new(arena.ptr()); - EXPECT_TRUE(upb_JsonDecode(json_buf, json_size, ext_msg3, m.ptr(), + EXPECT_TRUE(upb_JsonDecode(json_buf, json_size, UPB_UPCAST(ext_msg3), m.ptr(), defpool.ptr(), 0, arena.ptr(), status.ptr())) << status.error_message(); VerifyMessage(ext_msg3); @@ -132,8 +134,9 @@ TEST(MessageTest, MessageSet) { } )json"; upb::Status status; - EXPECT_TRUE(upb_JsonDecode(json.data(), json.size(), ext_msg, m.ptr(), - defpool.ptr(), 0, arena.ptr(), status.ptr())) + EXPECT_TRUE(upb_JsonDecode(json.data(), json.size(), UPB_UPCAST(ext_msg), + m.ptr(), defpool.ptr(), 0, arena.ptr(), + status.ptr())) << status.error_message(); VerifyMessageSet(ext_msg); @@ -151,14 +154,14 @@ TEST(MessageTest, MessageSet) { VerifyMessageSet(ext_msg2); // Test round-trip through JSON format. - size_t json_size = upb_JsonEncode(ext_msg, m.ptr(), defpool.ptr(), 0, nullptr, - 0, status.ptr()); + size_t json_size = upb_JsonEncode(UPB_UPCAST(ext_msg), m.ptr(), defpool.ptr(), + 0, nullptr, 0, status.ptr()); char* json_buf = static_cast(upb_Arena_Malloc(arena.ptr(), json_size + 1)); - upb_JsonEncode(ext_msg, m.ptr(), defpool.ptr(), 0, json_buf, json_size + 1, - status.ptr()); + upb_JsonEncode(UPB_UPCAST(ext_msg), m.ptr(), defpool.ptr(), 0, json_buf, + json_size + 1, status.ptr()); upb_test_TestMessageSet* ext_msg3 = upb_test_TestMessageSet_new(arena.ptr()); - EXPECT_TRUE(upb_JsonDecode(json_buf, json_size, ext_msg3, m.ptr(), + EXPECT_TRUE(upb_JsonDecode(json_buf, json_size, UPB_UPCAST(ext_msg3), m.ptr(), defpool.ptr(), 0, arena.ptr(), status.ptr())) << status.error_message(); VerifyMessageSet(ext_msg3); @@ -311,10 +314,10 @@ TEST(MessageTest, DecodeRequiredFieldsTopLevelMessage) { EXPECT_NE(nullptr, test_msg); // Fails, because required fields are missing. - EXPECT_EQ( - kUpb_DecodeStatus_MissingRequired, - upb_Decode(nullptr, 0, test_msg, &upb_0test__TestRequiredFields_msg_init, - nullptr, kUpb_DecodeOption_CheckRequired, arena.ptr())); + EXPECT_EQ(kUpb_DecodeStatus_MissingRequired, + upb_Decode(nullptr, 0, UPB_UPCAST(test_msg), + &upb_0test__TestRequiredFields_msg_init, nullptr, + kUpb_DecodeOption_CheckRequired, arena.ptr())); upb_test_TestRequiredFields_set_required_int32(test_msg, 1); size_t size; @@ -326,7 +329,7 @@ TEST(MessageTest, DecodeRequiredFieldsTopLevelMessage) { // Fails, but the code path is slightly different because the serialized // payload is not empty. EXPECT_EQ(kUpb_DecodeStatus_MissingRequired, - upb_Decode(serialized, size, test_msg, + upb_Decode(serialized, size, UPB_UPCAST(test_msg), &upb_0test__TestRequiredFields_msg_init, nullptr, kUpb_DecodeOption_CheckRequired, arena.ptr())); @@ -336,10 +339,10 @@ TEST(MessageTest, DecodeRequiredFieldsTopLevelMessage) { upb_test_TestRequiredFields_set_required_message(test_msg, empty_msg); // Succeeds, because required fields are present (though not in the input). - EXPECT_EQ( - kUpb_DecodeStatus_Ok, - upb_Decode(nullptr, 0, test_msg, &upb_0test__TestRequiredFields_msg_init, - nullptr, kUpb_DecodeOption_CheckRequired, arena.ptr())); + EXPECT_EQ(kUpb_DecodeStatus_Ok, + upb_Decode(nullptr, 0, UPB_UPCAST(test_msg), + &upb_0test__TestRequiredFields_msg_init, nullptr, + kUpb_DecodeOption_CheckRequired, arena.ptr())); // Serialize a complete payload. serialized = @@ -356,7 +359,7 @@ TEST(MessageTest, DecodeRequiredFieldsTopLevelMessage) { upb_test_TestRequiredFields_set_optional_message( test_msg2, upb_test_TestRequiredFields_new(arena.ptr())); EXPECT_EQ(kUpb_DecodeStatus_Ok, - upb_Decode(serialized, size, test_msg2, + upb_Decode(serialized, size, UPB_UPCAST(test_msg2), &upb_0test__TestRequiredFields_msg_init, nullptr, kUpb_DecodeOption_CheckRequired, arena.ptr())); } @@ -450,7 +453,7 @@ TEST(MessageTest, MaxRequiredFields) { for (int i = 1; i <= 61; i++) { upb::FieldDefPtr f = m.FindFieldByNumber(i); ASSERT_TRUE(f); - upb_Message_SetFieldByDef(test_msg, f.ptr(), val, arena.ptr()); + upb_Message_SetFieldByDef(UPB_UPCAST(test_msg), f.ptr(), val, arena.ptr()); } // Fails, field 63 still isn't set. @@ -461,7 +464,7 @@ TEST(MessageTest, MaxRequiredFields) { // Succeeds, all required fields are set. upb::FieldDefPtr f = m.FindFieldByNumber(62); ASSERT_TRUE(f); - upb_Message_SetFieldByDef(test_msg, f.ptr(), val, arena.ptr()); + upb_Message_SetFieldByDef(UPB_UPCAST(test_msg), f.ptr(), val, arena.ptr()); serialized = upb_test_TestMaxRequiredFields_serialize_ex( test_msg, kUpb_EncodeOption_CheckRequired, arena.ptr(), &size); ASSERT_TRUE(serialized != nullptr); diff --git a/upb/message/types.h b/upb/message/types.h index 3059e682c1c9b..d20cf27dfc86c 100644 --- a/upb/message/types.h +++ b/upb/message/types.h @@ -10,6 +10,8 @@ // This typedef is in a leaf header to resolve a circular dependency between // messages and mini tables. -typedef void upb_Message; +typedef struct upb_Message { + int unused; // Placeholder cuz Windows won't compile an empty struct. +} upb_Message; #endif /* UPB_MESSAGE_TYPES_H_ */ diff --git a/upb/message/utf8_test.cc b/upb/message/utf8_test.cc index e5764e68cf8ad..b900a954b3a92 100644 --- a/upb/message/utf8_test.cc +++ b/upb/message/utf8_test.cc @@ -9,6 +9,7 @@ #include #include "upb/base/string_view.h" +#include "upb/base/upcast.h" #include "upb/mem/arena.h" #include "upb/mem/arena.hpp" #include "upb/message/utf8_test.upb.h" @@ -46,9 +47,9 @@ TEST(Utf8Test, Proto3FieldValidates) { upb_test_TestUtf8Proto3String* msg = upb_test_TestUtf8Proto3String_new(arena.ptr()); - upb_DecodeStatus status = - upb_Decode(data, size, msg, &upb_0test__TestUtf8Proto3String_msg_init, - nullptr, 0, arena.ptr()); + upb_DecodeStatus status = upb_Decode( + data, size, UPB_UPCAST(msg), &upb_0test__TestUtf8Proto3String_msg_init, + nullptr, 0, arena.ptr()); // Parse fails, because proto3 string fields validate UTF-8. ASSERT_EQ(kUpb_DecodeStatus_BadUtf8, status); @@ -62,9 +63,10 @@ TEST(Utf8Test, RepeatedProto3FieldValidates) { upb_test_TestUtf8RepeatedProto3String* msg = upb_test_TestUtf8RepeatedProto3String_new(arena.ptr()); - upb_DecodeStatus status = upb_Decode( - data, size, msg, &upb_0test__TestUtf8RepeatedProto3String_msg_init, - nullptr, 0, arena.ptr()); + upb_DecodeStatus status = + upb_Decode(data, size, UPB_UPCAST(msg), + &upb_0test__TestUtf8RepeatedProto3String_msg_init, nullptr, 0, + arena.ptr()); // Parse fails, because proto3 string fields validate UTF-8. ASSERT_EQ(kUpb_DecodeStatus_BadUtf8, status); @@ -80,8 +82,8 @@ TEST(Utf8Test, RepeatedProto3FieldValidates) { // upb_test_TestUtf8Proto3StringMixed_new(arena.ptr()); // // upb_DecodeStatus status = upb_Decode( -// data, size, msg, &upb_0test__TestUtf8Proto3StringMixed_msg_init, nullptr, -// 0, arena.ptr()); +// data, size, UPB_UPCAST(msg), +// &upb_0test__TestUtf8Proto3StringMixed_msg_init, nullptr, 0, arena.ptr()); // // // Parse fails, because proto3 string fields validate UTF-8. // ASSERT_EQ(kUpb_DecodeStatus_BadUtf8, status); diff --git a/upb/reflection/BUILD b/upb/reflection/BUILD index fdd20ee1f7502..c3407c93d3156 100644 --- a/upb/reflection/BUILD +++ b/upb/reflection/BUILD @@ -146,6 +146,7 @@ bootstrap_cc_library( "//upb:mini_descriptor_internal", "//upb:mini_table", "//upb:port", + "//upb:wire", ], ) @@ -178,6 +179,7 @@ cc_test( deps = [ ":descriptor_upb_proto", "@com_google_googletest//:gtest_main", + "//upb:base", "//upb:hash", "//upb:mem", "//upb:port", diff --git a/upb/reflection/field_def.c b/upb/reflection/field_def.c index d81da1c0986a2..3b6089670d7d5 100644 --- a/upb/reflection/field_def.c +++ b/upb/reflection/field_def.c @@ -16,6 +16,7 @@ #include "upb/base/descriptor_constants.h" #include "upb/base/string_view.h" +#include "upb/base/upcast.h" #include "upb/mem/arena.h" #include "upb/message/accessors.h" #include "upb/message/value.h" @@ -607,7 +608,8 @@ static void _upb_FieldDef_Create(upb_DefBuilder* ctx, const char* prefix, bool implicit = false; if (syntax != kUpb_Syntax_Editions) { - upb_Message_Clear(ctx->legacy_features, UPB_DESC_MINITABLE(FeatureSet)); + upb_Message_Clear(UPB_UPCAST(ctx->legacy_features), + UPB_DESC_MINITABLE(FeatureSet)); if (_upb_FieldDef_InferLegacyFeatures(ctx, f, field_proto, f->opts, syntax, ctx->legacy_features)) { implicit = true; diff --git a/upb/reflection/internal/def_builder.c b/upb/reflection/internal/def_builder.c index 7558c9ebe9e2d..dcd8ee2f1d3e7 100644 --- a/upb/reflection/internal/def_builder.c +++ b/upb/reflection/internal/def_builder.c @@ -10,6 +10,7 @@ #include #include "upb/base/internal/log2.h" +#include "upb/base/upcast.h" #include "upb/mem/alloc.h" #include "upb/message/copy.h" #include "upb/reflection/def_pool.h" @@ -17,6 +18,7 @@ #include "upb/reflection/field_def.h" #include "upb/reflection/file_def.h" #include "upb/reflection/internal/strdup2.h" +#include "upb/wire/decode.h" // Must be last. #include "upb/port/def.inc" @@ -368,8 +370,8 @@ bool _upb_DefBuilder_GetOrCreateFeatureSet(upb_DefBuilder* ctx, return false; } - *set = - upb_Message_DeepClone(parent, UPB_DESC_MINITABLE(FeatureSet), ctx->arena); + *set = (UPB_DESC(FeatureSet*))upb_Message_DeepClone( + UPB_UPCAST(parent), UPB_DESC_MINITABLE(FeatureSet), ctx->arena); if (!*set) _upb_DefBuilder_OomErr(ctx); v = upb_value_ptr(*set); @@ -406,7 +408,7 @@ const UPB_DESC(FeatureSet*) } upb_DecodeStatus dec_status = - upb_Decode(child_bytes, child_size, resolved, + upb_Decode(child_bytes, child_size, UPB_UPCAST(resolved), UPB_DESC_MINITABLE(FeatureSet), NULL, 0, ctx->arena); if (dec_status != kUpb_DecodeStatus_Ok) _upb_DefBuilder_OomErr(ctx); diff --git a/upb/reflection/stage0/google/protobuf/descriptor.upb.h b/upb/reflection/stage0/google/protobuf/descriptor.upb.h index 99caf55dc0842..e94e8d6ae2443 100644 --- a/upb/reflection/stage0/google/protobuf/descriptor.upb.h +++ b/upb/reflection/stage0/google/protobuf/descriptor.upb.h @@ -67,38 +67,38 @@ extern const upb_MiniTableEnum* google_protobuf_FileOptions_OptimizeMode_enum_in extern const upb_MiniTableEnum* google_protobuf_GeneratedCodeInfo_Annotation_Semantic_enum_init(); extern const upb_MiniTableEnum* google_protobuf_MethodOptions_IdempotencyLevel_enum_init(); -typedef struct google_protobuf_FileDescriptorSet google_protobuf_FileDescriptorSet; -typedef struct google_protobuf_FileDescriptorProto google_protobuf_FileDescriptorProto; -typedef struct google_protobuf_DescriptorProto google_protobuf_DescriptorProto; -typedef struct google_protobuf_DescriptorProto_ExtensionRange google_protobuf_DescriptorProto_ExtensionRange; -typedef struct google_protobuf_DescriptorProto_ReservedRange google_protobuf_DescriptorProto_ReservedRange; -typedef struct google_protobuf_ExtensionRangeOptions google_protobuf_ExtensionRangeOptions; -typedef struct google_protobuf_ExtensionRangeOptions_Declaration google_protobuf_ExtensionRangeOptions_Declaration; -typedef struct google_protobuf_FieldDescriptorProto google_protobuf_FieldDescriptorProto; -typedef struct google_protobuf_OneofDescriptorProto google_protobuf_OneofDescriptorProto; -typedef struct google_protobuf_EnumDescriptorProto google_protobuf_EnumDescriptorProto; -typedef struct google_protobuf_EnumDescriptorProto_EnumReservedRange google_protobuf_EnumDescriptorProto_EnumReservedRange; -typedef struct google_protobuf_EnumValueDescriptorProto google_protobuf_EnumValueDescriptorProto; -typedef struct google_protobuf_ServiceDescriptorProto google_protobuf_ServiceDescriptorProto; -typedef struct google_protobuf_MethodDescriptorProto google_protobuf_MethodDescriptorProto; -typedef struct google_protobuf_FileOptions google_protobuf_FileOptions; -typedef struct google_protobuf_MessageOptions google_protobuf_MessageOptions; -typedef struct google_protobuf_FieldOptions google_protobuf_FieldOptions; -typedef struct google_protobuf_FieldOptions_EditionDefault google_protobuf_FieldOptions_EditionDefault; -typedef struct google_protobuf_OneofOptions google_protobuf_OneofOptions; -typedef struct google_protobuf_EnumOptions google_protobuf_EnumOptions; -typedef struct google_protobuf_EnumValueOptions google_protobuf_EnumValueOptions; -typedef struct google_protobuf_ServiceOptions google_protobuf_ServiceOptions; -typedef struct google_protobuf_MethodOptions google_protobuf_MethodOptions; -typedef struct google_protobuf_UninterpretedOption google_protobuf_UninterpretedOption; -typedef struct google_protobuf_UninterpretedOption_NamePart google_protobuf_UninterpretedOption_NamePart; -typedef struct google_protobuf_FeatureSet google_protobuf_FeatureSet; -typedef struct google_protobuf_FeatureSetDefaults google_protobuf_FeatureSetDefaults; -typedef struct google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault; -typedef struct google_protobuf_SourceCodeInfo google_protobuf_SourceCodeInfo; -typedef struct google_protobuf_SourceCodeInfo_Location google_protobuf_SourceCodeInfo_Location; -typedef struct google_protobuf_GeneratedCodeInfo google_protobuf_GeneratedCodeInfo; -typedef struct google_protobuf_GeneratedCodeInfo_Annotation google_protobuf_GeneratedCodeInfo_Annotation; +typedef struct google_protobuf_FileDescriptorSet { upb_Message UPB_PRIVATE(base); } google_protobuf_FileDescriptorSet; +typedef struct google_protobuf_FileDescriptorProto { upb_Message UPB_PRIVATE(base); } google_protobuf_FileDescriptorProto; +typedef struct google_protobuf_DescriptorProto { upb_Message UPB_PRIVATE(base); } google_protobuf_DescriptorProto; +typedef struct google_protobuf_DescriptorProto_ExtensionRange { upb_Message UPB_PRIVATE(base); } google_protobuf_DescriptorProto_ExtensionRange; +typedef struct google_protobuf_DescriptorProto_ReservedRange { upb_Message UPB_PRIVATE(base); } google_protobuf_DescriptorProto_ReservedRange; +typedef struct google_protobuf_ExtensionRangeOptions { upb_Message UPB_PRIVATE(base); } google_protobuf_ExtensionRangeOptions; +typedef struct google_protobuf_ExtensionRangeOptions_Declaration { upb_Message UPB_PRIVATE(base); } google_protobuf_ExtensionRangeOptions_Declaration; +typedef struct google_protobuf_FieldDescriptorProto { upb_Message UPB_PRIVATE(base); } google_protobuf_FieldDescriptorProto; +typedef struct google_protobuf_OneofDescriptorProto { upb_Message UPB_PRIVATE(base); } google_protobuf_OneofDescriptorProto; +typedef struct google_protobuf_EnumDescriptorProto { upb_Message UPB_PRIVATE(base); } google_protobuf_EnumDescriptorProto; +typedef struct google_protobuf_EnumDescriptorProto_EnumReservedRange { upb_Message UPB_PRIVATE(base); } google_protobuf_EnumDescriptorProto_EnumReservedRange; +typedef struct google_protobuf_EnumValueDescriptorProto { upb_Message UPB_PRIVATE(base); } google_protobuf_EnumValueDescriptorProto; +typedef struct google_protobuf_ServiceDescriptorProto { upb_Message UPB_PRIVATE(base); } google_protobuf_ServiceDescriptorProto; +typedef struct google_protobuf_MethodDescriptorProto { upb_Message UPB_PRIVATE(base); } google_protobuf_MethodDescriptorProto; +typedef struct google_protobuf_FileOptions { upb_Message UPB_PRIVATE(base); } google_protobuf_FileOptions; +typedef struct google_protobuf_MessageOptions { upb_Message UPB_PRIVATE(base); } google_protobuf_MessageOptions; +typedef struct google_protobuf_FieldOptions { upb_Message UPB_PRIVATE(base); } google_protobuf_FieldOptions; +typedef struct google_protobuf_FieldOptions_EditionDefault { upb_Message UPB_PRIVATE(base); } google_protobuf_FieldOptions_EditionDefault; +typedef struct google_protobuf_OneofOptions { upb_Message UPB_PRIVATE(base); } google_protobuf_OneofOptions; +typedef struct google_protobuf_EnumOptions { upb_Message UPB_PRIVATE(base); } google_protobuf_EnumOptions; +typedef struct google_protobuf_EnumValueOptions { upb_Message UPB_PRIVATE(base); } google_protobuf_EnumValueOptions; +typedef struct google_protobuf_ServiceOptions { upb_Message UPB_PRIVATE(base); } google_protobuf_ServiceOptions; +typedef struct google_protobuf_MethodOptions { upb_Message UPB_PRIVATE(base); } google_protobuf_MethodOptions; +typedef struct google_protobuf_UninterpretedOption { upb_Message UPB_PRIVATE(base); } google_protobuf_UninterpretedOption; +typedef struct google_protobuf_UninterpretedOption_NamePart { upb_Message UPB_PRIVATE(base); } google_protobuf_UninterpretedOption_NamePart; +typedef struct google_protobuf_FeatureSet { upb_Message UPB_PRIVATE(base); } google_protobuf_FeatureSet; +typedef struct google_protobuf_FeatureSetDefaults { upb_Message UPB_PRIVATE(base); } google_protobuf_FeatureSetDefaults; +typedef struct google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault { upb_Message UPB_PRIVATE(base); } google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault; +typedef struct google_protobuf_SourceCodeInfo { upb_Message UPB_PRIVATE(base); } google_protobuf_SourceCodeInfo; +typedef struct google_protobuf_SourceCodeInfo_Location { upb_Message UPB_PRIVATE(base); } google_protobuf_SourceCodeInfo_Location; +typedef struct google_protobuf_GeneratedCodeInfo { upb_Message UPB_PRIVATE(base); } google_protobuf_GeneratedCodeInfo; +typedef struct google_protobuf_GeneratedCodeInfo_Annotation { upb_Message UPB_PRIVATE(base); } google_protobuf_GeneratedCodeInfo_Annotation; typedef enum { google_protobuf_EDITION_UNKNOWN = 0, @@ -241,7 +241,8 @@ UPB_INLINE google_protobuf_FileDescriptorSet* google_protobuf_FileDescriptorSet_ UPB_INLINE google_protobuf_FileDescriptorSet* google_protobuf_FileDescriptorSet_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_FileDescriptorSet* ret = google_protobuf_FileDescriptorSet_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, google__protobuf__FileDescriptorSet_msg_init(), NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), google__protobuf__FileDescriptorSet_msg_init(), NULL, 0, arena) != + kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -251,30 +252,30 @@ UPB_INLINE google_protobuf_FileDescriptorSet* google_protobuf_FileDescriptorSet_ int options, upb_Arena* arena) { google_protobuf_FileDescriptorSet* ret = google_protobuf_FileDescriptorSet_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, google__protobuf__FileDescriptorSet_msg_init(), extreg, options, arena) != - kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), google__protobuf__FileDescriptorSet_msg_init(), extreg, options, + arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_FileDescriptorSet_serialize(const google_protobuf_FileDescriptorSet* msg, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, google__protobuf__FileDescriptorSet_msg_init(), 0, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), google__protobuf__FileDescriptorSet_msg_init(), 0, arena, &ptr, len); return ptr; } UPB_INLINE char* google_protobuf_FileDescriptorSet_serialize_ex(const google_protobuf_FileDescriptorSet* msg, int options, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, google__protobuf__FileDescriptorSet_msg_init(), options, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), google__protobuf__FileDescriptorSet_msg_init(), options, arena, &ptr, len); return ptr; } UPB_INLINE void google_protobuf_FileDescriptorSet_clear_file(google_protobuf_FileDescriptorSet* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorSet_msg_init(), 1); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_FileDescriptorProto* const* google_protobuf_FileDescriptorSet_file(const google_protobuf_FileDescriptorSet* msg, size_t* size) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorSet_msg_init(), 1); - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_FileDescriptorProto* const*)_upb_array_constptr(arr); @@ -285,16 +286,16 @@ UPB_INLINE const google_protobuf_FileDescriptorProto* const* google_protobuf_Fil } UPB_INLINE const upb_Array* _google_protobuf_FileDescriptorSet_file_upb_array(const google_protobuf_FileDescriptorSet* msg, size_t* size) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorSet_msg_init(), 1); - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } -UPB_INLINE upb_Array* _google_protobuf_FileDescriptorSet_file_mutable_upb_array(const google_protobuf_FileDescriptorSet* msg, size_t* size, upb_Arena* arena) { +UPB_INLINE upb_Array* _google_protobuf_FileDescriptorSet_file_mutable_upb_array(google_protobuf_FileDescriptorSet* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorSet_msg_init(), 1); upb_Array* arr = upb_Message_GetOrCreateMutableArray( - (upb_Message*)msg, &field, arena); + UPB_UPCAST(msg), &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -303,7 +304,7 @@ UPB_INLINE upb_Array* _google_protobuf_FileDescriptorSet_file_mutable_upb_array( UPB_INLINE google_protobuf_FileDescriptorProto** google_protobuf_FileDescriptorSet_mutable_file(google_protobuf_FileDescriptorSet* msg, size_t* size) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorSet_msg_init(), 1); - upb_Array* arr = upb_Message_GetMutableArray(msg, &field); + upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_FileDescriptorProto**)_upb_array_ptr(arr); @@ -314,11 +315,13 @@ UPB_INLINE google_protobuf_FileDescriptorProto** google_protobuf_FileDescriptorS } UPB_INLINE google_protobuf_FileDescriptorProto** google_protobuf_FileDescriptorSet_resize_file(google_protobuf_FileDescriptorSet* msg, size_t size, upb_Arena* arena) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorSet_msg_init(), 1); - return (google_protobuf_FileDescriptorProto**)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); + return (google_protobuf_FileDescriptorProto**)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg), + &field, size, arena); } UPB_INLINE struct google_protobuf_FileDescriptorProto* google_protobuf_FileDescriptorSet_add_file(google_protobuf_FileDescriptorSet* msg, upb_Arena* arena) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorSet_msg_init(), 1); - upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray( + UPB_UPCAST(msg), &field, arena); if (!arr || !_upb_Array_ResizeUninitialized( arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; @@ -338,7 +341,8 @@ UPB_INLINE google_protobuf_FileDescriptorProto* google_protobuf_FileDescriptorPr UPB_INLINE google_protobuf_FileDescriptorProto* google_protobuf_FileDescriptorProto_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_FileDescriptorProto* ret = google_protobuf_FileDescriptorProto_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, google__protobuf__FileDescriptorProto_msg_init(), NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), google__protobuf__FileDescriptorProto_msg_init(), NULL, 0, arena) != + kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -348,60 +352,62 @@ UPB_INLINE google_protobuf_FileDescriptorProto* google_protobuf_FileDescriptorPr int options, upb_Arena* arena) { google_protobuf_FileDescriptorProto* ret = google_protobuf_FileDescriptorProto_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, google__protobuf__FileDescriptorProto_msg_init(), extreg, options, arena) != - kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), google__protobuf__FileDescriptorProto_msg_init(), extreg, options, + arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_FileDescriptorProto_serialize(const google_protobuf_FileDescriptorProto* msg, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, google__protobuf__FileDescriptorProto_msg_init(), 0, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), google__protobuf__FileDescriptorProto_msg_init(), 0, arena, &ptr, len); return ptr; } UPB_INLINE char* google_protobuf_FileDescriptorProto_serialize_ex(const google_protobuf_FileDescriptorProto* msg, int options, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, google__protobuf__FileDescriptorProto_msg_init(), options, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), google__protobuf__FileDescriptorProto_msg_init(), options, arena, &ptr, len); return ptr; } UPB_INLINE void google_protobuf_FileDescriptorProto_clear_name(google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 1); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_FileDescriptorProto_name(const google_protobuf_FileDescriptorProto* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 1); - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FileDescriptorProto_has_name(const google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 1); - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileDescriptorProto_clear_package(google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 2); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_FileDescriptorProto_package(const google_protobuf_FileDescriptorProto* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 2); - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FileDescriptorProto_has_package(const google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 2); - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileDescriptorProto_clear_dependency(google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 3); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView const* google_protobuf_FileDescriptorProto_dependency(const google_protobuf_FileDescriptorProto* msg, size_t* size) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 3); - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (upb_StringView const*)_upb_array_constptr(arr); @@ -412,16 +418,16 @@ UPB_INLINE upb_StringView const* google_protobuf_FileDescriptorProto_dependency( } UPB_INLINE const upb_Array* _google_protobuf_FileDescriptorProto_dependency_upb_array(const google_protobuf_FileDescriptorProto* msg, size_t* size) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 3); - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } -UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_dependency_mutable_upb_array(const google_protobuf_FileDescriptorProto* msg, size_t* size, upb_Arena* arena) { +UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_dependency_mutable_upb_array(google_protobuf_FileDescriptorProto* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 3); upb_Array* arr = upb_Message_GetOrCreateMutableArray( - (upb_Message*)msg, &field, arena); + UPB_UPCAST(msg), &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -429,11 +435,11 @@ UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_dependency_mutable_up } UPB_INLINE void google_protobuf_FileDescriptorProto_clear_message_type(google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 4); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_DescriptorProto* const* google_protobuf_FileDescriptorProto_message_type(const google_protobuf_FileDescriptorProto* msg, size_t* size) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 4); - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_DescriptorProto* const*)_upb_array_constptr(arr); @@ -444,16 +450,16 @@ UPB_INLINE const google_protobuf_DescriptorProto* const* google_protobuf_FileDes } UPB_INLINE const upb_Array* _google_protobuf_FileDescriptorProto_message_type_upb_array(const google_protobuf_FileDescriptorProto* msg, size_t* size) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 4); - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } -UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_message_type_mutable_upb_array(const google_protobuf_FileDescriptorProto* msg, size_t* size, upb_Arena* arena) { +UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_message_type_mutable_upb_array(google_protobuf_FileDescriptorProto* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 4); upb_Array* arr = upb_Message_GetOrCreateMutableArray( - (upb_Message*)msg, &field, arena); + UPB_UPCAST(msg), &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -461,11 +467,11 @@ UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_message_type_mutable_ } UPB_INLINE void google_protobuf_FileDescriptorProto_clear_enum_type(google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 5); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_EnumDescriptorProto* const* google_protobuf_FileDescriptorProto_enum_type(const google_protobuf_FileDescriptorProto* msg, size_t* size) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 5); - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_EnumDescriptorProto* const*)_upb_array_constptr(arr); @@ -476,16 +482,16 @@ UPB_INLINE const google_protobuf_EnumDescriptorProto* const* google_protobuf_Fil } UPB_INLINE const upb_Array* _google_protobuf_FileDescriptorProto_enum_type_upb_array(const google_protobuf_FileDescriptorProto* msg, size_t* size) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 5); - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } -UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_enum_type_mutable_upb_array(const google_protobuf_FileDescriptorProto* msg, size_t* size, upb_Arena* arena) { +UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_enum_type_mutable_upb_array(google_protobuf_FileDescriptorProto* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 5); upb_Array* arr = upb_Message_GetOrCreateMutableArray( - (upb_Message*)msg, &field, arena); + UPB_UPCAST(msg), &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -493,11 +499,11 @@ UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_enum_type_mutable_upb } UPB_INLINE void google_protobuf_FileDescriptorProto_clear_service(google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 6); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_ServiceDescriptorProto* const* google_protobuf_FileDescriptorProto_service(const google_protobuf_FileDescriptorProto* msg, size_t* size) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 6); - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_ServiceDescriptorProto* const*)_upb_array_constptr(arr); @@ -508,16 +514,16 @@ UPB_INLINE const google_protobuf_ServiceDescriptorProto* const* google_protobuf_ } UPB_INLINE const upb_Array* _google_protobuf_FileDescriptorProto_service_upb_array(const google_protobuf_FileDescriptorProto* msg, size_t* size) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 6); - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } -UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_service_mutable_upb_array(const google_protobuf_FileDescriptorProto* msg, size_t* size, upb_Arena* arena) { +UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_service_mutable_upb_array(google_protobuf_FileDescriptorProto* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 6); upb_Array* arr = upb_Message_GetOrCreateMutableArray( - (upb_Message*)msg, &field, arena); + UPB_UPCAST(msg), &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -525,11 +531,11 @@ UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_service_mutable_upb_a } UPB_INLINE void google_protobuf_FileDescriptorProto_clear_extension(google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 7); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_FieldDescriptorProto* const* google_protobuf_FileDescriptorProto_extension(const google_protobuf_FileDescriptorProto* msg, size_t* size) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 7); - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_FieldDescriptorProto* const*)_upb_array_constptr(arr); @@ -540,16 +546,16 @@ UPB_INLINE const google_protobuf_FieldDescriptorProto* const* google_protobuf_Fi } UPB_INLINE const upb_Array* _google_protobuf_FileDescriptorProto_extension_upb_array(const google_protobuf_FileDescriptorProto* msg, size_t* size) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 7); - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } -UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_extension_mutable_upb_array(const google_protobuf_FileDescriptorProto* msg, size_t* size, upb_Arena* arena) { +UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_extension_mutable_upb_array(google_protobuf_FileDescriptorProto* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 7); upb_Array* arr = upb_Message_GetOrCreateMutableArray( - (upb_Message*)msg, &field, arena); + UPB_UPCAST(msg), &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -557,41 +563,43 @@ UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_extension_mutable_upb } UPB_INLINE void google_protobuf_FileDescriptorProto_clear_options(google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 8); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_FileOptions* google_protobuf_FileDescriptorProto_options(const google_protobuf_FileDescriptorProto* msg) { const google_protobuf_FileOptions* default_val = NULL; const google_protobuf_FileOptions* ret; const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 8); - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FileDescriptorProto_has_options(const google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 8); - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileDescriptorProto_clear_source_code_info(google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 9); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_SourceCodeInfo* google_protobuf_FileDescriptorProto_source_code_info(const google_protobuf_FileDescriptorProto* msg) { const google_protobuf_SourceCodeInfo* default_val = NULL; const google_protobuf_SourceCodeInfo* ret; const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 9); - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FileDescriptorProto_has_source_code_info(const google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 9); - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileDescriptorProto_clear_public_dependency(google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 10); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t const* google_protobuf_FileDescriptorProto_public_dependency(const google_protobuf_FileDescriptorProto* msg, size_t* size) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 10); - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (int32_t const*)_upb_array_constptr(arr); @@ -602,16 +610,16 @@ UPB_INLINE int32_t const* google_protobuf_FileDescriptorProto_public_dependency( } UPB_INLINE const upb_Array* _google_protobuf_FileDescriptorProto_public_dependency_upb_array(const google_protobuf_FileDescriptorProto* msg, size_t* size) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 10); - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } -UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_public_dependency_mutable_upb_array(const google_protobuf_FileDescriptorProto* msg, size_t* size, upb_Arena* arena) { +UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_public_dependency_mutable_upb_array(google_protobuf_FileDescriptorProto* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 10); upb_Array* arr = upb_Message_GetOrCreateMutableArray( - (upb_Message*)msg, &field, arena); + UPB_UPCAST(msg), &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -619,11 +627,11 @@ UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_public_dependency_mut } UPB_INLINE void google_protobuf_FileDescriptorProto_clear_weak_dependency(google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 11); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t const* google_protobuf_FileDescriptorProto_weak_dependency(const google_protobuf_FileDescriptorProto* msg, size_t* size) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 11); - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (int32_t const*)_upb_array_constptr(arr); @@ -634,16 +642,16 @@ UPB_INLINE int32_t const* google_protobuf_FileDescriptorProto_weak_dependency(co } UPB_INLINE const upb_Array* _google_protobuf_FileDescriptorProto_weak_dependency_upb_array(const google_protobuf_FileDescriptorProto* msg, size_t* size) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 11); - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } -UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_weak_dependency_mutable_upb_array(const google_protobuf_FileDescriptorProto* msg, size_t* size, upb_Arena* arena) { +UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_weak_dependency_mutable_upb_array(google_protobuf_FileDescriptorProto* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 11); upb_Array* arr = upb_Message_GetOrCreateMutableArray( - (upb_Message*)msg, &field, arena); + UPB_UPCAST(msg), &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -651,46 +659,48 @@ UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_weak_dependency_mutab } UPB_INLINE void google_protobuf_FileDescriptorProto_clear_syntax(google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 12); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_FileDescriptorProto_syntax(const google_protobuf_FileDescriptorProto* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 12); - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FileDescriptorProto_has_syntax(const google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 12); - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileDescriptorProto_clear_edition(google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 14); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_FileDescriptorProto_edition(const google_protobuf_FileDescriptorProto* msg) { int32_t default_val = 0; int32_t ret; const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 14); - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FileDescriptorProto_has_edition(const google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 14); - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileDescriptorProto_set_name(google_protobuf_FileDescriptorProto *msg, upb_StringView value) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 1); - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FileDescriptorProto_set_package(google_protobuf_FileDescriptorProto *msg, upb_StringView value) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 2); - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE upb_StringView* google_protobuf_FileDescriptorProto_mutable_dependency(google_protobuf_FileDescriptorProto* msg, size_t* size) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 3); - upb_Array* arr = upb_Message_GetMutableArray(msg, &field); + upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (upb_StringView*)_upb_array_ptr(arr); @@ -701,11 +711,13 @@ UPB_INLINE upb_StringView* google_protobuf_FileDescriptorProto_mutable_dependenc } UPB_INLINE upb_StringView* google_protobuf_FileDescriptorProto_resize_dependency(google_protobuf_FileDescriptorProto* msg, size_t size, upb_Arena* arena) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 3); - return (upb_StringView*)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); + return (upb_StringView*)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg), + &field, size, arena); } UPB_INLINE bool google_protobuf_FileDescriptorProto_add_dependency(google_protobuf_FileDescriptorProto* msg, upb_StringView val, upb_Arena* arena) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 3); - upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray( + UPB_UPCAST(msg), &field, arena); if (!arr || !_upb_Array_ResizeUninitialized( arr, arr->UPB_PRIVATE(size) + 1, arena)) { return false; @@ -716,7 +728,7 @@ UPB_INLINE bool google_protobuf_FileDescriptorProto_add_dependency(google_protob } UPB_INLINE google_protobuf_DescriptorProto** google_protobuf_FileDescriptorProto_mutable_message_type(google_protobuf_FileDescriptorProto* msg, size_t* size) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 4); - upb_Array* arr = upb_Message_GetMutableArray(msg, &field); + upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_DescriptorProto**)_upb_array_ptr(arr); @@ -727,11 +739,13 @@ UPB_INLINE google_protobuf_DescriptorProto** google_protobuf_FileDescriptorProto } UPB_INLINE google_protobuf_DescriptorProto** google_protobuf_FileDescriptorProto_resize_message_type(google_protobuf_FileDescriptorProto* msg, size_t size, upb_Arena* arena) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 4); - return (google_protobuf_DescriptorProto**)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); + return (google_protobuf_DescriptorProto**)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg), + &field, size, arena); } UPB_INLINE struct google_protobuf_DescriptorProto* google_protobuf_FileDescriptorProto_add_message_type(google_protobuf_FileDescriptorProto* msg, upb_Arena* arena) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 4); - upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray( + UPB_UPCAST(msg), &field, arena); if (!arr || !_upb_Array_ResizeUninitialized( arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; @@ -744,7 +758,7 @@ UPB_INLINE struct google_protobuf_DescriptorProto* google_protobuf_FileDescripto } UPB_INLINE google_protobuf_EnumDescriptorProto** google_protobuf_FileDescriptorProto_mutable_enum_type(google_protobuf_FileDescriptorProto* msg, size_t* size) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 5); - upb_Array* arr = upb_Message_GetMutableArray(msg, &field); + upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_EnumDescriptorProto**)_upb_array_ptr(arr); @@ -755,11 +769,13 @@ UPB_INLINE google_protobuf_EnumDescriptorProto** google_protobuf_FileDescriptorP } UPB_INLINE google_protobuf_EnumDescriptorProto** google_protobuf_FileDescriptorProto_resize_enum_type(google_protobuf_FileDescriptorProto* msg, size_t size, upb_Arena* arena) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 5); - return (google_protobuf_EnumDescriptorProto**)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); + return (google_protobuf_EnumDescriptorProto**)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg), + &field, size, arena); } UPB_INLINE struct google_protobuf_EnumDescriptorProto* google_protobuf_FileDescriptorProto_add_enum_type(google_protobuf_FileDescriptorProto* msg, upb_Arena* arena) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 5); - upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray( + UPB_UPCAST(msg), &field, arena); if (!arr || !_upb_Array_ResizeUninitialized( arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; @@ -772,7 +788,7 @@ UPB_INLINE struct google_protobuf_EnumDescriptorProto* google_protobuf_FileDescr } UPB_INLINE google_protobuf_ServiceDescriptorProto** google_protobuf_FileDescriptorProto_mutable_service(google_protobuf_FileDescriptorProto* msg, size_t* size) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 6); - upb_Array* arr = upb_Message_GetMutableArray(msg, &field); + upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_ServiceDescriptorProto**)_upb_array_ptr(arr); @@ -783,11 +799,13 @@ UPB_INLINE google_protobuf_ServiceDescriptorProto** google_protobuf_FileDescript } UPB_INLINE google_protobuf_ServiceDescriptorProto** google_protobuf_FileDescriptorProto_resize_service(google_protobuf_FileDescriptorProto* msg, size_t size, upb_Arena* arena) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 6); - return (google_protobuf_ServiceDescriptorProto**)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); + return (google_protobuf_ServiceDescriptorProto**)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg), + &field, size, arena); } UPB_INLINE struct google_protobuf_ServiceDescriptorProto* google_protobuf_FileDescriptorProto_add_service(google_protobuf_FileDescriptorProto* msg, upb_Arena* arena) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 6); - upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray( + UPB_UPCAST(msg), &field, arena); if (!arr || !_upb_Array_ResizeUninitialized( arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; @@ -800,7 +818,7 @@ UPB_INLINE struct google_protobuf_ServiceDescriptorProto* google_protobuf_FileDe } UPB_INLINE google_protobuf_FieldDescriptorProto** google_protobuf_FileDescriptorProto_mutable_extension(google_protobuf_FileDescriptorProto* msg, size_t* size) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 7); - upb_Array* arr = upb_Message_GetMutableArray(msg, &field); + upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_FieldDescriptorProto**)_upb_array_ptr(arr); @@ -811,11 +829,13 @@ UPB_INLINE google_protobuf_FieldDescriptorProto** google_protobuf_FileDescriptor } UPB_INLINE google_protobuf_FieldDescriptorProto** google_protobuf_FileDescriptorProto_resize_extension(google_protobuf_FileDescriptorProto* msg, size_t size, upb_Arena* arena) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 7); - return (google_protobuf_FieldDescriptorProto**)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); + return (google_protobuf_FieldDescriptorProto**)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg), + &field, size, arena); } UPB_INLINE struct google_protobuf_FieldDescriptorProto* google_protobuf_FileDescriptorProto_add_extension(google_protobuf_FileDescriptorProto* msg, upb_Arena* arena) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 7); - upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray( + UPB_UPCAST(msg), &field, arena); if (!arr || !_upb_Array_ResizeUninitialized( arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; @@ -828,7 +848,7 @@ UPB_INLINE struct google_protobuf_FieldDescriptorProto* google_protobuf_FileDesc } UPB_INLINE void google_protobuf_FileDescriptorProto_set_options(google_protobuf_FileDescriptorProto *msg, google_protobuf_FileOptions* value) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 8); - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE struct google_protobuf_FileOptions* google_protobuf_FileDescriptorProto_mutable_options(google_protobuf_FileDescriptorProto* msg, upb_Arena* arena) { struct google_protobuf_FileOptions* sub = (struct google_protobuf_FileOptions*)google_protobuf_FileDescriptorProto_options(msg); @@ -840,7 +860,7 @@ UPB_INLINE struct google_protobuf_FileOptions* google_protobuf_FileDescriptorPro } UPB_INLINE void google_protobuf_FileDescriptorProto_set_source_code_info(google_protobuf_FileDescriptorProto *msg, google_protobuf_SourceCodeInfo* value) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 9); - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE struct google_protobuf_SourceCodeInfo* google_protobuf_FileDescriptorProto_mutable_source_code_info(google_protobuf_FileDescriptorProto* msg, upb_Arena* arena) { struct google_protobuf_SourceCodeInfo* sub = (struct google_protobuf_SourceCodeInfo*)google_protobuf_FileDescriptorProto_source_code_info(msg); @@ -852,7 +872,7 @@ UPB_INLINE struct google_protobuf_SourceCodeInfo* google_protobuf_FileDescriptor } UPB_INLINE int32_t* google_protobuf_FileDescriptorProto_mutable_public_dependency(google_protobuf_FileDescriptorProto* msg, size_t* size) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 10); - upb_Array* arr = upb_Message_GetMutableArray(msg, &field); + upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (int32_t*)_upb_array_ptr(arr); @@ -863,11 +883,13 @@ UPB_INLINE int32_t* google_protobuf_FileDescriptorProto_mutable_public_dependenc } UPB_INLINE int32_t* google_protobuf_FileDescriptorProto_resize_public_dependency(google_protobuf_FileDescriptorProto* msg, size_t size, upb_Arena* arena) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 10); - return (int32_t*)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); + return (int32_t*)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg), + &field, size, arena); } UPB_INLINE bool google_protobuf_FileDescriptorProto_add_public_dependency(google_protobuf_FileDescriptorProto* msg, int32_t val, upb_Arena* arena) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 10); - upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray( + UPB_UPCAST(msg), &field, arena); if (!arr || !_upb_Array_ResizeUninitialized( arr, arr->UPB_PRIVATE(size) + 1, arena)) { return false; @@ -878,7 +900,7 @@ UPB_INLINE bool google_protobuf_FileDescriptorProto_add_public_dependency(google } UPB_INLINE int32_t* google_protobuf_FileDescriptorProto_mutable_weak_dependency(google_protobuf_FileDescriptorProto* msg, size_t* size) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 11); - upb_Array* arr = upb_Message_GetMutableArray(msg, &field); + upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (int32_t*)_upb_array_ptr(arr); @@ -889,11 +911,13 @@ UPB_INLINE int32_t* google_protobuf_FileDescriptorProto_mutable_weak_dependency( } UPB_INLINE int32_t* google_protobuf_FileDescriptorProto_resize_weak_dependency(google_protobuf_FileDescriptorProto* msg, size_t size, upb_Arena* arena) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 11); - return (int32_t*)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); + return (int32_t*)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg), + &field, size, arena); } UPB_INLINE bool google_protobuf_FileDescriptorProto_add_weak_dependency(google_protobuf_FileDescriptorProto* msg, int32_t val, upb_Arena* arena) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 11); - upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray( + UPB_UPCAST(msg), &field, arena); if (!arr || !_upb_Array_ResizeUninitialized( arr, arr->UPB_PRIVATE(size) + 1, arena)) { return false; @@ -904,11 +928,11 @@ UPB_INLINE bool google_protobuf_FileDescriptorProto_add_weak_dependency(google_p } UPB_INLINE void google_protobuf_FileDescriptorProto_set_syntax(google_protobuf_FileDescriptorProto *msg, upb_StringView value) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 12); - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FileDescriptorProto_set_edition(google_protobuf_FileDescriptorProto *msg, int32_t value) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 14); - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } /* google.protobuf.DescriptorProto */ @@ -919,7 +943,8 @@ UPB_INLINE google_protobuf_DescriptorProto* google_protobuf_DescriptorProto_new( UPB_INLINE google_protobuf_DescriptorProto* google_protobuf_DescriptorProto_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_DescriptorProto* ret = google_protobuf_DescriptorProto_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, google__protobuf__DescriptorProto_msg_init(), NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), google__protobuf__DescriptorProto_msg_init(), NULL, 0, arena) != + kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -929,45 +954,46 @@ UPB_INLINE google_protobuf_DescriptorProto* google_protobuf_DescriptorProto_pars int options, upb_Arena* arena) { google_protobuf_DescriptorProto* ret = google_protobuf_DescriptorProto_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, google__protobuf__DescriptorProto_msg_init(), extreg, options, arena) != - kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), google__protobuf__DescriptorProto_msg_init(), extreg, options, + arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_DescriptorProto_serialize(const google_protobuf_DescriptorProto* msg, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, google__protobuf__DescriptorProto_msg_init(), 0, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), google__protobuf__DescriptorProto_msg_init(), 0, arena, &ptr, len); return ptr; } UPB_INLINE char* google_protobuf_DescriptorProto_serialize_ex(const google_protobuf_DescriptorProto* msg, int options, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, google__protobuf__DescriptorProto_msg_init(), options, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), google__protobuf__DescriptorProto_msg_init(), options, arena, &ptr, len); return ptr; } UPB_INLINE void google_protobuf_DescriptorProto_clear_name(google_protobuf_DescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 1); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_DescriptorProto_name(const google_protobuf_DescriptorProto* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 1); - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_DescriptorProto_has_name(const google_protobuf_DescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 1); - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_DescriptorProto_clear_field(google_protobuf_DescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 2); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_FieldDescriptorProto* const* google_protobuf_DescriptorProto_field(const google_protobuf_DescriptorProto* msg, size_t* size) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 2); - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_FieldDescriptorProto* const*)_upb_array_constptr(arr); @@ -978,16 +1004,16 @@ UPB_INLINE const google_protobuf_FieldDescriptorProto* const* google_protobuf_De } UPB_INLINE const upb_Array* _google_protobuf_DescriptorProto_field_upb_array(const google_protobuf_DescriptorProto* msg, size_t* size) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 2); - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } -UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_field_mutable_upb_array(const google_protobuf_DescriptorProto* msg, size_t* size, upb_Arena* arena) { +UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_field_mutable_upb_array(google_protobuf_DescriptorProto* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 2); upb_Array* arr = upb_Message_GetOrCreateMutableArray( - (upb_Message*)msg, &field, arena); + UPB_UPCAST(msg), &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -995,11 +1021,11 @@ UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_field_mutable_upb_array(c } UPB_INLINE void google_protobuf_DescriptorProto_clear_nested_type(google_protobuf_DescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 3); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_DescriptorProto* const* google_protobuf_DescriptorProto_nested_type(const google_protobuf_DescriptorProto* msg, size_t* size) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 3); - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_DescriptorProto* const*)_upb_array_constptr(arr); @@ -1010,16 +1036,16 @@ UPB_INLINE const google_protobuf_DescriptorProto* const* google_protobuf_Descrip } UPB_INLINE const upb_Array* _google_protobuf_DescriptorProto_nested_type_upb_array(const google_protobuf_DescriptorProto* msg, size_t* size) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 3); - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } -UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_nested_type_mutable_upb_array(const google_protobuf_DescriptorProto* msg, size_t* size, upb_Arena* arena) { +UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_nested_type_mutable_upb_array(google_protobuf_DescriptorProto* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 3); upb_Array* arr = upb_Message_GetOrCreateMutableArray( - (upb_Message*)msg, &field, arena); + UPB_UPCAST(msg), &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -1027,11 +1053,11 @@ UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_nested_type_mutable_upb_a } UPB_INLINE void google_protobuf_DescriptorProto_clear_enum_type(google_protobuf_DescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 4); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_EnumDescriptorProto* const* google_protobuf_DescriptorProto_enum_type(const google_protobuf_DescriptorProto* msg, size_t* size) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 4); - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_EnumDescriptorProto* const*)_upb_array_constptr(arr); @@ -1042,16 +1068,16 @@ UPB_INLINE const google_protobuf_EnumDescriptorProto* const* google_protobuf_Des } UPB_INLINE const upb_Array* _google_protobuf_DescriptorProto_enum_type_upb_array(const google_protobuf_DescriptorProto* msg, size_t* size) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 4); - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } -UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_enum_type_mutable_upb_array(const google_protobuf_DescriptorProto* msg, size_t* size, upb_Arena* arena) { +UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_enum_type_mutable_upb_array(google_protobuf_DescriptorProto* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 4); upb_Array* arr = upb_Message_GetOrCreateMutableArray( - (upb_Message*)msg, &field, arena); + UPB_UPCAST(msg), &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -1059,11 +1085,11 @@ UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_enum_type_mutable_upb_arr } UPB_INLINE void google_protobuf_DescriptorProto_clear_extension_range(google_protobuf_DescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 5); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_DescriptorProto_ExtensionRange* const* google_protobuf_DescriptorProto_extension_range(const google_protobuf_DescriptorProto* msg, size_t* size) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 5); - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_DescriptorProto_ExtensionRange* const*)_upb_array_constptr(arr); @@ -1074,16 +1100,16 @@ UPB_INLINE const google_protobuf_DescriptorProto_ExtensionRange* const* google_p } UPB_INLINE const upb_Array* _google_protobuf_DescriptorProto_extension_range_upb_array(const google_protobuf_DescriptorProto* msg, size_t* size) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 5); - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } -UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_extension_range_mutable_upb_array(const google_protobuf_DescriptorProto* msg, size_t* size, upb_Arena* arena) { +UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_extension_range_mutable_upb_array(google_protobuf_DescriptorProto* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 5); upb_Array* arr = upb_Message_GetOrCreateMutableArray( - (upb_Message*)msg, &field, arena); + UPB_UPCAST(msg), &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -1091,11 +1117,11 @@ UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_extension_range_mutable_u } UPB_INLINE void google_protobuf_DescriptorProto_clear_extension(google_protobuf_DescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 6); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_FieldDescriptorProto* const* google_protobuf_DescriptorProto_extension(const google_protobuf_DescriptorProto* msg, size_t* size) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 6); - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_FieldDescriptorProto* const*)_upb_array_constptr(arr); @@ -1106,16 +1132,16 @@ UPB_INLINE const google_protobuf_FieldDescriptorProto* const* google_protobuf_De } UPB_INLINE const upb_Array* _google_protobuf_DescriptorProto_extension_upb_array(const google_protobuf_DescriptorProto* msg, size_t* size) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 6); - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } -UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_extension_mutable_upb_array(const google_protobuf_DescriptorProto* msg, size_t* size, upb_Arena* arena) { +UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_extension_mutable_upb_array(google_protobuf_DescriptorProto* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 6); upb_Array* arr = upb_Message_GetOrCreateMutableArray( - (upb_Message*)msg, &field, arena); + UPB_UPCAST(msg), &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -1123,26 +1149,27 @@ UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_extension_mutable_upb_arr } UPB_INLINE void google_protobuf_DescriptorProto_clear_options(google_protobuf_DescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 7); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_MessageOptions* google_protobuf_DescriptorProto_options(const google_protobuf_DescriptorProto* msg) { const google_protobuf_MessageOptions* default_val = NULL; const google_protobuf_MessageOptions* ret; const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 7); - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_DescriptorProto_has_options(const google_protobuf_DescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 7); - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_DescriptorProto_clear_oneof_decl(google_protobuf_DescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 8); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_OneofDescriptorProto* const* google_protobuf_DescriptorProto_oneof_decl(const google_protobuf_DescriptorProto* msg, size_t* size) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 8); - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_OneofDescriptorProto* const*)_upb_array_constptr(arr); @@ -1153,16 +1180,16 @@ UPB_INLINE const google_protobuf_OneofDescriptorProto* const* google_protobuf_De } UPB_INLINE const upb_Array* _google_protobuf_DescriptorProto_oneof_decl_upb_array(const google_protobuf_DescriptorProto* msg, size_t* size) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 8); - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } -UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_oneof_decl_mutable_upb_array(const google_protobuf_DescriptorProto* msg, size_t* size, upb_Arena* arena) { +UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_oneof_decl_mutable_upb_array(google_protobuf_DescriptorProto* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 8); upb_Array* arr = upb_Message_GetOrCreateMutableArray( - (upb_Message*)msg, &field, arena); + UPB_UPCAST(msg), &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -1170,11 +1197,11 @@ UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_oneof_decl_mutable_upb_ar } UPB_INLINE void google_protobuf_DescriptorProto_clear_reserved_range(google_protobuf_DescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 9); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_DescriptorProto_ReservedRange* const* google_protobuf_DescriptorProto_reserved_range(const google_protobuf_DescriptorProto* msg, size_t* size) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 9); - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_DescriptorProto_ReservedRange* const*)_upb_array_constptr(arr); @@ -1185,16 +1212,16 @@ UPB_INLINE const google_protobuf_DescriptorProto_ReservedRange* const* google_pr } UPB_INLINE const upb_Array* _google_protobuf_DescriptorProto_reserved_range_upb_array(const google_protobuf_DescriptorProto* msg, size_t* size) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 9); - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } -UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_reserved_range_mutable_upb_array(const google_protobuf_DescriptorProto* msg, size_t* size, upb_Arena* arena) { +UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_reserved_range_mutable_upb_array(google_protobuf_DescriptorProto* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 9); upb_Array* arr = upb_Message_GetOrCreateMutableArray( - (upb_Message*)msg, &field, arena); + UPB_UPCAST(msg), &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -1202,11 +1229,11 @@ UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_reserved_range_mutable_up } UPB_INLINE void google_protobuf_DescriptorProto_clear_reserved_name(google_protobuf_DescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 10); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView const* google_protobuf_DescriptorProto_reserved_name(const google_protobuf_DescriptorProto* msg, size_t* size) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 10); - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (upb_StringView const*)_upb_array_constptr(arr); @@ -1217,16 +1244,16 @@ UPB_INLINE upb_StringView const* google_protobuf_DescriptorProto_reserved_name(c } UPB_INLINE const upb_Array* _google_protobuf_DescriptorProto_reserved_name_upb_array(const google_protobuf_DescriptorProto* msg, size_t* size) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 10); - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } -UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_reserved_name_mutable_upb_array(const google_protobuf_DescriptorProto* msg, size_t* size, upb_Arena* arena) { +UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_reserved_name_mutable_upb_array(google_protobuf_DescriptorProto* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 10); upb_Array* arr = upb_Message_GetOrCreateMutableArray( - (upb_Message*)msg, &field, arena); + UPB_UPCAST(msg), &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -1235,11 +1262,11 @@ UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_reserved_name_mutable_upb UPB_INLINE void google_protobuf_DescriptorProto_set_name(google_protobuf_DescriptorProto *msg, upb_StringView value) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 1); - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE google_protobuf_FieldDescriptorProto** google_protobuf_DescriptorProto_mutable_field(google_protobuf_DescriptorProto* msg, size_t* size) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 2); - upb_Array* arr = upb_Message_GetMutableArray(msg, &field); + upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_FieldDescriptorProto**)_upb_array_ptr(arr); @@ -1250,11 +1277,13 @@ UPB_INLINE google_protobuf_FieldDescriptorProto** google_protobuf_DescriptorProt } UPB_INLINE google_protobuf_FieldDescriptorProto** google_protobuf_DescriptorProto_resize_field(google_protobuf_DescriptorProto* msg, size_t size, upb_Arena* arena) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 2); - return (google_protobuf_FieldDescriptorProto**)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); + return (google_protobuf_FieldDescriptorProto**)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg), + &field, size, arena); } UPB_INLINE struct google_protobuf_FieldDescriptorProto* google_protobuf_DescriptorProto_add_field(google_protobuf_DescriptorProto* msg, upb_Arena* arena) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 2); - upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray( + UPB_UPCAST(msg), &field, arena); if (!arr || !_upb_Array_ResizeUninitialized( arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; @@ -1267,7 +1296,7 @@ UPB_INLINE struct google_protobuf_FieldDescriptorProto* google_protobuf_Descript } UPB_INLINE google_protobuf_DescriptorProto** google_protobuf_DescriptorProto_mutable_nested_type(google_protobuf_DescriptorProto* msg, size_t* size) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 3); - upb_Array* arr = upb_Message_GetMutableArray(msg, &field); + upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_DescriptorProto**)_upb_array_ptr(arr); @@ -1278,11 +1307,13 @@ UPB_INLINE google_protobuf_DescriptorProto** google_protobuf_DescriptorProto_mut } UPB_INLINE google_protobuf_DescriptorProto** google_protobuf_DescriptorProto_resize_nested_type(google_protobuf_DescriptorProto* msg, size_t size, upb_Arena* arena) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 3); - return (google_protobuf_DescriptorProto**)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); + return (google_protobuf_DescriptorProto**)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg), + &field, size, arena); } UPB_INLINE struct google_protobuf_DescriptorProto* google_protobuf_DescriptorProto_add_nested_type(google_protobuf_DescriptorProto* msg, upb_Arena* arena) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 3); - upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray( + UPB_UPCAST(msg), &field, arena); if (!arr || !_upb_Array_ResizeUninitialized( arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; @@ -1295,7 +1326,7 @@ UPB_INLINE struct google_protobuf_DescriptorProto* google_protobuf_DescriptorPro } UPB_INLINE google_protobuf_EnumDescriptorProto** google_protobuf_DescriptorProto_mutable_enum_type(google_protobuf_DescriptorProto* msg, size_t* size) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 4); - upb_Array* arr = upb_Message_GetMutableArray(msg, &field); + upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_EnumDescriptorProto**)_upb_array_ptr(arr); @@ -1306,11 +1337,13 @@ UPB_INLINE google_protobuf_EnumDescriptorProto** google_protobuf_DescriptorProto } UPB_INLINE google_protobuf_EnumDescriptorProto** google_protobuf_DescriptorProto_resize_enum_type(google_protobuf_DescriptorProto* msg, size_t size, upb_Arena* arena) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 4); - return (google_protobuf_EnumDescriptorProto**)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); + return (google_protobuf_EnumDescriptorProto**)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg), + &field, size, arena); } UPB_INLINE struct google_protobuf_EnumDescriptorProto* google_protobuf_DescriptorProto_add_enum_type(google_protobuf_DescriptorProto* msg, upb_Arena* arena) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 4); - upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray( + UPB_UPCAST(msg), &field, arena); if (!arr || !_upb_Array_ResizeUninitialized( arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; @@ -1323,7 +1356,7 @@ UPB_INLINE struct google_protobuf_EnumDescriptorProto* google_protobuf_Descripto } UPB_INLINE google_protobuf_DescriptorProto_ExtensionRange** google_protobuf_DescriptorProto_mutable_extension_range(google_protobuf_DescriptorProto* msg, size_t* size) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 5); - upb_Array* arr = upb_Message_GetMutableArray(msg, &field); + upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_DescriptorProto_ExtensionRange**)_upb_array_ptr(arr); @@ -1334,11 +1367,13 @@ UPB_INLINE google_protobuf_DescriptorProto_ExtensionRange** google_protobuf_Desc } UPB_INLINE google_protobuf_DescriptorProto_ExtensionRange** google_protobuf_DescriptorProto_resize_extension_range(google_protobuf_DescriptorProto* msg, size_t size, upb_Arena* arena) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 5); - return (google_protobuf_DescriptorProto_ExtensionRange**)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); + return (google_protobuf_DescriptorProto_ExtensionRange**)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg), + &field, size, arena); } UPB_INLINE struct google_protobuf_DescriptorProto_ExtensionRange* google_protobuf_DescriptorProto_add_extension_range(google_protobuf_DescriptorProto* msg, upb_Arena* arena) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 5); - upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray( + UPB_UPCAST(msg), &field, arena); if (!arr || !_upb_Array_ResizeUninitialized( arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; @@ -1351,7 +1386,7 @@ UPB_INLINE struct google_protobuf_DescriptorProto_ExtensionRange* google_protobu } UPB_INLINE google_protobuf_FieldDescriptorProto** google_protobuf_DescriptorProto_mutable_extension(google_protobuf_DescriptorProto* msg, size_t* size) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 6); - upb_Array* arr = upb_Message_GetMutableArray(msg, &field); + upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_FieldDescriptorProto**)_upb_array_ptr(arr); @@ -1362,11 +1397,13 @@ UPB_INLINE google_protobuf_FieldDescriptorProto** google_protobuf_DescriptorProt } UPB_INLINE google_protobuf_FieldDescriptorProto** google_protobuf_DescriptorProto_resize_extension(google_protobuf_DescriptorProto* msg, size_t size, upb_Arena* arena) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 6); - return (google_protobuf_FieldDescriptorProto**)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); + return (google_protobuf_FieldDescriptorProto**)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg), + &field, size, arena); } UPB_INLINE struct google_protobuf_FieldDescriptorProto* google_protobuf_DescriptorProto_add_extension(google_protobuf_DescriptorProto* msg, upb_Arena* arena) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 6); - upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray( + UPB_UPCAST(msg), &field, arena); if (!arr || !_upb_Array_ResizeUninitialized( arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; @@ -1379,7 +1416,7 @@ UPB_INLINE struct google_protobuf_FieldDescriptorProto* google_protobuf_Descript } UPB_INLINE void google_protobuf_DescriptorProto_set_options(google_protobuf_DescriptorProto *msg, google_protobuf_MessageOptions* value) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 7); - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE struct google_protobuf_MessageOptions* google_protobuf_DescriptorProto_mutable_options(google_protobuf_DescriptorProto* msg, upb_Arena* arena) { struct google_protobuf_MessageOptions* sub = (struct google_protobuf_MessageOptions*)google_protobuf_DescriptorProto_options(msg); @@ -1391,7 +1428,7 @@ UPB_INLINE struct google_protobuf_MessageOptions* google_protobuf_DescriptorProt } UPB_INLINE google_protobuf_OneofDescriptorProto** google_protobuf_DescriptorProto_mutable_oneof_decl(google_protobuf_DescriptorProto* msg, size_t* size) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 8); - upb_Array* arr = upb_Message_GetMutableArray(msg, &field); + upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_OneofDescriptorProto**)_upb_array_ptr(arr); @@ -1402,11 +1439,13 @@ UPB_INLINE google_protobuf_OneofDescriptorProto** google_protobuf_DescriptorProt } UPB_INLINE google_protobuf_OneofDescriptorProto** google_protobuf_DescriptorProto_resize_oneof_decl(google_protobuf_DescriptorProto* msg, size_t size, upb_Arena* arena) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 8); - return (google_protobuf_OneofDescriptorProto**)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); + return (google_protobuf_OneofDescriptorProto**)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg), + &field, size, arena); } UPB_INLINE struct google_protobuf_OneofDescriptorProto* google_protobuf_DescriptorProto_add_oneof_decl(google_protobuf_DescriptorProto* msg, upb_Arena* arena) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 8); - upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray( + UPB_UPCAST(msg), &field, arena); if (!arr || !_upb_Array_ResizeUninitialized( arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; @@ -1419,7 +1458,7 @@ UPB_INLINE struct google_protobuf_OneofDescriptorProto* google_protobuf_Descript } UPB_INLINE google_protobuf_DescriptorProto_ReservedRange** google_protobuf_DescriptorProto_mutable_reserved_range(google_protobuf_DescriptorProto* msg, size_t* size) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 9); - upb_Array* arr = upb_Message_GetMutableArray(msg, &field); + upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_DescriptorProto_ReservedRange**)_upb_array_ptr(arr); @@ -1430,11 +1469,13 @@ UPB_INLINE google_protobuf_DescriptorProto_ReservedRange** google_protobuf_Descr } UPB_INLINE google_protobuf_DescriptorProto_ReservedRange** google_protobuf_DescriptorProto_resize_reserved_range(google_protobuf_DescriptorProto* msg, size_t size, upb_Arena* arena) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 9); - return (google_protobuf_DescriptorProto_ReservedRange**)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); + return (google_protobuf_DescriptorProto_ReservedRange**)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg), + &field, size, arena); } UPB_INLINE struct google_protobuf_DescriptorProto_ReservedRange* google_protobuf_DescriptorProto_add_reserved_range(google_protobuf_DescriptorProto* msg, upb_Arena* arena) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 9); - upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray( + UPB_UPCAST(msg), &field, arena); if (!arr || !_upb_Array_ResizeUninitialized( arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; @@ -1447,7 +1488,7 @@ UPB_INLINE struct google_protobuf_DescriptorProto_ReservedRange* google_protobuf } UPB_INLINE upb_StringView* google_protobuf_DescriptorProto_mutable_reserved_name(google_protobuf_DescriptorProto* msg, size_t* size) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 10); - upb_Array* arr = upb_Message_GetMutableArray(msg, &field); + upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (upb_StringView*)_upb_array_ptr(arr); @@ -1458,11 +1499,13 @@ UPB_INLINE upb_StringView* google_protobuf_DescriptorProto_mutable_reserved_name } UPB_INLINE upb_StringView* google_protobuf_DescriptorProto_resize_reserved_name(google_protobuf_DescriptorProto* msg, size_t size, upb_Arena* arena) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 10); - return (upb_StringView*)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); + return (upb_StringView*)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg), + &field, size, arena); } UPB_INLINE bool google_protobuf_DescriptorProto_add_reserved_name(google_protobuf_DescriptorProto* msg, upb_StringView val, upb_Arena* arena) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 10); - upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray( + UPB_UPCAST(msg), &field, arena); if (!arr || !_upb_Array_ResizeUninitialized( arr, arr->UPB_PRIVATE(size) + 1, arena)) { return false; @@ -1480,7 +1523,8 @@ UPB_INLINE google_protobuf_DescriptorProto_ExtensionRange* google_protobuf_Descr UPB_INLINE google_protobuf_DescriptorProto_ExtensionRange* google_protobuf_DescriptorProto_ExtensionRange_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_DescriptorProto_ExtensionRange* ret = google_protobuf_DescriptorProto_ExtensionRange_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, google__protobuf__DescriptorProto__ExtensionRange_msg_init(), NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), google__protobuf__DescriptorProto__ExtensionRange_msg_init(), NULL, 0, arena) != + kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -1490,80 +1534,83 @@ UPB_INLINE google_protobuf_DescriptorProto_ExtensionRange* google_protobuf_Descr int options, upb_Arena* arena) { google_protobuf_DescriptorProto_ExtensionRange* ret = google_protobuf_DescriptorProto_ExtensionRange_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, google__protobuf__DescriptorProto__ExtensionRange_msg_init(), extreg, options, arena) != - kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), google__protobuf__DescriptorProto__ExtensionRange_msg_init(), extreg, options, + arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_DescriptorProto_ExtensionRange_serialize(const google_protobuf_DescriptorProto_ExtensionRange* msg, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, google__protobuf__DescriptorProto__ExtensionRange_msg_init(), 0, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), google__protobuf__DescriptorProto__ExtensionRange_msg_init(), 0, arena, &ptr, len); return ptr; } UPB_INLINE char* google_protobuf_DescriptorProto_ExtensionRange_serialize_ex(const google_protobuf_DescriptorProto_ExtensionRange* msg, int options, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, google__protobuf__DescriptorProto__ExtensionRange_msg_init(), options, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), google__protobuf__DescriptorProto__ExtensionRange_msg_init(), options, arena, &ptr, len); return ptr; } UPB_INLINE void google_protobuf_DescriptorProto_ExtensionRange_clear_start(google_protobuf_DescriptorProto_ExtensionRange* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto__ExtensionRange_msg_init(), 1); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_DescriptorProto_ExtensionRange_start(const google_protobuf_DescriptorProto_ExtensionRange* msg) { int32_t default_val = (int32_t)0; int32_t ret; const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto__ExtensionRange_msg_init(), 1); - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_DescriptorProto_ExtensionRange_has_start(const google_protobuf_DescriptorProto_ExtensionRange* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto__ExtensionRange_msg_init(), 1); - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_DescriptorProto_ExtensionRange_clear_end(google_protobuf_DescriptorProto_ExtensionRange* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto__ExtensionRange_msg_init(), 2); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_DescriptorProto_ExtensionRange_end(const google_protobuf_DescriptorProto_ExtensionRange* msg) { int32_t default_val = (int32_t)0; int32_t ret; const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto__ExtensionRange_msg_init(), 2); - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_DescriptorProto_ExtensionRange_has_end(const google_protobuf_DescriptorProto_ExtensionRange* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto__ExtensionRange_msg_init(), 2); - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_DescriptorProto_ExtensionRange_clear_options(google_protobuf_DescriptorProto_ExtensionRange* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto__ExtensionRange_msg_init(), 3); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_ExtensionRangeOptions* google_protobuf_DescriptorProto_ExtensionRange_options(const google_protobuf_DescriptorProto_ExtensionRange* msg) { const google_protobuf_ExtensionRangeOptions* default_val = NULL; const google_protobuf_ExtensionRangeOptions* ret; const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto__ExtensionRange_msg_init(), 3); - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_DescriptorProto_ExtensionRange_has_options(const google_protobuf_DescriptorProto_ExtensionRange* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto__ExtensionRange_msg_init(), 3); - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_DescriptorProto_ExtensionRange_set_start(google_protobuf_DescriptorProto_ExtensionRange *msg, int32_t value) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto__ExtensionRange_msg_init(), 1); - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_DescriptorProto_ExtensionRange_set_end(google_protobuf_DescriptorProto_ExtensionRange *msg, int32_t value) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto__ExtensionRange_msg_init(), 2); - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_DescriptorProto_ExtensionRange_set_options(google_protobuf_DescriptorProto_ExtensionRange *msg, google_protobuf_ExtensionRangeOptions* value) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto__ExtensionRange_msg_init(), 3); - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE struct google_protobuf_ExtensionRangeOptions* google_protobuf_DescriptorProto_ExtensionRange_mutable_options(google_protobuf_DescriptorProto_ExtensionRange* msg, upb_Arena* arena) { struct google_protobuf_ExtensionRangeOptions* sub = (struct google_protobuf_ExtensionRangeOptions*)google_protobuf_DescriptorProto_ExtensionRange_options(msg); @@ -1582,7 +1629,8 @@ UPB_INLINE google_protobuf_DescriptorProto_ReservedRange* google_protobuf_Descri UPB_INLINE google_protobuf_DescriptorProto_ReservedRange* google_protobuf_DescriptorProto_ReservedRange_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_DescriptorProto_ReservedRange* ret = google_protobuf_DescriptorProto_ReservedRange_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, google__protobuf__DescriptorProto__ReservedRange_msg_init(), NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), google__protobuf__DescriptorProto__ReservedRange_msg_init(), NULL, 0, arena) != + kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -1592,61 +1640,63 @@ UPB_INLINE google_protobuf_DescriptorProto_ReservedRange* google_protobuf_Descri int options, upb_Arena* arena) { google_protobuf_DescriptorProto_ReservedRange* ret = google_protobuf_DescriptorProto_ReservedRange_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, google__protobuf__DescriptorProto__ReservedRange_msg_init(), extreg, options, arena) != - kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), google__protobuf__DescriptorProto__ReservedRange_msg_init(), extreg, options, + arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_DescriptorProto_ReservedRange_serialize(const google_protobuf_DescriptorProto_ReservedRange* msg, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, google__protobuf__DescriptorProto__ReservedRange_msg_init(), 0, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), google__protobuf__DescriptorProto__ReservedRange_msg_init(), 0, arena, &ptr, len); return ptr; } UPB_INLINE char* google_protobuf_DescriptorProto_ReservedRange_serialize_ex(const google_protobuf_DescriptorProto_ReservedRange* msg, int options, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, google__protobuf__DescriptorProto__ReservedRange_msg_init(), options, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), google__protobuf__DescriptorProto__ReservedRange_msg_init(), options, arena, &ptr, len); return ptr; } UPB_INLINE void google_protobuf_DescriptorProto_ReservedRange_clear_start(google_protobuf_DescriptorProto_ReservedRange* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto__ReservedRange_msg_init(), 1); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_DescriptorProto_ReservedRange_start(const google_protobuf_DescriptorProto_ReservedRange* msg) { int32_t default_val = (int32_t)0; int32_t ret; const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto__ReservedRange_msg_init(), 1); - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_DescriptorProto_ReservedRange_has_start(const google_protobuf_DescriptorProto_ReservedRange* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto__ReservedRange_msg_init(), 1); - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_DescriptorProto_ReservedRange_clear_end(google_protobuf_DescriptorProto_ReservedRange* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto__ReservedRange_msg_init(), 2); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_DescriptorProto_ReservedRange_end(const google_protobuf_DescriptorProto_ReservedRange* msg) { int32_t default_val = (int32_t)0; int32_t ret; const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto__ReservedRange_msg_init(), 2); - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_DescriptorProto_ReservedRange_has_end(const google_protobuf_DescriptorProto_ReservedRange* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto__ReservedRange_msg_init(), 2); - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_DescriptorProto_ReservedRange_set_start(google_protobuf_DescriptorProto_ReservedRange *msg, int32_t value) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto__ReservedRange_msg_init(), 1); - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_DescriptorProto_ReservedRange_set_end(google_protobuf_DescriptorProto_ReservedRange *msg, int32_t value) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto__ReservedRange_msg_init(), 2); - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } /* google.protobuf.ExtensionRangeOptions */ @@ -1657,7 +1707,8 @@ UPB_INLINE google_protobuf_ExtensionRangeOptions* google_protobuf_ExtensionRange UPB_INLINE google_protobuf_ExtensionRangeOptions* google_protobuf_ExtensionRangeOptions_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_ExtensionRangeOptions* ret = google_protobuf_ExtensionRangeOptions_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, google__protobuf__ExtensionRangeOptions_msg_init(), NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), google__protobuf__ExtensionRangeOptions_msg_init(), NULL, 0, arena) != + kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -1667,30 +1718,30 @@ UPB_INLINE google_protobuf_ExtensionRangeOptions* google_protobuf_ExtensionRange int options, upb_Arena* arena) { google_protobuf_ExtensionRangeOptions* ret = google_protobuf_ExtensionRangeOptions_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, google__protobuf__ExtensionRangeOptions_msg_init(), extreg, options, arena) != - kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), google__protobuf__ExtensionRangeOptions_msg_init(), extreg, options, + arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_ExtensionRangeOptions_serialize(const google_protobuf_ExtensionRangeOptions* msg, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, google__protobuf__ExtensionRangeOptions_msg_init(), 0, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), google__protobuf__ExtensionRangeOptions_msg_init(), 0, arena, &ptr, len); return ptr; } UPB_INLINE char* google_protobuf_ExtensionRangeOptions_serialize_ex(const google_protobuf_ExtensionRangeOptions* msg, int options, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, google__protobuf__ExtensionRangeOptions_msg_init(), options, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), google__protobuf__ExtensionRangeOptions_msg_init(), options, arena, &ptr, len); return ptr; } UPB_INLINE void google_protobuf_ExtensionRangeOptions_clear_declaration(google_protobuf_ExtensionRangeOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ExtensionRangeOptions_msg_init(), 2); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_ExtensionRangeOptions_Declaration* const* google_protobuf_ExtensionRangeOptions_declaration(const google_protobuf_ExtensionRangeOptions* msg, size_t* size) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ExtensionRangeOptions_msg_init(), 2); - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_ExtensionRangeOptions_Declaration* const*)_upb_array_constptr(arr); @@ -1701,16 +1752,16 @@ UPB_INLINE const google_protobuf_ExtensionRangeOptions_Declaration* const* googl } UPB_INLINE const upb_Array* _google_protobuf_ExtensionRangeOptions_declaration_upb_array(const google_protobuf_ExtensionRangeOptions* msg, size_t* size) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ExtensionRangeOptions_msg_init(), 2); - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } -UPB_INLINE upb_Array* _google_protobuf_ExtensionRangeOptions_declaration_mutable_upb_array(const google_protobuf_ExtensionRangeOptions* msg, size_t* size, upb_Arena* arena) { +UPB_INLINE upb_Array* _google_protobuf_ExtensionRangeOptions_declaration_mutable_upb_array(google_protobuf_ExtensionRangeOptions* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ExtensionRangeOptions_msg_init(), 2); upb_Array* arr = upb_Message_GetOrCreateMutableArray( - (upb_Message*)msg, &field, arena); + UPB_UPCAST(msg), &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -1718,41 +1769,43 @@ UPB_INLINE upb_Array* _google_protobuf_ExtensionRangeOptions_declaration_mutable } UPB_INLINE void google_protobuf_ExtensionRangeOptions_clear_verification(google_protobuf_ExtensionRangeOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ExtensionRangeOptions_msg_init(), 3); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_ExtensionRangeOptions_verification(const google_protobuf_ExtensionRangeOptions* msg) { int32_t default_val = 1; int32_t ret; const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ExtensionRangeOptions_msg_init(), 3); - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_ExtensionRangeOptions_has_verification(const google_protobuf_ExtensionRangeOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ExtensionRangeOptions_msg_init(), 3); - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_ExtensionRangeOptions_clear_features(google_protobuf_ExtensionRangeOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ExtensionRangeOptions_msg_init(), 50); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_FeatureSet* google_protobuf_ExtensionRangeOptions_features(const google_protobuf_ExtensionRangeOptions* msg) { const google_protobuf_FeatureSet* default_val = NULL; const google_protobuf_FeatureSet* ret; const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ExtensionRangeOptions_msg_init(), 50); - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_ExtensionRangeOptions_has_features(const google_protobuf_ExtensionRangeOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ExtensionRangeOptions_msg_init(), 50); - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_ExtensionRangeOptions_clear_uninterpreted_option(google_protobuf_ExtensionRangeOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ExtensionRangeOptions_msg_init(), 999); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_ExtensionRangeOptions_uninterpreted_option(const google_protobuf_ExtensionRangeOptions* msg, size_t* size) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ExtensionRangeOptions_msg_init(), 999); - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_UninterpretedOption* const*)_upb_array_constptr(arr); @@ -1763,16 +1816,16 @@ UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_Ext } UPB_INLINE const upb_Array* _google_protobuf_ExtensionRangeOptions_uninterpreted_option_upb_array(const google_protobuf_ExtensionRangeOptions* msg, size_t* size) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ExtensionRangeOptions_msg_init(), 999); - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } -UPB_INLINE upb_Array* _google_protobuf_ExtensionRangeOptions_uninterpreted_option_mutable_upb_array(const google_protobuf_ExtensionRangeOptions* msg, size_t* size, upb_Arena* arena) { +UPB_INLINE upb_Array* _google_protobuf_ExtensionRangeOptions_uninterpreted_option_mutable_upb_array(google_protobuf_ExtensionRangeOptions* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ExtensionRangeOptions_msg_init(), 999); upb_Array* arr = upb_Message_GetOrCreateMutableArray( - (upb_Message*)msg, &field, arena); + UPB_UPCAST(msg), &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -1781,7 +1834,7 @@ UPB_INLINE upb_Array* _google_protobuf_ExtensionRangeOptions_uninterpreted_optio UPB_INLINE google_protobuf_ExtensionRangeOptions_Declaration** google_protobuf_ExtensionRangeOptions_mutable_declaration(google_protobuf_ExtensionRangeOptions* msg, size_t* size) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ExtensionRangeOptions_msg_init(), 2); - upb_Array* arr = upb_Message_GetMutableArray(msg, &field); + upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_ExtensionRangeOptions_Declaration**)_upb_array_ptr(arr); @@ -1792,11 +1845,13 @@ UPB_INLINE google_protobuf_ExtensionRangeOptions_Declaration** google_protobuf_E } UPB_INLINE google_protobuf_ExtensionRangeOptions_Declaration** google_protobuf_ExtensionRangeOptions_resize_declaration(google_protobuf_ExtensionRangeOptions* msg, size_t size, upb_Arena* arena) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ExtensionRangeOptions_msg_init(), 2); - return (google_protobuf_ExtensionRangeOptions_Declaration**)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); + return (google_protobuf_ExtensionRangeOptions_Declaration**)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg), + &field, size, arena); } UPB_INLINE struct google_protobuf_ExtensionRangeOptions_Declaration* google_protobuf_ExtensionRangeOptions_add_declaration(google_protobuf_ExtensionRangeOptions* msg, upb_Arena* arena) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ExtensionRangeOptions_msg_init(), 2); - upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray( + UPB_UPCAST(msg), &field, arena); if (!arr || !_upb_Array_ResizeUninitialized( arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; @@ -1809,11 +1864,11 @@ UPB_INLINE struct google_protobuf_ExtensionRangeOptions_Declaration* google_prot } UPB_INLINE void google_protobuf_ExtensionRangeOptions_set_verification(google_protobuf_ExtensionRangeOptions *msg, int32_t value) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ExtensionRangeOptions_msg_init(), 3); - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_ExtensionRangeOptions_set_features(google_protobuf_ExtensionRangeOptions *msg, google_protobuf_FeatureSet* value) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ExtensionRangeOptions_msg_init(), 50); - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE struct google_protobuf_FeatureSet* google_protobuf_ExtensionRangeOptions_mutable_features(google_protobuf_ExtensionRangeOptions* msg, upb_Arena* arena) { struct google_protobuf_FeatureSet* sub = (struct google_protobuf_FeatureSet*)google_protobuf_ExtensionRangeOptions_features(msg); @@ -1825,7 +1880,7 @@ UPB_INLINE struct google_protobuf_FeatureSet* google_protobuf_ExtensionRangeOpti } UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_ExtensionRangeOptions_mutable_uninterpreted_option(google_protobuf_ExtensionRangeOptions* msg, size_t* size) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ExtensionRangeOptions_msg_init(), 999); - upb_Array* arr = upb_Message_GetMutableArray(msg, &field); + upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_UninterpretedOption**)_upb_array_ptr(arr); @@ -1836,11 +1891,13 @@ UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_ExtensionRangeO } UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_ExtensionRangeOptions_resize_uninterpreted_option(google_protobuf_ExtensionRangeOptions* msg, size_t size, upb_Arena* arena) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ExtensionRangeOptions_msg_init(), 999); - return (google_protobuf_UninterpretedOption**)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); + return (google_protobuf_UninterpretedOption**)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg), + &field, size, arena); } UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_ExtensionRangeOptions_add_uninterpreted_option(google_protobuf_ExtensionRangeOptions* msg, upb_Arena* arena) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ExtensionRangeOptions_msg_init(), 999); - upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray( + UPB_UPCAST(msg), &field, arena); if (!arr || !_upb_Array_ResizeUninitialized( arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; @@ -1860,7 +1917,8 @@ UPB_INLINE google_protobuf_ExtensionRangeOptions_Declaration* google_protobuf_Ex UPB_INLINE google_protobuf_ExtensionRangeOptions_Declaration* google_protobuf_ExtensionRangeOptions_Declaration_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_ExtensionRangeOptions_Declaration* ret = google_protobuf_ExtensionRangeOptions_Declaration_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, google__protobuf__ExtensionRangeOptions__Declaration_msg_init(), NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), google__protobuf__ExtensionRangeOptions__Declaration_msg_init(), NULL, 0, arena) != + kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -1870,118 +1928,123 @@ UPB_INLINE google_protobuf_ExtensionRangeOptions_Declaration* google_protobuf_Ex int options, upb_Arena* arena) { google_protobuf_ExtensionRangeOptions_Declaration* ret = google_protobuf_ExtensionRangeOptions_Declaration_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, google__protobuf__ExtensionRangeOptions__Declaration_msg_init(), extreg, options, arena) != - kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), google__protobuf__ExtensionRangeOptions__Declaration_msg_init(), extreg, options, + arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_ExtensionRangeOptions_Declaration_serialize(const google_protobuf_ExtensionRangeOptions_Declaration* msg, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, google__protobuf__ExtensionRangeOptions__Declaration_msg_init(), 0, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), google__protobuf__ExtensionRangeOptions__Declaration_msg_init(), 0, arena, &ptr, len); return ptr; } UPB_INLINE char* google_protobuf_ExtensionRangeOptions_Declaration_serialize_ex(const google_protobuf_ExtensionRangeOptions_Declaration* msg, int options, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, google__protobuf__ExtensionRangeOptions__Declaration_msg_init(), options, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), google__protobuf__ExtensionRangeOptions__Declaration_msg_init(), options, arena, &ptr, len); return ptr; } UPB_INLINE void google_protobuf_ExtensionRangeOptions_Declaration_clear_number(google_protobuf_ExtensionRangeOptions_Declaration* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ExtensionRangeOptions__Declaration_msg_init(), 1); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_ExtensionRangeOptions_Declaration_number(const google_protobuf_ExtensionRangeOptions_Declaration* msg) { int32_t default_val = (int32_t)0; int32_t ret; const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ExtensionRangeOptions__Declaration_msg_init(), 1); - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_ExtensionRangeOptions_Declaration_has_number(const google_protobuf_ExtensionRangeOptions_Declaration* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ExtensionRangeOptions__Declaration_msg_init(), 1); - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_ExtensionRangeOptions_Declaration_clear_full_name(google_protobuf_ExtensionRangeOptions_Declaration* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ExtensionRangeOptions__Declaration_msg_init(), 2); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_ExtensionRangeOptions_Declaration_full_name(const google_protobuf_ExtensionRangeOptions_Declaration* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ExtensionRangeOptions__Declaration_msg_init(), 2); - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_ExtensionRangeOptions_Declaration_has_full_name(const google_protobuf_ExtensionRangeOptions_Declaration* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ExtensionRangeOptions__Declaration_msg_init(), 2); - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_ExtensionRangeOptions_Declaration_clear_type(google_protobuf_ExtensionRangeOptions_Declaration* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ExtensionRangeOptions__Declaration_msg_init(), 3); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_ExtensionRangeOptions_Declaration_type(const google_protobuf_ExtensionRangeOptions_Declaration* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ExtensionRangeOptions__Declaration_msg_init(), 3); - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_ExtensionRangeOptions_Declaration_has_type(const google_protobuf_ExtensionRangeOptions_Declaration* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ExtensionRangeOptions__Declaration_msg_init(), 3); - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_ExtensionRangeOptions_Declaration_clear_reserved(google_protobuf_ExtensionRangeOptions_Declaration* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ExtensionRangeOptions__Declaration_msg_init(), 5); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_ExtensionRangeOptions_Declaration_reserved(const google_protobuf_ExtensionRangeOptions_Declaration* msg) { bool default_val = false; bool ret; const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ExtensionRangeOptions__Declaration_msg_init(), 5); - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_ExtensionRangeOptions_Declaration_has_reserved(const google_protobuf_ExtensionRangeOptions_Declaration* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ExtensionRangeOptions__Declaration_msg_init(), 5); - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_ExtensionRangeOptions_Declaration_clear_repeated(google_protobuf_ExtensionRangeOptions_Declaration* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ExtensionRangeOptions__Declaration_msg_init(), 6); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_ExtensionRangeOptions_Declaration_repeated(const google_protobuf_ExtensionRangeOptions_Declaration* msg) { bool default_val = false; bool ret; const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ExtensionRangeOptions__Declaration_msg_init(), 6); - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_ExtensionRangeOptions_Declaration_has_repeated(const google_protobuf_ExtensionRangeOptions_Declaration* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ExtensionRangeOptions__Declaration_msg_init(), 6); - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_ExtensionRangeOptions_Declaration_set_number(google_protobuf_ExtensionRangeOptions_Declaration *msg, int32_t value) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ExtensionRangeOptions__Declaration_msg_init(), 1); - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_ExtensionRangeOptions_Declaration_set_full_name(google_protobuf_ExtensionRangeOptions_Declaration *msg, upb_StringView value) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ExtensionRangeOptions__Declaration_msg_init(), 2); - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_ExtensionRangeOptions_Declaration_set_type(google_protobuf_ExtensionRangeOptions_Declaration *msg, upb_StringView value) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ExtensionRangeOptions__Declaration_msg_init(), 3); - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_ExtensionRangeOptions_Declaration_set_reserved(google_protobuf_ExtensionRangeOptions_Declaration *msg, bool value) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ExtensionRangeOptions__Declaration_msg_init(), 5); - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_ExtensionRangeOptions_Declaration_set_repeated(google_protobuf_ExtensionRangeOptions_Declaration *msg, bool value) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ExtensionRangeOptions__Declaration_msg_init(), 6); - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } /* google.protobuf.FieldDescriptorProto */ @@ -1992,7 +2055,8 @@ UPB_INLINE google_protobuf_FieldDescriptorProto* google_protobuf_FieldDescriptor UPB_INLINE google_protobuf_FieldDescriptorProto* google_protobuf_FieldDescriptorProto_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_FieldDescriptorProto* ret = google_protobuf_FieldDescriptorProto_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, google__protobuf__FieldDescriptorProto_msg_init(), NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), google__protobuf__FieldDescriptorProto_msg_init(), NULL, 0, arena) != + kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -2002,220 +2066,231 @@ UPB_INLINE google_protobuf_FieldDescriptorProto* google_protobuf_FieldDescriptor int options, upb_Arena* arena) { google_protobuf_FieldDescriptorProto* ret = google_protobuf_FieldDescriptorProto_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, google__protobuf__FieldDescriptorProto_msg_init(), extreg, options, arena) != - kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), google__protobuf__FieldDescriptorProto_msg_init(), extreg, options, + arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_FieldDescriptorProto_serialize(const google_protobuf_FieldDescriptorProto* msg, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, google__protobuf__FieldDescriptorProto_msg_init(), 0, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), google__protobuf__FieldDescriptorProto_msg_init(), 0, arena, &ptr, len); return ptr; } UPB_INLINE char* google_protobuf_FieldDescriptorProto_serialize_ex(const google_protobuf_FieldDescriptorProto* msg, int options, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, google__protobuf__FieldDescriptorProto_msg_init(), options, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), google__protobuf__FieldDescriptorProto_msg_init(), options, arena, &ptr, len); return ptr; } UPB_INLINE void google_protobuf_FieldDescriptorProto_clear_name(google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldDescriptorProto_msg_init(), 1); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_FieldDescriptorProto_name(const google_protobuf_FieldDescriptorProto* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldDescriptorProto_msg_init(), 1); - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_name(const google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldDescriptorProto_msg_init(), 1); - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldDescriptorProto_clear_extendee(google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldDescriptorProto_msg_init(), 2); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_FieldDescriptorProto_extendee(const google_protobuf_FieldDescriptorProto* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldDescriptorProto_msg_init(), 2); - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_extendee(const google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldDescriptorProto_msg_init(), 2); - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldDescriptorProto_clear_number(google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldDescriptorProto_msg_init(), 3); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_FieldDescriptorProto_number(const google_protobuf_FieldDescriptorProto* msg) { int32_t default_val = (int32_t)0; int32_t ret; const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldDescriptorProto_msg_init(), 3); - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_number(const google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldDescriptorProto_msg_init(), 3); - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldDescriptorProto_clear_label(google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldDescriptorProto_msg_init(), 4); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_FieldDescriptorProto_label(const google_protobuf_FieldDescriptorProto* msg) { int32_t default_val = 1; int32_t ret; const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldDescriptorProto_msg_init(), 4); - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_label(const google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldDescriptorProto_msg_init(), 4); - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldDescriptorProto_clear_type(google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldDescriptorProto_msg_init(), 5); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_FieldDescriptorProto_type(const google_protobuf_FieldDescriptorProto* msg) { int32_t default_val = 1; int32_t ret; const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldDescriptorProto_msg_init(), 5); - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_type(const google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldDescriptorProto_msg_init(), 5); - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldDescriptorProto_clear_type_name(google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldDescriptorProto_msg_init(), 6); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_FieldDescriptorProto_type_name(const google_protobuf_FieldDescriptorProto* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldDescriptorProto_msg_init(), 6); - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_type_name(const google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldDescriptorProto_msg_init(), 6); - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldDescriptorProto_clear_default_value(google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldDescriptorProto_msg_init(), 7); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_FieldDescriptorProto_default_value(const google_protobuf_FieldDescriptorProto* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldDescriptorProto_msg_init(), 7); - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_default_value(const google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldDescriptorProto_msg_init(), 7); - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldDescriptorProto_clear_options(google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldDescriptorProto_msg_init(), 8); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_FieldOptions* google_protobuf_FieldDescriptorProto_options(const google_protobuf_FieldDescriptorProto* msg) { const google_protobuf_FieldOptions* default_val = NULL; const google_protobuf_FieldOptions* ret; const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldDescriptorProto_msg_init(), 8); - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_options(const google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldDescriptorProto_msg_init(), 8); - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldDescriptorProto_clear_oneof_index(google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldDescriptorProto_msg_init(), 9); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_FieldDescriptorProto_oneof_index(const google_protobuf_FieldDescriptorProto* msg) { int32_t default_val = (int32_t)0; int32_t ret; const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldDescriptorProto_msg_init(), 9); - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_oneof_index(const google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldDescriptorProto_msg_init(), 9); - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldDescriptorProto_clear_json_name(google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldDescriptorProto_msg_init(), 10); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_FieldDescriptorProto_json_name(const google_protobuf_FieldDescriptorProto* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldDescriptorProto_msg_init(), 10); - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_json_name(const google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldDescriptorProto_msg_init(), 10); - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldDescriptorProto_clear_proto3_optional(google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldDescriptorProto_msg_init(), 17); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_FieldDescriptorProto_proto3_optional(const google_protobuf_FieldDescriptorProto* msg) { bool default_val = false; bool ret; const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldDescriptorProto_msg_init(), 17); - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_proto3_optional(const google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldDescriptorProto_msg_init(), 17); - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldDescriptorProto_set_name(google_protobuf_FieldDescriptorProto *msg, upb_StringView value) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldDescriptorProto_msg_init(), 1); - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FieldDescriptorProto_set_extendee(google_protobuf_FieldDescriptorProto *msg, upb_StringView value) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldDescriptorProto_msg_init(), 2); - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FieldDescriptorProto_set_number(google_protobuf_FieldDescriptorProto *msg, int32_t value) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldDescriptorProto_msg_init(), 3); - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FieldDescriptorProto_set_label(google_protobuf_FieldDescriptorProto *msg, int32_t value) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldDescriptorProto_msg_init(), 4); - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FieldDescriptorProto_set_type(google_protobuf_FieldDescriptorProto *msg, int32_t value) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldDescriptorProto_msg_init(), 5); - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FieldDescriptorProto_set_type_name(google_protobuf_FieldDescriptorProto *msg, upb_StringView value) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldDescriptorProto_msg_init(), 6); - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FieldDescriptorProto_set_default_value(google_protobuf_FieldDescriptorProto *msg, upb_StringView value) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldDescriptorProto_msg_init(), 7); - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FieldDescriptorProto_set_options(google_protobuf_FieldDescriptorProto *msg, google_protobuf_FieldOptions* value) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldDescriptorProto_msg_init(), 8); - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE struct google_protobuf_FieldOptions* google_protobuf_FieldDescriptorProto_mutable_options(google_protobuf_FieldDescriptorProto* msg, upb_Arena* arena) { struct google_protobuf_FieldOptions* sub = (struct google_protobuf_FieldOptions*)google_protobuf_FieldDescriptorProto_options(msg); @@ -2227,15 +2302,15 @@ UPB_INLINE struct google_protobuf_FieldOptions* google_protobuf_FieldDescriptorP } UPB_INLINE void google_protobuf_FieldDescriptorProto_set_oneof_index(google_protobuf_FieldDescriptorProto *msg, int32_t value) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldDescriptorProto_msg_init(), 9); - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FieldDescriptorProto_set_json_name(google_protobuf_FieldDescriptorProto *msg, upb_StringView value) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldDescriptorProto_msg_init(), 10); - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FieldDescriptorProto_set_proto3_optional(google_protobuf_FieldDescriptorProto *msg, bool value) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldDescriptorProto_msg_init(), 17); - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } /* google.protobuf.OneofDescriptorProto */ @@ -2246,7 +2321,8 @@ UPB_INLINE google_protobuf_OneofDescriptorProto* google_protobuf_OneofDescriptor UPB_INLINE google_protobuf_OneofDescriptorProto* google_protobuf_OneofDescriptorProto_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_OneofDescriptorProto* ret = google_protobuf_OneofDescriptorProto_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, google__protobuf__OneofDescriptorProto_msg_init(), NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), google__protobuf__OneofDescriptorProto_msg_init(), NULL, 0, arena) != + kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -2256,61 +2332,63 @@ UPB_INLINE google_protobuf_OneofDescriptorProto* google_protobuf_OneofDescriptor int options, upb_Arena* arena) { google_protobuf_OneofDescriptorProto* ret = google_protobuf_OneofDescriptorProto_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, google__protobuf__OneofDescriptorProto_msg_init(), extreg, options, arena) != - kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), google__protobuf__OneofDescriptorProto_msg_init(), extreg, options, + arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_OneofDescriptorProto_serialize(const google_protobuf_OneofDescriptorProto* msg, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, google__protobuf__OneofDescriptorProto_msg_init(), 0, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), google__protobuf__OneofDescriptorProto_msg_init(), 0, arena, &ptr, len); return ptr; } UPB_INLINE char* google_protobuf_OneofDescriptorProto_serialize_ex(const google_protobuf_OneofDescriptorProto* msg, int options, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, google__protobuf__OneofDescriptorProto_msg_init(), options, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), google__protobuf__OneofDescriptorProto_msg_init(), options, arena, &ptr, len); return ptr; } UPB_INLINE void google_protobuf_OneofDescriptorProto_clear_name(google_protobuf_OneofDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__OneofDescriptorProto_msg_init(), 1); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_OneofDescriptorProto_name(const google_protobuf_OneofDescriptorProto* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__OneofDescriptorProto_msg_init(), 1); - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_OneofDescriptorProto_has_name(const google_protobuf_OneofDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__OneofDescriptorProto_msg_init(), 1); - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_OneofDescriptorProto_clear_options(google_protobuf_OneofDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__OneofDescriptorProto_msg_init(), 2); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_OneofOptions* google_protobuf_OneofDescriptorProto_options(const google_protobuf_OneofDescriptorProto* msg) { const google_protobuf_OneofOptions* default_val = NULL; const google_protobuf_OneofOptions* ret; const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__OneofDescriptorProto_msg_init(), 2); - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_OneofDescriptorProto_has_options(const google_protobuf_OneofDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__OneofDescriptorProto_msg_init(), 2); - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_OneofDescriptorProto_set_name(google_protobuf_OneofDescriptorProto *msg, upb_StringView value) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__OneofDescriptorProto_msg_init(), 1); - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_OneofDescriptorProto_set_options(google_protobuf_OneofDescriptorProto *msg, google_protobuf_OneofOptions* value) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__OneofDescriptorProto_msg_init(), 2); - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE struct google_protobuf_OneofOptions* google_protobuf_OneofDescriptorProto_mutable_options(google_protobuf_OneofDescriptorProto* msg, upb_Arena* arena) { struct google_protobuf_OneofOptions* sub = (struct google_protobuf_OneofOptions*)google_protobuf_OneofDescriptorProto_options(msg); @@ -2329,7 +2407,8 @@ UPB_INLINE google_protobuf_EnumDescriptorProto* google_protobuf_EnumDescriptorPr UPB_INLINE google_protobuf_EnumDescriptorProto* google_protobuf_EnumDescriptorProto_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_EnumDescriptorProto* ret = google_protobuf_EnumDescriptorProto_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, google__protobuf__EnumDescriptorProto_msg_init(), NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), google__protobuf__EnumDescriptorProto_msg_init(), NULL, 0, arena) != + kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -2339,45 +2418,46 @@ UPB_INLINE google_protobuf_EnumDescriptorProto* google_protobuf_EnumDescriptorPr int options, upb_Arena* arena) { google_protobuf_EnumDescriptorProto* ret = google_protobuf_EnumDescriptorProto_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, google__protobuf__EnumDescriptorProto_msg_init(), extreg, options, arena) != - kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), google__protobuf__EnumDescriptorProto_msg_init(), extreg, options, + arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_EnumDescriptorProto_serialize(const google_protobuf_EnumDescriptorProto* msg, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, google__protobuf__EnumDescriptorProto_msg_init(), 0, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), google__protobuf__EnumDescriptorProto_msg_init(), 0, arena, &ptr, len); return ptr; } UPB_INLINE char* google_protobuf_EnumDescriptorProto_serialize_ex(const google_protobuf_EnumDescriptorProto* msg, int options, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, google__protobuf__EnumDescriptorProto_msg_init(), options, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), google__protobuf__EnumDescriptorProto_msg_init(), options, arena, &ptr, len); return ptr; } UPB_INLINE void google_protobuf_EnumDescriptorProto_clear_name(google_protobuf_EnumDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumDescriptorProto_msg_init(), 1); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_EnumDescriptorProto_name(const google_protobuf_EnumDescriptorProto* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumDescriptorProto_msg_init(), 1); - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_EnumDescriptorProto_has_name(const google_protobuf_EnumDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumDescriptorProto_msg_init(), 1); - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_EnumDescriptorProto_clear_value(google_protobuf_EnumDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumDescriptorProto_msg_init(), 2); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_EnumValueDescriptorProto* const* google_protobuf_EnumDescriptorProto_value(const google_protobuf_EnumDescriptorProto* msg, size_t* size) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumDescriptorProto_msg_init(), 2); - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_EnumValueDescriptorProto* const*)_upb_array_constptr(arr); @@ -2388,16 +2468,16 @@ UPB_INLINE const google_protobuf_EnumValueDescriptorProto* const* google_protobu } UPB_INLINE const upb_Array* _google_protobuf_EnumDescriptorProto_value_upb_array(const google_protobuf_EnumDescriptorProto* msg, size_t* size) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumDescriptorProto_msg_init(), 2); - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } -UPB_INLINE upb_Array* _google_protobuf_EnumDescriptorProto_value_mutable_upb_array(const google_protobuf_EnumDescriptorProto* msg, size_t* size, upb_Arena* arena) { +UPB_INLINE upb_Array* _google_protobuf_EnumDescriptorProto_value_mutable_upb_array(google_protobuf_EnumDescriptorProto* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumDescriptorProto_msg_init(), 2); upb_Array* arr = upb_Message_GetOrCreateMutableArray( - (upb_Message*)msg, &field, arena); + UPB_UPCAST(msg), &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -2405,26 +2485,27 @@ UPB_INLINE upb_Array* _google_protobuf_EnumDescriptorProto_value_mutable_upb_arr } UPB_INLINE void google_protobuf_EnumDescriptorProto_clear_options(google_protobuf_EnumDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumDescriptorProto_msg_init(), 3); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_EnumOptions* google_protobuf_EnumDescriptorProto_options(const google_protobuf_EnumDescriptorProto* msg) { const google_protobuf_EnumOptions* default_val = NULL; const google_protobuf_EnumOptions* ret; const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumDescriptorProto_msg_init(), 3); - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_EnumDescriptorProto_has_options(const google_protobuf_EnumDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumDescriptorProto_msg_init(), 3); - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_EnumDescriptorProto_clear_reserved_range(google_protobuf_EnumDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumDescriptorProto_msg_init(), 4); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_EnumDescriptorProto_EnumReservedRange* const* google_protobuf_EnumDescriptorProto_reserved_range(const google_protobuf_EnumDescriptorProto* msg, size_t* size) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumDescriptorProto_msg_init(), 4); - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_EnumDescriptorProto_EnumReservedRange* const*)_upb_array_constptr(arr); @@ -2435,16 +2516,16 @@ UPB_INLINE const google_protobuf_EnumDescriptorProto_EnumReservedRange* const* g } UPB_INLINE const upb_Array* _google_protobuf_EnumDescriptorProto_reserved_range_upb_array(const google_protobuf_EnumDescriptorProto* msg, size_t* size) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumDescriptorProto_msg_init(), 4); - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } -UPB_INLINE upb_Array* _google_protobuf_EnumDescriptorProto_reserved_range_mutable_upb_array(const google_protobuf_EnumDescriptorProto* msg, size_t* size, upb_Arena* arena) { +UPB_INLINE upb_Array* _google_protobuf_EnumDescriptorProto_reserved_range_mutable_upb_array(google_protobuf_EnumDescriptorProto* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumDescriptorProto_msg_init(), 4); upb_Array* arr = upb_Message_GetOrCreateMutableArray( - (upb_Message*)msg, &field, arena); + UPB_UPCAST(msg), &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -2452,11 +2533,11 @@ UPB_INLINE upb_Array* _google_protobuf_EnumDescriptorProto_reserved_range_mutabl } UPB_INLINE void google_protobuf_EnumDescriptorProto_clear_reserved_name(google_protobuf_EnumDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumDescriptorProto_msg_init(), 5); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView const* google_protobuf_EnumDescriptorProto_reserved_name(const google_protobuf_EnumDescriptorProto* msg, size_t* size) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumDescriptorProto_msg_init(), 5); - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (upb_StringView const*)_upb_array_constptr(arr); @@ -2467,16 +2548,16 @@ UPB_INLINE upb_StringView const* google_protobuf_EnumDescriptorProto_reserved_na } UPB_INLINE const upb_Array* _google_protobuf_EnumDescriptorProto_reserved_name_upb_array(const google_protobuf_EnumDescriptorProto* msg, size_t* size) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumDescriptorProto_msg_init(), 5); - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } -UPB_INLINE upb_Array* _google_protobuf_EnumDescriptorProto_reserved_name_mutable_upb_array(const google_protobuf_EnumDescriptorProto* msg, size_t* size, upb_Arena* arena) { +UPB_INLINE upb_Array* _google_protobuf_EnumDescriptorProto_reserved_name_mutable_upb_array(google_protobuf_EnumDescriptorProto* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumDescriptorProto_msg_init(), 5); upb_Array* arr = upb_Message_GetOrCreateMutableArray( - (upb_Message*)msg, &field, arena); + UPB_UPCAST(msg), &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -2485,11 +2566,11 @@ UPB_INLINE upb_Array* _google_protobuf_EnumDescriptorProto_reserved_name_mutable UPB_INLINE void google_protobuf_EnumDescriptorProto_set_name(google_protobuf_EnumDescriptorProto *msg, upb_StringView value) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumDescriptorProto_msg_init(), 1); - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE google_protobuf_EnumValueDescriptorProto** google_protobuf_EnumDescriptorProto_mutable_value(google_protobuf_EnumDescriptorProto* msg, size_t* size) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumDescriptorProto_msg_init(), 2); - upb_Array* arr = upb_Message_GetMutableArray(msg, &field); + upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_EnumValueDescriptorProto**)_upb_array_ptr(arr); @@ -2500,11 +2581,13 @@ UPB_INLINE google_protobuf_EnumValueDescriptorProto** google_protobuf_EnumDescri } UPB_INLINE google_protobuf_EnumValueDescriptorProto** google_protobuf_EnumDescriptorProto_resize_value(google_protobuf_EnumDescriptorProto* msg, size_t size, upb_Arena* arena) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumDescriptorProto_msg_init(), 2); - return (google_protobuf_EnumValueDescriptorProto**)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); + return (google_protobuf_EnumValueDescriptorProto**)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg), + &field, size, arena); } UPB_INLINE struct google_protobuf_EnumValueDescriptorProto* google_protobuf_EnumDescriptorProto_add_value(google_protobuf_EnumDescriptorProto* msg, upb_Arena* arena) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumDescriptorProto_msg_init(), 2); - upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray( + UPB_UPCAST(msg), &field, arena); if (!arr || !_upb_Array_ResizeUninitialized( arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; @@ -2517,7 +2600,7 @@ UPB_INLINE struct google_protobuf_EnumValueDescriptorProto* google_protobuf_Enum } UPB_INLINE void google_protobuf_EnumDescriptorProto_set_options(google_protobuf_EnumDescriptorProto *msg, google_protobuf_EnumOptions* value) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumDescriptorProto_msg_init(), 3); - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE struct google_protobuf_EnumOptions* google_protobuf_EnumDescriptorProto_mutable_options(google_protobuf_EnumDescriptorProto* msg, upb_Arena* arena) { struct google_protobuf_EnumOptions* sub = (struct google_protobuf_EnumOptions*)google_protobuf_EnumDescriptorProto_options(msg); @@ -2529,7 +2612,7 @@ UPB_INLINE struct google_protobuf_EnumOptions* google_protobuf_EnumDescriptorPro } UPB_INLINE google_protobuf_EnumDescriptorProto_EnumReservedRange** google_protobuf_EnumDescriptorProto_mutable_reserved_range(google_protobuf_EnumDescriptorProto* msg, size_t* size) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumDescriptorProto_msg_init(), 4); - upb_Array* arr = upb_Message_GetMutableArray(msg, &field); + upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_EnumDescriptorProto_EnumReservedRange**)_upb_array_ptr(arr); @@ -2540,11 +2623,13 @@ UPB_INLINE google_protobuf_EnumDescriptorProto_EnumReservedRange** google_protob } UPB_INLINE google_protobuf_EnumDescriptorProto_EnumReservedRange** google_protobuf_EnumDescriptorProto_resize_reserved_range(google_protobuf_EnumDescriptorProto* msg, size_t size, upb_Arena* arena) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumDescriptorProto_msg_init(), 4); - return (google_protobuf_EnumDescriptorProto_EnumReservedRange**)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); + return (google_protobuf_EnumDescriptorProto_EnumReservedRange**)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg), + &field, size, arena); } UPB_INLINE struct google_protobuf_EnumDescriptorProto_EnumReservedRange* google_protobuf_EnumDescriptorProto_add_reserved_range(google_protobuf_EnumDescriptorProto* msg, upb_Arena* arena) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumDescriptorProto_msg_init(), 4); - upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray( + UPB_UPCAST(msg), &field, arena); if (!arr || !_upb_Array_ResizeUninitialized( arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; @@ -2557,7 +2642,7 @@ UPB_INLINE struct google_protobuf_EnumDescriptorProto_EnumReservedRange* google_ } UPB_INLINE upb_StringView* google_protobuf_EnumDescriptorProto_mutable_reserved_name(google_protobuf_EnumDescriptorProto* msg, size_t* size) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumDescriptorProto_msg_init(), 5); - upb_Array* arr = upb_Message_GetMutableArray(msg, &field); + upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (upb_StringView*)_upb_array_ptr(arr); @@ -2568,11 +2653,13 @@ UPB_INLINE upb_StringView* google_protobuf_EnumDescriptorProto_mutable_reserved_ } UPB_INLINE upb_StringView* google_protobuf_EnumDescriptorProto_resize_reserved_name(google_protobuf_EnumDescriptorProto* msg, size_t size, upb_Arena* arena) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumDescriptorProto_msg_init(), 5); - return (upb_StringView*)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); + return (upb_StringView*)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg), + &field, size, arena); } UPB_INLINE bool google_protobuf_EnumDescriptorProto_add_reserved_name(google_protobuf_EnumDescriptorProto* msg, upb_StringView val, upb_Arena* arena) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumDescriptorProto_msg_init(), 5); - upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray( + UPB_UPCAST(msg), &field, arena); if (!arr || !_upb_Array_ResizeUninitialized( arr, arr->UPB_PRIVATE(size) + 1, arena)) { return false; @@ -2590,7 +2677,8 @@ UPB_INLINE google_protobuf_EnumDescriptorProto_EnumReservedRange* google_protobu UPB_INLINE google_protobuf_EnumDescriptorProto_EnumReservedRange* google_protobuf_EnumDescriptorProto_EnumReservedRange_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_EnumDescriptorProto_EnumReservedRange* ret = google_protobuf_EnumDescriptorProto_EnumReservedRange_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, google__protobuf__EnumDescriptorProto__EnumReservedRange_msg_init(), NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), google__protobuf__EnumDescriptorProto__EnumReservedRange_msg_init(), NULL, 0, arena) != + kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -2600,61 +2688,63 @@ UPB_INLINE google_protobuf_EnumDescriptorProto_EnumReservedRange* google_protobu int options, upb_Arena* arena) { google_protobuf_EnumDescriptorProto_EnumReservedRange* ret = google_protobuf_EnumDescriptorProto_EnumReservedRange_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, google__protobuf__EnumDescriptorProto__EnumReservedRange_msg_init(), extreg, options, arena) != - kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), google__protobuf__EnumDescriptorProto__EnumReservedRange_msg_init(), extreg, options, + arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_EnumDescriptorProto_EnumReservedRange_serialize(const google_protobuf_EnumDescriptorProto_EnumReservedRange* msg, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, google__protobuf__EnumDescriptorProto__EnumReservedRange_msg_init(), 0, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), google__protobuf__EnumDescriptorProto__EnumReservedRange_msg_init(), 0, arena, &ptr, len); return ptr; } UPB_INLINE char* google_protobuf_EnumDescriptorProto_EnumReservedRange_serialize_ex(const google_protobuf_EnumDescriptorProto_EnumReservedRange* msg, int options, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, google__protobuf__EnumDescriptorProto__EnumReservedRange_msg_init(), options, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), google__protobuf__EnumDescriptorProto__EnumReservedRange_msg_init(), options, arena, &ptr, len); return ptr; } UPB_INLINE void google_protobuf_EnumDescriptorProto_EnumReservedRange_clear_start(google_protobuf_EnumDescriptorProto_EnumReservedRange* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumDescriptorProto__EnumReservedRange_msg_init(), 1); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_EnumDescriptorProto_EnumReservedRange_start(const google_protobuf_EnumDescriptorProto_EnumReservedRange* msg) { int32_t default_val = (int32_t)0; int32_t ret; const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumDescriptorProto__EnumReservedRange_msg_init(), 1); - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_EnumDescriptorProto_EnumReservedRange_has_start(const google_protobuf_EnumDescriptorProto_EnumReservedRange* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumDescriptorProto__EnumReservedRange_msg_init(), 1); - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_EnumDescriptorProto_EnumReservedRange_clear_end(google_protobuf_EnumDescriptorProto_EnumReservedRange* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumDescriptorProto__EnumReservedRange_msg_init(), 2); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_EnumDescriptorProto_EnumReservedRange_end(const google_protobuf_EnumDescriptorProto_EnumReservedRange* msg) { int32_t default_val = (int32_t)0; int32_t ret; const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumDescriptorProto__EnumReservedRange_msg_init(), 2); - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_EnumDescriptorProto_EnumReservedRange_has_end(const google_protobuf_EnumDescriptorProto_EnumReservedRange* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumDescriptorProto__EnumReservedRange_msg_init(), 2); - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_EnumDescriptorProto_EnumReservedRange_set_start(google_protobuf_EnumDescriptorProto_EnumReservedRange *msg, int32_t value) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumDescriptorProto__EnumReservedRange_msg_init(), 1); - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_EnumDescriptorProto_EnumReservedRange_set_end(google_protobuf_EnumDescriptorProto_EnumReservedRange *msg, int32_t value) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumDescriptorProto__EnumReservedRange_msg_init(), 2); - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } /* google.protobuf.EnumValueDescriptorProto */ @@ -2665,7 +2755,8 @@ UPB_INLINE google_protobuf_EnumValueDescriptorProto* google_protobuf_EnumValueDe UPB_INLINE google_protobuf_EnumValueDescriptorProto* google_protobuf_EnumValueDescriptorProto_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_EnumValueDescriptorProto* ret = google_protobuf_EnumValueDescriptorProto_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, google__protobuf__EnumValueDescriptorProto_msg_init(), NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), google__protobuf__EnumValueDescriptorProto_msg_init(), NULL, 0, arena) != + kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -2675,80 +2766,83 @@ UPB_INLINE google_protobuf_EnumValueDescriptorProto* google_protobuf_EnumValueDe int options, upb_Arena* arena) { google_protobuf_EnumValueDescriptorProto* ret = google_protobuf_EnumValueDescriptorProto_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, google__protobuf__EnumValueDescriptorProto_msg_init(), extreg, options, arena) != - kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), google__protobuf__EnumValueDescriptorProto_msg_init(), extreg, options, + arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_EnumValueDescriptorProto_serialize(const google_protobuf_EnumValueDescriptorProto* msg, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, google__protobuf__EnumValueDescriptorProto_msg_init(), 0, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), google__protobuf__EnumValueDescriptorProto_msg_init(), 0, arena, &ptr, len); return ptr; } UPB_INLINE char* google_protobuf_EnumValueDescriptorProto_serialize_ex(const google_protobuf_EnumValueDescriptorProto* msg, int options, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, google__protobuf__EnumValueDescriptorProto_msg_init(), options, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), google__protobuf__EnumValueDescriptorProto_msg_init(), options, arena, &ptr, len); return ptr; } UPB_INLINE void google_protobuf_EnumValueDescriptorProto_clear_name(google_protobuf_EnumValueDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumValueDescriptorProto_msg_init(), 1); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_EnumValueDescriptorProto_name(const google_protobuf_EnumValueDescriptorProto* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumValueDescriptorProto_msg_init(), 1); - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_EnumValueDescriptorProto_has_name(const google_protobuf_EnumValueDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumValueDescriptorProto_msg_init(), 1); - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_EnumValueDescriptorProto_clear_number(google_protobuf_EnumValueDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumValueDescriptorProto_msg_init(), 2); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_EnumValueDescriptorProto_number(const google_protobuf_EnumValueDescriptorProto* msg) { int32_t default_val = (int32_t)0; int32_t ret; const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumValueDescriptorProto_msg_init(), 2); - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_EnumValueDescriptorProto_has_number(const google_protobuf_EnumValueDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumValueDescriptorProto_msg_init(), 2); - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_EnumValueDescriptorProto_clear_options(google_protobuf_EnumValueDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumValueDescriptorProto_msg_init(), 3); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_EnumValueOptions* google_protobuf_EnumValueDescriptorProto_options(const google_protobuf_EnumValueDescriptorProto* msg) { const google_protobuf_EnumValueOptions* default_val = NULL; const google_protobuf_EnumValueOptions* ret; const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumValueDescriptorProto_msg_init(), 3); - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_EnumValueDescriptorProto_has_options(const google_protobuf_EnumValueDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumValueDescriptorProto_msg_init(), 3); - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_EnumValueDescriptorProto_set_name(google_protobuf_EnumValueDescriptorProto *msg, upb_StringView value) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumValueDescriptorProto_msg_init(), 1); - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_EnumValueDescriptorProto_set_number(google_protobuf_EnumValueDescriptorProto *msg, int32_t value) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumValueDescriptorProto_msg_init(), 2); - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_EnumValueDescriptorProto_set_options(google_protobuf_EnumValueDescriptorProto *msg, google_protobuf_EnumValueOptions* value) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumValueDescriptorProto_msg_init(), 3); - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE struct google_protobuf_EnumValueOptions* google_protobuf_EnumValueDescriptorProto_mutable_options(google_protobuf_EnumValueDescriptorProto* msg, upb_Arena* arena) { struct google_protobuf_EnumValueOptions* sub = (struct google_protobuf_EnumValueOptions*)google_protobuf_EnumValueDescriptorProto_options(msg); @@ -2767,7 +2861,8 @@ UPB_INLINE google_protobuf_ServiceDescriptorProto* google_protobuf_ServiceDescri UPB_INLINE google_protobuf_ServiceDescriptorProto* google_protobuf_ServiceDescriptorProto_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_ServiceDescriptorProto* ret = google_protobuf_ServiceDescriptorProto_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, google__protobuf__ServiceDescriptorProto_msg_init(), NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), google__protobuf__ServiceDescriptorProto_msg_init(), NULL, 0, arena) != + kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -2777,45 +2872,46 @@ UPB_INLINE google_protobuf_ServiceDescriptorProto* google_protobuf_ServiceDescri int options, upb_Arena* arena) { google_protobuf_ServiceDescriptorProto* ret = google_protobuf_ServiceDescriptorProto_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, google__protobuf__ServiceDescriptorProto_msg_init(), extreg, options, arena) != - kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), google__protobuf__ServiceDescriptorProto_msg_init(), extreg, options, + arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_ServiceDescriptorProto_serialize(const google_protobuf_ServiceDescriptorProto* msg, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, google__protobuf__ServiceDescriptorProto_msg_init(), 0, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), google__protobuf__ServiceDescriptorProto_msg_init(), 0, arena, &ptr, len); return ptr; } UPB_INLINE char* google_protobuf_ServiceDescriptorProto_serialize_ex(const google_protobuf_ServiceDescriptorProto* msg, int options, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, google__protobuf__ServiceDescriptorProto_msg_init(), options, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), google__protobuf__ServiceDescriptorProto_msg_init(), options, arena, &ptr, len); return ptr; } UPB_INLINE void google_protobuf_ServiceDescriptorProto_clear_name(google_protobuf_ServiceDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ServiceDescriptorProto_msg_init(), 1); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_ServiceDescriptorProto_name(const google_protobuf_ServiceDescriptorProto* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ServiceDescriptorProto_msg_init(), 1); - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_ServiceDescriptorProto_has_name(const google_protobuf_ServiceDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ServiceDescriptorProto_msg_init(), 1); - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_ServiceDescriptorProto_clear_method(google_protobuf_ServiceDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ServiceDescriptorProto_msg_init(), 2); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_MethodDescriptorProto* const* google_protobuf_ServiceDescriptorProto_method(const google_protobuf_ServiceDescriptorProto* msg, size_t* size) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ServiceDescriptorProto_msg_init(), 2); - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_MethodDescriptorProto* const*)_upb_array_constptr(arr); @@ -2826,16 +2922,16 @@ UPB_INLINE const google_protobuf_MethodDescriptorProto* const* google_protobuf_S } UPB_INLINE const upb_Array* _google_protobuf_ServiceDescriptorProto_method_upb_array(const google_protobuf_ServiceDescriptorProto* msg, size_t* size) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ServiceDescriptorProto_msg_init(), 2); - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } -UPB_INLINE upb_Array* _google_protobuf_ServiceDescriptorProto_method_mutable_upb_array(const google_protobuf_ServiceDescriptorProto* msg, size_t* size, upb_Arena* arena) { +UPB_INLINE upb_Array* _google_protobuf_ServiceDescriptorProto_method_mutable_upb_array(google_protobuf_ServiceDescriptorProto* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ServiceDescriptorProto_msg_init(), 2); upb_Array* arr = upb_Message_GetOrCreateMutableArray( - (upb_Message*)msg, &field, arena); + UPB_UPCAST(msg), &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -2843,27 +2939,28 @@ UPB_INLINE upb_Array* _google_protobuf_ServiceDescriptorProto_method_mutable_upb } UPB_INLINE void google_protobuf_ServiceDescriptorProto_clear_options(google_protobuf_ServiceDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ServiceDescriptorProto_msg_init(), 3); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_ServiceOptions* google_protobuf_ServiceDescriptorProto_options(const google_protobuf_ServiceDescriptorProto* msg) { const google_protobuf_ServiceOptions* default_val = NULL; const google_protobuf_ServiceOptions* ret; const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ServiceDescriptorProto_msg_init(), 3); - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_ServiceDescriptorProto_has_options(const google_protobuf_ServiceDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ServiceDescriptorProto_msg_init(), 3); - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_ServiceDescriptorProto_set_name(google_protobuf_ServiceDescriptorProto *msg, upb_StringView value) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ServiceDescriptorProto_msg_init(), 1); - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE google_protobuf_MethodDescriptorProto** google_protobuf_ServiceDescriptorProto_mutable_method(google_protobuf_ServiceDescriptorProto* msg, size_t* size) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ServiceDescriptorProto_msg_init(), 2); - upb_Array* arr = upb_Message_GetMutableArray(msg, &field); + upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_MethodDescriptorProto**)_upb_array_ptr(arr); @@ -2874,11 +2971,13 @@ UPB_INLINE google_protobuf_MethodDescriptorProto** google_protobuf_ServiceDescri } UPB_INLINE google_protobuf_MethodDescriptorProto** google_protobuf_ServiceDescriptorProto_resize_method(google_protobuf_ServiceDescriptorProto* msg, size_t size, upb_Arena* arena) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ServiceDescriptorProto_msg_init(), 2); - return (google_protobuf_MethodDescriptorProto**)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); + return (google_protobuf_MethodDescriptorProto**)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg), + &field, size, arena); } UPB_INLINE struct google_protobuf_MethodDescriptorProto* google_protobuf_ServiceDescriptorProto_add_method(google_protobuf_ServiceDescriptorProto* msg, upb_Arena* arena) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ServiceDescriptorProto_msg_init(), 2); - upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray( + UPB_UPCAST(msg), &field, arena); if (!arr || !_upb_Array_ResizeUninitialized( arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; @@ -2891,7 +2990,7 @@ UPB_INLINE struct google_protobuf_MethodDescriptorProto* google_protobuf_Service } UPB_INLINE void google_protobuf_ServiceDescriptorProto_set_options(google_protobuf_ServiceDescriptorProto *msg, google_protobuf_ServiceOptions* value) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ServiceDescriptorProto_msg_init(), 3); - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE struct google_protobuf_ServiceOptions* google_protobuf_ServiceDescriptorProto_mutable_options(google_protobuf_ServiceDescriptorProto* msg, upb_Arena* arena) { struct google_protobuf_ServiceOptions* sub = (struct google_protobuf_ServiceOptions*)google_protobuf_ServiceDescriptorProto_options(msg); @@ -2910,7 +3009,8 @@ UPB_INLINE google_protobuf_MethodDescriptorProto* google_protobuf_MethodDescript UPB_INLINE google_protobuf_MethodDescriptorProto* google_protobuf_MethodDescriptorProto_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_MethodDescriptorProto* ret = google_protobuf_MethodDescriptorProto_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, google__protobuf__MethodDescriptorProto_msg_init(), NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), google__protobuf__MethodDescriptorProto_msg_init(), NULL, 0, arena) != + kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -2920,129 +3020,135 @@ UPB_INLINE google_protobuf_MethodDescriptorProto* google_protobuf_MethodDescript int options, upb_Arena* arena) { google_protobuf_MethodDescriptorProto* ret = google_protobuf_MethodDescriptorProto_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, google__protobuf__MethodDescriptorProto_msg_init(), extreg, options, arena) != - kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), google__protobuf__MethodDescriptorProto_msg_init(), extreg, options, + arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_MethodDescriptorProto_serialize(const google_protobuf_MethodDescriptorProto* msg, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, google__protobuf__MethodDescriptorProto_msg_init(), 0, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), google__protobuf__MethodDescriptorProto_msg_init(), 0, arena, &ptr, len); return ptr; } UPB_INLINE char* google_protobuf_MethodDescriptorProto_serialize_ex(const google_protobuf_MethodDescriptorProto* msg, int options, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, google__protobuf__MethodDescriptorProto_msg_init(), options, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), google__protobuf__MethodDescriptorProto_msg_init(), options, arena, &ptr, len); return ptr; } UPB_INLINE void google_protobuf_MethodDescriptorProto_clear_name(google_protobuf_MethodDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MethodDescriptorProto_msg_init(), 1); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_MethodDescriptorProto_name(const google_protobuf_MethodDescriptorProto* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MethodDescriptorProto_msg_init(), 1); - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_MethodDescriptorProto_has_name(const google_protobuf_MethodDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MethodDescriptorProto_msg_init(), 1); - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_MethodDescriptorProto_clear_input_type(google_protobuf_MethodDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MethodDescriptorProto_msg_init(), 2); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_MethodDescriptorProto_input_type(const google_protobuf_MethodDescriptorProto* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MethodDescriptorProto_msg_init(), 2); - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_MethodDescriptorProto_has_input_type(const google_protobuf_MethodDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MethodDescriptorProto_msg_init(), 2); - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_MethodDescriptorProto_clear_output_type(google_protobuf_MethodDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MethodDescriptorProto_msg_init(), 3); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_MethodDescriptorProto_output_type(const google_protobuf_MethodDescriptorProto* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MethodDescriptorProto_msg_init(), 3); - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_MethodDescriptorProto_has_output_type(const google_protobuf_MethodDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MethodDescriptorProto_msg_init(), 3); - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_MethodDescriptorProto_clear_options(google_protobuf_MethodDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MethodDescriptorProto_msg_init(), 4); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_MethodOptions* google_protobuf_MethodDescriptorProto_options(const google_protobuf_MethodDescriptorProto* msg) { const google_protobuf_MethodOptions* default_val = NULL; const google_protobuf_MethodOptions* ret; const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MethodDescriptorProto_msg_init(), 4); - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_MethodDescriptorProto_has_options(const google_protobuf_MethodDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MethodDescriptorProto_msg_init(), 4); - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_MethodDescriptorProto_clear_client_streaming(google_protobuf_MethodDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MethodDescriptorProto_msg_init(), 5); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_MethodDescriptorProto_client_streaming(const google_protobuf_MethodDescriptorProto* msg) { bool default_val = false; bool ret; const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MethodDescriptorProto_msg_init(), 5); - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_MethodDescriptorProto_has_client_streaming(const google_protobuf_MethodDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MethodDescriptorProto_msg_init(), 5); - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_MethodDescriptorProto_clear_server_streaming(google_protobuf_MethodDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MethodDescriptorProto_msg_init(), 6); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_MethodDescriptorProto_server_streaming(const google_protobuf_MethodDescriptorProto* msg) { bool default_val = false; bool ret; const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MethodDescriptorProto_msg_init(), 6); - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_MethodDescriptorProto_has_server_streaming(const google_protobuf_MethodDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MethodDescriptorProto_msg_init(), 6); - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_MethodDescriptorProto_set_name(google_protobuf_MethodDescriptorProto *msg, upb_StringView value) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MethodDescriptorProto_msg_init(), 1); - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_MethodDescriptorProto_set_input_type(google_protobuf_MethodDescriptorProto *msg, upb_StringView value) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MethodDescriptorProto_msg_init(), 2); - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_MethodDescriptorProto_set_output_type(google_protobuf_MethodDescriptorProto *msg, upb_StringView value) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MethodDescriptorProto_msg_init(), 3); - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_MethodDescriptorProto_set_options(google_protobuf_MethodDescriptorProto *msg, google_protobuf_MethodOptions* value) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MethodDescriptorProto_msg_init(), 4); - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE struct google_protobuf_MethodOptions* google_protobuf_MethodDescriptorProto_mutable_options(google_protobuf_MethodDescriptorProto* msg, upb_Arena* arena) { struct google_protobuf_MethodOptions* sub = (struct google_protobuf_MethodOptions*)google_protobuf_MethodDescriptorProto_options(msg); @@ -3054,11 +3160,11 @@ UPB_INLINE struct google_protobuf_MethodOptions* google_protobuf_MethodDescripto } UPB_INLINE void google_protobuf_MethodDescriptorProto_set_client_streaming(google_protobuf_MethodDescriptorProto *msg, bool value) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MethodDescriptorProto_msg_init(), 5); - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_MethodDescriptorProto_set_server_streaming(google_protobuf_MethodDescriptorProto *msg, bool value) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MethodDescriptorProto_msg_init(), 6); - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } /* google.protobuf.FileOptions */ @@ -3069,7 +3175,8 @@ UPB_INLINE google_protobuf_FileOptions* google_protobuf_FileOptions_new(upb_Aren UPB_INLINE google_protobuf_FileOptions* google_protobuf_FileOptions_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_FileOptions* ret = google_protobuf_FileOptions_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, google__protobuf__FileOptions_msg_init(), NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), google__protobuf__FileOptions_msg_init(), NULL, 0, arena) != + kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -3079,330 +3186,366 @@ UPB_INLINE google_protobuf_FileOptions* google_protobuf_FileOptions_parse_ex(con int options, upb_Arena* arena) { google_protobuf_FileOptions* ret = google_protobuf_FileOptions_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, google__protobuf__FileOptions_msg_init(), extreg, options, arena) != - kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), google__protobuf__FileOptions_msg_init(), extreg, options, + arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_FileOptions_serialize(const google_protobuf_FileOptions* msg, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, google__protobuf__FileOptions_msg_init(), 0, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), google__protobuf__FileOptions_msg_init(), 0, arena, &ptr, len); return ptr; } UPB_INLINE char* google_protobuf_FileOptions_serialize_ex(const google_protobuf_FileOptions* msg, int options, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, google__protobuf__FileOptions_msg_init(), options, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), google__protobuf__FileOptions_msg_init(), options, arena, &ptr, len); return ptr; } UPB_INLINE void google_protobuf_FileOptions_clear_java_package(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 1); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_FileOptions_java_package(const google_protobuf_FileOptions* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 1); - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FileOptions_has_java_package(const google_protobuf_FileOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 1); - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileOptions_clear_java_outer_classname(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 8); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_FileOptions_java_outer_classname(const google_protobuf_FileOptions* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 8); - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FileOptions_has_java_outer_classname(const google_protobuf_FileOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 8); - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileOptions_clear_optimize_for(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 9); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_FileOptions_optimize_for(const google_protobuf_FileOptions* msg) { int32_t default_val = 1; int32_t ret; const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 9); - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FileOptions_has_optimize_for(const google_protobuf_FileOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 9); - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileOptions_clear_java_multiple_files(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 10); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_FileOptions_java_multiple_files(const google_protobuf_FileOptions* msg) { bool default_val = false; bool ret; const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 10); - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FileOptions_has_java_multiple_files(const google_protobuf_FileOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 10); - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileOptions_clear_go_package(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 11); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_FileOptions_go_package(const google_protobuf_FileOptions* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 11); - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FileOptions_has_go_package(const google_protobuf_FileOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 11); - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileOptions_clear_cc_generic_services(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 16); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_FileOptions_cc_generic_services(const google_protobuf_FileOptions* msg) { bool default_val = false; bool ret; const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 16); - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FileOptions_has_cc_generic_services(const google_protobuf_FileOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 16); - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileOptions_clear_java_generic_services(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 17); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_FileOptions_java_generic_services(const google_protobuf_FileOptions* msg) { bool default_val = false; bool ret; const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 17); - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FileOptions_has_java_generic_services(const google_protobuf_FileOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 17); - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileOptions_clear_py_generic_services(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 18); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_FileOptions_py_generic_services(const google_protobuf_FileOptions* msg) { bool default_val = false; bool ret; const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 18); - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FileOptions_has_py_generic_services(const google_protobuf_FileOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 18); - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileOptions_clear_java_generate_equals_and_hash(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 20); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_FileOptions_java_generate_equals_and_hash(const google_protobuf_FileOptions* msg) { bool default_val = false; bool ret; const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 20); - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FileOptions_has_java_generate_equals_and_hash(const google_protobuf_FileOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 20); - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileOptions_clear_deprecated(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 23); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_FileOptions_deprecated(const google_protobuf_FileOptions* msg) { bool default_val = false; bool ret; const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 23); - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FileOptions_has_deprecated(const google_protobuf_FileOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 23); - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileOptions_clear_java_string_check_utf8(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 27); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_FileOptions_java_string_check_utf8(const google_protobuf_FileOptions* msg) { bool default_val = false; bool ret; const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 27); - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FileOptions_has_java_string_check_utf8(const google_protobuf_FileOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 27); - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileOptions_clear_cc_enable_arenas(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 31); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_FileOptions_cc_enable_arenas(const google_protobuf_FileOptions* msg) { bool default_val = true; bool ret; const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 31); - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FileOptions_has_cc_enable_arenas(const google_protobuf_FileOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 31); - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileOptions_clear_objc_class_prefix(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 36); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_FileOptions_objc_class_prefix(const google_protobuf_FileOptions* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 36); - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FileOptions_has_objc_class_prefix(const google_protobuf_FileOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 36); - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileOptions_clear_csharp_namespace(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 37); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_FileOptions_csharp_namespace(const google_protobuf_FileOptions* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 37); - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FileOptions_has_csharp_namespace(const google_protobuf_FileOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 37); - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileOptions_clear_swift_prefix(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 39); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_FileOptions_swift_prefix(const google_protobuf_FileOptions* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 39); - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FileOptions_has_swift_prefix(const google_protobuf_FileOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 39); - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileOptions_clear_php_class_prefix(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 40); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_FileOptions_php_class_prefix(const google_protobuf_FileOptions* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 40); - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FileOptions_has_php_class_prefix(const google_protobuf_FileOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 40); - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileOptions_clear_php_namespace(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 41); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_FileOptions_php_namespace(const google_protobuf_FileOptions* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 41); - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FileOptions_has_php_namespace(const google_protobuf_FileOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 41); - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); +} +UPB_INLINE void google_protobuf_FileOptions_clear_php_generic_services(google_protobuf_FileOptions* msg) { + const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 42); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); +} +UPB_INLINE bool google_protobuf_FileOptions_php_generic_services(const google_protobuf_FileOptions* msg) { + bool default_val = false; + bool ret; + const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 42); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); + return ret; +} +UPB_INLINE bool google_protobuf_FileOptions_has_php_generic_services(const google_protobuf_FileOptions* msg) { + const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 42); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileOptions_clear_php_metadata_namespace(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 44); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_FileOptions_php_metadata_namespace(const google_protobuf_FileOptions* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 44); - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FileOptions_has_php_metadata_namespace(const google_protobuf_FileOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 44); - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileOptions_clear_ruby_package(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 45); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_FileOptions_ruby_package(const google_protobuf_FileOptions* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 45); - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FileOptions_has_ruby_package(const google_protobuf_FileOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 45); - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileOptions_clear_features(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 50); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_FeatureSet* google_protobuf_FileOptions_features(const google_protobuf_FileOptions* msg) { const google_protobuf_FeatureSet* default_val = NULL; const google_protobuf_FeatureSet* ret; const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 50); - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FileOptions_has_features(const google_protobuf_FileOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 50); - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileOptions_clear_uninterpreted_option(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 999); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_FileOptions_uninterpreted_option(const google_protobuf_FileOptions* msg, size_t* size) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 999); - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_UninterpretedOption* const*)_upb_array_constptr(arr); @@ -3413,16 +3556,16 @@ UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_Fil } UPB_INLINE const upb_Array* _google_protobuf_FileOptions_uninterpreted_option_upb_array(const google_protobuf_FileOptions* msg, size_t* size) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 999); - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } -UPB_INLINE upb_Array* _google_protobuf_FileOptions_uninterpreted_option_mutable_upb_array(const google_protobuf_FileOptions* msg, size_t* size, upb_Arena* arena) { +UPB_INLINE upb_Array* _google_protobuf_FileOptions_uninterpreted_option_mutable_upb_array(google_protobuf_FileOptions* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 999); upb_Array* arr = upb_Message_GetOrCreateMutableArray( - (upb_Message*)msg, &field, arena); + UPB_UPCAST(msg), &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -3431,83 +3574,87 @@ UPB_INLINE upb_Array* _google_protobuf_FileOptions_uninterpreted_option_mutable_ UPB_INLINE void google_protobuf_FileOptions_set_java_package(google_protobuf_FileOptions *msg, upb_StringView value) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 1); - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FileOptions_set_java_outer_classname(google_protobuf_FileOptions *msg, upb_StringView value) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 8); - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FileOptions_set_optimize_for(google_protobuf_FileOptions *msg, int32_t value) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 9); - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FileOptions_set_java_multiple_files(google_protobuf_FileOptions *msg, bool value) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 10); - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FileOptions_set_go_package(google_protobuf_FileOptions *msg, upb_StringView value) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 11); - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FileOptions_set_cc_generic_services(google_protobuf_FileOptions *msg, bool value) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 16); - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FileOptions_set_java_generic_services(google_protobuf_FileOptions *msg, bool value) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 17); - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FileOptions_set_py_generic_services(google_protobuf_FileOptions *msg, bool value) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 18); - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FileOptions_set_java_generate_equals_and_hash(google_protobuf_FileOptions *msg, bool value) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 20); - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FileOptions_set_deprecated(google_protobuf_FileOptions *msg, bool value) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 23); - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FileOptions_set_java_string_check_utf8(google_protobuf_FileOptions *msg, bool value) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 27); - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FileOptions_set_cc_enable_arenas(google_protobuf_FileOptions *msg, bool value) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 31); - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FileOptions_set_objc_class_prefix(google_protobuf_FileOptions *msg, upb_StringView value) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 36); - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FileOptions_set_csharp_namespace(google_protobuf_FileOptions *msg, upb_StringView value) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 37); - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FileOptions_set_swift_prefix(google_protobuf_FileOptions *msg, upb_StringView value) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 39); - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FileOptions_set_php_class_prefix(google_protobuf_FileOptions *msg, upb_StringView value) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 40); - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FileOptions_set_php_namespace(google_protobuf_FileOptions *msg, upb_StringView value) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 41); - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); +} +UPB_INLINE void google_protobuf_FileOptions_set_php_generic_services(google_protobuf_FileOptions *msg, bool value) { + const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 42); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FileOptions_set_php_metadata_namespace(google_protobuf_FileOptions *msg, upb_StringView value) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 44); - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FileOptions_set_ruby_package(google_protobuf_FileOptions *msg, upb_StringView value) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 45); - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FileOptions_set_features(google_protobuf_FileOptions *msg, google_protobuf_FeatureSet* value) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 50); - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE struct google_protobuf_FeatureSet* google_protobuf_FileOptions_mutable_features(google_protobuf_FileOptions* msg, upb_Arena* arena) { struct google_protobuf_FeatureSet* sub = (struct google_protobuf_FeatureSet*)google_protobuf_FileOptions_features(msg); @@ -3519,7 +3666,7 @@ UPB_INLINE struct google_protobuf_FeatureSet* google_protobuf_FileOptions_mutabl } UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_FileOptions_mutable_uninterpreted_option(google_protobuf_FileOptions* msg, size_t* size) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 999); - upb_Array* arr = upb_Message_GetMutableArray(msg, &field); + upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_UninterpretedOption**)_upb_array_ptr(arr); @@ -3530,11 +3677,13 @@ UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_FileOptions_mut } UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_FileOptions_resize_uninterpreted_option(google_protobuf_FileOptions* msg, size_t size, upb_Arena* arena) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 999); - return (google_protobuf_UninterpretedOption**)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); + return (google_protobuf_UninterpretedOption**)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg), + &field, size, arena); } UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_FileOptions_add_uninterpreted_option(google_protobuf_FileOptions* msg, upb_Arena* arena) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 999); - upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray( + UPB_UPCAST(msg), &field, arena); if (!arr || !_upb_Array_ResizeUninitialized( arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; @@ -3554,7 +3703,8 @@ UPB_INLINE google_protobuf_MessageOptions* google_protobuf_MessageOptions_new(up UPB_INLINE google_protobuf_MessageOptions* google_protobuf_MessageOptions_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_MessageOptions* ret = google_protobuf_MessageOptions_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, google__protobuf__MessageOptions_msg_init(), NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), google__protobuf__MessageOptions_msg_init(), NULL, 0, arena) != + kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -3564,120 +3714,126 @@ UPB_INLINE google_protobuf_MessageOptions* google_protobuf_MessageOptions_parse_ int options, upb_Arena* arena) { google_protobuf_MessageOptions* ret = google_protobuf_MessageOptions_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, google__protobuf__MessageOptions_msg_init(), extreg, options, arena) != - kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), google__protobuf__MessageOptions_msg_init(), extreg, options, + arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_MessageOptions_serialize(const google_protobuf_MessageOptions* msg, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, google__protobuf__MessageOptions_msg_init(), 0, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), google__protobuf__MessageOptions_msg_init(), 0, arena, &ptr, len); return ptr; } UPB_INLINE char* google_protobuf_MessageOptions_serialize_ex(const google_protobuf_MessageOptions* msg, int options, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, google__protobuf__MessageOptions_msg_init(), options, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), google__protobuf__MessageOptions_msg_init(), options, arena, &ptr, len); return ptr; } UPB_INLINE void google_protobuf_MessageOptions_clear_message_set_wire_format(google_protobuf_MessageOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MessageOptions_msg_init(), 1); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_MessageOptions_message_set_wire_format(const google_protobuf_MessageOptions* msg) { bool default_val = false; bool ret; const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MessageOptions_msg_init(), 1); - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_MessageOptions_has_message_set_wire_format(const google_protobuf_MessageOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MessageOptions_msg_init(), 1); - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_MessageOptions_clear_no_standard_descriptor_accessor(google_protobuf_MessageOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MessageOptions_msg_init(), 2); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_MessageOptions_no_standard_descriptor_accessor(const google_protobuf_MessageOptions* msg) { bool default_val = false; bool ret; const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MessageOptions_msg_init(), 2); - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_MessageOptions_has_no_standard_descriptor_accessor(const google_protobuf_MessageOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MessageOptions_msg_init(), 2); - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_MessageOptions_clear_deprecated(google_protobuf_MessageOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MessageOptions_msg_init(), 3); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_MessageOptions_deprecated(const google_protobuf_MessageOptions* msg) { bool default_val = false; bool ret; const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MessageOptions_msg_init(), 3); - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_MessageOptions_has_deprecated(const google_protobuf_MessageOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MessageOptions_msg_init(), 3); - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_MessageOptions_clear_map_entry(google_protobuf_MessageOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MessageOptions_msg_init(), 7); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_MessageOptions_map_entry(const google_protobuf_MessageOptions* msg) { bool default_val = false; bool ret; const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MessageOptions_msg_init(), 7); - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_MessageOptions_has_map_entry(const google_protobuf_MessageOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MessageOptions_msg_init(), 7); - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_MessageOptions_clear_deprecated_legacy_json_field_conflicts(google_protobuf_MessageOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MessageOptions_msg_init(), 11); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_MessageOptions_deprecated_legacy_json_field_conflicts(const google_protobuf_MessageOptions* msg) { bool default_val = false; bool ret; const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MessageOptions_msg_init(), 11); - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_MessageOptions_has_deprecated_legacy_json_field_conflicts(const google_protobuf_MessageOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MessageOptions_msg_init(), 11); - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_MessageOptions_clear_features(google_protobuf_MessageOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MessageOptions_msg_init(), 12); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_FeatureSet* google_protobuf_MessageOptions_features(const google_protobuf_MessageOptions* msg) { const google_protobuf_FeatureSet* default_val = NULL; const google_protobuf_FeatureSet* ret; const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MessageOptions_msg_init(), 12); - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_MessageOptions_has_features(const google_protobuf_MessageOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MessageOptions_msg_init(), 12); - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_MessageOptions_clear_uninterpreted_option(google_protobuf_MessageOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MessageOptions_msg_init(), 999); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_MessageOptions_uninterpreted_option(const google_protobuf_MessageOptions* msg, size_t* size) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MessageOptions_msg_init(), 999); - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_UninterpretedOption* const*)_upb_array_constptr(arr); @@ -3688,16 +3844,16 @@ UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_Mes } UPB_INLINE const upb_Array* _google_protobuf_MessageOptions_uninterpreted_option_upb_array(const google_protobuf_MessageOptions* msg, size_t* size) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MessageOptions_msg_init(), 999); - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } -UPB_INLINE upb_Array* _google_protobuf_MessageOptions_uninterpreted_option_mutable_upb_array(const google_protobuf_MessageOptions* msg, size_t* size, upb_Arena* arena) { +UPB_INLINE upb_Array* _google_protobuf_MessageOptions_uninterpreted_option_mutable_upb_array(google_protobuf_MessageOptions* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MessageOptions_msg_init(), 999); upb_Array* arr = upb_Message_GetOrCreateMutableArray( - (upb_Message*)msg, &field, arena); + UPB_UPCAST(msg), &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -3706,27 +3862,27 @@ UPB_INLINE upb_Array* _google_protobuf_MessageOptions_uninterpreted_option_mutab UPB_INLINE void google_protobuf_MessageOptions_set_message_set_wire_format(google_protobuf_MessageOptions *msg, bool value) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MessageOptions_msg_init(), 1); - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_MessageOptions_set_no_standard_descriptor_accessor(google_protobuf_MessageOptions *msg, bool value) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MessageOptions_msg_init(), 2); - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_MessageOptions_set_deprecated(google_protobuf_MessageOptions *msg, bool value) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MessageOptions_msg_init(), 3); - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_MessageOptions_set_map_entry(google_protobuf_MessageOptions *msg, bool value) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MessageOptions_msg_init(), 7); - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_MessageOptions_set_deprecated_legacy_json_field_conflicts(google_protobuf_MessageOptions *msg, bool value) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MessageOptions_msg_init(), 11); - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_MessageOptions_set_features(google_protobuf_MessageOptions *msg, google_protobuf_FeatureSet* value) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MessageOptions_msg_init(), 12); - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE struct google_protobuf_FeatureSet* google_protobuf_MessageOptions_mutable_features(google_protobuf_MessageOptions* msg, upb_Arena* arena) { struct google_protobuf_FeatureSet* sub = (struct google_protobuf_FeatureSet*)google_protobuf_MessageOptions_features(msg); @@ -3738,7 +3894,7 @@ UPB_INLINE struct google_protobuf_FeatureSet* google_protobuf_MessageOptions_mut } UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_MessageOptions_mutable_uninterpreted_option(google_protobuf_MessageOptions* msg, size_t* size) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MessageOptions_msg_init(), 999); - upb_Array* arr = upb_Message_GetMutableArray(msg, &field); + upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_UninterpretedOption**)_upb_array_ptr(arr); @@ -3749,11 +3905,13 @@ UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_MessageOptions_ } UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_MessageOptions_resize_uninterpreted_option(google_protobuf_MessageOptions* msg, size_t size, upb_Arena* arena) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MessageOptions_msg_init(), 999); - return (google_protobuf_UninterpretedOption**)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); + return (google_protobuf_UninterpretedOption**)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg), + &field, size, arena); } UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_MessageOptions_add_uninterpreted_option(google_protobuf_MessageOptions* msg, upb_Arena* arena) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MessageOptions_msg_init(), 999); - upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray( + UPB_UPCAST(msg), &field, arena); if (!arr || !_upb_Array_ResizeUninitialized( arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; @@ -3773,7 +3931,8 @@ UPB_INLINE google_protobuf_FieldOptions* google_protobuf_FieldOptions_new(upb_Ar UPB_INLINE google_protobuf_FieldOptions* google_protobuf_FieldOptions_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_FieldOptions* ret = google_protobuf_FieldOptions_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, google__protobuf__FieldOptions_msg_init(), NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), google__protobuf__FieldOptions_msg_init(), NULL, 0, arena) != + kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -3783,165 +3942,174 @@ UPB_INLINE google_protobuf_FieldOptions* google_protobuf_FieldOptions_parse_ex(c int options, upb_Arena* arena) { google_protobuf_FieldOptions* ret = google_protobuf_FieldOptions_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, google__protobuf__FieldOptions_msg_init(), extreg, options, arena) != - kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), google__protobuf__FieldOptions_msg_init(), extreg, options, + arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_FieldOptions_serialize(const google_protobuf_FieldOptions* msg, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, google__protobuf__FieldOptions_msg_init(), 0, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), google__protobuf__FieldOptions_msg_init(), 0, arena, &ptr, len); return ptr; } UPB_INLINE char* google_protobuf_FieldOptions_serialize_ex(const google_protobuf_FieldOptions* msg, int options, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, google__protobuf__FieldOptions_msg_init(), options, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), google__protobuf__FieldOptions_msg_init(), options, arena, &ptr, len); return ptr; } UPB_INLINE void google_protobuf_FieldOptions_clear_ctype(google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 1); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_FieldOptions_ctype(const google_protobuf_FieldOptions* msg) { int32_t default_val = 0; int32_t ret; const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 1); - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FieldOptions_has_ctype(const google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 1); - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldOptions_clear_packed(google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 2); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_FieldOptions_packed(const google_protobuf_FieldOptions* msg) { bool default_val = false; bool ret; const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 2); - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FieldOptions_has_packed(const google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 2); - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldOptions_clear_deprecated(google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 3); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_FieldOptions_deprecated(const google_protobuf_FieldOptions* msg) { bool default_val = false; bool ret; const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 3); - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FieldOptions_has_deprecated(const google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 3); - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldOptions_clear_lazy(google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 5); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_FieldOptions_lazy(const google_protobuf_FieldOptions* msg) { bool default_val = false; bool ret; const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 5); - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FieldOptions_has_lazy(const google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 5); - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldOptions_clear_jstype(google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 6); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_FieldOptions_jstype(const google_protobuf_FieldOptions* msg) { int32_t default_val = 0; int32_t ret; const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 6); - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FieldOptions_has_jstype(const google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 6); - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldOptions_clear_weak(google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 10); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_FieldOptions_weak(const google_protobuf_FieldOptions* msg) { bool default_val = false; bool ret; const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 10); - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FieldOptions_has_weak(const google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 10); - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldOptions_clear_unverified_lazy(google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 15); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_FieldOptions_unverified_lazy(const google_protobuf_FieldOptions* msg) { bool default_val = false; bool ret; const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 15); - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FieldOptions_has_unverified_lazy(const google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 15); - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldOptions_clear_debug_redact(google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 16); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_FieldOptions_debug_redact(const google_protobuf_FieldOptions* msg) { bool default_val = false; bool ret; const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 16); - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FieldOptions_has_debug_redact(const google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 16); - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldOptions_clear_retention(google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 17); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_FieldOptions_retention(const google_protobuf_FieldOptions* msg) { int32_t default_val = 0; int32_t ret; const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 17); - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FieldOptions_has_retention(const google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 17); - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldOptions_clear_targets(google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 19); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t const* google_protobuf_FieldOptions_targets(const google_protobuf_FieldOptions* msg, size_t* size) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 19); - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (int32_t const*)_upb_array_constptr(arr); @@ -3952,16 +4120,16 @@ UPB_INLINE int32_t const* google_protobuf_FieldOptions_targets(const google_prot } UPB_INLINE const upb_Array* _google_protobuf_FieldOptions_targets_upb_array(const google_protobuf_FieldOptions* msg, size_t* size) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 19); - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } -UPB_INLINE upb_Array* _google_protobuf_FieldOptions_targets_mutable_upb_array(const google_protobuf_FieldOptions* msg, size_t* size, upb_Arena* arena) { +UPB_INLINE upb_Array* _google_protobuf_FieldOptions_targets_mutable_upb_array(google_protobuf_FieldOptions* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 19); upb_Array* arr = upb_Message_GetOrCreateMutableArray( - (upb_Message*)msg, &field, arena); + UPB_UPCAST(msg), &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -3969,11 +4137,11 @@ UPB_INLINE upb_Array* _google_protobuf_FieldOptions_targets_mutable_upb_array(co } UPB_INLINE void google_protobuf_FieldOptions_clear_edition_defaults(google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 20); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_FieldOptions_EditionDefault* const* google_protobuf_FieldOptions_edition_defaults(const google_protobuf_FieldOptions* msg, size_t* size) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 20); - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_FieldOptions_EditionDefault* const*)_upb_array_constptr(arr); @@ -3984,16 +4152,16 @@ UPB_INLINE const google_protobuf_FieldOptions_EditionDefault* const* google_prot } UPB_INLINE const upb_Array* _google_protobuf_FieldOptions_edition_defaults_upb_array(const google_protobuf_FieldOptions* msg, size_t* size) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 20); - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } -UPB_INLINE upb_Array* _google_protobuf_FieldOptions_edition_defaults_mutable_upb_array(const google_protobuf_FieldOptions* msg, size_t* size, upb_Arena* arena) { +UPB_INLINE upb_Array* _google_protobuf_FieldOptions_edition_defaults_mutable_upb_array(google_protobuf_FieldOptions* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 20); upb_Array* arr = upb_Message_GetOrCreateMutableArray( - (upb_Message*)msg, &field, arena); + UPB_UPCAST(msg), &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -4001,26 +4169,27 @@ UPB_INLINE upb_Array* _google_protobuf_FieldOptions_edition_defaults_mutable_upb } UPB_INLINE void google_protobuf_FieldOptions_clear_features(google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 21); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_FeatureSet* google_protobuf_FieldOptions_features(const google_protobuf_FieldOptions* msg) { const google_protobuf_FeatureSet* default_val = NULL; const google_protobuf_FeatureSet* ret; const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 21); - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FieldOptions_has_features(const google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 21); - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldOptions_clear_uninterpreted_option(google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 999); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_FieldOptions_uninterpreted_option(const google_protobuf_FieldOptions* msg, size_t* size) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 999); - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_UninterpretedOption* const*)_upb_array_constptr(arr); @@ -4031,16 +4200,16 @@ UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_Fie } UPB_INLINE const upb_Array* _google_protobuf_FieldOptions_uninterpreted_option_upb_array(const google_protobuf_FieldOptions* msg, size_t* size) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 999); - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } -UPB_INLINE upb_Array* _google_protobuf_FieldOptions_uninterpreted_option_mutable_upb_array(const google_protobuf_FieldOptions* msg, size_t* size, upb_Arena* arena) { +UPB_INLINE upb_Array* _google_protobuf_FieldOptions_uninterpreted_option_mutable_upb_array(google_protobuf_FieldOptions* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 999); upb_Array* arr = upb_Message_GetOrCreateMutableArray( - (upb_Message*)msg, &field, arena); + UPB_UPCAST(msg), &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -4049,43 +4218,43 @@ UPB_INLINE upb_Array* _google_protobuf_FieldOptions_uninterpreted_option_mutable UPB_INLINE void google_protobuf_FieldOptions_set_ctype(google_protobuf_FieldOptions *msg, int32_t value) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 1); - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FieldOptions_set_packed(google_protobuf_FieldOptions *msg, bool value) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 2); - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FieldOptions_set_deprecated(google_protobuf_FieldOptions *msg, bool value) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 3); - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FieldOptions_set_lazy(google_protobuf_FieldOptions *msg, bool value) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 5); - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FieldOptions_set_jstype(google_protobuf_FieldOptions *msg, int32_t value) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 6); - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FieldOptions_set_weak(google_protobuf_FieldOptions *msg, bool value) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 10); - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FieldOptions_set_unverified_lazy(google_protobuf_FieldOptions *msg, bool value) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 15); - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FieldOptions_set_debug_redact(google_protobuf_FieldOptions *msg, bool value) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 16); - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FieldOptions_set_retention(google_protobuf_FieldOptions *msg, int32_t value) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 17); - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE int32_t* google_protobuf_FieldOptions_mutable_targets(google_protobuf_FieldOptions* msg, size_t* size) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 19); - upb_Array* arr = upb_Message_GetMutableArray(msg, &field); + upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (int32_t*)_upb_array_ptr(arr); @@ -4096,11 +4265,13 @@ UPB_INLINE int32_t* google_protobuf_FieldOptions_mutable_targets(google_protobuf } UPB_INLINE int32_t* google_protobuf_FieldOptions_resize_targets(google_protobuf_FieldOptions* msg, size_t size, upb_Arena* arena) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 19); - return (int32_t*)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); + return (int32_t*)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg), + &field, size, arena); } UPB_INLINE bool google_protobuf_FieldOptions_add_targets(google_protobuf_FieldOptions* msg, int32_t val, upb_Arena* arena) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 19); - upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray( + UPB_UPCAST(msg), &field, arena); if (!arr || !_upb_Array_ResizeUninitialized( arr, arr->UPB_PRIVATE(size) + 1, arena)) { return false; @@ -4111,7 +4282,7 @@ UPB_INLINE bool google_protobuf_FieldOptions_add_targets(google_protobuf_FieldOp } UPB_INLINE google_protobuf_FieldOptions_EditionDefault** google_protobuf_FieldOptions_mutable_edition_defaults(google_protobuf_FieldOptions* msg, size_t* size) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 20); - upb_Array* arr = upb_Message_GetMutableArray(msg, &field); + upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_FieldOptions_EditionDefault**)_upb_array_ptr(arr); @@ -4122,11 +4293,13 @@ UPB_INLINE google_protobuf_FieldOptions_EditionDefault** google_protobuf_FieldOp } UPB_INLINE google_protobuf_FieldOptions_EditionDefault** google_protobuf_FieldOptions_resize_edition_defaults(google_protobuf_FieldOptions* msg, size_t size, upb_Arena* arena) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 20); - return (google_protobuf_FieldOptions_EditionDefault**)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); + return (google_protobuf_FieldOptions_EditionDefault**)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg), + &field, size, arena); } UPB_INLINE struct google_protobuf_FieldOptions_EditionDefault* google_protobuf_FieldOptions_add_edition_defaults(google_protobuf_FieldOptions* msg, upb_Arena* arena) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 20); - upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray( + UPB_UPCAST(msg), &field, arena); if (!arr || !_upb_Array_ResizeUninitialized( arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; @@ -4139,7 +4312,7 @@ UPB_INLINE struct google_protobuf_FieldOptions_EditionDefault* google_protobuf_F } UPB_INLINE void google_protobuf_FieldOptions_set_features(google_protobuf_FieldOptions *msg, google_protobuf_FeatureSet* value) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 21); - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE struct google_protobuf_FeatureSet* google_protobuf_FieldOptions_mutable_features(google_protobuf_FieldOptions* msg, upb_Arena* arena) { struct google_protobuf_FeatureSet* sub = (struct google_protobuf_FeatureSet*)google_protobuf_FieldOptions_features(msg); @@ -4151,7 +4324,7 @@ UPB_INLINE struct google_protobuf_FeatureSet* google_protobuf_FieldOptions_mutab } UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_FieldOptions_mutable_uninterpreted_option(google_protobuf_FieldOptions* msg, size_t* size) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 999); - upb_Array* arr = upb_Message_GetMutableArray(msg, &field); + upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_UninterpretedOption**)_upb_array_ptr(arr); @@ -4162,11 +4335,13 @@ UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_FieldOptions_mu } UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_FieldOptions_resize_uninterpreted_option(google_protobuf_FieldOptions* msg, size_t size, upb_Arena* arena) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 999); - return (google_protobuf_UninterpretedOption**)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); + return (google_protobuf_UninterpretedOption**)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg), + &field, size, arena); } UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_FieldOptions_add_uninterpreted_option(google_protobuf_FieldOptions* msg, upb_Arena* arena) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 999); - upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray( + UPB_UPCAST(msg), &field, arena); if (!arr || !_upb_Array_ResizeUninitialized( arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; @@ -4186,7 +4361,8 @@ UPB_INLINE google_protobuf_FieldOptions_EditionDefault* google_protobuf_FieldOpt UPB_INLINE google_protobuf_FieldOptions_EditionDefault* google_protobuf_FieldOptions_EditionDefault_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_FieldOptions_EditionDefault* ret = google_protobuf_FieldOptions_EditionDefault_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, google__protobuf__FieldOptions__EditionDefault_msg_init(), NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), google__protobuf__FieldOptions__EditionDefault_msg_init(), NULL, 0, arena) != + kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -4196,61 +4372,63 @@ UPB_INLINE google_protobuf_FieldOptions_EditionDefault* google_protobuf_FieldOpt int options, upb_Arena* arena) { google_protobuf_FieldOptions_EditionDefault* ret = google_protobuf_FieldOptions_EditionDefault_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, google__protobuf__FieldOptions__EditionDefault_msg_init(), extreg, options, arena) != - kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), google__protobuf__FieldOptions__EditionDefault_msg_init(), extreg, options, + arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_FieldOptions_EditionDefault_serialize(const google_protobuf_FieldOptions_EditionDefault* msg, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, google__protobuf__FieldOptions__EditionDefault_msg_init(), 0, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), google__protobuf__FieldOptions__EditionDefault_msg_init(), 0, arena, &ptr, len); return ptr; } UPB_INLINE char* google_protobuf_FieldOptions_EditionDefault_serialize_ex(const google_protobuf_FieldOptions_EditionDefault* msg, int options, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, google__protobuf__FieldOptions__EditionDefault_msg_init(), options, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), google__protobuf__FieldOptions__EditionDefault_msg_init(), options, arena, &ptr, len); return ptr; } UPB_INLINE void google_protobuf_FieldOptions_EditionDefault_clear_value(google_protobuf_FieldOptions_EditionDefault* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions__EditionDefault_msg_init(), 2); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_FieldOptions_EditionDefault_value(const google_protobuf_FieldOptions_EditionDefault* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions__EditionDefault_msg_init(), 2); - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FieldOptions_EditionDefault_has_value(const google_protobuf_FieldOptions_EditionDefault* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions__EditionDefault_msg_init(), 2); - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldOptions_EditionDefault_clear_edition(google_protobuf_FieldOptions_EditionDefault* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions__EditionDefault_msg_init(), 3); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_FieldOptions_EditionDefault_edition(const google_protobuf_FieldOptions_EditionDefault* msg) { int32_t default_val = 0; int32_t ret; const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions__EditionDefault_msg_init(), 3); - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FieldOptions_EditionDefault_has_edition(const google_protobuf_FieldOptions_EditionDefault* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions__EditionDefault_msg_init(), 3); - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldOptions_EditionDefault_set_value(google_protobuf_FieldOptions_EditionDefault *msg, upb_StringView value) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions__EditionDefault_msg_init(), 2); - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FieldOptions_EditionDefault_set_edition(google_protobuf_FieldOptions_EditionDefault *msg, int32_t value) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions__EditionDefault_msg_init(), 3); - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } /* google.protobuf.OneofOptions */ @@ -4261,7 +4439,8 @@ UPB_INLINE google_protobuf_OneofOptions* google_protobuf_OneofOptions_new(upb_Ar UPB_INLINE google_protobuf_OneofOptions* google_protobuf_OneofOptions_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_OneofOptions* ret = google_protobuf_OneofOptions_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, google__protobuf__OneofOptions_msg_init(), NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), google__protobuf__OneofOptions_msg_init(), NULL, 0, arena) != + kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -4271,45 +4450,46 @@ UPB_INLINE google_protobuf_OneofOptions* google_protobuf_OneofOptions_parse_ex(c int options, upb_Arena* arena) { google_protobuf_OneofOptions* ret = google_protobuf_OneofOptions_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, google__protobuf__OneofOptions_msg_init(), extreg, options, arena) != - kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), google__protobuf__OneofOptions_msg_init(), extreg, options, + arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_OneofOptions_serialize(const google_protobuf_OneofOptions* msg, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, google__protobuf__OneofOptions_msg_init(), 0, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), google__protobuf__OneofOptions_msg_init(), 0, arena, &ptr, len); return ptr; } UPB_INLINE char* google_protobuf_OneofOptions_serialize_ex(const google_protobuf_OneofOptions* msg, int options, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, google__protobuf__OneofOptions_msg_init(), options, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), google__protobuf__OneofOptions_msg_init(), options, arena, &ptr, len); return ptr; } UPB_INLINE void google_protobuf_OneofOptions_clear_features(google_protobuf_OneofOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__OneofOptions_msg_init(), 1); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_FeatureSet* google_protobuf_OneofOptions_features(const google_protobuf_OneofOptions* msg) { const google_protobuf_FeatureSet* default_val = NULL; const google_protobuf_FeatureSet* ret; const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__OneofOptions_msg_init(), 1); - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_OneofOptions_has_features(const google_protobuf_OneofOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__OneofOptions_msg_init(), 1); - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_OneofOptions_clear_uninterpreted_option(google_protobuf_OneofOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__OneofOptions_msg_init(), 999); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_OneofOptions_uninterpreted_option(const google_protobuf_OneofOptions* msg, size_t* size) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__OneofOptions_msg_init(), 999); - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_UninterpretedOption* const*)_upb_array_constptr(arr); @@ -4320,16 +4500,16 @@ UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_One } UPB_INLINE const upb_Array* _google_protobuf_OneofOptions_uninterpreted_option_upb_array(const google_protobuf_OneofOptions* msg, size_t* size) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__OneofOptions_msg_init(), 999); - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } -UPB_INLINE upb_Array* _google_protobuf_OneofOptions_uninterpreted_option_mutable_upb_array(const google_protobuf_OneofOptions* msg, size_t* size, upb_Arena* arena) { +UPB_INLINE upb_Array* _google_protobuf_OneofOptions_uninterpreted_option_mutable_upb_array(google_protobuf_OneofOptions* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__OneofOptions_msg_init(), 999); upb_Array* arr = upb_Message_GetOrCreateMutableArray( - (upb_Message*)msg, &field, arena); + UPB_UPCAST(msg), &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -4338,7 +4518,7 @@ UPB_INLINE upb_Array* _google_protobuf_OneofOptions_uninterpreted_option_mutable UPB_INLINE void google_protobuf_OneofOptions_set_features(google_protobuf_OneofOptions *msg, google_protobuf_FeatureSet* value) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__OneofOptions_msg_init(), 1); - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE struct google_protobuf_FeatureSet* google_protobuf_OneofOptions_mutable_features(google_protobuf_OneofOptions* msg, upb_Arena* arena) { struct google_protobuf_FeatureSet* sub = (struct google_protobuf_FeatureSet*)google_protobuf_OneofOptions_features(msg); @@ -4350,7 +4530,7 @@ UPB_INLINE struct google_protobuf_FeatureSet* google_protobuf_OneofOptions_mutab } UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_OneofOptions_mutable_uninterpreted_option(google_protobuf_OneofOptions* msg, size_t* size) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__OneofOptions_msg_init(), 999); - upb_Array* arr = upb_Message_GetMutableArray(msg, &field); + upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_UninterpretedOption**)_upb_array_ptr(arr); @@ -4361,11 +4541,13 @@ UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_OneofOptions_mu } UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_OneofOptions_resize_uninterpreted_option(google_protobuf_OneofOptions* msg, size_t size, upb_Arena* arena) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__OneofOptions_msg_init(), 999); - return (google_protobuf_UninterpretedOption**)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); + return (google_protobuf_UninterpretedOption**)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg), + &field, size, arena); } UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_OneofOptions_add_uninterpreted_option(google_protobuf_OneofOptions* msg, upb_Arena* arena) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__OneofOptions_msg_init(), 999); - upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray( + UPB_UPCAST(msg), &field, arena); if (!arr || !_upb_Array_ResizeUninitialized( arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; @@ -4385,7 +4567,8 @@ UPB_INLINE google_protobuf_EnumOptions* google_protobuf_EnumOptions_new(upb_Aren UPB_INLINE google_protobuf_EnumOptions* google_protobuf_EnumOptions_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_EnumOptions* ret = google_protobuf_EnumOptions_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, google__protobuf__EnumOptions_msg_init(), NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), google__protobuf__EnumOptions_msg_init(), NULL, 0, arena) != + kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -4395,90 +4578,94 @@ UPB_INLINE google_protobuf_EnumOptions* google_protobuf_EnumOptions_parse_ex(con int options, upb_Arena* arena) { google_protobuf_EnumOptions* ret = google_protobuf_EnumOptions_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, google__protobuf__EnumOptions_msg_init(), extreg, options, arena) != - kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), google__protobuf__EnumOptions_msg_init(), extreg, options, + arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_EnumOptions_serialize(const google_protobuf_EnumOptions* msg, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, google__protobuf__EnumOptions_msg_init(), 0, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), google__protobuf__EnumOptions_msg_init(), 0, arena, &ptr, len); return ptr; } UPB_INLINE char* google_protobuf_EnumOptions_serialize_ex(const google_protobuf_EnumOptions* msg, int options, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, google__protobuf__EnumOptions_msg_init(), options, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), google__protobuf__EnumOptions_msg_init(), options, arena, &ptr, len); return ptr; } UPB_INLINE void google_protobuf_EnumOptions_clear_allow_alias(google_protobuf_EnumOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumOptions_msg_init(), 2); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_EnumOptions_allow_alias(const google_protobuf_EnumOptions* msg) { bool default_val = false; bool ret; const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumOptions_msg_init(), 2); - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_EnumOptions_has_allow_alias(const google_protobuf_EnumOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumOptions_msg_init(), 2); - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_EnumOptions_clear_deprecated(google_protobuf_EnumOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumOptions_msg_init(), 3); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_EnumOptions_deprecated(const google_protobuf_EnumOptions* msg) { bool default_val = false; bool ret; const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumOptions_msg_init(), 3); - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_EnumOptions_has_deprecated(const google_protobuf_EnumOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumOptions_msg_init(), 3); - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_EnumOptions_clear_deprecated_legacy_json_field_conflicts(google_protobuf_EnumOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumOptions_msg_init(), 6); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_EnumOptions_deprecated_legacy_json_field_conflicts(const google_protobuf_EnumOptions* msg) { bool default_val = false; bool ret; const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumOptions_msg_init(), 6); - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_EnumOptions_has_deprecated_legacy_json_field_conflicts(const google_protobuf_EnumOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumOptions_msg_init(), 6); - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_EnumOptions_clear_features(google_protobuf_EnumOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumOptions_msg_init(), 7); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_FeatureSet* google_protobuf_EnumOptions_features(const google_protobuf_EnumOptions* msg) { const google_protobuf_FeatureSet* default_val = NULL; const google_protobuf_FeatureSet* ret; const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumOptions_msg_init(), 7); - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_EnumOptions_has_features(const google_protobuf_EnumOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumOptions_msg_init(), 7); - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_EnumOptions_clear_uninterpreted_option(google_protobuf_EnumOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumOptions_msg_init(), 999); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_EnumOptions_uninterpreted_option(const google_protobuf_EnumOptions* msg, size_t* size) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumOptions_msg_init(), 999); - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_UninterpretedOption* const*)_upb_array_constptr(arr); @@ -4489,16 +4676,16 @@ UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_Enu } UPB_INLINE const upb_Array* _google_protobuf_EnumOptions_uninterpreted_option_upb_array(const google_protobuf_EnumOptions* msg, size_t* size) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumOptions_msg_init(), 999); - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } -UPB_INLINE upb_Array* _google_protobuf_EnumOptions_uninterpreted_option_mutable_upb_array(const google_protobuf_EnumOptions* msg, size_t* size, upb_Arena* arena) { +UPB_INLINE upb_Array* _google_protobuf_EnumOptions_uninterpreted_option_mutable_upb_array(google_protobuf_EnumOptions* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumOptions_msg_init(), 999); upb_Array* arr = upb_Message_GetOrCreateMutableArray( - (upb_Message*)msg, &field, arena); + UPB_UPCAST(msg), &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -4507,19 +4694,19 @@ UPB_INLINE upb_Array* _google_protobuf_EnumOptions_uninterpreted_option_mutable_ UPB_INLINE void google_protobuf_EnumOptions_set_allow_alias(google_protobuf_EnumOptions *msg, bool value) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumOptions_msg_init(), 2); - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_EnumOptions_set_deprecated(google_protobuf_EnumOptions *msg, bool value) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumOptions_msg_init(), 3); - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_EnumOptions_set_deprecated_legacy_json_field_conflicts(google_protobuf_EnumOptions *msg, bool value) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumOptions_msg_init(), 6); - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_EnumOptions_set_features(google_protobuf_EnumOptions *msg, google_protobuf_FeatureSet* value) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumOptions_msg_init(), 7); - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE struct google_protobuf_FeatureSet* google_protobuf_EnumOptions_mutable_features(google_protobuf_EnumOptions* msg, upb_Arena* arena) { struct google_protobuf_FeatureSet* sub = (struct google_protobuf_FeatureSet*)google_protobuf_EnumOptions_features(msg); @@ -4531,7 +4718,7 @@ UPB_INLINE struct google_protobuf_FeatureSet* google_protobuf_EnumOptions_mutabl } UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_EnumOptions_mutable_uninterpreted_option(google_protobuf_EnumOptions* msg, size_t* size) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumOptions_msg_init(), 999); - upb_Array* arr = upb_Message_GetMutableArray(msg, &field); + upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_UninterpretedOption**)_upb_array_ptr(arr); @@ -4542,11 +4729,13 @@ UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_EnumOptions_mut } UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_EnumOptions_resize_uninterpreted_option(google_protobuf_EnumOptions* msg, size_t size, upb_Arena* arena) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumOptions_msg_init(), 999); - return (google_protobuf_UninterpretedOption**)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); + return (google_protobuf_UninterpretedOption**)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg), + &field, size, arena); } UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_EnumOptions_add_uninterpreted_option(google_protobuf_EnumOptions* msg, upb_Arena* arena) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumOptions_msg_init(), 999); - upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray( + UPB_UPCAST(msg), &field, arena); if (!arr || !_upb_Array_ResizeUninitialized( arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; @@ -4566,7 +4755,8 @@ UPB_INLINE google_protobuf_EnumValueOptions* google_protobuf_EnumValueOptions_ne UPB_INLINE google_protobuf_EnumValueOptions* google_protobuf_EnumValueOptions_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_EnumValueOptions* ret = google_protobuf_EnumValueOptions_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, google__protobuf__EnumValueOptions_msg_init(), NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), google__protobuf__EnumValueOptions_msg_init(), NULL, 0, arena) != + kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -4576,75 +4766,78 @@ UPB_INLINE google_protobuf_EnumValueOptions* google_protobuf_EnumValueOptions_pa int options, upb_Arena* arena) { google_protobuf_EnumValueOptions* ret = google_protobuf_EnumValueOptions_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, google__protobuf__EnumValueOptions_msg_init(), extreg, options, arena) != - kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), google__protobuf__EnumValueOptions_msg_init(), extreg, options, + arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_EnumValueOptions_serialize(const google_protobuf_EnumValueOptions* msg, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, google__protobuf__EnumValueOptions_msg_init(), 0, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), google__protobuf__EnumValueOptions_msg_init(), 0, arena, &ptr, len); return ptr; } UPB_INLINE char* google_protobuf_EnumValueOptions_serialize_ex(const google_protobuf_EnumValueOptions* msg, int options, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, google__protobuf__EnumValueOptions_msg_init(), options, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), google__protobuf__EnumValueOptions_msg_init(), options, arena, &ptr, len); return ptr; } UPB_INLINE void google_protobuf_EnumValueOptions_clear_deprecated(google_protobuf_EnumValueOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumValueOptions_msg_init(), 1); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_EnumValueOptions_deprecated(const google_protobuf_EnumValueOptions* msg) { bool default_val = false; bool ret; const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumValueOptions_msg_init(), 1); - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_EnumValueOptions_has_deprecated(const google_protobuf_EnumValueOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumValueOptions_msg_init(), 1); - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_EnumValueOptions_clear_features(google_protobuf_EnumValueOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumValueOptions_msg_init(), 2); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_FeatureSet* google_protobuf_EnumValueOptions_features(const google_protobuf_EnumValueOptions* msg) { const google_protobuf_FeatureSet* default_val = NULL; const google_protobuf_FeatureSet* ret; const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumValueOptions_msg_init(), 2); - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_EnumValueOptions_has_features(const google_protobuf_EnumValueOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumValueOptions_msg_init(), 2); - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_EnumValueOptions_clear_debug_redact(google_protobuf_EnumValueOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumValueOptions_msg_init(), 3); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_EnumValueOptions_debug_redact(const google_protobuf_EnumValueOptions* msg) { bool default_val = false; bool ret; const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumValueOptions_msg_init(), 3); - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_EnumValueOptions_has_debug_redact(const google_protobuf_EnumValueOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumValueOptions_msg_init(), 3); - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_EnumValueOptions_clear_uninterpreted_option(google_protobuf_EnumValueOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumValueOptions_msg_init(), 999); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_EnumValueOptions_uninterpreted_option(const google_protobuf_EnumValueOptions* msg, size_t* size) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumValueOptions_msg_init(), 999); - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_UninterpretedOption* const*)_upb_array_constptr(arr); @@ -4655,16 +4848,16 @@ UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_Enu } UPB_INLINE const upb_Array* _google_protobuf_EnumValueOptions_uninterpreted_option_upb_array(const google_protobuf_EnumValueOptions* msg, size_t* size) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumValueOptions_msg_init(), 999); - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } -UPB_INLINE upb_Array* _google_protobuf_EnumValueOptions_uninterpreted_option_mutable_upb_array(const google_protobuf_EnumValueOptions* msg, size_t* size, upb_Arena* arena) { +UPB_INLINE upb_Array* _google_protobuf_EnumValueOptions_uninterpreted_option_mutable_upb_array(google_protobuf_EnumValueOptions* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumValueOptions_msg_init(), 999); upb_Array* arr = upb_Message_GetOrCreateMutableArray( - (upb_Message*)msg, &field, arena); + UPB_UPCAST(msg), &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -4673,11 +4866,11 @@ UPB_INLINE upb_Array* _google_protobuf_EnumValueOptions_uninterpreted_option_mut UPB_INLINE void google_protobuf_EnumValueOptions_set_deprecated(google_protobuf_EnumValueOptions *msg, bool value) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumValueOptions_msg_init(), 1); - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_EnumValueOptions_set_features(google_protobuf_EnumValueOptions *msg, google_protobuf_FeatureSet* value) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumValueOptions_msg_init(), 2); - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE struct google_protobuf_FeatureSet* google_protobuf_EnumValueOptions_mutable_features(google_protobuf_EnumValueOptions* msg, upb_Arena* arena) { struct google_protobuf_FeatureSet* sub = (struct google_protobuf_FeatureSet*)google_protobuf_EnumValueOptions_features(msg); @@ -4689,11 +4882,11 @@ UPB_INLINE struct google_protobuf_FeatureSet* google_protobuf_EnumValueOptions_m } UPB_INLINE void google_protobuf_EnumValueOptions_set_debug_redact(google_protobuf_EnumValueOptions *msg, bool value) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumValueOptions_msg_init(), 3); - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_EnumValueOptions_mutable_uninterpreted_option(google_protobuf_EnumValueOptions* msg, size_t* size) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumValueOptions_msg_init(), 999); - upb_Array* arr = upb_Message_GetMutableArray(msg, &field); + upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_UninterpretedOption**)_upb_array_ptr(arr); @@ -4704,11 +4897,13 @@ UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_EnumValueOption } UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_EnumValueOptions_resize_uninterpreted_option(google_protobuf_EnumValueOptions* msg, size_t size, upb_Arena* arena) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumValueOptions_msg_init(), 999); - return (google_protobuf_UninterpretedOption**)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); + return (google_protobuf_UninterpretedOption**)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg), + &field, size, arena); } UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_EnumValueOptions_add_uninterpreted_option(google_protobuf_EnumValueOptions* msg, upb_Arena* arena) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumValueOptions_msg_init(), 999); - upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray( + UPB_UPCAST(msg), &field, arena); if (!arr || !_upb_Array_ResizeUninitialized( arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; @@ -4728,7 +4923,8 @@ UPB_INLINE google_protobuf_ServiceOptions* google_protobuf_ServiceOptions_new(up UPB_INLINE google_protobuf_ServiceOptions* google_protobuf_ServiceOptions_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_ServiceOptions* ret = google_protobuf_ServiceOptions_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, google__protobuf__ServiceOptions_msg_init(), NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), google__protobuf__ServiceOptions_msg_init(), NULL, 0, arena) != + kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -4738,60 +4934,62 @@ UPB_INLINE google_protobuf_ServiceOptions* google_protobuf_ServiceOptions_parse_ int options, upb_Arena* arena) { google_protobuf_ServiceOptions* ret = google_protobuf_ServiceOptions_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, google__protobuf__ServiceOptions_msg_init(), extreg, options, arena) != - kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), google__protobuf__ServiceOptions_msg_init(), extreg, options, + arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_ServiceOptions_serialize(const google_protobuf_ServiceOptions* msg, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, google__protobuf__ServiceOptions_msg_init(), 0, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), google__protobuf__ServiceOptions_msg_init(), 0, arena, &ptr, len); return ptr; } UPB_INLINE char* google_protobuf_ServiceOptions_serialize_ex(const google_protobuf_ServiceOptions* msg, int options, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, google__protobuf__ServiceOptions_msg_init(), options, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), google__protobuf__ServiceOptions_msg_init(), options, arena, &ptr, len); return ptr; } UPB_INLINE void google_protobuf_ServiceOptions_clear_deprecated(google_protobuf_ServiceOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ServiceOptions_msg_init(), 33); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_ServiceOptions_deprecated(const google_protobuf_ServiceOptions* msg) { bool default_val = false; bool ret; const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ServiceOptions_msg_init(), 33); - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_ServiceOptions_has_deprecated(const google_protobuf_ServiceOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ServiceOptions_msg_init(), 33); - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_ServiceOptions_clear_features(google_protobuf_ServiceOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ServiceOptions_msg_init(), 34); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_FeatureSet* google_protobuf_ServiceOptions_features(const google_protobuf_ServiceOptions* msg) { const google_protobuf_FeatureSet* default_val = NULL; const google_protobuf_FeatureSet* ret; const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ServiceOptions_msg_init(), 34); - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_ServiceOptions_has_features(const google_protobuf_ServiceOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ServiceOptions_msg_init(), 34); - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_ServiceOptions_clear_uninterpreted_option(google_protobuf_ServiceOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ServiceOptions_msg_init(), 999); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_ServiceOptions_uninterpreted_option(const google_protobuf_ServiceOptions* msg, size_t* size) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ServiceOptions_msg_init(), 999); - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_UninterpretedOption* const*)_upb_array_constptr(arr); @@ -4802,16 +5000,16 @@ UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_Ser } UPB_INLINE const upb_Array* _google_protobuf_ServiceOptions_uninterpreted_option_upb_array(const google_protobuf_ServiceOptions* msg, size_t* size) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ServiceOptions_msg_init(), 999); - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } -UPB_INLINE upb_Array* _google_protobuf_ServiceOptions_uninterpreted_option_mutable_upb_array(const google_protobuf_ServiceOptions* msg, size_t* size, upb_Arena* arena) { +UPB_INLINE upb_Array* _google_protobuf_ServiceOptions_uninterpreted_option_mutable_upb_array(google_protobuf_ServiceOptions* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ServiceOptions_msg_init(), 999); upb_Array* arr = upb_Message_GetOrCreateMutableArray( - (upb_Message*)msg, &field, arena); + UPB_UPCAST(msg), &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -4820,11 +5018,11 @@ UPB_INLINE upb_Array* _google_protobuf_ServiceOptions_uninterpreted_option_mutab UPB_INLINE void google_protobuf_ServiceOptions_set_deprecated(google_protobuf_ServiceOptions *msg, bool value) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ServiceOptions_msg_init(), 33); - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_ServiceOptions_set_features(google_protobuf_ServiceOptions *msg, google_protobuf_FeatureSet* value) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ServiceOptions_msg_init(), 34); - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE struct google_protobuf_FeatureSet* google_protobuf_ServiceOptions_mutable_features(google_protobuf_ServiceOptions* msg, upb_Arena* arena) { struct google_protobuf_FeatureSet* sub = (struct google_protobuf_FeatureSet*)google_protobuf_ServiceOptions_features(msg); @@ -4836,7 +5034,7 @@ UPB_INLINE struct google_protobuf_FeatureSet* google_protobuf_ServiceOptions_mut } UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_ServiceOptions_mutable_uninterpreted_option(google_protobuf_ServiceOptions* msg, size_t* size) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ServiceOptions_msg_init(), 999); - upb_Array* arr = upb_Message_GetMutableArray(msg, &field); + upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_UninterpretedOption**)_upb_array_ptr(arr); @@ -4847,11 +5045,13 @@ UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_ServiceOptions_ } UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_ServiceOptions_resize_uninterpreted_option(google_protobuf_ServiceOptions* msg, size_t size, upb_Arena* arena) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ServiceOptions_msg_init(), 999); - return (google_protobuf_UninterpretedOption**)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); + return (google_protobuf_UninterpretedOption**)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg), + &field, size, arena); } UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_ServiceOptions_add_uninterpreted_option(google_protobuf_ServiceOptions* msg, upb_Arena* arena) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ServiceOptions_msg_init(), 999); - upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray( + UPB_UPCAST(msg), &field, arena); if (!arr || !_upb_Array_ResizeUninitialized( arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; @@ -4871,7 +5071,8 @@ UPB_INLINE google_protobuf_MethodOptions* google_protobuf_MethodOptions_new(upb_ UPB_INLINE google_protobuf_MethodOptions* google_protobuf_MethodOptions_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_MethodOptions* ret = google_protobuf_MethodOptions_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, google__protobuf__MethodOptions_msg_init(), NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), google__protobuf__MethodOptions_msg_init(), NULL, 0, arena) != + kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -4881,75 +5082,78 @@ UPB_INLINE google_protobuf_MethodOptions* google_protobuf_MethodOptions_parse_ex int options, upb_Arena* arena) { google_protobuf_MethodOptions* ret = google_protobuf_MethodOptions_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, google__protobuf__MethodOptions_msg_init(), extreg, options, arena) != - kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), google__protobuf__MethodOptions_msg_init(), extreg, options, + arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_MethodOptions_serialize(const google_protobuf_MethodOptions* msg, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, google__protobuf__MethodOptions_msg_init(), 0, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), google__protobuf__MethodOptions_msg_init(), 0, arena, &ptr, len); return ptr; } UPB_INLINE char* google_protobuf_MethodOptions_serialize_ex(const google_protobuf_MethodOptions* msg, int options, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, google__protobuf__MethodOptions_msg_init(), options, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), google__protobuf__MethodOptions_msg_init(), options, arena, &ptr, len); return ptr; } UPB_INLINE void google_protobuf_MethodOptions_clear_deprecated(google_protobuf_MethodOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MethodOptions_msg_init(), 33); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_MethodOptions_deprecated(const google_protobuf_MethodOptions* msg) { bool default_val = false; bool ret; const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MethodOptions_msg_init(), 33); - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_MethodOptions_has_deprecated(const google_protobuf_MethodOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MethodOptions_msg_init(), 33); - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_MethodOptions_clear_idempotency_level(google_protobuf_MethodOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MethodOptions_msg_init(), 34); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_MethodOptions_idempotency_level(const google_protobuf_MethodOptions* msg) { int32_t default_val = 0; int32_t ret; const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MethodOptions_msg_init(), 34); - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_MethodOptions_has_idempotency_level(const google_protobuf_MethodOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MethodOptions_msg_init(), 34); - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_MethodOptions_clear_features(google_protobuf_MethodOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MethodOptions_msg_init(), 35); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_FeatureSet* google_protobuf_MethodOptions_features(const google_protobuf_MethodOptions* msg) { const google_protobuf_FeatureSet* default_val = NULL; const google_protobuf_FeatureSet* ret; const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MethodOptions_msg_init(), 35); - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_MethodOptions_has_features(const google_protobuf_MethodOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MethodOptions_msg_init(), 35); - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_MethodOptions_clear_uninterpreted_option(google_protobuf_MethodOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MethodOptions_msg_init(), 999); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_MethodOptions_uninterpreted_option(const google_protobuf_MethodOptions* msg, size_t* size) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MethodOptions_msg_init(), 999); - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_UninterpretedOption* const*)_upb_array_constptr(arr); @@ -4960,16 +5164,16 @@ UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_Met } UPB_INLINE const upb_Array* _google_protobuf_MethodOptions_uninterpreted_option_upb_array(const google_protobuf_MethodOptions* msg, size_t* size) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MethodOptions_msg_init(), 999); - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } -UPB_INLINE upb_Array* _google_protobuf_MethodOptions_uninterpreted_option_mutable_upb_array(const google_protobuf_MethodOptions* msg, size_t* size, upb_Arena* arena) { +UPB_INLINE upb_Array* _google_protobuf_MethodOptions_uninterpreted_option_mutable_upb_array(google_protobuf_MethodOptions* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MethodOptions_msg_init(), 999); upb_Array* arr = upb_Message_GetOrCreateMutableArray( - (upb_Message*)msg, &field, arena); + UPB_UPCAST(msg), &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -4978,15 +5182,15 @@ UPB_INLINE upb_Array* _google_protobuf_MethodOptions_uninterpreted_option_mutabl UPB_INLINE void google_protobuf_MethodOptions_set_deprecated(google_protobuf_MethodOptions *msg, bool value) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MethodOptions_msg_init(), 33); - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_MethodOptions_set_idempotency_level(google_protobuf_MethodOptions *msg, int32_t value) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MethodOptions_msg_init(), 34); - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_MethodOptions_set_features(google_protobuf_MethodOptions *msg, google_protobuf_FeatureSet* value) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MethodOptions_msg_init(), 35); - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE struct google_protobuf_FeatureSet* google_protobuf_MethodOptions_mutable_features(google_protobuf_MethodOptions* msg, upb_Arena* arena) { struct google_protobuf_FeatureSet* sub = (struct google_protobuf_FeatureSet*)google_protobuf_MethodOptions_features(msg); @@ -4998,7 +5202,7 @@ UPB_INLINE struct google_protobuf_FeatureSet* google_protobuf_MethodOptions_muta } UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_MethodOptions_mutable_uninterpreted_option(google_protobuf_MethodOptions* msg, size_t* size) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MethodOptions_msg_init(), 999); - upb_Array* arr = upb_Message_GetMutableArray(msg, &field); + upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_UninterpretedOption**)_upb_array_ptr(arr); @@ -5009,11 +5213,13 @@ UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_MethodOptions_m } UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_MethodOptions_resize_uninterpreted_option(google_protobuf_MethodOptions* msg, size_t size, upb_Arena* arena) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MethodOptions_msg_init(), 999); - return (google_protobuf_UninterpretedOption**)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); + return (google_protobuf_UninterpretedOption**)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg), + &field, size, arena); } UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_MethodOptions_add_uninterpreted_option(google_protobuf_MethodOptions* msg, upb_Arena* arena) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MethodOptions_msg_init(), 999); - upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray( + UPB_UPCAST(msg), &field, arena); if (!arr || !_upb_Array_ResizeUninitialized( arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; @@ -5033,7 +5239,8 @@ UPB_INLINE google_protobuf_UninterpretedOption* google_protobuf_UninterpretedOpt UPB_INLINE google_protobuf_UninterpretedOption* google_protobuf_UninterpretedOption_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_UninterpretedOption* ret = google_protobuf_UninterpretedOption_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, google__protobuf__UninterpretedOption_msg_init(), NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), google__protobuf__UninterpretedOption_msg_init(), NULL, 0, arena) != + kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -5043,30 +5250,30 @@ UPB_INLINE google_protobuf_UninterpretedOption* google_protobuf_UninterpretedOpt int options, upb_Arena* arena) { google_protobuf_UninterpretedOption* ret = google_protobuf_UninterpretedOption_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, google__protobuf__UninterpretedOption_msg_init(), extreg, options, arena) != - kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), google__protobuf__UninterpretedOption_msg_init(), extreg, options, + arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_UninterpretedOption_serialize(const google_protobuf_UninterpretedOption* msg, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, google__protobuf__UninterpretedOption_msg_init(), 0, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), google__protobuf__UninterpretedOption_msg_init(), 0, arena, &ptr, len); return ptr; } UPB_INLINE char* google_protobuf_UninterpretedOption_serialize_ex(const google_protobuf_UninterpretedOption* msg, int options, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, google__protobuf__UninterpretedOption_msg_init(), options, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), google__protobuf__UninterpretedOption_msg_init(), options, arena, &ptr, len); return ptr; } UPB_INLINE void google_protobuf_UninterpretedOption_clear_name(google_protobuf_UninterpretedOption* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__UninterpretedOption_msg_init(), 2); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_UninterpretedOption_NamePart* const* google_protobuf_UninterpretedOption_name(const google_protobuf_UninterpretedOption* msg, size_t* size) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__UninterpretedOption_msg_init(), 2); - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_UninterpretedOption_NamePart* const*)_upb_array_constptr(arr); @@ -5077,16 +5284,16 @@ UPB_INLINE const google_protobuf_UninterpretedOption_NamePart* const* google_pro } UPB_INLINE const upb_Array* _google_protobuf_UninterpretedOption_name_upb_array(const google_protobuf_UninterpretedOption* msg, size_t* size) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__UninterpretedOption_msg_init(), 2); - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } -UPB_INLINE upb_Array* _google_protobuf_UninterpretedOption_name_mutable_upb_array(const google_protobuf_UninterpretedOption* msg, size_t* size, upb_Arena* arena) { +UPB_INLINE upb_Array* _google_protobuf_UninterpretedOption_name_mutable_upb_array(google_protobuf_UninterpretedOption* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__UninterpretedOption_msg_init(), 2); upb_Array* arr = upb_Message_GetOrCreateMutableArray( - (upb_Message*)msg, &field, arena); + UPB_UPCAST(msg), &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -5094,98 +5301,104 @@ UPB_INLINE upb_Array* _google_protobuf_UninterpretedOption_name_mutable_upb_arra } UPB_INLINE void google_protobuf_UninterpretedOption_clear_identifier_value(google_protobuf_UninterpretedOption* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__UninterpretedOption_msg_init(), 3); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_UninterpretedOption_identifier_value(const google_protobuf_UninterpretedOption* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__UninterpretedOption_msg_init(), 3); - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_UninterpretedOption_has_identifier_value(const google_protobuf_UninterpretedOption* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__UninterpretedOption_msg_init(), 3); - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_UninterpretedOption_clear_positive_int_value(google_protobuf_UninterpretedOption* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__UninterpretedOption_msg_init(), 4); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE uint64_t google_protobuf_UninterpretedOption_positive_int_value(const google_protobuf_UninterpretedOption* msg) { uint64_t default_val = (uint64_t)0ull; uint64_t ret; const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__UninterpretedOption_msg_init(), 4); - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_UninterpretedOption_has_positive_int_value(const google_protobuf_UninterpretedOption* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__UninterpretedOption_msg_init(), 4); - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_UninterpretedOption_clear_negative_int_value(google_protobuf_UninterpretedOption* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__UninterpretedOption_msg_init(), 5); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE int64_t google_protobuf_UninterpretedOption_negative_int_value(const google_protobuf_UninterpretedOption* msg) { int64_t default_val = (int64_t)0ll; int64_t ret; const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__UninterpretedOption_msg_init(), 5); - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_UninterpretedOption_has_negative_int_value(const google_protobuf_UninterpretedOption* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__UninterpretedOption_msg_init(), 5); - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_UninterpretedOption_clear_double_value(google_protobuf_UninterpretedOption* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__UninterpretedOption_msg_init(), 6); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE double google_protobuf_UninterpretedOption_double_value(const google_protobuf_UninterpretedOption* msg) { double default_val = 0; double ret; const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__UninterpretedOption_msg_init(), 6); - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_UninterpretedOption_has_double_value(const google_protobuf_UninterpretedOption* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__UninterpretedOption_msg_init(), 6); - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_UninterpretedOption_clear_string_value(google_protobuf_UninterpretedOption* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__UninterpretedOption_msg_init(), 7); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_UninterpretedOption_string_value(const google_protobuf_UninterpretedOption* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__UninterpretedOption_msg_init(), 7); - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_UninterpretedOption_has_string_value(const google_protobuf_UninterpretedOption* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__UninterpretedOption_msg_init(), 7); - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_UninterpretedOption_clear_aggregate_value(google_protobuf_UninterpretedOption* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__UninterpretedOption_msg_init(), 8); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_UninterpretedOption_aggregate_value(const google_protobuf_UninterpretedOption* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__UninterpretedOption_msg_init(), 8); - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_UninterpretedOption_has_aggregate_value(const google_protobuf_UninterpretedOption* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__UninterpretedOption_msg_init(), 8); - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE google_protobuf_UninterpretedOption_NamePart** google_protobuf_UninterpretedOption_mutable_name(google_protobuf_UninterpretedOption* msg, size_t* size) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__UninterpretedOption_msg_init(), 2); - upb_Array* arr = upb_Message_GetMutableArray(msg, &field); + upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_UninterpretedOption_NamePart**)_upb_array_ptr(arr); @@ -5196,11 +5409,13 @@ UPB_INLINE google_protobuf_UninterpretedOption_NamePart** google_protobuf_Uninte } UPB_INLINE google_protobuf_UninterpretedOption_NamePart** google_protobuf_UninterpretedOption_resize_name(google_protobuf_UninterpretedOption* msg, size_t size, upb_Arena* arena) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__UninterpretedOption_msg_init(), 2); - return (google_protobuf_UninterpretedOption_NamePart**)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); + return (google_protobuf_UninterpretedOption_NamePart**)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg), + &field, size, arena); } UPB_INLINE struct google_protobuf_UninterpretedOption_NamePart* google_protobuf_UninterpretedOption_add_name(google_protobuf_UninterpretedOption* msg, upb_Arena* arena) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__UninterpretedOption_msg_init(), 2); - upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray( + UPB_UPCAST(msg), &field, arena); if (!arr || !_upb_Array_ResizeUninitialized( arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; @@ -5213,27 +5428,27 @@ UPB_INLINE struct google_protobuf_UninterpretedOption_NamePart* google_protobuf_ } UPB_INLINE void google_protobuf_UninterpretedOption_set_identifier_value(google_protobuf_UninterpretedOption *msg, upb_StringView value) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__UninterpretedOption_msg_init(), 3); - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_UninterpretedOption_set_positive_int_value(google_protobuf_UninterpretedOption *msg, uint64_t value) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__UninterpretedOption_msg_init(), 4); - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_UninterpretedOption_set_negative_int_value(google_protobuf_UninterpretedOption *msg, int64_t value) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__UninterpretedOption_msg_init(), 5); - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_UninterpretedOption_set_double_value(google_protobuf_UninterpretedOption *msg, double value) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__UninterpretedOption_msg_init(), 6); - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_UninterpretedOption_set_string_value(google_protobuf_UninterpretedOption *msg, upb_StringView value) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__UninterpretedOption_msg_init(), 7); - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_UninterpretedOption_set_aggregate_value(google_protobuf_UninterpretedOption *msg, upb_StringView value) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__UninterpretedOption_msg_init(), 8); - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } /* google.protobuf.UninterpretedOption.NamePart */ @@ -5244,7 +5459,8 @@ UPB_INLINE google_protobuf_UninterpretedOption_NamePart* google_protobuf_Uninter UPB_INLINE google_protobuf_UninterpretedOption_NamePart* google_protobuf_UninterpretedOption_NamePart_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_UninterpretedOption_NamePart* ret = google_protobuf_UninterpretedOption_NamePart_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, google__protobuf__UninterpretedOption__NamePart_msg_init(), NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), google__protobuf__UninterpretedOption__NamePart_msg_init(), NULL, 0, arena) != + kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -5254,61 +5470,63 @@ UPB_INLINE google_protobuf_UninterpretedOption_NamePart* google_protobuf_Uninter int options, upb_Arena* arena) { google_protobuf_UninterpretedOption_NamePart* ret = google_protobuf_UninterpretedOption_NamePart_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, google__protobuf__UninterpretedOption__NamePart_msg_init(), extreg, options, arena) != - kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), google__protobuf__UninterpretedOption__NamePart_msg_init(), extreg, options, + arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_UninterpretedOption_NamePart_serialize(const google_protobuf_UninterpretedOption_NamePart* msg, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, google__protobuf__UninterpretedOption__NamePart_msg_init(), 0, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), google__protobuf__UninterpretedOption__NamePart_msg_init(), 0, arena, &ptr, len); return ptr; } UPB_INLINE char* google_protobuf_UninterpretedOption_NamePart_serialize_ex(const google_protobuf_UninterpretedOption_NamePart* msg, int options, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, google__protobuf__UninterpretedOption__NamePart_msg_init(), options, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), google__protobuf__UninterpretedOption__NamePart_msg_init(), options, arena, &ptr, len); return ptr; } UPB_INLINE void google_protobuf_UninterpretedOption_NamePart_clear_name_part(google_protobuf_UninterpretedOption_NamePart* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__UninterpretedOption__NamePart_msg_init(), 1); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_UninterpretedOption_NamePart_name_part(const google_protobuf_UninterpretedOption_NamePart* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__UninterpretedOption__NamePart_msg_init(), 1); - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_UninterpretedOption_NamePart_has_name_part(const google_protobuf_UninterpretedOption_NamePart* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__UninterpretedOption__NamePart_msg_init(), 1); - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_UninterpretedOption_NamePart_clear_is_extension(google_protobuf_UninterpretedOption_NamePart* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__UninterpretedOption__NamePart_msg_init(), 2); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_UninterpretedOption_NamePart_is_extension(const google_protobuf_UninterpretedOption_NamePart* msg) { bool default_val = false; bool ret; const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__UninterpretedOption__NamePart_msg_init(), 2); - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_UninterpretedOption_NamePart_has_is_extension(const google_protobuf_UninterpretedOption_NamePart* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__UninterpretedOption__NamePart_msg_init(), 2); - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_UninterpretedOption_NamePart_set_name_part(google_protobuf_UninterpretedOption_NamePart *msg, upb_StringView value) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__UninterpretedOption__NamePart_msg_init(), 1); - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_UninterpretedOption_NamePart_set_is_extension(google_protobuf_UninterpretedOption_NamePart *msg, bool value) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__UninterpretedOption__NamePart_msg_init(), 2); - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } /* google.protobuf.FeatureSet */ @@ -5319,7 +5537,8 @@ UPB_INLINE google_protobuf_FeatureSet* google_protobuf_FeatureSet_new(upb_Arena* UPB_INLINE google_protobuf_FeatureSet* google_protobuf_FeatureSet_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_FeatureSet* ret = google_protobuf_FeatureSet_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, google__protobuf__FeatureSet_msg_init(), NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), google__protobuf__FeatureSet_msg_init(), NULL, 0, arena) != + kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -5329,137 +5548,143 @@ UPB_INLINE google_protobuf_FeatureSet* google_protobuf_FeatureSet_parse_ex(const int options, upb_Arena* arena) { google_protobuf_FeatureSet* ret = google_protobuf_FeatureSet_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, google__protobuf__FeatureSet_msg_init(), extreg, options, arena) != - kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), google__protobuf__FeatureSet_msg_init(), extreg, options, + arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_FeatureSet_serialize(const google_protobuf_FeatureSet* msg, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, google__protobuf__FeatureSet_msg_init(), 0, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), google__protobuf__FeatureSet_msg_init(), 0, arena, &ptr, len); return ptr; } UPB_INLINE char* google_protobuf_FeatureSet_serialize_ex(const google_protobuf_FeatureSet* msg, int options, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, google__protobuf__FeatureSet_msg_init(), options, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), google__protobuf__FeatureSet_msg_init(), options, arena, &ptr, len); return ptr; } UPB_INLINE void google_protobuf_FeatureSet_clear_field_presence(google_protobuf_FeatureSet* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FeatureSet_msg_init(), 1); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_FeatureSet_field_presence(const google_protobuf_FeatureSet* msg) { int32_t default_val = 0; int32_t ret; const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FeatureSet_msg_init(), 1); - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FeatureSet_has_field_presence(const google_protobuf_FeatureSet* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FeatureSet_msg_init(), 1); - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FeatureSet_clear_enum_type(google_protobuf_FeatureSet* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FeatureSet_msg_init(), 2); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_FeatureSet_enum_type(const google_protobuf_FeatureSet* msg) { int32_t default_val = 0; int32_t ret; const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FeatureSet_msg_init(), 2); - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FeatureSet_has_enum_type(const google_protobuf_FeatureSet* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FeatureSet_msg_init(), 2); - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FeatureSet_clear_repeated_field_encoding(google_protobuf_FeatureSet* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FeatureSet_msg_init(), 3); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_FeatureSet_repeated_field_encoding(const google_protobuf_FeatureSet* msg) { int32_t default_val = 0; int32_t ret; const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FeatureSet_msg_init(), 3); - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FeatureSet_has_repeated_field_encoding(const google_protobuf_FeatureSet* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FeatureSet_msg_init(), 3); - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FeatureSet_clear_utf8_validation(google_protobuf_FeatureSet* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FeatureSet_msg_init(), 4); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_FeatureSet_utf8_validation(const google_protobuf_FeatureSet* msg) { int32_t default_val = 0; int32_t ret; const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FeatureSet_msg_init(), 4); - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FeatureSet_has_utf8_validation(const google_protobuf_FeatureSet* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FeatureSet_msg_init(), 4); - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FeatureSet_clear_message_encoding(google_protobuf_FeatureSet* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FeatureSet_msg_init(), 5); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_FeatureSet_message_encoding(const google_protobuf_FeatureSet* msg) { int32_t default_val = 0; int32_t ret; const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FeatureSet_msg_init(), 5); - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FeatureSet_has_message_encoding(const google_protobuf_FeatureSet* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FeatureSet_msg_init(), 5); - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FeatureSet_clear_json_format(google_protobuf_FeatureSet* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FeatureSet_msg_init(), 6); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_FeatureSet_json_format(const google_protobuf_FeatureSet* msg) { int32_t default_val = 0; int32_t ret; const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FeatureSet_msg_init(), 6); - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FeatureSet_has_json_format(const google_protobuf_FeatureSet* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FeatureSet_msg_init(), 6); - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FeatureSet_set_field_presence(google_protobuf_FeatureSet *msg, int32_t value) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FeatureSet_msg_init(), 1); - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FeatureSet_set_enum_type(google_protobuf_FeatureSet *msg, int32_t value) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FeatureSet_msg_init(), 2); - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FeatureSet_set_repeated_field_encoding(google_protobuf_FeatureSet *msg, int32_t value) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FeatureSet_msg_init(), 3); - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FeatureSet_set_utf8_validation(google_protobuf_FeatureSet *msg, int32_t value) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FeatureSet_msg_init(), 4); - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FeatureSet_set_message_encoding(google_protobuf_FeatureSet *msg, int32_t value) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FeatureSet_msg_init(), 5); - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FeatureSet_set_json_format(google_protobuf_FeatureSet *msg, int32_t value) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FeatureSet_msg_init(), 6); - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } /* google.protobuf.FeatureSetDefaults */ @@ -5470,7 +5695,8 @@ UPB_INLINE google_protobuf_FeatureSetDefaults* google_protobuf_FeatureSetDefault UPB_INLINE google_protobuf_FeatureSetDefaults* google_protobuf_FeatureSetDefaults_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_FeatureSetDefaults* ret = google_protobuf_FeatureSetDefaults_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, google__protobuf__FeatureSetDefaults_msg_init(), NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), google__protobuf__FeatureSetDefaults_msg_init(), NULL, 0, arena) != + kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -5480,30 +5706,30 @@ UPB_INLINE google_protobuf_FeatureSetDefaults* google_protobuf_FeatureSetDefault int options, upb_Arena* arena) { google_protobuf_FeatureSetDefaults* ret = google_protobuf_FeatureSetDefaults_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, google__protobuf__FeatureSetDefaults_msg_init(), extreg, options, arena) != - kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), google__protobuf__FeatureSetDefaults_msg_init(), extreg, options, + arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_FeatureSetDefaults_serialize(const google_protobuf_FeatureSetDefaults* msg, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, google__protobuf__FeatureSetDefaults_msg_init(), 0, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), google__protobuf__FeatureSetDefaults_msg_init(), 0, arena, &ptr, len); return ptr; } UPB_INLINE char* google_protobuf_FeatureSetDefaults_serialize_ex(const google_protobuf_FeatureSetDefaults* msg, int options, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, google__protobuf__FeatureSetDefaults_msg_init(), options, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), google__protobuf__FeatureSetDefaults_msg_init(), options, arena, &ptr, len); return ptr; } UPB_INLINE void google_protobuf_FeatureSetDefaults_clear_defaults(google_protobuf_FeatureSetDefaults* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FeatureSetDefaults_msg_init(), 1); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* const* google_protobuf_FeatureSetDefaults_defaults(const google_protobuf_FeatureSetDefaults* msg, size_t* size) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FeatureSetDefaults_msg_init(), 1); - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* const*)_upb_array_constptr(arr); @@ -5514,16 +5740,16 @@ UPB_INLINE const google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* co } UPB_INLINE const upb_Array* _google_protobuf_FeatureSetDefaults_defaults_upb_array(const google_protobuf_FeatureSetDefaults* msg, size_t* size) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FeatureSetDefaults_msg_init(), 1); - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } -UPB_INLINE upb_Array* _google_protobuf_FeatureSetDefaults_defaults_mutable_upb_array(const google_protobuf_FeatureSetDefaults* msg, size_t* size, upb_Arena* arena) { +UPB_INLINE upb_Array* _google_protobuf_FeatureSetDefaults_defaults_mutable_upb_array(google_protobuf_FeatureSetDefaults* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FeatureSetDefaults_msg_init(), 1); upb_Array* arr = upb_Message_GetOrCreateMutableArray( - (upb_Message*)msg, &field, arena); + UPB_UPCAST(msg), &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -5531,38 +5757,40 @@ UPB_INLINE upb_Array* _google_protobuf_FeatureSetDefaults_defaults_mutable_upb_a } UPB_INLINE void google_protobuf_FeatureSetDefaults_clear_minimum_edition(google_protobuf_FeatureSetDefaults* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FeatureSetDefaults_msg_init(), 4); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_FeatureSetDefaults_minimum_edition(const google_protobuf_FeatureSetDefaults* msg) { int32_t default_val = 0; int32_t ret; const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FeatureSetDefaults_msg_init(), 4); - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FeatureSetDefaults_has_minimum_edition(const google_protobuf_FeatureSetDefaults* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FeatureSetDefaults_msg_init(), 4); - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FeatureSetDefaults_clear_maximum_edition(google_protobuf_FeatureSetDefaults* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FeatureSetDefaults_msg_init(), 5); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_FeatureSetDefaults_maximum_edition(const google_protobuf_FeatureSetDefaults* msg) { int32_t default_val = 0; int32_t ret; const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FeatureSetDefaults_msg_init(), 5); - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FeatureSetDefaults_has_maximum_edition(const google_protobuf_FeatureSetDefaults* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FeatureSetDefaults_msg_init(), 5); - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault** google_protobuf_FeatureSetDefaults_mutable_defaults(google_protobuf_FeatureSetDefaults* msg, size_t* size) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FeatureSetDefaults_msg_init(), 1); - upb_Array* arr = upb_Message_GetMutableArray(msg, &field); + upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault**)_upb_array_ptr(arr); @@ -5573,11 +5801,13 @@ UPB_INLINE google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault** google_ } UPB_INLINE google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault** google_protobuf_FeatureSetDefaults_resize_defaults(google_protobuf_FeatureSetDefaults* msg, size_t size, upb_Arena* arena) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FeatureSetDefaults_msg_init(), 1); - return (google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault**)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); + return (google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault**)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg), + &field, size, arena); } UPB_INLINE struct google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* google_protobuf_FeatureSetDefaults_add_defaults(google_protobuf_FeatureSetDefaults* msg, upb_Arena* arena) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FeatureSetDefaults_msg_init(), 1); - upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray( + UPB_UPCAST(msg), &field, arena); if (!arr || !_upb_Array_ResizeUninitialized( arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; @@ -5590,11 +5820,11 @@ UPB_INLINE struct google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* g } UPB_INLINE void google_protobuf_FeatureSetDefaults_set_minimum_edition(google_protobuf_FeatureSetDefaults *msg, int32_t value) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FeatureSetDefaults_msg_init(), 4); - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FeatureSetDefaults_set_maximum_edition(google_protobuf_FeatureSetDefaults *msg, int32_t value) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FeatureSetDefaults_msg_init(), 5); - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } /* google.protobuf.FeatureSetDefaults.FeatureSetEditionDefault */ @@ -5605,7 +5835,8 @@ UPB_INLINE google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* google_p UPB_INLINE google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* ret = google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, google__protobuf__FeatureSetDefaults__FeatureSetEditionDefault_msg_init(), NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), google__protobuf__FeatureSetDefaults__FeatureSetEditionDefault_msg_init(), NULL, 0, arena) != + kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -5615,57 +5846,59 @@ UPB_INLINE google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* google_p int options, upb_Arena* arena) { google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* ret = google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, google__protobuf__FeatureSetDefaults__FeatureSetEditionDefault_msg_init(), extreg, options, arena) != - kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), google__protobuf__FeatureSetDefaults__FeatureSetEditionDefault_msg_init(), extreg, options, + arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_serialize(const google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* msg, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, google__protobuf__FeatureSetDefaults__FeatureSetEditionDefault_msg_init(), 0, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), google__protobuf__FeatureSetDefaults__FeatureSetEditionDefault_msg_init(), 0, arena, &ptr, len); return ptr; } UPB_INLINE char* google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_serialize_ex(const google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* msg, int options, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, google__protobuf__FeatureSetDefaults__FeatureSetEditionDefault_msg_init(), options, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), google__protobuf__FeatureSetDefaults__FeatureSetEditionDefault_msg_init(), options, arena, &ptr, len); return ptr; } UPB_INLINE void google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_clear_features(google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FeatureSetDefaults__FeatureSetEditionDefault_msg_init(), 2); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_FeatureSet* google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_features(const google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* msg) { const google_protobuf_FeatureSet* default_val = NULL; const google_protobuf_FeatureSet* ret; const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FeatureSetDefaults__FeatureSetEditionDefault_msg_init(), 2); - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_has_features(const google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FeatureSetDefaults__FeatureSetEditionDefault_msg_init(), 2); - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_clear_edition(google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FeatureSetDefaults__FeatureSetEditionDefault_msg_init(), 3); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_edition(const google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* msg) { int32_t default_val = 0; int32_t ret; const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FeatureSetDefaults__FeatureSetEditionDefault_msg_init(), 3); - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_has_edition(const google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FeatureSetDefaults__FeatureSetEditionDefault_msg_init(), 3); - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_set_features(google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault *msg, google_protobuf_FeatureSet* value) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FeatureSetDefaults__FeatureSetEditionDefault_msg_init(), 2); - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE struct google_protobuf_FeatureSet* google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_mutable_features(google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* msg, upb_Arena* arena) { struct google_protobuf_FeatureSet* sub = (struct google_protobuf_FeatureSet*)google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_features(msg); @@ -5677,7 +5910,7 @@ UPB_INLINE struct google_protobuf_FeatureSet* google_protobuf_FeatureSetDefaults } UPB_INLINE void google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_set_edition(google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault *msg, int32_t value) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FeatureSetDefaults__FeatureSetEditionDefault_msg_init(), 3); - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } /* google.protobuf.SourceCodeInfo */ @@ -5688,7 +5921,8 @@ UPB_INLINE google_protobuf_SourceCodeInfo* google_protobuf_SourceCodeInfo_new(up UPB_INLINE google_protobuf_SourceCodeInfo* google_protobuf_SourceCodeInfo_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_SourceCodeInfo* ret = google_protobuf_SourceCodeInfo_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, google__protobuf__SourceCodeInfo_msg_init(), NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), google__protobuf__SourceCodeInfo_msg_init(), NULL, 0, arena) != + kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -5698,30 +5932,30 @@ UPB_INLINE google_protobuf_SourceCodeInfo* google_protobuf_SourceCodeInfo_parse_ int options, upb_Arena* arena) { google_protobuf_SourceCodeInfo* ret = google_protobuf_SourceCodeInfo_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, google__protobuf__SourceCodeInfo_msg_init(), extreg, options, arena) != - kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), google__protobuf__SourceCodeInfo_msg_init(), extreg, options, + arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_SourceCodeInfo_serialize(const google_protobuf_SourceCodeInfo* msg, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, google__protobuf__SourceCodeInfo_msg_init(), 0, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), google__protobuf__SourceCodeInfo_msg_init(), 0, arena, &ptr, len); return ptr; } UPB_INLINE char* google_protobuf_SourceCodeInfo_serialize_ex(const google_protobuf_SourceCodeInfo* msg, int options, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, google__protobuf__SourceCodeInfo_msg_init(), options, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), google__protobuf__SourceCodeInfo_msg_init(), options, arena, &ptr, len); return ptr; } UPB_INLINE void google_protobuf_SourceCodeInfo_clear_location(google_protobuf_SourceCodeInfo* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__SourceCodeInfo_msg_init(), 1); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_SourceCodeInfo_Location* const* google_protobuf_SourceCodeInfo_location(const google_protobuf_SourceCodeInfo* msg, size_t* size) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__SourceCodeInfo_msg_init(), 1); - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_SourceCodeInfo_Location* const*)_upb_array_constptr(arr); @@ -5732,16 +5966,16 @@ UPB_INLINE const google_protobuf_SourceCodeInfo_Location* const* google_protobuf } UPB_INLINE const upb_Array* _google_protobuf_SourceCodeInfo_location_upb_array(const google_protobuf_SourceCodeInfo* msg, size_t* size) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__SourceCodeInfo_msg_init(), 1); - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } -UPB_INLINE upb_Array* _google_protobuf_SourceCodeInfo_location_mutable_upb_array(const google_protobuf_SourceCodeInfo* msg, size_t* size, upb_Arena* arena) { +UPB_INLINE upb_Array* _google_protobuf_SourceCodeInfo_location_mutable_upb_array(google_protobuf_SourceCodeInfo* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__SourceCodeInfo_msg_init(), 1); upb_Array* arr = upb_Message_GetOrCreateMutableArray( - (upb_Message*)msg, &field, arena); + UPB_UPCAST(msg), &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -5750,7 +5984,7 @@ UPB_INLINE upb_Array* _google_protobuf_SourceCodeInfo_location_mutable_upb_array UPB_INLINE google_protobuf_SourceCodeInfo_Location** google_protobuf_SourceCodeInfo_mutable_location(google_protobuf_SourceCodeInfo* msg, size_t* size) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__SourceCodeInfo_msg_init(), 1); - upb_Array* arr = upb_Message_GetMutableArray(msg, &field); + upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_SourceCodeInfo_Location**)_upb_array_ptr(arr); @@ -5761,11 +5995,13 @@ UPB_INLINE google_protobuf_SourceCodeInfo_Location** google_protobuf_SourceCodeI } UPB_INLINE google_protobuf_SourceCodeInfo_Location** google_protobuf_SourceCodeInfo_resize_location(google_protobuf_SourceCodeInfo* msg, size_t size, upb_Arena* arena) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__SourceCodeInfo_msg_init(), 1); - return (google_protobuf_SourceCodeInfo_Location**)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); + return (google_protobuf_SourceCodeInfo_Location**)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg), + &field, size, arena); } UPB_INLINE struct google_protobuf_SourceCodeInfo_Location* google_protobuf_SourceCodeInfo_add_location(google_protobuf_SourceCodeInfo* msg, upb_Arena* arena) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__SourceCodeInfo_msg_init(), 1); - upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray( + UPB_UPCAST(msg), &field, arena); if (!arr || !_upb_Array_ResizeUninitialized( arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; @@ -5785,7 +6021,8 @@ UPB_INLINE google_protobuf_SourceCodeInfo_Location* google_protobuf_SourceCodeIn UPB_INLINE google_protobuf_SourceCodeInfo_Location* google_protobuf_SourceCodeInfo_Location_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_SourceCodeInfo_Location* ret = google_protobuf_SourceCodeInfo_Location_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, google__protobuf__SourceCodeInfo__Location_msg_init(), NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), google__protobuf__SourceCodeInfo__Location_msg_init(), NULL, 0, arena) != + kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -5795,30 +6032,30 @@ UPB_INLINE google_protobuf_SourceCodeInfo_Location* google_protobuf_SourceCodeIn int options, upb_Arena* arena) { google_protobuf_SourceCodeInfo_Location* ret = google_protobuf_SourceCodeInfo_Location_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, google__protobuf__SourceCodeInfo__Location_msg_init(), extreg, options, arena) != - kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), google__protobuf__SourceCodeInfo__Location_msg_init(), extreg, options, + arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_SourceCodeInfo_Location_serialize(const google_protobuf_SourceCodeInfo_Location* msg, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, google__protobuf__SourceCodeInfo__Location_msg_init(), 0, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), google__protobuf__SourceCodeInfo__Location_msg_init(), 0, arena, &ptr, len); return ptr; } UPB_INLINE char* google_protobuf_SourceCodeInfo_Location_serialize_ex(const google_protobuf_SourceCodeInfo_Location* msg, int options, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, google__protobuf__SourceCodeInfo__Location_msg_init(), options, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), google__protobuf__SourceCodeInfo__Location_msg_init(), options, arena, &ptr, len); return ptr; } UPB_INLINE void google_protobuf_SourceCodeInfo_Location_clear_path(google_protobuf_SourceCodeInfo_Location* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__SourceCodeInfo__Location_msg_init(), 1); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t const* google_protobuf_SourceCodeInfo_Location_path(const google_protobuf_SourceCodeInfo_Location* msg, size_t* size) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__SourceCodeInfo__Location_msg_init(), 1); - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (int32_t const*)_upb_array_constptr(arr); @@ -5829,16 +6066,16 @@ UPB_INLINE int32_t const* google_protobuf_SourceCodeInfo_Location_path(const goo } UPB_INLINE const upb_Array* _google_protobuf_SourceCodeInfo_Location_path_upb_array(const google_protobuf_SourceCodeInfo_Location* msg, size_t* size) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__SourceCodeInfo__Location_msg_init(), 1); - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } -UPB_INLINE upb_Array* _google_protobuf_SourceCodeInfo_Location_path_mutable_upb_array(const google_protobuf_SourceCodeInfo_Location* msg, size_t* size, upb_Arena* arena) { +UPB_INLINE upb_Array* _google_protobuf_SourceCodeInfo_Location_path_mutable_upb_array(google_protobuf_SourceCodeInfo_Location* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__SourceCodeInfo__Location_msg_init(), 1); upb_Array* arr = upb_Message_GetOrCreateMutableArray( - (upb_Message*)msg, &field, arena); + UPB_UPCAST(msg), &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -5846,11 +6083,11 @@ UPB_INLINE upb_Array* _google_protobuf_SourceCodeInfo_Location_path_mutable_upb_ } UPB_INLINE void google_protobuf_SourceCodeInfo_Location_clear_span(google_protobuf_SourceCodeInfo_Location* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__SourceCodeInfo__Location_msg_init(), 2); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t const* google_protobuf_SourceCodeInfo_Location_span(const google_protobuf_SourceCodeInfo_Location* msg, size_t* size) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__SourceCodeInfo__Location_msg_init(), 2); - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (int32_t const*)_upb_array_constptr(arr); @@ -5861,16 +6098,16 @@ UPB_INLINE int32_t const* google_protobuf_SourceCodeInfo_Location_span(const goo } UPB_INLINE const upb_Array* _google_protobuf_SourceCodeInfo_Location_span_upb_array(const google_protobuf_SourceCodeInfo_Location* msg, size_t* size) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__SourceCodeInfo__Location_msg_init(), 2); - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } -UPB_INLINE upb_Array* _google_protobuf_SourceCodeInfo_Location_span_mutable_upb_array(const google_protobuf_SourceCodeInfo_Location* msg, size_t* size, upb_Arena* arena) { +UPB_INLINE upb_Array* _google_protobuf_SourceCodeInfo_Location_span_mutable_upb_array(google_protobuf_SourceCodeInfo_Location* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__SourceCodeInfo__Location_msg_init(), 2); upb_Array* arr = upb_Message_GetOrCreateMutableArray( - (upb_Message*)msg, &field, arena); + UPB_UPCAST(msg), &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -5878,41 +6115,43 @@ UPB_INLINE upb_Array* _google_protobuf_SourceCodeInfo_Location_span_mutable_upb_ } UPB_INLINE void google_protobuf_SourceCodeInfo_Location_clear_leading_comments(google_protobuf_SourceCodeInfo_Location* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__SourceCodeInfo__Location_msg_init(), 3); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_SourceCodeInfo_Location_leading_comments(const google_protobuf_SourceCodeInfo_Location* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__SourceCodeInfo__Location_msg_init(), 3); - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_SourceCodeInfo_Location_has_leading_comments(const google_protobuf_SourceCodeInfo_Location* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__SourceCodeInfo__Location_msg_init(), 3); - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_SourceCodeInfo_Location_clear_trailing_comments(google_protobuf_SourceCodeInfo_Location* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__SourceCodeInfo__Location_msg_init(), 4); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_SourceCodeInfo_Location_trailing_comments(const google_protobuf_SourceCodeInfo_Location* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__SourceCodeInfo__Location_msg_init(), 4); - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_SourceCodeInfo_Location_has_trailing_comments(const google_protobuf_SourceCodeInfo_Location* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__SourceCodeInfo__Location_msg_init(), 4); - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_SourceCodeInfo_Location_clear_leading_detached_comments(google_protobuf_SourceCodeInfo_Location* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__SourceCodeInfo__Location_msg_init(), 6); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView const* google_protobuf_SourceCodeInfo_Location_leading_detached_comments(const google_protobuf_SourceCodeInfo_Location* msg, size_t* size) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__SourceCodeInfo__Location_msg_init(), 6); - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (upb_StringView const*)_upb_array_constptr(arr); @@ -5923,16 +6162,16 @@ UPB_INLINE upb_StringView const* google_protobuf_SourceCodeInfo_Location_leading } UPB_INLINE const upb_Array* _google_protobuf_SourceCodeInfo_Location_leading_detached_comments_upb_array(const google_protobuf_SourceCodeInfo_Location* msg, size_t* size) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__SourceCodeInfo__Location_msg_init(), 6); - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } -UPB_INLINE upb_Array* _google_protobuf_SourceCodeInfo_Location_leading_detached_comments_mutable_upb_array(const google_protobuf_SourceCodeInfo_Location* msg, size_t* size, upb_Arena* arena) { +UPB_INLINE upb_Array* _google_protobuf_SourceCodeInfo_Location_leading_detached_comments_mutable_upb_array(google_protobuf_SourceCodeInfo_Location* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__SourceCodeInfo__Location_msg_init(), 6); upb_Array* arr = upb_Message_GetOrCreateMutableArray( - (upb_Message*)msg, &field, arena); + UPB_UPCAST(msg), &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -5941,7 +6180,7 @@ UPB_INLINE upb_Array* _google_protobuf_SourceCodeInfo_Location_leading_detached_ UPB_INLINE int32_t* google_protobuf_SourceCodeInfo_Location_mutable_path(google_protobuf_SourceCodeInfo_Location* msg, size_t* size) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__SourceCodeInfo__Location_msg_init(), 1); - upb_Array* arr = upb_Message_GetMutableArray(msg, &field); + upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (int32_t*)_upb_array_ptr(arr); @@ -5952,11 +6191,13 @@ UPB_INLINE int32_t* google_protobuf_SourceCodeInfo_Location_mutable_path(google_ } UPB_INLINE int32_t* google_protobuf_SourceCodeInfo_Location_resize_path(google_protobuf_SourceCodeInfo_Location* msg, size_t size, upb_Arena* arena) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__SourceCodeInfo__Location_msg_init(), 1); - return (int32_t*)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); + return (int32_t*)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg), + &field, size, arena); } UPB_INLINE bool google_protobuf_SourceCodeInfo_Location_add_path(google_protobuf_SourceCodeInfo_Location* msg, int32_t val, upb_Arena* arena) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__SourceCodeInfo__Location_msg_init(), 1); - upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray( + UPB_UPCAST(msg), &field, arena); if (!arr || !_upb_Array_ResizeUninitialized( arr, arr->UPB_PRIVATE(size) + 1, arena)) { return false; @@ -5967,7 +6208,7 @@ UPB_INLINE bool google_protobuf_SourceCodeInfo_Location_add_path(google_protobuf } UPB_INLINE int32_t* google_protobuf_SourceCodeInfo_Location_mutable_span(google_protobuf_SourceCodeInfo_Location* msg, size_t* size) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__SourceCodeInfo__Location_msg_init(), 2); - upb_Array* arr = upb_Message_GetMutableArray(msg, &field); + upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (int32_t*)_upb_array_ptr(arr); @@ -5978,11 +6219,13 @@ UPB_INLINE int32_t* google_protobuf_SourceCodeInfo_Location_mutable_span(google_ } UPB_INLINE int32_t* google_protobuf_SourceCodeInfo_Location_resize_span(google_protobuf_SourceCodeInfo_Location* msg, size_t size, upb_Arena* arena) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__SourceCodeInfo__Location_msg_init(), 2); - return (int32_t*)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); + return (int32_t*)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg), + &field, size, arena); } UPB_INLINE bool google_protobuf_SourceCodeInfo_Location_add_span(google_protobuf_SourceCodeInfo_Location* msg, int32_t val, upb_Arena* arena) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__SourceCodeInfo__Location_msg_init(), 2); - upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray( + UPB_UPCAST(msg), &field, arena); if (!arr || !_upb_Array_ResizeUninitialized( arr, arr->UPB_PRIVATE(size) + 1, arena)) { return false; @@ -5993,15 +6236,15 @@ UPB_INLINE bool google_protobuf_SourceCodeInfo_Location_add_span(google_protobuf } UPB_INLINE void google_protobuf_SourceCodeInfo_Location_set_leading_comments(google_protobuf_SourceCodeInfo_Location *msg, upb_StringView value) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__SourceCodeInfo__Location_msg_init(), 3); - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_SourceCodeInfo_Location_set_trailing_comments(google_protobuf_SourceCodeInfo_Location *msg, upb_StringView value) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__SourceCodeInfo__Location_msg_init(), 4); - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE upb_StringView* google_protobuf_SourceCodeInfo_Location_mutable_leading_detached_comments(google_protobuf_SourceCodeInfo_Location* msg, size_t* size) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__SourceCodeInfo__Location_msg_init(), 6); - upb_Array* arr = upb_Message_GetMutableArray(msg, &field); + upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (upb_StringView*)_upb_array_ptr(arr); @@ -6012,11 +6255,13 @@ UPB_INLINE upb_StringView* google_protobuf_SourceCodeInfo_Location_mutable_leadi } UPB_INLINE upb_StringView* google_protobuf_SourceCodeInfo_Location_resize_leading_detached_comments(google_protobuf_SourceCodeInfo_Location* msg, size_t size, upb_Arena* arena) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__SourceCodeInfo__Location_msg_init(), 6); - return (upb_StringView*)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); + return (upb_StringView*)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg), + &field, size, arena); } UPB_INLINE bool google_protobuf_SourceCodeInfo_Location_add_leading_detached_comments(google_protobuf_SourceCodeInfo_Location* msg, upb_StringView val, upb_Arena* arena) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__SourceCodeInfo__Location_msg_init(), 6); - upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray( + UPB_UPCAST(msg), &field, arena); if (!arr || !_upb_Array_ResizeUninitialized( arr, arr->UPB_PRIVATE(size) + 1, arena)) { return false; @@ -6034,7 +6279,8 @@ UPB_INLINE google_protobuf_GeneratedCodeInfo* google_protobuf_GeneratedCodeInfo_ UPB_INLINE google_protobuf_GeneratedCodeInfo* google_protobuf_GeneratedCodeInfo_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_GeneratedCodeInfo* ret = google_protobuf_GeneratedCodeInfo_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, google__protobuf__GeneratedCodeInfo_msg_init(), NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), google__protobuf__GeneratedCodeInfo_msg_init(), NULL, 0, arena) != + kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -6044,30 +6290,30 @@ UPB_INLINE google_protobuf_GeneratedCodeInfo* google_protobuf_GeneratedCodeInfo_ int options, upb_Arena* arena) { google_protobuf_GeneratedCodeInfo* ret = google_protobuf_GeneratedCodeInfo_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, google__protobuf__GeneratedCodeInfo_msg_init(), extreg, options, arena) != - kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), google__protobuf__GeneratedCodeInfo_msg_init(), extreg, options, + arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_GeneratedCodeInfo_serialize(const google_protobuf_GeneratedCodeInfo* msg, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, google__protobuf__GeneratedCodeInfo_msg_init(), 0, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), google__protobuf__GeneratedCodeInfo_msg_init(), 0, arena, &ptr, len); return ptr; } UPB_INLINE char* google_protobuf_GeneratedCodeInfo_serialize_ex(const google_protobuf_GeneratedCodeInfo* msg, int options, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, google__protobuf__GeneratedCodeInfo_msg_init(), options, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), google__protobuf__GeneratedCodeInfo_msg_init(), options, arena, &ptr, len); return ptr; } UPB_INLINE void google_protobuf_GeneratedCodeInfo_clear_annotation(google_protobuf_GeneratedCodeInfo* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__GeneratedCodeInfo_msg_init(), 1); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_GeneratedCodeInfo_Annotation* const* google_protobuf_GeneratedCodeInfo_annotation(const google_protobuf_GeneratedCodeInfo* msg, size_t* size) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__GeneratedCodeInfo_msg_init(), 1); - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_GeneratedCodeInfo_Annotation* const*)_upb_array_constptr(arr); @@ -6078,16 +6324,16 @@ UPB_INLINE const google_protobuf_GeneratedCodeInfo_Annotation* const* google_pro } UPB_INLINE const upb_Array* _google_protobuf_GeneratedCodeInfo_annotation_upb_array(const google_protobuf_GeneratedCodeInfo* msg, size_t* size) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__GeneratedCodeInfo_msg_init(), 1); - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } -UPB_INLINE upb_Array* _google_protobuf_GeneratedCodeInfo_annotation_mutable_upb_array(const google_protobuf_GeneratedCodeInfo* msg, size_t* size, upb_Arena* arena) { +UPB_INLINE upb_Array* _google_protobuf_GeneratedCodeInfo_annotation_mutable_upb_array(google_protobuf_GeneratedCodeInfo* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__GeneratedCodeInfo_msg_init(), 1); upb_Array* arr = upb_Message_GetOrCreateMutableArray( - (upb_Message*)msg, &field, arena); + UPB_UPCAST(msg), &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -6096,7 +6342,7 @@ UPB_INLINE upb_Array* _google_protobuf_GeneratedCodeInfo_annotation_mutable_upb_ UPB_INLINE google_protobuf_GeneratedCodeInfo_Annotation** google_protobuf_GeneratedCodeInfo_mutable_annotation(google_protobuf_GeneratedCodeInfo* msg, size_t* size) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__GeneratedCodeInfo_msg_init(), 1); - upb_Array* arr = upb_Message_GetMutableArray(msg, &field); + upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_GeneratedCodeInfo_Annotation**)_upb_array_ptr(arr); @@ -6107,11 +6353,13 @@ UPB_INLINE google_protobuf_GeneratedCodeInfo_Annotation** google_protobuf_Genera } UPB_INLINE google_protobuf_GeneratedCodeInfo_Annotation** google_protobuf_GeneratedCodeInfo_resize_annotation(google_protobuf_GeneratedCodeInfo* msg, size_t size, upb_Arena* arena) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__GeneratedCodeInfo_msg_init(), 1); - return (google_protobuf_GeneratedCodeInfo_Annotation**)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); + return (google_protobuf_GeneratedCodeInfo_Annotation**)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg), + &field, size, arena); } UPB_INLINE struct google_protobuf_GeneratedCodeInfo_Annotation* google_protobuf_GeneratedCodeInfo_add_annotation(google_protobuf_GeneratedCodeInfo* msg, upb_Arena* arena) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__GeneratedCodeInfo_msg_init(), 1); - upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray( + UPB_UPCAST(msg), &field, arena); if (!arr || !_upb_Array_ResizeUninitialized( arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; @@ -6131,7 +6379,8 @@ UPB_INLINE google_protobuf_GeneratedCodeInfo_Annotation* google_protobuf_Generat UPB_INLINE google_protobuf_GeneratedCodeInfo_Annotation* google_protobuf_GeneratedCodeInfo_Annotation_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_GeneratedCodeInfo_Annotation* ret = google_protobuf_GeneratedCodeInfo_Annotation_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, google__protobuf__GeneratedCodeInfo__Annotation_msg_init(), NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), google__protobuf__GeneratedCodeInfo__Annotation_msg_init(), NULL, 0, arena) != + kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -6141,30 +6390,30 @@ UPB_INLINE google_protobuf_GeneratedCodeInfo_Annotation* google_protobuf_Generat int options, upb_Arena* arena) { google_protobuf_GeneratedCodeInfo_Annotation* ret = google_protobuf_GeneratedCodeInfo_Annotation_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, google__protobuf__GeneratedCodeInfo__Annotation_msg_init(), extreg, options, arena) != - kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), google__protobuf__GeneratedCodeInfo__Annotation_msg_init(), extreg, options, + arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_GeneratedCodeInfo_Annotation_serialize(const google_protobuf_GeneratedCodeInfo_Annotation* msg, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, google__protobuf__GeneratedCodeInfo__Annotation_msg_init(), 0, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), google__protobuf__GeneratedCodeInfo__Annotation_msg_init(), 0, arena, &ptr, len); return ptr; } UPB_INLINE char* google_protobuf_GeneratedCodeInfo_Annotation_serialize_ex(const google_protobuf_GeneratedCodeInfo_Annotation* msg, int options, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, google__protobuf__GeneratedCodeInfo__Annotation_msg_init(), options, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), google__protobuf__GeneratedCodeInfo__Annotation_msg_init(), options, arena, &ptr, len); return ptr; } UPB_INLINE void google_protobuf_GeneratedCodeInfo_Annotation_clear_path(google_protobuf_GeneratedCodeInfo_Annotation* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__GeneratedCodeInfo__Annotation_msg_init(), 1); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t const* google_protobuf_GeneratedCodeInfo_Annotation_path(const google_protobuf_GeneratedCodeInfo_Annotation* msg, size_t* size) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__GeneratedCodeInfo__Annotation_msg_init(), 1); - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (int32_t const*)_upb_array_constptr(arr); @@ -6175,16 +6424,16 @@ UPB_INLINE int32_t const* google_protobuf_GeneratedCodeInfo_Annotation_path(cons } UPB_INLINE const upb_Array* _google_protobuf_GeneratedCodeInfo_Annotation_path_upb_array(const google_protobuf_GeneratedCodeInfo_Annotation* msg, size_t* size) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__GeneratedCodeInfo__Annotation_msg_init(), 1); - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } -UPB_INLINE upb_Array* _google_protobuf_GeneratedCodeInfo_Annotation_path_mutable_upb_array(const google_protobuf_GeneratedCodeInfo_Annotation* msg, size_t* size, upb_Arena* arena) { +UPB_INLINE upb_Array* _google_protobuf_GeneratedCodeInfo_Annotation_path_mutable_upb_array(google_protobuf_GeneratedCodeInfo_Annotation* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__GeneratedCodeInfo__Annotation_msg_init(), 1); upb_Array* arr = upb_Message_GetOrCreateMutableArray( - (upb_Message*)msg, &field, arena); + UPB_UPCAST(msg), &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -6192,68 +6441,72 @@ UPB_INLINE upb_Array* _google_protobuf_GeneratedCodeInfo_Annotation_path_mutable } UPB_INLINE void google_protobuf_GeneratedCodeInfo_Annotation_clear_source_file(google_protobuf_GeneratedCodeInfo_Annotation* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__GeneratedCodeInfo__Annotation_msg_init(), 2); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_GeneratedCodeInfo_Annotation_source_file(const google_protobuf_GeneratedCodeInfo_Annotation* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__GeneratedCodeInfo__Annotation_msg_init(), 2); - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_GeneratedCodeInfo_Annotation_has_source_file(const google_protobuf_GeneratedCodeInfo_Annotation* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__GeneratedCodeInfo__Annotation_msg_init(), 2); - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_GeneratedCodeInfo_Annotation_clear_begin(google_protobuf_GeneratedCodeInfo_Annotation* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__GeneratedCodeInfo__Annotation_msg_init(), 3); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_GeneratedCodeInfo_Annotation_begin(const google_protobuf_GeneratedCodeInfo_Annotation* msg) { int32_t default_val = (int32_t)0; int32_t ret; const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__GeneratedCodeInfo__Annotation_msg_init(), 3); - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_GeneratedCodeInfo_Annotation_has_begin(const google_protobuf_GeneratedCodeInfo_Annotation* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__GeneratedCodeInfo__Annotation_msg_init(), 3); - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_GeneratedCodeInfo_Annotation_clear_end(google_protobuf_GeneratedCodeInfo_Annotation* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__GeneratedCodeInfo__Annotation_msg_init(), 4); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_GeneratedCodeInfo_Annotation_end(const google_protobuf_GeneratedCodeInfo_Annotation* msg) { int32_t default_val = (int32_t)0; int32_t ret; const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__GeneratedCodeInfo__Annotation_msg_init(), 4); - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_GeneratedCodeInfo_Annotation_has_end(const google_protobuf_GeneratedCodeInfo_Annotation* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__GeneratedCodeInfo__Annotation_msg_init(), 4); - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_GeneratedCodeInfo_Annotation_clear_semantic(google_protobuf_GeneratedCodeInfo_Annotation* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__GeneratedCodeInfo__Annotation_msg_init(), 5); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_GeneratedCodeInfo_Annotation_semantic(const google_protobuf_GeneratedCodeInfo_Annotation* msg) { int32_t default_val = 0; int32_t ret; const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__GeneratedCodeInfo__Annotation_msg_init(), 5); - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_GeneratedCodeInfo_Annotation_has_semantic(const google_protobuf_GeneratedCodeInfo_Annotation* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__GeneratedCodeInfo__Annotation_msg_init(), 5); - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t* google_protobuf_GeneratedCodeInfo_Annotation_mutable_path(google_protobuf_GeneratedCodeInfo_Annotation* msg, size_t* size) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__GeneratedCodeInfo__Annotation_msg_init(), 1); - upb_Array* arr = upb_Message_GetMutableArray(msg, &field); + upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (int32_t*)_upb_array_ptr(arr); @@ -6264,11 +6517,13 @@ UPB_INLINE int32_t* google_protobuf_GeneratedCodeInfo_Annotation_mutable_path(go } UPB_INLINE int32_t* google_protobuf_GeneratedCodeInfo_Annotation_resize_path(google_protobuf_GeneratedCodeInfo_Annotation* msg, size_t size, upb_Arena* arena) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__GeneratedCodeInfo__Annotation_msg_init(), 1); - return (int32_t*)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); + return (int32_t*)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg), + &field, size, arena); } UPB_INLINE bool google_protobuf_GeneratedCodeInfo_Annotation_add_path(google_protobuf_GeneratedCodeInfo_Annotation* msg, int32_t val, upb_Arena* arena) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__GeneratedCodeInfo__Annotation_msg_init(), 1); - upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray( + UPB_UPCAST(msg), &field, arena); if (!arr || !_upb_Array_ResizeUninitialized( arr, arr->UPB_PRIVATE(size) + 1, arena)) { return false; @@ -6279,19 +6534,19 @@ UPB_INLINE bool google_protobuf_GeneratedCodeInfo_Annotation_add_path(google_pro } UPB_INLINE void google_protobuf_GeneratedCodeInfo_Annotation_set_source_file(google_protobuf_GeneratedCodeInfo_Annotation *msg, upb_StringView value) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__GeneratedCodeInfo__Annotation_msg_init(), 2); - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_GeneratedCodeInfo_Annotation_set_begin(google_protobuf_GeneratedCodeInfo_Annotation *msg, int32_t value) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__GeneratedCodeInfo__Annotation_msg_init(), 3); - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_GeneratedCodeInfo_Annotation_set_end(google_protobuf_GeneratedCodeInfo_Annotation *msg, int32_t value) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__GeneratedCodeInfo__Annotation_msg_init(), 4); - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_GeneratedCodeInfo_Annotation_set_semantic(google_protobuf_GeneratedCodeInfo_Annotation *msg, int32_t value) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__GeneratedCodeInfo__Annotation_msg_init(), 5); - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } /* Max size 32 is google.protobuf.FileOptions */ diff --git a/upb/test/BUILD b/upb/test/BUILD index 726dd6bdef043..a447a82cc0e89 100644 --- a/upb/test/BUILD +++ b/upb/test/BUILD @@ -208,6 +208,7 @@ cc_test( ":timestamp_upb_proto", ":timestamp_upb_proto_reflection", "@com_google_googletest//:gtest_main", + "//upb:base", "//upb:json", "//upb:port", "//upb:reflection", diff --git a/upb/test/test_cpp.cc b/upb/test/test_cpp.cc index a2d1c4c4565e2..6f917150d58b8 100644 --- a/upb/test/test_cpp.cc +++ b/upb/test/test_cpp.cc @@ -17,6 +17,7 @@ #include "google/protobuf/timestamp.upb.h" #include "google/protobuf/timestamp.upbdefs.h" #include +#include "upb/base/upcast.h" #include "upb/json/decode.h" #include "upb/json/encode.h" #include "upb/reflection/def.h" @@ -57,7 +58,8 @@ TEST(Cpp, Default) { upb::Arena arena; upb::MessageDefPtr md(upb_test_TestMessage_getmsgdef(defpool.ptr())); upb_test_TestMessage* msg = upb_test_TestMessage_new(arena.ptr()); - size_t size = upb_JsonEncode(msg, md.ptr(), nullptr, 0, nullptr, 0, nullptr); + size_t size = upb_JsonEncode(UPB_UPCAST(msg), md.ptr(), nullptr, 0, nullptr, + 0, nullptr); EXPECT_EQ(2, size); // "{}" } @@ -95,10 +97,10 @@ TEST(Cpp, TimestampEncoder) { google_protobuf_Timestamp_set_seconds(timestamp_upb, timestamp); char json[128]; - size_t size = upb_JsonEncode(timestamp_upb, md.ptr(), nullptr, 0, json, - sizeof(json), nullptr); - bool result = upb_JsonDecode(json, size, timestamp_upb_decoded, md.ptr(), - nullptr, 0, arena.ptr(), nullptr); + size_t size = upb_JsonEncode(UPB_UPCAST(timestamp_upb), md.ptr(), nullptr, + 0, json, sizeof(json), nullptr); + bool result = upb_JsonDecode(json, size, UPB_UPCAST(timestamp_upb_decoded), + md.ptr(), nullptr, 0, arena.ptr(), nullptr); const int64_t timestamp_decoded = google_protobuf_Timestamp_seconds(timestamp_upb_decoded); diff --git a/upb/util/def_to_proto_test.cc b/upb/util/def_to_proto_test.cc index cad9abf53541a..523efd2708bf1 100644 --- a/upb/util/def_to_proto_test.cc +++ b/upb/util/def_to_proto_test.cc @@ -75,9 +75,9 @@ MATCHER_P2(EqualsUpbProto, proto, msgdef_func, AddMessageDescriptor(msgdef, &pool); EXPECT_TRUE(desc != nullptr); std::unique_ptr m1( - ToProto(proto, msgdef.ptr(), desc, &factory)); + ToProto(UPB_UPCAST(proto), msgdef.ptr(), desc, &factory)); std::unique_ptr m2( - ToProto(arg, msgdef.ptr(), desc, &factory)); + ToProto((upb_Message*)arg, msgdef.ptr(), desc, &factory)); std::string differences; google::protobuf::util::MessageDifferencer differencer; differencer.ReportDifferencesToString(&differences); diff --git a/upb/util/required_fields_test.cc b/upb/util/required_fields_test.cc index 396c3aa997550..7698cfb3b8900 100644 --- a/upb/util/required_fields_test.cc +++ b/upb/util/required_fields_test.cc @@ -12,6 +12,7 @@ #include #include "absl/strings/string_view.h" #include "upb/base/status.hpp" +#include "upb/base/upcast.h" #include "upb/json/decode.h" #include "upb/mem/arena.h" #include "upb/mem/arena.hpp" @@ -53,13 +54,14 @@ class RequiredFieldsTest : public testing::Test { auto* test_msg = T::NewMessage(arena.ptr()); upb::MessageDefPtr m = T::GetMessageDef(defpool.ptr()); upb::Status status; - EXPECT_TRUE(upb_JsonDecode(json.data(), json.size(), test_msg, m.ptr(), - defpool.ptr(), 0, arena.ptr(), status.ptr())) + EXPECT_TRUE(upb_JsonDecode(json.data(), json.size(), UPB_UPCAST(test_msg), + m.ptr(), defpool.ptr(), 0, arena.ptr(), + status.ptr())) << status.error_message(); upb_FieldPathEntry* entries = nullptr; - EXPECT_EQ( - !missing.empty(), - upb_util_HasUnsetRequired(test_msg, m.ptr(), defpool.ptr(), &entries)); + EXPECT_EQ(!missing.empty(), + upb_util_HasUnsetRequired(UPB_UPCAST(test_msg), m.ptr(), + defpool.ptr(), &entries)); if (entries) { EXPECT_EQ(missing, PathsToText(entries)); free(entries); @@ -67,8 +69,9 @@ class RequiredFieldsTest : public testing::Test { // Verify that we can pass a NULL pointer to entries when we don't care // about them. - EXPECT_EQ(!missing.empty(), upb_util_HasUnsetRequired( - test_msg, m.ptr(), defpool.ptr(), nullptr)); + EXPECT_EQ(!missing.empty(), + upb_util_HasUnsetRequired(UPB_UPCAST(test_msg), m.ptr(), + defpool.ptr(), nullptr)); } }; diff --git a/upb/wire/decode.c b/upb/wire/decode.c index 044cae261e2aa..f6bb42768ba20 100644 --- a/upb/wire/decode.c +++ b/upb/wire/decode.c @@ -647,18 +647,18 @@ static const char* _upb_Decoder_DecodeToMap(upb_Decoder* d, const char* ptr, ent.data.v.val = upb_value_uintptr(msg); } - ptr = - _upb_Decoder_DecodeSubMessage(d, ptr, &ent.data, subs, field, val->size); + ptr = _upb_Decoder_DecodeSubMessage(d, ptr, (upb_Message*)&ent.data, subs, + field, val->size); // check if ent had any unknown fields size_t size; - upb_Message_GetUnknown(&ent.data, &size); + upb_Message_GetUnknown((upb_Message*)&ent.data, &size); if (size != 0) { char* buf; size_t size; uint32_t tag = ((uint32_t)field->UPB_PRIVATE(number) << 3) | kUpb_WireType_Delimited; upb_EncodeStatus status = - upb_Encode(&ent.data, entry, 0, &d->arena, &buf, &size); + upb_Encode((upb_Message*)&ent.data, entry, 0, &d->arena, &buf, &size); if (status != kUpb_EncodeStatus_Ok) { _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_OutOfMemory); } @@ -1160,7 +1160,7 @@ static const char* _upb_Decoder_DecodeKnownField( _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_OutOfMemory); } d->unknown_msg = msg; - msg = &ext->data; + msg = (upb_Message*)&ext->data; subs = &ext->ext->UPB_PRIVATE(sub); } @@ -1351,7 +1351,7 @@ static upb_DecodeStatus upb_Decoder_Decode(upb_Decoder* const decoder, return decoder->status; } -upb_DecodeStatus upb_Decode(const char* buf, size_t size, void* msg, +upb_DecodeStatus upb_Decode(const char* buf, size_t size, upb_Message* msg, const upb_MiniTable* l, const upb_ExtensionRegistry* extreg, int options, upb_Arena* arena) { diff --git a/upb/wire/encode.c b/upb/wire/encode.c index 2e4f2e4812808..ae2be7f734333 100644 --- a/upb/wire/encode.c +++ b/upb/wire/encode.c @@ -535,7 +535,7 @@ static void encode_ext(upb_encstate* e, const upb_Extension* ext, if (UPB_UNLIKELY(is_message_set)) { encode_msgset_item(e, ext); } else { - encode_field(e, &ext->data, &ext->ext->UPB_PRIVATE(sub), + encode_field(e, (upb_Message*)&ext->data, &ext->ext->UPB_PRIVATE(sub), &ext->ext->UPB_PRIVATE(field)); } } @@ -603,7 +603,7 @@ static void encode_message(upb_encstate* e, const upb_Message* msg, } static upb_EncodeStatus upb_Encoder_Encode(upb_encstate* const encoder, - const void* const msg, + const upb_Message* const msg, const upb_MiniTable* const l, char** const buf, size_t* const size) { @@ -631,7 +631,7 @@ static upb_EncodeStatus upb_Encoder_Encode(upb_encstate* const encoder, return encoder->status; } -upb_EncodeStatus upb_Encode(const void* msg, const upb_MiniTable* l, +upb_EncodeStatus upb_Encode(const upb_Message* msg, const upb_MiniTable* l, int options, upb_Arena* arena, char** buf, size_t* size) { upb_encstate e; diff --git a/upb/wire/encode.h b/upb/wire/encode.h index 6fb5553143be1..fdccaf963e021 100644 --- a/upb/wire/encode.h +++ b/upb/wire/encode.h @@ -63,9 +63,9 @@ UPB_INLINE int upb_Encode_LimitDepth(uint32_t encode_options, uint32_t limit) { return upb_EncodeOptions_MaxDepth(max_depth) | (encode_options & 0xffff); } -UPB_API upb_EncodeStatus upb_Encode(const void* msg, const upb_MiniTable* l, - int options, upb_Arena* arena, char** buf, - size_t* size); +UPB_API upb_EncodeStatus upb_Encode(const upb_Message* msg, + const upb_MiniTable* l, int options, + upb_Arena* arena, char** buf, size_t* size); #ifdef __cplusplus } /* extern "C" */ diff --git a/upb_generator/protoc-gen-upb.cc b/upb_generator/protoc-gen-upb.cc index 8a7e213f54042..b5d3e2c487506 100644 --- a/upb_generator/protoc-gen-upb.cc +++ b/upb_generator/protoc-gen-upb.cc @@ -260,7 +260,7 @@ void GenerateExtensionInHeader(const DefPoolPair& pools, upb::FieldDefPtr ext, output( R"cc( UPB_INLINE bool $0_has_$1(const struct $2* msg) { - return _upb_Message_HasExtensionField(msg, &$3); + return _upb_Message_HasExtensionField((upb_Message*)msg, &$3); } )cc", ExtensionIdentBase(ext), ext.name(), MessageName(ext.containing_type()), @@ -269,7 +269,7 @@ void GenerateExtensionInHeader(const DefPoolPair& pools, upb::FieldDefPtr ext, output( R"cc( UPB_INLINE void $0_clear_$1(struct $2* msg) { - _upb_Message_ClearExtensionField(msg, &$3); + _upb_Message_ClearExtensionField((upb_Message*)msg, &$3); } )cc", ExtensionIdentBase(ext), ext.name(), MessageName(ext.containing_type()), @@ -287,7 +287,7 @@ void GenerateExtensionInHeader(const DefPoolPair& pools, upb::FieldDefPtr ext, &ext->UPB_PRIVATE(field)) == $5); $0 default_val = $6; $0 ret; - _upb_Message_GetExtensionField(msg, ext, &default_val, &ret); + _upb_Message_GetExtensionField((upb_Message*)msg, ext, &default_val, &ret); return ret; } )cc", @@ -301,7 +301,7 @@ void GenerateExtensionInHeader(const DefPoolPair& pools, upb::FieldDefPtr ext, UPB_ASSUME(upb_MiniTableField_IsScalar(&ext->UPB_PRIVATE(field))); UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)( &ext->UPB_PRIVATE(field)) == $5); - bool ok = _upb_Message_SetExtensionField(msg, ext, &val, arena); + bool ok = _upb_Message_SetExtensionField((upb_Message*)msg, ext, &val, arena); UPB_ASSERT(ok); } )cc", @@ -323,7 +323,8 @@ void GenerateMessageFunctionsInHeader(upb::MessageDefPtr message, UPB_INLINE $0* $0_parse(const char* buf, size_t size, upb_Arena* arena) { $0* ret = $0_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, $1, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), $1, NULL, 0, arena) != + kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -333,21 +334,21 @@ void GenerateMessageFunctionsInHeader(upb::MessageDefPtr message, int options, upb_Arena* arena) { $0* ret = $0_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, $1, extreg, options, arena) != - kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), $1, extreg, options, + arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* $0_serialize(const $0* msg, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, $1, 0, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), $1, 0, arena, &ptr, len); return ptr; } UPB_INLINE char* $0_serialize_ex(const $0* msg, int options, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, $1, options, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), $1, options, arena, &ptr, len); return ptr; } )cc", @@ -371,7 +372,8 @@ void GenerateOneofInHeader(upb::OneofDefPtr oneof, const DefPoolPair& pools, R"cc( UPB_INLINE $0_oneofcases $1_$2_case(const $1* msg) { const upb_MiniTableField field = $3; - return ($0_oneofcases)upb_Message_WhichOneofFieldNumber(msg, &field); + return ($0_oneofcases)upb_Message_WhichOneofFieldNumber( + UPB_UPCAST(msg), &field); } )cc", fullname, msg_name, oneof.name(), @@ -388,7 +390,7 @@ void GenerateHazzer(upb::FieldDefPtr field, const DefPoolPair& pools, R"cc( UPB_INLINE bool $0_has_$1(const $0* msg) { const upb_MiniTableField field = $2; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } )cc", msg_name, resolved_name, FieldInitializer(pools, field, options)); @@ -409,7 +411,7 @@ void GenerateClear(upb::FieldDefPtr field, const DefPoolPair& pools, R"cc( UPB_INLINE void $0_clear_$1($0* msg) { const upb_MiniTableField field = $2; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } )cc", msg_name, resolved_name, FieldInitializer(pools, field, options)); @@ -424,7 +426,7 @@ void GenerateMapGetters(upb::FieldDefPtr field, const DefPoolPair& pools, R"cc( UPB_INLINE size_t $0_$1_size(const $0* msg) { const upb_MiniTableField field = $2; - const upb_Map* map = upb_Message_GetMap(msg, &field); + const upb_Map* map = upb_Message_GetMap(UPB_UPCAST(msg), &field); return map ? _upb_Map_Size(map) : 0; } )cc", @@ -433,7 +435,7 @@ void GenerateMapGetters(upb::FieldDefPtr field, const DefPoolPair& pools, R"cc( UPB_INLINE bool $0_$1_get(const $0* msg, $2 key, $3* val) { const upb_MiniTableField field = $4; - const upb_Map* map = upb_Message_GetMap(msg, &field); + const upb_Map* map = upb_Message_GetMap(UPB_UPCAST(msg), &field); if (!map) return false; return _upb_Map_Get(map, &key, $5, val, $6); } @@ -445,7 +447,7 @@ void GenerateMapGetters(upb::FieldDefPtr field, const DefPoolPair& pools, R"cc( UPB_INLINE $0 $1_$2_next(const $1* msg, size_t* iter) { const upb_MiniTableField field = $3; - const upb_Map* map = upb_Message_GetMap(msg, &field); + const upb_Map* map = upb_Message_GetMap(UPB_UPCAST(msg), &field); if (!map) return NULL; return ($0)_upb_map_next(map, iter); } @@ -462,11 +464,11 @@ void GenerateMapGetters(upb::FieldDefPtr field, const DefPoolPair& pools, R"cc( UPB_INLINE const upb_Map* _$0_$1_$2($0* msg) { const upb_MiniTableField field = $4; - return upb_Message_GetMap(msg, &field); + return upb_Message_GetMap(UPB_UPCAST(msg), &field); } UPB_INLINE upb_Map* _$0_$1_$3($0* msg, upb_Arena* a) { const upb_MiniTableField field = $4; - return _upb_Message_GetOrCreateMutableMap(msg, &field, $5, $6, a); + return _upb_Message_GetOrCreateMutableMap(UPB_UPCAST(msg), &field, $5, $6, a); } )cc", msg_name, resolved_name, kMapGetterPostfix, kMutableMapGetterPostfix, @@ -501,7 +503,7 @@ void GenerateRepeatedGetters(upb::FieldDefPtr field, const DefPoolPair& pools, R"cc( UPB_INLINE $0 const* $1_$2(const $1* msg, size_t* size) { const upb_MiniTableField field = $3; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return ($0 const*)_upb_array_constptr(arr); @@ -526,16 +528,16 @@ void GenerateRepeatedGetters(upb::FieldDefPtr field, const DefPoolPair& pools, R"cc( UPB_INLINE const upb_Array* _$1_$2_$4(const $1* msg, size_t* size) { const upb_MiniTableField field = $3; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } - UPB_INLINE upb_Array* _$1_$2_$5(const $1* msg, size_t* size, upb_Arena* arena) { + UPB_INLINE upb_Array* _$1_$2_$5($1* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = $3; - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - (upb_Message*)msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), + &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -562,7 +564,8 @@ void GenerateScalarGetters(upb::FieldDefPtr field, const DefPoolPair& pools, $0 default_val = $3; $0 ret; const upb_MiniTableField field = $4; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } )cc", @@ -596,7 +599,7 @@ void GenerateMapSetters(upb::FieldDefPtr field, const DefPoolPair& pools, R"cc( UPB_INLINE void $0_$1_clear($0* msg) { const upb_MiniTableField field = $2; - upb_Map* map = (upb_Map*)upb_Message_GetMap(msg, &field); + upb_Map* map = (upb_Map*)upb_Message_GetMap(UPB_UPCAST(msg), &field); if (!map) return; _upb_Map_Clear(map); } @@ -606,7 +609,8 @@ void GenerateMapSetters(upb::FieldDefPtr field, const DefPoolPair& pools, R"cc( UPB_INLINE bool $0_$1_set($0* msg, $2 key, $3 val, upb_Arena* a) { const upb_MiniTableField field = $4; - upb_Map* map = _upb_Message_GetOrCreateMutableMap(msg, &field, $5, $6, a); + upb_Map* map = _upb_Message_GetOrCreateMutableMap(UPB_UPCAST(msg), + &field, $5, $6, a); return _upb_Map_Insert(map, &key, $5, &val, $6, a) != kUpb_MapInsertStatus_OutOfMemory; } @@ -618,7 +622,7 @@ void GenerateMapSetters(upb::FieldDefPtr field, const DefPoolPair& pools, R"cc( UPB_INLINE bool $0_$1_delete($0* msg, $2 key) { const upb_MiniTableField field = $3; - upb_Map* map = (upb_Map*)upb_Message_GetMap(msg, &field); + upb_Map* map = (upb_Map*)upb_Message_GetMap(UPB_UPCAST(msg), &field); if (!map) return false; return _upb_Map_Delete(map, &key, $4, NULL); } @@ -629,7 +633,7 @@ void GenerateMapSetters(upb::FieldDefPtr field, const DefPoolPair& pools, R"cc( UPB_INLINE $0 $1_$2_nextmutable($1* msg, size_t* iter) { const upb_MiniTableField field = $3; - upb_Map* map = (upb_Map*)upb_Message_GetMap(msg, &field); + upb_Map* map = (upb_Map*)upb_Message_GetMap(UPB_UPCAST(msg), &field); if (!map) return NULL; return ($0)_upb_map_next(map, iter); } @@ -647,7 +651,7 @@ void GenerateRepeatedSetters(upb::FieldDefPtr field, const DefPoolPair& pools, R"cc( UPB_INLINE $0* $1_mutable_$2($1* msg, size_t* size) { upb_MiniTableField field = $3; - upb_Array* arr = upb_Message_GetMutableArray(msg, &field); + upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return ($0*)_upb_array_ptr(arr); @@ -663,7 +667,8 @@ void GenerateRepeatedSetters(upb::FieldDefPtr field, const DefPoolPair& pools, R"cc( UPB_INLINE $0* $1_resize_$2($1* msg, size_t size, upb_Arena* arena) { upb_MiniTableField field = $3; - return ($0*)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); + return ($0*)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg), + &field, size, arena); } )cc", CType(field), msg_name, resolved_name, @@ -673,7 +678,8 @@ void GenerateRepeatedSetters(upb::FieldDefPtr field, const DefPoolPair& pools, R"cc( UPB_INLINE struct $0* $1_add_$2($1* msg, upb_Arena* arena) { upb_MiniTableField field = $4; - upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray( + UPB_UPCAST(msg), &field, arena); if (!arr || !_upb_Array_ResizeUninitialized( arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; @@ -693,7 +699,8 @@ void GenerateRepeatedSetters(upb::FieldDefPtr field, const DefPoolPair& pools, R"cc( UPB_INLINE bool $1_add_$2($1* msg, $0 val, upb_Arena* arena) { upb_MiniTableField field = $3; - upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray( + UPB_UPCAST(msg), &field, arena); if (!arr || !_upb_Array_ResizeUninitialized( arr, arr->UPB_PRIVATE(size) + 1, arena)) { return false; @@ -733,7 +740,7 @@ void GenerateNonRepeatedSetters(upb::FieldDefPtr field, output(R"cc( UPB_INLINE void $0_set_$1($0 *msg, $2 value) { const upb_MiniTableField field = $3; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } )cc", msg_name, field_name, CType(field), @@ -892,7 +899,8 @@ void WriteHeader(const DefPoolPair& pools, upb::FileDefPtr file, // Forward-declare types defined in this file. for (auto message : this_file_messages) { - output("typedef struct $0 $0;\n", ToCIdent(message.full_name())); + output("typedef struct $0 { upb_Message UPB_PRIVATE(base); } $0;\n", + ToCIdent(message.full_name())); } // Forward-declare types not in this file, but used as submessages. diff --git a/upb_generator/stage0/google/protobuf/compiler/plugin.upb.h b/upb_generator/stage0/google/protobuf/compiler/plugin.upb.h index b354a86aab843..f987de7a5cadc 100644 --- a/upb_generator/stage0/google/protobuf/compiler/plugin.upb.h +++ b/upb_generator/stage0/google/protobuf/compiler/plugin.upb.h @@ -25,10 +25,10 @@ extern const upb_MiniTable* google__protobuf__FileDescriptorProto_msg_init(); extern const upb_MiniTable* google__protobuf__GeneratedCodeInfo_msg_init(); extern const upb_MiniTableEnum* google_protobuf_compiler_CodeGeneratorResponse_Feature_enum_init(); -typedef struct google_protobuf_compiler_Version google_protobuf_compiler_Version; -typedef struct google_protobuf_compiler_CodeGeneratorRequest google_protobuf_compiler_CodeGeneratorRequest; -typedef struct google_protobuf_compiler_CodeGeneratorResponse google_protobuf_compiler_CodeGeneratorResponse; -typedef struct google_protobuf_compiler_CodeGeneratorResponse_File google_protobuf_compiler_CodeGeneratorResponse_File; +typedef struct google_protobuf_compiler_Version { upb_Message UPB_PRIVATE(base); } google_protobuf_compiler_Version; +typedef struct google_protobuf_compiler_CodeGeneratorRequest { upb_Message UPB_PRIVATE(base); } google_protobuf_compiler_CodeGeneratorRequest; +typedef struct google_protobuf_compiler_CodeGeneratorResponse { upb_Message UPB_PRIVATE(base); } google_protobuf_compiler_CodeGeneratorResponse; +typedef struct google_protobuf_compiler_CodeGeneratorResponse_File { upb_Message UPB_PRIVATE(base); } google_protobuf_compiler_CodeGeneratorResponse_File; struct google_protobuf_FileDescriptorProto; struct google_protobuf_GeneratedCodeInfo; @@ -48,7 +48,8 @@ UPB_INLINE google_protobuf_compiler_Version* google_protobuf_compiler_Version_ne UPB_INLINE google_protobuf_compiler_Version* google_protobuf_compiler_Version_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_compiler_Version* ret = google_protobuf_compiler_Version_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, google__protobuf__compiler__Version_msg_init(), NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), google__protobuf__compiler__Version_msg_init(), NULL, 0, arena) != + kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -58,99 +59,103 @@ UPB_INLINE google_protobuf_compiler_Version* google_protobuf_compiler_Version_pa int options, upb_Arena* arena) { google_protobuf_compiler_Version* ret = google_protobuf_compiler_Version_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, google__protobuf__compiler__Version_msg_init(), extreg, options, arena) != - kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), google__protobuf__compiler__Version_msg_init(), extreg, options, + arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_compiler_Version_serialize(const google_protobuf_compiler_Version* msg, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, google__protobuf__compiler__Version_msg_init(), 0, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), google__protobuf__compiler__Version_msg_init(), 0, arena, &ptr, len); return ptr; } UPB_INLINE char* google_protobuf_compiler_Version_serialize_ex(const google_protobuf_compiler_Version* msg, int options, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, google__protobuf__compiler__Version_msg_init(), options, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), google__protobuf__compiler__Version_msg_init(), options, arena, &ptr, len); return ptr; } UPB_INLINE void google_protobuf_compiler_Version_clear_major(google_protobuf_compiler_Version* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__Version_msg_init(), 1); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_compiler_Version_major(const google_protobuf_compiler_Version* msg) { int32_t default_val = (int32_t)0; int32_t ret; const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__Version_msg_init(), 1); - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_compiler_Version_has_major(const google_protobuf_compiler_Version* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__Version_msg_init(), 1); - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_compiler_Version_clear_minor(google_protobuf_compiler_Version* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__Version_msg_init(), 2); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_compiler_Version_minor(const google_protobuf_compiler_Version* msg) { int32_t default_val = (int32_t)0; int32_t ret; const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__Version_msg_init(), 2); - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_compiler_Version_has_minor(const google_protobuf_compiler_Version* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__Version_msg_init(), 2); - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_compiler_Version_clear_patch(google_protobuf_compiler_Version* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__Version_msg_init(), 3); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_compiler_Version_patch(const google_protobuf_compiler_Version* msg) { int32_t default_val = (int32_t)0; int32_t ret; const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__Version_msg_init(), 3); - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_compiler_Version_has_patch(const google_protobuf_compiler_Version* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__Version_msg_init(), 3); - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_compiler_Version_clear_suffix(google_protobuf_compiler_Version* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__Version_msg_init(), 4); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_compiler_Version_suffix(const google_protobuf_compiler_Version* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__Version_msg_init(), 4); - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_compiler_Version_has_suffix(const google_protobuf_compiler_Version* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__Version_msg_init(), 4); - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_compiler_Version_set_major(google_protobuf_compiler_Version *msg, int32_t value) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__Version_msg_init(), 1); - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_compiler_Version_set_minor(google_protobuf_compiler_Version *msg, int32_t value) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__Version_msg_init(), 2); - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_compiler_Version_set_patch(google_protobuf_compiler_Version *msg, int32_t value) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__Version_msg_init(), 3); - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_compiler_Version_set_suffix(google_protobuf_compiler_Version *msg, upb_StringView value) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__Version_msg_init(), 4); - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } /* google.protobuf.compiler.CodeGeneratorRequest */ @@ -161,7 +166,8 @@ UPB_INLINE google_protobuf_compiler_CodeGeneratorRequest* google_protobuf_compil UPB_INLINE google_protobuf_compiler_CodeGeneratorRequest* google_protobuf_compiler_CodeGeneratorRequest_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_compiler_CodeGeneratorRequest* ret = google_protobuf_compiler_CodeGeneratorRequest_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, google__protobuf__compiler__CodeGeneratorRequest_msg_init(), NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), google__protobuf__compiler__CodeGeneratorRequest_msg_init(), NULL, 0, arena) != + kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -171,30 +177,30 @@ UPB_INLINE google_protobuf_compiler_CodeGeneratorRequest* google_protobuf_compil int options, upb_Arena* arena) { google_protobuf_compiler_CodeGeneratorRequest* ret = google_protobuf_compiler_CodeGeneratorRequest_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, google__protobuf__compiler__CodeGeneratorRequest_msg_init(), extreg, options, arena) != - kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), google__protobuf__compiler__CodeGeneratorRequest_msg_init(), extreg, options, + arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_compiler_CodeGeneratorRequest_serialize(const google_protobuf_compiler_CodeGeneratorRequest* msg, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, google__protobuf__compiler__CodeGeneratorRequest_msg_init(), 0, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), google__protobuf__compiler__CodeGeneratorRequest_msg_init(), 0, arena, &ptr, len); return ptr; } UPB_INLINE char* google_protobuf_compiler_CodeGeneratorRequest_serialize_ex(const google_protobuf_compiler_CodeGeneratorRequest* msg, int options, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, google__protobuf__compiler__CodeGeneratorRequest_msg_init(), options, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), google__protobuf__compiler__CodeGeneratorRequest_msg_init(), options, arena, &ptr, len); return ptr; } UPB_INLINE void google_protobuf_compiler_CodeGeneratorRequest_clear_file_to_generate(google_protobuf_compiler_CodeGeneratorRequest* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorRequest_msg_init(), 1); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView const* google_protobuf_compiler_CodeGeneratorRequest_file_to_generate(const google_protobuf_compiler_CodeGeneratorRequest* msg, size_t* size) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorRequest_msg_init(), 1); - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (upb_StringView const*)_upb_array_constptr(arr); @@ -205,16 +211,16 @@ UPB_INLINE upb_StringView const* google_protobuf_compiler_CodeGeneratorRequest_f } UPB_INLINE const upb_Array* _google_protobuf_compiler_CodeGeneratorRequest_file_to_generate_upb_array(const google_protobuf_compiler_CodeGeneratorRequest* msg, size_t* size) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorRequest_msg_init(), 1); - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } -UPB_INLINE upb_Array* _google_protobuf_compiler_CodeGeneratorRequest_file_to_generate_mutable_upb_array(const google_protobuf_compiler_CodeGeneratorRequest* msg, size_t* size, upb_Arena* arena) { +UPB_INLINE upb_Array* _google_protobuf_compiler_CodeGeneratorRequest_file_to_generate_mutable_upb_array(google_protobuf_compiler_CodeGeneratorRequest* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorRequest_msg_init(), 1); upb_Array* arr = upb_Message_GetOrCreateMutableArray( - (upb_Message*)msg, &field, arena); + UPB_UPCAST(msg), &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -222,41 +228,43 @@ UPB_INLINE upb_Array* _google_protobuf_compiler_CodeGeneratorRequest_file_to_gen } UPB_INLINE void google_protobuf_compiler_CodeGeneratorRequest_clear_parameter(google_protobuf_compiler_CodeGeneratorRequest* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorRequest_msg_init(), 2); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_compiler_CodeGeneratorRequest_parameter(const google_protobuf_compiler_CodeGeneratorRequest* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorRequest_msg_init(), 2); - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_compiler_CodeGeneratorRequest_has_parameter(const google_protobuf_compiler_CodeGeneratorRequest* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorRequest_msg_init(), 2); - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_compiler_CodeGeneratorRequest_clear_compiler_version(google_protobuf_compiler_CodeGeneratorRequest* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorRequest_msg_init(), 3); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_compiler_Version* google_protobuf_compiler_CodeGeneratorRequest_compiler_version(const google_protobuf_compiler_CodeGeneratorRequest* msg) { const google_protobuf_compiler_Version* default_val = NULL; const google_protobuf_compiler_Version* ret; const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorRequest_msg_init(), 3); - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_compiler_CodeGeneratorRequest_has_compiler_version(const google_protobuf_compiler_CodeGeneratorRequest* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorRequest_msg_init(), 3); - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_compiler_CodeGeneratorRequest_clear_proto_file(google_protobuf_compiler_CodeGeneratorRequest* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorRequest_msg_init(), 15); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const struct google_protobuf_FileDescriptorProto* const* google_protobuf_compiler_CodeGeneratorRequest_proto_file(const google_protobuf_compiler_CodeGeneratorRequest* msg, size_t* size) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorRequest_msg_init(), 15); - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (const struct google_protobuf_FileDescriptorProto* const*)_upb_array_constptr(arr); @@ -267,16 +275,16 @@ UPB_INLINE const struct google_protobuf_FileDescriptorProto* const* google_proto } UPB_INLINE const upb_Array* _google_protobuf_compiler_CodeGeneratorRequest_proto_file_upb_array(const google_protobuf_compiler_CodeGeneratorRequest* msg, size_t* size) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorRequest_msg_init(), 15); - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } -UPB_INLINE upb_Array* _google_protobuf_compiler_CodeGeneratorRequest_proto_file_mutable_upb_array(const google_protobuf_compiler_CodeGeneratorRequest* msg, size_t* size, upb_Arena* arena) { +UPB_INLINE upb_Array* _google_protobuf_compiler_CodeGeneratorRequest_proto_file_mutable_upb_array(google_protobuf_compiler_CodeGeneratorRequest* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorRequest_msg_init(), 15); upb_Array* arr = upb_Message_GetOrCreateMutableArray( - (upb_Message*)msg, &field, arena); + UPB_UPCAST(msg), &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -284,11 +292,11 @@ UPB_INLINE upb_Array* _google_protobuf_compiler_CodeGeneratorRequest_proto_file_ } UPB_INLINE void google_protobuf_compiler_CodeGeneratorRequest_clear_source_file_descriptors(google_protobuf_compiler_CodeGeneratorRequest* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorRequest_msg_init(), 17); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const struct google_protobuf_FileDescriptorProto* const* google_protobuf_compiler_CodeGeneratorRequest_source_file_descriptors(const google_protobuf_compiler_CodeGeneratorRequest* msg, size_t* size) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorRequest_msg_init(), 17); - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (const struct google_protobuf_FileDescriptorProto* const*)_upb_array_constptr(arr); @@ -299,16 +307,16 @@ UPB_INLINE const struct google_protobuf_FileDescriptorProto* const* google_proto } UPB_INLINE const upb_Array* _google_protobuf_compiler_CodeGeneratorRequest_source_file_descriptors_upb_array(const google_protobuf_compiler_CodeGeneratorRequest* msg, size_t* size) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorRequest_msg_init(), 17); - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } -UPB_INLINE upb_Array* _google_protobuf_compiler_CodeGeneratorRequest_source_file_descriptors_mutable_upb_array(const google_protobuf_compiler_CodeGeneratorRequest* msg, size_t* size, upb_Arena* arena) { +UPB_INLINE upb_Array* _google_protobuf_compiler_CodeGeneratorRequest_source_file_descriptors_mutable_upb_array(google_protobuf_compiler_CodeGeneratorRequest* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorRequest_msg_init(), 17); upb_Array* arr = upb_Message_GetOrCreateMutableArray( - (upb_Message*)msg, &field, arena); + UPB_UPCAST(msg), &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -317,7 +325,7 @@ UPB_INLINE upb_Array* _google_protobuf_compiler_CodeGeneratorRequest_source_file UPB_INLINE upb_StringView* google_protobuf_compiler_CodeGeneratorRequest_mutable_file_to_generate(google_protobuf_compiler_CodeGeneratorRequest* msg, size_t* size) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorRequest_msg_init(), 1); - upb_Array* arr = upb_Message_GetMutableArray(msg, &field); + upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (upb_StringView*)_upb_array_ptr(arr); @@ -328,11 +336,13 @@ UPB_INLINE upb_StringView* google_protobuf_compiler_CodeGeneratorRequest_mutable } UPB_INLINE upb_StringView* google_protobuf_compiler_CodeGeneratorRequest_resize_file_to_generate(google_protobuf_compiler_CodeGeneratorRequest* msg, size_t size, upb_Arena* arena) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorRequest_msg_init(), 1); - return (upb_StringView*)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); + return (upb_StringView*)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg), + &field, size, arena); } UPB_INLINE bool google_protobuf_compiler_CodeGeneratorRequest_add_file_to_generate(google_protobuf_compiler_CodeGeneratorRequest* msg, upb_StringView val, upb_Arena* arena) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorRequest_msg_init(), 1); - upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray( + UPB_UPCAST(msg), &field, arena); if (!arr || !_upb_Array_ResizeUninitialized( arr, arr->UPB_PRIVATE(size) + 1, arena)) { return false; @@ -343,11 +353,11 @@ UPB_INLINE bool google_protobuf_compiler_CodeGeneratorRequest_add_file_to_genera } UPB_INLINE void google_protobuf_compiler_CodeGeneratorRequest_set_parameter(google_protobuf_compiler_CodeGeneratorRequest *msg, upb_StringView value) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorRequest_msg_init(), 2); - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_compiler_CodeGeneratorRequest_set_compiler_version(google_protobuf_compiler_CodeGeneratorRequest *msg, google_protobuf_compiler_Version* value) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorRequest_msg_init(), 3); - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE struct google_protobuf_compiler_Version* google_protobuf_compiler_CodeGeneratorRequest_mutable_compiler_version(google_protobuf_compiler_CodeGeneratorRequest* msg, upb_Arena* arena) { struct google_protobuf_compiler_Version* sub = (struct google_protobuf_compiler_Version*)google_protobuf_compiler_CodeGeneratorRequest_compiler_version(msg); @@ -359,7 +369,7 @@ UPB_INLINE struct google_protobuf_compiler_Version* google_protobuf_compiler_Cod } UPB_INLINE struct google_protobuf_FileDescriptorProto** google_protobuf_compiler_CodeGeneratorRequest_mutable_proto_file(google_protobuf_compiler_CodeGeneratorRequest* msg, size_t* size) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorRequest_msg_init(), 15); - upb_Array* arr = upb_Message_GetMutableArray(msg, &field); + upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (struct google_protobuf_FileDescriptorProto**)_upb_array_ptr(arr); @@ -370,11 +380,13 @@ UPB_INLINE struct google_protobuf_FileDescriptorProto** google_protobuf_compiler } UPB_INLINE struct google_protobuf_FileDescriptorProto** google_protobuf_compiler_CodeGeneratorRequest_resize_proto_file(google_protobuf_compiler_CodeGeneratorRequest* msg, size_t size, upb_Arena* arena) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorRequest_msg_init(), 15); - return (struct google_protobuf_FileDescriptorProto**)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); + return (struct google_protobuf_FileDescriptorProto**)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg), + &field, size, arena); } UPB_INLINE struct google_protobuf_FileDescriptorProto* google_protobuf_compiler_CodeGeneratorRequest_add_proto_file(google_protobuf_compiler_CodeGeneratorRequest* msg, upb_Arena* arena) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorRequest_msg_init(), 15); - upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray( + UPB_UPCAST(msg), &field, arena); if (!arr || !_upb_Array_ResizeUninitialized( arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; @@ -387,7 +399,7 @@ UPB_INLINE struct google_protobuf_FileDescriptorProto* google_protobuf_compiler_ } UPB_INLINE struct google_protobuf_FileDescriptorProto** google_protobuf_compiler_CodeGeneratorRequest_mutable_source_file_descriptors(google_protobuf_compiler_CodeGeneratorRequest* msg, size_t* size) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorRequest_msg_init(), 17); - upb_Array* arr = upb_Message_GetMutableArray(msg, &field); + upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (struct google_protobuf_FileDescriptorProto**)_upb_array_ptr(arr); @@ -398,11 +410,13 @@ UPB_INLINE struct google_protobuf_FileDescriptorProto** google_protobuf_compiler } UPB_INLINE struct google_protobuf_FileDescriptorProto** google_protobuf_compiler_CodeGeneratorRequest_resize_source_file_descriptors(google_protobuf_compiler_CodeGeneratorRequest* msg, size_t size, upb_Arena* arena) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorRequest_msg_init(), 17); - return (struct google_protobuf_FileDescriptorProto**)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); + return (struct google_protobuf_FileDescriptorProto**)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg), + &field, size, arena); } UPB_INLINE struct google_protobuf_FileDescriptorProto* google_protobuf_compiler_CodeGeneratorRequest_add_source_file_descriptors(google_protobuf_compiler_CodeGeneratorRequest* msg, upb_Arena* arena) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorRequest_msg_init(), 17); - upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray( + UPB_UPCAST(msg), &field, arena); if (!arr || !_upb_Array_ResizeUninitialized( arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; @@ -422,7 +436,8 @@ UPB_INLINE google_protobuf_compiler_CodeGeneratorResponse* google_protobuf_compi UPB_INLINE google_protobuf_compiler_CodeGeneratorResponse* google_protobuf_compiler_CodeGeneratorResponse_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_compiler_CodeGeneratorResponse* ret = google_protobuf_compiler_CodeGeneratorResponse_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, google__protobuf__compiler__CodeGeneratorResponse_msg_init(), NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), google__protobuf__compiler__CodeGeneratorResponse_msg_init(), NULL, 0, arena) != + kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -432,90 +447,94 @@ UPB_INLINE google_protobuf_compiler_CodeGeneratorResponse* google_protobuf_compi int options, upb_Arena* arena) { google_protobuf_compiler_CodeGeneratorResponse* ret = google_protobuf_compiler_CodeGeneratorResponse_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, google__protobuf__compiler__CodeGeneratorResponse_msg_init(), extreg, options, arena) != - kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), google__protobuf__compiler__CodeGeneratorResponse_msg_init(), extreg, options, + arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_compiler_CodeGeneratorResponse_serialize(const google_protobuf_compiler_CodeGeneratorResponse* msg, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, google__protobuf__compiler__CodeGeneratorResponse_msg_init(), 0, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), google__protobuf__compiler__CodeGeneratorResponse_msg_init(), 0, arena, &ptr, len); return ptr; } UPB_INLINE char* google_protobuf_compiler_CodeGeneratorResponse_serialize_ex(const google_protobuf_compiler_CodeGeneratorResponse* msg, int options, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, google__protobuf__compiler__CodeGeneratorResponse_msg_init(), options, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), google__protobuf__compiler__CodeGeneratorResponse_msg_init(), options, arena, &ptr, len); return ptr; } UPB_INLINE void google_protobuf_compiler_CodeGeneratorResponse_clear_error(google_protobuf_compiler_CodeGeneratorResponse* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorResponse_msg_init(), 1); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_compiler_CodeGeneratorResponse_error(const google_protobuf_compiler_CodeGeneratorResponse* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorResponse_msg_init(), 1); - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_compiler_CodeGeneratorResponse_has_error(const google_protobuf_compiler_CodeGeneratorResponse* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorResponse_msg_init(), 1); - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_compiler_CodeGeneratorResponse_clear_supported_features(google_protobuf_compiler_CodeGeneratorResponse* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorResponse_msg_init(), 2); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE uint64_t google_protobuf_compiler_CodeGeneratorResponse_supported_features(const google_protobuf_compiler_CodeGeneratorResponse* msg) { uint64_t default_val = (uint64_t)0ull; uint64_t ret; const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorResponse_msg_init(), 2); - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_compiler_CodeGeneratorResponse_has_supported_features(const google_protobuf_compiler_CodeGeneratorResponse* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorResponse_msg_init(), 2); - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_compiler_CodeGeneratorResponse_clear_minimum_edition(google_protobuf_compiler_CodeGeneratorResponse* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorResponse_msg_init(), 3); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_compiler_CodeGeneratorResponse_minimum_edition(const google_protobuf_compiler_CodeGeneratorResponse* msg) { int32_t default_val = (int32_t)0; int32_t ret; const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorResponse_msg_init(), 3); - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_compiler_CodeGeneratorResponse_has_minimum_edition(const google_protobuf_compiler_CodeGeneratorResponse* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorResponse_msg_init(), 3); - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_compiler_CodeGeneratorResponse_clear_maximum_edition(google_protobuf_compiler_CodeGeneratorResponse* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorResponse_msg_init(), 4); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_compiler_CodeGeneratorResponse_maximum_edition(const google_protobuf_compiler_CodeGeneratorResponse* msg) { int32_t default_val = (int32_t)0; int32_t ret; const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorResponse_msg_init(), 4); - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_compiler_CodeGeneratorResponse_has_maximum_edition(const google_protobuf_compiler_CodeGeneratorResponse* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorResponse_msg_init(), 4); - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_compiler_CodeGeneratorResponse_clear_file(google_protobuf_compiler_CodeGeneratorResponse* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorResponse_msg_init(), 15); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_compiler_CodeGeneratorResponse_File* const* google_protobuf_compiler_CodeGeneratorResponse_file(const google_protobuf_compiler_CodeGeneratorResponse* msg, size_t* size) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorResponse_msg_init(), 15); - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_compiler_CodeGeneratorResponse_File* const*)_upb_array_constptr(arr); @@ -526,16 +545,16 @@ UPB_INLINE const google_protobuf_compiler_CodeGeneratorResponse_File* const* goo } UPB_INLINE const upb_Array* _google_protobuf_compiler_CodeGeneratorResponse_file_upb_array(const google_protobuf_compiler_CodeGeneratorResponse* msg, size_t* size) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorResponse_msg_init(), 15); - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } -UPB_INLINE upb_Array* _google_protobuf_compiler_CodeGeneratorResponse_file_mutable_upb_array(const google_protobuf_compiler_CodeGeneratorResponse* msg, size_t* size, upb_Arena* arena) { +UPB_INLINE upb_Array* _google_protobuf_compiler_CodeGeneratorResponse_file_mutable_upb_array(google_protobuf_compiler_CodeGeneratorResponse* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorResponse_msg_init(), 15); upb_Array* arr = upb_Message_GetOrCreateMutableArray( - (upb_Message*)msg, &field, arena); + UPB_UPCAST(msg), &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -544,23 +563,23 @@ UPB_INLINE upb_Array* _google_protobuf_compiler_CodeGeneratorResponse_file_mutab UPB_INLINE void google_protobuf_compiler_CodeGeneratorResponse_set_error(google_protobuf_compiler_CodeGeneratorResponse *msg, upb_StringView value) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorResponse_msg_init(), 1); - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_compiler_CodeGeneratorResponse_set_supported_features(google_protobuf_compiler_CodeGeneratorResponse *msg, uint64_t value) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorResponse_msg_init(), 2); - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_compiler_CodeGeneratorResponse_set_minimum_edition(google_protobuf_compiler_CodeGeneratorResponse *msg, int32_t value) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorResponse_msg_init(), 3); - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_compiler_CodeGeneratorResponse_set_maximum_edition(google_protobuf_compiler_CodeGeneratorResponse *msg, int32_t value) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorResponse_msg_init(), 4); - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE google_protobuf_compiler_CodeGeneratorResponse_File** google_protobuf_compiler_CodeGeneratorResponse_mutable_file(google_protobuf_compiler_CodeGeneratorResponse* msg, size_t* size) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorResponse_msg_init(), 15); - upb_Array* arr = upb_Message_GetMutableArray(msg, &field); + upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_compiler_CodeGeneratorResponse_File**)_upb_array_ptr(arr); @@ -571,11 +590,13 @@ UPB_INLINE google_protobuf_compiler_CodeGeneratorResponse_File** google_protobuf } UPB_INLINE google_protobuf_compiler_CodeGeneratorResponse_File** google_protobuf_compiler_CodeGeneratorResponse_resize_file(google_protobuf_compiler_CodeGeneratorResponse* msg, size_t size, upb_Arena* arena) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorResponse_msg_init(), 15); - return (google_protobuf_compiler_CodeGeneratorResponse_File**)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); + return (google_protobuf_compiler_CodeGeneratorResponse_File**)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg), + &field, size, arena); } UPB_INLINE struct google_protobuf_compiler_CodeGeneratorResponse_File* google_protobuf_compiler_CodeGeneratorResponse_add_file(google_protobuf_compiler_CodeGeneratorResponse* msg, upb_Arena* arena) { upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorResponse_msg_init(), 15); - upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray( + UPB_UPCAST(msg), &field, arena); if (!arr || !_upb_Array_ResizeUninitialized( arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; @@ -595,7 +616,8 @@ UPB_INLINE google_protobuf_compiler_CodeGeneratorResponse_File* google_protobuf_ UPB_INLINE google_protobuf_compiler_CodeGeneratorResponse_File* google_protobuf_compiler_CodeGeneratorResponse_File_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_compiler_CodeGeneratorResponse_File* ret = google_protobuf_compiler_CodeGeneratorResponse_File_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, google__protobuf__compiler__CodeGeneratorResponse__File_msg_init(), NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), google__protobuf__compiler__CodeGeneratorResponse__File_msg_init(), NULL, 0, arena) != + kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -605,99 +627,103 @@ UPB_INLINE google_protobuf_compiler_CodeGeneratorResponse_File* google_protobuf_ int options, upb_Arena* arena) { google_protobuf_compiler_CodeGeneratorResponse_File* ret = google_protobuf_compiler_CodeGeneratorResponse_File_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, google__protobuf__compiler__CodeGeneratorResponse__File_msg_init(), extreg, options, arena) != - kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), google__protobuf__compiler__CodeGeneratorResponse__File_msg_init(), extreg, options, + arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_compiler_CodeGeneratorResponse_File_serialize(const google_protobuf_compiler_CodeGeneratorResponse_File* msg, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, google__protobuf__compiler__CodeGeneratorResponse__File_msg_init(), 0, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), google__protobuf__compiler__CodeGeneratorResponse__File_msg_init(), 0, arena, &ptr, len); return ptr; } UPB_INLINE char* google_protobuf_compiler_CodeGeneratorResponse_File_serialize_ex(const google_protobuf_compiler_CodeGeneratorResponse_File* msg, int options, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, google__protobuf__compiler__CodeGeneratorResponse__File_msg_init(), options, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), google__protobuf__compiler__CodeGeneratorResponse__File_msg_init(), options, arena, &ptr, len); return ptr; } UPB_INLINE void google_protobuf_compiler_CodeGeneratorResponse_File_clear_name(google_protobuf_compiler_CodeGeneratorResponse_File* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorResponse__File_msg_init(), 1); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_compiler_CodeGeneratorResponse_File_name(const google_protobuf_compiler_CodeGeneratorResponse_File* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorResponse__File_msg_init(), 1); - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_compiler_CodeGeneratorResponse_File_has_name(const google_protobuf_compiler_CodeGeneratorResponse_File* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorResponse__File_msg_init(), 1); - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_compiler_CodeGeneratorResponse_File_clear_insertion_point(google_protobuf_compiler_CodeGeneratorResponse_File* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorResponse__File_msg_init(), 2); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_compiler_CodeGeneratorResponse_File_insertion_point(const google_protobuf_compiler_CodeGeneratorResponse_File* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorResponse__File_msg_init(), 2); - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_compiler_CodeGeneratorResponse_File_has_insertion_point(const google_protobuf_compiler_CodeGeneratorResponse_File* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorResponse__File_msg_init(), 2); - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_compiler_CodeGeneratorResponse_File_clear_content(google_protobuf_compiler_CodeGeneratorResponse_File* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorResponse__File_msg_init(), 15); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_compiler_CodeGeneratorResponse_File_content(const google_protobuf_compiler_CodeGeneratorResponse_File* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorResponse__File_msg_init(), 15); - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_compiler_CodeGeneratorResponse_File_has_content(const google_protobuf_compiler_CodeGeneratorResponse_File* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorResponse__File_msg_init(), 15); - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_compiler_CodeGeneratorResponse_File_clear_generated_code_info(google_protobuf_compiler_CodeGeneratorResponse_File* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorResponse__File_msg_init(), 16); - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const struct google_protobuf_GeneratedCodeInfo* google_protobuf_compiler_CodeGeneratorResponse_File_generated_code_info(const google_protobuf_compiler_CodeGeneratorResponse_File* msg) { const struct google_protobuf_GeneratedCodeInfo* default_val = NULL; const struct google_protobuf_GeneratedCodeInfo* ret; const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorResponse__File_msg_init(), 16); - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_compiler_CodeGeneratorResponse_File_has_generated_code_info(const google_protobuf_compiler_CodeGeneratorResponse_File* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorResponse__File_msg_init(), 16); - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_compiler_CodeGeneratorResponse_File_set_name(google_protobuf_compiler_CodeGeneratorResponse_File *msg, upb_StringView value) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorResponse__File_msg_init(), 1); - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_compiler_CodeGeneratorResponse_File_set_insertion_point(google_protobuf_compiler_CodeGeneratorResponse_File *msg, upb_StringView value) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorResponse__File_msg_init(), 2); - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_compiler_CodeGeneratorResponse_File_set_content(google_protobuf_compiler_CodeGeneratorResponse_File *msg, upb_StringView value) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorResponse__File_msg_init(), 15); - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_compiler_CodeGeneratorResponse_File_set_generated_code_info(google_protobuf_compiler_CodeGeneratorResponse_File *msg, struct google_protobuf_GeneratedCodeInfo* value) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorResponse__File_msg_init(), 16); - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE struct google_protobuf_GeneratedCodeInfo* google_protobuf_compiler_CodeGeneratorResponse_File_mutable_generated_code_info(google_protobuf_compiler_CodeGeneratorResponse_File* msg, upb_Arena* arena) { struct google_protobuf_GeneratedCodeInfo* sub = (struct google_protobuf_GeneratedCodeInfo*)google_protobuf_compiler_CodeGeneratorResponse_File_generated_code_info(msg); diff --git a/upb_generator/upbdev.c b/upb_generator/upbdev.c index 3de46e5c2704d..ab67bf461db46 100644 --- a/upb_generator/upbdev.c +++ b/upb_generator/upbdev.c @@ -19,6 +19,7 @@ #include "google/protobuf/compiler/plugin.upb.h" #include "google/protobuf/compiler/plugin.upbdefs.h" #include "upb/base/status.h" +#include "upb/base/upcast.h" #include "upb/json/decode.h" #include "upb/json/encode.h" #include "upb/mem/arena.h" @@ -34,7 +35,8 @@ static google_protobuf_compiler_CodeGeneratorResponse* upbc_JsonDecode( upb_DefPool* s = upb_DefPool_New(); const upb_MessageDef* m = google_protobuf_compiler_CodeGeneratorResponse_getmsgdef(s); - (void)upb_JsonDecode(data, size, response, m, s, 0, arena, status); + (void)upb_JsonDecode(data, size, UPB_UPCAST(response), m, s, 0, arena, + status); if (!upb_Status_IsOk(status)) return NULL; upb_DefPool_Free(s); @@ -50,12 +52,14 @@ static upb_StringView upbc_JsonEncode(const upb_CodeGeneratorRequest* request, const upb_MessageDef* m = upb_CodeGeneratorRequest_getmsgdef(s); const int options = upb_JsonEncode_FormatEnumsAsIntegers; - out.size = upb_JsonEncode(request, m, s, options, NULL, 0, status); + out.size = + upb_JsonEncode(UPB_UPCAST(request), m, s, options, NULL, 0, status); if (!upb_Status_IsOk(status)) goto done; char* data = (char*)upb_Arena_Malloc(arena, out.size + 1); - (void)upb_JsonEncode(request, m, s, options, data, out.size + 1, status); + (void)upb_JsonEncode(UPB_UPCAST(request), m, s, options, data, out.size + 1, + status); if (!upb_Status_IsOk(status)) goto done; out.data = (const char*)data; From 4a8f21ea9458a5d214a619a54d84b6b9ef575eb6 Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Thu, 21 Dec 2023 16:23:10 +0000 Subject: [PATCH 089/255] Auto-generate files after cl/592863926 --- php/ext/google/protobuf/php-upb.c | 27 +- php/ext/google/protobuf/php-upb.h | 2354 +++++++++++--------- ruby/ext/google/protobuf_c/ruby-upb.c | 27 +- ruby/ext/google/protobuf_c/ruby-upb.h | 2354 +++++++++++--------- upb/cmake/google/protobuf/descriptor.upb.h | 2323 ++++++++++--------- 5 files changed, 3919 insertions(+), 3166 deletions(-) diff --git a/php/ext/google/protobuf/php-upb.c b/php/ext/google/protobuf/php-upb.c index 4a269cc05df36..6c8d4fc265065 100644 --- a/php/ext/google/protobuf/php-upb.c +++ b/php/ext/google/protobuf/php-upb.c @@ -10170,7 +10170,8 @@ static void _upb_FieldDef_Create(upb_DefBuilder* ctx, const char* prefix, bool implicit = false; if (syntax != kUpb_Syntax_Editions) { - upb_Message_Clear(ctx->legacy_features, UPB_DESC_MINITABLE(FeatureSet)); + upb_Message_Clear(UPB_UPCAST(ctx->legacy_features), + UPB_DESC_MINITABLE(FeatureSet)); if (_upb_FieldDef_InferLegacyFeatures(ctx, f, field_proto, f->opts, syntax, ctx->legacy_features)) { implicit = true; @@ -11323,8 +11324,8 @@ bool _upb_DefBuilder_GetOrCreateFeatureSet(upb_DefBuilder* ctx, return false; } - *set = - upb_Message_DeepClone(parent, UPB_DESC_MINITABLE(FeatureSet), ctx->arena); + *set = (UPB_DESC(FeatureSet*))upb_Message_DeepClone( + UPB_UPCAST(parent), UPB_DESC_MINITABLE(FeatureSet), ctx->arena); if (!*set) _upb_DefBuilder_OomErr(ctx); v = upb_value_ptr(*set); @@ -11361,7 +11362,7 @@ const UPB_DESC(FeatureSet*) } upb_DecodeStatus dec_status = - upb_Decode(child_bytes, child_size, resolved, + upb_Decode(child_bytes, child_size, UPB_UPCAST(resolved), UPB_DESC_MINITABLE(FeatureSet), NULL, 0, ctx->arena); if (dec_status != kUpb_DecodeStatus_Ok) _upb_DefBuilder_OomErr(ctx); @@ -13400,18 +13401,18 @@ static const char* _upb_Decoder_DecodeToMap(upb_Decoder* d, const char* ptr, ent.data.v.val = upb_value_uintptr(msg); } - ptr = - _upb_Decoder_DecodeSubMessage(d, ptr, &ent.data, subs, field, val->size); + ptr = _upb_Decoder_DecodeSubMessage(d, ptr, (upb_Message*)&ent.data, subs, + field, val->size); // check if ent had any unknown fields size_t size; - upb_Message_GetUnknown(&ent.data, &size); + upb_Message_GetUnknown((upb_Message*)&ent.data, &size); if (size != 0) { char* buf; size_t size; uint32_t tag = ((uint32_t)field->UPB_PRIVATE(number) << 3) | kUpb_WireType_Delimited; upb_EncodeStatus status = - upb_Encode(&ent.data, entry, 0, &d->arena, &buf, &size); + upb_Encode((upb_Message*)&ent.data, entry, 0, &d->arena, &buf, &size); if (status != kUpb_EncodeStatus_Ok) { _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_OutOfMemory); } @@ -13913,7 +13914,7 @@ static const char* _upb_Decoder_DecodeKnownField( _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_OutOfMemory); } d->unknown_msg = msg; - msg = &ext->data; + msg = (upb_Message*)&ext->data; subs = &ext->ext->UPB_PRIVATE(sub); } @@ -14104,7 +14105,7 @@ static upb_DecodeStatus upb_Decoder_Decode(upb_Decoder* const decoder, return decoder->status; } -upb_DecodeStatus upb_Decode(const char* buf, size_t size, void* msg, +upb_DecodeStatus upb_Decode(const char* buf, size_t size, upb_Message* msg, const upb_MiniTable* l, const upb_ExtensionRegistry* extreg, int options, upb_Arena* arena) { @@ -15629,7 +15630,7 @@ static void encode_ext(upb_encstate* e, const upb_Extension* ext, if (UPB_UNLIKELY(is_message_set)) { encode_msgset_item(e, ext); } else { - encode_field(e, &ext->data, &ext->ext->UPB_PRIVATE(sub), + encode_field(e, (upb_Message*)&ext->data, &ext->ext->UPB_PRIVATE(sub), &ext->ext->UPB_PRIVATE(field)); } } @@ -15697,7 +15698,7 @@ static void encode_message(upb_encstate* e, const upb_Message* msg, } static upb_EncodeStatus upb_Encoder_Encode(upb_encstate* const encoder, - const void* const msg, + const upb_Message* const msg, const upb_MiniTable* const l, char** const buf, size_t* const size) { @@ -15725,7 +15726,7 @@ static upb_EncodeStatus upb_Encoder_Encode(upb_encstate* const encoder, return encoder->status; } -upb_EncodeStatus upb_Encode(const void* msg, const upb_MiniTable* l, +upb_EncodeStatus upb_Encode(const upb_Message* msg, const upb_MiniTable* l, int options, upb_Arena* arena, char** buf, size_t* size) { upb_encstate e; diff --git a/php/ext/google/protobuf/php-upb.h b/php/ext/google/protobuf/php-upb.h index b8bd2044d90bf..d31ab2d530597 100644 --- a/php/ext/google/protobuf/php-upb.h +++ b/php/ext/google/protobuf/php-upb.h @@ -376,6 +376,27 @@ void upb_Status_VAppendErrorFormat(upb_Status* status, const char* fmt, // IWYU pragma: begin_exports +#ifndef UPB_BASE_UPCAST_H_ +#define UPB_BASE_UPCAST_H_ + +// Must be last. + +// This macro provides a way to upcast message pointers in a way that is +// somewhat more bulletproof than blindly casting a pointer. Example: +// +// typedef struct { +// upb_Message UPB_PRIVATE(base); +// } pkg_FooMessage; +// +// void f(pkg_FooMessage* msg) { +// upb_Decode(UPB_UPCAST(msg), ...); +// } + +#define UPB_UPCAST(x) (&(x)->base##_dont_copy_me__upb_internal_use_only) + + +#endif /* UPB_BASE_UPCAST_H_ */ + #ifndef UPB_MESSAGE_ACCESSORS_H_ #define UPB_MESSAGE_ACCESSORS_H_ @@ -808,7 +829,9 @@ UPB_API_INLINE void upb_Arena_ShrinkLast(upb_Arena* a, void* ptr, // This typedef is in a leaf header to resolve a circular dependency between // messages and mini tables. -typedef void upb_Message; +typedef struct upb_Message { + int unused; // Placeholder cuz Windows won't compile an empty struct. +} upb_Message; #endif /* UPB_MESSAGE_TYPES_H_ */ @@ -4167,9 +4190,9 @@ UPB_INLINE int upb_Encode_LimitDepth(uint32_t encode_options, uint32_t limit) { return upb_EncodeOptions_MaxDepth(max_depth) | (encode_options & 0xffff); } -UPB_API upb_EncodeStatus upb_Encode(const void* msg, const upb_MiniTable* l, - int options, upb_Arena* arena, char** buf, - size_t* size); +UPB_API upb_EncodeStatus upb_Encode(const upb_Message* msg, + const upb_MiniTable* l, int options, + upb_Arena* arena, char** buf, size_t* size); #ifdef __cplusplus } /* extern "C" */ @@ -4301,38 +4324,38 @@ extern const upb_MiniTableFile google_protobuf_descriptor_proto_upb_file_layout; extern "C" { #endif -typedef struct google_protobuf_FileDescriptorSet google_protobuf_FileDescriptorSet; -typedef struct google_protobuf_FileDescriptorProto google_protobuf_FileDescriptorProto; -typedef struct google_protobuf_DescriptorProto google_protobuf_DescriptorProto; -typedef struct google_protobuf_DescriptorProto_ExtensionRange google_protobuf_DescriptorProto_ExtensionRange; -typedef struct google_protobuf_DescriptorProto_ReservedRange google_protobuf_DescriptorProto_ReservedRange; -typedef struct google_protobuf_ExtensionRangeOptions google_protobuf_ExtensionRangeOptions; -typedef struct google_protobuf_ExtensionRangeOptions_Declaration google_protobuf_ExtensionRangeOptions_Declaration; -typedef struct google_protobuf_FieldDescriptorProto google_protobuf_FieldDescriptorProto; -typedef struct google_protobuf_OneofDescriptorProto google_protobuf_OneofDescriptorProto; -typedef struct google_protobuf_EnumDescriptorProto google_protobuf_EnumDescriptorProto; -typedef struct google_protobuf_EnumDescriptorProto_EnumReservedRange google_protobuf_EnumDescriptorProto_EnumReservedRange; -typedef struct google_protobuf_EnumValueDescriptorProto google_protobuf_EnumValueDescriptorProto; -typedef struct google_protobuf_ServiceDescriptorProto google_protobuf_ServiceDescriptorProto; -typedef struct google_protobuf_MethodDescriptorProto google_protobuf_MethodDescriptorProto; -typedef struct google_protobuf_FileOptions google_protobuf_FileOptions; -typedef struct google_protobuf_MessageOptions google_protobuf_MessageOptions; -typedef struct google_protobuf_FieldOptions google_protobuf_FieldOptions; -typedef struct google_protobuf_FieldOptions_EditionDefault google_protobuf_FieldOptions_EditionDefault; -typedef struct google_protobuf_OneofOptions google_protobuf_OneofOptions; -typedef struct google_protobuf_EnumOptions google_protobuf_EnumOptions; -typedef struct google_protobuf_EnumValueOptions google_protobuf_EnumValueOptions; -typedef struct google_protobuf_ServiceOptions google_protobuf_ServiceOptions; -typedef struct google_protobuf_MethodOptions google_protobuf_MethodOptions; -typedef struct google_protobuf_UninterpretedOption google_protobuf_UninterpretedOption; -typedef struct google_protobuf_UninterpretedOption_NamePart google_protobuf_UninterpretedOption_NamePart; -typedef struct google_protobuf_FeatureSet google_protobuf_FeatureSet; -typedef struct google_protobuf_FeatureSetDefaults google_protobuf_FeatureSetDefaults; -typedef struct google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault; -typedef struct google_protobuf_SourceCodeInfo google_protobuf_SourceCodeInfo; -typedef struct google_protobuf_SourceCodeInfo_Location google_protobuf_SourceCodeInfo_Location; -typedef struct google_protobuf_GeneratedCodeInfo google_protobuf_GeneratedCodeInfo; -typedef struct google_protobuf_GeneratedCodeInfo_Annotation google_protobuf_GeneratedCodeInfo_Annotation; +typedef struct google_protobuf_FileDescriptorSet { upb_Message UPB_PRIVATE(base); } google_protobuf_FileDescriptorSet; +typedef struct google_protobuf_FileDescriptorProto { upb_Message UPB_PRIVATE(base); } google_protobuf_FileDescriptorProto; +typedef struct google_protobuf_DescriptorProto { upb_Message UPB_PRIVATE(base); } google_protobuf_DescriptorProto; +typedef struct google_protobuf_DescriptorProto_ExtensionRange { upb_Message UPB_PRIVATE(base); } google_protobuf_DescriptorProto_ExtensionRange; +typedef struct google_protobuf_DescriptorProto_ReservedRange { upb_Message UPB_PRIVATE(base); } google_protobuf_DescriptorProto_ReservedRange; +typedef struct google_protobuf_ExtensionRangeOptions { upb_Message UPB_PRIVATE(base); } google_protobuf_ExtensionRangeOptions; +typedef struct google_protobuf_ExtensionRangeOptions_Declaration { upb_Message UPB_PRIVATE(base); } google_protobuf_ExtensionRangeOptions_Declaration; +typedef struct google_protobuf_FieldDescriptorProto { upb_Message UPB_PRIVATE(base); } google_protobuf_FieldDescriptorProto; +typedef struct google_protobuf_OneofDescriptorProto { upb_Message UPB_PRIVATE(base); } google_protobuf_OneofDescriptorProto; +typedef struct google_protobuf_EnumDescriptorProto { upb_Message UPB_PRIVATE(base); } google_protobuf_EnumDescriptorProto; +typedef struct google_protobuf_EnumDescriptorProto_EnumReservedRange { upb_Message UPB_PRIVATE(base); } google_protobuf_EnumDescriptorProto_EnumReservedRange; +typedef struct google_protobuf_EnumValueDescriptorProto { upb_Message UPB_PRIVATE(base); } google_protobuf_EnumValueDescriptorProto; +typedef struct google_protobuf_ServiceDescriptorProto { upb_Message UPB_PRIVATE(base); } google_protobuf_ServiceDescriptorProto; +typedef struct google_protobuf_MethodDescriptorProto { upb_Message UPB_PRIVATE(base); } google_protobuf_MethodDescriptorProto; +typedef struct google_protobuf_FileOptions { upb_Message UPB_PRIVATE(base); } google_protobuf_FileOptions; +typedef struct google_protobuf_MessageOptions { upb_Message UPB_PRIVATE(base); } google_protobuf_MessageOptions; +typedef struct google_protobuf_FieldOptions { upb_Message UPB_PRIVATE(base); } google_protobuf_FieldOptions; +typedef struct google_protobuf_FieldOptions_EditionDefault { upb_Message UPB_PRIVATE(base); } google_protobuf_FieldOptions_EditionDefault; +typedef struct google_protobuf_OneofOptions { upb_Message UPB_PRIVATE(base); } google_protobuf_OneofOptions; +typedef struct google_protobuf_EnumOptions { upb_Message UPB_PRIVATE(base); } google_protobuf_EnumOptions; +typedef struct google_protobuf_EnumValueOptions { upb_Message UPB_PRIVATE(base); } google_protobuf_EnumValueOptions; +typedef struct google_protobuf_ServiceOptions { upb_Message UPB_PRIVATE(base); } google_protobuf_ServiceOptions; +typedef struct google_protobuf_MethodOptions { upb_Message UPB_PRIVATE(base); } google_protobuf_MethodOptions; +typedef struct google_protobuf_UninterpretedOption { upb_Message UPB_PRIVATE(base); } google_protobuf_UninterpretedOption; +typedef struct google_protobuf_UninterpretedOption_NamePart { upb_Message UPB_PRIVATE(base); } google_protobuf_UninterpretedOption_NamePart; +typedef struct google_protobuf_FeatureSet { upb_Message UPB_PRIVATE(base); } google_protobuf_FeatureSet; +typedef struct google_protobuf_FeatureSetDefaults { upb_Message UPB_PRIVATE(base); } google_protobuf_FeatureSetDefaults; +typedef struct google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault { upb_Message UPB_PRIVATE(base); } google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault; +typedef struct google_protobuf_SourceCodeInfo { upb_Message UPB_PRIVATE(base); } google_protobuf_SourceCodeInfo; +typedef struct google_protobuf_SourceCodeInfo_Location { upb_Message UPB_PRIVATE(base); } google_protobuf_SourceCodeInfo_Location; +typedef struct google_protobuf_GeneratedCodeInfo { upb_Message UPB_PRIVATE(base); } google_protobuf_GeneratedCodeInfo; +typedef struct google_protobuf_GeneratedCodeInfo_Annotation { upb_Message UPB_PRIVATE(base); } google_protobuf_GeneratedCodeInfo_Annotation; typedef enum { google_protobuf_EDITION_UNKNOWN = 0, @@ -4475,7 +4498,8 @@ UPB_INLINE google_protobuf_FileDescriptorSet* google_protobuf_FileDescriptorSet_ UPB_INLINE google_protobuf_FileDescriptorSet* google_protobuf_FileDescriptorSet_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_FileDescriptorSet* ret = google_protobuf_FileDescriptorSet_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__FileDescriptorSet_msg_init, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__FileDescriptorSet_msg_init, NULL, 0, arena) != + kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -4485,30 +4509,30 @@ UPB_INLINE google_protobuf_FileDescriptorSet* google_protobuf_FileDescriptorSet_ int options, upb_Arena* arena) { google_protobuf_FileDescriptorSet* ret = google_protobuf_FileDescriptorSet_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__FileDescriptorSet_msg_init, extreg, options, arena) != - kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__FileDescriptorSet_msg_init, extreg, options, + arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_FileDescriptorSet_serialize(const google_protobuf_FileDescriptorSet* msg, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__FileDescriptorSet_msg_init, 0, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__FileDescriptorSet_msg_init, 0, arena, &ptr, len); return ptr; } UPB_INLINE char* google_protobuf_FileDescriptorSet_serialize_ex(const google_protobuf_FileDescriptorSet* msg, int options, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__FileDescriptorSet_msg_init, options, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__FileDescriptorSet_msg_init, options, arena, &ptr, len); return ptr; } UPB_INLINE void google_protobuf_FileDescriptorSet_clear_file(google_protobuf_FileDescriptorSet* msg) { const upb_MiniTableField field = {1, 0, 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_FileDescriptorProto* const* google_protobuf_FileDescriptorSet_file(const google_protobuf_FileDescriptorSet* msg, size_t* size) { const upb_MiniTableField field = {1, 0, 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_FileDescriptorProto* const*)_upb_array_constptr(arr); @@ -4519,16 +4543,16 @@ UPB_INLINE const google_protobuf_FileDescriptorProto* const* google_protobuf_Fil } UPB_INLINE const upb_Array* _google_protobuf_FileDescriptorSet_file_upb_array(const google_protobuf_FileDescriptorSet* msg, size_t* size) { const upb_MiniTableField field = {1, 0, 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } -UPB_INLINE upb_Array* _google_protobuf_FileDescriptorSet_file_mutable_upb_array(const google_protobuf_FileDescriptorSet* msg, size_t* size, upb_Arena* arena) { +UPB_INLINE upb_Array* _google_protobuf_FileDescriptorSet_file_mutable_upb_array(google_protobuf_FileDescriptorSet* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = {1, 0, 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - (upb_Message*)msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), + &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -4537,7 +4561,7 @@ UPB_INLINE upb_Array* _google_protobuf_FileDescriptorSet_file_mutable_upb_array( UPB_INLINE google_protobuf_FileDescriptorProto** google_protobuf_FileDescriptorSet_mutable_file(google_protobuf_FileDescriptorSet* msg, size_t* size) { upb_MiniTableField field = {1, 0, 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetMutableArray(msg, &field); + upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_FileDescriptorProto**)_upb_array_ptr(arr); @@ -4548,11 +4572,13 @@ UPB_INLINE google_protobuf_FileDescriptorProto** google_protobuf_FileDescriptorS } UPB_INLINE google_protobuf_FileDescriptorProto** google_protobuf_FileDescriptorSet_resize_file(google_protobuf_FileDescriptorSet* msg, size_t size, upb_Arena* arena) { upb_MiniTableField field = {1, 0, 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return (google_protobuf_FileDescriptorProto**)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); + return (google_protobuf_FileDescriptorProto**)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg), + &field, size, arena); } UPB_INLINE struct google_protobuf_FileDescriptorProto* google_protobuf_FileDescriptorSet_add_file(google_protobuf_FileDescriptorSet* msg, upb_Arena* arena) { upb_MiniTableField field = {1, 0, 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray( + UPB_UPCAST(msg), &field, arena); if (!arr || !_upb_Array_ResizeUninitialized( arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; @@ -4572,7 +4598,8 @@ UPB_INLINE google_protobuf_FileDescriptorProto* google_protobuf_FileDescriptorPr UPB_INLINE google_protobuf_FileDescriptorProto* google_protobuf_FileDescriptorProto_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_FileDescriptorProto* ret = google_protobuf_FileDescriptorProto_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__FileDescriptorProto_msg_init, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__FileDescriptorProto_msg_init, NULL, 0, arena) != + kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -4582,60 +4609,62 @@ UPB_INLINE google_protobuf_FileDescriptorProto* google_protobuf_FileDescriptorPr int options, upb_Arena* arena) { google_protobuf_FileDescriptorProto* ret = google_protobuf_FileDescriptorProto_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__FileDescriptorProto_msg_init, extreg, options, arena) != - kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__FileDescriptorProto_msg_init, extreg, options, + arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_FileDescriptorProto_serialize(const google_protobuf_FileDescriptorProto* msg, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__FileDescriptorProto_msg_init, 0, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__FileDescriptorProto_msg_init, 0, arena, &ptr, len); return ptr; } UPB_INLINE char* google_protobuf_FileDescriptorProto_serialize_ex(const google_protobuf_FileDescriptorProto* msg, int options, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__FileDescriptorProto_msg_init, options, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__FileDescriptorProto_msg_init, options, arena, &ptr, len); return ptr; } UPB_INLINE void google_protobuf_FileDescriptorProto_clear_name(google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = {1, UPB_SIZE(44, 8), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_FileDescriptorProto_name(const google_protobuf_FileDescriptorProto* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; const upb_MiniTableField field = {1, UPB_SIZE(44, 8), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FileDescriptorProto_has_name(const google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = {1, UPB_SIZE(44, 8), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileDescriptorProto_clear_package(google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = {2, UPB_SIZE(52, 24), 2, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_FileDescriptorProto_package(const google_protobuf_FileDescriptorProto* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; const upb_MiniTableField field = {2, UPB_SIZE(52, 24), 2, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FileDescriptorProto_has_package(const google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = {2, UPB_SIZE(52, 24), 2, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileDescriptorProto_clear_dependency(google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = {3, UPB_SIZE(4, 40), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView const* google_protobuf_FileDescriptorProto_dependency(const google_protobuf_FileDescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {3, UPB_SIZE(4, 40), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (upb_StringView const*)_upb_array_constptr(arr); @@ -4646,16 +4675,16 @@ UPB_INLINE upb_StringView const* google_protobuf_FileDescriptorProto_dependency( } UPB_INLINE const upb_Array* _google_protobuf_FileDescriptorProto_dependency_upb_array(const google_protobuf_FileDescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {3, UPB_SIZE(4, 40), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } -UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_dependency_mutable_upb_array(const google_protobuf_FileDescriptorProto* msg, size_t* size, upb_Arena* arena) { +UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_dependency_mutable_upb_array(google_protobuf_FileDescriptorProto* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = {3, UPB_SIZE(4, 40), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - (upb_Message*)msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), + &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -4663,11 +4692,11 @@ UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_dependency_mutable_up } UPB_INLINE void google_protobuf_FileDescriptorProto_clear_message_type(google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = {4, UPB_SIZE(8, 48), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_DescriptorProto* const* google_protobuf_FileDescriptorProto_message_type(const google_protobuf_FileDescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {4, UPB_SIZE(8, 48), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_DescriptorProto* const*)_upb_array_constptr(arr); @@ -4678,16 +4707,16 @@ UPB_INLINE const google_protobuf_DescriptorProto* const* google_protobuf_FileDes } UPB_INLINE const upb_Array* _google_protobuf_FileDescriptorProto_message_type_upb_array(const google_protobuf_FileDescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {4, UPB_SIZE(8, 48), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } -UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_message_type_mutable_upb_array(const google_protobuf_FileDescriptorProto* msg, size_t* size, upb_Arena* arena) { +UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_message_type_mutable_upb_array(google_protobuf_FileDescriptorProto* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = {4, UPB_SIZE(8, 48), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - (upb_Message*)msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), + &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -4695,11 +4724,11 @@ UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_message_type_mutable_ } UPB_INLINE void google_protobuf_FileDescriptorProto_clear_enum_type(google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = {5, UPB_SIZE(12, 56), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_EnumDescriptorProto* const* google_protobuf_FileDescriptorProto_enum_type(const google_protobuf_FileDescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {5, UPB_SIZE(12, 56), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_EnumDescriptorProto* const*)_upb_array_constptr(arr); @@ -4710,16 +4739,16 @@ UPB_INLINE const google_protobuf_EnumDescriptorProto* const* google_protobuf_Fil } UPB_INLINE const upb_Array* _google_protobuf_FileDescriptorProto_enum_type_upb_array(const google_protobuf_FileDescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {5, UPB_SIZE(12, 56), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } -UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_enum_type_mutable_upb_array(const google_protobuf_FileDescriptorProto* msg, size_t* size, upb_Arena* arena) { +UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_enum_type_mutable_upb_array(google_protobuf_FileDescriptorProto* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = {5, UPB_SIZE(12, 56), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - (upb_Message*)msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), + &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -4727,11 +4756,11 @@ UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_enum_type_mutable_upb } UPB_INLINE void google_protobuf_FileDescriptorProto_clear_service(google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = {6, UPB_SIZE(16, 64), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_ServiceDescriptorProto* const* google_protobuf_FileDescriptorProto_service(const google_protobuf_FileDescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {6, UPB_SIZE(16, 64), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_ServiceDescriptorProto* const*)_upb_array_constptr(arr); @@ -4742,16 +4771,16 @@ UPB_INLINE const google_protobuf_ServiceDescriptorProto* const* google_protobuf_ } UPB_INLINE const upb_Array* _google_protobuf_FileDescriptorProto_service_upb_array(const google_protobuf_FileDescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {6, UPB_SIZE(16, 64), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } -UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_service_mutable_upb_array(const google_protobuf_FileDescriptorProto* msg, size_t* size, upb_Arena* arena) { +UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_service_mutable_upb_array(google_protobuf_FileDescriptorProto* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = {6, UPB_SIZE(16, 64), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - (upb_Message*)msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), + &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -4759,11 +4788,11 @@ UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_service_mutable_upb_a } UPB_INLINE void google_protobuf_FileDescriptorProto_clear_extension(google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = {7, UPB_SIZE(20, 72), 0, 3, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_FieldDescriptorProto* const* google_protobuf_FileDescriptorProto_extension(const google_protobuf_FileDescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {7, UPB_SIZE(20, 72), 0, 3, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_FieldDescriptorProto* const*)_upb_array_constptr(arr); @@ -4774,16 +4803,16 @@ UPB_INLINE const google_protobuf_FieldDescriptorProto* const* google_protobuf_Fi } UPB_INLINE const upb_Array* _google_protobuf_FileDescriptorProto_extension_upb_array(const google_protobuf_FileDescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {7, UPB_SIZE(20, 72), 0, 3, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } -UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_extension_mutable_upb_array(const google_protobuf_FileDescriptorProto* msg, size_t* size, upb_Arena* arena) { +UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_extension_mutable_upb_array(google_protobuf_FileDescriptorProto* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = {7, UPB_SIZE(20, 72), 0, 3, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - (upb_Message*)msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), + &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -4791,41 +4820,43 @@ UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_extension_mutable_upb } UPB_INLINE void google_protobuf_FileDescriptorProto_clear_options(google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = {8, UPB_SIZE(24, 80), 3, 4, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_FileOptions* google_protobuf_FileDescriptorProto_options(const google_protobuf_FileDescriptorProto* msg) { const google_protobuf_FileOptions* default_val = NULL; const google_protobuf_FileOptions* ret; const upb_MiniTableField field = {8, UPB_SIZE(24, 80), 3, 4, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FileDescriptorProto_has_options(const google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = {8, UPB_SIZE(24, 80), 3, 4, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileDescriptorProto_clear_source_code_info(google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = {9, UPB_SIZE(28, 88), 4, 5, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_SourceCodeInfo* google_protobuf_FileDescriptorProto_source_code_info(const google_protobuf_FileDescriptorProto* msg) { const google_protobuf_SourceCodeInfo* default_val = NULL; const google_protobuf_SourceCodeInfo* ret; const upb_MiniTableField field = {9, UPB_SIZE(28, 88), 4, 5, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FileDescriptorProto_has_source_code_info(const google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = {9, UPB_SIZE(28, 88), 4, 5, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileDescriptorProto_clear_public_dependency(google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = {10, UPB_SIZE(32, 96), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t const* google_protobuf_FileDescriptorProto_public_dependency(const google_protobuf_FileDescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {10, UPB_SIZE(32, 96), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (int32_t const*)_upb_array_constptr(arr); @@ -4836,16 +4867,16 @@ UPB_INLINE int32_t const* google_protobuf_FileDescriptorProto_public_dependency( } UPB_INLINE const upb_Array* _google_protobuf_FileDescriptorProto_public_dependency_upb_array(const google_protobuf_FileDescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {10, UPB_SIZE(32, 96), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } -UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_public_dependency_mutable_upb_array(const google_protobuf_FileDescriptorProto* msg, size_t* size, upb_Arena* arena) { +UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_public_dependency_mutable_upb_array(google_protobuf_FileDescriptorProto* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = {10, UPB_SIZE(32, 96), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - (upb_Message*)msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), + &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -4853,11 +4884,11 @@ UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_public_dependency_mut } UPB_INLINE void google_protobuf_FileDescriptorProto_clear_weak_dependency(google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = {11, UPB_SIZE(36, 104), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t const* google_protobuf_FileDescriptorProto_weak_dependency(const google_protobuf_FileDescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {11, UPB_SIZE(36, 104), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (int32_t const*)_upb_array_constptr(arr); @@ -4868,16 +4899,16 @@ UPB_INLINE int32_t const* google_protobuf_FileDescriptorProto_weak_dependency(co } UPB_INLINE const upb_Array* _google_protobuf_FileDescriptorProto_weak_dependency_upb_array(const google_protobuf_FileDescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {11, UPB_SIZE(36, 104), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } -UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_weak_dependency_mutable_upb_array(const google_protobuf_FileDescriptorProto* msg, size_t* size, upb_Arena* arena) { +UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_weak_dependency_mutable_upb_array(google_protobuf_FileDescriptorProto* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = {11, UPB_SIZE(36, 104), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - (upb_Message*)msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), + &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -4885,46 +4916,48 @@ UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_weak_dependency_mutab } UPB_INLINE void google_protobuf_FileDescriptorProto_clear_syntax(google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = {12, UPB_SIZE(60, 112), 5, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_FileDescriptorProto_syntax(const google_protobuf_FileDescriptorProto* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; const upb_MiniTableField field = {12, UPB_SIZE(60, 112), 5, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FileDescriptorProto_has_syntax(const google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = {12, UPB_SIZE(60, 112), 5, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileDescriptorProto_clear_edition(google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = {14, UPB_SIZE(40, 4), 6, 6, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_FileDescriptorProto_edition(const google_protobuf_FileDescriptorProto* msg) { int32_t default_val = 0; int32_t ret; const upb_MiniTableField field = {14, UPB_SIZE(40, 4), 6, 6, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FileDescriptorProto_has_edition(const google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = {14, UPB_SIZE(40, 4), 6, 6, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileDescriptorProto_set_name(google_protobuf_FileDescriptorProto *msg, upb_StringView value) { const upb_MiniTableField field = {1, UPB_SIZE(44, 8), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FileDescriptorProto_set_package(google_protobuf_FileDescriptorProto *msg, upb_StringView value) { const upb_MiniTableField field = {2, UPB_SIZE(52, 24), 2, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE upb_StringView* google_protobuf_FileDescriptorProto_mutable_dependency(google_protobuf_FileDescriptorProto* msg, size_t* size) { upb_MiniTableField field = {3, UPB_SIZE(4, 40), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetMutableArray(msg, &field); + upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (upb_StringView*)_upb_array_ptr(arr); @@ -4935,11 +4968,13 @@ UPB_INLINE upb_StringView* google_protobuf_FileDescriptorProto_mutable_dependenc } UPB_INLINE upb_StringView* google_protobuf_FileDescriptorProto_resize_dependency(google_protobuf_FileDescriptorProto* msg, size_t size, upb_Arena* arena) { upb_MiniTableField field = {3, UPB_SIZE(4, 40), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return (upb_StringView*)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); + return (upb_StringView*)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg), + &field, size, arena); } UPB_INLINE bool google_protobuf_FileDescriptorProto_add_dependency(google_protobuf_FileDescriptorProto* msg, upb_StringView val, upb_Arena* arena) { upb_MiniTableField field = {3, UPB_SIZE(4, 40), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray( + UPB_UPCAST(msg), &field, arena); if (!arr || !_upb_Array_ResizeUninitialized( arr, arr->UPB_PRIVATE(size) + 1, arena)) { return false; @@ -4950,7 +4985,7 @@ UPB_INLINE bool google_protobuf_FileDescriptorProto_add_dependency(google_protob } UPB_INLINE google_protobuf_DescriptorProto** google_protobuf_FileDescriptorProto_mutable_message_type(google_protobuf_FileDescriptorProto* msg, size_t* size) { upb_MiniTableField field = {4, UPB_SIZE(8, 48), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetMutableArray(msg, &field); + upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_DescriptorProto**)_upb_array_ptr(arr); @@ -4961,11 +4996,13 @@ UPB_INLINE google_protobuf_DescriptorProto** google_protobuf_FileDescriptorProto } UPB_INLINE google_protobuf_DescriptorProto** google_protobuf_FileDescriptorProto_resize_message_type(google_protobuf_FileDescriptorProto* msg, size_t size, upb_Arena* arena) { upb_MiniTableField field = {4, UPB_SIZE(8, 48), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return (google_protobuf_DescriptorProto**)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); + return (google_protobuf_DescriptorProto**)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg), + &field, size, arena); } UPB_INLINE struct google_protobuf_DescriptorProto* google_protobuf_FileDescriptorProto_add_message_type(google_protobuf_FileDescriptorProto* msg, upb_Arena* arena) { upb_MiniTableField field = {4, UPB_SIZE(8, 48), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray( + UPB_UPCAST(msg), &field, arena); if (!arr || !_upb_Array_ResizeUninitialized( arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; @@ -4978,7 +5015,7 @@ UPB_INLINE struct google_protobuf_DescriptorProto* google_protobuf_FileDescripto } UPB_INLINE google_protobuf_EnumDescriptorProto** google_protobuf_FileDescriptorProto_mutable_enum_type(google_protobuf_FileDescriptorProto* msg, size_t* size) { upb_MiniTableField field = {5, UPB_SIZE(12, 56), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetMutableArray(msg, &field); + upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_EnumDescriptorProto**)_upb_array_ptr(arr); @@ -4989,11 +5026,13 @@ UPB_INLINE google_protobuf_EnumDescriptorProto** google_protobuf_FileDescriptorP } UPB_INLINE google_protobuf_EnumDescriptorProto** google_protobuf_FileDescriptorProto_resize_enum_type(google_protobuf_FileDescriptorProto* msg, size_t size, upb_Arena* arena) { upb_MiniTableField field = {5, UPB_SIZE(12, 56), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return (google_protobuf_EnumDescriptorProto**)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); + return (google_protobuf_EnumDescriptorProto**)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg), + &field, size, arena); } UPB_INLINE struct google_protobuf_EnumDescriptorProto* google_protobuf_FileDescriptorProto_add_enum_type(google_protobuf_FileDescriptorProto* msg, upb_Arena* arena) { upb_MiniTableField field = {5, UPB_SIZE(12, 56), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray( + UPB_UPCAST(msg), &field, arena); if (!arr || !_upb_Array_ResizeUninitialized( arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; @@ -5006,7 +5045,7 @@ UPB_INLINE struct google_protobuf_EnumDescriptorProto* google_protobuf_FileDescr } UPB_INLINE google_protobuf_ServiceDescriptorProto** google_protobuf_FileDescriptorProto_mutable_service(google_protobuf_FileDescriptorProto* msg, size_t* size) { upb_MiniTableField field = {6, UPB_SIZE(16, 64), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetMutableArray(msg, &field); + upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_ServiceDescriptorProto**)_upb_array_ptr(arr); @@ -5017,11 +5056,13 @@ UPB_INLINE google_protobuf_ServiceDescriptorProto** google_protobuf_FileDescript } UPB_INLINE google_protobuf_ServiceDescriptorProto** google_protobuf_FileDescriptorProto_resize_service(google_protobuf_FileDescriptorProto* msg, size_t size, upb_Arena* arena) { upb_MiniTableField field = {6, UPB_SIZE(16, 64), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return (google_protobuf_ServiceDescriptorProto**)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); + return (google_protobuf_ServiceDescriptorProto**)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg), + &field, size, arena); } UPB_INLINE struct google_protobuf_ServiceDescriptorProto* google_protobuf_FileDescriptorProto_add_service(google_protobuf_FileDescriptorProto* msg, upb_Arena* arena) { upb_MiniTableField field = {6, UPB_SIZE(16, 64), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray( + UPB_UPCAST(msg), &field, arena); if (!arr || !_upb_Array_ResizeUninitialized( arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; @@ -5034,7 +5075,7 @@ UPB_INLINE struct google_protobuf_ServiceDescriptorProto* google_protobuf_FileDe } UPB_INLINE google_protobuf_FieldDescriptorProto** google_protobuf_FileDescriptorProto_mutable_extension(google_protobuf_FileDescriptorProto* msg, size_t* size) { upb_MiniTableField field = {7, UPB_SIZE(20, 72), 0, 3, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetMutableArray(msg, &field); + upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_FieldDescriptorProto**)_upb_array_ptr(arr); @@ -5045,11 +5086,13 @@ UPB_INLINE google_protobuf_FieldDescriptorProto** google_protobuf_FileDescriptor } UPB_INLINE google_protobuf_FieldDescriptorProto** google_protobuf_FileDescriptorProto_resize_extension(google_protobuf_FileDescriptorProto* msg, size_t size, upb_Arena* arena) { upb_MiniTableField field = {7, UPB_SIZE(20, 72), 0, 3, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return (google_protobuf_FieldDescriptorProto**)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); + return (google_protobuf_FieldDescriptorProto**)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg), + &field, size, arena); } UPB_INLINE struct google_protobuf_FieldDescriptorProto* google_protobuf_FileDescriptorProto_add_extension(google_protobuf_FileDescriptorProto* msg, upb_Arena* arena) { upb_MiniTableField field = {7, UPB_SIZE(20, 72), 0, 3, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray( + UPB_UPCAST(msg), &field, arena); if (!arr || !_upb_Array_ResizeUninitialized( arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; @@ -5062,7 +5105,7 @@ UPB_INLINE struct google_protobuf_FieldDescriptorProto* google_protobuf_FileDesc } UPB_INLINE void google_protobuf_FileDescriptorProto_set_options(google_protobuf_FileDescriptorProto *msg, google_protobuf_FileOptions* value) { const upb_MiniTableField field = {8, UPB_SIZE(24, 80), 3, 4, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE struct google_protobuf_FileOptions* google_protobuf_FileDescriptorProto_mutable_options(google_protobuf_FileDescriptorProto* msg, upb_Arena* arena) { struct google_protobuf_FileOptions* sub = (struct google_protobuf_FileOptions*)google_protobuf_FileDescriptorProto_options(msg); @@ -5074,7 +5117,7 @@ UPB_INLINE struct google_protobuf_FileOptions* google_protobuf_FileDescriptorPro } UPB_INLINE void google_protobuf_FileDescriptorProto_set_source_code_info(google_protobuf_FileDescriptorProto *msg, google_protobuf_SourceCodeInfo* value) { const upb_MiniTableField field = {9, UPB_SIZE(28, 88), 4, 5, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE struct google_protobuf_SourceCodeInfo* google_protobuf_FileDescriptorProto_mutable_source_code_info(google_protobuf_FileDescriptorProto* msg, upb_Arena* arena) { struct google_protobuf_SourceCodeInfo* sub = (struct google_protobuf_SourceCodeInfo*)google_protobuf_FileDescriptorProto_source_code_info(msg); @@ -5086,7 +5129,7 @@ UPB_INLINE struct google_protobuf_SourceCodeInfo* google_protobuf_FileDescriptor } UPB_INLINE int32_t* google_protobuf_FileDescriptorProto_mutable_public_dependency(google_protobuf_FileDescriptorProto* msg, size_t* size) { upb_MiniTableField field = {10, UPB_SIZE(32, 96), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetMutableArray(msg, &field); + upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (int32_t*)_upb_array_ptr(arr); @@ -5097,11 +5140,13 @@ UPB_INLINE int32_t* google_protobuf_FileDescriptorProto_mutable_public_dependenc } UPB_INLINE int32_t* google_protobuf_FileDescriptorProto_resize_public_dependency(google_protobuf_FileDescriptorProto* msg, size_t size, upb_Arena* arena) { upb_MiniTableField field = {10, UPB_SIZE(32, 96), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return (int32_t*)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); + return (int32_t*)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg), + &field, size, arena); } UPB_INLINE bool google_protobuf_FileDescriptorProto_add_public_dependency(google_protobuf_FileDescriptorProto* msg, int32_t val, upb_Arena* arena) { upb_MiniTableField field = {10, UPB_SIZE(32, 96), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray( + UPB_UPCAST(msg), &field, arena); if (!arr || !_upb_Array_ResizeUninitialized( arr, arr->UPB_PRIVATE(size) + 1, arena)) { return false; @@ -5112,7 +5157,7 @@ UPB_INLINE bool google_protobuf_FileDescriptorProto_add_public_dependency(google } UPB_INLINE int32_t* google_protobuf_FileDescriptorProto_mutable_weak_dependency(google_protobuf_FileDescriptorProto* msg, size_t* size) { upb_MiniTableField field = {11, UPB_SIZE(36, 104), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetMutableArray(msg, &field); + upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (int32_t*)_upb_array_ptr(arr); @@ -5123,11 +5168,13 @@ UPB_INLINE int32_t* google_protobuf_FileDescriptorProto_mutable_weak_dependency( } UPB_INLINE int32_t* google_protobuf_FileDescriptorProto_resize_weak_dependency(google_protobuf_FileDescriptorProto* msg, size_t size, upb_Arena* arena) { upb_MiniTableField field = {11, UPB_SIZE(36, 104), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return (int32_t*)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); + return (int32_t*)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg), + &field, size, arena); } UPB_INLINE bool google_protobuf_FileDescriptorProto_add_weak_dependency(google_protobuf_FileDescriptorProto* msg, int32_t val, upb_Arena* arena) { upb_MiniTableField field = {11, UPB_SIZE(36, 104), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray( + UPB_UPCAST(msg), &field, arena); if (!arr || !_upb_Array_ResizeUninitialized( arr, arr->UPB_PRIVATE(size) + 1, arena)) { return false; @@ -5138,11 +5185,11 @@ UPB_INLINE bool google_protobuf_FileDescriptorProto_add_weak_dependency(google_p } UPB_INLINE void google_protobuf_FileDescriptorProto_set_syntax(google_protobuf_FileDescriptorProto *msg, upb_StringView value) { const upb_MiniTableField field = {12, UPB_SIZE(60, 112), 5, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FileDescriptorProto_set_edition(google_protobuf_FileDescriptorProto *msg, int32_t value) { const upb_MiniTableField field = {14, UPB_SIZE(40, 4), 6, 6, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } /* google.protobuf.DescriptorProto */ @@ -5153,7 +5200,8 @@ UPB_INLINE google_protobuf_DescriptorProto* google_protobuf_DescriptorProto_new( UPB_INLINE google_protobuf_DescriptorProto* google_protobuf_DescriptorProto_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_DescriptorProto* ret = google_protobuf_DescriptorProto_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__DescriptorProto_msg_init, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__DescriptorProto_msg_init, NULL, 0, arena) != + kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -5163,45 +5211,46 @@ UPB_INLINE google_protobuf_DescriptorProto* google_protobuf_DescriptorProto_pars int options, upb_Arena* arena) { google_protobuf_DescriptorProto* ret = google_protobuf_DescriptorProto_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__DescriptorProto_msg_init, extreg, options, arena) != - kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__DescriptorProto_msg_init, extreg, options, + arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_DescriptorProto_serialize(const google_protobuf_DescriptorProto* msg, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__DescriptorProto_msg_init, 0, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__DescriptorProto_msg_init, 0, arena, &ptr, len); return ptr; } UPB_INLINE char* google_protobuf_DescriptorProto_serialize_ex(const google_protobuf_DescriptorProto* msg, int options, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__DescriptorProto_msg_init, options, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__DescriptorProto_msg_init, options, arena, &ptr, len); return ptr; } UPB_INLINE void google_protobuf_DescriptorProto_clear_name(google_protobuf_DescriptorProto* msg) { const upb_MiniTableField field = {1, UPB_SIZE(40, 8), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_DescriptorProto_name(const google_protobuf_DescriptorProto* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; const upb_MiniTableField field = {1, UPB_SIZE(40, 8), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_DescriptorProto_has_name(const google_protobuf_DescriptorProto* msg) { const upb_MiniTableField field = {1, UPB_SIZE(40, 8), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_DescriptorProto_clear_field(google_protobuf_DescriptorProto* msg) { const upb_MiniTableField field = {2, UPB_SIZE(4, 24), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_FieldDescriptorProto* const* google_protobuf_DescriptorProto_field(const google_protobuf_DescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {2, UPB_SIZE(4, 24), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_FieldDescriptorProto* const*)_upb_array_constptr(arr); @@ -5212,16 +5261,16 @@ UPB_INLINE const google_protobuf_FieldDescriptorProto* const* google_protobuf_De } UPB_INLINE const upb_Array* _google_protobuf_DescriptorProto_field_upb_array(const google_protobuf_DescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {2, UPB_SIZE(4, 24), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } -UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_field_mutable_upb_array(const google_protobuf_DescriptorProto* msg, size_t* size, upb_Arena* arena) { +UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_field_mutable_upb_array(google_protobuf_DescriptorProto* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = {2, UPB_SIZE(4, 24), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - (upb_Message*)msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), + &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -5229,11 +5278,11 @@ UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_field_mutable_upb_array(c } UPB_INLINE void google_protobuf_DescriptorProto_clear_nested_type(google_protobuf_DescriptorProto* msg) { const upb_MiniTableField field = {3, UPB_SIZE(8, 32), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_DescriptorProto* const* google_protobuf_DescriptorProto_nested_type(const google_protobuf_DescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {3, UPB_SIZE(8, 32), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_DescriptorProto* const*)_upb_array_constptr(arr); @@ -5244,16 +5293,16 @@ UPB_INLINE const google_protobuf_DescriptorProto* const* google_protobuf_Descrip } UPB_INLINE const upb_Array* _google_protobuf_DescriptorProto_nested_type_upb_array(const google_protobuf_DescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {3, UPB_SIZE(8, 32), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } -UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_nested_type_mutable_upb_array(const google_protobuf_DescriptorProto* msg, size_t* size, upb_Arena* arena) { +UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_nested_type_mutable_upb_array(google_protobuf_DescriptorProto* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = {3, UPB_SIZE(8, 32), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - (upb_Message*)msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), + &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -5261,11 +5310,11 @@ UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_nested_type_mutable_upb_a } UPB_INLINE void google_protobuf_DescriptorProto_clear_enum_type(google_protobuf_DescriptorProto* msg) { const upb_MiniTableField field = {4, UPB_SIZE(12, 40), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_EnumDescriptorProto* const* google_protobuf_DescriptorProto_enum_type(const google_protobuf_DescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {4, UPB_SIZE(12, 40), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_EnumDescriptorProto* const*)_upb_array_constptr(arr); @@ -5276,16 +5325,16 @@ UPB_INLINE const google_protobuf_EnumDescriptorProto* const* google_protobuf_Des } UPB_INLINE const upb_Array* _google_protobuf_DescriptorProto_enum_type_upb_array(const google_protobuf_DescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {4, UPB_SIZE(12, 40), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } -UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_enum_type_mutable_upb_array(const google_protobuf_DescriptorProto* msg, size_t* size, upb_Arena* arena) { +UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_enum_type_mutable_upb_array(google_protobuf_DescriptorProto* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = {4, UPB_SIZE(12, 40), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - (upb_Message*)msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), + &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -5293,11 +5342,11 @@ UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_enum_type_mutable_upb_arr } UPB_INLINE void google_protobuf_DescriptorProto_clear_extension_range(google_protobuf_DescriptorProto* msg) { const upb_MiniTableField field = {5, UPB_SIZE(16, 48), 0, 3, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_DescriptorProto_ExtensionRange* const* google_protobuf_DescriptorProto_extension_range(const google_protobuf_DescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {5, UPB_SIZE(16, 48), 0, 3, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_DescriptorProto_ExtensionRange* const*)_upb_array_constptr(arr); @@ -5308,16 +5357,16 @@ UPB_INLINE const google_protobuf_DescriptorProto_ExtensionRange* const* google_p } UPB_INLINE const upb_Array* _google_protobuf_DescriptorProto_extension_range_upb_array(const google_protobuf_DescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {5, UPB_SIZE(16, 48), 0, 3, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } -UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_extension_range_mutable_upb_array(const google_protobuf_DescriptorProto* msg, size_t* size, upb_Arena* arena) { +UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_extension_range_mutable_upb_array(google_protobuf_DescriptorProto* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = {5, UPB_SIZE(16, 48), 0, 3, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - (upb_Message*)msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), + &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -5325,11 +5374,11 @@ UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_extension_range_mutable_u } UPB_INLINE void google_protobuf_DescriptorProto_clear_extension(google_protobuf_DescriptorProto* msg) { const upb_MiniTableField field = {6, UPB_SIZE(20, 56), 0, 4, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_FieldDescriptorProto* const* google_protobuf_DescriptorProto_extension(const google_protobuf_DescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {6, UPB_SIZE(20, 56), 0, 4, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_FieldDescriptorProto* const*)_upb_array_constptr(arr); @@ -5340,16 +5389,16 @@ UPB_INLINE const google_protobuf_FieldDescriptorProto* const* google_protobuf_De } UPB_INLINE const upb_Array* _google_protobuf_DescriptorProto_extension_upb_array(const google_protobuf_DescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {6, UPB_SIZE(20, 56), 0, 4, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } -UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_extension_mutable_upb_array(const google_protobuf_DescriptorProto* msg, size_t* size, upb_Arena* arena) { +UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_extension_mutable_upb_array(google_protobuf_DescriptorProto* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = {6, UPB_SIZE(20, 56), 0, 4, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - (upb_Message*)msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), + &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -5357,26 +5406,27 @@ UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_extension_mutable_upb_arr } UPB_INLINE void google_protobuf_DescriptorProto_clear_options(google_protobuf_DescriptorProto* msg) { const upb_MiniTableField field = {7, UPB_SIZE(24, 64), 2, 5, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_MessageOptions* google_protobuf_DescriptorProto_options(const google_protobuf_DescriptorProto* msg) { const google_protobuf_MessageOptions* default_val = NULL; const google_protobuf_MessageOptions* ret; const upb_MiniTableField field = {7, UPB_SIZE(24, 64), 2, 5, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_DescriptorProto_has_options(const google_protobuf_DescriptorProto* msg) { const upb_MiniTableField field = {7, UPB_SIZE(24, 64), 2, 5, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_DescriptorProto_clear_oneof_decl(google_protobuf_DescriptorProto* msg) { const upb_MiniTableField field = {8, UPB_SIZE(28, 72), 0, 6, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_OneofDescriptorProto* const* google_protobuf_DescriptorProto_oneof_decl(const google_protobuf_DescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {8, UPB_SIZE(28, 72), 0, 6, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_OneofDescriptorProto* const*)_upb_array_constptr(arr); @@ -5387,16 +5437,16 @@ UPB_INLINE const google_protobuf_OneofDescriptorProto* const* google_protobuf_De } UPB_INLINE const upb_Array* _google_protobuf_DescriptorProto_oneof_decl_upb_array(const google_protobuf_DescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {8, UPB_SIZE(28, 72), 0, 6, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } -UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_oneof_decl_mutable_upb_array(const google_protobuf_DescriptorProto* msg, size_t* size, upb_Arena* arena) { +UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_oneof_decl_mutable_upb_array(google_protobuf_DescriptorProto* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = {8, UPB_SIZE(28, 72), 0, 6, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - (upb_Message*)msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), + &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -5404,11 +5454,11 @@ UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_oneof_decl_mutable_upb_ar } UPB_INLINE void google_protobuf_DescriptorProto_clear_reserved_range(google_protobuf_DescriptorProto* msg) { const upb_MiniTableField field = {9, UPB_SIZE(32, 80), 0, 7, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_DescriptorProto_ReservedRange* const* google_protobuf_DescriptorProto_reserved_range(const google_protobuf_DescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {9, UPB_SIZE(32, 80), 0, 7, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_DescriptorProto_ReservedRange* const*)_upb_array_constptr(arr); @@ -5419,16 +5469,16 @@ UPB_INLINE const google_protobuf_DescriptorProto_ReservedRange* const* google_pr } UPB_INLINE const upb_Array* _google_protobuf_DescriptorProto_reserved_range_upb_array(const google_protobuf_DescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {9, UPB_SIZE(32, 80), 0, 7, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } -UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_reserved_range_mutable_upb_array(const google_protobuf_DescriptorProto* msg, size_t* size, upb_Arena* arena) { +UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_reserved_range_mutable_upb_array(google_protobuf_DescriptorProto* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = {9, UPB_SIZE(32, 80), 0, 7, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - (upb_Message*)msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), + &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -5436,11 +5486,11 @@ UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_reserved_range_mutable_up } UPB_INLINE void google_protobuf_DescriptorProto_clear_reserved_name(google_protobuf_DescriptorProto* msg) { const upb_MiniTableField field = {10, UPB_SIZE(36, 88), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView const* google_protobuf_DescriptorProto_reserved_name(const google_protobuf_DescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {10, UPB_SIZE(36, 88), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (upb_StringView const*)_upb_array_constptr(arr); @@ -5451,16 +5501,16 @@ UPB_INLINE upb_StringView const* google_protobuf_DescriptorProto_reserved_name(c } UPB_INLINE const upb_Array* _google_protobuf_DescriptorProto_reserved_name_upb_array(const google_protobuf_DescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {10, UPB_SIZE(36, 88), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } -UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_reserved_name_mutable_upb_array(const google_protobuf_DescriptorProto* msg, size_t* size, upb_Arena* arena) { +UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_reserved_name_mutable_upb_array(google_protobuf_DescriptorProto* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = {10, UPB_SIZE(36, 88), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - (upb_Message*)msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), + &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -5469,11 +5519,11 @@ UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_reserved_name_mutable_upb UPB_INLINE void google_protobuf_DescriptorProto_set_name(google_protobuf_DescriptorProto *msg, upb_StringView value) { const upb_MiniTableField field = {1, UPB_SIZE(40, 8), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE google_protobuf_FieldDescriptorProto** google_protobuf_DescriptorProto_mutable_field(google_protobuf_DescriptorProto* msg, size_t* size) { upb_MiniTableField field = {2, UPB_SIZE(4, 24), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetMutableArray(msg, &field); + upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_FieldDescriptorProto**)_upb_array_ptr(arr); @@ -5484,11 +5534,13 @@ UPB_INLINE google_protobuf_FieldDescriptorProto** google_protobuf_DescriptorProt } UPB_INLINE google_protobuf_FieldDescriptorProto** google_protobuf_DescriptorProto_resize_field(google_protobuf_DescriptorProto* msg, size_t size, upb_Arena* arena) { upb_MiniTableField field = {2, UPB_SIZE(4, 24), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return (google_protobuf_FieldDescriptorProto**)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); + return (google_protobuf_FieldDescriptorProto**)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg), + &field, size, arena); } UPB_INLINE struct google_protobuf_FieldDescriptorProto* google_protobuf_DescriptorProto_add_field(google_protobuf_DescriptorProto* msg, upb_Arena* arena) { upb_MiniTableField field = {2, UPB_SIZE(4, 24), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray( + UPB_UPCAST(msg), &field, arena); if (!arr || !_upb_Array_ResizeUninitialized( arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; @@ -5501,7 +5553,7 @@ UPB_INLINE struct google_protobuf_FieldDescriptorProto* google_protobuf_Descript } UPB_INLINE google_protobuf_DescriptorProto** google_protobuf_DescriptorProto_mutable_nested_type(google_protobuf_DescriptorProto* msg, size_t* size) { upb_MiniTableField field = {3, UPB_SIZE(8, 32), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetMutableArray(msg, &field); + upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_DescriptorProto**)_upb_array_ptr(arr); @@ -5512,11 +5564,13 @@ UPB_INLINE google_protobuf_DescriptorProto** google_protobuf_DescriptorProto_mut } UPB_INLINE google_protobuf_DescriptorProto** google_protobuf_DescriptorProto_resize_nested_type(google_protobuf_DescriptorProto* msg, size_t size, upb_Arena* arena) { upb_MiniTableField field = {3, UPB_SIZE(8, 32), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return (google_protobuf_DescriptorProto**)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); + return (google_protobuf_DescriptorProto**)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg), + &field, size, arena); } UPB_INLINE struct google_protobuf_DescriptorProto* google_protobuf_DescriptorProto_add_nested_type(google_protobuf_DescriptorProto* msg, upb_Arena* arena) { upb_MiniTableField field = {3, UPB_SIZE(8, 32), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray( + UPB_UPCAST(msg), &field, arena); if (!arr || !_upb_Array_ResizeUninitialized( arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; @@ -5529,7 +5583,7 @@ UPB_INLINE struct google_protobuf_DescriptorProto* google_protobuf_DescriptorPro } UPB_INLINE google_protobuf_EnumDescriptorProto** google_protobuf_DescriptorProto_mutable_enum_type(google_protobuf_DescriptorProto* msg, size_t* size) { upb_MiniTableField field = {4, UPB_SIZE(12, 40), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetMutableArray(msg, &field); + upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_EnumDescriptorProto**)_upb_array_ptr(arr); @@ -5540,11 +5594,13 @@ UPB_INLINE google_protobuf_EnumDescriptorProto** google_protobuf_DescriptorProto } UPB_INLINE google_protobuf_EnumDescriptorProto** google_protobuf_DescriptorProto_resize_enum_type(google_protobuf_DescriptorProto* msg, size_t size, upb_Arena* arena) { upb_MiniTableField field = {4, UPB_SIZE(12, 40), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return (google_protobuf_EnumDescriptorProto**)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); + return (google_protobuf_EnumDescriptorProto**)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg), + &field, size, arena); } UPB_INLINE struct google_protobuf_EnumDescriptorProto* google_protobuf_DescriptorProto_add_enum_type(google_protobuf_DescriptorProto* msg, upb_Arena* arena) { upb_MiniTableField field = {4, UPB_SIZE(12, 40), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray( + UPB_UPCAST(msg), &field, arena); if (!arr || !_upb_Array_ResizeUninitialized( arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; @@ -5557,7 +5613,7 @@ UPB_INLINE struct google_protobuf_EnumDescriptorProto* google_protobuf_Descripto } UPB_INLINE google_protobuf_DescriptorProto_ExtensionRange** google_protobuf_DescriptorProto_mutable_extension_range(google_protobuf_DescriptorProto* msg, size_t* size) { upb_MiniTableField field = {5, UPB_SIZE(16, 48), 0, 3, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetMutableArray(msg, &field); + upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_DescriptorProto_ExtensionRange**)_upb_array_ptr(arr); @@ -5568,11 +5624,13 @@ UPB_INLINE google_protobuf_DescriptorProto_ExtensionRange** google_protobuf_Desc } UPB_INLINE google_protobuf_DescriptorProto_ExtensionRange** google_protobuf_DescriptorProto_resize_extension_range(google_protobuf_DescriptorProto* msg, size_t size, upb_Arena* arena) { upb_MiniTableField field = {5, UPB_SIZE(16, 48), 0, 3, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return (google_protobuf_DescriptorProto_ExtensionRange**)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); + return (google_protobuf_DescriptorProto_ExtensionRange**)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg), + &field, size, arena); } UPB_INLINE struct google_protobuf_DescriptorProto_ExtensionRange* google_protobuf_DescriptorProto_add_extension_range(google_protobuf_DescriptorProto* msg, upb_Arena* arena) { upb_MiniTableField field = {5, UPB_SIZE(16, 48), 0, 3, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray( + UPB_UPCAST(msg), &field, arena); if (!arr || !_upb_Array_ResizeUninitialized( arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; @@ -5585,7 +5643,7 @@ UPB_INLINE struct google_protobuf_DescriptorProto_ExtensionRange* google_protobu } UPB_INLINE google_protobuf_FieldDescriptorProto** google_protobuf_DescriptorProto_mutable_extension(google_protobuf_DescriptorProto* msg, size_t* size) { upb_MiniTableField field = {6, UPB_SIZE(20, 56), 0, 4, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetMutableArray(msg, &field); + upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_FieldDescriptorProto**)_upb_array_ptr(arr); @@ -5596,11 +5654,13 @@ UPB_INLINE google_protobuf_FieldDescriptorProto** google_protobuf_DescriptorProt } UPB_INLINE google_protobuf_FieldDescriptorProto** google_protobuf_DescriptorProto_resize_extension(google_protobuf_DescriptorProto* msg, size_t size, upb_Arena* arena) { upb_MiniTableField field = {6, UPB_SIZE(20, 56), 0, 4, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return (google_protobuf_FieldDescriptorProto**)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); + return (google_protobuf_FieldDescriptorProto**)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg), + &field, size, arena); } UPB_INLINE struct google_protobuf_FieldDescriptorProto* google_protobuf_DescriptorProto_add_extension(google_protobuf_DescriptorProto* msg, upb_Arena* arena) { upb_MiniTableField field = {6, UPB_SIZE(20, 56), 0, 4, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray( + UPB_UPCAST(msg), &field, arena); if (!arr || !_upb_Array_ResizeUninitialized( arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; @@ -5613,7 +5673,7 @@ UPB_INLINE struct google_protobuf_FieldDescriptorProto* google_protobuf_Descript } UPB_INLINE void google_protobuf_DescriptorProto_set_options(google_protobuf_DescriptorProto *msg, google_protobuf_MessageOptions* value) { const upb_MiniTableField field = {7, UPB_SIZE(24, 64), 2, 5, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE struct google_protobuf_MessageOptions* google_protobuf_DescriptorProto_mutable_options(google_protobuf_DescriptorProto* msg, upb_Arena* arena) { struct google_protobuf_MessageOptions* sub = (struct google_protobuf_MessageOptions*)google_protobuf_DescriptorProto_options(msg); @@ -5625,7 +5685,7 @@ UPB_INLINE struct google_protobuf_MessageOptions* google_protobuf_DescriptorProt } UPB_INLINE google_protobuf_OneofDescriptorProto** google_protobuf_DescriptorProto_mutable_oneof_decl(google_protobuf_DescriptorProto* msg, size_t* size) { upb_MiniTableField field = {8, UPB_SIZE(28, 72), 0, 6, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetMutableArray(msg, &field); + upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_OneofDescriptorProto**)_upb_array_ptr(arr); @@ -5636,11 +5696,13 @@ UPB_INLINE google_protobuf_OneofDescriptorProto** google_protobuf_DescriptorProt } UPB_INLINE google_protobuf_OneofDescriptorProto** google_protobuf_DescriptorProto_resize_oneof_decl(google_protobuf_DescriptorProto* msg, size_t size, upb_Arena* arena) { upb_MiniTableField field = {8, UPB_SIZE(28, 72), 0, 6, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return (google_protobuf_OneofDescriptorProto**)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); + return (google_protobuf_OneofDescriptorProto**)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg), + &field, size, arena); } UPB_INLINE struct google_protobuf_OneofDescriptorProto* google_protobuf_DescriptorProto_add_oneof_decl(google_protobuf_DescriptorProto* msg, upb_Arena* arena) { upb_MiniTableField field = {8, UPB_SIZE(28, 72), 0, 6, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray( + UPB_UPCAST(msg), &field, arena); if (!arr || !_upb_Array_ResizeUninitialized( arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; @@ -5653,7 +5715,7 @@ UPB_INLINE struct google_protobuf_OneofDescriptorProto* google_protobuf_Descript } UPB_INLINE google_protobuf_DescriptorProto_ReservedRange** google_protobuf_DescriptorProto_mutable_reserved_range(google_protobuf_DescriptorProto* msg, size_t* size) { upb_MiniTableField field = {9, UPB_SIZE(32, 80), 0, 7, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetMutableArray(msg, &field); + upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_DescriptorProto_ReservedRange**)_upb_array_ptr(arr); @@ -5664,11 +5726,13 @@ UPB_INLINE google_protobuf_DescriptorProto_ReservedRange** google_protobuf_Descr } UPB_INLINE google_protobuf_DescriptorProto_ReservedRange** google_protobuf_DescriptorProto_resize_reserved_range(google_protobuf_DescriptorProto* msg, size_t size, upb_Arena* arena) { upb_MiniTableField field = {9, UPB_SIZE(32, 80), 0, 7, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return (google_protobuf_DescriptorProto_ReservedRange**)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); + return (google_protobuf_DescriptorProto_ReservedRange**)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg), + &field, size, arena); } UPB_INLINE struct google_protobuf_DescriptorProto_ReservedRange* google_protobuf_DescriptorProto_add_reserved_range(google_protobuf_DescriptorProto* msg, upb_Arena* arena) { upb_MiniTableField field = {9, UPB_SIZE(32, 80), 0, 7, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray( + UPB_UPCAST(msg), &field, arena); if (!arr || !_upb_Array_ResizeUninitialized( arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; @@ -5681,7 +5745,7 @@ UPB_INLINE struct google_protobuf_DescriptorProto_ReservedRange* google_protobuf } UPB_INLINE upb_StringView* google_protobuf_DescriptorProto_mutable_reserved_name(google_protobuf_DescriptorProto* msg, size_t* size) { upb_MiniTableField field = {10, UPB_SIZE(36, 88), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetMutableArray(msg, &field); + upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (upb_StringView*)_upb_array_ptr(arr); @@ -5692,11 +5756,13 @@ UPB_INLINE upb_StringView* google_protobuf_DescriptorProto_mutable_reserved_name } UPB_INLINE upb_StringView* google_protobuf_DescriptorProto_resize_reserved_name(google_protobuf_DescriptorProto* msg, size_t size, upb_Arena* arena) { upb_MiniTableField field = {10, UPB_SIZE(36, 88), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return (upb_StringView*)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); + return (upb_StringView*)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg), + &field, size, arena); } UPB_INLINE bool google_protobuf_DescriptorProto_add_reserved_name(google_protobuf_DescriptorProto* msg, upb_StringView val, upb_Arena* arena) { upb_MiniTableField field = {10, UPB_SIZE(36, 88), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray( + UPB_UPCAST(msg), &field, arena); if (!arr || !_upb_Array_ResizeUninitialized( arr, arr->UPB_PRIVATE(size) + 1, arena)) { return false; @@ -5714,7 +5780,8 @@ UPB_INLINE google_protobuf_DescriptorProto_ExtensionRange* google_protobuf_Descr UPB_INLINE google_protobuf_DescriptorProto_ExtensionRange* google_protobuf_DescriptorProto_ExtensionRange_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_DescriptorProto_ExtensionRange* ret = google_protobuf_DescriptorProto_ExtensionRange_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__DescriptorProto__ExtensionRange_msg_init, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__DescriptorProto__ExtensionRange_msg_init, NULL, 0, arena) != + kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -5724,80 +5791,83 @@ UPB_INLINE google_protobuf_DescriptorProto_ExtensionRange* google_protobuf_Descr int options, upb_Arena* arena) { google_protobuf_DescriptorProto_ExtensionRange* ret = google_protobuf_DescriptorProto_ExtensionRange_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__DescriptorProto__ExtensionRange_msg_init, extreg, options, arena) != - kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__DescriptorProto__ExtensionRange_msg_init, extreg, options, + arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_DescriptorProto_ExtensionRange_serialize(const google_protobuf_DescriptorProto_ExtensionRange* msg, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__DescriptorProto__ExtensionRange_msg_init, 0, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__DescriptorProto__ExtensionRange_msg_init, 0, arena, &ptr, len); return ptr; } UPB_INLINE char* google_protobuf_DescriptorProto_ExtensionRange_serialize_ex(const google_protobuf_DescriptorProto_ExtensionRange* msg, int options, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__DescriptorProto__ExtensionRange_msg_init, options, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__DescriptorProto__ExtensionRange_msg_init, options, arena, &ptr, len); return ptr; } UPB_INLINE void google_protobuf_DescriptorProto_ExtensionRange_clear_start(google_protobuf_DescriptorProto_ExtensionRange* msg) { const upb_MiniTableField field = {1, 4, 1, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_DescriptorProto_ExtensionRange_start(const google_protobuf_DescriptorProto_ExtensionRange* msg) { int32_t default_val = (int32_t)0; int32_t ret; const upb_MiniTableField field = {1, 4, 1, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_DescriptorProto_ExtensionRange_has_start(const google_protobuf_DescriptorProto_ExtensionRange* msg) { const upb_MiniTableField field = {1, 4, 1, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_DescriptorProto_ExtensionRange_clear_end(google_protobuf_DescriptorProto_ExtensionRange* msg) { const upb_MiniTableField field = {2, 8, 2, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_DescriptorProto_ExtensionRange_end(const google_protobuf_DescriptorProto_ExtensionRange* msg) { int32_t default_val = (int32_t)0; int32_t ret; const upb_MiniTableField field = {2, 8, 2, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_DescriptorProto_ExtensionRange_has_end(const google_protobuf_DescriptorProto_ExtensionRange* msg) { const upb_MiniTableField field = {2, 8, 2, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_DescriptorProto_ExtensionRange_clear_options(google_protobuf_DescriptorProto_ExtensionRange* msg) { const upb_MiniTableField field = {3, UPB_SIZE(12, 16), 3, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_ExtensionRangeOptions* google_protobuf_DescriptorProto_ExtensionRange_options(const google_protobuf_DescriptorProto_ExtensionRange* msg) { const google_protobuf_ExtensionRangeOptions* default_val = NULL; const google_protobuf_ExtensionRangeOptions* ret; const upb_MiniTableField field = {3, UPB_SIZE(12, 16), 3, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_DescriptorProto_ExtensionRange_has_options(const google_protobuf_DescriptorProto_ExtensionRange* msg) { const upb_MiniTableField field = {3, UPB_SIZE(12, 16), 3, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_DescriptorProto_ExtensionRange_set_start(google_protobuf_DescriptorProto_ExtensionRange *msg, int32_t value) { const upb_MiniTableField field = {1, 4, 1, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_DescriptorProto_ExtensionRange_set_end(google_protobuf_DescriptorProto_ExtensionRange *msg, int32_t value) { const upb_MiniTableField field = {2, 8, 2, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_DescriptorProto_ExtensionRange_set_options(google_protobuf_DescriptorProto_ExtensionRange *msg, google_protobuf_ExtensionRangeOptions* value) { const upb_MiniTableField field = {3, UPB_SIZE(12, 16), 3, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE struct google_protobuf_ExtensionRangeOptions* google_protobuf_DescriptorProto_ExtensionRange_mutable_options(google_protobuf_DescriptorProto_ExtensionRange* msg, upb_Arena* arena) { struct google_protobuf_ExtensionRangeOptions* sub = (struct google_protobuf_ExtensionRangeOptions*)google_protobuf_DescriptorProto_ExtensionRange_options(msg); @@ -5816,7 +5886,8 @@ UPB_INLINE google_protobuf_DescriptorProto_ReservedRange* google_protobuf_Descri UPB_INLINE google_protobuf_DescriptorProto_ReservedRange* google_protobuf_DescriptorProto_ReservedRange_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_DescriptorProto_ReservedRange* ret = google_protobuf_DescriptorProto_ReservedRange_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__DescriptorProto__ReservedRange_msg_init, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__DescriptorProto__ReservedRange_msg_init, NULL, 0, arena) != + kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -5826,61 +5897,63 @@ UPB_INLINE google_protobuf_DescriptorProto_ReservedRange* google_protobuf_Descri int options, upb_Arena* arena) { google_protobuf_DescriptorProto_ReservedRange* ret = google_protobuf_DescriptorProto_ReservedRange_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__DescriptorProto__ReservedRange_msg_init, extreg, options, arena) != - kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__DescriptorProto__ReservedRange_msg_init, extreg, options, + arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_DescriptorProto_ReservedRange_serialize(const google_protobuf_DescriptorProto_ReservedRange* msg, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__DescriptorProto__ReservedRange_msg_init, 0, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__DescriptorProto__ReservedRange_msg_init, 0, arena, &ptr, len); return ptr; } UPB_INLINE char* google_protobuf_DescriptorProto_ReservedRange_serialize_ex(const google_protobuf_DescriptorProto_ReservedRange* msg, int options, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__DescriptorProto__ReservedRange_msg_init, options, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__DescriptorProto__ReservedRange_msg_init, options, arena, &ptr, len); return ptr; } UPB_INLINE void google_protobuf_DescriptorProto_ReservedRange_clear_start(google_protobuf_DescriptorProto_ReservedRange* msg) { const upb_MiniTableField field = {1, 4, 1, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_DescriptorProto_ReservedRange_start(const google_protobuf_DescriptorProto_ReservedRange* msg) { int32_t default_val = (int32_t)0; int32_t ret; const upb_MiniTableField field = {1, 4, 1, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_DescriptorProto_ReservedRange_has_start(const google_protobuf_DescriptorProto_ReservedRange* msg) { const upb_MiniTableField field = {1, 4, 1, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_DescriptorProto_ReservedRange_clear_end(google_protobuf_DescriptorProto_ReservedRange* msg) { const upb_MiniTableField field = {2, 8, 2, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_DescriptorProto_ReservedRange_end(const google_protobuf_DescriptorProto_ReservedRange* msg) { int32_t default_val = (int32_t)0; int32_t ret; const upb_MiniTableField field = {2, 8, 2, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_DescriptorProto_ReservedRange_has_end(const google_protobuf_DescriptorProto_ReservedRange* msg) { const upb_MiniTableField field = {2, 8, 2, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_DescriptorProto_ReservedRange_set_start(google_protobuf_DescriptorProto_ReservedRange *msg, int32_t value) { const upb_MiniTableField field = {1, 4, 1, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_DescriptorProto_ReservedRange_set_end(google_protobuf_DescriptorProto_ReservedRange *msg, int32_t value) { const upb_MiniTableField field = {2, 8, 2, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } /* google.protobuf.ExtensionRangeOptions */ @@ -5891,7 +5964,8 @@ UPB_INLINE google_protobuf_ExtensionRangeOptions* google_protobuf_ExtensionRange UPB_INLINE google_protobuf_ExtensionRangeOptions* google_protobuf_ExtensionRangeOptions_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_ExtensionRangeOptions* ret = google_protobuf_ExtensionRangeOptions_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__ExtensionRangeOptions_msg_init, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__ExtensionRangeOptions_msg_init, NULL, 0, arena) != + kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -5901,30 +5975,30 @@ UPB_INLINE google_protobuf_ExtensionRangeOptions* google_protobuf_ExtensionRange int options, upb_Arena* arena) { google_protobuf_ExtensionRangeOptions* ret = google_protobuf_ExtensionRangeOptions_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__ExtensionRangeOptions_msg_init, extreg, options, arena) != - kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__ExtensionRangeOptions_msg_init, extreg, options, + arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_ExtensionRangeOptions_serialize(const google_protobuf_ExtensionRangeOptions* msg, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__ExtensionRangeOptions_msg_init, 0, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__ExtensionRangeOptions_msg_init, 0, arena, &ptr, len); return ptr; } UPB_INLINE char* google_protobuf_ExtensionRangeOptions_serialize_ex(const google_protobuf_ExtensionRangeOptions* msg, int options, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__ExtensionRangeOptions_msg_init, options, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__ExtensionRangeOptions_msg_init, options, arena, &ptr, len); return ptr; } UPB_INLINE void google_protobuf_ExtensionRangeOptions_clear_declaration(google_protobuf_ExtensionRangeOptions* msg) { const upb_MiniTableField field = {2, UPB_SIZE(4, 8), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_ExtensionRangeOptions_Declaration* const* google_protobuf_ExtensionRangeOptions_declaration(const google_protobuf_ExtensionRangeOptions* msg, size_t* size) { const upb_MiniTableField field = {2, UPB_SIZE(4, 8), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_ExtensionRangeOptions_Declaration* const*)_upb_array_constptr(arr); @@ -5935,16 +6009,16 @@ UPB_INLINE const google_protobuf_ExtensionRangeOptions_Declaration* const* googl } UPB_INLINE const upb_Array* _google_protobuf_ExtensionRangeOptions_declaration_upb_array(const google_protobuf_ExtensionRangeOptions* msg, size_t* size) { const upb_MiniTableField field = {2, UPB_SIZE(4, 8), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } -UPB_INLINE upb_Array* _google_protobuf_ExtensionRangeOptions_declaration_mutable_upb_array(const google_protobuf_ExtensionRangeOptions* msg, size_t* size, upb_Arena* arena) { +UPB_INLINE upb_Array* _google_protobuf_ExtensionRangeOptions_declaration_mutable_upb_array(google_protobuf_ExtensionRangeOptions* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = {2, UPB_SIZE(4, 8), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - (upb_Message*)msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), + &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -5952,41 +6026,43 @@ UPB_INLINE upb_Array* _google_protobuf_ExtensionRangeOptions_declaration_mutable } UPB_INLINE void google_protobuf_ExtensionRangeOptions_clear_verification(google_protobuf_ExtensionRangeOptions* msg) { const upb_MiniTableField field = {3, UPB_SIZE(8, 4), 1, 3, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_ExtensionRangeOptions_verification(const google_protobuf_ExtensionRangeOptions* msg) { int32_t default_val = 1; int32_t ret; const upb_MiniTableField field = {3, UPB_SIZE(8, 4), 1, 3, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_ExtensionRangeOptions_has_verification(const google_protobuf_ExtensionRangeOptions* msg) { const upb_MiniTableField field = {3, UPB_SIZE(8, 4), 1, 3, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_ExtensionRangeOptions_clear_features(google_protobuf_ExtensionRangeOptions* msg) { const upb_MiniTableField field = {50, UPB_SIZE(12, 16), 2, 1, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_FeatureSet* google_protobuf_ExtensionRangeOptions_features(const google_protobuf_ExtensionRangeOptions* msg) { const google_protobuf_FeatureSet* default_val = NULL; const google_protobuf_FeatureSet* ret; const upb_MiniTableField field = {50, UPB_SIZE(12, 16), 2, 1, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_ExtensionRangeOptions_has_features(const google_protobuf_ExtensionRangeOptions* msg) { const upb_MiniTableField field = {50, UPB_SIZE(12, 16), 2, 1, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_ExtensionRangeOptions_clear_uninterpreted_option(google_protobuf_ExtensionRangeOptions* msg) { const upb_MiniTableField field = {999, UPB_SIZE(16, 24), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_ExtensionRangeOptions_uninterpreted_option(const google_protobuf_ExtensionRangeOptions* msg, size_t* size) { const upb_MiniTableField field = {999, UPB_SIZE(16, 24), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_UninterpretedOption* const*)_upb_array_constptr(arr); @@ -5997,16 +6073,16 @@ UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_Ext } UPB_INLINE const upb_Array* _google_protobuf_ExtensionRangeOptions_uninterpreted_option_upb_array(const google_protobuf_ExtensionRangeOptions* msg, size_t* size) { const upb_MiniTableField field = {999, UPB_SIZE(16, 24), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } -UPB_INLINE upb_Array* _google_protobuf_ExtensionRangeOptions_uninterpreted_option_mutable_upb_array(const google_protobuf_ExtensionRangeOptions* msg, size_t* size, upb_Arena* arena) { +UPB_INLINE upb_Array* _google_protobuf_ExtensionRangeOptions_uninterpreted_option_mutable_upb_array(google_protobuf_ExtensionRangeOptions* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = {999, UPB_SIZE(16, 24), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - (upb_Message*)msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), + &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -6015,7 +6091,7 @@ UPB_INLINE upb_Array* _google_protobuf_ExtensionRangeOptions_uninterpreted_optio UPB_INLINE google_protobuf_ExtensionRangeOptions_Declaration** google_protobuf_ExtensionRangeOptions_mutable_declaration(google_protobuf_ExtensionRangeOptions* msg, size_t* size) { upb_MiniTableField field = {2, UPB_SIZE(4, 8), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetMutableArray(msg, &field); + upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_ExtensionRangeOptions_Declaration**)_upb_array_ptr(arr); @@ -6026,11 +6102,13 @@ UPB_INLINE google_protobuf_ExtensionRangeOptions_Declaration** google_protobuf_E } UPB_INLINE google_protobuf_ExtensionRangeOptions_Declaration** google_protobuf_ExtensionRangeOptions_resize_declaration(google_protobuf_ExtensionRangeOptions* msg, size_t size, upb_Arena* arena) { upb_MiniTableField field = {2, UPB_SIZE(4, 8), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return (google_protobuf_ExtensionRangeOptions_Declaration**)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); + return (google_protobuf_ExtensionRangeOptions_Declaration**)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg), + &field, size, arena); } UPB_INLINE struct google_protobuf_ExtensionRangeOptions_Declaration* google_protobuf_ExtensionRangeOptions_add_declaration(google_protobuf_ExtensionRangeOptions* msg, upb_Arena* arena) { upb_MiniTableField field = {2, UPB_SIZE(4, 8), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray( + UPB_UPCAST(msg), &field, arena); if (!arr || !_upb_Array_ResizeUninitialized( arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; @@ -6043,11 +6121,11 @@ UPB_INLINE struct google_protobuf_ExtensionRangeOptions_Declaration* google_prot } UPB_INLINE void google_protobuf_ExtensionRangeOptions_set_verification(google_protobuf_ExtensionRangeOptions *msg, int32_t value) { const upb_MiniTableField field = {3, UPB_SIZE(8, 4), 1, 3, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_ExtensionRangeOptions_set_features(google_protobuf_ExtensionRangeOptions *msg, google_protobuf_FeatureSet* value) { const upb_MiniTableField field = {50, UPB_SIZE(12, 16), 2, 1, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE struct google_protobuf_FeatureSet* google_protobuf_ExtensionRangeOptions_mutable_features(google_protobuf_ExtensionRangeOptions* msg, upb_Arena* arena) { struct google_protobuf_FeatureSet* sub = (struct google_protobuf_FeatureSet*)google_protobuf_ExtensionRangeOptions_features(msg); @@ -6059,7 +6137,7 @@ UPB_INLINE struct google_protobuf_FeatureSet* google_protobuf_ExtensionRangeOpti } UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_ExtensionRangeOptions_mutable_uninterpreted_option(google_protobuf_ExtensionRangeOptions* msg, size_t* size) { upb_MiniTableField field = {999, UPB_SIZE(16, 24), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetMutableArray(msg, &field); + upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_UninterpretedOption**)_upb_array_ptr(arr); @@ -6070,11 +6148,13 @@ UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_ExtensionRangeO } UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_ExtensionRangeOptions_resize_uninterpreted_option(google_protobuf_ExtensionRangeOptions* msg, size_t size, upb_Arena* arena) { upb_MiniTableField field = {999, UPB_SIZE(16, 24), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return (google_protobuf_UninterpretedOption**)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); + return (google_protobuf_UninterpretedOption**)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg), + &field, size, arena); } UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_ExtensionRangeOptions_add_uninterpreted_option(google_protobuf_ExtensionRangeOptions* msg, upb_Arena* arena) { upb_MiniTableField field = {999, UPB_SIZE(16, 24), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray( + UPB_UPCAST(msg), &field, arena); if (!arr || !_upb_Array_ResizeUninitialized( arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; @@ -6094,7 +6174,8 @@ UPB_INLINE google_protobuf_ExtensionRangeOptions_Declaration* google_protobuf_Ex UPB_INLINE google_protobuf_ExtensionRangeOptions_Declaration* google_protobuf_ExtensionRangeOptions_Declaration_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_ExtensionRangeOptions_Declaration* ret = google_protobuf_ExtensionRangeOptions_Declaration_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__ExtensionRangeOptions__Declaration_msg_init, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__ExtensionRangeOptions__Declaration_msg_init, NULL, 0, arena) != + kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -6104,118 +6185,123 @@ UPB_INLINE google_protobuf_ExtensionRangeOptions_Declaration* google_protobuf_Ex int options, upb_Arena* arena) { google_protobuf_ExtensionRangeOptions_Declaration* ret = google_protobuf_ExtensionRangeOptions_Declaration_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__ExtensionRangeOptions__Declaration_msg_init, extreg, options, arena) != - kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__ExtensionRangeOptions__Declaration_msg_init, extreg, options, + arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_ExtensionRangeOptions_Declaration_serialize(const google_protobuf_ExtensionRangeOptions_Declaration* msg, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__ExtensionRangeOptions__Declaration_msg_init, 0, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__ExtensionRangeOptions__Declaration_msg_init, 0, arena, &ptr, len); return ptr; } UPB_INLINE char* google_protobuf_ExtensionRangeOptions_Declaration_serialize_ex(const google_protobuf_ExtensionRangeOptions_Declaration* msg, int options, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__ExtensionRangeOptions__Declaration_msg_init, options, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__ExtensionRangeOptions__Declaration_msg_init, options, arena, &ptr, len); return ptr; } UPB_INLINE void google_protobuf_ExtensionRangeOptions_Declaration_clear_number(google_protobuf_ExtensionRangeOptions_Declaration* msg) { const upb_MiniTableField field = {1, 4, 1, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_ExtensionRangeOptions_Declaration_number(const google_protobuf_ExtensionRangeOptions_Declaration* msg) { int32_t default_val = (int32_t)0; int32_t ret; const upb_MiniTableField field = {1, 4, 1, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_ExtensionRangeOptions_Declaration_has_number(const google_protobuf_ExtensionRangeOptions_Declaration* msg) { const upb_MiniTableField field = {1, 4, 1, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_ExtensionRangeOptions_Declaration_clear_full_name(google_protobuf_ExtensionRangeOptions_Declaration* msg) { const upb_MiniTableField field = {2, UPB_SIZE(12, 16), 2, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_ExtensionRangeOptions_Declaration_full_name(const google_protobuf_ExtensionRangeOptions_Declaration* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; const upb_MiniTableField field = {2, UPB_SIZE(12, 16), 2, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_ExtensionRangeOptions_Declaration_has_full_name(const google_protobuf_ExtensionRangeOptions_Declaration* msg) { const upb_MiniTableField field = {2, UPB_SIZE(12, 16), 2, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_ExtensionRangeOptions_Declaration_clear_type(google_protobuf_ExtensionRangeOptions_Declaration* msg) { const upb_MiniTableField field = {3, UPB_SIZE(20, 32), 3, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_ExtensionRangeOptions_Declaration_type(const google_protobuf_ExtensionRangeOptions_Declaration* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; const upb_MiniTableField field = {3, UPB_SIZE(20, 32), 3, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_ExtensionRangeOptions_Declaration_has_type(const google_protobuf_ExtensionRangeOptions_Declaration* msg) { const upb_MiniTableField field = {3, UPB_SIZE(20, 32), 3, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_ExtensionRangeOptions_Declaration_clear_reserved(google_protobuf_ExtensionRangeOptions_Declaration* msg) { const upb_MiniTableField field = {5, 8, 4, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_ExtensionRangeOptions_Declaration_reserved(const google_protobuf_ExtensionRangeOptions_Declaration* msg) { bool default_val = false; bool ret; const upb_MiniTableField field = {5, 8, 4, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_ExtensionRangeOptions_Declaration_has_reserved(const google_protobuf_ExtensionRangeOptions_Declaration* msg) { const upb_MiniTableField field = {5, 8, 4, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_ExtensionRangeOptions_Declaration_clear_repeated(google_protobuf_ExtensionRangeOptions_Declaration* msg) { const upb_MiniTableField field = {6, 9, 5, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_ExtensionRangeOptions_Declaration_repeated(const google_protobuf_ExtensionRangeOptions_Declaration* msg) { bool default_val = false; bool ret; const upb_MiniTableField field = {6, 9, 5, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_ExtensionRangeOptions_Declaration_has_repeated(const google_protobuf_ExtensionRangeOptions_Declaration* msg) { const upb_MiniTableField field = {6, 9, 5, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_ExtensionRangeOptions_Declaration_set_number(google_protobuf_ExtensionRangeOptions_Declaration *msg, int32_t value) { const upb_MiniTableField field = {1, 4, 1, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_ExtensionRangeOptions_Declaration_set_full_name(google_protobuf_ExtensionRangeOptions_Declaration *msg, upb_StringView value) { const upb_MiniTableField field = {2, UPB_SIZE(12, 16), 2, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_ExtensionRangeOptions_Declaration_set_type(google_protobuf_ExtensionRangeOptions_Declaration *msg, upb_StringView value) { const upb_MiniTableField field = {3, UPB_SIZE(20, 32), 3, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_ExtensionRangeOptions_Declaration_set_reserved(google_protobuf_ExtensionRangeOptions_Declaration *msg, bool value) { const upb_MiniTableField field = {5, 8, 4, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_ExtensionRangeOptions_Declaration_set_repeated(google_protobuf_ExtensionRangeOptions_Declaration *msg, bool value) { const upb_MiniTableField field = {6, 9, 5, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } /* google.protobuf.FieldDescriptorProto */ @@ -6226,7 +6312,8 @@ UPB_INLINE google_protobuf_FieldDescriptorProto* google_protobuf_FieldDescriptor UPB_INLINE google_protobuf_FieldDescriptorProto* google_protobuf_FieldDescriptorProto_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_FieldDescriptorProto* ret = google_protobuf_FieldDescriptorProto_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__FieldDescriptorProto_msg_init, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__FieldDescriptorProto_msg_init, NULL, 0, arena) != + kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -6236,220 +6323,231 @@ UPB_INLINE google_protobuf_FieldDescriptorProto* google_protobuf_FieldDescriptor int options, upb_Arena* arena) { google_protobuf_FieldDescriptorProto* ret = google_protobuf_FieldDescriptorProto_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__FieldDescriptorProto_msg_init, extreg, options, arena) != - kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__FieldDescriptorProto_msg_init, extreg, options, + arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_FieldDescriptorProto_serialize(const google_protobuf_FieldDescriptorProto* msg, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__FieldDescriptorProto_msg_init, 0, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__FieldDescriptorProto_msg_init, 0, arena, &ptr, len); return ptr; } UPB_INLINE char* google_protobuf_FieldDescriptorProto_serialize_ex(const google_protobuf_FieldDescriptorProto* msg, int options, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__FieldDescriptorProto_msg_init, options, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__FieldDescriptorProto_msg_init, options, arena, &ptr, len); return ptr; } UPB_INLINE void google_protobuf_FieldDescriptorProto_clear_name(google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = {1, UPB_SIZE(28, 24), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_FieldDescriptorProto_name(const google_protobuf_FieldDescriptorProto* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; const upb_MiniTableField field = {1, UPB_SIZE(28, 24), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_name(const google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = {1, UPB_SIZE(28, 24), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldDescriptorProto_clear_extendee(google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = {2, UPB_SIZE(36, 40), 2, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_FieldDescriptorProto_extendee(const google_protobuf_FieldDescriptorProto* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; const upb_MiniTableField field = {2, UPB_SIZE(36, 40), 2, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_extendee(const google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = {2, UPB_SIZE(36, 40), 2, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldDescriptorProto_clear_number(google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = {3, 4, 3, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_FieldDescriptorProto_number(const google_protobuf_FieldDescriptorProto* msg) { int32_t default_val = (int32_t)0; int32_t ret; const upb_MiniTableField field = {3, 4, 3, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_number(const google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = {3, 4, 3, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldDescriptorProto_clear_label(google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = {4, 8, 4, 1, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_FieldDescriptorProto_label(const google_protobuf_FieldDescriptorProto* msg) { int32_t default_val = 1; int32_t ret; const upb_MiniTableField field = {4, 8, 4, 1, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_label(const google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = {4, 8, 4, 1, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldDescriptorProto_clear_type(google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = {5, 12, 5, 2, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_FieldDescriptorProto_type(const google_protobuf_FieldDescriptorProto* msg) { int32_t default_val = 1; int32_t ret; const upb_MiniTableField field = {5, 12, 5, 2, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_type(const google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = {5, 12, 5, 2, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldDescriptorProto_clear_type_name(google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = {6, UPB_SIZE(44, 56), 6, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_FieldDescriptorProto_type_name(const google_protobuf_FieldDescriptorProto* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; const upb_MiniTableField field = {6, UPB_SIZE(44, 56), 6, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_type_name(const google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = {6, UPB_SIZE(44, 56), 6, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldDescriptorProto_clear_default_value(google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = {7, UPB_SIZE(52, 72), 7, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_FieldDescriptorProto_default_value(const google_protobuf_FieldDescriptorProto* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; const upb_MiniTableField field = {7, UPB_SIZE(52, 72), 7, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_default_value(const google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = {7, UPB_SIZE(52, 72), 7, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldDescriptorProto_clear_options(google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = {8, UPB_SIZE(16, 88), 8, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_FieldOptions* google_protobuf_FieldDescriptorProto_options(const google_protobuf_FieldDescriptorProto* msg) { const google_protobuf_FieldOptions* default_val = NULL; const google_protobuf_FieldOptions* ret; const upb_MiniTableField field = {8, UPB_SIZE(16, 88), 8, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_options(const google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = {8, UPB_SIZE(16, 88), 8, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldDescriptorProto_clear_oneof_index(google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = {9, UPB_SIZE(20, 16), 9, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_FieldDescriptorProto_oneof_index(const google_protobuf_FieldDescriptorProto* msg) { int32_t default_val = (int32_t)0; int32_t ret; const upb_MiniTableField field = {9, UPB_SIZE(20, 16), 9, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_oneof_index(const google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = {9, UPB_SIZE(20, 16), 9, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldDescriptorProto_clear_json_name(google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = {10, UPB_SIZE(60, 96), 10, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_FieldDescriptorProto_json_name(const google_protobuf_FieldDescriptorProto* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; const upb_MiniTableField field = {10, UPB_SIZE(60, 96), 10, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_json_name(const google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = {10, UPB_SIZE(60, 96), 10, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldDescriptorProto_clear_proto3_optional(google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = {17, UPB_SIZE(24, 20), 11, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_FieldDescriptorProto_proto3_optional(const google_protobuf_FieldDescriptorProto* msg) { bool default_val = false; bool ret; const upb_MiniTableField field = {17, UPB_SIZE(24, 20), 11, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_proto3_optional(const google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = {17, UPB_SIZE(24, 20), 11, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldDescriptorProto_set_name(google_protobuf_FieldDescriptorProto *msg, upb_StringView value) { const upb_MiniTableField field = {1, UPB_SIZE(28, 24), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FieldDescriptorProto_set_extendee(google_protobuf_FieldDescriptorProto *msg, upb_StringView value) { const upb_MiniTableField field = {2, UPB_SIZE(36, 40), 2, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FieldDescriptorProto_set_number(google_protobuf_FieldDescriptorProto *msg, int32_t value) { const upb_MiniTableField field = {3, 4, 3, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FieldDescriptorProto_set_label(google_protobuf_FieldDescriptorProto *msg, int32_t value) { const upb_MiniTableField field = {4, 8, 4, 1, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FieldDescriptorProto_set_type(google_protobuf_FieldDescriptorProto *msg, int32_t value) { const upb_MiniTableField field = {5, 12, 5, 2, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FieldDescriptorProto_set_type_name(google_protobuf_FieldDescriptorProto *msg, upb_StringView value) { const upb_MiniTableField field = {6, UPB_SIZE(44, 56), 6, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FieldDescriptorProto_set_default_value(google_protobuf_FieldDescriptorProto *msg, upb_StringView value) { const upb_MiniTableField field = {7, UPB_SIZE(52, 72), 7, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FieldDescriptorProto_set_options(google_protobuf_FieldDescriptorProto *msg, google_protobuf_FieldOptions* value) { const upb_MiniTableField field = {8, UPB_SIZE(16, 88), 8, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE struct google_protobuf_FieldOptions* google_protobuf_FieldDescriptorProto_mutable_options(google_protobuf_FieldDescriptorProto* msg, upb_Arena* arena) { struct google_protobuf_FieldOptions* sub = (struct google_protobuf_FieldOptions*)google_protobuf_FieldDescriptorProto_options(msg); @@ -6461,15 +6559,15 @@ UPB_INLINE struct google_protobuf_FieldOptions* google_protobuf_FieldDescriptorP } UPB_INLINE void google_protobuf_FieldDescriptorProto_set_oneof_index(google_protobuf_FieldDescriptorProto *msg, int32_t value) { const upb_MiniTableField field = {9, UPB_SIZE(20, 16), 9, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FieldDescriptorProto_set_json_name(google_protobuf_FieldDescriptorProto *msg, upb_StringView value) { const upb_MiniTableField field = {10, UPB_SIZE(60, 96), 10, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FieldDescriptorProto_set_proto3_optional(google_protobuf_FieldDescriptorProto *msg, bool value) { const upb_MiniTableField field = {17, UPB_SIZE(24, 20), 11, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } /* google.protobuf.OneofDescriptorProto */ @@ -6480,7 +6578,8 @@ UPB_INLINE google_protobuf_OneofDescriptorProto* google_protobuf_OneofDescriptor UPB_INLINE google_protobuf_OneofDescriptorProto* google_protobuf_OneofDescriptorProto_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_OneofDescriptorProto* ret = google_protobuf_OneofDescriptorProto_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__OneofDescriptorProto_msg_init, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__OneofDescriptorProto_msg_init, NULL, 0, arena) != + kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -6490,61 +6589,63 @@ UPB_INLINE google_protobuf_OneofDescriptorProto* google_protobuf_OneofDescriptor int options, upb_Arena* arena) { google_protobuf_OneofDescriptorProto* ret = google_protobuf_OneofDescriptorProto_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__OneofDescriptorProto_msg_init, extreg, options, arena) != - kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__OneofDescriptorProto_msg_init, extreg, options, + arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_OneofDescriptorProto_serialize(const google_protobuf_OneofDescriptorProto* msg, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__OneofDescriptorProto_msg_init, 0, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__OneofDescriptorProto_msg_init, 0, arena, &ptr, len); return ptr; } UPB_INLINE char* google_protobuf_OneofDescriptorProto_serialize_ex(const google_protobuf_OneofDescriptorProto* msg, int options, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__OneofDescriptorProto_msg_init, options, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__OneofDescriptorProto_msg_init, options, arena, &ptr, len); return ptr; } UPB_INLINE void google_protobuf_OneofDescriptorProto_clear_name(google_protobuf_OneofDescriptorProto* msg) { const upb_MiniTableField field = {1, 8, 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_OneofDescriptorProto_name(const google_protobuf_OneofDescriptorProto* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; const upb_MiniTableField field = {1, 8, 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_OneofDescriptorProto_has_name(const google_protobuf_OneofDescriptorProto* msg) { const upb_MiniTableField field = {1, 8, 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_OneofDescriptorProto_clear_options(google_protobuf_OneofDescriptorProto* msg) { const upb_MiniTableField field = {2, UPB_SIZE(4, 24), 2, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_OneofOptions* google_protobuf_OneofDescriptorProto_options(const google_protobuf_OneofDescriptorProto* msg) { const google_protobuf_OneofOptions* default_val = NULL; const google_protobuf_OneofOptions* ret; const upb_MiniTableField field = {2, UPB_SIZE(4, 24), 2, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_OneofDescriptorProto_has_options(const google_protobuf_OneofDescriptorProto* msg) { const upb_MiniTableField field = {2, UPB_SIZE(4, 24), 2, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_OneofDescriptorProto_set_name(google_protobuf_OneofDescriptorProto *msg, upb_StringView value) { const upb_MiniTableField field = {1, 8, 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_OneofDescriptorProto_set_options(google_protobuf_OneofDescriptorProto *msg, google_protobuf_OneofOptions* value) { const upb_MiniTableField field = {2, UPB_SIZE(4, 24), 2, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE struct google_protobuf_OneofOptions* google_protobuf_OneofDescriptorProto_mutable_options(google_protobuf_OneofDescriptorProto* msg, upb_Arena* arena) { struct google_protobuf_OneofOptions* sub = (struct google_protobuf_OneofOptions*)google_protobuf_OneofDescriptorProto_options(msg); @@ -6563,7 +6664,8 @@ UPB_INLINE google_protobuf_EnumDescriptorProto* google_protobuf_EnumDescriptorPr UPB_INLINE google_protobuf_EnumDescriptorProto* google_protobuf_EnumDescriptorProto_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_EnumDescriptorProto* ret = google_protobuf_EnumDescriptorProto_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__EnumDescriptorProto_msg_init, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__EnumDescriptorProto_msg_init, NULL, 0, arena) != + kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -6573,45 +6675,46 @@ UPB_INLINE google_protobuf_EnumDescriptorProto* google_protobuf_EnumDescriptorPr int options, upb_Arena* arena) { google_protobuf_EnumDescriptorProto* ret = google_protobuf_EnumDescriptorProto_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__EnumDescriptorProto_msg_init, extreg, options, arena) != - kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__EnumDescriptorProto_msg_init, extreg, options, + arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_EnumDescriptorProto_serialize(const google_protobuf_EnumDescriptorProto* msg, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__EnumDescriptorProto_msg_init, 0, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__EnumDescriptorProto_msg_init, 0, arena, &ptr, len); return ptr; } UPB_INLINE char* google_protobuf_EnumDescriptorProto_serialize_ex(const google_protobuf_EnumDescriptorProto* msg, int options, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__EnumDescriptorProto_msg_init, options, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__EnumDescriptorProto_msg_init, options, arena, &ptr, len); return ptr; } UPB_INLINE void google_protobuf_EnumDescriptorProto_clear_name(google_protobuf_EnumDescriptorProto* msg) { const upb_MiniTableField field = {1, UPB_SIZE(20, 8), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_EnumDescriptorProto_name(const google_protobuf_EnumDescriptorProto* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; const upb_MiniTableField field = {1, UPB_SIZE(20, 8), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_EnumDescriptorProto_has_name(const google_protobuf_EnumDescriptorProto* msg) { const upb_MiniTableField field = {1, UPB_SIZE(20, 8), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_EnumDescriptorProto_clear_value(google_protobuf_EnumDescriptorProto* msg) { const upb_MiniTableField field = {2, UPB_SIZE(4, 24), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_EnumValueDescriptorProto* const* google_protobuf_EnumDescriptorProto_value(const google_protobuf_EnumDescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {2, UPB_SIZE(4, 24), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_EnumValueDescriptorProto* const*)_upb_array_constptr(arr); @@ -6622,16 +6725,16 @@ UPB_INLINE const google_protobuf_EnumValueDescriptorProto* const* google_protobu } UPB_INLINE const upb_Array* _google_protobuf_EnumDescriptorProto_value_upb_array(const google_protobuf_EnumDescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {2, UPB_SIZE(4, 24), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } -UPB_INLINE upb_Array* _google_protobuf_EnumDescriptorProto_value_mutable_upb_array(const google_protobuf_EnumDescriptorProto* msg, size_t* size, upb_Arena* arena) { +UPB_INLINE upb_Array* _google_protobuf_EnumDescriptorProto_value_mutable_upb_array(google_protobuf_EnumDescriptorProto* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = {2, UPB_SIZE(4, 24), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - (upb_Message*)msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), + &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -6639,26 +6742,27 @@ UPB_INLINE upb_Array* _google_protobuf_EnumDescriptorProto_value_mutable_upb_arr } UPB_INLINE void google_protobuf_EnumDescriptorProto_clear_options(google_protobuf_EnumDescriptorProto* msg) { const upb_MiniTableField field = {3, UPB_SIZE(8, 32), 2, 1, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_EnumOptions* google_protobuf_EnumDescriptorProto_options(const google_protobuf_EnumDescriptorProto* msg) { const google_protobuf_EnumOptions* default_val = NULL; const google_protobuf_EnumOptions* ret; const upb_MiniTableField field = {3, UPB_SIZE(8, 32), 2, 1, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_EnumDescriptorProto_has_options(const google_protobuf_EnumDescriptorProto* msg) { const upb_MiniTableField field = {3, UPB_SIZE(8, 32), 2, 1, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_EnumDescriptorProto_clear_reserved_range(google_protobuf_EnumDescriptorProto* msg) { const upb_MiniTableField field = {4, UPB_SIZE(12, 40), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_EnumDescriptorProto_EnumReservedRange* const* google_protobuf_EnumDescriptorProto_reserved_range(const google_protobuf_EnumDescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {4, UPB_SIZE(12, 40), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_EnumDescriptorProto_EnumReservedRange* const*)_upb_array_constptr(arr); @@ -6669,16 +6773,16 @@ UPB_INLINE const google_protobuf_EnumDescriptorProto_EnumReservedRange* const* g } UPB_INLINE const upb_Array* _google_protobuf_EnumDescriptorProto_reserved_range_upb_array(const google_protobuf_EnumDescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {4, UPB_SIZE(12, 40), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } -UPB_INLINE upb_Array* _google_protobuf_EnumDescriptorProto_reserved_range_mutable_upb_array(const google_protobuf_EnumDescriptorProto* msg, size_t* size, upb_Arena* arena) { +UPB_INLINE upb_Array* _google_protobuf_EnumDescriptorProto_reserved_range_mutable_upb_array(google_protobuf_EnumDescriptorProto* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = {4, UPB_SIZE(12, 40), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - (upb_Message*)msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), + &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -6686,11 +6790,11 @@ UPB_INLINE upb_Array* _google_protobuf_EnumDescriptorProto_reserved_range_mutabl } UPB_INLINE void google_protobuf_EnumDescriptorProto_clear_reserved_name(google_protobuf_EnumDescriptorProto* msg) { const upb_MiniTableField field = {5, UPB_SIZE(16, 48), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView const* google_protobuf_EnumDescriptorProto_reserved_name(const google_protobuf_EnumDescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {5, UPB_SIZE(16, 48), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (upb_StringView const*)_upb_array_constptr(arr); @@ -6701,16 +6805,16 @@ UPB_INLINE upb_StringView const* google_protobuf_EnumDescriptorProto_reserved_na } UPB_INLINE const upb_Array* _google_protobuf_EnumDescriptorProto_reserved_name_upb_array(const google_protobuf_EnumDescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {5, UPB_SIZE(16, 48), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } -UPB_INLINE upb_Array* _google_protobuf_EnumDescriptorProto_reserved_name_mutable_upb_array(const google_protobuf_EnumDescriptorProto* msg, size_t* size, upb_Arena* arena) { +UPB_INLINE upb_Array* _google_protobuf_EnumDescriptorProto_reserved_name_mutable_upb_array(google_protobuf_EnumDescriptorProto* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = {5, UPB_SIZE(16, 48), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - (upb_Message*)msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), + &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -6719,11 +6823,11 @@ UPB_INLINE upb_Array* _google_protobuf_EnumDescriptorProto_reserved_name_mutable UPB_INLINE void google_protobuf_EnumDescriptorProto_set_name(google_protobuf_EnumDescriptorProto *msg, upb_StringView value) { const upb_MiniTableField field = {1, UPB_SIZE(20, 8), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE google_protobuf_EnumValueDescriptorProto** google_protobuf_EnumDescriptorProto_mutable_value(google_protobuf_EnumDescriptorProto* msg, size_t* size) { upb_MiniTableField field = {2, UPB_SIZE(4, 24), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetMutableArray(msg, &field); + upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_EnumValueDescriptorProto**)_upb_array_ptr(arr); @@ -6734,11 +6838,13 @@ UPB_INLINE google_protobuf_EnumValueDescriptorProto** google_protobuf_EnumDescri } UPB_INLINE google_protobuf_EnumValueDescriptorProto** google_protobuf_EnumDescriptorProto_resize_value(google_protobuf_EnumDescriptorProto* msg, size_t size, upb_Arena* arena) { upb_MiniTableField field = {2, UPB_SIZE(4, 24), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return (google_protobuf_EnumValueDescriptorProto**)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); + return (google_protobuf_EnumValueDescriptorProto**)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg), + &field, size, arena); } UPB_INLINE struct google_protobuf_EnumValueDescriptorProto* google_protobuf_EnumDescriptorProto_add_value(google_protobuf_EnumDescriptorProto* msg, upb_Arena* arena) { upb_MiniTableField field = {2, UPB_SIZE(4, 24), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray( + UPB_UPCAST(msg), &field, arena); if (!arr || !_upb_Array_ResizeUninitialized( arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; @@ -6751,7 +6857,7 @@ UPB_INLINE struct google_protobuf_EnumValueDescriptorProto* google_protobuf_Enum } UPB_INLINE void google_protobuf_EnumDescriptorProto_set_options(google_protobuf_EnumDescriptorProto *msg, google_protobuf_EnumOptions* value) { const upb_MiniTableField field = {3, UPB_SIZE(8, 32), 2, 1, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE struct google_protobuf_EnumOptions* google_protobuf_EnumDescriptorProto_mutable_options(google_protobuf_EnumDescriptorProto* msg, upb_Arena* arena) { struct google_protobuf_EnumOptions* sub = (struct google_protobuf_EnumOptions*)google_protobuf_EnumDescriptorProto_options(msg); @@ -6763,7 +6869,7 @@ UPB_INLINE struct google_protobuf_EnumOptions* google_protobuf_EnumDescriptorPro } UPB_INLINE google_protobuf_EnumDescriptorProto_EnumReservedRange** google_protobuf_EnumDescriptorProto_mutable_reserved_range(google_protobuf_EnumDescriptorProto* msg, size_t* size) { upb_MiniTableField field = {4, UPB_SIZE(12, 40), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetMutableArray(msg, &field); + upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_EnumDescriptorProto_EnumReservedRange**)_upb_array_ptr(arr); @@ -6774,11 +6880,13 @@ UPB_INLINE google_protobuf_EnumDescriptorProto_EnumReservedRange** google_protob } UPB_INLINE google_protobuf_EnumDescriptorProto_EnumReservedRange** google_protobuf_EnumDescriptorProto_resize_reserved_range(google_protobuf_EnumDescriptorProto* msg, size_t size, upb_Arena* arena) { upb_MiniTableField field = {4, UPB_SIZE(12, 40), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return (google_protobuf_EnumDescriptorProto_EnumReservedRange**)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); + return (google_protobuf_EnumDescriptorProto_EnumReservedRange**)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg), + &field, size, arena); } UPB_INLINE struct google_protobuf_EnumDescriptorProto_EnumReservedRange* google_protobuf_EnumDescriptorProto_add_reserved_range(google_protobuf_EnumDescriptorProto* msg, upb_Arena* arena) { upb_MiniTableField field = {4, UPB_SIZE(12, 40), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray( + UPB_UPCAST(msg), &field, arena); if (!arr || !_upb_Array_ResizeUninitialized( arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; @@ -6791,7 +6899,7 @@ UPB_INLINE struct google_protobuf_EnumDescriptorProto_EnumReservedRange* google_ } UPB_INLINE upb_StringView* google_protobuf_EnumDescriptorProto_mutable_reserved_name(google_protobuf_EnumDescriptorProto* msg, size_t* size) { upb_MiniTableField field = {5, UPB_SIZE(16, 48), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetMutableArray(msg, &field); + upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (upb_StringView*)_upb_array_ptr(arr); @@ -6802,11 +6910,13 @@ UPB_INLINE upb_StringView* google_protobuf_EnumDescriptorProto_mutable_reserved_ } UPB_INLINE upb_StringView* google_protobuf_EnumDescriptorProto_resize_reserved_name(google_protobuf_EnumDescriptorProto* msg, size_t size, upb_Arena* arena) { upb_MiniTableField field = {5, UPB_SIZE(16, 48), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return (upb_StringView*)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); + return (upb_StringView*)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg), + &field, size, arena); } UPB_INLINE bool google_protobuf_EnumDescriptorProto_add_reserved_name(google_protobuf_EnumDescriptorProto* msg, upb_StringView val, upb_Arena* arena) { upb_MiniTableField field = {5, UPB_SIZE(16, 48), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray( + UPB_UPCAST(msg), &field, arena); if (!arr || !_upb_Array_ResizeUninitialized( arr, arr->UPB_PRIVATE(size) + 1, arena)) { return false; @@ -6824,7 +6934,8 @@ UPB_INLINE google_protobuf_EnumDescriptorProto_EnumReservedRange* google_protobu UPB_INLINE google_protobuf_EnumDescriptorProto_EnumReservedRange* google_protobuf_EnumDescriptorProto_EnumReservedRange_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_EnumDescriptorProto_EnumReservedRange* ret = google_protobuf_EnumDescriptorProto_EnumReservedRange_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__EnumDescriptorProto__EnumReservedRange_msg_init, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__EnumDescriptorProto__EnumReservedRange_msg_init, NULL, 0, arena) != + kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -6834,61 +6945,63 @@ UPB_INLINE google_protobuf_EnumDescriptorProto_EnumReservedRange* google_protobu int options, upb_Arena* arena) { google_protobuf_EnumDescriptorProto_EnumReservedRange* ret = google_protobuf_EnumDescriptorProto_EnumReservedRange_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__EnumDescriptorProto__EnumReservedRange_msg_init, extreg, options, arena) != - kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__EnumDescriptorProto__EnumReservedRange_msg_init, extreg, options, + arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_EnumDescriptorProto_EnumReservedRange_serialize(const google_protobuf_EnumDescriptorProto_EnumReservedRange* msg, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__EnumDescriptorProto__EnumReservedRange_msg_init, 0, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__EnumDescriptorProto__EnumReservedRange_msg_init, 0, arena, &ptr, len); return ptr; } UPB_INLINE char* google_protobuf_EnumDescriptorProto_EnumReservedRange_serialize_ex(const google_protobuf_EnumDescriptorProto_EnumReservedRange* msg, int options, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__EnumDescriptorProto__EnumReservedRange_msg_init, options, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__EnumDescriptorProto__EnumReservedRange_msg_init, options, arena, &ptr, len); return ptr; } UPB_INLINE void google_protobuf_EnumDescriptorProto_EnumReservedRange_clear_start(google_protobuf_EnumDescriptorProto_EnumReservedRange* msg) { const upb_MiniTableField field = {1, 4, 1, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_EnumDescriptorProto_EnumReservedRange_start(const google_protobuf_EnumDescriptorProto_EnumReservedRange* msg) { int32_t default_val = (int32_t)0; int32_t ret; const upb_MiniTableField field = {1, 4, 1, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_EnumDescriptorProto_EnumReservedRange_has_start(const google_protobuf_EnumDescriptorProto_EnumReservedRange* msg) { const upb_MiniTableField field = {1, 4, 1, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_EnumDescriptorProto_EnumReservedRange_clear_end(google_protobuf_EnumDescriptorProto_EnumReservedRange* msg) { const upb_MiniTableField field = {2, 8, 2, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_EnumDescriptorProto_EnumReservedRange_end(const google_protobuf_EnumDescriptorProto_EnumReservedRange* msg) { int32_t default_val = (int32_t)0; int32_t ret; const upb_MiniTableField field = {2, 8, 2, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_EnumDescriptorProto_EnumReservedRange_has_end(const google_protobuf_EnumDescriptorProto_EnumReservedRange* msg) { const upb_MiniTableField field = {2, 8, 2, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_EnumDescriptorProto_EnumReservedRange_set_start(google_protobuf_EnumDescriptorProto_EnumReservedRange *msg, int32_t value) { const upb_MiniTableField field = {1, 4, 1, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_EnumDescriptorProto_EnumReservedRange_set_end(google_protobuf_EnumDescriptorProto_EnumReservedRange *msg, int32_t value) { const upb_MiniTableField field = {2, 8, 2, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } /* google.protobuf.EnumValueDescriptorProto */ @@ -6899,7 +7012,8 @@ UPB_INLINE google_protobuf_EnumValueDescriptorProto* google_protobuf_EnumValueDe UPB_INLINE google_protobuf_EnumValueDescriptorProto* google_protobuf_EnumValueDescriptorProto_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_EnumValueDescriptorProto* ret = google_protobuf_EnumValueDescriptorProto_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__EnumValueDescriptorProto_msg_init, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__EnumValueDescriptorProto_msg_init, NULL, 0, arena) != + kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -6909,80 +7023,83 @@ UPB_INLINE google_protobuf_EnumValueDescriptorProto* google_protobuf_EnumValueDe int options, upb_Arena* arena) { google_protobuf_EnumValueDescriptorProto* ret = google_protobuf_EnumValueDescriptorProto_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__EnumValueDescriptorProto_msg_init, extreg, options, arena) != - kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__EnumValueDescriptorProto_msg_init, extreg, options, + arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_EnumValueDescriptorProto_serialize(const google_protobuf_EnumValueDescriptorProto* msg, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__EnumValueDescriptorProto_msg_init, 0, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__EnumValueDescriptorProto_msg_init, 0, arena, &ptr, len); return ptr; } UPB_INLINE char* google_protobuf_EnumValueDescriptorProto_serialize_ex(const google_protobuf_EnumValueDescriptorProto* msg, int options, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__EnumValueDescriptorProto_msg_init, options, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__EnumValueDescriptorProto_msg_init, options, arena, &ptr, len); return ptr; } UPB_INLINE void google_protobuf_EnumValueDescriptorProto_clear_name(google_protobuf_EnumValueDescriptorProto* msg) { const upb_MiniTableField field = {1, UPB_SIZE(12, 8), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_EnumValueDescriptorProto_name(const google_protobuf_EnumValueDescriptorProto* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; const upb_MiniTableField field = {1, UPB_SIZE(12, 8), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_EnumValueDescriptorProto_has_name(const google_protobuf_EnumValueDescriptorProto* msg) { const upb_MiniTableField field = {1, UPB_SIZE(12, 8), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_EnumValueDescriptorProto_clear_number(google_protobuf_EnumValueDescriptorProto* msg) { const upb_MiniTableField field = {2, 4, 2, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_EnumValueDescriptorProto_number(const google_protobuf_EnumValueDescriptorProto* msg) { int32_t default_val = (int32_t)0; int32_t ret; const upb_MiniTableField field = {2, 4, 2, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_EnumValueDescriptorProto_has_number(const google_protobuf_EnumValueDescriptorProto* msg) { const upb_MiniTableField field = {2, 4, 2, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_EnumValueDescriptorProto_clear_options(google_protobuf_EnumValueDescriptorProto* msg) { const upb_MiniTableField field = {3, UPB_SIZE(8, 24), 3, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_EnumValueOptions* google_protobuf_EnumValueDescriptorProto_options(const google_protobuf_EnumValueDescriptorProto* msg) { const google_protobuf_EnumValueOptions* default_val = NULL; const google_protobuf_EnumValueOptions* ret; const upb_MiniTableField field = {3, UPB_SIZE(8, 24), 3, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_EnumValueDescriptorProto_has_options(const google_protobuf_EnumValueDescriptorProto* msg) { const upb_MiniTableField field = {3, UPB_SIZE(8, 24), 3, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_EnumValueDescriptorProto_set_name(google_protobuf_EnumValueDescriptorProto *msg, upb_StringView value) { const upb_MiniTableField field = {1, UPB_SIZE(12, 8), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_EnumValueDescriptorProto_set_number(google_protobuf_EnumValueDescriptorProto *msg, int32_t value) { const upb_MiniTableField field = {2, 4, 2, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_EnumValueDescriptorProto_set_options(google_protobuf_EnumValueDescriptorProto *msg, google_protobuf_EnumValueOptions* value) { const upb_MiniTableField field = {3, UPB_SIZE(8, 24), 3, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE struct google_protobuf_EnumValueOptions* google_protobuf_EnumValueDescriptorProto_mutable_options(google_protobuf_EnumValueDescriptorProto* msg, upb_Arena* arena) { struct google_protobuf_EnumValueOptions* sub = (struct google_protobuf_EnumValueOptions*)google_protobuf_EnumValueDescriptorProto_options(msg); @@ -7001,7 +7118,8 @@ UPB_INLINE google_protobuf_ServiceDescriptorProto* google_protobuf_ServiceDescri UPB_INLINE google_protobuf_ServiceDescriptorProto* google_protobuf_ServiceDescriptorProto_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_ServiceDescriptorProto* ret = google_protobuf_ServiceDescriptorProto_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__ServiceDescriptorProto_msg_init, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__ServiceDescriptorProto_msg_init, NULL, 0, arena) != + kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -7011,45 +7129,46 @@ UPB_INLINE google_protobuf_ServiceDescriptorProto* google_protobuf_ServiceDescri int options, upb_Arena* arena) { google_protobuf_ServiceDescriptorProto* ret = google_protobuf_ServiceDescriptorProto_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__ServiceDescriptorProto_msg_init, extreg, options, arena) != - kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__ServiceDescriptorProto_msg_init, extreg, options, + arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_ServiceDescriptorProto_serialize(const google_protobuf_ServiceDescriptorProto* msg, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__ServiceDescriptorProto_msg_init, 0, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__ServiceDescriptorProto_msg_init, 0, arena, &ptr, len); return ptr; } UPB_INLINE char* google_protobuf_ServiceDescriptorProto_serialize_ex(const google_protobuf_ServiceDescriptorProto* msg, int options, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__ServiceDescriptorProto_msg_init, options, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__ServiceDescriptorProto_msg_init, options, arena, &ptr, len); return ptr; } UPB_INLINE void google_protobuf_ServiceDescriptorProto_clear_name(google_protobuf_ServiceDescriptorProto* msg) { const upb_MiniTableField field = {1, UPB_SIZE(12, 8), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_ServiceDescriptorProto_name(const google_protobuf_ServiceDescriptorProto* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; const upb_MiniTableField field = {1, UPB_SIZE(12, 8), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_ServiceDescriptorProto_has_name(const google_protobuf_ServiceDescriptorProto* msg) { const upb_MiniTableField field = {1, UPB_SIZE(12, 8), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_ServiceDescriptorProto_clear_method(google_protobuf_ServiceDescriptorProto* msg) { const upb_MiniTableField field = {2, UPB_SIZE(4, 24), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_MethodDescriptorProto* const* google_protobuf_ServiceDescriptorProto_method(const google_protobuf_ServiceDescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {2, UPB_SIZE(4, 24), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_MethodDescriptorProto* const*)_upb_array_constptr(arr); @@ -7060,16 +7179,16 @@ UPB_INLINE const google_protobuf_MethodDescriptorProto* const* google_protobuf_S } UPB_INLINE const upb_Array* _google_protobuf_ServiceDescriptorProto_method_upb_array(const google_protobuf_ServiceDescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {2, UPB_SIZE(4, 24), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } -UPB_INLINE upb_Array* _google_protobuf_ServiceDescriptorProto_method_mutable_upb_array(const google_protobuf_ServiceDescriptorProto* msg, size_t* size, upb_Arena* arena) { +UPB_INLINE upb_Array* _google_protobuf_ServiceDescriptorProto_method_mutable_upb_array(google_protobuf_ServiceDescriptorProto* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = {2, UPB_SIZE(4, 24), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - (upb_Message*)msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), + &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -7077,27 +7196,28 @@ UPB_INLINE upb_Array* _google_protobuf_ServiceDescriptorProto_method_mutable_upb } UPB_INLINE void google_protobuf_ServiceDescriptorProto_clear_options(google_protobuf_ServiceDescriptorProto* msg) { const upb_MiniTableField field = {3, UPB_SIZE(8, 32), 2, 1, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_ServiceOptions* google_protobuf_ServiceDescriptorProto_options(const google_protobuf_ServiceDescriptorProto* msg) { const google_protobuf_ServiceOptions* default_val = NULL; const google_protobuf_ServiceOptions* ret; const upb_MiniTableField field = {3, UPB_SIZE(8, 32), 2, 1, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_ServiceDescriptorProto_has_options(const google_protobuf_ServiceDescriptorProto* msg) { const upb_MiniTableField field = {3, UPB_SIZE(8, 32), 2, 1, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_ServiceDescriptorProto_set_name(google_protobuf_ServiceDescriptorProto *msg, upb_StringView value) { const upb_MiniTableField field = {1, UPB_SIZE(12, 8), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE google_protobuf_MethodDescriptorProto** google_protobuf_ServiceDescriptorProto_mutable_method(google_protobuf_ServiceDescriptorProto* msg, size_t* size) { upb_MiniTableField field = {2, UPB_SIZE(4, 24), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetMutableArray(msg, &field); + upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_MethodDescriptorProto**)_upb_array_ptr(arr); @@ -7108,11 +7228,13 @@ UPB_INLINE google_protobuf_MethodDescriptorProto** google_protobuf_ServiceDescri } UPB_INLINE google_protobuf_MethodDescriptorProto** google_protobuf_ServiceDescriptorProto_resize_method(google_protobuf_ServiceDescriptorProto* msg, size_t size, upb_Arena* arena) { upb_MiniTableField field = {2, UPB_SIZE(4, 24), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return (google_protobuf_MethodDescriptorProto**)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); + return (google_protobuf_MethodDescriptorProto**)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg), + &field, size, arena); } UPB_INLINE struct google_protobuf_MethodDescriptorProto* google_protobuf_ServiceDescriptorProto_add_method(google_protobuf_ServiceDescriptorProto* msg, upb_Arena* arena) { upb_MiniTableField field = {2, UPB_SIZE(4, 24), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray( + UPB_UPCAST(msg), &field, arena); if (!arr || !_upb_Array_ResizeUninitialized( arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; @@ -7125,7 +7247,7 @@ UPB_INLINE struct google_protobuf_MethodDescriptorProto* google_protobuf_Service } UPB_INLINE void google_protobuf_ServiceDescriptorProto_set_options(google_protobuf_ServiceDescriptorProto *msg, google_protobuf_ServiceOptions* value) { const upb_MiniTableField field = {3, UPB_SIZE(8, 32), 2, 1, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE struct google_protobuf_ServiceOptions* google_protobuf_ServiceDescriptorProto_mutable_options(google_protobuf_ServiceDescriptorProto* msg, upb_Arena* arena) { struct google_protobuf_ServiceOptions* sub = (struct google_protobuf_ServiceOptions*)google_protobuf_ServiceDescriptorProto_options(msg); @@ -7144,7 +7266,8 @@ UPB_INLINE google_protobuf_MethodDescriptorProto* google_protobuf_MethodDescript UPB_INLINE google_protobuf_MethodDescriptorProto* google_protobuf_MethodDescriptorProto_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_MethodDescriptorProto* ret = google_protobuf_MethodDescriptorProto_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__MethodDescriptorProto_msg_init, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__MethodDescriptorProto_msg_init, NULL, 0, arena) != + kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -7154,129 +7277,135 @@ UPB_INLINE google_protobuf_MethodDescriptorProto* google_protobuf_MethodDescript int options, upb_Arena* arena) { google_protobuf_MethodDescriptorProto* ret = google_protobuf_MethodDescriptorProto_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__MethodDescriptorProto_msg_init, extreg, options, arena) != - kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__MethodDescriptorProto_msg_init, extreg, options, + arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_MethodDescriptorProto_serialize(const google_protobuf_MethodDescriptorProto* msg, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__MethodDescriptorProto_msg_init, 0, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__MethodDescriptorProto_msg_init, 0, arena, &ptr, len); return ptr; } UPB_INLINE char* google_protobuf_MethodDescriptorProto_serialize_ex(const google_protobuf_MethodDescriptorProto* msg, int options, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__MethodDescriptorProto_msg_init, options, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__MethodDescriptorProto_msg_init, options, arena, &ptr, len); return ptr; } UPB_INLINE void google_protobuf_MethodDescriptorProto_clear_name(google_protobuf_MethodDescriptorProto* msg) { const upb_MiniTableField field = {1, UPB_SIZE(12, 8), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_MethodDescriptorProto_name(const google_protobuf_MethodDescriptorProto* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; const upb_MiniTableField field = {1, UPB_SIZE(12, 8), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_MethodDescriptorProto_has_name(const google_protobuf_MethodDescriptorProto* msg) { const upb_MiniTableField field = {1, UPB_SIZE(12, 8), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_MethodDescriptorProto_clear_input_type(google_protobuf_MethodDescriptorProto* msg) { const upb_MiniTableField field = {2, UPB_SIZE(20, 24), 2, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_MethodDescriptorProto_input_type(const google_protobuf_MethodDescriptorProto* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; const upb_MiniTableField field = {2, UPB_SIZE(20, 24), 2, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_MethodDescriptorProto_has_input_type(const google_protobuf_MethodDescriptorProto* msg) { const upb_MiniTableField field = {2, UPB_SIZE(20, 24), 2, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_MethodDescriptorProto_clear_output_type(google_protobuf_MethodDescriptorProto* msg) { const upb_MiniTableField field = {3, UPB_SIZE(28, 40), 3, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_MethodDescriptorProto_output_type(const google_protobuf_MethodDescriptorProto* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; const upb_MiniTableField field = {3, UPB_SIZE(28, 40), 3, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_MethodDescriptorProto_has_output_type(const google_protobuf_MethodDescriptorProto* msg) { const upb_MiniTableField field = {3, UPB_SIZE(28, 40), 3, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_MethodDescriptorProto_clear_options(google_protobuf_MethodDescriptorProto* msg) { const upb_MiniTableField field = {4, UPB_SIZE(4, 56), 4, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_MethodOptions* google_protobuf_MethodDescriptorProto_options(const google_protobuf_MethodDescriptorProto* msg) { const google_protobuf_MethodOptions* default_val = NULL; const google_protobuf_MethodOptions* ret; const upb_MiniTableField field = {4, UPB_SIZE(4, 56), 4, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_MethodDescriptorProto_has_options(const google_protobuf_MethodDescriptorProto* msg) { const upb_MiniTableField field = {4, UPB_SIZE(4, 56), 4, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_MethodDescriptorProto_clear_client_streaming(google_protobuf_MethodDescriptorProto* msg) { const upb_MiniTableField field = {5, UPB_SIZE(8, 1), 5, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_MethodDescriptorProto_client_streaming(const google_protobuf_MethodDescriptorProto* msg) { bool default_val = false; bool ret; const upb_MiniTableField field = {5, UPB_SIZE(8, 1), 5, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_MethodDescriptorProto_has_client_streaming(const google_protobuf_MethodDescriptorProto* msg) { const upb_MiniTableField field = {5, UPB_SIZE(8, 1), 5, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_MethodDescriptorProto_clear_server_streaming(google_protobuf_MethodDescriptorProto* msg) { const upb_MiniTableField field = {6, UPB_SIZE(9, 2), 6, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_MethodDescriptorProto_server_streaming(const google_protobuf_MethodDescriptorProto* msg) { bool default_val = false; bool ret; const upb_MiniTableField field = {6, UPB_SIZE(9, 2), 6, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_MethodDescriptorProto_has_server_streaming(const google_protobuf_MethodDescriptorProto* msg) { const upb_MiniTableField field = {6, UPB_SIZE(9, 2), 6, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_MethodDescriptorProto_set_name(google_protobuf_MethodDescriptorProto *msg, upb_StringView value) { const upb_MiniTableField field = {1, UPB_SIZE(12, 8), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_MethodDescriptorProto_set_input_type(google_protobuf_MethodDescriptorProto *msg, upb_StringView value) { const upb_MiniTableField field = {2, UPB_SIZE(20, 24), 2, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_MethodDescriptorProto_set_output_type(google_protobuf_MethodDescriptorProto *msg, upb_StringView value) { const upb_MiniTableField field = {3, UPB_SIZE(28, 40), 3, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_MethodDescriptorProto_set_options(google_protobuf_MethodDescriptorProto *msg, google_protobuf_MethodOptions* value) { const upb_MiniTableField field = {4, UPB_SIZE(4, 56), 4, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE struct google_protobuf_MethodOptions* google_protobuf_MethodDescriptorProto_mutable_options(google_protobuf_MethodDescriptorProto* msg, upb_Arena* arena) { struct google_protobuf_MethodOptions* sub = (struct google_protobuf_MethodOptions*)google_protobuf_MethodDescriptorProto_options(msg); @@ -7288,11 +7417,11 @@ UPB_INLINE struct google_protobuf_MethodOptions* google_protobuf_MethodDescripto } UPB_INLINE void google_protobuf_MethodDescriptorProto_set_client_streaming(google_protobuf_MethodDescriptorProto *msg, bool value) { const upb_MiniTableField field = {5, UPB_SIZE(8, 1), 5, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_MethodDescriptorProto_set_server_streaming(google_protobuf_MethodDescriptorProto *msg, bool value) { const upb_MiniTableField field = {6, UPB_SIZE(9, 2), 6, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } /* google.protobuf.FileOptions */ @@ -7303,7 +7432,8 @@ UPB_INLINE google_protobuf_FileOptions* google_protobuf_FileOptions_new(upb_Aren UPB_INLINE google_protobuf_FileOptions* google_protobuf_FileOptions_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_FileOptions* ret = google_protobuf_FileOptions_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__FileOptions_msg_init, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__FileOptions_msg_init, NULL, 0, arena) != + kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -7313,330 +7443,350 @@ UPB_INLINE google_protobuf_FileOptions* google_protobuf_FileOptions_parse_ex(con int options, upb_Arena* arena) { google_protobuf_FileOptions* ret = google_protobuf_FileOptions_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__FileOptions_msg_init, extreg, options, arena) != - kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__FileOptions_msg_init, extreg, options, + arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_FileOptions_serialize(const google_protobuf_FileOptions* msg, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__FileOptions_msg_init, 0, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__FileOptions_msg_init, 0, arena, &ptr, len); return ptr; } UPB_INLINE char* google_protobuf_FileOptions_serialize_ex(const google_protobuf_FileOptions* msg, int options, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__FileOptions_msg_init, options, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__FileOptions_msg_init, options, arena, &ptr, len); return ptr; } UPB_INLINE void google_protobuf_FileOptions_clear_java_package(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {1, UPB_SIZE(24, 16), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_FileOptions_java_package(const google_protobuf_FileOptions* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; const upb_MiniTableField field = {1, UPB_SIZE(24, 16), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FileOptions_has_java_package(const google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {1, UPB_SIZE(24, 16), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileOptions_clear_java_outer_classname(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {8, 32, 2, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_FileOptions_java_outer_classname(const google_protobuf_FileOptions* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; const upb_MiniTableField field = {8, 32, 2, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FileOptions_has_java_outer_classname(const google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {8, 32, 2, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileOptions_clear_optimize_for(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {9, 4, 3, 2, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_FileOptions_optimize_for(const google_protobuf_FileOptions* msg) { int32_t default_val = 1; int32_t ret; const upb_MiniTableField field = {9, 4, 3, 2, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FileOptions_has_optimize_for(const google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {9, 4, 3, 2, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileOptions_clear_java_multiple_files(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {10, 8, 4, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_FileOptions_java_multiple_files(const google_protobuf_FileOptions* msg) { bool default_val = false; bool ret; const upb_MiniTableField field = {10, 8, 4, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FileOptions_has_java_multiple_files(const google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {10, 8, 4, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileOptions_clear_go_package(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {11, UPB_SIZE(40, 48), 5, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_FileOptions_go_package(const google_protobuf_FileOptions* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; const upb_MiniTableField field = {11, UPB_SIZE(40, 48), 5, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FileOptions_has_go_package(const google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {11, UPB_SIZE(40, 48), 5, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileOptions_clear_cc_generic_services(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {16, 9, 6, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_FileOptions_cc_generic_services(const google_protobuf_FileOptions* msg) { bool default_val = false; bool ret; const upb_MiniTableField field = {16, 9, 6, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FileOptions_has_cc_generic_services(const google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {16, 9, 6, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileOptions_clear_java_generic_services(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {17, 10, 7, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_FileOptions_java_generic_services(const google_protobuf_FileOptions* msg) { bool default_val = false; bool ret; const upb_MiniTableField field = {17, 10, 7, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FileOptions_has_java_generic_services(const google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {17, 10, 7, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileOptions_clear_py_generic_services(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {18, 11, 8, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_FileOptions_py_generic_services(const google_protobuf_FileOptions* msg) { bool default_val = false; bool ret; const upb_MiniTableField field = {18, 11, 8, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FileOptions_has_py_generic_services(const google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {18, 11, 8, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileOptions_clear_java_generate_equals_and_hash(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {20, 12, 9, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_FileOptions_java_generate_equals_and_hash(const google_protobuf_FileOptions* msg) { bool default_val = false; bool ret; const upb_MiniTableField field = {20, 12, 9, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FileOptions_has_java_generate_equals_and_hash(const google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {20, 12, 9, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileOptions_clear_deprecated(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {23, 13, 10, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_FileOptions_deprecated(const google_protobuf_FileOptions* msg) { bool default_val = false; bool ret; const upb_MiniTableField field = {23, 13, 10, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FileOptions_has_deprecated(const google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {23, 13, 10, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileOptions_clear_java_string_check_utf8(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {27, 14, 11, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_FileOptions_java_string_check_utf8(const google_protobuf_FileOptions* msg) { bool default_val = false; bool ret; const upb_MiniTableField field = {27, 14, 11, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FileOptions_has_java_string_check_utf8(const google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {27, 14, 11, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileOptions_clear_cc_enable_arenas(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {31, 15, 12, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_FileOptions_cc_enable_arenas(const google_protobuf_FileOptions* msg) { bool default_val = true; bool ret; const upb_MiniTableField field = {31, 15, 12, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FileOptions_has_cc_enable_arenas(const google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {31, 15, 12, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileOptions_clear_objc_class_prefix(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {36, UPB_SIZE(48, 64), 13, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_FileOptions_objc_class_prefix(const google_protobuf_FileOptions* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; const upb_MiniTableField field = {36, UPB_SIZE(48, 64), 13, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FileOptions_has_objc_class_prefix(const google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {36, UPB_SIZE(48, 64), 13, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileOptions_clear_csharp_namespace(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {37, UPB_SIZE(56, 80), 14, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_FileOptions_csharp_namespace(const google_protobuf_FileOptions* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; const upb_MiniTableField field = {37, UPB_SIZE(56, 80), 14, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FileOptions_has_csharp_namespace(const google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {37, UPB_SIZE(56, 80), 14, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileOptions_clear_swift_prefix(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {39, UPB_SIZE(64, 96), 15, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_FileOptions_swift_prefix(const google_protobuf_FileOptions* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; const upb_MiniTableField field = {39, UPB_SIZE(64, 96), 15, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FileOptions_has_swift_prefix(const google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {39, UPB_SIZE(64, 96), 15, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileOptions_clear_php_class_prefix(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {40, UPB_SIZE(72, 112), 16, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_FileOptions_php_class_prefix(const google_protobuf_FileOptions* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; const upb_MiniTableField field = {40, UPB_SIZE(72, 112), 16, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FileOptions_has_php_class_prefix(const google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {40, UPB_SIZE(72, 112), 16, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileOptions_clear_php_namespace(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {41, UPB_SIZE(80, 128), 17, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_FileOptions_php_namespace(const google_protobuf_FileOptions* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; const upb_MiniTableField field = {41, UPB_SIZE(80, 128), 17, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FileOptions_has_php_namespace(const google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {41, UPB_SIZE(80, 128), 17, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileOptions_clear_php_metadata_namespace(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {44, UPB_SIZE(88, 144), 18, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_FileOptions_php_metadata_namespace(const google_protobuf_FileOptions* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; const upb_MiniTableField field = {44, UPB_SIZE(88, 144), 18, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FileOptions_has_php_metadata_namespace(const google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {44, UPB_SIZE(88, 144), 18, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileOptions_clear_ruby_package(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {45, UPB_SIZE(96, 160), 19, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_FileOptions_ruby_package(const google_protobuf_FileOptions* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; const upb_MiniTableField field = {45, UPB_SIZE(96, 160), 19, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FileOptions_has_ruby_package(const google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {45, UPB_SIZE(96, 160), 19, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileOptions_clear_features(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {50, UPB_SIZE(16, 176), 20, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_FeatureSet* google_protobuf_FileOptions_features(const google_protobuf_FileOptions* msg) { const google_protobuf_FeatureSet* default_val = NULL; const google_protobuf_FeatureSet* ret; const upb_MiniTableField field = {50, UPB_SIZE(16, 176), 20, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FileOptions_has_features(const google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {50, UPB_SIZE(16, 176), 20, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileOptions_clear_uninterpreted_option(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {999, UPB_SIZE(20, 184), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_FileOptions_uninterpreted_option(const google_protobuf_FileOptions* msg, size_t* size) { const upb_MiniTableField field = {999, UPB_SIZE(20, 184), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_UninterpretedOption* const*)_upb_array_constptr(arr); @@ -7647,16 +7797,16 @@ UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_Fil } UPB_INLINE const upb_Array* _google_protobuf_FileOptions_uninterpreted_option_upb_array(const google_protobuf_FileOptions* msg, size_t* size) { const upb_MiniTableField field = {999, UPB_SIZE(20, 184), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } -UPB_INLINE upb_Array* _google_protobuf_FileOptions_uninterpreted_option_mutable_upb_array(const google_protobuf_FileOptions* msg, size_t* size, upb_Arena* arena) { +UPB_INLINE upb_Array* _google_protobuf_FileOptions_uninterpreted_option_mutable_upb_array(google_protobuf_FileOptions* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = {999, UPB_SIZE(20, 184), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - (upb_Message*)msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), + &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -7665,83 +7815,83 @@ UPB_INLINE upb_Array* _google_protobuf_FileOptions_uninterpreted_option_mutable_ UPB_INLINE void google_protobuf_FileOptions_set_java_package(google_protobuf_FileOptions *msg, upb_StringView value) { const upb_MiniTableField field = {1, UPB_SIZE(24, 16), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FileOptions_set_java_outer_classname(google_protobuf_FileOptions *msg, upb_StringView value) { const upb_MiniTableField field = {8, 32, 2, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FileOptions_set_optimize_for(google_protobuf_FileOptions *msg, int32_t value) { const upb_MiniTableField field = {9, 4, 3, 2, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FileOptions_set_java_multiple_files(google_protobuf_FileOptions *msg, bool value) { const upb_MiniTableField field = {10, 8, 4, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FileOptions_set_go_package(google_protobuf_FileOptions *msg, upb_StringView value) { const upb_MiniTableField field = {11, UPB_SIZE(40, 48), 5, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FileOptions_set_cc_generic_services(google_protobuf_FileOptions *msg, bool value) { const upb_MiniTableField field = {16, 9, 6, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FileOptions_set_java_generic_services(google_protobuf_FileOptions *msg, bool value) { const upb_MiniTableField field = {17, 10, 7, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FileOptions_set_py_generic_services(google_protobuf_FileOptions *msg, bool value) { const upb_MiniTableField field = {18, 11, 8, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FileOptions_set_java_generate_equals_and_hash(google_protobuf_FileOptions *msg, bool value) { const upb_MiniTableField field = {20, 12, 9, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FileOptions_set_deprecated(google_protobuf_FileOptions *msg, bool value) { const upb_MiniTableField field = {23, 13, 10, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FileOptions_set_java_string_check_utf8(google_protobuf_FileOptions *msg, bool value) { const upb_MiniTableField field = {27, 14, 11, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FileOptions_set_cc_enable_arenas(google_protobuf_FileOptions *msg, bool value) { const upb_MiniTableField field = {31, 15, 12, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FileOptions_set_objc_class_prefix(google_protobuf_FileOptions *msg, upb_StringView value) { const upb_MiniTableField field = {36, UPB_SIZE(48, 64), 13, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FileOptions_set_csharp_namespace(google_protobuf_FileOptions *msg, upb_StringView value) { const upb_MiniTableField field = {37, UPB_SIZE(56, 80), 14, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FileOptions_set_swift_prefix(google_protobuf_FileOptions *msg, upb_StringView value) { const upb_MiniTableField field = {39, UPB_SIZE(64, 96), 15, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FileOptions_set_php_class_prefix(google_protobuf_FileOptions *msg, upb_StringView value) { const upb_MiniTableField field = {40, UPB_SIZE(72, 112), 16, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FileOptions_set_php_namespace(google_protobuf_FileOptions *msg, upb_StringView value) { const upb_MiniTableField field = {41, UPB_SIZE(80, 128), 17, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FileOptions_set_php_metadata_namespace(google_protobuf_FileOptions *msg, upb_StringView value) { const upb_MiniTableField field = {44, UPB_SIZE(88, 144), 18, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FileOptions_set_ruby_package(google_protobuf_FileOptions *msg, upb_StringView value) { const upb_MiniTableField field = {45, UPB_SIZE(96, 160), 19, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FileOptions_set_features(google_protobuf_FileOptions *msg, google_protobuf_FeatureSet* value) { const upb_MiniTableField field = {50, UPB_SIZE(16, 176), 20, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE struct google_protobuf_FeatureSet* google_protobuf_FileOptions_mutable_features(google_protobuf_FileOptions* msg, upb_Arena* arena) { struct google_protobuf_FeatureSet* sub = (struct google_protobuf_FeatureSet*)google_protobuf_FileOptions_features(msg); @@ -7753,7 +7903,7 @@ UPB_INLINE struct google_protobuf_FeatureSet* google_protobuf_FileOptions_mutabl } UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_FileOptions_mutable_uninterpreted_option(google_protobuf_FileOptions* msg, size_t* size) { upb_MiniTableField field = {999, UPB_SIZE(20, 184), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetMutableArray(msg, &field); + upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_UninterpretedOption**)_upb_array_ptr(arr); @@ -7764,11 +7914,13 @@ UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_FileOptions_mut } UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_FileOptions_resize_uninterpreted_option(google_protobuf_FileOptions* msg, size_t size, upb_Arena* arena) { upb_MiniTableField field = {999, UPB_SIZE(20, 184), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return (google_protobuf_UninterpretedOption**)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); + return (google_protobuf_UninterpretedOption**)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg), + &field, size, arena); } UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_FileOptions_add_uninterpreted_option(google_protobuf_FileOptions* msg, upb_Arena* arena) { upb_MiniTableField field = {999, UPB_SIZE(20, 184), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray( + UPB_UPCAST(msg), &field, arena); if (!arr || !_upb_Array_ResizeUninitialized( arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; @@ -7788,7 +7940,8 @@ UPB_INLINE google_protobuf_MessageOptions* google_protobuf_MessageOptions_new(up UPB_INLINE google_protobuf_MessageOptions* google_protobuf_MessageOptions_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_MessageOptions* ret = google_protobuf_MessageOptions_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__MessageOptions_msg_init, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__MessageOptions_msg_init, NULL, 0, arena) != + kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -7798,120 +7951,126 @@ UPB_INLINE google_protobuf_MessageOptions* google_protobuf_MessageOptions_parse_ int options, upb_Arena* arena) { google_protobuf_MessageOptions* ret = google_protobuf_MessageOptions_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__MessageOptions_msg_init, extreg, options, arena) != - kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__MessageOptions_msg_init, extreg, options, + arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_MessageOptions_serialize(const google_protobuf_MessageOptions* msg, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__MessageOptions_msg_init, 0, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__MessageOptions_msg_init, 0, arena, &ptr, len); return ptr; } UPB_INLINE char* google_protobuf_MessageOptions_serialize_ex(const google_protobuf_MessageOptions* msg, int options, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__MessageOptions_msg_init, options, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__MessageOptions_msg_init, options, arena, &ptr, len); return ptr; } UPB_INLINE void google_protobuf_MessageOptions_clear_message_set_wire_format(google_protobuf_MessageOptions* msg) { const upb_MiniTableField field = {1, 1, 1, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_MessageOptions_message_set_wire_format(const google_protobuf_MessageOptions* msg) { bool default_val = false; bool ret; const upb_MiniTableField field = {1, 1, 1, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_MessageOptions_has_message_set_wire_format(const google_protobuf_MessageOptions* msg) { const upb_MiniTableField field = {1, 1, 1, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_MessageOptions_clear_no_standard_descriptor_accessor(google_protobuf_MessageOptions* msg) { const upb_MiniTableField field = {2, 2, 2, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_MessageOptions_no_standard_descriptor_accessor(const google_protobuf_MessageOptions* msg) { bool default_val = false; bool ret; const upb_MiniTableField field = {2, 2, 2, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_MessageOptions_has_no_standard_descriptor_accessor(const google_protobuf_MessageOptions* msg) { const upb_MiniTableField field = {2, 2, 2, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_MessageOptions_clear_deprecated(google_protobuf_MessageOptions* msg) { const upb_MiniTableField field = {3, 3, 3, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_MessageOptions_deprecated(const google_protobuf_MessageOptions* msg) { bool default_val = false; bool ret; const upb_MiniTableField field = {3, 3, 3, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_MessageOptions_has_deprecated(const google_protobuf_MessageOptions* msg) { const upb_MiniTableField field = {3, 3, 3, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_MessageOptions_clear_map_entry(google_protobuf_MessageOptions* msg) { const upb_MiniTableField field = {7, 4, 4, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_MessageOptions_map_entry(const google_protobuf_MessageOptions* msg) { bool default_val = false; bool ret; const upb_MiniTableField field = {7, 4, 4, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_MessageOptions_has_map_entry(const google_protobuf_MessageOptions* msg) { const upb_MiniTableField field = {7, 4, 4, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_MessageOptions_clear_deprecated_legacy_json_field_conflicts(google_protobuf_MessageOptions* msg) { const upb_MiniTableField field = {11, 5, 5, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_MessageOptions_deprecated_legacy_json_field_conflicts(const google_protobuf_MessageOptions* msg) { bool default_val = false; bool ret; const upb_MiniTableField field = {11, 5, 5, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_MessageOptions_has_deprecated_legacy_json_field_conflicts(const google_protobuf_MessageOptions* msg) { const upb_MiniTableField field = {11, 5, 5, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_MessageOptions_clear_features(google_protobuf_MessageOptions* msg) { const upb_MiniTableField field = {12, 8, 6, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_FeatureSet* google_protobuf_MessageOptions_features(const google_protobuf_MessageOptions* msg) { const google_protobuf_FeatureSet* default_val = NULL; const google_protobuf_FeatureSet* ret; const upb_MiniTableField field = {12, 8, 6, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_MessageOptions_has_features(const google_protobuf_MessageOptions* msg) { const upb_MiniTableField field = {12, 8, 6, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_MessageOptions_clear_uninterpreted_option(google_protobuf_MessageOptions* msg) { const upb_MiniTableField field = {999, UPB_SIZE(12, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_MessageOptions_uninterpreted_option(const google_protobuf_MessageOptions* msg, size_t* size) { const upb_MiniTableField field = {999, UPB_SIZE(12, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_UninterpretedOption* const*)_upb_array_constptr(arr); @@ -7922,16 +8081,16 @@ UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_Mes } UPB_INLINE const upb_Array* _google_protobuf_MessageOptions_uninterpreted_option_upb_array(const google_protobuf_MessageOptions* msg, size_t* size) { const upb_MiniTableField field = {999, UPB_SIZE(12, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } -UPB_INLINE upb_Array* _google_protobuf_MessageOptions_uninterpreted_option_mutable_upb_array(const google_protobuf_MessageOptions* msg, size_t* size, upb_Arena* arena) { +UPB_INLINE upb_Array* _google_protobuf_MessageOptions_uninterpreted_option_mutable_upb_array(google_protobuf_MessageOptions* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = {999, UPB_SIZE(12, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - (upb_Message*)msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), + &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -7940,27 +8099,27 @@ UPB_INLINE upb_Array* _google_protobuf_MessageOptions_uninterpreted_option_mutab UPB_INLINE void google_protobuf_MessageOptions_set_message_set_wire_format(google_protobuf_MessageOptions *msg, bool value) { const upb_MiniTableField field = {1, 1, 1, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_MessageOptions_set_no_standard_descriptor_accessor(google_protobuf_MessageOptions *msg, bool value) { const upb_MiniTableField field = {2, 2, 2, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_MessageOptions_set_deprecated(google_protobuf_MessageOptions *msg, bool value) { const upb_MiniTableField field = {3, 3, 3, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_MessageOptions_set_map_entry(google_protobuf_MessageOptions *msg, bool value) { const upb_MiniTableField field = {7, 4, 4, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_MessageOptions_set_deprecated_legacy_json_field_conflicts(google_protobuf_MessageOptions *msg, bool value) { const upb_MiniTableField field = {11, 5, 5, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_MessageOptions_set_features(google_protobuf_MessageOptions *msg, google_protobuf_FeatureSet* value) { const upb_MiniTableField field = {12, 8, 6, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE struct google_protobuf_FeatureSet* google_protobuf_MessageOptions_mutable_features(google_protobuf_MessageOptions* msg, upb_Arena* arena) { struct google_protobuf_FeatureSet* sub = (struct google_protobuf_FeatureSet*)google_protobuf_MessageOptions_features(msg); @@ -7972,7 +8131,7 @@ UPB_INLINE struct google_protobuf_FeatureSet* google_protobuf_MessageOptions_mut } UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_MessageOptions_mutable_uninterpreted_option(google_protobuf_MessageOptions* msg, size_t* size) { upb_MiniTableField field = {999, UPB_SIZE(12, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetMutableArray(msg, &field); + upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_UninterpretedOption**)_upb_array_ptr(arr); @@ -7983,11 +8142,13 @@ UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_MessageOptions_ } UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_MessageOptions_resize_uninterpreted_option(google_protobuf_MessageOptions* msg, size_t size, upb_Arena* arena) { upb_MiniTableField field = {999, UPB_SIZE(12, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return (google_protobuf_UninterpretedOption**)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); + return (google_protobuf_UninterpretedOption**)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg), + &field, size, arena); } UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_MessageOptions_add_uninterpreted_option(google_protobuf_MessageOptions* msg, upb_Arena* arena) { upb_MiniTableField field = {999, UPB_SIZE(12, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray( + UPB_UPCAST(msg), &field, arena); if (!arr || !_upb_Array_ResizeUninitialized( arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; @@ -8007,7 +8168,8 @@ UPB_INLINE google_protobuf_FieldOptions* google_protobuf_FieldOptions_new(upb_Ar UPB_INLINE google_protobuf_FieldOptions* google_protobuf_FieldOptions_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_FieldOptions* ret = google_protobuf_FieldOptions_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__FieldOptions_msg_init, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__FieldOptions_msg_init, NULL, 0, arena) != + kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -8017,165 +8179,174 @@ UPB_INLINE google_protobuf_FieldOptions* google_protobuf_FieldOptions_parse_ex(c int options, upb_Arena* arena) { google_protobuf_FieldOptions* ret = google_protobuf_FieldOptions_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__FieldOptions_msg_init, extreg, options, arena) != - kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__FieldOptions_msg_init, extreg, options, + arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_FieldOptions_serialize(const google_protobuf_FieldOptions* msg, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__FieldOptions_msg_init, 0, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__FieldOptions_msg_init, 0, arena, &ptr, len); return ptr; } UPB_INLINE char* google_protobuf_FieldOptions_serialize_ex(const google_protobuf_FieldOptions* msg, int options, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__FieldOptions_msg_init, options, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__FieldOptions_msg_init, options, arena, &ptr, len); return ptr; } UPB_INLINE void google_protobuf_FieldOptions_clear_ctype(google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {1, 4, 1, 3, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_FieldOptions_ctype(const google_protobuf_FieldOptions* msg) { int32_t default_val = 0; int32_t ret; const upb_MiniTableField field = {1, 4, 1, 3, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FieldOptions_has_ctype(const google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {1, 4, 1, 3, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldOptions_clear_packed(google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {2, 8, 2, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_FieldOptions_packed(const google_protobuf_FieldOptions* msg) { bool default_val = false; bool ret; const upb_MiniTableField field = {2, 8, 2, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FieldOptions_has_packed(const google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {2, 8, 2, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldOptions_clear_deprecated(google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {3, 9, 3, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_FieldOptions_deprecated(const google_protobuf_FieldOptions* msg) { bool default_val = false; bool ret; const upb_MiniTableField field = {3, 9, 3, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FieldOptions_has_deprecated(const google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {3, 9, 3, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldOptions_clear_lazy(google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {5, 10, 4, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_FieldOptions_lazy(const google_protobuf_FieldOptions* msg) { bool default_val = false; bool ret; const upb_MiniTableField field = {5, 10, 4, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FieldOptions_has_lazy(const google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {5, 10, 4, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldOptions_clear_jstype(google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {6, 12, 5, 4, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_FieldOptions_jstype(const google_protobuf_FieldOptions* msg) { int32_t default_val = 0; int32_t ret; const upb_MiniTableField field = {6, 12, 5, 4, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FieldOptions_has_jstype(const google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {6, 12, 5, 4, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldOptions_clear_weak(google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {10, 16, 6, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_FieldOptions_weak(const google_protobuf_FieldOptions* msg) { bool default_val = false; bool ret; const upb_MiniTableField field = {10, 16, 6, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FieldOptions_has_weak(const google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {10, 16, 6, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldOptions_clear_unverified_lazy(google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {15, 17, 7, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_FieldOptions_unverified_lazy(const google_protobuf_FieldOptions* msg) { bool default_val = false; bool ret; const upb_MiniTableField field = {15, 17, 7, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FieldOptions_has_unverified_lazy(const google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {15, 17, 7, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldOptions_clear_debug_redact(google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {16, 18, 8, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_FieldOptions_debug_redact(const google_protobuf_FieldOptions* msg) { bool default_val = false; bool ret; const upb_MiniTableField field = {16, 18, 8, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FieldOptions_has_debug_redact(const google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {16, 18, 8, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldOptions_clear_retention(google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {17, 20, 9, 5, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_FieldOptions_retention(const google_protobuf_FieldOptions* msg) { int32_t default_val = 0; int32_t ret; const upb_MiniTableField field = {17, 20, 9, 5, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FieldOptions_has_retention(const google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {17, 20, 9, 5, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldOptions_clear_targets(google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {19, 24, 0, 6, 14, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t const* google_protobuf_FieldOptions_targets(const google_protobuf_FieldOptions* msg, size_t* size) { const upb_MiniTableField field = {19, 24, 0, 6, 14, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (int32_t const*)_upb_array_constptr(arr); @@ -8186,16 +8357,16 @@ UPB_INLINE int32_t const* google_protobuf_FieldOptions_targets(const google_prot } UPB_INLINE const upb_Array* _google_protobuf_FieldOptions_targets_upb_array(const google_protobuf_FieldOptions* msg, size_t* size) { const upb_MiniTableField field = {19, 24, 0, 6, 14, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } -UPB_INLINE upb_Array* _google_protobuf_FieldOptions_targets_mutable_upb_array(const google_protobuf_FieldOptions* msg, size_t* size, upb_Arena* arena) { +UPB_INLINE upb_Array* _google_protobuf_FieldOptions_targets_mutable_upb_array(google_protobuf_FieldOptions* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = {19, 24, 0, 6, 14, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - (upb_Message*)msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), + &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -8203,11 +8374,11 @@ UPB_INLINE upb_Array* _google_protobuf_FieldOptions_targets_mutable_upb_array(co } UPB_INLINE void google_protobuf_FieldOptions_clear_edition_defaults(google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {20, UPB_SIZE(28, 32), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_FieldOptions_EditionDefault* const* google_protobuf_FieldOptions_edition_defaults(const google_protobuf_FieldOptions* msg, size_t* size) { const upb_MiniTableField field = {20, UPB_SIZE(28, 32), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_FieldOptions_EditionDefault* const*)_upb_array_constptr(arr); @@ -8218,16 +8389,16 @@ UPB_INLINE const google_protobuf_FieldOptions_EditionDefault* const* google_prot } UPB_INLINE const upb_Array* _google_protobuf_FieldOptions_edition_defaults_upb_array(const google_protobuf_FieldOptions* msg, size_t* size) { const upb_MiniTableField field = {20, UPB_SIZE(28, 32), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } -UPB_INLINE upb_Array* _google_protobuf_FieldOptions_edition_defaults_mutable_upb_array(const google_protobuf_FieldOptions* msg, size_t* size, upb_Arena* arena) { +UPB_INLINE upb_Array* _google_protobuf_FieldOptions_edition_defaults_mutable_upb_array(google_protobuf_FieldOptions* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = {20, UPB_SIZE(28, 32), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - (upb_Message*)msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), + &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -8235,26 +8406,27 @@ UPB_INLINE upb_Array* _google_protobuf_FieldOptions_edition_defaults_mutable_upb } UPB_INLINE void google_protobuf_FieldOptions_clear_features(google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {21, UPB_SIZE(32, 40), 10, 1, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_FeatureSet* google_protobuf_FieldOptions_features(const google_protobuf_FieldOptions* msg) { const google_protobuf_FeatureSet* default_val = NULL; const google_protobuf_FeatureSet* ret; const upb_MiniTableField field = {21, UPB_SIZE(32, 40), 10, 1, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FieldOptions_has_features(const google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {21, UPB_SIZE(32, 40), 10, 1, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldOptions_clear_uninterpreted_option(google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {999, UPB_SIZE(36, 48), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_FieldOptions_uninterpreted_option(const google_protobuf_FieldOptions* msg, size_t* size) { const upb_MiniTableField field = {999, UPB_SIZE(36, 48), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_UninterpretedOption* const*)_upb_array_constptr(arr); @@ -8265,16 +8437,16 @@ UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_Fie } UPB_INLINE const upb_Array* _google_protobuf_FieldOptions_uninterpreted_option_upb_array(const google_protobuf_FieldOptions* msg, size_t* size) { const upb_MiniTableField field = {999, UPB_SIZE(36, 48), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } -UPB_INLINE upb_Array* _google_protobuf_FieldOptions_uninterpreted_option_mutable_upb_array(const google_protobuf_FieldOptions* msg, size_t* size, upb_Arena* arena) { +UPB_INLINE upb_Array* _google_protobuf_FieldOptions_uninterpreted_option_mutable_upb_array(google_protobuf_FieldOptions* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = {999, UPB_SIZE(36, 48), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - (upb_Message*)msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), + &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -8283,43 +8455,43 @@ UPB_INLINE upb_Array* _google_protobuf_FieldOptions_uninterpreted_option_mutable UPB_INLINE void google_protobuf_FieldOptions_set_ctype(google_protobuf_FieldOptions *msg, int32_t value) { const upb_MiniTableField field = {1, 4, 1, 3, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FieldOptions_set_packed(google_protobuf_FieldOptions *msg, bool value) { const upb_MiniTableField field = {2, 8, 2, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FieldOptions_set_deprecated(google_protobuf_FieldOptions *msg, bool value) { const upb_MiniTableField field = {3, 9, 3, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FieldOptions_set_lazy(google_protobuf_FieldOptions *msg, bool value) { const upb_MiniTableField field = {5, 10, 4, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FieldOptions_set_jstype(google_protobuf_FieldOptions *msg, int32_t value) { const upb_MiniTableField field = {6, 12, 5, 4, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FieldOptions_set_weak(google_protobuf_FieldOptions *msg, bool value) { const upb_MiniTableField field = {10, 16, 6, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FieldOptions_set_unverified_lazy(google_protobuf_FieldOptions *msg, bool value) { const upb_MiniTableField field = {15, 17, 7, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FieldOptions_set_debug_redact(google_protobuf_FieldOptions *msg, bool value) { const upb_MiniTableField field = {16, 18, 8, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FieldOptions_set_retention(google_protobuf_FieldOptions *msg, int32_t value) { const upb_MiniTableField field = {17, 20, 9, 5, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE int32_t* google_protobuf_FieldOptions_mutable_targets(google_protobuf_FieldOptions* msg, size_t* size) { upb_MiniTableField field = {19, 24, 0, 6, 14, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetMutableArray(msg, &field); + upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (int32_t*)_upb_array_ptr(arr); @@ -8330,11 +8502,13 @@ UPB_INLINE int32_t* google_protobuf_FieldOptions_mutable_targets(google_protobuf } UPB_INLINE int32_t* google_protobuf_FieldOptions_resize_targets(google_protobuf_FieldOptions* msg, size_t size, upb_Arena* arena) { upb_MiniTableField field = {19, 24, 0, 6, 14, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return (int32_t*)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); + return (int32_t*)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg), + &field, size, arena); } UPB_INLINE bool google_protobuf_FieldOptions_add_targets(google_protobuf_FieldOptions* msg, int32_t val, upb_Arena* arena) { upb_MiniTableField field = {19, 24, 0, 6, 14, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray( + UPB_UPCAST(msg), &field, arena); if (!arr || !_upb_Array_ResizeUninitialized( arr, arr->UPB_PRIVATE(size) + 1, arena)) { return false; @@ -8345,7 +8519,7 @@ UPB_INLINE bool google_protobuf_FieldOptions_add_targets(google_protobuf_FieldOp } UPB_INLINE google_protobuf_FieldOptions_EditionDefault** google_protobuf_FieldOptions_mutable_edition_defaults(google_protobuf_FieldOptions* msg, size_t* size) { upb_MiniTableField field = {20, UPB_SIZE(28, 32), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetMutableArray(msg, &field); + upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_FieldOptions_EditionDefault**)_upb_array_ptr(arr); @@ -8356,11 +8530,13 @@ UPB_INLINE google_protobuf_FieldOptions_EditionDefault** google_protobuf_FieldOp } UPB_INLINE google_protobuf_FieldOptions_EditionDefault** google_protobuf_FieldOptions_resize_edition_defaults(google_protobuf_FieldOptions* msg, size_t size, upb_Arena* arena) { upb_MiniTableField field = {20, UPB_SIZE(28, 32), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return (google_protobuf_FieldOptions_EditionDefault**)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); + return (google_protobuf_FieldOptions_EditionDefault**)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg), + &field, size, arena); } UPB_INLINE struct google_protobuf_FieldOptions_EditionDefault* google_protobuf_FieldOptions_add_edition_defaults(google_protobuf_FieldOptions* msg, upb_Arena* arena) { upb_MiniTableField field = {20, UPB_SIZE(28, 32), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray( + UPB_UPCAST(msg), &field, arena); if (!arr || !_upb_Array_ResizeUninitialized( arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; @@ -8373,7 +8549,7 @@ UPB_INLINE struct google_protobuf_FieldOptions_EditionDefault* google_protobuf_F } UPB_INLINE void google_protobuf_FieldOptions_set_features(google_protobuf_FieldOptions *msg, google_protobuf_FeatureSet* value) { const upb_MiniTableField field = {21, UPB_SIZE(32, 40), 10, 1, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE struct google_protobuf_FeatureSet* google_protobuf_FieldOptions_mutable_features(google_protobuf_FieldOptions* msg, upb_Arena* arena) { struct google_protobuf_FeatureSet* sub = (struct google_protobuf_FeatureSet*)google_protobuf_FieldOptions_features(msg); @@ -8385,7 +8561,7 @@ UPB_INLINE struct google_protobuf_FeatureSet* google_protobuf_FieldOptions_mutab } UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_FieldOptions_mutable_uninterpreted_option(google_protobuf_FieldOptions* msg, size_t* size) { upb_MiniTableField field = {999, UPB_SIZE(36, 48), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetMutableArray(msg, &field); + upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_UninterpretedOption**)_upb_array_ptr(arr); @@ -8396,11 +8572,13 @@ UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_FieldOptions_mu } UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_FieldOptions_resize_uninterpreted_option(google_protobuf_FieldOptions* msg, size_t size, upb_Arena* arena) { upb_MiniTableField field = {999, UPB_SIZE(36, 48), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return (google_protobuf_UninterpretedOption**)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); + return (google_protobuf_UninterpretedOption**)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg), + &field, size, arena); } UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_FieldOptions_add_uninterpreted_option(google_protobuf_FieldOptions* msg, upb_Arena* arena) { upb_MiniTableField field = {999, UPB_SIZE(36, 48), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray( + UPB_UPCAST(msg), &field, arena); if (!arr || !_upb_Array_ResizeUninitialized( arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; @@ -8420,7 +8598,8 @@ UPB_INLINE google_protobuf_FieldOptions_EditionDefault* google_protobuf_FieldOpt UPB_INLINE google_protobuf_FieldOptions_EditionDefault* google_protobuf_FieldOptions_EditionDefault_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_FieldOptions_EditionDefault* ret = google_protobuf_FieldOptions_EditionDefault_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__FieldOptions__EditionDefault_msg_init, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__FieldOptions__EditionDefault_msg_init, NULL, 0, arena) != + kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -8430,61 +8609,63 @@ UPB_INLINE google_protobuf_FieldOptions_EditionDefault* google_protobuf_FieldOpt int options, upb_Arena* arena) { google_protobuf_FieldOptions_EditionDefault* ret = google_protobuf_FieldOptions_EditionDefault_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__FieldOptions__EditionDefault_msg_init, extreg, options, arena) != - kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__FieldOptions__EditionDefault_msg_init, extreg, options, + arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_FieldOptions_EditionDefault_serialize(const google_protobuf_FieldOptions_EditionDefault* msg, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__FieldOptions__EditionDefault_msg_init, 0, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__FieldOptions__EditionDefault_msg_init, 0, arena, &ptr, len); return ptr; } UPB_INLINE char* google_protobuf_FieldOptions_EditionDefault_serialize_ex(const google_protobuf_FieldOptions_EditionDefault* msg, int options, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__FieldOptions__EditionDefault_msg_init, options, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__FieldOptions__EditionDefault_msg_init, options, arena, &ptr, len); return ptr; } UPB_INLINE void google_protobuf_FieldOptions_EditionDefault_clear_value(google_protobuf_FieldOptions_EditionDefault* msg) { const upb_MiniTableField field = {2, 8, 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_FieldOptions_EditionDefault_value(const google_protobuf_FieldOptions_EditionDefault* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; const upb_MiniTableField field = {2, 8, 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FieldOptions_EditionDefault_has_value(const google_protobuf_FieldOptions_EditionDefault* msg) { const upb_MiniTableField field = {2, 8, 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldOptions_EditionDefault_clear_edition(google_protobuf_FieldOptions_EditionDefault* msg) { const upb_MiniTableField field = {3, 4, 2, 0, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_FieldOptions_EditionDefault_edition(const google_protobuf_FieldOptions_EditionDefault* msg) { int32_t default_val = 0; int32_t ret; const upb_MiniTableField field = {3, 4, 2, 0, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FieldOptions_EditionDefault_has_edition(const google_protobuf_FieldOptions_EditionDefault* msg) { const upb_MiniTableField field = {3, 4, 2, 0, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldOptions_EditionDefault_set_value(google_protobuf_FieldOptions_EditionDefault *msg, upb_StringView value) { const upb_MiniTableField field = {2, 8, 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FieldOptions_EditionDefault_set_edition(google_protobuf_FieldOptions_EditionDefault *msg, int32_t value) { const upb_MiniTableField field = {3, 4, 2, 0, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } /* google.protobuf.OneofOptions */ @@ -8495,7 +8676,8 @@ UPB_INLINE google_protobuf_OneofOptions* google_protobuf_OneofOptions_new(upb_Ar UPB_INLINE google_protobuf_OneofOptions* google_protobuf_OneofOptions_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_OneofOptions* ret = google_protobuf_OneofOptions_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__OneofOptions_msg_init, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__OneofOptions_msg_init, NULL, 0, arena) != + kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -8505,45 +8687,46 @@ UPB_INLINE google_protobuf_OneofOptions* google_protobuf_OneofOptions_parse_ex(c int options, upb_Arena* arena) { google_protobuf_OneofOptions* ret = google_protobuf_OneofOptions_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__OneofOptions_msg_init, extreg, options, arena) != - kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__OneofOptions_msg_init, extreg, options, + arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_OneofOptions_serialize(const google_protobuf_OneofOptions* msg, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__OneofOptions_msg_init, 0, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__OneofOptions_msg_init, 0, arena, &ptr, len); return ptr; } UPB_INLINE char* google_protobuf_OneofOptions_serialize_ex(const google_protobuf_OneofOptions* msg, int options, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__OneofOptions_msg_init, options, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__OneofOptions_msg_init, options, arena, &ptr, len); return ptr; } UPB_INLINE void google_protobuf_OneofOptions_clear_features(google_protobuf_OneofOptions* msg) { const upb_MiniTableField field = {1, UPB_SIZE(4, 8), 1, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_FeatureSet* google_protobuf_OneofOptions_features(const google_protobuf_OneofOptions* msg) { const google_protobuf_FeatureSet* default_val = NULL; const google_protobuf_FeatureSet* ret; const upb_MiniTableField field = {1, UPB_SIZE(4, 8), 1, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_OneofOptions_has_features(const google_protobuf_OneofOptions* msg) { const upb_MiniTableField field = {1, UPB_SIZE(4, 8), 1, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_OneofOptions_clear_uninterpreted_option(google_protobuf_OneofOptions* msg) { const upb_MiniTableField field = {999, UPB_SIZE(8, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_OneofOptions_uninterpreted_option(const google_protobuf_OneofOptions* msg, size_t* size) { const upb_MiniTableField field = {999, UPB_SIZE(8, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_UninterpretedOption* const*)_upb_array_constptr(arr); @@ -8554,16 +8737,16 @@ UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_One } UPB_INLINE const upb_Array* _google_protobuf_OneofOptions_uninterpreted_option_upb_array(const google_protobuf_OneofOptions* msg, size_t* size) { const upb_MiniTableField field = {999, UPB_SIZE(8, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } -UPB_INLINE upb_Array* _google_protobuf_OneofOptions_uninterpreted_option_mutable_upb_array(const google_protobuf_OneofOptions* msg, size_t* size, upb_Arena* arena) { +UPB_INLINE upb_Array* _google_protobuf_OneofOptions_uninterpreted_option_mutable_upb_array(google_protobuf_OneofOptions* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = {999, UPB_SIZE(8, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - (upb_Message*)msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), + &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -8572,7 +8755,7 @@ UPB_INLINE upb_Array* _google_protobuf_OneofOptions_uninterpreted_option_mutable UPB_INLINE void google_protobuf_OneofOptions_set_features(google_protobuf_OneofOptions *msg, google_protobuf_FeatureSet* value) { const upb_MiniTableField field = {1, UPB_SIZE(4, 8), 1, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE struct google_protobuf_FeatureSet* google_protobuf_OneofOptions_mutable_features(google_protobuf_OneofOptions* msg, upb_Arena* arena) { struct google_protobuf_FeatureSet* sub = (struct google_protobuf_FeatureSet*)google_protobuf_OneofOptions_features(msg); @@ -8584,7 +8767,7 @@ UPB_INLINE struct google_protobuf_FeatureSet* google_protobuf_OneofOptions_mutab } UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_OneofOptions_mutable_uninterpreted_option(google_protobuf_OneofOptions* msg, size_t* size) { upb_MiniTableField field = {999, UPB_SIZE(8, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetMutableArray(msg, &field); + upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_UninterpretedOption**)_upb_array_ptr(arr); @@ -8595,11 +8778,13 @@ UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_OneofOptions_mu } UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_OneofOptions_resize_uninterpreted_option(google_protobuf_OneofOptions* msg, size_t size, upb_Arena* arena) { upb_MiniTableField field = {999, UPB_SIZE(8, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return (google_protobuf_UninterpretedOption**)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); + return (google_protobuf_UninterpretedOption**)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg), + &field, size, arena); } UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_OneofOptions_add_uninterpreted_option(google_protobuf_OneofOptions* msg, upb_Arena* arena) { upb_MiniTableField field = {999, UPB_SIZE(8, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray( + UPB_UPCAST(msg), &field, arena); if (!arr || !_upb_Array_ResizeUninitialized( arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; @@ -8619,7 +8804,8 @@ UPB_INLINE google_protobuf_EnumOptions* google_protobuf_EnumOptions_new(upb_Aren UPB_INLINE google_protobuf_EnumOptions* google_protobuf_EnumOptions_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_EnumOptions* ret = google_protobuf_EnumOptions_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__EnumOptions_msg_init, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__EnumOptions_msg_init, NULL, 0, arena) != + kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -8629,90 +8815,94 @@ UPB_INLINE google_protobuf_EnumOptions* google_protobuf_EnumOptions_parse_ex(con int options, upb_Arena* arena) { google_protobuf_EnumOptions* ret = google_protobuf_EnumOptions_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__EnumOptions_msg_init, extreg, options, arena) != - kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__EnumOptions_msg_init, extreg, options, + arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_EnumOptions_serialize(const google_protobuf_EnumOptions* msg, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__EnumOptions_msg_init, 0, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__EnumOptions_msg_init, 0, arena, &ptr, len); return ptr; } UPB_INLINE char* google_protobuf_EnumOptions_serialize_ex(const google_protobuf_EnumOptions* msg, int options, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__EnumOptions_msg_init, options, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__EnumOptions_msg_init, options, arena, &ptr, len); return ptr; } UPB_INLINE void google_protobuf_EnumOptions_clear_allow_alias(google_protobuf_EnumOptions* msg) { const upb_MiniTableField field = {2, 1, 1, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_EnumOptions_allow_alias(const google_protobuf_EnumOptions* msg) { bool default_val = false; bool ret; const upb_MiniTableField field = {2, 1, 1, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_EnumOptions_has_allow_alias(const google_protobuf_EnumOptions* msg) { const upb_MiniTableField field = {2, 1, 1, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_EnumOptions_clear_deprecated(google_protobuf_EnumOptions* msg) { const upb_MiniTableField field = {3, 2, 2, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_EnumOptions_deprecated(const google_protobuf_EnumOptions* msg) { bool default_val = false; bool ret; const upb_MiniTableField field = {3, 2, 2, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_EnumOptions_has_deprecated(const google_protobuf_EnumOptions* msg) { const upb_MiniTableField field = {3, 2, 2, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_EnumOptions_clear_deprecated_legacy_json_field_conflicts(google_protobuf_EnumOptions* msg) { const upb_MiniTableField field = {6, 3, 3, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_EnumOptions_deprecated_legacy_json_field_conflicts(const google_protobuf_EnumOptions* msg) { bool default_val = false; bool ret; const upb_MiniTableField field = {6, 3, 3, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_EnumOptions_has_deprecated_legacy_json_field_conflicts(const google_protobuf_EnumOptions* msg) { const upb_MiniTableField field = {6, 3, 3, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_EnumOptions_clear_features(google_protobuf_EnumOptions* msg) { const upb_MiniTableField field = {7, UPB_SIZE(4, 8), 4, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_FeatureSet* google_protobuf_EnumOptions_features(const google_protobuf_EnumOptions* msg) { const google_protobuf_FeatureSet* default_val = NULL; const google_protobuf_FeatureSet* ret; const upb_MiniTableField field = {7, UPB_SIZE(4, 8), 4, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_EnumOptions_has_features(const google_protobuf_EnumOptions* msg) { const upb_MiniTableField field = {7, UPB_SIZE(4, 8), 4, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_EnumOptions_clear_uninterpreted_option(google_protobuf_EnumOptions* msg) { const upb_MiniTableField field = {999, UPB_SIZE(8, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_EnumOptions_uninterpreted_option(const google_protobuf_EnumOptions* msg, size_t* size) { const upb_MiniTableField field = {999, UPB_SIZE(8, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_UninterpretedOption* const*)_upb_array_constptr(arr); @@ -8723,16 +8913,16 @@ UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_Enu } UPB_INLINE const upb_Array* _google_protobuf_EnumOptions_uninterpreted_option_upb_array(const google_protobuf_EnumOptions* msg, size_t* size) { const upb_MiniTableField field = {999, UPB_SIZE(8, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } -UPB_INLINE upb_Array* _google_protobuf_EnumOptions_uninterpreted_option_mutable_upb_array(const google_protobuf_EnumOptions* msg, size_t* size, upb_Arena* arena) { +UPB_INLINE upb_Array* _google_protobuf_EnumOptions_uninterpreted_option_mutable_upb_array(google_protobuf_EnumOptions* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = {999, UPB_SIZE(8, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - (upb_Message*)msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), + &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -8741,19 +8931,19 @@ UPB_INLINE upb_Array* _google_protobuf_EnumOptions_uninterpreted_option_mutable_ UPB_INLINE void google_protobuf_EnumOptions_set_allow_alias(google_protobuf_EnumOptions *msg, bool value) { const upb_MiniTableField field = {2, 1, 1, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_EnumOptions_set_deprecated(google_protobuf_EnumOptions *msg, bool value) { const upb_MiniTableField field = {3, 2, 2, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_EnumOptions_set_deprecated_legacy_json_field_conflicts(google_protobuf_EnumOptions *msg, bool value) { const upb_MiniTableField field = {6, 3, 3, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_EnumOptions_set_features(google_protobuf_EnumOptions *msg, google_protobuf_FeatureSet* value) { const upb_MiniTableField field = {7, UPB_SIZE(4, 8), 4, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE struct google_protobuf_FeatureSet* google_protobuf_EnumOptions_mutable_features(google_protobuf_EnumOptions* msg, upb_Arena* arena) { struct google_protobuf_FeatureSet* sub = (struct google_protobuf_FeatureSet*)google_protobuf_EnumOptions_features(msg); @@ -8765,7 +8955,7 @@ UPB_INLINE struct google_protobuf_FeatureSet* google_protobuf_EnumOptions_mutabl } UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_EnumOptions_mutable_uninterpreted_option(google_protobuf_EnumOptions* msg, size_t* size) { upb_MiniTableField field = {999, UPB_SIZE(8, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetMutableArray(msg, &field); + upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_UninterpretedOption**)_upb_array_ptr(arr); @@ -8776,11 +8966,13 @@ UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_EnumOptions_mut } UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_EnumOptions_resize_uninterpreted_option(google_protobuf_EnumOptions* msg, size_t size, upb_Arena* arena) { upb_MiniTableField field = {999, UPB_SIZE(8, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return (google_protobuf_UninterpretedOption**)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); + return (google_protobuf_UninterpretedOption**)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg), + &field, size, arena); } UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_EnumOptions_add_uninterpreted_option(google_protobuf_EnumOptions* msg, upb_Arena* arena) { upb_MiniTableField field = {999, UPB_SIZE(8, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray( + UPB_UPCAST(msg), &field, arena); if (!arr || !_upb_Array_ResizeUninitialized( arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; @@ -8800,7 +8992,8 @@ UPB_INLINE google_protobuf_EnumValueOptions* google_protobuf_EnumValueOptions_ne UPB_INLINE google_protobuf_EnumValueOptions* google_protobuf_EnumValueOptions_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_EnumValueOptions* ret = google_protobuf_EnumValueOptions_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__EnumValueOptions_msg_init, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__EnumValueOptions_msg_init, NULL, 0, arena) != + kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -8810,75 +9003,78 @@ UPB_INLINE google_protobuf_EnumValueOptions* google_protobuf_EnumValueOptions_pa int options, upb_Arena* arena) { google_protobuf_EnumValueOptions* ret = google_protobuf_EnumValueOptions_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__EnumValueOptions_msg_init, extreg, options, arena) != - kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__EnumValueOptions_msg_init, extreg, options, + arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_EnumValueOptions_serialize(const google_protobuf_EnumValueOptions* msg, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__EnumValueOptions_msg_init, 0, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__EnumValueOptions_msg_init, 0, arena, &ptr, len); return ptr; } UPB_INLINE char* google_protobuf_EnumValueOptions_serialize_ex(const google_protobuf_EnumValueOptions* msg, int options, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__EnumValueOptions_msg_init, options, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__EnumValueOptions_msg_init, options, arena, &ptr, len); return ptr; } UPB_INLINE void google_protobuf_EnumValueOptions_clear_deprecated(google_protobuf_EnumValueOptions* msg) { const upb_MiniTableField field = {1, 1, 1, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_EnumValueOptions_deprecated(const google_protobuf_EnumValueOptions* msg) { bool default_val = false; bool ret; const upb_MiniTableField field = {1, 1, 1, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_EnumValueOptions_has_deprecated(const google_protobuf_EnumValueOptions* msg) { const upb_MiniTableField field = {1, 1, 1, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_EnumValueOptions_clear_features(google_protobuf_EnumValueOptions* msg) { const upb_MiniTableField field = {2, UPB_SIZE(4, 8), 2, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_FeatureSet* google_protobuf_EnumValueOptions_features(const google_protobuf_EnumValueOptions* msg) { const google_protobuf_FeatureSet* default_val = NULL; const google_protobuf_FeatureSet* ret; const upb_MiniTableField field = {2, UPB_SIZE(4, 8), 2, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_EnumValueOptions_has_features(const google_protobuf_EnumValueOptions* msg) { const upb_MiniTableField field = {2, UPB_SIZE(4, 8), 2, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_EnumValueOptions_clear_debug_redact(google_protobuf_EnumValueOptions* msg) { const upb_MiniTableField field = {3, UPB_SIZE(8, 2), 3, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_EnumValueOptions_debug_redact(const google_protobuf_EnumValueOptions* msg) { bool default_val = false; bool ret; const upb_MiniTableField field = {3, UPB_SIZE(8, 2), 3, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_EnumValueOptions_has_debug_redact(const google_protobuf_EnumValueOptions* msg) { const upb_MiniTableField field = {3, UPB_SIZE(8, 2), 3, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_EnumValueOptions_clear_uninterpreted_option(google_protobuf_EnumValueOptions* msg) { const upb_MiniTableField field = {999, UPB_SIZE(12, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_EnumValueOptions_uninterpreted_option(const google_protobuf_EnumValueOptions* msg, size_t* size) { const upb_MiniTableField field = {999, UPB_SIZE(12, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_UninterpretedOption* const*)_upb_array_constptr(arr); @@ -8889,16 +9085,16 @@ UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_Enu } UPB_INLINE const upb_Array* _google_protobuf_EnumValueOptions_uninterpreted_option_upb_array(const google_protobuf_EnumValueOptions* msg, size_t* size) { const upb_MiniTableField field = {999, UPB_SIZE(12, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } -UPB_INLINE upb_Array* _google_protobuf_EnumValueOptions_uninterpreted_option_mutable_upb_array(const google_protobuf_EnumValueOptions* msg, size_t* size, upb_Arena* arena) { +UPB_INLINE upb_Array* _google_protobuf_EnumValueOptions_uninterpreted_option_mutable_upb_array(google_protobuf_EnumValueOptions* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = {999, UPB_SIZE(12, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - (upb_Message*)msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), + &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -8907,11 +9103,11 @@ UPB_INLINE upb_Array* _google_protobuf_EnumValueOptions_uninterpreted_option_mut UPB_INLINE void google_protobuf_EnumValueOptions_set_deprecated(google_protobuf_EnumValueOptions *msg, bool value) { const upb_MiniTableField field = {1, 1, 1, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_EnumValueOptions_set_features(google_protobuf_EnumValueOptions *msg, google_protobuf_FeatureSet* value) { const upb_MiniTableField field = {2, UPB_SIZE(4, 8), 2, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE struct google_protobuf_FeatureSet* google_protobuf_EnumValueOptions_mutable_features(google_protobuf_EnumValueOptions* msg, upb_Arena* arena) { struct google_protobuf_FeatureSet* sub = (struct google_protobuf_FeatureSet*)google_protobuf_EnumValueOptions_features(msg); @@ -8923,11 +9119,11 @@ UPB_INLINE struct google_protobuf_FeatureSet* google_protobuf_EnumValueOptions_m } UPB_INLINE void google_protobuf_EnumValueOptions_set_debug_redact(google_protobuf_EnumValueOptions *msg, bool value) { const upb_MiniTableField field = {3, UPB_SIZE(8, 2), 3, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_EnumValueOptions_mutable_uninterpreted_option(google_protobuf_EnumValueOptions* msg, size_t* size) { upb_MiniTableField field = {999, UPB_SIZE(12, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetMutableArray(msg, &field); + upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_UninterpretedOption**)_upb_array_ptr(arr); @@ -8938,11 +9134,13 @@ UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_EnumValueOption } UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_EnumValueOptions_resize_uninterpreted_option(google_protobuf_EnumValueOptions* msg, size_t size, upb_Arena* arena) { upb_MiniTableField field = {999, UPB_SIZE(12, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return (google_protobuf_UninterpretedOption**)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); + return (google_protobuf_UninterpretedOption**)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg), + &field, size, arena); } UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_EnumValueOptions_add_uninterpreted_option(google_protobuf_EnumValueOptions* msg, upb_Arena* arena) { upb_MiniTableField field = {999, UPB_SIZE(12, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray( + UPB_UPCAST(msg), &field, arena); if (!arr || !_upb_Array_ResizeUninitialized( arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; @@ -8962,7 +9160,8 @@ UPB_INLINE google_protobuf_ServiceOptions* google_protobuf_ServiceOptions_new(up UPB_INLINE google_protobuf_ServiceOptions* google_protobuf_ServiceOptions_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_ServiceOptions* ret = google_protobuf_ServiceOptions_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__ServiceOptions_msg_init, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__ServiceOptions_msg_init, NULL, 0, arena) != + kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -8972,60 +9171,62 @@ UPB_INLINE google_protobuf_ServiceOptions* google_protobuf_ServiceOptions_parse_ int options, upb_Arena* arena) { google_protobuf_ServiceOptions* ret = google_protobuf_ServiceOptions_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__ServiceOptions_msg_init, extreg, options, arena) != - kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__ServiceOptions_msg_init, extreg, options, + arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_ServiceOptions_serialize(const google_protobuf_ServiceOptions* msg, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__ServiceOptions_msg_init, 0, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__ServiceOptions_msg_init, 0, arena, &ptr, len); return ptr; } UPB_INLINE char* google_protobuf_ServiceOptions_serialize_ex(const google_protobuf_ServiceOptions* msg, int options, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__ServiceOptions_msg_init, options, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__ServiceOptions_msg_init, options, arena, &ptr, len); return ptr; } UPB_INLINE void google_protobuf_ServiceOptions_clear_deprecated(google_protobuf_ServiceOptions* msg) { const upb_MiniTableField field = {33, 1, 1, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_ServiceOptions_deprecated(const google_protobuf_ServiceOptions* msg) { bool default_val = false; bool ret; const upb_MiniTableField field = {33, 1, 1, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_ServiceOptions_has_deprecated(const google_protobuf_ServiceOptions* msg) { const upb_MiniTableField field = {33, 1, 1, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_ServiceOptions_clear_features(google_protobuf_ServiceOptions* msg) { const upb_MiniTableField field = {34, UPB_SIZE(4, 8), 2, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_FeatureSet* google_protobuf_ServiceOptions_features(const google_protobuf_ServiceOptions* msg) { const google_protobuf_FeatureSet* default_val = NULL; const google_protobuf_FeatureSet* ret; const upb_MiniTableField field = {34, UPB_SIZE(4, 8), 2, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_ServiceOptions_has_features(const google_protobuf_ServiceOptions* msg) { const upb_MiniTableField field = {34, UPB_SIZE(4, 8), 2, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_ServiceOptions_clear_uninterpreted_option(google_protobuf_ServiceOptions* msg) { const upb_MiniTableField field = {999, UPB_SIZE(8, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_ServiceOptions_uninterpreted_option(const google_protobuf_ServiceOptions* msg, size_t* size) { const upb_MiniTableField field = {999, UPB_SIZE(8, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_UninterpretedOption* const*)_upb_array_constptr(arr); @@ -9036,16 +9237,16 @@ UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_Ser } UPB_INLINE const upb_Array* _google_protobuf_ServiceOptions_uninterpreted_option_upb_array(const google_protobuf_ServiceOptions* msg, size_t* size) { const upb_MiniTableField field = {999, UPB_SIZE(8, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } -UPB_INLINE upb_Array* _google_protobuf_ServiceOptions_uninterpreted_option_mutable_upb_array(const google_protobuf_ServiceOptions* msg, size_t* size, upb_Arena* arena) { +UPB_INLINE upb_Array* _google_protobuf_ServiceOptions_uninterpreted_option_mutable_upb_array(google_protobuf_ServiceOptions* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = {999, UPB_SIZE(8, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - (upb_Message*)msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), + &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -9054,11 +9255,11 @@ UPB_INLINE upb_Array* _google_protobuf_ServiceOptions_uninterpreted_option_mutab UPB_INLINE void google_protobuf_ServiceOptions_set_deprecated(google_protobuf_ServiceOptions *msg, bool value) { const upb_MiniTableField field = {33, 1, 1, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_ServiceOptions_set_features(google_protobuf_ServiceOptions *msg, google_protobuf_FeatureSet* value) { const upb_MiniTableField field = {34, UPB_SIZE(4, 8), 2, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE struct google_protobuf_FeatureSet* google_protobuf_ServiceOptions_mutable_features(google_protobuf_ServiceOptions* msg, upb_Arena* arena) { struct google_protobuf_FeatureSet* sub = (struct google_protobuf_FeatureSet*)google_protobuf_ServiceOptions_features(msg); @@ -9070,7 +9271,7 @@ UPB_INLINE struct google_protobuf_FeatureSet* google_protobuf_ServiceOptions_mut } UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_ServiceOptions_mutable_uninterpreted_option(google_protobuf_ServiceOptions* msg, size_t* size) { upb_MiniTableField field = {999, UPB_SIZE(8, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetMutableArray(msg, &field); + upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_UninterpretedOption**)_upb_array_ptr(arr); @@ -9081,11 +9282,13 @@ UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_ServiceOptions_ } UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_ServiceOptions_resize_uninterpreted_option(google_protobuf_ServiceOptions* msg, size_t size, upb_Arena* arena) { upb_MiniTableField field = {999, UPB_SIZE(8, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return (google_protobuf_UninterpretedOption**)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); + return (google_protobuf_UninterpretedOption**)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg), + &field, size, arena); } UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_ServiceOptions_add_uninterpreted_option(google_protobuf_ServiceOptions* msg, upb_Arena* arena) { upb_MiniTableField field = {999, UPB_SIZE(8, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray( + UPB_UPCAST(msg), &field, arena); if (!arr || !_upb_Array_ResizeUninitialized( arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; @@ -9105,7 +9308,8 @@ UPB_INLINE google_protobuf_MethodOptions* google_protobuf_MethodOptions_new(upb_ UPB_INLINE google_protobuf_MethodOptions* google_protobuf_MethodOptions_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_MethodOptions* ret = google_protobuf_MethodOptions_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__MethodOptions_msg_init, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__MethodOptions_msg_init, NULL, 0, arena) != + kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -9115,75 +9319,78 @@ UPB_INLINE google_protobuf_MethodOptions* google_protobuf_MethodOptions_parse_ex int options, upb_Arena* arena) { google_protobuf_MethodOptions* ret = google_protobuf_MethodOptions_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__MethodOptions_msg_init, extreg, options, arena) != - kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__MethodOptions_msg_init, extreg, options, + arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_MethodOptions_serialize(const google_protobuf_MethodOptions* msg, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__MethodOptions_msg_init, 0, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__MethodOptions_msg_init, 0, arena, &ptr, len); return ptr; } UPB_INLINE char* google_protobuf_MethodOptions_serialize_ex(const google_protobuf_MethodOptions* msg, int options, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__MethodOptions_msg_init, options, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__MethodOptions_msg_init, options, arena, &ptr, len); return ptr; } UPB_INLINE void google_protobuf_MethodOptions_clear_deprecated(google_protobuf_MethodOptions* msg) { const upb_MiniTableField field = {33, 1, 1, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_MethodOptions_deprecated(const google_protobuf_MethodOptions* msg) { bool default_val = false; bool ret; const upb_MiniTableField field = {33, 1, 1, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_MethodOptions_has_deprecated(const google_protobuf_MethodOptions* msg) { const upb_MiniTableField field = {33, 1, 1, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_MethodOptions_clear_idempotency_level(google_protobuf_MethodOptions* msg) { const upb_MiniTableField field = {34, 4, 2, 2, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_MethodOptions_idempotency_level(const google_protobuf_MethodOptions* msg) { int32_t default_val = 0; int32_t ret; const upb_MiniTableField field = {34, 4, 2, 2, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_MethodOptions_has_idempotency_level(const google_protobuf_MethodOptions* msg) { const upb_MiniTableField field = {34, 4, 2, 2, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_MethodOptions_clear_features(google_protobuf_MethodOptions* msg) { const upb_MiniTableField field = {35, 8, 3, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_FeatureSet* google_protobuf_MethodOptions_features(const google_protobuf_MethodOptions* msg) { const google_protobuf_FeatureSet* default_val = NULL; const google_protobuf_FeatureSet* ret; const upb_MiniTableField field = {35, 8, 3, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_MethodOptions_has_features(const google_protobuf_MethodOptions* msg) { const upb_MiniTableField field = {35, 8, 3, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_MethodOptions_clear_uninterpreted_option(google_protobuf_MethodOptions* msg) { const upb_MiniTableField field = {999, UPB_SIZE(12, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_MethodOptions_uninterpreted_option(const google_protobuf_MethodOptions* msg, size_t* size) { const upb_MiniTableField field = {999, UPB_SIZE(12, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_UninterpretedOption* const*)_upb_array_constptr(arr); @@ -9194,16 +9401,16 @@ UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_Met } UPB_INLINE const upb_Array* _google_protobuf_MethodOptions_uninterpreted_option_upb_array(const google_protobuf_MethodOptions* msg, size_t* size) { const upb_MiniTableField field = {999, UPB_SIZE(12, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } -UPB_INLINE upb_Array* _google_protobuf_MethodOptions_uninterpreted_option_mutable_upb_array(const google_protobuf_MethodOptions* msg, size_t* size, upb_Arena* arena) { +UPB_INLINE upb_Array* _google_protobuf_MethodOptions_uninterpreted_option_mutable_upb_array(google_protobuf_MethodOptions* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = {999, UPB_SIZE(12, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - (upb_Message*)msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), + &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -9212,15 +9419,15 @@ UPB_INLINE upb_Array* _google_protobuf_MethodOptions_uninterpreted_option_mutabl UPB_INLINE void google_protobuf_MethodOptions_set_deprecated(google_protobuf_MethodOptions *msg, bool value) { const upb_MiniTableField field = {33, 1, 1, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_MethodOptions_set_idempotency_level(google_protobuf_MethodOptions *msg, int32_t value) { const upb_MiniTableField field = {34, 4, 2, 2, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_MethodOptions_set_features(google_protobuf_MethodOptions *msg, google_protobuf_FeatureSet* value) { const upb_MiniTableField field = {35, 8, 3, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE struct google_protobuf_FeatureSet* google_protobuf_MethodOptions_mutable_features(google_protobuf_MethodOptions* msg, upb_Arena* arena) { struct google_protobuf_FeatureSet* sub = (struct google_protobuf_FeatureSet*)google_protobuf_MethodOptions_features(msg); @@ -9232,7 +9439,7 @@ UPB_INLINE struct google_protobuf_FeatureSet* google_protobuf_MethodOptions_muta } UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_MethodOptions_mutable_uninterpreted_option(google_protobuf_MethodOptions* msg, size_t* size) { upb_MiniTableField field = {999, UPB_SIZE(12, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetMutableArray(msg, &field); + upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_UninterpretedOption**)_upb_array_ptr(arr); @@ -9243,11 +9450,13 @@ UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_MethodOptions_m } UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_MethodOptions_resize_uninterpreted_option(google_protobuf_MethodOptions* msg, size_t size, upb_Arena* arena) { upb_MiniTableField field = {999, UPB_SIZE(12, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return (google_protobuf_UninterpretedOption**)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); + return (google_protobuf_UninterpretedOption**)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg), + &field, size, arena); } UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_MethodOptions_add_uninterpreted_option(google_protobuf_MethodOptions* msg, upb_Arena* arena) { upb_MiniTableField field = {999, UPB_SIZE(12, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray( + UPB_UPCAST(msg), &field, arena); if (!arr || !_upb_Array_ResizeUninitialized( arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; @@ -9267,7 +9476,8 @@ UPB_INLINE google_protobuf_UninterpretedOption* google_protobuf_UninterpretedOpt UPB_INLINE google_protobuf_UninterpretedOption* google_protobuf_UninterpretedOption_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_UninterpretedOption* ret = google_protobuf_UninterpretedOption_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__UninterpretedOption_msg_init, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__UninterpretedOption_msg_init, NULL, 0, arena) != + kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -9277,30 +9487,30 @@ UPB_INLINE google_protobuf_UninterpretedOption* google_protobuf_UninterpretedOpt int options, upb_Arena* arena) { google_protobuf_UninterpretedOption* ret = google_protobuf_UninterpretedOption_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__UninterpretedOption_msg_init, extreg, options, arena) != - kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__UninterpretedOption_msg_init, extreg, options, + arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_UninterpretedOption_serialize(const google_protobuf_UninterpretedOption* msg, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__UninterpretedOption_msg_init, 0, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__UninterpretedOption_msg_init, 0, arena, &ptr, len); return ptr; } UPB_INLINE char* google_protobuf_UninterpretedOption_serialize_ex(const google_protobuf_UninterpretedOption* msg, int options, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__UninterpretedOption_msg_init, options, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__UninterpretedOption_msg_init, options, arena, &ptr, len); return ptr; } UPB_INLINE void google_protobuf_UninterpretedOption_clear_name(google_protobuf_UninterpretedOption* msg) { const upb_MiniTableField field = {2, UPB_SIZE(4, 8), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_UninterpretedOption_NamePart* const* google_protobuf_UninterpretedOption_name(const google_protobuf_UninterpretedOption* msg, size_t* size) { const upb_MiniTableField field = {2, UPB_SIZE(4, 8), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_UninterpretedOption_NamePart* const*)_upb_array_constptr(arr); @@ -9311,16 +9521,16 @@ UPB_INLINE const google_protobuf_UninterpretedOption_NamePart* const* google_pro } UPB_INLINE const upb_Array* _google_protobuf_UninterpretedOption_name_upb_array(const google_protobuf_UninterpretedOption* msg, size_t* size) { const upb_MiniTableField field = {2, UPB_SIZE(4, 8), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } -UPB_INLINE upb_Array* _google_protobuf_UninterpretedOption_name_mutable_upb_array(const google_protobuf_UninterpretedOption* msg, size_t* size, upb_Arena* arena) { +UPB_INLINE upb_Array* _google_protobuf_UninterpretedOption_name_mutable_upb_array(google_protobuf_UninterpretedOption* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = {2, UPB_SIZE(4, 8), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - (upb_Message*)msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), + &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -9328,98 +9538,104 @@ UPB_INLINE upb_Array* _google_protobuf_UninterpretedOption_name_mutable_upb_arra } UPB_INLINE void google_protobuf_UninterpretedOption_clear_identifier_value(google_protobuf_UninterpretedOption* msg) { const upb_MiniTableField field = {3, UPB_SIZE(8, 16), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_UninterpretedOption_identifier_value(const google_protobuf_UninterpretedOption* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; const upb_MiniTableField field = {3, UPB_SIZE(8, 16), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_UninterpretedOption_has_identifier_value(const google_protobuf_UninterpretedOption* msg) { const upb_MiniTableField field = {3, UPB_SIZE(8, 16), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_UninterpretedOption_clear_positive_int_value(google_protobuf_UninterpretedOption* msg) { const upb_MiniTableField field = {4, UPB_SIZE(16, 32), 2, kUpb_NoSub, 4, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_8Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE uint64_t google_protobuf_UninterpretedOption_positive_int_value(const google_protobuf_UninterpretedOption* msg) { uint64_t default_val = (uint64_t)0ull; uint64_t ret; const upb_MiniTableField field = {4, UPB_SIZE(16, 32), 2, kUpb_NoSub, 4, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_8Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_UninterpretedOption_has_positive_int_value(const google_protobuf_UninterpretedOption* msg) { const upb_MiniTableField field = {4, UPB_SIZE(16, 32), 2, kUpb_NoSub, 4, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_8Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_UninterpretedOption_clear_negative_int_value(google_protobuf_UninterpretedOption* msg) { const upb_MiniTableField field = {5, UPB_SIZE(24, 40), 3, kUpb_NoSub, 3, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_8Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE int64_t google_protobuf_UninterpretedOption_negative_int_value(const google_protobuf_UninterpretedOption* msg) { int64_t default_val = (int64_t)0ll; int64_t ret; const upb_MiniTableField field = {5, UPB_SIZE(24, 40), 3, kUpb_NoSub, 3, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_8Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_UninterpretedOption_has_negative_int_value(const google_protobuf_UninterpretedOption* msg) { const upb_MiniTableField field = {5, UPB_SIZE(24, 40), 3, kUpb_NoSub, 3, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_8Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_UninterpretedOption_clear_double_value(google_protobuf_UninterpretedOption* msg) { const upb_MiniTableField field = {6, UPB_SIZE(32, 48), 4, kUpb_NoSub, 1, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_8Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE double google_protobuf_UninterpretedOption_double_value(const google_protobuf_UninterpretedOption* msg) { double default_val = 0; double ret; const upb_MiniTableField field = {6, UPB_SIZE(32, 48), 4, kUpb_NoSub, 1, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_8Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_UninterpretedOption_has_double_value(const google_protobuf_UninterpretedOption* msg) { const upb_MiniTableField field = {6, UPB_SIZE(32, 48), 4, kUpb_NoSub, 1, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_8Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_UninterpretedOption_clear_string_value(google_protobuf_UninterpretedOption* msg) { const upb_MiniTableField field = {7, UPB_SIZE(40, 56), 5, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_UninterpretedOption_string_value(const google_protobuf_UninterpretedOption* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; const upb_MiniTableField field = {7, UPB_SIZE(40, 56), 5, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_UninterpretedOption_has_string_value(const google_protobuf_UninterpretedOption* msg) { const upb_MiniTableField field = {7, UPB_SIZE(40, 56), 5, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_UninterpretedOption_clear_aggregate_value(google_protobuf_UninterpretedOption* msg) { const upb_MiniTableField field = {8, UPB_SIZE(48, 72), 6, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_UninterpretedOption_aggregate_value(const google_protobuf_UninterpretedOption* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; const upb_MiniTableField field = {8, UPB_SIZE(48, 72), 6, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_UninterpretedOption_has_aggregate_value(const google_protobuf_UninterpretedOption* msg) { const upb_MiniTableField field = {8, UPB_SIZE(48, 72), 6, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE google_protobuf_UninterpretedOption_NamePart** google_protobuf_UninterpretedOption_mutable_name(google_protobuf_UninterpretedOption* msg, size_t* size) { upb_MiniTableField field = {2, UPB_SIZE(4, 8), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetMutableArray(msg, &field); + upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_UninterpretedOption_NamePart**)_upb_array_ptr(arr); @@ -9430,11 +9646,13 @@ UPB_INLINE google_protobuf_UninterpretedOption_NamePart** google_protobuf_Uninte } UPB_INLINE google_protobuf_UninterpretedOption_NamePart** google_protobuf_UninterpretedOption_resize_name(google_protobuf_UninterpretedOption* msg, size_t size, upb_Arena* arena) { upb_MiniTableField field = {2, UPB_SIZE(4, 8), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return (google_protobuf_UninterpretedOption_NamePart**)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); + return (google_protobuf_UninterpretedOption_NamePart**)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg), + &field, size, arena); } UPB_INLINE struct google_protobuf_UninterpretedOption_NamePart* google_protobuf_UninterpretedOption_add_name(google_protobuf_UninterpretedOption* msg, upb_Arena* arena) { upb_MiniTableField field = {2, UPB_SIZE(4, 8), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray( + UPB_UPCAST(msg), &field, arena); if (!arr || !_upb_Array_ResizeUninitialized( arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; @@ -9447,27 +9665,27 @@ UPB_INLINE struct google_protobuf_UninterpretedOption_NamePart* google_protobuf_ } UPB_INLINE void google_protobuf_UninterpretedOption_set_identifier_value(google_protobuf_UninterpretedOption *msg, upb_StringView value) { const upb_MiniTableField field = {3, UPB_SIZE(8, 16), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_UninterpretedOption_set_positive_int_value(google_protobuf_UninterpretedOption *msg, uint64_t value) { const upb_MiniTableField field = {4, UPB_SIZE(16, 32), 2, kUpb_NoSub, 4, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_8Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_UninterpretedOption_set_negative_int_value(google_protobuf_UninterpretedOption *msg, int64_t value) { const upb_MiniTableField field = {5, UPB_SIZE(24, 40), 3, kUpb_NoSub, 3, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_8Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_UninterpretedOption_set_double_value(google_protobuf_UninterpretedOption *msg, double value) { const upb_MiniTableField field = {6, UPB_SIZE(32, 48), 4, kUpb_NoSub, 1, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_8Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_UninterpretedOption_set_string_value(google_protobuf_UninterpretedOption *msg, upb_StringView value) { const upb_MiniTableField field = {7, UPB_SIZE(40, 56), 5, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_UninterpretedOption_set_aggregate_value(google_protobuf_UninterpretedOption *msg, upb_StringView value) { const upb_MiniTableField field = {8, UPB_SIZE(48, 72), 6, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } /* google.protobuf.UninterpretedOption.NamePart */ @@ -9478,7 +9696,8 @@ UPB_INLINE google_protobuf_UninterpretedOption_NamePart* google_protobuf_Uninter UPB_INLINE google_protobuf_UninterpretedOption_NamePart* google_protobuf_UninterpretedOption_NamePart_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_UninterpretedOption_NamePart* ret = google_protobuf_UninterpretedOption_NamePart_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__UninterpretedOption__NamePart_msg_init, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__UninterpretedOption__NamePart_msg_init, NULL, 0, arena) != + kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -9488,61 +9707,63 @@ UPB_INLINE google_protobuf_UninterpretedOption_NamePart* google_protobuf_Uninter int options, upb_Arena* arena) { google_protobuf_UninterpretedOption_NamePart* ret = google_protobuf_UninterpretedOption_NamePart_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__UninterpretedOption__NamePart_msg_init, extreg, options, arena) != - kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__UninterpretedOption__NamePart_msg_init, extreg, options, + arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_UninterpretedOption_NamePart_serialize(const google_protobuf_UninterpretedOption_NamePart* msg, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__UninterpretedOption__NamePart_msg_init, 0, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__UninterpretedOption__NamePart_msg_init, 0, arena, &ptr, len); return ptr; } UPB_INLINE char* google_protobuf_UninterpretedOption_NamePart_serialize_ex(const google_protobuf_UninterpretedOption_NamePart* msg, int options, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__UninterpretedOption__NamePart_msg_init, options, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__UninterpretedOption__NamePart_msg_init, options, arena, &ptr, len); return ptr; } UPB_INLINE void google_protobuf_UninterpretedOption_NamePart_clear_name_part(google_protobuf_UninterpretedOption_NamePart* msg) { const upb_MiniTableField field = {1, UPB_SIZE(4, 8), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_UninterpretedOption_NamePart_name_part(const google_protobuf_UninterpretedOption_NamePart* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; const upb_MiniTableField field = {1, UPB_SIZE(4, 8), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_UninterpretedOption_NamePart_has_name_part(const google_protobuf_UninterpretedOption_NamePart* msg) { const upb_MiniTableField field = {1, UPB_SIZE(4, 8), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_UninterpretedOption_NamePart_clear_is_extension(google_protobuf_UninterpretedOption_NamePart* msg) { const upb_MiniTableField field = {2, 1, 2, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_UninterpretedOption_NamePart_is_extension(const google_protobuf_UninterpretedOption_NamePart* msg) { bool default_val = false; bool ret; const upb_MiniTableField field = {2, 1, 2, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_UninterpretedOption_NamePart_has_is_extension(const google_protobuf_UninterpretedOption_NamePart* msg) { const upb_MiniTableField field = {2, 1, 2, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_UninterpretedOption_NamePart_set_name_part(google_protobuf_UninterpretedOption_NamePart *msg, upb_StringView value) { const upb_MiniTableField field = {1, UPB_SIZE(4, 8), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_UninterpretedOption_NamePart_set_is_extension(google_protobuf_UninterpretedOption_NamePart *msg, bool value) { const upb_MiniTableField field = {2, 1, 2, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } /* google.protobuf.FeatureSet */ @@ -9553,7 +9774,8 @@ UPB_INLINE google_protobuf_FeatureSet* google_protobuf_FeatureSet_new(upb_Arena* UPB_INLINE google_protobuf_FeatureSet* google_protobuf_FeatureSet_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_FeatureSet* ret = google_protobuf_FeatureSet_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__FeatureSet_msg_init, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__FeatureSet_msg_init, NULL, 0, arena) != + kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -9563,137 +9785,143 @@ UPB_INLINE google_protobuf_FeatureSet* google_protobuf_FeatureSet_parse_ex(const int options, upb_Arena* arena) { google_protobuf_FeatureSet* ret = google_protobuf_FeatureSet_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__FeatureSet_msg_init, extreg, options, arena) != - kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__FeatureSet_msg_init, extreg, options, + arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_FeatureSet_serialize(const google_protobuf_FeatureSet* msg, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__FeatureSet_msg_init, 0, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__FeatureSet_msg_init, 0, arena, &ptr, len); return ptr; } UPB_INLINE char* google_protobuf_FeatureSet_serialize_ex(const google_protobuf_FeatureSet* msg, int options, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__FeatureSet_msg_init, options, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__FeatureSet_msg_init, options, arena, &ptr, len); return ptr; } UPB_INLINE void google_protobuf_FeatureSet_clear_field_presence(google_protobuf_FeatureSet* msg) { const upb_MiniTableField field = {1, 4, 1, 0, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_FeatureSet_field_presence(const google_protobuf_FeatureSet* msg) { int32_t default_val = 0; int32_t ret; const upb_MiniTableField field = {1, 4, 1, 0, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FeatureSet_has_field_presence(const google_protobuf_FeatureSet* msg) { const upb_MiniTableField field = {1, 4, 1, 0, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FeatureSet_clear_enum_type(google_protobuf_FeatureSet* msg) { const upb_MiniTableField field = {2, 8, 2, 1, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_FeatureSet_enum_type(const google_protobuf_FeatureSet* msg) { int32_t default_val = 0; int32_t ret; const upb_MiniTableField field = {2, 8, 2, 1, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FeatureSet_has_enum_type(const google_protobuf_FeatureSet* msg) { const upb_MiniTableField field = {2, 8, 2, 1, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FeatureSet_clear_repeated_field_encoding(google_protobuf_FeatureSet* msg) { const upb_MiniTableField field = {3, 12, 3, 2, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_FeatureSet_repeated_field_encoding(const google_protobuf_FeatureSet* msg) { int32_t default_val = 0; int32_t ret; const upb_MiniTableField field = {3, 12, 3, 2, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FeatureSet_has_repeated_field_encoding(const google_protobuf_FeatureSet* msg) { const upb_MiniTableField field = {3, 12, 3, 2, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FeatureSet_clear_utf8_validation(google_protobuf_FeatureSet* msg) { const upb_MiniTableField field = {4, 16, 4, 3, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_FeatureSet_utf8_validation(const google_protobuf_FeatureSet* msg) { int32_t default_val = 0; int32_t ret; const upb_MiniTableField field = {4, 16, 4, 3, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FeatureSet_has_utf8_validation(const google_protobuf_FeatureSet* msg) { const upb_MiniTableField field = {4, 16, 4, 3, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FeatureSet_clear_message_encoding(google_protobuf_FeatureSet* msg) { const upb_MiniTableField field = {5, 20, 5, 4, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_FeatureSet_message_encoding(const google_protobuf_FeatureSet* msg) { int32_t default_val = 0; int32_t ret; const upb_MiniTableField field = {5, 20, 5, 4, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FeatureSet_has_message_encoding(const google_protobuf_FeatureSet* msg) { const upb_MiniTableField field = {5, 20, 5, 4, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FeatureSet_clear_json_format(google_protobuf_FeatureSet* msg) { const upb_MiniTableField field = {6, 24, 6, 5, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_FeatureSet_json_format(const google_protobuf_FeatureSet* msg) { int32_t default_val = 0; int32_t ret; const upb_MiniTableField field = {6, 24, 6, 5, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FeatureSet_has_json_format(const google_protobuf_FeatureSet* msg) { const upb_MiniTableField field = {6, 24, 6, 5, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FeatureSet_set_field_presence(google_protobuf_FeatureSet *msg, int32_t value) { const upb_MiniTableField field = {1, 4, 1, 0, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FeatureSet_set_enum_type(google_protobuf_FeatureSet *msg, int32_t value) { const upb_MiniTableField field = {2, 8, 2, 1, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FeatureSet_set_repeated_field_encoding(google_protobuf_FeatureSet *msg, int32_t value) { const upb_MiniTableField field = {3, 12, 3, 2, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FeatureSet_set_utf8_validation(google_protobuf_FeatureSet *msg, int32_t value) { const upb_MiniTableField field = {4, 16, 4, 3, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FeatureSet_set_message_encoding(google_protobuf_FeatureSet *msg, int32_t value) { const upb_MiniTableField field = {5, 20, 5, 4, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FeatureSet_set_json_format(google_protobuf_FeatureSet *msg, int32_t value) { const upb_MiniTableField field = {6, 24, 6, 5, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } /* google.protobuf.FeatureSetDefaults */ @@ -9704,7 +9932,8 @@ UPB_INLINE google_protobuf_FeatureSetDefaults* google_protobuf_FeatureSetDefault UPB_INLINE google_protobuf_FeatureSetDefaults* google_protobuf_FeatureSetDefaults_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_FeatureSetDefaults* ret = google_protobuf_FeatureSetDefaults_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__FeatureSetDefaults_msg_init, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__FeatureSetDefaults_msg_init, NULL, 0, arena) != + kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -9714,30 +9943,30 @@ UPB_INLINE google_protobuf_FeatureSetDefaults* google_protobuf_FeatureSetDefault int options, upb_Arena* arena) { google_protobuf_FeatureSetDefaults* ret = google_protobuf_FeatureSetDefaults_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__FeatureSetDefaults_msg_init, extreg, options, arena) != - kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__FeatureSetDefaults_msg_init, extreg, options, + arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_FeatureSetDefaults_serialize(const google_protobuf_FeatureSetDefaults* msg, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__FeatureSetDefaults_msg_init, 0, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__FeatureSetDefaults_msg_init, 0, arena, &ptr, len); return ptr; } UPB_INLINE char* google_protobuf_FeatureSetDefaults_serialize_ex(const google_protobuf_FeatureSetDefaults* msg, int options, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__FeatureSetDefaults_msg_init, options, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__FeatureSetDefaults_msg_init, options, arena, &ptr, len); return ptr; } UPB_INLINE void google_protobuf_FeatureSetDefaults_clear_defaults(google_protobuf_FeatureSetDefaults* msg) { const upb_MiniTableField field = {1, UPB_SIZE(4, 16), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* const* google_protobuf_FeatureSetDefaults_defaults(const google_protobuf_FeatureSetDefaults* msg, size_t* size) { const upb_MiniTableField field = {1, UPB_SIZE(4, 16), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* const*)_upb_array_constptr(arr); @@ -9748,16 +9977,16 @@ UPB_INLINE const google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* co } UPB_INLINE const upb_Array* _google_protobuf_FeatureSetDefaults_defaults_upb_array(const google_protobuf_FeatureSetDefaults* msg, size_t* size) { const upb_MiniTableField field = {1, UPB_SIZE(4, 16), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } -UPB_INLINE upb_Array* _google_protobuf_FeatureSetDefaults_defaults_mutable_upb_array(const google_protobuf_FeatureSetDefaults* msg, size_t* size, upb_Arena* arena) { +UPB_INLINE upb_Array* _google_protobuf_FeatureSetDefaults_defaults_mutable_upb_array(google_protobuf_FeatureSetDefaults* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = {1, UPB_SIZE(4, 16), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - (upb_Message*)msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), + &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -9765,38 +9994,40 @@ UPB_INLINE upb_Array* _google_protobuf_FeatureSetDefaults_defaults_mutable_upb_a } UPB_INLINE void google_protobuf_FeatureSetDefaults_clear_minimum_edition(google_protobuf_FeatureSetDefaults* msg) { const upb_MiniTableField field = {4, UPB_SIZE(8, 4), 1, 1, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_FeatureSetDefaults_minimum_edition(const google_protobuf_FeatureSetDefaults* msg) { int32_t default_val = 0; int32_t ret; const upb_MiniTableField field = {4, UPB_SIZE(8, 4), 1, 1, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FeatureSetDefaults_has_minimum_edition(const google_protobuf_FeatureSetDefaults* msg) { const upb_MiniTableField field = {4, UPB_SIZE(8, 4), 1, 1, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FeatureSetDefaults_clear_maximum_edition(google_protobuf_FeatureSetDefaults* msg) { const upb_MiniTableField field = {5, UPB_SIZE(12, 8), 2, 2, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_FeatureSetDefaults_maximum_edition(const google_protobuf_FeatureSetDefaults* msg) { int32_t default_val = 0; int32_t ret; const upb_MiniTableField field = {5, UPB_SIZE(12, 8), 2, 2, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FeatureSetDefaults_has_maximum_edition(const google_protobuf_FeatureSetDefaults* msg) { const upb_MiniTableField field = {5, UPB_SIZE(12, 8), 2, 2, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault** google_protobuf_FeatureSetDefaults_mutable_defaults(google_protobuf_FeatureSetDefaults* msg, size_t* size) { upb_MiniTableField field = {1, UPB_SIZE(4, 16), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetMutableArray(msg, &field); + upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault**)_upb_array_ptr(arr); @@ -9807,11 +10038,13 @@ UPB_INLINE google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault** google_ } UPB_INLINE google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault** google_protobuf_FeatureSetDefaults_resize_defaults(google_protobuf_FeatureSetDefaults* msg, size_t size, upb_Arena* arena) { upb_MiniTableField field = {1, UPB_SIZE(4, 16), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return (google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault**)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); + return (google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault**)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg), + &field, size, arena); } UPB_INLINE struct google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* google_protobuf_FeatureSetDefaults_add_defaults(google_protobuf_FeatureSetDefaults* msg, upb_Arena* arena) { upb_MiniTableField field = {1, UPB_SIZE(4, 16), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray( + UPB_UPCAST(msg), &field, arena); if (!arr || !_upb_Array_ResizeUninitialized( arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; @@ -9824,11 +10057,11 @@ UPB_INLINE struct google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* g } UPB_INLINE void google_protobuf_FeatureSetDefaults_set_minimum_edition(google_protobuf_FeatureSetDefaults *msg, int32_t value) { const upb_MiniTableField field = {4, UPB_SIZE(8, 4), 1, 1, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FeatureSetDefaults_set_maximum_edition(google_protobuf_FeatureSetDefaults *msg, int32_t value) { const upb_MiniTableField field = {5, UPB_SIZE(12, 8), 2, 2, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } /* google.protobuf.FeatureSetDefaults.FeatureSetEditionDefault */ @@ -9839,7 +10072,8 @@ UPB_INLINE google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* google_p UPB_INLINE google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* ret = google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__FeatureSetDefaults__FeatureSetEditionDefault_msg_init, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__FeatureSetDefaults__FeatureSetEditionDefault_msg_init, NULL, 0, arena) != + kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -9849,57 +10083,59 @@ UPB_INLINE google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* google_p int options, upb_Arena* arena) { google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* ret = google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__FeatureSetDefaults__FeatureSetEditionDefault_msg_init, extreg, options, arena) != - kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__FeatureSetDefaults__FeatureSetEditionDefault_msg_init, extreg, options, + arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_serialize(const google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* msg, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__FeatureSetDefaults__FeatureSetEditionDefault_msg_init, 0, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__FeatureSetDefaults__FeatureSetEditionDefault_msg_init, 0, arena, &ptr, len); return ptr; } UPB_INLINE char* google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_serialize_ex(const google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* msg, int options, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__FeatureSetDefaults__FeatureSetEditionDefault_msg_init, options, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__FeatureSetDefaults__FeatureSetEditionDefault_msg_init, options, arena, &ptr, len); return ptr; } UPB_INLINE void google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_clear_features(google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* msg) { const upb_MiniTableField field = {2, UPB_SIZE(4, 8), 1, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_FeatureSet* google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_features(const google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* msg) { const google_protobuf_FeatureSet* default_val = NULL; const google_protobuf_FeatureSet* ret; const upb_MiniTableField field = {2, UPB_SIZE(4, 8), 1, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_has_features(const google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* msg) { const upb_MiniTableField field = {2, UPB_SIZE(4, 8), 1, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_clear_edition(google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* msg) { const upb_MiniTableField field = {3, UPB_SIZE(8, 4), 2, 1, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_edition(const google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* msg) { int32_t default_val = 0; int32_t ret; const upb_MiniTableField field = {3, UPB_SIZE(8, 4), 2, 1, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_has_edition(const google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* msg) { const upb_MiniTableField field = {3, UPB_SIZE(8, 4), 2, 1, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_set_features(google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault *msg, google_protobuf_FeatureSet* value) { const upb_MiniTableField field = {2, UPB_SIZE(4, 8), 1, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE struct google_protobuf_FeatureSet* google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_mutable_features(google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* msg, upb_Arena* arena) { struct google_protobuf_FeatureSet* sub = (struct google_protobuf_FeatureSet*)google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_features(msg); @@ -9911,7 +10147,7 @@ UPB_INLINE struct google_protobuf_FeatureSet* google_protobuf_FeatureSetDefaults } UPB_INLINE void google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_set_edition(google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault *msg, int32_t value) { const upb_MiniTableField field = {3, UPB_SIZE(8, 4), 2, 1, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } /* google.protobuf.SourceCodeInfo */ @@ -9922,7 +10158,8 @@ UPB_INLINE google_protobuf_SourceCodeInfo* google_protobuf_SourceCodeInfo_new(up UPB_INLINE google_protobuf_SourceCodeInfo* google_protobuf_SourceCodeInfo_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_SourceCodeInfo* ret = google_protobuf_SourceCodeInfo_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__SourceCodeInfo_msg_init, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__SourceCodeInfo_msg_init, NULL, 0, arena) != + kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -9932,30 +10169,30 @@ UPB_INLINE google_protobuf_SourceCodeInfo* google_protobuf_SourceCodeInfo_parse_ int options, upb_Arena* arena) { google_protobuf_SourceCodeInfo* ret = google_protobuf_SourceCodeInfo_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__SourceCodeInfo_msg_init, extreg, options, arena) != - kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__SourceCodeInfo_msg_init, extreg, options, + arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_SourceCodeInfo_serialize(const google_protobuf_SourceCodeInfo* msg, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__SourceCodeInfo_msg_init, 0, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__SourceCodeInfo_msg_init, 0, arena, &ptr, len); return ptr; } UPB_INLINE char* google_protobuf_SourceCodeInfo_serialize_ex(const google_protobuf_SourceCodeInfo* msg, int options, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__SourceCodeInfo_msg_init, options, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__SourceCodeInfo_msg_init, options, arena, &ptr, len); return ptr; } UPB_INLINE void google_protobuf_SourceCodeInfo_clear_location(google_protobuf_SourceCodeInfo* msg) { const upb_MiniTableField field = {1, 0, 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_SourceCodeInfo_Location* const* google_protobuf_SourceCodeInfo_location(const google_protobuf_SourceCodeInfo* msg, size_t* size) { const upb_MiniTableField field = {1, 0, 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_SourceCodeInfo_Location* const*)_upb_array_constptr(arr); @@ -9966,16 +10203,16 @@ UPB_INLINE const google_protobuf_SourceCodeInfo_Location* const* google_protobuf } UPB_INLINE const upb_Array* _google_protobuf_SourceCodeInfo_location_upb_array(const google_protobuf_SourceCodeInfo* msg, size_t* size) { const upb_MiniTableField field = {1, 0, 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } -UPB_INLINE upb_Array* _google_protobuf_SourceCodeInfo_location_mutable_upb_array(const google_protobuf_SourceCodeInfo* msg, size_t* size, upb_Arena* arena) { +UPB_INLINE upb_Array* _google_protobuf_SourceCodeInfo_location_mutable_upb_array(google_protobuf_SourceCodeInfo* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = {1, 0, 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - (upb_Message*)msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), + &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -9984,7 +10221,7 @@ UPB_INLINE upb_Array* _google_protobuf_SourceCodeInfo_location_mutable_upb_array UPB_INLINE google_protobuf_SourceCodeInfo_Location** google_protobuf_SourceCodeInfo_mutable_location(google_protobuf_SourceCodeInfo* msg, size_t* size) { upb_MiniTableField field = {1, 0, 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetMutableArray(msg, &field); + upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_SourceCodeInfo_Location**)_upb_array_ptr(arr); @@ -9995,11 +10232,13 @@ UPB_INLINE google_protobuf_SourceCodeInfo_Location** google_protobuf_SourceCodeI } UPB_INLINE google_protobuf_SourceCodeInfo_Location** google_protobuf_SourceCodeInfo_resize_location(google_protobuf_SourceCodeInfo* msg, size_t size, upb_Arena* arena) { upb_MiniTableField field = {1, 0, 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return (google_protobuf_SourceCodeInfo_Location**)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); + return (google_protobuf_SourceCodeInfo_Location**)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg), + &field, size, arena); } UPB_INLINE struct google_protobuf_SourceCodeInfo_Location* google_protobuf_SourceCodeInfo_add_location(google_protobuf_SourceCodeInfo* msg, upb_Arena* arena) { upb_MiniTableField field = {1, 0, 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray( + UPB_UPCAST(msg), &field, arena); if (!arr || !_upb_Array_ResizeUninitialized( arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; @@ -10019,7 +10258,8 @@ UPB_INLINE google_protobuf_SourceCodeInfo_Location* google_protobuf_SourceCodeIn UPB_INLINE google_protobuf_SourceCodeInfo_Location* google_protobuf_SourceCodeInfo_Location_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_SourceCodeInfo_Location* ret = google_protobuf_SourceCodeInfo_Location_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__SourceCodeInfo__Location_msg_init, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__SourceCodeInfo__Location_msg_init, NULL, 0, arena) != + kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -10029,30 +10269,30 @@ UPB_INLINE google_protobuf_SourceCodeInfo_Location* google_protobuf_SourceCodeIn int options, upb_Arena* arena) { google_protobuf_SourceCodeInfo_Location* ret = google_protobuf_SourceCodeInfo_Location_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__SourceCodeInfo__Location_msg_init, extreg, options, arena) != - kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__SourceCodeInfo__Location_msg_init, extreg, options, + arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_SourceCodeInfo_Location_serialize(const google_protobuf_SourceCodeInfo_Location* msg, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__SourceCodeInfo__Location_msg_init, 0, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__SourceCodeInfo__Location_msg_init, 0, arena, &ptr, len); return ptr; } UPB_INLINE char* google_protobuf_SourceCodeInfo_Location_serialize_ex(const google_protobuf_SourceCodeInfo_Location* msg, int options, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__SourceCodeInfo__Location_msg_init, options, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__SourceCodeInfo__Location_msg_init, options, arena, &ptr, len); return ptr; } UPB_INLINE void google_protobuf_SourceCodeInfo_Location_clear_path(google_protobuf_SourceCodeInfo_Location* msg) { const upb_MiniTableField field = {1, UPB_SIZE(4, 8), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsPacked | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t const* google_protobuf_SourceCodeInfo_Location_path(const google_protobuf_SourceCodeInfo_Location* msg, size_t* size) { const upb_MiniTableField field = {1, UPB_SIZE(4, 8), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsPacked | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (int32_t const*)_upb_array_constptr(arr); @@ -10063,16 +10303,16 @@ UPB_INLINE int32_t const* google_protobuf_SourceCodeInfo_Location_path(const goo } UPB_INLINE const upb_Array* _google_protobuf_SourceCodeInfo_Location_path_upb_array(const google_protobuf_SourceCodeInfo_Location* msg, size_t* size) { const upb_MiniTableField field = {1, UPB_SIZE(4, 8), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsPacked | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } -UPB_INLINE upb_Array* _google_protobuf_SourceCodeInfo_Location_path_mutable_upb_array(const google_protobuf_SourceCodeInfo_Location* msg, size_t* size, upb_Arena* arena) { +UPB_INLINE upb_Array* _google_protobuf_SourceCodeInfo_Location_path_mutable_upb_array(google_protobuf_SourceCodeInfo_Location* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = {1, UPB_SIZE(4, 8), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsPacked | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - (upb_Message*)msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), + &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -10080,11 +10320,11 @@ UPB_INLINE upb_Array* _google_protobuf_SourceCodeInfo_Location_path_mutable_upb_ } UPB_INLINE void google_protobuf_SourceCodeInfo_Location_clear_span(google_protobuf_SourceCodeInfo_Location* msg) { const upb_MiniTableField field = {2, UPB_SIZE(8, 16), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsPacked | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t const* google_protobuf_SourceCodeInfo_Location_span(const google_protobuf_SourceCodeInfo_Location* msg, size_t* size) { const upb_MiniTableField field = {2, UPB_SIZE(8, 16), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsPacked | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (int32_t const*)_upb_array_constptr(arr); @@ -10095,16 +10335,16 @@ UPB_INLINE int32_t const* google_protobuf_SourceCodeInfo_Location_span(const goo } UPB_INLINE const upb_Array* _google_protobuf_SourceCodeInfo_Location_span_upb_array(const google_protobuf_SourceCodeInfo_Location* msg, size_t* size) { const upb_MiniTableField field = {2, UPB_SIZE(8, 16), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsPacked | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } -UPB_INLINE upb_Array* _google_protobuf_SourceCodeInfo_Location_span_mutable_upb_array(const google_protobuf_SourceCodeInfo_Location* msg, size_t* size, upb_Arena* arena) { +UPB_INLINE upb_Array* _google_protobuf_SourceCodeInfo_Location_span_mutable_upb_array(google_protobuf_SourceCodeInfo_Location* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = {2, UPB_SIZE(8, 16), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsPacked | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - (upb_Message*)msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), + &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -10112,41 +10352,43 @@ UPB_INLINE upb_Array* _google_protobuf_SourceCodeInfo_Location_span_mutable_upb_ } UPB_INLINE void google_protobuf_SourceCodeInfo_Location_clear_leading_comments(google_protobuf_SourceCodeInfo_Location* msg) { const upb_MiniTableField field = {3, UPB_SIZE(16, 24), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_SourceCodeInfo_Location_leading_comments(const google_protobuf_SourceCodeInfo_Location* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; const upb_MiniTableField field = {3, UPB_SIZE(16, 24), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_SourceCodeInfo_Location_has_leading_comments(const google_protobuf_SourceCodeInfo_Location* msg) { const upb_MiniTableField field = {3, UPB_SIZE(16, 24), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_SourceCodeInfo_Location_clear_trailing_comments(google_protobuf_SourceCodeInfo_Location* msg) { const upb_MiniTableField field = {4, UPB_SIZE(24, 40), 2, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_SourceCodeInfo_Location_trailing_comments(const google_protobuf_SourceCodeInfo_Location* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; const upb_MiniTableField field = {4, UPB_SIZE(24, 40), 2, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_SourceCodeInfo_Location_has_trailing_comments(const google_protobuf_SourceCodeInfo_Location* msg) { const upb_MiniTableField field = {4, UPB_SIZE(24, 40), 2, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_SourceCodeInfo_Location_clear_leading_detached_comments(google_protobuf_SourceCodeInfo_Location* msg) { const upb_MiniTableField field = {6, UPB_SIZE(12, 56), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView const* google_protobuf_SourceCodeInfo_Location_leading_detached_comments(const google_protobuf_SourceCodeInfo_Location* msg, size_t* size) { const upb_MiniTableField field = {6, UPB_SIZE(12, 56), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (upb_StringView const*)_upb_array_constptr(arr); @@ -10157,16 +10399,16 @@ UPB_INLINE upb_StringView const* google_protobuf_SourceCodeInfo_Location_leading } UPB_INLINE const upb_Array* _google_protobuf_SourceCodeInfo_Location_leading_detached_comments_upb_array(const google_protobuf_SourceCodeInfo_Location* msg, size_t* size) { const upb_MiniTableField field = {6, UPB_SIZE(12, 56), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } -UPB_INLINE upb_Array* _google_protobuf_SourceCodeInfo_Location_leading_detached_comments_mutable_upb_array(const google_protobuf_SourceCodeInfo_Location* msg, size_t* size, upb_Arena* arena) { +UPB_INLINE upb_Array* _google_protobuf_SourceCodeInfo_Location_leading_detached_comments_mutable_upb_array(google_protobuf_SourceCodeInfo_Location* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = {6, UPB_SIZE(12, 56), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - (upb_Message*)msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), + &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -10175,7 +10417,7 @@ UPB_INLINE upb_Array* _google_protobuf_SourceCodeInfo_Location_leading_detached_ UPB_INLINE int32_t* google_protobuf_SourceCodeInfo_Location_mutable_path(google_protobuf_SourceCodeInfo_Location* msg, size_t* size) { upb_MiniTableField field = {1, UPB_SIZE(4, 8), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsPacked | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetMutableArray(msg, &field); + upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (int32_t*)_upb_array_ptr(arr); @@ -10186,11 +10428,13 @@ UPB_INLINE int32_t* google_protobuf_SourceCodeInfo_Location_mutable_path(google_ } UPB_INLINE int32_t* google_protobuf_SourceCodeInfo_Location_resize_path(google_protobuf_SourceCodeInfo_Location* msg, size_t size, upb_Arena* arena) { upb_MiniTableField field = {1, UPB_SIZE(4, 8), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsPacked | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return (int32_t*)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); + return (int32_t*)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg), + &field, size, arena); } UPB_INLINE bool google_protobuf_SourceCodeInfo_Location_add_path(google_protobuf_SourceCodeInfo_Location* msg, int32_t val, upb_Arena* arena) { upb_MiniTableField field = {1, UPB_SIZE(4, 8), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsPacked | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray( + UPB_UPCAST(msg), &field, arena); if (!arr || !_upb_Array_ResizeUninitialized( arr, arr->UPB_PRIVATE(size) + 1, arena)) { return false; @@ -10201,7 +10445,7 @@ UPB_INLINE bool google_protobuf_SourceCodeInfo_Location_add_path(google_protobuf } UPB_INLINE int32_t* google_protobuf_SourceCodeInfo_Location_mutable_span(google_protobuf_SourceCodeInfo_Location* msg, size_t* size) { upb_MiniTableField field = {2, UPB_SIZE(8, 16), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsPacked | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetMutableArray(msg, &field); + upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (int32_t*)_upb_array_ptr(arr); @@ -10212,11 +10456,13 @@ UPB_INLINE int32_t* google_protobuf_SourceCodeInfo_Location_mutable_span(google_ } UPB_INLINE int32_t* google_protobuf_SourceCodeInfo_Location_resize_span(google_protobuf_SourceCodeInfo_Location* msg, size_t size, upb_Arena* arena) { upb_MiniTableField field = {2, UPB_SIZE(8, 16), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsPacked | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return (int32_t*)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); + return (int32_t*)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg), + &field, size, arena); } UPB_INLINE bool google_protobuf_SourceCodeInfo_Location_add_span(google_protobuf_SourceCodeInfo_Location* msg, int32_t val, upb_Arena* arena) { upb_MiniTableField field = {2, UPB_SIZE(8, 16), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsPacked | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray( + UPB_UPCAST(msg), &field, arena); if (!arr || !_upb_Array_ResizeUninitialized( arr, arr->UPB_PRIVATE(size) + 1, arena)) { return false; @@ -10227,15 +10473,15 @@ UPB_INLINE bool google_protobuf_SourceCodeInfo_Location_add_span(google_protobuf } UPB_INLINE void google_protobuf_SourceCodeInfo_Location_set_leading_comments(google_protobuf_SourceCodeInfo_Location *msg, upb_StringView value) { const upb_MiniTableField field = {3, UPB_SIZE(16, 24), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_SourceCodeInfo_Location_set_trailing_comments(google_protobuf_SourceCodeInfo_Location *msg, upb_StringView value) { const upb_MiniTableField field = {4, UPB_SIZE(24, 40), 2, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE upb_StringView* google_protobuf_SourceCodeInfo_Location_mutable_leading_detached_comments(google_protobuf_SourceCodeInfo_Location* msg, size_t* size) { upb_MiniTableField field = {6, UPB_SIZE(12, 56), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetMutableArray(msg, &field); + upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (upb_StringView*)_upb_array_ptr(arr); @@ -10246,11 +10492,13 @@ UPB_INLINE upb_StringView* google_protobuf_SourceCodeInfo_Location_mutable_leadi } UPB_INLINE upb_StringView* google_protobuf_SourceCodeInfo_Location_resize_leading_detached_comments(google_protobuf_SourceCodeInfo_Location* msg, size_t size, upb_Arena* arena) { upb_MiniTableField field = {6, UPB_SIZE(12, 56), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return (upb_StringView*)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); + return (upb_StringView*)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg), + &field, size, arena); } UPB_INLINE bool google_protobuf_SourceCodeInfo_Location_add_leading_detached_comments(google_protobuf_SourceCodeInfo_Location* msg, upb_StringView val, upb_Arena* arena) { upb_MiniTableField field = {6, UPB_SIZE(12, 56), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray( + UPB_UPCAST(msg), &field, arena); if (!arr || !_upb_Array_ResizeUninitialized( arr, arr->UPB_PRIVATE(size) + 1, arena)) { return false; @@ -10268,7 +10516,8 @@ UPB_INLINE google_protobuf_GeneratedCodeInfo* google_protobuf_GeneratedCodeInfo_ UPB_INLINE google_protobuf_GeneratedCodeInfo* google_protobuf_GeneratedCodeInfo_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_GeneratedCodeInfo* ret = google_protobuf_GeneratedCodeInfo_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__GeneratedCodeInfo_msg_init, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__GeneratedCodeInfo_msg_init, NULL, 0, arena) != + kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -10278,30 +10527,30 @@ UPB_INLINE google_protobuf_GeneratedCodeInfo* google_protobuf_GeneratedCodeInfo_ int options, upb_Arena* arena) { google_protobuf_GeneratedCodeInfo* ret = google_protobuf_GeneratedCodeInfo_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__GeneratedCodeInfo_msg_init, extreg, options, arena) != - kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__GeneratedCodeInfo_msg_init, extreg, options, + arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_GeneratedCodeInfo_serialize(const google_protobuf_GeneratedCodeInfo* msg, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__GeneratedCodeInfo_msg_init, 0, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__GeneratedCodeInfo_msg_init, 0, arena, &ptr, len); return ptr; } UPB_INLINE char* google_protobuf_GeneratedCodeInfo_serialize_ex(const google_protobuf_GeneratedCodeInfo* msg, int options, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__GeneratedCodeInfo_msg_init, options, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__GeneratedCodeInfo_msg_init, options, arena, &ptr, len); return ptr; } UPB_INLINE void google_protobuf_GeneratedCodeInfo_clear_annotation(google_protobuf_GeneratedCodeInfo* msg) { const upb_MiniTableField field = {1, 0, 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_GeneratedCodeInfo_Annotation* const* google_protobuf_GeneratedCodeInfo_annotation(const google_protobuf_GeneratedCodeInfo* msg, size_t* size) { const upb_MiniTableField field = {1, 0, 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_GeneratedCodeInfo_Annotation* const*)_upb_array_constptr(arr); @@ -10312,16 +10561,16 @@ UPB_INLINE const google_protobuf_GeneratedCodeInfo_Annotation* const* google_pro } UPB_INLINE const upb_Array* _google_protobuf_GeneratedCodeInfo_annotation_upb_array(const google_protobuf_GeneratedCodeInfo* msg, size_t* size) { const upb_MiniTableField field = {1, 0, 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } -UPB_INLINE upb_Array* _google_protobuf_GeneratedCodeInfo_annotation_mutable_upb_array(const google_protobuf_GeneratedCodeInfo* msg, size_t* size, upb_Arena* arena) { +UPB_INLINE upb_Array* _google_protobuf_GeneratedCodeInfo_annotation_mutable_upb_array(google_protobuf_GeneratedCodeInfo* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = {1, 0, 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - (upb_Message*)msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), + &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -10330,7 +10579,7 @@ UPB_INLINE upb_Array* _google_protobuf_GeneratedCodeInfo_annotation_mutable_upb_ UPB_INLINE google_protobuf_GeneratedCodeInfo_Annotation** google_protobuf_GeneratedCodeInfo_mutable_annotation(google_protobuf_GeneratedCodeInfo* msg, size_t* size) { upb_MiniTableField field = {1, 0, 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetMutableArray(msg, &field); + upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_GeneratedCodeInfo_Annotation**)_upb_array_ptr(arr); @@ -10341,11 +10590,13 @@ UPB_INLINE google_protobuf_GeneratedCodeInfo_Annotation** google_protobuf_Genera } UPB_INLINE google_protobuf_GeneratedCodeInfo_Annotation** google_protobuf_GeneratedCodeInfo_resize_annotation(google_protobuf_GeneratedCodeInfo* msg, size_t size, upb_Arena* arena) { upb_MiniTableField field = {1, 0, 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return (google_protobuf_GeneratedCodeInfo_Annotation**)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); + return (google_protobuf_GeneratedCodeInfo_Annotation**)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg), + &field, size, arena); } UPB_INLINE struct google_protobuf_GeneratedCodeInfo_Annotation* google_protobuf_GeneratedCodeInfo_add_annotation(google_protobuf_GeneratedCodeInfo* msg, upb_Arena* arena) { upb_MiniTableField field = {1, 0, 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray( + UPB_UPCAST(msg), &field, arena); if (!arr || !_upb_Array_ResizeUninitialized( arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; @@ -10365,7 +10616,8 @@ UPB_INLINE google_protobuf_GeneratedCodeInfo_Annotation* google_protobuf_Generat UPB_INLINE google_protobuf_GeneratedCodeInfo_Annotation* google_protobuf_GeneratedCodeInfo_Annotation_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_GeneratedCodeInfo_Annotation* ret = google_protobuf_GeneratedCodeInfo_Annotation_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__GeneratedCodeInfo__Annotation_msg_init, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__GeneratedCodeInfo__Annotation_msg_init, NULL, 0, arena) != + kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -10375,30 +10627,30 @@ UPB_INLINE google_protobuf_GeneratedCodeInfo_Annotation* google_protobuf_Generat int options, upb_Arena* arena) { google_protobuf_GeneratedCodeInfo_Annotation* ret = google_protobuf_GeneratedCodeInfo_Annotation_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__GeneratedCodeInfo__Annotation_msg_init, extreg, options, arena) != - kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__GeneratedCodeInfo__Annotation_msg_init, extreg, options, + arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_GeneratedCodeInfo_Annotation_serialize(const google_protobuf_GeneratedCodeInfo_Annotation* msg, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__GeneratedCodeInfo__Annotation_msg_init, 0, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__GeneratedCodeInfo__Annotation_msg_init, 0, arena, &ptr, len); return ptr; } UPB_INLINE char* google_protobuf_GeneratedCodeInfo_Annotation_serialize_ex(const google_protobuf_GeneratedCodeInfo_Annotation* msg, int options, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__GeneratedCodeInfo__Annotation_msg_init, options, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__GeneratedCodeInfo__Annotation_msg_init, options, arena, &ptr, len); return ptr; } UPB_INLINE void google_protobuf_GeneratedCodeInfo_Annotation_clear_path(google_protobuf_GeneratedCodeInfo_Annotation* msg) { const upb_MiniTableField field = {1, UPB_SIZE(4, 16), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsPacked | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t const* google_protobuf_GeneratedCodeInfo_Annotation_path(const google_protobuf_GeneratedCodeInfo_Annotation* msg, size_t* size) { const upb_MiniTableField field = {1, UPB_SIZE(4, 16), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsPacked | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (int32_t const*)_upb_array_constptr(arr); @@ -10409,16 +10661,16 @@ UPB_INLINE int32_t const* google_protobuf_GeneratedCodeInfo_Annotation_path(cons } UPB_INLINE const upb_Array* _google_protobuf_GeneratedCodeInfo_Annotation_path_upb_array(const google_protobuf_GeneratedCodeInfo_Annotation* msg, size_t* size) { const upb_MiniTableField field = {1, UPB_SIZE(4, 16), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsPacked | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } -UPB_INLINE upb_Array* _google_protobuf_GeneratedCodeInfo_Annotation_path_mutable_upb_array(const google_protobuf_GeneratedCodeInfo_Annotation* msg, size_t* size, upb_Arena* arena) { +UPB_INLINE upb_Array* _google_protobuf_GeneratedCodeInfo_Annotation_path_mutable_upb_array(google_protobuf_GeneratedCodeInfo_Annotation* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = {1, UPB_SIZE(4, 16), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsPacked | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - (upb_Message*)msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), + &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -10426,68 +10678,72 @@ UPB_INLINE upb_Array* _google_protobuf_GeneratedCodeInfo_Annotation_path_mutable } UPB_INLINE void google_protobuf_GeneratedCodeInfo_Annotation_clear_source_file(google_protobuf_GeneratedCodeInfo_Annotation* msg) { const upb_MiniTableField field = {2, UPB_SIZE(20, 24), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_GeneratedCodeInfo_Annotation_source_file(const google_protobuf_GeneratedCodeInfo_Annotation* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; const upb_MiniTableField field = {2, UPB_SIZE(20, 24), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_GeneratedCodeInfo_Annotation_has_source_file(const google_protobuf_GeneratedCodeInfo_Annotation* msg) { const upb_MiniTableField field = {2, UPB_SIZE(20, 24), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_GeneratedCodeInfo_Annotation_clear_begin(google_protobuf_GeneratedCodeInfo_Annotation* msg) { const upb_MiniTableField field = {3, UPB_SIZE(8, 4), 2, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_GeneratedCodeInfo_Annotation_begin(const google_protobuf_GeneratedCodeInfo_Annotation* msg) { int32_t default_val = (int32_t)0; int32_t ret; const upb_MiniTableField field = {3, UPB_SIZE(8, 4), 2, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_GeneratedCodeInfo_Annotation_has_begin(const google_protobuf_GeneratedCodeInfo_Annotation* msg) { const upb_MiniTableField field = {3, UPB_SIZE(8, 4), 2, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_GeneratedCodeInfo_Annotation_clear_end(google_protobuf_GeneratedCodeInfo_Annotation* msg) { const upb_MiniTableField field = {4, UPB_SIZE(12, 8), 3, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_GeneratedCodeInfo_Annotation_end(const google_protobuf_GeneratedCodeInfo_Annotation* msg) { int32_t default_val = (int32_t)0; int32_t ret; const upb_MiniTableField field = {4, UPB_SIZE(12, 8), 3, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_GeneratedCodeInfo_Annotation_has_end(const google_protobuf_GeneratedCodeInfo_Annotation* msg) { const upb_MiniTableField field = {4, UPB_SIZE(12, 8), 3, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_GeneratedCodeInfo_Annotation_clear_semantic(google_protobuf_GeneratedCodeInfo_Annotation* msg) { const upb_MiniTableField field = {5, UPB_SIZE(16, 12), 4, 0, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_GeneratedCodeInfo_Annotation_semantic(const google_protobuf_GeneratedCodeInfo_Annotation* msg) { int32_t default_val = 0; int32_t ret; const upb_MiniTableField field = {5, UPB_SIZE(16, 12), 4, 0, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_GeneratedCodeInfo_Annotation_has_semantic(const google_protobuf_GeneratedCodeInfo_Annotation* msg) { const upb_MiniTableField field = {5, UPB_SIZE(16, 12), 4, 0, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t* google_protobuf_GeneratedCodeInfo_Annotation_mutable_path(google_protobuf_GeneratedCodeInfo_Annotation* msg, size_t* size) { upb_MiniTableField field = {1, UPB_SIZE(4, 16), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsPacked | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetMutableArray(msg, &field); + upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (int32_t*)_upb_array_ptr(arr); @@ -10498,11 +10754,13 @@ UPB_INLINE int32_t* google_protobuf_GeneratedCodeInfo_Annotation_mutable_path(go } UPB_INLINE int32_t* google_protobuf_GeneratedCodeInfo_Annotation_resize_path(google_protobuf_GeneratedCodeInfo_Annotation* msg, size_t size, upb_Arena* arena) { upb_MiniTableField field = {1, UPB_SIZE(4, 16), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsPacked | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return (int32_t*)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); + return (int32_t*)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg), + &field, size, arena); } UPB_INLINE bool google_protobuf_GeneratedCodeInfo_Annotation_add_path(google_protobuf_GeneratedCodeInfo_Annotation* msg, int32_t val, upb_Arena* arena) { upb_MiniTableField field = {1, UPB_SIZE(4, 16), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsPacked | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray( + UPB_UPCAST(msg), &field, arena); if (!arr || !_upb_Array_ResizeUninitialized( arr, arr->UPB_PRIVATE(size) + 1, arena)) { return false; @@ -10513,19 +10771,19 @@ UPB_INLINE bool google_protobuf_GeneratedCodeInfo_Annotation_add_path(google_pro } UPB_INLINE void google_protobuf_GeneratedCodeInfo_Annotation_set_source_file(google_protobuf_GeneratedCodeInfo_Annotation *msg, upb_StringView value) { const upb_MiniTableField field = {2, UPB_SIZE(20, 24), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_GeneratedCodeInfo_Annotation_set_begin(google_protobuf_GeneratedCodeInfo_Annotation *msg, int32_t value) { const upb_MiniTableField field = {3, UPB_SIZE(8, 4), 2, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_GeneratedCodeInfo_Annotation_set_end(google_protobuf_GeneratedCodeInfo_Annotation *msg, int32_t value) { const upb_MiniTableField field = {4, UPB_SIZE(12, 8), 3, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_GeneratedCodeInfo_Annotation_set_semantic(google_protobuf_GeneratedCodeInfo_Annotation *msg, int32_t value) { const upb_MiniTableField field = {5, UPB_SIZE(16, 12), 4, 0, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } /* Max size 32 is google.protobuf.FileOptions */ diff --git a/ruby/ext/google/protobuf_c/ruby-upb.c b/ruby/ext/google/protobuf_c/ruby-upb.c index ecc7cedc714b9..efd6dd089ec2f 100644 --- a/ruby/ext/google/protobuf_c/ruby-upb.c +++ b/ruby/ext/google/protobuf_c/ruby-upb.c @@ -9686,7 +9686,8 @@ static void _upb_FieldDef_Create(upb_DefBuilder* ctx, const char* prefix, bool implicit = false; if (syntax != kUpb_Syntax_Editions) { - upb_Message_Clear(ctx->legacy_features, UPB_DESC_MINITABLE(FeatureSet)); + upb_Message_Clear(UPB_UPCAST(ctx->legacy_features), + UPB_DESC_MINITABLE(FeatureSet)); if (_upb_FieldDef_InferLegacyFeatures(ctx, f, field_proto, f->opts, syntax, ctx->legacy_features)) { implicit = true; @@ -10839,8 +10840,8 @@ bool _upb_DefBuilder_GetOrCreateFeatureSet(upb_DefBuilder* ctx, return false; } - *set = - upb_Message_DeepClone(parent, UPB_DESC_MINITABLE(FeatureSet), ctx->arena); + *set = (UPB_DESC(FeatureSet*))upb_Message_DeepClone( + UPB_UPCAST(parent), UPB_DESC_MINITABLE(FeatureSet), ctx->arena); if (!*set) _upb_DefBuilder_OomErr(ctx); v = upb_value_ptr(*set); @@ -10877,7 +10878,7 @@ const UPB_DESC(FeatureSet*) } upb_DecodeStatus dec_status = - upb_Decode(child_bytes, child_size, resolved, + upb_Decode(child_bytes, child_size, UPB_UPCAST(resolved), UPB_DESC_MINITABLE(FeatureSet), NULL, 0, ctx->arena); if (dec_status != kUpb_DecodeStatus_Ok) _upb_DefBuilder_OomErr(ctx); @@ -12916,18 +12917,18 @@ static const char* _upb_Decoder_DecodeToMap(upb_Decoder* d, const char* ptr, ent.data.v.val = upb_value_uintptr(msg); } - ptr = - _upb_Decoder_DecodeSubMessage(d, ptr, &ent.data, subs, field, val->size); + ptr = _upb_Decoder_DecodeSubMessage(d, ptr, (upb_Message*)&ent.data, subs, + field, val->size); // check if ent had any unknown fields size_t size; - upb_Message_GetUnknown(&ent.data, &size); + upb_Message_GetUnknown((upb_Message*)&ent.data, &size); if (size != 0) { char* buf; size_t size; uint32_t tag = ((uint32_t)field->UPB_PRIVATE(number) << 3) | kUpb_WireType_Delimited; upb_EncodeStatus status = - upb_Encode(&ent.data, entry, 0, &d->arena, &buf, &size); + upb_Encode((upb_Message*)&ent.data, entry, 0, &d->arena, &buf, &size); if (status != kUpb_EncodeStatus_Ok) { _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_OutOfMemory); } @@ -13429,7 +13430,7 @@ static const char* _upb_Decoder_DecodeKnownField( _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_OutOfMemory); } d->unknown_msg = msg; - msg = &ext->data; + msg = (upb_Message*)&ext->data; subs = &ext->ext->UPB_PRIVATE(sub); } @@ -13620,7 +13621,7 @@ static upb_DecodeStatus upb_Decoder_Decode(upb_Decoder* const decoder, return decoder->status; } -upb_DecodeStatus upb_Decode(const char* buf, size_t size, void* msg, +upb_DecodeStatus upb_Decode(const char* buf, size_t size, upb_Message* msg, const upb_MiniTable* l, const upb_ExtensionRegistry* extreg, int options, upb_Arena* arena) { @@ -15145,7 +15146,7 @@ static void encode_ext(upb_encstate* e, const upb_Extension* ext, if (UPB_UNLIKELY(is_message_set)) { encode_msgset_item(e, ext); } else { - encode_field(e, &ext->data, &ext->ext->UPB_PRIVATE(sub), + encode_field(e, (upb_Message*)&ext->data, &ext->ext->UPB_PRIVATE(sub), &ext->ext->UPB_PRIVATE(field)); } } @@ -15213,7 +15214,7 @@ static void encode_message(upb_encstate* e, const upb_Message* msg, } static upb_EncodeStatus upb_Encoder_Encode(upb_encstate* const encoder, - const void* const msg, + const upb_Message* const msg, const upb_MiniTable* const l, char** const buf, size_t* const size) { @@ -15241,7 +15242,7 @@ static upb_EncodeStatus upb_Encoder_Encode(upb_encstate* const encoder, return encoder->status; } -upb_EncodeStatus upb_Encode(const void* msg, const upb_MiniTable* l, +upb_EncodeStatus upb_Encode(const upb_Message* msg, const upb_MiniTable* l, int options, upb_Arena* arena, char** buf, size_t* size) { upb_encstate e; diff --git a/ruby/ext/google/protobuf_c/ruby-upb.h b/ruby/ext/google/protobuf_c/ruby-upb.h index 6f8c22bb881fb..3e2d23cc185a2 100755 --- a/ruby/ext/google/protobuf_c/ruby-upb.h +++ b/ruby/ext/google/protobuf_c/ruby-upb.h @@ -378,6 +378,27 @@ void upb_Status_VAppendErrorFormat(upb_Status* status, const char* fmt, // IWYU pragma: begin_exports +#ifndef UPB_BASE_UPCAST_H_ +#define UPB_BASE_UPCAST_H_ + +// Must be last. + +// This macro provides a way to upcast message pointers in a way that is +// somewhat more bulletproof than blindly casting a pointer. Example: +// +// typedef struct { +// upb_Message UPB_PRIVATE(base); +// } pkg_FooMessage; +// +// void f(pkg_FooMessage* msg) { +// upb_Decode(UPB_UPCAST(msg), ...); +// } + +#define UPB_UPCAST(x) (&(x)->base##_dont_copy_me__upb_internal_use_only) + + +#endif /* UPB_BASE_UPCAST_H_ */ + #ifndef UPB_MESSAGE_ACCESSORS_H_ #define UPB_MESSAGE_ACCESSORS_H_ @@ -810,7 +831,9 @@ UPB_API_INLINE void upb_Arena_ShrinkLast(upb_Arena* a, void* ptr, // This typedef is in a leaf header to resolve a circular dependency between // messages and mini tables. -typedef void upb_Message; +typedef struct upb_Message { + int unused; // Placeholder cuz Windows won't compile an empty struct. +} upb_Message; #endif /* UPB_MESSAGE_TYPES_H_ */ @@ -4169,9 +4192,9 @@ UPB_INLINE int upb_Encode_LimitDepth(uint32_t encode_options, uint32_t limit) { return upb_EncodeOptions_MaxDepth(max_depth) | (encode_options & 0xffff); } -UPB_API upb_EncodeStatus upb_Encode(const void* msg, const upb_MiniTable* l, - int options, upb_Arena* arena, char** buf, - size_t* size); +UPB_API upb_EncodeStatus upb_Encode(const upb_Message* msg, + const upb_MiniTable* l, int options, + upb_Arena* arena, char** buf, size_t* size); #ifdef __cplusplus } /* extern "C" */ @@ -4805,38 +4828,38 @@ void upb_inttable_removeiter(upb_inttable* t, intptr_t* iter); extern "C" { #endif -typedef struct google_protobuf_FileDescriptorSet google_protobuf_FileDescriptorSet; -typedef struct google_protobuf_FileDescriptorProto google_protobuf_FileDescriptorProto; -typedef struct google_protobuf_DescriptorProto google_protobuf_DescriptorProto; -typedef struct google_protobuf_DescriptorProto_ExtensionRange google_protobuf_DescriptorProto_ExtensionRange; -typedef struct google_protobuf_DescriptorProto_ReservedRange google_protobuf_DescriptorProto_ReservedRange; -typedef struct google_protobuf_ExtensionRangeOptions google_protobuf_ExtensionRangeOptions; -typedef struct google_protobuf_ExtensionRangeOptions_Declaration google_protobuf_ExtensionRangeOptions_Declaration; -typedef struct google_protobuf_FieldDescriptorProto google_protobuf_FieldDescriptorProto; -typedef struct google_protobuf_OneofDescriptorProto google_protobuf_OneofDescriptorProto; -typedef struct google_protobuf_EnumDescriptorProto google_protobuf_EnumDescriptorProto; -typedef struct google_protobuf_EnumDescriptorProto_EnumReservedRange google_protobuf_EnumDescriptorProto_EnumReservedRange; -typedef struct google_protobuf_EnumValueDescriptorProto google_protobuf_EnumValueDescriptorProto; -typedef struct google_protobuf_ServiceDescriptorProto google_protobuf_ServiceDescriptorProto; -typedef struct google_protobuf_MethodDescriptorProto google_protobuf_MethodDescriptorProto; -typedef struct google_protobuf_FileOptions google_protobuf_FileOptions; -typedef struct google_protobuf_MessageOptions google_protobuf_MessageOptions; -typedef struct google_protobuf_FieldOptions google_protobuf_FieldOptions; -typedef struct google_protobuf_FieldOptions_EditionDefault google_protobuf_FieldOptions_EditionDefault; -typedef struct google_protobuf_OneofOptions google_protobuf_OneofOptions; -typedef struct google_protobuf_EnumOptions google_protobuf_EnumOptions; -typedef struct google_protobuf_EnumValueOptions google_protobuf_EnumValueOptions; -typedef struct google_protobuf_ServiceOptions google_protobuf_ServiceOptions; -typedef struct google_protobuf_MethodOptions google_protobuf_MethodOptions; -typedef struct google_protobuf_UninterpretedOption google_protobuf_UninterpretedOption; -typedef struct google_protobuf_UninterpretedOption_NamePart google_protobuf_UninterpretedOption_NamePart; -typedef struct google_protobuf_FeatureSet google_protobuf_FeatureSet; -typedef struct google_protobuf_FeatureSetDefaults google_protobuf_FeatureSetDefaults; -typedef struct google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault; -typedef struct google_protobuf_SourceCodeInfo google_protobuf_SourceCodeInfo; -typedef struct google_protobuf_SourceCodeInfo_Location google_protobuf_SourceCodeInfo_Location; -typedef struct google_protobuf_GeneratedCodeInfo google_protobuf_GeneratedCodeInfo; -typedef struct google_protobuf_GeneratedCodeInfo_Annotation google_protobuf_GeneratedCodeInfo_Annotation; +typedef struct google_protobuf_FileDescriptorSet { upb_Message UPB_PRIVATE(base); } google_protobuf_FileDescriptorSet; +typedef struct google_protobuf_FileDescriptorProto { upb_Message UPB_PRIVATE(base); } google_protobuf_FileDescriptorProto; +typedef struct google_protobuf_DescriptorProto { upb_Message UPB_PRIVATE(base); } google_protobuf_DescriptorProto; +typedef struct google_protobuf_DescriptorProto_ExtensionRange { upb_Message UPB_PRIVATE(base); } google_protobuf_DescriptorProto_ExtensionRange; +typedef struct google_protobuf_DescriptorProto_ReservedRange { upb_Message UPB_PRIVATE(base); } google_protobuf_DescriptorProto_ReservedRange; +typedef struct google_protobuf_ExtensionRangeOptions { upb_Message UPB_PRIVATE(base); } google_protobuf_ExtensionRangeOptions; +typedef struct google_protobuf_ExtensionRangeOptions_Declaration { upb_Message UPB_PRIVATE(base); } google_protobuf_ExtensionRangeOptions_Declaration; +typedef struct google_protobuf_FieldDescriptorProto { upb_Message UPB_PRIVATE(base); } google_protobuf_FieldDescriptorProto; +typedef struct google_protobuf_OneofDescriptorProto { upb_Message UPB_PRIVATE(base); } google_protobuf_OneofDescriptorProto; +typedef struct google_protobuf_EnumDescriptorProto { upb_Message UPB_PRIVATE(base); } google_protobuf_EnumDescriptorProto; +typedef struct google_protobuf_EnumDescriptorProto_EnumReservedRange { upb_Message UPB_PRIVATE(base); } google_protobuf_EnumDescriptorProto_EnumReservedRange; +typedef struct google_protobuf_EnumValueDescriptorProto { upb_Message UPB_PRIVATE(base); } google_protobuf_EnumValueDescriptorProto; +typedef struct google_protobuf_ServiceDescriptorProto { upb_Message UPB_PRIVATE(base); } google_protobuf_ServiceDescriptorProto; +typedef struct google_protobuf_MethodDescriptorProto { upb_Message UPB_PRIVATE(base); } google_protobuf_MethodDescriptorProto; +typedef struct google_protobuf_FileOptions { upb_Message UPB_PRIVATE(base); } google_protobuf_FileOptions; +typedef struct google_protobuf_MessageOptions { upb_Message UPB_PRIVATE(base); } google_protobuf_MessageOptions; +typedef struct google_protobuf_FieldOptions { upb_Message UPB_PRIVATE(base); } google_protobuf_FieldOptions; +typedef struct google_protobuf_FieldOptions_EditionDefault { upb_Message UPB_PRIVATE(base); } google_protobuf_FieldOptions_EditionDefault; +typedef struct google_protobuf_OneofOptions { upb_Message UPB_PRIVATE(base); } google_protobuf_OneofOptions; +typedef struct google_protobuf_EnumOptions { upb_Message UPB_PRIVATE(base); } google_protobuf_EnumOptions; +typedef struct google_protobuf_EnumValueOptions { upb_Message UPB_PRIVATE(base); } google_protobuf_EnumValueOptions; +typedef struct google_protobuf_ServiceOptions { upb_Message UPB_PRIVATE(base); } google_protobuf_ServiceOptions; +typedef struct google_protobuf_MethodOptions { upb_Message UPB_PRIVATE(base); } google_protobuf_MethodOptions; +typedef struct google_protobuf_UninterpretedOption { upb_Message UPB_PRIVATE(base); } google_protobuf_UninterpretedOption; +typedef struct google_protobuf_UninterpretedOption_NamePart { upb_Message UPB_PRIVATE(base); } google_protobuf_UninterpretedOption_NamePart; +typedef struct google_protobuf_FeatureSet { upb_Message UPB_PRIVATE(base); } google_protobuf_FeatureSet; +typedef struct google_protobuf_FeatureSetDefaults { upb_Message UPB_PRIVATE(base); } google_protobuf_FeatureSetDefaults; +typedef struct google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault { upb_Message UPB_PRIVATE(base); } google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault; +typedef struct google_protobuf_SourceCodeInfo { upb_Message UPB_PRIVATE(base); } google_protobuf_SourceCodeInfo; +typedef struct google_protobuf_SourceCodeInfo_Location { upb_Message UPB_PRIVATE(base); } google_protobuf_SourceCodeInfo_Location; +typedef struct google_protobuf_GeneratedCodeInfo { upb_Message UPB_PRIVATE(base); } google_protobuf_GeneratedCodeInfo; +typedef struct google_protobuf_GeneratedCodeInfo_Annotation { upb_Message UPB_PRIVATE(base); } google_protobuf_GeneratedCodeInfo_Annotation; typedef enum { google_protobuf_EDITION_UNKNOWN = 0, @@ -4979,7 +5002,8 @@ UPB_INLINE google_protobuf_FileDescriptorSet* google_protobuf_FileDescriptorSet_ UPB_INLINE google_protobuf_FileDescriptorSet* google_protobuf_FileDescriptorSet_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_FileDescriptorSet* ret = google_protobuf_FileDescriptorSet_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__FileDescriptorSet_msg_init, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__FileDescriptorSet_msg_init, NULL, 0, arena) != + kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -4989,30 +5013,30 @@ UPB_INLINE google_protobuf_FileDescriptorSet* google_protobuf_FileDescriptorSet_ int options, upb_Arena* arena) { google_protobuf_FileDescriptorSet* ret = google_protobuf_FileDescriptorSet_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__FileDescriptorSet_msg_init, extreg, options, arena) != - kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__FileDescriptorSet_msg_init, extreg, options, + arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_FileDescriptorSet_serialize(const google_protobuf_FileDescriptorSet* msg, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__FileDescriptorSet_msg_init, 0, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__FileDescriptorSet_msg_init, 0, arena, &ptr, len); return ptr; } UPB_INLINE char* google_protobuf_FileDescriptorSet_serialize_ex(const google_protobuf_FileDescriptorSet* msg, int options, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__FileDescriptorSet_msg_init, options, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__FileDescriptorSet_msg_init, options, arena, &ptr, len); return ptr; } UPB_INLINE void google_protobuf_FileDescriptorSet_clear_file(google_protobuf_FileDescriptorSet* msg) { const upb_MiniTableField field = {1, 0, 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_FileDescriptorProto* const* google_protobuf_FileDescriptorSet_file(const google_protobuf_FileDescriptorSet* msg, size_t* size) { const upb_MiniTableField field = {1, 0, 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_FileDescriptorProto* const*)_upb_array_constptr(arr); @@ -5023,16 +5047,16 @@ UPB_INLINE const google_protobuf_FileDescriptorProto* const* google_protobuf_Fil } UPB_INLINE const upb_Array* _google_protobuf_FileDescriptorSet_file_upb_array(const google_protobuf_FileDescriptorSet* msg, size_t* size) { const upb_MiniTableField field = {1, 0, 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } -UPB_INLINE upb_Array* _google_protobuf_FileDescriptorSet_file_mutable_upb_array(const google_protobuf_FileDescriptorSet* msg, size_t* size, upb_Arena* arena) { +UPB_INLINE upb_Array* _google_protobuf_FileDescriptorSet_file_mutable_upb_array(google_protobuf_FileDescriptorSet* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = {1, 0, 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - (upb_Message*)msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), + &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -5041,7 +5065,7 @@ UPB_INLINE upb_Array* _google_protobuf_FileDescriptorSet_file_mutable_upb_array( UPB_INLINE google_protobuf_FileDescriptorProto** google_protobuf_FileDescriptorSet_mutable_file(google_protobuf_FileDescriptorSet* msg, size_t* size) { upb_MiniTableField field = {1, 0, 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetMutableArray(msg, &field); + upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_FileDescriptorProto**)_upb_array_ptr(arr); @@ -5052,11 +5076,13 @@ UPB_INLINE google_protobuf_FileDescriptorProto** google_protobuf_FileDescriptorS } UPB_INLINE google_protobuf_FileDescriptorProto** google_protobuf_FileDescriptorSet_resize_file(google_protobuf_FileDescriptorSet* msg, size_t size, upb_Arena* arena) { upb_MiniTableField field = {1, 0, 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return (google_protobuf_FileDescriptorProto**)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); + return (google_protobuf_FileDescriptorProto**)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg), + &field, size, arena); } UPB_INLINE struct google_protobuf_FileDescriptorProto* google_protobuf_FileDescriptorSet_add_file(google_protobuf_FileDescriptorSet* msg, upb_Arena* arena) { upb_MiniTableField field = {1, 0, 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray( + UPB_UPCAST(msg), &field, arena); if (!arr || !_upb_Array_ResizeUninitialized( arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; @@ -5076,7 +5102,8 @@ UPB_INLINE google_protobuf_FileDescriptorProto* google_protobuf_FileDescriptorPr UPB_INLINE google_protobuf_FileDescriptorProto* google_protobuf_FileDescriptorProto_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_FileDescriptorProto* ret = google_protobuf_FileDescriptorProto_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__FileDescriptorProto_msg_init, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__FileDescriptorProto_msg_init, NULL, 0, arena) != + kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -5086,60 +5113,62 @@ UPB_INLINE google_protobuf_FileDescriptorProto* google_protobuf_FileDescriptorPr int options, upb_Arena* arena) { google_protobuf_FileDescriptorProto* ret = google_protobuf_FileDescriptorProto_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__FileDescriptorProto_msg_init, extreg, options, arena) != - kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__FileDescriptorProto_msg_init, extreg, options, + arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_FileDescriptorProto_serialize(const google_protobuf_FileDescriptorProto* msg, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__FileDescriptorProto_msg_init, 0, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__FileDescriptorProto_msg_init, 0, arena, &ptr, len); return ptr; } UPB_INLINE char* google_protobuf_FileDescriptorProto_serialize_ex(const google_protobuf_FileDescriptorProto* msg, int options, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__FileDescriptorProto_msg_init, options, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__FileDescriptorProto_msg_init, options, arena, &ptr, len); return ptr; } UPB_INLINE void google_protobuf_FileDescriptorProto_clear_name(google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = {1, UPB_SIZE(44, 8), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_FileDescriptorProto_name(const google_protobuf_FileDescriptorProto* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; const upb_MiniTableField field = {1, UPB_SIZE(44, 8), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FileDescriptorProto_has_name(const google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = {1, UPB_SIZE(44, 8), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileDescriptorProto_clear_package(google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = {2, UPB_SIZE(52, 24), 2, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_FileDescriptorProto_package(const google_protobuf_FileDescriptorProto* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; const upb_MiniTableField field = {2, UPB_SIZE(52, 24), 2, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FileDescriptorProto_has_package(const google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = {2, UPB_SIZE(52, 24), 2, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileDescriptorProto_clear_dependency(google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = {3, UPB_SIZE(4, 40), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView const* google_protobuf_FileDescriptorProto_dependency(const google_protobuf_FileDescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {3, UPB_SIZE(4, 40), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (upb_StringView const*)_upb_array_constptr(arr); @@ -5150,16 +5179,16 @@ UPB_INLINE upb_StringView const* google_protobuf_FileDescriptorProto_dependency( } UPB_INLINE const upb_Array* _google_protobuf_FileDescriptorProto_dependency_upb_array(const google_protobuf_FileDescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {3, UPB_SIZE(4, 40), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } -UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_dependency_mutable_upb_array(const google_protobuf_FileDescriptorProto* msg, size_t* size, upb_Arena* arena) { +UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_dependency_mutable_upb_array(google_protobuf_FileDescriptorProto* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = {3, UPB_SIZE(4, 40), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - (upb_Message*)msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), + &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -5167,11 +5196,11 @@ UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_dependency_mutable_up } UPB_INLINE void google_protobuf_FileDescriptorProto_clear_message_type(google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = {4, UPB_SIZE(8, 48), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_DescriptorProto* const* google_protobuf_FileDescriptorProto_message_type(const google_protobuf_FileDescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {4, UPB_SIZE(8, 48), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_DescriptorProto* const*)_upb_array_constptr(arr); @@ -5182,16 +5211,16 @@ UPB_INLINE const google_protobuf_DescriptorProto* const* google_protobuf_FileDes } UPB_INLINE const upb_Array* _google_protobuf_FileDescriptorProto_message_type_upb_array(const google_protobuf_FileDescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {4, UPB_SIZE(8, 48), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } -UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_message_type_mutable_upb_array(const google_protobuf_FileDescriptorProto* msg, size_t* size, upb_Arena* arena) { +UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_message_type_mutable_upb_array(google_protobuf_FileDescriptorProto* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = {4, UPB_SIZE(8, 48), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - (upb_Message*)msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), + &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -5199,11 +5228,11 @@ UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_message_type_mutable_ } UPB_INLINE void google_protobuf_FileDescriptorProto_clear_enum_type(google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = {5, UPB_SIZE(12, 56), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_EnumDescriptorProto* const* google_protobuf_FileDescriptorProto_enum_type(const google_protobuf_FileDescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {5, UPB_SIZE(12, 56), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_EnumDescriptorProto* const*)_upb_array_constptr(arr); @@ -5214,16 +5243,16 @@ UPB_INLINE const google_protobuf_EnumDescriptorProto* const* google_protobuf_Fil } UPB_INLINE const upb_Array* _google_protobuf_FileDescriptorProto_enum_type_upb_array(const google_protobuf_FileDescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {5, UPB_SIZE(12, 56), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } -UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_enum_type_mutable_upb_array(const google_protobuf_FileDescriptorProto* msg, size_t* size, upb_Arena* arena) { +UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_enum_type_mutable_upb_array(google_protobuf_FileDescriptorProto* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = {5, UPB_SIZE(12, 56), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - (upb_Message*)msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), + &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -5231,11 +5260,11 @@ UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_enum_type_mutable_upb } UPB_INLINE void google_protobuf_FileDescriptorProto_clear_service(google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = {6, UPB_SIZE(16, 64), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_ServiceDescriptorProto* const* google_protobuf_FileDescriptorProto_service(const google_protobuf_FileDescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {6, UPB_SIZE(16, 64), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_ServiceDescriptorProto* const*)_upb_array_constptr(arr); @@ -5246,16 +5275,16 @@ UPB_INLINE const google_protobuf_ServiceDescriptorProto* const* google_protobuf_ } UPB_INLINE const upb_Array* _google_protobuf_FileDescriptorProto_service_upb_array(const google_protobuf_FileDescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {6, UPB_SIZE(16, 64), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } -UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_service_mutable_upb_array(const google_protobuf_FileDescriptorProto* msg, size_t* size, upb_Arena* arena) { +UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_service_mutable_upb_array(google_protobuf_FileDescriptorProto* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = {6, UPB_SIZE(16, 64), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - (upb_Message*)msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), + &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -5263,11 +5292,11 @@ UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_service_mutable_upb_a } UPB_INLINE void google_protobuf_FileDescriptorProto_clear_extension(google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = {7, UPB_SIZE(20, 72), 0, 3, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_FieldDescriptorProto* const* google_protobuf_FileDescriptorProto_extension(const google_protobuf_FileDescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {7, UPB_SIZE(20, 72), 0, 3, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_FieldDescriptorProto* const*)_upb_array_constptr(arr); @@ -5278,16 +5307,16 @@ UPB_INLINE const google_protobuf_FieldDescriptorProto* const* google_protobuf_Fi } UPB_INLINE const upb_Array* _google_protobuf_FileDescriptorProto_extension_upb_array(const google_protobuf_FileDescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {7, UPB_SIZE(20, 72), 0, 3, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } -UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_extension_mutable_upb_array(const google_protobuf_FileDescriptorProto* msg, size_t* size, upb_Arena* arena) { +UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_extension_mutable_upb_array(google_protobuf_FileDescriptorProto* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = {7, UPB_SIZE(20, 72), 0, 3, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - (upb_Message*)msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), + &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -5295,41 +5324,43 @@ UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_extension_mutable_upb } UPB_INLINE void google_protobuf_FileDescriptorProto_clear_options(google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = {8, UPB_SIZE(24, 80), 3, 4, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_FileOptions* google_protobuf_FileDescriptorProto_options(const google_protobuf_FileDescriptorProto* msg) { const google_protobuf_FileOptions* default_val = NULL; const google_protobuf_FileOptions* ret; const upb_MiniTableField field = {8, UPB_SIZE(24, 80), 3, 4, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FileDescriptorProto_has_options(const google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = {8, UPB_SIZE(24, 80), 3, 4, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileDescriptorProto_clear_source_code_info(google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = {9, UPB_SIZE(28, 88), 4, 5, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_SourceCodeInfo* google_protobuf_FileDescriptorProto_source_code_info(const google_protobuf_FileDescriptorProto* msg) { const google_protobuf_SourceCodeInfo* default_val = NULL; const google_protobuf_SourceCodeInfo* ret; const upb_MiniTableField field = {9, UPB_SIZE(28, 88), 4, 5, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FileDescriptorProto_has_source_code_info(const google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = {9, UPB_SIZE(28, 88), 4, 5, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileDescriptorProto_clear_public_dependency(google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = {10, UPB_SIZE(32, 96), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t const* google_protobuf_FileDescriptorProto_public_dependency(const google_protobuf_FileDescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {10, UPB_SIZE(32, 96), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (int32_t const*)_upb_array_constptr(arr); @@ -5340,16 +5371,16 @@ UPB_INLINE int32_t const* google_protobuf_FileDescriptorProto_public_dependency( } UPB_INLINE const upb_Array* _google_protobuf_FileDescriptorProto_public_dependency_upb_array(const google_protobuf_FileDescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {10, UPB_SIZE(32, 96), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } -UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_public_dependency_mutable_upb_array(const google_protobuf_FileDescriptorProto* msg, size_t* size, upb_Arena* arena) { +UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_public_dependency_mutable_upb_array(google_protobuf_FileDescriptorProto* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = {10, UPB_SIZE(32, 96), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - (upb_Message*)msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), + &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -5357,11 +5388,11 @@ UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_public_dependency_mut } UPB_INLINE void google_protobuf_FileDescriptorProto_clear_weak_dependency(google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = {11, UPB_SIZE(36, 104), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t const* google_protobuf_FileDescriptorProto_weak_dependency(const google_protobuf_FileDescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {11, UPB_SIZE(36, 104), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (int32_t const*)_upb_array_constptr(arr); @@ -5372,16 +5403,16 @@ UPB_INLINE int32_t const* google_protobuf_FileDescriptorProto_weak_dependency(co } UPB_INLINE const upb_Array* _google_protobuf_FileDescriptorProto_weak_dependency_upb_array(const google_protobuf_FileDescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {11, UPB_SIZE(36, 104), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } -UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_weak_dependency_mutable_upb_array(const google_protobuf_FileDescriptorProto* msg, size_t* size, upb_Arena* arena) { +UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_weak_dependency_mutable_upb_array(google_protobuf_FileDescriptorProto* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = {11, UPB_SIZE(36, 104), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - (upb_Message*)msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), + &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -5389,46 +5420,48 @@ UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_weak_dependency_mutab } UPB_INLINE void google_protobuf_FileDescriptorProto_clear_syntax(google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = {12, UPB_SIZE(60, 112), 5, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_FileDescriptorProto_syntax(const google_protobuf_FileDescriptorProto* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; const upb_MiniTableField field = {12, UPB_SIZE(60, 112), 5, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FileDescriptorProto_has_syntax(const google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = {12, UPB_SIZE(60, 112), 5, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileDescriptorProto_clear_edition(google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = {14, UPB_SIZE(40, 4), 6, 6, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_FileDescriptorProto_edition(const google_protobuf_FileDescriptorProto* msg) { int32_t default_val = 0; int32_t ret; const upb_MiniTableField field = {14, UPB_SIZE(40, 4), 6, 6, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FileDescriptorProto_has_edition(const google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = {14, UPB_SIZE(40, 4), 6, 6, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileDescriptorProto_set_name(google_protobuf_FileDescriptorProto *msg, upb_StringView value) { const upb_MiniTableField field = {1, UPB_SIZE(44, 8), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FileDescriptorProto_set_package(google_protobuf_FileDescriptorProto *msg, upb_StringView value) { const upb_MiniTableField field = {2, UPB_SIZE(52, 24), 2, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE upb_StringView* google_protobuf_FileDescriptorProto_mutable_dependency(google_protobuf_FileDescriptorProto* msg, size_t* size) { upb_MiniTableField field = {3, UPB_SIZE(4, 40), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetMutableArray(msg, &field); + upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (upb_StringView*)_upb_array_ptr(arr); @@ -5439,11 +5472,13 @@ UPB_INLINE upb_StringView* google_protobuf_FileDescriptorProto_mutable_dependenc } UPB_INLINE upb_StringView* google_protobuf_FileDescriptorProto_resize_dependency(google_protobuf_FileDescriptorProto* msg, size_t size, upb_Arena* arena) { upb_MiniTableField field = {3, UPB_SIZE(4, 40), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return (upb_StringView*)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); + return (upb_StringView*)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg), + &field, size, arena); } UPB_INLINE bool google_protobuf_FileDescriptorProto_add_dependency(google_protobuf_FileDescriptorProto* msg, upb_StringView val, upb_Arena* arena) { upb_MiniTableField field = {3, UPB_SIZE(4, 40), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray( + UPB_UPCAST(msg), &field, arena); if (!arr || !_upb_Array_ResizeUninitialized( arr, arr->UPB_PRIVATE(size) + 1, arena)) { return false; @@ -5454,7 +5489,7 @@ UPB_INLINE bool google_protobuf_FileDescriptorProto_add_dependency(google_protob } UPB_INLINE google_protobuf_DescriptorProto** google_protobuf_FileDescriptorProto_mutable_message_type(google_protobuf_FileDescriptorProto* msg, size_t* size) { upb_MiniTableField field = {4, UPB_SIZE(8, 48), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetMutableArray(msg, &field); + upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_DescriptorProto**)_upb_array_ptr(arr); @@ -5465,11 +5500,13 @@ UPB_INLINE google_protobuf_DescriptorProto** google_protobuf_FileDescriptorProto } UPB_INLINE google_protobuf_DescriptorProto** google_protobuf_FileDescriptorProto_resize_message_type(google_protobuf_FileDescriptorProto* msg, size_t size, upb_Arena* arena) { upb_MiniTableField field = {4, UPB_SIZE(8, 48), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return (google_protobuf_DescriptorProto**)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); + return (google_protobuf_DescriptorProto**)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg), + &field, size, arena); } UPB_INLINE struct google_protobuf_DescriptorProto* google_protobuf_FileDescriptorProto_add_message_type(google_protobuf_FileDescriptorProto* msg, upb_Arena* arena) { upb_MiniTableField field = {4, UPB_SIZE(8, 48), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray( + UPB_UPCAST(msg), &field, arena); if (!arr || !_upb_Array_ResizeUninitialized( arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; @@ -5482,7 +5519,7 @@ UPB_INLINE struct google_protobuf_DescriptorProto* google_protobuf_FileDescripto } UPB_INLINE google_protobuf_EnumDescriptorProto** google_protobuf_FileDescriptorProto_mutable_enum_type(google_protobuf_FileDescriptorProto* msg, size_t* size) { upb_MiniTableField field = {5, UPB_SIZE(12, 56), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetMutableArray(msg, &field); + upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_EnumDescriptorProto**)_upb_array_ptr(arr); @@ -5493,11 +5530,13 @@ UPB_INLINE google_protobuf_EnumDescriptorProto** google_protobuf_FileDescriptorP } UPB_INLINE google_protobuf_EnumDescriptorProto** google_protobuf_FileDescriptorProto_resize_enum_type(google_protobuf_FileDescriptorProto* msg, size_t size, upb_Arena* arena) { upb_MiniTableField field = {5, UPB_SIZE(12, 56), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return (google_protobuf_EnumDescriptorProto**)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); + return (google_protobuf_EnumDescriptorProto**)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg), + &field, size, arena); } UPB_INLINE struct google_protobuf_EnumDescriptorProto* google_protobuf_FileDescriptorProto_add_enum_type(google_protobuf_FileDescriptorProto* msg, upb_Arena* arena) { upb_MiniTableField field = {5, UPB_SIZE(12, 56), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray( + UPB_UPCAST(msg), &field, arena); if (!arr || !_upb_Array_ResizeUninitialized( arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; @@ -5510,7 +5549,7 @@ UPB_INLINE struct google_protobuf_EnumDescriptorProto* google_protobuf_FileDescr } UPB_INLINE google_protobuf_ServiceDescriptorProto** google_protobuf_FileDescriptorProto_mutable_service(google_protobuf_FileDescriptorProto* msg, size_t* size) { upb_MiniTableField field = {6, UPB_SIZE(16, 64), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetMutableArray(msg, &field); + upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_ServiceDescriptorProto**)_upb_array_ptr(arr); @@ -5521,11 +5560,13 @@ UPB_INLINE google_protobuf_ServiceDescriptorProto** google_protobuf_FileDescript } UPB_INLINE google_protobuf_ServiceDescriptorProto** google_protobuf_FileDescriptorProto_resize_service(google_protobuf_FileDescriptorProto* msg, size_t size, upb_Arena* arena) { upb_MiniTableField field = {6, UPB_SIZE(16, 64), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return (google_protobuf_ServiceDescriptorProto**)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); + return (google_protobuf_ServiceDescriptorProto**)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg), + &field, size, arena); } UPB_INLINE struct google_protobuf_ServiceDescriptorProto* google_protobuf_FileDescriptorProto_add_service(google_protobuf_FileDescriptorProto* msg, upb_Arena* arena) { upb_MiniTableField field = {6, UPB_SIZE(16, 64), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray( + UPB_UPCAST(msg), &field, arena); if (!arr || !_upb_Array_ResizeUninitialized( arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; @@ -5538,7 +5579,7 @@ UPB_INLINE struct google_protobuf_ServiceDescriptorProto* google_protobuf_FileDe } UPB_INLINE google_protobuf_FieldDescriptorProto** google_protobuf_FileDescriptorProto_mutable_extension(google_protobuf_FileDescriptorProto* msg, size_t* size) { upb_MiniTableField field = {7, UPB_SIZE(20, 72), 0, 3, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetMutableArray(msg, &field); + upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_FieldDescriptorProto**)_upb_array_ptr(arr); @@ -5549,11 +5590,13 @@ UPB_INLINE google_protobuf_FieldDescriptorProto** google_protobuf_FileDescriptor } UPB_INLINE google_protobuf_FieldDescriptorProto** google_protobuf_FileDescriptorProto_resize_extension(google_protobuf_FileDescriptorProto* msg, size_t size, upb_Arena* arena) { upb_MiniTableField field = {7, UPB_SIZE(20, 72), 0, 3, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return (google_protobuf_FieldDescriptorProto**)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); + return (google_protobuf_FieldDescriptorProto**)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg), + &field, size, arena); } UPB_INLINE struct google_protobuf_FieldDescriptorProto* google_protobuf_FileDescriptorProto_add_extension(google_protobuf_FileDescriptorProto* msg, upb_Arena* arena) { upb_MiniTableField field = {7, UPB_SIZE(20, 72), 0, 3, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray( + UPB_UPCAST(msg), &field, arena); if (!arr || !_upb_Array_ResizeUninitialized( arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; @@ -5566,7 +5609,7 @@ UPB_INLINE struct google_protobuf_FieldDescriptorProto* google_protobuf_FileDesc } UPB_INLINE void google_protobuf_FileDescriptorProto_set_options(google_protobuf_FileDescriptorProto *msg, google_protobuf_FileOptions* value) { const upb_MiniTableField field = {8, UPB_SIZE(24, 80), 3, 4, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE struct google_protobuf_FileOptions* google_protobuf_FileDescriptorProto_mutable_options(google_protobuf_FileDescriptorProto* msg, upb_Arena* arena) { struct google_protobuf_FileOptions* sub = (struct google_protobuf_FileOptions*)google_protobuf_FileDescriptorProto_options(msg); @@ -5578,7 +5621,7 @@ UPB_INLINE struct google_protobuf_FileOptions* google_protobuf_FileDescriptorPro } UPB_INLINE void google_protobuf_FileDescriptorProto_set_source_code_info(google_protobuf_FileDescriptorProto *msg, google_protobuf_SourceCodeInfo* value) { const upb_MiniTableField field = {9, UPB_SIZE(28, 88), 4, 5, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE struct google_protobuf_SourceCodeInfo* google_protobuf_FileDescriptorProto_mutable_source_code_info(google_protobuf_FileDescriptorProto* msg, upb_Arena* arena) { struct google_protobuf_SourceCodeInfo* sub = (struct google_protobuf_SourceCodeInfo*)google_protobuf_FileDescriptorProto_source_code_info(msg); @@ -5590,7 +5633,7 @@ UPB_INLINE struct google_protobuf_SourceCodeInfo* google_protobuf_FileDescriptor } UPB_INLINE int32_t* google_protobuf_FileDescriptorProto_mutable_public_dependency(google_protobuf_FileDescriptorProto* msg, size_t* size) { upb_MiniTableField field = {10, UPB_SIZE(32, 96), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetMutableArray(msg, &field); + upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (int32_t*)_upb_array_ptr(arr); @@ -5601,11 +5644,13 @@ UPB_INLINE int32_t* google_protobuf_FileDescriptorProto_mutable_public_dependenc } UPB_INLINE int32_t* google_protobuf_FileDescriptorProto_resize_public_dependency(google_protobuf_FileDescriptorProto* msg, size_t size, upb_Arena* arena) { upb_MiniTableField field = {10, UPB_SIZE(32, 96), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return (int32_t*)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); + return (int32_t*)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg), + &field, size, arena); } UPB_INLINE bool google_protobuf_FileDescriptorProto_add_public_dependency(google_protobuf_FileDescriptorProto* msg, int32_t val, upb_Arena* arena) { upb_MiniTableField field = {10, UPB_SIZE(32, 96), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray( + UPB_UPCAST(msg), &field, arena); if (!arr || !_upb_Array_ResizeUninitialized( arr, arr->UPB_PRIVATE(size) + 1, arena)) { return false; @@ -5616,7 +5661,7 @@ UPB_INLINE bool google_protobuf_FileDescriptorProto_add_public_dependency(google } UPB_INLINE int32_t* google_protobuf_FileDescriptorProto_mutable_weak_dependency(google_protobuf_FileDescriptorProto* msg, size_t* size) { upb_MiniTableField field = {11, UPB_SIZE(36, 104), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetMutableArray(msg, &field); + upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (int32_t*)_upb_array_ptr(arr); @@ -5627,11 +5672,13 @@ UPB_INLINE int32_t* google_protobuf_FileDescriptorProto_mutable_weak_dependency( } UPB_INLINE int32_t* google_protobuf_FileDescriptorProto_resize_weak_dependency(google_protobuf_FileDescriptorProto* msg, size_t size, upb_Arena* arena) { upb_MiniTableField field = {11, UPB_SIZE(36, 104), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return (int32_t*)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); + return (int32_t*)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg), + &field, size, arena); } UPB_INLINE bool google_protobuf_FileDescriptorProto_add_weak_dependency(google_protobuf_FileDescriptorProto* msg, int32_t val, upb_Arena* arena) { upb_MiniTableField field = {11, UPB_SIZE(36, 104), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray( + UPB_UPCAST(msg), &field, arena); if (!arr || !_upb_Array_ResizeUninitialized( arr, arr->UPB_PRIVATE(size) + 1, arena)) { return false; @@ -5642,11 +5689,11 @@ UPB_INLINE bool google_protobuf_FileDescriptorProto_add_weak_dependency(google_p } UPB_INLINE void google_protobuf_FileDescriptorProto_set_syntax(google_protobuf_FileDescriptorProto *msg, upb_StringView value) { const upb_MiniTableField field = {12, UPB_SIZE(60, 112), 5, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FileDescriptorProto_set_edition(google_protobuf_FileDescriptorProto *msg, int32_t value) { const upb_MiniTableField field = {14, UPB_SIZE(40, 4), 6, 6, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } /* google.protobuf.DescriptorProto */ @@ -5657,7 +5704,8 @@ UPB_INLINE google_protobuf_DescriptorProto* google_protobuf_DescriptorProto_new( UPB_INLINE google_protobuf_DescriptorProto* google_protobuf_DescriptorProto_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_DescriptorProto* ret = google_protobuf_DescriptorProto_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__DescriptorProto_msg_init, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__DescriptorProto_msg_init, NULL, 0, arena) != + kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -5667,45 +5715,46 @@ UPB_INLINE google_protobuf_DescriptorProto* google_protobuf_DescriptorProto_pars int options, upb_Arena* arena) { google_protobuf_DescriptorProto* ret = google_protobuf_DescriptorProto_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__DescriptorProto_msg_init, extreg, options, arena) != - kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__DescriptorProto_msg_init, extreg, options, + arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_DescriptorProto_serialize(const google_protobuf_DescriptorProto* msg, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__DescriptorProto_msg_init, 0, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__DescriptorProto_msg_init, 0, arena, &ptr, len); return ptr; } UPB_INLINE char* google_protobuf_DescriptorProto_serialize_ex(const google_protobuf_DescriptorProto* msg, int options, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__DescriptorProto_msg_init, options, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__DescriptorProto_msg_init, options, arena, &ptr, len); return ptr; } UPB_INLINE void google_protobuf_DescriptorProto_clear_name(google_protobuf_DescriptorProto* msg) { const upb_MiniTableField field = {1, UPB_SIZE(40, 8), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_DescriptorProto_name(const google_protobuf_DescriptorProto* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; const upb_MiniTableField field = {1, UPB_SIZE(40, 8), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_DescriptorProto_has_name(const google_protobuf_DescriptorProto* msg) { const upb_MiniTableField field = {1, UPB_SIZE(40, 8), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_DescriptorProto_clear_field(google_protobuf_DescriptorProto* msg) { const upb_MiniTableField field = {2, UPB_SIZE(4, 24), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_FieldDescriptorProto* const* google_protobuf_DescriptorProto_field(const google_protobuf_DescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {2, UPB_SIZE(4, 24), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_FieldDescriptorProto* const*)_upb_array_constptr(arr); @@ -5716,16 +5765,16 @@ UPB_INLINE const google_protobuf_FieldDescriptorProto* const* google_protobuf_De } UPB_INLINE const upb_Array* _google_protobuf_DescriptorProto_field_upb_array(const google_protobuf_DescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {2, UPB_SIZE(4, 24), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } -UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_field_mutable_upb_array(const google_protobuf_DescriptorProto* msg, size_t* size, upb_Arena* arena) { +UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_field_mutable_upb_array(google_protobuf_DescriptorProto* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = {2, UPB_SIZE(4, 24), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - (upb_Message*)msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), + &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -5733,11 +5782,11 @@ UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_field_mutable_upb_array(c } UPB_INLINE void google_protobuf_DescriptorProto_clear_nested_type(google_protobuf_DescriptorProto* msg) { const upb_MiniTableField field = {3, UPB_SIZE(8, 32), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_DescriptorProto* const* google_protobuf_DescriptorProto_nested_type(const google_protobuf_DescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {3, UPB_SIZE(8, 32), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_DescriptorProto* const*)_upb_array_constptr(arr); @@ -5748,16 +5797,16 @@ UPB_INLINE const google_protobuf_DescriptorProto* const* google_protobuf_Descrip } UPB_INLINE const upb_Array* _google_protobuf_DescriptorProto_nested_type_upb_array(const google_protobuf_DescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {3, UPB_SIZE(8, 32), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } -UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_nested_type_mutable_upb_array(const google_protobuf_DescriptorProto* msg, size_t* size, upb_Arena* arena) { +UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_nested_type_mutable_upb_array(google_protobuf_DescriptorProto* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = {3, UPB_SIZE(8, 32), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - (upb_Message*)msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), + &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -5765,11 +5814,11 @@ UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_nested_type_mutable_upb_a } UPB_INLINE void google_protobuf_DescriptorProto_clear_enum_type(google_protobuf_DescriptorProto* msg) { const upb_MiniTableField field = {4, UPB_SIZE(12, 40), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_EnumDescriptorProto* const* google_protobuf_DescriptorProto_enum_type(const google_protobuf_DescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {4, UPB_SIZE(12, 40), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_EnumDescriptorProto* const*)_upb_array_constptr(arr); @@ -5780,16 +5829,16 @@ UPB_INLINE const google_protobuf_EnumDescriptorProto* const* google_protobuf_Des } UPB_INLINE const upb_Array* _google_protobuf_DescriptorProto_enum_type_upb_array(const google_protobuf_DescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {4, UPB_SIZE(12, 40), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } -UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_enum_type_mutable_upb_array(const google_protobuf_DescriptorProto* msg, size_t* size, upb_Arena* arena) { +UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_enum_type_mutable_upb_array(google_protobuf_DescriptorProto* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = {4, UPB_SIZE(12, 40), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - (upb_Message*)msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), + &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -5797,11 +5846,11 @@ UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_enum_type_mutable_upb_arr } UPB_INLINE void google_protobuf_DescriptorProto_clear_extension_range(google_protobuf_DescriptorProto* msg) { const upb_MiniTableField field = {5, UPB_SIZE(16, 48), 0, 3, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_DescriptorProto_ExtensionRange* const* google_protobuf_DescriptorProto_extension_range(const google_protobuf_DescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {5, UPB_SIZE(16, 48), 0, 3, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_DescriptorProto_ExtensionRange* const*)_upb_array_constptr(arr); @@ -5812,16 +5861,16 @@ UPB_INLINE const google_protobuf_DescriptorProto_ExtensionRange* const* google_p } UPB_INLINE const upb_Array* _google_protobuf_DescriptorProto_extension_range_upb_array(const google_protobuf_DescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {5, UPB_SIZE(16, 48), 0, 3, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } -UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_extension_range_mutable_upb_array(const google_protobuf_DescriptorProto* msg, size_t* size, upb_Arena* arena) { +UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_extension_range_mutable_upb_array(google_protobuf_DescriptorProto* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = {5, UPB_SIZE(16, 48), 0, 3, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - (upb_Message*)msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), + &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -5829,11 +5878,11 @@ UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_extension_range_mutable_u } UPB_INLINE void google_protobuf_DescriptorProto_clear_extension(google_protobuf_DescriptorProto* msg) { const upb_MiniTableField field = {6, UPB_SIZE(20, 56), 0, 4, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_FieldDescriptorProto* const* google_protobuf_DescriptorProto_extension(const google_protobuf_DescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {6, UPB_SIZE(20, 56), 0, 4, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_FieldDescriptorProto* const*)_upb_array_constptr(arr); @@ -5844,16 +5893,16 @@ UPB_INLINE const google_protobuf_FieldDescriptorProto* const* google_protobuf_De } UPB_INLINE const upb_Array* _google_protobuf_DescriptorProto_extension_upb_array(const google_protobuf_DescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {6, UPB_SIZE(20, 56), 0, 4, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } -UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_extension_mutable_upb_array(const google_protobuf_DescriptorProto* msg, size_t* size, upb_Arena* arena) { +UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_extension_mutable_upb_array(google_protobuf_DescriptorProto* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = {6, UPB_SIZE(20, 56), 0, 4, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - (upb_Message*)msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), + &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -5861,26 +5910,27 @@ UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_extension_mutable_upb_arr } UPB_INLINE void google_protobuf_DescriptorProto_clear_options(google_protobuf_DescriptorProto* msg) { const upb_MiniTableField field = {7, UPB_SIZE(24, 64), 2, 5, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_MessageOptions* google_protobuf_DescriptorProto_options(const google_protobuf_DescriptorProto* msg) { const google_protobuf_MessageOptions* default_val = NULL; const google_protobuf_MessageOptions* ret; const upb_MiniTableField field = {7, UPB_SIZE(24, 64), 2, 5, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_DescriptorProto_has_options(const google_protobuf_DescriptorProto* msg) { const upb_MiniTableField field = {7, UPB_SIZE(24, 64), 2, 5, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_DescriptorProto_clear_oneof_decl(google_protobuf_DescriptorProto* msg) { const upb_MiniTableField field = {8, UPB_SIZE(28, 72), 0, 6, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_OneofDescriptorProto* const* google_protobuf_DescriptorProto_oneof_decl(const google_protobuf_DescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {8, UPB_SIZE(28, 72), 0, 6, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_OneofDescriptorProto* const*)_upb_array_constptr(arr); @@ -5891,16 +5941,16 @@ UPB_INLINE const google_protobuf_OneofDescriptorProto* const* google_protobuf_De } UPB_INLINE const upb_Array* _google_protobuf_DescriptorProto_oneof_decl_upb_array(const google_protobuf_DescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {8, UPB_SIZE(28, 72), 0, 6, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } -UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_oneof_decl_mutable_upb_array(const google_protobuf_DescriptorProto* msg, size_t* size, upb_Arena* arena) { +UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_oneof_decl_mutable_upb_array(google_protobuf_DescriptorProto* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = {8, UPB_SIZE(28, 72), 0, 6, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - (upb_Message*)msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), + &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -5908,11 +5958,11 @@ UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_oneof_decl_mutable_upb_ar } UPB_INLINE void google_protobuf_DescriptorProto_clear_reserved_range(google_protobuf_DescriptorProto* msg) { const upb_MiniTableField field = {9, UPB_SIZE(32, 80), 0, 7, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_DescriptorProto_ReservedRange* const* google_protobuf_DescriptorProto_reserved_range(const google_protobuf_DescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {9, UPB_SIZE(32, 80), 0, 7, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_DescriptorProto_ReservedRange* const*)_upb_array_constptr(arr); @@ -5923,16 +5973,16 @@ UPB_INLINE const google_protobuf_DescriptorProto_ReservedRange* const* google_pr } UPB_INLINE const upb_Array* _google_protobuf_DescriptorProto_reserved_range_upb_array(const google_protobuf_DescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {9, UPB_SIZE(32, 80), 0, 7, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } -UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_reserved_range_mutable_upb_array(const google_protobuf_DescriptorProto* msg, size_t* size, upb_Arena* arena) { +UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_reserved_range_mutable_upb_array(google_protobuf_DescriptorProto* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = {9, UPB_SIZE(32, 80), 0, 7, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - (upb_Message*)msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), + &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -5940,11 +5990,11 @@ UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_reserved_range_mutable_up } UPB_INLINE void google_protobuf_DescriptorProto_clear_reserved_name(google_protobuf_DescriptorProto* msg) { const upb_MiniTableField field = {10, UPB_SIZE(36, 88), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView const* google_protobuf_DescriptorProto_reserved_name(const google_protobuf_DescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {10, UPB_SIZE(36, 88), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (upb_StringView const*)_upb_array_constptr(arr); @@ -5955,16 +6005,16 @@ UPB_INLINE upb_StringView const* google_protobuf_DescriptorProto_reserved_name(c } UPB_INLINE const upb_Array* _google_protobuf_DescriptorProto_reserved_name_upb_array(const google_protobuf_DescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {10, UPB_SIZE(36, 88), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } -UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_reserved_name_mutable_upb_array(const google_protobuf_DescriptorProto* msg, size_t* size, upb_Arena* arena) { +UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_reserved_name_mutable_upb_array(google_protobuf_DescriptorProto* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = {10, UPB_SIZE(36, 88), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - (upb_Message*)msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), + &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -5973,11 +6023,11 @@ UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_reserved_name_mutable_upb UPB_INLINE void google_protobuf_DescriptorProto_set_name(google_protobuf_DescriptorProto *msg, upb_StringView value) { const upb_MiniTableField field = {1, UPB_SIZE(40, 8), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE google_protobuf_FieldDescriptorProto** google_protobuf_DescriptorProto_mutable_field(google_protobuf_DescriptorProto* msg, size_t* size) { upb_MiniTableField field = {2, UPB_SIZE(4, 24), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetMutableArray(msg, &field); + upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_FieldDescriptorProto**)_upb_array_ptr(arr); @@ -5988,11 +6038,13 @@ UPB_INLINE google_protobuf_FieldDescriptorProto** google_protobuf_DescriptorProt } UPB_INLINE google_protobuf_FieldDescriptorProto** google_protobuf_DescriptorProto_resize_field(google_protobuf_DescriptorProto* msg, size_t size, upb_Arena* arena) { upb_MiniTableField field = {2, UPB_SIZE(4, 24), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return (google_protobuf_FieldDescriptorProto**)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); + return (google_protobuf_FieldDescriptorProto**)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg), + &field, size, arena); } UPB_INLINE struct google_protobuf_FieldDescriptorProto* google_protobuf_DescriptorProto_add_field(google_protobuf_DescriptorProto* msg, upb_Arena* arena) { upb_MiniTableField field = {2, UPB_SIZE(4, 24), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray( + UPB_UPCAST(msg), &field, arena); if (!arr || !_upb_Array_ResizeUninitialized( arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; @@ -6005,7 +6057,7 @@ UPB_INLINE struct google_protobuf_FieldDescriptorProto* google_protobuf_Descript } UPB_INLINE google_protobuf_DescriptorProto** google_protobuf_DescriptorProto_mutable_nested_type(google_protobuf_DescriptorProto* msg, size_t* size) { upb_MiniTableField field = {3, UPB_SIZE(8, 32), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetMutableArray(msg, &field); + upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_DescriptorProto**)_upb_array_ptr(arr); @@ -6016,11 +6068,13 @@ UPB_INLINE google_protobuf_DescriptorProto** google_protobuf_DescriptorProto_mut } UPB_INLINE google_protobuf_DescriptorProto** google_protobuf_DescriptorProto_resize_nested_type(google_protobuf_DescriptorProto* msg, size_t size, upb_Arena* arena) { upb_MiniTableField field = {3, UPB_SIZE(8, 32), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return (google_protobuf_DescriptorProto**)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); + return (google_protobuf_DescriptorProto**)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg), + &field, size, arena); } UPB_INLINE struct google_protobuf_DescriptorProto* google_protobuf_DescriptorProto_add_nested_type(google_protobuf_DescriptorProto* msg, upb_Arena* arena) { upb_MiniTableField field = {3, UPB_SIZE(8, 32), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray( + UPB_UPCAST(msg), &field, arena); if (!arr || !_upb_Array_ResizeUninitialized( arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; @@ -6033,7 +6087,7 @@ UPB_INLINE struct google_protobuf_DescriptorProto* google_protobuf_DescriptorPro } UPB_INLINE google_protobuf_EnumDescriptorProto** google_protobuf_DescriptorProto_mutable_enum_type(google_protobuf_DescriptorProto* msg, size_t* size) { upb_MiniTableField field = {4, UPB_SIZE(12, 40), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetMutableArray(msg, &field); + upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_EnumDescriptorProto**)_upb_array_ptr(arr); @@ -6044,11 +6098,13 @@ UPB_INLINE google_protobuf_EnumDescriptorProto** google_protobuf_DescriptorProto } UPB_INLINE google_protobuf_EnumDescriptorProto** google_protobuf_DescriptorProto_resize_enum_type(google_protobuf_DescriptorProto* msg, size_t size, upb_Arena* arena) { upb_MiniTableField field = {4, UPB_SIZE(12, 40), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return (google_protobuf_EnumDescriptorProto**)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); + return (google_protobuf_EnumDescriptorProto**)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg), + &field, size, arena); } UPB_INLINE struct google_protobuf_EnumDescriptorProto* google_protobuf_DescriptorProto_add_enum_type(google_protobuf_DescriptorProto* msg, upb_Arena* arena) { upb_MiniTableField field = {4, UPB_SIZE(12, 40), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray( + UPB_UPCAST(msg), &field, arena); if (!arr || !_upb_Array_ResizeUninitialized( arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; @@ -6061,7 +6117,7 @@ UPB_INLINE struct google_protobuf_EnumDescriptorProto* google_protobuf_Descripto } UPB_INLINE google_protobuf_DescriptorProto_ExtensionRange** google_protobuf_DescriptorProto_mutable_extension_range(google_protobuf_DescriptorProto* msg, size_t* size) { upb_MiniTableField field = {5, UPB_SIZE(16, 48), 0, 3, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetMutableArray(msg, &field); + upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_DescriptorProto_ExtensionRange**)_upb_array_ptr(arr); @@ -6072,11 +6128,13 @@ UPB_INLINE google_protobuf_DescriptorProto_ExtensionRange** google_protobuf_Desc } UPB_INLINE google_protobuf_DescriptorProto_ExtensionRange** google_protobuf_DescriptorProto_resize_extension_range(google_protobuf_DescriptorProto* msg, size_t size, upb_Arena* arena) { upb_MiniTableField field = {5, UPB_SIZE(16, 48), 0, 3, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return (google_protobuf_DescriptorProto_ExtensionRange**)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); + return (google_protobuf_DescriptorProto_ExtensionRange**)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg), + &field, size, arena); } UPB_INLINE struct google_protobuf_DescriptorProto_ExtensionRange* google_protobuf_DescriptorProto_add_extension_range(google_protobuf_DescriptorProto* msg, upb_Arena* arena) { upb_MiniTableField field = {5, UPB_SIZE(16, 48), 0, 3, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray( + UPB_UPCAST(msg), &field, arena); if (!arr || !_upb_Array_ResizeUninitialized( arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; @@ -6089,7 +6147,7 @@ UPB_INLINE struct google_protobuf_DescriptorProto_ExtensionRange* google_protobu } UPB_INLINE google_protobuf_FieldDescriptorProto** google_protobuf_DescriptorProto_mutable_extension(google_protobuf_DescriptorProto* msg, size_t* size) { upb_MiniTableField field = {6, UPB_SIZE(20, 56), 0, 4, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetMutableArray(msg, &field); + upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_FieldDescriptorProto**)_upb_array_ptr(arr); @@ -6100,11 +6158,13 @@ UPB_INLINE google_protobuf_FieldDescriptorProto** google_protobuf_DescriptorProt } UPB_INLINE google_protobuf_FieldDescriptorProto** google_protobuf_DescriptorProto_resize_extension(google_protobuf_DescriptorProto* msg, size_t size, upb_Arena* arena) { upb_MiniTableField field = {6, UPB_SIZE(20, 56), 0, 4, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return (google_protobuf_FieldDescriptorProto**)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); + return (google_protobuf_FieldDescriptorProto**)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg), + &field, size, arena); } UPB_INLINE struct google_protobuf_FieldDescriptorProto* google_protobuf_DescriptorProto_add_extension(google_protobuf_DescriptorProto* msg, upb_Arena* arena) { upb_MiniTableField field = {6, UPB_SIZE(20, 56), 0, 4, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray( + UPB_UPCAST(msg), &field, arena); if (!arr || !_upb_Array_ResizeUninitialized( arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; @@ -6117,7 +6177,7 @@ UPB_INLINE struct google_protobuf_FieldDescriptorProto* google_protobuf_Descript } UPB_INLINE void google_protobuf_DescriptorProto_set_options(google_protobuf_DescriptorProto *msg, google_protobuf_MessageOptions* value) { const upb_MiniTableField field = {7, UPB_SIZE(24, 64), 2, 5, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE struct google_protobuf_MessageOptions* google_protobuf_DescriptorProto_mutable_options(google_protobuf_DescriptorProto* msg, upb_Arena* arena) { struct google_protobuf_MessageOptions* sub = (struct google_protobuf_MessageOptions*)google_protobuf_DescriptorProto_options(msg); @@ -6129,7 +6189,7 @@ UPB_INLINE struct google_protobuf_MessageOptions* google_protobuf_DescriptorProt } UPB_INLINE google_protobuf_OneofDescriptorProto** google_protobuf_DescriptorProto_mutable_oneof_decl(google_protobuf_DescriptorProto* msg, size_t* size) { upb_MiniTableField field = {8, UPB_SIZE(28, 72), 0, 6, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetMutableArray(msg, &field); + upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_OneofDescriptorProto**)_upb_array_ptr(arr); @@ -6140,11 +6200,13 @@ UPB_INLINE google_protobuf_OneofDescriptorProto** google_protobuf_DescriptorProt } UPB_INLINE google_protobuf_OneofDescriptorProto** google_protobuf_DescriptorProto_resize_oneof_decl(google_protobuf_DescriptorProto* msg, size_t size, upb_Arena* arena) { upb_MiniTableField field = {8, UPB_SIZE(28, 72), 0, 6, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return (google_protobuf_OneofDescriptorProto**)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); + return (google_protobuf_OneofDescriptorProto**)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg), + &field, size, arena); } UPB_INLINE struct google_protobuf_OneofDescriptorProto* google_protobuf_DescriptorProto_add_oneof_decl(google_protobuf_DescriptorProto* msg, upb_Arena* arena) { upb_MiniTableField field = {8, UPB_SIZE(28, 72), 0, 6, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray( + UPB_UPCAST(msg), &field, arena); if (!arr || !_upb_Array_ResizeUninitialized( arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; @@ -6157,7 +6219,7 @@ UPB_INLINE struct google_protobuf_OneofDescriptorProto* google_protobuf_Descript } UPB_INLINE google_protobuf_DescriptorProto_ReservedRange** google_protobuf_DescriptorProto_mutable_reserved_range(google_protobuf_DescriptorProto* msg, size_t* size) { upb_MiniTableField field = {9, UPB_SIZE(32, 80), 0, 7, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetMutableArray(msg, &field); + upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_DescriptorProto_ReservedRange**)_upb_array_ptr(arr); @@ -6168,11 +6230,13 @@ UPB_INLINE google_protobuf_DescriptorProto_ReservedRange** google_protobuf_Descr } UPB_INLINE google_protobuf_DescriptorProto_ReservedRange** google_protobuf_DescriptorProto_resize_reserved_range(google_protobuf_DescriptorProto* msg, size_t size, upb_Arena* arena) { upb_MiniTableField field = {9, UPB_SIZE(32, 80), 0, 7, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return (google_protobuf_DescriptorProto_ReservedRange**)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); + return (google_protobuf_DescriptorProto_ReservedRange**)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg), + &field, size, arena); } UPB_INLINE struct google_protobuf_DescriptorProto_ReservedRange* google_protobuf_DescriptorProto_add_reserved_range(google_protobuf_DescriptorProto* msg, upb_Arena* arena) { upb_MiniTableField field = {9, UPB_SIZE(32, 80), 0, 7, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray( + UPB_UPCAST(msg), &field, arena); if (!arr || !_upb_Array_ResizeUninitialized( arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; @@ -6185,7 +6249,7 @@ UPB_INLINE struct google_protobuf_DescriptorProto_ReservedRange* google_protobuf } UPB_INLINE upb_StringView* google_protobuf_DescriptorProto_mutable_reserved_name(google_protobuf_DescriptorProto* msg, size_t* size) { upb_MiniTableField field = {10, UPB_SIZE(36, 88), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetMutableArray(msg, &field); + upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (upb_StringView*)_upb_array_ptr(arr); @@ -6196,11 +6260,13 @@ UPB_INLINE upb_StringView* google_protobuf_DescriptorProto_mutable_reserved_name } UPB_INLINE upb_StringView* google_protobuf_DescriptorProto_resize_reserved_name(google_protobuf_DescriptorProto* msg, size_t size, upb_Arena* arena) { upb_MiniTableField field = {10, UPB_SIZE(36, 88), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return (upb_StringView*)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); + return (upb_StringView*)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg), + &field, size, arena); } UPB_INLINE bool google_protobuf_DescriptorProto_add_reserved_name(google_protobuf_DescriptorProto* msg, upb_StringView val, upb_Arena* arena) { upb_MiniTableField field = {10, UPB_SIZE(36, 88), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray( + UPB_UPCAST(msg), &field, arena); if (!arr || !_upb_Array_ResizeUninitialized( arr, arr->UPB_PRIVATE(size) + 1, arena)) { return false; @@ -6218,7 +6284,8 @@ UPB_INLINE google_protobuf_DescriptorProto_ExtensionRange* google_protobuf_Descr UPB_INLINE google_protobuf_DescriptorProto_ExtensionRange* google_protobuf_DescriptorProto_ExtensionRange_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_DescriptorProto_ExtensionRange* ret = google_protobuf_DescriptorProto_ExtensionRange_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__DescriptorProto__ExtensionRange_msg_init, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__DescriptorProto__ExtensionRange_msg_init, NULL, 0, arena) != + kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -6228,80 +6295,83 @@ UPB_INLINE google_protobuf_DescriptorProto_ExtensionRange* google_protobuf_Descr int options, upb_Arena* arena) { google_protobuf_DescriptorProto_ExtensionRange* ret = google_protobuf_DescriptorProto_ExtensionRange_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__DescriptorProto__ExtensionRange_msg_init, extreg, options, arena) != - kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__DescriptorProto__ExtensionRange_msg_init, extreg, options, + arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_DescriptorProto_ExtensionRange_serialize(const google_protobuf_DescriptorProto_ExtensionRange* msg, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__DescriptorProto__ExtensionRange_msg_init, 0, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__DescriptorProto__ExtensionRange_msg_init, 0, arena, &ptr, len); return ptr; } UPB_INLINE char* google_protobuf_DescriptorProto_ExtensionRange_serialize_ex(const google_protobuf_DescriptorProto_ExtensionRange* msg, int options, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__DescriptorProto__ExtensionRange_msg_init, options, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__DescriptorProto__ExtensionRange_msg_init, options, arena, &ptr, len); return ptr; } UPB_INLINE void google_protobuf_DescriptorProto_ExtensionRange_clear_start(google_protobuf_DescriptorProto_ExtensionRange* msg) { const upb_MiniTableField field = {1, 4, 1, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_DescriptorProto_ExtensionRange_start(const google_protobuf_DescriptorProto_ExtensionRange* msg) { int32_t default_val = (int32_t)0; int32_t ret; const upb_MiniTableField field = {1, 4, 1, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_DescriptorProto_ExtensionRange_has_start(const google_protobuf_DescriptorProto_ExtensionRange* msg) { const upb_MiniTableField field = {1, 4, 1, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_DescriptorProto_ExtensionRange_clear_end(google_protobuf_DescriptorProto_ExtensionRange* msg) { const upb_MiniTableField field = {2, 8, 2, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_DescriptorProto_ExtensionRange_end(const google_protobuf_DescriptorProto_ExtensionRange* msg) { int32_t default_val = (int32_t)0; int32_t ret; const upb_MiniTableField field = {2, 8, 2, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_DescriptorProto_ExtensionRange_has_end(const google_protobuf_DescriptorProto_ExtensionRange* msg) { const upb_MiniTableField field = {2, 8, 2, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_DescriptorProto_ExtensionRange_clear_options(google_protobuf_DescriptorProto_ExtensionRange* msg) { const upb_MiniTableField field = {3, UPB_SIZE(12, 16), 3, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_ExtensionRangeOptions* google_protobuf_DescriptorProto_ExtensionRange_options(const google_protobuf_DescriptorProto_ExtensionRange* msg) { const google_protobuf_ExtensionRangeOptions* default_val = NULL; const google_protobuf_ExtensionRangeOptions* ret; const upb_MiniTableField field = {3, UPB_SIZE(12, 16), 3, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_DescriptorProto_ExtensionRange_has_options(const google_protobuf_DescriptorProto_ExtensionRange* msg) { const upb_MiniTableField field = {3, UPB_SIZE(12, 16), 3, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_DescriptorProto_ExtensionRange_set_start(google_protobuf_DescriptorProto_ExtensionRange *msg, int32_t value) { const upb_MiniTableField field = {1, 4, 1, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_DescriptorProto_ExtensionRange_set_end(google_protobuf_DescriptorProto_ExtensionRange *msg, int32_t value) { const upb_MiniTableField field = {2, 8, 2, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_DescriptorProto_ExtensionRange_set_options(google_protobuf_DescriptorProto_ExtensionRange *msg, google_protobuf_ExtensionRangeOptions* value) { const upb_MiniTableField field = {3, UPB_SIZE(12, 16), 3, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE struct google_protobuf_ExtensionRangeOptions* google_protobuf_DescriptorProto_ExtensionRange_mutable_options(google_protobuf_DescriptorProto_ExtensionRange* msg, upb_Arena* arena) { struct google_protobuf_ExtensionRangeOptions* sub = (struct google_protobuf_ExtensionRangeOptions*)google_protobuf_DescriptorProto_ExtensionRange_options(msg); @@ -6320,7 +6390,8 @@ UPB_INLINE google_protobuf_DescriptorProto_ReservedRange* google_protobuf_Descri UPB_INLINE google_protobuf_DescriptorProto_ReservedRange* google_protobuf_DescriptorProto_ReservedRange_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_DescriptorProto_ReservedRange* ret = google_protobuf_DescriptorProto_ReservedRange_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__DescriptorProto__ReservedRange_msg_init, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__DescriptorProto__ReservedRange_msg_init, NULL, 0, arena) != + kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -6330,61 +6401,63 @@ UPB_INLINE google_protobuf_DescriptorProto_ReservedRange* google_protobuf_Descri int options, upb_Arena* arena) { google_protobuf_DescriptorProto_ReservedRange* ret = google_protobuf_DescriptorProto_ReservedRange_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__DescriptorProto__ReservedRange_msg_init, extreg, options, arena) != - kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__DescriptorProto__ReservedRange_msg_init, extreg, options, + arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_DescriptorProto_ReservedRange_serialize(const google_protobuf_DescriptorProto_ReservedRange* msg, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__DescriptorProto__ReservedRange_msg_init, 0, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__DescriptorProto__ReservedRange_msg_init, 0, arena, &ptr, len); return ptr; } UPB_INLINE char* google_protobuf_DescriptorProto_ReservedRange_serialize_ex(const google_protobuf_DescriptorProto_ReservedRange* msg, int options, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__DescriptorProto__ReservedRange_msg_init, options, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__DescriptorProto__ReservedRange_msg_init, options, arena, &ptr, len); return ptr; } UPB_INLINE void google_protobuf_DescriptorProto_ReservedRange_clear_start(google_protobuf_DescriptorProto_ReservedRange* msg) { const upb_MiniTableField field = {1, 4, 1, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_DescriptorProto_ReservedRange_start(const google_protobuf_DescriptorProto_ReservedRange* msg) { int32_t default_val = (int32_t)0; int32_t ret; const upb_MiniTableField field = {1, 4, 1, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_DescriptorProto_ReservedRange_has_start(const google_protobuf_DescriptorProto_ReservedRange* msg) { const upb_MiniTableField field = {1, 4, 1, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_DescriptorProto_ReservedRange_clear_end(google_protobuf_DescriptorProto_ReservedRange* msg) { const upb_MiniTableField field = {2, 8, 2, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_DescriptorProto_ReservedRange_end(const google_protobuf_DescriptorProto_ReservedRange* msg) { int32_t default_val = (int32_t)0; int32_t ret; const upb_MiniTableField field = {2, 8, 2, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_DescriptorProto_ReservedRange_has_end(const google_protobuf_DescriptorProto_ReservedRange* msg) { const upb_MiniTableField field = {2, 8, 2, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_DescriptorProto_ReservedRange_set_start(google_protobuf_DescriptorProto_ReservedRange *msg, int32_t value) { const upb_MiniTableField field = {1, 4, 1, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_DescriptorProto_ReservedRange_set_end(google_protobuf_DescriptorProto_ReservedRange *msg, int32_t value) { const upb_MiniTableField field = {2, 8, 2, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } /* google.protobuf.ExtensionRangeOptions */ @@ -6395,7 +6468,8 @@ UPB_INLINE google_protobuf_ExtensionRangeOptions* google_protobuf_ExtensionRange UPB_INLINE google_protobuf_ExtensionRangeOptions* google_protobuf_ExtensionRangeOptions_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_ExtensionRangeOptions* ret = google_protobuf_ExtensionRangeOptions_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__ExtensionRangeOptions_msg_init, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__ExtensionRangeOptions_msg_init, NULL, 0, arena) != + kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -6405,30 +6479,30 @@ UPB_INLINE google_protobuf_ExtensionRangeOptions* google_protobuf_ExtensionRange int options, upb_Arena* arena) { google_protobuf_ExtensionRangeOptions* ret = google_protobuf_ExtensionRangeOptions_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__ExtensionRangeOptions_msg_init, extreg, options, arena) != - kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__ExtensionRangeOptions_msg_init, extreg, options, + arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_ExtensionRangeOptions_serialize(const google_protobuf_ExtensionRangeOptions* msg, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__ExtensionRangeOptions_msg_init, 0, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__ExtensionRangeOptions_msg_init, 0, arena, &ptr, len); return ptr; } UPB_INLINE char* google_protobuf_ExtensionRangeOptions_serialize_ex(const google_protobuf_ExtensionRangeOptions* msg, int options, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__ExtensionRangeOptions_msg_init, options, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__ExtensionRangeOptions_msg_init, options, arena, &ptr, len); return ptr; } UPB_INLINE void google_protobuf_ExtensionRangeOptions_clear_declaration(google_protobuf_ExtensionRangeOptions* msg) { const upb_MiniTableField field = {2, UPB_SIZE(4, 8), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_ExtensionRangeOptions_Declaration* const* google_protobuf_ExtensionRangeOptions_declaration(const google_protobuf_ExtensionRangeOptions* msg, size_t* size) { const upb_MiniTableField field = {2, UPB_SIZE(4, 8), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_ExtensionRangeOptions_Declaration* const*)_upb_array_constptr(arr); @@ -6439,16 +6513,16 @@ UPB_INLINE const google_protobuf_ExtensionRangeOptions_Declaration* const* googl } UPB_INLINE const upb_Array* _google_protobuf_ExtensionRangeOptions_declaration_upb_array(const google_protobuf_ExtensionRangeOptions* msg, size_t* size) { const upb_MiniTableField field = {2, UPB_SIZE(4, 8), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } -UPB_INLINE upb_Array* _google_protobuf_ExtensionRangeOptions_declaration_mutable_upb_array(const google_protobuf_ExtensionRangeOptions* msg, size_t* size, upb_Arena* arena) { +UPB_INLINE upb_Array* _google_protobuf_ExtensionRangeOptions_declaration_mutable_upb_array(google_protobuf_ExtensionRangeOptions* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = {2, UPB_SIZE(4, 8), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - (upb_Message*)msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), + &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -6456,41 +6530,43 @@ UPB_INLINE upb_Array* _google_protobuf_ExtensionRangeOptions_declaration_mutable } UPB_INLINE void google_protobuf_ExtensionRangeOptions_clear_verification(google_protobuf_ExtensionRangeOptions* msg) { const upb_MiniTableField field = {3, UPB_SIZE(8, 4), 1, 3, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_ExtensionRangeOptions_verification(const google_protobuf_ExtensionRangeOptions* msg) { int32_t default_val = 1; int32_t ret; const upb_MiniTableField field = {3, UPB_SIZE(8, 4), 1, 3, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_ExtensionRangeOptions_has_verification(const google_protobuf_ExtensionRangeOptions* msg) { const upb_MiniTableField field = {3, UPB_SIZE(8, 4), 1, 3, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_ExtensionRangeOptions_clear_features(google_protobuf_ExtensionRangeOptions* msg) { const upb_MiniTableField field = {50, UPB_SIZE(12, 16), 2, 1, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_FeatureSet* google_protobuf_ExtensionRangeOptions_features(const google_protobuf_ExtensionRangeOptions* msg) { const google_protobuf_FeatureSet* default_val = NULL; const google_protobuf_FeatureSet* ret; const upb_MiniTableField field = {50, UPB_SIZE(12, 16), 2, 1, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_ExtensionRangeOptions_has_features(const google_protobuf_ExtensionRangeOptions* msg) { const upb_MiniTableField field = {50, UPB_SIZE(12, 16), 2, 1, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_ExtensionRangeOptions_clear_uninterpreted_option(google_protobuf_ExtensionRangeOptions* msg) { const upb_MiniTableField field = {999, UPB_SIZE(16, 24), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_ExtensionRangeOptions_uninterpreted_option(const google_protobuf_ExtensionRangeOptions* msg, size_t* size) { const upb_MiniTableField field = {999, UPB_SIZE(16, 24), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_UninterpretedOption* const*)_upb_array_constptr(arr); @@ -6501,16 +6577,16 @@ UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_Ext } UPB_INLINE const upb_Array* _google_protobuf_ExtensionRangeOptions_uninterpreted_option_upb_array(const google_protobuf_ExtensionRangeOptions* msg, size_t* size) { const upb_MiniTableField field = {999, UPB_SIZE(16, 24), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } -UPB_INLINE upb_Array* _google_protobuf_ExtensionRangeOptions_uninterpreted_option_mutable_upb_array(const google_protobuf_ExtensionRangeOptions* msg, size_t* size, upb_Arena* arena) { +UPB_INLINE upb_Array* _google_protobuf_ExtensionRangeOptions_uninterpreted_option_mutable_upb_array(google_protobuf_ExtensionRangeOptions* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = {999, UPB_SIZE(16, 24), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - (upb_Message*)msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), + &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -6519,7 +6595,7 @@ UPB_INLINE upb_Array* _google_protobuf_ExtensionRangeOptions_uninterpreted_optio UPB_INLINE google_protobuf_ExtensionRangeOptions_Declaration** google_protobuf_ExtensionRangeOptions_mutable_declaration(google_protobuf_ExtensionRangeOptions* msg, size_t* size) { upb_MiniTableField field = {2, UPB_SIZE(4, 8), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetMutableArray(msg, &field); + upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_ExtensionRangeOptions_Declaration**)_upb_array_ptr(arr); @@ -6530,11 +6606,13 @@ UPB_INLINE google_protobuf_ExtensionRangeOptions_Declaration** google_protobuf_E } UPB_INLINE google_protobuf_ExtensionRangeOptions_Declaration** google_protobuf_ExtensionRangeOptions_resize_declaration(google_protobuf_ExtensionRangeOptions* msg, size_t size, upb_Arena* arena) { upb_MiniTableField field = {2, UPB_SIZE(4, 8), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return (google_protobuf_ExtensionRangeOptions_Declaration**)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); + return (google_protobuf_ExtensionRangeOptions_Declaration**)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg), + &field, size, arena); } UPB_INLINE struct google_protobuf_ExtensionRangeOptions_Declaration* google_protobuf_ExtensionRangeOptions_add_declaration(google_protobuf_ExtensionRangeOptions* msg, upb_Arena* arena) { upb_MiniTableField field = {2, UPB_SIZE(4, 8), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray( + UPB_UPCAST(msg), &field, arena); if (!arr || !_upb_Array_ResizeUninitialized( arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; @@ -6547,11 +6625,11 @@ UPB_INLINE struct google_protobuf_ExtensionRangeOptions_Declaration* google_prot } UPB_INLINE void google_protobuf_ExtensionRangeOptions_set_verification(google_protobuf_ExtensionRangeOptions *msg, int32_t value) { const upb_MiniTableField field = {3, UPB_SIZE(8, 4), 1, 3, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_ExtensionRangeOptions_set_features(google_protobuf_ExtensionRangeOptions *msg, google_protobuf_FeatureSet* value) { const upb_MiniTableField field = {50, UPB_SIZE(12, 16), 2, 1, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE struct google_protobuf_FeatureSet* google_protobuf_ExtensionRangeOptions_mutable_features(google_protobuf_ExtensionRangeOptions* msg, upb_Arena* arena) { struct google_protobuf_FeatureSet* sub = (struct google_protobuf_FeatureSet*)google_protobuf_ExtensionRangeOptions_features(msg); @@ -6563,7 +6641,7 @@ UPB_INLINE struct google_protobuf_FeatureSet* google_protobuf_ExtensionRangeOpti } UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_ExtensionRangeOptions_mutable_uninterpreted_option(google_protobuf_ExtensionRangeOptions* msg, size_t* size) { upb_MiniTableField field = {999, UPB_SIZE(16, 24), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetMutableArray(msg, &field); + upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_UninterpretedOption**)_upb_array_ptr(arr); @@ -6574,11 +6652,13 @@ UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_ExtensionRangeO } UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_ExtensionRangeOptions_resize_uninterpreted_option(google_protobuf_ExtensionRangeOptions* msg, size_t size, upb_Arena* arena) { upb_MiniTableField field = {999, UPB_SIZE(16, 24), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return (google_protobuf_UninterpretedOption**)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); + return (google_protobuf_UninterpretedOption**)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg), + &field, size, arena); } UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_ExtensionRangeOptions_add_uninterpreted_option(google_protobuf_ExtensionRangeOptions* msg, upb_Arena* arena) { upb_MiniTableField field = {999, UPB_SIZE(16, 24), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray( + UPB_UPCAST(msg), &field, arena); if (!arr || !_upb_Array_ResizeUninitialized( arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; @@ -6598,7 +6678,8 @@ UPB_INLINE google_protobuf_ExtensionRangeOptions_Declaration* google_protobuf_Ex UPB_INLINE google_protobuf_ExtensionRangeOptions_Declaration* google_protobuf_ExtensionRangeOptions_Declaration_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_ExtensionRangeOptions_Declaration* ret = google_protobuf_ExtensionRangeOptions_Declaration_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__ExtensionRangeOptions__Declaration_msg_init, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__ExtensionRangeOptions__Declaration_msg_init, NULL, 0, arena) != + kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -6608,118 +6689,123 @@ UPB_INLINE google_protobuf_ExtensionRangeOptions_Declaration* google_protobuf_Ex int options, upb_Arena* arena) { google_protobuf_ExtensionRangeOptions_Declaration* ret = google_protobuf_ExtensionRangeOptions_Declaration_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__ExtensionRangeOptions__Declaration_msg_init, extreg, options, arena) != - kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__ExtensionRangeOptions__Declaration_msg_init, extreg, options, + arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_ExtensionRangeOptions_Declaration_serialize(const google_protobuf_ExtensionRangeOptions_Declaration* msg, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__ExtensionRangeOptions__Declaration_msg_init, 0, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__ExtensionRangeOptions__Declaration_msg_init, 0, arena, &ptr, len); return ptr; } UPB_INLINE char* google_protobuf_ExtensionRangeOptions_Declaration_serialize_ex(const google_protobuf_ExtensionRangeOptions_Declaration* msg, int options, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__ExtensionRangeOptions__Declaration_msg_init, options, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__ExtensionRangeOptions__Declaration_msg_init, options, arena, &ptr, len); return ptr; } UPB_INLINE void google_protobuf_ExtensionRangeOptions_Declaration_clear_number(google_protobuf_ExtensionRangeOptions_Declaration* msg) { const upb_MiniTableField field = {1, 4, 1, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_ExtensionRangeOptions_Declaration_number(const google_protobuf_ExtensionRangeOptions_Declaration* msg) { int32_t default_val = (int32_t)0; int32_t ret; const upb_MiniTableField field = {1, 4, 1, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_ExtensionRangeOptions_Declaration_has_number(const google_protobuf_ExtensionRangeOptions_Declaration* msg) { const upb_MiniTableField field = {1, 4, 1, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_ExtensionRangeOptions_Declaration_clear_full_name(google_protobuf_ExtensionRangeOptions_Declaration* msg) { const upb_MiniTableField field = {2, UPB_SIZE(12, 16), 2, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_ExtensionRangeOptions_Declaration_full_name(const google_protobuf_ExtensionRangeOptions_Declaration* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; const upb_MiniTableField field = {2, UPB_SIZE(12, 16), 2, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_ExtensionRangeOptions_Declaration_has_full_name(const google_protobuf_ExtensionRangeOptions_Declaration* msg) { const upb_MiniTableField field = {2, UPB_SIZE(12, 16), 2, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_ExtensionRangeOptions_Declaration_clear_type(google_protobuf_ExtensionRangeOptions_Declaration* msg) { const upb_MiniTableField field = {3, UPB_SIZE(20, 32), 3, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_ExtensionRangeOptions_Declaration_type(const google_protobuf_ExtensionRangeOptions_Declaration* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; const upb_MiniTableField field = {3, UPB_SIZE(20, 32), 3, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_ExtensionRangeOptions_Declaration_has_type(const google_protobuf_ExtensionRangeOptions_Declaration* msg) { const upb_MiniTableField field = {3, UPB_SIZE(20, 32), 3, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_ExtensionRangeOptions_Declaration_clear_reserved(google_protobuf_ExtensionRangeOptions_Declaration* msg) { const upb_MiniTableField field = {5, 8, 4, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_ExtensionRangeOptions_Declaration_reserved(const google_protobuf_ExtensionRangeOptions_Declaration* msg) { bool default_val = false; bool ret; const upb_MiniTableField field = {5, 8, 4, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_ExtensionRangeOptions_Declaration_has_reserved(const google_protobuf_ExtensionRangeOptions_Declaration* msg) { const upb_MiniTableField field = {5, 8, 4, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_ExtensionRangeOptions_Declaration_clear_repeated(google_protobuf_ExtensionRangeOptions_Declaration* msg) { const upb_MiniTableField field = {6, 9, 5, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_ExtensionRangeOptions_Declaration_repeated(const google_protobuf_ExtensionRangeOptions_Declaration* msg) { bool default_val = false; bool ret; const upb_MiniTableField field = {6, 9, 5, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_ExtensionRangeOptions_Declaration_has_repeated(const google_protobuf_ExtensionRangeOptions_Declaration* msg) { const upb_MiniTableField field = {6, 9, 5, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_ExtensionRangeOptions_Declaration_set_number(google_protobuf_ExtensionRangeOptions_Declaration *msg, int32_t value) { const upb_MiniTableField field = {1, 4, 1, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_ExtensionRangeOptions_Declaration_set_full_name(google_protobuf_ExtensionRangeOptions_Declaration *msg, upb_StringView value) { const upb_MiniTableField field = {2, UPB_SIZE(12, 16), 2, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_ExtensionRangeOptions_Declaration_set_type(google_protobuf_ExtensionRangeOptions_Declaration *msg, upb_StringView value) { const upb_MiniTableField field = {3, UPB_SIZE(20, 32), 3, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_ExtensionRangeOptions_Declaration_set_reserved(google_protobuf_ExtensionRangeOptions_Declaration *msg, bool value) { const upb_MiniTableField field = {5, 8, 4, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_ExtensionRangeOptions_Declaration_set_repeated(google_protobuf_ExtensionRangeOptions_Declaration *msg, bool value) { const upb_MiniTableField field = {6, 9, 5, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } /* google.protobuf.FieldDescriptorProto */ @@ -6730,7 +6816,8 @@ UPB_INLINE google_protobuf_FieldDescriptorProto* google_protobuf_FieldDescriptor UPB_INLINE google_protobuf_FieldDescriptorProto* google_protobuf_FieldDescriptorProto_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_FieldDescriptorProto* ret = google_protobuf_FieldDescriptorProto_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__FieldDescriptorProto_msg_init, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__FieldDescriptorProto_msg_init, NULL, 0, arena) != + kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -6740,220 +6827,231 @@ UPB_INLINE google_protobuf_FieldDescriptorProto* google_protobuf_FieldDescriptor int options, upb_Arena* arena) { google_protobuf_FieldDescriptorProto* ret = google_protobuf_FieldDescriptorProto_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__FieldDescriptorProto_msg_init, extreg, options, arena) != - kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__FieldDescriptorProto_msg_init, extreg, options, + arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_FieldDescriptorProto_serialize(const google_protobuf_FieldDescriptorProto* msg, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__FieldDescriptorProto_msg_init, 0, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__FieldDescriptorProto_msg_init, 0, arena, &ptr, len); return ptr; } UPB_INLINE char* google_protobuf_FieldDescriptorProto_serialize_ex(const google_protobuf_FieldDescriptorProto* msg, int options, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__FieldDescriptorProto_msg_init, options, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__FieldDescriptorProto_msg_init, options, arena, &ptr, len); return ptr; } UPB_INLINE void google_protobuf_FieldDescriptorProto_clear_name(google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = {1, UPB_SIZE(28, 24), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_FieldDescriptorProto_name(const google_protobuf_FieldDescriptorProto* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; const upb_MiniTableField field = {1, UPB_SIZE(28, 24), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_name(const google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = {1, UPB_SIZE(28, 24), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldDescriptorProto_clear_extendee(google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = {2, UPB_SIZE(36, 40), 2, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_FieldDescriptorProto_extendee(const google_protobuf_FieldDescriptorProto* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; const upb_MiniTableField field = {2, UPB_SIZE(36, 40), 2, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_extendee(const google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = {2, UPB_SIZE(36, 40), 2, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldDescriptorProto_clear_number(google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = {3, 4, 3, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_FieldDescriptorProto_number(const google_protobuf_FieldDescriptorProto* msg) { int32_t default_val = (int32_t)0; int32_t ret; const upb_MiniTableField field = {3, 4, 3, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_number(const google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = {3, 4, 3, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldDescriptorProto_clear_label(google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = {4, 8, 4, 1, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_FieldDescriptorProto_label(const google_protobuf_FieldDescriptorProto* msg) { int32_t default_val = 1; int32_t ret; const upb_MiniTableField field = {4, 8, 4, 1, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_label(const google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = {4, 8, 4, 1, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldDescriptorProto_clear_type(google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = {5, 12, 5, 2, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_FieldDescriptorProto_type(const google_protobuf_FieldDescriptorProto* msg) { int32_t default_val = 1; int32_t ret; const upb_MiniTableField field = {5, 12, 5, 2, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_type(const google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = {5, 12, 5, 2, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldDescriptorProto_clear_type_name(google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = {6, UPB_SIZE(44, 56), 6, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_FieldDescriptorProto_type_name(const google_protobuf_FieldDescriptorProto* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; const upb_MiniTableField field = {6, UPB_SIZE(44, 56), 6, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_type_name(const google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = {6, UPB_SIZE(44, 56), 6, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldDescriptorProto_clear_default_value(google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = {7, UPB_SIZE(52, 72), 7, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_FieldDescriptorProto_default_value(const google_protobuf_FieldDescriptorProto* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; const upb_MiniTableField field = {7, UPB_SIZE(52, 72), 7, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_default_value(const google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = {7, UPB_SIZE(52, 72), 7, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldDescriptorProto_clear_options(google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = {8, UPB_SIZE(16, 88), 8, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_FieldOptions* google_protobuf_FieldDescriptorProto_options(const google_protobuf_FieldDescriptorProto* msg) { const google_protobuf_FieldOptions* default_val = NULL; const google_protobuf_FieldOptions* ret; const upb_MiniTableField field = {8, UPB_SIZE(16, 88), 8, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_options(const google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = {8, UPB_SIZE(16, 88), 8, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldDescriptorProto_clear_oneof_index(google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = {9, UPB_SIZE(20, 16), 9, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_FieldDescriptorProto_oneof_index(const google_protobuf_FieldDescriptorProto* msg) { int32_t default_val = (int32_t)0; int32_t ret; const upb_MiniTableField field = {9, UPB_SIZE(20, 16), 9, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_oneof_index(const google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = {9, UPB_SIZE(20, 16), 9, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldDescriptorProto_clear_json_name(google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = {10, UPB_SIZE(60, 96), 10, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_FieldDescriptorProto_json_name(const google_protobuf_FieldDescriptorProto* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; const upb_MiniTableField field = {10, UPB_SIZE(60, 96), 10, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_json_name(const google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = {10, UPB_SIZE(60, 96), 10, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldDescriptorProto_clear_proto3_optional(google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = {17, UPB_SIZE(24, 20), 11, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_FieldDescriptorProto_proto3_optional(const google_protobuf_FieldDescriptorProto* msg) { bool default_val = false; bool ret; const upb_MiniTableField field = {17, UPB_SIZE(24, 20), 11, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_proto3_optional(const google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = {17, UPB_SIZE(24, 20), 11, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldDescriptorProto_set_name(google_protobuf_FieldDescriptorProto *msg, upb_StringView value) { const upb_MiniTableField field = {1, UPB_SIZE(28, 24), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FieldDescriptorProto_set_extendee(google_protobuf_FieldDescriptorProto *msg, upb_StringView value) { const upb_MiniTableField field = {2, UPB_SIZE(36, 40), 2, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FieldDescriptorProto_set_number(google_protobuf_FieldDescriptorProto *msg, int32_t value) { const upb_MiniTableField field = {3, 4, 3, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FieldDescriptorProto_set_label(google_protobuf_FieldDescriptorProto *msg, int32_t value) { const upb_MiniTableField field = {4, 8, 4, 1, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FieldDescriptorProto_set_type(google_protobuf_FieldDescriptorProto *msg, int32_t value) { const upb_MiniTableField field = {5, 12, 5, 2, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FieldDescriptorProto_set_type_name(google_protobuf_FieldDescriptorProto *msg, upb_StringView value) { const upb_MiniTableField field = {6, UPB_SIZE(44, 56), 6, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FieldDescriptorProto_set_default_value(google_protobuf_FieldDescriptorProto *msg, upb_StringView value) { const upb_MiniTableField field = {7, UPB_SIZE(52, 72), 7, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FieldDescriptorProto_set_options(google_protobuf_FieldDescriptorProto *msg, google_protobuf_FieldOptions* value) { const upb_MiniTableField field = {8, UPB_SIZE(16, 88), 8, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE struct google_protobuf_FieldOptions* google_protobuf_FieldDescriptorProto_mutable_options(google_protobuf_FieldDescriptorProto* msg, upb_Arena* arena) { struct google_protobuf_FieldOptions* sub = (struct google_protobuf_FieldOptions*)google_protobuf_FieldDescriptorProto_options(msg); @@ -6965,15 +7063,15 @@ UPB_INLINE struct google_protobuf_FieldOptions* google_protobuf_FieldDescriptorP } UPB_INLINE void google_protobuf_FieldDescriptorProto_set_oneof_index(google_protobuf_FieldDescriptorProto *msg, int32_t value) { const upb_MiniTableField field = {9, UPB_SIZE(20, 16), 9, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FieldDescriptorProto_set_json_name(google_protobuf_FieldDescriptorProto *msg, upb_StringView value) { const upb_MiniTableField field = {10, UPB_SIZE(60, 96), 10, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FieldDescriptorProto_set_proto3_optional(google_protobuf_FieldDescriptorProto *msg, bool value) { const upb_MiniTableField field = {17, UPB_SIZE(24, 20), 11, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } /* google.protobuf.OneofDescriptorProto */ @@ -6984,7 +7082,8 @@ UPB_INLINE google_protobuf_OneofDescriptorProto* google_protobuf_OneofDescriptor UPB_INLINE google_protobuf_OneofDescriptorProto* google_protobuf_OneofDescriptorProto_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_OneofDescriptorProto* ret = google_protobuf_OneofDescriptorProto_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__OneofDescriptorProto_msg_init, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__OneofDescriptorProto_msg_init, NULL, 0, arena) != + kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -6994,61 +7093,63 @@ UPB_INLINE google_protobuf_OneofDescriptorProto* google_protobuf_OneofDescriptor int options, upb_Arena* arena) { google_protobuf_OneofDescriptorProto* ret = google_protobuf_OneofDescriptorProto_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__OneofDescriptorProto_msg_init, extreg, options, arena) != - kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__OneofDescriptorProto_msg_init, extreg, options, + arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_OneofDescriptorProto_serialize(const google_protobuf_OneofDescriptorProto* msg, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__OneofDescriptorProto_msg_init, 0, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__OneofDescriptorProto_msg_init, 0, arena, &ptr, len); return ptr; } UPB_INLINE char* google_protobuf_OneofDescriptorProto_serialize_ex(const google_protobuf_OneofDescriptorProto* msg, int options, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__OneofDescriptorProto_msg_init, options, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__OneofDescriptorProto_msg_init, options, arena, &ptr, len); return ptr; } UPB_INLINE void google_protobuf_OneofDescriptorProto_clear_name(google_protobuf_OneofDescriptorProto* msg) { const upb_MiniTableField field = {1, 8, 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_OneofDescriptorProto_name(const google_protobuf_OneofDescriptorProto* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; const upb_MiniTableField field = {1, 8, 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_OneofDescriptorProto_has_name(const google_protobuf_OneofDescriptorProto* msg) { const upb_MiniTableField field = {1, 8, 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_OneofDescriptorProto_clear_options(google_protobuf_OneofDescriptorProto* msg) { const upb_MiniTableField field = {2, UPB_SIZE(4, 24), 2, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_OneofOptions* google_protobuf_OneofDescriptorProto_options(const google_protobuf_OneofDescriptorProto* msg) { const google_protobuf_OneofOptions* default_val = NULL; const google_protobuf_OneofOptions* ret; const upb_MiniTableField field = {2, UPB_SIZE(4, 24), 2, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_OneofDescriptorProto_has_options(const google_protobuf_OneofDescriptorProto* msg) { const upb_MiniTableField field = {2, UPB_SIZE(4, 24), 2, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_OneofDescriptorProto_set_name(google_protobuf_OneofDescriptorProto *msg, upb_StringView value) { const upb_MiniTableField field = {1, 8, 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_OneofDescriptorProto_set_options(google_protobuf_OneofDescriptorProto *msg, google_protobuf_OneofOptions* value) { const upb_MiniTableField field = {2, UPB_SIZE(4, 24), 2, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE struct google_protobuf_OneofOptions* google_protobuf_OneofDescriptorProto_mutable_options(google_protobuf_OneofDescriptorProto* msg, upb_Arena* arena) { struct google_protobuf_OneofOptions* sub = (struct google_protobuf_OneofOptions*)google_protobuf_OneofDescriptorProto_options(msg); @@ -7067,7 +7168,8 @@ UPB_INLINE google_protobuf_EnumDescriptorProto* google_protobuf_EnumDescriptorPr UPB_INLINE google_protobuf_EnumDescriptorProto* google_protobuf_EnumDescriptorProto_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_EnumDescriptorProto* ret = google_protobuf_EnumDescriptorProto_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__EnumDescriptorProto_msg_init, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__EnumDescriptorProto_msg_init, NULL, 0, arena) != + kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -7077,45 +7179,46 @@ UPB_INLINE google_protobuf_EnumDescriptorProto* google_protobuf_EnumDescriptorPr int options, upb_Arena* arena) { google_protobuf_EnumDescriptorProto* ret = google_protobuf_EnumDescriptorProto_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__EnumDescriptorProto_msg_init, extreg, options, arena) != - kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__EnumDescriptorProto_msg_init, extreg, options, + arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_EnumDescriptorProto_serialize(const google_protobuf_EnumDescriptorProto* msg, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__EnumDescriptorProto_msg_init, 0, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__EnumDescriptorProto_msg_init, 0, arena, &ptr, len); return ptr; } UPB_INLINE char* google_protobuf_EnumDescriptorProto_serialize_ex(const google_protobuf_EnumDescriptorProto* msg, int options, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__EnumDescriptorProto_msg_init, options, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__EnumDescriptorProto_msg_init, options, arena, &ptr, len); return ptr; } UPB_INLINE void google_protobuf_EnumDescriptorProto_clear_name(google_protobuf_EnumDescriptorProto* msg) { const upb_MiniTableField field = {1, UPB_SIZE(20, 8), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_EnumDescriptorProto_name(const google_protobuf_EnumDescriptorProto* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; const upb_MiniTableField field = {1, UPB_SIZE(20, 8), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_EnumDescriptorProto_has_name(const google_protobuf_EnumDescriptorProto* msg) { const upb_MiniTableField field = {1, UPB_SIZE(20, 8), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_EnumDescriptorProto_clear_value(google_protobuf_EnumDescriptorProto* msg) { const upb_MiniTableField field = {2, UPB_SIZE(4, 24), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_EnumValueDescriptorProto* const* google_protobuf_EnumDescriptorProto_value(const google_protobuf_EnumDescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {2, UPB_SIZE(4, 24), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_EnumValueDescriptorProto* const*)_upb_array_constptr(arr); @@ -7126,16 +7229,16 @@ UPB_INLINE const google_protobuf_EnumValueDescriptorProto* const* google_protobu } UPB_INLINE const upb_Array* _google_protobuf_EnumDescriptorProto_value_upb_array(const google_protobuf_EnumDescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {2, UPB_SIZE(4, 24), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } -UPB_INLINE upb_Array* _google_protobuf_EnumDescriptorProto_value_mutable_upb_array(const google_protobuf_EnumDescriptorProto* msg, size_t* size, upb_Arena* arena) { +UPB_INLINE upb_Array* _google_protobuf_EnumDescriptorProto_value_mutable_upb_array(google_protobuf_EnumDescriptorProto* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = {2, UPB_SIZE(4, 24), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - (upb_Message*)msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), + &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -7143,26 +7246,27 @@ UPB_INLINE upb_Array* _google_protobuf_EnumDescriptorProto_value_mutable_upb_arr } UPB_INLINE void google_protobuf_EnumDescriptorProto_clear_options(google_protobuf_EnumDescriptorProto* msg) { const upb_MiniTableField field = {3, UPB_SIZE(8, 32), 2, 1, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_EnumOptions* google_protobuf_EnumDescriptorProto_options(const google_protobuf_EnumDescriptorProto* msg) { const google_protobuf_EnumOptions* default_val = NULL; const google_protobuf_EnumOptions* ret; const upb_MiniTableField field = {3, UPB_SIZE(8, 32), 2, 1, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_EnumDescriptorProto_has_options(const google_protobuf_EnumDescriptorProto* msg) { const upb_MiniTableField field = {3, UPB_SIZE(8, 32), 2, 1, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_EnumDescriptorProto_clear_reserved_range(google_protobuf_EnumDescriptorProto* msg) { const upb_MiniTableField field = {4, UPB_SIZE(12, 40), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_EnumDescriptorProto_EnumReservedRange* const* google_protobuf_EnumDescriptorProto_reserved_range(const google_protobuf_EnumDescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {4, UPB_SIZE(12, 40), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_EnumDescriptorProto_EnumReservedRange* const*)_upb_array_constptr(arr); @@ -7173,16 +7277,16 @@ UPB_INLINE const google_protobuf_EnumDescriptorProto_EnumReservedRange* const* g } UPB_INLINE const upb_Array* _google_protobuf_EnumDescriptorProto_reserved_range_upb_array(const google_protobuf_EnumDescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {4, UPB_SIZE(12, 40), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } -UPB_INLINE upb_Array* _google_protobuf_EnumDescriptorProto_reserved_range_mutable_upb_array(const google_protobuf_EnumDescriptorProto* msg, size_t* size, upb_Arena* arena) { +UPB_INLINE upb_Array* _google_protobuf_EnumDescriptorProto_reserved_range_mutable_upb_array(google_protobuf_EnumDescriptorProto* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = {4, UPB_SIZE(12, 40), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - (upb_Message*)msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), + &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -7190,11 +7294,11 @@ UPB_INLINE upb_Array* _google_protobuf_EnumDescriptorProto_reserved_range_mutabl } UPB_INLINE void google_protobuf_EnumDescriptorProto_clear_reserved_name(google_protobuf_EnumDescriptorProto* msg) { const upb_MiniTableField field = {5, UPB_SIZE(16, 48), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView const* google_protobuf_EnumDescriptorProto_reserved_name(const google_protobuf_EnumDescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {5, UPB_SIZE(16, 48), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (upb_StringView const*)_upb_array_constptr(arr); @@ -7205,16 +7309,16 @@ UPB_INLINE upb_StringView const* google_protobuf_EnumDescriptorProto_reserved_na } UPB_INLINE const upb_Array* _google_protobuf_EnumDescriptorProto_reserved_name_upb_array(const google_protobuf_EnumDescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {5, UPB_SIZE(16, 48), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } -UPB_INLINE upb_Array* _google_protobuf_EnumDescriptorProto_reserved_name_mutable_upb_array(const google_protobuf_EnumDescriptorProto* msg, size_t* size, upb_Arena* arena) { +UPB_INLINE upb_Array* _google_protobuf_EnumDescriptorProto_reserved_name_mutable_upb_array(google_protobuf_EnumDescriptorProto* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = {5, UPB_SIZE(16, 48), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - (upb_Message*)msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), + &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -7223,11 +7327,11 @@ UPB_INLINE upb_Array* _google_protobuf_EnumDescriptorProto_reserved_name_mutable UPB_INLINE void google_protobuf_EnumDescriptorProto_set_name(google_protobuf_EnumDescriptorProto *msg, upb_StringView value) { const upb_MiniTableField field = {1, UPB_SIZE(20, 8), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE google_protobuf_EnumValueDescriptorProto** google_protobuf_EnumDescriptorProto_mutable_value(google_protobuf_EnumDescriptorProto* msg, size_t* size) { upb_MiniTableField field = {2, UPB_SIZE(4, 24), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetMutableArray(msg, &field); + upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_EnumValueDescriptorProto**)_upb_array_ptr(arr); @@ -7238,11 +7342,13 @@ UPB_INLINE google_protobuf_EnumValueDescriptorProto** google_protobuf_EnumDescri } UPB_INLINE google_protobuf_EnumValueDescriptorProto** google_protobuf_EnumDescriptorProto_resize_value(google_protobuf_EnumDescriptorProto* msg, size_t size, upb_Arena* arena) { upb_MiniTableField field = {2, UPB_SIZE(4, 24), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return (google_protobuf_EnumValueDescriptorProto**)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); + return (google_protobuf_EnumValueDescriptorProto**)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg), + &field, size, arena); } UPB_INLINE struct google_protobuf_EnumValueDescriptorProto* google_protobuf_EnumDescriptorProto_add_value(google_protobuf_EnumDescriptorProto* msg, upb_Arena* arena) { upb_MiniTableField field = {2, UPB_SIZE(4, 24), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray( + UPB_UPCAST(msg), &field, arena); if (!arr || !_upb_Array_ResizeUninitialized( arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; @@ -7255,7 +7361,7 @@ UPB_INLINE struct google_protobuf_EnumValueDescriptorProto* google_protobuf_Enum } UPB_INLINE void google_protobuf_EnumDescriptorProto_set_options(google_protobuf_EnumDescriptorProto *msg, google_protobuf_EnumOptions* value) { const upb_MiniTableField field = {3, UPB_SIZE(8, 32), 2, 1, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE struct google_protobuf_EnumOptions* google_protobuf_EnumDescriptorProto_mutable_options(google_protobuf_EnumDescriptorProto* msg, upb_Arena* arena) { struct google_protobuf_EnumOptions* sub = (struct google_protobuf_EnumOptions*)google_protobuf_EnumDescriptorProto_options(msg); @@ -7267,7 +7373,7 @@ UPB_INLINE struct google_protobuf_EnumOptions* google_protobuf_EnumDescriptorPro } UPB_INLINE google_protobuf_EnumDescriptorProto_EnumReservedRange** google_protobuf_EnumDescriptorProto_mutable_reserved_range(google_protobuf_EnumDescriptorProto* msg, size_t* size) { upb_MiniTableField field = {4, UPB_SIZE(12, 40), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetMutableArray(msg, &field); + upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_EnumDescriptorProto_EnumReservedRange**)_upb_array_ptr(arr); @@ -7278,11 +7384,13 @@ UPB_INLINE google_protobuf_EnumDescriptorProto_EnumReservedRange** google_protob } UPB_INLINE google_protobuf_EnumDescriptorProto_EnumReservedRange** google_protobuf_EnumDescriptorProto_resize_reserved_range(google_protobuf_EnumDescriptorProto* msg, size_t size, upb_Arena* arena) { upb_MiniTableField field = {4, UPB_SIZE(12, 40), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return (google_protobuf_EnumDescriptorProto_EnumReservedRange**)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); + return (google_protobuf_EnumDescriptorProto_EnumReservedRange**)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg), + &field, size, arena); } UPB_INLINE struct google_protobuf_EnumDescriptorProto_EnumReservedRange* google_protobuf_EnumDescriptorProto_add_reserved_range(google_protobuf_EnumDescriptorProto* msg, upb_Arena* arena) { upb_MiniTableField field = {4, UPB_SIZE(12, 40), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray( + UPB_UPCAST(msg), &field, arena); if (!arr || !_upb_Array_ResizeUninitialized( arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; @@ -7295,7 +7403,7 @@ UPB_INLINE struct google_protobuf_EnumDescriptorProto_EnumReservedRange* google_ } UPB_INLINE upb_StringView* google_protobuf_EnumDescriptorProto_mutable_reserved_name(google_protobuf_EnumDescriptorProto* msg, size_t* size) { upb_MiniTableField field = {5, UPB_SIZE(16, 48), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetMutableArray(msg, &field); + upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (upb_StringView*)_upb_array_ptr(arr); @@ -7306,11 +7414,13 @@ UPB_INLINE upb_StringView* google_protobuf_EnumDescriptorProto_mutable_reserved_ } UPB_INLINE upb_StringView* google_protobuf_EnumDescriptorProto_resize_reserved_name(google_protobuf_EnumDescriptorProto* msg, size_t size, upb_Arena* arena) { upb_MiniTableField field = {5, UPB_SIZE(16, 48), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return (upb_StringView*)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); + return (upb_StringView*)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg), + &field, size, arena); } UPB_INLINE bool google_protobuf_EnumDescriptorProto_add_reserved_name(google_protobuf_EnumDescriptorProto* msg, upb_StringView val, upb_Arena* arena) { upb_MiniTableField field = {5, UPB_SIZE(16, 48), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray( + UPB_UPCAST(msg), &field, arena); if (!arr || !_upb_Array_ResizeUninitialized( arr, arr->UPB_PRIVATE(size) + 1, arena)) { return false; @@ -7328,7 +7438,8 @@ UPB_INLINE google_protobuf_EnumDescriptorProto_EnumReservedRange* google_protobu UPB_INLINE google_protobuf_EnumDescriptorProto_EnumReservedRange* google_protobuf_EnumDescriptorProto_EnumReservedRange_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_EnumDescriptorProto_EnumReservedRange* ret = google_protobuf_EnumDescriptorProto_EnumReservedRange_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__EnumDescriptorProto__EnumReservedRange_msg_init, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__EnumDescriptorProto__EnumReservedRange_msg_init, NULL, 0, arena) != + kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -7338,61 +7449,63 @@ UPB_INLINE google_protobuf_EnumDescriptorProto_EnumReservedRange* google_protobu int options, upb_Arena* arena) { google_protobuf_EnumDescriptorProto_EnumReservedRange* ret = google_protobuf_EnumDescriptorProto_EnumReservedRange_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__EnumDescriptorProto__EnumReservedRange_msg_init, extreg, options, arena) != - kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__EnumDescriptorProto__EnumReservedRange_msg_init, extreg, options, + arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_EnumDescriptorProto_EnumReservedRange_serialize(const google_protobuf_EnumDescriptorProto_EnumReservedRange* msg, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__EnumDescriptorProto__EnumReservedRange_msg_init, 0, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__EnumDescriptorProto__EnumReservedRange_msg_init, 0, arena, &ptr, len); return ptr; } UPB_INLINE char* google_protobuf_EnumDescriptorProto_EnumReservedRange_serialize_ex(const google_protobuf_EnumDescriptorProto_EnumReservedRange* msg, int options, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__EnumDescriptorProto__EnumReservedRange_msg_init, options, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__EnumDescriptorProto__EnumReservedRange_msg_init, options, arena, &ptr, len); return ptr; } UPB_INLINE void google_protobuf_EnumDescriptorProto_EnumReservedRange_clear_start(google_protobuf_EnumDescriptorProto_EnumReservedRange* msg) { const upb_MiniTableField field = {1, 4, 1, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_EnumDescriptorProto_EnumReservedRange_start(const google_protobuf_EnumDescriptorProto_EnumReservedRange* msg) { int32_t default_val = (int32_t)0; int32_t ret; const upb_MiniTableField field = {1, 4, 1, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_EnumDescriptorProto_EnumReservedRange_has_start(const google_protobuf_EnumDescriptorProto_EnumReservedRange* msg) { const upb_MiniTableField field = {1, 4, 1, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_EnumDescriptorProto_EnumReservedRange_clear_end(google_protobuf_EnumDescriptorProto_EnumReservedRange* msg) { const upb_MiniTableField field = {2, 8, 2, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_EnumDescriptorProto_EnumReservedRange_end(const google_protobuf_EnumDescriptorProto_EnumReservedRange* msg) { int32_t default_val = (int32_t)0; int32_t ret; const upb_MiniTableField field = {2, 8, 2, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_EnumDescriptorProto_EnumReservedRange_has_end(const google_protobuf_EnumDescriptorProto_EnumReservedRange* msg) { const upb_MiniTableField field = {2, 8, 2, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_EnumDescriptorProto_EnumReservedRange_set_start(google_protobuf_EnumDescriptorProto_EnumReservedRange *msg, int32_t value) { const upb_MiniTableField field = {1, 4, 1, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_EnumDescriptorProto_EnumReservedRange_set_end(google_protobuf_EnumDescriptorProto_EnumReservedRange *msg, int32_t value) { const upb_MiniTableField field = {2, 8, 2, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } /* google.protobuf.EnumValueDescriptorProto */ @@ -7403,7 +7516,8 @@ UPB_INLINE google_protobuf_EnumValueDescriptorProto* google_protobuf_EnumValueDe UPB_INLINE google_protobuf_EnumValueDescriptorProto* google_protobuf_EnumValueDescriptorProto_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_EnumValueDescriptorProto* ret = google_protobuf_EnumValueDescriptorProto_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__EnumValueDescriptorProto_msg_init, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__EnumValueDescriptorProto_msg_init, NULL, 0, arena) != + kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -7413,80 +7527,83 @@ UPB_INLINE google_protobuf_EnumValueDescriptorProto* google_protobuf_EnumValueDe int options, upb_Arena* arena) { google_protobuf_EnumValueDescriptorProto* ret = google_protobuf_EnumValueDescriptorProto_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__EnumValueDescriptorProto_msg_init, extreg, options, arena) != - kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__EnumValueDescriptorProto_msg_init, extreg, options, + arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_EnumValueDescriptorProto_serialize(const google_protobuf_EnumValueDescriptorProto* msg, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__EnumValueDescriptorProto_msg_init, 0, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__EnumValueDescriptorProto_msg_init, 0, arena, &ptr, len); return ptr; } UPB_INLINE char* google_protobuf_EnumValueDescriptorProto_serialize_ex(const google_protobuf_EnumValueDescriptorProto* msg, int options, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__EnumValueDescriptorProto_msg_init, options, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__EnumValueDescriptorProto_msg_init, options, arena, &ptr, len); return ptr; } UPB_INLINE void google_protobuf_EnumValueDescriptorProto_clear_name(google_protobuf_EnumValueDescriptorProto* msg) { const upb_MiniTableField field = {1, UPB_SIZE(12, 8), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_EnumValueDescriptorProto_name(const google_protobuf_EnumValueDescriptorProto* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; const upb_MiniTableField field = {1, UPB_SIZE(12, 8), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_EnumValueDescriptorProto_has_name(const google_protobuf_EnumValueDescriptorProto* msg) { const upb_MiniTableField field = {1, UPB_SIZE(12, 8), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_EnumValueDescriptorProto_clear_number(google_protobuf_EnumValueDescriptorProto* msg) { const upb_MiniTableField field = {2, 4, 2, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_EnumValueDescriptorProto_number(const google_protobuf_EnumValueDescriptorProto* msg) { int32_t default_val = (int32_t)0; int32_t ret; const upb_MiniTableField field = {2, 4, 2, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_EnumValueDescriptorProto_has_number(const google_protobuf_EnumValueDescriptorProto* msg) { const upb_MiniTableField field = {2, 4, 2, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_EnumValueDescriptorProto_clear_options(google_protobuf_EnumValueDescriptorProto* msg) { const upb_MiniTableField field = {3, UPB_SIZE(8, 24), 3, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_EnumValueOptions* google_protobuf_EnumValueDescriptorProto_options(const google_protobuf_EnumValueDescriptorProto* msg) { const google_protobuf_EnumValueOptions* default_val = NULL; const google_protobuf_EnumValueOptions* ret; const upb_MiniTableField field = {3, UPB_SIZE(8, 24), 3, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_EnumValueDescriptorProto_has_options(const google_protobuf_EnumValueDescriptorProto* msg) { const upb_MiniTableField field = {3, UPB_SIZE(8, 24), 3, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_EnumValueDescriptorProto_set_name(google_protobuf_EnumValueDescriptorProto *msg, upb_StringView value) { const upb_MiniTableField field = {1, UPB_SIZE(12, 8), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_EnumValueDescriptorProto_set_number(google_protobuf_EnumValueDescriptorProto *msg, int32_t value) { const upb_MiniTableField field = {2, 4, 2, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_EnumValueDescriptorProto_set_options(google_protobuf_EnumValueDescriptorProto *msg, google_protobuf_EnumValueOptions* value) { const upb_MiniTableField field = {3, UPB_SIZE(8, 24), 3, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE struct google_protobuf_EnumValueOptions* google_protobuf_EnumValueDescriptorProto_mutable_options(google_protobuf_EnumValueDescriptorProto* msg, upb_Arena* arena) { struct google_protobuf_EnumValueOptions* sub = (struct google_protobuf_EnumValueOptions*)google_protobuf_EnumValueDescriptorProto_options(msg); @@ -7505,7 +7622,8 @@ UPB_INLINE google_protobuf_ServiceDescriptorProto* google_protobuf_ServiceDescri UPB_INLINE google_protobuf_ServiceDescriptorProto* google_protobuf_ServiceDescriptorProto_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_ServiceDescriptorProto* ret = google_protobuf_ServiceDescriptorProto_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__ServiceDescriptorProto_msg_init, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__ServiceDescriptorProto_msg_init, NULL, 0, arena) != + kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -7515,45 +7633,46 @@ UPB_INLINE google_protobuf_ServiceDescriptorProto* google_protobuf_ServiceDescri int options, upb_Arena* arena) { google_protobuf_ServiceDescriptorProto* ret = google_protobuf_ServiceDescriptorProto_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__ServiceDescriptorProto_msg_init, extreg, options, arena) != - kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__ServiceDescriptorProto_msg_init, extreg, options, + arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_ServiceDescriptorProto_serialize(const google_protobuf_ServiceDescriptorProto* msg, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__ServiceDescriptorProto_msg_init, 0, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__ServiceDescriptorProto_msg_init, 0, arena, &ptr, len); return ptr; } UPB_INLINE char* google_protobuf_ServiceDescriptorProto_serialize_ex(const google_protobuf_ServiceDescriptorProto* msg, int options, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__ServiceDescriptorProto_msg_init, options, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__ServiceDescriptorProto_msg_init, options, arena, &ptr, len); return ptr; } UPB_INLINE void google_protobuf_ServiceDescriptorProto_clear_name(google_protobuf_ServiceDescriptorProto* msg) { const upb_MiniTableField field = {1, UPB_SIZE(12, 8), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_ServiceDescriptorProto_name(const google_protobuf_ServiceDescriptorProto* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; const upb_MiniTableField field = {1, UPB_SIZE(12, 8), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_ServiceDescriptorProto_has_name(const google_protobuf_ServiceDescriptorProto* msg) { const upb_MiniTableField field = {1, UPB_SIZE(12, 8), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_ServiceDescriptorProto_clear_method(google_protobuf_ServiceDescriptorProto* msg) { const upb_MiniTableField field = {2, UPB_SIZE(4, 24), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_MethodDescriptorProto* const* google_protobuf_ServiceDescriptorProto_method(const google_protobuf_ServiceDescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {2, UPB_SIZE(4, 24), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_MethodDescriptorProto* const*)_upb_array_constptr(arr); @@ -7564,16 +7683,16 @@ UPB_INLINE const google_protobuf_MethodDescriptorProto* const* google_protobuf_S } UPB_INLINE const upb_Array* _google_protobuf_ServiceDescriptorProto_method_upb_array(const google_protobuf_ServiceDescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {2, UPB_SIZE(4, 24), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } -UPB_INLINE upb_Array* _google_protobuf_ServiceDescriptorProto_method_mutable_upb_array(const google_protobuf_ServiceDescriptorProto* msg, size_t* size, upb_Arena* arena) { +UPB_INLINE upb_Array* _google_protobuf_ServiceDescriptorProto_method_mutable_upb_array(google_protobuf_ServiceDescriptorProto* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = {2, UPB_SIZE(4, 24), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - (upb_Message*)msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), + &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -7581,27 +7700,28 @@ UPB_INLINE upb_Array* _google_protobuf_ServiceDescriptorProto_method_mutable_upb } UPB_INLINE void google_protobuf_ServiceDescriptorProto_clear_options(google_protobuf_ServiceDescriptorProto* msg) { const upb_MiniTableField field = {3, UPB_SIZE(8, 32), 2, 1, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_ServiceOptions* google_protobuf_ServiceDescriptorProto_options(const google_protobuf_ServiceDescriptorProto* msg) { const google_protobuf_ServiceOptions* default_val = NULL; const google_protobuf_ServiceOptions* ret; const upb_MiniTableField field = {3, UPB_SIZE(8, 32), 2, 1, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_ServiceDescriptorProto_has_options(const google_protobuf_ServiceDescriptorProto* msg) { const upb_MiniTableField field = {3, UPB_SIZE(8, 32), 2, 1, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_ServiceDescriptorProto_set_name(google_protobuf_ServiceDescriptorProto *msg, upb_StringView value) { const upb_MiniTableField field = {1, UPB_SIZE(12, 8), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE google_protobuf_MethodDescriptorProto** google_protobuf_ServiceDescriptorProto_mutable_method(google_protobuf_ServiceDescriptorProto* msg, size_t* size) { upb_MiniTableField field = {2, UPB_SIZE(4, 24), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetMutableArray(msg, &field); + upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_MethodDescriptorProto**)_upb_array_ptr(arr); @@ -7612,11 +7732,13 @@ UPB_INLINE google_protobuf_MethodDescriptorProto** google_protobuf_ServiceDescri } UPB_INLINE google_protobuf_MethodDescriptorProto** google_protobuf_ServiceDescriptorProto_resize_method(google_protobuf_ServiceDescriptorProto* msg, size_t size, upb_Arena* arena) { upb_MiniTableField field = {2, UPB_SIZE(4, 24), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return (google_protobuf_MethodDescriptorProto**)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); + return (google_protobuf_MethodDescriptorProto**)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg), + &field, size, arena); } UPB_INLINE struct google_protobuf_MethodDescriptorProto* google_protobuf_ServiceDescriptorProto_add_method(google_protobuf_ServiceDescriptorProto* msg, upb_Arena* arena) { upb_MiniTableField field = {2, UPB_SIZE(4, 24), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray( + UPB_UPCAST(msg), &field, arena); if (!arr || !_upb_Array_ResizeUninitialized( arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; @@ -7629,7 +7751,7 @@ UPB_INLINE struct google_protobuf_MethodDescriptorProto* google_protobuf_Service } UPB_INLINE void google_protobuf_ServiceDescriptorProto_set_options(google_protobuf_ServiceDescriptorProto *msg, google_protobuf_ServiceOptions* value) { const upb_MiniTableField field = {3, UPB_SIZE(8, 32), 2, 1, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE struct google_protobuf_ServiceOptions* google_protobuf_ServiceDescriptorProto_mutable_options(google_protobuf_ServiceDescriptorProto* msg, upb_Arena* arena) { struct google_protobuf_ServiceOptions* sub = (struct google_protobuf_ServiceOptions*)google_protobuf_ServiceDescriptorProto_options(msg); @@ -7648,7 +7770,8 @@ UPB_INLINE google_protobuf_MethodDescriptorProto* google_protobuf_MethodDescript UPB_INLINE google_protobuf_MethodDescriptorProto* google_protobuf_MethodDescriptorProto_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_MethodDescriptorProto* ret = google_protobuf_MethodDescriptorProto_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__MethodDescriptorProto_msg_init, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__MethodDescriptorProto_msg_init, NULL, 0, arena) != + kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -7658,129 +7781,135 @@ UPB_INLINE google_protobuf_MethodDescriptorProto* google_protobuf_MethodDescript int options, upb_Arena* arena) { google_protobuf_MethodDescriptorProto* ret = google_protobuf_MethodDescriptorProto_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__MethodDescriptorProto_msg_init, extreg, options, arena) != - kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__MethodDescriptorProto_msg_init, extreg, options, + arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_MethodDescriptorProto_serialize(const google_protobuf_MethodDescriptorProto* msg, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__MethodDescriptorProto_msg_init, 0, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__MethodDescriptorProto_msg_init, 0, arena, &ptr, len); return ptr; } UPB_INLINE char* google_protobuf_MethodDescriptorProto_serialize_ex(const google_protobuf_MethodDescriptorProto* msg, int options, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__MethodDescriptorProto_msg_init, options, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__MethodDescriptorProto_msg_init, options, arena, &ptr, len); return ptr; } UPB_INLINE void google_protobuf_MethodDescriptorProto_clear_name(google_protobuf_MethodDescriptorProto* msg) { const upb_MiniTableField field = {1, UPB_SIZE(12, 8), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_MethodDescriptorProto_name(const google_protobuf_MethodDescriptorProto* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; const upb_MiniTableField field = {1, UPB_SIZE(12, 8), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_MethodDescriptorProto_has_name(const google_protobuf_MethodDescriptorProto* msg) { const upb_MiniTableField field = {1, UPB_SIZE(12, 8), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_MethodDescriptorProto_clear_input_type(google_protobuf_MethodDescriptorProto* msg) { const upb_MiniTableField field = {2, UPB_SIZE(20, 24), 2, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_MethodDescriptorProto_input_type(const google_protobuf_MethodDescriptorProto* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; const upb_MiniTableField field = {2, UPB_SIZE(20, 24), 2, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_MethodDescriptorProto_has_input_type(const google_protobuf_MethodDescriptorProto* msg) { const upb_MiniTableField field = {2, UPB_SIZE(20, 24), 2, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_MethodDescriptorProto_clear_output_type(google_protobuf_MethodDescriptorProto* msg) { const upb_MiniTableField field = {3, UPB_SIZE(28, 40), 3, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_MethodDescriptorProto_output_type(const google_protobuf_MethodDescriptorProto* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; const upb_MiniTableField field = {3, UPB_SIZE(28, 40), 3, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_MethodDescriptorProto_has_output_type(const google_protobuf_MethodDescriptorProto* msg) { const upb_MiniTableField field = {3, UPB_SIZE(28, 40), 3, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_MethodDescriptorProto_clear_options(google_protobuf_MethodDescriptorProto* msg) { const upb_MiniTableField field = {4, UPB_SIZE(4, 56), 4, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_MethodOptions* google_protobuf_MethodDescriptorProto_options(const google_protobuf_MethodDescriptorProto* msg) { const google_protobuf_MethodOptions* default_val = NULL; const google_protobuf_MethodOptions* ret; const upb_MiniTableField field = {4, UPB_SIZE(4, 56), 4, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_MethodDescriptorProto_has_options(const google_protobuf_MethodDescriptorProto* msg) { const upb_MiniTableField field = {4, UPB_SIZE(4, 56), 4, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_MethodDescriptorProto_clear_client_streaming(google_protobuf_MethodDescriptorProto* msg) { const upb_MiniTableField field = {5, UPB_SIZE(8, 1), 5, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_MethodDescriptorProto_client_streaming(const google_protobuf_MethodDescriptorProto* msg) { bool default_val = false; bool ret; const upb_MiniTableField field = {5, UPB_SIZE(8, 1), 5, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_MethodDescriptorProto_has_client_streaming(const google_protobuf_MethodDescriptorProto* msg) { const upb_MiniTableField field = {5, UPB_SIZE(8, 1), 5, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_MethodDescriptorProto_clear_server_streaming(google_protobuf_MethodDescriptorProto* msg) { const upb_MiniTableField field = {6, UPB_SIZE(9, 2), 6, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_MethodDescriptorProto_server_streaming(const google_protobuf_MethodDescriptorProto* msg) { bool default_val = false; bool ret; const upb_MiniTableField field = {6, UPB_SIZE(9, 2), 6, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_MethodDescriptorProto_has_server_streaming(const google_protobuf_MethodDescriptorProto* msg) { const upb_MiniTableField field = {6, UPB_SIZE(9, 2), 6, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_MethodDescriptorProto_set_name(google_protobuf_MethodDescriptorProto *msg, upb_StringView value) { const upb_MiniTableField field = {1, UPB_SIZE(12, 8), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_MethodDescriptorProto_set_input_type(google_protobuf_MethodDescriptorProto *msg, upb_StringView value) { const upb_MiniTableField field = {2, UPB_SIZE(20, 24), 2, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_MethodDescriptorProto_set_output_type(google_protobuf_MethodDescriptorProto *msg, upb_StringView value) { const upb_MiniTableField field = {3, UPB_SIZE(28, 40), 3, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_MethodDescriptorProto_set_options(google_protobuf_MethodDescriptorProto *msg, google_protobuf_MethodOptions* value) { const upb_MiniTableField field = {4, UPB_SIZE(4, 56), 4, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE struct google_protobuf_MethodOptions* google_protobuf_MethodDescriptorProto_mutable_options(google_protobuf_MethodDescriptorProto* msg, upb_Arena* arena) { struct google_protobuf_MethodOptions* sub = (struct google_protobuf_MethodOptions*)google_protobuf_MethodDescriptorProto_options(msg); @@ -7792,11 +7921,11 @@ UPB_INLINE struct google_protobuf_MethodOptions* google_protobuf_MethodDescripto } UPB_INLINE void google_protobuf_MethodDescriptorProto_set_client_streaming(google_protobuf_MethodDescriptorProto *msg, bool value) { const upb_MiniTableField field = {5, UPB_SIZE(8, 1), 5, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_MethodDescriptorProto_set_server_streaming(google_protobuf_MethodDescriptorProto *msg, bool value) { const upb_MiniTableField field = {6, UPB_SIZE(9, 2), 6, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } /* google.protobuf.FileOptions */ @@ -7807,7 +7936,8 @@ UPB_INLINE google_protobuf_FileOptions* google_protobuf_FileOptions_new(upb_Aren UPB_INLINE google_protobuf_FileOptions* google_protobuf_FileOptions_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_FileOptions* ret = google_protobuf_FileOptions_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__FileOptions_msg_init, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__FileOptions_msg_init, NULL, 0, arena) != + kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -7817,330 +7947,350 @@ UPB_INLINE google_protobuf_FileOptions* google_protobuf_FileOptions_parse_ex(con int options, upb_Arena* arena) { google_protobuf_FileOptions* ret = google_protobuf_FileOptions_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__FileOptions_msg_init, extreg, options, arena) != - kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__FileOptions_msg_init, extreg, options, + arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_FileOptions_serialize(const google_protobuf_FileOptions* msg, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__FileOptions_msg_init, 0, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__FileOptions_msg_init, 0, arena, &ptr, len); return ptr; } UPB_INLINE char* google_protobuf_FileOptions_serialize_ex(const google_protobuf_FileOptions* msg, int options, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__FileOptions_msg_init, options, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__FileOptions_msg_init, options, arena, &ptr, len); return ptr; } UPB_INLINE void google_protobuf_FileOptions_clear_java_package(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {1, UPB_SIZE(24, 16), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_FileOptions_java_package(const google_protobuf_FileOptions* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; const upb_MiniTableField field = {1, UPB_SIZE(24, 16), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FileOptions_has_java_package(const google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {1, UPB_SIZE(24, 16), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileOptions_clear_java_outer_classname(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {8, 32, 2, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_FileOptions_java_outer_classname(const google_protobuf_FileOptions* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; const upb_MiniTableField field = {8, 32, 2, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FileOptions_has_java_outer_classname(const google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {8, 32, 2, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileOptions_clear_optimize_for(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {9, 4, 3, 2, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_FileOptions_optimize_for(const google_protobuf_FileOptions* msg) { int32_t default_val = 1; int32_t ret; const upb_MiniTableField field = {9, 4, 3, 2, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FileOptions_has_optimize_for(const google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {9, 4, 3, 2, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileOptions_clear_java_multiple_files(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {10, 8, 4, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_FileOptions_java_multiple_files(const google_protobuf_FileOptions* msg) { bool default_val = false; bool ret; const upb_MiniTableField field = {10, 8, 4, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FileOptions_has_java_multiple_files(const google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {10, 8, 4, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileOptions_clear_go_package(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {11, UPB_SIZE(40, 48), 5, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_FileOptions_go_package(const google_protobuf_FileOptions* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; const upb_MiniTableField field = {11, UPB_SIZE(40, 48), 5, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FileOptions_has_go_package(const google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {11, UPB_SIZE(40, 48), 5, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileOptions_clear_cc_generic_services(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {16, 9, 6, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_FileOptions_cc_generic_services(const google_protobuf_FileOptions* msg) { bool default_val = false; bool ret; const upb_MiniTableField field = {16, 9, 6, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FileOptions_has_cc_generic_services(const google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {16, 9, 6, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileOptions_clear_java_generic_services(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {17, 10, 7, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_FileOptions_java_generic_services(const google_protobuf_FileOptions* msg) { bool default_val = false; bool ret; const upb_MiniTableField field = {17, 10, 7, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FileOptions_has_java_generic_services(const google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {17, 10, 7, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileOptions_clear_py_generic_services(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {18, 11, 8, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_FileOptions_py_generic_services(const google_protobuf_FileOptions* msg) { bool default_val = false; bool ret; const upb_MiniTableField field = {18, 11, 8, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FileOptions_has_py_generic_services(const google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {18, 11, 8, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileOptions_clear_java_generate_equals_and_hash(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {20, 12, 9, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_FileOptions_java_generate_equals_and_hash(const google_protobuf_FileOptions* msg) { bool default_val = false; bool ret; const upb_MiniTableField field = {20, 12, 9, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FileOptions_has_java_generate_equals_and_hash(const google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {20, 12, 9, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileOptions_clear_deprecated(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {23, 13, 10, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_FileOptions_deprecated(const google_protobuf_FileOptions* msg) { bool default_val = false; bool ret; const upb_MiniTableField field = {23, 13, 10, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FileOptions_has_deprecated(const google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {23, 13, 10, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileOptions_clear_java_string_check_utf8(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {27, 14, 11, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_FileOptions_java_string_check_utf8(const google_protobuf_FileOptions* msg) { bool default_val = false; bool ret; const upb_MiniTableField field = {27, 14, 11, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FileOptions_has_java_string_check_utf8(const google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {27, 14, 11, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileOptions_clear_cc_enable_arenas(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {31, 15, 12, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_FileOptions_cc_enable_arenas(const google_protobuf_FileOptions* msg) { bool default_val = true; bool ret; const upb_MiniTableField field = {31, 15, 12, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FileOptions_has_cc_enable_arenas(const google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {31, 15, 12, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileOptions_clear_objc_class_prefix(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {36, UPB_SIZE(48, 64), 13, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_FileOptions_objc_class_prefix(const google_protobuf_FileOptions* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; const upb_MiniTableField field = {36, UPB_SIZE(48, 64), 13, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FileOptions_has_objc_class_prefix(const google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {36, UPB_SIZE(48, 64), 13, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileOptions_clear_csharp_namespace(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {37, UPB_SIZE(56, 80), 14, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_FileOptions_csharp_namespace(const google_protobuf_FileOptions* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; const upb_MiniTableField field = {37, UPB_SIZE(56, 80), 14, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FileOptions_has_csharp_namespace(const google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {37, UPB_SIZE(56, 80), 14, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileOptions_clear_swift_prefix(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {39, UPB_SIZE(64, 96), 15, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_FileOptions_swift_prefix(const google_protobuf_FileOptions* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; const upb_MiniTableField field = {39, UPB_SIZE(64, 96), 15, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FileOptions_has_swift_prefix(const google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {39, UPB_SIZE(64, 96), 15, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileOptions_clear_php_class_prefix(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {40, UPB_SIZE(72, 112), 16, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_FileOptions_php_class_prefix(const google_protobuf_FileOptions* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; const upb_MiniTableField field = {40, UPB_SIZE(72, 112), 16, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FileOptions_has_php_class_prefix(const google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {40, UPB_SIZE(72, 112), 16, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileOptions_clear_php_namespace(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {41, UPB_SIZE(80, 128), 17, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_FileOptions_php_namespace(const google_protobuf_FileOptions* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; const upb_MiniTableField field = {41, UPB_SIZE(80, 128), 17, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FileOptions_has_php_namespace(const google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {41, UPB_SIZE(80, 128), 17, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileOptions_clear_php_metadata_namespace(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {44, UPB_SIZE(88, 144), 18, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_FileOptions_php_metadata_namespace(const google_protobuf_FileOptions* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; const upb_MiniTableField field = {44, UPB_SIZE(88, 144), 18, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FileOptions_has_php_metadata_namespace(const google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {44, UPB_SIZE(88, 144), 18, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileOptions_clear_ruby_package(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {45, UPB_SIZE(96, 160), 19, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_FileOptions_ruby_package(const google_protobuf_FileOptions* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; const upb_MiniTableField field = {45, UPB_SIZE(96, 160), 19, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FileOptions_has_ruby_package(const google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {45, UPB_SIZE(96, 160), 19, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileOptions_clear_features(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {50, UPB_SIZE(16, 176), 20, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_FeatureSet* google_protobuf_FileOptions_features(const google_protobuf_FileOptions* msg) { const google_protobuf_FeatureSet* default_val = NULL; const google_protobuf_FeatureSet* ret; const upb_MiniTableField field = {50, UPB_SIZE(16, 176), 20, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FileOptions_has_features(const google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {50, UPB_SIZE(16, 176), 20, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileOptions_clear_uninterpreted_option(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {999, UPB_SIZE(20, 184), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_FileOptions_uninterpreted_option(const google_protobuf_FileOptions* msg, size_t* size) { const upb_MiniTableField field = {999, UPB_SIZE(20, 184), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_UninterpretedOption* const*)_upb_array_constptr(arr); @@ -8151,16 +8301,16 @@ UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_Fil } UPB_INLINE const upb_Array* _google_protobuf_FileOptions_uninterpreted_option_upb_array(const google_protobuf_FileOptions* msg, size_t* size) { const upb_MiniTableField field = {999, UPB_SIZE(20, 184), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } -UPB_INLINE upb_Array* _google_protobuf_FileOptions_uninterpreted_option_mutable_upb_array(const google_protobuf_FileOptions* msg, size_t* size, upb_Arena* arena) { +UPB_INLINE upb_Array* _google_protobuf_FileOptions_uninterpreted_option_mutable_upb_array(google_protobuf_FileOptions* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = {999, UPB_SIZE(20, 184), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - (upb_Message*)msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), + &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -8169,83 +8319,83 @@ UPB_INLINE upb_Array* _google_protobuf_FileOptions_uninterpreted_option_mutable_ UPB_INLINE void google_protobuf_FileOptions_set_java_package(google_protobuf_FileOptions *msg, upb_StringView value) { const upb_MiniTableField field = {1, UPB_SIZE(24, 16), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FileOptions_set_java_outer_classname(google_protobuf_FileOptions *msg, upb_StringView value) { const upb_MiniTableField field = {8, 32, 2, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FileOptions_set_optimize_for(google_protobuf_FileOptions *msg, int32_t value) { const upb_MiniTableField field = {9, 4, 3, 2, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FileOptions_set_java_multiple_files(google_protobuf_FileOptions *msg, bool value) { const upb_MiniTableField field = {10, 8, 4, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FileOptions_set_go_package(google_protobuf_FileOptions *msg, upb_StringView value) { const upb_MiniTableField field = {11, UPB_SIZE(40, 48), 5, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FileOptions_set_cc_generic_services(google_protobuf_FileOptions *msg, bool value) { const upb_MiniTableField field = {16, 9, 6, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FileOptions_set_java_generic_services(google_protobuf_FileOptions *msg, bool value) { const upb_MiniTableField field = {17, 10, 7, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FileOptions_set_py_generic_services(google_protobuf_FileOptions *msg, bool value) { const upb_MiniTableField field = {18, 11, 8, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FileOptions_set_java_generate_equals_and_hash(google_protobuf_FileOptions *msg, bool value) { const upb_MiniTableField field = {20, 12, 9, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FileOptions_set_deprecated(google_protobuf_FileOptions *msg, bool value) { const upb_MiniTableField field = {23, 13, 10, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FileOptions_set_java_string_check_utf8(google_protobuf_FileOptions *msg, bool value) { const upb_MiniTableField field = {27, 14, 11, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FileOptions_set_cc_enable_arenas(google_protobuf_FileOptions *msg, bool value) { const upb_MiniTableField field = {31, 15, 12, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FileOptions_set_objc_class_prefix(google_protobuf_FileOptions *msg, upb_StringView value) { const upb_MiniTableField field = {36, UPB_SIZE(48, 64), 13, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FileOptions_set_csharp_namespace(google_protobuf_FileOptions *msg, upb_StringView value) { const upb_MiniTableField field = {37, UPB_SIZE(56, 80), 14, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FileOptions_set_swift_prefix(google_protobuf_FileOptions *msg, upb_StringView value) { const upb_MiniTableField field = {39, UPB_SIZE(64, 96), 15, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FileOptions_set_php_class_prefix(google_protobuf_FileOptions *msg, upb_StringView value) { const upb_MiniTableField field = {40, UPB_SIZE(72, 112), 16, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FileOptions_set_php_namespace(google_protobuf_FileOptions *msg, upb_StringView value) { const upb_MiniTableField field = {41, UPB_SIZE(80, 128), 17, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FileOptions_set_php_metadata_namespace(google_protobuf_FileOptions *msg, upb_StringView value) { const upb_MiniTableField field = {44, UPB_SIZE(88, 144), 18, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FileOptions_set_ruby_package(google_protobuf_FileOptions *msg, upb_StringView value) { const upb_MiniTableField field = {45, UPB_SIZE(96, 160), 19, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FileOptions_set_features(google_protobuf_FileOptions *msg, google_protobuf_FeatureSet* value) { const upb_MiniTableField field = {50, UPB_SIZE(16, 176), 20, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE struct google_protobuf_FeatureSet* google_protobuf_FileOptions_mutable_features(google_protobuf_FileOptions* msg, upb_Arena* arena) { struct google_protobuf_FeatureSet* sub = (struct google_protobuf_FeatureSet*)google_protobuf_FileOptions_features(msg); @@ -8257,7 +8407,7 @@ UPB_INLINE struct google_protobuf_FeatureSet* google_protobuf_FileOptions_mutabl } UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_FileOptions_mutable_uninterpreted_option(google_protobuf_FileOptions* msg, size_t* size) { upb_MiniTableField field = {999, UPB_SIZE(20, 184), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetMutableArray(msg, &field); + upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_UninterpretedOption**)_upb_array_ptr(arr); @@ -8268,11 +8418,13 @@ UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_FileOptions_mut } UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_FileOptions_resize_uninterpreted_option(google_protobuf_FileOptions* msg, size_t size, upb_Arena* arena) { upb_MiniTableField field = {999, UPB_SIZE(20, 184), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return (google_protobuf_UninterpretedOption**)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); + return (google_protobuf_UninterpretedOption**)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg), + &field, size, arena); } UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_FileOptions_add_uninterpreted_option(google_protobuf_FileOptions* msg, upb_Arena* arena) { upb_MiniTableField field = {999, UPB_SIZE(20, 184), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray( + UPB_UPCAST(msg), &field, arena); if (!arr || !_upb_Array_ResizeUninitialized( arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; @@ -8292,7 +8444,8 @@ UPB_INLINE google_protobuf_MessageOptions* google_protobuf_MessageOptions_new(up UPB_INLINE google_protobuf_MessageOptions* google_protobuf_MessageOptions_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_MessageOptions* ret = google_protobuf_MessageOptions_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__MessageOptions_msg_init, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__MessageOptions_msg_init, NULL, 0, arena) != + kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -8302,120 +8455,126 @@ UPB_INLINE google_protobuf_MessageOptions* google_protobuf_MessageOptions_parse_ int options, upb_Arena* arena) { google_protobuf_MessageOptions* ret = google_protobuf_MessageOptions_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__MessageOptions_msg_init, extreg, options, arena) != - kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__MessageOptions_msg_init, extreg, options, + arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_MessageOptions_serialize(const google_protobuf_MessageOptions* msg, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__MessageOptions_msg_init, 0, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__MessageOptions_msg_init, 0, arena, &ptr, len); return ptr; } UPB_INLINE char* google_protobuf_MessageOptions_serialize_ex(const google_protobuf_MessageOptions* msg, int options, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__MessageOptions_msg_init, options, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__MessageOptions_msg_init, options, arena, &ptr, len); return ptr; } UPB_INLINE void google_protobuf_MessageOptions_clear_message_set_wire_format(google_protobuf_MessageOptions* msg) { const upb_MiniTableField field = {1, 1, 1, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_MessageOptions_message_set_wire_format(const google_protobuf_MessageOptions* msg) { bool default_val = false; bool ret; const upb_MiniTableField field = {1, 1, 1, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_MessageOptions_has_message_set_wire_format(const google_protobuf_MessageOptions* msg) { const upb_MiniTableField field = {1, 1, 1, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_MessageOptions_clear_no_standard_descriptor_accessor(google_protobuf_MessageOptions* msg) { const upb_MiniTableField field = {2, 2, 2, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_MessageOptions_no_standard_descriptor_accessor(const google_protobuf_MessageOptions* msg) { bool default_val = false; bool ret; const upb_MiniTableField field = {2, 2, 2, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_MessageOptions_has_no_standard_descriptor_accessor(const google_protobuf_MessageOptions* msg) { const upb_MiniTableField field = {2, 2, 2, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_MessageOptions_clear_deprecated(google_protobuf_MessageOptions* msg) { const upb_MiniTableField field = {3, 3, 3, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_MessageOptions_deprecated(const google_protobuf_MessageOptions* msg) { bool default_val = false; bool ret; const upb_MiniTableField field = {3, 3, 3, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_MessageOptions_has_deprecated(const google_protobuf_MessageOptions* msg) { const upb_MiniTableField field = {3, 3, 3, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_MessageOptions_clear_map_entry(google_protobuf_MessageOptions* msg) { const upb_MiniTableField field = {7, 4, 4, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_MessageOptions_map_entry(const google_protobuf_MessageOptions* msg) { bool default_val = false; bool ret; const upb_MiniTableField field = {7, 4, 4, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_MessageOptions_has_map_entry(const google_protobuf_MessageOptions* msg) { const upb_MiniTableField field = {7, 4, 4, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_MessageOptions_clear_deprecated_legacy_json_field_conflicts(google_protobuf_MessageOptions* msg) { const upb_MiniTableField field = {11, 5, 5, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_MessageOptions_deprecated_legacy_json_field_conflicts(const google_protobuf_MessageOptions* msg) { bool default_val = false; bool ret; const upb_MiniTableField field = {11, 5, 5, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_MessageOptions_has_deprecated_legacy_json_field_conflicts(const google_protobuf_MessageOptions* msg) { const upb_MiniTableField field = {11, 5, 5, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_MessageOptions_clear_features(google_protobuf_MessageOptions* msg) { const upb_MiniTableField field = {12, 8, 6, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_FeatureSet* google_protobuf_MessageOptions_features(const google_protobuf_MessageOptions* msg) { const google_protobuf_FeatureSet* default_val = NULL; const google_protobuf_FeatureSet* ret; const upb_MiniTableField field = {12, 8, 6, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_MessageOptions_has_features(const google_protobuf_MessageOptions* msg) { const upb_MiniTableField field = {12, 8, 6, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_MessageOptions_clear_uninterpreted_option(google_protobuf_MessageOptions* msg) { const upb_MiniTableField field = {999, UPB_SIZE(12, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_MessageOptions_uninterpreted_option(const google_protobuf_MessageOptions* msg, size_t* size) { const upb_MiniTableField field = {999, UPB_SIZE(12, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_UninterpretedOption* const*)_upb_array_constptr(arr); @@ -8426,16 +8585,16 @@ UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_Mes } UPB_INLINE const upb_Array* _google_protobuf_MessageOptions_uninterpreted_option_upb_array(const google_protobuf_MessageOptions* msg, size_t* size) { const upb_MiniTableField field = {999, UPB_SIZE(12, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } -UPB_INLINE upb_Array* _google_protobuf_MessageOptions_uninterpreted_option_mutable_upb_array(const google_protobuf_MessageOptions* msg, size_t* size, upb_Arena* arena) { +UPB_INLINE upb_Array* _google_protobuf_MessageOptions_uninterpreted_option_mutable_upb_array(google_protobuf_MessageOptions* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = {999, UPB_SIZE(12, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - (upb_Message*)msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), + &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -8444,27 +8603,27 @@ UPB_INLINE upb_Array* _google_protobuf_MessageOptions_uninterpreted_option_mutab UPB_INLINE void google_protobuf_MessageOptions_set_message_set_wire_format(google_protobuf_MessageOptions *msg, bool value) { const upb_MiniTableField field = {1, 1, 1, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_MessageOptions_set_no_standard_descriptor_accessor(google_protobuf_MessageOptions *msg, bool value) { const upb_MiniTableField field = {2, 2, 2, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_MessageOptions_set_deprecated(google_protobuf_MessageOptions *msg, bool value) { const upb_MiniTableField field = {3, 3, 3, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_MessageOptions_set_map_entry(google_protobuf_MessageOptions *msg, bool value) { const upb_MiniTableField field = {7, 4, 4, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_MessageOptions_set_deprecated_legacy_json_field_conflicts(google_protobuf_MessageOptions *msg, bool value) { const upb_MiniTableField field = {11, 5, 5, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_MessageOptions_set_features(google_protobuf_MessageOptions *msg, google_protobuf_FeatureSet* value) { const upb_MiniTableField field = {12, 8, 6, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE struct google_protobuf_FeatureSet* google_protobuf_MessageOptions_mutable_features(google_protobuf_MessageOptions* msg, upb_Arena* arena) { struct google_protobuf_FeatureSet* sub = (struct google_protobuf_FeatureSet*)google_protobuf_MessageOptions_features(msg); @@ -8476,7 +8635,7 @@ UPB_INLINE struct google_protobuf_FeatureSet* google_protobuf_MessageOptions_mut } UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_MessageOptions_mutable_uninterpreted_option(google_protobuf_MessageOptions* msg, size_t* size) { upb_MiniTableField field = {999, UPB_SIZE(12, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetMutableArray(msg, &field); + upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_UninterpretedOption**)_upb_array_ptr(arr); @@ -8487,11 +8646,13 @@ UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_MessageOptions_ } UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_MessageOptions_resize_uninterpreted_option(google_protobuf_MessageOptions* msg, size_t size, upb_Arena* arena) { upb_MiniTableField field = {999, UPB_SIZE(12, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return (google_protobuf_UninterpretedOption**)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); + return (google_protobuf_UninterpretedOption**)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg), + &field, size, arena); } UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_MessageOptions_add_uninterpreted_option(google_protobuf_MessageOptions* msg, upb_Arena* arena) { upb_MiniTableField field = {999, UPB_SIZE(12, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray( + UPB_UPCAST(msg), &field, arena); if (!arr || !_upb_Array_ResizeUninitialized( arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; @@ -8511,7 +8672,8 @@ UPB_INLINE google_protobuf_FieldOptions* google_protobuf_FieldOptions_new(upb_Ar UPB_INLINE google_protobuf_FieldOptions* google_protobuf_FieldOptions_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_FieldOptions* ret = google_protobuf_FieldOptions_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__FieldOptions_msg_init, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__FieldOptions_msg_init, NULL, 0, arena) != + kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -8521,165 +8683,174 @@ UPB_INLINE google_protobuf_FieldOptions* google_protobuf_FieldOptions_parse_ex(c int options, upb_Arena* arena) { google_protobuf_FieldOptions* ret = google_protobuf_FieldOptions_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__FieldOptions_msg_init, extreg, options, arena) != - kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__FieldOptions_msg_init, extreg, options, + arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_FieldOptions_serialize(const google_protobuf_FieldOptions* msg, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__FieldOptions_msg_init, 0, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__FieldOptions_msg_init, 0, arena, &ptr, len); return ptr; } UPB_INLINE char* google_protobuf_FieldOptions_serialize_ex(const google_protobuf_FieldOptions* msg, int options, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__FieldOptions_msg_init, options, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__FieldOptions_msg_init, options, arena, &ptr, len); return ptr; } UPB_INLINE void google_protobuf_FieldOptions_clear_ctype(google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {1, 4, 1, 3, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_FieldOptions_ctype(const google_protobuf_FieldOptions* msg) { int32_t default_val = 0; int32_t ret; const upb_MiniTableField field = {1, 4, 1, 3, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FieldOptions_has_ctype(const google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {1, 4, 1, 3, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldOptions_clear_packed(google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {2, 8, 2, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_FieldOptions_packed(const google_protobuf_FieldOptions* msg) { bool default_val = false; bool ret; const upb_MiniTableField field = {2, 8, 2, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FieldOptions_has_packed(const google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {2, 8, 2, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldOptions_clear_deprecated(google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {3, 9, 3, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_FieldOptions_deprecated(const google_protobuf_FieldOptions* msg) { bool default_val = false; bool ret; const upb_MiniTableField field = {3, 9, 3, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FieldOptions_has_deprecated(const google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {3, 9, 3, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldOptions_clear_lazy(google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {5, 10, 4, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_FieldOptions_lazy(const google_protobuf_FieldOptions* msg) { bool default_val = false; bool ret; const upb_MiniTableField field = {5, 10, 4, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FieldOptions_has_lazy(const google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {5, 10, 4, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldOptions_clear_jstype(google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {6, 12, 5, 4, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_FieldOptions_jstype(const google_protobuf_FieldOptions* msg) { int32_t default_val = 0; int32_t ret; const upb_MiniTableField field = {6, 12, 5, 4, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FieldOptions_has_jstype(const google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {6, 12, 5, 4, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldOptions_clear_weak(google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {10, 16, 6, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_FieldOptions_weak(const google_protobuf_FieldOptions* msg) { bool default_val = false; bool ret; const upb_MiniTableField field = {10, 16, 6, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FieldOptions_has_weak(const google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {10, 16, 6, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldOptions_clear_unverified_lazy(google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {15, 17, 7, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_FieldOptions_unverified_lazy(const google_protobuf_FieldOptions* msg) { bool default_val = false; bool ret; const upb_MiniTableField field = {15, 17, 7, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FieldOptions_has_unverified_lazy(const google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {15, 17, 7, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldOptions_clear_debug_redact(google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {16, 18, 8, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_FieldOptions_debug_redact(const google_protobuf_FieldOptions* msg) { bool default_val = false; bool ret; const upb_MiniTableField field = {16, 18, 8, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FieldOptions_has_debug_redact(const google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {16, 18, 8, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldOptions_clear_retention(google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {17, 20, 9, 5, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_FieldOptions_retention(const google_protobuf_FieldOptions* msg) { int32_t default_val = 0; int32_t ret; const upb_MiniTableField field = {17, 20, 9, 5, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FieldOptions_has_retention(const google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {17, 20, 9, 5, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldOptions_clear_targets(google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {19, 24, 0, 6, 14, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t const* google_protobuf_FieldOptions_targets(const google_protobuf_FieldOptions* msg, size_t* size) { const upb_MiniTableField field = {19, 24, 0, 6, 14, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (int32_t const*)_upb_array_constptr(arr); @@ -8690,16 +8861,16 @@ UPB_INLINE int32_t const* google_protobuf_FieldOptions_targets(const google_prot } UPB_INLINE const upb_Array* _google_protobuf_FieldOptions_targets_upb_array(const google_protobuf_FieldOptions* msg, size_t* size) { const upb_MiniTableField field = {19, 24, 0, 6, 14, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } -UPB_INLINE upb_Array* _google_protobuf_FieldOptions_targets_mutable_upb_array(const google_protobuf_FieldOptions* msg, size_t* size, upb_Arena* arena) { +UPB_INLINE upb_Array* _google_protobuf_FieldOptions_targets_mutable_upb_array(google_protobuf_FieldOptions* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = {19, 24, 0, 6, 14, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - (upb_Message*)msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), + &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -8707,11 +8878,11 @@ UPB_INLINE upb_Array* _google_protobuf_FieldOptions_targets_mutable_upb_array(co } UPB_INLINE void google_protobuf_FieldOptions_clear_edition_defaults(google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {20, UPB_SIZE(28, 32), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_FieldOptions_EditionDefault* const* google_protobuf_FieldOptions_edition_defaults(const google_protobuf_FieldOptions* msg, size_t* size) { const upb_MiniTableField field = {20, UPB_SIZE(28, 32), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_FieldOptions_EditionDefault* const*)_upb_array_constptr(arr); @@ -8722,16 +8893,16 @@ UPB_INLINE const google_protobuf_FieldOptions_EditionDefault* const* google_prot } UPB_INLINE const upb_Array* _google_protobuf_FieldOptions_edition_defaults_upb_array(const google_protobuf_FieldOptions* msg, size_t* size) { const upb_MiniTableField field = {20, UPB_SIZE(28, 32), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } -UPB_INLINE upb_Array* _google_protobuf_FieldOptions_edition_defaults_mutable_upb_array(const google_protobuf_FieldOptions* msg, size_t* size, upb_Arena* arena) { +UPB_INLINE upb_Array* _google_protobuf_FieldOptions_edition_defaults_mutable_upb_array(google_protobuf_FieldOptions* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = {20, UPB_SIZE(28, 32), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - (upb_Message*)msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), + &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -8739,26 +8910,27 @@ UPB_INLINE upb_Array* _google_protobuf_FieldOptions_edition_defaults_mutable_upb } UPB_INLINE void google_protobuf_FieldOptions_clear_features(google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {21, UPB_SIZE(32, 40), 10, 1, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_FeatureSet* google_protobuf_FieldOptions_features(const google_protobuf_FieldOptions* msg) { const google_protobuf_FeatureSet* default_val = NULL; const google_protobuf_FeatureSet* ret; const upb_MiniTableField field = {21, UPB_SIZE(32, 40), 10, 1, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FieldOptions_has_features(const google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {21, UPB_SIZE(32, 40), 10, 1, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldOptions_clear_uninterpreted_option(google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {999, UPB_SIZE(36, 48), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_FieldOptions_uninterpreted_option(const google_protobuf_FieldOptions* msg, size_t* size) { const upb_MiniTableField field = {999, UPB_SIZE(36, 48), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_UninterpretedOption* const*)_upb_array_constptr(arr); @@ -8769,16 +8941,16 @@ UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_Fie } UPB_INLINE const upb_Array* _google_protobuf_FieldOptions_uninterpreted_option_upb_array(const google_protobuf_FieldOptions* msg, size_t* size) { const upb_MiniTableField field = {999, UPB_SIZE(36, 48), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } -UPB_INLINE upb_Array* _google_protobuf_FieldOptions_uninterpreted_option_mutable_upb_array(const google_protobuf_FieldOptions* msg, size_t* size, upb_Arena* arena) { +UPB_INLINE upb_Array* _google_protobuf_FieldOptions_uninterpreted_option_mutable_upb_array(google_protobuf_FieldOptions* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = {999, UPB_SIZE(36, 48), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - (upb_Message*)msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), + &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -8787,43 +8959,43 @@ UPB_INLINE upb_Array* _google_protobuf_FieldOptions_uninterpreted_option_mutable UPB_INLINE void google_protobuf_FieldOptions_set_ctype(google_protobuf_FieldOptions *msg, int32_t value) { const upb_MiniTableField field = {1, 4, 1, 3, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FieldOptions_set_packed(google_protobuf_FieldOptions *msg, bool value) { const upb_MiniTableField field = {2, 8, 2, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FieldOptions_set_deprecated(google_protobuf_FieldOptions *msg, bool value) { const upb_MiniTableField field = {3, 9, 3, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FieldOptions_set_lazy(google_protobuf_FieldOptions *msg, bool value) { const upb_MiniTableField field = {5, 10, 4, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FieldOptions_set_jstype(google_protobuf_FieldOptions *msg, int32_t value) { const upb_MiniTableField field = {6, 12, 5, 4, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FieldOptions_set_weak(google_protobuf_FieldOptions *msg, bool value) { const upb_MiniTableField field = {10, 16, 6, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FieldOptions_set_unverified_lazy(google_protobuf_FieldOptions *msg, bool value) { const upb_MiniTableField field = {15, 17, 7, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FieldOptions_set_debug_redact(google_protobuf_FieldOptions *msg, bool value) { const upb_MiniTableField field = {16, 18, 8, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FieldOptions_set_retention(google_protobuf_FieldOptions *msg, int32_t value) { const upb_MiniTableField field = {17, 20, 9, 5, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE int32_t* google_protobuf_FieldOptions_mutable_targets(google_protobuf_FieldOptions* msg, size_t* size) { upb_MiniTableField field = {19, 24, 0, 6, 14, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetMutableArray(msg, &field); + upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (int32_t*)_upb_array_ptr(arr); @@ -8834,11 +9006,13 @@ UPB_INLINE int32_t* google_protobuf_FieldOptions_mutable_targets(google_protobuf } UPB_INLINE int32_t* google_protobuf_FieldOptions_resize_targets(google_protobuf_FieldOptions* msg, size_t size, upb_Arena* arena) { upb_MiniTableField field = {19, 24, 0, 6, 14, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return (int32_t*)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); + return (int32_t*)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg), + &field, size, arena); } UPB_INLINE bool google_protobuf_FieldOptions_add_targets(google_protobuf_FieldOptions* msg, int32_t val, upb_Arena* arena) { upb_MiniTableField field = {19, 24, 0, 6, 14, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray( + UPB_UPCAST(msg), &field, arena); if (!arr || !_upb_Array_ResizeUninitialized( arr, arr->UPB_PRIVATE(size) + 1, arena)) { return false; @@ -8849,7 +9023,7 @@ UPB_INLINE bool google_protobuf_FieldOptions_add_targets(google_protobuf_FieldOp } UPB_INLINE google_protobuf_FieldOptions_EditionDefault** google_protobuf_FieldOptions_mutable_edition_defaults(google_protobuf_FieldOptions* msg, size_t* size) { upb_MiniTableField field = {20, UPB_SIZE(28, 32), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetMutableArray(msg, &field); + upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_FieldOptions_EditionDefault**)_upb_array_ptr(arr); @@ -8860,11 +9034,13 @@ UPB_INLINE google_protobuf_FieldOptions_EditionDefault** google_protobuf_FieldOp } UPB_INLINE google_protobuf_FieldOptions_EditionDefault** google_protobuf_FieldOptions_resize_edition_defaults(google_protobuf_FieldOptions* msg, size_t size, upb_Arena* arena) { upb_MiniTableField field = {20, UPB_SIZE(28, 32), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return (google_protobuf_FieldOptions_EditionDefault**)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); + return (google_protobuf_FieldOptions_EditionDefault**)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg), + &field, size, arena); } UPB_INLINE struct google_protobuf_FieldOptions_EditionDefault* google_protobuf_FieldOptions_add_edition_defaults(google_protobuf_FieldOptions* msg, upb_Arena* arena) { upb_MiniTableField field = {20, UPB_SIZE(28, 32), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray( + UPB_UPCAST(msg), &field, arena); if (!arr || !_upb_Array_ResizeUninitialized( arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; @@ -8877,7 +9053,7 @@ UPB_INLINE struct google_protobuf_FieldOptions_EditionDefault* google_protobuf_F } UPB_INLINE void google_protobuf_FieldOptions_set_features(google_protobuf_FieldOptions *msg, google_protobuf_FeatureSet* value) { const upb_MiniTableField field = {21, UPB_SIZE(32, 40), 10, 1, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE struct google_protobuf_FeatureSet* google_protobuf_FieldOptions_mutable_features(google_protobuf_FieldOptions* msg, upb_Arena* arena) { struct google_protobuf_FeatureSet* sub = (struct google_protobuf_FeatureSet*)google_protobuf_FieldOptions_features(msg); @@ -8889,7 +9065,7 @@ UPB_INLINE struct google_protobuf_FeatureSet* google_protobuf_FieldOptions_mutab } UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_FieldOptions_mutable_uninterpreted_option(google_protobuf_FieldOptions* msg, size_t* size) { upb_MiniTableField field = {999, UPB_SIZE(36, 48), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetMutableArray(msg, &field); + upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_UninterpretedOption**)_upb_array_ptr(arr); @@ -8900,11 +9076,13 @@ UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_FieldOptions_mu } UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_FieldOptions_resize_uninterpreted_option(google_protobuf_FieldOptions* msg, size_t size, upb_Arena* arena) { upb_MiniTableField field = {999, UPB_SIZE(36, 48), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return (google_protobuf_UninterpretedOption**)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); + return (google_protobuf_UninterpretedOption**)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg), + &field, size, arena); } UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_FieldOptions_add_uninterpreted_option(google_protobuf_FieldOptions* msg, upb_Arena* arena) { upb_MiniTableField field = {999, UPB_SIZE(36, 48), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray( + UPB_UPCAST(msg), &field, arena); if (!arr || !_upb_Array_ResizeUninitialized( arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; @@ -8924,7 +9102,8 @@ UPB_INLINE google_protobuf_FieldOptions_EditionDefault* google_protobuf_FieldOpt UPB_INLINE google_protobuf_FieldOptions_EditionDefault* google_protobuf_FieldOptions_EditionDefault_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_FieldOptions_EditionDefault* ret = google_protobuf_FieldOptions_EditionDefault_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__FieldOptions__EditionDefault_msg_init, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__FieldOptions__EditionDefault_msg_init, NULL, 0, arena) != + kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -8934,61 +9113,63 @@ UPB_INLINE google_protobuf_FieldOptions_EditionDefault* google_protobuf_FieldOpt int options, upb_Arena* arena) { google_protobuf_FieldOptions_EditionDefault* ret = google_protobuf_FieldOptions_EditionDefault_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__FieldOptions__EditionDefault_msg_init, extreg, options, arena) != - kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__FieldOptions__EditionDefault_msg_init, extreg, options, + arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_FieldOptions_EditionDefault_serialize(const google_protobuf_FieldOptions_EditionDefault* msg, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__FieldOptions__EditionDefault_msg_init, 0, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__FieldOptions__EditionDefault_msg_init, 0, arena, &ptr, len); return ptr; } UPB_INLINE char* google_protobuf_FieldOptions_EditionDefault_serialize_ex(const google_protobuf_FieldOptions_EditionDefault* msg, int options, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__FieldOptions__EditionDefault_msg_init, options, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__FieldOptions__EditionDefault_msg_init, options, arena, &ptr, len); return ptr; } UPB_INLINE void google_protobuf_FieldOptions_EditionDefault_clear_value(google_protobuf_FieldOptions_EditionDefault* msg) { const upb_MiniTableField field = {2, 8, 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_FieldOptions_EditionDefault_value(const google_protobuf_FieldOptions_EditionDefault* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; const upb_MiniTableField field = {2, 8, 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FieldOptions_EditionDefault_has_value(const google_protobuf_FieldOptions_EditionDefault* msg) { const upb_MiniTableField field = {2, 8, 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldOptions_EditionDefault_clear_edition(google_protobuf_FieldOptions_EditionDefault* msg) { const upb_MiniTableField field = {3, 4, 2, 0, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_FieldOptions_EditionDefault_edition(const google_protobuf_FieldOptions_EditionDefault* msg) { int32_t default_val = 0; int32_t ret; const upb_MiniTableField field = {3, 4, 2, 0, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FieldOptions_EditionDefault_has_edition(const google_protobuf_FieldOptions_EditionDefault* msg) { const upb_MiniTableField field = {3, 4, 2, 0, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldOptions_EditionDefault_set_value(google_protobuf_FieldOptions_EditionDefault *msg, upb_StringView value) { const upb_MiniTableField field = {2, 8, 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FieldOptions_EditionDefault_set_edition(google_protobuf_FieldOptions_EditionDefault *msg, int32_t value) { const upb_MiniTableField field = {3, 4, 2, 0, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } /* google.protobuf.OneofOptions */ @@ -8999,7 +9180,8 @@ UPB_INLINE google_protobuf_OneofOptions* google_protobuf_OneofOptions_new(upb_Ar UPB_INLINE google_protobuf_OneofOptions* google_protobuf_OneofOptions_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_OneofOptions* ret = google_protobuf_OneofOptions_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__OneofOptions_msg_init, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__OneofOptions_msg_init, NULL, 0, arena) != + kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -9009,45 +9191,46 @@ UPB_INLINE google_protobuf_OneofOptions* google_protobuf_OneofOptions_parse_ex(c int options, upb_Arena* arena) { google_protobuf_OneofOptions* ret = google_protobuf_OneofOptions_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__OneofOptions_msg_init, extreg, options, arena) != - kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__OneofOptions_msg_init, extreg, options, + arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_OneofOptions_serialize(const google_protobuf_OneofOptions* msg, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__OneofOptions_msg_init, 0, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__OneofOptions_msg_init, 0, arena, &ptr, len); return ptr; } UPB_INLINE char* google_protobuf_OneofOptions_serialize_ex(const google_protobuf_OneofOptions* msg, int options, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__OneofOptions_msg_init, options, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__OneofOptions_msg_init, options, arena, &ptr, len); return ptr; } UPB_INLINE void google_protobuf_OneofOptions_clear_features(google_protobuf_OneofOptions* msg) { const upb_MiniTableField field = {1, UPB_SIZE(4, 8), 1, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_FeatureSet* google_protobuf_OneofOptions_features(const google_protobuf_OneofOptions* msg) { const google_protobuf_FeatureSet* default_val = NULL; const google_protobuf_FeatureSet* ret; const upb_MiniTableField field = {1, UPB_SIZE(4, 8), 1, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_OneofOptions_has_features(const google_protobuf_OneofOptions* msg) { const upb_MiniTableField field = {1, UPB_SIZE(4, 8), 1, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_OneofOptions_clear_uninterpreted_option(google_protobuf_OneofOptions* msg) { const upb_MiniTableField field = {999, UPB_SIZE(8, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_OneofOptions_uninterpreted_option(const google_protobuf_OneofOptions* msg, size_t* size) { const upb_MiniTableField field = {999, UPB_SIZE(8, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_UninterpretedOption* const*)_upb_array_constptr(arr); @@ -9058,16 +9241,16 @@ UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_One } UPB_INLINE const upb_Array* _google_protobuf_OneofOptions_uninterpreted_option_upb_array(const google_protobuf_OneofOptions* msg, size_t* size) { const upb_MiniTableField field = {999, UPB_SIZE(8, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } -UPB_INLINE upb_Array* _google_protobuf_OneofOptions_uninterpreted_option_mutable_upb_array(const google_protobuf_OneofOptions* msg, size_t* size, upb_Arena* arena) { +UPB_INLINE upb_Array* _google_protobuf_OneofOptions_uninterpreted_option_mutable_upb_array(google_protobuf_OneofOptions* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = {999, UPB_SIZE(8, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - (upb_Message*)msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), + &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -9076,7 +9259,7 @@ UPB_INLINE upb_Array* _google_protobuf_OneofOptions_uninterpreted_option_mutable UPB_INLINE void google_protobuf_OneofOptions_set_features(google_protobuf_OneofOptions *msg, google_protobuf_FeatureSet* value) { const upb_MiniTableField field = {1, UPB_SIZE(4, 8), 1, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE struct google_protobuf_FeatureSet* google_protobuf_OneofOptions_mutable_features(google_protobuf_OneofOptions* msg, upb_Arena* arena) { struct google_protobuf_FeatureSet* sub = (struct google_protobuf_FeatureSet*)google_protobuf_OneofOptions_features(msg); @@ -9088,7 +9271,7 @@ UPB_INLINE struct google_protobuf_FeatureSet* google_protobuf_OneofOptions_mutab } UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_OneofOptions_mutable_uninterpreted_option(google_protobuf_OneofOptions* msg, size_t* size) { upb_MiniTableField field = {999, UPB_SIZE(8, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetMutableArray(msg, &field); + upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_UninterpretedOption**)_upb_array_ptr(arr); @@ -9099,11 +9282,13 @@ UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_OneofOptions_mu } UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_OneofOptions_resize_uninterpreted_option(google_protobuf_OneofOptions* msg, size_t size, upb_Arena* arena) { upb_MiniTableField field = {999, UPB_SIZE(8, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return (google_protobuf_UninterpretedOption**)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); + return (google_protobuf_UninterpretedOption**)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg), + &field, size, arena); } UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_OneofOptions_add_uninterpreted_option(google_protobuf_OneofOptions* msg, upb_Arena* arena) { upb_MiniTableField field = {999, UPB_SIZE(8, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray( + UPB_UPCAST(msg), &field, arena); if (!arr || !_upb_Array_ResizeUninitialized( arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; @@ -9123,7 +9308,8 @@ UPB_INLINE google_protobuf_EnumOptions* google_protobuf_EnumOptions_new(upb_Aren UPB_INLINE google_protobuf_EnumOptions* google_protobuf_EnumOptions_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_EnumOptions* ret = google_protobuf_EnumOptions_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__EnumOptions_msg_init, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__EnumOptions_msg_init, NULL, 0, arena) != + kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -9133,90 +9319,94 @@ UPB_INLINE google_protobuf_EnumOptions* google_protobuf_EnumOptions_parse_ex(con int options, upb_Arena* arena) { google_protobuf_EnumOptions* ret = google_protobuf_EnumOptions_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__EnumOptions_msg_init, extreg, options, arena) != - kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__EnumOptions_msg_init, extreg, options, + arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_EnumOptions_serialize(const google_protobuf_EnumOptions* msg, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__EnumOptions_msg_init, 0, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__EnumOptions_msg_init, 0, arena, &ptr, len); return ptr; } UPB_INLINE char* google_protobuf_EnumOptions_serialize_ex(const google_protobuf_EnumOptions* msg, int options, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__EnumOptions_msg_init, options, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__EnumOptions_msg_init, options, arena, &ptr, len); return ptr; } UPB_INLINE void google_protobuf_EnumOptions_clear_allow_alias(google_protobuf_EnumOptions* msg) { const upb_MiniTableField field = {2, 1, 1, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_EnumOptions_allow_alias(const google_protobuf_EnumOptions* msg) { bool default_val = false; bool ret; const upb_MiniTableField field = {2, 1, 1, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_EnumOptions_has_allow_alias(const google_protobuf_EnumOptions* msg) { const upb_MiniTableField field = {2, 1, 1, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_EnumOptions_clear_deprecated(google_protobuf_EnumOptions* msg) { const upb_MiniTableField field = {3, 2, 2, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_EnumOptions_deprecated(const google_protobuf_EnumOptions* msg) { bool default_val = false; bool ret; const upb_MiniTableField field = {3, 2, 2, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_EnumOptions_has_deprecated(const google_protobuf_EnumOptions* msg) { const upb_MiniTableField field = {3, 2, 2, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_EnumOptions_clear_deprecated_legacy_json_field_conflicts(google_protobuf_EnumOptions* msg) { const upb_MiniTableField field = {6, 3, 3, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_EnumOptions_deprecated_legacy_json_field_conflicts(const google_protobuf_EnumOptions* msg) { bool default_val = false; bool ret; const upb_MiniTableField field = {6, 3, 3, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_EnumOptions_has_deprecated_legacy_json_field_conflicts(const google_protobuf_EnumOptions* msg) { const upb_MiniTableField field = {6, 3, 3, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_EnumOptions_clear_features(google_protobuf_EnumOptions* msg) { const upb_MiniTableField field = {7, UPB_SIZE(4, 8), 4, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_FeatureSet* google_protobuf_EnumOptions_features(const google_protobuf_EnumOptions* msg) { const google_protobuf_FeatureSet* default_val = NULL; const google_protobuf_FeatureSet* ret; const upb_MiniTableField field = {7, UPB_SIZE(4, 8), 4, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_EnumOptions_has_features(const google_protobuf_EnumOptions* msg) { const upb_MiniTableField field = {7, UPB_SIZE(4, 8), 4, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_EnumOptions_clear_uninterpreted_option(google_protobuf_EnumOptions* msg) { const upb_MiniTableField field = {999, UPB_SIZE(8, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_EnumOptions_uninterpreted_option(const google_protobuf_EnumOptions* msg, size_t* size) { const upb_MiniTableField field = {999, UPB_SIZE(8, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_UninterpretedOption* const*)_upb_array_constptr(arr); @@ -9227,16 +9417,16 @@ UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_Enu } UPB_INLINE const upb_Array* _google_protobuf_EnumOptions_uninterpreted_option_upb_array(const google_protobuf_EnumOptions* msg, size_t* size) { const upb_MiniTableField field = {999, UPB_SIZE(8, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } -UPB_INLINE upb_Array* _google_protobuf_EnumOptions_uninterpreted_option_mutable_upb_array(const google_protobuf_EnumOptions* msg, size_t* size, upb_Arena* arena) { +UPB_INLINE upb_Array* _google_protobuf_EnumOptions_uninterpreted_option_mutable_upb_array(google_protobuf_EnumOptions* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = {999, UPB_SIZE(8, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - (upb_Message*)msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), + &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -9245,19 +9435,19 @@ UPB_INLINE upb_Array* _google_protobuf_EnumOptions_uninterpreted_option_mutable_ UPB_INLINE void google_protobuf_EnumOptions_set_allow_alias(google_protobuf_EnumOptions *msg, bool value) { const upb_MiniTableField field = {2, 1, 1, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_EnumOptions_set_deprecated(google_protobuf_EnumOptions *msg, bool value) { const upb_MiniTableField field = {3, 2, 2, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_EnumOptions_set_deprecated_legacy_json_field_conflicts(google_protobuf_EnumOptions *msg, bool value) { const upb_MiniTableField field = {6, 3, 3, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_EnumOptions_set_features(google_protobuf_EnumOptions *msg, google_protobuf_FeatureSet* value) { const upb_MiniTableField field = {7, UPB_SIZE(4, 8), 4, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE struct google_protobuf_FeatureSet* google_protobuf_EnumOptions_mutable_features(google_protobuf_EnumOptions* msg, upb_Arena* arena) { struct google_protobuf_FeatureSet* sub = (struct google_protobuf_FeatureSet*)google_protobuf_EnumOptions_features(msg); @@ -9269,7 +9459,7 @@ UPB_INLINE struct google_protobuf_FeatureSet* google_protobuf_EnumOptions_mutabl } UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_EnumOptions_mutable_uninterpreted_option(google_protobuf_EnumOptions* msg, size_t* size) { upb_MiniTableField field = {999, UPB_SIZE(8, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetMutableArray(msg, &field); + upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_UninterpretedOption**)_upb_array_ptr(arr); @@ -9280,11 +9470,13 @@ UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_EnumOptions_mut } UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_EnumOptions_resize_uninterpreted_option(google_protobuf_EnumOptions* msg, size_t size, upb_Arena* arena) { upb_MiniTableField field = {999, UPB_SIZE(8, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return (google_protobuf_UninterpretedOption**)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); + return (google_protobuf_UninterpretedOption**)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg), + &field, size, arena); } UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_EnumOptions_add_uninterpreted_option(google_protobuf_EnumOptions* msg, upb_Arena* arena) { upb_MiniTableField field = {999, UPB_SIZE(8, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray( + UPB_UPCAST(msg), &field, arena); if (!arr || !_upb_Array_ResizeUninitialized( arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; @@ -9304,7 +9496,8 @@ UPB_INLINE google_protobuf_EnumValueOptions* google_protobuf_EnumValueOptions_ne UPB_INLINE google_protobuf_EnumValueOptions* google_protobuf_EnumValueOptions_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_EnumValueOptions* ret = google_protobuf_EnumValueOptions_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__EnumValueOptions_msg_init, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__EnumValueOptions_msg_init, NULL, 0, arena) != + kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -9314,75 +9507,78 @@ UPB_INLINE google_protobuf_EnumValueOptions* google_protobuf_EnumValueOptions_pa int options, upb_Arena* arena) { google_protobuf_EnumValueOptions* ret = google_protobuf_EnumValueOptions_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__EnumValueOptions_msg_init, extreg, options, arena) != - kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__EnumValueOptions_msg_init, extreg, options, + arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_EnumValueOptions_serialize(const google_protobuf_EnumValueOptions* msg, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__EnumValueOptions_msg_init, 0, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__EnumValueOptions_msg_init, 0, arena, &ptr, len); return ptr; } UPB_INLINE char* google_protobuf_EnumValueOptions_serialize_ex(const google_protobuf_EnumValueOptions* msg, int options, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__EnumValueOptions_msg_init, options, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__EnumValueOptions_msg_init, options, arena, &ptr, len); return ptr; } UPB_INLINE void google_protobuf_EnumValueOptions_clear_deprecated(google_protobuf_EnumValueOptions* msg) { const upb_MiniTableField field = {1, 1, 1, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_EnumValueOptions_deprecated(const google_protobuf_EnumValueOptions* msg) { bool default_val = false; bool ret; const upb_MiniTableField field = {1, 1, 1, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_EnumValueOptions_has_deprecated(const google_protobuf_EnumValueOptions* msg) { const upb_MiniTableField field = {1, 1, 1, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_EnumValueOptions_clear_features(google_protobuf_EnumValueOptions* msg) { const upb_MiniTableField field = {2, UPB_SIZE(4, 8), 2, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_FeatureSet* google_protobuf_EnumValueOptions_features(const google_protobuf_EnumValueOptions* msg) { const google_protobuf_FeatureSet* default_val = NULL; const google_protobuf_FeatureSet* ret; const upb_MiniTableField field = {2, UPB_SIZE(4, 8), 2, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_EnumValueOptions_has_features(const google_protobuf_EnumValueOptions* msg) { const upb_MiniTableField field = {2, UPB_SIZE(4, 8), 2, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_EnumValueOptions_clear_debug_redact(google_protobuf_EnumValueOptions* msg) { const upb_MiniTableField field = {3, UPB_SIZE(8, 2), 3, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_EnumValueOptions_debug_redact(const google_protobuf_EnumValueOptions* msg) { bool default_val = false; bool ret; const upb_MiniTableField field = {3, UPB_SIZE(8, 2), 3, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_EnumValueOptions_has_debug_redact(const google_protobuf_EnumValueOptions* msg) { const upb_MiniTableField field = {3, UPB_SIZE(8, 2), 3, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_EnumValueOptions_clear_uninterpreted_option(google_protobuf_EnumValueOptions* msg) { const upb_MiniTableField field = {999, UPB_SIZE(12, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_EnumValueOptions_uninterpreted_option(const google_protobuf_EnumValueOptions* msg, size_t* size) { const upb_MiniTableField field = {999, UPB_SIZE(12, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_UninterpretedOption* const*)_upb_array_constptr(arr); @@ -9393,16 +9589,16 @@ UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_Enu } UPB_INLINE const upb_Array* _google_protobuf_EnumValueOptions_uninterpreted_option_upb_array(const google_protobuf_EnumValueOptions* msg, size_t* size) { const upb_MiniTableField field = {999, UPB_SIZE(12, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } -UPB_INLINE upb_Array* _google_protobuf_EnumValueOptions_uninterpreted_option_mutable_upb_array(const google_protobuf_EnumValueOptions* msg, size_t* size, upb_Arena* arena) { +UPB_INLINE upb_Array* _google_protobuf_EnumValueOptions_uninterpreted_option_mutable_upb_array(google_protobuf_EnumValueOptions* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = {999, UPB_SIZE(12, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - (upb_Message*)msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), + &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -9411,11 +9607,11 @@ UPB_INLINE upb_Array* _google_protobuf_EnumValueOptions_uninterpreted_option_mut UPB_INLINE void google_protobuf_EnumValueOptions_set_deprecated(google_protobuf_EnumValueOptions *msg, bool value) { const upb_MiniTableField field = {1, 1, 1, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_EnumValueOptions_set_features(google_protobuf_EnumValueOptions *msg, google_protobuf_FeatureSet* value) { const upb_MiniTableField field = {2, UPB_SIZE(4, 8), 2, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE struct google_protobuf_FeatureSet* google_protobuf_EnumValueOptions_mutable_features(google_protobuf_EnumValueOptions* msg, upb_Arena* arena) { struct google_protobuf_FeatureSet* sub = (struct google_protobuf_FeatureSet*)google_protobuf_EnumValueOptions_features(msg); @@ -9427,11 +9623,11 @@ UPB_INLINE struct google_protobuf_FeatureSet* google_protobuf_EnumValueOptions_m } UPB_INLINE void google_protobuf_EnumValueOptions_set_debug_redact(google_protobuf_EnumValueOptions *msg, bool value) { const upb_MiniTableField field = {3, UPB_SIZE(8, 2), 3, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_EnumValueOptions_mutable_uninterpreted_option(google_protobuf_EnumValueOptions* msg, size_t* size) { upb_MiniTableField field = {999, UPB_SIZE(12, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetMutableArray(msg, &field); + upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_UninterpretedOption**)_upb_array_ptr(arr); @@ -9442,11 +9638,13 @@ UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_EnumValueOption } UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_EnumValueOptions_resize_uninterpreted_option(google_protobuf_EnumValueOptions* msg, size_t size, upb_Arena* arena) { upb_MiniTableField field = {999, UPB_SIZE(12, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return (google_protobuf_UninterpretedOption**)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); + return (google_protobuf_UninterpretedOption**)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg), + &field, size, arena); } UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_EnumValueOptions_add_uninterpreted_option(google_protobuf_EnumValueOptions* msg, upb_Arena* arena) { upb_MiniTableField field = {999, UPB_SIZE(12, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray( + UPB_UPCAST(msg), &field, arena); if (!arr || !_upb_Array_ResizeUninitialized( arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; @@ -9466,7 +9664,8 @@ UPB_INLINE google_protobuf_ServiceOptions* google_protobuf_ServiceOptions_new(up UPB_INLINE google_protobuf_ServiceOptions* google_protobuf_ServiceOptions_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_ServiceOptions* ret = google_protobuf_ServiceOptions_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__ServiceOptions_msg_init, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__ServiceOptions_msg_init, NULL, 0, arena) != + kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -9476,60 +9675,62 @@ UPB_INLINE google_protobuf_ServiceOptions* google_protobuf_ServiceOptions_parse_ int options, upb_Arena* arena) { google_protobuf_ServiceOptions* ret = google_protobuf_ServiceOptions_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__ServiceOptions_msg_init, extreg, options, arena) != - kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__ServiceOptions_msg_init, extreg, options, + arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_ServiceOptions_serialize(const google_protobuf_ServiceOptions* msg, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__ServiceOptions_msg_init, 0, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__ServiceOptions_msg_init, 0, arena, &ptr, len); return ptr; } UPB_INLINE char* google_protobuf_ServiceOptions_serialize_ex(const google_protobuf_ServiceOptions* msg, int options, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__ServiceOptions_msg_init, options, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__ServiceOptions_msg_init, options, arena, &ptr, len); return ptr; } UPB_INLINE void google_protobuf_ServiceOptions_clear_deprecated(google_protobuf_ServiceOptions* msg) { const upb_MiniTableField field = {33, 1, 1, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_ServiceOptions_deprecated(const google_protobuf_ServiceOptions* msg) { bool default_val = false; bool ret; const upb_MiniTableField field = {33, 1, 1, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_ServiceOptions_has_deprecated(const google_protobuf_ServiceOptions* msg) { const upb_MiniTableField field = {33, 1, 1, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_ServiceOptions_clear_features(google_protobuf_ServiceOptions* msg) { const upb_MiniTableField field = {34, UPB_SIZE(4, 8), 2, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_FeatureSet* google_protobuf_ServiceOptions_features(const google_protobuf_ServiceOptions* msg) { const google_protobuf_FeatureSet* default_val = NULL; const google_protobuf_FeatureSet* ret; const upb_MiniTableField field = {34, UPB_SIZE(4, 8), 2, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_ServiceOptions_has_features(const google_protobuf_ServiceOptions* msg) { const upb_MiniTableField field = {34, UPB_SIZE(4, 8), 2, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_ServiceOptions_clear_uninterpreted_option(google_protobuf_ServiceOptions* msg) { const upb_MiniTableField field = {999, UPB_SIZE(8, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_ServiceOptions_uninterpreted_option(const google_protobuf_ServiceOptions* msg, size_t* size) { const upb_MiniTableField field = {999, UPB_SIZE(8, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_UninterpretedOption* const*)_upb_array_constptr(arr); @@ -9540,16 +9741,16 @@ UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_Ser } UPB_INLINE const upb_Array* _google_protobuf_ServiceOptions_uninterpreted_option_upb_array(const google_protobuf_ServiceOptions* msg, size_t* size) { const upb_MiniTableField field = {999, UPB_SIZE(8, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } -UPB_INLINE upb_Array* _google_protobuf_ServiceOptions_uninterpreted_option_mutable_upb_array(const google_protobuf_ServiceOptions* msg, size_t* size, upb_Arena* arena) { +UPB_INLINE upb_Array* _google_protobuf_ServiceOptions_uninterpreted_option_mutable_upb_array(google_protobuf_ServiceOptions* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = {999, UPB_SIZE(8, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - (upb_Message*)msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), + &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -9558,11 +9759,11 @@ UPB_INLINE upb_Array* _google_protobuf_ServiceOptions_uninterpreted_option_mutab UPB_INLINE void google_protobuf_ServiceOptions_set_deprecated(google_protobuf_ServiceOptions *msg, bool value) { const upb_MiniTableField field = {33, 1, 1, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_ServiceOptions_set_features(google_protobuf_ServiceOptions *msg, google_protobuf_FeatureSet* value) { const upb_MiniTableField field = {34, UPB_SIZE(4, 8), 2, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE struct google_protobuf_FeatureSet* google_protobuf_ServiceOptions_mutable_features(google_protobuf_ServiceOptions* msg, upb_Arena* arena) { struct google_protobuf_FeatureSet* sub = (struct google_protobuf_FeatureSet*)google_protobuf_ServiceOptions_features(msg); @@ -9574,7 +9775,7 @@ UPB_INLINE struct google_protobuf_FeatureSet* google_protobuf_ServiceOptions_mut } UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_ServiceOptions_mutable_uninterpreted_option(google_protobuf_ServiceOptions* msg, size_t* size) { upb_MiniTableField field = {999, UPB_SIZE(8, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetMutableArray(msg, &field); + upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_UninterpretedOption**)_upb_array_ptr(arr); @@ -9585,11 +9786,13 @@ UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_ServiceOptions_ } UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_ServiceOptions_resize_uninterpreted_option(google_protobuf_ServiceOptions* msg, size_t size, upb_Arena* arena) { upb_MiniTableField field = {999, UPB_SIZE(8, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return (google_protobuf_UninterpretedOption**)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); + return (google_protobuf_UninterpretedOption**)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg), + &field, size, arena); } UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_ServiceOptions_add_uninterpreted_option(google_protobuf_ServiceOptions* msg, upb_Arena* arena) { upb_MiniTableField field = {999, UPB_SIZE(8, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray( + UPB_UPCAST(msg), &field, arena); if (!arr || !_upb_Array_ResizeUninitialized( arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; @@ -9609,7 +9812,8 @@ UPB_INLINE google_protobuf_MethodOptions* google_protobuf_MethodOptions_new(upb_ UPB_INLINE google_protobuf_MethodOptions* google_protobuf_MethodOptions_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_MethodOptions* ret = google_protobuf_MethodOptions_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__MethodOptions_msg_init, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__MethodOptions_msg_init, NULL, 0, arena) != + kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -9619,75 +9823,78 @@ UPB_INLINE google_protobuf_MethodOptions* google_protobuf_MethodOptions_parse_ex int options, upb_Arena* arena) { google_protobuf_MethodOptions* ret = google_protobuf_MethodOptions_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__MethodOptions_msg_init, extreg, options, arena) != - kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__MethodOptions_msg_init, extreg, options, + arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_MethodOptions_serialize(const google_protobuf_MethodOptions* msg, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__MethodOptions_msg_init, 0, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__MethodOptions_msg_init, 0, arena, &ptr, len); return ptr; } UPB_INLINE char* google_protobuf_MethodOptions_serialize_ex(const google_protobuf_MethodOptions* msg, int options, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__MethodOptions_msg_init, options, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__MethodOptions_msg_init, options, arena, &ptr, len); return ptr; } UPB_INLINE void google_protobuf_MethodOptions_clear_deprecated(google_protobuf_MethodOptions* msg) { const upb_MiniTableField field = {33, 1, 1, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_MethodOptions_deprecated(const google_protobuf_MethodOptions* msg) { bool default_val = false; bool ret; const upb_MiniTableField field = {33, 1, 1, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_MethodOptions_has_deprecated(const google_protobuf_MethodOptions* msg) { const upb_MiniTableField field = {33, 1, 1, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_MethodOptions_clear_idempotency_level(google_protobuf_MethodOptions* msg) { const upb_MiniTableField field = {34, 4, 2, 2, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_MethodOptions_idempotency_level(const google_protobuf_MethodOptions* msg) { int32_t default_val = 0; int32_t ret; const upb_MiniTableField field = {34, 4, 2, 2, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_MethodOptions_has_idempotency_level(const google_protobuf_MethodOptions* msg) { const upb_MiniTableField field = {34, 4, 2, 2, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_MethodOptions_clear_features(google_protobuf_MethodOptions* msg) { const upb_MiniTableField field = {35, 8, 3, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_FeatureSet* google_protobuf_MethodOptions_features(const google_protobuf_MethodOptions* msg) { const google_protobuf_FeatureSet* default_val = NULL; const google_protobuf_FeatureSet* ret; const upb_MiniTableField field = {35, 8, 3, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_MethodOptions_has_features(const google_protobuf_MethodOptions* msg) { const upb_MiniTableField field = {35, 8, 3, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_MethodOptions_clear_uninterpreted_option(google_protobuf_MethodOptions* msg) { const upb_MiniTableField field = {999, UPB_SIZE(12, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_MethodOptions_uninterpreted_option(const google_protobuf_MethodOptions* msg, size_t* size) { const upb_MiniTableField field = {999, UPB_SIZE(12, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_UninterpretedOption* const*)_upb_array_constptr(arr); @@ -9698,16 +9905,16 @@ UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_Met } UPB_INLINE const upb_Array* _google_protobuf_MethodOptions_uninterpreted_option_upb_array(const google_protobuf_MethodOptions* msg, size_t* size) { const upb_MiniTableField field = {999, UPB_SIZE(12, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } -UPB_INLINE upb_Array* _google_protobuf_MethodOptions_uninterpreted_option_mutable_upb_array(const google_protobuf_MethodOptions* msg, size_t* size, upb_Arena* arena) { +UPB_INLINE upb_Array* _google_protobuf_MethodOptions_uninterpreted_option_mutable_upb_array(google_protobuf_MethodOptions* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = {999, UPB_SIZE(12, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - (upb_Message*)msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), + &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -9716,15 +9923,15 @@ UPB_INLINE upb_Array* _google_protobuf_MethodOptions_uninterpreted_option_mutabl UPB_INLINE void google_protobuf_MethodOptions_set_deprecated(google_protobuf_MethodOptions *msg, bool value) { const upb_MiniTableField field = {33, 1, 1, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_MethodOptions_set_idempotency_level(google_protobuf_MethodOptions *msg, int32_t value) { const upb_MiniTableField field = {34, 4, 2, 2, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_MethodOptions_set_features(google_protobuf_MethodOptions *msg, google_protobuf_FeatureSet* value) { const upb_MiniTableField field = {35, 8, 3, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE struct google_protobuf_FeatureSet* google_protobuf_MethodOptions_mutable_features(google_protobuf_MethodOptions* msg, upb_Arena* arena) { struct google_protobuf_FeatureSet* sub = (struct google_protobuf_FeatureSet*)google_protobuf_MethodOptions_features(msg); @@ -9736,7 +9943,7 @@ UPB_INLINE struct google_protobuf_FeatureSet* google_protobuf_MethodOptions_muta } UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_MethodOptions_mutable_uninterpreted_option(google_protobuf_MethodOptions* msg, size_t* size) { upb_MiniTableField field = {999, UPB_SIZE(12, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetMutableArray(msg, &field); + upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_UninterpretedOption**)_upb_array_ptr(arr); @@ -9747,11 +9954,13 @@ UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_MethodOptions_m } UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_MethodOptions_resize_uninterpreted_option(google_protobuf_MethodOptions* msg, size_t size, upb_Arena* arena) { upb_MiniTableField field = {999, UPB_SIZE(12, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return (google_protobuf_UninterpretedOption**)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); + return (google_protobuf_UninterpretedOption**)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg), + &field, size, arena); } UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_MethodOptions_add_uninterpreted_option(google_protobuf_MethodOptions* msg, upb_Arena* arena) { upb_MiniTableField field = {999, UPB_SIZE(12, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray( + UPB_UPCAST(msg), &field, arena); if (!arr || !_upb_Array_ResizeUninitialized( arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; @@ -9771,7 +9980,8 @@ UPB_INLINE google_protobuf_UninterpretedOption* google_protobuf_UninterpretedOpt UPB_INLINE google_protobuf_UninterpretedOption* google_protobuf_UninterpretedOption_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_UninterpretedOption* ret = google_protobuf_UninterpretedOption_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__UninterpretedOption_msg_init, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__UninterpretedOption_msg_init, NULL, 0, arena) != + kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -9781,30 +9991,30 @@ UPB_INLINE google_protobuf_UninterpretedOption* google_protobuf_UninterpretedOpt int options, upb_Arena* arena) { google_protobuf_UninterpretedOption* ret = google_protobuf_UninterpretedOption_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__UninterpretedOption_msg_init, extreg, options, arena) != - kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__UninterpretedOption_msg_init, extreg, options, + arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_UninterpretedOption_serialize(const google_protobuf_UninterpretedOption* msg, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__UninterpretedOption_msg_init, 0, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__UninterpretedOption_msg_init, 0, arena, &ptr, len); return ptr; } UPB_INLINE char* google_protobuf_UninterpretedOption_serialize_ex(const google_protobuf_UninterpretedOption* msg, int options, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__UninterpretedOption_msg_init, options, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__UninterpretedOption_msg_init, options, arena, &ptr, len); return ptr; } UPB_INLINE void google_protobuf_UninterpretedOption_clear_name(google_protobuf_UninterpretedOption* msg) { const upb_MiniTableField field = {2, UPB_SIZE(4, 8), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_UninterpretedOption_NamePart* const* google_protobuf_UninterpretedOption_name(const google_protobuf_UninterpretedOption* msg, size_t* size) { const upb_MiniTableField field = {2, UPB_SIZE(4, 8), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_UninterpretedOption_NamePart* const*)_upb_array_constptr(arr); @@ -9815,16 +10025,16 @@ UPB_INLINE const google_protobuf_UninterpretedOption_NamePart* const* google_pro } UPB_INLINE const upb_Array* _google_protobuf_UninterpretedOption_name_upb_array(const google_protobuf_UninterpretedOption* msg, size_t* size) { const upb_MiniTableField field = {2, UPB_SIZE(4, 8), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } -UPB_INLINE upb_Array* _google_protobuf_UninterpretedOption_name_mutable_upb_array(const google_protobuf_UninterpretedOption* msg, size_t* size, upb_Arena* arena) { +UPB_INLINE upb_Array* _google_protobuf_UninterpretedOption_name_mutable_upb_array(google_protobuf_UninterpretedOption* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = {2, UPB_SIZE(4, 8), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - (upb_Message*)msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), + &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -9832,98 +10042,104 @@ UPB_INLINE upb_Array* _google_protobuf_UninterpretedOption_name_mutable_upb_arra } UPB_INLINE void google_protobuf_UninterpretedOption_clear_identifier_value(google_protobuf_UninterpretedOption* msg) { const upb_MiniTableField field = {3, UPB_SIZE(8, 16), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_UninterpretedOption_identifier_value(const google_protobuf_UninterpretedOption* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; const upb_MiniTableField field = {3, UPB_SIZE(8, 16), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_UninterpretedOption_has_identifier_value(const google_protobuf_UninterpretedOption* msg) { const upb_MiniTableField field = {3, UPB_SIZE(8, 16), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_UninterpretedOption_clear_positive_int_value(google_protobuf_UninterpretedOption* msg) { const upb_MiniTableField field = {4, UPB_SIZE(16, 32), 2, kUpb_NoSub, 4, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_8Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE uint64_t google_protobuf_UninterpretedOption_positive_int_value(const google_protobuf_UninterpretedOption* msg) { uint64_t default_val = (uint64_t)0ull; uint64_t ret; const upb_MiniTableField field = {4, UPB_SIZE(16, 32), 2, kUpb_NoSub, 4, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_8Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_UninterpretedOption_has_positive_int_value(const google_protobuf_UninterpretedOption* msg) { const upb_MiniTableField field = {4, UPB_SIZE(16, 32), 2, kUpb_NoSub, 4, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_8Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_UninterpretedOption_clear_negative_int_value(google_protobuf_UninterpretedOption* msg) { const upb_MiniTableField field = {5, UPB_SIZE(24, 40), 3, kUpb_NoSub, 3, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_8Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE int64_t google_protobuf_UninterpretedOption_negative_int_value(const google_protobuf_UninterpretedOption* msg) { int64_t default_val = (int64_t)0ll; int64_t ret; const upb_MiniTableField field = {5, UPB_SIZE(24, 40), 3, kUpb_NoSub, 3, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_8Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_UninterpretedOption_has_negative_int_value(const google_protobuf_UninterpretedOption* msg) { const upb_MiniTableField field = {5, UPB_SIZE(24, 40), 3, kUpb_NoSub, 3, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_8Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_UninterpretedOption_clear_double_value(google_protobuf_UninterpretedOption* msg) { const upb_MiniTableField field = {6, UPB_SIZE(32, 48), 4, kUpb_NoSub, 1, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_8Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE double google_protobuf_UninterpretedOption_double_value(const google_protobuf_UninterpretedOption* msg) { double default_val = 0; double ret; const upb_MiniTableField field = {6, UPB_SIZE(32, 48), 4, kUpb_NoSub, 1, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_8Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_UninterpretedOption_has_double_value(const google_protobuf_UninterpretedOption* msg) { const upb_MiniTableField field = {6, UPB_SIZE(32, 48), 4, kUpb_NoSub, 1, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_8Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_UninterpretedOption_clear_string_value(google_protobuf_UninterpretedOption* msg) { const upb_MiniTableField field = {7, UPB_SIZE(40, 56), 5, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_UninterpretedOption_string_value(const google_protobuf_UninterpretedOption* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; const upb_MiniTableField field = {7, UPB_SIZE(40, 56), 5, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_UninterpretedOption_has_string_value(const google_protobuf_UninterpretedOption* msg) { const upb_MiniTableField field = {7, UPB_SIZE(40, 56), 5, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_UninterpretedOption_clear_aggregate_value(google_protobuf_UninterpretedOption* msg) { const upb_MiniTableField field = {8, UPB_SIZE(48, 72), 6, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_UninterpretedOption_aggregate_value(const google_protobuf_UninterpretedOption* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; const upb_MiniTableField field = {8, UPB_SIZE(48, 72), 6, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_UninterpretedOption_has_aggregate_value(const google_protobuf_UninterpretedOption* msg) { const upb_MiniTableField field = {8, UPB_SIZE(48, 72), 6, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE google_protobuf_UninterpretedOption_NamePart** google_protobuf_UninterpretedOption_mutable_name(google_protobuf_UninterpretedOption* msg, size_t* size) { upb_MiniTableField field = {2, UPB_SIZE(4, 8), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetMutableArray(msg, &field); + upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_UninterpretedOption_NamePart**)_upb_array_ptr(arr); @@ -9934,11 +10150,13 @@ UPB_INLINE google_protobuf_UninterpretedOption_NamePart** google_protobuf_Uninte } UPB_INLINE google_protobuf_UninterpretedOption_NamePart** google_protobuf_UninterpretedOption_resize_name(google_protobuf_UninterpretedOption* msg, size_t size, upb_Arena* arena) { upb_MiniTableField field = {2, UPB_SIZE(4, 8), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return (google_protobuf_UninterpretedOption_NamePart**)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); + return (google_protobuf_UninterpretedOption_NamePart**)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg), + &field, size, arena); } UPB_INLINE struct google_protobuf_UninterpretedOption_NamePart* google_protobuf_UninterpretedOption_add_name(google_protobuf_UninterpretedOption* msg, upb_Arena* arena) { upb_MiniTableField field = {2, UPB_SIZE(4, 8), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray( + UPB_UPCAST(msg), &field, arena); if (!arr || !_upb_Array_ResizeUninitialized( arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; @@ -9951,27 +10169,27 @@ UPB_INLINE struct google_protobuf_UninterpretedOption_NamePart* google_protobuf_ } UPB_INLINE void google_protobuf_UninterpretedOption_set_identifier_value(google_protobuf_UninterpretedOption *msg, upb_StringView value) { const upb_MiniTableField field = {3, UPB_SIZE(8, 16), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_UninterpretedOption_set_positive_int_value(google_protobuf_UninterpretedOption *msg, uint64_t value) { const upb_MiniTableField field = {4, UPB_SIZE(16, 32), 2, kUpb_NoSub, 4, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_8Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_UninterpretedOption_set_negative_int_value(google_protobuf_UninterpretedOption *msg, int64_t value) { const upb_MiniTableField field = {5, UPB_SIZE(24, 40), 3, kUpb_NoSub, 3, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_8Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_UninterpretedOption_set_double_value(google_protobuf_UninterpretedOption *msg, double value) { const upb_MiniTableField field = {6, UPB_SIZE(32, 48), 4, kUpb_NoSub, 1, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_8Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_UninterpretedOption_set_string_value(google_protobuf_UninterpretedOption *msg, upb_StringView value) { const upb_MiniTableField field = {7, UPB_SIZE(40, 56), 5, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_UninterpretedOption_set_aggregate_value(google_protobuf_UninterpretedOption *msg, upb_StringView value) { const upb_MiniTableField field = {8, UPB_SIZE(48, 72), 6, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } /* google.protobuf.UninterpretedOption.NamePart */ @@ -9982,7 +10200,8 @@ UPB_INLINE google_protobuf_UninterpretedOption_NamePart* google_protobuf_Uninter UPB_INLINE google_protobuf_UninterpretedOption_NamePart* google_protobuf_UninterpretedOption_NamePart_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_UninterpretedOption_NamePart* ret = google_protobuf_UninterpretedOption_NamePart_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__UninterpretedOption__NamePart_msg_init, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__UninterpretedOption__NamePart_msg_init, NULL, 0, arena) != + kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -9992,61 +10211,63 @@ UPB_INLINE google_protobuf_UninterpretedOption_NamePart* google_protobuf_Uninter int options, upb_Arena* arena) { google_protobuf_UninterpretedOption_NamePart* ret = google_protobuf_UninterpretedOption_NamePart_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__UninterpretedOption__NamePart_msg_init, extreg, options, arena) != - kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__UninterpretedOption__NamePart_msg_init, extreg, options, + arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_UninterpretedOption_NamePart_serialize(const google_protobuf_UninterpretedOption_NamePart* msg, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__UninterpretedOption__NamePart_msg_init, 0, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__UninterpretedOption__NamePart_msg_init, 0, arena, &ptr, len); return ptr; } UPB_INLINE char* google_protobuf_UninterpretedOption_NamePart_serialize_ex(const google_protobuf_UninterpretedOption_NamePart* msg, int options, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__UninterpretedOption__NamePart_msg_init, options, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__UninterpretedOption__NamePart_msg_init, options, arena, &ptr, len); return ptr; } UPB_INLINE void google_protobuf_UninterpretedOption_NamePart_clear_name_part(google_protobuf_UninterpretedOption_NamePart* msg) { const upb_MiniTableField field = {1, UPB_SIZE(4, 8), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_UninterpretedOption_NamePart_name_part(const google_protobuf_UninterpretedOption_NamePart* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; const upb_MiniTableField field = {1, UPB_SIZE(4, 8), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_UninterpretedOption_NamePart_has_name_part(const google_protobuf_UninterpretedOption_NamePart* msg) { const upb_MiniTableField field = {1, UPB_SIZE(4, 8), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_UninterpretedOption_NamePart_clear_is_extension(google_protobuf_UninterpretedOption_NamePart* msg) { const upb_MiniTableField field = {2, 1, 2, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_UninterpretedOption_NamePart_is_extension(const google_protobuf_UninterpretedOption_NamePart* msg) { bool default_val = false; bool ret; const upb_MiniTableField field = {2, 1, 2, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_UninterpretedOption_NamePart_has_is_extension(const google_protobuf_UninterpretedOption_NamePart* msg) { const upb_MiniTableField field = {2, 1, 2, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_UninterpretedOption_NamePart_set_name_part(google_protobuf_UninterpretedOption_NamePart *msg, upb_StringView value) { const upb_MiniTableField field = {1, UPB_SIZE(4, 8), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_UninterpretedOption_NamePart_set_is_extension(google_protobuf_UninterpretedOption_NamePart *msg, bool value) { const upb_MiniTableField field = {2, 1, 2, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } /* google.protobuf.FeatureSet */ @@ -10057,7 +10278,8 @@ UPB_INLINE google_protobuf_FeatureSet* google_protobuf_FeatureSet_new(upb_Arena* UPB_INLINE google_protobuf_FeatureSet* google_protobuf_FeatureSet_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_FeatureSet* ret = google_protobuf_FeatureSet_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__FeatureSet_msg_init, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__FeatureSet_msg_init, NULL, 0, arena) != + kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -10067,137 +10289,143 @@ UPB_INLINE google_protobuf_FeatureSet* google_protobuf_FeatureSet_parse_ex(const int options, upb_Arena* arena) { google_protobuf_FeatureSet* ret = google_protobuf_FeatureSet_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__FeatureSet_msg_init, extreg, options, arena) != - kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__FeatureSet_msg_init, extreg, options, + arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_FeatureSet_serialize(const google_protobuf_FeatureSet* msg, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__FeatureSet_msg_init, 0, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__FeatureSet_msg_init, 0, arena, &ptr, len); return ptr; } UPB_INLINE char* google_protobuf_FeatureSet_serialize_ex(const google_protobuf_FeatureSet* msg, int options, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__FeatureSet_msg_init, options, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__FeatureSet_msg_init, options, arena, &ptr, len); return ptr; } UPB_INLINE void google_protobuf_FeatureSet_clear_field_presence(google_protobuf_FeatureSet* msg) { const upb_MiniTableField field = {1, 4, 1, 0, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_FeatureSet_field_presence(const google_protobuf_FeatureSet* msg) { int32_t default_val = 0; int32_t ret; const upb_MiniTableField field = {1, 4, 1, 0, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FeatureSet_has_field_presence(const google_protobuf_FeatureSet* msg) { const upb_MiniTableField field = {1, 4, 1, 0, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FeatureSet_clear_enum_type(google_protobuf_FeatureSet* msg) { const upb_MiniTableField field = {2, 8, 2, 1, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_FeatureSet_enum_type(const google_protobuf_FeatureSet* msg) { int32_t default_val = 0; int32_t ret; const upb_MiniTableField field = {2, 8, 2, 1, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FeatureSet_has_enum_type(const google_protobuf_FeatureSet* msg) { const upb_MiniTableField field = {2, 8, 2, 1, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FeatureSet_clear_repeated_field_encoding(google_protobuf_FeatureSet* msg) { const upb_MiniTableField field = {3, 12, 3, 2, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_FeatureSet_repeated_field_encoding(const google_protobuf_FeatureSet* msg) { int32_t default_val = 0; int32_t ret; const upb_MiniTableField field = {3, 12, 3, 2, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FeatureSet_has_repeated_field_encoding(const google_protobuf_FeatureSet* msg) { const upb_MiniTableField field = {3, 12, 3, 2, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FeatureSet_clear_utf8_validation(google_protobuf_FeatureSet* msg) { const upb_MiniTableField field = {4, 16, 4, 3, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_FeatureSet_utf8_validation(const google_protobuf_FeatureSet* msg) { int32_t default_val = 0; int32_t ret; const upb_MiniTableField field = {4, 16, 4, 3, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FeatureSet_has_utf8_validation(const google_protobuf_FeatureSet* msg) { const upb_MiniTableField field = {4, 16, 4, 3, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FeatureSet_clear_message_encoding(google_protobuf_FeatureSet* msg) { const upb_MiniTableField field = {5, 20, 5, 4, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_FeatureSet_message_encoding(const google_protobuf_FeatureSet* msg) { int32_t default_val = 0; int32_t ret; const upb_MiniTableField field = {5, 20, 5, 4, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FeatureSet_has_message_encoding(const google_protobuf_FeatureSet* msg) { const upb_MiniTableField field = {5, 20, 5, 4, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FeatureSet_clear_json_format(google_protobuf_FeatureSet* msg) { const upb_MiniTableField field = {6, 24, 6, 5, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_FeatureSet_json_format(const google_protobuf_FeatureSet* msg) { int32_t default_val = 0; int32_t ret; const upb_MiniTableField field = {6, 24, 6, 5, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FeatureSet_has_json_format(const google_protobuf_FeatureSet* msg) { const upb_MiniTableField field = {6, 24, 6, 5, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FeatureSet_set_field_presence(google_protobuf_FeatureSet *msg, int32_t value) { const upb_MiniTableField field = {1, 4, 1, 0, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FeatureSet_set_enum_type(google_protobuf_FeatureSet *msg, int32_t value) { const upb_MiniTableField field = {2, 8, 2, 1, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FeatureSet_set_repeated_field_encoding(google_protobuf_FeatureSet *msg, int32_t value) { const upb_MiniTableField field = {3, 12, 3, 2, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FeatureSet_set_utf8_validation(google_protobuf_FeatureSet *msg, int32_t value) { const upb_MiniTableField field = {4, 16, 4, 3, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FeatureSet_set_message_encoding(google_protobuf_FeatureSet *msg, int32_t value) { const upb_MiniTableField field = {5, 20, 5, 4, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FeatureSet_set_json_format(google_protobuf_FeatureSet *msg, int32_t value) { const upb_MiniTableField field = {6, 24, 6, 5, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } /* google.protobuf.FeatureSetDefaults */ @@ -10208,7 +10436,8 @@ UPB_INLINE google_protobuf_FeatureSetDefaults* google_protobuf_FeatureSetDefault UPB_INLINE google_protobuf_FeatureSetDefaults* google_protobuf_FeatureSetDefaults_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_FeatureSetDefaults* ret = google_protobuf_FeatureSetDefaults_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__FeatureSetDefaults_msg_init, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__FeatureSetDefaults_msg_init, NULL, 0, arena) != + kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -10218,30 +10447,30 @@ UPB_INLINE google_protobuf_FeatureSetDefaults* google_protobuf_FeatureSetDefault int options, upb_Arena* arena) { google_protobuf_FeatureSetDefaults* ret = google_protobuf_FeatureSetDefaults_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__FeatureSetDefaults_msg_init, extreg, options, arena) != - kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__FeatureSetDefaults_msg_init, extreg, options, + arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_FeatureSetDefaults_serialize(const google_protobuf_FeatureSetDefaults* msg, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__FeatureSetDefaults_msg_init, 0, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__FeatureSetDefaults_msg_init, 0, arena, &ptr, len); return ptr; } UPB_INLINE char* google_protobuf_FeatureSetDefaults_serialize_ex(const google_protobuf_FeatureSetDefaults* msg, int options, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__FeatureSetDefaults_msg_init, options, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__FeatureSetDefaults_msg_init, options, arena, &ptr, len); return ptr; } UPB_INLINE void google_protobuf_FeatureSetDefaults_clear_defaults(google_protobuf_FeatureSetDefaults* msg) { const upb_MiniTableField field = {1, UPB_SIZE(4, 16), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* const* google_protobuf_FeatureSetDefaults_defaults(const google_protobuf_FeatureSetDefaults* msg, size_t* size) { const upb_MiniTableField field = {1, UPB_SIZE(4, 16), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* const*)_upb_array_constptr(arr); @@ -10252,16 +10481,16 @@ UPB_INLINE const google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* co } UPB_INLINE const upb_Array* _google_protobuf_FeatureSetDefaults_defaults_upb_array(const google_protobuf_FeatureSetDefaults* msg, size_t* size) { const upb_MiniTableField field = {1, UPB_SIZE(4, 16), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } -UPB_INLINE upb_Array* _google_protobuf_FeatureSetDefaults_defaults_mutable_upb_array(const google_protobuf_FeatureSetDefaults* msg, size_t* size, upb_Arena* arena) { +UPB_INLINE upb_Array* _google_protobuf_FeatureSetDefaults_defaults_mutable_upb_array(google_protobuf_FeatureSetDefaults* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = {1, UPB_SIZE(4, 16), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - (upb_Message*)msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), + &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -10269,38 +10498,40 @@ UPB_INLINE upb_Array* _google_protobuf_FeatureSetDefaults_defaults_mutable_upb_a } UPB_INLINE void google_protobuf_FeatureSetDefaults_clear_minimum_edition(google_protobuf_FeatureSetDefaults* msg) { const upb_MiniTableField field = {4, UPB_SIZE(8, 4), 1, 1, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_FeatureSetDefaults_minimum_edition(const google_protobuf_FeatureSetDefaults* msg) { int32_t default_val = 0; int32_t ret; const upb_MiniTableField field = {4, UPB_SIZE(8, 4), 1, 1, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FeatureSetDefaults_has_minimum_edition(const google_protobuf_FeatureSetDefaults* msg) { const upb_MiniTableField field = {4, UPB_SIZE(8, 4), 1, 1, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FeatureSetDefaults_clear_maximum_edition(google_protobuf_FeatureSetDefaults* msg) { const upb_MiniTableField field = {5, UPB_SIZE(12, 8), 2, 2, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_FeatureSetDefaults_maximum_edition(const google_protobuf_FeatureSetDefaults* msg) { int32_t default_val = 0; int32_t ret; const upb_MiniTableField field = {5, UPB_SIZE(12, 8), 2, 2, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FeatureSetDefaults_has_maximum_edition(const google_protobuf_FeatureSetDefaults* msg) { const upb_MiniTableField field = {5, UPB_SIZE(12, 8), 2, 2, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault** google_protobuf_FeatureSetDefaults_mutable_defaults(google_protobuf_FeatureSetDefaults* msg, size_t* size) { upb_MiniTableField field = {1, UPB_SIZE(4, 16), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetMutableArray(msg, &field); + upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault**)_upb_array_ptr(arr); @@ -10311,11 +10542,13 @@ UPB_INLINE google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault** google_ } UPB_INLINE google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault** google_protobuf_FeatureSetDefaults_resize_defaults(google_protobuf_FeatureSetDefaults* msg, size_t size, upb_Arena* arena) { upb_MiniTableField field = {1, UPB_SIZE(4, 16), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return (google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault**)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); + return (google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault**)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg), + &field, size, arena); } UPB_INLINE struct google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* google_protobuf_FeatureSetDefaults_add_defaults(google_protobuf_FeatureSetDefaults* msg, upb_Arena* arena) { upb_MiniTableField field = {1, UPB_SIZE(4, 16), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray( + UPB_UPCAST(msg), &field, arena); if (!arr || !_upb_Array_ResizeUninitialized( arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; @@ -10328,11 +10561,11 @@ UPB_INLINE struct google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* g } UPB_INLINE void google_protobuf_FeatureSetDefaults_set_minimum_edition(google_protobuf_FeatureSetDefaults *msg, int32_t value) { const upb_MiniTableField field = {4, UPB_SIZE(8, 4), 1, 1, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FeatureSetDefaults_set_maximum_edition(google_protobuf_FeatureSetDefaults *msg, int32_t value) { const upb_MiniTableField field = {5, UPB_SIZE(12, 8), 2, 2, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } /* google.protobuf.FeatureSetDefaults.FeatureSetEditionDefault */ @@ -10343,7 +10576,8 @@ UPB_INLINE google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* google_p UPB_INLINE google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* ret = google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__FeatureSetDefaults__FeatureSetEditionDefault_msg_init, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__FeatureSetDefaults__FeatureSetEditionDefault_msg_init, NULL, 0, arena) != + kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -10353,57 +10587,59 @@ UPB_INLINE google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* google_p int options, upb_Arena* arena) { google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* ret = google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__FeatureSetDefaults__FeatureSetEditionDefault_msg_init, extreg, options, arena) != - kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__FeatureSetDefaults__FeatureSetEditionDefault_msg_init, extreg, options, + arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_serialize(const google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* msg, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__FeatureSetDefaults__FeatureSetEditionDefault_msg_init, 0, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__FeatureSetDefaults__FeatureSetEditionDefault_msg_init, 0, arena, &ptr, len); return ptr; } UPB_INLINE char* google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_serialize_ex(const google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* msg, int options, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__FeatureSetDefaults__FeatureSetEditionDefault_msg_init, options, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__FeatureSetDefaults__FeatureSetEditionDefault_msg_init, options, arena, &ptr, len); return ptr; } UPB_INLINE void google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_clear_features(google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* msg) { const upb_MiniTableField field = {2, UPB_SIZE(4, 8), 1, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_FeatureSet* google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_features(const google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* msg) { const google_protobuf_FeatureSet* default_val = NULL; const google_protobuf_FeatureSet* ret; const upb_MiniTableField field = {2, UPB_SIZE(4, 8), 1, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_has_features(const google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* msg) { const upb_MiniTableField field = {2, UPB_SIZE(4, 8), 1, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_clear_edition(google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* msg) { const upb_MiniTableField field = {3, UPB_SIZE(8, 4), 2, 1, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_edition(const google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* msg) { int32_t default_val = 0; int32_t ret; const upb_MiniTableField field = {3, UPB_SIZE(8, 4), 2, 1, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_has_edition(const google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* msg) { const upb_MiniTableField field = {3, UPB_SIZE(8, 4), 2, 1, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_set_features(google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault *msg, google_protobuf_FeatureSet* value) { const upb_MiniTableField field = {2, UPB_SIZE(4, 8), 1, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE struct google_protobuf_FeatureSet* google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_mutable_features(google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* msg, upb_Arena* arena) { struct google_protobuf_FeatureSet* sub = (struct google_protobuf_FeatureSet*)google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_features(msg); @@ -10415,7 +10651,7 @@ UPB_INLINE struct google_protobuf_FeatureSet* google_protobuf_FeatureSetDefaults } UPB_INLINE void google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_set_edition(google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault *msg, int32_t value) { const upb_MiniTableField field = {3, UPB_SIZE(8, 4), 2, 1, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } /* google.protobuf.SourceCodeInfo */ @@ -10426,7 +10662,8 @@ UPB_INLINE google_protobuf_SourceCodeInfo* google_protobuf_SourceCodeInfo_new(up UPB_INLINE google_protobuf_SourceCodeInfo* google_protobuf_SourceCodeInfo_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_SourceCodeInfo* ret = google_protobuf_SourceCodeInfo_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__SourceCodeInfo_msg_init, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__SourceCodeInfo_msg_init, NULL, 0, arena) != + kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -10436,30 +10673,30 @@ UPB_INLINE google_protobuf_SourceCodeInfo* google_protobuf_SourceCodeInfo_parse_ int options, upb_Arena* arena) { google_protobuf_SourceCodeInfo* ret = google_protobuf_SourceCodeInfo_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__SourceCodeInfo_msg_init, extreg, options, arena) != - kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__SourceCodeInfo_msg_init, extreg, options, + arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_SourceCodeInfo_serialize(const google_protobuf_SourceCodeInfo* msg, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__SourceCodeInfo_msg_init, 0, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__SourceCodeInfo_msg_init, 0, arena, &ptr, len); return ptr; } UPB_INLINE char* google_protobuf_SourceCodeInfo_serialize_ex(const google_protobuf_SourceCodeInfo* msg, int options, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__SourceCodeInfo_msg_init, options, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__SourceCodeInfo_msg_init, options, arena, &ptr, len); return ptr; } UPB_INLINE void google_protobuf_SourceCodeInfo_clear_location(google_protobuf_SourceCodeInfo* msg) { const upb_MiniTableField field = {1, 0, 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_SourceCodeInfo_Location* const* google_protobuf_SourceCodeInfo_location(const google_protobuf_SourceCodeInfo* msg, size_t* size) { const upb_MiniTableField field = {1, 0, 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_SourceCodeInfo_Location* const*)_upb_array_constptr(arr); @@ -10470,16 +10707,16 @@ UPB_INLINE const google_protobuf_SourceCodeInfo_Location* const* google_protobuf } UPB_INLINE const upb_Array* _google_protobuf_SourceCodeInfo_location_upb_array(const google_protobuf_SourceCodeInfo* msg, size_t* size) { const upb_MiniTableField field = {1, 0, 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } -UPB_INLINE upb_Array* _google_protobuf_SourceCodeInfo_location_mutable_upb_array(const google_protobuf_SourceCodeInfo* msg, size_t* size, upb_Arena* arena) { +UPB_INLINE upb_Array* _google_protobuf_SourceCodeInfo_location_mutable_upb_array(google_protobuf_SourceCodeInfo* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = {1, 0, 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - (upb_Message*)msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), + &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -10488,7 +10725,7 @@ UPB_INLINE upb_Array* _google_protobuf_SourceCodeInfo_location_mutable_upb_array UPB_INLINE google_protobuf_SourceCodeInfo_Location** google_protobuf_SourceCodeInfo_mutable_location(google_protobuf_SourceCodeInfo* msg, size_t* size) { upb_MiniTableField field = {1, 0, 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetMutableArray(msg, &field); + upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_SourceCodeInfo_Location**)_upb_array_ptr(arr); @@ -10499,11 +10736,13 @@ UPB_INLINE google_protobuf_SourceCodeInfo_Location** google_protobuf_SourceCodeI } UPB_INLINE google_protobuf_SourceCodeInfo_Location** google_protobuf_SourceCodeInfo_resize_location(google_protobuf_SourceCodeInfo* msg, size_t size, upb_Arena* arena) { upb_MiniTableField field = {1, 0, 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return (google_protobuf_SourceCodeInfo_Location**)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); + return (google_protobuf_SourceCodeInfo_Location**)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg), + &field, size, arena); } UPB_INLINE struct google_protobuf_SourceCodeInfo_Location* google_protobuf_SourceCodeInfo_add_location(google_protobuf_SourceCodeInfo* msg, upb_Arena* arena) { upb_MiniTableField field = {1, 0, 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray( + UPB_UPCAST(msg), &field, arena); if (!arr || !_upb_Array_ResizeUninitialized( arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; @@ -10523,7 +10762,8 @@ UPB_INLINE google_protobuf_SourceCodeInfo_Location* google_protobuf_SourceCodeIn UPB_INLINE google_protobuf_SourceCodeInfo_Location* google_protobuf_SourceCodeInfo_Location_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_SourceCodeInfo_Location* ret = google_protobuf_SourceCodeInfo_Location_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__SourceCodeInfo__Location_msg_init, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__SourceCodeInfo__Location_msg_init, NULL, 0, arena) != + kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -10533,30 +10773,30 @@ UPB_INLINE google_protobuf_SourceCodeInfo_Location* google_protobuf_SourceCodeIn int options, upb_Arena* arena) { google_protobuf_SourceCodeInfo_Location* ret = google_protobuf_SourceCodeInfo_Location_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__SourceCodeInfo__Location_msg_init, extreg, options, arena) != - kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__SourceCodeInfo__Location_msg_init, extreg, options, + arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_SourceCodeInfo_Location_serialize(const google_protobuf_SourceCodeInfo_Location* msg, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__SourceCodeInfo__Location_msg_init, 0, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__SourceCodeInfo__Location_msg_init, 0, arena, &ptr, len); return ptr; } UPB_INLINE char* google_protobuf_SourceCodeInfo_Location_serialize_ex(const google_protobuf_SourceCodeInfo_Location* msg, int options, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__SourceCodeInfo__Location_msg_init, options, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__SourceCodeInfo__Location_msg_init, options, arena, &ptr, len); return ptr; } UPB_INLINE void google_protobuf_SourceCodeInfo_Location_clear_path(google_protobuf_SourceCodeInfo_Location* msg) { const upb_MiniTableField field = {1, UPB_SIZE(4, 8), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsPacked | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t const* google_protobuf_SourceCodeInfo_Location_path(const google_protobuf_SourceCodeInfo_Location* msg, size_t* size) { const upb_MiniTableField field = {1, UPB_SIZE(4, 8), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsPacked | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (int32_t const*)_upb_array_constptr(arr); @@ -10567,16 +10807,16 @@ UPB_INLINE int32_t const* google_protobuf_SourceCodeInfo_Location_path(const goo } UPB_INLINE const upb_Array* _google_protobuf_SourceCodeInfo_Location_path_upb_array(const google_protobuf_SourceCodeInfo_Location* msg, size_t* size) { const upb_MiniTableField field = {1, UPB_SIZE(4, 8), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsPacked | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } -UPB_INLINE upb_Array* _google_protobuf_SourceCodeInfo_Location_path_mutable_upb_array(const google_protobuf_SourceCodeInfo_Location* msg, size_t* size, upb_Arena* arena) { +UPB_INLINE upb_Array* _google_protobuf_SourceCodeInfo_Location_path_mutable_upb_array(google_protobuf_SourceCodeInfo_Location* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = {1, UPB_SIZE(4, 8), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsPacked | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - (upb_Message*)msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), + &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -10584,11 +10824,11 @@ UPB_INLINE upb_Array* _google_protobuf_SourceCodeInfo_Location_path_mutable_upb_ } UPB_INLINE void google_protobuf_SourceCodeInfo_Location_clear_span(google_protobuf_SourceCodeInfo_Location* msg) { const upb_MiniTableField field = {2, UPB_SIZE(8, 16), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsPacked | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t const* google_protobuf_SourceCodeInfo_Location_span(const google_protobuf_SourceCodeInfo_Location* msg, size_t* size) { const upb_MiniTableField field = {2, UPB_SIZE(8, 16), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsPacked | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (int32_t const*)_upb_array_constptr(arr); @@ -10599,16 +10839,16 @@ UPB_INLINE int32_t const* google_protobuf_SourceCodeInfo_Location_span(const goo } UPB_INLINE const upb_Array* _google_protobuf_SourceCodeInfo_Location_span_upb_array(const google_protobuf_SourceCodeInfo_Location* msg, size_t* size) { const upb_MiniTableField field = {2, UPB_SIZE(8, 16), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsPacked | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } -UPB_INLINE upb_Array* _google_protobuf_SourceCodeInfo_Location_span_mutable_upb_array(const google_protobuf_SourceCodeInfo_Location* msg, size_t* size, upb_Arena* arena) { +UPB_INLINE upb_Array* _google_protobuf_SourceCodeInfo_Location_span_mutable_upb_array(google_protobuf_SourceCodeInfo_Location* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = {2, UPB_SIZE(8, 16), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsPacked | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - (upb_Message*)msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), + &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -10616,41 +10856,43 @@ UPB_INLINE upb_Array* _google_protobuf_SourceCodeInfo_Location_span_mutable_upb_ } UPB_INLINE void google_protobuf_SourceCodeInfo_Location_clear_leading_comments(google_protobuf_SourceCodeInfo_Location* msg) { const upb_MiniTableField field = {3, UPB_SIZE(16, 24), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_SourceCodeInfo_Location_leading_comments(const google_protobuf_SourceCodeInfo_Location* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; const upb_MiniTableField field = {3, UPB_SIZE(16, 24), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_SourceCodeInfo_Location_has_leading_comments(const google_protobuf_SourceCodeInfo_Location* msg) { const upb_MiniTableField field = {3, UPB_SIZE(16, 24), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_SourceCodeInfo_Location_clear_trailing_comments(google_protobuf_SourceCodeInfo_Location* msg) { const upb_MiniTableField field = {4, UPB_SIZE(24, 40), 2, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_SourceCodeInfo_Location_trailing_comments(const google_protobuf_SourceCodeInfo_Location* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; const upb_MiniTableField field = {4, UPB_SIZE(24, 40), 2, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_SourceCodeInfo_Location_has_trailing_comments(const google_protobuf_SourceCodeInfo_Location* msg) { const upb_MiniTableField field = {4, UPB_SIZE(24, 40), 2, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_SourceCodeInfo_Location_clear_leading_detached_comments(google_protobuf_SourceCodeInfo_Location* msg) { const upb_MiniTableField field = {6, UPB_SIZE(12, 56), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView const* google_protobuf_SourceCodeInfo_Location_leading_detached_comments(const google_protobuf_SourceCodeInfo_Location* msg, size_t* size) { const upb_MiniTableField field = {6, UPB_SIZE(12, 56), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (upb_StringView const*)_upb_array_constptr(arr); @@ -10661,16 +10903,16 @@ UPB_INLINE upb_StringView const* google_protobuf_SourceCodeInfo_Location_leading } UPB_INLINE const upb_Array* _google_protobuf_SourceCodeInfo_Location_leading_detached_comments_upb_array(const google_protobuf_SourceCodeInfo_Location* msg, size_t* size) { const upb_MiniTableField field = {6, UPB_SIZE(12, 56), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } -UPB_INLINE upb_Array* _google_protobuf_SourceCodeInfo_Location_leading_detached_comments_mutable_upb_array(const google_protobuf_SourceCodeInfo_Location* msg, size_t* size, upb_Arena* arena) { +UPB_INLINE upb_Array* _google_protobuf_SourceCodeInfo_Location_leading_detached_comments_mutable_upb_array(google_protobuf_SourceCodeInfo_Location* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = {6, UPB_SIZE(12, 56), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - (upb_Message*)msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), + &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -10679,7 +10921,7 @@ UPB_INLINE upb_Array* _google_protobuf_SourceCodeInfo_Location_leading_detached_ UPB_INLINE int32_t* google_protobuf_SourceCodeInfo_Location_mutable_path(google_protobuf_SourceCodeInfo_Location* msg, size_t* size) { upb_MiniTableField field = {1, UPB_SIZE(4, 8), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsPacked | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetMutableArray(msg, &field); + upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (int32_t*)_upb_array_ptr(arr); @@ -10690,11 +10932,13 @@ UPB_INLINE int32_t* google_protobuf_SourceCodeInfo_Location_mutable_path(google_ } UPB_INLINE int32_t* google_protobuf_SourceCodeInfo_Location_resize_path(google_protobuf_SourceCodeInfo_Location* msg, size_t size, upb_Arena* arena) { upb_MiniTableField field = {1, UPB_SIZE(4, 8), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsPacked | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return (int32_t*)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); + return (int32_t*)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg), + &field, size, arena); } UPB_INLINE bool google_protobuf_SourceCodeInfo_Location_add_path(google_protobuf_SourceCodeInfo_Location* msg, int32_t val, upb_Arena* arena) { upb_MiniTableField field = {1, UPB_SIZE(4, 8), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsPacked | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray( + UPB_UPCAST(msg), &field, arena); if (!arr || !_upb_Array_ResizeUninitialized( arr, arr->UPB_PRIVATE(size) + 1, arena)) { return false; @@ -10705,7 +10949,7 @@ UPB_INLINE bool google_protobuf_SourceCodeInfo_Location_add_path(google_protobuf } UPB_INLINE int32_t* google_protobuf_SourceCodeInfo_Location_mutable_span(google_protobuf_SourceCodeInfo_Location* msg, size_t* size) { upb_MiniTableField field = {2, UPB_SIZE(8, 16), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsPacked | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetMutableArray(msg, &field); + upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (int32_t*)_upb_array_ptr(arr); @@ -10716,11 +10960,13 @@ UPB_INLINE int32_t* google_protobuf_SourceCodeInfo_Location_mutable_span(google_ } UPB_INLINE int32_t* google_protobuf_SourceCodeInfo_Location_resize_span(google_protobuf_SourceCodeInfo_Location* msg, size_t size, upb_Arena* arena) { upb_MiniTableField field = {2, UPB_SIZE(8, 16), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsPacked | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return (int32_t*)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); + return (int32_t*)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg), + &field, size, arena); } UPB_INLINE bool google_protobuf_SourceCodeInfo_Location_add_span(google_protobuf_SourceCodeInfo_Location* msg, int32_t val, upb_Arena* arena) { upb_MiniTableField field = {2, UPB_SIZE(8, 16), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsPacked | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray( + UPB_UPCAST(msg), &field, arena); if (!arr || !_upb_Array_ResizeUninitialized( arr, arr->UPB_PRIVATE(size) + 1, arena)) { return false; @@ -10731,15 +10977,15 @@ UPB_INLINE bool google_protobuf_SourceCodeInfo_Location_add_span(google_protobuf } UPB_INLINE void google_protobuf_SourceCodeInfo_Location_set_leading_comments(google_protobuf_SourceCodeInfo_Location *msg, upb_StringView value) { const upb_MiniTableField field = {3, UPB_SIZE(16, 24), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_SourceCodeInfo_Location_set_trailing_comments(google_protobuf_SourceCodeInfo_Location *msg, upb_StringView value) { const upb_MiniTableField field = {4, UPB_SIZE(24, 40), 2, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE upb_StringView* google_protobuf_SourceCodeInfo_Location_mutable_leading_detached_comments(google_protobuf_SourceCodeInfo_Location* msg, size_t* size) { upb_MiniTableField field = {6, UPB_SIZE(12, 56), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetMutableArray(msg, &field); + upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (upb_StringView*)_upb_array_ptr(arr); @@ -10750,11 +10996,13 @@ UPB_INLINE upb_StringView* google_protobuf_SourceCodeInfo_Location_mutable_leadi } UPB_INLINE upb_StringView* google_protobuf_SourceCodeInfo_Location_resize_leading_detached_comments(google_protobuf_SourceCodeInfo_Location* msg, size_t size, upb_Arena* arena) { upb_MiniTableField field = {6, UPB_SIZE(12, 56), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return (upb_StringView*)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); + return (upb_StringView*)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg), + &field, size, arena); } UPB_INLINE bool google_protobuf_SourceCodeInfo_Location_add_leading_detached_comments(google_protobuf_SourceCodeInfo_Location* msg, upb_StringView val, upb_Arena* arena) { upb_MiniTableField field = {6, UPB_SIZE(12, 56), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray( + UPB_UPCAST(msg), &field, arena); if (!arr || !_upb_Array_ResizeUninitialized( arr, arr->UPB_PRIVATE(size) + 1, arena)) { return false; @@ -10772,7 +11020,8 @@ UPB_INLINE google_protobuf_GeneratedCodeInfo* google_protobuf_GeneratedCodeInfo_ UPB_INLINE google_protobuf_GeneratedCodeInfo* google_protobuf_GeneratedCodeInfo_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_GeneratedCodeInfo* ret = google_protobuf_GeneratedCodeInfo_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__GeneratedCodeInfo_msg_init, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__GeneratedCodeInfo_msg_init, NULL, 0, arena) != + kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -10782,30 +11031,30 @@ UPB_INLINE google_protobuf_GeneratedCodeInfo* google_protobuf_GeneratedCodeInfo_ int options, upb_Arena* arena) { google_protobuf_GeneratedCodeInfo* ret = google_protobuf_GeneratedCodeInfo_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__GeneratedCodeInfo_msg_init, extreg, options, arena) != - kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__GeneratedCodeInfo_msg_init, extreg, options, + arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_GeneratedCodeInfo_serialize(const google_protobuf_GeneratedCodeInfo* msg, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__GeneratedCodeInfo_msg_init, 0, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__GeneratedCodeInfo_msg_init, 0, arena, &ptr, len); return ptr; } UPB_INLINE char* google_protobuf_GeneratedCodeInfo_serialize_ex(const google_protobuf_GeneratedCodeInfo* msg, int options, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__GeneratedCodeInfo_msg_init, options, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__GeneratedCodeInfo_msg_init, options, arena, &ptr, len); return ptr; } UPB_INLINE void google_protobuf_GeneratedCodeInfo_clear_annotation(google_protobuf_GeneratedCodeInfo* msg) { const upb_MiniTableField field = {1, 0, 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_GeneratedCodeInfo_Annotation* const* google_protobuf_GeneratedCodeInfo_annotation(const google_protobuf_GeneratedCodeInfo* msg, size_t* size) { const upb_MiniTableField field = {1, 0, 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_GeneratedCodeInfo_Annotation* const*)_upb_array_constptr(arr); @@ -10816,16 +11065,16 @@ UPB_INLINE const google_protobuf_GeneratedCodeInfo_Annotation* const* google_pro } UPB_INLINE const upb_Array* _google_protobuf_GeneratedCodeInfo_annotation_upb_array(const google_protobuf_GeneratedCodeInfo* msg, size_t* size) { const upb_MiniTableField field = {1, 0, 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } -UPB_INLINE upb_Array* _google_protobuf_GeneratedCodeInfo_annotation_mutable_upb_array(const google_protobuf_GeneratedCodeInfo* msg, size_t* size, upb_Arena* arena) { +UPB_INLINE upb_Array* _google_protobuf_GeneratedCodeInfo_annotation_mutable_upb_array(google_protobuf_GeneratedCodeInfo* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = {1, 0, 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - (upb_Message*)msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), + &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -10834,7 +11083,7 @@ UPB_INLINE upb_Array* _google_protobuf_GeneratedCodeInfo_annotation_mutable_upb_ UPB_INLINE google_protobuf_GeneratedCodeInfo_Annotation** google_protobuf_GeneratedCodeInfo_mutable_annotation(google_protobuf_GeneratedCodeInfo* msg, size_t* size) { upb_MiniTableField field = {1, 0, 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetMutableArray(msg, &field); + upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_GeneratedCodeInfo_Annotation**)_upb_array_ptr(arr); @@ -10845,11 +11094,13 @@ UPB_INLINE google_protobuf_GeneratedCodeInfo_Annotation** google_protobuf_Genera } UPB_INLINE google_protobuf_GeneratedCodeInfo_Annotation** google_protobuf_GeneratedCodeInfo_resize_annotation(google_protobuf_GeneratedCodeInfo* msg, size_t size, upb_Arena* arena) { upb_MiniTableField field = {1, 0, 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return (google_protobuf_GeneratedCodeInfo_Annotation**)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); + return (google_protobuf_GeneratedCodeInfo_Annotation**)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg), + &field, size, arena); } UPB_INLINE struct google_protobuf_GeneratedCodeInfo_Annotation* google_protobuf_GeneratedCodeInfo_add_annotation(google_protobuf_GeneratedCodeInfo* msg, upb_Arena* arena) { upb_MiniTableField field = {1, 0, 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray( + UPB_UPCAST(msg), &field, arena); if (!arr || !_upb_Array_ResizeUninitialized( arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; @@ -10869,7 +11120,8 @@ UPB_INLINE google_protobuf_GeneratedCodeInfo_Annotation* google_protobuf_Generat UPB_INLINE google_protobuf_GeneratedCodeInfo_Annotation* google_protobuf_GeneratedCodeInfo_Annotation_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_GeneratedCodeInfo_Annotation* ret = google_protobuf_GeneratedCodeInfo_Annotation_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__GeneratedCodeInfo__Annotation_msg_init, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__GeneratedCodeInfo__Annotation_msg_init, NULL, 0, arena) != + kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -10879,30 +11131,30 @@ UPB_INLINE google_protobuf_GeneratedCodeInfo_Annotation* google_protobuf_Generat int options, upb_Arena* arena) { google_protobuf_GeneratedCodeInfo_Annotation* ret = google_protobuf_GeneratedCodeInfo_Annotation_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__GeneratedCodeInfo__Annotation_msg_init, extreg, options, arena) != - kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__GeneratedCodeInfo__Annotation_msg_init, extreg, options, + arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_GeneratedCodeInfo_Annotation_serialize(const google_protobuf_GeneratedCodeInfo_Annotation* msg, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__GeneratedCodeInfo__Annotation_msg_init, 0, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__GeneratedCodeInfo__Annotation_msg_init, 0, arena, &ptr, len); return ptr; } UPB_INLINE char* google_protobuf_GeneratedCodeInfo_Annotation_serialize_ex(const google_protobuf_GeneratedCodeInfo_Annotation* msg, int options, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__GeneratedCodeInfo__Annotation_msg_init, options, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__GeneratedCodeInfo__Annotation_msg_init, options, arena, &ptr, len); return ptr; } UPB_INLINE void google_protobuf_GeneratedCodeInfo_Annotation_clear_path(google_protobuf_GeneratedCodeInfo_Annotation* msg) { const upb_MiniTableField field = {1, UPB_SIZE(4, 16), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsPacked | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t const* google_protobuf_GeneratedCodeInfo_Annotation_path(const google_protobuf_GeneratedCodeInfo_Annotation* msg, size_t* size) { const upb_MiniTableField field = {1, UPB_SIZE(4, 16), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsPacked | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (int32_t const*)_upb_array_constptr(arr); @@ -10913,16 +11165,16 @@ UPB_INLINE int32_t const* google_protobuf_GeneratedCodeInfo_Annotation_path(cons } UPB_INLINE const upb_Array* _google_protobuf_GeneratedCodeInfo_Annotation_path_upb_array(const google_protobuf_GeneratedCodeInfo_Annotation* msg, size_t* size) { const upb_MiniTableField field = {1, UPB_SIZE(4, 16), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsPacked | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } -UPB_INLINE upb_Array* _google_protobuf_GeneratedCodeInfo_Annotation_path_mutable_upb_array(const google_protobuf_GeneratedCodeInfo_Annotation* msg, size_t* size, upb_Arena* arena) { +UPB_INLINE upb_Array* _google_protobuf_GeneratedCodeInfo_Annotation_path_mutable_upb_array(google_protobuf_GeneratedCodeInfo_Annotation* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = {1, UPB_SIZE(4, 16), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsPacked | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - (upb_Message*)msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), + &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -10930,68 +11182,72 @@ UPB_INLINE upb_Array* _google_protobuf_GeneratedCodeInfo_Annotation_path_mutable } UPB_INLINE void google_protobuf_GeneratedCodeInfo_Annotation_clear_source_file(google_protobuf_GeneratedCodeInfo_Annotation* msg) { const upb_MiniTableField field = {2, UPB_SIZE(20, 24), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_GeneratedCodeInfo_Annotation_source_file(const google_protobuf_GeneratedCodeInfo_Annotation* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; const upb_MiniTableField field = {2, UPB_SIZE(20, 24), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_GeneratedCodeInfo_Annotation_has_source_file(const google_protobuf_GeneratedCodeInfo_Annotation* msg) { const upb_MiniTableField field = {2, UPB_SIZE(20, 24), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_GeneratedCodeInfo_Annotation_clear_begin(google_protobuf_GeneratedCodeInfo_Annotation* msg) { const upb_MiniTableField field = {3, UPB_SIZE(8, 4), 2, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_GeneratedCodeInfo_Annotation_begin(const google_protobuf_GeneratedCodeInfo_Annotation* msg) { int32_t default_val = (int32_t)0; int32_t ret; const upb_MiniTableField field = {3, UPB_SIZE(8, 4), 2, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_GeneratedCodeInfo_Annotation_has_begin(const google_protobuf_GeneratedCodeInfo_Annotation* msg) { const upb_MiniTableField field = {3, UPB_SIZE(8, 4), 2, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_GeneratedCodeInfo_Annotation_clear_end(google_protobuf_GeneratedCodeInfo_Annotation* msg) { const upb_MiniTableField field = {4, UPB_SIZE(12, 8), 3, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_GeneratedCodeInfo_Annotation_end(const google_protobuf_GeneratedCodeInfo_Annotation* msg) { int32_t default_val = (int32_t)0; int32_t ret; const upb_MiniTableField field = {4, UPB_SIZE(12, 8), 3, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_GeneratedCodeInfo_Annotation_has_end(const google_protobuf_GeneratedCodeInfo_Annotation* msg) { const upb_MiniTableField field = {4, UPB_SIZE(12, 8), 3, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_GeneratedCodeInfo_Annotation_clear_semantic(google_protobuf_GeneratedCodeInfo_Annotation* msg) { const upb_MiniTableField field = {5, UPB_SIZE(16, 12), 4, 0, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_GeneratedCodeInfo_Annotation_semantic(const google_protobuf_GeneratedCodeInfo_Annotation* msg) { int32_t default_val = 0; int32_t ret; const upb_MiniTableField field = {5, UPB_SIZE(16, 12), 4, 0, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_GeneratedCodeInfo_Annotation_has_semantic(const google_protobuf_GeneratedCodeInfo_Annotation* msg) { const upb_MiniTableField field = {5, UPB_SIZE(16, 12), 4, 0, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t* google_protobuf_GeneratedCodeInfo_Annotation_mutable_path(google_protobuf_GeneratedCodeInfo_Annotation* msg, size_t* size) { upb_MiniTableField field = {1, UPB_SIZE(4, 16), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsPacked | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetMutableArray(msg, &field); + upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (int32_t*)_upb_array_ptr(arr); @@ -11002,11 +11258,13 @@ UPB_INLINE int32_t* google_protobuf_GeneratedCodeInfo_Annotation_mutable_path(go } UPB_INLINE int32_t* google_protobuf_GeneratedCodeInfo_Annotation_resize_path(google_protobuf_GeneratedCodeInfo_Annotation* msg, size_t size, upb_Arena* arena) { upb_MiniTableField field = {1, UPB_SIZE(4, 16), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsPacked | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return (int32_t*)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); + return (int32_t*)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg), + &field, size, arena); } UPB_INLINE bool google_protobuf_GeneratedCodeInfo_Annotation_add_path(google_protobuf_GeneratedCodeInfo_Annotation* msg, int32_t val, upb_Arena* arena) { upb_MiniTableField field = {1, UPB_SIZE(4, 16), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsPacked | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray( + UPB_UPCAST(msg), &field, arena); if (!arr || !_upb_Array_ResizeUninitialized( arr, arr->UPB_PRIVATE(size) + 1, arena)) { return false; @@ -11017,19 +11275,19 @@ UPB_INLINE bool google_protobuf_GeneratedCodeInfo_Annotation_add_path(google_pro } UPB_INLINE void google_protobuf_GeneratedCodeInfo_Annotation_set_source_file(google_protobuf_GeneratedCodeInfo_Annotation *msg, upb_StringView value) { const upb_MiniTableField field = {2, UPB_SIZE(20, 24), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_GeneratedCodeInfo_Annotation_set_begin(google_protobuf_GeneratedCodeInfo_Annotation *msg, int32_t value) { const upb_MiniTableField field = {3, UPB_SIZE(8, 4), 2, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_GeneratedCodeInfo_Annotation_set_end(google_protobuf_GeneratedCodeInfo_Annotation *msg, int32_t value) { const upb_MiniTableField field = {4, UPB_SIZE(12, 8), 3, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_GeneratedCodeInfo_Annotation_set_semantic(google_protobuf_GeneratedCodeInfo_Annotation *msg, int32_t value) { const upb_MiniTableField field = {5, UPB_SIZE(16, 12), 4, 0, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } /* Max size 32 is google.protobuf.FileOptions */ diff --git a/upb/cmake/google/protobuf/descriptor.upb.h b/upb/cmake/google/protobuf/descriptor.upb.h index e1e8359d04b85..b872bb6ef6f1c 100644 --- a/upb/cmake/google/protobuf/descriptor.upb.h +++ b/upb/cmake/google/protobuf/descriptor.upb.h @@ -19,38 +19,38 @@ extern "C" { #endif -typedef struct google_protobuf_FileDescriptorSet google_protobuf_FileDescriptorSet; -typedef struct google_protobuf_FileDescriptorProto google_protobuf_FileDescriptorProto; -typedef struct google_protobuf_DescriptorProto google_protobuf_DescriptorProto; -typedef struct google_protobuf_DescriptorProto_ExtensionRange google_protobuf_DescriptorProto_ExtensionRange; -typedef struct google_protobuf_DescriptorProto_ReservedRange google_protobuf_DescriptorProto_ReservedRange; -typedef struct google_protobuf_ExtensionRangeOptions google_protobuf_ExtensionRangeOptions; -typedef struct google_protobuf_ExtensionRangeOptions_Declaration google_protobuf_ExtensionRangeOptions_Declaration; -typedef struct google_protobuf_FieldDescriptorProto google_protobuf_FieldDescriptorProto; -typedef struct google_protobuf_OneofDescriptorProto google_protobuf_OneofDescriptorProto; -typedef struct google_protobuf_EnumDescriptorProto google_protobuf_EnumDescriptorProto; -typedef struct google_protobuf_EnumDescriptorProto_EnumReservedRange google_protobuf_EnumDescriptorProto_EnumReservedRange; -typedef struct google_protobuf_EnumValueDescriptorProto google_protobuf_EnumValueDescriptorProto; -typedef struct google_protobuf_ServiceDescriptorProto google_protobuf_ServiceDescriptorProto; -typedef struct google_protobuf_MethodDescriptorProto google_protobuf_MethodDescriptorProto; -typedef struct google_protobuf_FileOptions google_protobuf_FileOptions; -typedef struct google_protobuf_MessageOptions google_protobuf_MessageOptions; -typedef struct google_protobuf_FieldOptions google_protobuf_FieldOptions; -typedef struct google_protobuf_FieldOptions_EditionDefault google_protobuf_FieldOptions_EditionDefault; -typedef struct google_protobuf_OneofOptions google_protobuf_OneofOptions; -typedef struct google_protobuf_EnumOptions google_protobuf_EnumOptions; -typedef struct google_protobuf_EnumValueOptions google_protobuf_EnumValueOptions; -typedef struct google_protobuf_ServiceOptions google_protobuf_ServiceOptions; -typedef struct google_protobuf_MethodOptions google_protobuf_MethodOptions; -typedef struct google_protobuf_UninterpretedOption google_protobuf_UninterpretedOption; -typedef struct google_protobuf_UninterpretedOption_NamePart google_protobuf_UninterpretedOption_NamePart; -typedef struct google_protobuf_FeatureSet google_protobuf_FeatureSet; -typedef struct google_protobuf_FeatureSetDefaults google_protobuf_FeatureSetDefaults; -typedef struct google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault; -typedef struct google_protobuf_SourceCodeInfo google_protobuf_SourceCodeInfo; -typedef struct google_protobuf_SourceCodeInfo_Location google_protobuf_SourceCodeInfo_Location; -typedef struct google_protobuf_GeneratedCodeInfo google_protobuf_GeneratedCodeInfo; -typedef struct google_protobuf_GeneratedCodeInfo_Annotation google_protobuf_GeneratedCodeInfo_Annotation; +typedef struct google_protobuf_FileDescriptorSet { upb_Message UPB_PRIVATE(base); } google_protobuf_FileDescriptorSet; +typedef struct google_protobuf_FileDescriptorProto { upb_Message UPB_PRIVATE(base); } google_protobuf_FileDescriptorProto; +typedef struct google_protobuf_DescriptorProto { upb_Message UPB_PRIVATE(base); } google_protobuf_DescriptorProto; +typedef struct google_protobuf_DescriptorProto_ExtensionRange { upb_Message UPB_PRIVATE(base); } google_protobuf_DescriptorProto_ExtensionRange; +typedef struct google_protobuf_DescriptorProto_ReservedRange { upb_Message UPB_PRIVATE(base); } google_protobuf_DescriptorProto_ReservedRange; +typedef struct google_protobuf_ExtensionRangeOptions { upb_Message UPB_PRIVATE(base); } google_protobuf_ExtensionRangeOptions; +typedef struct google_protobuf_ExtensionRangeOptions_Declaration { upb_Message UPB_PRIVATE(base); } google_protobuf_ExtensionRangeOptions_Declaration; +typedef struct google_protobuf_FieldDescriptorProto { upb_Message UPB_PRIVATE(base); } google_protobuf_FieldDescriptorProto; +typedef struct google_protobuf_OneofDescriptorProto { upb_Message UPB_PRIVATE(base); } google_protobuf_OneofDescriptorProto; +typedef struct google_protobuf_EnumDescriptorProto { upb_Message UPB_PRIVATE(base); } google_protobuf_EnumDescriptorProto; +typedef struct google_protobuf_EnumDescriptorProto_EnumReservedRange { upb_Message UPB_PRIVATE(base); } google_protobuf_EnumDescriptorProto_EnumReservedRange; +typedef struct google_protobuf_EnumValueDescriptorProto { upb_Message UPB_PRIVATE(base); } google_protobuf_EnumValueDescriptorProto; +typedef struct google_protobuf_ServiceDescriptorProto { upb_Message UPB_PRIVATE(base); } google_protobuf_ServiceDescriptorProto; +typedef struct google_protobuf_MethodDescriptorProto { upb_Message UPB_PRIVATE(base); } google_protobuf_MethodDescriptorProto; +typedef struct google_protobuf_FileOptions { upb_Message UPB_PRIVATE(base); } google_protobuf_FileOptions; +typedef struct google_protobuf_MessageOptions { upb_Message UPB_PRIVATE(base); } google_protobuf_MessageOptions; +typedef struct google_protobuf_FieldOptions { upb_Message UPB_PRIVATE(base); } google_protobuf_FieldOptions; +typedef struct google_protobuf_FieldOptions_EditionDefault { upb_Message UPB_PRIVATE(base); } google_protobuf_FieldOptions_EditionDefault; +typedef struct google_protobuf_OneofOptions { upb_Message UPB_PRIVATE(base); } google_protobuf_OneofOptions; +typedef struct google_protobuf_EnumOptions { upb_Message UPB_PRIVATE(base); } google_protobuf_EnumOptions; +typedef struct google_protobuf_EnumValueOptions { upb_Message UPB_PRIVATE(base); } google_protobuf_EnumValueOptions; +typedef struct google_protobuf_ServiceOptions { upb_Message UPB_PRIVATE(base); } google_protobuf_ServiceOptions; +typedef struct google_protobuf_MethodOptions { upb_Message UPB_PRIVATE(base); } google_protobuf_MethodOptions; +typedef struct google_protobuf_UninterpretedOption { upb_Message UPB_PRIVATE(base); } google_protobuf_UninterpretedOption; +typedef struct google_protobuf_UninterpretedOption_NamePart { upb_Message UPB_PRIVATE(base); } google_protobuf_UninterpretedOption_NamePart; +typedef struct google_protobuf_FeatureSet { upb_Message UPB_PRIVATE(base); } google_protobuf_FeatureSet; +typedef struct google_protobuf_FeatureSetDefaults { upb_Message UPB_PRIVATE(base); } google_protobuf_FeatureSetDefaults; +typedef struct google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault { upb_Message UPB_PRIVATE(base); } google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault; +typedef struct google_protobuf_SourceCodeInfo { upb_Message UPB_PRIVATE(base); } google_protobuf_SourceCodeInfo; +typedef struct google_protobuf_SourceCodeInfo_Location { upb_Message UPB_PRIVATE(base); } google_protobuf_SourceCodeInfo_Location; +typedef struct google_protobuf_GeneratedCodeInfo { upb_Message UPB_PRIVATE(base); } google_protobuf_GeneratedCodeInfo; +typedef struct google_protobuf_GeneratedCodeInfo_Annotation { upb_Message UPB_PRIVATE(base); } google_protobuf_GeneratedCodeInfo_Annotation; typedef enum { google_protobuf_EDITION_UNKNOWN = 0, @@ -193,7 +193,8 @@ UPB_INLINE google_protobuf_FileDescriptorSet* google_protobuf_FileDescriptorSet_ UPB_INLINE google_protobuf_FileDescriptorSet* google_protobuf_FileDescriptorSet_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_FileDescriptorSet* ret = google_protobuf_FileDescriptorSet_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__FileDescriptorSet_msg_init, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__FileDescriptorSet_msg_init, NULL, 0, arena) != + kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -203,30 +204,30 @@ UPB_INLINE google_protobuf_FileDescriptorSet* google_protobuf_FileDescriptorSet_ int options, upb_Arena* arena) { google_protobuf_FileDescriptorSet* ret = google_protobuf_FileDescriptorSet_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__FileDescriptorSet_msg_init, extreg, options, arena) != - kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__FileDescriptorSet_msg_init, extreg, options, + arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_FileDescriptorSet_serialize(const google_protobuf_FileDescriptorSet* msg, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__FileDescriptorSet_msg_init, 0, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__FileDescriptorSet_msg_init, 0, arena, &ptr, len); return ptr; } UPB_INLINE char* google_protobuf_FileDescriptorSet_serialize_ex(const google_protobuf_FileDescriptorSet* msg, int options, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__FileDescriptorSet_msg_init, options, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__FileDescriptorSet_msg_init, options, arena, &ptr, len); return ptr; } UPB_INLINE void google_protobuf_FileDescriptorSet_clear_file(google_protobuf_FileDescriptorSet* msg) { const upb_MiniTableField field = {1, 0, 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_FileDescriptorProto* const* google_protobuf_FileDescriptorSet_file(const google_protobuf_FileDescriptorSet* msg, size_t* size) { const upb_MiniTableField field = {1, 0, 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_FileDescriptorProto* const*)_upb_array_constptr(arr); @@ -237,16 +238,16 @@ UPB_INLINE const google_protobuf_FileDescriptorProto* const* google_protobuf_Fil } UPB_INLINE const upb_Array* _google_protobuf_FileDescriptorSet_file_upb_array(const google_protobuf_FileDescriptorSet* msg, size_t* size) { const upb_MiniTableField field = {1, 0, 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } -UPB_INLINE upb_Array* _google_protobuf_FileDescriptorSet_file_mutable_upb_array(const google_protobuf_FileDescriptorSet* msg, size_t* size, upb_Arena* arena) { +UPB_INLINE upb_Array* _google_protobuf_FileDescriptorSet_file_mutable_upb_array(google_protobuf_FileDescriptorSet* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = {1, 0, 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - (upb_Message*)msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), + &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -255,7 +256,7 @@ UPB_INLINE upb_Array* _google_protobuf_FileDescriptorSet_file_mutable_upb_array( UPB_INLINE google_protobuf_FileDescriptorProto** google_protobuf_FileDescriptorSet_mutable_file(google_protobuf_FileDescriptorSet* msg, size_t* size) { upb_MiniTableField field = {1, 0, 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetMutableArray(msg, &field); + upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_FileDescriptorProto**)_upb_array_ptr(arr); @@ -266,11 +267,13 @@ UPB_INLINE google_protobuf_FileDescriptorProto** google_protobuf_FileDescriptorS } UPB_INLINE google_protobuf_FileDescriptorProto** google_protobuf_FileDescriptorSet_resize_file(google_protobuf_FileDescriptorSet* msg, size_t size, upb_Arena* arena) { upb_MiniTableField field = {1, 0, 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return (google_protobuf_FileDescriptorProto**)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); + return (google_protobuf_FileDescriptorProto**)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg), + &field, size, arena); } UPB_INLINE struct google_protobuf_FileDescriptorProto* google_protobuf_FileDescriptorSet_add_file(google_protobuf_FileDescriptorSet* msg, upb_Arena* arena) { upb_MiniTableField field = {1, 0, 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray( + UPB_UPCAST(msg), &field, arena); if (!arr || !_upb_Array_ResizeUninitialized( arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; @@ -290,7 +293,8 @@ UPB_INLINE google_protobuf_FileDescriptorProto* google_protobuf_FileDescriptorPr UPB_INLINE google_protobuf_FileDescriptorProto* google_protobuf_FileDescriptorProto_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_FileDescriptorProto* ret = google_protobuf_FileDescriptorProto_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__FileDescriptorProto_msg_init, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__FileDescriptorProto_msg_init, NULL, 0, arena) != + kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -300,60 +304,62 @@ UPB_INLINE google_protobuf_FileDescriptorProto* google_protobuf_FileDescriptorPr int options, upb_Arena* arena) { google_protobuf_FileDescriptorProto* ret = google_protobuf_FileDescriptorProto_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__FileDescriptorProto_msg_init, extreg, options, arena) != - kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__FileDescriptorProto_msg_init, extreg, options, + arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_FileDescriptorProto_serialize(const google_protobuf_FileDescriptorProto* msg, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__FileDescriptorProto_msg_init, 0, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__FileDescriptorProto_msg_init, 0, arena, &ptr, len); return ptr; } UPB_INLINE char* google_protobuf_FileDescriptorProto_serialize_ex(const google_protobuf_FileDescriptorProto* msg, int options, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__FileDescriptorProto_msg_init, options, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__FileDescriptorProto_msg_init, options, arena, &ptr, len); return ptr; } UPB_INLINE void google_protobuf_FileDescriptorProto_clear_name(google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = {1, UPB_SIZE(44, 8), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_FileDescriptorProto_name(const google_protobuf_FileDescriptorProto* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; const upb_MiniTableField field = {1, UPB_SIZE(44, 8), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FileDescriptorProto_has_name(const google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = {1, UPB_SIZE(44, 8), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileDescriptorProto_clear_package(google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = {2, UPB_SIZE(52, 24), 2, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_FileDescriptorProto_package(const google_protobuf_FileDescriptorProto* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; const upb_MiniTableField field = {2, UPB_SIZE(52, 24), 2, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FileDescriptorProto_has_package(const google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = {2, UPB_SIZE(52, 24), 2, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileDescriptorProto_clear_dependency(google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = {3, UPB_SIZE(4, 40), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView const* google_protobuf_FileDescriptorProto_dependency(const google_protobuf_FileDescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {3, UPB_SIZE(4, 40), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (upb_StringView const*)_upb_array_constptr(arr); @@ -364,16 +370,16 @@ UPB_INLINE upb_StringView const* google_protobuf_FileDescriptorProto_dependency( } UPB_INLINE const upb_Array* _google_protobuf_FileDescriptorProto_dependency_upb_array(const google_protobuf_FileDescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {3, UPB_SIZE(4, 40), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } -UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_dependency_mutable_upb_array(const google_protobuf_FileDescriptorProto* msg, size_t* size, upb_Arena* arena) { +UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_dependency_mutable_upb_array(google_protobuf_FileDescriptorProto* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = {3, UPB_SIZE(4, 40), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - (upb_Message*)msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), + &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -381,11 +387,11 @@ UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_dependency_mutable_up } UPB_INLINE void google_protobuf_FileDescriptorProto_clear_message_type(google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = {4, UPB_SIZE(8, 48), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_DescriptorProto* const* google_protobuf_FileDescriptorProto_message_type(const google_protobuf_FileDescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {4, UPB_SIZE(8, 48), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_DescriptorProto* const*)_upb_array_constptr(arr); @@ -396,16 +402,16 @@ UPB_INLINE const google_protobuf_DescriptorProto* const* google_protobuf_FileDes } UPB_INLINE const upb_Array* _google_protobuf_FileDescriptorProto_message_type_upb_array(const google_protobuf_FileDescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {4, UPB_SIZE(8, 48), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } -UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_message_type_mutable_upb_array(const google_protobuf_FileDescriptorProto* msg, size_t* size, upb_Arena* arena) { +UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_message_type_mutable_upb_array(google_protobuf_FileDescriptorProto* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = {4, UPB_SIZE(8, 48), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - (upb_Message*)msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), + &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -413,11 +419,11 @@ UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_message_type_mutable_ } UPB_INLINE void google_protobuf_FileDescriptorProto_clear_enum_type(google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = {5, UPB_SIZE(12, 56), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_EnumDescriptorProto* const* google_protobuf_FileDescriptorProto_enum_type(const google_protobuf_FileDescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {5, UPB_SIZE(12, 56), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_EnumDescriptorProto* const*)_upb_array_constptr(arr); @@ -428,16 +434,16 @@ UPB_INLINE const google_protobuf_EnumDescriptorProto* const* google_protobuf_Fil } UPB_INLINE const upb_Array* _google_protobuf_FileDescriptorProto_enum_type_upb_array(const google_protobuf_FileDescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {5, UPB_SIZE(12, 56), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } -UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_enum_type_mutable_upb_array(const google_protobuf_FileDescriptorProto* msg, size_t* size, upb_Arena* arena) { +UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_enum_type_mutable_upb_array(google_protobuf_FileDescriptorProto* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = {5, UPB_SIZE(12, 56), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - (upb_Message*)msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), + &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -445,11 +451,11 @@ UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_enum_type_mutable_upb } UPB_INLINE void google_protobuf_FileDescriptorProto_clear_service(google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = {6, UPB_SIZE(16, 64), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_ServiceDescriptorProto* const* google_protobuf_FileDescriptorProto_service(const google_protobuf_FileDescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {6, UPB_SIZE(16, 64), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_ServiceDescriptorProto* const*)_upb_array_constptr(arr); @@ -460,16 +466,16 @@ UPB_INLINE const google_protobuf_ServiceDescriptorProto* const* google_protobuf_ } UPB_INLINE const upb_Array* _google_protobuf_FileDescriptorProto_service_upb_array(const google_protobuf_FileDescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {6, UPB_SIZE(16, 64), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } -UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_service_mutable_upb_array(const google_protobuf_FileDescriptorProto* msg, size_t* size, upb_Arena* arena) { +UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_service_mutable_upb_array(google_protobuf_FileDescriptorProto* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = {6, UPB_SIZE(16, 64), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - (upb_Message*)msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), + &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -477,11 +483,11 @@ UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_service_mutable_upb_a } UPB_INLINE void google_protobuf_FileDescriptorProto_clear_extension(google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = {7, UPB_SIZE(20, 72), 0, 3, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_FieldDescriptorProto* const* google_protobuf_FileDescriptorProto_extension(const google_protobuf_FileDescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {7, UPB_SIZE(20, 72), 0, 3, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_FieldDescriptorProto* const*)_upb_array_constptr(arr); @@ -492,16 +498,16 @@ UPB_INLINE const google_protobuf_FieldDescriptorProto* const* google_protobuf_Fi } UPB_INLINE const upb_Array* _google_protobuf_FileDescriptorProto_extension_upb_array(const google_protobuf_FileDescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {7, UPB_SIZE(20, 72), 0, 3, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } -UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_extension_mutable_upb_array(const google_protobuf_FileDescriptorProto* msg, size_t* size, upb_Arena* arena) { +UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_extension_mutable_upb_array(google_protobuf_FileDescriptorProto* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = {7, UPB_SIZE(20, 72), 0, 3, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - (upb_Message*)msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), + &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -509,41 +515,43 @@ UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_extension_mutable_upb } UPB_INLINE void google_protobuf_FileDescriptorProto_clear_options(google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = {8, UPB_SIZE(24, 80), 3, 4, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_FileOptions* google_protobuf_FileDescriptorProto_options(const google_protobuf_FileDescriptorProto* msg) { const google_protobuf_FileOptions* default_val = NULL; const google_protobuf_FileOptions* ret; const upb_MiniTableField field = {8, UPB_SIZE(24, 80), 3, 4, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FileDescriptorProto_has_options(const google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = {8, UPB_SIZE(24, 80), 3, 4, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileDescriptorProto_clear_source_code_info(google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = {9, UPB_SIZE(28, 88), 4, 5, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_SourceCodeInfo* google_protobuf_FileDescriptorProto_source_code_info(const google_protobuf_FileDescriptorProto* msg) { const google_protobuf_SourceCodeInfo* default_val = NULL; const google_protobuf_SourceCodeInfo* ret; const upb_MiniTableField field = {9, UPB_SIZE(28, 88), 4, 5, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FileDescriptorProto_has_source_code_info(const google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = {9, UPB_SIZE(28, 88), 4, 5, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileDescriptorProto_clear_public_dependency(google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = {10, UPB_SIZE(32, 96), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t const* google_protobuf_FileDescriptorProto_public_dependency(const google_protobuf_FileDescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {10, UPB_SIZE(32, 96), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (int32_t const*)_upb_array_constptr(arr); @@ -554,16 +562,16 @@ UPB_INLINE int32_t const* google_protobuf_FileDescriptorProto_public_dependency( } UPB_INLINE const upb_Array* _google_protobuf_FileDescriptorProto_public_dependency_upb_array(const google_protobuf_FileDescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {10, UPB_SIZE(32, 96), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } -UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_public_dependency_mutable_upb_array(const google_protobuf_FileDescriptorProto* msg, size_t* size, upb_Arena* arena) { +UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_public_dependency_mutable_upb_array(google_protobuf_FileDescriptorProto* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = {10, UPB_SIZE(32, 96), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - (upb_Message*)msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), + &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -571,11 +579,11 @@ UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_public_dependency_mut } UPB_INLINE void google_protobuf_FileDescriptorProto_clear_weak_dependency(google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = {11, UPB_SIZE(36, 104), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t const* google_protobuf_FileDescriptorProto_weak_dependency(const google_protobuf_FileDescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {11, UPB_SIZE(36, 104), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (int32_t const*)_upb_array_constptr(arr); @@ -586,16 +594,16 @@ UPB_INLINE int32_t const* google_protobuf_FileDescriptorProto_weak_dependency(co } UPB_INLINE const upb_Array* _google_protobuf_FileDescriptorProto_weak_dependency_upb_array(const google_protobuf_FileDescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {11, UPB_SIZE(36, 104), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } -UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_weak_dependency_mutable_upb_array(const google_protobuf_FileDescriptorProto* msg, size_t* size, upb_Arena* arena) { +UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_weak_dependency_mutable_upb_array(google_protobuf_FileDescriptorProto* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = {11, UPB_SIZE(36, 104), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - (upb_Message*)msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), + &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -603,46 +611,48 @@ UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_weak_dependency_mutab } UPB_INLINE void google_protobuf_FileDescriptorProto_clear_syntax(google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = {12, UPB_SIZE(60, 112), 5, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_FileDescriptorProto_syntax(const google_protobuf_FileDescriptorProto* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; const upb_MiniTableField field = {12, UPB_SIZE(60, 112), 5, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FileDescriptorProto_has_syntax(const google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = {12, UPB_SIZE(60, 112), 5, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileDescriptorProto_clear_edition(google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = {14, UPB_SIZE(40, 4), 6, 6, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_FileDescriptorProto_edition(const google_protobuf_FileDescriptorProto* msg) { int32_t default_val = 0; int32_t ret; const upb_MiniTableField field = {14, UPB_SIZE(40, 4), 6, 6, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FileDescriptorProto_has_edition(const google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = {14, UPB_SIZE(40, 4), 6, 6, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileDescriptorProto_set_name(google_protobuf_FileDescriptorProto *msg, upb_StringView value) { const upb_MiniTableField field = {1, UPB_SIZE(44, 8), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FileDescriptorProto_set_package(google_protobuf_FileDescriptorProto *msg, upb_StringView value) { const upb_MiniTableField field = {2, UPB_SIZE(52, 24), 2, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE upb_StringView* google_protobuf_FileDescriptorProto_mutable_dependency(google_protobuf_FileDescriptorProto* msg, size_t* size) { upb_MiniTableField field = {3, UPB_SIZE(4, 40), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetMutableArray(msg, &field); + upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (upb_StringView*)_upb_array_ptr(arr); @@ -653,11 +663,13 @@ UPB_INLINE upb_StringView* google_protobuf_FileDescriptorProto_mutable_dependenc } UPB_INLINE upb_StringView* google_protobuf_FileDescriptorProto_resize_dependency(google_protobuf_FileDescriptorProto* msg, size_t size, upb_Arena* arena) { upb_MiniTableField field = {3, UPB_SIZE(4, 40), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return (upb_StringView*)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); + return (upb_StringView*)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg), + &field, size, arena); } UPB_INLINE bool google_protobuf_FileDescriptorProto_add_dependency(google_protobuf_FileDescriptorProto* msg, upb_StringView val, upb_Arena* arena) { upb_MiniTableField field = {3, UPB_SIZE(4, 40), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray( + UPB_UPCAST(msg), &field, arena); if (!arr || !_upb_Array_ResizeUninitialized( arr, arr->UPB_PRIVATE(size) + 1, arena)) { return false; @@ -668,7 +680,7 @@ UPB_INLINE bool google_protobuf_FileDescriptorProto_add_dependency(google_protob } UPB_INLINE google_protobuf_DescriptorProto** google_protobuf_FileDescriptorProto_mutable_message_type(google_protobuf_FileDescriptorProto* msg, size_t* size) { upb_MiniTableField field = {4, UPB_SIZE(8, 48), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetMutableArray(msg, &field); + upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_DescriptorProto**)_upb_array_ptr(arr); @@ -679,11 +691,13 @@ UPB_INLINE google_protobuf_DescriptorProto** google_protobuf_FileDescriptorProto } UPB_INLINE google_protobuf_DescriptorProto** google_protobuf_FileDescriptorProto_resize_message_type(google_protobuf_FileDescriptorProto* msg, size_t size, upb_Arena* arena) { upb_MiniTableField field = {4, UPB_SIZE(8, 48), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return (google_protobuf_DescriptorProto**)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); + return (google_protobuf_DescriptorProto**)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg), + &field, size, arena); } UPB_INLINE struct google_protobuf_DescriptorProto* google_protobuf_FileDescriptorProto_add_message_type(google_protobuf_FileDescriptorProto* msg, upb_Arena* arena) { upb_MiniTableField field = {4, UPB_SIZE(8, 48), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray( + UPB_UPCAST(msg), &field, arena); if (!arr || !_upb_Array_ResizeUninitialized( arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; @@ -696,7 +710,7 @@ UPB_INLINE struct google_protobuf_DescriptorProto* google_protobuf_FileDescripto } UPB_INLINE google_protobuf_EnumDescriptorProto** google_protobuf_FileDescriptorProto_mutable_enum_type(google_protobuf_FileDescriptorProto* msg, size_t* size) { upb_MiniTableField field = {5, UPB_SIZE(12, 56), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetMutableArray(msg, &field); + upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_EnumDescriptorProto**)_upb_array_ptr(arr); @@ -707,11 +721,13 @@ UPB_INLINE google_protobuf_EnumDescriptorProto** google_protobuf_FileDescriptorP } UPB_INLINE google_protobuf_EnumDescriptorProto** google_protobuf_FileDescriptorProto_resize_enum_type(google_protobuf_FileDescriptorProto* msg, size_t size, upb_Arena* arena) { upb_MiniTableField field = {5, UPB_SIZE(12, 56), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return (google_protobuf_EnumDescriptorProto**)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); + return (google_protobuf_EnumDescriptorProto**)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg), + &field, size, arena); } UPB_INLINE struct google_protobuf_EnumDescriptorProto* google_protobuf_FileDescriptorProto_add_enum_type(google_protobuf_FileDescriptorProto* msg, upb_Arena* arena) { upb_MiniTableField field = {5, UPB_SIZE(12, 56), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray( + UPB_UPCAST(msg), &field, arena); if (!arr || !_upb_Array_ResizeUninitialized( arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; @@ -724,7 +740,7 @@ UPB_INLINE struct google_protobuf_EnumDescriptorProto* google_protobuf_FileDescr } UPB_INLINE google_protobuf_ServiceDescriptorProto** google_protobuf_FileDescriptorProto_mutable_service(google_protobuf_FileDescriptorProto* msg, size_t* size) { upb_MiniTableField field = {6, UPB_SIZE(16, 64), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetMutableArray(msg, &field); + upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_ServiceDescriptorProto**)_upb_array_ptr(arr); @@ -735,11 +751,13 @@ UPB_INLINE google_protobuf_ServiceDescriptorProto** google_protobuf_FileDescript } UPB_INLINE google_protobuf_ServiceDescriptorProto** google_protobuf_FileDescriptorProto_resize_service(google_protobuf_FileDescriptorProto* msg, size_t size, upb_Arena* arena) { upb_MiniTableField field = {6, UPB_SIZE(16, 64), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return (google_protobuf_ServiceDescriptorProto**)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); + return (google_protobuf_ServiceDescriptorProto**)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg), + &field, size, arena); } UPB_INLINE struct google_protobuf_ServiceDescriptorProto* google_protobuf_FileDescriptorProto_add_service(google_protobuf_FileDescriptorProto* msg, upb_Arena* arena) { upb_MiniTableField field = {6, UPB_SIZE(16, 64), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray( + UPB_UPCAST(msg), &field, arena); if (!arr || !_upb_Array_ResizeUninitialized( arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; @@ -752,7 +770,7 @@ UPB_INLINE struct google_protobuf_ServiceDescriptorProto* google_protobuf_FileDe } UPB_INLINE google_protobuf_FieldDescriptorProto** google_protobuf_FileDescriptorProto_mutable_extension(google_protobuf_FileDescriptorProto* msg, size_t* size) { upb_MiniTableField field = {7, UPB_SIZE(20, 72), 0, 3, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetMutableArray(msg, &field); + upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_FieldDescriptorProto**)_upb_array_ptr(arr); @@ -763,11 +781,13 @@ UPB_INLINE google_protobuf_FieldDescriptorProto** google_protobuf_FileDescriptor } UPB_INLINE google_protobuf_FieldDescriptorProto** google_protobuf_FileDescriptorProto_resize_extension(google_protobuf_FileDescriptorProto* msg, size_t size, upb_Arena* arena) { upb_MiniTableField field = {7, UPB_SIZE(20, 72), 0, 3, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return (google_protobuf_FieldDescriptorProto**)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); + return (google_protobuf_FieldDescriptorProto**)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg), + &field, size, arena); } UPB_INLINE struct google_protobuf_FieldDescriptorProto* google_protobuf_FileDescriptorProto_add_extension(google_protobuf_FileDescriptorProto* msg, upb_Arena* arena) { upb_MiniTableField field = {7, UPB_SIZE(20, 72), 0, 3, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray( + UPB_UPCAST(msg), &field, arena); if (!arr || !_upb_Array_ResizeUninitialized( arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; @@ -780,7 +800,7 @@ UPB_INLINE struct google_protobuf_FieldDescriptorProto* google_protobuf_FileDesc } UPB_INLINE void google_protobuf_FileDescriptorProto_set_options(google_protobuf_FileDescriptorProto *msg, google_protobuf_FileOptions* value) { const upb_MiniTableField field = {8, UPB_SIZE(24, 80), 3, 4, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE struct google_protobuf_FileOptions* google_protobuf_FileDescriptorProto_mutable_options(google_protobuf_FileDescriptorProto* msg, upb_Arena* arena) { struct google_protobuf_FileOptions* sub = (struct google_protobuf_FileOptions*)google_protobuf_FileDescriptorProto_options(msg); @@ -792,7 +812,7 @@ UPB_INLINE struct google_protobuf_FileOptions* google_protobuf_FileDescriptorPro } UPB_INLINE void google_protobuf_FileDescriptorProto_set_source_code_info(google_protobuf_FileDescriptorProto *msg, google_protobuf_SourceCodeInfo* value) { const upb_MiniTableField field = {9, UPB_SIZE(28, 88), 4, 5, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE struct google_protobuf_SourceCodeInfo* google_protobuf_FileDescriptorProto_mutable_source_code_info(google_protobuf_FileDescriptorProto* msg, upb_Arena* arena) { struct google_protobuf_SourceCodeInfo* sub = (struct google_protobuf_SourceCodeInfo*)google_protobuf_FileDescriptorProto_source_code_info(msg); @@ -804,7 +824,7 @@ UPB_INLINE struct google_protobuf_SourceCodeInfo* google_protobuf_FileDescriptor } UPB_INLINE int32_t* google_protobuf_FileDescriptorProto_mutable_public_dependency(google_protobuf_FileDescriptorProto* msg, size_t* size) { upb_MiniTableField field = {10, UPB_SIZE(32, 96), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetMutableArray(msg, &field); + upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (int32_t*)_upb_array_ptr(arr); @@ -815,11 +835,13 @@ UPB_INLINE int32_t* google_protobuf_FileDescriptorProto_mutable_public_dependenc } UPB_INLINE int32_t* google_protobuf_FileDescriptorProto_resize_public_dependency(google_protobuf_FileDescriptorProto* msg, size_t size, upb_Arena* arena) { upb_MiniTableField field = {10, UPB_SIZE(32, 96), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return (int32_t*)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); + return (int32_t*)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg), + &field, size, arena); } UPB_INLINE bool google_protobuf_FileDescriptorProto_add_public_dependency(google_protobuf_FileDescriptorProto* msg, int32_t val, upb_Arena* arena) { upb_MiniTableField field = {10, UPB_SIZE(32, 96), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray( + UPB_UPCAST(msg), &field, arena); if (!arr || !_upb_Array_ResizeUninitialized( arr, arr->UPB_PRIVATE(size) + 1, arena)) { return false; @@ -830,7 +852,7 @@ UPB_INLINE bool google_protobuf_FileDescriptorProto_add_public_dependency(google } UPB_INLINE int32_t* google_protobuf_FileDescriptorProto_mutable_weak_dependency(google_protobuf_FileDescriptorProto* msg, size_t* size) { upb_MiniTableField field = {11, UPB_SIZE(36, 104), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetMutableArray(msg, &field); + upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (int32_t*)_upb_array_ptr(arr); @@ -841,11 +863,13 @@ UPB_INLINE int32_t* google_protobuf_FileDescriptorProto_mutable_weak_dependency( } UPB_INLINE int32_t* google_protobuf_FileDescriptorProto_resize_weak_dependency(google_protobuf_FileDescriptorProto* msg, size_t size, upb_Arena* arena) { upb_MiniTableField field = {11, UPB_SIZE(36, 104), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return (int32_t*)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); + return (int32_t*)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg), + &field, size, arena); } UPB_INLINE bool google_protobuf_FileDescriptorProto_add_weak_dependency(google_protobuf_FileDescriptorProto* msg, int32_t val, upb_Arena* arena) { upb_MiniTableField field = {11, UPB_SIZE(36, 104), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray( + UPB_UPCAST(msg), &field, arena); if (!arr || !_upb_Array_ResizeUninitialized( arr, arr->UPB_PRIVATE(size) + 1, arena)) { return false; @@ -856,11 +880,11 @@ UPB_INLINE bool google_protobuf_FileDescriptorProto_add_weak_dependency(google_p } UPB_INLINE void google_protobuf_FileDescriptorProto_set_syntax(google_protobuf_FileDescriptorProto *msg, upb_StringView value) { const upb_MiniTableField field = {12, UPB_SIZE(60, 112), 5, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FileDescriptorProto_set_edition(google_protobuf_FileDescriptorProto *msg, int32_t value) { const upb_MiniTableField field = {14, UPB_SIZE(40, 4), 6, 6, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } /* google.protobuf.DescriptorProto */ @@ -871,7 +895,8 @@ UPB_INLINE google_protobuf_DescriptorProto* google_protobuf_DescriptorProto_new( UPB_INLINE google_protobuf_DescriptorProto* google_protobuf_DescriptorProto_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_DescriptorProto* ret = google_protobuf_DescriptorProto_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__DescriptorProto_msg_init, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__DescriptorProto_msg_init, NULL, 0, arena) != + kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -881,45 +906,46 @@ UPB_INLINE google_protobuf_DescriptorProto* google_protobuf_DescriptorProto_pars int options, upb_Arena* arena) { google_protobuf_DescriptorProto* ret = google_protobuf_DescriptorProto_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__DescriptorProto_msg_init, extreg, options, arena) != - kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__DescriptorProto_msg_init, extreg, options, + arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_DescriptorProto_serialize(const google_protobuf_DescriptorProto* msg, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__DescriptorProto_msg_init, 0, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__DescriptorProto_msg_init, 0, arena, &ptr, len); return ptr; } UPB_INLINE char* google_protobuf_DescriptorProto_serialize_ex(const google_protobuf_DescriptorProto* msg, int options, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__DescriptorProto_msg_init, options, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__DescriptorProto_msg_init, options, arena, &ptr, len); return ptr; } UPB_INLINE void google_protobuf_DescriptorProto_clear_name(google_protobuf_DescriptorProto* msg) { const upb_MiniTableField field = {1, UPB_SIZE(40, 8), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_DescriptorProto_name(const google_protobuf_DescriptorProto* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; const upb_MiniTableField field = {1, UPB_SIZE(40, 8), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_DescriptorProto_has_name(const google_protobuf_DescriptorProto* msg) { const upb_MiniTableField field = {1, UPB_SIZE(40, 8), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_DescriptorProto_clear_field(google_protobuf_DescriptorProto* msg) { const upb_MiniTableField field = {2, UPB_SIZE(4, 24), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_FieldDescriptorProto* const* google_protobuf_DescriptorProto_field(const google_protobuf_DescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {2, UPB_SIZE(4, 24), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_FieldDescriptorProto* const*)_upb_array_constptr(arr); @@ -930,16 +956,16 @@ UPB_INLINE const google_protobuf_FieldDescriptorProto* const* google_protobuf_De } UPB_INLINE const upb_Array* _google_protobuf_DescriptorProto_field_upb_array(const google_protobuf_DescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {2, UPB_SIZE(4, 24), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } -UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_field_mutable_upb_array(const google_protobuf_DescriptorProto* msg, size_t* size, upb_Arena* arena) { +UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_field_mutable_upb_array(google_protobuf_DescriptorProto* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = {2, UPB_SIZE(4, 24), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - (upb_Message*)msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), + &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -947,11 +973,11 @@ UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_field_mutable_upb_array(c } UPB_INLINE void google_protobuf_DescriptorProto_clear_nested_type(google_protobuf_DescriptorProto* msg) { const upb_MiniTableField field = {3, UPB_SIZE(8, 32), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_DescriptorProto* const* google_protobuf_DescriptorProto_nested_type(const google_protobuf_DescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {3, UPB_SIZE(8, 32), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_DescriptorProto* const*)_upb_array_constptr(arr); @@ -962,16 +988,16 @@ UPB_INLINE const google_protobuf_DescriptorProto* const* google_protobuf_Descrip } UPB_INLINE const upb_Array* _google_protobuf_DescriptorProto_nested_type_upb_array(const google_protobuf_DescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {3, UPB_SIZE(8, 32), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } -UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_nested_type_mutable_upb_array(const google_protobuf_DescriptorProto* msg, size_t* size, upb_Arena* arena) { +UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_nested_type_mutable_upb_array(google_protobuf_DescriptorProto* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = {3, UPB_SIZE(8, 32), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - (upb_Message*)msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), + &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -979,11 +1005,11 @@ UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_nested_type_mutable_upb_a } UPB_INLINE void google_protobuf_DescriptorProto_clear_enum_type(google_protobuf_DescriptorProto* msg) { const upb_MiniTableField field = {4, UPB_SIZE(12, 40), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_EnumDescriptorProto* const* google_protobuf_DescriptorProto_enum_type(const google_protobuf_DescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {4, UPB_SIZE(12, 40), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_EnumDescriptorProto* const*)_upb_array_constptr(arr); @@ -994,16 +1020,16 @@ UPB_INLINE const google_protobuf_EnumDescriptorProto* const* google_protobuf_Des } UPB_INLINE const upb_Array* _google_protobuf_DescriptorProto_enum_type_upb_array(const google_protobuf_DescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {4, UPB_SIZE(12, 40), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } -UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_enum_type_mutable_upb_array(const google_protobuf_DescriptorProto* msg, size_t* size, upb_Arena* arena) { +UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_enum_type_mutable_upb_array(google_protobuf_DescriptorProto* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = {4, UPB_SIZE(12, 40), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - (upb_Message*)msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), + &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -1011,11 +1037,11 @@ UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_enum_type_mutable_upb_arr } UPB_INLINE void google_protobuf_DescriptorProto_clear_extension_range(google_protobuf_DescriptorProto* msg) { const upb_MiniTableField field = {5, UPB_SIZE(16, 48), 0, 3, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_DescriptorProto_ExtensionRange* const* google_protobuf_DescriptorProto_extension_range(const google_protobuf_DescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {5, UPB_SIZE(16, 48), 0, 3, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_DescriptorProto_ExtensionRange* const*)_upb_array_constptr(arr); @@ -1026,16 +1052,16 @@ UPB_INLINE const google_protobuf_DescriptorProto_ExtensionRange* const* google_p } UPB_INLINE const upb_Array* _google_protobuf_DescriptorProto_extension_range_upb_array(const google_protobuf_DescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {5, UPB_SIZE(16, 48), 0, 3, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } -UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_extension_range_mutable_upb_array(const google_protobuf_DescriptorProto* msg, size_t* size, upb_Arena* arena) { +UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_extension_range_mutable_upb_array(google_protobuf_DescriptorProto* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = {5, UPB_SIZE(16, 48), 0, 3, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - (upb_Message*)msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), + &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -1043,11 +1069,11 @@ UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_extension_range_mutable_u } UPB_INLINE void google_protobuf_DescriptorProto_clear_extension(google_protobuf_DescriptorProto* msg) { const upb_MiniTableField field = {6, UPB_SIZE(20, 56), 0, 4, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_FieldDescriptorProto* const* google_protobuf_DescriptorProto_extension(const google_protobuf_DescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {6, UPB_SIZE(20, 56), 0, 4, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_FieldDescriptorProto* const*)_upb_array_constptr(arr); @@ -1058,16 +1084,16 @@ UPB_INLINE const google_protobuf_FieldDescriptorProto* const* google_protobuf_De } UPB_INLINE const upb_Array* _google_protobuf_DescriptorProto_extension_upb_array(const google_protobuf_DescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {6, UPB_SIZE(20, 56), 0, 4, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } -UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_extension_mutable_upb_array(const google_protobuf_DescriptorProto* msg, size_t* size, upb_Arena* arena) { +UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_extension_mutable_upb_array(google_protobuf_DescriptorProto* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = {6, UPB_SIZE(20, 56), 0, 4, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - (upb_Message*)msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), + &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -1075,26 +1101,27 @@ UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_extension_mutable_upb_arr } UPB_INLINE void google_protobuf_DescriptorProto_clear_options(google_protobuf_DescriptorProto* msg) { const upb_MiniTableField field = {7, UPB_SIZE(24, 64), 2, 5, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_MessageOptions* google_protobuf_DescriptorProto_options(const google_protobuf_DescriptorProto* msg) { const google_protobuf_MessageOptions* default_val = NULL; const google_protobuf_MessageOptions* ret; const upb_MiniTableField field = {7, UPB_SIZE(24, 64), 2, 5, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_DescriptorProto_has_options(const google_protobuf_DescriptorProto* msg) { const upb_MiniTableField field = {7, UPB_SIZE(24, 64), 2, 5, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_DescriptorProto_clear_oneof_decl(google_protobuf_DescriptorProto* msg) { const upb_MiniTableField field = {8, UPB_SIZE(28, 72), 0, 6, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_OneofDescriptorProto* const* google_protobuf_DescriptorProto_oneof_decl(const google_protobuf_DescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {8, UPB_SIZE(28, 72), 0, 6, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_OneofDescriptorProto* const*)_upb_array_constptr(arr); @@ -1105,16 +1132,16 @@ UPB_INLINE const google_protobuf_OneofDescriptorProto* const* google_protobuf_De } UPB_INLINE const upb_Array* _google_protobuf_DescriptorProto_oneof_decl_upb_array(const google_protobuf_DescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {8, UPB_SIZE(28, 72), 0, 6, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } -UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_oneof_decl_mutable_upb_array(const google_protobuf_DescriptorProto* msg, size_t* size, upb_Arena* arena) { +UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_oneof_decl_mutable_upb_array(google_protobuf_DescriptorProto* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = {8, UPB_SIZE(28, 72), 0, 6, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - (upb_Message*)msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), + &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -1122,11 +1149,11 @@ UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_oneof_decl_mutable_upb_ar } UPB_INLINE void google_protobuf_DescriptorProto_clear_reserved_range(google_protobuf_DescriptorProto* msg) { const upb_MiniTableField field = {9, UPB_SIZE(32, 80), 0, 7, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_DescriptorProto_ReservedRange* const* google_protobuf_DescriptorProto_reserved_range(const google_protobuf_DescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {9, UPB_SIZE(32, 80), 0, 7, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_DescriptorProto_ReservedRange* const*)_upb_array_constptr(arr); @@ -1137,16 +1164,16 @@ UPB_INLINE const google_protobuf_DescriptorProto_ReservedRange* const* google_pr } UPB_INLINE const upb_Array* _google_protobuf_DescriptorProto_reserved_range_upb_array(const google_protobuf_DescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {9, UPB_SIZE(32, 80), 0, 7, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } -UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_reserved_range_mutable_upb_array(const google_protobuf_DescriptorProto* msg, size_t* size, upb_Arena* arena) { +UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_reserved_range_mutable_upb_array(google_protobuf_DescriptorProto* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = {9, UPB_SIZE(32, 80), 0, 7, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - (upb_Message*)msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), + &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -1154,11 +1181,11 @@ UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_reserved_range_mutable_up } UPB_INLINE void google_protobuf_DescriptorProto_clear_reserved_name(google_protobuf_DescriptorProto* msg) { const upb_MiniTableField field = {10, UPB_SIZE(36, 88), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView const* google_protobuf_DescriptorProto_reserved_name(const google_protobuf_DescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {10, UPB_SIZE(36, 88), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (upb_StringView const*)_upb_array_constptr(arr); @@ -1169,16 +1196,16 @@ UPB_INLINE upb_StringView const* google_protobuf_DescriptorProto_reserved_name(c } UPB_INLINE const upb_Array* _google_protobuf_DescriptorProto_reserved_name_upb_array(const google_protobuf_DescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {10, UPB_SIZE(36, 88), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } -UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_reserved_name_mutable_upb_array(const google_protobuf_DescriptorProto* msg, size_t* size, upb_Arena* arena) { +UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_reserved_name_mutable_upb_array(google_protobuf_DescriptorProto* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = {10, UPB_SIZE(36, 88), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - (upb_Message*)msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), + &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -1187,11 +1214,11 @@ UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_reserved_name_mutable_upb UPB_INLINE void google_protobuf_DescriptorProto_set_name(google_protobuf_DescriptorProto *msg, upb_StringView value) { const upb_MiniTableField field = {1, UPB_SIZE(40, 8), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE google_protobuf_FieldDescriptorProto** google_protobuf_DescriptorProto_mutable_field(google_protobuf_DescriptorProto* msg, size_t* size) { upb_MiniTableField field = {2, UPB_SIZE(4, 24), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetMutableArray(msg, &field); + upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_FieldDescriptorProto**)_upb_array_ptr(arr); @@ -1202,11 +1229,13 @@ UPB_INLINE google_protobuf_FieldDescriptorProto** google_protobuf_DescriptorProt } UPB_INLINE google_protobuf_FieldDescriptorProto** google_protobuf_DescriptorProto_resize_field(google_protobuf_DescriptorProto* msg, size_t size, upb_Arena* arena) { upb_MiniTableField field = {2, UPB_SIZE(4, 24), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return (google_protobuf_FieldDescriptorProto**)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); + return (google_protobuf_FieldDescriptorProto**)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg), + &field, size, arena); } UPB_INLINE struct google_protobuf_FieldDescriptorProto* google_protobuf_DescriptorProto_add_field(google_protobuf_DescriptorProto* msg, upb_Arena* arena) { upb_MiniTableField field = {2, UPB_SIZE(4, 24), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray( + UPB_UPCAST(msg), &field, arena); if (!arr || !_upb_Array_ResizeUninitialized( arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; @@ -1219,7 +1248,7 @@ UPB_INLINE struct google_protobuf_FieldDescriptorProto* google_protobuf_Descript } UPB_INLINE google_protobuf_DescriptorProto** google_protobuf_DescriptorProto_mutable_nested_type(google_protobuf_DescriptorProto* msg, size_t* size) { upb_MiniTableField field = {3, UPB_SIZE(8, 32), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetMutableArray(msg, &field); + upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_DescriptorProto**)_upb_array_ptr(arr); @@ -1230,11 +1259,13 @@ UPB_INLINE google_protobuf_DescriptorProto** google_protobuf_DescriptorProto_mut } UPB_INLINE google_protobuf_DescriptorProto** google_protobuf_DescriptorProto_resize_nested_type(google_protobuf_DescriptorProto* msg, size_t size, upb_Arena* arena) { upb_MiniTableField field = {3, UPB_SIZE(8, 32), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return (google_protobuf_DescriptorProto**)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); + return (google_protobuf_DescriptorProto**)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg), + &field, size, arena); } UPB_INLINE struct google_protobuf_DescriptorProto* google_protobuf_DescriptorProto_add_nested_type(google_protobuf_DescriptorProto* msg, upb_Arena* arena) { upb_MiniTableField field = {3, UPB_SIZE(8, 32), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray( + UPB_UPCAST(msg), &field, arena); if (!arr || !_upb_Array_ResizeUninitialized( arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; @@ -1247,7 +1278,7 @@ UPB_INLINE struct google_protobuf_DescriptorProto* google_protobuf_DescriptorPro } UPB_INLINE google_protobuf_EnumDescriptorProto** google_protobuf_DescriptorProto_mutable_enum_type(google_protobuf_DescriptorProto* msg, size_t* size) { upb_MiniTableField field = {4, UPB_SIZE(12, 40), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetMutableArray(msg, &field); + upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_EnumDescriptorProto**)_upb_array_ptr(arr); @@ -1258,11 +1289,13 @@ UPB_INLINE google_protobuf_EnumDescriptorProto** google_protobuf_DescriptorProto } UPB_INLINE google_protobuf_EnumDescriptorProto** google_protobuf_DescriptorProto_resize_enum_type(google_protobuf_DescriptorProto* msg, size_t size, upb_Arena* arena) { upb_MiniTableField field = {4, UPB_SIZE(12, 40), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return (google_protobuf_EnumDescriptorProto**)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); + return (google_protobuf_EnumDescriptorProto**)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg), + &field, size, arena); } UPB_INLINE struct google_protobuf_EnumDescriptorProto* google_protobuf_DescriptorProto_add_enum_type(google_protobuf_DescriptorProto* msg, upb_Arena* arena) { upb_MiniTableField field = {4, UPB_SIZE(12, 40), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray( + UPB_UPCAST(msg), &field, arena); if (!arr || !_upb_Array_ResizeUninitialized( arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; @@ -1275,7 +1308,7 @@ UPB_INLINE struct google_protobuf_EnumDescriptorProto* google_protobuf_Descripto } UPB_INLINE google_protobuf_DescriptorProto_ExtensionRange** google_protobuf_DescriptorProto_mutable_extension_range(google_protobuf_DescriptorProto* msg, size_t* size) { upb_MiniTableField field = {5, UPB_SIZE(16, 48), 0, 3, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetMutableArray(msg, &field); + upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_DescriptorProto_ExtensionRange**)_upb_array_ptr(arr); @@ -1286,11 +1319,13 @@ UPB_INLINE google_protobuf_DescriptorProto_ExtensionRange** google_protobuf_Desc } UPB_INLINE google_protobuf_DescriptorProto_ExtensionRange** google_protobuf_DescriptorProto_resize_extension_range(google_protobuf_DescriptorProto* msg, size_t size, upb_Arena* arena) { upb_MiniTableField field = {5, UPB_SIZE(16, 48), 0, 3, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return (google_protobuf_DescriptorProto_ExtensionRange**)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); + return (google_protobuf_DescriptorProto_ExtensionRange**)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg), + &field, size, arena); } UPB_INLINE struct google_protobuf_DescriptorProto_ExtensionRange* google_protobuf_DescriptorProto_add_extension_range(google_protobuf_DescriptorProto* msg, upb_Arena* arena) { upb_MiniTableField field = {5, UPB_SIZE(16, 48), 0, 3, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray( + UPB_UPCAST(msg), &field, arena); if (!arr || !_upb_Array_ResizeUninitialized( arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; @@ -1303,7 +1338,7 @@ UPB_INLINE struct google_protobuf_DescriptorProto_ExtensionRange* google_protobu } UPB_INLINE google_protobuf_FieldDescriptorProto** google_protobuf_DescriptorProto_mutable_extension(google_protobuf_DescriptorProto* msg, size_t* size) { upb_MiniTableField field = {6, UPB_SIZE(20, 56), 0, 4, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetMutableArray(msg, &field); + upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_FieldDescriptorProto**)_upb_array_ptr(arr); @@ -1314,11 +1349,13 @@ UPB_INLINE google_protobuf_FieldDescriptorProto** google_protobuf_DescriptorProt } UPB_INLINE google_protobuf_FieldDescriptorProto** google_protobuf_DescriptorProto_resize_extension(google_protobuf_DescriptorProto* msg, size_t size, upb_Arena* arena) { upb_MiniTableField field = {6, UPB_SIZE(20, 56), 0, 4, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return (google_protobuf_FieldDescriptorProto**)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); + return (google_protobuf_FieldDescriptorProto**)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg), + &field, size, arena); } UPB_INLINE struct google_protobuf_FieldDescriptorProto* google_protobuf_DescriptorProto_add_extension(google_protobuf_DescriptorProto* msg, upb_Arena* arena) { upb_MiniTableField field = {6, UPB_SIZE(20, 56), 0, 4, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray( + UPB_UPCAST(msg), &field, arena); if (!arr || !_upb_Array_ResizeUninitialized( arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; @@ -1331,7 +1368,7 @@ UPB_INLINE struct google_protobuf_FieldDescriptorProto* google_protobuf_Descript } UPB_INLINE void google_protobuf_DescriptorProto_set_options(google_protobuf_DescriptorProto *msg, google_protobuf_MessageOptions* value) { const upb_MiniTableField field = {7, UPB_SIZE(24, 64), 2, 5, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE struct google_protobuf_MessageOptions* google_protobuf_DescriptorProto_mutable_options(google_protobuf_DescriptorProto* msg, upb_Arena* arena) { struct google_protobuf_MessageOptions* sub = (struct google_protobuf_MessageOptions*)google_protobuf_DescriptorProto_options(msg); @@ -1343,7 +1380,7 @@ UPB_INLINE struct google_protobuf_MessageOptions* google_protobuf_DescriptorProt } UPB_INLINE google_protobuf_OneofDescriptorProto** google_protobuf_DescriptorProto_mutable_oneof_decl(google_protobuf_DescriptorProto* msg, size_t* size) { upb_MiniTableField field = {8, UPB_SIZE(28, 72), 0, 6, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetMutableArray(msg, &field); + upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_OneofDescriptorProto**)_upb_array_ptr(arr); @@ -1354,11 +1391,13 @@ UPB_INLINE google_protobuf_OneofDescriptorProto** google_protobuf_DescriptorProt } UPB_INLINE google_protobuf_OneofDescriptorProto** google_protobuf_DescriptorProto_resize_oneof_decl(google_protobuf_DescriptorProto* msg, size_t size, upb_Arena* arena) { upb_MiniTableField field = {8, UPB_SIZE(28, 72), 0, 6, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return (google_protobuf_OneofDescriptorProto**)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); + return (google_protobuf_OneofDescriptorProto**)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg), + &field, size, arena); } UPB_INLINE struct google_protobuf_OneofDescriptorProto* google_protobuf_DescriptorProto_add_oneof_decl(google_protobuf_DescriptorProto* msg, upb_Arena* arena) { upb_MiniTableField field = {8, UPB_SIZE(28, 72), 0, 6, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray( + UPB_UPCAST(msg), &field, arena); if (!arr || !_upb_Array_ResizeUninitialized( arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; @@ -1371,7 +1410,7 @@ UPB_INLINE struct google_protobuf_OneofDescriptorProto* google_protobuf_Descript } UPB_INLINE google_protobuf_DescriptorProto_ReservedRange** google_protobuf_DescriptorProto_mutable_reserved_range(google_protobuf_DescriptorProto* msg, size_t* size) { upb_MiniTableField field = {9, UPB_SIZE(32, 80), 0, 7, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetMutableArray(msg, &field); + upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_DescriptorProto_ReservedRange**)_upb_array_ptr(arr); @@ -1382,11 +1421,13 @@ UPB_INLINE google_protobuf_DescriptorProto_ReservedRange** google_protobuf_Descr } UPB_INLINE google_protobuf_DescriptorProto_ReservedRange** google_protobuf_DescriptorProto_resize_reserved_range(google_protobuf_DescriptorProto* msg, size_t size, upb_Arena* arena) { upb_MiniTableField field = {9, UPB_SIZE(32, 80), 0, 7, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return (google_protobuf_DescriptorProto_ReservedRange**)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); + return (google_protobuf_DescriptorProto_ReservedRange**)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg), + &field, size, arena); } UPB_INLINE struct google_protobuf_DescriptorProto_ReservedRange* google_protobuf_DescriptorProto_add_reserved_range(google_protobuf_DescriptorProto* msg, upb_Arena* arena) { upb_MiniTableField field = {9, UPB_SIZE(32, 80), 0, 7, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray( + UPB_UPCAST(msg), &field, arena); if (!arr || !_upb_Array_ResizeUninitialized( arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; @@ -1399,7 +1440,7 @@ UPB_INLINE struct google_protobuf_DescriptorProto_ReservedRange* google_protobuf } UPB_INLINE upb_StringView* google_protobuf_DescriptorProto_mutable_reserved_name(google_protobuf_DescriptorProto* msg, size_t* size) { upb_MiniTableField field = {10, UPB_SIZE(36, 88), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetMutableArray(msg, &field); + upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (upb_StringView*)_upb_array_ptr(arr); @@ -1410,11 +1451,13 @@ UPB_INLINE upb_StringView* google_protobuf_DescriptorProto_mutable_reserved_name } UPB_INLINE upb_StringView* google_protobuf_DescriptorProto_resize_reserved_name(google_protobuf_DescriptorProto* msg, size_t size, upb_Arena* arena) { upb_MiniTableField field = {10, UPB_SIZE(36, 88), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return (upb_StringView*)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); + return (upb_StringView*)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg), + &field, size, arena); } UPB_INLINE bool google_protobuf_DescriptorProto_add_reserved_name(google_protobuf_DescriptorProto* msg, upb_StringView val, upb_Arena* arena) { upb_MiniTableField field = {10, UPB_SIZE(36, 88), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray( + UPB_UPCAST(msg), &field, arena); if (!arr || !_upb_Array_ResizeUninitialized( arr, arr->UPB_PRIVATE(size) + 1, arena)) { return false; @@ -1432,7 +1475,8 @@ UPB_INLINE google_protobuf_DescriptorProto_ExtensionRange* google_protobuf_Descr UPB_INLINE google_protobuf_DescriptorProto_ExtensionRange* google_protobuf_DescriptorProto_ExtensionRange_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_DescriptorProto_ExtensionRange* ret = google_protobuf_DescriptorProto_ExtensionRange_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__DescriptorProto__ExtensionRange_msg_init, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__DescriptorProto__ExtensionRange_msg_init, NULL, 0, arena) != + kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -1442,80 +1486,83 @@ UPB_INLINE google_protobuf_DescriptorProto_ExtensionRange* google_protobuf_Descr int options, upb_Arena* arena) { google_protobuf_DescriptorProto_ExtensionRange* ret = google_protobuf_DescriptorProto_ExtensionRange_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__DescriptorProto__ExtensionRange_msg_init, extreg, options, arena) != - kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__DescriptorProto__ExtensionRange_msg_init, extreg, options, + arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_DescriptorProto_ExtensionRange_serialize(const google_protobuf_DescriptorProto_ExtensionRange* msg, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__DescriptorProto__ExtensionRange_msg_init, 0, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__DescriptorProto__ExtensionRange_msg_init, 0, arena, &ptr, len); return ptr; } UPB_INLINE char* google_protobuf_DescriptorProto_ExtensionRange_serialize_ex(const google_protobuf_DescriptorProto_ExtensionRange* msg, int options, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__DescriptorProto__ExtensionRange_msg_init, options, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__DescriptorProto__ExtensionRange_msg_init, options, arena, &ptr, len); return ptr; } UPB_INLINE void google_protobuf_DescriptorProto_ExtensionRange_clear_start(google_protobuf_DescriptorProto_ExtensionRange* msg) { const upb_MiniTableField field = {1, 4, 1, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_DescriptorProto_ExtensionRange_start(const google_protobuf_DescriptorProto_ExtensionRange* msg) { int32_t default_val = (int32_t)0; int32_t ret; const upb_MiniTableField field = {1, 4, 1, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_DescriptorProto_ExtensionRange_has_start(const google_protobuf_DescriptorProto_ExtensionRange* msg) { const upb_MiniTableField field = {1, 4, 1, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_DescriptorProto_ExtensionRange_clear_end(google_protobuf_DescriptorProto_ExtensionRange* msg) { const upb_MiniTableField field = {2, 8, 2, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_DescriptorProto_ExtensionRange_end(const google_protobuf_DescriptorProto_ExtensionRange* msg) { int32_t default_val = (int32_t)0; int32_t ret; const upb_MiniTableField field = {2, 8, 2, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_DescriptorProto_ExtensionRange_has_end(const google_protobuf_DescriptorProto_ExtensionRange* msg) { const upb_MiniTableField field = {2, 8, 2, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_DescriptorProto_ExtensionRange_clear_options(google_protobuf_DescriptorProto_ExtensionRange* msg) { const upb_MiniTableField field = {3, UPB_SIZE(12, 16), 3, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_ExtensionRangeOptions* google_protobuf_DescriptorProto_ExtensionRange_options(const google_protobuf_DescriptorProto_ExtensionRange* msg) { const google_protobuf_ExtensionRangeOptions* default_val = NULL; const google_protobuf_ExtensionRangeOptions* ret; const upb_MiniTableField field = {3, UPB_SIZE(12, 16), 3, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_DescriptorProto_ExtensionRange_has_options(const google_protobuf_DescriptorProto_ExtensionRange* msg) { const upb_MiniTableField field = {3, UPB_SIZE(12, 16), 3, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_DescriptorProto_ExtensionRange_set_start(google_protobuf_DescriptorProto_ExtensionRange *msg, int32_t value) { const upb_MiniTableField field = {1, 4, 1, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_DescriptorProto_ExtensionRange_set_end(google_protobuf_DescriptorProto_ExtensionRange *msg, int32_t value) { const upb_MiniTableField field = {2, 8, 2, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_DescriptorProto_ExtensionRange_set_options(google_protobuf_DescriptorProto_ExtensionRange *msg, google_protobuf_ExtensionRangeOptions* value) { const upb_MiniTableField field = {3, UPB_SIZE(12, 16), 3, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE struct google_protobuf_ExtensionRangeOptions* google_protobuf_DescriptorProto_ExtensionRange_mutable_options(google_protobuf_DescriptorProto_ExtensionRange* msg, upb_Arena* arena) { struct google_protobuf_ExtensionRangeOptions* sub = (struct google_protobuf_ExtensionRangeOptions*)google_protobuf_DescriptorProto_ExtensionRange_options(msg); @@ -1534,7 +1581,8 @@ UPB_INLINE google_protobuf_DescriptorProto_ReservedRange* google_protobuf_Descri UPB_INLINE google_protobuf_DescriptorProto_ReservedRange* google_protobuf_DescriptorProto_ReservedRange_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_DescriptorProto_ReservedRange* ret = google_protobuf_DescriptorProto_ReservedRange_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__DescriptorProto__ReservedRange_msg_init, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__DescriptorProto__ReservedRange_msg_init, NULL, 0, arena) != + kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -1544,61 +1592,63 @@ UPB_INLINE google_protobuf_DescriptorProto_ReservedRange* google_protobuf_Descri int options, upb_Arena* arena) { google_protobuf_DescriptorProto_ReservedRange* ret = google_protobuf_DescriptorProto_ReservedRange_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__DescriptorProto__ReservedRange_msg_init, extreg, options, arena) != - kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__DescriptorProto__ReservedRange_msg_init, extreg, options, + arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_DescriptorProto_ReservedRange_serialize(const google_protobuf_DescriptorProto_ReservedRange* msg, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__DescriptorProto__ReservedRange_msg_init, 0, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__DescriptorProto__ReservedRange_msg_init, 0, arena, &ptr, len); return ptr; } UPB_INLINE char* google_protobuf_DescriptorProto_ReservedRange_serialize_ex(const google_protobuf_DescriptorProto_ReservedRange* msg, int options, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__DescriptorProto__ReservedRange_msg_init, options, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__DescriptorProto__ReservedRange_msg_init, options, arena, &ptr, len); return ptr; } UPB_INLINE void google_protobuf_DescriptorProto_ReservedRange_clear_start(google_protobuf_DescriptorProto_ReservedRange* msg) { const upb_MiniTableField field = {1, 4, 1, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_DescriptorProto_ReservedRange_start(const google_protobuf_DescriptorProto_ReservedRange* msg) { int32_t default_val = (int32_t)0; int32_t ret; const upb_MiniTableField field = {1, 4, 1, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_DescriptorProto_ReservedRange_has_start(const google_protobuf_DescriptorProto_ReservedRange* msg) { const upb_MiniTableField field = {1, 4, 1, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_DescriptorProto_ReservedRange_clear_end(google_protobuf_DescriptorProto_ReservedRange* msg) { const upb_MiniTableField field = {2, 8, 2, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_DescriptorProto_ReservedRange_end(const google_protobuf_DescriptorProto_ReservedRange* msg) { int32_t default_val = (int32_t)0; int32_t ret; const upb_MiniTableField field = {2, 8, 2, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_DescriptorProto_ReservedRange_has_end(const google_protobuf_DescriptorProto_ReservedRange* msg) { const upb_MiniTableField field = {2, 8, 2, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_DescriptorProto_ReservedRange_set_start(google_protobuf_DescriptorProto_ReservedRange *msg, int32_t value) { const upb_MiniTableField field = {1, 4, 1, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_DescriptorProto_ReservedRange_set_end(google_protobuf_DescriptorProto_ReservedRange *msg, int32_t value) { const upb_MiniTableField field = {2, 8, 2, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } /* google.protobuf.ExtensionRangeOptions */ @@ -1609,7 +1659,8 @@ UPB_INLINE google_protobuf_ExtensionRangeOptions* google_protobuf_ExtensionRange UPB_INLINE google_protobuf_ExtensionRangeOptions* google_protobuf_ExtensionRangeOptions_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_ExtensionRangeOptions* ret = google_protobuf_ExtensionRangeOptions_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__ExtensionRangeOptions_msg_init, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__ExtensionRangeOptions_msg_init, NULL, 0, arena) != + kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -1619,30 +1670,30 @@ UPB_INLINE google_protobuf_ExtensionRangeOptions* google_protobuf_ExtensionRange int options, upb_Arena* arena) { google_protobuf_ExtensionRangeOptions* ret = google_protobuf_ExtensionRangeOptions_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__ExtensionRangeOptions_msg_init, extreg, options, arena) != - kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__ExtensionRangeOptions_msg_init, extreg, options, + arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_ExtensionRangeOptions_serialize(const google_protobuf_ExtensionRangeOptions* msg, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__ExtensionRangeOptions_msg_init, 0, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__ExtensionRangeOptions_msg_init, 0, arena, &ptr, len); return ptr; } UPB_INLINE char* google_protobuf_ExtensionRangeOptions_serialize_ex(const google_protobuf_ExtensionRangeOptions* msg, int options, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__ExtensionRangeOptions_msg_init, options, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__ExtensionRangeOptions_msg_init, options, arena, &ptr, len); return ptr; } UPB_INLINE void google_protobuf_ExtensionRangeOptions_clear_declaration(google_protobuf_ExtensionRangeOptions* msg) { const upb_MiniTableField field = {2, UPB_SIZE(4, 8), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_ExtensionRangeOptions_Declaration* const* google_protobuf_ExtensionRangeOptions_declaration(const google_protobuf_ExtensionRangeOptions* msg, size_t* size) { const upb_MiniTableField field = {2, UPB_SIZE(4, 8), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_ExtensionRangeOptions_Declaration* const*)_upb_array_constptr(arr); @@ -1653,16 +1704,16 @@ UPB_INLINE const google_protobuf_ExtensionRangeOptions_Declaration* const* googl } UPB_INLINE const upb_Array* _google_protobuf_ExtensionRangeOptions_declaration_upb_array(const google_protobuf_ExtensionRangeOptions* msg, size_t* size) { const upb_MiniTableField field = {2, UPB_SIZE(4, 8), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } -UPB_INLINE upb_Array* _google_protobuf_ExtensionRangeOptions_declaration_mutable_upb_array(const google_protobuf_ExtensionRangeOptions* msg, size_t* size, upb_Arena* arena) { +UPB_INLINE upb_Array* _google_protobuf_ExtensionRangeOptions_declaration_mutable_upb_array(google_protobuf_ExtensionRangeOptions* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = {2, UPB_SIZE(4, 8), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - (upb_Message*)msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), + &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -1670,41 +1721,43 @@ UPB_INLINE upb_Array* _google_protobuf_ExtensionRangeOptions_declaration_mutable } UPB_INLINE void google_protobuf_ExtensionRangeOptions_clear_verification(google_protobuf_ExtensionRangeOptions* msg) { const upb_MiniTableField field = {3, UPB_SIZE(8, 4), 1, 3, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_ExtensionRangeOptions_verification(const google_protobuf_ExtensionRangeOptions* msg) { int32_t default_val = 1; int32_t ret; const upb_MiniTableField field = {3, UPB_SIZE(8, 4), 1, 3, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_ExtensionRangeOptions_has_verification(const google_protobuf_ExtensionRangeOptions* msg) { const upb_MiniTableField field = {3, UPB_SIZE(8, 4), 1, 3, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_ExtensionRangeOptions_clear_features(google_protobuf_ExtensionRangeOptions* msg) { const upb_MiniTableField field = {50, UPB_SIZE(12, 16), 2, 1, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_FeatureSet* google_protobuf_ExtensionRangeOptions_features(const google_protobuf_ExtensionRangeOptions* msg) { const google_protobuf_FeatureSet* default_val = NULL; const google_protobuf_FeatureSet* ret; const upb_MiniTableField field = {50, UPB_SIZE(12, 16), 2, 1, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_ExtensionRangeOptions_has_features(const google_protobuf_ExtensionRangeOptions* msg) { const upb_MiniTableField field = {50, UPB_SIZE(12, 16), 2, 1, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_ExtensionRangeOptions_clear_uninterpreted_option(google_protobuf_ExtensionRangeOptions* msg) { const upb_MiniTableField field = {999, UPB_SIZE(16, 24), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_ExtensionRangeOptions_uninterpreted_option(const google_protobuf_ExtensionRangeOptions* msg, size_t* size) { const upb_MiniTableField field = {999, UPB_SIZE(16, 24), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_UninterpretedOption* const*)_upb_array_constptr(arr); @@ -1715,16 +1768,16 @@ UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_Ext } UPB_INLINE const upb_Array* _google_protobuf_ExtensionRangeOptions_uninterpreted_option_upb_array(const google_protobuf_ExtensionRangeOptions* msg, size_t* size) { const upb_MiniTableField field = {999, UPB_SIZE(16, 24), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } -UPB_INLINE upb_Array* _google_protobuf_ExtensionRangeOptions_uninterpreted_option_mutable_upb_array(const google_protobuf_ExtensionRangeOptions* msg, size_t* size, upb_Arena* arena) { +UPB_INLINE upb_Array* _google_protobuf_ExtensionRangeOptions_uninterpreted_option_mutable_upb_array(google_protobuf_ExtensionRangeOptions* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = {999, UPB_SIZE(16, 24), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - (upb_Message*)msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), + &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -1733,7 +1786,7 @@ UPB_INLINE upb_Array* _google_protobuf_ExtensionRangeOptions_uninterpreted_optio UPB_INLINE google_protobuf_ExtensionRangeOptions_Declaration** google_protobuf_ExtensionRangeOptions_mutable_declaration(google_protobuf_ExtensionRangeOptions* msg, size_t* size) { upb_MiniTableField field = {2, UPB_SIZE(4, 8), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetMutableArray(msg, &field); + upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_ExtensionRangeOptions_Declaration**)_upb_array_ptr(arr); @@ -1744,11 +1797,13 @@ UPB_INLINE google_protobuf_ExtensionRangeOptions_Declaration** google_protobuf_E } UPB_INLINE google_protobuf_ExtensionRangeOptions_Declaration** google_protobuf_ExtensionRangeOptions_resize_declaration(google_protobuf_ExtensionRangeOptions* msg, size_t size, upb_Arena* arena) { upb_MiniTableField field = {2, UPB_SIZE(4, 8), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return (google_protobuf_ExtensionRangeOptions_Declaration**)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); + return (google_protobuf_ExtensionRangeOptions_Declaration**)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg), + &field, size, arena); } UPB_INLINE struct google_protobuf_ExtensionRangeOptions_Declaration* google_protobuf_ExtensionRangeOptions_add_declaration(google_protobuf_ExtensionRangeOptions* msg, upb_Arena* arena) { upb_MiniTableField field = {2, UPB_SIZE(4, 8), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray( + UPB_UPCAST(msg), &field, arena); if (!arr || !_upb_Array_ResizeUninitialized( arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; @@ -1761,11 +1816,11 @@ UPB_INLINE struct google_protobuf_ExtensionRangeOptions_Declaration* google_prot } UPB_INLINE void google_protobuf_ExtensionRangeOptions_set_verification(google_protobuf_ExtensionRangeOptions *msg, int32_t value) { const upb_MiniTableField field = {3, UPB_SIZE(8, 4), 1, 3, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_ExtensionRangeOptions_set_features(google_protobuf_ExtensionRangeOptions *msg, google_protobuf_FeatureSet* value) { const upb_MiniTableField field = {50, UPB_SIZE(12, 16), 2, 1, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE struct google_protobuf_FeatureSet* google_protobuf_ExtensionRangeOptions_mutable_features(google_protobuf_ExtensionRangeOptions* msg, upb_Arena* arena) { struct google_protobuf_FeatureSet* sub = (struct google_protobuf_FeatureSet*)google_protobuf_ExtensionRangeOptions_features(msg); @@ -1777,7 +1832,7 @@ UPB_INLINE struct google_protobuf_FeatureSet* google_protobuf_ExtensionRangeOpti } UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_ExtensionRangeOptions_mutable_uninterpreted_option(google_protobuf_ExtensionRangeOptions* msg, size_t* size) { upb_MiniTableField field = {999, UPB_SIZE(16, 24), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetMutableArray(msg, &field); + upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_UninterpretedOption**)_upb_array_ptr(arr); @@ -1788,11 +1843,13 @@ UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_ExtensionRangeO } UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_ExtensionRangeOptions_resize_uninterpreted_option(google_protobuf_ExtensionRangeOptions* msg, size_t size, upb_Arena* arena) { upb_MiniTableField field = {999, UPB_SIZE(16, 24), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return (google_protobuf_UninterpretedOption**)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); + return (google_protobuf_UninterpretedOption**)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg), + &field, size, arena); } UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_ExtensionRangeOptions_add_uninterpreted_option(google_protobuf_ExtensionRangeOptions* msg, upb_Arena* arena) { upb_MiniTableField field = {999, UPB_SIZE(16, 24), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray( + UPB_UPCAST(msg), &field, arena); if (!arr || !_upb_Array_ResizeUninitialized( arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; @@ -1812,7 +1869,8 @@ UPB_INLINE google_protobuf_ExtensionRangeOptions_Declaration* google_protobuf_Ex UPB_INLINE google_protobuf_ExtensionRangeOptions_Declaration* google_protobuf_ExtensionRangeOptions_Declaration_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_ExtensionRangeOptions_Declaration* ret = google_protobuf_ExtensionRangeOptions_Declaration_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__ExtensionRangeOptions__Declaration_msg_init, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__ExtensionRangeOptions__Declaration_msg_init, NULL, 0, arena) != + kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -1822,118 +1880,123 @@ UPB_INLINE google_protobuf_ExtensionRangeOptions_Declaration* google_protobuf_Ex int options, upb_Arena* arena) { google_protobuf_ExtensionRangeOptions_Declaration* ret = google_protobuf_ExtensionRangeOptions_Declaration_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__ExtensionRangeOptions__Declaration_msg_init, extreg, options, arena) != - kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__ExtensionRangeOptions__Declaration_msg_init, extreg, options, + arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_ExtensionRangeOptions_Declaration_serialize(const google_protobuf_ExtensionRangeOptions_Declaration* msg, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__ExtensionRangeOptions__Declaration_msg_init, 0, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__ExtensionRangeOptions__Declaration_msg_init, 0, arena, &ptr, len); return ptr; } UPB_INLINE char* google_protobuf_ExtensionRangeOptions_Declaration_serialize_ex(const google_protobuf_ExtensionRangeOptions_Declaration* msg, int options, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__ExtensionRangeOptions__Declaration_msg_init, options, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__ExtensionRangeOptions__Declaration_msg_init, options, arena, &ptr, len); return ptr; } UPB_INLINE void google_protobuf_ExtensionRangeOptions_Declaration_clear_number(google_protobuf_ExtensionRangeOptions_Declaration* msg) { const upb_MiniTableField field = {1, 4, 1, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_ExtensionRangeOptions_Declaration_number(const google_protobuf_ExtensionRangeOptions_Declaration* msg) { int32_t default_val = (int32_t)0; int32_t ret; const upb_MiniTableField field = {1, 4, 1, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_ExtensionRangeOptions_Declaration_has_number(const google_protobuf_ExtensionRangeOptions_Declaration* msg) { const upb_MiniTableField field = {1, 4, 1, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_ExtensionRangeOptions_Declaration_clear_full_name(google_protobuf_ExtensionRangeOptions_Declaration* msg) { const upb_MiniTableField field = {2, UPB_SIZE(12, 16), 2, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_ExtensionRangeOptions_Declaration_full_name(const google_protobuf_ExtensionRangeOptions_Declaration* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; const upb_MiniTableField field = {2, UPB_SIZE(12, 16), 2, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_ExtensionRangeOptions_Declaration_has_full_name(const google_protobuf_ExtensionRangeOptions_Declaration* msg) { const upb_MiniTableField field = {2, UPB_SIZE(12, 16), 2, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_ExtensionRangeOptions_Declaration_clear_type(google_protobuf_ExtensionRangeOptions_Declaration* msg) { const upb_MiniTableField field = {3, UPB_SIZE(20, 32), 3, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_ExtensionRangeOptions_Declaration_type(const google_protobuf_ExtensionRangeOptions_Declaration* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; const upb_MiniTableField field = {3, UPB_SIZE(20, 32), 3, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_ExtensionRangeOptions_Declaration_has_type(const google_protobuf_ExtensionRangeOptions_Declaration* msg) { const upb_MiniTableField field = {3, UPB_SIZE(20, 32), 3, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_ExtensionRangeOptions_Declaration_clear_reserved(google_protobuf_ExtensionRangeOptions_Declaration* msg) { const upb_MiniTableField field = {5, 8, 4, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_ExtensionRangeOptions_Declaration_reserved(const google_protobuf_ExtensionRangeOptions_Declaration* msg) { bool default_val = false; bool ret; const upb_MiniTableField field = {5, 8, 4, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_ExtensionRangeOptions_Declaration_has_reserved(const google_protobuf_ExtensionRangeOptions_Declaration* msg) { const upb_MiniTableField field = {5, 8, 4, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_ExtensionRangeOptions_Declaration_clear_repeated(google_protobuf_ExtensionRangeOptions_Declaration* msg) { const upb_MiniTableField field = {6, 9, 5, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_ExtensionRangeOptions_Declaration_repeated(const google_protobuf_ExtensionRangeOptions_Declaration* msg) { bool default_val = false; bool ret; const upb_MiniTableField field = {6, 9, 5, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_ExtensionRangeOptions_Declaration_has_repeated(const google_protobuf_ExtensionRangeOptions_Declaration* msg) { const upb_MiniTableField field = {6, 9, 5, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_ExtensionRangeOptions_Declaration_set_number(google_protobuf_ExtensionRangeOptions_Declaration *msg, int32_t value) { const upb_MiniTableField field = {1, 4, 1, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_ExtensionRangeOptions_Declaration_set_full_name(google_protobuf_ExtensionRangeOptions_Declaration *msg, upb_StringView value) { const upb_MiniTableField field = {2, UPB_SIZE(12, 16), 2, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_ExtensionRangeOptions_Declaration_set_type(google_protobuf_ExtensionRangeOptions_Declaration *msg, upb_StringView value) { const upb_MiniTableField field = {3, UPB_SIZE(20, 32), 3, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_ExtensionRangeOptions_Declaration_set_reserved(google_protobuf_ExtensionRangeOptions_Declaration *msg, bool value) { const upb_MiniTableField field = {5, 8, 4, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_ExtensionRangeOptions_Declaration_set_repeated(google_protobuf_ExtensionRangeOptions_Declaration *msg, bool value) { const upb_MiniTableField field = {6, 9, 5, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } /* google.protobuf.FieldDescriptorProto */ @@ -1944,7 +2007,8 @@ UPB_INLINE google_protobuf_FieldDescriptorProto* google_protobuf_FieldDescriptor UPB_INLINE google_protobuf_FieldDescriptorProto* google_protobuf_FieldDescriptorProto_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_FieldDescriptorProto* ret = google_protobuf_FieldDescriptorProto_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__FieldDescriptorProto_msg_init, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__FieldDescriptorProto_msg_init, NULL, 0, arena) != + kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -1954,220 +2018,231 @@ UPB_INLINE google_protobuf_FieldDescriptorProto* google_protobuf_FieldDescriptor int options, upb_Arena* arena) { google_protobuf_FieldDescriptorProto* ret = google_protobuf_FieldDescriptorProto_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__FieldDescriptorProto_msg_init, extreg, options, arena) != - kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__FieldDescriptorProto_msg_init, extreg, options, + arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_FieldDescriptorProto_serialize(const google_protobuf_FieldDescriptorProto* msg, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__FieldDescriptorProto_msg_init, 0, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__FieldDescriptorProto_msg_init, 0, arena, &ptr, len); return ptr; } UPB_INLINE char* google_protobuf_FieldDescriptorProto_serialize_ex(const google_protobuf_FieldDescriptorProto* msg, int options, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__FieldDescriptorProto_msg_init, options, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__FieldDescriptorProto_msg_init, options, arena, &ptr, len); return ptr; } UPB_INLINE void google_protobuf_FieldDescriptorProto_clear_name(google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = {1, UPB_SIZE(28, 24), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_FieldDescriptorProto_name(const google_protobuf_FieldDescriptorProto* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; const upb_MiniTableField field = {1, UPB_SIZE(28, 24), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_name(const google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = {1, UPB_SIZE(28, 24), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldDescriptorProto_clear_extendee(google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = {2, UPB_SIZE(36, 40), 2, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_FieldDescriptorProto_extendee(const google_protobuf_FieldDescriptorProto* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; const upb_MiniTableField field = {2, UPB_SIZE(36, 40), 2, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_extendee(const google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = {2, UPB_SIZE(36, 40), 2, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldDescriptorProto_clear_number(google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = {3, 4, 3, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_FieldDescriptorProto_number(const google_protobuf_FieldDescriptorProto* msg) { int32_t default_val = (int32_t)0; int32_t ret; const upb_MiniTableField field = {3, 4, 3, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_number(const google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = {3, 4, 3, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldDescriptorProto_clear_label(google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = {4, 8, 4, 1, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_FieldDescriptorProto_label(const google_protobuf_FieldDescriptorProto* msg) { int32_t default_val = 1; int32_t ret; const upb_MiniTableField field = {4, 8, 4, 1, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_label(const google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = {4, 8, 4, 1, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldDescriptorProto_clear_type(google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = {5, 12, 5, 2, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_FieldDescriptorProto_type(const google_protobuf_FieldDescriptorProto* msg) { int32_t default_val = 1; int32_t ret; const upb_MiniTableField field = {5, 12, 5, 2, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_type(const google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = {5, 12, 5, 2, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldDescriptorProto_clear_type_name(google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = {6, UPB_SIZE(44, 56), 6, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_FieldDescriptorProto_type_name(const google_protobuf_FieldDescriptorProto* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; const upb_MiniTableField field = {6, UPB_SIZE(44, 56), 6, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_type_name(const google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = {6, UPB_SIZE(44, 56), 6, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldDescriptorProto_clear_default_value(google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = {7, UPB_SIZE(52, 72), 7, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_FieldDescriptorProto_default_value(const google_protobuf_FieldDescriptorProto* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; const upb_MiniTableField field = {7, UPB_SIZE(52, 72), 7, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_default_value(const google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = {7, UPB_SIZE(52, 72), 7, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldDescriptorProto_clear_options(google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = {8, UPB_SIZE(16, 88), 8, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_FieldOptions* google_protobuf_FieldDescriptorProto_options(const google_protobuf_FieldDescriptorProto* msg) { const google_protobuf_FieldOptions* default_val = NULL; const google_protobuf_FieldOptions* ret; const upb_MiniTableField field = {8, UPB_SIZE(16, 88), 8, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_options(const google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = {8, UPB_SIZE(16, 88), 8, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldDescriptorProto_clear_oneof_index(google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = {9, UPB_SIZE(20, 16), 9, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_FieldDescriptorProto_oneof_index(const google_protobuf_FieldDescriptorProto* msg) { int32_t default_val = (int32_t)0; int32_t ret; const upb_MiniTableField field = {9, UPB_SIZE(20, 16), 9, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_oneof_index(const google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = {9, UPB_SIZE(20, 16), 9, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldDescriptorProto_clear_json_name(google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = {10, UPB_SIZE(60, 96), 10, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_FieldDescriptorProto_json_name(const google_protobuf_FieldDescriptorProto* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; const upb_MiniTableField field = {10, UPB_SIZE(60, 96), 10, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_json_name(const google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = {10, UPB_SIZE(60, 96), 10, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldDescriptorProto_clear_proto3_optional(google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = {17, UPB_SIZE(24, 20), 11, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_FieldDescriptorProto_proto3_optional(const google_protobuf_FieldDescriptorProto* msg) { bool default_val = false; bool ret; const upb_MiniTableField field = {17, UPB_SIZE(24, 20), 11, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_proto3_optional(const google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = {17, UPB_SIZE(24, 20), 11, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldDescriptorProto_set_name(google_protobuf_FieldDescriptorProto *msg, upb_StringView value) { const upb_MiniTableField field = {1, UPB_SIZE(28, 24), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FieldDescriptorProto_set_extendee(google_protobuf_FieldDescriptorProto *msg, upb_StringView value) { const upb_MiniTableField field = {2, UPB_SIZE(36, 40), 2, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FieldDescriptorProto_set_number(google_protobuf_FieldDescriptorProto *msg, int32_t value) { const upb_MiniTableField field = {3, 4, 3, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FieldDescriptorProto_set_label(google_protobuf_FieldDescriptorProto *msg, int32_t value) { const upb_MiniTableField field = {4, 8, 4, 1, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FieldDescriptorProto_set_type(google_protobuf_FieldDescriptorProto *msg, int32_t value) { const upb_MiniTableField field = {5, 12, 5, 2, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FieldDescriptorProto_set_type_name(google_protobuf_FieldDescriptorProto *msg, upb_StringView value) { const upb_MiniTableField field = {6, UPB_SIZE(44, 56), 6, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FieldDescriptorProto_set_default_value(google_protobuf_FieldDescriptorProto *msg, upb_StringView value) { const upb_MiniTableField field = {7, UPB_SIZE(52, 72), 7, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FieldDescriptorProto_set_options(google_protobuf_FieldDescriptorProto *msg, google_protobuf_FieldOptions* value) { const upb_MiniTableField field = {8, UPB_SIZE(16, 88), 8, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE struct google_protobuf_FieldOptions* google_protobuf_FieldDescriptorProto_mutable_options(google_protobuf_FieldDescriptorProto* msg, upb_Arena* arena) { struct google_protobuf_FieldOptions* sub = (struct google_protobuf_FieldOptions*)google_protobuf_FieldDescriptorProto_options(msg); @@ -2179,15 +2254,15 @@ UPB_INLINE struct google_protobuf_FieldOptions* google_protobuf_FieldDescriptorP } UPB_INLINE void google_protobuf_FieldDescriptorProto_set_oneof_index(google_protobuf_FieldDescriptorProto *msg, int32_t value) { const upb_MiniTableField field = {9, UPB_SIZE(20, 16), 9, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FieldDescriptorProto_set_json_name(google_protobuf_FieldDescriptorProto *msg, upb_StringView value) { const upb_MiniTableField field = {10, UPB_SIZE(60, 96), 10, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FieldDescriptorProto_set_proto3_optional(google_protobuf_FieldDescriptorProto *msg, bool value) { const upb_MiniTableField field = {17, UPB_SIZE(24, 20), 11, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } /* google.protobuf.OneofDescriptorProto */ @@ -2198,7 +2273,8 @@ UPB_INLINE google_protobuf_OneofDescriptorProto* google_protobuf_OneofDescriptor UPB_INLINE google_protobuf_OneofDescriptorProto* google_protobuf_OneofDescriptorProto_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_OneofDescriptorProto* ret = google_protobuf_OneofDescriptorProto_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__OneofDescriptorProto_msg_init, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__OneofDescriptorProto_msg_init, NULL, 0, arena) != + kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -2208,61 +2284,63 @@ UPB_INLINE google_protobuf_OneofDescriptorProto* google_protobuf_OneofDescriptor int options, upb_Arena* arena) { google_protobuf_OneofDescriptorProto* ret = google_protobuf_OneofDescriptorProto_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__OneofDescriptorProto_msg_init, extreg, options, arena) != - kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__OneofDescriptorProto_msg_init, extreg, options, + arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_OneofDescriptorProto_serialize(const google_protobuf_OneofDescriptorProto* msg, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__OneofDescriptorProto_msg_init, 0, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__OneofDescriptorProto_msg_init, 0, arena, &ptr, len); return ptr; } UPB_INLINE char* google_protobuf_OneofDescriptorProto_serialize_ex(const google_protobuf_OneofDescriptorProto* msg, int options, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__OneofDescriptorProto_msg_init, options, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__OneofDescriptorProto_msg_init, options, arena, &ptr, len); return ptr; } UPB_INLINE void google_protobuf_OneofDescriptorProto_clear_name(google_protobuf_OneofDescriptorProto* msg) { const upb_MiniTableField field = {1, 8, 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_OneofDescriptorProto_name(const google_protobuf_OneofDescriptorProto* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; const upb_MiniTableField field = {1, 8, 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_OneofDescriptorProto_has_name(const google_protobuf_OneofDescriptorProto* msg) { const upb_MiniTableField field = {1, 8, 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_OneofDescriptorProto_clear_options(google_protobuf_OneofDescriptorProto* msg) { const upb_MiniTableField field = {2, UPB_SIZE(4, 24), 2, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_OneofOptions* google_protobuf_OneofDescriptorProto_options(const google_protobuf_OneofDescriptorProto* msg) { const google_protobuf_OneofOptions* default_val = NULL; const google_protobuf_OneofOptions* ret; const upb_MiniTableField field = {2, UPB_SIZE(4, 24), 2, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_OneofDescriptorProto_has_options(const google_protobuf_OneofDescriptorProto* msg) { const upb_MiniTableField field = {2, UPB_SIZE(4, 24), 2, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_OneofDescriptorProto_set_name(google_protobuf_OneofDescriptorProto *msg, upb_StringView value) { const upb_MiniTableField field = {1, 8, 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_OneofDescriptorProto_set_options(google_protobuf_OneofDescriptorProto *msg, google_protobuf_OneofOptions* value) { const upb_MiniTableField field = {2, UPB_SIZE(4, 24), 2, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE struct google_protobuf_OneofOptions* google_protobuf_OneofDescriptorProto_mutable_options(google_protobuf_OneofDescriptorProto* msg, upb_Arena* arena) { struct google_protobuf_OneofOptions* sub = (struct google_protobuf_OneofOptions*)google_protobuf_OneofDescriptorProto_options(msg); @@ -2281,7 +2359,8 @@ UPB_INLINE google_protobuf_EnumDescriptorProto* google_protobuf_EnumDescriptorPr UPB_INLINE google_protobuf_EnumDescriptorProto* google_protobuf_EnumDescriptorProto_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_EnumDescriptorProto* ret = google_protobuf_EnumDescriptorProto_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__EnumDescriptorProto_msg_init, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__EnumDescriptorProto_msg_init, NULL, 0, arena) != + kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -2291,45 +2370,46 @@ UPB_INLINE google_protobuf_EnumDescriptorProto* google_protobuf_EnumDescriptorPr int options, upb_Arena* arena) { google_protobuf_EnumDescriptorProto* ret = google_protobuf_EnumDescriptorProto_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__EnumDescriptorProto_msg_init, extreg, options, arena) != - kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__EnumDescriptorProto_msg_init, extreg, options, + arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_EnumDescriptorProto_serialize(const google_protobuf_EnumDescriptorProto* msg, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__EnumDescriptorProto_msg_init, 0, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__EnumDescriptorProto_msg_init, 0, arena, &ptr, len); return ptr; } UPB_INLINE char* google_protobuf_EnumDescriptorProto_serialize_ex(const google_protobuf_EnumDescriptorProto* msg, int options, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__EnumDescriptorProto_msg_init, options, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__EnumDescriptorProto_msg_init, options, arena, &ptr, len); return ptr; } UPB_INLINE void google_protobuf_EnumDescriptorProto_clear_name(google_protobuf_EnumDescriptorProto* msg) { const upb_MiniTableField field = {1, UPB_SIZE(20, 8), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_EnumDescriptorProto_name(const google_protobuf_EnumDescriptorProto* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; const upb_MiniTableField field = {1, UPB_SIZE(20, 8), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_EnumDescriptorProto_has_name(const google_protobuf_EnumDescriptorProto* msg) { const upb_MiniTableField field = {1, UPB_SIZE(20, 8), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_EnumDescriptorProto_clear_value(google_protobuf_EnumDescriptorProto* msg) { const upb_MiniTableField field = {2, UPB_SIZE(4, 24), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_EnumValueDescriptorProto* const* google_protobuf_EnumDescriptorProto_value(const google_protobuf_EnumDescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {2, UPB_SIZE(4, 24), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_EnumValueDescriptorProto* const*)_upb_array_constptr(arr); @@ -2340,16 +2420,16 @@ UPB_INLINE const google_protobuf_EnumValueDescriptorProto* const* google_protobu } UPB_INLINE const upb_Array* _google_protobuf_EnumDescriptorProto_value_upb_array(const google_protobuf_EnumDescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {2, UPB_SIZE(4, 24), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } -UPB_INLINE upb_Array* _google_protobuf_EnumDescriptorProto_value_mutable_upb_array(const google_protobuf_EnumDescriptorProto* msg, size_t* size, upb_Arena* arena) { +UPB_INLINE upb_Array* _google_protobuf_EnumDescriptorProto_value_mutable_upb_array(google_protobuf_EnumDescriptorProto* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = {2, UPB_SIZE(4, 24), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - (upb_Message*)msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), + &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -2357,26 +2437,27 @@ UPB_INLINE upb_Array* _google_protobuf_EnumDescriptorProto_value_mutable_upb_arr } UPB_INLINE void google_protobuf_EnumDescriptorProto_clear_options(google_protobuf_EnumDescriptorProto* msg) { const upb_MiniTableField field = {3, UPB_SIZE(8, 32), 2, 1, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_EnumOptions* google_protobuf_EnumDescriptorProto_options(const google_protobuf_EnumDescriptorProto* msg) { const google_protobuf_EnumOptions* default_val = NULL; const google_protobuf_EnumOptions* ret; const upb_MiniTableField field = {3, UPB_SIZE(8, 32), 2, 1, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_EnumDescriptorProto_has_options(const google_protobuf_EnumDescriptorProto* msg) { const upb_MiniTableField field = {3, UPB_SIZE(8, 32), 2, 1, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_EnumDescriptorProto_clear_reserved_range(google_protobuf_EnumDescriptorProto* msg) { const upb_MiniTableField field = {4, UPB_SIZE(12, 40), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_EnumDescriptorProto_EnumReservedRange* const* google_protobuf_EnumDescriptorProto_reserved_range(const google_protobuf_EnumDescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {4, UPB_SIZE(12, 40), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_EnumDescriptorProto_EnumReservedRange* const*)_upb_array_constptr(arr); @@ -2387,16 +2468,16 @@ UPB_INLINE const google_protobuf_EnumDescriptorProto_EnumReservedRange* const* g } UPB_INLINE const upb_Array* _google_protobuf_EnumDescriptorProto_reserved_range_upb_array(const google_protobuf_EnumDescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {4, UPB_SIZE(12, 40), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } -UPB_INLINE upb_Array* _google_protobuf_EnumDescriptorProto_reserved_range_mutable_upb_array(const google_protobuf_EnumDescriptorProto* msg, size_t* size, upb_Arena* arena) { +UPB_INLINE upb_Array* _google_protobuf_EnumDescriptorProto_reserved_range_mutable_upb_array(google_protobuf_EnumDescriptorProto* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = {4, UPB_SIZE(12, 40), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - (upb_Message*)msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), + &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -2404,11 +2485,11 @@ UPB_INLINE upb_Array* _google_protobuf_EnumDescriptorProto_reserved_range_mutabl } UPB_INLINE void google_protobuf_EnumDescriptorProto_clear_reserved_name(google_protobuf_EnumDescriptorProto* msg) { const upb_MiniTableField field = {5, UPB_SIZE(16, 48), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView const* google_protobuf_EnumDescriptorProto_reserved_name(const google_protobuf_EnumDescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {5, UPB_SIZE(16, 48), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (upb_StringView const*)_upb_array_constptr(arr); @@ -2419,16 +2500,16 @@ UPB_INLINE upb_StringView const* google_protobuf_EnumDescriptorProto_reserved_na } UPB_INLINE const upb_Array* _google_protobuf_EnumDescriptorProto_reserved_name_upb_array(const google_protobuf_EnumDescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {5, UPB_SIZE(16, 48), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } -UPB_INLINE upb_Array* _google_protobuf_EnumDescriptorProto_reserved_name_mutable_upb_array(const google_protobuf_EnumDescriptorProto* msg, size_t* size, upb_Arena* arena) { +UPB_INLINE upb_Array* _google_protobuf_EnumDescriptorProto_reserved_name_mutable_upb_array(google_protobuf_EnumDescriptorProto* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = {5, UPB_SIZE(16, 48), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - (upb_Message*)msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), + &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -2437,11 +2518,11 @@ UPB_INLINE upb_Array* _google_protobuf_EnumDescriptorProto_reserved_name_mutable UPB_INLINE void google_protobuf_EnumDescriptorProto_set_name(google_protobuf_EnumDescriptorProto *msg, upb_StringView value) { const upb_MiniTableField field = {1, UPB_SIZE(20, 8), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE google_protobuf_EnumValueDescriptorProto** google_protobuf_EnumDescriptorProto_mutable_value(google_protobuf_EnumDescriptorProto* msg, size_t* size) { upb_MiniTableField field = {2, UPB_SIZE(4, 24), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetMutableArray(msg, &field); + upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_EnumValueDescriptorProto**)_upb_array_ptr(arr); @@ -2452,11 +2533,13 @@ UPB_INLINE google_protobuf_EnumValueDescriptorProto** google_protobuf_EnumDescri } UPB_INLINE google_protobuf_EnumValueDescriptorProto** google_protobuf_EnumDescriptorProto_resize_value(google_protobuf_EnumDescriptorProto* msg, size_t size, upb_Arena* arena) { upb_MiniTableField field = {2, UPB_SIZE(4, 24), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return (google_protobuf_EnumValueDescriptorProto**)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); + return (google_protobuf_EnumValueDescriptorProto**)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg), + &field, size, arena); } UPB_INLINE struct google_protobuf_EnumValueDescriptorProto* google_protobuf_EnumDescriptorProto_add_value(google_protobuf_EnumDescriptorProto* msg, upb_Arena* arena) { upb_MiniTableField field = {2, UPB_SIZE(4, 24), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray( + UPB_UPCAST(msg), &field, arena); if (!arr || !_upb_Array_ResizeUninitialized( arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; @@ -2469,7 +2552,7 @@ UPB_INLINE struct google_protobuf_EnumValueDescriptorProto* google_protobuf_Enum } UPB_INLINE void google_protobuf_EnumDescriptorProto_set_options(google_protobuf_EnumDescriptorProto *msg, google_protobuf_EnumOptions* value) { const upb_MiniTableField field = {3, UPB_SIZE(8, 32), 2, 1, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE struct google_protobuf_EnumOptions* google_protobuf_EnumDescriptorProto_mutable_options(google_protobuf_EnumDescriptorProto* msg, upb_Arena* arena) { struct google_protobuf_EnumOptions* sub = (struct google_protobuf_EnumOptions*)google_protobuf_EnumDescriptorProto_options(msg); @@ -2481,7 +2564,7 @@ UPB_INLINE struct google_protobuf_EnumOptions* google_protobuf_EnumDescriptorPro } UPB_INLINE google_protobuf_EnumDescriptorProto_EnumReservedRange** google_protobuf_EnumDescriptorProto_mutable_reserved_range(google_protobuf_EnumDescriptorProto* msg, size_t* size) { upb_MiniTableField field = {4, UPB_SIZE(12, 40), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetMutableArray(msg, &field); + upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_EnumDescriptorProto_EnumReservedRange**)_upb_array_ptr(arr); @@ -2492,11 +2575,13 @@ UPB_INLINE google_protobuf_EnumDescriptorProto_EnumReservedRange** google_protob } UPB_INLINE google_protobuf_EnumDescriptorProto_EnumReservedRange** google_protobuf_EnumDescriptorProto_resize_reserved_range(google_protobuf_EnumDescriptorProto* msg, size_t size, upb_Arena* arena) { upb_MiniTableField field = {4, UPB_SIZE(12, 40), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return (google_protobuf_EnumDescriptorProto_EnumReservedRange**)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); + return (google_protobuf_EnumDescriptorProto_EnumReservedRange**)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg), + &field, size, arena); } UPB_INLINE struct google_protobuf_EnumDescriptorProto_EnumReservedRange* google_protobuf_EnumDescriptorProto_add_reserved_range(google_protobuf_EnumDescriptorProto* msg, upb_Arena* arena) { upb_MiniTableField field = {4, UPB_SIZE(12, 40), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray( + UPB_UPCAST(msg), &field, arena); if (!arr || !_upb_Array_ResizeUninitialized( arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; @@ -2509,7 +2594,7 @@ UPB_INLINE struct google_protobuf_EnumDescriptorProto_EnumReservedRange* google_ } UPB_INLINE upb_StringView* google_protobuf_EnumDescriptorProto_mutable_reserved_name(google_protobuf_EnumDescriptorProto* msg, size_t* size) { upb_MiniTableField field = {5, UPB_SIZE(16, 48), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetMutableArray(msg, &field); + upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (upb_StringView*)_upb_array_ptr(arr); @@ -2520,11 +2605,13 @@ UPB_INLINE upb_StringView* google_protobuf_EnumDescriptorProto_mutable_reserved_ } UPB_INLINE upb_StringView* google_protobuf_EnumDescriptorProto_resize_reserved_name(google_protobuf_EnumDescriptorProto* msg, size_t size, upb_Arena* arena) { upb_MiniTableField field = {5, UPB_SIZE(16, 48), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return (upb_StringView*)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); + return (upb_StringView*)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg), + &field, size, arena); } UPB_INLINE bool google_protobuf_EnumDescriptorProto_add_reserved_name(google_protobuf_EnumDescriptorProto* msg, upb_StringView val, upb_Arena* arena) { upb_MiniTableField field = {5, UPB_SIZE(16, 48), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray( + UPB_UPCAST(msg), &field, arena); if (!arr || !_upb_Array_ResizeUninitialized( arr, arr->UPB_PRIVATE(size) + 1, arena)) { return false; @@ -2542,7 +2629,8 @@ UPB_INLINE google_protobuf_EnumDescriptorProto_EnumReservedRange* google_protobu UPB_INLINE google_protobuf_EnumDescriptorProto_EnumReservedRange* google_protobuf_EnumDescriptorProto_EnumReservedRange_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_EnumDescriptorProto_EnumReservedRange* ret = google_protobuf_EnumDescriptorProto_EnumReservedRange_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__EnumDescriptorProto__EnumReservedRange_msg_init, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__EnumDescriptorProto__EnumReservedRange_msg_init, NULL, 0, arena) != + kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -2552,61 +2640,63 @@ UPB_INLINE google_protobuf_EnumDescriptorProto_EnumReservedRange* google_protobu int options, upb_Arena* arena) { google_protobuf_EnumDescriptorProto_EnumReservedRange* ret = google_protobuf_EnumDescriptorProto_EnumReservedRange_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__EnumDescriptorProto__EnumReservedRange_msg_init, extreg, options, arena) != - kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__EnumDescriptorProto__EnumReservedRange_msg_init, extreg, options, + arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_EnumDescriptorProto_EnumReservedRange_serialize(const google_protobuf_EnumDescriptorProto_EnumReservedRange* msg, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__EnumDescriptorProto__EnumReservedRange_msg_init, 0, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__EnumDescriptorProto__EnumReservedRange_msg_init, 0, arena, &ptr, len); return ptr; } UPB_INLINE char* google_protobuf_EnumDescriptorProto_EnumReservedRange_serialize_ex(const google_protobuf_EnumDescriptorProto_EnumReservedRange* msg, int options, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__EnumDescriptorProto__EnumReservedRange_msg_init, options, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__EnumDescriptorProto__EnumReservedRange_msg_init, options, arena, &ptr, len); return ptr; } UPB_INLINE void google_protobuf_EnumDescriptorProto_EnumReservedRange_clear_start(google_protobuf_EnumDescriptorProto_EnumReservedRange* msg) { const upb_MiniTableField field = {1, 4, 1, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_EnumDescriptorProto_EnumReservedRange_start(const google_protobuf_EnumDescriptorProto_EnumReservedRange* msg) { int32_t default_val = (int32_t)0; int32_t ret; const upb_MiniTableField field = {1, 4, 1, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_EnumDescriptorProto_EnumReservedRange_has_start(const google_protobuf_EnumDescriptorProto_EnumReservedRange* msg) { const upb_MiniTableField field = {1, 4, 1, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_EnumDescriptorProto_EnumReservedRange_clear_end(google_protobuf_EnumDescriptorProto_EnumReservedRange* msg) { const upb_MiniTableField field = {2, 8, 2, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_EnumDescriptorProto_EnumReservedRange_end(const google_protobuf_EnumDescriptorProto_EnumReservedRange* msg) { int32_t default_val = (int32_t)0; int32_t ret; const upb_MiniTableField field = {2, 8, 2, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_EnumDescriptorProto_EnumReservedRange_has_end(const google_protobuf_EnumDescriptorProto_EnumReservedRange* msg) { const upb_MiniTableField field = {2, 8, 2, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_EnumDescriptorProto_EnumReservedRange_set_start(google_protobuf_EnumDescriptorProto_EnumReservedRange *msg, int32_t value) { const upb_MiniTableField field = {1, 4, 1, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_EnumDescriptorProto_EnumReservedRange_set_end(google_protobuf_EnumDescriptorProto_EnumReservedRange *msg, int32_t value) { const upb_MiniTableField field = {2, 8, 2, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } /* google.protobuf.EnumValueDescriptorProto */ @@ -2617,7 +2707,8 @@ UPB_INLINE google_protobuf_EnumValueDescriptorProto* google_protobuf_EnumValueDe UPB_INLINE google_protobuf_EnumValueDescriptorProto* google_protobuf_EnumValueDescriptorProto_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_EnumValueDescriptorProto* ret = google_protobuf_EnumValueDescriptorProto_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__EnumValueDescriptorProto_msg_init, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__EnumValueDescriptorProto_msg_init, NULL, 0, arena) != + kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -2627,80 +2718,83 @@ UPB_INLINE google_protobuf_EnumValueDescriptorProto* google_protobuf_EnumValueDe int options, upb_Arena* arena) { google_protobuf_EnumValueDescriptorProto* ret = google_protobuf_EnumValueDescriptorProto_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__EnumValueDescriptorProto_msg_init, extreg, options, arena) != - kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__EnumValueDescriptorProto_msg_init, extreg, options, + arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_EnumValueDescriptorProto_serialize(const google_protobuf_EnumValueDescriptorProto* msg, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__EnumValueDescriptorProto_msg_init, 0, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__EnumValueDescriptorProto_msg_init, 0, arena, &ptr, len); return ptr; } UPB_INLINE char* google_protobuf_EnumValueDescriptorProto_serialize_ex(const google_protobuf_EnumValueDescriptorProto* msg, int options, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__EnumValueDescriptorProto_msg_init, options, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__EnumValueDescriptorProto_msg_init, options, arena, &ptr, len); return ptr; } UPB_INLINE void google_protobuf_EnumValueDescriptorProto_clear_name(google_protobuf_EnumValueDescriptorProto* msg) { const upb_MiniTableField field = {1, UPB_SIZE(12, 8), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_EnumValueDescriptorProto_name(const google_protobuf_EnumValueDescriptorProto* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; const upb_MiniTableField field = {1, UPB_SIZE(12, 8), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_EnumValueDescriptorProto_has_name(const google_protobuf_EnumValueDescriptorProto* msg) { const upb_MiniTableField field = {1, UPB_SIZE(12, 8), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_EnumValueDescriptorProto_clear_number(google_protobuf_EnumValueDescriptorProto* msg) { const upb_MiniTableField field = {2, 4, 2, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_EnumValueDescriptorProto_number(const google_protobuf_EnumValueDescriptorProto* msg) { int32_t default_val = (int32_t)0; int32_t ret; const upb_MiniTableField field = {2, 4, 2, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_EnumValueDescriptorProto_has_number(const google_protobuf_EnumValueDescriptorProto* msg) { const upb_MiniTableField field = {2, 4, 2, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_EnumValueDescriptorProto_clear_options(google_protobuf_EnumValueDescriptorProto* msg) { const upb_MiniTableField field = {3, UPB_SIZE(8, 24), 3, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_EnumValueOptions* google_protobuf_EnumValueDescriptorProto_options(const google_protobuf_EnumValueDescriptorProto* msg) { const google_protobuf_EnumValueOptions* default_val = NULL; const google_protobuf_EnumValueOptions* ret; const upb_MiniTableField field = {3, UPB_SIZE(8, 24), 3, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_EnumValueDescriptorProto_has_options(const google_protobuf_EnumValueDescriptorProto* msg) { const upb_MiniTableField field = {3, UPB_SIZE(8, 24), 3, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_EnumValueDescriptorProto_set_name(google_protobuf_EnumValueDescriptorProto *msg, upb_StringView value) { const upb_MiniTableField field = {1, UPB_SIZE(12, 8), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_EnumValueDescriptorProto_set_number(google_protobuf_EnumValueDescriptorProto *msg, int32_t value) { const upb_MiniTableField field = {2, 4, 2, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_EnumValueDescriptorProto_set_options(google_protobuf_EnumValueDescriptorProto *msg, google_protobuf_EnumValueOptions* value) { const upb_MiniTableField field = {3, UPB_SIZE(8, 24), 3, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE struct google_protobuf_EnumValueOptions* google_protobuf_EnumValueDescriptorProto_mutable_options(google_protobuf_EnumValueDescriptorProto* msg, upb_Arena* arena) { struct google_protobuf_EnumValueOptions* sub = (struct google_protobuf_EnumValueOptions*)google_protobuf_EnumValueDescriptorProto_options(msg); @@ -2719,7 +2813,8 @@ UPB_INLINE google_protobuf_ServiceDescriptorProto* google_protobuf_ServiceDescri UPB_INLINE google_protobuf_ServiceDescriptorProto* google_protobuf_ServiceDescriptorProto_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_ServiceDescriptorProto* ret = google_protobuf_ServiceDescriptorProto_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__ServiceDescriptorProto_msg_init, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__ServiceDescriptorProto_msg_init, NULL, 0, arena) != + kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -2729,45 +2824,46 @@ UPB_INLINE google_protobuf_ServiceDescriptorProto* google_protobuf_ServiceDescri int options, upb_Arena* arena) { google_protobuf_ServiceDescriptorProto* ret = google_protobuf_ServiceDescriptorProto_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__ServiceDescriptorProto_msg_init, extreg, options, arena) != - kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__ServiceDescriptorProto_msg_init, extreg, options, + arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_ServiceDescriptorProto_serialize(const google_protobuf_ServiceDescriptorProto* msg, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__ServiceDescriptorProto_msg_init, 0, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__ServiceDescriptorProto_msg_init, 0, arena, &ptr, len); return ptr; } UPB_INLINE char* google_protobuf_ServiceDescriptorProto_serialize_ex(const google_protobuf_ServiceDescriptorProto* msg, int options, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__ServiceDescriptorProto_msg_init, options, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__ServiceDescriptorProto_msg_init, options, arena, &ptr, len); return ptr; } UPB_INLINE void google_protobuf_ServiceDescriptorProto_clear_name(google_protobuf_ServiceDescriptorProto* msg) { const upb_MiniTableField field = {1, UPB_SIZE(12, 8), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_ServiceDescriptorProto_name(const google_protobuf_ServiceDescriptorProto* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; const upb_MiniTableField field = {1, UPB_SIZE(12, 8), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_ServiceDescriptorProto_has_name(const google_protobuf_ServiceDescriptorProto* msg) { const upb_MiniTableField field = {1, UPB_SIZE(12, 8), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_ServiceDescriptorProto_clear_method(google_protobuf_ServiceDescriptorProto* msg) { const upb_MiniTableField field = {2, UPB_SIZE(4, 24), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_MethodDescriptorProto* const* google_protobuf_ServiceDescriptorProto_method(const google_protobuf_ServiceDescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {2, UPB_SIZE(4, 24), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_MethodDescriptorProto* const*)_upb_array_constptr(arr); @@ -2778,16 +2874,16 @@ UPB_INLINE const google_protobuf_MethodDescriptorProto* const* google_protobuf_S } UPB_INLINE const upb_Array* _google_protobuf_ServiceDescriptorProto_method_upb_array(const google_protobuf_ServiceDescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {2, UPB_SIZE(4, 24), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } -UPB_INLINE upb_Array* _google_protobuf_ServiceDescriptorProto_method_mutable_upb_array(const google_protobuf_ServiceDescriptorProto* msg, size_t* size, upb_Arena* arena) { +UPB_INLINE upb_Array* _google_protobuf_ServiceDescriptorProto_method_mutable_upb_array(google_protobuf_ServiceDescriptorProto* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = {2, UPB_SIZE(4, 24), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - (upb_Message*)msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), + &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -2795,27 +2891,28 @@ UPB_INLINE upb_Array* _google_protobuf_ServiceDescriptorProto_method_mutable_upb } UPB_INLINE void google_protobuf_ServiceDescriptorProto_clear_options(google_protobuf_ServiceDescriptorProto* msg) { const upb_MiniTableField field = {3, UPB_SIZE(8, 32), 2, 1, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_ServiceOptions* google_protobuf_ServiceDescriptorProto_options(const google_protobuf_ServiceDescriptorProto* msg) { const google_protobuf_ServiceOptions* default_val = NULL; const google_protobuf_ServiceOptions* ret; const upb_MiniTableField field = {3, UPB_SIZE(8, 32), 2, 1, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_ServiceDescriptorProto_has_options(const google_protobuf_ServiceDescriptorProto* msg) { const upb_MiniTableField field = {3, UPB_SIZE(8, 32), 2, 1, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_ServiceDescriptorProto_set_name(google_protobuf_ServiceDescriptorProto *msg, upb_StringView value) { const upb_MiniTableField field = {1, UPB_SIZE(12, 8), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE google_protobuf_MethodDescriptorProto** google_protobuf_ServiceDescriptorProto_mutable_method(google_protobuf_ServiceDescriptorProto* msg, size_t* size) { upb_MiniTableField field = {2, UPB_SIZE(4, 24), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetMutableArray(msg, &field); + upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_MethodDescriptorProto**)_upb_array_ptr(arr); @@ -2826,11 +2923,13 @@ UPB_INLINE google_protobuf_MethodDescriptorProto** google_protobuf_ServiceDescri } UPB_INLINE google_protobuf_MethodDescriptorProto** google_protobuf_ServiceDescriptorProto_resize_method(google_protobuf_ServiceDescriptorProto* msg, size_t size, upb_Arena* arena) { upb_MiniTableField field = {2, UPB_SIZE(4, 24), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return (google_protobuf_MethodDescriptorProto**)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); + return (google_protobuf_MethodDescriptorProto**)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg), + &field, size, arena); } UPB_INLINE struct google_protobuf_MethodDescriptorProto* google_protobuf_ServiceDescriptorProto_add_method(google_protobuf_ServiceDescriptorProto* msg, upb_Arena* arena) { upb_MiniTableField field = {2, UPB_SIZE(4, 24), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray( + UPB_UPCAST(msg), &field, arena); if (!arr || !_upb_Array_ResizeUninitialized( arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; @@ -2843,7 +2942,7 @@ UPB_INLINE struct google_protobuf_MethodDescriptorProto* google_protobuf_Service } UPB_INLINE void google_protobuf_ServiceDescriptorProto_set_options(google_protobuf_ServiceDescriptorProto *msg, google_protobuf_ServiceOptions* value) { const upb_MiniTableField field = {3, UPB_SIZE(8, 32), 2, 1, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE struct google_protobuf_ServiceOptions* google_protobuf_ServiceDescriptorProto_mutable_options(google_protobuf_ServiceDescriptorProto* msg, upb_Arena* arena) { struct google_protobuf_ServiceOptions* sub = (struct google_protobuf_ServiceOptions*)google_protobuf_ServiceDescriptorProto_options(msg); @@ -2862,7 +2961,8 @@ UPB_INLINE google_protobuf_MethodDescriptorProto* google_protobuf_MethodDescript UPB_INLINE google_protobuf_MethodDescriptorProto* google_protobuf_MethodDescriptorProto_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_MethodDescriptorProto* ret = google_protobuf_MethodDescriptorProto_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__MethodDescriptorProto_msg_init, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__MethodDescriptorProto_msg_init, NULL, 0, arena) != + kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -2872,129 +2972,135 @@ UPB_INLINE google_protobuf_MethodDescriptorProto* google_protobuf_MethodDescript int options, upb_Arena* arena) { google_protobuf_MethodDescriptorProto* ret = google_protobuf_MethodDescriptorProto_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__MethodDescriptorProto_msg_init, extreg, options, arena) != - kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__MethodDescriptorProto_msg_init, extreg, options, + arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_MethodDescriptorProto_serialize(const google_protobuf_MethodDescriptorProto* msg, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__MethodDescriptorProto_msg_init, 0, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__MethodDescriptorProto_msg_init, 0, arena, &ptr, len); return ptr; } UPB_INLINE char* google_protobuf_MethodDescriptorProto_serialize_ex(const google_protobuf_MethodDescriptorProto* msg, int options, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__MethodDescriptorProto_msg_init, options, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__MethodDescriptorProto_msg_init, options, arena, &ptr, len); return ptr; } UPB_INLINE void google_protobuf_MethodDescriptorProto_clear_name(google_protobuf_MethodDescriptorProto* msg) { const upb_MiniTableField field = {1, UPB_SIZE(12, 8), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_MethodDescriptorProto_name(const google_protobuf_MethodDescriptorProto* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; const upb_MiniTableField field = {1, UPB_SIZE(12, 8), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_MethodDescriptorProto_has_name(const google_protobuf_MethodDescriptorProto* msg) { const upb_MiniTableField field = {1, UPB_SIZE(12, 8), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_MethodDescriptorProto_clear_input_type(google_protobuf_MethodDescriptorProto* msg) { const upb_MiniTableField field = {2, UPB_SIZE(20, 24), 2, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_MethodDescriptorProto_input_type(const google_protobuf_MethodDescriptorProto* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; const upb_MiniTableField field = {2, UPB_SIZE(20, 24), 2, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_MethodDescriptorProto_has_input_type(const google_protobuf_MethodDescriptorProto* msg) { const upb_MiniTableField field = {2, UPB_SIZE(20, 24), 2, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_MethodDescriptorProto_clear_output_type(google_protobuf_MethodDescriptorProto* msg) { const upb_MiniTableField field = {3, UPB_SIZE(28, 40), 3, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_MethodDescriptorProto_output_type(const google_protobuf_MethodDescriptorProto* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; const upb_MiniTableField field = {3, UPB_SIZE(28, 40), 3, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_MethodDescriptorProto_has_output_type(const google_protobuf_MethodDescriptorProto* msg) { const upb_MiniTableField field = {3, UPB_SIZE(28, 40), 3, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_MethodDescriptorProto_clear_options(google_protobuf_MethodDescriptorProto* msg) { const upb_MiniTableField field = {4, UPB_SIZE(4, 56), 4, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_MethodOptions* google_protobuf_MethodDescriptorProto_options(const google_protobuf_MethodDescriptorProto* msg) { const google_protobuf_MethodOptions* default_val = NULL; const google_protobuf_MethodOptions* ret; const upb_MiniTableField field = {4, UPB_SIZE(4, 56), 4, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_MethodDescriptorProto_has_options(const google_protobuf_MethodDescriptorProto* msg) { const upb_MiniTableField field = {4, UPB_SIZE(4, 56), 4, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_MethodDescriptorProto_clear_client_streaming(google_protobuf_MethodDescriptorProto* msg) { const upb_MiniTableField field = {5, UPB_SIZE(8, 1), 5, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_MethodDescriptorProto_client_streaming(const google_protobuf_MethodDescriptorProto* msg) { bool default_val = false; bool ret; const upb_MiniTableField field = {5, UPB_SIZE(8, 1), 5, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_MethodDescriptorProto_has_client_streaming(const google_protobuf_MethodDescriptorProto* msg) { const upb_MiniTableField field = {5, UPB_SIZE(8, 1), 5, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_MethodDescriptorProto_clear_server_streaming(google_protobuf_MethodDescriptorProto* msg) { const upb_MiniTableField field = {6, UPB_SIZE(9, 2), 6, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_MethodDescriptorProto_server_streaming(const google_protobuf_MethodDescriptorProto* msg) { bool default_val = false; bool ret; const upb_MiniTableField field = {6, UPB_SIZE(9, 2), 6, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_MethodDescriptorProto_has_server_streaming(const google_protobuf_MethodDescriptorProto* msg) { const upb_MiniTableField field = {6, UPB_SIZE(9, 2), 6, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_MethodDescriptorProto_set_name(google_protobuf_MethodDescriptorProto *msg, upb_StringView value) { const upb_MiniTableField field = {1, UPB_SIZE(12, 8), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_MethodDescriptorProto_set_input_type(google_protobuf_MethodDescriptorProto *msg, upb_StringView value) { const upb_MiniTableField field = {2, UPB_SIZE(20, 24), 2, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_MethodDescriptorProto_set_output_type(google_protobuf_MethodDescriptorProto *msg, upb_StringView value) { const upb_MiniTableField field = {3, UPB_SIZE(28, 40), 3, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_MethodDescriptorProto_set_options(google_protobuf_MethodDescriptorProto *msg, google_protobuf_MethodOptions* value) { const upb_MiniTableField field = {4, UPB_SIZE(4, 56), 4, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE struct google_protobuf_MethodOptions* google_protobuf_MethodDescriptorProto_mutable_options(google_protobuf_MethodDescriptorProto* msg, upb_Arena* arena) { struct google_protobuf_MethodOptions* sub = (struct google_protobuf_MethodOptions*)google_protobuf_MethodDescriptorProto_options(msg); @@ -3006,11 +3112,11 @@ UPB_INLINE struct google_protobuf_MethodOptions* google_protobuf_MethodDescripto } UPB_INLINE void google_protobuf_MethodDescriptorProto_set_client_streaming(google_protobuf_MethodDescriptorProto *msg, bool value) { const upb_MiniTableField field = {5, UPB_SIZE(8, 1), 5, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_MethodDescriptorProto_set_server_streaming(google_protobuf_MethodDescriptorProto *msg, bool value) { const upb_MiniTableField field = {6, UPB_SIZE(9, 2), 6, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } /* google.protobuf.FileOptions */ @@ -3021,7 +3127,8 @@ UPB_INLINE google_protobuf_FileOptions* google_protobuf_FileOptions_new(upb_Aren UPB_INLINE google_protobuf_FileOptions* google_protobuf_FileOptions_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_FileOptions* ret = google_protobuf_FileOptions_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__FileOptions_msg_init, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__FileOptions_msg_init, NULL, 0, arena) != + kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -3031,330 +3138,350 @@ UPB_INLINE google_protobuf_FileOptions* google_protobuf_FileOptions_parse_ex(con int options, upb_Arena* arena) { google_protobuf_FileOptions* ret = google_protobuf_FileOptions_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__FileOptions_msg_init, extreg, options, arena) != - kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__FileOptions_msg_init, extreg, options, + arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_FileOptions_serialize(const google_protobuf_FileOptions* msg, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__FileOptions_msg_init, 0, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__FileOptions_msg_init, 0, arena, &ptr, len); return ptr; } UPB_INLINE char* google_protobuf_FileOptions_serialize_ex(const google_protobuf_FileOptions* msg, int options, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__FileOptions_msg_init, options, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__FileOptions_msg_init, options, arena, &ptr, len); return ptr; } UPB_INLINE void google_protobuf_FileOptions_clear_java_package(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {1, UPB_SIZE(24, 16), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_FileOptions_java_package(const google_protobuf_FileOptions* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; const upb_MiniTableField field = {1, UPB_SIZE(24, 16), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FileOptions_has_java_package(const google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {1, UPB_SIZE(24, 16), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileOptions_clear_java_outer_classname(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {8, 32, 2, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_FileOptions_java_outer_classname(const google_protobuf_FileOptions* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; const upb_MiniTableField field = {8, 32, 2, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FileOptions_has_java_outer_classname(const google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {8, 32, 2, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileOptions_clear_optimize_for(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {9, 4, 3, 2, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_FileOptions_optimize_for(const google_protobuf_FileOptions* msg) { int32_t default_val = 1; int32_t ret; const upb_MiniTableField field = {9, 4, 3, 2, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FileOptions_has_optimize_for(const google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {9, 4, 3, 2, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileOptions_clear_java_multiple_files(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {10, 8, 4, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_FileOptions_java_multiple_files(const google_protobuf_FileOptions* msg) { bool default_val = false; bool ret; const upb_MiniTableField field = {10, 8, 4, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FileOptions_has_java_multiple_files(const google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {10, 8, 4, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileOptions_clear_go_package(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {11, UPB_SIZE(40, 48), 5, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_FileOptions_go_package(const google_protobuf_FileOptions* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; const upb_MiniTableField field = {11, UPB_SIZE(40, 48), 5, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FileOptions_has_go_package(const google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {11, UPB_SIZE(40, 48), 5, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileOptions_clear_cc_generic_services(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {16, 9, 6, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_FileOptions_cc_generic_services(const google_protobuf_FileOptions* msg) { bool default_val = false; bool ret; const upb_MiniTableField field = {16, 9, 6, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FileOptions_has_cc_generic_services(const google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {16, 9, 6, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileOptions_clear_java_generic_services(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {17, 10, 7, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_FileOptions_java_generic_services(const google_protobuf_FileOptions* msg) { bool default_val = false; bool ret; const upb_MiniTableField field = {17, 10, 7, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FileOptions_has_java_generic_services(const google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {17, 10, 7, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileOptions_clear_py_generic_services(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {18, 11, 8, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_FileOptions_py_generic_services(const google_protobuf_FileOptions* msg) { bool default_val = false; bool ret; const upb_MiniTableField field = {18, 11, 8, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FileOptions_has_py_generic_services(const google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {18, 11, 8, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileOptions_clear_java_generate_equals_and_hash(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {20, 12, 9, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_FileOptions_java_generate_equals_and_hash(const google_protobuf_FileOptions* msg) { bool default_val = false; bool ret; const upb_MiniTableField field = {20, 12, 9, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FileOptions_has_java_generate_equals_and_hash(const google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {20, 12, 9, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileOptions_clear_deprecated(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {23, 13, 10, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_FileOptions_deprecated(const google_protobuf_FileOptions* msg) { bool default_val = false; bool ret; const upb_MiniTableField field = {23, 13, 10, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FileOptions_has_deprecated(const google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {23, 13, 10, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileOptions_clear_java_string_check_utf8(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {27, 14, 11, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_FileOptions_java_string_check_utf8(const google_protobuf_FileOptions* msg) { bool default_val = false; bool ret; const upb_MiniTableField field = {27, 14, 11, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FileOptions_has_java_string_check_utf8(const google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {27, 14, 11, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileOptions_clear_cc_enable_arenas(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {31, 15, 12, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_FileOptions_cc_enable_arenas(const google_protobuf_FileOptions* msg) { bool default_val = true; bool ret; const upb_MiniTableField field = {31, 15, 12, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FileOptions_has_cc_enable_arenas(const google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {31, 15, 12, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileOptions_clear_objc_class_prefix(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {36, UPB_SIZE(48, 64), 13, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_FileOptions_objc_class_prefix(const google_protobuf_FileOptions* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; const upb_MiniTableField field = {36, UPB_SIZE(48, 64), 13, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FileOptions_has_objc_class_prefix(const google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {36, UPB_SIZE(48, 64), 13, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileOptions_clear_csharp_namespace(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {37, UPB_SIZE(56, 80), 14, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_FileOptions_csharp_namespace(const google_protobuf_FileOptions* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; const upb_MiniTableField field = {37, UPB_SIZE(56, 80), 14, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FileOptions_has_csharp_namespace(const google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {37, UPB_SIZE(56, 80), 14, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileOptions_clear_swift_prefix(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {39, UPB_SIZE(64, 96), 15, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_FileOptions_swift_prefix(const google_protobuf_FileOptions* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; const upb_MiniTableField field = {39, UPB_SIZE(64, 96), 15, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FileOptions_has_swift_prefix(const google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {39, UPB_SIZE(64, 96), 15, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileOptions_clear_php_class_prefix(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {40, UPB_SIZE(72, 112), 16, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_FileOptions_php_class_prefix(const google_protobuf_FileOptions* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; const upb_MiniTableField field = {40, UPB_SIZE(72, 112), 16, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FileOptions_has_php_class_prefix(const google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {40, UPB_SIZE(72, 112), 16, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileOptions_clear_php_namespace(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {41, UPB_SIZE(80, 128), 17, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_FileOptions_php_namespace(const google_protobuf_FileOptions* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; const upb_MiniTableField field = {41, UPB_SIZE(80, 128), 17, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FileOptions_has_php_namespace(const google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {41, UPB_SIZE(80, 128), 17, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileOptions_clear_php_metadata_namespace(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {44, UPB_SIZE(88, 144), 18, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_FileOptions_php_metadata_namespace(const google_protobuf_FileOptions* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; const upb_MiniTableField field = {44, UPB_SIZE(88, 144), 18, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FileOptions_has_php_metadata_namespace(const google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {44, UPB_SIZE(88, 144), 18, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileOptions_clear_ruby_package(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {45, UPB_SIZE(96, 160), 19, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_FileOptions_ruby_package(const google_protobuf_FileOptions* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; const upb_MiniTableField field = {45, UPB_SIZE(96, 160), 19, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FileOptions_has_ruby_package(const google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {45, UPB_SIZE(96, 160), 19, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileOptions_clear_features(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {50, UPB_SIZE(16, 176), 20, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_FeatureSet* google_protobuf_FileOptions_features(const google_protobuf_FileOptions* msg) { const google_protobuf_FeatureSet* default_val = NULL; const google_protobuf_FeatureSet* ret; const upb_MiniTableField field = {50, UPB_SIZE(16, 176), 20, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FileOptions_has_features(const google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {50, UPB_SIZE(16, 176), 20, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileOptions_clear_uninterpreted_option(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {999, UPB_SIZE(20, 184), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_FileOptions_uninterpreted_option(const google_protobuf_FileOptions* msg, size_t* size) { const upb_MiniTableField field = {999, UPB_SIZE(20, 184), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_UninterpretedOption* const*)_upb_array_constptr(arr); @@ -3365,16 +3492,16 @@ UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_Fil } UPB_INLINE const upb_Array* _google_protobuf_FileOptions_uninterpreted_option_upb_array(const google_protobuf_FileOptions* msg, size_t* size) { const upb_MiniTableField field = {999, UPB_SIZE(20, 184), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } -UPB_INLINE upb_Array* _google_protobuf_FileOptions_uninterpreted_option_mutable_upb_array(const google_protobuf_FileOptions* msg, size_t* size, upb_Arena* arena) { +UPB_INLINE upb_Array* _google_protobuf_FileOptions_uninterpreted_option_mutable_upb_array(google_protobuf_FileOptions* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = {999, UPB_SIZE(20, 184), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - (upb_Message*)msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), + &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -3383,83 +3510,83 @@ UPB_INLINE upb_Array* _google_protobuf_FileOptions_uninterpreted_option_mutable_ UPB_INLINE void google_protobuf_FileOptions_set_java_package(google_protobuf_FileOptions *msg, upb_StringView value) { const upb_MiniTableField field = {1, UPB_SIZE(24, 16), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FileOptions_set_java_outer_classname(google_protobuf_FileOptions *msg, upb_StringView value) { const upb_MiniTableField field = {8, 32, 2, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FileOptions_set_optimize_for(google_protobuf_FileOptions *msg, int32_t value) { const upb_MiniTableField field = {9, 4, 3, 2, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FileOptions_set_java_multiple_files(google_protobuf_FileOptions *msg, bool value) { const upb_MiniTableField field = {10, 8, 4, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FileOptions_set_go_package(google_protobuf_FileOptions *msg, upb_StringView value) { const upb_MiniTableField field = {11, UPB_SIZE(40, 48), 5, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FileOptions_set_cc_generic_services(google_protobuf_FileOptions *msg, bool value) { const upb_MiniTableField field = {16, 9, 6, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FileOptions_set_java_generic_services(google_protobuf_FileOptions *msg, bool value) { const upb_MiniTableField field = {17, 10, 7, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FileOptions_set_py_generic_services(google_protobuf_FileOptions *msg, bool value) { const upb_MiniTableField field = {18, 11, 8, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FileOptions_set_java_generate_equals_and_hash(google_protobuf_FileOptions *msg, bool value) { const upb_MiniTableField field = {20, 12, 9, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FileOptions_set_deprecated(google_protobuf_FileOptions *msg, bool value) { const upb_MiniTableField field = {23, 13, 10, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FileOptions_set_java_string_check_utf8(google_protobuf_FileOptions *msg, bool value) { const upb_MiniTableField field = {27, 14, 11, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FileOptions_set_cc_enable_arenas(google_protobuf_FileOptions *msg, bool value) { const upb_MiniTableField field = {31, 15, 12, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FileOptions_set_objc_class_prefix(google_protobuf_FileOptions *msg, upb_StringView value) { const upb_MiniTableField field = {36, UPB_SIZE(48, 64), 13, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FileOptions_set_csharp_namespace(google_protobuf_FileOptions *msg, upb_StringView value) { const upb_MiniTableField field = {37, UPB_SIZE(56, 80), 14, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FileOptions_set_swift_prefix(google_protobuf_FileOptions *msg, upb_StringView value) { const upb_MiniTableField field = {39, UPB_SIZE(64, 96), 15, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FileOptions_set_php_class_prefix(google_protobuf_FileOptions *msg, upb_StringView value) { const upb_MiniTableField field = {40, UPB_SIZE(72, 112), 16, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FileOptions_set_php_namespace(google_protobuf_FileOptions *msg, upb_StringView value) { const upb_MiniTableField field = {41, UPB_SIZE(80, 128), 17, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FileOptions_set_php_metadata_namespace(google_protobuf_FileOptions *msg, upb_StringView value) { const upb_MiniTableField field = {44, UPB_SIZE(88, 144), 18, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FileOptions_set_ruby_package(google_protobuf_FileOptions *msg, upb_StringView value) { const upb_MiniTableField field = {45, UPB_SIZE(96, 160), 19, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FileOptions_set_features(google_protobuf_FileOptions *msg, google_protobuf_FeatureSet* value) { const upb_MiniTableField field = {50, UPB_SIZE(16, 176), 20, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE struct google_protobuf_FeatureSet* google_protobuf_FileOptions_mutable_features(google_protobuf_FileOptions* msg, upb_Arena* arena) { struct google_protobuf_FeatureSet* sub = (struct google_protobuf_FeatureSet*)google_protobuf_FileOptions_features(msg); @@ -3471,7 +3598,7 @@ UPB_INLINE struct google_protobuf_FeatureSet* google_protobuf_FileOptions_mutabl } UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_FileOptions_mutable_uninterpreted_option(google_protobuf_FileOptions* msg, size_t* size) { upb_MiniTableField field = {999, UPB_SIZE(20, 184), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetMutableArray(msg, &field); + upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_UninterpretedOption**)_upb_array_ptr(arr); @@ -3482,11 +3609,13 @@ UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_FileOptions_mut } UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_FileOptions_resize_uninterpreted_option(google_protobuf_FileOptions* msg, size_t size, upb_Arena* arena) { upb_MiniTableField field = {999, UPB_SIZE(20, 184), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return (google_protobuf_UninterpretedOption**)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); + return (google_protobuf_UninterpretedOption**)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg), + &field, size, arena); } UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_FileOptions_add_uninterpreted_option(google_protobuf_FileOptions* msg, upb_Arena* arena) { upb_MiniTableField field = {999, UPB_SIZE(20, 184), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray( + UPB_UPCAST(msg), &field, arena); if (!arr || !_upb_Array_ResizeUninitialized( arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; @@ -3506,7 +3635,8 @@ UPB_INLINE google_protobuf_MessageOptions* google_protobuf_MessageOptions_new(up UPB_INLINE google_protobuf_MessageOptions* google_protobuf_MessageOptions_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_MessageOptions* ret = google_protobuf_MessageOptions_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__MessageOptions_msg_init, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__MessageOptions_msg_init, NULL, 0, arena) != + kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -3516,120 +3646,126 @@ UPB_INLINE google_protobuf_MessageOptions* google_protobuf_MessageOptions_parse_ int options, upb_Arena* arena) { google_protobuf_MessageOptions* ret = google_protobuf_MessageOptions_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__MessageOptions_msg_init, extreg, options, arena) != - kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__MessageOptions_msg_init, extreg, options, + arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_MessageOptions_serialize(const google_protobuf_MessageOptions* msg, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__MessageOptions_msg_init, 0, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__MessageOptions_msg_init, 0, arena, &ptr, len); return ptr; } UPB_INLINE char* google_protobuf_MessageOptions_serialize_ex(const google_protobuf_MessageOptions* msg, int options, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__MessageOptions_msg_init, options, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__MessageOptions_msg_init, options, arena, &ptr, len); return ptr; } UPB_INLINE void google_protobuf_MessageOptions_clear_message_set_wire_format(google_protobuf_MessageOptions* msg) { const upb_MiniTableField field = {1, 1, 1, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_MessageOptions_message_set_wire_format(const google_protobuf_MessageOptions* msg) { bool default_val = false; bool ret; const upb_MiniTableField field = {1, 1, 1, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_MessageOptions_has_message_set_wire_format(const google_protobuf_MessageOptions* msg) { const upb_MiniTableField field = {1, 1, 1, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_MessageOptions_clear_no_standard_descriptor_accessor(google_protobuf_MessageOptions* msg) { const upb_MiniTableField field = {2, 2, 2, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_MessageOptions_no_standard_descriptor_accessor(const google_protobuf_MessageOptions* msg) { bool default_val = false; bool ret; const upb_MiniTableField field = {2, 2, 2, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_MessageOptions_has_no_standard_descriptor_accessor(const google_protobuf_MessageOptions* msg) { const upb_MiniTableField field = {2, 2, 2, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_MessageOptions_clear_deprecated(google_protobuf_MessageOptions* msg) { const upb_MiniTableField field = {3, 3, 3, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_MessageOptions_deprecated(const google_protobuf_MessageOptions* msg) { bool default_val = false; bool ret; const upb_MiniTableField field = {3, 3, 3, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_MessageOptions_has_deprecated(const google_protobuf_MessageOptions* msg) { const upb_MiniTableField field = {3, 3, 3, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_MessageOptions_clear_map_entry(google_protobuf_MessageOptions* msg) { const upb_MiniTableField field = {7, 4, 4, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_MessageOptions_map_entry(const google_protobuf_MessageOptions* msg) { bool default_val = false; bool ret; const upb_MiniTableField field = {7, 4, 4, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_MessageOptions_has_map_entry(const google_protobuf_MessageOptions* msg) { const upb_MiniTableField field = {7, 4, 4, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_MessageOptions_clear_deprecated_legacy_json_field_conflicts(google_protobuf_MessageOptions* msg) { const upb_MiniTableField field = {11, 5, 5, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_MessageOptions_deprecated_legacy_json_field_conflicts(const google_protobuf_MessageOptions* msg) { bool default_val = false; bool ret; const upb_MiniTableField field = {11, 5, 5, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_MessageOptions_has_deprecated_legacy_json_field_conflicts(const google_protobuf_MessageOptions* msg) { const upb_MiniTableField field = {11, 5, 5, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_MessageOptions_clear_features(google_protobuf_MessageOptions* msg) { const upb_MiniTableField field = {12, 8, 6, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_FeatureSet* google_protobuf_MessageOptions_features(const google_protobuf_MessageOptions* msg) { const google_protobuf_FeatureSet* default_val = NULL; const google_protobuf_FeatureSet* ret; const upb_MiniTableField field = {12, 8, 6, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_MessageOptions_has_features(const google_protobuf_MessageOptions* msg) { const upb_MiniTableField field = {12, 8, 6, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_MessageOptions_clear_uninterpreted_option(google_protobuf_MessageOptions* msg) { const upb_MiniTableField field = {999, UPB_SIZE(12, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_MessageOptions_uninterpreted_option(const google_protobuf_MessageOptions* msg, size_t* size) { const upb_MiniTableField field = {999, UPB_SIZE(12, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_UninterpretedOption* const*)_upb_array_constptr(arr); @@ -3640,16 +3776,16 @@ UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_Mes } UPB_INLINE const upb_Array* _google_protobuf_MessageOptions_uninterpreted_option_upb_array(const google_protobuf_MessageOptions* msg, size_t* size) { const upb_MiniTableField field = {999, UPB_SIZE(12, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } -UPB_INLINE upb_Array* _google_protobuf_MessageOptions_uninterpreted_option_mutable_upb_array(const google_protobuf_MessageOptions* msg, size_t* size, upb_Arena* arena) { +UPB_INLINE upb_Array* _google_protobuf_MessageOptions_uninterpreted_option_mutable_upb_array(google_protobuf_MessageOptions* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = {999, UPB_SIZE(12, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - (upb_Message*)msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), + &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -3658,27 +3794,27 @@ UPB_INLINE upb_Array* _google_protobuf_MessageOptions_uninterpreted_option_mutab UPB_INLINE void google_protobuf_MessageOptions_set_message_set_wire_format(google_protobuf_MessageOptions *msg, bool value) { const upb_MiniTableField field = {1, 1, 1, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_MessageOptions_set_no_standard_descriptor_accessor(google_protobuf_MessageOptions *msg, bool value) { const upb_MiniTableField field = {2, 2, 2, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_MessageOptions_set_deprecated(google_protobuf_MessageOptions *msg, bool value) { const upb_MiniTableField field = {3, 3, 3, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_MessageOptions_set_map_entry(google_protobuf_MessageOptions *msg, bool value) { const upb_MiniTableField field = {7, 4, 4, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_MessageOptions_set_deprecated_legacy_json_field_conflicts(google_protobuf_MessageOptions *msg, bool value) { const upb_MiniTableField field = {11, 5, 5, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_MessageOptions_set_features(google_protobuf_MessageOptions *msg, google_protobuf_FeatureSet* value) { const upb_MiniTableField field = {12, 8, 6, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE struct google_protobuf_FeatureSet* google_protobuf_MessageOptions_mutable_features(google_protobuf_MessageOptions* msg, upb_Arena* arena) { struct google_protobuf_FeatureSet* sub = (struct google_protobuf_FeatureSet*)google_protobuf_MessageOptions_features(msg); @@ -3690,7 +3826,7 @@ UPB_INLINE struct google_protobuf_FeatureSet* google_protobuf_MessageOptions_mut } UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_MessageOptions_mutable_uninterpreted_option(google_protobuf_MessageOptions* msg, size_t* size) { upb_MiniTableField field = {999, UPB_SIZE(12, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetMutableArray(msg, &field); + upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_UninterpretedOption**)_upb_array_ptr(arr); @@ -3701,11 +3837,13 @@ UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_MessageOptions_ } UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_MessageOptions_resize_uninterpreted_option(google_protobuf_MessageOptions* msg, size_t size, upb_Arena* arena) { upb_MiniTableField field = {999, UPB_SIZE(12, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return (google_protobuf_UninterpretedOption**)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); + return (google_protobuf_UninterpretedOption**)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg), + &field, size, arena); } UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_MessageOptions_add_uninterpreted_option(google_protobuf_MessageOptions* msg, upb_Arena* arena) { upb_MiniTableField field = {999, UPB_SIZE(12, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray( + UPB_UPCAST(msg), &field, arena); if (!arr || !_upb_Array_ResizeUninitialized( arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; @@ -3725,7 +3863,8 @@ UPB_INLINE google_protobuf_FieldOptions* google_protobuf_FieldOptions_new(upb_Ar UPB_INLINE google_protobuf_FieldOptions* google_protobuf_FieldOptions_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_FieldOptions* ret = google_protobuf_FieldOptions_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__FieldOptions_msg_init, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__FieldOptions_msg_init, NULL, 0, arena) != + kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -3735,165 +3874,174 @@ UPB_INLINE google_protobuf_FieldOptions* google_protobuf_FieldOptions_parse_ex(c int options, upb_Arena* arena) { google_protobuf_FieldOptions* ret = google_protobuf_FieldOptions_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__FieldOptions_msg_init, extreg, options, arena) != - kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__FieldOptions_msg_init, extreg, options, + arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_FieldOptions_serialize(const google_protobuf_FieldOptions* msg, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__FieldOptions_msg_init, 0, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__FieldOptions_msg_init, 0, arena, &ptr, len); return ptr; } UPB_INLINE char* google_protobuf_FieldOptions_serialize_ex(const google_protobuf_FieldOptions* msg, int options, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__FieldOptions_msg_init, options, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__FieldOptions_msg_init, options, arena, &ptr, len); return ptr; } UPB_INLINE void google_protobuf_FieldOptions_clear_ctype(google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {1, 4, 1, 3, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_FieldOptions_ctype(const google_protobuf_FieldOptions* msg) { int32_t default_val = 0; int32_t ret; const upb_MiniTableField field = {1, 4, 1, 3, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FieldOptions_has_ctype(const google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {1, 4, 1, 3, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldOptions_clear_packed(google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {2, 8, 2, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_FieldOptions_packed(const google_protobuf_FieldOptions* msg) { bool default_val = false; bool ret; const upb_MiniTableField field = {2, 8, 2, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FieldOptions_has_packed(const google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {2, 8, 2, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldOptions_clear_deprecated(google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {3, 9, 3, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_FieldOptions_deprecated(const google_protobuf_FieldOptions* msg) { bool default_val = false; bool ret; const upb_MiniTableField field = {3, 9, 3, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FieldOptions_has_deprecated(const google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {3, 9, 3, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldOptions_clear_lazy(google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {5, 10, 4, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_FieldOptions_lazy(const google_protobuf_FieldOptions* msg) { bool default_val = false; bool ret; const upb_MiniTableField field = {5, 10, 4, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FieldOptions_has_lazy(const google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {5, 10, 4, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldOptions_clear_jstype(google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {6, 12, 5, 4, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_FieldOptions_jstype(const google_protobuf_FieldOptions* msg) { int32_t default_val = 0; int32_t ret; const upb_MiniTableField field = {6, 12, 5, 4, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FieldOptions_has_jstype(const google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {6, 12, 5, 4, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldOptions_clear_weak(google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {10, 16, 6, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_FieldOptions_weak(const google_protobuf_FieldOptions* msg) { bool default_val = false; bool ret; const upb_MiniTableField field = {10, 16, 6, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FieldOptions_has_weak(const google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {10, 16, 6, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldOptions_clear_unverified_lazy(google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {15, 17, 7, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_FieldOptions_unverified_lazy(const google_protobuf_FieldOptions* msg) { bool default_val = false; bool ret; const upb_MiniTableField field = {15, 17, 7, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FieldOptions_has_unverified_lazy(const google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {15, 17, 7, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldOptions_clear_debug_redact(google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {16, 18, 8, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_FieldOptions_debug_redact(const google_protobuf_FieldOptions* msg) { bool default_val = false; bool ret; const upb_MiniTableField field = {16, 18, 8, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FieldOptions_has_debug_redact(const google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {16, 18, 8, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldOptions_clear_retention(google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {17, 20, 9, 5, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_FieldOptions_retention(const google_protobuf_FieldOptions* msg) { int32_t default_val = 0; int32_t ret; const upb_MiniTableField field = {17, 20, 9, 5, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FieldOptions_has_retention(const google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {17, 20, 9, 5, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldOptions_clear_targets(google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {19, 24, 0, 6, 14, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t const* google_protobuf_FieldOptions_targets(const google_protobuf_FieldOptions* msg, size_t* size) { const upb_MiniTableField field = {19, 24, 0, 6, 14, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (int32_t const*)_upb_array_constptr(arr); @@ -3904,16 +4052,16 @@ UPB_INLINE int32_t const* google_protobuf_FieldOptions_targets(const google_prot } UPB_INLINE const upb_Array* _google_protobuf_FieldOptions_targets_upb_array(const google_protobuf_FieldOptions* msg, size_t* size) { const upb_MiniTableField field = {19, 24, 0, 6, 14, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } -UPB_INLINE upb_Array* _google_protobuf_FieldOptions_targets_mutable_upb_array(const google_protobuf_FieldOptions* msg, size_t* size, upb_Arena* arena) { +UPB_INLINE upb_Array* _google_protobuf_FieldOptions_targets_mutable_upb_array(google_protobuf_FieldOptions* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = {19, 24, 0, 6, 14, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - (upb_Message*)msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), + &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -3921,11 +4069,11 @@ UPB_INLINE upb_Array* _google_protobuf_FieldOptions_targets_mutable_upb_array(co } UPB_INLINE void google_protobuf_FieldOptions_clear_edition_defaults(google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {20, UPB_SIZE(28, 32), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_FieldOptions_EditionDefault* const* google_protobuf_FieldOptions_edition_defaults(const google_protobuf_FieldOptions* msg, size_t* size) { const upb_MiniTableField field = {20, UPB_SIZE(28, 32), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_FieldOptions_EditionDefault* const*)_upb_array_constptr(arr); @@ -3936,16 +4084,16 @@ UPB_INLINE const google_protobuf_FieldOptions_EditionDefault* const* google_prot } UPB_INLINE const upb_Array* _google_protobuf_FieldOptions_edition_defaults_upb_array(const google_protobuf_FieldOptions* msg, size_t* size) { const upb_MiniTableField field = {20, UPB_SIZE(28, 32), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } -UPB_INLINE upb_Array* _google_protobuf_FieldOptions_edition_defaults_mutable_upb_array(const google_protobuf_FieldOptions* msg, size_t* size, upb_Arena* arena) { +UPB_INLINE upb_Array* _google_protobuf_FieldOptions_edition_defaults_mutable_upb_array(google_protobuf_FieldOptions* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = {20, UPB_SIZE(28, 32), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - (upb_Message*)msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), + &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -3953,26 +4101,27 @@ UPB_INLINE upb_Array* _google_protobuf_FieldOptions_edition_defaults_mutable_upb } UPB_INLINE void google_protobuf_FieldOptions_clear_features(google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {21, UPB_SIZE(32, 40), 10, 1, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_FeatureSet* google_protobuf_FieldOptions_features(const google_protobuf_FieldOptions* msg) { const google_protobuf_FeatureSet* default_val = NULL; const google_protobuf_FeatureSet* ret; const upb_MiniTableField field = {21, UPB_SIZE(32, 40), 10, 1, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FieldOptions_has_features(const google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {21, UPB_SIZE(32, 40), 10, 1, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldOptions_clear_uninterpreted_option(google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {999, UPB_SIZE(36, 48), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_FieldOptions_uninterpreted_option(const google_protobuf_FieldOptions* msg, size_t* size) { const upb_MiniTableField field = {999, UPB_SIZE(36, 48), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_UninterpretedOption* const*)_upb_array_constptr(arr); @@ -3983,16 +4132,16 @@ UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_Fie } UPB_INLINE const upb_Array* _google_protobuf_FieldOptions_uninterpreted_option_upb_array(const google_protobuf_FieldOptions* msg, size_t* size) { const upb_MiniTableField field = {999, UPB_SIZE(36, 48), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } -UPB_INLINE upb_Array* _google_protobuf_FieldOptions_uninterpreted_option_mutable_upb_array(const google_protobuf_FieldOptions* msg, size_t* size, upb_Arena* arena) { +UPB_INLINE upb_Array* _google_protobuf_FieldOptions_uninterpreted_option_mutable_upb_array(google_protobuf_FieldOptions* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = {999, UPB_SIZE(36, 48), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - (upb_Message*)msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), + &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -4001,43 +4150,43 @@ UPB_INLINE upb_Array* _google_protobuf_FieldOptions_uninterpreted_option_mutable UPB_INLINE void google_protobuf_FieldOptions_set_ctype(google_protobuf_FieldOptions *msg, int32_t value) { const upb_MiniTableField field = {1, 4, 1, 3, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FieldOptions_set_packed(google_protobuf_FieldOptions *msg, bool value) { const upb_MiniTableField field = {2, 8, 2, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FieldOptions_set_deprecated(google_protobuf_FieldOptions *msg, bool value) { const upb_MiniTableField field = {3, 9, 3, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FieldOptions_set_lazy(google_protobuf_FieldOptions *msg, bool value) { const upb_MiniTableField field = {5, 10, 4, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FieldOptions_set_jstype(google_protobuf_FieldOptions *msg, int32_t value) { const upb_MiniTableField field = {6, 12, 5, 4, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FieldOptions_set_weak(google_protobuf_FieldOptions *msg, bool value) { const upb_MiniTableField field = {10, 16, 6, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FieldOptions_set_unverified_lazy(google_protobuf_FieldOptions *msg, bool value) { const upb_MiniTableField field = {15, 17, 7, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FieldOptions_set_debug_redact(google_protobuf_FieldOptions *msg, bool value) { const upb_MiniTableField field = {16, 18, 8, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FieldOptions_set_retention(google_protobuf_FieldOptions *msg, int32_t value) { const upb_MiniTableField field = {17, 20, 9, 5, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE int32_t* google_protobuf_FieldOptions_mutable_targets(google_protobuf_FieldOptions* msg, size_t* size) { upb_MiniTableField field = {19, 24, 0, 6, 14, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetMutableArray(msg, &field); + upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (int32_t*)_upb_array_ptr(arr); @@ -4048,11 +4197,13 @@ UPB_INLINE int32_t* google_protobuf_FieldOptions_mutable_targets(google_protobuf } UPB_INLINE int32_t* google_protobuf_FieldOptions_resize_targets(google_protobuf_FieldOptions* msg, size_t size, upb_Arena* arena) { upb_MiniTableField field = {19, 24, 0, 6, 14, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return (int32_t*)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); + return (int32_t*)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg), + &field, size, arena); } UPB_INLINE bool google_protobuf_FieldOptions_add_targets(google_protobuf_FieldOptions* msg, int32_t val, upb_Arena* arena) { upb_MiniTableField field = {19, 24, 0, 6, 14, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray( + UPB_UPCAST(msg), &field, arena); if (!arr || !_upb_Array_ResizeUninitialized( arr, arr->UPB_PRIVATE(size) + 1, arena)) { return false; @@ -4063,7 +4214,7 @@ UPB_INLINE bool google_protobuf_FieldOptions_add_targets(google_protobuf_FieldOp } UPB_INLINE google_protobuf_FieldOptions_EditionDefault** google_protobuf_FieldOptions_mutable_edition_defaults(google_protobuf_FieldOptions* msg, size_t* size) { upb_MiniTableField field = {20, UPB_SIZE(28, 32), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetMutableArray(msg, &field); + upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_FieldOptions_EditionDefault**)_upb_array_ptr(arr); @@ -4074,11 +4225,13 @@ UPB_INLINE google_protobuf_FieldOptions_EditionDefault** google_protobuf_FieldOp } UPB_INLINE google_protobuf_FieldOptions_EditionDefault** google_protobuf_FieldOptions_resize_edition_defaults(google_protobuf_FieldOptions* msg, size_t size, upb_Arena* arena) { upb_MiniTableField field = {20, UPB_SIZE(28, 32), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return (google_protobuf_FieldOptions_EditionDefault**)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); + return (google_protobuf_FieldOptions_EditionDefault**)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg), + &field, size, arena); } UPB_INLINE struct google_protobuf_FieldOptions_EditionDefault* google_protobuf_FieldOptions_add_edition_defaults(google_protobuf_FieldOptions* msg, upb_Arena* arena) { upb_MiniTableField field = {20, UPB_SIZE(28, 32), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray( + UPB_UPCAST(msg), &field, arena); if (!arr || !_upb_Array_ResizeUninitialized( arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; @@ -4091,7 +4244,7 @@ UPB_INLINE struct google_protobuf_FieldOptions_EditionDefault* google_protobuf_F } UPB_INLINE void google_protobuf_FieldOptions_set_features(google_protobuf_FieldOptions *msg, google_protobuf_FeatureSet* value) { const upb_MiniTableField field = {21, UPB_SIZE(32, 40), 10, 1, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE struct google_protobuf_FeatureSet* google_protobuf_FieldOptions_mutable_features(google_protobuf_FieldOptions* msg, upb_Arena* arena) { struct google_protobuf_FeatureSet* sub = (struct google_protobuf_FeatureSet*)google_protobuf_FieldOptions_features(msg); @@ -4103,7 +4256,7 @@ UPB_INLINE struct google_protobuf_FeatureSet* google_protobuf_FieldOptions_mutab } UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_FieldOptions_mutable_uninterpreted_option(google_protobuf_FieldOptions* msg, size_t* size) { upb_MiniTableField field = {999, UPB_SIZE(36, 48), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetMutableArray(msg, &field); + upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_UninterpretedOption**)_upb_array_ptr(arr); @@ -4114,11 +4267,13 @@ UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_FieldOptions_mu } UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_FieldOptions_resize_uninterpreted_option(google_protobuf_FieldOptions* msg, size_t size, upb_Arena* arena) { upb_MiniTableField field = {999, UPB_SIZE(36, 48), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return (google_protobuf_UninterpretedOption**)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); + return (google_protobuf_UninterpretedOption**)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg), + &field, size, arena); } UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_FieldOptions_add_uninterpreted_option(google_protobuf_FieldOptions* msg, upb_Arena* arena) { upb_MiniTableField field = {999, UPB_SIZE(36, 48), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray( + UPB_UPCAST(msg), &field, arena); if (!arr || !_upb_Array_ResizeUninitialized( arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; @@ -4138,7 +4293,8 @@ UPB_INLINE google_protobuf_FieldOptions_EditionDefault* google_protobuf_FieldOpt UPB_INLINE google_protobuf_FieldOptions_EditionDefault* google_protobuf_FieldOptions_EditionDefault_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_FieldOptions_EditionDefault* ret = google_protobuf_FieldOptions_EditionDefault_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__FieldOptions__EditionDefault_msg_init, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__FieldOptions__EditionDefault_msg_init, NULL, 0, arena) != + kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -4148,61 +4304,63 @@ UPB_INLINE google_protobuf_FieldOptions_EditionDefault* google_protobuf_FieldOpt int options, upb_Arena* arena) { google_protobuf_FieldOptions_EditionDefault* ret = google_protobuf_FieldOptions_EditionDefault_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__FieldOptions__EditionDefault_msg_init, extreg, options, arena) != - kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__FieldOptions__EditionDefault_msg_init, extreg, options, + arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_FieldOptions_EditionDefault_serialize(const google_protobuf_FieldOptions_EditionDefault* msg, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__FieldOptions__EditionDefault_msg_init, 0, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__FieldOptions__EditionDefault_msg_init, 0, arena, &ptr, len); return ptr; } UPB_INLINE char* google_protobuf_FieldOptions_EditionDefault_serialize_ex(const google_protobuf_FieldOptions_EditionDefault* msg, int options, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__FieldOptions__EditionDefault_msg_init, options, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__FieldOptions__EditionDefault_msg_init, options, arena, &ptr, len); return ptr; } UPB_INLINE void google_protobuf_FieldOptions_EditionDefault_clear_value(google_protobuf_FieldOptions_EditionDefault* msg) { const upb_MiniTableField field = {2, 8, 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_FieldOptions_EditionDefault_value(const google_protobuf_FieldOptions_EditionDefault* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; const upb_MiniTableField field = {2, 8, 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FieldOptions_EditionDefault_has_value(const google_protobuf_FieldOptions_EditionDefault* msg) { const upb_MiniTableField field = {2, 8, 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldOptions_EditionDefault_clear_edition(google_protobuf_FieldOptions_EditionDefault* msg) { const upb_MiniTableField field = {3, 4, 2, 0, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_FieldOptions_EditionDefault_edition(const google_protobuf_FieldOptions_EditionDefault* msg) { int32_t default_val = 0; int32_t ret; const upb_MiniTableField field = {3, 4, 2, 0, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FieldOptions_EditionDefault_has_edition(const google_protobuf_FieldOptions_EditionDefault* msg) { const upb_MiniTableField field = {3, 4, 2, 0, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldOptions_EditionDefault_set_value(google_protobuf_FieldOptions_EditionDefault *msg, upb_StringView value) { const upb_MiniTableField field = {2, 8, 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FieldOptions_EditionDefault_set_edition(google_protobuf_FieldOptions_EditionDefault *msg, int32_t value) { const upb_MiniTableField field = {3, 4, 2, 0, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } /* google.protobuf.OneofOptions */ @@ -4213,7 +4371,8 @@ UPB_INLINE google_protobuf_OneofOptions* google_protobuf_OneofOptions_new(upb_Ar UPB_INLINE google_protobuf_OneofOptions* google_protobuf_OneofOptions_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_OneofOptions* ret = google_protobuf_OneofOptions_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__OneofOptions_msg_init, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__OneofOptions_msg_init, NULL, 0, arena) != + kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -4223,45 +4382,46 @@ UPB_INLINE google_protobuf_OneofOptions* google_protobuf_OneofOptions_parse_ex(c int options, upb_Arena* arena) { google_protobuf_OneofOptions* ret = google_protobuf_OneofOptions_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__OneofOptions_msg_init, extreg, options, arena) != - kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__OneofOptions_msg_init, extreg, options, + arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_OneofOptions_serialize(const google_protobuf_OneofOptions* msg, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__OneofOptions_msg_init, 0, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__OneofOptions_msg_init, 0, arena, &ptr, len); return ptr; } UPB_INLINE char* google_protobuf_OneofOptions_serialize_ex(const google_protobuf_OneofOptions* msg, int options, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__OneofOptions_msg_init, options, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__OneofOptions_msg_init, options, arena, &ptr, len); return ptr; } UPB_INLINE void google_protobuf_OneofOptions_clear_features(google_protobuf_OneofOptions* msg) { const upb_MiniTableField field = {1, UPB_SIZE(4, 8), 1, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_FeatureSet* google_protobuf_OneofOptions_features(const google_protobuf_OneofOptions* msg) { const google_protobuf_FeatureSet* default_val = NULL; const google_protobuf_FeatureSet* ret; const upb_MiniTableField field = {1, UPB_SIZE(4, 8), 1, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_OneofOptions_has_features(const google_protobuf_OneofOptions* msg) { const upb_MiniTableField field = {1, UPB_SIZE(4, 8), 1, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_OneofOptions_clear_uninterpreted_option(google_protobuf_OneofOptions* msg) { const upb_MiniTableField field = {999, UPB_SIZE(8, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_OneofOptions_uninterpreted_option(const google_protobuf_OneofOptions* msg, size_t* size) { const upb_MiniTableField field = {999, UPB_SIZE(8, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_UninterpretedOption* const*)_upb_array_constptr(arr); @@ -4272,16 +4432,16 @@ UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_One } UPB_INLINE const upb_Array* _google_protobuf_OneofOptions_uninterpreted_option_upb_array(const google_protobuf_OneofOptions* msg, size_t* size) { const upb_MiniTableField field = {999, UPB_SIZE(8, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } -UPB_INLINE upb_Array* _google_protobuf_OneofOptions_uninterpreted_option_mutable_upb_array(const google_protobuf_OneofOptions* msg, size_t* size, upb_Arena* arena) { +UPB_INLINE upb_Array* _google_protobuf_OneofOptions_uninterpreted_option_mutable_upb_array(google_protobuf_OneofOptions* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = {999, UPB_SIZE(8, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - (upb_Message*)msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), + &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -4290,7 +4450,7 @@ UPB_INLINE upb_Array* _google_protobuf_OneofOptions_uninterpreted_option_mutable UPB_INLINE void google_protobuf_OneofOptions_set_features(google_protobuf_OneofOptions *msg, google_protobuf_FeatureSet* value) { const upb_MiniTableField field = {1, UPB_SIZE(4, 8), 1, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE struct google_protobuf_FeatureSet* google_protobuf_OneofOptions_mutable_features(google_protobuf_OneofOptions* msg, upb_Arena* arena) { struct google_protobuf_FeatureSet* sub = (struct google_protobuf_FeatureSet*)google_protobuf_OneofOptions_features(msg); @@ -4302,7 +4462,7 @@ UPB_INLINE struct google_protobuf_FeatureSet* google_protobuf_OneofOptions_mutab } UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_OneofOptions_mutable_uninterpreted_option(google_protobuf_OneofOptions* msg, size_t* size) { upb_MiniTableField field = {999, UPB_SIZE(8, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetMutableArray(msg, &field); + upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_UninterpretedOption**)_upb_array_ptr(arr); @@ -4313,11 +4473,13 @@ UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_OneofOptions_mu } UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_OneofOptions_resize_uninterpreted_option(google_protobuf_OneofOptions* msg, size_t size, upb_Arena* arena) { upb_MiniTableField field = {999, UPB_SIZE(8, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return (google_protobuf_UninterpretedOption**)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); + return (google_protobuf_UninterpretedOption**)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg), + &field, size, arena); } UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_OneofOptions_add_uninterpreted_option(google_protobuf_OneofOptions* msg, upb_Arena* arena) { upb_MiniTableField field = {999, UPB_SIZE(8, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray( + UPB_UPCAST(msg), &field, arena); if (!arr || !_upb_Array_ResizeUninitialized( arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; @@ -4337,7 +4499,8 @@ UPB_INLINE google_protobuf_EnumOptions* google_protobuf_EnumOptions_new(upb_Aren UPB_INLINE google_protobuf_EnumOptions* google_protobuf_EnumOptions_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_EnumOptions* ret = google_protobuf_EnumOptions_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__EnumOptions_msg_init, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__EnumOptions_msg_init, NULL, 0, arena) != + kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -4347,90 +4510,94 @@ UPB_INLINE google_protobuf_EnumOptions* google_protobuf_EnumOptions_parse_ex(con int options, upb_Arena* arena) { google_protobuf_EnumOptions* ret = google_protobuf_EnumOptions_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__EnumOptions_msg_init, extreg, options, arena) != - kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__EnumOptions_msg_init, extreg, options, + arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_EnumOptions_serialize(const google_protobuf_EnumOptions* msg, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__EnumOptions_msg_init, 0, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__EnumOptions_msg_init, 0, arena, &ptr, len); return ptr; } UPB_INLINE char* google_protobuf_EnumOptions_serialize_ex(const google_protobuf_EnumOptions* msg, int options, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__EnumOptions_msg_init, options, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__EnumOptions_msg_init, options, arena, &ptr, len); return ptr; } UPB_INLINE void google_protobuf_EnumOptions_clear_allow_alias(google_protobuf_EnumOptions* msg) { const upb_MiniTableField field = {2, 1, 1, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_EnumOptions_allow_alias(const google_protobuf_EnumOptions* msg) { bool default_val = false; bool ret; const upb_MiniTableField field = {2, 1, 1, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_EnumOptions_has_allow_alias(const google_protobuf_EnumOptions* msg) { const upb_MiniTableField field = {2, 1, 1, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_EnumOptions_clear_deprecated(google_protobuf_EnumOptions* msg) { const upb_MiniTableField field = {3, 2, 2, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_EnumOptions_deprecated(const google_protobuf_EnumOptions* msg) { bool default_val = false; bool ret; const upb_MiniTableField field = {3, 2, 2, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_EnumOptions_has_deprecated(const google_protobuf_EnumOptions* msg) { const upb_MiniTableField field = {3, 2, 2, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_EnumOptions_clear_deprecated_legacy_json_field_conflicts(google_protobuf_EnumOptions* msg) { const upb_MiniTableField field = {6, 3, 3, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_EnumOptions_deprecated_legacy_json_field_conflicts(const google_protobuf_EnumOptions* msg) { bool default_val = false; bool ret; const upb_MiniTableField field = {6, 3, 3, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_EnumOptions_has_deprecated_legacy_json_field_conflicts(const google_protobuf_EnumOptions* msg) { const upb_MiniTableField field = {6, 3, 3, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_EnumOptions_clear_features(google_protobuf_EnumOptions* msg) { const upb_MiniTableField field = {7, UPB_SIZE(4, 8), 4, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_FeatureSet* google_protobuf_EnumOptions_features(const google_protobuf_EnumOptions* msg) { const google_protobuf_FeatureSet* default_val = NULL; const google_protobuf_FeatureSet* ret; const upb_MiniTableField field = {7, UPB_SIZE(4, 8), 4, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_EnumOptions_has_features(const google_protobuf_EnumOptions* msg) { const upb_MiniTableField field = {7, UPB_SIZE(4, 8), 4, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_EnumOptions_clear_uninterpreted_option(google_protobuf_EnumOptions* msg) { const upb_MiniTableField field = {999, UPB_SIZE(8, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_EnumOptions_uninterpreted_option(const google_protobuf_EnumOptions* msg, size_t* size) { const upb_MiniTableField field = {999, UPB_SIZE(8, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_UninterpretedOption* const*)_upb_array_constptr(arr); @@ -4441,16 +4608,16 @@ UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_Enu } UPB_INLINE const upb_Array* _google_protobuf_EnumOptions_uninterpreted_option_upb_array(const google_protobuf_EnumOptions* msg, size_t* size) { const upb_MiniTableField field = {999, UPB_SIZE(8, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } -UPB_INLINE upb_Array* _google_protobuf_EnumOptions_uninterpreted_option_mutable_upb_array(const google_protobuf_EnumOptions* msg, size_t* size, upb_Arena* arena) { +UPB_INLINE upb_Array* _google_protobuf_EnumOptions_uninterpreted_option_mutable_upb_array(google_protobuf_EnumOptions* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = {999, UPB_SIZE(8, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - (upb_Message*)msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), + &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -4459,19 +4626,19 @@ UPB_INLINE upb_Array* _google_protobuf_EnumOptions_uninterpreted_option_mutable_ UPB_INLINE void google_protobuf_EnumOptions_set_allow_alias(google_protobuf_EnumOptions *msg, bool value) { const upb_MiniTableField field = {2, 1, 1, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_EnumOptions_set_deprecated(google_protobuf_EnumOptions *msg, bool value) { const upb_MiniTableField field = {3, 2, 2, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_EnumOptions_set_deprecated_legacy_json_field_conflicts(google_protobuf_EnumOptions *msg, bool value) { const upb_MiniTableField field = {6, 3, 3, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_EnumOptions_set_features(google_protobuf_EnumOptions *msg, google_protobuf_FeatureSet* value) { const upb_MiniTableField field = {7, UPB_SIZE(4, 8), 4, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE struct google_protobuf_FeatureSet* google_protobuf_EnumOptions_mutable_features(google_protobuf_EnumOptions* msg, upb_Arena* arena) { struct google_protobuf_FeatureSet* sub = (struct google_protobuf_FeatureSet*)google_protobuf_EnumOptions_features(msg); @@ -4483,7 +4650,7 @@ UPB_INLINE struct google_protobuf_FeatureSet* google_protobuf_EnumOptions_mutabl } UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_EnumOptions_mutable_uninterpreted_option(google_protobuf_EnumOptions* msg, size_t* size) { upb_MiniTableField field = {999, UPB_SIZE(8, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetMutableArray(msg, &field); + upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_UninterpretedOption**)_upb_array_ptr(arr); @@ -4494,11 +4661,13 @@ UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_EnumOptions_mut } UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_EnumOptions_resize_uninterpreted_option(google_protobuf_EnumOptions* msg, size_t size, upb_Arena* arena) { upb_MiniTableField field = {999, UPB_SIZE(8, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return (google_protobuf_UninterpretedOption**)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); + return (google_protobuf_UninterpretedOption**)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg), + &field, size, arena); } UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_EnumOptions_add_uninterpreted_option(google_protobuf_EnumOptions* msg, upb_Arena* arena) { upb_MiniTableField field = {999, UPB_SIZE(8, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray( + UPB_UPCAST(msg), &field, arena); if (!arr || !_upb_Array_ResizeUninitialized( arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; @@ -4518,7 +4687,8 @@ UPB_INLINE google_protobuf_EnumValueOptions* google_protobuf_EnumValueOptions_ne UPB_INLINE google_protobuf_EnumValueOptions* google_protobuf_EnumValueOptions_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_EnumValueOptions* ret = google_protobuf_EnumValueOptions_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__EnumValueOptions_msg_init, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__EnumValueOptions_msg_init, NULL, 0, arena) != + kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -4528,75 +4698,78 @@ UPB_INLINE google_protobuf_EnumValueOptions* google_protobuf_EnumValueOptions_pa int options, upb_Arena* arena) { google_protobuf_EnumValueOptions* ret = google_protobuf_EnumValueOptions_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__EnumValueOptions_msg_init, extreg, options, arena) != - kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__EnumValueOptions_msg_init, extreg, options, + arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_EnumValueOptions_serialize(const google_protobuf_EnumValueOptions* msg, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__EnumValueOptions_msg_init, 0, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__EnumValueOptions_msg_init, 0, arena, &ptr, len); return ptr; } UPB_INLINE char* google_protobuf_EnumValueOptions_serialize_ex(const google_protobuf_EnumValueOptions* msg, int options, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__EnumValueOptions_msg_init, options, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__EnumValueOptions_msg_init, options, arena, &ptr, len); return ptr; } UPB_INLINE void google_protobuf_EnumValueOptions_clear_deprecated(google_protobuf_EnumValueOptions* msg) { const upb_MiniTableField field = {1, 1, 1, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_EnumValueOptions_deprecated(const google_protobuf_EnumValueOptions* msg) { bool default_val = false; bool ret; const upb_MiniTableField field = {1, 1, 1, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_EnumValueOptions_has_deprecated(const google_protobuf_EnumValueOptions* msg) { const upb_MiniTableField field = {1, 1, 1, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_EnumValueOptions_clear_features(google_protobuf_EnumValueOptions* msg) { const upb_MiniTableField field = {2, UPB_SIZE(4, 8), 2, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_FeatureSet* google_protobuf_EnumValueOptions_features(const google_protobuf_EnumValueOptions* msg) { const google_protobuf_FeatureSet* default_val = NULL; const google_protobuf_FeatureSet* ret; const upb_MiniTableField field = {2, UPB_SIZE(4, 8), 2, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_EnumValueOptions_has_features(const google_protobuf_EnumValueOptions* msg) { const upb_MiniTableField field = {2, UPB_SIZE(4, 8), 2, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_EnumValueOptions_clear_debug_redact(google_protobuf_EnumValueOptions* msg) { const upb_MiniTableField field = {3, UPB_SIZE(8, 2), 3, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_EnumValueOptions_debug_redact(const google_protobuf_EnumValueOptions* msg) { bool default_val = false; bool ret; const upb_MiniTableField field = {3, UPB_SIZE(8, 2), 3, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_EnumValueOptions_has_debug_redact(const google_protobuf_EnumValueOptions* msg) { const upb_MiniTableField field = {3, UPB_SIZE(8, 2), 3, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_EnumValueOptions_clear_uninterpreted_option(google_protobuf_EnumValueOptions* msg) { const upb_MiniTableField field = {999, UPB_SIZE(12, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_EnumValueOptions_uninterpreted_option(const google_protobuf_EnumValueOptions* msg, size_t* size) { const upb_MiniTableField field = {999, UPB_SIZE(12, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_UninterpretedOption* const*)_upb_array_constptr(arr); @@ -4607,16 +4780,16 @@ UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_Enu } UPB_INLINE const upb_Array* _google_protobuf_EnumValueOptions_uninterpreted_option_upb_array(const google_protobuf_EnumValueOptions* msg, size_t* size) { const upb_MiniTableField field = {999, UPB_SIZE(12, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } -UPB_INLINE upb_Array* _google_protobuf_EnumValueOptions_uninterpreted_option_mutable_upb_array(const google_protobuf_EnumValueOptions* msg, size_t* size, upb_Arena* arena) { +UPB_INLINE upb_Array* _google_protobuf_EnumValueOptions_uninterpreted_option_mutable_upb_array(google_protobuf_EnumValueOptions* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = {999, UPB_SIZE(12, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - (upb_Message*)msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), + &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -4625,11 +4798,11 @@ UPB_INLINE upb_Array* _google_protobuf_EnumValueOptions_uninterpreted_option_mut UPB_INLINE void google_protobuf_EnumValueOptions_set_deprecated(google_protobuf_EnumValueOptions *msg, bool value) { const upb_MiniTableField field = {1, 1, 1, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_EnumValueOptions_set_features(google_protobuf_EnumValueOptions *msg, google_protobuf_FeatureSet* value) { const upb_MiniTableField field = {2, UPB_SIZE(4, 8), 2, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE struct google_protobuf_FeatureSet* google_protobuf_EnumValueOptions_mutable_features(google_protobuf_EnumValueOptions* msg, upb_Arena* arena) { struct google_protobuf_FeatureSet* sub = (struct google_protobuf_FeatureSet*)google_protobuf_EnumValueOptions_features(msg); @@ -4641,11 +4814,11 @@ UPB_INLINE struct google_protobuf_FeatureSet* google_protobuf_EnumValueOptions_m } UPB_INLINE void google_protobuf_EnumValueOptions_set_debug_redact(google_protobuf_EnumValueOptions *msg, bool value) { const upb_MiniTableField field = {3, UPB_SIZE(8, 2), 3, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_EnumValueOptions_mutable_uninterpreted_option(google_protobuf_EnumValueOptions* msg, size_t* size) { upb_MiniTableField field = {999, UPB_SIZE(12, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetMutableArray(msg, &field); + upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_UninterpretedOption**)_upb_array_ptr(arr); @@ -4656,11 +4829,13 @@ UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_EnumValueOption } UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_EnumValueOptions_resize_uninterpreted_option(google_protobuf_EnumValueOptions* msg, size_t size, upb_Arena* arena) { upb_MiniTableField field = {999, UPB_SIZE(12, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return (google_protobuf_UninterpretedOption**)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); + return (google_protobuf_UninterpretedOption**)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg), + &field, size, arena); } UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_EnumValueOptions_add_uninterpreted_option(google_protobuf_EnumValueOptions* msg, upb_Arena* arena) { upb_MiniTableField field = {999, UPB_SIZE(12, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray( + UPB_UPCAST(msg), &field, arena); if (!arr || !_upb_Array_ResizeUninitialized( arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; @@ -4680,7 +4855,8 @@ UPB_INLINE google_protobuf_ServiceOptions* google_protobuf_ServiceOptions_new(up UPB_INLINE google_protobuf_ServiceOptions* google_protobuf_ServiceOptions_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_ServiceOptions* ret = google_protobuf_ServiceOptions_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__ServiceOptions_msg_init, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__ServiceOptions_msg_init, NULL, 0, arena) != + kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -4690,60 +4866,62 @@ UPB_INLINE google_protobuf_ServiceOptions* google_protobuf_ServiceOptions_parse_ int options, upb_Arena* arena) { google_protobuf_ServiceOptions* ret = google_protobuf_ServiceOptions_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__ServiceOptions_msg_init, extreg, options, arena) != - kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__ServiceOptions_msg_init, extreg, options, + arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_ServiceOptions_serialize(const google_protobuf_ServiceOptions* msg, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__ServiceOptions_msg_init, 0, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__ServiceOptions_msg_init, 0, arena, &ptr, len); return ptr; } UPB_INLINE char* google_protobuf_ServiceOptions_serialize_ex(const google_protobuf_ServiceOptions* msg, int options, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__ServiceOptions_msg_init, options, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__ServiceOptions_msg_init, options, arena, &ptr, len); return ptr; } UPB_INLINE void google_protobuf_ServiceOptions_clear_deprecated(google_protobuf_ServiceOptions* msg) { const upb_MiniTableField field = {33, 1, 1, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_ServiceOptions_deprecated(const google_protobuf_ServiceOptions* msg) { bool default_val = false; bool ret; const upb_MiniTableField field = {33, 1, 1, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_ServiceOptions_has_deprecated(const google_protobuf_ServiceOptions* msg) { const upb_MiniTableField field = {33, 1, 1, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_ServiceOptions_clear_features(google_protobuf_ServiceOptions* msg) { const upb_MiniTableField field = {34, UPB_SIZE(4, 8), 2, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_FeatureSet* google_protobuf_ServiceOptions_features(const google_protobuf_ServiceOptions* msg) { const google_protobuf_FeatureSet* default_val = NULL; const google_protobuf_FeatureSet* ret; const upb_MiniTableField field = {34, UPB_SIZE(4, 8), 2, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_ServiceOptions_has_features(const google_protobuf_ServiceOptions* msg) { const upb_MiniTableField field = {34, UPB_SIZE(4, 8), 2, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_ServiceOptions_clear_uninterpreted_option(google_protobuf_ServiceOptions* msg) { const upb_MiniTableField field = {999, UPB_SIZE(8, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_ServiceOptions_uninterpreted_option(const google_protobuf_ServiceOptions* msg, size_t* size) { const upb_MiniTableField field = {999, UPB_SIZE(8, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_UninterpretedOption* const*)_upb_array_constptr(arr); @@ -4754,16 +4932,16 @@ UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_Ser } UPB_INLINE const upb_Array* _google_protobuf_ServiceOptions_uninterpreted_option_upb_array(const google_protobuf_ServiceOptions* msg, size_t* size) { const upb_MiniTableField field = {999, UPB_SIZE(8, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } -UPB_INLINE upb_Array* _google_protobuf_ServiceOptions_uninterpreted_option_mutable_upb_array(const google_protobuf_ServiceOptions* msg, size_t* size, upb_Arena* arena) { +UPB_INLINE upb_Array* _google_protobuf_ServiceOptions_uninterpreted_option_mutable_upb_array(google_protobuf_ServiceOptions* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = {999, UPB_SIZE(8, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - (upb_Message*)msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), + &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -4772,11 +4950,11 @@ UPB_INLINE upb_Array* _google_protobuf_ServiceOptions_uninterpreted_option_mutab UPB_INLINE void google_protobuf_ServiceOptions_set_deprecated(google_protobuf_ServiceOptions *msg, bool value) { const upb_MiniTableField field = {33, 1, 1, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_ServiceOptions_set_features(google_protobuf_ServiceOptions *msg, google_protobuf_FeatureSet* value) { const upb_MiniTableField field = {34, UPB_SIZE(4, 8), 2, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE struct google_protobuf_FeatureSet* google_protobuf_ServiceOptions_mutable_features(google_protobuf_ServiceOptions* msg, upb_Arena* arena) { struct google_protobuf_FeatureSet* sub = (struct google_protobuf_FeatureSet*)google_protobuf_ServiceOptions_features(msg); @@ -4788,7 +4966,7 @@ UPB_INLINE struct google_protobuf_FeatureSet* google_protobuf_ServiceOptions_mut } UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_ServiceOptions_mutable_uninterpreted_option(google_protobuf_ServiceOptions* msg, size_t* size) { upb_MiniTableField field = {999, UPB_SIZE(8, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetMutableArray(msg, &field); + upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_UninterpretedOption**)_upb_array_ptr(arr); @@ -4799,11 +4977,13 @@ UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_ServiceOptions_ } UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_ServiceOptions_resize_uninterpreted_option(google_protobuf_ServiceOptions* msg, size_t size, upb_Arena* arena) { upb_MiniTableField field = {999, UPB_SIZE(8, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return (google_protobuf_UninterpretedOption**)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); + return (google_protobuf_UninterpretedOption**)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg), + &field, size, arena); } UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_ServiceOptions_add_uninterpreted_option(google_protobuf_ServiceOptions* msg, upb_Arena* arena) { upb_MiniTableField field = {999, UPB_SIZE(8, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray( + UPB_UPCAST(msg), &field, arena); if (!arr || !_upb_Array_ResizeUninitialized( arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; @@ -4823,7 +5003,8 @@ UPB_INLINE google_protobuf_MethodOptions* google_protobuf_MethodOptions_new(upb_ UPB_INLINE google_protobuf_MethodOptions* google_protobuf_MethodOptions_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_MethodOptions* ret = google_protobuf_MethodOptions_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__MethodOptions_msg_init, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__MethodOptions_msg_init, NULL, 0, arena) != + kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -4833,75 +5014,78 @@ UPB_INLINE google_protobuf_MethodOptions* google_protobuf_MethodOptions_parse_ex int options, upb_Arena* arena) { google_protobuf_MethodOptions* ret = google_protobuf_MethodOptions_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__MethodOptions_msg_init, extreg, options, arena) != - kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__MethodOptions_msg_init, extreg, options, + arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_MethodOptions_serialize(const google_protobuf_MethodOptions* msg, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__MethodOptions_msg_init, 0, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__MethodOptions_msg_init, 0, arena, &ptr, len); return ptr; } UPB_INLINE char* google_protobuf_MethodOptions_serialize_ex(const google_protobuf_MethodOptions* msg, int options, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__MethodOptions_msg_init, options, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__MethodOptions_msg_init, options, arena, &ptr, len); return ptr; } UPB_INLINE void google_protobuf_MethodOptions_clear_deprecated(google_protobuf_MethodOptions* msg) { const upb_MiniTableField field = {33, 1, 1, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_MethodOptions_deprecated(const google_protobuf_MethodOptions* msg) { bool default_val = false; bool ret; const upb_MiniTableField field = {33, 1, 1, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_MethodOptions_has_deprecated(const google_protobuf_MethodOptions* msg) { const upb_MiniTableField field = {33, 1, 1, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_MethodOptions_clear_idempotency_level(google_protobuf_MethodOptions* msg) { const upb_MiniTableField field = {34, 4, 2, 2, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_MethodOptions_idempotency_level(const google_protobuf_MethodOptions* msg) { int32_t default_val = 0; int32_t ret; const upb_MiniTableField field = {34, 4, 2, 2, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_MethodOptions_has_idempotency_level(const google_protobuf_MethodOptions* msg) { const upb_MiniTableField field = {34, 4, 2, 2, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_MethodOptions_clear_features(google_protobuf_MethodOptions* msg) { const upb_MiniTableField field = {35, 8, 3, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_FeatureSet* google_protobuf_MethodOptions_features(const google_protobuf_MethodOptions* msg) { const google_protobuf_FeatureSet* default_val = NULL; const google_protobuf_FeatureSet* ret; const upb_MiniTableField field = {35, 8, 3, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_MethodOptions_has_features(const google_protobuf_MethodOptions* msg) { const upb_MiniTableField field = {35, 8, 3, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_MethodOptions_clear_uninterpreted_option(google_protobuf_MethodOptions* msg) { const upb_MiniTableField field = {999, UPB_SIZE(12, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_MethodOptions_uninterpreted_option(const google_protobuf_MethodOptions* msg, size_t* size) { const upb_MiniTableField field = {999, UPB_SIZE(12, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_UninterpretedOption* const*)_upb_array_constptr(arr); @@ -4912,16 +5096,16 @@ UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_Met } UPB_INLINE const upb_Array* _google_protobuf_MethodOptions_uninterpreted_option_upb_array(const google_protobuf_MethodOptions* msg, size_t* size) { const upb_MiniTableField field = {999, UPB_SIZE(12, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } -UPB_INLINE upb_Array* _google_protobuf_MethodOptions_uninterpreted_option_mutable_upb_array(const google_protobuf_MethodOptions* msg, size_t* size, upb_Arena* arena) { +UPB_INLINE upb_Array* _google_protobuf_MethodOptions_uninterpreted_option_mutable_upb_array(google_protobuf_MethodOptions* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = {999, UPB_SIZE(12, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - (upb_Message*)msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), + &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -4930,15 +5114,15 @@ UPB_INLINE upb_Array* _google_protobuf_MethodOptions_uninterpreted_option_mutabl UPB_INLINE void google_protobuf_MethodOptions_set_deprecated(google_protobuf_MethodOptions *msg, bool value) { const upb_MiniTableField field = {33, 1, 1, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_MethodOptions_set_idempotency_level(google_protobuf_MethodOptions *msg, int32_t value) { const upb_MiniTableField field = {34, 4, 2, 2, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_MethodOptions_set_features(google_protobuf_MethodOptions *msg, google_protobuf_FeatureSet* value) { const upb_MiniTableField field = {35, 8, 3, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE struct google_protobuf_FeatureSet* google_protobuf_MethodOptions_mutable_features(google_protobuf_MethodOptions* msg, upb_Arena* arena) { struct google_protobuf_FeatureSet* sub = (struct google_protobuf_FeatureSet*)google_protobuf_MethodOptions_features(msg); @@ -4950,7 +5134,7 @@ UPB_INLINE struct google_protobuf_FeatureSet* google_protobuf_MethodOptions_muta } UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_MethodOptions_mutable_uninterpreted_option(google_protobuf_MethodOptions* msg, size_t* size) { upb_MiniTableField field = {999, UPB_SIZE(12, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetMutableArray(msg, &field); + upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_UninterpretedOption**)_upb_array_ptr(arr); @@ -4961,11 +5145,13 @@ UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_MethodOptions_m } UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_MethodOptions_resize_uninterpreted_option(google_protobuf_MethodOptions* msg, size_t size, upb_Arena* arena) { upb_MiniTableField field = {999, UPB_SIZE(12, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return (google_protobuf_UninterpretedOption**)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); + return (google_protobuf_UninterpretedOption**)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg), + &field, size, arena); } UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_MethodOptions_add_uninterpreted_option(google_protobuf_MethodOptions* msg, upb_Arena* arena) { upb_MiniTableField field = {999, UPB_SIZE(12, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray( + UPB_UPCAST(msg), &field, arena); if (!arr || !_upb_Array_ResizeUninitialized( arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; @@ -4985,7 +5171,8 @@ UPB_INLINE google_protobuf_UninterpretedOption* google_protobuf_UninterpretedOpt UPB_INLINE google_protobuf_UninterpretedOption* google_protobuf_UninterpretedOption_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_UninterpretedOption* ret = google_protobuf_UninterpretedOption_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__UninterpretedOption_msg_init, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__UninterpretedOption_msg_init, NULL, 0, arena) != + kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -4995,30 +5182,30 @@ UPB_INLINE google_protobuf_UninterpretedOption* google_protobuf_UninterpretedOpt int options, upb_Arena* arena) { google_protobuf_UninterpretedOption* ret = google_protobuf_UninterpretedOption_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__UninterpretedOption_msg_init, extreg, options, arena) != - kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__UninterpretedOption_msg_init, extreg, options, + arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_UninterpretedOption_serialize(const google_protobuf_UninterpretedOption* msg, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__UninterpretedOption_msg_init, 0, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__UninterpretedOption_msg_init, 0, arena, &ptr, len); return ptr; } UPB_INLINE char* google_protobuf_UninterpretedOption_serialize_ex(const google_protobuf_UninterpretedOption* msg, int options, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__UninterpretedOption_msg_init, options, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__UninterpretedOption_msg_init, options, arena, &ptr, len); return ptr; } UPB_INLINE void google_protobuf_UninterpretedOption_clear_name(google_protobuf_UninterpretedOption* msg) { const upb_MiniTableField field = {2, UPB_SIZE(4, 8), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_UninterpretedOption_NamePart* const* google_protobuf_UninterpretedOption_name(const google_protobuf_UninterpretedOption* msg, size_t* size) { const upb_MiniTableField field = {2, UPB_SIZE(4, 8), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_UninterpretedOption_NamePart* const*)_upb_array_constptr(arr); @@ -5029,16 +5216,16 @@ UPB_INLINE const google_protobuf_UninterpretedOption_NamePart* const* google_pro } UPB_INLINE const upb_Array* _google_protobuf_UninterpretedOption_name_upb_array(const google_protobuf_UninterpretedOption* msg, size_t* size) { const upb_MiniTableField field = {2, UPB_SIZE(4, 8), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } -UPB_INLINE upb_Array* _google_protobuf_UninterpretedOption_name_mutable_upb_array(const google_protobuf_UninterpretedOption* msg, size_t* size, upb_Arena* arena) { +UPB_INLINE upb_Array* _google_protobuf_UninterpretedOption_name_mutable_upb_array(google_protobuf_UninterpretedOption* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = {2, UPB_SIZE(4, 8), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - (upb_Message*)msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), + &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -5046,98 +5233,104 @@ UPB_INLINE upb_Array* _google_protobuf_UninterpretedOption_name_mutable_upb_arra } UPB_INLINE void google_protobuf_UninterpretedOption_clear_identifier_value(google_protobuf_UninterpretedOption* msg) { const upb_MiniTableField field = {3, UPB_SIZE(8, 16), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_UninterpretedOption_identifier_value(const google_protobuf_UninterpretedOption* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; const upb_MiniTableField field = {3, UPB_SIZE(8, 16), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_UninterpretedOption_has_identifier_value(const google_protobuf_UninterpretedOption* msg) { const upb_MiniTableField field = {3, UPB_SIZE(8, 16), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_UninterpretedOption_clear_positive_int_value(google_protobuf_UninterpretedOption* msg) { const upb_MiniTableField field = {4, UPB_SIZE(16, 32), 2, kUpb_NoSub, 4, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_8Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE uint64_t google_protobuf_UninterpretedOption_positive_int_value(const google_protobuf_UninterpretedOption* msg) { uint64_t default_val = (uint64_t)0ull; uint64_t ret; const upb_MiniTableField field = {4, UPB_SIZE(16, 32), 2, kUpb_NoSub, 4, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_8Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_UninterpretedOption_has_positive_int_value(const google_protobuf_UninterpretedOption* msg) { const upb_MiniTableField field = {4, UPB_SIZE(16, 32), 2, kUpb_NoSub, 4, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_8Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_UninterpretedOption_clear_negative_int_value(google_protobuf_UninterpretedOption* msg) { const upb_MiniTableField field = {5, UPB_SIZE(24, 40), 3, kUpb_NoSub, 3, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_8Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE int64_t google_protobuf_UninterpretedOption_negative_int_value(const google_protobuf_UninterpretedOption* msg) { int64_t default_val = (int64_t)0ll; int64_t ret; const upb_MiniTableField field = {5, UPB_SIZE(24, 40), 3, kUpb_NoSub, 3, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_8Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_UninterpretedOption_has_negative_int_value(const google_protobuf_UninterpretedOption* msg) { const upb_MiniTableField field = {5, UPB_SIZE(24, 40), 3, kUpb_NoSub, 3, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_8Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_UninterpretedOption_clear_double_value(google_protobuf_UninterpretedOption* msg) { const upb_MiniTableField field = {6, UPB_SIZE(32, 48), 4, kUpb_NoSub, 1, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_8Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE double google_protobuf_UninterpretedOption_double_value(const google_protobuf_UninterpretedOption* msg) { double default_val = 0; double ret; const upb_MiniTableField field = {6, UPB_SIZE(32, 48), 4, kUpb_NoSub, 1, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_8Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_UninterpretedOption_has_double_value(const google_protobuf_UninterpretedOption* msg) { const upb_MiniTableField field = {6, UPB_SIZE(32, 48), 4, kUpb_NoSub, 1, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_8Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_UninterpretedOption_clear_string_value(google_protobuf_UninterpretedOption* msg) { const upb_MiniTableField field = {7, UPB_SIZE(40, 56), 5, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_UninterpretedOption_string_value(const google_protobuf_UninterpretedOption* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; const upb_MiniTableField field = {7, UPB_SIZE(40, 56), 5, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_UninterpretedOption_has_string_value(const google_protobuf_UninterpretedOption* msg) { const upb_MiniTableField field = {7, UPB_SIZE(40, 56), 5, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_UninterpretedOption_clear_aggregate_value(google_protobuf_UninterpretedOption* msg) { const upb_MiniTableField field = {8, UPB_SIZE(48, 72), 6, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_UninterpretedOption_aggregate_value(const google_protobuf_UninterpretedOption* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; const upb_MiniTableField field = {8, UPB_SIZE(48, 72), 6, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_UninterpretedOption_has_aggregate_value(const google_protobuf_UninterpretedOption* msg) { const upb_MiniTableField field = {8, UPB_SIZE(48, 72), 6, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE google_protobuf_UninterpretedOption_NamePart** google_protobuf_UninterpretedOption_mutable_name(google_protobuf_UninterpretedOption* msg, size_t* size) { upb_MiniTableField field = {2, UPB_SIZE(4, 8), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetMutableArray(msg, &field); + upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_UninterpretedOption_NamePart**)_upb_array_ptr(arr); @@ -5148,11 +5341,13 @@ UPB_INLINE google_protobuf_UninterpretedOption_NamePart** google_protobuf_Uninte } UPB_INLINE google_protobuf_UninterpretedOption_NamePart** google_protobuf_UninterpretedOption_resize_name(google_protobuf_UninterpretedOption* msg, size_t size, upb_Arena* arena) { upb_MiniTableField field = {2, UPB_SIZE(4, 8), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return (google_protobuf_UninterpretedOption_NamePart**)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); + return (google_protobuf_UninterpretedOption_NamePart**)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg), + &field, size, arena); } UPB_INLINE struct google_protobuf_UninterpretedOption_NamePart* google_protobuf_UninterpretedOption_add_name(google_protobuf_UninterpretedOption* msg, upb_Arena* arena) { upb_MiniTableField field = {2, UPB_SIZE(4, 8), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray( + UPB_UPCAST(msg), &field, arena); if (!arr || !_upb_Array_ResizeUninitialized( arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; @@ -5165,27 +5360,27 @@ UPB_INLINE struct google_protobuf_UninterpretedOption_NamePart* google_protobuf_ } UPB_INLINE void google_protobuf_UninterpretedOption_set_identifier_value(google_protobuf_UninterpretedOption *msg, upb_StringView value) { const upb_MiniTableField field = {3, UPB_SIZE(8, 16), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_UninterpretedOption_set_positive_int_value(google_protobuf_UninterpretedOption *msg, uint64_t value) { const upb_MiniTableField field = {4, UPB_SIZE(16, 32), 2, kUpb_NoSub, 4, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_8Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_UninterpretedOption_set_negative_int_value(google_protobuf_UninterpretedOption *msg, int64_t value) { const upb_MiniTableField field = {5, UPB_SIZE(24, 40), 3, kUpb_NoSub, 3, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_8Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_UninterpretedOption_set_double_value(google_protobuf_UninterpretedOption *msg, double value) { const upb_MiniTableField field = {6, UPB_SIZE(32, 48), 4, kUpb_NoSub, 1, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_8Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_UninterpretedOption_set_string_value(google_protobuf_UninterpretedOption *msg, upb_StringView value) { const upb_MiniTableField field = {7, UPB_SIZE(40, 56), 5, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_UninterpretedOption_set_aggregate_value(google_protobuf_UninterpretedOption *msg, upb_StringView value) { const upb_MiniTableField field = {8, UPB_SIZE(48, 72), 6, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } /* google.protobuf.UninterpretedOption.NamePart */ @@ -5196,7 +5391,8 @@ UPB_INLINE google_protobuf_UninterpretedOption_NamePart* google_protobuf_Uninter UPB_INLINE google_protobuf_UninterpretedOption_NamePart* google_protobuf_UninterpretedOption_NamePart_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_UninterpretedOption_NamePart* ret = google_protobuf_UninterpretedOption_NamePart_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__UninterpretedOption__NamePart_msg_init, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__UninterpretedOption__NamePart_msg_init, NULL, 0, arena) != + kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -5206,61 +5402,63 @@ UPB_INLINE google_protobuf_UninterpretedOption_NamePart* google_protobuf_Uninter int options, upb_Arena* arena) { google_protobuf_UninterpretedOption_NamePart* ret = google_protobuf_UninterpretedOption_NamePart_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__UninterpretedOption__NamePart_msg_init, extreg, options, arena) != - kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__UninterpretedOption__NamePart_msg_init, extreg, options, + arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_UninterpretedOption_NamePart_serialize(const google_protobuf_UninterpretedOption_NamePart* msg, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__UninterpretedOption__NamePart_msg_init, 0, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__UninterpretedOption__NamePart_msg_init, 0, arena, &ptr, len); return ptr; } UPB_INLINE char* google_protobuf_UninterpretedOption_NamePart_serialize_ex(const google_protobuf_UninterpretedOption_NamePart* msg, int options, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__UninterpretedOption__NamePart_msg_init, options, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__UninterpretedOption__NamePart_msg_init, options, arena, &ptr, len); return ptr; } UPB_INLINE void google_protobuf_UninterpretedOption_NamePart_clear_name_part(google_protobuf_UninterpretedOption_NamePart* msg) { const upb_MiniTableField field = {1, UPB_SIZE(4, 8), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_UninterpretedOption_NamePart_name_part(const google_protobuf_UninterpretedOption_NamePart* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; const upb_MiniTableField field = {1, UPB_SIZE(4, 8), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_UninterpretedOption_NamePart_has_name_part(const google_protobuf_UninterpretedOption_NamePart* msg) { const upb_MiniTableField field = {1, UPB_SIZE(4, 8), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_UninterpretedOption_NamePart_clear_is_extension(google_protobuf_UninterpretedOption_NamePart* msg) { const upb_MiniTableField field = {2, 1, 2, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_UninterpretedOption_NamePart_is_extension(const google_protobuf_UninterpretedOption_NamePart* msg) { bool default_val = false; bool ret; const upb_MiniTableField field = {2, 1, 2, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_UninterpretedOption_NamePart_has_is_extension(const google_protobuf_UninterpretedOption_NamePart* msg) { const upb_MiniTableField field = {2, 1, 2, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_UninterpretedOption_NamePart_set_name_part(google_protobuf_UninterpretedOption_NamePart *msg, upb_StringView value) { const upb_MiniTableField field = {1, UPB_SIZE(4, 8), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_UninterpretedOption_NamePart_set_is_extension(google_protobuf_UninterpretedOption_NamePart *msg, bool value) { const upb_MiniTableField field = {2, 1, 2, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } /* google.protobuf.FeatureSet */ @@ -5271,7 +5469,8 @@ UPB_INLINE google_protobuf_FeatureSet* google_protobuf_FeatureSet_new(upb_Arena* UPB_INLINE google_protobuf_FeatureSet* google_protobuf_FeatureSet_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_FeatureSet* ret = google_protobuf_FeatureSet_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__FeatureSet_msg_init, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__FeatureSet_msg_init, NULL, 0, arena) != + kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -5281,137 +5480,143 @@ UPB_INLINE google_protobuf_FeatureSet* google_protobuf_FeatureSet_parse_ex(const int options, upb_Arena* arena) { google_protobuf_FeatureSet* ret = google_protobuf_FeatureSet_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__FeatureSet_msg_init, extreg, options, arena) != - kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__FeatureSet_msg_init, extreg, options, + arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_FeatureSet_serialize(const google_protobuf_FeatureSet* msg, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__FeatureSet_msg_init, 0, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__FeatureSet_msg_init, 0, arena, &ptr, len); return ptr; } UPB_INLINE char* google_protobuf_FeatureSet_serialize_ex(const google_protobuf_FeatureSet* msg, int options, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__FeatureSet_msg_init, options, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__FeatureSet_msg_init, options, arena, &ptr, len); return ptr; } UPB_INLINE void google_protobuf_FeatureSet_clear_field_presence(google_protobuf_FeatureSet* msg) { const upb_MiniTableField field = {1, 4, 1, 0, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_FeatureSet_field_presence(const google_protobuf_FeatureSet* msg) { int32_t default_val = 0; int32_t ret; const upb_MiniTableField field = {1, 4, 1, 0, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FeatureSet_has_field_presence(const google_protobuf_FeatureSet* msg) { const upb_MiniTableField field = {1, 4, 1, 0, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FeatureSet_clear_enum_type(google_protobuf_FeatureSet* msg) { const upb_MiniTableField field = {2, 8, 2, 1, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_FeatureSet_enum_type(const google_protobuf_FeatureSet* msg) { int32_t default_val = 0; int32_t ret; const upb_MiniTableField field = {2, 8, 2, 1, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FeatureSet_has_enum_type(const google_protobuf_FeatureSet* msg) { const upb_MiniTableField field = {2, 8, 2, 1, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FeatureSet_clear_repeated_field_encoding(google_protobuf_FeatureSet* msg) { const upb_MiniTableField field = {3, 12, 3, 2, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_FeatureSet_repeated_field_encoding(const google_protobuf_FeatureSet* msg) { int32_t default_val = 0; int32_t ret; const upb_MiniTableField field = {3, 12, 3, 2, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FeatureSet_has_repeated_field_encoding(const google_protobuf_FeatureSet* msg) { const upb_MiniTableField field = {3, 12, 3, 2, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FeatureSet_clear_utf8_validation(google_protobuf_FeatureSet* msg) { const upb_MiniTableField field = {4, 16, 4, 3, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_FeatureSet_utf8_validation(const google_protobuf_FeatureSet* msg) { int32_t default_val = 0; int32_t ret; const upb_MiniTableField field = {4, 16, 4, 3, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FeatureSet_has_utf8_validation(const google_protobuf_FeatureSet* msg) { const upb_MiniTableField field = {4, 16, 4, 3, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FeatureSet_clear_message_encoding(google_protobuf_FeatureSet* msg) { const upb_MiniTableField field = {5, 20, 5, 4, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_FeatureSet_message_encoding(const google_protobuf_FeatureSet* msg) { int32_t default_val = 0; int32_t ret; const upb_MiniTableField field = {5, 20, 5, 4, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FeatureSet_has_message_encoding(const google_protobuf_FeatureSet* msg) { const upb_MiniTableField field = {5, 20, 5, 4, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FeatureSet_clear_json_format(google_protobuf_FeatureSet* msg) { const upb_MiniTableField field = {6, 24, 6, 5, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_FeatureSet_json_format(const google_protobuf_FeatureSet* msg) { int32_t default_val = 0; int32_t ret; const upb_MiniTableField field = {6, 24, 6, 5, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FeatureSet_has_json_format(const google_protobuf_FeatureSet* msg) { const upb_MiniTableField field = {6, 24, 6, 5, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FeatureSet_set_field_presence(google_protobuf_FeatureSet *msg, int32_t value) { const upb_MiniTableField field = {1, 4, 1, 0, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FeatureSet_set_enum_type(google_protobuf_FeatureSet *msg, int32_t value) { const upb_MiniTableField field = {2, 8, 2, 1, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FeatureSet_set_repeated_field_encoding(google_protobuf_FeatureSet *msg, int32_t value) { const upb_MiniTableField field = {3, 12, 3, 2, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FeatureSet_set_utf8_validation(google_protobuf_FeatureSet *msg, int32_t value) { const upb_MiniTableField field = {4, 16, 4, 3, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FeatureSet_set_message_encoding(google_protobuf_FeatureSet *msg, int32_t value) { const upb_MiniTableField field = {5, 20, 5, 4, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FeatureSet_set_json_format(google_protobuf_FeatureSet *msg, int32_t value) { const upb_MiniTableField field = {6, 24, 6, 5, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } /* google.protobuf.FeatureSetDefaults */ @@ -5422,7 +5627,8 @@ UPB_INLINE google_protobuf_FeatureSetDefaults* google_protobuf_FeatureSetDefault UPB_INLINE google_protobuf_FeatureSetDefaults* google_protobuf_FeatureSetDefaults_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_FeatureSetDefaults* ret = google_protobuf_FeatureSetDefaults_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__FeatureSetDefaults_msg_init, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__FeatureSetDefaults_msg_init, NULL, 0, arena) != + kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -5432,30 +5638,30 @@ UPB_INLINE google_protobuf_FeatureSetDefaults* google_protobuf_FeatureSetDefault int options, upb_Arena* arena) { google_protobuf_FeatureSetDefaults* ret = google_protobuf_FeatureSetDefaults_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__FeatureSetDefaults_msg_init, extreg, options, arena) != - kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__FeatureSetDefaults_msg_init, extreg, options, + arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_FeatureSetDefaults_serialize(const google_protobuf_FeatureSetDefaults* msg, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__FeatureSetDefaults_msg_init, 0, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__FeatureSetDefaults_msg_init, 0, arena, &ptr, len); return ptr; } UPB_INLINE char* google_protobuf_FeatureSetDefaults_serialize_ex(const google_protobuf_FeatureSetDefaults* msg, int options, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__FeatureSetDefaults_msg_init, options, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__FeatureSetDefaults_msg_init, options, arena, &ptr, len); return ptr; } UPB_INLINE void google_protobuf_FeatureSetDefaults_clear_defaults(google_protobuf_FeatureSetDefaults* msg) { const upb_MiniTableField field = {1, UPB_SIZE(4, 16), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* const* google_protobuf_FeatureSetDefaults_defaults(const google_protobuf_FeatureSetDefaults* msg, size_t* size) { const upb_MiniTableField field = {1, UPB_SIZE(4, 16), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* const*)_upb_array_constptr(arr); @@ -5466,16 +5672,16 @@ UPB_INLINE const google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* co } UPB_INLINE const upb_Array* _google_protobuf_FeatureSetDefaults_defaults_upb_array(const google_protobuf_FeatureSetDefaults* msg, size_t* size) { const upb_MiniTableField field = {1, UPB_SIZE(4, 16), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } -UPB_INLINE upb_Array* _google_protobuf_FeatureSetDefaults_defaults_mutable_upb_array(const google_protobuf_FeatureSetDefaults* msg, size_t* size, upb_Arena* arena) { +UPB_INLINE upb_Array* _google_protobuf_FeatureSetDefaults_defaults_mutable_upb_array(google_protobuf_FeatureSetDefaults* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = {1, UPB_SIZE(4, 16), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - (upb_Message*)msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), + &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -5483,38 +5689,40 @@ UPB_INLINE upb_Array* _google_protobuf_FeatureSetDefaults_defaults_mutable_upb_a } UPB_INLINE void google_protobuf_FeatureSetDefaults_clear_minimum_edition(google_protobuf_FeatureSetDefaults* msg) { const upb_MiniTableField field = {4, UPB_SIZE(8, 4), 1, 1, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_FeatureSetDefaults_minimum_edition(const google_protobuf_FeatureSetDefaults* msg) { int32_t default_val = 0; int32_t ret; const upb_MiniTableField field = {4, UPB_SIZE(8, 4), 1, 1, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FeatureSetDefaults_has_minimum_edition(const google_protobuf_FeatureSetDefaults* msg) { const upb_MiniTableField field = {4, UPB_SIZE(8, 4), 1, 1, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FeatureSetDefaults_clear_maximum_edition(google_protobuf_FeatureSetDefaults* msg) { const upb_MiniTableField field = {5, UPB_SIZE(12, 8), 2, 2, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_FeatureSetDefaults_maximum_edition(const google_protobuf_FeatureSetDefaults* msg) { int32_t default_val = 0; int32_t ret; const upb_MiniTableField field = {5, UPB_SIZE(12, 8), 2, 2, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FeatureSetDefaults_has_maximum_edition(const google_protobuf_FeatureSetDefaults* msg) { const upb_MiniTableField field = {5, UPB_SIZE(12, 8), 2, 2, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault** google_protobuf_FeatureSetDefaults_mutable_defaults(google_protobuf_FeatureSetDefaults* msg, size_t* size) { upb_MiniTableField field = {1, UPB_SIZE(4, 16), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetMutableArray(msg, &field); + upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault**)_upb_array_ptr(arr); @@ -5525,11 +5733,13 @@ UPB_INLINE google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault** google_ } UPB_INLINE google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault** google_protobuf_FeatureSetDefaults_resize_defaults(google_protobuf_FeatureSetDefaults* msg, size_t size, upb_Arena* arena) { upb_MiniTableField field = {1, UPB_SIZE(4, 16), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return (google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault**)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); + return (google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault**)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg), + &field, size, arena); } UPB_INLINE struct google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* google_protobuf_FeatureSetDefaults_add_defaults(google_protobuf_FeatureSetDefaults* msg, upb_Arena* arena) { upb_MiniTableField field = {1, UPB_SIZE(4, 16), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray( + UPB_UPCAST(msg), &field, arena); if (!arr || !_upb_Array_ResizeUninitialized( arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; @@ -5542,11 +5752,11 @@ UPB_INLINE struct google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* g } UPB_INLINE void google_protobuf_FeatureSetDefaults_set_minimum_edition(google_protobuf_FeatureSetDefaults *msg, int32_t value) { const upb_MiniTableField field = {4, UPB_SIZE(8, 4), 1, 1, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_FeatureSetDefaults_set_maximum_edition(google_protobuf_FeatureSetDefaults *msg, int32_t value) { const upb_MiniTableField field = {5, UPB_SIZE(12, 8), 2, 2, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } /* google.protobuf.FeatureSetDefaults.FeatureSetEditionDefault */ @@ -5557,7 +5767,8 @@ UPB_INLINE google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* google_p UPB_INLINE google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* ret = google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__FeatureSetDefaults__FeatureSetEditionDefault_msg_init, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__FeatureSetDefaults__FeatureSetEditionDefault_msg_init, NULL, 0, arena) != + kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -5567,57 +5778,59 @@ UPB_INLINE google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* google_p int options, upb_Arena* arena) { google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* ret = google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__FeatureSetDefaults__FeatureSetEditionDefault_msg_init, extreg, options, arena) != - kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__FeatureSetDefaults__FeatureSetEditionDefault_msg_init, extreg, options, + arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_serialize(const google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* msg, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__FeatureSetDefaults__FeatureSetEditionDefault_msg_init, 0, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__FeatureSetDefaults__FeatureSetEditionDefault_msg_init, 0, arena, &ptr, len); return ptr; } UPB_INLINE char* google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_serialize_ex(const google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* msg, int options, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__FeatureSetDefaults__FeatureSetEditionDefault_msg_init, options, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__FeatureSetDefaults__FeatureSetEditionDefault_msg_init, options, arena, &ptr, len); return ptr; } UPB_INLINE void google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_clear_features(google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* msg) { const upb_MiniTableField field = {2, UPB_SIZE(4, 8), 1, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_FeatureSet* google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_features(const google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* msg) { const google_protobuf_FeatureSet* default_val = NULL; const google_protobuf_FeatureSet* ret; const upb_MiniTableField field = {2, UPB_SIZE(4, 8), 1, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_has_features(const google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* msg) { const upb_MiniTableField field = {2, UPB_SIZE(4, 8), 1, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_clear_edition(google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* msg) { const upb_MiniTableField field = {3, UPB_SIZE(8, 4), 2, 1, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_edition(const google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* msg) { int32_t default_val = 0; int32_t ret; const upb_MiniTableField field = {3, UPB_SIZE(8, 4), 2, 1, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_has_edition(const google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* msg) { const upb_MiniTableField field = {3, UPB_SIZE(8, 4), 2, 1, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_set_features(google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault *msg, google_protobuf_FeatureSet* value) { const upb_MiniTableField field = {2, UPB_SIZE(4, 8), 1, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE struct google_protobuf_FeatureSet* google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_mutable_features(google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* msg, upb_Arena* arena) { struct google_protobuf_FeatureSet* sub = (struct google_protobuf_FeatureSet*)google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_features(msg); @@ -5629,7 +5842,7 @@ UPB_INLINE struct google_protobuf_FeatureSet* google_protobuf_FeatureSetDefaults } UPB_INLINE void google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_set_edition(google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault *msg, int32_t value) { const upb_MiniTableField field = {3, UPB_SIZE(8, 4), 2, 1, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } /* google.protobuf.SourceCodeInfo */ @@ -5640,7 +5853,8 @@ UPB_INLINE google_protobuf_SourceCodeInfo* google_protobuf_SourceCodeInfo_new(up UPB_INLINE google_protobuf_SourceCodeInfo* google_protobuf_SourceCodeInfo_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_SourceCodeInfo* ret = google_protobuf_SourceCodeInfo_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__SourceCodeInfo_msg_init, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__SourceCodeInfo_msg_init, NULL, 0, arena) != + kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -5650,30 +5864,30 @@ UPB_INLINE google_protobuf_SourceCodeInfo* google_protobuf_SourceCodeInfo_parse_ int options, upb_Arena* arena) { google_protobuf_SourceCodeInfo* ret = google_protobuf_SourceCodeInfo_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__SourceCodeInfo_msg_init, extreg, options, arena) != - kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__SourceCodeInfo_msg_init, extreg, options, + arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_SourceCodeInfo_serialize(const google_protobuf_SourceCodeInfo* msg, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__SourceCodeInfo_msg_init, 0, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__SourceCodeInfo_msg_init, 0, arena, &ptr, len); return ptr; } UPB_INLINE char* google_protobuf_SourceCodeInfo_serialize_ex(const google_protobuf_SourceCodeInfo* msg, int options, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__SourceCodeInfo_msg_init, options, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__SourceCodeInfo_msg_init, options, arena, &ptr, len); return ptr; } UPB_INLINE void google_protobuf_SourceCodeInfo_clear_location(google_protobuf_SourceCodeInfo* msg) { const upb_MiniTableField field = {1, 0, 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_SourceCodeInfo_Location* const* google_protobuf_SourceCodeInfo_location(const google_protobuf_SourceCodeInfo* msg, size_t* size) { const upb_MiniTableField field = {1, 0, 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_SourceCodeInfo_Location* const*)_upb_array_constptr(arr); @@ -5684,16 +5898,16 @@ UPB_INLINE const google_protobuf_SourceCodeInfo_Location* const* google_protobuf } UPB_INLINE const upb_Array* _google_protobuf_SourceCodeInfo_location_upb_array(const google_protobuf_SourceCodeInfo* msg, size_t* size) { const upb_MiniTableField field = {1, 0, 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } -UPB_INLINE upb_Array* _google_protobuf_SourceCodeInfo_location_mutable_upb_array(const google_protobuf_SourceCodeInfo* msg, size_t* size, upb_Arena* arena) { +UPB_INLINE upb_Array* _google_protobuf_SourceCodeInfo_location_mutable_upb_array(google_protobuf_SourceCodeInfo* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = {1, 0, 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - (upb_Message*)msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), + &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -5702,7 +5916,7 @@ UPB_INLINE upb_Array* _google_protobuf_SourceCodeInfo_location_mutable_upb_array UPB_INLINE google_protobuf_SourceCodeInfo_Location** google_protobuf_SourceCodeInfo_mutable_location(google_protobuf_SourceCodeInfo* msg, size_t* size) { upb_MiniTableField field = {1, 0, 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetMutableArray(msg, &field); + upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_SourceCodeInfo_Location**)_upb_array_ptr(arr); @@ -5713,11 +5927,13 @@ UPB_INLINE google_protobuf_SourceCodeInfo_Location** google_protobuf_SourceCodeI } UPB_INLINE google_protobuf_SourceCodeInfo_Location** google_protobuf_SourceCodeInfo_resize_location(google_protobuf_SourceCodeInfo* msg, size_t size, upb_Arena* arena) { upb_MiniTableField field = {1, 0, 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return (google_protobuf_SourceCodeInfo_Location**)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); + return (google_protobuf_SourceCodeInfo_Location**)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg), + &field, size, arena); } UPB_INLINE struct google_protobuf_SourceCodeInfo_Location* google_protobuf_SourceCodeInfo_add_location(google_protobuf_SourceCodeInfo* msg, upb_Arena* arena) { upb_MiniTableField field = {1, 0, 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray( + UPB_UPCAST(msg), &field, arena); if (!arr || !_upb_Array_ResizeUninitialized( arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; @@ -5737,7 +5953,8 @@ UPB_INLINE google_protobuf_SourceCodeInfo_Location* google_protobuf_SourceCodeIn UPB_INLINE google_protobuf_SourceCodeInfo_Location* google_protobuf_SourceCodeInfo_Location_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_SourceCodeInfo_Location* ret = google_protobuf_SourceCodeInfo_Location_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__SourceCodeInfo__Location_msg_init, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__SourceCodeInfo__Location_msg_init, NULL, 0, arena) != + kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -5747,30 +5964,30 @@ UPB_INLINE google_protobuf_SourceCodeInfo_Location* google_protobuf_SourceCodeIn int options, upb_Arena* arena) { google_protobuf_SourceCodeInfo_Location* ret = google_protobuf_SourceCodeInfo_Location_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__SourceCodeInfo__Location_msg_init, extreg, options, arena) != - kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__SourceCodeInfo__Location_msg_init, extreg, options, + arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_SourceCodeInfo_Location_serialize(const google_protobuf_SourceCodeInfo_Location* msg, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__SourceCodeInfo__Location_msg_init, 0, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__SourceCodeInfo__Location_msg_init, 0, arena, &ptr, len); return ptr; } UPB_INLINE char* google_protobuf_SourceCodeInfo_Location_serialize_ex(const google_protobuf_SourceCodeInfo_Location* msg, int options, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__SourceCodeInfo__Location_msg_init, options, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__SourceCodeInfo__Location_msg_init, options, arena, &ptr, len); return ptr; } UPB_INLINE void google_protobuf_SourceCodeInfo_Location_clear_path(google_protobuf_SourceCodeInfo_Location* msg) { const upb_MiniTableField field = {1, UPB_SIZE(4, 8), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsPacked | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t const* google_protobuf_SourceCodeInfo_Location_path(const google_protobuf_SourceCodeInfo_Location* msg, size_t* size) { const upb_MiniTableField field = {1, UPB_SIZE(4, 8), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsPacked | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (int32_t const*)_upb_array_constptr(arr); @@ -5781,16 +5998,16 @@ UPB_INLINE int32_t const* google_protobuf_SourceCodeInfo_Location_path(const goo } UPB_INLINE const upb_Array* _google_protobuf_SourceCodeInfo_Location_path_upb_array(const google_protobuf_SourceCodeInfo_Location* msg, size_t* size) { const upb_MiniTableField field = {1, UPB_SIZE(4, 8), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsPacked | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } -UPB_INLINE upb_Array* _google_protobuf_SourceCodeInfo_Location_path_mutable_upb_array(const google_protobuf_SourceCodeInfo_Location* msg, size_t* size, upb_Arena* arena) { +UPB_INLINE upb_Array* _google_protobuf_SourceCodeInfo_Location_path_mutable_upb_array(google_protobuf_SourceCodeInfo_Location* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = {1, UPB_SIZE(4, 8), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsPacked | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - (upb_Message*)msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), + &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -5798,11 +6015,11 @@ UPB_INLINE upb_Array* _google_protobuf_SourceCodeInfo_Location_path_mutable_upb_ } UPB_INLINE void google_protobuf_SourceCodeInfo_Location_clear_span(google_protobuf_SourceCodeInfo_Location* msg) { const upb_MiniTableField field = {2, UPB_SIZE(8, 16), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsPacked | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t const* google_protobuf_SourceCodeInfo_Location_span(const google_protobuf_SourceCodeInfo_Location* msg, size_t* size) { const upb_MiniTableField field = {2, UPB_SIZE(8, 16), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsPacked | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (int32_t const*)_upb_array_constptr(arr); @@ -5813,16 +6030,16 @@ UPB_INLINE int32_t const* google_protobuf_SourceCodeInfo_Location_span(const goo } UPB_INLINE const upb_Array* _google_protobuf_SourceCodeInfo_Location_span_upb_array(const google_protobuf_SourceCodeInfo_Location* msg, size_t* size) { const upb_MiniTableField field = {2, UPB_SIZE(8, 16), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsPacked | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } -UPB_INLINE upb_Array* _google_protobuf_SourceCodeInfo_Location_span_mutable_upb_array(const google_protobuf_SourceCodeInfo_Location* msg, size_t* size, upb_Arena* arena) { +UPB_INLINE upb_Array* _google_protobuf_SourceCodeInfo_Location_span_mutable_upb_array(google_protobuf_SourceCodeInfo_Location* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = {2, UPB_SIZE(8, 16), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsPacked | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - (upb_Message*)msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), + &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -5830,41 +6047,43 @@ UPB_INLINE upb_Array* _google_protobuf_SourceCodeInfo_Location_span_mutable_upb_ } UPB_INLINE void google_protobuf_SourceCodeInfo_Location_clear_leading_comments(google_protobuf_SourceCodeInfo_Location* msg) { const upb_MiniTableField field = {3, UPB_SIZE(16, 24), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_SourceCodeInfo_Location_leading_comments(const google_protobuf_SourceCodeInfo_Location* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; const upb_MiniTableField field = {3, UPB_SIZE(16, 24), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_SourceCodeInfo_Location_has_leading_comments(const google_protobuf_SourceCodeInfo_Location* msg) { const upb_MiniTableField field = {3, UPB_SIZE(16, 24), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_SourceCodeInfo_Location_clear_trailing_comments(google_protobuf_SourceCodeInfo_Location* msg) { const upb_MiniTableField field = {4, UPB_SIZE(24, 40), 2, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_SourceCodeInfo_Location_trailing_comments(const google_protobuf_SourceCodeInfo_Location* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; const upb_MiniTableField field = {4, UPB_SIZE(24, 40), 2, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_SourceCodeInfo_Location_has_trailing_comments(const google_protobuf_SourceCodeInfo_Location* msg) { const upb_MiniTableField field = {4, UPB_SIZE(24, 40), 2, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_SourceCodeInfo_Location_clear_leading_detached_comments(google_protobuf_SourceCodeInfo_Location* msg) { const upb_MiniTableField field = {6, UPB_SIZE(12, 56), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView const* google_protobuf_SourceCodeInfo_Location_leading_detached_comments(const google_protobuf_SourceCodeInfo_Location* msg, size_t* size) { const upb_MiniTableField field = {6, UPB_SIZE(12, 56), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (upb_StringView const*)_upb_array_constptr(arr); @@ -5875,16 +6094,16 @@ UPB_INLINE upb_StringView const* google_protobuf_SourceCodeInfo_Location_leading } UPB_INLINE const upb_Array* _google_protobuf_SourceCodeInfo_Location_leading_detached_comments_upb_array(const google_protobuf_SourceCodeInfo_Location* msg, size_t* size) { const upb_MiniTableField field = {6, UPB_SIZE(12, 56), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } -UPB_INLINE upb_Array* _google_protobuf_SourceCodeInfo_Location_leading_detached_comments_mutable_upb_array(const google_protobuf_SourceCodeInfo_Location* msg, size_t* size, upb_Arena* arena) { +UPB_INLINE upb_Array* _google_protobuf_SourceCodeInfo_Location_leading_detached_comments_mutable_upb_array(google_protobuf_SourceCodeInfo_Location* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = {6, UPB_SIZE(12, 56), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - (upb_Message*)msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), + &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -5893,7 +6112,7 @@ UPB_INLINE upb_Array* _google_protobuf_SourceCodeInfo_Location_leading_detached_ UPB_INLINE int32_t* google_protobuf_SourceCodeInfo_Location_mutable_path(google_protobuf_SourceCodeInfo_Location* msg, size_t* size) { upb_MiniTableField field = {1, UPB_SIZE(4, 8), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsPacked | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetMutableArray(msg, &field); + upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (int32_t*)_upb_array_ptr(arr); @@ -5904,11 +6123,13 @@ UPB_INLINE int32_t* google_protobuf_SourceCodeInfo_Location_mutable_path(google_ } UPB_INLINE int32_t* google_protobuf_SourceCodeInfo_Location_resize_path(google_protobuf_SourceCodeInfo_Location* msg, size_t size, upb_Arena* arena) { upb_MiniTableField field = {1, UPB_SIZE(4, 8), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsPacked | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return (int32_t*)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); + return (int32_t*)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg), + &field, size, arena); } UPB_INLINE bool google_protobuf_SourceCodeInfo_Location_add_path(google_protobuf_SourceCodeInfo_Location* msg, int32_t val, upb_Arena* arena) { upb_MiniTableField field = {1, UPB_SIZE(4, 8), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsPacked | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray( + UPB_UPCAST(msg), &field, arena); if (!arr || !_upb_Array_ResizeUninitialized( arr, arr->UPB_PRIVATE(size) + 1, arena)) { return false; @@ -5919,7 +6140,7 @@ UPB_INLINE bool google_protobuf_SourceCodeInfo_Location_add_path(google_protobuf } UPB_INLINE int32_t* google_protobuf_SourceCodeInfo_Location_mutable_span(google_protobuf_SourceCodeInfo_Location* msg, size_t* size) { upb_MiniTableField field = {2, UPB_SIZE(8, 16), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsPacked | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetMutableArray(msg, &field); + upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (int32_t*)_upb_array_ptr(arr); @@ -5930,11 +6151,13 @@ UPB_INLINE int32_t* google_protobuf_SourceCodeInfo_Location_mutable_span(google_ } UPB_INLINE int32_t* google_protobuf_SourceCodeInfo_Location_resize_span(google_protobuf_SourceCodeInfo_Location* msg, size_t size, upb_Arena* arena) { upb_MiniTableField field = {2, UPB_SIZE(8, 16), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsPacked | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return (int32_t*)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); + return (int32_t*)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg), + &field, size, arena); } UPB_INLINE bool google_protobuf_SourceCodeInfo_Location_add_span(google_protobuf_SourceCodeInfo_Location* msg, int32_t val, upb_Arena* arena) { upb_MiniTableField field = {2, UPB_SIZE(8, 16), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsPacked | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray( + UPB_UPCAST(msg), &field, arena); if (!arr || !_upb_Array_ResizeUninitialized( arr, arr->UPB_PRIVATE(size) + 1, arena)) { return false; @@ -5945,15 +6168,15 @@ UPB_INLINE bool google_protobuf_SourceCodeInfo_Location_add_span(google_protobuf } UPB_INLINE void google_protobuf_SourceCodeInfo_Location_set_leading_comments(google_protobuf_SourceCodeInfo_Location *msg, upb_StringView value) { const upb_MiniTableField field = {3, UPB_SIZE(16, 24), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_SourceCodeInfo_Location_set_trailing_comments(google_protobuf_SourceCodeInfo_Location *msg, upb_StringView value) { const upb_MiniTableField field = {4, UPB_SIZE(24, 40), 2, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE upb_StringView* google_protobuf_SourceCodeInfo_Location_mutable_leading_detached_comments(google_protobuf_SourceCodeInfo_Location* msg, size_t* size) { upb_MiniTableField field = {6, UPB_SIZE(12, 56), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetMutableArray(msg, &field); + upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (upb_StringView*)_upb_array_ptr(arr); @@ -5964,11 +6187,13 @@ UPB_INLINE upb_StringView* google_protobuf_SourceCodeInfo_Location_mutable_leadi } UPB_INLINE upb_StringView* google_protobuf_SourceCodeInfo_Location_resize_leading_detached_comments(google_protobuf_SourceCodeInfo_Location* msg, size_t size, upb_Arena* arena) { upb_MiniTableField field = {6, UPB_SIZE(12, 56), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return (upb_StringView*)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); + return (upb_StringView*)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg), + &field, size, arena); } UPB_INLINE bool google_protobuf_SourceCodeInfo_Location_add_leading_detached_comments(google_protobuf_SourceCodeInfo_Location* msg, upb_StringView val, upb_Arena* arena) { upb_MiniTableField field = {6, UPB_SIZE(12, 56), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray( + UPB_UPCAST(msg), &field, arena); if (!arr || !_upb_Array_ResizeUninitialized( arr, arr->UPB_PRIVATE(size) + 1, arena)) { return false; @@ -5986,7 +6211,8 @@ UPB_INLINE google_protobuf_GeneratedCodeInfo* google_protobuf_GeneratedCodeInfo_ UPB_INLINE google_protobuf_GeneratedCodeInfo* google_protobuf_GeneratedCodeInfo_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_GeneratedCodeInfo* ret = google_protobuf_GeneratedCodeInfo_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__GeneratedCodeInfo_msg_init, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__GeneratedCodeInfo_msg_init, NULL, 0, arena) != + kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -5996,30 +6222,30 @@ UPB_INLINE google_protobuf_GeneratedCodeInfo* google_protobuf_GeneratedCodeInfo_ int options, upb_Arena* arena) { google_protobuf_GeneratedCodeInfo* ret = google_protobuf_GeneratedCodeInfo_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__GeneratedCodeInfo_msg_init, extreg, options, arena) != - kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__GeneratedCodeInfo_msg_init, extreg, options, + arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_GeneratedCodeInfo_serialize(const google_protobuf_GeneratedCodeInfo* msg, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__GeneratedCodeInfo_msg_init, 0, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__GeneratedCodeInfo_msg_init, 0, arena, &ptr, len); return ptr; } UPB_INLINE char* google_protobuf_GeneratedCodeInfo_serialize_ex(const google_protobuf_GeneratedCodeInfo* msg, int options, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__GeneratedCodeInfo_msg_init, options, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__GeneratedCodeInfo_msg_init, options, arena, &ptr, len); return ptr; } UPB_INLINE void google_protobuf_GeneratedCodeInfo_clear_annotation(google_protobuf_GeneratedCodeInfo* msg) { const upb_MiniTableField field = {1, 0, 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_GeneratedCodeInfo_Annotation* const* google_protobuf_GeneratedCodeInfo_annotation(const google_protobuf_GeneratedCodeInfo* msg, size_t* size) { const upb_MiniTableField field = {1, 0, 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (const google_protobuf_GeneratedCodeInfo_Annotation* const*)_upb_array_constptr(arr); @@ -6030,16 +6256,16 @@ UPB_INLINE const google_protobuf_GeneratedCodeInfo_Annotation* const* google_pro } UPB_INLINE const upb_Array* _google_protobuf_GeneratedCodeInfo_annotation_upb_array(const google_protobuf_GeneratedCodeInfo* msg, size_t* size) { const upb_MiniTableField field = {1, 0, 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } -UPB_INLINE upb_Array* _google_protobuf_GeneratedCodeInfo_annotation_mutable_upb_array(const google_protobuf_GeneratedCodeInfo* msg, size_t* size, upb_Arena* arena) { +UPB_INLINE upb_Array* _google_protobuf_GeneratedCodeInfo_annotation_mutable_upb_array(google_protobuf_GeneratedCodeInfo* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = {1, 0, 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - (upb_Message*)msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), + &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -6048,7 +6274,7 @@ UPB_INLINE upb_Array* _google_protobuf_GeneratedCodeInfo_annotation_mutable_upb_ UPB_INLINE google_protobuf_GeneratedCodeInfo_Annotation** google_protobuf_GeneratedCodeInfo_mutable_annotation(google_protobuf_GeneratedCodeInfo* msg, size_t* size) { upb_MiniTableField field = {1, 0, 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetMutableArray(msg, &field); + upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (google_protobuf_GeneratedCodeInfo_Annotation**)_upb_array_ptr(arr); @@ -6059,11 +6285,13 @@ UPB_INLINE google_protobuf_GeneratedCodeInfo_Annotation** google_protobuf_Genera } UPB_INLINE google_protobuf_GeneratedCodeInfo_Annotation** google_protobuf_GeneratedCodeInfo_resize_annotation(google_protobuf_GeneratedCodeInfo* msg, size_t size, upb_Arena* arena) { upb_MiniTableField field = {1, 0, 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return (google_protobuf_GeneratedCodeInfo_Annotation**)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); + return (google_protobuf_GeneratedCodeInfo_Annotation**)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg), + &field, size, arena); } UPB_INLINE struct google_protobuf_GeneratedCodeInfo_Annotation* google_protobuf_GeneratedCodeInfo_add_annotation(google_protobuf_GeneratedCodeInfo* msg, upb_Arena* arena) { upb_MiniTableField field = {1, 0, 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray( + UPB_UPCAST(msg), &field, arena); if (!arr || !_upb_Array_ResizeUninitialized( arr, arr->UPB_PRIVATE(size) + 1, arena)) { return NULL; @@ -6083,7 +6311,8 @@ UPB_INLINE google_protobuf_GeneratedCodeInfo_Annotation* google_protobuf_Generat UPB_INLINE google_protobuf_GeneratedCodeInfo_Annotation* google_protobuf_GeneratedCodeInfo_Annotation_parse(const char* buf, size_t size, upb_Arena* arena) { google_protobuf_GeneratedCodeInfo_Annotation* ret = google_protobuf_GeneratedCodeInfo_Annotation_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__GeneratedCodeInfo__Annotation_msg_init, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__GeneratedCodeInfo__Annotation_msg_init, NULL, 0, arena) != + kUpb_DecodeStatus_Ok) { return NULL; } return ret; @@ -6093,30 +6322,30 @@ UPB_INLINE google_protobuf_GeneratedCodeInfo_Annotation* google_protobuf_Generat int options, upb_Arena* arena) { google_protobuf_GeneratedCodeInfo_Annotation* ret = google_protobuf_GeneratedCodeInfo_Annotation_new(arena); if (!ret) return NULL; - if (upb_Decode(buf, size, ret, &google__protobuf__GeneratedCodeInfo__Annotation_msg_init, extreg, options, arena) != - kUpb_DecodeStatus_Ok) { + if (upb_Decode(buf, size, UPB_UPCAST(ret), &google__protobuf__GeneratedCodeInfo__Annotation_msg_init, extreg, options, + arena) != kUpb_DecodeStatus_Ok) { return NULL; } return ret; } UPB_INLINE char* google_protobuf_GeneratedCodeInfo_Annotation_serialize(const google_protobuf_GeneratedCodeInfo_Annotation* msg, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__GeneratedCodeInfo__Annotation_msg_init, 0, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__GeneratedCodeInfo__Annotation_msg_init, 0, arena, &ptr, len); return ptr; } UPB_INLINE char* google_protobuf_GeneratedCodeInfo_Annotation_serialize_ex(const google_protobuf_GeneratedCodeInfo_Annotation* msg, int options, upb_Arena* arena, size_t* len) { char* ptr; - (void)upb_Encode(msg, &google__protobuf__GeneratedCodeInfo__Annotation_msg_init, options, arena, &ptr, len); + (void)upb_Encode(UPB_UPCAST(msg), &google__protobuf__GeneratedCodeInfo__Annotation_msg_init, options, arena, &ptr, len); return ptr; } UPB_INLINE void google_protobuf_GeneratedCodeInfo_Annotation_clear_path(google_protobuf_GeneratedCodeInfo_Annotation* msg) { const upb_MiniTableField field = {1, UPB_SIZE(4, 16), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsPacked | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t const* google_protobuf_GeneratedCodeInfo_Annotation_path(const google_protobuf_GeneratedCodeInfo_Annotation* msg, size_t* size) { const upb_MiniTableField field = {1, UPB_SIZE(4, 16), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsPacked | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (int32_t const*)_upb_array_constptr(arr); @@ -6127,16 +6356,16 @@ UPB_INLINE int32_t const* google_protobuf_GeneratedCodeInfo_Annotation_path(cons } UPB_INLINE const upb_Array* _google_protobuf_GeneratedCodeInfo_Annotation_path_upb_array(const google_protobuf_GeneratedCodeInfo_Annotation* msg, size_t* size) { const upb_MiniTableField field = {1, UPB_SIZE(4, 16), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsPacked | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - const upb_Array* arr = upb_Message_GetArray(msg, &field); + const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } return arr; } -UPB_INLINE upb_Array* _google_protobuf_GeneratedCodeInfo_Annotation_path_mutable_upb_array(const google_protobuf_GeneratedCodeInfo_Annotation* msg, size_t* size, upb_Arena* arena) { +UPB_INLINE upb_Array* _google_protobuf_GeneratedCodeInfo_Annotation_path_mutable_upb_array(google_protobuf_GeneratedCodeInfo_Annotation* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = {1, UPB_SIZE(4, 16), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsPacked | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - (upb_Message*)msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), + &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -6144,68 +6373,72 @@ UPB_INLINE upb_Array* _google_protobuf_GeneratedCodeInfo_Annotation_path_mutable } UPB_INLINE void google_protobuf_GeneratedCodeInfo_Annotation_clear_source_file(google_protobuf_GeneratedCodeInfo_Annotation* msg) { const upb_MiniTableField field = {2, UPB_SIZE(20, 24), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_GeneratedCodeInfo_Annotation_source_file(const google_protobuf_GeneratedCodeInfo_Annotation* msg) { upb_StringView default_val = upb_StringView_FromString(""); upb_StringView ret; const upb_MiniTableField field = {2, UPB_SIZE(20, 24), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_GeneratedCodeInfo_Annotation_has_source_file(const google_protobuf_GeneratedCodeInfo_Annotation* msg) { const upb_MiniTableField field = {2, UPB_SIZE(20, 24), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_GeneratedCodeInfo_Annotation_clear_begin(google_protobuf_GeneratedCodeInfo_Annotation* msg) { const upb_MiniTableField field = {3, UPB_SIZE(8, 4), 2, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_GeneratedCodeInfo_Annotation_begin(const google_protobuf_GeneratedCodeInfo_Annotation* msg) { int32_t default_val = (int32_t)0; int32_t ret; const upb_MiniTableField field = {3, UPB_SIZE(8, 4), 2, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_GeneratedCodeInfo_Annotation_has_begin(const google_protobuf_GeneratedCodeInfo_Annotation* msg) { const upb_MiniTableField field = {3, UPB_SIZE(8, 4), 2, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_GeneratedCodeInfo_Annotation_clear_end(google_protobuf_GeneratedCodeInfo_Annotation* msg) { const upb_MiniTableField field = {4, UPB_SIZE(12, 8), 3, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_GeneratedCodeInfo_Annotation_end(const google_protobuf_GeneratedCodeInfo_Annotation* msg) { int32_t default_val = (int32_t)0; int32_t ret; const upb_MiniTableField field = {4, UPB_SIZE(12, 8), 3, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_GeneratedCodeInfo_Annotation_has_end(const google_protobuf_GeneratedCodeInfo_Annotation* msg) { const upb_MiniTableField field = {4, UPB_SIZE(12, 8), 3, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_GeneratedCodeInfo_Annotation_clear_semantic(google_protobuf_GeneratedCodeInfo_Annotation* msg) { const upb_MiniTableField field = {5, UPB_SIZE(16, 12), 4, 0, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(msg, &field); + _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_GeneratedCodeInfo_Annotation_semantic(const google_protobuf_GeneratedCodeInfo_Annotation* msg) { int32_t default_val = 0; int32_t ret; const upb_MiniTableField field = {5, UPB_SIZE(16, 12), 4, 0, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); + _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, + &default_val, &ret); return ret; } UPB_INLINE bool google_protobuf_GeneratedCodeInfo_Annotation_has_semantic(const google_protobuf_GeneratedCodeInfo_Annotation* msg) { const upb_MiniTableField field = {5, UPB_SIZE(16, 12), 4, 0, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(msg, &field); + return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t* google_protobuf_GeneratedCodeInfo_Annotation_mutable_path(google_protobuf_GeneratedCodeInfo_Annotation* msg, size_t* size) { upb_MiniTableField field = {1, UPB_SIZE(4, 16), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsPacked | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetMutableArray(msg, &field); + upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field); if (arr) { if (size) *size = arr->UPB_PRIVATE(size); return (int32_t*)_upb_array_ptr(arr); @@ -6216,11 +6449,13 @@ UPB_INLINE int32_t* google_protobuf_GeneratedCodeInfo_Annotation_mutable_path(go } UPB_INLINE int32_t* google_protobuf_GeneratedCodeInfo_Annotation_resize_path(google_protobuf_GeneratedCodeInfo_Annotation* msg, size_t size, upb_Arena* arena) { upb_MiniTableField field = {1, UPB_SIZE(4, 16), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsPacked | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return (int32_t*)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); + return (int32_t*)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg), + &field, size, arena); } UPB_INLINE bool google_protobuf_GeneratedCodeInfo_Annotation_add_path(google_protobuf_GeneratedCodeInfo_Annotation* msg, int32_t val, upb_Arena* arena) { upb_MiniTableField field = {1, UPB_SIZE(4, 16), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsPacked | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray( + UPB_UPCAST(msg), &field, arena); if (!arr || !_upb_Array_ResizeUninitialized( arr, arr->UPB_PRIVATE(size) + 1, arena)) { return false; @@ -6231,19 +6466,19 @@ UPB_INLINE bool google_protobuf_GeneratedCodeInfo_Annotation_add_path(google_pro } UPB_INLINE void google_protobuf_GeneratedCodeInfo_Annotation_set_source_file(google_protobuf_GeneratedCodeInfo_Annotation *msg, upb_StringView value) { const upb_MiniTableField field = {2, UPB_SIZE(20, 24), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_GeneratedCodeInfo_Annotation_set_begin(google_protobuf_GeneratedCodeInfo_Annotation *msg, int32_t value) { const upb_MiniTableField field = {3, UPB_SIZE(8, 4), 2, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_GeneratedCodeInfo_Annotation_set_end(google_protobuf_GeneratedCodeInfo_Annotation *msg, int32_t value) { const upb_MiniTableField field = {4, UPB_SIZE(12, 8), 3, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } UPB_INLINE void google_protobuf_GeneratedCodeInfo_Annotation_set_semantic(google_protobuf_GeneratedCodeInfo_Annotation *msg, int32_t value) { const upb_MiniTableField field = {5, UPB_SIZE(16, 12), 4, 0, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_SetNonExtensionField(msg, &field, &value); + _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } /* Max size 32 is google.protobuf.FileOptions */ From 238538b6ce736c2443c92a992aa1059cade2aebd Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Thu, 21 Dec 2023 13:15:35 -0800 Subject: [PATCH 090/255] Fixed breaking ARM tests by properly aligning default options. This char array is interpreted as a proto, so it needs pointer alignment at least. PiperOrigin-RevId: 592935088 --- upb/port/def.inc | 7 + upb/port/undef.inc | 1 + upb/reflection/internal/def_builder.c | 3 +- .../stage0/google/protobuf/descriptor.upb.h | 180 ++++++++---------- .../google/protobuf/compiler/plugin.upb.h | 16 +- 5 files changed, 98 insertions(+), 109 deletions(-) diff --git a/upb/port/def.inc b/upb/port/def.inc index 4b8a09c3b4449..5d07592b07740 100644 --- a/upb/port/def.inc +++ b/upb/port/def.inc @@ -99,6 +99,13 @@ Error, UINTPTR_MAX is undefined #define UPB_ALIGN_OF(type) offsetof (struct { char c; type member; }, member) #endif +#ifdef _MSC_VER +// Some versions of our Windows compiler don't support the C11 syntax. +#define UPB_ALIGN_AS(x) __declspec(align(x)) +#else +#define UPB_ALIGN_AS(x) _Alignas(x) +#endif + // Hints to the compiler about likely/unlikely branches. #if defined (__GNUC__) || defined(__clang__) #define UPB_LIKELY(x) __builtin_expect((bool)(x), 1) diff --git a/upb/port/undef.inc b/upb/port/undef.inc index 537c5dc4bd03e..e4aec84b50c95 100644 --- a/upb/port/undef.inc +++ b/upb/port/undef.inc @@ -18,6 +18,7 @@ #undef UPB_ALIGN_DOWN #undef UPB_ALIGN_MALLOC #undef UPB_ALIGN_OF +#undef UPB_ALIGN_AS #undef UPB_MALLOC_ALIGN #undef UPB_LIKELY #undef UPB_UNLIKELY diff --git a/upb/reflection/internal/def_builder.c b/upb/reflection/internal/def_builder.c index dcd8ee2f1d3e7..7e560177253b8 100644 --- a/upb/reflection/internal/def_builder.c +++ b/upb/reflection/internal/def_builder.c @@ -29,7 +29,8 @@ * initialized to zeroes. * * We have to allocate an extra pointer for upb's internal metadata. */ -static const char opt_default_buf[_UPB_MAXOPT_SIZE + sizeof(void*)] = {0}; +static UPB_ALIGN_AS(8) const + char opt_default_buf[_UPB_MAXOPT_SIZE + sizeof(void*)] = {0}; const char* kUpbDefOptDefault = &opt_default_buf[sizeof(void*)]; const char* _upb_DefBuilder_FullToShort(const char* fullname) { diff --git a/upb/reflection/stage0/google/protobuf/descriptor.upb.h b/upb/reflection/stage0/google/protobuf/descriptor.upb.h index e94e8d6ae2443..932a8185f1d03 100644 --- a/upb/reflection/stage0/google/protobuf/descriptor.upb.h +++ b/upb/reflection/stage0/google/protobuf/descriptor.upb.h @@ -294,8 +294,8 @@ UPB_INLINE const upb_Array* _google_protobuf_FileDescriptorSet_file_upb_array(co } UPB_INLINE upb_Array* _google_protobuf_FileDescriptorSet_file_mutable_upb_array(google_protobuf_FileDescriptorSet* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorSet_msg_init(), 1); - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - UPB_UPCAST(msg), &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), + &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -426,8 +426,8 @@ UPB_INLINE const upb_Array* _google_protobuf_FileDescriptorProto_dependency_upb_ } UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_dependency_mutable_upb_array(google_protobuf_FileDescriptorProto* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 3); - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - UPB_UPCAST(msg), &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), + &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -458,8 +458,8 @@ UPB_INLINE const upb_Array* _google_protobuf_FileDescriptorProto_message_type_up } UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_message_type_mutable_upb_array(google_protobuf_FileDescriptorProto* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 4); - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - UPB_UPCAST(msg), &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), + &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -490,8 +490,8 @@ UPB_INLINE const upb_Array* _google_protobuf_FileDescriptorProto_enum_type_upb_a } UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_enum_type_mutable_upb_array(google_protobuf_FileDescriptorProto* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 5); - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - UPB_UPCAST(msg), &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), + &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -522,8 +522,8 @@ UPB_INLINE const upb_Array* _google_protobuf_FileDescriptorProto_service_upb_arr } UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_service_mutable_upb_array(google_protobuf_FileDescriptorProto* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 6); - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - UPB_UPCAST(msg), &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), + &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -554,8 +554,8 @@ UPB_INLINE const upb_Array* _google_protobuf_FileDescriptorProto_extension_upb_a } UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_extension_mutable_upb_array(google_protobuf_FileDescriptorProto* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 7); - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - UPB_UPCAST(msg), &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), + &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -618,8 +618,8 @@ UPB_INLINE const upb_Array* _google_protobuf_FileDescriptorProto_public_dependen } UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_public_dependency_mutable_upb_array(google_protobuf_FileDescriptorProto* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 10); - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - UPB_UPCAST(msg), &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), + &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -650,8 +650,8 @@ UPB_INLINE const upb_Array* _google_protobuf_FileDescriptorProto_weak_dependency } UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_weak_dependency_mutable_upb_array(google_protobuf_FileDescriptorProto* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 11); - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - UPB_UPCAST(msg), &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), + &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -1012,8 +1012,8 @@ UPB_INLINE const upb_Array* _google_protobuf_DescriptorProto_field_upb_array(con } UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_field_mutable_upb_array(google_protobuf_DescriptorProto* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 2); - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - UPB_UPCAST(msg), &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), + &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -1044,8 +1044,8 @@ UPB_INLINE const upb_Array* _google_protobuf_DescriptorProto_nested_type_upb_arr } UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_nested_type_mutable_upb_array(google_protobuf_DescriptorProto* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 3); - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - UPB_UPCAST(msg), &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), + &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -1076,8 +1076,8 @@ UPB_INLINE const upb_Array* _google_protobuf_DescriptorProto_enum_type_upb_array } UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_enum_type_mutable_upb_array(google_protobuf_DescriptorProto* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 4); - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - UPB_UPCAST(msg), &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), + &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -1108,8 +1108,8 @@ UPB_INLINE const upb_Array* _google_protobuf_DescriptorProto_extension_range_upb } UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_extension_range_mutable_upb_array(google_protobuf_DescriptorProto* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 5); - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - UPB_UPCAST(msg), &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), + &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -1140,8 +1140,8 @@ UPB_INLINE const upb_Array* _google_protobuf_DescriptorProto_extension_upb_array } UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_extension_mutable_upb_array(google_protobuf_DescriptorProto* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 6); - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - UPB_UPCAST(msg), &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), + &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -1188,8 +1188,8 @@ UPB_INLINE const upb_Array* _google_protobuf_DescriptorProto_oneof_decl_upb_arra } UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_oneof_decl_mutable_upb_array(google_protobuf_DescriptorProto* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 8); - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - UPB_UPCAST(msg), &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), + &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -1220,8 +1220,8 @@ UPB_INLINE const upb_Array* _google_protobuf_DescriptorProto_reserved_range_upb_ } UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_reserved_range_mutable_upb_array(google_protobuf_DescriptorProto* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 9); - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - UPB_UPCAST(msg), &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), + &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -1252,8 +1252,8 @@ UPB_INLINE const upb_Array* _google_protobuf_DescriptorProto_reserved_name_upb_a } UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_reserved_name_mutable_upb_array(google_protobuf_DescriptorProto* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 10); - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - UPB_UPCAST(msg), &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), + &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -1760,8 +1760,8 @@ UPB_INLINE const upb_Array* _google_protobuf_ExtensionRangeOptions_declaration_u } UPB_INLINE upb_Array* _google_protobuf_ExtensionRangeOptions_declaration_mutable_upb_array(google_protobuf_ExtensionRangeOptions* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ExtensionRangeOptions_msg_init(), 2); - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - UPB_UPCAST(msg), &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), + &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -1824,8 +1824,8 @@ UPB_INLINE const upb_Array* _google_protobuf_ExtensionRangeOptions_uninterpreted } UPB_INLINE upb_Array* _google_protobuf_ExtensionRangeOptions_uninterpreted_option_mutable_upb_array(google_protobuf_ExtensionRangeOptions* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ExtensionRangeOptions_msg_init(), 999); - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - UPB_UPCAST(msg), &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), + &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -2476,8 +2476,8 @@ UPB_INLINE const upb_Array* _google_protobuf_EnumDescriptorProto_value_upb_array } UPB_INLINE upb_Array* _google_protobuf_EnumDescriptorProto_value_mutable_upb_array(google_protobuf_EnumDescriptorProto* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumDescriptorProto_msg_init(), 2); - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - UPB_UPCAST(msg), &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), + &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -2524,8 +2524,8 @@ UPB_INLINE const upb_Array* _google_protobuf_EnumDescriptorProto_reserved_range_ } UPB_INLINE upb_Array* _google_protobuf_EnumDescriptorProto_reserved_range_mutable_upb_array(google_protobuf_EnumDescriptorProto* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumDescriptorProto_msg_init(), 4); - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - UPB_UPCAST(msg), &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), + &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -2556,8 +2556,8 @@ UPB_INLINE const upb_Array* _google_protobuf_EnumDescriptorProto_reserved_name_u } UPB_INLINE upb_Array* _google_protobuf_EnumDescriptorProto_reserved_name_mutable_upb_array(google_protobuf_EnumDescriptorProto* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumDescriptorProto_msg_init(), 5); - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - UPB_UPCAST(msg), &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), + &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -2930,8 +2930,8 @@ UPB_INLINE const upb_Array* _google_protobuf_ServiceDescriptorProto_method_upb_a } UPB_INLINE upb_Array* _google_protobuf_ServiceDescriptorProto_method_mutable_upb_array(google_protobuf_ServiceDescriptorProto* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ServiceDescriptorProto_msg_init(), 2); - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - UPB_UPCAST(msg), &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), + &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -3475,22 +3475,6 @@ UPB_INLINE bool google_protobuf_FileOptions_has_php_namespace(const google_proto const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 41); return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); } -UPB_INLINE void google_protobuf_FileOptions_clear_php_generic_services(google_protobuf_FileOptions* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 42); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); -} -UPB_INLINE bool google_protobuf_FileOptions_php_generic_services(const google_protobuf_FileOptions* msg) { - bool default_val = false; - bool ret; - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 42); - _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field, - &default_val, &ret); - return ret; -} -UPB_INLINE bool google_protobuf_FileOptions_has_php_generic_services(const google_protobuf_FileOptions* msg) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 42); - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); -} UPB_INLINE void google_protobuf_FileOptions_clear_php_metadata_namespace(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 44); _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); @@ -3564,8 +3548,8 @@ UPB_INLINE const upb_Array* _google_protobuf_FileOptions_uninterpreted_option_up } UPB_INLINE upb_Array* _google_protobuf_FileOptions_uninterpreted_option_mutable_upb_array(google_protobuf_FileOptions* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 999); - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - UPB_UPCAST(msg), &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), + &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -3640,10 +3624,6 @@ UPB_INLINE void google_protobuf_FileOptions_set_php_namespace(google_protobuf_Fi const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 41); _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); } -UPB_INLINE void google_protobuf_FileOptions_set_php_generic_services(google_protobuf_FileOptions *msg, bool value) { - const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 42); - _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); -} UPB_INLINE void google_protobuf_FileOptions_set_php_metadata_namespace(google_protobuf_FileOptions *msg, upb_StringView value) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 44); _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value); @@ -3852,8 +3832,8 @@ UPB_INLINE const upb_Array* _google_protobuf_MessageOptions_uninterpreted_option } UPB_INLINE upb_Array* _google_protobuf_MessageOptions_uninterpreted_option_mutable_upb_array(google_protobuf_MessageOptions* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MessageOptions_msg_init(), 999); - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - UPB_UPCAST(msg), &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), + &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -4128,8 +4108,8 @@ UPB_INLINE const upb_Array* _google_protobuf_FieldOptions_targets_upb_array(cons } UPB_INLINE upb_Array* _google_protobuf_FieldOptions_targets_mutable_upb_array(google_protobuf_FieldOptions* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 19); - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - UPB_UPCAST(msg), &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), + &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -4160,8 +4140,8 @@ UPB_INLINE const upb_Array* _google_protobuf_FieldOptions_edition_defaults_upb_a } UPB_INLINE upb_Array* _google_protobuf_FieldOptions_edition_defaults_mutable_upb_array(google_protobuf_FieldOptions* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 20); - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - UPB_UPCAST(msg), &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), + &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -4208,8 +4188,8 @@ UPB_INLINE const upb_Array* _google_protobuf_FieldOptions_uninterpreted_option_u } UPB_INLINE upb_Array* _google_protobuf_FieldOptions_uninterpreted_option_mutable_upb_array(google_protobuf_FieldOptions* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 999); - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - UPB_UPCAST(msg), &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), + &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -4508,8 +4488,8 @@ UPB_INLINE const upb_Array* _google_protobuf_OneofOptions_uninterpreted_option_u } UPB_INLINE upb_Array* _google_protobuf_OneofOptions_uninterpreted_option_mutable_upb_array(google_protobuf_OneofOptions* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__OneofOptions_msg_init(), 999); - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - UPB_UPCAST(msg), &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), + &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -4684,8 +4664,8 @@ UPB_INLINE const upb_Array* _google_protobuf_EnumOptions_uninterpreted_option_up } UPB_INLINE upb_Array* _google_protobuf_EnumOptions_uninterpreted_option_mutable_upb_array(google_protobuf_EnumOptions* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumOptions_msg_init(), 999); - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - UPB_UPCAST(msg), &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), + &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -4856,8 +4836,8 @@ UPB_INLINE const upb_Array* _google_protobuf_EnumValueOptions_uninterpreted_opti } UPB_INLINE upb_Array* _google_protobuf_EnumValueOptions_uninterpreted_option_mutable_upb_array(google_protobuf_EnumValueOptions* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumValueOptions_msg_init(), 999); - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - UPB_UPCAST(msg), &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), + &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -5008,8 +4988,8 @@ UPB_INLINE const upb_Array* _google_protobuf_ServiceOptions_uninterpreted_option } UPB_INLINE upb_Array* _google_protobuf_ServiceOptions_uninterpreted_option_mutable_upb_array(google_protobuf_ServiceOptions* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ServiceOptions_msg_init(), 999); - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - UPB_UPCAST(msg), &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), + &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -5172,8 +5152,8 @@ UPB_INLINE const upb_Array* _google_protobuf_MethodOptions_uninterpreted_option_ } UPB_INLINE upb_Array* _google_protobuf_MethodOptions_uninterpreted_option_mutable_upb_array(google_protobuf_MethodOptions* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MethodOptions_msg_init(), 999); - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - UPB_UPCAST(msg), &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), + &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -5292,8 +5272,8 @@ UPB_INLINE const upb_Array* _google_protobuf_UninterpretedOption_name_upb_array( } UPB_INLINE upb_Array* _google_protobuf_UninterpretedOption_name_mutable_upb_array(google_protobuf_UninterpretedOption* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__UninterpretedOption_msg_init(), 2); - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - UPB_UPCAST(msg), &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), + &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -5748,8 +5728,8 @@ UPB_INLINE const upb_Array* _google_protobuf_FeatureSetDefaults_defaults_upb_arr } UPB_INLINE upb_Array* _google_protobuf_FeatureSetDefaults_defaults_mutable_upb_array(google_protobuf_FeatureSetDefaults* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FeatureSetDefaults_msg_init(), 1); - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - UPB_UPCAST(msg), &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), + &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -5974,8 +5954,8 @@ UPB_INLINE const upb_Array* _google_protobuf_SourceCodeInfo_location_upb_array(c } UPB_INLINE upb_Array* _google_protobuf_SourceCodeInfo_location_mutable_upb_array(google_protobuf_SourceCodeInfo* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__SourceCodeInfo_msg_init(), 1); - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - UPB_UPCAST(msg), &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), + &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -6074,8 +6054,8 @@ UPB_INLINE const upb_Array* _google_protobuf_SourceCodeInfo_Location_path_upb_ar } UPB_INLINE upb_Array* _google_protobuf_SourceCodeInfo_Location_path_mutable_upb_array(google_protobuf_SourceCodeInfo_Location* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__SourceCodeInfo__Location_msg_init(), 1); - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - UPB_UPCAST(msg), &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), + &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -6106,8 +6086,8 @@ UPB_INLINE const upb_Array* _google_protobuf_SourceCodeInfo_Location_span_upb_ar } UPB_INLINE upb_Array* _google_protobuf_SourceCodeInfo_Location_span_mutable_upb_array(google_protobuf_SourceCodeInfo_Location* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__SourceCodeInfo__Location_msg_init(), 2); - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - UPB_UPCAST(msg), &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), + &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -6170,8 +6150,8 @@ UPB_INLINE const upb_Array* _google_protobuf_SourceCodeInfo_Location_leading_det } UPB_INLINE upb_Array* _google_protobuf_SourceCodeInfo_Location_leading_detached_comments_mutable_upb_array(google_protobuf_SourceCodeInfo_Location* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__SourceCodeInfo__Location_msg_init(), 6); - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - UPB_UPCAST(msg), &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), + &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -6332,8 +6312,8 @@ UPB_INLINE const upb_Array* _google_protobuf_GeneratedCodeInfo_annotation_upb_ar } UPB_INLINE upb_Array* _google_protobuf_GeneratedCodeInfo_annotation_mutable_upb_array(google_protobuf_GeneratedCodeInfo* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__GeneratedCodeInfo_msg_init(), 1); - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - UPB_UPCAST(msg), &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), + &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -6432,8 +6412,8 @@ UPB_INLINE const upb_Array* _google_protobuf_GeneratedCodeInfo_Annotation_path_u } UPB_INLINE upb_Array* _google_protobuf_GeneratedCodeInfo_Annotation_path_mutable_upb_array(google_protobuf_GeneratedCodeInfo_Annotation* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__GeneratedCodeInfo__Annotation_msg_init(), 1); - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - UPB_UPCAST(msg), &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), + &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } diff --git a/upb_generator/stage0/google/protobuf/compiler/plugin.upb.h b/upb_generator/stage0/google/protobuf/compiler/plugin.upb.h index f987de7a5cadc..fedc5299d5ad8 100644 --- a/upb_generator/stage0/google/protobuf/compiler/plugin.upb.h +++ b/upb_generator/stage0/google/protobuf/compiler/plugin.upb.h @@ -219,8 +219,8 @@ UPB_INLINE const upb_Array* _google_protobuf_compiler_CodeGeneratorRequest_file_ } UPB_INLINE upb_Array* _google_protobuf_compiler_CodeGeneratorRequest_file_to_generate_mutable_upb_array(google_protobuf_compiler_CodeGeneratorRequest* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorRequest_msg_init(), 1); - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - UPB_UPCAST(msg), &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), + &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -283,8 +283,8 @@ UPB_INLINE const upb_Array* _google_protobuf_compiler_CodeGeneratorRequest_proto } UPB_INLINE upb_Array* _google_protobuf_compiler_CodeGeneratorRequest_proto_file_mutable_upb_array(google_protobuf_compiler_CodeGeneratorRequest* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorRequest_msg_init(), 15); - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - UPB_UPCAST(msg), &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), + &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -315,8 +315,8 @@ UPB_INLINE const upb_Array* _google_protobuf_compiler_CodeGeneratorRequest_sourc } UPB_INLINE upb_Array* _google_protobuf_compiler_CodeGeneratorRequest_source_file_descriptors_mutable_upb_array(google_protobuf_compiler_CodeGeneratorRequest* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorRequest_msg_init(), 17); - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - UPB_UPCAST(msg), &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), + &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } @@ -553,8 +553,8 @@ UPB_INLINE const upb_Array* _google_protobuf_compiler_CodeGeneratorResponse_file } UPB_INLINE upb_Array* _google_protobuf_compiler_CodeGeneratorResponse_file_mutable_upb_array(google_protobuf_compiler_CodeGeneratorResponse* msg, size_t* size, upb_Arena* arena) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorResponse_msg_init(), 15); - upb_Array* arr = upb_Message_GetOrCreateMutableArray( - UPB_UPCAST(msg), &field, arena); + upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg), + &field, arena); if (size) { *size = arr ? arr->UPB_PRIVATE(size) : 0; } From e27855032a6c9cb2339f7847658d9837861cd487 Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Thu, 21 Dec 2023 21:28:36 +0000 Subject: [PATCH 091/255] Auto-generate files after cl/592935088 --- php/ext/google/protobuf/php-upb.c | 11 ++++++++++- php/ext/google/protobuf/php-upb.h | 8 ++++++++ ruby/ext/google/protobuf_c/ruby-upb.c | 11 ++++++++++- ruby/ext/google/protobuf_c/ruby-upb.h | 8 ++++++++ 4 files changed, 36 insertions(+), 2 deletions(-) diff --git a/php/ext/google/protobuf/php-upb.c b/php/ext/google/protobuf/php-upb.c index 6c8d4fc265065..7ab0b5248e83d 100644 --- a/php/ext/google/protobuf/php-upb.c +++ b/php/ext/google/protobuf/php-upb.c @@ -95,6 +95,13 @@ Error, UINTPTR_MAX is undefined #define UPB_ALIGN_OF(type) offsetof (struct { char c; type member; }, member) #endif +#ifdef _MSC_VER +// Some versions of our Windows compiler don't support the C11 syntax. +#define UPB_ALIGN_AS(x) __declspec(align(x)) +#else +#define UPB_ALIGN_AS(x) _Alignas(x) +#endif + // Hints to the compiler about likely/unlikely branches. #if defined (__GNUC__) || defined(__clang__) #define UPB_LIKELY(x) __builtin_expect((bool)(x), 1) @@ -10983,7 +10990,8 @@ void _upb_FileDef_Create(upb_DefBuilder* ctx, * initialized to zeroes. * * We have to allocate an extra pointer for upb's internal metadata. */ -static const char opt_default_buf[_UPB_MAXOPT_SIZE + sizeof(void*)] = {0}; +static UPB_ALIGN_AS(8) const + char opt_default_buf[_UPB_MAXOPT_SIZE + sizeof(void*)] = {0}; const char* kUpbDefOptDefault = &opt_default_buf[sizeof(void*)]; const char* _upb_DefBuilder_FullToShort(const char* fullname) { @@ -15794,6 +15802,7 @@ const char* _upb_WireReader_SkipGroup(const char* ptr, uint32_t tag, #undef UPB_ALIGN_DOWN #undef UPB_ALIGN_MALLOC #undef UPB_ALIGN_OF +#undef UPB_ALIGN_AS #undef UPB_MALLOC_ALIGN #undef UPB_LIKELY #undef UPB_UNLIKELY diff --git a/php/ext/google/protobuf/php-upb.h b/php/ext/google/protobuf/php-upb.h index d31ab2d530597..87af0ee6e5ae9 100644 --- a/php/ext/google/protobuf/php-upb.h +++ b/php/ext/google/protobuf/php-upb.h @@ -94,6 +94,13 @@ Error, UINTPTR_MAX is undefined #define UPB_ALIGN_OF(type) offsetof (struct { char c; type member; }, member) #endif +#ifdef _MSC_VER +// Some versions of our Windows compiler don't support the C11 syntax. +#define UPB_ALIGN_AS(x) __declspec(align(x)) +#else +#define UPB_ALIGN_AS(x) _Alignas(x) +#endif + // Hints to the compiler about likely/unlikely branches. #if defined (__GNUC__) || defined(__clang__) #define UPB_LIKELY(x) __builtin_expect((bool)(x), 1) @@ -13968,6 +13975,7 @@ UPB_INLINE const char* upb_WireReader_SkipValue( #undef UPB_ALIGN_DOWN #undef UPB_ALIGN_MALLOC #undef UPB_ALIGN_OF +#undef UPB_ALIGN_AS #undef UPB_MALLOC_ALIGN #undef UPB_LIKELY #undef UPB_UNLIKELY diff --git a/ruby/ext/google/protobuf_c/ruby-upb.c b/ruby/ext/google/protobuf_c/ruby-upb.c index efd6dd089ec2f..bcfca4d07e322 100644 --- a/ruby/ext/google/protobuf_c/ruby-upb.c +++ b/ruby/ext/google/protobuf_c/ruby-upb.c @@ -95,6 +95,13 @@ Error, UINTPTR_MAX is undefined #define UPB_ALIGN_OF(type) offsetof (struct { char c; type member; }, member) #endif +#ifdef _MSC_VER +// Some versions of our Windows compiler don't support the C11 syntax. +#define UPB_ALIGN_AS(x) __declspec(align(x)) +#else +#define UPB_ALIGN_AS(x) _Alignas(x) +#endif + // Hints to the compiler about likely/unlikely branches. #if defined (__GNUC__) || defined(__clang__) #define UPB_LIKELY(x) __builtin_expect((bool)(x), 1) @@ -10499,7 +10506,8 @@ void _upb_FileDef_Create(upb_DefBuilder* ctx, * initialized to zeroes. * * We have to allocate an extra pointer for upb's internal metadata. */ -static const char opt_default_buf[_UPB_MAXOPT_SIZE + sizeof(void*)] = {0}; +static UPB_ALIGN_AS(8) const + char opt_default_buf[_UPB_MAXOPT_SIZE + sizeof(void*)] = {0}; const char* kUpbDefOptDefault = &opt_default_buf[sizeof(void*)]; const char* _upb_DefBuilder_FullToShort(const char* fullname) { @@ -15310,6 +15318,7 @@ const char* _upb_WireReader_SkipGroup(const char* ptr, uint32_t tag, #undef UPB_ALIGN_DOWN #undef UPB_ALIGN_MALLOC #undef UPB_ALIGN_OF +#undef UPB_ALIGN_AS #undef UPB_MALLOC_ALIGN #undef UPB_LIKELY #undef UPB_UNLIKELY diff --git a/ruby/ext/google/protobuf_c/ruby-upb.h b/ruby/ext/google/protobuf_c/ruby-upb.h index 3e2d23cc185a2..005e2349c2861 100755 --- a/ruby/ext/google/protobuf_c/ruby-upb.h +++ b/ruby/ext/google/protobuf_c/ruby-upb.h @@ -96,6 +96,13 @@ Error, UINTPTR_MAX is undefined #define UPB_ALIGN_OF(type) offsetof (struct { char c; type member; }, member) #endif +#ifdef _MSC_VER +// Some versions of our Windows compiler don't support the C11 syntax. +#define UPB_ALIGN_AS(x) __declspec(align(x)) +#else +#define UPB_ALIGN_AS(x) _Alignas(x) +#endif + // Hints to the compiler about likely/unlikely branches. #if defined (__GNUC__) || defined(__clang__) #define UPB_LIKELY(x) __builtin_expect((bool)(x), 1) @@ -13787,6 +13794,7 @@ UPB_INLINE const char* upb_WireReader_SkipValue( #undef UPB_ALIGN_DOWN #undef UPB_ALIGN_MALLOC #undef UPB_ALIGN_OF +#undef UPB_ALIGN_AS #undef UPB_MALLOC_ALIGN #undef UPB_LIKELY #undef UPB_UNLIKELY From a9bb9c5181d6b20cfe168839eda0c39600ad2bb2 Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Thu, 21 Dec 2023 14:07:32 -0800 Subject: [PATCH 092/255] TextFormat should always escape ASCII 127 (DEL). This was missed in the previous CL. DEL characters would be printed unescaped, which makes them more difficult to read but should still be data-preserving. PiperOrigin-RevId: 592946127 --- src/google/protobuf/text_format.cc | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/google/protobuf/text_format.cc b/src/google/protobuf/text_format.cc index 591543c90323f..cc74abc778982 100644 --- a/src/google/protobuf/text_format.cc +++ b/src/google/protobuf/text_format.cc @@ -1654,13 +1654,22 @@ namespace { // Returns true if `ch` needs to be escaped in TextFormat, independent of any // UTF-8 validity issues. bool DefinitelyNeedsEscape(unsigned char ch) { - if (ch < 32) return true; + if (ch >= 0x80) { + return false; // High byte; no escapes necessary if UTF-8 is vaid. + } + + if (!absl::ascii_isprint(ch)) { + return true; // Unprintable characters need escape. + } + switch (ch) { case '\"': case '\'': case '\\': + // These characters need escapes despite being printable. return true; } + return false; } From a4576cb8208ea8f1c4b05b9bb35533201e301171 Mon Sep 17 00:00:00 2001 From: Augie Fackler Date: Fri, 22 Dec 2023 00:52:58 -0800 Subject: [PATCH 093/255] RustInternalModuleName: use a more complete mangling system to avoid conflicts This is based on the mangling Mercurial used in its fncache system, and leaves us room to need to escape other symbols in the future. PiperOrigin-RevId: 593048297 --- src/google/protobuf/compiler/rust/naming.cc | 5 +-- .../protobuf/compiler/rust/naming_test.cc | 37 +++++++++++++++++++ 2 files changed, 39 insertions(+), 3 deletions(-) create mode 100644 src/google/protobuf/compiler/rust/naming_test.cc diff --git a/src/google/protobuf/compiler/rust/naming.cc b/src/google/protobuf/compiler/rust/naming.cc index 12fb0891a4ab1..1167ea7478408 100644 --- a/src/google/protobuf/compiler/rust/naming.cc +++ b/src/google/protobuf/compiler/rust/naming.cc @@ -214,9 +214,8 @@ std::string RustModule(Context& ctx, const Descriptor& msg) { } std::string RustInternalModuleName(Context& ctx, const FileDescriptor& file) { - // TODO: Introduce a more robust mangling here to avoid conflicts - // between `foo/bar/baz.proto` and `foo_bar/baz.proto`. - return absl::StrReplaceAll(StripProto(file.name()), {{"/", "_"}}); + return absl::StrReplaceAll(StripProto(file.name()), + {{"_", "__"}, {"/", "_s"}}); } std::string GetCrateRelativeQualifiedPath(Context& ctx, const Descriptor& msg) { diff --git a/src/google/protobuf/compiler/rust/naming_test.cc b/src/google/protobuf/compiler/rust/naming_test.cc new file mode 100644 index 0000000000000..a9294d00acec7 --- /dev/null +++ b/src/google/protobuf/compiler/rust/naming_test.cc @@ -0,0 +1,37 @@ +#include "google/protobuf/compiler/rust/naming.h" + +#include +#include + +#include +#include "google/protobuf/compiler/rust/context.h" +#include "google/protobuf/descriptor.h" +#include "google/protobuf/io/zero_copy_stream_impl_lite.h" + +using google::protobuf::compiler::rust::Context; +using google::protobuf::compiler::rust::Kernel; +using google::protobuf::compiler::rust::Options; +using google::protobuf::compiler::rust::RustGeneratorContext; +using google::protobuf::compiler::rust::RustInternalModuleName; +using google::protobuf::io::Printer; +using google::protobuf::io::StringOutputStream; + +namespace { +TEST(RustProtoNaming, RustInternalModuleName) { + google::protobuf::FileDescriptorProto foo_file; + foo_file.set_name("strong_bad/lol.proto"); + google::protobuf::DescriptorPool pool; + const google::protobuf::FileDescriptor* fd = pool.BuildFile(foo_file); + + const Options opts = {Kernel::kUpb}; + std::vector files{fd}; + const RustGeneratorContext rust_generator_context(&files); + std::string output; + StringOutputStream stream{&output}; + Printer printer(&stream); + Context c = Context(&opts, &rust_generator_context, &printer); + + EXPECT_EQ(RustInternalModuleName(c, *fd), "strong__bad_slol"); +} + +} // namespace From 16afb4dea76efab652d86e4ebf9a118138f88578 Mon Sep 17 00:00:00 2001 From: Sandy Zhang Date: Tue, 26 Dec 2023 09:04:12 -0800 Subject: [PATCH 094/255] Bump major versions in version.json for C++, Java, Python, PHP, and Ruby in preparation for v26.x release in January. These languages include breaking changes in accordance with https://protobuf.dev/support/version-support/ and should be announced in https://protobuf.dev/news/ PiperOrigin-RevId: 593803067 --- version.json | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/version.json b/version.json index 735b320f9f593..05700139ceb48 100644 --- a/version.json +++ b/version.json @@ -4,14 +4,14 @@ "lts": false, "date": "2023-11-01", "languages": { - "cpp": "4.26-dev", + "cpp": "5.26-dev", "csharp": "3.26-dev", - "java": "3.26-dev", + "java": "4.26-dev", "javascript": "3.26-dev", "objectivec": "3.26-dev", - "php": "3.26-dev", - "python": "4.26-dev", - "ruby": "3.26-dev" + "php": "4.26-dev", + "python": "5.26-dev", + "ruby": "4.26-dev" } } } From 2fb0b93d9de226ea96f2dc2b4779eb4712d01d5c Mon Sep 17 00:00:00 2001 From: Eric Salo Date: Tue, 26 Dec 2023 10:55:58 -0800 Subject: [PATCH 095/255] upb: tighten up and lock down upb/wire/ PiperOrigin-RevId: 593821827 --- protos/BUILD | 2 +- python/BUILD.bazel | 1 - upb/BUILD | 19 -------- upb/generated_code_support.h | 2 +- upb/message/BUILD | 2 - upb/mini_table/BUILD | 1 - upb/mini_table/internal/message.h | 4 +- upb/text/BUILD | 1 - upb/util/BUILD | 5 +- upb/util/compare_test.cc | 9 ++-- upb/wire/BUILD | 46 +++++------------- upb/wire/decode.c | 9 ++-- upb/wire/encode.c | 15 +++--- upb/wire/encode.h | 1 + upb/wire/{ => internal}/decode_fast.c | 2 +- upb/wire/{ => internal}/decode_fast.h | 6 +-- upb/wire/internal/{swap.h => endian.h} | 22 ++++----- upb/wire/internal/reader.h | 61 ++++++++++++++++++++++++ upb/wire/reader.c | 15 +++--- upb/wire/reader.h | 65 +++++++------------------- upb_generator/BUILD | 4 +- 21 files changed, 142 insertions(+), 150 deletions(-) rename upb/wire/{ => internal}/decode_fast.c (99%) rename upb/wire/{ => internal}/decode_fast.h (96%) rename upb/wire/internal/{swap.h => endian.h} (52%) create mode 100644 upb/wire/internal/reader.h diff --git a/protos/BUILD b/protos/BUILD index 867ce331eea44..b68a27eaac64d 100644 --- a/protos/BUILD +++ b/protos/BUILD @@ -62,7 +62,7 @@ cc_library( "//upb:message_types", "//upb:mini_table", "//upb:wire", - "//upb:wire_types", + "//upb:wire_reader", "@com_google_absl//absl/status", "@com_google_absl//absl/status:statusor", "@com_google_absl//absl/strings", diff --git a/python/BUILD.bazel b/python/BUILD.bazel index 7f2b24711524c..608381c274fe1 100644 --- a/python/BUILD.bazel +++ b/python/BUILD.bazel @@ -200,7 +200,6 @@ py_extension( "//upb:reflection", "//upb:text", "//upb:wire_reader", - "//upb:wire_types", "//upb/util:compare", "//upb/util:def_to_proto", "//upb/util:required_fields", diff --git a/upb/BUILD b/upb/BUILD index fe3374bc78a74..f0ecc770bb3da 100644 --- a/upb/BUILD +++ b/upb/BUILD @@ -117,7 +117,6 @@ cc_library( ":mini_descriptor", ":mini_table", ":wire", - ":wire_internal", ], ) @@ -327,24 +326,12 @@ alias( visibility = ["//visibility:public"], ) -alias( - name = "wire_internal", - actual = "//upb/wire:internal", - visibility = ["//visibility:public"], -) - alias( name = "wire_reader", actual = "//upb/wire:reader", visibility = ["//visibility:public"], ) -alias( - name = "wire_types", - actual = "//upb/wire:types", - visibility = ["//visibility:public"], -) - alias( name = "eps_copy_input_stream", actual = "//upb/wire:eps_copy_input_stream", @@ -407,9 +394,7 @@ upb_amalgamation( ":reflection", ":reflection_internal", ":wire", - ":wire_internal", ":wire_reader", - ":wire_types", ], strip_import_prefix = ["src"], ) @@ -455,9 +440,7 @@ upb_amalgamation( ":reflection", ":reflection_internal", ":wire", - ":wire_internal", ":wire_reader", - ":wire_types", ], prefix = "php-", strip_import_prefix = ["src"], @@ -504,9 +487,7 @@ upb_amalgamation( ":reflection", ":reflection_internal", ":wire", - ":wire_internal", ":wire_reader", - ":wire_types", ], prefix = "ruby-", strip_import_prefix = ["src"], diff --git a/upb/generated_code_support.h b/upb/generated_code_support.h index 025ff0eedaf6e..2a3d03d4eb281 100644 --- a/upb/generated_code_support.h +++ b/upb/generated_code_support.h @@ -27,8 +27,8 @@ #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" +#include "upb/wire/internal/decode_fast.h" // IWYU pragma: end_exports #endif // UPB_GENERATED_CODE_SUPPORT_H_ diff --git a/upb/message/BUILD b/upb/message/BUILD index ac2e3583cec38..98facaa8a797d 100644 --- a/upb/message/BUILD +++ b/upb/message/BUILD @@ -33,7 +33,6 @@ cc_library( ":message", ":tagged_ptr", "//upb:base", - "//upb:eps_copy_input_stream", "//upb:mem", "//upb:message_types", "//upb:mini_table", @@ -181,7 +180,6 @@ cc_library( "//upb:mini_table", "//upb:port", "//upb:wire", - "//upb:wire_internal", "//upb:wire_reader", ], ) diff --git a/upb/mini_table/BUILD b/upb/mini_table/BUILD index ba4b63ab2bea3..457f657d45291 100644 --- a/upb/mini_table/BUILD +++ b/upb/mini_table/BUILD @@ -40,7 +40,6 @@ cc_library( "//upb:base", "//upb:hash", "//upb:mem", - "//upb:message_types", "//upb:port", ], ) diff --git a/upb/mini_table/internal/message.h b/upb/mini_table/internal/message.h index d894a0bd177c0..5aa3b6097335e 100644 --- a/upb/mini_table/internal/message.h +++ b/upb/mini_table/internal/message.h @@ -10,7 +10,6 @@ #include -#include "upb/message/types.h" #include "upb/mini_table/internal/field.h" #include "upb/mini_table/internal/sub.h" #include "upb/mini_table/types.h" @@ -19,8 +18,9 @@ #include "upb/port/def.inc" struct upb_Decoder; +struct upb_Message; typedef const char* _upb_FieldParser(struct upb_Decoder* d, const char* ptr, - upb_Message* msg, intptr_t table, + struct upb_Message* msg, intptr_t table, uint64_t hasbits, uint64_t data); typedef struct { uint64_t field_data; diff --git a/upb/text/BUILD b/upb/text/BUILD index 575dda3bc3f84..e3826c92ce3a9 100644 --- a/upb/text/BUILD +++ b/upb/text/BUILD @@ -26,7 +26,6 @@ cc_library( "//upb:reflection", "//upb:wire", "//upb:wire_reader", - "//upb:wire_types", ], ) diff --git a/upb/util/BUILD b/upb/util/BUILD index d2279918da5fb..f4c9803b4a29c 100644 --- a/upb/util/BUILD +++ b/upb/util/BUILD @@ -153,7 +153,6 @@ cc_library( "//upb:mem", "//upb:port", "//upb:wire_reader", - "//upb:wire_types", ], ) @@ -163,8 +162,8 @@ cc_test( deps = [ ":compare", "@com_google_googletest//:gtest_main", - "//upb:wire_internal", - "//upb:wire_types", + "//upb:port", + "//upb:wire_reader", "@com_google_absl//absl/strings", ], ) diff --git a/upb/util/compare_test.cc b/upb/util/compare_test.cc index f9b34da7aa29b..b29a0ccbdce66 100644 --- a/upb/util/compare_test.cc +++ b/upb/util/compare_test.cc @@ -15,9 +15,12 @@ #include #include -#include "upb/wire/internal/swap.h" +#include "upb/wire/internal/endian.h" #include "upb/wire/types.h" +// Must be last. +#include "upb/port/def.inc" + struct UnknownField; using UnknownFields = std::vector; @@ -81,11 +84,11 @@ std::string ToBinaryPayload(const UnknownFields& fields) { ret.append(val->val); } else if (const auto* val = std::get_if(&field.value)) { EncodeVarint(field.field_number << 3 | kUpb_WireType_64Bit, &ret); - uint64_t swapped = _upb_BigEndian_Swap64(val->val); + uint64_t swapped = UPB_PRIVATE(_upb_BigEndian64)(val->val); ret.append(reinterpret_cast(&swapped), sizeof(swapped)); } else if (const auto* val = std::get_if(&field.value)) { EncodeVarint(field.field_number << 3 | kUpb_WireType_32Bit, &ret); - uint32_t swapped = _upb_BigEndian_Swap32(val->val); + uint32_t swapped = UPB_PRIVATE(_upb_BigEndian32)(val->val); ret.append(reinterpret_cast(&swapped), sizeof(swapped)); } else if (const auto* val = std::get_if(&field.value)) { EncodeVarint(field.field_number << 3 | kUpb_WireType_StartGroup, &ret); diff --git a/upb/wire/BUILD b/upb/wire/BUILD index d644af7f4c6ac..2275fb4e6d240 100644 --- a/upb/wire/BUILD +++ b/upb/wire/BUILD @@ -9,45 +9,23 @@ load("//bazel:build_defs.bzl", "UPB_DEFAULT_COPTS") cc_library( name = "wire", - srcs = [ - ], - hdrs = [ - "decode.h", - "encode.h", - ], - copts = UPB_DEFAULT_COPTS, - visibility = ["//visibility:public"], - deps = [ - ":internal", - ":types", - "//upb:mem", - "//upb:message", - "//upb:mini_table", - "//upb:port", - ], -) - -cc_library( - name = "internal", srcs = [ "decode.c", - "decode.h", - "decode_fast.c", "encode.c", - "encode.h", + "internal/decode_fast.c", ], hdrs = [ - "decode_fast.h", + "decode.h", + "encode.h", "internal/constants.h", "internal/decode.h", - "internal/swap.h", + "internal/decode_fast.h", ], copts = UPB_DEFAULT_COPTS, visibility = ["//visibility:public"], deps = [ ":eps_copy_input_stream", ":reader", - ":types", "//upb:base", "//upb:hash", "//upb:mem", @@ -56,6 +34,7 @@ cc_library( "//upb:message_internal", "//upb:message_internal_types", "//upb:message_tagged_ptr", + "//upb:message_types", "//upb:mini_table", "//upb:port", "//third_party/utf8_range", @@ -65,24 +44,21 @@ cc_library( cc_library( name = "reader", srcs = [ - "internal/swap.h", "reader.c", ], - hdrs = ["reader.h"], + hdrs = [ + "internal/endian.h", + "internal/reader.h", + "reader.h", + "types.h", + ], visibility = ["//visibility:public"], deps = [ ":eps_copy_input_stream", - ":types", "//upb:port", ], ) -cc_library( - name = "types", - hdrs = ["types.h"], - visibility = ["//visibility:public"], -) - cc_library( name = "eps_copy_input_stream", srcs = ["eps_copy_input_stream.c"], diff --git a/upb/wire/decode.c b/upb/wire/decode.c index f6bb42768ba20..ddc288f1a320d 100644 --- a/upb/wire/decode.c +++ b/upb/wire/decode.c @@ -31,6 +31,7 @@ #include "upb/mini_table/extension.h" #include "upb/mini_table/extension_registry.h" #include "upb/mini_table/field.h" +#include "upb/mini_table/internal/field.h" #include "upb/mini_table/internal/size_log2.h" #include "upb/mini_table/message.h" #include "upb/mini_table/sub.h" @@ -39,7 +40,7 @@ #include "upb/wire/eps_copy_input_stream.h" #include "upb/wire/internal/constants.h" #include "upb/wire/internal/decode.h" -#include "upb/wire/internal/swap.h" +#include "upb/wire/internal/endian.h" #include "upb/wire/reader.h" // Must be last. @@ -209,7 +210,7 @@ static const char* upb_Decoder_DecodeSize(upb_Decoder* d, const char* ptr, } static void _upb_Decoder_MungeInt32(wireval* val) { - if (!_upb_IsLittleEndian()) { + if (!UPB_PRIVATE(_upb_IsLittleEndian)()) { /* The next stage will memcpy(dst, &val, 4) */ val->uint32_val = val->uint64_val; } @@ -429,7 +430,7 @@ static const char* _upb_Decoder_DecodeFixedPacked( arr->UPB_PRIVATE(size) += count; // Note: if/when the decoder supports multi-buffer input, we will need to // handle buffer seams here. - if (_upb_IsLittleEndian()) { + if (UPB_PRIVATE(_upb_IsLittleEndian)()) { ptr = upb_EpsCopyInputStream_Copy(&d->input, ptr, mem, val->size); } else { int delta = upb_EpsCopyInputStream_PushLimit(&d->input, ptr, val->size); @@ -753,7 +754,7 @@ const char* _upb_Decoder_CheckRequired(upb_Decoder* d, const char* ptr, } uint64_t msg_head; memcpy(&msg_head, msg, 8); - msg_head = _upb_BigEndian_Swap64(msg_head); + msg_head = UPB_PRIVATE(_upb_BigEndian64)(msg_head); if (UPB_PRIVATE(_upb_MiniTable_RequiredMask)(m) & ~msg_head) { d->missing_required = true; } diff --git a/upb/wire/encode.c b/upb/wire/encode.c index ae2be7f734333..1d04ce6d975c2 100644 --- a/upb/wire/encode.c +++ b/upb/wire/encode.c @@ -31,10 +31,11 @@ #include "upb/message/tagged_ptr.h" #include "upb/mini_table/extension.h" #include "upb/mini_table/field.h" +#include "upb/mini_table/internal/field.h" #include "upb/mini_table/message.h" #include "upb/mini_table/sub.h" #include "upb/wire/internal/constants.h" -#include "upb/wire/internal/swap.h" +#include "upb/wire/internal/endian.h" #include "upb/wire/types.h" // Must be last. @@ -127,12 +128,12 @@ static void encode_bytes(upb_encstate* e, const void* data, size_t len) { } static void encode_fixed64(upb_encstate* e, uint64_t val) { - val = _upb_BigEndian_Swap64(val); + val = UPB_PRIVATE(_upb_BigEndian64)(val); encode_bytes(e, &val, sizeof(uint64_t)); } static void encode_fixed32(upb_encstate* e, uint32_t val) { - val = _upb_BigEndian_Swap32(val); + val = UPB_PRIVATE(_upb_BigEndian32)(val); encode_bytes(e, &val, sizeof(uint32_t)); } @@ -183,18 +184,18 @@ static void encode_fixedarray(upb_encstate* e, const upb_Array* arr, const char* data = _upb_array_constptr(arr); const char* ptr = data + bytes - elem_size; - if (tag || !_upb_IsLittleEndian()) { + if (tag || !UPB_PRIVATE(_upb_IsLittleEndian)()) { while (true) { if (elem_size == 4) { uint32_t val; memcpy(&val, ptr, sizeof(val)); - val = _upb_BigEndian_Swap32(val); + val = UPB_PRIVATE(_upb_BigEndian32)(val); encode_bytes(e, &val, elem_size); } else { UPB_ASSERT(elem_size == 8); uint64_t val; memcpy(&val, ptr, sizeof(val)); - val = _upb_BigEndian_Swap64(val); + val = UPB_PRIVATE(_upb_BigEndian64)(val); encode_bytes(e, &val, elem_size); } @@ -548,7 +549,7 @@ static void encode_message(upb_encstate* e, const upb_Message* msg, m->UPB_PRIVATE(required_count)) { uint64_t msg_head; memcpy(&msg_head, msg, 8); - msg_head = _upb_BigEndian_Swap64(msg_head); + msg_head = UPB_PRIVATE(_upb_BigEndian64)(msg_head); if (UPB_PRIVATE(_upb_MiniTable_RequiredMask)(m) & ~msg_head) { encode_err(e, kUpb_EncodeStatus_MissingRequired); } diff --git a/upb/wire/encode.h b/upb/wire/encode.h index fdccaf963e021..4c5969dee7b2c 100644 --- a/upb/wire/encode.h +++ b/upb/wire/encode.h @@ -14,6 +14,7 @@ #include #include "upb/mem/arena.h" +#include "upb/message/types.h" #include "upb/mini_table/message.h" // Must be last. diff --git a/upb/wire/decode_fast.c b/upb/wire/internal/decode_fast.c similarity index 99% rename from upb/wire/decode_fast.c rename to upb/wire/internal/decode_fast.c index 4062e2b619c93..61b19b6af5b12 100644 --- a/upb/wire/decode_fast.c +++ b/upb/wire/internal/decode_fast.c @@ -15,7 +15,7 @@ // field type (eg. oneof boolean field with a 1 byte tag) and then dispatch // to the specialized function as quickly as possible. -#include "upb/wire/decode_fast.h" +#include "upb/wire/internal/decode_fast.h" #include "upb/message/array.h" #include "upb/message/internal/array.h" diff --git a/upb/wire/decode_fast.h b/upb/wire/internal/decode_fast.h similarity index 96% rename from upb/wire/decode_fast.h rename to upb/wire/internal/decode_fast.h index 395342a2d6efc..5f486297196f0 100644 --- a/upb/wire/decode_fast.h +++ b/upb/wire/internal/decode_fast.h @@ -39,8 +39,8 @@ // - '1' for one-byte tags (field numbers 1-15) // - '2' for two-byte tags (field numbers 16-2048) -#ifndef UPB_WIRE_DECODE_FAST_H_ -#define UPB_WIRE_DECODE_FAST_H_ +#ifndef UPB_WIRE_DECODE_INTERNAL_FAST_H_ +#define UPB_WIRE_DECODE_INTERNAL_FAST_H_ #include "upb/message/message.h" @@ -144,4 +144,4 @@ TAGBYTES(r) #include "upb/port/undef.inc" -#endif /* UPB_WIRE_DECODE_FAST_H_ */ +#endif /* UPB_WIRE_DECODE_INTERNAL_FAST_H_ */ diff --git a/upb/wire/internal/swap.h b/upb/wire/internal/endian.h similarity index 52% rename from upb/wire/internal/swap.h rename to upb/wire/internal/endian.h index a203e45c43236..09788c9b313dc 100644 --- a/upb/wire/internal/swap.h +++ b/upb/wire/internal/endian.h @@ -5,8 +5,8 @@ // license that can be found in the LICENSE file or at // https://developers.google.com/open-source/licenses/bsd -#ifndef UPB_WIRE_INTERNAL_SWAP_H_ -#define UPB_WIRE_INTERNAL_SWAP_H_ +#ifndef UPB_WIRE_INTERNAL_ENDIAN_H_ +#define UPB_WIRE_INTERNAL_ENDIAN_H_ #include @@ -17,23 +17,23 @@ extern "C" { #endif -UPB_INLINE bool _upb_IsLittleEndian(void) { - int x = 1; +UPB_INLINE bool UPB_PRIVATE(_upb_IsLittleEndian)(void) { + const int x = 1; return *(char*)&x == 1; } -UPB_INLINE uint32_t _upb_BigEndian_Swap32(uint32_t val) { - if (_upb_IsLittleEndian()) return val; +UPB_INLINE uint32_t UPB_PRIVATE(_upb_BigEndian32)(uint32_t val) { + if (UPB_PRIVATE(_upb_IsLittleEndian)()) return val; return ((val & 0xff) << 24) | ((val & 0xff00) << 8) | ((val & 0xff0000) >> 8) | ((val & 0xff000000) >> 24); } -UPB_INLINE uint64_t _upb_BigEndian_Swap64(uint64_t val) { - if (_upb_IsLittleEndian()) return val; +UPB_INLINE uint64_t UPB_PRIVATE(_upb_BigEndian64)(uint64_t val) { + if (UPB_PRIVATE(_upb_IsLittleEndian)()) return val; - return ((uint64_t)_upb_BigEndian_Swap32((uint32_t)val) << 32) | - _upb_BigEndian_Swap32((uint32_t)(val >> 32)); + return ((uint64_t)UPB_PRIVATE(_upb_BigEndian32)((uint32_t)val) << 32) | + UPB_PRIVATE(_upb_BigEndian32)((uint32_t)(val >> 32)); } #ifdef __cplusplus @@ -42,4 +42,4 @@ UPB_INLINE uint64_t _upb_BigEndian_Swap64(uint64_t val) { #include "upb/port/undef.inc" -#endif /* UPB_WIRE_INTERNAL_SWAP_H_ */ +#endif /* UPB_WIRE_INTERNAL_ENDIAN_H_ */ diff --git a/upb/wire/internal/reader.h b/upb/wire/internal/reader.h new file mode 100644 index 0000000000000..2eff56bc86f40 --- /dev/null +++ b/upb/wire/internal/reader.h @@ -0,0 +1,61 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2023 Google LLC. All rights reserved. +// +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file or at +// https://developers.google.com/open-source/licenses/bsd + +#ifndef UPB_WIRE_INTERNAL_READER_H_ +#define UPB_WIRE_INTERNAL_READER_H_ + +// Must be last. +#include "upb/port/def.inc" + +#define kUpb_WireReader_WireTypeBits 3 +#define kUpb_WireReader_WireTypeMask 7 + +typedef struct { + const char* ptr; + uint64_t val; +} UPB_PRIVATE(_upb_WireReader_LongVarint); + +#ifdef __cplusplus +extern "C" { +#endif + +UPB_PRIVATE(_upb_WireReader_LongVarint) +UPB_PRIVATE(_upb_WireReader_ReadLongVarint)(const char* ptr, uint64_t val); + +static UPB_FORCEINLINE const char* UPB_PRIVATE(_upb_WireReader_ReadVarint)( + const char* ptr, uint64_t* val, int maxlen, uint64_t maxval) { + uint64_t byte = (uint8_t)*ptr; + if (UPB_LIKELY((byte & 0x80) == 0)) { + *val = (uint32_t)byte; + return ptr + 1; + } + const char* start = ptr; + UPB_PRIVATE(_upb_WireReader_LongVarint) + res = UPB_PRIVATE(_upb_WireReader_ReadLongVarint)(ptr, byte); + if (!res.ptr || (maxlen < 10 && res.ptr - start > maxlen) || + res.val > maxval) { + return NULL; // Malformed. + } + *val = res.val; + return res.ptr; +} + +UPB_INLINE uint32_t UPB_PRIVATE(_upb_WireReader_GetFieldNumber)(uint32_t tag) { + return tag >> kUpb_WireReader_WireTypeBits; +} + +UPB_INLINE uint8_t UPB_PRIVATE(_upb_WireReader_GetWireType)(uint32_t tag) { + return tag & kUpb_WireReader_WireTypeMask; +} + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#include "upb/port/undef.inc" + +#endif // UPB_WIRE_INTERNAL_READER_H_ diff --git a/upb/wire/reader.c b/upb/wire/reader.c index de6cde4fe7432..2af812bf58b9a 100644 --- a/upb/wire/reader.c +++ b/upb/wire/reader.c @@ -7,15 +7,18 @@ #include "upb/wire/reader.h" +#include +#include + #include "upb/wire/eps_copy_input_stream.h" #include "upb/wire/types.h" // Must be last. #include "upb/port/def.inc" -UPB_NOINLINE _upb_WireReader_ReadLongVarintRet -_upb_WireReader_ReadLongVarint(const char* ptr, uint64_t val) { - _upb_WireReader_ReadLongVarintRet ret = {NULL, 0}; +UPB_NOINLINE UPB_PRIVATE(_upb_WireReader_LongVarint) + UPB_PRIVATE(_upb_WireReader_ReadLongVarint)(const char* ptr, uint64_t val) { + UPB_PRIVATE(_upb_WireReader_LongVarint) ret = {NULL, 0}; uint64_t byte; int i; for (i = 1; i < 10; i++) { @@ -30,9 +33,9 @@ _upb_WireReader_ReadLongVarint(const char* ptr, uint64_t val) { return ret; } -const char* _upb_WireReader_SkipGroup(const char* ptr, uint32_t tag, - int depth_limit, - upb_EpsCopyInputStream* stream) { +const char* UPB_PRIVATE(_upb_WireReader_SkipGroup)( + const char* ptr, uint32_t tag, int depth_limit, + upb_EpsCopyInputStream* stream) { if (--depth_limit == 0) return NULL; uint32_t end_group_tag = (tag & ~7ULL) | kUpb_WireType_EndGroup; while (!upb_EpsCopyInputStream_IsDone(stream, &ptr)) { diff --git a/upb/wire/reader.h b/upb/wire/reader.h index 2181aa6a5e9ce..c3ec1a8b1839d 100644 --- a/upb/wire/reader.h +++ b/upb/wire/reader.h @@ -9,52 +9,22 @@ #define UPB_WIRE_READER_H_ #include "upb/wire/eps_copy_input_stream.h" -#include "upb/wire/internal/swap.h" +#include "upb/wire/internal/endian.h" +#include "upb/wire/internal/reader.h" #include "upb/wire/types.h" // IWYU pragma: export // Must be last. #include "upb/port/def.inc" -#ifdef __cplusplus -extern "C" { -#endif - // The upb_WireReader interface is suitable for general-purpose parsing of -// protobuf binary wire format. It is designed to be used along with +// protobuf binary wire format. It is designed to be used along with // upb_EpsCopyInputStream for buffering, and all parsing routines in this file // assume that at least kUpb_EpsCopyInputStream_SlopBytes worth of data is // available to read without any bounds checks. -#define kUpb_WireReader_WireTypeMask 7 -#define kUpb_WireReader_WireTypeBits 3 - -typedef struct { - const char* ptr; - uint64_t val; -} _upb_WireReader_ReadLongVarintRet; - -_upb_WireReader_ReadLongVarintRet _upb_WireReader_ReadLongVarint( - const char* ptr, uint64_t val); - -static UPB_FORCEINLINE const char* _upb_WireReader_ReadVarint(const char* ptr, - uint64_t* val, - int maxlen, - uint64_t maxval) { - uint64_t byte = (uint8_t)*ptr; - if (UPB_LIKELY((byte & 0x80) == 0)) { - *val = (uint32_t)byte; - return ptr + 1; - } - const char* start = ptr; - _upb_WireReader_ReadLongVarintRet res = - _upb_WireReader_ReadLongVarint(ptr, byte); - if (!res.ptr || (maxlen < 10 && res.ptr - start > maxlen) || - res.val > maxval) { - return NULL; // Malformed. - } - *val = res.val; - return res.ptr; -} +#ifdef __cplusplus +extern "C" { +#endif // Parses a tag into `tag`, and returns a pointer past the end of the tag, or // NULL if there was an error in the tag data. @@ -65,7 +35,7 @@ static UPB_FORCEINLINE const char* _upb_WireReader_ReadVarint(const char* ptr, static UPB_FORCEINLINE const char* upb_WireReader_ReadTag(const char* ptr, uint32_t* tag) { uint64_t val; - ptr = _upb_WireReader_ReadVarint(ptr, &val, 5, UINT32_MAX); + ptr = UPB_PRIVATE(_upb_WireReader_ReadVarint)(ptr, &val, 5, UINT32_MAX); if (!ptr) return NULL; *tag = val; return ptr; @@ -73,17 +43,17 @@ static UPB_FORCEINLINE const char* upb_WireReader_ReadTag(const char* ptr, // Given a tag, returns the field number. UPB_INLINE uint32_t upb_WireReader_GetFieldNumber(uint32_t tag) { - return tag >> kUpb_WireReader_WireTypeBits; + return UPB_PRIVATE(_upb_WireReader_GetFieldNumber)(tag); } // Given a tag, returns the wire type. UPB_INLINE uint8_t upb_WireReader_GetWireType(uint32_t tag) { - return tag & kUpb_WireReader_WireTypeMask; + return UPB_PRIVATE(_upb_WireReader_GetWireType)(tag); } UPB_INLINE const char* upb_WireReader_ReadVarint(const char* ptr, uint64_t* val) { - return _upb_WireReader_ReadVarint(ptr, val, 10, UINT64_MAX); + return UPB_PRIVATE(_upb_WireReader_ReadVarint)(ptr, val, 10, UINT64_MAX); } // Skips data for a varint, returning a pointer past the end of the varint, or @@ -119,7 +89,7 @@ UPB_INLINE const char* upb_WireReader_ReadSize(const char* ptr, int* size) { UPB_INLINE const char* upb_WireReader_ReadFixed32(const char* ptr, void* val) { uint32_t uval; memcpy(&uval, ptr, 4); - uval = _upb_BigEndian_Swap32(uval); + uval = UPB_PRIVATE(_upb_BigEndian32)(uval); memcpy(val, &uval, 4); return ptr + 4; } @@ -132,14 +102,14 @@ UPB_INLINE const char* upb_WireReader_ReadFixed32(const char* ptr, void* val) { UPB_INLINE const char* upb_WireReader_ReadFixed64(const char* ptr, void* val) { uint64_t uval; memcpy(&uval, ptr, 8); - uval = _upb_BigEndian_Swap64(uval); + uval = UPB_PRIVATE(_upb_BigEndian64)(uval); memcpy(val, &uval, 8); return ptr + 8; } -const char* _upb_WireReader_SkipGroup(const char* ptr, uint32_t tag, - int depth_limit, - upb_EpsCopyInputStream* stream); +const char* UPB_PRIVATE(_upb_WireReader_SkipGroup)( + const char* ptr, uint32_t tag, int depth_limit, + upb_EpsCopyInputStream* stream); // Skips data for a group, returning a pointer past the end of the group, or // NULL if there was an error parsing the group. The `tag` argument should be @@ -152,7 +122,7 @@ const char* _upb_WireReader_SkipGroup(const char* ptr, uint32_t tag, // control over this? UPB_INLINE const char* upb_WireReader_SkipGroup( const char* ptr, uint32_t tag, upb_EpsCopyInputStream* stream) { - return _upb_WireReader_SkipGroup(ptr, tag, 100, stream); + return UPB_PRIVATE(_upb_WireReader_SkipGroup)(ptr, tag, 100, stream); } UPB_INLINE const char* _upb_WireReader_SkipValue( @@ -173,7 +143,8 @@ UPB_INLINE const char* _upb_WireReader_SkipValue( return ptr; } case kUpb_WireType_StartGroup: - return _upb_WireReader_SkipGroup(ptr, tag, depth_limit, stream); + return UPB_PRIVATE(_upb_WireReader_SkipGroup)(ptr, tag, depth_limit, + stream); case kUpb_WireType_EndGroup: return NULL; // Should be handled before now. default: diff --git a/upb_generator/BUILD b/upb_generator/BUILD index 63bd0ac188786..c280281ae6ec0 100644 --- a/upb_generator/BUILD +++ b/upb_generator/BUILD @@ -266,7 +266,7 @@ bootstrap_cc_binary( "//upb:base", "//upb:mem", "//upb:port", - "//upb:wire_types", + "//upb:wire_reader", "@com_google_absl//absl/container:flat_hash_map", "@com_google_absl//absl/container:flat_hash_set", "@com_google_absl//absl/log:absl_check", @@ -305,7 +305,7 @@ bootstrap_cc_binary( "//upb:mem", "//upb:mini_table", "//upb:port", - "//upb:wire_types", + "//upb:wire_reader", "@com_google_absl//absl/container:flat_hash_map", "@com_google_absl//absl/container:flat_hash_set", "@com_google_absl//absl/log:absl_check", From da56def7c2461804d613a522df32799ca7a54f62 Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Tue, 26 Dec 2023 19:08:52 +0000 Subject: [PATCH 096/255] Auto-generate files after cl/593821827 --- php/ext/google/protobuf/php-upb.c | 2875 +++++++++++++------------ php/ext/google/protobuf/php-upb.h | 276 +-- ruby/ext/google/protobuf_c/ruby-upb.c | 2875 +++++++++++++------------ ruby/ext/google/protobuf_c/ruby-upb.h | 276 +-- upb/cmake/CMakeLists.txt | 3 +- 5 files changed, 3179 insertions(+), 3126 deletions(-) diff --git a/php/ext/google/protobuf/php-upb.c b/php/ext/google/protobuf/php-upb.c index 7ab0b5248e83d..00301dd36814f 100644 --- a/php/ext/google/protobuf/php-upb.c +++ b/php/ext/google/protobuf/php-upb.c @@ -12971,7 +12971,7 @@ static const char* upb_Decoder_DecodeSize(upb_Decoder* d, const char* ptr, } static void _upb_Decoder_MungeInt32(wireval* val) { - if (!_upb_IsLittleEndian()) { + if (!UPB_PRIVATE(_upb_IsLittleEndian)()) { /* The next stage will memcpy(dst, &val, 4) */ val->uint32_val = val->uint64_val; } @@ -13191,7 +13191,7 @@ static const char* _upb_Decoder_DecodeFixedPacked( arr->UPB_PRIVATE(size) += count; // Note: if/when the decoder supports multi-buffer input, we will need to // handle buffer seams here. - if (_upb_IsLittleEndian()) { + if (UPB_PRIVATE(_upb_IsLittleEndian)()) { ptr = upb_EpsCopyInputStream_Copy(&d->input, ptr, mem, val->size); } else { int delta = upb_EpsCopyInputStream_PushLimit(&d->input, ptr, val->size); @@ -13515,7 +13515,7 @@ const char* _upb_Decoder_CheckRequired(upb_Decoder* d, const char* ptr, } uint64_t msg_head; memcpy(&msg_head, msg, 8); - msg_head = _upb_BigEndian_Swap64(msg_head); + msg_head = UPB_PRIVATE(_upb_BigEndian64)(msg_head); if (UPB_PRIVATE(_upb_MiniTable_RequiredMask)(m) & ~msg_head) { d->missing_required = true; } @@ -14144,1621 +14144,1624 @@ upb_DecodeStatus upb_Decode(const char* buf, size_t size, upb_Message* msg, #undef OP_FIXPCK_LG2 #undef OP_VARPCK_LG2 -// Fast decoder: ~3x the speed of decode.c, but requires x86-64/ARM64. -// Also the table size grows by 2x. -// -// Could potentially be ported to other 64-bit archs that pass at least six -// arguments in registers and have 8 unused high bits in pointers. -// -// The overall design is to create specialized functions for every possible -// field type (eg. oneof boolean field with a 1 byte tag) and then dispatch -// to the specialized function as quickly as possible. +// We encode backwards, to avoid pre-computing lengths (one-pass encode). +#include +#include +#include +#include + // Must be last. -#if UPB_FASTTABLE +#define UPB_PB_VARINT_MAX_LEN 10 -// The standard set of arguments passed to each parsing function. -// Thanks to x86-64 calling conventions, these will stay in registers. -#define UPB_PARSE_PARAMS \ - upb_Decoder *d, const char *ptr, upb_Message *msg, intptr_t table, \ - uint64_t hasbits, uint64_t data +UPB_NOINLINE +static size_t encode_varint64(uint64_t val, char* buf) { + size_t i = 0; + do { + uint8_t byte = val & 0x7fU; + val >>= 7; + if (val) byte |= 0x80U; + buf[i++] = byte; + } while (val); + return i; +} -#define UPB_PARSE_ARGS d, ptr, msg, table, hasbits, data +static uint32_t encode_zz32(int32_t n) { + return ((uint32_t)n << 1) ^ (n >> 31); +} +static uint64_t encode_zz64(int64_t n) { + return ((uint64_t)n << 1) ^ (n >> 63); +} -#define RETURN_GENERIC(m) \ - /* Uncomment either of these for debugging purposes. */ \ - /* fprintf(stderr, m); */ \ - /*__builtin_trap(); */ \ - return _upb_FastDecoder_DecodeGeneric(d, ptr, msg, table, hasbits, 0); +typedef struct { + upb_EncodeStatus status; + jmp_buf err; + upb_Arena* arena; + char *buf, *ptr, *limit; + int options; + int depth; + _upb_mapsorter sorter; +} upb_encstate; -typedef enum { - CARD_s = 0, /* Singular (optional, non-repeated) */ - CARD_o = 1, /* Oneof */ - CARD_r = 2, /* Repeated */ - CARD_p = 3 /* Packed Repeated */ -} upb_card; +static size_t upb_roundup_pow2(size_t bytes) { + size_t ret = 128; + while (ret < bytes) { + ret *= 2; + } + return ret; +} -UPB_NOINLINE -static const char* fastdecode_isdonefallback(UPB_PARSE_PARAMS) { - int overrun = data; - ptr = _upb_EpsCopyInputStream_IsDoneFallbackInline( - &d->input, ptr, overrun, _upb_Decoder_BufferFlipCallback); - data = _upb_FastDecoder_LoadTag(ptr); - UPB_MUSTTAIL return _upb_FastDecoder_TagDispatch(UPB_PARSE_ARGS); +UPB_NORETURN static void encode_err(upb_encstate* e, upb_EncodeStatus s) { + UPB_ASSERT(s != kUpb_EncodeStatus_Ok); + e->status = s; + UPB_LONGJMP(e->err, 1); } -UPB_FORCEINLINE -static const char* fastdecode_dispatch(UPB_PARSE_PARAMS) { - int overrun; - switch (upb_EpsCopyInputStream_IsDoneStatus(&d->input, ptr, &overrun)) { - case kUpb_IsDoneStatus_Done: - *(uint32_t*)msg |= hasbits; // Sync hasbits. - const upb_MiniTable* m = decode_totablep(table); - return UPB_UNLIKELY(m->UPB_PRIVATE(required_count)) - ? _upb_Decoder_CheckRequired(d, ptr, msg, m) - : ptr; - case kUpb_IsDoneStatus_NotDone: - break; - case kUpb_IsDoneStatus_NeedFallback: - data = overrun; - UPB_MUSTTAIL return fastdecode_isdonefallback(UPB_PARSE_ARGS); - } +UPB_NOINLINE +static void encode_growbuffer(upb_encstate* e, size_t bytes) { + size_t old_size = e->limit - e->buf; + size_t new_size = upb_roundup_pow2(bytes + (e->limit - e->ptr)); + char* new_buf = upb_Arena_Realloc(e->arena, e->buf, old_size, new_size); - // Read two bytes of tag data (for a one-byte tag, the high byte is junk). - data = _upb_FastDecoder_LoadTag(ptr); - UPB_MUSTTAIL return _upb_FastDecoder_TagDispatch(UPB_PARSE_ARGS); -} + if (!new_buf) encode_err(e, kUpb_EncodeStatus_OutOfMemory); -UPB_FORCEINLINE -static bool fastdecode_checktag(uint16_t data, int tagbytes) { - if (tagbytes == 1) { - return (data & 0xff) == 0; - } else { - return data == 0; + // We want previous data at the end, realloc() put it at the beginning. + // TODO: This is somewhat inefficient since we are copying twice. + // Maybe create a realloc() that copies to the end of the new buffer? + if (old_size > 0) { + memmove(new_buf + new_size - old_size, e->buf, old_size); } -} -UPB_FORCEINLINE -static const char* fastdecode_longsize(const char* ptr, int* size) { - int i; - UPB_ASSERT(*size & 0x80); - *size &= 0xff; - for (i = 0; i < 3; i++) { - ptr++; - size_t byte = (uint8_t)ptr[-1]; - *size += (byte - 1) << (7 + 7 * i); - if (UPB_LIKELY((byte & 0x80) == 0)) return ptr; - } - ptr++; - size_t byte = (uint8_t)ptr[-1]; - // len is limited by 2gb not 4gb, hence 8 and not 16 as normally expected - // for a 32 bit varint. - if (UPB_UNLIKELY(byte >= 8)) return NULL; - *size += (byte - 1) << 28; - return ptr; + e->ptr = new_buf + new_size - (e->limit - e->ptr); + e->limit = new_buf + new_size; + e->buf = new_buf; + + e->ptr -= bytes; } +/* Call to ensure that at least "bytes" bytes are available for writing at + * e->ptr. Returns false if the bytes could not be allocated. */ UPB_FORCEINLINE -static const char* fastdecode_delimited( - upb_Decoder* d, const char* ptr, - upb_EpsCopyInputStream_ParseDelimitedFunc* func, void* ctx) { - ptr++; - - // Sign-extend so varint greater than one byte becomes negative, causing - // fast delimited parse to fail. - int len = (int8_t)ptr[-1]; - - if (!upb_EpsCopyInputStream_TryParseDelimitedFast(&d->input, &ptr, len, func, - ctx)) { - // Slow case: Sub-message is >=128 bytes and/or exceeds the current buffer. - // If it exceeds the buffer limit, limit/limit_ptr will change during - // sub-message parsing, so we need to preserve delta, not limit. - if (UPB_UNLIKELY(len & 0x80)) { - // Size varint >1 byte (length >= 128). - ptr = fastdecode_longsize(ptr, &len); - if (!ptr) { - // Corrupt wire format: size exceeded INT_MAX. - return NULL; - } - } - if (!upb_EpsCopyInputStream_CheckSize(&d->input, ptr, len)) { - // Corrupt wire format: invalid limit. - return NULL; - } - int delta = upb_EpsCopyInputStream_PushLimit(&d->input, ptr, len); - ptr = func(&d->input, ptr, ctx); - upb_EpsCopyInputStream_PopLimit(&d->input, ptr, delta); +static void encode_reserve(upb_encstate* e, size_t bytes) { + if ((size_t)(e->ptr - e->buf) < bytes) { + encode_growbuffer(e, bytes); + return; } - return ptr; + + e->ptr -= bytes; } -/* singular, oneof, repeated field handling ***********************************/ +/* Writes the given bytes to the buffer, handling reserve/advance. */ +static void encode_bytes(upb_encstate* e, const void* data, size_t len) { + if (len == 0) return; /* memcpy() with zero size is UB */ + encode_reserve(e, len); + memcpy(e->ptr, data, len); +} -typedef struct { - upb_Array* arr; - void* end; -} fastdecode_arr; +static void encode_fixed64(upb_encstate* e, uint64_t val) { + val = UPB_PRIVATE(_upb_BigEndian64)(val); + encode_bytes(e, &val, sizeof(uint64_t)); +} -typedef enum { - FD_NEXT_ATLIMIT, - FD_NEXT_SAMEFIELD, - FD_NEXT_OTHERFIELD -} fastdecode_next; +static void encode_fixed32(upb_encstate* e, uint32_t val) { + val = UPB_PRIVATE(_upb_BigEndian32)(val); + encode_bytes(e, &val, sizeof(uint32_t)); +} -typedef struct { - void* dst; - fastdecode_next next; - uint32_t tag; -} fastdecode_nextret; +UPB_NOINLINE +static void encode_longvarint(upb_encstate* e, uint64_t val) { + size_t len; + char* start; -UPB_FORCEINLINE -static void* fastdecode_resizearr(upb_Decoder* d, void* dst, - fastdecode_arr* farr, int valbytes) { - if (UPB_UNLIKELY(dst == farr->end)) { - size_t old_capacity = farr->arr->UPB_PRIVATE(capacity); - size_t old_bytes = old_capacity * valbytes; - size_t new_capacity = old_capacity * 2; - size_t new_bytes = new_capacity * valbytes; - char* old_ptr = _upb_array_ptr(farr->arr); - char* new_ptr = upb_Arena_Realloc(&d->arena, old_ptr, old_bytes, new_bytes); - uint8_t elem_size_lg2 = __builtin_ctz(valbytes); - UPB_PRIVATE(_upb_Array_SetTaggedPtr)(farr->arr, new_ptr, elem_size_lg2); - farr->arr->UPB_PRIVATE(capacity) = new_capacity; - dst = (void*)(new_ptr + (old_capacity * valbytes)); - farr->end = (void*)(new_ptr + (new_capacity * valbytes)); - } - return dst; + encode_reserve(e, UPB_PB_VARINT_MAX_LEN); + len = encode_varint64(val, e->ptr); + start = e->ptr + UPB_PB_VARINT_MAX_LEN - len; + memmove(start, e->ptr, len); + e->ptr = start; } UPB_FORCEINLINE -static bool fastdecode_tagmatch(uint32_t tag, uint64_t data, int tagbytes) { - if (tagbytes == 1) { - return (uint8_t)tag == (uint8_t)data; +static void encode_varint(upb_encstate* e, uint64_t val) { + if (val < 128 && e->ptr != e->buf) { + --e->ptr; + *e->ptr = val; } else { - return (uint16_t)tag == (uint16_t)data; + encode_longvarint(e, val); } } -UPB_FORCEINLINE -static void fastdecode_commitarr(void* dst, fastdecode_arr* farr, - int valbytes) { - farr->arr->UPB_PRIVATE(size) = - (size_t)((char*)dst - (char*)_upb_array_ptr(farr->arr)) / valbytes; +static void encode_double(upb_encstate* e, double d) { + uint64_t u64; + UPB_ASSERT(sizeof(double) == sizeof(uint64_t)); + memcpy(&u64, &d, sizeof(uint64_t)); + encode_fixed64(e, u64); } -UPB_FORCEINLINE -static fastdecode_nextret fastdecode_nextrepeated(upb_Decoder* d, void* dst, - const char** ptr, - fastdecode_arr* farr, - uint64_t data, int tagbytes, - int valbytes) { - fastdecode_nextret ret; - dst = (char*)dst + valbytes; +static void encode_float(upb_encstate* e, float d) { + uint32_t u32; + UPB_ASSERT(sizeof(float) == sizeof(uint32_t)); + memcpy(&u32, &d, sizeof(uint32_t)); + encode_fixed32(e, u32); +} - if (UPB_LIKELY(!_upb_Decoder_IsDone(d, ptr))) { - ret.tag = _upb_FastDecoder_LoadTag(*ptr); - if (fastdecode_tagmatch(ret.tag, data, tagbytes)) { - ret.next = FD_NEXT_SAMEFIELD; - } else { - fastdecode_commitarr(dst, farr, valbytes); - ret.next = FD_NEXT_OTHERFIELD; +static void encode_tag(upb_encstate* e, uint32_t field_number, + uint8_t wire_type) { + encode_varint(e, (field_number << 3) | wire_type); +} + +static void encode_fixedarray(upb_encstate* e, const upb_Array* arr, + size_t elem_size, uint32_t tag) { + size_t bytes = arr->UPB_PRIVATE(size) * elem_size; + const char* data = _upb_array_constptr(arr); + const char* ptr = data + bytes - elem_size; + + if (tag || !UPB_PRIVATE(_upb_IsLittleEndian)()) { + while (true) { + if (elem_size == 4) { + uint32_t val; + memcpy(&val, ptr, sizeof(val)); + val = UPB_PRIVATE(_upb_BigEndian32)(val); + encode_bytes(e, &val, elem_size); + } else { + UPB_ASSERT(elem_size == 8); + uint64_t val; + memcpy(&val, ptr, sizeof(val)); + val = UPB_PRIVATE(_upb_BigEndian64)(val); + encode_bytes(e, &val, elem_size); + } + + if (tag) encode_varint(e, tag); + if (ptr == data) break; + ptr -= elem_size; } } else { - fastdecode_commitarr(dst, farr, valbytes); - ret.next = FD_NEXT_ATLIMIT; + encode_bytes(e, data, bytes); } - - ret.dst = dst; - return ret; } -UPB_FORCEINLINE -static void* fastdecode_fieldmem(upb_Message* msg, uint64_t data) { - size_t ofs = data >> 48; - return (char*)msg + ofs; +static void encode_message(upb_encstate* e, const upb_Message* msg, + const upb_MiniTable* m, size_t* size); + +static void encode_TaggedMessagePtr(upb_encstate* e, + upb_TaggedMessagePtr tagged, + const upb_MiniTable* m, size_t* size) { + if (upb_TaggedMessagePtr_IsEmpty(tagged)) { + m = UPB_PRIVATE(_upb_MiniTable_Empty)(); + } + encode_message(e, _upb_TaggedMessagePtr_GetMessage(tagged), m, size); } -UPB_FORCEINLINE -static void* fastdecode_getfield(upb_Decoder* d, const char* ptr, - upb_Message* msg, uint64_t* data, - uint64_t* hasbits, fastdecode_arr* farr, - int valbytes, upb_card card) { - switch (card) { - case CARD_s: { - uint8_t hasbit_index = *data >> 24; - // Set hasbit and return pointer to scalar field. - *hasbits |= 1ull << hasbit_index; - return fastdecode_fieldmem(msg, *data); +static void encode_scalar(upb_encstate* e, const void* _field_mem, + const upb_MiniTableSub* subs, + const upb_MiniTableField* f) { + const char* field_mem = _field_mem; + int wire_type; + +#define CASE(ctype, type, wtype, encodeval) \ + { \ + ctype val = *(ctype*)field_mem; \ + encode_##type(e, encodeval); \ + wire_type = wtype; \ + break; \ + } + + switch (f->UPB_PRIVATE(descriptortype)) { + case kUpb_FieldType_Double: + CASE(double, double, kUpb_WireType_64Bit, val); + case kUpb_FieldType_Float: + CASE(float, float, kUpb_WireType_32Bit, val); + case kUpb_FieldType_Int64: + case kUpb_FieldType_UInt64: + CASE(uint64_t, varint, kUpb_WireType_Varint, val); + case kUpb_FieldType_UInt32: + CASE(uint32_t, varint, kUpb_WireType_Varint, val); + case kUpb_FieldType_Int32: + case kUpb_FieldType_Enum: + CASE(int32_t, varint, kUpb_WireType_Varint, (int64_t)val); + case kUpb_FieldType_SFixed64: + case kUpb_FieldType_Fixed64: + CASE(uint64_t, fixed64, kUpb_WireType_64Bit, val); + case kUpb_FieldType_Fixed32: + case kUpb_FieldType_SFixed32: + CASE(uint32_t, fixed32, kUpb_WireType_32Bit, val); + case kUpb_FieldType_Bool: + CASE(bool, varint, kUpb_WireType_Varint, val); + case kUpb_FieldType_SInt32: + CASE(int32_t, varint, kUpb_WireType_Varint, encode_zz32(val)); + case kUpb_FieldType_SInt64: + CASE(int64_t, varint, kUpb_WireType_Varint, encode_zz64(val)); + case kUpb_FieldType_String: + case kUpb_FieldType_Bytes: { + upb_StringView view = *(upb_StringView*)field_mem; + encode_bytes(e, view.data, view.size); + encode_varint(e, view.size); + wire_type = kUpb_WireType_Delimited; + break; } - case CARD_o: { - uint16_t case_ofs = *data >> 32; - uint32_t* oneof_case = UPB_PTR_AT(msg, case_ofs, uint32_t); - uint8_t field_number = *data >> 24; - *oneof_case = field_number; - return fastdecode_fieldmem(msg, *data); + case kUpb_FieldType_Group: { + size_t size; + upb_TaggedMessagePtr submsg = *(upb_TaggedMessagePtr*)field_mem; + const upb_MiniTable* subm = + upb_MiniTableSub_Message(subs[f->UPB_PRIVATE(submsg_index)]); + if (submsg == 0) { + return; + } + if (--e->depth == 0) encode_err(e, kUpb_EncodeStatus_MaxDepthExceeded); + encode_tag(e, f->UPB_PRIVATE(number), kUpb_WireType_EndGroup); + encode_TaggedMessagePtr(e, submsg, subm, &size); + wire_type = kUpb_WireType_StartGroup; + e->depth++; + break; } - case CARD_r: { - // Get pointer to upb_Array and allocate/expand if necessary. - uint8_t elem_size_lg2 = __builtin_ctz(valbytes); - upb_Array** arr_p = fastdecode_fieldmem(msg, *data); - char* begin; - *(uint32_t*)msg |= *hasbits; - *hasbits = 0; - if (UPB_LIKELY(!*arr_p)) { - farr->arr = UPB_PRIVATE(_upb_Array_New)(&d->arena, 8, elem_size_lg2); - *arr_p = farr->arr; - } else { - farr->arr = *arr_p; + case kUpb_FieldType_Message: { + size_t size; + upb_TaggedMessagePtr submsg = *(upb_TaggedMessagePtr*)field_mem; + const upb_MiniTable* subm = + upb_MiniTableSub_Message(subs[f->UPB_PRIVATE(submsg_index)]); + if (submsg == 0) { + return; } - begin = _upb_array_ptr(farr->arr); - farr->end = begin + (farr->arr->UPB_PRIVATE(capacity) * valbytes); - *data = _upb_FastDecoder_LoadTag(ptr); - return begin + (farr->arr->UPB_PRIVATE(size) * valbytes); + if (--e->depth == 0) encode_err(e, kUpb_EncodeStatus_MaxDepthExceeded); + encode_TaggedMessagePtr(e, submsg, subm, &size); + encode_varint(e, size); + wire_type = kUpb_WireType_Delimited; + e->depth++; + break; } default: UPB_UNREACHABLE(); } -} +#undef CASE -UPB_FORCEINLINE -static bool fastdecode_flippacked(uint64_t* data, int tagbytes) { - *data ^= (0x2 ^ 0x0); // Patch data to match packed wiretype. - return fastdecode_checktag(*data, tagbytes); + encode_tag(e, f->UPB_PRIVATE(number), wire_type); } -#define FASTDECODE_CHECKPACKED(tagbytes, card, func) \ - if (UPB_UNLIKELY(!fastdecode_checktag(data, tagbytes))) { \ - if (card == CARD_r && fastdecode_flippacked(&data, tagbytes)) { \ - UPB_MUSTTAIL return func(UPB_PARSE_ARGS); \ - } \ - RETURN_GENERIC("packed check tag mismatch\n"); \ - } - -/* varint fields **************************************************************/ +static void encode_array(upb_encstate* e, const upb_Message* msg, + const upb_MiniTableSub* subs, + const upb_MiniTableField* f) { + const upb_Array* arr = *UPB_PTR_AT(msg, f->UPB_PRIVATE(offset), upb_Array*); + bool packed = upb_MiniTableField_IsPacked(f); + size_t pre_len = e->limit - e->ptr; -UPB_FORCEINLINE -static uint64_t fastdecode_munge(uint64_t val, int valbytes, bool zigzag) { - if (valbytes == 1) { - return val != 0; - } else if (zigzag) { - if (valbytes == 4) { - uint32_t n = val; - return (n >> 1) ^ -(int32_t)(n & 1); - } else if (valbytes == 8) { - return (val >> 1) ^ -(int64_t)(val & 1); - } - UPB_UNREACHABLE(); + if (arr == NULL || arr->UPB_PRIVATE(size) == 0) { + return; } - return val; -} -UPB_FORCEINLINE -static const char* fastdecode_varint64(const char* ptr, uint64_t* val) { - ptr++; - *val = (uint8_t)ptr[-1]; - if (UPB_UNLIKELY(*val & 0x80)) { - int i; - for (i = 0; i < 8; i++) { - ptr++; - uint64_t byte = (uint8_t)ptr[-1]; - *val += (byte - 1) << (7 + 7 * i); - if (UPB_LIKELY((byte & 0x80) == 0)) goto done; - } - ptr++; - uint64_t byte = (uint8_t)ptr[-1]; - if (byte > 1) { - return NULL; - } - *val += (byte - 1) << 63; - } -done: - UPB_ASSUME(ptr != NULL); - return ptr; -} +#define VARINT_CASE(ctype, encode) \ + { \ + const ctype* start = _upb_array_constptr(arr); \ + const ctype* ptr = start + arr->UPB_PRIVATE(size); \ + uint32_t tag = \ + packed ? 0 : (f->UPB_PRIVATE(number) << 3) | kUpb_WireType_Varint; \ + do { \ + ptr--; \ + encode_varint(e, encode); \ + if (tag) encode_varint(e, tag); \ + } while (ptr != start); \ + } \ + break; -#define FASTDECODE_UNPACKEDVARINT(d, ptr, msg, table, hasbits, data, tagbytes, \ - valbytes, card, zigzag, packed) \ - uint64_t val; \ - void* dst; \ - fastdecode_arr farr; \ - \ - FASTDECODE_CHECKPACKED(tagbytes, card, packed); \ - \ - dst = fastdecode_getfield(d, ptr, msg, &data, &hasbits, &farr, valbytes, \ - card); \ - if (card == CARD_r) { \ - if (UPB_UNLIKELY(!dst)) { \ - RETURN_GENERIC("need array resize\n"); \ - } \ - } \ - \ - again: \ - if (card == CARD_r) { \ - dst = fastdecode_resizearr(d, dst, &farr, valbytes); \ - } \ - \ - ptr += tagbytes; \ - ptr = fastdecode_varint64(ptr, &val); \ - if (ptr == NULL) _upb_FastDecoder_ErrorJmp(d, kUpb_DecodeStatus_Malformed); \ - val = fastdecode_munge(val, valbytes, zigzag); \ - memcpy(dst, &val, valbytes); \ - \ - if (card == CARD_r) { \ - fastdecode_nextret ret = fastdecode_nextrepeated( \ - d, dst, &ptr, &farr, data, tagbytes, valbytes); \ - switch (ret.next) { \ - case FD_NEXT_SAMEFIELD: \ - dst = ret.dst; \ - goto again; \ - case FD_NEXT_OTHERFIELD: \ - data = ret.tag; \ - UPB_MUSTTAIL return _upb_FastDecoder_TagDispatch(UPB_PARSE_ARGS); \ - case FD_NEXT_ATLIMIT: \ - return ptr; \ - } \ - } \ - \ - UPB_MUSTTAIL return fastdecode_dispatch(UPB_PARSE_ARGS); - -typedef struct { - uint8_t valbytes; - bool zigzag; - void* dst; - fastdecode_arr farr; -} fastdecode_varintdata; - -UPB_FORCEINLINE -static const char* fastdecode_topackedvarint(upb_EpsCopyInputStream* e, - const char* ptr, void* ctx) { - upb_Decoder* d = (upb_Decoder*)e; - fastdecode_varintdata* data = ctx; - void* dst = data->dst; - uint64_t val; +#define TAG(wire_type) (packed ? 0 : (f->UPB_PRIVATE(number) << 3 | wire_type)) - while (!_upb_Decoder_IsDone(d, &ptr)) { - dst = fastdecode_resizearr(d, dst, &data->farr, data->valbytes); - ptr = fastdecode_varint64(ptr, &val); - if (ptr == NULL) return NULL; - val = fastdecode_munge(val, data->valbytes, data->zigzag); - memcpy(dst, &val, data->valbytes); - dst = (char*)dst + data->valbytes; + switch (f->UPB_PRIVATE(descriptortype)) { + case kUpb_FieldType_Double: + encode_fixedarray(e, arr, sizeof(double), TAG(kUpb_WireType_64Bit)); + break; + case kUpb_FieldType_Float: + encode_fixedarray(e, arr, sizeof(float), TAG(kUpb_WireType_32Bit)); + break; + case kUpb_FieldType_SFixed64: + case kUpb_FieldType_Fixed64: + encode_fixedarray(e, arr, sizeof(uint64_t), TAG(kUpb_WireType_64Bit)); + break; + case kUpb_FieldType_Fixed32: + case kUpb_FieldType_SFixed32: + encode_fixedarray(e, arr, sizeof(uint32_t), TAG(kUpb_WireType_32Bit)); + break; + case kUpb_FieldType_Int64: + case kUpb_FieldType_UInt64: + VARINT_CASE(uint64_t, *ptr); + case kUpb_FieldType_UInt32: + VARINT_CASE(uint32_t, *ptr); + case kUpb_FieldType_Int32: + case kUpb_FieldType_Enum: + VARINT_CASE(int32_t, (int64_t)*ptr); + case kUpb_FieldType_Bool: + VARINT_CASE(bool, *ptr); + case kUpb_FieldType_SInt32: + VARINT_CASE(int32_t, encode_zz32(*ptr)); + case kUpb_FieldType_SInt64: + VARINT_CASE(int64_t, encode_zz64(*ptr)); + case kUpb_FieldType_String: + case kUpb_FieldType_Bytes: { + const upb_StringView* start = _upb_array_constptr(arr); + const upb_StringView* ptr = start + arr->UPB_PRIVATE(size); + do { + ptr--; + encode_bytes(e, ptr->data, ptr->size); + encode_varint(e, ptr->size); + encode_tag(e, f->UPB_PRIVATE(number), kUpb_WireType_Delimited); + } while (ptr != start); + return; + } + case kUpb_FieldType_Group: { + const upb_TaggedMessagePtr* start = _upb_array_constptr(arr); + const upb_TaggedMessagePtr* ptr = start + arr->UPB_PRIVATE(size); + const upb_MiniTable* subm = + upb_MiniTableSub_Message(subs[f->UPB_PRIVATE(submsg_index)]); + if (--e->depth == 0) encode_err(e, kUpb_EncodeStatus_MaxDepthExceeded); + do { + size_t size; + ptr--; + encode_tag(e, f->UPB_PRIVATE(number), kUpb_WireType_EndGroup); + encode_TaggedMessagePtr(e, *ptr, subm, &size); + encode_tag(e, f->UPB_PRIVATE(number), kUpb_WireType_StartGroup); + } while (ptr != start); + e->depth++; + return; + } + case kUpb_FieldType_Message: { + const upb_TaggedMessagePtr* start = _upb_array_constptr(arr); + const upb_TaggedMessagePtr* ptr = start + arr->UPB_PRIVATE(size); + const upb_MiniTable* subm = + upb_MiniTableSub_Message(subs[f->UPB_PRIVATE(submsg_index)]); + if (--e->depth == 0) encode_err(e, kUpb_EncodeStatus_MaxDepthExceeded); + do { + size_t size; + ptr--; + encode_TaggedMessagePtr(e, *ptr, subm, &size); + encode_varint(e, size); + encode_tag(e, f->UPB_PRIVATE(number), kUpb_WireType_Delimited); + } while (ptr != start); + e->depth++; + return; + } } +#undef VARINT_CASE - fastdecode_commitarr(dst, &data->farr, data->valbytes); - return ptr; + if (packed) { + encode_varint(e, e->limit - e->ptr - pre_len); + encode_tag(e, f->UPB_PRIVATE(number), kUpb_WireType_Delimited); + } } -#define FASTDECODE_PACKEDVARINT(d, ptr, msg, table, hasbits, data, tagbytes, \ - valbytes, zigzag, unpacked) \ - fastdecode_varintdata ctx = {valbytes, zigzag}; \ - \ - FASTDECODE_CHECKPACKED(tagbytes, CARD_r, unpacked); \ - \ - ctx.dst = fastdecode_getfield(d, ptr, msg, &data, &hasbits, &ctx.farr, \ - valbytes, CARD_r); \ - if (UPB_UNLIKELY(!ctx.dst)) { \ - RETURN_GENERIC("need array resize\n"); \ - } \ - \ - ptr += tagbytes; \ - ptr = fastdecode_delimited(d, ptr, &fastdecode_topackedvarint, &ctx); \ - \ - if (UPB_UNLIKELY(ptr == NULL)) { \ - _upb_FastDecoder_ErrorJmp(d, kUpb_DecodeStatus_Malformed); \ - } \ - \ - UPB_MUSTTAIL return fastdecode_dispatch(d, ptr, msg, table, hasbits, 0); +static void encode_mapentry(upb_encstate* e, uint32_t number, + const upb_MiniTable* layout, + const upb_MapEntry* ent) { + const upb_MiniTableField* key_field = &layout->UPB_PRIVATE(fields)[0]; + const upb_MiniTableField* val_field = &layout->UPB_PRIVATE(fields)[1]; + size_t pre_len = e->limit - e->ptr; + size_t size; + encode_scalar(e, &ent->data.v, layout->UPB_PRIVATE(subs), val_field); + encode_scalar(e, &ent->data.k, layout->UPB_PRIVATE(subs), key_field); + size = (e->limit - e->ptr) - pre_len; + encode_varint(e, size); + encode_tag(e, number, kUpb_WireType_Delimited); +} -#define FASTDECODE_VARINT(d, ptr, msg, table, hasbits, data, tagbytes, \ - valbytes, card, zigzag, unpacked, packed) \ - if (card == CARD_p) { \ - FASTDECODE_PACKEDVARINT(d, ptr, msg, table, hasbits, data, tagbytes, \ - valbytes, zigzag, unpacked); \ - } else { \ - FASTDECODE_UNPACKEDVARINT(d, ptr, msg, table, hasbits, data, tagbytes, \ - valbytes, card, zigzag, packed); \ - } +static void encode_map(upb_encstate* e, const upb_Message* msg, + const upb_MiniTableSub* subs, + const upb_MiniTableField* f) { + const upb_Map* map = *UPB_PTR_AT(msg, f->UPB_PRIVATE(offset), const upb_Map*); + const upb_MiniTable* layout = + upb_MiniTableSub_Message(subs[f->UPB_PRIVATE(submsg_index)]); + UPB_ASSERT(layout->UPB_PRIVATE(field_count) == 2); -#define z_ZZ true -#define b_ZZ false -#define v_ZZ false + if (map == NULL) return; -/* Generate all combinations: - * {s,o,r,p} x {b1,v4,z4,v8,z8} x {1bt,2bt} */ + if (e->options & kUpb_EncodeOption_Deterministic) { + _upb_sortedmap sorted; + _upb_mapsorter_pushmap( + &e->sorter, layout->UPB_PRIVATE(fields)[0].UPB_PRIVATE(descriptortype), + map, &sorted); + upb_MapEntry ent; + while (_upb_sortedmap_next(&e->sorter, map, &sorted, &ent)) { + encode_mapentry(e, f->UPB_PRIVATE(number), layout, &ent); + } + _upb_mapsorter_popmap(&e->sorter, &sorted); + } else { + intptr_t iter = UPB_STRTABLE_BEGIN; + upb_StringView key; + upb_value val; + while (upb_strtable_next2(&map->table, &key, &val, &iter)) { + upb_MapEntry ent; + _upb_map_fromkey(key, &ent.data.k, map->key_size); + _upb_map_fromvalue(val, &ent.data.v, map->val_size); + encode_mapentry(e, f->UPB_PRIVATE(number), layout, &ent); + } + } +} -#define F(card, type, valbytes, tagbytes) \ - UPB_NOINLINE \ - const char* upb_p##card##type##valbytes##_##tagbytes##bt(UPB_PARSE_PARAMS) { \ - FASTDECODE_VARINT(d, ptr, msg, table, hasbits, data, tagbytes, valbytes, \ - CARD_##card, type##_ZZ, \ - upb_pr##type##valbytes##_##tagbytes##bt, \ - upb_pp##type##valbytes##_##tagbytes##bt); \ +static bool encode_shouldencode(upb_encstate* e, const upb_Message* msg, + const upb_MiniTableSub* subs, + const upb_MiniTableField* f) { + if (f->presence == 0) { + // Proto3 presence or map/array. + const void* mem = UPB_PTR_AT(msg, f->UPB_PRIVATE(offset), void); + switch (UPB_PRIVATE(_upb_MiniTableField_GetRep)(f)) { + case kUpb_FieldRep_1Byte: { + char ch; + memcpy(&ch, mem, 1); + return ch != 0; + } + case kUpb_FieldRep_4Byte: { + uint32_t u32; + memcpy(&u32, mem, 4); + return u32 != 0; + } + case kUpb_FieldRep_8Byte: { + uint64_t u64; + memcpy(&u64, mem, 8); + return u64 != 0; + } + case kUpb_FieldRep_StringView: { + const upb_StringView* str = (const upb_StringView*)mem; + return str->size != 0; + } + default: + UPB_UNREACHABLE(); + } + } else if (f->presence > 0) { + // Proto2 presence: hasbit. + return UPB_PRIVATE(_upb_Message_GetHasbit)(msg, f); + } else { + // Field is in a oneof. + return UPB_PRIVATE(_upb_Message_GetOneofCase)(msg, f) == + f->UPB_PRIVATE(number); } +} -#define TYPES(card, tagbytes) \ - F(card, b, 1, tagbytes) \ - F(card, v, 4, tagbytes) \ - F(card, v, 8, tagbytes) \ - F(card, z, 4, tagbytes) \ - F(card, z, 8, tagbytes) - -#define TAGBYTES(card) \ - TYPES(card, 1) \ - TYPES(card, 2) +static void encode_field(upb_encstate* e, const upb_Message* msg, + const upb_MiniTableSub* subs, + const upb_MiniTableField* field) { + switch (UPB_PRIVATE(_upb_MiniTableField_Mode)(field)) { + case kUpb_FieldMode_Array: + encode_array(e, msg, subs, field); + break; + case kUpb_FieldMode_Map: + encode_map(e, msg, subs, field); + break; + case kUpb_FieldMode_Scalar: + encode_scalar(e, UPB_PTR_AT(msg, field->UPB_PRIVATE(offset), void), subs, + field); + break; + default: + UPB_UNREACHABLE(); + } +} -TAGBYTES(s) -TAGBYTES(o) -TAGBYTES(r) -TAGBYTES(p) +static void encode_msgset_item(upb_encstate* e, const upb_Extension* ext) { + size_t size; + encode_tag(e, kUpb_MsgSet_Item, kUpb_WireType_EndGroup); + encode_message(e, ext->data.ptr, + upb_MiniTableExtension_GetSubMessage(ext->ext), &size); + encode_varint(e, size); + encode_tag(e, kUpb_MsgSet_Message, kUpb_WireType_Delimited); + encode_varint(e, upb_MiniTableExtension_Number(ext->ext)); + encode_tag(e, kUpb_MsgSet_TypeId, kUpb_WireType_Varint); + encode_tag(e, kUpb_MsgSet_Item, kUpb_WireType_StartGroup); +} -#undef z_ZZ -#undef b_ZZ -#undef v_ZZ -#undef o_ONEOF -#undef s_ONEOF -#undef r_ONEOF -#undef F -#undef TYPES -#undef TAGBYTES -#undef FASTDECODE_UNPACKEDVARINT -#undef FASTDECODE_PACKEDVARINT -#undef FASTDECODE_VARINT +static void encode_ext(upb_encstate* e, const upb_Extension* ext, + bool is_message_set) { + if (UPB_UNLIKELY(is_message_set)) { + encode_msgset_item(e, ext); + } else { + encode_field(e, (upb_Message*)&ext->data, &ext->ext->UPB_PRIVATE(sub), + &ext->ext->UPB_PRIVATE(field)); + } +} -/* fixed fields ***************************************************************/ +static void encode_message(upb_encstate* e, const upb_Message* msg, + const upb_MiniTable* m, size_t* size) { + size_t pre_len = e->limit - e->ptr; -#define FASTDECODE_UNPACKEDFIXED(d, ptr, msg, table, hasbits, data, tagbytes, \ - valbytes, card, packed) \ - void* dst; \ - fastdecode_arr farr; \ - \ - FASTDECODE_CHECKPACKED(tagbytes, card, packed) \ - \ - dst = fastdecode_getfield(d, ptr, msg, &data, &hasbits, &farr, valbytes, \ - card); \ - if (card == CARD_r) { \ - if (UPB_UNLIKELY(!dst)) { \ - RETURN_GENERIC("couldn't allocate array in arena\n"); \ - } \ - } \ - \ - again: \ - if (card == CARD_r) { \ - dst = fastdecode_resizearr(d, dst, &farr, valbytes); \ - } \ - \ - ptr += tagbytes; \ - memcpy(dst, ptr, valbytes); \ - ptr += valbytes; \ - \ - if (card == CARD_r) { \ - fastdecode_nextret ret = fastdecode_nextrepeated( \ - d, dst, &ptr, &farr, data, tagbytes, valbytes); \ - switch (ret.next) { \ - case FD_NEXT_SAMEFIELD: \ - dst = ret.dst; \ - goto again; \ - case FD_NEXT_OTHERFIELD: \ - data = ret.tag; \ - UPB_MUSTTAIL return _upb_FastDecoder_TagDispatch(UPB_PARSE_ARGS); \ - case FD_NEXT_ATLIMIT: \ - return ptr; \ - } \ - } \ - \ - UPB_MUSTTAIL return fastdecode_dispatch(UPB_PARSE_ARGS); + if ((e->options & kUpb_EncodeOption_CheckRequired) && + m->UPB_PRIVATE(required_count)) { + uint64_t msg_head; + memcpy(&msg_head, msg, 8); + msg_head = UPB_PRIVATE(_upb_BigEndian64)(msg_head); + if (UPB_PRIVATE(_upb_MiniTable_RequiredMask)(m) & ~msg_head) { + encode_err(e, kUpb_EncodeStatus_MissingRequired); + } + } -#define FASTDECODE_PACKEDFIXED(d, ptr, msg, table, hasbits, data, tagbytes, \ - valbytes, unpacked) \ - FASTDECODE_CHECKPACKED(tagbytes, CARD_r, unpacked) \ - \ - ptr += tagbytes; \ - int size = (uint8_t)ptr[0]; \ - ptr++; \ - if (size & 0x80) { \ - ptr = fastdecode_longsize(ptr, &size); \ - } \ - \ - if (UPB_UNLIKELY(!upb_EpsCopyInputStream_CheckDataSizeAvailable( \ - &d->input, ptr, size) || \ - (size % valbytes) != 0)) { \ - _upb_FastDecoder_ErrorJmp(d, kUpb_DecodeStatus_Malformed); \ - } \ - \ - upb_Array** arr_p = fastdecode_fieldmem(msg, data); \ - upb_Array* arr = *arr_p; \ - uint8_t elem_size_lg2 = __builtin_ctz(valbytes); \ - int elems = size / valbytes; \ - \ - if (UPB_LIKELY(!arr)) { \ - *arr_p = arr = \ - UPB_PRIVATE(_upb_Array_New)(&d->arena, elems, elem_size_lg2); \ - if (!arr) { \ - _upb_FastDecoder_ErrorJmp(d, kUpb_DecodeStatus_Malformed); \ - } \ - } else { \ - _upb_Array_ResizeUninitialized(arr, elems, &d->arena); \ - } \ - \ - char* dst = _upb_array_ptr(arr); \ - memcpy(dst, ptr, size); \ - arr->UPB_PRIVATE(size) = elems; \ - \ - ptr += size; \ - UPB_MUSTTAIL return fastdecode_dispatch(UPB_PARSE_ARGS); + if ((e->options & kUpb_EncodeOption_SkipUnknown) == 0) { + size_t unknown_size; + const char* unknown = upb_Message_GetUnknown(msg, &unknown_size); -#define FASTDECODE_FIXED(d, ptr, msg, table, hasbits, data, tagbytes, \ - valbytes, card, unpacked, packed) \ - if (card == CARD_p) { \ - FASTDECODE_PACKEDFIXED(d, ptr, msg, table, hasbits, data, tagbytes, \ - valbytes, unpacked); \ - } else { \ - FASTDECODE_UNPACKEDFIXED(d, ptr, msg, table, hasbits, data, tagbytes, \ - valbytes, card, packed); \ + if (unknown) { + encode_bytes(e, unknown, unknown_size); + } } -/* Generate all combinations: - * {s,o,r,p} x {f4,f8} x {1bt,2bt} */ - -#define F(card, valbytes, tagbytes) \ - UPB_NOINLINE \ - const char* upb_p##card##f##valbytes##_##tagbytes##bt(UPB_PARSE_PARAMS) { \ - FASTDECODE_FIXED(d, ptr, msg, table, hasbits, data, tagbytes, valbytes, \ - CARD_##card, upb_ppf##valbytes##_##tagbytes##bt, \ - upb_prf##valbytes##_##tagbytes##bt); \ + if (m->UPB_PRIVATE(ext) != kUpb_ExtMode_NonExtendable) { + /* Encode all extensions together. Unlike C++, we do not attempt to keep + * these in field number order relative to normal fields or even to each + * other. */ + size_t ext_count; + const upb_Extension* ext = + UPB_PRIVATE(_upb_Message_Getexts)(msg, &ext_count); + if (ext_count) { + if (e->options & kUpb_EncodeOption_Deterministic) { + _upb_sortedmap sorted; + _upb_mapsorter_pushexts(&e->sorter, ext, ext_count, &sorted); + while (_upb_sortedmap_nextext(&e->sorter, &sorted, &ext)) { + encode_ext(e, ext, m->UPB_PRIVATE(ext) == kUpb_ExtMode_IsMessageSet); + } + _upb_mapsorter_popmap(&e->sorter, &sorted); + } else { + const upb_Extension* end = ext + ext_count; + for (; ext != end; ext++) { + encode_ext(e, ext, m->UPB_PRIVATE(ext) == kUpb_ExtMode_IsMessageSet); + } + } + } } -#define TYPES(card, tagbytes) \ - F(card, 4, tagbytes) \ - F(card, 8, tagbytes) + if (m->UPB_PRIVATE(field_count)) { + const upb_MiniTableField* f = + &m->UPB_PRIVATE(fields)[m->UPB_PRIVATE(field_count)]; + const upb_MiniTableField* first = &m->UPB_PRIVATE(fields)[0]; + while (f != first) { + f--; + if (encode_shouldencode(e, msg, m->UPB_PRIVATE(subs), f)) { + encode_field(e, msg, m->UPB_PRIVATE(subs), f); + } + } + } -#define TAGBYTES(card) \ - TYPES(card, 1) \ - TYPES(card, 2) + *size = (e->limit - e->ptr) - pre_len; +} -TAGBYTES(s) -TAGBYTES(o) -TAGBYTES(r) -TAGBYTES(p) +static upb_EncodeStatus upb_Encoder_Encode(upb_encstate* const encoder, + const upb_Message* const msg, + const upb_MiniTable* const l, + char** const buf, + size_t* const size) { + // Unfortunately we must continue to perform hackery here because there are + // code paths which blindly copy the returned pointer without bothering to + // check for errors until much later (b/235839510). So we still set *buf to + // NULL on error and we still set it to non-NULL on a successful empty result. + if (UPB_SETJMP(encoder->err) == 0) { + encode_message(encoder, msg, l, size); + *size = encoder->limit - encoder->ptr; + if (*size == 0) { + static char ch; + *buf = &ch; + } else { + UPB_ASSERT(encoder->ptr); + *buf = encoder->ptr; + } + } else { + UPB_ASSERT(encoder->status != kUpb_EncodeStatus_Ok); + *buf = NULL; + *size = 0; + } -#undef F -#undef TYPES -#undef TAGBYTES -#undef FASTDECODE_UNPACKEDFIXED -#undef FASTDECODE_PACKEDFIXED + _upb_mapsorter_destroy(&encoder->sorter); + return encoder->status; +} -/* string fields **************************************************************/ +upb_EncodeStatus upb_Encode(const upb_Message* msg, const upb_MiniTable* l, + int options, upb_Arena* arena, char** buf, + size_t* size) { + upb_encstate e; + unsigned depth = (unsigned)options >> 16; -typedef const char* fastdecode_copystr_func(struct upb_Decoder* d, - const char* ptr, upb_Message* msg, - const upb_MiniTable* table, - uint64_t hasbits, - upb_StringView* dst); + e.status = kUpb_EncodeStatus_Ok; + e.arena = arena; + e.buf = NULL; + e.limit = NULL; + e.ptr = NULL; + e.depth = depth ? depth : kUpb_WireFormat_DefaultDepthLimit; + e.options = options; + _upb_mapsorter_init(&e.sorter); -UPB_NOINLINE -static const char* fastdecode_verifyutf8(upb_Decoder* d, const char* ptr, - upb_Message* msg, intptr_t table, - uint64_t hasbits, uint64_t data) { - upb_StringView* dst = (upb_StringView*)data; - if (!_upb_Decoder_VerifyUtf8Inline(dst->data, dst->size)) { - _upb_FastDecoder_ErrorJmp(d, kUpb_DecodeStatus_BadUtf8); - } - UPB_MUSTTAIL return fastdecode_dispatch(UPB_PARSE_ARGS); + return upb_Encoder_Encode(&e, msg, l, buf, size); } -#define FASTDECODE_LONGSTRING(d, ptr, msg, table, hasbits, dst, validate_utf8) \ - int size = (uint8_t)ptr[0]; /* Could plumb through hasbits. */ \ - ptr++; \ - if (size & 0x80) { \ - ptr = fastdecode_longsize(ptr, &size); \ - } \ - \ - if (UPB_UNLIKELY(!upb_EpsCopyInputStream_CheckSize(&d->input, ptr, size))) { \ - dst->size = 0; \ - _upb_FastDecoder_ErrorJmp(d, kUpb_DecodeStatus_Malformed); \ - } \ - \ - const char* s_ptr = ptr; \ - ptr = upb_EpsCopyInputStream_ReadString(&d->input, &s_ptr, size, &d->arena); \ - if (!ptr) _upb_FastDecoder_ErrorJmp(d, kUpb_DecodeStatus_OutOfMemory); \ - dst->data = s_ptr; \ - dst->size = size; \ - \ - if (validate_utf8) { \ - data = (uint64_t)dst; \ - UPB_MUSTTAIL return fastdecode_verifyutf8(UPB_PARSE_ARGS); \ - } else { \ - UPB_MUSTTAIL return fastdecode_dispatch(UPB_PARSE_ARGS); \ - } +// Fast decoder: ~3x the speed of decode.c, but requires x86-64/ARM64. +// Also the table size grows by 2x. +// +// Could potentially be ported to other 64-bit archs that pass at least six +// arguments in registers and have 8 unused high bits in pointers. +// +// The overall design is to create specialized functions for every possible +// field type (eg. oneof boolean field with a 1 byte tag) and then dispatch +// to the specialized function as quickly as possible. + + + +// Must be last. + +#if UPB_FASTTABLE + +// The standard set of arguments passed to each parsing function. +// Thanks to x86-64 calling conventions, these will stay in registers. +#define UPB_PARSE_PARAMS \ + upb_Decoder *d, const char *ptr, upb_Message *msg, intptr_t table, \ + uint64_t hasbits, uint64_t data + +#define UPB_PARSE_ARGS d, ptr, msg, table, hasbits, data + +#define RETURN_GENERIC(m) \ + /* Uncomment either of these for debugging purposes. */ \ + /* fprintf(stderr, m); */ \ + /*__builtin_trap(); */ \ + return _upb_FastDecoder_DecodeGeneric(d, ptr, msg, table, hasbits, 0); + +typedef enum { + CARD_s = 0, /* Singular (optional, non-repeated) */ + CARD_o = 1, /* Oneof */ + CARD_r = 2, /* Repeated */ + CARD_p = 3 /* Packed Repeated */ +} upb_card; UPB_NOINLINE -static const char* fastdecode_longstring_utf8(struct upb_Decoder* d, - const char* ptr, upb_Message* msg, - intptr_t table, uint64_t hasbits, - uint64_t data) { - upb_StringView* dst = (upb_StringView*)data; - FASTDECODE_LONGSTRING(d, ptr, msg, table, hasbits, dst, true); +static const char* fastdecode_isdonefallback(UPB_PARSE_PARAMS) { + int overrun = data; + ptr = _upb_EpsCopyInputStream_IsDoneFallbackInline( + &d->input, ptr, overrun, _upb_Decoder_BufferFlipCallback); + data = _upb_FastDecoder_LoadTag(ptr); + UPB_MUSTTAIL return _upb_FastDecoder_TagDispatch(UPB_PARSE_ARGS); } -UPB_NOINLINE -static const char* fastdecode_longstring_noutf8( - struct upb_Decoder* d, const char* ptr, upb_Message* msg, intptr_t table, - uint64_t hasbits, uint64_t data) { - upb_StringView* dst = (upb_StringView*)data; - FASTDECODE_LONGSTRING(d, ptr, msg, table, hasbits, dst, false); +UPB_FORCEINLINE +static const char* fastdecode_dispatch(UPB_PARSE_PARAMS) { + int overrun; + switch (upb_EpsCopyInputStream_IsDoneStatus(&d->input, ptr, &overrun)) { + case kUpb_IsDoneStatus_Done: + *(uint32_t*)msg |= hasbits; // Sync hasbits. + const upb_MiniTable* m = decode_totablep(table); + return UPB_UNLIKELY(m->UPB_PRIVATE(required_count)) + ? _upb_Decoder_CheckRequired(d, ptr, msg, m) + : ptr; + case kUpb_IsDoneStatus_NotDone: + break; + case kUpb_IsDoneStatus_NeedFallback: + data = overrun; + UPB_MUSTTAIL return fastdecode_isdonefallback(UPB_PARSE_ARGS); + } + + // Read two bytes of tag data (for a one-byte tag, the high byte is junk). + data = _upb_FastDecoder_LoadTag(ptr); + UPB_MUSTTAIL return _upb_FastDecoder_TagDispatch(UPB_PARSE_ARGS); } UPB_FORCEINLINE -static void fastdecode_docopy(upb_Decoder* d, const char* ptr, uint32_t size, - int copy, char* data, size_t data_offset, - upb_StringView* dst) { - d->arena.UPB_PRIVATE(ptr) += copy; - dst->data = data + data_offset; - UPB_UNPOISON_MEMORY_REGION(data, copy); - memcpy(data, ptr, copy); - UPB_POISON_MEMORY_REGION(data + data_offset + size, - copy - data_offset - size); +static bool fastdecode_checktag(uint16_t data, int tagbytes) { + if (tagbytes == 1) { + return (data & 0xff) == 0; + } else { + return data == 0; + } } -#define FASTDECODE_COPYSTRING(d, ptr, msg, table, hasbits, data, tagbytes, \ - card, validate_utf8) \ - upb_StringView* dst; \ - fastdecode_arr farr; \ - int64_t size; \ - size_t arena_has; \ - size_t common_has; \ - char* buf; \ - \ - UPB_ASSERT(!upb_EpsCopyInputStream_AliasingAvailable(&d->input, ptr, 0)); \ - UPB_ASSERT(fastdecode_checktag(data, tagbytes)); \ - \ - dst = fastdecode_getfield(d, ptr, msg, &data, &hasbits, &farr, \ - sizeof(upb_StringView), card); \ - \ - again: \ - if (card == CARD_r) { \ - dst = fastdecode_resizearr(d, dst, &farr, sizeof(upb_StringView)); \ - } \ - \ - size = (uint8_t)ptr[tagbytes]; \ - ptr += tagbytes + 1; \ - dst->size = size; \ - \ - buf = d->arena.UPB_PRIVATE(ptr); \ - arena_has = UPB_PRIVATE(_upb_ArenaHas)(&d->arena); \ - common_has = UPB_MIN(arena_has, \ - upb_EpsCopyInputStream_BytesAvailable(&d->input, ptr)); \ - \ - if (UPB_LIKELY(size <= 15 - tagbytes)) { \ - if (arena_has < 16) goto longstr; \ - fastdecode_docopy(d, ptr - tagbytes - 1, size, 16, buf, tagbytes + 1, \ - dst); \ - } else if (UPB_LIKELY(size <= 32)) { \ - if (UPB_UNLIKELY(common_has < 32)) goto longstr; \ - fastdecode_docopy(d, ptr, size, 32, buf, 0, dst); \ - } else if (UPB_LIKELY(size <= 64)) { \ - if (UPB_UNLIKELY(common_has < 64)) goto longstr; \ - fastdecode_docopy(d, ptr, size, 64, buf, 0, dst); \ - } else if (UPB_LIKELY(size < 128)) { \ - if (UPB_UNLIKELY(common_has < 128)) goto longstr; \ - fastdecode_docopy(d, ptr, size, 128, buf, 0, dst); \ - } else { \ - goto longstr; \ - } \ - \ - ptr += size; \ - \ - if (card == CARD_r) { \ - if (validate_utf8 && \ - !_upb_Decoder_VerifyUtf8Inline(dst->data, dst->size)) { \ - _upb_FastDecoder_ErrorJmp(d, kUpb_DecodeStatus_BadUtf8); \ - } \ - fastdecode_nextret ret = fastdecode_nextrepeated( \ - d, dst, &ptr, &farr, data, tagbytes, sizeof(upb_StringView)); \ - switch (ret.next) { \ - case FD_NEXT_SAMEFIELD: \ - dst = ret.dst; \ - goto again; \ - case FD_NEXT_OTHERFIELD: \ - data = ret.tag; \ - UPB_MUSTTAIL return _upb_FastDecoder_TagDispatch(UPB_PARSE_ARGS); \ - case FD_NEXT_ATLIMIT: \ - return ptr; \ - } \ - } \ - \ - if (card != CARD_r && validate_utf8) { \ - data = (uint64_t)dst; \ - UPB_MUSTTAIL return fastdecode_verifyutf8(UPB_PARSE_ARGS); \ - } \ - \ - UPB_MUSTTAIL return fastdecode_dispatch(UPB_PARSE_ARGS); \ - \ - longstr: \ - if (card == CARD_r) { \ - fastdecode_commitarr(dst + 1, &farr, sizeof(upb_StringView)); \ - } \ - ptr--; \ - if (validate_utf8) { \ - UPB_MUSTTAIL return fastdecode_longstring_utf8(d, ptr, msg, table, \ - hasbits, (uint64_t)dst); \ - } else { \ - UPB_MUSTTAIL return fastdecode_longstring_noutf8(d, ptr, msg, table, \ - hasbits, (uint64_t)dst); \ +UPB_FORCEINLINE +static const char* fastdecode_longsize(const char* ptr, int* size) { + int i; + UPB_ASSERT(*size & 0x80); + *size &= 0xff; + for (i = 0; i < 3; i++) { + ptr++; + size_t byte = (uint8_t)ptr[-1]; + *size += (byte - 1) << (7 + 7 * i); + if (UPB_LIKELY((byte & 0x80) == 0)) return ptr; } + ptr++; + size_t byte = (uint8_t)ptr[-1]; + // len is limited by 2gb not 4gb, hence 8 and not 16 as normally expected + // for a 32 bit varint. + if (UPB_UNLIKELY(byte >= 8)) return NULL; + *size += (byte - 1) << 28; + return ptr; +} -#define FASTDECODE_STRING(d, ptr, msg, table, hasbits, data, tagbytes, card, \ - copyfunc, validate_utf8) \ - upb_StringView* dst; \ - fastdecode_arr farr; \ - int64_t size; \ - \ - if (UPB_UNLIKELY(!fastdecode_checktag(data, tagbytes))) { \ - RETURN_GENERIC("string field tag mismatch\n"); \ - } \ - \ - if (UPB_UNLIKELY( \ - !upb_EpsCopyInputStream_AliasingAvailable(&d->input, ptr, 0))) { \ - UPB_MUSTTAIL return copyfunc(UPB_PARSE_ARGS); \ - } \ - \ - dst = fastdecode_getfield(d, ptr, msg, &data, &hasbits, &farr, \ - sizeof(upb_StringView), card); \ - \ - again: \ - if (card == CARD_r) { \ - dst = fastdecode_resizearr(d, dst, &farr, sizeof(upb_StringView)); \ - } \ - \ - size = (int8_t)ptr[tagbytes]; \ - ptr += tagbytes + 1; \ - \ - if (UPB_UNLIKELY( \ - !upb_EpsCopyInputStream_AliasingAvailable(&d->input, ptr, size))) { \ - ptr--; \ - if (validate_utf8) { \ - return fastdecode_longstring_utf8(d, ptr, msg, table, hasbits, \ - (uint64_t)dst); \ - } else { \ - return fastdecode_longstring_noutf8(d, ptr, msg, table, hasbits, \ - (uint64_t)dst); \ - } \ - } \ - \ - dst->data = ptr; \ - dst->size = size; \ - ptr = upb_EpsCopyInputStream_ReadStringAliased(&d->input, &dst->data, \ - dst->size); \ - \ - if (card == CARD_r) { \ - if (validate_utf8 && \ - !_upb_Decoder_VerifyUtf8Inline(dst->data, dst->size)) { \ - _upb_FastDecoder_ErrorJmp(d, kUpb_DecodeStatus_BadUtf8); \ - } \ - fastdecode_nextret ret = fastdecode_nextrepeated( \ - d, dst, &ptr, &farr, data, tagbytes, sizeof(upb_StringView)); \ - switch (ret.next) { \ - case FD_NEXT_SAMEFIELD: \ - dst = ret.dst; \ - goto again; \ - case FD_NEXT_OTHERFIELD: \ - data = ret.tag; \ - UPB_MUSTTAIL return _upb_FastDecoder_TagDispatch(UPB_PARSE_ARGS); \ - case FD_NEXT_ATLIMIT: \ - return ptr; \ - } \ - } \ - \ - if (card != CARD_r && validate_utf8) { \ - data = (uint64_t)dst; \ - UPB_MUSTTAIL return fastdecode_verifyutf8(UPB_PARSE_ARGS); \ - } \ - \ - UPB_MUSTTAIL return fastdecode_dispatch(UPB_PARSE_ARGS); - -/* Generate all combinations: - * {p,c} x {s,o,r} x {s, b} x {1bt,2bt} */ +UPB_FORCEINLINE +static const char* fastdecode_delimited( + upb_Decoder* d, const char* ptr, + upb_EpsCopyInputStream_ParseDelimitedFunc* func, void* ctx) { + ptr++; -#define s_VALIDATE true -#define b_VALIDATE false + // Sign-extend so varint greater than one byte becomes negative, causing + // fast delimited parse to fail. + int len = (int8_t)ptr[-1]; -#define F(card, tagbytes, type) \ - UPB_NOINLINE \ - const char* upb_c##card##type##_##tagbytes##bt(UPB_PARSE_PARAMS) { \ - FASTDECODE_COPYSTRING(d, ptr, msg, table, hasbits, data, tagbytes, \ - CARD_##card, type##_VALIDATE); \ - } \ - const char* upb_p##card##type##_##tagbytes##bt(UPB_PARSE_PARAMS) { \ - FASTDECODE_STRING(d, ptr, msg, table, hasbits, data, tagbytes, \ - CARD_##card, upb_c##card##type##_##tagbytes##bt, \ - type##_VALIDATE); \ + if (!upb_EpsCopyInputStream_TryParseDelimitedFast(&d->input, &ptr, len, func, + ctx)) { + // Slow case: Sub-message is >=128 bytes and/or exceeds the current buffer. + // If it exceeds the buffer limit, limit/limit_ptr will change during + // sub-message parsing, so we need to preserve delta, not limit. + if (UPB_UNLIKELY(len & 0x80)) { + // Size varint >1 byte (length >= 128). + ptr = fastdecode_longsize(ptr, &len); + if (!ptr) { + // Corrupt wire format: size exceeded INT_MAX. + return NULL; + } + } + if (!upb_EpsCopyInputStream_CheckSize(&d->input, ptr, len)) { + // Corrupt wire format: invalid limit. + return NULL; + } + int delta = upb_EpsCopyInputStream_PushLimit(&d->input, ptr, len); + ptr = func(&d->input, ptr, ctx); + upb_EpsCopyInputStream_PopLimit(&d->input, ptr, delta); } + return ptr; +} -#define UTF8(card, tagbytes) \ - F(card, tagbytes, s) \ - F(card, tagbytes, b) +/* singular, oneof, repeated field handling ***********************************/ -#define TAGBYTES(card) \ - UTF8(card, 1) \ - UTF8(card, 2) +typedef struct { + upb_Array* arr; + void* end; +} fastdecode_arr; -TAGBYTES(s) -TAGBYTES(o) -TAGBYTES(r) +typedef enum { + FD_NEXT_ATLIMIT, + FD_NEXT_SAMEFIELD, + FD_NEXT_OTHERFIELD +} fastdecode_next; -#undef s_VALIDATE -#undef b_VALIDATE -#undef F -#undef TAGBYTES -#undef FASTDECODE_LONGSTRING -#undef FASTDECODE_COPYSTRING -#undef FASTDECODE_STRING +typedef struct { + void* dst; + fastdecode_next next; + uint32_t tag; +} fastdecode_nextret; -/* message fields *************************************************************/ +UPB_FORCEINLINE +static void* fastdecode_resizearr(upb_Decoder* d, void* dst, + fastdecode_arr* farr, int valbytes) { + if (UPB_UNLIKELY(dst == farr->end)) { + size_t old_capacity = farr->arr->UPB_PRIVATE(capacity); + size_t old_bytes = old_capacity * valbytes; + size_t new_capacity = old_capacity * 2; + size_t new_bytes = new_capacity * valbytes; + char* old_ptr = _upb_array_ptr(farr->arr); + char* new_ptr = upb_Arena_Realloc(&d->arena, old_ptr, old_bytes, new_bytes); + uint8_t elem_size_lg2 = __builtin_ctz(valbytes); + UPB_PRIVATE(_upb_Array_SetTaggedPtr)(farr->arr, new_ptr, elem_size_lg2); + farr->arr->UPB_PRIVATE(capacity) = new_capacity; + dst = (void*)(new_ptr + (old_capacity * valbytes)); + farr->end = (void*)(new_ptr + (new_capacity * valbytes)); + } + return dst; +} -UPB_INLINE -upb_Message* decode_newmsg_ceil(upb_Decoder* d, const upb_MiniTable* m, - int msg_ceil_bytes) { - size_t size = m->UPB_PRIVATE(size) + sizeof(upb_Message_Internal); - char* msg_data; - if (UPB_LIKELY(msg_ceil_bytes > 0 && - UPB_PRIVATE(_upb_ArenaHas)(&d->arena) >= msg_ceil_bytes)) { - UPB_ASSERT(size <= (size_t)msg_ceil_bytes); - msg_data = d->arena.UPB_PRIVATE(ptr); - d->arena.UPB_PRIVATE(ptr) += size; - UPB_UNPOISON_MEMORY_REGION(msg_data, msg_ceil_bytes); - memset(msg_data, 0, msg_ceil_bytes); - UPB_POISON_MEMORY_REGION(msg_data + size, msg_ceil_bytes - size); +UPB_FORCEINLINE +static bool fastdecode_tagmatch(uint32_t tag, uint64_t data, int tagbytes) { + if (tagbytes == 1) { + return (uint8_t)tag == (uint8_t)data; } else { - msg_data = (char*)upb_Arena_Malloc(&d->arena, size); - memset(msg_data, 0, size); + return (uint16_t)tag == (uint16_t)data; } - return msg_data + sizeof(upb_Message_Internal); } -typedef struct { - intptr_t table; - upb_Message* msg; -} fastdecode_submsgdata; +UPB_FORCEINLINE +static void fastdecode_commitarr(void* dst, fastdecode_arr* farr, + int valbytes) { + farr->arr->UPB_PRIVATE(size) = + (size_t)((char*)dst - (char*)_upb_array_ptr(farr->arr)) / valbytes; +} UPB_FORCEINLINE -static const char* fastdecode_tosubmsg(upb_EpsCopyInputStream* e, - const char* ptr, void* ctx) { - upb_Decoder* d = (upb_Decoder*)e; - fastdecode_submsgdata* submsg = ctx; - ptr = fastdecode_dispatch(d, ptr, submsg->msg, submsg->table, 0, 0); - UPB_ASSUME(ptr != NULL); - return ptr; +static fastdecode_nextret fastdecode_nextrepeated(upb_Decoder* d, void* dst, + const char** ptr, + fastdecode_arr* farr, + uint64_t data, int tagbytes, + int valbytes) { + fastdecode_nextret ret; + dst = (char*)dst + valbytes; + + if (UPB_LIKELY(!_upb_Decoder_IsDone(d, ptr))) { + ret.tag = _upb_FastDecoder_LoadTag(*ptr); + if (fastdecode_tagmatch(ret.tag, data, tagbytes)) { + ret.next = FD_NEXT_SAMEFIELD; + } else { + fastdecode_commitarr(dst, farr, valbytes); + ret.next = FD_NEXT_OTHERFIELD; + } + } else { + fastdecode_commitarr(dst, farr, valbytes); + ret.next = FD_NEXT_ATLIMIT; + } + + ret.dst = dst; + return ret; } -#define FASTDECODE_SUBMSG(d, ptr, msg, table, hasbits, data, tagbytes, \ - msg_ceil_bytes, card) \ - \ - if (UPB_UNLIKELY(!fastdecode_checktag(data, tagbytes))) { \ - RETURN_GENERIC("submessage field tag mismatch\n"); \ - } \ - \ - if (--d->depth == 0) { \ - _upb_FastDecoder_ErrorJmp(d, kUpb_DecodeStatus_MaxDepthExceeded); \ - } \ - \ - upb_Message** dst; \ - uint32_t submsg_idx = (data >> 16) & 0xff; \ - const upb_MiniTable* tablep = decode_totablep(table); \ - const upb_MiniTable* subtablep = upb_MiniTableSub_Message( \ - *UPB_PRIVATE(_upb_MiniTable_GetSubByIndex)(tablep, submsg_idx)); \ - fastdecode_submsgdata submsg = {decode_totable(subtablep)}; \ - fastdecode_arr farr; \ - \ - if (subtablep->UPB_PRIVATE(table_mask) == (uint8_t)-1) { \ - d->depth++; \ - RETURN_GENERIC("submessage doesn't have fast tables."); \ - } \ - \ - dst = fastdecode_getfield(d, ptr, msg, &data, &hasbits, &farr, \ - sizeof(upb_Message*), card); \ - \ - if (card == CARD_s) { \ - *(uint32_t*)msg |= hasbits; \ - hasbits = 0; \ - } \ - \ - again: \ - if (card == CARD_r) { \ - dst = fastdecode_resizearr(d, dst, &farr, sizeof(upb_Message*)); \ - } \ - \ - submsg.msg = *dst; \ - \ - if (card == CARD_r || UPB_LIKELY(!submsg.msg)) { \ - *dst = submsg.msg = decode_newmsg_ceil(d, subtablep, msg_ceil_bytes); \ - } \ - \ - ptr += tagbytes; \ - ptr = fastdecode_delimited(d, ptr, fastdecode_tosubmsg, &submsg); \ - \ - if (UPB_UNLIKELY(ptr == NULL || d->end_group != DECODE_NOGROUP)) { \ - _upb_FastDecoder_ErrorJmp(d, kUpb_DecodeStatus_Malformed); \ - } \ - \ - if (card == CARD_r) { \ - fastdecode_nextret ret = fastdecode_nextrepeated( \ - d, dst, &ptr, &farr, data, tagbytes, sizeof(upb_Message*)); \ - switch (ret.next) { \ - case FD_NEXT_SAMEFIELD: \ - dst = ret.dst; \ - goto again; \ - case FD_NEXT_OTHERFIELD: \ - d->depth++; \ - data = ret.tag; \ - UPB_MUSTTAIL return _upb_FastDecoder_TagDispatch(UPB_PARSE_ARGS); \ - case FD_NEXT_ATLIMIT: \ - d->depth++; \ - return ptr; \ - } \ - } \ - \ - d->depth++; \ - UPB_MUSTTAIL return fastdecode_dispatch(UPB_PARSE_ARGS); - -#define F(card, tagbytes, size_ceil, ceil_arg) \ - const char* upb_p##card##m_##tagbytes##bt_max##size_ceil##b( \ - UPB_PARSE_PARAMS) { \ - FASTDECODE_SUBMSG(d, ptr, msg, table, hasbits, data, tagbytes, ceil_arg, \ - CARD_##card); \ - } - -#define SIZES(card, tagbytes) \ - F(card, tagbytes, 64, 64) \ - F(card, tagbytes, 128, 128) \ - F(card, tagbytes, 192, 192) \ - F(card, tagbytes, 256, 256) \ - F(card, tagbytes, max, -1) - -#define TAGBYTES(card) \ - SIZES(card, 1) \ - SIZES(card, 2) - -TAGBYTES(s) -TAGBYTES(o) -TAGBYTES(r) - -#undef TAGBYTES -#undef SIZES -#undef F -#undef FASTDECODE_SUBMSG - -#endif /* UPB_FASTTABLE */ - -// We encode backwards, to avoid pre-computing lengths (one-pass encode). - - -#include -#include -#include -#include - - -// Must be last. - -#define UPB_PB_VARINT_MAX_LEN 10 - -UPB_NOINLINE -static size_t encode_varint64(uint64_t val, char* buf) { - size_t i = 0; - do { - uint8_t byte = val & 0x7fU; - val >>= 7; - if (val) byte |= 0x80U; - buf[i++] = byte; - } while (val); - return i; -} - -static uint32_t encode_zz32(int32_t n) { - return ((uint32_t)n << 1) ^ (n >> 31); -} -static uint64_t encode_zz64(int64_t n) { - return ((uint64_t)n << 1) ^ (n >> 63); +UPB_FORCEINLINE +static void* fastdecode_fieldmem(upb_Message* msg, uint64_t data) { + size_t ofs = data >> 48; + return (char*)msg + ofs; } -typedef struct { - upb_EncodeStatus status; - jmp_buf err; - upb_Arena* arena; - char *buf, *ptr, *limit; - int options; - int depth; - _upb_mapsorter sorter; -} upb_encstate; - -static size_t upb_roundup_pow2(size_t bytes) { - size_t ret = 128; - while (ret < bytes) { - ret *= 2; +UPB_FORCEINLINE +static void* fastdecode_getfield(upb_Decoder* d, const char* ptr, + upb_Message* msg, uint64_t* data, + uint64_t* hasbits, fastdecode_arr* farr, + int valbytes, upb_card card) { + switch (card) { + case CARD_s: { + uint8_t hasbit_index = *data >> 24; + // Set hasbit and return pointer to scalar field. + *hasbits |= 1ull << hasbit_index; + return fastdecode_fieldmem(msg, *data); + } + case CARD_o: { + uint16_t case_ofs = *data >> 32; + uint32_t* oneof_case = UPB_PTR_AT(msg, case_ofs, uint32_t); + uint8_t field_number = *data >> 24; + *oneof_case = field_number; + return fastdecode_fieldmem(msg, *data); + } + case CARD_r: { + // Get pointer to upb_Array and allocate/expand if necessary. + uint8_t elem_size_lg2 = __builtin_ctz(valbytes); + upb_Array** arr_p = fastdecode_fieldmem(msg, *data); + char* begin; + *(uint32_t*)msg |= *hasbits; + *hasbits = 0; + if (UPB_LIKELY(!*arr_p)) { + farr->arr = UPB_PRIVATE(_upb_Array_New)(&d->arena, 8, elem_size_lg2); + *arr_p = farr->arr; + } else { + farr->arr = *arr_p; + } + begin = _upb_array_ptr(farr->arr); + farr->end = begin + (farr->arr->UPB_PRIVATE(capacity) * valbytes); + *data = _upb_FastDecoder_LoadTag(ptr); + return begin + (farr->arr->UPB_PRIVATE(size) * valbytes); + } + default: + UPB_UNREACHABLE(); } - return ret; } -UPB_NORETURN static void encode_err(upb_encstate* e, upb_EncodeStatus s) { - UPB_ASSERT(s != kUpb_EncodeStatus_Ok); - e->status = s; - UPB_LONGJMP(e->err, 1); +UPB_FORCEINLINE +static bool fastdecode_flippacked(uint64_t* data, int tagbytes) { + *data ^= (0x2 ^ 0x0); // Patch data to match packed wiretype. + return fastdecode_checktag(*data, tagbytes); } -UPB_NOINLINE -static void encode_growbuffer(upb_encstate* e, size_t bytes) { - size_t old_size = e->limit - e->buf; - size_t new_size = upb_roundup_pow2(bytes + (e->limit - e->ptr)); - char* new_buf = upb_Arena_Realloc(e->arena, e->buf, old_size, new_size); - - if (!new_buf) encode_err(e, kUpb_EncodeStatus_OutOfMemory); - - // We want previous data at the end, realloc() put it at the beginning. - // TODO: This is somewhat inefficient since we are copying twice. - // Maybe create a realloc() that copies to the end of the new buffer? - if (old_size > 0) { - memmove(new_buf + new_size - old_size, e->buf, old_size); +#define FASTDECODE_CHECKPACKED(tagbytes, card, func) \ + if (UPB_UNLIKELY(!fastdecode_checktag(data, tagbytes))) { \ + if (card == CARD_r && fastdecode_flippacked(&data, tagbytes)) { \ + UPB_MUSTTAIL return func(UPB_PARSE_ARGS); \ + } \ + RETURN_GENERIC("packed check tag mismatch\n"); \ } - e->ptr = new_buf + new_size - (e->limit - e->ptr); - e->limit = new_buf + new_size; - e->buf = new_buf; - - e->ptr -= bytes; -} +/* varint fields **************************************************************/ -/* Call to ensure that at least "bytes" bytes are available for writing at - * e->ptr. Returns false if the bytes could not be allocated. */ UPB_FORCEINLINE -static void encode_reserve(upb_encstate* e, size_t bytes) { - if ((size_t)(e->ptr - e->buf) < bytes) { - encode_growbuffer(e, bytes); - return; +static uint64_t fastdecode_munge(uint64_t val, int valbytes, bool zigzag) { + if (valbytes == 1) { + return val != 0; + } else if (zigzag) { + if (valbytes == 4) { + uint32_t n = val; + return (n >> 1) ^ -(int32_t)(n & 1); + } else if (valbytes == 8) { + return (val >> 1) ^ -(int64_t)(val & 1); + } + UPB_UNREACHABLE(); } - - e->ptr -= bytes; -} - -/* Writes the given bytes to the buffer, handling reserve/advance. */ -static void encode_bytes(upb_encstate* e, const void* data, size_t len) { - if (len == 0) return; /* memcpy() with zero size is UB */ - encode_reserve(e, len); - memcpy(e->ptr, data, len); -} - -static void encode_fixed64(upb_encstate* e, uint64_t val) { - val = _upb_BigEndian_Swap64(val); - encode_bytes(e, &val, sizeof(uint64_t)); -} - -static void encode_fixed32(upb_encstate* e, uint32_t val) { - val = _upb_BigEndian_Swap32(val); - encode_bytes(e, &val, sizeof(uint32_t)); -} - -UPB_NOINLINE -static void encode_longvarint(upb_encstate* e, uint64_t val) { - size_t len; - char* start; - - encode_reserve(e, UPB_PB_VARINT_MAX_LEN); - len = encode_varint64(val, e->ptr); - start = e->ptr + UPB_PB_VARINT_MAX_LEN - len; - memmove(start, e->ptr, len); - e->ptr = start; + return val; } UPB_FORCEINLINE -static void encode_varint(upb_encstate* e, uint64_t val) { - if (val < 128 && e->ptr != e->buf) { - --e->ptr; - *e->ptr = val; - } else { - encode_longvarint(e, val); +static const char* fastdecode_varint64(const char* ptr, uint64_t* val) { + ptr++; + *val = (uint8_t)ptr[-1]; + if (UPB_UNLIKELY(*val & 0x80)) { + int i; + for (i = 0; i < 8; i++) { + ptr++; + uint64_t byte = (uint8_t)ptr[-1]; + *val += (byte - 1) << (7 + 7 * i); + if (UPB_LIKELY((byte & 0x80) == 0)) goto done; + } + ptr++; + uint64_t byte = (uint8_t)ptr[-1]; + if (byte > 1) { + return NULL; + } + *val += (byte - 1) << 63; } +done: + UPB_ASSUME(ptr != NULL); + return ptr; } -static void encode_double(upb_encstate* e, double d) { - uint64_t u64; - UPB_ASSERT(sizeof(double) == sizeof(uint64_t)); - memcpy(&u64, &d, sizeof(uint64_t)); - encode_fixed64(e, u64); -} - -static void encode_float(upb_encstate* e, float d) { - uint32_t u32; - UPB_ASSERT(sizeof(float) == sizeof(uint32_t)); - memcpy(&u32, &d, sizeof(uint32_t)); - encode_fixed32(e, u32); -} - -static void encode_tag(upb_encstate* e, uint32_t field_number, - uint8_t wire_type) { - encode_varint(e, (field_number << 3) | wire_type); -} +#define FASTDECODE_UNPACKEDVARINT(d, ptr, msg, table, hasbits, data, tagbytes, \ + valbytes, card, zigzag, packed) \ + uint64_t val; \ + void* dst; \ + fastdecode_arr farr; \ + \ + FASTDECODE_CHECKPACKED(tagbytes, card, packed); \ + \ + dst = fastdecode_getfield(d, ptr, msg, &data, &hasbits, &farr, valbytes, \ + card); \ + if (card == CARD_r) { \ + if (UPB_UNLIKELY(!dst)) { \ + RETURN_GENERIC("need array resize\n"); \ + } \ + } \ + \ + again: \ + if (card == CARD_r) { \ + dst = fastdecode_resizearr(d, dst, &farr, valbytes); \ + } \ + \ + ptr += tagbytes; \ + ptr = fastdecode_varint64(ptr, &val); \ + if (ptr == NULL) _upb_FastDecoder_ErrorJmp(d, kUpb_DecodeStatus_Malformed); \ + val = fastdecode_munge(val, valbytes, zigzag); \ + memcpy(dst, &val, valbytes); \ + \ + if (card == CARD_r) { \ + fastdecode_nextret ret = fastdecode_nextrepeated( \ + d, dst, &ptr, &farr, data, tagbytes, valbytes); \ + switch (ret.next) { \ + case FD_NEXT_SAMEFIELD: \ + dst = ret.dst; \ + goto again; \ + case FD_NEXT_OTHERFIELD: \ + data = ret.tag; \ + UPB_MUSTTAIL return _upb_FastDecoder_TagDispatch(UPB_PARSE_ARGS); \ + case FD_NEXT_ATLIMIT: \ + return ptr; \ + } \ + } \ + \ + UPB_MUSTTAIL return fastdecode_dispatch(UPB_PARSE_ARGS); -static void encode_fixedarray(upb_encstate* e, const upb_Array* arr, - size_t elem_size, uint32_t tag) { - size_t bytes = arr->UPB_PRIVATE(size) * elem_size; - const char* data = _upb_array_constptr(arr); - const char* ptr = data + bytes - elem_size; +typedef struct { + uint8_t valbytes; + bool zigzag; + void* dst; + fastdecode_arr farr; +} fastdecode_varintdata; - if (tag || !_upb_IsLittleEndian()) { - while (true) { - if (elem_size == 4) { - uint32_t val; - memcpy(&val, ptr, sizeof(val)); - val = _upb_BigEndian_Swap32(val); - encode_bytes(e, &val, elem_size); - } else { - UPB_ASSERT(elem_size == 8); - uint64_t val; - memcpy(&val, ptr, sizeof(val)); - val = _upb_BigEndian_Swap64(val); - encode_bytes(e, &val, elem_size); - } +UPB_FORCEINLINE +static const char* fastdecode_topackedvarint(upb_EpsCopyInputStream* e, + const char* ptr, void* ctx) { + upb_Decoder* d = (upb_Decoder*)e; + fastdecode_varintdata* data = ctx; + void* dst = data->dst; + uint64_t val; - if (tag) encode_varint(e, tag); - if (ptr == data) break; - ptr -= elem_size; - } - } else { - encode_bytes(e, data, bytes); + while (!_upb_Decoder_IsDone(d, &ptr)) { + dst = fastdecode_resizearr(d, dst, &data->farr, data->valbytes); + ptr = fastdecode_varint64(ptr, &val); + if (ptr == NULL) return NULL; + val = fastdecode_munge(val, data->valbytes, data->zigzag); + memcpy(dst, &val, data->valbytes); + dst = (char*)dst + data->valbytes; } -} -static void encode_message(upb_encstate* e, const upb_Message* msg, - const upb_MiniTable* m, size_t* size); - -static void encode_TaggedMessagePtr(upb_encstate* e, - upb_TaggedMessagePtr tagged, - const upb_MiniTable* m, size_t* size) { - if (upb_TaggedMessagePtr_IsEmpty(tagged)) { - m = UPB_PRIVATE(_upb_MiniTable_Empty)(); - } - encode_message(e, _upb_TaggedMessagePtr_GetMessage(tagged), m, size); + fastdecode_commitarr(dst, &data->farr, data->valbytes); + return ptr; } -static void encode_scalar(upb_encstate* e, const void* _field_mem, - const upb_MiniTableSub* subs, - const upb_MiniTableField* f) { - const char* field_mem = _field_mem; - int wire_type; - -#define CASE(ctype, type, wtype, encodeval) \ - { \ - ctype val = *(ctype*)field_mem; \ - encode_##type(e, encodeval); \ - wire_type = wtype; \ - break; \ - } +#define FASTDECODE_PACKEDVARINT(d, ptr, msg, table, hasbits, data, tagbytes, \ + valbytes, zigzag, unpacked) \ + fastdecode_varintdata ctx = {valbytes, zigzag}; \ + \ + FASTDECODE_CHECKPACKED(tagbytes, CARD_r, unpacked); \ + \ + ctx.dst = fastdecode_getfield(d, ptr, msg, &data, &hasbits, &ctx.farr, \ + valbytes, CARD_r); \ + if (UPB_UNLIKELY(!ctx.dst)) { \ + RETURN_GENERIC("need array resize\n"); \ + } \ + \ + ptr += tagbytes; \ + ptr = fastdecode_delimited(d, ptr, &fastdecode_topackedvarint, &ctx); \ + \ + if (UPB_UNLIKELY(ptr == NULL)) { \ + _upb_FastDecoder_ErrorJmp(d, kUpb_DecodeStatus_Malformed); \ + } \ + \ + UPB_MUSTTAIL return fastdecode_dispatch(d, ptr, msg, table, hasbits, 0); - switch (f->UPB_PRIVATE(descriptortype)) { - case kUpb_FieldType_Double: - CASE(double, double, kUpb_WireType_64Bit, val); - case kUpb_FieldType_Float: - CASE(float, float, kUpb_WireType_32Bit, val); - case kUpb_FieldType_Int64: - case kUpb_FieldType_UInt64: - CASE(uint64_t, varint, kUpb_WireType_Varint, val); - case kUpb_FieldType_UInt32: - CASE(uint32_t, varint, kUpb_WireType_Varint, val); - case kUpb_FieldType_Int32: - case kUpb_FieldType_Enum: - CASE(int32_t, varint, kUpb_WireType_Varint, (int64_t)val); - case kUpb_FieldType_SFixed64: - case kUpb_FieldType_Fixed64: - CASE(uint64_t, fixed64, kUpb_WireType_64Bit, val); - case kUpb_FieldType_Fixed32: - case kUpb_FieldType_SFixed32: - CASE(uint32_t, fixed32, kUpb_WireType_32Bit, val); - case kUpb_FieldType_Bool: - CASE(bool, varint, kUpb_WireType_Varint, val); - case kUpb_FieldType_SInt32: - CASE(int32_t, varint, kUpb_WireType_Varint, encode_zz32(val)); - case kUpb_FieldType_SInt64: - CASE(int64_t, varint, kUpb_WireType_Varint, encode_zz64(val)); - case kUpb_FieldType_String: - case kUpb_FieldType_Bytes: { - upb_StringView view = *(upb_StringView*)field_mem; - encode_bytes(e, view.data, view.size); - encode_varint(e, view.size); - wire_type = kUpb_WireType_Delimited; - break; - } - case kUpb_FieldType_Group: { - size_t size; - upb_TaggedMessagePtr submsg = *(upb_TaggedMessagePtr*)field_mem; - const upb_MiniTable* subm = - upb_MiniTableSub_Message(subs[f->UPB_PRIVATE(submsg_index)]); - if (submsg == 0) { - return; - } - if (--e->depth == 0) encode_err(e, kUpb_EncodeStatus_MaxDepthExceeded); - encode_tag(e, f->UPB_PRIVATE(number), kUpb_WireType_EndGroup); - encode_TaggedMessagePtr(e, submsg, subm, &size); - wire_type = kUpb_WireType_StartGroup; - e->depth++; - break; - } - case kUpb_FieldType_Message: { - size_t size; - upb_TaggedMessagePtr submsg = *(upb_TaggedMessagePtr*)field_mem; - const upb_MiniTable* subm = - upb_MiniTableSub_Message(subs[f->UPB_PRIVATE(submsg_index)]); - if (submsg == 0) { - return; - } - if (--e->depth == 0) encode_err(e, kUpb_EncodeStatus_MaxDepthExceeded); - encode_TaggedMessagePtr(e, submsg, subm, &size); - encode_varint(e, size); - wire_type = kUpb_WireType_Delimited; - e->depth++; - break; - } - default: - UPB_UNREACHABLE(); +#define FASTDECODE_VARINT(d, ptr, msg, table, hasbits, data, tagbytes, \ + valbytes, card, zigzag, unpacked, packed) \ + if (card == CARD_p) { \ + FASTDECODE_PACKEDVARINT(d, ptr, msg, table, hasbits, data, tagbytes, \ + valbytes, zigzag, unpacked); \ + } else { \ + FASTDECODE_UNPACKEDVARINT(d, ptr, msg, table, hasbits, data, tagbytes, \ + valbytes, card, zigzag, packed); \ } -#undef CASE - encode_tag(e, f->UPB_PRIVATE(number), wire_type); -} +#define z_ZZ true +#define b_ZZ false +#define v_ZZ false -static void encode_array(upb_encstate* e, const upb_Message* msg, - const upb_MiniTableSub* subs, - const upb_MiniTableField* f) { - const upb_Array* arr = *UPB_PTR_AT(msg, f->UPB_PRIVATE(offset), upb_Array*); - bool packed = upb_MiniTableField_IsPacked(f); - size_t pre_len = e->limit - e->ptr; +/* Generate all combinations: + * {s,o,r,p} x {b1,v4,z4,v8,z8} x {1bt,2bt} */ - if (arr == NULL || arr->UPB_PRIVATE(size) == 0) { - return; +#define F(card, type, valbytes, tagbytes) \ + UPB_NOINLINE \ + const char* upb_p##card##type##valbytes##_##tagbytes##bt(UPB_PARSE_PARAMS) { \ + FASTDECODE_VARINT(d, ptr, msg, table, hasbits, data, tagbytes, valbytes, \ + CARD_##card, type##_ZZ, \ + upb_pr##type##valbytes##_##tagbytes##bt, \ + upb_pp##type##valbytes##_##tagbytes##bt); \ } -#define VARINT_CASE(ctype, encode) \ - { \ - const ctype* start = _upb_array_constptr(arr); \ - const ctype* ptr = start + arr->UPB_PRIVATE(size); \ - uint32_t tag = \ - packed ? 0 : (f->UPB_PRIVATE(number) << 3) | kUpb_WireType_Varint; \ - do { \ - ptr--; \ - encode_varint(e, encode); \ - if (tag) encode_varint(e, tag); \ - } while (ptr != start); \ - } \ - break; +#define TYPES(card, tagbytes) \ + F(card, b, 1, tagbytes) \ + F(card, v, 4, tagbytes) \ + F(card, v, 8, tagbytes) \ + F(card, z, 4, tagbytes) \ + F(card, z, 8, tagbytes) -#define TAG(wire_type) (packed ? 0 : (f->UPB_PRIVATE(number) << 3 | wire_type)) +#define TAGBYTES(card) \ + TYPES(card, 1) \ + TYPES(card, 2) - switch (f->UPB_PRIVATE(descriptortype)) { - case kUpb_FieldType_Double: - encode_fixedarray(e, arr, sizeof(double), TAG(kUpb_WireType_64Bit)); - break; - case kUpb_FieldType_Float: - encode_fixedarray(e, arr, sizeof(float), TAG(kUpb_WireType_32Bit)); - break; - case kUpb_FieldType_SFixed64: - case kUpb_FieldType_Fixed64: - encode_fixedarray(e, arr, sizeof(uint64_t), TAG(kUpb_WireType_64Bit)); - break; - case kUpb_FieldType_Fixed32: - case kUpb_FieldType_SFixed32: - encode_fixedarray(e, arr, sizeof(uint32_t), TAG(kUpb_WireType_32Bit)); - break; - case kUpb_FieldType_Int64: - case kUpb_FieldType_UInt64: - VARINT_CASE(uint64_t, *ptr); - case kUpb_FieldType_UInt32: - VARINT_CASE(uint32_t, *ptr); - case kUpb_FieldType_Int32: - case kUpb_FieldType_Enum: - VARINT_CASE(int32_t, (int64_t)*ptr); - case kUpb_FieldType_Bool: - VARINT_CASE(bool, *ptr); - case kUpb_FieldType_SInt32: - VARINT_CASE(int32_t, encode_zz32(*ptr)); - case kUpb_FieldType_SInt64: - VARINT_CASE(int64_t, encode_zz64(*ptr)); - case kUpb_FieldType_String: - case kUpb_FieldType_Bytes: { - const upb_StringView* start = _upb_array_constptr(arr); - const upb_StringView* ptr = start + arr->UPB_PRIVATE(size); - do { - ptr--; - encode_bytes(e, ptr->data, ptr->size); - encode_varint(e, ptr->size); - encode_tag(e, f->UPB_PRIVATE(number), kUpb_WireType_Delimited); - } while (ptr != start); - return; - } - case kUpb_FieldType_Group: { - const upb_TaggedMessagePtr* start = _upb_array_constptr(arr); - const upb_TaggedMessagePtr* ptr = start + arr->UPB_PRIVATE(size); - const upb_MiniTable* subm = - upb_MiniTableSub_Message(subs[f->UPB_PRIVATE(submsg_index)]); - if (--e->depth == 0) encode_err(e, kUpb_EncodeStatus_MaxDepthExceeded); - do { - size_t size; - ptr--; - encode_tag(e, f->UPB_PRIVATE(number), kUpb_WireType_EndGroup); - encode_TaggedMessagePtr(e, *ptr, subm, &size); - encode_tag(e, f->UPB_PRIVATE(number), kUpb_WireType_StartGroup); - } while (ptr != start); - e->depth++; - return; - } - case kUpb_FieldType_Message: { - const upb_TaggedMessagePtr* start = _upb_array_constptr(arr); - const upb_TaggedMessagePtr* ptr = start + arr->UPB_PRIVATE(size); - const upb_MiniTable* subm = - upb_MiniTableSub_Message(subs[f->UPB_PRIVATE(submsg_index)]); - if (--e->depth == 0) encode_err(e, kUpb_EncodeStatus_MaxDepthExceeded); - do { - size_t size; - ptr--; - encode_TaggedMessagePtr(e, *ptr, subm, &size); - encode_varint(e, size); - encode_tag(e, f->UPB_PRIVATE(number), kUpb_WireType_Delimited); - } while (ptr != start); - e->depth++; - return; - } +TAGBYTES(s) +TAGBYTES(o) +TAGBYTES(r) +TAGBYTES(p) + +#undef z_ZZ +#undef b_ZZ +#undef v_ZZ +#undef o_ONEOF +#undef s_ONEOF +#undef r_ONEOF +#undef F +#undef TYPES +#undef TAGBYTES +#undef FASTDECODE_UNPACKEDVARINT +#undef FASTDECODE_PACKEDVARINT +#undef FASTDECODE_VARINT + +/* fixed fields ***************************************************************/ + +#define FASTDECODE_UNPACKEDFIXED(d, ptr, msg, table, hasbits, data, tagbytes, \ + valbytes, card, packed) \ + void* dst; \ + fastdecode_arr farr; \ + \ + FASTDECODE_CHECKPACKED(tagbytes, card, packed) \ + \ + dst = fastdecode_getfield(d, ptr, msg, &data, &hasbits, &farr, valbytes, \ + card); \ + if (card == CARD_r) { \ + if (UPB_UNLIKELY(!dst)) { \ + RETURN_GENERIC("couldn't allocate array in arena\n"); \ + } \ + } \ + \ + again: \ + if (card == CARD_r) { \ + dst = fastdecode_resizearr(d, dst, &farr, valbytes); \ + } \ + \ + ptr += tagbytes; \ + memcpy(dst, ptr, valbytes); \ + ptr += valbytes; \ + \ + if (card == CARD_r) { \ + fastdecode_nextret ret = fastdecode_nextrepeated( \ + d, dst, &ptr, &farr, data, tagbytes, valbytes); \ + switch (ret.next) { \ + case FD_NEXT_SAMEFIELD: \ + dst = ret.dst; \ + goto again; \ + case FD_NEXT_OTHERFIELD: \ + data = ret.tag; \ + UPB_MUSTTAIL return _upb_FastDecoder_TagDispatch(UPB_PARSE_ARGS); \ + case FD_NEXT_ATLIMIT: \ + return ptr; \ + } \ + } \ + \ + UPB_MUSTTAIL return fastdecode_dispatch(UPB_PARSE_ARGS); + +#define FASTDECODE_PACKEDFIXED(d, ptr, msg, table, hasbits, data, tagbytes, \ + valbytes, unpacked) \ + FASTDECODE_CHECKPACKED(tagbytes, CARD_r, unpacked) \ + \ + ptr += tagbytes; \ + int size = (uint8_t)ptr[0]; \ + ptr++; \ + if (size & 0x80) { \ + ptr = fastdecode_longsize(ptr, &size); \ + } \ + \ + if (UPB_UNLIKELY(!upb_EpsCopyInputStream_CheckDataSizeAvailable( \ + &d->input, ptr, size) || \ + (size % valbytes) != 0)) { \ + _upb_FastDecoder_ErrorJmp(d, kUpb_DecodeStatus_Malformed); \ + } \ + \ + upb_Array** arr_p = fastdecode_fieldmem(msg, data); \ + upb_Array* arr = *arr_p; \ + uint8_t elem_size_lg2 = __builtin_ctz(valbytes); \ + int elems = size / valbytes; \ + \ + if (UPB_LIKELY(!arr)) { \ + *arr_p = arr = \ + UPB_PRIVATE(_upb_Array_New)(&d->arena, elems, elem_size_lg2); \ + if (!arr) { \ + _upb_FastDecoder_ErrorJmp(d, kUpb_DecodeStatus_Malformed); \ + } \ + } else { \ + _upb_Array_ResizeUninitialized(arr, elems, &d->arena); \ + } \ + \ + char* dst = _upb_array_ptr(arr); \ + memcpy(dst, ptr, size); \ + arr->UPB_PRIVATE(size) = elems; \ + \ + ptr += size; \ + UPB_MUSTTAIL return fastdecode_dispatch(UPB_PARSE_ARGS); + +#define FASTDECODE_FIXED(d, ptr, msg, table, hasbits, data, tagbytes, \ + valbytes, card, unpacked, packed) \ + if (card == CARD_p) { \ + FASTDECODE_PACKEDFIXED(d, ptr, msg, table, hasbits, data, tagbytes, \ + valbytes, unpacked); \ + } else { \ + FASTDECODE_UNPACKEDFIXED(d, ptr, msg, table, hasbits, data, tagbytes, \ + valbytes, card, packed); \ } -#undef VARINT_CASE - if (packed) { - encode_varint(e, e->limit - e->ptr - pre_len); - encode_tag(e, f->UPB_PRIVATE(number), kUpb_WireType_Delimited); +/* Generate all combinations: + * {s,o,r,p} x {f4,f8} x {1bt,2bt} */ + +#define F(card, valbytes, tagbytes) \ + UPB_NOINLINE \ + const char* upb_p##card##f##valbytes##_##tagbytes##bt(UPB_PARSE_PARAMS) { \ + FASTDECODE_FIXED(d, ptr, msg, table, hasbits, data, tagbytes, valbytes, \ + CARD_##card, upb_ppf##valbytes##_##tagbytes##bt, \ + upb_prf##valbytes##_##tagbytes##bt); \ } -} -static void encode_mapentry(upb_encstate* e, uint32_t number, - const upb_MiniTable* layout, - const upb_MapEntry* ent) { - const upb_MiniTableField* key_field = &layout->UPB_PRIVATE(fields)[0]; - const upb_MiniTableField* val_field = &layout->UPB_PRIVATE(fields)[1]; - size_t pre_len = e->limit - e->ptr; - size_t size; - encode_scalar(e, &ent->data.v, layout->UPB_PRIVATE(subs), val_field); - encode_scalar(e, &ent->data.k, layout->UPB_PRIVATE(subs), key_field); - size = (e->limit - e->ptr) - pre_len; - encode_varint(e, size); - encode_tag(e, number, kUpb_WireType_Delimited); -} +#define TYPES(card, tagbytes) \ + F(card, 4, tagbytes) \ + F(card, 8, tagbytes) -static void encode_map(upb_encstate* e, const upb_Message* msg, - const upb_MiniTableSub* subs, - const upb_MiniTableField* f) { - const upb_Map* map = *UPB_PTR_AT(msg, f->UPB_PRIVATE(offset), const upb_Map*); - const upb_MiniTable* layout = - upb_MiniTableSub_Message(subs[f->UPB_PRIVATE(submsg_index)]); - UPB_ASSERT(layout->UPB_PRIVATE(field_count) == 2); +#define TAGBYTES(card) \ + TYPES(card, 1) \ + TYPES(card, 2) - if (map == NULL) return; +TAGBYTES(s) +TAGBYTES(o) +TAGBYTES(r) +TAGBYTES(p) - if (e->options & kUpb_EncodeOption_Deterministic) { - _upb_sortedmap sorted; - _upb_mapsorter_pushmap( - &e->sorter, layout->UPB_PRIVATE(fields)[0].UPB_PRIVATE(descriptortype), - map, &sorted); - upb_MapEntry ent; - while (_upb_sortedmap_next(&e->sorter, map, &sorted, &ent)) { - encode_mapentry(e, f->UPB_PRIVATE(number), layout, &ent); - } - _upb_mapsorter_popmap(&e->sorter, &sorted); - } else { - intptr_t iter = UPB_STRTABLE_BEGIN; - upb_StringView key; - upb_value val; - while (upb_strtable_next2(&map->table, &key, &val, &iter)) { - upb_MapEntry ent; - _upb_map_fromkey(key, &ent.data.k, map->key_size); - _upb_map_fromvalue(val, &ent.data.v, map->val_size); - encode_mapentry(e, f->UPB_PRIVATE(number), layout, &ent); - } - } -} +#undef F +#undef TYPES +#undef TAGBYTES +#undef FASTDECODE_UNPACKEDFIXED +#undef FASTDECODE_PACKEDFIXED -static bool encode_shouldencode(upb_encstate* e, const upb_Message* msg, - const upb_MiniTableSub* subs, - const upb_MiniTableField* f) { - if (f->presence == 0) { - // Proto3 presence or map/array. - const void* mem = UPB_PTR_AT(msg, f->UPB_PRIVATE(offset), void); - switch (UPB_PRIVATE(_upb_MiniTableField_GetRep)(f)) { - case kUpb_FieldRep_1Byte: { - char ch; - memcpy(&ch, mem, 1); - return ch != 0; - } - case kUpb_FieldRep_4Byte: { - uint32_t u32; - memcpy(&u32, mem, 4); - return u32 != 0; - } - case kUpb_FieldRep_8Byte: { - uint64_t u64; - memcpy(&u64, mem, 8); - return u64 != 0; - } - case kUpb_FieldRep_StringView: { - const upb_StringView* str = (const upb_StringView*)mem; - return str->size != 0; - } - default: - UPB_UNREACHABLE(); - } - } else if (f->presence > 0) { - // Proto2 presence: hasbit. - return UPB_PRIVATE(_upb_Message_GetHasbit)(msg, f); - } else { - // Field is in a oneof. - return UPB_PRIVATE(_upb_Message_GetOneofCase)(msg, f) == - f->UPB_PRIVATE(number); +/* string fields **************************************************************/ + +typedef const char* fastdecode_copystr_func(struct upb_Decoder* d, + const char* ptr, upb_Message* msg, + const upb_MiniTable* table, + uint64_t hasbits, + upb_StringView* dst); + +UPB_NOINLINE +static const char* fastdecode_verifyutf8(upb_Decoder* d, const char* ptr, + upb_Message* msg, intptr_t table, + uint64_t hasbits, uint64_t data) { + upb_StringView* dst = (upb_StringView*)data; + if (!_upb_Decoder_VerifyUtf8Inline(dst->data, dst->size)) { + _upb_FastDecoder_ErrorJmp(d, kUpb_DecodeStatus_BadUtf8); } + UPB_MUSTTAIL return fastdecode_dispatch(UPB_PARSE_ARGS); } -static void encode_field(upb_encstate* e, const upb_Message* msg, - const upb_MiniTableSub* subs, - const upb_MiniTableField* field) { - switch (UPB_PRIVATE(_upb_MiniTableField_Mode)(field)) { - case kUpb_FieldMode_Array: - encode_array(e, msg, subs, field); - break; - case kUpb_FieldMode_Map: - encode_map(e, msg, subs, field); - break; - case kUpb_FieldMode_Scalar: - encode_scalar(e, UPB_PTR_AT(msg, field->UPB_PRIVATE(offset), void), subs, - field); - break; - default: - UPB_UNREACHABLE(); +#define FASTDECODE_LONGSTRING(d, ptr, msg, table, hasbits, dst, validate_utf8) \ + int size = (uint8_t)ptr[0]; /* Could plumb through hasbits. */ \ + ptr++; \ + if (size & 0x80) { \ + ptr = fastdecode_longsize(ptr, &size); \ + } \ + \ + if (UPB_UNLIKELY(!upb_EpsCopyInputStream_CheckSize(&d->input, ptr, size))) { \ + dst->size = 0; \ + _upb_FastDecoder_ErrorJmp(d, kUpb_DecodeStatus_Malformed); \ + } \ + \ + const char* s_ptr = ptr; \ + ptr = upb_EpsCopyInputStream_ReadString(&d->input, &s_ptr, size, &d->arena); \ + if (!ptr) _upb_FastDecoder_ErrorJmp(d, kUpb_DecodeStatus_OutOfMemory); \ + dst->data = s_ptr; \ + dst->size = size; \ + \ + if (validate_utf8) { \ + data = (uint64_t)dst; \ + UPB_MUSTTAIL return fastdecode_verifyutf8(UPB_PARSE_ARGS); \ + } else { \ + UPB_MUSTTAIL return fastdecode_dispatch(UPB_PARSE_ARGS); \ } + +UPB_NOINLINE +static const char* fastdecode_longstring_utf8(struct upb_Decoder* d, + const char* ptr, upb_Message* msg, + intptr_t table, uint64_t hasbits, + uint64_t data) { + upb_StringView* dst = (upb_StringView*)data; + FASTDECODE_LONGSTRING(d, ptr, msg, table, hasbits, dst, true); } -static void encode_msgset_item(upb_encstate* e, const upb_Extension* ext) { - size_t size; - encode_tag(e, kUpb_MsgSet_Item, kUpb_WireType_EndGroup); - encode_message(e, ext->data.ptr, - upb_MiniTableExtension_GetSubMessage(ext->ext), &size); - encode_varint(e, size); - encode_tag(e, kUpb_MsgSet_Message, kUpb_WireType_Delimited); - encode_varint(e, upb_MiniTableExtension_Number(ext->ext)); - encode_tag(e, kUpb_MsgSet_TypeId, kUpb_WireType_Varint); - encode_tag(e, kUpb_MsgSet_Item, kUpb_WireType_StartGroup); +UPB_NOINLINE +static const char* fastdecode_longstring_noutf8( + struct upb_Decoder* d, const char* ptr, upb_Message* msg, intptr_t table, + uint64_t hasbits, uint64_t data) { + upb_StringView* dst = (upb_StringView*)data; + FASTDECODE_LONGSTRING(d, ptr, msg, table, hasbits, dst, false); +} + +UPB_FORCEINLINE +static void fastdecode_docopy(upb_Decoder* d, const char* ptr, uint32_t size, + int copy, char* data, size_t data_offset, + upb_StringView* dst) { + d->arena.UPB_PRIVATE(ptr) += copy; + dst->data = data + data_offset; + UPB_UNPOISON_MEMORY_REGION(data, copy); + memcpy(data, ptr, copy); + UPB_POISON_MEMORY_REGION(data + data_offset + size, + copy - data_offset - size); } -static void encode_ext(upb_encstate* e, const upb_Extension* ext, - bool is_message_set) { - if (UPB_UNLIKELY(is_message_set)) { - encode_msgset_item(e, ext); - } else { - encode_field(e, (upb_Message*)&ext->data, &ext->ext->UPB_PRIVATE(sub), - &ext->ext->UPB_PRIVATE(field)); +#define FASTDECODE_COPYSTRING(d, ptr, msg, table, hasbits, data, tagbytes, \ + card, validate_utf8) \ + upb_StringView* dst; \ + fastdecode_arr farr; \ + int64_t size; \ + size_t arena_has; \ + size_t common_has; \ + char* buf; \ + \ + UPB_ASSERT(!upb_EpsCopyInputStream_AliasingAvailable(&d->input, ptr, 0)); \ + UPB_ASSERT(fastdecode_checktag(data, tagbytes)); \ + \ + dst = fastdecode_getfield(d, ptr, msg, &data, &hasbits, &farr, \ + sizeof(upb_StringView), card); \ + \ + again: \ + if (card == CARD_r) { \ + dst = fastdecode_resizearr(d, dst, &farr, sizeof(upb_StringView)); \ + } \ + \ + size = (uint8_t)ptr[tagbytes]; \ + ptr += tagbytes + 1; \ + dst->size = size; \ + \ + buf = d->arena.UPB_PRIVATE(ptr); \ + arena_has = UPB_PRIVATE(_upb_ArenaHas)(&d->arena); \ + common_has = UPB_MIN(arena_has, \ + upb_EpsCopyInputStream_BytesAvailable(&d->input, ptr)); \ + \ + if (UPB_LIKELY(size <= 15 - tagbytes)) { \ + if (arena_has < 16) goto longstr; \ + fastdecode_docopy(d, ptr - tagbytes - 1, size, 16, buf, tagbytes + 1, \ + dst); \ + } else if (UPB_LIKELY(size <= 32)) { \ + if (UPB_UNLIKELY(common_has < 32)) goto longstr; \ + fastdecode_docopy(d, ptr, size, 32, buf, 0, dst); \ + } else if (UPB_LIKELY(size <= 64)) { \ + if (UPB_UNLIKELY(common_has < 64)) goto longstr; \ + fastdecode_docopy(d, ptr, size, 64, buf, 0, dst); \ + } else if (UPB_LIKELY(size < 128)) { \ + if (UPB_UNLIKELY(common_has < 128)) goto longstr; \ + fastdecode_docopy(d, ptr, size, 128, buf, 0, dst); \ + } else { \ + goto longstr; \ + } \ + \ + ptr += size; \ + \ + if (card == CARD_r) { \ + if (validate_utf8 && \ + !_upb_Decoder_VerifyUtf8Inline(dst->data, dst->size)) { \ + _upb_FastDecoder_ErrorJmp(d, kUpb_DecodeStatus_BadUtf8); \ + } \ + fastdecode_nextret ret = fastdecode_nextrepeated( \ + d, dst, &ptr, &farr, data, tagbytes, sizeof(upb_StringView)); \ + switch (ret.next) { \ + case FD_NEXT_SAMEFIELD: \ + dst = ret.dst; \ + goto again; \ + case FD_NEXT_OTHERFIELD: \ + data = ret.tag; \ + UPB_MUSTTAIL return _upb_FastDecoder_TagDispatch(UPB_PARSE_ARGS); \ + case FD_NEXT_ATLIMIT: \ + return ptr; \ + } \ + } \ + \ + if (card != CARD_r && validate_utf8) { \ + data = (uint64_t)dst; \ + UPB_MUSTTAIL return fastdecode_verifyutf8(UPB_PARSE_ARGS); \ + } \ + \ + UPB_MUSTTAIL return fastdecode_dispatch(UPB_PARSE_ARGS); \ + \ + longstr: \ + if (card == CARD_r) { \ + fastdecode_commitarr(dst + 1, &farr, sizeof(upb_StringView)); \ + } \ + ptr--; \ + if (validate_utf8) { \ + UPB_MUSTTAIL return fastdecode_longstring_utf8(d, ptr, msg, table, \ + hasbits, (uint64_t)dst); \ + } else { \ + UPB_MUSTTAIL return fastdecode_longstring_noutf8(d, ptr, msg, table, \ + hasbits, (uint64_t)dst); \ + } + +#define FASTDECODE_STRING(d, ptr, msg, table, hasbits, data, tagbytes, card, \ + copyfunc, validate_utf8) \ + upb_StringView* dst; \ + fastdecode_arr farr; \ + int64_t size; \ + \ + if (UPB_UNLIKELY(!fastdecode_checktag(data, tagbytes))) { \ + RETURN_GENERIC("string field tag mismatch\n"); \ + } \ + \ + if (UPB_UNLIKELY( \ + !upb_EpsCopyInputStream_AliasingAvailable(&d->input, ptr, 0))) { \ + UPB_MUSTTAIL return copyfunc(UPB_PARSE_ARGS); \ + } \ + \ + dst = fastdecode_getfield(d, ptr, msg, &data, &hasbits, &farr, \ + sizeof(upb_StringView), card); \ + \ + again: \ + if (card == CARD_r) { \ + dst = fastdecode_resizearr(d, dst, &farr, sizeof(upb_StringView)); \ + } \ + \ + size = (int8_t)ptr[tagbytes]; \ + ptr += tagbytes + 1; \ + \ + if (UPB_UNLIKELY( \ + !upb_EpsCopyInputStream_AliasingAvailable(&d->input, ptr, size))) { \ + ptr--; \ + if (validate_utf8) { \ + return fastdecode_longstring_utf8(d, ptr, msg, table, hasbits, \ + (uint64_t)dst); \ + } else { \ + return fastdecode_longstring_noutf8(d, ptr, msg, table, hasbits, \ + (uint64_t)dst); \ + } \ + } \ + \ + dst->data = ptr; \ + dst->size = size; \ + ptr = upb_EpsCopyInputStream_ReadStringAliased(&d->input, &dst->data, \ + dst->size); \ + \ + if (card == CARD_r) { \ + if (validate_utf8 && \ + !_upb_Decoder_VerifyUtf8Inline(dst->data, dst->size)) { \ + _upb_FastDecoder_ErrorJmp(d, kUpb_DecodeStatus_BadUtf8); \ + } \ + fastdecode_nextret ret = fastdecode_nextrepeated( \ + d, dst, &ptr, &farr, data, tagbytes, sizeof(upb_StringView)); \ + switch (ret.next) { \ + case FD_NEXT_SAMEFIELD: \ + dst = ret.dst; \ + goto again; \ + case FD_NEXT_OTHERFIELD: \ + data = ret.tag; \ + UPB_MUSTTAIL return _upb_FastDecoder_TagDispatch(UPB_PARSE_ARGS); \ + case FD_NEXT_ATLIMIT: \ + return ptr; \ + } \ + } \ + \ + if (card != CARD_r && validate_utf8) { \ + data = (uint64_t)dst; \ + UPB_MUSTTAIL return fastdecode_verifyutf8(UPB_PARSE_ARGS); \ + } \ + \ + UPB_MUSTTAIL return fastdecode_dispatch(UPB_PARSE_ARGS); + +/* Generate all combinations: + * {p,c} x {s,o,r} x {s, b} x {1bt,2bt} */ + +#define s_VALIDATE true +#define b_VALIDATE false + +#define F(card, tagbytes, type) \ + UPB_NOINLINE \ + const char* upb_c##card##type##_##tagbytes##bt(UPB_PARSE_PARAMS) { \ + FASTDECODE_COPYSTRING(d, ptr, msg, table, hasbits, data, tagbytes, \ + CARD_##card, type##_VALIDATE); \ + } \ + const char* upb_p##card##type##_##tagbytes##bt(UPB_PARSE_PARAMS) { \ + FASTDECODE_STRING(d, ptr, msg, table, hasbits, data, tagbytes, \ + CARD_##card, upb_c##card##type##_##tagbytes##bt, \ + type##_VALIDATE); \ } -} -static void encode_message(upb_encstate* e, const upb_Message* msg, - const upb_MiniTable* m, size_t* size) { - size_t pre_len = e->limit - e->ptr; +#define UTF8(card, tagbytes) \ + F(card, tagbytes, s) \ + F(card, tagbytes, b) - if ((e->options & kUpb_EncodeOption_CheckRequired) && - m->UPB_PRIVATE(required_count)) { - uint64_t msg_head; - memcpy(&msg_head, msg, 8); - msg_head = _upb_BigEndian_Swap64(msg_head); - if (UPB_PRIVATE(_upb_MiniTable_RequiredMask)(m) & ~msg_head) { - encode_err(e, kUpb_EncodeStatus_MissingRequired); - } - } +#define TAGBYTES(card) \ + UTF8(card, 1) \ + UTF8(card, 2) - if ((e->options & kUpb_EncodeOption_SkipUnknown) == 0) { - size_t unknown_size; - const char* unknown = upb_Message_GetUnknown(msg, &unknown_size); +TAGBYTES(s) +TAGBYTES(o) +TAGBYTES(r) - if (unknown) { - encode_bytes(e, unknown, unknown_size); - } - } +#undef s_VALIDATE +#undef b_VALIDATE +#undef F +#undef TAGBYTES +#undef FASTDECODE_LONGSTRING +#undef FASTDECODE_COPYSTRING +#undef FASTDECODE_STRING - if (m->UPB_PRIVATE(ext) != kUpb_ExtMode_NonExtendable) { - /* Encode all extensions together. Unlike C++, we do not attempt to keep - * these in field number order relative to normal fields or even to each - * other. */ - size_t ext_count; - const upb_Extension* ext = - UPB_PRIVATE(_upb_Message_Getexts)(msg, &ext_count); - if (ext_count) { - if (e->options & kUpb_EncodeOption_Deterministic) { - _upb_sortedmap sorted; - _upb_mapsorter_pushexts(&e->sorter, ext, ext_count, &sorted); - while (_upb_sortedmap_nextext(&e->sorter, &sorted, &ext)) { - encode_ext(e, ext, m->UPB_PRIVATE(ext) == kUpb_ExtMode_IsMessageSet); - } - _upb_mapsorter_popmap(&e->sorter, &sorted); - } else { - const upb_Extension* end = ext + ext_count; - for (; ext != end; ext++) { - encode_ext(e, ext, m->UPB_PRIVATE(ext) == kUpb_ExtMode_IsMessageSet); - } - } - } - } +/* message fields *************************************************************/ - if (m->UPB_PRIVATE(field_count)) { - const upb_MiniTableField* f = - &m->UPB_PRIVATE(fields)[m->UPB_PRIVATE(field_count)]; - const upb_MiniTableField* first = &m->UPB_PRIVATE(fields)[0]; - while (f != first) { - f--; - if (encode_shouldencode(e, msg, m->UPB_PRIVATE(subs), f)) { - encode_field(e, msg, m->UPB_PRIVATE(subs), f); - } - } +UPB_INLINE +upb_Message* decode_newmsg_ceil(upb_Decoder* d, const upb_MiniTable* m, + int msg_ceil_bytes) { + size_t size = m->UPB_PRIVATE(size) + sizeof(upb_Message_Internal); + char* msg_data; + if (UPB_LIKELY(msg_ceil_bytes > 0 && + UPB_PRIVATE(_upb_ArenaHas)(&d->arena) >= msg_ceil_bytes)) { + UPB_ASSERT(size <= (size_t)msg_ceil_bytes); + msg_data = d->arena.UPB_PRIVATE(ptr); + d->arena.UPB_PRIVATE(ptr) += size; + UPB_UNPOISON_MEMORY_REGION(msg_data, msg_ceil_bytes); + memset(msg_data, 0, msg_ceil_bytes); + UPB_POISON_MEMORY_REGION(msg_data + size, msg_ceil_bytes - size); + } else { + msg_data = (char*)upb_Arena_Malloc(&d->arena, size); + memset(msg_data, 0, size); } + return msg_data + sizeof(upb_Message_Internal); +} - *size = (e->limit - e->ptr) - pre_len; +typedef struct { + intptr_t table; + upb_Message* msg; +} fastdecode_submsgdata; + +UPB_FORCEINLINE +static const char* fastdecode_tosubmsg(upb_EpsCopyInputStream* e, + const char* ptr, void* ctx) { + upb_Decoder* d = (upb_Decoder*)e; + fastdecode_submsgdata* submsg = ctx; + ptr = fastdecode_dispatch(d, ptr, submsg->msg, submsg->table, 0, 0); + UPB_ASSUME(ptr != NULL); + return ptr; } -static upb_EncodeStatus upb_Encoder_Encode(upb_encstate* const encoder, - const upb_Message* const msg, - const upb_MiniTable* const l, - char** const buf, - size_t* const size) { - // Unfortunately we must continue to perform hackery here because there are - // code paths which blindly copy the returned pointer without bothering to - // check for errors until much later (b/235839510). So we still set *buf to - // NULL on error and we still set it to non-NULL on a successful empty result. - if (UPB_SETJMP(encoder->err) == 0) { - encode_message(encoder, msg, l, size); - *size = encoder->limit - encoder->ptr; - if (*size == 0) { - static char ch; - *buf = &ch; - } else { - UPB_ASSERT(encoder->ptr); - *buf = encoder->ptr; - } - } else { - UPB_ASSERT(encoder->status != kUpb_EncodeStatus_Ok); - *buf = NULL; - *size = 0; +#define FASTDECODE_SUBMSG(d, ptr, msg, table, hasbits, data, tagbytes, \ + msg_ceil_bytes, card) \ + \ + if (UPB_UNLIKELY(!fastdecode_checktag(data, tagbytes))) { \ + RETURN_GENERIC("submessage field tag mismatch\n"); \ + } \ + \ + if (--d->depth == 0) { \ + _upb_FastDecoder_ErrorJmp(d, kUpb_DecodeStatus_MaxDepthExceeded); \ + } \ + \ + upb_Message** dst; \ + uint32_t submsg_idx = (data >> 16) & 0xff; \ + const upb_MiniTable* tablep = decode_totablep(table); \ + const upb_MiniTable* subtablep = upb_MiniTableSub_Message( \ + *UPB_PRIVATE(_upb_MiniTable_GetSubByIndex)(tablep, submsg_idx)); \ + fastdecode_submsgdata submsg = {decode_totable(subtablep)}; \ + fastdecode_arr farr; \ + \ + if (subtablep->UPB_PRIVATE(table_mask) == (uint8_t)-1) { \ + d->depth++; \ + RETURN_GENERIC("submessage doesn't have fast tables."); \ + } \ + \ + dst = fastdecode_getfield(d, ptr, msg, &data, &hasbits, &farr, \ + sizeof(upb_Message*), card); \ + \ + if (card == CARD_s) { \ + *(uint32_t*)msg |= hasbits; \ + hasbits = 0; \ + } \ + \ + again: \ + if (card == CARD_r) { \ + dst = fastdecode_resizearr(d, dst, &farr, sizeof(upb_Message*)); \ + } \ + \ + submsg.msg = *dst; \ + \ + if (card == CARD_r || UPB_LIKELY(!submsg.msg)) { \ + *dst = submsg.msg = decode_newmsg_ceil(d, subtablep, msg_ceil_bytes); \ + } \ + \ + ptr += tagbytes; \ + ptr = fastdecode_delimited(d, ptr, fastdecode_tosubmsg, &submsg); \ + \ + if (UPB_UNLIKELY(ptr == NULL || d->end_group != DECODE_NOGROUP)) { \ + _upb_FastDecoder_ErrorJmp(d, kUpb_DecodeStatus_Malformed); \ + } \ + \ + if (card == CARD_r) { \ + fastdecode_nextret ret = fastdecode_nextrepeated( \ + d, dst, &ptr, &farr, data, tagbytes, sizeof(upb_Message*)); \ + switch (ret.next) { \ + case FD_NEXT_SAMEFIELD: \ + dst = ret.dst; \ + goto again; \ + case FD_NEXT_OTHERFIELD: \ + d->depth++; \ + data = ret.tag; \ + UPB_MUSTTAIL return _upb_FastDecoder_TagDispatch(UPB_PARSE_ARGS); \ + case FD_NEXT_ATLIMIT: \ + d->depth++; \ + return ptr; \ + } \ + } \ + \ + d->depth++; \ + UPB_MUSTTAIL return fastdecode_dispatch(UPB_PARSE_ARGS); + +#define F(card, tagbytes, size_ceil, ceil_arg) \ + const char* upb_p##card##m_##tagbytes##bt_max##size_ceil##b( \ + UPB_PARSE_PARAMS) { \ + FASTDECODE_SUBMSG(d, ptr, msg, table, hasbits, data, tagbytes, ceil_arg, \ + CARD_##card); \ } - _upb_mapsorter_destroy(&encoder->sorter); - return encoder->status; -} +#define SIZES(card, tagbytes) \ + F(card, tagbytes, 64, 64) \ + F(card, tagbytes, 128, 128) \ + F(card, tagbytes, 192, 192) \ + F(card, tagbytes, 256, 256) \ + F(card, tagbytes, max, -1) -upb_EncodeStatus upb_Encode(const upb_Message* msg, const upb_MiniTable* l, - int options, upb_Arena* arena, char** buf, - size_t* size) { - upb_encstate e; - unsigned depth = (unsigned)options >> 16; +#define TAGBYTES(card) \ + SIZES(card, 1) \ + SIZES(card, 2) - e.status = kUpb_EncodeStatus_Ok; - e.arena = arena; - e.buf = NULL; - e.limit = NULL; - e.ptr = NULL; - e.depth = depth ? depth : kUpb_WireFormat_DefaultDepthLimit; - e.options = options; - _upb_mapsorter_init(&e.sorter); +TAGBYTES(s) +TAGBYTES(o) +TAGBYTES(r) + +#undef TAGBYTES +#undef SIZES +#undef F +#undef FASTDECODE_SUBMSG + +#endif /* UPB_FASTTABLE */ - return upb_Encoder_Encode(&e, msg, l, buf, size); -} +#include +#include // Must be last. -UPB_NOINLINE _upb_WireReader_ReadLongVarintRet -_upb_WireReader_ReadLongVarint(const char* ptr, uint64_t val) { - _upb_WireReader_ReadLongVarintRet ret = {NULL, 0}; +UPB_NOINLINE UPB_PRIVATE(_upb_WireReader_LongVarint) + UPB_PRIVATE(_upb_WireReader_ReadLongVarint)(const char* ptr, uint64_t val) { + UPB_PRIVATE(_upb_WireReader_LongVarint) ret = {NULL, 0}; uint64_t byte; int i; for (i = 1; i < 10; i++) { @@ -15773,9 +15776,9 @@ _upb_WireReader_ReadLongVarint(const char* ptr, uint64_t val) { return ret; } -const char* _upb_WireReader_SkipGroup(const char* ptr, uint32_t tag, - int depth_limit, - upb_EpsCopyInputStream* stream) { +const char* UPB_PRIVATE(_upb_WireReader_SkipGroup)( + const char* ptr, uint32_t tag, int depth_limit, + upb_EpsCopyInputStream* stream) { if (--depth_limit == 0) return NULL; uint32_t end_group_tag = (tag & ~7ULL) | kUpb_WireType_EndGroup; while (!upb_EpsCopyInputStream_IsDone(stream, &ptr)) { diff --git a/php/ext/google/protobuf/php-upb.h b/php/ext/google/protobuf/php-upb.h index 87af0ee6e5ae9..aaeb1170b9eee 100644 --- a/php/ext/google/protobuf/php-upb.h +++ b/php/ext/google/protobuf/php-upb.h @@ -1354,8 +1354,9 @@ UPB_INLINE const upb_MiniTable* UPB_PRIVATE(_upb_MiniTableSub_Message)( // Must be last. struct upb_Decoder; +struct upb_Message; typedef const char* _upb_FieldParser(struct upb_Decoder* d, const char* ptr, - upb_Message* msg, intptr_t table, + struct upb_Message* msg, intptr_t table, uint64_t hasbits, uint64_t data); typedef struct { uint64_t field_data; @@ -4004,6 +4005,72 @@ UPB_API upb_DecodeStatus upb_Decode(const char* buf, size_t size, #endif /* UPB_WIRE_DECODE_H_ */ +// upb_Encode: parsing from a upb_Message using a upb_MiniTable. + +#ifndef UPB_WIRE_ENCODE_H_ +#define UPB_WIRE_ENCODE_H_ + +#include +#include + + +// Must be last. + +#ifdef __cplusplus +extern "C" { +#endif + +enum { + /* If set, the results of serializing will be deterministic across all + * instances of this binary. There are no guarantees across different + * binary builds. + * + * If your proto contains maps, the encoder will need to malloc()/free() + * memory during encode. */ + kUpb_EncodeOption_Deterministic = 1, + + // When set, unknown fields are not printed. + kUpb_EncodeOption_SkipUnknown = 2, + + // When set, the encode will fail if any required fields are missing. + kUpb_EncodeOption_CheckRequired = 4, +}; + +typedef enum { + kUpb_EncodeStatus_Ok = 0, + kUpb_EncodeStatus_OutOfMemory = 1, // Arena alloc failed + kUpb_EncodeStatus_MaxDepthExceeded = 2, + + // kUpb_EncodeOption_CheckRequired failed but the parse otherwise succeeded. + kUpb_EncodeStatus_MissingRequired = 3, +} upb_EncodeStatus; + +UPB_INLINE uint32_t upb_EncodeOptions_MaxDepth(uint16_t depth) { + return (uint32_t)depth << 16; +} + +UPB_INLINE uint16_t upb_EncodeOptions_GetMaxDepth(uint32_t options) { + return options >> 16; +} + +// Enforce an upper bound on recursion depth. +UPB_INLINE int upb_Encode_LimitDepth(uint32_t encode_options, uint32_t limit) { + uint32_t max_depth = upb_EncodeOptions_GetMaxDepth(encode_options); + if (max_depth > limit) max_depth = limit; + return upb_EncodeOptions_MaxDepth(max_depth) | (encode_options & 0xffff); +} + +UPB_API upb_EncodeStatus upb_Encode(const upb_Message* msg, + const upb_MiniTable* l, int options, + upb_Arena* arena, char** buf, size_t* size); + +#ifdef __cplusplus +} /* extern "C" */ +#endif + + +#endif /* UPB_WIRE_ENCODE_H_ */ + // These are the specialized field parser functions for the fast parser. // Generated tables will refer to these by name. // @@ -4038,8 +4105,8 @@ UPB_API upb_DecodeStatus upb_Decode(const char* buf, size_t size, // - '1' for one-byte tags (field numbers 1-15) // - '2' for two-byte tags (field numbers 16-2048) -#ifndef UPB_WIRE_DECODE_FAST_H_ -#define UPB_WIRE_DECODE_FAST_H_ +#ifndef UPB_WIRE_DECODE_INTERNAL_FAST_H_ +#define UPB_WIRE_DECODE_INTERNAL_FAST_H_ // Must be last. @@ -4140,73 +4207,7 @@ TAGBYTES(r) #endif -#endif /* UPB_WIRE_DECODE_FAST_H_ */ - -// upb_Encode: parsing from a upb_Message using a upb_MiniTable. - -#ifndef UPB_WIRE_ENCODE_H_ -#define UPB_WIRE_ENCODE_H_ - -#include -#include - - -// Must be last. - -#ifdef __cplusplus -extern "C" { -#endif - -enum { - /* If set, the results of serializing will be deterministic across all - * instances of this binary. There are no guarantees across different - * binary builds. - * - * If your proto contains maps, the encoder will need to malloc()/free() - * memory during encode. */ - kUpb_EncodeOption_Deterministic = 1, - - // When set, unknown fields are not printed. - kUpb_EncodeOption_SkipUnknown = 2, - - // When set, the encode will fail if any required fields are missing. - kUpb_EncodeOption_CheckRequired = 4, -}; - -typedef enum { - kUpb_EncodeStatus_Ok = 0, - kUpb_EncodeStatus_OutOfMemory = 1, // Arena alloc failed - kUpb_EncodeStatus_MaxDepthExceeded = 2, - - // kUpb_EncodeOption_CheckRequired failed but the parse otherwise succeeded. - kUpb_EncodeStatus_MissingRequired = 3, -} upb_EncodeStatus; - -UPB_INLINE uint32_t upb_EncodeOptions_MaxDepth(uint16_t depth) { - return (uint32_t)depth << 16; -} - -UPB_INLINE uint16_t upb_EncodeOptions_GetMaxDepth(uint32_t options) { - return options >> 16; -} - -// Enforce an upper bound on recursion depth. -UPB_INLINE int upb_Encode_LimitDepth(uint32_t encode_options, uint32_t limit) { - uint32_t max_depth = upb_EncodeOptions_GetMaxDepth(encode_options); - if (max_depth > limit) max_depth = limit; - return upb_EncodeOptions_MaxDepth(max_depth) | (encode_options & 0xffff); -} - -UPB_API upb_EncodeStatus upb_Encode(const upb_Message* msg, - const upb_MiniTable* l, int options, - upb_Arena* arena, char** buf, size_t* size); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - - -#endif /* UPB_WIRE_ENCODE_H_ */ +#endif /* UPB_WIRE_DECODE_INTERNAL_FAST_H_ */ // IWYU pragma: end_exports #endif // UPB_GENERATED_CODE_SUPPORT_H_ @@ -13714,8 +13715,8 @@ UPB_INLINE uint32_t _upb_FastDecoder_LoadTag(const char* ptr) { #endif /* UPB_WIRE_INTERNAL_DECODE_H_ */ -#ifndef UPB_WIRE_INTERNAL_SWAP_H_ -#define UPB_WIRE_INTERNAL_SWAP_H_ +#ifndef UPB_WIRE_INTERNAL_ENDIAN_H_ +#define UPB_WIRE_INTERNAL_ENDIAN_H_ #include @@ -13725,23 +13726,23 @@ UPB_INLINE uint32_t _upb_FastDecoder_LoadTag(const char* ptr) { extern "C" { #endif -UPB_INLINE bool _upb_IsLittleEndian(void) { - int x = 1; +UPB_INLINE bool UPB_PRIVATE(_upb_IsLittleEndian)(void) { + const int x = 1; return *(char*)&x == 1; } -UPB_INLINE uint32_t _upb_BigEndian_Swap32(uint32_t val) { - if (_upb_IsLittleEndian()) return val; +UPB_INLINE uint32_t UPB_PRIVATE(_upb_BigEndian32)(uint32_t val) { + if (UPB_PRIVATE(_upb_IsLittleEndian)()) return val; return ((val & 0xff) << 24) | ((val & 0xff00) << 8) | ((val & 0xff0000) >> 8) | ((val & 0xff000000) >> 24); } -UPB_INLINE uint64_t _upb_BigEndian_Swap64(uint64_t val) { - if (_upb_IsLittleEndian()) return val; +UPB_INLINE uint64_t UPB_PRIVATE(_upb_BigEndian64)(uint64_t val) { + if (UPB_PRIVATE(_upb_IsLittleEndian)()) return val; - return ((uint64_t)_upb_BigEndian_Swap32((uint32_t)val) << 32) | - _upb_BigEndian_Swap32((uint32_t)(val >> 32)); + return ((uint64_t)UPB_PRIVATE(_upb_BigEndian32)((uint32_t)val) << 32) | + UPB_PRIVATE(_upb_BigEndian32)((uint32_t)(val >> 32)); } #ifdef __cplusplus @@ -13749,62 +13750,42 @@ UPB_INLINE uint64_t _upb_BigEndian_Swap64(uint64_t val) { #endif -#endif /* UPB_WIRE_INTERNAL_SWAP_H_ */ +#endif /* UPB_WIRE_INTERNAL_ENDIAN_H_ */ #ifndef UPB_WIRE_READER_H_ #define UPB_WIRE_READER_H_ -#ifndef UPB_WIRE_TYPES_H_ -#define UPB_WIRE_TYPES_H_ - -// A list of types as they are encoded on the wire. -typedef enum { - kUpb_WireType_Varint = 0, - kUpb_WireType_64Bit = 1, - kUpb_WireType_Delimited = 2, - kUpb_WireType_StartGroup = 3, - kUpb_WireType_EndGroup = 4, - kUpb_WireType_32Bit = 5 -} upb_WireType; - -#endif /* UPB_WIRE_TYPES_H_ */ +#ifndef UPB_WIRE_INTERNAL_READER_H_ +#define UPB_WIRE_INTERNAL_READER_H_ // Must be last. -#ifdef __cplusplus -extern "C" { -#endif - -// The upb_WireReader interface is suitable for general-purpose parsing of -// protobuf binary wire format. It is designed to be used along with -// upb_EpsCopyInputStream for buffering, and all parsing routines in this file -// assume that at least kUpb_EpsCopyInputStream_SlopBytes worth of data is -// available to read without any bounds checks. - -#define kUpb_WireReader_WireTypeMask 7 #define kUpb_WireReader_WireTypeBits 3 +#define kUpb_WireReader_WireTypeMask 7 typedef struct { const char* ptr; uint64_t val; -} _upb_WireReader_ReadLongVarintRet; +} UPB_PRIVATE(_upb_WireReader_LongVarint); -_upb_WireReader_ReadLongVarintRet _upb_WireReader_ReadLongVarint( - const char* ptr, uint64_t val); +#ifdef __cplusplus +extern "C" { +#endif + +UPB_PRIVATE(_upb_WireReader_LongVarint) +UPB_PRIVATE(_upb_WireReader_ReadLongVarint)(const char* ptr, uint64_t val); -static UPB_FORCEINLINE const char* _upb_WireReader_ReadVarint(const char* ptr, - uint64_t* val, - int maxlen, - uint64_t maxval) { +static UPB_FORCEINLINE const char* UPB_PRIVATE(_upb_WireReader_ReadVarint)( + const char* ptr, uint64_t* val, int maxlen, uint64_t maxval) { uint64_t byte = (uint8_t)*ptr; if (UPB_LIKELY((byte & 0x80) == 0)) { *val = (uint32_t)byte; return ptr + 1; } const char* start = ptr; - _upb_WireReader_ReadLongVarintRet res = - _upb_WireReader_ReadLongVarint(ptr, byte); + UPB_PRIVATE(_upb_WireReader_LongVarint) + res = UPB_PRIVATE(_upb_WireReader_ReadLongVarint)(ptr, byte); if (!res.ptr || (maxlen < 10 && res.ptr - start > maxlen) || res.val > maxval) { return NULL; // Malformed. @@ -13813,6 +13794,48 @@ static UPB_FORCEINLINE const char* _upb_WireReader_ReadVarint(const char* ptr, return res.ptr; } +UPB_INLINE uint32_t UPB_PRIVATE(_upb_WireReader_GetFieldNumber)(uint32_t tag) { + return tag >> kUpb_WireReader_WireTypeBits; +} + +UPB_INLINE uint8_t UPB_PRIVATE(_upb_WireReader_GetWireType)(uint32_t tag) { + return tag & kUpb_WireReader_WireTypeMask; +} + +#ifdef __cplusplus +} /* extern "C" */ +#endif + + +#endif // UPB_WIRE_INTERNAL_READER_H_ + +#ifndef UPB_WIRE_TYPES_H_ +#define UPB_WIRE_TYPES_H_ + +// A list of types as they are encoded on the wire. +typedef enum { + kUpb_WireType_Varint = 0, + kUpb_WireType_64Bit = 1, + kUpb_WireType_Delimited = 2, + kUpb_WireType_StartGroup = 3, + kUpb_WireType_EndGroup = 4, + kUpb_WireType_32Bit = 5 +} upb_WireType; + +#endif /* UPB_WIRE_TYPES_H_ */ + +// Must be last. + +// The upb_WireReader interface is suitable for general-purpose parsing of +// protobuf binary wire format. It is designed to be used along with +// upb_EpsCopyInputStream for buffering, and all parsing routines in this file +// assume that at least kUpb_EpsCopyInputStream_SlopBytes worth of data is +// available to read without any bounds checks. + +#ifdef __cplusplus +extern "C" { +#endif + // Parses a tag into `tag`, and returns a pointer past the end of the tag, or // NULL if there was an error in the tag data. // @@ -13822,7 +13845,7 @@ static UPB_FORCEINLINE const char* _upb_WireReader_ReadVarint(const char* ptr, static UPB_FORCEINLINE const char* upb_WireReader_ReadTag(const char* ptr, uint32_t* tag) { uint64_t val; - ptr = _upb_WireReader_ReadVarint(ptr, &val, 5, UINT32_MAX); + ptr = UPB_PRIVATE(_upb_WireReader_ReadVarint)(ptr, &val, 5, UINT32_MAX); if (!ptr) return NULL; *tag = val; return ptr; @@ -13830,17 +13853,17 @@ static UPB_FORCEINLINE const char* upb_WireReader_ReadTag(const char* ptr, // Given a tag, returns the field number. UPB_INLINE uint32_t upb_WireReader_GetFieldNumber(uint32_t tag) { - return tag >> kUpb_WireReader_WireTypeBits; + return UPB_PRIVATE(_upb_WireReader_GetFieldNumber)(tag); } // Given a tag, returns the wire type. UPB_INLINE uint8_t upb_WireReader_GetWireType(uint32_t tag) { - return tag & kUpb_WireReader_WireTypeMask; + return UPB_PRIVATE(_upb_WireReader_GetWireType)(tag); } UPB_INLINE const char* upb_WireReader_ReadVarint(const char* ptr, uint64_t* val) { - return _upb_WireReader_ReadVarint(ptr, val, 10, UINT64_MAX); + return UPB_PRIVATE(_upb_WireReader_ReadVarint)(ptr, val, 10, UINT64_MAX); } // Skips data for a varint, returning a pointer past the end of the varint, or @@ -13876,7 +13899,7 @@ UPB_INLINE const char* upb_WireReader_ReadSize(const char* ptr, int* size) { UPB_INLINE const char* upb_WireReader_ReadFixed32(const char* ptr, void* val) { uint32_t uval; memcpy(&uval, ptr, 4); - uval = _upb_BigEndian_Swap32(uval); + uval = UPB_PRIVATE(_upb_BigEndian32)(uval); memcpy(val, &uval, 4); return ptr + 4; } @@ -13889,14 +13912,14 @@ UPB_INLINE const char* upb_WireReader_ReadFixed32(const char* ptr, void* val) { UPB_INLINE const char* upb_WireReader_ReadFixed64(const char* ptr, void* val) { uint64_t uval; memcpy(&uval, ptr, 8); - uval = _upb_BigEndian_Swap64(uval); + uval = UPB_PRIVATE(_upb_BigEndian64)(uval); memcpy(val, &uval, 8); return ptr + 8; } -const char* _upb_WireReader_SkipGroup(const char* ptr, uint32_t tag, - int depth_limit, - upb_EpsCopyInputStream* stream); +const char* UPB_PRIVATE(_upb_WireReader_SkipGroup)( + const char* ptr, uint32_t tag, int depth_limit, + upb_EpsCopyInputStream* stream); // Skips data for a group, returning a pointer past the end of the group, or // NULL if there was an error parsing the group. The `tag` argument should be @@ -13909,7 +13932,7 @@ const char* _upb_WireReader_SkipGroup(const char* ptr, uint32_t tag, // control over this? UPB_INLINE const char* upb_WireReader_SkipGroup( const char* ptr, uint32_t tag, upb_EpsCopyInputStream* stream) { - return _upb_WireReader_SkipGroup(ptr, tag, 100, stream); + return UPB_PRIVATE(_upb_WireReader_SkipGroup)(ptr, tag, 100, stream); } UPB_INLINE const char* _upb_WireReader_SkipValue( @@ -13930,7 +13953,8 @@ UPB_INLINE const char* _upb_WireReader_SkipValue( return ptr; } case kUpb_WireType_StartGroup: - return _upb_WireReader_SkipGroup(ptr, tag, depth_limit, stream); + return UPB_PRIVATE(_upb_WireReader_SkipGroup)(ptr, tag, depth_limit, + stream); case kUpb_WireType_EndGroup: return NULL; // Should be handled before now. default: diff --git a/ruby/ext/google/protobuf_c/ruby-upb.c b/ruby/ext/google/protobuf_c/ruby-upb.c index bcfca4d07e322..27aa17ec2c233 100644 --- a/ruby/ext/google/protobuf_c/ruby-upb.c +++ b/ruby/ext/google/protobuf_c/ruby-upb.c @@ -12487,7 +12487,7 @@ static const char* upb_Decoder_DecodeSize(upb_Decoder* d, const char* ptr, } static void _upb_Decoder_MungeInt32(wireval* val) { - if (!_upb_IsLittleEndian()) { + if (!UPB_PRIVATE(_upb_IsLittleEndian)()) { /* The next stage will memcpy(dst, &val, 4) */ val->uint32_val = val->uint64_val; } @@ -12707,7 +12707,7 @@ static const char* _upb_Decoder_DecodeFixedPacked( arr->UPB_PRIVATE(size) += count; // Note: if/when the decoder supports multi-buffer input, we will need to // handle buffer seams here. - if (_upb_IsLittleEndian()) { + if (UPB_PRIVATE(_upb_IsLittleEndian)()) { ptr = upb_EpsCopyInputStream_Copy(&d->input, ptr, mem, val->size); } else { int delta = upb_EpsCopyInputStream_PushLimit(&d->input, ptr, val->size); @@ -13031,7 +13031,7 @@ const char* _upb_Decoder_CheckRequired(upb_Decoder* d, const char* ptr, } uint64_t msg_head; memcpy(&msg_head, msg, 8); - msg_head = _upb_BigEndian_Swap64(msg_head); + msg_head = UPB_PRIVATE(_upb_BigEndian64)(msg_head); if (UPB_PRIVATE(_upb_MiniTable_RequiredMask)(m) & ~msg_head) { d->missing_required = true; } @@ -13660,1621 +13660,1624 @@ upb_DecodeStatus upb_Decode(const char* buf, size_t size, upb_Message* msg, #undef OP_FIXPCK_LG2 #undef OP_VARPCK_LG2 -// Fast decoder: ~3x the speed of decode.c, but requires x86-64/ARM64. -// Also the table size grows by 2x. -// -// Could potentially be ported to other 64-bit archs that pass at least six -// arguments in registers and have 8 unused high bits in pointers. -// -// The overall design is to create specialized functions for every possible -// field type (eg. oneof boolean field with a 1 byte tag) and then dispatch -// to the specialized function as quickly as possible. +// We encode backwards, to avoid pre-computing lengths (one-pass encode). +#include +#include +#include +#include + // Must be last. -#if UPB_FASTTABLE +#define UPB_PB_VARINT_MAX_LEN 10 -// The standard set of arguments passed to each parsing function. -// Thanks to x86-64 calling conventions, these will stay in registers. -#define UPB_PARSE_PARAMS \ - upb_Decoder *d, const char *ptr, upb_Message *msg, intptr_t table, \ - uint64_t hasbits, uint64_t data +UPB_NOINLINE +static size_t encode_varint64(uint64_t val, char* buf) { + size_t i = 0; + do { + uint8_t byte = val & 0x7fU; + val >>= 7; + if (val) byte |= 0x80U; + buf[i++] = byte; + } while (val); + return i; +} -#define UPB_PARSE_ARGS d, ptr, msg, table, hasbits, data +static uint32_t encode_zz32(int32_t n) { + return ((uint32_t)n << 1) ^ (n >> 31); +} +static uint64_t encode_zz64(int64_t n) { + return ((uint64_t)n << 1) ^ (n >> 63); +} -#define RETURN_GENERIC(m) \ - /* Uncomment either of these for debugging purposes. */ \ - /* fprintf(stderr, m); */ \ - /*__builtin_trap(); */ \ - return _upb_FastDecoder_DecodeGeneric(d, ptr, msg, table, hasbits, 0); +typedef struct { + upb_EncodeStatus status; + jmp_buf err; + upb_Arena* arena; + char *buf, *ptr, *limit; + int options; + int depth; + _upb_mapsorter sorter; +} upb_encstate; -typedef enum { - CARD_s = 0, /* Singular (optional, non-repeated) */ - CARD_o = 1, /* Oneof */ - CARD_r = 2, /* Repeated */ - CARD_p = 3 /* Packed Repeated */ -} upb_card; +static size_t upb_roundup_pow2(size_t bytes) { + size_t ret = 128; + while (ret < bytes) { + ret *= 2; + } + return ret; +} -UPB_NOINLINE -static const char* fastdecode_isdonefallback(UPB_PARSE_PARAMS) { - int overrun = data; - ptr = _upb_EpsCopyInputStream_IsDoneFallbackInline( - &d->input, ptr, overrun, _upb_Decoder_BufferFlipCallback); - data = _upb_FastDecoder_LoadTag(ptr); - UPB_MUSTTAIL return _upb_FastDecoder_TagDispatch(UPB_PARSE_ARGS); +UPB_NORETURN static void encode_err(upb_encstate* e, upb_EncodeStatus s) { + UPB_ASSERT(s != kUpb_EncodeStatus_Ok); + e->status = s; + UPB_LONGJMP(e->err, 1); } -UPB_FORCEINLINE -static const char* fastdecode_dispatch(UPB_PARSE_PARAMS) { - int overrun; - switch (upb_EpsCopyInputStream_IsDoneStatus(&d->input, ptr, &overrun)) { - case kUpb_IsDoneStatus_Done: - *(uint32_t*)msg |= hasbits; // Sync hasbits. - const upb_MiniTable* m = decode_totablep(table); - return UPB_UNLIKELY(m->UPB_PRIVATE(required_count)) - ? _upb_Decoder_CheckRequired(d, ptr, msg, m) - : ptr; - case kUpb_IsDoneStatus_NotDone: - break; - case kUpb_IsDoneStatus_NeedFallback: - data = overrun; - UPB_MUSTTAIL return fastdecode_isdonefallback(UPB_PARSE_ARGS); - } +UPB_NOINLINE +static void encode_growbuffer(upb_encstate* e, size_t bytes) { + size_t old_size = e->limit - e->buf; + size_t new_size = upb_roundup_pow2(bytes + (e->limit - e->ptr)); + char* new_buf = upb_Arena_Realloc(e->arena, e->buf, old_size, new_size); - // Read two bytes of tag data (for a one-byte tag, the high byte is junk). - data = _upb_FastDecoder_LoadTag(ptr); - UPB_MUSTTAIL return _upb_FastDecoder_TagDispatch(UPB_PARSE_ARGS); -} + if (!new_buf) encode_err(e, kUpb_EncodeStatus_OutOfMemory); -UPB_FORCEINLINE -static bool fastdecode_checktag(uint16_t data, int tagbytes) { - if (tagbytes == 1) { - return (data & 0xff) == 0; - } else { - return data == 0; + // We want previous data at the end, realloc() put it at the beginning. + // TODO: This is somewhat inefficient since we are copying twice. + // Maybe create a realloc() that copies to the end of the new buffer? + if (old_size > 0) { + memmove(new_buf + new_size - old_size, e->buf, old_size); } -} -UPB_FORCEINLINE -static const char* fastdecode_longsize(const char* ptr, int* size) { - int i; - UPB_ASSERT(*size & 0x80); - *size &= 0xff; - for (i = 0; i < 3; i++) { - ptr++; - size_t byte = (uint8_t)ptr[-1]; - *size += (byte - 1) << (7 + 7 * i); - if (UPB_LIKELY((byte & 0x80) == 0)) return ptr; - } - ptr++; - size_t byte = (uint8_t)ptr[-1]; - // len is limited by 2gb not 4gb, hence 8 and not 16 as normally expected - // for a 32 bit varint. - if (UPB_UNLIKELY(byte >= 8)) return NULL; - *size += (byte - 1) << 28; - return ptr; + e->ptr = new_buf + new_size - (e->limit - e->ptr); + e->limit = new_buf + new_size; + e->buf = new_buf; + + e->ptr -= bytes; } +/* Call to ensure that at least "bytes" bytes are available for writing at + * e->ptr. Returns false if the bytes could not be allocated. */ UPB_FORCEINLINE -static const char* fastdecode_delimited( - upb_Decoder* d, const char* ptr, - upb_EpsCopyInputStream_ParseDelimitedFunc* func, void* ctx) { - ptr++; - - // Sign-extend so varint greater than one byte becomes negative, causing - // fast delimited parse to fail. - int len = (int8_t)ptr[-1]; - - if (!upb_EpsCopyInputStream_TryParseDelimitedFast(&d->input, &ptr, len, func, - ctx)) { - // Slow case: Sub-message is >=128 bytes and/or exceeds the current buffer. - // If it exceeds the buffer limit, limit/limit_ptr will change during - // sub-message parsing, so we need to preserve delta, not limit. - if (UPB_UNLIKELY(len & 0x80)) { - // Size varint >1 byte (length >= 128). - ptr = fastdecode_longsize(ptr, &len); - if (!ptr) { - // Corrupt wire format: size exceeded INT_MAX. - return NULL; - } - } - if (!upb_EpsCopyInputStream_CheckSize(&d->input, ptr, len)) { - // Corrupt wire format: invalid limit. - return NULL; - } - int delta = upb_EpsCopyInputStream_PushLimit(&d->input, ptr, len); - ptr = func(&d->input, ptr, ctx); - upb_EpsCopyInputStream_PopLimit(&d->input, ptr, delta); +static void encode_reserve(upb_encstate* e, size_t bytes) { + if ((size_t)(e->ptr - e->buf) < bytes) { + encode_growbuffer(e, bytes); + return; } - return ptr; + + e->ptr -= bytes; } -/* singular, oneof, repeated field handling ***********************************/ +/* Writes the given bytes to the buffer, handling reserve/advance. */ +static void encode_bytes(upb_encstate* e, const void* data, size_t len) { + if (len == 0) return; /* memcpy() with zero size is UB */ + encode_reserve(e, len); + memcpy(e->ptr, data, len); +} -typedef struct { - upb_Array* arr; - void* end; -} fastdecode_arr; +static void encode_fixed64(upb_encstate* e, uint64_t val) { + val = UPB_PRIVATE(_upb_BigEndian64)(val); + encode_bytes(e, &val, sizeof(uint64_t)); +} -typedef enum { - FD_NEXT_ATLIMIT, - FD_NEXT_SAMEFIELD, - FD_NEXT_OTHERFIELD -} fastdecode_next; +static void encode_fixed32(upb_encstate* e, uint32_t val) { + val = UPB_PRIVATE(_upb_BigEndian32)(val); + encode_bytes(e, &val, sizeof(uint32_t)); +} -typedef struct { - void* dst; - fastdecode_next next; - uint32_t tag; -} fastdecode_nextret; +UPB_NOINLINE +static void encode_longvarint(upb_encstate* e, uint64_t val) { + size_t len; + char* start; -UPB_FORCEINLINE -static void* fastdecode_resizearr(upb_Decoder* d, void* dst, - fastdecode_arr* farr, int valbytes) { - if (UPB_UNLIKELY(dst == farr->end)) { - size_t old_capacity = farr->arr->UPB_PRIVATE(capacity); - size_t old_bytes = old_capacity * valbytes; - size_t new_capacity = old_capacity * 2; - size_t new_bytes = new_capacity * valbytes; - char* old_ptr = _upb_array_ptr(farr->arr); - char* new_ptr = upb_Arena_Realloc(&d->arena, old_ptr, old_bytes, new_bytes); - uint8_t elem_size_lg2 = __builtin_ctz(valbytes); - UPB_PRIVATE(_upb_Array_SetTaggedPtr)(farr->arr, new_ptr, elem_size_lg2); - farr->arr->UPB_PRIVATE(capacity) = new_capacity; - dst = (void*)(new_ptr + (old_capacity * valbytes)); - farr->end = (void*)(new_ptr + (new_capacity * valbytes)); - } - return dst; + encode_reserve(e, UPB_PB_VARINT_MAX_LEN); + len = encode_varint64(val, e->ptr); + start = e->ptr + UPB_PB_VARINT_MAX_LEN - len; + memmove(start, e->ptr, len); + e->ptr = start; } UPB_FORCEINLINE -static bool fastdecode_tagmatch(uint32_t tag, uint64_t data, int tagbytes) { - if (tagbytes == 1) { - return (uint8_t)tag == (uint8_t)data; +static void encode_varint(upb_encstate* e, uint64_t val) { + if (val < 128 && e->ptr != e->buf) { + --e->ptr; + *e->ptr = val; } else { - return (uint16_t)tag == (uint16_t)data; + encode_longvarint(e, val); } } -UPB_FORCEINLINE -static void fastdecode_commitarr(void* dst, fastdecode_arr* farr, - int valbytes) { - farr->arr->UPB_PRIVATE(size) = - (size_t)((char*)dst - (char*)_upb_array_ptr(farr->arr)) / valbytes; +static void encode_double(upb_encstate* e, double d) { + uint64_t u64; + UPB_ASSERT(sizeof(double) == sizeof(uint64_t)); + memcpy(&u64, &d, sizeof(uint64_t)); + encode_fixed64(e, u64); } -UPB_FORCEINLINE -static fastdecode_nextret fastdecode_nextrepeated(upb_Decoder* d, void* dst, - const char** ptr, - fastdecode_arr* farr, - uint64_t data, int tagbytes, - int valbytes) { - fastdecode_nextret ret; - dst = (char*)dst + valbytes; +static void encode_float(upb_encstate* e, float d) { + uint32_t u32; + UPB_ASSERT(sizeof(float) == sizeof(uint32_t)); + memcpy(&u32, &d, sizeof(uint32_t)); + encode_fixed32(e, u32); +} - if (UPB_LIKELY(!_upb_Decoder_IsDone(d, ptr))) { - ret.tag = _upb_FastDecoder_LoadTag(*ptr); - if (fastdecode_tagmatch(ret.tag, data, tagbytes)) { - ret.next = FD_NEXT_SAMEFIELD; - } else { - fastdecode_commitarr(dst, farr, valbytes); - ret.next = FD_NEXT_OTHERFIELD; +static void encode_tag(upb_encstate* e, uint32_t field_number, + uint8_t wire_type) { + encode_varint(e, (field_number << 3) | wire_type); +} + +static void encode_fixedarray(upb_encstate* e, const upb_Array* arr, + size_t elem_size, uint32_t tag) { + size_t bytes = arr->UPB_PRIVATE(size) * elem_size; + const char* data = _upb_array_constptr(arr); + const char* ptr = data + bytes - elem_size; + + if (tag || !UPB_PRIVATE(_upb_IsLittleEndian)()) { + while (true) { + if (elem_size == 4) { + uint32_t val; + memcpy(&val, ptr, sizeof(val)); + val = UPB_PRIVATE(_upb_BigEndian32)(val); + encode_bytes(e, &val, elem_size); + } else { + UPB_ASSERT(elem_size == 8); + uint64_t val; + memcpy(&val, ptr, sizeof(val)); + val = UPB_PRIVATE(_upb_BigEndian64)(val); + encode_bytes(e, &val, elem_size); + } + + if (tag) encode_varint(e, tag); + if (ptr == data) break; + ptr -= elem_size; } } else { - fastdecode_commitarr(dst, farr, valbytes); - ret.next = FD_NEXT_ATLIMIT; + encode_bytes(e, data, bytes); } - - ret.dst = dst; - return ret; } -UPB_FORCEINLINE -static void* fastdecode_fieldmem(upb_Message* msg, uint64_t data) { - size_t ofs = data >> 48; - return (char*)msg + ofs; +static void encode_message(upb_encstate* e, const upb_Message* msg, + const upb_MiniTable* m, size_t* size); + +static void encode_TaggedMessagePtr(upb_encstate* e, + upb_TaggedMessagePtr tagged, + const upb_MiniTable* m, size_t* size) { + if (upb_TaggedMessagePtr_IsEmpty(tagged)) { + m = UPB_PRIVATE(_upb_MiniTable_Empty)(); + } + encode_message(e, _upb_TaggedMessagePtr_GetMessage(tagged), m, size); } -UPB_FORCEINLINE -static void* fastdecode_getfield(upb_Decoder* d, const char* ptr, - upb_Message* msg, uint64_t* data, - uint64_t* hasbits, fastdecode_arr* farr, - int valbytes, upb_card card) { - switch (card) { - case CARD_s: { - uint8_t hasbit_index = *data >> 24; - // Set hasbit and return pointer to scalar field. - *hasbits |= 1ull << hasbit_index; - return fastdecode_fieldmem(msg, *data); +static void encode_scalar(upb_encstate* e, const void* _field_mem, + const upb_MiniTableSub* subs, + const upb_MiniTableField* f) { + const char* field_mem = _field_mem; + int wire_type; + +#define CASE(ctype, type, wtype, encodeval) \ + { \ + ctype val = *(ctype*)field_mem; \ + encode_##type(e, encodeval); \ + wire_type = wtype; \ + break; \ + } + + switch (f->UPB_PRIVATE(descriptortype)) { + case kUpb_FieldType_Double: + CASE(double, double, kUpb_WireType_64Bit, val); + case kUpb_FieldType_Float: + CASE(float, float, kUpb_WireType_32Bit, val); + case kUpb_FieldType_Int64: + case kUpb_FieldType_UInt64: + CASE(uint64_t, varint, kUpb_WireType_Varint, val); + case kUpb_FieldType_UInt32: + CASE(uint32_t, varint, kUpb_WireType_Varint, val); + case kUpb_FieldType_Int32: + case kUpb_FieldType_Enum: + CASE(int32_t, varint, kUpb_WireType_Varint, (int64_t)val); + case kUpb_FieldType_SFixed64: + case kUpb_FieldType_Fixed64: + CASE(uint64_t, fixed64, kUpb_WireType_64Bit, val); + case kUpb_FieldType_Fixed32: + case kUpb_FieldType_SFixed32: + CASE(uint32_t, fixed32, kUpb_WireType_32Bit, val); + case kUpb_FieldType_Bool: + CASE(bool, varint, kUpb_WireType_Varint, val); + case kUpb_FieldType_SInt32: + CASE(int32_t, varint, kUpb_WireType_Varint, encode_zz32(val)); + case kUpb_FieldType_SInt64: + CASE(int64_t, varint, kUpb_WireType_Varint, encode_zz64(val)); + case kUpb_FieldType_String: + case kUpb_FieldType_Bytes: { + upb_StringView view = *(upb_StringView*)field_mem; + encode_bytes(e, view.data, view.size); + encode_varint(e, view.size); + wire_type = kUpb_WireType_Delimited; + break; } - case CARD_o: { - uint16_t case_ofs = *data >> 32; - uint32_t* oneof_case = UPB_PTR_AT(msg, case_ofs, uint32_t); - uint8_t field_number = *data >> 24; - *oneof_case = field_number; - return fastdecode_fieldmem(msg, *data); + case kUpb_FieldType_Group: { + size_t size; + upb_TaggedMessagePtr submsg = *(upb_TaggedMessagePtr*)field_mem; + const upb_MiniTable* subm = + upb_MiniTableSub_Message(subs[f->UPB_PRIVATE(submsg_index)]); + if (submsg == 0) { + return; + } + if (--e->depth == 0) encode_err(e, kUpb_EncodeStatus_MaxDepthExceeded); + encode_tag(e, f->UPB_PRIVATE(number), kUpb_WireType_EndGroup); + encode_TaggedMessagePtr(e, submsg, subm, &size); + wire_type = kUpb_WireType_StartGroup; + e->depth++; + break; } - case CARD_r: { - // Get pointer to upb_Array and allocate/expand if necessary. - uint8_t elem_size_lg2 = __builtin_ctz(valbytes); - upb_Array** arr_p = fastdecode_fieldmem(msg, *data); - char* begin; - *(uint32_t*)msg |= *hasbits; - *hasbits = 0; - if (UPB_LIKELY(!*arr_p)) { - farr->arr = UPB_PRIVATE(_upb_Array_New)(&d->arena, 8, elem_size_lg2); - *arr_p = farr->arr; - } else { - farr->arr = *arr_p; + case kUpb_FieldType_Message: { + size_t size; + upb_TaggedMessagePtr submsg = *(upb_TaggedMessagePtr*)field_mem; + const upb_MiniTable* subm = + upb_MiniTableSub_Message(subs[f->UPB_PRIVATE(submsg_index)]); + if (submsg == 0) { + return; } - begin = _upb_array_ptr(farr->arr); - farr->end = begin + (farr->arr->UPB_PRIVATE(capacity) * valbytes); - *data = _upb_FastDecoder_LoadTag(ptr); - return begin + (farr->arr->UPB_PRIVATE(size) * valbytes); + if (--e->depth == 0) encode_err(e, kUpb_EncodeStatus_MaxDepthExceeded); + encode_TaggedMessagePtr(e, submsg, subm, &size); + encode_varint(e, size); + wire_type = kUpb_WireType_Delimited; + e->depth++; + break; } default: UPB_UNREACHABLE(); } -} +#undef CASE -UPB_FORCEINLINE -static bool fastdecode_flippacked(uint64_t* data, int tagbytes) { - *data ^= (0x2 ^ 0x0); // Patch data to match packed wiretype. - return fastdecode_checktag(*data, tagbytes); + encode_tag(e, f->UPB_PRIVATE(number), wire_type); } -#define FASTDECODE_CHECKPACKED(tagbytes, card, func) \ - if (UPB_UNLIKELY(!fastdecode_checktag(data, tagbytes))) { \ - if (card == CARD_r && fastdecode_flippacked(&data, tagbytes)) { \ - UPB_MUSTTAIL return func(UPB_PARSE_ARGS); \ - } \ - RETURN_GENERIC("packed check tag mismatch\n"); \ - } - -/* varint fields **************************************************************/ +static void encode_array(upb_encstate* e, const upb_Message* msg, + const upb_MiniTableSub* subs, + const upb_MiniTableField* f) { + const upb_Array* arr = *UPB_PTR_AT(msg, f->UPB_PRIVATE(offset), upb_Array*); + bool packed = upb_MiniTableField_IsPacked(f); + size_t pre_len = e->limit - e->ptr; -UPB_FORCEINLINE -static uint64_t fastdecode_munge(uint64_t val, int valbytes, bool zigzag) { - if (valbytes == 1) { - return val != 0; - } else if (zigzag) { - if (valbytes == 4) { - uint32_t n = val; - return (n >> 1) ^ -(int32_t)(n & 1); - } else if (valbytes == 8) { - return (val >> 1) ^ -(int64_t)(val & 1); - } - UPB_UNREACHABLE(); + if (arr == NULL || arr->UPB_PRIVATE(size) == 0) { + return; } - return val; -} -UPB_FORCEINLINE -static const char* fastdecode_varint64(const char* ptr, uint64_t* val) { - ptr++; - *val = (uint8_t)ptr[-1]; - if (UPB_UNLIKELY(*val & 0x80)) { - int i; - for (i = 0; i < 8; i++) { - ptr++; - uint64_t byte = (uint8_t)ptr[-1]; - *val += (byte - 1) << (7 + 7 * i); - if (UPB_LIKELY((byte & 0x80) == 0)) goto done; - } - ptr++; - uint64_t byte = (uint8_t)ptr[-1]; - if (byte > 1) { - return NULL; - } - *val += (byte - 1) << 63; - } -done: - UPB_ASSUME(ptr != NULL); - return ptr; -} +#define VARINT_CASE(ctype, encode) \ + { \ + const ctype* start = _upb_array_constptr(arr); \ + const ctype* ptr = start + arr->UPB_PRIVATE(size); \ + uint32_t tag = \ + packed ? 0 : (f->UPB_PRIVATE(number) << 3) | kUpb_WireType_Varint; \ + do { \ + ptr--; \ + encode_varint(e, encode); \ + if (tag) encode_varint(e, tag); \ + } while (ptr != start); \ + } \ + break; -#define FASTDECODE_UNPACKEDVARINT(d, ptr, msg, table, hasbits, data, tagbytes, \ - valbytes, card, zigzag, packed) \ - uint64_t val; \ - void* dst; \ - fastdecode_arr farr; \ - \ - FASTDECODE_CHECKPACKED(tagbytes, card, packed); \ - \ - dst = fastdecode_getfield(d, ptr, msg, &data, &hasbits, &farr, valbytes, \ - card); \ - if (card == CARD_r) { \ - if (UPB_UNLIKELY(!dst)) { \ - RETURN_GENERIC("need array resize\n"); \ - } \ - } \ - \ - again: \ - if (card == CARD_r) { \ - dst = fastdecode_resizearr(d, dst, &farr, valbytes); \ - } \ - \ - ptr += tagbytes; \ - ptr = fastdecode_varint64(ptr, &val); \ - if (ptr == NULL) _upb_FastDecoder_ErrorJmp(d, kUpb_DecodeStatus_Malformed); \ - val = fastdecode_munge(val, valbytes, zigzag); \ - memcpy(dst, &val, valbytes); \ - \ - if (card == CARD_r) { \ - fastdecode_nextret ret = fastdecode_nextrepeated( \ - d, dst, &ptr, &farr, data, tagbytes, valbytes); \ - switch (ret.next) { \ - case FD_NEXT_SAMEFIELD: \ - dst = ret.dst; \ - goto again; \ - case FD_NEXT_OTHERFIELD: \ - data = ret.tag; \ - UPB_MUSTTAIL return _upb_FastDecoder_TagDispatch(UPB_PARSE_ARGS); \ - case FD_NEXT_ATLIMIT: \ - return ptr; \ - } \ - } \ - \ - UPB_MUSTTAIL return fastdecode_dispatch(UPB_PARSE_ARGS); - -typedef struct { - uint8_t valbytes; - bool zigzag; - void* dst; - fastdecode_arr farr; -} fastdecode_varintdata; - -UPB_FORCEINLINE -static const char* fastdecode_topackedvarint(upb_EpsCopyInputStream* e, - const char* ptr, void* ctx) { - upb_Decoder* d = (upb_Decoder*)e; - fastdecode_varintdata* data = ctx; - void* dst = data->dst; - uint64_t val; +#define TAG(wire_type) (packed ? 0 : (f->UPB_PRIVATE(number) << 3 | wire_type)) - while (!_upb_Decoder_IsDone(d, &ptr)) { - dst = fastdecode_resizearr(d, dst, &data->farr, data->valbytes); - ptr = fastdecode_varint64(ptr, &val); - if (ptr == NULL) return NULL; - val = fastdecode_munge(val, data->valbytes, data->zigzag); - memcpy(dst, &val, data->valbytes); - dst = (char*)dst + data->valbytes; + switch (f->UPB_PRIVATE(descriptortype)) { + case kUpb_FieldType_Double: + encode_fixedarray(e, arr, sizeof(double), TAG(kUpb_WireType_64Bit)); + break; + case kUpb_FieldType_Float: + encode_fixedarray(e, arr, sizeof(float), TAG(kUpb_WireType_32Bit)); + break; + case kUpb_FieldType_SFixed64: + case kUpb_FieldType_Fixed64: + encode_fixedarray(e, arr, sizeof(uint64_t), TAG(kUpb_WireType_64Bit)); + break; + case kUpb_FieldType_Fixed32: + case kUpb_FieldType_SFixed32: + encode_fixedarray(e, arr, sizeof(uint32_t), TAG(kUpb_WireType_32Bit)); + break; + case kUpb_FieldType_Int64: + case kUpb_FieldType_UInt64: + VARINT_CASE(uint64_t, *ptr); + case kUpb_FieldType_UInt32: + VARINT_CASE(uint32_t, *ptr); + case kUpb_FieldType_Int32: + case kUpb_FieldType_Enum: + VARINT_CASE(int32_t, (int64_t)*ptr); + case kUpb_FieldType_Bool: + VARINT_CASE(bool, *ptr); + case kUpb_FieldType_SInt32: + VARINT_CASE(int32_t, encode_zz32(*ptr)); + case kUpb_FieldType_SInt64: + VARINT_CASE(int64_t, encode_zz64(*ptr)); + case kUpb_FieldType_String: + case kUpb_FieldType_Bytes: { + const upb_StringView* start = _upb_array_constptr(arr); + const upb_StringView* ptr = start + arr->UPB_PRIVATE(size); + do { + ptr--; + encode_bytes(e, ptr->data, ptr->size); + encode_varint(e, ptr->size); + encode_tag(e, f->UPB_PRIVATE(number), kUpb_WireType_Delimited); + } while (ptr != start); + return; + } + case kUpb_FieldType_Group: { + const upb_TaggedMessagePtr* start = _upb_array_constptr(arr); + const upb_TaggedMessagePtr* ptr = start + arr->UPB_PRIVATE(size); + const upb_MiniTable* subm = + upb_MiniTableSub_Message(subs[f->UPB_PRIVATE(submsg_index)]); + if (--e->depth == 0) encode_err(e, kUpb_EncodeStatus_MaxDepthExceeded); + do { + size_t size; + ptr--; + encode_tag(e, f->UPB_PRIVATE(number), kUpb_WireType_EndGroup); + encode_TaggedMessagePtr(e, *ptr, subm, &size); + encode_tag(e, f->UPB_PRIVATE(number), kUpb_WireType_StartGroup); + } while (ptr != start); + e->depth++; + return; + } + case kUpb_FieldType_Message: { + const upb_TaggedMessagePtr* start = _upb_array_constptr(arr); + const upb_TaggedMessagePtr* ptr = start + arr->UPB_PRIVATE(size); + const upb_MiniTable* subm = + upb_MiniTableSub_Message(subs[f->UPB_PRIVATE(submsg_index)]); + if (--e->depth == 0) encode_err(e, kUpb_EncodeStatus_MaxDepthExceeded); + do { + size_t size; + ptr--; + encode_TaggedMessagePtr(e, *ptr, subm, &size); + encode_varint(e, size); + encode_tag(e, f->UPB_PRIVATE(number), kUpb_WireType_Delimited); + } while (ptr != start); + e->depth++; + return; + } } +#undef VARINT_CASE - fastdecode_commitarr(dst, &data->farr, data->valbytes); - return ptr; + if (packed) { + encode_varint(e, e->limit - e->ptr - pre_len); + encode_tag(e, f->UPB_PRIVATE(number), kUpb_WireType_Delimited); + } } -#define FASTDECODE_PACKEDVARINT(d, ptr, msg, table, hasbits, data, tagbytes, \ - valbytes, zigzag, unpacked) \ - fastdecode_varintdata ctx = {valbytes, zigzag}; \ - \ - FASTDECODE_CHECKPACKED(tagbytes, CARD_r, unpacked); \ - \ - ctx.dst = fastdecode_getfield(d, ptr, msg, &data, &hasbits, &ctx.farr, \ - valbytes, CARD_r); \ - if (UPB_UNLIKELY(!ctx.dst)) { \ - RETURN_GENERIC("need array resize\n"); \ - } \ - \ - ptr += tagbytes; \ - ptr = fastdecode_delimited(d, ptr, &fastdecode_topackedvarint, &ctx); \ - \ - if (UPB_UNLIKELY(ptr == NULL)) { \ - _upb_FastDecoder_ErrorJmp(d, kUpb_DecodeStatus_Malformed); \ - } \ - \ - UPB_MUSTTAIL return fastdecode_dispatch(d, ptr, msg, table, hasbits, 0); +static void encode_mapentry(upb_encstate* e, uint32_t number, + const upb_MiniTable* layout, + const upb_MapEntry* ent) { + const upb_MiniTableField* key_field = &layout->UPB_PRIVATE(fields)[0]; + const upb_MiniTableField* val_field = &layout->UPB_PRIVATE(fields)[1]; + size_t pre_len = e->limit - e->ptr; + size_t size; + encode_scalar(e, &ent->data.v, layout->UPB_PRIVATE(subs), val_field); + encode_scalar(e, &ent->data.k, layout->UPB_PRIVATE(subs), key_field); + size = (e->limit - e->ptr) - pre_len; + encode_varint(e, size); + encode_tag(e, number, kUpb_WireType_Delimited); +} -#define FASTDECODE_VARINT(d, ptr, msg, table, hasbits, data, tagbytes, \ - valbytes, card, zigzag, unpacked, packed) \ - if (card == CARD_p) { \ - FASTDECODE_PACKEDVARINT(d, ptr, msg, table, hasbits, data, tagbytes, \ - valbytes, zigzag, unpacked); \ - } else { \ - FASTDECODE_UNPACKEDVARINT(d, ptr, msg, table, hasbits, data, tagbytes, \ - valbytes, card, zigzag, packed); \ - } +static void encode_map(upb_encstate* e, const upb_Message* msg, + const upb_MiniTableSub* subs, + const upb_MiniTableField* f) { + const upb_Map* map = *UPB_PTR_AT(msg, f->UPB_PRIVATE(offset), const upb_Map*); + const upb_MiniTable* layout = + upb_MiniTableSub_Message(subs[f->UPB_PRIVATE(submsg_index)]); + UPB_ASSERT(layout->UPB_PRIVATE(field_count) == 2); -#define z_ZZ true -#define b_ZZ false -#define v_ZZ false + if (map == NULL) return; -/* Generate all combinations: - * {s,o,r,p} x {b1,v4,z4,v8,z8} x {1bt,2bt} */ + if (e->options & kUpb_EncodeOption_Deterministic) { + _upb_sortedmap sorted; + _upb_mapsorter_pushmap( + &e->sorter, layout->UPB_PRIVATE(fields)[0].UPB_PRIVATE(descriptortype), + map, &sorted); + upb_MapEntry ent; + while (_upb_sortedmap_next(&e->sorter, map, &sorted, &ent)) { + encode_mapentry(e, f->UPB_PRIVATE(number), layout, &ent); + } + _upb_mapsorter_popmap(&e->sorter, &sorted); + } else { + intptr_t iter = UPB_STRTABLE_BEGIN; + upb_StringView key; + upb_value val; + while (upb_strtable_next2(&map->table, &key, &val, &iter)) { + upb_MapEntry ent; + _upb_map_fromkey(key, &ent.data.k, map->key_size); + _upb_map_fromvalue(val, &ent.data.v, map->val_size); + encode_mapentry(e, f->UPB_PRIVATE(number), layout, &ent); + } + } +} -#define F(card, type, valbytes, tagbytes) \ - UPB_NOINLINE \ - const char* upb_p##card##type##valbytes##_##tagbytes##bt(UPB_PARSE_PARAMS) { \ - FASTDECODE_VARINT(d, ptr, msg, table, hasbits, data, tagbytes, valbytes, \ - CARD_##card, type##_ZZ, \ - upb_pr##type##valbytes##_##tagbytes##bt, \ - upb_pp##type##valbytes##_##tagbytes##bt); \ +static bool encode_shouldencode(upb_encstate* e, const upb_Message* msg, + const upb_MiniTableSub* subs, + const upb_MiniTableField* f) { + if (f->presence == 0) { + // Proto3 presence or map/array. + const void* mem = UPB_PTR_AT(msg, f->UPB_PRIVATE(offset), void); + switch (UPB_PRIVATE(_upb_MiniTableField_GetRep)(f)) { + case kUpb_FieldRep_1Byte: { + char ch; + memcpy(&ch, mem, 1); + return ch != 0; + } + case kUpb_FieldRep_4Byte: { + uint32_t u32; + memcpy(&u32, mem, 4); + return u32 != 0; + } + case kUpb_FieldRep_8Byte: { + uint64_t u64; + memcpy(&u64, mem, 8); + return u64 != 0; + } + case kUpb_FieldRep_StringView: { + const upb_StringView* str = (const upb_StringView*)mem; + return str->size != 0; + } + default: + UPB_UNREACHABLE(); + } + } else if (f->presence > 0) { + // Proto2 presence: hasbit. + return UPB_PRIVATE(_upb_Message_GetHasbit)(msg, f); + } else { + // Field is in a oneof. + return UPB_PRIVATE(_upb_Message_GetOneofCase)(msg, f) == + f->UPB_PRIVATE(number); } +} -#define TYPES(card, tagbytes) \ - F(card, b, 1, tagbytes) \ - F(card, v, 4, tagbytes) \ - F(card, v, 8, tagbytes) \ - F(card, z, 4, tagbytes) \ - F(card, z, 8, tagbytes) - -#define TAGBYTES(card) \ - TYPES(card, 1) \ - TYPES(card, 2) +static void encode_field(upb_encstate* e, const upb_Message* msg, + const upb_MiniTableSub* subs, + const upb_MiniTableField* field) { + switch (UPB_PRIVATE(_upb_MiniTableField_Mode)(field)) { + case kUpb_FieldMode_Array: + encode_array(e, msg, subs, field); + break; + case kUpb_FieldMode_Map: + encode_map(e, msg, subs, field); + break; + case kUpb_FieldMode_Scalar: + encode_scalar(e, UPB_PTR_AT(msg, field->UPB_PRIVATE(offset), void), subs, + field); + break; + default: + UPB_UNREACHABLE(); + } +} -TAGBYTES(s) -TAGBYTES(o) -TAGBYTES(r) -TAGBYTES(p) +static void encode_msgset_item(upb_encstate* e, const upb_Extension* ext) { + size_t size; + encode_tag(e, kUpb_MsgSet_Item, kUpb_WireType_EndGroup); + encode_message(e, ext->data.ptr, + upb_MiniTableExtension_GetSubMessage(ext->ext), &size); + encode_varint(e, size); + encode_tag(e, kUpb_MsgSet_Message, kUpb_WireType_Delimited); + encode_varint(e, upb_MiniTableExtension_Number(ext->ext)); + encode_tag(e, kUpb_MsgSet_TypeId, kUpb_WireType_Varint); + encode_tag(e, kUpb_MsgSet_Item, kUpb_WireType_StartGroup); +} -#undef z_ZZ -#undef b_ZZ -#undef v_ZZ -#undef o_ONEOF -#undef s_ONEOF -#undef r_ONEOF -#undef F -#undef TYPES -#undef TAGBYTES -#undef FASTDECODE_UNPACKEDVARINT -#undef FASTDECODE_PACKEDVARINT -#undef FASTDECODE_VARINT +static void encode_ext(upb_encstate* e, const upb_Extension* ext, + bool is_message_set) { + if (UPB_UNLIKELY(is_message_set)) { + encode_msgset_item(e, ext); + } else { + encode_field(e, (upb_Message*)&ext->data, &ext->ext->UPB_PRIVATE(sub), + &ext->ext->UPB_PRIVATE(field)); + } +} -/* fixed fields ***************************************************************/ +static void encode_message(upb_encstate* e, const upb_Message* msg, + const upb_MiniTable* m, size_t* size) { + size_t pre_len = e->limit - e->ptr; -#define FASTDECODE_UNPACKEDFIXED(d, ptr, msg, table, hasbits, data, tagbytes, \ - valbytes, card, packed) \ - void* dst; \ - fastdecode_arr farr; \ - \ - FASTDECODE_CHECKPACKED(tagbytes, card, packed) \ - \ - dst = fastdecode_getfield(d, ptr, msg, &data, &hasbits, &farr, valbytes, \ - card); \ - if (card == CARD_r) { \ - if (UPB_UNLIKELY(!dst)) { \ - RETURN_GENERIC("couldn't allocate array in arena\n"); \ - } \ - } \ - \ - again: \ - if (card == CARD_r) { \ - dst = fastdecode_resizearr(d, dst, &farr, valbytes); \ - } \ - \ - ptr += tagbytes; \ - memcpy(dst, ptr, valbytes); \ - ptr += valbytes; \ - \ - if (card == CARD_r) { \ - fastdecode_nextret ret = fastdecode_nextrepeated( \ - d, dst, &ptr, &farr, data, tagbytes, valbytes); \ - switch (ret.next) { \ - case FD_NEXT_SAMEFIELD: \ - dst = ret.dst; \ - goto again; \ - case FD_NEXT_OTHERFIELD: \ - data = ret.tag; \ - UPB_MUSTTAIL return _upb_FastDecoder_TagDispatch(UPB_PARSE_ARGS); \ - case FD_NEXT_ATLIMIT: \ - return ptr; \ - } \ - } \ - \ - UPB_MUSTTAIL return fastdecode_dispatch(UPB_PARSE_ARGS); + if ((e->options & kUpb_EncodeOption_CheckRequired) && + m->UPB_PRIVATE(required_count)) { + uint64_t msg_head; + memcpy(&msg_head, msg, 8); + msg_head = UPB_PRIVATE(_upb_BigEndian64)(msg_head); + if (UPB_PRIVATE(_upb_MiniTable_RequiredMask)(m) & ~msg_head) { + encode_err(e, kUpb_EncodeStatus_MissingRequired); + } + } -#define FASTDECODE_PACKEDFIXED(d, ptr, msg, table, hasbits, data, tagbytes, \ - valbytes, unpacked) \ - FASTDECODE_CHECKPACKED(tagbytes, CARD_r, unpacked) \ - \ - ptr += tagbytes; \ - int size = (uint8_t)ptr[0]; \ - ptr++; \ - if (size & 0x80) { \ - ptr = fastdecode_longsize(ptr, &size); \ - } \ - \ - if (UPB_UNLIKELY(!upb_EpsCopyInputStream_CheckDataSizeAvailable( \ - &d->input, ptr, size) || \ - (size % valbytes) != 0)) { \ - _upb_FastDecoder_ErrorJmp(d, kUpb_DecodeStatus_Malformed); \ - } \ - \ - upb_Array** arr_p = fastdecode_fieldmem(msg, data); \ - upb_Array* arr = *arr_p; \ - uint8_t elem_size_lg2 = __builtin_ctz(valbytes); \ - int elems = size / valbytes; \ - \ - if (UPB_LIKELY(!arr)) { \ - *arr_p = arr = \ - UPB_PRIVATE(_upb_Array_New)(&d->arena, elems, elem_size_lg2); \ - if (!arr) { \ - _upb_FastDecoder_ErrorJmp(d, kUpb_DecodeStatus_Malformed); \ - } \ - } else { \ - _upb_Array_ResizeUninitialized(arr, elems, &d->arena); \ - } \ - \ - char* dst = _upb_array_ptr(arr); \ - memcpy(dst, ptr, size); \ - arr->UPB_PRIVATE(size) = elems; \ - \ - ptr += size; \ - UPB_MUSTTAIL return fastdecode_dispatch(UPB_PARSE_ARGS); + if ((e->options & kUpb_EncodeOption_SkipUnknown) == 0) { + size_t unknown_size; + const char* unknown = upb_Message_GetUnknown(msg, &unknown_size); -#define FASTDECODE_FIXED(d, ptr, msg, table, hasbits, data, tagbytes, \ - valbytes, card, unpacked, packed) \ - if (card == CARD_p) { \ - FASTDECODE_PACKEDFIXED(d, ptr, msg, table, hasbits, data, tagbytes, \ - valbytes, unpacked); \ - } else { \ - FASTDECODE_UNPACKEDFIXED(d, ptr, msg, table, hasbits, data, tagbytes, \ - valbytes, card, packed); \ + if (unknown) { + encode_bytes(e, unknown, unknown_size); + } } -/* Generate all combinations: - * {s,o,r,p} x {f4,f8} x {1bt,2bt} */ - -#define F(card, valbytes, tagbytes) \ - UPB_NOINLINE \ - const char* upb_p##card##f##valbytes##_##tagbytes##bt(UPB_PARSE_PARAMS) { \ - FASTDECODE_FIXED(d, ptr, msg, table, hasbits, data, tagbytes, valbytes, \ - CARD_##card, upb_ppf##valbytes##_##tagbytes##bt, \ - upb_prf##valbytes##_##tagbytes##bt); \ + if (m->UPB_PRIVATE(ext) != kUpb_ExtMode_NonExtendable) { + /* Encode all extensions together. Unlike C++, we do not attempt to keep + * these in field number order relative to normal fields or even to each + * other. */ + size_t ext_count; + const upb_Extension* ext = + UPB_PRIVATE(_upb_Message_Getexts)(msg, &ext_count); + if (ext_count) { + if (e->options & kUpb_EncodeOption_Deterministic) { + _upb_sortedmap sorted; + _upb_mapsorter_pushexts(&e->sorter, ext, ext_count, &sorted); + while (_upb_sortedmap_nextext(&e->sorter, &sorted, &ext)) { + encode_ext(e, ext, m->UPB_PRIVATE(ext) == kUpb_ExtMode_IsMessageSet); + } + _upb_mapsorter_popmap(&e->sorter, &sorted); + } else { + const upb_Extension* end = ext + ext_count; + for (; ext != end; ext++) { + encode_ext(e, ext, m->UPB_PRIVATE(ext) == kUpb_ExtMode_IsMessageSet); + } + } + } } -#define TYPES(card, tagbytes) \ - F(card, 4, tagbytes) \ - F(card, 8, tagbytes) + if (m->UPB_PRIVATE(field_count)) { + const upb_MiniTableField* f = + &m->UPB_PRIVATE(fields)[m->UPB_PRIVATE(field_count)]; + const upb_MiniTableField* first = &m->UPB_PRIVATE(fields)[0]; + while (f != first) { + f--; + if (encode_shouldencode(e, msg, m->UPB_PRIVATE(subs), f)) { + encode_field(e, msg, m->UPB_PRIVATE(subs), f); + } + } + } -#define TAGBYTES(card) \ - TYPES(card, 1) \ - TYPES(card, 2) + *size = (e->limit - e->ptr) - pre_len; +} -TAGBYTES(s) -TAGBYTES(o) -TAGBYTES(r) -TAGBYTES(p) +static upb_EncodeStatus upb_Encoder_Encode(upb_encstate* const encoder, + const upb_Message* const msg, + const upb_MiniTable* const l, + char** const buf, + size_t* const size) { + // Unfortunately we must continue to perform hackery here because there are + // code paths which blindly copy the returned pointer without bothering to + // check for errors until much later (b/235839510). So we still set *buf to + // NULL on error and we still set it to non-NULL on a successful empty result. + if (UPB_SETJMP(encoder->err) == 0) { + encode_message(encoder, msg, l, size); + *size = encoder->limit - encoder->ptr; + if (*size == 0) { + static char ch; + *buf = &ch; + } else { + UPB_ASSERT(encoder->ptr); + *buf = encoder->ptr; + } + } else { + UPB_ASSERT(encoder->status != kUpb_EncodeStatus_Ok); + *buf = NULL; + *size = 0; + } -#undef F -#undef TYPES -#undef TAGBYTES -#undef FASTDECODE_UNPACKEDFIXED -#undef FASTDECODE_PACKEDFIXED + _upb_mapsorter_destroy(&encoder->sorter); + return encoder->status; +} -/* string fields **************************************************************/ +upb_EncodeStatus upb_Encode(const upb_Message* msg, const upb_MiniTable* l, + int options, upb_Arena* arena, char** buf, + size_t* size) { + upb_encstate e; + unsigned depth = (unsigned)options >> 16; -typedef const char* fastdecode_copystr_func(struct upb_Decoder* d, - const char* ptr, upb_Message* msg, - const upb_MiniTable* table, - uint64_t hasbits, - upb_StringView* dst); + e.status = kUpb_EncodeStatus_Ok; + e.arena = arena; + e.buf = NULL; + e.limit = NULL; + e.ptr = NULL; + e.depth = depth ? depth : kUpb_WireFormat_DefaultDepthLimit; + e.options = options; + _upb_mapsorter_init(&e.sorter); -UPB_NOINLINE -static const char* fastdecode_verifyutf8(upb_Decoder* d, const char* ptr, - upb_Message* msg, intptr_t table, - uint64_t hasbits, uint64_t data) { - upb_StringView* dst = (upb_StringView*)data; - if (!_upb_Decoder_VerifyUtf8Inline(dst->data, dst->size)) { - _upb_FastDecoder_ErrorJmp(d, kUpb_DecodeStatus_BadUtf8); - } - UPB_MUSTTAIL return fastdecode_dispatch(UPB_PARSE_ARGS); + return upb_Encoder_Encode(&e, msg, l, buf, size); } -#define FASTDECODE_LONGSTRING(d, ptr, msg, table, hasbits, dst, validate_utf8) \ - int size = (uint8_t)ptr[0]; /* Could plumb through hasbits. */ \ - ptr++; \ - if (size & 0x80) { \ - ptr = fastdecode_longsize(ptr, &size); \ - } \ - \ - if (UPB_UNLIKELY(!upb_EpsCopyInputStream_CheckSize(&d->input, ptr, size))) { \ - dst->size = 0; \ - _upb_FastDecoder_ErrorJmp(d, kUpb_DecodeStatus_Malformed); \ - } \ - \ - const char* s_ptr = ptr; \ - ptr = upb_EpsCopyInputStream_ReadString(&d->input, &s_ptr, size, &d->arena); \ - if (!ptr) _upb_FastDecoder_ErrorJmp(d, kUpb_DecodeStatus_OutOfMemory); \ - dst->data = s_ptr; \ - dst->size = size; \ - \ - if (validate_utf8) { \ - data = (uint64_t)dst; \ - UPB_MUSTTAIL return fastdecode_verifyutf8(UPB_PARSE_ARGS); \ - } else { \ - UPB_MUSTTAIL return fastdecode_dispatch(UPB_PARSE_ARGS); \ - } +// Fast decoder: ~3x the speed of decode.c, but requires x86-64/ARM64. +// Also the table size grows by 2x. +// +// Could potentially be ported to other 64-bit archs that pass at least six +// arguments in registers and have 8 unused high bits in pointers. +// +// The overall design is to create specialized functions for every possible +// field type (eg. oneof boolean field with a 1 byte tag) and then dispatch +// to the specialized function as quickly as possible. + + + +// Must be last. + +#if UPB_FASTTABLE + +// The standard set of arguments passed to each parsing function. +// Thanks to x86-64 calling conventions, these will stay in registers. +#define UPB_PARSE_PARAMS \ + upb_Decoder *d, const char *ptr, upb_Message *msg, intptr_t table, \ + uint64_t hasbits, uint64_t data + +#define UPB_PARSE_ARGS d, ptr, msg, table, hasbits, data + +#define RETURN_GENERIC(m) \ + /* Uncomment either of these for debugging purposes. */ \ + /* fprintf(stderr, m); */ \ + /*__builtin_trap(); */ \ + return _upb_FastDecoder_DecodeGeneric(d, ptr, msg, table, hasbits, 0); + +typedef enum { + CARD_s = 0, /* Singular (optional, non-repeated) */ + CARD_o = 1, /* Oneof */ + CARD_r = 2, /* Repeated */ + CARD_p = 3 /* Packed Repeated */ +} upb_card; UPB_NOINLINE -static const char* fastdecode_longstring_utf8(struct upb_Decoder* d, - const char* ptr, upb_Message* msg, - intptr_t table, uint64_t hasbits, - uint64_t data) { - upb_StringView* dst = (upb_StringView*)data; - FASTDECODE_LONGSTRING(d, ptr, msg, table, hasbits, dst, true); +static const char* fastdecode_isdonefallback(UPB_PARSE_PARAMS) { + int overrun = data; + ptr = _upb_EpsCopyInputStream_IsDoneFallbackInline( + &d->input, ptr, overrun, _upb_Decoder_BufferFlipCallback); + data = _upb_FastDecoder_LoadTag(ptr); + UPB_MUSTTAIL return _upb_FastDecoder_TagDispatch(UPB_PARSE_ARGS); } -UPB_NOINLINE -static const char* fastdecode_longstring_noutf8( - struct upb_Decoder* d, const char* ptr, upb_Message* msg, intptr_t table, - uint64_t hasbits, uint64_t data) { - upb_StringView* dst = (upb_StringView*)data; - FASTDECODE_LONGSTRING(d, ptr, msg, table, hasbits, dst, false); +UPB_FORCEINLINE +static const char* fastdecode_dispatch(UPB_PARSE_PARAMS) { + int overrun; + switch (upb_EpsCopyInputStream_IsDoneStatus(&d->input, ptr, &overrun)) { + case kUpb_IsDoneStatus_Done: + *(uint32_t*)msg |= hasbits; // Sync hasbits. + const upb_MiniTable* m = decode_totablep(table); + return UPB_UNLIKELY(m->UPB_PRIVATE(required_count)) + ? _upb_Decoder_CheckRequired(d, ptr, msg, m) + : ptr; + case kUpb_IsDoneStatus_NotDone: + break; + case kUpb_IsDoneStatus_NeedFallback: + data = overrun; + UPB_MUSTTAIL return fastdecode_isdonefallback(UPB_PARSE_ARGS); + } + + // Read two bytes of tag data (for a one-byte tag, the high byte is junk). + data = _upb_FastDecoder_LoadTag(ptr); + UPB_MUSTTAIL return _upb_FastDecoder_TagDispatch(UPB_PARSE_ARGS); } UPB_FORCEINLINE -static void fastdecode_docopy(upb_Decoder* d, const char* ptr, uint32_t size, - int copy, char* data, size_t data_offset, - upb_StringView* dst) { - d->arena.UPB_PRIVATE(ptr) += copy; - dst->data = data + data_offset; - UPB_UNPOISON_MEMORY_REGION(data, copy); - memcpy(data, ptr, copy); - UPB_POISON_MEMORY_REGION(data + data_offset + size, - copy - data_offset - size); +static bool fastdecode_checktag(uint16_t data, int tagbytes) { + if (tagbytes == 1) { + return (data & 0xff) == 0; + } else { + return data == 0; + } } -#define FASTDECODE_COPYSTRING(d, ptr, msg, table, hasbits, data, tagbytes, \ - card, validate_utf8) \ - upb_StringView* dst; \ - fastdecode_arr farr; \ - int64_t size; \ - size_t arena_has; \ - size_t common_has; \ - char* buf; \ - \ - UPB_ASSERT(!upb_EpsCopyInputStream_AliasingAvailable(&d->input, ptr, 0)); \ - UPB_ASSERT(fastdecode_checktag(data, tagbytes)); \ - \ - dst = fastdecode_getfield(d, ptr, msg, &data, &hasbits, &farr, \ - sizeof(upb_StringView), card); \ - \ - again: \ - if (card == CARD_r) { \ - dst = fastdecode_resizearr(d, dst, &farr, sizeof(upb_StringView)); \ - } \ - \ - size = (uint8_t)ptr[tagbytes]; \ - ptr += tagbytes + 1; \ - dst->size = size; \ - \ - buf = d->arena.UPB_PRIVATE(ptr); \ - arena_has = UPB_PRIVATE(_upb_ArenaHas)(&d->arena); \ - common_has = UPB_MIN(arena_has, \ - upb_EpsCopyInputStream_BytesAvailable(&d->input, ptr)); \ - \ - if (UPB_LIKELY(size <= 15 - tagbytes)) { \ - if (arena_has < 16) goto longstr; \ - fastdecode_docopy(d, ptr - tagbytes - 1, size, 16, buf, tagbytes + 1, \ - dst); \ - } else if (UPB_LIKELY(size <= 32)) { \ - if (UPB_UNLIKELY(common_has < 32)) goto longstr; \ - fastdecode_docopy(d, ptr, size, 32, buf, 0, dst); \ - } else if (UPB_LIKELY(size <= 64)) { \ - if (UPB_UNLIKELY(common_has < 64)) goto longstr; \ - fastdecode_docopy(d, ptr, size, 64, buf, 0, dst); \ - } else if (UPB_LIKELY(size < 128)) { \ - if (UPB_UNLIKELY(common_has < 128)) goto longstr; \ - fastdecode_docopy(d, ptr, size, 128, buf, 0, dst); \ - } else { \ - goto longstr; \ - } \ - \ - ptr += size; \ - \ - if (card == CARD_r) { \ - if (validate_utf8 && \ - !_upb_Decoder_VerifyUtf8Inline(dst->data, dst->size)) { \ - _upb_FastDecoder_ErrorJmp(d, kUpb_DecodeStatus_BadUtf8); \ - } \ - fastdecode_nextret ret = fastdecode_nextrepeated( \ - d, dst, &ptr, &farr, data, tagbytes, sizeof(upb_StringView)); \ - switch (ret.next) { \ - case FD_NEXT_SAMEFIELD: \ - dst = ret.dst; \ - goto again; \ - case FD_NEXT_OTHERFIELD: \ - data = ret.tag; \ - UPB_MUSTTAIL return _upb_FastDecoder_TagDispatch(UPB_PARSE_ARGS); \ - case FD_NEXT_ATLIMIT: \ - return ptr; \ - } \ - } \ - \ - if (card != CARD_r && validate_utf8) { \ - data = (uint64_t)dst; \ - UPB_MUSTTAIL return fastdecode_verifyutf8(UPB_PARSE_ARGS); \ - } \ - \ - UPB_MUSTTAIL return fastdecode_dispatch(UPB_PARSE_ARGS); \ - \ - longstr: \ - if (card == CARD_r) { \ - fastdecode_commitarr(dst + 1, &farr, sizeof(upb_StringView)); \ - } \ - ptr--; \ - if (validate_utf8) { \ - UPB_MUSTTAIL return fastdecode_longstring_utf8(d, ptr, msg, table, \ - hasbits, (uint64_t)dst); \ - } else { \ - UPB_MUSTTAIL return fastdecode_longstring_noutf8(d, ptr, msg, table, \ - hasbits, (uint64_t)dst); \ +UPB_FORCEINLINE +static const char* fastdecode_longsize(const char* ptr, int* size) { + int i; + UPB_ASSERT(*size & 0x80); + *size &= 0xff; + for (i = 0; i < 3; i++) { + ptr++; + size_t byte = (uint8_t)ptr[-1]; + *size += (byte - 1) << (7 + 7 * i); + if (UPB_LIKELY((byte & 0x80) == 0)) return ptr; } + ptr++; + size_t byte = (uint8_t)ptr[-1]; + // len is limited by 2gb not 4gb, hence 8 and not 16 as normally expected + // for a 32 bit varint. + if (UPB_UNLIKELY(byte >= 8)) return NULL; + *size += (byte - 1) << 28; + return ptr; +} -#define FASTDECODE_STRING(d, ptr, msg, table, hasbits, data, tagbytes, card, \ - copyfunc, validate_utf8) \ - upb_StringView* dst; \ - fastdecode_arr farr; \ - int64_t size; \ - \ - if (UPB_UNLIKELY(!fastdecode_checktag(data, tagbytes))) { \ - RETURN_GENERIC("string field tag mismatch\n"); \ - } \ - \ - if (UPB_UNLIKELY( \ - !upb_EpsCopyInputStream_AliasingAvailable(&d->input, ptr, 0))) { \ - UPB_MUSTTAIL return copyfunc(UPB_PARSE_ARGS); \ - } \ - \ - dst = fastdecode_getfield(d, ptr, msg, &data, &hasbits, &farr, \ - sizeof(upb_StringView), card); \ - \ - again: \ - if (card == CARD_r) { \ - dst = fastdecode_resizearr(d, dst, &farr, sizeof(upb_StringView)); \ - } \ - \ - size = (int8_t)ptr[tagbytes]; \ - ptr += tagbytes + 1; \ - \ - if (UPB_UNLIKELY( \ - !upb_EpsCopyInputStream_AliasingAvailable(&d->input, ptr, size))) { \ - ptr--; \ - if (validate_utf8) { \ - return fastdecode_longstring_utf8(d, ptr, msg, table, hasbits, \ - (uint64_t)dst); \ - } else { \ - return fastdecode_longstring_noutf8(d, ptr, msg, table, hasbits, \ - (uint64_t)dst); \ - } \ - } \ - \ - dst->data = ptr; \ - dst->size = size; \ - ptr = upb_EpsCopyInputStream_ReadStringAliased(&d->input, &dst->data, \ - dst->size); \ - \ - if (card == CARD_r) { \ - if (validate_utf8 && \ - !_upb_Decoder_VerifyUtf8Inline(dst->data, dst->size)) { \ - _upb_FastDecoder_ErrorJmp(d, kUpb_DecodeStatus_BadUtf8); \ - } \ - fastdecode_nextret ret = fastdecode_nextrepeated( \ - d, dst, &ptr, &farr, data, tagbytes, sizeof(upb_StringView)); \ - switch (ret.next) { \ - case FD_NEXT_SAMEFIELD: \ - dst = ret.dst; \ - goto again; \ - case FD_NEXT_OTHERFIELD: \ - data = ret.tag; \ - UPB_MUSTTAIL return _upb_FastDecoder_TagDispatch(UPB_PARSE_ARGS); \ - case FD_NEXT_ATLIMIT: \ - return ptr; \ - } \ - } \ - \ - if (card != CARD_r && validate_utf8) { \ - data = (uint64_t)dst; \ - UPB_MUSTTAIL return fastdecode_verifyutf8(UPB_PARSE_ARGS); \ - } \ - \ - UPB_MUSTTAIL return fastdecode_dispatch(UPB_PARSE_ARGS); - -/* Generate all combinations: - * {p,c} x {s,o,r} x {s, b} x {1bt,2bt} */ +UPB_FORCEINLINE +static const char* fastdecode_delimited( + upb_Decoder* d, const char* ptr, + upb_EpsCopyInputStream_ParseDelimitedFunc* func, void* ctx) { + ptr++; -#define s_VALIDATE true -#define b_VALIDATE false + // Sign-extend so varint greater than one byte becomes negative, causing + // fast delimited parse to fail. + int len = (int8_t)ptr[-1]; -#define F(card, tagbytes, type) \ - UPB_NOINLINE \ - const char* upb_c##card##type##_##tagbytes##bt(UPB_PARSE_PARAMS) { \ - FASTDECODE_COPYSTRING(d, ptr, msg, table, hasbits, data, tagbytes, \ - CARD_##card, type##_VALIDATE); \ - } \ - const char* upb_p##card##type##_##tagbytes##bt(UPB_PARSE_PARAMS) { \ - FASTDECODE_STRING(d, ptr, msg, table, hasbits, data, tagbytes, \ - CARD_##card, upb_c##card##type##_##tagbytes##bt, \ - type##_VALIDATE); \ + if (!upb_EpsCopyInputStream_TryParseDelimitedFast(&d->input, &ptr, len, func, + ctx)) { + // Slow case: Sub-message is >=128 bytes and/or exceeds the current buffer. + // If it exceeds the buffer limit, limit/limit_ptr will change during + // sub-message parsing, so we need to preserve delta, not limit. + if (UPB_UNLIKELY(len & 0x80)) { + // Size varint >1 byte (length >= 128). + ptr = fastdecode_longsize(ptr, &len); + if (!ptr) { + // Corrupt wire format: size exceeded INT_MAX. + return NULL; + } + } + if (!upb_EpsCopyInputStream_CheckSize(&d->input, ptr, len)) { + // Corrupt wire format: invalid limit. + return NULL; + } + int delta = upb_EpsCopyInputStream_PushLimit(&d->input, ptr, len); + ptr = func(&d->input, ptr, ctx); + upb_EpsCopyInputStream_PopLimit(&d->input, ptr, delta); } + return ptr; +} -#define UTF8(card, tagbytes) \ - F(card, tagbytes, s) \ - F(card, tagbytes, b) +/* singular, oneof, repeated field handling ***********************************/ -#define TAGBYTES(card) \ - UTF8(card, 1) \ - UTF8(card, 2) +typedef struct { + upb_Array* arr; + void* end; +} fastdecode_arr; -TAGBYTES(s) -TAGBYTES(o) -TAGBYTES(r) +typedef enum { + FD_NEXT_ATLIMIT, + FD_NEXT_SAMEFIELD, + FD_NEXT_OTHERFIELD +} fastdecode_next; -#undef s_VALIDATE -#undef b_VALIDATE -#undef F -#undef TAGBYTES -#undef FASTDECODE_LONGSTRING -#undef FASTDECODE_COPYSTRING -#undef FASTDECODE_STRING +typedef struct { + void* dst; + fastdecode_next next; + uint32_t tag; +} fastdecode_nextret; -/* message fields *************************************************************/ +UPB_FORCEINLINE +static void* fastdecode_resizearr(upb_Decoder* d, void* dst, + fastdecode_arr* farr, int valbytes) { + if (UPB_UNLIKELY(dst == farr->end)) { + size_t old_capacity = farr->arr->UPB_PRIVATE(capacity); + size_t old_bytes = old_capacity * valbytes; + size_t new_capacity = old_capacity * 2; + size_t new_bytes = new_capacity * valbytes; + char* old_ptr = _upb_array_ptr(farr->arr); + char* new_ptr = upb_Arena_Realloc(&d->arena, old_ptr, old_bytes, new_bytes); + uint8_t elem_size_lg2 = __builtin_ctz(valbytes); + UPB_PRIVATE(_upb_Array_SetTaggedPtr)(farr->arr, new_ptr, elem_size_lg2); + farr->arr->UPB_PRIVATE(capacity) = new_capacity; + dst = (void*)(new_ptr + (old_capacity * valbytes)); + farr->end = (void*)(new_ptr + (new_capacity * valbytes)); + } + return dst; +} -UPB_INLINE -upb_Message* decode_newmsg_ceil(upb_Decoder* d, const upb_MiniTable* m, - int msg_ceil_bytes) { - size_t size = m->UPB_PRIVATE(size) + sizeof(upb_Message_Internal); - char* msg_data; - if (UPB_LIKELY(msg_ceil_bytes > 0 && - UPB_PRIVATE(_upb_ArenaHas)(&d->arena) >= msg_ceil_bytes)) { - UPB_ASSERT(size <= (size_t)msg_ceil_bytes); - msg_data = d->arena.UPB_PRIVATE(ptr); - d->arena.UPB_PRIVATE(ptr) += size; - UPB_UNPOISON_MEMORY_REGION(msg_data, msg_ceil_bytes); - memset(msg_data, 0, msg_ceil_bytes); - UPB_POISON_MEMORY_REGION(msg_data + size, msg_ceil_bytes - size); +UPB_FORCEINLINE +static bool fastdecode_tagmatch(uint32_t tag, uint64_t data, int tagbytes) { + if (tagbytes == 1) { + return (uint8_t)tag == (uint8_t)data; } else { - msg_data = (char*)upb_Arena_Malloc(&d->arena, size); - memset(msg_data, 0, size); + return (uint16_t)tag == (uint16_t)data; } - return msg_data + sizeof(upb_Message_Internal); } -typedef struct { - intptr_t table; - upb_Message* msg; -} fastdecode_submsgdata; +UPB_FORCEINLINE +static void fastdecode_commitarr(void* dst, fastdecode_arr* farr, + int valbytes) { + farr->arr->UPB_PRIVATE(size) = + (size_t)((char*)dst - (char*)_upb_array_ptr(farr->arr)) / valbytes; +} UPB_FORCEINLINE -static const char* fastdecode_tosubmsg(upb_EpsCopyInputStream* e, - const char* ptr, void* ctx) { - upb_Decoder* d = (upb_Decoder*)e; - fastdecode_submsgdata* submsg = ctx; - ptr = fastdecode_dispatch(d, ptr, submsg->msg, submsg->table, 0, 0); - UPB_ASSUME(ptr != NULL); - return ptr; +static fastdecode_nextret fastdecode_nextrepeated(upb_Decoder* d, void* dst, + const char** ptr, + fastdecode_arr* farr, + uint64_t data, int tagbytes, + int valbytes) { + fastdecode_nextret ret; + dst = (char*)dst + valbytes; + + if (UPB_LIKELY(!_upb_Decoder_IsDone(d, ptr))) { + ret.tag = _upb_FastDecoder_LoadTag(*ptr); + if (fastdecode_tagmatch(ret.tag, data, tagbytes)) { + ret.next = FD_NEXT_SAMEFIELD; + } else { + fastdecode_commitarr(dst, farr, valbytes); + ret.next = FD_NEXT_OTHERFIELD; + } + } else { + fastdecode_commitarr(dst, farr, valbytes); + ret.next = FD_NEXT_ATLIMIT; + } + + ret.dst = dst; + return ret; } -#define FASTDECODE_SUBMSG(d, ptr, msg, table, hasbits, data, tagbytes, \ - msg_ceil_bytes, card) \ - \ - if (UPB_UNLIKELY(!fastdecode_checktag(data, tagbytes))) { \ - RETURN_GENERIC("submessage field tag mismatch\n"); \ - } \ - \ - if (--d->depth == 0) { \ - _upb_FastDecoder_ErrorJmp(d, kUpb_DecodeStatus_MaxDepthExceeded); \ - } \ - \ - upb_Message** dst; \ - uint32_t submsg_idx = (data >> 16) & 0xff; \ - const upb_MiniTable* tablep = decode_totablep(table); \ - const upb_MiniTable* subtablep = upb_MiniTableSub_Message( \ - *UPB_PRIVATE(_upb_MiniTable_GetSubByIndex)(tablep, submsg_idx)); \ - fastdecode_submsgdata submsg = {decode_totable(subtablep)}; \ - fastdecode_arr farr; \ - \ - if (subtablep->UPB_PRIVATE(table_mask) == (uint8_t)-1) { \ - d->depth++; \ - RETURN_GENERIC("submessage doesn't have fast tables."); \ - } \ - \ - dst = fastdecode_getfield(d, ptr, msg, &data, &hasbits, &farr, \ - sizeof(upb_Message*), card); \ - \ - if (card == CARD_s) { \ - *(uint32_t*)msg |= hasbits; \ - hasbits = 0; \ - } \ - \ - again: \ - if (card == CARD_r) { \ - dst = fastdecode_resizearr(d, dst, &farr, sizeof(upb_Message*)); \ - } \ - \ - submsg.msg = *dst; \ - \ - if (card == CARD_r || UPB_LIKELY(!submsg.msg)) { \ - *dst = submsg.msg = decode_newmsg_ceil(d, subtablep, msg_ceil_bytes); \ - } \ - \ - ptr += tagbytes; \ - ptr = fastdecode_delimited(d, ptr, fastdecode_tosubmsg, &submsg); \ - \ - if (UPB_UNLIKELY(ptr == NULL || d->end_group != DECODE_NOGROUP)) { \ - _upb_FastDecoder_ErrorJmp(d, kUpb_DecodeStatus_Malformed); \ - } \ - \ - if (card == CARD_r) { \ - fastdecode_nextret ret = fastdecode_nextrepeated( \ - d, dst, &ptr, &farr, data, tagbytes, sizeof(upb_Message*)); \ - switch (ret.next) { \ - case FD_NEXT_SAMEFIELD: \ - dst = ret.dst; \ - goto again; \ - case FD_NEXT_OTHERFIELD: \ - d->depth++; \ - data = ret.tag; \ - UPB_MUSTTAIL return _upb_FastDecoder_TagDispatch(UPB_PARSE_ARGS); \ - case FD_NEXT_ATLIMIT: \ - d->depth++; \ - return ptr; \ - } \ - } \ - \ - d->depth++; \ - UPB_MUSTTAIL return fastdecode_dispatch(UPB_PARSE_ARGS); - -#define F(card, tagbytes, size_ceil, ceil_arg) \ - const char* upb_p##card##m_##tagbytes##bt_max##size_ceil##b( \ - UPB_PARSE_PARAMS) { \ - FASTDECODE_SUBMSG(d, ptr, msg, table, hasbits, data, tagbytes, ceil_arg, \ - CARD_##card); \ - } - -#define SIZES(card, tagbytes) \ - F(card, tagbytes, 64, 64) \ - F(card, tagbytes, 128, 128) \ - F(card, tagbytes, 192, 192) \ - F(card, tagbytes, 256, 256) \ - F(card, tagbytes, max, -1) - -#define TAGBYTES(card) \ - SIZES(card, 1) \ - SIZES(card, 2) - -TAGBYTES(s) -TAGBYTES(o) -TAGBYTES(r) - -#undef TAGBYTES -#undef SIZES -#undef F -#undef FASTDECODE_SUBMSG - -#endif /* UPB_FASTTABLE */ - -// We encode backwards, to avoid pre-computing lengths (one-pass encode). - - -#include -#include -#include -#include - - -// Must be last. - -#define UPB_PB_VARINT_MAX_LEN 10 - -UPB_NOINLINE -static size_t encode_varint64(uint64_t val, char* buf) { - size_t i = 0; - do { - uint8_t byte = val & 0x7fU; - val >>= 7; - if (val) byte |= 0x80U; - buf[i++] = byte; - } while (val); - return i; -} - -static uint32_t encode_zz32(int32_t n) { - return ((uint32_t)n << 1) ^ (n >> 31); -} -static uint64_t encode_zz64(int64_t n) { - return ((uint64_t)n << 1) ^ (n >> 63); +UPB_FORCEINLINE +static void* fastdecode_fieldmem(upb_Message* msg, uint64_t data) { + size_t ofs = data >> 48; + return (char*)msg + ofs; } -typedef struct { - upb_EncodeStatus status; - jmp_buf err; - upb_Arena* arena; - char *buf, *ptr, *limit; - int options; - int depth; - _upb_mapsorter sorter; -} upb_encstate; - -static size_t upb_roundup_pow2(size_t bytes) { - size_t ret = 128; - while (ret < bytes) { - ret *= 2; +UPB_FORCEINLINE +static void* fastdecode_getfield(upb_Decoder* d, const char* ptr, + upb_Message* msg, uint64_t* data, + uint64_t* hasbits, fastdecode_arr* farr, + int valbytes, upb_card card) { + switch (card) { + case CARD_s: { + uint8_t hasbit_index = *data >> 24; + // Set hasbit and return pointer to scalar field. + *hasbits |= 1ull << hasbit_index; + return fastdecode_fieldmem(msg, *data); + } + case CARD_o: { + uint16_t case_ofs = *data >> 32; + uint32_t* oneof_case = UPB_PTR_AT(msg, case_ofs, uint32_t); + uint8_t field_number = *data >> 24; + *oneof_case = field_number; + return fastdecode_fieldmem(msg, *data); + } + case CARD_r: { + // Get pointer to upb_Array and allocate/expand if necessary. + uint8_t elem_size_lg2 = __builtin_ctz(valbytes); + upb_Array** arr_p = fastdecode_fieldmem(msg, *data); + char* begin; + *(uint32_t*)msg |= *hasbits; + *hasbits = 0; + if (UPB_LIKELY(!*arr_p)) { + farr->arr = UPB_PRIVATE(_upb_Array_New)(&d->arena, 8, elem_size_lg2); + *arr_p = farr->arr; + } else { + farr->arr = *arr_p; + } + begin = _upb_array_ptr(farr->arr); + farr->end = begin + (farr->arr->UPB_PRIVATE(capacity) * valbytes); + *data = _upb_FastDecoder_LoadTag(ptr); + return begin + (farr->arr->UPB_PRIVATE(size) * valbytes); + } + default: + UPB_UNREACHABLE(); } - return ret; } -UPB_NORETURN static void encode_err(upb_encstate* e, upb_EncodeStatus s) { - UPB_ASSERT(s != kUpb_EncodeStatus_Ok); - e->status = s; - UPB_LONGJMP(e->err, 1); +UPB_FORCEINLINE +static bool fastdecode_flippacked(uint64_t* data, int tagbytes) { + *data ^= (0x2 ^ 0x0); // Patch data to match packed wiretype. + return fastdecode_checktag(*data, tagbytes); } -UPB_NOINLINE -static void encode_growbuffer(upb_encstate* e, size_t bytes) { - size_t old_size = e->limit - e->buf; - size_t new_size = upb_roundup_pow2(bytes + (e->limit - e->ptr)); - char* new_buf = upb_Arena_Realloc(e->arena, e->buf, old_size, new_size); - - if (!new_buf) encode_err(e, kUpb_EncodeStatus_OutOfMemory); - - // We want previous data at the end, realloc() put it at the beginning. - // TODO: This is somewhat inefficient since we are copying twice. - // Maybe create a realloc() that copies to the end of the new buffer? - if (old_size > 0) { - memmove(new_buf + new_size - old_size, e->buf, old_size); +#define FASTDECODE_CHECKPACKED(tagbytes, card, func) \ + if (UPB_UNLIKELY(!fastdecode_checktag(data, tagbytes))) { \ + if (card == CARD_r && fastdecode_flippacked(&data, tagbytes)) { \ + UPB_MUSTTAIL return func(UPB_PARSE_ARGS); \ + } \ + RETURN_GENERIC("packed check tag mismatch\n"); \ } - e->ptr = new_buf + new_size - (e->limit - e->ptr); - e->limit = new_buf + new_size; - e->buf = new_buf; - - e->ptr -= bytes; -} +/* varint fields **************************************************************/ -/* Call to ensure that at least "bytes" bytes are available for writing at - * e->ptr. Returns false if the bytes could not be allocated. */ UPB_FORCEINLINE -static void encode_reserve(upb_encstate* e, size_t bytes) { - if ((size_t)(e->ptr - e->buf) < bytes) { - encode_growbuffer(e, bytes); - return; +static uint64_t fastdecode_munge(uint64_t val, int valbytes, bool zigzag) { + if (valbytes == 1) { + return val != 0; + } else if (zigzag) { + if (valbytes == 4) { + uint32_t n = val; + return (n >> 1) ^ -(int32_t)(n & 1); + } else if (valbytes == 8) { + return (val >> 1) ^ -(int64_t)(val & 1); + } + UPB_UNREACHABLE(); } - - e->ptr -= bytes; -} - -/* Writes the given bytes to the buffer, handling reserve/advance. */ -static void encode_bytes(upb_encstate* e, const void* data, size_t len) { - if (len == 0) return; /* memcpy() with zero size is UB */ - encode_reserve(e, len); - memcpy(e->ptr, data, len); -} - -static void encode_fixed64(upb_encstate* e, uint64_t val) { - val = _upb_BigEndian_Swap64(val); - encode_bytes(e, &val, sizeof(uint64_t)); -} - -static void encode_fixed32(upb_encstate* e, uint32_t val) { - val = _upb_BigEndian_Swap32(val); - encode_bytes(e, &val, sizeof(uint32_t)); -} - -UPB_NOINLINE -static void encode_longvarint(upb_encstate* e, uint64_t val) { - size_t len; - char* start; - - encode_reserve(e, UPB_PB_VARINT_MAX_LEN); - len = encode_varint64(val, e->ptr); - start = e->ptr + UPB_PB_VARINT_MAX_LEN - len; - memmove(start, e->ptr, len); - e->ptr = start; + return val; } UPB_FORCEINLINE -static void encode_varint(upb_encstate* e, uint64_t val) { - if (val < 128 && e->ptr != e->buf) { - --e->ptr; - *e->ptr = val; - } else { - encode_longvarint(e, val); +static const char* fastdecode_varint64(const char* ptr, uint64_t* val) { + ptr++; + *val = (uint8_t)ptr[-1]; + if (UPB_UNLIKELY(*val & 0x80)) { + int i; + for (i = 0; i < 8; i++) { + ptr++; + uint64_t byte = (uint8_t)ptr[-1]; + *val += (byte - 1) << (7 + 7 * i); + if (UPB_LIKELY((byte & 0x80) == 0)) goto done; + } + ptr++; + uint64_t byte = (uint8_t)ptr[-1]; + if (byte > 1) { + return NULL; + } + *val += (byte - 1) << 63; } +done: + UPB_ASSUME(ptr != NULL); + return ptr; } -static void encode_double(upb_encstate* e, double d) { - uint64_t u64; - UPB_ASSERT(sizeof(double) == sizeof(uint64_t)); - memcpy(&u64, &d, sizeof(uint64_t)); - encode_fixed64(e, u64); -} - -static void encode_float(upb_encstate* e, float d) { - uint32_t u32; - UPB_ASSERT(sizeof(float) == sizeof(uint32_t)); - memcpy(&u32, &d, sizeof(uint32_t)); - encode_fixed32(e, u32); -} - -static void encode_tag(upb_encstate* e, uint32_t field_number, - uint8_t wire_type) { - encode_varint(e, (field_number << 3) | wire_type); -} +#define FASTDECODE_UNPACKEDVARINT(d, ptr, msg, table, hasbits, data, tagbytes, \ + valbytes, card, zigzag, packed) \ + uint64_t val; \ + void* dst; \ + fastdecode_arr farr; \ + \ + FASTDECODE_CHECKPACKED(tagbytes, card, packed); \ + \ + dst = fastdecode_getfield(d, ptr, msg, &data, &hasbits, &farr, valbytes, \ + card); \ + if (card == CARD_r) { \ + if (UPB_UNLIKELY(!dst)) { \ + RETURN_GENERIC("need array resize\n"); \ + } \ + } \ + \ + again: \ + if (card == CARD_r) { \ + dst = fastdecode_resizearr(d, dst, &farr, valbytes); \ + } \ + \ + ptr += tagbytes; \ + ptr = fastdecode_varint64(ptr, &val); \ + if (ptr == NULL) _upb_FastDecoder_ErrorJmp(d, kUpb_DecodeStatus_Malformed); \ + val = fastdecode_munge(val, valbytes, zigzag); \ + memcpy(dst, &val, valbytes); \ + \ + if (card == CARD_r) { \ + fastdecode_nextret ret = fastdecode_nextrepeated( \ + d, dst, &ptr, &farr, data, tagbytes, valbytes); \ + switch (ret.next) { \ + case FD_NEXT_SAMEFIELD: \ + dst = ret.dst; \ + goto again; \ + case FD_NEXT_OTHERFIELD: \ + data = ret.tag; \ + UPB_MUSTTAIL return _upb_FastDecoder_TagDispatch(UPB_PARSE_ARGS); \ + case FD_NEXT_ATLIMIT: \ + return ptr; \ + } \ + } \ + \ + UPB_MUSTTAIL return fastdecode_dispatch(UPB_PARSE_ARGS); -static void encode_fixedarray(upb_encstate* e, const upb_Array* arr, - size_t elem_size, uint32_t tag) { - size_t bytes = arr->UPB_PRIVATE(size) * elem_size; - const char* data = _upb_array_constptr(arr); - const char* ptr = data + bytes - elem_size; +typedef struct { + uint8_t valbytes; + bool zigzag; + void* dst; + fastdecode_arr farr; +} fastdecode_varintdata; - if (tag || !_upb_IsLittleEndian()) { - while (true) { - if (elem_size == 4) { - uint32_t val; - memcpy(&val, ptr, sizeof(val)); - val = _upb_BigEndian_Swap32(val); - encode_bytes(e, &val, elem_size); - } else { - UPB_ASSERT(elem_size == 8); - uint64_t val; - memcpy(&val, ptr, sizeof(val)); - val = _upb_BigEndian_Swap64(val); - encode_bytes(e, &val, elem_size); - } +UPB_FORCEINLINE +static const char* fastdecode_topackedvarint(upb_EpsCopyInputStream* e, + const char* ptr, void* ctx) { + upb_Decoder* d = (upb_Decoder*)e; + fastdecode_varintdata* data = ctx; + void* dst = data->dst; + uint64_t val; - if (tag) encode_varint(e, tag); - if (ptr == data) break; - ptr -= elem_size; - } - } else { - encode_bytes(e, data, bytes); + while (!_upb_Decoder_IsDone(d, &ptr)) { + dst = fastdecode_resizearr(d, dst, &data->farr, data->valbytes); + ptr = fastdecode_varint64(ptr, &val); + if (ptr == NULL) return NULL; + val = fastdecode_munge(val, data->valbytes, data->zigzag); + memcpy(dst, &val, data->valbytes); + dst = (char*)dst + data->valbytes; } -} -static void encode_message(upb_encstate* e, const upb_Message* msg, - const upb_MiniTable* m, size_t* size); - -static void encode_TaggedMessagePtr(upb_encstate* e, - upb_TaggedMessagePtr tagged, - const upb_MiniTable* m, size_t* size) { - if (upb_TaggedMessagePtr_IsEmpty(tagged)) { - m = UPB_PRIVATE(_upb_MiniTable_Empty)(); - } - encode_message(e, _upb_TaggedMessagePtr_GetMessage(tagged), m, size); + fastdecode_commitarr(dst, &data->farr, data->valbytes); + return ptr; } -static void encode_scalar(upb_encstate* e, const void* _field_mem, - const upb_MiniTableSub* subs, - const upb_MiniTableField* f) { - const char* field_mem = _field_mem; - int wire_type; - -#define CASE(ctype, type, wtype, encodeval) \ - { \ - ctype val = *(ctype*)field_mem; \ - encode_##type(e, encodeval); \ - wire_type = wtype; \ - break; \ - } +#define FASTDECODE_PACKEDVARINT(d, ptr, msg, table, hasbits, data, tagbytes, \ + valbytes, zigzag, unpacked) \ + fastdecode_varintdata ctx = {valbytes, zigzag}; \ + \ + FASTDECODE_CHECKPACKED(tagbytes, CARD_r, unpacked); \ + \ + ctx.dst = fastdecode_getfield(d, ptr, msg, &data, &hasbits, &ctx.farr, \ + valbytes, CARD_r); \ + if (UPB_UNLIKELY(!ctx.dst)) { \ + RETURN_GENERIC("need array resize\n"); \ + } \ + \ + ptr += tagbytes; \ + ptr = fastdecode_delimited(d, ptr, &fastdecode_topackedvarint, &ctx); \ + \ + if (UPB_UNLIKELY(ptr == NULL)) { \ + _upb_FastDecoder_ErrorJmp(d, kUpb_DecodeStatus_Malformed); \ + } \ + \ + UPB_MUSTTAIL return fastdecode_dispatch(d, ptr, msg, table, hasbits, 0); - switch (f->UPB_PRIVATE(descriptortype)) { - case kUpb_FieldType_Double: - CASE(double, double, kUpb_WireType_64Bit, val); - case kUpb_FieldType_Float: - CASE(float, float, kUpb_WireType_32Bit, val); - case kUpb_FieldType_Int64: - case kUpb_FieldType_UInt64: - CASE(uint64_t, varint, kUpb_WireType_Varint, val); - case kUpb_FieldType_UInt32: - CASE(uint32_t, varint, kUpb_WireType_Varint, val); - case kUpb_FieldType_Int32: - case kUpb_FieldType_Enum: - CASE(int32_t, varint, kUpb_WireType_Varint, (int64_t)val); - case kUpb_FieldType_SFixed64: - case kUpb_FieldType_Fixed64: - CASE(uint64_t, fixed64, kUpb_WireType_64Bit, val); - case kUpb_FieldType_Fixed32: - case kUpb_FieldType_SFixed32: - CASE(uint32_t, fixed32, kUpb_WireType_32Bit, val); - case kUpb_FieldType_Bool: - CASE(bool, varint, kUpb_WireType_Varint, val); - case kUpb_FieldType_SInt32: - CASE(int32_t, varint, kUpb_WireType_Varint, encode_zz32(val)); - case kUpb_FieldType_SInt64: - CASE(int64_t, varint, kUpb_WireType_Varint, encode_zz64(val)); - case kUpb_FieldType_String: - case kUpb_FieldType_Bytes: { - upb_StringView view = *(upb_StringView*)field_mem; - encode_bytes(e, view.data, view.size); - encode_varint(e, view.size); - wire_type = kUpb_WireType_Delimited; - break; - } - case kUpb_FieldType_Group: { - size_t size; - upb_TaggedMessagePtr submsg = *(upb_TaggedMessagePtr*)field_mem; - const upb_MiniTable* subm = - upb_MiniTableSub_Message(subs[f->UPB_PRIVATE(submsg_index)]); - if (submsg == 0) { - return; - } - if (--e->depth == 0) encode_err(e, kUpb_EncodeStatus_MaxDepthExceeded); - encode_tag(e, f->UPB_PRIVATE(number), kUpb_WireType_EndGroup); - encode_TaggedMessagePtr(e, submsg, subm, &size); - wire_type = kUpb_WireType_StartGroup; - e->depth++; - break; - } - case kUpb_FieldType_Message: { - size_t size; - upb_TaggedMessagePtr submsg = *(upb_TaggedMessagePtr*)field_mem; - const upb_MiniTable* subm = - upb_MiniTableSub_Message(subs[f->UPB_PRIVATE(submsg_index)]); - if (submsg == 0) { - return; - } - if (--e->depth == 0) encode_err(e, kUpb_EncodeStatus_MaxDepthExceeded); - encode_TaggedMessagePtr(e, submsg, subm, &size); - encode_varint(e, size); - wire_type = kUpb_WireType_Delimited; - e->depth++; - break; - } - default: - UPB_UNREACHABLE(); +#define FASTDECODE_VARINT(d, ptr, msg, table, hasbits, data, tagbytes, \ + valbytes, card, zigzag, unpacked, packed) \ + if (card == CARD_p) { \ + FASTDECODE_PACKEDVARINT(d, ptr, msg, table, hasbits, data, tagbytes, \ + valbytes, zigzag, unpacked); \ + } else { \ + FASTDECODE_UNPACKEDVARINT(d, ptr, msg, table, hasbits, data, tagbytes, \ + valbytes, card, zigzag, packed); \ } -#undef CASE - encode_tag(e, f->UPB_PRIVATE(number), wire_type); -} +#define z_ZZ true +#define b_ZZ false +#define v_ZZ false -static void encode_array(upb_encstate* e, const upb_Message* msg, - const upb_MiniTableSub* subs, - const upb_MiniTableField* f) { - const upb_Array* arr = *UPB_PTR_AT(msg, f->UPB_PRIVATE(offset), upb_Array*); - bool packed = upb_MiniTableField_IsPacked(f); - size_t pre_len = e->limit - e->ptr; +/* Generate all combinations: + * {s,o,r,p} x {b1,v4,z4,v8,z8} x {1bt,2bt} */ - if (arr == NULL || arr->UPB_PRIVATE(size) == 0) { - return; +#define F(card, type, valbytes, tagbytes) \ + UPB_NOINLINE \ + const char* upb_p##card##type##valbytes##_##tagbytes##bt(UPB_PARSE_PARAMS) { \ + FASTDECODE_VARINT(d, ptr, msg, table, hasbits, data, tagbytes, valbytes, \ + CARD_##card, type##_ZZ, \ + upb_pr##type##valbytes##_##tagbytes##bt, \ + upb_pp##type##valbytes##_##tagbytes##bt); \ } -#define VARINT_CASE(ctype, encode) \ - { \ - const ctype* start = _upb_array_constptr(arr); \ - const ctype* ptr = start + arr->UPB_PRIVATE(size); \ - uint32_t tag = \ - packed ? 0 : (f->UPB_PRIVATE(number) << 3) | kUpb_WireType_Varint; \ - do { \ - ptr--; \ - encode_varint(e, encode); \ - if (tag) encode_varint(e, tag); \ - } while (ptr != start); \ - } \ - break; +#define TYPES(card, tagbytes) \ + F(card, b, 1, tagbytes) \ + F(card, v, 4, tagbytes) \ + F(card, v, 8, tagbytes) \ + F(card, z, 4, tagbytes) \ + F(card, z, 8, tagbytes) -#define TAG(wire_type) (packed ? 0 : (f->UPB_PRIVATE(number) << 3 | wire_type)) +#define TAGBYTES(card) \ + TYPES(card, 1) \ + TYPES(card, 2) - switch (f->UPB_PRIVATE(descriptortype)) { - case kUpb_FieldType_Double: - encode_fixedarray(e, arr, sizeof(double), TAG(kUpb_WireType_64Bit)); - break; - case kUpb_FieldType_Float: - encode_fixedarray(e, arr, sizeof(float), TAG(kUpb_WireType_32Bit)); - break; - case kUpb_FieldType_SFixed64: - case kUpb_FieldType_Fixed64: - encode_fixedarray(e, arr, sizeof(uint64_t), TAG(kUpb_WireType_64Bit)); - break; - case kUpb_FieldType_Fixed32: - case kUpb_FieldType_SFixed32: - encode_fixedarray(e, arr, sizeof(uint32_t), TAG(kUpb_WireType_32Bit)); - break; - case kUpb_FieldType_Int64: - case kUpb_FieldType_UInt64: - VARINT_CASE(uint64_t, *ptr); - case kUpb_FieldType_UInt32: - VARINT_CASE(uint32_t, *ptr); - case kUpb_FieldType_Int32: - case kUpb_FieldType_Enum: - VARINT_CASE(int32_t, (int64_t)*ptr); - case kUpb_FieldType_Bool: - VARINT_CASE(bool, *ptr); - case kUpb_FieldType_SInt32: - VARINT_CASE(int32_t, encode_zz32(*ptr)); - case kUpb_FieldType_SInt64: - VARINT_CASE(int64_t, encode_zz64(*ptr)); - case kUpb_FieldType_String: - case kUpb_FieldType_Bytes: { - const upb_StringView* start = _upb_array_constptr(arr); - const upb_StringView* ptr = start + arr->UPB_PRIVATE(size); - do { - ptr--; - encode_bytes(e, ptr->data, ptr->size); - encode_varint(e, ptr->size); - encode_tag(e, f->UPB_PRIVATE(number), kUpb_WireType_Delimited); - } while (ptr != start); - return; - } - case kUpb_FieldType_Group: { - const upb_TaggedMessagePtr* start = _upb_array_constptr(arr); - const upb_TaggedMessagePtr* ptr = start + arr->UPB_PRIVATE(size); - const upb_MiniTable* subm = - upb_MiniTableSub_Message(subs[f->UPB_PRIVATE(submsg_index)]); - if (--e->depth == 0) encode_err(e, kUpb_EncodeStatus_MaxDepthExceeded); - do { - size_t size; - ptr--; - encode_tag(e, f->UPB_PRIVATE(number), kUpb_WireType_EndGroup); - encode_TaggedMessagePtr(e, *ptr, subm, &size); - encode_tag(e, f->UPB_PRIVATE(number), kUpb_WireType_StartGroup); - } while (ptr != start); - e->depth++; - return; - } - case kUpb_FieldType_Message: { - const upb_TaggedMessagePtr* start = _upb_array_constptr(arr); - const upb_TaggedMessagePtr* ptr = start + arr->UPB_PRIVATE(size); - const upb_MiniTable* subm = - upb_MiniTableSub_Message(subs[f->UPB_PRIVATE(submsg_index)]); - if (--e->depth == 0) encode_err(e, kUpb_EncodeStatus_MaxDepthExceeded); - do { - size_t size; - ptr--; - encode_TaggedMessagePtr(e, *ptr, subm, &size); - encode_varint(e, size); - encode_tag(e, f->UPB_PRIVATE(number), kUpb_WireType_Delimited); - } while (ptr != start); - e->depth++; - return; - } +TAGBYTES(s) +TAGBYTES(o) +TAGBYTES(r) +TAGBYTES(p) + +#undef z_ZZ +#undef b_ZZ +#undef v_ZZ +#undef o_ONEOF +#undef s_ONEOF +#undef r_ONEOF +#undef F +#undef TYPES +#undef TAGBYTES +#undef FASTDECODE_UNPACKEDVARINT +#undef FASTDECODE_PACKEDVARINT +#undef FASTDECODE_VARINT + +/* fixed fields ***************************************************************/ + +#define FASTDECODE_UNPACKEDFIXED(d, ptr, msg, table, hasbits, data, tagbytes, \ + valbytes, card, packed) \ + void* dst; \ + fastdecode_arr farr; \ + \ + FASTDECODE_CHECKPACKED(tagbytes, card, packed) \ + \ + dst = fastdecode_getfield(d, ptr, msg, &data, &hasbits, &farr, valbytes, \ + card); \ + if (card == CARD_r) { \ + if (UPB_UNLIKELY(!dst)) { \ + RETURN_GENERIC("couldn't allocate array in arena\n"); \ + } \ + } \ + \ + again: \ + if (card == CARD_r) { \ + dst = fastdecode_resizearr(d, dst, &farr, valbytes); \ + } \ + \ + ptr += tagbytes; \ + memcpy(dst, ptr, valbytes); \ + ptr += valbytes; \ + \ + if (card == CARD_r) { \ + fastdecode_nextret ret = fastdecode_nextrepeated( \ + d, dst, &ptr, &farr, data, tagbytes, valbytes); \ + switch (ret.next) { \ + case FD_NEXT_SAMEFIELD: \ + dst = ret.dst; \ + goto again; \ + case FD_NEXT_OTHERFIELD: \ + data = ret.tag; \ + UPB_MUSTTAIL return _upb_FastDecoder_TagDispatch(UPB_PARSE_ARGS); \ + case FD_NEXT_ATLIMIT: \ + return ptr; \ + } \ + } \ + \ + UPB_MUSTTAIL return fastdecode_dispatch(UPB_PARSE_ARGS); + +#define FASTDECODE_PACKEDFIXED(d, ptr, msg, table, hasbits, data, tagbytes, \ + valbytes, unpacked) \ + FASTDECODE_CHECKPACKED(tagbytes, CARD_r, unpacked) \ + \ + ptr += tagbytes; \ + int size = (uint8_t)ptr[0]; \ + ptr++; \ + if (size & 0x80) { \ + ptr = fastdecode_longsize(ptr, &size); \ + } \ + \ + if (UPB_UNLIKELY(!upb_EpsCopyInputStream_CheckDataSizeAvailable( \ + &d->input, ptr, size) || \ + (size % valbytes) != 0)) { \ + _upb_FastDecoder_ErrorJmp(d, kUpb_DecodeStatus_Malformed); \ + } \ + \ + upb_Array** arr_p = fastdecode_fieldmem(msg, data); \ + upb_Array* arr = *arr_p; \ + uint8_t elem_size_lg2 = __builtin_ctz(valbytes); \ + int elems = size / valbytes; \ + \ + if (UPB_LIKELY(!arr)) { \ + *arr_p = arr = \ + UPB_PRIVATE(_upb_Array_New)(&d->arena, elems, elem_size_lg2); \ + if (!arr) { \ + _upb_FastDecoder_ErrorJmp(d, kUpb_DecodeStatus_Malformed); \ + } \ + } else { \ + _upb_Array_ResizeUninitialized(arr, elems, &d->arena); \ + } \ + \ + char* dst = _upb_array_ptr(arr); \ + memcpy(dst, ptr, size); \ + arr->UPB_PRIVATE(size) = elems; \ + \ + ptr += size; \ + UPB_MUSTTAIL return fastdecode_dispatch(UPB_PARSE_ARGS); + +#define FASTDECODE_FIXED(d, ptr, msg, table, hasbits, data, tagbytes, \ + valbytes, card, unpacked, packed) \ + if (card == CARD_p) { \ + FASTDECODE_PACKEDFIXED(d, ptr, msg, table, hasbits, data, tagbytes, \ + valbytes, unpacked); \ + } else { \ + FASTDECODE_UNPACKEDFIXED(d, ptr, msg, table, hasbits, data, tagbytes, \ + valbytes, card, packed); \ } -#undef VARINT_CASE - if (packed) { - encode_varint(e, e->limit - e->ptr - pre_len); - encode_tag(e, f->UPB_PRIVATE(number), kUpb_WireType_Delimited); +/* Generate all combinations: + * {s,o,r,p} x {f4,f8} x {1bt,2bt} */ + +#define F(card, valbytes, tagbytes) \ + UPB_NOINLINE \ + const char* upb_p##card##f##valbytes##_##tagbytes##bt(UPB_PARSE_PARAMS) { \ + FASTDECODE_FIXED(d, ptr, msg, table, hasbits, data, tagbytes, valbytes, \ + CARD_##card, upb_ppf##valbytes##_##tagbytes##bt, \ + upb_prf##valbytes##_##tagbytes##bt); \ } -} -static void encode_mapentry(upb_encstate* e, uint32_t number, - const upb_MiniTable* layout, - const upb_MapEntry* ent) { - const upb_MiniTableField* key_field = &layout->UPB_PRIVATE(fields)[0]; - const upb_MiniTableField* val_field = &layout->UPB_PRIVATE(fields)[1]; - size_t pre_len = e->limit - e->ptr; - size_t size; - encode_scalar(e, &ent->data.v, layout->UPB_PRIVATE(subs), val_field); - encode_scalar(e, &ent->data.k, layout->UPB_PRIVATE(subs), key_field); - size = (e->limit - e->ptr) - pre_len; - encode_varint(e, size); - encode_tag(e, number, kUpb_WireType_Delimited); -} +#define TYPES(card, tagbytes) \ + F(card, 4, tagbytes) \ + F(card, 8, tagbytes) -static void encode_map(upb_encstate* e, const upb_Message* msg, - const upb_MiniTableSub* subs, - const upb_MiniTableField* f) { - const upb_Map* map = *UPB_PTR_AT(msg, f->UPB_PRIVATE(offset), const upb_Map*); - const upb_MiniTable* layout = - upb_MiniTableSub_Message(subs[f->UPB_PRIVATE(submsg_index)]); - UPB_ASSERT(layout->UPB_PRIVATE(field_count) == 2); +#define TAGBYTES(card) \ + TYPES(card, 1) \ + TYPES(card, 2) - if (map == NULL) return; +TAGBYTES(s) +TAGBYTES(o) +TAGBYTES(r) +TAGBYTES(p) - if (e->options & kUpb_EncodeOption_Deterministic) { - _upb_sortedmap sorted; - _upb_mapsorter_pushmap( - &e->sorter, layout->UPB_PRIVATE(fields)[0].UPB_PRIVATE(descriptortype), - map, &sorted); - upb_MapEntry ent; - while (_upb_sortedmap_next(&e->sorter, map, &sorted, &ent)) { - encode_mapentry(e, f->UPB_PRIVATE(number), layout, &ent); - } - _upb_mapsorter_popmap(&e->sorter, &sorted); - } else { - intptr_t iter = UPB_STRTABLE_BEGIN; - upb_StringView key; - upb_value val; - while (upb_strtable_next2(&map->table, &key, &val, &iter)) { - upb_MapEntry ent; - _upb_map_fromkey(key, &ent.data.k, map->key_size); - _upb_map_fromvalue(val, &ent.data.v, map->val_size); - encode_mapentry(e, f->UPB_PRIVATE(number), layout, &ent); - } - } -} +#undef F +#undef TYPES +#undef TAGBYTES +#undef FASTDECODE_UNPACKEDFIXED +#undef FASTDECODE_PACKEDFIXED -static bool encode_shouldencode(upb_encstate* e, const upb_Message* msg, - const upb_MiniTableSub* subs, - const upb_MiniTableField* f) { - if (f->presence == 0) { - // Proto3 presence or map/array. - const void* mem = UPB_PTR_AT(msg, f->UPB_PRIVATE(offset), void); - switch (UPB_PRIVATE(_upb_MiniTableField_GetRep)(f)) { - case kUpb_FieldRep_1Byte: { - char ch; - memcpy(&ch, mem, 1); - return ch != 0; - } - case kUpb_FieldRep_4Byte: { - uint32_t u32; - memcpy(&u32, mem, 4); - return u32 != 0; - } - case kUpb_FieldRep_8Byte: { - uint64_t u64; - memcpy(&u64, mem, 8); - return u64 != 0; - } - case kUpb_FieldRep_StringView: { - const upb_StringView* str = (const upb_StringView*)mem; - return str->size != 0; - } - default: - UPB_UNREACHABLE(); - } - } else if (f->presence > 0) { - // Proto2 presence: hasbit. - return UPB_PRIVATE(_upb_Message_GetHasbit)(msg, f); - } else { - // Field is in a oneof. - return UPB_PRIVATE(_upb_Message_GetOneofCase)(msg, f) == - f->UPB_PRIVATE(number); +/* string fields **************************************************************/ + +typedef const char* fastdecode_copystr_func(struct upb_Decoder* d, + const char* ptr, upb_Message* msg, + const upb_MiniTable* table, + uint64_t hasbits, + upb_StringView* dst); + +UPB_NOINLINE +static const char* fastdecode_verifyutf8(upb_Decoder* d, const char* ptr, + upb_Message* msg, intptr_t table, + uint64_t hasbits, uint64_t data) { + upb_StringView* dst = (upb_StringView*)data; + if (!_upb_Decoder_VerifyUtf8Inline(dst->data, dst->size)) { + _upb_FastDecoder_ErrorJmp(d, kUpb_DecodeStatus_BadUtf8); } + UPB_MUSTTAIL return fastdecode_dispatch(UPB_PARSE_ARGS); } -static void encode_field(upb_encstate* e, const upb_Message* msg, - const upb_MiniTableSub* subs, - const upb_MiniTableField* field) { - switch (UPB_PRIVATE(_upb_MiniTableField_Mode)(field)) { - case kUpb_FieldMode_Array: - encode_array(e, msg, subs, field); - break; - case kUpb_FieldMode_Map: - encode_map(e, msg, subs, field); - break; - case kUpb_FieldMode_Scalar: - encode_scalar(e, UPB_PTR_AT(msg, field->UPB_PRIVATE(offset), void), subs, - field); - break; - default: - UPB_UNREACHABLE(); +#define FASTDECODE_LONGSTRING(d, ptr, msg, table, hasbits, dst, validate_utf8) \ + int size = (uint8_t)ptr[0]; /* Could plumb through hasbits. */ \ + ptr++; \ + if (size & 0x80) { \ + ptr = fastdecode_longsize(ptr, &size); \ + } \ + \ + if (UPB_UNLIKELY(!upb_EpsCopyInputStream_CheckSize(&d->input, ptr, size))) { \ + dst->size = 0; \ + _upb_FastDecoder_ErrorJmp(d, kUpb_DecodeStatus_Malformed); \ + } \ + \ + const char* s_ptr = ptr; \ + ptr = upb_EpsCopyInputStream_ReadString(&d->input, &s_ptr, size, &d->arena); \ + if (!ptr) _upb_FastDecoder_ErrorJmp(d, kUpb_DecodeStatus_OutOfMemory); \ + dst->data = s_ptr; \ + dst->size = size; \ + \ + if (validate_utf8) { \ + data = (uint64_t)dst; \ + UPB_MUSTTAIL return fastdecode_verifyutf8(UPB_PARSE_ARGS); \ + } else { \ + UPB_MUSTTAIL return fastdecode_dispatch(UPB_PARSE_ARGS); \ } + +UPB_NOINLINE +static const char* fastdecode_longstring_utf8(struct upb_Decoder* d, + const char* ptr, upb_Message* msg, + intptr_t table, uint64_t hasbits, + uint64_t data) { + upb_StringView* dst = (upb_StringView*)data; + FASTDECODE_LONGSTRING(d, ptr, msg, table, hasbits, dst, true); } -static void encode_msgset_item(upb_encstate* e, const upb_Extension* ext) { - size_t size; - encode_tag(e, kUpb_MsgSet_Item, kUpb_WireType_EndGroup); - encode_message(e, ext->data.ptr, - upb_MiniTableExtension_GetSubMessage(ext->ext), &size); - encode_varint(e, size); - encode_tag(e, kUpb_MsgSet_Message, kUpb_WireType_Delimited); - encode_varint(e, upb_MiniTableExtension_Number(ext->ext)); - encode_tag(e, kUpb_MsgSet_TypeId, kUpb_WireType_Varint); - encode_tag(e, kUpb_MsgSet_Item, kUpb_WireType_StartGroup); +UPB_NOINLINE +static const char* fastdecode_longstring_noutf8( + struct upb_Decoder* d, const char* ptr, upb_Message* msg, intptr_t table, + uint64_t hasbits, uint64_t data) { + upb_StringView* dst = (upb_StringView*)data; + FASTDECODE_LONGSTRING(d, ptr, msg, table, hasbits, dst, false); +} + +UPB_FORCEINLINE +static void fastdecode_docopy(upb_Decoder* d, const char* ptr, uint32_t size, + int copy, char* data, size_t data_offset, + upb_StringView* dst) { + d->arena.UPB_PRIVATE(ptr) += copy; + dst->data = data + data_offset; + UPB_UNPOISON_MEMORY_REGION(data, copy); + memcpy(data, ptr, copy); + UPB_POISON_MEMORY_REGION(data + data_offset + size, + copy - data_offset - size); } -static void encode_ext(upb_encstate* e, const upb_Extension* ext, - bool is_message_set) { - if (UPB_UNLIKELY(is_message_set)) { - encode_msgset_item(e, ext); - } else { - encode_field(e, (upb_Message*)&ext->data, &ext->ext->UPB_PRIVATE(sub), - &ext->ext->UPB_PRIVATE(field)); +#define FASTDECODE_COPYSTRING(d, ptr, msg, table, hasbits, data, tagbytes, \ + card, validate_utf8) \ + upb_StringView* dst; \ + fastdecode_arr farr; \ + int64_t size; \ + size_t arena_has; \ + size_t common_has; \ + char* buf; \ + \ + UPB_ASSERT(!upb_EpsCopyInputStream_AliasingAvailable(&d->input, ptr, 0)); \ + UPB_ASSERT(fastdecode_checktag(data, tagbytes)); \ + \ + dst = fastdecode_getfield(d, ptr, msg, &data, &hasbits, &farr, \ + sizeof(upb_StringView), card); \ + \ + again: \ + if (card == CARD_r) { \ + dst = fastdecode_resizearr(d, dst, &farr, sizeof(upb_StringView)); \ + } \ + \ + size = (uint8_t)ptr[tagbytes]; \ + ptr += tagbytes + 1; \ + dst->size = size; \ + \ + buf = d->arena.UPB_PRIVATE(ptr); \ + arena_has = UPB_PRIVATE(_upb_ArenaHas)(&d->arena); \ + common_has = UPB_MIN(arena_has, \ + upb_EpsCopyInputStream_BytesAvailable(&d->input, ptr)); \ + \ + if (UPB_LIKELY(size <= 15 - tagbytes)) { \ + if (arena_has < 16) goto longstr; \ + fastdecode_docopy(d, ptr - tagbytes - 1, size, 16, buf, tagbytes + 1, \ + dst); \ + } else if (UPB_LIKELY(size <= 32)) { \ + if (UPB_UNLIKELY(common_has < 32)) goto longstr; \ + fastdecode_docopy(d, ptr, size, 32, buf, 0, dst); \ + } else if (UPB_LIKELY(size <= 64)) { \ + if (UPB_UNLIKELY(common_has < 64)) goto longstr; \ + fastdecode_docopy(d, ptr, size, 64, buf, 0, dst); \ + } else if (UPB_LIKELY(size < 128)) { \ + if (UPB_UNLIKELY(common_has < 128)) goto longstr; \ + fastdecode_docopy(d, ptr, size, 128, buf, 0, dst); \ + } else { \ + goto longstr; \ + } \ + \ + ptr += size; \ + \ + if (card == CARD_r) { \ + if (validate_utf8 && \ + !_upb_Decoder_VerifyUtf8Inline(dst->data, dst->size)) { \ + _upb_FastDecoder_ErrorJmp(d, kUpb_DecodeStatus_BadUtf8); \ + } \ + fastdecode_nextret ret = fastdecode_nextrepeated( \ + d, dst, &ptr, &farr, data, tagbytes, sizeof(upb_StringView)); \ + switch (ret.next) { \ + case FD_NEXT_SAMEFIELD: \ + dst = ret.dst; \ + goto again; \ + case FD_NEXT_OTHERFIELD: \ + data = ret.tag; \ + UPB_MUSTTAIL return _upb_FastDecoder_TagDispatch(UPB_PARSE_ARGS); \ + case FD_NEXT_ATLIMIT: \ + return ptr; \ + } \ + } \ + \ + if (card != CARD_r && validate_utf8) { \ + data = (uint64_t)dst; \ + UPB_MUSTTAIL return fastdecode_verifyutf8(UPB_PARSE_ARGS); \ + } \ + \ + UPB_MUSTTAIL return fastdecode_dispatch(UPB_PARSE_ARGS); \ + \ + longstr: \ + if (card == CARD_r) { \ + fastdecode_commitarr(dst + 1, &farr, sizeof(upb_StringView)); \ + } \ + ptr--; \ + if (validate_utf8) { \ + UPB_MUSTTAIL return fastdecode_longstring_utf8(d, ptr, msg, table, \ + hasbits, (uint64_t)dst); \ + } else { \ + UPB_MUSTTAIL return fastdecode_longstring_noutf8(d, ptr, msg, table, \ + hasbits, (uint64_t)dst); \ + } + +#define FASTDECODE_STRING(d, ptr, msg, table, hasbits, data, tagbytes, card, \ + copyfunc, validate_utf8) \ + upb_StringView* dst; \ + fastdecode_arr farr; \ + int64_t size; \ + \ + if (UPB_UNLIKELY(!fastdecode_checktag(data, tagbytes))) { \ + RETURN_GENERIC("string field tag mismatch\n"); \ + } \ + \ + if (UPB_UNLIKELY( \ + !upb_EpsCopyInputStream_AliasingAvailable(&d->input, ptr, 0))) { \ + UPB_MUSTTAIL return copyfunc(UPB_PARSE_ARGS); \ + } \ + \ + dst = fastdecode_getfield(d, ptr, msg, &data, &hasbits, &farr, \ + sizeof(upb_StringView), card); \ + \ + again: \ + if (card == CARD_r) { \ + dst = fastdecode_resizearr(d, dst, &farr, sizeof(upb_StringView)); \ + } \ + \ + size = (int8_t)ptr[tagbytes]; \ + ptr += tagbytes + 1; \ + \ + if (UPB_UNLIKELY( \ + !upb_EpsCopyInputStream_AliasingAvailable(&d->input, ptr, size))) { \ + ptr--; \ + if (validate_utf8) { \ + return fastdecode_longstring_utf8(d, ptr, msg, table, hasbits, \ + (uint64_t)dst); \ + } else { \ + return fastdecode_longstring_noutf8(d, ptr, msg, table, hasbits, \ + (uint64_t)dst); \ + } \ + } \ + \ + dst->data = ptr; \ + dst->size = size; \ + ptr = upb_EpsCopyInputStream_ReadStringAliased(&d->input, &dst->data, \ + dst->size); \ + \ + if (card == CARD_r) { \ + if (validate_utf8 && \ + !_upb_Decoder_VerifyUtf8Inline(dst->data, dst->size)) { \ + _upb_FastDecoder_ErrorJmp(d, kUpb_DecodeStatus_BadUtf8); \ + } \ + fastdecode_nextret ret = fastdecode_nextrepeated( \ + d, dst, &ptr, &farr, data, tagbytes, sizeof(upb_StringView)); \ + switch (ret.next) { \ + case FD_NEXT_SAMEFIELD: \ + dst = ret.dst; \ + goto again; \ + case FD_NEXT_OTHERFIELD: \ + data = ret.tag; \ + UPB_MUSTTAIL return _upb_FastDecoder_TagDispatch(UPB_PARSE_ARGS); \ + case FD_NEXT_ATLIMIT: \ + return ptr; \ + } \ + } \ + \ + if (card != CARD_r && validate_utf8) { \ + data = (uint64_t)dst; \ + UPB_MUSTTAIL return fastdecode_verifyutf8(UPB_PARSE_ARGS); \ + } \ + \ + UPB_MUSTTAIL return fastdecode_dispatch(UPB_PARSE_ARGS); + +/* Generate all combinations: + * {p,c} x {s,o,r} x {s, b} x {1bt,2bt} */ + +#define s_VALIDATE true +#define b_VALIDATE false + +#define F(card, tagbytes, type) \ + UPB_NOINLINE \ + const char* upb_c##card##type##_##tagbytes##bt(UPB_PARSE_PARAMS) { \ + FASTDECODE_COPYSTRING(d, ptr, msg, table, hasbits, data, tagbytes, \ + CARD_##card, type##_VALIDATE); \ + } \ + const char* upb_p##card##type##_##tagbytes##bt(UPB_PARSE_PARAMS) { \ + FASTDECODE_STRING(d, ptr, msg, table, hasbits, data, tagbytes, \ + CARD_##card, upb_c##card##type##_##tagbytes##bt, \ + type##_VALIDATE); \ } -} -static void encode_message(upb_encstate* e, const upb_Message* msg, - const upb_MiniTable* m, size_t* size) { - size_t pre_len = e->limit - e->ptr; +#define UTF8(card, tagbytes) \ + F(card, tagbytes, s) \ + F(card, tagbytes, b) - if ((e->options & kUpb_EncodeOption_CheckRequired) && - m->UPB_PRIVATE(required_count)) { - uint64_t msg_head; - memcpy(&msg_head, msg, 8); - msg_head = _upb_BigEndian_Swap64(msg_head); - if (UPB_PRIVATE(_upb_MiniTable_RequiredMask)(m) & ~msg_head) { - encode_err(e, kUpb_EncodeStatus_MissingRequired); - } - } +#define TAGBYTES(card) \ + UTF8(card, 1) \ + UTF8(card, 2) - if ((e->options & kUpb_EncodeOption_SkipUnknown) == 0) { - size_t unknown_size; - const char* unknown = upb_Message_GetUnknown(msg, &unknown_size); +TAGBYTES(s) +TAGBYTES(o) +TAGBYTES(r) - if (unknown) { - encode_bytes(e, unknown, unknown_size); - } - } +#undef s_VALIDATE +#undef b_VALIDATE +#undef F +#undef TAGBYTES +#undef FASTDECODE_LONGSTRING +#undef FASTDECODE_COPYSTRING +#undef FASTDECODE_STRING - if (m->UPB_PRIVATE(ext) != kUpb_ExtMode_NonExtendable) { - /* Encode all extensions together. Unlike C++, we do not attempt to keep - * these in field number order relative to normal fields or even to each - * other. */ - size_t ext_count; - const upb_Extension* ext = - UPB_PRIVATE(_upb_Message_Getexts)(msg, &ext_count); - if (ext_count) { - if (e->options & kUpb_EncodeOption_Deterministic) { - _upb_sortedmap sorted; - _upb_mapsorter_pushexts(&e->sorter, ext, ext_count, &sorted); - while (_upb_sortedmap_nextext(&e->sorter, &sorted, &ext)) { - encode_ext(e, ext, m->UPB_PRIVATE(ext) == kUpb_ExtMode_IsMessageSet); - } - _upb_mapsorter_popmap(&e->sorter, &sorted); - } else { - const upb_Extension* end = ext + ext_count; - for (; ext != end; ext++) { - encode_ext(e, ext, m->UPB_PRIVATE(ext) == kUpb_ExtMode_IsMessageSet); - } - } - } - } +/* message fields *************************************************************/ - if (m->UPB_PRIVATE(field_count)) { - const upb_MiniTableField* f = - &m->UPB_PRIVATE(fields)[m->UPB_PRIVATE(field_count)]; - const upb_MiniTableField* first = &m->UPB_PRIVATE(fields)[0]; - while (f != first) { - f--; - if (encode_shouldencode(e, msg, m->UPB_PRIVATE(subs), f)) { - encode_field(e, msg, m->UPB_PRIVATE(subs), f); - } - } +UPB_INLINE +upb_Message* decode_newmsg_ceil(upb_Decoder* d, const upb_MiniTable* m, + int msg_ceil_bytes) { + size_t size = m->UPB_PRIVATE(size) + sizeof(upb_Message_Internal); + char* msg_data; + if (UPB_LIKELY(msg_ceil_bytes > 0 && + UPB_PRIVATE(_upb_ArenaHas)(&d->arena) >= msg_ceil_bytes)) { + UPB_ASSERT(size <= (size_t)msg_ceil_bytes); + msg_data = d->arena.UPB_PRIVATE(ptr); + d->arena.UPB_PRIVATE(ptr) += size; + UPB_UNPOISON_MEMORY_REGION(msg_data, msg_ceil_bytes); + memset(msg_data, 0, msg_ceil_bytes); + UPB_POISON_MEMORY_REGION(msg_data + size, msg_ceil_bytes - size); + } else { + msg_data = (char*)upb_Arena_Malloc(&d->arena, size); + memset(msg_data, 0, size); } + return msg_data + sizeof(upb_Message_Internal); +} - *size = (e->limit - e->ptr) - pre_len; +typedef struct { + intptr_t table; + upb_Message* msg; +} fastdecode_submsgdata; + +UPB_FORCEINLINE +static const char* fastdecode_tosubmsg(upb_EpsCopyInputStream* e, + const char* ptr, void* ctx) { + upb_Decoder* d = (upb_Decoder*)e; + fastdecode_submsgdata* submsg = ctx; + ptr = fastdecode_dispatch(d, ptr, submsg->msg, submsg->table, 0, 0); + UPB_ASSUME(ptr != NULL); + return ptr; } -static upb_EncodeStatus upb_Encoder_Encode(upb_encstate* const encoder, - const upb_Message* const msg, - const upb_MiniTable* const l, - char** const buf, - size_t* const size) { - // Unfortunately we must continue to perform hackery here because there are - // code paths which blindly copy the returned pointer without bothering to - // check for errors until much later (b/235839510). So we still set *buf to - // NULL on error and we still set it to non-NULL on a successful empty result. - if (UPB_SETJMP(encoder->err) == 0) { - encode_message(encoder, msg, l, size); - *size = encoder->limit - encoder->ptr; - if (*size == 0) { - static char ch; - *buf = &ch; - } else { - UPB_ASSERT(encoder->ptr); - *buf = encoder->ptr; - } - } else { - UPB_ASSERT(encoder->status != kUpb_EncodeStatus_Ok); - *buf = NULL; - *size = 0; +#define FASTDECODE_SUBMSG(d, ptr, msg, table, hasbits, data, tagbytes, \ + msg_ceil_bytes, card) \ + \ + if (UPB_UNLIKELY(!fastdecode_checktag(data, tagbytes))) { \ + RETURN_GENERIC("submessage field tag mismatch\n"); \ + } \ + \ + if (--d->depth == 0) { \ + _upb_FastDecoder_ErrorJmp(d, kUpb_DecodeStatus_MaxDepthExceeded); \ + } \ + \ + upb_Message** dst; \ + uint32_t submsg_idx = (data >> 16) & 0xff; \ + const upb_MiniTable* tablep = decode_totablep(table); \ + const upb_MiniTable* subtablep = upb_MiniTableSub_Message( \ + *UPB_PRIVATE(_upb_MiniTable_GetSubByIndex)(tablep, submsg_idx)); \ + fastdecode_submsgdata submsg = {decode_totable(subtablep)}; \ + fastdecode_arr farr; \ + \ + if (subtablep->UPB_PRIVATE(table_mask) == (uint8_t)-1) { \ + d->depth++; \ + RETURN_GENERIC("submessage doesn't have fast tables."); \ + } \ + \ + dst = fastdecode_getfield(d, ptr, msg, &data, &hasbits, &farr, \ + sizeof(upb_Message*), card); \ + \ + if (card == CARD_s) { \ + *(uint32_t*)msg |= hasbits; \ + hasbits = 0; \ + } \ + \ + again: \ + if (card == CARD_r) { \ + dst = fastdecode_resizearr(d, dst, &farr, sizeof(upb_Message*)); \ + } \ + \ + submsg.msg = *dst; \ + \ + if (card == CARD_r || UPB_LIKELY(!submsg.msg)) { \ + *dst = submsg.msg = decode_newmsg_ceil(d, subtablep, msg_ceil_bytes); \ + } \ + \ + ptr += tagbytes; \ + ptr = fastdecode_delimited(d, ptr, fastdecode_tosubmsg, &submsg); \ + \ + if (UPB_UNLIKELY(ptr == NULL || d->end_group != DECODE_NOGROUP)) { \ + _upb_FastDecoder_ErrorJmp(d, kUpb_DecodeStatus_Malformed); \ + } \ + \ + if (card == CARD_r) { \ + fastdecode_nextret ret = fastdecode_nextrepeated( \ + d, dst, &ptr, &farr, data, tagbytes, sizeof(upb_Message*)); \ + switch (ret.next) { \ + case FD_NEXT_SAMEFIELD: \ + dst = ret.dst; \ + goto again; \ + case FD_NEXT_OTHERFIELD: \ + d->depth++; \ + data = ret.tag; \ + UPB_MUSTTAIL return _upb_FastDecoder_TagDispatch(UPB_PARSE_ARGS); \ + case FD_NEXT_ATLIMIT: \ + d->depth++; \ + return ptr; \ + } \ + } \ + \ + d->depth++; \ + UPB_MUSTTAIL return fastdecode_dispatch(UPB_PARSE_ARGS); + +#define F(card, tagbytes, size_ceil, ceil_arg) \ + const char* upb_p##card##m_##tagbytes##bt_max##size_ceil##b( \ + UPB_PARSE_PARAMS) { \ + FASTDECODE_SUBMSG(d, ptr, msg, table, hasbits, data, tagbytes, ceil_arg, \ + CARD_##card); \ } - _upb_mapsorter_destroy(&encoder->sorter); - return encoder->status; -} +#define SIZES(card, tagbytes) \ + F(card, tagbytes, 64, 64) \ + F(card, tagbytes, 128, 128) \ + F(card, tagbytes, 192, 192) \ + F(card, tagbytes, 256, 256) \ + F(card, tagbytes, max, -1) -upb_EncodeStatus upb_Encode(const upb_Message* msg, const upb_MiniTable* l, - int options, upb_Arena* arena, char** buf, - size_t* size) { - upb_encstate e; - unsigned depth = (unsigned)options >> 16; +#define TAGBYTES(card) \ + SIZES(card, 1) \ + SIZES(card, 2) - e.status = kUpb_EncodeStatus_Ok; - e.arena = arena; - e.buf = NULL; - e.limit = NULL; - e.ptr = NULL; - e.depth = depth ? depth : kUpb_WireFormat_DefaultDepthLimit; - e.options = options; - _upb_mapsorter_init(&e.sorter); +TAGBYTES(s) +TAGBYTES(o) +TAGBYTES(r) + +#undef TAGBYTES +#undef SIZES +#undef F +#undef FASTDECODE_SUBMSG + +#endif /* UPB_FASTTABLE */ - return upb_Encoder_Encode(&e, msg, l, buf, size); -} +#include +#include // Must be last. -UPB_NOINLINE _upb_WireReader_ReadLongVarintRet -_upb_WireReader_ReadLongVarint(const char* ptr, uint64_t val) { - _upb_WireReader_ReadLongVarintRet ret = {NULL, 0}; +UPB_NOINLINE UPB_PRIVATE(_upb_WireReader_LongVarint) + UPB_PRIVATE(_upb_WireReader_ReadLongVarint)(const char* ptr, uint64_t val) { + UPB_PRIVATE(_upb_WireReader_LongVarint) ret = {NULL, 0}; uint64_t byte; int i; for (i = 1; i < 10; i++) { @@ -15289,9 +15292,9 @@ _upb_WireReader_ReadLongVarint(const char* ptr, uint64_t val) { return ret; } -const char* _upb_WireReader_SkipGroup(const char* ptr, uint32_t tag, - int depth_limit, - upb_EpsCopyInputStream* stream) { +const char* UPB_PRIVATE(_upb_WireReader_SkipGroup)( + const char* ptr, uint32_t tag, int depth_limit, + upb_EpsCopyInputStream* stream) { if (--depth_limit == 0) return NULL; uint32_t end_group_tag = (tag & ~7ULL) | kUpb_WireType_EndGroup; while (!upb_EpsCopyInputStream_IsDone(stream, &ptr)) { diff --git a/ruby/ext/google/protobuf_c/ruby-upb.h b/ruby/ext/google/protobuf_c/ruby-upb.h index 005e2349c2861..d6444164c49bc 100755 --- a/ruby/ext/google/protobuf_c/ruby-upb.h +++ b/ruby/ext/google/protobuf_c/ruby-upb.h @@ -1356,8 +1356,9 @@ UPB_INLINE const upb_MiniTable* UPB_PRIVATE(_upb_MiniTableSub_Message)( // Must be last. struct upb_Decoder; +struct upb_Message; typedef const char* _upb_FieldParser(struct upb_Decoder* d, const char* ptr, - upb_Message* msg, intptr_t table, + struct upb_Message* msg, intptr_t table, uint64_t hasbits, uint64_t data); typedef struct { uint64_t field_data; @@ -4006,6 +4007,72 @@ UPB_API upb_DecodeStatus upb_Decode(const char* buf, size_t size, #endif /* UPB_WIRE_DECODE_H_ */ +// upb_Encode: parsing from a upb_Message using a upb_MiniTable. + +#ifndef UPB_WIRE_ENCODE_H_ +#define UPB_WIRE_ENCODE_H_ + +#include +#include + + +// Must be last. + +#ifdef __cplusplus +extern "C" { +#endif + +enum { + /* If set, the results of serializing will be deterministic across all + * instances of this binary. There are no guarantees across different + * binary builds. + * + * If your proto contains maps, the encoder will need to malloc()/free() + * memory during encode. */ + kUpb_EncodeOption_Deterministic = 1, + + // When set, unknown fields are not printed. + kUpb_EncodeOption_SkipUnknown = 2, + + // When set, the encode will fail if any required fields are missing. + kUpb_EncodeOption_CheckRequired = 4, +}; + +typedef enum { + kUpb_EncodeStatus_Ok = 0, + kUpb_EncodeStatus_OutOfMemory = 1, // Arena alloc failed + kUpb_EncodeStatus_MaxDepthExceeded = 2, + + // kUpb_EncodeOption_CheckRequired failed but the parse otherwise succeeded. + kUpb_EncodeStatus_MissingRequired = 3, +} upb_EncodeStatus; + +UPB_INLINE uint32_t upb_EncodeOptions_MaxDepth(uint16_t depth) { + return (uint32_t)depth << 16; +} + +UPB_INLINE uint16_t upb_EncodeOptions_GetMaxDepth(uint32_t options) { + return options >> 16; +} + +// Enforce an upper bound on recursion depth. +UPB_INLINE int upb_Encode_LimitDepth(uint32_t encode_options, uint32_t limit) { + uint32_t max_depth = upb_EncodeOptions_GetMaxDepth(encode_options); + if (max_depth > limit) max_depth = limit; + return upb_EncodeOptions_MaxDepth(max_depth) | (encode_options & 0xffff); +} + +UPB_API upb_EncodeStatus upb_Encode(const upb_Message* msg, + const upb_MiniTable* l, int options, + upb_Arena* arena, char** buf, size_t* size); + +#ifdef __cplusplus +} /* extern "C" */ +#endif + + +#endif /* UPB_WIRE_ENCODE_H_ */ + // These are the specialized field parser functions for the fast parser. // Generated tables will refer to these by name. // @@ -4040,8 +4107,8 @@ UPB_API upb_DecodeStatus upb_Decode(const char* buf, size_t size, // - '1' for one-byte tags (field numbers 1-15) // - '2' for two-byte tags (field numbers 16-2048) -#ifndef UPB_WIRE_DECODE_FAST_H_ -#define UPB_WIRE_DECODE_FAST_H_ +#ifndef UPB_WIRE_DECODE_INTERNAL_FAST_H_ +#define UPB_WIRE_DECODE_INTERNAL_FAST_H_ // Must be last. @@ -4142,73 +4209,7 @@ TAGBYTES(r) #endif -#endif /* UPB_WIRE_DECODE_FAST_H_ */ - -// upb_Encode: parsing from a upb_Message using a upb_MiniTable. - -#ifndef UPB_WIRE_ENCODE_H_ -#define UPB_WIRE_ENCODE_H_ - -#include -#include - - -// Must be last. - -#ifdef __cplusplus -extern "C" { -#endif - -enum { - /* If set, the results of serializing will be deterministic across all - * instances of this binary. There are no guarantees across different - * binary builds. - * - * If your proto contains maps, the encoder will need to malloc()/free() - * memory during encode. */ - kUpb_EncodeOption_Deterministic = 1, - - // When set, unknown fields are not printed. - kUpb_EncodeOption_SkipUnknown = 2, - - // When set, the encode will fail if any required fields are missing. - kUpb_EncodeOption_CheckRequired = 4, -}; - -typedef enum { - kUpb_EncodeStatus_Ok = 0, - kUpb_EncodeStatus_OutOfMemory = 1, // Arena alloc failed - kUpb_EncodeStatus_MaxDepthExceeded = 2, - - // kUpb_EncodeOption_CheckRequired failed but the parse otherwise succeeded. - kUpb_EncodeStatus_MissingRequired = 3, -} upb_EncodeStatus; - -UPB_INLINE uint32_t upb_EncodeOptions_MaxDepth(uint16_t depth) { - return (uint32_t)depth << 16; -} - -UPB_INLINE uint16_t upb_EncodeOptions_GetMaxDepth(uint32_t options) { - return options >> 16; -} - -// Enforce an upper bound on recursion depth. -UPB_INLINE int upb_Encode_LimitDepth(uint32_t encode_options, uint32_t limit) { - uint32_t max_depth = upb_EncodeOptions_GetMaxDepth(encode_options); - if (max_depth > limit) max_depth = limit; - return upb_EncodeOptions_MaxDepth(max_depth) | (encode_options & 0xffff); -} - -UPB_API upb_EncodeStatus upb_Encode(const upb_Message* msg, - const upb_MiniTable* l, int options, - upb_Arena* arena, char** buf, size_t* size); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - - -#endif /* UPB_WIRE_ENCODE_H_ */ +#endif /* UPB_WIRE_DECODE_INTERNAL_FAST_H_ */ // IWYU pragma: end_exports #endif // UPB_GENERATED_CODE_SUPPORT_H_ @@ -13533,8 +13534,8 @@ UPB_INLINE uint32_t _upb_FastDecoder_LoadTag(const char* ptr) { #endif /* UPB_WIRE_INTERNAL_DECODE_H_ */ -#ifndef UPB_WIRE_INTERNAL_SWAP_H_ -#define UPB_WIRE_INTERNAL_SWAP_H_ +#ifndef UPB_WIRE_INTERNAL_ENDIAN_H_ +#define UPB_WIRE_INTERNAL_ENDIAN_H_ #include @@ -13544,23 +13545,23 @@ UPB_INLINE uint32_t _upb_FastDecoder_LoadTag(const char* ptr) { extern "C" { #endif -UPB_INLINE bool _upb_IsLittleEndian(void) { - int x = 1; +UPB_INLINE bool UPB_PRIVATE(_upb_IsLittleEndian)(void) { + const int x = 1; return *(char*)&x == 1; } -UPB_INLINE uint32_t _upb_BigEndian_Swap32(uint32_t val) { - if (_upb_IsLittleEndian()) return val; +UPB_INLINE uint32_t UPB_PRIVATE(_upb_BigEndian32)(uint32_t val) { + if (UPB_PRIVATE(_upb_IsLittleEndian)()) return val; return ((val & 0xff) << 24) | ((val & 0xff00) << 8) | ((val & 0xff0000) >> 8) | ((val & 0xff000000) >> 24); } -UPB_INLINE uint64_t _upb_BigEndian_Swap64(uint64_t val) { - if (_upb_IsLittleEndian()) return val; +UPB_INLINE uint64_t UPB_PRIVATE(_upb_BigEndian64)(uint64_t val) { + if (UPB_PRIVATE(_upb_IsLittleEndian)()) return val; - return ((uint64_t)_upb_BigEndian_Swap32((uint32_t)val) << 32) | - _upb_BigEndian_Swap32((uint32_t)(val >> 32)); + return ((uint64_t)UPB_PRIVATE(_upb_BigEndian32)((uint32_t)val) << 32) | + UPB_PRIVATE(_upb_BigEndian32)((uint32_t)(val >> 32)); } #ifdef __cplusplus @@ -13568,62 +13569,42 @@ UPB_INLINE uint64_t _upb_BigEndian_Swap64(uint64_t val) { #endif -#endif /* UPB_WIRE_INTERNAL_SWAP_H_ */ +#endif /* UPB_WIRE_INTERNAL_ENDIAN_H_ */ #ifndef UPB_WIRE_READER_H_ #define UPB_WIRE_READER_H_ -#ifndef UPB_WIRE_TYPES_H_ -#define UPB_WIRE_TYPES_H_ - -// A list of types as they are encoded on the wire. -typedef enum { - kUpb_WireType_Varint = 0, - kUpb_WireType_64Bit = 1, - kUpb_WireType_Delimited = 2, - kUpb_WireType_StartGroup = 3, - kUpb_WireType_EndGroup = 4, - kUpb_WireType_32Bit = 5 -} upb_WireType; - -#endif /* UPB_WIRE_TYPES_H_ */ +#ifndef UPB_WIRE_INTERNAL_READER_H_ +#define UPB_WIRE_INTERNAL_READER_H_ // Must be last. -#ifdef __cplusplus -extern "C" { -#endif - -// The upb_WireReader interface is suitable for general-purpose parsing of -// protobuf binary wire format. It is designed to be used along with -// upb_EpsCopyInputStream for buffering, and all parsing routines in this file -// assume that at least kUpb_EpsCopyInputStream_SlopBytes worth of data is -// available to read without any bounds checks. - -#define kUpb_WireReader_WireTypeMask 7 #define kUpb_WireReader_WireTypeBits 3 +#define kUpb_WireReader_WireTypeMask 7 typedef struct { const char* ptr; uint64_t val; -} _upb_WireReader_ReadLongVarintRet; +} UPB_PRIVATE(_upb_WireReader_LongVarint); -_upb_WireReader_ReadLongVarintRet _upb_WireReader_ReadLongVarint( - const char* ptr, uint64_t val); +#ifdef __cplusplus +extern "C" { +#endif + +UPB_PRIVATE(_upb_WireReader_LongVarint) +UPB_PRIVATE(_upb_WireReader_ReadLongVarint)(const char* ptr, uint64_t val); -static UPB_FORCEINLINE const char* _upb_WireReader_ReadVarint(const char* ptr, - uint64_t* val, - int maxlen, - uint64_t maxval) { +static UPB_FORCEINLINE const char* UPB_PRIVATE(_upb_WireReader_ReadVarint)( + const char* ptr, uint64_t* val, int maxlen, uint64_t maxval) { uint64_t byte = (uint8_t)*ptr; if (UPB_LIKELY((byte & 0x80) == 0)) { *val = (uint32_t)byte; return ptr + 1; } const char* start = ptr; - _upb_WireReader_ReadLongVarintRet res = - _upb_WireReader_ReadLongVarint(ptr, byte); + UPB_PRIVATE(_upb_WireReader_LongVarint) + res = UPB_PRIVATE(_upb_WireReader_ReadLongVarint)(ptr, byte); if (!res.ptr || (maxlen < 10 && res.ptr - start > maxlen) || res.val > maxval) { return NULL; // Malformed. @@ -13632,6 +13613,48 @@ static UPB_FORCEINLINE const char* _upb_WireReader_ReadVarint(const char* ptr, return res.ptr; } +UPB_INLINE uint32_t UPB_PRIVATE(_upb_WireReader_GetFieldNumber)(uint32_t tag) { + return tag >> kUpb_WireReader_WireTypeBits; +} + +UPB_INLINE uint8_t UPB_PRIVATE(_upb_WireReader_GetWireType)(uint32_t tag) { + return tag & kUpb_WireReader_WireTypeMask; +} + +#ifdef __cplusplus +} /* extern "C" */ +#endif + + +#endif // UPB_WIRE_INTERNAL_READER_H_ + +#ifndef UPB_WIRE_TYPES_H_ +#define UPB_WIRE_TYPES_H_ + +// A list of types as they are encoded on the wire. +typedef enum { + kUpb_WireType_Varint = 0, + kUpb_WireType_64Bit = 1, + kUpb_WireType_Delimited = 2, + kUpb_WireType_StartGroup = 3, + kUpb_WireType_EndGroup = 4, + kUpb_WireType_32Bit = 5 +} upb_WireType; + +#endif /* UPB_WIRE_TYPES_H_ */ + +// Must be last. + +// The upb_WireReader interface is suitable for general-purpose parsing of +// protobuf binary wire format. It is designed to be used along with +// upb_EpsCopyInputStream for buffering, and all parsing routines in this file +// assume that at least kUpb_EpsCopyInputStream_SlopBytes worth of data is +// available to read without any bounds checks. + +#ifdef __cplusplus +extern "C" { +#endif + // Parses a tag into `tag`, and returns a pointer past the end of the tag, or // NULL if there was an error in the tag data. // @@ -13641,7 +13664,7 @@ static UPB_FORCEINLINE const char* _upb_WireReader_ReadVarint(const char* ptr, static UPB_FORCEINLINE const char* upb_WireReader_ReadTag(const char* ptr, uint32_t* tag) { uint64_t val; - ptr = _upb_WireReader_ReadVarint(ptr, &val, 5, UINT32_MAX); + ptr = UPB_PRIVATE(_upb_WireReader_ReadVarint)(ptr, &val, 5, UINT32_MAX); if (!ptr) return NULL; *tag = val; return ptr; @@ -13649,17 +13672,17 @@ static UPB_FORCEINLINE const char* upb_WireReader_ReadTag(const char* ptr, // Given a tag, returns the field number. UPB_INLINE uint32_t upb_WireReader_GetFieldNumber(uint32_t tag) { - return tag >> kUpb_WireReader_WireTypeBits; + return UPB_PRIVATE(_upb_WireReader_GetFieldNumber)(tag); } // Given a tag, returns the wire type. UPB_INLINE uint8_t upb_WireReader_GetWireType(uint32_t tag) { - return tag & kUpb_WireReader_WireTypeMask; + return UPB_PRIVATE(_upb_WireReader_GetWireType)(tag); } UPB_INLINE const char* upb_WireReader_ReadVarint(const char* ptr, uint64_t* val) { - return _upb_WireReader_ReadVarint(ptr, val, 10, UINT64_MAX); + return UPB_PRIVATE(_upb_WireReader_ReadVarint)(ptr, val, 10, UINT64_MAX); } // Skips data for a varint, returning a pointer past the end of the varint, or @@ -13695,7 +13718,7 @@ UPB_INLINE const char* upb_WireReader_ReadSize(const char* ptr, int* size) { UPB_INLINE const char* upb_WireReader_ReadFixed32(const char* ptr, void* val) { uint32_t uval; memcpy(&uval, ptr, 4); - uval = _upb_BigEndian_Swap32(uval); + uval = UPB_PRIVATE(_upb_BigEndian32)(uval); memcpy(val, &uval, 4); return ptr + 4; } @@ -13708,14 +13731,14 @@ UPB_INLINE const char* upb_WireReader_ReadFixed32(const char* ptr, void* val) { UPB_INLINE const char* upb_WireReader_ReadFixed64(const char* ptr, void* val) { uint64_t uval; memcpy(&uval, ptr, 8); - uval = _upb_BigEndian_Swap64(uval); + uval = UPB_PRIVATE(_upb_BigEndian64)(uval); memcpy(val, &uval, 8); return ptr + 8; } -const char* _upb_WireReader_SkipGroup(const char* ptr, uint32_t tag, - int depth_limit, - upb_EpsCopyInputStream* stream); +const char* UPB_PRIVATE(_upb_WireReader_SkipGroup)( + const char* ptr, uint32_t tag, int depth_limit, + upb_EpsCopyInputStream* stream); // Skips data for a group, returning a pointer past the end of the group, or // NULL if there was an error parsing the group. The `tag` argument should be @@ -13728,7 +13751,7 @@ const char* _upb_WireReader_SkipGroup(const char* ptr, uint32_t tag, // control over this? UPB_INLINE const char* upb_WireReader_SkipGroup( const char* ptr, uint32_t tag, upb_EpsCopyInputStream* stream) { - return _upb_WireReader_SkipGroup(ptr, tag, 100, stream); + return UPB_PRIVATE(_upb_WireReader_SkipGroup)(ptr, tag, 100, stream); } UPB_INLINE const char* _upb_WireReader_SkipValue( @@ -13749,7 +13772,8 @@ UPB_INLINE const char* _upb_WireReader_SkipValue( return ptr; } case kUpb_WireType_StartGroup: - return _upb_WireReader_SkipGroup(ptr, tag, depth_limit, stream); + return UPB_PRIVATE(_upb_WireReader_SkipGroup)(ptr, tag, depth_limit, + stream); case kUpb_WireType_EndGroup: return NULL; // Should be handled before now. default: diff --git a/upb/cmake/CMakeLists.txt b/upb/cmake/CMakeLists.txt index 61d3650fdfcbe..6374432ba59d6 100644 --- a/upb/cmake/CMakeLists.txt +++ b/upb/cmake/CMakeLists.txt @@ -96,8 +96,7 @@ target_link_libraries(generated_code_support__only_for_generated_code_do_not_use message_internal mini_descriptor mini_table - wire - wire_internal) + wire) add_library(generated_cpp_support__only_for_generated_code_do_not_use__i_give_permission_to_break_me INTERFACE From f869cfa479c293ecd55c2f8ccbf981cd3bb41ecf Mon Sep 17 00:00:00 2001 From: Charles OuGuo Date: Tue, 26 Dec 2023 12:09:51 -0800 Subject: [PATCH 097/255] In Ruby repeated fields, each_index actually iterates over the index (#11767) Currently we're aliasing `each_index` to `each_with_index`, incorrectly passing both the index and the value of a repeated field to the block. What we want is to just pass the index. Luckily this is a method on Ruby arrays, so we just wrap the native Ruby array method. Fixes https://github.com/protocolbuffers/protobuf/issues/7806 Closes #11767 COPYBARA_INTEGRATE_REVIEW=https://github.com/protocolbuffers/protobuf/pull/11767 from shaldengeki:shaldengeki-repeated-field-each-index-returns-actual-index 874916c21db5e728ce84f5349a607c7ce42f6006 PiperOrigin-RevId: 593835025 --- .../v3.0.0/tests/repeated_field_test.rb | 14 ++++++++++++++ ruby/lib/google/protobuf/repeated_field.rb | 3 +-- ruby/tests/repeated_field_test.rb | 14 ++++++++++++++ 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/ruby/compatibility_tests/v3.0.0/tests/repeated_field_test.rb b/ruby/compatibility_tests/v3.0.0/tests/repeated_field_test.rb index 56fa7fe41bd40..ed12eaa8de638 100755 --- a/ruby/compatibility_tests/v3.0.0/tests/repeated_field_test.rb +++ b/ruby/compatibility_tests/v3.0.0/tests/repeated_field_test.rb @@ -122,6 +122,20 @@ def test_each end + def test_each_index + m = TestMessage.new + 5.times{|i| m.repeated_string << 'string' } + + expected = 0 + m.repeated_string.each_index do |idx| + assert_equal expected, idx + expected += 1 + assert_equal 'string', m.repeated_string[idx] + end + assert_equal 5, expected + end + + def test_empty? m = TestMessage.new assert_empty m.repeated_string diff --git a/ruby/lib/google/protobuf/repeated_field.rb b/ruby/lib/google/protobuf/repeated_field.rb index a48095b62e010..b8c71e0655010 100644 --- a/ruby/lib/google/protobuf/repeated_field.rb +++ b/ruby/lib/google/protobuf/repeated_field.rb @@ -94,7 +94,6 @@ def empty? end # array aliases into enumerable - alias_method :each_index, :each_with_index alias_method :slice, :[] alias_method :values_at, :select alias_method :map, :collect @@ -145,7 +144,7 @@ def define_array_wrapper_with_result_method(method_name) end - %w(collect! compact! delete_if fill flatten! insert reverse! + %w(collect! compact! delete_if each_index fill flatten! insert reverse! rotate! select! shuffle! sort! sort_by! uniq!).each do |method_name| define_array_wrapper_with_result_method(method_name) end diff --git a/ruby/tests/repeated_field_test.rb b/ruby/tests/repeated_field_test.rb index 8e49fdce35318..293b4e42e17b3 100755 --- a/ruby/tests/repeated_field_test.rb +++ b/ruby/tests/repeated_field_test.rb @@ -143,6 +143,20 @@ def test_each end + def test_each_index + m = TestMessage.new + 5.times{|i| m.repeated_string << 'string' } + + expected = 0 + m.repeated_string.each_index do |idx| + assert_equal expected, idx + expected += 1 + assert_equal 'string', m.repeated_string[idx] + end + assert_equal 5, expected + end + + def test_empty? m = TestMessage.new assert_empty m.repeated_string From f50ea84d19d8b538dd03a4771ce97b15f9476ff1 Mon Sep 17 00:00:00 2001 From: Eric Salo Date: Tue, 26 Dec 2023 12:14:17 -0800 Subject: [PATCH 098/255] upb: the triumphant return of upb/mem:internal PiperOrigin-RevId: 593835739 --- upb/BUILD | 3 +++ upb/mem/BUILD | 12 ++++++++++++ upb/wire/BUILD | 1 + 3 files changed, 16 insertions(+) diff --git a/upb/BUILD b/upb/BUILD index f0ecc770bb3da..094054b14783e 100644 --- a/upb/BUILD +++ b/upb/BUILD @@ -395,6 +395,7 @@ upb_amalgamation( ":reflection_internal", ":wire", ":wire_reader", + "//upb/mem:internal", ], strip_import_prefix = ["src"], ) @@ -441,6 +442,7 @@ upb_amalgamation( ":reflection_internal", ":wire", ":wire_reader", + "//upb/mem:internal", ], prefix = "php-", strip_import_prefix = ["src"], @@ -488,6 +490,7 @@ upb_amalgamation( ":reflection_internal", ":wire", ":wire_reader", + "//upb/mem:internal", ], prefix = "ruby-", strip_import_prefix = ["src"], diff --git a/upb/mem/BUILD b/upb/mem/BUILD index f4b3226e50bdd..14e6e6aeeaee3 100644 --- a/upb/mem/BUILD +++ b/upb/mem/BUILD @@ -17,6 +17,18 @@ cc_library( "alloc.h", "arena.h", "arena.hpp", + ], + copts = UPB_DEFAULT_COPTS, + visibility = ["//visibility:public"], + deps = [ + ":internal", + "//upb:port", + ], +) + +cc_library( + name = "internal", + hdrs = [ "internal/arena.h", ], copts = UPB_DEFAULT_COPTS, diff --git a/upb/wire/BUILD b/upb/wire/BUILD index 2275fb4e6d240..3ef01192f87ce 100644 --- a/upb/wire/BUILD +++ b/upb/wire/BUILD @@ -37,6 +37,7 @@ cc_library( "//upb:message_types", "//upb:mini_table", "//upb:port", + "//upb/mem:internal", "//third_party/utf8_range", ], ) From 3c3d77158fceaf54c55e00f7eca50b2c2194ee87 Mon Sep 17 00:00:00 2001 From: Eric Salo Date: Tue, 26 Dec 2023 14:10:05 -0800 Subject: [PATCH 099/255] upb: add :test_srcs targets for cmake on GH PiperOrigin-RevId: 593854176 --- upb/hash/BUILD | 12 ++++++++++++ upb/json/BUILD | 21 +++++++++++++++++++++ upb/lex/BUILD | 12 ++++++++++++ upb/mem/BUILD | 12 ++++++++++++ upb/message/BUILD | 21 +++++++++++++++++++++ upb/mini_descriptor/BUILD | 12 ++++++++++++ upb/mini_table/BUILD | 12 ++++++++++++ upb/test/BUILD | 22 ++++++++++++++++++++++ upb/util/BUILD | 21 +++++++++++++++++++++ upb/wire/BUILD | 12 ++++++++++++ 10 files changed, 157 insertions(+) diff --git a/upb/hash/BUILD b/upb/hash/BUILD index 4c18e0cc4d04b..c7e4ea6b42259 100644 --- a/upb/hash/BUILD +++ b/upb/hash/BUILD @@ -54,3 +54,15 @@ filegroup( ] ) # end:github_only + +# begin:github_only +filegroup( + name = "test_srcs", + srcs = glob( + [ + "**/*test.cc", + ], + ), + visibility = ["//pkg:__pkg__"], +) +# end:github_only diff --git a/upb/json/BUILD b/upb/json/BUILD index 91c7dc1658ecd..b04c4fdb322e9 100644 --- a/upb/json/BUILD +++ b/upb/json/BUILD @@ -107,3 +107,24 @@ upb_c_proto_library( # ], # ) # end:google_only + +# begin:github_only +filegroup( + name = "test_srcs", + srcs = glob( + [ + "**/*test.cc", + ], + ), + visibility = ["//pkg:__pkg__"], +) +filegroup( + name = "test_utils", + srcs = glob( + [ + "**/*test.proto", + ], + ), + visibility = ["//pkg:__pkg__"], +) +# end:github_only diff --git a/upb/lex/BUILD b/upb/lex/BUILD index 664074b85f7d0..2dbf258e74bae 100644 --- a/upb/lex/BUILD +++ b/upb/lex/BUILD @@ -51,3 +51,15 @@ filegroup( ] ) # end:github_only + +# begin:github_only +filegroup( + name = "test_srcs", + srcs = glob( + [ + "**/*test.cc", + ], + ), + visibility = ["//pkg:__pkg__"], +) +# end:github_only diff --git a/upb/mem/BUILD b/upb/mem/BUILD index 14e6e6aeeaee3..a26b92eca5b3a 100644 --- a/upb/mem/BUILD +++ b/upb/mem/BUILD @@ -68,3 +68,15 @@ filegroup( ] ) # end:github_only + +# begin:github_only +filegroup( + name = "test_srcs", + srcs = glob( + [ + "**/*test.cc", + ], + ), + visibility = ["//pkg:__pkg__"], +) +# end:github_only diff --git a/upb/message/BUILD b/upb/message/BUILD index 98facaa8a797d..6a2660ace90c4 100644 --- a/upb/message/BUILD +++ b/upb/message/BUILD @@ -423,3 +423,24 @@ filegroup( ] ) # end:github_only + +# begin:github_only +filegroup( + name = "test_srcs", + srcs = glob( + [ + "**/*test.cc", + ], + ), + visibility = ["//pkg:__pkg__"], +) +filegroup( + name = "test_utils", + srcs = glob( + [ + "**/*test.proto", + ], + ), + visibility = ["//pkg:__pkg__"], +) +# end:github_only diff --git a/upb/mini_descriptor/BUILD b/upb/mini_descriptor/BUILD index f8292601ddc09..9ea571e6bbe28 100644 --- a/upb/mini_descriptor/BUILD +++ b/upb/mini_descriptor/BUILD @@ -85,3 +85,15 @@ filegroup( ] ) # end:github_only + +# begin:github_only +filegroup( + name = "test_srcs", + srcs = glob( + [ + "**/*test.cc", + ], + ), + visibility = ["//pkg:__pkg__"], +) +# end:github_only diff --git a/upb/mini_table/BUILD b/upb/mini_table/BUILD index 457f657d45291..4c73d1c39a453 100644 --- a/upb/mini_table/BUILD +++ b/upb/mini_table/BUILD @@ -90,3 +90,15 @@ filegroup( ] ) # end:github_only + +# begin:github_only +filegroup( + name = "test_srcs", + srcs = glob( + [ + "**/*test.cc", + ], + ), + visibility = ["//pkg:__pkg__"], +) +# end:github_only diff --git a/upb/test/BUILD b/upb/test/BUILD index a447a82cc0e89..186dacd37c4ce 100644 --- a/upb/test/BUILD +++ b/upb/test/BUILD @@ -299,3 +299,25 @@ cc_test( "@com_google_googletest//:gtest_main", ], ) + +# begin:github_only +filegroup( + name = "test_srcs", + srcs = glob( + [ + "**/*.cc", + "**/*.h", + ], + ), + visibility = ["//pkg:__pkg__"], +) +filegroup( + name = "test_utils", + srcs = glob( + [ + "**/*.proto", + ], + ), + visibility = ["//pkg:__pkg__"], +) +# end:github_only diff --git a/upb/util/BUILD b/upb/util/BUILD index f4c9803b4a29c..e299780ec5996 100644 --- a/upb/util/BUILD +++ b/upb/util/BUILD @@ -182,3 +182,24 @@ filegroup( visibility = ["//python/dist:__pkg__"], ) # end:github_only + +# begin:github_only +filegroup( + name = "test_srcs", + srcs = glob( + [ + "**/*test.cc", + ], + ), + visibility = ["//pkg:__pkg__"], +) +filegroup( + name = "test_utils", + srcs = glob( + [ + "**/*test.proto", + ], + ), + visibility = ["//pkg:__pkg__"], +) +# end:github_only diff --git a/upb/wire/BUILD b/upb/wire/BUILD index 3ef01192f87ce..e415a1894de1c 100644 --- a/upb/wire/BUILD +++ b/upb/wire/BUILD @@ -96,3 +96,15 @@ filegroup( ] ) # end:github_only + +# begin:github_only +filegroup( + name = "test_srcs", + srcs = glob( + [ + "**/*test.cc", + ], + ), + visibility = ["//pkg:__pkg__"], +) +# end:github_only From 08961460345d89f633ae3dbf9e2314961156b2c8 Mon Sep 17 00:00:00 2001 From: Eric Salo Date: Tue, 26 Dec 2023 14:42:52 -0800 Subject: [PATCH 100/255] upb: make all mini_table/ includes unidirectional PiperOrigin-RevId: 593859422 --- upb/message/accessors.h | 1 + upb/mini_table/internal/enum.h | 4 +-- upb/mini_table/internal/extension.h | 29 ++++++++++---------- upb/mini_table/internal/field.h | 37 +++++++++++++------------- upb/mini_table/internal/file.h | 26 +++++++++--------- upb/mini_table/internal/message.c | 4 +-- upb/mini_table/internal/message.h | 41 ++++++++++++++++------------- upb/mini_table/internal/sub.h | 26 +++++++++--------- 8 files changed, 83 insertions(+), 85 deletions(-) diff --git a/upb/message/accessors.h b/upb/message/accessors.h index b7f553808d7d0..ecd1751cf834b 100644 --- a/upb/message/accessors.h +++ b/upb/message/accessors.h @@ -25,6 +25,7 @@ #include "upb/message/tagged_ptr.h" #include "upb/message/types.h" #include "upb/mini_table/enum.h" +#include "upb/mini_table/sub.h" // Must be last. #include "upb/port/def.inc" diff --git a/upb/mini_table/internal/enum.h b/upb/mini_table/internal/enum.h index 85ca9b3282d1f..6f8bec8d1e559 100644 --- a/upb/mini_table/internal/enum.h +++ b/upb/mini_table/internal/enum.h @@ -10,8 +10,6 @@ #include -#include "upb/mini_table/types.h" - // Must be last. #include "upb/port/def.inc" @@ -26,7 +24,7 @@ extern "C" { #endif UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableEnum_CheckValue)( - const upb_MiniTableEnum* e, uint32_t val) { + const struct upb_MiniTableEnum* e, uint32_t val) { if (UPB_LIKELY(val < 64)) { const uint64_t mask = e->UPB_PRIVATE(data)[0] | ((uint64_t)e->UPB_PRIVATE(data)[1] << 32); diff --git a/upb/mini_table/internal/extension.h b/upb/mini_table/internal/extension.h index e28a9fad265ee..b46ee76a3cc7e 100644 --- a/upb/mini_table/internal/extension.h +++ b/upb/mini_table/internal/extension.h @@ -10,41 +10,42 @@ #include -#include "upb/mini_table/field.h" -#include "upb/mini_table/sub.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 UPB_PRIVATE(field); + struct upb_MiniTableField UPB_PRIVATE(field); - const upb_MiniTable* UPB_PRIVATE(extendee); - upb_MiniTableSub UPB_PRIVATE(sub); // NULL unless submsg or proto2 enum + const struct upb_MiniTable* UPB_PRIVATE(extendee); + union upb_MiniTableSub UPB_PRIVATE(sub); // NULL unless submsg or proto2 enum }; #ifdef __cplusplus extern "C" { #endif -UPB_INLINE const upb_MiniTableField* UPB_PRIVATE( - _upb_MiniTableExtension_AsField)(const upb_MiniTableExtension* e) { - return (const upb_MiniTableField*)&e->UPB_PRIVATE(field); +UPB_INLINE const struct upb_MiniTableField* UPB_PRIVATE( + _upb_MiniTableExtension_AsField)(const struct upb_MiniTableExtension* e) { + return (const struct upb_MiniTableField*)&e->UPB_PRIVATE(field); } -UPB_INLINE uint32_t -UPB_PRIVATE(_upb_MiniTableExtension_Number)(const upb_MiniTableExtension* e) { +UPB_INLINE uint32_t UPB_PRIVATE(_upb_MiniTableExtension_Number)( + const struct upb_MiniTableExtension* e) { return e->UPB_PRIVATE(field).UPB_ONLYBITS(number); } -UPB_INLINE const upb_MiniTable* UPB_PRIVATE( - _upb_MiniTableExtension_GetSubMessage)(const upb_MiniTableExtension* e) { - return upb_MiniTableSub_Message(e->UPB_PRIVATE(sub)); +UPB_INLINE const struct upb_MiniTable* UPB_PRIVATE( + _upb_MiniTableExtension_GetSubMessage)( + const struct upb_MiniTableExtension* e) { + return UPB_PRIVATE(_upb_MiniTableSub_Message)(e->UPB_PRIVATE(sub)); } UPB_INLINE void UPB_PRIVATE(_upb_MiniTableExtension_SetSubMessage)( - upb_MiniTableExtension* e, const upb_MiniTable* m) { + struct upb_MiniTableExtension* e, const struct upb_MiniTable* m) { e->UPB_PRIVATE(sub).UPB_PRIVATE(submsg) = m; } diff --git a/upb/mini_table/internal/field.h b/upb/mini_table/internal/field.h index a450f0521afb2..37568e017b550 100644 --- a/upb/mini_table/internal/field.h +++ b/upb/mini_table/internal/field.h @@ -13,7 +13,6 @@ #include "upb/base/descriptor_constants.h" #include "upb/mini_table/internal/size_log2.h" -#include "upb/mini_table/types.h" // Must be last. #include "upb/port/def.inc" @@ -76,47 +75,47 @@ extern "C" { #endif UPB_INLINE upb_FieldMode -UPB_PRIVATE(_upb_MiniTableField_Mode)(const upb_MiniTableField* f) { +UPB_PRIVATE(_upb_MiniTableField_Mode)(const struct upb_MiniTableField* f) { return (upb_FieldMode)(f->UPB_ONLYBITS(mode) & kUpb_FieldMode_Mask); } UPB_INLINE upb_FieldRep -UPB_PRIVATE(_upb_MiniTableField_GetRep)(const upb_MiniTableField* f) { +UPB_PRIVATE(_upb_MiniTableField_GetRep)(const struct upb_MiniTableField* f) { return (upb_FieldRep)(f->UPB_ONLYBITS(mode) >> kUpb_FieldRep_Shift); } UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsArray)( - const upb_MiniTableField* f) { + const struct upb_MiniTableField* f) { return UPB_PRIVATE(_upb_MiniTableField_Mode)(f) == kUpb_FieldMode_Array; } UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsMap)( - const upb_MiniTableField* f) { + const struct upb_MiniTableField* f) { return UPB_PRIVATE(_upb_MiniTableField_Mode)(f) == kUpb_FieldMode_Map; } UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsScalar)( - const upb_MiniTableField* f) { + const struct upb_MiniTableField* f) { return UPB_PRIVATE(_upb_MiniTableField_Mode)(f) == kUpb_FieldMode_Scalar; } UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsAlternate)( - const upb_MiniTableField* f) { + const struct upb_MiniTableField* f) { return (f->UPB_ONLYBITS(mode) & kUpb_LabelFlags_IsAlternate) != 0; } UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsExtension)( - const upb_MiniTableField* f) { + const struct upb_MiniTableField* f) { return (f->UPB_ONLYBITS(mode) & kUpb_LabelFlags_IsExtension) != 0; } UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsPacked)( - const upb_MiniTableField* f) { + const struct upb_MiniTableField* f) { return (f->UPB_ONLYBITS(mode) & kUpb_LabelFlags_IsPacked) != 0; } UPB_INLINE upb_FieldType -UPB_PRIVATE(_upb_MiniTableField_Type)(const upb_MiniTableField* f) { +UPB_PRIVATE(_upb_MiniTableField_Type)(const struct upb_MiniTableField* f) { const upb_FieldType type = (upb_FieldType)f->UPB_PRIVATE(descriptortype); if (UPB_PRIVATE(_upb_MiniTableField_IsAlternate)(f)) { if (type == kUpb_FieldType_Int32) return kUpb_FieldType_Enum; @@ -127,7 +126,7 @@ UPB_PRIVATE(_upb_MiniTableField_Type)(const upb_MiniTableField* f) { } UPB_INLINE upb_CType -UPB_PRIVATE(_upb_MiniTableField_CType)(const upb_MiniTableField* f) { +UPB_PRIVATE(_upb_MiniTableField_CType)(const struct upb_MiniTableField* f) { return upb_FieldType_CType(UPB_PRIVATE(_upb_MiniTableField_Type)(f)); } @@ -146,23 +145,23 @@ UPB_INLINE size_t UPB_PRIVATE(_upb_MiniTableField_HasbitOffset)( } UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsClosedEnum)( - const upb_MiniTableField* f) { + const struct upb_MiniTableField* f) { return f->UPB_PRIVATE(descriptortype) == kUpb_FieldType_Enum; } UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsInOneof)( - const upb_MiniTableField* f) { + const struct upb_MiniTableField* f) { return f->presence < 0; } UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsSubMessage)( - const upb_MiniTableField* f) { + const struct upb_MiniTableField* f) { return f->UPB_PRIVATE(descriptortype) == kUpb_FieldType_Message || f->UPB_PRIVATE(descriptortype) == kUpb_FieldType_Group; } UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_HasPresence)( - const upb_MiniTableField* f) { + const struct upb_MiniTableField* f) { if (UPB_PRIVATE(_upb_MiniTableField_IsExtension)(f)) { return UPB_PRIVATE(_upb_MiniTableField_IsScalar)(f); } else { @@ -187,7 +186,7 @@ UPB_INLINE size_t UPB_PRIVATE(_upb_MiniTableField_OneofOffset)( } UPB_INLINE void UPB_PRIVATE(_upb_MiniTableField_CheckIsArray)( - const upb_MiniTableField* f) { + const struct upb_MiniTableField* f) { UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_NativePointer); UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_IsArray)(f)); @@ -195,15 +194,15 @@ UPB_INLINE void UPB_PRIVATE(_upb_MiniTableField_CheckIsArray)( } UPB_INLINE void UPB_PRIVATE(_upb_MiniTableField_CheckIsMap)( - const upb_MiniTableField* f) { + const struct upb_MiniTableField* f) { UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_NativePointer); UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_IsMap)(f)); UPB_ASSUME(f->presence == 0); } -UPB_INLINE size_t -UPB_PRIVATE(_upb_MiniTableField_ElemSizeLg2)(const upb_MiniTableField* f) { +UPB_INLINE size_t UPB_PRIVATE(_upb_MiniTableField_ElemSizeLg2)( + const struct upb_MiniTableField* f) { const upb_FieldType field_type = UPB_PRIVATE(_upb_MiniTableField_Type)(f); return UPB_PRIVATE(_upb_FieldType_SizeLg2)(field_type); } diff --git a/upb/mini_table/internal/file.h b/upb/mini_table/internal/file.h index 6c1406ec81685..0afabcf1b3824 100644 --- a/upb/mini_table/internal/file.h +++ b/upb/mini_table/internal/file.h @@ -8,15 +8,13 @@ #ifndef UPB_MINI_TABLE_INTERNAL_FILE_H_ #define UPB_MINI_TABLE_INTERNAL_FILE_H_ -#include "upb/mini_table/types.h" - // Must be last. #include "upb/port/def.inc" struct upb_MiniTableFile { - const upb_MiniTable** UPB_PRIVATE(msgs); - const upb_MiniTableEnum** UPB_PRIVATE(enums); - const upb_MiniTableExtension** UPB_PRIVATE(exts); + const struct upb_MiniTable** UPB_PRIVATE(msgs); + const struct upb_MiniTableEnum** UPB_PRIVATE(enums); + const struct upb_MiniTableExtension** UPB_PRIVATE(exts); int UPB_PRIVATE(msg_count); int UPB_PRIVATE(enum_count); int UPB_PRIVATE(ext_count); @@ -27,34 +25,34 @@ extern "C" { #endif UPB_INLINE int UPB_PRIVATE(_upb_MiniTableFile_EnumCount)( - const upb_MiniTableFile* f) { + const struct upb_MiniTableFile* f) { return f->UPB_PRIVATE(enum_count); } UPB_INLINE int UPB_PRIVATE(_upb_MiniTableFile_ExtensionCount)( - const upb_MiniTableFile* f) { + const struct upb_MiniTableFile* f) { return f->UPB_PRIVATE(ext_count); } UPB_INLINE int UPB_PRIVATE(_upb_MiniTableFile_MessageCount)( - const upb_MiniTableFile* f) { + const struct upb_MiniTableFile* f) { return f->UPB_PRIVATE(msg_count); } -UPB_INLINE const upb_MiniTableEnum* UPB_PRIVATE(_upb_MiniTableFile_Enum)( - const upb_MiniTableFile* f, int i) { +UPB_INLINE const struct upb_MiniTableEnum* UPB_PRIVATE(_upb_MiniTableFile_Enum)( + const struct upb_MiniTableFile* f, int i) { UPB_ASSERT(i < f->UPB_PRIVATE(enum_count)); return f->UPB_PRIVATE(enums)[i]; } -UPB_INLINE const upb_MiniTableExtension* UPB_PRIVATE( - _upb_MiniTableFile_Extension)(const upb_MiniTableFile* f, int i) { +UPB_INLINE const struct upb_MiniTableExtension* UPB_PRIVATE( + _upb_MiniTableFile_Extension)(const struct upb_MiniTableFile* f, int i) { UPB_ASSERT(i < f->UPB_PRIVATE(ext_count)); return f->UPB_PRIVATE(exts)[i]; } -UPB_INLINE const upb_MiniTable* UPB_PRIVATE(_upb_MiniTableFile_Message)( - const upb_MiniTableFile* f, int i) { +UPB_INLINE const struct upb_MiniTable* UPB_PRIVATE(_upb_MiniTableFile_Message)( + const struct upb_MiniTableFile* f, int i) { UPB_ASSERT(i < f->UPB_PRIVATE(msg_count)); return f->UPB_PRIVATE(msgs)[i]; } diff --git a/upb/mini_table/internal/message.c b/upb/mini_table/internal/message.c index ff0884963fbb1..a1d736aa32f39 100644 --- a/upb/mini_table/internal/message.c +++ b/upb/mini_table/internal/message.c @@ -5,7 +5,7 @@ // license that can be found in the LICENSE file or at // https://developers.google.com/open-source/licenses/bsd -#include "upb/mini_table/message.h" +#include "upb/mini_table/internal/message.h" #include @@ -13,7 +13,7 @@ #include "upb/port/def.inc" // A MiniTable for an empty message, used for unlinked sub-messages. -const upb_MiniTable UPB_PRIVATE(_kUpb_MiniTable_Empty) = { +const struct upb_MiniTable UPB_PRIVATE(_kUpb_MiniTable_Empty) = { .UPB_PRIVATE(subs) = NULL, .UPB_PRIVATE(fields) = NULL, .UPB_PRIVATE(size) = 0, diff --git a/upb/mini_table/internal/message.h b/upb/mini_table/internal/message.h index 5aa3b6097335e..d833a455a3826 100644 --- a/upb/mini_table/internal/message.h +++ b/upb/mini_table/internal/message.h @@ -12,7 +12,6 @@ #include "upb/mini_table/internal/field.h" #include "upb/mini_table/internal/sub.h" -#include "upb/mini_table/types.h" // Must be last. #include "upb/port/def.inc" @@ -45,8 +44,8 @@ typedef enum { // LINT.IfChange(minitable_struct_definition) struct upb_MiniTable { - const upb_MiniTableSub* UPB_PRIVATE(subs); - const upb_MiniTableField* UPB_ONLYBITS(fields); + const union upb_MiniTableSub* UPB_PRIVATE(subs); + const struct upb_MiniTableField* UPB_ONLYBITS(fields); // Must be aligned to sizeof(void*). Doesn't include internal members like // unknown fields, extension dict, pointer to msglayout, etc. @@ -70,43 +69,47 @@ struct upb_MiniTable { extern "C" { #endif -UPB_INLINE const upb_MiniTable* UPB_PRIVATE(_upb_MiniTable_Empty)(void) { - extern const upb_MiniTable UPB_PRIVATE(_kUpb_MiniTable_Empty); +UPB_INLINE const struct upb_MiniTable* UPB_PRIVATE(_upb_MiniTable_Empty)(void) { + extern const struct upb_MiniTable UPB_PRIVATE(_kUpb_MiniTable_Empty); return &UPB_PRIVATE(_kUpb_MiniTable_Empty); } -UPB_INLINE int UPB_PRIVATE(_upb_MiniTable_FieldCount)(const upb_MiniTable* m) { +UPB_INLINE int UPB_PRIVATE(_upb_MiniTable_FieldCount)( + const struct upb_MiniTable* m) { return m->UPB_ONLYBITS(field_count); } -UPB_INLINE bool UPB_PRIVATE(_upb_MiniTable_IsEmpty)(const upb_MiniTable* m) { - extern const upb_MiniTable UPB_PRIVATE(_kUpb_MiniTable_Empty); +UPB_INLINE bool UPB_PRIVATE(_upb_MiniTable_IsEmpty)( + const struct upb_MiniTable* m) { + extern const struct upb_MiniTable UPB_PRIVATE(_kUpb_MiniTable_Empty); return m == &UPB_PRIVATE(_kUpb_MiniTable_Empty); } -UPB_INLINE const upb_MiniTableField* UPB_PRIVATE( - _upb_MiniTable_GetFieldByIndex)(const upb_MiniTable* m, uint32_t i) { +UPB_INLINE const struct upb_MiniTableField* UPB_PRIVATE( + _upb_MiniTable_GetFieldByIndex)(const struct upb_MiniTable* m, uint32_t i) { return &m->UPB_ONLYBITS(fields)[i]; } -UPB_INLINE const upb_MiniTableSub* UPB_PRIVATE(_upb_MiniTable_GetSubByIndex)( - const upb_MiniTable* m, uint32_t i) { +UPB_INLINE const union upb_MiniTableSub* UPB_PRIVATE( + _upb_MiniTable_GetSubByIndex)(const struct upb_MiniTable* m, uint32_t i) { return &m->UPB_PRIVATE(subs)[i]; } -UPB_INLINE const upb_MiniTable* UPB_PRIVATE(_upb_MiniTable_GetSubMessageTable)( - const upb_MiniTable* m, const upb_MiniTableField* f) { +UPB_INLINE const struct upb_MiniTable* UPB_PRIVATE( + _upb_MiniTable_GetSubMessageTable)(const struct upb_MiniTable* m, + const struct upb_MiniTableField* f) { UPB_ASSERT(UPB_PRIVATE(_upb_MiniTableField_CType)(f) == kUpb_CType_Message); - const upb_MiniTable* ret = UPB_PRIVATE(_upb_MiniTableSub_Message)( + const struct upb_MiniTable* ret = UPB_PRIVATE(_upb_MiniTableSub_Message)( m->UPB_PRIVATE(subs)[f->UPB_PRIVATE(submsg_index)]); UPB_ASSUME(ret); return UPB_PRIVATE(_upb_MiniTable_IsEmpty)(ret) ? NULL : ret; } -UPB_INLINE const upb_MiniTableEnum* UPB_PRIVATE(_upb_MiniTable_GetSubEnumTable)( - const upb_MiniTable* m, const upb_MiniTableField* f) { +UPB_INLINE const struct upb_MiniTableEnum* UPB_PRIVATE( + _upb_MiniTable_GetSubEnumTable)(const struct upb_MiniTable* m, + const struct upb_MiniTableField* f) { UPB_ASSERT(UPB_PRIVATE(_upb_MiniTableField_CType)(f) == kUpb_CType_Enum); return UPB_PRIVATE(_upb_MiniTableSub_Enum)( m->UPB_PRIVATE(subs)[f->UPB_PRIVATE(submsg_index)]); @@ -131,7 +134,7 @@ UPB_INLINE const struct upb_MiniTableField* UPB_PRIVATE( } UPB_INLINE bool UPB_PRIVATE(_upb_MiniTable_MessageFieldIsLinked)( - const upb_MiniTable* m, const upb_MiniTableField* f) { + const struct upb_MiniTable* m, const struct upb_MiniTableField* f) { return UPB_PRIVATE(_upb_MiniTable_GetSubMessageTable)(m, f) != NULL; } @@ -142,7 +145,7 @@ UPB_INLINE bool UPB_PRIVATE(_upb_MiniTable_MessageFieldIsLinked)( // RequiredMask(1) => 0b10 (0x2) // RequiredMask(5) => 0b111110 (0x3e) UPB_INLINE uint64_t -UPB_PRIVATE(_upb_MiniTable_RequiredMask)(const upb_MiniTable* m) { +UPB_PRIVATE(_upb_MiniTable_RequiredMask)(const struct upb_MiniTable* m) { int n = m->UPB_PRIVATE(required_count); UPB_ASSERT(0 < n && n <= 63); return ((1ULL << n) - 1) << 1; diff --git a/upb/mini_table/internal/sub.h b/upb/mini_table/internal/sub.h index ad25d68933121..99e35bd33c107 100644 --- a/upb/mini_table/internal/sub.h +++ b/upb/mini_table/internal/sub.h @@ -8,41 +8,39 @@ #ifndef UPB_MINI_TABLE_INTERNAL_SUB_H_ #define UPB_MINI_TABLE_INTERNAL_SUB_H_ -#include "upb/mini_table/types.h" - // Must be last. #include "upb/port/def.inc" union upb_MiniTableSub { - const upb_MiniTable* UPB_PRIVATE(submsg); - const upb_MiniTableEnum* UPB_PRIVATE(subenum); + const struct upb_MiniTable* UPB_PRIVATE(submsg); + const struct upb_MiniTableEnum* UPB_PRIVATE(subenum); }; #ifdef __cplusplus extern "C" { #endif -UPB_INLINE upb_MiniTableSub -UPB_PRIVATE(_upb_MiniTableSub_FromEnum)(const upb_MiniTableEnum* subenum) { - upb_MiniTableSub out; +UPB_INLINE union upb_MiniTableSub UPB_PRIVATE(_upb_MiniTableSub_FromEnum)( + const struct upb_MiniTableEnum* subenum) { + union upb_MiniTableSub out; out.UPB_PRIVATE(subenum) = subenum; return out; } -UPB_INLINE upb_MiniTableSub -UPB_PRIVATE(_upb_MiniTableSub_FromMessage)(const upb_MiniTable* submsg) { - upb_MiniTableSub out; +UPB_INLINE union upb_MiniTableSub UPB_PRIVATE(_upb_MiniTableSub_FromMessage)( + const struct upb_MiniTable* submsg) { + union upb_MiniTableSub out; out.UPB_PRIVATE(submsg) = submsg; return out; } -UPB_INLINE const upb_MiniTableEnum* UPB_PRIVATE(_upb_MiniTableSub_Enum)( - const upb_MiniTableSub sub) { +UPB_INLINE const struct upb_MiniTableEnum* UPB_PRIVATE(_upb_MiniTableSub_Enum)( + const union upb_MiniTableSub sub) { return sub.UPB_PRIVATE(subenum); } -UPB_INLINE const upb_MiniTable* UPB_PRIVATE(_upb_MiniTableSub_Message)( - const upb_MiniTableSub sub) { +UPB_INLINE const struct upb_MiniTable* UPB_PRIVATE(_upb_MiniTableSub_Message)( + const union upb_MiniTableSub sub) { return sub.UPB_PRIVATE(submsg); } From 4c7434560d7e85514fc86a7f02454c21467d6d96 Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Tue, 26 Dec 2023 22:55:49 +0000 Subject: [PATCH 101/255] Auto-generate files after cl/593859422 --- php/ext/google/protobuf/php-upb.c | 2 +- php/ext/google/protobuf/php-upb.h | 410 +++++++++++++------------- ruby/ext/google/protobuf_c/ruby-upb.c | 2 +- ruby/ext/google/protobuf_c/ruby-upb.h | 410 +++++++++++++------------- 4 files changed, 414 insertions(+), 410 deletions(-) diff --git a/php/ext/google/protobuf/php-upb.c b/php/ext/google/protobuf/php-upb.c index 00301dd36814f..9b13b7f4d0c6b 100644 --- a/php/ext/google/protobuf/php-upb.c +++ b/php/ext/google/protobuf/php-upb.c @@ -8425,7 +8425,7 @@ const upb_MiniTableExtension* upb_ExtensionRegistry_Lookup( // Must be last. // A MiniTable for an empty message, used for unlinked sub-messages. -const upb_MiniTable UPB_PRIVATE(_kUpb_MiniTable_Empty) = { +const struct upb_MiniTable UPB_PRIVATE(_kUpb_MiniTable_Empty) = { .UPB_PRIVATE(subs) = NULL, .UPB_PRIVATE(fields) = NULL, .UPB_PRIVATE(size) = 0, diff --git a/php/ext/google/protobuf/php-upb.h b/php/ext/google/protobuf/php-upb.h index aaeb1170b9eee..eb716f45c4d94 100644 --- a/php/ext/google/protobuf/php-upb.h +++ b/php/ext/google/protobuf/php-upb.h @@ -1089,21 +1089,6 @@ UPB_INLINE int UPB_PRIVATE(_upb_FieldType_SizeLg2)(upb_FieldType field_type) { #endif /* UPB_MINI_TABLE_INTERNAL_SIZE_LOG2_H_ */ -#ifndef UPB_MINI_TABLE_TYPES_H_ -#define UPB_MINI_TABLE_TYPES_H_ - -// Minitable types are recursively defined so declare them all together here. - -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; - -#endif /* UPB_MINI_TABLE_TYPES_H_ */ - // Must be last. // LINT.IfChange(struct_definition) @@ -1164,47 +1149,47 @@ extern "C" { #endif UPB_INLINE upb_FieldMode -UPB_PRIVATE(_upb_MiniTableField_Mode)(const upb_MiniTableField* f) { +UPB_PRIVATE(_upb_MiniTableField_Mode)(const struct upb_MiniTableField* f) { return (upb_FieldMode)(f->UPB_ONLYBITS(mode) & kUpb_FieldMode_Mask); } UPB_INLINE upb_FieldRep -UPB_PRIVATE(_upb_MiniTableField_GetRep)(const upb_MiniTableField* f) { +UPB_PRIVATE(_upb_MiniTableField_GetRep)(const struct upb_MiniTableField* f) { return (upb_FieldRep)(f->UPB_ONLYBITS(mode) >> kUpb_FieldRep_Shift); } UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsArray)( - const upb_MiniTableField* f) { + const struct upb_MiniTableField* f) { return UPB_PRIVATE(_upb_MiniTableField_Mode)(f) == kUpb_FieldMode_Array; } UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsMap)( - const upb_MiniTableField* f) { + const struct upb_MiniTableField* f) { return UPB_PRIVATE(_upb_MiniTableField_Mode)(f) == kUpb_FieldMode_Map; } UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsScalar)( - const upb_MiniTableField* f) { + const struct upb_MiniTableField* f) { return UPB_PRIVATE(_upb_MiniTableField_Mode)(f) == kUpb_FieldMode_Scalar; } UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsAlternate)( - const upb_MiniTableField* f) { + const struct upb_MiniTableField* f) { return (f->UPB_ONLYBITS(mode) & kUpb_LabelFlags_IsAlternate) != 0; } UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsExtension)( - const upb_MiniTableField* f) { + const struct upb_MiniTableField* f) { return (f->UPB_ONLYBITS(mode) & kUpb_LabelFlags_IsExtension) != 0; } UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsPacked)( - const upb_MiniTableField* f) { + const struct upb_MiniTableField* f) { return (f->UPB_ONLYBITS(mode) & kUpb_LabelFlags_IsPacked) != 0; } UPB_INLINE upb_FieldType -UPB_PRIVATE(_upb_MiniTableField_Type)(const upb_MiniTableField* f) { +UPB_PRIVATE(_upb_MiniTableField_Type)(const struct upb_MiniTableField* f) { const upb_FieldType type = (upb_FieldType)f->UPB_PRIVATE(descriptortype); if (UPB_PRIVATE(_upb_MiniTableField_IsAlternate)(f)) { if (type == kUpb_FieldType_Int32) return kUpb_FieldType_Enum; @@ -1215,7 +1200,7 @@ UPB_PRIVATE(_upb_MiniTableField_Type)(const upb_MiniTableField* f) { } UPB_INLINE upb_CType -UPB_PRIVATE(_upb_MiniTableField_CType)(const upb_MiniTableField* f) { +UPB_PRIVATE(_upb_MiniTableField_CType)(const struct upb_MiniTableField* f) { return upb_FieldType_CType(UPB_PRIVATE(_upb_MiniTableField_Type)(f)); } @@ -1234,23 +1219,23 @@ UPB_INLINE size_t UPB_PRIVATE(_upb_MiniTableField_HasbitOffset)( } UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsClosedEnum)( - const upb_MiniTableField* f) { + const struct upb_MiniTableField* f) { return f->UPB_PRIVATE(descriptortype) == kUpb_FieldType_Enum; } UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsInOneof)( - const upb_MiniTableField* f) { + const struct upb_MiniTableField* f) { return f->presence < 0; } UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsSubMessage)( - const upb_MiniTableField* f) { + const struct upb_MiniTableField* f) { return f->UPB_PRIVATE(descriptortype) == kUpb_FieldType_Message || f->UPB_PRIVATE(descriptortype) == kUpb_FieldType_Group; } UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_HasPresence)( - const upb_MiniTableField* f) { + const struct upb_MiniTableField* f) { if (UPB_PRIVATE(_upb_MiniTableField_IsExtension)(f)) { return UPB_PRIVATE(_upb_MiniTableField_IsScalar)(f); } else { @@ -1275,7 +1260,7 @@ UPB_INLINE size_t UPB_PRIVATE(_upb_MiniTableField_OneofOffset)( } UPB_INLINE void UPB_PRIVATE(_upb_MiniTableField_CheckIsArray)( - const upb_MiniTableField* f) { + const struct upb_MiniTableField* f) { UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_NativePointer); UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_IsArray)(f)); @@ -1283,15 +1268,15 @@ UPB_INLINE void UPB_PRIVATE(_upb_MiniTableField_CheckIsArray)( } UPB_INLINE void UPB_PRIVATE(_upb_MiniTableField_CheckIsMap)( - const upb_MiniTableField* f) { + const struct upb_MiniTableField* f) { UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_NativePointer); UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_IsMap)(f)); UPB_ASSUME(f->presence == 0); } -UPB_INLINE size_t -UPB_PRIVATE(_upb_MiniTableField_ElemSizeLg2)(const upb_MiniTableField* f) { +UPB_INLINE size_t UPB_PRIVATE(_upb_MiniTableField_ElemSizeLg2)( + const struct upb_MiniTableField* f) { const upb_FieldType field_type = UPB_PRIVATE(_upb_MiniTableField_Type)(f); return UPB_PRIVATE(_upb_FieldType_SizeLg2)(field_type); } @@ -1308,39 +1293,38 @@ UPB_PRIVATE(_upb_MiniTableField_ElemSizeLg2)(const upb_MiniTableField* f) { #ifndef UPB_MINI_TABLE_INTERNAL_SUB_H_ #define UPB_MINI_TABLE_INTERNAL_SUB_H_ - // Must be last. union upb_MiniTableSub { - const upb_MiniTable* UPB_PRIVATE(submsg); - const upb_MiniTableEnum* UPB_PRIVATE(subenum); + const struct upb_MiniTable* UPB_PRIVATE(submsg); + const struct upb_MiniTableEnum* UPB_PRIVATE(subenum); }; #ifdef __cplusplus extern "C" { #endif -UPB_INLINE upb_MiniTableSub -UPB_PRIVATE(_upb_MiniTableSub_FromEnum)(const upb_MiniTableEnum* subenum) { - upb_MiniTableSub out; +UPB_INLINE union upb_MiniTableSub UPB_PRIVATE(_upb_MiniTableSub_FromEnum)( + const struct upb_MiniTableEnum* subenum) { + union upb_MiniTableSub out; out.UPB_PRIVATE(subenum) = subenum; return out; } -UPB_INLINE upb_MiniTableSub -UPB_PRIVATE(_upb_MiniTableSub_FromMessage)(const upb_MiniTable* submsg) { - upb_MiniTableSub out; +UPB_INLINE union upb_MiniTableSub UPB_PRIVATE(_upb_MiniTableSub_FromMessage)( + const struct upb_MiniTable* submsg) { + union upb_MiniTableSub out; out.UPB_PRIVATE(submsg) = submsg; return out; } -UPB_INLINE const upb_MiniTableEnum* UPB_PRIVATE(_upb_MiniTableSub_Enum)( - const upb_MiniTableSub sub) { +UPB_INLINE const struct upb_MiniTableEnum* UPB_PRIVATE(_upb_MiniTableSub_Enum)( + const union upb_MiniTableSub sub) { return sub.UPB_PRIVATE(subenum); } -UPB_INLINE const upb_MiniTable* UPB_PRIVATE(_upb_MiniTableSub_Message)( - const upb_MiniTableSub sub) { +UPB_INLINE const struct upb_MiniTable* UPB_PRIVATE(_upb_MiniTableSub_Message)( + const union upb_MiniTableSub sub) { return sub.UPB_PRIVATE(submsg); } @@ -1381,8 +1365,8 @@ typedef enum { // LINT.IfChange(minitable_struct_definition) struct upb_MiniTable { - const upb_MiniTableSub* UPB_PRIVATE(subs); - const upb_MiniTableField* UPB_ONLYBITS(fields); + const union upb_MiniTableSub* UPB_PRIVATE(subs); + const struct upb_MiniTableField* UPB_ONLYBITS(fields); // Must be aligned to sizeof(void*). Doesn't include internal members like // unknown fields, extension dict, pointer to msglayout, etc. @@ -1406,43 +1390,47 @@ struct upb_MiniTable { extern "C" { #endif -UPB_INLINE const upb_MiniTable* UPB_PRIVATE(_upb_MiniTable_Empty)(void) { - extern const upb_MiniTable UPB_PRIVATE(_kUpb_MiniTable_Empty); +UPB_INLINE const struct upb_MiniTable* UPB_PRIVATE(_upb_MiniTable_Empty)(void) { + extern const struct upb_MiniTable UPB_PRIVATE(_kUpb_MiniTable_Empty); return &UPB_PRIVATE(_kUpb_MiniTable_Empty); } -UPB_INLINE int UPB_PRIVATE(_upb_MiniTable_FieldCount)(const upb_MiniTable* m) { +UPB_INLINE int UPB_PRIVATE(_upb_MiniTable_FieldCount)( + const struct upb_MiniTable* m) { return m->UPB_ONLYBITS(field_count); } -UPB_INLINE bool UPB_PRIVATE(_upb_MiniTable_IsEmpty)(const upb_MiniTable* m) { - extern const upb_MiniTable UPB_PRIVATE(_kUpb_MiniTable_Empty); +UPB_INLINE bool UPB_PRIVATE(_upb_MiniTable_IsEmpty)( + const struct upb_MiniTable* m) { + extern const struct upb_MiniTable UPB_PRIVATE(_kUpb_MiniTable_Empty); return m == &UPB_PRIVATE(_kUpb_MiniTable_Empty); } -UPB_INLINE const upb_MiniTableField* UPB_PRIVATE( - _upb_MiniTable_GetFieldByIndex)(const upb_MiniTable* m, uint32_t i) { +UPB_INLINE const struct upb_MiniTableField* UPB_PRIVATE( + _upb_MiniTable_GetFieldByIndex)(const struct upb_MiniTable* m, uint32_t i) { return &m->UPB_ONLYBITS(fields)[i]; } -UPB_INLINE const upb_MiniTableSub* UPB_PRIVATE(_upb_MiniTable_GetSubByIndex)( - const upb_MiniTable* m, uint32_t i) { +UPB_INLINE const union upb_MiniTableSub* UPB_PRIVATE( + _upb_MiniTable_GetSubByIndex)(const struct upb_MiniTable* m, uint32_t i) { return &m->UPB_PRIVATE(subs)[i]; } -UPB_INLINE const upb_MiniTable* UPB_PRIVATE(_upb_MiniTable_GetSubMessageTable)( - const upb_MiniTable* m, const upb_MiniTableField* f) { +UPB_INLINE const struct upb_MiniTable* UPB_PRIVATE( + _upb_MiniTable_GetSubMessageTable)(const struct upb_MiniTable* m, + const struct upb_MiniTableField* f) { UPB_ASSERT(UPB_PRIVATE(_upb_MiniTableField_CType)(f) == kUpb_CType_Message); - const upb_MiniTable* ret = UPB_PRIVATE(_upb_MiniTableSub_Message)( + const struct upb_MiniTable* ret = UPB_PRIVATE(_upb_MiniTableSub_Message)( m->UPB_PRIVATE(subs)[f->UPB_PRIVATE(submsg_index)]); UPB_ASSUME(ret); return UPB_PRIVATE(_upb_MiniTable_IsEmpty)(ret) ? NULL : ret; } -UPB_INLINE const upb_MiniTableEnum* UPB_PRIVATE(_upb_MiniTable_GetSubEnumTable)( - const upb_MiniTable* m, const upb_MiniTableField* f) { +UPB_INLINE const struct upb_MiniTableEnum* UPB_PRIVATE( + _upb_MiniTable_GetSubEnumTable)(const struct upb_MiniTable* m, + const struct upb_MiniTableField* f) { UPB_ASSERT(UPB_PRIVATE(_upb_MiniTableField_CType)(f) == kUpb_CType_Enum); return UPB_PRIVATE(_upb_MiniTableSub_Enum)( m->UPB_PRIVATE(subs)[f->UPB_PRIVATE(submsg_index)]); @@ -1467,7 +1455,7 @@ UPB_INLINE const struct upb_MiniTableField* UPB_PRIVATE( } UPB_INLINE bool UPB_PRIVATE(_upb_MiniTable_MessageFieldIsLinked)( - const upb_MiniTable* m, const upb_MiniTableField* f) { + const struct upb_MiniTable* m, const struct upb_MiniTableField* f) { return UPB_PRIVATE(_upb_MiniTable_GetSubMessageTable)(m, f) != NULL; } @@ -1478,7 +1466,7 @@ UPB_INLINE bool UPB_PRIVATE(_upb_MiniTable_MessageFieldIsLinked)( // RequiredMask(1) => 0b10 (0x2) // RequiredMask(5) => 0b111110 (0x3e) UPB_INLINE uint64_t -UPB_PRIVATE(_upb_MiniTable_RequiredMask)(const upb_MiniTable* m) { +UPB_PRIVATE(_upb_MiniTable_RequiredMask)(const struct upb_MiniTable* m) { int n = m->UPB_PRIVATE(required_count); UPB_ASSERT(0 < n && n <= 63); return ((1ULL << n) - 1) << 1; @@ -1491,6 +1479,21 @@ UPB_PRIVATE(_upb_MiniTable_RequiredMask)(const upb_MiniTable* m) { #endif /* UPB_MINI_TABLE_INTERNAL_MESSAGE_H_ */ +#ifndef UPB_MINI_TABLE_TYPES_H_ +#define UPB_MINI_TABLE_TYPES_H_ + +// Minitable types are recursively defined so declare them all together here. + +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; + +#endif /* UPB_MINI_TABLE_TYPES_H_ */ + // Must be last. #ifdef __cplusplus @@ -1607,150 +1610,38 @@ size_t upb_Message_ExtensionCount(const upb_Message* msg); #include -#ifndef UPB_MINI_TABLE_FIELD_H_ -#define UPB_MINI_TABLE_FIELD_H_ - -#include - - -// Must be last. - -#ifdef __cplusplus -extern "C" { -#endif - -UPB_API_INLINE upb_CType upb_MiniTableField_CType(const upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTableField_CType)(f); -} - -UPB_API_INLINE bool upb_MiniTableField_HasPresence( - const upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTableField_HasPresence)(f); -} - -UPB_API_INLINE bool upb_MiniTableField_IsArray(const upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTableField_IsArray)(f); -} - -UPB_API_INLINE bool upb_MiniTableField_IsClosedEnum( - const upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTableField_IsClosedEnum)(f); -} - -UPB_API_INLINE bool upb_MiniTableField_IsExtension( - const upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTableField_IsExtension)(f); -} - -UPB_API_INLINE bool upb_MiniTableField_IsInOneof(const upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTableField_IsInOneof)(f); -} - -UPB_API_INLINE bool upb_MiniTableField_IsMap(const upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTableField_IsMap)(f); -} - -UPB_API_INLINE bool upb_MiniTableField_IsPacked(const upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTableField_IsPacked)(f); -} - -UPB_API_INLINE bool upb_MiniTableField_IsScalar(const upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTableField_IsScalar)(f); -} - -UPB_API_INLINE bool upb_MiniTableField_IsSubMessage( - const upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTableField_IsSubMessage)(f); -} - -UPB_API_INLINE uint32_t upb_MiniTableField_Number(const upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTableField_Number)(f); -} - -UPB_API_INLINE upb_FieldType -upb_MiniTableField_Type(const upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTableField_Type)(f); -} - -#ifdef __cplusplus -} /* extern "C" */ -#endif - - -#endif /* UPB_MINI_TABLE_FIELD_H_ */ - -#ifndef UPB_MINI_TABLE_SUB_H_ -#define UPB_MINI_TABLE_SUB_H_ - - -// Must be last. - -#ifdef __cplusplus -extern "C" { -#endif - -// Constructors - -UPB_API_INLINE upb_MiniTableSub -upb_MiniTableSub_FromEnum(const upb_MiniTableEnum* subenum) { - return UPB_PRIVATE(_upb_MiniTableSub_FromEnum)(subenum); -} - -UPB_API_INLINE upb_MiniTableSub -upb_MiniTableSub_FromMessage(const upb_MiniTable* submsg) { - return UPB_PRIVATE(_upb_MiniTableSub_FromMessage)(submsg); -} - -// Getters - -UPB_API_INLINE const upb_MiniTableEnum* upb_MiniTableSub_Enum( - upb_MiniTableSub sub) { - return UPB_PRIVATE(_upb_MiniTableSub_Enum)(sub); -} - -UPB_API_INLINE const upb_MiniTable* upb_MiniTableSub_Message( - upb_MiniTableSub sub) { - return UPB_PRIVATE(_upb_MiniTableSub_Message)(sub); -} - -#ifdef __cplusplus -} /* extern "C" */ -#endif - - -#endif /* UPB_MINI_TABLE_SUB_H_ */ - // Must be last. struct upb_MiniTableExtension { // Do not move this field. We need to be able to alias pointers. - upb_MiniTableField UPB_PRIVATE(field); + struct upb_MiniTableField UPB_PRIVATE(field); - const upb_MiniTable* UPB_PRIVATE(extendee); - upb_MiniTableSub UPB_PRIVATE(sub); // NULL unless submsg or proto2 enum + const struct upb_MiniTable* UPB_PRIVATE(extendee); + union upb_MiniTableSub UPB_PRIVATE(sub); // NULL unless submsg or proto2 enum }; #ifdef __cplusplus extern "C" { #endif -UPB_INLINE const upb_MiniTableField* UPB_PRIVATE( - _upb_MiniTableExtension_AsField)(const upb_MiniTableExtension* e) { - return (const upb_MiniTableField*)&e->UPB_PRIVATE(field); +UPB_INLINE const struct upb_MiniTableField* UPB_PRIVATE( + _upb_MiniTableExtension_AsField)(const struct upb_MiniTableExtension* e) { + return (const struct upb_MiniTableField*)&e->UPB_PRIVATE(field); } -UPB_INLINE uint32_t -UPB_PRIVATE(_upb_MiniTableExtension_Number)(const upb_MiniTableExtension* e) { +UPB_INLINE uint32_t UPB_PRIVATE(_upb_MiniTableExtension_Number)( + const struct upb_MiniTableExtension* e) { return e->UPB_PRIVATE(field).UPB_ONLYBITS(number); } -UPB_INLINE const upb_MiniTable* UPB_PRIVATE( - _upb_MiniTableExtension_GetSubMessage)(const upb_MiniTableExtension* e) { - return upb_MiniTableSub_Message(e->UPB_PRIVATE(sub)); +UPB_INLINE const struct upb_MiniTable* UPB_PRIVATE( + _upb_MiniTableExtension_GetSubMessage)( + const struct upb_MiniTableExtension* e) { + return UPB_PRIVATE(_upb_MiniTableSub_Message)(e->UPB_PRIVATE(sub)); } UPB_INLINE void UPB_PRIVATE(_upb_MiniTableExtension_SetSubMessage)( - upb_MiniTableExtension* e, const upb_MiniTable* m) { + struct upb_MiniTableExtension* e, const struct upb_MiniTable* m) { e->UPB_PRIVATE(sub).UPB_PRIVATE(submsg) = m; } @@ -2500,6 +2391,78 @@ bool UPB_PRIVATE(_upb_Message_Realloc)(upb_Message* msg, size_t need, #endif /* UPB_MESSAGE_INTERNAL_H_ */ +#ifndef UPB_MINI_TABLE_FIELD_H_ +#define UPB_MINI_TABLE_FIELD_H_ + +#include + + +// Must be last. + +#ifdef __cplusplus +extern "C" { +#endif + +UPB_API_INLINE upb_CType upb_MiniTableField_CType(const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_CType)(f); +} + +UPB_API_INLINE bool upb_MiniTableField_HasPresence( + const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_HasPresence)(f); +} + +UPB_API_INLINE bool upb_MiniTableField_IsArray(const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_IsArray)(f); +} + +UPB_API_INLINE bool upb_MiniTableField_IsClosedEnum( + const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_IsClosedEnum)(f); +} + +UPB_API_INLINE bool upb_MiniTableField_IsExtension( + const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_IsExtension)(f); +} + +UPB_API_INLINE bool upb_MiniTableField_IsInOneof(const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_IsInOneof)(f); +} + +UPB_API_INLINE bool upb_MiniTableField_IsMap(const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_IsMap)(f); +} + +UPB_API_INLINE bool upb_MiniTableField_IsPacked(const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_IsPacked)(f); +} + +UPB_API_INLINE bool upb_MiniTableField_IsScalar(const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_IsScalar)(f); +} + +UPB_API_INLINE bool upb_MiniTableField_IsSubMessage( + const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_IsSubMessage)(f); +} + +UPB_API_INLINE uint32_t upb_MiniTableField_Number(const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_Number)(f); +} + +UPB_API_INLINE upb_FieldType +upb_MiniTableField_Type(const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_Type)(f); +} + +#ifdef __cplusplus +} /* extern "C" */ +#endif + + +#endif /* UPB_MINI_TABLE_FIELD_H_ */ + // Must be last. #if defined(__GNUC__) && !defined(__clang__) @@ -2960,7 +2923,6 @@ UPB_INLINE void UPB_PRIVATE(_upb_Array_Set)(upb_Array* array, size_t i, #include - // Must be last. struct upb_MiniTableEnum { @@ -2974,7 +2936,7 @@ extern "C" { #endif UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableEnum_CheckValue)( - const upb_MiniTableEnum* e, uint32_t val) { + const struct upb_MiniTableEnum* e, uint32_t val) { if (UPB_LIKELY(val < 64)) { const uint64_t mask = e->UPB_PRIVATE(data)[0] | ((uint64_t)e->UPB_PRIVATE(data)[1] << 32); @@ -3024,6 +2986,47 @@ UPB_INLINE bool upb_MiniTableEnum_CheckValue(const upb_MiniTableEnum* e, #endif /* UPB_MINI_TABLE_ENUM_H_ */ +#ifndef UPB_MINI_TABLE_SUB_H_ +#define UPB_MINI_TABLE_SUB_H_ + + +// Must be last. + +#ifdef __cplusplus +extern "C" { +#endif + +// Constructors + +UPB_API_INLINE upb_MiniTableSub +upb_MiniTableSub_FromEnum(const upb_MiniTableEnum* subenum) { + return UPB_PRIVATE(_upb_MiniTableSub_FromEnum)(subenum); +} + +UPB_API_INLINE upb_MiniTableSub +upb_MiniTableSub_FromMessage(const upb_MiniTable* submsg) { + return UPB_PRIVATE(_upb_MiniTableSub_FromMessage)(submsg); +} + +// Getters + +UPB_API_INLINE const upb_MiniTableEnum* upb_MiniTableSub_Enum( + upb_MiniTableSub sub) { + return UPB_PRIVATE(_upb_MiniTableSub_Enum)(sub); +} + +UPB_API_INLINE const upb_MiniTable* upb_MiniTableSub_Message( + upb_MiniTableSub sub) { + return UPB_PRIVATE(_upb_MiniTableSub_Message)(sub); +} + +#ifdef __cplusplus +} /* extern "C" */ +#endif + + +#endif /* UPB_MINI_TABLE_SUB_H_ */ + // Must be last. #ifdef __cplusplus @@ -3788,13 +3791,12 @@ UPB_API const upb_MiniTableExtension* upb_ExtensionRegistry_Lookup( #ifndef UPB_MINI_TABLE_INTERNAL_FILE_H_ #define UPB_MINI_TABLE_INTERNAL_FILE_H_ - // Must be last. struct upb_MiniTableFile { - const upb_MiniTable** UPB_PRIVATE(msgs); - const upb_MiniTableEnum** UPB_PRIVATE(enums); - const upb_MiniTableExtension** UPB_PRIVATE(exts); + const struct upb_MiniTable** UPB_PRIVATE(msgs); + const struct upb_MiniTableEnum** UPB_PRIVATE(enums); + const struct upb_MiniTableExtension** UPB_PRIVATE(exts); int UPB_PRIVATE(msg_count); int UPB_PRIVATE(enum_count); int UPB_PRIVATE(ext_count); @@ -3805,34 +3807,34 @@ extern "C" { #endif UPB_INLINE int UPB_PRIVATE(_upb_MiniTableFile_EnumCount)( - const upb_MiniTableFile* f) { + const struct upb_MiniTableFile* f) { return f->UPB_PRIVATE(enum_count); } UPB_INLINE int UPB_PRIVATE(_upb_MiniTableFile_ExtensionCount)( - const upb_MiniTableFile* f) { + const struct upb_MiniTableFile* f) { return f->UPB_PRIVATE(ext_count); } UPB_INLINE int UPB_PRIVATE(_upb_MiniTableFile_MessageCount)( - const upb_MiniTableFile* f) { + const struct upb_MiniTableFile* f) { return f->UPB_PRIVATE(msg_count); } -UPB_INLINE const upb_MiniTableEnum* UPB_PRIVATE(_upb_MiniTableFile_Enum)( - const upb_MiniTableFile* f, int i) { +UPB_INLINE const struct upb_MiniTableEnum* UPB_PRIVATE(_upb_MiniTableFile_Enum)( + const struct upb_MiniTableFile* f, int i) { UPB_ASSERT(i < f->UPB_PRIVATE(enum_count)); return f->UPB_PRIVATE(enums)[i]; } -UPB_INLINE const upb_MiniTableExtension* UPB_PRIVATE( - _upb_MiniTableFile_Extension)(const upb_MiniTableFile* f, int i) { +UPB_INLINE const struct upb_MiniTableExtension* UPB_PRIVATE( + _upb_MiniTableFile_Extension)(const struct upb_MiniTableFile* f, int i) { UPB_ASSERT(i < f->UPB_PRIVATE(ext_count)); return f->UPB_PRIVATE(exts)[i]; } -UPB_INLINE const upb_MiniTable* UPB_PRIVATE(_upb_MiniTableFile_Message)( - const upb_MiniTableFile* f, int i) { +UPB_INLINE const struct upb_MiniTable* UPB_PRIVATE(_upb_MiniTableFile_Message)( + const struct upb_MiniTableFile* f, int i) { UPB_ASSERT(i < f->UPB_PRIVATE(msg_count)); return f->UPB_PRIVATE(msgs)[i]; } diff --git a/ruby/ext/google/protobuf_c/ruby-upb.c b/ruby/ext/google/protobuf_c/ruby-upb.c index 27aa17ec2c233..89a20f3d56513 100644 --- a/ruby/ext/google/protobuf_c/ruby-upb.c +++ b/ruby/ext/google/protobuf_c/ruby-upb.c @@ -7941,7 +7941,7 @@ const upb_MiniTableExtension* upb_ExtensionRegistry_Lookup( // Must be last. // A MiniTable for an empty message, used for unlinked sub-messages. -const upb_MiniTable UPB_PRIVATE(_kUpb_MiniTable_Empty) = { +const struct upb_MiniTable UPB_PRIVATE(_kUpb_MiniTable_Empty) = { .UPB_PRIVATE(subs) = NULL, .UPB_PRIVATE(fields) = NULL, .UPB_PRIVATE(size) = 0, diff --git a/ruby/ext/google/protobuf_c/ruby-upb.h b/ruby/ext/google/protobuf_c/ruby-upb.h index d6444164c49bc..46a568f0dd565 100755 --- a/ruby/ext/google/protobuf_c/ruby-upb.h +++ b/ruby/ext/google/protobuf_c/ruby-upb.h @@ -1091,21 +1091,6 @@ UPB_INLINE int UPB_PRIVATE(_upb_FieldType_SizeLg2)(upb_FieldType field_type) { #endif /* UPB_MINI_TABLE_INTERNAL_SIZE_LOG2_H_ */ -#ifndef UPB_MINI_TABLE_TYPES_H_ -#define UPB_MINI_TABLE_TYPES_H_ - -// Minitable types are recursively defined so declare them all together here. - -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; - -#endif /* UPB_MINI_TABLE_TYPES_H_ */ - // Must be last. // LINT.IfChange(struct_definition) @@ -1166,47 +1151,47 @@ extern "C" { #endif UPB_INLINE upb_FieldMode -UPB_PRIVATE(_upb_MiniTableField_Mode)(const upb_MiniTableField* f) { +UPB_PRIVATE(_upb_MiniTableField_Mode)(const struct upb_MiniTableField* f) { return (upb_FieldMode)(f->UPB_ONLYBITS(mode) & kUpb_FieldMode_Mask); } UPB_INLINE upb_FieldRep -UPB_PRIVATE(_upb_MiniTableField_GetRep)(const upb_MiniTableField* f) { +UPB_PRIVATE(_upb_MiniTableField_GetRep)(const struct upb_MiniTableField* f) { return (upb_FieldRep)(f->UPB_ONLYBITS(mode) >> kUpb_FieldRep_Shift); } UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsArray)( - const upb_MiniTableField* f) { + const struct upb_MiniTableField* f) { return UPB_PRIVATE(_upb_MiniTableField_Mode)(f) == kUpb_FieldMode_Array; } UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsMap)( - const upb_MiniTableField* f) { + const struct upb_MiniTableField* f) { return UPB_PRIVATE(_upb_MiniTableField_Mode)(f) == kUpb_FieldMode_Map; } UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsScalar)( - const upb_MiniTableField* f) { + const struct upb_MiniTableField* f) { return UPB_PRIVATE(_upb_MiniTableField_Mode)(f) == kUpb_FieldMode_Scalar; } UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsAlternate)( - const upb_MiniTableField* f) { + const struct upb_MiniTableField* f) { return (f->UPB_ONLYBITS(mode) & kUpb_LabelFlags_IsAlternate) != 0; } UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsExtension)( - const upb_MiniTableField* f) { + const struct upb_MiniTableField* f) { return (f->UPB_ONLYBITS(mode) & kUpb_LabelFlags_IsExtension) != 0; } UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsPacked)( - const upb_MiniTableField* f) { + const struct upb_MiniTableField* f) { return (f->UPB_ONLYBITS(mode) & kUpb_LabelFlags_IsPacked) != 0; } UPB_INLINE upb_FieldType -UPB_PRIVATE(_upb_MiniTableField_Type)(const upb_MiniTableField* f) { +UPB_PRIVATE(_upb_MiniTableField_Type)(const struct upb_MiniTableField* f) { const upb_FieldType type = (upb_FieldType)f->UPB_PRIVATE(descriptortype); if (UPB_PRIVATE(_upb_MiniTableField_IsAlternate)(f)) { if (type == kUpb_FieldType_Int32) return kUpb_FieldType_Enum; @@ -1217,7 +1202,7 @@ UPB_PRIVATE(_upb_MiniTableField_Type)(const upb_MiniTableField* f) { } UPB_INLINE upb_CType -UPB_PRIVATE(_upb_MiniTableField_CType)(const upb_MiniTableField* f) { +UPB_PRIVATE(_upb_MiniTableField_CType)(const struct upb_MiniTableField* f) { return upb_FieldType_CType(UPB_PRIVATE(_upb_MiniTableField_Type)(f)); } @@ -1236,23 +1221,23 @@ UPB_INLINE size_t UPB_PRIVATE(_upb_MiniTableField_HasbitOffset)( } UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsClosedEnum)( - const upb_MiniTableField* f) { + const struct upb_MiniTableField* f) { return f->UPB_PRIVATE(descriptortype) == kUpb_FieldType_Enum; } UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsInOneof)( - const upb_MiniTableField* f) { + const struct upb_MiniTableField* f) { return f->presence < 0; } UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsSubMessage)( - const upb_MiniTableField* f) { + const struct upb_MiniTableField* f) { return f->UPB_PRIVATE(descriptortype) == kUpb_FieldType_Message || f->UPB_PRIVATE(descriptortype) == kUpb_FieldType_Group; } UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_HasPresence)( - const upb_MiniTableField* f) { + const struct upb_MiniTableField* f) { if (UPB_PRIVATE(_upb_MiniTableField_IsExtension)(f)) { return UPB_PRIVATE(_upb_MiniTableField_IsScalar)(f); } else { @@ -1277,7 +1262,7 @@ UPB_INLINE size_t UPB_PRIVATE(_upb_MiniTableField_OneofOffset)( } UPB_INLINE void UPB_PRIVATE(_upb_MiniTableField_CheckIsArray)( - const upb_MiniTableField* f) { + const struct upb_MiniTableField* f) { UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_NativePointer); UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_IsArray)(f)); @@ -1285,15 +1270,15 @@ UPB_INLINE void UPB_PRIVATE(_upb_MiniTableField_CheckIsArray)( } UPB_INLINE void UPB_PRIVATE(_upb_MiniTableField_CheckIsMap)( - const upb_MiniTableField* f) { + const struct upb_MiniTableField* f) { UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_NativePointer); UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_IsMap)(f)); UPB_ASSUME(f->presence == 0); } -UPB_INLINE size_t -UPB_PRIVATE(_upb_MiniTableField_ElemSizeLg2)(const upb_MiniTableField* f) { +UPB_INLINE size_t UPB_PRIVATE(_upb_MiniTableField_ElemSizeLg2)( + const struct upb_MiniTableField* f) { const upb_FieldType field_type = UPB_PRIVATE(_upb_MiniTableField_Type)(f); return UPB_PRIVATE(_upb_FieldType_SizeLg2)(field_type); } @@ -1310,39 +1295,38 @@ UPB_PRIVATE(_upb_MiniTableField_ElemSizeLg2)(const upb_MiniTableField* f) { #ifndef UPB_MINI_TABLE_INTERNAL_SUB_H_ #define UPB_MINI_TABLE_INTERNAL_SUB_H_ - // Must be last. union upb_MiniTableSub { - const upb_MiniTable* UPB_PRIVATE(submsg); - const upb_MiniTableEnum* UPB_PRIVATE(subenum); + const struct upb_MiniTable* UPB_PRIVATE(submsg); + const struct upb_MiniTableEnum* UPB_PRIVATE(subenum); }; #ifdef __cplusplus extern "C" { #endif -UPB_INLINE upb_MiniTableSub -UPB_PRIVATE(_upb_MiniTableSub_FromEnum)(const upb_MiniTableEnum* subenum) { - upb_MiniTableSub out; +UPB_INLINE union upb_MiniTableSub UPB_PRIVATE(_upb_MiniTableSub_FromEnum)( + const struct upb_MiniTableEnum* subenum) { + union upb_MiniTableSub out; out.UPB_PRIVATE(subenum) = subenum; return out; } -UPB_INLINE upb_MiniTableSub -UPB_PRIVATE(_upb_MiniTableSub_FromMessage)(const upb_MiniTable* submsg) { - upb_MiniTableSub out; +UPB_INLINE union upb_MiniTableSub UPB_PRIVATE(_upb_MiniTableSub_FromMessage)( + const struct upb_MiniTable* submsg) { + union upb_MiniTableSub out; out.UPB_PRIVATE(submsg) = submsg; return out; } -UPB_INLINE const upb_MiniTableEnum* UPB_PRIVATE(_upb_MiniTableSub_Enum)( - const upb_MiniTableSub sub) { +UPB_INLINE const struct upb_MiniTableEnum* UPB_PRIVATE(_upb_MiniTableSub_Enum)( + const union upb_MiniTableSub sub) { return sub.UPB_PRIVATE(subenum); } -UPB_INLINE const upb_MiniTable* UPB_PRIVATE(_upb_MiniTableSub_Message)( - const upb_MiniTableSub sub) { +UPB_INLINE const struct upb_MiniTable* UPB_PRIVATE(_upb_MiniTableSub_Message)( + const union upb_MiniTableSub sub) { return sub.UPB_PRIVATE(submsg); } @@ -1383,8 +1367,8 @@ typedef enum { // LINT.IfChange(minitable_struct_definition) struct upb_MiniTable { - const upb_MiniTableSub* UPB_PRIVATE(subs); - const upb_MiniTableField* UPB_ONLYBITS(fields); + const union upb_MiniTableSub* UPB_PRIVATE(subs); + const struct upb_MiniTableField* UPB_ONLYBITS(fields); // Must be aligned to sizeof(void*). Doesn't include internal members like // unknown fields, extension dict, pointer to msglayout, etc. @@ -1408,43 +1392,47 @@ struct upb_MiniTable { extern "C" { #endif -UPB_INLINE const upb_MiniTable* UPB_PRIVATE(_upb_MiniTable_Empty)(void) { - extern const upb_MiniTable UPB_PRIVATE(_kUpb_MiniTable_Empty); +UPB_INLINE const struct upb_MiniTable* UPB_PRIVATE(_upb_MiniTable_Empty)(void) { + extern const struct upb_MiniTable UPB_PRIVATE(_kUpb_MiniTable_Empty); return &UPB_PRIVATE(_kUpb_MiniTable_Empty); } -UPB_INLINE int UPB_PRIVATE(_upb_MiniTable_FieldCount)(const upb_MiniTable* m) { +UPB_INLINE int UPB_PRIVATE(_upb_MiniTable_FieldCount)( + const struct upb_MiniTable* m) { return m->UPB_ONLYBITS(field_count); } -UPB_INLINE bool UPB_PRIVATE(_upb_MiniTable_IsEmpty)(const upb_MiniTable* m) { - extern const upb_MiniTable UPB_PRIVATE(_kUpb_MiniTable_Empty); +UPB_INLINE bool UPB_PRIVATE(_upb_MiniTable_IsEmpty)( + const struct upb_MiniTable* m) { + extern const struct upb_MiniTable UPB_PRIVATE(_kUpb_MiniTable_Empty); return m == &UPB_PRIVATE(_kUpb_MiniTable_Empty); } -UPB_INLINE const upb_MiniTableField* UPB_PRIVATE( - _upb_MiniTable_GetFieldByIndex)(const upb_MiniTable* m, uint32_t i) { +UPB_INLINE const struct upb_MiniTableField* UPB_PRIVATE( + _upb_MiniTable_GetFieldByIndex)(const struct upb_MiniTable* m, uint32_t i) { return &m->UPB_ONLYBITS(fields)[i]; } -UPB_INLINE const upb_MiniTableSub* UPB_PRIVATE(_upb_MiniTable_GetSubByIndex)( - const upb_MiniTable* m, uint32_t i) { +UPB_INLINE const union upb_MiniTableSub* UPB_PRIVATE( + _upb_MiniTable_GetSubByIndex)(const struct upb_MiniTable* m, uint32_t i) { return &m->UPB_PRIVATE(subs)[i]; } -UPB_INLINE const upb_MiniTable* UPB_PRIVATE(_upb_MiniTable_GetSubMessageTable)( - const upb_MiniTable* m, const upb_MiniTableField* f) { +UPB_INLINE const struct upb_MiniTable* UPB_PRIVATE( + _upb_MiniTable_GetSubMessageTable)(const struct upb_MiniTable* m, + const struct upb_MiniTableField* f) { UPB_ASSERT(UPB_PRIVATE(_upb_MiniTableField_CType)(f) == kUpb_CType_Message); - const upb_MiniTable* ret = UPB_PRIVATE(_upb_MiniTableSub_Message)( + const struct upb_MiniTable* ret = UPB_PRIVATE(_upb_MiniTableSub_Message)( m->UPB_PRIVATE(subs)[f->UPB_PRIVATE(submsg_index)]); UPB_ASSUME(ret); return UPB_PRIVATE(_upb_MiniTable_IsEmpty)(ret) ? NULL : ret; } -UPB_INLINE const upb_MiniTableEnum* UPB_PRIVATE(_upb_MiniTable_GetSubEnumTable)( - const upb_MiniTable* m, const upb_MiniTableField* f) { +UPB_INLINE const struct upb_MiniTableEnum* UPB_PRIVATE( + _upb_MiniTable_GetSubEnumTable)(const struct upb_MiniTable* m, + const struct upb_MiniTableField* f) { UPB_ASSERT(UPB_PRIVATE(_upb_MiniTableField_CType)(f) == kUpb_CType_Enum); return UPB_PRIVATE(_upb_MiniTableSub_Enum)( m->UPB_PRIVATE(subs)[f->UPB_PRIVATE(submsg_index)]); @@ -1469,7 +1457,7 @@ UPB_INLINE const struct upb_MiniTableField* UPB_PRIVATE( } UPB_INLINE bool UPB_PRIVATE(_upb_MiniTable_MessageFieldIsLinked)( - const upb_MiniTable* m, const upb_MiniTableField* f) { + const struct upb_MiniTable* m, const struct upb_MiniTableField* f) { return UPB_PRIVATE(_upb_MiniTable_GetSubMessageTable)(m, f) != NULL; } @@ -1480,7 +1468,7 @@ UPB_INLINE bool UPB_PRIVATE(_upb_MiniTable_MessageFieldIsLinked)( // RequiredMask(1) => 0b10 (0x2) // RequiredMask(5) => 0b111110 (0x3e) UPB_INLINE uint64_t -UPB_PRIVATE(_upb_MiniTable_RequiredMask)(const upb_MiniTable* m) { +UPB_PRIVATE(_upb_MiniTable_RequiredMask)(const struct upb_MiniTable* m) { int n = m->UPB_PRIVATE(required_count); UPB_ASSERT(0 < n && n <= 63); return ((1ULL << n) - 1) << 1; @@ -1493,6 +1481,21 @@ UPB_PRIVATE(_upb_MiniTable_RequiredMask)(const upb_MiniTable* m) { #endif /* UPB_MINI_TABLE_INTERNAL_MESSAGE_H_ */ +#ifndef UPB_MINI_TABLE_TYPES_H_ +#define UPB_MINI_TABLE_TYPES_H_ + +// Minitable types are recursively defined so declare them all together here. + +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; + +#endif /* UPB_MINI_TABLE_TYPES_H_ */ + // Must be last. #ifdef __cplusplus @@ -1609,150 +1612,38 @@ size_t upb_Message_ExtensionCount(const upb_Message* msg); #include -#ifndef UPB_MINI_TABLE_FIELD_H_ -#define UPB_MINI_TABLE_FIELD_H_ - -#include - - -// Must be last. - -#ifdef __cplusplus -extern "C" { -#endif - -UPB_API_INLINE upb_CType upb_MiniTableField_CType(const upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTableField_CType)(f); -} - -UPB_API_INLINE bool upb_MiniTableField_HasPresence( - const upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTableField_HasPresence)(f); -} - -UPB_API_INLINE bool upb_MiniTableField_IsArray(const upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTableField_IsArray)(f); -} - -UPB_API_INLINE bool upb_MiniTableField_IsClosedEnum( - const upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTableField_IsClosedEnum)(f); -} - -UPB_API_INLINE bool upb_MiniTableField_IsExtension( - const upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTableField_IsExtension)(f); -} - -UPB_API_INLINE bool upb_MiniTableField_IsInOneof(const upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTableField_IsInOneof)(f); -} - -UPB_API_INLINE bool upb_MiniTableField_IsMap(const upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTableField_IsMap)(f); -} - -UPB_API_INLINE bool upb_MiniTableField_IsPacked(const upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTableField_IsPacked)(f); -} - -UPB_API_INLINE bool upb_MiniTableField_IsScalar(const upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTableField_IsScalar)(f); -} - -UPB_API_INLINE bool upb_MiniTableField_IsSubMessage( - const upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTableField_IsSubMessage)(f); -} - -UPB_API_INLINE uint32_t upb_MiniTableField_Number(const upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTableField_Number)(f); -} - -UPB_API_INLINE upb_FieldType -upb_MiniTableField_Type(const upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTableField_Type)(f); -} - -#ifdef __cplusplus -} /* extern "C" */ -#endif - - -#endif /* UPB_MINI_TABLE_FIELD_H_ */ - -#ifndef UPB_MINI_TABLE_SUB_H_ -#define UPB_MINI_TABLE_SUB_H_ - - -// Must be last. - -#ifdef __cplusplus -extern "C" { -#endif - -// Constructors - -UPB_API_INLINE upb_MiniTableSub -upb_MiniTableSub_FromEnum(const upb_MiniTableEnum* subenum) { - return UPB_PRIVATE(_upb_MiniTableSub_FromEnum)(subenum); -} - -UPB_API_INLINE upb_MiniTableSub -upb_MiniTableSub_FromMessage(const upb_MiniTable* submsg) { - return UPB_PRIVATE(_upb_MiniTableSub_FromMessage)(submsg); -} - -// Getters - -UPB_API_INLINE const upb_MiniTableEnum* upb_MiniTableSub_Enum( - upb_MiniTableSub sub) { - return UPB_PRIVATE(_upb_MiniTableSub_Enum)(sub); -} - -UPB_API_INLINE const upb_MiniTable* upb_MiniTableSub_Message( - upb_MiniTableSub sub) { - return UPB_PRIVATE(_upb_MiniTableSub_Message)(sub); -} - -#ifdef __cplusplus -} /* extern "C" */ -#endif - - -#endif /* UPB_MINI_TABLE_SUB_H_ */ - // Must be last. struct upb_MiniTableExtension { // Do not move this field. We need to be able to alias pointers. - upb_MiniTableField UPB_PRIVATE(field); + struct upb_MiniTableField UPB_PRIVATE(field); - const upb_MiniTable* UPB_PRIVATE(extendee); - upb_MiniTableSub UPB_PRIVATE(sub); // NULL unless submsg or proto2 enum + const struct upb_MiniTable* UPB_PRIVATE(extendee); + union upb_MiniTableSub UPB_PRIVATE(sub); // NULL unless submsg or proto2 enum }; #ifdef __cplusplus extern "C" { #endif -UPB_INLINE const upb_MiniTableField* UPB_PRIVATE( - _upb_MiniTableExtension_AsField)(const upb_MiniTableExtension* e) { - return (const upb_MiniTableField*)&e->UPB_PRIVATE(field); +UPB_INLINE const struct upb_MiniTableField* UPB_PRIVATE( + _upb_MiniTableExtension_AsField)(const struct upb_MiniTableExtension* e) { + return (const struct upb_MiniTableField*)&e->UPB_PRIVATE(field); } -UPB_INLINE uint32_t -UPB_PRIVATE(_upb_MiniTableExtension_Number)(const upb_MiniTableExtension* e) { +UPB_INLINE uint32_t UPB_PRIVATE(_upb_MiniTableExtension_Number)( + const struct upb_MiniTableExtension* e) { return e->UPB_PRIVATE(field).UPB_ONLYBITS(number); } -UPB_INLINE const upb_MiniTable* UPB_PRIVATE( - _upb_MiniTableExtension_GetSubMessage)(const upb_MiniTableExtension* e) { - return upb_MiniTableSub_Message(e->UPB_PRIVATE(sub)); +UPB_INLINE const struct upb_MiniTable* UPB_PRIVATE( + _upb_MiniTableExtension_GetSubMessage)( + const struct upb_MiniTableExtension* e) { + return UPB_PRIVATE(_upb_MiniTableSub_Message)(e->UPB_PRIVATE(sub)); } UPB_INLINE void UPB_PRIVATE(_upb_MiniTableExtension_SetSubMessage)( - upb_MiniTableExtension* e, const upb_MiniTable* m) { + struct upb_MiniTableExtension* e, const struct upb_MiniTable* m) { e->UPB_PRIVATE(sub).UPB_PRIVATE(submsg) = m; } @@ -2502,6 +2393,78 @@ bool UPB_PRIVATE(_upb_Message_Realloc)(upb_Message* msg, size_t need, #endif /* UPB_MESSAGE_INTERNAL_H_ */ +#ifndef UPB_MINI_TABLE_FIELD_H_ +#define UPB_MINI_TABLE_FIELD_H_ + +#include + + +// Must be last. + +#ifdef __cplusplus +extern "C" { +#endif + +UPB_API_INLINE upb_CType upb_MiniTableField_CType(const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_CType)(f); +} + +UPB_API_INLINE bool upb_MiniTableField_HasPresence( + const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_HasPresence)(f); +} + +UPB_API_INLINE bool upb_MiniTableField_IsArray(const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_IsArray)(f); +} + +UPB_API_INLINE bool upb_MiniTableField_IsClosedEnum( + const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_IsClosedEnum)(f); +} + +UPB_API_INLINE bool upb_MiniTableField_IsExtension( + const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_IsExtension)(f); +} + +UPB_API_INLINE bool upb_MiniTableField_IsInOneof(const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_IsInOneof)(f); +} + +UPB_API_INLINE bool upb_MiniTableField_IsMap(const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_IsMap)(f); +} + +UPB_API_INLINE bool upb_MiniTableField_IsPacked(const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_IsPacked)(f); +} + +UPB_API_INLINE bool upb_MiniTableField_IsScalar(const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_IsScalar)(f); +} + +UPB_API_INLINE bool upb_MiniTableField_IsSubMessage( + const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_IsSubMessage)(f); +} + +UPB_API_INLINE uint32_t upb_MiniTableField_Number(const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_Number)(f); +} + +UPB_API_INLINE upb_FieldType +upb_MiniTableField_Type(const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_Type)(f); +} + +#ifdef __cplusplus +} /* extern "C" */ +#endif + + +#endif /* UPB_MINI_TABLE_FIELD_H_ */ + // Must be last. #if defined(__GNUC__) && !defined(__clang__) @@ -2962,7 +2925,6 @@ UPB_INLINE void UPB_PRIVATE(_upb_Array_Set)(upb_Array* array, size_t i, #include - // Must be last. struct upb_MiniTableEnum { @@ -2976,7 +2938,7 @@ extern "C" { #endif UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableEnum_CheckValue)( - const upb_MiniTableEnum* e, uint32_t val) { + const struct upb_MiniTableEnum* e, uint32_t val) { if (UPB_LIKELY(val < 64)) { const uint64_t mask = e->UPB_PRIVATE(data)[0] | ((uint64_t)e->UPB_PRIVATE(data)[1] << 32); @@ -3026,6 +2988,47 @@ UPB_INLINE bool upb_MiniTableEnum_CheckValue(const upb_MiniTableEnum* e, #endif /* UPB_MINI_TABLE_ENUM_H_ */ +#ifndef UPB_MINI_TABLE_SUB_H_ +#define UPB_MINI_TABLE_SUB_H_ + + +// Must be last. + +#ifdef __cplusplus +extern "C" { +#endif + +// Constructors + +UPB_API_INLINE upb_MiniTableSub +upb_MiniTableSub_FromEnum(const upb_MiniTableEnum* subenum) { + return UPB_PRIVATE(_upb_MiniTableSub_FromEnum)(subenum); +} + +UPB_API_INLINE upb_MiniTableSub +upb_MiniTableSub_FromMessage(const upb_MiniTable* submsg) { + return UPB_PRIVATE(_upb_MiniTableSub_FromMessage)(submsg); +} + +// Getters + +UPB_API_INLINE const upb_MiniTableEnum* upb_MiniTableSub_Enum( + upb_MiniTableSub sub) { + return UPB_PRIVATE(_upb_MiniTableSub_Enum)(sub); +} + +UPB_API_INLINE const upb_MiniTable* upb_MiniTableSub_Message( + upb_MiniTableSub sub) { + return UPB_PRIVATE(_upb_MiniTableSub_Message)(sub); +} + +#ifdef __cplusplus +} /* extern "C" */ +#endif + + +#endif /* UPB_MINI_TABLE_SUB_H_ */ + // Must be last. #ifdef __cplusplus @@ -3790,13 +3793,12 @@ UPB_API const upb_MiniTableExtension* upb_ExtensionRegistry_Lookup( #ifndef UPB_MINI_TABLE_INTERNAL_FILE_H_ #define UPB_MINI_TABLE_INTERNAL_FILE_H_ - // Must be last. struct upb_MiniTableFile { - const upb_MiniTable** UPB_PRIVATE(msgs); - const upb_MiniTableEnum** UPB_PRIVATE(enums); - const upb_MiniTableExtension** UPB_PRIVATE(exts); + const struct upb_MiniTable** UPB_PRIVATE(msgs); + const struct upb_MiniTableEnum** UPB_PRIVATE(enums); + const struct upb_MiniTableExtension** UPB_PRIVATE(exts); int UPB_PRIVATE(msg_count); int UPB_PRIVATE(enum_count); int UPB_PRIVATE(ext_count); @@ -3807,34 +3809,34 @@ extern "C" { #endif UPB_INLINE int UPB_PRIVATE(_upb_MiniTableFile_EnumCount)( - const upb_MiniTableFile* f) { + const struct upb_MiniTableFile* f) { return f->UPB_PRIVATE(enum_count); } UPB_INLINE int UPB_PRIVATE(_upb_MiniTableFile_ExtensionCount)( - const upb_MiniTableFile* f) { + const struct upb_MiniTableFile* f) { return f->UPB_PRIVATE(ext_count); } UPB_INLINE int UPB_PRIVATE(_upb_MiniTableFile_MessageCount)( - const upb_MiniTableFile* f) { + const struct upb_MiniTableFile* f) { return f->UPB_PRIVATE(msg_count); } -UPB_INLINE const upb_MiniTableEnum* UPB_PRIVATE(_upb_MiniTableFile_Enum)( - const upb_MiniTableFile* f, int i) { +UPB_INLINE const struct upb_MiniTableEnum* UPB_PRIVATE(_upb_MiniTableFile_Enum)( + const struct upb_MiniTableFile* f, int i) { UPB_ASSERT(i < f->UPB_PRIVATE(enum_count)); return f->UPB_PRIVATE(enums)[i]; } -UPB_INLINE const upb_MiniTableExtension* UPB_PRIVATE( - _upb_MiniTableFile_Extension)(const upb_MiniTableFile* f, int i) { +UPB_INLINE const struct upb_MiniTableExtension* UPB_PRIVATE( + _upb_MiniTableFile_Extension)(const struct upb_MiniTableFile* f, int i) { UPB_ASSERT(i < f->UPB_PRIVATE(ext_count)); return f->UPB_PRIVATE(exts)[i]; } -UPB_INLINE const upb_MiniTable* UPB_PRIVATE(_upb_MiniTableFile_Message)( - const upb_MiniTableFile* f, int i) { +UPB_INLINE const struct upb_MiniTable* UPB_PRIVATE(_upb_MiniTableFile_Message)( + const struct upb_MiniTableFile* f, int i) { UPB_ASSERT(i < f->UPB_PRIVATE(msg_count)); return f->UPB_PRIVATE(msgs)[i]; } From ca58c35e249e8e9153fe96cec705335279ebce7c Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Tue, 26 Dec 2023 15:33:13 -0800 Subject: [PATCH 102/255] Added `explicit` to a single-arg constructor to fix a ClangTidy warning. This is the only remaining ClangTidy warning in this directory. PiperOrigin-RevId: 593867029 --- upb/wire/eps_copy_input_stream_test.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/upb/wire/eps_copy_input_stream_test.cc b/upb/wire/eps_copy_input_stream_test.cc index 7a3caa2df0754..c28d1457e4743 100644 --- a/upb/wire/eps_copy_input_stream_test.cc +++ b/upb/wire/eps_copy_input_stream_test.cc @@ -34,7 +34,7 @@ TEST(EpsCopyInputStreamTest, ZeroSize) { // // class FakeStream { // public: -// FakeStream(const std::string& data) : data_(data), offset_(0) { +// explicit FakeStream(const std::string& data) : data_(data), offset_(0) { // limits_.push_back(data.size()); // } // From e3972962176f0db6340213ada3ea34285349b199 Mon Sep 17 00:00:00 2001 From: Eric Salo Date: Tue, 26 Dec 2023 16:00:42 -0800 Subject: [PATCH 103/255] upb: restore the mini_table:internal target PiperOrigin-RevId: 593870914 --- upb/BUILD | 5 +++++ upb/message/BUILD | 2 ++ upb/mini_descriptor/BUILD | 1 + upb/mini_table/BUILD | 25 +++++++++++++++++++++---- upb/wire/BUILD | 1 + 5 files changed, 30 insertions(+), 4 deletions(-) diff --git a/upb/BUILD b/upb/BUILD index 094054b14783e..6ac5299826ce2 100644 --- a/upb/BUILD +++ b/upb/BUILD @@ -396,6 +396,7 @@ upb_amalgamation( ":wire", ":wire_reader", "//upb/mem:internal", + "//upb/mini_table:internal", ], strip_import_prefix = ["src"], ) @@ -437,12 +438,14 @@ upb_amalgamation( ":mini_descriptor", ":mini_descriptor_internal", ":mini_table", + ":mini_table_compat", ":port", ":reflection", ":reflection_internal", ":wire", ":wire_reader", "//upb/mem:internal", + "//upb/mini_table:internal", ], prefix = "php-", strip_import_prefix = ["src"], @@ -485,12 +488,14 @@ upb_amalgamation( ":mini_descriptor", ":mini_descriptor_internal", ":mini_table", + ":mini_table_compat", ":port", ":reflection", ":reflection_internal", ":wire", ":wire_reader", "//upb/mem:internal", + "//upb/mini_table:internal", ], prefix = "ruby-", strip_import_prefix = ["src"], diff --git a/upb/message/BUILD b/upb/message/BUILD index 6a2660ace90c4..cfb883e24e90f 100644 --- a/upb/message/BUILD +++ b/upb/message/BUILD @@ -82,6 +82,7 @@ cc_library( "//upb:mem", "//upb:mini_table", "//upb:port", + "//upb/mini_table:internal", ], ) @@ -119,6 +120,7 @@ cc_library( "//upb:mem", "//upb:mini_table", "//upb:port", + "//upb/mini_table:internal", ], ) diff --git a/upb/mini_descriptor/BUILD b/upb/mini_descriptor/BUILD index 9ea571e6bbe28..fafcf419c931e 100644 --- a/upb/mini_descriptor/BUILD +++ b/upb/mini_descriptor/BUILD @@ -25,6 +25,7 @@ cc_library( "//upb:mem", "//upb:mini_table", "//upb:port", + "//upb/mini_table:internal", ], ) diff --git a/upb/mini_table/BUILD b/upb/mini_table/BUILD index 4c73d1c39a453..7fb1c1693ebf7 100644 --- a/upb/mini_table/BUILD +++ b/upb/mini_table/BUILD @@ -14,7 +14,6 @@ cc_library( name = "mini_table", srcs = [ "extension_registry.c", - "internal/message.c", "message.c", ], hdrs = [ @@ -23,6 +22,27 @@ cc_library( "extension_registry.h", "field.h", "file.h", + "message.h", + "sub.h", + "types.h", + ], + copts = UPB_DEFAULT_COPTS, + visibility = ["//visibility:public"], + deps = [ + ":internal", + "//upb:base", + "//upb:hash", + "//upb:mem", + "//upb:port", + ], +) + +cc_library( + name = "internal", + srcs = [ + "internal/message.c", + ], + hdrs = [ "internal/enum.h", "internal/extension.h", "internal/field.h", @@ -30,9 +50,6 @@ cc_library( "internal/message.h", "internal/size_log2.h", "internal/sub.h", - "message.h", - "sub.h", - "types.h", ], copts = UPB_DEFAULT_COPTS, visibility = ["//visibility:public"], diff --git a/upb/wire/BUILD b/upb/wire/BUILD index e415a1894de1c..3e93221067a21 100644 --- a/upb/wire/BUILD +++ b/upb/wire/BUILD @@ -38,6 +38,7 @@ cc_library( "//upb:mini_table", "//upb:port", "//upb/mem:internal", + "//upb/mini_table:internal", "//third_party/utf8_range", ], ) From c4a7b036ad42df95342914cbfea264a8f4931c49 Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Wed, 27 Dec 2023 00:12:48 +0000 Subject: [PATCH 104/255] Auto-generate files after cl/593870914 --- php/ext/google/protobuf/php-upb.c | 134 ++++++++++++++++++++++---- php/ext/google/protobuf/php-upb.h | 36 +++++++ ruby/ext/google/protobuf_c/ruby-upb.c | 134 ++++++++++++++++++++++---- ruby/ext/google/protobuf_c/ruby-upb.h | 36 +++++++ 4 files changed, 306 insertions(+), 34 deletions(-) diff --git a/php/ext/google/protobuf/php-upb.c b/php/ext/google/protobuf/php-upb.c index 9b13b7f4d0c6b..4d866a5b33086 100644 --- a/php/ext/google/protobuf/php-upb.c +++ b/php/ext/google/protobuf/php-upb.c @@ -8420,23 +8420,6 @@ const upb_MiniTableExtension* upb_ExtensionRegistry_Lookup( } -#include - -// Must be last. - -// A MiniTable for an empty message, used for unlinked sub-messages. -const struct upb_MiniTable UPB_PRIVATE(_kUpb_MiniTable_Empty) = { - .UPB_PRIVATE(subs) = NULL, - .UPB_PRIVATE(fields) = NULL, - .UPB_PRIVATE(size) = 0, - .UPB_PRIVATE(field_count) = 0, - .UPB_PRIVATE(ext) = kUpb_ExtMode_NonExtendable, - .UPB_PRIVATE(dense_below) = 0, - .UPB_PRIVATE(table_mask) = -1, - .UPB_PRIVATE(required_count) = 0, -}; - - #include #include #include @@ -8504,6 +8487,106 @@ bool upb_MiniTable_NextOneofField(const upb_MiniTable* m, } +#include +#include + + +// Must be last. + +// Checks if source and target mini table fields are identical. +// +// If the field is a sub message and sub messages are identical we record +// the association in table. +// +// Hashing the source sub message mini table and it's equivalent in the table +// stops recursing when a cycle is detected and instead just checks if the +// destination table is equal. +static upb_MiniTableEquals_Status upb_deep_check(const upb_MiniTable* src, + const upb_MiniTable* dst, + upb_inttable* table, + upb_Arena** arena) { + if (src->UPB_PRIVATE(field_count) != dst->UPB_PRIVATE(field_count)) + return kUpb_MiniTableEquals_NotEqual; + bool marked_src = false; + for (int i = 0; i < upb_MiniTable_FieldCount(src); i++) { + const upb_MiniTableField* src_field = upb_MiniTable_GetFieldByIndex(src, i); + const upb_MiniTableField* dst_field = upb_MiniTable_FindFieldByNumber( + dst, upb_MiniTableField_Number(src_field)); + + if (upb_MiniTableField_CType(src_field) != + upb_MiniTableField_CType(dst_field)) + return false; + if (src_field->UPB_PRIVATE(mode) != dst_field->UPB_PRIVATE(mode)) + return false; + if (src_field->UPB_PRIVATE(offset) != dst_field->UPB_PRIVATE(offset)) + return false; + if (src_field->presence != dst_field->presence) return false; + if (src_field->UPB_PRIVATE(submsg_index) != + dst_field->UPB_PRIVATE(submsg_index)) + return kUpb_MiniTableEquals_NotEqual; + + // Go no further if we are only checking for compatibility. + if (!table) continue; + + if (upb_MiniTableField_CType(src_field) == kUpb_CType_Message) { + if (!*arena) { + *arena = upb_Arena_New(); + if (!upb_inttable_init(table, *arena)) { + return kUpb_MiniTableEquals_OutOfMemory; + } + } + if (!marked_src) { + marked_src = true; + upb_value val; + val.val = (uint64_t)dst; + if (!upb_inttable_insert(table, (uintptr_t)src, val, *arena)) { + return kUpb_MiniTableEquals_OutOfMemory; + } + } + const upb_MiniTable* sub_src = + upb_MiniTable_GetSubMessageTable(src, src_field); + const upb_MiniTable* sub_dst = + upb_MiniTable_GetSubMessageTable(dst, dst_field); + if (sub_src != NULL) { + upb_value cmp; + if (upb_inttable_lookup(table, (uintptr_t)sub_src, &cmp)) { + // We already compared this src before. Check if same dst. + if (cmp.val != (uint64_t)sub_dst) { + return kUpb_MiniTableEquals_NotEqual; + } + } else { + // Recurse if not already visited. + upb_MiniTableEquals_Status s = + upb_deep_check(sub_src, sub_dst, table, arena); + if (s != kUpb_MiniTableEquals_Equal) { + return s; + } + } + } + } + } + return kUpb_MiniTableEquals_Equal; +} + +bool upb_MiniTable_Compatible(const upb_MiniTable* src, + const upb_MiniTable* dst) { + return upb_deep_check(src, dst, NULL, NULL); +} + +upb_MiniTableEquals_Status upb_MiniTable_Equals(const upb_MiniTable* src, + const upb_MiniTable* dst) { + // Arena allocated on demand for hash table. + upb_Arena* arena = NULL; + // Table to keep track of visited mini tables to guard against cycles. + upb_inttable table; + upb_MiniTableEquals_Status status = upb_deep_check(src, dst, &table, &arena); + if (arena) { + upb_Arena_Free(arena); + } + return status; +} + + // Must be last. @@ -15792,6 +15875,23 @@ const char* UPB_PRIVATE(_upb_WireReader_SkipGroup)( return ptr; } + +#include + +// Must be last. + +// A MiniTable for an empty message, used for unlinked sub-messages. +const struct upb_MiniTable UPB_PRIVATE(_kUpb_MiniTable_Empty) = { + .UPB_PRIVATE(subs) = NULL, + .UPB_PRIVATE(fields) = NULL, + .UPB_PRIVATE(size) = 0, + .UPB_PRIVATE(field_count) = 0, + .UPB_PRIVATE(ext) = kUpb_ExtMode_NonExtendable, + .UPB_PRIVATE(dense_below) = 0, + .UPB_PRIVATE(table_mask) = -1, + .UPB_PRIVATE(required_count) = 0, +}; + // This should #undef all macros #defined in def.inc #undef UPB_SIZE diff --git a/php/ext/google/protobuf/php-upb.h b/php/ext/google/protobuf/php-upb.h index eb716f45c4d94..6dd35f57d4de8 100644 --- a/php/ext/google/protobuf/php-upb.h +++ b/php/ext/google/protobuf/php-upb.h @@ -12986,6 +12986,42 @@ char* upb_MtDataEncoder_EncodeMessageSet(upb_MtDataEncoder* e, char* ptr); #endif /* UPB_MINI_DESCRIPTOR_INTERNAL_ENCODE_H_ */ +#ifndef UPB_MINI_TABLE_COMPAT_H_ +#define UPB_MINI_TABLE_COMPAT_H_ + + +// Must be last. + +// upb does not support mixing minitables from different sources but these +// functions are still used by some existing users so for now we make them +// available here. This may or may not change in the future so do not add +// them to new code. + +#ifdef __cplusplus +extern "C" { +#endif + +// Checks if memory layout of src is compatible with dst. +bool upb_MiniTable_Compatible(const upb_MiniTable* src, + const upb_MiniTable* dst); + +typedef enum { + kUpb_MiniTableEquals_NotEqual, + kUpb_MiniTableEquals_Equal, + kUpb_MiniTableEquals_OutOfMemory, +} upb_MiniTableEquals_Status; + +// Checks equality of mini tables originating from different language runtimes. +upb_MiniTableEquals_Status upb_MiniTable_Equals(const upb_MiniTable* src, + const upb_MiniTable* dst); + +#ifdef __cplusplus +} /* extern "C" */ +#endif + + +#endif /* UPB_MINI_TABLE_COMPAT_H_ */ + #ifndef UPB_REFLECTION_DEF_BUILDER_INTERNAL_H_ #define UPB_REFLECTION_DEF_BUILDER_INTERNAL_H_ diff --git a/ruby/ext/google/protobuf_c/ruby-upb.c b/ruby/ext/google/protobuf_c/ruby-upb.c index 89a20f3d56513..07f17c3ff6245 100644 --- a/ruby/ext/google/protobuf_c/ruby-upb.c +++ b/ruby/ext/google/protobuf_c/ruby-upb.c @@ -7936,23 +7936,6 @@ const upb_MiniTableExtension* upb_ExtensionRegistry_Lookup( } -#include - -// Must be last. - -// A MiniTable for an empty message, used for unlinked sub-messages. -const struct upb_MiniTable UPB_PRIVATE(_kUpb_MiniTable_Empty) = { - .UPB_PRIVATE(subs) = NULL, - .UPB_PRIVATE(fields) = NULL, - .UPB_PRIVATE(size) = 0, - .UPB_PRIVATE(field_count) = 0, - .UPB_PRIVATE(ext) = kUpb_ExtMode_NonExtendable, - .UPB_PRIVATE(dense_below) = 0, - .UPB_PRIVATE(table_mask) = -1, - .UPB_PRIVATE(required_count) = 0, -}; - - #include #include #include @@ -8020,6 +8003,106 @@ bool upb_MiniTable_NextOneofField(const upb_MiniTable* m, } +#include +#include + + +// Must be last. + +// Checks if source and target mini table fields are identical. +// +// If the field is a sub message and sub messages are identical we record +// the association in table. +// +// Hashing the source sub message mini table and it's equivalent in the table +// stops recursing when a cycle is detected and instead just checks if the +// destination table is equal. +static upb_MiniTableEquals_Status upb_deep_check(const upb_MiniTable* src, + const upb_MiniTable* dst, + upb_inttable* table, + upb_Arena** arena) { + if (src->UPB_PRIVATE(field_count) != dst->UPB_PRIVATE(field_count)) + return kUpb_MiniTableEquals_NotEqual; + bool marked_src = false; + for (int i = 0; i < upb_MiniTable_FieldCount(src); i++) { + const upb_MiniTableField* src_field = upb_MiniTable_GetFieldByIndex(src, i); + const upb_MiniTableField* dst_field = upb_MiniTable_FindFieldByNumber( + dst, upb_MiniTableField_Number(src_field)); + + if (upb_MiniTableField_CType(src_field) != + upb_MiniTableField_CType(dst_field)) + return false; + if (src_field->UPB_PRIVATE(mode) != dst_field->UPB_PRIVATE(mode)) + return false; + if (src_field->UPB_PRIVATE(offset) != dst_field->UPB_PRIVATE(offset)) + return false; + if (src_field->presence != dst_field->presence) return false; + if (src_field->UPB_PRIVATE(submsg_index) != + dst_field->UPB_PRIVATE(submsg_index)) + return kUpb_MiniTableEquals_NotEqual; + + // Go no further if we are only checking for compatibility. + if (!table) continue; + + if (upb_MiniTableField_CType(src_field) == kUpb_CType_Message) { + if (!*arena) { + *arena = upb_Arena_New(); + if (!upb_inttable_init(table, *arena)) { + return kUpb_MiniTableEquals_OutOfMemory; + } + } + if (!marked_src) { + marked_src = true; + upb_value val; + val.val = (uint64_t)dst; + if (!upb_inttable_insert(table, (uintptr_t)src, val, *arena)) { + return kUpb_MiniTableEquals_OutOfMemory; + } + } + const upb_MiniTable* sub_src = + upb_MiniTable_GetSubMessageTable(src, src_field); + const upb_MiniTable* sub_dst = + upb_MiniTable_GetSubMessageTable(dst, dst_field); + if (sub_src != NULL) { + upb_value cmp; + if (upb_inttable_lookup(table, (uintptr_t)sub_src, &cmp)) { + // We already compared this src before. Check if same dst. + if (cmp.val != (uint64_t)sub_dst) { + return kUpb_MiniTableEquals_NotEqual; + } + } else { + // Recurse if not already visited. + upb_MiniTableEquals_Status s = + upb_deep_check(sub_src, sub_dst, table, arena); + if (s != kUpb_MiniTableEquals_Equal) { + return s; + } + } + } + } + } + return kUpb_MiniTableEquals_Equal; +} + +bool upb_MiniTable_Compatible(const upb_MiniTable* src, + const upb_MiniTable* dst) { + return upb_deep_check(src, dst, NULL, NULL); +} + +upb_MiniTableEquals_Status upb_MiniTable_Equals(const upb_MiniTable* src, + const upb_MiniTable* dst) { + // Arena allocated on demand for hash table. + upb_Arena* arena = NULL; + // Table to keep track of visited mini tables to guard against cycles. + upb_inttable table; + upb_MiniTableEquals_Status status = upb_deep_check(src, dst, &table, &arena); + if (arena) { + upb_Arena_Free(arena); + } + return status; +} + + // Must be last. @@ -15308,6 +15391,23 @@ const char* UPB_PRIVATE(_upb_WireReader_SkipGroup)( return ptr; } + +#include + +// Must be last. + +// A MiniTable for an empty message, used for unlinked sub-messages. +const struct upb_MiniTable UPB_PRIVATE(_kUpb_MiniTable_Empty) = { + .UPB_PRIVATE(subs) = NULL, + .UPB_PRIVATE(fields) = NULL, + .UPB_PRIVATE(size) = 0, + .UPB_PRIVATE(field_count) = 0, + .UPB_PRIVATE(ext) = kUpb_ExtMode_NonExtendable, + .UPB_PRIVATE(dense_below) = 0, + .UPB_PRIVATE(table_mask) = -1, + .UPB_PRIVATE(required_count) = 0, +}; + // This should #undef all macros #defined in def.inc #undef UPB_SIZE diff --git a/ruby/ext/google/protobuf_c/ruby-upb.h b/ruby/ext/google/protobuf_c/ruby-upb.h index 46a568f0dd565..244da19429f60 100755 --- a/ruby/ext/google/protobuf_c/ruby-upb.h +++ b/ruby/ext/google/protobuf_c/ruby-upb.h @@ -12758,6 +12758,42 @@ char* upb_MtDataEncoder_EncodeMessageSet(upb_MtDataEncoder* e, char* ptr); #endif /* UPB_MINI_DESCRIPTOR_INTERNAL_ENCODE_H_ */ +#ifndef UPB_MINI_TABLE_COMPAT_H_ +#define UPB_MINI_TABLE_COMPAT_H_ + + +// Must be last. + +// upb does not support mixing minitables from different sources but these +// functions are still used by some existing users so for now we make them +// available here. This may or may not change in the future so do not add +// them to new code. + +#ifdef __cplusplus +extern "C" { +#endif + +// Checks if memory layout of src is compatible with dst. +bool upb_MiniTable_Compatible(const upb_MiniTable* src, + const upb_MiniTable* dst); + +typedef enum { + kUpb_MiniTableEquals_NotEqual, + kUpb_MiniTableEquals_Equal, + kUpb_MiniTableEquals_OutOfMemory, +} upb_MiniTableEquals_Status; + +// Checks equality of mini tables originating from different language runtimes. +upb_MiniTableEquals_Status upb_MiniTable_Equals(const upb_MiniTable* src, + const upb_MiniTable* dst); + +#ifdef __cplusplus +} /* extern "C" */ +#endif + + +#endif /* UPB_MINI_TABLE_COMPAT_H_ */ + #ifndef UPB_REFLECTION_DEF_POOL_INTERNAL_H_ #define UPB_REFLECTION_DEF_POOL_INTERNAL_H_ From 2f7b2832b6a62fec88efacbb97bf0a91b6a3670e Mon Sep 17 00:00:00 2001 From: Sandy Zhang Date: Tue, 26 Dec 2023 19:44:33 -0800 Subject: [PATCH 105/255] Update Ruby GHA to test against Ruby 3.3. Fixes #15182 PiperOrigin-RevId: 593899707 --- .github/workflows/test_ruby.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test_ruby.yml b/.github/workflows/test_ruby.yml index 80b4db9c9a0bd..726e0aa9c5b2e 100644 --- a/.github/workflows/test_ruby.yml +++ b/.github/workflows/test_ruby.yml @@ -25,6 +25,7 @@ jobs: - { name: Ruby 3.0, ruby: ruby-3.0.2 } - { name: Ruby 3.1, ruby: ruby-3.1.0 } - { name: Ruby 3.2, ruby: ruby-3.2.0, ffi: NATIVE } + - { name: Ruby 3.3, ruby: ruby-3.3.0, ffi: NATIVE } # TODO Re-enable these once flakes are fixed #- { name: Ruby 3.2, ruby: ruby-3.2.0, ffi: FFI } - { name: JRuby 9.4, ruby: jruby-9.4.3.0, ffi: NATIVE } @@ -40,7 +41,7 @@ jobs: - name: Run tests uses: protocolbuffers/protobuf-ci/bazel-docker@v2 with: - image: ${{ matrix.image || format('us-docker.pkg.dev/protobuf-build/containers/test/linux/ruby:{0}-6.3.0-66964dc8b07b6d1fc73a5cc14e59e84c1c534cea', matrix.ruby) }} + image: ${{ matrix.image || format('us-docker.pkg.dev/protobuf-build/containers/test/linux/ruby:{0}-6.3.0-904cad5249547845454998ca3837a34c71fabf96', matrix.ruby) }} credentials: ${{ secrets.GAR_SERVICE_ACCOUNT }} bazel-cache: ruby_linux/${{ matrix.ruby }}_${{ matrix.bazel }} bazel: test //ruby/... //ruby/tests:ruby_version --test_env=KOKORO_RUBY_VERSION --test_env=BAZEL=true ${{ matrix.ffi == 'FFI' && '--//ruby:ffi=enabled --test_env=PROTOCOL_BUFFERS_RUBY_IMPLEMENTATION=FFI' || '' }} From 090c3adbf2f23c56d9aec67c367574a6b92aaa4d Mon Sep 17 00:00:00 2001 From: Eric Salo Date: Wed, 27 Dec 2023 11:52:12 -0800 Subject: [PATCH 106/255] upb: start consolidating the upb/message/ build targets PiperOrigin-RevId: 594074354 --- protos/BUILD | 4 +-- upb/BUILD | 29 ++++----------- upb/message/BUILD | 74 +++++++++------------------------------ upb/message/accessors.c | 25 ------------- upb/message/accessors.h | 4 --- upb/message/compare.c | 43 +++++++++++++++++++++++ upb/message/compare.h | 32 +++++++++++++++++ upb/mini_descriptor/BUILD | 2 +- upb/reflection/BUILD | 2 -- upb/text/BUILD | 1 - upb/upb_so.c | 3 ++ upb/wire/BUILD | 4 +-- 12 files changed, 105 insertions(+), 118 deletions(-) create mode 100644 upb/message/compare.c create mode 100644 upb/message/compare.h diff --git a/protos/BUILD b/protos/BUILD index b68a27eaac64d..7712c38bcb971 100644 --- a/protos/BUILD +++ b/protos/BUILD @@ -55,9 +55,9 @@ cc_library( ":protos_extension_lock", "//upb:base", "//upb:mem", - "//upb:message_accessors_internal", + "//upb:message", + "//upb:message_accessors", "//upb:message_copy", - "//upb:message_internal", "//upb:message_promote", "//upb:message_types", "//upb:mini_table", diff --git a/upb/BUILD b/upb/BUILD index 6ac5299826ce2..ff7ff72c49204 100644 --- a/upb/BUILD +++ b/upb/BUILD @@ -112,8 +112,6 @@ cc_library( ":mem", ":message", ":message_accessors", - ":message_accessors_internal", - ":message_internal", ":mini_descriptor", ":mini_table", ":wire", @@ -213,8 +211,8 @@ alias( ) alias( - name = "message_accessors_internal", - actual = "//upb/message:accessors_internal", + name = "message_compare", + actual = "//upb/message:compare", visibility = ["//upb:friends"], ) @@ -224,18 +222,6 @@ alias( visibility = ["//visibility:public"], ) -alias( - name = "message_internal", - actual = "//upb/message:internal", - visibility = ["//visibility:public"], -) - -alias( - name = "message_internal_types", - actual = "//upb/message:internal_types", - visibility = ["//visibility:public"], -) - alias( name = "message_promote", actual = "//upb/message:promote", @@ -351,10 +337,12 @@ cc_binary( ":mem", ":message", ":message_accessors", + ":message_compare", ":message_split64", ":mini_descriptor", ":mini_table", ":port", + ":wire", ], ) @@ -380,9 +368,8 @@ upb_amalgamation( ":mem", ":message", ":message_accessors", + ":message_compare", ":message_copy", - ":message_internal", - ":message_internal_types", ":message_tagged_ptr", ":message_types", ":message_value", @@ -429,9 +416,8 @@ upb_amalgamation( ":mem", ":message", ":message_accessors", + ":message_compare", ":message_copy", - ":message_internal", - ":message_internal_types", ":message_tagged_ptr", ":message_types", ":message_value", @@ -479,9 +465,8 @@ upb_amalgamation( ":mem", ":message", ":message_accessors", + ":message_compare", ":message_copy", - ":message_internal", - ":message_internal_types", ":message_tagged_ptr", ":message_types", ":message_value", diff --git a/upb/message/BUILD b/upb/message/BUILD index cfb883e24e90f..298acd918573d 100644 --- a/upb/message/BUILD +++ b/upb/message/BUILD @@ -20,44 +20,41 @@ cc_library( name = "accessors", srcs = [ "accessors.c", - "internal/accessors.h", ], hdrs = [ "accessors.h", + "internal/accessors.h", ], copts = UPB_DEFAULT_COPTS, visibility = ["//visibility:public"], deps = [ - ":internal", - ":internal_types", ":message", ":tagged_ptr", + ":types", "//upb:base", "//upb:mem", - "//upb:message_types", "//upb:mini_table", "//upb:port", - "//upb:wire", - "//upb:wire_reader", ], ) cc_library( - name = "accessors_internal", + name = "compare", + srcs = [ + "compare.c", + ], hdrs = [ - "internal/accessors.h", + "compare.h", ], copts = UPB_DEFAULT_COPTS, visibility = ["//visibility:public"], deps = [ - ":internal", - ":internal_types", ":message", - ":tagged_ptr", - "//upb:base", + ":types", "//upb:mem", "//upb:mini_table", "//upb:port", + "//upb:wire", ], ) @@ -73,8 +70,6 @@ cc_library( visibility = ["//visibility:public"], deps = [ ":accessors", - ":accessors_internal", - ":internal", ":message", ":tagged_ptr", ":types", @@ -87,31 +82,33 @@ cc_library( ) cc_library( - name = "internal", + name = "message", srcs = [ "array.c", - "array.h", + "compat.c", "internal/extension.c", "internal/message.c", "map.c", - "map.h", "map_sorter.c", "message.c", - "message.h", ], hdrs = [ + "array.h", + "compat.h", "internal/array.h", "internal/extension.h", "internal/map.h", "internal/map_entry.h", "internal/map_sorter.h", "internal/message.h", + "internal/types.h", + "map.h", "map_gencode_util.h", + "message.h", ], copts = UPB_DEFAULT_COPTS, visibility = ["//visibility:public"], deps = [ - ":internal_types", ":types", ":value", "//upb:base", @@ -124,41 +121,6 @@ cc_library( ], ) -cc_library( - name = "internal_types", - hdrs = [ - "internal/types.h", - ], - copts = UPB_DEFAULT_COPTS, - visibility = ["//visibility:public"], - deps = [ - ], -) - -cc_library( - name = "message", - srcs = [ - "compat.c", - ], - hdrs = [ - "array.h", - "compat.h", - "map.h", - "message.h", - ], - copts = UPB_DEFAULT_COPTS, - visibility = ["//visibility:public"], - deps = [ - ":internal", - ":types", - ":value", - "//upb:base", - "//upb:mem", - "//upb:mini_table", - "//upb:port", - ], -) - cc_library( name = "promote", srcs = [ @@ -171,8 +133,6 @@ cc_library( visibility = ["//visibility:public"], deps = [ ":accessors", - ":accessors_internal", - ":internal", ":message", ":tagged_ptr", ":types", @@ -302,7 +262,6 @@ cc_test( deps = [ ":accessors", ":copy", - ":internal", ":message", "//:protobuf", "@com_google_googletest//:gtest_main", @@ -335,7 +294,6 @@ cc_test( deps = [ ":accessors", ":copy", - ":internal", ":message", ":promote", ":tagged_ptr", diff --git a/upb/message/accessors.c b/upb/message/accessors.c index 0153956f12d22..2b02c82571a6c 100644 --- a/upb/message/accessors.c +++ b/upb/message/accessors.c @@ -16,7 +16,6 @@ #include "upb/mini_table/field.h" #include "upb/mini_table/message.h" #include "upb/mini_table/sub.h" -#include "upb/wire/encode.h" // Must be last. #include "upb/port/def.inc" @@ -43,27 +42,3 @@ bool upb_Message_SetMapEntry(upb_Map* map, const upb_MiniTable* mini_table, map_entry_message, map_entry_value_field, default_val); return upb_Map_Set(map, map_entry_key, map_entry_value, arena); } - -bool upb_Message_IsExactlyEqual(const upb_Message* m1, const upb_Message* m2, - const upb_MiniTable* layout) { - if (m1 == m2) return true; - - int opts = kUpb_EncodeOption_SkipUnknown | kUpb_EncodeOption_Deterministic; - upb_Arena* a = upb_Arena_New(); - - // Compare deterministically serialized payloads with no unknown fields. - size_t size1, size2; - char *data1, *data2; - upb_EncodeStatus status1 = upb_Encode(m1, layout, opts, a, &data1, &size1); - upb_EncodeStatus status2 = upb_Encode(m2, layout, opts, a, &data2, &size2); - - if (status1 != kUpb_EncodeStatus_Ok || status2 != kUpb_EncodeStatus_Ok) { - // TODO: How should we fail here? (In Ruby we throw an exception.) - upb_Arena_Free(a); - return false; - } - - const bool ret = (size1 == size2) && (memcmp(data1, data2, size1) == 0); - upb_Arena_Free(a); - return ret; -} diff --git a/upb/message/accessors.h b/upb/message/accessors.h index ecd1751cf834b..ac5788ebf8123 100644 --- a/upb/message/accessors.h +++ b/upb/message/accessors.h @@ -449,10 +449,6 @@ bool upb_Message_SetMapEntry(upb_Map* map, const upb_MiniTable* mini_table, const upb_MiniTableField* field, upb_Message* map_entry_message, upb_Arena* arena); -// Compares two messages by serializing them and calling memcmp(). -bool upb_Message_IsExactlyEqual(const upb_Message* m1, const upb_Message* m2, - const upb_MiniTable* layout); - #ifdef __cplusplus } /* extern "C" */ #endif diff --git a/upb/message/compare.c b/upb/message/compare.c new file mode 100644 index 0000000000000..5a10164b7c9c6 --- /dev/null +++ b/upb/message/compare.c @@ -0,0 +1,43 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2023 Google LLC. All rights reserved. +// +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file or at +// https://developers.google.com/open-source/licenses/bsd + +#include "upb/message/compare.h" + +#include + +#include "upb/mem/arena.h" +#include "upb/message/message.h" +#include "upb/mini_table/message.h" +#include "upb/wire/encode.h" + +// Must be last. +#include "upb/port/def.inc" + +bool upb_Message_IsExactlyEqual(const upb_Message* msg1, + const upb_Message* msg2, + const upb_MiniTable* m) { + if (msg1 == msg2) return true; + + int opts = kUpb_EncodeOption_SkipUnknown | kUpb_EncodeOption_Deterministic; + upb_Arena* a = upb_Arena_New(); + + // Compare deterministically serialized payloads with no unknown fields. + size_t size1, size2; + char *data1, *data2; + upb_EncodeStatus status1 = upb_Encode(msg1, m, opts, a, &data1, &size1); + upb_EncodeStatus status2 = upb_Encode(msg2, m, opts, a, &data2, &size2); + + if (status1 != kUpb_EncodeStatus_Ok || status2 != kUpb_EncodeStatus_Ok) { + // TODO: How should we fail here? (In Ruby we throw an exception.) + upb_Arena_Free(a); + return false; + } + + const bool ret = (size1 == size2) && (memcmp(data1, data2, size1) == 0); + upb_Arena_Free(a); + return ret; +} diff --git a/upb/message/compare.h b/upb/message/compare.h new file mode 100644 index 0000000000000..98d165c5de2e8 --- /dev/null +++ b/upb/message/compare.h @@ -0,0 +1,32 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2023 Google LLC. All rights reserved. +// +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file or at +// https://developers.google.com/open-source/licenses/bsd + +#ifndef UPB_MESSAGE_COMPARE_H_ +#define UPB_MESSAGE_COMPARE_H_ + +#include "upb/message/types.h" +#include "upb/mini_table/message.h" + +// Must be last. +#include "upb/port/def.inc" + +#ifdef __cplusplus +extern "C" { +#endif + +// Compares two messages by serializing them and calling memcmp(). +UPB_API bool upb_Message_IsExactlyEqual(const upb_Message* msg1, + const upb_Message* msg2, + const upb_MiniTable* m); + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#include "upb/port/undef.inc" + +#endif // UPB_MESSAGE_COMPARE_H_ diff --git a/upb/mini_descriptor/BUILD b/upb/mini_descriptor/BUILD index fafcf419c931e..c4247eb01840b 100644 --- a/upb/mini_descriptor/BUILD +++ b/upb/mini_descriptor/BUILD @@ -63,7 +63,7 @@ cc_test( "@com_google_googletest//:gtest_main", "//upb:base", "//upb:mem", - "//upb:message_accessors_internal", + "//upb:message_accessors", "//upb:mini_table", "//upb:port", "//upb:wire", diff --git a/upb/reflection/BUILD b/upb/reflection/BUILD index c3407c93d3156..72562999b6334 100644 --- a/upb/reflection/BUILD +++ b/upb/reflection/BUILD @@ -138,9 +138,7 @@ bootstrap_cc_library( "//upb:mem", "//upb:message", "//upb:message_accessors", - "//upb:message_accessors_internal", "//upb:message_copy", - "//upb:message_internal", "//upb:message_value", "//upb:mini_descriptor", "//upb:mini_descriptor_internal", diff --git a/upb/text/BUILD b/upb/text/BUILD index e3826c92ce3a9..7bc0953946e9f 100644 --- a/upb/text/BUILD +++ b/upb/text/BUILD @@ -21,7 +21,6 @@ cc_library( "//upb:eps_copy_input_stream", "//upb:lex", "//upb:message", - "//upb:message_internal", "//upb:port", "//upb:reflection", "//upb:wire", diff --git a/upb/upb_so.c b/upb/upb_so.c index a7bb3e7ffc812..a8769ab79d7d4 100644 --- a/upb/upb_so.c +++ b/upb/upb_so.c @@ -10,7 +10,10 @@ // IWYU pragma: begin_exports #include "upb/message/accessors_split64.h" #include "upb/message/array_split64.h" +#include "upb/message/compare.h" #include "upb/message/map.h" #include "upb/message/message.h" #include "upb/mini_descriptor/decode.h" +#include "upb/wire/decode.h" +#include "upb/wire/encode.h" // IWYU pragma: end_exports diff --git a/upb/wire/BUILD b/upb/wire/BUILD index 3e93221067a21..5130a711cd478 100644 --- a/upb/wire/BUILD +++ b/upb/wire/BUILD @@ -30,9 +30,7 @@ cc_library( "//upb:hash", "//upb:mem", "//upb:message", - "//upb:message_accessors_internal", - "//upb:message_internal", - "//upb:message_internal_types", + "//upb:message_accessors", "//upb:message_tagged_ptr", "//upb:message_types", "//upb:mini_table", From 80b5fe437b8d98661146aed3908cab1ae925de80 Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Wed, 27 Dec 2023 20:08:36 +0000 Subject: [PATCH 107/255] Auto-generate files after cl/594074354 --- php/ext/google/protobuf/php-upb.c | 1213 +++++++++++++------------ php/ext/google/protobuf/php-upb.h | 112 ++- ruby/ext/google/protobuf_c/ruby-upb.c | 1213 +++++++++++++------------ ruby/ext/google/protobuf_c/ruby-upb.h | 112 ++- upb/cmake/CMakeLists.txt | 2 - 5 files changed, 1350 insertions(+), 1302 deletions(-) diff --git a/php/ext/google/protobuf/php-upb.c b/php/ext/google/protobuf/php-upb.c index 4d866a5b33086..54ef40bdbecc7 100644 --- a/php/ext/google/protobuf/php-upb.c +++ b/php/ext/google/protobuf/php-upb.c @@ -6006,6 +6006,117 @@ void UPB_PRIVATE(_upb_Arena_SwapOut)(upb_Arena* des, const upb_Arena* src) { } +#include +#include + + +// Must be last. + +upb_Array* upb_Array_New(upb_Arena* a, upb_CType type) { + const int lg2 = UPB_PRIVATE(_upb_CType_SizeLg2)(type); + return UPB_PRIVATE(_upb_Array_New)(a, 4, lg2); +} + +const void* upb_Array_DataPtr(const upb_Array* arr) { + return _upb_array_ptr((upb_Array*)arr); +} + +void* upb_Array_MutableDataPtr(upb_Array* arr) { return _upb_array_ptr(arr); } + +size_t upb_Array_Size(const upb_Array* arr) { return arr->UPB_PRIVATE(size); } + +upb_MessageValue upb_Array_Get(const upb_Array* arr, size_t i) { + upb_MessageValue ret; + const char* data = _upb_array_constptr(arr); + const int lg2 = UPB_PRIVATE(_upb_Array_ElemSizeLg2)(arr); + UPB_ASSERT(i < arr->UPB_PRIVATE(size)); + memcpy(&ret, data + (i << lg2), 1 << lg2); + return ret; +} + +void upb_Array_Set(upb_Array* arr, size_t i, upb_MessageValue val) { + char* data = _upb_array_ptr(arr); + const int lg2 = UPB_PRIVATE(_upb_Array_ElemSizeLg2)(arr); + UPB_ASSERT(i < arr->UPB_PRIVATE(size)); + memcpy(data + (i << lg2), &val, 1 << lg2); +} + +bool upb_Array_Append(upb_Array* arr, upb_MessageValue val, upb_Arena* arena) { + UPB_ASSERT(arena); + if (!_upb_Array_ResizeUninitialized(arr, arr->UPB_PRIVATE(size) + 1, arena)) { + return false; + } + upb_Array_Set(arr, arr->UPB_PRIVATE(size) - 1, val); + return true; +} + +void upb_Array_Move(upb_Array* arr, size_t dst_idx, size_t src_idx, + size_t count) { + const int lg2 = UPB_PRIVATE(_upb_Array_ElemSizeLg2)(arr); + char* data = _upb_array_ptr(arr); + memmove(&data[dst_idx << lg2], &data[src_idx << lg2], count << lg2); +} + +bool upb_Array_Insert(upb_Array* arr, size_t i, size_t count, + upb_Arena* arena) { + UPB_ASSERT(arena); + UPB_ASSERT(i <= arr->UPB_PRIVATE(size)); + UPB_ASSERT(count + arr->UPB_PRIVATE(size) >= count); + const size_t oldsize = arr->UPB_PRIVATE(size); + if (!_upb_Array_ResizeUninitialized(arr, arr->UPB_PRIVATE(size) + count, + arena)) { + return false; + } + upb_Array_Move(arr, i + count, i, oldsize - i); + return true; +} + +/* + * i end arr->size + * |------------|XXXXXXXX|--------| + */ +void upb_Array_Delete(upb_Array* arr, size_t i, size_t count) { + const size_t end = i + count; + UPB_ASSERT(i <= end); + UPB_ASSERT(end <= arr->UPB_PRIVATE(size)); + upb_Array_Move(arr, i, end, arr->UPB_PRIVATE(size) - end); + arr->UPB_PRIVATE(size) -= count; +} + +bool upb_Array_Resize(upb_Array* arr, size_t size, upb_Arena* arena) { + const size_t oldsize = arr->UPB_PRIVATE(size); + if (UPB_UNLIKELY(!_upb_Array_ResizeUninitialized(arr, size, arena))) { + return false; + } + const size_t newsize = arr->UPB_PRIVATE(size); + if (newsize > oldsize) { + const int lg2 = UPB_PRIVATE(_upb_Array_ElemSizeLg2)(arr); + char* data = _upb_array_ptr(arr); + memset(data + (oldsize << lg2), 0, (newsize - oldsize) << lg2); + } + return true; +} + +bool UPB_PRIVATE(_upb_Array_Realloc)(upb_Array* array, size_t min_capacity, + upb_Arena* arena) { + size_t new_capacity = UPB_MAX(array->UPB_PRIVATE(capacity), 4); + const int lg2 = UPB_PRIVATE(_upb_Array_ElemSizeLg2)(array); + size_t old_bytes = array->UPB_PRIVATE(capacity) << lg2; + void* ptr = _upb_array_ptr(array); + + // Log2 ceiling of size. + while (new_capacity < min_capacity) new_capacity *= 2; + + const size_t new_bytes = new_capacity << lg2; + ptr = upb_Arena_Realloc(arena, ptr, old_bytes, new_bytes); + if (!ptr) return false; + + UPB_PRIVATE(_upb_Array_SetTaggedPtr)(array, ptr, lg2); + array->UPB_PRIVATE(capacity) = new_capacity; + return true; +} + + #include #include @@ -6039,556 +6150,96 @@ const upb_Extension* upb_Message_FindExtensionByNumber(const upb_Message* msg, // Must be last. -bool upb_Message_SetMapEntry(upb_Map* map, const upb_MiniTable* mini_table, - const upb_MiniTableField* f, - upb_Message* map_entry_message, upb_Arena* arena) { - // TODO: use a variant of upb_MiniTable_GetSubMessageTable() here. - const upb_MiniTable* map_entry_mini_table = upb_MiniTableSub_Message( - mini_table->UPB_PRIVATE(subs)[f->UPB_PRIVATE(submsg_index)]); - UPB_ASSERT(map_entry_mini_table); - UPB_ASSERT(map_entry_mini_table->UPB_PRIVATE(field_count) == 2); - const upb_MiniTableField* map_entry_key_field = - &map_entry_mini_table->UPB_PRIVATE(fields)[0]; - const upb_MiniTableField* map_entry_value_field = - &map_entry_mini_table->UPB_PRIVATE(fields)[1]; - // Map key/value cannot have explicit defaults, - // hence assuming a zero default is valid. - upb_MessageValue default_val; - memset(&default_val, 0, sizeof(upb_MessageValue)); - upb_MessageValue map_entry_key = - upb_Message_GetField(map_entry_message, map_entry_key_field, default_val); - upb_MessageValue map_entry_value = upb_Message_GetField( - map_entry_message, map_entry_value_field, default_val); - return upb_Map_Set(map, map_entry_key, map_entry_value, arena); -} - -bool upb_Message_IsExactlyEqual(const upb_Message* m1, const upb_Message* m2, - const upb_MiniTable* layout) { - if (m1 == m2) return true; +const struct upb_Extension* _upb_Message_Getext( + const upb_Message* msg, const upb_MiniTableExtension* e) { + size_t n; + const struct upb_Extension* ext = UPB_PRIVATE(_upb_Message_Getexts)(msg, &n); - int opts = kUpb_EncodeOption_SkipUnknown | kUpb_EncodeOption_Deterministic; - upb_Arena* a = upb_Arena_New(); + // For now we use linear search exclusively to find extensions. + // If this becomes an issue due to messages with lots of extensions, + // we can introduce a table of some sort. + for (size_t i = 0; i < n; i++) { + if (ext[i].ext == e) { + return &ext[i]; + } + } - // Compare deterministically serialized payloads with no unknown fields. - size_t size1, size2; - char *data1, *data2; - upb_EncodeStatus status1 = upb_Encode(m1, layout, opts, a, &data1, &size1); - upb_EncodeStatus status2 = upb_Encode(m2, layout, opts, a, &data2, &size2); + return NULL; +} - if (status1 != kUpb_EncodeStatus_Ok || status2 != kUpb_EncodeStatus_Ok) { - // TODO: How should we fail here? (In Ruby we throw an exception.) - upb_Arena_Free(a); - return false; +const struct upb_Extension* UPB_PRIVATE(_upb_Message_Getexts)( + const upb_Message* msg, size_t* count) { + const upb_Message_Internal* in = upb_Message_Getinternal(msg); + if (in->internal) { + *count = (in->internal->size - in->internal->ext_begin) / + sizeof(struct upb_Extension); + return UPB_PTR_AT(in->internal, in->internal->ext_begin, void); + } else { + *count = 0; + return NULL; } +} - const bool ret = (size1 == size2) && (memcmp(data1, data2, size1) == 0); - upb_Arena_Free(a); - return ret; +struct upb_Extension* _upb_Message_GetOrCreateExtension( + upb_Message* msg, const upb_MiniTableExtension* e, upb_Arena* arena) { + struct upb_Extension* ext = + (struct upb_Extension*)_upb_Message_Getext(msg, e); + if (ext) return ext; + if (!UPB_PRIVATE(_upb_Message_Realloc)(msg, sizeof(struct upb_Extension), + arena)) + return NULL; + upb_Message_Internal* in = upb_Message_Getinternal(msg); + in->internal->ext_begin -= sizeof(struct upb_Extension); + ext = UPB_PTR_AT(in->internal, in->internal->ext_begin, void); + memset(ext, 0, sizeof(struct upb_Extension)); + ext->ext = e; + return ext; } -#include +#include #include // Must be last. -static upb_StringView upb_Clone_StringView(upb_StringView str, - upb_Arena* arena) { - if (str.size == 0) { - return upb_StringView_FromDataAndSize(NULL, 0); +const float kUpb_FltInfinity = INFINITY; +const double kUpb_Infinity = INFINITY; +const double kUpb_NaN = NAN; + +static const size_t realloc_overhead = sizeof(upb_Message_InternalData); + +bool UPB_PRIVATE(_upb_Message_Realloc)(upb_Message* msg, size_t need, + upb_Arena* arena) { + upb_Message_Internal* in = upb_Message_Getinternal(msg); + if (!in->internal) { + // No internal data, allocate from scratch. + size_t size = UPB_MAX(128, upb_Log2CeilingSize(need + realloc_overhead)); + upb_Message_InternalData* internal = upb_Arena_Malloc(arena, size); + if (!internal) return false; + internal->size = size; + internal->unknown_end = realloc_overhead; + internal->ext_begin = size; + in->internal = internal; + } else if (in->internal->ext_begin - in->internal->unknown_end < need) { + // Internal data is too small, reallocate. + size_t new_size = upb_Log2CeilingSize(in->internal->size + need); + size_t ext_bytes = in->internal->size - in->internal->ext_begin; + size_t new_ext_begin = new_size - ext_bytes; + upb_Message_InternalData* internal = + upb_Arena_Realloc(arena, in->internal, in->internal->size, new_size); + if (!internal) return false; + if (ext_bytes) { + // Need to move extension data to the end. + char* ptr = (char*)internal; + memmove(ptr + new_ext_begin, ptr + internal->ext_begin, ext_bytes); + } + internal->ext_begin = new_ext_begin; + internal->size = new_size; + in->internal = internal; } - void* cloned_data = upb_Arena_Malloc(arena, str.size); - upb_StringView cloned_str = - upb_StringView_FromDataAndSize(cloned_data, str.size); - memcpy(cloned_data, str.data, str.size); - return cloned_str; -} - -static bool upb_Clone_MessageValue(void* value, upb_CType value_type, - const upb_MiniTable* sub, upb_Arena* arena) { - switch (value_type) { - case kUpb_CType_Bool: - case kUpb_CType_Float: - case kUpb_CType_Int32: - case kUpb_CType_UInt32: - case kUpb_CType_Enum: - case kUpb_CType_Double: - case kUpb_CType_Int64: - case kUpb_CType_UInt64: - return true; - case kUpb_CType_String: - case kUpb_CType_Bytes: { - upb_StringView source = *(upb_StringView*)value; - int size = source.size; - void* cloned_data = upb_Arena_Malloc(arena, size); - if (cloned_data == NULL) { - return false; - } - *(upb_StringView*)value = - upb_StringView_FromDataAndSize(cloned_data, size); - memcpy(cloned_data, source.data, size); - return true; - } break; - case kUpb_CType_Message: { - const upb_TaggedMessagePtr source = *(upb_TaggedMessagePtr*)value; - bool is_empty = upb_TaggedMessagePtr_IsEmpty(source); - if (is_empty) sub = UPB_PRIVATE(_upb_MiniTable_Empty)(); - UPB_ASSERT(source); - upb_Message* clone = upb_Message_DeepClone( - _upb_TaggedMessagePtr_GetMessage(source), sub, arena); - *(upb_TaggedMessagePtr*)value = - _upb_TaggedMessagePtr_Pack(clone, is_empty); - return clone != NULL; - } break; - } - UPB_UNREACHABLE(); -} - -upb_Map* upb_Map_DeepClone(const upb_Map* map, upb_CType key_type, - upb_CType value_type, - const upb_MiniTable* map_entry_table, - upb_Arena* arena) { - upb_Map* cloned_map = _upb_Map_New(arena, map->key_size, map->val_size); - if (cloned_map == NULL) { - return NULL; - } - upb_MessageValue key, val; - size_t iter = kUpb_Map_Begin; - while (upb_Map_Next(map, &key, &val, &iter)) { - const upb_MiniTableField* value_field = - &map_entry_table->UPB_PRIVATE(fields)[1]; - const upb_MiniTable* value_sub = - (value_field->UPB_PRIVATE(submsg_index) != kUpb_NoSub) - ? upb_MiniTable_GetSubMessageTable(map_entry_table, value_field) - : NULL; - upb_CType value_field_type = upb_MiniTableField_CType(value_field); - if (!upb_Clone_MessageValue(&val, value_field_type, value_sub, arena)) { - return NULL; - } - if (!upb_Map_Set(cloned_map, key, val, arena)) { - return NULL; - } - } - return cloned_map; -} - -static upb_Map* upb_Message_Map_DeepClone(const upb_Map* map, - const upb_MiniTable* mini_table, - const upb_MiniTableField* f, - upb_Message* clone, - upb_Arena* arena) { - // TODO: use a variant of upb_MiniTable_GetSubMessageTable() here. - const upb_MiniTable* map_entry_table = upb_MiniTableSub_Message( - mini_table->UPB_PRIVATE(subs)[f->UPB_PRIVATE(submsg_index)]); - UPB_ASSERT(map_entry_table); - - const upb_MiniTableField* key_field = - &map_entry_table->UPB_PRIVATE(fields)[0]; - const upb_MiniTableField* value_field = - &map_entry_table->UPB_PRIVATE(fields)[1]; - - upb_Map* cloned_map = upb_Map_DeepClone( - map, upb_MiniTableField_CType(key_field), - upb_MiniTableField_CType(value_field), map_entry_table, arena); - if (!cloned_map) { - return NULL; - } - _upb_Message_SetNonExtensionField(clone, f, &cloned_map); - return cloned_map; -} - -upb_Array* upb_Array_DeepClone(const upb_Array* array, upb_CType value_type, - const upb_MiniTable* sub, upb_Arena* arena) { - const size_t size = array->UPB_PRIVATE(size); - const int lg2 = UPB_PRIVATE(_upb_CType_SizeLg2)(value_type); - upb_Array* cloned_array = UPB_PRIVATE(_upb_Array_New)(arena, size, lg2); - if (!cloned_array) { - return NULL; - } - if (!_upb_Array_ResizeUninitialized(cloned_array, size, arena)) { - return NULL; - } - for (size_t i = 0; i < size; ++i) { - upb_MessageValue val = upb_Array_Get(array, i); - if (!upb_Clone_MessageValue(&val, value_type, sub, arena)) { - return false; - } - upb_Array_Set(cloned_array, i, val); - } - return cloned_array; -} - -static bool upb_Message_Array_DeepClone(const upb_Array* array, - const upb_MiniTable* mini_table, - const upb_MiniTableField* field, - upb_Message* clone, upb_Arena* arena) { - UPB_PRIVATE(_upb_MiniTableField_CheckIsArray)(field); - upb_Array* cloned_array = upb_Array_DeepClone( - array, upb_MiniTableField_CType(field), - upb_MiniTableField_CType(field) == kUpb_CType_Message && - field->UPB_PRIVATE(submsg_index) != kUpb_NoSub - ? upb_MiniTable_GetSubMessageTable(mini_table, field) - : NULL, - arena); - - // Clear out upb_Array* due to parent memcpy. - _upb_Message_SetNonExtensionField(clone, field, &cloned_array); - return true; -} - -static bool upb_Clone_ExtensionValue( - const upb_MiniTableExtension* mini_table_ext, const upb_Extension* source, - upb_Extension* dest, upb_Arena* arena) { - dest->data = source->data; - return upb_Clone_MessageValue( - &dest->data, - upb_MiniTableField_CType(&mini_table_ext->UPB_PRIVATE(field)), - upb_MiniTableExtension_GetSubMessage(mini_table_ext), arena); -} - -upb_Message* _upb_Message_Copy(upb_Message* dst, const upb_Message* src, - const upb_MiniTable* mini_table, - upb_Arena* arena) { - upb_StringView empty_string = upb_StringView_FromDataAndSize(NULL, 0); - // Only copy message area skipping upb_Message_Internal. - memcpy(dst, src, mini_table->UPB_PRIVATE(size)); - for (size_t i = 0; i < mini_table->UPB_PRIVATE(field_count); ++i) { - const upb_MiniTableField* field = &mini_table->UPB_PRIVATE(fields)[i]; - if (upb_MiniTableField_IsScalar(field)) { - switch (upb_MiniTableField_CType(field)) { - case kUpb_CType_Message: { - upb_TaggedMessagePtr tagged = - upb_Message_GetTaggedMessagePtr(src, field, NULL); - const upb_Message* sub_message = - _upb_TaggedMessagePtr_GetMessage(tagged); - if (sub_message != NULL) { - // If the message is currently in an unlinked, "empty" state we keep - // it that way, because we don't want to deal with decode options, - // decode status, or possible parse failure here. - bool is_empty = upb_TaggedMessagePtr_IsEmpty(tagged); - const upb_MiniTable* sub_message_table = - is_empty ? UPB_PRIVATE(_upb_MiniTable_Empty)() - : upb_MiniTable_GetSubMessageTable(mini_table, field); - upb_Message* dst_sub_message = - upb_Message_DeepClone(sub_message, sub_message_table, arena); - if (dst_sub_message == NULL) { - return NULL; - } - _upb_Message_SetTaggedMessagePtr( - dst, mini_table, field, - _upb_TaggedMessagePtr_Pack(dst_sub_message, is_empty)); - } - } break; - case kUpb_CType_String: - case kUpb_CType_Bytes: { - upb_StringView str = upb_Message_GetString(src, field, empty_string); - if (str.size != 0) { - if (!upb_Message_SetString( - dst, field, upb_Clone_StringView(str, arena), arena)) { - return NULL; - } - } - } break; - default: - // Scalar, already copied. - break; - } - } else { - if (upb_MiniTableField_IsMap(field)) { - const upb_Map* map = upb_Message_GetMap(src, field); - if (map != NULL) { - if (!upb_Message_Map_DeepClone(map, mini_table, field, dst, arena)) { - return NULL; - } - } - } else { - const upb_Array* array = upb_Message_GetArray(src, field); - if (array != NULL) { - if (!upb_Message_Array_DeepClone(array, mini_table, field, dst, - arena)) { - return NULL; - } - } - } - } - } - // Clone extensions. - size_t ext_count; - const upb_Extension* ext = UPB_PRIVATE(_upb_Message_Getexts)(src, &ext_count); - for (size_t i = 0; i < ext_count; ++i) { - const upb_Extension* msg_ext = &ext[i]; - const upb_MiniTableField* field = &msg_ext->ext->UPB_PRIVATE(field); - upb_Extension* dst_ext = - _upb_Message_GetOrCreateExtension(dst, msg_ext->ext, arena); - if (!dst_ext) return NULL; - if (upb_MiniTableField_IsScalar(field)) { - if (!upb_Clone_ExtensionValue(msg_ext->ext, msg_ext, dst_ext, arena)) { - return NULL; - } - } else { - upb_Array* msg_array = (upb_Array*)msg_ext->data.ptr; - UPB_ASSERT(msg_array); - upb_Array* cloned_array = upb_Array_DeepClone( - msg_array, upb_MiniTableField_CType(field), - upb_MiniTableExtension_GetSubMessage(msg_ext->ext), arena); - if (!cloned_array) { - return NULL; - } - dst_ext->data.ptr = (void*)cloned_array; - } - } - - // Clone unknowns. - size_t unknown_size = 0; - const char* ptr = upb_Message_GetUnknown(src, &unknown_size); - if (unknown_size != 0) { - UPB_ASSERT(ptr); - // Make a copy into destination arena. - if (!UPB_PRIVATE(_upb_Message_AddUnknown)(dst, ptr, unknown_size, arena)) { - return NULL; - } - } - return dst; -} - -bool upb_Message_DeepCopy(upb_Message* dst, const upb_Message* src, - const upb_MiniTable* mini_table, upb_Arena* arena) { - upb_Message_Clear(dst, mini_table); - return _upb_Message_Copy(dst, src, mini_table, arena) != NULL; -} - -// Deep clones a message using the provided target arena. -// -// Returns NULL on failure. -upb_Message* upb_Message_DeepClone(const upb_Message* msg, - const upb_MiniTable* m, upb_Arena* arena) { - upb_Message* clone = upb_Message_New(m, arena); - return _upb_Message_Copy(clone, msg, m, arena); -} - -// Performs a shallow copy. TODO: Extend to handle unknown fields. -void upb_Message_ShallowCopy(upb_Message* dst, const upb_Message* src, - const upb_MiniTable* m) { - memcpy(dst, src, m->UPB_PRIVATE(size)); -} - -// Performs a shallow clone. Ignores unknown fields. -upb_Message* upb_Message_ShallowClone(const upb_Message* msg, - const upb_MiniTable* m, - upb_Arena* arena) { - upb_Message* clone = upb_Message_New(m, arena); - upb_Message_ShallowCopy(clone, msg, m); - return clone; -} - - -#include -#include - - -// Must be last. - -upb_Array* upb_Array_New(upb_Arena* a, upb_CType type) { - const int lg2 = UPB_PRIVATE(_upb_CType_SizeLg2)(type); - return UPB_PRIVATE(_upb_Array_New)(a, 4, lg2); -} - -const void* upb_Array_DataPtr(const upb_Array* arr) { - return _upb_array_ptr((upb_Array*)arr); -} - -void* upb_Array_MutableDataPtr(upb_Array* arr) { return _upb_array_ptr(arr); } - -size_t upb_Array_Size(const upb_Array* arr) { return arr->UPB_PRIVATE(size); } - -upb_MessageValue upb_Array_Get(const upb_Array* arr, size_t i) { - upb_MessageValue ret; - const char* data = _upb_array_constptr(arr); - const int lg2 = UPB_PRIVATE(_upb_Array_ElemSizeLg2)(arr); - UPB_ASSERT(i < arr->UPB_PRIVATE(size)); - memcpy(&ret, data + (i << lg2), 1 << lg2); - return ret; -} - -void upb_Array_Set(upb_Array* arr, size_t i, upb_MessageValue val) { - char* data = _upb_array_ptr(arr); - const int lg2 = UPB_PRIVATE(_upb_Array_ElemSizeLg2)(arr); - UPB_ASSERT(i < arr->UPB_PRIVATE(size)); - memcpy(data + (i << lg2), &val, 1 << lg2); -} - -bool upb_Array_Append(upb_Array* arr, upb_MessageValue val, upb_Arena* arena) { - UPB_ASSERT(arena); - if (!_upb_Array_ResizeUninitialized(arr, arr->UPB_PRIVATE(size) + 1, arena)) { - return false; - } - upb_Array_Set(arr, arr->UPB_PRIVATE(size) - 1, val); - return true; -} - -void upb_Array_Move(upb_Array* arr, size_t dst_idx, size_t src_idx, - size_t count) { - const int lg2 = UPB_PRIVATE(_upb_Array_ElemSizeLg2)(arr); - char* data = _upb_array_ptr(arr); - memmove(&data[dst_idx << lg2], &data[src_idx << lg2], count << lg2); -} - -bool upb_Array_Insert(upb_Array* arr, size_t i, size_t count, - upb_Arena* arena) { - UPB_ASSERT(arena); - UPB_ASSERT(i <= arr->UPB_PRIVATE(size)); - UPB_ASSERT(count + arr->UPB_PRIVATE(size) >= count); - const size_t oldsize = arr->UPB_PRIVATE(size); - if (!_upb_Array_ResizeUninitialized(arr, arr->UPB_PRIVATE(size) + count, - arena)) { - return false; - } - upb_Array_Move(arr, i + count, i, oldsize - i); - return true; -} - -/* - * i end arr->size - * |------------|XXXXXXXX|--------| - */ -void upb_Array_Delete(upb_Array* arr, size_t i, size_t count) { - const size_t end = i + count; - UPB_ASSERT(i <= end); - UPB_ASSERT(end <= arr->UPB_PRIVATE(size)); - upb_Array_Move(arr, i, end, arr->UPB_PRIVATE(size) - end); - arr->UPB_PRIVATE(size) -= count; -} - -bool upb_Array_Resize(upb_Array* arr, size_t size, upb_Arena* arena) { - const size_t oldsize = arr->UPB_PRIVATE(size); - if (UPB_UNLIKELY(!_upb_Array_ResizeUninitialized(arr, size, arena))) { - return false; - } - const size_t newsize = arr->UPB_PRIVATE(size); - if (newsize > oldsize) { - const int lg2 = UPB_PRIVATE(_upb_Array_ElemSizeLg2)(arr); - char* data = _upb_array_ptr(arr); - memset(data + (oldsize << lg2), 0, (newsize - oldsize) << lg2); - } - return true; -} - -bool UPB_PRIVATE(_upb_Array_Realloc)(upb_Array* array, size_t min_capacity, - upb_Arena* arena) { - size_t new_capacity = UPB_MAX(array->UPB_PRIVATE(capacity), 4); - const int lg2 = UPB_PRIVATE(_upb_Array_ElemSizeLg2)(array); - size_t old_bytes = array->UPB_PRIVATE(capacity) << lg2; - void* ptr = _upb_array_ptr(array); - - // Log2 ceiling of size. - while (new_capacity < min_capacity) new_capacity *= 2; - - const size_t new_bytes = new_capacity << lg2; - ptr = upb_Arena_Realloc(arena, ptr, old_bytes, new_bytes); - if (!ptr) return false; - - UPB_PRIVATE(_upb_Array_SetTaggedPtr)(array, ptr, lg2); - array->UPB_PRIVATE(capacity) = new_capacity; - return true; -} - - -#include - - -// Must be last. - -const struct upb_Extension* _upb_Message_Getext( - const upb_Message* msg, const upb_MiniTableExtension* e) { - size_t n; - const struct upb_Extension* ext = UPB_PRIVATE(_upb_Message_Getexts)(msg, &n); - - // For now we use linear search exclusively to find extensions. - // If this becomes an issue due to messages with lots of extensions, - // we can introduce a table of some sort. - for (size_t i = 0; i < n; i++) { - if (ext[i].ext == e) { - return &ext[i]; - } - } - - return NULL; -} - -const struct upb_Extension* UPB_PRIVATE(_upb_Message_Getexts)( - const upb_Message* msg, size_t* count) { - const upb_Message_Internal* in = upb_Message_Getinternal(msg); - if (in->internal) { - *count = (in->internal->size - in->internal->ext_begin) / - sizeof(struct upb_Extension); - return UPB_PTR_AT(in->internal, in->internal->ext_begin, void); - } else { - *count = 0; - return NULL; - } -} - -struct upb_Extension* _upb_Message_GetOrCreateExtension( - upb_Message* msg, const upb_MiniTableExtension* e, upb_Arena* arena) { - struct upb_Extension* ext = - (struct upb_Extension*)_upb_Message_Getext(msg, e); - if (ext) return ext; - if (!UPB_PRIVATE(_upb_Message_Realloc)(msg, sizeof(struct upb_Extension), - arena)) - return NULL; - upb_Message_Internal* in = upb_Message_Getinternal(msg); - in->internal->ext_begin -= sizeof(struct upb_Extension); - ext = UPB_PTR_AT(in->internal, in->internal->ext_begin, void); - memset(ext, 0, sizeof(struct upb_Extension)); - ext->ext = e; - return ext; -} - - -#include -#include - - -// Must be last. - -const float kUpb_FltInfinity = INFINITY; -const double kUpb_Infinity = INFINITY; -const double kUpb_NaN = NAN; - -static const size_t realloc_overhead = sizeof(upb_Message_InternalData); - -bool UPB_PRIVATE(_upb_Message_Realloc)(upb_Message* msg, size_t need, - upb_Arena* arena) { - upb_Message_Internal* in = upb_Message_Getinternal(msg); - if (!in->internal) { - // No internal data, allocate from scratch. - size_t size = UPB_MAX(128, upb_Log2CeilingSize(need + realloc_overhead)); - upb_Message_InternalData* internal = upb_Arena_Malloc(arena, size); - if (!internal) return false; - internal->size = size; - internal->unknown_end = realloc_overhead; - internal->ext_begin = size; - in->internal = internal; - } else if (in->internal->ext_begin - in->internal->unknown_end < need) { - // Internal data is too small, reallocate. - size_t new_size = upb_Log2CeilingSize(in->internal->size + need); - size_t ext_bytes = in->internal->size - in->internal->ext_begin; - size_t new_ext_begin = new_size - ext_bytes; - upb_Message_InternalData* internal = - upb_Arena_Realloc(arena, in->internal, in->internal->size, new_size); - if (!internal) return false; - if (ext_bytes) { - // Need to move extension data to the end. - char* ptr = (char*)internal; - memmove(ptr + new_ext_begin, ptr + internal->ext_begin, ext_bytes); - } - internal->ext_begin = new_ext_begin; - internal->size = new_size; - in->internal = internal; - } - UPB_ASSERT(in->internal->ext_begin - in->internal->unknown_end >= need); - return true; + UPB_ASSERT(in->internal->ext_begin - in->internal->unknown_end >= need); + return true; } @@ -6823,91 +6474,447 @@ bool _upb_mapsorter_pushmap(_upb_mapsorter* s, upb_FieldType key_type, return true; } -static int _upb_mapsorter_cmpext(const void* _a, const void* _b) { - const upb_Extension* const* a = _a; - const upb_Extension* const* b = _b; - uint32_t a_num = upb_MiniTableExtension_Number((*a)->ext); - uint32_t b_num = upb_MiniTableExtension_Number((*b)->ext); - assert(a_num != b_num); - return a_num < b_num ? -1 : 1; -} +static int _upb_mapsorter_cmpext(const void* _a, const void* _b) { + const upb_Extension* const* a = _a; + const upb_Extension* const* b = _b; + uint32_t a_num = upb_MiniTableExtension_Number((*a)->ext); + uint32_t b_num = upb_MiniTableExtension_Number((*b)->ext); + assert(a_num != b_num); + return a_num < b_num ? -1 : 1; +} + +bool _upb_mapsorter_pushexts(_upb_mapsorter* s, const upb_Extension* exts, + size_t count, _upb_sortedmap* sorted) { + if (!_upb_mapsorter_resize(s, sorted, count)) return false; + + for (size_t i = 0; i < count; i++) { + s->entries[sorted->start + i] = &exts[i]; + } + + qsort(&s->entries[sorted->start], count, sizeof(*s->entries), + _upb_mapsorter_cmpext); + return true; +} + + +#include +#include +#include + + +// Must be last. + +static const size_t message_overhead = sizeof(upb_Message_InternalData); + +upb_Message* upb_Message_New(const upb_MiniTable* m, upb_Arena* arena) { + return _upb_Message_New(m, arena); +} + +bool UPB_PRIVATE(_upb_Message_AddUnknown)(upb_Message* msg, const char* data, + size_t len, upb_Arena* arena) { + if (!UPB_PRIVATE(_upb_Message_Realloc)(msg, len, arena)) return false; + upb_Message_Internal* in = upb_Message_Getinternal(msg); + memcpy(UPB_PTR_AT(in->internal, in->internal->unknown_end, char), data, len); + in->internal->unknown_end += len; + return true; +} + +void _upb_Message_DiscardUnknown_shallow(upb_Message* msg) { + upb_Message_Internal* in = upb_Message_Getinternal(msg); + if (in->internal) { + in->internal->unknown_end = message_overhead; + } +} + +const char* upb_Message_GetUnknown(const upb_Message* msg, size_t* len) { + const upb_Message_Internal* in = upb_Message_Getinternal(msg); + if (in->internal) { + *len = in->internal->unknown_end - message_overhead; + return (char*)(in->internal + 1); + } else { + *len = 0; + return NULL; + } +} + +void upb_Message_DeleteUnknown(upb_Message* msg, const char* data, size_t len) { + upb_Message_Internal* in = upb_Message_Getinternal(msg); + const char* internal_unknown_end = + UPB_PTR_AT(in->internal, in->internal->unknown_end, char); +#ifndef NDEBUG + size_t full_unknown_size; + const char* full_unknown = upb_Message_GetUnknown(msg, &full_unknown_size); + UPB_ASSERT((uintptr_t)data >= (uintptr_t)full_unknown); + UPB_ASSERT((uintptr_t)data < (uintptr_t)(full_unknown + full_unknown_size)); + UPB_ASSERT((uintptr_t)(data + len) > (uintptr_t)data); + UPB_ASSERT((uintptr_t)(data + len) <= (uintptr_t)internal_unknown_end); +#endif + if ((data + len) != internal_unknown_end) { + memmove((char*)data, data + len, internal_unknown_end - data - len); + } + in->internal->unknown_end -= len; +} + +size_t upb_Message_ExtensionCount(const upb_Message* msg) { + size_t count; + UPB_PRIVATE(_upb_Message_Getexts)(msg, &count); + return count; +} + + +#include + + +// Must be last. + +bool upb_Message_SetMapEntry(upb_Map* map, const upb_MiniTable* mini_table, + const upb_MiniTableField* f, + upb_Message* map_entry_message, upb_Arena* arena) { + // TODO: use a variant of upb_MiniTable_GetSubMessageTable() here. + const upb_MiniTable* map_entry_mini_table = upb_MiniTableSub_Message( + mini_table->UPB_PRIVATE(subs)[f->UPB_PRIVATE(submsg_index)]); + UPB_ASSERT(map_entry_mini_table); + UPB_ASSERT(map_entry_mini_table->UPB_PRIVATE(field_count) == 2); + const upb_MiniTableField* map_entry_key_field = + &map_entry_mini_table->UPB_PRIVATE(fields)[0]; + const upb_MiniTableField* map_entry_value_field = + &map_entry_mini_table->UPB_PRIVATE(fields)[1]; + // Map key/value cannot have explicit defaults, + // hence assuming a zero default is valid. + upb_MessageValue default_val; + memset(&default_val, 0, sizeof(upb_MessageValue)); + upb_MessageValue map_entry_key = + upb_Message_GetField(map_entry_message, map_entry_key_field, default_val); + upb_MessageValue map_entry_value = upb_Message_GetField( + map_entry_message, map_entry_value_field, default_val); + return upb_Map_Set(map, map_entry_key, map_entry_value, arena); +} + + +#include + + +// Must be last. + +bool upb_Message_IsExactlyEqual(const upb_Message* msg1, + const upb_Message* msg2, + const upb_MiniTable* m) { + if (msg1 == msg2) return true; + + int opts = kUpb_EncodeOption_SkipUnknown | kUpb_EncodeOption_Deterministic; + upb_Arena* a = upb_Arena_New(); + + // Compare deterministically serialized payloads with no unknown fields. + size_t size1, size2; + char *data1, *data2; + upb_EncodeStatus status1 = upb_Encode(msg1, m, opts, a, &data1, &size1); + upb_EncodeStatus status2 = upb_Encode(msg2, m, opts, a, &data2, &size2); + + if (status1 != kUpb_EncodeStatus_Ok || status2 != kUpb_EncodeStatus_Ok) { + // TODO: How should we fail here? (In Ruby we throw an exception.) + upb_Arena_Free(a); + return false; + } + + const bool ret = (size1 == size2) && (memcmp(data1, data2, size1) == 0); + upb_Arena_Free(a); + return ret; +} + + +#include +#include + + +// Must be last. + +static upb_StringView upb_Clone_StringView(upb_StringView str, + upb_Arena* arena) { + if (str.size == 0) { + return upb_StringView_FromDataAndSize(NULL, 0); + } + void* cloned_data = upb_Arena_Malloc(arena, str.size); + upb_StringView cloned_str = + upb_StringView_FromDataAndSize(cloned_data, str.size); + memcpy(cloned_data, str.data, str.size); + return cloned_str; +} + +static bool upb_Clone_MessageValue(void* value, upb_CType value_type, + const upb_MiniTable* sub, upb_Arena* arena) { + switch (value_type) { + case kUpb_CType_Bool: + case kUpb_CType_Float: + case kUpb_CType_Int32: + case kUpb_CType_UInt32: + case kUpb_CType_Enum: + case kUpb_CType_Double: + case kUpb_CType_Int64: + case kUpb_CType_UInt64: + return true; + case kUpb_CType_String: + case kUpb_CType_Bytes: { + upb_StringView source = *(upb_StringView*)value; + int size = source.size; + void* cloned_data = upb_Arena_Malloc(arena, size); + if (cloned_data == NULL) { + return false; + } + *(upb_StringView*)value = + upb_StringView_FromDataAndSize(cloned_data, size); + memcpy(cloned_data, source.data, size); + return true; + } break; + case kUpb_CType_Message: { + const upb_TaggedMessagePtr source = *(upb_TaggedMessagePtr*)value; + bool is_empty = upb_TaggedMessagePtr_IsEmpty(source); + if (is_empty) sub = UPB_PRIVATE(_upb_MiniTable_Empty)(); + UPB_ASSERT(source); + upb_Message* clone = upb_Message_DeepClone( + _upb_TaggedMessagePtr_GetMessage(source), sub, arena); + *(upb_TaggedMessagePtr*)value = + _upb_TaggedMessagePtr_Pack(clone, is_empty); + return clone != NULL; + } break; + } + UPB_UNREACHABLE(); +} + +upb_Map* upb_Map_DeepClone(const upb_Map* map, upb_CType key_type, + upb_CType value_type, + const upb_MiniTable* map_entry_table, + upb_Arena* arena) { + upb_Map* cloned_map = _upb_Map_New(arena, map->key_size, map->val_size); + if (cloned_map == NULL) { + return NULL; + } + upb_MessageValue key, val; + size_t iter = kUpb_Map_Begin; + while (upb_Map_Next(map, &key, &val, &iter)) { + const upb_MiniTableField* value_field = + &map_entry_table->UPB_PRIVATE(fields)[1]; + const upb_MiniTable* value_sub = + (value_field->UPB_PRIVATE(submsg_index) != kUpb_NoSub) + ? upb_MiniTable_GetSubMessageTable(map_entry_table, value_field) + : NULL; + upb_CType value_field_type = upb_MiniTableField_CType(value_field); + if (!upb_Clone_MessageValue(&val, value_field_type, value_sub, arena)) { + return NULL; + } + if (!upb_Map_Set(cloned_map, key, val, arena)) { + return NULL; + } + } + return cloned_map; +} + +static upb_Map* upb_Message_Map_DeepClone(const upb_Map* map, + const upb_MiniTable* mini_table, + const upb_MiniTableField* f, + upb_Message* clone, + upb_Arena* arena) { + // TODO: use a variant of upb_MiniTable_GetSubMessageTable() here. + const upb_MiniTable* map_entry_table = upb_MiniTableSub_Message( + mini_table->UPB_PRIVATE(subs)[f->UPB_PRIVATE(submsg_index)]); + UPB_ASSERT(map_entry_table); -bool _upb_mapsorter_pushexts(_upb_mapsorter* s, const upb_Extension* exts, - size_t count, _upb_sortedmap* sorted) { - if (!_upb_mapsorter_resize(s, sorted, count)) return false; + const upb_MiniTableField* key_field = + &map_entry_table->UPB_PRIVATE(fields)[0]; + const upb_MiniTableField* value_field = + &map_entry_table->UPB_PRIVATE(fields)[1]; - for (size_t i = 0; i < count; i++) { - s->entries[sorted->start + i] = &exts[i]; + upb_Map* cloned_map = upb_Map_DeepClone( + map, upb_MiniTableField_CType(key_field), + upb_MiniTableField_CType(value_field), map_entry_table, arena); + if (!cloned_map) { + return NULL; } - - qsort(&s->entries[sorted->start], count, sizeof(*s->entries), - _upb_mapsorter_cmpext); - return true; + _upb_Message_SetNonExtensionField(clone, f, &cloned_map); + return cloned_map; } +upb_Array* upb_Array_DeepClone(const upb_Array* array, upb_CType value_type, + const upb_MiniTable* sub, upb_Arena* arena) { + const size_t size = array->UPB_PRIVATE(size); + const int lg2 = UPB_PRIVATE(_upb_CType_SizeLg2)(value_type); + upb_Array* cloned_array = UPB_PRIVATE(_upb_Array_New)(arena, size, lg2); + if (!cloned_array) { + return NULL; + } + if (!_upb_Array_ResizeUninitialized(cloned_array, size, arena)) { + return NULL; + } + for (size_t i = 0; i < size; ++i) { + upb_MessageValue val = upb_Array_Get(array, i); + if (!upb_Clone_MessageValue(&val, value_type, sub, arena)) { + return false; + } + upb_Array_Set(cloned_array, i, val); + } + return cloned_array; +} -#include -#include -#include - - -// Must be last. - -static const size_t message_overhead = sizeof(upb_Message_InternalData); +static bool upb_Message_Array_DeepClone(const upb_Array* array, + const upb_MiniTable* mini_table, + const upb_MiniTableField* field, + upb_Message* clone, upb_Arena* arena) { + UPB_PRIVATE(_upb_MiniTableField_CheckIsArray)(field); + upb_Array* cloned_array = upb_Array_DeepClone( + array, upb_MiniTableField_CType(field), + upb_MiniTableField_CType(field) == kUpb_CType_Message && + field->UPB_PRIVATE(submsg_index) != kUpb_NoSub + ? upb_MiniTable_GetSubMessageTable(mini_table, field) + : NULL, + arena); -upb_Message* upb_Message_New(const upb_MiniTable* m, upb_Arena* arena) { - return _upb_Message_New(m, arena); + // Clear out upb_Array* due to parent memcpy. + _upb_Message_SetNonExtensionField(clone, field, &cloned_array); + return true; } -bool UPB_PRIVATE(_upb_Message_AddUnknown)(upb_Message* msg, const char* data, - size_t len, upb_Arena* arena) { - if (!UPB_PRIVATE(_upb_Message_Realloc)(msg, len, arena)) return false; - upb_Message_Internal* in = upb_Message_Getinternal(msg); - memcpy(UPB_PTR_AT(in->internal, in->internal->unknown_end, char), data, len); - in->internal->unknown_end += len; - return true; +static bool upb_Clone_ExtensionValue( + const upb_MiniTableExtension* mini_table_ext, const upb_Extension* source, + upb_Extension* dest, upb_Arena* arena) { + dest->data = source->data; + return upb_Clone_MessageValue( + &dest->data, + upb_MiniTableField_CType(&mini_table_ext->UPB_PRIVATE(field)), + upb_MiniTableExtension_GetSubMessage(mini_table_ext), arena); } -void _upb_Message_DiscardUnknown_shallow(upb_Message* msg) { - upb_Message_Internal* in = upb_Message_Getinternal(msg); - if (in->internal) { - in->internal->unknown_end = message_overhead; +upb_Message* _upb_Message_Copy(upb_Message* dst, const upb_Message* src, + const upb_MiniTable* mini_table, + upb_Arena* arena) { + upb_StringView empty_string = upb_StringView_FromDataAndSize(NULL, 0); + // Only copy message area skipping upb_Message_Internal. + memcpy(dst, src, mini_table->UPB_PRIVATE(size)); + for (size_t i = 0; i < mini_table->UPB_PRIVATE(field_count); ++i) { + const upb_MiniTableField* field = &mini_table->UPB_PRIVATE(fields)[i]; + if (upb_MiniTableField_IsScalar(field)) { + switch (upb_MiniTableField_CType(field)) { + case kUpb_CType_Message: { + upb_TaggedMessagePtr tagged = + upb_Message_GetTaggedMessagePtr(src, field, NULL); + const upb_Message* sub_message = + _upb_TaggedMessagePtr_GetMessage(tagged); + if (sub_message != NULL) { + // If the message is currently in an unlinked, "empty" state we keep + // it that way, because we don't want to deal with decode options, + // decode status, or possible parse failure here. + bool is_empty = upb_TaggedMessagePtr_IsEmpty(tagged); + const upb_MiniTable* sub_message_table = + is_empty ? UPB_PRIVATE(_upb_MiniTable_Empty)() + : upb_MiniTable_GetSubMessageTable(mini_table, field); + upb_Message* dst_sub_message = + upb_Message_DeepClone(sub_message, sub_message_table, arena); + if (dst_sub_message == NULL) { + return NULL; + } + _upb_Message_SetTaggedMessagePtr( + dst, mini_table, field, + _upb_TaggedMessagePtr_Pack(dst_sub_message, is_empty)); + } + } break; + case kUpb_CType_String: + case kUpb_CType_Bytes: { + upb_StringView str = upb_Message_GetString(src, field, empty_string); + if (str.size != 0) { + if (!upb_Message_SetString( + dst, field, upb_Clone_StringView(str, arena), arena)) { + return NULL; + } + } + } break; + default: + // Scalar, already copied. + break; + } + } else { + if (upb_MiniTableField_IsMap(field)) { + const upb_Map* map = upb_Message_GetMap(src, field); + if (map != NULL) { + if (!upb_Message_Map_DeepClone(map, mini_table, field, dst, arena)) { + return NULL; + } + } + } else { + const upb_Array* array = upb_Message_GetArray(src, field); + if (array != NULL) { + if (!upb_Message_Array_DeepClone(array, mini_table, field, dst, + arena)) { + return NULL; + } + } + } + } + } + // Clone extensions. + size_t ext_count; + const upb_Extension* ext = UPB_PRIVATE(_upb_Message_Getexts)(src, &ext_count); + for (size_t i = 0; i < ext_count; ++i) { + const upb_Extension* msg_ext = &ext[i]; + const upb_MiniTableField* field = &msg_ext->ext->UPB_PRIVATE(field); + upb_Extension* dst_ext = + _upb_Message_GetOrCreateExtension(dst, msg_ext->ext, arena); + if (!dst_ext) return NULL; + if (upb_MiniTableField_IsScalar(field)) { + if (!upb_Clone_ExtensionValue(msg_ext->ext, msg_ext, dst_ext, arena)) { + return NULL; + } + } else { + upb_Array* msg_array = (upb_Array*)msg_ext->data.ptr; + UPB_ASSERT(msg_array); + upb_Array* cloned_array = upb_Array_DeepClone( + msg_array, upb_MiniTableField_CType(field), + upb_MiniTableExtension_GetSubMessage(msg_ext->ext), arena); + if (!cloned_array) { + return NULL; + } + dst_ext->data.ptr = (void*)cloned_array; + } } -} -const char* upb_Message_GetUnknown(const upb_Message* msg, size_t* len) { - const upb_Message_Internal* in = upb_Message_Getinternal(msg); - if (in->internal) { - *len = in->internal->unknown_end - message_overhead; - return (char*)(in->internal + 1); - } else { - *len = 0; - return NULL; + // Clone unknowns. + size_t unknown_size = 0; + const char* ptr = upb_Message_GetUnknown(src, &unknown_size); + if (unknown_size != 0) { + UPB_ASSERT(ptr); + // Make a copy into destination arena. + if (!UPB_PRIVATE(_upb_Message_AddUnknown)(dst, ptr, unknown_size, arena)) { + return NULL; + } } + return dst; } -void upb_Message_DeleteUnknown(upb_Message* msg, const char* data, size_t len) { - upb_Message_Internal* in = upb_Message_Getinternal(msg); - const char* internal_unknown_end = - UPB_PTR_AT(in->internal, in->internal->unknown_end, char); -#ifndef NDEBUG - size_t full_unknown_size; - const char* full_unknown = upb_Message_GetUnknown(msg, &full_unknown_size); - UPB_ASSERT((uintptr_t)data >= (uintptr_t)full_unknown); - UPB_ASSERT((uintptr_t)data < (uintptr_t)(full_unknown + full_unknown_size)); - UPB_ASSERT((uintptr_t)(data + len) > (uintptr_t)data); - UPB_ASSERT((uintptr_t)(data + len) <= (uintptr_t)internal_unknown_end); -#endif - if ((data + len) != internal_unknown_end) { - memmove((char*)data, data + len, internal_unknown_end - data - len); - } - in->internal->unknown_end -= len; +bool upb_Message_DeepCopy(upb_Message* dst, const upb_Message* src, + const upb_MiniTable* mini_table, upb_Arena* arena) { + upb_Message_Clear(dst, mini_table); + return _upb_Message_Copy(dst, src, mini_table, arena) != NULL; } -size_t upb_Message_ExtensionCount(const upb_Message* msg) { - size_t count; - UPB_PRIVATE(_upb_Message_Getexts)(msg, &count); - return count; +// Deep clones a message using the provided target arena. +// +// Returns NULL on failure. +upb_Message* upb_Message_DeepClone(const upb_Message* msg, + const upb_MiniTable* m, upb_Arena* arena) { + upb_Message* clone = upb_Message_New(m, arena); + return _upb_Message_Copy(clone, msg, m, arena); +} + +// Performs a shallow copy. TODO: Extend to handle unknown fields. +void upb_Message_ShallowCopy(upb_Message* dst, const upb_Message* src, + const upb_MiniTable* m) { + memcpy(dst, src, m->UPB_PRIVATE(size)); +} + +// Performs a shallow clone. Ignores unknown fields. +upb_Message* upb_Message_ShallowClone(const upb_Message* msg, + const upb_MiniTable* m, + upb_Arena* arena) { + upb_Message* clone = upb_Message_New(m, arena); + upb_Message_ShallowCopy(clone, msg, m); + return clone; } diff --git a/php/ext/google/protobuf/php-upb.h b/php/ext/google/protobuf/php-upb.h index 6dd35f57d4de8..153345b4ff4ea 100644 --- a/php/ext/google/protobuf/php-upb.h +++ b/php/ext/google/protobuf/php-upb.h @@ -3448,10 +3448,6 @@ bool upb_Message_SetMapEntry(upb_Map* map, const upb_MiniTable* mini_table, const upb_MiniTableField* field, upb_Message* map_entry_message, upb_Arena* arena); -// Compares two messages by serializing them and calling memcmp(). -bool upb_Message_IsExactlyEqual(const upb_Message* m1, const upb_Message* m2, - const upb_MiniTable* layout); - #ifdef __cplusplus } /* extern "C" */ #endif @@ -12563,49 +12559,6 @@ const upb_Extension* upb_Message_FindExtensionByNumber(const upb_Message* msg, #endif /* UPB_MESSAGE_COMPAT_H_ */ -#ifndef UPB_MESSAGE_COPY_H_ -#define UPB_MESSAGE_COPY_H_ - - -// Must be last. - -#ifdef __cplusplus -extern "C" { -#endif - -// Deep clones a message using the provided target arena. -upb_Message* upb_Message_DeepClone(const upb_Message* msg, - const upb_MiniTable* m, upb_Arena* arena); - -// Shallow clones a message using the provided target arena. -upb_Message* upb_Message_ShallowClone(const upb_Message* msg, - const upb_MiniTable* m, upb_Arena* arena); - -// Deep clones array contents. -upb_Array* upb_Array_DeepClone(const upb_Array* array, upb_CType value_type, - const upb_MiniTable* sub, upb_Arena* arena); - -// Deep clones map contents. -upb_Map* upb_Map_DeepClone(const upb_Map* map, upb_CType key_type, - upb_CType value_type, - const upb_MiniTable* map_entry_table, - upb_Arena* arena); - -// Deep copies the message from src to dst. -bool upb_Message_DeepCopy(upb_Message* dst, const upb_Message* src, - const upb_MiniTable* m, upb_Arena* arena); - -// Shallow copies the message from src to dst. -void upb_Message_ShallowCopy(upb_Message* dst, const upb_Message* src, - const upb_MiniTable* m); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - - -#endif // UPB_MESSAGE_COPY_H_ - // EVERYTHING BELOW THIS LINE IS INTERNAL - DO NOT USE ///////////////////////// #ifndef UPB_MESSAGE_INTERNAL_MAP_SORTER_H_ @@ -12719,6 +12672,71 @@ bool _upb_mapsorter_pushexts(_upb_mapsorter* s, const upb_Extension* exts, #endif /* UPB_MESSAGE_INTERNAL_MAP_SORTER_H_ */ +#ifndef UPB_MESSAGE_COMPARE_H_ +#define UPB_MESSAGE_COMPARE_H_ + + +// Must be last. + +#ifdef __cplusplus +extern "C" { +#endif + +// Compares two messages by serializing them and calling memcmp(). +UPB_API bool upb_Message_IsExactlyEqual(const upb_Message* msg1, + const upb_Message* msg2, + const upb_MiniTable* m); + +#ifdef __cplusplus +} /* extern "C" */ +#endif + + +#endif // UPB_MESSAGE_COMPARE_H_ + +#ifndef UPB_MESSAGE_COPY_H_ +#define UPB_MESSAGE_COPY_H_ + + +// Must be last. + +#ifdef __cplusplus +extern "C" { +#endif + +// Deep clones a message using the provided target arena. +upb_Message* upb_Message_DeepClone(const upb_Message* msg, + const upb_MiniTable* m, upb_Arena* arena); + +// Shallow clones a message using the provided target arena. +upb_Message* upb_Message_ShallowClone(const upb_Message* msg, + const upb_MiniTable* m, upb_Arena* arena); + +// Deep clones array contents. +upb_Array* upb_Array_DeepClone(const upb_Array* array, upb_CType value_type, + const upb_MiniTable* sub, upb_Arena* arena); + +// Deep clones map contents. +upb_Map* upb_Map_DeepClone(const upb_Map* map, upb_CType key_type, + upb_CType value_type, + const upb_MiniTable* map_entry_table, + upb_Arena* arena); + +// Deep copies the message from src to dst. +bool upb_Message_DeepCopy(upb_Message* dst, const upb_Message* src, + const upb_MiniTable* m, upb_Arena* arena); + +// Shallow copies the message from src to dst. +void upb_Message_ShallowCopy(upb_Message* dst, const upb_Message* src, + const upb_MiniTable* m); + +#ifdef __cplusplus +} /* extern "C" */ +#endif + + +#endif // UPB_MESSAGE_COPY_H_ + #ifndef UPB_MINI_DESCRIPTOR_INTERNAL_BASE92_H_ #define UPB_MINI_DESCRIPTOR_INTERNAL_BASE92_H_ diff --git a/ruby/ext/google/protobuf_c/ruby-upb.c b/ruby/ext/google/protobuf_c/ruby-upb.c index 07f17c3ff6245..a6c49cbdcc81b 100644 --- a/ruby/ext/google/protobuf_c/ruby-upb.c +++ b/ruby/ext/google/protobuf_c/ruby-upb.c @@ -5522,6 +5522,117 @@ void UPB_PRIVATE(_upb_Arena_SwapOut)(upb_Arena* des, const upb_Arena* src) { } +#include +#include + + +// Must be last. + +upb_Array* upb_Array_New(upb_Arena* a, upb_CType type) { + const int lg2 = UPB_PRIVATE(_upb_CType_SizeLg2)(type); + return UPB_PRIVATE(_upb_Array_New)(a, 4, lg2); +} + +const void* upb_Array_DataPtr(const upb_Array* arr) { + return _upb_array_ptr((upb_Array*)arr); +} + +void* upb_Array_MutableDataPtr(upb_Array* arr) { return _upb_array_ptr(arr); } + +size_t upb_Array_Size(const upb_Array* arr) { return arr->UPB_PRIVATE(size); } + +upb_MessageValue upb_Array_Get(const upb_Array* arr, size_t i) { + upb_MessageValue ret; + const char* data = _upb_array_constptr(arr); + const int lg2 = UPB_PRIVATE(_upb_Array_ElemSizeLg2)(arr); + UPB_ASSERT(i < arr->UPB_PRIVATE(size)); + memcpy(&ret, data + (i << lg2), 1 << lg2); + return ret; +} + +void upb_Array_Set(upb_Array* arr, size_t i, upb_MessageValue val) { + char* data = _upb_array_ptr(arr); + const int lg2 = UPB_PRIVATE(_upb_Array_ElemSizeLg2)(arr); + UPB_ASSERT(i < arr->UPB_PRIVATE(size)); + memcpy(data + (i << lg2), &val, 1 << lg2); +} + +bool upb_Array_Append(upb_Array* arr, upb_MessageValue val, upb_Arena* arena) { + UPB_ASSERT(arena); + if (!_upb_Array_ResizeUninitialized(arr, arr->UPB_PRIVATE(size) + 1, arena)) { + return false; + } + upb_Array_Set(arr, arr->UPB_PRIVATE(size) - 1, val); + return true; +} + +void upb_Array_Move(upb_Array* arr, size_t dst_idx, size_t src_idx, + size_t count) { + const int lg2 = UPB_PRIVATE(_upb_Array_ElemSizeLg2)(arr); + char* data = _upb_array_ptr(arr); + memmove(&data[dst_idx << lg2], &data[src_idx << lg2], count << lg2); +} + +bool upb_Array_Insert(upb_Array* arr, size_t i, size_t count, + upb_Arena* arena) { + UPB_ASSERT(arena); + UPB_ASSERT(i <= arr->UPB_PRIVATE(size)); + UPB_ASSERT(count + arr->UPB_PRIVATE(size) >= count); + const size_t oldsize = arr->UPB_PRIVATE(size); + if (!_upb_Array_ResizeUninitialized(arr, arr->UPB_PRIVATE(size) + count, + arena)) { + return false; + } + upb_Array_Move(arr, i + count, i, oldsize - i); + return true; +} + +/* + * i end arr->size + * |------------|XXXXXXXX|--------| + */ +void upb_Array_Delete(upb_Array* arr, size_t i, size_t count) { + const size_t end = i + count; + UPB_ASSERT(i <= end); + UPB_ASSERT(end <= arr->UPB_PRIVATE(size)); + upb_Array_Move(arr, i, end, arr->UPB_PRIVATE(size) - end); + arr->UPB_PRIVATE(size) -= count; +} + +bool upb_Array_Resize(upb_Array* arr, size_t size, upb_Arena* arena) { + const size_t oldsize = arr->UPB_PRIVATE(size); + if (UPB_UNLIKELY(!_upb_Array_ResizeUninitialized(arr, size, arena))) { + return false; + } + const size_t newsize = arr->UPB_PRIVATE(size); + if (newsize > oldsize) { + const int lg2 = UPB_PRIVATE(_upb_Array_ElemSizeLg2)(arr); + char* data = _upb_array_ptr(arr); + memset(data + (oldsize << lg2), 0, (newsize - oldsize) << lg2); + } + return true; +} + +bool UPB_PRIVATE(_upb_Array_Realloc)(upb_Array* array, size_t min_capacity, + upb_Arena* arena) { + size_t new_capacity = UPB_MAX(array->UPB_PRIVATE(capacity), 4); + const int lg2 = UPB_PRIVATE(_upb_Array_ElemSizeLg2)(array); + size_t old_bytes = array->UPB_PRIVATE(capacity) << lg2; + void* ptr = _upb_array_ptr(array); + + // Log2 ceiling of size. + while (new_capacity < min_capacity) new_capacity *= 2; + + const size_t new_bytes = new_capacity << lg2; + ptr = upb_Arena_Realloc(arena, ptr, old_bytes, new_bytes); + if (!ptr) return false; + + UPB_PRIVATE(_upb_Array_SetTaggedPtr)(array, ptr, lg2); + array->UPB_PRIVATE(capacity) = new_capacity; + return true; +} + + #include #include @@ -5555,556 +5666,96 @@ const upb_Extension* upb_Message_FindExtensionByNumber(const upb_Message* msg, // Must be last. -bool upb_Message_SetMapEntry(upb_Map* map, const upb_MiniTable* mini_table, - const upb_MiniTableField* f, - upb_Message* map_entry_message, upb_Arena* arena) { - // TODO: use a variant of upb_MiniTable_GetSubMessageTable() here. - const upb_MiniTable* map_entry_mini_table = upb_MiniTableSub_Message( - mini_table->UPB_PRIVATE(subs)[f->UPB_PRIVATE(submsg_index)]); - UPB_ASSERT(map_entry_mini_table); - UPB_ASSERT(map_entry_mini_table->UPB_PRIVATE(field_count) == 2); - const upb_MiniTableField* map_entry_key_field = - &map_entry_mini_table->UPB_PRIVATE(fields)[0]; - const upb_MiniTableField* map_entry_value_field = - &map_entry_mini_table->UPB_PRIVATE(fields)[1]; - // Map key/value cannot have explicit defaults, - // hence assuming a zero default is valid. - upb_MessageValue default_val; - memset(&default_val, 0, sizeof(upb_MessageValue)); - upb_MessageValue map_entry_key = - upb_Message_GetField(map_entry_message, map_entry_key_field, default_val); - upb_MessageValue map_entry_value = upb_Message_GetField( - map_entry_message, map_entry_value_field, default_val); - return upb_Map_Set(map, map_entry_key, map_entry_value, arena); -} - -bool upb_Message_IsExactlyEqual(const upb_Message* m1, const upb_Message* m2, - const upb_MiniTable* layout) { - if (m1 == m2) return true; +const struct upb_Extension* _upb_Message_Getext( + const upb_Message* msg, const upb_MiniTableExtension* e) { + size_t n; + const struct upb_Extension* ext = UPB_PRIVATE(_upb_Message_Getexts)(msg, &n); - int opts = kUpb_EncodeOption_SkipUnknown | kUpb_EncodeOption_Deterministic; - upb_Arena* a = upb_Arena_New(); + // For now we use linear search exclusively to find extensions. + // If this becomes an issue due to messages with lots of extensions, + // we can introduce a table of some sort. + for (size_t i = 0; i < n; i++) { + if (ext[i].ext == e) { + return &ext[i]; + } + } - // Compare deterministically serialized payloads with no unknown fields. - size_t size1, size2; - char *data1, *data2; - upb_EncodeStatus status1 = upb_Encode(m1, layout, opts, a, &data1, &size1); - upb_EncodeStatus status2 = upb_Encode(m2, layout, opts, a, &data2, &size2); + return NULL; +} - if (status1 != kUpb_EncodeStatus_Ok || status2 != kUpb_EncodeStatus_Ok) { - // TODO: How should we fail here? (In Ruby we throw an exception.) - upb_Arena_Free(a); - return false; +const struct upb_Extension* UPB_PRIVATE(_upb_Message_Getexts)( + const upb_Message* msg, size_t* count) { + const upb_Message_Internal* in = upb_Message_Getinternal(msg); + if (in->internal) { + *count = (in->internal->size - in->internal->ext_begin) / + sizeof(struct upb_Extension); + return UPB_PTR_AT(in->internal, in->internal->ext_begin, void); + } else { + *count = 0; + return NULL; } +} - const bool ret = (size1 == size2) && (memcmp(data1, data2, size1) == 0); - upb_Arena_Free(a); - return ret; +struct upb_Extension* _upb_Message_GetOrCreateExtension( + upb_Message* msg, const upb_MiniTableExtension* e, upb_Arena* arena) { + struct upb_Extension* ext = + (struct upb_Extension*)_upb_Message_Getext(msg, e); + if (ext) return ext; + if (!UPB_PRIVATE(_upb_Message_Realloc)(msg, sizeof(struct upb_Extension), + arena)) + return NULL; + upb_Message_Internal* in = upb_Message_Getinternal(msg); + in->internal->ext_begin -= sizeof(struct upb_Extension); + ext = UPB_PTR_AT(in->internal, in->internal->ext_begin, void); + memset(ext, 0, sizeof(struct upb_Extension)); + ext->ext = e; + return ext; } -#include +#include #include // Must be last. -static upb_StringView upb_Clone_StringView(upb_StringView str, - upb_Arena* arena) { - if (str.size == 0) { - return upb_StringView_FromDataAndSize(NULL, 0); +const float kUpb_FltInfinity = INFINITY; +const double kUpb_Infinity = INFINITY; +const double kUpb_NaN = NAN; + +static const size_t realloc_overhead = sizeof(upb_Message_InternalData); + +bool UPB_PRIVATE(_upb_Message_Realloc)(upb_Message* msg, size_t need, + upb_Arena* arena) { + upb_Message_Internal* in = upb_Message_Getinternal(msg); + if (!in->internal) { + // No internal data, allocate from scratch. + size_t size = UPB_MAX(128, upb_Log2CeilingSize(need + realloc_overhead)); + upb_Message_InternalData* internal = upb_Arena_Malloc(arena, size); + if (!internal) return false; + internal->size = size; + internal->unknown_end = realloc_overhead; + internal->ext_begin = size; + in->internal = internal; + } else if (in->internal->ext_begin - in->internal->unknown_end < need) { + // Internal data is too small, reallocate. + size_t new_size = upb_Log2CeilingSize(in->internal->size + need); + size_t ext_bytes = in->internal->size - in->internal->ext_begin; + size_t new_ext_begin = new_size - ext_bytes; + upb_Message_InternalData* internal = + upb_Arena_Realloc(arena, in->internal, in->internal->size, new_size); + if (!internal) return false; + if (ext_bytes) { + // Need to move extension data to the end. + char* ptr = (char*)internal; + memmove(ptr + new_ext_begin, ptr + internal->ext_begin, ext_bytes); + } + internal->ext_begin = new_ext_begin; + internal->size = new_size; + in->internal = internal; } - void* cloned_data = upb_Arena_Malloc(arena, str.size); - upb_StringView cloned_str = - upb_StringView_FromDataAndSize(cloned_data, str.size); - memcpy(cloned_data, str.data, str.size); - return cloned_str; -} - -static bool upb_Clone_MessageValue(void* value, upb_CType value_type, - const upb_MiniTable* sub, upb_Arena* arena) { - switch (value_type) { - case kUpb_CType_Bool: - case kUpb_CType_Float: - case kUpb_CType_Int32: - case kUpb_CType_UInt32: - case kUpb_CType_Enum: - case kUpb_CType_Double: - case kUpb_CType_Int64: - case kUpb_CType_UInt64: - return true; - case kUpb_CType_String: - case kUpb_CType_Bytes: { - upb_StringView source = *(upb_StringView*)value; - int size = source.size; - void* cloned_data = upb_Arena_Malloc(arena, size); - if (cloned_data == NULL) { - return false; - } - *(upb_StringView*)value = - upb_StringView_FromDataAndSize(cloned_data, size); - memcpy(cloned_data, source.data, size); - return true; - } break; - case kUpb_CType_Message: { - const upb_TaggedMessagePtr source = *(upb_TaggedMessagePtr*)value; - bool is_empty = upb_TaggedMessagePtr_IsEmpty(source); - if (is_empty) sub = UPB_PRIVATE(_upb_MiniTable_Empty)(); - UPB_ASSERT(source); - upb_Message* clone = upb_Message_DeepClone( - _upb_TaggedMessagePtr_GetMessage(source), sub, arena); - *(upb_TaggedMessagePtr*)value = - _upb_TaggedMessagePtr_Pack(clone, is_empty); - return clone != NULL; - } break; - } - UPB_UNREACHABLE(); -} - -upb_Map* upb_Map_DeepClone(const upb_Map* map, upb_CType key_type, - upb_CType value_type, - const upb_MiniTable* map_entry_table, - upb_Arena* arena) { - upb_Map* cloned_map = _upb_Map_New(arena, map->key_size, map->val_size); - if (cloned_map == NULL) { - return NULL; - } - upb_MessageValue key, val; - size_t iter = kUpb_Map_Begin; - while (upb_Map_Next(map, &key, &val, &iter)) { - const upb_MiniTableField* value_field = - &map_entry_table->UPB_PRIVATE(fields)[1]; - const upb_MiniTable* value_sub = - (value_field->UPB_PRIVATE(submsg_index) != kUpb_NoSub) - ? upb_MiniTable_GetSubMessageTable(map_entry_table, value_field) - : NULL; - upb_CType value_field_type = upb_MiniTableField_CType(value_field); - if (!upb_Clone_MessageValue(&val, value_field_type, value_sub, arena)) { - return NULL; - } - if (!upb_Map_Set(cloned_map, key, val, arena)) { - return NULL; - } - } - return cloned_map; -} - -static upb_Map* upb_Message_Map_DeepClone(const upb_Map* map, - const upb_MiniTable* mini_table, - const upb_MiniTableField* f, - upb_Message* clone, - upb_Arena* arena) { - // TODO: use a variant of upb_MiniTable_GetSubMessageTable() here. - const upb_MiniTable* map_entry_table = upb_MiniTableSub_Message( - mini_table->UPB_PRIVATE(subs)[f->UPB_PRIVATE(submsg_index)]); - UPB_ASSERT(map_entry_table); - - const upb_MiniTableField* key_field = - &map_entry_table->UPB_PRIVATE(fields)[0]; - const upb_MiniTableField* value_field = - &map_entry_table->UPB_PRIVATE(fields)[1]; - - upb_Map* cloned_map = upb_Map_DeepClone( - map, upb_MiniTableField_CType(key_field), - upb_MiniTableField_CType(value_field), map_entry_table, arena); - if (!cloned_map) { - return NULL; - } - _upb_Message_SetNonExtensionField(clone, f, &cloned_map); - return cloned_map; -} - -upb_Array* upb_Array_DeepClone(const upb_Array* array, upb_CType value_type, - const upb_MiniTable* sub, upb_Arena* arena) { - const size_t size = array->UPB_PRIVATE(size); - const int lg2 = UPB_PRIVATE(_upb_CType_SizeLg2)(value_type); - upb_Array* cloned_array = UPB_PRIVATE(_upb_Array_New)(arena, size, lg2); - if (!cloned_array) { - return NULL; - } - if (!_upb_Array_ResizeUninitialized(cloned_array, size, arena)) { - return NULL; - } - for (size_t i = 0; i < size; ++i) { - upb_MessageValue val = upb_Array_Get(array, i); - if (!upb_Clone_MessageValue(&val, value_type, sub, arena)) { - return false; - } - upb_Array_Set(cloned_array, i, val); - } - return cloned_array; -} - -static bool upb_Message_Array_DeepClone(const upb_Array* array, - const upb_MiniTable* mini_table, - const upb_MiniTableField* field, - upb_Message* clone, upb_Arena* arena) { - UPB_PRIVATE(_upb_MiniTableField_CheckIsArray)(field); - upb_Array* cloned_array = upb_Array_DeepClone( - array, upb_MiniTableField_CType(field), - upb_MiniTableField_CType(field) == kUpb_CType_Message && - field->UPB_PRIVATE(submsg_index) != kUpb_NoSub - ? upb_MiniTable_GetSubMessageTable(mini_table, field) - : NULL, - arena); - - // Clear out upb_Array* due to parent memcpy. - _upb_Message_SetNonExtensionField(clone, field, &cloned_array); - return true; -} - -static bool upb_Clone_ExtensionValue( - const upb_MiniTableExtension* mini_table_ext, const upb_Extension* source, - upb_Extension* dest, upb_Arena* arena) { - dest->data = source->data; - return upb_Clone_MessageValue( - &dest->data, - upb_MiniTableField_CType(&mini_table_ext->UPB_PRIVATE(field)), - upb_MiniTableExtension_GetSubMessage(mini_table_ext), arena); -} - -upb_Message* _upb_Message_Copy(upb_Message* dst, const upb_Message* src, - const upb_MiniTable* mini_table, - upb_Arena* arena) { - upb_StringView empty_string = upb_StringView_FromDataAndSize(NULL, 0); - // Only copy message area skipping upb_Message_Internal. - memcpy(dst, src, mini_table->UPB_PRIVATE(size)); - for (size_t i = 0; i < mini_table->UPB_PRIVATE(field_count); ++i) { - const upb_MiniTableField* field = &mini_table->UPB_PRIVATE(fields)[i]; - if (upb_MiniTableField_IsScalar(field)) { - switch (upb_MiniTableField_CType(field)) { - case kUpb_CType_Message: { - upb_TaggedMessagePtr tagged = - upb_Message_GetTaggedMessagePtr(src, field, NULL); - const upb_Message* sub_message = - _upb_TaggedMessagePtr_GetMessage(tagged); - if (sub_message != NULL) { - // If the message is currently in an unlinked, "empty" state we keep - // it that way, because we don't want to deal with decode options, - // decode status, or possible parse failure here. - bool is_empty = upb_TaggedMessagePtr_IsEmpty(tagged); - const upb_MiniTable* sub_message_table = - is_empty ? UPB_PRIVATE(_upb_MiniTable_Empty)() - : upb_MiniTable_GetSubMessageTable(mini_table, field); - upb_Message* dst_sub_message = - upb_Message_DeepClone(sub_message, sub_message_table, arena); - if (dst_sub_message == NULL) { - return NULL; - } - _upb_Message_SetTaggedMessagePtr( - dst, mini_table, field, - _upb_TaggedMessagePtr_Pack(dst_sub_message, is_empty)); - } - } break; - case kUpb_CType_String: - case kUpb_CType_Bytes: { - upb_StringView str = upb_Message_GetString(src, field, empty_string); - if (str.size != 0) { - if (!upb_Message_SetString( - dst, field, upb_Clone_StringView(str, arena), arena)) { - return NULL; - } - } - } break; - default: - // Scalar, already copied. - break; - } - } else { - if (upb_MiniTableField_IsMap(field)) { - const upb_Map* map = upb_Message_GetMap(src, field); - if (map != NULL) { - if (!upb_Message_Map_DeepClone(map, mini_table, field, dst, arena)) { - return NULL; - } - } - } else { - const upb_Array* array = upb_Message_GetArray(src, field); - if (array != NULL) { - if (!upb_Message_Array_DeepClone(array, mini_table, field, dst, - arena)) { - return NULL; - } - } - } - } - } - // Clone extensions. - size_t ext_count; - const upb_Extension* ext = UPB_PRIVATE(_upb_Message_Getexts)(src, &ext_count); - for (size_t i = 0; i < ext_count; ++i) { - const upb_Extension* msg_ext = &ext[i]; - const upb_MiniTableField* field = &msg_ext->ext->UPB_PRIVATE(field); - upb_Extension* dst_ext = - _upb_Message_GetOrCreateExtension(dst, msg_ext->ext, arena); - if (!dst_ext) return NULL; - if (upb_MiniTableField_IsScalar(field)) { - if (!upb_Clone_ExtensionValue(msg_ext->ext, msg_ext, dst_ext, arena)) { - return NULL; - } - } else { - upb_Array* msg_array = (upb_Array*)msg_ext->data.ptr; - UPB_ASSERT(msg_array); - upb_Array* cloned_array = upb_Array_DeepClone( - msg_array, upb_MiniTableField_CType(field), - upb_MiniTableExtension_GetSubMessage(msg_ext->ext), arena); - if (!cloned_array) { - return NULL; - } - dst_ext->data.ptr = (void*)cloned_array; - } - } - - // Clone unknowns. - size_t unknown_size = 0; - const char* ptr = upb_Message_GetUnknown(src, &unknown_size); - if (unknown_size != 0) { - UPB_ASSERT(ptr); - // Make a copy into destination arena. - if (!UPB_PRIVATE(_upb_Message_AddUnknown)(dst, ptr, unknown_size, arena)) { - return NULL; - } - } - return dst; -} - -bool upb_Message_DeepCopy(upb_Message* dst, const upb_Message* src, - const upb_MiniTable* mini_table, upb_Arena* arena) { - upb_Message_Clear(dst, mini_table); - return _upb_Message_Copy(dst, src, mini_table, arena) != NULL; -} - -// Deep clones a message using the provided target arena. -// -// Returns NULL on failure. -upb_Message* upb_Message_DeepClone(const upb_Message* msg, - const upb_MiniTable* m, upb_Arena* arena) { - upb_Message* clone = upb_Message_New(m, arena); - return _upb_Message_Copy(clone, msg, m, arena); -} - -// Performs a shallow copy. TODO: Extend to handle unknown fields. -void upb_Message_ShallowCopy(upb_Message* dst, const upb_Message* src, - const upb_MiniTable* m) { - memcpy(dst, src, m->UPB_PRIVATE(size)); -} - -// Performs a shallow clone. Ignores unknown fields. -upb_Message* upb_Message_ShallowClone(const upb_Message* msg, - const upb_MiniTable* m, - upb_Arena* arena) { - upb_Message* clone = upb_Message_New(m, arena); - upb_Message_ShallowCopy(clone, msg, m); - return clone; -} - - -#include -#include - - -// Must be last. - -upb_Array* upb_Array_New(upb_Arena* a, upb_CType type) { - const int lg2 = UPB_PRIVATE(_upb_CType_SizeLg2)(type); - return UPB_PRIVATE(_upb_Array_New)(a, 4, lg2); -} - -const void* upb_Array_DataPtr(const upb_Array* arr) { - return _upb_array_ptr((upb_Array*)arr); -} - -void* upb_Array_MutableDataPtr(upb_Array* arr) { return _upb_array_ptr(arr); } - -size_t upb_Array_Size(const upb_Array* arr) { return arr->UPB_PRIVATE(size); } - -upb_MessageValue upb_Array_Get(const upb_Array* arr, size_t i) { - upb_MessageValue ret; - const char* data = _upb_array_constptr(arr); - const int lg2 = UPB_PRIVATE(_upb_Array_ElemSizeLg2)(arr); - UPB_ASSERT(i < arr->UPB_PRIVATE(size)); - memcpy(&ret, data + (i << lg2), 1 << lg2); - return ret; -} - -void upb_Array_Set(upb_Array* arr, size_t i, upb_MessageValue val) { - char* data = _upb_array_ptr(arr); - const int lg2 = UPB_PRIVATE(_upb_Array_ElemSizeLg2)(arr); - UPB_ASSERT(i < arr->UPB_PRIVATE(size)); - memcpy(data + (i << lg2), &val, 1 << lg2); -} - -bool upb_Array_Append(upb_Array* arr, upb_MessageValue val, upb_Arena* arena) { - UPB_ASSERT(arena); - if (!_upb_Array_ResizeUninitialized(arr, arr->UPB_PRIVATE(size) + 1, arena)) { - return false; - } - upb_Array_Set(arr, arr->UPB_PRIVATE(size) - 1, val); - return true; -} - -void upb_Array_Move(upb_Array* arr, size_t dst_idx, size_t src_idx, - size_t count) { - const int lg2 = UPB_PRIVATE(_upb_Array_ElemSizeLg2)(arr); - char* data = _upb_array_ptr(arr); - memmove(&data[dst_idx << lg2], &data[src_idx << lg2], count << lg2); -} - -bool upb_Array_Insert(upb_Array* arr, size_t i, size_t count, - upb_Arena* arena) { - UPB_ASSERT(arena); - UPB_ASSERT(i <= arr->UPB_PRIVATE(size)); - UPB_ASSERT(count + arr->UPB_PRIVATE(size) >= count); - const size_t oldsize = arr->UPB_PRIVATE(size); - if (!_upb_Array_ResizeUninitialized(arr, arr->UPB_PRIVATE(size) + count, - arena)) { - return false; - } - upb_Array_Move(arr, i + count, i, oldsize - i); - return true; -} - -/* - * i end arr->size - * |------------|XXXXXXXX|--------| - */ -void upb_Array_Delete(upb_Array* arr, size_t i, size_t count) { - const size_t end = i + count; - UPB_ASSERT(i <= end); - UPB_ASSERT(end <= arr->UPB_PRIVATE(size)); - upb_Array_Move(arr, i, end, arr->UPB_PRIVATE(size) - end); - arr->UPB_PRIVATE(size) -= count; -} - -bool upb_Array_Resize(upb_Array* arr, size_t size, upb_Arena* arena) { - const size_t oldsize = arr->UPB_PRIVATE(size); - if (UPB_UNLIKELY(!_upb_Array_ResizeUninitialized(arr, size, arena))) { - return false; - } - const size_t newsize = arr->UPB_PRIVATE(size); - if (newsize > oldsize) { - const int lg2 = UPB_PRIVATE(_upb_Array_ElemSizeLg2)(arr); - char* data = _upb_array_ptr(arr); - memset(data + (oldsize << lg2), 0, (newsize - oldsize) << lg2); - } - return true; -} - -bool UPB_PRIVATE(_upb_Array_Realloc)(upb_Array* array, size_t min_capacity, - upb_Arena* arena) { - size_t new_capacity = UPB_MAX(array->UPB_PRIVATE(capacity), 4); - const int lg2 = UPB_PRIVATE(_upb_Array_ElemSizeLg2)(array); - size_t old_bytes = array->UPB_PRIVATE(capacity) << lg2; - void* ptr = _upb_array_ptr(array); - - // Log2 ceiling of size. - while (new_capacity < min_capacity) new_capacity *= 2; - - const size_t new_bytes = new_capacity << lg2; - ptr = upb_Arena_Realloc(arena, ptr, old_bytes, new_bytes); - if (!ptr) return false; - - UPB_PRIVATE(_upb_Array_SetTaggedPtr)(array, ptr, lg2); - array->UPB_PRIVATE(capacity) = new_capacity; - return true; -} - - -#include - - -// Must be last. - -const struct upb_Extension* _upb_Message_Getext( - const upb_Message* msg, const upb_MiniTableExtension* e) { - size_t n; - const struct upb_Extension* ext = UPB_PRIVATE(_upb_Message_Getexts)(msg, &n); - - // For now we use linear search exclusively to find extensions. - // If this becomes an issue due to messages with lots of extensions, - // we can introduce a table of some sort. - for (size_t i = 0; i < n; i++) { - if (ext[i].ext == e) { - return &ext[i]; - } - } - - return NULL; -} - -const struct upb_Extension* UPB_PRIVATE(_upb_Message_Getexts)( - const upb_Message* msg, size_t* count) { - const upb_Message_Internal* in = upb_Message_Getinternal(msg); - if (in->internal) { - *count = (in->internal->size - in->internal->ext_begin) / - sizeof(struct upb_Extension); - return UPB_PTR_AT(in->internal, in->internal->ext_begin, void); - } else { - *count = 0; - return NULL; - } -} - -struct upb_Extension* _upb_Message_GetOrCreateExtension( - upb_Message* msg, const upb_MiniTableExtension* e, upb_Arena* arena) { - struct upb_Extension* ext = - (struct upb_Extension*)_upb_Message_Getext(msg, e); - if (ext) return ext; - if (!UPB_PRIVATE(_upb_Message_Realloc)(msg, sizeof(struct upb_Extension), - arena)) - return NULL; - upb_Message_Internal* in = upb_Message_Getinternal(msg); - in->internal->ext_begin -= sizeof(struct upb_Extension); - ext = UPB_PTR_AT(in->internal, in->internal->ext_begin, void); - memset(ext, 0, sizeof(struct upb_Extension)); - ext->ext = e; - return ext; -} - - -#include -#include - - -// Must be last. - -const float kUpb_FltInfinity = INFINITY; -const double kUpb_Infinity = INFINITY; -const double kUpb_NaN = NAN; - -static const size_t realloc_overhead = sizeof(upb_Message_InternalData); - -bool UPB_PRIVATE(_upb_Message_Realloc)(upb_Message* msg, size_t need, - upb_Arena* arena) { - upb_Message_Internal* in = upb_Message_Getinternal(msg); - if (!in->internal) { - // No internal data, allocate from scratch. - size_t size = UPB_MAX(128, upb_Log2CeilingSize(need + realloc_overhead)); - upb_Message_InternalData* internal = upb_Arena_Malloc(arena, size); - if (!internal) return false; - internal->size = size; - internal->unknown_end = realloc_overhead; - internal->ext_begin = size; - in->internal = internal; - } else if (in->internal->ext_begin - in->internal->unknown_end < need) { - // Internal data is too small, reallocate. - size_t new_size = upb_Log2CeilingSize(in->internal->size + need); - size_t ext_bytes = in->internal->size - in->internal->ext_begin; - size_t new_ext_begin = new_size - ext_bytes; - upb_Message_InternalData* internal = - upb_Arena_Realloc(arena, in->internal, in->internal->size, new_size); - if (!internal) return false; - if (ext_bytes) { - // Need to move extension data to the end. - char* ptr = (char*)internal; - memmove(ptr + new_ext_begin, ptr + internal->ext_begin, ext_bytes); - } - internal->ext_begin = new_ext_begin; - internal->size = new_size; - in->internal = internal; - } - UPB_ASSERT(in->internal->ext_begin - in->internal->unknown_end >= need); - return true; + UPB_ASSERT(in->internal->ext_begin - in->internal->unknown_end >= need); + return true; } @@ -6339,91 +5990,447 @@ bool _upb_mapsorter_pushmap(_upb_mapsorter* s, upb_FieldType key_type, return true; } -static int _upb_mapsorter_cmpext(const void* _a, const void* _b) { - const upb_Extension* const* a = _a; - const upb_Extension* const* b = _b; - uint32_t a_num = upb_MiniTableExtension_Number((*a)->ext); - uint32_t b_num = upb_MiniTableExtension_Number((*b)->ext); - assert(a_num != b_num); - return a_num < b_num ? -1 : 1; -} +static int _upb_mapsorter_cmpext(const void* _a, const void* _b) { + const upb_Extension* const* a = _a; + const upb_Extension* const* b = _b; + uint32_t a_num = upb_MiniTableExtension_Number((*a)->ext); + uint32_t b_num = upb_MiniTableExtension_Number((*b)->ext); + assert(a_num != b_num); + return a_num < b_num ? -1 : 1; +} + +bool _upb_mapsorter_pushexts(_upb_mapsorter* s, const upb_Extension* exts, + size_t count, _upb_sortedmap* sorted) { + if (!_upb_mapsorter_resize(s, sorted, count)) return false; + + for (size_t i = 0; i < count; i++) { + s->entries[sorted->start + i] = &exts[i]; + } + + qsort(&s->entries[sorted->start], count, sizeof(*s->entries), + _upb_mapsorter_cmpext); + return true; +} + + +#include +#include +#include + + +// Must be last. + +static const size_t message_overhead = sizeof(upb_Message_InternalData); + +upb_Message* upb_Message_New(const upb_MiniTable* m, upb_Arena* arena) { + return _upb_Message_New(m, arena); +} + +bool UPB_PRIVATE(_upb_Message_AddUnknown)(upb_Message* msg, const char* data, + size_t len, upb_Arena* arena) { + if (!UPB_PRIVATE(_upb_Message_Realloc)(msg, len, arena)) return false; + upb_Message_Internal* in = upb_Message_Getinternal(msg); + memcpy(UPB_PTR_AT(in->internal, in->internal->unknown_end, char), data, len); + in->internal->unknown_end += len; + return true; +} + +void _upb_Message_DiscardUnknown_shallow(upb_Message* msg) { + upb_Message_Internal* in = upb_Message_Getinternal(msg); + if (in->internal) { + in->internal->unknown_end = message_overhead; + } +} + +const char* upb_Message_GetUnknown(const upb_Message* msg, size_t* len) { + const upb_Message_Internal* in = upb_Message_Getinternal(msg); + if (in->internal) { + *len = in->internal->unknown_end - message_overhead; + return (char*)(in->internal + 1); + } else { + *len = 0; + return NULL; + } +} + +void upb_Message_DeleteUnknown(upb_Message* msg, const char* data, size_t len) { + upb_Message_Internal* in = upb_Message_Getinternal(msg); + const char* internal_unknown_end = + UPB_PTR_AT(in->internal, in->internal->unknown_end, char); +#ifndef NDEBUG + size_t full_unknown_size; + const char* full_unknown = upb_Message_GetUnknown(msg, &full_unknown_size); + UPB_ASSERT((uintptr_t)data >= (uintptr_t)full_unknown); + UPB_ASSERT((uintptr_t)data < (uintptr_t)(full_unknown + full_unknown_size)); + UPB_ASSERT((uintptr_t)(data + len) > (uintptr_t)data); + UPB_ASSERT((uintptr_t)(data + len) <= (uintptr_t)internal_unknown_end); +#endif + if ((data + len) != internal_unknown_end) { + memmove((char*)data, data + len, internal_unknown_end - data - len); + } + in->internal->unknown_end -= len; +} + +size_t upb_Message_ExtensionCount(const upb_Message* msg) { + size_t count; + UPB_PRIVATE(_upb_Message_Getexts)(msg, &count); + return count; +} + + +#include + + +// Must be last. + +bool upb_Message_SetMapEntry(upb_Map* map, const upb_MiniTable* mini_table, + const upb_MiniTableField* f, + upb_Message* map_entry_message, upb_Arena* arena) { + // TODO: use a variant of upb_MiniTable_GetSubMessageTable() here. + const upb_MiniTable* map_entry_mini_table = upb_MiniTableSub_Message( + mini_table->UPB_PRIVATE(subs)[f->UPB_PRIVATE(submsg_index)]); + UPB_ASSERT(map_entry_mini_table); + UPB_ASSERT(map_entry_mini_table->UPB_PRIVATE(field_count) == 2); + const upb_MiniTableField* map_entry_key_field = + &map_entry_mini_table->UPB_PRIVATE(fields)[0]; + const upb_MiniTableField* map_entry_value_field = + &map_entry_mini_table->UPB_PRIVATE(fields)[1]; + // Map key/value cannot have explicit defaults, + // hence assuming a zero default is valid. + upb_MessageValue default_val; + memset(&default_val, 0, sizeof(upb_MessageValue)); + upb_MessageValue map_entry_key = + upb_Message_GetField(map_entry_message, map_entry_key_field, default_val); + upb_MessageValue map_entry_value = upb_Message_GetField( + map_entry_message, map_entry_value_field, default_val); + return upb_Map_Set(map, map_entry_key, map_entry_value, arena); +} + + +#include + + +// Must be last. + +bool upb_Message_IsExactlyEqual(const upb_Message* msg1, + const upb_Message* msg2, + const upb_MiniTable* m) { + if (msg1 == msg2) return true; + + int opts = kUpb_EncodeOption_SkipUnknown | kUpb_EncodeOption_Deterministic; + upb_Arena* a = upb_Arena_New(); + + // Compare deterministically serialized payloads with no unknown fields. + size_t size1, size2; + char *data1, *data2; + upb_EncodeStatus status1 = upb_Encode(msg1, m, opts, a, &data1, &size1); + upb_EncodeStatus status2 = upb_Encode(msg2, m, opts, a, &data2, &size2); + + if (status1 != kUpb_EncodeStatus_Ok || status2 != kUpb_EncodeStatus_Ok) { + // TODO: How should we fail here? (In Ruby we throw an exception.) + upb_Arena_Free(a); + return false; + } + + const bool ret = (size1 == size2) && (memcmp(data1, data2, size1) == 0); + upb_Arena_Free(a); + return ret; +} + + +#include +#include + + +// Must be last. + +static upb_StringView upb_Clone_StringView(upb_StringView str, + upb_Arena* arena) { + if (str.size == 0) { + return upb_StringView_FromDataAndSize(NULL, 0); + } + void* cloned_data = upb_Arena_Malloc(arena, str.size); + upb_StringView cloned_str = + upb_StringView_FromDataAndSize(cloned_data, str.size); + memcpy(cloned_data, str.data, str.size); + return cloned_str; +} + +static bool upb_Clone_MessageValue(void* value, upb_CType value_type, + const upb_MiniTable* sub, upb_Arena* arena) { + switch (value_type) { + case kUpb_CType_Bool: + case kUpb_CType_Float: + case kUpb_CType_Int32: + case kUpb_CType_UInt32: + case kUpb_CType_Enum: + case kUpb_CType_Double: + case kUpb_CType_Int64: + case kUpb_CType_UInt64: + return true; + case kUpb_CType_String: + case kUpb_CType_Bytes: { + upb_StringView source = *(upb_StringView*)value; + int size = source.size; + void* cloned_data = upb_Arena_Malloc(arena, size); + if (cloned_data == NULL) { + return false; + } + *(upb_StringView*)value = + upb_StringView_FromDataAndSize(cloned_data, size); + memcpy(cloned_data, source.data, size); + return true; + } break; + case kUpb_CType_Message: { + const upb_TaggedMessagePtr source = *(upb_TaggedMessagePtr*)value; + bool is_empty = upb_TaggedMessagePtr_IsEmpty(source); + if (is_empty) sub = UPB_PRIVATE(_upb_MiniTable_Empty)(); + UPB_ASSERT(source); + upb_Message* clone = upb_Message_DeepClone( + _upb_TaggedMessagePtr_GetMessage(source), sub, arena); + *(upb_TaggedMessagePtr*)value = + _upb_TaggedMessagePtr_Pack(clone, is_empty); + return clone != NULL; + } break; + } + UPB_UNREACHABLE(); +} + +upb_Map* upb_Map_DeepClone(const upb_Map* map, upb_CType key_type, + upb_CType value_type, + const upb_MiniTable* map_entry_table, + upb_Arena* arena) { + upb_Map* cloned_map = _upb_Map_New(arena, map->key_size, map->val_size); + if (cloned_map == NULL) { + return NULL; + } + upb_MessageValue key, val; + size_t iter = kUpb_Map_Begin; + while (upb_Map_Next(map, &key, &val, &iter)) { + const upb_MiniTableField* value_field = + &map_entry_table->UPB_PRIVATE(fields)[1]; + const upb_MiniTable* value_sub = + (value_field->UPB_PRIVATE(submsg_index) != kUpb_NoSub) + ? upb_MiniTable_GetSubMessageTable(map_entry_table, value_field) + : NULL; + upb_CType value_field_type = upb_MiniTableField_CType(value_field); + if (!upb_Clone_MessageValue(&val, value_field_type, value_sub, arena)) { + return NULL; + } + if (!upb_Map_Set(cloned_map, key, val, arena)) { + return NULL; + } + } + return cloned_map; +} + +static upb_Map* upb_Message_Map_DeepClone(const upb_Map* map, + const upb_MiniTable* mini_table, + const upb_MiniTableField* f, + upb_Message* clone, + upb_Arena* arena) { + // TODO: use a variant of upb_MiniTable_GetSubMessageTable() here. + const upb_MiniTable* map_entry_table = upb_MiniTableSub_Message( + mini_table->UPB_PRIVATE(subs)[f->UPB_PRIVATE(submsg_index)]); + UPB_ASSERT(map_entry_table); -bool _upb_mapsorter_pushexts(_upb_mapsorter* s, const upb_Extension* exts, - size_t count, _upb_sortedmap* sorted) { - if (!_upb_mapsorter_resize(s, sorted, count)) return false; + const upb_MiniTableField* key_field = + &map_entry_table->UPB_PRIVATE(fields)[0]; + const upb_MiniTableField* value_field = + &map_entry_table->UPB_PRIVATE(fields)[1]; - for (size_t i = 0; i < count; i++) { - s->entries[sorted->start + i] = &exts[i]; + upb_Map* cloned_map = upb_Map_DeepClone( + map, upb_MiniTableField_CType(key_field), + upb_MiniTableField_CType(value_field), map_entry_table, arena); + if (!cloned_map) { + return NULL; } - - qsort(&s->entries[sorted->start], count, sizeof(*s->entries), - _upb_mapsorter_cmpext); - return true; + _upb_Message_SetNonExtensionField(clone, f, &cloned_map); + return cloned_map; } +upb_Array* upb_Array_DeepClone(const upb_Array* array, upb_CType value_type, + const upb_MiniTable* sub, upb_Arena* arena) { + const size_t size = array->UPB_PRIVATE(size); + const int lg2 = UPB_PRIVATE(_upb_CType_SizeLg2)(value_type); + upb_Array* cloned_array = UPB_PRIVATE(_upb_Array_New)(arena, size, lg2); + if (!cloned_array) { + return NULL; + } + if (!_upb_Array_ResizeUninitialized(cloned_array, size, arena)) { + return NULL; + } + for (size_t i = 0; i < size; ++i) { + upb_MessageValue val = upb_Array_Get(array, i); + if (!upb_Clone_MessageValue(&val, value_type, sub, arena)) { + return false; + } + upb_Array_Set(cloned_array, i, val); + } + return cloned_array; +} -#include -#include -#include - - -// Must be last. - -static const size_t message_overhead = sizeof(upb_Message_InternalData); +static bool upb_Message_Array_DeepClone(const upb_Array* array, + const upb_MiniTable* mini_table, + const upb_MiniTableField* field, + upb_Message* clone, upb_Arena* arena) { + UPB_PRIVATE(_upb_MiniTableField_CheckIsArray)(field); + upb_Array* cloned_array = upb_Array_DeepClone( + array, upb_MiniTableField_CType(field), + upb_MiniTableField_CType(field) == kUpb_CType_Message && + field->UPB_PRIVATE(submsg_index) != kUpb_NoSub + ? upb_MiniTable_GetSubMessageTable(mini_table, field) + : NULL, + arena); -upb_Message* upb_Message_New(const upb_MiniTable* m, upb_Arena* arena) { - return _upb_Message_New(m, arena); + // Clear out upb_Array* due to parent memcpy. + _upb_Message_SetNonExtensionField(clone, field, &cloned_array); + return true; } -bool UPB_PRIVATE(_upb_Message_AddUnknown)(upb_Message* msg, const char* data, - size_t len, upb_Arena* arena) { - if (!UPB_PRIVATE(_upb_Message_Realloc)(msg, len, arena)) return false; - upb_Message_Internal* in = upb_Message_Getinternal(msg); - memcpy(UPB_PTR_AT(in->internal, in->internal->unknown_end, char), data, len); - in->internal->unknown_end += len; - return true; +static bool upb_Clone_ExtensionValue( + const upb_MiniTableExtension* mini_table_ext, const upb_Extension* source, + upb_Extension* dest, upb_Arena* arena) { + dest->data = source->data; + return upb_Clone_MessageValue( + &dest->data, + upb_MiniTableField_CType(&mini_table_ext->UPB_PRIVATE(field)), + upb_MiniTableExtension_GetSubMessage(mini_table_ext), arena); } -void _upb_Message_DiscardUnknown_shallow(upb_Message* msg) { - upb_Message_Internal* in = upb_Message_Getinternal(msg); - if (in->internal) { - in->internal->unknown_end = message_overhead; +upb_Message* _upb_Message_Copy(upb_Message* dst, const upb_Message* src, + const upb_MiniTable* mini_table, + upb_Arena* arena) { + upb_StringView empty_string = upb_StringView_FromDataAndSize(NULL, 0); + // Only copy message area skipping upb_Message_Internal. + memcpy(dst, src, mini_table->UPB_PRIVATE(size)); + for (size_t i = 0; i < mini_table->UPB_PRIVATE(field_count); ++i) { + const upb_MiniTableField* field = &mini_table->UPB_PRIVATE(fields)[i]; + if (upb_MiniTableField_IsScalar(field)) { + switch (upb_MiniTableField_CType(field)) { + case kUpb_CType_Message: { + upb_TaggedMessagePtr tagged = + upb_Message_GetTaggedMessagePtr(src, field, NULL); + const upb_Message* sub_message = + _upb_TaggedMessagePtr_GetMessage(tagged); + if (sub_message != NULL) { + // If the message is currently in an unlinked, "empty" state we keep + // it that way, because we don't want to deal with decode options, + // decode status, or possible parse failure here. + bool is_empty = upb_TaggedMessagePtr_IsEmpty(tagged); + const upb_MiniTable* sub_message_table = + is_empty ? UPB_PRIVATE(_upb_MiniTable_Empty)() + : upb_MiniTable_GetSubMessageTable(mini_table, field); + upb_Message* dst_sub_message = + upb_Message_DeepClone(sub_message, sub_message_table, arena); + if (dst_sub_message == NULL) { + return NULL; + } + _upb_Message_SetTaggedMessagePtr( + dst, mini_table, field, + _upb_TaggedMessagePtr_Pack(dst_sub_message, is_empty)); + } + } break; + case kUpb_CType_String: + case kUpb_CType_Bytes: { + upb_StringView str = upb_Message_GetString(src, field, empty_string); + if (str.size != 0) { + if (!upb_Message_SetString( + dst, field, upb_Clone_StringView(str, arena), arena)) { + return NULL; + } + } + } break; + default: + // Scalar, already copied. + break; + } + } else { + if (upb_MiniTableField_IsMap(field)) { + const upb_Map* map = upb_Message_GetMap(src, field); + if (map != NULL) { + if (!upb_Message_Map_DeepClone(map, mini_table, field, dst, arena)) { + return NULL; + } + } + } else { + const upb_Array* array = upb_Message_GetArray(src, field); + if (array != NULL) { + if (!upb_Message_Array_DeepClone(array, mini_table, field, dst, + arena)) { + return NULL; + } + } + } + } + } + // Clone extensions. + size_t ext_count; + const upb_Extension* ext = UPB_PRIVATE(_upb_Message_Getexts)(src, &ext_count); + for (size_t i = 0; i < ext_count; ++i) { + const upb_Extension* msg_ext = &ext[i]; + const upb_MiniTableField* field = &msg_ext->ext->UPB_PRIVATE(field); + upb_Extension* dst_ext = + _upb_Message_GetOrCreateExtension(dst, msg_ext->ext, arena); + if (!dst_ext) return NULL; + if (upb_MiniTableField_IsScalar(field)) { + if (!upb_Clone_ExtensionValue(msg_ext->ext, msg_ext, dst_ext, arena)) { + return NULL; + } + } else { + upb_Array* msg_array = (upb_Array*)msg_ext->data.ptr; + UPB_ASSERT(msg_array); + upb_Array* cloned_array = upb_Array_DeepClone( + msg_array, upb_MiniTableField_CType(field), + upb_MiniTableExtension_GetSubMessage(msg_ext->ext), arena); + if (!cloned_array) { + return NULL; + } + dst_ext->data.ptr = (void*)cloned_array; + } } -} -const char* upb_Message_GetUnknown(const upb_Message* msg, size_t* len) { - const upb_Message_Internal* in = upb_Message_Getinternal(msg); - if (in->internal) { - *len = in->internal->unknown_end - message_overhead; - return (char*)(in->internal + 1); - } else { - *len = 0; - return NULL; + // Clone unknowns. + size_t unknown_size = 0; + const char* ptr = upb_Message_GetUnknown(src, &unknown_size); + if (unknown_size != 0) { + UPB_ASSERT(ptr); + // Make a copy into destination arena. + if (!UPB_PRIVATE(_upb_Message_AddUnknown)(dst, ptr, unknown_size, arena)) { + return NULL; + } } + return dst; } -void upb_Message_DeleteUnknown(upb_Message* msg, const char* data, size_t len) { - upb_Message_Internal* in = upb_Message_Getinternal(msg); - const char* internal_unknown_end = - UPB_PTR_AT(in->internal, in->internal->unknown_end, char); -#ifndef NDEBUG - size_t full_unknown_size; - const char* full_unknown = upb_Message_GetUnknown(msg, &full_unknown_size); - UPB_ASSERT((uintptr_t)data >= (uintptr_t)full_unknown); - UPB_ASSERT((uintptr_t)data < (uintptr_t)(full_unknown + full_unknown_size)); - UPB_ASSERT((uintptr_t)(data + len) > (uintptr_t)data); - UPB_ASSERT((uintptr_t)(data + len) <= (uintptr_t)internal_unknown_end); -#endif - if ((data + len) != internal_unknown_end) { - memmove((char*)data, data + len, internal_unknown_end - data - len); - } - in->internal->unknown_end -= len; +bool upb_Message_DeepCopy(upb_Message* dst, const upb_Message* src, + const upb_MiniTable* mini_table, upb_Arena* arena) { + upb_Message_Clear(dst, mini_table); + return _upb_Message_Copy(dst, src, mini_table, arena) != NULL; } -size_t upb_Message_ExtensionCount(const upb_Message* msg) { - size_t count; - UPB_PRIVATE(_upb_Message_Getexts)(msg, &count); - return count; +// Deep clones a message using the provided target arena. +// +// Returns NULL on failure. +upb_Message* upb_Message_DeepClone(const upb_Message* msg, + const upb_MiniTable* m, upb_Arena* arena) { + upb_Message* clone = upb_Message_New(m, arena); + return _upb_Message_Copy(clone, msg, m, arena); +} + +// Performs a shallow copy. TODO: Extend to handle unknown fields. +void upb_Message_ShallowCopy(upb_Message* dst, const upb_Message* src, + const upb_MiniTable* m) { + memcpy(dst, src, m->UPB_PRIVATE(size)); +} + +// Performs a shallow clone. Ignores unknown fields. +upb_Message* upb_Message_ShallowClone(const upb_Message* msg, + const upb_MiniTable* m, + upb_Arena* arena) { + upb_Message* clone = upb_Message_New(m, arena); + upb_Message_ShallowCopy(clone, msg, m); + return clone; } diff --git a/ruby/ext/google/protobuf_c/ruby-upb.h b/ruby/ext/google/protobuf_c/ruby-upb.h index 244da19429f60..4e0c0977002a1 100755 --- a/ruby/ext/google/protobuf_c/ruby-upb.h +++ b/ruby/ext/google/protobuf_c/ruby-upb.h @@ -3450,10 +3450,6 @@ bool upb_Message_SetMapEntry(upb_Map* map, const upb_MiniTable* mini_table, const upb_MiniTableField* field, upb_Message* map_entry_message, upb_Arena* arena); -// Compares two messages by serializing them and calling memcmp(). -bool upb_Message_IsExactlyEqual(const upb_Message* m1, const upb_Message* m2, - const upb_MiniTable* layout); - #ifdef __cplusplus } /* extern "C" */ #endif @@ -12335,49 +12331,6 @@ const upb_Extension* upb_Message_FindExtensionByNumber(const upb_Message* msg, #endif /* UPB_MESSAGE_COMPAT_H_ */ -#ifndef UPB_MESSAGE_COPY_H_ -#define UPB_MESSAGE_COPY_H_ - - -// Must be last. - -#ifdef __cplusplus -extern "C" { -#endif - -// Deep clones a message using the provided target arena. -upb_Message* upb_Message_DeepClone(const upb_Message* msg, - const upb_MiniTable* m, upb_Arena* arena); - -// Shallow clones a message using the provided target arena. -upb_Message* upb_Message_ShallowClone(const upb_Message* msg, - const upb_MiniTable* m, upb_Arena* arena); - -// Deep clones array contents. -upb_Array* upb_Array_DeepClone(const upb_Array* array, upb_CType value_type, - const upb_MiniTable* sub, upb_Arena* arena); - -// Deep clones map contents. -upb_Map* upb_Map_DeepClone(const upb_Map* map, upb_CType key_type, - upb_CType value_type, - const upb_MiniTable* map_entry_table, - upb_Arena* arena); - -// Deep copies the message from src to dst. -bool upb_Message_DeepCopy(upb_Message* dst, const upb_Message* src, - const upb_MiniTable* m, upb_Arena* arena); - -// Shallow copies the message from src to dst. -void upb_Message_ShallowCopy(upb_Message* dst, const upb_Message* src, - const upb_MiniTable* m); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - - -#endif // UPB_MESSAGE_COPY_H_ - // EVERYTHING BELOW THIS LINE IS INTERNAL - DO NOT USE ///////////////////////// #ifndef UPB_MESSAGE_INTERNAL_MAP_SORTER_H_ @@ -12491,6 +12444,71 @@ bool _upb_mapsorter_pushexts(_upb_mapsorter* s, const upb_Extension* exts, #endif /* UPB_MESSAGE_INTERNAL_MAP_SORTER_H_ */ +#ifndef UPB_MESSAGE_COMPARE_H_ +#define UPB_MESSAGE_COMPARE_H_ + + +// Must be last. + +#ifdef __cplusplus +extern "C" { +#endif + +// Compares two messages by serializing them and calling memcmp(). +UPB_API bool upb_Message_IsExactlyEqual(const upb_Message* msg1, + const upb_Message* msg2, + const upb_MiniTable* m); + +#ifdef __cplusplus +} /* extern "C" */ +#endif + + +#endif // UPB_MESSAGE_COMPARE_H_ + +#ifndef UPB_MESSAGE_COPY_H_ +#define UPB_MESSAGE_COPY_H_ + + +// Must be last. + +#ifdef __cplusplus +extern "C" { +#endif + +// Deep clones a message using the provided target arena. +upb_Message* upb_Message_DeepClone(const upb_Message* msg, + const upb_MiniTable* m, upb_Arena* arena); + +// Shallow clones a message using the provided target arena. +upb_Message* upb_Message_ShallowClone(const upb_Message* msg, + const upb_MiniTable* m, upb_Arena* arena); + +// Deep clones array contents. +upb_Array* upb_Array_DeepClone(const upb_Array* array, upb_CType value_type, + const upb_MiniTable* sub, upb_Arena* arena); + +// Deep clones map contents. +upb_Map* upb_Map_DeepClone(const upb_Map* map, upb_CType key_type, + upb_CType value_type, + const upb_MiniTable* map_entry_table, + upb_Arena* arena); + +// Deep copies the message from src to dst. +bool upb_Message_DeepCopy(upb_Message* dst, const upb_Message* src, + const upb_MiniTable* m, upb_Arena* arena); + +// Shallow copies the message from src to dst. +void upb_Message_ShallowCopy(upb_Message* dst, const upb_Message* src, + const upb_MiniTable* m); + +#ifdef __cplusplus +} /* extern "C" */ +#endif + + +#endif // UPB_MESSAGE_COPY_H_ + #ifndef UPB_MINI_DESCRIPTOR_INTERNAL_BASE92_H_ #define UPB_MINI_DESCRIPTOR_INTERNAL_BASE92_H_ diff --git a/upb/cmake/CMakeLists.txt b/upb/cmake/CMakeLists.txt index 6374432ba59d6..bdab6883d9289 100644 --- a/upb/cmake/CMakeLists.txt +++ b/upb/cmake/CMakeLists.txt @@ -92,8 +92,6 @@ target_link_libraries(generated_code_support__only_for_generated_code_do_not_use mem message message_accessors - message_accessors_internal - message_internal mini_descriptor mini_table wire) From e4057a4014628368de45a2bac22579f96d63416d Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Wed, 27 Dec 2023 12:29:05 -0800 Subject: [PATCH 108/255] Enable Rust conformance test on proto3 message. PiperOrigin-RevId: 594080663 --- conformance/conformance_rust.rs | 24 +- conformance/failure_list_rust_cc.txt | 314 ++++++++++++++++++ conformance/failure_list_rust_upb.txt | 314 ++++++++++++++++++ .../text_format_failure_list_rust_cc.txt | 9 + .../text_format_failure_list_rust_upb.txt | 9 + 5 files changed, 661 insertions(+), 9 deletions(-) diff --git a/conformance/conformance_rust.rs b/conformance/conformance_rust.rs index db7df6aa00eb3..06cbc785f139e 100644 --- a/conformance/conformance_rust.rs +++ b/conformance/conformance_rust.rs @@ -16,6 +16,7 @@ use kernel::Optional::{Set, Unset}; use std::io::{self, ErrorKind, Read, Write}; use test_messages_proto2::protobuf_test_messages::proto2::TestAllTypesProto2; +use test_messages_proto3::protobuf_test_messages::proto3::TestAllTypesProto3; /// Returns Some(i32) if a binary read can succeed from stdin. /// Returns None if we have reached an EOF. @@ -64,8 +65,8 @@ fn do_test(req: &ConformanceRequest) -> ConformanceResponse { }; // Enums aren't supported yet (and not in scope for v0.6) so we can't perform - // this check yet. - + // this check yet. Note that this causes Rust to fail every test case that asks + // for output that isn't wire format. // if req.requested_output_format() != WireFormat.PROTOBUF { // resp.skipped_mut().set("only wire format output implemented") // } @@ -78,19 +79,24 @@ fn do_test(req: &ConformanceRequest) -> ConformanceResponse { Set(bytes) => bytes, }; - if is_proto2 { + let serialized = if is_proto2 { let mut proto = TestAllTypesProto2::new(); if let Err(_) = proto.deserialize(bytes) { resp.parse_error_mut().set("failed to parse bytes"); return resp; } - let serialized = proto.serialize(); // Note: serialize() is infallible in Rust api. - resp.protobuf_payload_mut().set(serialized.as_ref()); - return resp; + proto.serialize() } else { - resp.skipped_mut().set("only proto2 supported"); - return resp; - } + let mut proto = TestAllTypesProto3::new(); + if let Err(_) = proto.deserialize(bytes) { + resp.parse_error_mut().set("failed to parse bytes"); + return resp; + } + proto.serialize() + }; + + resp.protobuf_payload_mut().set(serialized); + return resp; } fn main() { diff --git a/conformance/failure_list_rust_cc.txt b/conformance/failure_list_rust_cc.txt index e69de29bb2d1d..04f06c1087fe8 100644 --- a/conformance/failure_list_rust_cc.txt +++ b/conformance/failure_list_rust_cc.txt @@ -0,0 +1,314 @@ +# All JsonOutput tests currently fail and can't be skipped yet. b/285468558 + Recommended.Proto3.FieldMaskNumbersDontRoundTrip.JsonOutput + Recommended.Proto3.FieldMaskPathsDontRoundTrip.JsonOutput + Recommended.Proto3.FieldMaskTooManyUnderscore.JsonOutput + Recommended.Proto3.ProtobufInput.OneofZeroBool.JsonOutput + Recommended.Proto3.ProtobufInput.OneofZeroBytes.JsonOutput + Recommended.Proto3.ProtobufInput.OneofZeroDouble.JsonOutput + Recommended.Proto3.ProtobufInput.OneofZeroEnum.JsonOutput + Recommended.Proto3.ProtobufInput.OneofZeroFloat.JsonOutput + Recommended.Proto3.ProtobufInput.OneofZeroMessage.JsonOutput + Recommended.Proto3.ProtobufInput.OneofZeroMessageSetTwice.JsonOutput + Recommended.Proto3.ProtobufInput.OneofZeroString.JsonOutput + Recommended.Proto3.ProtobufInput.OneofZeroUint32.JsonOutput + Recommended.Proto3.ProtobufInput.OneofZeroUint64.JsonOutput + Recommended.Proto3.ValueRejectInfNumberValue.JsonOutput + Recommended.Proto3.ValueRejectNanNumberValue.JsonOutput + Required.Proto3.DurationProtoInputTooLarge.JsonOutput + Required.Proto3.DurationProtoInputTooSmall.JsonOutput + Required.Proto3.ProtobufInput.DoubleFieldNormalizeQuietNan.JsonOutput + Required.Proto3.ProtobufInput.DoubleFieldNormalizeSignalingNan.JsonOutput + Required.Proto3.ProtobufInput.FloatFieldNormalizeQuietNan.JsonOutput + Required.Proto3.ProtobufInput.FloatFieldNormalizeSignalingNan.JsonOutput + Required.Proto3.ProtobufInput.RepeatedScalarMessageMerge.JsonOutput + Required.Proto3.ProtobufInput.RepeatedScalarSelectsLast.BOOL.JsonOutput + Required.Proto3.ProtobufInput.RepeatedScalarSelectsLast.BYTES.JsonOutput + Required.Proto3.ProtobufInput.RepeatedScalarSelectsLast.DOUBLE.JsonOutput + Required.Proto3.ProtobufInput.RepeatedScalarSelectsLast.ENUM.JsonOutput + Required.Proto3.ProtobufInput.RepeatedScalarSelectsLast.FIXED32.JsonOutput + Required.Proto3.ProtobufInput.RepeatedScalarSelectsLast.FIXED64.JsonOutput + Required.Proto3.ProtobufInput.RepeatedScalarSelectsLast.FLOAT.JsonOutput + Required.Proto3.ProtobufInput.RepeatedScalarSelectsLast.INT32.JsonOutput + Required.Proto3.ProtobufInput.RepeatedScalarSelectsLast.INT64.JsonOutput + Required.Proto3.ProtobufInput.RepeatedScalarSelectsLast.SFIXED32.JsonOutput + Required.Proto3.ProtobufInput.RepeatedScalarSelectsLast.SFIXED64.JsonOutput + Required.Proto3.ProtobufInput.RepeatedScalarSelectsLast.SINT32.JsonOutput + Required.Proto3.ProtobufInput.RepeatedScalarSelectsLast.SINT64.JsonOutput + Required.Proto3.ProtobufInput.RepeatedScalarSelectsLast.STRING.JsonOutput + Required.Proto3.ProtobufInput.RepeatedScalarSelectsLast.UINT32.JsonOutput + Required.Proto3.ProtobufInput.RepeatedScalarSelectsLast.UINT64.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.BOOL.BOOL.Default.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.BOOL.BOOL.DuplicateKey.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.BOOL.BOOL.DuplicateKeyInMapEntry.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.BOOL.BOOL.DuplicateValueInMapEntry.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.BOOL.BOOL.MissingDefault.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.BOOL.BOOL.NonDefault.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.BOOL.BOOL.Unordered.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.FIXED32.FIXED32.Default.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.FIXED32.FIXED32.DuplicateKey.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.FIXED32.FIXED32.DuplicateKeyInMapEntry.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.FIXED32.FIXED32.DuplicateValueInMapEntry.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.FIXED32.FIXED32.MissingDefault.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.FIXED32.FIXED32.NonDefault.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.FIXED32.FIXED32.Unordered.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.FIXED64.FIXED64.Default.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.FIXED64.FIXED64.DuplicateKey.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.FIXED64.FIXED64.DuplicateKeyInMapEntry.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.FIXED64.FIXED64.DuplicateValueInMapEntry.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.FIXED64.FIXED64.MissingDefault.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.FIXED64.FIXED64.NonDefault.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.FIXED64.FIXED64.Unordered.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.INT32.DOUBLE.Default.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.INT32.DOUBLE.DuplicateKey.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.INT32.DOUBLE.DuplicateKeyInMapEntry.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.INT32.DOUBLE.DuplicateValueInMapEntry.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.INT32.DOUBLE.MissingDefault.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.INT32.DOUBLE.NonDefault.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.INT32.DOUBLE.Unordered.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.INT32.FLOAT.Default.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.INT32.FLOAT.DuplicateKey.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.INT32.FLOAT.DuplicateKeyInMapEntry.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.INT32.FLOAT.DuplicateValueInMapEntry.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.INT32.FLOAT.MissingDefault.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.INT32.FLOAT.NonDefault.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.INT32.FLOAT.Unordered.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.INT32.INT32.Default.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.INT32.INT32.DuplicateKey.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.INT32.INT32.DuplicateKeyInMapEntry.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.INT32.INT32.DuplicateValueInMapEntry.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.INT32.INT32.MissingDefault.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.INT32.INT32.NonDefault.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.INT32.INT32.Unordered.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.INT64.INT64.Default.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.INT64.INT64.DuplicateKey.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.INT64.INT64.DuplicateKeyInMapEntry.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.INT64.INT64.DuplicateValueInMapEntry.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.INT64.INT64.MissingDefault.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.INT64.INT64.NonDefault.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.INT64.INT64.Unordered.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.SFIXED32.SFIXED32.Default.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.SFIXED32.SFIXED32.DuplicateKey.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.SFIXED32.SFIXED32.DuplicateKeyInMapEntry.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.SFIXED32.SFIXED32.DuplicateValueInMapEntry.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.SFIXED32.SFIXED32.MissingDefault.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.SFIXED32.SFIXED32.NonDefault.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.SFIXED32.SFIXED32.Unordered.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.SFIXED64.SFIXED64.Default.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.SFIXED64.SFIXED64.DuplicateKey.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.SFIXED64.SFIXED64.DuplicateKeyInMapEntry.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.SFIXED64.SFIXED64.DuplicateValueInMapEntry.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.SFIXED64.SFIXED64.MissingDefault.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.SFIXED64.SFIXED64.NonDefault.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.SFIXED64.SFIXED64.Unordered.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.SINT32.SINT32.Default.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.SINT32.SINT32.DuplicateKey.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.SINT32.SINT32.DuplicateKeyInMapEntry.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.SINT32.SINT32.DuplicateValueInMapEntry.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.SINT32.SINT32.MissingDefault.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.SINT32.SINT32.NonDefault.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.SINT32.SINT32.Unordered.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.SINT64.SINT64.Default.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.SINT64.SINT64.DuplicateKey.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.SINT64.SINT64.DuplicateKeyInMapEntry.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.SINT64.SINT64.DuplicateValueInMapEntry.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.SINT64.SINT64.MissingDefault.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.SINT64.SINT64.NonDefault.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.SINT64.SINT64.Unordered.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.STRING.BYTES.Default.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.STRING.BYTES.DuplicateKey.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.STRING.BYTES.DuplicateKeyInMapEntry.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.STRING.BYTES.DuplicateValueInMapEntry.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.STRING.BYTES.MissingDefault.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.STRING.BYTES.NonDefault.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.STRING.BYTES.Unordered.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.STRING.ENUM.Default.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.STRING.ENUM.DuplicateKey.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.STRING.ENUM.DuplicateKeyInMapEntry.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.STRING.ENUM.DuplicateValueInMapEntry.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.STRING.ENUM.MissingDefault.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.STRING.ENUM.NonDefault.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.STRING.ENUM.Unordered.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.STRING.MESSAGE.Default.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.STRING.MESSAGE.DuplicateKey.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.STRING.MESSAGE.DuplicateKeyInMapEntry.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.STRING.MESSAGE.DuplicateValueInMapEntry.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.STRING.MESSAGE.MergeValue.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.STRING.MESSAGE.MissingDefault.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.STRING.MESSAGE.NonDefault.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.STRING.MESSAGE.Unordered.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.STRING.STRING.Default.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.STRING.STRING.DuplicateKey.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.STRING.STRING.DuplicateKeyInMapEntry.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.STRING.STRING.DuplicateValueInMapEntry.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.STRING.STRING.MissingDefault.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.STRING.STRING.NonDefault.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.STRING.STRING.Unordered.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.UINT32.UINT32.Default.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.UINT32.UINT32.DuplicateKey.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.UINT32.UINT32.DuplicateKeyInMapEntry.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.UINT32.UINT32.DuplicateValueInMapEntry.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.UINT32.UINT32.MissingDefault.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.UINT32.UINT32.NonDefault.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.UINT32.UINT32.Unordered.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.UINT64.UINT64.Default.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.UINT64.UINT64.DuplicateKey.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.UINT64.UINT64.DuplicateKeyInMapEntry.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.UINT64.UINT64.DuplicateValueInMapEntry.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.UINT64.UINT64.MissingDefault.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.UINT64.UINT64.NonDefault.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.UINT64.UINT64.Unordered.JsonOutput + Required.Proto3.ProtobufInput.ValidDataOneof.BOOL.DefaultValue.JsonOutput + Required.Proto3.ProtobufInput.ValidDataOneof.BOOL.MultipleValuesForDifferentField.JsonOutput + Required.Proto3.ProtobufInput.ValidDataOneof.BOOL.MultipleValuesForSameField.JsonOutput + Required.Proto3.ProtobufInput.ValidDataOneof.BOOL.NonDefaultValue.JsonOutput + Required.Proto3.ProtobufInput.ValidDataOneof.BYTES.DefaultValue.JsonOutput + Required.Proto3.ProtobufInput.ValidDataOneof.BYTES.MultipleValuesForDifferentField.JsonOutput + Required.Proto3.ProtobufInput.ValidDataOneof.BYTES.MultipleValuesForSameField.JsonOutput + Required.Proto3.ProtobufInput.ValidDataOneof.BYTES.NonDefaultValue.JsonOutput + Required.Proto3.ProtobufInput.ValidDataOneof.DOUBLE.DefaultValue.JsonOutput + Required.Proto3.ProtobufInput.ValidDataOneof.DOUBLE.MultipleValuesForDifferentField.JsonOutput + Required.Proto3.ProtobufInput.ValidDataOneof.DOUBLE.MultipleValuesForSameField.JsonOutput + Required.Proto3.ProtobufInput.ValidDataOneof.DOUBLE.NonDefaultValue.JsonOutput + Required.Proto3.ProtobufInput.ValidDataOneof.ENUM.DefaultValue.JsonOutput + Required.Proto3.ProtobufInput.ValidDataOneof.ENUM.MultipleValuesForDifferentField.JsonOutput + Required.Proto3.ProtobufInput.ValidDataOneof.ENUM.MultipleValuesForSameField.JsonOutput + Required.Proto3.ProtobufInput.ValidDataOneof.ENUM.NonDefaultValue.JsonOutput + Required.Proto3.ProtobufInput.ValidDataOneof.FLOAT.DefaultValue.JsonOutput + Required.Proto3.ProtobufInput.ValidDataOneof.FLOAT.MultipleValuesForDifferentField.JsonOutput + Required.Proto3.ProtobufInput.ValidDataOneof.FLOAT.MultipleValuesForSameField.JsonOutput + Required.Proto3.ProtobufInput.ValidDataOneof.FLOAT.NonDefaultValue.JsonOutput + Required.Proto3.ProtobufInput.ValidDataOneof.MESSAGE.DefaultValue.JsonOutput + Required.Proto3.ProtobufInput.ValidDataOneof.MESSAGE.Merge.JsonOutput + Required.Proto3.ProtobufInput.ValidDataOneof.MESSAGE.MultipleValuesForDifferentField.JsonOutput + Required.Proto3.ProtobufInput.ValidDataOneof.MESSAGE.MultipleValuesForSameField.JsonOutput + Required.Proto3.ProtobufInput.ValidDataOneof.MESSAGE.NonDefaultValue.JsonOutput + Required.Proto3.ProtobufInput.ValidDataOneof.STRING.DefaultValue.JsonOutput + Required.Proto3.ProtobufInput.ValidDataOneof.STRING.MultipleValuesForDifferentField.JsonOutput + Required.Proto3.ProtobufInput.ValidDataOneof.STRING.MultipleValuesForSameField.JsonOutput + Required.Proto3.ProtobufInput.ValidDataOneof.STRING.NonDefaultValue.JsonOutput + Required.Proto3.ProtobufInput.ValidDataOneof.UINT32.DefaultValue.JsonOutput + Required.Proto3.ProtobufInput.ValidDataOneof.UINT32.MultipleValuesForDifferentField.JsonOutput + Required.Proto3.ProtobufInput.ValidDataOneof.UINT32.MultipleValuesForSameField.JsonOutput + Required.Proto3.ProtobufInput.ValidDataOneof.UINT32.NonDefaultValue.JsonOutput + Required.Proto3.ProtobufInput.ValidDataOneof.UINT64.DefaultValue.JsonOutput + Required.Proto3.ProtobufInput.ValidDataOneof.UINT64.MultipleValuesForDifferentField.JsonOutput + Required.Proto3.ProtobufInput.ValidDataOneof.UINT64.MultipleValuesForSameField.JsonOutput + Required.Proto3.ProtobufInput.ValidDataOneof.UINT64.NonDefaultValue.JsonOutput + Required.Proto3.ProtobufInput.ValidDataRepeated.BOOL.PackedInput.JsonOutput + Required.Proto3.ProtobufInput.ValidDataRepeated.BOOL.UnpackedInput.JsonOutput + Required.Proto3.ProtobufInput.ValidDataRepeated.BYTES.JsonOutput + Required.Proto3.ProtobufInput.ValidDataRepeated.DOUBLE.PackedInput.JsonOutput + Required.Proto3.ProtobufInput.ValidDataRepeated.DOUBLE.UnpackedInput.JsonOutput + Required.Proto3.ProtobufInput.ValidDataRepeated.ENUM.PackedInput.JsonOutput + Required.Proto3.ProtobufInput.ValidDataRepeated.ENUM.UnpackedInput.JsonOutput + Required.Proto3.ProtobufInput.ValidDataRepeated.FIXED32.PackedInput.JsonOutput + Required.Proto3.ProtobufInput.ValidDataRepeated.FIXED32.UnpackedInput.JsonOutput + Required.Proto3.ProtobufInput.ValidDataRepeated.FIXED64.PackedInput.JsonOutput + Required.Proto3.ProtobufInput.ValidDataRepeated.FIXED64.UnpackedInput.JsonOutput + Required.Proto3.ProtobufInput.ValidDataRepeated.FLOAT.PackedInput.JsonOutput + Required.Proto3.ProtobufInput.ValidDataRepeated.FLOAT.UnpackedInput.JsonOutput + Required.Proto3.ProtobufInput.ValidDataRepeated.INT32.PackedInput.JsonOutput + Required.Proto3.ProtobufInput.ValidDataRepeated.INT32.UnpackedInput.JsonOutput + Required.Proto3.ProtobufInput.ValidDataRepeated.INT64.PackedInput.JsonOutput + Required.Proto3.ProtobufInput.ValidDataRepeated.INT64.UnpackedInput.JsonOutput + Required.Proto3.ProtobufInput.ValidDataRepeated.MESSAGE.JsonOutput + Required.Proto3.ProtobufInput.ValidDataRepeated.SFIXED32.PackedInput.JsonOutput + Required.Proto3.ProtobufInput.ValidDataRepeated.SFIXED32.UnpackedInput.JsonOutput + Required.Proto3.ProtobufInput.ValidDataRepeated.SFIXED64.PackedInput.JsonOutput + Required.Proto3.ProtobufInput.ValidDataRepeated.SFIXED64.UnpackedInput.JsonOutput + Required.Proto3.ProtobufInput.ValidDataRepeated.SINT32.PackedInput.JsonOutput + Required.Proto3.ProtobufInput.ValidDataRepeated.SINT32.UnpackedInput.JsonOutput + Required.Proto3.ProtobufInput.ValidDataRepeated.SINT64.PackedInput.JsonOutput + Required.Proto3.ProtobufInput.ValidDataRepeated.SINT64.UnpackedInput.JsonOutput + Required.Proto3.ProtobufInput.ValidDataRepeated.STRING.JsonOutput + Required.Proto3.ProtobufInput.ValidDataRepeated.UINT32.PackedInput.JsonOutput + Required.Proto3.ProtobufInput.ValidDataRepeated.UINT32.UnpackedInput.JsonOutput + Required.Proto3.ProtobufInput.ValidDataRepeated.UINT64.PackedInput.JsonOutput + Required.Proto3.ProtobufInput.ValidDataRepeated.UINT64.UnpackedInput.JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.BOOL[0].JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.BOOL[1].JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.BOOL[2].JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.BOOL[3].JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.BOOL[4].JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.BOOL[5].JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.BOOL[6].JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.BYTES[0].JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.BYTES[1].JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.BYTES[2].JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.BYTES[3].JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.DOUBLE[0].JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.DOUBLE[1].JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.DOUBLE[2].JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.DOUBLE[3].JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.ENUM[0].JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.ENUM[1].JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.ENUM[2].JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.ENUM[3].JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.ENUM[4].JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.ENUM[5].JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.FIXED32[0].JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.FIXED32[1].JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.FIXED32[2].JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.FIXED64[0].JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.FIXED64[1].JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.FIXED64[2].JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.FLOAT[0].JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.FLOAT[1].JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.FLOAT[2].JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.FLOAT[3].JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.FLOAT[4].JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.INT32[0].JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.INT32[1].JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.INT32[2].JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.INT32[3].JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.INT32[4].JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.INT32[5].JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.INT32[6].JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.INT32[7].JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.INT32[8].JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.INT32[9].JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.INT64[0].JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.INT64[1].JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.INT64[2].JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.INT64[3].JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.MESSAGE[0].JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.MESSAGE[1].JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.SFIXED32[0].JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.SFIXED32[1].JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.SFIXED32[2].JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.SFIXED32[3].JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.SFIXED64[0].JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.SFIXED64[1].JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.SFIXED64[2].JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.SFIXED64[3].JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.SINT32[0].JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.SINT32[1].JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.SINT32[2].JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.SINT32[3].JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.SINT32[4].JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.SINT64[0].JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.SINT64[1].JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.SINT64[2].JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.SINT64[3].JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.STRING[0].JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.STRING[1].JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.STRING[2].JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.STRING[3].JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.STRING[4].JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.STRING[5].JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.STRING[6].JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.UINT32[0].JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.UINT32[1].JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.UINT32[2].JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.UINT32[3].JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.UINT32[4].JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.UINT32[5].JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.UINT32[6].JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.UINT32[7].JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.UINT32[8].JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.UINT32[9].JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.UINT64[0].JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.UINT64[1].JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.UINT64[2].JsonOutput + Required.Proto3.TimestampProtoInputTooLarge.JsonOutput + Required.Proto3.TimestampProtoInputTooSmall.JsonOutput \ No newline at end of file diff --git a/conformance/failure_list_rust_upb.txt b/conformance/failure_list_rust_upb.txt index e69de29bb2d1d..04f06c1087fe8 100644 --- a/conformance/failure_list_rust_upb.txt +++ b/conformance/failure_list_rust_upb.txt @@ -0,0 +1,314 @@ +# All JsonOutput tests currently fail and can't be skipped yet. b/285468558 + Recommended.Proto3.FieldMaskNumbersDontRoundTrip.JsonOutput + Recommended.Proto3.FieldMaskPathsDontRoundTrip.JsonOutput + Recommended.Proto3.FieldMaskTooManyUnderscore.JsonOutput + Recommended.Proto3.ProtobufInput.OneofZeroBool.JsonOutput + Recommended.Proto3.ProtobufInput.OneofZeroBytes.JsonOutput + Recommended.Proto3.ProtobufInput.OneofZeroDouble.JsonOutput + Recommended.Proto3.ProtobufInput.OneofZeroEnum.JsonOutput + Recommended.Proto3.ProtobufInput.OneofZeroFloat.JsonOutput + Recommended.Proto3.ProtobufInput.OneofZeroMessage.JsonOutput + Recommended.Proto3.ProtobufInput.OneofZeroMessageSetTwice.JsonOutput + Recommended.Proto3.ProtobufInput.OneofZeroString.JsonOutput + Recommended.Proto3.ProtobufInput.OneofZeroUint32.JsonOutput + Recommended.Proto3.ProtobufInput.OneofZeroUint64.JsonOutput + Recommended.Proto3.ValueRejectInfNumberValue.JsonOutput + Recommended.Proto3.ValueRejectNanNumberValue.JsonOutput + Required.Proto3.DurationProtoInputTooLarge.JsonOutput + Required.Proto3.DurationProtoInputTooSmall.JsonOutput + Required.Proto3.ProtobufInput.DoubleFieldNormalizeQuietNan.JsonOutput + Required.Proto3.ProtobufInput.DoubleFieldNormalizeSignalingNan.JsonOutput + Required.Proto3.ProtobufInput.FloatFieldNormalizeQuietNan.JsonOutput + Required.Proto3.ProtobufInput.FloatFieldNormalizeSignalingNan.JsonOutput + Required.Proto3.ProtobufInput.RepeatedScalarMessageMerge.JsonOutput + Required.Proto3.ProtobufInput.RepeatedScalarSelectsLast.BOOL.JsonOutput + Required.Proto3.ProtobufInput.RepeatedScalarSelectsLast.BYTES.JsonOutput + Required.Proto3.ProtobufInput.RepeatedScalarSelectsLast.DOUBLE.JsonOutput + Required.Proto3.ProtobufInput.RepeatedScalarSelectsLast.ENUM.JsonOutput + Required.Proto3.ProtobufInput.RepeatedScalarSelectsLast.FIXED32.JsonOutput + Required.Proto3.ProtobufInput.RepeatedScalarSelectsLast.FIXED64.JsonOutput + Required.Proto3.ProtobufInput.RepeatedScalarSelectsLast.FLOAT.JsonOutput + Required.Proto3.ProtobufInput.RepeatedScalarSelectsLast.INT32.JsonOutput + Required.Proto3.ProtobufInput.RepeatedScalarSelectsLast.INT64.JsonOutput + Required.Proto3.ProtobufInput.RepeatedScalarSelectsLast.SFIXED32.JsonOutput + Required.Proto3.ProtobufInput.RepeatedScalarSelectsLast.SFIXED64.JsonOutput + Required.Proto3.ProtobufInput.RepeatedScalarSelectsLast.SINT32.JsonOutput + Required.Proto3.ProtobufInput.RepeatedScalarSelectsLast.SINT64.JsonOutput + Required.Proto3.ProtobufInput.RepeatedScalarSelectsLast.STRING.JsonOutput + Required.Proto3.ProtobufInput.RepeatedScalarSelectsLast.UINT32.JsonOutput + Required.Proto3.ProtobufInput.RepeatedScalarSelectsLast.UINT64.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.BOOL.BOOL.Default.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.BOOL.BOOL.DuplicateKey.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.BOOL.BOOL.DuplicateKeyInMapEntry.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.BOOL.BOOL.DuplicateValueInMapEntry.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.BOOL.BOOL.MissingDefault.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.BOOL.BOOL.NonDefault.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.BOOL.BOOL.Unordered.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.FIXED32.FIXED32.Default.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.FIXED32.FIXED32.DuplicateKey.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.FIXED32.FIXED32.DuplicateKeyInMapEntry.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.FIXED32.FIXED32.DuplicateValueInMapEntry.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.FIXED32.FIXED32.MissingDefault.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.FIXED32.FIXED32.NonDefault.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.FIXED32.FIXED32.Unordered.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.FIXED64.FIXED64.Default.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.FIXED64.FIXED64.DuplicateKey.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.FIXED64.FIXED64.DuplicateKeyInMapEntry.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.FIXED64.FIXED64.DuplicateValueInMapEntry.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.FIXED64.FIXED64.MissingDefault.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.FIXED64.FIXED64.NonDefault.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.FIXED64.FIXED64.Unordered.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.INT32.DOUBLE.Default.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.INT32.DOUBLE.DuplicateKey.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.INT32.DOUBLE.DuplicateKeyInMapEntry.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.INT32.DOUBLE.DuplicateValueInMapEntry.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.INT32.DOUBLE.MissingDefault.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.INT32.DOUBLE.NonDefault.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.INT32.DOUBLE.Unordered.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.INT32.FLOAT.Default.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.INT32.FLOAT.DuplicateKey.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.INT32.FLOAT.DuplicateKeyInMapEntry.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.INT32.FLOAT.DuplicateValueInMapEntry.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.INT32.FLOAT.MissingDefault.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.INT32.FLOAT.NonDefault.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.INT32.FLOAT.Unordered.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.INT32.INT32.Default.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.INT32.INT32.DuplicateKey.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.INT32.INT32.DuplicateKeyInMapEntry.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.INT32.INT32.DuplicateValueInMapEntry.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.INT32.INT32.MissingDefault.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.INT32.INT32.NonDefault.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.INT32.INT32.Unordered.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.INT64.INT64.Default.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.INT64.INT64.DuplicateKey.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.INT64.INT64.DuplicateKeyInMapEntry.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.INT64.INT64.DuplicateValueInMapEntry.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.INT64.INT64.MissingDefault.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.INT64.INT64.NonDefault.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.INT64.INT64.Unordered.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.SFIXED32.SFIXED32.Default.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.SFIXED32.SFIXED32.DuplicateKey.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.SFIXED32.SFIXED32.DuplicateKeyInMapEntry.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.SFIXED32.SFIXED32.DuplicateValueInMapEntry.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.SFIXED32.SFIXED32.MissingDefault.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.SFIXED32.SFIXED32.NonDefault.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.SFIXED32.SFIXED32.Unordered.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.SFIXED64.SFIXED64.Default.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.SFIXED64.SFIXED64.DuplicateKey.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.SFIXED64.SFIXED64.DuplicateKeyInMapEntry.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.SFIXED64.SFIXED64.DuplicateValueInMapEntry.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.SFIXED64.SFIXED64.MissingDefault.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.SFIXED64.SFIXED64.NonDefault.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.SFIXED64.SFIXED64.Unordered.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.SINT32.SINT32.Default.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.SINT32.SINT32.DuplicateKey.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.SINT32.SINT32.DuplicateKeyInMapEntry.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.SINT32.SINT32.DuplicateValueInMapEntry.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.SINT32.SINT32.MissingDefault.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.SINT32.SINT32.NonDefault.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.SINT32.SINT32.Unordered.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.SINT64.SINT64.Default.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.SINT64.SINT64.DuplicateKey.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.SINT64.SINT64.DuplicateKeyInMapEntry.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.SINT64.SINT64.DuplicateValueInMapEntry.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.SINT64.SINT64.MissingDefault.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.SINT64.SINT64.NonDefault.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.SINT64.SINT64.Unordered.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.STRING.BYTES.Default.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.STRING.BYTES.DuplicateKey.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.STRING.BYTES.DuplicateKeyInMapEntry.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.STRING.BYTES.DuplicateValueInMapEntry.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.STRING.BYTES.MissingDefault.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.STRING.BYTES.NonDefault.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.STRING.BYTES.Unordered.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.STRING.ENUM.Default.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.STRING.ENUM.DuplicateKey.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.STRING.ENUM.DuplicateKeyInMapEntry.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.STRING.ENUM.DuplicateValueInMapEntry.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.STRING.ENUM.MissingDefault.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.STRING.ENUM.NonDefault.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.STRING.ENUM.Unordered.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.STRING.MESSAGE.Default.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.STRING.MESSAGE.DuplicateKey.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.STRING.MESSAGE.DuplicateKeyInMapEntry.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.STRING.MESSAGE.DuplicateValueInMapEntry.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.STRING.MESSAGE.MergeValue.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.STRING.MESSAGE.MissingDefault.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.STRING.MESSAGE.NonDefault.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.STRING.MESSAGE.Unordered.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.STRING.STRING.Default.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.STRING.STRING.DuplicateKey.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.STRING.STRING.DuplicateKeyInMapEntry.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.STRING.STRING.DuplicateValueInMapEntry.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.STRING.STRING.MissingDefault.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.STRING.STRING.NonDefault.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.STRING.STRING.Unordered.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.UINT32.UINT32.Default.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.UINT32.UINT32.DuplicateKey.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.UINT32.UINT32.DuplicateKeyInMapEntry.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.UINT32.UINT32.DuplicateValueInMapEntry.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.UINT32.UINT32.MissingDefault.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.UINT32.UINT32.NonDefault.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.UINT32.UINT32.Unordered.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.UINT64.UINT64.Default.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.UINT64.UINT64.DuplicateKey.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.UINT64.UINT64.DuplicateKeyInMapEntry.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.UINT64.UINT64.DuplicateValueInMapEntry.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.UINT64.UINT64.MissingDefault.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.UINT64.UINT64.NonDefault.JsonOutput + Required.Proto3.ProtobufInput.ValidDataMap.UINT64.UINT64.Unordered.JsonOutput + Required.Proto3.ProtobufInput.ValidDataOneof.BOOL.DefaultValue.JsonOutput + Required.Proto3.ProtobufInput.ValidDataOneof.BOOL.MultipleValuesForDifferentField.JsonOutput + Required.Proto3.ProtobufInput.ValidDataOneof.BOOL.MultipleValuesForSameField.JsonOutput + Required.Proto3.ProtobufInput.ValidDataOneof.BOOL.NonDefaultValue.JsonOutput + Required.Proto3.ProtobufInput.ValidDataOneof.BYTES.DefaultValue.JsonOutput + Required.Proto3.ProtobufInput.ValidDataOneof.BYTES.MultipleValuesForDifferentField.JsonOutput + Required.Proto3.ProtobufInput.ValidDataOneof.BYTES.MultipleValuesForSameField.JsonOutput + Required.Proto3.ProtobufInput.ValidDataOneof.BYTES.NonDefaultValue.JsonOutput + Required.Proto3.ProtobufInput.ValidDataOneof.DOUBLE.DefaultValue.JsonOutput + Required.Proto3.ProtobufInput.ValidDataOneof.DOUBLE.MultipleValuesForDifferentField.JsonOutput + Required.Proto3.ProtobufInput.ValidDataOneof.DOUBLE.MultipleValuesForSameField.JsonOutput + Required.Proto3.ProtobufInput.ValidDataOneof.DOUBLE.NonDefaultValue.JsonOutput + Required.Proto3.ProtobufInput.ValidDataOneof.ENUM.DefaultValue.JsonOutput + Required.Proto3.ProtobufInput.ValidDataOneof.ENUM.MultipleValuesForDifferentField.JsonOutput + Required.Proto3.ProtobufInput.ValidDataOneof.ENUM.MultipleValuesForSameField.JsonOutput + Required.Proto3.ProtobufInput.ValidDataOneof.ENUM.NonDefaultValue.JsonOutput + Required.Proto3.ProtobufInput.ValidDataOneof.FLOAT.DefaultValue.JsonOutput + Required.Proto3.ProtobufInput.ValidDataOneof.FLOAT.MultipleValuesForDifferentField.JsonOutput + Required.Proto3.ProtobufInput.ValidDataOneof.FLOAT.MultipleValuesForSameField.JsonOutput + Required.Proto3.ProtobufInput.ValidDataOneof.FLOAT.NonDefaultValue.JsonOutput + Required.Proto3.ProtobufInput.ValidDataOneof.MESSAGE.DefaultValue.JsonOutput + Required.Proto3.ProtobufInput.ValidDataOneof.MESSAGE.Merge.JsonOutput + Required.Proto3.ProtobufInput.ValidDataOneof.MESSAGE.MultipleValuesForDifferentField.JsonOutput + Required.Proto3.ProtobufInput.ValidDataOneof.MESSAGE.MultipleValuesForSameField.JsonOutput + Required.Proto3.ProtobufInput.ValidDataOneof.MESSAGE.NonDefaultValue.JsonOutput + Required.Proto3.ProtobufInput.ValidDataOneof.STRING.DefaultValue.JsonOutput + Required.Proto3.ProtobufInput.ValidDataOneof.STRING.MultipleValuesForDifferentField.JsonOutput + Required.Proto3.ProtobufInput.ValidDataOneof.STRING.MultipleValuesForSameField.JsonOutput + Required.Proto3.ProtobufInput.ValidDataOneof.STRING.NonDefaultValue.JsonOutput + Required.Proto3.ProtobufInput.ValidDataOneof.UINT32.DefaultValue.JsonOutput + Required.Proto3.ProtobufInput.ValidDataOneof.UINT32.MultipleValuesForDifferentField.JsonOutput + Required.Proto3.ProtobufInput.ValidDataOneof.UINT32.MultipleValuesForSameField.JsonOutput + Required.Proto3.ProtobufInput.ValidDataOneof.UINT32.NonDefaultValue.JsonOutput + Required.Proto3.ProtobufInput.ValidDataOneof.UINT64.DefaultValue.JsonOutput + Required.Proto3.ProtobufInput.ValidDataOneof.UINT64.MultipleValuesForDifferentField.JsonOutput + Required.Proto3.ProtobufInput.ValidDataOneof.UINT64.MultipleValuesForSameField.JsonOutput + Required.Proto3.ProtobufInput.ValidDataOneof.UINT64.NonDefaultValue.JsonOutput + Required.Proto3.ProtobufInput.ValidDataRepeated.BOOL.PackedInput.JsonOutput + Required.Proto3.ProtobufInput.ValidDataRepeated.BOOL.UnpackedInput.JsonOutput + Required.Proto3.ProtobufInput.ValidDataRepeated.BYTES.JsonOutput + Required.Proto3.ProtobufInput.ValidDataRepeated.DOUBLE.PackedInput.JsonOutput + Required.Proto3.ProtobufInput.ValidDataRepeated.DOUBLE.UnpackedInput.JsonOutput + Required.Proto3.ProtobufInput.ValidDataRepeated.ENUM.PackedInput.JsonOutput + Required.Proto3.ProtobufInput.ValidDataRepeated.ENUM.UnpackedInput.JsonOutput + Required.Proto3.ProtobufInput.ValidDataRepeated.FIXED32.PackedInput.JsonOutput + Required.Proto3.ProtobufInput.ValidDataRepeated.FIXED32.UnpackedInput.JsonOutput + Required.Proto3.ProtobufInput.ValidDataRepeated.FIXED64.PackedInput.JsonOutput + Required.Proto3.ProtobufInput.ValidDataRepeated.FIXED64.UnpackedInput.JsonOutput + Required.Proto3.ProtobufInput.ValidDataRepeated.FLOAT.PackedInput.JsonOutput + Required.Proto3.ProtobufInput.ValidDataRepeated.FLOAT.UnpackedInput.JsonOutput + Required.Proto3.ProtobufInput.ValidDataRepeated.INT32.PackedInput.JsonOutput + Required.Proto3.ProtobufInput.ValidDataRepeated.INT32.UnpackedInput.JsonOutput + Required.Proto3.ProtobufInput.ValidDataRepeated.INT64.PackedInput.JsonOutput + Required.Proto3.ProtobufInput.ValidDataRepeated.INT64.UnpackedInput.JsonOutput + Required.Proto3.ProtobufInput.ValidDataRepeated.MESSAGE.JsonOutput + Required.Proto3.ProtobufInput.ValidDataRepeated.SFIXED32.PackedInput.JsonOutput + Required.Proto3.ProtobufInput.ValidDataRepeated.SFIXED32.UnpackedInput.JsonOutput + Required.Proto3.ProtobufInput.ValidDataRepeated.SFIXED64.PackedInput.JsonOutput + Required.Proto3.ProtobufInput.ValidDataRepeated.SFIXED64.UnpackedInput.JsonOutput + Required.Proto3.ProtobufInput.ValidDataRepeated.SINT32.PackedInput.JsonOutput + Required.Proto3.ProtobufInput.ValidDataRepeated.SINT32.UnpackedInput.JsonOutput + Required.Proto3.ProtobufInput.ValidDataRepeated.SINT64.PackedInput.JsonOutput + Required.Proto3.ProtobufInput.ValidDataRepeated.SINT64.UnpackedInput.JsonOutput + Required.Proto3.ProtobufInput.ValidDataRepeated.STRING.JsonOutput + Required.Proto3.ProtobufInput.ValidDataRepeated.UINT32.PackedInput.JsonOutput + Required.Proto3.ProtobufInput.ValidDataRepeated.UINT32.UnpackedInput.JsonOutput + Required.Proto3.ProtobufInput.ValidDataRepeated.UINT64.PackedInput.JsonOutput + Required.Proto3.ProtobufInput.ValidDataRepeated.UINT64.UnpackedInput.JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.BOOL[0].JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.BOOL[1].JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.BOOL[2].JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.BOOL[3].JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.BOOL[4].JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.BOOL[5].JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.BOOL[6].JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.BYTES[0].JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.BYTES[1].JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.BYTES[2].JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.BYTES[3].JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.DOUBLE[0].JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.DOUBLE[1].JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.DOUBLE[2].JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.DOUBLE[3].JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.ENUM[0].JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.ENUM[1].JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.ENUM[2].JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.ENUM[3].JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.ENUM[4].JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.ENUM[5].JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.FIXED32[0].JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.FIXED32[1].JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.FIXED32[2].JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.FIXED64[0].JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.FIXED64[1].JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.FIXED64[2].JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.FLOAT[0].JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.FLOAT[1].JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.FLOAT[2].JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.FLOAT[3].JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.FLOAT[4].JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.INT32[0].JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.INT32[1].JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.INT32[2].JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.INT32[3].JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.INT32[4].JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.INT32[5].JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.INT32[6].JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.INT32[7].JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.INT32[8].JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.INT32[9].JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.INT64[0].JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.INT64[1].JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.INT64[2].JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.INT64[3].JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.MESSAGE[0].JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.MESSAGE[1].JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.SFIXED32[0].JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.SFIXED32[1].JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.SFIXED32[2].JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.SFIXED32[3].JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.SFIXED64[0].JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.SFIXED64[1].JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.SFIXED64[2].JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.SFIXED64[3].JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.SINT32[0].JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.SINT32[1].JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.SINT32[2].JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.SINT32[3].JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.SINT32[4].JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.SINT64[0].JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.SINT64[1].JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.SINT64[2].JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.SINT64[3].JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.STRING[0].JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.STRING[1].JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.STRING[2].JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.STRING[3].JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.STRING[4].JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.STRING[5].JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.STRING[6].JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.UINT32[0].JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.UINT32[1].JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.UINT32[2].JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.UINT32[3].JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.UINT32[4].JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.UINT32[5].JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.UINT32[6].JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.UINT32[7].JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.UINT32[8].JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.UINT32[9].JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.UINT64[0].JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.UINT64[1].JsonOutput + Required.Proto3.ProtobufInput.ValidDataScalar.UINT64[2].JsonOutput + Required.Proto3.TimestampProtoInputTooLarge.JsonOutput + Required.Proto3.TimestampProtoInputTooSmall.JsonOutput \ No newline at end of file diff --git a/conformance/text_format_failure_list_rust_cc.txt b/conformance/text_format_failure_list_rust_cc.txt index e69de29bb2d1d..bb9866c1051ca 100644 --- a/conformance/text_format_failure_list_rust_cc.txt +++ b/conformance/text_format_failure_list_rust_cc.txt @@ -0,0 +1,9 @@ +# All TextFormatOutput tests currently fail and can't be skipped yet. b/285468558 + Recommended.Proto3.ProtobufInput.GroupUnknownFields_Drop.TextFormatOutput + Recommended.Proto3.ProtobufInput.GroupUnknownFields_Print.TextFormatOutput + Recommended.Proto3.ProtobufInput.MessageUnknownFields_Drop.TextFormatOutput + Recommended.Proto3.ProtobufInput.MessageUnknownFields_Print.TextFormatOutput + Recommended.Proto3.ProtobufInput.RepeatedUnknownFields_Drop.TextFormatOutput + Recommended.Proto3.ProtobufInput.RepeatedUnknownFields_Print.TextFormatOutput + Recommended.Proto3.ProtobufInput.ScalarUnknownFields_Drop.TextFormatOutput + Recommended.Proto3.ProtobufInput.ScalarUnknownFields_Print.TextFormatOutput \ No newline at end of file diff --git a/conformance/text_format_failure_list_rust_upb.txt b/conformance/text_format_failure_list_rust_upb.txt index e69de29bb2d1d..bb9866c1051ca 100644 --- a/conformance/text_format_failure_list_rust_upb.txt +++ b/conformance/text_format_failure_list_rust_upb.txt @@ -0,0 +1,9 @@ +# All TextFormatOutput tests currently fail and can't be skipped yet. b/285468558 + Recommended.Proto3.ProtobufInput.GroupUnknownFields_Drop.TextFormatOutput + Recommended.Proto3.ProtobufInput.GroupUnknownFields_Print.TextFormatOutput + Recommended.Proto3.ProtobufInput.MessageUnknownFields_Drop.TextFormatOutput + Recommended.Proto3.ProtobufInput.MessageUnknownFields_Print.TextFormatOutput + Recommended.Proto3.ProtobufInput.RepeatedUnknownFields_Drop.TextFormatOutput + Recommended.Proto3.ProtobufInput.RepeatedUnknownFields_Print.TextFormatOutput + Recommended.Proto3.ProtobufInput.ScalarUnknownFields_Drop.TextFormatOutput + Recommended.Proto3.ProtobufInput.ScalarUnknownFields_Print.TextFormatOutput \ No newline at end of file From 19c800c4f873c8a36ab597af02f16f4ac5c9220e Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Wed, 27 Dec 2023 12:29:51 -0800 Subject: [PATCH 109/255] Fix warning from missing (void) on a 0-arg function. PiperOrigin-RevId: 594080778 --- upb_generator/upbdev.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/upb_generator/upbdev.c b/upb_generator/upbdev.c index ab67bf461db46..1a48621a9bec8 100644 --- a/upb_generator/upbdev.c +++ b/upb_generator/upbdev.c @@ -112,6 +112,6 @@ void upbdev_ProcessStdout(const char* buf, size_t size, upb_Arena* arena, } } -upb_Arena* upbdev_Arena_New() { return upb_Arena_New(); } +upb_Arena* upbdev_Arena_New(void) { return upb_Arena_New(); } void upbdev_Status_Clear(upb_Status* status) { upb_Status_Clear(status); } From 27eae8f4049cff8afd4ecdc7c9f697a8ef4ef08c Mon Sep 17 00:00:00 2001 From: Eric Salo Date: Wed, 27 Dec 2023 13:22:22 -0800 Subject: [PATCH 110/255] upb: delete mini_table/types.h PiperOrigin-RevId: 594089137 --- upb/mini_descriptor/decode.h | 1 + upb/mini_descriptor/link.h | 5 ++++- upb/mini_table/BUILD | 2 -- upb/mini_table/enum.h | 3 ++- upb/mini_table/extension.h | 5 ++++- upb/mini_table/field.h | 3 ++- upb/mini_table/file.h | 6 +++++- upb/mini_table/message.h | 5 ++++- upb/mini_table/sub.h | 5 ++++- upb/mini_table/types.h | 21 --------------------- upb/test/fuzz_util.h | 3 ++- 11 files changed, 28 insertions(+), 31 deletions(-) delete mode 100644 upb/mini_table/types.h diff --git a/upb/mini_descriptor/decode.h b/upb/mini_descriptor/decode.h index c73a44a5a0c26..ca0afc04d0171 100644 --- a/upb/mini_descriptor/decode.h +++ b/upb/mini_descriptor/decode.h @@ -10,6 +10,7 @@ #include "upb/base/status.h" #include "upb/mem/arena.h" +#include "upb/mini_table/extension.h" #include "upb/mini_table/sub.h" // Export the newer headers, for legacy users. New users should include the diff --git a/upb/mini_descriptor/link.h b/upb/mini_descriptor/link.h index 3326e06fc38c0..3e880fdd8784c 100644 --- a/upb/mini_descriptor/link.h +++ b/upb/mini_descriptor/link.h @@ -18,7 +18,10 @@ #include "upb/base/status.h" #include "upb/mem/arena.h" -#include "upb/mini_table/types.h" +#include "upb/mini_table/enum.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" diff --git a/upb/mini_table/BUILD b/upb/mini_table/BUILD index 7fb1c1693ebf7..71de9f2b5da82 100644 --- a/upb/mini_table/BUILD +++ b/upb/mini_table/BUILD @@ -24,7 +24,6 @@ cc_library( "file.h", "message.h", "sub.h", - "types.h", ], copts = UPB_DEFAULT_COPTS, visibility = ["//visibility:public"], @@ -55,7 +54,6 @@ cc_library( visibility = ["//visibility:public"], deps = [ "//upb:base", - "//upb:hash", "//upb:mem", "//upb:port", ], diff --git a/upb/mini_table/enum.h b/upb/mini_table/enum.h index 34656d07061b5..cad31ec253c70 100644 --- a/upb/mini_table/enum.h +++ b/upb/mini_table/enum.h @@ -11,11 +11,12 @@ #include #include "upb/mini_table/internal/enum.h" -#include "upb/mini_table/types.h" // IWYU pragma: export // Must be last #include "upb/port/def.inc" +typedef struct upb_MiniTableEnum upb_MiniTableEnum; + #ifdef __cplusplus extern "C" { #endif diff --git a/upb/mini_table/extension.h b/upb/mini_table/extension.h index 341dff64d1b88..58a71b60c4a3b 100644 --- a/upb/mini_table/extension.h +++ b/upb/mini_table/extension.h @@ -10,12 +10,15 @@ #include +#include "upb/mini_table/field.h" #include "upb/mini_table/internal/extension.h" -#include "upb/mini_table/types.h" // IWYU pragma: export +#include "upb/mini_table/message.h" // Must be last. #include "upb/port/def.inc" +typedef struct upb_MiniTableExtension upb_MiniTableExtension; + #ifdef __cplusplus extern "C" { #endif diff --git a/upb/mini_table/field.h b/upb/mini_table/field.h index c764164f401f8..1df96cecc3838 100644 --- a/upb/mini_table/field.h +++ b/upb/mini_table/field.h @@ -12,11 +12,12 @@ #include "upb/base/descriptor_constants.h" #include "upb/mini_table/internal/field.h" -#include "upb/mini_table/types.h" // IWYU pragma: export // Must be last. #include "upb/port/def.inc" +typedef struct upb_MiniTableField upb_MiniTableField; + #ifdef __cplusplus extern "C" { #endif diff --git a/upb/mini_table/file.h b/upb/mini_table/file.h index bae16ba340570..bc109eb0ebdd2 100644 --- a/upb/mini_table/file.h +++ b/upb/mini_table/file.h @@ -8,12 +8,16 @@ #ifndef UPB_MINI_TABLE_FILE_H_ #define UPB_MINI_TABLE_FILE_H_ +#include "upb/mini_table/enum.h" +#include "upb/mini_table/extension.h" #include "upb/mini_table/internal/file.h" -#include "upb/mini_table/types.h" // IWYU pragma: export +#include "upb/mini_table/message.h" // Must be last. #include "upb/port/def.inc" +typedef struct upb_MiniTableFile upb_MiniTableFile; + #ifdef __cplusplus extern "C" { #endif diff --git a/upb/mini_table/message.h b/upb/mini_table/message.h index 986e429dcdc37..3a1517c13e731 100644 --- a/upb/mini_table/message.h +++ b/upb/mini_table/message.h @@ -8,12 +8,15 @@ #ifndef UPB_MINI_TABLE_MESSAGE_H_ #define UPB_MINI_TABLE_MESSAGE_H_ +#include "upb/mini_table/enum.h" +#include "upb/mini_table/field.h" #include "upb/mini_table/internal/message.h" -#include "upb/mini_table/types.h" // IWYU pragma: export // Must be last. #include "upb/port/def.inc" +typedef struct upb_MiniTable upb_MiniTable; + #ifdef __cplusplus extern "C" { #endif diff --git a/upb/mini_table/sub.h b/upb/mini_table/sub.h index e5cd522583613..c2798a18e8332 100644 --- a/upb/mini_table/sub.h +++ b/upb/mini_table/sub.h @@ -8,12 +8,15 @@ #ifndef UPB_MINI_TABLE_SUB_H_ #define UPB_MINI_TABLE_SUB_H_ +#include "upb/mini_table/enum.h" #include "upb/mini_table/internal/sub.h" -#include "upb/mini_table/types.h" // IWYU pragma: export +#include "upb/mini_table/message.h" // Must be last. #include "upb/port/def.inc" +typedef union upb_MiniTableSub upb_MiniTableSub; + #ifdef __cplusplus extern "C" { #endif diff --git a/upb/mini_table/types.h b/upb/mini_table/types.h deleted file mode 100644 index ec82342c17cfa..0000000000000 --- a/upb/mini_table/types.h +++ /dev/null @@ -1,21 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#ifndef UPB_MINI_TABLE_TYPES_H_ -#define UPB_MINI_TABLE_TYPES_H_ - -// Minitable types are recursively defined so declare them all together here. - -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; - -#endif /* UPB_MINI_TABLE_TYPES_H_ */ diff --git a/upb/test/fuzz_util.h b/upb/test/fuzz_util.h index 72bf31ec82454..8e585d8124c9d 100644 --- a/upb/test/fuzz_util.h +++ b/upb/test/fuzz_util.h @@ -11,8 +11,9 @@ #include #include +#include "upb/mem/arena.h" #include "upb/mini_table/extension_registry.h" -// #include "upb/mini_table/types.h" +#include "upb/mini_table/message.h" namespace upb { namespace fuzz { From 9b4aff2a43beaee287429a190268f029b4608657 Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Wed, 27 Dec 2023 21:35:01 +0000 Subject: [PATCH 111/255] Auto-generate files after cl/594089137 --- php/ext/google/protobuf/php-upb.h | 321 +++++++++++++------------- ruby/ext/google/protobuf_c/ruby-upb.h | 321 +++++++++++++------------- 2 files changed, 318 insertions(+), 324 deletions(-) diff --git a/php/ext/google/protobuf/php-upb.h b/php/ext/google/protobuf/php-upb.h index 153345b4ff4ea..e048e505a2485 100644 --- a/php/ext/google/protobuf/php-upb.h +++ b/php/ext/google/protobuf/php-upb.h @@ -1009,8 +1009,84 @@ UPB_API void* upb_Array_MutableDataPtr(upb_Array* arr); #define UPB_MINI_TABLE_MESSAGE_H_ -#ifndef UPB_MINI_TABLE_INTERNAL_MESSAGE_H_ -#define UPB_MINI_TABLE_INTERNAL_MESSAGE_H_ +#ifndef UPB_MINI_TABLE_ENUM_H_ +#define UPB_MINI_TABLE_ENUM_H_ + +#include + + +#ifndef UPB_MINI_TABLE_INTERNAL_ENUM_H_ +#define UPB_MINI_TABLE_INTERNAL_ENUM_H_ + +#include + +// Must be last. + +struct upb_MiniTableEnum { + uint32_t UPB_PRIVATE(mask_limit); // Highest that can be tested with mask. + uint32_t UPB_PRIVATE(value_count); // Number of values after the bitfield. + uint32_t UPB_PRIVATE(data)[]; // Bitmask + enumerated values follow. +}; + +#ifdef __cplusplus +extern "C" { +#endif + +UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableEnum_CheckValue)( + const struct upb_MiniTableEnum* e, uint32_t val) { + if (UPB_LIKELY(val < 64)) { + const uint64_t mask = + e->UPB_PRIVATE(data)[0] | ((uint64_t)e->UPB_PRIVATE(data)[1] << 32); + const uint64_t bit = 1ULL << val; + return (mask & bit) != 0; + } + if (UPB_LIKELY(val < e->UPB_PRIVATE(mask_limit))) { + const uint32_t mask = e->UPB_PRIVATE(data)[val / 32]; + const uint32_t bit = 1ULL << (val % 32); + return (mask & bit) != 0; + } + + // OPT: binary search long lists? + const uint32_t* start = + &e->UPB_PRIVATE(data)[e->UPB_PRIVATE(mask_limit) / 32]; + const uint32_t* limit = &e->UPB_PRIVATE( + data)[e->UPB_PRIVATE(mask_limit) / 32 + e->UPB_PRIVATE(value_count)]; + for (const uint32_t* p = start; p < limit; p++) { + if (*p == val) return true; + } + return false; +} + +#ifdef __cplusplus +} /* extern "C" */ +#endif + + +#endif /* UPB_MINI_TABLE_INTERNAL_ENUM_H_ */ + +// Must be last + +typedef struct upb_MiniTableEnum upb_MiniTableEnum; + +#ifdef __cplusplus +extern "C" { +#endif + +// Validates enum value against range defined by enum mini table. +UPB_INLINE bool upb_MiniTableEnum_CheckValue(const upb_MiniTableEnum* e, + uint32_t val) { + return UPB_PRIVATE(_upb_MiniTableEnum_CheckValue)(e, val); +} + +#ifdef __cplusplus +} /* extern "C" */ +#endif + + +#endif /* UPB_MINI_TABLE_ENUM_H_ */ + +#ifndef UPB_MINI_TABLE_FIELD_H_ +#define UPB_MINI_TABLE_FIELD_H_ #include @@ -1290,6 +1366,80 @@ UPB_INLINE size_t UPB_PRIVATE(_upb_MiniTableField_ElemSizeLg2)( #endif /* UPB_MINI_TABLE_INTERNAL_FIELD_H_ */ +// Must be last. + +typedef struct upb_MiniTableField upb_MiniTableField; + +#ifdef __cplusplus +extern "C" { +#endif + +UPB_API_INLINE upb_CType upb_MiniTableField_CType(const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_CType)(f); +} + +UPB_API_INLINE bool upb_MiniTableField_HasPresence( + const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_HasPresence)(f); +} + +UPB_API_INLINE bool upb_MiniTableField_IsArray(const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_IsArray)(f); +} + +UPB_API_INLINE bool upb_MiniTableField_IsClosedEnum( + const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_IsClosedEnum)(f); +} + +UPB_API_INLINE bool upb_MiniTableField_IsExtension( + const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_IsExtension)(f); +} + +UPB_API_INLINE bool upb_MiniTableField_IsInOneof(const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_IsInOneof)(f); +} + +UPB_API_INLINE bool upb_MiniTableField_IsMap(const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_IsMap)(f); +} + +UPB_API_INLINE bool upb_MiniTableField_IsPacked(const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_IsPacked)(f); +} + +UPB_API_INLINE bool upb_MiniTableField_IsScalar(const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_IsScalar)(f); +} + +UPB_API_INLINE bool upb_MiniTableField_IsSubMessage( + const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_IsSubMessage)(f); +} + +UPB_API_INLINE uint32_t upb_MiniTableField_Number(const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_Number)(f); +} + +UPB_API_INLINE upb_FieldType +upb_MiniTableField_Type(const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_Type)(f); +} + +#ifdef __cplusplus +} /* extern "C" */ +#endif + + +#endif /* UPB_MINI_TABLE_FIELD_H_ */ + +#ifndef UPB_MINI_TABLE_INTERNAL_MESSAGE_H_ +#define UPB_MINI_TABLE_INTERNAL_MESSAGE_H_ + +#include + + #ifndef UPB_MINI_TABLE_INTERNAL_SUB_H_ #define UPB_MINI_TABLE_INTERNAL_SUB_H_ @@ -1479,22 +1629,9 @@ UPB_PRIVATE(_upb_MiniTable_RequiredMask)(const struct upb_MiniTable* m) { #endif /* UPB_MINI_TABLE_INTERNAL_MESSAGE_H_ */ -#ifndef UPB_MINI_TABLE_TYPES_H_ -#define UPB_MINI_TABLE_TYPES_H_ - -// Minitable types are recursively defined so declare them all together here. +// Must be last. 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; - -#endif /* UPB_MINI_TABLE_TYPES_H_ */ - -// Must be last. #ifdef __cplusplus extern "C" { @@ -1654,6 +1791,8 @@ UPB_INLINE void UPB_PRIVATE(_upb_MiniTableExtension_SetSubMessage)( // Must be last. +typedef struct upb_MiniTableExtension upb_MiniTableExtension; + #ifdef __cplusplus extern "C" { #endif @@ -2391,78 +2530,6 @@ bool UPB_PRIVATE(_upb_Message_Realloc)(upb_Message* msg, size_t need, #endif /* UPB_MESSAGE_INTERNAL_H_ */ -#ifndef UPB_MINI_TABLE_FIELD_H_ -#define UPB_MINI_TABLE_FIELD_H_ - -#include - - -// Must be last. - -#ifdef __cplusplus -extern "C" { -#endif - -UPB_API_INLINE upb_CType upb_MiniTableField_CType(const upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTableField_CType)(f); -} - -UPB_API_INLINE bool upb_MiniTableField_HasPresence( - const upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTableField_HasPresence)(f); -} - -UPB_API_INLINE bool upb_MiniTableField_IsArray(const upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTableField_IsArray)(f); -} - -UPB_API_INLINE bool upb_MiniTableField_IsClosedEnum( - const upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTableField_IsClosedEnum)(f); -} - -UPB_API_INLINE bool upb_MiniTableField_IsExtension( - const upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTableField_IsExtension)(f); -} - -UPB_API_INLINE bool upb_MiniTableField_IsInOneof(const upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTableField_IsInOneof)(f); -} - -UPB_API_INLINE bool upb_MiniTableField_IsMap(const upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTableField_IsMap)(f); -} - -UPB_API_INLINE bool upb_MiniTableField_IsPacked(const upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTableField_IsPacked)(f); -} - -UPB_API_INLINE bool upb_MiniTableField_IsScalar(const upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTableField_IsScalar)(f); -} - -UPB_API_INLINE bool upb_MiniTableField_IsSubMessage( - const upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTableField_IsSubMessage)(f); -} - -UPB_API_INLINE uint32_t upb_MiniTableField_Number(const upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTableField_Number)(f); -} - -UPB_API_INLINE upb_FieldType -upb_MiniTableField_Type(const upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTableField_Type)(f); -} - -#ifdef __cplusplus -} /* extern "C" */ -#endif - - -#endif /* UPB_MINI_TABLE_FIELD_H_ */ - // Must be last. #if defined(__GNUC__) && !defined(__clang__) @@ -2912,86 +2979,14 @@ UPB_INLINE void UPB_PRIVATE(_upb_Array_Set)(upb_Array* array, size_t i, #endif /* UPB_MESSAGE_INTERNAL_ARRAY_H_ */ -#ifndef UPB_MINI_TABLE_ENUM_H_ -#define UPB_MINI_TABLE_ENUM_H_ - -#include - - -#ifndef UPB_MINI_TABLE_INTERNAL_ENUM_H_ -#define UPB_MINI_TABLE_INTERNAL_ENUM_H_ - -#include - -// Must be last. - -struct upb_MiniTableEnum { - uint32_t UPB_PRIVATE(mask_limit); // Highest that can be tested with mask. - uint32_t UPB_PRIVATE(value_count); // Number of values after the bitfield. - uint32_t UPB_PRIVATE(data)[]; // Bitmask + enumerated values follow. -}; - -#ifdef __cplusplus -extern "C" { -#endif - -UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableEnum_CheckValue)( - const struct upb_MiniTableEnum* e, uint32_t val) { - if (UPB_LIKELY(val < 64)) { - const uint64_t mask = - e->UPB_PRIVATE(data)[0] | ((uint64_t)e->UPB_PRIVATE(data)[1] << 32); - const uint64_t bit = 1ULL << val; - return (mask & bit) != 0; - } - if (UPB_LIKELY(val < e->UPB_PRIVATE(mask_limit))) { - const uint32_t mask = e->UPB_PRIVATE(data)[val / 32]; - const uint32_t bit = 1ULL << (val % 32); - return (mask & bit) != 0; - } - - // OPT: binary search long lists? - const uint32_t* start = - &e->UPB_PRIVATE(data)[e->UPB_PRIVATE(mask_limit) / 32]; - const uint32_t* limit = &e->UPB_PRIVATE( - data)[e->UPB_PRIVATE(mask_limit) / 32 + e->UPB_PRIVATE(value_count)]; - for (const uint32_t* p = start; p < limit; p++) { - if (*p == val) return true; - } - return false; -} - -#ifdef __cplusplus -} /* extern "C" */ -#endif - - -#endif /* UPB_MINI_TABLE_INTERNAL_ENUM_H_ */ - -// Must be last - -#ifdef __cplusplus -extern "C" { -#endif - -// Validates enum value against range defined by enum mini table. -UPB_INLINE bool upb_MiniTableEnum_CheckValue(const upb_MiniTableEnum* e, - uint32_t val) { - return UPB_PRIVATE(_upb_MiniTableEnum_CheckValue)(e, val); -} - -#ifdef __cplusplus -} /* extern "C" */ -#endif - - -#endif /* UPB_MINI_TABLE_ENUM_H_ */ - #ifndef UPB_MINI_TABLE_SUB_H_ #define UPB_MINI_TABLE_SUB_H_ // Must be last. +typedef union upb_MiniTableSub upb_MiniTableSub; + #ifdef __cplusplus extern "C" { #endif @@ -3844,6 +3839,8 @@ UPB_INLINE const struct upb_MiniTable* UPB_PRIVATE(_upb_MiniTableFile_Message)( // Must be last. +typedef struct upb_MiniTableFile upb_MiniTableFile; + #ifdef __cplusplus extern "C" { #endif diff --git a/ruby/ext/google/protobuf_c/ruby-upb.h b/ruby/ext/google/protobuf_c/ruby-upb.h index 4e0c0977002a1..55f35955d2e84 100755 --- a/ruby/ext/google/protobuf_c/ruby-upb.h +++ b/ruby/ext/google/protobuf_c/ruby-upb.h @@ -1011,8 +1011,84 @@ UPB_API void* upb_Array_MutableDataPtr(upb_Array* arr); #define UPB_MINI_TABLE_MESSAGE_H_ -#ifndef UPB_MINI_TABLE_INTERNAL_MESSAGE_H_ -#define UPB_MINI_TABLE_INTERNAL_MESSAGE_H_ +#ifndef UPB_MINI_TABLE_ENUM_H_ +#define UPB_MINI_TABLE_ENUM_H_ + +#include + + +#ifndef UPB_MINI_TABLE_INTERNAL_ENUM_H_ +#define UPB_MINI_TABLE_INTERNAL_ENUM_H_ + +#include + +// Must be last. + +struct upb_MiniTableEnum { + uint32_t UPB_PRIVATE(mask_limit); // Highest that can be tested with mask. + uint32_t UPB_PRIVATE(value_count); // Number of values after the bitfield. + uint32_t UPB_PRIVATE(data)[]; // Bitmask + enumerated values follow. +}; + +#ifdef __cplusplus +extern "C" { +#endif + +UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableEnum_CheckValue)( + const struct upb_MiniTableEnum* e, uint32_t val) { + if (UPB_LIKELY(val < 64)) { + const uint64_t mask = + e->UPB_PRIVATE(data)[0] | ((uint64_t)e->UPB_PRIVATE(data)[1] << 32); + const uint64_t bit = 1ULL << val; + return (mask & bit) != 0; + } + if (UPB_LIKELY(val < e->UPB_PRIVATE(mask_limit))) { + const uint32_t mask = e->UPB_PRIVATE(data)[val / 32]; + const uint32_t bit = 1ULL << (val % 32); + return (mask & bit) != 0; + } + + // OPT: binary search long lists? + const uint32_t* start = + &e->UPB_PRIVATE(data)[e->UPB_PRIVATE(mask_limit) / 32]; + const uint32_t* limit = &e->UPB_PRIVATE( + data)[e->UPB_PRIVATE(mask_limit) / 32 + e->UPB_PRIVATE(value_count)]; + for (const uint32_t* p = start; p < limit; p++) { + if (*p == val) return true; + } + return false; +} + +#ifdef __cplusplus +} /* extern "C" */ +#endif + + +#endif /* UPB_MINI_TABLE_INTERNAL_ENUM_H_ */ + +// Must be last + +typedef struct upb_MiniTableEnum upb_MiniTableEnum; + +#ifdef __cplusplus +extern "C" { +#endif + +// Validates enum value against range defined by enum mini table. +UPB_INLINE bool upb_MiniTableEnum_CheckValue(const upb_MiniTableEnum* e, + uint32_t val) { + return UPB_PRIVATE(_upb_MiniTableEnum_CheckValue)(e, val); +} + +#ifdef __cplusplus +} /* extern "C" */ +#endif + + +#endif /* UPB_MINI_TABLE_ENUM_H_ */ + +#ifndef UPB_MINI_TABLE_FIELD_H_ +#define UPB_MINI_TABLE_FIELD_H_ #include @@ -1292,6 +1368,80 @@ UPB_INLINE size_t UPB_PRIVATE(_upb_MiniTableField_ElemSizeLg2)( #endif /* UPB_MINI_TABLE_INTERNAL_FIELD_H_ */ +// Must be last. + +typedef struct upb_MiniTableField upb_MiniTableField; + +#ifdef __cplusplus +extern "C" { +#endif + +UPB_API_INLINE upb_CType upb_MiniTableField_CType(const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_CType)(f); +} + +UPB_API_INLINE bool upb_MiniTableField_HasPresence( + const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_HasPresence)(f); +} + +UPB_API_INLINE bool upb_MiniTableField_IsArray(const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_IsArray)(f); +} + +UPB_API_INLINE bool upb_MiniTableField_IsClosedEnum( + const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_IsClosedEnum)(f); +} + +UPB_API_INLINE bool upb_MiniTableField_IsExtension( + const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_IsExtension)(f); +} + +UPB_API_INLINE bool upb_MiniTableField_IsInOneof(const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_IsInOneof)(f); +} + +UPB_API_INLINE bool upb_MiniTableField_IsMap(const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_IsMap)(f); +} + +UPB_API_INLINE bool upb_MiniTableField_IsPacked(const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_IsPacked)(f); +} + +UPB_API_INLINE bool upb_MiniTableField_IsScalar(const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_IsScalar)(f); +} + +UPB_API_INLINE bool upb_MiniTableField_IsSubMessage( + const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_IsSubMessage)(f); +} + +UPB_API_INLINE uint32_t upb_MiniTableField_Number(const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_Number)(f); +} + +UPB_API_INLINE upb_FieldType +upb_MiniTableField_Type(const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_Type)(f); +} + +#ifdef __cplusplus +} /* extern "C" */ +#endif + + +#endif /* UPB_MINI_TABLE_FIELD_H_ */ + +#ifndef UPB_MINI_TABLE_INTERNAL_MESSAGE_H_ +#define UPB_MINI_TABLE_INTERNAL_MESSAGE_H_ + +#include + + #ifndef UPB_MINI_TABLE_INTERNAL_SUB_H_ #define UPB_MINI_TABLE_INTERNAL_SUB_H_ @@ -1481,22 +1631,9 @@ UPB_PRIVATE(_upb_MiniTable_RequiredMask)(const struct upb_MiniTable* m) { #endif /* UPB_MINI_TABLE_INTERNAL_MESSAGE_H_ */ -#ifndef UPB_MINI_TABLE_TYPES_H_ -#define UPB_MINI_TABLE_TYPES_H_ - -// Minitable types are recursively defined so declare them all together here. +// Must be last. 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; - -#endif /* UPB_MINI_TABLE_TYPES_H_ */ - -// Must be last. #ifdef __cplusplus extern "C" { @@ -1656,6 +1793,8 @@ UPB_INLINE void UPB_PRIVATE(_upb_MiniTableExtension_SetSubMessage)( // Must be last. +typedef struct upb_MiniTableExtension upb_MiniTableExtension; + #ifdef __cplusplus extern "C" { #endif @@ -2393,78 +2532,6 @@ bool UPB_PRIVATE(_upb_Message_Realloc)(upb_Message* msg, size_t need, #endif /* UPB_MESSAGE_INTERNAL_H_ */ -#ifndef UPB_MINI_TABLE_FIELD_H_ -#define UPB_MINI_TABLE_FIELD_H_ - -#include - - -// Must be last. - -#ifdef __cplusplus -extern "C" { -#endif - -UPB_API_INLINE upb_CType upb_MiniTableField_CType(const upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTableField_CType)(f); -} - -UPB_API_INLINE bool upb_MiniTableField_HasPresence( - const upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTableField_HasPresence)(f); -} - -UPB_API_INLINE bool upb_MiniTableField_IsArray(const upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTableField_IsArray)(f); -} - -UPB_API_INLINE bool upb_MiniTableField_IsClosedEnum( - const upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTableField_IsClosedEnum)(f); -} - -UPB_API_INLINE bool upb_MiniTableField_IsExtension( - const upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTableField_IsExtension)(f); -} - -UPB_API_INLINE bool upb_MiniTableField_IsInOneof(const upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTableField_IsInOneof)(f); -} - -UPB_API_INLINE bool upb_MiniTableField_IsMap(const upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTableField_IsMap)(f); -} - -UPB_API_INLINE bool upb_MiniTableField_IsPacked(const upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTableField_IsPacked)(f); -} - -UPB_API_INLINE bool upb_MiniTableField_IsScalar(const upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTableField_IsScalar)(f); -} - -UPB_API_INLINE bool upb_MiniTableField_IsSubMessage( - const upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTableField_IsSubMessage)(f); -} - -UPB_API_INLINE uint32_t upb_MiniTableField_Number(const upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTableField_Number)(f); -} - -UPB_API_INLINE upb_FieldType -upb_MiniTableField_Type(const upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTableField_Type)(f); -} - -#ifdef __cplusplus -} /* extern "C" */ -#endif - - -#endif /* UPB_MINI_TABLE_FIELD_H_ */ - // Must be last. #if defined(__GNUC__) && !defined(__clang__) @@ -2914,86 +2981,14 @@ UPB_INLINE void UPB_PRIVATE(_upb_Array_Set)(upb_Array* array, size_t i, #endif /* UPB_MESSAGE_INTERNAL_ARRAY_H_ */ -#ifndef UPB_MINI_TABLE_ENUM_H_ -#define UPB_MINI_TABLE_ENUM_H_ - -#include - - -#ifndef UPB_MINI_TABLE_INTERNAL_ENUM_H_ -#define UPB_MINI_TABLE_INTERNAL_ENUM_H_ - -#include - -// Must be last. - -struct upb_MiniTableEnum { - uint32_t UPB_PRIVATE(mask_limit); // Highest that can be tested with mask. - uint32_t UPB_PRIVATE(value_count); // Number of values after the bitfield. - uint32_t UPB_PRIVATE(data)[]; // Bitmask + enumerated values follow. -}; - -#ifdef __cplusplus -extern "C" { -#endif - -UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableEnum_CheckValue)( - const struct upb_MiniTableEnum* e, uint32_t val) { - if (UPB_LIKELY(val < 64)) { - const uint64_t mask = - e->UPB_PRIVATE(data)[0] | ((uint64_t)e->UPB_PRIVATE(data)[1] << 32); - const uint64_t bit = 1ULL << val; - return (mask & bit) != 0; - } - if (UPB_LIKELY(val < e->UPB_PRIVATE(mask_limit))) { - const uint32_t mask = e->UPB_PRIVATE(data)[val / 32]; - const uint32_t bit = 1ULL << (val % 32); - return (mask & bit) != 0; - } - - // OPT: binary search long lists? - const uint32_t* start = - &e->UPB_PRIVATE(data)[e->UPB_PRIVATE(mask_limit) / 32]; - const uint32_t* limit = &e->UPB_PRIVATE( - data)[e->UPB_PRIVATE(mask_limit) / 32 + e->UPB_PRIVATE(value_count)]; - for (const uint32_t* p = start; p < limit; p++) { - if (*p == val) return true; - } - return false; -} - -#ifdef __cplusplus -} /* extern "C" */ -#endif - - -#endif /* UPB_MINI_TABLE_INTERNAL_ENUM_H_ */ - -// Must be last - -#ifdef __cplusplus -extern "C" { -#endif - -// Validates enum value against range defined by enum mini table. -UPB_INLINE bool upb_MiniTableEnum_CheckValue(const upb_MiniTableEnum* e, - uint32_t val) { - return UPB_PRIVATE(_upb_MiniTableEnum_CheckValue)(e, val); -} - -#ifdef __cplusplus -} /* extern "C" */ -#endif - - -#endif /* UPB_MINI_TABLE_ENUM_H_ */ - #ifndef UPB_MINI_TABLE_SUB_H_ #define UPB_MINI_TABLE_SUB_H_ // Must be last. +typedef union upb_MiniTableSub upb_MiniTableSub; + #ifdef __cplusplus extern "C" { #endif @@ -3846,6 +3841,8 @@ UPB_INLINE const struct upb_MiniTable* UPB_PRIVATE(_upb_MiniTableFile_Message)( // Must be last. +typedef struct upb_MiniTableFile upb_MiniTableFile; + #ifdef __cplusplus extern "C" { #endif From 36bb6fb0dd67a151879c645652992ad11bcef614 Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Wed, 27 Dec 2023 14:45:36 -0800 Subject: [PATCH 112/255] Disable MacOS C++ Cmake test for now. PiperOrigin-RevId: 594102279 --- .github/workflows/test_cpp.yml | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/.github/workflows/test_cpp.yml b/.github/workflows/test_cpp.yml index a6dd8b8c028f5..a2011b18610f1 100644 --- a/.github/workflows/test_cpp.yml +++ b/.github/workflows/test_cpp.yml @@ -361,10 +361,11 @@ jobs: fail-fast: false # Don't cancel all jobs if one fails. matrix: include: - - name: MacOS CMake - os: macos-12 - flags: -DCMAKE_CXX_STANDARD=14 - cache-prefix: macos-cmake + # TODO: investigate and fix + # - name: MacOS CMake + # os: macos-12 + # flags: -DCMAKE_CXX_STANDARD=14 + # cache-prefix: macos-cmake - name: Windows CMake os: windows-2022 flags: >- From 75455eae6c5cfc8eccfcf04e6a80e3f0485f8b1e Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Wed, 27 Dec 2023 15:07:28 -0800 Subject: [PATCH 113/255] Fixed compiler warnings in the Ruby C extension. PiperOrigin-RevId: 594106078 --- ruby/ext/google/protobuf_c/convert.c | 9 ++++++--- ruby/ext/google/protobuf_c/defs.c | 6 +++--- ruby/ext/google/protobuf_c/map.c | 4 ++-- ruby/ext/google/protobuf_c/message.c | 13 ++++++++----- ruby/ext/google/protobuf_c/shared_convert.c | 6 +++--- ruby/ext/google/protobuf_c/shared_convert.h | 4 ++-- ruby/ext/google/protobuf_c/shared_message.c | 1 + 7 files changed, 25 insertions(+), 18 deletions(-) diff --git a/ruby/ext/google/protobuf_c/convert.c b/ruby/ext/google/protobuf_c/convert.c index b97c050580b8c..1fae52446f703 100644 --- a/ruby/ext/google/protobuf_c/convert.c +++ b/ruby/ext/google/protobuf_c/convert.c @@ -208,7 +208,8 @@ upb_MessageValue Convert_RubyToUpb(VALUE value, const char* name, } break; default: - break; + rb_raise(cTypeError, + "Convert_RubyToUpb(): Unexpected type %d", (int)type_info.type); } return ret; @@ -296,7 +297,8 @@ bool Msgval_IsEqual(upb_MessageValue val1, upb_MessageValue val2, if (upb_Status_IsOk(&status)) { return return_value; } else { - rb_raise(rb_eRuntimeError, upb_Status_ErrorMessage(&status)); + rb_raise(rb_eRuntimeError, "Msgval_IsEqual(): %s", + upb_Status_ErrorMessage(&status)); } } @@ -309,6 +311,7 @@ uint64_t Msgval_GetHash(upb_MessageValue val, TypeInfo type_info, if (upb_Status_IsOk(&status)) { return return_value; } else { - rb_raise(rb_eRuntimeError, upb_Status_ErrorMessage(&status)); + rb_raise(rb_eRuntimeError, "Msgval_GetHash(): %s", + upb_Status_ErrorMessage(&status)); } } diff --git a/ruby/ext/google/protobuf_c/defs.c b/ruby/ext/google/protobuf_c/defs.c index ea91853215d3c..8761b84f32b93 100644 --- a/ruby/ext/google/protobuf_c/defs.c +++ b/ruby/ext/google/protobuf_c/defs.c @@ -862,7 +862,7 @@ static VALUE FieldDescriptor_get(VALUE _self, VALUE msg_rb) { static VALUE FieldDescriptor_has(VALUE _self, VALUE msg_rb) { FieldDescriptor* self = ruby_to_FieldDescriptor(_self); const upb_MessageDef* m; - const upb_MessageDef* msg = Message_Get(msg_rb, &m); + const upb_Message* msg = Message_Get(msg_rb, &m); if (m != upb_FieldDef_ContainingType(self->fielddef)) { rb_raise(cTypeError, "has method called on wrong message type"); @@ -882,7 +882,7 @@ static VALUE FieldDescriptor_has(VALUE _self, VALUE msg_rb) { static VALUE FieldDescriptor_clear(VALUE _self, VALUE msg_rb) { FieldDescriptor* self = ruby_to_FieldDescriptor(_self); const upb_MessageDef* m; - upb_MessageDef* msg = Message_GetMutable(msg_rb, &m); + upb_Message* msg = Message_GetMutable(msg_rb, &m); if (m != upb_FieldDef_ContainingType(self->fielddef)) { rb_raise(cTypeError, "has method called on wrong message type"); @@ -903,7 +903,7 @@ static VALUE FieldDescriptor_clear(VALUE _self, VALUE msg_rb) { static VALUE FieldDescriptor_set(VALUE _self, VALUE msg_rb, VALUE value) { FieldDescriptor* self = ruby_to_FieldDescriptor(_self); const upb_MessageDef* m; - upb_MessageDef* msg = Message_GetMutable(msg_rb, &m); + upb_Message* msg = Message_GetMutable(msg_rb, &m); upb_Arena* arena = Arena_get(Message_GetArena(msg_rb)); upb_MessageValue msgval; diff --git a/ruby/ext/google/protobuf_c/map.c b/ruby/ext/google/protobuf_c/map.c index e3bd80c05964e..c0c4cb2accc01 100644 --- a/ruby/ext/google/protobuf_c/map.c +++ b/ruby/ext/google/protobuf_c/map.c @@ -212,7 +212,7 @@ static VALUE Map_merge_into_self(VALUE _self, VALUE hashmap) { Map* self = ruby_to_Map(_self); Map* other = ruby_to_Map(hashmap); upb_Arena* arena = Arena_get(self->arena); - upb_Message* self_msg = Map_GetMutable(_self); + upb_Map* self_map = Map_GetMutable(_self); Arena_fuse(other->arena, arena); @@ -225,7 +225,7 @@ static VALUE Map_merge_into_self(VALUE _self, VALUE hashmap) { size_t iter = kUpb_Map_Begin; upb_MessageValue key, val; while (upb_Map_Next(other->map, &key, &val, &iter)) { - upb_Map_Set(self_msg, key, val, arena); + upb_Map_Set(self_map, key, val, arena); } } else { rb_raise(rb_eArgError, "Unknown type merging into Map"); diff --git a/ruby/ext/google/protobuf_c/message.c b/ruby/ext/google/protobuf_c/message.c index dfb586e8e9948..d48c8c025f58b 100644 --- a/ruby/ext/google/protobuf_c/message.c +++ b/ruby/ext/google/protobuf_c/message.c @@ -488,7 +488,8 @@ static int Map_initialize_kwarg(VALUE key, VALUE val, VALUE _self) { k = Convert_RubyToUpb(key, "", map_init->key_type, NULL); if (map_init->val_type.type == kUpb_CType_Message && TYPE(val) == T_HASH) { - upb_MiniTable* t = upb_MessageDef_MiniTable(map_init->val_type.def.msgdef); + const upb_MiniTable* t = + upb_MessageDef_MiniTable(map_init->val_type.def.msgdef); upb_Message* msg = upb_Message_New(t, map_init->arena); Message_InitFromValue(msg, map_init->val_type.def.msgdef, val, map_init->arena); @@ -519,7 +520,7 @@ static upb_MessageValue MessageValue_FromValue(VALUE val, TypeInfo info, upb_Arena* arena) { if (info.type == kUpb_CType_Message) { upb_MessageValue msgval; - upb_MiniTable* t = upb_MessageDef_MiniTable(info.def.msgdef); + const upb_MiniTable* t = upb_MessageDef_MiniTable(info.def.msgdef); upb_Message* msg = upb_Message_New(t, arena); Message_InitFromValue(msg, info.def.msgdef, val, arena); msgval.msg_val = msg; @@ -635,7 +636,7 @@ static VALUE Message_initialize(int argc, VALUE* argv, VALUE _self) { Message* self = ruby_to_Message(_self); VALUE arena_rb = Arena_new(); upb_Arena* arena = Arena_get(arena_rb); - upb_MiniTable* t = upb_MessageDef_MiniTable(self->msgdef); + const upb_MiniTable* t = upb_MessageDef_MiniTable(self->msgdef); upb_Message* msg = upb_Message_New(t, arena); Message_InitPtr(_self, msg, arena_rb); @@ -675,7 +676,8 @@ bool Message_Equal(const upb_Message* m1, const upb_Message* m2, if (upb_Status_IsOk(&status)) { return return_value; } else { - rb_raise(cParseError, upb_Status_ErrorMessage(&status)); + rb_raise(cParseError, "Message_Equal(): %s", + upb_Status_ErrorMessage(&status)); } } @@ -706,7 +708,8 @@ uint64_t Message_Hash(const upb_Message* msg, const upb_MessageDef* m, if (upb_Status_IsOk(&status)) { return return_value; } else { - rb_raise(cParseError, upb_Status_ErrorMessage(&status)); + rb_raise(cParseError, "Message_Hash(): %s", + upb_Status_ErrorMessage(&status)); } } diff --git a/ruby/ext/google/protobuf_c/shared_convert.c b/ruby/ext/google/protobuf_c/shared_convert.c index d3b78e3dfae64..9116f62b15535 100644 --- a/ruby/ext/google/protobuf_c/shared_convert.c +++ b/ruby/ext/google/protobuf_c/shared_convert.c @@ -12,7 +12,7 @@ #include "shared_convert.h" bool shared_Msgval_IsEqual(upb_MessageValue val1, upb_MessageValue val2, - upb_CType type, upb_MessageDef* msgdef, + upb_CType type, const upb_MessageDef* msgdef, upb_Status* status) { switch (type) { case kUpb_CType_Bool: @@ -39,7 +39,7 @@ bool shared_Msgval_IsEqual(upb_MessageValue val1, upb_MessageValue val2, } uint64_t shared_Msgval_GetHash(upb_MessageValue val, upb_CType type, - upb_MessageDef* msgdef, uint64_t seed, + const upb_MessageDef* msgdef, uint64_t seed, upb_Status* status) { switch (type) { case kUpb_CType_Bool: @@ -61,4 +61,4 @@ uint64_t shared_Msgval_GetHash(upb_MessageValue val, upb_CType type, default: upb_Status_SetErrorMessage(status, "Internal error, unexpected type"); } -} \ No newline at end of file +} diff --git a/ruby/ext/google/protobuf_c/shared_convert.h b/ruby/ext/google/protobuf_c/shared_convert.h index e97aa365eb61f..ca1e91d57ec09 100644 --- a/ruby/ext/google/protobuf_c/shared_convert.h +++ b/ruby/ext/google/protobuf_c/shared_convert.h @@ -16,11 +16,11 @@ #include "shared_message.h" bool shared_Msgval_IsEqual(upb_MessageValue val1, upb_MessageValue val2, - upb_CType type, upb_MessageDef* msgdef, + upb_CType type, const upb_MessageDef* msgdef, upb_Status* status); uint64_t shared_Msgval_GetHash(upb_MessageValue val, upb_CType type, - upb_MessageDef* msgdef, uint64_t seed, + const upb_MessageDef* msgdef, uint64_t seed, upb_Status* status); #endif // RUBY_PROTOBUF_SHARED_CONVERT_H_ diff --git a/ruby/ext/google/protobuf_c/shared_message.c b/ruby/ext/google/protobuf_c/shared_message.c index 9e650c3c366e8..7d140fbca41a8 100644 --- a/ruby/ext/google/protobuf_c/shared_message.c +++ b/ruby/ext/google/protobuf_c/shared_message.c @@ -32,6 +32,7 @@ uint64_t shared_Message_Hash(const upb_Message* msg, const upb_MessageDef* m, } else { upb_Arena_Free(arena); upb_Status_SetErrorMessage(status, "Error calculating hash"); + return 0; } } From 4f77929203cbf33ae3a710f7370794e36912acbc Mon Sep 17 00:00:00 2001 From: Jie Luo Date: Wed, 27 Dec 2023 16:36:39 -0800 Subject: [PATCH 114/255] BREAKING CHANGE in v26: check if Timestamp is valid. Seconds should be in range [-62135596800, 253402300799] Nanos should be in range [0, 999999999] PiperOrigin-RevId: 594119545 --- .../protobuf/internal/json_format_test.py | 9 ++- .../protobuf/internal/well_known_types.py | 57 +++++++++++++++---- .../internal/well_known_types_test.py | 24 +++----- 3 files changed, 60 insertions(+), 30 deletions(-) diff --git a/python/google/protobuf/internal/json_format_test.py b/python/google/protobuf/internal/json_format_test.py index 15b376c181d93..6c4d2dac0b9ca 100644 --- a/python/google/protobuf/internal/json_format_test.py +++ b/python/google/protobuf/internal/json_format_test.py @@ -1060,7 +1060,14 @@ def testInvalidTimestamp(self): json_format.Parse, text, message) # Time bigger than maximum time. message.value.seconds = 253402300800 - self.assertRaisesRegex(OverflowError, 'date value out of range', + self.assertRaisesRegex(json_format.SerializeToJsonError, + 'Timestamp is not valid', + json_format.MessageToJson, message) + # Nanos smaller than 0 + message.value.seconds = 0 + message.value.nanos = -1 + self.assertRaisesRegex(json_format.SerializeToJsonError, + 'Timestamp is not valid', json_format.MessageToJson, message) # Lower case t does not accept. text = '{"value": "0001-01-01t00:00:00Z"}' diff --git a/python/google/protobuf/internal/well_known_types.py b/python/google/protobuf/internal/well_known_types.py index 5727bc98c2c06..59e99e05d1764 100644 --- a/python/google/protobuf/internal/well_known_types.py +++ b/python/google/protobuf/internal/well_known_types.py @@ -20,6 +20,7 @@ import calendar import collections.abc import datetime +import warnings from google.protobuf.internal import field_mask @@ -33,6 +34,8 @@ _MICROS_PER_SECOND = 1000000 _SECONDS_PER_DAY = 24 * 3600 _DURATION_SECONDS_MAX = 315576000000 +_TIMESTAMP_SECONDS_MIN = -62135596800 +_TIMESTAMP_SECONDS_MAX = 253402300799 _EPOCH_DATETIME_NAIVE = datetime.datetime(1970, 1, 1, tzinfo=None) _EPOCH_DATETIME_AWARE = _EPOCH_DATETIME_NAIVE.replace( @@ -85,10 +88,10 @@ def ToJsonString(self): and uses 3, 6 or 9 fractional digits as required to represent the exact time. Example of the return format: '1972-01-01T10:00:20.021Z' """ - nanos = self.nanos % _NANOS_PER_SECOND - total_sec = self.seconds + (self.nanos - nanos) // _NANOS_PER_SECOND - seconds = total_sec % _SECONDS_PER_DAY - days = (total_sec - seconds) // _SECONDS_PER_DAY + _CheckTimestampValid(self.seconds, self.nanos) + nanos = self.nanos + seconds = self.seconds % _SECONDS_PER_DAY + days = (self.seconds - seconds) // _SECONDS_PER_DAY dt = datetime.datetime(1970, 1, 1) + datetime.timedelta(days, seconds) result = dt.isoformat() @@ -166,6 +169,7 @@ def FromJsonString(self, value): else: seconds += (int(timezone[1:pos])*60+int(timezone[pos+1:]))*60 # Set seconds and nanos + _CheckTimestampValid(seconds, nanos) self.seconds = int(seconds) self.nanos = int(nanos) @@ -175,39 +179,53 @@ def GetCurrentTime(self): def ToNanoseconds(self): """Converts Timestamp to nanoseconds since epoch.""" + _CheckTimestampValid(self.seconds, self.nanos) return self.seconds * _NANOS_PER_SECOND + self.nanos def ToMicroseconds(self): """Converts Timestamp to microseconds since epoch.""" + _CheckTimestampValid(self.seconds, self.nanos) return (self.seconds * _MICROS_PER_SECOND + self.nanos // _NANOS_PER_MICROSECOND) def ToMilliseconds(self): """Converts Timestamp to milliseconds since epoch.""" + _CheckTimestampValid(self.seconds, self.nanos) return (self.seconds * _MILLIS_PER_SECOND + self.nanos // _NANOS_PER_MILLISECOND) def ToSeconds(self): """Converts Timestamp to seconds since epoch.""" + _CheckTimestampValid(self.seconds, self.nanos) return self.seconds def FromNanoseconds(self, nanos): """Converts nanoseconds since epoch to Timestamp.""" - self.seconds = nanos // _NANOS_PER_SECOND - self.nanos = nanos % _NANOS_PER_SECOND + seconds = nanos // _NANOS_PER_SECOND + nanos = nanos % _NANOS_PER_SECOND + _CheckTimestampValid(seconds, nanos) + self.seconds = seconds + self.nanos = nanos def FromMicroseconds(self, micros): """Converts microseconds since epoch to Timestamp.""" - self.seconds = micros // _MICROS_PER_SECOND - self.nanos = (micros % _MICROS_PER_SECOND) * _NANOS_PER_MICROSECOND + seconds = micros // _MICROS_PER_SECOND + nanos = (micros % _MICROS_PER_SECOND) * _NANOS_PER_MICROSECOND + _CheckTimestampValid(seconds, nanos) + self.seconds = seconds + self.nanos = nanos def FromMilliseconds(self, millis): """Converts milliseconds since epoch to Timestamp.""" - self.seconds = millis // _MILLIS_PER_SECOND - self.nanos = (millis % _MILLIS_PER_SECOND) * _NANOS_PER_MILLISECOND + seconds = millis // _MILLIS_PER_SECOND + nanos = (millis % _MILLIS_PER_SECOND) * _NANOS_PER_MILLISECOND + _CheckTimestampValid(seconds, nanos) + self.seconds = seconds + self.nanos = nanos def FromSeconds(self, seconds): """Converts seconds since epoch to Timestamp.""" + _CheckTimestampValid(seconds, 0) self.seconds = seconds self.nanos = 0 @@ -229,6 +247,7 @@ def ToDatetime(self, tzinfo=None): # https://github.com/python/cpython/issues/109849) or full range (on some # platforms, see https://github.com/python/cpython/issues/110042) of # datetime. + _CheckTimestampValid(self.seconds, self.nanos) delta = datetime.timedelta( seconds=self.seconds, microseconds=_RoundTowardZero(self.nanos, _NANOS_PER_MICROSECOND), @@ -252,8 +271,22 @@ def FromDatetime(self, dt): # manipulated into a long value of seconds. During the conversion from # struct_time to long, the source date in UTC, and so it follows that the # correct transformation is calendar.timegm() - self.seconds = calendar.timegm(dt.utctimetuple()) - self.nanos = dt.microsecond * _NANOS_PER_MICROSECOND + seconds = calendar.timegm(dt.utctimetuple()) + nanos = dt.microsecond * _NANOS_PER_MICROSECOND + _CheckTimestampValid(seconds, nanos) + self.seconds = seconds + self.nanos = nanos + + +def _CheckTimestampValid(seconds, nanos): + if seconds < _TIMESTAMP_SECONDS_MIN or seconds > _TIMESTAMP_SECONDS_MAX: + raise ValueError( + 'Timestamp is not valid: Seconds {0} must be in range ' + '[-62135596800, 253402300799].'.format(seconds)) + if nanos < 0 or nanos >= _NANOS_PER_SECOND: + raise ValueError( + 'Timestamp is not valid: Nanos {} must be in a range ' + '[0, 999999].'.format(nanos)) class Duration(object): diff --git a/python/google/protobuf/internal/well_known_types_test.py b/python/google/protobuf/internal/well_known_types_test.py index 37d20491735f1..da273166eb970 100644 --- a/python/google/protobuf/internal/well_known_types_test.py +++ b/python/google/protobuf/internal/well_known_types_test.py @@ -352,27 +352,15 @@ def testTimezoneAwareMinDatetimeConversion(self): ) def testNanosOneSecond(self): - # TODO: b/301980950 - Test error behavior instead once ToDatetime validates - # that nanos are in expected range. tz = _TZ_PACIFIC ts = timestamp_pb2.Timestamp(nanos=1_000_000_000) - self.assertEqual(ts.ToDatetime(), datetime.datetime(1970, 1, 1, 0, 0, 1)) - self.assertEqual( - ts.ToDatetime(tz), datetime.datetime(1969, 12, 31, 16, 0, 1, tzinfo=tz) - ) + self.assertRaisesRegex(ValueError, 'Timestamp is not valid', + ts.ToDatetime) def testNanosNegativeOneSecond(self): - # TODO: b/301980950 - Test error behavior instead once ToDatetime validates - # that nanos are in expected range. - tz = _TZ_PACIFIC ts = timestamp_pb2.Timestamp(nanos=-1_000_000_000) - self.assertEqual( - ts.ToDatetime(), datetime.datetime(1969, 12, 31, 23, 59, 59) - ) - self.assertEqual( - ts.ToDatetime(tz), - datetime.datetime(1969, 12, 31, 15, 59, 59, tzinfo=tz), - ) + self.assertRaisesRegex(ValueError, 'Timestamp is not valid', + ts.ToDatetime) def testTimedeltaConversion(self): message = duration_pb2.Duration() @@ -421,8 +409,10 @@ def testInvalidTimestamp(self): self.assertRaisesRegex(ValueError, 'year (0 )?is out of range', message.FromJsonString, '0000-01-01T00:00:00Z') message.seconds = 253402300800 - self.assertRaisesRegex(OverflowError, 'date value out of range', + self.assertRaisesRegex(ValueError, 'Timestamp is not valid', message.ToJsonString) + self.assertRaisesRegex(ValueError, 'Timestamp is not valid', + message.FromSeconds, -62135596801) def testInvalidDuration(self): message = duration_pb2.Duration() From 0317875286380c604235a61d90093eb3731918f7 Mon Sep 17 00:00:00 2001 From: Sandy Zhang Date: Wed, 27 Dec 2023 18:18:08 -0800 Subject: [PATCH 115/255] Update Ruby GHA to test against Ruby 3.3 in Linux / MacOS / Install and FFI combinations. PiperOrigin-RevId: 594132729 --- .github/workflows/test_ruby.yml | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/.github/workflows/test_ruby.yml b/.github/workflows/test_ruby.yml index 726e0aa9c5b2e..6c456cb248f24 100644 --- a/.github/workflows/test_ruby.yml +++ b/.github/workflows/test_ruby.yml @@ -24,10 +24,10 @@ jobs: #- { name: Ruby 2.7, ruby: ruby-2.7.0, ffi: FFI } - { name: Ruby 3.0, ruby: ruby-3.0.2 } - { name: Ruby 3.1, ruby: ruby-3.1.0 } - - { name: Ruby 3.2, ruby: ruby-3.2.0, ffi: NATIVE } + - { name: Ruby 3.2, ruby: ruby-3.2.0 } - { name: Ruby 3.3, ruby: ruby-3.3.0, ffi: NATIVE } # TODO Re-enable these once flakes are fixed - #- { name: Ruby 3.2, ruby: ruby-3.2.0, ffi: FFI } + #- { name: Ruby 3.3, ruby: ruby-3.3.0, ffi: FFI } - { name: JRuby 9.4, ruby: jruby-9.4.3.0, ffi: NATIVE } - { name: JRuby 9.4, ruby: jruby-9.4.3.0, ffi: FFI } @@ -123,9 +123,10 @@ jobs: #- { version: "2.7", ffi: FFI } - { version: "3.0" } - { version: "3.1" } - - { version: "3.2", ffi: NATIVE } + - { version: "3.2" } + - { version: "3.3", ffi: NATIVE } # TODO Re-enable these once flakes are fixed - #- { version: "3.2", ffi: FFI } + #- { version: "3.3", ffi: FFI } name: MacOS Ruby ${{ matrix.version }}${{ matrix.ffi == 'FFI' && ' FFI' || '' }} runs-on: macos-12 @@ -136,7 +137,7 @@ jobs: ref: ${{ inputs.safe-checkout }} - name: Pin Ruby version - uses: ruby/setup-ruby@ee26e27437bde475b19a6bf8cb73c9fa658876a2 # v1.134.0 + uses: ruby/setup-ruby@961f85197f92e4842e3cb92a4f97bd8e010cdbaf # v1.165.0 with: ruby-version: ${{ matrix.version }} @@ -161,8 +162,9 @@ jobs: - { name: Ruby 2.7, ruby: ruby-2.7.0, ffi: FFI } - { name: Ruby 3.0, ruby: ruby-3.0.2} - { name: Ruby 3.1, ruby: ruby-3.1.0} - - { name: Ruby 3.2, ruby: ruby-3.2.0, ffi: NATIVE } - - { name: Ruby 3.2, ruby: ruby-3.2.0, ffi: FFI } + - { name: Ruby 3.2, ruby: ruby-3.2.0} + - { name: Ruby 3.3, ruby: ruby-3.3.0, ffi: NATIVE } + - { name: Ruby 3.3, ruby: ruby-3.3.0, ffi: FFI } - { name: JRuby 9.4, ruby: jruby-9.4.3.0, ffi: NATIVE } - { name: JRuby 9.4, ruby: jruby-9.4.3.0, ffi: FFI } name: Install ${{ matrix.name }}${{ matrix.ffi == 'FFI' && ' FFI' || '' }} @@ -175,7 +177,7 @@ jobs: - name: Run tests uses: protocolbuffers/protobuf-ci/bazel-docker@v2 with: - image: us-docker.pkg.dev/protobuf-build/containers/test/linux/ruby:${{ matrix.ruby }}-6.3.0-66964dc8b07b6d1fc73a5cc14e59e84c1c534cea + image: us-docker.pkg.dev/protobuf-build/containers/test/linux/ruby:${{ matrix.ruby }}-6.3.0-904cad5249547845454998ca3837a34c71fabf96 credentials: ${{ secrets.GAR_SERVICE_ACCOUNT }} bazel-cache: ruby_install/${{ matrix.ruby }}_${{ matrix.bazel }} bash: > From 7e1fd6866708d3aafc1f2cffe79f47aee297f7a3 Mon Sep 17 00:00:00 2001 From: Eric Salo Date: Wed, 27 Dec 2023 18:43:45 -0800 Subject: [PATCH 116/255] upb: clean up some of the includes in upb/message/ PiperOrigin-RevId: 594135760 --- upb/message/internal/accessors.h | 22 +++++++++----------- upb/message/internal/array.h | 34 ++++++++++++++++--------------- upb/message/internal/extension.h | 15 +++++++------- upb/message/internal/map.h | 21 ++++++++++--------- upb/message/internal/map_sorter.h | 9 ++++---- upb/message/internal/message.c | 5 ++--- upb/message/internal/message.h | 18 ++++++++-------- upb/message/value.h | 5 ++--- 8 files changed, 66 insertions(+), 63 deletions(-) diff --git a/upb/message/internal/accessors.h b/upb/message/internal/accessors.h index 089fb64d9094d..191df0552daad 100644 --- a/upb/message/internal/accessors.h +++ b/upb/message/internal/accessors.h @@ -14,13 +14,10 @@ #include "upb/base/string_view.h" #include "upb/mem/arena.h" -#include "upb/message/array.h" #include "upb/message/internal/extension.h" #include "upb/message/internal/map.h" #include "upb/message/internal/message.h" #include "upb/message/internal/types.h" -#include "upb/message/map.h" -#include "upb/message/message.h" #include "upb/message/tagged_ptr.h" #include "upb/mini_table/extension.h" #include "upb/mini_table/field.h" @@ -232,7 +229,7 @@ static UPB_FORCEINLINE void _upb_Message_GetNonExtensionField( UPB_INLINE void _upb_Message_GetExtensionField( const upb_Message* msg, const upb_MiniTableExtension* mt_ext, const void* default_val, void* val) { - const upb_Extension* ext = _upb_Message_Getext(msg, mt_ext); + const struct upb_Extension* ext = _upb_Message_Getext(msg, mt_ext); const upb_MiniTableField* f = &mt_ext->UPB_PRIVATE(field); UPB_ASSUME(upb_MiniTableField_IsExtension(f)); @@ -282,7 +279,7 @@ UPB_INLINE bool _upb_Message_SetExtensionField( upb_Message* msg, const upb_MiniTableExtension* mt_ext, const void* val, upb_Arena* a) { UPB_ASSERT(a); - upb_Extension* ext = _upb_Message_GetOrCreateExtension(msg, mt_ext, a); + struct upb_Extension* ext = _upb_Message_GetOrCreateExtension(msg, mt_ext, a); if (!ext) return false; UPB_PRIVATE(_upb_MiniTableField_DataCopy) (&mt_ext->UPB_PRIVATE(field), &ext->data, val); @@ -293,12 +290,13 @@ UPB_INLINE void _upb_Message_ClearExtensionField( upb_Message* msg, const upb_MiniTableExtension* ext_l) { upb_Message_Internal* in = upb_Message_Getinternal(msg); if (!in->internal) return; - const upb_Extension* base = - UPB_PTR_AT(in->internal, in->internal->ext_begin, upb_Extension); - upb_Extension* ext = (upb_Extension*)_upb_Message_Getext(msg, ext_l); + const struct upb_Extension* base = + UPB_PTR_AT(in->internal, in->internal->ext_begin, struct upb_Extension); + struct upb_Extension* ext = + (struct upb_Extension*)_upb_Message_Getext(msg, ext_l); if (ext) { *ext = *base; - in->internal->ext_begin += sizeof(upb_Extension); + in->internal->ext_begin += sizeof(struct upb_Extension); } } @@ -328,13 +326,13 @@ UPB_INLINE void _upb_Message_AssertMapIsUntagged( #endif } -UPB_INLINE upb_Map* _upb_Message_GetOrCreateMutableMap( +UPB_INLINE struct upb_Map* _upb_Message_GetOrCreateMutableMap( upb_Message* msg, const upb_MiniTableField* field, size_t key_size, size_t val_size, upb_Arena* arena) { UPB_PRIVATE(_upb_MiniTableField_CheckIsMap)(field); _upb_Message_AssertMapIsUntagged(msg, field); - upb_Map* map = NULL; - upb_Map* default_map_value = NULL; + struct upb_Map* map = NULL; + struct upb_Map* default_map_value = NULL; _upb_Message_GetNonExtensionField(msg, field, &default_map_value, &map); if (!map) { map = _upb_Map_New(arena, key_size, val_size); diff --git a/upb/message/internal/array.h b/upb/message/internal/array.h index 4d03e4b97854f..96152f0b56768 100644 --- a/upb/message/internal/array.h +++ b/upb/message/internal/array.h @@ -10,7 +10,7 @@ #include -#include "upb/message/array.h" +#include "upb/mem/arena.h" // Must be last. #include "upb/port/def.inc" @@ -39,7 +39,7 @@ struct upb_Array { size_t UPB_PRIVATE(capacity); // Allocated storage. Measured in elements. }; -UPB_INLINE void UPB_PRIVATE(_upb_Array_SetTaggedPtr)(upb_Array* array, +UPB_INLINE void UPB_PRIVATE(_upb_Array_SetTaggedPtr)(struct upb_Array* array, void* data, size_t lg2) { UPB_ASSERT(lg2 != 1); UPB_ASSERT(lg2 <= 4); @@ -47,29 +47,31 @@ UPB_INLINE void UPB_PRIVATE(_upb_Array_SetTaggedPtr)(upb_Array* array, array->data = (uintptr_t)data | bits; } -UPB_INLINE size_t UPB_PRIVATE(_upb_Array_ElemSizeLg2)(const upb_Array* array) { +UPB_INLINE size_t +UPB_PRIVATE(_upb_Array_ElemSizeLg2)(const struct upb_Array* array) { const size_t bits = array->data & _UPB_ARRAY_MASK_LG2; const size_t lg2 = bits + (bits != 0); return lg2; } -UPB_INLINE const void* _upb_array_constptr(const upb_Array* array) { +UPB_INLINE const void* _upb_array_constptr(const struct upb_Array* array) { UPB_PRIVATE(_upb_Array_ElemSizeLg2)(array); // Check assertions. return (void*)(array->data & ~(uintptr_t)_UPB_ARRAY_MASK_ALL); } -UPB_INLINE void* _upb_array_ptr(upb_Array* array) { +UPB_INLINE void* _upb_array_ptr(struct upb_Array* array) { return (void*)_upb_array_constptr(array); } -UPB_INLINE upb_Array* UPB_PRIVATE(_upb_Array_New)(upb_Arena* arena, - size_t init_capacity, - int elem_size_lg2) { +UPB_INLINE struct upb_Array* UPB_PRIVATE(_upb_Array_New)(upb_Arena* arena, + size_t init_capacity, + int elem_size_lg2) { UPB_ASSERT(elem_size_lg2 != 1); UPB_ASSERT(elem_size_lg2 <= 4); - const size_t array_size = UPB_ALIGN_UP(sizeof(upb_Array), UPB_MALLOC_ALIGN); + const size_t array_size = + UPB_ALIGN_UP(sizeof(struct upb_Array), UPB_MALLOC_ALIGN); const size_t bytes = array_size + (init_capacity << elem_size_lg2); - upb_Array* array = (upb_Array*)upb_Arena_Malloc(arena, bytes); + struct upb_Array* array = (struct upb_Array*)upb_Arena_Malloc(arena, bytes); if (!array) return NULL; UPB_PRIVATE(_upb_Array_SetTaggedPtr) (array, UPB_PTR_AT(array, array_size, void), elem_size_lg2); @@ -79,19 +81,19 @@ UPB_INLINE upb_Array* UPB_PRIVATE(_upb_Array_New)(upb_Arena* arena, } // Resizes the capacity of the array to be at least min_size. -bool UPB_PRIVATE(_upb_Array_Realloc)(upb_Array* array, size_t min_size, +bool UPB_PRIVATE(_upb_Array_Realloc)(struct upb_Array* array, size_t min_size, upb_Arena* arena); -UPB_INLINE bool UPB_PRIVATE(_upb_Array_Reserve)(upb_Array* array, size_t size, - upb_Arena* arena) { +UPB_INLINE bool UPB_PRIVATE(_upb_Array_Reserve)(struct upb_Array* array, + size_t size, upb_Arena* arena) { if (array->UPB_PRIVATE(capacity) < size) return UPB_PRIVATE(_upb_Array_Realloc)(array, size, arena); return true; } // Resize without initializing new elements. -UPB_INLINE bool _upb_Array_ResizeUninitialized(upb_Array* array, size_t size, - upb_Arena* arena) { +UPB_INLINE bool _upb_Array_ResizeUninitialized(struct upb_Array* array, + size_t size, upb_Arena* arena) { UPB_ASSERT(size <= array->UPB_ONLYBITS(size) || arena); // Allow NULL arena when shrinking. if (!UPB_PRIVATE(_upb_Array_Reserve)(array, size, arena)) return false; @@ -102,7 +104,7 @@ UPB_INLINE bool _upb_Array_ResizeUninitialized(upb_Array* array, size_t size, // This function is intended for situations where elem_size is compile-time // constant or a known expression of the form (1 << lg2), so that the expression // i*elem_size does not result in an actual multiplication. -UPB_INLINE void UPB_PRIVATE(_upb_Array_Set)(upb_Array* array, size_t i, +UPB_INLINE void UPB_PRIVATE(_upb_Array_Set)(struct upb_Array* array, size_t i, const void* data, size_t elem_size) { UPB_ASSERT(i < array->UPB_ONLYBITS(size)); diff --git a/upb/message/internal/extension.h b/upb/message/internal/extension.h index 86b1e6f2beb38..9325732833801 100644 --- a/upb/message/internal/extension.h +++ b/upb/message/internal/extension.h @@ -10,7 +10,7 @@ #include "upb/base/string_view.h" #include "upb/mem/arena.h" -#include "upb/message/message.h" +#include "upb/message/internal/message.h" #include "upb/mini_table/extension.h" // Must be last. @@ -40,18 +40,19 @@ extern "C" { // Adds the given extension data to the given message. // |ext| is copied into the message instance. // This logically replaces any previously-added extension with this number. -upb_Extension* _upb_Message_GetOrCreateExtension( - upb_Message* msg, const upb_MiniTableExtension* ext, upb_Arena* arena); +struct upb_Extension* _upb_Message_GetOrCreateExtension( + struct upb_Message* msg, const upb_MiniTableExtension* ext, + upb_Arena* arena); // Returns an array of extensions for this message. // Note: the array is ordered in reverse relative to the order of creation. -const upb_Extension* UPB_PRIVATE(_upb_Message_Getexts)(const upb_Message* msg, - size_t* count); +const struct upb_Extension* UPB_PRIVATE(_upb_Message_Getexts)( + const struct upb_Message* msg, size_t* count); // Returns an extension for a message with a given mini table, // or NULL if no extension exists with this mini table. -const upb_Extension* _upb_Message_Getext(const upb_Message* msg, - const upb_MiniTableExtension* ext); +const struct upb_Extension* _upb_Message_Getext( + const struct upb_Message* msg, const upb_MiniTableExtension* ext); #ifdef __cplusplus } /* extern "C" */ diff --git a/upb/message/internal/map.h b/upb/message/internal/map.h index 51bc16be12f82..139243ca2f3f8 100644 --- a/upb/message/internal/map.h +++ b/upb/message/internal/map.h @@ -81,7 +81,7 @@ UPB_INLINE void _upb_map_fromvalue(upb_value val, void* out, size_t size) { } } -UPB_INLINE void* _upb_map_next(const upb_Map* map, size_t* iter) { +UPB_INLINE void* _upb_map_next(const struct upb_Map* map, size_t* iter) { upb_strtable_iter it; it.t = &map->table; it.index = *iter; @@ -91,17 +91,17 @@ UPB_INLINE void* _upb_map_next(const upb_Map* map, size_t* iter) { return (void*)str_tabent(&it); } -UPB_INLINE void _upb_Map_Clear(upb_Map* map) { +UPB_INLINE void _upb_Map_Clear(struct upb_Map* map) { upb_strtable_clear(&map->table); } -UPB_INLINE bool _upb_Map_Delete(upb_Map* map, const void* key, size_t key_size, - upb_value* val) { +UPB_INLINE bool _upb_Map_Delete(struct upb_Map* map, const void* key, + size_t key_size, upb_value* val) { upb_StringView k = _upb_map_tokey(key, key_size); return upb_strtable_remove2(&map->table, k.data, k.size, val); } -UPB_INLINE bool _upb_Map_Get(const upb_Map* map, const void* key, +UPB_INLINE bool _upb_Map_Get(const struct upb_Map* map, const void* key, size_t key_size, void* val, size_t val_size) { upb_value tabval; upb_StringView k = _upb_map_tokey(key, key_size); @@ -112,9 +112,10 @@ UPB_INLINE bool _upb_Map_Get(const upb_Map* map, const void* key, return ret; } -UPB_INLINE upb_MapInsertStatus _upb_Map_Insert(upb_Map* map, const void* key, - size_t key_size, void* val, - size_t val_size, upb_Arena* a) { +UPB_INLINE upb_MapInsertStatus _upb_Map_Insert(struct upb_Map* map, + const void* key, size_t key_size, + void* val, size_t val_size, + upb_Arena* a) { upb_StringView strkey = _upb_map_tokey(key, key_size); upb_value tabval = {0}; if (!_upb_map_tovalue(val, val_size, &tabval, a)) { @@ -131,7 +132,7 @@ UPB_INLINE upb_MapInsertStatus _upb_Map_Insert(upb_Map* map, const void* key, : kUpb_MapInsertStatus_Inserted; } -UPB_INLINE size_t _upb_Map_Size(const upb_Map* map) { +UPB_INLINE size_t _upb_Map_Size(const struct upb_Map* map) { return map->table.t.count; } @@ -143,7 +144,7 @@ UPB_INLINE size_t _upb_Map_CTypeSize(upb_CType ctype) { } // Creates a new map on the given arena with this key/value type. -upb_Map* _upb_Map_New(upb_Arena* a, size_t key_size, size_t value_size); +struct upb_Map* _upb_Map_New(upb_Arena* a, size_t key_size, size_t value_size); #ifdef __cplusplus } /* extern "C" */ diff --git a/upb/message/internal/map_sorter.h b/upb/message/internal/map_sorter.h index 93be85ec363a6..2a09b3c63f83f 100644 --- a/upb/message/internal/map_sorter.h +++ b/upb/message/internal/map_sorter.h @@ -63,9 +63,9 @@ UPB_INLINE bool _upb_sortedmap_next(_upb_mapsorter* s, const upb_Map* map, UPB_INLINE bool _upb_sortedmap_nextext(_upb_mapsorter* s, _upb_sortedmap* sorted, - const upb_Extension** ext) { + const struct upb_Extension** ext) { if (sorted->pos == sorted->end) return false; - *ext = (const upb_Extension*)s->entries[sorted->pos++]; + *ext = (const struct upb_Extension*)s->entries[sorted->pos++]; return true; } @@ -77,8 +77,9 @@ UPB_INLINE void _upb_mapsorter_popmap(_upb_mapsorter* s, bool _upb_mapsorter_pushmap(_upb_mapsorter* s, upb_FieldType key_type, const upb_Map* map, _upb_sortedmap* sorted); -bool _upb_mapsorter_pushexts(_upb_mapsorter* s, const upb_Extension* exts, - size_t count, _upb_sortedmap* sorted); +bool _upb_mapsorter_pushexts(_upb_mapsorter* s, + const struct upb_Extension* exts, size_t count, + _upb_sortedmap* sorted); #ifdef __cplusplus } /* extern "C" */ diff --git a/upb/message/internal/message.c b/upb/message/internal/message.c index 94ed339a72241..08b70d2d61e5e 100644 --- a/upb/message/internal/message.c +++ b/upb/message/internal/message.c @@ -5,14 +5,13 @@ // license that can be found in the LICENSE file or at // https://developers.google.com/open-source/licenses/bsd -#include "upb/message/message.h" +#include "upb/message/internal/message.h" #include #include #include "upb/base/internal/log2.h" #include "upb/mem/arena.h" -#include "upb/message/internal/message.h" #include "upb/message/internal/types.h" // Must be last. @@ -24,7 +23,7 @@ const double kUpb_NaN = NAN; static const size_t realloc_overhead = sizeof(upb_Message_InternalData); -bool UPB_PRIVATE(_upb_Message_Realloc)(upb_Message* msg, size_t need, +bool UPB_PRIVATE(_upb_Message_Realloc)(struct upb_Message* msg, size_t need, upb_Arena* arena) { upb_Message_Internal* in = upb_Message_Getinternal(msg); if (!in->internal) { diff --git a/upb/message/internal/message.h b/upb/message/internal/message.h index 5cbc652a5e62b..54af496fb02b6 100644 --- a/upb/message/internal/message.h +++ b/upb/message/internal/message.h @@ -68,31 +68,33 @@ UPB_INLINE size_t upb_msg_sizeof(const upb_MiniTable* m) { } // Inline version upb_Message_New(), for internal use. -UPB_INLINE upb_Message* _upb_Message_New(const upb_MiniTable* mini_table, - upb_Arena* arena) { +UPB_INLINE struct upb_Message* _upb_Message_New(const upb_MiniTable* mini_table, + upb_Arena* arena) { size_t size = upb_msg_sizeof(mini_table); void* mem = upb_Arena_Malloc(arena, size + sizeof(upb_Message_Internal)); if (UPB_UNLIKELY(!mem)) return NULL; - upb_Message* msg = UPB_PTR_AT(mem, sizeof(upb_Message_Internal), upb_Message); + struct upb_Message* msg = + UPB_PTR_AT(mem, sizeof(upb_Message_Internal), struct upb_Message); memset(mem, 0, size); return msg; } UPB_INLINE upb_Message_Internal* upb_Message_Getinternal( - const upb_Message* msg) { + const struct upb_Message* msg) { ptrdiff_t size = sizeof(upb_Message_Internal); return (upb_Message_Internal*)((char*)msg - size); } // Discards the unknown fields for this message only. -void _upb_Message_DiscardUnknown_shallow(upb_Message* msg); +void _upb_Message_DiscardUnknown_shallow(struct upb_Message* msg); // Adds unknown data (serialized protobuf data) to the given message. // The data is copied into the message instance. -bool UPB_PRIVATE(_upb_Message_AddUnknown)(upb_Message* msg, const char* data, - size_t len, upb_Arena* arena); +bool UPB_PRIVATE(_upb_Message_AddUnknown)(struct upb_Message* msg, + const char* data, size_t len, + upb_Arena* arena); -bool UPB_PRIVATE(_upb_Message_Realloc)(upb_Message* msg, size_t need, +bool UPB_PRIVATE(_upb_Message_Realloc)(struct upb_Message* msg, size_t need, upb_Arena* arena); #ifdef __cplusplus diff --git a/upb/message/value.h b/upb/message/value.h index 99df02597cb64..547edc1d2e3af 100644 --- a/upb/message/value.h +++ b/upb/message/value.h @@ -15,7 +15,6 @@ #include "upb/base/string_view.h" #include "upb/message/tagged_ptr.h" -#include "upb/message/types.h" typedef union { bool bool_val; @@ -27,7 +26,7 @@ typedef union { uint64_t uint64_val; const struct upb_Array* array_val; const struct upb_Map* map_val; - const upb_Message* msg_val; + const struct upb_Message* msg_val; upb_StringView str_val; // EXPERIMENTAL: A tagged upb_Message*. Users must use this instead of @@ -40,7 +39,7 @@ typedef union { typedef union { struct upb_Array* array; struct upb_Map* map; - upb_Message* msg; + struct upb_Message* msg; } upb_MutableMessageValue; #endif /* UPB_MESSAGE_VALUE_H_ */ From e9ea4a5154d49ef76e546bb9f3172204e4123cdf Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Thu, 28 Dec 2023 02:56:22 +0000 Subject: [PATCH 117/255] Auto-generate files after cl/594135760 --- php/ext/google/protobuf/php-upb.c | 2 +- php/ext/google/protobuf/php-upb.h | 352 +++++++++++++------------- ruby/ext/google/protobuf_c/ruby-upb.c | 2 +- ruby/ext/google/protobuf_c/ruby-upb.h | 352 +++++++++++++------------- 4 files changed, 362 insertions(+), 346 deletions(-) diff --git a/php/ext/google/protobuf/php-upb.c b/php/ext/google/protobuf/php-upb.c index 54ef40bdbecc7..2104c27271a77 100644 --- a/php/ext/google/protobuf/php-upb.c +++ b/php/ext/google/protobuf/php-upb.c @@ -6209,7 +6209,7 @@ const double kUpb_NaN = NAN; static const size_t realloc_overhead = sizeof(upb_Message_InternalData); -bool UPB_PRIVATE(_upb_Message_Realloc)(upb_Message* msg, size_t need, +bool UPB_PRIVATE(_upb_Message_Realloc)(struct upb_Message* msg, size_t need, upb_Arena* arena) { upb_Message_Internal* in = upb_Message_Getinternal(msg); if (!in->internal) { diff --git a/php/ext/google/protobuf/php-upb.h b/php/ext/google/protobuf/php-upb.h index e048e505a2485..67947df0c9f9b 100644 --- a/php/ext/google/protobuf/php-upb.h +++ b/php/ext/google/protobuf/php-upb.h @@ -907,7 +907,7 @@ typedef union { uint64_t uint64_val; const struct upb_Array* array_val; const struct upb_Map* map_val; - const upb_Message* msg_val; + const struct upb_Message* msg_val; upb_StringView str_val; // EXPERIMENTAL: A tagged upb_Message*. Users must use this instead of @@ -920,7 +920,7 @@ typedef union { typedef union { struct upb_Array* array; struct upb_Map* map; - upb_Message* msg; + struct upb_Message* msg; } upb_MutableMessageValue; #endif /* UPB_MESSAGE_VALUE_H_ */ @@ -995,15 +995,36 @@ UPB_API void* upb_Array_MutableDataPtr(upb_Array* arr); #define UPB_MESSAGE_INTERNAL_EXTENSION_H_ -// Public APIs for message operations that do not depend on the schema. -// -// MiniTable-based accessors live in accessors.h. +/* +** Our memory representation for parsing tables and messages themselves. +** Functions in this file are used by generated code and possibly reflection. +** +** The definitions in this file are internal to upb. +**/ -#ifndef UPB_MESSAGE_MESSAGE_H_ -#define UPB_MESSAGE_MESSAGE_H_ +#ifndef UPB_MESSAGE_INTERNAL_H_ +#define UPB_MESSAGE_INTERNAL_H_ -#include +#include +#include + + +#ifndef UPB_MINI_TABLE_INTERNAL_TYPES_H_ +#define UPB_MINI_TABLE_INTERNAL_TYPES_H_ + +typedef struct upb_Message_InternalData upb_Message_InternalData; + +typedef struct { + union { + upb_Message_InternalData* internal; + + // Force 8-byte alignment, since the data members may contain members that + // require 8-byte alignment. + double d; + }; +} upb_Message_Internal; +#endif // UPB_MINI_TABLE_INTERNAL_TYPES_H_ #ifndef UPB_MINI_TABLE_MESSAGE_H_ #define UPB_MINI_TABLE_MESSAGE_H_ @@ -1710,30 +1731,83 @@ bool upb_MiniTable_NextOneofField(const upb_MiniTable* m, // Must be last. -typedef struct upb_Extension upb_Extension; - #ifdef __cplusplus extern "C" { #endif -// Creates a new message with the given mini_table on the given arena. -UPB_API upb_Message* upb_Message_New(const upb_MiniTable* m, upb_Arena* arena); +extern const float kUpb_FltInfinity; +extern const double kUpb_Infinity; +extern const double kUpb_NaN; -// Returns a reference to the message's unknown data. -const char* upb_Message_GetUnknown(const upb_Message* msg, size_t* len); +/* Internal members of a upb_Message that track unknown fields and/or + * extensions. We can change this without breaking binary compatibility. We put + * these before the user's data. The user's upb_Message* points after the + * upb_Message_Internal. */ -// Removes partial unknown data from message. -void upb_Message_DeleteUnknown(upb_Message* msg, const char* data, size_t len); +struct upb_Message_InternalData { + /* Total size of this structure, including the data that follows. + * Must be aligned to 8, which is alignof(upb_Extension) */ + uint32_t size; -// Returns the number of extensions present in this message. -size_t upb_Message_ExtensionCount(const upb_Message* msg); + /* Offsets relative to the beginning of this structure. + * + * Unknown data grows forward from the beginning to unknown_end. + * Extension data grows backward from size to ext_begin. + * When the two meet, we're out of data and have to realloc. + * + * If we imagine that the final member of this struct is: + * char data[size - overhead]; // overhead = + * sizeof(upb_Message_InternalData) + * + * Then we have: + * unknown data: data[0 .. (unknown_end - overhead)] + * extensions data: data[(ext_begin - overhead) .. (size - overhead)] */ + uint32_t unknown_end; + uint32_t ext_begin; + /* Data follows, as if there were an array: + * char data[size - sizeof(upb_Message_InternalData)]; */ +}; + +UPB_INLINE size_t upb_msg_sizeof(const upb_MiniTable* m) { + return m->UPB_PRIVATE(size) + sizeof(upb_Message_Internal); +} + +// Inline version upb_Message_New(), for internal use. +UPB_INLINE struct upb_Message* _upb_Message_New(const upb_MiniTable* mini_table, + upb_Arena* arena) { + size_t size = upb_msg_sizeof(mini_table); + void* mem = upb_Arena_Malloc(arena, size + sizeof(upb_Message_Internal)); + if (UPB_UNLIKELY(!mem)) return NULL; + struct upb_Message* msg = + UPB_PTR_AT(mem, sizeof(upb_Message_Internal), struct upb_Message); + memset(mem, 0, size); + return msg; +} + +UPB_INLINE upb_Message_Internal* upb_Message_Getinternal( + const struct upb_Message* msg) { + ptrdiff_t size = sizeof(upb_Message_Internal); + return (upb_Message_Internal*)((char*)msg - size); +} + +// Discards the unknown fields for this message only. +void _upb_Message_DiscardUnknown_shallow(struct upb_Message* msg); + +// Adds unknown data (serialized protobuf data) to the given message. +// The data is copied into the message instance. +bool UPB_PRIVATE(_upb_Message_AddUnknown)(struct upb_Message* msg, + const char* data, size_t len, + upb_Arena* arena); + +bool UPB_PRIVATE(_upb_Message_Realloc)(struct upb_Message* msg, size_t need, + upb_Arena* arena); #ifdef __cplusplus } /* extern "C" */ #endif -#endif /* UPB_MESSAGE_MESSAGE_H_ */ +#endif /* UPB_MESSAGE_INTERNAL_H_ */ #ifndef UPB_MINI_TABLE_EXTENSION_H_ #define UPB_MINI_TABLE_EXTENSION_H_ @@ -1850,18 +1924,19 @@ extern "C" { // Adds the given extension data to the given message. // |ext| is copied into the message instance. // This logically replaces any previously-added extension with this number. -upb_Extension* _upb_Message_GetOrCreateExtension( - upb_Message* msg, const upb_MiniTableExtension* ext, upb_Arena* arena); +struct upb_Extension* _upb_Message_GetOrCreateExtension( + struct upb_Message* msg, const upb_MiniTableExtension* ext, + upb_Arena* arena); // Returns an array of extensions for this message. // Note: the array is ordered in reverse relative to the order of creation. -const upb_Extension* UPB_PRIVATE(_upb_Message_Getexts)(const upb_Message* msg, - size_t* count); +const struct upb_Extension* UPB_PRIVATE(_upb_Message_Getexts)( + const struct upb_Message* msg, size_t* count); // Returns an extension for a message with a given mini table, // or NULL if no extension exists with this mini table. -const upb_Extension* _upb_Message_Getext(const upb_Message* msg, - const upb_MiniTableExtension* ext); +const struct upb_Extension* _upb_Message_Getext( + const struct upb_Message* msg, const upb_MiniTableExtension* ext); #ifdef __cplusplus } /* extern "C" */ @@ -2350,7 +2425,7 @@ UPB_INLINE void _upb_map_fromvalue(upb_value val, void* out, size_t size) { } } -UPB_INLINE void* _upb_map_next(const upb_Map* map, size_t* iter) { +UPB_INLINE void* _upb_map_next(const struct upb_Map* map, size_t* iter) { upb_strtable_iter it; it.t = &map->table; it.index = *iter; @@ -2360,17 +2435,17 @@ UPB_INLINE void* _upb_map_next(const upb_Map* map, size_t* iter) { return (void*)str_tabent(&it); } -UPB_INLINE void _upb_Map_Clear(upb_Map* map) { +UPB_INLINE void _upb_Map_Clear(struct upb_Map* map) { upb_strtable_clear(&map->table); } -UPB_INLINE bool _upb_Map_Delete(upb_Map* map, const void* key, size_t key_size, - upb_value* val) { +UPB_INLINE bool _upb_Map_Delete(struct upb_Map* map, const void* key, + size_t key_size, upb_value* val) { upb_StringView k = _upb_map_tokey(key, key_size); return upb_strtable_remove2(&map->table, k.data, k.size, val); } -UPB_INLINE bool _upb_Map_Get(const upb_Map* map, const void* key, +UPB_INLINE bool _upb_Map_Get(const struct upb_Map* map, const void* key, size_t key_size, void* val, size_t val_size) { upb_value tabval; upb_StringView k = _upb_map_tokey(key, key_size); @@ -2381,9 +2456,10 @@ UPB_INLINE bool _upb_Map_Get(const upb_Map* map, const void* key, return ret; } -UPB_INLINE upb_MapInsertStatus _upb_Map_Insert(upb_Map* map, const void* key, - size_t key_size, void* val, - size_t val_size, upb_Arena* a) { +UPB_INLINE upb_MapInsertStatus _upb_Map_Insert(struct upb_Map* map, + const void* key, size_t key_size, + void* val, size_t val_size, + upb_Arena* a) { upb_StringView strkey = _upb_map_tokey(key, key_size); upb_value tabval = {0}; if (!_upb_map_tovalue(val, val_size, &tabval, a)) { @@ -2400,7 +2476,7 @@ UPB_INLINE upb_MapInsertStatus _upb_Map_Insert(upb_Map* map, const void* key, : kUpb_MapInsertStatus_Inserted; } -UPB_INLINE size_t _upb_Map_Size(const upb_Map* map) { +UPB_INLINE size_t _upb_Map_Size(const struct upb_Map* map) { return map->table.t.count; } @@ -2412,7 +2488,7 @@ UPB_INLINE size_t _upb_Map_CTypeSize(upb_CType ctype) { } // Creates a new map on the given arena with this key/value type. -upb_Map* _upb_Map_New(upb_Arena* a, size_t key_size, size_t value_size); +struct upb_Map* _upb_Map_New(upb_Arena* a, size_t key_size, size_t value_size); #ifdef __cplusplus } /* extern "C" */ @@ -2421,115 +2497,6 @@ upb_Map* _upb_Map_New(upb_Arena* a, size_t key_size, size_t value_size); #endif /* UPB_MESSAGE_INTERNAL_MAP_H_ */ -/* -** Our memory representation for parsing tables and messages themselves. -** Functions in this file are used by generated code and possibly reflection. -** -** The definitions in this file are internal to upb. -**/ - -#ifndef UPB_MESSAGE_INTERNAL_H_ -#define UPB_MESSAGE_INTERNAL_H_ - -#include -#include - - -#ifndef UPB_MINI_TABLE_INTERNAL_TYPES_H_ -#define UPB_MINI_TABLE_INTERNAL_TYPES_H_ - -typedef struct upb_Message_InternalData upb_Message_InternalData; - -typedef struct { - union { - upb_Message_InternalData* internal; - - // Force 8-byte alignment, since the data members may contain members that - // require 8-byte alignment. - double d; - }; -} upb_Message_Internal; - -#endif // UPB_MINI_TABLE_INTERNAL_TYPES_H_ - -// Must be last. - -#ifdef __cplusplus -extern "C" { -#endif - -extern const float kUpb_FltInfinity; -extern const double kUpb_Infinity; -extern const double kUpb_NaN; - -/* Internal members of a upb_Message that track unknown fields and/or - * extensions. We can change this without breaking binary compatibility. We put - * these before the user's data. The user's upb_Message* points after the - * upb_Message_Internal. */ - -struct upb_Message_InternalData { - /* Total size of this structure, including the data that follows. - * Must be aligned to 8, which is alignof(upb_Extension) */ - uint32_t size; - - /* Offsets relative to the beginning of this structure. - * - * Unknown data grows forward from the beginning to unknown_end. - * Extension data grows backward from size to ext_begin. - * When the two meet, we're out of data and have to realloc. - * - * If we imagine that the final member of this struct is: - * char data[size - overhead]; // overhead = - * sizeof(upb_Message_InternalData) - * - * Then we have: - * unknown data: data[0 .. (unknown_end - overhead)] - * extensions data: data[(ext_begin - overhead) .. (size - overhead)] */ - uint32_t unknown_end; - uint32_t ext_begin; - /* Data follows, as if there were an array: - * char data[size - sizeof(upb_Message_InternalData)]; */ -}; - -UPB_INLINE size_t upb_msg_sizeof(const upb_MiniTable* m) { - return m->UPB_PRIVATE(size) + sizeof(upb_Message_Internal); -} - -// Inline version upb_Message_New(), for internal use. -UPB_INLINE upb_Message* _upb_Message_New(const upb_MiniTable* mini_table, - upb_Arena* arena) { - size_t size = upb_msg_sizeof(mini_table); - void* mem = upb_Arena_Malloc(arena, size + sizeof(upb_Message_Internal)); - if (UPB_UNLIKELY(!mem)) return NULL; - upb_Message* msg = UPB_PTR_AT(mem, sizeof(upb_Message_Internal), upb_Message); - memset(mem, 0, size); - return msg; -} - -UPB_INLINE upb_Message_Internal* upb_Message_Getinternal( - const upb_Message* msg) { - ptrdiff_t size = sizeof(upb_Message_Internal); - return (upb_Message_Internal*)((char*)msg - size); -} - -// Discards the unknown fields for this message only. -void _upb_Message_DiscardUnknown_shallow(upb_Message* msg); - -// Adds unknown data (serialized protobuf data) to the given message. -// The data is copied into the message instance. -bool UPB_PRIVATE(_upb_Message_AddUnknown)(upb_Message* msg, const char* data, - size_t len, upb_Arena* arena); - -bool UPB_PRIVATE(_upb_Message_Realloc)(upb_Message* msg, size_t need, - upb_Arena* arena); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - - -#endif /* UPB_MESSAGE_INTERNAL_H_ */ - // Must be last. #if defined(__GNUC__) && !defined(__clang__) @@ -2736,7 +2703,7 @@ static UPB_FORCEINLINE void _upb_Message_GetNonExtensionField( UPB_INLINE void _upb_Message_GetExtensionField( const upb_Message* msg, const upb_MiniTableExtension* mt_ext, const void* default_val, void* val) { - const upb_Extension* ext = _upb_Message_Getext(msg, mt_ext); + const struct upb_Extension* ext = _upb_Message_Getext(msg, mt_ext); const upb_MiniTableField* f = &mt_ext->UPB_PRIVATE(field); UPB_ASSUME(upb_MiniTableField_IsExtension(f)); @@ -2786,7 +2753,7 @@ UPB_INLINE bool _upb_Message_SetExtensionField( upb_Message* msg, const upb_MiniTableExtension* mt_ext, const void* val, upb_Arena* a) { UPB_ASSERT(a); - upb_Extension* ext = _upb_Message_GetOrCreateExtension(msg, mt_ext, a); + struct upb_Extension* ext = _upb_Message_GetOrCreateExtension(msg, mt_ext, a); if (!ext) return false; UPB_PRIVATE(_upb_MiniTableField_DataCopy) (&mt_ext->UPB_PRIVATE(field), &ext->data, val); @@ -2797,12 +2764,13 @@ UPB_INLINE void _upb_Message_ClearExtensionField( upb_Message* msg, const upb_MiniTableExtension* ext_l) { upb_Message_Internal* in = upb_Message_Getinternal(msg); if (!in->internal) return; - const upb_Extension* base = - UPB_PTR_AT(in->internal, in->internal->ext_begin, upb_Extension); - upb_Extension* ext = (upb_Extension*)_upb_Message_Getext(msg, ext_l); + const struct upb_Extension* base = + UPB_PTR_AT(in->internal, in->internal->ext_begin, struct upb_Extension); + struct upb_Extension* ext = + (struct upb_Extension*)_upb_Message_Getext(msg, ext_l); if (ext) { *ext = *base; - in->internal->ext_begin += sizeof(upb_Extension); + in->internal->ext_begin += sizeof(struct upb_Extension); } } @@ -2832,13 +2800,13 @@ UPB_INLINE void _upb_Message_AssertMapIsUntagged( #endif } -UPB_INLINE upb_Map* _upb_Message_GetOrCreateMutableMap( +UPB_INLINE struct upb_Map* _upb_Message_GetOrCreateMutableMap( upb_Message* msg, const upb_MiniTableField* field, size_t key_size, size_t val_size, upb_Arena* arena) { UPB_PRIVATE(_upb_MiniTableField_CheckIsMap)(field); _upb_Message_AssertMapIsUntagged(msg, field); - upb_Map* map = NULL; - upb_Map* default_map_value = NULL; + struct upb_Map* map = NULL; + struct upb_Map* default_map_value = NULL; _upb_Message_GetNonExtensionField(msg, field, &default_map_value, &map); if (!map) { map = _upb_Map_New(arena, key_size, val_size); @@ -2892,7 +2860,7 @@ struct upb_Array { size_t UPB_PRIVATE(capacity); // Allocated storage. Measured in elements. }; -UPB_INLINE void UPB_PRIVATE(_upb_Array_SetTaggedPtr)(upb_Array* array, +UPB_INLINE void UPB_PRIVATE(_upb_Array_SetTaggedPtr)(struct upb_Array* array, void* data, size_t lg2) { UPB_ASSERT(lg2 != 1); UPB_ASSERT(lg2 <= 4); @@ -2900,29 +2868,31 @@ UPB_INLINE void UPB_PRIVATE(_upb_Array_SetTaggedPtr)(upb_Array* array, array->data = (uintptr_t)data | bits; } -UPB_INLINE size_t UPB_PRIVATE(_upb_Array_ElemSizeLg2)(const upb_Array* array) { +UPB_INLINE size_t +UPB_PRIVATE(_upb_Array_ElemSizeLg2)(const struct upb_Array* array) { const size_t bits = array->data & _UPB_ARRAY_MASK_LG2; const size_t lg2 = bits + (bits != 0); return lg2; } -UPB_INLINE const void* _upb_array_constptr(const upb_Array* array) { +UPB_INLINE const void* _upb_array_constptr(const struct upb_Array* array) { UPB_PRIVATE(_upb_Array_ElemSizeLg2)(array); // Check assertions. return (void*)(array->data & ~(uintptr_t)_UPB_ARRAY_MASK_ALL); } -UPB_INLINE void* _upb_array_ptr(upb_Array* array) { +UPB_INLINE void* _upb_array_ptr(struct upb_Array* array) { return (void*)_upb_array_constptr(array); } -UPB_INLINE upb_Array* UPB_PRIVATE(_upb_Array_New)(upb_Arena* arena, - size_t init_capacity, - int elem_size_lg2) { +UPB_INLINE struct upb_Array* UPB_PRIVATE(_upb_Array_New)(upb_Arena* arena, + size_t init_capacity, + int elem_size_lg2) { UPB_ASSERT(elem_size_lg2 != 1); UPB_ASSERT(elem_size_lg2 <= 4); - const size_t array_size = UPB_ALIGN_UP(sizeof(upb_Array), UPB_MALLOC_ALIGN); + const size_t array_size = + UPB_ALIGN_UP(sizeof(struct upb_Array), UPB_MALLOC_ALIGN); const size_t bytes = array_size + (init_capacity << elem_size_lg2); - upb_Array* array = (upb_Array*)upb_Arena_Malloc(arena, bytes); + struct upb_Array* array = (struct upb_Array*)upb_Arena_Malloc(arena, bytes); if (!array) return NULL; UPB_PRIVATE(_upb_Array_SetTaggedPtr) (array, UPB_PTR_AT(array, array_size, void), elem_size_lg2); @@ -2932,19 +2902,19 @@ UPB_INLINE upb_Array* UPB_PRIVATE(_upb_Array_New)(upb_Arena* arena, } // Resizes the capacity of the array to be at least min_size. -bool UPB_PRIVATE(_upb_Array_Realloc)(upb_Array* array, size_t min_size, +bool UPB_PRIVATE(_upb_Array_Realloc)(struct upb_Array* array, size_t min_size, upb_Arena* arena); -UPB_INLINE bool UPB_PRIVATE(_upb_Array_Reserve)(upb_Array* array, size_t size, - upb_Arena* arena) { +UPB_INLINE bool UPB_PRIVATE(_upb_Array_Reserve)(struct upb_Array* array, + size_t size, upb_Arena* arena) { if (array->UPB_PRIVATE(capacity) < size) return UPB_PRIVATE(_upb_Array_Realloc)(array, size, arena); return true; } // Resize without initializing new elements. -UPB_INLINE bool _upb_Array_ResizeUninitialized(upb_Array* array, size_t size, - upb_Arena* arena) { +UPB_INLINE bool _upb_Array_ResizeUninitialized(struct upb_Array* array, + size_t size, upb_Arena* arena) { UPB_ASSERT(size <= array->UPB_ONLYBITS(size) || arena); // Allow NULL arena when shrinking. if (!UPB_PRIVATE(_upb_Array_Reserve)(array, size, arena)) return false; @@ -2955,7 +2925,7 @@ UPB_INLINE bool _upb_Array_ResizeUninitialized(upb_Array* array, size_t size, // This function is intended for situations where elem_size is compile-time // constant or a known expression of the form (1 << lg2), so that the expression // i*elem_size does not result in an actual multiplication. -UPB_INLINE void UPB_PRIVATE(_upb_Array_Set)(upb_Array* array, size_t i, +UPB_INLINE void UPB_PRIVATE(_upb_Array_Set)(struct upb_Array* array, size_t i, const void* data, size_t elem_size) { UPB_ASSERT(i < array->UPB_ONLYBITS(size)); @@ -3499,6 +3469,43 @@ UPB_INLINE void _upb_msg_map_set_value(void* msg, const void* val, #endif /* UPB_MESSAGE_MAP_GENCODE_UTIL_H_ */ +// Public APIs for message operations that do not depend on the schema. +// +// MiniTable-based accessors live in accessors.h. + +#ifndef UPB_MESSAGE_MESSAGE_H_ +#define UPB_MESSAGE_MESSAGE_H_ + +#include + + +// Must be last. + +typedef struct upb_Extension upb_Extension; + +#ifdef __cplusplus +extern "C" { +#endif + +// Creates a new message with the given mini_table on the given arena. +UPB_API upb_Message* upb_Message_New(const upb_MiniTable* m, upb_Arena* arena); + +// Returns a reference to the message's unknown data. +const char* upb_Message_GetUnknown(const upb_Message* msg, size_t* len); + +// Removes partial unknown data from message. +void upb_Message_DeleteUnknown(upb_Message* msg, const char* data, size_t len); + +// Returns the number of extensions present in this message. +size_t upb_Message_ExtensionCount(const upb_Message* msg); + +#ifdef __cplusplus +} /* extern "C" */ +#endif + + +#endif /* UPB_MESSAGE_MESSAGE_H_ */ + #ifndef UPB_MINI_TABLE_DECODE_H_ #define UPB_MINI_TABLE_DECODE_H_ @@ -12645,9 +12652,9 @@ UPB_INLINE bool _upb_sortedmap_next(_upb_mapsorter* s, const upb_Map* map, UPB_INLINE bool _upb_sortedmap_nextext(_upb_mapsorter* s, _upb_sortedmap* sorted, - const upb_Extension** ext) { + const struct upb_Extension** ext) { if (sorted->pos == sorted->end) return false; - *ext = (const upb_Extension*)s->entries[sorted->pos++]; + *ext = (const struct upb_Extension*)s->entries[sorted->pos++]; return true; } @@ -12659,8 +12666,9 @@ UPB_INLINE void _upb_mapsorter_popmap(_upb_mapsorter* s, bool _upb_mapsorter_pushmap(_upb_mapsorter* s, upb_FieldType key_type, const upb_Map* map, _upb_sortedmap* sorted); -bool _upb_mapsorter_pushexts(_upb_mapsorter* s, const upb_Extension* exts, - size_t count, _upb_sortedmap* sorted); +bool _upb_mapsorter_pushexts(_upb_mapsorter* s, + const struct upb_Extension* exts, size_t count, + _upb_sortedmap* sorted); #ifdef __cplusplus } /* extern "C" */ diff --git a/ruby/ext/google/protobuf_c/ruby-upb.c b/ruby/ext/google/protobuf_c/ruby-upb.c index a6c49cbdcc81b..3133ea760be85 100644 --- a/ruby/ext/google/protobuf_c/ruby-upb.c +++ b/ruby/ext/google/protobuf_c/ruby-upb.c @@ -5725,7 +5725,7 @@ const double kUpb_NaN = NAN; static const size_t realloc_overhead = sizeof(upb_Message_InternalData); -bool UPB_PRIVATE(_upb_Message_Realloc)(upb_Message* msg, size_t need, +bool UPB_PRIVATE(_upb_Message_Realloc)(struct upb_Message* msg, size_t need, upb_Arena* arena) { upb_Message_Internal* in = upb_Message_Getinternal(msg); if (!in->internal) { diff --git a/ruby/ext/google/protobuf_c/ruby-upb.h b/ruby/ext/google/protobuf_c/ruby-upb.h index 55f35955d2e84..29f0e80b91eac 100755 --- a/ruby/ext/google/protobuf_c/ruby-upb.h +++ b/ruby/ext/google/protobuf_c/ruby-upb.h @@ -909,7 +909,7 @@ typedef union { uint64_t uint64_val; const struct upb_Array* array_val; const struct upb_Map* map_val; - const upb_Message* msg_val; + const struct upb_Message* msg_val; upb_StringView str_val; // EXPERIMENTAL: A tagged upb_Message*. Users must use this instead of @@ -922,7 +922,7 @@ typedef union { typedef union { struct upb_Array* array; struct upb_Map* map; - upb_Message* msg; + struct upb_Message* msg; } upb_MutableMessageValue; #endif /* UPB_MESSAGE_VALUE_H_ */ @@ -997,15 +997,36 @@ UPB_API void* upb_Array_MutableDataPtr(upb_Array* arr); #define UPB_MESSAGE_INTERNAL_EXTENSION_H_ -// Public APIs for message operations that do not depend on the schema. -// -// MiniTable-based accessors live in accessors.h. +/* +** Our memory representation for parsing tables and messages themselves. +** Functions in this file are used by generated code and possibly reflection. +** +** The definitions in this file are internal to upb. +**/ -#ifndef UPB_MESSAGE_MESSAGE_H_ -#define UPB_MESSAGE_MESSAGE_H_ +#ifndef UPB_MESSAGE_INTERNAL_H_ +#define UPB_MESSAGE_INTERNAL_H_ -#include +#include +#include + + +#ifndef UPB_MINI_TABLE_INTERNAL_TYPES_H_ +#define UPB_MINI_TABLE_INTERNAL_TYPES_H_ + +typedef struct upb_Message_InternalData upb_Message_InternalData; + +typedef struct { + union { + upb_Message_InternalData* internal; + + // Force 8-byte alignment, since the data members may contain members that + // require 8-byte alignment. + double d; + }; +} upb_Message_Internal; +#endif // UPB_MINI_TABLE_INTERNAL_TYPES_H_ #ifndef UPB_MINI_TABLE_MESSAGE_H_ #define UPB_MINI_TABLE_MESSAGE_H_ @@ -1712,30 +1733,83 @@ bool upb_MiniTable_NextOneofField(const upb_MiniTable* m, // Must be last. -typedef struct upb_Extension upb_Extension; - #ifdef __cplusplus extern "C" { #endif -// Creates a new message with the given mini_table on the given arena. -UPB_API upb_Message* upb_Message_New(const upb_MiniTable* m, upb_Arena* arena); +extern const float kUpb_FltInfinity; +extern const double kUpb_Infinity; +extern const double kUpb_NaN; -// Returns a reference to the message's unknown data. -const char* upb_Message_GetUnknown(const upb_Message* msg, size_t* len); +/* Internal members of a upb_Message that track unknown fields and/or + * extensions. We can change this without breaking binary compatibility. We put + * these before the user's data. The user's upb_Message* points after the + * upb_Message_Internal. */ -// Removes partial unknown data from message. -void upb_Message_DeleteUnknown(upb_Message* msg, const char* data, size_t len); +struct upb_Message_InternalData { + /* Total size of this structure, including the data that follows. + * Must be aligned to 8, which is alignof(upb_Extension) */ + uint32_t size; -// Returns the number of extensions present in this message. -size_t upb_Message_ExtensionCount(const upb_Message* msg); + /* Offsets relative to the beginning of this structure. + * + * Unknown data grows forward from the beginning to unknown_end. + * Extension data grows backward from size to ext_begin. + * When the two meet, we're out of data and have to realloc. + * + * If we imagine that the final member of this struct is: + * char data[size - overhead]; // overhead = + * sizeof(upb_Message_InternalData) + * + * Then we have: + * unknown data: data[0 .. (unknown_end - overhead)] + * extensions data: data[(ext_begin - overhead) .. (size - overhead)] */ + uint32_t unknown_end; + uint32_t ext_begin; + /* Data follows, as if there were an array: + * char data[size - sizeof(upb_Message_InternalData)]; */ +}; + +UPB_INLINE size_t upb_msg_sizeof(const upb_MiniTable* m) { + return m->UPB_PRIVATE(size) + sizeof(upb_Message_Internal); +} + +// Inline version upb_Message_New(), for internal use. +UPB_INLINE struct upb_Message* _upb_Message_New(const upb_MiniTable* mini_table, + upb_Arena* arena) { + size_t size = upb_msg_sizeof(mini_table); + void* mem = upb_Arena_Malloc(arena, size + sizeof(upb_Message_Internal)); + if (UPB_UNLIKELY(!mem)) return NULL; + struct upb_Message* msg = + UPB_PTR_AT(mem, sizeof(upb_Message_Internal), struct upb_Message); + memset(mem, 0, size); + return msg; +} + +UPB_INLINE upb_Message_Internal* upb_Message_Getinternal( + const struct upb_Message* msg) { + ptrdiff_t size = sizeof(upb_Message_Internal); + return (upb_Message_Internal*)((char*)msg - size); +} + +// Discards the unknown fields for this message only. +void _upb_Message_DiscardUnknown_shallow(struct upb_Message* msg); + +// Adds unknown data (serialized protobuf data) to the given message. +// The data is copied into the message instance. +bool UPB_PRIVATE(_upb_Message_AddUnknown)(struct upb_Message* msg, + const char* data, size_t len, + upb_Arena* arena); + +bool UPB_PRIVATE(_upb_Message_Realloc)(struct upb_Message* msg, size_t need, + upb_Arena* arena); #ifdef __cplusplus } /* extern "C" */ #endif -#endif /* UPB_MESSAGE_MESSAGE_H_ */ +#endif /* UPB_MESSAGE_INTERNAL_H_ */ #ifndef UPB_MINI_TABLE_EXTENSION_H_ #define UPB_MINI_TABLE_EXTENSION_H_ @@ -1852,18 +1926,19 @@ extern "C" { // Adds the given extension data to the given message. // |ext| is copied into the message instance. // This logically replaces any previously-added extension with this number. -upb_Extension* _upb_Message_GetOrCreateExtension( - upb_Message* msg, const upb_MiniTableExtension* ext, upb_Arena* arena); +struct upb_Extension* _upb_Message_GetOrCreateExtension( + struct upb_Message* msg, const upb_MiniTableExtension* ext, + upb_Arena* arena); // Returns an array of extensions for this message. // Note: the array is ordered in reverse relative to the order of creation. -const upb_Extension* UPB_PRIVATE(_upb_Message_Getexts)(const upb_Message* msg, - size_t* count); +const struct upb_Extension* UPB_PRIVATE(_upb_Message_Getexts)( + const struct upb_Message* msg, size_t* count); // Returns an extension for a message with a given mini table, // or NULL if no extension exists with this mini table. -const upb_Extension* _upb_Message_Getext(const upb_Message* msg, - const upb_MiniTableExtension* ext); +const struct upb_Extension* _upb_Message_Getext( + const struct upb_Message* msg, const upb_MiniTableExtension* ext); #ifdef __cplusplus } /* extern "C" */ @@ -2352,7 +2427,7 @@ UPB_INLINE void _upb_map_fromvalue(upb_value val, void* out, size_t size) { } } -UPB_INLINE void* _upb_map_next(const upb_Map* map, size_t* iter) { +UPB_INLINE void* _upb_map_next(const struct upb_Map* map, size_t* iter) { upb_strtable_iter it; it.t = &map->table; it.index = *iter; @@ -2362,17 +2437,17 @@ UPB_INLINE void* _upb_map_next(const upb_Map* map, size_t* iter) { return (void*)str_tabent(&it); } -UPB_INLINE void _upb_Map_Clear(upb_Map* map) { +UPB_INLINE void _upb_Map_Clear(struct upb_Map* map) { upb_strtable_clear(&map->table); } -UPB_INLINE bool _upb_Map_Delete(upb_Map* map, const void* key, size_t key_size, - upb_value* val) { +UPB_INLINE bool _upb_Map_Delete(struct upb_Map* map, const void* key, + size_t key_size, upb_value* val) { upb_StringView k = _upb_map_tokey(key, key_size); return upb_strtable_remove2(&map->table, k.data, k.size, val); } -UPB_INLINE bool _upb_Map_Get(const upb_Map* map, const void* key, +UPB_INLINE bool _upb_Map_Get(const struct upb_Map* map, const void* key, size_t key_size, void* val, size_t val_size) { upb_value tabval; upb_StringView k = _upb_map_tokey(key, key_size); @@ -2383,9 +2458,10 @@ UPB_INLINE bool _upb_Map_Get(const upb_Map* map, const void* key, return ret; } -UPB_INLINE upb_MapInsertStatus _upb_Map_Insert(upb_Map* map, const void* key, - size_t key_size, void* val, - size_t val_size, upb_Arena* a) { +UPB_INLINE upb_MapInsertStatus _upb_Map_Insert(struct upb_Map* map, + const void* key, size_t key_size, + void* val, size_t val_size, + upb_Arena* a) { upb_StringView strkey = _upb_map_tokey(key, key_size); upb_value tabval = {0}; if (!_upb_map_tovalue(val, val_size, &tabval, a)) { @@ -2402,7 +2478,7 @@ UPB_INLINE upb_MapInsertStatus _upb_Map_Insert(upb_Map* map, const void* key, : kUpb_MapInsertStatus_Inserted; } -UPB_INLINE size_t _upb_Map_Size(const upb_Map* map) { +UPB_INLINE size_t _upb_Map_Size(const struct upb_Map* map) { return map->table.t.count; } @@ -2414,7 +2490,7 @@ UPB_INLINE size_t _upb_Map_CTypeSize(upb_CType ctype) { } // Creates a new map on the given arena with this key/value type. -upb_Map* _upb_Map_New(upb_Arena* a, size_t key_size, size_t value_size); +struct upb_Map* _upb_Map_New(upb_Arena* a, size_t key_size, size_t value_size); #ifdef __cplusplus } /* extern "C" */ @@ -2423,115 +2499,6 @@ upb_Map* _upb_Map_New(upb_Arena* a, size_t key_size, size_t value_size); #endif /* UPB_MESSAGE_INTERNAL_MAP_H_ */ -/* -** Our memory representation for parsing tables and messages themselves. -** Functions in this file are used by generated code and possibly reflection. -** -** The definitions in this file are internal to upb. -**/ - -#ifndef UPB_MESSAGE_INTERNAL_H_ -#define UPB_MESSAGE_INTERNAL_H_ - -#include -#include - - -#ifndef UPB_MINI_TABLE_INTERNAL_TYPES_H_ -#define UPB_MINI_TABLE_INTERNAL_TYPES_H_ - -typedef struct upb_Message_InternalData upb_Message_InternalData; - -typedef struct { - union { - upb_Message_InternalData* internal; - - // Force 8-byte alignment, since the data members may contain members that - // require 8-byte alignment. - double d; - }; -} upb_Message_Internal; - -#endif // UPB_MINI_TABLE_INTERNAL_TYPES_H_ - -// Must be last. - -#ifdef __cplusplus -extern "C" { -#endif - -extern const float kUpb_FltInfinity; -extern const double kUpb_Infinity; -extern const double kUpb_NaN; - -/* Internal members of a upb_Message that track unknown fields and/or - * extensions. We can change this without breaking binary compatibility. We put - * these before the user's data. The user's upb_Message* points after the - * upb_Message_Internal. */ - -struct upb_Message_InternalData { - /* Total size of this structure, including the data that follows. - * Must be aligned to 8, which is alignof(upb_Extension) */ - uint32_t size; - - /* Offsets relative to the beginning of this structure. - * - * Unknown data grows forward from the beginning to unknown_end. - * Extension data grows backward from size to ext_begin. - * When the two meet, we're out of data and have to realloc. - * - * If we imagine that the final member of this struct is: - * char data[size - overhead]; // overhead = - * sizeof(upb_Message_InternalData) - * - * Then we have: - * unknown data: data[0 .. (unknown_end - overhead)] - * extensions data: data[(ext_begin - overhead) .. (size - overhead)] */ - uint32_t unknown_end; - uint32_t ext_begin; - /* Data follows, as if there were an array: - * char data[size - sizeof(upb_Message_InternalData)]; */ -}; - -UPB_INLINE size_t upb_msg_sizeof(const upb_MiniTable* m) { - return m->UPB_PRIVATE(size) + sizeof(upb_Message_Internal); -} - -// Inline version upb_Message_New(), for internal use. -UPB_INLINE upb_Message* _upb_Message_New(const upb_MiniTable* mini_table, - upb_Arena* arena) { - size_t size = upb_msg_sizeof(mini_table); - void* mem = upb_Arena_Malloc(arena, size + sizeof(upb_Message_Internal)); - if (UPB_UNLIKELY(!mem)) return NULL; - upb_Message* msg = UPB_PTR_AT(mem, sizeof(upb_Message_Internal), upb_Message); - memset(mem, 0, size); - return msg; -} - -UPB_INLINE upb_Message_Internal* upb_Message_Getinternal( - const upb_Message* msg) { - ptrdiff_t size = sizeof(upb_Message_Internal); - return (upb_Message_Internal*)((char*)msg - size); -} - -// Discards the unknown fields for this message only. -void _upb_Message_DiscardUnknown_shallow(upb_Message* msg); - -// Adds unknown data (serialized protobuf data) to the given message. -// The data is copied into the message instance. -bool UPB_PRIVATE(_upb_Message_AddUnknown)(upb_Message* msg, const char* data, - size_t len, upb_Arena* arena); - -bool UPB_PRIVATE(_upb_Message_Realloc)(upb_Message* msg, size_t need, - upb_Arena* arena); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - - -#endif /* UPB_MESSAGE_INTERNAL_H_ */ - // Must be last. #if defined(__GNUC__) && !defined(__clang__) @@ -2738,7 +2705,7 @@ static UPB_FORCEINLINE void _upb_Message_GetNonExtensionField( UPB_INLINE void _upb_Message_GetExtensionField( const upb_Message* msg, const upb_MiniTableExtension* mt_ext, const void* default_val, void* val) { - const upb_Extension* ext = _upb_Message_Getext(msg, mt_ext); + const struct upb_Extension* ext = _upb_Message_Getext(msg, mt_ext); const upb_MiniTableField* f = &mt_ext->UPB_PRIVATE(field); UPB_ASSUME(upb_MiniTableField_IsExtension(f)); @@ -2788,7 +2755,7 @@ UPB_INLINE bool _upb_Message_SetExtensionField( upb_Message* msg, const upb_MiniTableExtension* mt_ext, const void* val, upb_Arena* a) { UPB_ASSERT(a); - upb_Extension* ext = _upb_Message_GetOrCreateExtension(msg, mt_ext, a); + struct upb_Extension* ext = _upb_Message_GetOrCreateExtension(msg, mt_ext, a); if (!ext) return false; UPB_PRIVATE(_upb_MiniTableField_DataCopy) (&mt_ext->UPB_PRIVATE(field), &ext->data, val); @@ -2799,12 +2766,13 @@ UPB_INLINE void _upb_Message_ClearExtensionField( upb_Message* msg, const upb_MiniTableExtension* ext_l) { upb_Message_Internal* in = upb_Message_Getinternal(msg); if (!in->internal) return; - const upb_Extension* base = - UPB_PTR_AT(in->internal, in->internal->ext_begin, upb_Extension); - upb_Extension* ext = (upb_Extension*)_upb_Message_Getext(msg, ext_l); + const struct upb_Extension* base = + UPB_PTR_AT(in->internal, in->internal->ext_begin, struct upb_Extension); + struct upb_Extension* ext = + (struct upb_Extension*)_upb_Message_Getext(msg, ext_l); if (ext) { *ext = *base; - in->internal->ext_begin += sizeof(upb_Extension); + in->internal->ext_begin += sizeof(struct upb_Extension); } } @@ -2834,13 +2802,13 @@ UPB_INLINE void _upb_Message_AssertMapIsUntagged( #endif } -UPB_INLINE upb_Map* _upb_Message_GetOrCreateMutableMap( +UPB_INLINE struct upb_Map* _upb_Message_GetOrCreateMutableMap( upb_Message* msg, const upb_MiniTableField* field, size_t key_size, size_t val_size, upb_Arena* arena) { UPB_PRIVATE(_upb_MiniTableField_CheckIsMap)(field); _upb_Message_AssertMapIsUntagged(msg, field); - upb_Map* map = NULL; - upb_Map* default_map_value = NULL; + struct upb_Map* map = NULL; + struct upb_Map* default_map_value = NULL; _upb_Message_GetNonExtensionField(msg, field, &default_map_value, &map); if (!map) { map = _upb_Map_New(arena, key_size, val_size); @@ -2894,7 +2862,7 @@ struct upb_Array { size_t UPB_PRIVATE(capacity); // Allocated storage. Measured in elements. }; -UPB_INLINE void UPB_PRIVATE(_upb_Array_SetTaggedPtr)(upb_Array* array, +UPB_INLINE void UPB_PRIVATE(_upb_Array_SetTaggedPtr)(struct upb_Array* array, void* data, size_t lg2) { UPB_ASSERT(lg2 != 1); UPB_ASSERT(lg2 <= 4); @@ -2902,29 +2870,31 @@ UPB_INLINE void UPB_PRIVATE(_upb_Array_SetTaggedPtr)(upb_Array* array, array->data = (uintptr_t)data | bits; } -UPB_INLINE size_t UPB_PRIVATE(_upb_Array_ElemSizeLg2)(const upb_Array* array) { +UPB_INLINE size_t +UPB_PRIVATE(_upb_Array_ElemSizeLg2)(const struct upb_Array* array) { const size_t bits = array->data & _UPB_ARRAY_MASK_LG2; const size_t lg2 = bits + (bits != 0); return lg2; } -UPB_INLINE const void* _upb_array_constptr(const upb_Array* array) { +UPB_INLINE const void* _upb_array_constptr(const struct upb_Array* array) { UPB_PRIVATE(_upb_Array_ElemSizeLg2)(array); // Check assertions. return (void*)(array->data & ~(uintptr_t)_UPB_ARRAY_MASK_ALL); } -UPB_INLINE void* _upb_array_ptr(upb_Array* array) { +UPB_INLINE void* _upb_array_ptr(struct upb_Array* array) { return (void*)_upb_array_constptr(array); } -UPB_INLINE upb_Array* UPB_PRIVATE(_upb_Array_New)(upb_Arena* arena, - size_t init_capacity, - int elem_size_lg2) { +UPB_INLINE struct upb_Array* UPB_PRIVATE(_upb_Array_New)(upb_Arena* arena, + size_t init_capacity, + int elem_size_lg2) { UPB_ASSERT(elem_size_lg2 != 1); UPB_ASSERT(elem_size_lg2 <= 4); - const size_t array_size = UPB_ALIGN_UP(sizeof(upb_Array), UPB_MALLOC_ALIGN); + const size_t array_size = + UPB_ALIGN_UP(sizeof(struct upb_Array), UPB_MALLOC_ALIGN); const size_t bytes = array_size + (init_capacity << elem_size_lg2); - upb_Array* array = (upb_Array*)upb_Arena_Malloc(arena, bytes); + struct upb_Array* array = (struct upb_Array*)upb_Arena_Malloc(arena, bytes); if (!array) return NULL; UPB_PRIVATE(_upb_Array_SetTaggedPtr) (array, UPB_PTR_AT(array, array_size, void), elem_size_lg2); @@ -2934,19 +2904,19 @@ UPB_INLINE upb_Array* UPB_PRIVATE(_upb_Array_New)(upb_Arena* arena, } // Resizes the capacity of the array to be at least min_size. -bool UPB_PRIVATE(_upb_Array_Realloc)(upb_Array* array, size_t min_size, +bool UPB_PRIVATE(_upb_Array_Realloc)(struct upb_Array* array, size_t min_size, upb_Arena* arena); -UPB_INLINE bool UPB_PRIVATE(_upb_Array_Reserve)(upb_Array* array, size_t size, - upb_Arena* arena) { +UPB_INLINE bool UPB_PRIVATE(_upb_Array_Reserve)(struct upb_Array* array, + size_t size, upb_Arena* arena) { if (array->UPB_PRIVATE(capacity) < size) return UPB_PRIVATE(_upb_Array_Realloc)(array, size, arena); return true; } // Resize without initializing new elements. -UPB_INLINE bool _upb_Array_ResizeUninitialized(upb_Array* array, size_t size, - upb_Arena* arena) { +UPB_INLINE bool _upb_Array_ResizeUninitialized(struct upb_Array* array, + size_t size, upb_Arena* arena) { UPB_ASSERT(size <= array->UPB_ONLYBITS(size) || arena); // Allow NULL arena when shrinking. if (!UPB_PRIVATE(_upb_Array_Reserve)(array, size, arena)) return false; @@ -2957,7 +2927,7 @@ UPB_INLINE bool _upb_Array_ResizeUninitialized(upb_Array* array, size_t size, // This function is intended for situations where elem_size is compile-time // constant or a known expression of the form (1 << lg2), so that the expression // i*elem_size does not result in an actual multiplication. -UPB_INLINE void UPB_PRIVATE(_upb_Array_Set)(upb_Array* array, size_t i, +UPB_INLINE void UPB_PRIVATE(_upb_Array_Set)(struct upb_Array* array, size_t i, const void* data, size_t elem_size) { UPB_ASSERT(i < array->UPB_ONLYBITS(size)); @@ -3501,6 +3471,43 @@ UPB_INLINE void _upb_msg_map_set_value(void* msg, const void* val, #endif /* UPB_MESSAGE_MAP_GENCODE_UTIL_H_ */ +// Public APIs for message operations that do not depend on the schema. +// +// MiniTable-based accessors live in accessors.h. + +#ifndef UPB_MESSAGE_MESSAGE_H_ +#define UPB_MESSAGE_MESSAGE_H_ + +#include + + +// Must be last. + +typedef struct upb_Extension upb_Extension; + +#ifdef __cplusplus +extern "C" { +#endif + +// Creates a new message with the given mini_table on the given arena. +UPB_API upb_Message* upb_Message_New(const upb_MiniTable* m, upb_Arena* arena); + +// Returns a reference to the message's unknown data. +const char* upb_Message_GetUnknown(const upb_Message* msg, size_t* len); + +// Removes partial unknown data from message. +void upb_Message_DeleteUnknown(upb_Message* msg, const char* data, size_t len); + +// Returns the number of extensions present in this message. +size_t upb_Message_ExtensionCount(const upb_Message* msg); + +#ifdef __cplusplus +} /* extern "C" */ +#endif + + +#endif /* UPB_MESSAGE_MESSAGE_H_ */ + #ifndef UPB_MINI_TABLE_DECODE_H_ #define UPB_MINI_TABLE_DECODE_H_ @@ -12417,9 +12424,9 @@ UPB_INLINE bool _upb_sortedmap_next(_upb_mapsorter* s, const upb_Map* map, UPB_INLINE bool _upb_sortedmap_nextext(_upb_mapsorter* s, _upb_sortedmap* sorted, - const upb_Extension** ext) { + const struct upb_Extension** ext) { if (sorted->pos == sorted->end) return false; - *ext = (const upb_Extension*)s->entries[sorted->pos++]; + *ext = (const struct upb_Extension*)s->entries[sorted->pos++]; return true; } @@ -12431,8 +12438,9 @@ UPB_INLINE void _upb_mapsorter_popmap(_upb_mapsorter* s, bool _upb_mapsorter_pushmap(_upb_mapsorter* s, upb_FieldType key_type, const upb_Map* map, _upb_sortedmap* sorted); -bool _upb_mapsorter_pushexts(_upb_mapsorter* s, const upb_Extension* exts, - size_t count, _upb_sortedmap* sorted); +bool _upb_mapsorter_pushexts(_upb_mapsorter* s, + const struct upb_Extension* exts, size_t count, + _upb_sortedmap* sorted); #ifdef __cplusplus } /* extern "C" */ From 442e079677780f5551cb0f5ef5a78f35e5ee2f5f Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Wed, 27 Dec 2023 21:05:28 -0800 Subject: [PATCH 118/255] Removed Ruby compatibility tests. In Ruby protobuf 4.26.0 we are intentionally breaking compatibility with our generated code from Protobuf 3.0.0. So these tests are now obsolete. PiperOrigin-RevId: 594157323 --- ruby/compatibility_tests/v3.0.0/BUILD.bazel | 34 - ruby/compatibility_tests/v3.0.0/README.md | 5 - ruby/compatibility_tests/v3.0.0/Rakefile | 26 - ruby/compatibility_tests/v3.0.0/test.sh | 17 - .../v3.0.0/tests/BUILD.bazel | 64 - .../compatibility_tests/v3.0.0/tests/basic.rb | 1133 ----------------- .../v3.0.0/tests/generated_code.proto | 67 - .../v3.0.0/tests/generated_code_test.rb | 19 - .../v3.0.0/tests/repeated_field_test.rb | 647 ---------- .../v3.0.0/tests/stress.rb | 38 - .../v3.0.0/tests/test_import.proto | 5 - 11 files changed, 2055 deletions(-) delete mode 100644 ruby/compatibility_tests/v3.0.0/BUILD.bazel delete mode 100644 ruby/compatibility_tests/v3.0.0/README.md delete mode 100644 ruby/compatibility_tests/v3.0.0/Rakefile delete mode 100755 ruby/compatibility_tests/v3.0.0/test.sh delete mode 100644 ruby/compatibility_tests/v3.0.0/tests/BUILD.bazel delete mode 100755 ruby/compatibility_tests/v3.0.0/tests/basic.rb delete mode 100644 ruby/compatibility_tests/v3.0.0/tests/generated_code.proto delete mode 100755 ruby/compatibility_tests/v3.0.0/tests/generated_code_test.rb delete mode 100755 ruby/compatibility_tests/v3.0.0/tests/repeated_field_test.rb delete mode 100755 ruby/compatibility_tests/v3.0.0/tests/stress.rb delete mode 100644 ruby/compatibility_tests/v3.0.0/tests/test_import.proto diff --git a/ruby/compatibility_tests/v3.0.0/BUILD.bazel b/ruby/compatibility_tests/v3.0.0/BUILD.bazel deleted file mode 100644 index 60c4985f39774..0000000000000 --- a/ruby/compatibility_tests/v3.0.0/BUILD.bazel +++ /dev/null @@ -1,34 +0,0 @@ -load("@rules_pkg//:mappings.bzl", "pkg_files", "strip_prefix") - -################################################################################ -# Distribution files -############################################################################ - -genrule( - name = "protoc-compat-gen", - outs = ["protoc"], - cmd = """ - PROTOC_BINARY_NAME="protoc-3.0.0-linux-x86_64.exe" - if [ `uname` = "Darwin" ]; then - PROTOC_BINARY_NAME="protoc-3.0.0-osx-x86_64.exe" - fi - wget https://repo1.maven.org/maven2/com/google/protobuf/protoc/3.0.0/$${PROTOC_BINARY_NAME} -O protoc - chmod +x protoc - mv protoc $@ - """, - executable = True, - visibility = ["//ruby/compatibility_tests/v3.0.0:__subpackages__"], -) - -pkg_files( - name = "dist_files", - srcs = [ - "BUILD.bazel", - "README.md", - "Rakefile", - "test.sh", - "//ruby/compatibility_tests/v3.0.0/tests:dist_files", - ], - strip_prefix = strip_prefix.from_root(""), - visibility = ["//pkg:__pkg__"], -) diff --git a/ruby/compatibility_tests/v3.0.0/README.md b/ruby/compatibility_tests/v3.0.0/README.md deleted file mode 100644 index 06d981c90ddbc..0000000000000 --- a/ruby/compatibility_tests/v3.0.0/README.md +++ /dev/null @@ -1,5 +0,0 @@ -# Protobuf Ruby Compatibility Tests - -This directory contains a snapshot of protobuf ruby 3.0.0 unittest code and -test scripts used to verifies whether the latest version of protobuf is -still compatible with 3.0.0 generated code. diff --git a/ruby/compatibility_tests/v3.0.0/Rakefile b/ruby/compatibility_tests/v3.0.0/Rakefile deleted file mode 100644 index fee72b415cb01..0000000000000 --- a/ruby/compatibility_tests/v3.0.0/Rakefile +++ /dev/null @@ -1,26 +0,0 @@ -require "rake/testtask" - -# Proto for tests. -genproto_output = [] - -genproto_output << "tests/generated_code.rb" -genproto_output << "tests/test_import.rb" -file "tests/generated_code.rb" => "tests/generated_code.proto" do |file_task| - sh "./protoc --ruby_out=. tests/generated_code.proto" -end - -file "tests/test_import.rb" => "tests/test_import.proto" do |file_task| - sh "./protoc --ruby_out=. tests/test_import.proto" -end - -task :genproto => genproto_output - -task :clean do - sh "rm -f #{genproto_output.join(' ')}" -end - -Rake::TestTask.new(:test => :genproto) do |t| - t.test_files = FileList["tests/*.rb"] -end - -task :default => [:test] diff --git a/ruby/compatibility_tests/v3.0.0/test.sh b/ruby/compatibility_tests/v3.0.0/test.sh deleted file mode 100755 index 1a9b798422393..0000000000000 --- a/ruby/compatibility_tests/v3.0.0/test.sh +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/bash - -set -ex - -# Change to the script's directory -cd $(dirname $0) - -# Download 3.0.0 version of protoc -PROTOC_BINARY_NAME="protoc-3.0.0-linux-x86_64.exe" -if [ `uname` = "Darwin" ]; then - PROTOC_BINARY_NAME="protoc-3.0.0-osx-x86_64.exe" -fi -wget https://repo1.maven.org/maven2/com/google/protobuf/protoc/3.0.0/${PROTOC_BINARY_NAME} -O protoc -chmod +x protoc - -# Run tests -RUBYLIB=../../lib:. rake test diff --git a/ruby/compatibility_tests/v3.0.0/tests/BUILD.bazel b/ruby/compatibility_tests/v3.0.0/tests/BUILD.bazel deleted file mode 100644 index 697f876991fd2..0000000000000 --- a/ruby/compatibility_tests/v3.0.0/tests/BUILD.bazel +++ /dev/null @@ -1,64 +0,0 @@ -load("@rules_pkg//:mappings.bzl", "pkg_files", "strip_prefix") -load("@rules_ruby//ruby:defs.bzl", "ruby_test") -load("//ruby:defs.bzl", "internal_ruby_proto_library") - -internal_ruby_proto_library( - name = "test_ruby_protos", - srcs = glob(["*.proto"]), - includes = ["."], - protoc = "//ruby/compatibility_tests/v3.0.0:protoc", -) - -ruby_test( - name = "basic", - srcs = ["basic.rb"], - deps = [ - ":test_ruby_protos", - "//ruby:protobuf", - "@protobuf_bundle//:test-unit", - ], -) - -ruby_test( - name = "generated_code_test", - srcs = ["generated_code_test.rb"], - deps = [ - ":test_ruby_protos", - "//ruby:protobuf", - "@protobuf_bundle//:test-unit", - ], -) - -ruby_test( - name = "repeated_field_test", - srcs = ["repeated_field_test.rb"], - deps = [ - ":test_ruby_protos", - "//ruby:protobuf", - "@protobuf_bundle//:test-unit", - ], -) - -ruby_test( - name = "stress", - srcs = ["stress.rb"], - deps = [ - ":test_ruby_protos", - "//ruby:protobuf", - "@protobuf_bundle//:test-unit", - ], -) - -################################################################################ -# Distribution files -############################################################################ - -pkg_files( - name = "dist_files", - srcs = glob([ - "**/*.rb", - "**/*.proto", - ]), - strip_prefix = strip_prefix.from_root(""), - visibility = ["//ruby/compatibility_tests/v3.0.0:__pkg__"], -) diff --git a/ruby/compatibility_tests/v3.0.0/tests/basic.rb b/ruby/compatibility_tests/v3.0.0/tests/basic.rb deleted file mode 100755 index b59193e000a9a..0000000000000 --- a/ruby/compatibility_tests/v3.0.0/tests/basic.rb +++ /dev/null @@ -1,1133 +0,0 @@ -#!/usr/bin/ruby - -require 'google/protobuf' -require 'test/unit' - -# ------------- generated code -------------- - -module BasicTest - pool = Google::Protobuf::DescriptorPool.new - pool.build do - add_message "Foo" do - optional :bar, :message, 1, "Bar" - repeated :baz, :message, 2, "Baz" - end - - add_message "Bar" do - optional :msg, :string, 1 - end - - add_message "Baz" do - optional :msg, :string, 1 - end - - add_message "TestMessage" do - optional :optional_int32, :int32, 1 - optional :optional_int64, :int64, 2 - optional :optional_uint32, :uint32, 3 - optional :optional_uint64, :uint64, 4 - optional :optional_bool, :bool, 5 - optional :optional_float, :float, 6 - optional :optional_double, :double, 7 - optional :optional_string, :string, 8 - optional :optional_bytes, :bytes, 9 - optional :optional_msg, :message, 10, "TestMessage2" - optional :optional_enum, :enum, 11, "TestEnum" - - repeated :repeated_int32, :int32, 12 - repeated :repeated_int64, :int64, 13 - repeated :repeated_uint32, :uint32, 14 - repeated :repeated_uint64, :uint64, 15 - repeated :repeated_bool, :bool, 16 - repeated :repeated_float, :float, 17 - repeated :repeated_double, :double, 18 - repeated :repeated_string, :string, 19 - repeated :repeated_bytes, :bytes, 20 - repeated :repeated_msg, :message, 21, "TestMessage2" - repeated :repeated_enum, :enum, 22, "TestEnum" - end - add_message "TestMessage2" do - optional :foo, :int32, 1 - end - - add_message "Recursive1" do - optional :foo, :message, 1, "Recursive2" - end - add_message "Recursive2" do - optional :foo, :message, 1, "Recursive1" - end - - add_enum "TestEnum" do - value :Default, 0 - value :A, 1 - value :B, 2 - value :C, 3 - end - - add_message "BadFieldNames" do - optional :dup, :int32, 1 - optional :class, :int32, 2 - end - - add_message "MapMessage" do - map :map_string_int32, :string, :int32, 1 - map :map_string_msg, :string, :message, 2, "TestMessage2" - end - add_message "MapMessageWireEquiv" do - repeated :map_string_int32, :message, 1, "MapMessageWireEquiv_entry1" - repeated :map_string_msg, :message, 2, "MapMessageWireEquiv_entry2" - end - add_message "MapMessageWireEquiv_entry1" do - optional :key, :string, 1 - optional :value, :int32, 2 - end - add_message "MapMessageWireEquiv_entry2" do - optional :key, :string, 1 - optional :value, :message, 2, "TestMessage2" - end - - add_message "OneofMessage" do - oneof :my_oneof do - optional :a, :string, 1 - optional :b, :int32, 2 - optional :c, :message, 3, "TestMessage2" - optional :d, :enum, 4, "TestEnum" - end - end - end - - Foo = pool.lookup("Foo").msgclass - Bar = pool.lookup("Bar").msgclass - Baz = pool.lookup("Baz").msgclass - TestMessage = pool.lookup("TestMessage").msgclass - TestMessage2 = pool.lookup("TestMessage2").msgclass - Recursive1 = pool.lookup("Recursive1").msgclass - Recursive2 = pool.lookup("Recursive2").msgclass - TestEnum = pool.lookup("TestEnum").enummodule - BadFieldNames = pool.lookup("BadFieldNames").msgclass - MapMessage = pool.lookup("MapMessage").msgclass - MapMessageWireEquiv = pool.lookup("MapMessageWireEquiv").msgclass - MapMessageWireEquiv_entry1 = - pool.lookup("MapMessageWireEquiv_entry1").msgclass - MapMessageWireEquiv_entry2 = - pool.lookup("MapMessageWireEquiv_entry2").msgclass - OneofMessage = pool.lookup("OneofMessage").msgclass - -# ------------ test cases --------------- - - class MessageContainerTest < Test::Unit::TestCase - - def test_defaults - m = TestMessage.new - assert_equal 0, m.optional_int32 - assert_equal 0, m.optional_int64 - assert_equal 0, m.optional_uint32 - assert_equal 0, m.optional_uint64 - refute m.optional_bool - assert_equal 0.0, m.optional_float - assert_equal 0.0, m.optional_double - assert_empty m.optional_string - assert_empty m.optional_bytes - assert_nil m.optional_msg - assert_equal :Default, m.optional_enum - end - - def test_setters - m = TestMessage.new - m.optional_int32 = -42 - assert_equal -42, m.optional_int32 - m.optional_int64 = -0x1_0000_0000 - assert_equal -0x1_0000_0000, m.optional_int64 - m.optional_uint32 = 0x9000_0000 - assert_equal 0x9000_0000, m.optional_uint32 - m.optional_uint64 = 0x9000_0000_0000_0000 - assert_equal 0x9000_0000_0000_0000, m.optional_uint64 - m.optional_bool = true - assert m.optional_bool - m.optional_float = 0.5 - assert_equal 0.5, m.optional_float - m.optional_double = 0.5 - assert_equal 0.5, m.optional_double - m.optional_string = "hello" - assert_equal "hello", m.optional_string - m.optional_bytes = "world".encode!('ASCII-8BIT') - assert_equal "world", m.optional_bytes - m.optional_msg = TestMessage2.new(:foo => 42) - assert_equal m.optional_msg, TestMessage2.new(:foo => 42) - m.optional_msg = nil - assert_nil m.optional_msg - end - - def test_ctor_args - m = TestMessage.new(:optional_int32 => -42, - :optional_msg => TestMessage2.new, - :optional_enum => :C, - :repeated_string => ["hello", "there", "world"]) - assert_equal -42, m.optional_int32 - assert_instance_of TestMessage2, m.optional_msg - assert_equal 3, m.repeated_string.length - assert_equal :C, m.optional_enum - assert_equal "hello", m.repeated_string[0] - assert_equal "there", m.repeated_string[1] - assert_equal "world", m.repeated_string[2] - end - - def test_inspect - m = TestMessage.new(:optional_int32 => -42, - :optional_enum => :A, - :optional_msg => TestMessage2.new, - :repeated_string => ["hello", "there", "world"]) - expected = ', optional_enum: :A, repeated_int32: [], repeated_int64: [], repeated_uint32: [], repeated_uint64: [], repeated_bool: [], repeated_float: [], repeated_double: [], repeated_string: ["hello", "there", "world"], repeated_bytes: [], repeated_msg: [], repeated_enum: []>' - assert_equal expected, m.inspect - end - - def test_hash - m1 = TestMessage.new(:optional_int32 => 42) - m2 = TestMessage.new(:optional_int32 => 102) - refute_equal 0, m1.hash - refute_equal 0, m2.hash - # relying on the randomness here -- if hash function changes and we are - # unlucky enough to get a collision, then change the values above. - refute_equal m1.hash, m2.hash - end - - def test_unknown_field_errors - e = assert_raises NoMethodError do - TestMessage.new.hello - end - assert_match(/hello/, e.message) - - e = assert_raises NoMethodError do - TestMessage.new.hello = "world" - end - assert_match(/hello/, e.message) - end - - def test_initialization_map_errors - e = assert_raises ArgumentError do - TestMessage.new(:hello => "world") - end - assert_match(/hello/, e.message) - - e = assert_raises ArgumentError do - MapMessage.new(:map_string_int32 => "hello") - end - assert_equal "Expected Hash object as initializer value for map field 'map_string_int32' (given String).", e.message - e = assert_raises ArgumentError do - TestMessage.new(:repeated_uint32 => "hello") - end - assert_equal "Expected array as initializer value for repeated field 'repeated_uint32' (given String).", e.message - end - - def test_type_errors - m = TestMessage.new - - assert_raises Google::Protobuf::TypeError do - m.optional_int32 = "hello" - end - - assert_raises Google::Protobuf::TypeError do - m.optional_string = nil - end - - assert_raises Google::Protobuf::TypeError do - m.optional_bool = 42 - end - - assert_raises Google::Protobuf::TypeError do - m.optional_msg = TestMessage.new # expects TestMessage2 - end - - assert_raises Google::Protobuf::TypeError do - m.repeated_int32 = [] # needs RepeatedField - end - - assert_raises Google::Protobuf::TypeError do - m.repeated_msg.push TestMessage.new - end - end - - def test_string_encoding - m = TestMessage.new - - # Assigning a normal (ASCII or UTF8) string to a bytes field, or - # ASCII-8BIT to a string field will convert to the proper encoding. - m.optional_bytes = "Test string ASCII".encode!('ASCII') - assert m.optional_bytes.frozen? - assert_equal Encoding::ASCII_8BIT, m.optional_bytes.encoding - assert_equal "Test string ASCII", m.optional_bytes - - assert_raises Encoding::UndefinedConversionError do - m.optional_bytes = "Test string UTF-8 \u0100".encode!('UTF-8') - end - - assert_raises Encoding::UndefinedConversionError do - m.optional_string = ["FFFF"].pack('H*') - end - - # "Ordinary" use case. - m.optional_bytes = ["FFFF"].pack('H*') - m.optional_string = "\u0100" - - # strings are immutable so we can't do this, but serialize should catch it. - m.optional_string = "asdf".encode!('UTF-8') - assert_raises do - m.optional_string.encode!('ASCII-8BIT') - end - end - - def test_rptfield_int32 - l = Google::Protobuf::RepeatedField.new(:int32) - assert_equal 0, l.count - l = Google::Protobuf::RepeatedField.new(:int32, [1, 2, 3]) - assert_equal 3, l.count - assert_equal [1, 2, 3], l - assert_equal [1, 2, 3], l - l.push 4 - assert_equal [1, 2, 3, 4], l - dst_list = [] - l.each { |val| dst_list.push val } - assert_equal [1, 2, 3, 4], dst_list - assert_equal [1, 2, 3, 4], l.to_a - assert_equal 1, l[0] - assert_equal 4, l[3] - l[0] = 5 - assert_equal [5, 2, 3, 4], l - l2 = l.dup - assert_equal l, l2 - refute_same l, l2 - l2.push 6 - assert_equal 4, l.count - assert_equal 5, l2.count - assert_equal '[5, 2, 3, 4]', l.inspect - l.concat([7, 8, 9]) - assert_equal [5, 2, 3, 4, 7, 8, 9], l - assert_equal 9, l.pop - assert_equal [5, 2, 3, 4, 7, 8], l - m = TestMessage.new - assert_raises Google::Protobuf::TypeError do - l.push m - end - - m.repeated_int32 = l - assert_equal [5, 2, 3, 4, 7, 8], m.repeated_int32 - assert_same m.repeated_int32, l - l.push 42 - assert_equal 42, m.repeated_int32.pop - l3 = l + l.dup - assert_equal l.count * 2, l3.count - l.count.times do |i| - assert_equal l[i], l3[i] - assert_equal l[i], l3[l.count + i] - end - - l.clear - assert_equal 0, l.count - l += [1, 2, 3, 4] - l.replace([5, 6, 7, 8]) - assert_equal [5, 6, 7, 8], l - l4 = Google::Protobuf::RepeatedField.new(:int32) - l4[5] = 42 - assert_equal [0, 0, 0, 0, 0, 42], l4 - l4 << 100 - assert_equal [0, 0, 0, 0, 0, 42, 100], l4 - l4 << 101 << 102 - assert_equal [0, 0, 0, 0, 0, 42, 100, 101, 102], l4 - end - - def test_parent_rptfield - #make sure we set the RepeatedField and can add to it - m = TestMessage.new - assert_empty m.repeated_string - m.repeated_string << 'ok' - m.repeated_string.push('ok2') - assert_equal ['ok', 'ok2'], m.repeated_string - m.repeated_string += ['ok3'] - assert_equal ['ok', 'ok2', 'ok3'], m.repeated_string - end - - def test_rptfield_msg - l = Google::Protobuf::RepeatedField.new(:message, TestMessage) - l.push TestMessage.new - assert_equal 1, l.count - assert_raises Google::Protobuf::TypeError do - l.push TestMessage2.new - end - assert_raises Google::Protobuf::TypeError do - l.push 42 - end - - l2 = l.dup - assert_equal l[0], l2[0] - assert_same l2[0], l[0] - l2 = Google::Protobuf.deep_copy(l) - assert_equal l[0], l2[0] - refute_same l2[0], l[0] - l3 = l + l2 - assert_equal 2, l3.count - assert_equal l[0], l3[0] - assert_equal l2[0], l3[1] - l3[0].optional_int32 = 1000 - assert_equal 1000, l[0].optional_int32 - new_msg = TestMessage.new(:optional_int32 => 200) - l4 = l + [new_msg] - assert_equal 2, l4.count - new_msg.optional_int32 = 1000 - assert_equal 1000, l4[1].optional_int32 - end - - def test_rptfield_enum - l = Google::Protobuf::RepeatedField.new(:enum, TestEnum) - l.push :A - l.push :B - l.push :C - assert_equal 3, l.count - assert_raises RangeError do - l.push :D - end - assert_equal :A, l[0] - l.push 4 - assert_equal 4, l[3] - end - - def test_rptfield_initialize - assert_raises ArgumentError do - l = Google::Protobuf::RepeatedField.new - end - assert_raises ArgumentError do - l = Google::Protobuf::RepeatedField.new(:message) - end - assert_raises ArgumentError do - l = Google::Protobuf::RepeatedField.new([1, 2, 3]) - end - assert_raises ArgumentError do - l = Google::Protobuf::RepeatedField.new(:message, [TestMessage2.new]) - end - end - - def test_rptfield_array_ducktyping - l = Google::Protobuf::RepeatedField.new(:int32) - length_methods = %w(count length size) - length_methods.each do |lm| - assert_equal 0, l.send(lm) - end - # out of bounds returns a nil - assert_nil l[0] - assert_nil l[1] - assert_nil l[-1] - l.push 4 - length_methods.each do |lm| - assert_equal 1, l.send(lm) - end - assert_equal 4, l[0] - assert_nil l[1] - assert_equal 4, l[-1] - assert_nil l[-2] - l.push 2 - length_methods.each do |lm| - assert_equal 2, l.send(lm) - end - assert_equal 4, l[0] - assert_equal 2, l[1] - assert_nil l[2] - assert_equal 2, l[-1] - assert_equal 4, l[-2] - assert_nil l[-3] - #adding out of scope will backfill with empty objects - end - - def test_map_basic - # allowed key types: - # :int32, :int64, :uint32, :uint64, :bool, :string, :bytes. - - m = Google::Protobuf::Map.new(:string, :int32) - m["asdf"] = 1 - assert_equal 1, m["asdf"] - m["jkl;"] = 42 - assert_equal({ "jkl;" => 42, "asdf" => 1 }, m.to_h) - assert_includes m.to_h, "asdf" - refute_includes m, "qwerty" - assert_equal 2, m.length - m2 = m.dup - assert_equal m, m2 - refute_equal 0, m.hash - assert_equal m.hash, m2.hash - collected = {} - m.each { |k,v| collected[v] = k } - assert_equal({ 42 => "jkl;", 1 => "asdf" }, collected) - assert_equal 1, m.delete("asdf") - refute_includes m, "asdf" - assert_nil m["asdf"] - refute_includes m, "asdf" - - # We only assert on inspect value when there is one map entry because the - # order in which elements appear is unspecified (depends on the internal - # hash function). We don't want a brittle test. - assert_equal "{\"jkl;\"=>42}", m.inspect - assert_equal ["jkl;"], m.keys - assert_equal [42], m.values - m.clear - assert_equal 0, m.length - assert_empty m.to_h - assert_raises Google::Protobuf::TypeError do - m[1] = 1 - end - - assert_raises RangeError do - m["asdf"] = 0x1_0000_0000 - end - end - - def test_map_ctor - m = Google::Protobuf::Map.new(:string, :int32, - {"a" => 1, "b" => 2, "c" => 3}) - assert_equal({"a" => 1, "c" => 3, "b" => 2}, m.to_h) - end - - def test_map_keytypes - m = Google::Protobuf::Map.new(:int32, :int32) - m[1] = 42 - m[-1] = 42 - assert_raises RangeError do - m[0x8000_0000] = 1 - end - - assert_raises Google::Protobuf::TypeError do - m["asdf"] = 1 - end - - m = Google::Protobuf::Map.new(:int64, :int32) - m[0x1000_0000_0000_0000] = 1 - assert_raises RangeError do - m[0x1_0000_0000_0000_0000] = 1 - end - - assert_raises Google::Protobuf::TypeError do - m["asdf"] = 1 - end - - m = Google::Protobuf::Map.new(:uint32, :int32) - m[0x8000_0000] = 1 - assert_raises RangeError do - m[0x1_0000_0000] = 1 - end - assert_raises RangeError do - m[-1] = 1 - end - - m = Google::Protobuf::Map.new(:uint64, :int32) - m[0x8000_0000_0000_0000] = 1 - assert_raises RangeError do - m[0x1_0000_0000_0000_0000] = 1 - end - assert_raises RangeError do - m[-1] = 1 - end - - m = Google::Protobuf::Map.new(:bool, :int32) - m[true] = 1 - m[false] = 2 - - assert_raises Google::Protobuf::TypeError do - m[1] = 1 - end - - assert_raises Google::Protobuf::TypeError do - m["asdf"] = 1 - end - - m = Google::Protobuf::Map.new(:string, :int32) - m["asdf"] = 1 - assert_raises Google::Protobuf::TypeError do - m[1] = 1 - end - bytestring = ["FFFF"].pack("H*") - assert_raises Encoding::UndefinedConversionError do - m[bytestring] = 1 - end - - m = Google::Protobuf::Map.new(:bytes, :int32) - bytestring = ["FFFF"].pack("H*") - m[bytestring] = 1 - # Allowed -- we will automatically convert to ASCII-8BIT. - m["asdf"] = 1 - assert_raises Google::Protobuf::TypeError do - m[1] = 1 - end - end - - def test_map_msg_enum_valuetypes - m = Google::Protobuf::Map.new(:string, :message, TestMessage) - m["asdf"] = TestMessage.new - assert_raises Google::Protobuf::TypeError do - m["jkl;"] = TestMessage2.new - end - - m = Google::Protobuf::Map.new( - :string, :message, TestMessage, - { "a" => TestMessage.new(:optional_int32 => 42), - "b" => TestMessage.new(:optional_int32 => 84) }) - assert_equal 2, m.length - assert_equal [42, 84], m.values.map{|msg| msg.optional_int32}.sort - m = Google::Protobuf::Map.new(:string, :enum, TestEnum, - { "x" => :A, "y" => :B, "z" => :C }) - assert_equal 3, m.length - assert_equal :C, m["z"] - m["z"] = 2 - assert_equal :B, m["z"] - m["z"] = 5 - assert_equal 5, m["z"] - assert_raises RangeError do - m["z"] = :Z - end - assert_raises RangeError do - m["z"] = "z" - end - end - - def test_map_dup_deep_copy - m = Google::Protobuf::Map.new( - :string, :message, TestMessage, - { "a" => TestMessage.new(:optional_int32 => 42), - "b" => TestMessage.new(:optional_int32 => 84) }) - - m2 = m.dup - assert_equal m, m2 - refute_same m, m2 - assert_same m["a"], m2["a"] - assert_same m["b"], m2["b"] - m2 = Google::Protobuf.deep_copy(m) - assert_equal m, m2 - refute_same m, m2 - refute_same m["a"], m2["a"] - refute_same m["b"], m2["b"] - end - - def test_map_field - m = MapMessage.new - assert_empty m.map_string_int32.to_h - assert_empty m.map_string_msg.to_h - m = MapMessage.new( - :map_string_int32 => {"a" => 1, "b" => 2}, - :map_string_msg => {"a" => TestMessage2.new(:foo => 1), - "b" => TestMessage2.new(:foo => 2)}) - assert_equal ["a", "b"], m.map_string_int32.keys.sort - assert_equal 1, m.map_string_int32["a"] - assert_equal 2, m.map_string_msg["b"].foo - m.map_string_int32["c"] = 3 - assert_equal 3, m.map_string_int32["c"] - m.map_string_msg["c"] = TestMessage2.new(:foo => 3) - assert_equal TestMessage2.new(:foo => 3), m.map_string_msg["c"] - m.map_string_msg.delete("b") - m.map_string_msg.delete("c") - assert_equal({ "a" => TestMessage2.new(:foo => 1).to_h }, m.map_string_msg.to_h) - assert_raises Google::Protobuf::TypeError do - m.map_string_msg["e"] = TestMessage.new # wrong value type - end - # ensure nothing was added by the above - assert_equal({ "a" => TestMessage2.new(:foo => 1).to_h }, m.map_string_msg.to_h) - m.map_string_int32 = Google::Protobuf::Map.new(:string, :int32) - assert_raises Google::Protobuf::TypeError do - m.map_string_int32 = Google::Protobuf::Map.new(:string, :int64) - end - assert_raises Google::Protobuf::TypeError do - m.map_string_int32 = {} - end - assert_raises Google::Protobuf::TypeError do - m = MapMessage.new(:map_string_int32 => { 1 => "I am not a number" }) - end - end - - def test_map_encode_decode - m = MapMessage.new( - :map_string_int32 => {"a" => 1, "b" => 2}, - :map_string_msg => {"a" => TestMessage2.new(:foo => 1), - "b" => TestMessage2.new(:foo => 2)}) - m2 = MapMessage.decode(MapMessage.encode(m)) - assert_equal m, m2 - m3 = MapMessageWireEquiv.decode(MapMessage.encode(m)) - assert_equal 2, m3.map_string_int32.length - kv = {} - m3.map_string_int32.map { |msg| kv[msg.key] = msg.value } - assert_equal({"a" => 1, "b" => 2}, kv) - kv = {} - m3.map_string_msg.map { |msg| kv[msg.key] = msg.value } - assert_equal({"a" => TestMessage2.new(:foo => 1), - "b" => TestMessage2.new(:foo => 2)}, kv) - end - - def test_oneof_descriptors - d = OneofMessage.descriptor - o = d.lookup_oneof("my_oneof") - refute_nil o - assert_instance_of Google::Protobuf::OneofDescriptor, o - assert_equal "my_oneof", o.name - oneof_count = 0 - d.each_oneof{ |oneof| - oneof_count += 1 - assert_equal o, oneof - } - assert_equal 1, oneof_count - assert_equal 4, o.count - field_names = o.map{|f| f.name}.sort - assert_equal ["a", "b", "c", "d"], field_names - end - - def test_oneof - d = OneofMessage.new - assert_empty d.a - assert_equal 0, d.b - assert_nil d.c - assert_equal :Default, d.d - assert_nil d.my_oneof - d.a = "hi" - assert_equal "hi", d.a - assert_equal 0, d.b - assert_nil d.c - assert_equal :Default, d.d - assert_equal :a, d.my_oneof - d.b = 42 - assert_empty d.a - assert_equal 42, d.b - assert_nil d.c - assert_equal :Default, d.d - assert_equal :b, d.my_oneof - d.c = TestMessage2.new(:foo => 100) - assert_empty d.a - assert_equal 0, d.b - assert_equal 100, d.c.foo - assert_equal :Default, d.d - assert_equal :c, d.my_oneof - d.d = :C - assert_empty d.a - assert_equal 0, d.b - assert_nil d.c - assert_equal :C, d.d - assert_equal :d, d.my_oneof - d2 = OneofMessage.decode(OneofMessage.encode(d)) - assert_equal d2, d - encoded_field_a = OneofMessage.encode(OneofMessage.new(:a => "string")) - encoded_field_b = OneofMessage.encode(OneofMessage.new(:b => 1000)) - encoded_field_c = OneofMessage.encode( - OneofMessage.new(:c => TestMessage2.new(:foo => 1))) - encoded_field_d = OneofMessage.encode(OneofMessage.new(:d => :B)) - - d3 = OneofMessage.decode( - encoded_field_c + encoded_field_a + encoded_field_d) - assert_empty d3.a - assert_equal 0, d3.b - assert_nil d3.c - assert_equal :B, d3.d - d4 = OneofMessage.decode( - encoded_field_c + encoded_field_a + encoded_field_d + - encoded_field_c) - assert_empty d4.a - assert_equal 0, d4.b - assert_equal 1, d4.c.foo - assert_equal :Default, d4.d - d5 = OneofMessage.new(:a => "hello") - assert_equal "hello", d5.a - d5.a = nil - assert_empty d5.a - assert_empty OneofMessage.encode(d5) - assert_nil d5.my_oneof - end - - def test_enum_field - m = TestMessage.new - assert_equal :Default, m.optional_enum - m.optional_enum = :A - assert_equal :A, m.optional_enum - assert_raises RangeError do - m.optional_enum = :ASDF - end - m.optional_enum = 1 - assert_equal :A, m.optional_enum - m.optional_enum = 100 - assert_equal 100, m.optional_enum - end - - def test_dup - m = TestMessage.new - m.optional_string = "hello" - m.optional_int32 = 42 - tm1 = TestMessage2.new(:foo => 100) - tm2 = TestMessage2.new(:foo => 200) - m.repeated_msg.push tm1 - assert_equal m.repeated_msg[-1], tm1 - m.repeated_msg.push tm2 - assert_equal m.repeated_msg[-1], tm2 - m2 = m.dup - assert_equal m, m2 - m.optional_int32 += 1 - refute_equal m2, m - assert_equal m.repeated_msg[0], m2.repeated_msg[0] - assert_same m.repeated_msg[0], m2.repeated_msg[0] - end - - def test_deep_copy - m = TestMessage.new(:optional_int32 => 42, - :repeated_msg => [TestMessage2.new(:foo => 100)]) - m2 = Google::Protobuf.deep_copy(m) - assert_equal m, m2 - assert_equal m.repeated_msg, m2.repeated_msg - refute_same m.repeated_msg, m2.repeated_msg - refute_same m.repeated_msg[0], m2.repeated_msg[0] - end - - def test_eq - m = TestMessage.new(:optional_int32 => 42, - :repeated_int32 => [1, 2, 3]) - m2 = TestMessage.new(:optional_int32 => 43, - :repeated_int32 => [1, 2, 3]) - refute_equal m2, m - end - - def test_enum_lookup - assert_equal 1, TestEnum::A - assert_equal 2, TestEnum::B - assert_equal 3, TestEnum::C - assert_equal :A, TestEnum::lookup(1) - assert_equal :B, TestEnum::lookup(2) - assert_equal :C, TestEnum::lookup(3) - assert_equal 1, TestEnum::resolve(:A) - assert_equal 2, TestEnum::resolve(:B) - assert_equal 3, TestEnum::resolve(:C) - end - - def test_parse_serialize - m = TestMessage.new(:optional_int32 => 42, - :optional_string => "hello world", - :optional_enum => :B, - :repeated_string => ["a", "b", "c"], - :repeated_int32 => [42, 43, 44], - :repeated_enum => [:A, :B, :C, 100], - :repeated_msg => [TestMessage2.new(:foo => 1), - TestMessage2.new(:foo => 2)]) - data = TestMessage.encode m - m2 = TestMessage.decode data - assert_equal m, m2 - data = Google::Protobuf.encode m - m2 = Google::Protobuf.decode(TestMessage, data) - assert_equal m, m2 - end - - def test_encode_decode_helpers - m = TestMessage.new(:optional_string => 'foo', :repeated_string => ['bar1', 'bar2']) - assert_equal 'foo', m.optional_string - assert_equal ['bar1', 'bar2'], m.repeated_string - - json = m.to_json - m2 = TestMessage.decode_json(json) - assert_equal 'foo', m2.optional_string - assert_equal ['bar1', 'bar2'], m2.repeated_string - if RUBY_PLATFORM != "java" - assert m2.optional_string.frozen? - assert m2.repeated_string[0].frozen? - end - - proto = m.to_proto - m2 = TestMessage.decode(proto) - assert_equal 'foo', m2.optional_string - assert_equal ['bar1', 'bar2'], m2.repeated_string - end - - def test_protobuf_encode_decode_helpers - m = TestMessage.new(:optional_string => 'foo', :repeated_string => ['bar1', 'bar2']) - encoded_msg = Google::Protobuf.encode(m) - assert_equal m.to_proto, encoded_msg - - decoded_msg = Google::Protobuf.decode(TestMessage, encoded_msg) - assert_equal TestMessage.decode(m.to_proto), decoded_msg - end - - def test_protobuf_encode_decode_json_helpers - m = TestMessage.new(:optional_string => 'foo', :repeated_string => ['bar1', 'bar2']) - encoded_msg = Google::Protobuf.encode_json(m) - assert_equal m.to_json, encoded_msg - - decoded_msg = Google::Protobuf.decode_json(TestMessage, encoded_msg) - assert_equal TestMessage.decode_json(m.to_json), decoded_msg - end - - def test_to_h - m = TestMessage.new(:optional_bool => true, :optional_double => -10.100001, :optional_string => 'foo', :repeated_string => ['bar1', 'bar2']) - expected_result = { - :optional_bool=>true, - :optional_bytes=>"", - :optional_double=>-10.100001, - :optional_enum=>:Default, - :optional_float=>0.0, - :optional_int32=>0, - :optional_int64=>0, - :optional_msg=>nil, - :optional_string=>"foo", - :optional_uint32=>0, - :optional_uint64=>0, - :repeated_bool=>[], - :repeated_bytes=>[], - :repeated_double=>[], - :repeated_enum=>[], - :repeated_float=>[], - :repeated_int32=>[], - :repeated_int64=>[], - :repeated_msg=>[], - :repeated_string=>["bar1", "bar2"], - :repeated_uint32=>[], - :repeated_uint64=>[] - } - assert_equal expected_result, m.to_h - end - - - def test_def_errors - s = Google::Protobuf::DescriptorPool.new - assert_raises Google::Protobuf::TypeError do - s.build do - # enum with no default (integer value 0) - add_enum "MyEnum" do - value :A, 1 - end - end - end - assert_raises Google::Protobuf::TypeError do - s.build do - # message with required field (unsupported in proto3) - add_message "MyMessage" do - required :foo, :int32, 1 - end - end - end - end - - def test_corecursive - # just be sure that we can instantiate types with corecursive field-type - # references. - m = Recursive1.new(:foo => Recursive2.new(:foo => Recursive1.new)) - assert_equal Recursive2.descriptor, Recursive1.descriptor.lookup("foo").subtype - assert_equal Recursive1.descriptor, Recursive2.descriptor.lookup("foo").subtype - serialized = Recursive1.encode(m) - m2 = Recursive1.decode(serialized) - assert_equal m, m2 - end - - def test_serialize_cycle - m = Recursive1.new(:foo => Recursive2.new) - m.foo.foo = m - assert_raises RuntimeError do - Recursive1.encode(m) - end - end - - def test_bad_field_names - m = BadFieldNames.new(:dup => 1, :class => 2) - m2 = m.dup - assert_equal m, m2 - assert_equal 1, m['dup'] - assert_equal 2, m['class'] - m['dup'] = 3 - assert_equal 3, m['dup'] - end - - def test_int_ranges - m = TestMessage.new - - m.optional_int32 = 0 - m.optional_int32 = -0x8000_0000 - m.optional_int32 = +0x7fff_ffff - m.optional_int32 = 1.0 - m.optional_int32 = -1.0 - m.optional_int32 = 2e9 - assert_raises RangeError do - m.optional_int32 = -0x8000_0001 - end - assert_raises RangeError do - m.optional_int32 = +0x8000_0000 - end - assert_raises RangeError do - m.optional_int32 = +0x1000_0000_0000_0000_0000_0000 # force Bignum - end - assert_raises RangeError do - m.optional_int32 = 1e12 - end - assert_raises RangeError do - m.optional_int32 = 1.5 - end - - m.optional_uint32 = 0 - m.optional_uint32 = +0xffff_ffff - m.optional_uint32 = 1.0 - m.optional_uint32 = 4e9 - assert_raises RangeError do - m.optional_uint32 = -1 - end - assert_raises RangeError do - m.optional_uint32 = -1.5 - end - assert_raises RangeError do - m.optional_uint32 = -1.5e12 - end - assert_raises RangeError do - m.optional_uint32 = -0x1000_0000_0000_0000 - end - assert_raises RangeError do - m.optional_uint32 = +0x1_0000_0000 - end - assert_raises RangeError do - m.optional_uint32 = +0x1000_0000_0000_0000_0000_0000 # force Bignum - end - assert_raises RangeError do - m.optional_uint32 = 1e12 - end - assert_raises RangeError do - m.optional_uint32 = 1.5 - end - - m.optional_int64 = 0 - m.optional_int64 = -0x8000_0000_0000_0000 - m.optional_int64 = +0x7fff_ffff_ffff_ffff - m.optional_int64 = 1.0 - m.optional_int64 = -1.0 - m.optional_int64 = 8e18 - m.optional_int64 = -8e18 - assert_raises RangeError do - m.optional_int64 = -0x8000_0000_0000_0001 - end - assert_raises RangeError do - m.optional_int64 = +0x8000_0000_0000_0000 - end - assert_raises RangeError do - m.optional_int64 = +0x1000_0000_0000_0000_0000_0000 # force Bignum - end - assert_raises RangeError do - m.optional_int64 = 1e50 - end - assert_raises RangeError do - m.optional_int64 = 1.5 - end - - m.optional_uint64 = 0 - m.optional_uint64 = +0xffff_ffff_ffff_ffff - m.optional_uint64 = 1.0 - m.optional_uint64 = 16e18 - assert_raises RangeError do - m.optional_uint64 = -1 - end - assert_raises RangeError do - m.optional_uint64 = -1.5 - end - assert_raises RangeError do - m.optional_uint64 = -1.5e12 - end - assert_raises RangeError do - m.optional_uint64 = -0x1_0000_0000_0000_0000 - end - assert_raises RangeError do - m.optional_uint64 = +0x1_0000_0000_0000_0000 - end - assert_raises RangeError do - m.optional_uint64 = +0x1000_0000_0000_0000_0000_0000 # force Bignum - end - assert_raises RangeError do - m.optional_uint64 = 1e50 - end - assert_raises RangeError do - m.optional_uint64 = 1.5 - end - end - - def test_stress_test - m = TestMessage.new - m.optional_int32 = 42 - m.optional_int64 = 0x100000000 - m.optional_string = "hello world" - 10.times do m.repeated_msg.push TestMessage2.new(:foo => 42) end - 10.times do m.repeated_string.push "hello world" end - - data = TestMessage.encode(m) - - l = 0 - 10_000.times do - m = TestMessage.decode(data) - data_new = TestMessage.encode(m) - assert_equal data, data_new - data = data_new - end - end - - def test_reflection - m = TestMessage.new(:optional_int32 => 1234) - msgdef = m.class.descriptor - assert_instance_of Google::Protobuf::Descriptor, msgdef - assert msgdef.any? {|field| field.name == "optional_int32"} - optional_int32 = msgdef.lookup "optional_int32" - assert_instance_of Google::Protobuf::FieldDescriptor, optional_int32 - refute_nil optional_int32 - assert_equal "optional_int32", optional_int32.name - assert_equal :int32, optional_int32.type - optional_int32.set(m, 5678) - assert_equal 5678, m.optional_int32 - m.optional_int32 = 1000 - assert_equal 1000, optional_int32.get(m) - optional_msg = msgdef.lookup "optional_msg" - assert_equal TestMessage2.descriptor, optional_msg.subtype - optional_msg.set(m, optional_msg.subtype.msgclass.new) - - assert_equal TestMessage, msgdef.msgclass - optional_enum = msgdef.lookup "optional_enum" - assert_equal TestEnum.descriptor, optional_enum.subtype - assert_instance_of Google::Protobuf::EnumDescriptor, optional_enum.subtype - optional_enum.subtype.each do |k, v| - # set with integer, check resolution to symbolic name - optional_enum.set(m, v) - assert_equal k, optional_enum.get(m) - end - end - - def test_json - # TODO: Fix JSON in JRuby version. - return if RUBY_PLATFORM == "java" - m = TestMessage.new(:optional_int32 => 1234, - :optional_int64 => -0x1_0000_0000, - :optional_uint32 => 0x8000_0000, - :optional_uint64 => 0xffff_ffff_ffff_ffff, - :optional_bool => true, - :optional_float => 1.0, - :optional_double => -1e100, - :optional_string => "Test string", - :optional_bytes => ["FFFFFFFF"].pack('H*'), - :optional_msg => TestMessage2.new(:foo => 42), - :repeated_int32 => [1, 2, 3, 4], - :repeated_string => ["a", "b", "c"], - :repeated_bool => [true, false, true, false], - :repeated_msg => [TestMessage2.new(:foo => 1), - TestMessage2.new(:foo => 2)]) - - json_text = TestMessage.encode_json(m) - m2 = TestMessage.decode_json(json_text) - assert_equal m, m2 - # Crash case from GitHub issue 283. - bar = Bar.new(msg: "bar") - baz1 = Baz.new(msg: "baz") - baz2 = Baz.new(msg: "quux") - Foo.encode_json(Foo.new) - Foo.encode_json(Foo.new(bar: bar)) - Foo.encode_json(Foo.new(bar: bar, baz: [baz1, baz2])) - end - - def test_json_maps - # TODO: Fix JSON in JRuby version. - return if RUBY_PLATFORM == "java" - m = MapMessage.new(:map_string_int32 => {"a" => 1}) - expected = '{"mapStringInt32":{"a":1},"mapStringMsg":{}}' - expected_preserve = '{"map_string_int32":{"a":1},"map_string_msg":{}}' - assert_equal expected, MapMessage.encode_json(m, :emit_defaults => true) - - json = MapMessage.encode_json(m, :preserve_proto_fieldnames => true, :emit_defaults => true) - assert_equal expected_preserve, json - - m2 = MapMessage.decode_json(MapMessage.encode_json(m)) - assert_equal m, m2 - end - end -end diff --git a/ruby/compatibility_tests/v3.0.0/tests/generated_code.proto b/ruby/compatibility_tests/v3.0.0/tests/generated_code.proto deleted file mode 100644 index 62fd83ed896be..0000000000000 --- a/ruby/compatibility_tests/v3.0.0/tests/generated_code.proto +++ /dev/null @@ -1,67 +0,0 @@ -syntax = "proto3"; - -package a.b.c; - -message TestMessage { - int32 optional_int32 = 1; - int64 optional_int64 = 2; - uint32 optional_uint32 = 3; - uint64 optional_uint64 = 4; - bool optional_bool = 5; - double optional_double = 6; - float optional_float = 7; - string optional_string = 8; - bytes optional_bytes = 9; - TestEnum optional_enum = 10; - TestMessage optional_msg = 11; - - repeated int32 repeated_int32 = 21; - repeated int64 repeated_int64 = 22; - repeated uint32 repeated_uint32 = 23; - repeated uint64 repeated_uint64 = 24; - repeated bool repeated_bool = 25; - repeated double repeated_double = 26; - repeated float repeated_float = 27; - repeated string repeated_string = 28; - repeated bytes repeated_bytes = 29; - repeated TestEnum repeated_enum = 30; - repeated TestMessage repeated_msg = 31; - - oneof my_oneof { - int32 oneof_int32 = 41; - int64 oneof_int64 = 42; - uint32 oneof_uint32 = 43; - uint64 oneof_uint64 = 44; - bool oneof_bool = 45; - double oneof_double = 46; - float oneof_float = 47; - string oneof_string = 48; - bytes oneof_bytes = 49; - TestEnum oneof_enum = 50; - TestMessage oneof_msg = 51; - } - - map map_int32_string = 61; - map map_int64_string = 62; - map map_uint32_string = 63; - map map_uint64_string = 64; - map map_bool_string = 65; - map map_string_string = 66; - map map_string_msg = 67; - map map_string_enum = 68; - map map_string_int32 = 69; - map map_string_bool = 70; - - message NestedMessage { - int32 foo = 1; - } - - NestedMessage nested_message = 80; -} - -enum TestEnum { - Default = 0; - A = 1; - B = 2; - C = 3; -} diff --git a/ruby/compatibility_tests/v3.0.0/tests/generated_code_test.rb b/ruby/compatibility_tests/v3.0.0/tests/generated_code_test.rb deleted file mode 100755 index b92b0462d1556..0000000000000 --- a/ruby/compatibility_tests/v3.0.0/tests/generated_code_test.rb +++ /dev/null @@ -1,19 +0,0 @@ -#!/usr/bin/ruby - -# generated_code.rb is in the same directory as this test. -$LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__))) - -require 'generated_code_pb' -require 'test_import_pb' -require 'test/unit' - -class GeneratedCodeTest < Test::Unit::TestCase - def test_generated_msg - # just test that we can instantiate the message. The purpose of this test - # is to ensure that the output of the code generator is valid Ruby and - # successfully creates message definitions and classes, not to test every - # aspect of the extension (basic.rb is for that). - m = A::B::C::TestMessage.new() - m2 = FooBar::TestImportedMessage.new() - end -end diff --git a/ruby/compatibility_tests/v3.0.0/tests/repeated_field_test.rb b/ruby/compatibility_tests/v3.0.0/tests/repeated_field_test.rb deleted file mode 100755 index ed12eaa8de638..0000000000000 --- a/ruby/compatibility_tests/v3.0.0/tests/repeated_field_test.rb +++ /dev/null @@ -1,647 +0,0 @@ -#!/usr/bin/ruby - -require 'google/protobuf' -require 'test/unit' - -class RepeatedFieldTest < Test::Unit::TestCase - - def test_acts_like_enumerator - m = TestMessage.new - (Enumerable.instance_methods - TestMessage.new.repeated_string.methods).each do |method_name| - assert_respond_to m.repeated_string, method_name - end - end - - def test_acts_like_an_array - m = TestMessage.new - arr_methods = ([].methods - TestMessage.new.repeated_string.methods) - # jRuby additions to the Array class that we can ignore - arr_methods -= [ :indices, :iter_for_each, :iter_for_each_index, - :iter_for_each_with_index, :dimensions, :copy_data, :copy_data_simple, - :nitems, :iter_for_reverse_each, :indexes, :append, :prepend] - arr_methods -= [:union, :difference, :filter!] - # ruby 2.7 methods we can ignore - arr_methods -= [:intersection, :deconstruct, :resolve_feature_path] - # ruby 3.1 methods we can ignore - arr_methods -= [:intersect?] - arr_methods.each do |method_name| - assert_respond_to m.repeated_string, method_name - end - end - - def test_first - m = TestMessage.new - repeated_field_names(TestMessage).each do |field_name| - assert_nil m.send(field_name).first - end - fill_test_msg(m) - assert_equal -10, m.repeated_int32.first - assert_equal -1_000_000, m.repeated_int64.first - assert_equal 10, m.repeated_uint32.first - assert_equal 1_000_000, m.repeated_uint64.first - assert m.repeated_bool.first - assert_equal -1.01, m.repeated_float.first.round(2) - assert_equal -1.0000000000001, m.repeated_double.first - assert_equal 'foo', m.repeated_string.first - assert_equal "bar".encode!('ASCII-8BIT'), m.repeated_bytes.first - assert_equal TestMessage2.new(:foo => 1), m.repeated_msg.first - assert_equal :A, m.repeated_enum.first - end - - - def test_last - m = TestMessage.new - repeated_field_names(TestMessage).each do |field_name| - assert_nil m.send(field_name).first - end - fill_test_msg(m) - assert_equal -11, m.repeated_int32.last - assert_equal -1_000_001, m.repeated_int64.last - assert_equal 11, m.repeated_uint32.last - assert_equal 1_000_001, m.repeated_uint64.last - refute m.repeated_bool.last - assert_equal -1.02, m.repeated_float.last.round(2) - assert_equal -1.0000000000002, m.repeated_double.last - assert_equal 'bar', m.repeated_string.last - assert_equal "foo".encode!('ASCII-8BIT'), m.repeated_bytes.last - assert_equal TestMessage2.new(:foo => 2), m.repeated_msg.last - assert_equal :B, m.repeated_enum.last - end - - - def test_pop - m = TestMessage.new - repeated_field_names(TestMessage).each do |field_name| - assert_nil m.send(field_name).pop - end - fill_test_msg(m) - - assert_equal -11, m.repeated_int32.pop - assert_equal -10, m.repeated_int32.pop - assert_equal -1_000_001, m.repeated_int64.pop - assert_equal -1_000_000, m.repeated_int64.pop - assert_equal 11, m.repeated_uint32.pop - assert_equal 10, m.repeated_uint32.pop - assert_equal 1_000_001, m.repeated_uint64.pop - assert_equal 1_000_000, m.repeated_uint64.pop - refute m.repeated_bool.pop - assert m.repeated_bool.pop - assert_equal -1.02, m.repeated_float.pop.round(2) - assert_equal -1.01, m.repeated_float.pop.round(2) - assert_equal -1.0000000000002, m.repeated_double.pop - assert_equal -1.0000000000001, m.repeated_double.pop - assert_equal 'bar', m.repeated_string.pop - assert_equal 'foo', m.repeated_string.pop - assert_equal "foo".encode!('ASCII-8BIT'), m.repeated_bytes.pop - assert_equal "bar".encode!('ASCII-8BIT'), m.repeated_bytes.pop - assert_equal TestMessage2.new(:foo => 2), m.repeated_msg.pop - assert_equal TestMessage2.new(:foo => 1), m.repeated_msg.pop - assert_equal :B, m.repeated_enum.pop - assert_equal :A, m.repeated_enum.pop - repeated_field_names(TestMessage).each do |field_name| - assert_nil m.send(field_name).pop - end - - fill_test_msg(m) - assert_equal ['bar', 'foo'], m.repeated_string.pop(2) - assert_nil m.repeated_string.pop - end - - - def test_each - m = TestMessage.new - 5.times{|i| m.repeated_string << 'string' } - count = 0 - m.repeated_string.each do |val| - assert_equal 'string', val - count += 1 - end - assert_equal 5, count - result = m.repeated_string.each{|val| val + '_junk'} - assert_equal ['string'] * 5, result - end - - - def test_each_index - m = TestMessage.new - 5.times{|i| m.repeated_string << 'string' } - - expected = 0 - m.repeated_string.each_index do |idx| - assert_equal expected, idx - expected += 1 - assert_equal 'string', m.repeated_string[idx] - end - assert_equal 5, expected - end - - - def test_empty? - m = TestMessage.new - assert_empty m.repeated_string - m.repeated_string << 'foo' - refute_empty m.repeated_string - m.repeated_string << 'bar' - refute_empty m.repeated_string - end - - def test_array_accessor - m = TestMessage.new - reference_arr = %w(foo bar baz) - m.repeated_string += reference_arr.clone - check_self_modifying_method(m.repeated_string, reference_arr) do |arr| - arr[1] - end - check_self_modifying_method(m.repeated_string, reference_arr) do |arr| - arr[-2] - end - check_self_modifying_method(m.repeated_string, reference_arr) do |arr| - arr[20] - end - check_self_modifying_method(m.repeated_string, reference_arr) do |arr| - arr[1, 2] - end - check_self_modifying_method(m.repeated_string, reference_arr) do |arr| - arr[0..2] - end - check_self_modifying_method(m.repeated_string, reference_arr) do |arr| - arr[-1, 1] - end - check_self_modifying_method(m.repeated_string, reference_arr) do |arr| - arr[10, 12] - end - end - - def test_array_settor - m = TestMessage.new - reference_arr = %w(foo bar baz) - m.repeated_string += reference_arr.clone - - check_self_modifying_method(m.repeated_string, reference_arr) do |arr| - arr[1] = 'junk' - end - check_self_modifying_method(m.repeated_string, reference_arr) do |arr| - arr[-2] = 'snappy' - end - check_self_modifying_method(m.repeated_string, reference_arr) do |arr| - arr[3] = '' - end - # slight deviation; we are strongly typed, and nil is not allowed - # for string types; - m.repeated_string[5] = 'spacious' - assert_equal ["foo", "snappy", "baz", "", "", "spacious"], m.repeated_string - - #make sure it sests the default types for other fields besides strings - %w(repeated_int32 repeated_int64 repeated_uint32 repeated_uint64).each do |field_name| - m.send(field_name)[3] = 10 - assert_equal [0,0,0,10], m.send(field_name) - end - m.repeated_float[3] = 10.1 - #wonky mri float handling - assert_equal [0,0,0], m.repeated_float.to_a[0..2] - assert_equal 10.1, m.repeated_float[3].round(1) - m.repeated_double[3] = 10.1 - assert_equal [0,0,0,10.1], m.repeated_double - m.repeated_bool[3] = true - assert_equal [false, false, false, true], m.repeated_bool - m.repeated_bytes[3] = "bar".encode!('ASCII-8BIT') - assert_equal ['', '', '', "bar".encode!('ASCII-8BIT')], m.repeated_bytes - m.repeated_msg[3] = TestMessage2.new(:foo => 1) - assert_equal [nil, nil, nil, TestMessage2.new(:foo => 1)], m.repeated_msg - m.repeated_enum[3] = :A - assert_equal [:Default, :Default, :Default, :A], m.repeated_enum - - # check_self_modifying_method(m.repeated_string, reference_arr) do |arr| - # arr[20] = 'spacious' - # end - # TODO: accessor doesn't allow other ruby-like methods - # check_self_modifying_method(m.repeated_string, reference_arr) do |arr| - # arr[1, 2] = 'fizz' - # end - # check_self_modifying_method(m.repeated_string, reference_arr) do |arr| - # arr[0..2] = 'buzz' - # end - end - - def test_push - m = TestMessage.new - reference_arr = %w(foo bar baz) - m.repeated_string += reference_arr.clone - - check_self_modifying_method(m.repeated_string, reference_arr) do |arr| - arr.push('fizz') - end - check_self_modifying_method(m.repeated_string, reference_arr) do |arr| - arr << 'fizz' - end - #TODO: push should support multiple - # check_self_modifying_method(m.repeated_string, reference_arr) do |arr| - # arr.push('fizz', 'buzz') - # end - end - - def test_clear - m = TestMessage.new - reference_arr = %w(foo bar baz) - m.repeated_string += reference_arr.clone - - check_self_modifying_method(m.repeated_string, reference_arr) do |arr| - arr.clear - end - end - - def test_concat - m = TestMessage.new - reference_arr = %w(foo bar baz) - m.repeated_string += reference_arr.clone - m.repeated_string.concat(['fizz', 'buzz']) - assert_equal %w(foo bar baz fizz buzz), m.repeated_string - #TODO: concat should return the orig array - # check_self_modifying_method(m.repeated_string, reference_arr) do |arr| - # arr.concat(['fizz', 'buzz']) - # end - end - - def test_equal - m = TestMessage.new - reference_arr = %w(foo bar baz) - m.repeated_string += reference_arr.clone - assert_equal reference_arr, m.repeated_string - reference_arr << 'fizz' - refute_equal reference_arr, m.repeated_string - m.repeated_string << 'fizz' - assert_equal reference_arr, m.repeated_string - end - - def test_hash - # just a sanity check - m = TestMessage.new - reference_arr = %w(foo bar baz) - m.repeated_string += reference_arr.clone - assert m.repeated_string.hash.is_a?(Integer) - hash = m.repeated_string.hash - assert_equal hash, m.repeated_string.hash - m.repeated_string << 'j' - refute_equal hash, m.repeated_string.hash - end - - def test_plus - m = TestMessage.new - reference_arr = %w(foo bar baz) - m.repeated_string += reference_arr.clone - - check_self_modifying_method(m.repeated_string, reference_arr) do |arr| - arr + ['fizz', 'buzz'] - end - check_self_modifying_method(m.repeated_string, reference_arr) do |arr| - arr += ['fizz', 'buzz'] - end - end - - def test_replace - m = TestMessage.new - reference_arr = %w(foo bar baz) - m.repeated_string += reference_arr.clone - - check_self_modifying_method(m.repeated_string, reference_arr) do |arr| - arr.replace(['fizz', 'buzz']) - end - end - - def test_to_a - m = TestMessage.new - reference_arr = %w(foo bar baz) - m.repeated_string += reference_arr.clone - - check_self_modifying_method(m.repeated_string, reference_arr) do |arr| - arr.to_a - end - end - - def test_to_ary - m = TestMessage.new - reference_arr = %w(foo bar baz) - m.repeated_string += reference_arr.clone - - check_self_modifying_method(m.repeated_string, reference_arr) do |arr| - arr.to_ary - end - end - - # emulate Array behavior - ########################## - - def test_collect! - m = TestMessage.new - reference_arr = %w(foo bar baz) - m.repeated_string += reference_arr.clone - check_self_modifying_method(m.repeated_string, reference_arr) do |arr| - arr.collect!{|x| x + "!" } - end - check_self_modifying_method(m.repeated_string, reference_arr) do |arr| - arr.collect!.with_index{|x, i| x[0...i] } - end - end - - def test_delete - m = TestMessage.new - reference_arr = %w(foo bar baz) - m.repeated_string += reference_arr.clone - check_self_modifying_method(m.repeated_string, reference_arr) do |arr| - arr.delete('bar') - end - check_self_modifying_method(m.repeated_string, reference_arr) do |arr| - arr.delete('nope') - end - check_self_modifying_method(m.repeated_string, reference_arr) do |arr| - arr.delete('nope'){'within'} - end - end - - def test_delete_at - m = TestMessage.new - reference_arr = %w(foo bar baz) - m.repeated_string += reference_arr.clone - check_self_modifying_method(m.repeated_string, reference_arr) do |arr| - arr.delete_at(2) - end - check_self_modifying_method(m.repeated_string, reference_arr) do |arr| - arr.delete_at(10) - end - end - - def test_fill - m = TestMessage.new - reference_arr = %w(foo bar baz) - m.repeated_string += reference_arr.clone - - check_self_modifying_method(m.repeated_string, reference_arr) do |arr| - arr.fill("x") - end - check_self_modifying_method(m.repeated_string, reference_arr) do |arr| - arr.fill("z", 2, 2) - end - check_self_modifying_method(m.repeated_string, reference_arr) do |arr| - arr.fill("y", 0..1) - end - check_self_modifying_method(m.repeated_string, reference_arr) do |arr| - arr.fill { |i| (i*i).to_s } - end - check_self_modifying_method(m.repeated_string, reference_arr) do |arr| - arr.fill(-2) { |i| (i*i*i).to_s } - end - end - - def test_flatten! - m = TestMessage.new - reference_arr = %w(foo bar baz) - m.repeated_string += reference_arr.clone - - check_self_modifying_method(m.repeated_string, reference_arr) do |arr| - arr.flatten! - end - check_self_modifying_method(m.repeated_string, reference_arr) do |arr| - arr.flatten!(1) - end - end - - def test_insert - m = TestMessage.new - reference_arr = %w(foo bar baz) - m.repeated_string += reference_arr.clone - check_self_modifying_method(m.repeated_string, reference_arr) do |arr| - arr.insert(2, 'fizz') - end - check_self_modifying_method(m.repeated_string, reference_arr) do |arr| - arr.insert(3, 'fizz', 'buzz', 'bazz') - end - end - - def test_inspect - m = TestMessage.new - assert_equal '[]', m.repeated_string.inspect - m.repeated_string << 'foo' - assert_equal m.repeated_string.to_a.inspect, m.repeated_string.inspect - m.repeated_string << 'bar' - assert_equal m.repeated_string.to_a.inspect, m.repeated_string.inspect - end - - def test_reverse! - m = TestMessage.new - reference_arr = %w(foo bar baz) - m.repeated_string += reference_arr.clone - - check_self_modifying_method(m.repeated_string, reference_arr) do |arr| - arr.reverse! - end - end - - def test_rotate! - m = TestMessage.new - reference_arr = %w(foo bar baz) - m.repeated_string += reference_arr.clone - - check_self_modifying_method(m.repeated_string, reference_arr) do |arr| - arr.rotate! - end - check_self_modifying_method(m.repeated_string, reference_arr) do |arr| - arr.rotate!(2) - end - end - - def test_select! - m = TestMessage.new - reference_arr = %w(foo bar baz) - m.repeated_string += reference_arr.clone - - check_self_modifying_method(m.repeated_string, reference_arr) do |arr| - arr.select! { |v| v =~ /[aeiou]/ } - end - end - - def test_shift - m = TestMessage.new - reference_arr = %w(foo bar baz) - m.repeated_string += reference_arr.clone - - # should return an element - check_self_modifying_method(m.repeated_string, reference_arr) do |arr| - arr.shift - end - # should return an array - check_self_modifying_method(m.repeated_string, reference_arr) do |arr| - arr.shift(2) - end - # should return nil - check_self_modifying_method(m.repeated_string, reference_arr) do |arr| - arr.shift - end - end - - def test_shuffle! - m = TestMessage.new - m.repeated_string += %w(foo bar baz) - orig_repeated_string = m.repeated_string.clone - result = m.repeated_string.shuffle! - assert_equal m.repeated_string, result - # NOTE: sometimes it doesn't change the order... - # refute_equal m.repeated_string.to_a, orig_repeated_string.to_a - end - - def test_slice! - m = TestMessage.new - reference_arr = %w(foo bar baz bar fizz buzz) - m.repeated_string += reference_arr.clone - - check_self_modifying_method(m.repeated_string, reference_arr) do |arr| - arr.slice!(2) - end - check_self_modifying_method(m.repeated_string, reference_arr) do |arr| - arr.slice!(1,2) - end - check_self_modifying_method(m.repeated_string, reference_arr) do |arr| - arr.slice!(0..1) - end - check_self_modifying_method(m.repeated_string, reference_arr) do |arr| - arr.slice!(10) - end - end - - def test_sort! - m = TestMessage.new - reference_arr = %w(foo bar baz) - m.repeated_string += reference_arr.clone - - check_self_modifying_method(m.repeated_string, reference_arr) do |arr| - arr.sort! - end - check_self_modifying_method(m.repeated_string, reference_arr) do |arr| - arr.sort! { |x,y| y <=> x } - end - end - - def test_sort_by! - m = TestMessage.new - reference_arr = %w(foo bar baz) - m.repeated_string += reference_arr.clone - - check_self_modifying_method(m.repeated_string, reference_arr) do |arr| - arr.sort_by! - end - check_self_modifying_method(m.repeated_string, reference_arr) do |arr| - arr.sort_by!(&:hash) - end - end - - def test_uniq! - m = TestMessage.new - reference_arr = %w(foo bar baz) - m.repeated_string += reference_arr.clone - - check_self_modifying_method(m.repeated_string, reference_arr) do |arr| - arr.uniq! - end - check_self_modifying_method(m.repeated_string, reference_arr) do |arr| - arr.uniq!{|s| s[0] } - end - end - - def test_unshift - m = TestMessage.new - reference_arr = %w(foo bar baz) - m.repeated_string += reference_arr.clone - - check_self_modifying_method(m.repeated_string, reference_arr) do |arr| - arr.unshift('1') - end - check_self_modifying_method(m.repeated_string, reference_arr) do |arr| - arr.unshift('a', 'b') - end - check_self_modifying_method(m.repeated_string, reference_arr) do |arr| - arr.unshift('') - end - end - - - ##### HELPER METHODS - - def check_self_modifying_method(repeated_field, ref_array) - expected_result = yield(ref_array) - actual_result = yield(repeated_field) - if expected_result.is_a?(Enumerator) - assert_equal expected_result.to_a, actual_result.to_a - else - assert_equal expected_result, actual_result - end - assert_equal ref_array, repeated_field - end - - - def repeated_field_names(klass) - klass.descriptor.find_all{|f| f.label == :repeated}.map(&:name) - end - - - def fill_test_msg(test_msg) - test_msg.repeated_int32 += [-10, -11] - test_msg.repeated_int64 += [-1_000_000, -1_000_001] - test_msg.repeated_uint32 += [10, 11] - test_msg.repeated_uint64 += [1_000_000, 1_000_001] - test_msg.repeated_bool += [true, false] - test_msg.repeated_float += [-1.01, -1.02] - test_msg.repeated_double += [-1.0000000000001, -1.0000000000002] - test_msg.repeated_string += %w(foo bar) - test_msg.repeated_bytes += ["bar".encode!('ASCII-8BIT'), "foo".encode!('ASCII-8BIT')] - test_msg.repeated_msg << TestMessage2.new(:foo => 1) - test_msg.repeated_msg << TestMessage2.new(:foo => 2) - test_msg.repeated_enum << :A - test_msg.repeated_enum << :B - end - - - pool = Google::Protobuf::DescriptorPool.new - pool.build do - - add_message "TestMessage" do - optional :optional_int32, :int32, 1 - optional :optional_int64, :int64, 2 - optional :optional_uint32, :uint32, 3 - optional :optional_uint64, :uint64, 4 - optional :optional_bool, :bool, 5 - optional :optional_float, :float, 6 - optional :optional_double, :double, 7 - optional :optional_string, :string, 8 - optional :optional_bytes, :bytes, 9 - optional :optional_msg, :message, 10, "TestMessage2" - optional :optional_enum, :enum, 11, "TestEnum" - - repeated :repeated_int32, :int32, 12 - repeated :repeated_int64, :int64, 13 - repeated :repeated_uint32, :uint32, 14 - repeated :repeated_uint64, :uint64, 15 - repeated :repeated_bool, :bool, 16 - repeated :repeated_float, :float, 17 - repeated :repeated_double, :double, 18 - repeated :repeated_string, :string, 19 - repeated :repeated_bytes, :bytes, 20 - repeated :repeated_msg, :message, 21, "TestMessage2" - repeated :repeated_enum, :enum, 22, "TestEnum" - end - add_message "TestMessage2" do - optional :foo, :int32, 1 - end - - add_enum "TestEnum" do - value :Default, 0 - value :A, 1 - value :B, 2 - value :C, 3 - end - end - - TestMessage = pool.lookup("TestMessage").msgclass - TestMessage2 = pool.lookup("TestMessage2").msgclass - TestEnum = pool.lookup("TestEnum").enummodule - - -end diff --git a/ruby/compatibility_tests/v3.0.0/tests/stress.rb b/ruby/compatibility_tests/v3.0.0/tests/stress.rb deleted file mode 100755 index b688e8b0bd4df..0000000000000 --- a/ruby/compatibility_tests/v3.0.0/tests/stress.rb +++ /dev/null @@ -1,38 +0,0 @@ -#!/usr/bin/ruby - -require 'google/protobuf' -require 'test/unit' - -module StressTest - pool = Google::Protobuf::DescriptorPool.new - pool.build do - add_message "TestMessage" do - optional :a, :int32, 1 - repeated :b, :message, 2, "M" - end - add_message "M" do - optional :foo, :string, 1 - end - end - - TestMessage = pool.lookup("TestMessage").msgclass - M = pool.lookup("M").msgclass - - class StressTest < Test::Unit::TestCase - def get_msg - TestMessage.new(:a => 1000, - :b => [M.new(:foo => "hello"), - M.new(:foo => "world")]) - end - def test_stress - m = get_msg - data = TestMessage.encode(m) - 100_000.times do - mnew = TestMessage.decode(data) - mnew = mnew.dup - assert_equal m.inspect, mnew.inspect - assert_equal data, TestMessage.encode(mnew) - end - end - end -end diff --git a/ruby/compatibility_tests/v3.0.0/tests/test_import.proto b/ruby/compatibility_tests/v3.0.0/tests/test_import.proto deleted file mode 100644 index 230484ee57672..0000000000000 --- a/ruby/compatibility_tests/v3.0.0/tests/test_import.proto +++ /dev/null @@ -1,5 +0,0 @@ -syntax = "proto3"; - -package foo_bar; - -message TestImportedMessage {} From 0b237199c562dad168d5c992bba8a0d7c9d23e00 Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Thu, 28 Dec 2023 05:26:28 -0800 Subject: [PATCH 119/255] Hook up the edition2023 cases to Rust conformance test. PiperOrigin-RevId: 594235463 --- conformance/conformance_rust.rs | 51 ++- conformance/failure_list_rust_cc.txt | 315 +++++++++++++++++- conformance/failure_list_rust_upb.txt | 315 +++++++++++++++++- .../text_format_failure_list_rust_cc.txt | 10 +- .../text_format_failure_list_rust_upb.txt | 10 +- src/google/protobuf/editions/BUILD | 29 ++ 6 files changed, 709 insertions(+), 21 deletions(-) diff --git a/conformance/conformance_rust.rs b/conformance/conformance_rust.rs index 06cbc785f139e..ee18da0760750 100644 --- a/conformance/conformance_rust.rs +++ b/conformance/conformance_rust.rs @@ -16,7 +16,9 @@ use kernel::Optional::{Set, Unset}; use std::io::{self, ErrorKind, Read, Write}; use test_messages_proto2::protobuf_test_messages::proto2::TestAllTypesProto2; +use test_messages_proto2_editions_proto::protobuf_test_messages::editions::proto2::TestAllTypesProto2 as EditionsTestAllTypesProto2; use test_messages_proto3::protobuf_test_messages::proto3::TestAllTypesProto3; +use test_messages_proto3_editions_proto::protobuf_test_messages::editions::proto3::TestAllTypesProto3 as EditionsTestAllTypesProto3; /// Returns Some(i32) if a binary read can succeed from stdin. /// Returns None if we have reached an EOF. @@ -58,11 +60,6 @@ fn write_response_to_stdout(resp: &ConformanceResponse) { fn do_test(req: &ConformanceRequest) -> ConformanceResponse { let mut resp = ConformanceResponse::new(); let message_type = req.message_type(); - let is_proto2 = match message_type.as_bytes() { - b"protobuf_test_messages.proto2.TestAllTypesProto2" => true, - b"protobuf_test_messages.proto3.TestAllTypesProto3" => false, - _ => panic!("unexpected msg type {message_type}"), - }; // Enums aren't supported yet (and not in scope for v0.6) so we can't perform // this check yet. Note that this causes Rust to fail every test case that asks @@ -79,20 +76,40 @@ fn do_test(req: &ConformanceRequest) -> ConformanceResponse { Set(bytes) => bytes, }; - let serialized = if is_proto2 { - let mut proto = TestAllTypesProto2::new(); - if let Err(_) = proto.deserialize(bytes) { - resp.parse_error_mut().set("failed to parse bytes"); - return resp; + let serialized = match message_type.as_bytes() { + b"protobuf_test_messages.proto2.TestAllTypesProto2" => { + let mut proto = TestAllTypesProto2::new(); + if let Err(_) = proto.deserialize(bytes) { + resp.parse_error_mut().set("failed to parse bytes"); + return resp; + } + proto.serialize() } - proto.serialize() - } else { - let mut proto = TestAllTypesProto3::new(); - if let Err(_) = proto.deserialize(bytes) { - resp.parse_error_mut().set("failed to parse bytes"); - return resp; + b"protobuf_test_messages.proto3.TestAllTypesProto3" => { + let mut proto = TestAllTypesProto3::new(); + if let Err(_) = proto.deserialize(bytes) { + resp.parse_error_mut().set("failed to parse bytes"); + return resp; + } + proto.serialize() + } + b"protobuf_test_messages.editions.proto2.TestAllTypesProto2" => { + let mut proto = EditionsTestAllTypesProto2::new(); + if let Err(_) = proto.deserialize(bytes) { + resp.parse_error_mut().set("failed to parse bytes"); + return resp; + } + proto.serialize() } - proto.serialize() + b"protobuf_test_messages.editions.proto3.TestAllTypesProto3" => { + let mut proto = EditionsTestAllTypesProto3::new(); + if let Err(_) = proto.deserialize(bytes) { + resp.parse_error_mut().set("failed to parse bytes"); + return resp; + } + proto.serialize() + } + _ => panic!("unexpected msg type {message_type}"), }; resp.protobuf_payload_mut().set(serialized); diff --git a/conformance/failure_list_rust_cc.txt b/conformance/failure_list_rust_cc.txt index 04f06c1087fe8..2d3a235d0c592 100644 --- a/conformance/failure_list_rust_cc.txt +++ b/conformance/failure_list_rust_cc.txt @@ -311,4 +311,317 @@ Required.Proto3.ProtobufInput.ValidDataScalar.UINT64[1].JsonOutput Required.Proto3.ProtobufInput.ValidDataScalar.UINT64[2].JsonOutput Required.Proto3.TimestampProtoInputTooLarge.JsonOutput - Required.Proto3.TimestampProtoInputTooSmall.JsonOutput \ No newline at end of file + Required.Proto3.TimestampProtoInputTooSmall.JsonOutput + Recommended.Editions_Proto3.FieldMaskNumbersDontRoundTrip.JsonOutput + Recommended.Editions_Proto3.FieldMaskPathsDontRoundTrip.JsonOutput + Recommended.Editions_Proto3.FieldMaskTooManyUnderscore.JsonOutput + Recommended.Editions_Proto3.ProtobufInput.OneofZeroBool.JsonOutput + Recommended.Editions_Proto3.ProtobufInput.OneofZeroBytes.JsonOutput + Recommended.Editions_Proto3.ProtobufInput.OneofZeroDouble.JsonOutput + Recommended.Editions_Proto3.ProtobufInput.OneofZeroEnum.JsonOutput + Recommended.Editions_Proto3.ProtobufInput.OneofZeroFloat.JsonOutput + Recommended.Editions_Proto3.ProtobufInput.OneofZeroMessage.JsonOutput + Recommended.Editions_Proto3.ProtobufInput.OneofZeroMessageSetTwice.JsonOutput + Recommended.Editions_Proto3.ProtobufInput.OneofZeroString.JsonOutput + Recommended.Editions_Proto3.ProtobufInput.OneofZeroUint32.JsonOutput + Recommended.Editions_Proto3.ProtobufInput.OneofZeroUint64.JsonOutput + Recommended.Editions_Proto3.ValueRejectInfNumberValue.JsonOutput + Recommended.Editions_Proto3.ValueRejectNanNumberValue.JsonOutput + Required.Editions_Proto3.DurationProtoInputTooLarge.JsonOutput + Required.Editions_Proto3.DurationProtoInputTooSmall.JsonOutput + Required.Editions_Proto3.ProtobufInput.DoubleFieldNormalizeQuietNan.JsonOutput + Required.Editions_Proto3.ProtobufInput.DoubleFieldNormalizeSignalingNan.JsonOutput + Required.Editions_Proto3.ProtobufInput.FloatFieldNormalizeQuietNan.JsonOutput + Required.Editions_Proto3.ProtobufInput.FloatFieldNormalizeSignalingNan.JsonOutput + Required.Editions_Proto3.ProtobufInput.RepeatedScalarMessageMerge.JsonOutput + Required.Editions_Proto3.ProtobufInput.RepeatedScalarSelectsLast.BOOL.JsonOutput + Required.Editions_Proto3.ProtobufInput.RepeatedScalarSelectsLast.BYTES.JsonOutput + Required.Editions_Proto3.ProtobufInput.RepeatedScalarSelectsLast.DOUBLE.JsonOutput + Required.Editions_Proto3.ProtobufInput.RepeatedScalarSelectsLast.ENUM.JsonOutput + Required.Editions_Proto3.ProtobufInput.RepeatedScalarSelectsLast.FIXED32.JsonOutput + Required.Editions_Proto3.ProtobufInput.RepeatedScalarSelectsLast.FIXED64.JsonOutput + Required.Editions_Proto3.ProtobufInput.RepeatedScalarSelectsLast.FLOAT.JsonOutput + Required.Editions_Proto3.ProtobufInput.RepeatedScalarSelectsLast.INT32.JsonOutput + Required.Editions_Proto3.ProtobufInput.RepeatedScalarSelectsLast.INT64.JsonOutput + Required.Editions_Proto3.ProtobufInput.RepeatedScalarSelectsLast.SFIXED32.JsonOutput + Required.Editions_Proto3.ProtobufInput.RepeatedScalarSelectsLast.SFIXED64.JsonOutput + Required.Editions_Proto3.ProtobufInput.RepeatedScalarSelectsLast.SINT32.JsonOutput + Required.Editions_Proto3.ProtobufInput.RepeatedScalarSelectsLast.SINT64.JsonOutput + Required.Editions_Proto3.ProtobufInput.RepeatedScalarSelectsLast.STRING.JsonOutput + Required.Editions_Proto3.ProtobufInput.RepeatedScalarSelectsLast.UINT32.JsonOutput + Required.Editions_Proto3.ProtobufInput.RepeatedScalarSelectsLast.UINT64.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.BOOL.BOOL.Default.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.BOOL.BOOL.DuplicateKey.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.BOOL.BOOL.DuplicateKeyInMapEntry.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.BOOL.BOOL.DuplicateValueInMapEntry.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.BOOL.BOOL.MissingDefault.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.BOOL.BOOL.NonDefault.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.BOOL.BOOL.Unordered.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.FIXED32.FIXED32.Default.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.FIXED32.FIXED32.DuplicateKey.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.FIXED32.FIXED32.DuplicateKeyInMapEntry.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.FIXED32.FIXED32.DuplicateValueInMapEntry.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.FIXED32.FIXED32.MissingDefault.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.FIXED32.FIXED32.NonDefault.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.FIXED32.FIXED32.Unordered.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.FIXED64.FIXED64.Default.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.FIXED64.FIXED64.DuplicateKey.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.FIXED64.FIXED64.DuplicateKeyInMapEntry.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.FIXED64.FIXED64.DuplicateValueInMapEntry.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.FIXED64.FIXED64.MissingDefault.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.FIXED64.FIXED64.NonDefault.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.FIXED64.FIXED64.Unordered.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.INT32.DOUBLE.Default.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.INT32.DOUBLE.DuplicateKey.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.INT32.DOUBLE.DuplicateKeyInMapEntry.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.INT32.DOUBLE.DuplicateValueInMapEntry.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.INT32.DOUBLE.MissingDefault.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.INT32.DOUBLE.NonDefault.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.INT32.DOUBLE.Unordered.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.INT32.FLOAT.Default.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.INT32.FLOAT.DuplicateKey.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.INT32.FLOAT.DuplicateKeyInMapEntry.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.INT32.FLOAT.DuplicateValueInMapEntry.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.INT32.FLOAT.MissingDefault.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.INT32.FLOAT.NonDefault.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.INT32.FLOAT.Unordered.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.INT32.INT32.Default.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.INT32.INT32.DuplicateKey.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.INT32.INT32.DuplicateKeyInMapEntry.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.INT32.INT32.DuplicateValueInMapEntry.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.INT32.INT32.MissingDefault.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.INT32.INT32.NonDefault.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.INT32.INT32.Unordered.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.INT64.INT64.Default.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.INT64.INT64.DuplicateKey.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.INT64.INT64.DuplicateKeyInMapEntry.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.INT64.INT64.DuplicateValueInMapEntry.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.INT64.INT64.MissingDefault.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.INT64.INT64.NonDefault.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.INT64.INT64.Unordered.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.SFIXED32.SFIXED32.Default.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.SFIXED32.SFIXED32.DuplicateKey.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.SFIXED32.SFIXED32.DuplicateKeyInMapEntry.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.SFIXED32.SFIXED32.DuplicateValueInMapEntry.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.SFIXED32.SFIXED32.MissingDefault.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.SFIXED32.SFIXED32.NonDefault.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.SFIXED32.SFIXED32.Unordered.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.SFIXED64.SFIXED64.Default.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.SFIXED64.SFIXED64.DuplicateKey.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.SFIXED64.SFIXED64.DuplicateKeyInMapEntry.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.SFIXED64.SFIXED64.DuplicateValueInMapEntry.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.SFIXED64.SFIXED64.MissingDefault.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.SFIXED64.SFIXED64.NonDefault.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.SFIXED64.SFIXED64.Unordered.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.SINT32.SINT32.Default.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.SINT32.SINT32.DuplicateKey.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.SINT32.SINT32.DuplicateKeyInMapEntry.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.SINT32.SINT32.DuplicateValueInMapEntry.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.SINT32.SINT32.MissingDefault.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.SINT32.SINT32.NonDefault.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.SINT32.SINT32.Unordered.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.SINT64.SINT64.Default.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.SINT64.SINT64.DuplicateKey.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.SINT64.SINT64.DuplicateKeyInMapEntry.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.SINT64.SINT64.DuplicateValueInMapEntry.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.SINT64.SINT64.MissingDefault.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.SINT64.SINT64.NonDefault.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.SINT64.SINT64.Unordered.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.STRING.BYTES.Default.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.STRING.BYTES.DuplicateKey.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.STRING.BYTES.DuplicateKeyInMapEntry.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.STRING.BYTES.DuplicateValueInMapEntry.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.STRING.BYTES.MissingDefault.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.STRING.BYTES.NonDefault.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.STRING.BYTES.Unordered.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.STRING.ENUM.Default.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.STRING.ENUM.DuplicateKey.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.STRING.ENUM.DuplicateKeyInMapEntry.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.STRING.ENUM.DuplicateValueInMapEntry.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.STRING.ENUM.MissingDefault.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.STRING.ENUM.NonDefault.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.STRING.ENUM.Unordered.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.STRING.MESSAGE.Default.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.STRING.MESSAGE.DuplicateKey.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.STRING.MESSAGE.DuplicateKeyInMapEntry.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.STRING.MESSAGE.DuplicateValueInMapEntry.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.STRING.MESSAGE.MergeValue.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.STRING.MESSAGE.MissingDefault.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.STRING.MESSAGE.NonDefault.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.STRING.MESSAGE.Unordered.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.STRING.STRING.Default.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.STRING.STRING.DuplicateKey.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.STRING.STRING.DuplicateKeyInMapEntry.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.STRING.STRING.DuplicateValueInMapEntry.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.STRING.STRING.MissingDefault.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.STRING.STRING.NonDefault.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.STRING.STRING.Unordered.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.UINT32.UINT32.Default.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.UINT32.UINT32.DuplicateKey.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.UINT32.UINT32.DuplicateKeyInMapEntry.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.UINT32.UINT32.DuplicateValueInMapEntry.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.UINT32.UINT32.MissingDefault.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.UINT32.UINT32.NonDefault.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.UINT32.UINT32.Unordered.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.UINT64.UINT64.Default.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.UINT64.UINT64.DuplicateKey.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.UINT64.UINT64.DuplicateKeyInMapEntry.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.UINT64.UINT64.DuplicateValueInMapEntry.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.UINT64.UINT64.MissingDefault.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.UINT64.UINT64.NonDefault.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.UINT64.UINT64.Unordered.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataOneof.BOOL.DefaultValue.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataOneof.BOOL.MultipleValuesForDifferentField.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataOneof.BOOL.MultipleValuesForSameField.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataOneof.BOOL.NonDefaultValue.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataOneof.BYTES.DefaultValue.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataOneof.BYTES.MultipleValuesForDifferentField.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataOneof.BYTES.MultipleValuesForSameField.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataOneof.BYTES.NonDefaultValue.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataOneof.DOUBLE.DefaultValue.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataOneof.DOUBLE.MultipleValuesForDifferentField.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataOneof.DOUBLE.MultipleValuesForSameField.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataOneof.DOUBLE.NonDefaultValue.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataOneof.ENUM.DefaultValue.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataOneof.ENUM.MultipleValuesForDifferentField.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataOneof.ENUM.MultipleValuesForSameField.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataOneof.ENUM.NonDefaultValue.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataOneof.FLOAT.DefaultValue.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataOneof.FLOAT.MultipleValuesForDifferentField.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataOneof.FLOAT.MultipleValuesForSameField.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataOneof.FLOAT.NonDefaultValue.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataOneof.MESSAGE.DefaultValue.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataOneof.MESSAGE.Merge.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataOneof.MESSAGE.MultipleValuesForDifferentField.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataOneof.MESSAGE.MultipleValuesForSameField.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataOneof.MESSAGE.NonDefaultValue.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataOneof.STRING.DefaultValue.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataOneof.STRING.MultipleValuesForDifferentField.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataOneof.STRING.MultipleValuesForSameField.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataOneof.STRING.NonDefaultValue.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataOneof.UINT32.DefaultValue.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataOneof.UINT32.MultipleValuesForDifferentField.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataOneof.UINT32.MultipleValuesForSameField.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataOneof.UINT32.NonDefaultValue.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataOneof.UINT64.DefaultValue.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataOneof.UINT64.MultipleValuesForDifferentField.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataOneof.UINT64.MultipleValuesForSameField.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataOneof.UINT64.NonDefaultValue.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataRepeated.BOOL.PackedInput.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataRepeated.BOOL.UnpackedInput.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataRepeated.BYTES.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataRepeated.DOUBLE.PackedInput.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataRepeated.DOUBLE.UnpackedInput.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataRepeated.ENUM.PackedInput.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataRepeated.ENUM.UnpackedInput.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataRepeated.FIXED32.PackedInput.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataRepeated.FIXED32.UnpackedInput.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataRepeated.FIXED64.PackedInput.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataRepeated.FIXED64.UnpackedInput.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataRepeated.FLOAT.PackedInput.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataRepeated.FLOAT.UnpackedInput.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataRepeated.INT32.PackedInput.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataRepeated.INT32.UnpackedInput.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataRepeated.INT64.PackedInput.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataRepeated.INT64.UnpackedInput.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataRepeated.MESSAGE.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataRepeated.SFIXED32.PackedInput.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataRepeated.SFIXED32.UnpackedInput.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataRepeated.SFIXED64.PackedInput.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataRepeated.SFIXED64.UnpackedInput.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataRepeated.SINT32.PackedInput.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataRepeated.SINT32.UnpackedInput.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataRepeated.SINT64.PackedInput.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataRepeated.SINT64.UnpackedInput.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataRepeated.STRING.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataRepeated.UINT32.PackedInput.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataRepeated.UINT32.UnpackedInput.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataRepeated.UINT64.PackedInput.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataRepeated.UINT64.UnpackedInput.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.BOOL[0].JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.BOOL[1].JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.BOOL[2].JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.BOOL[3].JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.BOOL[4].JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.BOOL[5].JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.BOOL[6].JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.BYTES[0].JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.BYTES[1].JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.BYTES[2].JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.BYTES[3].JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.DOUBLE[0].JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.DOUBLE[1].JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.DOUBLE[2].JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.DOUBLE[3].JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.ENUM[0].JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.ENUM[1].JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.ENUM[2].JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.ENUM[3].JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.ENUM[4].JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.ENUM[5].JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.FIXED32[0].JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.FIXED32[1].JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.FIXED32[2].JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.FIXED64[0].JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.FIXED64[1].JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.FIXED64[2].JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.FLOAT[0].JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.FLOAT[1].JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.FLOAT[2].JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.FLOAT[3].JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.FLOAT[4].JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.INT32[0].JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.INT32[1].JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.INT32[2].JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.INT32[3].JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.INT32[4].JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.INT32[5].JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.INT32[6].JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.INT32[7].JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.INT32[8].JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.INT32[9].JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.INT64[0].JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.INT64[1].JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.INT64[2].JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.INT64[3].JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.MESSAGE[0].JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.MESSAGE[1].JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.SFIXED32[0].JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.SFIXED32[1].JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.SFIXED32[2].JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.SFIXED32[3].JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.SFIXED64[0].JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.SFIXED64[1].JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.SFIXED64[2].JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.SFIXED64[3].JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.SINT32[0].JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.SINT32[1].JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.SINT32[2].JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.SINT32[3].JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.SINT32[4].JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.SINT64[0].JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.SINT64[1].JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.SINT64[2].JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.SINT64[3].JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.STRING[0].JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.STRING[1].JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.STRING[2].JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.STRING[3].JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.STRING[4].JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.STRING[5].JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.STRING[6].JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.UINT32[0].JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.UINT32[1].JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.UINT32[2].JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.UINT32[3].JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.UINT32[4].JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.UINT32[5].JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.UINT32[6].JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.UINT32[7].JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.UINT32[8].JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.UINT32[9].JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.UINT64[0].JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.UINT64[1].JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.UINT64[2].JsonOutput + Required.Editions_Proto3.TimestampProtoInputTooLarge.JsonOutput + Required.Editions_Proto3.TimestampProtoInputTooSmall.JsonOutput diff --git a/conformance/failure_list_rust_upb.txt b/conformance/failure_list_rust_upb.txt index 04f06c1087fe8..2d3a235d0c592 100644 --- a/conformance/failure_list_rust_upb.txt +++ b/conformance/failure_list_rust_upb.txt @@ -311,4 +311,317 @@ Required.Proto3.ProtobufInput.ValidDataScalar.UINT64[1].JsonOutput Required.Proto3.ProtobufInput.ValidDataScalar.UINT64[2].JsonOutput Required.Proto3.TimestampProtoInputTooLarge.JsonOutput - Required.Proto3.TimestampProtoInputTooSmall.JsonOutput \ No newline at end of file + Required.Proto3.TimestampProtoInputTooSmall.JsonOutput + Recommended.Editions_Proto3.FieldMaskNumbersDontRoundTrip.JsonOutput + Recommended.Editions_Proto3.FieldMaskPathsDontRoundTrip.JsonOutput + Recommended.Editions_Proto3.FieldMaskTooManyUnderscore.JsonOutput + Recommended.Editions_Proto3.ProtobufInput.OneofZeroBool.JsonOutput + Recommended.Editions_Proto3.ProtobufInput.OneofZeroBytes.JsonOutput + Recommended.Editions_Proto3.ProtobufInput.OneofZeroDouble.JsonOutput + Recommended.Editions_Proto3.ProtobufInput.OneofZeroEnum.JsonOutput + Recommended.Editions_Proto3.ProtobufInput.OneofZeroFloat.JsonOutput + Recommended.Editions_Proto3.ProtobufInput.OneofZeroMessage.JsonOutput + Recommended.Editions_Proto3.ProtobufInput.OneofZeroMessageSetTwice.JsonOutput + Recommended.Editions_Proto3.ProtobufInput.OneofZeroString.JsonOutput + Recommended.Editions_Proto3.ProtobufInput.OneofZeroUint32.JsonOutput + Recommended.Editions_Proto3.ProtobufInput.OneofZeroUint64.JsonOutput + Recommended.Editions_Proto3.ValueRejectInfNumberValue.JsonOutput + Recommended.Editions_Proto3.ValueRejectNanNumberValue.JsonOutput + Required.Editions_Proto3.DurationProtoInputTooLarge.JsonOutput + Required.Editions_Proto3.DurationProtoInputTooSmall.JsonOutput + Required.Editions_Proto3.ProtobufInput.DoubleFieldNormalizeQuietNan.JsonOutput + Required.Editions_Proto3.ProtobufInput.DoubleFieldNormalizeSignalingNan.JsonOutput + Required.Editions_Proto3.ProtobufInput.FloatFieldNormalizeQuietNan.JsonOutput + Required.Editions_Proto3.ProtobufInput.FloatFieldNormalizeSignalingNan.JsonOutput + Required.Editions_Proto3.ProtobufInput.RepeatedScalarMessageMerge.JsonOutput + Required.Editions_Proto3.ProtobufInput.RepeatedScalarSelectsLast.BOOL.JsonOutput + Required.Editions_Proto3.ProtobufInput.RepeatedScalarSelectsLast.BYTES.JsonOutput + Required.Editions_Proto3.ProtobufInput.RepeatedScalarSelectsLast.DOUBLE.JsonOutput + Required.Editions_Proto3.ProtobufInput.RepeatedScalarSelectsLast.ENUM.JsonOutput + Required.Editions_Proto3.ProtobufInput.RepeatedScalarSelectsLast.FIXED32.JsonOutput + Required.Editions_Proto3.ProtobufInput.RepeatedScalarSelectsLast.FIXED64.JsonOutput + Required.Editions_Proto3.ProtobufInput.RepeatedScalarSelectsLast.FLOAT.JsonOutput + Required.Editions_Proto3.ProtobufInput.RepeatedScalarSelectsLast.INT32.JsonOutput + Required.Editions_Proto3.ProtobufInput.RepeatedScalarSelectsLast.INT64.JsonOutput + Required.Editions_Proto3.ProtobufInput.RepeatedScalarSelectsLast.SFIXED32.JsonOutput + Required.Editions_Proto3.ProtobufInput.RepeatedScalarSelectsLast.SFIXED64.JsonOutput + Required.Editions_Proto3.ProtobufInput.RepeatedScalarSelectsLast.SINT32.JsonOutput + Required.Editions_Proto3.ProtobufInput.RepeatedScalarSelectsLast.SINT64.JsonOutput + Required.Editions_Proto3.ProtobufInput.RepeatedScalarSelectsLast.STRING.JsonOutput + Required.Editions_Proto3.ProtobufInput.RepeatedScalarSelectsLast.UINT32.JsonOutput + Required.Editions_Proto3.ProtobufInput.RepeatedScalarSelectsLast.UINT64.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.BOOL.BOOL.Default.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.BOOL.BOOL.DuplicateKey.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.BOOL.BOOL.DuplicateKeyInMapEntry.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.BOOL.BOOL.DuplicateValueInMapEntry.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.BOOL.BOOL.MissingDefault.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.BOOL.BOOL.NonDefault.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.BOOL.BOOL.Unordered.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.FIXED32.FIXED32.Default.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.FIXED32.FIXED32.DuplicateKey.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.FIXED32.FIXED32.DuplicateKeyInMapEntry.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.FIXED32.FIXED32.DuplicateValueInMapEntry.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.FIXED32.FIXED32.MissingDefault.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.FIXED32.FIXED32.NonDefault.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.FIXED32.FIXED32.Unordered.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.FIXED64.FIXED64.Default.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.FIXED64.FIXED64.DuplicateKey.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.FIXED64.FIXED64.DuplicateKeyInMapEntry.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.FIXED64.FIXED64.DuplicateValueInMapEntry.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.FIXED64.FIXED64.MissingDefault.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.FIXED64.FIXED64.NonDefault.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.FIXED64.FIXED64.Unordered.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.INT32.DOUBLE.Default.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.INT32.DOUBLE.DuplicateKey.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.INT32.DOUBLE.DuplicateKeyInMapEntry.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.INT32.DOUBLE.DuplicateValueInMapEntry.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.INT32.DOUBLE.MissingDefault.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.INT32.DOUBLE.NonDefault.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.INT32.DOUBLE.Unordered.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.INT32.FLOAT.Default.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.INT32.FLOAT.DuplicateKey.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.INT32.FLOAT.DuplicateKeyInMapEntry.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.INT32.FLOAT.DuplicateValueInMapEntry.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.INT32.FLOAT.MissingDefault.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.INT32.FLOAT.NonDefault.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.INT32.FLOAT.Unordered.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.INT32.INT32.Default.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.INT32.INT32.DuplicateKey.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.INT32.INT32.DuplicateKeyInMapEntry.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.INT32.INT32.DuplicateValueInMapEntry.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.INT32.INT32.MissingDefault.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.INT32.INT32.NonDefault.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.INT32.INT32.Unordered.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.INT64.INT64.Default.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.INT64.INT64.DuplicateKey.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.INT64.INT64.DuplicateKeyInMapEntry.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.INT64.INT64.DuplicateValueInMapEntry.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.INT64.INT64.MissingDefault.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.INT64.INT64.NonDefault.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.INT64.INT64.Unordered.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.SFIXED32.SFIXED32.Default.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.SFIXED32.SFIXED32.DuplicateKey.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.SFIXED32.SFIXED32.DuplicateKeyInMapEntry.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.SFIXED32.SFIXED32.DuplicateValueInMapEntry.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.SFIXED32.SFIXED32.MissingDefault.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.SFIXED32.SFIXED32.NonDefault.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.SFIXED32.SFIXED32.Unordered.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.SFIXED64.SFIXED64.Default.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.SFIXED64.SFIXED64.DuplicateKey.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.SFIXED64.SFIXED64.DuplicateKeyInMapEntry.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.SFIXED64.SFIXED64.DuplicateValueInMapEntry.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.SFIXED64.SFIXED64.MissingDefault.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.SFIXED64.SFIXED64.NonDefault.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.SFIXED64.SFIXED64.Unordered.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.SINT32.SINT32.Default.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.SINT32.SINT32.DuplicateKey.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.SINT32.SINT32.DuplicateKeyInMapEntry.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.SINT32.SINT32.DuplicateValueInMapEntry.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.SINT32.SINT32.MissingDefault.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.SINT32.SINT32.NonDefault.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.SINT32.SINT32.Unordered.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.SINT64.SINT64.Default.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.SINT64.SINT64.DuplicateKey.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.SINT64.SINT64.DuplicateKeyInMapEntry.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.SINT64.SINT64.DuplicateValueInMapEntry.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.SINT64.SINT64.MissingDefault.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.SINT64.SINT64.NonDefault.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.SINT64.SINT64.Unordered.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.STRING.BYTES.Default.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.STRING.BYTES.DuplicateKey.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.STRING.BYTES.DuplicateKeyInMapEntry.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.STRING.BYTES.DuplicateValueInMapEntry.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.STRING.BYTES.MissingDefault.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.STRING.BYTES.NonDefault.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.STRING.BYTES.Unordered.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.STRING.ENUM.Default.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.STRING.ENUM.DuplicateKey.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.STRING.ENUM.DuplicateKeyInMapEntry.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.STRING.ENUM.DuplicateValueInMapEntry.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.STRING.ENUM.MissingDefault.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.STRING.ENUM.NonDefault.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.STRING.ENUM.Unordered.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.STRING.MESSAGE.Default.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.STRING.MESSAGE.DuplicateKey.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.STRING.MESSAGE.DuplicateKeyInMapEntry.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.STRING.MESSAGE.DuplicateValueInMapEntry.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.STRING.MESSAGE.MergeValue.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.STRING.MESSAGE.MissingDefault.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.STRING.MESSAGE.NonDefault.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.STRING.MESSAGE.Unordered.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.STRING.STRING.Default.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.STRING.STRING.DuplicateKey.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.STRING.STRING.DuplicateKeyInMapEntry.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.STRING.STRING.DuplicateValueInMapEntry.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.STRING.STRING.MissingDefault.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.STRING.STRING.NonDefault.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.STRING.STRING.Unordered.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.UINT32.UINT32.Default.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.UINT32.UINT32.DuplicateKey.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.UINT32.UINT32.DuplicateKeyInMapEntry.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.UINT32.UINT32.DuplicateValueInMapEntry.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.UINT32.UINT32.MissingDefault.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.UINT32.UINT32.NonDefault.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.UINT32.UINT32.Unordered.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.UINT64.UINT64.Default.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.UINT64.UINT64.DuplicateKey.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.UINT64.UINT64.DuplicateKeyInMapEntry.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.UINT64.UINT64.DuplicateValueInMapEntry.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.UINT64.UINT64.MissingDefault.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.UINT64.UINT64.NonDefault.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataMap.UINT64.UINT64.Unordered.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataOneof.BOOL.DefaultValue.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataOneof.BOOL.MultipleValuesForDifferentField.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataOneof.BOOL.MultipleValuesForSameField.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataOneof.BOOL.NonDefaultValue.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataOneof.BYTES.DefaultValue.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataOneof.BYTES.MultipleValuesForDifferentField.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataOneof.BYTES.MultipleValuesForSameField.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataOneof.BYTES.NonDefaultValue.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataOneof.DOUBLE.DefaultValue.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataOneof.DOUBLE.MultipleValuesForDifferentField.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataOneof.DOUBLE.MultipleValuesForSameField.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataOneof.DOUBLE.NonDefaultValue.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataOneof.ENUM.DefaultValue.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataOneof.ENUM.MultipleValuesForDifferentField.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataOneof.ENUM.MultipleValuesForSameField.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataOneof.ENUM.NonDefaultValue.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataOneof.FLOAT.DefaultValue.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataOneof.FLOAT.MultipleValuesForDifferentField.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataOneof.FLOAT.MultipleValuesForSameField.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataOneof.FLOAT.NonDefaultValue.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataOneof.MESSAGE.DefaultValue.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataOneof.MESSAGE.Merge.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataOneof.MESSAGE.MultipleValuesForDifferentField.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataOneof.MESSAGE.MultipleValuesForSameField.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataOneof.MESSAGE.NonDefaultValue.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataOneof.STRING.DefaultValue.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataOneof.STRING.MultipleValuesForDifferentField.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataOneof.STRING.MultipleValuesForSameField.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataOneof.STRING.NonDefaultValue.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataOneof.UINT32.DefaultValue.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataOneof.UINT32.MultipleValuesForDifferentField.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataOneof.UINT32.MultipleValuesForSameField.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataOneof.UINT32.NonDefaultValue.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataOneof.UINT64.DefaultValue.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataOneof.UINT64.MultipleValuesForDifferentField.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataOneof.UINT64.MultipleValuesForSameField.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataOneof.UINT64.NonDefaultValue.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataRepeated.BOOL.PackedInput.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataRepeated.BOOL.UnpackedInput.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataRepeated.BYTES.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataRepeated.DOUBLE.PackedInput.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataRepeated.DOUBLE.UnpackedInput.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataRepeated.ENUM.PackedInput.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataRepeated.ENUM.UnpackedInput.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataRepeated.FIXED32.PackedInput.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataRepeated.FIXED32.UnpackedInput.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataRepeated.FIXED64.PackedInput.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataRepeated.FIXED64.UnpackedInput.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataRepeated.FLOAT.PackedInput.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataRepeated.FLOAT.UnpackedInput.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataRepeated.INT32.PackedInput.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataRepeated.INT32.UnpackedInput.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataRepeated.INT64.PackedInput.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataRepeated.INT64.UnpackedInput.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataRepeated.MESSAGE.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataRepeated.SFIXED32.PackedInput.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataRepeated.SFIXED32.UnpackedInput.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataRepeated.SFIXED64.PackedInput.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataRepeated.SFIXED64.UnpackedInput.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataRepeated.SINT32.PackedInput.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataRepeated.SINT32.UnpackedInput.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataRepeated.SINT64.PackedInput.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataRepeated.SINT64.UnpackedInput.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataRepeated.STRING.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataRepeated.UINT32.PackedInput.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataRepeated.UINT32.UnpackedInput.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataRepeated.UINT64.PackedInput.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataRepeated.UINT64.UnpackedInput.JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.BOOL[0].JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.BOOL[1].JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.BOOL[2].JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.BOOL[3].JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.BOOL[4].JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.BOOL[5].JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.BOOL[6].JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.BYTES[0].JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.BYTES[1].JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.BYTES[2].JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.BYTES[3].JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.DOUBLE[0].JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.DOUBLE[1].JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.DOUBLE[2].JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.DOUBLE[3].JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.ENUM[0].JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.ENUM[1].JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.ENUM[2].JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.ENUM[3].JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.ENUM[4].JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.ENUM[5].JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.FIXED32[0].JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.FIXED32[1].JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.FIXED32[2].JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.FIXED64[0].JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.FIXED64[1].JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.FIXED64[2].JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.FLOAT[0].JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.FLOAT[1].JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.FLOAT[2].JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.FLOAT[3].JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.FLOAT[4].JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.INT32[0].JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.INT32[1].JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.INT32[2].JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.INT32[3].JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.INT32[4].JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.INT32[5].JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.INT32[6].JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.INT32[7].JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.INT32[8].JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.INT32[9].JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.INT64[0].JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.INT64[1].JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.INT64[2].JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.INT64[3].JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.MESSAGE[0].JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.MESSAGE[1].JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.SFIXED32[0].JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.SFIXED32[1].JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.SFIXED32[2].JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.SFIXED32[3].JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.SFIXED64[0].JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.SFIXED64[1].JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.SFIXED64[2].JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.SFIXED64[3].JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.SINT32[0].JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.SINT32[1].JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.SINT32[2].JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.SINT32[3].JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.SINT32[4].JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.SINT64[0].JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.SINT64[1].JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.SINT64[2].JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.SINT64[3].JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.STRING[0].JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.STRING[1].JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.STRING[2].JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.STRING[3].JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.STRING[4].JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.STRING[5].JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.STRING[6].JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.UINT32[0].JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.UINT32[1].JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.UINT32[2].JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.UINT32[3].JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.UINT32[4].JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.UINT32[5].JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.UINT32[6].JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.UINT32[7].JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.UINT32[8].JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.UINT32[9].JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.UINT64[0].JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.UINT64[1].JsonOutput + Required.Editions_Proto3.ProtobufInput.ValidDataScalar.UINT64[2].JsonOutput + Required.Editions_Proto3.TimestampProtoInputTooLarge.JsonOutput + Required.Editions_Proto3.TimestampProtoInputTooSmall.JsonOutput diff --git a/conformance/text_format_failure_list_rust_cc.txt b/conformance/text_format_failure_list_rust_cc.txt index bb9866c1051ca..830ee9ad527a4 100644 --- a/conformance/text_format_failure_list_rust_cc.txt +++ b/conformance/text_format_failure_list_rust_cc.txt @@ -6,4 +6,12 @@ Recommended.Proto3.ProtobufInput.RepeatedUnknownFields_Drop.TextFormatOutput Recommended.Proto3.ProtobufInput.RepeatedUnknownFields_Print.TextFormatOutput Recommended.Proto3.ProtobufInput.ScalarUnknownFields_Drop.TextFormatOutput - Recommended.Proto3.ProtobufInput.ScalarUnknownFields_Print.TextFormatOutput \ No newline at end of file + Recommended.Proto3.ProtobufInput.ScalarUnknownFields_Print.TextFormatOutput + Recommended.Editions_Proto3.ProtobufInput.GroupUnknownFields_Drop.TextFormatOutput + Recommended.Editions_Proto3.ProtobufInput.GroupUnknownFields_Print.TextFormatOutput + Recommended.Editions_Proto3.ProtobufInput.MessageUnknownFields_Drop.TextFormatOutput + Recommended.Editions_Proto3.ProtobufInput.MessageUnknownFields_Print.TextFormatOutput + Recommended.Editions_Proto3.ProtobufInput.RepeatedUnknownFields_Drop.TextFormatOutput + Recommended.Editions_Proto3.ProtobufInput.RepeatedUnknownFields_Print.TextFormatOutput + Recommended.Editions_Proto3.ProtobufInput.ScalarUnknownFields_Drop.TextFormatOutput + Recommended.Editions_Proto3.ProtobufInput.ScalarUnknownFields_Print.TextFormatOutput \ No newline at end of file diff --git a/conformance/text_format_failure_list_rust_upb.txt b/conformance/text_format_failure_list_rust_upb.txt index bb9866c1051ca..830ee9ad527a4 100644 --- a/conformance/text_format_failure_list_rust_upb.txt +++ b/conformance/text_format_failure_list_rust_upb.txt @@ -6,4 +6,12 @@ Recommended.Proto3.ProtobufInput.RepeatedUnknownFields_Drop.TextFormatOutput Recommended.Proto3.ProtobufInput.RepeatedUnknownFields_Print.TextFormatOutput Recommended.Proto3.ProtobufInput.ScalarUnknownFields_Drop.TextFormatOutput - Recommended.Proto3.ProtobufInput.ScalarUnknownFields_Print.TextFormatOutput \ No newline at end of file + Recommended.Proto3.ProtobufInput.ScalarUnknownFields_Print.TextFormatOutput + Recommended.Editions_Proto3.ProtobufInput.GroupUnknownFields_Drop.TextFormatOutput + Recommended.Editions_Proto3.ProtobufInput.GroupUnknownFields_Print.TextFormatOutput + Recommended.Editions_Proto3.ProtobufInput.MessageUnknownFields_Drop.TextFormatOutput + Recommended.Editions_Proto3.ProtobufInput.MessageUnknownFields_Print.TextFormatOutput + Recommended.Editions_Proto3.ProtobufInput.RepeatedUnknownFields_Drop.TextFormatOutput + Recommended.Editions_Proto3.ProtobufInput.RepeatedUnknownFields_Print.TextFormatOutput + Recommended.Editions_Proto3.ProtobufInput.ScalarUnknownFields_Drop.TextFormatOutput + Recommended.Editions_Proto3.ProtobufInput.ScalarUnknownFields_Print.TextFormatOutput \ No newline at end of file diff --git a/src/google/protobuf/editions/BUILD b/src/google/protobuf/editions/BUILD index 96fc9b1385dc1..52c6a402df7f3 100644 --- a/src/google/protobuf/editions/BUILD +++ b/src/google/protobuf/editions/BUILD @@ -1,4 +1,5 @@ load("@rules_python//python:proto.bzl", "py_proto_library") +load("//rust:defs.bzl", "rust_cc_proto_library", "rust_upb_proto_library") load("//bazel:upb_proto_library.bzl", "upb_c_proto_library", "upb_proto_reflection_library") load("@rules_cc//cc:defs.bzl", "cc_proto_library") load("@bazel_skylib//:bzl_library.bzl", "bzl_library") @@ -116,6 +117,20 @@ py_proto_library( deps = [":test_messages_proto2_editions_proto"], ) +rust_cc_proto_library( + name = "test_messages_proto2_editions_rust_cc_proto", + testonly = True, + visibility = ["//conformance:__pkg__"], + deps = [":test_messages_proto2_editions_cc_proto"], +) + +rust_upb_proto_library( + name = "test_messages_proto2_editions_rust_upb_proto", + testonly = True, + visibility = ["//conformance:__pkg__"], + deps = [":test_messages_proto2_editions_proto"], +) + upb_c_proto_library( name = "test_messages_proto2_editions_upb_proto", testonly = 1, @@ -171,6 +186,20 @@ py_proto_library( deps = [":test_messages_proto3_editions_proto"], ) +rust_cc_proto_library( + name = "test_messages_proto3_editions_rust_cc_proto", + testonly = True, + visibility = ["//conformance:__pkg__"], + deps = [":test_messages_proto3_editions_cc_proto"], +) + +rust_upb_proto_library( + name = "test_messages_proto3_editions_rust_upb_proto", + testonly = True, + visibility = ["//conformance:__pkg__"], + deps = [":test_messages_proto3_editions_proto"], +) + upb_c_proto_library( name = "test_messages_proto3_editions_upb_proto", testonly = 1, From 0bcc8ef9f25273f94a7ce2284b0050dbb4674eda Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Thu, 28 Dec 2023 08:39:58 -0800 Subject: [PATCH 120/255] Removed the unused "JSPB (internal)" from conformance the conformance test suite. PiperOrigin-RevId: 594261739 --- conformance/conformance.proto | 24 +++++------------------- conformance/conformance_objc.m | 11 ----------- conformance/conformance_test.cc | 13 ------------- 3 files changed, 5 insertions(+), 43 deletions(-) diff --git a/conformance/conformance.proto b/conformance/conformance.proto index c4aed80ad097c..a3bbc1a488cd6 100644 --- a/conformance/conformance.proto +++ b/conformance/conformance.proto @@ -35,8 +35,8 @@ enum WireFormat { UNSPECIFIED = 0; PROTOBUF = 1; JSON = 2; - JSPB = 3; // Only used inside Google. Opensource testees just skip it. TEXT_FORMAT = 4; + reserved 3; } enum TestCategory { @@ -49,12 +49,10 @@ enum TestCategory { // https://developers.google.com/protocol-buffers/docs/proto3#json_options // for more detail. JSON_IGNORE_UNKNOWN_PARSING_TEST = 3; - // Test jspb wire format. Only used inside Google. Opensource testees just - // skip it. - JSPB_TEST = 4; // Test text format. For cpp, java and python, testees can already deal with // this type. Testees of other languages can simply skip it. TEXT_FORMAT_TEST = 5; + reserved 4; } // The conformance runner will request a list of failures as the first request. @@ -76,8 +74,6 @@ message ConformanceRequest { oneof payload { bytes protobuf_payload = 1; string json_payload = 2; - // Only used inside Google. Opensource testees just skip it. - string jspb_payload = 7; string text_payload = 8; } @@ -94,12 +90,11 @@ message ConformanceRequest { // TestCategory for more information. TestCategory test_category = 5; - // Specify details for how to encode jspb. - JspbEncodingConfig jspb_encoding_options = 6; - // This can be used in json and text format. If true, testee should print // unknown fields instead of ignore. This feature is optional. bool print_unknown_fields = 9; + + reserved 6, 7; } // Represents a single test case's output. @@ -139,19 +134,10 @@ message ConformanceResponse { // wasn't supported, like JSON input/output. string skipped = 5; - // If the input was successfully parsed and the requested output was JSPB, - // serialize to JSPB and set it in this field. JSPB is only used inside - // Google. Opensource testees can just skip it. - string jspb_payload = 7; - // If the input was successfully parsed and the requested output was // TEXT_FORMAT, serialize to TEXT_FORMAT and set it in this field. string text_payload = 8; } -} -// Encoding options for jspb format. -message JspbEncodingConfig { - // Encode the value field of Any as jspb array if true, otherwise binary. - bool use_jspb_array_any_format = 1; + reserved 7; } diff --git a/conformance/conformance_objc.m b/conformance/conformance_objc.m index 8a37b72beccae..17b1f4de2fc5b 100644 --- a/conformance/conformance_objc.m +++ b/conformance/conformance_objc.m @@ -78,11 +78,6 @@ static void Die(NSString *format, ...) { response.skipped = @"ObjC doesn't support parsing JSON"; break; - case ConformanceRequest_Payload_OneOfCase_JspbPayload: - response.skipped = @"ConformanceRequest had a jspb_payload ConformanceRequest.payload;" - " those aren't supposed to happen with opensource."; - break; - case ConformanceRequest_Payload_OneOfCase_TextPayload: response.skipped = @"ObjC doesn't support parsing TextFormat"; break; @@ -108,12 +103,6 @@ static void Die(NSString *format, ...) { response.skipped = @"ObjC doesn't support generating JSON"; break; - case ConformanceWireFormat_Jspb: - response.skipped = - @"ConformanceRequest had a requested_output_format of JSPB WireFormat; that" - " isn't supposed to happen with opensource."; - break; - case ConformanceWireFormat_TextFormat: // ObjC only has partial objc generation, so don't attempt any tests that need // support. diff --git a/conformance/conformance_test.cc b/conformance/conformance_test.cc index ef049c8a539da..9fb32d87ce095 100644 --- a/conformance/conformance_test.cc +++ b/conformance/conformance_test.cc @@ -115,11 +115,6 @@ ConformanceTestSuite::ConformanceRequestSetting::ConformanceRequestSetting( break; } - case conformance::JSPB: { - request_.set_jspb_payload(input); - break; - } - case conformance::TEXT_FORMAT: { request_.set_text_payload(input); break; @@ -230,9 +225,6 @@ ConformanceRequest ConformanceTestSuite::TruncateRequest( case ConformanceRequest::kTextPayload: TruncateDebugPayload(debug_request.mutable_text_payload()); break; - case ConformanceRequest::kJspbPayload: - TruncateDebugPayload(debug_request.mutable_jspb_payload()); - break; default: // Do nothing. break; @@ -253,9 +245,6 @@ ConformanceResponse ConformanceTestSuite::TruncateResponse( case ConformanceResponse::kTextPayload: TruncateDebugPayload(debug_response.mutable_text_payload()); break; - case ConformanceResponse::kJspbPayload: - TruncateDebugPayload(debug_response.mutable_jspb_payload()); - break; default: // Do nothing. break; @@ -429,8 +418,6 @@ std::string ConformanceTestSuite::WireFormatToString(WireFormat wire_format) { return "PROTOBUF"; case conformance::JSON: return "JSON"; - case conformance::JSPB: - return "JSPB"; case conformance::TEXT_FORMAT: return "TEXT_FORMAT"; case conformance::UNSPECIFIED: From e0b3610e7f4b0f50ee0a0dcda9bc8b2a2d9fa7ae Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Thu, 28 Dec 2023 16:52:32 +0000 Subject: [PATCH 121/255] Auto-generate files after cl/594261739 --- .../Conformance.pb.cs | 414 +----------------- 1 file changed, 20 insertions(+), 394 deletions(-) diff --git a/csharp/src/Google.Protobuf.Conformance/Conformance.pb.cs b/csharp/src/Google.Protobuf.Conformance/Conformance.pb.cs index 26b32fb1762b3..167d4aa08222e 100644 --- a/csharp/src/Google.Protobuf.Conformance/Conformance.pb.cs +++ b/csharp/src/Google.Protobuf.Conformance/Conformance.pb.cs @@ -25,35 +25,31 @@ static ConformanceReflection() { byte[] descriptorData = global::System.Convert.FromBase64String( string.Concat( "Ch1jb25mb3JtYW5jZS9jb25mb3JtYW5jZS5wcm90bxILY29uZm9ybWFuY2Ui", - "HQoKRmFpbHVyZVNldBIPCgdmYWlsdXJlGAEgAygJIuMCChJDb25mb3JtYW5j", + "HQoKRmFpbHVyZVNldBIPCgdmYWlsdXJlGAEgAygJIpcCChJDb25mb3JtYW5j", "ZVJlcXVlc3QSGgoQcHJvdG9idWZfcGF5bG9hZBgBIAEoDEgAEhYKDGpzb25f", - "cGF5bG9hZBgCIAEoCUgAEhYKDGpzcGJfcGF5bG9hZBgHIAEoCUgAEhYKDHRl", - "eHRfcGF5bG9hZBgIIAEoCUgAEjgKF3JlcXVlc3RlZF9vdXRwdXRfZm9ybWF0", - "GAMgASgOMhcuY29uZm9ybWFuY2UuV2lyZUZvcm1hdBIUCgxtZXNzYWdlX3R5", - "cGUYBCABKAkSMAoNdGVzdF9jYXRlZ29yeRgFIAEoDjIZLmNvbmZvcm1hbmNl", - "LlRlc3RDYXRlZ29yeRI+ChVqc3BiX2VuY29kaW5nX29wdGlvbnMYBiABKAsy", - "Hy5jb25mb3JtYW5jZS5Kc3BiRW5jb2RpbmdDb25maWcSHAoUcHJpbnRfdW5r", - "bm93bl9maWVsZHMYCSABKAhCCQoHcGF5bG9hZCL6AQoTQ29uZm9ybWFuY2VS", - "ZXNwb25zZRIVCgtwYXJzZV9lcnJvchgBIAEoCUgAEhkKD3NlcmlhbGl6ZV9l", - "cnJvchgGIAEoCUgAEhcKDXRpbWVvdXRfZXJyb3IYCSABKAlIABIXCg1ydW50", - "aW1lX2Vycm9yGAIgASgJSAASGgoQcHJvdG9idWZfcGF5bG9hZBgDIAEoDEgA", - "EhYKDGpzb25fcGF5bG9hZBgEIAEoCUgAEhEKB3NraXBwZWQYBSABKAlIABIW", - "Cgxqc3BiX3BheWxvYWQYByABKAlIABIWCgx0ZXh0X3BheWxvYWQYCCABKAlI", - "AEIICgZyZXN1bHQiNwoSSnNwYkVuY29kaW5nQ29uZmlnEiEKGXVzZV9qc3Bi", - "X2FycmF5X2FueV9mb3JtYXQYASABKAgqUAoKV2lyZUZvcm1hdBIPCgtVTlNQ", - "RUNJRklFRBAAEgwKCFBST1RPQlVGEAESCAoESlNPThACEggKBEpTUEIQAxIP", - "CgtURVhUX0ZPUk1BVBAEKo8BCgxUZXN0Q2F0ZWdvcnkSFAoQVU5TUEVDSUZJ", - "RURfVEVTVBAAEg8KC0JJTkFSWV9URVNUEAESDQoJSlNPTl9URVNUEAISJAog", - "SlNPTl9JR05PUkVfVU5LTk9XTl9QQVJTSU5HX1RFU1QQAxINCglKU1BCX1RF", - "U1QQBBIUChBURVhUX0ZPUk1BVF9URVNUEAVCLwofY29tLmdvb2dsZS5wcm90", - "b2J1Zi5jb25mb3JtYW5jZaICC0NvbmZvcm1hbmNlYgZwcm90bzM=")); + "cGF5bG9hZBgCIAEoCUgAEhYKDHRleHRfcGF5bG9hZBgIIAEoCUgAEjgKF3Jl", + "cXVlc3RlZF9vdXRwdXRfZm9ybWF0GAMgASgOMhcuY29uZm9ybWFuY2UuV2ly", + "ZUZvcm1hdBIUCgxtZXNzYWdlX3R5cGUYBCABKAkSMAoNdGVzdF9jYXRlZ29y", + "eRgFIAEoDjIZLmNvbmZvcm1hbmNlLlRlc3RDYXRlZ29yeRIcChRwcmludF91", + "bmtub3duX2ZpZWxkcxgJIAEoCEIJCgdwYXlsb2FkSgQIBhAHSgQIBxAIIugB", + "ChNDb25mb3JtYW5jZVJlc3BvbnNlEhUKC3BhcnNlX2Vycm9yGAEgASgJSAAS", + "GQoPc2VyaWFsaXplX2Vycm9yGAYgASgJSAASFwoNdGltZW91dF9lcnJvchgJ", + "IAEoCUgAEhcKDXJ1bnRpbWVfZXJyb3IYAiABKAlIABIaChBwcm90b2J1Zl9w", + "YXlsb2FkGAMgASgMSAASFgoManNvbl9wYXlsb2FkGAQgASgJSAASEQoHc2tp", + "cHBlZBgFIAEoCUgAEhYKDHRleHRfcGF5bG9hZBgIIAEoCUgAQggKBnJlc3Vs", + "dEoECAcQCCpMCgpXaXJlRm9ybWF0Eg8KC1VOU1BFQ0lGSUVEEAASDAoIUFJP", + "VE9CVUYQARIICgRKU09OEAISDwoLVEVYVF9GT1JNQVQQBCIECAMQAyqGAQoM", + "VGVzdENhdGVnb3J5EhQKEFVOU1BFQ0lGSUVEX1RFU1QQABIPCgtCSU5BUllf", + "VEVTVBABEg0KCUpTT05fVEVTVBACEiQKIEpTT05fSUdOT1JFX1VOS05PV05f", + "UEFSU0lOR19URVNUEAMSFAoQVEVYVF9GT1JNQVRfVEVTVBAFIgQIBBAEQi8K", + "H2NvbS5nb29nbGUucHJvdG9idWYuY29uZm9ybWFuY2WiAgtDb25mb3JtYW5j", + "ZWIGcHJvdG8z")); descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData, new pbr::FileDescriptor[] { }, new pbr::GeneratedClrTypeInfo(new[] {typeof(global::Conformance.WireFormat), typeof(global::Conformance.TestCategory), }, null, new pbr::GeneratedClrTypeInfo[] { new pbr::GeneratedClrTypeInfo(typeof(global::Conformance.FailureSet), global::Conformance.FailureSet.Parser, new[]{ "Failure" }, null, null, null, null), - new pbr::GeneratedClrTypeInfo(typeof(global::Conformance.ConformanceRequest), global::Conformance.ConformanceRequest.Parser, new[]{ "ProtobufPayload", "JsonPayload", "JspbPayload", "TextPayload", "RequestedOutputFormat", "MessageType", "TestCategory", "JspbEncodingOptions", "PrintUnknownFields" }, new[]{ "Payload" }, null, null, null), - new pbr::GeneratedClrTypeInfo(typeof(global::Conformance.ConformanceResponse), global::Conformance.ConformanceResponse.Parser, new[]{ "ParseError", "SerializeError", "TimeoutError", "RuntimeError", "ProtobufPayload", "JsonPayload", "Skipped", "JspbPayload", "TextPayload" }, new[]{ "Result" }, null, null, null), - new pbr::GeneratedClrTypeInfo(typeof(global::Conformance.JspbEncodingConfig), global::Conformance.JspbEncodingConfig.Parser, new[]{ "UseJspbArrayAnyFormat" }, null, null, null, null) + new pbr::GeneratedClrTypeInfo(typeof(global::Conformance.ConformanceRequest), global::Conformance.ConformanceRequest.Parser, new[]{ "ProtobufPayload", "JsonPayload", "TextPayload", "RequestedOutputFormat", "MessageType", "TestCategory", "PrintUnknownFields" }, new[]{ "Payload" }, null, null, null), + new pbr::GeneratedClrTypeInfo(typeof(global::Conformance.ConformanceResponse), global::Conformance.ConformanceResponse.Parser, new[]{ "ParseError", "SerializeError", "TimeoutError", "RuntimeError", "ProtobufPayload", "JsonPayload", "Skipped", "TextPayload" }, new[]{ "Result" }, null, null, null) })); } #endregion @@ -64,10 +60,6 @@ public enum WireFormat { [pbr::OriginalName("UNSPECIFIED")] Unspecified = 0, [pbr::OriginalName("PROTOBUF")] Protobuf = 1, [pbr::OriginalName("JSON")] Json = 2, - /// - /// Only used inside Google. Opensource testees just skip it. - /// - [pbr::OriginalName("JSPB")] Jspb = 3, [pbr::OriginalName("TEXT_FORMAT")] TextFormat = 4, } @@ -90,11 +82,6 @@ public enum TestCategory { /// [pbr::OriginalName("JSON_IGNORE_UNKNOWN_PARSING_TEST")] JsonIgnoreUnknownParsingTest = 3, /// - /// Test jspb wire format. Only used inside Google. Opensource testees just - /// skip it. - /// - [pbr::OriginalName("JSPB_TEST")] JspbTest = 4, - /// /// Test text format. For cpp, java and python, testees can already deal with /// this type. Testees of other languages can simply skip it. /// @@ -333,7 +320,6 @@ public ConformanceRequest(ConformanceRequest other) : this() { requestedOutputFormat_ = other.requestedOutputFormat_; messageType_ = other.messageType_; testCategory_ = other.testCategory_; - jspbEncodingOptions_ = other.jspbEncodingOptions_ != null ? other.jspbEncodingOptions_.Clone() : null; printUnknownFields_ = other.printUnknownFields_; switch (other.PayloadCase) { case PayloadOneofCase.ProtobufPayload: @@ -342,9 +328,6 @@ public ConformanceRequest(ConformanceRequest other) : this() { case PayloadOneofCase.JsonPayload: JsonPayload = other.JsonPayload; break; - case PayloadOneofCase.JspbPayload: - JspbPayload = other.JspbPayload; - break; case PayloadOneofCase.TextPayload: TextPayload = other.TextPayload; break; @@ -411,35 +394,6 @@ public void ClearJsonPayload() { } } - /// Field number for the "jspb_payload" field. - public const int JspbPayloadFieldNumber = 7; - /// - /// Only used inside Google. Opensource testees just skip it. - /// - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public string JspbPayload { - get { return HasJspbPayload ? (string) payload_ : ""; } - set { - payload_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); - payloadCase_ = PayloadOneofCase.JspbPayload; - } - } - /// Gets whether the "jspb_payload" field is set - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public bool HasJspbPayload { - get { return payloadCase_ == PayloadOneofCase.JspbPayload; } - } - /// Clears the value of the oneof if it's currently set to "jspb_payload" - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public void ClearJspbPayload() { - if (HasJspbPayload) { - ClearPayload(); - } - } - /// Field number for the "text_payload" field. public const int TextPayloadFieldNumber = 8; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -515,21 +469,6 @@ public string MessageType { } } - /// Field number for the "jspb_encoding_options" field. - public const int JspbEncodingOptionsFieldNumber = 6; - private global::Conformance.JspbEncodingConfig jspbEncodingOptions_; - /// - /// Specify details for how to encode jspb. - /// - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public global::Conformance.JspbEncodingConfig JspbEncodingOptions { - get { return jspbEncodingOptions_; } - set { - jspbEncodingOptions_ = value; - } - } - /// Field number for the "print_unknown_fields" field. public const int PrintUnknownFieldsFieldNumber = 9; private bool printUnknownFields_; @@ -552,7 +491,6 @@ public enum PayloadOneofCase { None = 0, ProtobufPayload = 1, JsonPayload = 2, - JspbPayload = 7, TextPayload = 8, } private PayloadOneofCase payloadCase_ = PayloadOneofCase.None; @@ -586,12 +524,10 @@ public bool Equals(ConformanceRequest other) { } if (ProtobufPayload != other.ProtobufPayload) return false; if (JsonPayload != other.JsonPayload) return false; - if (JspbPayload != other.JspbPayload) return false; if (TextPayload != other.TextPayload) return false; if (RequestedOutputFormat != other.RequestedOutputFormat) return false; if (MessageType != other.MessageType) return false; if (TestCategory != other.TestCategory) return false; - if (!object.Equals(JspbEncodingOptions, other.JspbEncodingOptions)) return false; if (PrintUnknownFields != other.PrintUnknownFields) return false; if (PayloadCase != other.PayloadCase) return false; return Equals(_unknownFields, other._unknownFields); @@ -603,12 +539,10 @@ public override int GetHashCode() { int hash = 1; if (HasProtobufPayload) hash ^= ProtobufPayload.GetHashCode(); if (HasJsonPayload) hash ^= JsonPayload.GetHashCode(); - if (HasJspbPayload) hash ^= JspbPayload.GetHashCode(); if (HasTextPayload) hash ^= TextPayload.GetHashCode(); if (RequestedOutputFormat != global::Conformance.WireFormat.Unspecified) hash ^= RequestedOutputFormat.GetHashCode(); if (MessageType.Length != 0) hash ^= MessageType.GetHashCode(); if (TestCategory != global::Conformance.TestCategory.UnspecifiedTest) hash ^= TestCategory.GetHashCode(); - if (jspbEncodingOptions_ != null) hash ^= JspbEncodingOptions.GetHashCode(); if (PrintUnknownFields != false) hash ^= PrintUnknownFields.GetHashCode(); hash ^= (int) payloadCase_; if (_unknownFields != null) { @@ -649,14 +583,6 @@ public void WriteTo(pb::CodedOutputStream output) { output.WriteRawTag(40); output.WriteEnum((int) TestCategory); } - if (jspbEncodingOptions_ != null) { - output.WriteRawTag(50); - output.WriteMessage(JspbEncodingOptions); - } - if (HasJspbPayload) { - output.WriteRawTag(58); - output.WriteString(JspbPayload); - } if (HasTextPayload) { output.WriteRawTag(66); output.WriteString(TextPayload); @@ -695,14 +621,6 @@ public void WriteTo(pb::CodedOutputStream output) { output.WriteRawTag(40); output.WriteEnum((int) TestCategory); } - if (jspbEncodingOptions_ != null) { - output.WriteRawTag(50); - output.WriteMessage(JspbEncodingOptions); - } - if (HasJspbPayload) { - output.WriteRawTag(58); - output.WriteString(JspbPayload); - } if (HasTextPayload) { output.WriteRawTag(66); output.WriteString(TextPayload); @@ -727,9 +645,6 @@ public int CalculateSize() { if (HasJsonPayload) { size += 1 + pb::CodedOutputStream.ComputeStringSize(JsonPayload); } - if (HasJspbPayload) { - size += 1 + pb::CodedOutputStream.ComputeStringSize(JspbPayload); - } if (HasTextPayload) { size += 1 + pb::CodedOutputStream.ComputeStringSize(TextPayload); } @@ -742,9 +657,6 @@ public int CalculateSize() { if (TestCategory != global::Conformance.TestCategory.UnspecifiedTest) { size += 1 + pb::CodedOutputStream.ComputeEnumSize((int) TestCategory); } - if (jspbEncodingOptions_ != null) { - size += 1 + pb::CodedOutputStream.ComputeMessageSize(JspbEncodingOptions); - } if (PrintUnknownFields != false) { size += 1 + 1; } @@ -769,12 +681,6 @@ public void MergeFrom(ConformanceRequest other) { if (other.TestCategory != global::Conformance.TestCategory.UnspecifiedTest) { TestCategory = other.TestCategory; } - if (other.jspbEncodingOptions_ != null) { - if (jspbEncodingOptions_ == null) { - JspbEncodingOptions = new global::Conformance.JspbEncodingConfig(); - } - JspbEncodingOptions.MergeFrom(other.JspbEncodingOptions); - } if (other.PrintUnknownFields != false) { PrintUnknownFields = other.PrintUnknownFields; } @@ -785,9 +691,6 @@ public void MergeFrom(ConformanceRequest other) { case PayloadOneofCase.JsonPayload: JsonPayload = other.JsonPayload; break; - case PayloadOneofCase.JspbPayload: - JspbPayload = other.JspbPayload; - break; case PayloadOneofCase.TextPayload: TextPayload = other.TextPayload; break; @@ -828,17 +731,6 @@ public void MergeFrom(pb::CodedInputStream input) { TestCategory = (global::Conformance.TestCategory) input.ReadEnum(); break; } - case 50: { - if (jspbEncodingOptions_ == null) { - JspbEncodingOptions = new global::Conformance.JspbEncodingConfig(); - } - input.ReadMessage(JspbEncodingOptions); - break; - } - case 58: { - JspbPayload = input.ReadString(); - break; - } case 66: { TextPayload = input.ReadString(); break; @@ -882,17 +774,6 @@ public void MergeFrom(pb::CodedInputStream input) { TestCategory = (global::Conformance.TestCategory) input.ReadEnum(); break; } - case 50: { - if (jspbEncodingOptions_ == null) { - JspbEncodingOptions = new global::Conformance.JspbEncodingConfig(); - } - input.ReadMessage(JspbEncodingOptions); - break; - } - case 58: { - JspbPayload = input.ReadString(); - break; - } case 66: { TextPayload = input.ReadString(); break; @@ -968,9 +849,6 @@ public ConformanceResponse(ConformanceResponse other) : this() { case ResultOneofCase.Skipped: Skipped = other.Skipped; break; - case ResultOneofCase.JspbPayload: - JspbPayload = other.JspbPayload; - break; case ResultOneofCase.TextPayload: TextPayload = other.TextPayload; break; @@ -1201,37 +1079,6 @@ public void ClearSkipped() { } } - /// Field number for the "jspb_payload" field. - public const int JspbPayloadFieldNumber = 7; - /// - /// If the input was successfully parsed and the requested output was JSPB, - /// serialize to JSPB and set it in this field. JSPB is only used inside - /// Google. Opensource testees can just skip it. - /// - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public string JspbPayload { - get { return HasJspbPayload ? (string) result_ : ""; } - set { - result_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); - resultCase_ = ResultOneofCase.JspbPayload; - } - } - /// Gets whether the "jspb_payload" field is set - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public bool HasJspbPayload { - get { return resultCase_ == ResultOneofCase.JspbPayload; } - } - /// Clears the value of the oneof if it's currently set to "jspb_payload" - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public void ClearJspbPayload() { - if (HasJspbPayload) { - ClearResult(); - } - } - /// Field number for the "text_payload" field. public const int TextPayloadFieldNumber = 8; /// @@ -1273,7 +1120,6 @@ public enum ResultOneofCase { ProtobufPayload = 3, JsonPayload = 4, Skipped = 5, - JspbPayload = 7, TextPayload = 8, } private ResultOneofCase resultCase_ = ResultOneofCase.None; @@ -1312,7 +1158,6 @@ public bool Equals(ConformanceResponse other) { if (ProtobufPayload != other.ProtobufPayload) return false; if (JsonPayload != other.JsonPayload) return false; if (Skipped != other.Skipped) return false; - if (JspbPayload != other.JspbPayload) return false; if (TextPayload != other.TextPayload) return false; if (ResultCase != other.ResultCase) return false; return Equals(_unknownFields, other._unknownFields); @@ -1329,7 +1174,6 @@ public override int GetHashCode() { if (HasProtobufPayload) hash ^= ProtobufPayload.GetHashCode(); if (HasJsonPayload) hash ^= JsonPayload.GetHashCode(); if (HasSkipped) hash ^= Skipped.GetHashCode(); - if (HasJspbPayload) hash ^= JspbPayload.GetHashCode(); if (HasTextPayload) hash ^= TextPayload.GetHashCode(); hash ^= (int) resultCase_; if (_unknownFields != null) { @@ -1374,10 +1218,6 @@ public void WriteTo(pb::CodedOutputStream output) { output.WriteRawTag(50); output.WriteString(SerializeError); } - if (HasJspbPayload) { - output.WriteRawTag(58); - output.WriteString(JspbPayload); - } if (HasTextPayload) { output.WriteRawTag(66); output.WriteString(TextPayload); @@ -1420,10 +1260,6 @@ public void WriteTo(pb::CodedOutputStream output) { output.WriteRawTag(50); output.WriteString(SerializeError); } - if (HasJspbPayload) { - output.WriteRawTag(58); - output.WriteString(JspbPayload); - } if (HasTextPayload) { output.WriteRawTag(66); output.WriteString(TextPayload); @@ -1463,9 +1299,6 @@ public int CalculateSize() { if (HasSkipped) { size += 1 + pb::CodedOutputStream.ComputeStringSize(Skipped); } - if (HasJspbPayload) { - size += 1 + pb::CodedOutputStream.ComputeStringSize(JspbPayload); - } if (HasTextPayload) { size += 1 + pb::CodedOutputStream.ComputeStringSize(TextPayload); } @@ -1503,9 +1336,6 @@ public void MergeFrom(ConformanceResponse other) { case ResultOneofCase.Skipped: Skipped = other.Skipped; break; - case ResultOneofCase.JspbPayload: - JspbPayload = other.JspbPayload; - break; case ResultOneofCase.TextPayload: TextPayload = other.TextPayload; break; @@ -1550,10 +1380,6 @@ public void MergeFrom(pb::CodedInputStream input) { SerializeError = input.ReadString(); break; } - case 58: { - JspbPayload = input.ReadString(); - break; - } case 66: { TextPayload = input.ReadString(); break; @@ -1601,10 +1427,6 @@ public void MergeFrom(pb::CodedInputStream input) { SerializeError = input.ReadString(); break; } - case 58: { - JspbPayload = input.ReadString(); - break; - } case 66: { TextPayload = input.ReadString(); break; @@ -1620,202 +1442,6 @@ public void MergeFrom(pb::CodedInputStream input) { } - /// - /// Encoding options for jspb format. - /// - [global::System.Diagnostics.DebuggerDisplayAttribute("{ToString(),nq}")] - public sealed partial class JspbEncodingConfig : pb::IMessage - #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE - , pb::IBufferMessage - #endif - { - private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new JspbEncodingConfig()); - private pb::UnknownFieldSet _unknownFields; - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public static pb::MessageParser Parser { get { return _parser; } } - - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public static pbr::MessageDescriptor Descriptor { - get { return global::Conformance.ConformanceReflection.Descriptor.MessageTypes[3]; } - } - - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - pbr::MessageDescriptor pb::IMessage.Descriptor { - get { return Descriptor; } - } - - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public JspbEncodingConfig() { - OnConstruction(); - } - - partial void OnConstruction(); - - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public JspbEncodingConfig(JspbEncodingConfig other) : this() { - useJspbArrayAnyFormat_ = other.useJspbArrayAnyFormat_; - _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields); - } - - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public JspbEncodingConfig Clone() { - return new JspbEncodingConfig(this); - } - - /// Field number for the "use_jspb_array_any_format" field. - public const int UseJspbArrayAnyFormatFieldNumber = 1; - private bool useJspbArrayAnyFormat_; - /// - /// Encode the value field of Any as jspb array if true, otherwise binary. - /// - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public bool UseJspbArrayAnyFormat { - get { return useJspbArrayAnyFormat_; } - set { - useJspbArrayAnyFormat_ = value; - } - } - - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public override bool Equals(object other) { - return Equals(other as JspbEncodingConfig); - } - - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public bool Equals(JspbEncodingConfig other) { - if (ReferenceEquals(other, null)) { - return false; - } - if (ReferenceEquals(other, this)) { - return true; - } - if (UseJspbArrayAnyFormat != other.UseJspbArrayAnyFormat) return false; - return Equals(_unknownFields, other._unknownFields); - } - - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public override int GetHashCode() { - int hash = 1; - if (UseJspbArrayAnyFormat != false) hash ^= UseJspbArrayAnyFormat.GetHashCode(); - if (_unknownFields != null) { - hash ^= _unknownFields.GetHashCode(); - } - return hash; - } - - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public override string ToString() { - return pb::JsonFormatter.ToDiagnosticString(this); - } - - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public void WriteTo(pb::CodedOutputStream output) { - #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE - output.WriteRawMessage(this); - #else - if (UseJspbArrayAnyFormat != false) { - output.WriteRawTag(8); - output.WriteBool(UseJspbArrayAnyFormat); - } - if (_unknownFields != null) { - _unknownFields.WriteTo(output); - } - #endif - } - - #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) { - if (UseJspbArrayAnyFormat != false) { - output.WriteRawTag(8); - output.WriteBool(UseJspbArrayAnyFormat); - } - if (_unknownFields != null) { - _unknownFields.WriteTo(ref output); - } - } - #endif - - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public int CalculateSize() { - int size = 0; - if (UseJspbArrayAnyFormat != false) { - size += 1 + 1; - } - if (_unknownFields != null) { - size += _unknownFields.CalculateSize(); - } - return size; - } - - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public void MergeFrom(JspbEncodingConfig other) { - if (other == null) { - return; - } - if (other.UseJspbArrayAnyFormat != false) { - UseJspbArrayAnyFormat = other.UseJspbArrayAnyFormat; - } - _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); - } - - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - public void MergeFrom(pb::CodedInputStream input) { - #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE - input.ReadRawMessage(this); - #else - uint tag; - while ((tag = input.ReadTag()) != 0) { - switch(tag) { - default: - _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); - break; - case 8: { - UseJspbArrayAnyFormat = input.ReadBool(); - break; - } - } - } - #endif - } - - #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] - void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) { - uint tag; - while ((tag = input.ReadTag()) != 0) { - switch(tag) { - default: - _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); - break; - case 8: { - UseJspbArrayAnyFormat = input.ReadBool(); - break; - } - } - } - } - #endif - - } - #endregion } From b82bb29340b3279c6700ef3b3616ae663dc670a6 Mon Sep 17 00:00:00 2001 From: Dmitri Gribenko Date: Thu, 28 Dec 2023 09:11:40 -0800 Subject: [PATCH 122/255] Internal Code Change PiperOrigin-RevId: 594266511 --- src/google/protobuf/json/internal/parser_traits.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/google/protobuf/json/internal/parser_traits.h b/src/google/protobuf/json/internal/parser_traits.h index 22e6efe2e85bf..9d2745b1a2dca 100644 --- a/src/google/protobuf/json/internal/parser_traits.h +++ b/src/google/protobuf/json/internal/parser_traits.h @@ -173,7 +173,7 @@ struct ParseProto2Descriptor : Proto2Descriptor { } } - static void SetInt32(Field f, Msg& msg, int32 x) { + static void SetInt32(Field f, Msg& msg, int32_t x) { RecordAsSeen(f, msg); if (f->is_repeated()) { msg.msg_->GetReflection()->AddInt32(msg.msg_, f, x); @@ -182,7 +182,7 @@ struct ParseProto2Descriptor : Proto2Descriptor { } } - static void SetUInt32(Field f, Msg& msg, uint32 x) { + static void SetUInt32(Field f, Msg& msg, uint32_t x) { RecordAsSeen(f, msg); if (f->is_repeated()) { msg.msg_->GetReflection()->AddUInt32(msg.msg_, f, x); From 0eac807f3b40357fe09f8d41989a70b873fd4702 Mon Sep 17 00:00:00 2001 From: Eric Salo Date: Thu, 28 Dec 2023 10:38:18 -0800 Subject: [PATCH 123/255] upb: delete the aliases for base:internal and mini_descriptor:internal PiperOrigin-RevId: 594280505 --- benchmarks/BUILD | 2 +- upb/BUILD | 24 ++++++------------------ upb/hash/BUILD | 2 +- upb/message/BUILD | 6 +++--- upb/mini_descriptor/BUILD | 4 ++-- upb/reflection/BUILD | 4 ++-- 6 files changed, 15 insertions(+), 27 deletions(-) diff --git a/benchmarks/BUILD b/benchmarks/BUILD index 108eab493f8a3..3559926d51bd6 100644 --- a/benchmarks/BUILD +++ b/benchmarks/BUILD @@ -78,10 +78,10 @@ cc_test( "//:protobuf", "@com_google_googletest//:gtest_main", "//upb:base", - "//upb:base_internal", "//upb:descriptor_upb_proto", "//upb:mem", "//upb:reflection", + "//upb/base:internal", "@com_github_google_benchmark//:benchmark_main", "@com_google_absl//absl/container:flat_hash_set", ], diff --git a/upb/BUILD b/upb/BUILD index ff7ff72c49204..e6cdff77dd990 100644 --- a/upb/BUILD +++ b/upb/BUILD @@ -137,12 +137,6 @@ alias( visibility = ["//visibility:public"], ) -alias( - name = "base_internal", - actual = "//upb/base:internal", - visibility = ["//visibility:public"], -) - alias( name = "collections", actual = "//upb/collections", @@ -258,12 +252,6 @@ alias( visibility = ["//visibility:public"], ) -alias( - name = "mini_descriptor_internal", - actual = "//upb/mini_descriptor:internal", - visibility = ["//upb:__subpackages__"], -) - alias( name = "mini_table", actual = "//upb/mini_table", @@ -358,7 +346,6 @@ upb_amalgamation( ], libs = [ ":base", - ":base_internal", ":descriptor_upb_minitable_proto", ":descriptor_upb_proto", ":eps_copy_input_stream", @@ -374,7 +361,6 @@ upb_amalgamation( ":message_types", ":message_value", ":mini_descriptor", - ":mini_descriptor_internal", ":mini_table", ":mini_table_compat", ":port", @@ -382,7 +368,9 @@ upb_amalgamation( ":reflection_internal", ":wire", ":wire_reader", + "//upb/base:internal", "//upb/mem:internal", + "//upb/mini_descriptor:internal", "//upb/mini_table:internal", ], strip_import_prefix = ["src"], @@ -404,7 +392,6 @@ upb_amalgamation( ], libs = [ ":base", - ":base_internal", ":descriptor_upb_minitable_proto", ":descriptor_upb_proto_reflection", ":descriptor_upb_proto", @@ -422,7 +409,6 @@ upb_amalgamation( ":message_types", ":message_value", ":mini_descriptor", - ":mini_descriptor_internal", ":mini_table", ":mini_table_compat", ":port", @@ -430,7 +416,9 @@ upb_amalgamation( ":reflection_internal", ":wire", ":wire_reader", + "//upb/base:internal", "//upb/mem:internal", + "//upb/mini_descriptor:internal", "//upb/mini_table:internal", ], prefix = "php-", @@ -454,7 +442,6 @@ upb_amalgamation( ], libs = [ ":base", - ":base_internal", ":descriptor_upb_minitable_proto", ":descriptor_upb_proto", ":eps_copy_input_stream", @@ -471,7 +458,6 @@ upb_amalgamation( ":message_types", ":message_value", ":mini_descriptor", - ":mini_descriptor_internal", ":mini_table", ":mini_table_compat", ":port", @@ -479,7 +465,9 @@ upb_amalgamation( ":reflection_internal", ":wire", ":wire_reader", + "//upb/base:internal", "//upb/mem:internal", + "//upb/mini_descriptor:internal", "//upb/mini_table:internal", ], prefix = "ruby-", diff --git a/upb/hash/BUILD b/upb/hash/BUILD index c7e4ea6b42259..7ef3bd7e0d7af 100644 --- a/upb/hash/BUILD +++ b/upb/hash/BUILD @@ -21,9 +21,9 @@ cc_library( visibility = ["//visibility:public"], deps = [ "//upb:base", - "//upb:base_internal", "//upb:mem", "//upb:port", + "//upb/base:internal", ], ) diff --git a/upb/message/BUILD b/upb/message/BUILD index 298acd918573d..76eb94c3debb3 100644 --- a/upb/message/BUILD +++ b/upb/message/BUILD @@ -112,11 +112,11 @@ cc_library( ":types", ":value", "//upb:base", - "//upb:base_internal", "//upb:hash", "//upb:mem", "//upb:mini_table", "//upb:port", + "//upb/base:internal", "//upb/mini_table:internal", ], ) @@ -232,10 +232,10 @@ cc_test( "//upb:base", "//upb:mem", "//upb:mini_descriptor", - "//upb:mini_descriptor_internal", "//upb:mini_table", "//upb:port", "//upb:wire", + "//upb/mini_descriptor:internal", "//upb/test:test_messages_proto2_upb_minitable", "//upb/test:test_messages_proto2_upb_proto", "//upb/test:test_messages_proto3_upb_minitable", @@ -302,9 +302,9 @@ cc_test( "//upb:base", "//upb:mem", "//upb:mini_descriptor", - "//upb:mini_descriptor_internal", "//upb:mini_table", "//upb:wire", + "//upb/mini_descriptor:internal", "//upb/test:test_messages_proto2_upb_proto", "//upb/test:test_messages_proto3_upb_proto", "//upb/test:test_proto_upb_minitable", diff --git a/upb/mini_descriptor/BUILD b/upb/mini_descriptor/BUILD index c4247eb01840b..1857b9c338e3f 100644 --- a/upb/mini_descriptor/BUILD +++ b/upb/mini_descriptor/BUILD @@ -21,10 +21,10 @@ cc_library( deps = [ ":internal", "//upb:base", - "//upb:base_internal", "//upb:mem", "//upb:mini_table", "//upb:port", + "//upb/base:internal", "//upb/mini_table:internal", ], ) @@ -47,8 +47,8 @@ cc_library( visibility = ["//visibility:public"], deps = [ "//upb:base", - "//upb:base_internal", "//upb:port", + "//upb/base:internal", ], ) diff --git a/upb/reflection/BUILD b/upb/reflection/BUILD index 72562999b6334..5854704bf6d09 100644 --- a/upb/reflection/BUILD +++ b/upb/reflection/BUILD @@ -133,7 +133,6 @@ bootstrap_cc_library( visibility = ["//visibility:public"], deps = [ "//upb:base", - "//upb:base_internal", "//upb:hash", "//upb:mem", "//upb:message", @@ -141,10 +140,11 @@ bootstrap_cc_library( "//upb:message_copy", "//upb:message_value", "//upb:mini_descriptor", - "//upb:mini_descriptor_internal", "//upb:mini_table", "//upb:port", "//upb:wire", + "//upb/base:internal", + "//upb/mini_descriptor:internal", ], ) From c2c01b6166da86feb66a20f612494109d3762a3b Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Thu, 28 Dec 2023 18:51:30 +0000 Subject: [PATCH 124/255] Auto-generate files after cl/594280505 --- php/ext/google/protobuf/php-upb.c | 2434 ++++++++++++------------- php/ext/google/protobuf/php-upb.h | 166 +- ruby/ext/google/protobuf_c/ruby-upb.c | 2434 ++++++++++++------------- ruby/ext/google/protobuf_c/ruby-upb.h | 166 +- 4 files changed, 2600 insertions(+), 2600 deletions(-) diff --git a/php/ext/google/protobuf/php-upb.c b/php/ext/google/protobuf/php-upb.c index 2104c27271a77..fb226ca3c7a08 100644 --- a/php/ext/google/protobuf/php-upb.c +++ b/php/ext/google/protobuf/php-upb.c @@ -8026,1221 +8026,891 @@ bool upb_MiniTable_Link(upb_MiniTable* mt, const upb_MiniTable** sub_tables, } -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, -}; - - -#include #include #include +#include // Must be last. -typedef struct { - uint64_t present_values_mask; - uint32_t last_written_value; -} upb_MtDataEncoderInternal_EnumState; - -typedef struct { - uint64_t msg_modifiers; - uint32_t last_field_num; - enum { - kUpb_OneofState_NotStarted, - kUpb_OneofState_StartedOneof, - kUpb_OneofState_EmittedOneofField, - } oneof_state; -} upb_MtDataEncoderInternal_MsgState; +#define EXTREG_KEY_SIZE (sizeof(upb_MiniTable*) + sizeof(uint32_t)) -typedef struct { - char* buf_start; // Only for checking kUpb_MtDataEncoder_MinSize. - union { - upb_MtDataEncoderInternal_EnumState enum_state; - upb_MtDataEncoderInternal_MsgState msg_state; - } state; -} upb_MtDataEncoderInternal; +struct upb_ExtensionRegistry { + upb_Arena* arena; + upb_strtable exts; // Key is upb_MiniTable* concatenated with fieldnum. +}; -static upb_MtDataEncoderInternal* upb_MtDataEncoder_GetInternal( - upb_MtDataEncoder* e, char* buf_start) { - UPB_ASSERT(sizeof(upb_MtDataEncoderInternal) <= sizeof(e->internal)); - upb_MtDataEncoderInternal* ret = (upb_MtDataEncoderInternal*)e->internal; - ret->buf_start = buf_start; - return ret; +static void extreg_key(char* buf, const upb_MiniTable* l, uint32_t fieldnum) { + memcpy(buf, &l, sizeof(l)); + memcpy(buf + sizeof(l), &fieldnum, sizeof(fieldnum)); } -static char* upb_MtDataEncoder_PutRaw(upb_MtDataEncoder* e, char* ptr, - char ch) { - upb_MtDataEncoderInternal* in = (upb_MtDataEncoderInternal*)e->internal; - UPB_ASSERT(ptr - in->buf_start < kUpb_MtDataEncoder_MinSize); - if (ptr == e->end) return NULL; - *ptr++ = ch; - return ptr; +upb_ExtensionRegistry* upb_ExtensionRegistry_New(upb_Arena* arena) { + upb_ExtensionRegistry* r = upb_Arena_Malloc(arena, sizeof(*r)); + if (!r) return NULL; + r->arena = arena; + if (!upb_strtable_init(&r->exts, 8, arena)) return NULL; + return r; } -static char* upb_MtDataEncoder_Put(upb_MtDataEncoder* e, char* ptr, char ch) { - return upb_MtDataEncoder_PutRaw(e, ptr, _upb_ToBase92(ch)); +UPB_API bool upb_ExtensionRegistry_Add(upb_ExtensionRegistry* r, + const upb_MiniTableExtension* e) { + char buf[EXTREG_KEY_SIZE]; + extreg_key(buf, e->UPB_PRIVATE(extendee), upb_MiniTableExtension_Number(e)); + if (upb_strtable_lookup2(&r->exts, buf, EXTREG_KEY_SIZE, NULL)) return false; + return upb_strtable_insert(&r->exts, buf, EXTREG_KEY_SIZE, + upb_value_constptr(e), r->arena); } -static char* upb_MtDataEncoder_PutBase92Varint(upb_MtDataEncoder* e, char* ptr, - uint32_t val, int min, int max) { - int shift = upb_Log2Ceiling(_upb_FromBase92(max) - _upb_FromBase92(min) + 1); - UPB_ASSERT(shift <= 6); - uint32_t mask = (1 << shift) - 1; - do { - uint32_t bits = val & mask; - ptr = upb_MtDataEncoder_Put(e, ptr, bits + _upb_FromBase92(min)); - if (!ptr) return NULL; - val >>= shift; - } while (val); - return ptr; +bool upb_ExtensionRegistry_AddArray(upb_ExtensionRegistry* r, + const upb_MiniTableExtension** e, + size_t count) { + const upb_MiniTableExtension** start = e; + const upb_MiniTableExtension** end = UPB_PTRADD(e, count); + for (; e < end; e++) { + if (!upb_ExtensionRegistry_Add(r, *e)) goto failure; + } + return true; + +failure: + // Back out the entries previously added. + for (end = e, e = start; e < end; e++) { + const upb_MiniTableExtension* ext = *e; + char buf[EXTREG_KEY_SIZE]; + extreg_key(buf, ext->UPB_PRIVATE(extendee), + upb_MiniTableExtension_Number(ext)); + upb_strtable_remove2(&r->exts, buf, EXTREG_KEY_SIZE, NULL); + } + return false; } -char* upb_MtDataEncoder_PutModifier(upb_MtDataEncoder* e, char* ptr, - uint64_t mod) { - if (mod) { - ptr = upb_MtDataEncoder_PutBase92Varint(e, ptr, mod, - kUpb_EncodedValue_MinModifier, - kUpb_EncodedValue_MaxModifier); +const upb_MiniTableExtension* upb_ExtensionRegistry_Lookup( + const upb_ExtensionRegistry* r, const upb_MiniTable* t, uint32_t num) { + char buf[EXTREG_KEY_SIZE]; + upb_value v; + extreg_key(buf, t, num); + if (upb_strtable_lookup2(&r->exts, buf, EXTREG_KEY_SIZE, &v)) { + return upb_value_getconstptr(v); + } else { + return NULL; } - return ptr; } -char* upb_MtDataEncoder_EncodeExtension(upb_MtDataEncoder* e, char* ptr, - upb_FieldType type, uint32_t field_num, - uint64_t field_mod) { - upb_MtDataEncoderInternal* in = upb_MtDataEncoder_GetInternal(e, ptr); - in->state.msg_state.msg_modifiers = 0; - in->state.msg_state.last_field_num = 0; - in->state.msg_state.oneof_state = kUpb_OneofState_NotStarted; - ptr = upb_MtDataEncoder_PutRaw(e, ptr, kUpb_EncodedVersion_ExtensionV1); - if (!ptr) return NULL; +#include +#include +#include - return upb_MtDataEncoder_PutField(e, ptr, type, field_num, field_mod); -} -char* upb_MtDataEncoder_EncodeMap(upb_MtDataEncoder* e, char* ptr, - upb_FieldType key_type, - upb_FieldType value_type, uint64_t key_mod, - uint64_t value_mod) { - upb_MtDataEncoderInternal* in = upb_MtDataEncoder_GetInternal(e, ptr); - in->state.msg_state.msg_modifiers = 0; - in->state.msg_state.last_field_num = 0; - in->state.msg_state.oneof_state = kUpb_OneofState_NotStarted; +// Must be last. - ptr = upb_MtDataEncoder_PutRaw(e, ptr, kUpb_EncodedVersion_MapV1); - if (!ptr) return NULL; +const upb_MiniTableField* upb_MiniTable_FindFieldByNumber( + const upb_MiniTable* m, uint32_t number) { + const size_t i = ((size_t)number) - 1; // 0 wraps to SIZE_MAX - ptr = upb_MtDataEncoder_PutField(e, ptr, key_type, 1, key_mod); - if (!ptr) return NULL; + // Ideal case: index into dense fields + if (i < m->UPB_PRIVATE(dense_below)) { + UPB_ASSERT(m->UPB_PRIVATE(fields)[i].UPB_PRIVATE(number) == number); + return &m->UPB_PRIVATE(fields)[i]; + } - return upb_MtDataEncoder_PutField(e, ptr, value_type, 2, value_mod); + // Slow case: binary search + int lo = m->UPB_PRIVATE(dense_below); + int hi = m->UPB_PRIVATE(field_count) - 1; + while (lo <= hi) { + int mid = (lo + hi) / 2; + uint32_t num = m->UPB_PRIVATE(fields)[mid].UPB_PRIVATE(number); + if (num < number) { + lo = mid + 1; + continue; + } + if (num > number) { + hi = mid - 1; + continue; + } + return &m->UPB_PRIVATE(fields)[mid]; + } + return NULL; } -char* upb_MtDataEncoder_EncodeMessageSet(upb_MtDataEncoder* e, char* ptr) { - (void)upb_MtDataEncoder_GetInternal(e, ptr); - return upb_MtDataEncoder_PutRaw(e, ptr, kUpb_EncodedVersion_MessageSetV1); +const upb_MiniTableField* upb_MiniTable_GetOneof(const upb_MiniTable* m, + const upb_MiniTableField* f) { + if (UPB_UNLIKELY(!upb_MiniTableField_IsInOneof(f))) { + return NULL; + } + const upb_MiniTableField* ptr = &m->UPB_PRIVATE(fields)[0]; + const upb_MiniTableField* end = + &m->UPB_PRIVATE(fields)[m->UPB_PRIVATE(field_count)]; + for (; ptr < end; ptr++) { + if (ptr->presence == (*f).presence) { + return ptr; + } + } + return NULL; } -char* upb_MtDataEncoder_StartMessage(upb_MtDataEncoder* e, char* ptr, - uint64_t msg_mod) { - upb_MtDataEncoderInternal* in = upb_MtDataEncoder_GetInternal(e, ptr); - in->state.msg_state.msg_modifiers = msg_mod; - in->state.msg_state.last_field_num = 0; - in->state.msg_state.oneof_state = kUpb_OneofState_NotStarted; +bool upb_MiniTable_NextOneofField(const upb_MiniTable* m, + const upb_MiniTableField** f) { + const upb_MiniTableField* ptr = *f; + const upb_MiniTableField* end = + &m->UPB_PRIVATE(fields)[m->UPB_PRIVATE(field_count)]; + while (++ptr < end) { + if (ptr->presence == (*f)->presence) { + *f = ptr; + return true; + } + } + return false; +} - ptr = upb_MtDataEncoder_PutRaw(e, ptr, kUpb_EncodedVersion_MessageV1); - if (!ptr) return NULL; - return upb_MtDataEncoder_PutModifier(e, ptr, msg_mod); -} +#include +#include -static char* _upb_MtDataEncoder_MaybePutFieldSkip(upb_MtDataEncoder* e, - char* ptr, - uint32_t field_num) { - upb_MtDataEncoderInternal* in = (upb_MtDataEncoderInternal*)e->internal; - if (field_num <= in->state.msg_state.last_field_num) return NULL; - if (in->state.msg_state.last_field_num + 1 != field_num) { - // Put skip. - UPB_ASSERT(field_num > in->state.msg_state.last_field_num); - uint32_t skip = field_num - in->state.msg_state.last_field_num; - ptr = upb_MtDataEncoder_PutBase92Varint( - e, ptr, skip, kUpb_EncodedValue_MinSkip, kUpb_EncodedValue_MaxSkip); - if (!ptr) return NULL; - } - in->state.msg_state.last_field_num = field_num; - return ptr; -} -static char* _upb_MtDataEncoder_PutFieldType(upb_MtDataEncoder* e, char* ptr, - upb_FieldType type, - uint64_t field_mod) { - static const char kUpb_TypeToEncoded[] = { - [kUpb_FieldType_Double] = kUpb_EncodedType_Double, - [kUpb_FieldType_Float] = kUpb_EncodedType_Float, - [kUpb_FieldType_Int64] = kUpb_EncodedType_Int64, - [kUpb_FieldType_UInt64] = kUpb_EncodedType_UInt64, - [kUpb_FieldType_Int32] = kUpb_EncodedType_Int32, - [kUpb_FieldType_Fixed64] = kUpb_EncodedType_Fixed64, - [kUpb_FieldType_Fixed32] = kUpb_EncodedType_Fixed32, - [kUpb_FieldType_Bool] = kUpb_EncodedType_Bool, - [kUpb_FieldType_String] = kUpb_EncodedType_String, - [kUpb_FieldType_Group] = kUpb_EncodedType_Group, - [kUpb_FieldType_Message] = kUpb_EncodedType_Message, - [kUpb_FieldType_Bytes] = kUpb_EncodedType_Bytes, - [kUpb_FieldType_UInt32] = kUpb_EncodedType_UInt32, - [kUpb_FieldType_Enum] = kUpb_EncodedType_OpenEnum, - [kUpb_FieldType_SFixed32] = kUpb_EncodedType_SFixed32, - [kUpb_FieldType_SFixed64] = kUpb_EncodedType_SFixed64, - [kUpb_FieldType_SInt32] = kUpb_EncodedType_SInt32, - [kUpb_FieldType_SInt64] = kUpb_EncodedType_SInt64, - }; - - int encoded_type = kUpb_TypeToEncoded[type]; - - if (field_mod & kUpb_FieldModifier_IsClosedEnum) { - UPB_ASSERT(type == kUpb_FieldType_Enum); - encoded_type = kUpb_EncodedType_ClosedEnum; - } +// Must be last. - if (field_mod & kUpb_FieldModifier_IsRepeated) { - // Repeated fields shift the type number up (unlike other modifiers which - // are bit flags). - encoded_type += kUpb_EncodedType_RepeatedBase; - } +// Checks if source and target mini table fields are identical. +// +// If the field is a sub message and sub messages are identical we record +// the association in table. +// +// Hashing the source sub message mini table and it's equivalent in the table +// stops recursing when a cycle is detected and instead just checks if the +// destination table is equal. +static upb_MiniTableEquals_Status upb_deep_check(const upb_MiniTable* src, + const upb_MiniTable* dst, + upb_inttable* table, + upb_Arena** arena) { + if (src->UPB_PRIVATE(field_count) != dst->UPB_PRIVATE(field_count)) + return kUpb_MiniTableEquals_NotEqual; + bool marked_src = false; + for (int i = 0; i < upb_MiniTable_FieldCount(src); i++) { + const upb_MiniTableField* src_field = upb_MiniTable_GetFieldByIndex(src, i); + const upb_MiniTableField* dst_field = upb_MiniTable_FindFieldByNumber( + dst, upb_MiniTableField_Number(src_field)); - return upb_MtDataEncoder_Put(e, ptr, encoded_type); -} + if (upb_MiniTableField_CType(src_field) != + upb_MiniTableField_CType(dst_field)) + return false; + if (src_field->UPB_PRIVATE(mode) != dst_field->UPB_PRIVATE(mode)) + return false; + if (src_field->UPB_PRIVATE(offset) != dst_field->UPB_PRIVATE(offset)) + return false; + if (src_field->presence != dst_field->presence) return false; + if (src_field->UPB_PRIVATE(submsg_index) != + dst_field->UPB_PRIVATE(submsg_index)) + return kUpb_MiniTableEquals_NotEqual; -static char* _upb_MtDataEncoder_MaybePutModifiers(upb_MtDataEncoder* e, - char* ptr, upb_FieldType type, - uint64_t field_mod) { - upb_MtDataEncoderInternal* in = (upb_MtDataEncoderInternal*)e->internal; - uint32_t encoded_modifiers = 0; - if ((field_mod & kUpb_FieldModifier_IsRepeated) && - upb_FieldType_IsPackable(type)) { - bool field_is_packed = field_mod & kUpb_FieldModifier_IsPacked; - bool default_is_packed = in->state.msg_state.msg_modifiers & - kUpb_MessageModifier_DefaultIsPacked; - if (field_is_packed != default_is_packed) { - encoded_modifiers |= kUpb_EncodedFieldModifier_FlipPacked; - } - } + // Go no further if we are only checking for compatibility. + if (!table) continue; - if (type == kUpb_FieldType_String) { - bool field_validates_utf8 = field_mod & kUpb_FieldModifier_ValidateUtf8; - bool message_validates_utf8 = - in->state.msg_state.msg_modifiers & kUpb_MessageModifier_ValidateUtf8; - if (field_validates_utf8 != message_validates_utf8) { - // Old binaries do not recognize the field modifier. We need the failure - // mode to be too lax rather than too strict. Our caller should have - // handled this (see _upb_MessageDef_ValidateUtf8()). - assert(!message_validates_utf8); - encoded_modifiers |= kUpb_EncodedFieldModifier_FlipValidateUtf8; + if (upb_MiniTableField_CType(src_field) == kUpb_CType_Message) { + if (!*arena) { + *arena = upb_Arena_New(); + if (!upb_inttable_init(table, *arena)) { + return kUpb_MiniTableEquals_OutOfMemory; + } + } + if (!marked_src) { + marked_src = true; + upb_value val; + val.val = (uint64_t)dst; + if (!upb_inttable_insert(table, (uintptr_t)src, val, *arena)) { + return kUpb_MiniTableEquals_OutOfMemory; + } + } + const upb_MiniTable* sub_src = + upb_MiniTable_GetSubMessageTable(src, src_field); + const upb_MiniTable* sub_dst = + upb_MiniTable_GetSubMessageTable(dst, dst_field); + if (sub_src != NULL) { + upb_value cmp; + if (upb_inttable_lookup(table, (uintptr_t)sub_src, &cmp)) { + // We already compared this src before. Check if same dst. + if (cmp.val != (uint64_t)sub_dst) { + return kUpb_MiniTableEquals_NotEqual; + } + } else { + // Recurse if not already visited. + upb_MiniTableEquals_Status s = + upb_deep_check(sub_src, sub_dst, table, arena); + if (s != kUpb_MiniTableEquals_Equal) { + return s; + } + } + } } } + return kUpb_MiniTableEquals_Equal; +} - if (field_mod & kUpb_FieldModifier_IsProto3Singular) { - encoded_modifiers |= kUpb_EncodedFieldModifier_IsProto3Singular; - } +bool upb_MiniTable_Compatible(const upb_MiniTable* src, + const upb_MiniTable* dst) { + return upb_deep_check(src, dst, NULL, NULL); +} - if (field_mod & kUpb_FieldModifier_IsRequired) { - encoded_modifiers |= kUpb_EncodedFieldModifier_IsRequired; +upb_MiniTableEquals_Status upb_MiniTable_Equals(const upb_MiniTable* src, + const upb_MiniTable* dst) { + // Arena allocated on demand for hash table. + upb_Arena* arena = NULL; + // Table to keep track of visited mini tables to guard against cycles. + upb_inttable table; + upb_MiniTableEquals_Status status = upb_deep_check(src, dst, &table, &arena); + if (arena) { + upb_Arena_Free(arena); } - - return upb_MtDataEncoder_PutModifier(e, ptr, encoded_modifiers); + return status; } -char* upb_MtDataEncoder_PutField(upb_MtDataEncoder* e, char* ptr, - upb_FieldType type, uint32_t field_num, - uint64_t field_mod) { - upb_MtDataEncoder_GetInternal(e, ptr); - - ptr = _upb_MtDataEncoder_MaybePutFieldSkip(e, ptr, field_num); - if (!ptr) return NULL; - ptr = _upb_MtDataEncoder_PutFieldType(e, ptr, type, field_mod); - if (!ptr) return NULL; - return _upb_MtDataEncoder_MaybePutModifiers(e, ptr, type, field_mod); -} +// Must be last. -char* upb_MtDataEncoder_StartOneof(upb_MtDataEncoder* e, char* ptr) { - upb_MtDataEncoderInternal* in = upb_MtDataEncoder_GetInternal(e, ptr); - if (in->state.msg_state.oneof_state == kUpb_OneofState_NotStarted) { - ptr = upb_MtDataEncoder_Put(e, ptr, _upb_FromBase92(kUpb_EncodedValue_End)); - } else { - ptr = upb_MtDataEncoder_Put( - e, ptr, _upb_FromBase92(kUpb_EncodedValue_OneofSeparator)); - } - in->state.msg_state.oneof_state = kUpb_OneofState_StartedOneof; - return ptr; -} +struct upb_DefPool { + upb_Arena* arena; + upb_strtable syms; // full_name -> packed def ptr + upb_strtable files; // file_name -> (upb_FileDef*) + upb_inttable exts; // (upb_MiniTableExtension*) -> (upb_FieldDef*) + upb_ExtensionRegistry* extreg; + const UPB_DESC(FeatureSetDefaults) * feature_set_defaults; + upb_MiniTablePlatform platform; + void* scratch_data; + size_t scratch_size; + size_t bytes_loaded; +}; -char* upb_MtDataEncoder_PutOneofField(upb_MtDataEncoder* e, char* ptr, - uint32_t field_num) { - upb_MtDataEncoderInternal* in = upb_MtDataEncoder_GetInternal(e, ptr); - if (in->state.msg_state.oneof_state == kUpb_OneofState_EmittedOneofField) { - ptr = upb_MtDataEncoder_Put( - e, ptr, _upb_FromBase92(kUpb_EncodedValue_FieldSeparator)); - if (!ptr) return NULL; - } - ptr = upb_MtDataEncoder_PutBase92Varint(e, ptr, field_num, _upb_ToBase92(0), - _upb_ToBase92(63)); - in->state.msg_state.oneof_state = kUpb_OneofState_EmittedOneofField; - return ptr; +void upb_DefPool_Free(upb_DefPool* s) { + upb_Arena_Free(s->arena); + upb_gfree(s->scratch_data); + upb_gfree(s); } -char* upb_MtDataEncoder_StartEnum(upb_MtDataEncoder* e, char* ptr) { - upb_MtDataEncoderInternal* in = upb_MtDataEncoder_GetInternal(e, ptr); - in->state.enum_state.present_values_mask = 0; - in->state.enum_state.last_written_value = 0; +static const char serialized_defaults[] = UPB_INTERNAL_UPB_EDITION_DEFAULTS; - return upb_MtDataEncoder_PutRaw(e, ptr, kUpb_EncodedVersion_EnumV1); -} +upb_DefPool* upb_DefPool_New(void) { + upb_DefPool* s = upb_gmalloc(sizeof(*s)); + if (!s) return NULL; -static char* upb_MtDataEncoder_FlushDenseEnumMask(upb_MtDataEncoder* e, - char* ptr) { - upb_MtDataEncoderInternal* in = (upb_MtDataEncoderInternal*)e->internal; - ptr = upb_MtDataEncoder_Put(e, ptr, in->state.enum_state.present_values_mask); - in->state.enum_state.present_values_mask = 0; - in->state.enum_state.last_written_value += 5; - return ptr; -} + s->arena = upb_Arena_New(); + s->bytes_loaded = 0; -char* upb_MtDataEncoder_PutEnumValue(upb_MtDataEncoder* e, char* ptr, - uint32_t val) { - // TODO: optimize this encoding. - upb_MtDataEncoderInternal* in = upb_MtDataEncoder_GetInternal(e, ptr); - UPB_ASSERT(val >= in->state.enum_state.last_written_value); - uint32_t delta = val - in->state.enum_state.last_written_value; - if (delta >= 5 && in->state.enum_state.present_values_mask) { - ptr = upb_MtDataEncoder_FlushDenseEnumMask(e, ptr); - if (!ptr) { - return NULL; - } - delta -= 5; - } + s->scratch_size = 240; + s->scratch_data = upb_gmalloc(s->scratch_size); + if (!s->scratch_data) goto err; - if (delta >= 5) { - ptr = upb_MtDataEncoder_PutBase92Varint( - e, ptr, delta, kUpb_EncodedValue_MinSkip, kUpb_EncodedValue_MaxSkip); - in->state.enum_state.last_written_value += delta; - delta = 0; - } + if (!upb_strtable_init(&s->syms, 32, s->arena)) goto err; + if (!upb_strtable_init(&s->files, 4, s->arena)) goto err; + if (!upb_inttable_init(&s->exts, s->arena)) goto err; - UPB_ASSERT((in->state.enum_state.present_values_mask >> delta) == 0); - in->state.enum_state.present_values_mask |= 1ULL << delta; - return ptr; -} + s->extreg = upb_ExtensionRegistry_New(s->arena); + if (!s->extreg) goto err; -char* upb_MtDataEncoder_EndEnum(upb_MtDataEncoder* e, char* ptr) { - upb_MtDataEncoderInternal* in = upb_MtDataEncoder_GetInternal(e, ptr); - if (!in->state.enum_state.present_values_mask) return ptr; - return upb_MtDataEncoder_FlushDenseEnumMask(e, ptr); -} + s->platform = kUpb_MiniTablePlatform_Native; + upb_Status status; + if (!upb_DefPool_SetFeatureSetDefaults( + s, serialized_defaults, sizeof(serialized_defaults) - 1, &status)) { + goto err; + } -#include -#include -#include + if (!s->feature_set_defaults) goto err; + return s; -// Must be last. +err: + upb_DefPool_Free(s); + return NULL; +} -#define EXTREG_KEY_SIZE (sizeof(upb_MiniTable*) + sizeof(uint32_t)) - -struct upb_ExtensionRegistry { - upb_Arena* arena; - upb_strtable exts; // Key is upb_MiniTable* concatenated with fieldnum. -}; - -static void extreg_key(char* buf, const upb_MiniTable* l, uint32_t fieldnum) { - memcpy(buf, &l, sizeof(l)); - memcpy(buf + sizeof(l), &fieldnum, sizeof(fieldnum)); +const UPB_DESC(FeatureSetDefaults) * + upb_DefPool_FeatureSetDefaults(const upb_DefPool* s) { + return s->feature_set_defaults; } -upb_ExtensionRegistry* upb_ExtensionRegistry_New(upb_Arena* arena) { - upb_ExtensionRegistry* r = upb_Arena_Malloc(arena, sizeof(*r)); - if (!r) return NULL; - r->arena = arena; - if (!upb_strtable_init(&r->exts, 8, arena)) return NULL; - return r; +bool upb_DefPool_SetFeatureSetDefaults(upb_DefPool* s, + const char* serialized_defaults, + size_t serialized_len, + upb_Status* status) { + const UPB_DESC(FeatureSetDefaults)* defaults = UPB_DESC( + FeatureSetDefaults_parse)(serialized_defaults, serialized_len, s->arena); + if (!defaults) { + upb_Status_SetErrorFormat(status, "Failed to parse defaults"); + return false; + } + if (upb_strtable_count(&s->files) > 0) { + upb_Status_SetErrorFormat(status, + "Feature set defaults can't be changed once the " + "pool has started building"); + return false; + } + int min_edition = UPB_DESC(FeatureSetDefaults_minimum_edition(defaults)); + int max_edition = UPB_DESC(FeatureSetDefaults_maximum_edition(defaults)); + if (min_edition > max_edition) { + upb_Status_SetErrorFormat(status, "Invalid edition range %s to %s", + upb_FileDef_EditionName(min_edition), + upb_FileDef_EditionName(max_edition)); + return false; + } + size_t size; + const UPB_DESC( + FeatureSetDefaults_FeatureSetEditionDefault)* const* default_list = + UPB_DESC(FeatureSetDefaults_defaults(defaults, &size)); + int prev_edition = UPB_DESC(EDITION_UNKNOWN); + for (size_t i = 0; i < size; ++i) { + int edition = UPB_DESC( + FeatureSetDefaults_FeatureSetEditionDefault_edition(default_list[i])); + if (edition == UPB_DESC(EDITION_UNKNOWN)) { + upb_Status_SetErrorFormat(status, "Invalid edition UNKNOWN specified"); + return false; + } + if (edition <= prev_edition) { + upb_Status_SetErrorFormat(status, + "Feature set defaults are not strictly " + "increasing, %s is greater than or equal to %s", + upb_FileDef_EditionName(prev_edition), + upb_FileDef_EditionName(edition)); + return false; + } + prev_edition = edition; + } + + // Copy the defaults into the pool. + s->feature_set_defaults = defaults; + return true; } -UPB_API bool upb_ExtensionRegistry_Add(upb_ExtensionRegistry* r, - const upb_MiniTableExtension* e) { - char buf[EXTREG_KEY_SIZE]; - extreg_key(buf, e->UPB_PRIVATE(extendee), upb_MiniTableExtension_Number(e)); - if (upb_strtable_lookup2(&r->exts, buf, EXTREG_KEY_SIZE, NULL)) return false; - return upb_strtable_insert(&r->exts, buf, EXTREG_KEY_SIZE, - upb_value_constptr(e), r->arena); +bool _upb_DefPool_InsertExt(upb_DefPool* s, const upb_MiniTableExtension* ext, + const upb_FieldDef* f) { + return upb_inttable_insert(&s->exts, (uintptr_t)ext, upb_value_constptr(f), + s->arena); } -bool upb_ExtensionRegistry_AddArray(upb_ExtensionRegistry* r, - const upb_MiniTableExtension** e, - size_t count) { - const upb_MiniTableExtension** start = e; - const upb_MiniTableExtension** end = UPB_PTRADD(e, count); - for (; e < end; e++) { - if (!upb_ExtensionRegistry_Add(r, *e)) goto failure; +bool _upb_DefPool_InsertSym(upb_DefPool* s, upb_StringView sym, upb_value v, + upb_Status* status) { + // TODO: table should support an operation "tryinsert" to avoid the double + // lookup. + if (upb_strtable_lookup2(&s->syms, sym.data, sym.size, NULL)) { + upb_Status_SetErrorFormat(status, "duplicate symbol '%s'", sym.data); + return false; } - return true; - -failure: - // Back out the entries previously added. - for (end = e, e = start; e < end; e++) { - const upb_MiniTableExtension* ext = *e; - char buf[EXTREG_KEY_SIZE]; - extreg_key(buf, ext->UPB_PRIVATE(extendee), - upb_MiniTableExtension_Number(ext)); - upb_strtable_remove2(&r->exts, buf, EXTREG_KEY_SIZE, NULL); + if (!upb_strtable_insert(&s->syms, sym.data, sym.size, v, s->arena)) { + upb_Status_SetErrorMessage(status, "out of memory"); + return false; } - return false; + return true; } -const upb_MiniTableExtension* upb_ExtensionRegistry_Lookup( - const upb_ExtensionRegistry* r, const upb_MiniTable* t, uint32_t num) { - char buf[EXTREG_KEY_SIZE]; +static const void* _upb_DefPool_Unpack(const upb_DefPool* s, const char* sym, + size_t size, upb_deftype_t type) { upb_value v; - extreg_key(buf, t, num); - if (upb_strtable_lookup2(&r->exts, buf, EXTREG_KEY_SIZE, &v)) { - return upb_value_getconstptr(v); - } else { - return NULL; - } + return upb_strtable_lookup2(&s->syms, sym, size, &v) + ? _upb_DefType_Unpack(v, type) + : NULL; } +bool _upb_DefPool_LookupSym(const upb_DefPool* s, const char* sym, size_t size, + upb_value* v) { + return upb_strtable_lookup2(&s->syms, sym, size, v); +} -#include -#include -#include +upb_ExtensionRegistry* _upb_DefPool_ExtReg(const upb_DefPool* s) { + return s->extreg; +} +void** _upb_DefPool_ScratchData(const upb_DefPool* s) { + return (void**)&s->scratch_data; +} -// Must be last. +size_t* _upb_DefPool_ScratchSize(const upb_DefPool* s) { + return (size_t*)&s->scratch_size; +} -const upb_MiniTableField* upb_MiniTable_FindFieldByNumber( - const upb_MiniTable* m, uint32_t number) { - const size_t i = ((size_t)number) - 1; // 0 wraps to SIZE_MAX +void _upb_DefPool_SetPlatform(upb_DefPool* s, upb_MiniTablePlatform platform) { + assert(upb_strtable_count(&s->files) == 0); + s->platform = platform; +} - // Ideal case: index into dense fields - if (i < m->UPB_PRIVATE(dense_below)) { - UPB_ASSERT(m->UPB_PRIVATE(fields)[i].UPB_PRIVATE(number) == number); - return &m->UPB_PRIVATE(fields)[i]; - } +const upb_MessageDef* upb_DefPool_FindMessageByName(const upb_DefPool* s, + const char* sym) { + return _upb_DefPool_Unpack(s, sym, strlen(sym), UPB_DEFTYPE_MSG); +} - // Slow case: binary search - int lo = m->UPB_PRIVATE(dense_below); - int hi = m->UPB_PRIVATE(field_count) - 1; - while (lo <= hi) { - int mid = (lo + hi) / 2; - uint32_t num = m->UPB_PRIVATE(fields)[mid].UPB_PRIVATE(number); - if (num < number) { - lo = mid + 1; - continue; - } - if (num > number) { - hi = mid - 1; - continue; - } - return &m->UPB_PRIVATE(fields)[mid]; - } - return NULL; +const upb_MessageDef* upb_DefPool_FindMessageByNameWithSize( + const upb_DefPool* s, const char* sym, size_t len) { + return _upb_DefPool_Unpack(s, sym, len, UPB_DEFTYPE_MSG); } -const upb_MiniTableField* upb_MiniTable_GetOneof(const upb_MiniTable* m, - const upb_MiniTableField* f) { - if (UPB_UNLIKELY(!upb_MiniTableField_IsInOneof(f))) { - return NULL; - } - const upb_MiniTableField* ptr = &m->UPB_PRIVATE(fields)[0]; - const upb_MiniTableField* end = - &m->UPB_PRIVATE(fields)[m->UPB_PRIVATE(field_count)]; - for (; ptr < end; ptr++) { - if (ptr->presence == (*f).presence) { - return ptr; - } - } - return NULL; +const upb_EnumDef* upb_DefPool_FindEnumByName(const upb_DefPool* s, + const char* sym) { + return _upb_DefPool_Unpack(s, sym, strlen(sym), UPB_DEFTYPE_ENUM); } -bool upb_MiniTable_NextOneofField(const upb_MiniTable* m, - const upb_MiniTableField** f) { - const upb_MiniTableField* ptr = *f; - const upb_MiniTableField* end = - &m->UPB_PRIVATE(fields)[m->UPB_PRIVATE(field_count)]; - while (++ptr < end) { - if (ptr->presence == (*f)->presence) { - *f = ptr; - return true; +const upb_EnumValueDef* upb_DefPool_FindEnumByNameval(const upb_DefPool* s, + const char* sym) { + return _upb_DefPool_Unpack(s, sym, strlen(sym), UPB_DEFTYPE_ENUMVAL); +} + +const upb_FileDef* upb_DefPool_FindFileByName(const upb_DefPool* s, + const char* name) { + upb_value v; + return upb_strtable_lookup(&s->files, name, &v) ? upb_value_getconstptr(v) + : NULL; +} + +const upb_FileDef* upb_DefPool_FindFileByNameWithSize(const upb_DefPool* s, + const char* name, + size_t len) { + upb_value v; + return upb_strtable_lookup2(&s->files, name, len, &v) + ? upb_value_getconstptr(v) + : NULL; +} + +const upb_FieldDef* upb_DefPool_FindExtensionByNameWithSize( + const upb_DefPool* s, const char* name, size_t size) { + upb_value v; + if (!upb_strtable_lookup2(&s->syms, name, size, &v)) return NULL; + + switch (_upb_DefType_Type(v)) { + case UPB_DEFTYPE_FIELD: + return _upb_DefType_Unpack(v, UPB_DEFTYPE_FIELD); + case UPB_DEFTYPE_MSG: { + const upb_MessageDef* m = _upb_DefType_Unpack(v, UPB_DEFTYPE_MSG); + return _upb_MessageDef_InMessageSet(m) + ? upb_MessageDef_NestedExtension(m, 0) + : NULL; } + default: + break; } - return false; + + return NULL; } +const upb_FieldDef* upb_DefPool_FindExtensionByName(const upb_DefPool* s, + const char* sym) { + return upb_DefPool_FindExtensionByNameWithSize(s, sym, strlen(sym)); +} -#include -#include +const upb_ServiceDef* upb_DefPool_FindServiceByName(const upb_DefPool* s, + const char* name) { + return _upb_DefPool_Unpack(s, name, strlen(name), UPB_DEFTYPE_SERVICE); +} +const upb_ServiceDef* upb_DefPool_FindServiceByNameWithSize( + const upb_DefPool* s, const char* name, size_t size) { + return _upb_DefPool_Unpack(s, name, size, UPB_DEFTYPE_SERVICE); +} -// Must be last. - -// Checks if source and target mini table fields are identical. -// -// If the field is a sub message and sub messages are identical we record -// the association in table. -// -// Hashing the source sub message mini table and it's equivalent in the table -// stops recursing when a cycle is detected and instead just checks if the -// destination table is equal. -static upb_MiniTableEquals_Status upb_deep_check(const upb_MiniTable* src, - const upb_MiniTable* dst, - upb_inttable* table, - upb_Arena** arena) { - if (src->UPB_PRIVATE(field_count) != dst->UPB_PRIVATE(field_count)) - return kUpb_MiniTableEquals_NotEqual; - bool marked_src = false; - for (int i = 0; i < upb_MiniTable_FieldCount(src); i++) { - const upb_MiniTableField* src_field = upb_MiniTable_GetFieldByIndex(src, i); - const upb_MiniTableField* dst_field = upb_MiniTable_FindFieldByNumber( - dst, upb_MiniTableField_Number(src_field)); - - if (upb_MiniTableField_CType(src_field) != - upb_MiniTableField_CType(dst_field)) - return false; - if (src_field->UPB_PRIVATE(mode) != dst_field->UPB_PRIVATE(mode)) - return false; - if (src_field->UPB_PRIVATE(offset) != dst_field->UPB_PRIVATE(offset)) - return false; - if (src_field->presence != dst_field->presence) return false; - if (src_field->UPB_PRIVATE(submsg_index) != - dst_field->UPB_PRIVATE(submsg_index)) - return kUpb_MiniTableEquals_NotEqual; - - // Go no further if we are only checking for compatibility. - if (!table) continue; - - if (upb_MiniTableField_CType(src_field) == kUpb_CType_Message) { - if (!*arena) { - *arena = upb_Arena_New(); - if (!upb_inttable_init(table, *arena)) { - return kUpb_MiniTableEquals_OutOfMemory; - } +const upb_FileDef* upb_DefPool_FindFileContainingSymbol(const upb_DefPool* s, + const char* name) { + upb_value v; + // TODO: non-extension fields and oneofs. + if (upb_strtable_lookup(&s->syms, name, &v)) { + switch (_upb_DefType_Type(v)) { + case UPB_DEFTYPE_EXT: { + const upb_FieldDef* f = _upb_DefType_Unpack(v, UPB_DEFTYPE_EXT); + return upb_FieldDef_File(f); } - if (!marked_src) { - marked_src = true; - upb_value val; - val.val = (uint64_t)dst; - if (!upb_inttable_insert(table, (uintptr_t)src, val, *arena)) { - return kUpb_MiniTableEquals_OutOfMemory; - } + case UPB_DEFTYPE_MSG: { + const upb_MessageDef* m = _upb_DefType_Unpack(v, UPB_DEFTYPE_MSG); + return upb_MessageDef_File(m); } - const upb_MiniTable* sub_src = - upb_MiniTable_GetSubMessageTable(src, src_field); - const upb_MiniTable* sub_dst = - upb_MiniTable_GetSubMessageTable(dst, dst_field); - if (sub_src != NULL) { - upb_value cmp; - if (upb_inttable_lookup(table, (uintptr_t)sub_src, &cmp)) { - // We already compared this src before. Check if same dst. - if (cmp.val != (uint64_t)sub_dst) { - return kUpb_MiniTableEquals_NotEqual; - } - } else { - // Recurse if not already visited. - upb_MiniTableEquals_Status s = - upb_deep_check(sub_src, sub_dst, table, arena); - if (s != kUpb_MiniTableEquals_Equal) { - return s; - } - } + case UPB_DEFTYPE_ENUM: { + const upb_EnumDef* e = _upb_DefType_Unpack(v, UPB_DEFTYPE_ENUM); + return upb_EnumDef_File(e); + } + case UPB_DEFTYPE_ENUMVAL: { + const upb_EnumValueDef* ev = + _upb_DefType_Unpack(v, UPB_DEFTYPE_ENUMVAL); + return upb_EnumDef_File(upb_EnumValueDef_Enum(ev)); } + case UPB_DEFTYPE_SERVICE: { + const upb_ServiceDef* service = + _upb_DefType_Unpack(v, UPB_DEFTYPE_SERVICE); + return upb_ServiceDef_File(service); + } + default: + UPB_UNREACHABLE(); } } - return kUpb_MiniTableEquals_Equal; + + const char* last_dot = strrchr(name, '.'); + if (last_dot) { + const upb_MessageDef* parent = + upb_DefPool_FindMessageByNameWithSize(s, name, last_dot - name); + if (parent) { + const char* shortname = last_dot + 1; + if (upb_MessageDef_FindByNameWithSize(parent, shortname, + strlen(shortname), NULL, NULL)) { + return upb_MessageDef_File(parent); + } + } + } + + return NULL; } -bool upb_MiniTable_Compatible(const upb_MiniTable* src, - const upb_MiniTable* dst) { - return upb_deep_check(src, dst, NULL, NULL); +static void remove_filedef(upb_DefPool* s, upb_FileDef* file) { + intptr_t iter = UPB_INTTABLE_BEGIN; + upb_StringView key; + upb_value val; + while (upb_strtable_next2(&s->syms, &key, &val, &iter)) { + const upb_FileDef* f; + switch (_upb_DefType_Type(val)) { + case UPB_DEFTYPE_EXT: + f = upb_FieldDef_File(_upb_DefType_Unpack(val, UPB_DEFTYPE_EXT)); + break; + case UPB_DEFTYPE_MSG: + f = upb_MessageDef_File(_upb_DefType_Unpack(val, UPB_DEFTYPE_MSG)); + break; + case UPB_DEFTYPE_ENUM: + f = upb_EnumDef_File(_upb_DefType_Unpack(val, UPB_DEFTYPE_ENUM)); + break; + case UPB_DEFTYPE_ENUMVAL: + f = upb_EnumDef_File(upb_EnumValueDef_Enum( + _upb_DefType_Unpack(val, UPB_DEFTYPE_ENUMVAL))); + break; + case UPB_DEFTYPE_SERVICE: + f = upb_ServiceDef_File(_upb_DefType_Unpack(val, UPB_DEFTYPE_SERVICE)); + break; + default: + UPB_UNREACHABLE(); + } + + if (f == file) upb_strtable_removeiter(&s->syms, &iter); + } } -upb_MiniTableEquals_Status upb_MiniTable_Equals(const upb_MiniTable* src, - const upb_MiniTable* dst) { - // Arena allocated on demand for hash table. - upb_Arena* arena = NULL; - // Table to keep track of visited mini tables to guard against cycles. - upb_inttable table; - upb_MiniTableEquals_Status status = upb_deep_check(src, dst, &table, &arena); - if (arena) { - upb_Arena_Free(arena); +static const upb_FileDef* upb_DefBuilder_AddFileToPool( + upb_DefBuilder* const builder, upb_DefPool* const s, + const UPB_DESC(FileDescriptorProto) * const file_proto, + const upb_StringView name, upb_Status* const status) { + if (UPB_SETJMP(builder->err) != 0) { + UPB_ASSERT(!upb_Status_IsOk(status)); + if (builder->file) { + remove_filedef(s, builder->file); + builder->file = NULL; + } + } else if (!builder->arena || !builder->tmp_arena || + !upb_strtable_init(&builder->feature_cache, 16, + builder->tmp_arena) || + !(builder->legacy_features = + UPB_DESC(FeatureSet_new)(builder->tmp_arena))) { + _upb_DefBuilder_OomErr(builder); + } else { + _upb_FileDef_Create(builder, file_proto); + upb_strtable_insert(&s->files, name.data, name.size, + upb_value_constptr(builder->file), builder->arena); + UPB_ASSERT(upb_Status_IsOk(status)); + upb_Arena_Fuse(s->arena, builder->arena); } - return status; + + if (builder->arena) upb_Arena_Free(builder->arena); + if (builder->tmp_arena) upb_Arena_Free(builder->tmp_arena); + return builder->file; } +static const upb_FileDef* _upb_DefPool_AddFile( + upb_DefPool* s, const UPB_DESC(FileDescriptorProto) * file_proto, + const upb_MiniTableFile* layout, upb_Status* status) { + const upb_StringView name = UPB_DESC(FileDescriptorProto_name)(file_proto); + // Determine whether we already know about this file. + { + upb_value v; + if (upb_strtable_lookup2(&s->files, name.data, name.size, &v)) { + upb_Status_SetErrorFormat(status, + "duplicate file name " UPB_STRINGVIEW_FORMAT, + UPB_STRINGVIEW_ARGS(name)); + return NULL; + } + } -// Must be last. + upb_DefBuilder ctx = { + .symtab = s, + .tmp_buf = NULL, + .tmp_buf_size = 0, + .layout = layout, + .platform = s->platform, + .msg_count = 0, + .enum_count = 0, + .ext_count = 0, + .status = status, + .file = NULL, + .arena = upb_Arena_New(), + .tmp_arena = upb_Arena_New(), + }; -struct upb_DefPool { - upb_Arena* arena; - upb_strtable syms; // full_name -> packed def ptr - upb_strtable files; // file_name -> (upb_FileDef*) - upb_inttable exts; // (upb_MiniTableExtension*) -> (upb_FieldDef*) - upb_ExtensionRegistry* extreg; - const UPB_DESC(FeatureSetDefaults) * feature_set_defaults; - upb_MiniTablePlatform platform; - void* scratch_data; - size_t scratch_size; - size_t bytes_loaded; -}; + return upb_DefBuilder_AddFileToPool(&ctx, s, file_proto, name, status); +} -void upb_DefPool_Free(upb_DefPool* s) { - upb_Arena_Free(s->arena); - upb_gfree(s->scratch_data); - upb_gfree(s); +const upb_FileDef* upb_DefPool_AddFile(upb_DefPool* s, + const UPB_DESC(FileDescriptorProto) * + file_proto, + upb_Status* status) { + return _upb_DefPool_AddFile(s, file_proto, NULL, status); } -static const char serialized_defaults[] = UPB_INTERNAL_UPB_EDITION_DEFAULTS; +bool _upb_DefPool_LoadDefInitEx(upb_DefPool* s, const _upb_DefPool_Init* init, + bool rebuild_minitable) { + /* Since this function should never fail (it would indicate a bug in upb) we + * print errors to stderr instead of returning error status to the user. */ + _upb_DefPool_Init** deps = init->deps; + UPB_DESC(FileDescriptorProto) * file; + upb_Arena* arena; + upb_Status status; -upb_DefPool* upb_DefPool_New(void) { - upb_DefPool* s = upb_gmalloc(sizeof(*s)); - if (!s) return NULL; + upb_Status_Clear(&status); - s->arena = upb_Arena_New(); - s->bytes_loaded = 0; + if (upb_DefPool_FindFileByName(s, init->filename)) { + return true; + } - s->scratch_size = 240; - s->scratch_data = upb_gmalloc(s->scratch_size); - if (!s->scratch_data) goto err; + arena = upb_Arena_New(); - if (!upb_strtable_init(&s->syms, 32, s->arena)) goto err; - if (!upb_strtable_init(&s->files, 4, s->arena)) goto err; - if (!upb_inttable_init(&s->exts, s->arena)) goto err; - - s->extreg = upb_ExtensionRegistry_New(s->arena); - if (!s->extreg) goto err; + for (; *deps; deps++) { + if (!_upb_DefPool_LoadDefInitEx(s, *deps, rebuild_minitable)) goto err; + } - s->platform = kUpb_MiniTablePlatform_Native; + file = UPB_DESC(FileDescriptorProto_parse_ex)( + init->descriptor.data, init->descriptor.size, NULL, + kUpb_DecodeOption_AliasString, arena); + s->bytes_loaded += init->descriptor.size; - upb_Status status; - if (!upb_DefPool_SetFeatureSetDefaults( - s, serialized_defaults, sizeof(serialized_defaults) - 1, &status)) { + if (!file) { + upb_Status_SetErrorFormat( + &status, + "Failed to parse compiled-in descriptor for file '%s'. This should " + "never happen.", + init->filename); goto err; } - if (!s->feature_set_defaults) goto err; - - return s; - -err: - upb_DefPool_Free(s); - return NULL; -} - -const UPB_DESC(FeatureSetDefaults) * - upb_DefPool_FeatureSetDefaults(const upb_DefPool* s) { - return s->feature_set_defaults; -} - -bool upb_DefPool_SetFeatureSetDefaults(upb_DefPool* s, - const char* serialized_defaults, - size_t serialized_len, - upb_Status* status) { - const UPB_DESC(FeatureSetDefaults)* defaults = UPB_DESC( - FeatureSetDefaults_parse)(serialized_defaults, serialized_len, s->arena); - if (!defaults) { - upb_Status_SetErrorFormat(status, "Failed to parse defaults"); - return false; - } - if (upb_strtable_count(&s->files) > 0) { - upb_Status_SetErrorFormat(status, - "Feature set defaults can't be changed once the " - "pool has started building"); - return false; - } - int min_edition = UPB_DESC(FeatureSetDefaults_minimum_edition(defaults)); - int max_edition = UPB_DESC(FeatureSetDefaults_maximum_edition(defaults)); - if (min_edition > max_edition) { - upb_Status_SetErrorFormat(status, "Invalid edition range %s to %s", - upb_FileDef_EditionName(min_edition), - upb_FileDef_EditionName(max_edition)); - return false; - } - size_t size; - const UPB_DESC( - FeatureSetDefaults_FeatureSetEditionDefault)* const* default_list = - UPB_DESC(FeatureSetDefaults_defaults(defaults, &size)); - int prev_edition = UPB_DESC(EDITION_UNKNOWN); - for (size_t i = 0; i < size; ++i) { - int edition = UPB_DESC( - FeatureSetDefaults_FeatureSetEditionDefault_edition(default_list[i])); - if (edition == UPB_DESC(EDITION_UNKNOWN)) { - upb_Status_SetErrorFormat(status, "Invalid edition UNKNOWN specified"); - return false; - } - if (edition <= prev_edition) { - upb_Status_SetErrorFormat(status, - "Feature set defaults are not strictly " - "increasing, %s is greater than or equal to %s", - upb_FileDef_EditionName(prev_edition), - upb_FileDef_EditionName(edition)); - return false; - } - prev_edition = edition; + const upb_MiniTableFile* mt = rebuild_minitable ? NULL : init->layout; + if (!_upb_DefPool_AddFile(s, file, mt, &status)) { + goto err; } - // Copy the defaults into the pool. - s->feature_set_defaults = defaults; + upb_Arena_Free(arena); return true; -} -bool _upb_DefPool_InsertExt(upb_DefPool* s, const upb_MiniTableExtension* ext, - const upb_FieldDef* f) { - return upb_inttable_insert(&s->exts, (uintptr_t)ext, upb_value_constptr(f), - s->arena); +err: + fprintf(stderr, + "Error loading compiled-in descriptor for file '%s' (this should " + "never happen): %s\n", + init->filename, upb_Status_ErrorMessage(&status)); + upb_Arena_Free(arena); + return false; } -bool _upb_DefPool_InsertSym(upb_DefPool* s, upb_StringView sym, upb_value v, - upb_Status* status) { - // TODO: table should support an operation "tryinsert" to avoid the double - // lookup. - if (upb_strtable_lookup2(&s->syms, sym.data, sym.size, NULL)) { - upb_Status_SetErrorFormat(status, "duplicate symbol '%s'", sym.data); - return false; - } - if (!upb_strtable_insert(&s->syms, sym.data, sym.size, v, s->arena)) { - upb_Status_SetErrorMessage(status, "out of memory"); - return false; - } - return true; +size_t _upb_DefPool_BytesLoaded(const upb_DefPool* s) { + return s->bytes_loaded; } -static const void* _upb_DefPool_Unpack(const upb_DefPool* s, const char* sym, - size_t size, upb_deftype_t type) { +upb_Arena* _upb_DefPool_Arena(const upb_DefPool* s) { return s->arena; } + +const upb_FieldDef* upb_DefPool_FindExtensionByMiniTable( + const upb_DefPool* s, const upb_MiniTableExtension* ext) { upb_value v; - return upb_strtable_lookup2(&s->syms, sym, size, &v) - ? _upb_DefType_Unpack(v, type) - : NULL; + bool ok = upb_inttable_lookup(&s->exts, (uintptr_t)ext, &v); + UPB_ASSERT(ok); + return upb_value_getconstptr(v); } -bool _upb_DefPool_LookupSym(const upb_DefPool* s, const char* sym, size_t size, - upb_value* v) { - return upb_strtable_lookup2(&s->syms, sym, size, v); +const upb_FieldDef* upb_DefPool_FindExtensionByNumber(const upb_DefPool* s, + const upb_MessageDef* m, + int32_t fieldnum) { + const upb_MiniTable* t = upb_MessageDef_MiniTable(m); + const upb_MiniTableExtension* ext = + upb_ExtensionRegistry_Lookup(s->extreg, t, fieldnum); + return ext ? upb_DefPool_FindExtensionByMiniTable(s, ext) : NULL; } -upb_ExtensionRegistry* _upb_DefPool_ExtReg(const upb_DefPool* s) { +const upb_ExtensionRegistry* upb_DefPool_ExtensionRegistry( + const upb_DefPool* s) { return s->extreg; } -void** _upb_DefPool_ScratchData(const upb_DefPool* s) { - return (void**)&s->scratch_data; +const upb_FieldDef** upb_DefPool_GetAllExtensions(const upb_DefPool* s, + const upb_MessageDef* m, + size_t* count) { + size_t n = 0; + intptr_t iter = UPB_INTTABLE_BEGIN; + uintptr_t key; + upb_value val; + // This is O(all exts) instead of O(exts for m). If we need this to be + // efficient we may need to make extreg into a two-level table, or have a + // second per-message index. + while (upb_inttable_next(&s->exts, &key, &val, &iter)) { + const upb_FieldDef* f = upb_value_getconstptr(val); + if (upb_FieldDef_ContainingType(f) == m) n++; + } + const upb_FieldDef** exts = upb_gmalloc(n * sizeof(*exts)); + iter = UPB_INTTABLE_BEGIN; + size_t i = 0; + while (upb_inttable_next(&s->exts, &key, &val, &iter)) { + const upb_FieldDef* f = upb_value_getconstptr(val); + if (upb_FieldDef_ContainingType(f) == m) exts[i++] = f; + } + *count = n; + return exts; } -size_t* _upb_DefPool_ScratchSize(const upb_DefPool* s) { - return (size_t*)&s->scratch_size; +bool _upb_DefPool_LoadDefInit(upb_DefPool* s, const _upb_DefPool_Init* init) { + return _upb_DefPool_LoadDefInitEx(s, init, false); } -void _upb_DefPool_SetPlatform(upb_DefPool* s, upb_MiniTablePlatform platform) { - assert(upb_strtable_count(&s->files) == 0); - s->platform = platform; -} -const upb_MessageDef* upb_DefPool_FindMessageByName(const upb_DefPool* s, - const char* sym) { - return _upb_DefPool_Unpack(s, sym, strlen(sym), UPB_DEFTYPE_MSG); -} +// Must be last. -const upb_MessageDef* upb_DefPool_FindMessageByNameWithSize( - const upb_DefPool* s, const char* sym, size_t len) { - return _upb_DefPool_Unpack(s, sym, len, UPB_DEFTYPE_MSG); +upb_deftype_t _upb_DefType_Type(upb_value v) { + const uintptr_t num = (uintptr_t)upb_value_getconstptr(v); + return num & UPB_DEFTYPE_MASK; } -const upb_EnumDef* upb_DefPool_FindEnumByName(const upb_DefPool* s, - const char* sym) { - return _upb_DefPool_Unpack(s, sym, strlen(sym), UPB_DEFTYPE_ENUM); +upb_value _upb_DefType_Pack(const void* ptr, upb_deftype_t type) { + uintptr_t num = (uintptr_t)ptr; + UPB_ASSERT((num & UPB_DEFTYPE_MASK) == 0); + num |= type; + return upb_value_constptr((const void*)num); } -const upb_EnumValueDef* upb_DefPool_FindEnumByNameval(const upb_DefPool* s, - const char* sym) { - return _upb_DefPool_Unpack(s, sym, strlen(sym), UPB_DEFTYPE_ENUMVAL); +const void* _upb_DefType_Unpack(upb_value v, upb_deftype_t type) { + uintptr_t num = (uintptr_t)upb_value_getconstptr(v); + return (num & UPB_DEFTYPE_MASK) == type + ? (const void*)(num & ~UPB_DEFTYPE_MASK) + : NULL; } -const upb_FileDef* upb_DefPool_FindFileByName(const upb_DefPool* s, - const char* name) { - upb_value v; - return upb_strtable_lookup(&s->files, name, &v) ? upb_value_getconstptr(v) - : NULL; -} -const upb_FileDef* upb_DefPool_FindFileByNameWithSize(const upb_DefPool* s, - const char* name, - size_t len) { - upb_value v; - return upb_strtable_lookup2(&s->files, name, len, &v) - ? upb_value_getconstptr(v) - : NULL; -} +// Must be last. -const upb_FieldDef* upb_DefPool_FindExtensionByNameWithSize( - const upb_DefPool* s, const char* name, size_t size) { - upb_value v; - if (!upb_strtable_lookup2(&s->syms, name, size, &v)) return NULL; +bool _upb_DescState_Grow(upb_DescState* d, upb_Arena* a) { + const size_t oldbufsize = d->bufsize; + const int used = d->ptr - d->buf; - switch (_upb_DefType_Type(v)) { - case UPB_DEFTYPE_FIELD: - return _upb_DefType_Unpack(v, UPB_DEFTYPE_FIELD); - case UPB_DEFTYPE_MSG: { - const upb_MessageDef* m = _upb_DefType_Unpack(v, UPB_DEFTYPE_MSG); - return _upb_MessageDef_InMessageSet(m) - ? upb_MessageDef_NestedExtension(m, 0) - : NULL; - } - default: - break; + if (!d->buf) { + d->buf = upb_Arena_Malloc(a, d->bufsize); + if (!d->buf) return false; + d->ptr = d->buf; + d->e.end = d->buf + d->bufsize; } - return NULL; -} + if (oldbufsize - used < kUpb_MtDataEncoder_MinSize) { + d->bufsize *= 2; + d->buf = upb_Arena_Realloc(a, d->buf, oldbufsize, d->bufsize); + if (!d->buf) return false; + d->ptr = d->buf + used; + d->e.end = d->buf + d->bufsize; + } -const upb_FieldDef* upb_DefPool_FindExtensionByName(const upb_DefPool* s, - const char* sym) { - return upb_DefPool_FindExtensionByNameWithSize(s, sym, strlen(sym)); + return true; } -const upb_ServiceDef* upb_DefPool_FindServiceByName(const upb_DefPool* s, - const char* name) { - return _upb_DefPool_Unpack(s, name, strlen(name), UPB_DEFTYPE_SERVICE); -} -const upb_ServiceDef* upb_DefPool_FindServiceByNameWithSize( - const upb_DefPool* s, const char* name, size_t size) { - return _upb_DefPool_Unpack(s, name, size, UPB_DEFTYPE_SERVICE); -} - -const upb_FileDef* upb_DefPool_FindFileContainingSymbol(const upb_DefPool* s, - const char* name) { - upb_value v; - // TODO: non-extension fields and oneofs. - if (upb_strtable_lookup(&s->syms, name, &v)) { - switch (_upb_DefType_Type(v)) { - case UPB_DEFTYPE_EXT: { - const upb_FieldDef* f = _upb_DefType_Unpack(v, UPB_DEFTYPE_EXT); - return upb_FieldDef_File(f); - } - case UPB_DEFTYPE_MSG: { - const upb_MessageDef* m = _upb_DefType_Unpack(v, UPB_DEFTYPE_MSG); - return upb_MessageDef_File(m); - } - case UPB_DEFTYPE_ENUM: { - const upb_EnumDef* e = _upb_DefType_Unpack(v, UPB_DEFTYPE_ENUM); - return upb_EnumDef_File(e); - } - case UPB_DEFTYPE_ENUMVAL: { - const upb_EnumValueDef* ev = - _upb_DefType_Unpack(v, UPB_DEFTYPE_ENUMVAL); - return upb_EnumDef_File(upb_EnumValueDef_Enum(ev)); - } - case UPB_DEFTYPE_SERVICE: { - const upb_ServiceDef* service = - _upb_DefType_Unpack(v, UPB_DEFTYPE_SERVICE); - return upb_ServiceDef_File(service); - } - default: - UPB_UNREACHABLE(); - } - } +#include +#include +#include - const char* last_dot = strrchr(name, '.'); - if (last_dot) { - const upb_MessageDef* parent = - upb_DefPool_FindMessageByNameWithSize(s, name, last_dot - name); - if (parent) { - const char* shortname = last_dot + 1; - if (upb_MessageDef_FindByNameWithSize(parent, shortname, - strlen(shortname), NULL, NULL)) { - return upb_MessageDef_File(parent); - } - } - } - return NULL; -} +// Must be last. -static void remove_filedef(upb_DefPool* s, upb_FileDef* file) { - intptr_t iter = UPB_INTTABLE_BEGIN; - upb_StringView key; - upb_value val; - while (upb_strtable_next2(&s->syms, &key, &val, &iter)) { - const upb_FileDef* f; - switch (_upb_DefType_Type(val)) { - case UPB_DEFTYPE_EXT: - f = upb_FieldDef_File(_upb_DefType_Unpack(val, UPB_DEFTYPE_EXT)); - break; - case UPB_DEFTYPE_MSG: - f = upb_MessageDef_File(_upb_DefType_Unpack(val, UPB_DEFTYPE_MSG)); - break; - case UPB_DEFTYPE_ENUM: - f = upb_EnumDef_File(_upb_DefType_Unpack(val, UPB_DEFTYPE_ENUM)); - break; - case UPB_DEFTYPE_ENUMVAL: - f = upb_EnumDef_File(upb_EnumValueDef_Enum( - _upb_DefType_Unpack(val, UPB_DEFTYPE_ENUMVAL))); - break; - case UPB_DEFTYPE_SERVICE: - f = upb_ServiceDef_File(_upb_DefType_Unpack(val, UPB_DEFTYPE_SERVICE)); - break; - default: - UPB_UNREACHABLE(); - } +struct upb_EnumDef { + const UPB_DESC(EnumOptions*) opts; + const UPB_DESC(FeatureSet*) resolved_features; + const upb_MiniTableEnum* layout; // Only for proto2. + const upb_FileDef* file; + const upb_MessageDef* containing_type; // Could be merged with "file". + const char* full_name; + upb_strtable ntoi; + upb_inttable iton; + const upb_EnumValueDef* values; + const upb_EnumReservedRange* res_ranges; + const upb_StringView* res_names; + int value_count; + int res_range_count; + int res_name_count; + int32_t defaultval; + bool is_sorted; // Whether all of the values are defined in ascending order. +#if UINTPTR_MAX == 0xffffffff + uint32_t padding; // Increase size to a multiple of 8. +#endif +}; - if (f == file) upb_strtable_removeiter(&s->syms, &iter); - } +upb_EnumDef* _upb_EnumDef_At(const upb_EnumDef* e, int i) { + return (upb_EnumDef*)&e[i]; } -static const upb_FileDef* upb_DefBuilder_AddFileToPool( - upb_DefBuilder* const builder, upb_DefPool* const s, - const UPB_DESC(FileDescriptorProto) * const file_proto, - const upb_StringView name, upb_Status* const status) { - if (UPB_SETJMP(builder->err) != 0) { - UPB_ASSERT(!upb_Status_IsOk(status)); - if (builder->file) { - remove_filedef(s, builder->file); - builder->file = NULL; - } - } else if (!builder->arena || !builder->tmp_arena || - !upb_strtable_init(&builder->feature_cache, 16, - builder->tmp_arena) || - !(builder->legacy_features = - UPB_DESC(FeatureSet_new)(builder->tmp_arena))) { - _upb_DefBuilder_OomErr(builder); - } else { - _upb_FileDef_Create(builder, file_proto); - upb_strtable_insert(&s->files, name.data, name.size, - upb_value_constptr(builder->file), builder->arena); - UPB_ASSERT(upb_Status_IsOk(status)); - upb_Arena_Fuse(s->arena, builder->arena); - } - - if (builder->arena) upb_Arena_Free(builder->arena); - if (builder->tmp_arena) upb_Arena_Free(builder->tmp_arena); - return builder->file; +const upb_MiniTableEnum* _upb_EnumDef_MiniTable(const upb_EnumDef* e) { + return e->layout; } -static const upb_FileDef* _upb_DefPool_AddFile( - upb_DefPool* s, const UPB_DESC(FileDescriptorProto) * file_proto, - const upb_MiniTableFile* layout, upb_Status* status) { - const upb_StringView name = UPB_DESC(FileDescriptorProto_name)(file_proto); +bool _upb_EnumDef_Insert(upb_EnumDef* e, upb_EnumValueDef* v, upb_Arena* a) { + const char* name = upb_EnumValueDef_Name(v); + const upb_value val = upb_value_constptr(v); + bool ok = upb_strtable_insert(&e->ntoi, name, strlen(name), val, a); + if (!ok) return false; - // Determine whether we already know about this file. - { - upb_value v; - if (upb_strtable_lookup2(&s->files, name.data, name.size, &v)) { - upb_Status_SetErrorFormat(status, - "duplicate file name " UPB_STRINGVIEW_FORMAT, - UPB_STRINGVIEW_ARGS(name)); - return NULL; - } + // Multiple enumerators can have the same number, first one wins. + const int number = upb_EnumValueDef_Number(v); + if (!upb_inttable_lookup(&e->iton, number, NULL)) { + return upb_inttable_insert(&e->iton, number, val, a); } - - upb_DefBuilder ctx = { - .symtab = s, - .tmp_buf = NULL, - .tmp_buf_size = 0, - .layout = layout, - .platform = s->platform, - .msg_count = 0, - .enum_count = 0, - .ext_count = 0, - .status = status, - .file = NULL, - .arena = upb_Arena_New(), - .tmp_arena = upb_Arena_New(), - }; - - return upb_DefBuilder_AddFileToPool(&ctx, s, file_proto, name, status); + return true; } -const upb_FileDef* upb_DefPool_AddFile(upb_DefPool* s, - const UPB_DESC(FileDescriptorProto) * - file_proto, - upb_Status* status) { - return _upb_DefPool_AddFile(s, file_proto, NULL, status); +const UPB_DESC(EnumOptions) * upb_EnumDef_Options(const upb_EnumDef* e) { + return e->opts; } -bool _upb_DefPool_LoadDefInitEx(upb_DefPool* s, const _upb_DefPool_Init* init, - bool rebuild_minitable) { - /* Since this function should never fail (it would indicate a bug in upb) we - * print errors to stderr instead of returning error status to the user. */ - _upb_DefPool_Init** deps = init->deps; - UPB_DESC(FileDescriptorProto) * file; - upb_Arena* arena; - upb_Status status; +bool upb_EnumDef_HasOptions(const upb_EnumDef* e) { + return e->opts != (void*)kUpbDefOptDefault; +} - upb_Status_Clear(&status); +const UPB_DESC(FeatureSet) * + upb_EnumDef_ResolvedFeatures(const upb_EnumDef* e) { + return e->resolved_features; +} - if (upb_DefPool_FindFileByName(s, init->filename)) { - return true; - } +const char* upb_EnumDef_FullName(const upb_EnumDef* e) { return e->full_name; } - arena = upb_Arena_New(); +const char* upb_EnumDef_Name(const upb_EnumDef* e) { + return _upb_DefBuilder_FullToShort(e->full_name); +} - for (; *deps; deps++) { - if (!_upb_DefPool_LoadDefInitEx(s, *deps, rebuild_minitable)) goto err; - } +const upb_FileDef* upb_EnumDef_File(const upb_EnumDef* e) { return e->file; } - file = UPB_DESC(FileDescriptorProto_parse_ex)( - init->descriptor.data, init->descriptor.size, NULL, - kUpb_DecodeOption_AliasString, arena); - s->bytes_loaded += init->descriptor.size; +const upb_MessageDef* upb_EnumDef_ContainingType(const upb_EnumDef* e) { + return e->containing_type; +} - if (!file) { - upb_Status_SetErrorFormat( - &status, - "Failed to parse compiled-in descriptor for file '%s'. This should " - "never happen.", - init->filename); - goto err; - } +int32_t upb_EnumDef_Default(const upb_EnumDef* e) { + UPB_ASSERT(upb_EnumDef_FindValueByNumber(e, e->defaultval)); + return e->defaultval; +} - const upb_MiniTableFile* mt = rebuild_minitable ? NULL : init->layout; - if (!_upb_DefPool_AddFile(s, file, mt, &status)) { - goto err; - } +int upb_EnumDef_ReservedRangeCount(const upb_EnumDef* e) { + return e->res_range_count; +} - upb_Arena_Free(arena); - return true; +const upb_EnumReservedRange* upb_EnumDef_ReservedRange(const upb_EnumDef* e, + int i) { + UPB_ASSERT(0 <= i && i < e->res_range_count); + return _upb_EnumReservedRange_At(e->res_ranges, i); +} -err: - fprintf(stderr, - "Error loading compiled-in descriptor for file '%s' (this should " - "never happen): %s\n", - init->filename, upb_Status_ErrorMessage(&status)); - upb_Arena_Free(arena); - return false; +int upb_EnumDef_ReservedNameCount(const upb_EnumDef* e) { + return e->res_name_count; } -size_t _upb_DefPool_BytesLoaded(const upb_DefPool* s) { - return s->bytes_loaded; +upb_StringView upb_EnumDef_ReservedName(const upb_EnumDef* e, int i) { + UPB_ASSERT(0 <= i && i < e->res_name_count); + return e->res_names[i]; } -upb_Arena* _upb_DefPool_Arena(const upb_DefPool* s) { return s->arena; } - -const upb_FieldDef* upb_DefPool_FindExtensionByMiniTable( - const upb_DefPool* s, const upb_MiniTableExtension* ext) { - upb_value v; - bool ok = upb_inttable_lookup(&s->exts, (uintptr_t)ext, &v); - UPB_ASSERT(ok); - return upb_value_getconstptr(v); -} - -const upb_FieldDef* upb_DefPool_FindExtensionByNumber(const upb_DefPool* s, - const upb_MessageDef* m, - int32_t fieldnum) { - const upb_MiniTable* t = upb_MessageDef_MiniTable(m); - const upb_MiniTableExtension* ext = - upb_ExtensionRegistry_Lookup(s->extreg, t, fieldnum); - return ext ? upb_DefPool_FindExtensionByMiniTable(s, ext) : NULL; -} - -const upb_ExtensionRegistry* upb_DefPool_ExtensionRegistry( - const upb_DefPool* s) { - return s->extreg; -} - -const upb_FieldDef** upb_DefPool_GetAllExtensions(const upb_DefPool* s, - const upb_MessageDef* m, - size_t* count) { - size_t n = 0; - intptr_t iter = UPB_INTTABLE_BEGIN; - uintptr_t key; - upb_value val; - // This is O(all exts) instead of O(exts for m). If we need this to be - // efficient we may need to make extreg into a two-level table, or have a - // second per-message index. - while (upb_inttable_next(&s->exts, &key, &val, &iter)) { - const upb_FieldDef* f = upb_value_getconstptr(val); - if (upb_FieldDef_ContainingType(f) == m) n++; - } - const upb_FieldDef** exts = upb_gmalloc(n * sizeof(*exts)); - iter = UPB_INTTABLE_BEGIN; - size_t i = 0; - while (upb_inttable_next(&s->exts, &key, &val, &iter)) { - const upb_FieldDef* f = upb_value_getconstptr(val); - if (upb_FieldDef_ContainingType(f) == m) exts[i++] = f; - } - *count = n; - return exts; -} - -bool _upb_DefPool_LoadDefInit(upb_DefPool* s, const _upb_DefPool_Init* init) { - return _upb_DefPool_LoadDefInitEx(s, init, false); -} - - -// Must be last. - -upb_deftype_t _upb_DefType_Type(upb_value v) { - const uintptr_t num = (uintptr_t)upb_value_getconstptr(v); - return num & UPB_DEFTYPE_MASK; -} - -upb_value _upb_DefType_Pack(const void* ptr, upb_deftype_t type) { - uintptr_t num = (uintptr_t)ptr; - UPB_ASSERT((num & UPB_DEFTYPE_MASK) == 0); - num |= type; - return upb_value_constptr((const void*)num); -} - -const void* _upb_DefType_Unpack(upb_value v, upb_deftype_t type) { - uintptr_t num = (uintptr_t)upb_value_getconstptr(v); - return (num & UPB_DEFTYPE_MASK) == type - ? (const void*)(num & ~UPB_DEFTYPE_MASK) - : NULL; -} - - -// Must be last. - -bool _upb_DescState_Grow(upb_DescState* d, upb_Arena* a) { - const size_t oldbufsize = d->bufsize; - const int used = d->ptr - d->buf; - - if (!d->buf) { - d->buf = upb_Arena_Malloc(a, d->bufsize); - if (!d->buf) return false; - d->ptr = d->buf; - d->e.end = d->buf + d->bufsize; - } - - if (oldbufsize - used < kUpb_MtDataEncoder_MinSize) { - d->bufsize *= 2; - d->buf = upb_Arena_Realloc(a, d->buf, oldbufsize, d->bufsize); - if (!d->buf) return false; - d->ptr = d->buf + used; - d->e.end = d->buf + d->bufsize; - } - - return true; -} - - -#include -#include -#include - - -// Must be last. - -struct upb_EnumDef { - const UPB_DESC(EnumOptions*) opts; - const UPB_DESC(FeatureSet*) resolved_features; - const upb_MiniTableEnum* layout; // Only for proto2. - const upb_FileDef* file; - const upb_MessageDef* containing_type; // Could be merged with "file". - const char* full_name; - upb_strtable ntoi; - upb_inttable iton; - const upb_EnumValueDef* values; - const upb_EnumReservedRange* res_ranges; - const upb_StringView* res_names; - int value_count; - int res_range_count; - int res_name_count; - int32_t defaultval; - bool is_sorted; // Whether all of the values are defined in ascending order. -#if UINTPTR_MAX == 0xffffffff - uint32_t padding; // Increase size to a multiple of 8. -#endif -}; - -upb_EnumDef* _upb_EnumDef_At(const upb_EnumDef* e, int i) { - return (upb_EnumDef*)&e[i]; -} - -const upb_MiniTableEnum* _upb_EnumDef_MiniTable(const upb_EnumDef* e) { - return e->layout; -} - -bool _upb_EnumDef_Insert(upb_EnumDef* e, upb_EnumValueDef* v, upb_Arena* a) { - const char* name = upb_EnumValueDef_Name(v); - const upb_value val = upb_value_constptr(v); - bool ok = upb_strtable_insert(&e->ntoi, name, strlen(name), val, a); - if (!ok) return false; - - // Multiple enumerators can have the same number, first one wins. - const int number = upb_EnumValueDef_Number(v); - if (!upb_inttable_lookup(&e->iton, number, NULL)) { - return upb_inttable_insert(&e->iton, number, val, a); - } - return true; -} - -const UPB_DESC(EnumOptions) * upb_EnumDef_Options(const upb_EnumDef* e) { - return e->opts; -} - -bool upb_EnumDef_HasOptions(const upb_EnumDef* e) { - return e->opts != (void*)kUpbDefOptDefault; -} - -const UPB_DESC(FeatureSet) * - upb_EnumDef_ResolvedFeatures(const upb_EnumDef* e) { - return e->resolved_features; -} - -const char* upb_EnumDef_FullName(const upb_EnumDef* e) { return e->full_name; } - -const char* upb_EnumDef_Name(const upb_EnumDef* e) { - return _upb_DefBuilder_FullToShort(e->full_name); -} - -const upb_FileDef* upb_EnumDef_File(const upb_EnumDef* e) { return e->file; } - -const upb_MessageDef* upb_EnumDef_ContainingType(const upb_EnumDef* e) { - return e->containing_type; -} - -int32_t upb_EnumDef_Default(const upb_EnumDef* e) { - UPB_ASSERT(upb_EnumDef_FindValueByNumber(e, e->defaultval)); - return e->defaultval; -} - -int upb_EnumDef_ReservedRangeCount(const upb_EnumDef* e) { - return e->res_range_count; -} - -const upb_EnumReservedRange* upb_EnumDef_ReservedRange(const upb_EnumDef* e, - int i) { - UPB_ASSERT(0 <= i && i < e->res_range_count); - return _upb_EnumReservedRange_At(e->res_ranges, i); -} - -int upb_EnumDef_ReservedNameCount(const upb_EnumDef* e) { - return e->res_name_count; -} - -upb_StringView upb_EnumDef_ReservedName(const upb_EnumDef* e, int i) { - UPB_ASSERT(0 <= i && i < e->res_name_count); - return e->res_names[i]; -} - -int upb_EnumDef_ValueCount(const upb_EnumDef* e) { return e->value_count; } +int upb_EnumDef_ValueCount(const upb_EnumDef* e) { return e->value_count; } const upb_EnumValueDef* upb_EnumDef_FindValueByName(const upb_EnumDef* e, const char* name) { @@ -15674,214 +15344,544 @@ static void fastdecode_docopy(upb_Decoder* d, const char* ptr, uint32_t size, #define s_VALIDATE true #define b_VALIDATE false -#define F(card, tagbytes, type) \ - UPB_NOINLINE \ - const char* upb_c##card##type##_##tagbytes##bt(UPB_PARSE_PARAMS) { \ - FASTDECODE_COPYSTRING(d, ptr, msg, table, hasbits, data, tagbytes, \ - CARD_##card, type##_VALIDATE); \ - } \ - const char* upb_p##card##type##_##tagbytes##bt(UPB_PARSE_PARAMS) { \ - FASTDECODE_STRING(d, ptr, msg, table, hasbits, data, tagbytes, \ - CARD_##card, upb_c##card##type##_##tagbytes##bt, \ - type##_VALIDATE); \ +#define F(card, tagbytes, type) \ + UPB_NOINLINE \ + const char* upb_c##card##type##_##tagbytes##bt(UPB_PARSE_PARAMS) { \ + FASTDECODE_COPYSTRING(d, ptr, msg, table, hasbits, data, tagbytes, \ + CARD_##card, type##_VALIDATE); \ + } \ + const char* upb_p##card##type##_##tagbytes##bt(UPB_PARSE_PARAMS) { \ + FASTDECODE_STRING(d, ptr, msg, table, hasbits, data, tagbytes, \ + CARD_##card, upb_c##card##type##_##tagbytes##bt, \ + type##_VALIDATE); \ + } + +#define UTF8(card, tagbytes) \ + F(card, tagbytes, s) \ + F(card, tagbytes, b) + +#define TAGBYTES(card) \ + UTF8(card, 1) \ + UTF8(card, 2) + +TAGBYTES(s) +TAGBYTES(o) +TAGBYTES(r) + +#undef s_VALIDATE +#undef b_VALIDATE +#undef F +#undef TAGBYTES +#undef FASTDECODE_LONGSTRING +#undef FASTDECODE_COPYSTRING +#undef FASTDECODE_STRING + +/* message fields *************************************************************/ + +UPB_INLINE +upb_Message* decode_newmsg_ceil(upb_Decoder* d, const upb_MiniTable* m, + int msg_ceil_bytes) { + size_t size = m->UPB_PRIVATE(size) + sizeof(upb_Message_Internal); + char* msg_data; + if (UPB_LIKELY(msg_ceil_bytes > 0 && + UPB_PRIVATE(_upb_ArenaHas)(&d->arena) >= msg_ceil_bytes)) { + UPB_ASSERT(size <= (size_t)msg_ceil_bytes); + msg_data = d->arena.UPB_PRIVATE(ptr); + d->arena.UPB_PRIVATE(ptr) += size; + UPB_UNPOISON_MEMORY_REGION(msg_data, msg_ceil_bytes); + memset(msg_data, 0, msg_ceil_bytes); + UPB_POISON_MEMORY_REGION(msg_data + size, msg_ceil_bytes - size); + } else { + msg_data = (char*)upb_Arena_Malloc(&d->arena, size); + memset(msg_data, 0, size); + } + return msg_data + sizeof(upb_Message_Internal); +} + +typedef struct { + intptr_t table; + upb_Message* msg; +} fastdecode_submsgdata; + +UPB_FORCEINLINE +static const char* fastdecode_tosubmsg(upb_EpsCopyInputStream* e, + const char* ptr, void* ctx) { + upb_Decoder* d = (upb_Decoder*)e; + fastdecode_submsgdata* submsg = ctx; + ptr = fastdecode_dispatch(d, ptr, submsg->msg, submsg->table, 0, 0); + UPB_ASSUME(ptr != NULL); + return ptr; +} + +#define FASTDECODE_SUBMSG(d, ptr, msg, table, hasbits, data, tagbytes, \ + msg_ceil_bytes, card) \ + \ + if (UPB_UNLIKELY(!fastdecode_checktag(data, tagbytes))) { \ + RETURN_GENERIC("submessage field tag mismatch\n"); \ + } \ + \ + if (--d->depth == 0) { \ + _upb_FastDecoder_ErrorJmp(d, kUpb_DecodeStatus_MaxDepthExceeded); \ + } \ + \ + upb_Message** dst; \ + uint32_t submsg_idx = (data >> 16) & 0xff; \ + const upb_MiniTable* tablep = decode_totablep(table); \ + const upb_MiniTable* subtablep = upb_MiniTableSub_Message( \ + *UPB_PRIVATE(_upb_MiniTable_GetSubByIndex)(tablep, submsg_idx)); \ + fastdecode_submsgdata submsg = {decode_totable(subtablep)}; \ + fastdecode_arr farr; \ + \ + if (subtablep->UPB_PRIVATE(table_mask) == (uint8_t)-1) { \ + d->depth++; \ + RETURN_GENERIC("submessage doesn't have fast tables."); \ + } \ + \ + dst = fastdecode_getfield(d, ptr, msg, &data, &hasbits, &farr, \ + sizeof(upb_Message*), card); \ + \ + if (card == CARD_s) { \ + *(uint32_t*)msg |= hasbits; \ + hasbits = 0; \ + } \ + \ + again: \ + if (card == CARD_r) { \ + dst = fastdecode_resizearr(d, dst, &farr, sizeof(upb_Message*)); \ + } \ + \ + submsg.msg = *dst; \ + \ + if (card == CARD_r || UPB_LIKELY(!submsg.msg)) { \ + *dst = submsg.msg = decode_newmsg_ceil(d, subtablep, msg_ceil_bytes); \ + } \ + \ + ptr += tagbytes; \ + ptr = fastdecode_delimited(d, ptr, fastdecode_tosubmsg, &submsg); \ + \ + if (UPB_UNLIKELY(ptr == NULL || d->end_group != DECODE_NOGROUP)) { \ + _upb_FastDecoder_ErrorJmp(d, kUpb_DecodeStatus_Malformed); \ + } \ + \ + if (card == CARD_r) { \ + fastdecode_nextret ret = fastdecode_nextrepeated( \ + d, dst, &ptr, &farr, data, tagbytes, sizeof(upb_Message*)); \ + switch (ret.next) { \ + case FD_NEXT_SAMEFIELD: \ + dst = ret.dst; \ + goto again; \ + case FD_NEXT_OTHERFIELD: \ + d->depth++; \ + data = ret.tag; \ + UPB_MUSTTAIL return _upb_FastDecoder_TagDispatch(UPB_PARSE_ARGS); \ + case FD_NEXT_ATLIMIT: \ + d->depth++; \ + return ptr; \ + } \ + } \ + \ + d->depth++; \ + UPB_MUSTTAIL return fastdecode_dispatch(UPB_PARSE_ARGS); + +#define F(card, tagbytes, size_ceil, ceil_arg) \ + const char* upb_p##card##m_##tagbytes##bt_max##size_ceil##b( \ + UPB_PARSE_PARAMS) { \ + FASTDECODE_SUBMSG(d, ptr, msg, table, hasbits, data, tagbytes, ceil_arg, \ + CARD_##card); \ + } + +#define SIZES(card, tagbytes) \ + F(card, tagbytes, 64, 64) \ + F(card, tagbytes, 128, 128) \ + F(card, tagbytes, 192, 192) \ + F(card, tagbytes, 256, 256) \ + F(card, tagbytes, max, -1) + +#define TAGBYTES(card) \ + SIZES(card, 1) \ + SIZES(card, 2) + +TAGBYTES(s) +TAGBYTES(o) +TAGBYTES(r) + +#undef TAGBYTES +#undef SIZES +#undef F +#undef FASTDECODE_SUBMSG + +#endif /* UPB_FASTTABLE */ + + +#include +#include + + +// Must be last. + +UPB_NOINLINE UPB_PRIVATE(_upb_WireReader_LongVarint) + UPB_PRIVATE(_upb_WireReader_ReadLongVarint)(const char* ptr, uint64_t val) { + UPB_PRIVATE(_upb_WireReader_LongVarint) ret = {NULL, 0}; + uint64_t byte; + int i; + for (i = 1; i < 10; i++) { + byte = (uint8_t)ptr[i]; + val += (byte - 1) << (i * 7); + if (!(byte & 0x80)) { + ret.ptr = ptr + i + 1; + ret.val = val; + return ret; + } + } + return ret; +} + +const char* UPB_PRIVATE(_upb_WireReader_SkipGroup)( + const char* ptr, uint32_t tag, int depth_limit, + upb_EpsCopyInputStream* stream) { + if (--depth_limit == 0) return NULL; + uint32_t end_group_tag = (tag & ~7ULL) | kUpb_WireType_EndGroup; + while (!upb_EpsCopyInputStream_IsDone(stream, &ptr)) { + uint32_t tag; + ptr = upb_WireReader_ReadTag(ptr, &tag); + if (!ptr) return NULL; + if (tag == end_group_tag) return ptr; + ptr = _upb_WireReader_SkipValue(ptr, tag, depth_limit, stream); + if (!ptr) return NULL; + } + return ptr; +} + + +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, +}; + + +#include +#include +#include + + +// Must be last. + +typedef struct { + uint64_t present_values_mask; + uint32_t last_written_value; +} upb_MtDataEncoderInternal_EnumState; + +typedef struct { + uint64_t msg_modifiers; + uint32_t last_field_num; + enum { + kUpb_OneofState_NotStarted, + kUpb_OneofState_StartedOneof, + kUpb_OneofState_EmittedOneofField, + } oneof_state; +} upb_MtDataEncoderInternal_MsgState; + +typedef struct { + char* buf_start; // Only for checking kUpb_MtDataEncoder_MinSize. + union { + upb_MtDataEncoderInternal_EnumState enum_state; + upb_MtDataEncoderInternal_MsgState msg_state; + } state; +} upb_MtDataEncoderInternal; + +static upb_MtDataEncoderInternal* upb_MtDataEncoder_GetInternal( + upb_MtDataEncoder* e, char* buf_start) { + UPB_ASSERT(sizeof(upb_MtDataEncoderInternal) <= sizeof(e->internal)); + upb_MtDataEncoderInternal* ret = (upb_MtDataEncoderInternal*)e->internal; + ret->buf_start = buf_start; + return ret; +} + +static char* upb_MtDataEncoder_PutRaw(upb_MtDataEncoder* e, char* ptr, + char ch) { + upb_MtDataEncoderInternal* in = (upb_MtDataEncoderInternal*)e->internal; + UPB_ASSERT(ptr - in->buf_start < kUpb_MtDataEncoder_MinSize); + if (ptr == e->end) return NULL; + *ptr++ = ch; + return ptr; +} + +static char* upb_MtDataEncoder_Put(upb_MtDataEncoder* e, char* ptr, char ch) { + return upb_MtDataEncoder_PutRaw(e, ptr, _upb_ToBase92(ch)); +} + +static char* upb_MtDataEncoder_PutBase92Varint(upb_MtDataEncoder* e, char* ptr, + uint32_t val, int min, int max) { + int shift = upb_Log2Ceiling(_upb_FromBase92(max) - _upb_FromBase92(min) + 1); + UPB_ASSERT(shift <= 6); + uint32_t mask = (1 << shift) - 1; + do { + uint32_t bits = val & mask; + ptr = upb_MtDataEncoder_Put(e, ptr, bits + _upb_FromBase92(min)); + if (!ptr) return NULL; + val >>= shift; + } while (val); + return ptr; +} + +char* upb_MtDataEncoder_PutModifier(upb_MtDataEncoder* e, char* ptr, + uint64_t mod) { + if (mod) { + ptr = upb_MtDataEncoder_PutBase92Varint(e, ptr, mod, + kUpb_EncodedValue_MinModifier, + kUpb_EncodedValue_MaxModifier); + } + return ptr; +} + +char* upb_MtDataEncoder_EncodeExtension(upb_MtDataEncoder* e, char* ptr, + upb_FieldType type, uint32_t field_num, + uint64_t field_mod) { + upb_MtDataEncoderInternal* in = upb_MtDataEncoder_GetInternal(e, ptr); + in->state.msg_state.msg_modifiers = 0; + in->state.msg_state.last_field_num = 0; + in->state.msg_state.oneof_state = kUpb_OneofState_NotStarted; + + ptr = upb_MtDataEncoder_PutRaw(e, ptr, kUpb_EncodedVersion_ExtensionV1); + if (!ptr) return NULL; + + return upb_MtDataEncoder_PutField(e, ptr, type, field_num, field_mod); +} + +char* upb_MtDataEncoder_EncodeMap(upb_MtDataEncoder* e, char* ptr, + upb_FieldType key_type, + upb_FieldType value_type, uint64_t key_mod, + uint64_t value_mod) { + upb_MtDataEncoderInternal* in = upb_MtDataEncoder_GetInternal(e, ptr); + in->state.msg_state.msg_modifiers = 0; + in->state.msg_state.last_field_num = 0; + in->state.msg_state.oneof_state = kUpb_OneofState_NotStarted; + + ptr = upb_MtDataEncoder_PutRaw(e, ptr, kUpb_EncodedVersion_MapV1); + if (!ptr) return NULL; + + ptr = upb_MtDataEncoder_PutField(e, ptr, key_type, 1, key_mod); + if (!ptr) return NULL; + + return upb_MtDataEncoder_PutField(e, ptr, value_type, 2, value_mod); +} + +char* upb_MtDataEncoder_EncodeMessageSet(upb_MtDataEncoder* e, char* ptr) { + (void)upb_MtDataEncoder_GetInternal(e, ptr); + return upb_MtDataEncoder_PutRaw(e, ptr, kUpb_EncodedVersion_MessageSetV1); +} + +char* upb_MtDataEncoder_StartMessage(upb_MtDataEncoder* e, char* ptr, + uint64_t msg_mod) { + upb_MtDataEncoderInternal* in = upb_MtDataEncoder_GetInternal(e, ptr); + in->state.msg_state.msg_modifiers = msg_mod; + in->state.msg_state.last_field_num = 0; + in->state.msg_state.oneof_state = kUpb_OneofState_NotStarted; + + ptr = upb_MtDataEncoder_PutRaw(e, ptr, kUpb_EncodedVersion_MessageV1); + if (!ptr) return NULL; + + return upb_MtDataEncoder_PutModifier(e, ptr, msg_mod); +} + +static char* _upb_MtDataEncoder_MaybePutFieldSkip(upb_MtDataEncoder* e, + char* ptr, + uint32_t field_num) { + upb_MtDataEncoderInternal* in = (upb_MtDataEncoderInternal*)e->internal; + if (field_num <= in->state.msg_state.last_field_num) return NULL; + if (in->state.msg_state.last_field_num + 1 != field_num) { + // Put skip. + UPB_ASSERT(field_num > in->state.msg_state.last_field_num); + uint32_t skip = field_num - in->state.msg_state.last_field_num; + ptr = upb_MtDataEncoder_PutBase92Varint( + e, ptr, skip, kUpb_EncodedValue_MinSkip, kUpb_EncodedValue_MaxSkip); + if (!ptr) return NULL; + } + in->state.msg_state.last_field_num = field_num; + return ptr; +} + +static char* _upb_MtDataEncoder_PutFieldType(upb_MtDataEncoder* e, char* ptr, + upb_FieldType type, + uint64_t field_mod) { + static const char kUpb_TypeToEncoded[] = { + [kUpb_FieldType_Double] = kUpb_EncodedType_Double, + [kUpb_FieldType_Float] = kUpb_EncodedType_Float, + [kUpb_FieldType_Int64] = kUpb_EncodedType_Int64, + [kUpb_FieldType_UInt64] = kUpb_EncodedType_UInt64, + [kUpb_FieldType_Int32] = kUpb_EncodedType_Int32, + [kUpb_FieldType_Fixed64] = kUpb_EncodedType_Fixed64, + [kUpb_FieldType_Fixed32] = kUpb_EncodedType_Fixed32, + [kUpb_FieldType_Bool] = kUpb_EncodedType_Bool, + [kUpb_FieldType_String] = kUpb_EncodedType_String, + [kUpb_FieldType_Group] = kUpb_EncodedType_Group, + [kUpb_FieldType_Message] = kUpb_EncodedType_Message, + [kUpb_FieldType_Bytes] = kUpb_EncodedType_Bytes, + [kUpb_FieldType_UInt32] = kUpb_EncodedType_UInt32, + [kUpb_FieldType_Enum] = kUpb_EncodedType_OpenEnum, + [kUpb_FieldType_SFixed32] = kUpb_EncodedType_SFixed32, + [kUpb_FieldType_SFixed64] = kUpb_EncodedType_SFixed64, + [kUpb_FieldType_SInt32] = kUpb_EncodedType_SInt32, + [kUpb_FieldType_SInt64] = kUpb_EncodedType_SInt64, + }; + + int encoded_type = kUpb_TypeToEncoded[type]; + + if (field_mod & kUpb_FieldModifier_IsClosedEnum) { + UPB_ASSERT(type == kUpb_FieldType_Enum); + encoded_type = kUpb_EncodedType_ClosedEnum; + } + + if (field_mod & kUpb_FieldModifier_IsRepeated) { + // Repeated fields shift the type number up (unlike other modifiers which + // are bit flags). + encoded_type += kUpb_EncodedType_RepeatedBase; + } + + return upb_MtDataEncoder_Put(e, ptr, encoded_type); +} + +static char* _upb_MtDataEncoder_MaybePutModifiers(upb_MtDataEncoder* e, + char* ptr, upb_FieldType type, + uint64_t field_mod) { + upb_MtDataEncoderInternal* in = (upb_MtDataEncoderInternal*)e->internal; + uint32_t encoded_modifiers = 0; + if ((field_mod & kUpb_FieldModifier_IsRepeated) && + upb_FieldType_IsPackable(type)) { + bool field_is_packed = field_mod & kUpb_FieldModifier_IsPacked; + bool default_is_packed = in->state.msg_state.msg_modifiers & + kUpb_MessageModifier_DefaultIsPacked; + if (field_is_packed != default_is_packed) { + encoded_modifiers |= kUpb_EncodedFieldModifier_FlipPacked; + } + } + + if (type == kUpb_FieldType_String) { + bool field_validates_utf8 = field_mod & kUpb_FieldModifier_ValidateUtf8; + bool message_validates_utf8 = + in->state.msg_state.msg_modifiers & kUpb_MessageModifier_ValidateUtf8; + if (field_validates_utf8 != message_validates_utf8) { + // Old binaries do not recognize the field modifier. We need the failure + // mode to be too lax rather than too strict. Our caller should have + // handled this (see _upb_MessageDef_ValidateUtf8()). + assert(!message_validates_utf8); + encoded_modifiers |= kUpb_EncodedFieldModifier_FlipValidateUtf8; + } + } + + if (field_mod & kUpb_FieldModifier_IsProto3Singular) { + encoded_modifiers |= kUpb_EncodedFieldModifier_IsProto3Singular; + } + + if (field_mod & kUpb_FieldModifier_IsRequired) { + encoded_modifiers |= kUpb_EncodedFieldModifier_IsRequired; } -#define UTF8(card, tagbytes) \ - F(card, tagbytes, s) \ - F(card, tagbytes, b) + return upb_MtDataEncoder_PutModifier(e, ptr, encoded_modifiers); +} -#define TAGBYTES(card) \ - UTF8(card, 1) \ - UTF8(card, 2) +char* upb_MtDataEncoder_PutField(upb_MtDataEncoder* e, char* ptr, + upb_FieldType type, uint32_t field_num, + uint64_t field_mod) { + upb_MtDataEncoder_GetInternal(e, ptr); -TAGBYTES(s) -TAGBYTES(o) -TAGBYTES(r) + ptr = _upb_MtDataEncoder_MaybePutFieldSkip(e, ptr, field_num); + if (!ptr) return NULL; -#undef s_VALIDATE -#undef b_VALIDATE -#undef F -#undef TAGBYTES -#undef FASTDECODE_LONGSTRING -#undef FASTDECODE_COPYSTRING -#undef FASTDECODE_STRING + ptr = _upb_MtDataEncoder_PutFieldType(e, ptr, type, field_mod); + if (!ptr) return NULL; -/* message fields *************************************************************/ + return _upb_MtDataEncoder_MaybePutModifiers(e, ptr, type, field_mod); +} -UPB_INLINE -upb_Message* decode_newmsg_ceil(upb_Decoder* d, const upb_MiniTable* m, - int msg_ceil_bytes) { - size_t size = m->UPB_PRIVATE(size) + sizeof(upb_Message_Internal); - char* msg_data; - if (UPB_LIKELY(msg_ceil_bytes > 0 && - UPB_PRIVATE(_upb_ArenaHas)(&d->arena) >= msg_ceil_bytes)) { - UPB_ASSERT(size <= (size_t)msg_ceil_bytes); - msg_data = d->arena.UPB_PRIVATE(ptr); - d->arena.UPB_PRIVATE(ptr) += size; - UPB_UNPOISON_MEMORY_REGION(msg_data, msg_ceil_bytes); - memset(msg_data, 0, msg_ceil_bytes); - UPB_POISON_MEMORY_REGION(msg_data + size, msg_ceil_bytes - size); +char* upb_MtDataEncoder_StartOneof(upb_MtDataEncoder* e, char* ptr) { + upb_MtDataEncoderInternal* in = upb_MtDataEncoder_GetInternal(e, ptr); + if (in->state.msg_state.oneof_state == kUpb_OneofState_NotStarted) { + ptr = upb_MtDataEncoder_Put(e, ptr, _upb_FromBase92(kUpb_EncodedValue_End)); } else { - msg_data = (char*)upb_Arena_Malloc(&d->arena, size); - memset(msg_data, 0, size); + ptr = upb_MtDataEncoder_Put( + e, ptr, _upb_FromBase92(kUpb_EncodedValue_OneofSeparator)); } - return msg_data + sizeof(upb_Message_Internal); -} - -typedef struct { - intptr_t table; - upb_Message* msg; -} fastdecode_submsgdata; - -UPB_FORCEINLINE -static const char* fastdecode_tosubmsg(upb_EpsCopyInputStream* e, - const char* ptr, void* ctx) { - upb_Decoder* d = (upb_Decoder*)e; - fastdecode_submsgdata* submsg = ctx; - ptr = fastdecode_dispatch(d, ptr, submsg->msg, submsg->table, 0, 0); - UPB_ASSUME(ptr != NULL); + in->state.msg_state.oneof_state = kUpb_OneofState_StartedOneof; return ptr; } -#define FASTDECODE_SUBMSG(d, ptr, msg, table, hasbits, data, tagbytes, \ - msg_ceil_bytes, card) \ - \ - if (UPB_UNLIKELY(!fastdecode_checktag(data, tagbytes))) { \ - RETURN_GENERIC("submessage field tag mismatch\n"); \ - } \ - \ - if (--d->depth == 0) { \ - _upb_FastDecoder_ErrorJmp(d, kUpb_DecodeStatus_MaxDepthExceeded); \ - } \ - \ - upb_Message** dst; \ - uint32_t submsg_idx = (data >> 16) & 0xff; \ - const upb_MiniTable* tablep = decode_totablep(table); \ - const upb_MiniTable* subtablep = upb_MiniTableSub_Message( \ - *UPB_PRIVATE(_upb_MiniTable_GetSubByIndex)(tablep, submsg_idx)); \ - fastdecode_submsgdata submsg = {decode_totable(subtablep)}; \ - fastdecode_arr farr; \ - \ - if (subtablep->UPB_PRIVATE(table_mask) == (uint8_t)-1) { \ - d->depth++; \ - RETURN_GENERIC("submessage doesn't have fast tables."); \ - } \ - \ - dst = fastdecode_getfield(d, ptr, msg, &data, &hasbits, &farr, \ - sizeof(upb_Message*), card); \ - \ - if (card == CARD_s) { \ - *(uint32_t*)msg |= hasbits; \ - hasbits = 0; \ - } \ - \ - again: \ - if (card == CARD_r) { \ - dst = fastdecode_resizearr(d, dst, &farr, sizeof(upb_Message*)); \ - } \ - \ - submsg.msg = *dst; \ - \ - if (card == CARD_r || UPB_LIKELY(!submsg.msg)) { \ - *dst = submsg.msg = decode_newmsg_ceil(d, subtablep, msg_ceil_bytes); \ - } \ - \ - ptr += tagbytes; \ - ptr = fastdecode_delimited(d, ptr, fastdecode_tosubmsg, &submsg); \ - \ - if (UPB_UNLIKELY(ptr == NULL || d->end_group != DECODE_NOGROUP)) { \ - _upb_FastDecoder_ErrorJmp(d, kUpb_DecodeStatus_Malformed); \ - } \ - \ - if (card == CARD_r) { \ - fastdecode_nextret ret = fastdecode_nextrepeated( \ - d, dst, &ptr, &farr, data, tagbytes, sizeof(upb_Message*)); \ - switch (ret.next) { \ - case FD_NEXT_SAMEFIELD: \ - dst = ret.dst; \ - goto again; \ - case FD_NEXT_OTHERFIELD: \ - d->depth++; \ - data = ret.tag; \ - UPB_MUSTTAIL return _upb_FastDecoder_TagDispatch(UPB_PARSE_ARGS); \ - case FD_NEXT_ATLIMIT: \ - d->depth++; \ - return ptr; \ - } \ - } \ - \ - d->depth++; \ - UPB_MUSTTAIL return fastdecode_dispatch(UPB_PARSE_ARGS); - -#define F(card, tagbytes, size_ceil, ceil_arg) \ - const char* upb_p##card##m_##tagbytes##bt_max##size_ceil##b( \ - UPB_PARSE_PARAMS) { \ - FASTDECODE_SUBMSG(d, ptr, msg, table, hasbits, data, tagbytes, ceil_arg, \ - CARD_##card); \ +char* upb_MtDataEncoder_PutOneofField(upb_MtDataEncoder* e, char* ptr, + uint32_t field_num) { + upb_MtDataEncoderInternal* in = upb_MtDataEncoder_GetInternal(e, ptr); + if (in->state.msg_state.oneof_state == kUpb_OneofState_EmittedOneofField) { + ptr = upb_MtDataEncoder_Put( + e, ptr, _upb_FromBase92(kUpb_EncodedValue_FieldSeparator)); + if (!ptr) return NULL; } + ptr = upb_MtDataEncoder_PutBase92Varint(e, ptr, field_num, _upb_ToBase92(0), + _upb_ToBase92(63)); + in->state.msg_state.oneof_state = kUpb_OneofState_EmittedOneofField; + return ptr; +} -#define SIZES(card, tagbytes) \ - F(card, tagbytes, 64, 64) \ - F(card, tagbytes, 128, 128) \ - F(card, tagbytes, 192, 192) \ - F(card, tagbytes, 256, 256) \ - F(card, tagbytes, max, -1) - -#define TAGBYTES(card) \ - SIZES(card, 1) \ - SIZES(card, 2) - -TAGBYTES(s) -TAGBYTES(o) -TAGBYTES(r) - -#undef TAGBYTES -#undef SIZES -#undef F -#undef FASTDECODE_SUBMSG - -#endif /* UPB_FASTTABLE */ - - -#include -#include +char* upb_MtDataEncoder_StartEnum(upb_MtDataEncoder* e, char* ptr) { + upb_MtDataEncoderInternal* in = upb_MtDataEncoder_GetInternal(e, ptr); + in->state.enum_state.present_values_mask = 0; + in->state.enum_state.last_written_value = 0; + return upb_MtDataEncoder_PutRaw(e, ptr, kUpb_EncodedVersion_EnumV1); +} -// Must be last. +static char* upb_MtDataEncoder_FlushDenseEnumMask(upb_MtDataEncoder* e, + char* ptr) { + upb_MtDataEncoderInternal* in = (upb_MtDataEncoderInternal*)e->internal; + ptr = upb_MtDataEncoder_Put(e, ptr, in->state.enum_state.present_values_mask); + in->state.enum_state.present_values_mask = 0; + in->state.enum_state.last_written_value += 5; + return ptr; +} -UPB_NOINLINE UPB_PRIVATE(_upb_WireReader_LongVarint) - UPB_PRIVATE(_upb_WireReader_ReadLongVarint)(const char* ptr, uint64_t val) { - UPB_PRIVATE(_upb_WireReader_LongVarint) ret = {NULL, 0}; - uint64_t byte; - int i; - for (i = 1; i < 10; i++) { - byte = (uint8_t)ptr[i]; - val += (byte - 1) << (i * 7); - if (!(byte & 0x80)) { - ret.ptr = ptr + i + 1; - ret.val = val; - return ret; +char* upb_MtDataEncoder_PutEnumValue(upb_MtDataEncoder* e, char* ptr, + uint32_t val) { + // TODO: optimize this encoding. + upb_MtDataEncoderInternal* in = upb_MtDataEncoder_GetInternal(e, ptr); + UPB_ASSERT(val >= in->state.enum_state.last_written_value); + uint32_t delta = val - in->state.enum_state.last_written_value; + if (delta >= 5 && in->state.enum_state.present_values_mask) { + ptr = upb_MtDataEncoder_FlushDenseEnumMask(e, ptr); + if (!ptr) { + return NULL; } + delta -= 5; } - return ret; -} -const char* UPB_PRIVATE(_upb_WireReader_SkipGroup)( - const char* ptr, uint32_t tag, int depth_limit, - upb_EpsCopyInputStream* stream) { - if (--depth_limit == 0) return NULL; - uint32_t end_group_tag = (tag & ~7ULL) | kUpb_WireType_EndGroup; - while (!upb_EpsCopyInputStream_IsDone(stream, &ptr)) { - uint32_t tag; - ptr = upb_WireReader_ReadTag(ptr, &tag); - if (!ptr) return NULL; - if (tag == end_group_tag) return ptr; - ptr = _upb_WireReader_SkipValue(ptr, tag, depth_limit, stream); - if (!ptr) return NULL; + if (delta >= 5) { + ptr = upb_MtDataEncoder_PutBase92Varint( + e, ptr, delta, kUpb_EncodedValue_MinSkip, kUpb_EncodedValue_MaxSkip); + in->state.enum_state.last_written_value += delta; + delta = 0; } + + UPB_ASSERT((in->state.enum_state.present_values_mask >> delta) == 0); + in->state.enum_state.present_values_mask |= 1ULL << delta; return ptr; } +char* upb_MtDataEncoder_EndEnum(upb_MtDataEncoder* e, char* ptr) { + upb_MtDataEncoderInternal* in = upb_MtDataEncoder_GetInternal(e, ptr); + if (!in->state.enum_state.present_values_mask) return ptr; + return upb_MtDataEncoder_FlushDenseEnumMask(e, ptr); +} + #include diff --git a/php/ext/google/protobuf/php-upb.h b/php/ext/google/protobuf/php-upb.h index 67947df0c9f9b..663a94132d2e1 100644 --- a/php/ext/google/protobuf/php-upb.h +++ b/php/ext/google/protobuf/php-upb.h @@ -12926,89 +12926,6 @@ typedef enum { #endif // UPB_MINI_DESCRIPTOR_INTERNAL_MODIFIERS_H_ -#ifndef UPB_MINI_DESCRIPTOR_INTERNAL_ENCODE_H_ -#define UPB_MINI_DESCRIPTOR_INTERNAL_ENCODE_H_ - -#include - - -// Must be last. - -// If the input buffer has at least this many bytes available, the encoder call -// is guaranteed to succeed (as long as field number order is maintained). -#define kUpb_MtDataEncoder_MinSize 16 - -typedef struct { - char* end; // Limit of the buffer passed as a parameter. - // Aliased to internal-only members in .cc. - char internal[32]; -} upb_MtDataEncoder; - -#ifdef __cplusplus -extern "C" { -#endif - -// Encodes field/oneof information for a given message. The sequence of calls -// should look like: -// -// upb_MtDataEncoder e; -// char buf[256]; -// char* ptr = buf; -// e.end = ptr + sizeof(buf); -// unit64_t msg_mod = ...; // bitwise & of kUpb_MessageModifiers or zero -// ptr = upb_MtDataEncoder_StartMessage(&e, ptr, msg_mod); -// // Fields *must* be in field number order. -// ptr = upb_MtDataEncoder_PutField(&e, ptr, ...); -// ptr = upb_MtDataEncoder_PutField(&e, ptr, ...); -// ptr = upb_MtDataEncoder_PutField(&e, ptr, ...); -// -// // If oneofs are present. Oneofs must be encoded after regular fields. -// ptr = upb_MiniTable_StartOneof(&e, ptr) -// ptr = upb_MiniTable_PutOneofField(&e, ptr, ...); -// ptr = upb_MiniTable_PutOneofField(&e, ptr, ...); -// -// ptr = upb_MiniTable_StartOneof(&e, ptr); -// ptr = upb_MiniTable_PutOneofField(&e, ptr, ...); -// ptr = upb_MiniTable_PutOneofField(&e, ptr, ...); -// -// Oneofs must be encoded after all regular fields. -char* upb_MtDataEncoder_StartMessage(upb_MtDataEncoder* e, char* ptr, - uint64_t msg_mod); -char* upb_MtDataEncoder_PutField(upb_MtDataEncoder* e, char* ptr, - upb_FieldType type, uint32_t field_num, - uint64_t field_mod); -char* upb_MtDataEncoder_StartOneof(upb_MtDataEncoder* e, char* ptr); -char* upb_MtDataEncoder_PutOneofField(upb_MtDataEncoder* e, char* ptr, - uint32_t field_num); - -// Encodes the set of values for a given enum. The values must be given in -// order (after casting to uint32_t), and repeats are not allowed. -char* upb_MtDataEncoder_StartEnum(upb_MtDataEncoder* e, char* ptr); -char* upb_MtDataEncoder_PutEnumValue(upb_MtDataEncoder* e, char* ptr, - uint32_t val); -char* upb_MtDataEncoder_EndEnum(upb_MtDataEncoder* e, char* ptr); - -// Encodes an entire mini descriptor for an extension. -char* upb_MtDataEncoder_EncodeExtension(upb_MtDataEncoder* e, char* ptr, - upb_FieldType type, uint32_t field_num, - uint64_t field_mod); - -// Encodes an entire mini descriptor for a map. -char* upb_MtDataEncoder_EncodeMap(upb_MtDataEncoder* e, char* ptr, - upb_FieldType key_type, - upb_FieldType value_type, uint64_t key_mod, - uint64_t value_mod); - -// Encodes an entire mini descriptor for a message set. -char* upb_MtDataEncoder_EncodeMessageSet(upb_MtDataEncoder* e, char* ptr); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - - -#endif /* UPB_MINI_DESCRIPTOR_INTERNAL_ENCODE_H_ */ - #ifndef UPB_MINI_TABLE_COMPAT_H_ #define UPB_MINI_TABLE_COMPAT_H_ @@ -13410,6 +13327,89 @@ upb_ServiceDef* _upb_ServiceDefs_New(upb_DefBuilder* ctx, int n, #define UPB_REFLECTION_DESC_STATE_INTERNAL_H_ +#ifndef UPB_MINI_DESCRIPTOR_INTERNAL_ENCODE_H_ +#define UPB_MINI_DESCRIPTOR_INTERNAL_ENCODE_H_ + +#include + + +// Must be last. + +// If the input buffer has at least this many bytes available, the encoder call +// is guaranteed to succeed (as long as field number order is maintained). +#define kUpb_MtDataEncoder_MinSize 16 + +typedef struct { + char* end; // Limit of the buffer passed as a parameter. + // Aliased to internal-only members in .cc. + char internal[32]; +} upb_MtDataEncoder; + +#ifdef __cplusplus +extern "C" { +#endif + +// Encodes field/oneof information for a given message. The sequence of calls +// should look like: +// +// upb_MtDataEncoder e; +// char buf[256]; +// char* ptr = buf; +// e.end = ptr + sizeof(buf); +// unit64_t msg_mod = ...; // bitwise & of kUpb_MessageModifiers or zero +// ptr = upb_MtDataEncoder_StartMessage(&e, ptr, msg_mod); +// // Fields *must* be in field number order. +// ptr = upb_MtDataEncoder_PutField(&e, ptr, ...); +// ptr = upb_MtDataEncoder_PutField(&e, ptr, ...); +// ptr = upb_MtDataEncoder_PutField(&e, ptr, ...); +// +// // If oneofs are present. Oneofs must be encoded after regular fields. +// ptr = upb_MiniTable_StartOneof(&e, ptr) +// ptr = upb_MiniTable_PutOneofField(&e, ptr, ...); +// ptr = upb_MiniTable_PutOneofField(&e, ptr, ...); +// +// ptr = upb_MiniTable_StartOneof(&e, ptr); +// ptr = upb_MiniTable_PutOneofField(&e, ptr, ...); +// ptr = upb_MiniTable_PutOneofField(&e, ptr, ...); +// +// Oneofs must be encoded after all regular fields. +char* upb_MtDataEncoder_StartMessage(upb_MtDataEncoder* e, char* ptr, + uint64_t msg_mod); +char* upb_MtDataEncoder_PutField(upb_MtDataEncoder* e, char* ptr, + upb_FieldType type, uint32_t field_num, + uint64_t field_mod); +char* upb_MtDataEncoder_StartOneof(upb_MtDataEncoder* e, char* ptr); +char* upb_MtDataEncoder_PutOneofField(upb_MtDataEncoder* e, char* ptr, + uint32_t field_num); + +// Encodes the set of values for a given enum. The values must be given in +// order (after casting to uint32_t), and repeats are not allowed. +char* upb_MtDataEncoder_StartEnum(upb_MtDataEncoder* e, char* ptr); +char* upb_MtDataEncoder_PutEnumValue(upb_MtDataEncoder* e, char* ptr, + uint32_t val); +char* upb_MtDataEncoder_EndEnum(upb_MtDataEncoder* e, char* ptr); + +// Encodes an entire mini descriptor for an extension. +char* upb_MtDataEncoder_EncodeExtension(upb_MtDataEncoder* e, char* ptr, + upb_FieldType type, uint32_t field_num, + uint64_t field_mod); + +// Encodes an entire mini descriptor for a map. +char* upb_MtDataEncoder_EncodeMap(upb_MtDataEncoder* e, char* ptr, + upb_FieldType key_type, + upb_FieldType value_type, uint64_t key_mod, + uint64_t value_mod); + +// Encodes an entire mini descriptor for a message set. +char* upb_MtDataEncoder_EncodeMessageSet(upb_MtDataEncoder* e, char* ptr); + +#ifdef __cplusplus +} /* extern "C" */ +#endif + + +#endif /* UPB_MINI_DESCRIPTOR_INTERNAL_ENCODE_H_ */ + // Must be last. // Manages the storage for mini descriptor strings as they are being encoded. diff --git a/ruby/ext/google/protobuf_c/ruby-upb.c b/ruby/ext/google/protobuf_c/ruby-upb.c index 3133ea760be85..eac3e83cee603 100644 --- a/ruby/ext/google/protobuf_c/ruby-upb.c +++ b/ruby/ext/google/protobuf_c/ruby-upb.c @@ -7542,1221 +7542,891 @@ bool upb_MiniTable_Link(upb_MiniTable* mt, const upb_MiniTable** sub_tables, } -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, -}; - - -#include #include #include +#include // Must be last. -typedef struct { - uint64_t present_values_mask; - uint32_t last_written_value; -} upb_MtDataEncoderInternal_EnumState; - -typedef struct { - uint64_t msg_modifiers; - uint32_t last_field_num; - enum { - kUpb_OneofState_NotStarted, - kUpb_OneofState_StartedOneof, - kUpb_OneofState_EmittedOneofField, - } oneof_state; -} upb_MtDataEncoderInternal_MsgState; +#define EXTREG_KEY_SIZE (sizeof(upb_MiniTable*) + sizeof(uint32_t)) -typedef struct { - char* buf_start; // Only for checking kUpb_MtDataEncoder_MinSize. - union { - upb_MtDataEncoderInternal_EnumState enum_state; - upb_MtDataEncoderInternal_MsgState msg_state; - } state; -} upb_MtDataEncoderInternal; +struct upb_ExtensionRegistry { + upb_Arena* arena; + upb_strtable exts; // Key is upb_MiniTable* concatenated with fieldnum. +}; -static upb_MtDataEncoderInternal* upb_MtDataEncoder_GetInternal( - upb_MtDataEncoder* e, char* buf_start) { - UPB_ASSERT(sizeof(upb_MtDataEncoderInternal) <= sizeof(e->internal)); - upb_MtDataEncoderInternal* ret = (upb_MtDataEncoderInternal*)e->internal; - ret->buf_start = buf_start; - return ret; +static void extreg_key(char* buf, const upb_MiniTable* l, uint32_t fieldnum) { + memcpy(buf, &l, sizeof(l)); + memcpy(buf + sizeof(l), &fieldnum, sizeof(fieldnum)); } -static char* upb_MtDataEncoder_PutRaw(upb_MtDataEncoder* e, char* ptr, - char ch) { - upb_MtDataEncoderInternal* in = (upb_MtDataEncoderInternal*)e->internal; - UPB_ASSERT(ptr - in->buf_start < kUpb_MtDataEncoder_MinSize); - if (ptr == e->end) return NULL; - *ptr++ = ch; - return ptr; +upb_ExtensionRegistry* upb_ExtensionRegistry_New(upb_Arena* arena) { + upb_ExtensionRegistry* r = upb_Arena_Malloc(arena, sizeof(*r)); + if (!r) return NULL; + r->arena = arena; + if (!upb_strtable_init(&r->exts, 8, arena)) return NULL; + return r; } -static char* upb_MtDataEncoder_Put(upb_MtDataEncoder* e, char* ptr, char ch) { - return upb_MtDataEncoder_PutRaw(e, ptr, _upb_ToBase92(ch)); +UPB_API bool upb_ExtensionRegistry_Add(upb_ExtensionRegistry* r, + const upb_MiniTableExtension* e) { + char buf[EXTREG_KEY_SIZE]; + extreg_key(buf, e->UPB_PRIVATE(extendee), upb_MiniTableExtension_Number(e)); + if (upb_strtable_lookup2(&r->exts, buf, EXTREG_KEY_SIZE, NULL)) return false; + return upb_strtable_insert(&r->exts, buf, EXTREG_KEY_SIZE, + upb_value_constptr(e), r->arena); } -static char* upb_MtDataEncoder_PutBase92Varint(upb_MtDataEncoder* e, char* ptr, - uint32_t val, int min, int max) { - int shift = upb_Log2Ceiling(_upb_FromBase92(max) - _upb_FromBase92(min) + 1); - UPB_ASSERT(shift <= 6); - uint32_t mask = (1 << shift) - 1; - do { - uint32_t bits = val & mask; - ptr = upb_MtDataEncoder_Put(e, ptr, bits + _upb_FromBase92(min)); - if (!ptr) return NULL; - val >>= shift; - } while (val); - return ptr; +bool upb_ExtensionRegistry_AddArray(upb_ExtensionRegistry* r, + const upb_MiniTableExtension** e, + size_t count) { + const upb_MiniTableExtension** start = e; + const upb_MiniTableExtension** end = UPB_PTRADD(e, count); + for (; e < end; e++) { + if (!upb_ExtensionRegistry_Add(r, *e)) goto failure; + } + return true; + +failure: + // Back out the entries previously added. + for (end = e, e = start; e < end; e++) { + const upb_MiniTableExtension* ext = *e; + char buf[EXTREG_KEY_SIZE]; + extreg_key(buf, ext->UPB_PRIVATE(extendee), + upb_MiniTableExtension_Number(ext)); + upb_strtable_remove2(&r->exts, buf, EXTREG_KEY_SIZE, NULL); + } + return false; } -char* upb_MtDataEncoder_PutModifier(upb_MtDataEncoder* e, char* ptr, - uint64_t mod) { - if (mod) { - ptr = upb_MtDataEncoder_PutBase92Varint(e, ptr, mod, - kUpb_EncodedValue_MinModifier, - kUpb_EncodedValue_MaxModifier); +const upb_MiniTableExtension* upb_ExtensionRegistry_Lookup( + const upb_ExtensionRegistry* r, const upb_MiniTable* t, uint32_t num) { + char buf[EXTREG_KEY_SIZE]; + upb_value v; + extreg_key(buf, t, num); + if (upb_strtable_lookup2(&r->exts, buf, EXTREG_KEY_SIZE, &v)) { + return upb_value_getconstptr(v); + } else { + return NULL; } - return ptr; } -char* upb_MtDataEncoder_EncodeExtension(upb_MtDataEncoder* e, char* ptr, - upb_FieldType type, uint32_t field_num, - uint64_t field_mod) { - upb_MtDataEncoderInternal* in = upb_MtDataEncoder_GetInternal(e, ptr); - in->state.msg_state.msg_modifiers = 0; - in->state.msg_state.last_field_num = 0; - in->state.msg_state.oneof_state = kUpb_OneofState_NotStarted; - ptr = upb_MtDataEncoder_PutRaw(e, ptr, kUpb_EncodedVersion_ExtensionV1); - if (!ptr) return NULL; +#include +#include +#include - return upb_MtDataEncoder_PutField(e, ptr, type, field_num, field_mod); -} -char* upb_MtDataEncoder_EncodeMap(upb_MtDataEncoder* e, char* ptr, - upb_FieldType key_type, - upb_FieldType value_type, uint64_t key_mod, - uint64_t value_mod) { - upb_MtDataEncoderInternal* in = upb_MtDataEncoder_GetInternal(e, ptr); - in->state.msg_state.msg_modifiers = 0; - in->state.msg_state.last_field_num = 0; - in->state.msg_state.oneof_state = kUpb_OneofState_NotStarted; +// Must be last. - ptr = upb_MtDataEncoder_PutRaw(e, ptr, kUpb_EncodedVersion_MapV1); - if (!ptr) return NULL; +const upb_MiniTableField* upb_MiniTable_FindFieldByNumber( + const upb_MiniTable* m, uint32_t number) { + const size_t i = ((size_t)number) - 1; // 0 wraps to SIZE_MAX - ptr = upb_MtDataEncoder_PutField(e, ptr, key_type, 1, key_mod); - if (!ptr) return NULL; + // Ideal case: index into dense fields + if (i < m->UPB_PRIVATE(dense_below)) { + UPB_ASSERT(m->UPB_PRIVATE(fields)[i].UPB_PRIVATE(number) == number); + return &m->UPB_PRIVATE(fields)[i]; + } - return upb_MtDataEncoder_PutField(e, ptr, value_type, 2, value_mod); + // Slow case: binary search + int lo = m->UPB_PRIVATE(dense_below); + int hi = m->UPB_PRIVATE(field_count) - 1; + while (lo <= hi) { + int mid = (lo + hi) / 2; + uint32_t num = m->UPB_PRIVATE(fields)[mid].UPB_PRIVATE(number); + if (num < number) { + lo = mid + 1; + continue; + } + if (num > number) { + hi = mid - 1; + continue; + } + return &m->UPB_PRIVATE(fields)[mid]; + } + return NULL; } -char* upb_MtDataEncoder_EncodeMessageSet(upb_MtDataEncoder* e, char* ptr) { - (void)upb_MtDataEncoder_GetInternal(e, ptr); - return upb_MtDataEncoder_PutRaw(e, ptr, kUpb_EncodedVersion_MessageSetV1); +const upb_MiniTableField* upb_MiniTable_GetOneof(const upb_MiniTable* m, + const upb_MiniTableField* f) { + if (UPB_UNLIKELY(!upb_MiniTableField_IsInOneof(f))) { + return NULL; + } + const upb_MiniTableField* ptr = &m->UPB_PRIVATE(fields)[0]; + const upb_MiniTableField* end = + &m->UPB_PRIVATE(fields)[m->UPB_PRIVATE(field_count)]; + for (; ptr < end; ptr++) { + if (ptr->presence == (*f).presence) { + return ptr; + } + } + return NULL; } -char* upb_MtDataEncoder_StartMessage(upb_MtDataEncoder* e, char* ptr, - uint64_t msg_mod) { - upb_MtDataEncoderInternal* in = upb_MtDataEncoder_GetInternal(e, ptr); - in->state.msg_state.msg_modifiers = msg_mod; - in->state.msg_state.last_field_num = 0; - in->state.msg_state.oneof_state = kUpb_OneofState_NotStarted; +bool upb_MiniTable_NextOneofField(const upb_MiniTable* m, + const upb_MiniTableField** f) { + const upb_MiniTableField* ptr = *f; + const upb_MiniTableField* end = + &m->UPB_PRIVATE(fields)[m->UPB_PRIVATE(field_count)]; + while (++ptr < end) { + if (ptr->presence == (*f)->presence) { + *f = ptr; + return true; + } + } + return false; +} - ptr = upb_MtDataEncoder_PutRaw(e, ptr, kUpb_EncodedVersion_MessageV1); - if (!ptr) return NULL; - return upb_MtDataEncoder_PutModifier(e, ptr, msg_mod); -} +#include +#include -static char* _upb_MtDataEncoder_MaybePutFieldSkip(upb_MtDataEncoder* e, - char* ptr, - uint32_t field_num) { - upb_MtDataEncoderInternal* in = (upb_MtDataEncoderInternal*)e->internal; - if (field_num <= in->state.msg_state.last_field_num) return NULL; - if (in->state.msg_state.last_field_num + 1 != field_num) { - // Put skip. - UPB_ASSERT(field_num > in->state.msg_state.last_field_num); - uint32_t skip = field_num - in->state.msg_state.last_field_num; - ptr = upb_MtDataEncoder_PutBase92Varint( - e, ptr, skip, kUpb_EncodedValue_MinSkip, kUpb_EncodedValue_MaxSkip); - if (!ptr) return NULL; - } - in->state.msg_state.last_field_num = field_num; - return ptr; -} -static char* _upb_MtDataEncoder_PutFieldType(upb_MtDataEncoder* e, char* ptr, - upb_FieldType type, - uint64_t field_mod) { - static const char kUpb_TypeToEncoded[] = { - [kUpb_FieldType_Double] = kUpb_EncodedType_Double, - [kUpb_FieldType_Float] = kUpb_EncodedType_Float, - [kUpb_FieldType_Int64] = kUpb_EncodedType_Int64, - [kUpb_FieldType_UInt64] = kUpb_EncodedType_UInt64, - [kUpb_FieldType_Int32] = kUpb_EncodedType_Int32, - [kUpb_FieldType_Fixed64] = kUpb_EncodedType_Fixed64, - [kUpb_FieldType_Fixed32] = kUpb_EncodedType_Fixed32, - [kUpb_FieldType_Bool] = kUpb_EncodedType_Bool, - [kUpb_FieldType_String] = kUpb_EncodedType_String, - [kUpb_FieldType_Group] = kUpb_EncodedType_Group, - [kUpb_FieldType_Message] = kUpb_EncodedType_Message, - [kUpb_FieldType_Bytes] = kUpb_EncodedType_Bytes, - [kUpb_FieldType_UInt32] = kUpb_EncodedType_UInt32, - [kUpb_FieldType_Enum] = kUpb_EncodedType_OpenEnum, - [kUpb_FieldType_SFixed32] = kUpb_EncodedType_SFixed32, - [kUpb_FieldType_SFixed64] = kUpb_EncodedType_SFixed64, - [kUpb_FieldType_SInt32] = kUpb_EncodedType_SInt32, - [kUpb_FieldType_SInt64] = kUpb_EncodedType_SInt64, - }; - - int encoded_type = kUpb_TypeToEncoded[type]; - - if (field_mod & kUpb_FieldModifier_IsClosedEnum) { - UPB_ASSERT(type == kUpb_FieldType_Enum); - encoded_type = kUpb_EncodedType_ClosedEnum; - } +// Must be last. - if (field_mod & kUpb_FieldModifier_IsRepeated) { - // Repeated fields shift the type number up (unlike other modifiers which - // are bit flags). - encoded_type += kUpb_EncodedType_RepeatedBase; - } +// Checks if source and target mini table fields are identical. +// +// If the field is a sub message and sub messages are identical we record +// the association in table. +// +// Hashing the source sub message mini table and it's equivalent in the table +// stops recursing when a cycle is detected and instead just checks if the +// destination table is equal. +static upb_MiniTableEquals_Status upb_deep_check(const upb_MiniTable* src, + const upb_MiniTable* dst, + upb_inttable* table, + upb_Arena** arena) { + if (src->UPB_PRIVATE(field_count) != dst->UPB_PRIVATE(field_count)) + return kUpb_MiniTableEquals_NotEqual; + bool marked_src = false; + for (int i = 0; i < upb_MiniTable_FieldCount(src); i++) { + const upb_MiniTableField* src_field = upb_MiniTable_GetFieldByIndex(src, i); + const upb_MiniTableField* dst_field = upb_MiniTable_FindFieldByNumber( + dst, upb_MiniTableField_Number(src_field)); - return upb_MtDataEncoder_Put(e, ptr, encoded_type); -} + if (upb_MiniTableField_CType(src_field) != + upb_MiniTableField_CType(dst_field)) + return false; + if (src_field->UPB_PRIVATE(mode) != dst_field->UPB_PRIVATE(mode)) + return false; + if (src_field->UPB_PRIVATE(offset) != dst_field->UPB_PRIVATE(offset)) + return false; + if (src_field->presence != dst_field->presence) return false; + if (src_field->UPB_PRIVATE(submsg_index) != + dst_field->UPB_PRIVATE(submsg_index)) + return kUpb_MiniTableEquals_NotEqual; -static char* _upb_MtDataEncoder_MaybePutModifiers(upb_MtDataEncoder* e, - char* ptr, upb_FieldType type, - uint64_t field_mod) { - upb_MtDataEncoderInternal* in = (upb_MtDataEncoderInternal*)e->internal; - uint32_t encoded_modifiers = 0; - if ((field_mod & kUpb_FieldModifier_IsRepeated) && - upb_FieldType_IsPackable(type)) { - bool field_is_packed = field_mod & kUpb_FieldModifier_IsPacked; - bool default_is_packed = in->state.msg_state.msg_modifiers & - kUpb_MessageModifier_DefaultIsPacked; - if (field_is_packed != default_is_packed) { - encoded_modifiers |= kUpb_EncodedFieldModifier_FlipPacked; - } - } + // Go no further if we are only checking for compatibility. + if (!table) continue; - if (type == kUpb_FieldType_String) { - bool field_validates_utf8 = field_mod & kUpb_FieldModifier_ValidateUtf8; - bool message_validates_utf8 = - in->state.msg_state.msg_modifiers & kUpb_MessageModifier_ValidateUtf8; - if (field_validates_utf8 != message_validates_utf8) { - // Old binaries do not recognize the field modifier. We need the failure - // mode to be too lax rather than too strict. Our caller should have - // handled this (see _upb_MessageDef_ValidateUtf8()). - assert(!message_validates_utf8); - encoded_modifiers |= kUpb_EncodedFieldModifier_FlipValidateUtf8; + if (upb_MiniTableField_CType(src_field) == kUpb_CType_Message) { + if (!*arena) { + *arena = upb_Arena_New(); + if (!upb_inttable_init(table, *arena)) { + return kUpb_MiniTableEquals_OutOfMemory; + } + } + if (!marked_src) { + marked_src = true; + upb_value val; + val.val = (uint64_t)dst; + if (!upb_inttable_insert(table, (uintptr_t)src, val, *arena)) { + return kUpb_MiniTableEquals_OutOfMemory; + } + } + const upb_MiniTable* sub_src = + upb_MiniTable_GetSubMessageTable(src, src_field); + const upb_MiniTable* sub_dst = + upb_MiniTable_GetSubMessageTable(dst, dst_field); + if (sub_src != NULL) { + upb_value cmp; + if (upb_inttable_lookup(table, (uintptr_t)sub_src, &cmp)) { + // We already compared this src before. Check if same dst. + if (cmp.val != (uint64_t)sub_dst) { + return kUpb_MiniTableEquals_NotEqual; + } + } else { + // Recurse if not already visited. + upb_MiniTableEquals_Status s = + upb_deep_check(sub_src, sub_dst, table, arena); + if (s != kUpb_MiniTableEquals_Equal) { + return s; + } + } + } } } + return kUpb_MiniTableEquals_Equal; +} - if (field_mod & kUpb_FieldModifier_IsProto3Singular) { - encoded_modifiers |= kUpb_EncodedFieldModifier_IsProto3Singular; - } +bool upb_MiniTable_Compatible(const upb_MiniTable* src, + const upb_MiniTable* dst) { + return upb_deep_check(src, dst, NULL, NULL); +} - if (field_mod & kUpb_FieldModifier_IsRequired) { - encoded_modifiers |= kUpb_EncodedFieldModifier_IsRequired; +upb_MiniTableEquals_Status upb_MiniTable_Equals(const upb_MiniTable* src, + const upb_MiniTable* dst) { + // Arena allocated on demand for hash table. + upb_Arena* arena = NULL; + // Table to keep track of visited mini tables to guard against cycles. + upb_inttable table; + upb_MiniTableEquals_Status status = upb_deep_check(src, dst, &table, &arena); + if (arena) { + upb_Arena_Free(arena); } - - return upb_MtDataEncoder_PutModifier(e, ptr, encoded_modifiers); + return status; } -char* upb_MtDataEncoder_PutField(upb_MtDataEncoder* e, char* ptr, - upb_FieldType type, uint32_t field_num, - uint64_t field_mod) { - upb_MtDataEncoder_GetInternal(e, ptr); - - ptr = _upb_MtDataEncoder_MaybePutFieldSkip(e, ptr, field_num); - if (!ptr) return NULL; - ptr = _upb_MtDataEncoder_PutFieldType(e, ptr, type, field_mod); - if (!ptr) return NULL; - return _upb_MtDataEncoder_MaybePutModifiers(e, ptr, type, field_mod); -} +// Must be last. -char* upb_MtDataEncoder_StartOneof(upb_MtDataEncoder* e, char* ptr) { - upb_MtDataEncoderInternal* in = upb_MtDataEncoder_GetInternal(e, ptr); - if (in->state.msg_state.oneof_state == kUpb_OneofState_NotStarted) { - ptr = upb_MtDataEncoder_Put(e, ptr, _upb_FromBase92(kUpb_EncodedValue_End)); - } else { - ptr = upb_MtDataEncoder_Put( - e, ptr, _upb_FromBase92(kUpb_EncodedValue_OneofSeparator)); - } - in->state.msg_state.oneof_state = kUpb_OneofState_StartedOneof; - return ptr; -} +struct upb_DefPool { + upb_Arena* arena; + upb_strtable syms; // full_name -> packed def ptr + upb_strtable files; // file_name -> (upb_FileDef*) + upb_inttable exts; // (upb_MiniTableExtension*) -> (upb_FieldDef*) + upb_ExtensionRegistry* extreg; + const UPB_DESC(FeatureSetDefaults) * feature_set_defaults; + upb_MiniTablePlatform platform; + void* scratch_data; + size_t scratch_size; + size_t bytes_loaded; +}; -char* upb_MtDataEncoder_PutOneofField(upb_MtDataEncoder* e, char* ptr, - uint32_t field_num) { - upb_MtDataEncoderInternal* in = upb_MtDataEncoder_GetInternal(e, ptr); - if (in->state.msg_state.oneof_state == kUpb_OneofState_EmittedOneofField) { - ptr = upb_MtDataEncoder_Put( - e, ptr, _upb_FromBase92(kUpb_EncodedValue_FieldSeparator)); - if (!ptr) return NULL; - } - ptr = upb_MtDataEncoder_PutBase92Varint(e, ptr, field_num, _upb_ToBase92(0), - _upb_ToBase92(63)); - in->state.msg_state.oneof_state = kUpb_OneofState_EmittedOneofField; - return ptr; +void upb_DefPool_Free(upb_DefPool* s) { + upb_Arena_Free(s->arena); + upb_gfree(s->scratch_data); + upb_gfree(s); } -char* upb_MtDataEncoder_StartEnum(upb_MtDataEncoder* e, char* ptr) { - upb_MtDataEncoderInternal* in = upb_MtDataEncoder_GetInternal(e, ptr); - in->state.enum_state.present_values_mask = 0; - in->state.enum_state.last_written_value = 0; +static const char serialized_defaults[] = UPB_INTERNAL_UPB_EDITION_DEFAULTS; - return upb_MtDataEncoder_PutRaw(e, ptr, kUpb_EncodedVersion_EnumV1); -} +upb_DefPool* upb_DefPool_New(void) { + upb_DefPool* s = upb_gmalloc(sizeof(*s)); + if (!s) return NULL; -static char* upb_MtDataEncoder_FlushDenseEnumMask(upb_MtDataEncoder* e, - char* ptr) { - upb_MtDataEncoderInternal* in = (upb_MtDataEncoderInternal*)e->internal; - ptr = upb_MtDataEncoder_Put(e, ptr, in->state.enum_state.present_values_mask); - in->state.enum_state.present_values_mask = 0; - in->state.enum_state.last_written_value += 5; - return ptr; -} + s->arena = upb_Arena_New(); + s->bytes_loaded = 0; -char* upb_MtDataEncoder_PutEnumValue(upb_MtDataEncoder* e, char* ptr, - uint32_t val) { - // TODO: optimize this encoding. - upb_MtDataEncoderInternal* in = upb_MtDataEncoder_GetInternal(e, ptr); - UPB_ASSERT(val >= in->state.enum_state.last_written_value); - uint32_t delta = val - in->state.enum_state.last_written_value; - if (delta >= 5 && in->state.enum_state.present_values_mask) { - ptr = upb_MtDataEncoder_FlushDenseEnumMask(e, ptr); - if (!ptr) { - return NULL; - } - delta -= 5; - } + s->scratch_size = 240; + s->scratch_data = upb_gmalloc(s->scratch_size); + if (!s->scratch_data) goto err; - if (delta >= 5) { - ptr = upb_MtDataEncoder_PutBase92Varint( - e, ptr, delta, kUpb_EncodedValue_MinSkip, kUpb_EncodedValue_MaxSkip); - in->state.enum_state.last_written_value += delta; - delta = 0; - } + if (!upb_strtable_init(&s->syms, 32, s->arena)) goto err; + if (!upb_strtable_init(&s->files, 4, s->arena)) goto err; + if (!upb_inttable_init(&s->exts, s->arena)) goto err; - UPB_ASSERT((in->state.enum_state.present_values_mask >> delta) == 0); - in->state.enum_state.present_values_mask |= 1ULL << delta; - return ptr; -} + s->extreg = upb_ExtensionRegistry_New(s->arena); + if (!s->extreg) goto err; -char* upb_MtDataEncoder_EndEnum(upb_MtDataEncoder* e, char* ptr) { - upb_MtDataEncoderInternal* in = upb_MtDataEncoder_GetInternal(e, ptr); - if (!in->state.enum_state.present_values_mask) return ptr; - return upb_MtDataEncoder_FlushDenseEnumMask(e, ptr); -} + s->platform = kUpb_MiniTablePlatform_Native; + upb_Status status; + if (!upb_DefPool_SetFeatureSetDefaults( + s, serialized_defaults, sizeof(serialized_defaults) - 1, &status)) { + goto err; + } -#include -#include -#include + if (!s->feature_set_defaults) goto err; + return s; -// Must be last. +err: + upb_DefPool_Free(s); + return NULL; +} -#define EXTREG_KEY_SIZE (sizeof(upb_MiniTable*) + sizeof(uint32_t)) - -struct upb_ExtensionRegistry { - upb_Arena* arena; - upb_strtable exts; // Key is upb_MiniTable* concatenated with fieldnum. -}; - -static void extreg_key(char* buf, const upb_MiniTable* l, uint32_t fieldnum) { - memcpy(buf, &l, sizeof(l)); - memcpy(buf + sizeof(l), &fieldnum, sizeof(fieldnum)); +const UPB_DESC(FeatureSetDefaults) * + upb_DefPool_FeatureSetDefaults(const upb_DefPool* s) { + return s->feature_set_defaults; } -upb_ExtensionRegistry* upb_ExtensionRegistry_New(upb_Arena* arena) { - upb_ExtensionRegistry* r = upb_Arena_Malloc(arena, sizeof(*r)); - if (!r) return NULL; - r->arena = arena; - if (!upb_strtable_init(&r->exts, 8, arena)) return NULL; - return r; +bool upb_DefPool_SetFeatureSetDefaults(upb_DefPool* s, + const char* serialized_defaults, + size_t serialized_len, + upb_Status* status) { + const UPB_DESC(FeatureSetDefaults)* defaults = UPB_DESC( + FeatureSetDefaults_parse)(serialized_defaults, serialized_len, s->arena); + if (!defaults) { + upb_Status_SetErrorFormat(status, "Failed to parse defaults"); + return false; + } + if (upb_strtable_count(&s->files) > 0) { + upb_Status_SetErrorFormat(status, + "Feature set defaults can't be changed once the " + "pool has started building"); + return false; + } + int min_edition = UPB_DESC(FeatureSetDefaults_minimum_edition(defaults)); + int max_edition = UPB_DESC(FeatureSetDefaults_maximum_edition(defaults)); + if (min_edition > max_edition) { + upb_Status_SetErrorFormat(status, "Invalid edition range %s to %s", + upb_FileDef_EditionName(min_edition), + upb_FileDef_EditionName(max_edition)); + return false; + } + size_t size; + const UPB_DESC( + FeatureSetDefaults_FeatureSetEditionDefault)* const* default_list = + UPB_DESC(FeatureSetDefaults_defaults(defaults, &size)); + int prev_edition = UPB_DESC(EDITION_UNKNOWN); + for (size_t i = 0; i < size; ++i) { + int edition = UPB_DESC( + FeatureSetDefaults_FeatureSetEditionDefault_edition(default_list[i])); + if (edition == UPB_DESC(EDITION_UNKNOWN)) { + upb_Status_SetErrorFormat(status, "Invalid edition UNKNOWN specified"); + return false; + } + if (edition <= prev_edition) { + upb_Status_SetErrorFormat(status, + "Feature set defaults are not strictly " + "increasing, %s is greater than or equal to %s", + upb_FileDef_EditionName(prev_edition), + upb_FileDef_EditionName(edition)); + return false; + } + prev_edition = edition; + } + + // Copy the defaults into the pool. + s->feature_set_defaults = defaults; + return true; } -UPB_API bool upb_ExtensionRegistry_Add(upb_ExtensionRegistry* r, - const upb_MiniTableExtension* e) { - char buf[EXTREG_KEY_SIZE]; - extreg_key(buf, e->UPB_PRIVATE(extendee), upb_MiniTableExtension_Number(e)); - if (upb_strtable_lookup2(&r->exts, buf, EXTREG_KEY_SIZE, NULL)) return false; - return upb_strtable_insert(&r->exts, buf, EXTREG_KEY_SIZE, - upb_value_constptr(e), r->arena); +bool _upb_DefPool_InsertExt(upb_DefPool* s, const upb_MiniTableExtension* ext, + const upb_FieldDef* f) { + return upb_inttable_insert(&s->exts, (uintptr_t)ext, upb_value_constptr(f), + s->arena); } -bool upb_ExtensionRegistry_AddArray(upb_ExtensionRegistry* r, - const upb_MiniTableExtension** e, - size_t count) { - const upb_MiniTableExtension** start = e; - const upb_MiniTableExtension** end = UPB_PTRADD(e, count); - for (; e < end; e++) { - if (!upb_ExtensionRegistry_Add(r, *e)) goto failure; +bool _upb_DefPool_InsertSym(upb_DefPool* s, upb_StringView sym, upb_value v, + upb_Status* status) { + // TODO: table should support an operation "tryinsert" to avoid the double + // lookup. + if (upb_strtable_lookup2(&s->syms, sym.data, sym.size, NULL)) { + upb_Status_SetErrorFormat(status, "duplicate symbol '%s'", sym.data); + return false; } - return true; - -failure: - // Back out the entries previously added. - for (end = e, e = start; e < end; e++) { - const upb_MiniTableExtension* ext = *e; - char buf[EXTREG_KEY_SIZE]; - extreg_key(buf, ext->UPB_PRIVATE(extendee), - upb_MiniTableExtension_Number(ext)); - upb_strtable_remove2(&r->exts, buf, EXTREG_KEY_SIZE, NULL); + if (!upb_strtable_insert(&s->syms, sym.data, sym.size, v, s->arena)) { + upb_Status_SetErrorMessage(status, "out of memory"); + return false; } - return false; + return true; } -const upb_MiniTableExtension* upb_ExtensionRegistry_Lookup( - const upb_ExtensionRegistry* r, const upb_MiniTable* t, uint32_t num) { - char buf[EXTREG_KEY_SIZE]; +static const void* _upb_DefPool_Unpack(const upb_DefPool* s, const char* sym, + size_t size, upb_deftype_t type) { upb_value v; - extreg_key(buf, t, num); - if (upb_strtable_lookup2(&r->exts, buf, EXTREG_KEY_SIZE, &v)) { - return upb_value_getconstptr(v); - } else { - return NULL; - } + return upb_strtable_lookup2(&s->syms, sym, size, &v) + ? _upb_DefType_Unpack(v, type) + : NULL; } +bool _upb_DefPool_LookupSym(const upb_DefPool* s, const char* sym, size_t size, + upb_value* v) { + return upb_strtable_lookup2(&s->syms, sym, size, v); +} -#include -#include -#include +upb_ExtensionRegistry* _upb_DefPool_ExtReg(const upb_DefPool* s) { + return s->extreg; +} +void** _upb_DefPool_ScratchData(const upb_DefPool* s) { + return (void**)&s->scratch_data; +} -// Must be last. +size_t* _upb_DefPool_ScratchSize(const upb_DefPool* s) { + return (size_t*)&s->scratch_size; +} -const upb_MiniTableField* upb_MiniTable_FindFieldByNumber( - const upb_MiniTable* m, uint32_t number) { - const size_t i = ((size_t)number) - 1; // 0 wraps to SIZE_MAX +void _upb_DefPool_SetPlatform(upb_DefPool* s, upb_MiniTablePlatform platform) { + assert(upb_strtable_count(&s->files) == 0); + s->platform = platform; +} - // Ideal case: index into dense fields - if (i < m->UPB_PRIVATE(dense_below)) { - UPB_ASSERT(m->UPB_PRIVATE(fields)[i].UPB_PRIVATE(number) == number); - return &m->UPB_PRIVATE(fields)[i]; - } +const upb_MessageDef* upb_DefPool_FindMessageByName(const upb_DefPool* s, + const char* sym) { + return _upb_DefPool_Unpack(s, sym, strlen(sym), UPB_DEFTYPE_MSG); +} - // Slow case: binary search - int lo = m->UPB_PRIVATE(dense_below); - int hi = m->UPB_PRIVATE(field_count) - 1; - while (lo <= hi) { - int mid = (lo + hi) / 2; - uint32_t num = m->UPB_PRIVATE(fields)[mid].UPB_PRIVATE(number); - if (num < number) { - lo = mid + 1; - continue; - } - if (num > number) { - hi = mid - 1; - continue; - } - return &m->UPB_PRIVATE(fields)[mid]; - } - return NULL; +const upb_MessageDef* upb_DefPool_FindMessageByNameWithSize( + const upb_DefPool* s, const char* sym, size_t len) { + return _upb_DefPool_Unpack(s, sym, len, UPB_DEFTYPE_MSG); } -const upb_MiniTableField* upb_MiniTable_GetOneof(const upb_MiniTable* m, - const upb_MiniTableField* f) { - if (UPB_UNLIKELY(!upb_MiniTableField_IsInOneof(f))) { - return NULL; - } - const upb_MiniTableField* ptr = &m->UPB_PRIVATE(fields)[0]; - const upb_MiniTableField* end = - &m->UPB_PRIVATE(fields)[m->UPB_PRIVATE(field_count)]; - for (; ptr < end; ptr++) { - if (ptr->presence == (*f).presence) { - return ptr; - } - } - return NULL; +const upb_EnumDef* upb_DefPool_FindEnumByName(const upb_DefPool* s, + const char* sym) { + return _upb_DefPool_Unpack(s, sym, strlen(sym), UPB_DEFTYPE_ENUM); } -bool upb_MiniTable_NextOneofField(const upb_MiniTable* m, - const upb_MiniTableField** f) { - const upb_MiniTableField* ptr = *f; - const upb_MiniTableField* end = - &m->UPB_PRIVATE(fields)[m->UPB_PRIVATE(field_count)]; - while (++ptr < end) { - if (ptr->presence == (*f)->presence) { - *f = ptr; - return true; +const upb_EnumValueDef* upb_DefPool_FindEnumByNameval(const upb_DefPool* s, + const char* sym) { + return _upb_DefPool_Unpack(s, sym, strlen(sym), UPB_DEFTYPE_ENUMVAL); +} + +const upb_FileDef* upb_DefPool_FindFileByName(const upb_DefPool* s, + const char* name) { + upb_value v; + return upb_strtable_lookup(&s->files, name, &v) ? upb_value_getconstptr(v) + : NULL; +} + +const upb_FileDef* upb_DefPool_FindFileByNameWithSize(const upb_DefPool* s, + const char* name, + size_t len) { + upb_value v; + return upb_strtable_lookup2(&s->files, name, len, &v) + ? upb_value_getconstptr(v) + : NULL; +} + +const upb_FieldDef* upb_DefPool_FindExtensionByNameWithSize( + const upb_DefPool* s, const char* name, size_t size) { + upb_value v; + if (!upb_strtable_lookup2(&s->syms, name, size, &v)) return NULL; + + switch (_upb_DefType_Type(v)) { + case UPB_DEFTYPE_FIELD: + return _upb_DefType_Unpack(v, UPB_DEFTYPE_FIELD); + case UPB_DEFTYPE_MSG: { + const upb_MessageDef* m = _upb_DefType_Unpack(v, UPB_DEFTYPE_MSG); + return _upb_MessageDef_InMessageSet(m) + ? upb_MessageDef_NestedExtension(m, 0) + : NULL; } + default: + break; } - return false; + + return NULL; } +const upb_FieldDef* upb_DefPool_FindExtensionByName(const upb_DefPool* s, + const char* sym) { + return upb_DefPool_FindExtensionByNameWithSize(s, sym, strlen(sym)); +} -#include -#include +const upb_ServiceDef* upb_DefPool_FindServiceByName(const upb_DefPool* s, + const char* name) { + return _upb_DefPool_Unpack(s, name, strlen(name), UPB_DEFTYPE_SERVICE); +} +const upb_ServiceDef* upb_DefPool_FindServiceByNameWithSize( + const upb_DefPool* s, const char* name, size_t size) { + return _upb_DefPool_Unpack(s, name, size, UPB_DEFTYPE_SERVICE); +} -// Must be last. - -// Checks if source and target mini table fields are identical. -// -// If the field is a sub message and sub messages are identical we record -// the association in table. -// -// Hashing the source sub message mini table and it's equivalent in the table -// stops recursing when a cycle is detected and instead just checks if the -// destination table is equal. -static upb_MiniTableEquals_Status upb_deep_check(const upb_MiniTable* src, - const upb_MiniTable* dst, - upb_inttable* table, - upb_Arena** arena) { - if (src->UPB_PRIVATE(field_count) != dst->UPB_PRIVATE(field_count)) - return kUpb_MiniTableEquals_NotEqual; - bool marked_src = false; - for (int i = 0; i < upb_MiniTable_FieldCount(src); i++) { - const upb_MiniTableField* src_field = upb_MiniTable_GetFieldByIndex(src, i); - const upb_MiniTableField* dst_field = upb_MiniTable_FindFieldByNumber( - dst, upb_MiniTableField_Number(src_field)); - - if (upb_MiniTableField_CType(src_field) != - upb_MiniTableField_CType(dst_field)) - return false; - if (src_field->UPB_PRIVATE(mode) != dst_field->UPB_PRIVATE(mode)) - return false; - if (src_field->UPB_PRIVATE(offset) != dst_field->UPB_PRIVATE(offset)) - return false; - if (src_field->presence != dst_field->presence) return false; - if (src_field->UPB_PRIVATE(submsg_index) != - dst_field->UPB_PRIVATE(submsg_index)) - return kUpb_MiniTableEquals_NotEqual; - - // Go no further if we are only checking for compatibility. - if (!table) continue; - - if (upb_MiniTableField_CType(src_field) == kUpb_CType_Message) { - if (!*arena) { - *arena = upb_Arena_New(); - if (!upb_inttable_init(table, *arena)) { - return kUpb_MiniTableEquals_OutOfMemory; - } +const upb_FileDef* upb_DefPool_FindFileContainingSymbol(const upb_DefPool* s, + const char* name) { + upb_value v; + // TODO: non-extension fields and oneofs. + if (upb_strtable_lookup(&s->syms, name, &v)) { + switch (_upb_DefType_Type(v)) { + case UPB_DEFTYPE_EXT: { + const upb_FieldDef* f = _upb_DefType_Unpack(v, UPB_DEFTYPE_EXT); + return upb_FieldDef_File(f); } - if (!marked_src) { - marked_src = true; - upb_value val; - val.val = (uint64_t)dst; - if (!upb_inttable_insert(table, (uintptr_t)src, val, *arena)) { - return kUpb_MiniTableEquals_OutOfMemory; - } + case UPB_DEFTYPE_MSG: { + const upb_MessageDef* m = _upb_DefType_Unpack(v, UPB_DEFTYPE_MSG); + return upb_MessageDef_File(m); } - const upb_MiniTable* sub_src = - upb_MiniTable_GetSubMessageTable(src, src_field); - const upb_MiniTable* sub_dst = - upb_MiniTable_GetSubMessageTable(dst, dst_field); - if (sub_src != NULL) { - upb_value cmp; - if (upb_inttable_lookup(table, (uintptr_t)sub_src, &cmp)) { - // We already compared this src before. Check if same dst. - if (cmp.val != (uint64_t)sub_dst) { - return kUpb_MiniTableEquals_NotEqual; - } - } else { - // Recurse if not already visited. - upb_MiniTableEquals_Status s = - upb_deep_check(sub_src, sub_dst, table, arena); - if (s != kUpb_MiniTableEquals_Equal) { - return s; - } - } + case UPB_DEFTYPE_ENUM: { + const upb_EnumDef* e = _upb_DefType_Unpack(v, UPB_DEFTYPE_ENUM); + return upb_EnumDef_File(e); + } + case UPB_DEFTYPE_ENUMVAL: { + const upb_EnumValueDef* ev = + _upb_DefType_Unpack(v, UPB_DEFTYPE_ENUMVAL); + return upb_EnumDef_File(upb_EnumValueDef_Enum(ev)); } + case UPB_DEFTYPE_SERVICE: { + const upb_ServiceDef* service = + _upb_DefType_Unpack(v, UPB_DEFTYPE_SERVICE); + return upb_ServiceDef_File(service); + } + default: + UPB_UNREACHABLE(); } } - return kUpb_MiniTableEquals_Equal; + + const char* last_dot = strrchr(name, '.'); + if (last_dot) { + const upb_MessageDef* parent = + upb_DefPool_FindMessageByNameWithSize(s, name, last_dot - name); + if (parent) { + const char* shortname = last_dot + 1; + if (upb_MessageDef_FindByNameWithSize(parent, shortname, + strlen(shortname), NULL, NULL)) { + return upb_MessageDef_File(parent); + } + } + } + + return NULL; } -bool upb_MiniTable_Compatible(const upb_MiniTable* src, - const upb_MiniTable* dst) { - return upb_deep_check(src, dst, NULL, NULL); +static void remove_filedef(upb_DefPool* s, upb_FileDef* file) { + intptr_t iter = UPB_INTTABLE_BEGIN; + upb_StringView key; + upb_value val; + while (upb_strtable_next2(&s->syms, &key, &val, &iter)) { + const upb_FileDef* f; + switch (_upb_DefType_Type(val)) { + case UPB_DEFTYPE_EXT: + f = upb_FieldDef_File(_upb_DefType_Unpack(val, UPB_DEFTYPE_EXT)); + break; + case UPB_DEFTYPE_MSG: + f = upb_MessageDef_File(_upb_DefType_Unpack(val, UPB_DEFTYPE_MSG)); + break; + case UPB_DEFTYPE_ENUM: + f = upb_EnumDef_File(_upb_DefType_Unpack(val, UPB_DEFTYPE_ENUM)); + break; + case UPB_DEFTYPE_ENUMVAL: + f = upb_EnumDef_File(upb_EnumValueDef_Enum( + _upb_DefType_Unpack(val, UPB_DEFTYPE_ENUMVAL))); + break; + case UPB_DEFTYPE_SERVICE: + f = upb_ServiceDef_File(_upb_DefType_Unpack(val, UPB_DEFTYPE_SERVICE)); + break; + default: + UPB_UNREACHABLE(); + } + + if (f == file) upb_strtable_removeiter(&s->syms, &iter); + } } -upb_MiniTableEquals_Status upb_MiniTable_Equals(const upb_MiniTable* src, - const upb_MiniTable* dst) { - // Arena allocated on demand for hash table. - upb_Arena* arena = NULL; - // Table to keep track of visited mini tables to guard against cycles. - upb_inttable table; - upb_MiniTableEquals_Status status = upb_deep_check(src, dst, &table, &arena); - if (arena) { - upb_Arena_Free(arena); +static const upb_FileDef* upb_DefBuilder_AddFileToPool( + upb_DefBuilder* const builder, upb_DefPool* const s, + const UPB_DESC(FileDescriptorProto) * const file_proto, + const upb_StringView name, upb_Status* const status) { + if (UPB_SETJMP(builder->err) != 0) { + UPB_ASSERT(!upb_Status_IsOk(status)); + if (builder->file) { + remove_filedef(s, builder->file); + builder->file = NULL; + } + } else if (!builder->arena || !builder->tmp_arena || + !upb_strtable_init(&builder->feature_cache, 16, + builder->tmp_arena) || + !(builder->legacy_features = + UPB_DESC(FeatureSet_new)(builder->tmp_arena))) { + _upb_DefBuilder_OomErr(builder); + } else { + _upb_FileDef_Create(builder, file_proto); + upb_strtable_insert(&s->files, name.data, name.size, + upb_value_constptr(builder->file), builder->arena); + UPB_ASSERT(upb_Status_IsOk(status)); + upb_Arena_Fuse(s->arena, builder->arena); } - return status; + + if (builder->arena) upb_Arena_Free(builder->arena); + if (builder->tmp_arena) upb_Arena_Free(builder->tmp_arena); + return builder->file; } +static const upb_FileDef* _upb_DefPool_AddFile( + upb_DefPool* s, const UPB_DESC(FileDescriptorProto) * file_proto, + const upb_MiniTableFile* layout, upb_Status* status) { + const upb_StringView name = UPB_DESC(FileDescriptorProto_name)(file_proto); + // Determine whether we already know about this file. + { + upb_value v; + if (upb_strtable_lookup2(&s->files, name.data, name.size, &v)) { + upb_Status_SetErrorFormat(status, + "duplicate file name " UPB_STRINGVIEW_FORMAT, + UPB_STRINGVIEW_ARGS(name)); + return NULL; + } + } -// Must be last. + upb_DefBuilder ctx = { + .symtab = s, + .tmp_buf = NULL, + .tmp_buf_size = 0, + .layout = layout, + .platform = s->platform, + .msg_count = 0, + .enum_count = 0, + .ext_count = 0, + .status = status, + .file = NULL, + .arena = upb_Arena_New(), + .tmp_arena = upb_Arena_New(), + }; -struct upb_DefPool { - upb_Arena* arena; - upb_strtable syms; // full_name -> packed def ptr - upb_strtable files; // file_name -> (upb_FileDef*) - upb_inttable exts; // (upb_MiniTableExtension*) -> (upb_FieldDef*) - upb_ExtensionRegistry* extreg; - const UPB_DESC(FeatureSetDefaults) * feature_set_defaults; - upb_MiniTablePlatform platform; - void* scratch_data; - size_t scratch_size; - size_t bytes_loaded; -}; + return upb_DefBuilder_AddFileToPool(&ctx, s, file_proto, name, status); +} -void upb_DefPool_Free(upb_DefPool* s) { - upb_Arena_Free(s->arena); - upb_gfree(s->scratch_data); - upb_gfree(s); +const upb_FileDef* upb_DefPool_AddFile(upb_DefPool* s, + const UPB_DESC(FileDescriptorProto) * + file_proto, + upb_Status* status) { + return _upb_DefPool_AddFile(s, file_proto, NULL, status); } -static const char serialized_defaults[] = UPB_INTERNAL_UPB_EDITION_DEFAULTS; +bool _upb_DefPool_LoadDefInitEx(upb_DefPool* s, const _upb_DefPool_Init* init, + bool rebuild_minitable) { + /* Since this function should never fail (it would indicate a bug in upb) we + * print errors to stderr instead of returning error status to the user. */ + _upb_DefPool_Init** deps = init->deps; + UPB_DESC(FileDescriptorProto) * file; + upb_Arena* arena; + upb_Status status; -upb_DefPool* upb_DefPool_New(void) { - upb_DefPool* s = upb_gmalloc(sizeof(*s)); - if (!s) return NULL; + upb_Status_Clear(&status); - s->arena = upb_Arena_New(); - s->bytes_loaded = 0; + if (upb_DefPool_FindFileByName(s, init->filename)) { + return true; + } - s->scratch_size = 240; - s->scratch_data = upb_gmalloc(s->scratch_size); - if (!s->scratch_data) goto err; + arena = upb_Arena_New(); - if (!upb_strtable_init(&s->syms, 32, s->arena)) goto err; - if (!upb_strtable_init(&s->files, 4, s->arena)) goto err; - if (!upb_inttable_init(&s->exts, s->arena)) goto err; - - s->extreg = upb_ExtensionRegistry_New(s->arena); - if (!s->extreg) goto err; + for (; *deps; deps++) { + if (!_upb_DefPool_LoadDefInitEx(s, *deps, rebuild_minitable)) goto err; + } - s->platform = kUpb_MiniTablePlatform_Native; + file = UPB_DESC(FileDescriptorProto_parse_ex)( + init->descriptor.data, init->descriptor.size, NULL, + kUpb_DecodeOption_AliasString, arena); + s->bytes_loaded += init->descriptor.size; - upb_Status status; - if (!upb_DefPool_SetFeatureSetDefaults( - s, serialized_defaults, sizeof(serialized_defaults) - 1, &status)) { + if (!file) { + upb_Status_SetErrorFormat( + &status, + "Failed to parse compiled-in descriptor for file '%s'. This should " + "never happen.", + init->filename); goto err; } - if (!s->feature_set_defaults) goto err; - - return s; - -err: - upb_DefPool_Free(s); - return NULL; -} - -const UPB_DESC(FeatureSetDefaults) * - upb_DefPool_FeatureSetDefaults(const upb_DefPool* s) { - return s->feature_set_defaults; -} - -bool upb_DefPool_SetFeatureSetDefaults(upb_DefPool* s, - const char* serialized_defaults, - size_t serialized_len, - upb_Status* status) { - const UPB_DESC(FeatureSetDefaults)* defaults = UPB_DESC( - FeatureSetDefaults_parse)(serialized_defaults, serialized_len, s->arena); - if (!defaults) { - upb_Status_SetErrorFormat(status, "Failed to parse defaults"); - return false; - } - if (upb_strtable_count(&s->files) > 0) { - upb_Status_SetErrorFormat(status, - "Feature set defaults can't be changed once the " - "pool has started building"); - return false; - } - int min_edition = UPB_DESC(FeatureSetDefaults_minimum_edition(defaults)); - int max_edition = UPB_DESC(FeatureSetDefaults_maximum_edition(defaults)); - if (min_edition > max_edition) { - upb_Status_SetErrorFormat(status, "Invalid edition range %s to %s", - upb_FileDef_EditionName(min_edition), - upb_FileDef_EditionName(max_edition)); - return false; - } - size_t size; - const UPB_DESC( - FeatureSetDefaults_FeatureSetEditionDefault)* const* default_list = - UPB_DESC(FeatureSetDefaults_defaults(defaults, &size)); - int prev_edition = UPB_DESC(EDITION_UNKNOWN); - for (size_t i = 0; i < size; ++i) { - int edition = UPB_DESC( - FeatureSetDefaults_FeatureSetEditionDefault_edition(default_list[i])); - if (edition == UPB_DESC(EDITION_UNKNOWN)) { - upb_Status_SetErrorFormat(status, "Invalid edition UNKNOWN specified"); - return false; - } - if (edition <= prev_edition) { - upb_Status_SetErrorFormat(status, - "Feature set defaults are not strictly " - "increasing, %s is greater than or equal to %s", - upb_FileDef_EditionName(prev_edition), - upb_FileDef_EditionName(edition)); - return false; - } - prev_edition = edition; + const upb_MiniTableFile* mt = rebuild_minitable ? NULL : init->layout; + if (!_upb_DefPool_AddFile(s, file, mt, &status)) { + goto err; } - // Copy the defaults into the pool. - s->feature_set_defaults = defaults; + upb_Arena_Free(arena); return true; -} -bool _upb_DefPool_InsertExt(upb_DefPool* s, const upb_MiniTableExtension* ext, - const upb_FieldDef* f) { - return upb_inttable_insert(&s->exts, (uintptr_t)ext, upb_value_constptr(f), - s->arena); +err: + fprintf(stderr, + "Error loading compiled-in descriptor for file '%s' (this should " + "never happen): %s\n", + init->filename, upb_Status_ErrorMessage(&status)); + upb_Arena_Free(arena); + return false; } -bool _upb_DefPool_InsertSym(upb_DefPool* s, upb_StringView sym, upb_value v, - upb_Status* status) { - // TODO: table should support an operation "tryinsert" to avoid the double - // lookup. - if (upb_strtable_lookup2(&s->syms, sym.data, sym.size, NULL)) { - upb_Status_SetErrorFormat(status, "duplicate symbol '%s'", sym.data); - return false; - } - if (!upb_strtable_insert(&s->syms, sym.data, sym.size, v, s->arena)) { - upb_Status_SetErrorMessage(status, "out of memory"); - return false; - } - return true; +size_t _upb_DefPool_BytesLoaded(const upb_DefPool* s) { + return s->bytes_loaded; } -static const void* _upb_DefPool_Unpack(const upb_DefPool* s, const char* sym, - size_t size, upb_deftype_t type) { +upb_Arena* _upb_DefPool_Arena(const upb_DefPool* s) { return s->arena; } + +const upb_FieldDef* upb_DefPool_FindExtensionByMiniTable( + const upb_DefPool* s, const upb_MiniTableExtension* ext) { upb_value v; - return upb_strtable_lookup2(&s->syms, sym, size, &v) - ? _upb_DefType_Unpack(v, type) - : NULL; + bool ok = upb_inttable_lookup(&s->exts, (uintptr_t)ext, &v); + UPB_ASSERT(ok); + return upb_value_getconstptr(v); } -bool _upb_DefPool_LookupSym(const upb_DefPool* s, const char* sym, size_t size, - upb_value* v) { - return upb_strtable_lookup2(&s->syms, sym, size, v); +const upb_FieldDef* upb_DefPool_FindExtensionByNumber(const upb_DefPool* s, + const upb_MessageDef* m, + int32_t fieldnum) { + const upb_MiniTable* t = upb_MessageDef_MiniTable(m); + const upb_MiniTableExtension* ext = + upb_ExtensionRegistry_Lookup(s->extreg, t, fieldnum); + return ext ? upb_DefPool_FindExtensionByMiniTable(s, ext) : NULL; } -upb_ExtensionRegistry* _upb_DefPool_ExtReg(const upb_DefPool* s) { +const upb_ExtensionRegistry* upb_DefPool_ExtensionRegistry( + const upb_DefPool* s) { return s->extreg; } -void** _upb_DefPool_ScratchData(const upb_DefPool* s) { - return (void**)&s->scratch_data; +const upb_FieldDef** upb_DefPool_GetAllExtensions(const upb_DefPool* s, + const upb_MessageDef* m, + size_t* count) { + size_t n = 0; + intptr_t iter = UPB_INTTABLE_BEGIN; + uintptr_t key; + upb_value val; + // This is O(all exts) instead of O(exts for m). If we need this to be + // efficient we may need to make extreg into a two-level table, or have a + // second per-message index. + while (upb_inttable_next(&s->exts, &key, &val, &iter)) { + const upb_FieldDef* f = upb_value_getconstptr(val); + if (upb_FieldDef_ContainingType(f) == m) n++; + } + const upb_FieldDef** exts = upb_gmalloc(n * sizeof(*exts)); + iter = UPB_INTTABLE_BEGIN; + size_t i = 0; + while (upb_inttable_next(&s->exts, &key, &val, &iter)) { + const upb_FieldDef* f = upb_value_getconstptr(val); + if (upb_FieldDef_ContainingType(f) == m) exts[i++] = f; + } + *count = n; + return exts; } -size_t* _upb_DefPool_ScratchSize(const upb_DefPool* s) { - return (size_t*)&s->scratch_size; +bool _upb_DefPool_LoadDefInit(upb_DefPool* s, const _upb_DefPool_Init* init) { + return _upb_DefPool_LoadDefInitEx(s, init, false); } -void _upb_DefPool_SetPlatform(upb_DefPool* s, upb_MiniTablePlatform platform) { - assert(upb_strtable_count(&s->files) == 0); - s->platform = platform; -} -const upb_MessageDef* upb_DefPool_FindMessageByName(const upb_DefPool* s, - const char* sym) { - return _upb_DefPool_Unpack(s, sym, strlen(sym), UPB_DEFTYPE_MSG); -} +// Must be last. -const upb_MessageDef* upb_DefPool_FindMessageByNameWithSize( - const upb_DefPool* s, const char* sym, size_t len) { - return _upb_DefPool_Unpack(s, sym, len, UPB_DEFTYPE_MSG); +upb_deftype_t _upb_DefType_Type(upb_value v) { + const uintptr_t num = (uintptr_t)upb_value_getconstptr(v); + return num & UPB_DEFTYPE_MASK; } -const upb_EnumDef* upb_DefPool_FindEnumByName(const upb_DefPool* s, - const char* sym) { - return _upb_DefPool_Unpack(s, sym, strlen(sym), UPB_DEFTYPE_ENUM); +upb_value _upb_DefType_Pack(const void* ptr, upb_deftype_t type) { + uintptr_t num = (uintptr_t)ptr; + UPB_ASSERT((num & UPB_DEFTYPE_MASK) == 0); + num |= type; + return upb_value_constptr((const void*)num); } -const upb_EnumValueDef* upb_DefPool_FindEnumByNameval(const upb_DefPool* s, - const char* sym) { - return _upb_DefPool_Unpack(s, sym, strlen(sym), UPB_DEFTYPE_ENUMVAL); +const void* _upb_DefType_Unpack(upb_value v, upb_deftype_t type) { + uintptr_t num = (uintptr_t)upb_value_getconstptr(v); + return (num & UPB_DEFTYPE_MASK) == type + ? (const void*)(num & ~UPB_DEFTYPE_MASK) + : NULL; } -const upb_FileDef* upb_DefPool_FindFileByName(const upb_DefPool* s, - const char* name) { - upb_value v; - return upb_strtable_lookup(&s->files, name, &v) ? upb_value_getconstptr(v) - : NULL; -} -const upb_FileDef* upb_DefPool_FindFileByNameWithSize(const upb_DefPool* s, - const char* name, - size_t len) { - upb_value v; - return upb_strtable_lookup2(&s->files, name, len, &v) - ? upb_value_getconstptr(v) - : NULL; -} +// Must be last. -const upb_FieldDef* upb_DefPool_FindExtensionByNameWithSize( - const upb_DefPool* s, const char* name, size_t size) { - upb_value v; - if (!upb_strtable_lookup2(&s->syms, name, size, &v)) return NULL; +bool _upb_DescState_Grow(upb_DescState* d, upb_Arena* a) { + const size_t oldbufsize = d->bufsize; + const int used = d->ptr - d->buf; - switch (_upb_DefType_Type(v)) { - case UPB_DEFTYPE_FIELD: - return _upb_DefType_Unpack(v, UPB_DEFTYPE_FIELD); - case UPB_DEFTYPE_MSG: { - const upb_MessageDef* m = _upb_DefType_Unpack(v, UPB_DEFTYPE_MSG); - return _upb_MessageDef_InMessageSet(m) - ? upb_MessageDef_NestedExtension(m, 0) - : NULL; - } - default: - break; + if (!d->buf) { + d->buf = upb_Arena_Malloc(a, d->bufsize); + if (!d->buf) return false; + d->ptr = d->buf; + d->e.end = d->buf + d->bufsize; } - return NULL; -} + if (oldbufsize - used < kUpb_MtDataEncoder_MinSize) { + d->bufsize *= 2; + d->buf = upb_Arena_Realloc(a, d->buf, oldbufsize, d->bufsize); + if (!d->buf) return false; + d->ptr = d->buf + used; + d->e.end = d->buf + d->bufsize; + } -const upb_FieldDef* upb_DefPool_FindExtensionByName(const upb_DefPool* s, - const char* sym) { - return upb_DefPool_FindExtensionByNameWithSize(s, sym, strlen(sym)); + return true; } -const upb_ServiceDef* upb_DefPool_FindServiceByName(const upb_DefPool* s, - const char* name) { - return _upb_DefPool_Unpack(s, name, strlen(name), UPB_DEFTYPE_SERVICE); -} -const upb_ServiceDef* upb_DefPool_FindServiceByNameWithSize( - const upb_DefPool* s, const char* name, size_t size) { - return _upb_DefPool_Unpack(s, name, size, UPB_DEFTYPE_SERVICE); -} - -const upb_FileDef* upb_DefPool_FindFileContainingSymbol(const upb_DefPool* s, - const char* name) { - upb_value v; - // TODO: non-extension fields and oneofs. - if (upb_strtable_lookup(&s->syms, name, &v)) { - switch (_upb_DefType_Type(v)) { - case UPB_DEFTYPE_EXT: { - const upb_FieldDef* f = _upb_DefType_Unpack(v, UPB_DEFTYPE_EXT); - return upb_FieldDef_File(f); - } - case UPB_DEFTYPE_MSG: { - const upb_MessageDef* m = _upb_DefType_Unpack(v, UPB_DEFTYPE_MSG); - return upb_MessageDef_File(m); - } - case UPB_DEFTYPE_ENUM: { - const upb_EnumDef* e = _upb_DefType_Unpack(v, UPB_DEFTYPE_ENUM); - return upb_EnumDef_File(e); - } - case UPB_DEFTYPE_ENUMVAL: { - const upb_EnumValueDef* ev = - _upb_DefType_Unpack(v, UPB_DEFTYPE_ENUMVAL); - return upb_EnumDef_File(upb_EnumValueDef_Enum(ev)); - } - case UPB_DEFTYPE_SERVICE: { - const upb_ServiceDef* service = - _upb_DefType_Unpack(v, UPB_DEFTYPE_SERVICE); - return upb_ServiceDef_File(service); - } - default: - UPB_UNREACHABLE(); - } - } +#include +#include +#include - const char* last_dot = strrchr(name, '.'); - if (last_dot) { - const upb_MessageDef* parent = - upb_DefPool_FindMessageByNameWithSize(s, name, last_dot - name); - if (parent) { - const char* shortname = last_dot + 1; - if (upb_MessageDef_FindByNameWithSize(parent, shortname, - strlen(shortname), NULL, NULL)) { - return upb_MessageDef_File(parent); - } - } - } - return NULL; -} +// Must be last. -static void remove_filedef(upb_DefPool* s, upb_FileDef* file) { - intptr_t iter = UPB_INTTABLE_BEGIN; - upb_StringView key; - upb_value val; - while (upb_strtable_next2(&s->syms, &key, &val, &iter)) { - const upb_FileDef* f; - switch (_upb_DefType_Type(val)) { - case UPB_DEFTYPE_EXT: - f = upb_FieldDef_File(_upb_DefType_Unpack(val, UPB_DEFTYPE_EXT)); - break; - case UPB_DEFTYPE_MSG: - f = upb_MessageDef_File(_upb_DefType_Unpack(val, UPB_DEFTYPE_MSG)); - break; - case UPB_DEFTYPE_ENUM: - f = upb_EnumDef_File(_upb_DefType_Unpack(val, UPB_DEFTYPE_ENUM)); - break; - case UPB_DEFTYPE_ENUMVAL: - f = upb_EnumDef_File(upb_EnumValueDef_Enum( - _upb_DefType_Unpack(val, UPB_DEFTYPE_ENUMVAL))); - break; - case UPB_DEFTYPE_SERVICE: - f = upb_ServiceDef_File(_upb_DefType_Unpack(val, UPB_DEFTYPE_SERVICE)); - break; - default: - UPB_UNREACHABLE(); - } +struct upb_EnumDef { + const UPB_DESC(EnumOptions*) opts; + const UPB_DESC(FeatureSet*) resolved_features; + const upb_MiniTableEnum* layout; // Only for proto2. + const upb_FileDef* file; + const upb_MessageDef* containing_type; // Could be merged with "file". + const char* full_name; + upb_strtable ntoi; + upb_inttable iton; + const upb_EnumValueDef* values; + const upb_EnumReservedRange* res_ranges; + const upb_StringView* res_names; + int value_count; + int res_range_count; + int res_name_count; + int32_t defaultval; + bool is_sorted; // Whether all of the values are defined in ascending order. +#if UINTPTR_MAX == 0xffffffff + uint32_t padding; // Increase size to a multiple of 8. +#endif +}; - if (f == file) upb_strtable_removeiter(&s->syms, &iter); - } +upb_EnumDef* _upb_EnumDef_At(const upb_EnumDef* e, int i) { + return (upb_EnumDef*)&e[i]; } -static const upb_FileDef* upb_DefBuilder_AddFileToPool( - upb_DefBuilder* const builder, upb_DefPool* const s, - const UPB_DESC(FileDescriptorProto) * const file_proto, - const upb_StringView name, upb_Status* const status) { - if (UPB_SETJMP(builder->err) != 0) { - UPB_ASSERT(!upb_Status_IsOk(status)); - if (builder->file) { - remove_filedef(s, builder->file); - builder->file = NULL; - } - } else if (!builder->arena || !builder->tmp_arena || - !upb_strtable_init(&builder->feature_cache, 16, - builder->tmp_arena) || - !(builder->legacy_features = - UPB_DESC(FeatureSet_new)(builder->tmp_arena))) { - _upb_DefBuilder_OomErr(builder); - } else { - _upb_FileDef_Create(builder, file_proto); - upb_strtable_insert(&s->files, name.data, name.size, - upb_value_constptr(builder->file), builder->arena); - UPB_ASSERT(upb_Status_IsOk(status)); - upb_Arena_Fuse(s->arena, builder->arena); - } - - if (builder->arena) upb_Arena_Free(builder->arena); - if (builder->tmp_arena) upb_Arena_Free(builder->tmp_arena); - return builder->file; +const upb_MiniTableEnum* _upb_EnumDef_MiniTable(const upb_EnumDef* e) { + return e->layout; } -static const upb_FileDef* _upb_DefPool_AddFile( - upb_DefPool* s, const UPB_DESC(FileDescriptorProto) * file_proto, - const upb_MiniTableFile* layout, upb_Status* status) { - const upb_StringView name = UPB_DESC(FileDescriptorProto_name)(file_proto); +bool _upb_EnumDef_Insert(upb_EnumDef* e, upb_EnumValueDef* v, upb_Arena* a) { + const char* name = upb_EnumValueDef_Name(v); + const upb_value val = upb_value_constptr(v); + bool ok = upb_strtable_insert(&e->ntoi, name, strlen(name), val, a); + if (!ok) return false; - // Determine whether we already know about this file. - { - upb_value v; - if (upb_strtable_lookup2(&s->files, name.data, name.size, &v)) { - upb_Status_SetErrorFormat(status, - "duplicate file name " UPB_STRINGVIEW_FORMAT, - UPB_STRINGVIEW_ARGS(name)); - return NULL; - } + // Multiple enumerators can have the same number, first one wins. + const int number = upb_EnumValueDef_Number(v); + if (!upb_inttable_lookup(&e->iton, number, NULL)) { + return upb_inttable_insert(&e->iton, number, val, a); } - - upb_DefBuilder ctx = { - .symtab = s, - .tmp_buf = NULL, - .tmp_buf_size = 0, - .layout = layout, - .platform = s->platform, - .msg_count = 0, - .enum_count = 0, - .ext_count = 0, - .status = status, - .file = NULL, - .arena = upb_Arena_New(), - .tmp_arena = upb_Arena_New(), - }; - - return upb_DefBuilder_AddFileToPool(&ctx, s, file_proto, name, status); + return true; } -const upb_FileDef* upb_DefPool_AddFile(upb_DefPool* s, - const UPB_DESC(FileDescriptorProto) * - file_proto, - upb_Status* status) { - return _upb_DefPool_AddFile(s, file_proto, NULL, status); +const UPB_DESC(EnumOptions) * upb_EnumDef_Options(const upb_EnumDef* e) { + return e->opts; } -bool _upb_DefPool_LoadDefInitEx(upb_DefPool* s, const _upb_DefPool_Init* init, - bool rebuild_minitable) { - /* Since this function should never fail (it would indicate a bug in upb) we - * print errors to stderr instead of returning error status to the user. */ - _upb_DefPool_Init** deps = init->deps; - UPB_DESC(FileDescriptorProto) * file; - upb_Arena* arena; - upb_Status status; +bool upb_EnumDef_HasOptions(const upb_EnumDef* e) { + return e->opts != (void*)kUpbDefOptDefault; +} - upb_Status_Clear(&status); +const UPB_DESC(FeatureSet) * + upb_EnumDef_ResolvedFeatures(const upb_EnumDef* e) { + return e->resolved_features; +} - if (upb_DefPool_FindFileByName(s, init->filename)) { - return true; - } +const char* upb_EnumDef_FullName(const upb_EnumDef* e) { return e->full_name; } - arena = upb_Arena_New(); +const char* upb_EnumDef_Name(const upb_EnumDef* e) { + return _upb_DefBuilder_FullToShort(e->full_name); +} - for (; *deps; deps++) { - if (!_upb_DefPool_LoadDefInitEx(s, *deps, rebuild_minitable)) goto err; - } +const upb_FileDef* upb_EnumDef_File(const upb_EnumDef* e) { return e->file; } - file = UPB_DESC(FileDescriptorProto_parse_ex)( - init->descriptor.data, init->descriptor.size, NULL, - kUpb_DecodeOption_AliasString, arena); - s->bytes_loaded += init->descriptor.size; +const upb_MessageDef* upb_EnumDef_ContainingType(const upb_EnumDef* e) { + return e->containing_type; +} - if (!file) { - upb_Status_SetErrorFormat( - &status, - "Failed to parse compiled-in descriptor for file '%s'. This should " - "never happen.", - init->filename); - goto err; - } +int32_t upb_EnumDef_Default(const upb_EnumDef* e) { + UPB_ASSERT(upb_EnumDef_FindValueByNumber(e, e->defaultval)); + return e->defaultval; +} - const upb_MiniTableFile* mt = rebuild_minitable ? NULL : init->layout; - if (!_upb_DefPool_AddFile(s, file, mt, &status)) { - goto err; - } +int upb_EnumDef_ReservedRangeCount(const upb_EnumDef* e) { + return e->res_range_count; +} - upb_Arena_Free(arena); - return true; +const upb_EnumReservedRange* upb_EnumDef_ReservedRange(const upb_EnumDef* e, + int i) { + UPB_ASSERT(0 <= i && i < e->res_range_count); + return _upb_EnumReservedRange_At(e->res_ranges, i); +} -err: - fprintf(stderr, - "Error loading compiled-in descriptor for file '%s' (this should " - "never happen): %s\n", - init->filename, upb_Status_ErrorMessage(&status)); - upb_Arena_Free(arena); - return false; +int upb_EnumDef_ReservedNameCount(const upb_EnumDef* e) { + return e->res_name_count; } -size_t _upb_DefPool_BytesLoaded(const upb_DefPool* s) { - return s->bytes_loaded; +upb_StringView upb_EnumDef_ReservedName(const upb_EnumDef* e, int i) { + UPB_ASSERT(0 <= i && i < e->res_name_count); + return e->res_names[i]; } -upb_Arena* _upb_DefPool_Arena(const upb_DefPool* s) { return s->arena; } - -const upb_FieldDef* upb_DefPool_FindExtensionByMiniTable( - const upb_DefPool* s, const upb_MiniTableExtension* ext) { - upb_value v; - bool ok = upb_inttable_lookup(&s->exts, (uintptr_t)ext, &v); - UPB_ASSERT(ok); - return upb_value_getconstptr(v); -} - -const upb_FieldDef* upb_DefPool_FindExtensionByNumber(const upb_DefPool* s, - const upb_MessageDef* m, - int32_t fieldnum) { - const upb_MiniTable* t = upb_MessageDef_MiniTable(m); - const upb_MiniTableExtension* ext = - upb_ExtensionRegistry_Lookup(s->extreg, t, fieldnum); - return ext ? upb_DefPool_FindExtensionByMiniTable(s, ext) : NULL; -} - -const upb_ExtensionRegistry* upb_DefPool_ExtensionRegistry( - const upb_DefPool* s) { - return s->extreg; -} - -const upb_FieldDef** upb_DefPool_GetAllExtensions(const upb_DefPool* s, - const upb_MessageDef* m, - size_t* count) { - size_t n = 0; - intptr_t iter = UPB_INTTABLE_BEGIN; - uintptr_t key; - upb_value val; - // This is O(all exts) instead of O(exts for m). If we need this to be - // efficient we may need to make extreg into a two-level table, or have a - // second per-message index. - while (upb_inttable_next(&s->exts, &key, &val, &iter)) { - const upb_FieldDef* f = upb_value_getconstptr(val); - if (upb_FieldDef_ContainingType(f) == m) n++; - } - const upb_FieldDef** exts = upb_gmalloc(n * sizeof(*exts)); - iter = UPB_INTTABLE_BEGIN; - size_t i = 0; - while (upb_inttable_next(&s->exts, &key, &val, &iter)) { - const upb_FieldDef* f = upb_value_getconstptr(val); - if (upb_FieldDef_ContainingType(f) == m) exts[i++] = f; - } - *count = n; - return exts; -} - -bool _upb_DefPool_LoadDefInit(upb_DefPool* s, const _upb_DefPool_Init* init) { - return _upb_DefPool_LoadDefInitEx(s, init, false); -} - - -// Must be last. - -upb_deftype_t _upb_DefType_Type(upb_value v) { - const uintptr_t num = (uintptr_t)upb_value_getconstptr(v); - return num & UPB_DEFTYPE_MASK; -} - -upb_value _upb_DefType_Pack(const void* ptr, upb_deftype_t type) { - uintptr_t num = (uintptr_t)ptr; - UPB_ASSERT((num & UPB_DEFTYPE_MASK) == 0); - num |= type; - return upb_value_constptr((const void*)num); -} - -const void* _upb_DefType_Unpack(upb_value v, upb_deftype_t type) { - uintptr_t num = (uintptr_t)upb_value_getconstptr(v); - return (num & UPB_DEFTYPE_MASK) == type - ? (const void*)(num & ~UPB_DEFTYPE_MASK) - : NULL; -} - - -// Must be last. - -bool _upb_DescState_Grow(upb_DescState* d, upb_Arena* a) { - const size_t oldbufsize = d->bufsize; - const int used = d->ptr - d->buf; - - if (!d->buf) { - d->buf = upb_Arena_Malloc(a, d->bufsize); - if (!d->buf) return false; - d->ptr = d->buf; - d->e.end = d->buf + d->bufsize; - } - - if (oldbufsize - used < kUpb_MtDataEncoder_MinSize) { - d->bufsize *= 2; - d->buf = upb_Arena_Realloc(a, d->buf, oldbufsize, d->bufsize); - if (!d->buf) return false; - d->ptr = d->buf + used; - d->e.end = d->buf + d->bufsize; - } - - return true; -} - - -#include -#include -#include - - -// Must be last. - -struct upb_EnumDef { - const UPB_DESC(EnumOptions*) opts; - const UPB_DESC(FeatureSet*) resolved_features; - const upb_MiniTableEnum* layout; // Only for proto2. - const upb_FileDef* file; - const upb_MessageDef* containing_type; // Could be merged with "file". - const char* full_name; - upb_strtable ntoi; - upb_inttable iton; - const upb_EnumValueDef* values; - const upb_EnumReservedRange* res_ranges; - const upb_StringView* res_names; - int value_count; - int res_range_count; - int res_name_count; - int32_t defaultval; - bool is_sorted; // Whether all of the values are defined in ascending order. -#if UINTPTR_MAX == 0xffffffff - uint32_t padding; // Increase size to a multiple of 8. -#endif -}; - -upb_EnumDef* _upb_EnumDef_At(const upb_EnumDef* e, int i) { - return (upb_EnumDef*)&e[i]; -} - -const upb_MiniTableEnum* _upb_EnumDef_MiniTable(const upb_EnumDef* e) { - return e->layout; -} - -bool _upb_EnumDef_Insert(upb_EnumDef* e, upb_EnumValueDef* v, upb_Arena* a) { - const char* name = upb_EnumValueDef_Name(v); - const upb_value val = upb_value_constptr(v); - bool ok = upb_strtable_insert(&e->ntoi, name, strlen(name), val, a); - if (!ok) return false; - - // Multiple enumerators can have the same number, first one wins. - const int number = upb_EnumValueDef_Number(v); - if (!upb_inttable_lookup(&e->iton, number, NULL)) { - return upb_inttable_insert(&e->iton, number, val, a); - } - return true; -} - -const UPB_DESC(EnumOptions) * upb_EnumDef_Options(const upb_EnumDef* e) { - return e->opts; -} - -bool upb_EnumDef_HasOptions(const upb_EnumDef* e) { - return e->opts != (void*)kUpbDefOptDefault; -} - -const UPB_DESC(FeatureSet) * - upb_EnumDef_ResolvedFeatures(const upb_EnumDef* e) { - return e->resolved_features; -} - -const char* upb_EnumDef_FullName(const upb_EnumDef* e) { return e->full_name; } - -const char* upb_EnumDef_Name(const upb_EnumDef* e) { - return _upb_DefBuilder_FullToShort(e->full_name); -} - -const upb_FileDef* upb_EnumDef_File(const upb_EnumDef* e) { return e->file; } - -const upb_MessageDef* upb_EnumDef_ContainingType(const upb_EnumDef* e) { - return e->containing_type; -} - -int32_t upb_EnumDef_Default(const upb_EnumDef* e) { - UPB_ASSERT(upb_EnumDef_FindValueByNumber(e, e->defaultval)); - return e->defaultval; -} - -int upb_EnumDef_ReservedRangeCount(const upb_EnumDef* e) { - return e->res_range_count; -} - -const upb_EnumReservedRange* upb_EnumDef_ReservedRange(const upb_EnumDef* e, - int i) { - UPB_ASSERT(0 <= i && i < e->res_range_count); - return _upb_EnumReservedRange_At(e->res_ranges, i); -} - -int upb_EnumDef_ReservedNameCount(const upb_EnumDef* e) { - return e->res_name_count; -} - -upb_StringView upb_EnumDef_ReservedName(const upb_EnumDef* e, int i) { - UPB_ASSERT(0 <= i && i < e->res_name_count); - return e->res_names[i]; -} - -int upb_EnumDef_ValueCount(const upb_EnumDef* e) { return e->value_count; } +int upb_EnumDef_ValueCount(const upb_EnumDef* e) { return e->value_count; } const upb_EnumValueDef* upb_EnumDef_FindValueByName(const upb_EnumDef* e, const char* name) { @@ -15190,214 +14860,544 @@ static void fastdecode_docopy(upb_Decoder* d, const char* ptr, uint32_t size, #define s_VALIDATE true #define b_VALIDATE false -#define F(card, tagbytes, type) \ - UPB_NOINLINE \ - const char* upb_c##card##type##_##tagbytes##bt(UPB_PARSE_PARAMS) { \ - FASTDECODE_COPYSTRING(d, ptr, msg, table, hasbits, data, tagbytes, \ - CARD_##card, type##_VALIDATE); \ - } \ - const char* upb_p##card##type##_##tagbytes##bt(UPB_PARSE_PARAMS) { \ - FASTDECODE_STRING(d, ptr, msg, table, hasbits, data, tagbytes, \ - CARD_##card, upb_c##card##type##_##tagbytes##bt, \ - type##_VALIDATE); \ +#define F(card, tagbytes, type) \ + UPB_NOINLINE \ + const char* upb_c##card##type##_##tagbytes##bt(UPB_PARSE_PARAMS) { \ + FASTDECODE_COPYSTRING(d, ptr, msg, table, hasbits, data, tagbytes, \ + CARD_##card, type##_VALIDATE); \ + } \ + const char* upb_p##card##type##_##tagbytes##bt(UPB_PARSE_PARAMS) { \ + FASTDECODE_STRING(d, ptr, msg, table, hasbits, data, tagbytes, \ + CARD_##card, upb_c##card##type##_##tagbytes##bt, \ + type##_VALIDATE); \ + } + +#define UTF8(card, tagbytes) \ + F(card, tagbytes, s) \ + F(card, tagbytes, b) + +#define TAGBYTES(card) \ + UTF8(card, 1) \ + UTF8(card, 2) + +TAGBYTES(s) +TAGBYTES(o) +TAGBYTES(r) + +#undef s_VALIDATE +#undef b_VALIDATE +#undef F +#undef TAGBYTES +#undef FASTDECODE_LONGSTRING +#undef FASTDECODE_COPYSTRING +#undef FASTDECODE_STRING + +/* message fields *************************************************************/ + +UPB_INLINE +upb_Message* decode_newmsg_ceil(upb_Decoder* d, const upb_MiniTable* m, + int msg_ceil_bytes) { + size_t size = m->UPB_PRIVATE(size) + sizeof(upb_Message_Internal); + char* msg_data; + if (UPB_LIKELY(msg_ceil_bytes > 0 && + UPB_PRIVATE(_upb_ArenaHas)(&d->arena) >= msg_ceil_bytes)) { + UPB_ASSERT(size <= (size_t)msg_ceil_bytes); + msg_data = d->arena.UPB_PRIVATE(ptr); + d->arena.UPB_PRIVATE(ptr) += size; + UPB_UNPOISON_MEMORY_REGION(msg_data, msg_ceil_bytes); + memset(msg_data, 0, msg_ceil_bytes); + UPB_POISON_MEMORY_REGION(msg_data + size, msg_ceil_bytes - size); + } else { + msg_data = (char*)upb_Arena_Malloc(&d->arena, size); + memset(msg_data, 0, size); + } + return msg_data + sizeof(upb_Message_Internal); +} + +typedef struct { + intptr_t table; + upb_Message* msg; +} fastdecode_submsgdata; + +UPB_FORCEINLINE +static const char* fastdecode_tosubmsg(upb_EpsCopyInputStream* e, + const char* ptr, void* ctx) { + upb_Decoder* d = (upb_Decoder*)e; + fastdecode_submsgdata* submsg = ctx; + ptr = fastdecode_dispatch(d, ptr, submsg->msg, submsg->table, 0, 0); + UPB_ASSUME(ptr != NULL); + return ptr; +} + +#define FASTDECODE_SUBMSG(d, ptr, msg, table, hasbits, data, tagbytes, \ + msg_ceil_bytes, card) \ + \ + if (UPB_UNLIKELY(!fastdecode_checktag(data, tagbytes))) { \ + RETURN_GENERIC("submessage field tag mismatch\n"); \ + } \ + \ + if (--d->depth == 0) { \ + _upb_FastDecoder_ErrorJmp(d, kUpb_DecodeStatus_MaxDepthExceeded); \ + } \ + \ + upb_Message** dst; \ + uint32_t submsg_idx = (data >> 16) & 0xff; \ + const upb_MiniTable* tablep = decode_totablep(table); \ + const upb_MiniTable* subtablep = upb_MiniTableSub_Message( \ + *UPB_PRIVATE(_upb_MiniTable_GetSubByIndex)(tablep, submsg_idx)); \ + fastdecode_submsgdata submsg = {decode_totable(subtablep)}; \ + fastdecode_arr farr; \ + \ + if (subtablep->UPB_PRIVATE(table_mask) == (uint8_t)-1) { \ + d->depth++; \ + RETURN_GENERIC("submessage doesn't have fast tables."); \ + } \ + \ + dst = fastdecode_getfield(d, ptr, msg, &data, &hasbits, &farr, \ + sizeof(upb_Message*), card); \ + \ + if (card == CARD_s) { \ + *(uint32_t*)msg |= hasbits; \ + hasbits = 0; \ + } \ + \ + again: \ + if (card == CARD_r) { \ + dst = fastdecode_resizearr(d, dst, &farr, sizeof(upb_Message*)); \ + } \ + \ + submsg.msg = *dst; \ + \ + if (card == CARD_r || UPB_LIKELY(!submsg.msg)) { \ + *dst = submsg.msg = decode_newmsg_ceil(d, subtablep, msg_ceil_bytes); \ + } \ + \ + ptr += tagbytes; \ + ptr = fastdecode_delimited(d, ptr, fastdecode_tosubmsg, &submsg); \ + \ + if (UPB_UNLIKELY(ptr == NULL || d->end_group != DECODE_NOGROUP)) { \ + _upb_FastDecoder_ErrorJmp(d, kUpb_DecodeStatus_Malformed); \ + } \ + \ + if (card == CARD_r) { \ + fastdecode_nextret ret = fastdecode_nextrepeated( \ + d, dst, &ptr, &farr, data, tagbytes, sizeof(upb_Message*)); \ + switch (ret.next) { \ + case FD_NEXT_SAMEFIELD: \ + dst = ret.dst; \ + goto again; \ + case FD_NEXT_OTHERFIELD: \ + d->depth++; \ + data = ret.tag; \ + UPB_MUSTTAIL return _upb_FastDecoder_TagDispatch(UPB_PARSE_ARGS); \ + case FD_NEXT_ATLIMIT: \ + d->depth++; \ + return ptr; \ + } \ + } \ + \ + d->depth++; \ + UPB_MUSTTAIL return fastdecode_dispatch(UPB_PARSE_ARGS); + +#define F(card, tagbytes, size_ceil, ceil_arg) \ + const char* upb_p##card##m_##tagbytes##bt_max##size_ceil##b( \ + UPB_PARSE_PARAMS) { \ + FASTDECODE_SUBMSG(d, ptr, msg, table, hasbits, data, tagbytes, ceil_arg, \ + CARD_##card); \ + } + +#define SIZES(card, tagbytes) \ + F(card, tagbytes, 64, 64) \ + F(card, tagbytes, 128, 128) \ + F(card, tagbytes, 192, 192) \ + F(card, tagbytes, 256, 256) \ + F(card, tagbytes, max, -1) + +#define TAGBYTES(card) \ + SIZES(card, 1) \ + SIZES(card, 2) + +TAGBYTES(s) +TAGBYTES(o) +TAGBYTES(r) + +#undef TAGBYTES +#undef SIZES +#undef F +#undef FASTDECODE_SUBMSG + +#endif /* UPB_FASTTABLE */ + + +#include +#include + + +// Must be last. + +UPB_NOINLINE UPB_PRIVATE(_upb_WireReader_LongVarint) + UPB_PRIVATE(_upb_WireReader_ReadLongVarint)(const char* ptr, uint64_t val) { + UPB_PRIVATE(_upb_WireReader_LongVarint) ret = {NULL, 0}; + uint64_t byte; + int i; + for (i = 1; i < 10; i++) { + byte = (uint8_t)ptr[i]; + val += (byte - 1) << (i * 7); + if (!(byte & 0x80)) { + ret.ptr = ptr + i + 1; + ret.val = val; + return ret; + } + } + return ret; +} + +const char* UPB_PRIVATE(_upb_WireReader_SkipGroup)( + const char* ptr, uint32_t tag, int depth_limit, + upb_EpsCopyInputStream* stream) { + if (--depth_limit == 0) return NULL; + uint32_t end_group_tag = (tag & ~7ULL) | kUpb_WireType_EndGroup; + while (!upb_EpsCopyInputStream_IsDone(stream, &ptr)) { + uint32_t tag; + ptr = upb_WireReader_ReadTag(ptr, &tag); + if (!ptr) return NULL; + if (tag == end_group_tag) return ptr; + ptr = _upb_WireReader_SkipValue(ptr, tag, depth_limit, stream); + if (!ptr) return NULL; + } + return ptr; +} + + +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, +}; + + +#include +#include +#include + + +// Must be last. + +typedef struct { + uint64_t present_values_mask; + uint32_t last_written_value; +} upb_MtDataEncoderInternal_EnumState; + +typedef struct { + uint64_t msg_modifiers; + uint32_t last_field_num; + enum { + kUpb_OneofState_NotStarted, + kUpb_OneofState_StartedOneof, + kUpb_OneofState_EmittedOneofField, + } oneof_state; +} upb_MtDataEncoderInternal_MsgState; + +typedef struct { + char* buf_start; // Only for checking kUpb_MtDataEncoder_MinSize. + union { + upb_MtDataEncoderInternal_EnumState enum_state; + upb_MtDataEncoderInternal_MsgState msg_state; + } state; +} upb_MtDataEncoderInternal; + +static upb_MtDataEncoderInternal* upb_MtDataEncoder_GetInternal( + upb_MtDataEncoder* e, char* buf_start) { + UPB_ASSERT(sizeof(upb_MtDataEncoderInternal) <= sizeof(e->internal)); + upb_MtDataEncoderInternal* ret = (upb_MtDataEncoderInternal*)e->internal; + ret->buf_start = buf_start; + return ret; +} + +static char* upb_MtDataEncoder_PutRaw(upb_MtDataEncoder* e, char* ptr, + char ch) { + upb_MtDataEncoderInternal* in = (upb_MtDataEncoderInternal*)e->internal; + UPB_ASSERT(ptr - in->buf_start < kUpb_MtDataEncoder_MinSize); + if (ptr == e->end) return NULL; + *ptr++ = ch; + return ptr; +} + +static char* upb_MtDataEncoder_Put(upb_MtDataEncoder* e, char* ptr, char ch) { + return upb_MtDataEncoder_PutRaw(e, ptr, _upb_ToBase92(ch)); +} + +static char* upb_MtDataEncoder_PutBase92Varint(upb_MtDataEncoder* e, char* ptr, + uint32_t val, int min, int max) { + int shift = upb_Log2Ceiling(_upb_FromBase92(max) - _upb_FromBase92(min) + 1); + UPB_ASSERT(shift <= 6); + uint32_t mask = (1 << shift) - 1; + do { + uint32_t bits = val & mask; + ptr = upb_MtDataEncoder_Put(e, ptr, bits + _upb_FromBase92(min)); + if (!ptr) return NULL; + val >>= shift; + } while (val); + return ptr; +} + +char* upb_MtDataEncoder_PutModifier(upb_MtDataEncoder* e, char* ptr, + uint64_t mod) { + if (mod) { + ptr = upb_MtDataEncoder_PutBase92Varint(e, ptr, mod, + kUpb_EncodedValue_MinModifier, + kUpb_EncodedValue_MaxModifier); + } + return ptr; +} + +char* upb_MtDataEncoder_EncodeExtension(upb_MtDataEncoder* e, char* ptr, + upb_FieldType type, uint32_t field_num, + uint64_t field_mod) { + upb_MtDataEncoderInternal* in = upb_MtDataEncoder_GetInternal(e, ptr); + in->state.msg_state.msg_modifiers = 0; + in->state.msg_state.last_field_num = 0; + in->state.msg_state.oneof_state = kUpb_OneofState_NotStarted; + + ptr = upb_MtDataEncoder_PutRaw(e, ptr, kUpb_EncodedVersion_ExtensionV1); + if (!ptr) return NULL; + + return upb_MtDataEncoder_PutField(e, ptr, type, field_num, field_mod); +} + +char* upb_MtDataEncoder_EncodeMap(upb_MtDataEncoder* e, char* ptr, + upb_FieldType key_type, + upb_FieldType value_type, uint64_t key_mod, + uint64_t value_mod) { + upb_MtDataEncoderInternal* in = upb_MtDataEncoder_GetInternal(e, ptr); + in->state.msg_state.msg_modifiers = 0; + in->state.msg_state.last_field_num = 0; + in->state.msg_state.oneof_state = kUpb_OneofState_NotStarted; + + ptr = upb_MtDataEncoder_PutRaw(e, ptr, kUpb_EncodedVersion_MapV1); + if (!ptr) return NULL; + + ptr = upb_MtDataEncoder_PutField(e, ptr, key_type, 1, key_mod); + if (!ptr) return NULL; + + return upb_MtDataEncoder_PutField(e, ptr, value_type, 2, value_mod); +} + +char* upb_MtDataEncoder_EncodeMessageSet(upb_MtDataEncoder* e, char* ptr) { + (void)upb_MtDataEncoder_GetInternal(e, ptr); + return upb_MtDataEncoder_PutRaw(e, ptr, kUpb_EncodedVersion_MessageSetV1); +} + +char* upb_MtDataEncoder_StartMessage(upb_MtDataEncoder* e, char* ptr, + uint64_t msg_mod) { + upb_MtDataEncoderInternal* in = upb_MtDataEncoder_GetInternal(e, ptr); + in->state.msg_state.msg_modifiers = msg_mod; + in->state.msg_state.last_field_num = 0; + in->state.msg_state.oneof_state = kUpb_OneofState_NotStarted; + + ptr = upb_MtDataEncoder_PutRaw(e, ptr, kUpb_EncodedVersion_MessageV1); + if (!ptr) return NULL; + + return upb_MtDataEncoder_PutModifier(e, ptr, msg_mod); +} + +static char* _upb_MtDataEncoder_MaybePutFieldSkip(upb_MtDataEncoder* e, + char* ptr, + uint32_t field_num) { + upb_MtDataEncoderInternal* in = (upb_MtDataEncoderInternal*)e->internal; + if (field_num <= in->state.msg_state.last_field_num) return NULL; + if (in->state.msg_state.last_field_num + 1 != field_num) { + // Put skip. + UPB_ASSERT(field_num > in->state.msg_state.last_field_num); + uint32_t skip = field_num - in->state.msg_state.last_field_num; + ptr = upb_MtDataEncoder_PutBase92Varint( + e, ptr, skip, kUpb_EncodedValue_MinSkip, kUpb_EncodedValue_MaxSkip); + if (!ptr) return NULL; + } + in->state.msg_state.last_field_num = field_num; + return ptr; +} + +static char* _upb_MtDataEncoder_PutFieldType(upb_MtDataEncoder* e, char* ptr, + upb_FieldType type, + uint64_t field_mod) { + static const char kUpb_TypeToEncoded[] = { + [kUpb_FieldType_Double] = kUpb_EncodedType_Double, + [kUpb_FieldType_Float] = kUpb_EncodedType_Float, + [kUpb_FieldType_Int64] = kUpb_EncodedType_Int64, + [kUpb_FieldType_UInt64] = kUpb_EncodedType_UInt64, + [kUpb_FieldType_Int32] = kUpb_EncodedType_Int32, + [kUpb_FieldType_Fixed64] = kUpb_EncodedType_Fixed64, + [kUpb_FieldType_Fixed32] = kUpb_EncodedType_Fixed32, + [kUpb_FieldType_Bool] = kUpb_EncodedType_Bool, + [kUpb_FieldType_String] = kUpb_EncodedType_String, + [kUpb_FieldType_Group] = kUpb_EncodedType_Group, + [kUpb_FieldType_Message] = kUpb_EncodedType_Message, + [kUpb_FieldType_Bytes] = kUpb_EncodedType_Bytes, + [kUpb_FieldType_UInt32] = kUpb_EncodedType_UInt32, + [kUpb_FieldType_Enum] = kUpb_EncodedType_OpenEnum, + [kUpb_FieldType_SFixed32] = kUpb_EncodedType_SFixed32, + [kUpb_FieldType_SFixed64] = kUpb_EncodedType_SFixed64, + [kUpb_FieldType_SInt32] = kUpb_EncodedType_SInt32, + [kUpb_FieldType_SInt64] = kUpb_EncodedType_SInt64, + }; + + int encoded_type = kUpb_TypeToEncoded[type]; + + if (field_mod & kUpb_FieldModifier_IsClosedEnum) { + UPB_ASSERT(type == kUpb_FieldType_Enum); + encoded_type = kUpb_EncodedType_ClosedEnum; + } + + if (field_mod & kUpb_FieldModifier_IsRepeated) { + // Repeated fields shift the type number up (unlike other modifiers which + // are bit flags). + encoded_type += kUpb_EncodedType_RepeatedBase; + } + + return upb_MtDataEncoder_Put(e, ptr, encoded_type); +} + +static char* _upb_MtDataEncoder_MaybePutModifiers(upb_MtDataEncoder* e, + char* ptr, upb_FieldType type, + uint64_t field_mod) { + upb_MtDataEncoderInternal* in = (upb_MtDataEncoderInternal*)e->internal; + uint32_t encoded_modifiers = 0; + if ((field_mod & kUpb_FieldModifier_IsRepeated) && + upb_FieldType_IsPackable(type)) { + bool field_is_packed = field_mod & kUpb_FieldModifier_IsPacked; + bool default_is_packed = in->state.msg_state.msg_modifiers & + kUpb_MessageModifier_DefaultIsPacked; + if (field_is_packed != default_is_packed) { + encoded_modifiers |= kUpb_EncodedFieldModifier_FlipPacked; + } + } + + if (type == kUpb_FieldType_String) { + bool field_validates_utf8 = field_mod & kUpb_FieldModifier_ValidateUtf8; + bool message_validates_utf8 = + in->state.msg_state.msg_modifiers & kUpb_MessageModifier_ValidateUtf8; + if (field_validates_utf8 != message_validates_utf8) { + // Old binaries do not recognize the field modifier. We need the failure + // mode to be too lax rather than too strict. Our caller should have + // handled this (see _upb_MessageDef_ValidateUtf8()). + assert(!message_validates_utf8); + encoded_modifiers |= kUpb_EncodedFieldModifier_FlipValidateUtf8; + } + } + + if (field_mod & kUpb_FieldModifier_IsProto3Singular) { + encoded_modifiers |= kUpb_EncodedFieldModifier_IsProto3Singular; + } + + if (field_mod & kUpb_FieldModifier_IsRequired) { + encoded_modifiers |= kUpb_EncodedFieldModifier_IsRequired; } -#define UTF8(card, tagbytes) \ - F(card, tagbytes, s) \ - F(card, tagbytes, b) + return upb_MtDataEncoder_PutModifier(e, ptr, encoded_modifiers); +} -#define TAGBYTES(card) \ - UTF8(card, 1) \ - UTF8(card, 2) +char* upb_MtDataEncoder_PutField(upb_MtDataEncoder* e, char* ptr, + upb_FieldType type, uint32_t field_num, + uint64_t field_mod) { + upb_MtDataEncoder_GetInternal(e, ptr); -TAGBYTES(s) -TAGBYTES(o) -TAGBYTES(r) + ptr = _upb_MtDataEncoder_MaybePutFieldSkip(e, ptr, field_num); + if (!ptr) return NULL; -#undef s_VALIDATE -#undef b_VALIDATE -#undef F -#undef TAGBYTES -#undef FASTDECODE_LONGSTRING -#undef FASTDECODE_COPYSTRING -#undef FASTDECODE_STRING + ptr = _upb_MtDataEncoder_PutFieldType(e, ptr, type, field_mod); + if (!ptr) return NULL; -/* message fields *************************************************************/ + return _upb_MtDataEncoder_MaybePutModifiers(e, ptr, type, field_mod); +} -UPB_INLINE -upb_Message* decode_newmsg_ceil(upb_Decoder* d, const upb_MiniTable* m, - int msg_ceil_bytes) { - size_t size = m->UPB_PRIVATE(size) + sizeof(upb_Message_Internal); - char* msg_data; - if (UPB_LIKELY(msg_ceil_bytes > 0 && - UPB_PRIVATE(_upb_ArenaHas)(&d->arena) >= msg_ceil_bytes)) { - UPB_ASSERT(size <= (size_t)msg_ceil_bytes); - msg_data = d->arena.UPB_PRIVATE(ptr); - d->arena.UPB_PRIVATE(ptr) += size; - UPB_UNPOISON_MEMORY_REGION(msg_data, msg_ceil_bytes); - memset(msg_data, 0, msg_ceil_bytes); - UPB_POISON_MEMORY_REGION(msg_data + size, msg_ceil_bytes - size); +char* upb_MtDataEncoder_StartOneof(upb_MtDataEncoder* e, char* ptr) { + upb_MtDataEncoderInternal* in = upb_MtDataEncoder_GetInternal(e, ptr); + if (in->state.msg_state.oneof_state == kUpb_OneofState_NotStarted) { + ptr = upb_MtDataEncoder_Put(e, ptr, _upb_FromBase92(kUpb_EncodedValue_End)); } else { - msg_data = (char*)upb_Arena_Malloc(&d->arena, size); - memset(msg_data, 0, size); + ptr = upb_MtDataEncoder_Put( + e, ptr, _upb_FromBase92(kUpb_EncodedValue_OneofSeparator)); } - return msg_data + sizeof(upb_Message_Internal); -} - -typedef struct { - intptr_t table; - upb_Message* msg; -} fastdecode_submsgdata; - -UPB_FORCEINLINE -static const char* fastdecode_tosubmsg(upb_EpsCopyInputStream* e, - const char* ptr, void* ctx) { - upb_Decoder* d = (upb_Decoder*)e; - fastdecode_submsgdata* submsg = ctx; - ptr = fastdecode_dispatch(d, ptr, submsg->msg, submsg->table, 0, 0); - UPB_ASSUME(ptr != NULL); + in->state.msg_state.oneof_state = kUpb_OneofState_StartedOneof; return ptr; } -#define FASTDECODE_SUBMSG(d, ptr, msg, table, hasbits, data, tagbytes, \ - msg_ceil_bytes, card) \ - \ - if (UPB_UNLIKELY(!fastdecode_checktag(data, tagbytes))) { \ - RETURN_GENERIC("submessage field tag mismatch\n"); \ - } \ - \ - if (--d->depth == 0) { \ - _upb_FastDecoder_ErrorJmp(d, kUpb_DecodeStatus_MaxDepthExceeded); \ - } \ - \ - upb_Message** dst; \ - uint32_t submsg_idx = (data >> 16) & 0xff; \ - const upb_MiniTable* tablep = decode_totablep(table); \ - const upb_MiniTable* subtablep = upb_MiniTableSub_Message( \ - *UPB_PRIVATE(_upb_MiniTable_GetSubByIndex)(tablep, submsg_idx)); \ - fastdecode_submsgdata submsg = {decode_totable(subtablep)}; \ - fastdecode_arr farr; \ - \ - if (subtablep->UPB_PRIVATE(table_mask) == (uint8_t)-1) { \ - d->depth++; \ - RETURN_GENERIC("submessage doesn't have fast tables."); \ - } \ - \ - dst = fastdecode_getfield(d, ptr, msg, &data, &hasbits, &farr, \ - sizeof(upb_Message*), card); \ - \ - if (card == CARD_s) { \ - *(uint32_t*)msg |= hasbits; \ - hasbits = 0; \ - } \ - \ - again: \ - if (card == CARD_r) { \ - dst = fastdecode_resizearr(d, dst, &farr, sizeof(upb_Message*)); \ - } \ - \ - submsg.msg = *dst; \ - \ - if (card == CARD_r || UPB_LIKELY(!submsg.msg)) { \ - *dst = submsg.msg = decode_newmsg_ceil(d, subtablep, msg_ceil_bytes); \ - } \ - \ - ptr += tagbytes; \ - ptr = fastdecode_delimited(d, ptr, fastdecode_tosubmsg, &submsg); \ - \ - if (UPB_UNLIKELY(ptr == NULL || d->end_group != DECODE_NOGROUP)) { \ - _upb_FastDecoder_ErrorJmp(d, kUpb_DecodeStatus_Malformed); \ - } \ - \ - if (card == CARD_r) { \ - fastdecode_nextret ret = fastdecode_nextrepeated( \ - d, dst, &ptr, &farr, data, tagbytes, sizeof(upb_Message*)); \ - switch (ret.next) { \ - case FD_NEXT_SAMEFIELD: \ - dst = ret.dst; \ - goto again; \ - case FD_NEXT_OTHERFIELD: \ - d->depth++; \ - data = ret.tag; \ - UPB_MUSTTAIL return _upb_FastDecoder_TagDispatch(UPB_PARSE_ARGS); \ - case FD_NEXT_ATLIMIT: \ - d->depth++; \ - return ptr; \ - } \ - } \ - \ - d->depth++; \ - UPB_MUSTTAIL return fastdecode_dispatch(UPB_PARSE_ARGS); - -#define F(card, tagbytes, size_ceil, ceil_arg) \ - const char* upb_p##card##m_##tagbytes##bt_max##size_ceil##b( \ - UPB_PARSE_PARAMS) { \ - FASTDECODE_SUBMSG(d, ptr, msg, table, hasbits, data, tagbytes, ceil_arg, \ - CARD_##card); \ +char* upb_MtDataEncoder_PutOneofField(upb_MtDataEncoder* e, char* ptr, + uint32_t field_num) { + upb_MtDataEncoderInternal* in = upb_MtDataEncoder_GetInternal(e, ptr); + if (in->state.msg_state.oneof_state == kUpb_OneofState_EmittedOneofField) { + ptr = upb_MtDataEncoder_Put( + e, ptr, _upb_FromBase92(kUpb_EncodedValue_FieldSeparator)); + if (!ptr) return NULL; } + ptr = upb_MtDataEncoder_PutBase92Varint(e, ptr, field_num, _upb_ToBase92(0), + _upb_ToBase92(63)); + in->state.msg_state.oneof_state = kUpb_OneofState_EmittedOneofField; + return ptr; +} -#define SIZES(card, tagbytes) \ - F(card, tagbytes, 64, 64) \ - F(card, tagbytes, 128, 128) \ - F(card, tagbytes, 192, 192) \ - F(card, tagbytes, 256, 256) \ - F(card, tagbytes, max, -1) - -#define TAGBYTES(card) \ - SIZES(card, 1) \ - SIZES(card, 2) - -TAGBYTES(s) -TAGBYTES(o) -TAGBYTES(r) - -#undef TAGBYTES -#undef SIZES -#undef F -#undef FASTDECODE_SUBMSG - -#endif /* UPB_FASTTABLE */ - - -#include -#include +char* upb_MtDataEncoder_StartEnum(upb_MtDataEncoder* e, char* ptr) { + upb_MtDataEncoderInternal* in = upb_MtDataEncoder_GetInternal(e, ptr); + in->state.enum_state.present_values_mask = 0; + in->state.enum_state.last_written_value = 0; + return upb_MtDataEncoder_PutRaw(e, ptr, kUpb_EncodedVersion_EnumV1); +} -// Must be last. +static char* upb_MtDataEncoder_FlushDenseEnumMask(upb_MtDataEncoder* e, + char* ptr) { + upb_MtDataEncoderInternal* in = (upb_MtDataEncoderInternal*)e->internal; + ptr = upb_MtDataEncoder_Put(e, ptr, in->state.enum_state.present_values_mask); + in->state.enum_state.present_values_mask = 0; + in->state.enum_state.last_written_value += 5; + return ptr; +} -UPB_NOINLINE UPB_PRIVATE(_upb_WireReader_LongVarint) - UPB_PRIVATE(_upb_WireReader_ReadLongVarint)(const char* ptr, uint64_t val) { - UPB_PRIVATE(_upb_WireReader_LongVarint) ret = {NULL, 0}; - uint64_t byte; - int i; - for (i = 1; i < 10; i++) { - byte = (uint8_t)ptr[i]; - val += (byte - 1) << (i * 7); - if (!(byte & 0x80)) { - ret.ptr = ptr + i + 1; - ret.val = val; - return ret; +char* upb_MtDataEncoder_PutEnumValue(upb_MtDataEncoder* e, char* ptr, + uint32_t val) { + // TODO: optimize this encoding. + upb_MtDataEncoderInternal* in = upb_MtDataEncoder_GetInternal(e, ptr); + UPB_ASSERT(val >= in->state.enum_state.last_written_value); + uint32_t delta = val - in->state.enum_state.last_written_value; + if (delta >= 5 && in->state.enum_state.present_values_mask) { + ptr = upb_MtDataEncoder_FlushDenseEnumMask(e, ptr); + if (!ptr) { + return NULL; } + delta -= 5; } - return ret; -} -const char* UPB_PRIVATE(_upb_WireReader_SkipGroup)( - const char* ptr, uint32_t tag, int depth_limit, - upb_EpsCopyInputStream* stream) { - if (--depth_limit == 0) return NULL; - uint32_t end_group_tag = (tag & ~7ULL) | kUpb_WireType_EndGroup; - while (!upb_EpsCopyInputStream_IsDone(stream, &ptr)) { - uint32_t tag; - ptr = upb_WireReader_ReadTag(ptr, &tag); - if (!ptr) return NULL; - if (tag == end_group_tag) return ptr; - ptr = _upb_WireReader_SkipValue(ptr, tag, depth_limit, stream); - if (!ptr) return NULL; + if (delta >= 5) { + ptr = upb_MtDataEncoder_PutBase92Varint( + e, ptr, delta, kUpb_EncodedValue_MinSkip, kUpb_EncodedValue_MaxSkip); + in->state.enum_state.last_written_value += delta; + delta = 0; } + + UPB_ASSERT((in->state.enum_state.present_values_mask >> delta) == 0); + in->state.enum_state.present_values_mask |= 1ULL << delta; return ptr; } +char* upb_MtDataEncoder_EndEnum(upb_MtDataEncoder* e, char* ptr) { + upb_MtDataEncoderInternal* in = upb_MtDataEncoder_GetInternal(e, ptr); + if (!in->state.enum_state.present_values_mask) return ptr; + return upb_MtDataEncoder_FlushDenseEnumMask(e, ptr); +} + #include diff --git a/ruby/ext/google/protobuf_c/ruby-upb.h b/ruby/ext/google/protobuf_c/ruby-upb.h index 29f0e80b91eac..a9f020025552f 100755 --- a/ruby/ext/google/protobuf_c/ruby-upb.h +++ b/ruby/ext/google/protobuf_c/ruby-upb.h @@ -12698,89 +12698,6 @@ typedef enum { #endif // UPB_MINI_DESCRIPTOR_INTERNAL_MODIFIERS_H_ -#ifndef UPB_MINI_DESCRIPTOR_INTERNAL_ENCODE_H_ -#define UPB_MINI_DESCRIPTOR_INTERNAL_ENCODE_H_ - -#include - - -// Must be last. - -// If the input buffer has at least this many bytes available, the encoder call -// is guaranteed to succeed (as long as field number order is maintained). -#define kUpb_MtDataEncoder_MinSize 16 - -typedef struct { - char* end; // Limit of the buffer passed as a parameter. - // Aliased to internal-only members in .cc. - char internal[32]; -} upb_MtDataEncoder; - -#ifdef __cplusplus -extern "C" { -#endif - -// Encodes field/oneof information for a given message. The sequence of calls -// should look like: -// -// upb_MtDataEncoder e; -// char buf[256]; -// char* ptr = buf; -// e.end = ptr + sizeof(buf); -// unit64_t msg_mod = ...; // bitwise & of kUpb_MessageModifiers or zero -// ptr = upb_MtDataEncoder_StartMessage(&e, ptr, msg_mod); -// // Fields *must* be in field number order. -// ptr = upb_MtDataEncoder_PutField(&e, ptr, ...); -// ptr = upb_MtDataEncoder_PutField(&e, ptr, ...); -// ptr = upb_MtDataEncoder_PutField(&e, ptr, ...); -// -// // If oneofs are present. Oneofs must be encoded after regular fields. -// ptr = upb_MiniTable_StartOneof(&e, ptr) -// ptr = upb_MiniTable_PutOneofField(&e, ptr, ...); -// ptr = upb_MiniTable_PutOneofField(&e, ptr, ...); -// -// ptr = upb_MiniTable_StartOneof(&e, ptr); -// ptr = upb_MiniTable_PutOneofField(&e, ptr, ...); -// ptr = upb_MiniTable_PutOneofField(&e, ptr, ...); -// -// Oneofs must be encoded after all regular fields. -char* upb_MtDataEncoder_StartMessage(upb_MtDataEncoder* e, char* ptr, - uint64_t msg_mod); -char* upb_MtDataEncoder_PutField(upb_MtDataEncoder* e, char* ptr, - upb_FieldType type, uint32_t field_num, - uint64_t field_mod); -char* upb_MtDataEncoder_StartOneof(upb_MtDataEncoder* e, char* ptr); -char* upb_MtDataEncoder_PutOneofField(upb_MtDataEncoder* e, char* ptr, - uint32_t field_num); - -// Encodes the set of values for a given enum. The values must be given in -// order (after casting to uint32_t), and repeats are not allowed. -char* upb_MtDataEncoder_StartEnum(upb_MtDataEncoder* e, char* ptr); -char* upb_MtDataEncoder_PutEnumValue(upb_MtDataEncoder* e, char* ptr, - uint32_t val); -char* upb_MtDataEncoder_EndEnum(upb_MtDataEncoder* e, char* ptr); - -// Encodes an entire mini descriptor for an extension. -char* upb_MtDataEncoder_EncodeExtension(upb_MtDataEncoder* e, char* ptr, - upb_FieldType type, uint32_t field_num, - uint64_t field_mod); - -// Encodes an entire mini descriptor for a map. -char* upb_MtDataEncoder_EncodeMap(upb_MtDataEncoder* e, char* ptr, - upb_FieldType key_type, - upb_FieldType value_type, uint64_t key_mod, - uint64_t value_mod); - -// Encodes an entire mini descriptor for a message set. -char* upb_MtDataEncoder_EncodeMessageSet(upb_MtDataEncoder* e, char* ptr); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - - -#endif /* UPB_MINI_DESCRIPTOR_INTERNAL_ENCODE_H_ */ - #ifndef UPB_MINI_TABLE_COMPAT_H_ #define UPB_MINI_TABLE_COMPAT_H_ @@ -13229,6 +13146,89 @@ upb_ServiceDef* _upb_ServiceDefs_New(upb_DefBuilder* ctx, int n, #define UPB_REFLECTION_DESC_STATE_INTERNAL_H_ +#ifndef UPB_MINI_DESCRIPTOR_INTERNAL_ENCODE_H_ +#define UPB_MINI_DESCRIPTOR_INTERNAL_ENCODE_H_ + +#include + + +// Must be last. + +// If the input buffer has at least this many bytes available, the encoder call +// is guaranteed to succeed (as long as field number order is maintained). +#define kUpb_MtDataEncoder_MinSize 16 + +typedef struct { + char* end; // Limit of the buffer passed as a parameter. + // Aliased to internal-only members in .cc. + char internal[32]; +} upb_MtDataEncoder; + +#ifdef __cplusplus +extern "C" { +#endif + +// Encodes field/oneof information for a given message. The sequence of calls +// should look like: +// +// upb_MtDataEncoder e; +// char buf[256]; +// char* ptr = buf; +// e.end = ptr + sizeof(buf); +// unit64_t msg_mod = ...; // bitwise & of kUpb_MessageModifiers or zero +// ptr = upb_MtDataEncoder_StartMessage(&e, ptr, msg_mod); +// // Fields *must* be in field number order. +// ptr = upb_MtDataEncoder_PutField(&e, ptr, ...); +// ptr = upb_MtDataEncoder_PutField(&e, ptr, ...); +// ptr = upb_MtDataEncoder_PutField(&e, ptr, ...); +// +// // If oneofs are present. Oneofs must be encoded after regular fields. +// ptr = upb_MiniTable_StartOneof(&e, ptr) +// ptr = upb_MiniTable_PutOneofField(&e, ptr, ...); +// ptr = upb_MiniTable_PutOneofField(&e, ptr, ...); +// +// ptr = upb_MiniTable_StartOneof(&e, ptr); +// ptr = upb_MiniTable_PutOneofField(&e, ptr, ...); +// ptr = upb_MiniTable_PutOneofField(&e, ptr, ...); +// +// Oneofs must be encoded after all regular fields. +char* upb_MtDataEncoder_StartMessage(upb_MtDataEncoder* e, char* ptr, + uint64_t msg_mod); +char* upb_MtDataEncoder_PutField(upb_MtDataEncoder* e, char* ptr, + upb_FieldType type, uint32_t field_num, + uint64_t field_mod); +char* upb_MtDataEncoder_StartOneof(upb_MtDataEncoder* e, char* ptr); +char* upb_MtDataEncoder_PutOneofField(upb_MtDataEncoder* e, char* ptr, + uint32_t field_num); + +// Encodes the set of values for a given enum. The values must be given in +// order (after casting to uint32_t), and repeats are not allowed. +char* upb_MtDataEncoder_StartEnum(upb_MtDataEncoder* e, char* ptr); +char* upb_MtDataEncoder_PutEnumValue(upb_MtDataEncoder* e, char* ptr, + uint32_t val); +char* upb_MtDataEncoder_EndEnum(upb_MtDataEncoder* e, char* ptr); + +// Encodes an entire mini descriptor for an extension. +char* upb_MtDataEncoder_EncodeExtension(upb_MtDataEncoder* e, char* ptr, + upb_FieldType type, uint32_t field_num, + uint64_t field_mod); + +// Encodes an entire mini descriptor for a map. +char* upb_MtDataEncoder_EncodeMap(upb_MtDataEncoder* e, char* ptr, + upb_FieldType key_type, + upb_FieldType value_type, uint64_t key_mod, + uint64_t value_mod); + +// Encodes an entire mini descriptor for a message set. +char* upb_MtDataEncoder_EncodeMessageSet(upb_MtDataEncoder* e, char* ptr); + +#ifdef __cplusplus +} /* extern "C" */ +#endif + + +#endif /* UPB_MINI_DESCRIPTOR_INTERNAL_ENCODE_H_ */ + // Must be last. // Manages the storage for mini descriptor strings as they are being encoded. From 50f01407806859cdd8f3a939ceadba2128a5f3ce Mon Sep 17 00:00:00 2001 From: Hong Shin Date: Thu, 28 Dec 2023 11:15:02 -0800 Subject: [PATCH 125/255] Fix textfmt typo: vaid -> valid PiperOrigin-RevId: 594286947 --- src/google/protobuf/text_format.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/google/protobuf/text_format.cc b/src/google/protobuf/text_format.cc index cc74abc778982..7637a368a7b90 100644 --- a/src/google/protobuf/text_format.cc +++ b/src/google/protobuf/text_format.cc @@ -1655,7 +1655,7 @@ namespace { // UTF-8 validity issues. bool DefinitelyNeedsEscape(unsigned char ch) { if (ch >= 0x80) { - return false; // High byte; no escapes necessary if UTF-8 is vaid. + return false; // High byte; no escapes necessary if UTF-8 is valid. } if (!absl::ascii_isprint(ch)) { From 27cccac563634ff58d843bc54e8d16ebb56e80f8 Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Thu, 28 Dec 2023 11:18:45 -0800 Subject: [PATCH 126/255] Fix some non-breaking issues with rust gencode. - Stop emitting a clear thunk for without-presence string/bytes fields (was unused, but would link-error it was used since there's no such operation). - Remove unused clearer_thunk variable in message.cc - Remove unsafe{} block surrounding non-unsafe BytesMutVTable::new - Add #[allow(non_snake_case)] on module names (the new mangling added in cr/593048297 puts double-underscore in names which rustc recognizes as non-snake). PiperOrigin-RevId: 594287606 --- .../compiler/rust/accessors/singular_scalar.cc | 8 ++++---- .../compiler/rust/accessors/singular_string.cc | 15 +++++++-------- src/google/protobuf/compiler/rust/generator.cc | 2 ++ src/google/protobuf/compiler/rust/message.cc | 2 -- 4 files changed, 13 insertions(+), 14 deletions(-) diff --git a/src/google/protobuf/compiler/rust/accessors/singular_scalar.cc b/src/google/protobuf/compiler/rust/accessors/singular_scalar.cc index 48aa4dbfca645..5e520242e409f 100644 --- a/src/google/protobuf/compiler/rust/accessors/singular_scalar.cc +++ b/src/google/protobuf/compiler/rust/accessors/singular_scalar.cc @@ -122,7 +122,7 @@ void SingularScalar::InExternC(Context& ctx, {"getter_thunk", Thunk(ctx, field, "get")}, {"setter_thunk", Thunk(ctx, field, "set")}, {"clearer_thunk", Thunk(ctx, field, "clear")}, - {"hazzer_and_clearer", + {"with_presence_fields_thunks", [&] { if (field.has_presence()) { ctx.Emit( @@ -133,7 +133,7 @@ void SingularScalar::InExternC(Context& ctx, } }}}, R"rs( - $hazzer_and_clearer$ + $with_presence_fields_thunks$ fn $getter_thunk$(raw_msg: $pbi$::RawMessage) -> $Scalar$; fn $setter_thunk$(raw_msg: $pbi$::RawMessage, val: $Scalar$); )rs"); @@ -148,7 +148,7 @@ void SingularScalar::InThunkCc(Context& ctx, {"getter_thunk", Thunk(ctx, field, "get")}, {"setter_thunk", Thunk(ctx, field, "set")}, {"clearer_thunk", Thunk(ctx, field, "clear")}, - {"hazzer_and_clearer", + {"with_presence_fields_thunks", [&] { if (field.has_presence()) { ctx.Emit(R"cc( @@ -160,7 +160,7 @@ void SingularScalar::InThunkCc(Context& ctx, } }}}, R"cc( - $hazzer_and_clearer$; + $with_presence_fields_thunks$; $Scalar$ $getter_thunk$($QualifiedMsg$* msg) { return msg->$field$(); } void $setter_thunk$($QualifiedMsg$* msg, $Scalar$ val) { msg->set_$field$(val); diff --git a/src/google/protobuf/compiler/rust/accessors/singular_string.cc b/src/google/protobuf/compiler/rust/accessors/singular_string.cc index c70380c67c825..b89c8bf43a892 100644 --- a/src/google/protobuf/compiler/rust/accessors/singular_string.cc +++ b/src/google/protobuf/compiler/rust/accessors/singular_string.cc @@ -118,13 +118,12 @@ void SingularString::InMsgImpl(Context& ctx, {"setter_thunk", setter_thunk}}, R"rs( pub fn $field$_mut(&mut self) -> $pb$::Mut<'_, $proxied_type$> { - static VTABLE: $pbi$::BytesMutVTable = unsafe { + static VTABLE: $pbi$::BytesMutVTable = $pbi$::BytesMutVTable::new( $pbi$::Private, $getter_thunk$, $setter_thunk$, - ) - }; + ); unsafe { <$pb$::Mut<$proxied_type$>>::from_inner( $pbi$::Private, @@ -158,19 +157,19 @@ void SingularString::InExternC(Context& ctx, {"getter_thunk", Thunk(ctx, field, "get")}, {"setter_thunk", Thunk(ctx, field, "set")}, {"clearer_thunk", Thunk(ctx, field, "clear")}, - {"hazzer", + {"with_presence_fields_thunks", [&] { if (field.has_presence()) { ctx.Emit(R"rs( fn $hazzer_thunk$(raw_msg: $pbi$::RawMessage) -> bool; + fn $clearer_thunk$(raw_msg: $pbi$::RawMessage); )rs"); } }}}, R"rs( - $hazzer$ + $with_presence_fields_thunks$ fn $getter_thunk$(raw_msg: $pbi$::RawMessage) -> $pbi$::PtrAndLen; fn $setter_thunk$(raw_msg: $pbi$::RawMessage, val: $pbi$::PtrAndLen); - fn $clearer_thunk$(raw_msg: $pbi$::RawMessage); )rs"); } @@ -182,7 +181,7 @@ void SingularString::InThunkCc(Context& ctx, {"getter_thunk", Thunk(ctx, field, "get")}, {"setter_thunk", Thunk(ctx, field, "set")}, {"clearer_thunk", Thunk(ctx, field, "clear")}, - {"hazzer", + {"with_presence_fields_thunks", [&] { if (field.has_presence()) { ctx.Emit(R"cc( @@ -194,7 +193,7 @@ void SingularString::InThunkCc(Context& ctx, } }}}, R"cc( - $hazzer$; + $with_presence_fields_thunks$; ::google::protobuf::rust_internal::PtrAndLen $getter_thunk$($QualifiedMsg$* msg) { absl::string_view val = msg->$field$(); return ::google::protobuf::rust_internal::PtrAndLen(val.data(), val.size()); diff --git a/src/google/protobuf/compiler/rust/generator.cc b/src/google/protobuf/compiler/rust/generator.cc index bc23a120216ea..c15f8743ff7a5 100644 --- a/src/google/protobuf/compiler/rust/generator.cc +++ b/src/google/protobuf/compiler/rust/generator.cc @@ -54,6 +54,7 @@ void EmitOpeningOfPackageModules(Context& ctx, absl::string_view pkg) { for (absl::string_view segment : absl::StrSplit(pkg, '.')) { ctx.Emit({{"segment", segment}}, R"rs( + #[allow(non_snake_case)] pub mod $segment$ { )rs"); } @@ -157,6 +158,7 @@ void DeclareSubmodulesForNonPrimarySrcs( {"mod_name", RustInternalModuleName(ctx, *non_primary_src)}}, R"rs( #[path="$file_path$"] + #[allow(non_snake_case)] pub mod $mod_name$; )rs"); } diff --git a/src/google/protobuf/compiler/rust/message.cc b/src/google/protobuf/compiler/rust/message.cc index 21151e3cc7790..408678367cc5b 100644 --- a/src/google/protobuf/compiler/rust/message.cc +++ b/src/google/protobuf/compiler/rust/message.cc @@ -175,7 +175,6 @@ void GetterForViewOrMut(Context& ctx, const FieldDescriptor& field, auto fieldType = field.type(); auto getter_thunk = Thunk(ctx, field, "get"); auto setter_thunk = Thunk(ctx, field, "set"); - auto clearer_thunk = Thunk(ctx, field, "clear"); // If we're dealing with a Mut, the getter must be supplied // self.inner.msg() whereas a View has to be supplied self.msg auto self = is_mut ? "self.inner.msg()" : "self.msg"; @@ -240,7 +239,6 @@ void GetterForViewOrMut(Context& ctx, const FieldDescriptor& field, ctx.Emit({{"field", fieldName}, {"getter_thunk", getter_thunk}, {"setter_thunk", setter_thunk}, - {"clearer_thunk", clearer_thunk}, {"self", self}, {"RsType", rsType}, {"as_ref", asRef}, From 37a926e177e1baad668a4a56dec1c0cd0ba4c870 Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Thu, 28 Dec 2023 11:56:59 -0800 Subject: [PATCH 127/255] Added JSON parsing/serialization to benchmark PiperOrigin-RevId: 594293336 --- benchmarks/BUILD | 14 +++-- benchmarks/benchmark.cc | 111 ++++++++++++++++++++++++++++++++++++++-- 2 files changed, 116 insertions(+), 9 deletions(-) diff --git a/benchmarks/BUILD b/benchmarks/BUILD index 3559926d51bd6..b975bac8e3ee9 100644 --- a/benchmarks/BUILD +++ b/benchmarks/BUILD @@ -6,16 +6,16 @@ # https://developers.google.com/open-source/licenses/bsd load("@rules_python//python:defs.bzl", "py_binary") - -# begin:google_only -# load("@rules_cc//cc:defs.bzl", "cc_proto_library") -# end:google_only - load( "//bazel:upb_proto_library.bzl", "upb_c_proto_library", "upb_proto_reflection_library", ) + +# begin:google_only +# load("@rules_cc//cc:defs.bzl", "cc_proto_library") +# end:google_only + load( ":build_defs.bzl", "cc_optimizefor_proto_library", @@ -77,13 +77,17 @@ cc_test( ":benchmark_descriptor_upb_proto_reflection", "//:protobuf", "@com_google_googletest//:gtest_main", + "//src/google/protobuf/json", "//upb:base", "//upb:descriptor_upb_proto", + "//upb:json", "//upb:mem", "//upb:reflection", + "//upb:wire", "//upb/base:internal", "@com_github_google_benchmark//:benchmark_main", "@com_google_absl//absl/container:flat_hash_set", + "@com_google_absl//absl/log:absl_check", ], ) diff --git a/benchmarks/benchmark.cc b/benchmarks/benchmark.cc index e972b0b721817..c9658eae72688 100644 --- a/benchmarks/benchmark.cc +++ b/benchmarks/benchmark.cc @@ -7,23 +7,32 @@ #include +#include #include +#include #include #include "google/ads/googleads/v13/services/google_ads_service.upbdefs.h" #include "google/protobuf/descriptor.pb.h" #include "absl/container/flat_hash_set.h" +#include "absl/log/absl_check.h" #include "google/protobuf/dynamic_message.h" +#include "google/protobuf/json/json.h" #include "benchmarks/descriptor.pb.h" #include "benchmarks/descriptor.upb.h" #include "benchmarks/descriptor.upbdefs.h" #include "benchmarks/descriptor_sv.pb.h" #include "upb/base/internal/log2.h" +#include "upb/base/upcast.h" +#include "upb/json/decode.h" +#include "upb/json/encode.h" #include "upb/mem/arena.h" #include "upb/reflection/def.hpp" +#include "upb/wire/decode.h" -upb_StringView descriptor = benchmarks_descriptor_proto_upbdefinit.descriptor; +upb_StringView descriptor = + benchmarks_descriptor_proto_upbdefinit.descriptor; namespace protobuf = ::google::protobuf; // A buffer big enough to parse descriptor.proto without going to heap. @@ -341,9 +350,7 @@ static void BM_SerializeDescriptor_Proto2(benchmark::State& state) { } BENCHMARK(BM_SerializeDescriptor_Proto2); -static void BM_SerializeDescriptor_Upb(benchmark::State& state) { - int64_t total = 0; - upb_Arena* arena = upb_Arena_New(); +static upb_benchmark_FileDescriptorProto* UpbParseDescriptor(upb_Arena* arena) { upb_benchmark_FileDescriptorProto* set = upb_benchmark_FileDescriptorProto_parse(descriptor.data, descriptor.size, arena); @@ -351,6 +358,13 @@ static void BM_SerializeDescriptor_Upb(benchmark::State& state) { printf("Failed to parse.\n"); exit(1); } + return set; +} + +static void BM_SerializeDescriptor_Upb(benchmark::State& state) { + int64_t total = 0; + upb_Arena* arena = upb_Arena_New(); + upb_benchmark_FileDescriptorProto* set = UpbParseDescriptor(arena); for (auto _ : state) { upb_Arena* enc_arena = upb_Arena_Init(buf, sizeof(buf), nullptr); size_t size; @@ -365,3 +379,92 @@ static void BM_SerializeDescriptor_Upb(benchmark::State& state) { state.SetBytesProcessed(total); } BENCHMARK(BM_SerializeDescriptor_Upb); + +static absl::string_view UpbJsonEncode(upb_benchmark_FileDescriptorProto* proto, + const upb_MessageDef* md, + upb_Arena* arena) { + size_t size = + upb_JsonEncode(UPB_UPCAST(proto), md, nullptr, 0, nullptr, 0, nullptr); + char* buf = reinterpret_cast(upb_Arena_Malloc(arena, size + 1)); + upb_JsonEncode(UPB_UPCAST(proto), md, nullptr, 0, buf, size, nullptr); + return absl::string_view(buf, size); +} + +static void BM_JsonParse_Upb(benchmark::State& state) { + upb_Arena* arena = upb_Arena_New(); + upb_benchmark_FileDescriptorProto* set = + upb_benchmark_FileDescriptorProto_parse(descriptor.data, descriptor.size, + arena); + if (!set) { + printf("Failed to parse.\n"); + exit(1); + } + + upb::DefPool defpool; + const upb_MessageDef* md = + upb_benchmark_FileDescriptorProto_getmsgdef(defpool.ptr()); + auto json = UpbJsonEncode(set, md, arena); + + for (auto _ : state) { + upb_Arena* arena = upb_Arena_New(); + upb_benchmark_FileDescriptorProto* proto = + upb_benchmark_FileDescriptorProto_new(arena); + upb_JsonDecode(json.data(), json.size(), UPB_UPCAST(proto), md, + defpool.ptr(), 0, arena, nullptr); + upb_Arena_Free(arena); + } + state.SetBytesProcessed(state.iterations() * json.size()); +} +BENCHMARK(BM_JsonParse_Upb); + +static void BM_JsonParse_Proto2(benchmark::State& state) { + protobuf::FileDescriptorProto proto; + absl::string_view input(descriptor.data, descriptor.size); + proto.ParseFromString(input); + std::string json; + ABSL_CHECK_OK(google::protobuf::json::MessageToJsonString(proto, &json)); + for (auto _ : state) { + protobuf::FileDescriptorProto proto; + ABSL_CHECK_OK(google::protobuf::json::JsonStringToMessage(json, &proto)); + } + state.SetBytesProcessed(state.iterations() * json.size()); +} +BENCHMARK(BM_JsonParse_Proto2); + +static void BM_JsonSerialize_Upb(benchmark::State& state) { + upb_Arena* arena = upb_Arena_New(); + upb_benchmark_FileDescriptorProto* set = + upb_benchmark_FileDescriptorProto_parse(descriptor.data, descriptor.size, + arena); + ABSL_CHECK(set != nullptr); + + upb::DefPool defpool; + const upb_MessageDef* md = + upb_benchmark_FileDescriptorProto_getmsgdef(defpool.ptr()); + auto json = UpbJsonEncode(set, md, arena); + std::string json_str; + json_str.resize(json.size()); + + for (auto _ : state) { + // This isn't a fully fair comparison, as it assumes we already know the + // correct size of the buffer. In practice, we usually need to run the + // encoder twice, once to discover the size of the buffer. + upb_JsonEncode(UPB_UPCAST(set), md, nullptr, 0, json_str.data(), + json_str.size(), nullptr); + } + state.SetBytesProcessed(state.iterations() * json.size()); +} +BENCHMARK(BM_JsonSerialize_Upb); + +static void BM_JsonSerialize_Proto2(benchmark::State& state) { + protobuf::FileDescriptorProto proto; + absl::string_view input(descriptor.data, descriptor.size); + proto.ParseFromString(input); + std::string json; + for (auto _ : state) { + json.clear(); + ABSL_CHECK_OK(google::protobuf::json::MessageToJsonString(proto, &json)); + } + state.SetBytesProcessed(state.iterations() * json.size()); +} +BENCHMARK(BM_JsonSerialize_Proto2); From 4c35408777a1305b45fed1ef5806a5cca2b841b8 Mon Sep 17 00:00:00 2001 From: Hong Shin Date: Thu, 28 Dec 2023 12:39:44 -0800 Subject: [PATCH 128/255] Rename Thunk to ThunkName Let's hint at returning a name as opposed to a computed chunk / lambda PiperOrigin-RevId: 594300381 --- .../protobuf/compiler/rust/accessors/map.cc | 12 +++--- .../rust/accessors/repeated_scalar.cc | 18 ++++----- .../rust/accessors/singular_message.cc | 18 ++++----- .../rust/accessors/singular_scalar.cc | 24 +++++------ .../rust/accessors/singular_string.cc | 24 +++++------ src/google/protobuf/compiler/rust/message.cc | 40 +++++++++---------- src/google/protobuf/compiler/rust/naming.cc | 33 +++++++-------- src/google/protobuf/compiler/rust/naming.h | 11 ++--- src/google/protobuf/compiler/rust/oneof.cc | 6 +-- 9 files changed, 94 insertions(+), 92 deletions(-) diff --git a/src/google/protobuf/compiler/rust/accessors/map.cc b/src/google/protobuf/compiler/rust/accessors/map.cc index 633e21cfda6a1..4061d731cacf7 100644 --- a/src/google/protobuf/compiler/rust/accessors/map.cc +++ b/src/google/protobuf/compiler/rust/accessors/map.cc @@ -24,8 +24,8 @@ void Map::InMsgImpl(Context& ctx, const FieldDescriptor& field) const { ctx.Emit({{"field", field.name()}, {"Key", PrimitiveRsTypeName(key_type)}, {"Value", PrimitiveRsTypeName(value_type)}, - {"getter_thunk", Thunk(ctx, field, "get")}, - {"getter_mut_thunk", Thunk(ctx, field, "get_mut")}, + {"getter_thunk", ThunkName(ctx, field, "get")}, + {"getter_mut_thunk", ThunkName(ctx, field, "get_mut")}, {"getter", [&] { if (ctx.is_upb()) { @@ -97,8 +97,8 @@ void Map::InMsgImpl(Context& ctx, const FieldDescriptor& field) const { void Map::InExternC(Context& ctx, const FieldDescriptor& field) const { ctx.Emit( { - {"getter_thunk", Thunk(ctx, field, "get")}, - {"getter_mut_thunk", Thunk(ctx, field, "get_mut")}, + {"getter_thunk", ThunkName(ctx, field, "get")}, + {"getter_mut_thunk", ThunkName(ctx, field, "get_mut")}, {"getter", [&] { if (ctx.is_upb()) { @@ -129,8 +129,8 @@ void Map::InThunkCc(Context& ctx, const FieldDescriptor& field) const { {"Value", cpp::PrimitiveTypeName(field.message_type()->map_value()->cpp_type())}, {"QualifiedMsg", cpp::QualifiedClassName(field.containing_type())}, - {"getter_thunk", Thunk(ctx, field, "get")}, - {"getter_mut_thunk", Thunk(ctx, field, "get_mut")}, + {"getter_thunk", ThunkName(ctx, field, "get")}, + {"getter_mut_thunk", ThunkName(ctx, field, "get_mut")}, {"impls", [&] { ctx.Emit( diff --git a/src/google/protobuf/compiler/rust/accessors/repeated_scalar.cc b/src/google/protobuf/compiler/rust/accessors/repeated_scalar.cc index 9b26784384278..b88fa9fe37731 100644 --- a/src/google/protobuf/compiler/rust/accessors/repeated_scalar.cc +++ b/src/google/protobuf/compiler/rust/accessors/repeated_scalar.cc @@ -21,8 +21,8 @@ void RepeatedScalar::InMsgImpl(Context& ctx, const FieldDescriptor& field) const { ctx.Emit({{"field", field.name()}, {"Scalar", PrimitiveRsTypeName(field)}, - {"getter_thunk", Thunk(ctx, field, "get")}, - {"getter_mut_thunk", Thunk(ctx, field, "get_mut")}, + {"getter_thunk", ThunkName(ctx, field, "get")}, + {"getter_mut_thunk", ThunkName(ctx, field, "get_mut")}, {"getter", [&] { if (ctx.is_upb()) { @@ -54,7 +54,7 @@ void RepeatedScalar::InMsgImpl(Context& ctx, )rs"); } }}, - {"clearer_thunk", Thunk(ctx, field, "clear")}, + {"clearer_thunk", ThunkName(ctx, field, "clear")}, {"field_mutator_getter", [&] { if (ctx.is_upb()) { @@ -101,8 +101,8 @@ void RepeatedScalar::InMsgImpl(Context& ctx, void RepeatedScalar::InExternC(Context& ctx, const FieldDescriptor& field) const { ctx.Emit({{"Scalar", PrimitiveRsTypeName(field)}, - {"getter_thunk", Thunk(ctx, field, "get")}, - {"getter_mut_thunk", Thunk(ctx, field, "get_mut")}, + {"getter_thunk", ThunkName(ctx, field, "get")}, + {"getter_mut_thunk", ThunkName(ctx, field, "get_mut")}, {"getter", [&] { if (ctx.is_upb()) { @@ -125,7 +125,7 @@ void RepeatedScalar::InExternC(Context& ctx, )rs"); } }}, - {"clearer_thunk", Thunk(ctx, field, "clear")}}, + {"clearer_thunk", ThunkName(ctx, field, "clear")}}, R"rs( fn $clearer_thunk$(raw_msg: $pbi$::RawMessage); $getter$ @@ -137,9 +137,9 @@ void RepeatedScalar::InThunkCc(Context& ctx, ctx.Emit({{"field", cpp::FieldName(&field)}, {"Scalar", cpp::PrimitiveTypeName(field.cpp_type())}, {"QualifiedMsg", cpp::QualifiedClassName(field.containing_type())}, - {"clearer_thunk", Thunk(ctx, field, "clear")}, - {"getter_thunk", Thunk(ctx, field, "get")}, - {"getter_mut_thunk", Thunk(ctx, field, "get_mut")}, + {"clearer_thunk", ThunkName(ctx, field, "clear")}, + {"getter_thunk", ThunkName(ctx, field, "get")}, + {"getter_mut_thunk", ThunkName(ctx, field, "get_mut")}, {"impls", [&] { ctx.Emit( diff --git a/src/google/protobuf/compiler/rust/accessors/singular_message.cc b/src/google/protobuf/compiler/rust/accessors/singular_message.cc index ca5dce246ae7d..b94473cb6d77a 100644 --- a/src/google/protobuf/compiler/rust/accessors/singular_message.cc +++ b/src/google/protobuf/compiler/rust/accessors/singular_message.cc @@ -26,9 +26,9 @@ void SingularMessage::InMsgImpl(Context& ctx, { {"prefix", prefix}, {"field", field.name()}, - {"getter_thunk", Thunk(ctx, field, "get")}, - {"getter_mut_thunk", Thunk(ctx, field, "get_mut")}, - {"clearer_thunk", Thunk(ctx, field, "clear")}, + {"getter_thunk", ThunkName(ctx, field, "get")}, + {"getter_mut_thunk", ThunkName(ctx, field, "get_mut")}, + {"clearer_thunk", ThunkName(ctx, field, "clear")}, { "view_body", [&] { @@ -91,9 +91,9 @@ void SingularMessage::InExternC(Context& ctx, const FieldDescriptor& field) const { ctx.Emit( { - {"getter_thunk", Thunk(ctx, field, "get")}, - {"getter_mut_thunk", Thunk(ctx, field, "get_mut")}, - {"clearer_thunk", Thunk(ctx, field, "clear")}, + {"getter_thunk", ThunkName(ctx, field, "get")}, + {"getter_mut_thunk", ThunkName(ctx, field, "get_mut")}, + {"clearer_thunk", ThunkName(ctx, field, "clear")}, {"getter_mut", [&] { if (ctx.is_cpp()) { @@ -130,9 +130,9 @@ void SingularMessage::InExternC(Context& ctx, void SingularMessage::InThunkCc(Context& ctx, const FieldDescriptor& field) const { ctx.Emit({{"QualifiedMsg", cpp::QualifiedClassName(field.containing_type())}, - {"getter_thunk", Thunk(ctx, field, "get")}, - {"getter_mut_thunk", Thunk(ctx, field, "get_mut")}, - {"clearer_thunk", Thunk(ctx, field, "clear")}, + {"getter_thunk", ThunkName(ctx, field, "get")}, + {"getter_mut_thunk", ThunkName(ctx, field, "get_mut")}, + {"clearer_thunk", ThunkName(ctx, field, "clear")}, {"field", cpp::FieldName(&field)}}, R"cc( const void* $getter_thunk$($QualifiedMsg$* msg) { diff --git a/src/google/protobuf/compiler/rust/accessors/singular_scalar.cc b/src/google/protobuf/compiler/rust/accessors/singular_scalar.cc index 5e520242e409f..a49cf6cbc2596 100644 --- a/src/google/protobuf/compiler/rust/accessors/singular_scalar.cc +++ b/src/google/protobuf/compiler/rust/accessors/singular_scalar.cc @@ -24,7 +24,7 @@ void SingularScalar::InMsgImpl(Context& ctx, { {"field", field.name()}, {"Scalar", PrimitiveRsTypeName(field)}, - {"hazzer_thunk", Thunk(ctx, field, "has")}, + {"hazzer_thunk", ThunkName(ctx, field, "has")}, {"default_value", DefaultValue(field)}, {"getter", [&] { @@ -48,9 +48,9 @@ void SingularScalar::InMsgImpl(Context& ctx, } )rs"); }}, - {"getter_thunk", Thunk(ctx, field, "get")}, - {"setter_thunk", Thunk(ctx, field, "set")}, - {"clearer_thunk", Thunk(ctx, field, "clear")}, + {"getter_thunk", ThunkName(ctx, field, "get")}, + {"setter_thunk", ThunkName(ctx, field, "set")}, + {"clearer_thunk", ThunkName(ctx, field, "clear")}, {"field_mutator_getter", [&] { if (field.has_presence()) { @@ -118,10 +118,10 @@ void SingularScalar::InMsgImpl(Context& ctx, void SingularScalar::InExternC(Context& ctx, const FieldDescriptor& field) const { ctx.Emit({{"Scalar", PrimitiveRsTypeName(field)}, - {"hazzer_thunk", Thunk(ctx, field, "has")}, - {"getter_thunk", Thunk(ctx, field, "get")}, - {"setter_thunk", Thunk(ctx, field, "set")}, - {"clearer_thunk", Thunk(ctx, field, "clear")}, + {"hazzer_thunk", ThunkName(ctx, field, "has")}, + {"getter_thunk", ThunkName(ctx, field, "get")}, + {"setter_thunk", ThunkName(ctx, field, "set")}, + {"clearer_thunk", ThunkName(ctx, field, "clear")}, {"with_presence_fields_thunks", [&] { if (field.has_presence()) { @@ -144,10 +144,10 @@ void SingularScalar::InThunkCc(Context& ctx, ctx.Emit({{"field", cpp::FieldName(&field)}, {"Scalar", cpp::PrimitiveTypeName(field.cpp_type())}, {"QualifiedMsg", cpp::QualifiedClassName(field.containing_type())}, - {"hazzer_thunk", Thunk(ctx, field, "has")}, - {"getter_thunk", Thunk(ctx, field, "get")}, - {"setter_thunk", Thunk(ctx, field, "set")}, - {"clearer_thunk", Thunk(ctx, field, "clear")}, + {"hazzer_thunk", ThunkName(ctx, field, "has")}, + {"getter_thunk", ThunkName(ctx, field, "get")}, + {"setter_thunk", ThunkName(ctx, field, "set")}, + {"clearer_thunk", ThunkName(ctx, field, "clear")}, {"with_presence_fields_thunks", [&] { if (field.has_presence()) { diff --git a/src/google/protobuf/compiler/rust/accessors/singular_string.cc b/src/google/protobuf/compiler/rust/accessors/singular_string.cc index b89c8bf43a892..227c11b34b266 100644 --- a/src/google/protobuf/compiler/rust/accessors/singular_string.cc +++ b/src/google/protobuf/compiler/rust/accessors/singular_string.cc @@ -22,9 +22,9 @@ namespace rust { void SingularString::InMsgImpl(Context& ctx, const FieldDescriptor& field) const { - std::string hazzer_thunk = Thunk(ctx, field, "has"); - std::string getter_thunk = Thunk(ctx, field, "get"); - std::string setter_thunk = Thunk(ctx, field, "set"); + std::string hazzer_thunk = ThunkName(ctx, field, "has"); + std::string getter_thunk = ThunkName(ctx, field, "get"); + std::string setter_thunk = ThunkName(ctx, field, "set"); std::string proxied_type = PrimitiveRsTypeName(field); auto transform_view = [&] { if (field.type() == FieldDescriptor::TYPE_STRING) { @@ -85,7 +85,7 @@ void SingularString::InMsgImpl(Context& ctx, {"hazzer_thunk", hazzer_thunk}, {"getter_thunk", getter_thunk}, {"setter_thunk", setter_thunk}, - {"clearer_thunk", Thunk(ctx, field, "clear")}, + {"clearer_thunk", ThunkName(ctx, field, "clear")}, }, R"rs( pub fn $field$_mut(&mut self) -> $pb$::FieldEntry<'_, $proxied_type$> { @@ -153,10 +153,10 @@ void SingularString::InMsgImpl(Context& ctx, void SingularString::InExternC(Context& ctx, const FieldDescriptor& field) const { - ctx.Emit({{"hazzer_thunk", Thunk(ctx, field, "has")}, - {"getter_thunk", Thunk(ctx, field, "get")}, - {"setter_thunk", Thunk(ctx, field, "set")}, - {"clearer_thunk", Thunk(ctx, field, "clear")}, + ctx.Emit({{"hazzer_thunk", ThunkName(ctx, field, "has")}, + {"getter_thunk", ThunkName(ctx, field, "get")}, + {"setter_thunk", ThunkName(ctx, field, "set")}, + {"clearer_thunk", ThunkName(ctx, field, "clear")}, {"with_presence_fields_thunks", [&] { if (field.has_presence()) { @@ -177,10 +177,10 @@ void SingularString::InThunkCc(Context& ctx, const FieldDescriptor& field) const { ctx.Emit({{"field", cpp::FieldName(&field)}, {"QualifiedMsg", cpp::QualifiedClassName(field.containing_type())}, - {"hazzer_thunk", Thunk(ctx, field, "has")}, - {"getter_thunk", Thunk(ctx, field, "get")}, - {"setter_thunk", Thunk(ctx, field, "set")}, - {"clearer_thunk", Thunk(ctx, field, "clear")}, + {"hazzer_thunk", ThunkName(ctx, field, "has")}, + {"getter_thunk", ThunkName(ctx, field, "get")}, + {"setter_thunk", ThunkName(ctx, field, "set")}, + {"clearer_thunk", ThunkName(ctx, field, "clear")}, {"with_presence_fields_thunks", [&] { if (field.has_presence()) { diff --git a/src/google/protobuf/compiler/rust/message.cc b/src/google/protobuf/compiler/rust/message.cc index 408678367cc5b..5247acfce24dc 100644 --- a/src/google/protobuf/compiler/rust/message.cc +++ b/src/google/protobuf/compiler/rust/message.cc @@ -29,13 +29,13 @@ namespace { void MessageNew(Context& ctx, const Descriptor& msg) { switch (ctx.opts().kernel) { case Kernel::kCpp: - ctx.Emit({{"new_thunk", Thunk(ctx, msg, "new")}}, R"rs( + ctx.Emit({{"new_thunk", ThunkName(ctx, msg, "new")}}, R"rs( Self { inner: $pbr$::MessageInner { msg: unsafe { $new_thunk$() } } } )rs"); return; case Kernel::kUpb: - ctx.Emit({{"new_thunk", Thunk(ctx, msg, "new")}}, R"rs( + ctx.Emit({{"new_thunk", ThunkName(ctx, msg, "new")}}, R"rs( let arena = $pbr$::Arena::new(); Self { inner: $pbr$::MessageInner { @@ -53,13 +53,13 @@ void MessageNew(Context& ctx, const Descriptor& msg) { void MessageSerialize(Context& ctx, const Descriptor& msg) { switch (ctx.opts().kernel) { case Kernel::kCpp: - ctx.Emit({{"serialize_thunk", Thunk(ctx, msg, "serialize")}}, R"rs( + ctx.Emit({{"serialize_thunk", ThunkName(ctx, msg, "serialize")}}, R"rs( unsafe { $serialize_thunk$(self.inner.msg) } )rs"); return; case Kernel::kUpb: - ctx.Emit({{"serialize_thunk", Thunk(ctx, msg, "serialize")}}, R"rs( + ctx.Emit({{"serialize_thunk", ThunkName(ctx, msg, "serialize")}}, R"rs( let arena = $pbr$::Arena::new(); let mut len = 0; unsafe { @@ -78,7 +78,7 @@ void MessageDeserialize(Context& ctx, const Descriptor& msg) { case Kernel::kCpp: ctx.Emit( { - {"deserialize_thunk", Thunk(ctx, msg, "deserialize")}, + {"deserialize_thunk", ThunkName(ctx, msg, "deserialize")}, }, R"rs( let success = unsafe { @@ -94,7 +94,7 @@ void MessageDeserialize(Context& ctx, const Descriptor& msg) { return; case Kernel::kUpb: - ctx.Emit({{"deserialize_thunk", Thunk(ctx, msg, "parse")}}, R"rs( + ctx.Emit({{"deserialize_thunk", ThunkName(ctx, msg, "parse")}}, R"rs( let arena = $pbr$::Arena::new(); let msg = unsafe { $deserialize_thunk$(data.as_ptr(), data.len(), arena.raw()) @@ -122,10 +122,10 @@ void MessageExterns(Context& ctx, const Descriptor& msg) { case Kernel::kCpp: ctx.Emit( { - {"new_thunk", Thunk(ctx, msg, "new")}, - {"delete_thunk", Thunk(ctx, msg, "delete")}, - {"serialize_thunk", Thunk(ctx, msg, "serialize")}, - {"deserialize_thunk", Thunk(ctx, msg, "deserialize")}, + {"new_thunk", ThunkName(ctx, msg, "new")}, + {"delete_thunk", ThunkName(ctx, msg, "delete")}, + {"serialize_thunk", ThunkName(ctx, msg, "serialize")}, + {"deserialize_thunk", ThunkName(ctx, msg, "deserialize")}, }, R"rs( fn $new_thunk$() -> $pbi$::RawMessage; @@ -138,9 +138,9 @@ void MessageExterns(Context& ctx, const Descriptor& msg) { case Kernel::kUpb: ctx.Emit( { - {"new_thunk", Thunk(ctx, msg, "new")}, - {"serialize_thunk", Thunk(ctx, msg, "serialize")}, - {"deserialize_thunk", Thunk(ctx, msg, "parse")}, + {"new_thunk", ThunkName(ctx, msg, "new")}, + {"serialize_thunk", ThunkName(ctx, msg, "serialize")}, + {"deserialize_thunk", ThunkName(ctx, msg, "parse")}, }, R"rs( fn $new_thunk$(arena: $pbi$::RawArena) -> $pbi$::RawMessage; @@ -160,7 +160,7 @@ void MessageDrop(Context& ctx, const Descriptor& msg) { return; } - ctx.Emit({{"delete_thunk", Thunk(ctx, msg, "delete")}}, R"rs( + ctx.Emit({{"delete_thunk", ThunkName(ctx, msg, "delete")}}, R"rs( unsafe { $delete_thunk$(self.inner.msg); } )rs"); } @@ -173,8 +173,8 @@ void GetterForViewOrMut(Context& ctx, const FieldDescriptor& field, bool is_mut) { auto fieldName = field.name(); auto fieldType = field.type(); - auto getter_thunk = Thunk(ctx, field, "get"); - auto setter_thunk = Thunk(ctx, field, "set"); + auto getter_thunk = ThunkName(ctx, field, "get"); + auto setter_thunk = ThunkName(ctx, field, "set"); // If we're dealing with a Mut, the getter must be supplied // self.inner.msg() whereas a View has to be supplied self.msg auto self = is_mut ? "self.inner.msg()" : "self.msg"; @@ -552,10 +552,10 @@ void GenerateThunksCc(Context& ctx, const Descriptor& msg) { {{"abi", "\"C\""}, // Workaround for syntax highlight bug in VSCode. {"Msg", msg.name()}, {"QualifiedMsg", cpp::QualifiedClassName(&msg)}, - {"new_thunk", Thunk(ctx, msg, "new")}, - {"delete_thunk", Thunk(ctx, msg, "delete")}, - {"serialize_thunk", Thunk(ctx, msg, "serialize")}, - {"deserialize_thunk", Thunk(ctx, msg, "deserialize")}, + {"new_thunk", ThunkName(ctx, msg, "new")}, + {"delete_thunk", ThunkName(ctx, msg, "delete")}, + {"serialize_thunk", ThunkName(ctx, msg, "serialize")}, + {"deserialize_thunk", ThunkName(ctx, msg, "deserialize")}, {"nested_msg_thunks", [&] { for (int i = 0; i < msg.nested_type_count(); ++i) { diff --git a/src/google/protobuf/compiler/rust/naming.cc b/src/google/protobuf/compiler/rust/naming.cc index 1167ea7478408..8f6258ec238b0 100644 --- a/src/google/protobuf/compiler/rust/naming.cc +++ b/src/google/protobuf/compiler/rust/naming.cc @@ -77,8 +77,8 @@ std::string FieldPrefix(Context& ctx, const T& field) { } template -std::string Thunk(Context& ctx, const T& field, absl::string_view op) { - std::string thunk = FieldPrefix(ctx, field); +std::string ThunkName(Context& ctx, const T& field, absl::string_view op) { + std::string thunkName = FieldPrefix(ctx, field); absl::string_view format; if (ctx.is_upb() && op == "get") { @@ -95,46 +95,47 @@ std::string Thunk(Context& ctx, const T& field, absl::string_view op) { format = "_$0_$1"; } - absl::SubstituteAndAppend(&thunk, format, op, field.name()); - return thunk; + absl::SubstituteAndAppend(&thunkName, format, op, field.name()); + return thunkName; } std::string ThunkMapOrRepeated(Context& ctx, const FieldDescriptor& field, absl::string_view op) { if (!ctx.is_upb()) { - return Thunk(ctx, field, op); + return ThunkName(ctx, field, op); } - std::string thunk = absl::StrCat("_", FieldPrefix(ctx, field)); + std::string thunkName = absl::StrCat("_", FieldPrefix(ctx, field)); absl::string_view format; if (op == "get") { format = field.is_map() ? "_$1_upb_map" : "_$1_upb_array"; } else if (op == "get_mut") { format = field.is_map() ? "_$1_mutable_upb_map" : "_$1_mutable_upb_array"; } else { - return Thunk(ctx, field, op); + return ThunkName(ctx, field, op); } - absl::SubstituteAndAppend(&thunk, format, op, field.name()); - return thunk; + absl::SubstituteAndAppend(&thunkName, format, op, field.name()); + return thunkName; } } // namespace -std::string Thunk(Context& ctx, const FieldDescriptor& field, - absl::string_view op) { +std::string ThunkName(Context& ctx, const FieldDescriptor& field, + absl::string_view op) { if (field.is_map() || field.is_repeated()) { return ThunkMapOrRepeated(ctx, field, op); } - return Thunk(ctx, field, op); + return ThunkName(ctx, field, op); } -std::string Thunk(Context& ctx, const OneofDescriptor& field, - absl::string_view op) { - return Thunk(ctx, field, op); +std::string ThunkName(Context& ctx, const OneofDescriptor& field, + absl::string_view op) { + return ThunkName(ctx, field, op); } -std::string Thunk(Context& ctx, const Descriptor& msg, absl::string_view op) { +std::string ThunkName(Context& ctx, const Descriptor& msg, + absl::string_view op) { absl::string_view prefix = ctx.is_cpp() ? "__rust_proto_thunk__" : ""; return absl::StrCat(prefix, GetUnderscoreDelimitedFullName(ctx, msg), "_", op); diff --git a/src/google/protobuf/compiler/rust/naming.h b/src/google/protobuf/compiler/rust/naming.h index e6f7b7f970ae9..154e9024c26a1 100644 --- a/src/google/protobuf/compiler/rust/naming.h +++ b/src/google/protobuf/compiler/rust/naming.h @@ -25,12 +25,13 @@ std::string GetRsFile(Context& ctx, const FileDescriptor& file); std::string GetThunkCcFile(Context& ctx, const FileDescriptor& file); std::string GetHeaderFile(Context& ctx, const FileDescriptor& file); -std::string Thunk(Context& ctx, const FieldDescriptor& field, - absl::string_view op); -std::string Thunk(Context& ctx, const OneofDescriptor& field, - absl::string_view op); +std::string ThunkName(Context& ctx, const FieldDescriptor& field, + absl::string_view op); +std::string ThunkName(Context& ctx, const OneofDescriptor& field, + absl::string_view op); -std::string Thunk(Context& ctx, const Descriptor& msg, absl::string_view op); +std::string ThunkName(Context& ctx, const Descriptor& msg, + absl::string_view op); std::string PrimitiveRsTypeName(const FieldDescriptor& field); diff --git a/src/google/protobuf/compiler/rust/oneof.cc b/src/google/protobuf/compiler/rust/oneof.cc index 8d269ae29e612..a2d4ca86e404a 100644 --- a/src/google/protobuf/compiler/rust/oneof.cc +++ b/src/google/protobuf/compiler/rust/oneof.cc @@ -319,7 +319,7 @@ void GenerateOneofAccessors(Context& ctx, const OneofDescriptor& oneof) { )rs"); } }}, - {"case_thunk", Thunk(ctx, oneof, "case")}}, + {"case_thunk", ThunkName(ctx, oneof, "case")}}, R"rs( pub fn r#$oneof_name$(&self) -> $Msg$_::$view_enum_name$ { match unsafe { $case_thunk$(self.inner.msg) } { @@ -342,7 +342,7 @@ void GenerateOneofExternC(Context& ctx, const OneofDescriptor& oneof) { ctx.Emit( { {"case_enum_rs_name", oneofCaseEnumName(oneof)}, - {"case_thunk", Thunk(ctx, oneof, "case")}, + {"case_thunk", ThunkName(ctx, oneof, "case")}, }, R"rs( fn $case_thunk$(raw_msg: $pbi$::RawMessage) -> $Msg$_::$case_enum_rs_name$; @@ -354,7 +354,7 @@ void GenerateOneofThunkCc(Context& ctx, const OneofDescriptor& oneof) { { {"oneof_name", oneof.name()}, {"case_enum_name", oneofCaseEnumName(oneof)}, - {"case_thunk", Thunk(ctx, oneof, "case")}, + {"case_thunk", ThunkName(ctx, oneof, "case")}, {"QualifiedMsg", cpp::QualifiedClassName(oneof.containing_type())}, }, R"cc( From a83da510c47b16e4e399ae77552513dbe889c253 Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Thu, 28 Dec 2023 14:04:53 -0800 Subject: [PATCH 129/255] Automated rollback of commit 0bcc8ef9f25273f94a7ce2284b0050dbb4674eda. PiperOrigin-RevId: 594312823 --- conformance/conformance.proto | 24 +++++++++++++++++++----- conformance/conformance_objc.m | 11 +++++++++++ conformance/conformance_test.cc | 13 +++++++++++++ 3 files changed, 43 insertions(+), 5 deletions(-) diff --git a/conformance/conformance.proto b/conformance/conformance.proto index a3bbc1a488cd6..c4aed80ad097c 100644 --- a/conformance/conformance.proto +++ b/conformance/conformance.proto @@ -35,8 +35,8 @@ enum WireFormat { UNSPECIFIED = 0; PROTOBUF = 1; JSON = 2; + JSPB = 3; // Only used inside Google. Opensource testees just skip it. TEXT_FORMAT = 4; - reserved 3; } enum TestCategory { @@ -49,10 +49,12 @@ enum TestCategory { // https://developers.google.com/protocol-buffers/docs/proto3#json_options // for more detail. JSON_IGNORE_UNKNOWN_PARSING_TEST = 3; + // Test jspb wire format. Only used inside Google. Opensource testees just + // skip it. + JSPB_TEST = 4; // Test text format. For cpp, java and python, testees can already deal with // this type. Testees of other languages can simply skip it. TEXT_FORMAT_TEST = 5; - reserved 4; } // The conformance runner will request a list of failures as the first request. @@ -74,6 +76,8 @@ message ConformanceRequest { oneof payload { bytes protobuf_payload = 1; string json_payload = 2; + // Only used inside Google. Opensource testees just skip it. + string jspb_payload = 7; string text_payload = 8; } @@ -90,11 +94,12 @@ message ConformanceRequest { // TestCategory for more information. TestCategory test_category = 5; + // Specify details for how to encode jspb. + JspbEncodingConfig jspb_encoding_options = 6; + // This can be used in json and text format. If true, testee should print // unknown fields instead of ignore. This feature is optional. bool print_unknown_fields = 9; - - reserved 6, 7; } // Represents a single test case's output. @@ -134,10 +139,19 @@ message ConformanceResponse { // wasn't supported, like JSON input/output. string skipped = 5; + // If the input was successfully parsed and the requested output was JSPB, + // serialize to JSPB and set it in this field. JSPB is only used inside + // Google. Opensource testees can just skip it. + string jspb_payload = 7; + // If the input was successfully parsed and the requested output was // TEXT_FORMAT, serialize to TEXT_FORMAT and set it in this field. string text_payload = 8; } +} - reserved 7; +// Encoding options for jspb format. +message JspbEncodingConfig { + // Encode the value field of Any as jspb array if true, otherwise binary. + bool use_jspb_array_any_format = 1; } diff --git a/conformance/conformance_objc.m b/conformance/conformance_objc.m index 17b1f4de2fc5b..8a37b72beccae 100644 --- a/conformance/conformance_objc.m +++ b/conformance/conformance_objc.m @@ -78,6 +78,11 @@ static void Die(NSString *format, ...) { response.skipped = @"ObjC doesn't support parsing JSON"; break; + case ConformanceRequest_Payload_OneOfCase_JspbPayload: + response.skipped = @"ConformanceRequest had a jspb_payload ConformanceRequest.payload;" + " those aren't supposed to happen with opensource."; + break; + case ConformanceRequest_Payload_OneOfCase_TextPayload: response.skipped = @"ObjC doesn't support parsing TextFormat"; break; @@ -103,6 +108,12 @@ static void Die(NSString *format, ...) { response.skipped = @"ObjC doesn't support generating JSON"; break; + case ConformanceWireFormat_Jspb: + response.skipped = + @"ConformanceRequest had a requested_output_format of JSPB WireFormat; that" + " isn't supposed to happen with opensource."; + break; + case ConformanceWireFormat_TextFormat: // ObjC only has partial objc generation, so don't attempt any tests that need // support. diff --git a/conformance/conformance_test.cc b/conformance/conformance_test.cc index 9fb32d87ce095..ef049c8a539da 100644 --- a/conformance/conformance_test.cc +++ b/conformance/conformance_test.cc @@ -115,6 +115,11 @@ ConformanceTestSuite::ConformanceRequestSetting::ConformanceRequestSetting( break; } + case conformance::JSPB: { + request_.set_jspb_payload(input); + break; + } + case conformance::TEXT_FORMAT: { request_.set_text_payload(input); break; @@ -225,6 +230,9 @@ ConformanceRequest ConformanceTestSuite::TruncateRequest( case ConformanceRequest::kTextPayload: TruncateDebugPayload(debug_request.mutable_text_payload()); break; + case ConformanceRequest::kJspbPayload: + TruncateDebugPayload(debug_request.mutable_jspb_payload()); + break; default: // Do nothing. break; @@ -245,6 +253,9 @@ ConformanceResponse ConformanceTestSuite::TruncateResponse( case ConformanceResponse::kTextPayload: TruncateDebugPayload(debug_response.mutable_text_payload()); break; + case ConformanceResponse::kJspbPayload: + TruncateDebugPayload(debug_response.mutable_jspb_payload()); + break; default: // Do nothing. break; @@ -418,6 +429,8 @@ std::string ConformanceTestSuite::WireFormatToString(WireFormat wire_format) { return "PROTOBUF"; case conformance::JSON: return "JSON"; + case conformance::JSPB: + return "JSPB"; case conformance::TEXT_FORMAT: return "TEXT_FORMAT"; case conformance::UNSPECIFIED: From 79cc57bf57b07cfda731a47c96a325e923b351e0 Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Thu, 28 Dec 2023 22:17:21 +0000 Subject: [PATCH 130/255] Auto-generate files after cl/594312823 --- .../Conformance.pb.cs | 414 +++++++++++++++++- 1 file changed, 394 insertions(+), 20 deletions(-) diff --git a/csharp/src/Google.Protobuf.Conformance/Conformance.pb.cs b/csharp/src/Google.Protobuf.Conformance/Conformance.pb.cs index 167d4aa08222e..26b32fb1762b3 100644 --- a/csharp/src/Google.Protobuf.Conformance/Conformance.pb.cs +++ b/csharp/src/Google.Protobuf.Conformance/Conformance.pb.cs @@ -25,31 +25,35 @@ static ConformanceReflection() { byte[] descriptorData = global::System.Convert.FromBase64String( string.Concat( "Ch1jb25mb3JtYW5jZS9jb25mb3JtYW5jZS5wcm90bxILY29uZm9ybWFuY2Ui", - "HQoKRmFpbHVyZVNldBIPCgdmYWlsdXJlGAEgAygJIpcCChJDb25mb3JtYW5j", + "HQoKRmFpbHVyZVNldBIPCgdmYWlsdXJlGAEgAygJIuMCChJDb25mb3JtYW5j", "ZVJlcXVlc3QSGgoQcHJvdG9idWZfcGF5bG9hZBgBIAEoDEgAEhYKDGpzb25f", - "cGF5bG9hZBgCIAEoCUgAEhYKDHRleHRfcGF5bG9hZBgIIAEoCUgAEjgKF3Jl", - "cXVlc3RlZF9vdXRwdXRfZm9ybWF0GAMgASgOMhcuY29uZm9ybWFuY2UuV2ly", - "ZUZvcm1hdBIUCgxtZXNzYWdlX3R5cGUYBCABKAkSMAoNdGVzdF9jYXRlZ29y", - "eRgFIAEoDjIZLmNvbmZvcm1hbmNlLlRlc3RDYXRlZ29yeRIcChRwcmludF91", - "bmtub3duX2ZpZWxkcxgJIAEoCEIJCgdwYXlsb2FkSgQIBhAHSgQIBxAIIugB", - "ChNDb25mb3JtYW5jZVJlc3BvbnNlEhUKC3BhcnNlX2Vycm9yGAEgASgJSAAS", - "GQoPc2VyaWFsaXplX2Vycm9yGAYgASgJSAASFwoNdGltZW91dF9lcnJvchgJ", - "IAEoCUgAEhcKDXJ1bnRpbWVfZXJyb3IYAiABKAlIABIaChBwcm90b2J1Zl9w", - "YXlsb2FkGAMgASgMSAASFgoManNvbl9wYXlsb2FkGAQgASgJSAASEQoHc2tp", - "cHBlZBgFIAEoCUgAEhYKDHRleHRfcGF5bG9hZBgIIAEoCUgAQggKBnJlc3Vs", - "dEoECAcQCCpMCgpXaXJlRm9ybWF0Eg8KC1VOU1BFQ0lGSUVEEAASDAoIUFJP", - "VE9CVUYQARIICgRKU09OEAISDwoLVEVYVF9GT1JNQVQQBCIECAMQAyqGAQoM", - "VGVzdENhdGVnb3J5EhQKEFVOU1BFQ0lGSUVEX1RFU1QQABIPCgtCSU5BUllf", - "VEVTVBABEg0KCUpTT05fVEVTVBACEiQKIEpTT05fSUdOT1JFX1VOS05PV05f", - "UEFSU0lOR19URVNUEAMSFAoQVEVYVF9GT1JNQVRfVEVTVBAFIgQIBBAEQi8K", - "H2NvbS5nb29nbGUucHJvdG9idWYuY29uZm9ybWFuY2WiAgtDb25mb3JtYW5j", - "ZWIGcHJvdG8z")); + "cGF5bG9hZBgCIAEoCUgAEhYKDGpzcGJfcGF5bG9hZBgHIAEoCUgAEhYKDHRl", + "eHRfcGF5bG9hZBgIIAEoCUgAEjgKF3JlcXVlc3RlZF9vdXRwdXRfZm9ybWF0", + "GAMgASgOMhcuY29uZm9ybWFuY2UuV2lyZUZvcm1hdBIUCgxtZXNzYWdlX3R5", + "cGUYBCABKAkSMAoNdGVzdF9jYXRlZ29yeRgFIAEoDjIZLmNvbmZvcm1hbmNl", + "LlRlc3RDYXRlZ29yeRI+ChVqc3BiX2VuY29kaW5nX29wdGlvbnMYBiABKAsy", + "Hy5jb25mb3JtYW5jZS5Kc3BiRW5jb2RpbmdDb25maWcSHAoUcHJpbnRfdW5r", + "bm93bl9maWVsZHMYCSABKAhCCQoHcGF5bG9hZCL6AQoTQ29uZm9ybWFuY2VS", + "ZXNwb25zZRIVCgtwYXJzZV9lcnJvchgBIAEoCUgAEhkKD3NlcmlhbGl6ZV9l", + "cnJvchgGIAEoCUgAEhcKDXRpbWVvdXRfZXJyb3IYCSABKAlIABIXCg1ydW50", + "aW1lX2Vycm9yGAIgASgJSAASGgoQcHJvdG9idWZfcGF5bG9hZBgDIAEoDEgA", + "EhYKDGpzb25fcGF5bG9hZBgEIAEoCUgAEhEKB3NraXBwZWQYBSABKAlIABIW", + "Cgxqc3BiX3BheWxvYWQYByABKAlIABIWCgx0ZXh0X3BheWxvYWQYCCABKAlI", + "AEIICgZyZXN1bHQiNwoSSnNwYkVuY29kaW5nQ29uZmlnEiEKGXVzZV9qc3Bi", + "X2FycmF5X2FueV9mb3JtYXQYASABKAgqUAoKV2lyZUZvcm1hdBIPCgtVTlNQ", + "RUNJRklFRBAAEgwKCFBST1RPQlVGEAESCAoESlNPThACEggKBEpTUEIQAxIP", + "CgtURVhUX0ZPUk1BVBAEKo8BCgxUZXN0Q2F0ZWdvcnkSFAoQVU5TUEVDSUZJ", + "RURfVEVTVBAAEg8KC0JJTkFSWV9URVNUEAESDQoJSlNPTl9URVNUEAISJAog", + "SlNPTl9JR05PUkVfVU5LTk9XTl9QQVJTSU5HX1RFU1QQAxINCglKU1BCX1RF", + "U1QQBBIUChBURVhUX0ZPUk1BVF9URVNUEAVCLwofY29tLmdvb2dsZS5wcm90", + "b2J1Zi5jb25mb3JtYW5jZaICC0NvbmZvcm1hbmNlYgZwcm90bzM=")); descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData, new pbr::FileDescriptor[] { }, new pbr::GeneratedClrTypeInfo(new[] {typeof(global::Conformance.WireFormat), typeof(global::Conformance.TestCategory), }, null, new pbr::GeneratedClrTypeInfo[] { new pbr::GeneratedClrTypeInfo(typeof(global::Conformance.FailureSet), global::Conformance.FailureSet.Parser, new[]{ "Failure" }, null, null, null, null), - new pbr::GeneratedClrTypeInfo(typeof(global::Conformance.ConformanceRequest), global::Conformance.ConformanceRequest.Parser, new[]{ "ProtobufPayload", "JsonPayload", "TextPayload", "RequestedOutputFormat", "MessageType", "TestCategory", "PrintUnknownFields" }, new[]{ "Payload" }, null, null, null), - new pbr::GeneratedClrTypeInfo(typeof(global::Conformance.ConformanceResponse), global::Conformance.ConformanceResponse.Parser, new[]{ "ParseError", "SerializeError", "TimeoutError", "RuntimeError", "ProtobufPayload", "JsonPayload", "Skipped", "TextPayload" }, new[]{ "Result" }, null, null, null) + new pbr::GeneratedClrTypeInfo(typeof(global::Conformance.ConformanceRequest), global::Conformance.ConformanceRequest.Parser, new[]{ "ProtobufPayload", "JsonPayload", "JspbPayload", "TextPayload", "RequestedOutputFormat", "MessageType", "TestCategory", "JspbEncodingOptions", "PrintUnknownFields" }, new[]{ "Payload" }, null, null, null), + new pbr::GeneratedClrTypeInfo(typeof(global::Conformance.ConformanceResponse), global::Conformance.ConformanceResponse.Parser, new[]{ "ParseError", "SerializeError", "TimeoutError", "RuntimeError", "ProtobufPayload", "JsonPayload", "Skipped", "JspbPayload", "TextPayload" }, new[]{ "Result" }, null, null, null), + new pbr::GeneratedClrTypeInfo(typeof(global::Conformance.JspbEncodingConfig), global::Conformance.JspbEncodingConfig.Parser, new[]{ "UseJspbArrayAnyFormat" }, null, null, null, null) })); } #endregion @@ -60,6 +64,10 @@ public enum WireFormat { [pbr::OriginalName("UNSPECIFIED")] Unspecified = 0, [pbr::OriginalName("PROTOBUF")] Protobuf = 1, [pbr::OriginalName("JSON")] Json = 2, + /// + /// Only used inside Google. Opensource testees just skip it. + /// + [pbr::OriginalName("JSPB")] Jspb = 3, [pbr::OriginalName("TEXT_FORMAT")] TextFormat = 4, } @@ -82,6 +90,11 @@ public enum TestCategory { /// [pbr::OriginalName("JSON_IGNORE_UNKNOWN_PARSING_TEST")] JsonIgnoreUnknownParsingTest = 3, /// + /// Test jspb wire format. Only used inside Google. Opensource testees just + /// skip it. + /// + [pbr::OriginalName("JSPB_TEST")] JspbTest = 4, + /// /// Test text format. For cpp, java and python, testees can already deal with /// this type. Testees of other languages can simply skip it. /// @@ -320,6 +333,7 @@ public ConformanceRequest(ConformanceRequest other) : this() { requestedOutputFormat_ = other.requestedOutputFormat_; messageType_ = other.messageType_; testCategory_ = other.testCategory_; + jspbEncodingOptions_ = other.jspbEncodingOptions_ != null ? other.jspbEncodingOptions_.Clone() : null; printUnknownFields_ = other.printUnknownFields_; switch (other.PayloadCase) { case PayloadOneofCase.ProtobufPayload: @@ -328,6 +342,9 @@ public ConformanceRequest(ConformanceRequest other) : this() { case PayloadOneofCase.JsonPayload: JsonPayload = other.JsonPayload; break; + case PayloadOneofCase.JspbPayload: + JspbPayload = other.JspbPayload; + break; case PayloadOneofCase.TextPayload: TextPayload = other.TextPayload; break; @@ -394,6 +411,35 @@ public void ClearJsonPayload() { } } + /// Field number for the "jspb_payload" field. + public const int JspbPayloadFieldNumber = 7; + /// + /// Only used inside Google. Opensource testees just skip it. + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public string JspbPayload { + get { return HasJspbPayload ? (string) payload_ : ""; } + set { + payload_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); + payloadCase_ = PayloadOneofCase.JspbPayload; + } + } + /// Gets whether the "jspb_payload" field is set + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public bool HasJspbPayload { + get { return payloadCase_ == PayloadOneofCase.JspbPayload; } + } + /// Clears the value of the oneof if it's currently set to "jspb_payload" + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public void ClearJspbPayload() { + if (HasJspbPayload) { + ClearPayload(); + } + } + /// Field number for the "text_payload" field. public const int TextPayloadFieldNumber = 8; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -469,6 +515,21 @@ public string MessageType { } } + /// Field number for the "jspb_encoding_options" field. + public const int JspbEncodingOptionsFieldNumber = 6; + private global::Conformance.JspbEncodingConfig jspbEncodingOptions_; + /// + /// Specify details for how to encode jspb. + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public global::Conformance.JspbEncodingConfig JspbEncodingOptions { + get { return jspbEncodingOptions_; } + set { + jspbEncodingOptions_ = value; + } + } + /// Field number for the "print_unknown_fields" field. public const int PrintUnknownFieldsFieldNumber = 9; private bool printUnknownFields_; @@ -491,6 +552,7 @@ public enum PayloadOneofCase { None = 0, ProtobufPayload = 1, JsonPayload = 2, + JspbPayload = 7, TextPayload = 8, } private PayloadOneofCase payloadCase_ = PayloadOneofCase.None; @@ -524,10 +586,12 @@ public bool Equals(ConformanceRequest other) { } if (ProtobufPayload != other.ProtobufPayload) return false; if (JsonPayload != other.JsonPayload) return false; + if (JspbPayload != other.JspbPayload) return false; if (TextPayload != other.TextPayload) return false; if (RequestedOutputFormat != other.RequestedOutputFormat) return false; if (MessageType != other.MessageType) return false; if (TestCategory != other.TestCategory) return false; + if (!object.Equals(JspbEncodingOptions, other.JspbEncodingOptions)) return false; if (PrintUnknownFields != other.PrintUnknownFields) return false; if (PayloadCase != other.PayloadCase) return false; return Equals(_unknownFields, other._unknownFields); @@ -539,10 +603,12 @@ public override int GetHashCode() { int hash = 1; if (HasProtobufPayload) hash ^= ProtobufPayload.GetHashCode(); if (HasJsonPayload) hash ^= JsonPayload.GetHashCode(); + if (HasJspbPayload) hash ^= JspbPayload.GetHashCode(); if (HasTextPayload) hash ^= TextPayload.GetHashCode(); if (RequestedOutputFormat != global::Conformance.WireFormat.Unspecified) hash ^= RequestedOutputFormat.GetHashCode(); if (MessageType.Length != 0) hash ^= MessageType.GetHashCode(); if (TestCategory != global::Conformance.TestCategory.UnspecifiedTest) hash ^= TestCategory.GetHashCode(); + if (jspbEncodingOptions_ != null) hash ^= JspbEncodingOptions.GetHashCode(); if (PrintUnknownFields != false) hash ^= PrintUnknownFields.GetHashCode(); hash ^= (int) payloadCase_; if (_unknownFields != null) { @@ -583,6 +649,14 @@ public void WriteTo(pb::CodedOutputStream output) { output.WriteRawTag(40); output.WriteEnum((int) TestCategory); } + if (jspbEncodingOptions_ != null) { + output.WriteRawTag(50); + output.WriteMessage(JspbEncodingOptions); + } + if (HasJspbPayload) { + output.WriteRawTag(58); + output.WriteString(JspbPayload); + } if (HasTextPayload) { output.WriteRawTag(66); output.WriteString(TextPayload); @@ -621,6 +695,14 @@ public void WriteTo(pb::CodedOutputStream output) { output.WriteRawTag(40); output.WriteEnum((int) TestCategory); } + if (jspbEncodingOptions_ != null) { + output.WriteRawTag(50); + output.WriteMessage(JspbEncodingOptions); + } + if (HasJspbPayload) { + output.WriteRawTag(58); + output.WriteString(JspbPayload); + } if (HasTextPayload) { output.WriteRawTag(66); output.WriteString(TextPayload); @@ -645,6 +727,9 @@ public int CalculateSize() { if (HasJsonPayload) { size += 1 + pb::CodedOutputStream.ComputeStringSize(JsonPayload); } + if (HasJspbPayload) { + size += 1 + pb::CodedOutputStream.ComputeStringSize(JspbPayload); + } if (HasTextPayload) { size += 1 + pb::CodedOutputStream.ComputeStringSize(TextPayload); } @@ -657,6 +742,9 @@ public int CalculateSize() { if (TestCategory != global::Conformance.TestCategory.UnspecifiedTest) { size += 1 + pb::CodedOutputStream.ComputeEnumSize((int) TestCategory); } + if (jspbEncodingOptions_ != null) { + size += 1 + pb::CodedOutputStream.ComputeMessageSize(JspbEncodingOptions); + } if (PrintUnknownFields != false) { size += 1 + 1; } @@ -681,6 +769,12 @@ public void MergeFrom(ConformanceRequest other) { if (other.TestCategory != global::Conformance.TestCategory.UnspecifiedTest) { TestCategory = other.TestCategory; } + if (other.jspbEncodingOptions_ != null) { + if (jspbEncodingOptions_ == null) { + JspbEncodingOptions = new global::Conformance.JspbEncodingConfig(); + } + JspbEncodingOptions.MergeFrom(other.JspbEncodingOptions); + } if (other.PrintUnknownFields != false) { PrintUnknownFields = other.PrintUnknownFields; } @@ -691,6 +785,9 @@ public void MergeFrom(ConformanceRequest other) { case PayloadOneofCase.JsonPayload: JsonPayload = other.JsonPayload; break; + case PayloadOneofCase.JspbPayload: + JspbPayload = other.JspbPayload; + break; case PayloadOneofCase.TextPayload: TextPayload = other.TextPayload; break; @@ -731,6 +828,17 @@ public void MergeFrom(pb::CodedInputStream input) { TestCategory = (global::Conformance.TestCategory) input.ReadEnum(); break; } + case 50: { + if (jspbEncodingOptions_ == null) { + JspbEncodingOptions = new global::Conformance.JspbEncodingConfig(); + } + input.ReadMessage(JspbEncodingOptions); + break; + } + case 58: { + JspbPayload = input.ReadString(); + break; + } case 66: { TextPayload = input.ReadString(); break; @@ -774,6 +882,17 @@ public void MergeFrom(pb::CodedInputStream input) { TestCategory = (global::Conformance.TestCategory) input.ReadEnum(); break; } + case 50: { + if (jspbEncodingOptions_ == null) { + JspbEncodingOptions = new global::Conformance.JspbEncodingConfig(); + } + input.ReadMessage(JspbEncodingOptions); + break; + } + case 58: { + JspbPayload = input.ReadString(); + break; + } case 66: { TextPayload = input.ReadString(); break; @@ -849,6 +968,9 @@ public ConformanceResponse(ConformanceResponse other) : this() { case ResultOneofCase.Skipped: Skipped = other.Skipped; break; + case ResultOneofCase.JspbPayload: + JspbPayload = other.JspbPayload; + break; case ResultOneofCase.TextPayload: TextPayload = other.TextPayload; break; @@ -1079,6 +1201,37 @@ public void ClearSkipped() { } } + /// Field number for the "jspb_payload" field. + public const int JspbPayloadFieldNumber = 7; + /// + /// If the input was successfully parsed and the requested output was JSPB, + /// serialize to JSPB and set it in this field. JSPB is only used inside + /// Google. Opensource testees can just skip it. + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public string JspbPayload { + get { return HasJspbPayload ? (string) result_ : ""; } + set { + result_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); + resultCase_ = ResultOneofCase.JspbPayload; + } + } + /// Gets whether the "jspb_payload" field is set + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public bool HasJspbPayload { + get { return resultCase_ == ResultOneofCase.JspbPayload; } + } + /// Clears the value of the oneof if it's currently set to "jspb_payload" + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public void ClearJspbPayload() { + if (HasJspbPayload) { + ClearResult(); + } + } + /// Field number for the "text_payload" field. public const int TextPayloadFieldNumber = 8; /// @@ -1120,6 +1273,7 @@ public enum ResultOneofCase { ProtobufPayload = 3, JsonPayload = 4, Skipped = 5, + JspbPayload = 7, TextPayload = 8, } private ResultOneofCase resultCase_ = ResultOneofCase.None; @@ -1158,6 +1312,7 @@ public bool Equals(ConformanceResponse other) { if (ProtobufPayload != other.ProtobufPayload) return false; if (JsonPayload != other.JsonPayload) return false; if (Skipped != other.Skipped) return false; + if (JspbPayload != other.JspbPayload) return false; if (TextPayload != other.TextPayload) return false; if (ResultCase != other.ResultCase) return false; return Equals(_unknownFields, other._unknownFields); @@ -1174,6 +1329,7 @@ public override int GetHashCode() { if (HasProtobufPayload) hash ^= ProtobufPayload.GetHashCode(); if (HasJsonPayload) hash ^= JsonPayload.GetHashCode(); if (HasSkipped) hash ^= Skipped.GetHashCode(); + if (HasJspbPayload) hash ^= JspbPayload.GetHashCode(); if (HasTextPayload) hash ^= TextPayload.GetHashCode(); hash ^= (int) resultCase_; if (_unknownFields != null) { @@ -1218,6 +1374,10 @@ public void WriteTo(pb::CodedOutputStream output) { output.WriteRawTag(50); output.WriteString(SerializeError); } + if (HasJspbPayload) { + output.WriteRawTag(58); + output.WriteString(JspbPayload); + } if (HasTextPayload) { output.WriteRawTag(66); output.WriteString(TextPayload); @@ -1260,6 +1420,10 @@ public void WriteTo(pb::CodedOutputStream output) { output.WriteRawTag(50); output.WriteString(SerializeError); } + if (HasJspbPayload) { + output.WriteRawTag(58); + output.WriteString(JspbPayload); + } if (HasTextPayload) { output.WriteRawTag(66); output.WriteString(TextPayload); @@ -1299,6 +1463,9 @@ public int CalculateSize() { if (HasSkipped) { size += 1 + pb::CodedOutputStream.ComputeStringSize(Skipped); } + if (HasJspbPayload) { + size += 1 + pb::CodedOutputStream.ComputeStringSize(JspbPayload); + } if (HasTextPayload) { size += 1 + pb::CodedOutputStream.ComputeStringSize(TextPayload); } @@ -1336,6 +1503,9 @@ public void MergeFrom(ConformanceResponse other) { case ResultOneofCase.Skipped: Skipped = other.Skipped; break; + case ResultOneofCase.JspbPayload: + JspbPayload = other.JspbPayload; + break; case ResultOneofCase.TextPayload: TextPayload = other.TextPayload; break; @@ -1380,6 +1550,10 @@ public void MergeFrom(pb::CodedInputStream input) { SerializeError = input.ReadString(); break; } + case 58: { + JspbPayload = input.ReadString(); + break; + } case 66: { TextPayload = input.ReadString(); break; @@ -1427,6 +1601,10 @@ public void MergeFrom(pb::CodedInputStream input) { SerializeError = input.ReadString(); break; } + case 58: { + JspbPayload = input.ReadString(); + break; + } case 66: { TextPayload = input.ReadString(); break; @@ -1442,6 +1620,202 @@ public void MergeFrom(pb::CodedInputStream input) { } + /// + /// Encoding options for jspb format. + /// + [global::System.Diagnostics.DebuggerDisplayAttribute("{ToString(),nq}")] + public sealed partial class JspbEncodingConfig : pb::IMessage + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + , pb::IBufferMessage + #endif + { + private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new JspbEncodingConfig()); + private pb::UnknownFieldSet _unknownFields; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public static pb::MessageParser Parser { get { return _parser; } } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public static pbr::MessageDescriptor Descriptor { + get { return global::Conformance.ConformanceReflection.Descriptor.MessageTypes[3]; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + pbr::MessageDescriptor pb::IMessage.Descriptor { + get { return Descriptor; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public JspbEncodingConfig() { + OnConstruction(); + } + + partial void OnConstruction(); + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public JspbEncodingConfig(JspbEncodingConfig other) : this() { + useJspbArrayAnyFormat_ = other.useJspbArrayAnyFormat_; + _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public JspbEncodingConfig Clone() { + return new JspbEncodingConfig(this); + } + + /// Field number for the "use_jspb_array_any_format" field. + public const int UseJspbArrayAnyFormatFieldNumber = 1; + private bool useJspbArrayAnyFormat_; + /// + /// Encode the value field of Any as jspb array if true, otherwise binary. + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public bool UseJspbArrayAnyFormat { + get { return useJspbArrayAnyFormat_; } + set { + useJspbArrayAnyFormat_ = value; + } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public override bool Equals(object other) { + return Equals(other as JspbEncodingConfig); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public bool Equals(JspbEncodingConfig other) { + if (ReferenceEquals(other, null)) { + return false; + } + if (ReferenceEquals(other, this)) { + return true; + } + if (UseJspbArrayAnyFormat != other.UseJspbArrayAnyFormat) return false; + return Equals(_unknownFields, other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public override int GetHashCode() { + int hash = 1; + if (UseJspbArrayAnyFormat != false) hash ^= UseJspbArrayAnyFormat.GetHashCode(); + if (_unknownFields != null) { + hash ^= _unknownFields.GetHashCode(); + } + return hash; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public override string ToString() { + return pb::JsonFormatter.ToDiagnosticString(this); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public void WriteTo(pb::CodedOutputStream output) { + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + output.WriteRawMessage(this); + #else + if (UseJspbArrayAnyFormat != false) { + output.WriteRawTag(8); + output.WriteBool(UseJspbArrayAnyFormat); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(output); + } + #endif + } + + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) { + if (UseJspbArrayAnyFormat != false) { + output.WriteRawTag(8); + output.WriteBool(UseJspbArrayAnyFormat); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public int CalculateSize() { + int size = 0; + if (UseJspbArrayAnyFormat != false) { + size += 1 + 1; + } + if (_unknownFields != null) { + size += _unknownFields.CalculateSize(); + } + return size; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public void MergeFrom(JspbEncodingConfig other) { + if (other == null) { + return; + } + if (other.UseJspbArrayAnyFormat != false) { + UseJspbArrayAnyFormat = other.UseJspbArrayAnyFormat; + } + _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public void MergeFrom(pb::CodedInputStream input) { + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + input.ReadRawMessage(this); + #else + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); + break; + case 8: { + UseJspbArrayAnyFormat = input.ReadBool(); + break; + } + } + } + #endif + } + + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 8: { + UseJspbArrayAnyFormat = input.ReadBool(); + break; + } + } + } + } + #endif + + } + #endregion } From 4ec9170bcdfaba23c15fbbc90917e6316a99cc86 Mon Sep 17 00:00:00 2001 From: Adam Cozzette Date: Thu, 28 Dec 2023 14:40:25 -0800 Subject: [PATCH 131/255] Fix layering check for usage of gtest To satisfy the layering check, we need to depend on :gtest for the headers, in addition to :gtest_main which provides the main() function. There are a bunch of formatting changes as a side effect of this, but they should be harmless. PiperOrigin-RevId: 594318263 --- bazel/BUILD | 2 +- bazel/build_defs.bzl | 8 ++-- .../cc_library_func.bzl | 1 + benchmarks/BUILD | 3 +- java/internal/testing.bzl | 2 +- protos/BUILD | 11 +++-- protos/bazel/BUILD | 2 +- protos/bazel/upb_cc_proto_library.bzl | 1 + protos_generator/BUILD | 4 +- protos_generator/tests/BUILD | 3 +- python/BUILD.bazel | 15 ++++--- python/pb_unit_tests/BUILD | 15 ++++--- rust/BUILD | 3 +- rust/cpp_kernel/BUILD | 4 +- rust/test/BUILD | 5 +++ rust/test/cpp/interop/BUILD | 4 +- rust/test/shared/BUILD | 44 +++++++++---------- rust/upb_kernel/BUILD | 2 +- src/google/protobuf/editions/BUILD | 3 ++ third_party/utf8_range/BUILD.bazel | 1 + upb/BUILD | 6 +-- upb/base/BUILD | 4 +- upb/collections/BUILD | 4 +- upb/hash/BUILD | 7 +-- upb/io/BUILD | 13 +++--- upb/json/BUILD | 9 ++-- upb/lex/BUILD | 7 +-- upb/mem/BUILD | 7 +-- upb/message/BUILD | 26 +++++++---- upb/mini_descriptor/BUILD | 7 +-- upb/mini_table/BUILD | 7 +-- upb/port/BUILD | 4 +- upb/reflection/BUILD | 7 +-- upb/test/BUILD | 17 ++++--- upb/text/BUILD | 4 +- upb/util/BUILD | 12 +++-- upb/wire/BUILD | 9 ++-- 37 files changed, 166 insertions(+), 117 deletions(-) diff --git a/bazel/BUILD b/bazel/BUILD index be2e946f4cb27..90d578fd50948 100644 --- a/bazel/BUILD +++ b/bazel/BUILD @@ -52,8 +52,8 @@ bzl_library( ], deps = [ "@bazel_skylib//lib:paths", - "@rules_proto//proto:defs", "@bazel_tools//tools/cpp:toolchain_utils.bzl", + "@rules_proto//proto:defs", ], ) diff --git a/bazel/build_defs.bzl b/bazel/build_defs.bzl index 1ed1ffe40c5e2..2da636871ec35 100644 --- a/bazel/build_defs.bzl +++ b/bazel/build_defs.bzl @@ -31,8 +31,8 @@ _DEFAULT_COPTS.extend([ UPB_DEFAULT_CPPOPTS = select({ "//upb:windows": [], # begin:google_only -# # Override default -Oz for release builds on Android. -# "//bazel:android_opt": _DEFAULT_CPPOPTS + ["-O2"], + # # Override default -Oz for release builds on Android. + # "//bazel:android_opt": _DEFAULT_CPPOPTS + ["-O2"], # end:google_only "//conditions:default": _DEFAULT_CPPOPTS, }) @@ -41,8 +41,8 @@ UPB_DEFAULT_COPTS = select({ "//upb:windows": [], "//upb:fasttable_enabled_setting": ["-std=gnu99", "-DUPB_ENABLE_FASTTABLE"], # begin:google_only -# # Override default -Oz for release builds on Android. -# "//bazel:android_opt": _DEFAULT_COPTS + ["-O2"], + # # Override default -Oz for release builds on Android. + # "//bazel:android_opt": _DEFAULT_COPTS + ["-O2"], # end:google_only "//conditions:default": _DEFAULT_COPTS, }) diff --git a/bazel/upb_proto_library_internal/cc_library_func.bzl b/bazel/upb_proto_library_internal/cc_library_func.bzl index 31ebe9057b8b2..0c567ce8d4e4f 100644 --- a/bazel/upb_proto_library_internal/cc_library_func.bzl +++ b/bazel/upb_proto_library_internal/cc_library_func.bzl @@ -14,6 +14,7 @@ load("@bazel_tools//tools/cpp:toolchain_utils.bzl", "find_cpp_toolchain") def upb_use_cpp_toolchain(): return ["@bazel_tools//tools/cpp:toolchain_type"] + # end:github_only def cc_library_func(ctx, name, hdrs, srcs, copts, includes, dep_ccinfos): diff --git a/benchmarks/BUILD b/benchmarks/BUILD index b975bac8e3ee9..3b9a9cbde0231 100644 --- a/benchmarks/BUILD +++ b/benchmarks/BUILD @@ -76,7 +76,6 @@ cc_test( ":benchmark_descriptor_upb_proto", ":benchmark_descriptor_upb_proto_reflection", "//:protobuf", - "@com_google_googletest//:gtest_main", "//src/google/protobuf/json", "//upb:base", "//upb:descriptor_upb_proto", @@ -88,6 +87,8 @@ cc_test( "@com_github_google_benchmark//:benchmark_main", "@com_google_absl//absl/container:flat_hash_set", "@com_google_absl//absl/log:absl_check", + "@com_google_googletest//:gtest", + "@com_google_googletest//:gtest_main", ], ) diff --git a/java/internal/testing.bzl b/java/internal/testing.bzl index b2a781baba3e4..ee8f80f2623eb 100644 --- a/java/internal/testing.bzl +++ b/java/internal/testing.bzl @@ -52,7 +52,7 @@ def junit_tests(name, srcs, data = [], deps = [], package_name = "com.google.pro if test_prefix: test_name = "%s%s" % (test_prefix, test_name) test_names = test_names + [test_name] - suite_name = prefix + '_' + test_name + suite_name = prefix + "_" + test_name _gen_suite( name = suite_name, srcs = [src], diff --git a/protos/BUILD b/protos/BUILD index 7712c38bcb971..f903249a04a52 100644 --- a/protos/BUILD +++ b/protos/BUILD @@ -132,10 +132,11 @@ cc_test( copts = UPB_DEFAULT_CPPOPTS, deps = [ ":protos_internal", - "@com_google_googletest//:gtest_main", - "//upb:mem", "//protos_generator/tests:test_model_upb_cc_proto", "//protos_generator/tests:test_model_upb_proto", + "//upb:mem", + "@com_google_googletest//:gtest", + "@com_google_googletest//:gtest_main", ], ) @@ -150,6 +151,7 @@ cc_test( srcs = ["repeated_field_iterator_test.cc"], deps = [ ":repeated_field", + "@com_google_googletest//:gtest", "@com_google_googletest//:gtest_main", ], ) @@ -158,12 +160,13 @@ cc_test( name = "protos_extension_lock_test", srcs = ["protos_extension_lock_test.cc"], deps = [ - "@com_google_googletest//:gtest_main", - "//upb:mem", "//protos", "//protos:protos_extension_lock", "//protos_generator/tests:test_model_upb_cc_proto", + "//upb:mem", "@com_google_absl//absl/hash", "@com_google_absl//absl/log:absl_check", + "@com_google_googletest//:gtest", + "@com_google_googletest//:gtest_main", ], ) diff --git a/protos/bazel/BUILD b/protos/bazel/BUILD index ea91541adf39b..7381375fed39a 100644 --- a/protos/bazel/BUILD +++ b/protos/bazel/BUILD @@ -18,8 +18,8 @@ bzl_library( srcs = ["upb_cc_proto_library.bzl"], visibility = ["//visibility:public"], deps = [ - "@bazel_skylib//lib:paths", "//bazel:upb_proto_library_bzl", + "@bazel_skylib//lib:paths", "@bazel_tools//tools/cpp:toolchain_utils.bzl", ], ) diff --git a/protos/bazel/upb_cc_proto_library.bzl b/protos/bazel/upb_cc_proto_library.bzl index ad193b4a8a8fa..cacf709a61a29 100644 --- a/protos/bazel/upb_cc_proto_library.bzl +++ b/protos/bazel/upb_cc_proto_library.bzl @@ -22,6 +22,7 @@ load("@bazel_tools//tools/cpp:toolchain_utils.bzl", "find_cpp_toolchain") def use_cpp_toolchain(): return ["@bazel_tools//tools/cpp:toolchain_type"] + # end:github_only # Generic support code ######################################################### diff --git a/protos_generator/BUILD b/protos_generator/BUILD index ac8cfeca8b2d3..d76c944faefe2 100644 --- a/protos_generator/BUILD +++ b/protos_generator/BUILD @@ -56,12 +56,12 @@ cc_library( ":names", ":output", "//:protobuf", - "@com_google_absl//absl/container:flat_hash_set", - "@com_google_absl//absl/strings", "//upb_generator:common", "//upb_generator:file_layout", "//upb_generator:keywords", "//upb_generator:names", + "@com_google_absl//absl/container:flat_hash_set", + "@com_google_absl//absl/strings", ], ) diff --git a/protos_generator/tests/BUILD b/protos_generator/tests/BUILD index c47a71fec45ef..8ebb985531ca7 100644 --- a/protos_generator/tests/BUILD +++ b/protos_generator/tests/BUILD @@ -124,12 +124,13 @@ cc_test( copts = UPB_DEFAULT_CPPOPTS, deps = [ # begin:google_only -# ":legacy_name_test_proto", + # ":legacy_name_test_proto", # end:google_only ":no_package_upb_cc_proto", ":test_model_upb_cc_proto", ":test_model_upb_proto", ":naming_conflict_upb_cc_proto", + "@com_google_googletest//:gtest", "@com_google_googletest//:gtest_main", "@com_google_absl//absl/status:statusor", "@com_google_absl//absl/strings", diff --git a/python/BUILD.bazel b/python/BUILD.bazel index 608381c274fe1..8967bacb3dcd0 100644 --- a/python/BUILD.bazel +++ b/python/BUILD.bazel @@ -13,6 +13,7 @@ load("//bazel:build_defs.bzl", "UPB_DEFAULT_COPTS") # begin:github_only load("@rules_pkg//:mappings.bzl", "pkg_files") load("//python:build_targets.bzl", "build_targets") + build_targets(name = "python") # end:github_only @@ -20,7 +21,7 @@ licenses(["notice"]) package( # begin:google_only -# default_applicable_licenses = ["//upb:license"], + # default_applicable_licenses = ["//upb:license"], # end:google_only default_visibility = ["//python/dist:__pkg__"], ) @@ -136,10 +137,10 @@ selects.config_setting_group( # begin:github_only _message_target_compatible_with = { - "@platforms//os:windows": ["@platforms//:incompatible"], - "@system_python//:none": ["@platforms//:incompatible"], - "@system_python//:unsupported": ["@platforms//:incompatible"], - "//conditions:default": [], + "@platforms//os:windows": ["@platforms//:incompatible"], + "@system_python//:none": ["@platforms//:incompatible"], + "@system_python//:unsupported": ["@platforms//:incompatible"], + "//conditions:default": [], } # end:github_only @@ -176,7 +177,7 @@ filegroup( "unknown_fields.h", ], # begin:google_only -# compatible_with = ["//buildenv/target:non_prod"], + # compatible_with = ["//buildenv/target:non_prod"], # end:google_only ) @@ -190,6 +191,7 @@ py_extension( ], target_compatible_with = select(_message_target_compatible_with), deps = [ + "//third_party/utf8_range", "//upb:base", "//upb:descriptor_upb_proto_reflection", "//upb:eps_copy_input_stream", @@ -203,6 +205,5 @@ py_extension( "//upb/util:compare", "//upb/util:def_to_proto", "//upb/util:required_fields", - "//third_party/utf8_range", ], ) diff --git a/python/pb_unit_tests/BUILD b/python/pb_unit_tests/BUILD index 56ee25086d625..8bb43dcc4e5f1 100644 --- a/python/pb_unit_tests/BUILD +++ b/python/pb_unit_tests/BUILD @@ -6,6 +6,7 @@ # https://developers.google.com/open-source/licenses/bsd load(":pyproto_test_wrapper.bzl", "pyproto_test_wrapper") + # begin:github_only load("@pip_deps//:requirements.bzl", "requirement") # end:github_only @@ -39,15 +40,15 @@ py_test( name = "numpy_test", srcs = ["numpy_test_wrapper.py"], main = "numpy_test_wrapper.py", - deps = [ - requirement("numpy"), - "//python/google/protobuf/internal/numpy:numpy_test", - "//python:_message", - ], target_compatible_with = select({ - "@system_python//:supported": [], - "//conditions:default": ["@platforms//:incompatible"], + "@system_python//:supported": [], + "//conditions:default": ["@platforms//:incompatible"], }), + deps = [ + requirement("numpy"), + "//python:_message", + "//python/google/protobuf/internal/numpy:numpy_test", + ], ) # end:github_only diff --git a/rust/BUILD b/rust/BUILD index b3374f434fe53..62ae297d66452 100644 --- a/rust/BUILD +++ b/rust/BUILD @@ -2,7 +2,6 @@ load("@rules_rust//rust:defs.bzl", "rust_library", "rust_test") load("@bazel_skylib//rules:common_settings.bzl", "string_flag") - load("@rules_proto//proto:defs.bzl", "proto_lang_toolchain") package( @@ -74,8 +73,8 @@ rust_library( ], rustc_flags = ["--cfg=upb_kernel"], visibility = [ - "//src/google/protobuf:__subpackages__", "//rust:__subpackages__", + "//src/google/protobuf:__subpackages__", ], deps = [ ":utf8", diff --git a/rust/cpp_kernel/BUILD b/rust/cpp_kernel/BUILD index e9baa3a467aee..6582b038985e0 100644 --- a/rust/cpp_kernel/BUILD +++ b/rust/cpp_kernel/BUILD @@ -7,13 +7,13 @@ cc_library( srcs = ["cpp_api.cc"], hdrs = ["cpp_api.h"], visibility = [ - "//src/google/protobuf:__subpackages__", "//rust:__subpackages__", + "//src/google/protobuf:__subpackages__", ], deps = [ ":rust_alloc_for_cpp_api", # buildcleaner: keep - "@com_google_absl//absl/strings:string_view", "//:protobuf_nowkt", + "@com_google_absl//absl/strings:string_view", ], ) diff --git a/rust/test/BUILD b/rust/test/BUILD index 186374fb9c399..2541732ebe51e 100644 --- a/rust/test/BUILD +++ b/rust/test/BUILD @@ -7,10 +7,15 @@ load( load("@rules_cc//cc:defs.bzl", "cc_proto_library") UNITTEST_PROTO_TARGET = "//src/google/protobuf:test_protos" + UNITTEST_CC_PROTO_TARGET = "//src/google/protobuf:cc_test_protos" + UNITTEST_PROTO3_TARGET = "//src/google/protobuf:test_protos" + UNITTEST_PROTO3_CC_TARGET = "//src/google/protobuf:cc_test_protos" + UNITTEST_PROTO3_OPTIONAL_TARGET = "//src/google/protobuf:test_protos" + UNITTEST_PROTO3_OPTIONAL_CC_TARGET = "//src/google/protobuf:cc_test_protos" alias( diff --git a/rust/test/cpp/interop/BUILD b/rust/test/cpp/interop/BUILD index bacd078cf0d3f..abbf0d224f5f1 100644 --- a/rust/test/cpp/interop/BUILD +++ b/rust/test/cpp/interop/BUILD @@ -6,9 +6,9 @@ cc_library( name = "test_utils", srcs = ["test_utils.cc"], deps = [ - "@com_google_absl//absl/strings", "//rust/cpp_kernel:cpp_api", "//rust/test:unittest_cc_proto", + "@com_google_absl//absl/strings", ], ) @@ -21,8 +21,8 @@ rust_test( ], deps = [ ":test_utils", - "@crate_index//:googletest", "//rust:protobuf_cpp", "//rust/test:unittest_cc_rust_proto", + "@crate_index//:googletest", ], ) diff --git a/rust/test/shared/BUILD b/rust/test/shared/BUILD index 3a61c4d1439ce..9fb9a1bd00c49 100644 --- a/rust/test/shared/BUILD +++ b/rust/test/shared/BUILD @@ -23,8 +23,8 @@ rust_library( "//rust:protobuf_upb": "protobuf", }, deps = [ - "@crate_index//:googletest", "//rust:protobuf_upb", + "@crate_index//:googletest", ], ) @@ -35,8 +35,8 @@ rust_library( "//rust:protobuf_cpp": "protobuf", }, deps = [ - "@crate_index//:googletest", "//rust:protobuf_cpp", + "@crate_index//:googletest", ], ) @@ -48,9 +48,9 @@ rust_test( "not_build:arm", ], deps = [ - "@crate_index//:googletest", "//rust/test:child_upb_rust_proto", "//rust/test:parent_upb_rust_proto", + "@crate_index//:googletest", ], ) @@ -62,9 +62,9 @@ rust_test( "not_build:arm", ], deps = [ - "@crate_index//:googletest", "//rust/test:child_cc_rust_proto", "//rust/test:parent_cc_rust_proto", + "@crate_index//:googletest", ], ) @@ -76,8 +76,8 @@ rust_test( "not_build:arm", ], deps = [ - "@crate_index//:googletest", "//rust/test:edition2023_cc_rust_proto", + "@crate_index//:googletest", ], ) @@ -89,8 +89,8 @@ rust_test( "not_build:arm", ], deps = [ - "@crate_index//:googletest", "//rust/test:edition2023_upb_rust_proto", + "@crate_index//:googletest", ], ) @@ -105,10 +105,10 @@ rust_test( "not_build:arm", ], deps = [ - "@crate_index//:googletest", "//rust:protobuf_cpp", "//rust/test:enums_cc_rust_proto", "//rust/test:unittest_cc_rust_proto", + "@crate_index//:googletest", ], ) @@ -123,10 +123,10 @@ rust_test( "not_build:arm", ], deps = [ - "@crate_index//:googletest", "//rust:protobuf_upb", "//rust/test:enums_upb_rust_proto", "//rust/test:unittest_upb_rust_proto", + "@crate_index//:googletest", ], ) @@ -166,9 +166,9 @@ rust_test( "not_build:arm", ], deps = [ - "@crate_index//:googletest", "//rust/test:reserved_cc_rust_proto", "//rust/test:unittest_cc_rust_proto", + "@crate_index//:googletest", ], ) @@ -180,9 +180,9 @@ rust_test( "not_build:arm", ], deps = [ - "@crate_index//:googletest", "//rust/test:reserved_upb_rust_proto", "//rust/test:unittest_upb_rust_proto", + "@crate_index//:googletest", ], ) @@ -221,10 +221,10 @@ rust_test( "not_build:arm", ], deps = [ - "@crate_index//:googletest", "//rust:protobuf_cpp", "//rust/test:unittest_cc_rust_proto", "//rust/test/shared:matchers_cpp", + "@crate_index//:googletest", ], ) @@ -243,10 +243,10 @@ rust_test( "not_build:arm", ], deps = [ - "@crate_index//:googletest", "//rust:protobuf_upb", "//rust/test:unittest_upb_rust_proto", "//rust/test/shared:matchers_upb", + "@crate_index//:googletest", ], ) @@ -262,11 +262,11 @@ rust_test( "not_build:arm", ], deps = [ - "@crate_index//:googletest", "//rust:protobuf_cpp", "//rust/test:unittest_proto3_cc_rust_proto", "//rust/test:unittest_proto3_optional_cc_rust_proto", "//rust/test/shared:matchers_cpp", + "@crate_index//:googletest", ], ) @@ -282,11 +282,11 @@ rust_test( "not_build:arm", ], deps = [ - "@crate_index//:googletest", "//rust:protobuf_upb", "//rust/test:unittest_proto3_optional_upb_rust_proto", "//rust/test:unittest_proto3_upb_rust_proto", "//rust/test/shared:matchers_upb", + "@crate_index//:googletest", ], ) @@ -298,8 +298,8 @@ rust_test( "not_build:arm", ], deps = [ - "@crate_index//:googletest", "//rust/test:unittest_upb_rust_proto", + "@crate_index//:googletest", ], ) @@ -311,8 +311,8 @@ rust_test( "not_build:arm", ], deps = [ - "@crate_index//:googletest", "//rust/test:unittest_cc_rust_proto", + "@crate_index//:googletest", ], ) @@ -324,8 +324,8 @@ rust_test( "not_build:arm", ], deps = [ - "@crate_index//:googletest", "//rust/test:nested_cc_rust_proto", + "@crate_index//:googletest", ], ) @@ -337,8 +337,8 @@ rust_test( "not_build:arm", ], deps = [ - "@crate_index//:googletest", "//rust/test:nested_upb_rust_proto", + "@crate_index//:googletest", ], ) @@ -356,9 +356,9 @@ rust_test( "not_build:arm", ], deps = [ - "@crate_index//:googletest", "//rust:protobuf_cpp", "//rust/test:unittest_cc_rust_proto", + "@crate_index//:googletest", ], ) @@ -376,9 +376,9 @@ rust_test( "not_build:arm", ], deps = [ - "@crate_index//:googletest", "//rust:protobuf_upb", "//rust/test:unittest_upb_rust_proto", + "@crate_index//:googletest", ], ) @@ -393,8 +393,8 @@ rust_test( "not_build:arm", ], deps = [ - "@crate_index//:googletest", "//rust/test:map_unittest_cc_rust_proto", + "@crate_index//:googletest", ], ) @@ -409,7 +409,7 @@ rust_test( "not_build:arm", ], deps = [ - "@crate_index//:googletest", "//rust/test:map_unittest_upb_rust_proto", + "@crate_index//:googletest", ], ) diff --git a/rust/upb_kernel/BUILD b/rust/upb_kernel/BUILD index 3c373323e03ac..62ae49a3f8cca 100644 --- a/rust/upb_kernel/BUILD +++ b/rust/upb_kernel/BUILD @@ -4,8 +4,8 @@ cc_library( name = "upb_c_api", srcs = ["upb_api.c"], visibility = [ - "//src/google/protobuf:__subpackages__", "//rust:__subpackages__", + "//src/google/protobuf:__subpackages__", ], deps = [ "//upb:mem", diff --git a/src/google/protobuf/editions/BUILD b/src/google/protobuf/editions/BUILD index 52c6a402df7f3..76d1a0ed61dfd 100644 --- a/src/google/protobuf/editions/BUILD +++ b/src/google/protobuf/editions/BUILD @@ -84,6 +84,7 @@ cc_test( "@com_google_absl//absl/status:statusor", "@com_google_absl//absl/strings", "@com_google_absl//absl/strings:string_view", + "@com_google_googletest//:gtest", "@com_google_googletest//:gtest_main", ], ) @@ -246,6 +247,7 @@ cc_test( ":test_messages_proto3_editions_cc_proto", "//:protobuf", "//src/google/protobuf:test_textproto", + "@com_google_googletest//:gtest", "@com_google_googletest//:gtest_main", ], ) @@ -255,6 +257,7 @@ cc_test( srcs = ["generated_reflection_test.cc"], deps = [ ":test_messages_proto2_editions_cc_proto", + "@com_google_googletest//:gtest", "@com_google_googletest//:gtest_main", ], ) diff --git a/third_party/utf8_range/BUILD.bazel b/third_party/utf8_range/BUILD.bazel index d24e8a14314cd..fdc1a49b1e109 100644 --- a/third_party/utf8_range/BUILD.bazel +++ b/third_party/utf8_range/BUILD.bazel @@ -59,6 +59,7 @@ cc_test( ":utf8_range", ":utf8_validity", "@com_google_absl//absl/strings", + "@com_google_googletest//:gtest", "@com_google_googletest//:gtest_main", ], ) diff --git a/upb/BUILD b/upb/BUILD index e6cdff77dd990..13047648e5bcb 100644 --- a/upb/BUILD +++ b/upb/BUILD @@ -498,16 +498,16 @@ filegroup( "**/*.c", "**/*.h", "**/*.hpp", - ], + ], exclude = [ "**/conformance_upb.c", "reflection/stage0/**/*", ], ), visibility = [ - "//upb/cmake:__pkg__", "//python/dist:__pkg__", - ] + "//upb/cmake:__pkg__", + ], ) # end:github_only diff --git a/upb/base/BUILD b/upb/base/BUILD index 1a025c295da7b..2fce94baf5335 100644 --- a/upb/base/BUILD +++ b/upb/base/BUILD @@ -47,8 +47,8 @@ filegroup( ], ), visibility = [ - "//upb/cmake:__pkg__", "//python/dist:__pkg__", - ] + "//upb/cmake:__pkg__", + ], ) # end:github_only diff --git a/upb/collections/BUILD b/upb/collections/BUILD index 8437cd598ad43..5a900c6c7bae2 100644 --- a/upb/collections/BUILD +++ b/upb/collections/BUILD @@ -29,8 +29,8 @@ filegroup( ], ), visibility = [ - "//upb/cmake:__pkg__", "//python/dist:__pkg__", - ] + "//upb/cmake:__pkg__", + ], ) # end:github_only diff --git a/upb/hash/BUILD b/upb/hash/BUILD index 7ef3bd7e0d7af..b061413e8d14d 100644 --- a/upb/hash/BUILD +++ b/upb/hash/BUILD @@ -32,10 +32,11 @@ cc_test( srcs = ["test.cc"], deps = [ ":hash", - "@com_google_googletest//:gtest_main", "//upb:mem", "//upb:port", "@com_google_absl//absl/container:flat_hash_map", + "@com_google_googletest//:gtest", + "@com_google_googletest//:gtest_main", ], ) @@ -49,9 +50,9 @@ filegroup( ], ), visibility = [ - "//upb/cmake:__pkg__", "//python/dist:__pkg__", - ] + "//upb/cmake:__pkg__", + ], ) # end:github_only diff --git a/upb/io/BUILD b/upb/io/BUILD index 31648646baf5f..490096a153f2b 100644 --- a/upb/io/BUILD +++ b/upb/io/BUILD @@ -64,8 +64,9 @@ cc_test( srcs = ["string_test.cc"], deps = [ ":string", - "@com_google_googletest//:gtest_main", "//upb:mem", + "@com_google_googletest//:gtest", + "@com_google_googletest//:gtest_main", ], ) @@ -78,12 +79,13 @@ cc_test( ":string", ":tokenizer", ":zero_copy_stream", - "@com_google_googletest//:gtest_main", - "@com_google_absl//absl/strings", - "@com_google_absl//absl/strings:str_format", "//upb:lex", "//upb:mem", "//upb:port", + "@com_google_absl//absl/strings", + "@com_google_absl//absl/strings:str_format", + "@com_google_googletest//:gtest", + "@com_google_googletest//:gtest_main", ], ) @@ -96,8 +98,9 @@ cc_test( deps = [ ":chunked_stream", ":zero_copy_stream", - "@com_google_googletest//:gtest_main", "//upb:base", "//upb:mem", + "@com_google_googletest//:gtest", + "@com_google_googletest//:gtest_main", ], ) diff --git a/upb/json/BUILD b/upb/json/BUILD index b04c4fdb322e9..6331725465b1a 100644 --- a/upb/json/BUILD +++ b/upb/json/BUILD @@ -40,10 +40,11 @@ cc_test( ":struct_upb_proto", ":test_upb_proto", ":test_upb_proto_reflection", - "@com_google_googletest//:gtest_main", "//upb:base", "//upb:mem", "//upb:reflection", + "@com_google_googletest//:gtest", + "@com_google_googletest//:gtest_main", ], ) @@ -55,10 +56,11 @@ cc_test( ":struct_upb_proto", ":test_upb_proto", ":test_upb_proto_reflection", - "@com_google_googletest//:gtest_main", "//upb:base", "//upb:mem", "//upb:reflection", + "@com_google_googletest//:gtest", + "@com_google_googletest//:gtest_main", ], ) @@ -96,7 +98,7 @@ upb_c_proto_library( # ":json", # ":test_upb_proto", # ":test_upb_proto_reflection", -# "@com_google_googletest//:gtest_main", +# "@com_google_googletest//:gtest", "@com_google_googletest//:gtest_main", # "//testing/fuzzing:fuzztest", # "//upb:base", # "//upb:mem", @@ -118,6 +120,7 @@ filegroup( ), visibility = ["//pkg:__pkg__"], ) + filegroup( name = "test_utils", srcs = glob( diff --git a/upb/lex/BUILD b/upb/lex/BUILD index 2dbf258e74bae..81c6c898a251a 100644 --- a/upb/lex/BUILD +++ b/upb/lex/BUILD @@ -31,8 +31,9 @@ cc_test( srcs = ["atoi_test.cc"], deps = [ ":lex", - "@com_google_googletest//:gtest_main", "@com_google_absl//absl/strings", + "@com_google_googletest//:gtest", + "@com_google_googletest//:gtest_main", ], ) @@ -46,9 +47,9 @@ filegroup( ], ), visibility = [ - "//upb/cmake:__pkg__", "//python/dist:__pkg__", - ] + "//upb/cmake:__pkg__", + ], ) # end:github_only diff --git a/upb/mem/BUILD b/upb/mem/BUILD index a26b92eca5b3a..9227a3194e88b 100644 --- a/upb/mem/BUILD +++ b/upb/mem/BUILD @@ -43,12 +43,13 @@ cc_test( srcs = ["arena_test.cc"], deps = [ ":mem", - "@com_google_googletest//:gtest_main", "//upb:port", "@com_google_absl//absl/random", "@com_google_absl//absl/random:distributions", "@com_google_absl//absl/synchronization", "@com_google_absl//absl/time", + "@com_google_googletest//:gtest", + "@com_google_googletest//:gtest_main", ], ) @@ -63,9 +64,9 @@ filegroup( ], ), visibility = [ - "//upb/cmake:__pkg__", "//python/dist:__pkg__", - ] + "//upb/cmake:__pkg__", + ], ) # end:github_only diff --git a/upb/message/BUILD b/upb/message/BUILD index 76eb94c3debb3..969b2ecaca84f 100644 --- a/upb/message/BUILD +++ b/upb/message/BUILD @@ -228,7 +228,6 @@ cc_test( ":accessors", ":message", "//:protobuf", - "@com_google_googletest//:gtest_main", "//upb:base", "//upb:mem", "//upb:mini_descriptor", @@ -242,6 +241,8 @@ cc_test( "//upb/test:test_messages_proto3_upb_proto", "//upb/test:test_upb_proto", "@com_google_absl//absl/container:flat_hash_set", + "@com_google_googletest//:gtest", + "@com_google_googletest//:gtest_main", ], ) @@ -250,9 +251,10 @@ cc_test( srcs = ["array_test.cc"], deps = [ ":message", - "@com_google_googletest//:gtest_main", "//upb:base", "//upb:mem", + "@com_google_googletest//:gtest", + "@com_google_googletest//:gtest_main", ], ) @@ -264,7 +266,6 @@ cc_test( ":copy", ":message", "//:protobuf", - "@com_google_googletest//:gtest_main", "//upb:base", "//upb:mem", "//upb:mini_table", @@ -274,6 +275,8 @@ cc_test( "//upb/test:test_messages_proto2_upb_proto", "//upb/test:test_upb_proto", "@com_google_absl//absl/container:flat_hash_set", + "@com_google_googletest//:gtest", + "@com_google_googletest//:gtest_main", ], ) @@ -282,9 +285,10 @@ cc_test( srcs = ["map_test.cc"], deps = [ ":message", - "@com_google_googletest//:gtest_main", "//upb:base", "//upb:mem", + "@com_google_googletest//:gtest", + "@com_google_googletest//:gtest_main", ], ) @@ -298,7 +302,6 @@ cc_test( ":promote", ":tagged_ptr", "//:protobuf", - "@com_google_googletest//:gtest_main", "//upb:base", "//upb:mem", "//upb:mini_descriptor", @@ -310,6 +313,8 @@ cc_test( "//upb/test:test_proto_upb_minitable", "//upb/test:test_upb_proto", "@com_google_absl//absl/container:flat_hash_set", + "@com_google_googletest//:gtest", + "@com_google_googletest//:gtest_main", ], ) @@ -323,7 +328,6 @@ cc_test( ":message_test_upb_proto", ":message_test_upb_proto_reflection", ":value", - "@com_google_googletest//:gtest_main", "//upb:base", "//upb:json", "//upb:mem", @@ -333,6 +337,8 @@ cc_test( "//upb:wire", "//upb/test:fuzz_util", "//upb/test:test_messages_proto3_upb_proto", + "@com_google_googletest//:gtest", + "@com_google_googletest//:gtest_main", ], ) @@ -361,10 +367,11 @@ cc_test( deps = [ ":utf8_test_upb_minitable_proto", ":utf8_test_upb_proto", - "@com_google_googletest//:gtest_main", "//upb:base", "//upb:mem", "//upb:wire", + "@com_google_googletest//:gtest", + "@com_google_googletest//:gtest_main", ], ) @@ -378,9 +385,9 @@ filegroup( ], ), visibility = [ - "//upb/cmake:__pkg__", "//python/dist:__pkg__", - ] + "//upb/cmake:__pkg__", + ], ) # end:github_only @@ -394,6 +401,7 @@ filegroup( ), visibility = ["//pkg:__pkg__"], ) + filegroup( name = "test_utils", srcs = glob( diff --git a/upb/mini_descriptor/BUILD b/upb/mini_descriptor/BUILD index 1857b9c338e3f..b1932ead9872a 100644 --- a/upb/mini_descriptor/BUILD +++ b/upb/mini_descriptor/BUILD @@ -60,7 +60,6 @@ cc_test( ":internal", ":mini_descriptor", "//:protobuf", - "@com_google_googletest//:gtest_main", "//upb:base", "//upb:mem", "//upb:message_accessors", @@ -68,6 +67,8 @@ cc_test( "//upb:port", "//upb:wire", "@com_google_absl//absl/container:flat_hash_set", + "@com_google_googletest//:gtest", + "@com_google_googletest//:gtest_main", ], ) @@ -81,9 +82,9 @@ filegroup( ], ), visibility = [ - "//upb/cmake:__pkg__", "//python/dist:__pkg__", - ] + "//upb/cmake:__pkg__", + ], ) # end:github_only diff --git a/upb/mini_table/BUILD b/upb/mini_table/BUILD index 71de9f2b5da82..221e87be83002 100644 --- a/upb/mini_table/BUILD +++ b/upb/mini_table/BUILD @@ -82,11 +82,12 @@ cc_test( name = "compat_test", srcs = ["compat_test.cc"], deps = [ - "@com_google_googletest//:gtest_main", "//upb:mini_table_compat", "//upb/test:test_messages_proto2_upb_minitable", "//upb/test:test_messages_proto3_upb_minitable", "//upb/test:test_upb_proto", + "@com_google_googletest//:gtest", + "@com_google_googletest//:gtest_main", ], ) @@ -100,9 +101,9 @@ filegroup( ], ), visibility = [ - "//upb/cmake:__pkg__", "//python/dist:__pkg__", - ] + "//upb/cmake:__pkg__", + ], ) # end:github_only diff --git a/upb/port/BUILD b/upb/port/BUILD index fe20c085e5cd4..db3a91f549ecf 100644 --- a/upb/port/BUILD +++ b/upb/port/BUILD @@ -45,8 +45,8 @@ filegroup( ], ), visibility = [ - "//upb/cmake:__pkg__", "//python/dist:__pkg__", - ] + "//upb/cmake:__pkg__", + ], ) # end:github_only diff --git a/upb/reflection/BUILD b/upb/reflection/BUILD index 5854704bf6d09..e42ebda23b43c 100644 --- a/upb/reflection/BUILD +++ b/upb/reflection/BUILD @@ -176,7 +176,6 @@ cc_test( ], deps = [ ":descriptor_upb_proto", - "@com_google_googletest//:gtest_main", "//upb:base", "//upb:hash", "//upb:mem", @@ -184,6 +183,8 @@ cc_test( "//upb:reflection", "//upb:reflection_internal", "@com_google_absl//absl/strings", + "@com_google_googletest//:gtest", + "@com_google_googletest//:gtest_main", ], ) @@ -223,8 +224,8 @@ filegroup( exclude = ["stage0/**"], ), visibility = [ - "//upb/cmake:__pkg__", "//python/dist:__pkg__", - ] + "//upb/cmake:__pkg__", + ], ) # end:github_only diff --git a/upb/test/BUILD b/upb/test/BUILD index 186dacd37c4ce..493a51eb11878 100644 --- a/upb/test/BUILD +++ b/upb/test/BUILD @@ -179,8 +179,9 @@ cc_test( deps = [ ":proto3_test_upb_proto", ":proto3_test_upb_proto_reflection", - "@com_google_googletest//:gtest_main", "//upb:reflection", + "@com_google_googletest//:gtest", + "@com_google_googletest//:gtest_main", ], ) @@ -191,10 +192,11 @@ cc_test( deps = [ ":editions_test_upb_c_proto", ":editions_test_upb_proto_reflection", - "@com_google_googletest//:gtest_main", "//upb:base", "//upb:mem", "//upb:reflection", + "@com_google_googletest//:gtest", + "@com_google_googletest//:gtest_main", ], ) @@ -207,11 +209,12 @@ cc_test( ":test_cpp_upb_proto_reflection", ":timestamp_upb_proto", ":timestamp_upb_proto_reflection", - "@com_google_googletest//:gtest_main", "//upb:base", "//upb:json", "//upb:port", "//upb:reflection", + "@com_google_googletest//:gtest", + "@com_google_googletest//:gtest_main", ], ) @@ -225,11 +228,12 @@ cc_test( ":test_messages_proto2_upb_proto", ":test_messages_proto3_upb_proto", ":test_upb_proto", - "@com_google_googletest//:gtest_main", "//upb:base", "//upb:mem", "//upb:message", "//upb:port", + "@com_google_googletest//:gtest", + "@com_google_googletest//:gtest_main", ], ) @@ -243,8 +247,9 @@ cc_test( ":proto3_test_upb_proto", ":test_messages_proto2_upb_minitable", ":test_upb_proto", - "@com_google_googletest//:gtest_main", "//upb:mini_table", + "@com_google_googletest//:gtest", + "@com_google_googletest//:gtest_main", ], ) @@ -296,6 +301,7 @@ cc_test( srcs = ["test_import_empty_srcs.cc"], deps = [ ":test_import_empty_srcs_upb_minitable_proto", + "@com_google_googletest//:gtest", "@com_google_googletest//:gtest_main", ], ) @@ -311,6 +317,7 @@ filegroup( ), visibility = ["//pkg:__pkg__"], ) + filegroup( name = "test_utils", srcs = glob( diff --git a/upb/text/BUILD b/upb/text/BUILD index 7bc0953946e9f..6a1a97c6eb17b 100644 --- a/upb/text/BUILD +++ b/upb/text/BUILD @@ -38,8 +38,8 @@ filegroup( ], ), visibility = [ - "//upb/cmake:__pkg__", "//python/dist:__pkg__", - ] + "//upb/cmake:__pkg__", + ], ) # end:github_only diff --git a/upb/util/BUILD b/upb/util/BUILD index e299780ec5996..e43b23959c530 100644 --- a/upb/util/BUILD +++ b/upb/util/BUILD @@ -67,12 +67,13 @@ cc_test( ":def_to_proto_test_upb_proto", ":def_to_proto_test_upb_proto_reflection", "//:protobuf", - "@com_google_googletest//:gtest_main", "//upb:descriptor_upb_proto_reflection", "//upb:mem", "//upb:reflection", "//upb/test:parse_text_proto", "@com_google_absl//absl/strings", + "@com_google_googletest//:gtest", + "@com_google_googletest//:gtest_main", ], ) @@ -83,7 +84,7 @@ cc_test( # tags = ["clang_only"], # deps = [ # ":def_to_proto_test_lib", -# "@com_google_googletest//:gtest_main", +# "@com_google_googletest//:gtest", "@com_google_googletest//:gtest_main", # "//testing/fuzzing:fuzztest", # ], # ) @@ -130,13 +131,14 @@ cc_test( ":required_fields", ":required_fields_test_upb_proto", ":required_fields_test_upb_proto_reflection", - "@com_google_googletest//:gtest_main", "//upb:base", "//upb:json", "//upb:mem", "//upb:reflection", "//upb:reflection_internal", "@com_google_absl//absl/strings", + "@com_google_googletest//:gtest", + "@com_google_googletest//:gtest_main", ], ) @@ -161,10 +163,11 @@ cc_test( srcs = ["compare_test.cc"], deps = [ ":compare", - "@com_google_googletest//:gtest_main", "//upb:port", "//upb:wire_reader", "@com_google_absl//absl/strings", + "@com_google_googletest//:gtest", + "@com_google_googletest//:gtest_main", ], ) @@ -193,6 +196,7 @@ filegroup( ), visibility = ["//pkg:__pkg__"], ) + filegroup( name = "test_utils", srcs = glob( diff --git a/upb/wire/BUILD b/upb/wire/BUILD index 5130a711cd478..56b8927cf5c61 100644 --- a/upb/wire/BUILD +++ b/upb/wire/BUILD @@ -26,6 +26,7 @@ cc_library( deps = [ ":eps_copy_input_stream", ":reader", + "//third_party/utf8_range", "//upb:base", "//upb:hash", "//upb:mem", @@ -37,7 +38,6 @@ cc_library( "//upb:port", "//upb/mem:internal", "//upb/mini_table:internal", - "//third_party/utf8_range", ], ) @@ -75,8 +75,9 @@ cc_test( srcs = ["eps_copy_input_stream_test.cc"], deps = [ ":eps_copy_input_stream", - "@com_google_googletest//:gtest_main", "//upb:mem", + "@com_google_googletest//:gtest", + "@com_google_googletest//:gtest_main", ], ) @@ -90,9 +91,9 @@ filegroup( ], ), visibility = [ - "//upb/cmake:__pkg__", "//python/dist:__pkg__", - ] + "//upb/cmake:__pkg__", + ], ) # end:github_only From c16ac66e8581b55471eff9860b02e3d32cae7a79 Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Thu, 28 Dec 2023 15:09:06 -0800 Subject: [PATCH 132/255] Fixed non-conformance in upb JSON enum decoding when ignoring unknown enum values. PiperOrigin-RevId: 594322509 --- conformance/failure_list_jruby_ffi.txt | 2 - conformance/failure_list_php_c.txt | 2 - conformance/failure_list_ruby.txt | 2 - upb/conformance/conformance_upb_failures.txt | 4 -- upb/json/decode.c | 60 +++++++++++++------- 5 files changed, 41 insertions(+), 29 deletions(-) diff --git a/conformance/failure_list_jruby_ffi.txt b/conformance/failure_list_jruby_ffi.txt index 6a487cb293a91..e69de29bb2d1d 100644 --- a/conformance/failure_list_jruby_ffi.txt +++ b/conformance/failure_list_jruby_ffi.txt @@ -1,2 +0,0 @@ -Recommended.Proto3.JsonInput.IgnoreUnknownEnumStringValueInMapValue.ProtobufOutput -Recommended.Proto3.JsonInput.IgnoreUnknownEnumStringValueInRepeatedField.ProtobufOutput \ No newline at end of file diff --git a/conformance/failure_list_php_c.txt b/conformance/failure_list_php_c.txt index 284448652f6fe..63c7e8a024ccf 100644 --- a/conformance/failure_list_php_c.txt +++ b/conformance/failure_list_php_c.txt @@ -1,4 +1,2 @@ Recommended.Proto2.JsonInput.FieldNameExtension.Validator -Recommended.Proto3.JsonInput.IgnoreUnknownEnumStringValueInMapValue.ProtobufOutput -Recommended.Proto3.JsonInput.IgnoreUnknownEnumStringValueInRepeatedField.ProtobufOutput Required.Proto2.JsonInput.StoresDefaultPrimitive.Validator diff --git a/conformance/failure_list_ruby.txt b/conformance/failure_list_ruby.txt index 2fb4dc881f168..e69de29bb2d1d 100644 --- a/conformance/failure_list_ruby.txt +++ b/conformance/failure_list_ruby.txt @@ -1,2 +0,0 @@ -Recommended.Proto3.JsonInput.IgnoreUnknownEnumStringValueInMapValue.ProtobufOutput -Recommended.Proto3.JsonInput.IgnoreUnknownEnumStringValueInRepeatedField.ProtobufOutput diff --git a/upb/conformance/conformance_upb_failures.txt b/upb/conformance/conformance_upb_failures.txt index 9b78753bdc307..e69de29bb2d1d 100644 --- a/upb/conformance/conformance_upb_failures.txt +++ b/upb/conformance/conformance_upb_failures.txt @@ -1,4 +0,0 @@ -Recommended.Proto3.JsonInput.IgnoreUnknownEnumStringValueInMapValue.ProtobufOutput -Recommended.Proto3.JsonInput.IgnoreUnknownEnumStringValueInRepeatedField.ProtobufOutput -Recommended.Editions_Proto3.JsonInput.IgnoreUnknownEnumStringValueInMapValue.ProtobufOutput -Recommended.Editions_Proto3.JsonInput.IgnoreUnknownEnumStringValueInRepeatedField.ProtobufOutput diff --git a/upb/json/decode.c b/upb/json/decode.c index 89e5bd60793e6..531e937456dcf 100644 --- a/upb/json/decode.c +++ b/upb/json/decode.c @@ -51,12 +51,17 @@ typedef struct { const upb_FieldDef* debug_field; } jsondec; +typedef struct { + upb_MessageValue value; + bool ignore; +} upb_JsonMessageValue; + enum { JD_OBJECT, JD_ARRAY, JD_STRING, JD_NUMBER, JD_TRUE, JD_FALSE, JD_NULL }; /* Forward declarations of mutually-recursive functions. */ static void jsondec_wellknown(jsondec* d, upb_Message* msg, const upb_MessageDef* m); -static upb_MessageValue jsondec_value(jsondec* d, const upb_FieldDef* f); +static upb_JsonMessageValue jsondec_value(jsondec* d, const upb_FieldDef* f); static void jsondec_wellknownvalue(jsondec* d, upb_Message* msg, const upb_MessageDef* m); static void jsondec_object(jsondec* d, upb_Message* msg, @@ -787,19 +792,19 @@ static upb_MessageValue jsondec_strfield(jsondec* d, const upb_FieldDef* f) { return val; } -static upb_MessageValue jsondec_enum(jsondec* d, const upb_FieldDef* f) { +static upb_JsonMessageValue jsondec_enum(jsondec* d, const upb_FieldDef* f) { switch (jsondec_peek(d)) { case JD_STRING: { upb_StringView str = jsondec_string(d); const upb_EnumDef* e = upb_FieldDef_EnumSubDef(f); const upb_EnumValueDef* ev = upb_EnumDef_FindValueByNameWithSize(e, str.data, str.size); - upb_MessageValue val; + upb_JsonMessageValue val = {.ignore = false}; if (ev) { - val.int32_val = upb_EnumValueDef_Number(ev); + val.value.int32_val = upb_EnumValueDef_Number(ev); } else { if (d->options & upb_JsonDecode_IgnoreUnknown) { - val.int32_val = 0; + val.ignore = true; } else { jsondec_errf(d, "Unknown enumerator: '" UPB_STRINGVIEW_FORMAT "'", UPB_STRINGVIEW_ARGS(str)); @@ -809,15 +814,16 @@ static upb_MessageValue jsondec_enum(jsondec* d, const upb_FieldDef* f) { } case JD_NULL: { if (jsondec_isnullvalue(f)) { - upb_MessageValue val; + upb_JsonMessageValue val = {.ignore = false}; jsondec_null(d); - val.int32_val = 0; + val.value.int32_val = 0; return val; } } /* Fallthrough. */ default: - return jsondec_int(d, f); + return (upb_JsonMessageValue){.value = jsondec_int(d, f), + .ignore = false}; } } @@ -860,8 +866,10 @@ static void jsondec_array(jsondec* d, upb_Message* msg, const upb_FieldDef* f) { jsondec_arrstart(d); while (jsondec_arrnext(d)) { - upb_MessageValue elem = jsondec_value(d, f); - upb_Array_Append(arr, elem, d->arena); + upb_JsonMessageValue elem = jsondec_value(d, f); + if (!elem.ignore) { + upb_Array_Append(arr, elem.value, d->arena); + } } jsondec_arrend(d); } @@ -874,11 +882,14 @@ static void jsondec_map(jsondec* d, upb_Message* msg, const upb_FieldDef* f) { jsondec_objstart(d); while (jsondec_objnext(d)) { - upb_MessageValue key, val; + upb_JsonMessageValue key, val; key = jsondec_value(d, key_f); + UPB_ASSUME(!key.ignore); // Map key cannot be enum. jsondec_entrysep(d); val = jsondec_value(d, val_f); - upb_Map_Set(map, key, val, d->arena); + if (!val.ignore) { + upb_Map_Set(map, key.value, val.value, d->arena); + } } jsondec_objend(d); } @@ -959,8 +970,10 @@ static void jsondec_field(jsondec* d, upb_Message* msg, const upb_MessageDef* subm = upb_FieldDef_MessageSubDef(f); jsondec_tomsg(d, submsg, subm); } else { - upb_MessageValue val = jsondec_value(d, f); - upb_Message_SetFieldByDef(msg, f, val, d->arena); + upb_JsonMessageValue val = jsondec_value(d, f); + if (!val.ignore) { + upb_Message_SetFieldByDef(msg, f, val.value, d->arena); + } } d->debug_field = preserved; @@ -975,7 +988,7 @@ static void jsondec_object(jsondec* d, upb_Message* msg, jsondec_objend(d); } -static upb_MessageValue jsondec_value(jsondec* d, const upb_FieldDef* f) { +static upb_MessageValue jsondec_nonenum(jsondec* d, const upb_FieldDef* f) { switch (upb_FieldDef_CType(f)) { case kUpb_CType_Bool: return jsondec_bool(d, f); @@ -991,15 +1004,23 @@ static upb_MessageValue jsondec_value(jsondec* d, const upb_FieldDef* f) { case kUpb_CType_String: case kUpb_CType_Bytes: return jsondec_strfield(d, f); - case kUpb_CType_Enum: - return jsondec_enum(d, f); case kUpb_CType_Message: return jsondec_msg(d, f); + case kUpb_CType_Enum: default: UPB_UNREACHABLE(); } } +static upb_JsonMessageValue jsondec_value(jsondec* d, const upb_FieldDef* f) { + if (upb_FieldDef_CType(f) == kUpb_CType_Enum) { + return jsondec_enum(d, f); + } else { + return (upb_JsonMessageValue){.value = jsondec_nonenum(d, f), + .ignore = false}; + } +} + /* Well-known types ***********************************************************/ static int jsondec_tsdigits(jsondec* d, const char** ptr, size_t digits, @@ -1424,8 +1445,9 @@ static void jsondec_any(jsondec* d, upb_Message* msg, const upb_MessageDef* m) { static void jsondec_wrapper(jsondec* d, upb_Message* msg, const upb_MessageDef* m) { const upb_FieldDef* value_f = upb_MessageDef_FindFieldByNumber(m, 1); - upb_MessageValue val = jsondec_value(d, value_f); - upb_Message_SetFieldByDef(msg, value_f, val, d->arena); + upb_JsonMessageValue val = jsondec_value(d, value_f); + UPB_ASSUME(val.ignore == false); // Wrapper cannot be an enum. + upb_Message_SetFieldByDef(msg, value_f, val.value, d->arena); } static void jsondec_wellknown(jsondec* d, upb_Message* msg, From 1597bf4971c4685743b9f68f170392bde2f5c3f3 Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Thu, 28 Dec 2023 23:23:14 +0000 Subject: [PATCH 133/255] Auto-generate files after cl/594322509 --- php/ext/google/protobuf/php-upb.c | 60 ++++++++++++++++++--------- ruby/ext/google/protobuf_c/ruby-upb.c | 60 ++++++++++++++++++--------- 2 files changed, 82 insertions(+), 38 deletions(-) diff --git a/php/ext/google/protobuf/php-upb.c b/php/ext/google/protobuf/php-upb.c index fb226ca3c7a08..e02c084a12bba 100644 --- a/php/ext/google/protobuf/php-upb.c +++ b/php/ext/google/protobuf/php-upb.c @@ -3100,12 +3100,17 @@ typedef struct { const upb_FieldDef* debug_field; } jsondec; +typedef struct { + upb_MessageValue value; + bool ignore; +} upb_JsonMessageValue; + enum { JD_OBJECT, JD_ARRAY, JD_STRING, JD_NUMBER, JD_TRUE, JD_FALSE, JD_NULL }; /* Forward declarations of mutually-recursive functions. */ static void jsondec_wellknown(jsondec* d, upb_Message* msg, const upb_MessageDef* m); -static upb_MessageValue jsondec_value(jsondec* d, const upb_FieldDef* f); +static upb_JsonMessageValue jsondec_value(jsondec* d, const upb_FieldDef* f); static void jsondec_wellknownvalue(jsondec* d, upb_Message* msg, const upb_MessageDef* m); static void jsondec_object(jsondec* d, upb_Message* msg, @@ -3836,19 +3841,19 @@ static upb_MessageValue jsondec_strfield(jsondec* d, const upb_FieldDef* f) { return val; } -static upb_MessageValue jsondec_enum(jsondec* d, const upb_FieldDef* f) { +static upb_JsonMessageValue jsondec_enum(jsondec* d, const upb_FieldDef* f) { switch (jsondec_peek(d)) { case JD_STRING: { upb_StringView str = jsondec_string(d); const upb_EnumDef* e = upb_FieldDef_EnumSubDef(f); const upb_EnumValueDef* ev = upb_EnumDef_FindValueByNameWithSize(e, str.data, str.size); - upb_MessageValue val; + upb_JsonMessageValue val = {.ignore = false}; if (ev) { - val.int32_val = upb_EnumValueDef_Number(ev); + val.value.int32_val = upb_EnumValueDef_Number(ev); } else { if (d->options & upb_JsonDecode_IgnoreUnknown) { - val.int32_val = 0; + val.ignore = true; } else { jsondec_errf(d, "Unknown enumerator: '" UPB_STRINGVIEW_FORMAT "'", UPB_STRINGVIEW_ARGS(str)); @@ -3858,15 +3863,16 @@ static upb_MessageValue jsondec_enum(jsondec* d, const upb_FieldDef* f) { } case JD_NULL: { if (jsondec_isnullvalue(f)) { - upb_MessageValue val; + upb_JsonMessageValue val = {.ignore = false}; jsondec_null(d); - val.int32_val = 0; + val.value.int32_val = 0; return val; } } /* Fallthrough. */ default: - return jsondec_int(d, f); + return (upb_JsonMessageValue){.value = jsondec_int(d, f), + .ignore = false}; } } @@ -3909,8 +3915,10 @@ static void jsondec_array(jsondec* d, upb_Message* msg, const upb_FieldDef* f) { jsondec_arrstart(d); while (jsondec_arrnext(d)) { - upb_MessageValue elem = jsondec_value(d, f); - upb_Array_Append(arr, elem, d->arena); + upb_JsonMessageValue elem = jsondec_value(d, f); + if (!elem.ignore) { + upb_Array_Append(arr, elem.value, d->arena); + } } jsondec_arrend(d); } @@ -3923,11 +3931,14 @@ static void jsondec_map(jsondec* d, upb_Message* msg, const upb_FieldDef* f) { jsondec_objstart(d); while (jsondec_objnext(d)) { - upb_MessageValue key, val; + upb_JsonMessageValue key, val; key = jsondec_value(d, key_f); + UPB_ASSUME(!key.ignore); // Map key cannot be enum. jsondec_entrysep(d); val = jsondec_value(d, val_f); - upb_Map_Set(map, key, val, d->arena); + if (!val.ignore) { + upb_Map_Set(map, key.value, val.value, d->arena); + } } jsondec_objend(d); } @@ -4008,8 +4019,10 @@ static void jsondec_field(jsondec* d, upb_Message* msg, const upb_MessageDef* subm = upb_FieldDef_MessageSubDef(f); jsondec_tomsg(d, submsg, subm); } else { - upb_MessageValue val = jsondec_value(d, f); - upb_Message_SetFieldByDef(msg, f, val, d->arena); + upb_JsonMessageValue val = jsondec_value(d, f); + if (!val.ignore) { + upb_Message_SetFieldByDef(msg, f, val.value, d->arena); + } } d->debug_field = preserved; @@ -4024,7 +4037,7 @@ static void jsondec_object(jsondec* d, upb_Message* msg, jsondec_objend(d); } -static upb_MessageValue jsondec_value(jsondec* d, const upb_FieldDef* f) { +static upb_MessageValue jsondec_nonenum(jsondec* d, const upb_FieldDef* f) { switch (upb_FieldDef_CType(f)) { case kUpb_CType_Bool: return jsondec_bool(d, f); @@ -4040,15 +4053,23 @@ static upb_MessageValue jsondec_value(jsondec* d, const upb_FieldDef* f) { case kUpb_CType_String: case kUpb_CType_Bytes: return jsondec_strfield(d, f); - case kUpb_CType_Enum: - return jsondec_enum(d, f); case kUpb_CType_Message: return jsondec_msg(d, f); + case kUpb_CType_Enum: default: UPB_UNREACHABLE(); } } +static upb_JsonMessageValue jsondec_value(jsondec* d, const upb_FieldDef* f) { + if (upb_FieldDef_CType(f) == kUpb_CType_Enum) { + return jsondec_enum(d, f); + } else { + return (upb_JsonMessageValue){.value = jsondec_nonenum(d, f), + .ignore = false}; + } +} + /* Well-known types ***********************************************************/ static int jsondec_tsdigits(jsondec* d, const char** ptr, size_t digits, @@ -4473,8 +4494,9 @@ static void jsondec_any(jsondec* d, upb_Message* msg, const upb_MessageDef* m) { static void jsondec_wrapper(jsondec* d, upb_Message* msg, const upb_MessageDef* m) { const upb_FieldDef* value_f = upb_MessageDef_FindFieldByNumber(m, 1); - upb_MessageValue val = jsondec_value(d, value_f); - upb_Message_SetFieldByDef(msg, value_f, val, d->arena); + upb_JsonMessageValue val = jsondec_value(d, value_f); + UPB_ASSUME(val.ignore == false); // Wrapper cannot be an enum. + upb_Message_SetFieldByDef(msg, value_f, val.value, d->arena); } static void jsondec_wellknown(jsondec* d, upb_Message* msg, diff --git a/ruby/ext/google/protobuf_c/ruby-upb.c b/ruby/ext/google/protobuf_c/ruby-upb.c index eac3e83cee603..d2ea1895bc53f 100644 --- a/ruby/ext/google/protobuf_c/ruby-upb.c +++ b/ruby/ext/google/protobuf_c/ruby-upb.c @@ -2616,12 +2616,17 @@ typedef struct { const upb_FieldDef* debug_field; } jsondec; +typedef struct { + upb_MessageValue value; + bool ignore; +} upb_JsonMessageValue; + enum { JD_OBJECT, JD_ARRAY, JD_STRING, JD_NUMBER, JD_TRUE, JD_FALSE, JD_NULL }; /* Forward declarations of mutually-recursive functions. */ static void jsondec_wellknown(jsondec* d, upb_Message* msg, const upb_MessageDef* m); -static upb_MessageValue jsondec_value(jsondec* d, const upb_FieldDef* f); +static upb_JsonMessageValue jsondec_value(jsondec* d, const upb_FieldDef* f); static void jsondec_wellknownvalue(jsondec* d, upb_Message* msg, const upb_MessageDef* m); static void jsondec_object(jsondec* d, upb_Message* msg, @@ -3352,19 +3357,19 @@ static upb_MessageValue jsondec_strfield(jsondec* d, const upb_FieldDef* f) { return val; } -static upb_MessageValue jsondec_enum(jsondec* d, const upb_FieldDef* f) { +static upb_JsonMessageValue jsondec_enum(jsondec* d, const upb_FieldDef* f) { switch (jsondec_peek(d)) { case JD_STRING: { upb_StringView str = jsondec_string(d); const upb_EnumDef* e = upb_FieldDef_EnumSubDef(f); const upb_EnumValueDef* ev = upb_EnumDef_FindValueByNameWithSize(e, str.data, str.size); - upb_MessageValue val; + upb_JsonMessageValue val = {.ignore = false}; if (ev) { - val.int32_val = upb_EnumValueDef_Number(ev); + val.value.int32_val = upb_EnumValueDef_Number(ev); } else { if (d->options & upb_JsonDecode_IgnoreUnknown) { - val.int32_val = 0; + val.ignore = true; } else { jsondec_errf(d, "Unknown enumerator: '" UPB_STRINGVIEW_FORMAT "'", UPB_STRINGVIEW_ARGS(str)); @@ -3374,15 +3379,16 @@ static upb_MessageValue jsondec_enum(jsondec* d, const upb_FieldDef* f) { } case JD_NULL: { if (jsondec_isnullvalue(f)) { - upb_MessageValue val; + upb_JsonMessageValue val = {.ignore = false}; jsondec_null(d); - val.int32_val = 0; + val.value.int32_val = 0; return val; } } /* Fallthrough. */ default: - return jsondec_int(d, f); + return (upb_JsonMessageValue){.value = jsondec_int(d, f), + .ignore = false}; } } @@ -3425,8 +3431,10 @@ static void jsondec_array(jsondec* d, upb_Message* msg, const upb_FieldDef* f) { jsondec_arrstart(d); while (jsondec_arrnext(d)) { - upb_MessageValue elem = jsondec_value(d, f); - upb_Array_Append(arr, elem, d->arena); + upb_JsonMessageValue elem = jsondec_value(d, f); + if (!elem.ignore) { + upb_Array_Append(arr, elem.value, d->arena); + } } jsondec_arrend(d); } @@ -3439,11 +3447,14 @@ static void jsondec_map(jsondec* d, upb_Message* msg, const upb_FieldDef* f) { jsondec_objstart(d); while (jsondec_objnext(d)) { - upb_MessageValue key, val; + upb_JsonMessageValue key, val; key = jsondec_value(d, key_f); + UPB_ASSUME(!key.ignore); // Map key cannot be enum. jsondec_entrysep(d); val = jsondec_value(d, val_f); - upb_Map_Set(map, key, val, d->arena); + if (!val.ignore) { + upb_Map_Set(map, key.value, val.value, d->arena); + } } jsondec_objend(d); } @@ -3524,8 +3535,10 @@ static void jsondec_field(jsondec* d, upb_Message* msg, const upb_MessageDef* subm = upb_FieldDef_MessageSubDef(f); jsondec_tomsg(d, submsg, subm); } else { - upb_MessageValue val = jsondec_value(d, f); - upb_Message_SetFieldByDef(msg, f, val, d->arena); + upb_JsonMessageValue val = jsondec_value(d, f); + if (!val.ignore) { + upb_Message_SetFieldByDef(msg, f, val.value, d->arena); + } } d->debug_field = preserved; @@ -3540,7 +3553,7 @@ static void jsondec_object(jsondec* d, upb_Message* msg, jsondec_objend(d); } -static upb_MessageValue jsondec_value(jsondec* d, const upb_FieldDef* f) { +static upb_MessageValue jsondec_nonenum(jsondec* d, const upb_FieldDef* f) { switch (upb_FieldDef_CType(f)) { case kUpb_CType_Bool: return jsondec_bool(d, f); @@ -3556,15 +3569,23 @@ static upb_MessageValue jsondec_value(jsondec* d, const upb_FieldDef* f) { case kUpb_CType_String: case kUpb_CType_Bytes: return jsondec_strfield(d, f); - case kUpb_CType_Enum: - return jsondec_enum(d, f); case kUpb_CType_Message: return jsondec_msg(d, f); + case kUpb_CType_Enum: default: UPB_UNREACHABLE(); } } +static upb_JsonMessageValue jsondec_value(jsondec* d, const upb_FieldDef* f) { + if (upb_FieldDef_CType(f) == kUpb_CType_Enum) { + return jsondec_enum(d, f); + } else { + return (upb_JsonMessageValue){.value = jsondec_nonenum(d, f), + .ignore = false}; + } +} + /* Well-known types ***********************************************************/ static int jsondec_tsdigits(jsondec* d, const char** ptr, size_t digits, @@ -3989,8 +4010,9 @@ static void jsondec_any(jsondec* d, upb_Message* msg, const upb_MessageDef* m) { static void jsondec_wrapper(jsondec* d, upb_Message* msg, const upb_MessageDef* m) { const upb_FieldDef* value_f = upb_MessageDef_FindFieldByNumber(m, 1); - upb_MessageValue val = jsondec_value(d, value_f); - upb_Message_SetFieldByDef(msg, value_f, val, d->arena); + upb_JsonMessageValue val = jsondec_value(d, value_f); + UPB_ASSUME(val.ignore == false); // Wrapper cannot be an enum. + upb_Message_SetFieldByDef(msg, value_f, val.value, d->arena); } static void jsondec_wellknown(jsondec* d, upb_Message* msg, From 1fc0e72416272970f19fa9d6850bb948f29c1afd Mon Sep 17 00:00:00 2001 From: Eric Salo Date: Thu, 28 Dec 2023 17:00:28 -0800 Subject: [PATCH 134/255] upb: make :wire internal headers private PiperOrigin-RevId: 594337191 --- upb/message/promote.c | 3 +-- upb/wire/BUILD | 4 ++-- upb/wire/decode.c | 2 +- upb/wire/internal/decode_fast.c | 2 +- upb/wire/internal/{decode.h => decoder.h} | 6 +++--- 5 files changed, 8 insertions(+), 9 deletions(-) rename upb/wire/internal/{decode.h => decoder.h} (97%) diff --git a/upb/message/promote.c b/upb/message/promote.c index 4801c86247624..593b09f24cccd 100644 --- a/upb/message/promote.c +++ b/upb/message/promote.c @@ -27,7 +27,6 @@ #include "upb/mini_table/sub.h" #include "upb/wire/decode.h" #include "upb/wire/eps_copy_input_stream.h" -#include "upb/wire/internal/constants.h" #include "upb/wire/reader.h" // Must be last. @@ -118,7 +117,7 @@ static upb_FindUnknownRet upb_FindUnknownRet_ParseError(void) { upb_FindUnknownRet upb_Message_FindUnknown(const upb_Message* msg, uint32_t field_number, int depth_limit) { - depth_limit = depth_limit ? depth_limit : kUpb_WireFormat_DefaultDepthLimit; + depth_limit = depth_limit ? depth_limit : 100; size_t size; upb_FindUnknownRet ret; diff --git a/upb/wire/BUILD b/upb/wire/BUILD index 56b8927cf5c61..fdfb223a9e76a 100644 --- a/upb/wire/BUILD +++ b/upb/wire/BUILD @@ -12,13 +12,13 @@ cc_library( srcs = [ "decode.c", "encode.c", + "internal/constants.h", "internal/decode_fast.c", + "internal/decoder.h", ], hdrs = [ "decode.h", "encode.h", - "internal/constants.h", - "internal/decode.h", "internal/decode_fast.h", ], copts = UPB_DEFAULT_COPTS, diff --git a/upb/wire/decode.c b/upb/wire/decode.c index ddc288f1a320d..a0fd7c11b68ed 100644 --- a/upb/wire/decode.c +++ b/upb/wire/decode.c @@ -39,7 +39,7 @@ #include "upb/wire/encode.h" #include "upb/wire/eps_copy_input_stream.h" #include "upb/wire/internal/constants.h" -#include "upb/wire/internal/decode.h" +#include "upb/wire/internal/decoder.h" #include "upb/wire/internal/endian.h" #include "upb/wire/reader.h" diff --git a/upb/wire/internal/decode_fast.c b/upb/wire/internal/decode_fast.c index 61b19b6af5b12..27d648ff80a7c 100644 --- a/upb/wire/internal/decode_fast.c +++ b/upb/wire/internal/decode_fast.c @@ -21,7 +21,7 @@ #include "upb/message/internal/array.h" #include "upb/message/internal/types.h" #include "upb/mini_table/sub.h" -#include "upb/wire/internal/decode.h" +#include "upb/wire/internal/decoder.h" // Must be last. #include "upb/port/def.inc" diff --git a/upb/wire/internal/decode.h b/upb/wire/internal/decoder.h similarity index 97% rename from upb/wire/internal/decode.h rename to upb/wire/internal/decoder.h index fcc04cfaa1231..5ca1e1b2b2a8e 100644 --- a/upb/wire/internal/decode.h +++ b/upb/wire/internal/decoder.h @@ -10,8 +10,8 @@ * decode.c and decode_fast.c. */ -#ifndef UPB_WIRE_INTERNAL_DECODE_H_ -#define UPB_WIRE_INTERNAL_DECODE_H_ +#ifndef UPB_WIRE_INTERNAL_DECODER_H_ +#define UPB_WIRE_INTERNAL_DECODER_H_ #include "upb/mem/internal/arena.h" #include "upb/message/internal/message.h" @@ -124,4 +124,4 @@ UPB_INLINE uint32_t _upb_FastDecoder_LoadTag(const char* ptr) { #include "upb/port/undef.inc" -#endif /* UPB_WIRE_INTERNAL_DECODE_H_ */ +#endif /* UPB_WIRE_INTERNAL_DECODER_H_ */ From 61b82528ba50059f03204b4e9866a76dd4d56059 Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Fri, 29 Dec 2023 01:13:48 +0000 Subject: [PATCH 135/255] Auto-generate files after cl/594337191 --- php/ext/google/protobuf/php-upb.h | 6 +++--- ruby/ext/google/protobuf_c/ruby-upb.h | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/php/ext/google/protobuf/php-upb.h b/php/ext/google/protobuf/php-upb.h index 663a94132d2e1..be65077a21960 100644 --- a/php/ext/google/protobuf/php-upb.h +++ b/php/ext/google/protobuf/php-upb.h @@ -13666,8 +13666,8 @@ enum { * decode.c and decode_fast.c. */ -#ifndef UPB_WIRE_INTERNAL_DECODE_H_ -#define UPB_WIRE_INTERNAL_DECODE_H_ +#ifndef UPB_WIRE_INTERNAL_DECODER_H_ +#define UPB_WIRE_INTERNAL_DECODER_H_ #include "utf8_range.h" @@ -13774,7 +13774,7 @@ UPB_INLINE uint32_t _upb_FastDecoder_LoadTag(const char* ptr) { } -#endif /* UPB_WIRE_INTERNAL_DECODE_H_ */ +#endif /* UPB_WIRE_INTERNAL_DECODER_H_ */ #ifndef UPB_WIRE_INTERNAL_ENDIAN_H_ #define UPB_WIRE_INTERNAL_ENDIAN_H_ diff --git a/ruby/ext/google/protobuf_c/ruby-upb.h b/ruby/ext/google/protobuf_c/ruby-upb.h index a9f020025552f..73437cecebf4c 100755 --- a/ruby/ext/google/protobuf_c/ruby-upb.h +++ b/ruby/ext/google/protobuf_c/ruby-upb.h @@ -13485,8 +13485,8 @@ enum { * decode.c and decode_fast.c. */ -#ifndef UPB_WIRE_INTERNAL_DECODE_H_ -#define UPB_WIRE_INTERNAL_DECODE_H_ +#ifndef UPB_WIRE_INTERNAL_DECODER_H_ +#define UPB_WIRE_INTERNAL_DECODER_H_ #include "utf8_range.h" @@ -13593,7 +13593,7 @@ UPB_INLINE uint32_t _upb_FastDecoder_LoadTag(const char* ptr) { } -#endif /* UPB_WIRE_INTERNAL_DECODE_H_ */ +#endif /* UPB_WIRE_INTERNAL_DECODER_H_ */ #ifndef UPB_WIRE_INTERNAL_ENDIAN_H_ #define UPB_WIRE_INTERNAL_ENDIAN_H_ From 6e25bb8d4c112a7b5397879c50140894d27a1d01 Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Fri, 29 Dec 2023 03:08:59 -0800 Subject: [PATCH 136/255] Optimize AddAllocatedForParse function. PiperOrigin-RevId: 594422850 --- src/google/protobuf/repeated_ptr_field.h | 31 ++++++++++++++---------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/src/google/protobuf/repeated_ptr_field.h b/src/google/protobuf/repeated_ptr_field.h index 1f41a83f17274..2fb46157ad384 100644 --- a/src/google/protobuf/repeated_ptr_field.h +++ b/src/google/protobuf/repeated_ptr_field.h @@ -283,21 +283,26 @@ class PROTOBUF_EXPORT RepeatedPtrFieldBase { reinterpret_cast(this), reinterpret_cast(rhs)); } - // Prepares the container for adding elements via `AddAllocatedForParse`. - // It ensures we have no preallocated elements in the array. - // Returns true if the invariants hold and `AddAllocatedForParse` can be - // used. + // Returns true if there are no preallocated elements in the array. bool PrepareForParse() { return allocated_size() == current_size_; } // Similar to `AddAllocated` but faster. - // Can only be invoked after a call to `PrepareForParse` that returned `true`, - // or other calls to `AddAllocatedForParse`. - template - void AddAllocatedForParse(Value* value) { - ABSL_DCHECK_EQ(current_size_, allocated_size()); - MaybeExtend(); - element_at(current_size_++) = value; - if (!using_sso()) ++rep()->allocated_size; + // + // Pre-condition: PrepareForParse() is true. + void AddAllocatedForParse(void* value) { + ABSL_DCHECK(PrepareForParse()); + if (PROTOBUF_PREDICT_FALSE(SizeAtCapacity())) { + *InternalExtend(1) = value; + ++rep()->allocated_size; + } else { + if (using_sso()) { + tagged_rep_or_elem_ = value; + } else { + rep()->elements[current_size_] = value; + ++rep()->allocated_size; + } + } + ExchangeCurrentSize(current_size_ + 1); } protected: @@ -1202,7 +1207,7 @@ class RepeatedPtrField final : private internal::RepeatedPtrFieldBase { void AddAllocatedForParse(Element* p) { - return RepeatedPtrFieldBase::AddAllocatedForParse(p); + return RepeatedPtrFieldBase::AddAllocatedForParse(p); } }; From f0cf0b653c740093cffbd051369ce5f342287818 Mon Sep 17 00:00:00 2001 From: Eric Salo Date: Fri, 29 Dec 2023 17:28:36 -0800 Subject: [PATCH 137/255] upb: clean up and consolidate the upb/message/ build targets PiperOrigin-RevId: 594514934 --- protos/BUILD | 3 +- protos/protos.cc | 2 +- protos/repeated_field.h | 2 +- protos/repeated_field_iterator.h | 2 +- upb/BUILD | 31 +------ upb/json/BUILD | 2 - upb/json/decode.c | 1 - upb/message/BUILD | 145 +++++++++++++----------------- upb/message/accessors.h | 7 +- upb/message/array.h | 2 +- upb/message/compare.h | 2 +- upb/message/copy.c | 10 ++- upb/message/copy.h | 1 + upb/message/internal/accessors.h | 74 +++++---------- upb/message/internal/extension.c | 8 +- upb/message/internal/map.h | 11 ++- upb/message/internal/map_entry.h | 2 +- upb/message/internal/map_sorter.h | 7 +- upb/message/internal/message.c | 1 - upb/message/internal/message.h | 23 +++-- upb/message/internal/tagged_ptr.h | 59 ++++++++++++ upb/message/internal/types.h | 23 ----- upb/message/map.h | 9 +- upb/message/message.c | 1 - upb/message/message.h | 2 +- upb/message/promote.c | 6 +- upb/message/tagged_ptr.h | 32 ++----- upb/message/types.h | 17 ---- upb/message/value.h | 5 +- upb/mini_descriptor/BUILD | 1 + upb/reflection/BUILD | 4 +- upb/reflection/field_def.c | 1 - upb/reflection/message.h | 1 - upb/text/BUILD | 1 + upb/wire/BUILD | 3 +- upb/wire/decode.c | 10 ++- upb/wire/encode.c | 5 +- upb/wire/encode.h | 2 +- upb/wire/internal/decode_fast.c | 1 - 39 files changed, 237 insertions(+), 282 deletions(-) create mode 100644 upb/message/internal/tagged_ptr.h delete mode 100644 upb/message/internal/types.h delete mode 100644 upb/message/types.h diff --git a/protos/BUILD b/protos/BUILD index f903249a04a52..0167b19d5ee17 100644 --- a/protos/BUILD +++ b/protos/BUILD @@ -35,7 +35,6 @@ cc_library( "//upb:mem", "//upb:message", "//upb:message_copy", - "//upb:message_types", "@com_google_absl//absl/base:core_headers", "@com_google_absl//absl/strings", ], @@ -59,10 +58,10 @@ cc_library( "//upb:message_accessors", "//upb:message_copy", "//upb:message_promote", - "//upb:message_types", "//upb:mini_table", "//upb:wire", "//upb:wire_reader", + "//upb/message:internal", "@com_google_absl//absl/status", "@com_google_absl//absl/status:statusor", "@com_google_absl//absl/strings", diff --git a/protos/protos.cc b/protos/protos.cc index 57570e4039af5..6522405c12628 100644 --- a/protos/protos.cc +++ b/protos/protos.cc @@ -18,8 +18,8 @@ #include "upb/mem/arena.h" #include "upb/message/copy.h" #include "upb/message/internal/extension.h" +#include "upb/message/message.h" #include "upb/message/promote.h" -#include "upb/message/types.h" #include "upb/mini_table/extension.h" #include "upb/mini_table/extension_registry.h" #include "upb/mini_table/message.h" diff --git a/protos/repeated_field.h b/protos/repeated_field.h index 6d37b569fa2bf..f8f3f5acaf796 100644 --- a/protos/repeated_field.h +++ b/protos/repeated_field.h @@ -22,7 +22,7 @@ #include "upb/mem/arena.h" #include "upb/message/array.h" #include "upb/message/copy.h" -#include "upb/message/types.h" +#include "upb/message/message.h" namespace protos { namespace internal { diff --git a/protos/repeated_field_iterator.h b/protos/repeated_field_iterator.h index 79c284c8dbce4..27af26b89991f 100644 --- a/protos/repeated_field_iterator.h +++ b/protos/repeated_field_iterator.h @@ -18,7 +18,7 @@ #include "upb/base/string_view.h" #include "upb/mem/arena.h" #include "upb/message/array.h" -#include "upb/message/types.h" +#include "upb/message/message.h" namespace protos { namespace internal { diff --git a/upb/BUILD b/upb/BUILD index 13047648e5bcb..eff6314ec9d03 100644 --- a/upb/BUILD +++ b/upb/BUILD @@ -115,6 +115,7 @@ cc_library( ":mini_descriptor", ":mini_table", ":wire", + "//upb/message:internal", ], ) @@ -228,24 +229,6 @@ alias( visibility = ["//visibility:public"], ) -alias( - name = "message_tagged_ptr", - actual = "//upb/message:tagged_ptr", - visibility = ["//upb:friends"], -) - -alias( - name = "message_types", - actual = "//upb/message:types", - visibility = ["//visibility:public"], -) - -alias( - name = "message_value", - actual = "//upb/message:value", - visibility = ["//visibility:public"], -) - alias( name = "mini_descriptor", actual = "//upb/mini_descriptor", @@ -357,9 +340,6 @@ upb_amalgamation( ":message_accessors", ":message_compare", ":message_copy", - ":message_tagged_ptr", - ":message_types", - ":message_value", ":mini_descriptor", ":mini_table", ":mini_table_compat", @@ -370,6 +350,7 @@ upb_amalgamation( ":wire_reader", "//upb/base:internal", "//upb/mem:internal", + "//upb/message:internal", "//upb/mini_descriptor:internal", "//upb/mini_table:internal", ], @@ -405,9 +386,6 @@ upb_amalgamation( ":message_accessors", ":message_compare", ":message_copy", - ":message_tagged_ptr", - ":message_types", - ":message_value", ":mini_descriptor", ":mini_table", ":mini_table_compat", @@ -418,6 +396,7 @@ upb_amalgamation( ":wire_reader", "//upb/base:internal", "//upb/mem:internal", + "//upb/message:internal", "//upb/mini_descriptor:internal", "//upb/mini_table:internal", ], @@ -454,9 +433,6 @@ upb_amalgamation( ":message_accessors", ":message_compare", ":message_copy", - ":message_tagged_ptr", - ":message_types", - ":message_value", ":mini_descriptor", ":mini_table", ":mini_table_compat", @@ -467,6 +443,7 @@ upb_amalgamation( ":wire_reader", "//upb/base:internal", "//upb/mem:internal", + "//upb/message:internal", "//upb/mini_descriptor:internal", "//upb/mini_table:internal", ], diff --git a/upb/json/BUILD b/upb/json/BUILD index 6331725465b1a..d10498fadadc1 100644 --- a/upb/json/BUILD +++ b/upb/json/BUILD @@ -24,7 +24,6 @@ cc_library( "//upb:lex", "//upb:mem", "//upb:message", - "//upb:message_types", "//upb:mini_table", "//upb:port", "//upb:reflection", @@ -103,7 +102,6 @@ upb_c_proto_library( # "//upb:base", # "//upb:mem", # "//upb:message", -# "//upb:message_types", # "//upb:mini_table", # "//upb:reflection", # ], diff --git a/upb/json/decode.c b/upb/json/decode.c index 531e937456dcf..66f0929619b7f 100644 --- a/upb/json/decode.c +++ b/upb/json/decode.c @@ -28,7 +28,6 @@ #include "upb/message/array.h" #include "upb/message/map.h" #include "upb/message/message.h" -#include "upb/message/types.h" #include "upb/mini_table/message.h" #include "upb/reflection/def.h" #include "upb/reflection/message.h" diff --git a/upb/message/BUILD b/upb/message/BUILD index 969b2ecaca84f..1b10994878f8a 100644 --- a/upb/message/BUILD +++ b/upb/message/BUILD @@ -17,102 +17,118 @@ load( ) cc_library( - name = "accessors", + name = "message", srcs = [ - "accessors.c", + "array.c", + "compat.c", + "map.c", + "map_sorter.c", + "message.c", + ], + hdrs = [ + "array.h", + "compat.h", + "map.h", + "map_gencode_util.h", + "message.h", + "tagged_ptr.h", + "value.h", + ], + copts = UPB_DEFAULT_COPTS, + visibility = ["//visibility:public"], + deps = [ + ":internal", + "//upb:base", + "//upb:mem", + "//upb:mini_table", + "//upb:port", + "//upb/base:internal", + "//upb/mini_table:internal", + ], +) + +cc_library( + name = "internal", + srcs = [ + "internal/extension.c", + "internal/message.c", ], hdrs = [ - "accessors.h", "internal/accessors.h", + "internal/array.h", + "internal/extension.h", + "internal/map.h", + "internal/map_entry.h", + "internal/map_sorter.h", + "internal/message.h", + "internal/tagged_ptr.h", ], copts = UPB_DEFAULT_COPTS, visibility = ["//visibility:public"], deps = [ - ":message", - ":tagged_ptr", - ":types", "//upb:base", + "//upb:hash", "//upb:mem", "//upb:mini_table", "//upb:port", + "//upb/base:internal", ], ) cc_library( - name = "compare", + name = "accessors", srcs = [ - "compare.c", + "accessors.c", ], hdrs = [ - "compare.h", + "accessors.h", ], copts = UPB_DEFAULT_COPTS, visibility = ["//visibility:public"], deps = [ + ":internal", ":message", - ":types", + "//upb:base", "//upb:mem", "//upb:mini_table", "//upb:port", - "//upb:wire", ], ) cc_library( - name = "copy", + name = "compare", srcs = [ - "copy.c", + "compare.c", ], hdrs = [ - "copy.h", + "compare.h", ], copts = UPB_DEFAULT_COPTS, visibility = ["//visibility:public"], deps = [ - ":accessors", ":message", - ":tagged_ptr", - ":types", - "//upb:base", "//upb:mem", "//upb:mini_table", "//upb:port", - "//upb/mini_table:internal", + "//upb:wire", ], ) cc_library( - name = "message", + name = "copy", srcs = [ - "array.c", - "compat.c", - "internal/extension.c", - "internal/message.c", - "map.c", - "map_sorter.c", - "message.c", + "copy.c", ], hdrs = [ - "array.h", - "compat.h", - "internal/array.h", - "internal/extension.h", - "internal/map.h", - "internal/map_entry.h", - "internal/map_sorter.h", - "internal/message.h", - "internal/types.h", - "map.h", - "map_gencode_util.h", - "message.h", + "copy.h", ], copts = UPB_DEFAULT_COPTS, visibility = ["//visibility:public"], deps = [ - ":types", - ":value", + ":accessors", + ":internal", + ":message", "//upb:base", - "//upb:hash", "//upb:mem", "//upb:mini_table", "//upb:port", @@ -133,9 +149,8 @@ cc_library( visibility = ["//visibility:public"], deps = [ ":accessors", + ":internal", ":message", - ":tagged_ptr", - ":types", "//upb:base", "//upb:eps_copy_input_stream", "//upb:mem", @@ -161,41 +176,6 @@ cc_library( ], ) -cc_library( - name = "tagged_ptr", - hdrs = ["tagged_ptr.h"], - copts = UPB_DEFAULT_COPTS, - visibility = ["//visibility:public"], - deps = [ - ":types", - "//upb:port", - ], -) - -cc_library( - name = "types", - hdrs = [ - "types.h", - ], - copts = UPB_DEFAULT_COPTS, - visibility = ["//visibility:public"], - deps = [], -) - -cc_library( - name = "value", - hdrs = [ - "value.h", - ], - copts = UPB_DEFAULT_COPTS, - visibility = ["//visibility:public"], - deps = [ - ":tagged_ptr", - ":types", - "//upb:base", - ], -) - proto_library( name = "message_test_proto", testonly = 1, @@ -264,6 +244,7 @@ cc_test( deps = [ ":accessors", ":copy", + ":internal", ":message", "//:protobuf", "//upb:base", @@ -298,9 +279,9 @@ cc_test( deps = [ ":accessors", ":copy", + ":internal", ":message", ":promote", - ":tagged_ptr", "//:protobuf", "//upb:base", "//upb:mem", @@ -324,14 +305,14 @@ cc_test( name = "test", srcs = ["test.cc"], deps = [ + ":internal", + ":message", ":message_test_upb_minitable_proto", ":message_test_upb_proto", ":message_test_upb_proto_reflection", - ":value", "//upb:base", "//upb:json", "//upb:mem", - "//upb:message", "//upb:mini_table", "//upb:reflection", "//upb:wire", diff --git a/upb/message/accessors.h b/upb/message/accessors.h index ac5788ebf8123..e55781cb6c57d 100644 --- a/upb/message/accessors.h +++ b/upb/message/accessors.h @@ -20,10 +20,10 @@ #include "upb/message/internal/array.h" #include "upb/message/internal/map.h" #include "upb/message/internal/message.h" -#include "upb/message/internal/types.h" +#include "upb/message/internal/tagged_ptr.h" #include "upb/message/map.h" #include "upb/message/tagged_ptr.h" -#include "upb/message/types.h" +#include "upb/message/value.h" #include "upb/mini_table/enum.h" #include "upb/mini_table/sub.h" @@ -352,7 +352,8 @@ UPB_API_INLINE void upb_Message_SetMessage(upb_Message* msg, const upb_MiniTableField* field, upb_Message* sub_message) { _upb_Message_SetTaggedMessagePtr( - msg, mini_table, field, _upb_TaggedMessagePtr_Pack(sub_message, false)); + msg, mini_table, field, + UPB_PRIVATE(_upb_TaggedMessagePtr_Pack)(sub_message, false)); } UPB_API_INLINE upb_Message* upb_Message_GetOrCreateMutableMessage( diff --git a/upb/message/array.h b/upb/message/array.h index 62500f0a1d4f7..b217bfbcb8ad2 100644 --- a/upb/message/array.h +++ b/upb/message/array.h @@ -12,7 +12,7 @@ #include "upb/base/descriptor_constants.h" #include "upb/mem/arena.h" -#include "upb/message/value.h" // IWYU pragma: export +#include "upb/message/value.h" // Must be last. #include "upb/port/def.inc" diff --git a/upb/message/compare.h b/upb/message/compare.h index 98d165c5de2e8..db7e20a0ba305 100644 --- a/upb/message/compare.h +++ b/upb/message/compare.h @@ -8,7 +8,7 @@ #ifndef UPB_MESSAGE_COMPARE_H_ #define UPB_MESSAGE_COMPARE_H_ -#include "upb/message/types.h" +#include "upb/message/message.h" #include "upb/mini_table/message.h" // Must be last. diff --git a/upb/message/copy.c b/upb/message/copy.c index 9ee6be71c37a1..9342293e31373 100644 --- a/upb/message/copy.c +++ b/upb/message/copy.c @@ -24,6 +24,7 @@ #include "upb/message/tagged_ptr.h" #include "upb/mini_table/extension.h" #include "upb/mini_table/field.h" +#include "upb/mini_table/internal/field.h" #include "upb/mini_table/internal/size_log2.h" #include "upb/mini_table/message.h" #include "upb/mini_table/sub.h" @@ -74,9 +75,9 @@ static bool upb_Clone_MessageValue(void* value, upb_CType value_type, if (is_empty) sub = UPB_PRIVATE(_upb_MiniTable_Empty)(); UPB_ASSERT(source); upb_Message* clone = upb_Message_DeepClone( - _upb_TaggedMessagePtr_GetMessage(source), sub, arena); + UPB_PRIVATE(_upb_TaggedMessagePtr_GetMessage)(source), sub, arena); *(upb_TaggedMessagePtr*)value = - _upb_TaggedMessagePtr_Pack(clone, is_empty); + UPB_PRIVATE(_upb_TaggedMessagePtr_Pack)(clone, is_empty); return clone != NULL; } break; } @@ -199,7 +200,7 @@ upb_Message* _upb_Message_Copy(upb_Message* dst, const upb_Message* src, upb_TaggedMessagePtr tagged = upb_Message_GetTaggedMessagePtr(src, field, NULL); const upb_Message* sub_message = - _upb_TaggedMessagePtr_GetMessage(tagged); + UPB_PRIVATE(_upb_TaggedMessagePtr_GetMessage)(tagged); if (sub_message != NULL) { // If the message is currently in an unlinked, "empty" state we keep // it that way, because we don't want to deal with decode options, @@ -215,7 +216,8 @@ upb_Message* _upb_Message_Copy(upb_Message* dst, const upb_Message* src, } _upb_Message_SetTaggedMessagePtr( dst, mini_table, field, - _upb_TaggedMessagePtr_Pack(dst_sub_message, is_empty)); + UPB_PRIVATE(_upb_TaggedMessagePtr_Pack)(dst_sub_message, + is_empty)); } } break; case kUpb_CType_String: diff --git a/upb/message/copy.h b/upb/message/copy.h index 17f82d85c70ea..33fe537f4ff9b 100644 --- a/upb/message/copy.h +++ b/upb/message/copy.h @@ -11,6 +11,7 @@ #include "upb/mem/arena.h" #include "upb/message/array.h" #include "upb/message/map.h" +#include "upb/message/message.h" #include "upb/mini_table/message.h" // Must be last. diff --git a/upb/message/internal/accessors.h b/upb/message/internal/accessors.h index 191df0552daad..2c585cd3bbe09 100644 --- a/upb/message/internal/accessors.h +++ b/upb/message/internal/accessors.h @@ -17,8 +17,7 @@ #include "upb/message/internal/extension.h" #include "upb/message/internal/map.h" #include "upb/message/internal/message.h" -#include "upb/message/internal/types.h" -#include "upb/message/tagged_ptr.h" +#include "upb/message/internal/tagged_ptr.h" #include "upb/mini_table/extension.h" #include "upb/mini_table/field.h" @@ -52,7 +51,7 @@ extern "C" { // Hasbit access /////////////////////////////////////////////////////////////// UPB_INLINE bool UPB_PRIVATE(_upb_Message_GetHasbit)( - const upb_Message* msg, const upb_MiniTableField* f) { + const struct upb_Message* msg, const upb_MiniTableField* f) { const size_t offset = UPB_PRIVATE(_upb_MiniTableField_HasbitOffset)(f); const char mask = UPB_PRIVATE(_upb_MiniTableField_HasbitMask)(f); @@ -60,7 +59,7 @@ UPB_INLINE bool UPB_PRIVATE(_upb_Message_GetHasbit)( } UPB_INLINE void UPB_PRIVATE(_upb_Message_SetHasbit)( - const upb_Message* msg, const upb_MiniTableField* f) { + const struct upb_Message* msg, const upb_MiniTableField* f) { const size_t offset = UPB_PRIVATE(_upb_MiniTableField_HasbitOffset)(f); const char mask = UPB_PRIVATE(_upb_MiniTableField_HasbitMask)(f); @@ -68,7 +67,7 @@ UPB_INLINE void UPB_PRIVATE(_upb_Message_SetHasbit)( } UPB_INLINE void UPB_PRIVATE(_upb_Message_ClearHasbit)( - const upb_Message* msg, const upb_MiniTableField* f) { + const struct upb_Message* msg, const upb_MiniTableField* f) { const size_t offset = UPB_PRIVATE(_upb_MiniTableField_HasbitOffset)(f); const char mask = UPB_PRIVATE(_upb_MiniTableField_HasbitMask)(f); @@ -78,18 +77,18 @@ UPB_INLINE void UPB_PRIVATE(_upb_Message_ClearHasbit)( // Oneof case access /////////////////////////////////////////////////////////// UPB_INLINE uint32_t* UPB_PRIVATE(_upb_Message_OneofCasePtr)( - upb_Message* msg, const upb_MiniTableField* f) { + struct upb_Message* msg, const upb_MiniTableField* f) { return UPB_PTR_AT(msg, UPB_PRIVATE(_upb_MiniTableField_OneofOffset)(f), uint32_t); } UPB_INLINE uint32_t UPB_PRIVATE(_upb_Message_GetOneofCase)( - const upb_Message* msg, const upb_MiniTableField* f) { - return *UPB_PRIVATE(_upb_Message_OneofCasePtr)((upb_Message*)msg, f); + const struct upb_Message* msg, const upb_MiniTableField* f) { + return *UPB_PRIVATE(_upb_Message_OneofCasePtr)((struct upb_Message*)msg, f); } UPB_INLINE void UPB_PRIVATE(_upb_Message_SetOneofCase)( - upb_Message* msg, const upb_MiniTableField* f) { + struct upb_Message* msg, const upb_MiniTableField* f) { *UPB_PRIVATE(_upb_Message_OneofCasePtr)(msg, f) = upb_MiniTableField_Number(f); } @@ -98,18 +97,18 @@ UPB_INLINE void UPB_PRIVATE(_upb_Message_SetOneofCase)( // LINT.ThenChange(GoogleInternalName2) -UPB_INLINE void* _upb_MiniTableField_GetPtr(upb_Message* msg, +UPB_INLINE void* _upb_MiniTableField_GetPtr(struct upb_Message* msg, const upb_MiniTableField* field) { return (char*)msg + field->UPB_ONLYBITS(offset); } UPB_INLINE const void* _upb_MiniTableField_GetConstPtr( - const upb_Message* msg, const upb_MiniTableField* field) { + const struct upb_Message* msg, const upb_MiniTableField* field) { return (char*)msg + field->UPB_ONLYBITS(offset); } UPB_INLINE void UPB_PRIVATE(_upb_Message_SetPresence)( - upb_Message* msg, const upb_MiniTableField* field) { + struct upb_Message* msg, const upb_MiniTableField* field) { if (field->presence > 0) { UPB_PRIVATE(_upb_Message_SetHasbit)(msg, field); } else if (upb_MiniTableField_IsInOneof(field)) { @@ -195,13 +194,13 @@ UPB_INLINE void UPB_PRIVATE(_upb_MiniTableField_DataCopy)( // returned bool value may be ignored since it will always succeed. UPB_INLINE bool _upb_Message_HasExtensionField( - const upb_Message* msg, const upb_MiniTableExtension* ext) { + const struct upb_Message* msg, const upb_MiniTableExtension* ext) { UPB_ASSERT(upb_MiniTableField_HasPresence(&ext->UPB_PRIVATE(field))); return _upb_Message_Getext(msg, ext) != NULL; } UPB_INLINE bool _upb_Message_HasNonExtensionField( - const upb_Message* msg, const upb_MiniTableField* field) { + const struct upb_Message* msg, const upb_MiniTableField* field) { UPB_ASSERT(upb_MiniTableField_HasPresence(field)); UPB_ASSUME(!upb_MiniTableField_IsExtension(field)); if (upb_MiniTableField_IsInOneof(field)) { @@ -213,7 +212,7 @@ UPB_INLINE bool _upb_Message_HasNonExtensionField( } static UPB_FORCEINLINE void _upb_Message_GetNonExtensionField( - const upb_Message* msg, const upb_MiniTableField* field, + const struct upb_Message* msg, const upb_MiniTableField* field, const void* default_val, void* val) { UPB_ASSUME(!upb_MiniTableField_IsExtension(field)); if ((upb_MiniTableField_IsInOneof(field) || @@ -227,7 +226,7 @@ static UPB_FORCEINLINE void _upb_Message_GetNonExtensionField( } UPB_INLINE void _upb_Message_GetExtensionField( - const upb_Message* msg, const upb_MiniTableExtension* mt_ext, + const struct upb_Message* msg, const upb_MiniTableExtension* mt_ext, const void* default_val, void* val) { const struct upb_Extension* ext = _upb_Message_Getext(msg, mt_ext); const upb_MiniTableField* f = &mt_ext->UPB_PRIVATE(field); @@ -240,35 +239,8 @@ UPB_INLINE void _upb_Message_GetExtensionField( } } -// Gets a mutable Array, Map or Message field. -// NOTE: For repeated/map fields, the resulting upb_Array*/upb_Map* can -// be NULL if a upb_Array/upb_Map has not been allocated yet. Array/map -// fields do not have presence, so this is semantically identical to a -// pointer to an empty array/map, and must be treated the same for all -// semantic purposes. -// -// For message fields, the pointer is guaranteed to be NULL iff the field -// is unset (as message fields do have presence). -UPB_INLINE upb_MutableMessageValue _upb_Message_GetMutableField( - const upb_Message* msg, const upb_MiniTableField* field) { - UPB_ASSUME(!upb_MiniTableField_IsScalar(field) || - upb_MiniTableField_IsSubMessage(field)); - - upb_MutableMessageValue default_val; - default_val.msg = NULL; - - upb_MutableMessageValue ret; - if (upb_MiniTableField_IsExtension(field)) { - _upb_Message_GetExtensionField(msg, (upb_MiniTableExtension*)field, - &default_val, &ret); - } else { - _upb_Message_GetNonExtensionField(msg, field, &default_val, &ret); - } - return ret; -} - UPB_INLINE void _upb_Message_SetNonExtensionField( - upb_Message* msg, const upb_MiniTableField* field, const void* val) { + struct upb_Message* msg, const upb_MiniTableField* field, const void* val) { UPB_ASSUME(!upb_MiniTableField_IsExtension(field)); UPB_PRIVATE(_upb_Message_SetPresence)(msg, field); UPB_PRIVATE(_upb_MiniTableField_DataCopy) @@ -276,8 +248,8 @@ UPB_INLINE void _upb_Message_SetNonExtensionField( } UPB_INLINE bool _upb_Message_SetExtensionField( - upb_Message* msg, const upb_MiniTableExtension* mt_ext, const void* val, - upb_Arena* a) { + struct upb_Message* msg, const upb_MiniTableExtension* mt_ext, + const void* val, upb_Arena* a) { UPB_ASSERT(a); struct upb_Extension* ext = _upb_Message_GetOrCreateExtension(msg, mt_ext, a); if (!ext) return false; @@ -287,7 +259,7 @@ UPB_INLINE bool _upb_Message_SetExtensionField( } UPB_INLINE void _upb_Message_ClearExtensionField( - upb_Message* msg, const upb_MiniTableExtension* ext_l) { + struct upb_Message* msg, const upb_MiniTableExtension* ext_l) { upb_Message_Internal* in = upb_Message_Getinternal(msg); if (!in->internal) return; const struct upb_Extension* base = @@ -301,7 +273,7 @@ UPB_INLINE void _upb_Message_ClearExtensionField( } UPB_INLINE void _upb_Message_ClearNonExtensionField( - upb_Message* msg, const upb_MiniTableField* field) { + struct upb_Message* msg, const upb_MiniTableField* field) { if (field->presence > 0) { UPB_PRIVATE(_upb_Message_ClearHasbit)(msg, field); } else if (upb_MiniTableField_IsInOneof(field)) { @@ -315,19 +287,19 @@ UPB_INLINE void _upb_Message_ClearNonExtensionField( } UPB_INLINE void _upb_Message_AssertMapIsUntagged( - const upb_Message* msg, const upb_MiniTableField* field) { + const struct upb_Message* msg, const upb_MiniTableField* field) { UPB_UNUSED(msg); UPB_PRIVATE(_upb_MiniTableField_CheckIsMap)(field); #ifndef NDEBUG upb_TaggedMessagePtr default_val = 0; upb_TaggedMessagePtr tagged; _upb_Message_GetNonExtensionField(msg, field, &default_val, &tagged); - UPB_ASSERT(!upb_TaggedMessagePtr_IsEmpty(tagged)); + UPB_ASSERT(!UPB_PRIVATE(_upb_TaggedMessagePtr_IsEmpty)(tagged)); #endif } UPB_INLINE struct upb_Map* _upb_Message_GetOrCreateMutableMap( - upb_Message* msg, const upb_MiniTableField* field, size_t key_size, + struct upb_Message* msg, const upb_MiniTableField* field, size_t key_size, size_t val_size, upb_Arena* arena) { UPB_PRIVATE(_upb_MiniTableField_CheckIsMap)(field); _upb_Message_AssertMapIsUntagged(msg, field); diff --git a/upb/message/internal/extension.c b/upb/message/internal/extension.c index 81cfa0f519025..bc180f47c8fce 100644 --- a/upb/message/internal/extension.c +++ b/upb/message/internal/extension.c @@ -12,14 +12,13 @@ #include "upb/mem/arena.h" #include "upb/message/internal/extension.h" #include "upb/message/internal/message.h" -#include "upb/message/types.h" #include "upb/mini_table/extension.h" // Must be last. #include "upb/port/def.inc" const struct upb_Extension* _upb_Message_Getext( - const upb_Message* msg, const upb_MiniTableExtension* e) { + const struct upb_Message* msg, const upb_MiniTableExtension* e) { size_t n; const struct upb_Extension* ext = UPB_PRIVATE(_upb_Message_Getexts)(msg, &n); @@ -36,7 +35,7 @@ const struct upb_Extension* _upb_Message_Getext( } const struct upb_Extension* UPB_PRIVATE(_upb_Message_Getexts)( - const upb_Message* msg, size_t* count) { + const struct upb_Message* msg, size_t* count) { const upb_Message_Internal* in = upb_Message_Getinternal(msg); if (in->internal) { *count = (in->internal->size - in->internal->ext_begin) / @@ -49,7 +48,8 @@ const struct upb_Extension* UPB_PRIVATE(_upb_Message_Getexts)( } struct upb_Extension* _upb_Message_GetOrCreateExtension( - upb_Message* msg, const upb_MiniTableExtension* e, upb_Arena* arena) { + struct upb_Message* msg, const upb_MiniTableExtension* e, + upb_Arena* arena) { struct upb_Extension* ext = (struct upb_Extension*)_upb_Message_Getext(msg, e); if (ext) return ext; diff --git a/upb/message/internal/map.h b/upb/message/internal/map.h index 139243ca2f3f8..da4223d305b24 100644 --- a/upb/message/internal/map.h +++ b/upb/message/internal/map.h @@ -5,8 +5,6 @@ // license that can be found in the LICENSE file or at // https://developers.google.com/open-source/licenses/bsd -// EVERYTHING BELOW THIS LINE IS INTERNAL - DO NOT USE ///////////////////////// - #ifndef UPB_MESSAGE_INTERNAL_MAP_H_ #define UPB_MESSAGE_INTERNAL_MAP_H_ @@ -17,11 +15,18 @@ #include "upb/base/string_view.h" #include "upb/hash/str_table.h" #include "upb/mem/arena.h" -#include "upb/message/map.h" // Must be last. #include "upb/port/def.inc" +typedef enum { + kUpb_MapInsertStatus_Inserted = 0, + kUpb_MapInsertStatus_Replaced = 1, + kUpb_MapInsertStatus_OutOfMemory = 2, +} upb_MapInsertStatus; + +// EVERYTHING BELOW THIS LINE IS INTERNAL - DO NOT USE ///////////////////////// + struct upb_Map { // Size of key and val, based on the map type. // Strings are represented as '0' because they must be handled specially. diff --git a/upb/message/internal/map_entry.h b/upb/message/internal/map_entry.h index 0c5c25e919b75..9c1ec6b5b50d3 100644 --- a/upb/message/internal/map_entry.h +++ b/upb/message/internal/map_entry.h @@ -12,7 +12,7 @@ #include "upb/base/string_view.h" #include "upb/hash/common.h" -#include "upb/message/internal/types.h" +#include "upb/message/internal/message.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 diff --git a/upb/message/internal/map_sorter.h b/upb/message/internal/map_sorter.h index 2a09b3c63f83f..65b58a5b14258 100644 --- a/upb/message/internal/map_sorter.h +++ b/upb/message/internal/map_sorter.h @@ -12,6 +12,8 @@ #include +#include "upb/base/descriptor_constants.h" +#include "upb/base/string_view.h" #include "upb/mem/alloc.h" #include "upb/message/internal/extension.h" #include "upb/message/internal/map.h" @@ -50,7 +52,8 @@ UPB_INLINE void _upb_mapsorter_destroy(_upb_mapsorter* s) { if (s->entries) upb_gfree(s->entries); } -UPB_INLINE bool _upb_sortedmap_next(_upb_mapsorter* s, const upb_Map* map, +UPB_INLINE bool _upb_sortedmap_next(_upb_mapsorter* s, + const struct upb_Map* map, _upb_sortedmap* sorted, upb_MapEntry* ent) { if (sorted->pos == sorted->end) return false; const upb_tabent* tabent = (const upb_tabent*)s->entries[sorted->pos++]; @@ -75,7 +78,7 @@ UPB_INLINE void _upb_mapsorter_popmap(_upb_mapsorter* s, } bool _upb_mapsorter_pushmap(_upb_mapsorter* s, upb_FieldType key_type, - const upb_Map* map, _upb_sortedmap* sorted); + const struct upb_Map* map, _upb_sortedmap* sorted); bool _upb_mapsorter_pushexts(_upb_mapsorter* s, const struct upb_Extension* exts, size_t count, diff --git a/upb/message/internal/message.c b/upb/message/internal/message.c index 08b70d2d61e5e..1287dc327e862 100644 --- a/upb/message/internal/message.c +++ b/upb/message/internal/message.c @@ -12,7 +12,6 @@ #include "upb/base/internal/log2.h" #include "upb/mem/arena.h" -#include "upb/message/internal/types.h" // Must be last. #include "upb/port/def.inc" diff --git a/upb/message/internal/message.h b/upb/message/internal/message.h index 54af496fb02b6..a7b5203eb318a 100644 --- a/upb/message/internal/message.h +++ b/upb/message/internal/message.h @@ -12,15 +12,14 @@ ** The definitions in this file are internal to upb. **/ -#ifndef UPB_MESSAGE_INTERNAL_H_ -#define UPB_MESSAGE_INTERNAL_H_ +#ifndef UPB_MESSAGE_INTERNAL_MESSAGE_H_ +#define UPB_MESSAGE_INTERNAL_MESSAGE_H_ #include #include #include "upb/mem/arena.h" #include "upb/message/internal/extension.h" -#include "upb/message/internal/types.h" #include "upb/mini_table/message.h" // Must be last. @@ -39,7 +38,7 @@ extern const double kUpb_NaN; * these before the user's data. The user's upb_Message* points after the * upb_Message_Internal. */ -struct upb_Message_InternalData { +typedef struct { /* Total size of this structure, including the data that follows. * Must be aligned to 8, which is alignof(upb_Extension) */ uint32_t size; @@ -61,6 +60,20 @@ struct upb_Message_InternalData { uint32_t ext_begin; /* Data follows, as if there were an array: * char data[size - sizeof(upb_Message_InternalData)]; */ +} upb_Message_InternalData; + +typedef struct { + union { + upb_Message_InternalData* internal; + + // Force 8-byte alignment, since the data members may contain members that + // require 8-byte alignment. + double d; + }; +} upb_Message_Internal; + +struct upb_Message { + int unused; // Placeholder cuz Windows won't compile an empty struct. }; UPB_INLINE size_t upb_msg_sizeof(const upb_MiniTable* m) { @@ -103,4 +116,4 @@ bool UPB_PRIVATE(_upb_Message_Realloc)(struct upb_Message* msg, size_t need, #include "upb/port/undef.inc" -#endif /* UPB_MESSAGE_INTERNAL_H_ */ +#endif /* UPB_MESSAGE_INTERNAL_MESSAGE_H_ */ diff --git a/upb/message/internal/tagged_ptr.h b/upb/message/internal/tagged_ptr.h new file mode 100644 index 0000000000000..b1c9a77b3d6fc --- /dev/null +++ b/upb/message/internal/tagged_ptr.h @@ -0,0 +1,59 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2023 Google LLC. All rights reserved. +// +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file or at +// https://developers.google.com/open-source/licenses/bsd + +#ifndef UPB_MINI_TABLE_INTERNAL_TAGGED_PTR_H_ +#define UPB_MINI_TABLE_INTERNAL_TAGGED_PTR_H_ + +#include + +#include "upb/message/internal/message.h" + +// Must be last. +#include "upb/port/def.inc" + +typedef uintptr_t upb_TaggedMessagePtr; + +#ifdef __cplusplus +extern "C" { +#endif + +// Internal-only because empty messages cannot be created by the user. +UPB_INLINE upb_TaggedMessagePtr +UPB_PRIVATE(_upb_TaggedMessagePtr_Pack)(struct upb_Message* ptr, bool empty) { + UPB_ASSERT(((uintptr_t)ptr & 1) == 0); + return (uintptr_t)ptr | (empty ? 1 : 0); +} + +UPB_INLINE bool UPB_PRIVATE(_upb_TaggedMessagePtr_IsEmpty)( + upb_TaggedMessagePtr ptr) { + return ptr & 1; +} + +UPB_INLINE struct upb_Message* UPB_PRIVATE(_upb_TaggedMessagePtr_GetMessage)( + upb_TaggedMessagePtr ptr) { + return (struct upb_Message*)(ptr & ~(uintptr_t)1); +} + +UPB_INLINE struct upb_Message* UPB_PRIVATE( + _upb_TaggedMessagePtr_GetNonEmptyMessage)(upb_TaggedMessagePtr ptr) { + UPB_ASSERT(!UPB_PRIVATE(_upb_TaggedMessagePtr_IsEmpty)(ptr)); + return UPB_PRIVATE(_upb_TaggedMessagePtr_GetMessage)(ptr); +} + +UPB_INLINE struct upb_Message* UPB_PRIVATE( + _upb_TaggedMessagePtr_GetEmptyMessage)(upb_TaggedMessagePtr ptr) { + UPB_ASSERT(UPB_PRIVATE(_upb_TaggedMessagePtr_IsEmpty)(ptr)); + return UPB_PRIVATE(_upb_TaggedMessagePtr_GetMessage)(ptr); +} + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#include "upb/port/undef.inc" + +#endif /* UPB_MINI_TABLE_INTERNAL_TAGGED_PTR_H_ */ diff --git a/upb/message/internal/types.h b/upb/message/internal/types.h deleted file mode 100644 index 2bd3b0b1344c5..0000000000000 --- a/upb/message/internal/types.h +++ /dev/null @@ -1,23 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#ifndef UPB_MINI_TABLE_INTERNAL_TYPES_H_ -#define UPB_MINI_TABLE_INTERNAL_TYPES_H_ - -typedef struct upb_Message_InternalData upb_Message_InternalData; - -typedef struct { - union { - upb_Message_InternalData* internal; - - // Force 8-byte alignment, since the data members may contain members that - // require 8-byte alignment. - double d; - }; -} upb_Message_Internal; - -#endif // UPB_MINI_TABLE_INTERNAL_TYPES_H_ diff --git a/upb/message/map.h b/upb/message/map.h index 4160c35163a55..e471a6bbe3788 100644 --- a/upb/message/map.h +++ b/upb/message/map.h @@ -12,7 +12,8 @@ #include "upb/base/descriptor_constants.h" #include "upb/mem/arena.h" -#include "upb/message/value.h" // IWYU pragma: export +#include "upb/message/internal/map.h" +#include "upb/message/value.h" // Must be last. #include "upb/port/def.inc" @@ -39,12 +40,6 @@ UPB_API bool upb_Map_Get(const upb_Map* map, upb_MessageValue key, // Removes all entries in the map. UPB_API void upb_Map_Clear(upb_Map* map); -typedef enum { - kUpb_MapInsertStatus_Inserted = 0, - kUpb_MapInsertStatus_Replaced = 1, - kUpb_MapInsertStatus_OutOfMemory = 2, -} upb_MapInsertStatus; - // Sets the given key to the given value, returning whether the key was inserted // or replaced. If the key was inserted, then any existing iterators will be // invalidated. diff --git a/upb/message/message.c b/upb/message/message.c index 4f0fee1ad341c..fe52731eb9c2d 100644 --- a/upb/message/message.c +++ b/upb/message/message.c @@ -13,7 +13,6 @@ #include "upb/mem/arena.h" #include "upb/message/internal/message.h" -#include "upb/message/internal/types.h" #include "upb/mini_table/message.h" // Must be last. diff --git a/upb/message/message.h b/upb/message/message.h index bf04f6f9c64fb..95ac5047b8434 100644 --- a/upb/message/message.h +++ b/upb/message/message.h @@ -15,13 +15,13 @@ #include #include "upb/mem/arena.h" -#include "upb/message/types.h" // IWYU pragma: export #include "upb/mini_table/message.h" // Must be last. #include "upb/port/def.inc" typedef struct upb_Extension upb_Extension; +typedef struct upb_Message upb_Message; #ifdef __cplusplus extern "C" { diff --git a/upb/message/promote.c b/upb/message/promote.c index 593b09f24cccd..2cd0888c83e57 100644 --- a/upb/message/promote.c +++ b/upb/message/promote.c @@ -18,6 +18,7 @@ #include "upb/message/internal/array.h" #include "upb/message/internal/extension.h" #include "upb/message/internal/message.h" +#include "upb/message/internal/tagged_ptr.h" #include "upb/message/map.h" #include "upb/message/message.h" #include "upb/message/tagged_ptr.h" @@ -154,7 +155,8 @@ static upb_DecodeStatus upb_Message_PromoteOne(upb_TaggedMessagePtr* tagged, const upb_MiniTable* mini_table, int decode_options, upb_Arena* arena) { - upb_Message* empty = _upb_TaggedMessagePtr_GetEmptyMessage(*tagged); + upb_Message* empty = + UPB_PRIVATE(_upb_TaggedMessagePtr_GetEmptyMessage)(*tagged); size_t unknown_size; const char* unknown_data = upb_Message_GetUnknown(empty, &unknown_size); upb_Message* promoted = upb_Message_New(mini_table, arena); @@ -162,7 +164,7 @@ static upb_DecodeStatus upb_Message_PromoteOne(upb_TaggedMessagePtr* tagged, upb_DecodeStatus status = upb_Decode(unknown_data, unknown_size, promoted, mini_table, NULL, decode_options, arena); if (status == kUpb_DecodeStatus_Ok) { - *tagged = _upb_TaggedMessagePtr_Pack(promoted, false); + *tagged = UPB_PRIVATE(_upb_TaggedMessagePtr_Pack)(promoted, false); } return status; } diff --git a/upb/message/tagged_ptr.h b/upb/message/tagged_ptr.h index 9004c773dd621..f2e1bfd3b65a5 100644 --- a/upb/message/tagged_ptr.h +++ b/upb/message/tagged_ptr.h @@ -10,15 +10,16 @@ #include -#include "upb/message/types.h" // IWYU pragma: export +#include "upb/message/internal/tagged_ptr.h" +#include "upb/message/message.h" // Must be last. #include "upb/port/def.inc" // 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 +// 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 -// that field's true message type. This forms the basis of what we call +// that field's true message type. This forms the basis of what we call // "dynamic tree shaking." // // See the documentation for kUpb_DecodeOption_ExperimentalAllowUnlinked for @@ -30,35 +31,16 @@ typedef uintptr_t upb_TaggedMessagePtr; extern "C" { #endif -// Internal-only because empty messages cannot be created by the user. -UPB_INLINE upb_TaggedMessagePtr _upb_TaggedMessagePtr_Pack(upb_Message* ptr, - bool empty) { - UPB_ASSERT(((uintptr_t)ptr & 1) == 0); - return (uintptr_t)ptr | (empty ? 1 : 0); -} - // Users who enable unlinked sub-messages must use this to test whether a -// message is empty before accessing it. If a message is empty, it must be +// message is empty before accessing it. If a message is empty, it must be // first promoted using the interfaces in message/promote.h. UPB_INLINE bool upb_TaggedMessagePtr_IsEmpty(upb_TaggedMessagePtr ptr) { - return ptr & 1; -} - -UPB_INLINE upb_Message* _upb_TaggedMessagePtr_GetMessage( - upb_TaggedMessagePtr ptr) { - return (upb_Message*)(ptr & ~(uintptr_t)1); + return UPB_PRIVATE(_upb_TaggedMessagePtr_IsEmpty)(ptr); } UPB_INLINE upb_Message* upb_TaggedMessagePtr_GetNonEmptyMessage( upb_TaggedMessagePtr ptr) { - UPB_ASSERT(!upb_TaggedMessagePtr_IsEmpty(ptr)); - return _upb_TaggedMessagePtr_GetMessage(ptr); -} - -UPB_INLINE upb_Message* _upb_TaggedMessagePtr_GetEmptyMessage( - upb_TaggedMessagePtr ptr) { - UPB_ASSERT(upb_TaggedMessagePtr_IsEmpty(ptr)); - return _upb_TaggedMessagePtr_GetMessage(ptr); + return UPB_PRIVATE(_upb_TaggedMessagePtr_GetNonEmptyMessage)(ptr); } #ifdef __cplusplus diff --git a/upb/message/types.h b/upb/message/types.h deleted file mode 100644 index d20cf27dfc86c..0000000000000 --- a/upb/message/types.h +++ /dev/null @@ -1,17 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -#ifndef UPB_MESSAGE_TYPES_H_ -#define UPB_MESSAGE_TYPES_H_ - -// This typedef is in a leaf header to resolve a circular dependency between -// messages and mini tables. -typedef struct upb_Message { - int unused; // Placeholder cuz Windows won't compile an empty struct. -} upb_Message; - -#endif /* UPB_MESSAGE_TYPES_H_ */ diff --git a/upb/message/value.h b/upb/message/value.h index 547edc1d2e3af..775622c910cab 100644 --- a/upb/message/value.h +++ b/upb/message/value.h @@ -14,7 +14,10 @@ #include #include "upb/base/string_view.h" -#include "upb/message/tagged_ptr.h" +#include "upb/message/internal/array.h" +#include "upb/message/internal/map.h" +#include "upb/message/internal/message.h" +#include "upb/message/internal/tagged_ptr.h" typedef union { bool bool_val; diff --git a/upb/mini_descriptor/BUILD b/upb/mini_descriptor/BUILD index b1932ead9872a..b1793c6bf7451 100644 --- a/upb/mini_descriptor/BUILD +++ b/upb/mini_descriptor/BUILD @@ -66,6 +66,7 @@ cc_test( "//upb:mini_table", "//upb:port", "//upb:wire", + "//upb/message:internal", "@com_google_absl//absl/container:flat_hash_set", "@com_google_googletest//:gtest", "@com_google_googletest//:gtest_main", diff --git a/upb/reflection/BUILD b/upb/reflection/BUILD index e42ebda23b43c..9bb1b648c56df 100644 --- a/upb/reflection/BUILD +++ b/upb/reflection/BUILD @@ -64,10 +64,10 @@ bootstrap_cc_library( "//upb:base", "//upb:mem", "//upb:message", - "//upb:message_value", "//upb:mini_descriptor", "//upb:mini_table", "//upb:port", + "//upb/message:internal", ], ) @@ -138,12 +138,12 @@ bootstrap_cc_library( "//upb:message", "//upb:message_accessors", "//upb:message_copy", - "//upb:message_value", "//upb:mini_descriptor", "//upb:mini_table", "//upb:port", "//upb:wire", "//upb/base:internal", + "//upb/message:internal", "//upb/mini_descriptor:internal", ], ) diff --git a/upb/reflection/field_def.c b/upb/reflection/field_def.c index 3b6089670d7d5..8f849a57bce80 100644 --- a/upb/reflection/field_def.c +++ b/upb/reflection/field_def.c @@ -19,7 +19,6 @@ #include "upb/base/upcast.h" #include "upb/mem/arena.h" #include "upb/message/accessors.h" -#include "upb/message/value.h" #include "upb/mini_descriptor/decode.h" #include "upb/mini_descriptor/internal/encode.h" #include "upb/mini_descriptor/internal/modifiers.h" diff --git a/upb/reflection/message.h b/upb/reflection/message.h index 54af6f15af3cc..d31f6b9b26015 100644 --- a/upb/reflection/message.h +++ b/upb/reflection/message.h @@ -13,7 +13,6 @@ #include "upb/mem/arena.h" #include "upb/message/map.h" #include "upb/message/message.h" -#include "upb/message/value.h" // IWYU pragma: export #include "upb/reflection/common.h" // Must be last. diff --git a/upb/text/BUILD b/upb/text/BUILD index 6a1a97c6eb17b..a9ba0db43692c 100644 --- a/upb/text/BUILD +++ b/upb/text/BUILD @@ -25,6 +25,7 @@ cc_library( "//upb:reflection", "//upb:wire", "//upb:wire_reader", + "//upb/message:internal", ], ) diff --git a/upb/wire/BUILD b/upb/wire/BUILD index fdfb223a9e76a..93be09bd9fee8 100644 --- a/upb/wire/BUILD +++ b/upb/wire/BUILD @@ -32,11 +32,10 @@ cc_library( "//upb:mem", "//upb:message", "//upb:message_accessors", - "//upb:message_tagged_ptr", - "//upb:message_types", "//upb:mini_table", "//upb:port", "//upb/mem:internal", + "//upb/message:internal", "//upb/mini_table:internal", ], ) diff --git a/upb/wire/decode.c b/upb/wire/decode.c index a0fd7c11b68ed..a80f65c11c9ea 100644 --- a/upb/wire/decode.c +++ b/upb/wire/decode.c @@ -24,6 +24,7 @@ #include "upb/message/internal/map.h" #include "upb/message/internal/map_entry.h" #include "upb/message/internal/message.h" +#include "upb/message/internal/tagged_ptr.h" #include "upb/message/map.h" #include "upb/message/message.h" #include "upb/message/tagged_ptr.h" @@ -32,6 +33,7 @@ #include "upb/mini_table/extension_registry.h" #include "upb/mini_table/field.h" #include "upb/mini_table/internal/field.h" +#include "upb/mini_table/internal/message.h" #include "upb/mini_table/internal/size_log2.h" #include "upb/mini_table/message.h" #include "upb/mini_table/sub.h" @@ -258,7 +260,8 @@ static upb_Message* _upb_Decoder_NewSubMessage(upb_Decoder* d, _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_UnlinkedSubMessage); } - upb_TaggedMessagePtr tagged = _upb_TaggedMessagePtr_Pack(msg, is_empty); + upb_TaggedMessagePtr tagged = + UPB_PRIVATE(_upb_TaggedMessagePtr_Pack)(msg, is_empty); memcpy(target, &tagged, sizeof(tagged)); return msg; } @@ -271,13 +274,14 @@ static upb_Message* _upb_Decoder_ReuseSubMessage( UPB_ASSERT(subl); if (!upb_TaggedMessagePtr_IsEmpty(tagged) || UPB_PRIVATE(_upb_MiniTable_IsEmpty)(subl)) { - return _upb_TaggedMessagePtr_GetMessage(tagged); + return UPB_PRIVATE(_upb_TaggedMessagePtr_GetMessage)(tagged); } // We found an empty message from a previous parse that was performed before // this field was linked. But it is linked now, so we want to allocate a new // message of the correct type and promote data into it before continuing. - upb_Message* existing = _upb_TaggedMessagePtr_GetEmptyMessage(tagged); + upb_Message* existing = + UPB_PRIVATE(_upb_TaggedMessagePtr_GetEmptyMessage)(tagged); upb_Message* promoted = _upb_Decoder_NewSubMessage(d, subs, field, target); size_t size; const char* unknown = upb_Message_GetUnknown(existing, &size); diff --git a/upb/wire/encode.c b/upb/wire/encode.c index 1d04ce6d975c2..5797e97ec1f70 100644 --- a/upb/wire/encode.c +++ b/upb/wire/encode.c @@ -26,12 +26,14 @@ #include "upb/message/internal/map.h" #include "upb/message/internal/map_entry.h" #include "upb/message/internal/map_sorter.h" +#include "upb/message/internal/tagged_ptr.h" #include "upb/message/map.h" #include "upb/message/message.h" #include "upb/message/tagged_ptr.h" #include "upb/mini_table/extension.h" #include "upb/mini_table/field.h" #include "upb/mini_table/internal/field.h" +#include "upb/mini_table/internal/message.h" #include "upb/mini_table/message.h" #include "upb/mini_table/sub.h" #include "upb/wire/internal/constants.h" @@ -217,7 +219,8 @@ static void encode_TaggedMessagePtr(upb_encstate* e, if (upb_TaggedMessagePtr_IsEmpty(tagged)) { m = UPB_PRIVATE(_upb_MiniTable_Empty)(); } - encode_message(e, _upb_TaggedMessagePtr_GetMessage(tagged), m, size); + encode_message(e, UPB_PRIVATE(_upb_TaggedMessagePtr_GetMessage)(tagged), m, + size); } static void encode_scalar(upb_encstate* e, const void* _field_mem, diff --git a/upb/wire/encode.h b/upb/wire/encode.h index 4c5969dee7b2c..fed261de516bf 100644 --- a/upb/wire/encode.h +++ b/upb/wire/encode.h @@ -14,7 +14,7 @@ #include #include "upb/mem/arena.h" -#include "upb/message/types.h" +#include "upb/message/message.h" #include "upb/mini_table/message.h" // Must be last. diff --git a/upb/wire/internal/decode_fast.c b/upb/wire/internal/decode_fast.c index 27d648ff80a7c..9837003f3f352 100644 --- a/upb/wire/internal/decode_fast.c +++ b/upb/wire/internal/decode_fast.c @@ -19,7 +19,6 @@ #include "upb/message/array.h" #include "upb/message/internal/array.h" -#include "upb/message/internal/types.h" #include "upb/mini_table/sub.h" #include "upb/wire/internal/decoder.h" From 499c748e39f59ae51c2a7b259689c611b33c1424 Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Sat, 30 Dec 2023 01:42:17 +0000 Subject: [PATCH 138/255] Auto-generate files after cl/594514934 --- php/ext/google/protobuf/php-upb.c | 217 +- php/ext/google/protobuf/php-upb.h | 2873 ++++++++++++------------- ruby/ext/google/protobuf_c/ruby-upb.c | 217 +- ruby/ext/google/protobuf_c/ruby-upb.h | 2873 ++++++++++++------------- upb/cmake/CMakeLists.txt | 3 +- 5 files changed, 3090 insertions(+), 3093 deletions(-) diff --git a/php/ext/google/protobuf/php-upb.c b/php/ext/google/protobuf/php-upb.c index e02c084a12bba..00db89189728e 100644 --- a/php/ext/google/protobuf/php-upb.c +++ b/php/ext/google/protobuf/php-upb.c @@ -6170,104 +6170,6 @@ const upb_Extension* upb_Message_FindExtensionByNumber(const upb_Message* msg, #include -// Must be last. - -const struct upb_Extension* _upb_Message_Getext( - const upb_Message* msg, const upb_MiniTableExtension* e) { - size_t n; - const struct upb_Extension* ext = UPB_PRIVATE(_upb_Message_Getexts)(msg, &n); - - // For now we use linear search exclusively to find extensions. - // If this becomes an issue due to messages with lots of extensions, - // we can introduce a table of some sort. - for (size_t i = 0; i < n; i++) { - if (ext[i].ext == e) { - return &ext[i]; - } - } - - return NULL; -} - -const struct upb_Extension* UPB_PRIVATE(_upb_Message_Getexts)( - const upb_Message* msg, size_t* count) { - const upb_Message_Internal* in = upb_Message_Getinternal(msg); - if (in->internal) { - *count = (in->internal->size - in->internal->ext_begin) / - sizeof(struct upb_Extension); - return UPB_PTR_AT(in->internal, in->internal->ext_begin, void); - } else { - *count = 0; - return NULL; - } -} - -struct upb_Extension* _upb_Message_GetOrCreateExtension( - upb_Message* msg, const upb_MiniTableExtension* e, upb_Arena* arena) { - struct upb_Extension* ext = - (struct upb_Extension*)_upb_Message_Getext(msg, e); - if (ext) return ext; - if (!UPB_PRIVATE(_upb_Message_Realloc)(msg, sizeof(struct upb_Extension), - arena)) - return NULL; - upb_Message_Internal* in = upb_Message_Getinternal(msg); - in->internal->ext_begin -= sizeof(struct upb_Extension); - ext = UPB_PTR_AT(in->internal, in->internal->ext_begin, void); - memset(ext, 0, sizeof(struct upb_Extension)); - ext->ext = e; - return ext; -} - - -#include -#include - - -// Must be last. - -const float kUpb_FltInfinity = INFINITY; -const double kUpb_Infinity = INFINITY; -const double kUpb_NaN = NAN; - -static const size_t realloc_overhead = sizeof(upb_Message_InternalData); - -bool UPB_PRIVATE(_upb_Message_Realloc)(struct upb_Message* msg, size_t need, - upb_Arena* arena) { - upb_Message_Internal* in = upb_Message_Getinternal(msg); - if (!in->internal) { - // No internal data, allocate from scratch. - size_t size = UPB_MAX(128, upb_Log2CeilingSize(need + realloc_overhead)); - upb_Message_InternalData* internal = upb_Arena_Malloc(arena, size); - if (!internal) return false; - internal->size = size; - internal->unknown_end = realloc_overhead; - internal->ext_begin = size; - in->internal = internal; - } else if (in->internal->ext_begin - in->internal->unknown_end < need) { - // Internal data is too small, reallocate. - size_t new_size = upb_Log2CeilingSize(in->internal->size + need); - size_t ext_bytes = in->internal->size - in->internal->ext_begin; - size_t new_ext_begin = new_size - ext_bytes; - upb_Message_InternalData* internal = - upb_Arena_Realloc(arena, in->internal, in->internal->size, new_size); - if (!internal) return false; - if (ext_bytes) { - // Need to move extension data to the end. - char* ptr = (char*)internal; - memmove(ptr + new_ext_begin, ptr + internal->ext_begin, ext_bytes); - } - internal->ext_begin = new_ext_begin; - internal->size = new_size; - in->internal = internal; - } - UPB_ASSERT(in->internal->ext_begin - in->internal->unknown_end >= need); - return true; -} - - -#include - - // Must be last. // Strings/bytes are special-cased in maps. @@ -6693,9 +6595,9 @@ static bool upb_Clone_MessageValue(void* value, upb_CType value_type, if (is_empty) sub = UPB_PRIVATE(_upb_MiniTable_Empty)(); UPB_ASSERT(source); upb_Message* clone = upb_Message_DeepClone( - _upb_TaggedMessagePtr_GetMessage(source), sub, arena); + UPB_PRIVATE(_upb_TaggedMessagePtr_GetMessage)(source), sub, arena); *(upb_TaggedMessagePtr*)value = - _upb_TaggedMessagePtr_Pack(clone, is_empty); + UPB_PRIVATE(_upb_TaggedMessagePtr_Pack)(clone, is_empty); return clone != NULL; } break; } @@ -6818,7 +6720,7 @@ upb_Message* _upb_Message_Copy(upb_Message* dst, const upb_Message* src, upb_TaggedMessagePtr tagged = upb_Message_GetTaggedMessagePtr(src, field, NULL); const upb_Message* sub_message = - _upb_TaggedMessagePtr_GetMessage(tagged); + UPB_PRIVATE(_upb_TaggedMessagePtr_GetMessage)(tagged); if (sub_message != NULL) { // If the message is currently in an unlinked, "empty" state we keep // it that way, because we don't want to deal with decode options, @@ -6834,7 +6736,8 @@ upb_Message* _upb_Message_Copy(upb_Message* dst, const upb_Message* src, } _upb_Message_SetTaggedMessagePtr( dst, mini_table, field, - _upb_TaggedMessagePtr_Pack(dst_sub_message, is_empty)); + UPB_PRIVATE(_upb_TaggedMessagePtr_Pack)(dst_sub_message, + is_empty)); } } break; case kUpb_CType_String: @@ -12801,7 +12704,8 @@ static upb_Message* _upb_Decoder_NewSubMessage(upb_Decoder* d, _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_UnlinkedSubMessage); } - upb_TaggedMessagePtr tagged = _upb_TaggedMessagePtr_Pack(msg, is_empty); + upb_TaggedMessagePtr tagged = + UPB_PRIVATE(_upb_TaggedMessagePtr_Pack)(msg, is_empty); memcpy(target, &tagged, sizeof(tagged)); return msg; } @@ -12814,13 +12718,14 @@ static upb_Message* _upb_Decoder_ReuseSubMessage( UPB_ASSERT(subl); if (!upb_TaggedMessagePtr_IsEmpty(tagged) || UPB_PRIVATE(_upb_MiniTable_IsEmpty)(subl)) { - return _upb_TaggedMessagePtr_GetMessage(tagged); + return UPB_PRIVATE(_upb_TaggedMessagePtr_GetMessage)(tagged); } // We found an empty message from a previous parse that was performed before // this field was linked. But it is linked now, so we want to allocate a new // message of the correct type and promote data into it before continuing. - upb_Message* existing = _upb_TaggedMessagePtr_GetEmptyMessage(tagged); + upb_Message* existing = + UPB_PRIVATE(_upb_TaggedMessagePtr_GetEmptyMessage)(tagged); upb_Message* promoted = _upb_Decoder_NewSubMessage(d, subs, field, target); size_t size; const char* unknown = upb_Message_GetUnknown(existing, &size); @@ -14113,7 +14018,8 @@ static void encode_TaggedMessagePtr(upb_encstate* e, if (upb_TaggedMessagePtr_IsEmpty(tagged)) { m = UPB_PRIVATE(_upb_MiniTable_Empty)(); } - encode_message(e, _upb_TaggedMessagePtr_GetMessage(tagged), m, size); + encode_message(e, UPB_PRIVATE(_upb_TaggedMessagePtr_GetMessage)(tagged), m, + size); } static void encode_scalar(upb_encstate* e, const void* _field_mem, @@ -15575,6 +15481,105 @@ const char* UPB_PRIVATE(_upb_WireReader_SkipGroup)( } +#include + + +// Must be last. + +const struct upb_Extension* _upb_Message_Getext( + const struct upb_Message* msg, const upb_MiniTableExtension* e) { + size_t n; + const struct upb_Extension* ext = UPB_PRIVATE(_upb_Message_Getexts)(msg, &n); + + // For now we use linear search exclusively to find extensions. + // If this becomes an issue due to messages with lots of extensions, + // we can introduce a table of some sort. + for (size_t i = 0; i < n; i++) { + if (ext[i].ext == e) { + return &ext[i]; + } + } + + return NULL; +} + +const struct upb_Extension* UPB_PRIVATE(_upb_Message_Getexts)( + const struct upb_Message* msg, size_t* count) { + const upb_Message_Internal* in = upb_Message_Getinternal(msg); + if (in->internal) { + *count = (in->internal->size - in->internal->ext_begin) / + sizeof(struct upb_Extension); + return UPB_PTR_AT(in->internal, in->internal->ext_begin, void); + } else { + *count = 0; + return NULL; + } +} + +struct upb_Extension* _upb_Message_GetOrCreateExtension( + struct upb_Message* msg, const upb_MiniTableExtension* e, + upb_Arena* arena) { + struct upb_Extension* ext = + (struct upb_Extension*)_upb_Message_Getext(msg, e); + if (ext) return ext; + if (!UPB_PRIVATE(_upb_Message_Realloc)(msg, sizeof(struct upb_Extension), + arena)) + return NULL; + upb_Message_Internal* in = upb_Message_Getinternal(msg); + in->internal->ext_begin -= sizeof(struct upb_Extension); + ext = UPB_PTR_AT(in->internal, in->internal->ext_begin, void); + memset(ext, 0, sizeof(struct upb_Extension)); + ext->ext = e; + return ext; +} + + +#include +#include + + +// Must be last. + +const float kUpb_FltInfinity = INFINITY; +const double kUpb_Infinity = INFINITY; +const double kUpb_NaN = NAN; + +static const size_t realloc_overhead = sizeof(upb_Message_InternalData); + +bool UPB_PRIVATE(_upb_Message_Realloc)(struct upb_Message* msg, size_t need, + upb_Arena* arena) { + upb_Message_Internal* in = upb_Message_Getinternal(msg); + if (!in->internal) { + // No internal data, allocate from scratch. + size_t size = UPB_MAX(128, upb_Log2CeilingSize(need + realloc_overhead)); + upb_Message_InternalData* internal = upb_Arena_Malloc(arena, size); + if (!internal) return false; + internal->size = size; + internal->unknown_end = realloc_overhead; + internal->ext_begin = size; + in->internal = internal; + } else if (in->internal->ext_begin - in->internal->unknown_end < need) { + // Internal data is too small, reallocate. + size_t new_size = upb_Log2CeilingSize(in->internal->size + need); + size_t ext_bytes = in->internal->size - in->internal->ext_begin; + size_t new_ext_begin = new_size - ext_bytes; + upb_Message_InternalData* internal = + upb_Arena_Realloc(arena, in->internal, in->internal->size, new_size); + if (!internal) return false; + if (ext_bytes) { + // Need to move extension data to the end. + char* ptr = (char*)internal; + memmove(ptr + new_ext_begin, ptr + internal->ext_begin, ext_bytes); + } + internal->ext_begin = new_ext_begin; + internal->size = new_size; + in->internal = internal; + } + UPB_ASSERT(in->internal->ext_begin - in->internal->unknown_end >= need); + return true; +} + + const char _kUpb_ToBase92[] = { ' ', '!', '#', '$', '%', '&', '(', ')', '*', '+', ',', '-', '.', '/', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '<', '=', diff --git a/php/ext/google/protobuf/php-upb.h b/php/ext/google/protobuf/php-upb.h index be65077a21960..5944824f2096a 100644 --- a/php/ext/google/protobuf/php-upb.h +++ b/php/ext/google/protobuf/php-upb.h @@ -825,678 +825,667 @@ UPB_API_INLINE void upb_Arena_ShrinkLast(upb_Arena* a, void* ptr, #include -#ifndef UPB_MINI_TABLE_TAGGED_PTR_H_ -#define UPB_MINI_TABLE_TAGGED_PTR_H_ - -#include - - -#ifndef UPB_MESSAGE_TYPES_H_ -#define UPB_MESSAGE_TYPES_H_ +#ifndef UPB_MESSAGE_INTERNAL_ARRAY_H_ +#define UPB_MESSAGE_INTERNAL_ARRAY_H_ -// This typedef is in a leaf header to resolve a circular dependency between -// messages and mini tables. -typedef struct upb_Message { - int unused; // Placeholder cuz Windows won't compile an empty struct. -} upb_Message; +#include -#endif /* UPB_MESSAGE_TYPES_H_ */ // Must be last. -// 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 -// that field's true message type. This forms the basis of what we call -// "dynamic tree shaking." -// -// See the documentation for kUpb_DecodeOption_ExperimentalAllowUnlinked for -// more information. - -typedef uintptr_t upb_TaggedMessagePtr; +#define _UPB_ARRAY_MASK_IMM 0x4 // Frozen/immutable bit. +#define _UPB_ARRAY_MASK_LG2 0x3 // Encoded elem size. +#define _UPB_ARRAY_MASK_ALL (_UPB_ARRAY_MASK_IMM | _UPB_ARRAY_MASK_LG2) #ifdef __cplusplus extern "C" { #endif -// Internal-only because empty messages cannot be created by the user. -UPB_INLINE upb_TaggedMessagePtr _upb_TaggedMessagePtr_Pack(upb_Message* ptr, - bool empty) { - UPB_ASSERT(((uintptr_t)ptr & 1) == 0); - return (uintptr_t)ptr | (empty ? 1 : 0); -} +// LINT.IfChange(struct_definition) +// Our internal representation for repeated fields. +struct upb_Array { + // This is a tagged pointer. Bits #0 and #1 encode the elem size as follows: + // 0 maps to elem size 1 + // 1 maps to elem size 4 + // 2 maps to elem size 8 + // 3 maps to elem size 16 + // + // Bit #2 contains the frozen/immutable flag (currently unimplemented). + uintptr_t data; -// Users who enable unlinked sub-messages must use this to test whether a -// message is empty before accessing it. If a message is empty, it must be -// first promoted using the interfaces in message/promote.h. -UPB_INLINE bool upb_TaggedMessagePtr_IsEmpty(upb_TaggedMessagePtr ptr) { - return ptr & 1; -} + size_t UPB_ONLYBITS(size); // The number of elements in the array. + size_t UPB_PRIVATE(capacity); // Allocated storage. Measured in elements. +}; -UPB_INLINE upb_Message* _upb_TaggedMessagePtr_GetMessage( - upb_TaggedMessagePtr ptr) { - return (upb_Message*)(ptr & ~(uintptr_t)1); +UPB_INLINE void UPB_PRIVATE(_upb_Array_SetTaggedPtr)(struct upb_Array* array, + void* data, size_t lg2) { + UPB_ASSERT(lg2 != 1); + UPB_ASSERT(lg2 <= 4); + const size_t bits = lg2 - (lg2 != 0); + array->data = (uintptr_t)data | bits; } -UPB_INLINE upb_Message* upb_TaggedMessagePtr_GetNonEmptyMessage( - upb_TaggedMessagePtr ptr) { - UPB_ASSERT(!upb_TaggedMessagePtr_IsEmpty(ptr)); - return _upb_TaggedMessagePtr_GetMessage(ptr); +UPB_INLINE size_t +UPB_PRIVATE(_upb_Array_ElemSizeLg2)(const struct upb_Array* array) { + const size_t bits = array->data & _UPB_ARRAY_MASK_LG2; + const size_t lg2 = bits + (bits != 0); + return lg2; } -UPB_INLINE upb_Message* _upb_TaggedMessagePtr_GetEmptyMessage( - upb_TaggedMessagePtr ptr) { - UPB_ASSERT(upb_TaggedMessagePtr_IsEmpty(ptr)); - return _upb_TaggedMessagePtr_GetMessage(ptr); +UPB_INLINE const void* _upb_array_constptr(const struct upb_Array* array) { + UPB_PRIVATE(_upb_Array_ElemSizeLg2)(array); // Check assertions. + return (void*)(array->data & ~(uintptr_t)_UPB_ARRAY_MASK_ALL); } -#ifdef __cplusplus -} /* extern "C" */ -#endif - - -#endif /* UPB_MINI_TABLE_TAGGED_PTR_H_ */ - -typedef union { - bool bool_val; - float float_val; - double double_val; - int32_t int32_val; - int64_t int64_val; - uint32_t uint32_val; - uint64_t uint64_val; - const struct upb_Array* array_val; - const struct upb_Map* map_val; - const struct upb_Message* msg_val; - upb_StringView str_val; - - // EXPERIMENTAL: A tagged upb_Message*. Users must use this instead of - // msg_val if unlinked sub-messages may possibly be in use. See the - // documentation in kUpb_DecodeOption_ExperimentalAllowUnlinked for more - // information. - upb_TaggedMessagePtr tagged_msg_val; -} upb_MessageValue; - -typedef union { - struct upb_Array* array; - struct upb_Map* map; - struct upb_Message* msg; -} upb_MutableMessageValue; - -#endif /* UPB_MESSAGE_VALUE_H_ */ - -// Must be last. - -typedef struct upb_Array upb_Array; - -#ifdef __cplusplus -extern "C" { -#endif - -// Creates a new array on the given arena that holds elements of this type. -UPB_API upb_Array* upb_Array_New(upb_Arena* a, upb_CType type); - -// Returns the number of elements in the array. -UPB_API size_t upb_Array_Size(const upb_Array* arr); - -// Returns the given element, which must be within the array's current size. -UPB_API upb_MessageValue upb_Array_Get(const upb_Array* arr, size_t i); - -// Sets the given element, which must be within the array's current size. -UPB_API void upb_Array_Set(upb_Array* arr, size_t i, upb_MessageValue val); - -// Appends an element to the array. Returns false on allocation failure. -UPB_API bool upb_Array_Append(upb_Array* array, upb_MessageValue val, - upb_Arena* arena); +UPB_INLINE void* _upb_array_ptr(struct upb_Array* array) { + return (void*)_upb_array_constptr(array); +} -// Moves elements within the array using memmove(). -// Like memmove(), the source and destination elements may be overlapping. -UPB_API void upb_Array_Move(upb_Array* array, size_t dst_idx, size_t src_idx, - size_t count); +UPB_INLINE struct upb_Array* UPB_PRIVATE(_upb_Array_New)(upb_Arena* arena, + size_t init_capacity, + int elem_size_lg2) { + UPB_ASSERT(elem_size_lg2 != 1); + UPB_ASSERT(elem_size_lg2 <= 4); + const size_t array_size = + UPB_ALIGN_UP(sizeof(struct upb_Array), UPB_MALLOC_ALIGN); + const size_t bytes = array_size + (init_capacity << elem_size_lg2); + struct upb_Array* array = (struct upb_Array*)upb_Arena_Malloc(arena, bytes); + if (!array) return NULL; + UPB_PRIVATE(_upb_Array_SetTaggedPtr) + (array, UPB_PTR_AT(array, array_size, void), elem_size_lg2); + array->UPB_ONLYBITS(size) = 0; + array->UPB_PRIVATE(capacity) = init_capacity; + return array; +} -// Inserts one or more empty elements into the array. -// Existing elements are shifted right. -// The new elements have undefined state and must be set with `upb_Array_Set()`. -// REQUIRES: `i <= upb_Array_Size(arr)` -UPB_API bool upb_Array_Insert(upb_Array* array, size_t i, size_t count, - upb_Arena* arena); +// Resizes the capacity of the array to be at least min_size. +bool UPB_PRIVATE(_upb_Array_Realloc)(struct upb_Array* array, size_t min_size, + upb_Arena* arena); -// Deletes one or more elements from the array. -// Existing elements are shifted left. -// REQUIRES: `i + count <= upb_Array_Size(arr)` -UPB_API void upb_Array_Delete(upb_Array* array, size_t i, size_t count); +UPB_INLINE bool UPB_PRIVATE(_upb_Array_Reserve)(struct upb_Array* array, + size_t size, upb_Arena* arena) { + if (array->UPB_PRIVATE(capacity) < size) + return UPB_PRIVATE(_upb_Array_Realloc)(array, size, arena); + return true; +} -// Changes the size of a vector. New elements are initialized to NULL/0. -// Returns false on allocation failure. -UPB_API bool upb_Array_Resize(upb_Array* array, size_t size, upb_Arena* arena); +// Resize without initializing new elements. +UPB_INLINE bool _upb_Array_ResizeUninitialized(struct upb_Array* array, + size_t size, upb_Arena* arena) { + UPB_ASSERT(size <= array->UPB_ONLYBITS(size) || + arena); // Allow NULL arena when shrinking. + if (!UPB_PRIVATE(_upb_Array_Reserve)(array, size, arena)) return false; + array->UPB_ONLYBITS(size) = size; + return true; +} -// Returns pointer to array data. -UPB_API const void* upb_Array_DataPtr(const upb_Array* arr); +// This function is intended for situations where elem_size is compile-time +// constant or a known expression of the form (1 << lg2), so that the expression +// i*elem_size does not result in an actual multiplication. +UPB_INLINE void UPB_PRIVATE(_upb_Array_Set)(struct upb_Array* array, size_t i, + const void* data, + size_t elem_size) { + UPB_ASSERT(i < array->UPB_ONLYBITS(size)); + UPB_ASSERT(elem_size == 1U << UPB_PRIVATE(_upb_Array_ElemSizeLg2)(array)); + char* arr_data = (char*)_upb_array_ptr(array); + memcpy(arr_data + (i * elem_size), data, elem_size); +} -// Returns mutable pointer to array data. -UPB_API void* upb_Array_MutableDataPtr(upb_Array* arr); +// LINT.ThenChange( +// GoogleInternalName1, +//) #ifdef __cplusplus } /* extern "C" */ #endif +#undef _UPB_ARRAY_MASK_IMM +#undef _UPB_ARRAY_MASK_LG2 +#undef _UPB_ARRAY_MASK_ALL -#endif /* UPB_MESSAGE_ARRAY_H_ */ -#ifndef UPB_MESSAGE_INTERNAL_ACCESSORS_H_ -#define UPB_MESSAGE_INTERNAL_ACCESSORS_H_ +#endif /* UPB_MESSAGE_INTERNAL_ARRAY_H_ */ + +#ifndef UPB_MESSAGE_INTERNAL_MAP_H_ +#define UPB_MESSAGE_INTERNAL_MAP_H_ #include -#include #include -#ifndef UPB_MESSAGE_INTERNAL_EXTENSION_H_ -#define UPB_MESSAGE_INTERNAL_EXTENSION_H_ +#ifndef UPB_HASH_STR_TABLE_H_ +#define UPB_HASH_STR_TABLE_H_ /* -** Our memory representation for parsing tables and messages themselves. -** Functions in this file are used by generated code and possibly reflection. -** -** The definitions in this file are internal to upb. -**/ + * upb_table + * + * This header is INTERNAL-ONLY! Its interfaces are not public or stable! + * This file defines very fast int->upb_value (inttable) and string->upb_value + * (strtable) hash tables. + * + * The table uses chained scatter with Brent's variation (inspired by the Lua + * implementation of hash tables). The hash function for strings is Austin + * Appleby's "MurmurHash." + * + * The inttable uses uintptr_t as its key, which guarantees it can be used to + * store pointers or integers of at least 32 bits (upb isn't really useful on + * systems where sizeof(void*) < 4). + * + * The table must be homogeneous (all values of the same type). In debug + * mode, we check this on insert and lookup. + */ -#ifndef UPB_MESSAGE_INTERNAL_H_ -#define UPB_MESSAGE_INTERNAL_H_ +#ifndef UPB_HASH_COMMON_H_ +#define UPB_HASH_COMMON_H_ -#include #include -#ifndef UPB_MINI_TABLE_INTERNAL_TYPES_H_ -#define UPB_MINI_TABLE_INTERNAL_TYPES_H_ - -typedef struct upb_Message_InternalData upb_Message_InternalData; - -typedef struct { - union { - upb_Message_InternalData* internal; - - // Force 8-byte alignment, since the data members may contain members that - // require 8-byte alignment. - double d; - }; -} upb_Message_Internal; +// Must be last. -#endif // UPB_MINI_TABLE_INTERNAL_TYPES_H_ +#ifdef __cplusplus +extern "C" { +#endif -#ifndef UPB_MINI_TABLE_MESSAGE_H_ -#define UPB_MINI_TABLE_MESSAGE_H_ +/* upb_value ******************************************************************/ +typedef struct { + uint64_t val; +} upb_value; -#ifndef UPB_MINI_TABLE_ENUM_H_ -#define UPB_MINI_TABLE_ENUM_H_ +UPB_INLINE void _upb_value_setval(upb_value* v, uint64_t val) { v->val = val; } -#include - - -#ifndef UPB_MINI_TABLE_INTERNAL_ENUM_H_ -#define UPB_MINI_TABLE_INTERNAL_ENUM_H_ - -#include - -// Must be last. - -struct upb_MiniTableEnum { - uint32_t UPB_PRIVATE(mask_limit); // Highest that can be tested with mask. - uint32_t UPB_PRIVATE(value_count); // Number of values after the bitfield. - uint32_t UPB_PRIVATE(data)[]; // Bitmask + enumerated values follow. -}; - -#ifdef __cplusplus -extern "C" { -#endif - -UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableEnum_CheckValue)( - const struct upb_MiniTableEnum* e, uint32_t val) { - if (UPB_LIKELY(val < 64)) { - const uint64_t mask = - e->UPB_PRIVATE(data)[0] | ((uint64_t)e->UPB_PRIVATE(data)[1] << 32); - const uint64_t bit = 1ULL << val; - return (mask & bit) != 0; - } - if (UPB_LIKELY(val < e->UPB_PRIVATE(mask_limit))) { - const uint32_t mask = e->UPB_PRIVATE(data)[val / 32]; - const uint32_t bit = 1ULL << (val % 32); - return (mask & bit) != 0; - } - - // OPT: binary search long lists? - const uint32_t* start = - &e->UPB_PRIVATE(data)[e->UPB_PRIVATE(mask_limit) / 32]; - const uint32_t* limit = &e->UPB_PRIVATE( - data)[e->UPB_PRIVATE(mask_limit) / 32 + e->UPB_PRIVATE(value_count)]; - for (const uint32_t* p = start; p < limit; p++) { - if (*p == val) return true; +/* For each value ctype, define the following set of functions: + * + * // Get/set an int32 from a upb_value. + * int32_t upb_value_getint32(upb_value val); + * void upb_value_setint32(upb_value *val, int32_t cval); + * + * // Construct a new upb_value from an int32. + * upb_value upb_value_int32(int32_t val); */ +#define FUNCS(name, membername, type_t, converter) \ + UPB_INLINE void upb_value_set##name(upb_value* val, type_t cval) { \ + val->val = (converter)cval; \ + } \ + UPB_INLINE upb_value upb_value_##name(type_t val) { \ + upb_value ret; \ + upb_value_set##name(&ret, val); \ + return ret; \ + } \ + UPB_INLINE type_t upb_value_get##name(upb_value val) { \ + return (type_t)(converter)val.val; \ } - return false; -} -#ifdef __cplusplus -} /* extern "C" */ -#endif - - -#endif /* UPB_MINI_TABLE_INTERNAL_ENUM_H_ */ - -// Must be last - -typedef struct upb_MiniTableEnum upb_MiniTableEnum; +FUNCS(int32, int32, int32_t, int32_t) +FUNCS(int64, int64, int64_t, int64_t) +FUNCS(uint32, uint32, uint32_t, uint32_t) +FUNCS(uint64, uint64, uint64_t, uint64_t) +FUNCS(bool, _bool, bool, bool) +FUNCS(cstr, cstr, char*, uintptr_t) +FUNCS(uintptr, uptr, uintptr_t, uintptr_t) +FUNCS(ptr, ptr, void*, uintptr_t) +FUNCS(constptr, constptr, const void*, uintptr_t) -#ifdef __cplusplus -extern "C" { -#endif +#undef FUNCS -// Validates enum value against range defined by enum mini table. -UPB_INLINE bool upb_MiniTableEnum_CheckValue(const upb_MiniTableEnum* e, - uint32_t val) { - return UPB_PRIVATE(_upb_MiniTableEnum_CheckValue)(e, val); +UPB_INLINE void upb_value_setfloat(upb_value* val, float cval) { + memcpy(&val->val, &cval, sizeof(cval)); } -#ifdef __cplusplus -} /* extern "C" */ -#endif - +UPB_INLINE void upb_value_setdouble(upb_value* val, double cval) { + memcpy(&val->val, &cval, sizeof(cval)); +} -#endif /* UPB_MINI_TABLE_ENUM_H_ */ +UPB_INLINE upb_value upb_value_float(float cval) { + upb_value ret; + upb_value_setfloat(&ret, cval); + return ret; +} -#ifndef UPB_MINI_TABLE_FIELD_H_ -#define UPB_MINI_TABLE_FIELD_H_ +UPB_INLINE upb_value upb_value_double(double cval) { + upb_value ret; + upb_value_setdouble(&ret, cval); + return ret; +} -#include +/* upb_tabkey *****************************************************************/ +/* Either: + * 1. an actual integer key, or + * 2. a pointer to a string prefixed by its uint32_t length, owned by us. + * + * ...depending on whether this is a string table or an int table. We would + * make this a union of those two types, but C89 doesn't support statically + * initializing a non-first union member. */ +typedef uintptr_t upb_tabkey; -#ifndef UPB_MINI_TABLE_INTERNAL_FIELD_H_ -#define UPB_MINI_TABLE_INTERNAL_FIELD_H_ +UPB_INLINE char* upb_tabstr(upb_tabkey key, uint32_t* len) { + char* mem = (char*)key; + if (len) memcpy(len, mem, sizeof(*len)); + return mem + sizeof(*len); +} -#include -#include +UPB_INLINE upb_StringView upb_tabstrview(upb_tabkey key) { + upb_StringView ret; + uint32_t len; + ret.data = upb_tabstr(key, &len); + ret.size = len; + return ret; +} +/* upb_tabval *****************************************************************/ -#ifndef UPB_MINI_TABLE_INTERNAL_SIZE_LOG2_H_ -#define UPB_MINI_TABLE_INTERNAL_SIZE_LOG2_H_ +typedef struct upb_tabval { + uint64_t val; +} upb_tabval; -#include -#include +#define UPB_TABVALUE_EMPTY_INIT \ + { -1 } +/* upb_table ******************************************************************/ -// Must be last. +typedef struct _upb_tabent { + upb_tabkey key; + upb_tabval val; -#ifdef __cplusplus -extern "C" { -#endif + /* Internal chaining. This is const so we can create static initializers for + * tables. We cast away const sometimes, but *only* when the containing + * upb_table is known to be non-const. This requires a bit of care, but + * the subtlety is confined to table.c. */ + const struct _upb_tabent* next; +} upb_tabent; -// Return the log2 of the storage size in bytes for a upb_CType -UPB_INLINE int UPB_PRIVATE(_upb_CType_SizeLg2)(upb_CType c_type) { - static const int8_t size[] = { - 0, // kUpb_CType_Bool - 2, // kUpb_CType_Float - 2, // kUpb_CType_Int32 - 2, // kUpb_CType_UInt32 - 2, // kUpb_CType_Enum - UPB_SIZE(2, 3), // kUpb_CType_Message - 3, // kUpb_CType_Double - 3, // kUpb_CType_Int64 - 3, // kUpb_CType_UInt64 - UPB_SIZE(3, 4), // kUpb_CType_String - UPB_SIZE(3, 4), // kUpb_CType_Bytes - }; +typedef struct { + size_t count; /* Number of entries in the hash part. */ + uint32_t mask; /* Mask to turn hash value -> bucket. */ + uint32_t max_count; /* Max count before we hit our load limit. */ + uint8_t size_lg2; /* Size of the hashtable part is 2^size_lg2 entries. */ + upb_tabent* entries; +} upb_table; - // -1 here because the enum is one-based but the table is zero-based. - return size[c_type - 1]; +UPB_INLINE size_t upb_table_size(const upb_table* t) { + return t->size_lg2 ? 1 << t->size_lg2 : 0; } -// Return the log2 of the storage size in bytes for a upb_FieldType -UPB_INLINE int UPB_PRIVATE(_upb_FieldType_SizeLg2)(upb_FieldType field_type) { - static const int8_t size[] = { - 3, // kUpb_FieldType_Double - 2, // kUpb_FieldType_Float - 3, // kUpb_FieldType_Int64 - 3, // kUpb_FieldType_UInt64 - 2, // kUpb_FieldType_Int32 - 3, // kUpb_FieldType_Fixed64 - 2, // kUpb_FieldType_Fixed32 - 0, // kUpb_FieldType_Bool - UPB_SIZE(3, 4), // kUpb_FieldType_String - UPB_SIZE(2, 3), // kUpb_FieldType_Group - UPB_SIZE(2, 3), // kUpb_FieldType_Message - UPB_SIZE(3, 4), // kUpb_FieldType_Bytes - 2, // kUpb_FieldType_UInt32 - 2, // kUpb_FieldType_Enum - 2, // kUpb_FieldType_SFixed32 - 3, // kUpb_FieldType_SFixed64 - 2, // kUpb_FieldType_SInt32 - 3, // kUpb_FieldType_SInt64 - }; +// Internal-only functions, in .h file only out of necessity. - // -1 here because the enum is one-based but the table is zero-based. - return size[field_type - 1]; -} +UPB_INLINE bool upb_tabent_isempty(const upb_tabent* e) { return e->key == 0; } + +uint32_t _upb_Hash(const void* p, size_t n, uint64_t seed); #ifdef __cplusplus } /* extern "C" */ #endif -#endif /* UPB_MINI_TABLE_INTERNAL_SIZE_LOG2_H_ */ +#endif /* UPB_HASH_COMMON_H_ */ // Must be last. -// LINT.IfChange(struct_definition) -struct upb_MiniTableField { - uint32_t UPB_ONLYBITS(number); - uint16_t UPB_ONLYBITS(offset); - int16_t presence; // If >0, hasbit_index. If <0, ~oneof_index - - // Indexes into `upb_MiniTable.subs` - // Will be set to `kUpb_NoSub` if `descriptortype` != MESSAGE/GROUP/ENUM - uint16_t UPB_PRIVATE(submsg_index); - - uint8_t UPB_PRIVATE(descriptortype); - - // upb_FieldMode | upb_LabelFlags | (upb_FieldRep << kUpb_FieldRep_Shift) - uint8_t UPB_ONLYBITS(mode); -}; - -#define kUpb_NoSub ((uint16_t)-1) - -typedef enum { - kUpb_FieldMode_Map = 0, - kUpb_FieldMode_Array = 1, - kUpb_FieldMode_Scalar = 2, -} upb_FieldMode; - -// Mask to isolate the upb_FieldMode from field.mode. -#define kUpb_FieldMode_Mask 3 - -// Extra flags on the mode field. -typedef enum { - kUpb_LabelFlags_IsPacked = 4, - kUpb_LabelFlags_IsExtension = 8, - // Indicates that this descriptor type is an "alternate type": - // - for Int32, this indicates that the actual type is Enum (but was - // rewritten to Int32 because it is an open enum that requires no check). - // - for Bytes, this indicates that the actual type is String (but does - // not require any UTF-8 check). - kUpb_LabelFlags_IsAlternate = 16, -} upb_LabelFlags; - -// Note: we sort by this number when calculating layout order. -typedef enum { - kUpb_FieldRep_1Byte = 0, - kUpb_FieldRep_4Byte = 1, - kUpb_FieldRep_StringView = 2, - kUpb_FieldRep_8Byte = 3, - - kUpb_FieldRep_NativePointer = - UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte), - kUpb_FieldRep_Max = kUpb_FieldRep_8Byte, -} upb_FieldRep; - -#define kUpb_FieldRep_Shift 6 +typedef struct { + upb_table t; +} upb_strtable; #ifdef __cplusplus extern "C" { #endif -UPB_INLINE upb_FieldMode -UPB_PRIVATE(_upb_MiniTableField_Mode)(const struct upb_MiniTableField* f) { - return (upb_FieldMode)(f->UPB_ONLYBITS(mode) & kUpb_FieldMode_Mask); -} - -UPB_INLINE upb_FieldRep -UPB_PRIVATE(_upb_MiniTableField_GetRep)(const struct upb_MiniTableField* f) { - return (upb_FieldRep)(f->UPB_ONLYBITS(mode) >> kUpb_FieldRep_Shift); -} - -UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsArray)( - const struct upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTableField_Mode)(f) == kUpb_FieldMode_Array; -} - -UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsMap)( - const struct upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTableField_Mode)(f) == kUpb_FieldMode_Map; -} - -UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsScalar)( - const struct upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTableField_Mode)(f) == kUpb_FieldMode_Scalar; -} - -UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsAlternate)( - const struct upb_MiniTableField* f) { - return (f->UPB_ONLYBITS(mode) & kUpb_LabelFlags_IsAlternate) != 0; -} - -UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsExtension)( - const struct upb_MiniTableField* f) { - return (f->UPB_ONLYBITS(mode) & kUpb_LabelFlags_IsExtension) != 0; -} - -UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsPacked)( - const struct upb_MiniTableField* f) { - return (f->UPB_ONLYBITS(mode) & kUpb_LabelFlags_IsPacked) != 0; -} +// Initialize a table. If memory allocation failed, false is returned and +// the table is uninitialized. +bool upb_strtable_init(upb_strtable* table, size_t expected_size, upb_Arena* a); -UPB_INLINE upb_FieldType -UPB_PRIVATE(_upb_MiniTableField_Type)(const struct upb_MiniTableField* f) { - const upb_FieldType type = (upb_FieldType)f->UPB_PRIVATE(descriptortype); - if (UPB_PRIVATE(_upb_MiniTableField_IsAlternate)(f)) { - if (type == kUpb_FieldType_Int32) return kUpb_FieldType_Enum; - if (type == kUpb_FieldType_Bytes) return kUpb_FieldType_String; - UPB_ASSERT(false); - } - return type; +// Returns the number of values in the table. +UPB_INLINE size_t upb_strtable_count(const upb_strtable* t) { + return t->t.count; } -UPB_INLINE upb_CType -UPB_PRIVATE(_upb_MiniTableField_CType)(const struct upb_MiniTableField* f) { - return upb_FieldType_CType(UPB_PRIVATE(_upb_MiniTableField_Type)(f)); -} +void upb_strtable_clear(upb_strtable* t); -UPB_INLINE char UPB_PRIVATE(_upb_MiniTableField_HasbitMask)( - const struct upb_MiniTableField* f) { - UPB_ASSERT(f->presence > 0); - const size_t index = f->presence; - return 1 << (index % 8); -} +// Inserts the given key into the hashtable with the given value. +// The key must not already exist in the hash table. The key is not required +// to be NULL-terminated, and the table will make an internal copy of the key. +// +// If a table resize was required but memory allocation failed, false is +// returned and the table is unchanged. */ +bool upb_strtable_insert(upb_strtable* t, const char* key, size_t len, + upb_value val, upb_Arena* a); -UPB_INLINE size_t UPB_PRIVATE(_upb_MiniTableField_HasbitOffset)( - const struct upb_MiniTableField* f) { - UPB_ASSERT(f->presence > 0); - const size_t index = f->presence; - return index / 8; -} +// Looks up key in this table, returning "true" if the key was found. +// If v is non-NULL, copies the value for this key into *v. +bool upb_strtable_lookup2(const upb_strtable* t, const char* key, size_t len, + upb_value* v); -UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsClosedEnum)( - const struct upb_MiniTableField* f) { - return f->UPB_PRIVATE(descriptortype) == kUpb_FieldType_Enum; +// For NULL-terminated strings. +UPB_INLINE bool upb_strtable_lookup(const upb_strtable* t, const char* key, + upb_value* v) { + return upb_strtable_lookup2(t, key, strlen(key), v); } -UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsInOneof)( - const struct upb_MiniTableField* f) { - return f->presence < 0; -} +// Removes an item from the table. Returns true if the remove was successful, +// and stores the removed item in *val if non-NULL. +bool upb_strtable_remove2(upb_strtable* t, const char* key, size_t len, + upb_value* val); -UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsSubMessage)( - const struct upb_MiniTableField* f) { - return f->UPB_PRIVATE(descriptortype) == kUpb_FieldType_Message || - f->UPB_PRIVATE(descriptortype) == kUpb_FieldType_Group; +UPB_INLINE bool upb_strtable_remove(upb_strtable* t, const char* key, + upb_value* v) { + return upb_strtable_remove2(t, key, strlen(key), v); } -UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_HasPresence)( - const struct upb_MiniTableField* f) { - if (UPB_PRIVATE(_upb_MiniTableField_IsExtension)(f)) { - return UPB_PRIVATE(_upb_MiniTableField_IsScalar)(f); - } else { - return f->presence != 0; - } -} +// Exposed for testing only. +bool upb_strtable_resize(upb_strtable* t, size_t size_lg2, upb_Arena* a); -UPB_INLINE uint32_t -UPB_PRIVATE(_upb_MiniTableField_Number)(const struct upb_MiniTableField* f) { - return f->UPB_ONLYBITS(number); -} +/* Iteration over strtable: + * + * intptr_t iter = UPB_STRTABLE_BEGIN; + * upb_StringView key; + * upb_value val; + * while (upb_strtable_next2(t, &key, &val, &iter)) { + * // ... + * } + */ -UPB_INLINE uint16_t -UPB_PRIVATE(_upb_MiniTableField_Offset)(const struct upb_MiniTableField* f) { - return f->UPB_ONLYBITS(offset); -} +#define UPB_STRTABLE_BEGIN -1 -UPB_INLINE size_t UPB_PRIVATE(_upb_MiniTableField_OneofOffset)( - const struct upb_MiniTableField* f) { - UPB_ASSERT(UPB_PRIVATE(_upb_MiniTableField_IsInOneof)(f)); - return ~(ptrdiff_t)f->presence; -} +bool upb_strtable_next2(const upb_strtable* t, upb_StringView* key, + upb_value* val, intptr_t* iter); +void upb_strtable_removeiter(upb_strtable* t, intptr_t* iter); +void upb_strtable_setentryvalue(upb_strtable* t, intptr_t iter, upb_value v); -UPB_INLINE void UPB_PRIVATE(_upb_MiniTableField_CheckIsArray)( - const struct upb_MiniTableField* f) { - UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == - kUpb_FieldRep_NativePointer); - UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_IsArray)(f)); - UPB_ASSUME(f->presence == 0); -} +/* DEPRECATED iterators, slated for removal. + * + * Iterators for string tables. We are subject to some kind of unusual + * design constraints: + * + * For high-level languages: + * - we must be able to guarantee that we don't crash or corrupt memory even if + * the program accesses an invalidated iterator. + * + * For C++11 range-based for: + * - iterators must be copyable + * - iterators must be comparable + * - it must be possible to construct an "end" value. + * + * Iteration order is undefined. + * + * Modifying the table invalidates iterators. upb_{str,int}table_done() is + * guaranteed to work even on an invalidated iterator, as long as the table it + * is iterating over has not been freed. Calling next() or accessing data from + * an invalidated iterator yields unspecified elements from the table, but it is + * guaranteed not to crash and to return real table elements (except when done() + * is true). */ +/* upb_strtable_iter **********************************************************/ -UPB_INLINE void UPB_PRIVATE(_upb_MiniTableField_CheckIsMap)( - const struct upb_MiniTableField* f) { - UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == - kUpb_FieldRep_NativePointer); - UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_IsMap)(f)); - UPB_ASSUME(f->presence == 0); -} +/* upb_strtable_iter i; + * upb_strtable_begin(&i, t); + * for(; !upb_strtable_done(&i); upb_strtable_next(&i)) { + * const char *key = upb_strtable_iter_key(&i); + * const upb_value val = upb_strtable_iter_value(&i); + * // ... + * } + */ -UPB_INLINE size_t UPB_PRIVATE(_upb_MiniTableField_ElemSizeLg2)( - const struct upb_MiniTableField* f) { - const upb_FieldType field_type = UPB_PRIVATE(_upb_MiniTableField_Type)(f); - return UPB_PRIVATE(_upb_FieldType_SizeLg2)(field_type); +typedef struct { + const upb_strtable* t; + size_t index; +} upb_strtable_iter; + +UPB_INLINE const upb_tabent* str_tabent(const upb_strtable_iter* i) { + return &i->t->t.entries[i->index]; } -// LINT.ThenChange(//depot/google3/third_party/upb/bits/typescript/mini_table_field.ts) +void upb_strtable_begin(upb_strtable_iter* i, const upb_strtable* t); +void upb_strtable_next(upb_strtable_iter* i); +bool upb_strtable_done(const upb_strtable_iter* i); +upb_StringView upb_strtable_iter_key(const upb_strtable_iter* i); +upb_value upb_strtable_iter_value(const upb_strtable_iter* i); +void upb_strtable_iter_setdone(upb_strtable_iter* i); +bool upb_strtable_iter_isequal(const upb_strtable_iter* i1, + const upb_strtable_iter* i2); #ifdef __cplusplus } /* extern "C" */ #endif -#endif /* UPB_MINI_TABLE_INTERNAL_FIELD_H_ */ +#endif /* UPB_HASH_STR_TABLE_H_ */ // Must be last. -typedef struct upb_MiniTableField upb_MiniTableField; +typedef enum { + kUpb_MapInsertStatus_Inserted = 0, + kUpb_MapInsertStatus_Replaced = 1, + kUpb_MapInsertStatus_OutOfMemory = 2, +} upb_MapInsertStatus; + +// EVERYTHING BELOW THIS LINE IS INTERNAL - DO NOT USE ///////////////////////// + +struct upb_Map { + // Size of key and val, based on the map type. + // Strings are represented as '0' because they must be handled specially. + char key_size; + char val_size; + + upb_strtable table; +}; #ifdef __cplusplus extern "C" { #endif -UPB_API_INLINE upb_CType upb_MiniTableField_CType(const upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTableField_CType)(f); -} +// Converting between internal table representation and user values. +// +// _upb_map_tokey() and _upb_map_fromkey() are inverses. +// _upb_map_tovalue() and _upb_map_fromvalue() are inverses. +// +// These functions account for the fact that strings are treated differently +// from other types when stored in a map. -UPB_API_INLINE bool upb_MiniTableField_HasPresence( - const upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTableField_HasPresence)(f); +UPB_INLINE upb_StringView _upb_map_tokey(const void* key, size_t size) { + if (size == UPB_MAPTYPE_STRING) { + return *(upb_StringView*)key; + } else { + return upb_StringView_FromDataAndSize((const char*)key, size); + } } -UPB_API_INLINE bool upb_MiniTableField_IsArray(const upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTableField_IsArray)(f); +UPB_INLINE void _upb_map_fromkey(upb_StringView key, void* out, size_t size) { + if (size == UPB_MAPTYPE_STRING) { + memcpy(out, &key, sizeof(key)); + } else { + memcpy(out, key.data, size); + } } -UPB_API_INLINE bool upb_MiniTableField_IsClosedEnum( - const upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTableField_IsClosedEnum)(f); +UPB_INLINE bool _upb_map_tovalue(const void* val, size_t size, + upb_value* msgval, upb_Arena* a) { + if (size == UPB_MAPTYPE_STRING) { + upb_StringView* strp = (upb_StringView*)upb_Arena_Malloc(a, sizeof(*strp)); + if (!strp) return false; + *strp = *(upb_StringView*)val; + *msgval = upb_value_ptr(strp); + } else { + memcpy(msgval, val, size); + } + return true; } -UPB_API_INLINE bool upb_MiniTableField_IsExtension( - const upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTableField_IsExtension)(f); +UPB_INLINE void _upb_map_fromvalue(upb_value val, void* out, size_t size) { + if (size == UPB_MAPTYPE_STRING) { + const upb_StringView* strp = (const upb_StringView*)upb_value_getptr(val); + memcpy(out, strp, sizeof(upb_StringView)); + } else { + memcpy(out, &val, size); + } } -UPB_API_INLINE bool upb_MiniTableField_IsInOneof(const upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTableField_IsInOneof)(f); +UPB_INLINE void* _upb_map_next(const struct upb_Map* map, size_t* iter) { + upb_strtable_iter it; + it.t = &map->table; + it.index = *iter; + upb_strtable_next(&it); + *iter = it.index; + if (upb_strtable_done(&it)) return NULL; + return (void*)str_tabent(&it); } -UPB_API_INLINE bool upb_MiniTableField_IsMap(const upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTableField_IsMap)(f); +UPB_INLINE void _upb_Map_Clear(struct upb_Map* map) { + upb_strtable_clear(&map->table); } -UPB_API_INLINE bool upb_MiniTableField_IsPacked(const upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTableField_IsPacked)(f); +UPB_INLINE bool _upb_Map_Delete(struct upb_Map* map, const void* key, + size_t key_size, upb_value* val) { + upb_StringView k = _upb_map_tokey(key, key_size); + return upb_strtable_remove2(&map->table, k.data, k.size, val); } -UPB_API_INLINE bool upb_MiniTableField_IsScalar(const upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTableField_IsScalar)(f); +UPB_INLINE bool _upb_Map_Get(const struct upb_Map* map, const void* key, + size_t key_size, void* val, size_t val_size) { + upb_value tabval; + upb_StringView k = _upb_map_tokey(key, key_size); + bool ret = upb_strtable_lookup2(&map->table, k.data, k.size, &tabval); + if (ret && val) { + _upb_map_fromvalue(tabval, val, val_size); + } + return ret; } -UPB_API_INLINE bool upb_MiniTableField_IsSubMessage( - const upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTableField_IsSubMessage)(f); +UPB_INLINE upb_MapInsertStatus _upb_Map_Insert(struct upb_Map* map, + const void* key, size_t key_size, + void* val, size_t val_size, + upb_Arena* a) { + upb_StringView strkey = _upb_map_tokey(key, key_size); + upb_value tabval = {0}; + if (!_upb_map_tovalue(val, val_size, &tabval, a)) { + return kUpb_MapInsertStatus_OutOfMemory; + } + + // TODO: add overwrite operation to minimize number of lookups. + bool removed = + upb_strtable_remove2(&map->table, strkey.data, strkey.size, NULL); + if (!upb_strtable_insert(&map->table, strkey.data, strkey.size, tabval, a)) { + return kUpb_MapInsertStatus_OutOfMemory; + } + return removed ? kUpb_MapInsertStatus_Replaced + : kUpb_MapInsertStatus_Inserted; } -UPB_API_INLINE uint32_t upb_MiniTableField_Number(const upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTableField_Number)(f); +UPB_INLINE size_t _upb_Map_Size(const struct upb_Map* map) { + return map->table.t.count; } -UPB_API_INLINE upb_FieldType -upb_MiniTableField_Type(const upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTableField_Type)(f); +// Strings/bytes are special-cased in maps. +extern char _upb_Map_CTypeSizeTable[12]; + +UPB_INLINE size_t _upb_Map_CTypeSize(upb_CType ctype) { + return _upb_Map_CTypeSizeTable[ctype]; } +// Creates a new map on the given arena with this key/value type. +struct upb_Map* _upb_Map_New(upb_Arena* a, size_t key_size, size_t value_size); + #ifdef __cplusplus } /* extern "C" */ #endif -#endif /* UPB_MINI_TABLE_FIELD_H_ */ +#endif /* UPB_MESSAGE_INTERNAL_MAP_H_ */ -#ifndef UPB_MINI_TABLE_INTERNAL_MESSAGE_H_ -#define UPB_MINI_TABLE_INTERNAL_MESSAGE_H_ +/* +** Our memory representation for parsing tables and messages themselves. +** Functions in this file are used by generated code and possibly reflection. +** +** The definitions in this file are internal to upb. +**/ + +#ifndef UPB_MESSAGE_INTERNAL_MESSAGE_H_ +#define UPB_MESSAGE_INTERNAL_MESSAGE_H_ + +#include +#include + + +#ifndef UPB_MESSAGE_INTERNAL_EXTENSION_H_ +#define UPB_MESSAGE_INTERNAL_EXTENSION_H_ + + +#ifndef UPB_MINI_TABLE_EXTENSION_H_ +#define UPB_MINI_TABLE_EXTENSION_H_ #include -#ifndef UPB_MINI_TABLE_INTERNAL_SUB_H_ -#define UPB_MINI_TABLE_INTERNAL_SUB_H_ +#ifndef UPB_MINI_TABLE_FIELD_H_ +#define UPB_MINI_TABLE_FIELD_H_ -// Must be last. +#include + + +#ifndef UPB_MINI_TABLE_INTERNAL_FIELD_H_ +#define UPB_MINI_TABLE_INTERNAL_FIELD_H_ + +#include +#include + + +#ifndef UPB_MINI_TABLE_INTERNAL_SIZE_LOG2_H_ +#define UPB_MINI_TABLE_INTERNAL_SIZE_LOG2_H_ + +#include +#include -union upb_MiniTableSub { - const struct upb_MiniTable* UPB_PRIVATE(submsg); - const struct upb_MiniTableEnum* UPB_PRIVATE(subenum); -}; + +// Must be last. #ifdef __cplusplus extern "C" { #endif -UPB_INLINE union upb_MiniTableSub UPB_PRIVATE(_upb_MiniTableSub_FromEnum)( - const struct upb_MiniTableEnum* subenum) { - union upb_MiniTableSub out; - out.UPB_PRIVATE(subenum) = subenum; - return out; -} +// Return the log2 of the storage size in bytes for a upb_CType +UPB_INLINE int UPB_PRIVATE(_upb_CType_SizeLg2)(upb_CType c_type) { + static const int8_t size[] = { + 0, // kUpb_CType_Bool + 2, // kUpb_CType_Float + 2, // kUpb_CType_Int32 + 2, // kUpb_CType_UInt32 + 2, // kUpb_CType_Enum + UPB_SIZE(2, 3), // kUpb_CType_Message + 3, // kUpb_CType_Double + 3, // kUpb_CType_Int64 + 3, // kUpb_CType_UInt64 + UPB_SIZE(3, 4), // kUpb_CType_String + UPB_SIZE(3, 4), // kUpb_CType_Bytes + }; -UPB_INLINE union upb_MiniTableSub UPB_PRIVATE(_upb_MiniTableSub_FromMessage)( - const struct upb_MiniTable* submsg) { - union upb_MiniTableSub out; - out.UPB_PRIVATE(submsg) = submsg; - return out; + // -1 here because the enum is one-based but the table is zero-based. + return size[c_type - 1]; } -UPB_INLINE const struct upb_MiniTableEnum* UPB_PRIVATE(_upb_MiniTableSub_Enum)( - const union upb_MiniTableSub sub) { - return sub.UPB_PRIVATE(subenum); -} +// Return the log2 of the storage size in bytes for a upb_FieldType +UPB_INLINE int UPB_PRIVATE(_upb_FieldType_SizeLg2)(upb_FieldType field_type) { + static const int8_t size[] = { + 3, // kUpb_FieldType_Double + 2, // kUpb_FieldType_Float + 3, // kUpb_FieldType_Int64 + 3, // kUpb_FieldType_UInt64 + 2, // kUpb_FieldType_Int32 + 3, // kUpb_FieldType_Fixed64 + 2, // kUpb_FieldType_Fixed32 + 0, // kUpb_FieldType_Bool + UPB_SIZE(3, 4), // kUpb_FieldType_String + UPB_SIZE(2, 3), // kUpb_FieldType_Group + UPB_SIZE(2, 3), // kUpb_FieldType_Message + UPB_SIZE(3, 4), // kUpb_FieldType_Bytes + 2, // kUpb_FieldType_UInt32 + 2, // kUpb_FieldType_Enum + 2, // kUpb_FieldType_SFixed32 + 3, // kUpb_FieldType_SFixed64 + 2, // kUpb_FieldType_SInt32 + 3, // kUpb_FieldType_SInt64 + }; -UPB_INLINE const struct upb_MiniTable* UPB_PRIVATE(_upb_MiniTableSub_Message)( - const union upb_MiniTableSub sub) { - return sub.UPB_PRIVATE(submsg); + // -1 here because the enum is one-based but the table is zero-based. + return size[field_type - 1]; } #ifdef __cplusplus @@ -1504,322 +1493,327 @@ UPB_INLINE const struct upb_MiniTable* UPB_PRIVATE(_upb_MiniTableSub_Message)( #endif -#endif /* UPB_MINI_TABLE_INTERNAL_SUB_H_ */ +#endif /* UPB_MINI_TABLE_INTERNAL_SIZE_LOG2_H_ */ // Must be last. -struct upb_Decoder; -struct upb_Message; -typedef const char* _upb_FieldParser(struct upb_Decoder* d, const char* ptr, - struct upb_Message* msg, intptr_t table, - uint64_t hasbits, uint64_t data); -typedef struct { - uint64_t field_data; - _upb_FieldParser* field_parser; -} _upb_FastTable_Entry; +// LINT.IfChange(struct_definition) +struct upb_MiniTableField { + uint32_t UPB_ONLYBITS(number); + uint16_t UPB_ONLYBITS(offset); + int16_t presence; // If >0, hasbit_index. If <0, ~oneof_index -typedef enum { - kUpb_ExtMode_NonExtendable = 0, // Non-extendable message. - kUpb_ExtMode_Extendable = 1, // Normal extendable message. - kUpb_ExtMode_IsMessageSet = 2, // MessageSet message. - kUpb_ExtMode_IsMessageSet_ITEM = - 3, // MessageSet item (temporary only, see decode.c) + // Indexes into `upb_MiniTable.subs` + // Will be set to `kUpb_NoSub` if `descriptortype` != MESSAGE/GROUP/ENUM + uint16_t UPB_PRIVATE(submsg_index); - // During table building we steal a bit to indicate that the message is a map - // entry. *Only* used during table building! - kUpb_ExtMode_IsMapEntry = 4, -} upb_ExtMode; + uint8_t UPB_PRIVATE(descriptortype); -// 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. + // upb_FieldMode | upb_LabelFlags | (upb_FieldRep << kUpb_FieldRep_Shift) + uint8_t UPB_ONLYBITS(mode); +}; -// LINT.IfChange(minitable_struct_definition) -struct upb_MiniTable { - const union upb_MiniTableSub* UPB_PRIVATE(subs); - const struct upb_MiniTableField* UPB_ONLYBITS(fields); +#define kUpb_NoSub ((uint16_t)-1) - // Must be aligned to sizeof(void*). Doesn't include internal members like - // unknown fields, extension dict, pointer to msglayout, etc. - uint16_t UPB_PRIVATE(size); +typedef enum { + kUpb_FieldMode_Map = 0, + kUpb_FieldMode_Array = 1, + kUpb_FieldMode_Scalar = 2, +} upb_FieldMode; - uint16_t UPB_ONLYBITS(field_count); +// Mask to isolate the upb_FieldMode from field.mode. +#define kUpb_FieldMode_Mask 3 - uint8_t UPB_PRIVATE(ext); // upb_ExtMode, uint8_t here so sizeof(ext) == 1 - uint8_t UPB_PRIVATE(dense_below); - uint8_t UPB_PRIVATE(table_mask); - uint8_t UPB_PRIVATE(required_count); // Required fields have the low hasbits. +// Extra flags on the mode field. +typedef enum { + kUpb_LabelFlags_IsPacked = 4, + kUpb_LabelFlags_IsExtension = 8, + // Indicates that this descriptor type is an "alternate type": + // - for Int32, this indicates that the actual type is Enum (but was + // rewritten to Int32 because it is an open enum that requires no check). + // - for Bytes, this indicates that the actual type is String (but does + // not require any UTF-8 check). + kUpb_LabelFlags_IsAlternate = 16, +} upb_LabelFlags; - // To statically initialize the tables of variable length, we need a flexible - // array member, and we need to compile in gnu99 mode (constant initialization - // of flexible array members is a GNU extension, not in C99 unfortunately. - _upb_FastTable_Entry UPB_PRIVATE(fasttable)[]; -}; -// LINT.ThenChange(//depot/google3/third_party/upb/bits/typescript/mini_table.ts) +// Note: we sort by this number when calculating layout order. +typedef enum { + kUpb_FieldRep_1Byte = 0, + kUpb_FieldRep_4Byte = 1, + kUpb_FieldRep_StringView = 2, + kUpb_FieldRep_8Byte = 3, + + kUpb_FieldRep_NativePointer = + UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte), + kUpb_FieldRep_Max = kUpb_FieldRep_8Byte, +} upb_FieldRep; + +#define kUpb_FieldRep_Shift 6 #ifdef __cplusplus extern "C" { #endif -UPB_INLINE const struct upb_MiniTable* UPB_PRIVATE(_upb_MiniTable_Empty)(void) { - extern const struct upb_MiniTable UPB_PRIVATE(_kUpb_MiniTable_Empty); +UPB_INLINE upb_FieldMode +UPB_PRIVATE(_upb_MiniTableField_Mode)(const struct upb_MiniTableField* f) { + return (upb_FieldMode)(f->UPB_ONLYBITS(mode) & kUpb_FieldMode_Mask); +} - return &UPB_PRIVATE(_kUpb_MiniTable_Empty); +UPB_INLINE upb_FieldRep +UPB_PRIVATE(_upb_MiniTableField_GetRep)(const struct upb_MiniTableField* f) { + return (upb_FieldRep)(f->UPB_ONLYBITS(mode) >> kUpb_FieldRep_Shift); } -UPB_INLINE int UPB_PRIVATE(_upb_MiniTable_FieldCount)( - const struct upb_MiniTable* m) { - return m->UPB_ONLYBITS(field_count); +UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsArray)( + const struct upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_Mode)(f) == kUpb_FieldMode_Array; } -UPB_INLINE bool UPB_PRIVATE(_upb_MiniTable_IsEmpty)( - const struct upb_MiniTable* m) { - extern const struct upb_MiniTable UPB_PRIVATE(_kUpb_MiniTable_Empty); +UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsMap)( + const struct upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_Mode)(f) == kUpb_FieldMode_Map; +} - return m == &UPB_PRIVATE(_kUpb_MiniTable_Empty); +UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsScalar)( + const struct upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_Mode)(f) == kUpb_FieldMode_Scalar; } -UPB_INLINE const struct upb_MiniTableField* UPB_PRIVATE( - _upb_MiniTable_GetFieldByIndex)(const struct upb_MiniTable* m, uint32_t i) { - return &m->UPB_ONLYBITS(fields)[i]; +UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsAlternate)( + const struct upb_MiniTableField* f) { + return (f->UPB_ONLYBITS(mode) & kUpb_LabelFlags_IsAlternate) != 0; } -UPB_INLINE const union upb_MiniTableSub* UPB_PRIVATE( - _upb_MiniTable_GetSubByIndex)(const struct upb_MiniTable* m, uint32_t i) { - return &m->UPB_PRIVATE(subs)[i]; +UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsExtension)( + const struct upb_MiniTableField* f) { + return (f->UPB_ONLYBITS(mode) & kUpb_LabelFlags_IsExtension) != 0; } -UPB_INLINE const struct upb_MiniTable* UPB_PRIVATE( - _upb_MiniTable_GetSubMessageTable)(const struct upb_MiniTable* m, - const struct upb_MiniTableField* f) { - UPB_ASSERT(UPB_PRIVATE(_upb_MiniTableField_CType)(f) == kUpb_CType_Message); - const struct upb_MiniTable* ret = UPB_PRIVATE(_upb_MiniTableSub_Message)( - m->UPB_PRIVATE(subs)[f->UPB_PRIVATE(submsg_index)]); - UPB_ASSUME(ret); - return UPB_PRIVATE(_upb_MiniTable_IsEmpty)(ret) ? NULL : ret; +UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsPacked)( + const struct upb_MiniTableField* f) { + return (f->UPB_ONLYBITS(mode) & kUpb_LabelFlags_IsPacked) != 0; } -UPB_INLINE const struct upb_MiniTableEnum* UPB_PRIVATE( - _upb_MiniTable_GetSubEnumTable)(const struct upb_MiniTable* m, - const struct upb_MiniTableField* f) { - UPB_ASSERT(UPB_PRIVATE(_upb_MiniTableField_CType)(f) == kUpb_CType_Enum); - return UPB_PRIVATE(_upb_MiniTableSub_Enum)( - m->UPB_PRIVATE(subs)[f->UPB_PRIVATE(submsg_index)]); +UPB_INLINE upb_FieldType +UPB_PRIVATE(_upb_MiniTableField_Type)(const struct upb_MiniTableField* f) { + const upb_FieldType type = (upb_FieldType)f->UPB_PRIVATE(descriptortype); + if (UPB_PRIVATE(_upb_MiniTableField_IsAlternate)(f)) { + if (type == kUpb_FieldType_Int32) return kUpb_FieldType_Enum; + if (type == kUpb_FieldType_Bytes) return kUpb_FieldType_String; + UPB_ASSERT(false); + } + return type; } -UPB_INLINE const struct upb_MiniTableField* UPB_PRIVATE(_upb_MiniTable_MapKey)( - const struct upb_MiniTable* m) { - UPB_ASSERT(UPB_PRIVATE(_upb_MiniTable_FieldCount)(m) == 2); - const struct upb_MiniTableField* f = - UPB_PRIVATE(_upb_MiniTable_GetFieldByIndex)(m, 0); - UPB_ASSERT(UPB_PRIVATE(_upb_MiniTableField_Number)(f) == 1); - return f; +UPB_INLINE upb_CType +UPB_PRIVATE(_upb_MiniTableField_CType)(const struct upb_MiniTableField* f) { + return upb_FieldType_CType(UPB_PRIVATE(_upb_MiniTableField_Type)(f)); } -UPB_INLINE const struct upb_MiniTableField* UPB_PRIVATE( - _upb_MiniTable_MapValue)(const struct upb_MiniTable* m) { - UPB_ASSERT(UPB_PRIVATE(_upb_MiniTable_FieldCount)(m) == 2); - const struct upb_MiniTableField* f = - UPB_PRIVATE(_upb_MiniTable_GetFieldByIndex)(m, 1); - UPB_ASSERT(UPB_PRIVATE(_upb_MiniTableField_Number)(f) == 2); - return f; +UPB_INLINE char UPB_PRIVATE(_upb_MiniTableField_HasbitMask)( + const struct upb_MiniTableField* f) { + UPB_ASSERT(f->presence > 0); + const size_t index = f->presence; + return 1 << (index % 8); } -UPB_INLINE bool UPB_PRIVATE(_upb_MiniTable_MessageFieldIsLinked)( - const struct upb_MiniTable* m, const struct upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTable_GetSubMessageTable)(m, f) != NULL; +UPB_INLINE size_t UPB_PRIVATE(_upb_MiniTableField_HasbitOffset)( + const struct upb_MiniTableField* f) { + UPB_ASSERT(f->presence > 0); + const size_t index = f->presence; + return index / 8; } -// Computes a bitmask in which the |m->required_count| lowest bits are set, -// except that we skip the lowest bit (because upb never uses hasbit 0). -// -// Sample output: -// RequiredMask(1) => 0b10 (0x2) -// RequiredMask(5) => 0b111110 (0x3e) -UPB_INLINE uint64_t -UPB_PRIVATE(_upb_MiniTable_RequiredMask)(const struct upb_MiniTable* m) { - int n = m->UPB_PRIVATE(required_count); - UPB_ASSERT(0 < n && n <= 63); - return ((1ULL << n) - 1) << 1; +UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsClosedEnum)( + const struct upb_MiniTableField* f) { + return f->UPB_PRIVATE(descriptortype) == kUpb_FieldType_Enum; +} + +UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsInOneof)( + const struct upb_MiniTableField* f) { + return f->presence < 0; +} + +UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsSubMessage)( + const struct upb_MiniTableField* f) { + return f->UPB_PRIVATE(descriptortype) == kUpb_FieldType_Message || + f->UPB_PRIVATE(descriptortype) == kUpb_FieldType_Group; +} + +UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_HasPresence)( + const struct upb_MiniTableField* f) { + if (UPB_PRIVATE(_upb_MiniTableField_IsExtension)(f)) { + return UPB_PRIVATE(_upb_MiniTableField_IsScalar)(f); + } else { + return f->presence != 0; + } +} + +UPB_INLINE uint32_t +UPB_PRIVATE(_upb_MiniTableField_Number)(const struct upb_MiniTableField* f) { + return f->UPB_ONLYBITS(number); +} + +UPB_INLINE uint16_t +UPB_PRIVATE(_upb_MiniTableField_Offset)(const struct upb_MiniTableField* f) { + return f->UPB_ONLYBITS(offset); +} + +UPB_INLINE size_t UPB_PRIVATE(_upb_MiniTableField_OneofOffset)( + const struct upb_MiniTableField* f) { + UPB_ASSERT(UPB_PRIVATE(_upb_MiniTableField_IsInOneof)(f)); + return ~(ptrdiff_t)f->presence; +} + +UPB_INLINE void UPB_PRIVATE(_upb_MiniTableField_CheckIsArray)( + const struct upb_MiniTableField* f) { + UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == + kUpb_FieldRep_NativePointer); + UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_IsArray)(f)); + UPB_ASSUME(f->presence == 0); +} + +UPB_INLINE void UPB_PRIVATE(_upb_MiniTableField_CheckIsMap)( + const struct upb_MiniTableField* f) { + UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == + kUpb_FieldRep_NativePointer); + UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_IsMap)(f)); + UPB_ASSUME(f->presence == 0); +} + +UPB_INLINE size_t UPB_PRIVATE(_upb_MiniTableField_ElemSizeLg2)( + const struct upb_MiniTableField* f) { + const upb_FieldType field_type = UPB_PRIVATE(_upb_MiniTableField_Type)(f); + return UPB_PRIVATE(_upb_FieldType_SizeLg2)(field_type); } +// LINT.ThenChange(//depot/google3/third_party/upb/bits/typescript/mini_table_field.ts) + #ifdef __cplusplus } /* extern "C" */ #endif -#endif /* UPB_MINI_TABLE_INTERNAL_MESSAGE_H_ */ +#endif /* UPB_MINI_TABLE_INTERNAL_FIELD_H_ */ // Must be last. -typedef struct upb_MiniTable upb_MiniTable; +typedef struct upb_MiniTableField upb_MiniTableField; #ifdef __cplusplus extern "C" { #endif -UPB_API const upb_MiniTableField* upb_MiniTable_FindFieldByNumber( - const upb_MiniTable* m, uint32_t number); +UPB_API_INLINE upb_CType upb_MiniTableField_CType(const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_CType)(f); +} -UPB_API_INLINE const upb_MiniTableField* upb_MiniTable_GetFieldByIndex( - const upb_MiniTable* m, uint32_t index) { - return UPB_PRIVATE(_upb_MiniTable_GetFieldByIndex)(m, index); +UPB_API_INLINE bool upb_MiniTableField_HasPresence( + const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_HasPresence)(f); } -UPB_API_INLINE int upb_MiniTable_FieldCount(const upb_MiniTable* m) { - return UPB_PRIVATE(_upb_MiniTable_FieldCount)(m); +UPB_API_INLINE bool upb_MiniTableField_IsArray(const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_IsArray)(f); } -// Returns the MiniTable for a message field, NULL if the field is unlinked. -UPB_API_INLINE const upb_MiniTable* upb_MiniTable_GetSubMessageTable( - const upb_MiniTable* m, const upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTable_GetSubMessageTable)(m, f); +UPB_API_INLINE bool upb_MiniTableField_IsClosedEnum( + const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_IsClosedEnum)(f); } -// Returns the MiniTableEnum for a message field, NULL if the field is unlinked. -UPB_API_INLINE const upb_MiniTableEnum* upb_MiniTable_GetSubEnumTable( - const upb_MiniTable* m, const upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTable_GetSubEnumTable)(m, f); +UPB_API_INLINE bool upb_MiniTableField_IsExtension( + const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_IsExtension)(f); } -// Returns the MiniTableField for the key of a map. -UPB_API_INLINE const upb_MiniTableField* upb_MiniTable_MapKey( - const upb_MiniTable* m) { - return UPB_PRIVATE(_upb_MiniTable_MapKey)(m); +UPB_API_INLINE bool upb_MiniTableField_IsInOneof(const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_IsInOneof)(f); } -// Returns the MiniTableField for the value of a map. -UPB_API_INLINE const upb_MiniTableField* upb_MiniTable_MapValue( - const upb_MiniTable* m) { - return UPB_PRIVATE(_upb_MiniTable_MapValue)(m); +UPB_API_INLINE bool upb_MiniTableField_IsMap(const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_IsMap)(f); } -// Returns true if this MiniTable field is linked to a MiniTable for the -// sub-message. -UPB_API_INLINE bool upb_MiniTable_MessageFieldIsLinked( - const upb_MiniTable* m, const upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTable_MessageFieldIsLinked)(m, f); +UPB_API_INLINE bool upb_MiniTableField_IsPacked(const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_IsPacked)(f); } -// If this field is in a oneof, returns the first field in the oneof. -// -// Otherwise returns NULL. -// -// Usage: -// const upb_MiniTableField* field = upb_MiniTable_GetOneof(m, f); -// do { -// .. -// } while (upb_MiniTable_NextOneofField(m, &field); -// -const upb_MiniTableField* upb_MiniTable_GetOneof(const upb_MiniTable* m, - const upb_MiniTableField* f); +UPB_API_INLINE bool upb_MiniTableField_IsScalar(const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_IsScalar)(f); +} -// Iterates to the next field in the oneof. If this is the last field in the -// oneof, returns false. The ordering of fields in the oneof is not -// guaranteed. -// REQUIRES: |f| is the field initialized by upb_MiniTable_GetOneof and updated -// by prior upb_MiniTable_NextOneofField calls. -bool upb_MiniTable_NextOneofField(const upb_MiniTable* m, - const upb_MiniTableField** f); +UPB_API_INLINE bool upb_MiniTableField_IsSubMessage( + const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_IsSubMessage)(f); +} + +UPB_API_INLINE uint32_t upb_MiniTableField_Number(const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_Number)(f); +} + +UPB_API_INLINE upb_FieldType +upb_MiniTableField_Type(const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_Type)(f); +} #ifdef __cplusplus } /* extern "C" */ #endif -#endif /* UPB_MINI_TABLE_MESSAGE_H_ */ +#endif /* UPB_MINI_TABLE_FIELD_H_ */ -// Must be last. +#ifndef UPB_MINI_TABLE_INTERNAL_EXTENSION_H_ +#define UPB_MINI_TABLE_INTERNAL_EXTENSION_H_ -#ifdef __cplusplus -extern "C" { -#endif +#include -extern const float kUpb_FltInfinity; -extern const double kUpb_Infinity; -extern const double kUpb_NaN; -/* Internal members of a upb_Message that track unknown fields and/or - * extensions. We can change this without breaking binary compatibility. We put - * these before the user's data. The user's upb_Message* points after the - * upb_Message_Internal. */ +#ifndef UPB_MINI_TABLE_INTERNAL_SUB_H_ +#define UPB_MINI_TABLE_INTERNAL_SUB_H_ -struct upb_Message_InternalData { - /* Total size of this structure, including the data that follows. - * Must be aligned to 8, which is alignof(upb_Extension) */ - uint32_t size; +// Must be last. - /* Offsets relative to the beginning of this structure. - * - * Unknown data grows forward from the beginning to unknown_end. - * Extension data grows backward from size to ext_begin. - * When the two meet, we're out of data and have to realloc. - * - * If we imagine that the final member of this struct is: - * char data[size - overhead]; // overhead = - * sizeof(upb_Message_InternalData) - * - * Then we have: - * unknown data: data[0 .. (unknown_end - overhead)] - * extensions data: data[(ext_begin - overhead) .. (size - overhead)] */ - uint32_t unknown_end; - uint32_t ext_begin; - /* Data follows, as if there were an array: - * char data[size - sizeof(upb_Message_InternalData)]; */ +union upb_MiniTableSub { + const struct upb_MiniTable* UPB_PRIVATE(submsg); + const struct upb_MiniTableEnum* UPB_PRIVATE(subenum); }; -UPB_INLINE size_t upb_msg_sizeof(const upb_MiniTable* m) { - return m->UPB_PRIVATE(size) + sizeof(upb_Message_Internal); -} +#ifdef __cplusplus +extern "C" { +#endif -// Inline version upb_Message_New(), for internal use. -UPB_INLINE struct upb_Message* _upb_Message_New(const upb_MiniTable* mini_table, - upb_Arena* arena) { - size_t size = upb_msg_sizeof(mini_table); - void* mem = upb_Arena_Malloc(arena, size + sizeof(upb_Message_Internal)); - if (UPB_UNLIKELY(!mem)) return NULL; - struct upb_Message* msg = - UPB_PTR_AT(mem, sizeof(upb_Message_Internal), struct upb_Message); - memset(mem, 0, size); - return msg; +UPB_INLINE union upb_MiniTableSub UPB_PRIVATE(_upb_MiniTableSub_FromEnum)( + const struct upb_MiniTableEnum* subenum) { + union upb_MiniTableSub out; + out.UPB_PRIVATE(subenum) = subenum; + return out; } -UPB_INLINE upb_Message_Internal* upb_Message_Getinternal( - const struct upb_Message* msg) { - ptrdiff_t size = sizeof(upb_Message_Internal); - return (upb_Message_Internal*)((char*)msg - size); +UPB_INLINE union upb_MiniTableSub UPB_PRIVATE(_upb_MiniTableSub_FromMessage)( + const struct upb_MiniTable* submsg) { + union upb_MiniTableSub out; + out.UPB_PRIVATE(submsg) = submsg; + return out; } -// Discards the unknown fields for this message only. -void _upb_Message_DiscardUnknown_shallow(struct upb_Message* msg); - -// Adds unknown data (serialized protobuf data) to the given message. -// The data is copied into the message instance. -bool UPB_PRIVATE(_upb_Message_AddUnknown)(struct upb_Message* msg, - const char* data, size_t len, - upb_Arena* arena); +UPB_INLINE const struct upb_MiniTableEnum* UPB_PRIVATE(_upb_MiniTableSub_Enum)( + const union upb_MiniTableSub sub) { + return sub.UPB_PRIVATE(subenum); +} -bool UPB_PRIVATE(_upb_Message_Realloc)(struct upb_Message* msg, size_t need, - upb_Arena* arena); +UPB_INLINE const struct upb_MiniTable* UPB_PRIVATE(_upb_MiniTableSub_Message)( + const union upb_MiniTableSub sub) { + return sub.UPB_PRIVATE(submsg); +} #ifdef __cplusplus } /* extern "C" */ #endif -#endif /* UPB_MESSAGE_INTERNAL_H_ */ - -#ifndef UPB_MINI_TABLE_EXTENSION_H_ -#define UPB_MINI_TABLE_EXTENSION_H_ - -#include - - -#ifndef UPB_MINI_TABLE_INTERNAL_EXTENSION_H_ -#define UPB_MINI_TABLE_INTERNAL_EXTENSION_H_ - -#include - +#endif /* UPB_MINI_TABLE_INTERNAL_SUB_H_ */ // Must be last. @@ -1863,32 +1857,56 @@ UPB_INLINE void UPB_PRIVATE(_upb_MiniTableExtension_SetSubMessage)( #endif /* UPB_MINI_TABLE_INTERNAL_EXTENSION_H_ */ +#ifndef UPB_MINI_TABLE_MESSAGE_H_ +#define UPB_MINI_TABLE_MESSAGE_H_ + + +#ifndef UPB_MINI_TABLE_ENUM_H_ +#define UPB_MINI_TABLE_ENUM_H_ + +#include + + +#ifndef UPB_MINI_TABLE_INTERNAL_ENUM_H_ +#define UPB_MINI_TABLE_INTERNAL_ENUM_H_ + +#include + // Must be last. -typedef struct upb_MiniTableExtension upb_MiniTableExtension; +struct upb_MiniTableEnum { + uint32_t UPB_PRIVATE(mask_limit); // Highest that can be tested with mask. + uint32_t UPB_PRIVATE(value_count); // Number of values after the bitfield. + uint32_t UPB_PRIVATE(data)[]; // Bitmask + enumerated values follow. +}; #ifdef __cplusplus extern "C" { #endif -UPB_API_INLINE const upb_MiniTableField* upb_MiniTableExtension_AsField( - const upb_MiniTableExtension* e) { - return UPB_PRIVATE(_upb_MiniTableExtension_AsField)(e); -} - -UPB_API_INLINE uint32_t -upb_MiniTableExtension_Number(const upb_MiniTableExtension* e) { - return UPB_PRIVATE(_upb_MiniTableExtension_Number)(e); -} - -UPB_API_INLINE const upb_MiniTable* upb_MiniTableExtension_GetSubMessage( - const upb_MiniTableExtension* e) { - return UPB_PRIVATE(_upb_MiniTableExtension_GetSubMessage)(e); -} +UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableEnum_CheckValue)( + const struct upb_MiniTableEnum* e, uint32_t val) { + if (UPB_LIKELY(val < 64)) { + const uint64_t mask = + e->UPB_PRIVATE(data)[0] | ((uint64_t)e->UPB_PRIVATE(data)[1] << 32); + const uint64_t bit = 1ULL << val; + return (mask & bit) != 0; + } + if (UPB_LIKELY(val < e->UPB_PRIVATE(mask_limit))) { + const uint32_t mask = e->UPB_PRIVATE(data)[val / 32]; + const uint32_t bit = 1ULL << (val % 32); + return (mask & bit) != 0; + } -UPB_API_INLINE void upb_MiniTableExtension_SetSubMessage( - upb_MiniTableExtension* e, const upb_MiniTable* m) { - UPB_PRIVATE(_upb_MiniTableExtension_SetSubMessage)(e, m); + // OPT: binary search long lists? + const uint32_t* start = + &e->UPB_PRIVATE(data)[e->UPB_PRIVATE(mask_limit) / 32]; + const uint32_t* limit = &e->UPB_PRIVATE( + data)[e->UPB_PRIVATE(mask_limit) / 32 + e->UPB_PRIVATE(value_count)]; + for (const uint32_t* p = start; p < limit; p++) { + if (*p == val) return true; + } + return false; } #ifdef __cplusplus @@ -1896,606 +1914,577 @@ UPB_API_INLINE void upb_MiniTableExtension_SetSubMessage( #endif -#endif /* UPB_MINI_TABLE_EXTENSION_H_ */ +#endif /* UPB_MINI_TABLE_INTERNAL_ENUM_H_ */ -// Must be last. +// Must be last -// The internal representation of an extension is self-describing: it contains -// enough information that we can serialize it to binary format without needing -// to look it up in a upb_ExtensionRegistry. -// -// This representation allocates 16 bytes to data on 64-bit platforms. -// This is rather wasteful for scalars (in the extreme case of bool, -// it wastes 15 bytes). We accept this because we expect messages to be -// the most common extension type. -struct upb_Extension { - const upb_MiniTableExtension* ext; - union { - upb_StringView str; - void* ptr; - char scalar_data[8]; - } data; -}; +typedef struct upb_MiniTableEnum upb_MiniTableEnum; #ifdef __cplusplus extern "C" { #endif -// Adds the given extension data to the given message. -// |ext| is copied into the message instance. -// This logically replaces any previously-added extension with this number. -struct upb_Extension* _upb_Message_GetOrCreateExtension( - struct upb_Message* msg, const upb_MiniTableExtension* ext, - upb_Arena* arena); - -// Returns an array of extensions for this message. -// Note: the array is ordered in reverse relative to the order of creation. -const struct upb_Extension* UPB_PRIVATE(_upb_Message_Getexts)( - const struct upb_Message* msg, size_t* count); - -// Returns an extension for a message with a given mini table, -// or NULL if no extension exists with this mini table. -const struct upb_Extension* _upb_Message_Getext( - const struct upb_Message* msg, const upb_MiniTableExtension* ext); +// Validates enum value against range defined by enum mini table. +UPB_INLINE bool upb_MiniTableEnum_CheckValue(const upb_MiniTableEnum* e, + uint32_t val) { + return UPB_PRIVATE(_upb_MiniTableEnum_CheckValue)(e, val); +} #ifdef __cplusplus } /* extern "C" */ #endif -#endif /* UPB_MESSAGE_INTERNAL_EXTENSION_H_ */ +#endif /* UPB_MINI_TABLE_ENUM_H_ */ -// EVERYTHING BELOW THIS LINE IS INTERNAL - DO NOT USE ///////////////////////// +#ifndef UPB_MINI_TABLE_INTERNAL_MESSAGE_H_ +#define UPB_MINI_TABLE_INTERNAL_MESSAGE_H_ -#ifndef UPB_MESSAGE_INTERNAL_MAP_H_ -#define UPB_MESSAGE_INTERNAL_MAP_H_ +#include -#include -#include +// Must be last. -#ifndef UPB_HASH_STR_TABLE_H_ -#define UPB_HASH_STR_TABLE_H_ +struct upb_Decoder; +struct upb_Message; +typedef const char* _upb_FieldParser(struct upb_Decoder* d, const char* ptr, + struct upb_Message* msg, intptr_t table, + uint64_t hasbits, uint64_t data); +typedef struct { + uint64_t field_data; + _upb_FieldParser* field_parser; +} _upb_FastTable_Entry; +typedef enum { + kUpb_ExtMode_NonExtendable = 0, // Non-extendable message. + kUpb_ExtMode_Extendable = 1, // Normal extendable message. + kUpb_ExtMode_IsMessageSet = 2, // MessageSet message. + kUpb_ExtMode_IsMessageSet_ITEM = + 3, // MessageSet item (temporary only, see decode.c) -/* - * upb_table - * - * This header is INTERNAL-ONLY! Its interfaces are not public or stable! - * This file defines very fast int->upb_value (inttable) and string->upb_value - * (strtable) hash tables. - * - * The table uses chained scatter with Brent's variation (inspired by the Lua - * implementation of hash tables). The hash function for strings is Austin - * Appleby's "MurmurHash." - * - * The inttable uses uintptr_t as its key, which guarantees it can be used to - * store pointers or integers of at least 32 bits (upb isn't really useful on - * systems where sizeof(void*) < 4). - * - * The table must be homogeneous (all values of the same type). In debug - * mode, we check this on insert and lookup. - */ + // During table building we steal a bit to indicate that the message is a map + // entry. *Only* used during table building! + kUpb_ExtMode_IsMapEntry = 4, +} upb_ExtMode; -#ifndef UPB_HASH_COMMON_H_ -#define UPB_HASH_COMMON_H_ +// 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. -#include +// LINT.IfChange(minitable_struct_definition) +struct upb_MiniTable { + const union upb_MiniTableSub* UPB_PRIVATE(subs); + const struct upb_MiniTableField* UPB_ONLYBITS(fields); + // Must be aligned to sizeof(void*). Doesn't include internal members like + // unknown fields, extension dict, pointer to msglayout, etc. + uint16_t UPB_PRIVATE(size); -// Must be last. + uint16_t UPB_ONLYBITS(field_count); + + uint8_t UPB_PRIVATE(ext); // upb_ExtMode, uint8_t here so sizeof(ext) == 1 + uint8_t UPB_PRIVATE(dense_below); + uint8_t UPB_PRIVATE(table_mask); + uint8_t UPB_PRIVATE(required_count); // Required fields have the low hasbits. + + // To statically initialize the tables of variable length, we need a flexible + // array member, and we need to compile in gnu99 mode (constant initialization + // of flexible array members is a GNU extension, not in C99 unfortunately. + _upb_FastTable_Entry UPB_PRIVATE(fasttable)[]; +}; +// LINT.ThenChange(//depot/google3/third_party/upb/bits/typescript/mini_table.ts) #ifdef __cplusplus extern "C" { #endif -/* upb_value ******************************************************************/ - -typedef struct { - uint64_t val; -} upb_value; - -UPB_INLINE void _upb_value_setval(upb_value* v, uint64_t val) { v->val = val; } - -/* For each value ctype, define the following set of functions: - * - * // Get/set an int32 from a upb_value. - * int32_t upb_value_getint32(upb_value val); - * void upb_value_setint32(upb_value *val, int32_t cval); - * - * // Construct a new upb_value from an int32. - * upb_value upb_value_int32(int32_t val); */ -#define FUNCS(name, membername, type_t, converter) \ - UPB_INLINE void upb_value_set##name(upb_value* val, type_t cval) { \ - val->val = (converter)cval; \ - } \ - UPB_INLINE upb_value upb_value_##name(type_t val) { \ - upb_value ret; \ - upb_value_set##name(&ret, val); \ - return ret; \ - } \ - UPB_INLINE type_t upb_value_get##name(upb_value val) { \ - return (type_t)(converter)val.val; \ - } - -FUNCS(int32, int32, int32_t, int32_t) -FUNCS(int64, int64, int64_t, int64_t) -FUNCS(uint32, uint32, uint32_t, uint32_t) -FUNCS(uint64, uint64, uint64_t, uint64_t) -FUNCS(bool, _bool, bool, bool) -FUNCS(cstr, cstr, char*, uintptr_t) -FUNCS(uintptr, uptr, uintptr_t, uintptr_t) -FUNCS(ptr, ptr, void*, uintptr_t) -FUNCS(constptr, constptr, const void*, uintptr_t) - -#undef FUNCS +UPB_INLINE const struct upb_MiniTable* UPB_PRIVATE(_upb_MiniTable_Empty)(void) { + extern const struct upb_MiniTable UPB_PRIVATE(_kUpb_MiniTable_Empty); -UPB_INLINE void upb_value_setfloat(upb_value* val, float cval) { - memcpy(&val->val, &cval, sizeof(cval)); + return &UPB_PRIVATE(_kUpb_MiniTable_Empty); } -UPB_INLINE void upb_value_setdouble(upb_value* val, double cval) { - memcpy(&val->val, &cval, sizeof(cval)); +UPB_INLINE int UPB_PRIVATE(_upb_MiniTable_FieldCount)( + const struct upb_MiniTable* m) { + return m->UPB_ONLYBITS(field_count); } -UPB_INLINE upb_value upb_value_float(float cval) { - upb_value ret; - upb_value_setfloat(&ret, cval); - return ret; -} +UPB_INLINE bool UPB_PRIVATE(_upb_MiniTable_IsEmpty)( + const struct upb_MiniTable* m) { + extern const struct upb_MiniTable UPB_PRIVATE(_kUpb_MiniTable_Empty); -UPB_INLINE upb_value upb_value_double(double cval) { - upb_value ret; - upb_value_setdouble(&ret, cval); - return ret; + return m == &UPB_PRIVATE(_kUpb_MiniTable_Empty); } -/* upb_tabkey *****************************************************************/ - -/* Either: - * 1. an actual integer key, or - * 2. a pointer to a string prefixed by its uint32_t length, owned by us. - * - * ...depending on whether this is a string table or an int table. We would - * make this a union of those two types, but C89 doesn't support statically - * initializing a non-first union member. */ -typedef uintptr_t upb_tabkey; - -UPB_INLINE char* upb_tabstr(upb_tabkey key, uint32_t* len) { - char* mem = (char*)key; - if (len) memcpy(len, mem, sizeof(*len)); - return mem + sizeof(*len); +UPB_INLINE const struct upb_MiniTableField* UPB_PRIVATE( + _upb_MiniTable_GetFieldByIndex)(const struct upb_MiniTable* m, uint32_t i) { + return &m->UPB_ONLYBITS(fields)[i]; } -UPB_INLINE upb_StringView upb_tabstrview(upb_tabkey key) { - upb_StringView ret; - uint32_t len; - ret.data = upb_tabstr(key, &len); - ret.size = len; - return ret; +UPB_INLINE const union upb_MiniTableSub* UPB_PRIVATE( + _upb_MiniTable_GetSubByIndex)(const struct upb_MiniTable* m, uint32_t i) { + return &m->UPB_PRIVATE(subs)[i]; } -/* upb_tabval *****************************************************************/ - -typedef struct upb_tabval { - uint64_t val; -} upb_tabval; - -#define UPB_TABVALUE_EMPTY_INIT \ - { -1 } - -/* upb_table ******************************************************************/ - -typedef struct _upb_tabent { - upb_tabkey key; - upb_tabval val; - - /* Internal chaining. This is const so we can create static initializers for - * tables. We cast away const sometimes, but *only* when the containing - * upb_table is known to be non-const. This requires a bit of care, but - * the subtlety is confined to table.c. */ - const struct _upb_tabent* next; -} upb_tabent; +UPB_INLINE const struct upb_MiniTable* UPB_PRIVATE( + _upb_MiniTable_GetSubMessageTable)(const struct upb_MiniTable* m, + const struct upb_MiniTableField* f) { + UPB_ASSERT(UPB_PRIVATE(_upb_MiniTableField_CType)(f) == kUpb_CType_Message); + const struct upb_MiniTable* ret = UPB_PRIVATE(_upb_MiniTableSub_Message)( + m->UPB_PRIVATE(subs)[f->UPB_PRIVATE(submsg_index)]); + UPB_ASSUME(ret); + return UPB_PRIVATE(_upb_MiniTable_IsEmpty)(ret) ? NULL : ret; +} -typedef struct { - size_t count; /* Number of entries in the hash part. */ - uint32_t mask; /* Mask to turn hash value -> bucket. */ - uint32_t max_count; /* Max count before we hit our load limit. */ - uint8_t size_lg2; /* Size of the hashtable part is 2^size_lg2 entries. */ - upb_tabent* entries; -} upb_table; +UPB_INLINE const struct upb_MiniTableEnum* UPB_PRIVATE( + _upb_MiniTable_GetSubEnumTable)(const struct upb_MiniTable* m, + const struct upb_MiniTableField* f) { + UPB_ASSERT(UPB_PRIVATE(_upb_MiniTableField_CType)(f) == kUpb_CType_Enum); + return UPB_PRIVATE(_upb_MiniTableSub_Enum)( + m->UPB_PRIVATE(subs)[f->UPB_PRIVATE(submsg_index)]); +} -UPB_INLINE size_t upb_table_size(const upb_table* t) { - return t->size_lg2 ? 1 << t->size_lg2 : 0; +UPB_INLINE const struct upb_MiniTableField* UPB_PRIVATE(_upb_MiniTable_MapKey)( + const struct upb_MiniTable* m) { + UPB_ASSERT(UPB_PRIVATE(_upb_MiniTable_FieldCount)(m) == 2); + const struct upb_MiniTableField* f = + UPB_PRIVATE(_upb_MiniTable_GetFieldByIndex)(m, 0); + UPB_ASSERT(UPB_PRIVATE(_upb_MiniTableField_Number)(f) == 1); + return f; } -// Internal-only functions, in .h file only out of necessity. +UPB_INLINE const struct upb_MiniTableField* UPB_PRIVATE( + _upb_MiniTable_MapValue)(const struct upb_MiniTable* m) { + UPB_ASSERT(UPB_PRIVATE(_upb_MiniTable_FieldCount)(m) == 2); + const struct upb_MiniTableField* f = + UPB_PRIVATE(_upb_MiniTable_GetFieldByIndex)(m, 1); + UPB_ASSERT(UPB_PRIVATE(_upb_MiniTableField_Number)(f) == 2); + return f; +} -UPB_INLINE bool upb_tabent_isempty(const upb_tabent* e) { return e->key == 0; } +UPB_INLINE bool UPB_PRIVATE(_upb_MiniTable_MessageFieldIsLinked)( + const struct upb_MiniTable* m, const struct upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTable_GetSubMessageTable)(m, f) != NULL; +} -uint32_t _upb_Hash(const void* p, size_t n, uint64_t seed); +// Computes a bitmask in which the |m->required_count| lowest bits are set, +// except that we skip the lowest bit (because upb never uses hasbit 0). +// +// Sample output: +// RequiredMask(1) => 0b10 (0x2) +// RequiredMask(5) => 0b111110 (0x3e) +UPB_INLINE uint64_t +UPB_PRIVATE(_upb_MiniTable_RequiredMask)(const struct upb_MiniTable* m) { + int n = m->UPB_PRIVATE(required_count); + UPB_ASSERT(0 < n && n <= 63); + return ((1ULL << n) - 1) << 1; +} #ifdef __cplusplus } /* extern "C" */ #endif -#endif /* UPB_HASH_COMMON_H_ */ +#endif /* UPB_MINI_TABLE_INTERNAL_MESSAGE_H_ */ // Must be last. -typedef struct { - upb_table t; -} upb_strtable; +typedef struct upb_MiniTable upb_MiniTable; #ifdef __cplusplus extern "C" { #endif -// Initialize a table. If memory allocation failed, false is returned and -// the table is uninitialized. -bool upb_strtable_init(upb_strtable* table, size_t expected_size, upb_Arena* a); +UPB_API const upb_MiniTableField* upb_MiniTable_FindFieldByNumber( + const upb_MiniTable* m, uint32_t number); -// Returns the number of values in the table. -UPB_INLINE size_t upb_strtable_count(const upb_strtable* t) { - return t->t.count; +UPB_API_INLINE const upb_MiniTableField* upb_MiniTable_GetFieldByIndex( + const upb_MiniTable* m, uint32_t index) { + return UPB_PRIVATE(_upb_MiniTable_GetFieldByIndex)(m, index); } -void upb_strtable_clear(upb_strtable* t); +UPB_API_INLINE int upb_MiniTable_FieldCount(const upb_MiniTable* m) { + return UPB_PRIVATE(_upb_MiniTable_FieldCount)(m); +} -// Inserts the given key into the hashtable with the given value. -// The key must not already exist in the hash table. The key is not required -// to be NULL-terminated, and the table will make an internal copy of the key. -// -// If a table resize was required but memory allocation failed, false is -// returned and the table is unchanged. */ -bool upb_strtable_insert(upb_strtable* t, const char* key, size_t len, - upb_value val, upb_Arena* a); +// Returns the MiniTable for a message field, NULL if the field is unlinked. +UPB_API_INLINE const upb_MiniTable* upb_MiniTable_GetSubMessageTable( + const upb_MiniTable* m, const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTable_GetSubMessageTable)(m, f); +} -// Looks up key in this table, returning "true" if the key was found. -// If v is non-NULL, copies the value for this key into *v. -bool upb_strtable_lookup2(const upb_strtable* t, const char* key, size_t len, - upb_value* v); +// Returns the MiniTableEnum for a message field, NULL if the field is unlinked. +UPB_API_INLINE const upb_MiniTableEnum* upb_MiniTable_GetSubEnumTable( + const upb_MiniTable* m, const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTable_GetSubEnumTable)(m, f); +} -// For NULL-terminated strings. -UPB_INLINE bool upb_strtable_lookup(const upb_strtable* t, const char* key, - upb_value* v) { - return upb_strtable_lookup2(t, key, strlen(key), v); +// Returns the MiniTableField for the key of a map. +UPB_API_INLINE const upb_MiniTableField* upb_MiniTable_MapKey( + const upb_MiniTable* m) { + return UPB_PRIVATE(_upb_MiniTable_MapKey)(m); } -// Removes an item from the table. Returns true if the remove was successful, -// and stores the removed item in *val if non-NULL. -bool upb_strtable_remove2(upb_strtable* t, const char* key, size_t len, - upb_value* val); +// Returns the MiniTableField for the value of a map. +UPB_API_INLINE const upb_MiniTableField* upb_MiniTable_MapValue( + const upb_MiniTable* m) { + return UPB_PRIVATE(_upb_MiniTable_MapValue)(m); +} -UPB_INLINE bool upb_strtable_remove(upb_strtable* t, const char* key, - upb_value* v) { - return upb_strtable_remove2(t, key, strlen(key), v); +// Returns true if this MiniTable field is linked to a MiniTable for the +// sub-message. +UPB_API_INLINE bool upb_MiniTable_MessageFieldIsLinked( + const upb_MiniTable* m, const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTable_MessageFieldIsLinked)(m, f); } -// Exposed for testing only. -bool upb_strtable_resize(upb_strtable* t, size_t size_lg2, upb_Arena* a); +// If this field is in a oneof, returns the first field in the oneof. +// +// Otherwise returns NULL. +// +// Usage: +// const upb_MiniTableField* field = upb_MiniTable_GetOneof(m, f); +// do { +// .. +// } while (upb_MiniTable_NextOneofField(m, &field); +// +const upb_MiniTableField* upb_MiniTable_GetOneof(const upb_MiniTable* m, + const upb_MiniTableField* f); -/* Iteration over strtable: - * - * intptr_t iter = UPB_STRTABLE_BEGIN; - * upb_StringView key; - * upb_value val; - * while (upb_strtable_next2(t, &key, &val, &iter)) { - * // ... - * } - */ +// Iterates to the next field in the oneof. If this is the last field in the +// oneof, returns false. The ordering of fields in the oneof is not +// guaranteed. +// REQUIRES: |f| is the field initialized by upb_MiniTable_GetOneof and updated +// by prior upb_MiniTable_NextOneofField calls. +bool upb_MiniTable_NextOneofField(const upb_MiniTable* m, + const upb_MiniTableField** f); -#define UPB_STRTABLE_BEGIN -1 +#ifdef __cplusplus +} /* extern "C" */ +#endif -bool upb_strtable_next2(const upb_strtable* t, upb_StringView* key, - upb_value* val, intptr_t* iter); -void upb_strtable_removeiter(upb_strtable* t, intptr_t* iter); -void upb_strtable_setentryvalue(upb_strtable* t, intptr_t iter, upb_value v); -/* DEPRECATED iterators, slated for removal. - * - * Iterators for string tables. We are subject to some kind of unusual - * design constraints: - * - * For high-level languages: - * - we must be able to guarantee that we don't crash or corrupt memory even if - * the program accesses an invalidated iterator. - * - * For C++11 range-based for: - * - iterators must be copyable - * - iterators must be comparable - * - it must be possible to construct an "end" value. - * - * Iteration order is undefined. - * - * Modifying the table invalidates iterators. upb_{str,int}table_done() is - * guaranteed to work even on an invalidated iterator, as long as the table it - * is iterating over has not been freed. Calling next() or accessing data from - * an invalidated iterator yields unspecified elements from the table, but it is - * guaranteed not to crash and to return real table elements (except when done() - * is true). */ -/* upb_strtable_iter **********************************************************/ +#endif /* UPB_MINI_TABLE_MESSAGE_H_ */ -/* upb_strtable_iter i; - * upb_strtable_begin(&i, t); - * for(; !upb_strtable_done(&i); upb_strtable_next(&i)) { - * const char *key = upb_strtable_iter_key(&i); - * const upb_value val = upb_strtable_iter_value(&i); - * // ... - * } - */ +// Must be last. -typedef struct { - const upb_strtable* t; - size_t index; -} upb_strtable_iter; +typedef struct upb_MiniTableExtension upb_MiniTableExtension; -UPB_INLINE const upb_tabent* str_tabent(const upb_strtable_iter* i) { - return &i->t->t.entries[i->index]; +#ifdef __cplusplus +extern "C" { +#endif + +UPB_API_INLINE const upb_MiniTableField* upb_MiniTableExtension_AsField( + const upb_MiniTableExtension* e) { + return UPB_PRIVATE(_upb_MiniTableExtension_AsField)(e); } -void upb_strtable_begin(upb_strtable_iter* i, const upb_strtable* t); -void upb_strtable_next(upb_strtable_iter* i); -bool upb_strtable_done(const upb_strtable_iter* i); -upb_StringView upb_strtable_iter_key(const upb_strtable_iter* i); -upb_value upb_strtable_iter_value(const upb_strtable_iter* i); -void upb_strtable_iter_setdone(upb_strtable_iter* i); -bool upb_strtable_iter_isequal(const upb_strtable_iter* i1, - const upb_strtable_iter* i2); +UPB_API_INLINE uint32_t +upb_MiniTableExtension_Number(const upb_MiniTableExtension* e) { + return UPB_PRIVATE(_upb_MiniTableExtension_Number)(e); +} + +UPB_API_INLINE const upb_MiniTable* upb_MiniTableExtension_GetSubMessage( + const upb_MiniTableExtension* e) { + return UPB_PRIVATE(_upb_MiniTableExtension_GetSubMessage)(e); +} + +UPB_API_INLINE void upb_MiniTableExtension_SetSubMessage( + upb_MiniTableExtension* e, const upb_MiniTable* m) { + UPB_PRIVATE(_upb_MiniTableExtension_SetSubMessage)(e, m); +} #ifdef __cplusplus } /* extern "C" */ #endif -#endif /* UPB_HASH_STR_TABLE_H_ */ +#endif /* UPB_MINI_TABLE_EXTENSION_H_ */ + +// Must be last. + +// The internal representation of an extension is self-describing: it contains +// enough information that we can serialize it to binary format without needing +// to look it up in a upb_ExtensionRegistry. +// +// This representation allocates 16 bytes to data on 64-bit platforms. +// This is rather wasteful for scalars (in the extreme case of bool, +// it wastes 15 bytes). We accept this because we expect messages to be +// the most common extension type. +struct upb_Extension { + const upb_MiniTableExtension* ext; + union { + upb_StringView str; + void* ptr; + char scalar_data[8]; + } data; +}; + +#ifdef __cplusplus +extern "C" { +#endif + +// Adds the given extension data to the given message. +// |ext| is copied into the message instance. +// This logically replaces any previously-added extension with this number. +struct upb_Extension* _upb_Message_GetOrCreateExtension( + struct upb_Message* msg, const upb_MiniTableExtension* ext, + upb_Arena* arena); + +// Returns an array of extensions for this message. +// Note: the array is ordered in reverse relative to the order of creation. +const struct upb_Extension* UPB_PRIVATE(_upb_Message_Getexts)( + const struct upb_Message* msg, size_t* count); + +// Returns an extension for a message with a given mini table, +// or NULL if no extension exists with this mini table. +const struct upb_Extension* _upb_Message_Getext( + const struct upb_Message* msg, const upb_MiniTableExtension* ext); -#ifndef UPB_MESSAGE_MAP_H_ -#define UPB_MESSAGE_MAP_H_ +#ifdef __cplusplus +} /* extern "C" */ +#endif -#include +#endif /* UPB_MESSAGE_INTERNAL_EXTENSION_H_ */ // Must be last. -typedef struct upb_Map upb_Map; - #ifdef __cplusplus extern "C" { #endif -// Creates a new map on the given arena with the given key/value size. -UPB_API upb_Map* upb_Map_New(upb_Arena* a, upb_CType key_type, - upb_CType value_type); - -// Returns the number of entries in the map. -UPB_API size_t upb_Map_Size(const upb_Map* map); +extern const float kUpb_FltInfinity; +extern const double kUpb_Infinity; +extern const double kUpb_NaN; -// Stores a value for the given key into |*val| (or the zero value if the key is -// not present). Returns whether the key was present. The |val| pointer may be -// NULL, in which case the function tests whether the given key is present. -UPB_API bool upb_Map_Get(const upb_Map* map, upb_MessageValue key, - upb_MessageValue* val); +/* Internal members of a upb_Message that track unknown fields and/or + * extensions. We can change this without breaking binary compatibility. We put + * these before the user's data. The user's upb_Message* points after the + * upb_Message_Internal. */ -// Removes all entries in the map. -UPB_API void upb_Map_Clear(upb_Map* map); +typedef struct { + /* Total size of this structure, including the data that follows. + * Must be aligned to 8, which is alignof(upb_Extension) */ + uint32_t size; -typedef enum { - kUpb_MapInsertStatus_Inserted = 0, - kUpb_MapInsertStatus_Replaced = 1, - kUpb_MapInsertStatus_OutOfMemory = 2, -} upb_MapInsertStatus; + /* Offsets relative to the beginning of this structure. + * + * Unknown data grows forward from the beginning to unknown_end. + * Extension data grows backward from size to ext_begin. + * When the two meet, we're out of data and have to realloc. + * + * If we imagine that the final member of this struct is: + * char data[size - overhead]; // overhead = + * sizeof(upb_Message_InternalData) + * + * Then we have: + * unknown data: data[0 .. (unknown_end - overhead)] + * extensions data: data[(ext_begin - overhead) .. (size - overhead)] */ + uint32_t unknown_end; + uint32_t ext_begin; + /* Data follows, as if there were an array: + * char data[size - sizeof(upb_Message_InternalData)]; */ +} upb_Message_InternalData; -// Sets the given key to the given value, returning whether the key was inserted -// or replaced. If the key was inserted, then any existing iterators will be -// invalidated. -UPB_API upb_MapInsertStatus upb_Map_Insert(upb_Map* map, upb_MessageValue key, - upb_MessageValue val, - upb_Arena* arena); +typedef struct { + union { + upb_Message_InternalData* internal; -// Sets the given key to the given value. Returns false if memory allocation -// failed. If the key is newly inserted, then any existing iterators will be -// invalidated. -UPB_API_INLINE bool upb_Map_Set(upb_Map* map, upb_MessageValue key, - upb_MessageValue val, upb_Arena* arena) { - return upb_Map_Insert(map, key, val, arena) != - kUpb_MapInsertStatus_OutOfMemory; -} + // Force 8-byte alignment, since the data members may contain members that + // require 8-byte alignment. + double d; + }; +} upb_Message_Internal; -// Deletes this key from the table. Returns true if the key was present. -// If present and |val| is non-NULL, stores the deleted value. -UPB_API bool upb_Map_Delete(upb_Map* map, upb_MessageValue key, - upb_MessageValue* val); +struct upb_Message { + int unused; // Placeholder cuz Windows won't compile an empty struct. +}; -// (DEPRECATED and going away soon. Do not use.) -UPB_INLINE bool upb_Map_Delete2(upb_Map* map, upb_MessageValue key, - upb_MessageValue* val) { - return upb_Map_Delete(map, key, val); +UPB_INLINE size_t upb_msg_sizeof(const upb_MiniTable* m) { + return m->UPB_PRIVATE(size) + sizeof(upb_Message_Internal); } -// Map iteration: -// -// size_t iter = kUpb_Map_Begin; -// upb_MessageValue key, val; -// while (upb_Map_Next(map, &key, &val, &iter)) { -// ... -// } - -#define kUpb_Map_Begin ((size_t)-1) - -// Advances to the next entry. Returns false if no more entries are present. -// Otherwise returns true and populates both *key and *value. -UPB_API bool upb_Map_Next(const upb_Map* map, upb_MessageValue* key, - upb_MessageValue* val, size_t* iter); - -// Sets the value for the entry pointed to by iter. -// WARNING: this does not currently work for string values! -UPB_API void upb_Map_SetEntryValue(upb_Map* map, size_t iter, - upb_MessageValue val); - -// DEPRECATED iterator, slated for removal. +// Inline version upb_Message_New(), for internal use. +UPB_INLINE struct upb_Message* _upb_Message_New(const upb_MiniTable* mini_table, + upb_Arena* arena) { + size_t size = upb_msg_sizeof(mini_table); + void* mem = upb_Arena_Malloc(arena, size + sizeof(upb_Message_Internal)); + if (UPB_UNLIKELY(!mem)) return NULL; + struct upb_Message* msg = + UPB_PTR_AT(mem, sizeof(upb_Message_Internal), struct upb_Message); + memset(mem, 0, size); + return msg; +} -/* Map iteration: - * - * size_t iter = kUpb_Map_Begin; - * while (upb_MapIterator_Next(map, &iter)) { - * upb_MessageValue key = upb_MapIterator_Key(map, iter); - * upb_MessageValue val = upb_MapIterator_Value(map, iter); - * } - */ +UPB_INLINE upb_Message_Internal* upb_Message_Getinternal( + const struct upb_Message* msg) { + ptrdiff_t size = sizeof(upb_Message_Internal); + return (upb_Message_Internal*)((char*)msg - size); +} -// Advances to the next entry. Returns false if no more entries are present. -UPB_API bool upb_MapIterator_Next(const upb_Map* map, size_t* iter); +// Discards the unknown fields for this message only. +void _upb_Message_DiscardUnknown_shallow(struct upb_Message* msg); -// Returns true if the iterator still points to a valid entry, or false if the -// iterator is past the last element. It is an error to call this function with -// kUpb_Map_Begin (you must call next() at least once first). -UPB_API bool upb_MapIterator_Done(const upb_Map* map, size_t iter); +// Adds unknown data (serialized protobuf data) to the given message. +// The data is copied into the message instance. +bool UPB_PRIVATE(_upb_Message_AddUnknown)(struct upb_Message* msg, + const char* data, size_t len, + upb_Arena* arena); -// Returns the key and value for this entry of the map. -UPB_API upb_MessageValue upb_MapIterator_Key(const upb_Map* map, size_t iter); -UPB_API upb_MessageValue upb_MapIterator_Value(const upb_Map* map, size_t iter); +bool UPB_PRIVATE(_upb_Message_Realloc)(struct upb_Message* msg, size_t need, + upb_Arena* arena); #ifdef __cplusplus } /* extern "C" */ #endif -#endif /* UPB_MESSAGE_MAP_H_ */ +#endif /* UPB_MESSAGE_INTERNAL_MESSAGE_H_ */ -// Must be last. +#ifndef UPB_MINI_TABLE_INTERNAL_TAGGED_PTR_H_ +#define UPB_MINI_TABLE_INTERNAL_TAGGED_PTR_H_ -struct upb_Map { - // Size of key and val, based on the map type. - // Strings are represented as '0' because they must be handled specially. - char key_size; - char val_size; +#include - upb_strtable table; -}; + +// Must be last. + +typedef uintptr_t upb_TaggedMessagePtr; #ifdef __cplusplus extern "C" { #endif -// Converting between internal table representation and user values. -// -// _upb_map_tokey() and _upb_map_fromkey() are inverses. -// _upb_map_tovalue() and _upb_map_fromvalue() are inverses. -// -// These functions account for the fact that strings are treated differently -// from other types when stored in a map. - -UPB_INLINE upb_StringView _upb_map_tokey(const void* key, size_t size) { - if (size == UPB_MAPTYPE_STRING) { - return *(upb_StringView*)key; - } else { - return upb_StringView_FromDataAndSize((const char*)key, size); - } +// Internal-only because empty messages cannot be created by the user. +UPB_INLINE upb_TaggedMessagePtr +UPB_PRIVATE(_upb_TaggedMessagePtr_Pack)(struct upb_Message* ptr, bool empty) { + UPB_ASSERT(((uintptr_t)ptr & 1) == 0); + return (uintptr_t)ptr | (empty ? 1 : 0); } -UPB_INLINE void _upb_map_fromkey(upb_StringView key, void* out, size_t size) { - if (size == UPB_MAPTYPE_STRING) { - memcpy(out, &key, sizeof(key)); - } else { - memcpy(out, key.data, size); - } +UPB_INLINE bool UPB_PRIVATE(_upb_TaggedMessagePtr_IsEmpty)( + upb_TaggedMessagePtr ptr) { + return ptr & 1; } -UPB_INLINE bool _upb_map_tovalue(const void* val, size_t size, - upb_value* msgval, upb_Arena* a) { - if (size == UPB_MAPTYPE_STRING) { - upb_StringView* strp = (upb_StringView*)upb_Arena_Malloc(a, sizeof(*strp)); - if (!strp) return false; - *strp = *(upb_StringView*)val; - *msgval = upb_value_ptr(strp); - } else { - memcpy(msgval, val, size); - } - return true; +UPB_INLINE struct upb_Message* UPB_PRIVATE(_upb_TaggedMessagePtr_GetMessage)( + upb_TaggedMessagePtr ptr) { + return (struct upb_Message*)(ptr & ~(uintptr_t)1); } -UPB_INLINE void _upb_map_fromvalue(upb_value val, void* out, size_t size) { - if (size == UPB_MAPTYPE_STRING) { - const upb_StringView* strp = (const upb_StringView*)upb_value_getptr(val); - memcpy(out, strp, sizeof(upb_StringView)); - } else { - memcpy(out, &val, size); - } +UPB_INLINE struct upb_Message* UPB_PRIVATE( + _upb_TaggedMessagePtr_GetNonEmptyMessage)(upb_TaggedMessagePtr ptr) { + UPB_ASSERT(!UPB_PRIVATE(_upb_TaggedMessagePtr_IsEmpty)(ptr)); + return UPB_PRIVATE(_upb_TaggedMessagePtr_GetMessage)(ptr); } -UPB_INLINE void* _upb_map_next(const struct upb_Map* map, size_t* iter) { - upb_strtable_iter it; - it.t = &map->table; - it.index = *iter; - upb_strtable_next(&it); - *iter = it.index; - if (upb_strtable_done(&it)) return NULL; - return (void*)str_tabent(&it); +UPB_INLINE struct upb_Message* UPB_PRIVATE( + _upb_TaggedMessagePtr_GetEmptyMessage)(upb_TaggedMessagePtr ptr) { + UPB_ASSERT(UPB_PRIVATE(_upb_TaggedMessagePtr_IsEmpty)(ptr)); + return UPB_PRIVATE(_upb_TaggedMessagePtr_GetMessage)(ptr); } -UPB_INLINE void _upb_Map_Clear(struct upb_Map* map) { - upb_strtable_clear(&map->table); -} +#ifdef __cplusplus +} /* extern "C" */ +#endif + + +#endif /* UPB_MINI_TABLE_INTERNAL_TAGGED_PTR_H_ */ + +typedef union { + bool bool_val; + float float_val; + double double_val; + int32_t int32_val; + int64_t int64_val; + uint32_t uint32_val; + uint64_t uint64_val; + const struct upb_Array* array_val; + const struct upb_Map* map_val; + const struct upb_Message* msg_val; + upb_StringView str_val; + + // EXPERIMENTAL: A tagged upb_Message*. Users must use this instead of + // msg_val if unlinked sub-messages may possibly be in use. See the + // documentation in kUpb_DecodeOption_ExperimentalAllowUnlinked for more + // information. + upb_TaggedMessagePtr tagged_msg_val; +} upb_MessageValue; + +typedef union { + struct upb_Array* array; + struct upb_Map* map; + struct upb_Message* msg; +} upb_MutableMessageValue; + +#endif /* UPB_MESSAGE_VALUE_H_ */ + +// Must be last. + +typedef struct upb_Array upb_Array; + +#ifdef __cplusplus +extern "C" { +#endif -UPB_INLINE bool _upb_Map_Delete(struct upb_Map* map, const void* key, - size_t key_size, upb_value* val) { - upb_StringView k = _upb_map_tokey(key, key_size); - return upb_strtable_remove2(&map->table, k.data, k.size, val); -} +// Creates a new array on the given arena that holds elements of this type. +UPB_API upb_Array* upb_Array_New(upb_Arena* a, upb_CType type); -UPB_INLINE bool _upb_Map_Get(const struct upb_Map* map, const void* key, - size_t key_size, void* val, size_t val_size) { - upb_value tabval; - upb_StringView k = _upb_map_tokey(key, key_size); - bool ret = upb_strtable_lookup2(&map->table, k.data, k.size, &tabval); - if (ret && val) { - _upb_map_fromvalue(tabval, val, val_size); - } - return ret; -} +// Returns the number of elements in the array. +UPB_API size_t upb_Array_Size(const upb_Array* arr); -UPB_INLINE upb_MapInsertStatus _upb_Map_Insert(struct upb_Map* map, - const void* key, size_t key_size, - void* val, size_t val_size, - upb_Arena* a) { - upb_StringView strkey = _upb_map_tokey(key, key_size); - upb_value tabval = {0}; - if (!_upb_map_tovalue(val, val_size, &tabval, a)) { - return kUpb_MapInsertStatus_OutOfMemory; - } +// Returns the given element, which must be within the array's current size. +UPB_API upb_MessageValue upb_Array_Get(const upb_Array* arr, size_t i); - // TODO: add overwrite operation to minimize number of lookups. - bool removed = - upb_strtable_remove2(&map->table, strkey.data, strkey.size, NULL); - if (!upb_strtable_insert(&map->table, strkey.data, strkey.size, tabval, a)) { - return kUpb_MapInsertStatus_OutOfMemory; - } - return removed ? kUpb_MapInsertStatus_Replaced - : kUpb_MapInsertStatus_Inserted; -} +// Sets the given element, which must be within the array's current size. +UPB_API void upb_Array_Set(upb_Array* arr, size_t i, upb_MessageValue val); -UPB_INLINE size_t _upb_Map_Size(const struct upb_Map* map) { - return map->table.t.count; -} +// Appends an element to the array. Returns false on allocation failure. +UPB_API bool upb_Array_Append(upb_Array* array, upb_MessageValue val, + upb_Arena* arena); -// Strings/bytes are special-cased in maps. -extern char _upb_Map_CTypeSizeTable[12]; +// Moves elements within the array using memmove(). +// Like memmove(), the source and destination elements may be overlapping. +UPB_API void upb_Array_Move(upb_Array* array, size_t dst_idx, size_t src_idx, + size_t count); -UPB_INLINE size_t _upb_Map_CTypeSize(upb_CType ctype) { - return _upb_Map_CTypeSizeTable[ctype]; -} +// Inserts one or more empty elements into the array. +// Existing elements are shifted right. +// The new elements have undefined state and must be set with `upb_Array_Set()`. +// REQUIRES: `i <= upb_Array_Size(arr)` +UPB_API bool upb_Array_Insert(upb_Array* array, size_t i, size_t count, + upb_Arena* arena); -// Creates a new map on the given arena with this key/value type. -struct upb_Map* _upb_Map_New(upb_Arena* a, size_t key_size, size_t value_size); +// Deletes one or more elements from the array. +// Existing elements are shifted left. +// REQUIRES: `i + count <= upb_Array_Size(arr)` +UPB_API void upb_Array_Delete(upb_Array* array, size_t i, size_t count); + +// Changes the size of a vector. New elements are initialized to NULL/0. +// Returns false on allocation failure. +UPB_API bool upb_Array_Resize(upb_Array* array, size_t size, upb_Arena* arena); + +// Returns pointer to array data. +UPB_API const void* upb_Array_DataPtr(const upb_Array* arr); + +// Returns mutable pointer to array data. +UPB_API void* upb_Array_MutableDataPtr(upb_Array* arr); #ifdef __cplusplus } /* extern "C" */ #endif -#endif /* UPB_MESSAGE_INTERNAL_MAP_H_ */ +#endif /* UPB_MESSAGE_ARRAY_H_ */ + +#ifndef UPB_MESSAGE_INTERNAL_ACCESSORS_H_ +#define UPB_MESSAGE_INTERNAL_ACCESSORS_H_ + +#include +#include +#include + // Must be last. @@ -2526,7 +2515,7 @@ extern "C" { // Hasbit access /////////////////////////////////////////////////////////////// UPB_INLINE bool UPB_PRIVATE(_upb_Message_GetHasbit)( - const upb_Message* msg, const upb_MiniTableField* f) { + const struct upb_Message* msg, const upb_MiniTableField* f) { const size_t offset = UPB_PRIVATE(_upb_MiniTableField_HasbitOffset)(f); const char mask = UPB_PRIVATE(_upb_MiniTableField_HasbitMask)(f); @@ -2534,7 +2523,7 @@ UPB_INLINE bool UPB_PRIVATE(_upb_Message_GetHasbit)( } UPB_INLINE void UPB_PRIVATE(_upb_Message_SetHasbit)( - const upb_Message* msg, const upb_MiniTableField* f) { + const struct upb_Message* msg, const upb_MiniTableField* f) { const size_t offset = UPB_PRIVATE(_upb_MiniTableField_HasbitOffset)(f); const char mask = UPB_PRIVATE(_upb_MiniTableField_HasbitMask)(f); @@ -2542,7 +2531,7 @@ UPB_INLINE void UPB_PRIVATE(_upb_Message_SetHasbit)( } UPB_INLINE void UPB_PRIVATE(_upb_Message_ClearHasbit)( - const upb_Message* msg, const upb_MiniTableField* f) { + const struct upb_Message* msg, const upb_MiniTableField* f) { const size_t offset = UPB_PRIVATE(_upb_MiniTableField_HasbitOffset)(f); const char mask = UPB_PRIVATE(_upb_MiniTableField_HasbitMask)(f); @@ -2552,18 +2541,18 @@ UPB_INLINE void UPB_PRIVATE(_upb_Message_ClearHasbit)( // Oneof case access /////////////////////////////////////////////////////////// UPB_INLINE uint32_t* UPB_PRIVATE(_upb_Message_OneofCasePtr)( - upb_Message* msg, const upb_MiniTableField* f) { + struct upb_Message* msg, const upb_MiniTableField* f) { return UPB_PTR_AT(msg, UPB_PRIVATE(_upb_MiniTableField_OneofOffset)(f), uint32_t); } UPB_INLINE uint32_t UPB_PRIVATE(_upb_Message_GetOneofCase)( - const upb_Message* msg, const upb_MiniTableField* f) { - return *UPB_PRIVATE(_upb_Message_OneofCasePtr)((upb_Message*)msg, f); + const struct upb_Message* msg, const upb_MiniTableField* f) { + return *UPB_PRIVATE(_upb_Message_OneofCasePtr)((struct upb_Message*)msg, f); } UPB_INLINE void UPB_PRIVATE(_upb_Message_SetOneofCase)( - upb_Message* msg, const upb_MiniTableField* f) { + struct upb_Message* msg, const upb_MiniTableField* f) { *UPB_PRIVATE(_upb_Message_OneofCasePtr)(msg, f) = upb_MiniTableField_Number(f); } @@ -2572,18 +2561,18 @@ UPB_INLINE void UPB_PRIVATE(_upb_Message_SetOneofCase)( // LINT.ThenChange(GoogleInternalName2) -UPB_INLINE void* _upb_MiniTableField_GetPtr(upb_Message* msg, +UPB_INLINE void* _upb_MiniTableField_GetPtr(struct upb_Message* msg, const upb_MiniTableField* field) { return (char*)msg + field->UPB_ONLYBITS(offset); } UPB_INLINE const void* _upb_MiniTableField_GetConstPtr( - const upb_Message* msg, const upb_MiniTableField* field) { + const struct upb_Message* msg, const upb_MiniTableField* field) { return (char*)msg + field->UPB_ONLYBITS(offset); } UPB_INLINE void UPB_PRIVATE(_upb_Message_SetPresence)( - upb_Message* msg, const upb_MiniTableField* field) { + struct upb_Message* msg, const upb_MiniTableField* field) { if (field->presence > 0) { UPB_PRIVATE(_upb_Message_SetHasbit)(msg, field); } else if (upb_MiniTableField_IsInOneof(field)) { @@ -2669,13 +2658,13 @@ UPB_INLINE void UPB_PRIVATE(_upb_MiniTableField_DataCopy)( // returned bool value may be ignored since it will always succeed. UPB_INLINE bool _upb_Message_HasExtensionField( - const upb_Message* msg, const upb_MiniTableExtension* ext) { + const struct upb_Message* msg, const upb_MiniTableExtension* ext) { UPB_ASSERT(upb_MiniTableField_HasPresence(&ext->UPB_PRIVATE(field))); return _upb_Message_Getext(msg, ext) != NULL; } UPB_INLINE bool _upb_Message_HasNonExtensionField( - const upb_Message* msg, const upb_MiniTableField* field) { + const struct upb_Message* msg, const upb_MiniTableField* field) { UPB_ASSERT(upb_MiniTableField_HasPresence(field)); UPB_ASSUME(!upb_MiniTableField_IsExtension(field)); if (upb_MiniTableField_IsInOneof(field)) { @@ -2687,7 +2676,7 @@ UPB_INLINE bool _upb_Message_HasNonExtensionField( } static UPB_FORCEINLINE void _upb_Message_GetNonExtensionField( - const upb_Message* msg, const upb_MiniTableField* field, + const struct upb_Message* msg, const upb_MiniTableField* field, const void* default_val, void* val) { UPB_ASSUME(!upb_MiniTableField_IsExtension(field)); if ((upb_MiniTableField_IsInOneof(field) || @@ -2701,7 +2690,7 @@ static UPB_FORCEINLINE void _upb_Message_GetNonExtensionField( } UPB_INLINE void _upb_Message_GetExtensionField( - const upb_Message* msg, const upb_MiniTableExtension* mt_ext, + const struct upb_Message* msg, const upb_MiniTableExtension* mt_ext, const void* default_val, void* val) { const struct upb_Extension* ext = _upb_Message_Getext(msg, mt_ext); const upb_MiniTableField* f = &mt_ext->UPB_PRIVATE(field); @@ -2714,240 +2703,279 @@ UPB_INLINE void _upb_Message_GetExtensionField( } } -// Gets a mutable Array, Map or Message field. -// NOTE: For repeated/map fields, the resulting upb_Array*/upb_Map* can -// be NULL if a upb_Array/upb_Map has not been allocated yet. Array/map -// fields do not have presence, so this is semantically identical to a -// pointer to an empty array/map, and must be treated the same for all -// semantic purposes. -// -// For message fields, the pointer is guaranteed to be NULL iff the field -// is unset (as message fields do have presence). -UPB_INLINE upb_MutableMessageValue _upb_Message_GetMutableField( - const upb_Message* msg, const upb_MiniTableField* field) { - UPB_ASSUME(!upb_MiniTableField_IsScalar(field) || - upb_MiniTableField_IsSubMessage(field)); +UPB_INLINE void _upb_Message_SetNonExtensionField( + struct upb_Message* msg, const upb_MiniTableField* field, const void* val) { + UPB_ASSUME(!upb_MiniTableField_IsExtension(field)); + UPB_PRIVATE(_upb_Message_SetPresence)(msg, field); + UPB_PRIVATE(_upb_MiniTableField_DataCopy) + (field, _upb_MiniTableField_GetPtr(msg, field), val); +} - upb_MutableMessageValue default_val; - default_val.msg = NULL; +UPB_INLINE bool _upb_Message_SetExtensionField( + struct upb_Message* msg, const upb_MiniTableExtension* mt_ext, + const void* val, upb_Arena* a) { + UPB_ASSERT(a); + struct upb_Extension* ext = _upb_Message_GetOrCreateExtension(msg, mt_ext, a); + if (!ext) return false; + UPB_PRIVATE(_upb_MiniTableField_DataCopy) + (&mt_ext->UPB_PRIVATE(field), &ext->data, val); + return true; +} - upb_MutableMessageValue ret; - if (upb_MiniTableField_IsExtension(field)) { - _upb_Message_GetExtensionField(msg, (upb_MiniTableExtension*)field, - &default_val, &ret); - } else { - _upb_Message_GetNonExtensionField(msg, field, &default_val, &ret); +UPB_INLINE void _upb_Message_ClearExtensionField( + struct upb_Message* msg, const upb_MiniTableExtension* ext_l) { + upb_Message_Internal* in = upb_Message_Getinternal(msg); + if (!in->internal) return; + const struct upb_Extension* base = + UPB_PTR_AT(in->internal, in->internal->ext_begin, struct upb_Extension); + struct upb_Extension* ext = + (struct upb_Extension*)_upb_Message_Getext(msg, ext_l); + if (ext) { + *ext = *base; + in->internal->ext_begin += sizeof(struct upb_Extension); } - return ret; } -UPB_INLINE void _upb_Message_SetNonExtensionField( - upb_Message* msg, const upb_MiniTableField* field, const void* val) { - UPB_ASSUME(!upb_MiniTableField_IsExtension(field)); - UPB_PRIVATE(_upb_Message_SetPresence)(msg, field); +UPB_INLINE void _upb_Message_ClearNonExtensionField( + struct upb_Message* msg, const upb_MiniTableField* field) { + if (field->presence > 0) { + UPB_PRIVATE(_upb_Message_ClearHasbit)(msg, field); + } else if (upb_MiniTableField_IsInOneof(field)) { + uint32_t* ptr = UPB_PRIVATE(_upb_Message_OneofCasePtr)(msg, field); + if (*ptr != upb_MiniTableField_Number(field)) return; + *ptr = 0; + } + const char zeros[16] = {0}; UPB_PRIVATE(_upb_MiniTableField_DataCopy) - (field, _upb_MiniTableField_GetPtr(msg, field), val); + (field, _upb_MiniTableField_GetPtr(msg, field), zeros); +} + +UPB_INLINE void _upb_Message_AssertMapIsUntagged( + const struct upb_Message* msg, const upb_MiniTableField* field) { + UPB_UNUSED(msg); + UPB_PRIVATE(_upb_MiniTableField_CheckIsMap)(field); +#ifndef NDEBUG + upb_TaggedMessagePtr default_val = 0; + upb_TaggedMessagePtr tagged; + _upb_Message_GetNonExtensionField(msg, field, &default_val, &tagged); + UPB_ASSERT(!UPB_PRIVATE(_upb_TaggedMessagePtr_IsEmpty)(tagged)); +#endif +} + +UPB_INLINE struct upb_Map* _upb_Message_GetOrCreateMutableMap( + struct upb_Message* msg, const upb_MiniTableField* field, size_t key_size, + size_t val_size, upb_Arena* arena) { + UPB_PRIVATE(_upb_MiniTableField_CheckIsMap)(field); + _upb_Message_AssertMapIsUntagged(msg, field); + struct upb_Map* map = NULL; + struct upb_Map* default_map_value = NULL; + _upb_Message_GetNonExtensionField(msg, field, &default_map_value, &map); + if (!map) { + map = _upb_Map_New(arena, key_size, val_size); + // Check again due to: https://godbolt.org/z/7WfaoKG1r + UPB_PRIVATE(_upb_MiniTableField_CheckIsMap)(field); + _upb_Message_SetNonExtensionField(msg, field, &map); + } + return map; +} + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#if defined(__GNUC__) && !defined(__clang__) +#pragma GCC diagnostic pop +#endif + + +#endif // UPB_MESSAGE_INTERNAL_ACCESSORS_H_ + +#ifndef UPB_MESSAGE_MAP_H_ +#define UPB_MESSAGE_MAP_H_ + +#include + + +// Must be last. + +typedef struct upb_Map upb_Map; + +#ifdef __cplusplus +extern "C" { +#endif + +// Creates a new map on the given arena with the given key/value size. +UPB_API upb_Map* upb_Map_New(upb_Arena* a, upb_CType key_type, + upb_CType value_type); + +// Returns the number of entries in the map. +UPB_API size_t upb_Map_Size(const upb_Map* map); + +// Stores a value for the given key into |*val| (or the zero value if the key is +// not present). Returns whether the key was present. The |val| pointer may be +// NULL, in which case the function tests whether the given key is present. +UPB_API bool upb_Map_Get(const upb_Map* map, upb_MessageValue key, + upb_MessageValue* val); + +// Removes all entries in the map. +UPB_API void upb_Map_Clear(upb_Map* map); + +// Sets the given key to the given value, returning whether the key was inserted +// or replaced. If the key was inserted, then any existing iterators will be +// invalidated. +UPB_API upb_MapInsertStatus upb_Map_Insert(upb_Map* map, upb_MessageValue key, + upb_MessageValue val, + upb_Arena* arena); + +// Sets the given key to the given value. Returns false if memory allocation +// failed. If the key is newly inserted, then any existing iterators will be +// invalidated. +UPB_API_INLINE bool upb_Map_Set(upb_Map* map, upb_MessageValue key, + upb_MessageValue val, upb_Arena* arena) { + return upb_Map_Insert(map, key, val, arena) != + kUpb_MapInsertStatus_OutOfMemory; +} + +// Deletes this key from the table. Returns true if the key was present. +// If present and |val| is non-NULL, stores the deleted value. +UPB_API bool upb_Map_Delete(upb_Map* map, upb_MessageValue key, + upb_MessageValue* val); + +// (DEPRECATED and going away soon. Do not use.) +UPB_INLINE bool upb_Map_Delete2(upb_Map* map, upb_MessageValue key, + upb_MessageValue* val) { + return upb_Map_Delete(map, key, val); } -UPB_INLINE bool _upb_Message_SetExtensionField( - upb_Message* msg, const upb_MiniTableExtension* mt_ext, const void* val, - upb_Arena* a) { - UPB_ASSERT(a); - struct upb_Extension* ext = _upb_Message_GetOrCreateExtension(msg, mt_ext, a); - if (!ext) return false; - UPB_PRIVATE(_upb_MiniTableField_DataCopy) - (&mt_ext->UPB_PRIVATE(field), &ext->data, val); - return true; -} +// Map iteration: +// +// size_t iter = kUpb_Map_Begin; +// upb_MessageValue key, val; +// while (upb_Map_Next(map, &key, &val, &iter)) { +// ... +// } + +#define kUpb_Map_Begin ((size_t)-1) + +// Advances to the next entry. Returns false if no more entries are present. +// Otherwise returns true and populates both *key and *value. +UPB_API bool upb_Map_Next(const upb_Map* map, upb_MessageValue* key, + upb_MessageValue* val, size_t* iter); + +// Sets the value for the entry pointed to by iter. +// WARNING: this does not currently work for string values! +UPB_API void upb_Map_SetEntryValue(upb_Map* map, size_t iter, + upb_MessageValue val); + +// DEPRECATED iterator, slated for removal. -UPB_INLINE void _upb_Message_ClearExtensionField( - upb_Message* msg, const upb_MiniTableExtension* ext_l) { - upb_Message_Internal* in = upb_Message_Getinternal(msg); - if (!in->internal) return; - const struct upb_Extension* base = - UPB_PTR_AT(in->internal, in->internal->ext_begin, struct upb_Extension); - struct upb_Extension* ext = - (struct upb_Extension*)_upb_Message_Getext(msg, ext_l); - if (ext) { - *ext = *base; - in->internal->ext_begin += sizeof(struct upb_Extension); - } -} +/* Map iteration: + * + * size_t iter = kUpb_Map_Begin; + * while (upb_MapIterator_Next(map, &iter)) { + * upb_MessageValue key = upb_MapIterator_Key(map, iter); + * upb_MessageValue val = upb_MapIterator_Value(map, iter); + * } + */ -UPB_INLINE void _upb_Message_ClearNonExtensionField( - upb_Message* msg, const upb_MiniTableField* field) { - if (field->presence > 0) { - UPB_PRIVATE(_upb_Message_ClearHasbit)(msg, field); - } else if (upb_MiniTableField_IsInOneof(field)) { - uint32_t* ptr = UPB_PRIVATE(_upb_Message_OneofCasePtr)(msg, field); - if (*ptr != upb_MiniTableField_Number(field)) return; - *ptr = 0; - } - const char zeros[16] = {0}; - UPB_PRIVATE(_upb_MiniTableField_DataCopy) - (field, _upb_MiniTableField_GetPtr(msg, field), zeros); -} +// Advances to the next entry. Returns false if no more entries are present. +UPB_API bool upb_MapIterator_Next(const upb_Map* map, size_t* iter); -UPB_INLINE void _upb_Message_AssertMapIsUntagged( - const upb_Message* msg, const upb_MiniTableField* field) { - UPB_UNUSED(msg); - UPB_PRIVATE(_upb_MiniTableField_CheckIsMap)(field); -#ifndef NDEBUG - upb_TaggedMessagePtr default_val = 0; - upb_TaggedMessagePtr tagged; - _upb_Message_GetNonExtensionField(msg, field, &default_val, &tagged); - UPB_ASSERT(!upb_TaggedMessagePtr_IsEmpty(tagged)); -#endif -} +// Returns true if the iterator still points to a valid entry, or false if the +// iterator is past the last element. It is an error to call this function with +// kUpb_Map_Begin (you must call next() at least once first). +UPB_API bool upb_MapIterator_Done(const upb_Map* map, size_t iter); -UPB_INLINE struct upb_Map* _upb_Message_GetOrCreateMutableMap( - upb_Message* msg, const upb_MiniTableField* field, size_t key_size, - size_t val_size, upb_Arena* arena) { - UPB_PRIVATE(_upb_MiniTableField_CheckIsMap)(field); - _upb_Message_AssertMapIsUntagged(msg, field); - struct upb_Map* map = NULL; - struct upb_Map* default_map_value = NULL; - _upb_Message_GetNonExtensionField(msg, field, &default_map_value, &map); - if (!map) { - map = _upb_Map_New(arena, key_size, val_size); - // Check again due to: https://godbolt.org/z/7WfaoKG1r - UPB_PRIVATE(_upb_MiniTableField_CheckIsMap)(field); - _upb_Message_SetNonExtensionField(msg, field, &map); - } - return map; -} +// Returns the key and value for this entry of the map. +UPB_API upb_MessageValue upb_MapIterator_Key(const upb_Map* map, size_t iter); +UPB_API upb_MessageValue upb_MapIterator_Value(const upb_Map* map, size_t iter); #ifdef __cplusplus } /* extern "C" */ #endif -#if defined(__GNUC__) && !defined(__clang__) -#pragma GCC diagnostic pop -#endif +#endif /* UPB_MESSAGE_MAP_H_ */ -#endif // UPB_MESSAGE_INTERNAL_ACCESSORS_H_ +#ifndef UPB_MINI_TABLE_TAGGED_PTR_H_ +#define UPB_MINI_TABLE_TAGGED_PTR_H_ -#ifndef UPB_MESSAGE_INTERNAL_ARRAY_H_ -#define UPB_MESSAGE_INTERNAL_ARRAY_H_ +#include -#include + +// Public APIs for message operations that do not depend on the schema. +// +// MiniTable-based accessors live in accessors.h. + +#ifndef UPB_MESSAGE_MESSAGE_H_ +#define UPB_MESSAGE_MESSAGE_H_ + +#include // Must be last. -#define _UPB_ARRAY_MASK_IMM 0x4 // Frozen/immutable bit. -#define _UPB_ARRAY_MASK_LG2 0x3 // Encoded elem size. -#define _UPB_ARRAY_MASK_ALL (_UPB_ARRAY_MASK_IMM | _UPB_ARRAY_MASK_LG2) +typedef struct upb_Extension upb_Extension; +typedef struct upb_Message upb_Message; #ifdef __cplusplus extern "C" { #endif -// LINT.IfChange(struct_definition) -// Our internal representation for repeated fields. -struct upb_Array { - // This is a tagged pointer. Bits #0 and #1 encode the elem size as follows: - // 0 maps to elem size 1 - // 1 maps to elem size 4 - // 2 maps to elem size 8 - // 3 maps to elem size 16 - // - // Bit #2 contains the frozen/immutable flag (currently unimplemented). - uintptr_t data; +// Creates a new message with the given mini_table on the given arena. +UPB_API upb_Message* upb_Message_New(const upb_MiniTable* m, upb_Arena* arena); - size_t UPB_ONLYBITS(size); // The number of elements in the array. - size_t UPB_PRIVATE(capacity); // Allocated storage. Measured in elements. -}; +// Returns a reference to the message's unknown data. +const char* upb_Message_GetUnknown(const upb_Message* msg, size_t* len); -UPB_INLINE void UPB_PRIVATE(_upb_Array_SetTaggedPtr)(struct upb_Array* array, - void* data, size_t lg2) { - UPB_ASSERT(lg2 != 1); - UPB_ASSERT(lg2 <= 4); - const size_t bits = lg2 - (lg2 != 0); - array->data = (uintptr_t)data | bits; -} +// Removes partial unknown data from message. +void upb_Message_DeleteUnknown(upb_Message* msg, const char* data, size_t len); -UPB_INLINE size_t -UPB_PRIVATE(_upb_Array_ElemSizeLg2)(const struct upb_Array* array) { - const size_t bits = array->data & _UPB_ARRAY_MASK_LG2; - const size_t lg2 = bits + (bits != 0); - return lg2; -} +// Returns the number of extensions present in this message. +size_t upb_Message_ExtensionCount(const upb_Message* msg); -UPB_INLINE const void* _upb_array_constptr(const struct upb_Array* array) { - UPB_PRIVATE(_upb_Array_ElemSizeLg2)(array); // Check assertions. - return (void*)(array->data & ~(uintptr_t)_UPB_ARRAY_MASK_ALL); -} +#ifdef __cplusplus +} /* extern "C" */ +#endif -UPB_INLINE void* _upb_array_ptr(struct upb_Array* array) { - return (void*)_upb_array_constptr(array); -} -UPB_INLINE struct upb_Array* UPB_PRIVATE(_upb_Array_New)(upb_Arena* arena, - size_t init_capacity, - int elem_size_lg2) { - UPB_ASSERT(elem_size_lg2 != 1); - UPB_ASSERT(elem_size_lg2 <= 4); - const size_t array_size = - UPB_ALIGN_UP(sizeof(struct upb_Array), UPB_MALLOC_ALIGN); - const size_t bytes = array_size + (init_capacity << elem_size_lg2); - struct upb_Array* array = (struct upb_Array*)upb_Arena_Malloc(arena, bytes); - if (!array) return NULL; - UPB_PRIVATE(_upb_Array_SetTaggedPtr) - (array, UPB_PTR_AT(array, array_size, void), elem_size_lg2); - array->UPB_ONLYBITS(size) = 0; - array->UPB_PRIVATE(capacity) = init_capacity; - return array; -} +#endif /* UPB_MESSAGE_MESSAGE_H_ */ -// Resizes the capacity of the array to be at least min_size. -bool UPB_PRIVATE(_upb_Array_Realloc)(struct upb_Array* array, size_t min_size, - upb_Arena* arena); +// Must be last. -UPB_INLINE bool UPB_PRIVATE(_upb_Array_Reserve)(struct upb_Array* array, - size_t size, upb_Arena* arena) { - if (array->UPB_PRIVATE(capacity) < size) - return UPB_PRIVATE(_upb_Array_Realloc)(array, size, arena); - return true; -} +// 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 +// that field's true message type. This forms the basis of what we call +// "dynamic tree shaking." +// +// See the documentation for kUpb_DecodeOption_ExperimentalAllowUnlinked for +// more information. -// Resize without initializing new elements. -UPB_INLINE bool _upb_Array_ResizeUninitialized(struct upb_Array* array, - size_t size, upb_Arena* arena) { - UPB_ASSERT(size <= array->UPB_ONLYBITS(size) || - arena); // Allow NULL arena when shrinking. - if (!UPB_PRIVATE(_upb_Array_Reserve)(array, size, arena)) return false; - array->UPB_ONLYBITS(size) = size; - return true; -} +typedef uintptr_t upb_TaggedMessagePtr; -// This function is intended for situations where elem_size is compile-time -// constant or a known expression of the form (1 << lg2), so that the expression -// i*elem_size does not result in an actual multiplication. -UPB_INLINE void UPB_PRIVATE(_upb_Array_Set)(struct upb_Array* array, size_t i, - const void* data, - size_t elem_size) { - UPB_ASSERT(i < array->UPB_ONLYBITS(size)); - UPB_ASSERT(elem_size == 1U << UPB_PRIVATE(_upb_Array_ElemSizeLg2)(array)); - char* arr_data = (char*)_upb_array_ptr(array); - memcpy(arr_data + (i * elem_size), data, elem_size); +#ifdef __cplusplus +extern "C" { +#endif + +// Users who enable unlinked sub-messages must use this to test whether a +// message is empty before accessing it. If a message is empty, it must be +// first promoted using the interfaces in message/promote.h. +UPB_INLINE bool upb_TaggedMessagePtr_IsEmpty(upb_TaggedMessagePtr ptr) { + return UPB_PRIVATE(_upb_TaggedMessagePtr_IsEmpty)(ptr); } -// LINT.ThenChange( -// GoogleInternalName1, -//) +UPB_INLINE upb_Message* upb_TaggedMessagePtr_GetNonEmptyMessage( + upb_TaggedMessagePtr ptr) { + return UPB_PRIVATE(_upb_TaggedMessagePtr_GetNonEmptyMessage)(ptr); +} #ifdef __cplusplus } /* extern "C" */ #endif -#undef _UPB_ARRAY_MASK_IMM -#undef _UPB_ARRAY_MASK_LG2 -#undef _UPB_ARRAY_MASK_ALL - -#endif /* UPB_MESSAGE_INTERNAL_ARRAY_H_ */ +#endif /* UPB_MINI_TABLE_TAGGED_PTR_H_ */ #ifndef UPB_MINI_TABLE_SUB_H_ #define UPB_MINI_TABLE_SUB_H_ @@ -3316,7 +3344,8 @@ UPB_API_INLINE void upb_Message_SetMessage(upb_Message* msg, const upb_MiniTableField* field, upb_Message* sub_message) { _upb_Message_SetTaggedMessagePtr( - msg, mini_table, field, _upb_TaggedMessagePtr_Pack(sub_message, false)); + msg, mini_table, field, + UPB_PRIVATE(_upb_TaggedMessagePtr_Pack)(sub_message, false)); } UPB_API_INLINE upb_Message* upb_Message_GetOrCreateMutableMessage( @@ -3469,43 +3498,6 @@ UPB_INLINE void _upb_msg_map_set_value(void* msg, const void* val, #endif /* UPB_MESSAGE_MAP_GENCODE_UTIL_H_ */ -// Public APIs for message operations that do not depend on the schema. -// -// MiniTable-based accessors live in accessors.h. - -#ifndef UPB_MESSAGE_MESSAGE_H_ -#define UPB_MESSAGE_MESSAGE_H_ - -#include - - -// Must be last. - -typedef struct upb_Extension upb_Extension; - -#ifdef __cplusplus -extern "C" { -#endif - -// Creates a new message with the given mini_table on the given arena. -UPB_API upb_Message* upb_Message_New(const upb_MiniTable* m, upb_Arena* arena); - -// Returns a reference to the message's unknown data. -const char* upb_Message_GetUnknown(const upb_Message* msg, size_t* len); - -// Removes partial unknown data from message. -void upb_Message_DeleteUnknown(upb_Message* msg, const char* data, size_t len); - -// Returns the number of extensions present in this message. -size_t upb_Message_ExtensionCount(const upb_Message* msg); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - - -#endif /* UPB_MESSAGE_MESSAGE_H_ */ - #ifndef UPB_MINI_TABLE_DECODE_H_ #define UPB_MINI_TABLE_DECODE_H_ @@ -12639,7 +12631,8 @@ UPB_INLINE void _upb_mapsorter_destroy(_upb_mapsorter* s) { if (s->entries) upb_gfree(s->entries); } -UPB_INLINE bool _upb_sortedmap_next(_upb_mapsorter* s, const upb_Map* map, +UPB_INLINE bool _upb_sortedmap_next(_upb_mapsorter* s, + const struct upb_Map* map, _upb_sortedmap* sorted, upb_MapEntry* ent) { if (sorted->pos == sorted->end) return false; const upb_tabent* tabent = (const upb_tabent*)s->entries[sorted->pos++]; @@ -12664,7 +12657,7 @@ UPB_INLINE void _upb_mapsorter_popmap(_upb_mapsorter* s, } bool _upb_mapsorter_pushmap(_upb_mapsorter* s, upb_FieldType key_type, - const upb_Map* map, _upb_sortedmap* sorted); + const struct upb_Map* map, _upb_sortedmap* sorted); bool _upb_mapsorter_pushexts(_upb_mapsorter* s, const struct upb_Extension* exts, size_t count, diff --git a/ruby/ext/google/protobuf_c/ruby-upb.c b/ruby/ext/google/protobuf_c/ruby-upb.c index d2ea1895bc53f..037a4d21dbabe 100644 --- a/ruby/ext/google/protobuf_c/ruby-upb.c +++ b/ruby/ext/google/protobuf_c/ruby-upb.c @@ -5686,104 +5686,6 @@ const upb_Extension* upb_Message_FindExtensionByNumber(const upb_Message* msg, #include -// Must be last. - -const struct upb_Extension* _upb_Message_Getext( - const upb_Message* msg, const upb_MiniTableExtension* e) { - size_t n; - const struct upb_Extension* ext = UPB_PRIVATE(_upb_Message_Getexts)(msg, &n); - - // For now we use linear search exclusively to find extensions. - // If this becomes an issue due to messages with lots of extensions, - // we can introduce a table of some sort. - for (size_t i = 0; i < n; i++) { - if (ext[i].ext == e) { - return &ext[i]; - } - } - - return NULL; -} - -const struct upb_Extension* UPB_PRIVATE(_upb_Message_Getexts)( - const upb_Message* msg, size_t* count) { - const upb_Message_Internal* in = upb_Message_Getinternal(msg); - if (in->internal) { - *count = (in->internal->size - in->internal->ext_begin) / - sizeof(struct upb_Extension); - return UPB_PTR_AT(in->internal, in->internal->ext_begin, void); - } else { - *count = 0; - return NULL; - } -} - -struct upb_Extension* _upb_Message_GetOrCreateExtension( - upb_Message* msg, const upb_MiniTableExtension* e, upb_Arena* arena) { - struct upb_Extension* ext = - (struct upb_Extension*)_upb_Message_Getext(msg, e); - if (ext) return ext; - if (!UPB_PRIVATE(_upb_Message_Realloc)(msg, sizeof(struct upb_Extension), - arena)) - return NULL; - upb_Message_Internal* in = upb_Message_Getinternal(msg); - in->internal->ext_begin -= sizeof(struct upb_Extension); - ext = UPB_PTR_AT(in->internal, in->internal->ext_begin, void); - memset(ext, 0, sizeof(struct upb_Extension)); - ext->ext = e; - return ext; -} - - -#include -#include - - -// Must be last. - -const float kUpb_FltInfinity = INFINITY; -const double kUpb_Infinity = INFINITY; -const double kUpb_NaN = NAN; - -static const size_t realloc_overhead = sizeof(upb_Message_InternalData); - -bool UPB_PRIVATE(_upb_Message_Realloc)(struct upb_Message* msg, size_t need, - upb_Arena* arena) { - upb_Message_Internal* in = upb_Message_Getinternal(msg); - if (!in->internal) { - // No internal data, allocate from scratch. - size_t size = UPB_MAX(128, upb_Log2CeilingSize(need + realloc_overhead)); - upb_Message_InternalData* internal = upb_Arena_Malloc(arena, size); - if (!internal) return false; - internal->size = size; - internal->unknown_end = realloc_overhead; - internal->ext_begin = size; - in->internal = internal; - } else if (in->internal->ext_begin - in->internal->unknown_end < need) { - // Internal data is too small, reallocate. - size_t new_size = upb_Log2CeilingSize(in->internal->size + need); - size_t ext_bytes = in->internal->size - in->internal->ext_begin; - size_t new_ext_begin = new_size - ext_bytes; - upb_Message_InternalData* internal = - upb_Arena_Realloc(arena, in->internal, in->internal->size, new_size); - if (!internal) return false; - if (ext_bytes) { - // Need to move extension data to the end. - char* ptr = (char*)internal; - memmove(ptr + new_ext_begin, ptr + internal->ext_begin, ext_bytes); - } - internal->ext_begin = new_ext_begin; - internal->size = new_size; - in->internal = internal; - } - UPB_ASSERT(in->internal->ext_begin - in->internal->unknown_end >= need); - return true; -} - - -#include - - // Must be last. // Strings/bytes are special-cased in maps. @@ -6209,9 +6111,9 @@ static bool upb_Clone_MessageValue(void* value, upb_CType value_type, if (is_empty) sub = UPB_PRIVATE(_upb_MiniTable_Empty)(); UPB_ASSERT(source); upb_Message* clone = upb_Message_DeepClone( - _upb_TaggedMessagePtr_GetMessage(source), sub, arena); + UPB_PRIVATE(_upb_TaggedMessagePtr_GetMessage)(source), sub, arena); *(upb_TaggedMessagePtr*)value = - _upb_TaggedMessagePtr_Pack(clone, is_empty); + UPB_PRIVATE(_upb_TaggedMessagePtr_Pack)(clone, is_empty); return clone != NULL; } break; } @@ -6334,7 +6236,7 @@ upb_Message* _upb_Message_Copy(upb_Message* dst, const upb_Message* src, upb_TaggedMessagePtr tagged = upb_Message_GetTaggedMessagePtr(src, field, NULL); const upb_Message* sub_message = - _upb_TaggedMessagePtr_GetMessage(tagged); + UPB_PRIVATE(_upb_TaggedMessagePtr_GetMessage)(tagged); if (sub_message != NULL) { // If the message is currently in an unlinked, "empty" state we keep // it that way, because we don't want to deal with decode options, @@ -6350,7 +6252,8 @@ upb_Message* _upb_Message_Copy(upb_Message* dst, const upb_Message* src, } _upb_Message_SetTaggedMessagePtr( dst, mini_table, field, - _upb_TaggedMessagePtr_Pack(dst_sub_message, is_empty)); + UPB_PRIVATE(_upb_TaggedMessagePtr_Pack)(dst_sub_message, + is_empty)); } } break; case kUpb_CType_String: @@ -12317,7 +12220,8 @@ static upb_Message* _upb_Decoder_NewSubMessage(upb_Decoder* d, _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_UnlinkedSubMessage); } - upb_TaggedMessagePtr tagged = _upb_TaggedMessagePtr_Pack(msg, is_empty); + upb_TaggedMessagePtr tagged = + UPB_PRIVATE(_upb_TaggedMessagePtr_Pack)(msg, is_empty); memcpy(target, &tagged, sizeof(tagged)); return msg; } @@ -12330,13 +12234,14 @@ static upb_Message* _upb_Decoder_ReuseSubMessage( UPB_ASSERT(subl); if (!upb_TaggedMessagePtr_IsEmpty(tagged) || UPB_PRIVATE(_upb_MiniTable_IsEmpty)(subl)) { - return _upb_TaggedMessagePtr_GetMessage(tagged); + return UPB_PRIVATE(_upb_TaggedMessagePtr_GetMessage)(tagged); } // We found an empty message from a previous parse that was performed before // this field was linked. But it is linked now, so we want to allocate a new // message of the correct type and promote data into it before continuing. - upb_Message* existing = _upb_TaggedMessagePtr_GetEmptyMessage(tagged); + upb_Message* existing = + UPB_PRIVATE(_upb_TaggedMessagePtr_GetEmptyMessage)(tagged); upb_Message* promoted = _upb_Decoder_NewSubMessage(d, subs, field, target); size_t size; const char* unknown = upb_Message_GetUnknown(existing, &size); @@ -13629,7 +13534,8 @@ static void encode_TaggedMessagePtr(upb_encstate* e, if (upb_TaggedMessagePtr_IsEmpty(tagged)) { m = UPB_PRIVATE(_upb_MiniTable_Empty)(); } - encode_message(e, _upb_TaggedMessagePtr_GetMessage(tagged), m, size); + encode_message(e, UPB_PRIVATE(_upb_TaggedMessagePtr_GetMessage)(tagged), m, + size); } static void encode_scalar(upb_encstate* e, const void* _field_mem, @@ -15091,6 +14997,105 @@ const char* UPB_PRIVATE(_upb_WireReader_SkipGroup)( } +#include + + +// Must be last. + +const struct upb_Extension* _upb_Message_Getext( + const struct upb_Message* msg, const upb_MiniTableExtension* e) { + size_t n; + const struct upb_Extension* ext = UPB_PRIVATE(_upb_Message_Getexts)(msg, &n); + + // For now we use linear search exclusively to find extensions. + // If this becomes an issue due to messages with lots of extensions, + // we can introduce a table of some sort. + for (size_t i = 0; i < n; i++) { + if (ext[i].ext == e) { + return &ext[i]; + } + } + + return NULL; +} + +const struct upb_Extension* UPB_PRIVATE(_upb_Message_Getexts)( + const struct upb_Message* msg, size_t* count) { + const upb_Message_Internal* in = upb_Message_Getinternal(msg); + if (in->internal) { + *count = (in->internal->size - in->internal->ext_begin) / + sizeof(struct upb_Extension); + return UPB_PTR_AT(in->internal, in->internal->ext_begin, void); + } else { + *count = 0; + return NULL; + } +} + +struct upb_Extension* _upb_Message_GetOrCreateExtension( + struct upb_Message* msg, const upb_MiniTableExtension* e, + upb_Arena* arena) { + struct upb_Extension* ext = + (struct upb_Extension*)_upb_Message_Getext(msg, e); + if (ext) return ext; + if (!UPB_PRIVATE(_upb_Message_Realloc)(msg, sizeof(struct upb_Extension), + arena)) + return NULL; + upb_Message_Internal* in = upb_Message_Getinternal(msg); + in->internal->ext_begin -= sizeof(struct upb_Extension); + ext = UPB_PTR_AT(in->internal, in->internal->ext_begin, void); + memset(ext, 0, sizeof(struct upb_Extension)); + ext->ext = e; + return ext; +} + + +#include +#include + + +// Must be last. + +const float kUpb_FltInfinity = INFINITY; +const double kUpb_Infinity = INFINITY; +const double kUpb_NaN = NAN; + +static const size_t realloc_overhead = sizeof(upb_Message_InternalData); + +bool UPB_PRIVATE(_upb_Message_Realloc)(struct upb_Message* msg, size_t need, + upb_Arena* arena) { + upb_Message_Internal* in = upb_Message_Getinternal(msg); + if (!in->internal) { + // No internal data, allocate from scratch. + size_t size = UPB_MAX(128, upb_Log2CeilingSize(need + realloc_overhead)); + upb_Message_InternalData* internal = upb_Arena_Malloc(arena, size); + if (!internal) return false; + internal->size = size; + internal->unknown_end = realloc_overhead; + internal->ext_begin = size; + in->internal = internal; + } else if (in->internal->ext_begin - in->internal->unknown_end < need) { + // Internal data is too small, reallocate. + size_t new_size = upb_Log2CeilingSize(in->internal->size + need); + size_t ext_bytes = in->internal->size - in->internal->ext_begin; + size_t new_ext_begin = new_size - ext_bytes; + upb_Message_InternalData* internal = + upb_Arena_Realloc(arena, in->internal, in->internal->size, new_size); + if (!internal) return false; + if (ext_bytes) { + // Need to move extension data to the end. + char* ptr = (char*)internal; + memmove(ptr + new_ext_begin, ptr + internal->ext_begin, ext_bytes); + } + internal->ext_begin = new_ext_begin; + internal->size = new_size; + in->internal = internal; + } + UPB_ASSERT(in->internal->ext_begin - in->internal->unknown_end >= need); + return true; +} + + const char _kUpb_ToBase92[] = { ' ', '!', '#', '$', '%', '&', '(', ')', '*', '+', ',', '-', '.', '/', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '<', '=', diff --git a/ruby/ext/google/protobuf_c/ruby-upb.h b/ruby/ext/google/protobuf_c/ruby-upb.h index 73437cecebf4c..59d543cc25dbd 100755 --- a/ruby/ext/google/protobuf_c/ruby-upb.h +++ b/ruby/ext/google/protobuf_c/ruby-upb.h @@ -827,678 +827,667 @@ UPB_API_INLINE void upb_Arena_ShrinkLast(upb_Arena* a, void* ptr, #include -#ifndef UPB_MINI_TABLE_TAGGED_PTR_H_ -#define UPB_MINI_TABLE_TAGGED_PTR_H_ - -#include - - -#ifndef UPB_MESSAGE_TYPES_H_ -#define UPB_MESSAGE_TYPES_H_ +#ifndef UPB_MESSAGE_INTERNAL_ARRAY_H_ +#define UPB_MESSAGE_INTERNAL_ARRAY_H_ -// This typedef is in a leaf header to resolve a circular dependency between -// messages and mini tables. -typedef struct upb_Message { - int unused; // Placeholder cuz Windows won't compile an empty struct. -} upb_Message; +#include -#endif /* UPB_MESSAGE_TYPES_H_ */ // Must be last. -// 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 -// that field's true message type. This forms the basis of what we call -// "dynamic tree shaking." -// -// See the documentation for kUpb_DecodeOption_ExperimentalAllowUnlinked for -// more information. - -typedef uintptr_t upb_TaggedMessagePtr; +#define _UPB_ARRAY_MASK_IMM 0x4 // Frozen/immutable bit. +#define _UPB_ARRAY_MASK_LG2 0x3 // Encoded elem size. +#define _UPB_ARRAY_MASK_ALL (_UPB_ARRAY_MASK_IMM | _UPB_ARRAY_MASK_LG2) #ifdef __cplusplus extern "C" { #endif -// Internal-only because empty messages cannot be created by the user. -UPB_INLINE upb_TaggedMessagePtr _upb_TaggedMessagePtr_Pack(upb_Message* ptr, - bool empty) { - UPB_ASSERT(((uintptr_t)ptr & 1) == 0); - return (uintptr_t)ptr | (empty ? 1 : 0); -} +// LINT.IfChange(struct_definition) +// Our internal representation for repeated fields. +struct upb_Array { + // This is a tagged pointer. Bits #0 and #1 encode the elem size as follows: + // 0 maps to elem size 1 + // 1 maps to elem size 4 + // 2 maps to elem size 8 + // 3 maps to elem size 16 + // + // Bit #2 contains the frozen/immutable flag (currently unimplemented). + uintptr_t data; -// Users who enable unlinked sub-messages must use this to test whether a -// message is empty before accessing it. If a message is empty, it must be -// first promoted using the interfaces in message/promote.h. -UPB_INLINE bool upb_TaggedMessagePtr_IsEmpty(upb_TaggedMessagePtr ptr) { - return ptr & 1; -} + size_t UPB_ONLYBITS(size); // The number of elements in the array. + size_t UPB_PRIVATE(capacity); // Allocated storage. Measured in elements. +}; -UPB_INLINE upb_Message* _upb_TaggedMessagePtr_GetMessage( - upb_TaggedMessagePtr ptr) { - return (upb_Message*)(ptr & ~(uintptr_t)1); +UPB_INLINE void UPB_PRIVATE(_upb_Array_SetTaggedPtr)(struct upb_Array* array, + void* data, size_t lg2) { + UPB_ASSERT(lg2 != 1); + UPB_ASSERT(lg2 <= 4); + const size_t bits = lg2 - (lg2 != 0); + array->data = (uintptr_t)data | bits; } -UPB_INLINE upb_Message* upb_TaggedMessagePtr_GetNonEmptyMessage( - upb_TaggedMessagePtr ptr) { - UPB_ASSERT(!upb_TaggedMessagePtr_IsEmpty(ptr)); - return _upb_TaggedMessagePtr_GetMessage(ptr); +UPB_INLINE size_t +UPB_PRIVATE(_upb_Array_ElemSizeLg2)(const struct upb_Array* array) { + const size_t bits = array->data & _UPB_ARRAY_MASK_LG2; + const size_t lg2 = bits + (bits != 0); + return lg2; } -UPB_INLINE upb_Message* _upb_TaggedMessagePtr_GetEmptyMessage( - upb_TaggedMessagePtr ptr) { - UPB_ASSERT(upb_TaggedMessagePtr_IsEmpty(ptr)); - return _upb_TaggedMessagePtr_GetMessage(ptr); +UPB_INLINE const void* _upb_array_constptr(const struct upb_Array* array) { + UPB_PRIVATE(_upb_Array_ElemSizeLg2)(array); // Check assertions. + return (void*)(array->data & ~(uintptr_t)_UPB_ARRAY_MASK_ALL); } -#ifdef __cplusplus -} /* extern "C" */ -#endif - - -#endif /* UPB_MINI_TABLE_TAGGED_PTR_H_ */ - -typedef union { - bool bool_val; - float float_val; - double double_val; - int32_t int32_val; - int64_t int64_val; - uint32_t uint32_val; - uint64_t uint64_val; - const struct upb_Array* array_val; - const struct upb_Map* map_val; - const struct upb_Message* msg_val; - upb_StringView str_val; - - // EXPERIMENTAL: A tagged upb_Message*. Users must use this instead of - // msg_val if unlinked sub-messages may possibly be in use. See the - // documentation in kUpb_DecodeOption_ExperimentalAllowUnlinked for more - // information. - upb_TaggedMessagePtr tagged_msg_val; -} upb_MessageValue; - -typedef union { - struct upb_Array* array; - struct upb_Map* map; - struct upb_Message* msg; -} upb_MutableMessageValue; - -#endif /* UPB_MESSAGE_VALUE_H_ */ - -// Must be last. - -typedef struct upb_Array upb_Array; - -#ifdef __cplusplus -extern "C" { -#endif - -// Creates a new array on the given arena that holds elements of this type. -UPB_API upb_Array* upb_Array_New(upb_Arena* a, upb_CType type); - -// Returns the number of elements in the array. -UPB_API size_t upb_Array_Size(const upb_Array* arr); - -// Returns the given element, which must be within the array's current size. -UPB_API upb_MessageValue upb_Array_Get(const upb_Array* arr, size_t i); - -// Sets the given element, which must be within the array's current size. -UPB_API void upb_Array_Set(upb_Array* arr, size_t i, upb_MessageValue val); - -// Appends an element to the array. Returns false on allocation failure. -UPB_API bool upb_Array_Append(upb_Array* array, upb_MessageValue val, - upb_Arena* arena); +UPB_INLINE void* _upb_array_ptr(struct upb_Array* array) { + return (void*)_upb_array_constptr(array); +} -// Moves elements within the array using memmove(). -// Like memmove(), the source and destination elements may be overlapping. -UPB_API void upb_Array_Move(upb_Array* array, size_t dst_idx, size_t src_idx, - size_t count); +UPB_INLINE struct upb_Array* UPB_PRIVATE(_upb_Array_New)(upb_Arena* arena, + size_t init_capacity, + int elem_size_lg2) { + UPB_ASSERT(elem_size_lg2 != 1); + UPB_ASSERT(elem_size_lg2 <= 4); + const size_t array_size = + UPB_ALIGN_UP(sizeof(struct upb_Array), UPB_MALLOC_ALIGN); + const size_t bytes = array_size + (init_capacity << elem_size_lg2); + struct upb_Array* array = (struct upb_Array*)upb_Arena_Malloc(arena, bytes); + if (!array) return NULL; + UPB_PRIVATE(_upb_Array_SetTaggedPtr) + (array, UPB_PTR_AT(array, array_size, void), elem_size_lg2); + array->UPB_ONLYBITS(size) = 0; + array->UPB_PRIVATE(capacity) = init_capacity; + return array; +} -// Inserts one or more empty elements into the array. -// Existing elements are shifted right. -// The new elements have undefined state and must be set with `upb_Array_Set()`. -// REQUIRES: `i <= upb_Array_Size(arr)` -UPB_API bool upb_Array_Insert(upb_Array* array, size_t i, size_t count, - upb_Arena* arena); +// Resizes the capacity of the array to be at least min_size. +bool UPB_PRIVATE(_upb_Array_Realloc)(struct upb_Array* array, size_t min_size, + upb_Arena* arena); -// Deletes one or more elements from the array. -// Existing elements are shifted left. -// REQUIRES: `i + count <= upb_Array_Size(arr)` -UPB_API void upb_Array_Delete(upb_Array* array, size_t i, size_t count); +UPB_INLINE bool UPB_PRIVATE(_upb_Array_Reserve)(struct upb_Array* array, + size_t size, upb_Arena* arena) { + if (array->UPB_PRIVATE(capacity) < size) + return UPB_PRIVATE(_upb_Array_Realloc)(array, size, arena); + return true; +} -// Changes the size of a vector. New elements are initialized to NULL/0. -// Returns false on allocation failure. -UPB_API bool upb_Array_Resize(upb_Array* array, size_t size, upb_Arena* arena); +// Resize without initializing new elements. +UPB_INLINE bool _upb_Array_ResizeUninitialized(struct upb_Array* array, + size_t size, upb_Arena* arena) { + UPB_ASSERT(size <= array->UPB_ONLYBITS(size) || + arena); // Allow NULL arena when shrinking. + if (!UPB_PRIVATE(_upb_Array_Reserve)(array, size, arena)) return false; + array->UPB_ONLYBITS(size) = size; + return true; +} -// Returns pointer to array data. -UPB_API const void* upb_Array_DataPtr(const upb_Array* arr); +// This function is intended for situations where elem_size is compile-time +// constant or a known expression of the form (1 << lg2), so that the expression +// i*elem_size does not result in an actual multiplication. +UPB_INLINE void UPB_PRIVATE(_upb_Array_Set)(struct upb_Array* array, size_t i, + const void* data, + size_t elem_size) { + UPB_ASSERT(i < array->UPB_ONLYBITS(size)); + UPB_ASSERT(elem_size == 1U << UPB_PRIVATE(_upb_Array_ElemSizeLg2)(array)); + char* arr_data = (char*)_upb_array_ptr(array); + memcpy(arr_data + (i * elem_size), data, elem_size); +} -// Returns mutable pointer to array data. -UPB_API void* upb_Array_MutableDataPtr(upb_Array* arr); +// LINT.ThenChange( +// GoogleInternalName1, +//) #ifdef __cplusplus } /* extern "C" */ #endif +#undef _UPB_ARRAY_MASK_IMM +#undef _UPB_ARRAY_MASK_LG2 +#undef _UPB_ARRAY_MASK_ALL -#endif /* UPB_MESSAGE_ARRAY_H_ */ -#ifndef UPB_MESSAGE_INTERNAL_ACCESSORS_H_ -#define UPB_MESSAGE_INTERNAL_ACCESSORS_H_ +#endif /* UPB_MESSAGE_INTERNAL_ARRAY_H_ */ + +#ifndef UPB_MESSAGE_INTERNAL_MAP_H_ +#define UPB_MESSAGE_INTERNAL_MAP_H_ #include -#include #include -#ifndef UPB_MESSAGE_INTERNAL_EXTENSION_H_ -#define UPB_MESSAGE_INTERNAL_EXTENSION_H_ +#ifndef UPB_HASH_STR_TABLE_H_ +#define UPB_HASH_STR_TABLE_H_ /* -** Our memory representation for parsing tables and messages themselves. -** Functions in this file are used by generated code and possibly reflection. -** -** The definitions in this file are internal to upb. -**/ + * upb_table + * + * This header is INTERNAL-ONLY! Its interfaces are not public or stable! + * This file defines very fast int->upb_value (inttable) and string->upb_value + * (strtable) hash tables. + * + * The table uses chained scatter with Brent's variation (inspired by the Lua + * implementation of hash tables). The hash function for strings is Austin + * Appleby's "MurmurHash." + * + * The inttable uses uintptr_t as its key, which guarantees it can be used to + * store pointers or integers of at least 32 bits (upb isn't really useful on + * systems where sizeof(void*) < 4). + * + * The table must be homogeneous (all values of the same type). In debug + * mode, we check this on insert and lookup. + */ -#ifndef UPB_MESSAGE_INTERNAL_H_ -#define UPB_MESSAGE_INTERNAL_H_ +#ifndef UPB_HASH_COMMON_H_ +#define UPB_HASH_COMMON_H_ -#include #include -#ifndef UPB_MINI_TABLE_INTERNAL_TYPES_H_ -#define UPB_MINI_TABLE_INTERNAL_TYPES_H_ - -typedef struct upb_Message_InternalData upb_Message_InternalData; - -typedef struct { - union { - upb_Message_InternalData* internal; - - // Force 8-byte alignment, since the data members may contain members that - // require 8-byte alignment. - double d; - }; -} upb_Message_Internal; +// Must be last. -#endif // UPB_MINI_TABLE_INTERNAL_TYPES_H_ +#ifdef __cplusplus +extern "C" { +#endif -#ifndef UPB_MINI_TABLE_MESSAGE_H_ -#define UPB_MINI_TABLE_MESSAGE_H_ +/* upb_value ******************************************************************/ +typedef struct { + uint64_t val; +} upb_value; -#ifndef UPB_MINI_TABLE_ENUM_H_ -#define UPB_MINI_TABLE_ENUM_H_ +UPB_INLINE void _upb_value_setval(upb_value* v, uint64_t val) { v->val = val; } -#include - - -#ifndef UPB_MINI_TABLE_INTERNAL_ENUM_H_ -#define UPB_MINI_TABLE_INTERNAL_ENUM_H_ - -#include - -// Must be last. - -struct upb_MiniTableEnum { - uint32_t UPB_PRIVATE(mask_limit); // Highest that can be tested with mask. - uint32_t UPB_PRIVATE(value_count); // Number of values after the bitfield. - uint32_t UPB_PRIVATE(data)[]; // Bitmask + enumerated values follow. -}; - -#ifdef __cplusplus -extern "C" { -#endif - -UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableEnum_CheckValue)( - const struct upb_MiniTableEnum* e, uint32_t val) { - if (UPB_LIKELY(val < 64)) { - const uint64_t mask = - e->UPB_PRIVATE(data)[0] | ((uint64_t)e->UPB_PRIVATE(data)[1] << 32); - const uint64_t bit = 1ULL << val; - return (mask & bit) != 0; - } - if (UPB_LIKELY(val < e->UPB_PRIVATE(mask_limit))) { - const uint32_t mask = e->UPB_PRIVATE(data)[val / 32]; - const uint32_t bit = 1ULL << (val % 32); - return (mask & bit) != 0; - } - - // OPT: binary search long lists? - const uint32_t* start = - &e->UPB_PRIVATE(data)[e->UPB_PRIVATE(mask_limit) / 32]; - const uint32_t* limit = &e->UPB_PRIVATE( - data)[e->UPB_PRIVATE(mask_limit) / 32 + e->UPB_PRIVATE(value_count)]; - for (const uint32_t* p = start; p < limit; p++) { - if (*p == val) return true; +/* For each value ctype, define the following set of functions: + * + * // Get/set an int32 from a upb_value. + * int32_t upb_value_getint32(upb_value val); + * void upb_value_setint32(upb_value *val, int32_t cval); + * + * // Construct a new upb_value from an int32. + * upb_value upb_value_int32(int32_t val); */ +#define FUNCS(name, membername, type_t, converter) \ + UPB_INLINE void upb_value_set##name(upb_value* val, type_t cval) { \ + val->val = (converter)cval; \ + } \ + UPB_INLINE upb_value upb_value_##name(type_t val) { \ + upb_value ret; \ + upb_value_set##name(&ret, val); \ + return ret; \ + } \ + UPB_INLINE type_t upb_value_get##name(upb_value val) { \ + return (type_t)(converter)val.val; \ } - return false; -} -#ifdef __cplusplus -} /* extern "C" */ -#endif - - -#endif /* UPB_MINI_TABLE_INTERNAL_ENUM_H_ */ - -// Must be last - -typedef struct upb_MiniTableEnum upb_MiniTableEnum; +FUNCS(int32, int32, int32_t, int32_t) +FUNCS(int64, int64, int64_t, int64_t) +FUNCS(uint32, uint32, uint32_t, uint32_t) +FUNCS(uint64, uint64, uint64_t, uint64_t) +FUNCS(bool, _bool, bool, bool) +FUNCS(cstr, cstr, char*, uintptr_t) +FUNCS(uintptr, uptr, uintptr_t, uintptr_t) +FUNCS(ptr, ptr, void*, uintptr_t) +FUNCS(constptr, constptr, const void*, uintptr_t) -#ifdef __cplusplus -extern "C" { -#endif +#undef FUNCS -// Validates enum value against range defined by enum mini table. -UPB_INLINE bool upb_MiniTableEnum_CheckValue(const upb_MiniTableEnum* e, - uint32_t val) { - return UPB_PRIVATE(_upb_MiniTableEnum_CheckValue)(e, val); +UPB_INLINE void upb_value_setfloat(upb_value* val, float cval) { + memcpy(&val->val, &cval, sizeof(cval)); } -#ifdef __cplusplus -} /* extern "C" */ -#endif - +UPB_INLINE void upb_value_setdouble(upb_value* val, double cval) { + memcpy(&val->val, &cval, sizeof(cval)); +} -#endif /* UPB_MINI_TABLE_ENUM_H_ */ +UPB_INLINE upb_value upb_value_float(float cval) { + upb_value ret; + upb_value_setfloat(&ret, cval); + return ret; +} -#ifndef UPB_MINI_TABLE_FIELD_H_ -#define UPB_MINI_TABLE_FIELD_H_ +UPB_INLINE upb_value upb_value_double(double cval) { + upb_value ret; + upb_value_setdouble(&ret, cval); + return ret; +} -#include +/* upb_tabkey *****************************************************************/ +/* Either: + * 1. an actual integer key, or + * 2. a pointer to a string prefixed by its uint32_t length, owned by us. + * + * ...depending on whether this is a string table or an int table. We would + * make this a union of those two types, but C89 doesn't support statically + * initializing a non-first union member. */ +typedef uintptr_t upb_tabkey; -#ifndef UPB_MINI_TABLE_INTERNAL_FIELD_H_ -#define UPB_MINI_TABLE_INTERNAL_FIELD_H_ +UPB_INLINE char* upb_tabstr(upb_tabkey key, uint32_t* len) { + char* mem = (char*)key; + if (len) memcpy(len, mem, sizeof(*len)); + return mem + sizeof(*len); +} -#include -#include +UPB_INLINE upb_StringView upb_tabstrview(upb_tabkey key) { + upb_StringView ret; + uint32_t len; + ret.data = upb_tabstr(key, &len); + ret.size = len; + return ret; +} +/* upb_tabval *****************************************************************/ -#ifndef UPB_MINI_TABLE_INTERNAL_SIZE_LOG2_H_ -#define UPB_MINI_TABLE_INTERNAL_SIZE_LOG2_H_ +typedef struct upb_tabval { + uint64_t val; +} upb_tabval; -#include -#include +#define UPB_TABVALUE_EMPTY_INIT \ + { -1 } +/* upb_table ******************************************************************/ -// Must be last. +typedef struct _upb_tabent { + upb_tabkey key; + upb_tabval val; -#ifdef __cplusplus -extern "C" { -#endif + /* Internal chaining. This is const so we can create static initializers for + * tables. We cast away const sometimes, but *only* when the containing + * upb_table is known to be non-const. This requires a bit of care, but + * the subtlety is confined to table.c. */ + const struct _upb_tabent* next; +} upb_tabent; -// Return the log2 of the storage size in bytes for a upb_CType -UPB_INLINE int UPB_PRIVATE(_upb_CType_SizeLg2)(upb_CType c_type) { - static const int8_t size[] = { - 0, // kUpb_CType_Bool - 2, // kUpb_CType_Float - 2, // kUpb_CType_Int32 - 2, // kUpb_CType_UInt32 - 2, // kUpb_CType_Enum - UPB_SIZE(2, 3), // kUpb_CType_Message - 3, // kUpb_CType_Double - 3, // kUpb_CType_Int64 - 3, // kUpb_CType_UInt64 - UPB_SIZE(3, 4), // kUpb_CType_String - UPB_SIZE(3, 4), // kUpb_CType_Bytes - }; +typedef struct { + size_t count; /* Number of entries in the hash part. */ + uint32_t mask; /* Mask to turn hash value -> bucket. */ + uint32_t max_count; /* Max count before we hit our load limit. */ + uint8_t size_lg2; /* Size of the hashtable part is 2^size_lg2 entries. */ + upb_tabent* entries; +} upb_table; - // -1 here because the enum is one-based but the table is zero-based. - return size[c_type - 1]; +UPB_INLINE size_t upb_table_size(const upb_table* t) { + return t->size_lg2 ? 1 << t->size_lg2 : 0; } -// Return the log2 of the storage size in bytes for a upb_FieldType -UPB_INLINE int UPB_PRIVATE(_upb_FieldType_SizeLg2)(upb_FieldType field_type) { - static const int8_t size[] = { - 3, // kUpb_FieldType_Double - 2, // kUpb_FieldType_Float - 3, // kUpb_FieldType_Int64 - 3, // kUpb_FieldType_UInt64 - 2, // kUpb_FieldType_Int32 - 3, // kUpb_FieldType_Fixed64 - 2, // kUpb_FieldType_Fixed32 - 0, // kUpb_FieldType_Bool - UPB_SIZE(3, 4), // kUpb_FieldType_String - UPB_SIZE(2, 3), // kUpb_FieldType_Group - UPB_SIZE(2, 3), // kUpb_FieldType_Message - UPB_SIZE(3, 4), // kUpb_FieldType_Bytes - 2, // kUpb_FieldType_UInt32 - 2, // kUpb_FieldType_Enum - 2, // kUpb_FieldType_SFixed32 - 3, // kUpb_FieldType_SFixed64 - 2, // kUpb_FieldType_SInt32 - 3, // kUpb_FieldType_SInt64 - }; +// Internal-only functions, in .h file only out of necessity. - // -1 here because the enum is one-based but the table is zero-based. - return size[field_type - 1]; -} +UPB_INLINE bool upb_tabent_isempty(const upb_tabent* e) { return e->key == 0; } + +uint32_t _upb_Hash(const void* p, size_t n, uint64_t seed); #ifdef __cplusplus } /* extern "C" */ #endif -#endif /* UPB_MINI_TABLE_INTERNAL_SIZE_LOG2_H_ */ +#endif /* UPB_HASH_COMMON_H_ */ // Must be last. -// LINT.IfChange(struct_definition) -struct upb_MiniTableField { - uint32_t UPB_ONLYBITS(number); - uint16_t UPB_ONLYBITS(offset); - int16_t presence; // If >0, hasbit_index. If <0, ~oneof_index - - // Indexes into `upb_MiniTable.subs` - // Will be set to `kUpb_NoSub` if `descriptortype` != MESSAGE/GROUP/ENUM - uint16_t UPB_PRIVATE(submsg_index); - - uint8_t UPB_PRIVATE(descriptortype); - - // upb_FieldMode | upb_LabelFlags | (upb_FieldRep << kUpb_FieldRep_Shift) - uint8_t UPB_ONLYBITS(mode); -}; - -#define kUpb_NoSub ((uint16_t)-1) - -typedef enum { - kUpb_FieldMode_Map = 0, - kUpb_FieldMode_Array = 1, - kUpb_FieldMode_Scalar = 2, -} upb_FieldMode; - -// Mask to isolate the upb_FieldMode from field.mode. -#define kUpb_FieldMode_Mask 3 - -// Extra flags on the mode field. -typedef enum { - kUpb_LabelFlags_IsPacked = 4, - kUpb_LabelFlags_IsExtension = 8, - // Indicates that this descriptor type is an "alternate type": - // - for Int32, this indicates that the actual type is Enum (but was - // rewritten to Int32 because it is an open enum that requires no check). - // - for Bytes, this indicates that the actual type is String (but does - // not require any UTF-8 check). - kUpb_LabelFlags_IsAlternate = 16, -} upb_LabelFlags; - -// Note: we sort by this number when calculating layout order. -typedef enum { - kUpb_FieldRep_1Byte = 0, - kUpb_FieldRep_4Byte = 1, - kUpb_FieldRep_StringView = 2, - kUpb_FieldRep_8Byte = 3, - - kUpb_FieldRep_NativePointer = - UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte), - kUpb_FieldRep_Max = kUpb_FieldRep_8Byte, -} upb_FieldRep; - -#define kUpb_FieldRep_Shift 6 +typedef struct { + upb_table t; +} upb_strtable; #ifdef __cplusplus extern "C" { #endif -UPB_INLINE upb_FieldMode -UPB_PRIVATE(_upb_MiniTableField_Mode)(const struct upb_MiniTableField* f) { - return (upb_FieldMode)(f->UPB_ONLYBITS(mode) & kUpb_FieldMode_Mask); -} - -UPB_INLINE upb_FieldRep -UPB_PRIVATE(_upb_MiniTableField_GetRep)(const struct upb_MiniTableField* f) { - return (upb_FieldRep)(f->UPB_ONLYBITS(mode) >> kUpb_FieldRep_Shift); -} - -UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsArray)( - const struct upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTableField_Mode)(f) == kUpb_FieldMode_Array; -} - -UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsMap)( - const struct upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTableField_Mode)(f) == kUpb_FieldMode_Map; -} - -UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsScalar)( - const struct upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTableField_Mode)(f) == kUpb_FieldMode_Scalar; -} - -UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsAlternate)( - const struct upb_MiniTableField* f) { - return (f->UPB_ONLYBITS(mode) & kUpb_LabelFlags_IsAlternate) != 0; -} - -UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsExtension)( - const struct upb_MiniTableField* f) { - return (f->UPB_ONLYBITS(mode) & kUpb_LabelFlags_IsExtension) != 0; -} - -UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsPacked)( - const struct upb_MiniTableField* f) { - return (f->UPB_ONLYBITS(mode) & kUpb_LabelFlags_IsPacked) != 0; -} +// Initialize a table. If memory allocation failed, false is returned and +// the table is uninitialized. +bool upb_strtable_init(upb_strtable* table, size_t expected_size, upb_Arena* a); -UPB_INLINE upb_FieldType -UPB_PRIVATE(_upb_MiniTableField_Type)(const struct upb_MiniTableField* f) { - const upb_FieldType type = (upb_FieldType)f->UPB_PRIVATE(descriptortype); - if (UPB_PRIVATE(_upb_MiniTableField_IsAlternate)(f)) { - if (type == kUpb_FieldType_Int32) return kUpb_FieldType_Enum; - if (type == kUpb_FieldType_Bytes) return kUpb_FieldType_String; - UPB_ASSERT(false); - } - return type; +// Returns the number of values in the table. +UPB_INLINE size_t upb_strtable_count(const upb_strtable* t) { + return t->t.count; } -UPB_INLINE upb_CType -UPB_PRIVATE(_upb_MiniTableField_CType)(const struct upb_MiniTableField* f) { - return upb_FieldType_CType(UPB_PRIVATE(_upb_MiniTableField_Type)(f)); -} +void upb_strtable_clear(upb_strtable* t); -UPB_INLINE char UPB_PRIVATE(_upb_MiniTableField_HasbitMask)( - const struct upb_MiniTableField* f) { - UPB_ASSERT(f->presence > 0); - const size_t index = f->presence; - return 1 << (index % 8); -} +// Inserts the given key into the hashtable with the given value. +// The key must not already exist in the hash table. The key is not required +// to be NULL-terminated, and the table will make an internal copy of the key. +// +// If a table resize was required but memory allocation failed, false is +// returned and the table is unchanged. */ +bool upb_strtable_insert(upb_strtable* t, const char* key, size_t len, + upb_value val, upb_Arena* a); -UPB_INLINE size_t UPB_PRIVATE(_upb_MiniTableField_HasbitOffset)( - const struct upb_MiniTableField* f) { - UPB_ASSERT(f->presence > 0); - const size_t index = f->presence; - return index / 8; -} +// Looks up key in this table, returning "true" if the key was found. +// If v is non-NULL, copies the value for this key into *v. +bool upb_strtable_lookup2(const upb_strtable* t, const char* key, size_t len, + upb_value* v); -UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsClosedEnum)( - const struct upb_MiniTableField* f) { - return f->UPB_PRIVATE(descriptortype) == kUpb_FieldType_Enum; +// For NULL-terminated strings. +UPB_INLINE bool upb_strtable_lookup(const upb_strtable* t, const char* key, + upb_value* v) { + return upb_strtable_lookup2(t, key, strlen(key), v); } -UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsInOneof)( - const struct upb_MiniTableField* f) { - return f->presence < 0; -} +// Removes an item from the table. Returns true if the remove was successful, +// and stores the removed item in *val if non-NULL. +bool upb_strtable_remove2(upb_strtable* t, const char* key, size_t len, + upb_value* val); -UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsSubMessage)( - const struct upb_MiniTableField* f) { - return f->UPB_PRIVATE(descriptortype) == kUpb_FieldType_Message || - f->UPB_PRIVATE(descriptortype) == kUpb_FieldType_Group; +UPB_INLINE bool upb_strtable_remove(upb_strtable* t, const char* key, + upb_value* v) { + return upb_strtable_remove2(t, key, strlen(key), v); } -UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_HasPresence)( - const struct upb_MiniTableField* f) { - if (UPB_PRIVATE(_upb_MiniTableField_IsExtension)(f)) { - return UPB_PRIVATE(_upb_MiniTableField_IsScalar)(f); - } else { - return f->presence != 0; - } -} +// Exposed for testing only. +bool upb_strtable_resize(upb_strtable* t, size_t size_lg2, upb_Arena* a); -UPB_INLINE uint32_t -UPB_PRIVATE(_upb_MiniTableField_Number)(const struct upb_MiniTableField* f) { - return f->UPB_ONLYBITS(number); -} +/* Iteration over strtable: + * + * intptr_t iter = UPB_STRTABLE_BEGIN; + * upb_StringView key; + * upb_value val; + * while (upb_strtable_next2(t, &key, &val, &iter)) { + * // ... + * } + */ -UPB_INLINE uint16_t -UPB_PRIVATE(_upb_MiniTableField_Offset)(const struct upb_MiniTableField* f) { - return f->UPB_ONLYBITS(offset); -} +#define UPB_STRTABLE_BEGIN -1 -UPB_INLINE size_t UPB_PRIVATE(_upb_MiniTableField_OneofOffset)( - const struct upb_MiniTableField* f) { - UPB_ASSERT(UPB_PRIVATE(_upb_MiniTableField_IsInOneof)(f)); - return ~(ptrdiff_t)f->presence; -} +bool upb_strtable_next2(const upb_strtable* t, upb_StringView* key, + upb_value* val, intptr_t* iter); +void upb_strtable_removeiter(upb_strtable* t, intptr_t* iter); +void upb_strtable_setentryvalue(upb_strtable* t, intptr_t iter, upb_value v); -UPB_INLINE void UPB_PRIVATE(_upb_MiniTableField_CheckIsArray)( - const struct upb_MiniTableField* f) { - UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == - kUpb_FieldRep_NativePointer); - UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_IsArray)(f)); - UPB_ASSUME(f->presence == 0); -} +/* DEPRECATED iterators, slated for removal. + * + * Iterators for string tables. We are subject to some kind of unusual + * design constraints: + * + * For high-level languages: + * - we must be able to guarantee that we don't crash or corrupt memory even if + * the program accesses an invalidated iterator. + * + * For C++11 range-based for: + * - iterators must be copyable + * - iterators must be comparable + * - it must be possible to construct an "end" value. + * + * Iteration order is undefined. + * + * Modifying the table invalidates iterators. upb_{str,int}table_done() is + * guaranteed to work even on an invalidated iterator, as long as the table it + * is iterating over has not been freed. Calling next() or accessing data from + * an invalidated iterator yields unspecified elements from the table, but it is + * guaranteed not to crash and to return real table elements (except when done() + * is true). */ +/* upb_strtable_iter **********************************************************/ -UPB_INLINE void UPB_PRIVATE(_upb_MiniTableField_CheckIsMap)( - const struct upb_MiniTableField* f) { - UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == - kUpb_FieldRep_NativePointer); - UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_IsMap)(f)); - UPB_ASSUME(f->presence == 0); -} +/* upb_strtable_iter i; + * upb_strtable_begin(&i, t); + * for(; !upb_strtable_done(&i); upb_strtable_next(&i)) { + * const char *key = upb_strtable_iter_key(&i); + * const upb_value val = upb_strtable_iter_value(&i); + * // ... + * } + */ -UPB_INLINE size_t UPB_PRIVATE(_upb_MiniTableField_ElemSizeLg2)( - const struct upb_MiniTableField* f) { - const upb_FieldType field_type = UPB_PRIVATE(_upb_MiniTableField_Type)(f); - return UPB_PRIVATE(_upb_FieldType_SizeLg2)(field_type); +typedef struct { + const upb_strtable* t; + size_t index; +} upb_strtable_iter; + +UPB_INLINE const upb_tabent* str_tabent(const upb_strtable_iter* i) { + return &i->t->t.entries[i->index]; } -// LINT.ThenChange(//depot/google3/third_party/upb/bits/typescript/mini_table_field.ts) +void upb_strtable_begin(upb_strtable_iter* i, const upb_strtable* t); +void upb_strtable_next(upb_strtable_iter* i); +bool upb_strtable_done(const upb_strtable_iter* i); +upb_StringView upb_strtable_iter_key(const upb_strtable_iter* i); +upb_value upb_strtable_iter_value(const upb_strtable_iter* i); +void upb_strtable_iter_setdone(upb_strtable_iter* i); +bool upb_strtable_iter_isequal(const upb_strtable_iter* i1, + const upb_strtable_iter* i2); #ifdef __cplusplus } /* extern "C" */ #endif -#endif /* UPB_MINI_TABLE_INTERNAL_FIELD_H_ */ +#endif /* UPB_HASH_STR_TABLE_H_ */ // Must be last. -typedef struct upb_MiniTableField upb_MiniTableField; +typedef enum { + kUpb_MapInsertStatus_Inserted = 0, + kUpb_MapInsertStatus_Replaced = 1, + kUpb_MapInsertStatus_OutOfMemory = 2, +} upb_MapInsertStatus; + +// EVERYTHING BELOW THIS LINE IS INTERNAL - DO NOT USE ///////////////////////// + +struct upb_Map { + // Size of key and val, based on the map type. + // Strings are represented as '0' because they must be handled specially. + char key_size; + char val_size; + + upb_strtable table; +}; #ifdef __cplusplus extern "C" { #endif -UPB_API_INLINE upb_CType upb_MiniTableField_CType(const upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTableField_CType)(f); -} +// Converting between internal table representation and user values. +// +// _upb_map_tokey() and _upb_map_fromkey() are inverses. +// _upb_map_tovalue() and _upb_map_fromvalue() are inverses. +// +// These functions account for the fact that strings are treated differently +// from other types when stored in a map. -UPB_API_INLINE bool upb_MiniTableField_HasPresence( - const upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTableField_HasPresence)(f); +UPB_INLINE upb_StringView _upb_map_tokey(const void* key, size_t size) { + if (size == UPB_MAPTYPE_STRING) { + return *(upb_StringView*)key; + } else { + return upb_StringView_FromDataAndSize((const char*)key, size); + } } -UPB_API_INLINE bool upb_MiniTableField_IsArray(const upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTableField_IsArray)(f); +UPB_INLINE void _upb_map_fromkey(upb_StringView key, void* out, size_t size) { + if (size == UPB_MAPTYPE_STRING) { + memcpy(out, &key, sizeof(key)); + } else { + memcpy(out, key.data, size); + } } -UPB_API_INLINE bool upb_MiniTableField_IsClosedEnum( - const upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTableField_IsClosedEnum)(f); +UPB_INLINE bool _upb_map_tovalue(const void* val, size_t size, + upb_value* msgval, upb_Arena* a) { + if (size == UPB_MAPTYPE_STRING) { + upb_StringView* strp = (upb_StringView*)upb_Arena_Malloc(a, sizeof(*strp)); + if (!strp) return false; + *strp = *(upb_StringView*)val; + *msgval = upb_value_ptr(strp); + } else { + memcpy(msgval, val, size); + } + return true; } -UPB_API_INLINE bool upb_MiniTableField_IsExtension( - const upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTableField_IsExtension)(f); +UPB_INLINE void _upb_map_fromvalue(upb_value val, void* out, size_t size) { + if (size == UPB_MAPTYPE_STRING) { + const upb_StringView* strp = (const upb_StringView*)upb_value_getptr(val); + memcpy(out, strp, sizeof(upb_StringView)); + } else { + memcpy(out, &val, size); + } } -UPB_API_INLINE bool upb_MiniTableField_IsInOneof(const upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTableField_IsInOneof)(f); +UPB_INLINE void* _upb_map_next(const struct upb_Map* map, size_t* iter) { + upb_strtable_iter it; + it.t = &map->table; + it.index = *iter; + upb_strtable_next(&it); + *iter = it.index; + if (upb_strtable_done(&it)) return NULL; + return (void*)str_tabent(&it); } -UPB_API_INLINE bool upb_MiniTableField_IsMap(const upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTableField_IsMap)(f); +UPB_INLINE void _upb_Map_Clear(struct upb_Map* map) { + upb_strtable_clear(&map->table); } -UPB_API_INLINE bool upb_MiniTableField_IsPacked(const upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTableField_IsPacked)(f); +UPB_INLINE bool _upb_Map_Delete(struct upb_Map* map, const void* key, + size_t key_size, upb_value* val) { + upb_StringView k = _upb_map_tokey(key, key_size); + return upb_strtable_remove2(&map->table, k.data, k.size, val); } -UPB_API_INLINE bool upb_MiniTableField_IsScalar(const upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTableField_IsScalar)(f); +UPB_INLINE bool _upb_Map_Get(const struct upb_Map* map, const void* key, + size_t key_size, void* val, size_t val_size) { + upb_value tabval; + upb_StringView k = _upb_map_tokey(key, key_size); + bool ret = upb_strtable_lookup2(&map->table, k.data, k.size, &tabval); + if (ret && val) { + _upb_map_fromvalue(tabval, val, val_size); + } + return ret; } -UPB_API_INLINE bool upb_MiniTableField_IsSubMessage( - const upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTableField_IsSubMessage)(f); +UPB_INLINE upb_MapInsertStatus _upb_Map_Insert(struct upb_Map* map, + const void* key, size_t key_size, + void* val, size_t val_size, + upb_Arena* a) { + upb_StringView strkey = _upb_map_tokey(key, key_size); + upb_value tabval = {0}; + if (!_upb_map_tovalue(val, val_size, &tabval, a)) { + return kUpb_MapInsertStatus_OutOfMemory; + } + + // TODO: add overwrite operation to minimize number of lookups. + bool removed = + upb_strtable_remove2(&map->table, strkey.data, strkey.size, NULL); + if (!upb_strtable_insert(&map->table, strkey.data, strkey.size, tabval, a)) { + return kUpb_MapInsertStatus_OutOfMemory; + } + return removed ? kUpb_MapInsertStatus_Replaced + : kUpb_MapInsertStatus_Inserted; } -UPB_API_INLINE uint32_t upb_MiniTableField_Number(const upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTableField_Number)(f); +UPB_INLINE size_t _upb_Map_Size(const struct upb_Map* map) { + return map->table.t.count; } -UPB_API_INLINE upb_FieldType -upb_MiniTableField_Type(const upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTableField_Type)(f); +// Strings/bytes are special-cased in maps. +extern char _upb_Map_CTypeSizeTable[12]; + +UPB_INLINE size_t _upb_Map_CTypeSize(upb_CType ctype) { + return _upb_Map_CTypeSizeTable[ctype]; } +// Creates a new map on the given arena with this key/value type. +struct upb_Map* _upb_Map_New(upb_Arena* a, size_t key_size, size_t value_size); + #ifdef __cplusplus } /* extern "C" */ #endif -#endif /* UPB_MINI_TABLE_FIELD_H_ */ +#endif /* UPB_MESSAGE_INTERNAL_MAP_H_ */ -#ifndef UPB_MINI_TABLE_INTERNAL_MESSAGE_H_ -#define UPB_MINI_TABLE_INTERNAL_MESSAGE_H_ +/* +** Our memory representation for parsing tables and messages themselves. +** Functions in this file are used by generated code and possibly reflection. +** +** The definitions in this file are internal to upb. +**/ + +#ifndef UPB_MESSAGE_INTERNAL_MESSAGE_H_ +#define UPB_MESSAGE_INTERNAL_MESSAGE_H_ + +#include +#include + + +#ifndef UPB_MESSAGE_INTERNAL_EXTENSION_H_ +#define UPB_MESSAGE_INTERNAL_EXTENSION_H_ + + +#ifndef UPB_MINI_TABLE_EXTENSION_H_ +#define UPB_MINI_TABLE_EXTENSION_H_ #include -#ifndef UPB_MINI_TABLE_INTERNAL_SUB_H_ -#define UPB_MINI_TABLE_INTERNAL_SUB_H_ +#ifndef UPB_MINI_TABLE_FIELD_H_ +#define UPB_MINI_TABLE_FIELD_H_ -// Must be last. +#include + + +#ifndef UPB_MINI_TABLE_INTERNAL_FIELD_H_ +#define UPB_MINI_TABLE_INTERNAL_FIELD_H_ + +#include +#include + + +#ifndef UPB_MINI_TABLE_INTERNAL_SIZE_LOG2_H_ +#define UPB_MINI_TABLE_INTERNAL_SIZE_LOG2_H_ + +#include +#include -union upb_MiniTableSub { - const struct upb_MiniTable* UPB_PRIVATE(submsg); - const struct upb_MiniTableEnum* UPB_PRIVATE(subenum); -}; + +// Must be last. #ifdef __cplusplus extern "C" { #endif -UPB_INLINE union upb_MiniTableSub UPB_PRIVATE(_upb_MiniTableSub_FromEnum)( - const struct upb_MiniTableEnum* subenum) { - union upb_MiniTableSub out; - out.UPB_PRIVATE(subenum) = subenum; - return out; -} +// Return the log2 of the storage size in bytes for a upb_CType +UPB_INLINE int UPB_PRIVATE(_upb_CType_SizeLg2)(upb_CType c_type) { + static const int8_t size[] = { + 0, // kUpb_CType_Bool + 2, // kUpb_CType_Float + 2, // kUpb_CType_Int32 + 2, // kUpb_CType_UInt32 + 2, // kUpb_CType_Enum + UPB_SIZE(2, 3), // kUpb_CType_Message + 3, // kUpb_CType_Double + 3, // kUpb_CType_Int64 + 3, // kUpb_CType_UInt64 + UPB_SIZE(3, 4), // kUpb_CType_String + UPB_SIZE(3, 4), // kUpb_CType_Bytes + }; -UPB_INLINE union upb_MiniTableSub UPB_PRIVATE(_upb_MiniTableSub_FromMessage)( - const struct upb_MiniTable* submsg) { - union upb_MiniTableSub out; - out.UPB_PRIVATE(submsg) = submsg; - return out; + // -1 here because the enum is one-based but the table is zero-based. + return size[c_type - 1]; } -UPB_INLINE const struct upb_MiniTableEnum* UPB_PRIVATE(_upb_MiniTableSub_Enum)( - const union upb_MiniTableSub sub) { - return sub.UPB_PRIVATE(subenum); -} +// Return the log2 of the storage size in bytes for a upb_FieldType +UPB_INLINE int UPB_PRIVATE(_upb_FieldType_SizeLg2)(upb_FieldType field_type) { + static const int8_t size[] = { + 3, // kUpb_FieldType_Double + 2, // kUpb_FieldType_Float + 3, // kUpb_FieldType_Int64 + 3, // kUpb_FieldType_UInt64 + 2, // kUpb_FieldType_Int32 + 3, // kUpb_FieldType_Fixed64 + 2, // kUpb_FieldType_Fixed32 + 0, // kUpb_FieldType_Bool + UPB_SIZE(3, 4), // kUpb_FieldType_String + UPB_SIZE(2, 3), // kUpb_FieldType_Group + UPB_SIZE(2, 3), // kUpb_FieldType_Message + UPB_SIZE(3, 4), // kUpb_FieldType_Bytes + 2, // kUpb_FieldType_UInt32 + 2, // kUpb_FieldType_Enum + 2, // kUpb_FieldType_SFixed32 + 3, // kUpb_FieldType_SFixed64 + 2, // kUpb_FieldType_SInt32 + 3, // kUpb_FieldType_SInt64 + }; -UPB_INLINE const struct upb_MiniTable* UPB_PRIVATE(_upb_MiniTableSub_Message)( - const union upb_MiniTableSub sub) { - return sub.UPB_PRIVATE(submsg); + // -1 here because the enum is one-based but the table is zero-based. + return size[field_type - 1]; } #ifdef __cplusplus @@ -1506,322 +1495,327 @@ UPB_INLINE const struct upb_MiniTable* UPB_PRIVATE(_upb_MiniTableSub_Message)( #endif -#endif /* UPB_MINI_TABLE_INTERNAL_SUB_H_ */ +#endif /* UPB_MINI_TABLE_INTERNAL_SIZE_LOG2_H_ */ // Must be last. -struct upb_Decoder; -struct upb_Message; -typedef const char* _upb_FieldParser(struct upb_Decoder* d, const char* ptr, - struct upb_Message* msg, intptr_t table, - uint64_t hasbits, uint64_t data); -typedef struct { - uint64_t field_data; - _upb_FieldParser* field_parser; -} _upb_FastTable_Entry; +// LINT.IfChange(struct_definition) +struct upb_MiniTableField { + uint32_t UPB_ONLYBITS(number); + uint16_t UPB_ONLYBITS(offset); + int16_t presence; // If >0, hasbit_index. If <0, ~oneof_index -typedef enum { - kUpb_ExtMode_NonExtendable = 0, // Non-extendable message. - kUpb_ExtMode_Extendable = 1, // Normal extendable message. - kUpb_ExtMode_IsMessageSet = 2, // MessageSet message. - kUpb_ExtMode_IsMessageSet_ITEM = - 3, // MessageSet item (temporary only, see decode.c) + // Indexes into `upb_MiniTable.subs` + // Will be set to `kUpb_NoSub` if `descriptortype` != MESSAGE/GROUP/ENUM + uint16_t UPB_PRIVATE(submsg_index); - // During table building we steal a bit to indicate that the message is a map - // entry. *Only* used during table building! - kUpb_ExtMode_IsMapEntry = 4, -} upb_ExtMode; + uint8_t UPB_PRIVATE(descriptortype); -// 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. + // upb_FieldMode | upb_LabelFlags | (upb_FieldRep << kUpb_FieldRep_Shift) + uint8_t UPB_ONLYBITS(mode); +}; -// LINT.IfChange(minitable_struct_definition) -struct upb_MiniTable { - const union upb_MiniTableSub* UPB_PRIVATE(subs); - const struct upb_MiniTableField* UPB_ONLYBITS(fields); +#define kUpb_NoSub ((uint16_t)-1) - // Must be aligned to sizeof(void*). Doesn't include internal members like - // unknown fields, extension dict, pointer to msglayout, etc. - uint16_t UPB_PRIVATE(size); +typedef enum { + kUpb_FieldMode_Map = 0, + kUpb_FieldMode_Array = 1, + kUpb_FieldMode_Scalar = 2, +} upb_FieldMode; - uint16_t UPB_ONLYBITS(field_count); +// Mask to isolate the upb_FieldMode from field.mode. +#define kUpb_FieldMode_Mask 3 - uint8_t UPB_PRIVATE(ext); // upb_ExtMode, uint8_t here so sizeof(ext) == 1 - uint8_t UPB_PRIVATE(dense_below); - uint8_t UPB_PRIVATE(table_mask); - uint8_t UPB_PRIVATE(required_count); // Required fields have the low hasbits. +// Extra flags on the mode field. +typedef enum { + kUpb_LabelFlags_IsPacked = 4, + kUpb_LabelFlags_IsExtension = 8, + // Indicates that this descriptor type is an "alternate type": + // - for Int32, this indicates that the actual type is Enum (but was + // rewritten to Int32 because it is an open enum that requires no check). + // - for Bytes, this indicates that the actual type is String (but does + // not require any UTF-8 check). + kUpb_LabelFlags_IsAlternate = 16, +} upb_LabelFlags; - // To statically initialize the tables of variable length, we need a flexible - // array member, and we need to compile in gnu99 mode (constant initialization - // of flexible array members is a GNU extension, not in C99 unfortunately. - _upb_FastTable_Entry UPB_PRIVATE(fasttable)[]; -}; -// LINT.ThenChange(//depot/google3/third_party/upb/bits/typescript/mini_table.ts) +// Note: we sort by this number when calculating layout order. +typedef enum { + kUpb_FieldRep_1Byte = 0, + kUpb_FieldRep_4Byte = 1, + kUpb_FieldRep_StringView = 2, + kUpb_FieldRep_8Byte = 3, + + kUpb_FieldRep_NativePointer = + UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte), + kUpb_FieldRep_Max = kUpb_FieldRep_8Byte, +} upb_FieldRep; + +#define kUpb_FieldRep_Shift 6 #ifdef __cplusplus extern "C" { #endif -UPB_INLINE const struct upb_MiniTable* UPB_PRIVATE(_upb_MiniTable_Empty)(void) { - extern const struct upb_MiniTable UPB_PRIVATE(_kUpb_MiniTable_Empty); +UPB_INLINE upb_FieldMode +UPB_PRIVATE(_upb_MiniTableField_Mode)(const struct upb_MiniTableField* f) { + return (upb_FieldMode)(f->UPB_ONLYBITS(mode) & kUpb_FieldMode_Mask); +} - return &UPB_PRIVATE(_kUpb_MiniTable_Empty); +UPB_INLINE upb_FieldRep +UPB_PRIVATE(_upb_MiniTableField_GetRep)(const struct upb_MiniTableField* f) { + return (upb_FieldRep)(f->UPB_ONLYBITS(mode) >> kUpb_FieldRep_Shift); } -UPB_INLINE int UPB_PRIVATE(_upb_MiniTable_FieldCount)( - const struct upb_MiniTable* m) { - return m->UPB_ONLYBITS(field_count); +UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsArray)( + const struct upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_Mode)(f) == kUpb_FieldMode_Array; } -UPB_INLINE bool UPB_PRIVATE(_upb_MiniTable_IsEmpty)( - const struct upb_MiniTable* m) { - extern const struct upb_MiniTable UPB_PRIVATE(_kUpb_MiniTable_Empty); +UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsMap)( + const struct upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_Mode)(f) == kUpb_FieldMode_Map; +} - return m == &UPB_PRIVATE(_kUpb_MiniTable_Empty); +UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsScalar)( + const struct upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_Mode)(f) == kUpb_FieldMode_Scalar; } -UPB_INLINE const struct upb_MiniTableField* UPB_PRIVATE( - _upb_MiniTable_GetFieldByIndex)(const struct upb_MiniTable* m, uint32_t i) { - return &m->UPB_ONLYBITS(fields)[i]; +UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsAlternate)( + const struct upb_MiniTableField* f) { + return (f->UPB_ONLYBITS(mode) & kUpb_LabelFlags_IsAlternate) != 0; } -UPB_INLINE const union upb_MiniTableSub* UPB_PRIVATE( - _upb_MiniTable_GetSubByIndex)(const struct upb_MiniTable* m, uint32_t i) { - return &m->UPB_PRIVATE(subs)[i]; +UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsExtension)( + const struct upb_MiniTableField* f) { + return (f->UPB_ONLYBITS(mode) & kUpb_LabelFlags_IsExtension) != 0; } -UPB_INLINE const struct upb_MiniTable* UPB_PRIVATE( - _upb_MiniTable_GetSubMessageTable)(const struct upb_MiniTable* m, - const struct upb_MiniTableField* f) { - UPB_ASSERT(UPB_PRIVATE(_upb_MiniTableField_CType)(f) == kUpb_CType_Message); - const struct upb_MiniTable* ret = UPB_PRIVATE(_upb_MiniTableSub_Message)( - m->UPB_PRIVATE(subs)[f->UPB_PRIVATE(submsg_index)]); - UPB_ASSUME(ret); - return UPB_PRIVATE(_upb_MiniTable_IsEmpty)(ret) ? NULL : ret; +UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsPacked)( + const struct upb_MiniTableField* f) { + return (f->UPB_ONLYBITS(mode) & kUpb_LabelFlags_IsPacked) != 0; } -UPB_INLINE const struct upb_MiniTableEnum* UPB_PRIVATE( - _upb_MiniTable_GetSubEnumTable)(const struct upb_MiniTable* m, - const struct upb_MiniTableField* f) { - UPB_ASSERT(UPB_PRIVATE(_upb_MiniTableField_CType)(f) == kUpb_CType_Enum); - return UPB_PRIVATE(_upb_MiniTableSub_Enum)( - m->UPB_PRIVATE(subs)[f->UPB_PRIVATE(submsg_index)]); +UPB_INLINE upb_FieldType +UPB_PRIVATE(_upb_MiniTableField_Type)(const struct upb_MiniTableField* f) { + const upb_FieldType type = (upb_FieldType)f->UPB_PRIVATE(descriptortype); + if (UPB_PRIVATE(_upb_MiniTableField_IsAlternate)(f)) { + if (type == kUpb_FieldType_Int32) return kUpb_FieldType_Enum; + if (type == kUpb_FieldType_Bytes) return kUpb_FieldType_String; + UPB_ASSERT(false); + } + return type; } -UPB_INLINE const struct upb_MiniTableField* UPB_PRIVATE(_upb_MiniTable_MapKey)( - const struct upb_MiniTable* m) { - UPB_ASSERT(UPB_PRIVATE(_upb_MiniTable_FieldCount)(m) == 2); - const struct upb_MiniTableField* f = - UPB_PRIVATE(_upb_MiniTable_GetFieldByIndex)(m, 0); - UPB_ASSERT(UPB_PRIVATE(_upb_MiniTableField_Number)(f) == 1); - return f; +UPB_INLINE upb_CType +UPB_PRIVATE(_upb_MiniTableField_CType)(const struct upb_MiniTableField* f) { + return upb_FieldType_CType(UPB_PRIVATE(_upb_MiniTableField_Type)(f)); } -UPB_INLINE const struct upb_MiniTableField* UPB_PRIVATE( - _upb_MiniTable_MapValue)(const struct upb_MiniTable* m) { - UPB_ASSERT(UPB_PRIVATE(_upb_MiniTable_FieldCount)(m) == 2); - const struct upb_MiniTableField* f = - UPB_PRIVATE(_upb_MiniTable_GetFieldByIndex)(m, 1); - UPB_ASSERT(UPB_PRIVATE(_upb_MiniTableField_Number)(f) == 2); - return f; +UPB_INLINE char UPB_PRIVATE(_upb_MiniTableField_HasbitMask)( + const struct upb_MiniTableField* f) { + UPB_ASSERT(f->presence > 0); + const size_t index = f->presence; + return 1 << (index % 8); } -UPB_INLINE bool UPB_PRIVATE(_upb_MiniTable_MessageFieldIsLinked)( - const struct upb_MiniTable* m, const struct upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTable_GetSubMessageTable)(m, f) != NULL; +UPB_INLINE size_t UPB_PRIVATE(_upb_MiniTableField_HasbitOffset)( + const struct upb_MiniTableField* f) { + UPB_ASSERT(f->presence > 0); + const size_t index = f->presence; + return index / 8; } -// Computes a bitmask in which the |m->required_count| lowest bits are set, -// except that we skip the lowest bit (because upb never uses hasbit 0). -// -// Sample output: -// RequiredMask(1) => 0b10 (0x2) -// RequiredMask(5) => 0b111110 (0x3e) -UPB_INLINE uint64_t -UPB_PRIVATE(_upb_MiniTable_RequiredMask)(const struct upb_MiniTable* m) { - int n = m->UPB_PRIVATE(required_count); - UPB_ASSERT(0 < n && n <= 63); - return ((1ULL << n) - 1) << 1; +UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsClosedEnum)( + const struct upb_MiniTableField* f) { + return f->UPB_PRIVATE(descriptortype) == kUpb_FieldType_Enum; +} + +UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsInOneof)( + const struct upb_MiniTableField* f) { + return f->presence < 0; +} + +UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsSubMessage)( + const struct upb_MiniTableField* f) { + return f->UPB_PRIVATE(descriptortype) == kUpb_FieldType_Message || + f->UPB_PRIVATE(descriptortype) == kUpb_FieldType_Group; +} + +UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_HasPresence)( + const struct upb_MiniTableField* f) { + if (UPB_PRIVATE(_upb_MiniTableField_IsExtension)(f)) { + return UPB_PRIVATE(_upb_MiniTableField_IsScalar)(f); + } else { + return f->presence != 0; + } +} + +UPB_INLINE uint32_t +UPB_PRIVATE(_upb_MiniTableField_Number)(const struct upb_MiniTableField* f) { + return f->UPB_ONLYBITS(number); +} + +UPB_INLINE uint16_t +UPB_PRIVATE(_upb_MiniTableField_Offset)(const struct upb_MiniTableField* f) { + return f->UPB_ONLYBITS(offset); +} + +UPB_INLINE size_t UPB_PRIVATE(_upb_MiniTableField_OneofOffset)( + const struct upb_MiniTableField* f) { + UPB_ASSERT(UPB_PRIVATE(_upb_MiniTableField_IsInOneof)(f)); + return ~(ptrdiff_t)f->presence; +} + +UPB_INLINE void UPB_PRIVATE(_upb_MiniTableField_CheckIsArray)( + const struct upb_MiniTableField* f) { + UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == + kUpb_FieldRep_NativePointer); + UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_IsArray)(f)); + UPB_ASSUME(f->presence == 0); +} + +UPB_INLINE void UPB_PRIVATE(_upb_MiniTableField_CheckIsMap)( + const struct upb_MiniTableField* f) { + UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == + kUpb_FieldRep_NativePointer); + UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_IsMap)(f)); + UPB_ASSUME(f->presence == 0); +} + +UPB_INLINE size_t UPB_PRIVATE(_upb_MiniTableField_ElemSizeLg2)( + const struct upb_MiniTableField* f) { + const upb_FieldType field_type = UPB_PRIVATE(_upb_MiniTableField_Type)(f); + return UPB_PRIVATE(_upb_FieldType_SizeLg2)(field_type); } +// LINT.ThenChange(//depot/google3/third_party/upb/bits/typescript/mini_table_field.ts) + #ifdef __cplusplus } /* extern "C" */ #endif -#endif /* UPB_MINI_TABLE_INTERNAL_MESSAGE_H_ */ +#endif /* UPB_MINI_TABLE_INTERNAL_FIELD_H_ */ // Must be last. -typedef struct upb_MiniTable upb_MiniTable; +typedef struct upb_MiniTableField upb_MiniTableField; #ifdef __cplusplus extern "C" { #endif -UPB_API const upb_MiniTableField* upb_MiniTable_FindFieldByNumber( - const upb_MiniTable* m, uint32_t number); +UPB_API_INLINE upb_CType upb_MiniTableField_CType(const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_CType)(f); +} -UPB_API_INLINE const upb_MiniTableField* upb_MiniTable_GetFieldByIndex( - const upb_MiniTable* m, uint32_t index) { - return UPB_PRIVATE(_upb_MiniTable_GetFieldByIndex)(m, index); +UPB_API_INLINE bool upb_MiniTableField_HasPresence( + const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_HasPresence)(f); } -UPB_API_INLINE int upb_MiniTable_FieldCount(const upb_MiniTable* m) { - return UPB_PRIVATE(_upb_MiniTable_FieldCount)(m); +UPB_API_INLINE bool upb_MiniTableField_IsArray(const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_IsArray)(f); } -// Returns the MiniTable for a message field, NULL if the field is unlinked. -UPB_API_INLINE const upb_MiniTable* upb_MiniTable_GetSubMessageTable( - const upb_MiniTable* m, const upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTable_GetSubMessageTable)(m, f); +UPB_API_INLINE bool upb_MiniTableField_IsClosedEnum( + const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_IsClosedEnum)(f); } -// Returns the MiniTableEnum for a message field, NULL if the field is unlinked. -UPB_API_INLINE const upb_MiniTableEnum* upb_MiniTable_GetSubEnumTable( - const upb_MiniTable* m, const upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTable_GetSubEnumTable)(m, f); +UPB_API_INLINE bool upb_MiniTableField_IsExtension( + const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_IsExtension)(f); } -// Returns the MiniTableField for the key of a map. -UPB_API_INLINE const upb_MiniTableField* upb_MiniTable_MapKey( - const upb_MiniTable* m) { - return UPB_PRIVATE(_upb_MiniTable_MapKey)(m); +UPB_API_INLINE bool upb_MiniTableField_IsInOneof(const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_IsInOneof)(f); } -// Returns the MiniTableField for the value of a map. -UPB_API_INLINE const upb_MiniTableField* upb_MiniTable_MapValue( - const upb_MiniTable* m) { - return UPB_PRIVATE(_upb_MiniTable_MapValue)(m); +UPB_API_INLINE bool upb_MiniTableField_IsMap(const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_IsMap)(f); } -// Returns true if this MiniTable field is linked to a MiniTable for the -// sub-message. -UPB_API_INLINE bool upb_MiniTable_MessageFieldIsLinked( - const upb_MiniTable* m, const upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTable_MessageFieldIsLinked)(m, f); +UPB_API_INLINE bool upb_MiniTableField_IsPacked(const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_IsPacked)(f); } -// If this field is in a oneof, returns the first field in the oneof. -// -// Otherwise returns NULL. -// -// Usage: -// const upb_MiniTableField* field = upb_MiniTable_GetOneof(m, f); -// do { -// .. -// } while (upb_MiniTable_NextOneofField(m, &field); -// -const upb_MiniTableField* upb_MiniTable_GetOneof(const upb_MiniTable* m, - const upb_MiniTableField* f); +UPB_API_INLINE bool upb_MiniTableField_IsScalar(const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_IsScalar)(f); +} -// Iterates to the next field in the oneof. If this is the last field in the -// oneof, returns false. The ordering of fields in the oneof is not -// guaranteed. -// REQUIRES: |f| is the field initialized by upb_MiniTable_GetOneof and updated -// by prior upb_MiniTable_NextOneofField calls. -bool upb_MiniTable_NextOneofField(const upb_MiniTable* m, - const upb_MiniTableField** f); +UPB_API_INLINE bool upb_MiniTableField_IsSubMessage( + const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_IsSubMessage)(f); +} + +UPB_API_INLINE uint32_t upb_MiniTableField_Number(const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_Number)(f); +} + +UPB_API_INLINE upb_FieldType +upb_MiniTableField_Type(const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_Type)(f); +} #ifdef __cplusplus } /* extern "C" */ #endif -#endif /* UPB_MINI_TABLE_MESSAGE_H_ */ +#endif /* UPB_MINI_TABLE_FIELD_H_ */ -// Must be last. +#ifndef UPB_MINI_TABLE_INTERNAL_EXTENSION_H_ +#define UPB_MINI_TABLE_INTERNAL_EXTENSION_H_ -#ifdef __cplusplus -extern "C" { -#endif +#include -extern const float kUpb_FltInfinity; -extern const double kUpb_Infinity; -extern const double kUpb_NaN; -/* Internal members of a upb_Message that track unknown fields and/or - * extensions. We can change this without breaking binary compatibility. We put - * these before the user's data. The user's upb_Message* points after the - * upb_Message_Internal. */ +#ifndef UPB_MINI_TABLE_INTERNAL_SUB_H_ +#define UPB_MINI_TABLE_INTERNAL_SUB_H_ -struct upb_Message_InternalData { - /* Total size of this structure, including the data that follows. - * Must be aligned to 8, which is alignof(upb_Extension) */ - uint32_t size; +// Must be last. - /* Offsets relative to the beginning of this structure. - * - * Unknown data grows forward from the beginning to unknown_end. - * Extension data grows backward from size to ext_begin. - * When the two meet, we're out of data and have to realloc. - * - * If we imagine that the final member of this struct is: - * char data[size - overhead]; // overhead = - * sizeof(upb_Message_InternalData) - * - * Then we have: - * unknown data: data[0 .. (unknown_end - overhead)] - * extensions data: data[(ext_begin - overhead) .. (size - overhead)] */ - uint32_t unknown_end; - uint32_t ext_begin; - /* Data follows, as if there were an array: - * char data[size - sizeof(upb_Message_InternalData)]; */ +union upb_MiniTableSub { + const struct upb_MiniTable* UPB_PRIVATE(submsg); + const struct upb_MiniTableEnum* UPB_PRIVATE(subenum); }; -UPB_INLINE size_t upb_msg_sizeof(const upb_MiniTable* m) { - return m->UPB_PRIVATE(size) + sizeof(upb_Message_Internal); -} +#ifdef __cplusplus +extern "C" { +#endif -// Inline version upb_Message_New(), for internal use. -UPB_INLINE struct upb_Message* _upb_Message_New(const upb_MiniTable* mini_table, - upb_Arena* arena) { - size_t size = upb_msg_sizeof(mini_table); - void* mem = upb_Arena_Malloc(arena, size + sizeof(upb_Message_Internal)); - if (UPB_UNLIKELY(!mem)) return NULL; - struct upb_Message* msg = - UPB_PTR_AT(mem, sizeof(upb_Message_Internal), struct upb_Message); - memset(mem, 0, size); - return msg; +UPB_INLINE union upb_MiniTableSub UPB_PRIVATE(_upb_MiniTableSub_FromEnum)( + const struct upb_MiniTableEnum* subenum) { + union upb_MiniTableSub out; + out.UPB_PRIVATE(subenum) = subenum; + return out; } -UPB_INLINE upb_Message_Internal* upb_Message_Getinternal( - const struct upb_Message* msg) { - ptrdiff_t size = sizeof(upb_Message_Internal); - return (upb_Message_Internal*)((char*)msg - size); +UPB_INLINE union upb_MiniTableSub UPB_PRIVATE(_upb_MiniTableSub_FromMessage)( + const struct upb_MiniTable* submsg) { + union upb_MiniTableSub out; + out.UPB_PRIVATE(submsg) = submsg; + return out; } -// Discards the unknown fields for this message only. -void _upb_Message_DiscardUnknown_shallow(struct upb_Message* msg); - -// Adds unknown data (serialized protobuf data) to the given message. -// The data is copied into the message instance. -bool UPB_PRIVATE(_upb_Message_AddUnknown)(struct upb_Message* msg, - const char* data, size_t len, - upb_Arena* arena); +UPB_INLINE const struct upb_MiniTableEnum* UPB_PRIVATE(_upb_MiniTableSub_Enum)( + const union upb_MiniTableSub sub) { + return sub.UPB_PRIVATE(subenum); +} -bool UPB_PRIVATE(_upb_Message_Realloc)(struct upb_Message* msg, size_t need, - upb_Arena* arena); +UPB_INLINE const struct upb_MiniTable* UPB_PRIVATE(_upb_MiniTableSub_Message)( + const union upb_MiniTableSub sub) { + return sub.UPB_PRIVATE(submsg); +} #ifdef __cplusplus } /* extern "C" */ #endif -#endif /* UPB_MESSAGE_INTERNAL_H_ */ - -#ifndef UPB_MINI_TABLE_EXTENSION_H_ -#define UPB_MINI_TABLE_EXTENSION_H_ - -#include - - -#ifndef UPB_MINI_TABLE_INTERNAL_EXTENSION_H_ -#define UPB_MINI_TABLE_INTERNAL_EXTENSION_H_ - -#include - +#endif /* UPB_MINI_TABLE_INTERNAL_SUB_H_ */ // Must be last. @@ -1865,32 +1859,56 @@ UPB_INLINE void UPB_PRIVATE(_upb_MiniTableExtension_SetSubMessage)( #endif /* UPB_MINI_TABLE_INTERNAL_EXTENSION_H_ */ +#ifndef UPB_MINI_TABLE_MESSAGE_H_ +#define UPB_MINI_TABLE_MESSAGE_H_ + + +#ifndef UPB_MINI_TABLE_ENUM_H_ +#define UPB_MINI_TABLE_ENUM_H_ + +#include + + +#ifndef UPB_MINI_TABLE_INTERNAL_ENUM_H_ +#define UPB_MINI_TABLE_INTERNAL_ENUM_H_ + +#include + // Must be last. -typedef struct upb_MiniTableExtension upb_MiniTableExtension; +struct upb_MiniTableEnum { + uint32_t UPB_PRIVATE(mask_limit); // Highest that can be tested with mask. + uint32_t UPB_PRIVATE(value_count); // Number of values after the bitfield. + uint32_t UPB_PRIVATE(data)[]; // Bitmask + enumerated values follow. +}; #ifdef __cplusplus extern "C" { #endif -UPB_API_INLINE const upb_MiniTableField* upb_MiniTableExtension_AsField( - const upb_MiniTableExtension* e) { - return UPB_PRIVATE(_upb_MiniTableExtension_AsField)(e); -} - -UPB_API_INLINE uint32_t -upb_MiniTableExtension_Number(const upb_MiniTableExtension* e) { - return UPB_PRIVATE(_upb_MiniTableExtension_Number)(e); -} - -UPB_API_INLINE const upb_MiniTable* upb_MiniTableExtension_GetSubMessage( - const upb_MiniTableExtension* e) { - return UPB_PRIVATE(_upb_MiniTableExtension_GetSubMessage)(e); -} +UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableEnum_CheckValue)( + const struct upb_MiniTableEnum* e, uint32_t val) { + if (UPB_LIKELY(val < 64)) { + const uint64_t mask = + e->UPB_PRIVATE(data)[0] | ((uint64_t)e->UPB_PRIVATE(data)[1] << 32); + const uint64_t bit = 1ULL << val; + return (mask & bit) != 0; + } + if (UPB_LIKELY(val < e->UPB_PRIVATE(mask_limit))) { + const uint32_t mask = e->UPB_PRIVATE(data)[val / 32]; + const uint32_t bit = 1ULL << (val % 32); + return (mask & bit) != 0; + } -UPB_API_INLINE void upb_MiniTableExtension_SetSubMessage( - upb_MiniTableExtension* e, const upb_MiniTable* m) { - UPB_PRIVATE(_upb_MiniTableExtension_SetSubMessage)(e, m); + // OPT: binary search long lists? + const uint32_t* start = + &e->UPB_PRIVATE(data)[e->UPB_PRIVATE(mask_limit) / 32]; + const uint32_t* limit = &e->UPB_PRIVATE( + data)[e->UPB_PRIVATE(mask_limit) / 32 + e->UPB_PRIVATE(value_count)]; + for (const uint32_t* p = start; p < limit; p++) { + if (*p == val) return true; + } + return false; } #ifdef __cplusplus @@ -1898,606 +1916,577 @@ UPB_API_INLINE void upb_MiniTableExtension_SetSubMessage( #endif -#endif /* UPB_MINI_TABLE_EXTENSION_H_ */ +#endif /* UPB_MINI_TABLE_INTERNAL_ENUM_H_ */ -// Must be last. +// Must be last -// The internal representation of an extension is self-describing: it contains -// enough information that we can serialize it to binary format without needing -// to look it up in a upb_ExtensionRegistry. -// -// This representation allocates 16 bytes to data on 64-bit platforms. -// This is rather wasteful for scalars (in the extreme case of bool, -// it wastes 15 bytes). We accept this because we expect messages to be -// the most common extension type. -struct upb_Extension { - const upb_MiniTableExtension* ext; - union { - upb_StringView str; - void* ptr; - char scalar_data[8]; - } data; -}; +typedef struct upb_MiniTableEnum upb_MiniTableEnum; #ifdef __cplusplus extern "C" { #endif -// Adds the given extension data to the given message. -// |ext| is copied into the message instance. -// This logically replaces any previously-added extension with this number. -struct upb_Extension* _upb_Message_GetOrCreateExtension( - struct upb_Message* msg, const upb_MiniTableExtension* ext, - upb_Arena* arena); - -// Returns an array of extensions for this message. -// Note: the array is ordered in reverse relative to the order of creation. -const struct upb_Extension* UPB_PRIVATE(_upb_Message_Getexts)( - const struct upb_Message* msg, size_t* count); - -// Returns an extension for a message with a given mini table, -// or NULL if no extension exists with this mini table. -const struct upb_Extension* _upb_Message_Getext( - const struct upb_Message* msg, const upb_MiniTableExtension* ext); +// Validates enum value against range defined by enum mini table. +UPB_INLINE bool upb_MiniTableEnum_CheckValue(const upb_MiniTableEnum* e, + uint32_t val) { + return UPB_PRIVATE(_upb_MiniTableEnum_CheckValue)(e, val); +} #ifdef __cplusplus } /* extern "C" */ #endif -#endif /* UPB_MESSAGE_INTERNAL_EXTENSION_H_ */ +#endif /* UPB_MINI_TABLE_ENUM_H_ */ -// EVERYTHING BELOW THIS LINE IS INTERNAL - DO NOT USE ///////////////////////// +#ifndef UPB_MINI_TABLE_INTERNAL_MESSAGE_H_ +#define UPB_MINI_TABLE_INTERNAL_MESSAGE_H_ -#ifndef UPB_MESSAGE_INTERNAL_MAP_H_ -#define UPB_MESSAGE_INTERNAL_MAP_H_ +#include -#include -#include +// Must be last. -#ifndef UPB_HASH_STR_TABLE_H_ -#define UPB_HASH_STR_TABLE_H_ +struct upb_Decoder; +struct upb_Message; +typedef const char* _upb_FieldParser(struct upb_Decoder* d, const char* ptr, + struct upb_Message* msg, intptr_t table, + uint64_t hasbits, uint64_t data); +typedef struct { + uint64_t field_data; + _upb_FieldParser* field_parser; +} _upb_FastTable_Entry; +typedef enum { + kUpb_ExtMode_NonExtendable = 0, // Non-extendable message. + kUpb_ExtMode_Extendable = 1, // Normal extendable message. + kUpb_ExtMode_IsMessageSet = 2, // MessageSet message. + kUpb_ExtMode_IsMessageSet_ITEM = + 3, // MessageSet item (temporary only, see decode.c) -/* - * upb_table - * - * This header is INTERNAL-ONLY! Its interfaces are not public or stable! - * This file defines very fast int->upb_value (inttable) and string->upb_value - * (strtable) hash tables. - * - * The table uses chained scatter with Brent's variation (inspired by the Lua - * implementation of hash tables). The hash function for strings is Austin - * Appleby's "MurmurHash." - * - * The inttable uses uintptr_t as its key, which guarantees it can be used to - * store pointers or integers of at least 32 bits (upb isn't really useful on - * systems where sizeof(void*) < 4). - * - * The table must be homogeneous (all values of the same type). In debug - * mode, we check this on insert and lookup. - */ + // During table building we steal a bit to indicate that the message is a map + // entry. *Only* used during table building! + kUpb_ExtMode_IsMapEntry = 4, +} upb_ExtMode; -#ifndef UPB_HASH_COMMON_H_ -#define UPB_HASH_COMMON_H_ +// 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. -#include +// LINT.IfChange(minitable_struct_definition) +struct upb_MiniTable { + const union upb_MiniTableSub* UPB_PRIVATE(subs); + const struct upb_MiniTableField* UPB_ONLYBITS(fields); + // Must be aligned to sizeof(void*). Doesn't include internal members like + // unknown fields, extension dict, pointer to msglayout, etc. + uint16_t UPB_PRIVATE(size); -// Must be last. + uint16_t UPB_ONLYBITS(field_count); + + uint8_t UPB_PRIVATE(ext); // upb_ExtMode, uint8_t here so sizeof(ext) == 1 + uint8_t UPB_PRIVATE(dense_below); + uint8_t UPB_PRIVATE(table_mask); + uint8_t UPB_PRIVATE(required_count); // Required fields have the low hasbits. + + // To statically initialize the tables of variable length, we need a flexible + // array member, and we need to compile in gnu99 mode (constant initialization + // of flexible array members is a GNU extension, not in C99 unfortunately. + _upb_FastTable_Entry UPB_PRIVATE(fasttable)[]; +}; +// LINT.ThenChange(//depot/google3/third_party/upb/bits/typescript/mini_table.ts) #ifdef __cplusplus extern "C" { #endif -/* upb_value ******************************************************************/ - -typedef struct { - uint64_t val; -} upb_value; - -UPB_INLINE void _upb_value_setval(upb_value* v, uint64_t val) { v->val = val; } - -/* For each value ctype, define the following set of functions: - * - * // Get/set an int32 from a upb_value. - * int32_t upb_value_getint32(upb_value val); - * void upb_value_setint32(upb_value *val, int32_t cval); - * - * // Construct a new upb_value from an int32. - * upb_value upb_value_int32(int32_t val); */ -#define FUNCS(name, membername, type_t, converter) \ - UPB_INLINE void upb_value_set##name(upb_value* val, type_t cval) { \ - val->val = (converter)cval; \ - } \ - UPB_INLINE upb_value upb_value_##name(type_t val) { \ - upb_value ret; \ - upb_value_set##name(&ret, val); \ - return ret; \ - } \ - UPB_INLINE type_t upb_value_get##name(upb_value val) { \ - return (type_t)(converter)val.val; \ - } - -FUNCS(int32, int32, int32_t, int32_t) -FUNCS(int64, int64, int64_t, int64_t) -FUNCS(uint32, uint32, uint32_t, uint32_t) -FUNCS(uint64, uint64, uint64_t, uint64_t) -FUNCS(bool, _bool, bool, bool) -FUNCS(cstr, cstr, char*, uintptr_t) -FUNCS(uintptr, uptr, uintptr_t, uintptr_t) -FUNCS(ptr, ptr, void*, uintptr_t) -FUNCS(constptr, constptr, const void*, uintptr_t) - -#undef FUNCS +UPB_INLINE const struct upb_MiniTable* UPB_PRIVATE(_upb_MiniTable_Empty)(void) { + extern const struct upb_MiniTable UPB_PRIVATE(_kUpb_MiniTable_Empty); -UPB_INLINE void upb_value_setfloat(upb_value* val, float cval) { - memcpy(&val->val, &cval, sizeof(cval)); + return &UPB_PRIVATE(_kUpb_MiniTable_Empty); } -UPB_INLINE void upb_value_setdouble(upb_value* val, double cval) { - memcpy(&val->val, &cval, sizeof(cval)); +UPB_INLINE int UPB_PRIVATE(_upb_MiniTable_FieldCount)( + const struct upb_MiniTable* m) { + return m->UPB_ONLYBITS(field_count); } -UPB_INLINE upb_value upb_value_float(float cval) { - upb_value ret; - upb_value_setfloat(&ret, cval); - return ret; -} +UPB_INLINE bool UPB_PRIVATE(_upb_MiniTable_IsEmpty)( + const struct upb_MiniTable* m) { + extern const struct upb_MiniTable UPB_PRIVATE(_kUpb_MiniTable_Empty); -UPB_INLINE upb_value upb_value_double(double cval) { - upb_value ret; - upb_value_setdouble(&ret, cval); - return ret; + return m == &UPB_PRIVATE(_kUpb_MiniTable_Empty); } -/* upb_tabkey *****************************************************************/ - -/* Either: - * 1. an actual integer key, or - * 2. a pointer to a string prefixed by its uint32_t length, owned by us. - * - * ...depending on whether this is a string table or an int table. We would - * make this a union of those two types, but C89 doesn't support statically - * initializing a non-first union member. */ -typedef uintptr_t upb_tabkey; - -UPB_INLINE char* upb_tabstr(upb_tabkey key, uint32_t* len) { - char* mem = (char*)key; - if (len) memcpy(len, mem, sizeof(*len)); - return mem + sizeof(*len); +UPB_INLINE const struct upb_MiniTableField* UPB_PRIVATE( + _upb_MiniTable_GetFieldByIndex)(const struct upb_MiniTable* m, uint32_t i) { + return &m->UPB_ONLYBITS(fields)[i]; } -UPB_INLINE upb_StringView upb_tabstrview(upb_tabkey key) { - upb_StringView ret; - uint32_t len; - ret.data = upb_tabstr(key, &len); - ret.size = len; - return ret; +UPB_INLINE const union upb_MiniTableSub* UPB_PRIVATE( + _upb_MiniTable_GetSubByIndex)(const struct upb_MiniTable* m, uint32_t i) { + return &m->UPB_PRIVATE(subs)[i]; } -/* upb_tabval *****************************************************************/ - -typedef struct upb_tabval { - uint64_t val; -} upb_tabval; - -#define UPB_TABVALUE_EMPTY_INIT \ - { -1 } - -/* upb_table ******************************************************************/ - -typedef struct _upb_tabent { - upb_tabkey key; - upb_tabval val; - - /* Internal chaining. This is const so we can create static initializers for - * tables. We cast away const sometimes, but *only* when the containing - * upb_table is known to be non-const. This requires a bit of care, but - * the subtlety is confined to table.c. */ - const struct _upb_tabent* next; -} upb_tabent; +UPB_INLINE const struct upb_MiniTable* UPB_PRIVATE( + _upb_MiniTable_GetSubMessageTable)(const struct upb_MiniTable* m, + const struct upb_MiniTableField* f) { + UPB_ASSERT(UPB_PRIVATE(_upb_MiniTableField_CType)(f) == kUpb_CType_Message); + const struct upb_MiniTable* ret = UPB_PRIVATE(_upb_MiniTableSub_Message)( + m->UPB_PRIVATE(subs)[f->UPB_PRIVATE(submsg_index)]); + UPB_ASSUME(ret); + return UPB_PRIVATE(_upb_MiniTable_IsEmpty)(ret) ? NULL : ret; +} -typedef struct { - size_t count; /* Number of entries in the hash part. */ - uint32_t mask; /* Mask to turn hash value -> bucket. */ - uint32_t max_count; /* Max count before we hit our load limit. */ - uint8_t size_lg2; /* Size of the hashtable part is 2^size_lg2 entries. */ - upb_tabent* entries; -} upb_table; +UPB_INLINE const struct upb_MiniTableEnum* UPB_PRIVATE( + _upb_MiniTable_GetSubEnumTable)(const struct upb_MiniTable* m, + const struct upb_MiniTableField* f) { + UPB_ASSERT(UPB_PRIVATE(_upb_MiniTableField_CType)(f) == kUpb_CType_Enum); + return UPB_PRIVATE(_upb_MiniTableSub_Enum)( + m->UPB_PRIVATE(subs)[f->UPB_PRIVATE(submsg_index)]); +} -UPB_INLINE size_t upb_table_size(const upb_table* t) { - return t->size_lg2 ? 1 << t->size_lg2 : 0; +UPB_INLINE const struct upb_MiniTableField* UPB_PRIVATE(_upb_MiniTable_MapKey)( + const struct upb_MiniTable* m) { + UPB_ASSERT(UPB_PRIVATE(_upb_MiniTable_FieldCount)(m) == 2); + const struct upb_MiniTableField* f = + UPB_PRIVATE(_upb_MiniTable_GetFieldByIndex)(m, 0); + UPB_ASSERT(UPB_PRIVATE(_upb_MiniTableField_Number)(f) == 1); + return f; } -// Internal-only functions, in .h file only out of necessity. +UPB_INLINE const struct upb_MiniTableField* UPB_PRIVATE( + _upb_MiniTable_MapValue)(const struct upb_MiniTable* m) { + UPB_ASSERT(UPB_PRIVATE(_upb_MiniTable_FieldCount)(m) == 2); + const struct upb_MiniTableField* f = + UPB_PRIVATE(_upb_MiniTable_GetFieldByIndex)(m, 1); + UPB_ASSERT(UPB_PRIVATE(_upb_MiniTableField_Number)(f) == 2); + return f; +} -UPB_INLINE bool upb_tabent_isempty(const upb_tabent* e) { return e->key == 0; } +UPB_INLINE bool UPB_PRIVATE(_upb_MiniTable_MessageFieldIsLinked)( + const struct upb_MiniTable* m, const struct upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTable_GetSubMessageTable)(m, f) != NULL; +} -uint32_t _upb_Hash(const void* p, size_t n, uint64_t seed); +// Computes a bitmask in which the |m->required_count| lowest bits are set, +// except that we skip the lowest bit (because upb never uses hasbit 0). +// +// Sample output: +// RequiredMask(1) => 0b10 (0x2) +// RequiredMask(5) => 0b111110 (0x3e) +UPB_INLINE uint64_t +UPB_PRIVATE(_upb_MiniTable_RequiredMask)(const struct upb_MiniTable* m) { + int n = m->UPB_PRIVATE(required_count); + UPB_ASSERT(0 < n && n <= 63); + return ((1ULL << n) - 1) << 1; +} #ifdef __cplusplus } /* extern "C" */ #endif -#endif /* UPB_HASH_COMMON_H_ */ +#endif /* UPB_MINI_TABLE_INTERNAL_MESSAGE_H_ */ // Must be last. -typedef struct { - upb_table t; -} upb_strtable; +typedef struct upb_MiniTable upb_MiniTable; #ifdef __cplusplus extern "C" { #endif -// Initialize a table. If memory allocation failed, false is returned and -// the table is uninitialized. -bool upb_strtable_init(upb_strtable* table, size_t expected_size, upb_Arena* a); +UPB_API const upb_MiniTableField* upb_MiniTable_FindFieldByNumber( + const upb_MiniTable* m, uint32_t number); -// Returns the number of values in the table. -UPB_INLINE size_t upb_strtable_count(const upb_strtable* t) { - return t->t.count; +UPB_API_INLINE const upb_MiniTableField* upb_MiniTable_GetFieldByIndex( + const upb_MiniTable* m, uint32_t index) { + return UPB_PRIVATE(_upb_MiniTable_GetFieldByIndex)(m, index); } -void upb_strtable_clear(upb_strtable* t); +UPB_API_INLINE int upb_MiniTable_FieldCount(const upb_MiniTable* m) { + return UPB_PRIVATE(_upb_MiniTable_FieldCount)(m); +} -// Inserts the given key into the hashtable with the given value. -// The key must not already exist in the hash table. The key is not required -// to be NULL-terminated, and the table will make an internal copy of the key. -// -// If a table resize was required but memory allocation failed, false is -// returned and the table is unchanged. */ -bool upb_strtable_insert(upb_strtable* t, const char* key, size_t len, - upb_value val, upb_Arena* a); +// Returns the MiniTable for a message field, NULL if the field is unlinked. +UPB_API_INLINE const upb_MiniTable* upb_MiniTable_GetSubMessageTable( + const upb_MiniTable* m, const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTable_GetSubMessageTable)(m, f); +} -// Looks up key in this table, returning "true" if the key was found. -// If v is non-NULL, copies the value for this key into *v. -bool upb_strtable_lookup2(const upb_strtable* t, const char* key, size_t len, - upb_value* v); +// Returns the MiniTableEnum for a message field, NULL if the field is unlinked. +UPB_API_INLINE const upb_MiniTableEnum* upb_MiniTable_GetSubEnumTable( + const upb_MiniTable* m, const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTable_GetSubEnumTable)(m, f); +} -// For NULL-terminated strings. -UPB_INLINE bool upb_strtable_lookup(const upb_strtable* t, const char* key, - upb_value* v) { - return upb_strtable_lookup2(t, key, strlen(key), v); +// Returns the MiniTableField for the key of a map. +UPB_API_INLINE const upb_MiniTableField* upb_MiniTable_MapKey( + const upb_MiniTable* m) { + return UPB_PRIVATE(_upb_MiniTable_MapKey)(m); } -// Removes an item from the table. Returns true if the remove was successful, -// and stores the removed item in *val if non-NULL. -bool upb_strtable_remove2(upb_strtable* t, const char* key, size_t len, - upb_value* val); +// Returns the MiniTableField for the value of a map. +UPB_API_INLINE const upb_MiniTableField* upb_MiniTable_MapValue( + const upb_MiniTable* m) { + return UPB_PRIVATE(_upb_MiniTable_MapValue)(m); +} -UPB_INLINE bool upb_strtable_remove(upb_strtable* t, const char* key, - upb_value* v) { - return upb_strtable_remove2(t, key, strlen(key), v); +// Returns true if this MiniTable field is linked to a MiniTable for the +// sub-message. +UPB_API_INLINE bool upb_MiniTable_MessageFieldIsLinked( + const upb_MiniTable* m, const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTable_MessageFieldIsLinked)(m, f); } -// Exposed for testing only. -bool upb_strtable_resize(upb_strtable* t, size_t size_lg2, upb_Arena* a); +// If this field is in a oneof, returns the first field in the oneof. +// +// Otherwise returns NULL. +// +// Usage: +// const upb_MiniTableField* field = upb_MiniTable_GetOneof(m, f); +// do { +// .. +// } while (upb_MiniTable_NextOneofField(m, &field); +// +const upb_MiniTableField* upb_MiniTable_GetOneof(const upb_MiniTable* m, + const upb_MiniTableField* f); -/* Iteration over strtable: - * - * intptr_t iter = UPB_STRTABLE_BEGIN; - * upb_StringView key; - * upb_value val; - * while (upb_strtable_next2(t, &key, &val, &iter)) { - * // ... - * } - */ +// Iterates to the next field in the oneof. If this is the last field in the +// oneof, returns false. The ordering of fields in the oneof is not +// guaranteed. +// REQUIRES: |f| is the field initialized by upb_MiniTable_GetOneof and updated +// by prior upb_MiniTable_NextOneofField calls. +bool upb_MiniTable_NextOneofField(const upb_MiniTable* m, + const upb_MiniTableField** f); -#define UPB_STRTABLE_BEGIN -1 +#ifdef __cplusplus +} /* extern "C" */ +#endif -bool upb_strtable_next2(const upb_strtable* t, upb_StringView* key, - upb_value* val, intptr_t* iter); -void upb_strtable_removeiter(upb_strtable* t, intptr_t* iter); -void upb_strtable_setentryvalue(upb_strtable* t, intptr_t iter, upb_value v); -/* DEPRECATED iterators, slated for removal. - * - * Iterators for string tables. We are subject to some kind of unusual - * design constraints: - * - * For high-level languages: - * - we must be able to guarantee that we don't crash or corrupt memory even if - * the program accesses an invalidated iterator. - * - * For C++11 range-based for: - * - iterators must be copyable - * - iterators must be comparable - * - it must be possible to construct an "end" value. - * - * Iteration order is undefined. - * - * Modifying the table invalidates iterators. upb_{str,int}table_done() is - * guaranteed to work even on an invalidated iterator, as long as the table it - * is iterating over has not been freed. Calling next() or accessing data from - * an invalidated iterator yields unspecified elements from the table, but it is - * guaranteed not to crash and to return real table elements (except when done() - * is true). */ -/* upb_strtable_iter **********************************************************/ +#endif /* UPB_MINI_TABLE_MESSAGE_H_ */ -/* upb_strtable_iter i; - * upb_strtable_begin(&i, t); - * for(; !upb_strtable_done(&i); upb_strtable_next(&i)) { - * const char *key = upb_strtable_iter_key(&i); - * const upb_value val = upb_strtable_iter_value(&i); - * // ... - * } - */ +// Must be last. -typedef struct { - const upb_strtable* t; - size_t index; -} upb_strtable_iter; +typedef struct upb_MiniTableExtension upb_MiniTableExtension; -UPB_INLINE const upb_tabent* str_tabent(const upb_strtable_iter* i) { - return &i->t->t.entries[i->index]; +#ifdef __cplusplus +extern "C" { +#endif + +UPB_API_INLINE const upb_MiniTableField* upb_MiniTableExtension_AsField( + const upb_MiniTableExtension* e) { + return UPB_PRIVATE(_upb_MiniTableExtension_AsField)(e); } -void upb_strtable_begin(upb_strtable_iter* i, const upb_strtable* t); -void upb_strtable_next(upb_strtable_iter* i); -bool upb_strtable_done(const upb_strtable_iter* i); -upb_StringView upb_strtable_iter_key(const upb_strtable_iter* i); -upb_value upb_strtable_iter_value(const upb_strtable_iter* i); -void upb_strtable_iter_setdone(upb_strtable_iter* i); -bool upb_strtable_iter_isequal(const upb_strtable_iter* i1, - const upb_strtable_iter* i2); +UPB_API_INLINE uint32_t +upb_MiniTableExtension_Number(const upb_MiniTableExtension* e) { + return UPB_PRIVATE(_upb_MiniTableExtension_Number)(e); +} + +UPB_API_INLINE const upb_MiniTable* upb_MiniTableExtension_GetSubMessage( + const upb_MiniTableExtension* e) { + return UPB_PRIVATE(_upb_MiniTableExtension_GetSubMessage)(e); +} + +UPB_API_INLINE void upb_MiniTableExtension_SetSubMessage( + upb_MiniTableExtension* e, const upb_MiniTable* m) { + UPB_PRIVATE(_upb_MiniTableExtension_SetSubMessage)(e, m); +} #ifdef __cplusplus } /* extern "C" */ #endif -#endif /* UPB_HASH_STR_TABLE_H_ */ +#endif /* UPB_MINI_TABLE_EXTENSION_H_ */ + +// Must be last. + +// The internal representation of an extension is self-describing: it contains +// enough information that we can serialize it to binary format without needing +// to look it up in a upb_ExtensionRegistry. +// +// This representation allocates 16 bytes to data on 64-bit platforms. +// This is rather wasteful for scalars (in the extreme case of bool, +// it wastes 15 bytes). We accept this because we expect messages to be +// the most common extension type. +struct upb_Extension { + const upb_MiniTableExtension* ext; + union { + upb_StringView str; + void* ptr; + char scalar_data[8]; + } data; +}; + +#ifdef __cplusplus +extern "C" { +#endif + +// Adds the given extension data to the given message. +// |ext| is copied into the message instance. +// This logically replaces any previously-added extension with this number. +struct upb_Extension* _upb_Message_GetOrCreateExtension( + struct upb_Message* msg, const upb_MiniTableExtension* ext, + upb_Arena* arena); + +// Returns an array of extensions for this message. +// Note: the array is ordered in reverse relative to the order of creation. +const struct upb_Extension* UPB_PRIVATE(_upb_Message_Getexts)( + const struct upb_Message* msg, size_t* count); + +// Returns an extension for a message with a given mini table, +// or NULL if no extension exists with this mini table. +const struct upb_Extension* _upb_Message_Getext( + const struct upb_Message* msg, const upb_MiniTableExtension* ext); -#ifndef UPB_MESSAGE_MAP_H_ -#define UPB_MESSAGE_MAP_H_ +#ifdef __cplusplus +} /* extern "C" */ +#endif -#include +#endif /* UPB_MESSAGE_INTERNAL_EXTENSION_H_ */ // Must be last. -typedef struct upb_Map upb_Map; - #ifdef __cplusplus extern "C" { #endif -// Creates a new map on the given arena with the given key/value size. -UPB_API upb_Map* upb_Map_New(upb_Arena* a, upb_CType key_type, - upb_CType value_type); - -// Returns the number of entries in the map. -UPB_API size_t upb_Map_Size(const upb_Map* map); +extern const float kUpb_FltInfinity; +extern const double kUpb_Infinity; +extern const double kUpb_NaN; -// Stores a value for the given key into |*val| (or the zero value if the key is -// not present). Returns whether the key was present. The |val| pointer may be -// NULL, in which case the function tests whether the given key is present. -UPB_API bool upb_Map_Get(const upb_Map* map, upb_MessageValue key, - upb_MessageValue* val); +/* Internal members of a upb_Message that track unknown fields and/or + * extensions. We can change this without breaking binary compatibility. We put + * these before the user's data. The user's upb_Message* points after the + * upb_Message_Internal. */ -// Removes all entries in the map. -UPB_API void upb_Map_Clear(upb_Map* map); +typedef struct { + /* Total size of this structure, including the data that follows. + * Must be aligned to 8, which is alignof(upb_Extension) */ + uint32_t size; -typedef enum { - kUpb_MapInsertStatus_Inserted = 0, - kUpb_MapInsertStatus_Replaced = 1, - kUpb_MapInsertStatus_OutOfMemory = 2, -} upb_MapInsertStatus; + /* Offsets relative to the beginning of this structure. + * + * Unknown data grows forward from the beginning to unknown_end. + * Extension data grows backward from size to ext_begin. + * When the two meet, we're out of data and have to realloc. + * + * If we imagine that the final member of this struct is: + * char data[size - overhead]; // overhead = + * sizeof(upb_Message_InternalData) + * + * Then we have: + * unknown data: data[0 .. (unknown_end - overhead)] + * extensions data: data[(ext_begin - overhead) .. (size - overhead)] */ + uint32_t unknown_end; + uint32_t ext_begin; + /* Data follows, as if there were an array: + * char data[size - sizeof(upb_Message_InternalData)]; */ +} upb_Message_InternalData; -// Sets the given key to the given value, returning whether the key was inserted -// or replaced. If the key was inserted, then any existing iterators will be -// invalidated. -UPB_API upb_MapInsertStatus upb_Map_Insert(upb_Map* map, upb_MessageValue key, - upb_MessageValue val, - upb_Arena* arena); +typedef struct { + union { + upb_Message_InternalData* internal; -// Sets the given key to the given value. Returns false if memory allocation -// failed. If the key is newly inserted, then any existing iterators will be -// invalidated. -UPB_API_INLINE bool upb_Map_Set(upb_Map* map, upb_MessageValue key, - upb_MessageValue val, upb_Arena* arena) { - return upb_Map_Insert(map, key, val, arena) != - kUpb_MapInsertStatus_OutOfMemory; -} + // Force 8-byte alignment, since the data members may contain members that + // require 8-byte alignment. + double d; + }; +} upb_Message_Internal; -// Deletes this key from the table. Returns true if the key was present. -// If present and |val| is non-NULL, stores the deleted value. -UPB_API bool upb_Map_Delete(upb_Map* map, upb_MessageValue key, - upb_MessageValue* val); +struct upb_Message { + int unused; // Placeholder cuz Windows won't compile an empty struct. +}; -// (DEPRECATED and going away soon. Do not use.) -UPB_INLINE bool upb_Map_Delete2(upb_Map* map, upb_MessageValue key, - upb_MessageValue* val) { - return upb_Map_Delete(map, key, val); +UPB_INLINE size_t upb_msg_sizeof(const upb_MiniTable* m) { + return m->UPB_PRIVATE(size) + sizeof(upb_Message_Internal); } -// Map iteration: -// -// size_t iter = kUpb_Map_Begin; -// upb_MessageValue key, val; -// while (upb_Map_Next(map, &key, &val, &iter)) { -// ... -// } - -#define kUpb_Map_Begin ((size_t)-1) - -// Advances to the next entry. Returns false if no more entries are present. -// Otherwise returns true and populates both *key and *value. -UPB_API bool upb_Map_Next(const upb_Map* map, upb_MessageValue* key, - upb_MessageValue* val, size_t* iter); - -// Sets the value for the entry pointed to by iter. -// WARNING: this does not currently work for string values! -UPB_API void upb_Map_SetEntryValue(upb_Map* map, size_t iter, - upb_MessageValue val); - -// DEPRECATED iterator, slated for removal. +// Inline version upb_Message_New(), for internal use. +UPB_INLINE struct upb_Message* _upb_Message_New(const upb_MiniTable* mini_table, + upb_Arena* arena) { + size_t size = upb_msg_sizeof(mini_table); + void* mem = upb_Arena_Malloc(arena, size + sizeof(upb_Message_Internal)); + if (UPB_UNLIKELY(!mem)) return NULL; + struct upb_Message* msg = + UPB_PTR_AT(mem, sizeof(upb_Message_Internal), struct upb_Message); + memset(mem, 0, size); + return msg; +} -/* Map iteration: - * - * size_t iter = kUpb_Map_Begin; - * while (upb_MapIterator_Next(map, &iter)) { - * upb_MessageValue key = upb_MapIterator_Key(map, iter); - * upb_MessageValue val = upb_MapIterator_Value(map, iter); - * } - */ +UPB_INLINE upb_Message_Internal* upb_Message_Getinternal( + const struct upb_Message* msg) { + ptrdiff_t size = sizeof(upb_Message_Internal); + return (upb_Message_Internal*)((char*)msg - size); +} -// Advances to the next entry. Returns false if no more entries are present. -UPB_API bool upb_MapIterator_Next(const upb_Map* map, size_t* iter); +// Discards the unknown fields for this message only. +void _upb_Message_DiscardUnknown_shallow(struct upb_Message* msg); -// Returns true if the iterator still points to a valid entry, or false if the -// iterator is past the last element. It is an error to call this function with -// kUpb_Map_Begin (you must call next() at least once first). -UPB_API bool upb_MapIterator_Done(const upb_Map* map, size_t iter); +// Adds unknown data (serialized protobuf data) to the given message. +// The data is copied into the message instance. +bool UPB_PRIVATE(_upb_Message_AddUnknown)(struct upb_Message* msg, + const char* data, size_t len, + upb_Arena* arena); -// Returns the key and value for this entry of the map. -UPB_API upb_MessageValue upb_MapIterator_Key(const upb_Map* map, size_t iter); -UPB_API upb_MessageValue upb_MapIterator_Value(const upb_Map* map, size_t iter); +bool UPB_PRIVATE(_upb_Message_Realloc)(struct upb_Message* msg, size_t need, + upb_Arena* arena); #ifdef __cplusplus } /* extern "C" */ #endif -#endif /* UPB_MESSAGE_MAP_H_ */ +#endif /* UPB_MESSAGE_INTERNAL_MESSAGE_H_ */ -// Must be last. +#ifndef UPB_MINI_TABLE_INTERNAL_TAGGED_PTR_H_ +#define UPB_MINI_TABLE_INTERNAL_TAGGED_PTR_H_ -struct upb_Map { - // Size of key and val, based on the map type. - // Strings are represented as '0' because they must be handled specially. - char key_size; - char val_size; +#include - upb_strtable table; -}; + +// Must be last. + +typedef uintptr_t upb_TaggedMessagePtr; #ifdef __cplusplus extern "C" { #endif -// Converting between internal table representation and user values. -// -// _upb_map_tokey() and _upb_map_fromkey() are inverses. -// _upb_map_tovalue() and _upb_map_fromvalue() are inverses. -// -// These functions account for the fact that strings are treated differently -// from other types when stored in a map. - -UPB_INLINE upb_StringView _upb_map_tokey(const void* key, size_t size) { - if (size == UPB_MAPTYPE_STRING) { - return *(upb_StringView*)key; - } else { - return upb_StringView_FromDataAndSize((const char*)key, size); - } +// Internal-only because empty messages cannot be created by the user. +UPB_INLINE upb_TaggedMessagePtr +UPB_PRIVATE(_upb_TaggedMessagePtr_Pack)(struct upb_Message* ptr, bool empty) { + UPB_ASSERT(((uintptr_t)ptr & 1) == 0); + return (uintptr_t)ptr | (empty ? 1 : 0); } -UPB_INLINE void _upb_map_fromkey(upb_StringView key, void* out, size_t size) { - if (size == UPB_MAPTYPE_STRING) { - memcpy(out, &key, sizeof(key)); - } else { - memcpy(out, key.data, size); - } +UPB_INLINE bool UPB_PRIVATE(_upb_TaggedMessagePtr_IsEmpty)( + upb_TaggedMessagePtr ptr) { + return ptr & 1; } -UPB_INLINE bool _upb_map_tovalue(const void* val, size_t size, - upb_value* msgval, upb_Arena* a) { - if (size == UPB_MAPTYPE_STRING) { - upb_StringView* strp = (upb_StringView*)upb_Arena_Malloc(a, sizeof(*strp)); - if (!strp) return false; - *strp = *(upb_StringView*)val; - *msgval = upb_value_ptr(strp); - } else { - memcpy(msgval, val, size); - } - return true; +UPB_INLINE struct upb_Message* UPB_PRIVATE(_upb_TaggedMessagePtr_GetMessage)( + upb_TaggedMessagePtr ptr) { + return (struct upb_Message*)(ptr & ~(uintptr_t)1); } -UPB_INLINE void _upb_map_fromvalue(upb_value val, void* out, size_t size) { - if (size == UPB_MAPTYPE_STRING) { - const upb_StringView* strp = (const upb_StringView*)upb_value_getptr(val); - memcpy(out, strp, sizeof(upb_StringView)); - } else { - memcpy(out, &val, size); - } +UPB_INLINE struct upb_Message* UPB_PRIVATE( + _upb_TaggedMessagePtr_GetNonEmptyMessage)(upb_TaggedMessagePtr ptr) { + UPB_ASSERT(!UPB_PRIVATE(_upb_TaggedMessagePtr_IsEmpty)(ptr)); + return UPB_PRIVATE(_upb_TaggedMessagePtr_GetMessage)(ptr); } -UPB_INLINE void* _upb_map_next(const struct upb_Map* map, size_t* iter) { - upb_strtable_iter it; - it.t = &map->table; - it.index = *iter; - upb_strtable_next(&it); - *iter = it.index; - if (upb_strtable_done(&it)) return NULL; - return (void*)str_tabent(&it); +UPB_INLINE struct upb_Message* UPB_PRIVATE( + _upb_TaggedMessagePtr_GetEmptyMessage)(upb_TaggedMessagePtr ptr) { + UPB_ASSERT(UPB_PRIVATE(_upb_TaggedMessagePtr_IsEmpty)(ptr)); + return UPB_PRIVATE(_upb_TaggedMessagePtr_GetMessage)(ptr); } -UPB_INLINE void _upb_Map_Clear(struct upb_Map* map) { - upb_strtable_clear(&map->table); -} +#ifdef __cplusplus +} /* extern "C" */ +#endif + + +#endif /* UPB_MINI_TABLE_INTERNAL_TAGGED_PTR_H_ */ + +typedef union { + bool bool_val; + float float_val; + double double_val; + int32_t int32_val; + int64_t int64_val; + uint32_t uint32_val; + uint64_t uint64_val; + const struct upb_Array* array_val; + const struct upb_Map* map_val; + const struct upb_Message* msg_val; + upb_StringView str_val; + + // EXPERIMENTAL: A tagged upb_Message*. Users must use this instead of + // msg_val if unlinked sub-messages may possibly be in use. See the + // documentation in kUpb_DecodeOption_ExperimentalAllowUnlinked for more + // information. + upb_TaggedMessagePtr tagged_msg_val; +} upb_MessageValue; + +typedef union { + struct upb_Array* array; + struct upb_Map* map; + struct upb_Message* msg; +} upb_MutableMessageValue; + +#endif /* UPB_MESSAGE_VALUE_H_ */ + +// Must be last. + +typedef struct upb_Array upb_Array; + +#ifdef __cplusplus +extern "C" { +#endif -UPB_INLINE bool _upb_Map_Delete(struct upb_Map* map, const void* key, - size_t key_size, upb_value* val) { - upb_StringView k = _upb_map_tokey(key, key_size); - return upb_strtable_remove2(&map->table, k.data, k.size, val); -} +// Creates a new array on the given arena that holds elements of this type. +UPB_API upb_Array* upb_Array_New(upb_Arena* a, upb_CType type); -UPB_INLINE bool _upb_Map_Get(const struct upb_Map* map, const void* key, - size_t key_size, void* val, size_t val_size) { - upb_value tabval; - upb_StringView k = _upb_map_tokey(key, key_size); - bool ret = upb_strtable_lookup2(&map->table, k.data, k.size, &tabval); - if (ret && val) { - _upb_map_fromvalue(tabval, val, val_size); - } - return ret; -} +// Returns the number of elements in the array. +UPB_API size_t upb_Array_Size(const upb_Array* arr); -UPB_INLINE upb_MapInsertStatus _upb_Map_Insert(struct upb_Map* map, - const void* key, size_t key_size, - void* val, size_t val_size, - upb_Arena* a) { - upb_StringView strkey = _upb_map_tokey(key, key_size); - upb_value tabval = {0}; - if (!_upb_map_tovalue(val, val_size, &tabval, a)) { - return kUpb_MapInsertStatus_OutOfMemory; - } +// Returns the given element, which must be within the array's current size. +UPB_API upb_MessageValue upb_Array_Get(const upb_Array* arr, size_t i); - // TODO: add overwrite operation to minimize number of lookups. - bool removed = - upb_strtable_remove2(&map->table, strkey.data, strkey.size, NULL); - if (!upb_strtable_insert(&map->table, strkey.data, strkey.size, tabval, a)) { - return kUpb_MapInsertStatus_OutOfMemory; - } - return removed ? kUpb_MapInsertStatus_Replaced - : kUpb_MapInsertStatus_Inserted; -} +// Sets the given element, which must be within the array's current size. +UPB_API void upb_Array_Set(upb_Array* arr, size_t i, upb_MessageValue val); -UPB_INLINE size_t _upb_Map_Size(const struct upb_Map* map) { - return map->table.t.count; -} +// Appends an element to the array. Returns false on allocation failure. +UPB_API bool upb_Array_Append(upb_Array* array, upb_MessageValue val, + upb_Arena* arena); -// Strings/bytes are special-cased in maps. -extern char _upb_Map_CTypeSizeTable[12]; +// Moves elements within the array using memmove(). +// Like memmove(), the source and destination elements may be overlapping. +UPB_API void upb_Array_Move(upb_Array* array, size_t dst_idx, size_t src_idx, + size_t count); -UPB_INLINE size_t _upb_Map_CTypeSize(upb_CType ctype) { - return _upb_Map_CTypeSizeTable[ctype]; -} +// Inserts one or more empty elements into the array. +// Existing elements are shifted right. +// The new elements have undefined state and must be set with `upb_Array_Set()`. +// REQUIRES: `i <= upb_Array_Size(arr)` +UPB_API bool upb_Array_Insert(upb_Array* array, size_t i, size_t count, + upb_Arena* arena); -// Creates a new map on the given arena with this key/value type. -struct upb_Map* _upb_Map_New(upb_Arena* a, size_t key_size, size_t value_size); +// Deletes one or more elements from the array. +// Existing elements are shifted left. +// REQUIRES: `i + count <= upb_Array_Size(arr)` +UPB_API void upb_Array_Delete(upb_Array* array, size_t i, size_t count); + +// Changes the size of a vector. New elements are initialized to NULL/0. +// Returns false on allocation failure. +UPB_API bool upb_Array_Resize(upb_Array* array, size_t size, upb_Arena* arena); + +// Returns pointer to array data. +UPB_API const void* upb_Array_DataPtr(const upb_Array* arr); + +// Returns mutable pointer to array data. +UPB_API void* upb_Array_MutableDataPtr(upb_Array* arr); #ifdef __cplusplus } /* extern "C" */ #endif -#endif /* UPB_MESSAGE_INTERNAL_MAP_H_ */ +#endif /* UPB_MESSAGE_ARRAY_H_ */ + +#ifndef UPB_MESSAGE_INTERNAL_ACCESSORS_H_ +#define UPB_MESSAGE_INTERNAL_ACCESSORS_H_ + +#include +#include +#include + // Must be last. @@ -2528,7 +2517,7 @@ extern "C" { // Hasbit access /////////////////////////////////////////////////////////////// UPB_INLINE bool UPB_PRIVATE(_upb_Message_GetHasbit)( - const upb_Message* msg, const upb_MiniTableField* f) { + const struct upb_Message* msg, const upb_MiniTableField* f) { const size_t offset = UPB_PRIVATE(_upb_MiniTableField_HasbitOffset)(f); const char mask = UPB_PRIVATE(_upb_MiniTableField_HasbitMask)(f); @@ -2536,7 +2525,7 @@ UPB_INLINE bool UPB_PRIVATE(_upb_Message_GetHasbit)( } UPB_INLINE void UPB_PRIVATE(_upb_Message_SetHasbit)( - const upb_Message* msg, const upb_MiniTableField* f) { + const struct upb_Message* msg, const upb_MiniTableField* f) { const size_t offset = UPB_PRIVATE(_upb_MiniTableField_HasbitOffset)(f); const char mask = UPB_PRIVATE(_upb_MiniTableField_HasbitMask)(f); @@ -2544,7 +2533,7 @@ UPB_INLINE void UPB_PRIVATE(_upb_Message_SetHasbit)( } UPB_INLINE void UPB_PRIVATE(_upb_Message_ClearHasbit)( - const upb_Message* msg, const upb_MiniTableField* f) { + const struct upb_Message* msg, const upb_MiniTableField* f) { const size_t offset = UPB_PRIVATE(_upb_MiniTableField_HasbitOffset)(f); const char mask = UPB_PRIVATE(_upb_MiniTableField_HasbitMask)(f); @@ -2554,18 +2543,18 @@ UPB_INLINE void UPB_PRIVATE(_upb_Message_ClearHasbit)( // Oneof case access /////////////////////////////////////////////////////////// UPB_INLINE uint32_t* UPB_PRIVATE(_upb_Message_OneofCasePtr)( - upb_Message* msg, const upb_MiniTableField* f) { + struct upb_Message* msg, const upb_MiniTableField* f) { return UPB_PTR_AT(msg, UPB_PRIVATE(_upb_MiniTableField_OneofOffset)(f), uint32_t); } UPB_INLINE uint32_t UPB_PRIVATE(_upb_Message_GetOneofCase)( - const upb_Message* msg, const upb_MiniTableField* f) { - return *UPB_PRIVATE(_upb_Message_OneofCasePtr)((upb_Message*)msg, f); + const struct upb_Message* msg, const upb_MiniTableField* f) { + return *UPB_PRIVATE(_upb_Message_OneofCasePtr)((struct upb_Message*)msg, f); } UPB_INLINE void UPB_PRIVATE(_upb_Message_SetOneofCase)( - upb_Message* msg, const upb_MiniTableField* f) { + struct upb_Message* msg, const upb_MiniTableField* f) { *UPB_PRIVATE(_upb_Message_OneofCasePtr)(msg, f) = upb_MiniTableField_Number(f); } @@ -2574,18 +2563,18 @@ UPB_INLINE void UPB_PRIVATE(_upb_Message_SetOneofCase)( // LINT.ThenChange(GoogleInternalName2) -UPB_INLINE void* _upb_MiniTableField_GetPtr(upb_Message* msg, +UPB_INLINE void* _upb_MiniTableField_GetPtr(struct upb_Message* msg, const upb_MiniTableField* field) { return (char*)msg + field->UPB_ONLYBITS(offset); } UPB_INLINE const void* _upb_MiniTableField_GetConstPtr( - const upb_Message* msg, const upb_MiniTableField* field) { + const struct upb_Message* msg, const upb_MiniTableField* field) { return (char*)msg + field->UPB_ONLYBITS(offset); } UPB_INLINE void UPB_PRIVATE(_upb_Message_SetPresence)( - upb_Message* msg, const upb_MiniTableField* field) { + struct upb_Message* msg, const upb_MiniTableField* field) { if (field->presence > 0) { UPB_PRIVATE(_upb_Message_SetHasbit)(msg, field); } else if (upb_MiniTableField_IsInOneof(field)) { @@ -2671,13 +2660,13 @@ UPB_INLINE void UPB_PRIVATE(_upb_MiniTableField_DataCopy)( // returned bool value may be ignored since it will always succeed. UPB_INLINE bool _upb_Message_HasExtensionField( - const upb_Message* msg, const upb_MiniTableExtension* ext) { + const struct upb_Message* msg, const upb_MiniTableExtension* ext) { UPB_ASSERT(upb_MiniTableField_HasPresence(&ext->UPB_PRIVATE(field))); return _upb_Message_Getext(msg, ext) != NULL; } UPB_INLINE bool _upb_Message_HasNonExtensionField( - const upb_Message* msg, const upb_MiniTableField* field) { + const struct upb_Message* msg, const upb_MiniTableField* field) { UPB_ASSERT(upb_MiniTableField_HasPresence(field)); UPB_ASSUME(!upb_MiniTableField_IsExtension(field)); if (upb_MiniTableField_IsInOneof(field)) { @@ -2689,7 +2678,7 @@ UPB_INLINE bool _upb_Message_HasNonExtensionField( } static UPB_FORCEINLINE void _upb_Message_GetNonExtensionField( - const upb_Message* msg, const upb_MiniTableField* field, + const struct upb_Message* msg, const upb_MiniTableField* field, const void* default_val, void* val) { UPB_ASSUME(!upb_MiniTableField_IsExtension(field)); if ((upb_MiniTableField_IsInOneof(field) || @@ -2703,7 +2692,7 @@ static UPB_FORCEINLINE void _upb_Message_GetNonExtensionField( } UPB_INLINE void _upb_Message_GetExtensionField( - const upb_Message* msg, const upb_MiniTableExtension* mt_ext, + const struct upb_Message* msg, const upb_MiniTableExtension* mt_ext, const void* default_val, void* val) { const struct upb_Extension* ext = _upb_Message_Getext(msg, mt_ext); const upb_MiniTableField* f = &mt_ext->UPB_PRIVATE(field); @@ -2716,240 +2705,279 @@ UPB_INLINE void _upb_Message_GetExtensionField( } } -// Gets a mutable Array, Map or Message field. -// NOTE: For repeated/map fields, the resulting upb_Array*/upb_Map* can -// be NULL if a upb_Array/upb_Map has not been allocated yet. Array/map -// fields do not have presence, so this is semantically identical to a -// pointer to an empty array/map, and must be treated the same for all -// semantic purposes. -// -// For message fields, the pointer is guaranteed to be NULL iff the field -// is unset (as message fields do have presence). -UPB_INLINE upb_MutableMessageValue _upb_Message_GetMutableField( - const upb_Message* msg, const upb_MiniTableField* field) { - UPB_ASSUME(!upb_MiniTableField_IsScalar(field) || - upb_MiniTableField_IsSubMessage(field)); +UPB_INLINE void _upb_Message_SetNonExtensionField( + struct upb_Message* msg, const upb_MiniTableField* field, const void* val) { + UPB_ASSUME(!upb_MiniTableField_IsExtension(field)); + UPB_PRIVATE(_upb_Message_SetPresence)(msg, field); + UPB_PRIVATE(_upb_MiniTableField_DataCopy) + (field, _upb_MiniTableField_GetPtr(msg, field), val); +} - upb_MutableMessageValue default_val; - default_val.msg = NULL; +UPB_INLINE bool _upb_Message_SetExtensionField( + struct upb_Message* msg, const upb_MiniTableExtension* mt_ext, + const void* val, upb_Arena* a) { + UPB_ASSERT(a); + struct upb_Extension* ext = _upb_Message_GetOrCreateExtension(msg, mt_ext, a); + if (!ext) return false; + UPB_PRIVATE(_upb_MiniTableField_DataCopy) + (&mt_ext->UPB_PRIVATE(field), &ext->data, val); + return true; +} - upb_MutableMessageValue ret; - if (upb_MiniTableField_IsExtension(field)) { - _upb_Message_GetExtensionField(msg, (upb_MiniTableExtension*)field, - &default_val, &ret); - } else { - _upb_Message_GetNonExtensionField(msg, field, &default_val, &ret); +UPB_INLINE void _upb_Message_ClearExtensionField( + struct upb_Message* msg, const upb_MiniTableExtension* ext_l) { + upb_Message_Internal* in = upb_Message_Getinternal(msg); + if (!in->internal) return; + const struct upb_Extension* base = + UPB_PTR_AT(in->internal, in->internal->ext_begin, struct upb_Extension); + struct upb_Extension* ext = + (struct upb_Extension*)_upb_Message_Getext(msg, ext_l); + if (ext) { + *ext = *base; + in->internal->ext_begin += sizeof(struct upb_Extension); } - return ret; } -UPB_INLINE void _upb_Message_SetNonExtensionField( - upb_Message* msg, const upb_MiniTableField* field, const void* val) { - UPB_ASSUME(!upb_MiniTableField_IsExtension(field)); - UPB_PRIVATE(_upb_Message_SetPresence)(msg, field); +UPB_INLINE void _upb_Message_ClearNonExtensionField( + struct upb_Message* msg, const upb_MiniTableField* field) { + if (field->presence > 0) { + UPB_PRIVATE(_upb_Message_ClearHasbit)(msg, field); + } else if (upb_MiniTableField_IsInOneof(field)) { + uint32_t* ptr = UPB_PRIVATE(_upb_Message_OneofCasePtr)(msg, field); + if (*ptr != upb_MiniTableField_Number(field)) return; + *ptr = 0; + } + const char zeros[16] = {0}; UPB_PRIVATE(_upb_MiniTableField_DataCopy) - (field, _upb_MiniTableField_GetPtr(msg, field), val); + (field, _upb_MiniTableField_GetPtr(msg, field), zeros); +} + +UPB_INLINE void _upb_Message_AssertMapIsUntagged( + const struct upb_Message* msg, const upb_MiniTableField* field) { + UPB_UNUSED(msg); + UPB_PRIVATE(_upb_MiniTableField_CheckIsMap)(field); +#ifndef NDEBUG + upb_TaggedMessagePtr default_val = 0; + upb_TaggedMessagePtr tagged; + _upb_Message_GetNonExtensionField(msg, field, &default_val, &tagged); + UPB_ASSERT(!UPB_PRIVATE(_upb_TaggedMessagePtr_IsEmpty)(tagged)); +#endif +} + +UPB_INLINE struct upb_Map* _upb_Message_GetOrCreateMutableMap( + struct upb_Message* msg, const upb_MiniTableField* field, size_t key_size, + size_t val_size, upb_Arena* arena) { + UPB_PRIVATE(_upb_MiniTableField_CheckIsMap)(field); + _upb_Message_AssertMapIsUntagged(msg, field); + struct upb_Map* map = NULL; + struct upb_Map* default_map_value = NULL; + _upb_Message_GetNonExtensionField(msg, field, &default_map_value, &map); + if (!map) { + map = _upb_Map_New(arena, key_size, val_size); + // Check again due to: https://godbolt.org/z/7WfaoKG1r + UPB_PRIVATE(_upb_MiniTableField_CheckIsMap)(field); + _upb_Message_SetNonExtensionField(msg, field, &map); + } + return map; +} + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#if defined(__GNUC__) && !defined(__clang__) +#pragma GCC diagnostic pop +#endif + + +#endif // UPB_MESSAGE_INTERNAL_ACCESSORS_H_ + +#ifndef UPB_MESSAGE_MAP_H_ +#define UPB_MESSAGE_MAP_H_ + +#include + + +// Must be last. + +typedef struct upb_Map upb_Map; + +#ifdef __cplusplus +extern "C" { +#endif + +// Creates a new map on the given arena with the given key/value size. +UPB_API upb_Map* upb_Map_New(upb_Arena* a, upb_CType key_type, + upb_CType value_type); + +// Returns the number of entries in the map. +UPB_API size_t upb_Map_Size(const upb_Map* map); + +// Stores a value for the given key into |*val| (or the zero value if the key is +// not present). Returns whether the key was present. The |val| pointer may be +// NULL, in which case the function tests whether the given key is present. +UPB_API bool upb_Map_Get(const upb_Map* map, upb_MessageValue key, + upb_MessageValue* val); + +// Removes all entries in the map. +UPB_API void upb_Map_Clear(upb_Map* map); + +// Sets the given key to the given value, returning whether the key was inserted +// or replaced. If the key was inserted, then any existing iterators will be +// invalidated. +UPB_API upb_MapInsertStatus upb_Map_Insert(upb_Map* map, upb_MessageValue key, + upb_MessageValue val, + upb_Arena* arena); + +// Sets the given key to the given value. Returns false if memory allocation +// failed. If the key is newly inserted, then any existing iterators will be +// invalidated. +UPB_API_INLINE bool upb_Map_Set(upb_Map* map, upb_MessageValue key, + upb_MessageValue val, upb_Arena* arena) { + return upb_Map_Insert(map, key, val, arena) != + kUpb_MapInsertStatus_OutOfMemory; +} + +// Deletes this key from the table. Returns true if the key was present. +// If present and |val| is non-NULL, stores the deleted value. +UPB_API bool upb_Map_Delete(upb_Map* map, upb_MessageValue key, + upb_MessageValue* val); + +// (DEPRECATED and going away soon. Do not use.) +UPB_INLINE bool upb_Map_Delete2(upb_Map* map, upb_MessageValue key, + upb_MessageValue* val) { + return upb_Map_Delete(map, key, val); } -UPB_INLINE bool _upb_Message_SetExtensionField( - upb_Message* msg, const upb_MiniTableExtension* mt_ext, const void* val, - upb_Arena* a) { - UPB_ASSERT(a); - struct upb_Extension* ext = _upb_Message_GetOrCreateExtension(msg, mt_ext, a); - if (!ext) return false; - UPB_PRIVATE(_upb_MiniTableField_DataCopy) - (&mt_ext->UPB_PRIVATE(field), &ext->data, val); - return true; -} +// Map iteration: +// +// size_t iter = kUpb_Map_Begin; +// upb_MessageValue key, val; +// while (upb_Map_Next(map, &key, &val, &iter)) { +// ... +// } + +#define kUpb_Map_Begin ((size_t)-1) + +// Advances to the next entry. Returns false if no more entries are present. +// Otherwise returns true and populates both *key and *value. +UPB_API bool upb_Map_Next(const upb_Map* map, upb_MessageValue* key, + upb_MessageValue* val, size_t* iter); + +// Sets the value for the entry pointed to by iter. +// WARNING: this does not currently work for string values! +UPB_API void upb_Map_SetEntryValue(upb_Map* map, size_t iter, + upb_MessageValue val); + +// DEPRECATED iterator, slated for removal. -UPB_INLINE void _upb_Message_ClearExtensionField( - upb_Message* msg, const upb_MiniTableExtension* ext_l) { - upb_Message_Internal* in = upb_Message_Getinternal(msg); - if (!in->internal) return; - const struct upb_Extension* base = - UPB_PTR_AT(in->internal, in->internal->ext_begin, struct upb_Extension); - struct upb_Extension* ext = - (struct upb_Extension*)_upb_Message_Getext(msg, ext_l); - if (ext) { - *ext = *base; - in->internal->ext_begin += sizeof(struct upb_Extension); - } -} +/* Map iteration: + * + * size_t iter = kUpb_Map_Begin; + * while (upb_MapIterator_Next(map, &iter)) { + * upb_MessageValue key = upb_MapIterator_Key(map, iter); + * upb_MessageValue val = upb_MapIterator_Value(map, iter); + * } + */ -UPB_INLINE void _upb_Message_ClearNonExtensionField( - upb_Message* msg, const upb_MiniTableField* field) { - if (field->presence > 0) { - UPB_PRIVATE(_upb_Message_ClearHasbit)(msg, field); - } else if (upb_MiniTableField_IsInOneof(field)) { - uint32_t* ptr = UPB_PRIVATE(_upb_Message_OneofCasePtr)(msg, field); - if (*ptr != upb_MiniTableField_Number(field)) return; - *ptr = 0; - } - const char zeros[16] = {0}; - UPB_PRIVATE(_upb_MiniTableField_DataCopy) - (field, _upb_MiniTableField_GetPtr(msg, field), zeros); -} +// Advances to the next entry. Returns false if no more entries are present. +UPB_API bool upb_MapIterator_Next(const upb_Map* map, size_t* iter); -UPB_INLINE void _upb_Message_AssertMapIsUntagged( - const upb_Message* msg, const upb_MiniTableField* field) { - UPB_UNUSED(msg); - UPB_PRIVATE(_upb_MiniTableField_CheckIsMap)(field); -#ifndef NDEBUG - upb_TaggedMessagePtr default_val = 0; - upb_TaggedMessagePtr tagged; - _upb_Message_GetNonExtensionField(msg, field, &default_val, &tagged); - UPB_ASSERT(!upb_TaggedMessagePtr_IsEmpty(tagged)); -#endif -} +// Returns true if the iterator still points to a valid entry, or false if the +// iterator is past the last element. It is an error to call this function with +// kUpb_Map_Begin (you must call next() at least once first). +UPB_API bool upb_MapIterator_Done(const upb_Map* map, size_t iter); -UPB_INLINE struct upb_Map* _upb_Message_GetOrCreateMutableMap( - upb_Message* msg, const upb_MiniTableField* field, size_t key_size, - size_t val_size, upb_Arena* arena) { - UPB_PRIVATE(_upb_MiniTableField_CheckIsMap)(field); - _upb_Message_AssertMapIsUntagged(msg, field); - struct upb_Map* map = NULL; - struct upb_Map* default_map_value = NULL; - _upb_Message_GetNonExtensionField(msg, field, &default_map_value, &map); - if (!map) { - map = _upb_Map_New(arena, key_size, val_size); - // Check again due to: https://godbolt.org/z/7WfaoKG1r - UPB_PRIVATE(_upb_MiniTableField_CheckIsMap)(field); - _upb_Message_SetNonExtensionField(msg, field, &map); - } - return map; -} +// Returns the key and value for this entry of the map. +UPB_API upb_MessageValue upb_MapIterator_Key(const upb_Map* map, size_t iter); +UPB_API upb_MessageValue upb_MapIterator_Value(const upb_Map* map, size_t iter); #ifdef __cplusplus } /* extern "C" */ #endif -#if defined(__GNUC__) && !defined(__clang__) -#pragma GCC diagnostic pop -#endif +#endif /* UPB_MESSAGE_MAP_H_ */ -#endif // UPB_MESSAGE_INTERNAL_ACCESSORS_H_ +#ifndef UPB_MINI_TABLE_TAGGED_PTR_H_ +#define UPB_MINI_TABLE_TAGGED_PTR_H_ -#ifndef UPB_MESSAGE_INTERNAL_ARRAY_H_ -#define UPB_MESSAGE_INTERNAL_ARRAY_H_ +#include -#include + +// Public APIs for message operations that do not depend on the schema. +// +// MiniTable-based accessors live in accessors.h. + +#ifndef UPB_MESSAGE_MESSAGE_H_ +#define UPB_MESSAGE_MESSAGE_H_ + +#include // Must be last. -#define _UPB_ARRAY_MASK_IMM 0x4 // Frozen/immutable bit. -#define _UPB_ARRAY_MASK_LG2 0x3 // Encoded elem size. -#define _UPB_ARRAY_MASK_ALL (_UPB_ARRAY_MASK_IMM | _UPB_ARRAY_MASK_LG2) +typedef struct upb_Extension upb_Extension; +typedef struct upb_Message upb_Message; #ifdef __cplusplus extern "C" { #endif -// LINT.IfChange(struct_definition) -// Our internal representation for repeated fields. -struct upb_Array { - // This is a tagged pointer. Bits #0 and #1 encode the elem size as follows: - // 0 maps to elem size 1 - // 1 maps to elem size 4 - // 2 maps to elem size 8 - // 3 maps to elem size 16 - // - // Bit #2 contains the frozen/immutable flag (currently unimplemented). - uintptr_t data; +// Creates a new message with the given mini_table on the given arena. +UPB_API upb_Message* upb_Message_New(const upb_MiniTable* m, upb_Arena* arena); - size_t UPB_ONLYBITS(size); // The number of elements in the array. - size_t UPB_PRIVATE(capacity); // Allocated storage. Measured in elements. -}; +// Returns a reference to the message's unknown data. +const char* upb_Message_GetUnknown(const upb_Message* msg, size_t* len); -UPB_INLINE void UPB_PRIVATE(_upb_Array_SetTaggedPtr)(struct upb_Array* array, - void* data, size_t lg2) { - UPB_ASSERT(lg2 != 1); - UPB_ASSERT(lg2 <= 4); - const size_t bits = lg2 - (lg2 != 0); - array->data = (uintptr_t)data | bits; -} +// Removes partial unknown data from message. +void upb_Message_DeleteUnknown(upb_Message* msg, const char* data, size_t len); -UPB_INLINE size_t -UPB_PRIVATE(_upb_Array_ElemSizeLg2)(const struct upb_Array* array) { - const size_t bits = array->data & _UPB_ARRAY_MASK_LG2; - const size_t lg2 = bits + (bits != 0); - return lg2; -} +// Returns the number of extensions present in this message. +size_t upb_Message_ExtensionCount(const upb_Message* msg); -UPB_INLINE const void* _upb_array_constptr(const struct upb_Array* array) { - UPB_PRIVATE(_upb_Array_ElemSizeLg2)(array); // Check assertions. - return (void*)(array->data & ~(uintptr_t)_UPB_ARRAY_MASK_ALL); -} +#ifdef __cplusplus +} /* extern "C" */ +#endif -UPB_INLINE void* _upb_array_ptr(struct upb_Array* array) { - return (void*)_upb_array_constptr(array); -} -UPB_INLINE struct upb_Array* UPB_PRIVATE(_upb_Array_New)(upb_Arena* arena, - size_t init_capacity, - int elem_size_lg2) { - UPB_ASSERT(elem_size_lg2 != 1); - UPB_ASSERT(elem_size_lg2 <= 4); - const size_t array_size = - UPB_ALIGN_UP(sizeof(struct upb_Array), UPB_MALLOC_ALIGN); - const size_t bytes = array_size + (init_capacity << elem_size_lg2); - struct upb_Array* array = (struct upb_Array*)upb_Arena_Malloc(arena, bytes); - if (!array) return NULL; - UPB_PRIVATE(_upb_Array_SetTaggedPtr) - (array, UPB_PTR_AT(array, array_size, void), elem_size_lg2); - array->UPB_ONLYBITS(size) = 0; - array->UPB_PRIVATE(capacity) = init_capacity; - return array; -} +#endif /* UPB_MESSAGE_MESSAGE_H_ */ -// Resizes the capacity of the array to be at least min_size. -bool UPB_PRIVATE(_upb_Array_Realloc)(struct upb_Array* array, size_t min_size, - upb_Arena* arena); +// Must be last. -UPB_INLINE bool UPB_PRIVATE(_upb_Array_Reserve)(struct upb_Array* array, - size_t size, upb_Arena* arena) { - if (array->UPB_PRIVATE(capacity) < size) - return UPB_PRIVATE(_upb_Array_Realloc)(array, size, arena); - return true; -} +// 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 +// that field's true message type. This forms the basis of what we call +// "dynamic tree shaking." +// +// See the documentation for kUpb_DecodeOption_ExperimentalAllowUnlinked for +// more information. -// Resize without initializing new elements. -UPB_INLINE bool _upb_Array_ResizeUninitialized(struct upb_Array* array, - size_t size, upb_Arena* arena) { - UPB_ASSERT(size <= array->UPB_ONLYBITS(size) || - arena); // Allow NULL arena when shrinking. - if (!UPB_PRIVATE(_upb_Array_Reserve)(array, size, arena)) return false; - array->UPB_ONLYBITS(size) = size; - return true; -} +typedef uintptr_t upb_TaggedMessagePtr; -// This function is intended for situations where elem_size is compile-time -// constant or a known expression of the form (1 << lg2), so that the expression -// i*elem_size does not result in an actual multiplication. -UPB_INLINE void UPB_PRIVATE(_upb_Array_Set)(struct upb_Array* array, size_t i, - const void* data, - size_t elem_size) { - UPB_ASSERT(i < array->UPB_ONLYBITS(size)); - UPB_ASSERT(elem_size == 1U << UPB_PRIVATE(_upb_Array_ElemSizeLg2)(array)); - char* arr_data = (char*)_upb_array_ptr(array); - memcpy(arr_data + (i * elem_size), data, elem_size); +#ifdef __cplusplus +extern "C" { +#endif + +// Users who enable unlinked sub-messages must use this to test whether a +// message is empty before accessing it. If a message is empty, it must be +// first promoted using the interfaces in message/promote.h. +UPB_INLINE bool upb_TaggedMessagePtr_IsEmpty(upb_TaggedMessagePtr ptr) { + return UPB_PRIVATE(_upb_TaggedMessagePtr_IsEmpty)(ptr); } -// LINT.ThenChange( -// GoogleInternalName1, -//) +UPB_INLINE upb_Message* upb_TaggedMessagePtr_GetNonEmptyMessage( + upb_TaggedMessagePtr ptr) { + return UPB_PRIVATE(_upb_TaggedMessagePtr_GetNonEmptyMessage)(ptr); +} #ifdef __cplusplus } /* extern "C" */ #endif -#undef _UPB_ARRAY_MASK_IMM -#undef _UPB_ARRAY_MASK_LG2 -#undef _UPB_ARRAY_MASK_ALL - -#endif /* UPB_MESSAGE_INTERNAL_ARRAY_H_ */ +#endif /* UPB_MINI_TABLE_TAGGED_PTR_H_ */ #ifndef UPB_MINI_TABLE_SUB_H_ #define UPB_MINI_TABLE_SUB_H_ @@ -3318,7 +3346,8 @@ UPB_API_INLINE void upb_Message_SetMessage(upb_Message* msg, const upb_MiniTableField* field, upb_Message* sub_message) { _upb_Message_SetTaggedMessagePtr( - msg, mini_table, field, _upb_TaggedMessagePtr_Pack(sub_message, false)); + msg, mini_table, field, + UPB_PRIVATE(_upb_TaggedMessagePtr_Pack)(sub_message, false)); } UPB_API_INLINE upb_Message* upb_Message_GetOrCreateMutableMessage( @@ -3471,43 +3500,6 @@ UPB_INLINE void _upb_msg_map_set_value(void* msg, const void* val, #endif /* UPB_MESSAGE_MAP_GENCODE_UTIL_H_ */ -// Public APIs for message operations that do not depend on the schema. -// -// MiniTable-based accessors live in accessors.h. - -#ifndef UPB_MESSAGE_MESSAGE_H_ -#define UPB_MESSAGE_MESSAGE_H_ - -#include - - -// Must be last. - -typedef struct upb_Extension upb_Extension; - -#ifdef __cplusplus -extern "C" { -#endif - -// Creates a new message with the given mini_table on the given arena. -UPB_API upb_Message* upb_Message_New(const upb_MiniTable* m, upb_Arena* arena); - -// Returns a reference to the message's unknown data. -const char* upb_Message_GetUnknown(const upb_Message* msg, size_t* len); - -// Removes partial unknown data from message. -void upb_Message_DeleteUnknown(upb_Message* msg, const char* data, size_t len); - -// Returns the number of extensions present in this message. -size_t upb_Message_ExtensionCount(const upb_Message* msg); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - - -#endif /* UPB_MESSAGE_MESSAGE_H_ */ - #ifndef UPB_MINI_TABLE_DECODE_H_ #define UPB_MINI_TABLE_DECODE_H_ @@ -12411,7 +12403,8 @@ UPB_INLINE void _upb_mapsorter_destroy(_upb_mapsorter* s) { if (s->entries) upb_gfree(s->entries); } -UPB_INLINE bool _upb_sortedmap_next(_upb_mapsorter* s, const upb_Map* map, +UPB_INLINE bool _upb_sortedmap_next(_upb_mapsorter* s, + const struct upb_Map* map, _upb_sortedmap* sorted, upb_MapEntry* ent) { if (sorted->pos == sorted->end) return false; const upb_tabent* tabent = (const upb_tabent*)s->entries[sorted->pos++]; @@ -12436,7 +12429,7 @@ UPB_INLINE void _upb_mapsorter_popmap(_upb_mapsorter* s, } bool _upb_mapsorter_pushmap(_upb_mapsorter* s, upb_FieldType key_type, - const upb_Map* map, _upb_sortedmap* sorted); + const struct upb_Map* map, _upb_sortedmap* sorted); bool _upb_mapsorter_pushexts(_upb_mapsorter* s, const struct upb_Extension* exts, size_t count, diff --git a/upb/cmake/CMakeLists.txt b/upb/cmake/CMakeLists.txt index bdab6883d9289..308bc33600332 100644 --- a/upb/cmake/CMakeLists.txt +++ b/upb/cmake/CMakeLists.txt @@ -94,7 +94,8 @@ target_link_libraries(generated_code_support__only_for_generated_code_do_not_use message_accessors mini_descriptor mini_table - wire) + wire + /upb/message:internal) add_library(generated_cpp_support__only_for_generated_code_do_not_use__i_give_permission_to_break_me INTERFACE From f1b8f477d71a48e345aef0ae731107ab9c5931f2 Mon Sep 17 00:00:00 2001 From: Eric Salo Date: Sat, 30 Dec 2023 15:04:17 -0800 Subject: [PATCH 139/255] upb: factor out message internal data pointers PiperOrigin-RevId: 594654099 --- upb/message/internal/accessors.h | 8 ++--- upb/message/internal/extension.c | 21 ++++++------- upb/message/internal/message.c | 51 +++++++++++++++++--------------- upb/message/internal/message.h | 5 ++++ upb/message/message.c | 37 +++++++++++++---------- 5 files changed, 66 insertions(+), 56 deletions(-) diff --git a/upb/message/internal/accessors.h b/upb/message/internal/accessors.h index 2c585cd3bbe09..5a84b0259adc5 100644 --- a/upb/message/internal/accessors.h +++ b/upb/message/internal/accessors.h @@ -260,15 +260,15 @@ UPB_INLINE bool _upb_Message_SetExtensionField( UPB_INLINE void _upb_Message_ClearExtensionField( struct upb_Message* msg, const upb_MiniTableExtension* ext_l) { - upb_Message_Internal* in = upb_Message_Getinternal(msg); - if (!in->internal) return; + upb_Message_InternalData* in = upb_Message_GetInternalData(msg); + if (!in) return; const struct upb_Extension* base = - UPB_PTR_AT(in->internal, in->internal->ext_begin, struct upb_Extension); + UPB_PTR_AT(in, in->ext_begin, struct upb_Extension); struct upb_Extension* ext = (struct upb_Extension*)_upb_Message_Getext(msg, ext_l); if (ext) { *ext = *base; - in->internal->ext_begin += sizeof(struct upb_Extension); + in->ext_begin += sizeof(struct upb_Extension); } } diff --git a/upb/message/internal/extension.c b/upb/message/internal/extension.c index bc180f47c8fce..c2920b90d9bd7 100644 --- a/upb/message/internal/extension.c +++ b/upb/message/internal/extension.c @@ -36,11 +36,10 @@ const struct upb_Extension* _upb_Message_Getext( const struct upb_Extension* UPB_PRIVATE(_upb_Message_Getexts)( const struct upb_Message* msg, size_t* count) { - const upb_Message_Internal* in = upb_Message_Getinternal(msg); - if (in->internal) { - *count = (in->internal->size - in->internal->ext_begin) / - sizeof(struct upb_Extension); - return UPB_PTR_AT(in->internal, in->internal->ext_begin, void); + upb_Message_InternalData* in = upb_Message_GetInternalData(msg); + if (in) { + *count = (in->size - in->ext_begin) / sizeof(struct upb_Extension); + return UPB_PTR_AT(in, in->ext_begin, void); } else { *count = 0; return NULL; @@ -48,17 +47,15 @@ const struct upb_Extension* UPB_PRIVATE(_upb_Message_Getexts)( } struct upb_Extension* _upb_Message_GetOrCreateExtension( - struct upb_Message* msg, const upb_MiniTableExtension* e, - upb_Arena* arena) { + struct upb_Message* msg, const upb_MiniTableExtension* e, upb_Arena* a) { struct upb_Extension* ext = (struct upb_Extension*)_upb_Message_Getext(msg, e); if (ext) return ext; - if (!UPB_PRIVATE(_upb_Message_Realloc)(msg, sizeof(struct upb_Extension), - arena)) + if (!UPB_PRIVATE(_upb_Message_Realloc)(msg, sizeof(struct upb_Extension), a)) return NULL; - upb_Message_Internal* in = upb_Message_Getinternal(msg); - in->internal->ext_begin -= sizeof(struct upb_Extension); - ext = UPB_PTR_AT(in->internal, in->internal->ext_begin, void); + upb_Message_InternalData* in = upb_Message_GetInternalData(msg); + in->ext_begin -= sizeof(struct upb_Extension); + ext = UPB_PTR_AT(in, in->ext_begin, void); memset(ext, 0, sizeof(struct upb_Extension)); ext->ext = e; return ext; diff --git a/upb/message/internal/message.c b/upb/message/internal/message.c index 1287dc327e862..b83a5a138dc54 100644 --- a/upb/message/internal/message.c +++ b/upb/message/internal/message.c @@ -20,37 +20,40 @@ const float kUpb_FltInfinity = INFINITY; const double kUpb_Infinity = INFINITY; const double kUpb_NaN = NAN; -static const size_t realloc_overhead = sizeof(upb_Message_InternalData); - bool UPB_PRIVATE(_upb_Message_Realloc)(struct upb_Message* msg, size_t need, - upb_Arena* arena) { - upb_Message_Internal* in = upb_Message_Getinternal(msg); - if (!in->internal) { + upb_Arena* a) { + const size_t overhead = sizeof(upb_Message_InternalData); + + upb_Message_Internal* owner = upb_Message_Getinternal(msg); + upb_Message_InternalData* in = owner->internal; + if (!in) { // No internal data, allocate from scratch. - size_t size = UPB_MAX(128, upb_Log2CeilingSize(need + realloc_overhead)); - upb_Message_InternalData* internal = upb_Arena_Malloc(arena, size); - if (!internal) return false; - internal->size = size; - internal->unknown_end = realloc_overhead; - internal->ext_begin = size; - in->internal = internal; - } else if (in->internal->ext_begin - in->internal->unknown_end < need) { + size_t size = UPB_MAX(128, upb_Log2CeilingSize(need + overhead)); + in = upb_Arena_Malloc(a, size); + if (!in) return false; + + in->size = size; + in->unknown_end = overhead; + in->ext_begin = size; + owner->internal = in; + } else if (in->ext_begin - in->unknown_end < need) { // Internal data is too small, reallocate. - size_t new_size = upb_Log2CeilingSize(in->internal->size + need); - size_t ext_bytes = in->internal->size - in->internal->ext_begin; + size_t new_size = upb_Log2CeilingSize(in->size + need); + size_t ext_bytes = in->size - in->ext_begin; size_t new_ext_begin = new_size - ext_bytes; - upb_Message_InternalData* internal = - upb_Arena_Realloc(arena, in->internal, in->internal->size, new_size); - if (!internal) return false; + in = upb_Arena_Realloc(a, in, in->size, new_size); + if (!in) return false; + if (ext_bytes) { // Need to move extension data to the end. - char* ptr = (char*)internal; - memmove(ptr + new_ext_begin, ptr + internal->ext_begin, ext_bytes); + char* ptr = (char*)in; + memmove(ptr + new_ext_begin, ptr + in->ext_begin, ext_bytes); } - internal->ext_begin = new_ext_begin; - internal->size = new_size; - in->internal = internal; + in->ext_begin = new_ext_begin; + in->size = new_size; + owner->internal = in; } - UPB_ASSERT(in->internal->ext_begin - in->internal->unknown_end >= need); + + UPB_ASSERT(in->ext_begin - in->unknown_end >= need); return true; } diff --git a/upb/message/internal/message.h b/upb/message/internal/message.h index a7b5203eb318a..da9aa09740ec4 100644 --- a/upb/message/internal/message.h +++ b/upb/message/internal/message.h @@ -98,6 +98,11 @@ UPB_INLINE upb_Message_Internal* upb_Message_Getinternal( return (upb_Message_Internal*)((char*)msg - size); } +UPB_INLINE upb_Message_InternalData* upb_Message_GetInternalData( + const struct upb_Message* msg) { + return upb_Message_Getinternal(msg)->internal; +} + // Discards the unknown fields for this message only. void _upb_Message_DiscardUnknown_shallow(struct upb_Message* msg); diff --git a/upb/message/message.c b/upb/message/message.c index fe52731eb9c2d..d59ea4d84f47a 100644 --- a/upb/message/message.c +++ b/upb/message/message.c @@ -20,31 +20,34 @@ static const size_t message_overhead = sizeof(upb_Message_InternalData); -upb_Message* upb_Message_New(const upb_MiniTable* m, upb_Arena* arena) { - return _upb_Message_New(m, arena); +upb_Message* upb_Message_New(const upb_MiniTable* m, upb_Arena* a) { + return _upb_Message_New(m, a); } bool UPB_PRIVATE(_upb_Message_AddUnknown)(upb_Message* msg, const char* data, size_t len, upb_Arena* arena) { if (!UPB_PRIVATE(_upb_Message_Realloc)(msg, len, arena)) return false; - upb_Message_Internal* in = upb_Message_Getinternal(msg); - memcpy(UPB_PTR_AT(in->internal, in->internal->unknown_end, char), data, len); - in->internal->unknown_end += len; + upb_Message_Internal* owner = upb_Message_Getinternal(msg); + upb_Message_InternalData* in = owner->internal; + memcpy(UPB_PTR_AT(in, in->unknown_end, char), data, len); + in->unknown_end += len; return true; } void _upb_Message_DiscardUnknown_shallow(upb_Message* msg) { - upb_Message_Internal* in = upb_Message_Getinternal(msg); - if (in->internal) { - in->internal->unknown_end = message_overhead; + upb_Message_Internal* owner = upb_Message_Getinternal(msg); + upb_Message_InternalData* in = owner->internal; + if (in) { + in->unknown_end = message_overhead; } } const char* upb_Message_GetUnknown(const upb_Message* msg, size_t* len) { - const upb_Message_Internal* in = upb_Message_Getinternal(msg); - if (in->internal) { - *len = in->internal->unknown_end - message_overhead; - return (char*)(in->internal + 1); + upb_Message_Internal* owner = upb_Message_Getinternal(msg); + upb_Message_InternalData* in = owner->internal; + if (in) { + *len = in->unknown_end - message_overhead; + return (char*)(in + 1); } else { *len = 0; return NULL; @@ -52,9 +55,10 @@ const char* upb_Message_GetUnknown(const upb_Message* msg, size_t* len) { } void upb_Message_DeleteUnknown(upb_Message* msg, const char* data, size_t len) { - upb_Message_Internal* in = upb_Message_Getinternal(msg); - const char* internal_unknown_end = - UPB_PTR_AT(in->internal, in->internal->unknown_end, char); + upb_Message_Internal* owner = upb_Message_Getinternal(msg); + upb_Message_InternalData* in = owner->internal; + const char* internal_unknown_end = UPB_PTR_AT(in, in->unknown_end, char); + #ifndef NDEBUG size_t full_unknown_size; const char* full_unknown = upb_Message_GetUnknown(msg, &full_unknown_size); @@ -63,10 +67,11 @@ void upb_Message_DeleteUnknown(upb_Message* msg, const char* data, size_t len) { UPB_ASSERT((uintptr_t)(data + len) > (uintptr_t)data); UPB_ASSERT((uintptr_t)(data + len) <= (uintptr_t)internal_unknown_end); #endif + if ((data + len) != internal_unknown_end) { memmove((char*)data, data + len, internal_unknown_end - data - len); } - in->internal->unknown_end -= len; + in->unknown_end -= len; } size_t upb_Message_ExtensionCount(const upb_Message* msg) { From 2b79738d5f84aa37226b4ac2bc0210e672d07191 Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Sat, 30 Dec 2023 23:16:16 +0000 Subject: [PATCH 140/255] Auto-generate files after cl/594654099 --- php/ext/google/protobuf/php-upb.c | 109 ++++++++++++++------------ php/ext/google/protobuf/php-upb.h | 13 ++- ruby/ext/google/protobuf_c/ruby-upb.c | 109 ++++++++++++++------------ ruby/ext/google/protobuf_c/ruby-upb.h | 13 ++- 4 files changed, 132 insertions(+), 112 deletions(-) diff --git a/php/ext/google/protobuf/php-upb.c b/php/ext/google/protobuf/php-upb.c index 00db89189728e..b4094324334bd 100644 --- a/php/ext/google/protobuf/php-upb.c +++ b/php/ext/google/protobuf/php-upb.c @@ -6430,31 +6430,34 @@ bool _upb_mapsorter_pushexts(_upb_mapsorter* s, const upb_Extension* exts, static const size_t message_overhead = sizeof(upb_Message_InternalData); -upb_Message* upb_Message_New(const upb_MiniTable* m, upb_Arena* arena) { - return _upb_Message_New(m, arena); +upb_Message* upb_Message_New(const upb_MiniTable* m, upb_Arena* a) { + return _upb_Message_New(m, a); } bool UPB_PRIVATE(_upb_Message_AddUnknown)(upb_Message* msg, const char* data, size_t len, upb_Arena* arena) { if (!UPB_PRIVATE(_upb_Message_Realloc)(msg, len, arena)) return false; - upb_Message_Internal* in = upb_Message_Getinternal(msg); - memcpy(UPB_PTR_AT(in->internal, in->internal->unknown_end, char), data, len); - in->internal->unknown_end += len; + upb_Message_Internal* owner = upb_Message_Getinternal(msg); + upb_Message_InternalData* in = owner->internal; + memcpy(UPB_PTR_AT(in, in->unknown_end, char), data, len); + in->unknown_end += len; return true; } void _upb_Message_DiscardUnknown_shallow(upb_Message* msg) { - upb_Message_Internal* in = upb_Message_Getinternal(msg); - if (in->internal) { - in->internal->unknown_end = message_overhead; + upb_Message_Internal* owner = upb_Message_Getinternal(msg); + upb_Message_InternalData* in = owner->internal; + if (in) { + in->unknown_end = message_overhead; } } const char* upb_Message_GetUnknown(const upb_Message* msg, size_t* len) { - const upb_Message_Internal* in = upb_Message_Getinternal(msg); - if (in->internal) { - *len = in->internal->unknown_end - message_overhead; - return (char*)(in->internal + 1); + upb_Message_Internal* owner = upb_Message_Getinternal(msg); + upb_Message_InternalData* in = owner->internal; + if (in) { + *len = in->unknown_end - message_overhead; + return (char*)(in + 1); } else { *len = 0; return NULL; @@ -6462,9 +6465,10 @@ const char* upb_Message_GetUnknown(const upb_Message* msg, size_t* len) { } void upb_Message_DeleteUnknown(upb_Message* msg, const char* data, size_t len) { - upb_Message_Internal* in = upb_Message_Getinternal(msg); - const char* internal_unknown_end = - UPB_PTR_AT(in->internal, in->internal->unknown_end, char); + upb_Message_Internal* owner = upb_Message_Getinternal(msg); + upb_Message_InternalData* in = owner->internal; + const char* internal_unknown_end = UPB_PTR_AT(in, in->unknown_end, char); + #ifndef NDEBUG size_t full_unknown_size; const char* full_unknown = upb_Message_GetUnknown(msg, &full_unknown_size); @@ -6473,10 +6477,11 @@ void upb_Message_DeleteUnknown(upb_Message* msg, const char* data, size_t len) { UPB_ASSERT((uintptr_t)(data + len) > (uintptr_t)data); UPB_ASSERT((uintptr_t)(data + len) <= (uintptr_t)internal_unknown_end); #endif + if ((data + len) != internal_unknown_end) { memmove((char*)data, data + len, internal_unknown_end - data - len); } - in->internal->unknown_end -= len; + in->unknown_end -= len; } size_t upb_Message_ExtensionCount(const upb_Message* msg) { @@ -15505,11 +15510,10 @@ const struct upb_Extension* _upb_Message_Getext( const struct upb_Extension* UPB_PRIVATE(_upb_Message_Getexts)( const struct upb_Message* msg, size_t* count) { - const upb_Message_Internal* in = upb_Message_Getinternal(msg); - if (in->internal) { - *count = (in->internal->size - in->internal->ext_begin) / - sizeof(struct upb_Extension); - return UPB_PTR_AT(in->internal, in->internal->ext_begin, void); + upb_Message_InternalData* in = upb_Message_GetInternalData(msg); + if (in) { + *count = (in->size - in->ext_begin) / sizeof(struct upb_Extension); + return UPB_PTR_AT(in, in->ext_begin, void); } else { *count = 0; return NULL; @@ -15517,17 +15521,15 @@ const struct upb_Extension* UPB_PRIVATE(_upb_Message_Getexts)( } struct upb_Extension* _upb_Message_GetOrCreateExtension( - struct upb_Message* msg, const upb_MiniTableExtension* e, - upb_Arena* arena) { + struct upb_Message* msg, const upb_MiniTableExtension* e, upb_Arena* a) { struct upb_Extension* ext = (struct upb_Extension*)_upb_Message_Getext(msg, e); if (ext) return ext; - if (!UPB_PRIVATE(_upb_Message_Realloc)(msg, sizeof(struct upb_Extension), - arena)) + if (!UPB_PRIVATE(_upb_Message_Realloc)(msg, sizeof(struct upb_Extension), a)) return NULL; - upb_Message_Internal* in = upb_Message_Getinternal(msg); - in->internal->ext_begin -= sizeof(struct upb_Extension); - ext = UPB_PTR_AT(in->internal, in->internal->ext_begin, void); + upb_Message_InternalData* in = upb_Message_GetInternalData(msg); + in->ext_begin -= sizeof(struct upb_Extension); + ext = UPB_PTR_AT(in, in->ext_begin, void); memset(ext, 0, sizeof(struct upb_Extension)); ext->ext = e; return ext; @@ -15544,38 +15546,41 @@ const float kUpb_FltInfinity = INFINITY; const double kUpb_Infinity = INFINITY; const double kUpb_NaN = NAN; -static const size_t realloc_overhead = sizeof(upb_Message_InternalData); - bool UPB_PRIVATE(_upb_Message_Realloc)(struct upb_Message* msg, size_t need, - upb_Arena* arena) { - upb_Message_Internal* in = upb_Message_Getinternal(msg); - if (!in->internal) { + upb_Arena* a) { + const size_t overhead = sizeof(upb_Message_InternalData); + + upb_Message_Internal* owner = upb_Message_Getinternal(msg); + upb_Message_InternalData* in = owner->internal; + if (!in) { // No internal data, allocate from scratch. - size_t size = UPB_MAX(128, upb_Log2CeilingSize(need + realloc_overhead)); - upb_Message_InternalData* internal = upb_Arena_Malloc(arena, size); - if (!internal) return false; - internal->size = size; - internal->unknown_end = realloc_overhead; - internal->ext_begin = size; - in->internal = internal; - } else if (in->internal->ext_begin - in->internal->unknown_end < need) { + size_t size = UPB_MAX(128, upb_Log2CeilingSize(need + overhead)); + in = upb_Arena_Malloc(a, size); + if (!in) return false; + + in->size = size; + in->unknown_end = overhead; + in->ext_begin = size; + owner->internal = in; + } else if (in->ext_begin - in->unknown_end < need) { // Internal data is too small, reallocate. - size_t new_size = upb_Log2CeilingSize(in->internal->size + need); - size_t ext_bytes = in->internal->size - in->internal->ext_begin; + size_t new_size = upb_Log2CeilingSize(in->size + need); + size_t ext_bytes = in->size - in->ext_begin; size_t new_ext_begin = new_size - ext_bytes; - upb_Message_InternalData* internal = - upb_Arena_Realloc(arena, in->internal, in->internal->size, new_size); - if (!internal) return false; + in = upb_Arena_Realloc(a, in, in->size, new_size); + if (!in) return false; + if (ext_bytes) { // Need to move extension data to the end. - char* ptr = (char*)internal; - memmove(ptr + new_ext_begin, ptr + internal->ext_begin, ext_bytes); + char* ptr = (char*)in; + memmove(ptr + new_ext_begin, ptr + in->ext_begin, ext_bytes); } - internal->ext_begin = new_ext_begin; - internal->size = new_size; - in->internal = internal; + in->ext_begin = new_ext_begin; + in->size = new_size; + owner->internal = in; } - UPB_ASSERT(in->internal->ext_begin - in->internal->unknown_end >= need); + + UPB_ASSERT(in->ext_begin - in->unknown_end >= need); return true; } diff --git a/php/ext/google/protobuf/php-upb.h b/php/ext/google/protobuf/php-upb.h index 5944824f2096a..a533b97709c24 100644 --- a/php/ext/google/protobuf/php-upb.h +++ b/php/ext/google/protobuf/php-upb.h @@ -2323,6 +2323,11 @@ UPB_INLINE upb_Message_Internal* upb_Message_Getinternal( return (upb_Message_Internal*)((char*)msg - size); } +UPB_INLINE upb_Message_InternalData* upb_Message_GetInternalData( + const struct upb_Message* msg) { + return upb_Message_Getinternal(msg)->internal; +} + // Discards the unknown fields for this message only. void _upb_Message_DiscardUnknown_shallow(struct upb_Message* msg); @@ -2724,15 +2729,15 @@ UPB_INLINE bool _upb_Message_SetExtensionField( UPB_INLINE void _upb_Message_ClearExtensionField( struct upb_Message* msg, const upb_MiniTableExtension* ext_l) { - upb_Message_Internal* in = upb_Message_Getinternal(msg); - if (!in->internal) return; + upb_Message_InternalData* in = upb_Message_GetInternalData(msg); + if (!in) return; const struct upb_Extension* base = - UPB_PTR_AT(in->internal, in->internal->ext_begin, struct upb_Extension); + UPB_PTR_AT(in, in->ext_begin, struct upb_Extension); struct upb_Extension* ext = (struct upb_Extension*)_upb_Message_Getext(msg, ext_l); if (ext) { *ext = *base; - in->internal->ext_begin += sizeof(struct upb_Extension); + in->ext_begin += sizeof(struct upb_Extension); } } diff --git a/ruby/ext/google/protobuf_c/ruby-upb.c b/ruby/ext/google/protobuf_c/ruby-upb.c index 037a4d21dbabe..e2dbc47fe486a 100644 --- a/ruby/ext/google/protobuf_c/ruby-upb.c +++ b/ruby/ext/google/protobuf_c/ruby-upb.c @@ -5946,31 +5946,34 @@ bool _upb_mapsorter_pushexts(_upb_mapsorter* s, const upb_Extension* exts, static const size_t message_overhead = sizeof(upb_Message_InternalData); -upb_Message* upb_Message_New(const upb_MiniTable* m, upb_Arena* arena) { - return _upb_Message_New(m, arena); +upb_Message* upb_Message_New(const upb_MiniTable* m, upb_Arena* a) { + return _upb_Message_New(m, a); } bool UPB_PRIVATE(_upb_Message_AddUnknown)(upb_Message* msg, const char* data, size_t len, upb_Arena* arena) { if (!UPB_PRIVATE(_upb_Message_Realloc)(msg, len, arena)) return false; - upb_Message_Internal* in = upb_Message_Getinternal(msg); - memcpy(UPB_PTR_AT(in->internal, in->internal->unknown_end, char), data, len); - in->internal->unknown_end += len; + upb_Message_Internal* owner = upb_Message_Getinternal(msg); + upb_Message_InternalData* in = owner->internal; + memcpy(UPB_PTR_AT(in, in->unknown_end, char), data, len); + in->unknown_end += len; return true; } void _upb_Message_DiscardUnknown_shallow(upb_Message* msg) { - upb_Message_Internal* in = upb_Message_Getinternal(msg); - if (in->internal) { - in->internal->unknown_end = message_overhead; + upb_Message_Internal* owner = upb_Message_Getinternal(msg); + upb_Message_InternalData* in = owner->internal; + if (in) { + in->unknown_end = message_overhead; } } const char* upb_Message_GetUnknown(const upb_Message* msg, size_t* len) { - const upb_Message_Internal* in = upb_Message_Getinternal(msg); - if (in->internal) { - *len = in->internal->unknown_end - message_overhead; - return (char*)(in->internal + 1); + upb_Message_Internal* owner = upb_Message_Getinternal(msg); + upb_Message_InternalData* in = owner->internal; + if (in) { + *len = in->unknown_end - message_overhead; + return (char*)(in + 1); } else { *len = 0; return NULL; @@ -5978,9 +5981,10 @@ const char* upb_Message_GetUnknown(const upb_Message* msg, size_t* len) { } void upb_Message_DeleteUnknown(upb_Message* msg, const char* data, size_t len) { - upb_Message_Internal* in = upb_Message_Getinternal(msg); - const char* internal_unknown_end = - UPB_PTR_AT(in->internal, in->internal->unknown_end, char); + upb_Message_Internal* owner = upb_Message_Getinternal(msg); + upb_Message_InternalData* in = owner->internal; + const char* internal_unknown_end = UPB_PTR_AT(in, in->unknown_end, char); + #ifndef NDEBUG size_t full_unknown_size; const char* full_unknown = upb_Message_GetUnknown(msg, &full_unknown_size); @@ -5989,10 +5993,11 @@ void upb_Message_DeleteUnknown(upb_Message* msg, const char* data, size_t len) { UPB_ASSERT((uintptr_t)(data + len) > (uintptr_t)data); UPB_ASSERT((uintptr_t)(data + len) <= (uintptr_t)internal_unknown_end); #endif + if ((data + len) != internal_unknown_end) { memmove((char*)data, data + len, internal_unknown_end - data - len); } - in->internal->unknown_end -= len; + in->unknown_end -= len; } size_t upb_Message_ExtensionCount(const upb_Message* msg) { @@ -15021,11 +15026,10 @@ const struct upb_Extension* _upb_Message_Getext( const struct upb_Extension* UPB_PRIVATE(_upb_Message_Getexts)( const struct upb_Message* msg, size_t* count) { - const upb_Message_Internal* in = upb_Message_Getinternal(msg); - if (in->internal) { - *count = (in->internal->size - in->internal->ext_begin) / - sizeof(struct upb_Extension); - return UPB_PTR_AT(in->internal, in->internal->ext_begin, void); + upb_Message_InternalData* in = upb_Message_GetInternalData(msg); + if (in) { + *count = (in->size - in->ext_begin) / sizeof(struct upb_Extension); + return UPB_PTR_AT(in, in->ext_begin, void); } else { *count = 0; return NULL; @@ -15033,17 +15037,15 @@ const struct upb_Extension* UPB_PRIVATE(_upb_Message_Getexts)( } struct upb_Extension* _upb_Message_GetOrCreateExtension( - struct upb_Message* msg, const upb_MiniTableExtension* e, - upb_Arena* arena) { + struct upb_Message* msg, const upb_MiniTableExtension* e, upb_Arena* a) { struct upb_Extension* ext = (struct upb_Extension*)_upb_Message_Getext(msg, e); if (ext) return ext; - if (!UPB_PRIVATE(_upb_Message_Realloc)(msg, sizeof(struct upb_Extension), - arena)) + if (!UPB_PRIVATE(_upb_Message_Realloc)(msg, sizeof(struct upb_Extension), a)) return NULL; - upb_Message_Internal* in = upb_Message_Getinternal(msg); - in->internal->ext_begin -= sizeof(struct upb_Extension); - ext = UPB_PTR_AT(in->internal, in->internal->ext_begin, void); + upb_Message_InternalData* in = upb_Message_GetInternalData(msg); + in->ext_begin -= sizeof(struct upb_Extension); + ext = UPB_PTR_AT(in, in->ext_begin, void); memset(ext, 0, sizeof(struct upb_Extension)); ext->ext = e; return ext; @@ -15060,38 +15062,41 @@ const float kUpb_FltInfinity = INFINITY; const double kUpb_Infinity = INFINITY; const double kUpb_NaN = NAN; -static const size_t realloc_overhead = sizeof(upb_Message_InternalData); - bool UPB_PRIVATE(_upb_Message_Realloc)(struct upb_Message* msg, size_t need, - upb_Arena* arena) { - upb_Message_Internal* in = upb_Message_Getinternal(msg); - if (!in->internal) { + upb_Arena* a) { + const size_t overhead = sizeof(upb_Message_InternalData); + + upb_Message_Internal* owner = upb_Message_Getinternal(msg); + upb_Message_InternalData* in = owner->internal; + if (!in) { // No internal data, allocate from scratch. - size_t size = UPB_MAX(128, upb_Log2CeilingSize(need + realloc_overhead)); - upb_Message_InternalData* internal = upb_Arena_Malloc(arena, size); - if (!internal) return false; - internal->size = size; - internal->unknown_end = realloc_overhead; - internal->ext_begin = size; - in->internal = internal; - } else if (in->internal->ext_begin - in->internal->unknown_end < need) { + size_t size = UPB_MAX(128, upb_Log2CeilingSize(need + overhead)); + in = upb_Arena_Malloc(a, size); + if (!in) return false; + + in->size = size; + in->unknown_end = overhead; + in->ext_begin = size; + owner->internal = in; + } else if (in->ext_begin - in->unknown_end < need) { // Internal data is too small, reallocate. - size_t new_size = upb_Log2CeilingSize(in->internal->size + need); - size_t ext_bytes = in->internal->size - in->internal->ext_begin; + size_t new_size = upb_Log2CeilingSize(in->size + need); + size_t ext_bytes = in->size - in->ext_begin; size_t new_ext_begin = new_size - ext_bytes; - upb_Message_InternalData* internal = - upb_Arena_Realloc(arena, in->internal, in->internal->size, new_size); - if (!internal) return false; + in = upb_Arena_Realloc(a, in, in->size, new_size); + if (!in) return false; + if (ext_bytes) { // Need to move extension data to the end. - char* ptr = (char*)internal; - memmove(ptr + new_ext_begin, ptr + internal->ext_begin, ext_bytes); + char* ptr = (char*)in; + memmove(ptr + new_ext_begin, ptr + in->ext_begin, ext_bytes); } - internal->ext_begin = new_ext_begin; - internal->size = new_size; - in->internal = internal; + in->ext_begin = new_ext_begin; + in->size = new_size; + owner->internal = in; } - UPB_ASSERT(in->internal->ext_begin - in->internal->unknown_end >= need); + + UPB_ASSERT(in->ext_begin - in->unknown_end >= need); return true; } diff --git a/ruby/ext/google/protobuf_c/ruby-upb.h b/ruby/ext/google/protobuf_c/ruby-upb.h index 59d543cc25dbd..e44b7b645363f 100755 --- a/ruby/ext/google/protobuf_c/ruby-upb.h +++ b/ruby/ext/google/protobuf_c/ruby-upb.h @@ -2325,6 +2325,11 @@ UPB_INLINE upb_Message_Internal* upb_Message_Getinternal( return (upb_Message_Internal*)((char*)msg - size); } +UPB_INLINE upb_Message_InternalData* upb_Message_GetInternalData( + const struct upb_Message* msg) { + return upb_Message_Getinternal(msg)->internal; +} + // Discards the unknown fields for this message only. void _upb_Message_DiscardUnknown_shallow(struct upb_Message* msg); @@ -2726,15 +2731,15 @@ UPB_INLINE bool _upb_Message_SetExtensionField( UPB_INLINE void _upb_Message_ClearExtensionField( struct upb_Message* msg, const upb_MiniTableExtension* ext_l) { - upb_Message_Internal* in = upb_Message_Getinternal(msg); - if (!in->internal) return; + upb_Message_InternalData* in = upb_Message_GetInternalData(msg); + if (!in) return; const struct upb_Extension* base = - UPB_PTR_AT(in->internal, in->internal->ext_begin, struct upb_Extension); + UPB_PTR_AT(in, in->ext_begin, struct upb_Extension); struct upb_Extension* ext = (struct upb_Extension*)_upb_Message_Getext(msg, ext_l); if (ext) { *ext = *base; - in->internal->ext_begin += sizeof(struct upb_Extension); + in->ext_begin += sizeof(struct upb_Extension); } } From 64dbf0dba475690f292e34ea74bebcfd8d1fab70 Mon Sep 17 00:00:00 2001 From: Eric Salo Date: Mon, 1 Jan 2024 18:19:56 -0800 Subject: [PATCH 141/255] upb: delete the aliases for upb:hash, upb:lex, upb:reflection_internal PiperOrigin-RevId: 594992691 --- python/BUILD.bazel | 2 +- upb/BUILD | 36 +++++++++--------------------------- upb/io/BUILD | 4 ++-- upb/json/BUILD | 2 +- upb/message/BUILD | 2 +- upb/mini_table/BUILD | 4 ++-- upb/reflection/BUILD | 8 ++++---- upb/text/BUILD | 2 +- upb/util/BUILD | 6 +++--- upb/wire/BUILD | 2 +- upb_generator/BUILD | 2 +- 11 files changed, 26 insertions(+), 44 deletions(-) diff --git a/python/BUILD.bazel b/python/BUILD.bazel index 8967bacb3dcd0..325a56bd34046 100644 --- a/python/BUILD.bazel +++ b/python/BUILD.bazel @@ -195,13 +195,13 @@ py_extension( "//upb:base", "//upb:descriptor_upb_proto_reflection", "//upb:eps_copy_input_stream", - "//upb:hash", "//upb:message", "//upb:message_copy", "//upb:port", "//upb:reflection", "//upb:text", "//upb:wire_reader", + "//upb/hash", "//upb/util:compare", "//upb/util:def_to_proto", "//upb/util:required_fields", diff --git a/upb/BUILD b/upb/BUILD index eff6314ec9d03..8979c279bd81f 100644 --- a/upb/BUILD +++ b/upb/BUILD @@ -169,24 +169,12 @@ alias( visibility = ["//visibility:public"], ) -alias( - name = "hash", - actual = "//upb/hash", - visibility = ["//visibility:public"], -) - alias( name = "json", actual = "//upb/json", visibility = ["//visibility:public"], ) -alias( - name = "lex", - actual = "//upb/lex", - visibility = ["//visibility:public"], -) - alias( name = "mem", actual = "//upb/mem", @@ -265,12 +253,6 @@ alias( visibility = ["//visibility:public"], ) -alias( - name = "reflection_internal", - actual = "//upb/reflection:internal", - visibility = ["//visibility:public"], -) - alias( name = "text", actual = "//upb/text", @@ -333,8 +315,6 @@ upb_amalgamation( ":descriptor_upb_proto", ":eps_copy_input_stream", ":generated_code_support__only_for_generated_code_do_not_use__i_give_permission_to_break_me", - ":hash", - ":lex", ":mem", ":message", ":message_accessors", @@ -345,14 +325,16 @@ upb_amalgamation( ":mini_table_compat", ":port", ":reflection", - ":reflection_internal", ":wire", ":wire_reader", "//upb/base:internal", + "//upb/hash:hash", + "//upb/lex:lex", "//upb/mem:internal", "//upb/message:internal", "//upb/mini_descriptor:internal", "//upb/mini_table:internal", + "//upb/reflection:internal", ], strip_import_prefix = ["src"], ) @@ -378,9 +360,7 @@ upb_amalgamation( ":descriptor_upb_proto", ":eps_copy_input_stream", ":generated_code_support__only_for_generated_code_do_not_use__i_give_permission_to_break_me", - ":hash", ":json", - ":lex", ":mem", ":message", ":message_accessors", @@ -391,14 +371,16 @@ upb_amalgamation( ":mini_table_compat", ":port", ":reflection", - ":reflection_internal", ":wire", ":wire_reader", "//upb/base:internal", + "//upb/hash:hash", + "//upb/lex:lex", "//upb/mem:internal", "//upb/message:internal", "//upb/mini_descriptor:internal", "//upb/mini_table:internal", + "//upb/reflection:internal", ], prefix = "php-", strip_import_prefix = ["src"], @@ -425,9 +407,7 @@ upb_amalgamation( ":descriptor_upb_proto", ":eps_copy_input_stream", ":generated_code_support__only_for_generated_code_do_not_use__i_give_permission_to_break_me", - ":hash", ":json", - ":lex", ":mem", ":message", ":message_accessors", @@ -438,14 +418,16 @@ upb_amalgamation( ":mini_table_compat", ":port", ":reflection", - ":reflection_internal", ":wire", ":wire_reader", "//upb/base:internal", + "//upb/hash:hash", + "//upb/lex:lex", "//upb/mem:internal", "//upb/message:internal", "//upb/mini_descriptor:internal", "//upb/mini_table:internal", + "//upb/reflection:internal", ], prefix = "ruby-", strip_import_prefix = ["src"], diff --git a/upb/io/BUILD b/upb/io/BUILD index 490096a153f2b..c1886185c2b26 100644 --- a/upb/io/BUILD +++ b/upb/io/BUILD @@ -19,9 +19,9 @@ cc_library( ":string", ":zero_copy_stream", "//upb:base", - "//upb:lex", "//upb:mem", "//upb:port", + "//upb/lex", ], ) @@ -79,9 +79,9 @@ cc_test( ":string", ":tokenizer", ":zero_copy_stream", - "//upb:lex", "//upb:mem", "//upb:port", + "//upb/lex", "@com_google_absl//absl/strings", "@com_google_absl//absl/strings:str_format", "@com_google_googletest//:gtest", diff --git a/upb/json/BUILD b/upb/json/BUILD index d10498fadadc1..61461be38ccaf 100644 --- a/upb/json/BUILD +++ b/upb/json/BUILD @@ -21,13 +21,13 @@ cc_library( visibility = ["//visibility:public"], deps = [ "//upb:base", - "//upb:lex", "//upb:mem", "//upb:message", "//upb:mini_table", "//upb:port", "//upb:reflection", "//upb:wire", + "//upb/lex", ], ) diff --git a/upb/message/BUILD b/upb/message/BUILD index 1b10994878f8a..6988edbc16fbe 100644 --- a/upb/message/BUILD +++ b/upb/message/BUILD @@ -67,11 +67,11 @@ cc_library( visibility = ["//visibility:public"], deps = [ "//upb:base", - "//upb:hash", "//upb:mem", "//upb:mini_table", "//upb:port", "//upb/base:internal", + "//upb/hash", ], ) diff --git a/upb/mini_table/BUILD b/upb/mini_table/BUILD index 221e87be83002..6df9ff0b5cbb0 100644 --- a/upb/mini_table/BUILD +++ b/upb/mini_table/BUILD @@ -30,9 +30,9 @@ cc_library( deps = [ ":internal", "//upb:base", - "//upb:hash", "//upb:mem", "//upb:port", + "//upb/hash", ], ) @@ -72,9 +72,9 @@ cc_library( deps = [ ":mini_table", "//upb:base", - "//upb:hash", "//upb:mem", "//upb:port", + "//upb/hash", ], ) diff --git a/upb/reflection/BUILD b/upb/reflection/BUILD index 9bb1b648c56df..685f2d5bd251f 100644 --- a/upb/reflection/BUILD +++ b/upb/reflection/BUILD @@ -133,7 +133,6 @@ bootstrap_cc_library( visibility = ["//visibility:public"], deps = [ "//upb:base", - "//upb:hash", "//upb:mem", "//upb:message", "//upb:message_accessors", @@ -143,6 +142,7 @@ bootstrap_cc_library( "//upb:port", "//upb:wire", "//upb/base:internal", + "//upb/hash", "//upb/message:internal", "//upb/mini_descriptor:internal", ], @@ -160,9 +160,9 @@ cc_library( ], visibility = ["//visibility:public"], deps = [ + ":internal", "//upb:mem", "//upb:mini_descriptor", - "//upb:reflection_internal", ], ) @@ -176,12 +176,12 @@ cc_test( ], deps = [ ":descriptor_upb_proto", + ":internal", "//upb:base", - "//upb:hash", "//upb:mem", "//upb:port", "//upb:reflection", - "//upb:reflection_internal", + "//upb/hash", "@com_google_absl//absl/strings", "@com_google_googletest//:gtest", "@com_google_googletest//:gtest_main", diff --git a/upb/text/BUILD b/upb/text/BUILD index a9ba0db43692c..5d2418545d37c 100644 --- a/upb/text/BUILD +++ b/upb/text/BUILD @@ -19,12 +19,12 @@ cc_library( visibility = ["//visibility:public"], deps = [ "//upb:eps_copy_input_stream", - "//upb:lex", "//upb:message", "//upb:port", "//upb:reflection", "//upb:wire", "//upb:wire_reader", + "//upb/lex", "//upb/message:internal", ], ) diff --git a/upb/util/BUILD b/upb/util/BUILD index e43b23959c530..962f208f8e82d 100644 --- a/upb/util/BUILD +++ b/upb/util/BUILD @@ -20,7 +20,7 @@ cc_library( deps = [ "//upb:port", "//upb:reflection", - "//upb:reflection_internal", + "//upb/reflection:internal", ], ) @@ -53,7 +53,7 @@ cc_library( "//upb:base", "//upb:descriptor_upb_proto", "//upb:mem", - "//upb:reflection_internal", + "//upb/reflection:internal", "@com_google_googletest//:gtest", ], ) @@ -135,7 +135,7 @@ cc_test( "//upb:json", "//upb:mem", "//upb:reflection", - "//upb:reflection_internal", + "//upb/reflection:internal", "@com_google_absl//absl/strings", "@com_google_googletest//:gtest", "@com_google_googletest//:gtest_main", diff --git a/upb/wire/BUILD b/upb/wire/BUILD index 93be09bd9fee8..6a7a68b2cbb63 100644 --- a/upb/wire/BUILD +++ b/upb/wire/BUILD @@ -28,12 +28,12 @@ cc_library( ":reader", "//third_party/utf8_range", "//upb:base", - "//upb:hash", "//upb:mem", "//upb:message", "//upb:message_accessors", "//upb:mini_table", "//upb:port", + "//upb/hash", "//upb/mem:internal", "//upb/message:internal", "//upb/mini_table:internal", diff --git a/upb_generator/BUILD b/upb_generator/BUILD index c280281ae6ec0..8fc302850c522 100644 --- a/upb_generator/BUILD +++ b/upb_generator/BUILD @@ -243,8 +243,8 @@ cc_library( "//upb:mini_table", "//upb:port", "//upb:reflection", - "//upb:reflection_internal", "//upb:wire", + "//upb/reflection:internal", ], ) From cb8a31ee3de447ab08266482c79691837bd8fd4a Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Tue, 2 Jan 2024 02:33:01 +0000 Subject: [PATCH 142/255] Auto-generate files after cl/594992691 --- php/ext/google/protobuf/php-upb.c | 22336 ++++++++++++------------ php/ext/google/protobuf/php-upb.h | 1452 +- ruby/ext/google/protobuf_c/ruby-upb.c | 22336 ++++++++++++------------ ruby/ext/google/protobuf_c/ruby-upb.h | 1420 +- 4 files changed, 23772 insertions(+), 23772 deletions(-) diff --git a/php/ext/google/protobuf/php-upb.c b/php/ext/google/protobuf/php-upb.c index b4094324334bd..c30b837b9d3af 100644 --- a/php/ext/google/protobuf/php-upb.c +++ b/php/ext/google/protobuf/php-upb.c @@ -2244,2284 +2244,2056 @@ const char* _upb_EpsCopyInputStream_IsDoneFallbackNoCallback( e, ptr, overrun, _upb_EpsCopyInputStream_NoOpCallback); } -/* - * upb_table Implementation - * - * Implementation is heavily inspired by Lua's ltable.c. - */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include // Must be last. -#define UPB_MAXARRSIZE 16 // 2**16 = 64k. - -// From Chromium. -#define ARRAY_SIZE(x) \ - ((sizeof(x) / sizeof(0 [x])) / ((size_t)(!(sizeof(x) % sizeof(0 [x]))))) +typedef struct { + const char *ptr, *end; + upb_Arena* arena; /* TODO: should we have a tmp arena for tmp data? */ + const upb_DefPool* symtab; + int depth; + upb_Status* status; + jmp_buf err; + int line; + const char* line_begin; + bool is_first; + int options; + const upb_FieldDef* debug_field; +} jsondec; -static const double MAX_LOAD = 0.85; +typedef struct { + upb_MessageValue value; + bool ignore; +} upb_JsonMessageValue; -/* The minimum utilization of the array part of a mixed hash/array table. This - * is a speed/memory-usage tradeoff (though it's not straightforward because of - * cache effects). The lower this is, the more memory we'll use. */ -static const double MIN_DENSITY = 0.1; +enum { JD_OBJECT, JD_ARRAY, JD_STRING, JD_NUMBER, JD_TRUE, JD_FALSE, JD_NULL }; -static bool is_pow2(uint64_t v) { return v == 0 || (v & (v - 1)) == 0; } +/* Forward declarations of mutually-recursive functions. */ +static void jsondec_wellknown(jsondec* d, upb_Message* msg, + const upb_MessageDef* m); +static upb_JsonMessageValue jsondec_value(jsondec* d, const upb_FieldDef* f); +static void jsondec_wellknownvalue(jsondec* d, upb_Message* msg, + const upb_MessageDef* m); +static void jsondec_object(jsondec* d, upb_Message* msg, + const upb_MessageDef* m); -static upb_value _upb_value_val(uint64_t val) { - upb_value ret; - _upb_value_setval(&ret, val); - return ret; +static bool jsondec_streql(upb_StringView str, const char* lit) { + return str.size == strlen(lit) && memcmp(str.data, lit, str.size) == 0; } -static int log2ceil(uint64_t v) { - int ret = 0; - bool pow2 = is_pow2(v); - while (v >>= 1) ret++; - ret = pow2 ? ret : ret + 1; // Ceiling. - return UPB_MIN(UPB_MAXARRSIZE, ret); +static bool jsondec_isnullvalue(const upb_FieldDef* f) { + return upb_FieldDef_CType(f) == kUpb_CType_Enum && + strcmp(upb_EnumDef_FullName(upb_FieldDef_EnumSubDef(f)), + "google.protobuf.NullValue") == 0; } -/* A type to represent the lookup key of either a strtable or an inttable. */ -typedef union { - uintptr_t num; - struct { - const char* str; - size_t len; - } str; -} lookupkey_t; - -static lookupkey_t strkey2(const char* str, size_t len) { - lookupkey_t k; - k.str.str = str; - k.str.len = len; - return k; +static bool jsondec_isvalue(const upb_FieldDef* f) { + return (upb_FieldDef_CType(f) == kUpb_CType_Message && + upb_MessageDef_WellKnownType(upb_FieldDef_MessageSubDef(f)) == + kUpb_WellKnown_Value) || + jsondec_isnullvalue(f); } -static lookupkey_t intkey(uintptr_t key) { - lookupkey_t k; - k.num = key; - return k; +static void jsondec_seterrmsg(jsondec* d, const char* msg) { + upb_Status_SetErrorFormat(d->status, "Error parsing JSON @%d:%d: %s", d->line, + (int)(d->ptr - d->line_begin), msg); } -typedef uint32_t hashfunc_t(upb_tabkey key); -typedef bool eqlfunc_t(upb_tabkey k1, lookupkey_t k2); - -/* Base table (shared code) ***************************************************/ - -static uint32_t upb_inthash(uintptr_t key) { return (uint32_t)key; } - -static const upb_tabent* upb_getentry(const upb_table* t, uint32_t hash) { - return t->entries + (hash & t->mask); +UPB_NORETURN static void jsondec_err(jsondec* d, const char* msg) { + jsondec_seterrmsg(d, msg); + UPB_LONGJMP(d->err, 1); } -static bool upb_arrhas(upb_tabval key) { return key.val != (uint64_t)-1; } - -static bool isfull(upb_table* t) { return t->count == t->max_count; } - -static bool init(upb_table* t, uint8_t size_lg2, upb_Arena* a) { - size_t bytes; +UPB_PRINTF(2, 3) +UPB_NORETURN static void jsondec_errf(jsondec* d, const char* fmt, ...) { + va_list argp; + upb_Status_SetErrorFormat(d->status, "Error parsing JSON @%d:%d: ", d->line, + (int)(d->ptr - d->line_begin)); + va_start(argp, fmt); + upb_Status_VAppendErrorFormat(d->status, fmt, argp); + va_end(argp); + UPB_LONGJMP(d->err, 1); +} - t->count = 0; - t->size_lg2 = size_lg2; - t->mask = upb_table_size(t) ? upb_table_size(t) - 1 : 0; - t->max_count = upb_table_size(t) * MAX_LOAD; - bytes = upb_table_size(t) * sizeof(upb_tabent); - if (bytes > 0) { - t->entries = upb_Arena_Malloc(a, bytes); - if (!t->entries) return false; - memset(t->entries, 0, bytes); - } else { - t->entries = NULL; +// Advances d->ptr until the next non-whitespace character or to the end of +// the buffer. +static void jsondec_consumews(jsondec* d) { + while (d->ptr != d->end) { + switch (*d->ptr) { + case '\n': + d->line++; + d->line_begin = d->ptr; + /* Fallthrough. */ + case '\r': + case '\t': + case ' ': + d->ptr++; + break; + default: + return; + } } - return true; } -static upb_tabent* emptyent(upb_table* t, upb_tabent* e) { - upb_tabent* begin = t->entries; - upb_tabent* end = begin + upb_table_size(t); - for (e = e + 1; e < end; e++) { - if (upb_tabent_isempty(e)) return e; - } - for (e = begin; e < end; e++) { - if (upb_tabent_isempty(e)) return e; +// Advances d->ptr until the next non-whitespace character. Postcondition that +// d->ptr is pointing at a valid non-whitespace character (will err if end of +// buffer is reached). +static void jsondec_skipws(jsondec* d) { + jsondec_consumews(d); + if (d->ptr == d->end) { + jsondec_err(d, "Unexpected EOF"); } - UPB_ASSERT(false); - return NULL; } -static upb_tabent* getentry_mutable(upb_table* t, uint32_t hash) { - return (upb_tabent*)upb_getentry(t, hash); +static bool jsondec_tryparsech(jsondec* d, char ch) { + if (d->ptr == d->end || *d->ptr != ch) return false; + d->ptr++; + return true; } -static const upb_tabent* findentry(const upb_table* t, lookupkey_t key, - uint32_t hash, eqlfunc_t* eql) { - const upb_tabent* e; +static void jsondec_parselit(jsondec* d, const char* lit) { + size_t avail = d->end - d->ptr; + size_t len = strlen(lit); + if (avail < len || memcmp(d->ptr, lit, len) != 0) { + jsondec_errf(d, "Expected: '%s'", lit); + } + d->ptr += len; +} - if (t->size_lg2 == 0) return NULL; - e = upb_getentry(t, hash); - if (upb_tabent_isempty(e)) return NULL; - while (1) { - if (eql(e->key, key)) return e; - if ((e = e->next) == NULL) return NULL; +static void jsondec_wsch(jsondec* d, char ch) { + jsondec_skipws(d); + if (!jsondec_tryparsech(d, ch)) { + jsondec_errf(d, "Expected: '%c'", ch); } } -static upb_tabent* findentry_mutable(upb_table* t, lookupkey_t key, - uint32_t hash, eqlfunc_t* eql) { - return (upb_tabent*)findentry(t, key, hash, eql); +static void jsondec_true(jsondec* d) { jsondec_parselit(d, "true"); } +static void jsondec_false(jsondec* d) { jsondec_parselit(d, "false"); } +static void jsondec_null(jsondec* d) { jsondec_parselit(d, "null"); } + +static void jsondec_entrysep(jsondec* d) { + jsondec_skipws(d); + jsondec_parselit(d, ":"); } -static bool lookup(const upb_table* t, lookupkey_t key, upb_value* v, - uint32_t hash, eqlfunc_t* eql) { - const upb_tabent* e = findentry(t, key, hash, eql); - if (e) { - if (v) { - _upb_value_setval(v, e->val.val); - } - return true; - } else { - return false; +static int jsondec_rawpeek(jsondec* d) { + if (d->ptr == d->end) { + jsondec_err(d, "Unexpected EOF"); } -} -/* The given key must not already exist in the table. */ -static void insert(upb_table* t, lookupkey_t key, upb_tabkey tabkey, - upb_value val, uint32_t hash, hashfunc_t* hashfunc, - eqlfunc_t* eql) { - upb_tabent* mainpos_e; - upb_tabent* our_e; + switch (*d->ptr) { + case '{': + return JD_OBJECT; + case '[': + return JD_ARRAY; + case '"': + return JD_STRING; + case '-': + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + return JD_NUMBER; + case 't': + return JD_TRUE; + case 'f': + return JD_FALSE; + case 'n': + return JD_NULL; + default: + jsondec_errf(d, "Unexpected character: '%c'", *d->ptr); + } +} - UPB_ASSERT(findentry(t, key, hash, eql) == NULL); +/* JSON object/array **********************************************************/ - t->count++; - mainpos_e = getentry_mutable(t, hash); - our_e = mainpos_e; +/* These are used like so: + * + * jsondec_objstart(d); + * while (jsondec_objnext(d)) { + * ... + * } + * jsondec_objend(d) */ - if (upb_tabent_isempty(mainpos_e)) { - /* Our main position is empty; use it. */ - our_e->next = NULL; - } else { - /* Collision. */ - upb_tabent* new_e = emptyent(t, mainpos_e); - /* Head of collider's chain. */ - upb_tabent* chain = getentry_mutable(t, hashfunc(mainpos_e->key)); - if (chain == mainpos_e) { - /* Existing ent is in its main position (it has the same hash as us, and - * is the head of our chain). Insert to new ent and append to this chain. - */ - new_e->next = mainpos_e->next; - mainpos_e->next = new_e; - our_e = new_e; - } else { - /* Existing ent is not in its main position (it is a node in some other - * chain). This implies that no existing ent in the table has our hash. - * Evict it (updating its chain) and use its ent for head of our chain. */ - *new_e = *mainpos_e; /* copies next. */ - while (chain->next != mainpos_e) { - chain = (upb_tabent*)chain->next; - UPB_ASSERT(chain); - } - chain->next = new_e; - our_e = mainpos_e; - our_e->next = NULL; - } - } - our_e->key = tabkey; - our_e->val.val = val.val; - UPB_ASSERT(findentry(t, key, hash, eql) == our_e); +static int jsondec_peek(jsondec* d) { + jsondec_skipws(d); + return jsondec_rawpeek(d); } -static bool rm(upb_table* t, lookupkey_t key, upb_value* val, - upb_tabkey* removed, uint32_t hash, eqlfunc_t* eql) { - upb_tabent* chain = getentry_mutable(t, hash); - if (upb_tabent_isempty(chain)) return false; - if (eql(chain->key, key)) { - /* Element to remove is at the head of its chain. */ - t->count--; - if (val) _upb_value_setval(val, chain->val.val); - if (removed) *removed = chain->key; - if (chain->next) { - upb_tabent* move = (upb_tabent*)chain->next; - *chain = *move; - move->key = 0; /* Make the slot empty. */ - } else { - chain->key = 0; /* Make the slot empty. */ - } - return true; - } else { - /* Element to remove is either in a non-head position or not in the - * table. */ - while (chain->next && !eql(chain->next->key, key)) { - chain = (upb_tabent*)chain->next; - } - if (chain->next) { - /* Found element to remove. */ - upb_tabent* rm = (upb_tabent*)chain->next; - t->count--; - if (val) _upb_value_setval(val, chain->next->val.val); - if (removed) *removed = rm->key; - rm->key = 0; /* Make the slot empty. */ - chain->next = rm->next; - return true; - } else { - /* Element to remove is not in the table. */ - return false; - } +static void jsondec_push(jsondec* d) { + if (--d->depth < 0) { + jsondec_err(d, "Recursion limit exceeded"); } + d->is_first = true; } -static size_t next(const upb_table* t, size_t i) { - do { - if (++i >= upb_table_size(t)) return SIZE_MAX - 1; /* Distinct from -1. */ - } while (upb_tabent_isempty(&t->entries[i])); - - return i; +static bool jsondec_seqnext(jsondec* d, char end_ch) { + bool is_first = d->is_first; + d->is_first = false; + jsondec_skipws(d); + if (*d->ptr == end_ch) return false; + if (!is_first) jsondec_parselit(d, ","); + return true; } -static size_t begin(const upb_table* t) { return next(t, -1); } - -/* upb_strtable ***************************************************************/ - -/* A simple "subclass" of upb_table that only adds a hash function for strings. - */ +static void jsondec_arrstart(jsondec* d) { + jsondec_push(d); + jsondec_wsch(d, '['); +} -static upb_tabkey strcopy(lookupkey_t k2, upb_Arena* a) { - uint32_t len = (uint32_t)k2.str.len; - char* str = upb_Arena_Malloc(a, k2.str.len + sizeof(uint32_t) + 1); - if (str == NULL) return 0; - memcpy(str, &len, sizeof(uint32_t)); - if (k2.str.len) memcpy(str + sizeof(uint32_t), k2.str.str, k2.str.len); - str[sizeof(uint32_t) + k2.str.len] = '\0'; - return (uintptr_t)str; +static void jsondec_arrend(jsondec* d) { + d->depth++; + jsondec_wsch(d, ']'); } -/* Adapted from ABSL's wyhash. */ +static bool jsondec_arrnext(jsondec* d) { return jsondec_seqnext(d, ']'); } -static uint64_t UnalignedLoad64(const void* p) { - uint64_t val; - memcpy(&val, p, 8); - return val; +static void jsondec_objstart(jsondec* d) { + jsondec_push(d); + jsondec_wsch(d, '{'); } -static uint32_t UnalignedLoad32(const void* p) { - uint32_t val; - memcpy(&val, p, 4); - return val; +static void jsondec_objend(jsondec* d) { + d->depth++; + jsondec_wsch(d, '}'); } -#if defined(_MSC_VER) && defined(_M_X64) -#include -#endif - -/* Computes a * b, returning the low 64 bits of the result and storing the high - * 64 bits in |*high|. */ -static uint64_t upb_umul128(uint64_t v0, uint64_t v1, uint64_t* out_high) { -#ifdef __SIZEOF_INT128__ - __uint128_t p = v0; - p *= v1; - *out_high = (uint64_t)(p >> 64); - return (uint64_t)p; -#elif defined(_MSC_VER) && defined(_M_X64) - return _umul128(v0, v1, out_high); -#else - uint64_t a32 = v0 >> 32; - uint64_t a00 = v0 & 0xffffffff; - uint64_t b32 = v1 >> 32; - uint64_t b00 = v1 & 0xffffffff; - uint64_t high = a32 * b32; - uint64_t low = a00 * b00; - uint64_t mid1 = a32 * b00; - uint64_t mid2 = a00 * b32; - low += (mid1 << 32) + (mid2 << 32); - // Omit carry bit, for mixing we do not care about exact numerical precision. - high += (mid1 >> 32) + (mid2 >> 32); - *out_high = high; - return low; -#endif +static bool jsondec_objnext(jsondec* d) { + if (!jsondec_seqnext(d, '}')) return false; + if (jsondec_peek(d) != JD_STRING) { + jsondec_err(d, "Object must start with string"); + } + return true; } -static uint64_t WyhashMix(uint64_t v0, uint64_t v1) { - uint64_t high; - uint64_t low = upb_umul128(v0, v1, &high); - return low ^ high; -} +/* JSON number ****************************************************************/ -static uint64_t Wyhash(const void* data, size_t len, uint64_t seed, - const uint64_t salt[]) { - const uint8_t* ptr = (const uint8_t*)data; - uint64_t starting_length = (uint64_t)len; - uint64_t current_state = seed ^ salt[0]; +static bool jsondec_tryskipdigits(jsondec* d) { + const char* start = d->ptr; - if (len > 64) { - // If we have more than 64 bytes, we're going to handle chunks of 64 - // bytes at a time. We're going to build up two separate hash states - // which we will then hash together. - uint64_t duplicated_state = current_state; + while (d->ptr < d->end) { + if (*d->ptr < '0' || *d->ptr > '9') { + break; + } + d->ptr++; + } - do { - uint64_t a = UnalignedLoad64(ptr); - uint64_t b = UnalignedLoad64(ptr + 8); - uint64_t c = UnalignedLoad64(ptr + 16); - uint64_t d = UnalignedLoad64(ptr + 24); - uint64_t e = UnalignedLoad64(ptr + 32); - uint64_t f = UnalignedLoad64(ptr + 40); - uint64_t g = UnalignedLoad64(ptr + 48); - uint64_t h = UnalignedLoad64(ptr + 56); + return d->ptr != start; +} - uint64_t cs0 = WyhashMix(a ^ salt[1], b ^ current_state); - uint64_t cs1 = WyhashMix(c ^ salt[2], d ^ current_state); - current_state = (cs0 ^ cs1); +static void jsondec_skipdigits(jsondec* d) { + if (!jsondec_tryskipdigits(d)) { + jsondec_err(d, "Expected one or more digits"); + } +} - uint64_t ds0 = WyhashMix(e ^ salt[3], f ^ duplicated_state); - uint64_t ds1 = WyhashMix(g ^ salt[4], h ^ duplicated_state); - duplicated_state = (ds0 ^ ds1); +static double jsondec_number(jsondec* d) { + const char* start = d->ptr; - ptr += 64; - len -= 64; - } while (len > 64); + UPB_ASSERT(jsondec_rawpeek(d) == JD_NUMBER); - current_state = current_state ^ duplicated_state; - } + /* Skip over the syntax of a number, as specified by JSON. */ + if (*d->ptr == '-') d->ptr++; - // We now have a data `ptr` with at most 64 bytes and the current state - // of the hashing state machine stored in current_state. - while (len > 16) { - uint64_t a = UnalignedLoad64(ptr); - uint64_t b = UnalignedLoad64(ptr + 8); + if (jsondec_tryparsech(d, '0')) { + if (jsondec_tryskipdigits(d)) { + jsondec_err(d, "number cannot have leading zero"); + } + } else { + jsondec_skipdigits(d); + } - current_state = WyhashMix(a ^ salt[1], b ^ current_state); + if (d->ptr == d->end) goto parse; + if (jsondec_tryparsech(d, '.')) { + jsondec_skipdigits(d); + } + if (d->ptr == d->end) goto parse; - ptr += 16; - len -= 16; + if (*d->ptr == 'e' || *d->ptr == 'E') { + d->ptr++; + if (d->ptr == d->end) { + jsondec_err(d, "Unexpected EOF in number"); + } + if (*d->ptr == '+' || *d->ptr == '-') { + d->ptr++; + } + jsondec_skipdigits(d); } - // We now have a data `ptr` with at most 16 bytes. - uint64_t a = 0; - uint64_t b = 0; - if (len > 8) { - // When we have at least 9 and at most 16 bytes, set A to the first 64 - // bits of the input and B to the last 64 bits of the input. Yes, they will - // overlap in the middle if we are working with less than the full 16 - // bytes. - a = UnalignedLoad64(ptr); - b = UnalignedLoad64(ptr + len - 8); - } else if (len > 3) { - // If we have at least 4 and at most 8 bytes, set A to the first 32 - // bits and B to the last 32 bits. - a = UnalignedLoad32(ptr); - b = UnalignedLoad32(ptr + len - 4); - } else if (len > 0) { - // If we have at least 1 and at most 3 bytes, read all of the provided - // bits into A, with some adjustments. - a = ((ptr[0] << 16) | (ptr[len >> 1] << 8) | ptr[len - 1]); - b = 0; - } else { - a = 0; - b = 0; - } - - uint64_t w = WyhashMix(a ^ salt[1], b ^ current_state); - uint64_t z = salt[1] ^ starting_length; - return WyhashMix(w, z); -} - -const uint64_t kWyhashSalt[5] = { - 0x243F6A8885A308D3ULL, 0x13198A2E03707344ULL, 0xA4093822299F31D0ULL, - 0x082EFA98EC4E6C89ULL, 0x452821E638D01377ULL, -}; +parse: + /* Having verified the syntax of a JSON number, use strtod() to parse + * (strtod() accepts a superset of JSON syntax). */ + errno = 0; + { + // Copy the number into a null-terminated scratch buffer since strtod + // expects a null-terminated string. + char nullz[64]; + ptrdiff_t len = d->ptr - start; + if (len > (ptrdiff_t)(sizeof(nullz) - 1)) { + jsondec_err(d, "excessively long number"); + } + memcpy(nullz, start, len); + nullz[len] = '\0'; -uint32_t _upb_Hash(const void* p, size_t n, uint64_t seed) { - return Wyhash(p, n, seed, kWyhashSalt); -} + char* end; + double val = strtod(nullz, &end); + UPB_ASSERT(end - nullz == len); -static uint32_t _upb_Hash_NoSeed(const char* p, size_t n) { - return _upb_Hash(p, n, 0); -} + /* Currently the min/max-val conformance tests fail if we check this. Does + * this mean the conformance tests are wrong or strtod() is wrong, or + * something else? Investigate further. */ + /* + if (errno == ERANGE) { + jsondec_err(d, "Number out of range"); + } + */ -static uint32_t strhash(upb_tabkey key) { - uint32_t len; - char* str = upb_tabstr(key, &len); - return _upb_Hash_NoSeed(str, len); -} + if (val > DBL_MAX || val < -DBL_MAX) { + jsondec_err(d, "Number out of range"); + } -static bool streql(upb_tabkey k1, lookupkey_t k2) { - uint32_t len; - char* str = upb_tabstr(k1, &len); - return len == k2.str.len && (len == 0 || memcmp(str, k2.str.str, len) == 0); + return val; + } } -bool upb_strtable_init(upb_strtable* t, size_t expected_size, upb_Arena* a) { - // Multiply by approximate reciprocal of MAX_LOAD (0.85), with pow2 - // denominator. - size_t need_entries = (expected_size + 1) * 1204 / 1024; - UPB_ASSERT(need_entries >= expected_size * 0.85); - int size_lg2 = upb_Log2Ceiling(need_entries); - return init(&t->t, size_lg2, a); -} +/* JSON string ****************************************************************/ -void upb_strtable_clear(upb_strtable* t) { - size_t bytes = upb_table_size(&t->t) * sizeof(upb_tabent); - t->t.count = 0; - memset((char*)t->t.entries, 0, bytes); +static char jsondec_escape(jsondec* d) { + switch (*d->ptr++) { + case '"': + return '\"'; + case '\\': + return '\\'; + case '/': + return '/'; + case 'b': + return '\b'; + case 'f': + return '\f'; + case 'n': + return '\n'; + case 'r': + return '\r'; + case 't': + return '\t'; + default: + jsondec_err(d, "Invalid escape char"); + } } -bool upb_strtable_resize(upb_strtable* t, size_t size_lg2, upb_Arena* a) { - upb_strtable new_table; - if (!init(&new_table.t, size_lg2, a)) return false; +static uint32_t jsondec_codepoint(jsondec* d) { + uint32_t cp = 0; + const char* end; - intptr_t iter = UPB_STRTABLE_BEGIN; - upb_StringView key; - upb_value val; - while (upb_strtable_next2(t, &key, &val, &iter)) { - upb_strtable_insert(&new_table, key.data, key.size, val, a); + if (d->end - d->ptr < 4) { + jsondec_err(d, "EOF inside string"); } - *t = new_table; - return true; -} -bool upb_strtable_insert(upb_strtable* t, const char* k, size_t len, - upb_value v, upb_Arena* a) { - lookupkey_t key; - upb_tabkey tabkey; - uint32_t hash; - - if (isfull(&t->t)) { - /* Need to resize. New table of double the size, add old elements to it. */ - if (!upb_strtable_resize(t, t->t.size_lg2 + 1, a)) { - return false; + end = d->ptr + 4; + while (d->ptr < end) { + char ch = *d->ptr++; + if (ch >= '0' && ch <= '9') { + ch -= '0'; + } else if (ch >= 'a' && ch <= 'f') { + ch = ch - 'a' + 10; + } else if (ch >= 'A' && ch <= 'F') { + ch = ch - 'A' + 10; + } else { + jsondec_err(d, "Invalid hex digit"); } + cp = (cp << 4) | ch; } - key = strkey2(k, len); - tabkey = strcopy(key, a); - if (tabkey == 0) return false; - - hash = _upb_Hash_NoSeed(key.str.str, key.str.len); - insert(&t->t, key, tabkey, v, hash, &strhash, &streql); - return true; -} - -bool upb_strtable_lookup2(const upb_strtable* t, const char* key, size_t len, - upb_value* v) { - uint32_t hash = _upb_Hash_NoSeed(key, len); - return lookup(&t->t, strkey2(key, len), v, hash, &streql); -} - -bool upb_strtable_remove2(upb_strtable* t, const char* key, size_t len, - upb_value* val) { - uint32_t hash = _upb_Hash_NoSeed(key, len); - upb_tabkey tabkey; - return rm(&t->t, strkey2(key, len), val, &tabkey, hash, &streql); -} - -/* Iteration */ - -void upb_strtable_begin(upb_strtable_iter* i, const upb_strtable* t) { - i->t = t; - i->index = begin(&t->t); -} - -void upb_strtable_next(upb_strtable_iter* i) { - i->index = next(&i->t->t, i->index); + return cp; } -bool upb_strtable_done(const upb_strtable_iter* i) { - if (!i->t) return true; - return i->index >= upb_table_size(&i->t->t) || - upb_tabent_isempty(str_tabent(i)); -} +/* Parses a \uXXXX unicode escape (possibly a surrogate pair). */ +static size_t jsondec_unicode(jsondec* d, char* out) { + uint32_t cp = jsondec_codepoint(d); + if (upb_Unicode_IsHigh(cp)) { + /* Surrogate pair: two 16-bit codepoints become a 32-bit codepoint. */ + jsondec_parselit(d, "\\u"); + uint32_t low = jsondec_codepoint(d); + if (!upb_Unicode_IsLow(low)) jsondec_err(d, "Invalid low surrogate"); + cp = upb_Unicode_FromPair(cp, low); + } else if (upb_Unicode_IsLow(cp)) { + jsondec_err(d, "Unpaired low surrogate"); + } -upb_StringView upb_strtable_iter_key(const upb_strtable_iter* i) { - upb_StringView key; - uint32_t len; - UPB_ASSERT(!upb_strtable_done(i)); - key.data = upb_tabstr(str_tabent(i)->key, &len); - key.size = len; - return key; + /* Write to UTF-8 */ + int bytes = upb_Unicode_ToUTF8(cp, out); + if (bytes == 0) jsondec_err(d, "Invalid codepoint"); + return bytes; } -upb_value upb_strtable_iter_value(const upb_strtable_iter* i) { - UPB_ASSERT(!upb_strtable_done(i)); - return _upb_value_val(str_tabent(i)->val.val); -} +static void jsondec_resize(jsondec* d, char** buf, char** end, char** buf_end) { + size_t oldsize = *buf_end - *buf; + size_t len = *end - *buf; + size_t size = UPB_MAX(8, 2 * oldsize); -void upb_strtable_iter_setdone(upb_strtable_iter* i) { - i->t = NULL; - i->index = SIZE_MAX; -} + *buf = upb_Arena_Realloc(d->arena, *buf, len, size); + if (!*buf) jsondec_err(d, "Out of memory"); -bool upb_strtable_iter_isequal(const upb_strtable_iter* i1, - const upb_strtable_iter* i2) { - if (upb_strtable_done(i1) && upb_strtable_done(i2)) return true; - return i1->t == i2->t && i1->index == i2->index; + *end = *buf + len; + *buf_end = *buf + size; } -/* upb_inttable ***************************************************************/ +static upb_StringView jsondec_string(jsondec* d) { + char* buf = NULL; + char* end = NULL; + char* buf_end = NULL; -/* For inttables we use a hybrid structure where small keys are kept in an - * array and large keys are put in the hash table. */ + jsondec_skipws(d); -static uint32_t inthash(upb_tabkey key) { return upb_inthash(key); } + if (*d->ptr++ != '"') { + jsondec_err(d, "Expected string"); + } -static bool inteql(upb_tabkey k1, lookupkey_t k2) { return k1 == k2.num; } + while (d->ptr < d->end) { + char ch = *d->ptr++; -static upb_tabval* mutable_array(upb_inttable* t) { - return (upb_tabval*)t->array; -} + if (end == buf_end) { + jsondec_resize(d, &buf, &end, &buf_end); + } -static upb_tabval* inttable_val(upb_inttable* t, uintptr_t key) { - if (key < t->array_size) { - return upb_arrhas(t->array[key]) ? &(mutable_array(t)[key]) : NULL; - } else { - upb_tabent* e = - findentry_mutable(&t->t, intkey(key), upb_inthash(key), &inteql); - return e ? &e->val : NULL; + switch (ch) { + case '"': { + upb_StringView ret; + ret.data = buf; + ret.size = end - buf; + *end = '\0'; /* Needed for possible strtod(). */ + return ret; + } + case '\\': + if (d->ptr == d->end) goto eof; + if (*d->ptr == 'u') { + d->ptr++; + if (buf_end - end < 4) { + /* Allow space for maximum-sized codepoint (4 bytes). */ + jsondec_resize(d, &buf, &end, &buf_end); + } + end += jsondec_unicode(d, end); + } else { + *end++ = jsondec_escape(d); + } + break; + default: + if ((unsigned char)ch < 0x20) { + jsondec_err(d, "Invalid char in JSON string"); + } + *end++ = ch; + break; + } } -} - -static const upb_tabval* inttable_val_const(const upb_inttable* t, - uintptr_t key) { - return inttable_val((upb_inttable*)t, key); -} -size_t upb_inttable_count(const upb_inttable* t) { - return t->t.count + t->array_count; +eof: + jsondec_err(d, "EOF inside string"); } -static void check(upb_inttable* t) { - UPB_UNUSED(t); -#if defined(UPB_DEBUG_TABLE) && !defined(NDEBUG) - { - // This check is very expensive (makes inserts/deletes O(N)). - size_t count = 0; - intptr_t iter = UPB_INTTABLE_BEGIN; - uintptr_t key; - upb_value val; - while (upb_inttable_next(t, &key, &val, &iter)) { - UPB_ASSERT(upb_inttable_lookup(t, key, NULL)); - } - UPB_ASSERT(count == upb_inttable_count(t)); +static void jsondec_skipval(jsondec* d) { + switch (jsondec_peek(d)) { + case JD_OBJECT: + jsondec_objstart(d); + while (jsondec_objnext(d)) { + jsondec_string(d); + jsondec_entrysep(d); + jsondec_skipval(d); + } + jsondec_objend(d); + break; + case JD_ARRAY: + jsondec_arrstart(d); + while (jsondec_arrnext(d)) { + jsondec_skipval(d); + } + jsondec_arrend(d); + break; + case JD_TRUE: + jsondec_true(d); + break; + case JD_FALSE: + jsondec_false(d); + break; + case JD_NULL: + jsondec_null(d); + break; + case JD_STRING: + jsondec_string(d); + break; + case JD_NUMBER: + jsondec_number(d); + break; } -#endif } -bool upb_inttable_sizedinit(upb_inttable* t, size_t asize, int hsize_lg2, - upb_Arena* a) { - size_t array_bytes; +/* Base64 decoding for bytes fields. ******************************************/ - if (!init(&t->t, hsize_lg2, a)) return false; - /* Always make the array part at least 1 long, so that we know key 0 - * won't be in the hash part, which simplifies things. */ - t->array_size = UPB_MAX(1, asize); - t->array_count = 0; - array_bytes = t->array_size * sizeof(upb_value); - t->array = upb_Arena_Malloc(a, array_bytes); - if (!t->array) { - return false; - } - memset(mutable_array(t), 0xff, array_bytes); - check(t); - return true; -} +static unsigned int jsondec_base64_tablelookup(const char ch) { + /* Table includes the normal base64 chars plus the URL-safe variant. */ + const signed char table[256] = { + -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, + -1, 62 /*+*/, -1, 62 /*-*/, -1, 63 /*/ */, 52 /*0*/, + 53 /*1*/, 54 /*2*/, 55 /*3*/, 56 /*4*/, 57 /*5*/, 58 /*6*/, 59 /*7*/, + 60 /*8*/, 61 /*9*/, -1, -1, -1, -1, -1, + -1, -1, 0 /*A*/, 1 /*B*/, 2 /*C*/, 3 /*D*/, 4 /*E*/, + 5 /*F*/, 6 /*G*/, 07 /*H*/, 8 /*I*/, 9 /*J*/, 10 /*K*/, 11 /*L*/, + 12 /*M*/, 13 /*N*/, 14 /*O*/, 15 /*P*/, 16 /*Q*/, 17 /*R*/, 18 /*S*/, + 19 /*T*/, 20 /*U*/, 21 /*V*/, 22 /*W*/, 23 /*X*/, 24 /*Y*/, 25 /*Z*/, + -1, -1, -1, -1, 63 /*_*/, -1, 26 /*a*/, + 27 /*b*/, 28 /*c*/, 29 /*d*/, 30 /*e*/, 31 /*f*/, 32 /*g*/, 33 /*h*/, + 34 /*i*/, 35 /*j*/, 36 /*k*/, 37 /*l*/, 38 /*m*/, 39 /*n*/, 40 /*o*/, + 41 /*p*/, 42 /*q*/, 43 /*r*/, 44 /*s*/, 45 /*t*/, 46 /*u*/, 47 /*v*/, + 48 /*w*/, 49 /*x*/, 50 /*y*/, 51 /*z*/, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1}; -bool upb_inttable_init(upb_inttable* t, upb_Arena* a) { - return upb_inttable_sizedinit(t, 0, 4, a); + /* Sign-extend return value so high bit will be set on any unexpected char. */ + return table[(unsigned)ch]; } -bool upb_inttable_insert(upb_inttable* t, uintptr_t key, upb_value val, - upb_Arena* a) { - upb_tabval tabval; - tabval.val = val.val; - UPB_ASSERT( - upb_arrhas(tabval)); /* This will reject (uint64_t)-1. Fix this. */ +static char* jsondec_partialbase64(jsondec* d, const char* ptr, const char* end, + char* out) { + int32_t val = -1; - if (key < t->array_size) { - UPB_ASSERT(!upb_arrhas(t->array[key])); - t->array_count++; - mutable_array(t)[key].val = val.val; - } else { - if (isfull(&t->t)) { - /* Need to resize the hash part, but we re-use the array part. */ - size_t i; - upb_table new_table; + switch (end - ptr) { + case 2: + val = jsondec_base64_tablelookup(ptr[0]) << 18 | + jsondec_base64_tablelookup(ptr[1]) << 12; + out[0] = val >> 16; + out += 1; + break; + case 3: + val = jsondec_base64_tablelookup(ptr[0]) << 18 | + jsondec_base64_tablelookup(ptr[1]) << 12 | + jsondec_base64_tablelookup(ptr[2]) << 6; + out[0] = val >> 16; + out[1] = (val >> 8) & 0xff; + out += 2; + break; + } - if (!init(&new_table, t->t.size_lg2 + 1, a)) { - return false; - } + if (val < 0) { + jsondec_err(d, "Corrupt base64"); + } - for (i = begin(&t->t); i < upb_table_size(&t->t); i = next(&t->t, i)) { - const upb_tabent* e = &t->t.entries[i]; - uint32_t hash; - upb_value v; + return out; +} - _upb_value_setval(&v, e->val.val); - hash = upb_inthash(e->key); - insert(&new_table, intkey(e->key), e->key, v, hash, &inthash, &inteql); - } +static size_t jsondec_base64(jsondec* d, upb_StringView str) { + /* We decode in place. This is safe because this is a new buffer (not + * aliasing the input) and because base64 decoding shrinks 4 bytes into 3. */ + char* out = (char*)str.data; + const char* ptr = str.data; + const char* end = ptr + str.size; + const char* end4 = ptr + (str.size & -4); /* Round down to multiple of 4. */ - UPB_ASSERT(t->t.count == new_table.count); + for (; ptr < end4; ptr += 4, out += 3) { + int val = jsondec_base64_tablelookup(ptr[0]) << 18 | + jsondec_base64_tablelookup(ptr[1]) << 12 | + jsondec_base64_tablelookup(ptr[2]) << 6 | + jsondec_base64_tablelookup(ptr[3]) << 0; - t->t = new_table; + if (val < 0) { + /* Junk chars or padding. Remove trailing padding, if any. */ + if (end - ptr == 4 && ptr[3] == '=') { + if (ptr[2] == '=') { + end -= 2; + } else { + end -= 1; + } + } + break; } - insert(&t->t, intkey(key), key, val, upb_inthash(key), &inthash, &inteql); + + out[0] = val >> 16; + out[1] = (val >> 8) & 0xff; + out[2] = val & 0xff; } - check(t); - return true; -} -bool upb_inttable_lookup(const upb_inttable* t, uintptr_t key, upb_value* v) { - const upb_tabval* table_v = inttable_val_const(t, key); - if (!table_v) return false; - if (v) _upb_value_setval(v, table_v->val); - return true; + if (ptr < end) { + /* Process remaining chars. We do not require padding. */ + out = jsondec_partialbase64(d, ptr, end, out); + } + + return out - str.data; } -bool upb_inttable_replace(upb_inttable* t, uintptr_t key, upb_value val) { - upb_tabval* table_v = inttable_val(t, key); - if (!table_v) return false; - table_v->val = val.val; - return true; +/* Low-level integer parsing **************************************************/ + +static const char* jsondec_buftouint64(jsondec* d, const char* ptr, + const char* end, uint64_t* val) { + const char* out = upb_BufToUint64(ptr, end, val); + if (!out) jsondec_err(d, "Integer overflow"); + return out; } -bool upb_inttable_remove(upb_inttable* t, uintptr_t key, upb_value* val) { - bool success; - if (key < t->array_size) { - if (upb_arrhas(t->array[key])) { - upb_tabval empty = UPB_TABVALUE_EMPTY_INIT; - t->array_count--; - if (val) { - _upb_value_setval(val, t->array[key].val); - } - mutable_array(t)[key] = empty; - success = true; - } else { - success = false; - } - } else { - success = rm(&t->t, intkey(key), val, NULL, upb_inthash(key), &inteql); - } - check(t); - return success; +static const char* jsondec_buftoint64(jsondec* d, const char* ptr, + const char* end, int64_t* val, + bool* is_neg) { + const char* out = upb_BufToInt64(ptr, end, val, is_neg); + if (!out) jsondec_err(d, "Integer overflow"); + return out; } -void upb_inttable_compact(upb_inttable* t, upb_Arena* a) { - /* A power-of-two histogram of the table keys. */ - size_t counts[UPB_MAXARRSIZE + 1] = {0}; - - /* The max key in each bucket. */ - uintptr_t max[UPB_MAXARRSIZE + 1] = {0}; - - { - intptr_t iter = UPB_INTTABLE_BEGIN; - uintptr_t key; - upb_value val; - while (upb_inttable_next(t, &key, &val, &iter)) { - int bucket = log2ceil(key); - max[bucket] = UPB_MAX(max[bucket], key); - counts[bucket]++; - } +static uint64_t jsondec_strtouint64(jsondec* d, upb_StringView str) { + const char* end = str.data + str.size; + uint64_t ret; + if (jsondec_buftouint64(d, str.data, end, &ret) != end) { + jsondec_err(d, "Non-number characters in quoted integer"); } + return ret; +} - /* Find the largest power of two that satisfies the MIN_DENSITY - * definition (while actually having some keys). */ - size_t arr_count = upb_inttable_count(t); - int size_lg2; - upb_inttable new_t; - - for (size_lg2 = ARRAY_SIZE(counts) - 1; size_lg2 > 0; size_lg2--) { - if (counts[size_lg2] == 0) { - /* We can halve again without losing any entries. */ - continue; - } else if (arr_count >= (1 << size_lg2) * MIN_DENSITY) { - break; - } - - arr_count -= counts[size_lg2]; +static int64_t jsondec_strtoint64(jsondec* d, upb_StringView str) { + const char* end = str.data + str.size; + int64_t ret; + if (jsondec_buftoint64(d, str.data, end, &ret, NULL) != end) { + jsondec_err(d, "Non-number characters in quoted integer"); } + return ret; +} - UPB_ASSERT(arr_count <= upb_inttable_count(t)); - - { - /* Insert all elements into new, perfectly-sized table. */ - size_t arr_size = max[size_lg2] + 1; /* +1 so arr[max] will fit. */ - size_t hash_count = upb_inttable_count(t) - arr_count; - size_t hash_size = hash_count ? (hash_count / MAX_LOAD) + 1 : 0; - int hashsize_lg2 = log2ceil(hash_size); +/* Primitive value types ******************************************************/ - upb_inttable_sizedinit(&new_t, arr_size, hashsize_lg2, a); +/* Parse INT32 or INT64 value. */ +static upb_MessageValue jsondec_int(jsondec* d, const upb_FieldDef* f) { + upb_MessageValue val; - { - intptr_t iter = UPB_INTTABLE_BEGIN; - uintptr_t key; - upb_value val; - while (upb_inttable_next(t, &key, &val, &iter)) { - upb_inttable_insert(&new_t, key, val, a); + switch (jsondec_peek(d)) { + case JD_NUMBER: { + double dbl = jsondec_number(d); + if (dbl > 9223372036854774784.0 || dbl < -9223372036854775808.0) { + jsondec_err(d, "JSON number is out of range."); } - } - - UPB_ASSERT(new_t.array_size == arr_size); - UPB_ASSERT(new_t.t.size_lg2 == hashsize_lg2); - } - *t = new_t; -} - -// Iteration. - -bool upb_inttable_next(const upb_inttable* t, uintptr_t* key, upb_value* val, - intptr_t* iter) { - intptr_t i = *iter; - if ((size_t)(i + 1) <= t->array_size) { - while ((size_t)++i < t->array_size) { - upb_tabval ent = t->array[i]; - if (upb_arrhas(ent)) { - *key = i; - *val = _upb_value_val(ent.val); - *iter = i; - return true; + val.int64_val = dbl; /* must be guarded, overflow here is UB */ + if (val.int64_val != dbl) { + jsondec_errf(d, "JSON number was not integral (%f != %" PRId64 ")", dbl, + val.int64_val); } + break; } - i--; // Back up to exactly one position before the start of the table. + case JD_STRING: { + upb_StringView str = jsondec_string(d); + val.int64_val = jsondec_strtoint64(d, str); + break; + } + default: + jsondec_err(d, "Expected number or string"); } - size_t tab_idx = next(&t->t, i - t->array_size); - if (tab_idx < upb_table_size(&t->t)) { - upb_tabent* ent = &t->t.entries[tab_idx]; - *key = ent->key; - *val = _upb_value_val(ent->val.val); - *iter = tab_idx + t->array_size; - return true; + if (upb_FieldDef_CType(f) == kUpb_CType_Int32 || + upb_FieldDef_CType(f) == kUpb_CType_Enum) { + if (val.int64_val > INT32_MAX || val.int64_val < INT32_MIN) { + jsondec_err(d, "Integer out of range."); + } + val.int32_val = (int32_t)val.int64_val; } - return false; + return val; } -void upb_inttable_removeiter(upb_inttable* t, intptr_t* iter) { - intptr_t i = *iter; - if ((size_t)i < t->array_size) { - t->array_count--; - mutable_array(t)[i].val = -1; - } else { - upb_tabent* ent = &t->t.entries[i - t->array_size]; - upb_tabent* prev = NULL; +/* Parse UINT32 or UINT64 value. */ +static upb_MessageValue jsondec_uint(jsondec* d, const upb_FieldDef* f) { + upb_MessageValue val = {0}; - // Linear search, not great. - upb_tabent* end = &t->t.entries[upb_table_size(&t->t)]; - for (upb_tabent* e = t->t.entries; e != end; e++) { - if (e->next == ent) { - prev = e; - break; + switch (jsondec_peek(d)) { + case JD_NUMBER: { + double dbl = jsondec_number(d); + if (dbl > 18446744073709549568.0 || dbl < 0) { + jsondec_err(d, "JSON number is out of range."); + } + val.uint64_val = dbl; /* must be guarded, overflow here is UB */ + if (val.uint64_val != dbl) { + jsondec_errf(d, "JSON number was not integral (%f != %" PRIu64 ")", dbl, + val.uint64_val); } + break; } - - if (prev) { - prev->next = ent->next; + case JD_STRING: { + upb_StringView str = jsondec_string(d); + val.uint64_val = jsondec_strtouint64(d, str); + break; } - - t->t.count--; - ent->key = 0; - ent->next = NULL; + default: + jsondec_err(d, "Expected number or string"); } -} -bool upb_strtable_next2(const upb_strtable* t, upb_StringView* key, - upb_value* val, intptr_t* iter) { - size_t tab_idx = next(&t->t, *iter); - if (tab_idx < upb_table_size(&t->t)) { - upb_tabent* ent = &t->t.entries[tab_idx]; - uint32_t len; - key->data = upb_tabstr(ent->key, &len); - key->size = len; - *val = _upb_value_val(ent->val.val); - *iter = tab_idx; - return true; + if (upb_FieldDef_CType(f) == kUpb_CType_UInt32) { + if (val.uint64_val > UINT32_MAX) { + jsondec_err(d, "Integer out of range."); + } + val.uint32_val = (uint32_t)val.uint64_val; } - return false; + return val; } -void upb_strtable_removeiter(upb_strtable* t, intptr_t* iter) { - intptr_t i = *iter; - upb_tabent* ent = &t->t.entries[i]; - upb_tabent* prev = NULL; +/* Parse DOUBLE or FLOAT value. */ +static upb_MessageValue jsondec_double(jsondec* d, const upb_FieldDef* f) { + upb_StringView str; + upb_MessageValue val = {0}; - // Linear search, not great. - upb_tabent* end = &t->t.entries[upb_table_size(&t->t)]; - for (upb_tabent* e = t->t.entries; e != end; e++) { - if (e->next == ent) { - prev = e; + switch (jsondec_peek(d)) { + case JD_NUMBER: + val.double_val = jsondec_number(d); break; - } + case JD_STRING: + str = jsondec_string(d); + if (jsondec_streql(str, "NaN")) { + val.double_val = NAN; + } else if (jsondec_streql(str, "Infinity")) { + val.double_val = INFINITY; + } else if (jsondec_streql(str, "-Infinity")) { + val.double_val = -INFINITY; + } else { + val.double_val = strtod(str.data, NULL); + } + break; + default: + jsondec_err(d, "Expected number or string"); } - if (prev) { - prev->next = ent->next; + if (upb_FieldDef_CType(f) == kUpb_CType_Float) { + float f = val.double_val; + if (val.double_val != INFINITY && val.double_val != -INFINITY) { + if (f == INFINITY || f == -INFINITY) jsondec_err(d, "Float out of range"); + } + val.float_val = f; } - t->t.count--; - ent->key = 0; - ent->next = NULL; + return val; } -void upb_strtable_setentryvalue(upb_strtable* t, intptr_t iter, upb_value v) { - upb_tabent* ent = &t->t.entries[iter]; - ent->val.val = v.val; +/* Parse STRING or BYTES value. */ +static upb_MessageValue jsondec_strfield(jsondec* d, const upb_FieldDef* f) { + upb_MessageValue val; + val.str_val = jsondec_string(d); + if (upb_FieldDef_CType(f) == kUpb_CType_Bytes) { + val.str_val.size = jsondec_base64(d, val.str_val); + } + return val; } +static upb_JsonMessageValue jsondec_enum(jsondec* d, const upb_FieldDef* f) { + switch (jsondec_peek(d)) { + case JD_STRING: { + upb_StringView str = jsondec_string(d); + const upb_EnumDef* e = upb_FieldDef_EnumSubDef(f); + const upb_EnumValueDef* ev = + upb_EnumDef_FindValueByNameWithSize(e, str.data, str.size); + upb_JsonMessageValue val = {.ignore = false}; + if (ev) { + val.value.int32_val = upb_EnumValueDef_Number(ev); + } else { + if (d->options & upb_JsonDecode_IgnoreUnknown) { + val.ignore = true; + } else { + jsondec_errf(d, "Unknown enumerator: '" UPB_STRINGVIEW_FORMAT "'", + UPB_STRINGVIEW_ARGS(str)); + } + } + return val; + } + case JD_NULL: { + if (jsondec_isnullvalue(f)) { + upb_JsonMessageValue val = {.ignore = false}; + jsondec_null(d); + val.value.int32_val = 0; + return val; + } + } + /* Fallthrough. */ + default: + return (upb_JsonMessageValue){.value = jsondec_int(d, f), + .ignore = false}; + } +} -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - - -// Must be last. +static upb_MessageValue jsondec_bool(jsondec* d, const upb_FieldDef* f) { + bool is_map_key = upb_FieldDef_Number(f) == 1 && + upb_MessageDef_IsMapEntry(upb_FieldDef_ContainingType(f)); + upb_MessageValue val; -typedef struct { - const char *ptr, *end; - upb_Arena* arena; /* TODO: should we have a tmp arena for tmp data? */ - const upb_DefPool* symtab; - int depth; - upb_Status* status; - jmp_buf err; - int line; - const char* line_begin; - bool is_first; - int options; - const upb_FieldDef* debug_field; -} jsondec; + if (is_map_key) { + upb_StringView str = jsondec_string(d); + if (jsondec_streql(str, "true")) { + val.bool_val = true; + } else if (jsondec_streql(str, "false")) { + val.bool_val = false; + } else { + jsondec_err(d, "Invalid boolean map key"); + } + } else { + switch (jsondec_peek(d)) { + case JD_TRUE: + val.bool_val = true; + jsondec_true(d); + break; + case JD_FALSE: + val.bool_val = false; + jsondec_false(d); + break; + default: + jsondec_err(d, "Expected true or false"); + } + } -typedef struct { - upb_MessageValue value; - bool ignore; -} upb_JsonMessageValue; + return val; +} -enum { JD_OBJECT, JD_ARRAY, JD_STRING, JD_NUMBER, JD_TRUE, JD_FALSE, JD_NULL }; +/* Composite types (array/message/map) ****************************************/ -/* Forward declarations of mutually-recursive functions. */ -static void jsondec_wellknown(jsondec* d, upb_Message* msg, - const upb_MessageDef* m); -static upb_JsonMessageValue jsondec_value(jsondec* d, const upb_FieldDef* f); -static void jsondec_wellknownvalue(jsondec* d, upb_Message* msg, - const upb_MessageDef* m); -static void jsondec_object(jsondec* d, upb_Message* msg, - const upb_MessageDef* m); +static void jsondec_array(jsondec* d, upb_Message* msg, const upb_FieldDef* f) { + upb_Array* arr = upb_Message_Mutable(msg, f, d->arena).array; -static bool jsondec_streql(upb_StringView str, const char* lit) { - return str.size == strlen(lit) && memcmp(str.data, lit, str.size) == 0; + jsondec_arrstart(d); + while (jsondec_arrnext(d)) { + upb_JsonMessageValue elem = jsondec_value(d, f); + if (!elem.ignore) { + upb_Array_Append(arr, elem.value, d->arena); + } + } + jsondec_arrend(d); } -static bool jsondec_isnullvalue(const upb_FieldDef* f) { - return upb_FieldDef_CType(f) == kUpb_CType_Enum && - strcmp(upb_EnumDef_FullName(upb_FieldDef_EnumSubDef(f)), - "google.protobuf.NullValue") == 0; -} +static void jsondec_map(jsondec* d, upb_Message* msg, const upb_FieldDef* f) { + upb_Map* map = upb_Message_Mutable(msg, f, d->arena).map; + const upb_MessageDef* entry = upb_FieldDef_MessageSubDef(f); + const upb_FieldDef* key_f = upb_MessageDef_FindFieldByNumber(entry, 1); + const upb_FieldDef* val_f = upb_MessageDef_FindFieldByNumber(entry, 2); -static bool jsondec_isvalue(const upb_FieldDef* f) { - return (upb_FieldDef_CType(f) == kUpb_CType_Message && - upb_MessageDef_WellKnownType(upb_FieldDef_MessageSubDef(f)) == - kUpb_WellKnown_Value) || - jsondec_isnullvalue(f); + jsondec_objstart(d); + while (jsondec_objnext(d)) { + upb_JsonMessageValue key, val; + key = jsondec_value(d, key_f); + UPB_ASSUME(!key.ignore); // Map key cannot be enum. + jsondec_entrysep(d); + val = jsondec_value(d, val_f); + if (!val.ignore) { + upb_Map_Set(map, key.value, val.value, d->arena); + } + } + jsondec_objend(d); } -static void jsondec_seterrmsg(jsondec* d, const char* msg) { - upb_Status_SetErrorFormat(d->status, "Error parsing JSON @%d:%d: %s", d->line, - (int)(d->ptr - d->line_begin), msg); +static void jsondec_tomsg(jsondec* d, upb_Message* msg, + const upb_MessageDef* m) { + if (upb_MessageDef_WellKnownType(m) == kUpb_WellKnown_Unspecified) { + jsondec_object(d, msg, m); + } else { + jsondec_wellknown(d, msg, m); + } } -UPB_NORETURN static void jsondec_err(jsondec* d, const char* msg) { - jsondec_seterrmsg(d, msg); - UPB_LONGJMP(d->err, 1); -} +static upb_MessageValue jsondec_msg(jsondec* d, const upb_FieldDef* f) { + const upb_MessageDef* m = upb_FieldDef_MessageSubDef(f); + const upb_MiniTable* layout = upb_MessageDef_MiniTable(m); + upb_Message* msg = upb_Message_New(layout, d->arena); + upb_MessageValue val; -UPB_PRINTF(2, 3) -UPB_NORETURN static void jsondec_errf(jsondec* d, const char* fmt, ...) { - va_list argp; - upb_Status_SetErrorFormat(d->status, "Error parsing JSON @%d:%d: ", d->line, - (int)(d->ptr - d->line_begin)); - va_start(argp, fmt); - upb_Status_VAppendErrorFormat(d->status, fmt, argp); - va_end(argp); - UPB_LONGJMP(d->err, 1); + jsondec_tomsg(d, msg, m); + val.msg_val = msg; + return val; } -// Advances d->ptr until the next non-whitespace character or to the end of -// the buffer. -static void jsondec_consumews(jsondec* d) { - while (d->ptr != d->end) { - switch (*d->ptr) { - case '\n': - d->line++; - d->line_begin = d->ptr; - /* Fallthrough. */ - case '\r': - case '\t': - case ' ': - d->ptr++; - break; - default: - return; +static void jsondec_field(jsondec* d, upb_Message* msg, + const upb_MessageDef* m) { + upb_StringView name; + const upb_FieldDef* f; + const upb_FieldDef* preserved; + + name = jsondec_string(d); + jsondec_entrysep(d); + + if (name.size >= 2 && name.data[0] == '[' && + name.data[name.size - 1] == ']') { + f = upb_DefPool_FindExtensionByNameWithSize(d->symtab, name.data + 1, + name.size - 2); + if (f && upb_FieldDef_ContainingType(f) != m) { + jsondec_errf( + d, "Extension %s extends message %s, but was seen in message %s", + upb_FieldDef_FullName(f), + upb_MessageDef_FullName(upb_FieldDef_ContainingType(f)), + upb_MessageDef_FullName(m)); } + } else { + f = upb_MessageDef_FindByJsonNameWithSize(m, name.data, name.size); } -} -// Advances d->ptr until the next non-whitespace character. Postcondition that -// d->ptr is pointing at a valid non-whitespace character (will err if end of -// buffer is reached). -static void jsondec_skipws(jsondec* d) { - jsondec_consumews(d); - if (d->ptr == d->end) { - jsondec_err(d, "Unexpected EOF"); + if (!f) { + if ((d->options & upb_JsonDecode_IgnoreUnknown) == 0) { + jsondec_errf(d, "No such field: " UPB_STRINGVIEW_FORMAT, + UPB_STRINGVIEW_ARGS(name)); + } + jsondec_skipval(d); + return; } -} - -static bool jsondec_tryparsech(jsondec* d, char ch) { - if (d->ptr == d->end || *d->ptr != ch) return false; - d->ptr++; - return true; -} -static void jsondec_parselit(jsondec* d, const char* lit) { - size_t avail = d->end - d->ptr; - size_t len = strlen(lit); - if (avail < len || memcmp(d->ptr, lit, len) != 0) { - jsondec_errf(d, "Expected: '%s'", lit); + if (jsondec_peek(d) == JD_NULL && !jsondec_isvalue(f)) { + /* JSON "null" indicates a default value, so no need to set anything. */ + jsondec_null(d); + return; } - d->ptr += len; -} -static void jsondec_wsch(jsondec* d, char ch) { - jsondec_skipws(d); - if (!jsondec_tryparsech(d, ch)) { - jsondec_errf(d, "Expected: '%c'", ch); + if (upb_FieldDef_RealContainingOneof(f) && + upb_Message_WhichOneof(msg, upb_FieldDef_ContainingOneof(f))) { + jsondec_err(d, "More than one field for this oneof."); } -} -static void jsondec_true(jsondec* d) { jsondec_parselit(d, "true"); } -static void jsondec_false(jsondec* d) { jsondec_parselit(d, "false"); } -static void jsondec_null(jsondec* d) { jsondec_parselit(d, "null"); } + preserved = d->debug_field; + d->debug_field = f; -static void jsondec_entrysep(jsondec* d) { - jsondec_skipws(d); - jsondec_parselit(d, ":"); + if (upb_FieldDef_IsMap(f)) { + jsondec_map(d, msg, f); + } else if (upb_FieldDef_IsRepeated(f)) { + jsondec_array(d, msg, f); + } else if (upb_FieldDef_IsSubMessage(f)) { + upb_Message* submsg = upb_Message_Mutable(msg, f, d->arena).msg; + const upb_MessageDef* subm = upb_FieldDef_MessageSubDef(f); + jsondec_tomsg(d, submsg, subm); + } else { + upb_JsonMessageValue val = jsondec_value(d, f); + if (!val.ignore) { + upb_Message_SetFieldByDef(msg, f, val.value, d->arena); + } + } + + d->debug_field = preserved; } -static int jsondec_rawpeek(jsondec* d) { - if (d->ptr == d->end) { - jsondec_err(d, "Unexpected EOF"); +static void jsondec_object(jsondec* d, upb_Message* msg, + const upb_MessageDef* m) { + jsondec_objstart(d); + while (jsondec_objnext(d)) { + jsondec_field(d, msg, m); } + jsondec_objend(d); +} - switch (*d->ptr) { - case '{': - return JD_OBJECT; - case '[': - return JD_ARRAY; - case '"': - return JD_STRING; - case '-': - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - return JD_NUMBER; - case 't': - return JD_TRUE; - case 'f': - return JD_FALSE; - case 'n': - return JD_NULL; +static upb_MessageValue jsondec_nonenum(jsondec* d, const upb_FieldDef* f) { + switch (upb_FieldDef_CType(f)) { + case kUpb_CType_Bool: + return jsondec_bool(d, f); + case kUpb_CType_Float: + case kUpb_CType_Double: + return jsondec_double(d, f); + case kUpb_CType_UInt32: + case kUpb_CType_UInt64: + return jsondec_uint(d, f); + case kUpb_CType_Int32: + case kUpb_CType_Int64: + return jsondec_int(d, f); + case kUpb_CType_String: + case kUpb_CType_Bytes: + return jsondec_strfield(d, f); + case kUpb_CType_Message: + return jsondec_msg(d, f); + case kUpb_CType_Enum: default: - jsondec_errf(d, "Unexpected character: '%c'", *d->ptr); + UPB_UNREACHABLE(); } } -/* JSON object/array **********************************************************/ +static upb_JsonMessageValue jsondec_value(jsondec* d, const upb_FieldDef* f) { + if (upb_FieldDef_CType(f) == kUpb_CType_Enum) { + return jsondec_enum(d, f); + } else { + return (upb_JsonMessageValue){.value = jsondec_nonenum(d, f), + .ignore = false}; + } +} -/* These are used like so: - * - * jsondec_objstart(d); - * while (jsondec_objnext(d)) { - * ... - * } - * jsondec_objend(d) */ +/* Well-known types ***********************************************************/ -static int jsondec_peek(jsondec* d) { - jsondec_skipws(d); - return jsondec_rawpeek(d); -} +static int jsondec_tsdigits(jsondec* d, const char** ptr, size_t digits, + const char* after) { + uint64_t val; + const char* p = *ptr; + const char* end = p + digits; + size_t after_len = after ? strlen(after) : 0; -static void jsondec_push(jsondec* d) { - if (--d->depth < 0) { - jsondec_err(d, "Recursion limit exceeded"); + UPB_ASSERT(digits <= 9); /* int can't overflow. */ + + if (jsondec_buftouint64(d, p, end, &val) != end || + (after_len && memcmp(end, after, after_len) != 0)) { + jsondec_err(d, "Malformed timestamp"); } - d->is_first = true; -} -static bool jsondec_seqnext(jsondec* d, char end_ch) { - bool is_first = d->is_first; - d->is_first = false; - jsondec_skipws(d); - if (*d->ptr == end_ch) return false; - if (!is_first) jsondec_parselit(d, ","); - return true; -} + UPB_ASSERT(val < INT_MAX); -static void jsondec_arrstart(jsondec* d) { - jsondec_push(d); - jsondec_wsch(d, '['); + *ptr = end + after_len; + return (int)val; } -static void jsondec_arrend(jsondec* d) { - d->depth++; - jsondec_wsch(d, ']'); -} +static int jsondec_nanos(jsondec* d, const char** ptr, const char* end) { + uint64_t nanos = 0; + const char* p = *ptr; -static bool jsondec_arrnext(jsondec* d) { return jsondec_seqnext(d, ']'); } + if (p != end && *p == '.') { + const char* nano_end = jsondec_buftouint64(d, p + 1, end, &nanos); + int digits = (int)(nano_end - p - 1); + int exp_lg10 = 9 - digits; + if (digits > 9) { + jsondec_err(d, "Too many digits for partial seconds"); + } + while (exp_lg10--) nanos *= 10; + *ptr = nano_end; + } -static void jsondec_objstart(jsondec* d) { - jsondec_push(d); - jsondec_wsch(d, '{'); -} + UPB_ASSERT(nanos < INT_MAX); -static void jsondec_objend(jsondec* d) { - d->depth++; - jsondec_wsch(d, '}'); + return (int)nanos; } -static bool jsondec_objnext(jsondec* d) { - if (!jsondec_seqnext(d, '}')) return false; - if (jsondec_peek(d) != JD_STRING) { - jsondec_err(d, "Object must start with string"); - } - return true; +/* jsondec_epochdays(1970, 1, 1) == 1970-01-01 == 0. */ +int jsondec_epochdays(int y, int m, int d) { + const uint32_t year_base = 4800; /* Before min year, multiple of 400. */ + const uint32_t m_adj = m - 3; /* March-based month. */ + const uint32_t carry = m_adj > (uint32_t)m ? 1 : 0; + const uint32_t adjust = carry ? 12 : 0; + const uint32_t y_adj = y + year_base - carry; + const uint32_t month_days = ((m_adj + adjust) * 62719 + 769) / 2048; + const uint32_t leap_days = y_adj / 4 - y_adj / 100 + y_adj / 400; + return y_adj * 365 + leap_days + month_days + (d - 1) - 2472632; } -/* JSON number ****************************************************************/ +static int64_t jsondec_unixtime(int y, int m, int d, int h, int min, int s) { + return (int64_t)jsondec_epochdays(y, m, d) * 86400 + h * 3600 + min * 60 + s; +} -static bool jsondec_tryskipdigits(jsondec* d) { - const char* start = d->ptr; +static void jsondec_timestamp(jsondec* d, upb_Message* msg, + const upb_MessageDef* m) { + upb_MessageValue seconds; + upb_MessageValue nanos; + upb_StringView str = jsondec_string(d); + const char* ptr = str.data; + const char* end = ptr + str.size; - while (d->ptr < d->end) { - if (*d->ptr < '0' || *d->ptr > '9') { - break; - } - d->ptr++; - } + if (str.size < 20) goto malformed; - return d->ptr != start; -} + { + /* 1972-01-01T01:00:00 */ + int year = jsondec_tsdigits(d, &ptr, 4, "-"); + int mon = jsondec_tsdigits(d, &ptr, 2, "-"); + int day = jsondec_tsdigits(d, &ptr, 2, "T"); + int hour = jsondec_tsdigits(d, &ptr, 2, ":"); + int min = jsondec_tsdigits(d, &ptr, 2, ":"); + int sec = jsondec_tsdigits(d, &ptr, 2, NULL); -static void jsondec_skipdigits(jsondec* d) { - if (!jsondec_tryskipdigits(d)) { - jsondec_err(d, "Expected one or more digits"); + seconds.int64_val = jsondec_unixtime(year, mon, day, hour, min, sec); } -} -static double jsondec_number(jsondec* d) { - const char* start = d->ptr; + nanos.int32_val = jsondec_nanos(d, &ptr, end); - UPB_ASSERT(jsondec_rawpeek(d) == JD_NUMBER); + { + /* [+-]08:00 or Z */ + int ofs_hour = 0; + int ofs_min = 0; + bool neg = false; - /* Skip over the syntax of a number, as specified by JSON. */ - if (*d->ptr == '-') d->ptr++; + if (ptr == end) goto malformed; - if (jsondec_tryparsech(d, '0')) { - if (jsondec_tryskipdigits(d)) { - jsondec_err(d, "number cannot have leading zero"); + switch (*ptr++) { + case '-': + neg = true; + /* fallthrough */ + case '+': + if ((end - ptr) != 5) goto malformed; + ofs_hour = jsondec_tsdigits(d, &ptr, 2, ":"); + ofs_min = jsondec_tsdigits(d, &ptr, 2, NULL); + ofs_min = ((ofs_hour * 60) + ofs_min) * 60; + seconds.int64_val += (neg ? ofs_min : -ofs_min); + break; + case 'Z': + if (ptr != end) goto malformed; + break; + default: + goto malformed; } - } else { - jsondec_skipdigits(d); - } - - if (d->ptr == d->end) goto parse; - if (jsondec_tryparsech(d, '.')) { - jsondec_skipdigits(d); } - if (d->ptr == d->end) goto parse; - if (*d->ptr == 'e' || *d->ptr == 'E') { - d->ptr++; - if (d->ptr == d->end) { - jsondec_err(d, "Unexpected EOF in number"); - } - if (*d->ptr == '+' || *d->ptr == '-') { - d->ptr++; - } - jsondec_skipdigits(d); + if (seconds.int64_val < -62135596800) { + jsondec_err(d, "Timestamp out of range"); } -parse: - /* Having verified the syntax of a JSON number, use strtod() to parse - * (strtod() accepts a superset of JSON syntax). */ - errno = 0; - { - // Copy the number into a null-terminated scratch buffer since strtod - // expects a null-terminated string. - char nullz[64]; - ptrdiff_t len = d->ptr - start; - if (len > (ptrdiff_t)(sizeof(nullz) - 1)) { - jsondec_err(d, "excessively long number"); - } - memcpy(nullz, start, len); - nullz[len] = '\0'; - - char* end; - double val = strtod(nullz, &end); - UPB_ASSERT(end - nullz == len); - - /* Currently the min/max-val conformance tests fail if we check this. Does - * this mean the conformance tests are wrong or strtod() is wrong, or - * something else? Investigate further. */ - /* - if (errno == ERANGE) { - jsondec_err(d, "Number out of range"); - } - */ - - if (val > DBL_MAX || val < -DBL_MAX) { - jsondec_err(d, "Number out of range"); - } + upb_Message_SetFieldByDef(msg, upb_MessageDef_FindFieldByNumber(m, 1), + seconds, d->arena); + upb_Message_SetFieldByDef(msg, upb_MessageDef_FindFieldByNumber(m, 2), nanos, + d->arena); + return; - return val; - } +malformed: + jsondec_err(d, "Malformed timestamp"); } -/* JSON string ****************************************************************/ - -static char jsondec_escape(jsondec* d) { - switch (*d->ptr++) { - case '"': - return '\"'; - case '\\': - return '\\'; - case '/': - return '/'; - case 'b': - return '\b'; - case 'f': - return '\f'; - case 'n': - return '\n'; - case 'r': - return '\r'; - case 't': - return '\t'; - default: - jsondec_err(d, "Invalid escape char"); - } -} +static void jsondec_duration(jsondec* d, upb_Message* msg, + const upb_MessageDef* m) { + upb_MessageValue seconds; + upb_MessageValue nanos; + upb_StringView str = jsondec_string(d); + const char* ptr = str.data; + const char* end = ptr + str.size; + const int64_t max = (uint64_t)3652500 * 86400; + bool neg = false; -static uint32_t jsondec_codepoint(jsondec* d) { - uint32_t cp = 0; - const char* end; + /* "3.000000001s", "3s", etc. */ + ptr = jsondec_buftoint64(d, ptr, end, &seconds.int64_val, &neg); + nanos.int32_val = jsondec_nanos(d, &ptr, end); - if (d->end - d->ptr < 4) { - jsondec_err(d, "EOF inside string"); + if (end - ptr != 1 || *ptr != 's') { + jsondec_err(d, "Malformed duration"); } - end = d->ptr + 4; - while (d->ptr < end) { - char ch = *d->ptr++; - if (ch >= '0' && ch <= '9') { - ch -= '0'; - } else if (ch >= 'a' && ch <= 'f') { - ch = ch - 'a' + 10; - } else if (ch >= 'A' && ch <= 'F') { - ch = ch - 'A' + 10; - } else { - jsondec_err(d, "Invalid hex digit"); - } - cp = (cp << 4) | ch; + if (seconds.int64_val < -max || seconds.int64_val > max) { + jsondec_err(d, "Duration out of range"); } - return cp; -} - -/* Parses a \uXXXX unicode escape (possibly a surrogate pair). */ -static size_t jsondec_unicode(jsondec* d, char* out) { - uint32_t cp = jsondec_codepoint(d); - if (upb_Unicode_IsHigh(cp)) { - /* Surrogate pair: two 16-bit codepoints become a 32-bit codepoint. */ - jsondec_parselit(d, "\\u"); - uint32_t low = jsondec_codepoint(d); - if (!upb_Unicode_IsLow(low)) jsondec_err(d, "Invalid low surrogate"); - cp = upb_Unicode_FromPair(cp, low); - } else if (upb_Unicode_IsLow(cp)) { - jsondec_err(d, "Unpaired low surrogate"); + if (neg) { + nanos.int32_val = -nanos.int32_val; } - /* Write to UTF-8 */ - int bytes = upb_Unicode_ToUTF8(cp, out); - if (bytes == 0) jsondec_err(d, "Invalid codepoint"); - return bytes; -} - -static void jsondec_resize(jsondec* d, char** buf, char** end, char** buf_end) { - size_t oldsize = *buf_end - *buf; - size_t len = *end - *buf; - size_t size = UPB_MAX(8, 2 * oldsize); - - *buf = upb_Arena_Realloc(d->arena, *buf, len, size); - if (!*buf) jsondec_err(d, "Out of memory"); - - *end = *buf + len; - *buf_end = *buf + size; + upb_Message_SetFieldByDef(msg, upb_MessageDef_FindFieldByNumber(m, 1), + seconds, d->arena); + upb_Message_SetFieldByDef(msg, upb_MessageDef_FindFieldByNumber(m, 2), nanos, + d->arena); } -static upb_StringView jsondec_string(jsondec* d) { - char* buf = NULL; - char* end = NULL; - char* buf_end = NULL; - - jsondec_skipws(d); +static void jsondec_listvalue(jsondec* d, upb_Message* msg, + const upb_MessageDef* m) { + const upb_FieldDef* values_f = upb_MessageDef_FindFieldByNumber(m, 1); + const upb_MessageDef* value_m = upb_FieldDef_MessageSubDef(values_f); + const upb_MiniTable* value_layout = upb_MessageDef_MiniTable(value_m); + upb_Array* values = upb_Message_Mutable(msg, values_f, d->arena).array; - if (*d->ptr++ != '"') { - jsondec_err(d, "Expected string"); + jsondec_arrstart(d); + while (jsondec_arrnext(d)) { + upb_Message* value_msg = upb_Message_New(value_layout, d->arena); + upb_MessageValue value; + value.msg_val = value_msg; + upb_Array_Append(values, value, d->arena); + jsondec_wellknownvalue(d, value_msg, value_m); } + jsondec_arrend(d); +} - while (d->ptr < d->end) { - char ch = *d->ptr++; - - if (end == buf_end) { - jsondec_resize(d, &buf, &end, &buf_end); - } +static void jsondec_struct(jsondec* d, upb_Message* msg, + const upb_MessageDef* m) { + const upb_FieldDef* fields_f = upb_MessageDef_FindFieldByNumber(m, 1); + const upb_MessageDef* entry_m = upb_FieldDef_MessageSubDef(fields_f); + const upb_FieldDef* value_f = upb_MessageDef_FindFieldByNumber(entry_m, 2); + const upb_MessageDef* value_m = upb_FieldDef_MessageSubDef(value_f); + const upb_MiniTable* value_layout = upb_MessageDef_MiniTable(value_m); + upb_Map* fields = upb_Message_Mutable(msg, fields_f, d->arena).map; - switch (ch) { - case '"': { - upb_StringView ret; - ret.data = buf; - ret.size = end - buf; - *end = '\0'; /* Needed for possible strtod(). */ - return ret; - } - case '\\': - if (d->ptr == d->end) goto eof; - if (*d->ptr == 'u') { - d->ptr++; - if (buf_end - end < 4) { - /* Allow space for maximum-sized codepoint (4 bytes). */ - jsondec_resize(d, &buf, &end, &buf_end); - } - end += jsondec_unicode(d, end); - } else { - *end++ = jsondec_escape(d); - } - break; - default: - if ((unsigned char)ch < 0x20) { - jsondec_err(d, "Invalid char in JSON string"); - } - *end++ = ch; - break; - } + jsondec_objstart(d); + while (jsondec_objnext(d)) { + upb_MessageValue key, value; + upb_Message* value_msg = upb_Message_New(value_layout, d->arena); + key.str_val = jsondec_string(d); + value.msg_val = value_msg; + upb_Map_Set(fields, key, value, d->arena); + jsondec_entrysep(d); + jsondec_wellknownvalue(d, value_msg, value_m); } - -eof: - jsondec_err(d, "EOF inside string"); + jsondec_objend(d); } -static void jsondec_skipval(jsondec* d) { +static void jsondec_wellknownvalue(jsondec* d, upb_Message* msg, + const upb_MessageDef* m) { + upb_MessageValue val; + const upb_FieldDef* f; + upb_Message* submsg; + switch (jsondec_peek(d)) { - case JD_OBJECT: - jsondec_objstart(d); - while (jsondec_objnext(d)) { - jsondec_string(d); - jsondec_entrysep(d); - jsondec_skipval(d); - } - jsondec_objend(d); - break; - case JD_ARRAY: - jsondec_arrstart(d); - while (jsondec_arrnext(d)) { - jsondec_skipval(d); - } - jsondec_arrend(d); + case JD_NUMBER: + /* double number_value = 2; */ + f = upb_MessageDef_FindFieldByNumber(m, 2); + val.double_val = jsondec_number(d); break; - case JD_TRUE: - jsondec_true(d); + case JD_STRING: + /* string string_value = 3; */ + f = upb_MessageDef_FindFieldByNumber(m, 3); + val.str_val = jsondec_string(d); break; case JD_FALSE: + /* bool bool_value = 4; */ + f = upb_MessageDef_FindFieldByNumber(m, 4); + val.bool_val = false; jsondec_false(d); break; + case JD_TRUE: + /* bool bool_value = 4; */ + f = upb_MessageDef_FindFieldByNumber(m, 4); + val.bool_val = true; + jsondec_true(d); + break; case JD_NULL: + /* NullValue null_value = 1; */ + f = upb_MessageDef_FindFieldByNumber(m, 1); + val.int32_val = 0; jsondec_null(d); break; - case JD_STRING: - jsondec_string(d); - break; - case JD_NUMBER: - jsondec_number(d); - break; + /* Note: these cases return, because upb_Message_Mutable() is enough. */ + case JD_OBJECT: + /* Struct struct_value = 5; */ + f = upb_MessageDef_FindFieldByNumber(m, 5); + submsg = upb_Message_Mutable(msg, f, d->arena).msg; + jsondec_struct(d, submsg, upb_FieldDef_MessageSubDef(f)); + return; + case JD_ARRAY: + /* ListValue list_value = 6; */ + f = upb_MessageDef_FindFieldByNumber(m, 6); + submsg = upb_Message_Mutable(msg, f, d->arena).msg; + jsondec_listvalue(d, submsg, upb_FieldDef_MessageSubDef(f)); + return; + default: + UPB_UNREACHABLE(); } -} - -/* Base64 decoding for bytes fields. ******************************************/ - -static unsigned int jsondec_base64_tablelookup(const char ch) { - /* Table includes the normal base64 chars plus the URL-safe variant. */ - const signed char table[256] = { - -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, - -1, 62 /*+*/, -1, 62 /*-*/, -1, 63 /*/ */, 52 /*0*/, - 53 /*1*/, 54 /*2*/, 55 /*3*/, 56 /*4*/, 57 /*5*/, 58 /*6*/, 59 /*7*/, - 60 /*8*/, 61 /*9*/, -1, -1, -1, -1, -1, - -1, -1, 0 /*A*/, 1 /*B*/, 2 /*C*/, 3 /*D*/, 4 /*E*/, - 5 /*F*/, 6 /*G*/, 07 /*H*/, 8 /*I*/, 9 /*J*/, 10 /*K*/, 11 /*L*/, - 12 /*M*/, 13 /*N*/, 14 /*O*/, 15 /*P*/, 16 /*Q*/, 17 /*R*/, 18 /*S*/, - 19 /*T*/, 20 /*U*/, 21 /*V*/, 22 /*W*/, 23 /*X*/, 24 /*Y*/, 25 /*Z*/, - -1, -1, -1, -1, 63 /*_*/, -1, 26 /*a*/, - 27 /*b*/, 28 /*c*/, 29 /*d*/, 30 /*e*/, 31 /*f*/, 32 /*g*/, 33 /*h*/, - 34 /*i*/, 35 /*j*/, 36 /*k*/, 37 /*l*/, 38 /*m*/, 39 /*n*/, 40 /*o*/, - 41 /*p*/, 42 /*q*/, 43 /*r*/, 44 /*s*/, 45 /*t*/, 46 /*u*/, 47 /*v*/, - 48 /*w*/, 49 /*x*/, 50 /*y*/, 51 /*z*/, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1}; - /* Sign-extend return value so high bit will be set on any unexpected char. */ - return table[(unsigned)ch]; + upb_Message_SetFieldByDef(msg, f, val, d->arena); } -static char* jsondec_partialbase64(jsondec* d, const char* ptr, const char* end, - char* out) { - int32_t val = -1; +static upb_StringView jsondec_mask(jsondec* d, const char* buf, + const char* end) { + /* FieldMask fields grow due to inserted '_' characters, so we can't do the + * transform in place. */ + const char* ptr = buf; + upb_StringView ret; + char* out; - switch (end - ptr) { - case 2: - val = jsondec_base64_tablelookup(ptr[0]) << 18 | - jsondec_base64_tablelookup(ptr[1]) << 12; - out[0] = val >> 16; - out += 1; - break; - case 3: - val = jsondec_base64_tablelookup(ptr[0]) << 18 | - jsondec_base64_tablelookup(ptr[1]) << 12 | - jsondec_base64_tablelookup(ptr[2]) << 6; - out[0] = val >> 16; - out[1] = (val >> 8) & 0xff; - out += 2; - break; + ret.size = end - ptr; + while (ptr < end) { + ret.size += (*ptr >= 'A' && *ptr <= 'Z'); + ptr++; } - if (val < 0) { - jsondec_err(d, "Corrupt base64"); + out = upb_Arena_Malloc(d->arena, ret.size); + ptr = buf; + ret.data = out; + + while (ptr < end) { + char ch = *ptr++; + if (ch >= 'A' && ch <= 'Z') { + *out++ = '_'; + *out++ = ch + 32; + } else if (ch == '_') { + jsondec_err(d, "field mask may not contain '_'"); + } else { + *out++ = ch; + } } - return out; + return ret; } -static size_t jsondec_base64(jsondec* d, upb_StringView str) { - /* We decode in place. This is safe because this is a new buffer (not - * aliasing the input) and because base64 decoding shrinks 4 bytes into 3. */ - char* out = (char*)str.data; +static void jsondec_fieldmask(jsondec* d, upb_Message* msg, + const upb_MessageDef* m) { + /* repeated string paths = 1; */ + const upb_FieldDef* paths_f = upb_MessageDef_FindFieldByNumber(m, 1); + upb_Array* arr = upb_Message_Mutable(msg, paths_f, d->arena).array; + upb_StringView str = jsondec_string(d); const char* ptr = str.data; const char* end = ptr + str.size; - const char* end4 = ptr + (str.size & -4); /* Round down to multiple of 4. */ - - for (; ptr < end4; ptr += 4, out += 3) { - int val = jsondec_base64_tablelookup(ptr[0]) << 18 | - jsondec_base64_tablelookup(ptr[1]) << 12 | - jsondec_base64_tablelookup(ptr[2]) << 6 | - jsondec_base64_tablelookup(ptr[3]) << 0; + upb_MessageValue val; - if (val < 0) { - /* Junk chars or padding. Remove trailing padding, if any. */ - if (end - ptr == 4 && ptr[3] == '=') { - if (ptr[2] == '=') { - end -= 2; - } else { - end -= 1; - } - } - break; + while (ptr < end) { + const char* elem_end = memchr(ptr, ',', end - ptr); + if (elem_end) { + val.str_val = jsondec_mask(d, ptr, elem_end); + ptr = elem_end + 1; + } else { + val.str_val = jsondec_mask(d, ptr, end); + ptr = end; } - - out[0] = val >> 16; - out[1] = (val >> 8) & 0xff; - out[2] = val & 0xff; + upb_Array_Append(arr, val, d->arena); } +} - if (ptr < end) { - /* Process remaining chars. We do not require padding. */ - out = jsondec_partialbase64(d, ptr, end, out); +static void jsondec_anyfield(jsondec* d, upb_Message* msg, + const upb_MessageDef* m) { + if (upb_MessageDef_WellKnownType(m) == kUpb_WellKnown_Unspecified) { + /* For regular types: {"@type": "[user type]", "f1": , "f2": } + * where f1, f2, etc. are the normal fields of this type. */ + jsondec_field(d, msg, m); + } else { + /* For well-known types: {"@type": "[well-known type]", "value": } + * where is whatever encoding the WKT normally uses. */ + upb_StringView str = jsondec_string(d); + jsondec_entrysep(d); + if (!jsondec_streql(str, "value")) { + jsondec_err(d, "Key for well-known type must be 'value'"); + } + jsondec_wellknown(d, msg, m); } - - return out - str.data; } -/* Low-level integer parsing **************************************************/ +static const upb_MessageDef* jsondec_typeurl(jsondec* d, upb_Message* msg, + const upb_MessageDef* m) { + const upb_FieldDef* type_url_f = upb_MessageDef_FindFieldByNumber(m, 1); + const upb_MessageDef* type_m; + upb_StringView type_url = jsondec_string(d); + const char* end = type_url.data + type_url.size; + const char* ptr = end; + upb_MessageValue val; -static const char* jsondec_buftouint64(jsondec* d, const char* ptr, - const char* end, uint64_t* val) { - const char* out = upb_BufToUint64(ptr, end, val); - if (!out) jsondec_err(d, "Integer overflow"); - return out; -} + val.str_val = type_url; + upb_Message_SetFieldByDef(msg, type_url_f, val, d->arena); -static const char* jsondec_buftoint64(jsondec* d, const char* ptr, - const char* end, int64_t* val, - bool* is_neg) { - const char* out = upb_BufToInt64(ptr, end, val, is_neg); - if (!out) jsondec_err(d, "Integer overflow"); - return out; -} + /* Find message name after the last '/' */ + while (ptr > type_url.data && *--ptr != '/') { + } -static uint64_t jsondec_strtouint64(jsondec* d, upb_StringView str) { - const char* end = str.data + str.size; - uint64_t ret; - if (jsondec_buftouint64(d, str.data, end, &ret) != end) { - jsondec_err(d, "Non-number characters in quoted integer"); + if (ptr == type_url.data || ptr == end) { + jsondec_err(d, "Type url must have at least one '/' and non-empty host"); } - return ret; -} -static int64_t jsondec_strtoint64(jsondec* d, upb_StringView str) { - const char* end = str.data + str.size; - int64_t ret; - if (jsondec_buftoint64(d, str.data, end, &ret, NULL) != end) { - jsondec_err(d, "Non-number characters in quoted integer"); + ptr++; + type_m = upb_DefPool_FindMessageByNameWithSize(d->symtab, ptr, end - ptr); + + if (!type_m) { + jsondec_err(d, "Type was not found"); } - return ret; + + return type_m; } -/* Primitive value types ******************************************************/ +static void jsondec_any(jsondec* d, upb_Message* msg, const upb_MessageDef* m) { + /* string type_url = 1; + * bytes value = 2; */ + const upb_FieldDef* value_f = upb_MessageDef_FindFieldByNumber(m, 2); + upb_Message* any_msg; + const upb_MessageDef* any_m = NULL; + const char* pre_type_data = NULL; + const char* pre_type_end = NULL; + upb_MessageValue encoded; -/* Parse INT32 or INT64 value. */ -static upb_MessageValue jsondec_int(jsondec* d, const upb_FieldDef* f) { - upb_MessageValue val; + jsondec_objstart(d); - switch (jsondec_peek(d)) { - case JD_NUMBER: { - double dbl = jsondec_number(d); - if (dbl > 9223372036854774784.0 || dbl < -9223372036854775808.0) { - jsondec_err(d, "JSON number is out of range."); + /* Scan looking for "@type", which is not necessarily first. */ + while (!any_m && jsondec_objnext(d)) { + const char* start = d->ptr; + upb_StringView name = jsondec_string(d); + jsondec_entrysep(d); + if (jsondec_streql(name, "@type")) { + any_m = jsondec_typeurl(d, msg, m); + if (pre_type_data) { + pre_type_end = start; + while (*pre_type_end != ',') pre_type_end--; } - val.int64_val = dbl; /* must be guarded, overflow here is UB */ - if (val.int64_val != dbl) { - jsondec_errf(d, "JSON number was not integral (%f != %" PRId64 ")", dbl, - val.int64_val); - } - break; - } - case JD_STRING: { - upb_StringView str = jsondec_string(d); - val.int64_val = jsondec_strtoint64(d, str); - break; + } else { + if (!pre_type_data) pre_type_data = start; + jsondec_skipval(d); } - default: - jsondec_err(d, "Expected number or string"); } - if (upb_FieldDef_CType(f) == kUpb_CType_Int32 || - upb_FieldDef_CType(f) == kUpb_CType_Enum) { - if (val.int64_val > INT32_MAX || val.int64_val < INT32_MIN) { - jsondec_err(d, "Integer out of range."); - } - val.int32_val = (int32_t)val.int64_val; + if (!any_m) { + jsondec_err(d, "Any object didn't contain a '@type' field"); } - return val; -} - -/* Parse UINT32 or UINT64 value. */ -static upb_MessageValue jsondec_uint(jsondec* d, const upb_FieldDef* f) { - upb_MessageValue val = {0}; + const upb_MiniTable* any_layout = upb_MessageDef_MiniTable(any_m); + any_msg = upb_Message_New(any_layout, d->arena); - switch (jsondec_peek(d)) { - case JD_NUMBER: { - double dbl = jsondec_number(d); - if (dbl > 18446744073709549568.0 || dbl < 0) { - jsondec_err(d, "JSON number is out of range."); - } - val.uint64_val = dbl; /* must be guarded, overflow here is UB */ - if (val.uint64_val != dbl) { - jsondec_errf(d, "JSON number was not integral (%f != %" PRIu64 ")", dbl, - val.uint64_val); - } - break; - } - case JD_STRING: { - upb_StringView str = jsondec_string(d); - val.uint64_val = jsondec_strtouint64(d, str); - break; + if (pre_type_data) { + size_t len = pre_type_end - pre_type_data + 1; + char* tmp = upb_Arena_Malloc(d->arena, len); + const char* saved_ptr = d->ptr; + const char* saved_end = d->end; + memcpy(tmp, pre_type_data, len - 1); + tmp[len - 1] = '}'; + d->ptr = tmp; + d->end = tmp + len; + d->is_first = true; + while (jsondec_objnext(d)) { + jsondec_anyfield(d, any_msg, any_m); } - default: - jsondec_err(d, "Expected number or string"); + d->ptr = saved_ptr; + d->end = saved_end; } - if (upb_FieldDef_CType(f) == kUpb_CType_UInt32) { - if (val.uint64_val > UINT32_MAX) { - jsondec_err(d, "Integer out of range."); - } - val.uint32_val = (uint32_t)val.uint64_val; + while (jsondec_objnext(d)) { + jsondec_anyfield(d, any_msg, any_m); } - return val; + jsondec_objend(d); + + upb_EncodeStatus status = + upb_Encode(any_msg, upb_MessageDef_MiniTable(any_m), 0, d->arena, + (char**)&encoded.str_val.data, &encoded.str_val.size); + // TODO: We should fail gracefully here on a bad return status. + UPB_ASSERT(status == kUpb_EncodeStatus_Ok); + upb_Message_SetFieldByDef(msg, value_f, encoded, d->arena); } -/* Parse DOUBLE or FLOAT value. */ -static upb_MessageValue jsondec_double(jsondec* d, const upb_FieldDef* f) { - upb_StringView str; - upb_MessageValue val = {0}; +static void jsondec_wrapper(jsondec* d, upb_Message* msg, + const upb_MessageDef* m) { + const upb_FieldDef* value_f = upb_MessageDef_FindFieldByNumber(m, 1); + upb_JsonMessageValue val = jsondec_value(d, value_f); + UPB_ASSUME(val.ignore == false); // Wrapper cannot be an enum. + upb_Message_SetFieldByDef(msg, value_f, val.value, d->arena); +} - switch (jsondec_peek(d)) { - case JD_NUMBER: - val.double_val = jsondec_number(d); +static void jsondec_wellknown(jsondec* d, upb_Message* msg, + const upb_MessageDef* m) { + switch (upb_MessageDef_WellKnownType(m)) { + case kUpb_WellKnown_Any: + jsondec_any(d, msg, m); break; - case JD_STRING: - str = jsondec_string(d); - if (jsondec_streql(str, "NaN")) { - val.double_val = NAN; - } else if (jsondec_streql(str, "Infinity")) { - val.double_val = INFINITY; - } else if (jsondec_streql(str, "-Infinity")) { - val.double_val = -INFINITY; - } else { - val.double_val = strtod(str.data, NULL); - } + case kUpb_WellKnown_FieldMask: + jsondec_fieldmask(d, msg, m); + break; + case kUpb_WellKnown_Duration: + jsondec_duration(d, msg, m); + break; + case kUpb_WellKnown_Timestamp: + jsondec_timestamp(d, msg, m); + break; + case kUpb_WellKnown_Value: + jsondec_wellknownvalue(d, msg, m); + break; + case kUpb_WellKnown_ListValue: + jsondec_listvalue(d, msg, m); + break; + case kUpb_WellKnown_Struct: + jsondec_struct(d, msg, m); + break; + case kUpb_WellKnown_DoubleValue: + case kUpb_WellKnown_FloatValue: + case kUpb_WellKnown_Int64Value: + case kUpb_WellKnown_UInt64Value: + case kUpb_WellKnown_Int32Value: + case kUpb_WellKnown_UInt32Value: + case kUpb_WellKnown_StringValue: + case kUpb_WellKnown_BytesValue: + case kUpb_WellKnown_BoolValue: + jsondec_wrapper(d, msg, m); break; default: - jsondec_err(d, "Expected number or string"); + UPB_UNREACHABLE(); } +} - if (upb_FieldDef_CType(f) == kUpb_CType_Float) { - float f = val.double_val; - if (val.double_val != INFINITY && val.double_val != -INFINITY) { - if (f == INFINITY || f == -INFINITY) jsondec_err(d, "Float out of range"); - } - val.float_val = f; - } +static bool upb_JsonDecoder_Decode(jsondec* const d, upb_Message* const msg, + const upb_MessageDef* const m) { + if (UPB_SETJMP(d->err)) return false; - return val; -} + jsondec_tomsg(d, msg, m); -/* Parse STRING or BYTES value. */ -static upb_MessageValue jsondec_strfield(jsondec* d, const upb_FieldDef* f) { - upb_MessageValue val; - val.str_val = jsondec_string(d); - if (upb_FieldDef_CType(f) == kUpb_CType_Bytes) { - val.str_val.size = jsondec_base64(d, val.str_val); - } - return val; -} + // Consume any trailing whitespace before checking if we read the entire + // input. + jsondec_consumews(d); -static upb_JsonMessageValue jsondec_enum(jsondec* d, const upb_FieldDef* f) { - switch (jsondec_peek(d)) { - case JD_STRING: { - upb_StringView str = jsondec_string(d); - const upb_EnumDef* e = upb_FieldDef_EnumSubDef(f); - const upb_EnumValueDef* ev = - upb_EnumDef_FindValueByNameWithSize(e, str.data, str.size); - upb_JsonMessageValue val = {.ignore = false}; - if (ev) { - val.value.int32_val = upb_EnumValueDef_Number(ev); - } else { - if (d->options & upb_JsonDecode_IgnoreUnknown) { - val.ignore = true; - } else { - jsondec_errf(d, "Unknown enumerator: '" UPB_STRINGVIEW_FORMAT "'", - UPB_STRINGVIEW_ARGS(str)); - } - } - return val; - } - case JD_NULL: { - if (jsondec_isnullvalue(f)) { - upb_JsonMessageValue val = {.ignore = false}; - jsondec_null(d); - val.value.int32_val = 0; - return val; - } - } - /* Fallthrough. */ - default: - return (upb_JsonMessageValue){.value = jsondec_int(d, f), - .ignore = false}; + if (d->ptr == d->end) { + return true; + } else { + jsondec_seterrmsg(d, "unexpected trailing characters"); + return false; } } -static upb_MessageValue jsondec_bool(jsondec* d, const upb_FieldDef* f) { - bool is_map_key = upb_FieldDef_Number(f) == 1 && - upb_MessageDef_IsMapEntry(upb_FieldDef_ContainingType(f)); - upb_MessageValue val; +bool upb_JsonDecode(const char* buf, size_t size, upb_Message* msg, + const upb_MessageDef* m, const upb_DefPool* symtab, + int options, upb_Arena* arena, upb_Status* status) { + jsondec d; - if (is_map_key) { - upb_StringView str = jsondec_string(d); - if (jsondec_streql(str, "true")) { - val.bool_val = true; - } else if (jsondec_streql(str, "false")) { - val.bool_val = false; - } else { - jsondec_err(d, "Invalid boolean map key"); - } - } else { - switch (jsondec_peek(d)) { - case JD_TRUE: - val.bool_val = true; - jsondec_true(d); - break; - case JD_FALSE: - val.bool_val = false; - jsondec_false(d); - break; - default: - jsondec_err(d, "Expected true or false"); - } - } + if (size == 0) return true; - return val; + d.ptr = buf; + d.end = buf + size; + d.arena = arena; + d.symtab = symtab; + d.status = status; + d.options = options; + d.depth = 64; + d.line = 1; + d.line_begin = d.ptr; + d.debug_field = NULL; + d.is_first = false; + + return upb_JsonDecoder_Decode(&d, msg, m); } -/* Composite types (array/message/map) ****************************************/ -static void jsondec_array(jsondec* d, upb_Message* msg, const upb_FieldDef* f) { - upb_Array* arr = upb_Message_Mutable(msg, f, d->arena).array; +#include +#include +#include +#include +#include +#include - jsondec_arrstart(d); - while (jsondec_arrnext(d)) { - upb_JsonMessageValue elem = jsondec_value(d, f); - if (!elem.ignore) { - upb_Array_Append(arr, elem.value, d->arena); - } - } - jsondec_arrend(d); + +// Must be last. + +typedef struct { + char *buf, *ptr, *end; + size_t overflow; + int indent_depth; + int options; + const upb_DefPool* ext_pool; + jmp_buf err; + upb_Status* status; + upb_Arena* arena; +} jsonenc; + +static void jsonenc_msg(jsonenc* e, const upb_Message* msg, + const upb_MessageDef* m); +static void jsonenc_scalar(jsonenc* e, upb_MessageValue val, + const upb_FieldDef* f); +static void jsonenc_msgfield(jsonenc* e, const upb_Message* msg, + const upb_MessageDef* m); +static void jsonenc_msgfields(jsonenc* e, const upb_Message* msg, + const upb_MessageDef* m, bool first); +static void jsonenc_value(jsonenc* e, const upb_Message* msg, + const upb_MessageDef* m); + +UPB_NORETURN static void jsonenc_err(jsonenc* e, const char* msg) { + upb_Status_SetErrorMessage(e->status, msg); + longjmp(e->err, 1); } -static void jsondec_map(jsondec* d, upb_Message* msg, const upb_FieldDef* f) { - upb_Map* map = upb_Message_Mutable(msg, f, d->arena).map; - const upb_MessageDef* entry = upb_FieldDef_MessageSubDef(f); - const upb_FieldDef* key_f = upb_MessageDef_FindFieldByNumber(entry, 1); - const upb_FieldDef* val_f = upb_MessageDef_FindFieldByNumber(entry, 2); +UPB_PRINTF(2, 3) +UPB_NORETURN static void jsonenc_errf(jsonenc* e, const char* fmt, ...) { + va_list argp; + va_start(argp, fmt); + upb_Status_VSetErrorFormat(e->status, fmt, argp); + va_end(argp); + longjmp(e->err, 1); +} - jsondec_objstart(d); - while (jsondec_objnext(d)) { - upb_JsonMessageValue key, val; - key = jsondec_value(d, key_f); - UPB_ASSUME(!key.ignore); // Map key cannot be enum. - jsondec_entrysep(d); - val = jsondec_value(d, val_f); - if (!val.ignore) { - upb_Map_Set(map, key.value, val.value, d->arena); - } +static upb_Arena* jsonenc_arena(jsonenc* e) { + /* Create lazily, since it's only needed for Any */ + if (!e->arena) { + e->arena = upb_Arena_New(); } - jsondec_objend(d); + return e->arena; } -static void jsondec_tomsg(jsondec* d, upb_Message* msg, - const upb_MessageDef* m) { - if (upb_MessageDef_WellKnownType(m) == kUpb_WellKnown_Unspecified) { - jsondec_object(d, msg, m); +static void jsonenc_putbytes(jsonenc* e, const void* data, size_t len) { + size_t have = e->end - e->ptr; + if (UPB_LIKELY(have >= len)) { + memcpy(e->ptr, data, len); + e->ptr += len; } else { - jsondec_wellknown(d, msg, m); + if (have) { + memcpy(e->ptr, data, have); + e->ptr += have; + } + e->overflow += (len - have); } } -static upb_MessageValue jsondec_msg(jsondec* d, const upb_FieldDef* f) { - const upb_MessageDef* m = upb_FieldDef_MessageSubDef(f); - const upb_MiniTable* layout = upb_MessageDef_MiniTable(m); - upb_Message* msg = upb_Message_New(layout, d->arena); - upb_MessageValue val; - - jsondec_tomsg(d, msg, m); - val.msg_val = msg; - return val; +static void jsonenc_putstr(jsonenc* e, const char* str) { + jsonenc_putbytes(e, str, strlen(str)); } -static void jsondec_field(jsondec* d, upb_Message* msg, - const upb_MessageDef* m) { - upb_StringView name; - const upb_FieldDef* f; - const upb_FieldDef* preserved; +UPB_PRINTF(2, 3) +static void jsonenc_printf(jsonenc* e, const char* fmt, ...) { + size_t n; + size_t have = e->end - e->ptr; + va_list args; - name = jsondec_string(d); - jsondec_entrysep(d); + va_start(args, fmt); + n = _upb_vsnprintf(e->ptr, have, fmt, args); + va_end(args); - if (name.size >= 2 && name.data[0] == '[' && - name.data[name.size - 1] == ']') { - f = upb_DefPool_FindExtensionByNameWithSize(d->symtab, name.data + 1, - name.size - 2); - if (f && upb_FieldDef_ContainingType(f) != m) { - jsondec_errf( - d, "Extension %s extends message %s, but was seen in message %s", - upb_FieldDef_FullName(f), - upb_MessageDef_FullName(upb_FieldDef_ContainingType(f)), - upb_MessageDef_FullName(m)); - } + if (UPB_LIKELY(have > n)) { + e->ptr += n; } else { - f = upb_MessageDef_FindByJsonNameWithSize(m, name.data, name.size); - } - - if (!f) { - if ((d->options & upb_JsonDecode_IgnoreUnknown) == 0) { - jsondec_errf(d, "No such field: " UPB_STRINGVIEW_FORMAT, - UPB_STRINGVIEW_ARGS(name)); - } - jsondec_skipval(d); - return; + e->ptr = UPB_PTRADD(e->ptr, have); + e->overflow += (n - have); } +} - if (jsondec_peek(d) == JD_NULL && !jsondec_isvalue(f)) { - /* JSON "null" indicates a default value, so no need to set anything. */ - jsondec_null(d); - return; - } +static void jsonenc_nanos(jsonenc* e, int32_t nanos) { + int digits = 9; - if (upb_FieldDef_RealContainingOneof(f) && - upb_Message_WhichOneof(msg, upb_FieldDef_ContainingOneof(f))) { - jsondec_err(d, "More than one field for this oneof."); + if (nanos == 0) return; + if (nanos < 0 || nanos >= 1000000000) { + jsonenc_err(e, "error formatting timestamp as JSON: invalid nanos"); } - preserved = d->debug_field; - d->debug_field = f; - - if (upb_FieldDef_IsMap(f)) { - jsondec_map(d, msg, f); - } else if (upb_FieldDef_IsRepeated(f)) { - jsondec_array(d, msg, f); - } else if (upb_FieldDef_IsSubMessage(f)) { - upb_Message* submsg = upb_Message_Mutable(msg, f, d->arena).msg; - const upb_MessageDef* subm = upb_FieldDef_MessageSubDef(f); - jsondec_tomsg(d, submsg, subm); - } else { - upb_JsonMessageValue val = jsondec_value(d, f); - if (!val.ignore) { - upb_Message_SetFieldByDef(msg, f, val.value, d->arena); - } + while (nanos % 1000 == 0) { + nanos /= 1000; + digits -= 3; } - d->debug_field = preserved; + jsonenc_printf(e, ".%.*" PRId32, digits, nanos); } -static void jsondec_object(jsondec* d, upb_Message* msg, - const upb_MessageDef* m) { - jsondec_objstart(d); - while (jsondec_objnext(d)) { - jsondec_field(d, msg, m); - } - jsondec_objend(d); -} +static void jsonenc_timestamp(jsonenc* e, const upb_Message* msg, + const upb_MessageDef* m) { + const upb_FieldDef* seconds_f = upb_MessageDef_FindFieldByNumber(m, 1); + const upb_FieldDef* nanos_f = upb_MessageDef_FindFieldByNumber(m, 2); + int64_t seconds = upb_Message_GetFieldByDef(msg, seconds_f).int64_val; + int32_t nanos = upb_Message_GetFieldByDef(msg, nanos_f).int32_val; + int L, N, I, J, K, hour, min, sec; -static upb_MessageValue jsondec_nonenum(jsondec* d, const upb_FieldDef* f) { - switch (upb_FieldDef_CType(f)) { - case kUpb_CType_Bool: - return jsondec_bool(d, f); - case kUpb_CType_Float: - case kUpb_CType_Double: - return jsondec_double(d, f); - case kUpb_CType_UInt32: - case kUpb_CType_UInt64: - return jsondec_uint(d, f); - case kUpb_CType_Int32: - case kUpb_CType_Int64: - return jsondec_int(d, f); - case kUpb_CType_String: - case kUpb_CType_Bytes: - return jsondec_strfield(d, f); - case kUpb_CType_Message: - return jsondec_msg(d, f); - case kUpb_CType_Enum: - default: - UPB_UNREACHABLE(); + if (seconds < -62135596800) { + jsonenc_err(e, + "error formatting timestamp as JSON: minimum acceptable value " + "is 0001-01-01T00:00:00Z"); + } else if (seconds > 253402300799) { + jsonenc_err(e, + "error formatting timestamp as JSON: maximum acceptable value " + "is 9999-12-31T23:59:59Z"); } -} -static upb_JsonMessageValue jsondec_value(jsondec* d, const upb_FieldDef* f) { - if (upb_FieldDef_CType(f) == kUpb_CType_Enum) { - return jsondec_enum(d, f); - } else { - return (upb_JsonMessageValue){.value = jsondec_nonenum(d, f), - .ignore = false}; - } -} + /* Julian Day -> Y/M/D, Algorithm from: + * Fliegel, H. F., and Van Flandern, T. C., "A Machine Algorithm for + * Processing Calendar Dates," Communications of the Association of + * Computing Machines, vol. 11 (1968), p. 657. */ + seconds += 62135596800; // Ensure seconds is positive. + L = (int)(seconds / 86400) - 719162 + 68569 + 2440588; + N = 4 * L / 146097; + L = L - (146097 * N + 3) / 4; + I = 4000 * (L + 1) / 1461001; + L = L - 1461 * I / 4 + 31; + J = 80 * L / 2447; + K = L - 2447 * J / 80; + L = J / 11; + J = J + 2 - 12 * L; + I = 100 * (N - 49) + I + L; -/* Well-known types ***********************************************************/ + sec = seconds % 60; + min = (seconds / 60) % 60; + hour = (seconds / 3600) % 24; -static int jsondec_tsdigits(jsondec* d, const char** ptr, size_t digits, - const char* after) { - uint64_t val; - const char* p = *ptr; - const char* end = p + digits; - size_t after_len = after ? strlen(after) : 0; + jsonenc_printf(e, "\"%04d-%02d-%02dT%02d:%02d:%02d", I, J, K, hour, min, sec); + jsonenc_nanos(e, nanos); + jsonenc_putstr(e, "Z\""); +} - UPB_ASSERT(digits <= 9); /* int can't overflow. */ +static void jsonenc_duration(jsonenc* e, const upb_Message* msg, + const upb_MessageDef* m) { + const upb_FieldDef* seconds_f = upb_MessageDef_FindFieldByNumber(m, 1); + const upb_FieldDef* nanos_f = upb_MessageDef_FindFieldByNumber(m, 2); + int64_t seconds = upb_Message_GetFieldByDef(msg, seconds_f).int64_val; + int32_t nanos = upb_Message_GetFieldByDef(msg, nanos_f).int32_val; + bool negative = false; - if (jsondec_buftouint64(d, p, end, &val) != end || - (after_len && memcmp(end, after, after_len) != 0)) { - jsondec_err(d, "Malformed timestamp"); + if (seconds > 315576000000 || seconds < -315576000000 || + (seconds != 0 && nanos != 0 && (seconds < 0) != (nanos < 0))) { + jsonenc_err(e, "bad duration"); } - UPB_ASSERT(val < INT_MAX); + if (seconds < 0) { + negative = true; + seconds = -seconds; + } + if (nanos < 0) { + negative = true; + nanos = -nanos; + } - *ptr = end + after_len; - return (int)val; + jsonenc_putstr(e, "\""); + if (negative) { + jsonenc_putstr(e, "-"); + } + jsonenc_printf(e, "%" PRId64, seconds); + jsonenc_nanos(e, nanos); + jsonenc_putstr(e, "s\""); } -static int jsondec_nanos(jsondec* d, const char** ptr, const char* end) { - uint64_t nanos = 0; - const char* p = *ptr; +static void jsonenc_enum(int32_t val, const upb_FieldDef* f, jsonenc* e) { + const upb_EnumDef* e_def = upb_FieldDef_EnumSubDef(f); - if (p != end && *p == '.') { - const char* nano_end = jsondec_buftouint64(d, p + 1, end, &nanos); - int digits = (int)(nano_end - p - 1); - int exp_lg10 = 9 - digits; - if (digits > 9) { - jsondec_err(d, "Too many digits for partial seconds"); + if (strcmp(upb_EnumDef_FullName(e_def), "google.protobuf.NullValue") == 0) { + jsonenc_putstr(e, "null"); + } else { + const upb_EnumValueDef* ev = + (e->options & upb_JsonEncode_FormatEnumsAsIntegers) + ? NULL + : upb_EnumDef_FindValueByNumber(e_def, val); + + if (ev) { + jsonenc_printf(e, "\"%s\"", upb_EnumValueDef_Name(ev)); + } else { + jsonenc_printf(e, "%" PRId32, val); } - while (exp_lg10--) nanos *= 10; - *ptr = nano_end; } - - UPB_ASSERT(nanos < INT_MAX); - - return (int)nanos; -} - -/* jsondec_epochdays(1970, 1, 1) == 1970-01-01 == 0. */ -int jsondec_epochdays(int y, int m, int d) { - const uint32_t year_base = 4800; /* Before min year, multiple of 400. */ - const uint32_t m_adj = m - 3; /* March-based month. */ - const uint32_t carry = m_adj > (uint32_t)m ? 1 : 0; - const uint32_t adjust = carry ? 12 : 0; - const uint32_t y_adj = y + year_base - carry; - const uint32_t month_days = ((m_adj + adjust) * 62719 + 769) / 2048; - const uint32_t leap_days = y_adj / 4 - y_adj / 100 + y_adj / 400; - return y_adj * 365 + leap_days + month_days + (d - 1) - 2472632; -} - -static int64_t jsondec_unixtime(int y, int m, int d, int h, int min, int s) { - return (int64_t)jsondec_epochdays(y, m, d) * 86400 + h * 3600 + min * 60 + s; } -static void jsondec_timestamp(jsondec* d, upb_Message* msg, - const upb_MessageDef* m) { - upb_MessageValue seconds; - upb_MessageValue nanos; - upb_StringView str = jsondec_string(d); - const char* ptr = str.data; - const char* end = ptr + str.size; - - if (str.size < 20) goto malformed; +static void jsonenc_bytes(jsonenc* e, upb_StringView str) { + /* This is the regular base64, not the "web-safe" version. */ + static const char base64[] = + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; + const unsigned char* ptr = (unsigned char*)str.data; + const unsigned char* end = UPB_PTRADD(ptr, str.size); + char buf[4]; - { - /* 1972-01-01T01:00:00 */ - int year = jsondec_tsdigits(d, &ptr, 4, "-"); - int mon = jsondec_tsdigits(d, &ptr, 2, "-"); - int day = jsondec_tsdigits(d, &ptr, 2, "T"); - int hour = jsondec_tsdigits(d, &ptr, 2, ":"); - int min = jsondec_tsdigits(d, &ptr, 2, ":"); - int sec = jsondec_tsdigits(d, &ptr, 2, NULL); + jsonenc_putstr(e, "\""); - seconds.int64_val = jsondec_unixtime(year, mon, day, hour, min, sec); + while (end - ptr >= 3) { + buf[0] = base64[ptr[0] >> 2]; + buf[1] = base64[((ptr[0] & 0x3) << 4) | (ptr[1] >> 4)]; + buf[2] = base64[((ptr[1] & 0xf) << 2) | (ptr[2] >> 6)]; + buf[3] = base64[ptr[2] & 0x3f]; + jsonenc_putbytes(e, buf, 4); + ptr += 3; } - nanos.int32_val = jsondec_nanos(d, &ptr, end); + switch (end - ptr) { + case 2: + buf[0] = base64[ptr[0] >> 2]; + buf[1] = base64[((ptr[0] & 0x3) << 4) | (ptr[1] >> 4)]; + buf[2] = base64[(ptr[1] & 0xf) << 2]; + buf[3] = '='; + jsonenc_putbytes(e, buf, 4); + break; + case 1: + buf[0] = base64[ptr[0] >> 2]; + buf[1] = base64[((ptr[0] & 0x3) << 4)]; + buf[2] = '='; + buf[3] = '='; + jsonenc_putbytes(e, buf, 4); + break; + } - { - /* [+-]08:00 or Z */ - int ofs_hour = 0; - int ofs_min = 0; - bool neg = false; + jsonenc_putstr(e, "\""); +} - if (ptr == end) goto malformed; +static void jsonenc_stringbody(jsonenc* e, upb_StringView str) { + const char* ptr = str.data; + const char* end = UPB_PTRADD(ptr, str.size); - switch (*ptr++) { - case '-': - neg = true; - /* fallthrough */ - case '+': - if ((end - ptr) != 5) goto malformed; - ofs_hour = jsondec_tsdigits(d, &ptr, 2, ":"); - ofs_min = jsondec_tsdigits(d, &ptr, 2, NULL); - ofs_min = ((ofs_hour * 60) + ofs_min) * 60; - seconds.int64_val += (neg ? ofs_min : -ofs_min); + while (ptr < end) { + switch (*ptr) { + case '\n': + jsonenc_putstr(e, "\\n"); break; - case 'Z': - if (ptr != end) goto malformed; + case '\r': + jsonenc_putstr(e, "\\r"); + break; + case '\t': + jsonenc_putstr(e, "\\t"); + break; + case '\"': + jsonenc_putstr(e, "\\\""); + break; + case '\f': + jsonenc_putstr(e, "\\f"); + break; + case '\b': + jsonenc_putstr(e, "\\b"); + break; + case '\\': + jsonenc_putstr(e, "\\\\"); break; default: - goto malformed; + if ((uint8_t)*ptr < 0x20) { + jsonenc_printf(e, "\\u%04x", (int)(uint8_t)*ptr); + } else { + /* This could be a non-ASCII byte. We rely on the string being valid + * UTF-8. */ + jsonenc_putbytes(e, ptr, 1); + } + break; } + ptr++; } +} - if (seconds.int64_val < -62135596800) { - jsondec_err(d, "Timestamp out of range"); +static void jsonenc_string(jsonenc* e, upb_StringView str) { + jsonenc_putstr(e, "\""); + jsonenc_stringbody(e, str); + jsonenc_putstr(e, "\""); +} + +static bool upb_JsonEncode_HandleSpecialDoubles(jsonenc* e, double val) { + if (val == INFINITY) { + jsonenc_putstr(e, "\"Infinity\""); + } else if (val == -INFINITY) { + jsonenc_putstr(e, "\"-Infinity\""); + } else if (val != val) { + jsonenc_putstr(e, "\"NaN\""); + } else { + return false; } + return true; +} - upb_Message_SetFieldByDef(msg, upb_MessageDef_FindFieldByNumber(m, 1), - seconds, d->arena); - upb_Message_SetFieldByDef(msg, upb_MessageDef_FindFieldByNumber(m, 2), nanos, - d->arena); - return; +static void upb_JsonEncode_Double(jsonenc* e, double val) { + if (upb_JsonEncode_HandleSpecialDoubles(e, val)) return; + char buf[32]; + _upb_EncodeRoundTripDouble(val, buf, sizeof(buf)); + jsonenc_putstr(e, buf); +} -malformed: - jsondec_err(d, "Malformed timestamp"); +static void upb_JsonEncode_Float(jsonenc* e, float val) { + if (upb_JsonEncode_HandleSpecialDoubles(e, val)) return; + char buf[32]; + _upb_EncodeRoundTripFloat(val, buf, sizeof(buf)); + jsonenc_putstr(e, buf); } -static void jsondec_duration(jsondec* d, upb_Message* msg, - const upb_MessageDef* m) { - upb_MessageValue seconds; - upb_MessageValue nanos; - upb_StringView str = jsondec_string(d); - const char* ptr = str.data; - const char* end = ptr + str.size; - const int64_t max = (uint64_t)3652500 * 86400; - bool neg = false; +static void jsonenc_wrapper(jsonenc* e, const upb_Message* msg, + const upb_MessageDef* m) { + const upb_FieldDef* val_f = upb_MessageDef_FindFieldByNumber(m, 1); + upb_MessageValue val = upb_Message_GetFieldByDef(msg, val_f); + jsonenc_scalar(e, val, val_f); +} - /* "3.000000001s", "3s", etc. */ - ptr = jsondec_buftoint64(d, ptr, end, &seconds.int64_val, &neg); - nanos.int32_val = jsondec_nanos(d, &ptr, end); +static const upb_MessageDef* jsonenc_getanymsg(jsonenc* e, + upb_StringView type_url) { + /* Find last '/', if any. */ + const char* end = type_url.data + type_url.size; + const char* ptr = end; + const upb_MessageDef* ret; - if (end - ptr != 1 || *ptr != 's') { - jsondec_err(d, "Malformed duration"); + if (!e->ext_pool) { + jsonenc_err(e, "Tried to encode Any, but no symtab was provided"); } - if (seconds.int64_val < -max || seconds.int64_val > max) { - jsondec_err(d, "Duration out of range"); - } + if (type_url.size == 0) goto badurl; - if (neg) { - nanos.int32_val = -nanos.int32_val; + while (true) { + if (--ptr == type_url.data) { + /* Type URL must contain at least one '/', with host before. */ + goto badurl; + } + if (*ptr == '/') { + ptr++; + break; + } } - upb_Message_SetFieldByDef(msg, upb_MessageDef_FindFieldByNumber(m, 1), - seconds, d->arena); - upb_Message_SetFieldByDef(msg, upb_MessageDef_FindFieldByNumber(m, 2), nanos, - d->arena); -} - -static void jsondec_listvalue(jsondec* d, upb_Message* msg, - const upb_MessageDef* m) { - const upb_FieldDef* values_f = upb_MessageDef_FindFieldByNumber(m, 1); - const upb_MessageDef* value_m = upb_FieldDef_MessageSubDef(values_f); - const upb_MiniTable* value_layout = upb_MessageDef_MiniTable(value_m); - upb_Array* values = upb_Message_Mutable(msg, values_f, d->arena).array; + ret = upb_DefPool_FindMessageByNameWithSize(e->ext_pool, ptr, end - ptr); - jsondec_arrstart(d); - while (jsondec_arrnext(d)) { - upb_Message* value_msg = upb_Message_New(value_layout, d->arena); - upb_MessageValue value; - value.msg_val = value_msg; - upb_Array_Append(values, value, d->arena); - jsondec_wellknownvalue(d, value_msg, value_m); + if (!ret) { + jsonenc_errf(e, "Couldn't find Any type: %.*s", (int)(end - ptr), ptr); } - jsondec_arrend(d); + + return ret; + +badurl: + jsonenc_errf(e, "Bad type URL: " UPB_STRINGVIEW_FORMAT, + UPB_STRINGVIEW_ARGS(type_url)); } -static void jsondec_struct(jsondec* d, upb_Message* msg, - const upb_MessageDef* m) { - const upb_FieldDef* fields_f = upb_MessageDef_FindFieldByNumber(m, 1); - const upb_MessageDef* entry_m = upb_FieldDef_MessageSubDef(fields_f); - const upb_FieldDef* value_f = upb_MessageDef_FindFieldByNumber(entry_m, 2); - const upb_MessageDef* value_m = upb_FieldDef_MessageSubDef(value_f); - const upb_MiniTable* value_layout = upb_MessageDef_MiniTable(value_m); - upb_Map* fields = upb_Message_Mutable(msg, fields_f, d->arena).map; +static void jsonenc_any(jsonenc* e, const upb_Message* msg, + const upb_MessageDef* m) { + const upb_FieldDef* type_url_f = upb_MessageDef_FindFieldByNumber(m, 1); + const upb_FieldDef* value_f = upb_MessageDef_FindFieldByNumber(m, 2); + upb_StringView type_url = upb_Message_GetFieldByDef(msg, type_url_f).str_val; + upb_StringView value = upb_Message_GetFieldByDef(msg, value_f).str_val; + const upb_MessageDef* any_m = jsonenc_getanymsg(e, type_url); + const upb_MiniTable* any_layout = upb_MessageDef_MiniTable(any_m); + upb_Arena* arena = jsonenc_arena(e); + upb_Message* any = upb_Message_New(any_layout, arena); - jsondec_objstart(d); - while (jsondec_objnext(d)) { - upb_MessageValue key, value; - upb_Message* value_msg = upb_Message_New(value_layout, d->arena); - key.str_val = jsondec_string(d); - value.msg_val = value_msg; - upb_Map_Set(fields, key, value, d->arena); - jsondec_entrysep(d); - jsondec_wellknownvalue(d, value_msg, value_m); + if (upb_Decode(value.data, value.size, any, any_layout, NULL, 0, arena) != + kUpb_DecodeStatus_Ok) { + jsonenc_err(e, "Error decoding message in Any"); } - jsondec_objend(d); -} -static void jsondec_wellknownvalue(jsondec* d, upb_Message* msg, - const upb_MessageDef* m) { - upb_MessageValue val; - const upb_FieldDef* f; - upb_Message* submsg; + jsonenc_putstr(e, "{\"@type\":"); + jsonenc_string(e, type_url); - switch (jsondec_peek(d)) { - case JD_NUMBER: - /* double number_value = 2; */ - f = upb_MessageDef_FindFieldByNumber(m, 2); - val.double_val = jsondec_number(d); - break; - case JD_STRING: - /* string string_value = 3; */ - f = upb_MessageDef_FindFieldByNumber(m, 3); - val.str_val = jsondec_string(d); - break; - case JD_FALSE: - /* bool bool_value = 4; */ - f = upb_MessageDef_FindFieldByNumber(m, 4); - val.bool_val = false; - jsondec_false(d); - break; - case JD_TRUE: - /* bool bool_value = 4; */ - f = upb_MessageDef_FindFieldByNumber(m, 4); - val.bool_val = true; - jsondec_true(d); - break; - case JD_NULL: - /* NullValue null_value = 1; */ - f = upb_MessageDef_FindFieldByNumber(m, 1); - val.int32_val = 0; - jsondec_null(d); - break; - /* Note: these cases return, because upb_Message_Mutable() is enough. */ - case JD_OBJECT: - /* Struct struct_value = 5; */ - f = upb_MessageDef_FindFieldByNumber(m, 5); - submsg = upb_Message_Mutable(msg, f, d->arena).msg; - jsondec_struct(d, submsg, upb_FieldDef_MessageSubDef(f)); - return; - case JD_ARRAY: - /* ListValue list_value = 6; */ - f = upb_MessageDef_FindFieldByNumber(m, 6); - submsg = upb_Message_Mutable(msg, f, d->arena).msg; - jsondec_listvalue(d, submsg, upb_FieldDef_MessageSubDef(f)); - return; - default: - UPB_UNREACHABLE(); + if (upb_MessageDef_WellKnownType(any_m) == kUpb_WellKnown_Unspecified) { + /* Regular messages: {"@type": "...","foo": 1, "bar": 2} */ + jsonenc_msgfields(e, any, any_m, false); + } else { + /* Well-known type: {"@type": "...","value": } */ + jsonenc_putstr(e, ",\"value\":"); + jsonenc_msgfield(e, any, any_m); } - upb_Message_SetFieldByDef(msg, f, val, d->arena); + jsonenc_putstr(e, "}"); } -static upb_StringView jsondec_mask(jsondec* d, const char* buf, - const char* end) { - /* FieldMask fields grow due to inserted '_' characters, so we can't do the - * transform in place. */ - const char* ptr = buf; - upb_StringView ret; - char* out; - - ret.size = end - ptr; - while (ptr < end) { - ret.size += (*ptr >= 'A' && *ptr <= 'Z'); - ptr++; +static void jsonenc_putsep(jsonenc* e, const char* str, bool* first) { + if (*first) { + *first = false; + } else { + jsonenc_putstr(e, str); } +} - out = upb_Arena_Malloc(d->arena, ret.size); - ptr = buf; - ret.data = out; +static void jsonenc_fieldpath(jsonenc* e, upb_StringView path) { + const char* ptr = path.data; + const char* end = ptr + path.size; while (ptr < end) { - char ch = *ptr++; + char ch = *ptr; + if (ch >= 'A' && ch <= 'Z') { - *out++ = '_'; - *out++ = ch + 32; + jsonenc_err(e, "Field mask element may not have upper-case letter."); } else if (ch == '_') { - jsondec_err(d, "field mask may not contain '_'"); - } else { - *out++ = ch; + if (ptr == end - 1 || *(ptr + 1) < 'a' || *(ptr + 1) > 'z') { + jsonenc_err(e, "Underscore must be followed by a lowercase letter."); + } + ch = *++ptr - 32; } - } - return ret; + jsonenc_putbytes(e, &ch, 1); + ptr++; + } } -static void jsondec_fieldmask(jsondec* d, upb_Message* msg, +static void jsonenc_fieldmask(jsonenc* e, const upb_Message* msg, const upb_MessageDef* m) { - /* repeated string paths = 1; */ const upb_FieldDef* paths_f = upb_MessageDef_FindFieldByNumber(m, 1); - upb_Array* arr = upb_Message_Mutable(msg, paths_f, d->arena).array; - upb_StringView str = jsondec_string(d); - const char* ptr = str.data; - const char* end = ptr + str.size; - upb_MessageValue val; + const upb_Array* paths = upb_Message_GetFieldByDef(msg, paths_f).array_val; + bool first = true; + size_t i, n = 0; - while (ptr < end) { - const char* elem_end = memchr(ptr, ',', end - ptr); - if (elem_end) { - val.str_val = jsondec_mask(d, ptr, elem_end); - ptr = elem_end + 1; - } else { - val.str_val = jsondec_mask(d, ptr, end); - ptr = end; - } - upb_Array_Append(arr, val, d->arena); - } -} + if (paths) n = upb_Array_Size(paths); -static void jsondec_anyfield(jsondec* d, upb_Message* msg, - const upb_MessageDef* m) { - if (upb_MessageDef_WellKnownType(m) == kUpb_WellKnown_Unspecified) { - /* For regular types: {"@type": "[user type]", "f1": , "f2": } - * where f1, f2, etc. are the normal fields of this type. */ - jsondec_field(d, msg, m); - } else { - /* For well-known types: {"@type": "[well-known type]", "value": } - * where is whatever encoding the WKT normally uses. */ - upb_StringView str = jsondec_string(d); - jsondec_entrysep(d); - if (!jsondec_streql(str, "value")) { - jsondec_err(d, "Key for well-known type must be 'value'"); - } - jsondec_wellknown(d, msg, m); + jsonenc_putstr(e, "\""); + + for (i = 0; i < n; i++) { + jsonenc_putsep(e, ",", &first); + jsonenc_fieldpath(e, upb_Array_Get(paths, i).str_val); } -} -static const upb_MessageDef* jsondec_typeurl(jsondec* d, upb_Message* msg, - const upb_MessageDef* m) { - const upb_FieldDef* type_url_f = upb_MessageDef_FindFieldByNumber(m, 1); - const upb_MessageDef* type_m; - upb_StringView type_url = jsondec_string(d); - const char* end = type_url.data + type_url.size; - const char* ptr = end; - upb_MessageValue val; + jsonenc_putstr(e, "\""); +} - val.str_val = type_url; - upb_Message_SetFieldByDef(msg, type_url_f, val, d->arena); +static void jsonenc_struct(jsonenc* e, const upb_Message* msg, + const upb_MessageDef* m) { + jsonenc_putstr(e, "{"); - /* Find message name after the last '/' */ - while (ptr > type_url.data && *--ptr != '/') { - } + const upb_FieldDef* fields_f = upb_MessageDef_FindFieldByNumber(m, 1); + const upb_Map* fields = upb_Message_GetFieldByDef(msg, fields_f).map_val; - if (ptr == type_url.data || ptr == end) { - jsondec_err(d, "Type url must have at least one '/' and non-empty host"); - } + if (fields) { + const upb_MessageDef* entry_m = upb_FieldDef_MessageSubDef(fields_f); + const upb_FieldDef* value_f = upb_MessageDef_FindFieldByNumber(entry_m, 2); - ptr++; - type_m = upb_DefPool_FindMessageByNameWithSize(d->symtab, ptr, end - ptr); + size_t iter = kUpb_Map_Begin; + bool first = true; - if (!type_m) { - jsondec_err(d, "Type was not found"); + upb_MessageValue key, val; + while (upb_Map_Next(fields, &key, &val, &iter)) { + jsonenc_putsep(e, ",", &first); + jsonenc_string(e, key.str_val); + jsonenc_putstr(e, ":"); + jsonenc_value(e, val.msg_val, upb_FieldDef_MessageSubDef(value_f)); + } } - return type_m; + jsonenc_putstr(e, "}"); } -static void jsondec_any(jsondec* d, upb_Message* msg, const upb_MessageDef* m) { - /* string type_url = 1; - * bytes value = 2; */ - const upb_FieldDef* value_f = upb_MessageDef_FindFieldByNumber(m, 2); - upb_Message* any_msg; - const upb_MessageDef* any_m = NULL; - const char* pre_type_data = NULL; - const char* pre_type_end = NULL; - upb_MessageValue encoded; +static void jsonenc_listvalue(jsonenc* e, const upb_Message* msg, + const upb_MessageDef* m) { + const upb_FieldDef* values_f = upb_MessageDef_FindFieldByNumber(m, 1); + const upb_MessageDef* values_m = upb_FieldDef_MessageSubDef(values_f); + const upb_Array* values = upb_Message_GetFieldByDef(msg, values_f).array_val; + size_t i; + bool first = true; - jsondec_objstart(d); + jsonenc_putstr(e, "["); - /* Scan looking for "@type", which is not necessarily first. */ - while (!any_m && jsondec_objnext(d)) { - const char* start = d->ptr; - upb_StringView name = jsondec_string(d); - jsondec_entrysep(d); - if (jsondec_streql(name, "@type")) { - any_m = jsondec_typeurl(d, msg, m); - if (pre_type_data) { - pre_type_end = start; - while (*pre_type_end != ',') pre_type_end--; - } - } else { - if (!pre_type_data) pre_type_data = start; - jsondec_skipval(d); + if (values) { + const size_t size = upb_Array_Size(values); + for (i = 0; i < size; i++) { + upb_MessageValue elem = upb_Array_Get(values, i); + + jsonenc_putsep(e, ",", &first); + jsonenc_value(e, elem.msg_val, values_m); } } - if (!any_m) { - jsondec_err(d, "Any object didn't contain a '@type' field"); - } + jsonenc_putstr(e, "]"); +} - const upb_MiniTable* any_layout = upb_MessageDef_MiniTable(any_m); - any_msg = upb_Message_New(any_layout, d->arena); +static void jsonenc_value(jsonenc* e, const upb_Message* msg, + const upb_MessageDef* m) { + /* TODO: do we want a reflection method to get oneof case? */ + size_t iter = kUpb_Message_Begin; + const upb_FieldDef* f; + upb_MessageValue val; - if (pre_type_data) { - size_t len = pre_type_end - pre_type_data + 1; - char* tmp = upb_Arena_Malloc(d->arena, len); - const char* saved_ptr = d->ptr; - const char* saved_end = d->end; - memcpy(tmp, pre_type_data, len - 1); - tmp[len - 1] = '}'; - d->ptr = tmp; - d->end = tmp + len; - d->is_first = true; - while (jsondec_objnext(d)) { - jsondec_anyfield(d, any_msg, any_m); - } - d->ptr = saved_ptr; - d->end = saved_end; + if (!upb_Message_Next(msg, m, NULL, &f, &val, &iter)) { + jsonenc_err(e, "No value set in Value proto"); } - while (jsondec_objnext(d)) { - jsondec_anyfield(d, any_msg, any_m); + switch (upb_FieldDef_Number(f)) { + case 1: + jsonenc_putstr(e, "null"); + break; + case 2: + if (upb_JsonEncode_HandleSpecialDoubles(e, val.double_val)) { + jsonenc_err( + e, + "google.protobuf.Value cannot encode double values for " + "infinity or nan, because they would be parsed as a string"); + } + upb_JsonEncode_Double(e, val.double_val); + break; + case 3: + jsonenc_string(e, val.str_val); + break; + case 4: + jsonenc_putstr(e, val.bool_val ? "true" : "false"); + break; + case 5: + jsonenc_struct(e, val.msg_val, upb_FieldDef_MessageSubDef(f)); + break; + case 6: + jsonenc_listvalue(e, val.msg_val, upb_FieldDef_MessageSubDef(f)); + break; } - - jsondec_objend(d); - - upb_EncodeStatus status = - upb_Encode(any_msg, upb_MessageDef_MiniTable(any_m), 0, d->arena, - (char**)&encoded.str_val.data, &encoded.str_val.size); - // TODO: We should fail gracefully here on a bad return status. - UPB_ASSERT(status == kUpb_EncodeStatus_Ok); - upb_Message_SetFieldByDef(msg, value_f, encoded, d->arena); } -static void jsondec_wrapper(jsondec* d, upb_Message* msg, - const upb_MessageDef* m) { - const upb_FieldDef* value_f = upb_MessageDef_FindFieldByNumber(m, 1); - upb_JsonMessageValue val = jsondec_value(d, value_f); - UPB_ASSUME(val.ignore == false); // Wrapper cannot be an enum. - upb_Message_SetFieldByDef(msg, value_f, val.value, d->arena); -} - -static void jsondec_wellknown(jsondec* d, upb_Message* msg, - const upb_MessageDef* m) { +static void jsonenc_msgfield(jsonenc* e, const upb_Message* msg, + const upb_MessageDef* m) { switch (upb_MessageDef_WellKnownType(m)) { + case kUpb_WellKnown_Unspecified: + jsonenc_msg(e, msg, m); + break; case kUpb_WellKnown_Any: - jsondec_any(d, msg, m); + jsonenc_any(e, msg, m); break; case kUpb_WellKnown_FieldMask: - jsondec_fieldmask(d, msg, m); + jsonenc_fieldmask(e, msg, m); break; case kUpb_WellKnown_Duration: - jsondec_duration(d, msg, m); + jsonenc_duration(e, msg, m); break; case kUpb_WellKnown_Timestamp: - jsondec_timestamp(d, msg, m); - break; - case kUpb_WellKnown_Value: - jsondec_wellknownvalue(d, msg, m); - break; - case kUpb_WellKnown_ListValue: - jsondec_listvalue(d, msg, m); - break; - case kUpb_WellKnown_Struct: - jsondec_struct(d, msg, m); + jsonenc_timestamp(e, msg, m); break; case kUpb_WellKnown_DoubleValue: case kUpb_WellKnown_FloatValue: @@ -4532,2319 +4304,2531 @@ static void jsondec_wellknown(jsondec* d, upb_Message* msg, case kUpb_WellKnown_StringValue: case kUpb_WellKnown_BytesValue: case kUpb_WellKnown_BoolValue: - jsondec_wrapper(d, msg, m); + jsonenc_wrapper(e, msg, m); + break; + case kUpb_WellKnown_Value: + jsonenc_value(e, msg, m); + break; + case kUpb_WellKnown_ListValue: + jsonenc_listvalue(e, msg, m); + break; + case kUpb_WellKnown_Struct: + jsonenc_struct(e, msg, m); break; - default: - UPB_UNREACHABLE(); } } -static bool upb_JsonDecoder_Decode(jsondec* const d, upb_Message* const msg, - const upb_MessageDef* const m) { - if (UPB_SETJMP(d->err)) return false; - - jsondec_tomsg(d, msg, m); - - // Consume any trailing whitespace before checking if we read the entire - // input. - jsondec_consumews(d); - - if (d->ptr == d->end) { - return true; - } else { - jsondec_seterrmsg(d, "unexpected trailing characters"); - return false; +static void jsonenc_scalar(jsonenc* e, upb_MessageValue val, + const upb_FieldDef* f) { + switch (upb_FieldDef_CType(f)) { + case kUpb_CType_Bool: + jsonenc_putstr(e, val.bool_val ? "true" : "false"); + break; + case kUpb_CType_Float: + upb_JsonEncode_Float(e, val.float_val); + break; + case kUpb_CType_Double: + upb_JsonEncode_Double(e, val.double_val); + break; + case kUpb_CType_Int32: + jsonenc_printf(e, "%" PRId32, val.int32_val); + break; + case kUpb_CType_UInt32: + jsonenc_printf(e, "%" PRIu32, val.uint32_val); + break; + case kUpb_CType_Int64: + jsonenc_printf(e, "\"%" PRId64 "\"", val.int64_val); + break; + case kUpb_CType_UInt64: + jsonenc_printf(e, "\"%" PRIu64 "\"", val.uint64_val); + break; + case kUpb_CType_String: + jsonenc_string(e, val.str_val); + break; + case kUpb_CType_Bytes: + jsonenc_bytes(e, val.str_val); + break; + case kUpb_CType_Enum: + jsonenc_enum(val.int32_val, f, e); + break; + case kUpb_CType_Message: + jsonenc_msgfield(e, val.msg_val, upb_FieldDef_MessageSubDef(f)); + break; } } -bool upb_JsonDecode(const char* buf, size_t size, upb_Message* msg, - const upb_MessageDef* m, const upb_DefPool* symtab, - int options, upb_Arena* arena, upb_Status* status) { - jsondec d; - - if (size == 0) return true; +static void jsonenc_mapkey(jsonenc* e, upb_MessageValue val, + const upb_FieldDef* f) { + jsonenc_putstr(e, "\""); - d.ptr = buf; - d.end = buf + size; - d.arena = arena; - d.symtab = symtab; - d.status = status; - d.options = options; - d.depth = 64; - d.line = 1; - d.line_begin = d.ptr; - d.debug_field = NULL; - d.is_first = false; + switch (upb_FieldDef_CType(f)) { + case kUpb_CType_Bool: + jsonenc_putstr(e, val.bool_val ? "true" : "false"); + break; + case kUpb_CType_Int32: + jsonenc_printf(e, "%" PRId32, val.int32_val); + break; + case kUpb_CType_UInt32: + jsonenc_printf(e, "%" PRIu32, val.uint32_val); + break; + case kUpb_CType_Int64: + jsonenc_printf(e, "%" PRId64, val.int64_val); + break; + case kUpb_CType_UInt64: + jsonenc_printf(e, "%" PRIu64, val.uint64_val); + break; + case kUpb_CType_String: + jsonenc_stringbody(e, val.str_val); + break; + default: + UPB_UNREACHABLE(); + } - return upb_JsonDecoder_Decode(&d, msg, m); + jsonenc_putstr(e, "\":"); } +static void jsonenc_array(jsonenc* e, const upb_Array* arr, + const upb_FieldDef* f) { + size_t i; + size_t size = arr ? upb_Array_Size(arr) : 0; + bool first = true; -#include -#include -#include -#include -#include -#include + jsonenc_putstr(e, "["); + for (i = 0; i < size; i++) { + jsonenc_putsep(e, ",", &first); + jsonenc_scalar(e, upb_Array_Get(arr, i), f); + } -// Must be last. + jsonenc_putstr(e, "]"); +} -typedef struct { - char *buf, *ptr, *end; - size_t overflow; - int indent_depth; - int options; - const upb_DefPool* ext_pool; - jmp_buf err; - upb_Status* status; - upb_Arena* arena; -} jsonenc; - -static void jsonenc_msg(jsonenc* e, const upb_Message* msg, - const upb_MessageDef* m); -static void jsonenc_scalar(jsonenc* e, upb_MessageValue val, - const upb_FieldDef* f); -static void jsonenc_msgfield(jsonenc* e, const upb_Message* msg, - const upb_MessageDef* m); -static void jsonenc_msgfields(jsonenc* e, const upb_Message* msg, - const upb_MessageDef* m, bool first); -static void jsonenc_value(jsonenc* e, const upb_Message* msg, - const upb_MessageDef* m); +static void jsonenc_map(jsonenc* e, const upb_Map* map, const upb_FieldDef* f) { + jsonenc_putstr(e, "{"); -UPB_NORETURN static void jsonenc_err(jsonenc* e, const char* msg) { - upb_Status_SetErrorMessage(e->status, msg); - longjmp(e->err, 1); -} + const upb_MessageDef* entry = upb_FieldDef_MessageSubDef(f); + const upb_FieldDef* key_f = upb_MessageDef_FindFieldByNumber(entry, 1); + const upb_FieldDef* val_f = upb_MessageDef_FindFieldByNumber(entry, 2); -UPB_PRINTF(2, 3) -UPB_NORETURN static void jsonenc_errf(jsonenc* e, const char* fmt, ...) { - va_list argp; - va_start(argp, fmt); - upb_Status_VSetErrorFormat(e->status, fmt, argp); - va_end(argp); - longjmp(e->err, 1); -} + if (map) { + size_t iter = kUpb_Map_Begin; + bool first = true; -static upb_Arena* jsonenc_arena(jsonenc* e) { - /* Create lazily, since it's only needed for Any */ - if (!e->arena) { - e->arena = upb_Arena_New(); + upb_MessageValue key, val; + while (upb_Map_Next(map, &key, &val, &iter)) { + jsonenc_putsep(e, ",", &first); + jsonenc_mapkey(e, key, key_f); + jsonenc_scalar(e, val, val_f); + } } - return e->arena; + + jsonenc_putstr(e, "}"); } -static void jsonenc_putbytes(jsonenc* e, const void* data, size_t len) { - size_t have = e->end - e->ptr; - if (UPB_LIKELY(have >= len)) { - memcpy(e->ptr, data, len); - e->ptr += len; +static void jsonenc_fieldval(jsonenc* e, const upb_FieldDef* f, + upb_MessageValue val, bool* first) { + const char* name; + + jsonenc_putsep(e, ",", first); + + if (upb_FieldDef_IsExtension(f)) { + // TODO: For MessageSet, I would have expected this to print the message + // name here, but Python doesn't appear to do this. We should do more + // research here about what various implementations do. + jsonenc_printf(e, "\"[%s]\":", upb_FieldDef_FullName(f)); } else { - if (have) { - memcpy(e->ptr, data, have); - e->ptr += have; + if (e->options & upb_JsonEncode_UseProtoNames) { + name = upb_FieldDef_Name(f); + } else { + name = upb_FieldDef_JsonName(f); } - e->overflow += (len - have); + jsonenc_printf(e, "\"%s\":", name); } -} -static void jsonenc_putstr(jsonenc* e, const char* str) { - jsonenc_putbytes(e, str, strlen(str)); + if (upb_FieldDef_IsMap(f)) { + jsonenc_map(e, val.map_val, f); + } else if (upb_FieldDef_IsRepeated(f)) { + jsonenc_array(e, val.array_val, f); + } else { + jsonenc_scalar(e, val, f); + } } -UPB_PRINTF(2, 3) -static void jsonenc_printf(jsonenc* e, const char* fmt, ...) { - size_t n; - size_t have = e->end - e->ptr; - va_list args; - - va_start(args, fmt); - n = _upb_vsnprintf(e->ptr, have, fmt, args); - va_end(args); +static void jsonenc_msgfields(jsonenc* e, const upb_Message* msg, + const upb_MessageDef* m, bool first) { + upb_MessageValue val; + const upb_FieldDef* f; - if (UPB_LIKELY(have > n)) { - e->ptr += n; + if (e->options & upb_JsonEncode_EmitDefaults) { + /* Iterate over all fields. */ + int i = 0; + int n = upb_MessageDef_FieldCount(m); + for (i = 0; i < n; i++) { + f = upb_MessageDef_Field(m, i); + if (!upb_FieldDef_HasPresence(f) || upb_Message_HasFieldByDef(msg, f)) { + jsonenc_fieldval(e, f, upb_Message_GetFieldByDef(msg, f), &first); + } + } } else { - e->ptr = UPB_PTRADD(e->ptr, have); - e->overflow += (n - have); + /* Iterate over non-empty fields. */ + size_t iter = kUpb_Message_Begin; + while (upb_Message_Next(msg, m, e->ext_pool, &f, &val, &iter)) { + jsonenc_fieldval(e, f, val, &first); + } } } -static void jsonenc_nanos(jsonenc* e, int32_t nanos) { - int digits = 9; +static void jsonenc_msg(jsonenc* e, const upb_Message* msg, + const upb_MessageDef* m) { + jsonenc_putstr(e, "{"); + jsonenc_msgfields(e, msg, m, true); + jsonenc_putstr(e, "}"); +} - if (nanos == 0) return; - if (nanos < 0 || nanos >= 1000000000) { - jsonenc_err(e, "error formatting timestamp as JSON: invalid nanos"); - } +static size_t jsonenc_nullz(jsonenc* e, size_t size) { + size_t ret = e->ptr - e->buf + e->overflow; - while (nanos % 1000 == 0) { - nanos /= 1000; - digits -= 3; + if (size > 0) { + if (e->ptr == e->end) e->ptr--; + *e->ptr = '\0'; } - jsonenc_printf(e, ".%.*" PRId32, digits, nanos); + return ret; } -static void jsonenc_timestamp(jsonenc* e, const upb_Message* msg, - const upb_MessageDef* m) { - const upb_FieldDef* seconds_f = upb_MessageDef_FindFieldByNumber(m, 1); - const upb_FieldDef* nanos_f = upb_MessageDef_FindFieldByNumber(m, 2); - int64_t seconds = upb_Message_GetFieldByDef(msg, seconds_f).int64_val; - int32_t nanos = upb_Message_GetFieldByDef(msg, nanos_f).int32_val; - int L, N, I, J, K, hour, min, sec; +static size_t upb_JsonEncoder_Encode(jsonenc* const e, + const upb_Message* const msg, + const upb_MessageDef* const m, + const size_t size) { + if (UPB_SETJMP(e->err) != 0) return -1; - if (seconds < -62135596800) { - jsonenc_err(e, - "error formatting timestamp as JSON: minimum acceptable value " - "is 0001-01-01T00:00:00Z"); - } else if (seconds > 253402300799) { - jsonenc_err(e, - "error formatting timestamp as JSON: maximum acceptable value " - "is 9999-12-31T23:59:59Z"); - } + jsonenc_msgfield(e, msg, m); + if (e->arena) upb_Arena_Free(e->arena); + return jsonenc_nullz(e, size); +} - /* Julian Day -> Y/M/D, Algorithm from: - * Fliegel, H. F., and Van Flandern, T. C., "A Machine Algorithm for - * Processing Calendar Dates," Communications of the Association of - * Computing Machines, vol. 11 (1968), p. 657. */ - seconds += 62135596800; // Ensure seconds is positive. - L = (int)(seconds / 86400) - 719162 + 68569 + 2440588; - N = 4 * L / 146097; - L = L - (146097 * N + 3) / 4; - I = 4000 * (L + 1) / 1461001; - L = L - 1461 * I / 4 + 31; - J = 80 * L / 2447; - K = L - 2447 * J / 80; - L = J / 11; - J = J + 2 - 12 * L; - I = 100 * (N - 49) + I + L; +size_t upb_JsonEncode(const upb_Message* msg, const upb_MessageDef* m, + const upb_DefPool* ext_pool, int options, char* buf, + size_t size, upb_Status* status) { + jsonenc e; - sec = seconds % 60; - min = (seconds / 60) % 60; - hour = (seconds / 3600) % 24; + e.buf = buf; + e.ptr = buf; + e.end = UPB_PTRADD(buf, size); + e.overflow = 0; + e.options = options; + e.ext_pool = ext_pool; + e.status = status; + e.arena = NULL; - jsonenc_printf(e, "\"%04d-%02d-%02dT%02d:%02d:%02d", I, J, K, hour, min, sec); - jsonenc_nanos(e, nanos); - jsonenc_putstr(e, "Z\""); + return upb_JsonEncoder_Encode(&e, msg, m, size); } -static void jsonenc_duration(jsonenc* e, const upb_Message* msg, - const upb_MessageDef* m) { - const upb_FieldDef* seconds_f = upb_MessageDef_FindFieldByNumber(m, 1); - const upb_FieldDef* nanos_f = upb_MessageDef_FindFieldByNumber(m, 2); - int64_t seconds = upb_Message_GetFieldByDef(msg, seconds_f).int64_val; - int32_t nanos = upb_Message_GetFieldByDef(msg, nanos_f).int32_val; - bool negative = false; - if (seconds > 315576000000 || seconds < -315576000000 || - (seconds != 0 && nanos != 0 && (seconds < 0) != (nanos < 0))) { - jsonenc_err(e, "bad duration"); - } +#include - if (seconds < 0) { - negative = true; - seconds = -seconds; - } - if (nanos < 0) { - negative = true; - nanos = -nanos; - } +// Must be last. - jsonenc_putstr(e, "\""); - if (negative) { - jsonenc_putstr(e, "-"); +static void* upb_global_allocfunc(upb_alloc* alloc, void* ptr, size_t oldsize, + size_t size) { + UPB_UNUSED(alloc); + UPB_UNUSED(oldsize); + if (size == 0) { + free(ptr); + return NULL; + } else { + return realloc(ptr, size); } - jsonenc_printf(e, "%" PRId64, seconds); - jsonenc_nanos(e, nanos); - jsonenc_putstr(e, "s\""); } -static void jsonenc_enum(int32_t val, const upb_FieldDef* f, jsonenc* e) { - const upb_EnumDef* e_def = upb_FieldDef_EnumSubDef(f); +upb_alloc upb_alloc_global = {&upb_global_allocfunc}; - if (strcmp(upb_EnumDef_FullName(e_def), "google.protobuf.NullValue") == 0) { - jsonenc_putstr(e, "null"); - } else { - const upb_EnumValueDef* ev = - (e->options & upb_JsonEncode_FormatEnumsAsIntegers) - ? NULL - : upb_EnumDef_FindValueByNumber(e_def, val); - if (ev) { - jsonenc_printf(e, "\"%s\"", upb_EnumValueDef_Name(ev)); - } else { - jsonenc_printf(e, "%" PRId32, val); - } - } -} +#include +#include -static void jsonenc_bytes(jsonenc* e, upb_StringView str) { - /* This is the regular base64, not the "web-safe" version. */ - static const char base64[] = - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; - const unsigned char* ptr = (unsigned char*)str.data; - const unsigned char* end = UPB_PTRADD(ptr, str.size); - char buf[4]; - jsonenc_putstr(e, "\""); +// Must be last. - while (end - ptr >= 3) { - buf[0] = base64[ptr[0] >> 2]; - buf[1] = base64[((ptr[0] & 0x3) << 4) | (ptr[1] >> 4)]; - buf[2] = base64[((ptr[1] & 0xf) << 2) | (ptr[2] >> 6)]; - buf[3] = base64[ptr[2] & 0x3f]; - jsonenc_putbytes(e, buf, 4); - ptr += 3; - } +typedef struct upb_MemBlock { + // Atomic only for the benefit of SpaceAllocated(). + UPB_ATOMIC(struct upb_MemBlock*) next; + uint32_t size; + // Data follows. +} upb_MemBlock; - switch (end - ptr) { - case 2: - buf[0] = base64[ptr[0] >> 2]; - buf[1] = base64[((ptr[0] & 0x3) << 4) | (ptr[1] >> 4)]; - buf[2] = base64[(ptr[1] & 0xf) << 2]; - buf[3] = '='; - jsonenc_putbytes(e, buf, 4); - break; - case 1: - buf[0] = base64[ptr[0] >> 2]; - buf[1] = base64[((ptr[0] & 0x3) << 4)]; - buf[2] = '='; - buf[3] = '='; - jsonenc_putbytes(e, buf, 4); - break; - } +typedef struct upb_ArenaInternal { + // upb_alloc* together with a low bit which signals if there is an initial + // block. + uintptr_t block_alloc; - jsonenc_putstr(e, "\""); + // When multiple arenas are fused together, each arena points to a parent + // arena (root points to itself). The root tracks how many live arenas + // reference it. + + // The low bit is tagged: + // 0: pointer to parent + // 1: count, left shifted by one + UPB_ATOMIC(uintptr_t) parent_or_count; + + // All nodes that are fused together are in a singly-linked list. + // == NULL at end of list. + UPB_ATOMIC(struct upb_ArenaInternal*) next; + + // The last element of the linked list. This is present only as an + // optimization, so that we do not have to iterate over all members for every + // fuse. Only significant for an arena root. In other cases it is ignored. + // == self when no other list members. + UPB_ATOMIC(struct upb_ArenaInternal*) tail; + + // Linked list of blocks to free/cleanup. Atomic only for the benefit of + // upb_Arena_SpaceAllocated(). + UPB_ATOMIC(upb_MemBlock*) blocks; +} upb_ArenaInternal; + +// All public + private state for an arena. +typedef struct { + upb_Arena head; + upb_ArenaInternal body; +} upb_ArenaState; + +typedef struct { + upb_ArenaInternal* root; + uintptr_t tagged_count; +} upb_ArenaRoot; + +static const size_t kUpb_MemblockReserve = + UPB_ALIGN_UP(sizeof(upb_MemBlock), UPB_MALLOC_ALIGN); + +// Extracts the (upb_ArenaInternal*) from a (upb_Arena*) +static upb_ArenaInternal* upb_Arena_Internal(const upb_Arena* a) { + return &((upb_ArenaState*)a)->body; } -static void jsonenc_stringbody(jsonenc* e, upb_StringView str) { - const char* ptr = str.data; - const char* end = UPB_PTRADD(ptr, str.size); +static bool _upb_Arena_IsTaggedRefcount(uintptr_t parent_or_count) { + return (parent_or_count & 1) == 1; +} - while (ptr < end) { - switch (*ptr) { - case '\n': - jsonenc_putstr(e, "\\n"); - break; - case '\r': - jsonenc_putstr(e, "\\r"); - break; - case '\t': - jsonenc_putstr(e, "\\t"); - break; - case '\"': - jsonenc_putstr(e, "\\\""); - break; - case '\f': - jsonenc_putstr(e, "\\f"); - break; - case '\b': - jsonenc_putstr(e, "\\b"); - break; - case '\\': - jsonenc_putstr(e, "\\\\"); - break; - default: - if ((uint8_t)*ptr < 0x20) { - jsonenc_printf(e, "\\u%04x", (int)(uint8_t)*ptr); - } else { - /* This could be a non-ASCII byte. We rely on the string being valid - * UTF-8. */ - jsonenc_putbytes(e, ptr, 1); - } - break; - } - ptr++; - } +static bool _upb_Arena_IsTaggedPointer(uintptr_t parent_or_count) { + return (parent_or_count & 1) == 0; } -static void jsonenc_string(jsonenc* e, upb_StringView str) { - jsonenc_putstr(e, "\""); - jsonenc_stringbody(e, str); - jsonenc_putstr(e, "\""); +static uintptr_t _upb_Arena_RefCountFromTagged(uintptr_t parent_or_count) { + UPB_ASSERT(_upb_Arena_IsTaggedRefcount(parent_or_count)); + return parent_or_count >> 1; } -static bool upb_JsonEncode_HandleSpecialDoubles(jsonenc* e, double val) { - if (val == INFINITY) { - jsonenc_putstr(e, "\"Infinity\""); - } else if (val == -INFINITY) { - jsonenc_putstr(e, "\"-Infinity\""); - } else if (val != val) { - jsonenc_putstr(e, "\"NaN\""); - } else { - return false; - } - return true; +static uintptr_t _upb_Arena_TaggedFromRefcount(uintptr_t refcount) { + uintptr_t parent_or_count = (refcount << 1) | 1; + UPB_ASSERT(_upb_Arena_IsTaggedRefcount(parent_or_count)); + return parent_or_count; } -static void upb_JsonEncode_Double(jsonenc* e, double val) { - if (upb_JsonEncode_HandleSpecialDoubles(e, val)) return; - char buf[32]; - _upb_EncodeRoundTripDouble(val, buf, sizeof(buf)); - jsonenc_putstr(e, buf); +static upb_ArenaInternal* _upb_Arena_PointerFromTagged( + uintptr_t parent_or_count) { + UPB_ASSERT(_upb_Arena_IsTaggedPointer(parent_or_count)); + return (upb_ArenaInternal*)parent_or_count; } -static void upb_JsonEncode_Float(jsonenc* e, float val) { - if (upb_JsonEncode_HandleSpecialDoubles(e, val)) return; - char buf[32]; - _upb_EncodeRoundTripFloat(val, buf, sizeof(buf)); - jsonenc_putstr(e, buf); +static uintptr_t _upb_Arena_TaggedFromPointer(upb_ArenaInternal* ai) { + uintptr_t parent_or_count = (uintptr_t)ai; + UPB_ASSERT(_upb_Arena_IsTaggedPointer(parent_or_count)); + return parent_or_count; } -static void jsonenc_wrapper(jsonenc* e, const upb_Message* msg, - const upb_MessageDef* m) { - const upb_FieldDef* val_f = upb_MessageDef_FindFieldByNumber(m, 1); - upb_MessageValue val = upb_Message_GetFieldByDef(msg, val_f); - jsonenc_scalar(e, val, val_f); +static upb_alloc* _upb_ArenaInternal_BlockAlloc(upb_ArenaInternal* ai) { + return (upb_alloc*)(ai->block_alloc & ~0x1); } -static const upb_MessageDef* jsonenc_getanymsg(jsonenc* e, - upb_StringView type_url) { - /* Find last '/', if any. */ - const char* end = type_url.data + type_url.size; - const char* ptr = end; - const upb_MessageDef* ret; +static uintptr_t _upb_Arena_MakeBlockAlloc(upb_alloc* alloc, bool has_initial) { + uintptr_t alloc_uint = (uintptr_t)alloc; + UPB_ASSERT((alloc_uint & 1) == 0); + return alloc_uint | (has_initial ? 1 : 0); +} - if (!e->ext_pool) { - jsonenc_err(e, "Tried to encode Any, but no symtab was provided"); - } +static bool _upb_ArenaInternal_HasInitialBlock(upb_ArenaInternal* ai) { + return ai->block_alloc & 0x1; +} - if (type_url.size == 0) goto badurl; +static upb_ArenaRoot _upb_Arena_FindRoot(upb_Arena* a) { + upb_ArenaInternal* ai = upb_Arena_Internal(a); + uintptr_t poc = upb_Atomic_Load(&ai->parent_or_count, memory_order_acquire); + while (_upb_Arena_IsTaggedPointer(poc)) { + upb_ArenaInternal* next = _upb_Arena_PointerFromTagged(poc); + UPB_ASSERT(ai != next); + uintptr_t next_poc = + upb_Atomic_Load(&next->parent_or_count, memory_order_acquire); - while (true) { - if (--ptr == type_url.data) { - /* Type URL must contain at least one '/', with host before. */ - goto badurl; - } - if (*ptr == '/') { - ptr++; - break; + if (_upb_Arena_IsTaggedPointer(next_poc)) { + // To keep complexity down, we lazily collapse levels of the tree. This + // keeps it flat in the final case, but doesn't cost much incrementally. + // + // Path splitting keeps time complexity down, see: + // https://en.wikipedia.org/wiki/Disjoint-set_data_structure + // + // We can safely use a relaxed atomic here because all threads doing this + // will converge on the same value and we don't need memory orderings to + // be visible. + // + // This is true because: + // - If no fuses occur, this will eventually become the root. + // - If fuses are actively occurring, the root may change, but the + // invariant is that `parent_or_count` merely points to *a* parent. + // + // In other words, it is moving towards "the" root, and that root may move + // further away over time, but the path towards that root will continue to + // be valid and the creation of the path carries all the memory orderings + // required. + UPB_ASSERT(ai != _upb_Arena_PointerFromTagged(next_poc)); + upb_Atomic_Store(&ai->parent_or_count, next_poc, memory_order_relaxed); } + ai = next; + poc = next_poc; } + return (upb_ArenaRoot){.root = ai, .tagged_count = poc}; +} - ret = upb_DefPool_FindMessageByNameWithSize(e->ext_pool, ptr, end - ptr); +size_t upb_Arena_SpaceAllocated(upb_Arena* arena) { + upb_ArenaInternal* ai = _upb_Arena_FindRoot(arena).root; + size_t memsize = 0; - if (!ret) { - jsonenc_errf(e, "Couldn't find Any type: %.*s", (int)(end - ptr), ptr); + while (ai != NULL) { + upb_MemBlock* block = upb_Atomic_Load(&ai->blocks, memory_order_relaxed); + while (block != NULL) { + memsize += sizeof(upb_MemBlock) + block->size; + block = upb_Atomic_Load(&block->next, memory_order_relaxed); + } + ai = upb_Atomic_Load(&ai->next, memory_order_relaxed); } - return ret; - -badurl: - jsonenc_errf(e, "Bad type URL: " UPB_STRINGVIEW_FORMAT, - UPB_STRINGVIEW_ARGS(type_url)); + return memsize; } -static void jsonenc_any(jsonenc* e, const upb_Message* msg, - const upb_MessageDef* m) { - const upb_FieldDef* type_url_f = upb_MessageDef_FindFieldByNumber(m, 1); - const upb_FieldDef* value_f = upb_MessageDef_FindFieldByNumber(m, 2); - upb_StringView type_url = upb_Message_GetFieldByDef(msg, type_url_f).str_val; - upb_StringView value = upb_Message_GetFieldByDef(msg, value_f).str_val; - const upb_MessageDef* any_m = jsonenc_getanymsg(e, type_url); - const upb_MiniTable* any_layout = upb_MessageDef_MiniTable(any_m); - upb_Arena* arena = jsonenc_arena(e); - upb_Message* any = upb_Message_New(any_layout, arena); - - if (upb_Decode(value.data, value.size, any, any_layout, NULL, 0, arena) != - kUpb_DecodeStatus_Ok) { - jsonenc_err(e, "Error decoding message in Any"); +uint32_t upb_Arena_DebugRefCount(upb_Arena* a) { + upb_ArenaInternal* ai = upb_Arena_Internal(a); + // These loads could probably be relaxed, but given that this is debug-only, + // it's not worth introducing a new variant for it. + uintptr_t poc = upb_Atomic_Load(&ai->parent_or_count, memory_order_acquire); + while (_upb_Arena_IsTaggedPointer(poc)) { + ai = _upb_Arena_PointerFromTagged(poc); + poc = upb_Atomic_Load(&ai->parent_or_count, memory_order_acquire); } + return _upb_Arena_RefCountFromTagged(poc); +} - jsonenc_putstr(e, "{\"@type\":"); - jsonenc_string(e, type_url); +static void _upb_Arena_AddBlock(upb_Arena* a, void* ptr, size_t size) { + upb_ArenaInternal* ai = upb_Arena_Internal(a); + upb_MemBlock* block = ptr; - if (upb_MessageDef_WellKnownType(any_m) == kUpb_WellKnown_Unspecified) { - /* Regular messages: {"@type": "...","foo": 1, "bar": 2} */ - jsonenc_msgfields(e, any, any_m, false); - } else { - /* Well-known type: {"@type": "...","value": } */ - jsonenc_putstr(e, ",\"value\":"); - jsonenc_msgfield(e, any, any_m); - } + // Insert into linked list. + block->size = (uint32_t)size; + upb_Atomic_Init(&block->next, ai->blocks); + upb_Atomic_Store(&ai->blocks, block, memory_order_release); - jsonenc_putstr(e, "}"); -} + a->UPB_PRIVATE(ptr) = UPB_PTR_AT(block, kUpb_MemblockReserve, char); + a->UPB_PRIVATE(end) = UPB_PTR_AT(block, size, char); -static void jsonenc_putsep(jsonenc* e, const char* str, bool* first) { - if (*first) { - *first = false; - } else { - jsonenc_putstr(e, str); - } + UPB_POISON_MEMORY_REGION(a->UPB_PRIVATE(ptr), + a->UPB_PRIVATE(end) - a->UPB_PRIVATE(ptr)); } -static void jsonenc_fieldpath(jsonenc* e, upb_StringView path) { - const char* ptr = path.data; - const char* end = ptr + path.size; - - while (ptr < end) { - char ch = *ptr; +static bool _upb_Arena_AllocBlock(upb_Arena* a, size_t size) { + upb_ArenaInternal* ai = upb_Arena_Internal(a); + if (!ai->block_alloc) return false; + upb_MemBlock* last_block = upb_Atomic_Load(&ai->blocks, memory_order_acquire); + size_t last_size = last_block != NULL ? last_block->size : 128; + size_t block_size = UPB_MAX(size, last_size * 2) + kUpb_MemblockReserve; + upb_MemBlock* block = + upb_malloc(_upb_ArenaInternal_BlockAlloc(ai), block_size); - if (ch >= 'A' && ch <= 'Z') { - jsonenc_err(e, "Field mask element may not have upper-case letter."); - } else if (ch == '_') { - if (ptr == end - 1 || *(ptr + 1) < 'a' || *(ptr + 1) > 'z') { - jsonenc_err(e, "Underscore must be followed by a lowercase letter."); - } - ch = *++ptr - 32; - } + if (!block) return false; + _upb_Arena_AddBlock(a, block, block_size); + UPB_ASSERT(UPB_PRIVATE(_upb_ArenaHas)(a) >= size); + return true; +} - jsonenc_putbytes(e, &ch, 1); - ptr++; - } +void* UPB_PRIVATE(_upb_Arena_SlowMalloc)(upb_Arena* a, size_t size) { + if (!_upb_Arena_AllocBlock(a, size)) return NULL; // OOM + return upb_Arena_Malloc(a, size - UPB_ASAN_GUARD_SIZE); } -static void jsonenc_fieldmask(jsonenc* e, const upb_Message* msg, - const upb_MessageDef* m) { - const upb_FieldDef* paths_f = upb_MessageDef_FindFieldByNumber(m, 1); - const upb_Array* paths = upb_Message_GetFieldByDef(msg, paths_f).array_val; - bool first = true; - size_t i, n = 0; +static upb_Arena* _upb_Arena_InitSlow(upb_alloc* alloc) { + const size_t first_block_overhead = + sizeof(upb_ArenaState) + kUpb_MemblockReserve; + upb_ArenaState* a; - if (paths) n = upb_Array_Size(paths); + // We need to malloc the initial block. + char* mem; + size_t n = first_block_overhead + 256; + if (!alloc || !(mem = upb_malloc(alloc, n))) { + return NULL; + } - jsonenc_putstr(e, "\""); + a = UPB_PTR_AT(mem, n - sizeof(upb_ArenaState), upb_ArenaState); + n -= sizeof(upb_ArenaState); - for (i = 0; i < n; i++) { - jsonenc_putsep(e, ",", &first); - jsonenc_fieldpath(e, upb_Array_Get(paths, i).str_val); - } + a->body.block_alloc = _upb_Arena_MakeBlockAlloc(alloc, 0); + upb_Atomic_Init(&a->body.parent_or_count, _upb_Arena_TaggedFromRefcount(1)); + upb_Atomic_Init(&a->body.next, NULL); + upb_Atomic_Init(&a->body.tail, &a->body); + upb_Atomic_Init(&a->body.blocks, NULL); - jsonenc_putstr(e, "\""); -} + _upb_Arena_AddBlock(&a->head, mem, n); -static void jsonenc_struct(jsonenc* e, const upb_Message* msg, - const upb_MessageDef* m) { - jsonenc_putstr(e, "{"); + return &a->head; +} - const upb_FieldDef* fields_f = upb_MessageDef_FindFieldByNumber(m, 1); - const upb_Map* fields = upb_Message_GetFieldByDef(msg, fields_f).map_val; +upb_Arena* upb_Arena_Init(void* mem, size_t n, upb_alloc* alloc) { + UPB_ASSERT(sizeof(void*) * UPB_ARENA_SIZE_HACK >= sizeof(upb_ArenaState)); + upb_ArenaState* a; - if (fields) { - const upb_MessageDef* entry_m = upb_FieldDef_MessageSubDef(fields_f); - const upb_FieldDef* value_f = upb_MessageDef_FindFieldByNumber(entry_m, 2); + if (n) { + /* Align initial pointer up so that we return properly-aligned pointers. */ + void* aligned = (void*)UPB_ALIGN_UP((uintptr_t)mem, UPB_MALLOC_ALIGN); + size_t delta = (uintptr_t)aligned - (uintptr_t)mem; + n = delta <= n ? n - delta : 0; + mem = aligned; + } - size_t iter = kUpb_Map_Begin; - bool first = true; + /* Round block size down to alignof(*a) since we will allocate the arena + * itself at the end. */ + n = UPB_ALIGN_DOWN(n, UPB_ALIGN_OF(upb_ArenaState)); - upb_MessageValue key, val; - while (upb_Map_Next(fields, &key, &val, &iter)) { - jsonenc_putsep(e, ",", &first); - jsonenc_string(e, key.str_val); - jsonenc_putstr(e, ":"); - jsonenc_value(e, val.msg_val, upb_FieldDef_MessageSubDef(value_f)); - } + if (UPB_UNLIKELY(n < sizeof(upb_ArenaState))) { + return _upb_Arena_InitSlow(alloc); } - jsonenc_putstr(e, "}"); -} + a = UPB_PTR_AT(mem, n - sizeof(upb_ArenaState), upb_ArenaState); -static void jsonenc_listvalue(jsonenc* e, const upb_Message* msg, - const upb_MessageDef* m) { - const upb_FieldDef* values_f = upb_MessageDef_FindFieldByNumber(m, 1); - const upb_MessageDef* values_m = upb_FieldDef_MessageSubDef(values_f); - const upb_Array* values = upb_Message_GetFieldByDef(msg, values_f).array_val; - size_t i; - bool first = true; + upb_Atomic_Init(&a->body.parent_or_count, _upb_Arena_TaggedFromRefcount(1)); + upb_Atomic_Init(&a->body.next, NULL); + upb_Atomic_Init(&a->body.tail, &a->body); + upb_Atomic_Init(&a->body.blocks, NULL); - jsonenc_putstr(e, "["); + a->body.block_alloc = _upb_Arena_MakeBlockAlloc(alloc, 1); + a->head.UPB_PRIVATE(ptr) = mem; + a->head.UPB_PRIVATE(end) = UPB_PTR_AT(mem, n - sizeof(upb_ArenaState), char); - if (values) { - const size_t size = upb_Array_Size(values); - for (i = 0; i < size; i++) { - upb_MessageValue elem = upb_Array_Get(values, i); + return &a->head; +} - jsonenc_putsep(e, ",", &first); - jsonenc_value(e, elem.msg_val, values_m); +static void _upb_Arena_DoFree(upb_ArenaInternal* ai) { + UPB_ASSERT(_upb_Arena_RefCountFromTagged(ai->parent_or_count) == 1); + + while (ai != NULL) { + // Load first since arena itself is likely from one of its blocks. + upb_ArenaInternal* next_arena = + (upb_ArenaInternal*)upb_Atomic_Load(&ai->next, memory_order_acquire); + upb_alloc* block_alloc = _upb_ArenaInternal_BlockAlloc(ai); + upb_MemBlock* block = upb_Atomic_Load(&ai->blocks, memory_order_acquire); + while (block != NULL) { + // Load first since we are deleting block. + upb_MemBlock* next_block = + upb_Atomic_Load(&block->next, memory_order_acquire); + upb_free(block_alloc, block); + block = next_block; } + ai = next_arena; } - - jsonenc_putstr(e, "]"); } -static void jsonenc_value(jsonenc* e, const upb_Message* msg, - const upb_MessageDef* m) { - /* TODO: do we want a reflection method to get oneof case? */ - size_t iter = kUpb_Message_Begin; - const upb_FieldDef* f; - upb_MessageValue val; +void upb_Arena_Free(upb_Arena* a) { + upb_ArenaInternal* ai = upb_Arena_Internal(a); + uintptr_t poc = upb_Atomic_Load(&ai->parent_or_count, memory_order_acquire); +retry: + while (_upb_Arena_IsTaggedPointer(poc)) { + ai = _upb_Arena_PointerFromTagged(poc); + poc = upb_Atomic_Load(&ai->parent_or_count, memory_order_acquire); + } - if (!upb_Message_Next(msg, m, NULL, &f, &val, &iter)) { - jsonenc_err(e, "No value set in Value proto"); + // compare_exchange or fetch_sub are RMW operations, which are more + // expensive then direct loads. As an optimization, we only do RMW ops + // when we need to update things for other threads to see. + if (poc == _upb_Arena_TaggedFromRefcount(1)) { + _upb_Arena_DoFree(ai); + return; } - switch (upb_FieldDef_Number(f)) { - case 1: - jsonenc_putstr(e, "null"); - break; - case 2: - if (upb_JsonEncode_HandleSpecialDoubles(e, val.double_val)) { - jsonenc_err( - e, - "google.protobuf.Value cannot encode double values for " - "infinity or nan, because they would be parsed as a string"); - } - upb_JsonEncode_Double(e, val.double_val); - break; - case 3: - jsonenc_string(e, val.str_val); - break; - case 4: - jsonenc_putstr(e, val.bool_val ? "true" : "false"); - break; - case 5: - jsonenc_struct(e, val.msg_val, upb_FieldDef_MessageSubDef(f)); - break; - case 6: - jsonenc_listvalue(e, val.msg_val, upb_FieldDef_MessageSubDef(f)); - break; + if (upb_Atomic_CompareExchangeWeak( + &ai->parent_or_count, &poc, + _upb_Arena_TaggedFromRefcount(_upb_Arena_RefCountFromTagged(poc) - 1), + memory_order_release, memory_order_acquire)) { + // We were >1 and we decremented it successfully, so we are done. + return; } + + // We failed our update, so someone has done something, retry the whole + // process, but the failed exchange reloaded `poc` for us. + goto retry; } -static void jsonenc_msgfield(jsonenc* e, const upb_Message* msg, - const upb_MessageDef* m) { - switch (upb_MessageDef_WellKnownType(m)) { - case kUpb_WellKnown_Unspecified: - jsonenc_msg(e, msg, m); - break; - case kUpb_WellKnown_Any: - jsonenc_any(e, msg, m); - break; - case kUpb_WellKnown_FieldMask: - jsonenc_fieldmask(e, msg, m); - break; - case kUpb_WellKnown_Duration: - jsonenc_duration(e, msg, m); - break; - case kUpb_WellKnown_Timestamp: - jsonenc_timestamp(e, msg, m); - break; - case kUpb_WellKnown_DoubleValue: - case kUpb_WellKnown_FloatValue: - case kUpb_WellKnown_Int64Value: - case kUpb_WellKnown_UInt64Value: - case kUpb_WellKnown_Int32Value: - case kUpb_WellKnown_UInt32Value: - case kUpb_WellKnown_StringValue: - case kUpb_WellKnown_BytesValue: - case kUpb_WellKnown_BoolValue: - jsonenc_wrapper(e, msg, m); - break; - case kUpb_WellKnown_Value: - jsonenc_value(e, msg, m); - break; - case kUpb_WellKnown_ListValue: - jsonenc_listvalue(e, msg, m); - break; - case kUpb_WellKnown_Struct: - jsonenc_struct(e, msg, m); - break; - } -} +static void _upb_Arena_DoFuseArenaLists(upb_ArenaInternal* const parent, + upb_ArenaInternal* child) { + upb_ArenaInternal* parent_tail = + upb_Atomic_Load(&parent->tail, memory_order_relaxed); -static void jsonenc_scalar(jsonenc* e, upb_MessageValue val, - const upb_FieldDef* f) { - switch (upb_FieldDef_CType(f)) { - case kUpb_CType_Bool: - jsonenc_putstr(e, val.bool_val ? "true" : "false"); - break; - case kUpb_CType_Float: - upb_JsonEncode_Float(e, val.float_val); - break; - case kUpb_CType_Double: - upb_JsonEncode_Double(e, val.double_val); - break; - case kUpb_CType_Int32: - jsonenc_printf(e, "%" PRId32, val.int32_val); - break; - case kUpb_CType_UInt32: - jsonenc_printf(e, "%" PRIu32, val.uint32_val); - break; - case kUpb_CType_Int64: - jsonenc_printf(e, "\"%" PRId64 "\"", val.int64_val); - break; - case kUpb_CType_UInt64: - jsonenc_printf(e, "\"%" PRIu64 "\"", val.uint64_val); - break; - case kUpb_CType_String: - jsonenc_string(e, val.str_val); - break; - case kUpb_CType_Bytes: - jsonenc_bytes(e, val.str_val); - break; - case kUpb_CType_Enum: - jsonenc_enum(val.int32_val, f, e); - break; - case kUpb_CType_Message: - jsonenc_msgfield(e, val.msg_val, upb_FieldDef_MessageSubDef(f)); - break; - } -} + do { + // Our tail might be stale, but it will always converge to the true tail. + upb_ArenaInternal* parent_tail_next = + upb_Atomic_Load(&parent_tail->next, memory_order_relaxed); + while (parent_tail_next != NULL) { + parent_tail = parent_tail_next; + parent_tail_next = + upb_Atomic_Load(&parent_tail->next, memory_order_relaxed); + } -static void jsonenc_mapkey(jsonenc* e, upb_MessageValue val, - const upb_FieldDef* f) { - jsonenc_putstr(e, "\""); + upb_ArenaInternal* displaced = + upb_Atomic_Exchange(&parent_tail->next, child, memory_order_relaxed); + parent_tail = upb_Atomic_Load(&child->tail, memory_order_relaxed); - switch (upb_FieldDef_CType(f)) { - case kUpb_CType_Bool: - jsonenc_putstr(e, val.bool_val ? "true" : "false"); - break; - case kUpb_CType_Int32: - jsonenc_printf(e, "%" PRId32, val.int32_val); - break; - case kUpb_CType_UInt32: - jsonenc_printf(e, "%" PRIu32, val.uint32_val); - break; - case kUpb_CType_Int64: - jsonenc_printf(e, "%" PRId64, val.int64_val); - break; - case kUpb_CType_UInt64: - jsonenc_printf(e, "%" PRIu64, val.uint64_val); - break; - case kUpb_CType_String: - jsonenc_stringbody(e, val.str_val); - break; - default: - UPB_UNREACHABLE(); - } + // If we displaced something that got installed racily, we can simply + // reinstall it on our new tail. + child = displaced; + } while (child != NULL); - jsonenc_putstr(e, "\":"); + upb_Atomic_Store(&parent->tail, parent_tail, memory_order_relaxed); } -static void jsonenc_array(jsonenc* e, const upb_Array* arr, - const upb_FieldDef* f) { - size_t i; - size_t size = arr ? upb_Array_Size(arr) : 0; - bool first = true; +static upb_ArenaInternal* _upb_Arena_DoFuse(upb_Arena* a1, upb_Arena* a2, + uintptr_t* ref_delta) { + // `parent_or_count` has two disctint modes + // - parent pointer mode + // - refcount mode + // + // In parent pointer mode, it may change what pointer it refers to in the + // tree, but it will always approach a root. Any operation that walks the + // tree to the root may collapse levels of the tree concurrently. + upb_ArenaRoot r1 = _upb_Arena_FindRoot(a1); + upb_ArenaRoot r2 = _upb_Arena_FindRoot(a2); - jsonenc_putstr(e, "["); + if (r1.root == r2.root) return r1.root; // Already fused. - for (i = 0; i < size; i++) { - jsonenc_putsep(e, ",", &first); - jsonenc_scalar(e, upb_Array_Get(arr, i), f); + // Avoid cycles by always fusing into the root with the lower address. + if ((uintptr_t)r1.root > (uintptr_t)r2.root) { + upb_ArenaRoot tmp = r1; + r1 = r2; + r2 = tmp; } - jsonenc_putstr(e, "]"); -} - -static void jsonenc_map(jsonenc* e, const upb_Map* map, const upb_FieldDef* f) { - jsonenc_putstr(e, "{"); - - const upb_MessageDef* entry = upb_FieldDef_MessageSubDef(f); - const upb_FieldDef* key_f = upb_MessageDef_FindFieldByNumber(entry, 1); - const upb_FieldDef* val_f = upb_MessageDef_FindFieldByNumber(entry, 2); - - if (map) { - size_t iter = kUpb_Map_Begin; - bool first = true; + // The moment we install `r1` as the parent for `r2` all racing frees may + // immediately begin decrementing `r1`'s refcount (including pending + // increments to that refcount and their frees!). We need to add `r2`'s refs + // now, so that `r1` can withstand any unrefs that come from r2. + // + // Note that while it is possible for `r2`'s refcount to increase + // asynchronously, we will not actually do the reparenting operation below + // unless `r2`'s refcount is unchanged from when we read it. + // + // Note that we may have done this previously, either to this node or a + // different node, during a previous and failed DoFuse() attempt. But we will + // not lose track of these refs because we always add them to our overall + // delta. + uintptr_t r2_untagged_count = r2.tagged_count & ~1; + uintptr_t with_r2_refs = r1.tagged_count + r2_untagged_count; + if (!upb_Atomic_CompareExchangeStrong( + &r1.root->parent_or_count, &r1.tagged_count, with_r2_refs, + memory_order_release, memory_order_acquire)) { + return NULL; + } - upb_MessageValue key, val; - while (upb_Map_Next(map, &key, &val, &iter)) { - jsonenc_putsep(e, ",", &first); - jsonenc_mapkey(e, key, key_f); - jsonenc_scalar(e, val, val_f); - } + // Perform the actual fuse by removing the refs from `r2` and swapping in the + // parent pointer. + if (!upb_Atomic_CompareExchangeStrong( + &r2.root->parent_or_count, &r2.tagged_count, + _upb_Arena_TaggedFromPointer(r1.root), memory_order_release, + memory_order_acquire)) { + // We'll need to remove the excess refs we added to r1 previously. + *ref_delta += r2_untagged_count; + return NULL; } - jsonenc_putstr(e, "}"); + // Now that the fuse has been performed (and can no longer fail) we need to + // append `r2` to `r1`'s linked list. + _upb_Arena_DoFuseArenaLists(r1.root, r2.root); + return r1.root; } -static void jsonenc_fieldval(jsonenc* e, const upb_FieldDef* f, - upb_MessageValue val, bool* first) { - const char* name; +static bool _upb_Arena_FixupRefs(upb_ArenaInternal* new_root, + uintptr_t ref_delta) { + if (ref_delta == 0) return true; // No fixup required. + uintptr_t poc = + upb_Atomic_Load(&new_root->parent_or_count, memory_order_relaxed); + if (_upb_Arena_IsTaggedPointer(poc)) return false; + uintptr_t with_refs = poc - ref_delta; + UPB_ASSERT(!_upb_Arena_IsTaggedPointer(with_refs)); + return upb_Atomic_CompareExchangeStrong(&new_root->parent_or_count, &poc, + with_refs, memory_order_relaxed, + memory_order_relaxed); +} - jsonenc_putsep(e, ",", first); +bool upb_Arena_Fuse(upb_Arena* a1, upb_Arena* a2) { + if (a1 == a2) return true; // trivial fuse - if (upb_FieldDef_IsExtension(f)) { - // TODO: For MessageSet, I would have expected this to print the message - // name here, but Python doesn't appear to do this. We should do more - // research here about what various implementations do. - jsonenc_printf(e, "\"[%s]\":", upb_FieldDef_FullName(f)); - } else { - if (e->options & upb_JsonEncode_UseProtoNames) { - name = upb_FieldDef_Name(f); - } else { - name = upb_FieldDef_JsonName(f); - } - jsonenc_printf(e, "\"%s\":", name); + upb_ArenaInternal* ai1 = upb_Arena_Internal(a1); + upb_ArenaInternal* ai2 = upb_Arena_Internal(a2); + + // Do not fuse initial blocks since we cannot lifetime extend them. + // Any other fuse scenario is allowed. + if (_upb_ArenaInternal_HasInitialBlock(ai1) || + _upb_ArenaInternal_HasInitialBlock(ai2)) { + return false; } - if (upb_FieldDef_IsMap(f)) { - jsonenc_map(e, val.map_val, f); - } else if (upb_FieldDef_IsRepeated(f)) { - jsonenc_array(e, val.array_val, f); - } else { - jsonenc_scalar(e, val, f); + // The number of refs we ultimately need to transfer to the new root. + uintptr_t ref_delta = 0; + while (true) { + upb_ArenaInternal* new_root = _upb_Arena_DoFuse(a1, a2, &ref_delta); + if (new_root != NULL && _upb_Arena_FixupRefs(new_root, ref_delta)) { + return true; + } } } -static void jsonenc_msgfields(jsonenc* e, const upb_Message* msg, - const upb_MessageDef* m, bool first) { - upb_MessageValue val; - const upb_FieldDef* f; - - if (e->options & upb_JsonEncode_EmitDefaults) { - /* Iterate over all fields. */ - int i = 0; - int n = upb_MessageDef_FieldCount(m); - for (i = 0; i < n; i++) { - f = upb_MessageDef_Field(m, i); - if (!upb_FieldDef_HasPresence(f) || upb_Message_HasFieldByDef(msg, f)) { - jsonenc_fieldval(e, f, upb_Message_GetFieldByDef(msg, f), &first); - } - } - } else { - /* Iterate over non-empty fields. */ - size_t iter = kUpb_Message_Begin; - while (upb_Message_Next(msg, m, e->ext_pool, &f, &val, &iter)) { - jsonenc_fieldval(e, f, val, &first); - } - } -} +bool upb_Arena_IncRefFor(upb_Arena* a, const void* owner) { + upb_ArenaInternal* ai = upb_Arena_Internal(a); + if (_upb_ArenaInternal_HasInitialBlock(ai)) return false; + upb_ArenaRoot r; -static void jsonenc_msg(jsonenc* e, const upb_Message* msg, - const upb_MessageDef* m) { - jsonenc_putstr(e, "{"); - jsonenc_msgfields(e, msg, m, true); - jsonenc_putstr(e, "}"); +retry: + r = _upb_Arena_FindRoot(a); + if (upb_Atomic_CompareExchangeWeak( + &r.root->parent_or_count, &r.tagged_count, + _upb_Arena_TaggedFromRefcount( + _upb_Arena_RefCountFromTagged(r.tagged_count) + 1), + memory_order_release, memory_order_acquire)) { + // We incremented it successfully, so we are done. + return true; + } + // We failed update due to parent switching on the arena. + goto retry; } -static size_t jsonenc_nullz(jsonenc* e, size_t size) { - size_t ret = e->ptr - e->buf + e->overflow; +void upb_Arena_DecRefFor(upb_Arena* a, const void* owner) { upb_Arena_Free(a); } - if (size > 0) { - if (e->ptr == e->end) e->ptr--; - *e->ptr = '\0'; - } +void UPB_PRIVATE(_upb_Arena_SwapIn)(upb_Arena* des, const upb_Arena* src) { + upb_ArenaInternal* desi = upb_Arena_Internal(des); + upb_ArenaInternal* srci = upb_Arena_Internal(src); - return ret; + *des = *src; + desi->block_alloc = srci->block_alloc; + upb_MemBlock* blocks = upb_Atomic_Load(&srci->blocks, memory_order_relaxed); + upb_Atomic_Init(&desi->blocks, blocks); } -static size_t upb_JsonEncoder_Encode(jsonenc* const e, - const upb_Message* const msg, - const upb_MessageDef* const m, - const size_t size) { - if (UPB_SETJMP(e->err) != 0) return -1; +void UPB_PRIVATE(_upb_Arena_SwapOut)(upb_Arena* des, const upb_Arena* src) { + upb_ArenaInternal* desi = upb_Arena_Internal(des); + upb_ArenaInternal* srci = upb_Arena_Internal(src); - jsonenc_msgfield(e, msg, m); - if (e->arena) upb_Arena_Free(e->arena); - return jsonenc_nullz(e, size); + *des = *src; + upb_MemBlock* blocks = upb_Atomic_Load(&srci->blocks, memory_order_relaxed); + upb_Atomic_Store(&desi->blocks, blocks, memory_order_relaxed); } -size_t upb_JsonEncode(const upb_Message* msg, const upb_MessageDef* m, - const upb_DefPool* ext_pool, int options, char* buf, - size_t size, upb_Status* status) { - jsonenc e; - - e.buf = buf; - e.ptr = buf; - e.end = UPB_PTRADD(buf, size); - e.overflow = 0; - e.options = options; - e.ext_pool = ext_pool; - e.status = status; - e.arena = NULL; - return upb_JsonEncoder_Encode(&e, msg, m, size); -} +#include +#include // Must be last. -const char* upb_BufToUint64(const char* ptr, const char* end, uint64_t* val) { - uint64_t u64 = 0; - while (ptr < end) { - unsigned ch = *ptr - '0'; - if (ch >= 10) break; - if (u64 > UINT64_MAX / 10 || u64 * 10 > UINT64_MAX - ch) { - return NULL; // integer overflow - } - u64 *= 10; - u64 += ch; - ptr++; - } - - *val = u64; - return ptr; +upb_Array* upb_Array_New(upb_Arena* a, upb_CType type) { + const int lg2 = UPB_PRIVATE(_upb_CType_SizeLg2)(type); + return UPB_PRIVATE(_upb_Array_New)(a, 4, lg2); } -const char* upb_BufToInt64(const char* ptr, const char* end, int64_t* val, - bool* is_neg) { - bool neg = false; - uint64_t u64; +const void* upb_Array_DataPtr(const upb_Array* arr) { + return _upb_array_ptr((upb_Array*)arr); +} - if (ptr != end && *ptr == '-') { - ptr++; - neg = true; - } +void* upb_Array_MutableDataPtr(upb_Array* arr) { return _upb_array_ptr(arr); } - ptr = upb_BufToUint64(ptr, end, &u64); - if (!ptr || u64 > (uint64_t)INT64_MAX + neg) { - return NULL; // integer overflow - } +size_t upb_Array_Size(const upb_Array* arr) { return arr->UPB_PRIVATE(size); } - *val = neg ? -u64 : u64; - if (is_neg) *is_neg = neg; - return ptr; +upb_MessageValue upb_Array_Get(const upb_Array* arr, size_t i) { + upb_MessageValue ret; + const char* data = _upb_array_constptr(arr); + const int lg2 = UPB_PRIVATE(_upb_Array_ElemSizeLg2)(arr); + UPB_ASSERT(i < arr->UPB_PRIVATE(size)); + memcpy(&ret, data + (i << lg2), 1 << lg2); + return ret; } +void upb_Array_Set(upb_Array* arr, size_t i, upb_MessageValue val) { + char* data = _upb_array_ptr(arr); + const int lg2 = UPB_PRIVATE(_upb_Array_ElemSizeLg2)(arr); + UPB_ASSERT(i < arr->UPB_PRIVATE(size)); + memcpy(data + (i << lg2), &val, 1 << lg2); +} -#include -#include - -// Must be last. +bool upb_Array_Append(upb_Array* arr, upb_MessageValue val, upb_Arena* arena) { + UPB_ASSERT(arena); + if (!_upb_Array_ResizeUninitialized(arr, arr->UPB_PRIVATE(size) + 1, arena)) { + return false; + } + upb_Array_Set(arr, arr->UPB_PRIVATE(size) - 1, val); + return true; +} -/* Miscellaneous utilities ****************************************************/ +void upb_Array_Move(upb_Array* arr, size_t dst_idx, size_t src_idx, + size_t count) { + const int lg2 = UPB_PRIVATE(_upb_Array_ElemSizeLg2)(arr); + char* data = _upb_array_ptr(arr); + memmove(&data[dst_idx << lg2], &data[src_idx << lg2], count << lg2); +} -static void upb_FixLocale(char* p) { - /* printf() is dependent on locales; sadly there is no easy and portable way - * to avoid this. This little post-processing step will translate 1,2 -> 1.2 - * since JSON needs the latter. Arguably a hack, but it is simple and the - * alternatives are far more complicated, platform-dependent, and/or larger - * in code size. */ - for (; *p; p++) { - if (*p == ',') *p = '.'; +bool upb_Array_Insert(upb_Array* arr, size_t i, size_t count, + upb_Arena* arena) { + UPB_ASSERT(arena); + UPB_ASSERT(i <= arr->UPB_PRIVATE(size)); + UPB_ASSERT(count + arr->UPB_PRIVATE(size) >= count); + const size_t oldsize = arr->UPB_PRIVATE(size); + if (!_upb_Array_ResizeUninitialized(arr, arr->UPB_PRIVATE(size) + count, + arena)) { + return false; } + upb_Array_Move(arr, i + count, i, oldsize - i); + return true; } -void _upb_EncodeRoundTripDouble(double val, char* buf, size_t size) { - assert(size >= kUpb_RoundTripBufferSize); - snprintf(buf, size, "%.*g", DBL_DIG, val); - if (strtod(buf, NULL) != val) { - snprintf(buf, size, "%.*g", DBL_DIG + 2, val); - assert(strtod(buf, NULL) == val); - } - upb_FixLocale(buf); +/* + * i end arr->size + * |------------|XXXXXXXX|--------| + */ +void upb_Array_Delete(upb_Array* arr, size_t i, size_t count) { + const size_t end = i + count; + UPB_ASSERT(i <= end); + UPB_ASSERT(end <= arr->UPB_PRIVATE(size)); + upb_Array_Move(arr, i, end, arr->UPB_PRIVATE(size) - end); + arr->UPB_PRIVATE(size) -= count; } -void _upb_EncodeRoundTripFloat(float val, char* buf, size_t size) { - assert(size >= kUpb_RoundTripBufferSize); - snprintf(buf, size, "%.*g", FLT_DIG, val); - if (strtof(buf, NULL) != val) { - snprintf(buf, size, "%.*g", FLT_DIG + 3, val); - assert(strtof(buf, NULL) == val); +bool upb_Array_Resize(upb_Array* arr, size_t size, upb_Arena* arena) { + const size_t oldsize = arr->UPB_PRIVATE(size); + if (UPB_UNLIKELY(!_upb_Array_ResizeUninitialized(arr, size, arena))) { + return false; } - upb_FixLocale(buf); + const size_t newsize = arr->UPB_PRIVATE(size); + if (newsize > oldsize) { + const int lg2 = UPB_PRIVATE(_upb_Array_ElemSizeLg2)(arr); + char* data = _upb_array_ptr(arr); + memset(data + (oldsize << lg2), 0, (newsize - oldsize) << lg2); + } + return true; } +bool UPB_PRIVATE(_upb_Array_Realloc)(upb_Array* array, size_t min_capacity, + upb_Arena* arena) { + size_t new_capacity = UPB_MAX(array->UPB_PRIVATE(capacity), 4); + const int lg2 = UPB_PRIVATE(_upb_Array_ElemSizeLg2)(array); + size_t old_bytes = array->UPB_PRIVATE(capacity) << lg2; + void* ptr = _upb_array_ptr(array); -#include -#include - -// Must be last. + // Log2 ceiling of size. + while (new_capacity < min_capacity) new_capacity *= 2; -// Determine the locale-specific radix character by calling sprintf() to print -// the number 1.5, then stripping off the digits. As far as I can tell, this -// is the only portable, thread-safe way to get the C library to divulge the -// locale's radix character. No, localeconv() is NOT thread-safe. + const size_t new_bytes = new_capacity << lg2; + ptr = upb_Arena_Realloc(arena, ptr, old_bytes, new_bytes); + if (!ptr) return false; -static int GetLocaleRadix(char *data, size_t capacity) { - char temp[16]; - const int size = snprintf(temp, sizeof(temp), "%.1f", 1.5); - UPB_ASSERT(temp[0] == '1'); - UPB_ASSERT(temp[size - 1] == '5'); - UPB_ASSERT(size < capacity); - temp[size - 1] = '\0'; - strcpy(data, temp + 1); - return size - 2; + UPB_PRIVATE(_upb_Array_SetTaggedPtr)(array, ptr, lg2); + array->UPB_PRIVATE(capacity) = new_capacity; + return true; } -// Populates a string identical to *input except that the character pointed to -// by pos (which should be '.') is replaced with the locale-specific radix. -static void LocalizeRadix(const char *input, const char *pos, char *output) { - const int len1 = pos - input; +#include +#include - char radix[8]; - const int len2 = GetLocaleRadix(radix, sizeof(radix)); - memcpy(output, input, len1); - memcpy(output + len1, radix, len2); - strcpy(output + len1 + len2, input + len1 + 1); -} +// Must be last. -double _upb_NoLocaleStrtod(const char *str, char **endptr) { - // We cannot simply set the locale to "C" temporarily with setlocale() - // as this is not thread-safe. Instead, we try to parse in the current - // locale first. If parsing stops at a '.' character, then this is a - // pretty good hint that we're actually in some other locale in which - // '.' is not the radix character. +const upb_Extension* upb_Message_ExtensionByIndex(const upb_Message* msg, + size_t index) { + size_t count; + const upb_Extension* ext = UPB_PRIVATE(_upb_Message_Getexts)(msg, &count); - char *temp_endptr; - double result = strtod(str, &temp_endptr); - if (endptr != NULL) *endptr = temp_endptr; - if (*temp_endptr != '.') return result; + UPB_ASSERT(index < count); + return &ext[index]; +} - // Parsing halted on a '.'. Perhaps we're in a different locale? Let's - // try to replace the '.' with a locale-specific radix character and - // try again. +const upb_Extension* upb_Message_FindExtensionByNumber(const upb_Message* msg, + uint32_t field_number) { + size_t count; + const upb_Extension* ext = UPB_PRIVATE(_upb_Message_Getexts)(msg, &count); - char localized[80]; - LocalizeRadix(str, temp_endptr, localized); - char *localized_endptr; - result = strtod(localized, &localized_endptr); - if ((localized_endptr - &localized[0]) > (temp_endptr - str)) { - // This attempt got further, so replacing the decimal must have helped. - // Update endptr to point at the right location. - if (endptr != NULL) { - // size_diff is non-zero if the localized radix has multiple bytes. - int size_diff = strlen(localized) - strlen(str); - *endptr = (char *)str + (localized_endptr - &localized[0] - size_diff); - } + while (count--) { + if (upb_MiniTableExtension_Number(ext->ext) == field_number) return ext; + ext++; } - - return result; + return NULL; } +#include + + // Must be last. -int upb_Unicode_ToUTF8(uint32_t cp, char* out) { - if (cp <= 0x7f) { - out[0] = cp; - return 1; - } - if (cp <= 0x07ff) { - out[0] = (cp >> 6) | 0xc0; - out[1] = (cp & 0x3f) | 0x80; - return 2; - } - if (cp <= 0xffff) { - out[0] = (cp >> 12) | 0xe0; - out[1] = ((cp >> 6) & 0x3f) | 0x80; - out[2] = (cp & 0x3f) | 0x80; - return 3; - } - if (cp <= 0x10ffff) { - out[0] = (cp >> 18) | 0xf0; - out[1] = ((cp >> 12) & 0x3f) | 0x80; - out[2] = ((cp >> 6) & 0x3f) | 0x80; - out[3] = (cp & 0x3f) | 0x80; - return 4; - } - return 0; +// Strings/bytes are special-cased in maps. +char _upb_Map_CTypeSizeTable[12] = { + [kUpb_CType_Bool] = 1, + [kUpb_CType_Float] = 4, + [kUpb_CType_Int32] = 4, + [kUpb_CType_UInt32] = 4, + [kUpb_CType_Enum] = 4, + [kUpb_CType_Message] = sizeof(void*), + [kUpb_CType_Double] = 8, + [kUpb_CType_Int64] = 8, + [kUpb_CType_UInt64] = 8, + [kUpb_CType_String] = UPB_MAPTYPE_STRING, + [kUpb_CType_Bytes] = UPB_MAPTYPE_STRING, +}; + +upb_Map* upb_Map_New(upb_Arena* a, upb_CType key_type, upb_CType value_type) { + return _upb_Map_New(a, _upb_Map_CTypeSize(key_type), + _upb_Map_CTypeSize(value_type)); } +size_t upb_Map_Size(const upb_Map* map) { return _upb_Map_Size(map); } -#include +bool upb_Map_Get(const upb_Map* map, upb_MessageValue key, + upb_MessageValue* val) { + return _upb_Map_Get(map, &key, map->key_size, val, map->val_size); +} -// Must be last. +void upb_Map_Clear(upb_Map* map) { _upb_Map_Clear(map); } -static void* upb_global_allocfunc(upb_alloc* alloc, void* ptr, size_t oldsize, - size_t size) { - UPB_UNUSED(alloc); - UPB_UNUSED(oldsize); - if (size == 0) { - free(ptr); - return NULL; - } else { - return realloc(ptr, size); - } +upb_MapInsertStatus upb_Map_Insert(upb_Map* map, upb_MessageValue key, + upb_MessageValue val, upb_Arena* arena) { + UPB_ASSERT(arena); + return (upb_MapInsertStatus)_upb_Map_Insert(map, &key, map->key_size, &val, + map->val_size, arena); } -upb_alloc upb_alloc_global = {&upb_global_allocfunc}; +bool upb_Map_Delete(upb_Map* map, upb_MessageValue key, upb_MessageValue* val) { + upb_value v; + const bool removed = _upb_Map_Delete(map, &key, map->key_size, &v); + if (val) _upb_map_fromvalue(v, val, map->val_size); + return removed; +} +bool upb_Map_Next(const upb_Map* map, upb_MessageValue* key, + upb_MessageValue* val, size_t* iter) { + upb_StringView k; + upb_value v; + const bool ok = upb_strtable_next2(&map->table, &k, &v, (intptr_t*)iter); + if (ok) { + _upb_map_fromkey(k, key, map->key_size); + _upb_map_fromvalue(v, val, map->val_size); + } + return ok; +} -#include -#include +UPB_API void upb_Map_SetEntryValue(upb_Map* map, size_t iter, + upb_MessageValue val) { + upb_value v; + _upb_map_tovalue(&val, map->val_size, &v, NULL); + upb_strtable_setentryvalue(&map->table, iter, v); +} +bool upb_MapIterator_Next(const upb_Map* map, size_t* iter) { + return _upb_map_next(map, iter); +} -// Must be last. +bool upb_MapIterator_Done(const upb_Map* map, size_t iter) { + upb_strtable_iter i; + UPB_ASSERT(iter != kUpb_Map_Begin); + i.t = &map->table; + i.index = iter; + return upb_strtable_done(&i); +} -typedef struct upb_MemBlock { - // Atomic only for the benefit of SpaceAllocated(). - UPB_ATOMIC(struct upb_MemBlock*) next; - uint32_t size; - // Data follows. -} upb_MemBlock; +// Returns the key and value for this entry of the map. +upb_MessageValue upb_MapIterator_Key(const upb_Map* map, size_t iter) { + upb_strtable_iter i; + upb_MessageValue ret; + i.t = &map->table; + i.index = iter; + _upb_map_fromkey(upb_strtable_iter_key(&i), &ret, map->key_size); + return ret; +} -typedef struct upb_ArenaInternal { - // upb_alloc* together with a low bit which signals if there is an initial - // block. - uintptr_t block_alloc; +upb_MessageValue upb_MapIterator_Value(const upb_Map* map, size_t iter) { + upb_strtable_iter i; + upb_MessageValue ret; + i.t = &map->table; + i.index = iter; + _upb_map_fromvalue(upb_strtable_iter_value(&i), &ret, map->val_size); + return ret; +} - // When multiple arenas are fused together, each arena points to a parent - // arena (root points to itself). The root tracks how many live arenas - // reference it. +// EVERYTHING BELOW THIS LINE IS INTERNAL - DO NOT USE ///////////////////////// - // The low bit is tagged: - // 0: pointer to parent - // 1: count, left shifted by one - UPB_ATOMIC(uintptr_t) parent_or_count; +upb_Map* _upb_Map_New(upb_Arena* a, size_t key_size, size_t value_size) { + upb_Map* map = upb_Arena_Malloc(a, sizeof(upb_Map)); + if (!map) return NULL; - // All nodes that are fused together are in a singly-linked list. - // == NULL at end of list. - UPB_ATOMIC(struct upb_ArenaInternal*) next; + upb_strtable_init(&map->table, 4, a); + map->key_size = key_size; + map->val_size = value_size; - // The last element of the linked list. This is present only as an - // optimization, so that we do not have to iterate over all members for every - // fuse. Only significant for an arena root. In other cases it is ignored. - // == self when no other list members. - UPB_ATOMIC(struct upb_ArenaInternal*) tail; + return map; +} - // Linked list of blocks to free/cleanup. Atomic only for the benefit of - // upb_Arena_SpaceAllocated(). - UPB_ATOMIC(upb_MemBlock*) blocks; -} upb_ArenaInternal; -// All public + private state for an arena. -typedef struct { - upb_Arena head; - upb_ArenaInternal body; -} upb_ArenaState; +#include +#include -typedef struct { - upb_ArenaInternal* root; - uintptr_t tagged_count; -} upb_ArenaRoot; -static const size_t kUpb_MemblockReserve = - UPB_ALIGN_UP(sizeof(upb_MemBlock), UPB_MALLOC_ALIGN); +// Must be last. -// Extracts the (upb_ArenaInternal*) from a (upb_Arena*) -static upb_ArenaInternal* upb_Arena_Internal(const upb_Arena* a) { - return &((upb_ArenaState*)a)->body; +static void _upb_mapsorter_getkeys(const void* _a, const void* _b, void* a_key, + void* b_key, size_t size) { + const upb_tabent* const* a = _a; + const upb_tabent* const* b = _b; + upb_StringView a_tabkey = upb_tabstrview((*a)->key); + upb_StringView b_tabkey = upb_tabstrview((*b)->key); + _upb_map_fromkey(a_tabkey, a_key, size); + _upb_map_fromkey(b_tabkey, b_key, size); } -static bool _upb_Arena_IsTaggedRefcount(uintptr_t parent_or_count) { - return (parent_or_count & 1) == 1; +static int _upb_mapsorter_cmpi64(const void* _a, const void* _b) { + int64_t a, b; + _upb_mapsorter_getkeys(_a, _b, &a, &b, 8); + return a < b ? -1 : a > b; } -static bool _upb_Arena_IsTaggedPointer(uintptr_t parent_or_count) { - return (parent_or_count & 1) == 0; +static int _upb_mapsorter_cmpu64(const void* _a, const void* _b) { + uint64_t a, b; + _upb_mapsorter_getkeys(_a, _b, &a, &b, 8); + return a < b ? -1 : a > b; } -static uintptr_t _upb_Arena_RefCountFromTagged(uintptr_t parent_or_count) { - UPB_ASSERT(_upb_Arena_IsTaggedRefcount(parent_or_count)); - return parent_or_count >> 1; +static int _upb_mapsorter_cmpi32(const void* _a, const void* _b) { + int32_t a, b; + _upb_mapsorter_getkeys(_a, _b, &a, &b, 4); + return a < b ? -1 : a > b; } -static uintptr_t _upb_Arena_TaggedFromRefcount(uintptr_t refcount) { - uintptr_t parent_or_count = (refcount << 1) | 1; - UPB_ASSERT(_upb_Arena_IsTaggedRefcount(parent_or_count)); - return parent_or_count; +static int _upb_mapsorter_cmpu32(const void* _a, const void* _b) { + uint32_t a, b; + _upb_mapsorter_getkeys(_a, _b, &a, &b, 4); + return a < b ? -1 : a > b; } -static upb_ArenaInternal* _upb_Arena_PointerFromTagged( - uintptr_t parent_or_count) { - UPB_ASSERT(_upb_Arena_IsTaggedPointer(parent_or_count)); - return (upb_ArenaInternal*)parent_or_count; -} - -static uintptr_t _upb_Arena_TaggedFromPointer(upb_ArenaInternal* ai) { - uintptr_t parent_or_count = (uintptr_t)ai; - UPB_ASSERT(_upb_Arena_IsTaggedPointer(parent_or_count)); - return parent_or_count; +static int _upb_mapsorter_cmpbool(const void* _a, const void* _b) { + bool a, b; + _upb_mapsorter_getkeys(_a, _b, &a, &b, 1); + return a < b ? -1 : a > b; } -static upb_alloc* _upb_ArenaInternal_BlockAlloc(upb_ArenaInternal* ai) { - return (upb_alloc*)(ai->block_alloc & ~0x1); +static int _upb_mapsorter_cmpstr(const void* _a, const void* _b) { + upb_StringView a, b; + _upb_mapsorter_getkeys(_a, _b, &a, &b, UPB_MAPTYPE_STRING); + size_t common_size = UPB_MIN(a.size, b.size); + int cmp = memcmp(a.data, b.data, common_size); + if (cmp) return -cmp; + return a.size < b.size ? -1 : a.size > b.size; } -static uintptr_t _upb_Arena_MakeBlockAlloc(upb_alloc* alloc, bool has_initial) { - uintptr_t alloc_uint = (uintptr_t)alloc; - UPB_ASSERT((alloc_uint & 1) == 0); - return alloc_uint | (has_initial ? 1 : 0); -} +static int (*const compar[kUpb_FieldType_SizeOf])(const void*, const void*) = { + [kUpb_FieldType_Int64] = _upb_mapsorter_cmpi64, + [kUpb_FieldType_SFixed64] = _upb_mapsorter_cmpi64, + [kUpb_FieldType_SInt64] = _upb_mapsorter_cmpi64, -static bool _upb_ArenaInternal_HasInitialBlock(upb_ArenaInternal* ai) { - return ai->block_alloc & 0x1; -} + [kUpb_FieldType_UInt64] = _upb_mapsorter_cmpu64, + [kUpb_FieldType_Fixed64] = _upb_mapsorter_cmpu64, -static upb_ArenaRoot _upb_Arena_FindRoot(upb_Arena* a) { - upb_ArenaInternal* ai = upb_Arena_Internal(a); - uintptr_t poc = upb_Atomic_Load(&ai->parent_or_count, memory_order_acquire); - while (_upb_Arena_IsTaggedPointer(poc)) { - upb_ArenaInternal* next = _upb_Arena_PointerFromTagged(poc); - UPB_ASSERT(ai != next); - uintptr_t next_poc = - upb_Atomic_Load(&next->parent_or_count, memory_order_acquire); + [kUpb_FieldType_Int32] = _upb_mapsorter_cmpi32, + [kUpb_FieldType_SInt32] = _upb_mapsorter_cmpi32, + [kUpb_FieldType_SFixed32] = _upb_mapsorter_cmpi32, + [kUpb_FieldType_Enum] = _upb_mapsorter_cmpi32, - if (_upb_Arena_IsTaggedPointer(next_poc)) { - // To keep complexity down, we lazily collapse levels of the tree. This - // keeps it flat in the final case, but doesn't cost much incrementally. - // - // Path splitting keeps time complexity down, see: - // https://en.wikipedia.org/wiki/Disjoint-set_data_structure - // - // We can safely use a relaxed atomic here because all threads doing this - // will converge on the same value and we don't need memory orderings to - // be visible. - // - // This is true because: - // - If no fuses occur, this will eventually become the root. - // - If fuses are actively occurring, the root may change, but the - // invariant is that `parent_or_count` merely points to *a* parent. - // - // In other words, it is moving towards "the" root, and that root may move - // further away over time, but the path towards that root will continue to - // be valid and the creation of the path carries all the memory orderings - // required. - UPB_ASSERT(ai != _upb_Arena_PointerFromTagged(next_poc)); - upb_Atomic_Store(&ai->parent_or_count, next_poc, memory_order_relaxed); - } - ai = next; - poc = next_poc; + [kUpb_FieldType_UInt32] = _upb_mapsorter_cmpu32, + [kUpb_FieldType_Fixed32] = _upb_mapsorter_cmpu32, + + [kUpb_FieldType_Bool] = _upb_mapsorter_cmpbool, + + [kUpb_FieldType_String] = _upb_mapsorter_cmpstr, + [kUpb_FieldType_Bytes] = _upb_mapsorter_cmpstr, +}; + +static bool _upb_mapsorter_resize(_upb_mapsorter* s, _upb_sortedmap* sorted, + int size) { + sorted->start = s->size; + sorted->pos = sorted->start; + sorted->end = sorted->start + size; + + if (sorted->end > s->cap) { + const int oldsize = s->cap * sizeof(*s->entries); + s->cap = upb_Log2CeilingSize(sorted->end); + const int newsize = s->cap * sizeof(*s->entries); + s->entries = upb_grealloc(s->entries, oldsize, newsize); + if (!s->entries) return false; } - return (upb_ArenaRoot){.root = ai, .tagged_count = poc}; + + s->size = sorted->end; + return true; } -size_t upb_Arena_SpaceAllocated(upb_Arena* arena) { - upb_ArenaInternal* ai = _upb_Arena_FindRoot(arena).root; - size_t memsize = 0; +bool _upb_mapsorter_pushmap(_upb_mapsorter* s, upb_FieldType key_type, + const upb_Map* map, _upb_sortedmap* sorted) { + int map_size = _upb_Map_Size(map); - while (ai != NULL) { - upb_MemBlock* block = upb_Atomic_Load(&ai->blocks, memory_order_relaxed); - while (block != NULL) { - memsize += sizeof(upb_MemBlock) + block->size; - block = upb_Atomic_Load(&block->next, memory_order_relaxed); + if (!_upb_mapsorter_resize(s, sorted, map_size)) return false; + + // Copy non-empty entries from the table to s->entries. + const void** dst = &s->entries[sorted->start]; + const upb_tabent* src = map->table.t.entries; + const upb_tabent* end = src + upb_table_size(&map->table.t); + for (; src < end; src++) { + if (!upb_tabent_isempty(src)) { + *dst = src; + dst++; } - ai = upb_Atomic_Load(&ai->next, memory_order_relaxed); } + UPB_ASSERT(dst == &s->entries[sorted->end]); - return memsize; + // Sort entries according to the key type. + qsort(&s->entries[sorted->start], map_size, sizeof(*s->entries), + compar[key_type]); + return true; } -uint32_t upb_Arena_DebugRefCount(upb_Arena* a) { - upb_ArenaInternal* ai = upb_Arena_Internal(a); - // These loads could probably be relaxed, but given that this is debug-only, - // it's not worth introducing a new variant for it. - uintptr_t poc = upb_Atomic_Load(&ai->parent_or_count, memory_order_acquire); - while (_upb_Arena_IsTaggedPointer(poc)) { - ai = _upb_Arena_PointerFromTagged(poc); - poc = upb_Atomic_Load(&ai->parent_or_count, memory_order_acquire); +static int _upb_mapsorter_cmpext(const void* _a, const void* _b) { + const upb_Extension* const* a = _a; + const upb_Extension* const* b = _b; + uint32_t a_num = upb_MiniTableExtension_Number((*a)->ext); + uint32_t b_num = upb_MiniTableExtension_Number((*b)->ext); + assert(a_num != b_num); + return a_num < b_num ? -1 : 1; +} + +bool _upb_mapsorter_pushexts(_upb_mapsorter* s, const upb_Extension* exts, + size_t count, _upb_sortedmap* sorted) { + if (!_upb_mapsorter_resize(s, sorted, count)) return false; + + for (size_t i = 0; i < count; i++) { + s->entries[sorted->start + i] = &exts[i]; } - return _upb_Arena_RefCountFromTagged(poc); + + qsort(&s->entries[sorted->start], count, sizeof(*s->entries), + _upb_mapsorter_cmpext); + return true; } -static void _upb_Arena_AddBlock(upb_Arena* a, void* ptr, size_t size) { - upb_ArenaInternal* ai = upb_Arena_Internal(a); - upb_MemBlock* block = ptr; - // Insert into linked list. - block->size = (uint32_t)size; - upb_Atomic_Init(&block->next, ai->blocks); - upb_Atomic_Store(&ai->blocks, block, memory_order_release); +#include +#include +#include - a->UPB_PRIVATE(ptr) = UPB_PTR_AT(block, kUpb_MemblockReserve, char); - a->UPB_PRIVATE(end) = UPB_PTR_AT(block, size, char); - UPB_POISON_MEMORY_REGION(a->UPB_PRIVATE(ptr), - a->UPB_PRIVATE(end) - a->UPB_PRIVATE(ptr)); -} +// Must be last. -static bool _upb_Arena_AllocBlock(upb_Arena* a, size_t size) { - upb_ArenaInternal* ai = upb_Arena_Internal(a); - if (!ai->block_alloc) return false; - upb_MemBlock* last_block = upb_Atomic_Load(&ai->blocks, memory_order_acquire); - size_t last_size = last_block != NULL ? last_block->size : 128; - size_t block_size = UPB_MAX(size, last_size * 2) + kUpb_MemblockReserve; - upb_MemBlock* block = - upb_malloc(_upb_ArenaInternal_BlockAlloc(ai), block_size); +static const size_t message_overhead = sizeof(upb_Message_InternalData); - if (!block) return false; - _upb_Arena_AddBlock(a, block, block_size); - UPB_ASSERT(UPB_PRIVATE(_upb_ArenaHas)(a) >= size); - return true; +upb_Message* upb_Message_New(const upb_MiniTable* m, upb_Arena* a) { + return _upb_Message_New(m, a); } -void* UPB_PRIVATE(_upb_Arena_SlowMalloc)(upb_Arena* a, size_t size) { - if (!_upb_Arena_AllocBlock(a, size)) return NULL; // OOM - return upb_Arena_Malloc(a, size - UPB_ASAN_GUARD_SIZE); +bool UPB_PRIVATE(_upb_Message_AddUnknown)(upb_Message* msg, const char* data, + size_t len, upb_Arena* arena) { + if (!UPB_PRIVATE(_upb_Message_Realloc)(msg, len, arena)) return false; + upb_Message_Internal* owner = upb_Message_Getinternal(msg); + upb_Message_InternalData* in = owner->internal; + memcpy(UPB_PTR_AT(in, in->unknown_end, char), data, len); + in->unknown_end += len; + return true; } -static upb_Arena* _upb_Arena_InitSlow(upb_alloc* alloc) { - const size_t first_block_overhead = - sizeof(upb_ArenaState) + kUpb_MemblockReserve; - upb_ArenaState* a; +void _upb_Message_DiscardUnknown_shallow(upb_Message* msg) { + upb_Message_Internal* owner = upb_Message_Getinternal(msg); + upb_Message_InternalData* in = owner->internal; + if (in) { + in->unknown_end = message_overhead; + } +} - // We need to malloc the initial block. - char* mem; - size_t n = first_block_overhead + 256; - if (!alloc || !(mem = upb_malloc(alloc, n))) { +const char* upb_Message_GetUnknown(const upb_Message* msg, size_t* len) { + upb_Message_Internal* owner = upb_Message_Getinternal(msg); + upb_Message_InternalData* in = owner->internal; + if (in) { + *len = in->unknown_end - message_overhead; + return (char*)(in + 1); + } else { + *len = 0; return NULL; } +} - a = UPB_PTR_AT(mem, n - sizeof(upb_ArenaState), upb_ArenaState); - n -= sizeof(upb_ArenaState); +void upb_Message_DeleteUnknown(upb_Message* msg, const char* data, size_t len) { + upb_Message_Internal* owner = upb_Message_Getinternal(msg); + upb_Message_InternalData* in = owner->internal; + const char* internal_unknown_end = UPB_PTR_AT(in, in->unknown_end, char); - a->body.block_alloc = _upb_Arena_MakeBlockAlloc(alloc, 0); - upb_Atomic_Init(&a->body.parent_or_count, _upb_Arena_TaggedFromRefcount(1)); - upb_Atomic_Init(&a->body.next, NULL); - upb_Atomic_Init(&a->body.tail, &a->body); - upb_Atomic_Init(&a->body.blocks, NULL); +#ifndef NDEBUG + size_t full_unknown_size; + const char* full_unknown = upb_Message_GetUnknown(msg, &full_unknown_size); + UPB_ASSERT((uintptr_t)data >= (uintptr_t)full_unknown); + UPB_ASSERT((uintptr_t)data < (uintptr_t)(full_unknown + full_unknown_size)); + UPB_ASSERT((uintptr_t)(data + len) > (uintptr_t)data); + UPB_ASSERT((uintptr_t)(data + len) <= (uintptr_t)internal_unknown_end); +#endif - _upb_Arena_AddBlock(&a->head, mem, n); + if ((data + len) != internal_unknown_end) { + memmove((char*)data, data + len, internal_unknown_end - data - len); + } + in->unknown_end -= len; +} - return &a->head; +size_t upb_Message_ExtensionCount(const upb_Message* msg) { + size_t count; + UPB_PRIVATE(_upb_Message_Getexts)(msg, &count); + return count; } -upb_Arena* upb_Arena_Init(void* mem, size_t n, upb_alloc* alloc) { - UPB_ASSERT(sizeof(void*) * UPB_ARENA_SIZE_HACK >= sizeof(upb_ArenaState)); - upb_ArenaState* a; - if (n) { - /* Align initial pointer up so that we return properly-aligned pointers. */ - void* aligned = (void*)UPB_ALIGN_UP((uintptr_t)mem, UPB_MALLOC_ALIGN); - size_t delta = (uintptr_t)aligned - (uintptr_t)mem; - n = delta <= n ? n - delta : 0; - mem = aligned; - } +#include - /* Round block size down to alignof(*a) since we will allocate the arena - * itself at the end. */ - n = UPB_ALIGN_DOWN(n, UPB_ALIGN_OF(upb_ArenaState)); - if (UPB_UNLIKELY(n < sizeof(upb_ArenaState))) { - return _upb_Arena_InitSlow(alloc); - } +// Must be last. - a = UPB_PTR_AT(mem, n - sizeof(upb_ArenaState), upb_ArenaState); +bool upb_Message_SetMapEntry(upb_Map* map, const upb_MiniTable* mini_table, + const upb_MiniTableField* f, + upb_Message* map_entry_message, upb_Arena* arena) { + // TODO: use a variant of upb_MiniTable_GetSubMessageTable() here. + const upb_MiniTable* map_entry_mini_table = upb_MiniTableSub_Message( + mini_table->UPB_PRIVATE(subs)[f->UPB_PRIVATE(submsg_index)]); + UPB_ASSERT(map_entry_mini_table); + UPB_ASSERT(map_entry_mini_table->UPB_PRIVATE(field_count) == 2); + const upb_MiniTableField* map_entry_key_field = + &map_entry_mini_table->UPB_PRIVATE(fields)[0]; + const upb_MiniTableField* map_entry_value_field = + &map_entry_mini_table->UPB_PRIVATE(fields)[1]; + // Map key/value cannot have explicit defaults, + // hence assuming a zero default is valid. + upb_MessageValue default_val; + memset(&default_val, 0, sizeof(upb_MessageValue)); + upb_MessageValue map_entry_key = + upb_Message_GetField(map_entry_message, map_entry_key_field, default_val); + upb_MessageValue map_entry_value = upb_Message_GetField( + map_entry_message, map_entry_value_field, default_val); + return upb_Map_Set(map, map_entry_key, map_entry_value, arena); +} - upb_Atomic_Init(&a->body.parent_or_count, _upb_Arena_TaggedFromRefcount(1)); - upb_Atomic_Init(&a->body.next, NULL); - upb_Atomic_Init(&a->body.tail, &a->body); - upb_Atomic_Init(&a->body.blocks, NULL); - a->body.block_alloc = _upb_Arena_MakeBlockAlloc(alloc, 1); - a->head.UPB_PRIVATE(ptr) = mem; - a->head.UPB_PRIVATE(end) = UPB_PTR_AT(mem, n - sizeof(upb_ArenaState), char); +#include - return &a->head; -} -static void _upb_Arena_DoFree(upb_ArenaInternal* ai) { - UPB_ASSERT(_upb_Arena_RefCountFromTagged(ai->parent_or_count) == 1); +// Must be last. - while (ai != NULL) { - // Load first since arena itself is likely from one of its blocks. - upb_ArenaInternal* next_arena = - (upb_ArenaInternal*)upb_Atomic_Load(&ai->next, memory_order_acquire); - upb_alloc* block_alloc = _upb_ArenaInternal_BlockAlloc(ai); - upb_MemBlock* block = upb_Atomic_Load(&ai->blocks, memory_order_acquire); - while (block != NULL) { - // Load first since we are deleting block. - upb_MemBlock* next_block = - upb_Atomic_Load(&block->next, memory_order_acquire); - upb_free(block_alloc, block); - block = next_block; - } - ai = next_arena; - } -} +bool upb_Message_IsExactlyEqual(const upb_Message* msg1, + const upb_Message* msg2, + const upb_MiniTable* m) { + if (msg1 == msg2) return true; -void upb_Arena_Free(upb_Arena* a) { - upb_ArenaInternal* ai = upb_Arena_Internal(a); - uintptr_t poc = upb_Atomic_Load(&ai->parent_or_count, memory_order_acquire); -retry: - while (_upb_Arena_IsTaggedPointer(poc)) { - ai = _upb_Arena_PointerFromTagged(poc); - poc = upb_Atomic_Load(&ai->parent_or_count, memory_order_acquire); - } + int opts = kUpb_EncodeOption_SkipUnknown | kUpb_EncodeOption_Deterministic; + upb_Arena* a = upb_Arena_New(); - // compare_exchange or fetch_sub are RMW operations, which are more - // expensive then direct loads. As an optimization, we only do RMW ops - // when we need to update things for other threads to see. - if (poc == _upb_Arena_TaggedFromRefcount(1)) { - _upb_Arena_DoFree(ai); - return; - } + // Compare deterministically serialized payloads with no unknown fields. + size_t size1, size2; + char *data1, *data2; + upb_EncodeStatus status1 = upb_Encode(msg1, m, opts, a, &data1, &size1); + upb_EncodeStatus status2 = upb_Encode(msg2, m, opts, a, &data2, &size2); - if (upb_Atomic_CompareExchangeWeak( - &ai->parent_or_count, &poc, - _upb_Arena_TaggedFromRefcount(_upb_Arena_RefCountFromTagged(poc) - 1), - memory_order_release, memory_order_acquire)) { - // We were >1 and we decremented it successfully, so we are done. - return; + if (status1 != kUpb_EncodeStatus_Ok || status2 != kUpb_EncodeStatus_Ok) { + // TODO: How should we fail here? (In Ruby we throw an exception.) + upb_Arena_Free(a); + return false; } - // We failed our update, so someone has done something, retry the whole - // process, but the failed exchange reloaded `poc` for us. - goto retry; + const bool ret = (size1 == size2) && (memcmp(data1, data2, size1) == 0); + upb_Arena_Free(a); + return ret; } -static void _upb_Arena_DoFuseArenaLists(upb_ArenaInternal* const parent, - upb_ArenaInternal* child) { - upb_ArenaInternal* parent_tail = - upb_Atomic_Load(&parent->tail, memory_order_relaxed); - do { - // Our tail might be stale, but it will always converge to the true tail. - upb_ArenaInternal* parent_tail_next = - upb_Atomic_Load(&parent_tail->next, memory_order_relaxed); - while (parent_tail_next != NULL) { - parent_tail = parent_tail_next; - parent_tail_next = - upb_Atomic_Load(&parent_tail->next, memory_order_relaxed); - } +#include +#include - upb_ArenaInternal* displaced = - upb_Atomic_Exchange(&parent_tail->next, child, memory_order_relaxed); - parent_tail = upb_Atomic_Load(&child->tail, memory_order_relaxed); - // If we displaced something that got installed racily, we can simply - // reinstall it on our new tail. - child = displaced; - } while (child != NULL); +// Must be last. - upb_Atomic_Store(&parent->tail, parent_tail, memory_order_relaxed); +static upb_StringView upb_Clone_StringView(upb_StringView str, + upb_Arena* arena) { + if (str.size == 0) { + return upb_StringView_FromDataAndSize(NULL, 0); + } + void* cloned_data = upb_Arena_Malloc(arena, str.size); + upb_StringView cloned_str = + upb_StringView_FromDataAndSize(cloned_data, str.size); + memcpy(cloned_data, str.data, str.size); + return cloned_str; } -static upb_ArenaInternal* _upb_Arena_DoFuse(upb_Arena* a1, upb_Arena* a2, - uintptr_t* ref_delta) { - // `parent_or_count` has two disctint modes - // - parent pointer mode - // - refcount mode - // - // In parent pointer mode, it may change what pointer it refers to in the - // tree, but it will always approach a root. Any operation that walks the - // tree to the root may collapse levels of the tree concurrently. - upb_ArenaRoot r1 = _upb_Arena_FindRoot(a1); - upb_ArenaRoot r2 = _upb_Arena_FindRoot(a2); - - if (r1.root == r2.root) return r1.root; // Already fused. - - // Avoid cycles by always fusing into the root with the lower address. - if ((uintptr_t)r1.root > (uintptr_t)r2.root) { - upb_ArenaRoot tmp = r1; - r1 = r2; - r2 = tmp; +static bool upb_Clone_MessageValue(void* value, upb_CType value_type, + const upb_MiniTable* sub, upb_Arena* arena) { + switch (value_type) { + case kUpb_CType_Bool: + case kUpb_CType_Float: + case kUpb_CType_Int32: + case kUpb_CType_UInt32: + case kUpb_CType_Enum: + case kUpb_CType_Double: + case kUpb_CType_Int64: + case kUpb_CType_UInt64: + return true; + case kUpb_CType_String: + case kUpb_CType_Bytes: { + upb_StringView source = *(upb_StringView*)value; + int size = source.size; + void* cloned_data = upb_Arena_Malloc(arena, size); + if (cloned_data == NULL) { + return false; + } + *(upb_StringView*)value = + upb_StringView_FromDataAndSize(cloned_data, size); + memcpy(cloned_data, source.data, size); + return true; + } break; + case kUpb_CType_Message: { + const upb_TaggedMessagePtr source = *(upb_TaggedMessagePtr*)value; + bool is_empty = upb_TaggedMessagePtr_IsEmpty(source); + if (is_empty) sub = UPB_PRIVATE(_upb_MiniTable_Empty)(); + UPB_ASSERT(source); + upb_Message* clone = upb_Message_DeepClone( + UPB_PRIVATE(_upb_TaggedMessagePtr_GetMessage)(source), sub, arena); + *(upb_TaggedMessagePtr*)value = + UPB_PRIVATE(_upb_TaggedMessagePtr_Pack)(clone, is_empty); + return clone != NULL; + } break; } + UPB_UNREACHABLE(); +} - // The moment we install `r1` as the parent for `r2` all racing frees may - // immediately begin decrementing `r1`'s refcount (including pending - // increments to that refcount and their frees!). We need to add `r2`'s refs - // now, so that `r1` can withstand any unrefs that come from r2. - // - // Note that while it is possible for `r2`'s refcount to increase - // asynchronously, we will not actually do the reparenting operation below - // unless `r2`'s refcount is unchanged from when we read it. - // - // Note that we may have done this previously, either to this node or a - // different node, during a previous and failed DoFuse() attempt. But we will - // not lose track of these refs because we always add them to our overall - // delta. - uintptr_t r2_untagged_count = r2.tagged_count & ~1; - uintptr_t with_r2_refs = r1.tagged_count + r2_untagged_count; - if (!upb_Atomic_CompareExchangeStrong( - &r1.root->parent_or_count, &r1.tagged_count, with_r2_refs, - memory_order_release, memory_order_acquire)) { +upb_Map* upb_Map_DeepClone(const upb_Map* map, upb_CType key_type, + upb_CType value_type, + const upb_MiniTable* map_entry_table, + upb_Arena* arena) { + upb_Map* cloned_map = _upb_Map_New(arena, map->key_size, map->val_size); + if (cloned_map == NULL) { return NULL; } - - // Perform the actual fuse by removing the refs from `r2` and swapping in the - // parent pointer. - if (!upb_Atomic_CompareExchangeStrong( - &r2.root->parent_or_count, &r2.tagged_count, - _upb_Arena_TaggedFromPointer(r1.root), memory_order_release, - memory_order_acquire)) { - // We'll need to remove the excess refs we added to r1 previously. - *ref_delta += r2_untagged_count; - return NULL; + upb_MessageValue key, val; + size_t iter = kUpb_Map_Begin; + while (upb_Map_Next(map, &key, &val, &iter)) { + const upb_MiniTableField* value_field = + &map_entry_table->UPB_PRIVATE(fields)[1]; + const upb_MiniTable* value_sub = + (value_field->UPB_PRIVATE(submsg_index) != kUpb_NoSub) + ? upb_MiniTable_GetSubMessageTable(map_entry_table, value_field) + : NULL; + upb_CType value_field_type = upb_MiniTableField_CType(value_field); + if (!upb_Clone_MessageValue(&val, value_field_type, value_sub, arena)) { + return NULL; + } + if (!upb_Map_Set(cloned_map, key, val, arena)) { + return NULL; + } } - - // Now that the fuse has been performed (and can no longer fail) we need to - // append `r2` to `r1`'s linked list. - _upb_Arena_DoFuseArenaLists(r1.root, r2.root); - return r1.root; + return cloned_map; } -static bool _upb_Arena_FixupRefs(upb_ArenaInternal* new_root, - uintptr_t ref_delta) { - if (ref_delta == 0) return true; // No fixup required. - uintptr_t poc = - upb_Atomic_Load(&new_root->parent_or_count, memory_order_relaxed); - if (_upb_Arena_IsTaggedPointer(poc)) return false; - uintptr_t with_refs = poc - ref_delta; - UPB_ASSERT(!_upb_Arena_IsTaggedPointer(with_refs)); - return upb_Atomic_CompareExchangeStrong(&new_root->parent_or_count, &poc, - with_refs, memory_order_relaxed, - memory_order_relaxed); -} - -bool upb_Arena_Fuse(upb_Arena* a1, upb_Arena* a2) { - if (a1 == a2) return true; // trivial fuse +static upb_Map* upb_Message_Map_DeepClone(const upb_Map* map, + const upb_MiniTable* mini_table, + const upb_MiniTableField* f, + upb_Message* clone, + upb_Arena* arena) { + // TODO: use a variant of upb_MiniTable_GetSubMessageTable() here. + const upb_MiniTable* map_entry_table = upb_MiniTableSub_Message( + mini_table->UPB_PRIVATE(subs)[f->UPB_PRIVATE(submsg_index)]); + UPB_ASSERT(map_entry_table); - upb_ArenaInternal* ai1 = upb_Arena_Internal(a1); - upb_ArenaInternal* ai2 = upb_Arena_Internal(a2); + const upb_MiniTableField* key_field = + &map_entry_table->UPB_PRIVATE(fields)[0]; + const upb_MiniTableField* value_field = + &map_entry_table->UPB_PRIVATE(fields)[1]; - // Do not fuse initial blocks since we cannot lifetime extend them. - // Any other fuse scenario is allowed. - if (_upb_ArenaInternal_HasInitialBlock(ai1) || - _upb_ArenaInternal_HasInitialBlock(ai2)) { - return false; + upb_Map* cloned_map = upb_Map_DeepClone( + map, upb_MiniTableField_CType(key_field), + upb_MiniTableField_CType(value_field), map_entry_table, arena); + if (!cloned_map) { + return NULL; } + _upb_Message_SetNonExtensionField(clone, f, &cloned_map); + return cloned_map; +} - // The number of refs we ultimately need to transfer to the new root. - uintptr_t ref_delta = 0; - while (true) { - upb_ArenaInternal* new_root = _upb_Arena_DoFuse(a1, a2, &ref_delta); - if (new_root != NULL && _upb_Arena_FixupRefs(new_root, ref_delta)) { - return true; +upb_Array* upb_Array_DeepClone(const upb_Array* array, upb_CType value_type, + const upb_MiniTable* sub, upb_Arena* arena) { + const size_t size = array->UPB_PRIVATE(size); + const int lg2 = UPB_PRIVATE(_upb_CType_SizeLg2)(value_type); + upb_Array* cloned_array = UPB_PRIVATE(_upb_Array_New)(arena, size, lg2); + if (!cloned_array) { + return NULL; + } + if (!_upb_Array_ResizeUninitialized(cloned_array, size, arena)) { + return NULL; + } + for (size_t i = 0; i < size; ++i) { + upb_MessageValue val = upb_Array_Get(array, i); + if (!upb_Clone_MessageValue(&val, value_type, sub, arena)) { + return false; } + upb_Array_Set(cloned_array, i, val); } + return cloned_array; } -bool upb_Arena_IncRefFor(upb_Arena* a, const void* owner) { - upb_ArenaInternal* ai = upb_Arena_Internal(a); - if (_upb_ArenaInternal_HasInitialBlock(ai)) return false; - upb_ArenaRoot r; +static bool upb_Message_Array_DeepClone(const upb_Array* array, + const upb_MiniTable* mini_table, + const upb_MiniTableField* field, + upb_Message* clone, upb_Arena* arena) { + UPB_PRIVATE(_upb_MiniTableField_CheckIsArray)(field); + upb_Array* cloned_array = upb_Array_DeepClone( + array, upb_MiniTableField_CType(field), + upb_MiniTableField_CType(field) == kUpb_CType_Message && + field->UPB_PRIVATE(submsg_index) != kUpb_NoSub + ? upb_MiniTable_GetSubMessageTable(mini_table, field) + : NULL, + arena); -retry: - r = _upb_Arena_FindRoot(a); - if (upb_Atomic_CompareExchangeWeak( - &r.root->parent_or_count, &r.tagged_count, - _upb_Arena_TaggedFromRefcount( - _upb_Arena_RefCountFromTagged(r.tagged_count) + 1), - memory_order_release, memory_order_acquire)) { - // We incremented it successfully, so we are done. - return true; - } - // We failed update due to parent switching on the arena. - goto retry; + // Clear out upb_Array* due to parent memcpy. + _upb_Message_SetNonExtensionField(clone, field, &cloned_array); + return true; } -void upb_Arena_DecRefFor(upb_Arena* a, const void* owner) { upb_Arena_Free(a); } - -void UPB_PRIVATE(_upb_Arena_SwapIn)(upb_Arena* des, const upb_Arena* src) { - upb_ArenaInternal* desi = upb_Arena_Internal(des); - upb_ArenaInternal* srci = upb_Arena_Internal(src); - - *des = *src; - desi->block_alloc = srci->block_alloc; - upb_MemBlock* blocks = upb_Atomic_Load(&srci->blocks, memory_order_relaxed); - upb_Atomic_Init(&desi->blocks, blocks); +static bool upb_Clone_ExtensionValue( + const upb_MiniTableExtension* mini_table_ext, const upb_Extension* source, + upb_Extension* dest, upb_Arena* arena) { + dest->data = source->data; + return upb_Clone_MessageValue( + &dest->data, + upb_MiniTableField_CType(&mini_table_ext->UPB_PRIVATE(field)), + upb_MiniTableExtension_GetSubMessage(mini_table_ext), arena); } -void UPB_PRIVATE(_upb_Arena_SwapOut)(upb_Arena* des, const upb_Arena* src) { - upb_ArenaInternal* desi = upb_Arena_Internal(des); - upb_ArenaInternal* srci = upb_Arena_Internal(src); +upb_Message* _upb_Message_Copy(upb_Message* dst, const upb_Message* src, + const upb_MiniTable* mini_table, + upb_Arena* arena) { + upb_StringView empty_string = upb_StringView_FromDataAndSize(NULL, 0); + // Only copy message area skipping upb_Message_Internal. + memcpy(dst, src, mini_table->UPB_PRIVATE(size)); + for (size_t i = 0; i < mini_table->UPB_PRIVATE(field_count); ++i) { + const upb_MiniTableField* field = &mini_table->UPB_PRIVATE(fields)[i]; + if (upb_MiniTableField_IsScalar(field)) { + switch (upb_MiniTableField_CType(field)) { + case kUpb_CType_Message: { + upb_TaggedMessagePtr tagged = + upb_Message_GetTaggedMessagePtr(src, field, NULL); + const upb_Message* sub_message = + UPB_PRIVATE(_upb_TaggedMessagePtr_GetMessage)(tagged); + if (sub_message != NULL) { + // If the message is currently in an unlinked, "empty" state we keep + // it that way, because we don't want to deal with decode options, + // decode status, or possible parse failure here. + bool is_empty = upb_TaggedMessagePtr_IsEmpty(tagged); + const upb_MiniTable* sub_message_table = + is_empty ? UPB_PRIVATE(_upb_MiniTable_Empty)() + : upb_MiniTable_GetSubMessageTable(mini_table, field); + upb_Message* dst_sub_message = + upb_Message_DeepClone(sub_message, sub_message_table, arena); + if (dst_sub_message == NULL) { + return NULL; + } + _upb_Message_SetTaggedMessagePtr( + dst, mini_table, field, + UPB_PRIVATE(_upb_TaggedMessagePtr_Pack)(dst_sub_message, + is_empty)); + } + } break; + case kUpb_CType_String: + case kUpb_CType_Bytes: { + upb_StringView str = upb_Message_GetString(src, field, empty_string); + if (str.size != 0) { + if (!upb_Message_SetString( + dst, field, upb_Clone_StringView(str, arena), arena)) { + return NULL; + } + } + } break; + default: + // Scalar, already copied. + break; + } + } else { + if (upb_MiniTableField_IsMap(field)) { + const upb_Map* map = upb_Message_GetMap(src, field); + if (map != NULL) { + if (!upb_Message_Map_DeepClone(map, mini_table, field, dst, arena)) { + return NULL; + } + } + } else { + const upb_Array* array = upb_Message_GetArray(src, field); + if (array != NULL) { + if (!upb_Message_Array_DeepClone(array, mini_table, field, dst, + arena)) { + return NULL; + } + } + } + } + } + // Clone extensions. + size_t ext_count; + const upb_Extension* ext = UPB_PRIVATE(_upb_Message_Getexts)(src, &ext_count); + for (size_t i = 0; i < ext_count; ++i) { + const upb_Extension* msg_ext = &ext[i]; + const upb_MiniTableField* field = &msg_ext->ext->UPB_PRIVATE(field); + upb_Extension* dst_ext = + _upb_Message_GetOrCreateExtension(dst, msg_ext->ext, arena); + if (!dst_ext) return NULL; + if (upb_MiniTableField_IsScalar(field)) { + if (!upb_Clone_ExtensionValue(msg_ext->ext, msg_ext, dst_ext, arena)) { + return NULL; + } + } else { + upb_Array* msg_array = (upb_Array*)msg_ext->data.ptr; + UPB_ASSERT(msg_array); + upb_Array* cloned_array = upb_Array_DeepClone( + msg_array, upb_MiniTableField_CType(field), + upb_MiniTableExtension_GetSubMessage(msg_ext->ext), arena); + if (!cloned_array) { + return NULL; + } + dst_ext->data.ptr = (void*)cloned_array; + } + } - *des = *src; - upb_MemBlock* blocks = upb_Atomic_Load(&srci->blocks, memory_order_relaxed); - upb_Atomic_Store(&desi->blocks, blocks, memory_order_relaxed); + // Clone unknowns. + size_t unknown_size = 0; + const char* ptr = upb_Message_GetUnknown(src, &unknown_size); + if (unknown_size != 0) { + UPB_ASSERT(ptr); + // Make a copy into destination arena. + if (!UPB_PRIVATE(_upb_Message_AddUnknown)(dst, ptr, unknown_size, arena)) { + return NULL; + } + } + return dst; } +bool upb_Message_DeepCopy(upb_Message* dst, const upb_Message* src, + const upb_MiniTable* mini_table, upb_Arena* arena) { + upb_Message_Clear(dst, mini_table); + return _upb_Message_Copy(dst, src, mini_table, arena) != NULL; +} -#include -#include - - -// Must be last. +// Deep clones a message using the provided target arena. +// +// Returns NULL on failure. +upb_Message* upb_Message_DeepClone(const upb_Message* msg, + const upb_MiniTable* m, upb_Arena* arena) { + upb_Message* clone = upb_Message_New(m, arena); + return _upb_Message_Copy(clone, msg, m, arena); +} -upb_Array* upb_Array_New(upb_Arena* a, upb_CType type) { - const int lg2 = UPB_PRIVATE(_upb_CType_SizeLg2)(type); - return UPB_PRIVATE(_upb_Array_New)(a, 4, lg2); +// Performs a shallow copy. TODO: Extend to handle unknown fields. +void upb_Message_ShallowCopy(upb_Message* dst, const upb_Message* src, + const upb_MiniTable* m) { + memcpy(dst, src, m->UPB_PRIVATE(size)); } -const void* upb_Array_DataPtr(const upb_Array* arr) { - return _upb_array_ptr((upb_Array*)arr); +// Performs a shallow clone. Ignores unknown fields. +upb_Message* upb_Message_ShallowClone(const upb_Message* msg, + const upb_MiniTable* m, + upb_Arena* arena) { + upb_Message* clone = upb_Message_New(m, arena); + upb_Message_ShallowCopy(clone, msg, m); + return clone; } -void* upb_Array_MutableDataPtr(upb_Array* arr) { return _upb_array_ptr(arr); } -size_t upb_Array_Size(const upb_Array* arr) { return arr->UPB_PRIVATE(size); } +#include +#include -upb_MessageValue upb_Array_Get(const upb_Array* arr, size_t i) { - upb_MessageValue ret; - const char* data = _upb_array_constptr(arr); - const int lg2 = UPB_PRIVATE(_upb_Array_ElemSizeLg2)(arr); - UPB_ASSERT(i < arr->UPB_PRIVATE(size)); - memcpy(&ret, data + (i << lg2), 1 << lg2); - return ret; -} -void upb_Array_Set(upb_Array* arr, size_t i, upb_MessageValue val) { - char* data = _upb_array_ptr(arr); - const int lg2 = UPB_PRIVATE(_upb_Array_ElemSizeLg2)(arr); - UPB_ASSERT(i < arr->UPB_PRIVATE(size)); - memcpy(data + (i << lg2), &val, 1 << lg2); -} +// Must be last. -bool upb_Array_Append(upb_Array* arr, upb_MessageValue val, upb_Arena* arena) { - UPB_ASSERT(arena); - if (!_upb_Array_ResizeUninitialized(arr, arr->UPB_PRIVATE(size) + 1, arena)) { - return false; - } - upb_Array_Set(arr, arr->UPB_PRIVATE(size) - 1, val); - return true; -} +typedef struct { + upb_MdDecoder base; + upb_Arena* arena; + upb_MiniTableEnum* enum_table; + uint32_t enum_value_count; + uint32_t enum_data_count; + uint32_t enum_data_capacity; +} upb_MdEnumDecoder; -void upb_Array_Move(upb_Array* arr, size_t dst_idx, size_t src_idx, - size_t count) { - const int lg2 = UPB_PRIVATE(_upb_Array_ElemSizeLg2)(arr); - char* data = _upb_array_ptr(arr); - memmove(&data[dst_idx << lg2], &data[src_idx << lg2], count << lg2); +static size_t upb_MiniTableEnum_Size(size_t count) { + return sizeof(upb_MiniTableEnum) + count * sizeof(uint32_t); } -bool upb_Array_Insert(upb_Array* arr, size_t i, size_t count, - upb_Arena* arena) { - UPB_ASSERT(arena); - UPB_ASSERT(i <= arr->UPB_PRIVATE(size)); - UPB_ASSERT(count + arr->UPB_PRIVATE(size) >= count); - const size_t oldsize = arr->UPB_PRIVATE(size); - if (!_upb_Array_ResizeUninitialized(arr, arr->UPB_PRIVATE(size) + count, - arena)) { - return false; +static upb_MiniTableEnum* _upb_MiniTable_AddEnumDataMember(upb_MdEnumDecoder* d, + uint32_t val) { + if (d->enum_data_count == d->enum_data_capacity) { + size_t old_sz = upb_MiniTableEnum_Size(d->enum_data_capacity); + d->enum_data_capacity = UPB_MAX(2, d->enum_data_capacity * 2); + size_t new_sz = upb_MiniTableEnum_Size(d->enum_data_capacity); + d->enum_table = upb_Arena_Realloc(d->arena, d->enum_table, old_sz, new_sz); + upb_MdDecoder_CheckOutOfMemory(&d->base, d->enum_table); } - upb_Array_Move(arr, i + count, i, oldsize - i); - return true; -} - -/* - * i end arr->size - * |------------|XXXXXXXX|--------| - */ -void upb_Array_Delete(upb_Array* arr, size_t i, size_t count) { - const size_t end = i + count; - UPB_ASSERT(i <= end); - UPB_ASSERT(end <= arr->UPB_PRIVATE(size)); - upb_Array_Move(arr, i, end, arr->UPB_PRIVATE(size) - end); - arr->UPB_PRIVATE(size) -= count; + d->enum_table->UPB_PRIVATE(data)[d->enum_data_count++] = val; + return d->enum_table; } -bool upb_Array_Resize(upb_Array* arr, size_t size, upb_Arena* arena) { - const size_t oldsize = arr->UPB_PRIVATE(size); - if (UPB_UNLIKELY(!_upb_Array_ResizeUninitialized(arr, size, arena))) { - return false; - } - const size_t newsize = arr->UPB_PRIVATE(size); - if (newsize > oldsize) { - const int lg2 = UPB_PRIVATE(_upb_Array_ElemSizeLg2)(arr); - char* data = _upb_array_ptr(arr); - memset(data + (oldsize << lg2), 0, (newsize - oldsize) << lg2); +static void upb_MiniTableEnum_BuildValue(upb_MdEnumDecoder* d, uint32_t val) { + upb_MiniTableEnum* table = d->enum_table; + d->enum_value_count++; + if (table->UPB_PRIVATE(value_count) || + (val > 512 && d->enum_value_count < val / 32)) { + if (table->UPB_PRIVATE(value_count) == 0) { + UPB_ASSERT(d->enum_data_count == table->UPB_PRIVATE(mask_limit) / 32); + } + table = _upb_MiniTable_AddEnumDataMember(d, val); + table->UPB_PRIVATE(value_count)++; + } else { + uint32_t new_mask_limit = ((val / 32) + 1) * 32; + while (table->UPB_PRIVATE(mask_limit) < new_mask_limit) { + table = _upb_MiniTable_AddEnumDataMember(d, 0); + table->UPB_PRIVATE(mask_limit) += 32; + } + table->UPB_PRIVATE(data)[val / 32] |= 1ULL << (val % 32); } - return true; } -bool UPB_PRIVATE(_upb_Array_Realloc)(upb_Array* array, size_t min_capacity, - upb_Arena* arena) { - size_t new_capacity = UPB_MAX(array->UPB_PRIVATE(capacity), 4); - const int lg2 = UPB_PRIVATE(_upb_Array_ElemSizeLg2)(array); - size_t old_bytes = array->UPB_PRIVATE(capacity) << lg2; - void* ptr = _upb_array_ptr(array); - - // Log2 ceiling of size. - while (new_capacity < min_capacity) new_capacity *= 2; - - const size_t new_bytes = new_capacity << lg2; - ptr = upb_Arena_Realloc(arena, ptr, old_bytes, new_bytes); - if (!ptr) return false; +static upb_MiniTableEnum* upb_MtDecoder_DoBuildMiniTableEnum( + upb_MdEnumDecoder* d, const char* data, size_t len) { + // If the string is non-empty then it must begin with a version tag. + if (len) { + if (*data != kUpb_EncodedVersion_EnumV1) { + upb_MdDecoder_ErrorJmp(&d->base, "Invalid enum version: %c", *data); + } + data++; + len--; + } - UPB_PRIVATE(_upb_Array_SetTaggedPtr)(array, ptr, lg2); - array->UPB_PRIVATE(capacity) = new_capacity; - return true; -} + upb_MdDecoder_CheckOutOfMemory(&d->base, d->enum_table); + // Guarantee at least 64 bits of mask without checking mask size. + d->enum_table->UPB_PRIVATE(mask_limit) = 64; + d->enum_table = _upb_MiniTable_AddEnumDataMember(d, 0); + d->enum_table = _upb_MiniTable_AddEnumDataMember(d, 0); -#include -#include + d->enum_table->UPB_PRIVATE(value_count) = 0; + const char* ptr = data; + uint32_t base = 0; -// Must be last. + while (ptr < d->base.end) { + char ch = *ptr++; + if (ch <= kUpb_EncodedValue_MaxEnumMask) { + uint32_t mask = _upb_FromBase92(ch); + for (int i = 0; i < 5; i++, base++, mask >>= 1) { + if (mask & 1) upb_MiniTableEnum_BuildValue(d, base); + } + } else if (kUpb_EncodedValue_MinSkip <= ch && + ch <= kUpb_EncodedValue_MaxSkip) { + uint32_t skip; + ptr = upb_MdDecoder_DecodeBase92Varint(&d->base, ptr, ch, + kUpb_EncodedValue_MinSkip, + kUpb_EncodedValue_MaxSkip, &skip); + base += skip; + } else { + upb_MdDecoder_ErrorJmp(&d->base, "Unexpected character: %c", ch); + } + } -const upb_Extension* upb_Message_ExtensionByIndex(const upb_Message* msg, - size_t index) { - size_t count; - const upb_Extension* ext = UPB_PRIVATE(_upb_Message_Getexts)(msg, &count); + return d->enum_table; +} - UPB_ASSERT(index < count); - return &ext[index]; +static upb_MiniTableEnum* upb_MtDecoder_BuildMiniTableEnum( + upb_MdEnumDecoder* const decoder, const char* const data, + size_t const len) { + if (UPB_SETJMP(decoder->base.err) != 0) return NULL; + return upb_MtDecoder_DoBuildMiniTableEnum(decoder, data, len); } -const upb_Extension* upb_Message_FindExtensionByNumber(const upb_Message* msg, - uint32_t field_number) { - size_t count; - const upb_Extension* ext = UPB_PRIVATE(_upb_Message_Getexts)(msg, &count); +upb_MiniTableEnum* upb_MiniDescriptor_BuildEnum(const char* data, size_t len, + upb_Arena* arena, + upb_Status* status) { + upb_MdEnumDecoder decoder = { + .base = + { + .end = UPB_PTRADD(data, len), + .status = status, + }, + .arena = arena, + .enum_table = upb_Arena_Malloc(arena, upb_MiniTableEnum_Size(2)), + .enum_value_count = 0, + .enum_data_count = 0, + .enum_data_capacity = 1, + }; - while (count--) { - if (upb_MiniTableExtension_Number(ext->ext) == field_number) return ext; - ext++; - } - return NULL; + return upb_MtDecoder_BuildMiniTableEnum(&decoder, data, len); } -#include +#include +#include +#include // Must be last. -// Strings/bytes are special-cased in maps. -char _upb_Map_CTypeSizeTable[12] = { - [kUpb_CType_Bool] = 1, - [kUpb_CType_Float] = 4, - [kUpb_CType_Int32] = 4, - [kUpb_CType_UInt32] = 4, - [kUpb_CType_Enum] = 4, - [kUpb_CType_Message] = sizeof(void*), - [kUpb_CType_Double] = 8, - [kUpb_CType_Int64] = 8, - [kUpb_CType_UInt64] = 8, - [kUpb_CType_String] = UPB_MAPTYPE_STRING, - [kUpb_CType_Bytes] = UPB_MAPTYPE_STRING, -}; +// Note: we sort by this number when calculating layout order. +typedef enum { + kUpb_LayoutItemType_OneofCase, // Oneof case. + kUpb_LayoutItemType_OneofField, // Oneof field data. + kUpb_LayoutItemType_Field, // Non-oneof field data. -upb_Map* upb_Map_New(upb_Arena* a, upb_CType key_type, upb_CType value_type) { - return _upb_Map_New(a, _upb_Map_CTypeSize(key_type), - _upb_Map_CTypeSize(value_type)); -} + kUpb_LayoutItemType_Max = kUpb_LayoutItemType_Field, +} upb_LayoutItemType; -size_t upb_Map_Size(const upb_Map* map) { return _upb_Map_Size(map); } +#define kUpb_LayoutItem_IndexSentinel ((uint16_t)-1) -bool upb_Map_Get(const upb_Map* map, upb_MessageValue key, - upb_MessageValue* val) { - return _upb_Map_Get(map, &key, map->key_size, val, map->val_size); -} +typedef struct { + // Index of the corresponding field. When this is a oneof field, the field's + // offset will be the index of the next field in a linked list. + uint16_t field_index; + uint16_t offset; + upb_FieldRep rep; + upb_LayoutItemType type; +} upb_LayoutItem; -void upb_Map_Clear(upb_Map* map) { _upb_Map_Clear(map); } +typedef struct { + upb_LayoutItem* data; + size_t size; + size_t capacity; +} upb_LayoutItemVector; -upb_MapInsertStatus upb_Map_Insert(upb_Map* map, upb_MessageValue key, - upb_MessageValue val, upb_Arena* arena) { - UPB_ASSERT(arena); - return (upb_MapInsertStatus)_upb_Map_Insert(map, &key, map->key_size, &val, - map->val_size, arena); -} +typedef struct { + upb_MdDecoder base; + upb_MiniTable* table; + upb_MiniTableField* fields; + upb_MiniTablePlatform platform; + upb_LayoutItemVector vec; + upb_Arena* arena; +} upb_MtDecoder; -bool upb_Map_Delete(upb_Map* map, upb_MessageValue key, upb_MessageValue* val) { - upb_value v; - const bool removed = _upb_Map_Delete(map, &key, map->key_size, &v); - if (val) _upb_map_fromvalue(v, val, map->val_size); - return removed; -} +// In each field's offset, we temporarily store a presence classifier: +enum PresenceClass { + kNoPresence = 0, + kHasbitPresence = 1, + kRequiredPresence = 2, + kOneofBase = 3, + // Negative values refer to a specific oneof with that number. Positive + // values >= kOneofBase indicate that this field is in a oneof, and specify + // the next field in this oneof's linked list. +}; -bool upb_Map_Next(const upb_Map* map, upb_MessageValue* key, - upb_MessageValue* val, size_t* iter) { - upb_StringView k; - upb_value v; - const bool ok = upb_strtable_next2(&map->table, &k, &v, (intptr_t*)iter); - if (ok) { - _upb_map_fromkey(k, key, map->key_size); - _upb_map_fromvalue(v, val, map->val_size); - } - return ok; +static bool upb_MtDecoder_FieldIsPackable(upb_MiniTableField* field) { + return (field->UPB_PRIVATE(mode) & kUpb_FieldMode_Array) && + upb_FieldType_IsPackable(field->UPB_PRIVATE(descriptortype)); } -UPB_API void upb_Map_SetEntryValue(upb_Map* map, size_t iter, - upb_MessageValue val) { - upb_value v; - _upb_map_tovalue(&val, map->val_size, &v, NULL); - upb_strtable_setentryvalue(&map->table, iter, v); -} +typedef struct { + uint16_t submsg_count; + uint16_t subenum_count; +} upb_SubCounts; -bool upb_MapIterator_Next(const upb_Map* map, size_t* iter) { - return _upb_map_next(map, iter); -} +static void upb_MiniTable_SetTypeAndSub(upb_MiniTableField* field, + upb_FieldType type, + upb_SubCounts* sub_counts, + uint64_t msg_modifiers, + bool is_proto3_enum) { + if (is_proto3_enum) { + UPB_ASSERT(type == kUpb_FieldType_Enum); + type = kUpb_FieldType_Int32; + field->UPB_PRIVATE(mode) |= kUpb_LabelFlags_IsAlternate; + } else if (type == kUpb_FieldType_String && + !(msg_modifiers & kUpb_MessageModifier_ValidateUtf8)) { + type = kUpb_FieldType_Bytes; + field->UPB_PRIVATE(mode) |= kUpb_LabelFlags_IsAlternate; + } -bool upb_MapIterator_Done(const upb_Map* map, size_t iter) { - upb_strtable_iter i; - UPB_ASSERT(iter != kUpb_Map_Begin); - i.t = &map->table; - i.index = iter; - return upb_strtable_done(&i); -} + field->UPB_PRIVATE(descriptortype) = type; -// Returns the key and value for this entry of the map. -upb_MessageValue upb_MapIterator_Key(const upb_Map* map, size_t iter) { - upb_strtable_iter i; - upb_MessageValue ret; - i.t = &map->table; - i.index = iter; - _upb_map_fromkey(upb_strtable_iter_key(&i), &ret, map->key_size); - return ret; -} + if (upb_MtDecoder_FieldIsPackable(field) && + (msg_modifiers & kUpb_MessageModifier_DefaultIsPacked)) { + field->UPB_PRIVATE(mode) |= kUpb_LabelFlags_IsPacked; + } -upb_MessageValue upb_MapIterator_Value(const upb_Map* map, size_t iter) { - upb_strtable_iter i; - upb_MessageValue ret; - i.t = &map->table; - i.index = iter; - _upb_map_fromvalue(upb_strtable_iter_value(&i), &ret, map->val_size); - return ret; + if (type == kUpb_FieldType_Message || type == kUpb_FieldType_Group) { + field->UPB_PRIVATE(submsg_index) = sub_counts->submsg_count++; + } else if (type == kUpb_FieldType_Enum) { + // We will need to update this later once we know the total number of + // submsg fields. + field->UPB_PRIVATE(submsg_index) = sub_counts->subenum_count++; + } else { + field->UPB_PRIVATE(submsg_index) = kUpb_NoSub; + } } -// EVERYTHING BELOW THIS LINE IS INTERNAL - DO NOT USE ///////////////////////// +static const char kUpb_EncodedToType[] = { + [kUpb_EncodedType_Double] = kUpb_FieldType_Double, + [kUpb_EncodedType_Float] = kUpb_FieldType_Float, + [kUpb_EncodedType_Int64] = kUpb_FieldType_Int64, + [kUpb_EncodedType_UInt64] = kUpb_FieldType_UInt64, + [kUpb_EncodedType_Int32] = kUpb_FieldType_Int32, + [kUpb_EncodedType_Fixed64] = kUpb_FieldType_Fixed64, + [kUpb_EncodedType_Fixed32] = kUpb_FieldType_Fixed32, + [kUpb_EncodedType_Bool] = kUpb_FieldType_Bool, + [kUpb_EncodedType_String] = kUpb_FieldType_String, + [kUpb_EncodedType_Group] = kUpb_FieldType_Group, + [kUpb_EncodedType_Message] = kUpb_FieldType_Message, + [kUpb_EncodedType_Bytes] = kUpb_FieldType_Bytes, + [kUpb_EncodedType_UInt32] = kUpb_FieldType_UInt32, + [kUpb_EncodedType_OpenEnum] = kUpb_FieldType_Enum, + [kUpb_EncodedType_SFixed32] = kUpb_FieldType_SFixed32, + [kUpb_EncodedType_SFixed64] = kUpb_FieldType_SFixed64, + [kUpb_EncodedType_SInt32] = kUpb_FieldType_SInt32, + [kUpb_EncodedType_SInt64] = kUpb_FieldType_SInt64, + [kUpb_EncodedType_ClosedEnum] = kUpb_FieldType_Enum, +}; -upb_Map* _upb_Map_New(upb_Arena* a, size_t key_size, size_t value_size) { - upb_Map* map = upb_Arena_Malloc(a, sizeof(upb_Map)); - if (!map) return NULL; +static void upb_MiniTable_SetField(upb_MtDecoder* d, uint8_t ch, + upb_MiniTableField* field, + uint64_t msg_modifiers, + upb_SubCounts* sub_counts) { + static const char kUpb_EncodedToFieldRep[] = { + [kUpb_EncodedType_Double] = kUpb_FieldRep_8Byte, + [kUpb_EncodedType_Float] = kUpb_FieldRep_4Byte, + [kUpb_EncodedType_Int64] = kUpb_FieldRep_8Byte, + [kUpb_EncodedType_UInt64] = kUpb_FieldRep_8Byte, + [kUpb_EncodedType_Int32] = kUpb_FieldRep_4Byte, + [kUpb_EncodedType_Fixed64] = kUpb_FieldRep_8Byte, + [kUpb_EncodedType_Fixed32] = kUpb_FieldRep_4Byte, + [kUpb_EncodedType_Bool] = kUpb_FieldRep_1Byte, + [kUpb_EncodedType_String] = kUpb_FieldRep_StringView, + [kUpb_EncodedType_Bytes] = kUpb_FieldRep_StringView, + [kUpb_EncodedType_UInt32] = kUpb_FieldRep_4Byte, + [kUpb_EncodedType_OpenEnum] = kUpb_FieldRep_4Byte, + [kUpb_EncodedType_SFixed32] = kUpb_FieldRep_4Byte, + [kUpb_EncodedType_SFixed64] = kUpb_FieldRep_8Byte, + [kUpb_EncodedType_SInt32] = kUpb_FieldRep_4Byte, + [kUpb_EncodedType_SInt64] = kUpb_FieldRep_8Byte, + [kUpb_EncodedType_ClosedEnum] = kUpb_FieldRep_4Byte, + }; - upb_strtable_init(&map->table, 4, a); - map->key_size = key_size; - map->val_size = value_size; + char pointer_rep = d->platform == kUpb_MiniTablePlatform_32Bit + ? kUpb_FieldRep_4Byte + : kUpb_FieldRep_8Byte; - return map; + int8_t type = _upb_FromBase92(ch); + if (ch >= _upb_ToBase92(kUpb_EncodedType_RepeatedBase)) { + type -= kUpb_EncodedType_RepeatedBase; + field->UPB_PRIVATE(mode) = kUpb_FieldMode_Array; + field->UPB_PRIVATE(mode) |= pointer_rep << kUpb_FieldRep_Shift; + field->UPB_PRIVATE(offset) = kNoPresence; + } else { + field->UPB_PRIVATE(mode) = kUpb_FieldMode_Scalar; + field->UPB_PRIVATE(offset) = kHasbitPresence; + if (type == kUpb_EncodedType_Group || type == kUpb_EncodedType_Message) { + field->UPB_PRIVATE(mode) |= pointer_rep << kUpb_FieldRep_Shift; + } else if ((unsigned long)type >= sizeof(kUpb_EncodedToFieldRep)) { + upb_MdDecoder_ErrorJmp(&d->base, "Invalid field type: %d", (int)type); + } else { + field->UPB_PRIVATE(mode) |= kUpb_EncodedToFieldRep[type] + << kUpb_FieldRep_Shift; + } + } + if ((unsigned long)type >= sizeof(kUpb_EncodedToType)) { + upb_MdDecoder_ErrorJmp(&d->base, "Invalid field type: %d", (int)type); + } + upb_MiniTable_SetTypeAndSub(field, kUpb_EncodedToType[type], sub_counts, + msg_modifiers, type == kUpb_EncodedType_OpenEnum); } +static void upb_MtDecoder_ModifyField(upb_MtDecoder* d, + uint32_t message_modifiers, + uint32_t field_modifiers, + upb_MiniTableField* field) { + if (field_modifiers & kUpb_EncodedFieldModifier_FlipPacked) { + if (!upb_MtDecoder_FieldIsPackable(field)) { + upb_MdDecoder_ErrorJmp(&d->base, + "Cannot flip packed on unpackable field %" PRIu32, + upb_MiniTableField_Number(field)); + } + field->UPB_PRIVATE(mode) ^= kUpb_LabelFlags_IsPacked; + } -#include -#include + if (field_modifiers & kUpb_EncodedFieldModifier_FlipValidateUtf8) { + if (field->UPB_PRIVATE(descriptortype) != kUpb_FieldType_Bytes || + !(field->UPB_PRIVATE(mode) & kUpb_LabelFlags_IsAlternate)) { + upb_MdDecoder_ErrorJmp(&d->base, + "Cannot flip ValidateUtf8 on field %" PRIu32 + ", type=%d, mode=%d", + upb_MiniTableField_Number(field), + (int)field->UPB_PRIVATE(descriptortype), + (int)field->UPB_PRIVATE(mode)); + } + field->UPB_PRIVATE(descriptortype) = kUpb_FieldType_String; + field->UPB_PRIVATE(mode) &= ~kUpb_LabelFlags_IsAlternate; + } + bool singular = field_modifiers & kUpb_EncodedFieldModifier_IsProto3Singular; + bool required = field_modifiers & kUpb_EncodedFieldModifier_IsRequired; -// Must be last. + // Validate. + if ((singular || required) && field->UPB_PRIVATE(offset) != kHasbitPresence) { + upb_MdDecoder_ErrorJmp(&d->base, + "Invalid modifier(s) for repeated field %" PRIu32, + upb_MiniTableField_Number(field)); + } + if (singular && required) { + upb_MdDecoder_ErrorJmp( + &d->base, "Field %" PRIu32 " cannot be both singular and required", + upb_MiniTableField_Number(field)); + } -static void _upb_mapsorter_getkeys(const void* _a, const void* _b, void* a_key, - void* b_key, size_t size) { - const upb_tabent* const* a = _a; - const upb_tabent* const* b = _b; - upb_StringView a_tabkey = upb_tabstrview((*a)->key); - upb_StringView b_tabkey = upb_tabstrview((*b)->key); - _upb_map_fromkey(a_tabkey, a_key, size); - _upb_map_fromkey(b_tabkey, b_key, size); + if (singular) field->UPB_PRIVATE(offset) = kNoPresence; + if (required) { + field->UPB_PRIVATE(offset) = kRequiredPresence; + } } -static int _upb_mapsorter_cmpi64(const void* _a, const void* _b) { - int64_t a, b; - _upb_mapsorter_getkeys(_a, _b, &a, &b, 8); - return a < b ? -1 : a > b; +static void upb_MtDecoder_PushItem(upb_MtDecoder* d, upb_LayoutItem item) { + if (d->vec.size == d->vec.capacity) { + size_t new_cap = UPB_MAX(8, d->vec.size * 2); + d->vec.data = realloc(d->vec.data, new_cap * sizeof(*d->vec.data)); + upb_MdDecoder_CheckOutOfMemory(&d->base, d->vec.data); + d->vec.capacity = new_cap; + } + d->vec.data[d->vec.size++] = item; } -static int _upb_mapsorter_cmpu64(const void* _a, const void* _b) { - uint64_t a, b; - _upb_mapsorter_getkeys(_a, _b, &a, &b, 8); - return a < b ? -1 : a > b; -} +static void upb_MtDecoder_PushOneof(upb_MtDecoder* d, upb_LayoutItem item) { + if (item.field_index == kUpb_LayoutItem_IndexSentinel) { + upb_MdDecoder_ErrorJmp(&d->base, "Empty oneof"); + } + item.field_index -= kOneofBase; -static int _upb_mapsorter_cmpi32(const void* _a, const void* _b) { - int32_t a, b; - _upb_mapsorter_getkeys(_a, _b, &a, &b, 4); - return a < b ? -1 : a > b; -} + // Push oneof data. + item.type = kUpb_LayoutItemType_OneofField; + upb_MtDecoder_PushItem(d, item); -static int _upb_mapsorter_cmpu32(const void* _a, const void* _b) { - uint32_t a, b; - _upb_mapsorter_getkeys(_a, _b, &a, &b, 4); - return a < b ? -1 : a > b; + // Push oneof case. + item.rep = kUpb_FieldRep_4Byte; // Field Number. + item.type = kUpb_LayoutItemType_OneofCase; + upb_MtDecoder_PushItem(d, item); } -static int _upb_mapsorter_cmpbool(const void* _a, const void* _b) { - bool a, b; - _upb_mapsorter_getkeys(_a, _b, &a, &b, 1); - return a < b ? -1 : a > b; +size_t upb_MtDecoder_SizeOfRep(upb_FieldRep rep, + upb_MiniTablePlatform platform) { + static const uint8_t kRepToSize32[] = { + [kUpb_FieldRep_1Byte] = 1, + [kUpb_FieldRep_4Byte] = 4, + [kUpb_FieldRep_StringView] = 8, + [kUpb_FieldRep_8Byte] = 8, + }; + static const uint8_t kRepToSize64[] = { + [kUpb_FieldRep_1Byte] = 1, + [kUpb_FieldRep_4Byte] = 4, + [kUpb_FieldRep_StringView] = 16, + [kUpb_FieldRep_8Byte] = 8, + }; + UPB_ASSERT(sizeof(upb_StringView) == + UPB_SIZE(kRepToSize32, kRepToSize64)[kUpb_FieldRep_StringView]); + return platform == kUpb_MiniTablePlatform_32Bit ? kRepToSize32[rep] + : kRepToSize64[rep]; } -static int _upb_mapsorter_cmpstr(const void* _a, const void* _b) { - upb_StringView a, b; - _upb_mapsorter_getkeys(_a, _b, &a, &b, UPB_MAPTYPE_STRING); - size_t common_size = UPB_MIN(a.size, b.size); - int cmp = memcmp(a.data, b.data, common_size); - if (cmp) return -cmp; - return a.size < b.size ? -1 : a.size > b.size; +size_t upb_MtDecoder_AlignOfRep(upb_FieldRep rep, + upb_MiniTablePlatform platform) { + static const uint8_t kRepToAlign32[] = { + [kUpb_FieldRep_1Byte] = 1, + [kUpb_FieldRep_4Byte] = 4, + [kUpb_FieldRep_StringView] = 4, + [kUpb_FieldRep_8Byte] = 8, + }; + static const uint8_t kRepToAlign64[] = { + [kUpb_FieldRep_1Byte] = 1, + [kUpb_FieldRep_4Byte] = 4, + [kUpb_FieldRep_StringView] = 8, + [kUpb_FieldRep_8Byte] = 8, + }; + UPB_ASSERT(UPB_ALIGN_OF(upb_StringView) == + UPB_SIZE(kRepToAlign32, kRepToAlign64)[kUpb_FieldRep_StringView]); + return platform == kUpb_MiniTablePlatform_32Bit ? kRepToAlign32[rep] + : kRepToAlign64[rep]; } -static int (*const compar[kUpb_FieldType_SizeOf])(const void*, const void*) = { - [kUpb_FieldType_Int64] = _upb_mapsorter_cmpi64, - [kUpb_FieldType_SFixed64] = _upb_mapsorter_cmpi64, - [kUpb_FieldType_SInt64] = _upb_mapsorter_cmpi64, - - [kUpb_FieldType_UInt64] = _upb_mapsorter_cmpu64, - [kUpb_FieldType_Fixed64] = _upb_mapsorter_cmpu64, - - [kUpb_FieldType_Int32] = _upb_mapsorter_cmpi32, - [kUpb_FieldType_SInt32] = _upb_mapsorter_cmpi32, - [kUpb_FieldType_SFixed32] = _upb_mapsorter_cmpi32, - [kUpb_FieldType_Enum] = _upb_mapsorter_cmpi32, - - [kUpb_FieldType_UInt32] = _upb_mapsorter_cmpu32, - [kUpb_FieldType_Fixed32] = _upb_mapsorter_cmpu32, - - [kUpb_FieldType_Bool] = _upb_mapsorter_cmpbool, - - [kUpb_FieldType_String] = _upb_mapsorter_cmpstr, - [kUpb_FieldType_Bytes] = _upb_mapsorter_cmpstr, -}; - -static bool _upb_mapsorter_resize(_upb_mapsorter* s, _upb_sortedmap* sorted, - int size) { - sorted->start = s->size; - sorted->pos = sorted->start; - sorted->end = sorted->start + size; +static const char* upb_MtDecoder_DecodeOneofField(upb_MtDecoder* d, + const char* ptr, + char first_ch, + upb_LayoutItem* item) { + uint32_t field_num; + ptr = upb_MdDecoder_DecodeBase92Varint( + &d->base, ptr, first_ch, kUpb_EncodedValue_MinOneofField, + kUpb_EncodedValue_MaxOneofField, &field_num); + upb_MiniTableField* f = + (void*)upb_MiniTable_FindFieldByNumber(d->table, field_num); - if (sorted->end > s->cap) { - const int oldsize = s->cap * sizeof(*s->entries); - s->cap = upb_Log2CeilingSize(sorted->end); - const int newsize = s->cap * sizeof(*s->entries); - s->entries = upb_grealloc(s->entries, oldsize, newsize); - if (!s->entries) return false; + if (!f) { + upb_MdDecoder_ErrorJmp(&d->base, + "Couldn't add field number %" PRIu32 + " to oneof, no such field number.", + field_num); + } + if (f->UPB_PRIVATE(offset) != kHasbitPresence) { + upb_MdDecoder_ErrorJmp( + &d->base, + "Cannot add repeated, required, or singular field %" PRIu32 + " to oneof.", + field_num); } - s->size = sorted->end; - return true; + // Oneof storage must be large enough to accommodate the largest member. + int rep = f->UPB_PRIVATE(mode) >> kUpb_FieldRep_Shift; + if (upb_MtDecoder_SizeOfRep(rep, d->platform) > + upb_MtDecoder_SizeOfRep(item->rep, d->platform)) { + item->rep = rep; + } + // Prepend this field to the linked list. + f->UPB_PRIVATE(offset) = item->field_index; + item->field_index = (f - d->fields) + kOneofBase; + return ptr; } -bool _upb_mapsorter_pushmap(_upb_mapsorter* s, upb_FieldType key_type, - const upb_Map* map, _upb_sortedmap* sorted) { - int map_size = _upb_Map_Size(map); - - if (!_upb_mapsorter_resize(s, sorted, map_size)) return false; - - // Copy non-empty entries from the table to s->entries. - const void** dst = &s->entries[sorted->start]; - const upb_tabent* src = map->table.t.entries; - const upb_tabent* end = src + upb_table_size(&map->table.t); - for (; src < end; src++) { - if (!upb_tabent_isempty(src)) { - *dst = src; - dst++; +static const char* upb_MtDecoder_DecodeOneofs(upb_MtDecoder* d, + const char* ptr) { + upb_LayoutItem item = {.rep = 0, + .field_index = kUpb_LayoutItem_IndexSentinel}; + while (ptr < d->base.end) { + char ch = *ptr++; + if (ch == kUpb_EncodedValue_FieldSeparator) { + // Field separator, no action needed. + } else if (ch == kUpb_EncodedValue_OneofSeparator) { + // End of oneof. + upb_MtDecoder_PushOneof(d, item); + item.field_index = kUpb_LayoutItem_IndexSentinel; // Move to next oneof. + } else { + ptr = upb_MtDecoder_DecodeOneofField(d, ptr, ch, &item); } } - UPB_ASSERT(dst == &s->entries[sorted->end]); - - // Sort entries according to the key type. - qsort(&s->entries[sorted->start], map_size, sizeof(*s->entries), - compar[key_type]); - return true; -} -static int _upb_mapsorter_cmpext(const void* _a, const void* _b) { - const upb_Extension* const* a = _a; - const upb_Extension* const* b = _b; - uint32_t a_num = upb_MiniTableExtension_Number((*a)->ext); - uint32_t b_num = upb_MiniTableExtension_Number((*b)->ext); - assert(a_num != b_num); - return a_num < b_num ? -1 : 1; + // Push final oneof. + upb_MtDecoder_PushOneof(d, item); + return ptr; } -bool _upb_mapsorter_pushexts(_upb_mapsorter* s, const upb_Extension* exts, - size_t count, _upb_sortedmap* sorted) { - if (!_upb_mapsorter_resize(s, sorted, count)) return false; - - for (size_t i = 0; i < count; i++) { - s->entries[sorted->start + i] = &exts[i]; +static const char* upb_MtDecoder_ParseModifier(upb_MtDecoder* d, + const char* ptr, char first_ch, + upb_MiniTableField* last_field, + uint64_t* msg_modifiers) { + uint32_t mod; + ptr = upb_MdDecoder_DecodeBase92Varint(&d->base, ptr, first_ch, + kUpb_EncodedValue_MinModifier, + kUpb_EncodedValue_MaxModifier, &mod); + if (last_field) { + upb_MtDecoder_ModifyField(d, *msg_modifiers, mod, last_field); + } else { + if (!d->table) { + upb_MdDecoder_ErrorJmp(&d->base, + "Extensions cannot have message modifiers"); + } + *msg_modifiers = mod; } - qsort(&s->entries[sorted->start], count, sizeof(*s->entries), - _upb_mapsorter_cmpext); - return true; -} - - -#include -#include -#include - - -// Must be last. - -static const size_t message_overhead = sizeof(upb_Message_InternalData); - -upb_Message* upb_Message_New(const upb_MiniTable* m, upb_Arena* a) { - return _upb_Message_New(m, a); -} - -bool UPB_PRIVATE(_upb_Message_AddUnknown)(upb_Message* msg, const char* data, - size_t len, upb_Arena* arena) { - if (!UPB_PRIVATE(_upb_Message_Realloc)(msg, len, arena)) return false; - upb_Message_Internal* owner = upb_Message_Getinternal(msg); - upb_Message_InternalData* in = owner->internal; - memcpy(UPB_PTR_AT(in, in->unknown_end, char), data, len); - in->unknown_end += len; - return true; + return ptr; } -void _upb_Message_DiscardUnknown_shallow(upb_Message* msg) { - upb_Message_Internal* owner = upb_Message_Getinternal(msg); - upb_Message_InternalData* in = owner->internal; - if (in) { - in->unknown_end = message_overhead; +static void upb_MtDecoder_AllocateSubs(upb_MtDecoder* d, + upb_SubCounts sub_counts) { + uint32_t total_count = sub_counts.submsg_count + sub_counts.subenum_count; + size_t subs_bytes = sizeof(*d->table->UPB_PRIVATE(subs)) * total_count; + upb_MiniTableSub* subs = upb_Arena_Malloc(d->arena, subs_bytes); + upb_MdDecoder_CheckOutOfMemory(&d->base, subs); + uint32_t i = 0; + for (; i < sub_counts.submsg_count; i++) { + subs[i].UPB_PRIVATE(submsg) = UPB_PRIVATE(_upb_MiniTable_Empty)(); } -} - -const char* upb_Message_GetUnknown(const upb_Message* msg, size_t* len) { - upb_Message_Internal* owner = upb_Message_Getinternal(msg); - upb_Message_InternalData* in = owner->internal; - if (in) { - *len = in->unknown_end - message_overhead; - return (char*)(in + 1); - } else { - *len = 0; - return NULL; + if (sub_counts.subenum_count) { + upb_MiniTableField* f = d->fields; + upb_MiniTableField* end_f = f + d->table->UPB_PRIVATE(field_count); + for (; f < end_f; f++) { + if (f->UPB_PRIVATE(descriptortype) == kUpb_FieldType_Enum) { + f->UPB_PRIVATE(submsg_index) += sub_counts.submsg_count; + } + } + for (; i < sub_counts.submsg_count + sub_counts.subenum_count; i++) { + subs[i].UPB_PRIVATE(subenum) = NULL; + } } + d->table->UPB_PRIVATE(subs) = subs; } -void upb_Message_DeleteUnknown(upb_Message* msg, const char* data, size_t len) { - upb_Message_Internal* owner = upb_Message_Getinternal(msg); - upb_Message_InternalData* in = owner->internal; - const char* internal_unknown_end = UPB_PTR_AT(in, in->unknown_end, char); - -#ifndef NDEBUG - size_t full_unknown_size; - const char* full_unknown = upb_Message_GetUnknown(msg, &full_unknown_size); - UPB_ASSERT((uintptr_t)data >= (uintptr_t)full_unknown); - UPB_ASSERT((uintptr_t)data < (uintptr_t)(full_unknown + full_unknown_size)); - UPB_ASSERT((uintptr_t)(data + len) > (uintptr_t)data); - UPB_ASSERT((uintptr_t)(data + len) <= (uintptr_t)internal_unknown_end); -#endif +static const char* upb_MtDecoder_Parse(upb_MtDecoder* d, const char* ptr, + size_t len, void* fields, + size_t field_size, uint16_t* field_count, + upb_SubCounts* sub_counts) { + uint64_t msg_modifiers = 0; + uint32_t last_field_number = 0; + upb_MiniTableField* last_field = NULL; + bool need_dense_below = d->table != NULL; - if ((data + len) != internal_unknown_end) { - memmove((char*)data, data + len, internal_unknown_end - data - len); + d->base.end = UPB_PTRADD(ptr, len); + + while (ptr < d->base.end) { + char ch = *ptr++; + if (ch <= kUpb_EncodedValue_MaxField) { + if (!d->table && last_field) { + // For extensions, consume only a single field and then return. + return --ptr; + } + upb_MiniTableField* field = fields; + *field_count += 1; + fields = (char*)fields + field_size; + field->UPB_PRIVATE(number) = ++last_field_number; + last_field = field; + upb_MiniTable_SetField(d, ch, field, msg_modifiers, sub_counts); + } else if (kUpb_EncodedValue_MinModifier <= ch && + ch <= kUpb_EncodedValue_MaxModifier) { + ptr = upb_MtDecoder_ParseModifier(d, ptr, ch, last_field, &msg_modifiers); + if (msg_modifiers & kUpb_MessageModifier_IsExtendable) { + d->table->UPB_PRIVATE(ext) |= kUpb_ExtMode_Extendable; + } + } else if (ch == kUpb_EncodedValue_End) { + if (!d->table) { + upb_MdDecoder_ErrorJmp(&d->base, "Extensions cannot have oneofs."); + } + ptr = upb_MtDecoder_DecodeOneofs(d, ptr); + } else if (kUpb_EncodedValue_MinSkip <= ch && + ch <= kUpb_EncodedValue_MaxSkip) { + if (need_dense_below) { + d->table->UPB_PRIVATE(dense_below) = d->table->UPB_PRIVATE(field_count); + need_dense_below = false; + } + uint32_t skip; + ptr = upb_MdDecoder_DecodeBase92Varint(&d->base, ptr, ch, + kUpb_EncodedValue_MinSkip, + kUpb_EncodedValue_MaxSkip, &skip); + last_field_number += skip; + last_field_number--; // Next field seen will increment. + } else { + upb_MdDecoder_ErrorJmp(&d->base, "Invalid char: %c", ch); + } } - in->unknown_end -= len; -} -size_t upb_Message_ExtensionCount(const upb_Message* msg) { - size_t count; - UPB_PRIVATE(_upb_Message_Getexts)(msg, &count); - return count; -} + if (need_dense_below) { + d->table->UPB_PRIVATE(dense_below) = d->table->UPB_PRIVATE(field_count); + } + return ptr; +} -#include +static void upb_MtDecoder_ParseMessage(upb_MtDecoder* d, const char* data, + size_t len) { + // Buffer length is an upper bound on the number of fields. We will return + // what we don't use. + d->fields = upb_Arena_Malloc(d->arena, sizeof(*d->fields) * len); + upb_MdDecoder_CheckOutOfMemory(&d->base, d->fields); + upb_SubCounts sub_counts = {0, 0}; + d->table->UPB_PRIVATE(field_count) = 0; + d->table->UPB_PRIVATE(fields) = d->fields; + upb_MtDecoder_Parse(d, data, len, d->fields, sizeof(*d->fields), + &d->table->UPB_PRIVATE(field_count), &sub_counts); -// Must be last. + upb_Arena_ShrinkLast(d->arena, d->fields, sizeof(*d->fields) * len, + sizeof(*d->fields) * d->table->UPB_PRIVATE(field_count)); + d->table->UPB_PRIVATE(fields) = d->fields; + upb_MtDecoder_AllocateSubs(d, sub_counts); +} -bool upb_Message_SetMapEntry(upb_Map* map, const upb_MiniTable* mini_table, - const upb_MiniTableField* f, - upb_Message* map_entry_message, upb_Arena* arena) { - // TODO: use a variant of upb_MiniTable_GetSubMessageTable() here. - const upb_MiniTable* map_entry_mini_table = upb_MiniTableSub_Message( - mini_table->UPB_PRIVATE(subs)[f->UPB_PRIVATE(submsg_index)]); - UPB_ASSERT(map_entry_mini_table); - UPB_ASSERT(map_entry_mini_table->UPB_PRIVATE(field_count) == 2); - const upb_MiniTableField* map_entry_key_field = - &map_entry_mini_table->UPB_PRIVATE(fields)[0]; - const upb_MiniTableField* map_entry_value_field = - &map_entry_mini_table->UPB_PRIVATE(fields)[1]; - // Map key/value cannot have explicit defaults, - // hence assuming a zero default is valid. - upb_MessageValue default_val; - memset(&default_val, 0, sizeof(upb_MessageValue)); - upb_MessageValue map_entry_key = - upb_Message_GetField(map_entry_message, map_entry_key_field, default_val); - upb_MessageValue map_entry_value = upb_Message_GetField( - map_entry_message, map_entry_value_field, default_val); - return upb_Map_Set(map, map_entry_key, map_entry_value, arena); +int upb_MtDecoder_CompareFields(const void* _a, const void* _b) { + const upb_LayoutItem* a = _a; + const upb_LayoutItem* b = _b; + // Currently we just sort by: + // 1. rep (smallest fields first) + // 2. type (oneof cases first) + // 2. field_index (smallest numbers first) + // The main goal of this is to reduce space lost to padding. + // Later we may have more subtle reasons to prefer a different ordering. + const int rep_bits = upb_Log2Ceiling(kUpb_FieldRep_Max); + const int type_bits = upb_Log2Ceiling(kUpb_LayoutItemType_Max); + const int idx_bits = (sizeof(a->field_index) * 8); + UPB_ASSERT(idx_bits + rep_bits + type_bits < 32); +#define UPB_COMBINE(rep, ty, idx) (((rep << type_bits) | ty) << idx_bits) | idx + uint32_t a_packed = UPB_COMBINE(a->rep, a->type, a->field_index); + uint32_t b_packed = UPB_COMBINE(b->rep, b->type, b->field_index); + UPB_ASSERT(a_packed != b_packed); +#undef UPB_COMBINE + return a_packed < b_packed ? -1 : 1; } +static bool upb_MtDecoder_SortLayoutItems(upb_MtDecoder* d) { + // Add items for all non-oneof fields (oneofs were already added). + int n = d->table->UPB_PRIVATE(field_count); + for (int i = 0; i < n; i++) { + upb_MiniTableField* f = &d->fields[i]; + if (f->UPB_PRIVATE(offset) >= kOneofBase) continue; + upb_LayoutItem item = {.field_index = i, + .rep = f->UPB_PRIVATE(mode) >> kUpb_FieldRep_Shift, + .type = kUpb_LayoutItemType_Field}; + upb_MtDecoder_PushItem(d, item); + } -#include + if (d->vec.size) { + qsort(d->vec.data, d->vec.size, sizeof(*d->vec.data), + upb_MtDecoder_CompareFields); + } + return true; +} -// Must be last. +static size_t upb_MiniTable_DivideRoundUp(size_t n, size_t d) { + return (n + d - 1) / d; +} -bool upb_Message_IsExactlyEqual(const upb_Message* msg1, - const upb_Message* msg2, - const upb_MiniTable* m) { - if (msg1 == msg2) return true; +static void upb_MtDecoder_AssignHasbits(upb_MtDecoder* d) { + upb_MiniTable* ret = d->table; + int n = ret->UPB_PRIVATE(field_count); + int last_hasbit = 0; // 0 cannot be used. - int opts = kUpb_EncodeOption_SkipUnknown | kUpb_EncodeOption_Deterministic; - upb_Arena* a = upb_Arena_New(); + // First assign required fields, which must have the lowest hasbits. + for (int i = 0; i < n; i++) { + upb_MiniTableField* field = + (upb_MiniTableField*)&ret->UPB_PRIVATE(fields)[i]; + if (field->UPB_PRIVATE(offset) == kRequiredPresence) { + field->presence = ++last_hasbit; + } else if (field->UPB_PRIVATE(offset) == kNoPresence) { + field->presence = 0; + } + } + if (last_hasbit > 63) { + upb_MdDecoder_ErrorJmp(&d->base, "Too many required fields"); + } - // Compare deterministically serialized payloads with no unknown fields. - size_t size1, size2; - char *data1, *data2; - upb_EncodeStatus status1 = upb_Encode(msg1, m, opts, a, &data1, &size1); - upb_EncodeStatus status2 = upb_Encode(msg2, m, opts, a, &data2, &size2); + ret->UPB_PRIVATE(required_count) = last_hasbit; - if (status1 != kUpb_EncodeStatus_Ok || status2 != kUpb_EncodeStatus_Ok) { - // TODO: How should we fail here? (In Ruby we throw an exception.) - upb_Arena_Free(a); - return false; + // Next assign non-required hasbit fields. + for (int i = 0; i < n; i++) { + upb_MiniTableField* field = + (upb_MiniTableField*)&ret->UPB_PRIVATE(fields)[i]; + if (field->UPB_PRIVATE(offset) == kHasbitPresence) { + field->presence = ++last_hasbit; + } } - const bool ret = (size1 == size2) && (memcmp(data1, data2, size1) == 0); - upb_Arena_Free(a); - return ret; + ret->UPB_PRIVATE(size) = + last_hasbit ? upb_MiniTable_DivideRoundUp(last_hasbit + 1, 8) : 0; } +size_t upb_MtDecoder_Place(upb_MtDecoder* d, upb_FieldRep rep) { + size_t size = upb_MtDecoder_SizeOfRep(rep, d->platform); + size_t align = upb_MtDecoder_AlignOfRep(rep, d->platform); + size_t ret = UPB_ALIGN_UP(d->table->UPB_PRIVATE(size), align); + static const size_t max = UINT16_MAX; + size_t new_size = ret + size; + if (new_size > max) { + upb_MdDecoder_ErrorJmp( + &d->base, "Message size exceeded maximum size of %zu bytes", max); + } + d->table->UPB_PRIVATE(size) = new_size; + return ret; +} -#include -#include - +static void upb_MtDecoder_AssignOffsets(upb_MtDecoder* d) { + upb_LayoutItem* end = UPB_PTRADD(d->vec.data, d->vec.size); -// Must be last. + // Compute offsets. + for (upb_LayoutItem* item = d->vec.data; item < end; item++) { + item->offset = upb_MtDecoder_Place(d, item->rep); + } -static upb_StringView upb_Clone_StringView(upb_StringView str, - upb_Arena* arena) { - if (str.size == 0) { - return upb_StringView_FromDataAndSize(NULL, 0); + // Assign oneof case offsets. We must do these first, since assigning + // actual offsets will overwrite the links of the linked list. + for (upb_LayoutItem* item = d->vec.data; item < end; item++) { + if (item->type != kUpb_LayoutItemType_OneofCase) continue; + upb_MiniTableField* f = &d->fields[item->field_index]; + while (true) { + f->presence = ~item->offset; + if (f->UPB_PRIVATE(offset) == kUpb_LayoutItem_IndexSentinel) break; + UPB_ASSERT(f->UPB_PRIVATE(offset) - kOneofBase < + d->table->UPB_PRIVATE(field_count)); + f = &d->fields[f->UPB_PRIVATE(offset) - kOneofBase]; + } } - void* cloned_data = upb_Arena_Malloc(arena, str.size); - upb_StringView cloned_str = - upb_StringView_FromDataAndSize(cloned_data, str.size); - memcpy(cloned_data, str.data, str.size); - return cloned_str; -} -static bool upb_Clone_MessageValue(void* value, upb_CType value_type, - const upb_MiniTable* sub, upb_Arena* arena) { - switch (value_type) { - case kUpb_CType_Bool: - case kUpb_CType_Float: - case kUpb_CType_Int32: - case kUpb_CType_UInt32: - case kUpb_CType_Enum: - case kUpb_CType_Double: - case kUpb_CType_Int64: - case kUpb_CType_UInt64: - return true; - case kUpb_CType_String: - case kUpb_CType_Bytes: { - upb_StringView source = *(upb_StringView*)value; - int size = source.size; - void* cloned_data = upb_Arena_Malloc(arena, size); - if (cloned_data == NULL) { - return false; - } - *(upb_StringView*)value = - upb_StringView_FromDataAndSize(cloned_data, size); - memcpy(cloned_data, source.data, size); - return true; - } break; - case kUpb_CType_Message: { - const upb_TaggedMessagePtr source = *(upb_TaggedMessagePtr*)value; - bool is_empty = upb_TaggedMessagePtr_IsEmpty(source); - if (is_empty) sub = UPB_PRIVATE(_upb_MiniTable_Empty)(); - UPB_ASSERT(source); - upb_Message* clone = upb_Message_DeepClone( - UPB_PRIVATE(_upb_TaggedMessagePtr_GetMessage)(source), sub, arena); - *(upb_TaggedMessagePtr*)value = - UPB_PRIVATE(_upb_TaggedMessagePtr_Pack)(clone, is_empty); - return clone != NULL; - } break; + // Assign offsets. + for (upb_LayoutItem* item = d->vec.data; item < end; item++) { + upb_MiniTableField* f = &d->fields[item->field_index]; + switch (item->type) { + case kUpb_LayoutItemType_OneofField: + while (true) { + uint16_t next_offset = f->UPB_PRIVATE(offset); + f->UPB_PRIVATE(offset) = item->offset; + if (next_offset == kUpb_LayoutItem_IndexSentinel) break; + f = &d->fields[next_offset - kOneofBase]; + } + break; + case kUpb_LayoutItemType_Field: + f->UPB_PRIVATE(offset) = item->offset; + break; + default: + break; + } } - UPB_UNREACHABLE(); + + // The fasttable parser (supported on 64-bit only) depends on this being a + // multiple of 8 in order to satisfy UPB_MALLOC_ALIGN, which is also 8. + // + // On 32-bit we could potentially make this smaller, but there is no + // compelling reason to optimize this right now. + d->table->UPB_PRIVATE(size) = UPB_ALIGN_UP(d->table->UPB_PRIVATE(size), 8); } -upb_Map* upb_Map_DeepClone(const upb_Map* map, upb_CType key_type, - upb_CType value_type, - const upb_MiniTable* map_entry_table, - upb_Arena* arena) { - upb_Map* cloned_map = _upb_Map_New(arena, map->key_size, map->val_size); - if (cloned_map == NULL) { - return NULL; - } - upb_MessageValue key, val; - size_t iter = kUpb_Map_Begin; - while (upb_Map_Next(map, &key, &val, &iter)) { - const upb_MiniTableField* value_field = - &map_entry_table->UPB_PRIVATE(fields)[1]; - const upb_MiniTable* value_sub = - (value_field->UPB_PRIVATE(submsg_index) != kUpb_NoSub) - ? upb_MiniTable_GetSubMessageTable(map_entry_table, value_field) - : NULL; - upb_CType value_field_type = upb_MiniTableField_CType(value_field); - if (!upb_Clone_MessageValue(&val, value_field_type, value_sub, arena)) { - return NULL; - } - if (!upb_Map_Set(cloned_map, key, val, arena)) { - return NULL; - } +static void upb_MtDecoder_ValidateEntryField(upb_MtDecoder* d, + const upb_MiniTableField* f, + uint32_t expected_num) { + const char* name = expected_num == 1 ? "key" : "val"; + const uint32_t f_number = upb_MiniTableField_Number(f); + if (f_number != expected_num) { + upb_MdDecoder_ErrorJmp(&d->base, + "map %s did not have expected number (%d vs %d)", + name, expected_num, f_number); } - return cloned_map; -} -static upb_Map* upb_Message_Map_DeepClone(const upb_Map* map, - const upb_MiniTable* mini_table, - const upb_MiniTableField* f, - upb_Message* clone, - upb_Arena* arena) { - // TODO: use a variant of upb_MiniTable_GetSubMessageTable() here. - const upb_MiniTable* map_entry_table = upb_MiniTableSub_Message( - mini_table->UPB_PRIVATE(subs)[f->UPB_PRIVATE(submsg_index)]); - UPB_ASSERT(map_entry_table); + if (!upb_MiniTableField_IsScalar(f)) { + upb_MdDecoder_ErrorJmp( + &d->base, "map %s cannot be repeated or map, or be in oneof", name); + } - const upb_MiniTableField* key_field = - &map_entry_table->UPB_PRIVATE(fields)[0]; - const upb_MiniTableField* value_field = - &map_entry_table->UPB_PRIVATE(fields)[1]; + uint32_t not_ok_types; + if (expected_num == 1) { + not_ok_types = (1 << kUpb_FieldType_Float) | (1 << kUpb_FieldType_Double) | + (1 << kUpb_FieldType_Message) | (1 << kUpb_FieldType_Group) | + (1 << kUpb_FieldType_Bytes) | (1 << kUpb_FieldType_Enum); + } else { + not_ok_types = 1 << kUpb_FieldType_Group; + } - upb_Map* cloned_map = upb_Map_DeepClone( - map, upb_MiniTableField_CType(key_field), - upb_MiniTableField_CType(value_field), map_entry_table, arena); - if (!cloned_map) { - return NULL; + if ((1 << upb_MiniTableField_Type(f)) & not_ok_types) { + upb_MdDecoder_ErrorJmp(&d->base, "map %s cannot have type %d", name, + (int)f->UPB_PRIVATE(descriptortype)); } - _upb_Message_SetNonExtensionField(clone, f, &cloned_map); - return cloned_map; } -upb_Array* upb_Array_DeepClone(const upb_Array* array, upb_CType value_type, - const upb_MiniTable* sub, upb_Arena* arena) { - const size_t size = array->UPB_PRIVATE(size); - const int lg2 = UPB_PRIVATE(_upb_CType_SizeLg2)(value_type); - upb_Array* cloned_array = UPB_PRIVATE(_upb_Array_New)(arena, size, lg2); - if (!cloned_array) { - return NULL; - } - if (!_upb_Array_ResizeUninitialized(cloned_array, size, arena)) { - return NULL; +static void upb_MtDecoder_ParseMap(upb_MtDecoder* d, const char* data, + size_t len) { + upb_MtDecoder_ParseMessage(d, data, len); + upb_MtDecoder_AssignHasbits(d); + + if (UPB_UNLIKELY(d->table->UPB_PRIVATE(field_count) != 2)) { + upb_MdDecoder_ErrorJmp(&d->base, "%hu fields in map", + d->table->UPB_PRIVATE(field_count)); + UPB_UNREACHABLE(); } - for (size_t i = 0; i < size; ++i) { - upb_MessageValue val = upb_Array_Get(array, i); - if (!upb_Clone_MessageValue(&val, value_type, sub, arena)) { - return false; + + upb_LayoutItem* end = UPB_PTRADD(d->vec.data, d->vec.size); + for (upb_LayoutItem* item = d->vec.data; item < end; item++) { + if (item->type == kUpb_LayoutItemType_OneofCase) { + upb_MdDecoder_ErrorJmp(&d->base, "Map entry cannot have oneof"); } - upb_Array_Set(cloned_array, i, val); } - return cloned_array; + + upb_MtDecoder_ValidateEntryField(d, &d->table->UPB_PRIVATE(fields)[0], 1); + upb_MtDecoder_ValidateEntryField(d, &d->table->UPB_PRIVATE(fields)[1], 2); + + // Map entries have a pre-determined layout, regardless of types. + // NOTE: sync with mini_table/message_internal.h. + const size_t kv_size = d->platform == kUpb_MiniTablePlatform_32Bit ? 8 : 16; + const size_t hasbit_size = 8; + d->fields[0].UPB_PRIVATE(offset) = hasbit_size; + d->fields[1].UPB_PRIVATE(offset) = hasbit_size + kv_size; + d->table->UPB_PRIVATE(size) = + UPB_ALIGN_UP(hasbit_size + kv_size + kv_size, 8); + + // Map entries have a special bit set to signal it's a map entry, used in + // upb_MiniTable_SetSubMessage() below. + d->table->UPB_PRIVATE(ext) |= kUpb_ExtMode_IsMapEntry; } -static bool upb_Message_Array_DeepClone(const upb_Array* array, - const upb_MiniTable* mini_table, - const upb_MiniTableField* field, - upb_Message* clone, upb_Arena* arena) { - UPB_PRIVATE(_upb_MiniTableField_CheckIsArray)(field); - upb_Array* cloned_array = upb_Array_DeepClone( - array, upb_MiniTableField_CType(field), - upb_MiniTableField_CType(field) == kUpb_CType_Message && - field->UPB_PRIVATE(submsg_index) != kUpb_NoSub - ? upb_MiniTable_GetSubMessageTable(mini_table, field) - : NULL, - arena); +static void upb_MtDecoder_ParseMessageSet(upb_MtDecoder* d, const char* data, + size_t len) { + if (len > 0) { + upb_MdDecoder_ErrorJmp(&d->base, "Invalid message set encode length: %zu", + len); + } - // Clear out upb_Array* due to parent memcpy. - _upb_Message_SetNonExtensionField(clone, field, &cloned_array); - return true; + upb_MiniTable* ret = d->table; + ret->UPB_PRIVATE(size) = 0; + ret->UPB_PRIVATE(field_count) = 0; + ret->UPB_PRIVATE(ext) = kUpb_ExtMode_IsMessageSet; + ret->UPB_PRIVATE(dense_below) = 0; + ret->UPB_PRIVATE(table_mask) = -1; + ret->UPB_PRIVATE(required_count) = 0; } -static bool upb_Clone_ExtensionValue( - const upb_MiniTableExtension* mini_table_ext, const upb_Extension* source, - upb_Extension* dest, upb_Arena* arena) { - dest->data = source->data; - return upb_Clone_MessageValue( - &dest->data, - upb_MiniTableField_CType(&mini_table_ext->UPB_PRIVATE(field)), - upb_MiniTableExtension_GetSubMessage(mini_table_ext), arena); +static upb_MiniTable* upb_MtDecoder_DoBuildMiniTableWithBuf( + upb_MtDecoder* decoder, const char* data, size_t len, void** buf, + size_t* buf_size) { + upb_MdDecoder_CheckOutOfMemory(&decoder->base, decoder->table); + + decoder->table->UPB_PRIVATE(size) = 0; + decoder->table->UPB_PRIVATE(field_count) = 0; + decoder->table->UPB_PRIVATE(ext) = kUpb_ExtMode_NonExtendable; + decoder->table->UPB_PRIVATE(dense_below) = 0; + decoder->table->UPB_PRIVATE(table_mask) = -1; + decoder->table->UPB_PRIVATE(required_count) = 0; + + // Strip off and verify the version tag. + if (!len--) goto done; + const char vers = *data++; + + switch (vers) { + case kUpb_EncodedVersion_MapV1: + upb_MtDecoder_ParseMap(decoder, data, len); + break; + + case kUpb_EncodedVersion_MessageV1: + upb_MtDecoder_ParseMessage(decoder, data, len); + upb_MtDecoder_AssignHasbits(decoder); + upb_MtDecoder_SortLayoutItems(decoder); + upb_MtDecoder_AssignOffsets(decoder); + break; + + case kUpb_EncodedVersion_MessageSetV1: + upb_MtDecoder_ParseMessageSet(decoder, data, len); + break; + + default: + upb_MdDecoder_ErrorJmp(&decoder->base, "Invalid message version: %c", + vers); + } + +done: + *buf = decoder->vec.data; + *buf_size = decoder->vec.capacity * sizeof(*decoder->vec.data); + return decoder->table; } -upb_Message* _upb_Message_Copy(upb_Message* dst, const upb_Message* src, - const upb_MiniTable* mini_table, - upb_Arena* arena) { - upb_StringView empty_string = upb_StringView_FromDataAndSize(NULL, 0); - // Only copy message area skipping upb_Message_Internal. - memcpy(dst, src, mini_table->UPB_PRIVATE(size)); - for (size_t i = 0; i < mini_table->UPB_PRIVATE(field_count); ++i) { - const upb_MiniTableField* field = &mini_table->UPB_PRIVATE(fields)[i]; - if (upb_MiniTableField_IsScalar(field)) { - switch (upb_MiniTableField_CType(field)) { - case kUpb_CType_Message: { - upb_TaggedMessagePtr tagged = - upb_Message_GetTaggedMessagePtr(src, field, NULL); - const upb_Message* sub_message = - UPB_PRIVATE(_upb_TaggedMessagePtr_GetMessage)(tagged); - if (sub_message != NULL) { - // If the message is currently in an unlinked, "empty" state we keep - // it that way, because we don't want to deal with decode options, - // decode status, or possible parse failure here. - bool is_empty = upb_TaggedMessagePtr_IsEmpty(tagged); - const upb_MiniTable* sub_message_table = - is_empty ? UPB_PRIVATE(_upb_MiniTable_Empty)() - : upb_MiniTable_GetSubMessageTable(mini_table, field); - upb_Message* dst_sub_message = - upb_Message_DeepClone(sub_message, sub_message_table, arena); - if (dst_sub_message == NULL) { - return NULL; - } - _upb_Message_SetTaggedMessagePtr( - dst, mini_table, field, - UPB_PRIVATE(_upb_TaggedMessagePtr_Pack)(dst_sub_message, - is_empty)); - } - } break; - case kUpb_CType_String: - case kUpb_CType_Bytes: { - upb_StringView str = upb_Message_GetString(src, field, empty_string); - if (str.size != 0) { - if (!upb_Message_SetString( - dst, field, upb_Clone_StringView(str, arena), arena)) { - return NULL; - } - } - } break; - default: - // Scalar, already copied. - break; - } - } else { - if (upb_MiniTableField_IsMap(field)) { - const upb_Map* map = upb_Message_GetMap(src, field); - if (map != NULL) { - if (!upb_Message_Map_DeepClone(map, mini_table, field, dst, arena)) { - return NULL; - } - } - } else { - const upb_Array* array = upb_Message_GetArray(src, field); - if (array != NULL) { - if (!upb_Message_Array_DeepClone(array, mini_table, field, dst, - arena)) { - return NULL; - } - } - } - } +static upb_MiniTable* upb_MtDecoder_BuildMiniTableWithBuf( + upb_MtDecoder* const decoder, const char* const data, const size_t len, + void** const buf, size_t* const buf_size) { + if (UPB_SETJMP(decoder->base.err) != 0) { + *buf = decoder->vec.data; + *buf_size = decoder->vec.capacity * sizeof(*decoder->vec.data); + return NULL; } - // Clone extensions. - size_t ext_count; - const upb_Extension* ext = UPB_PRIVATE(_upb_Message_Getexts)(src, &ext_count); - for (size_t i = 0; i < ext_count; ++i) { - const upb_Extension* msg_ext = &ext[i]; - const upb_MiniTableField* field = &msg_ext->ext->UPB_PRIVATE(field); - upb_Extension* dst_ext = - _upb_Message_GetOrCreateExtension(dst, msg_ext->ext, arena); - if (!dst_ext) return NULL; - if (upb_MiniTableField_IsScalar(field)) { - if (!upb_Clone_ExtensionValue(msg_ext->ext, msg_ext, dst_ext, arena)) { - return NULL; - } - } else { - upb_Array* msg_array = (upb_Array*)msg_ext->data.ptr; - UPB_ASSERT(msg_array); - upb_Array* cloned_array = upb_Array_DeepClone( - msg_array, upb_MiniTableField_CType(field), - upb_MiniTableExtension_GetSubMessage(msg_ext->ext), arena); - if (!cloned_array) { - return NULL; - } - dst_ext->data.ptr = (void*)cloned_array; + + return upb_MtDecoder_DoBuildMiniTableWithBuf(decoder, data, len, buf, + buf_size); +} + +upb_MiniTable* upb_MiniTable_BuildWithBuf(const char* data, size_t len, + upb_MiniTablePlatform platform, + upb_Arena* arena, void** buf, + size_t* buf_size, + upb_Status* status) { + upb_MtDecoder decoder = { + .base = {.status = status}, + .platform = platform, + .vec = + { + .data = *buf, + .capacity = *buf_size / sizeof(*decoder.vec.data), + .size = 0, + }, + .arena = arena, + .table = upb_Arena_Malloc(arena, sizeof(*decoder.table)), + }; + + return upb_MtDecoder_BuildMiniTableWithBuf(&decoder, data, len, buf, + buf_size); +} + +static const char* upb_MtDecoder_DoBuildMiniTableExtension( + upb_MtDecoder* decoder, const char* data, size_t len, + upb_MiniTableExtension* ext, const upb_MiniTable* extendee, + upb_MiniTableSub sub) { + // If the string is non-empty then it must begin with a version tag. + if (len) { + if (*data != kUpb_EncodedVersion_ExtensionV1) { + upb_MdDecoder_ErrorJmp(&decoder->base, "Invalid ext version: %c", *data); } + data++; + len--; } - // Clone unknowns. - size_t unknown_size = 0; - const char* ptr = upb_Message_GetUnknown(src, &unknown_size); - if (unknown_size != 0) { - UPB_ASSERT(ptr); - // Make a copy into destination arena. - if (!UPB_PRIVATE(_upb_Message_AddUnknown)(dst, ptr, unknown_size, arena)) { - return NULL; - } + uint16_t count = 0; + upb_SubCounts sub_counts = {0, 0}; + const char* ret = upb_MtDecoder_Parse(decoder, data, len, ext, sizeof(*ext), + &count, &sub_counts); + if (!ret || count != 1) return NULL; + + upb_MiniTableField* f = &ext->UPB_PRIVATE(field); + + f->UPB_PRIVATE(mode) |= kUpb_LabelFlags_IsExtension; + f->UPB_PRIVATE(offset) = 0; + f->presence = 0; + + if (extendee->UPB_PRIVATE(ext) & kUpb_ExtMode_IsMessageSet) { + // Extensions of MessageSet must be messages. + if (!upb_MiniTableField_IsSubMessage(f)) return NULL; + + // Extensions of MessageSet must be non-repeating. + if (upb_MiniTableField_IsArray(f)) return NULL; } - return dst; + + ext->UPB_PRIVATE(extendee) = extendee; + ext->UPB_PRIVATE(sub) = sub; + + return ret; } -bool upb_Message_DeepCopy(upb_Message* dst, const upb_Message* src, - const upb_MiniTable* mini_table, upb_Arena* arena) { - upb_Message_Clear(dst, mini_table); - return _upb_Message_Copy(dst, src, mini_table, arena) != NULL; +static const char* upb_MtDecoder_BuildMiniTableExtension( + upb_MtDecoder* const decoder, const char* const data, const size_t len, + upb_MiniTableExtension* const ext, const upb_MiniTable* const extendee, + const upb_MiniTableSub sub) { + if (UPB_SETJMP(decoder->base.err) != 0) return NULL; + return upb_MtDecoder_DoBuildMiniTableExtension(decoder, data, len, ext, + extendee, sub); } -// Deep clones a message using the provided target arena. -// -// Returns NULL on failure. -upb_Message* upb_Message_DeepClone(const upb_Message* msg, - const upb_MiniTable* m, upb_Arena* arena) { - upb_Message* clone = upb_Message_New(m, arena); - return _upb_Message_Copy(clone, msg, m, arena); +const char* _upb_MiniTableExtension_Init(const char* data, size_t len, + upb_MiniTableExtension* ext, + const upb_MiniTable* extendee, + upb_MiniTableSub sub, + upb_MiniTablePlatform platform, + upb_Status* status) { + upb_MtDecoder decoder = { + .base = {.status = status}, + .arena = NULL, + .table = NULL, + .platform = platform, + }; + + return upb_MtDecoder_BuildMiniTableExtension(&decoder, data, len, ext, + extendee, sub); } -// Performs a shallow copy. TODO: Extend to handle unknown fields. -void upb_Message_ShallowCopy(upb_Message* dst, const upb_Message* src, - const upb_MiniTable* m) { - memcpy(dst, src, m->UPB_PRIVATE(size)); +upb_MiniTableExtension* _upb_MiniTableExtension_Build( + const char* data, size_t len, const upb_MiniTable* extendee, + upb_MiniTableSub sub, upb_MiniTablePlatform platform, upb_Arena* arena, + upb_Status* status) { + upb_MiniTableExtension* ext = + upb_Arena_Malloc(arena, sizeof(upb_MiniTableExtension)); + if (UPB_UNLIKELY(!ext)) return NULL; + + const char* ptr = _upb_MiniTableExtension_Init(data, len, ext, extendee, sub, + platform, status); + if (UPB_UNLIKELY(!ptr)) return NULL; + + return ext; } -// Performs a shallow clone. Ignores unknown fields. -upb_Message* upb_Message_ShallowClone(const upb_Message* msg, - const upb_MiniTable* m, - upb_Arena* arena) { - upb_Message* clone = upb_Message_New(m, arena); - upb_Message_ShallowCopy(clone, msg, m); - return clone; +upb_MiniTable* _upb_MiniTable_Build(const char* data, size_t len, + upb_MiniTablePlatform platform, + upb_Arena* arena, upb_Status* status) { + void* buf = NULL; + size_t size = 0; + upb_MiniTable* ret = upb_MiniTable_BuildWithBuf(data, len, platform, arena, + &buf, &size, status); + free(buf); + return ret; } @@ -6854,5212 +6838,5892 @@ upb_Message* upb_Message_ShallowClone(const upb_Message* msg, // Must be last. -typedef struct { - upb_MdDecoder base; - upb_Arena* arena; - upb_MiniTableEnum* enum_table; - uint32_t enum_value_count; - uint32_t enum_data_count; - uint32_t enum_data_capacity; -} upb_MdEnumDecoder; +bool upb_MiniTable_SetSubMessage(upb_MiniTable* table, + upb_MiniTableField* field, + const upb_MiniTable* sub) { + UPB_ASSERT((uintptr_t)table->UPB_PRIVATE(fields) <= (uintptr_t)field && + (uintptr_t)field < (uintptr_t)(table->UPB_PRIVATE(fields) + + table->UPB_PRIVATE(field_count))); + UPB_ASSERT(sub); -static size_t upb_MiniTableEnum_Size(size_t count) { - return sizeof(upb_MiniTableEnum) + count * sizeof(uint32_t); -} + const bool sub_is_map = sub->UPB_PRIVATE(ext) & kUpb_ExtMode_IsMapEntry; -static upb_MiniTableEnum* _upb_MiniTable_AddEnumDataMember(upb_MdEnumDecoder* d, - uint32_t val) { - if (d->enum_data_count == d->enum_data_capacity) { - size_t old_sz = upb_MiniTableEnum_Size(d->enum_data_capacity); - d->enum_data_capacity = UPB_MAX(2, d->enum_data_capacity * 2); - size_t new_sz = upb_MiniTableEnum_Size(d->enum_data_capacity); - d->enum_table = upb_Arena_Realloc(d->arena, d->enum_table, old_sz, new_sz); - upb_MdDecoder_CheckOutOfMemory(&d->base, d->enum_table); - } - d->enum_table->UPB_PRIVATE(data)[d->enum_data_count++] = val; - return d->enum_table; -} + switch (field->UPB_PRIVATE(descriptortype)) { + case kUpb_FieldType_Message: + if (sub_is_map) { + const bool table_is_map = + table->UPB_PRIVATE(ext) & kUpb_ExtMode_IsMapEntry; + if (UPB_UNLIKELY(table_is_map)) return false; -static void upb_MiniTableEnum_BuildValue(upb_MdEnumDecoder* d, uint32_t val) { - upb_MiniTableEnum* table = d->enum_table; - d->enum_value_count++; - if (table->UPB_PRIVATE(value_count) || - (val > 512 && d->enum_value_count < val / 32)) { - if (table->UPB_PRIVATE(value_count) == 0) { - UPB_ASSERT(d->enum_data_count == table->UPB_PRIVATE(mask_limit) / 32); - } - table = _upb_MiniTable_AddEnumDataMember(d, val); - table->UPB_PRIVATE(value_count)++; - } else { - uint32_t new_mask_limit = ((val / 32) + 1) * 32; - while (table->UPB_PRIVATE(mask_limit) < new_mask_limit) { - table = _upb_MiniTable_AddEnumDataMember(d, 0); - table->UPB_PRIVATE(mask_limit) += 32; - } - table->UPB_PRIVATE(data)[val / 32] |= 1ULL << (val % 32); - } -} + field->UPB_PRIVATE(mode) = + (field->UPB_PRIVATE(mode) & ~kUpb_FieldMode_Mask) | + kUpb_FieldMode_Map; + } + break; -static upb_MiniTableEnum* upb_MtDecoder_DoBuildMiniTableEnum( - upb_MdEnumDecoder* d, const char* data, size_t len) { - // If the string is non-empty then it must begin with a version tag. - if (len) { - if (*data != kUpb_EncodedVersion_EnumV1) { - upb_MdDecoder_ErrorJmp(&d->base, "Invalid enum version: %c", *data); - } - data++; - len--; + case kUpb_FieldType_Group: + if (UPB_UNLIKELY(sub_is_map)) return false; + break; + + default: + return false; } - upb_MdDecoder_CheckOutOfMemory(&d->base, d->enum_table); + upb_MiniTableSub* table_sub = + (void*)&table->UPB_PRIVATE(subs)[field->UPB_PRIVATE(submsg_index)]; + // TODO: Add this assert back once YouTube is updated to not call + // this function repeatedly. + // UPB_ASSERT(UPB_PRIVATE(_upb_MiniTable_IsEmpty)(table_sub->submsg)); + *table_sub = upb_MiniTableSub_FromMessage(sub); + return true; +} - // Guarantee at least 64 bits of mask without checking mask size. - d->enum_table->UPB_PRIVATE(mask_limit) = 64; - d->enum_table = _upb_MiniTable_AddEnumDataMember(d, 0); - d->enum_table = _upb_MiniTable_AddEnumDataMember(d, 0); +bool upb_MiniTable_SetSubEnum(upb_MiniTable* table, upb_MiniTableField* field, + const upb_MiniTableEnum* sub) { + UPB_ASSERT((uintptr_t)table->UPB_PRIVATE(fields) <= (uintptr_t)field && + (uintptr_t)field < (uintptr_t)(table->UPB_PRIVATE(fields) + + table->UPB_PRIVATE(field_count))); + UPB_ASSERT(sub); - d->enum_table->UPB_PRIVATE(value_count) = 0; + upb_MiniTableSub* table_sub = + (void*)&table->UPB_PRIVATE(subs)[field->UPB_PRIVATE(submsg_index)]; + *table_sub = upb_MiniTableSub_FromEnum(sub); + return true; +} - const char* ptr = data; - uint32_t base = 0; +uint32_t upb_MiniTable_GetSubList(const upb_MiniTable* mt, + const upb_MiniTableField** subs) { + uint32_t msg_count = 0; + uint32_t enum_count = 0; - while (ptr < d->base.end) { - char ch = *ptr++; - if (ch <= kUpb_EncodedValue_MaxEnumMask) { - uint32_t mask = _upb_FromBase92(ch); - for (int i = 0; i < 5; i++, base++, mask >>= 1) { - if (mask & 1) upb_MiniTableEnum_BuildValue(d, base); - } - } else if (kUpb_EncodedValue_MinSkip <= ch && - ch <= kUpb_EncodedValue_MaxSkip) { - uint32_t skip; - ptr = upb_MdDecoder_DecodeBase92Varint(&d->base, ptr, ch, - kUpb_EncodedValue_MinSkip, - kUpb_EncodedValue_MaxSkip, &skip); - base += skip; - } else { - upb_MdDecoder_ErrorJmp(&d->base, "Unexpected character: %c", ch); + for (int i = 0; i < mt->UPB_PRIVATE(field_count); i++) { + const upb_MiniTableField* f = &mt->UPB_PRIVATE(fields)[i]; + if (upb_MiniTableField_CType(f) == kUpb_CType_Message) { + *subs = f; + ++subs; + msg_count++; } } - return d->enum_table; -} + for (int i = 0; i < mt->UPB_PRIVATE(field_count); i++) { + const upb_MiniTableField* f = &mt->UPB_PRIVATE(fields)[i]; + if (upb_MiniTableField_CType(f) == kUpb_CType_Enum) { + *subs = f; + ++subs; + enum_count++; + } + } -static upb_MiniTableEnum* upb_MtDecoder_BuildMiniTableEnum( - upb_MdEnumDecoder* const decoder, const char* const data, - size_t const len) { - if (UPB_SETJMP(decoder->base.err) != 0) return NULL; - return upb_MtDecoder_DoBuildMiniTableEnum(decoder, data, len); + return (msg_count << 16) | enum_count; } -upb_MiniTableEnum* upb_MiniDescriptor_BuildEnum(const char* data, size_t len, - upb_Arena* arena, - upb_Status* status) { - upb_MdEnumDecoder decoder = { - .base = - { - .end = UPB_PTRADD(data, len), - .status = status, - }, - .arena = arena, - .enum_table = upb_Arena_Malloc(arena, upb_MiniTableEnum_Size(2)), - .enum_value_count = 0, - .enum_data_count = 0, - .enum_data_capacity = 1, - }; +// The list of sub_tables and sub_enums must exactly match the number and order +// of sub-message fields and sub-enum fields given by upb_MiniTable_GetSubList() +// above. +bool upb_MiniTable_Link(upb_MiniTable* mt, const upb_MiniTable** sub_tables, + size_t sub_table_count, + const upb_MiniTableEnum** sub_enums, + size_t sub_enum_count) { + uint32_t msg_count = 0; + uint32_t enum_count = 0; - return upb_MtDecoder_BuildMiniTableEnum(&decoder, data, len); + for (int i = 0; i < mt->UPB_PRIVATE(field_count); i++) { + upb_MiniTableField* f = (upb_MiniTableField*)&mt->UPB_PRIVATE(fields)[i]; + if (upb_MiniTableField_CType(f) == kUpb_CType_Message) { + const upb_MiniTable* sub = sub_tables[msg_count++]; + if (msg_count > sub_table_count) return false; + if (sub != NULL) { + if (!upb_MiniTable_SetSubMessage(mt, f, sub)) return false; + } + } + } + + for (int i = 0; i < mt->UPB_PRIVATE(field_count); i++) { + upb_MiniTableField* f = (upb_MiniTableField*)&mt->UPB_PRIVATE(fields)[i]; + if (upb_MiniTableField_IsClosedEnum(f)) { + const upb_MiniTableEnum* sub = sub_enums[enum_count++]; + if (enum_count > sub_enum_count) return false; + if (sub != NULL) { + if (!upb_MiniTable_SetSubEnum(mt, f, sub)) return false; + } + } + } + + return true; } -#include +#include #include -#include +#include // Must be last. -// Note: we sort by this number when calculating layout order. -typedef enum { - kUpb_LayoutItemType_OneofCase, // Oneof case. - kUpb_LayoutItemType_OneofField, // Oneof field data. - kUpb_LayoutItemType_Field, // Non-oneof field data. - - kUpb_LayoutItemType_Max = kUpb_LayoutItemType_Field, -} upb_LayoutItemType; - -#define kUpb_LayoutItem_IndexSentinel ((uint16_t)-1) - -typedef struct { - // Index of the corresponding field. When this is a oneof field, the field's - // offset will be the index of the next field in a linked list. - uint16_t field_index; - uint16_t offset; - upb_FieldRep rep; - upb_LayoutItemType type; -} upb_LayoutItem; - -typedef struct { - upb_LayoutItem* data; - size_t size; - size_t capacity; -} upb_LayoutItemVector; +#define EXTREG_KEY_SIZE (sizeof(upb_MiniTable*) + sizeof(uint32_t)) -typedef struct { - upb_MdDecoder base; - upb_MiniTable* table; - upb_MiniTableField* fields; - upb_MiniTablePlatform platform; - upb_LayoutItemVector vec; +struct upb_ExtensionRegistry { upb_Arena* arena; -} upb_MtDecoder; - -// In each field's offset, we temporarily store a presence classifier: -enum PresenceClass { - kNoPresence = 0, - kHasbitPresence = 1, - kRequiredPresence = 2, - kOneofBase = 3, - // Negative values refer to a specific oneof with that number. Positive - // values >= kOneofBase indicate that this field is in a oneof, and specify - // the next field in this oneof's linked list. + upb_strtable exts; // Key is upb_MiniTable* concatenated with fieldnum. }; -static bool upb_MtDecoder_FieldIsPackable(upb_MiniTableField* field) { - return (field->UPB_PRIVATE(mode) & kUpb_FieldMode_Array) && - upb_FieldType_IsPackable(field->UPB_PRIVATE(descriptortype)); +static void extreg_key(char* buf, const upb_MiniTable* l, uint32_t fieldnum) { + memcpy(buf, &l, sizeof(l)); + memcpy(buf + sizeof(l), &fieldnum, sizeof(fieldnum)); } -typedef struct { - uint16_t submsg_count; - uint16_t subenum_count; -} upb_SubCounts; - -static void upb_MiniTable_SetTypeAndSub(upb_MiniTableField* field, - upb_FieldType type, - upb_SubCounts* sub_counts, - uint64_t msg_modifiers, - bool is_proto3_enum) { - if (is_proto3_enum) { - UPB_ASSERT(type == kUpb_FieldType_Enum); - type = kUpb_FieldType_Int32; - field->UPB_PRIVATE(mode) |= kUpb_LabelFlags_IsAlternate; - } else if (type == kUpb_FieldType_String && - !(msg_modifiers & kUpb_MessageModifier_ValidateUtf8)) { - type = kUpb_FieldType_Bytes; - field->UPB_PRIVATE(mode) |= kUpb_LabelFlags_IsAlternate; - } +upb_ExtensionRegistry* upb_ExtensionRegistry_New(upb_Arena* arena) { + upb_ExtensionRegistry* r = upb_Arena_Malloc(arena, sizeof(*r)); + if (!r) return NULL; + r->arena = arena; + if (!upb_strtable_init(&r->exts, 8, arena)) return NULL; + return r; +} - field->UPB_PRIVATE(descriptortype) = type; +UPB_API bool upb_ExtensionRegistry_Add(upb_ExtensionRegistry* r, + const upb_MiniTableExtension* e) { + char buf[EXTREG_KEY_SIZE]; + extreg_key(buf, e->UPB_PRIVATE(extendee), upb_MiniTableExtension_Number(e)); + if (upb_strtable_lookup2(&r->exts, buf, EXTREG_KEY_SIZE, NULL)) return false; + return upb_strtable_insert(&r->exts, buf, EXTREG_KEY_SIZE, + upb_value_constptr(e), r->arena); +} - if (upb_MtDecoder_FieldIsPackable(field) && - (msg_modifiers & kUpb_MessageModifier_DefaultIsPacked)) { - field->UPB_PRIVATE(mode) |= kUpb_LabelFlags_IsPacked; +bool upb_ExtensionRegistry_AddArray(upb_ExtensionRegistry* r, + const upb_MiniTableExtension** e, + size_t count) { + const upb_MiniTableExtension** start = e; + const upb_MiniTableExtension** end = UPB_PTRADD(e, count); + for (; e < end; e++) { + if (!upb_ExtensionRegistry_Add(r, *e)) goto failure; } + return true; - if (type == kUpb_FieldType_Message || type == kUpb_FieldType_Group) { - field->UPB_PRIVATE(submsg_index) = sub_counts->submsg_count++; - } else if (type == kUpb_FieldType_Enum) { - // We will need to update this later once we know the total number of - // submsg fields. - field->UPB_PRIVATE(submsg_index) = sub_counts->subenum_count++; - } else { - field->UPB_PRIVATE(submsg_index) = kUpb_NoSub; +failure: + // Back out the entries previously added. + for (end = e, e = start; e < end; e++) { + const upb_MiniTableExtension* ext = *e; + char buf[EXTREG_KEY_SIZE]; + extreg_key(buf, ext->UPB_PRIVATE(extendee), + upb_MiniTableExtension_Number(ext)); + upb_strtable_remove2(&r->exts, buf, EXTREG_KEY_SIZE, NULL); } + return false; } -static const char kUpb_EncodedToType[] = { - [kUpb_EncodedType_Double] = kUpb_FieldType_Double, - [kUpb_EncodedType_Float] = kUpb_FieldType_Float, - [kUpb_EncodedType_Int64] = kUpb_FieldType_Int64, - [kUpb_EncodedType_UInt64] = kUpb_FieldType_UInt64, - [kUpb_EncodedType_Int32] = kUpb_FieldType_Int32, - [kUpb_EncodedType_Fixed64] = kUpb_FieldType_Fixed64, - [kUpb_EncodedType_Fixed32] = kUpb_FieldType_Fixed32, - [kUpb_EncodedType_Bool] = kUpb_FieldType_Bool, - [kUpb_EncodedType_String] = kUpb_FieldType_String, - [kUpb_EncodedType_Group] = kUpb_FieldType_Group, - [kUpb_EncodedType_Message] = kUpb_FieldType_Message, - [kUpb_EncodedType_Bytes] = kUpb_FieldType_Bytes, - [kUpb_EncodedType_UInt32] = kUpb_FieldType_UInt32, - [kUpb_EncodedType_OpenEnum] = kUpb_FieldType_Enum, - [kUpb_EncodedType_SFixed32] = kUpb_FieldType_SFixed32, - [kUpb_EncodedType_SFixed64] = kUpb_FieldType_SFixed64, - [kUpb_EncodedType_SInt32] = kUpb_FieldType_SInt32, - [kUpb_EncodedType_SInt64] = kUpb_FieldType_SInt64, - [kUpb_EncodedType_ClosedEnum] = kUpb_FieldType_Enum, -}; - -static void upb_MiniTable_SetField(upb_MtDecoder* d, uint8_t ch, - upb_MiniTableField* field, - uint64_t msg_modifiers, - upb_SubCounts* sub_counts) { - static const char kUpb_EncodedToFieldRep[] = { - [kUpb_EncodedType_Double] = kUpb_FieldRep_8Byte, - [kUpb_EncodedType_Float] = kUpb_FieldRep_4Byte, - [kUpb_EncodedType_Int64] = kUpb_FieldRep_8Byte, - [kUpb_EncodedType_UInt64] = kUpb_FieldRep_8Byte, - [kUpb_EncodedType_Int32] = kUpb_FieldRep_4Byte, - [kUpb_EncodedType_Fixed64] = kUpb_FieldRep_8Byte, - [kUpb_EncodedType_Fixed32] = kUpb_FieldRep_4Byte, - [kUpb_EncodedType_Bool] = kUpb_FieldRep_1Byte, - [kUpb_EncodedType_String] = kUpb_FieldRep_StringView, - [kUpb_EncodedType_Bytes] = kUpb_FieldRep_StringView, - [kUpb_EncodedType_UInt32] = kUpb_FieldRep_4Byte, - [kUpb_EncodedType_OpenEnum] = kUpb_FieldRep_4Byte, - [kUpb_EncodedType_SFixed32] = kUpb_FieldRep_4Byte, - [kUpb_EncodedType_SFixed64] = kUpb_FieldRep_8Byte, - [kUpb_EncodedType_SInt32] = kUpb_FieldRep_4Byte, - [kUpb_EncodedType_SInt64] = kUpb_FieldRep_8Byte, - [kUpb_EncodedType_ClosedEnum] = kUpb_FieldRep_4Byte, - }; - - char pointer_rep = d->platform == kUpb_MiniTablePlatform_32Bit - ? kUpb_FieldRep_4Byte - : kUpb_FieldRep_8Byte; - - int8_t type = _upb_FromBase92(ch); - if (ch >= _upb_ToBase92(kUpb_EncodedType_RepeatedBase)) { - type -= kUpb_EncodedType_RepeatedBase; - field->UPB_PRIVATE(mode) = kUpb_FieldMode_Array; - field->UPB_PRIVATE(mode) |= pointer_rep << kUpb_FieldRep_Shift; - field->UPB_PRIVATE(offset) = kNoPresence; +const upb_MiniTableExtension* upb_ExtensionRegistry_Lookup( + const upb_ExtensionRegistry* r, const upb_MiniTable* t, uint32_t num) { + char buf[EXTREG_KEY_SIZE]; + upb_value v; + extreg_key(buf, t, num); + if (upb_strtable_lookup2(&r->exts, buf, EXTREG_KEY_SIZE, &v)) { + return upb_value_getconstptr(v); } else { - field->UPB_PRIVATE(mode) = kUpb_FieldMode_Scalar; - field->UPB_PRIVATE(offset) = kHasbitPresence; - if (type == kUpb_EncodedType_Group || type == kUpb_EncodedType_Message) { - field->UPB_PRIVATE(mode) |= pointer_rep << kUpb_FieldRep_Shift; - } else if ((unsigned long)type >= sizeof(kUpb_EncodedToFieldRep)) { - upb_MdDecoder_ErrorJmp(&d->base, "Invalid field type: %d", (int)type); - } else { - field->UPB_PRIVATE(mode) |= kUpb_EncodedToFieldRep[type] - << kUpb_FieldRep_Shift; - } - } - if ((unsigned long)type >= sizeof(kUpb_EncodedToType)) { - upb_MdDecoder_ErrorJmp(&d->base, "Invalid field type: %d", (int)type); + return NULL; } - upb_MiniTable_SetTypeAndSub(field, kUpb_EncodedToType[type], sub_counts, - msg_modifiers, type == kUpb_EncodedType_OpenEnum); } -static void upb_MtDecoder_ModifyField(upb_MtDecoder* d, - uint32_t message_modifiers, - uint32_t field_modifiers, - upb_MiniTableField* field) { - if (field_modifiers & kUpb_EncodedFieldModifier_FlipPacked) { - if (!upb_MtDecoder_FieldIsPackable(field)) { - upb_MdDecoder_ErrorJmp(&d->base, - "Cannot flip packed on unpackable field %" PRIu32, - upb_MiniTableField_Number(field)); - } - field->UPB_PRIVATE(mode) ^= kUpb_LabelFlags_IsPacked; - } - if (field_modifiers & kUpb_EncodedFieldModifier_FlipValidateUtf8) { - if (field->UPB_PRIVATE(descriptortype) != kUpb_FieldType_Bytes || - !(field->UPB_PRIVATE(mode) & kUpb_LabelFlags_IsAlternate)) { - upb_MdDecoder_ErrorJmp(&d->base, - "Cannot flip ValidateUtf8 on field %" PRIu32 - ", type=%d, mode=%d", - upb_MiniTableField_Number(field), - (int)field->UPB_PRIVATE(descriptortype), - (int)field->UPB_PRIVATE(mode)); - } - field->UPB_PRIVATE(descriptortype) = kUpb_FieldType_String; - field->UPB_PRIVATE(mode) &= ~kUpb_LabelFlags_IsAlternate; - } +#include +#include +#include - bool singular = field_modifiers & kUpb_EncodedFieldModifier_IsProto3Singular; - bool required = field_modifiers & kUpb_EncodedFieldModifier_IsRequired; - // Validate. - if ((singular || required) && field->UPB_PRIVATE(offset) != kHasbitPresence) { - upb_MdDecoder_ErrorJmp(&d->base, - "Invalid modifier(s) for repeated field %" PRIu32, - upb_MiniTableField_Number(field)); - } - if (singular && required) { - upb_MdDecoder_ErrorJmp( - &d->base, "Field %" PRIu32 " cannot be both singular and required", - upb_MiniTableField_Number(field)); +// Must be last. + +const upb_MiniTableField* upb_MiniTable_FindFieldByNumber( + const upb_MiniTable* m, uint32_t number) { + const size_t i = ((size_t)number) - 1; // 0 wraps to SIZE_MAX + + // Ideal case: index into dense fields + if (i < m->UPB_PRIVATE(dense_below)) { + UPB_ASSERT(m->UPB_PRIVATE(fields)[i].UPB_PRIVATE(number) == number); + return &m->UPB_PRIVATE(fields)[i]; } - if (singular) field->UPB_PRIVATE(offset) = kNoPresence; - if (required) { - field->UPB_PRIVATE(offset) = kRequiredPresence; + // Slow case: binary search + int lo = m->UPB_PRIVATE(dense_below); + int hi = m->UPB_PRIVATE(field_count) - 1; + while (lo <= hi) { + int mid = (lo + hi) / 2; + uint32_t num = m->UPB_PRIVATE(fields)[mid].UPB_PRIVATE(number); + if (num < number) { + lo = mid + 1; + continue; + } + if (num > number) { + hi = mid - 1; + continue; + } + return &m->UPB_PRIVATE(fields)[mid]; } + return NULL; } -static void upb_MtDecoder_PushItem(upb_MtDecoder* d, upb_LayoutItem item) { - if (d->vec.size == d->vec.capacity) { - size_t new_cap = UPB_MAX(8, d->vec.size * 2); - d->vec.data = realloc(d->vec.data, new_cap * sizeof(*d->vec.data)); - upb_MdDecoder_CheckOutOfMemory(&d->base, d->vec.data); - d->vec.capacity = new_cap; +const upb_MiniTableField* upb_MiniTable_GetOneof(const upb_MiniTable* m, + const upb_MiniTableField* f) { + if (UPB_UNLIKELY(!upb_MiniTableField_IsInOneof(f))) { + return NULL; } - d->vec.data[d->vec.size++] = item; + const upb_MiniTableField* ptr = &m->UPB_PRIVATE(fields)[0]; + const upb_MiniTableField* end = + &m->UPB_PRIVATE(fields)[m->UPB_PRIVATE(field_count)]; + for (; ptr < end; ptr++) { + if (ptr->presence == (*f).presence) { + return ptr; + } + } + return NULL; } -static void upb_MtDecoder_PushOneof(upb_MtDecoder* d, upb_LayoutItem item) { - if (item.field_index == kUpb_LayoutItem_IndexSentinel) { - upb_MdDecoder_ErrorJmp(&d->base, "Empty oneof"); +bool upb_MiniTable_NextOneofField(const upb_MiniTable* m, + const upb_MiniTableField** f) { + const upb_MiniTableField* ptr = *f; + const upb_MiniTableField* end = + &m->UPB_PRIVATE(fields)[m->UPB_PRIVATE(field_count)]; + while (++ptr < end) { + if (ptr->presence == (*f)->presence) { + *f = ptr; + return true; + } } - item.field_index -= kOneofBase; + return false; +} - // Push oneof data. - item.type = kUpb_LayoutItemType_OneofField; - upb_MtDecoder_PushItem(d, item); - // Push oneof case. - item.rep = kUpb_FieldRep_4Byte; // Field Number. - item.type = kUpb_LayoutItemType_OneofCase; - upb_MtDecoder_PushItem(d, item); -} +#include +#include -size_t upb_MtDecoder_SizeOfRep(upb_FieldRep rep, - upb_MiniTablePlatform platform) { - static const uint8_t kRepToSize32[] = { - [kUpb_FieldRep_1Byte] = 1, - [kUpb_FieldRep_4Byte] = 4, - [kUpb_FieldRep_StringView] = 8, - [kUpb_FieldRep_8Byte] = 8, - }; - static const uint8_t kRepToSize64[] = { - [kUpb_FieldRep_1Byte] = 1, - [kUpb_FieldRep_4Byte] = 4, - [kUpb_FieldRep_StringView] = 16, - [kUpb_FieldRep_8Byte] = 8, - }; - UPB_ASSERT(sizeof(upb_StringView) == - UPB_SIZE(kRepToSize32, kRepToSize64)[kUpb_FieldRep_StringView]); - return platform == kUpb_MiniTablePlatform_32Bit ? kRepToSize32[rep] - : kRepToSize64[rep]; -} -size_t upb_MtDecoder_AlignOfRep(upb_FieldRep rep, - upb_MiniTablePlatform platform) { - static const uint8_t kRepToAlign32[] = { - [kUpb_FieldRep_1Byte] = 1, - [kUpb_FieldRep_4Byte] = 4, - [kUpb_FieldRep_StringView] = 4, - [kUpb_FieldRep_8Byte] = 8, - }; - static const uint8_t kRepToAlign64[] = { - [kUpb_FieldRep_1Byte] = 1, - [kUpb_FieldRep_4Byte] = 4, - [kUpb_FieldRep_StringView] = 8, - [kUpb_FieldRep_8Byte] = 8, - }; - UPB_ASSERT(UPB_ALIGN_OF(upb_StringView) == - UPB_SIZE(kRepToAlign32, kRepToAlign64)[kUpb_FieldRep_StringView]); - return platform == kUpb_MiniTablePlatform_32Bit ? kRepToAlign32[rep] - : kRepToAlign64[rep]; -} +// Must be last. -static const char* upb_MtDecoder_DecodeOneofField(upb_MtDecoder* d, - const char* ptr, - char first_ch, - upb_LayoutItem* item) { - uint32_t field_num; - ptr = upb_MdDecoder_DecodeBase92Varint( - &d->base, ptr, first_ch, kUpb_EncodedValue_MinOneofField, - kUpb_EncodedValue_MaxOneofField, &field_num); - upb_MiniTableField* f = - (void*)upb_MiniTable_FindFieldByNumber(d->table, field_num); +// Checks if source and target mini table fields are identical. +// +// If the field is a sub message and sub messages are identical we record +// the association in table. +// +// Hashing the source sub message mini table and it's equivalent in the table +// stops recursing when a cycle is detected and instead just checks if the +// destination table is equal. +static upb_MiniTableEquals_Status upb_deep_check(const upb_MiniTable* src, + const upb_MiniTable* dst, + upb_inttable* table, + upb_Arena** arena) { + if (src->UPB_PRIVATE(field_count) != dst->UPB_PRIVATE(field_count)) + return kUpb_MiniTableEquals_NotEqual; + bool marked_src = false; + for (int i = 0; i < upb_MiniTable_FieldCount(src); i++) { + const upb_MiniTableField* src_field = upb_MiniTable_GetFieldByIndex(src, i); + const upb_MiniTableField* dst_field = upb_MiniTable_FindFieldByNumber( + dst, upb_MiniTableField_Number(src_field)); - if (!f) { - upb_MdDecoder_ErrorJmp(&d->base, - "Couldn't add field number %" PRIu32 - " to oneof, no such field number.", - field_num); - } - if (f->UPB_PRIVATE(offset) != kHasbitPresence) { - upb_MdDecoder_ErrorJmp( - &d->base, - "Cannot add repeated, required, or singular field %" PRIu32 - " to oneof.", - field_num); - } + if (upb_MiniTableField_CType(src_field) != + upb_MiniTableField_CType(dst_field)) + return false; + if (src_field->UPB_PRIVATE(mode) != dst_field->UPB_PRIVATE(mode)) + return false; + if (src_field->UPB_PRIVATE(offset) != dst_field->UPB_PRIVATE(offset)) + return false; + if (src_field->presence != dst_field->presence) return false; + if (src_field->UPB_PRIVATE(submsg_index) != + dst_field->UPB_PRIVATE(submsg_index)) + return kUpb_MiniTableEquals_NotEqual; - // Oneof storage must be large enough to accommodate the largest member. - int rep = f->UPB_PRIVATE(mode) >> kUpb_FieldRep_Shift; - if (upb_MtDecoder_SizeOfRep(rep, d->platform) > - upb_MtDecoder_SizeOfRep(item->rep, d->platform)) { - item->rep = rep; - } - // Prepend this field to the linked list. - f->UPB_PRIVATE(offset) = item->field_index; - item->field_index = (f - d->fields) + kOneofBase; - return ptr; -} + // Go no further if we are only checking for compatibility. + if (!table) continue; -static const char* upb_MtDecoder_DecodeOneofs(upb_MtDecoder* d, - const char* ptr) { - upb_LayoutItem item = {.rep = 0, - .field_index = kUpb_LayoutItem_IndexSentinel}; - while (ptr < d->base.end) { - char ch = *ptr++; - if (ch == kUpb_EncodedValue_FieldSeparator) { - // Field separator, no action needed. - } else if (ch == kUpb_EncodedValue_OneofSeparator) { - // End of oneof. - upb_MtDecoder_PushOneof(d, item); - item.field_index = kUpb_LayoutItem_IndexSentinel; // Move to next oneof. - } else { - ptr = upb_MtDecoder_DecodeOneofField(d, ptr, ch, &item); + if (upb_MiniTableField_CType(src_field) == kUpb_CType_Message) { + if (!*arena) { + *arena = upb_Arena_New(); + if (!upb_inttable_init(table, *arena)) { + return kUpb_MiniTableEquals_OutOfMemory; + } + } + if (!marked_src) { + marked_src = true; + upb_value val; + val.val = (uint64_t)dst; + if (!upb_inttable_insert(table, (uintptr_t)src, val, *arena)) { + return kUpb_MiniTableEquals_OutOfMemory; + } + } + const upb_MiniTable* sub_src = + upb_MiniTable_GetSubMessageTable(src, src_field); + const upb_MiniTable* sub_dst = + upb_MiniTable_GetSubMessageTable(dst, dst_field); + if (sub_src != NULL) { + upb_value cmp; + if (upb_inttable_lookup(table, (uintptr_t)sub_src, &cmp)) { + // We already compared this src before. Check if same dst. + if (cmp.val != (uint64_t)sub_dst) { + return kUpb_MiniTableEquals_NotEqual; + } + } else { + // Recurse if not already visited. + upb_MiniTableEquals_Status s = + upb_deep_check(sub_src, sub_dst, table, arena); + if (s != kUpb_MiniTableEquals_Equal) { + return s; + } + } + } } } - - // Push final oneof. - upb_MtDecoder_PushOneof(d, item); - return ptr; + return kUpb_MiniTableEquals_Equal; } -static const char* upb_MtDecoder_ParseModifier(upb_MtDecoder* d, - const char* ptr, char first_ch, - upb_MiniTableField* last_field, - uint64_t* msg_modifiers) { - uint32_t mod; - ptr = upb_MdDecoder_DecodeBase92Varint(&d->base, ptr, first_ch, - kUpb_EncodedValue_MinModifier, - kUpb_EncodedValue_MaxModifier, &mod); - if (last_field) { - upb_MtDecoder_ModifyField(d, *msg_modifiers, mod, last_field); - } else { - if (!d->table) { - upb_MdDecoder_ErrorJmp(&d->base, - "Extensions cannot have message modifiers"); - } - *msg_modifiers = mod; - } - - return ptr; +bool upb_MiniTable_Compatible(const upb_MiniTable* src, + const upb_MiniTable* dst) { + return upb_deep_check(src, dst, NULL, NULL); } -static void upb_MtDecoder_AllocateSubs(upb_MtDecoder* d, - upb_SubCounts sub_counts) { - uint32_t total_count = sub_counts.submsg_count + sub_counts.subenum_count; - size_t subs_bytes = sizeof(*d->table->UPB_PRIVATE(subs)) * total_count; - upb_MiniTableSub* subs = upb_Arena_Malloc(d->arena, subs_bytes); - upb_MdDecoder_CheckOutOfMemory(&d->base, subs); - uint32_t i = 0; - for (; i < sub_counts.submsg_count; i++) { - subs[i].UPB_PRIVATE(submsg) = UPB_PRIVATE(_upb_MiniTable_Empty)(); - } - if (sub_counts.subenum_count) { - upb_MiniTableField* f = d->fields; - upb_MiniTableField* end_f = f + d->table->UPB_PRIVATE(field_count); - for (; f < end_f; f++) { - if (f->UPB_PRIVATE(descriptortype) == kUpb_FieldType_Enum) { - f->UPB_PRIVATE(submsg_index) += sub_counts.submsg_count; - } - } - for (; i < sub_counts.submsg_count + sub_counts.subenum_count; i++) { - subs[i].UPB_PRIVATE(subenum) = NULL; - } +upb_MiniTableEquals_Status upb_MiniTable_Equals(const upb_MiniTable* src, + const upb_MiniTable* dst) { + // Arena allocated on demand for hash table. + upb_Arena* arena = NULL; + // Table to keep track of visited mini tables to guard against cycles. + upb_inttable table; + upb_MiniTableEquals_Status status = upb_deep_check(src, dst, &table, &arena); + if (arena) { + upb_Arena_Free(arena); } - d->table->UPB_PRIVATE(subs) = subs; + return status; } -static const char* upb_MtDecoder_Parse(upb_MtDecoder* d, const char* ptr, - size_t len, void* fields, - size_t field_size, uint16_t* field_count, - upb_SubCounts* sub_counts) { - uint64_t msg_modifiers = 0; - uint32_t last_field_number = 0; - upb_MiniTableField* last_field = NULL; - bool need_dense_below = d->table != NULL; - d->base.end = UPB_PTRADD(ptr, len); +#include +#include +#include +#include +#include - while (ptr < d->base.end) { - char ch = *ptr++; - if (ch <= kUpb_EncodedValue_MaxField) { - if (!d->table && last_field) { - // For extensions, consume only a single field and then return. - return --ptr; - } - upb_MiniTableField* field = fields; - *field_count += 1; - fields = (char*)fields + field_size; - field->UPB_PRIVATE(number) = ++last_field_number; - last_field = field; - upb_MiniTable_SetField(d, ch, field, msg_modifiers, sub_counts); - } else if (kUpb_EncodedValue_MinModifier <= ch && - ch <= kUpb_EncodedValue_MaxModifier) { - ptr = upb_MtDecoder_ParseModifier(d, ptr, ch, last_field, &msg_modifiers); - if (msg_modifiers & kUpb_MessageModifier_IsExtendable) { - d->table->UPB_PRIVATE(ext) |= kUpb_ExtMode_Extendable; - } - } else if (ch == kUpb_EncodedValue_End) { - if (!d->table) { - upb_MdDecoder_ErrorJmp(&d->base, "Extensions cannot have oneofs."); - } - ptr = upb_MtDecoder_DecodeOneofs(d, ptr); - } else if (kUpb_EncodedValue_MinSkip <= ch && - ch <= kUpb_EncodedValue_MaxSkip) { - if (need_dense_below) { - d->table->UPB_PRIVATE(dense_below) = d->table->UPB_PRIVATE(field_count); - need_dense_below = false; - } - uint32_t skip; - ptr = upb_MdDecoder_DecodeBase92Varint(&d->base, ptr, ch, - kUpb_EncodedValue_MinSkip, - kUpb_EncodedValue_MaxSkip, &skip); - last_field_number += skip; - last_field_number--; // Next field seen will increment. - } else { - upb_MdDecoder_ErrorJmp(&d->base, "Invalid char: %c", ch); - } - } - if (need_dense_below) { - d->table->UPB_PRIVATE(dense_below) = d->table->UPB_PRIVATE(field_count); - } +// Must be last. - return ptr; -} +// A few fake field types for our tables. +enum { + kUpb_FakeFieldType_FieldNotFound = 0, + kUpb_FakeFieldType_MessageSetItem = 19, +}; -static void upb_MtDecoder_ParseMessage(upb_MtDecoder* d, const char* data, - size_t len) { - // Buffer length is an upper bound on the number of fields. We will return - // what we don't use. - d->fields = upb_Arena_Malloc(d->arena, sizeof(*d->fields) * len); - upb_MdDecoder_CheckOutOfMemory(&d->base, d->fields); +// DecodeOp: an action to be performed for a wire-type/field-type combination. +enum { + // Special ops: we don't write data to regular fields for these. + kUpb_DecodeOp_UnknownField = -1, + kUpb_DecodeOp_MessageSetItem = -2, - upb_SubCounts sub_counts = {0, 0}; - d->table->UPB_PRIVATE(field_count) = 0; - d->table->UPB_PRIVATE(fields) = d->fields; - upb_MtDecoder_Parse(d, data, len, d->fields, sizeof(*d->fields), - &d->table->UPB_PRIVATE(field_count), &sub_counts); + // Scalar-only ops. + kUpb_DecodeOp_Scalar1Byte = 0, + kUpb_DecodeOp_Scalar4Byte = 2, + kUpb_DecodeOp_Scalar8Byte = 3, + kUpb_DecodeOp_Enum = 1, - upb_Arena_ShrinkLast(d->arena, d->fields, sizeof(*d->fields) * len, - sizeof(*d->fields) * d->table->UPB_PRIVATE(field_count)); - d->table->UPB_PRIVATE(fields) = d->fields; - upb_MtDecoder_AllocateSubs(d, sub_counts); -} + // Scalar/repeated ops. + kUpb_DecodeOp_String = 4, + kUpb_DecodeOp_Bytes = 5, + kUpb_DecodeOp_SubMessage = 6, -int upb_MtDecoder_CompareFields(const void* _a, const void* _b) { - const upb_LayoutItem* a = _a; - const upb_LayoutItem* b = _b; - // Currently we just sort by: - // 1. rep (smallest fields first) - // 2. type (oneof cases first) - // 2. field_index (smallest numbers first) - // The main goal of this is to reduce space lost to padding. - // Later we may have more subtle reasons to prefer a different ordering. - const int rep_bits = upb_Log2Ceiling(kUpb_FieldRep_Max); - const int type_bits = upb_Log2Ceiling(kUpb_LayoutItemType_Max); - const int idx_bits = (sizeof(a->field_index) * 8); - UPB_ASSERT(idx_bits + rep_bits + type_bits < 32); -#define UPB_COMBINE(rep, ty, idx) (((rep << type_bits) | ty) << idx_bits) | idx - uint32_t a_packed = UPB_COMBINE(a->rep, a->type, a->field_index); - uint32_t b_packed = UPB_COMBINE(b->rep, b->type, b->field_index); - UPB_ASSERT(a_packed != b_packed); -#undef UPB_COMBINE - return a_packed < b_packed ? -1 : 1; -} + // Repeated-only ops (also see macros below). + kUpb_DecodeOp_PackedEnum = 13, +}; -static bool upb_MtDecoder_SortLayoutItems(upb_MtDecoder* d) { - // Add items for all non-oneof fields (oneofs were already added). - int n = d->table->UPB_PRIVATE(field_count); - for (int i = 0; i < n; i++) { - upb_MiniTableField* f = &d->fields[i]; - if (f->UPB_PRIVATE(offset) >= kOneofBase) continue; - upb_LayoutItem item = {.field_index = i, - .rep = f->UPB_PRIVATE(mode) >> kUpb_FieldRep_Shift, - .type = kUpb_LayoutItemType_Field}; - upb_MtDecoder_PushItem(d, item); - } +// For packed fields it is helpful to be able to recover the lg2 of the data +// size from the op. +#define OP_FIXPCK_LG2(n) (n + 5) /* n in [2, 3] => op in [7, 8] */ +#define OP_VARPCK_LG2(n) (n + 9) /* n in [0, 2, 3] => op in [9, 11, 12] */ - if (d->vec.size) { - qsort(d->vec.data, d->vec.size, sizeof(*d->vec.data), - upb_MtDecoder_CompareFields); - } +typedef union { + bool bool_val; + uint32_t uint32_val; + uint64_t uint64_val; + uint32_t size; +} wireval; - return true; +// Ideally these two functions should take the owning MiniTable pointer as a +// first argument, then we could just put them in mini_table/message.h as nice +// clean getters. But we don't have that so instead we gotta write these +// Frankenfunctions that take an array of subtables. +// TODO: Move these to mini_table/ anyway since there are other places +// that could use them. + +// Returns the MiniTable corresponding to a given MiniTableField +// from an array of MiniTableSubs. +static const upb_MiniTable* _upb_MiniTableSubs_MessageByField( + const upb_MiniTableSub* subs, const upb_MiniTableField* field) { + return upb_MiniTableSub_Message(subs[field->UPB_PRIVATE(submsg_index)]); } -static size_t upb_MiniTable_DivideRoundUp(size_t n, size_t d) { - return (n + d - 1) / d; +// Returns the MiniTableEnum corresponding to a given MiniTableField +// from an array of MiniTableSub. +static const upb_MiniTableEnum* _upb_MiniTableSubs_EnumByField( + const upb_MiniTableSub* subs, const upb_MiniTableField* field) { + return upb_MiniTableSub_Enum(subs[field->UPB_PRIVATE(submsg_index)]); } -static void upb_MtDecoder_AssignHasbits(upb_MtDecoder* d) { - upb_MiniTable* ret = d->table; - int n = ret->UPB_PRIVATE(field_count); - int last_hasbit = 0; // 0 cannot be used. +static const char* _upb_Decoder_DecodeMessage(upb_Decoder* d, const char* ptr, + upb_Message* msg, + const upb_MiniTable* layout); - // First assign required fields, which must have the lowest hasbits. - for (int i = 0; i < n; i++) { - upb_MiniTableField* field = - (upb_MiniTableField*)&ret->UPB_PRIVATE(fields)[i]; - if (field->UPB_PRIVATE(offset) == kRequiredPresence) { - field->presence = ++last_hasbit; - } else if (field->UPB_PRIVATE(offset) == kNoPresence) { - field->presence = 0; - } - } - if (last_hasbit > 63) { - upb_MdDecoder_ErrorJmp(&d->base, "Too many required fields"); - } +UPB_NORETURN static void* _upb_Decoder_ErrorJmp(upb_Decoder* d, + upb_DecodeStatus status) { + UPB_ASSERT(status != kUpb_DecodeStatus_Ok); + d->status = status; + UPB_LONGJMP(d->err, 1); +} - ret->UPB_PRIVATE(required_count) = last_hasbit; +const char* _upb_FastDecoder_ErrorJmp(upb_Decoder* d, int status) { + UPB_ASSERT(status != kUpb_DecodeStatus_Ok); + d->status = status; + UPB_LONGJMP(d->err, 1); + return NULL; +} - // Next assign non-required hasbit fields. - for (int i = 0; i < n; i++) { - upb_MiniTableField* field = - (upb_MiniTableField*)&ret->UPB_PRIVATE(fields)[i]; - if (field->UPB_PRIVATE(offset) == kHasbitPresence) { - field->presence = ++last_hasbit; - } +static void _upb_Decoder_VerifyUtf8(upb_Decoder* d, const char* buf, int len) { + if (!_upb_Decoder_VerifyUtf8Inline(buf, len)) { + _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_BadUtf8); } - - ret->UPB_PRIVATE(size) = - last_hasbit ? upb_MiniTable_DivideRoundUp(last_hasbit + 1, 8) : 0; } -size_t upb_MtDecoder_Place(upb_MtDecoder* d, upb_FieldRep rep) { - size_t size = upb_MtDecoder_SizeOfRep(rep, d->platform); - size_t align = upb_MtDecoder_AlignOfRep(rep, d->platform); - size_t ret = UPB_ALIGN_UP(d->table->UPB_PRIVATE(size), align); - static const size_t max = UINT16_MAX; - size_t new_size = ret + size; - if (new_size > max) { - upb_MdDecoder_ErrorJmp( - &d->base, "Message size exceeded maximum size of %zu bytes", max); +static bool _upb_Decoder_Reserve(upb_Decoder* d, upb_Array* arr, size_t elem) { + bool need_realloc = + arr->UPB_PRIVATE(capacity) - arr->UPB_PRIVATE(size) < elem; + if (need_realloc && !UPB_PRIVATE(_upb_Array_Realloc)( + arr, arr->UPB_PRIVATE(size) + elem, &d->arena)) { + _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_OutOfMemory); } - d->table->UPB_PRIVATE(size) = new_size; - return ret; + return need_realloc; } -static void upb_MtDecoder_AssignOffsets(upb_MtDecoder* d) { - upb_LayoutItem* end = UPB_PTRADD(d->vec.data, d->vec.size); +typedef struct { + const char* ptr; + uint64_t val; +} _upb_DecodeLongVarintReturn; - // Compute offsets. - for (upb_LayoutItem* item = d->vec.data; item < end; item++) { - item->offset = upb_MtDecoder_Place(d, item->rep); +UPB_NOINLINE +static _upb_DecodeLongVarintReturn _upb_Decoder_DecodeLongVarint( + const char* ptr, uint64_t val) { + _upb_DecodeLongVarintReturn ret = {NULL, 0}; + uint64_t byte; + int i; + for (i = 1; i < 10; i++) { + byte = (uint8_t)ptr[i]; + val += (byte - 1) << (i * 7); + if (!(byte & 0x80)) { + ret.ptr = ptr + i + 1; + ret.val = val; + return ret; + } } + return ret; +} - // Assign oneof case offsets. We must do these first, since assigning - // actual offsets will overwrite the links of the linked list. - for (upb_LayoutItem* item = d->vec.data; item < end; item++) { - if (item->type != kUpb_LayoutItemType_OneofCase) continue; - upb_MiniTableField* f = &d->fields[item->field_index]; - while (true) { - f->presence = ~item->offset; - if (f->UPB_PRIVATE(offset) == kUpb_LayoutItem_IndexSentinel) break; - UPB_ASSERT(f->UPB_PRIVATE(offset) - kOneofBase < - d->table->UPB_PRIVATE(field_count)); - f = &d->fields[f->UPB_PRIVATE(offset) - kOneofBase]; - } +UPB_FORCEINLINE +static const char* _upb_Decoder_DecodeVarint(upb_Decoder* d, const char* ptr, + uint64_t* val) { + uint64_t byte = (uint8_t)*ptr; + if (UPB_LIKELY((byte & 0x80) == 0)) { + *val = byte; + return ptr + 1; + } else { + _upb_DecodeLongVarintReturn res = _upb_Decoder_DecodeLongVarint(ptr, byte); + if (!res.ptr) _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_Malformed); + *val = res.val; + return res.ptr; } +} - // Assign offsets. - for (upb_LayoutItem* item = d->vec.data; item < end; item++) { - upb_MiniTableField* f = &d->fields[item->field_index]; - switch (item->type) { - case kUpb_LayoutItemType_OneofField: - while (true) { - uint16_t next_offset = f->UPB_PRIVATE(offset); - f->UPB_PRIVATE(offset) = item->offset; - if (next_offset == kUpb_LayoutItem_IndexSentinel) break; - f = &d->fields[next_offset - kOneofBase]; - } - break; - case kUpb_LayoutItemType_Field: - f->UPB_PRIVATE(offset) = item->offset; - break; - default: - break; +UPB_FORCEINLINE +static const char* _upb_Decoder_DecodeTag(upb_Decoder* d, const char* ptr, + uint32_t* val) { + uint64_t byte = (uint8_t)*ptr; + if (UPB_LIKELY((byte & 0x80) == 0)) { + *val = byte; + return ptr + 1; + } else { + const char* start = ptr; + _upb_DecodeLongVarintReturn res = _upb_Decoder_DecodeLongVarint(ptr, byte); + if (!res.ptr || res.ptr - start > 5 || res.val > UINT32_MAX) { + _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_Malformed); } + *val = res.val; + return res.ptr; } - - // The fasttable parser (supported on 64-bit only) depends on this being a - // multiple of 8 in order to satisfy UPB_MALLOC_ALIGN, which is also 8. - // - // On 32-bit we could potentially make this smaller, but there is no - // compelling reason to optimize this right now. - d->table->UPB_PRIVATE(size) = UPB_ALIGN_UP(d->table->UPB_PRIVATE(size), 8); } -static void upb_MtDecoder_ValidateEntryField(upb_MtDecoder* d, - const upb_MiniTableField* f, - uint32_t expected_num) { - const char* name = expected_num == 1 ? "key" : "val"; - const uint32_t f_number = upb_MiniTableField_Number(f); - if (f_number != expected_num) { - upb_MdDecoder_ErrorJmp(&d->base, - "map %s did not have expected number (%d vs %d)", - name, expected_num, f_number); +UPB_FORCEINLINE +static const char* upb_Decoder_DecodeSize(upb_Decoder* d, const char* ptr, + uint32_t* size) { + uint64_t size64; + ptr = _upb_Decoder_DecodeVarint(d, ptr, &size64); + if (size64 >= INT32_MAX || + !upb_EpsCopyInputStream_CheckSize(&d->input, ptr, (int)size64)) { + _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_Malformed); } + *size = size64; + return ptr; +} - if (!upb_MiniTableField_IsScalar(f)) { - upb_MdDecoder_ErrorJmp( - &d->base, "map %s cannot be repeated or map, or be in oneof", name); +static void _upb_Decoder_MungeInt32(wireval* val) { + if (!UPB_PRIVATE(_upb_IsLittleEndian)()) { + /* The next stage will memcpy(dst, &val, 4) */ + val->uint32_val = val->uint64_val; } +} - uint32_t not_ok_types; - if (expected_num == 1) { - not_ok_types = (1 << kUpb_FieldType_Float) | (1 << kUpb_FieldType_Double) | - (1 << kUpb_FieldType_Message) | (1 << kUpb_FieldType_Group) | - (1 << kUpb_FieldType_Bytes) | (1 << kUpb_FieldType_Enum); - } else { - not_ok_types = 1 << kUpb_FieldType_Group; - } - - if ((1 << upb_MiniTableField_Type(f)) & not_ok_types) { - upb_MdDecoder_ErrorJmp(&d->base, "map %s cannot have type %d", name, - (int)f->UPB_PRIVATE(descriptortype)); +static void _upb_Decoder_Munge(int type, wireval* val) { + switch (type) { + case kUpb_FieldType_Bool: + val->bool_val = val->uint64_val != 0; + break; + case kUpb_FieldType_SInt32: { + uint32_t n = val->uint64_val; + val->uint32_val = (n >> 1) ^ -(int32_t)(n & 1); + break; + } + case kUpb_FieldType_SInt64: { + uint64_t n = val->uint64_val; + val->uint64_val = (n >> 1) ^ -(int64_t)(n & 1); + break; + } + case kUpb_FieldType_Int32: + case kUpb_FieldType_UInt32: + case kUpb_FieldType_Enum: + _upb_Decoder_MungeInt32(val); + break; } } -static void upb_MtDecoder_ParseMap(upb_MtDecoder* d, const char* data, - size_t len) { - upb_MtDecoder_ParseMessage(d, data, len); - upb_MtDecoder_AssignHasbits(d); +static upb_Message* _upb_Decoder_NewSubMessage(upb_Decoder* d, + const upb_MiniTableSub* subs, + const upb_MiniTableField* field, + upb_TaggedMessagePtr* target) { + const upb_MiniTable* subl = _upb_MiniTableSubs_MessageByField(subs, field); + UPB_ASSERT(subl); + upb_Message* msg = _upb_Message_New(subl, &d->arena); + if (!msg) _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_OutOfMemory); - if (UPB_UNLIKELY(d->table->UPB_PRIVATE(field_count) != 2)) { - upb_MdDecoder_ErrorJmp(&d->base, "%hu fields in map", - d->table->UPB_PRIVATE(field_count)); - UPB_UNREACHABLE(); - } + // Extensions should not be unlinked. A message extension should not be + // registered until its sub-message type is available to be linked. + bool is_empty = UPB_PRIVATE(_upb_MiniTable_IsEmpty)(subl); + bool is_extension = field->UPB_PRIVATE(mode) & kUpb_LabelFlags_IsExtension; + UPB_ASSERT(!(is_empty && is_extension)); - upb_LayoutItem* end = UPB_PTRADD(d->vec.data, d->vec.size); - for (upb_LayoutItem* item = d->vec.data; item < end; item++) { - if (item->type == kUpb_LayoutItemType_OneofCase) { - upb_MdDecoder_ErrorJmp(&d->base, "Map entry cannot have oneof"); - } + if (is_empty && !(d->options & kUpb_DecodeOption_ExperimentalAllowUnlinked)) { + _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_UnlinkedSubMessage); } - upb_MtDecoder_ValidateEntryField(d, &d->table->UPB_PRIVATE(fields)[0], 1); - upb_MtDecoder_ValidateEntryField(d, &d->table->UPB_PRIVATE(fields)[1], 2); - - // Map entries have a pre-determined layout, regardless of types. - // NOTE: sync with mini_table/message_internal.h. - const size_t kv_size = d->platform == kUpb_MiniTablePlatform_32Bit ? 8 : 16; - const size_t hasbit_size = 8; - d->fields[0].UPB_PRIVATE(offset) = hasbit_size; - d->fields[1].UPB_PRIVATE(offset) = hasbit_size + kv_size; - d->table->UPB_PRIVATE(size) = - UPB_ALIGN_UP(hasbit_size + kv_size + kv_size, 8); - - // Map entries have a special bit set to signal it's a map entry, used in - // upb_MiniTable_SetSubMessage() below. - d->table->UPB_PRIVATE(ext) |= kUpb_ExtMode_IsMapEntry; + upb_TaggedMessagePtr tagged = + UPB_PRIVATE(_upb_TaggedMessagePtr_Pack)(msg, is_empty); + memcpy(target, &tagged, sizeof(tagged)); + return msg; } -static void upb_MtDecoder_ParseMessageSet(upb_MtDecoder* d, const char* data, - size_t len) { - if (len > 0) { - upb_MdDecoder_ErrorJmp(&d->base, "Invalid message set encode length: %zu", - len); +static upb_Message* _upb_Decoder_ReuseSubMessage( + upb_Decoder* d, const upb_MiniTableSub* subs, + const upb_MiniTableField* field, upb_TaggedMessagePtr* target) { + upb_TaggedMessagePtr tagged = *target; + const upb_MiniTable* subl = _upb_MiniTableSubs_MessageByField(subs, field); + UPB_ASSERT(subl); + if (!upb_TaggedMessagePtr_IsEmpty(tagged) || + UPB_PRIVATE(_upb_MiniTable_IsEmpty)(subl)) { + return UPB_PRIVATE(_upb_TaggedMessagePtr_GetMessage)(tagged); } - upb_MiniTable* ret = d->table; - ret->UPB_PRIVATE(size) = 0; - ret->UPB_PRIVATE(field_count) = 0; - ret->UPB_PRIVATE(ext) = kUpb_ExtMode_IsMessageSet; - ret->UPB_PRIVATE(dense_below) = 0; - ret->UPB_PRIVATE(table_mask) = -1; - ret->UPB_PRIVATE(required_count) = 0; + // We found an empty message from a previous parse that was performed before + // this field was linked. But it is linked now, so we want to allocate a new + // message of the correct type and promote data into it before continuing. + upb_Message* existing = + UPB_PRIVATE(_upb_TaggedMessagePtr_GetEmptyMessage)(tagged); + upb_Message* promoted = _upb_Decoder_NewSubMessage(d, subs, field, target); + size_t size; + const char* unknown = upb_Message_GetUnknown(existing, &size); + upb_DecodeStatus status = upb_Decode(unknown, size, promoted, subl, d->extreg, + d->options, &d->arena); + if (status != kUpb_DecodeStatus_Ok) _upb_Decoder_ErrorJmp(d, status); + return promoted; } -static upb_MiniTable* upb_MtDecoder_DoBuildMiniTableWithBuf( - upb_MtDecoder* decoder, const char* data, size_t len, void** buf, - size_t* buf_size) { - upb_MdDecoder_CheckOutOfMemory(&decoder->base, decoder->table); - - decoder->table->UPB_PRIVATE(size) = 0; - decoder->table->UPB_PRIVATE(field_count) = 0; - decoder->table->UPB_PRIVATE(ext) = kUpb_ExtMode_NonExtendable; - decoder->table->UPB_PRIVATE(dense_below) = 0; - decoder->table->UPB_PRIVATE(table_mask) = -1; - decoder->table->UPB_PRIVATE(required_count) = 0; - - // Strip off and verify the version tag. - if (!len--) goto done; - const char vers = *data++; - - switch (vers) { - case kUpb_EncodedVersion_MapV1: - upb_MtDecoder_ParseMap(decoder, data, len); - break; +static const char* _upb_Decoder_ReadString(upb_Decoder* d, const char* ptr, + int size, upb_StringView* str) { + const char* str_ptr = ptr; + ptr = upb_EpsCopyInputStream_ReadString(&d->input, &str_ptr, size, &d->arena); + if (!ptr) _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_OutOfMemory); + str->data = str_ptr; + str->size = size; + return ptr; +} - case kUpb_EncodedVersion_MessageV1: - upb_MtDecoder_ParseMessage(decoder, data, len); - upb_MtDecoder_AssignHasbits(decoder); - upb_MtDecoder_SortLayoutItems(decoder); - upb_MtDecoder_AssignOffsets(decoder); - break; +UPB_FORCEINLINE +static const char* _upb_Decoder_RecurseSubMessage(upb_Decoder* d, + const char* ptr, + upb_Message* submsg, + const upb_MiniTable* subl, + uint32_t expected_end_group) { + if (--d->depth < 0) { + _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_MaxDepthExceeded); + } + ptr = _upb_Decoder_DecodeMessage(d, ptr, submsg, subl); + d->depth++; + if (d->end_group != expected_end_group) { + _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_Malformed); + } + return ptr; +} - case kUpb_EncodedVersion_MessageSetV1: - upb_MtDecoder_ParseMessageSet(decoder, data, len); - break; +UPB_FORCEINLINE +static const char* _upb_Decoder_DecodeSubMessage( + upb_Decoder* d, const char* ptr, upb_Message* submsg, + const upb_MiniTableSub* subs, const upb_MiniTableField* field, int size) { + int saved_delta = upb_EpsCopyInputStream_PushLimit(&d->input, ptr, size); + const upb_MiniTable* subl = _upb_MiniTableSubs_MessageByField(subs, field); + UPB_ASSERT(subl); + ptr = _upb_Decoder_RecurseSubMessage(d, ptr, submsg, subl, DECODE_NOGROUP); + upb_EpsCopyInputStream_PopLimit(&d->input, ptr, saved_delta); + return ptr; +} - default: - upb_MdDecoder_ErrorJmp(&decoder->base, "Invalid message version: %c", - vers); +UPB_FORCEINLINE +static const char* _upb_Decoder_DecodeGroup(upb_Decoder* d, const char* ptr, + upb_Message* submsg, + const upb_MiniTable* subl, + uint32_t number) { + if (_upb_Decoder_IsDone(d, &ptr)) { + _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_Malformed); } + ptr = _upb_Decoder_RecurseSubMessage(d, ptr, submsg, subl, number); + d->end_group = DECODE_NOGROUP; + return ptr; +} -done: - *buf = decoder->vec.data; - *buf_size = decoder->vec.capacity * sizeof(*decoder->vec.data); - return decoder->table; +UPB_FORCEINLINE +static const char* _upb_Decoder_DecodeUnknownGroup(upb_Decoder* d, + const char* ptr, + uint32_t number) { + return _upb_Decoder_DecodeGroup(d, ptr, NULL, NULL, number); } -static upb_MiniTable* upb_MtDecoder_BuildMiniTableWithBuf( - upb_MtDecoder* const decoder, const char* const data, const size_t len, - void** const buf, size_t* const buf_size) { - if (UPB_SETJMP(decoder->base.err) != 0) { - *buf = decoder->vec.data; - *buf_size = decoder->vec.capacity * sizeof(*decoder->vec.data); - return NULL; - } +UPB_FORCEINLINE +static const char* _upb_Decoder_DecodeKnownGroup( + upb_Decoder* d, const char* ptr, upb_Message* submsg, + const upb_MiniTableSub* subs, const upb_MiniTableField* field) { + const upb_MiniTable* subl = _upb_MiniTableSubs_MessageByField(subs, field); + UPB_ASSERT(subl); + return _upb_Decoder_DecodeGroup(d, ptr, submsg, subl, + field->UPB_PRIVATE(number)); +} - return upb_MtDecoder_DoBuildMiniTableWithBuf(decoder, data, len, buf, - buf_size); +static char* upb_Decoder_EncodeVarint32(uint32_t val, char* ptr) { + do { + uint8_t byte = val & 0x7fU; + val >>= 7; + if (val) byte |= 0x80U; + *(ptr++) = byte; + } while (val); + return ptr; } -upb_MiniTable* upb_MiniTable_BuildWithBuf(const char* data, size_t len, - upb_MiniTablePlatform platform, - upb_Arena* arena, void** buf, - size_t* buf_size, - upb_Status* status) { - upb_MtDecoder decoder = { - .base = {.status = status}, - .platform = platform, - .vec = - { - .data = *buf, - .capacity = *buf_size / sizeof(*decoder.vec.data), - .size = 0, - }, - .arena = arena, - .table = upb_Arena_Malloc(arena, sizeof(*decoder.table)), - }; +static void _upb_Decoder_AddUnknownVarints(upb_Decoder* d, upb_Message* msg, + uint32_t val1, uint32_t val2) { + char buf[20]; + char* end = buf; + end = upb_Decoder_EncodeVarint32(val1, end); + end = upb_Decoder_EncodeVarint32(val2, end); - return upb_MtDecoder_BuildMiniTableWithBuf(&decoder, data, len, buf, - buf_size); + if (!UPB_PRIVATE(_upb_Message_AddUnknown)(msg, buf, end - buf, &d->arena)) { + _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_OutOfMemory); + } } -static const char* upb_MtDecoder_DoBuildMiniTableExtension( - upb_MtDecoder* decoder, const char* data, size_t len, - upb_MiniTableExtension* ext, const upb_MiniTable* extendee, - upb_MiniTableSub sub) { - // If the string is non-empty then it must begin with a version tag. - if (len) { - if (*data != kUpb_EncodedVersion_ExtensionV1) { - upb_MdDecoder_ErrorJmp(&decoder->base, "Invalid ext version: %c", *data); - } - data++; - len--; - } - - uint16_t count = 0; - upb_SubCounts sub_counts = {0, 0}; - const char* ret = upb_MtDecoder_Parse(decoder, data, len, ext, sizeof(*ext), - &count, &sub_counts); - if (!ret || count != 1) return NULL; - - upb_MiniTableField* f = &ext->UPB_PRIVATE(field); - - f->UPB_PRIVATE(mode) |= kUpb_LabelFlags_IsExtension; - f->UPB_PRIVATE(offset) = 0; - f->presence = 0; - - if (extendee->UPB_PRIVATE(ext) & kUpb_ExtMode_IsMessageSet) { - // Extensions of MessageSet must be messages. - if (!upb_MiniTableField_IsSubMessage(f)) return NULL; - - // Extensions of MessageSet must be non-repeating. - if (upb_MiniTableField_IsArray(f)) return NULL; - } +UPB_FORCEINLINE +static bool _upb_Decoder_CheckEnum(upb_Decoder* d, const char* ptr, + upb_Message* msg, const upb_MiniTableEnum* e, + const upb_MiniTableField* field, + wireval* val) { + const uint32_t v = val->uint32_val; - ext->UPB_PRIVATE(extendee) = extendee; - ext->UPB_PRIVATE(sub) = sub; + if (UPB_LIKELY(upb_MiniTableEnum_CheckValue(e, v))) return true; - return ret; + // Unrecognized enum goes into unknown fields. + // For packed fields the tag could be arbitrarily far in the past, + // so we just re-encode the tag and value here. + const uint32_t tag = + ((uint32_t)field->UPB_PRIVATE(number) << 3) | kUpb_WireType_Varint; + upb_Message* unknown_msg = + field->UPB_PRIVATE(mode) & kUpb_LabelFlags_IsExtension ? d->unknown_msg + : msg; + _upb_Decoder_AddUnknownVarints(d, unknown_msg, tag, v); + return false; } -static const char* upb_MtDecoder_BuildMiniTableExtension( - upb_MtDecoder* const decoder, const char* const data, const size_t len, - upb_MiniTableExtension* const ext, const upb_MiniTable* const extendee, - const upb_MiniTableSub sub) { - if (UPB_SETJMP(decoder->base.err) != 0) return NULL; - return upb_MtDecoder_DoBuildMiniTableExtension(decoder, data, len, ext, - extendee, sub); +UPB_NOINLINE +static const char* _upb_Decoder_DecodeEnumArray(upb_Decoder* d, const char* ptr, + upb_Message* msg, + upb_Array* arr, + const upb_MiniTableSub* subs, + const upb_MiniTableField* field, + wireval* val) { + const upb_MiniTableEnum* e = _upb_MiniTableSubs_EnumByField(subs, field); + if (!_upb_Decoder_CheckEnum(d, ptr, msg, e, field, val)) return ptr; + void* mem = UPB_PTR_AT(_upb_array_ptr(arr), arr->UPB_PRIVATE(size) * 4, void); + arr->UPB_PRIVATE(size)++; + memcpy(mem, val, 4); + return ptr; } -const char* _upb_MiniTableExtension_Init(const char* data, size_t len, - upb_MiniTableExtension* ext, - const upb_MiniTable* extendee, - upb_MiniTableSub sub, - upb_MiniTablePlatform platform, - upb_Status* status) { - upb_MtDecoder decoder = { - .base = {.status = status}, - .arena = NULL, - .table = NULL, - .platform = platform, - }; +UPB_FORCEINLINE +static const char* _upb_Decoder_DecodeFixedPacked( + upb_Decoder* d, const char* ptr, upb_Array* arr, wireval* val, + const upb_MiniTableField* field, int lg2) { + int mask = (1 << lg2) - 1; + size_t count = val->size >> lg2; + if ((val->size & mask) != 0) { + // Length isn't a round multiple of elem size. + _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_Malformed); + } + _upb_Decoder_Reserve(d, arr, count); + void* mem = + UPB_PTR_AT(_upb_array_ptr(arr), arr->UPB_PRIVATE(size) << lg2, void); + arr->UPB_PRIVATE(size) += count; + // Note: if/when the decoder supports multi-buffer input, we will need to + // handle buffer seams here. + if (UPB_PRIVATE(_upb_IsLittleEndian)()) { + ptr = upb_EpsCopyInputStream_Copy(&d->input, ptr, mem, val->size); + } else { + int delta = upb_EpsCopyInputStream_PushLimit(&d->input, ptr, val->size); + char* dst = mem; + while (!_upb_Decoder_IsDone(d, &ptr)) { + if (lg2 == 2) { + ptr = upb_WireReader_ReadFixed32(ptr, dst); + dst += 4; + } else { + UPB_ASSERT(lg2 == 3); + ptr = upb_WireReader_ReadFixed64(ptr, dst); + dst += 8; + } + } + upb_EpsCopyInputStream_PopLimit(&d->input, ptr, delta); + } - return upb_MtDecoder_BuildMiniTableExtension(&decoder, data, len, ext, - extendee, sub); + return ptr; } -upb_MiniTableExtension* _upb_MiniTableExtension_Build( - const char* data, size_t len, const upb_MiniTable* extendee, - upb_MiniTableSub sub, upb_MiniTablePlatform platform, upb_Arena* arena, - upb_Status* status) { - upb_MiniTableExtension* ext = - upb_Arena_Malloc(arena, sizeof(upb_MiniTableExtension)); - if (UPB_UNLIKELY(!ext)) return NULL; - - const char* ptr = _upb_MiniTableExtension_Init(data, len, ext, extendee, sub, - platform, status); - if (UPB_UNLIKELY(!ptr)) return NULL; +UPB_FORCEINLINE +static const char* _upb_Decoder_DecodeVarintPacked( + upb_Decoder* d, const char* ptr, upb_Array* arr, wireval* val, + const upb_MiniTableField* field, int lg2) { + int scale = 1 << lg2; + int saved_limit = upb_EpsCopyInputStream_PushLimit(&d->input, ptr, val->size); + char* out = + UPB_PTR_AT(_upb_array_ptr(arr), arr->UPB_PRIVATE(size) << lg2, void); + while (!_upb_Decoder_IsDone(d, &ptr)) { + wireval elem; + ptr = _upb_Decoder_DecodeVarint(d, ptr, &elem.uint64_val); + _upb_Decoder_Munge(field->UPB_PRIVATE(descriptortype), &elem); + if (_upb_Decoder_Reserve(d, arr, 1)) { + out = + UPB_PTR_AT(_upb_array_ptr(arr), arr->UPB_PRIVATE(size) << lg2, void); + } + arr->UPB_PRIVATE(size)++; + memcpy(out, &elem, scale); + out += scale; + } + upb_EpsCopyInputStream_PopLimit(&d->input, ptr, saved_limit); + return ptr; +} - return ext; +UPB_NOINLINE +static const char* _upb_Decoder_DecodeEnumPacked( + upb_Decoder* d, const char* ptr, upb_Message* msg, upb_Array* arr, + const upb_MiniTableSub* subs, const upb_MiniTableField* field, + wireval* val) { + const upb_MiniTableEnum* e = _upb_MiniTableSubs_EnumByField(subs, field); + int saved_limit = upb_EpsCopyInputStream_PushLimit(&d->input, ptr, val->size); + char* out = UPB_PTR_AT(_upb_array_ptr(arr), arr->UPB_PRIVATE(size) * 4, void); + while (!_upb_Decoder_IsDone(d, &ptr)) { + wireval elem; + ptr = _upb_Decoder_DecodeVarint(d, ptr, &elem.uint64_val); + _upb_Decoder_MungeInt32(&elem); + if (!_upb_Decoder_CheckEnum(d, ptr, msg, e, field, &elem)) { + continue; + } + if (_upb_Decoder_Reserve(d, arr, 1)) { + out = UPB_PTR_AT(_upb_array_ptr(arr), arr->UPB_PRIVATE(size) * 4, void); + } + arr->UPB_PRIVATE(size)++; + memcpy(out, &elem, 4); + out += 4; + } + upb_EpsCopyInputStream_PopLimit(&d->input, ptr, saved_limit); + return ptr; } -upb_MiniTable* _upb_MiniTable_Build(const char* data, size_t len, - upb_MiniTablePlatform platform, - upb_Arena* arena, upb_Status* status) { - void* buf = NULL; - size_t size = 0; - upb_MiniTable* ret = upb_MiniTable_BuildWithBuf(data, len, platform, arena, - &buf, &size, status); - free(buf); +upb_Array* _upb_Decoder_CreateArray(upb_Decoder* d, + const upb_MiniTableField* field) { + const upb_FieldType field_type = field->UPB_PRIVATE(descriptortype); + const size_t lg2 = UPB_PRIVATE(_upb_FieldType_SizeLg2)(field_type); + upb_Array* ret = UPB_PRIVATE(_upb_Array_New)(&d->arena, 4, lg2); + if (!ret) _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_OutOfMemory); return ret; } +static const char* _upb_Decoder_DecodeToArray(upb_Decoder* d, const char* ptr, + upb_Message* msg, + const upb_MiniTableSub* subs, + const upb_MiniTableField* field, + wireval* val, int op) { + upb_Array** arrp = UPB_PTR_AT(msg, field->UPB_PRIVATE(offset), void); + upb_Array* arr = *arrp; + void* mem; -#include -#include - - -// Must be last. - -bool upb_MiniTable_SetSubMessage(upb_MiniTable* table, - upb_MiniTableField* field, - const upb_MiniTable* sub) { - UPB_ASSERT((uintptr_t)table->UPB_PRIVATE(fields) <= (uintptr_t)field && - (uintptr_t)field < (uintptr_t)(table->UPB_PRIVATE(fields) + - table->UPB_PRIVATE(field_count))); - UPB_ASSERT(sub); - - const bool sub_is_map = sub->UPB_PRIVATE(ext) & kUpb_ExtMode_IsMapEntry; - - switch (field->UPB_PRIVATE(descriptortype)) { - case kUpb_FieldType_Message: - if (sub_is_map) { - const bool table_is_map = - table->UPB_PRIVATE(ext) & kUpb_ExtMode_IsMapEntry; - if (UPB_UNLIKELY(table_is_map)) return false; - - field->UPB_PRIVATE(mode) = - (field->UPB_PRIVATE(mode) & ~kUpb_FieldMode_Mask) | - kUpb_FieldMode_Map; - } - break; - - case kUpb_FieldType_Group: - if (UPB_UNLIKELY(sub_is_map)) return false; - break; - - default: - return false; + if (arr) { + _upb_Decoder_Reserve(d, arr, 1); + } else { + arr = _upb_Decoder_CreateArray(d, field); + *arrp = arr; } - upb_MiniTableSub* table_sub = - (void*)&table->UPB_PRIVATE(subs)[field->UPB_PRIVATE(submsg_index)]; - // TODO: Add this assert back once YouTube is updated to not call - // this function repeatedly. - // UPB_ASSERT(UPB_PRIVATE(_upb_MiniTable_IsEmpty)(table_sub->submsg)); - *table_sub = upb_MiniTableSub_FromMessage(sub); - return true; -} - -bool upb_MiniTable_SetSubEnum(upb_MiniTable* table, upb_MiniTableField* field, - const upb_MiniTableEnum* sub) { - UPB_ASSERT((uintptr_t)table->UPB_PRIVATE(fields) <= (uintptr_t)field && - (uintptr_t)field < (uintptr_t)(table->UPB_PRIVATE(fields) + - table->UPB_PRIVATE(field_count))); - UPB_ASSERT(sub); - - upb_MiniTableSub* table_sub = - (void*)&table->UPB_PRIVATE(subs)[field->UPB_PRIVATE(submsg_index)]; - *table_sub = upb_MiniTableSub_FromEnum(sub); - return true; -} - -uint32_t upb_MiniTable_GetSubList(const upb_MiniTable* mt, - const upb_MiniTableField** subs) { - uint32_t msg_count = 0; - uint32_t enum_count = 0; - - for (int i = 0; i < mt->UPB_PRIVATE(field_count); i++) { - const upb_MiniTableField* f = &mt->UPB_PRIVATE(fields)[i]; - if (upb_MiniTableField_CType(f) == kUpb_CType_Message) { - *subs = f; - ++subs; - msg_count++; - } - } - - for (int i = 0; i < mt->UPB_PRIVATE(field_count); i++) { - const upb_MiniTableField* f = &mt->UPB_PRIVATE(fields)[i]; - if (upb_MiniTableField_CType(f) == kUpb_CType_Enum) { - *subs = f; - ++subs; - enum_count++; - } - } - - return (msg_count << 16) | enum_count; -} - -// The list of sub_tables and sub_enums must exactly match the number and order -// of sub-message fields and sub-enum fields given by upb_MiniTable_GetSubList() -// above. -bool upb_MiniTable_Link(upb_MiniTable* mt, const upb_MiniTable** sub_tables, - size_t sub_table_count, - const upb_MiniTableEnum** sub_enums, - size_t sub_enum_count) { - uint32_t msg_count = 0; - uint32_t enum_count = 0; - - for (int i = 0; i < mt->UPB_PRIVATE(field_count); i++) { - upb_MiniTableField* f = (upb_MiniTableField*)&mt->UPB_PRIVATE(fields)[i]; - if (upb_MiniTableField_CType(f) == kUpb_CType_Message) { - const upb_MiniTable* sub = sub_tables[msg_count++]; - if (msg_count > sub_table_count) return false; - if (sub != NULL) { - if (!upb_MiniTable_SetSubMessage(mt, f, sub)) return false; - } + switch (op) { + case kUpb_DecodeOp_Scalar1Byte: + case kUpb_DecodeOp_Scalar4Byte: + case kUpb_DecodeOp_Scalar8Byte: + /* Append scalar value. */ + mem = UPB_PTR_AT(_upb_array_ptr(arr), arr->UPB_PRIVATE(size) << op, void); + arr->UPB_PRIVATE(size)++; + memcpy(mem, val, 1 << op); + return ptr; + case kUpb_DecodeOp_String: + _upb_Decoder_VerifyUtf8(d, ptr, val->size); + /* Fallthrough. */ + case kUpb_DecodeOp_Bytes: { + /* Append bytes. */ + upb_StringView* str = + (upb_StringView*)_upb_array_ptr(arr) + arr->UPB_PRIVATE(size); + arr->UPB_PRIVATE(size)++; + return _upb_Decoder_ReadString(d, ptr, val->size, str); } - } - - for (int i = 0; i < mt->UPB_PRIVATE(field_count); i++) { - upb_MiniTableField* f = (upb_MiniTableField*)&mt->UPB_PRIVATE(fields)[i]; - if (upb_MiniTableField_IsClosedEnum(f)) { - const upb_MiniTableEnum* sub = sub_enums[enum_count++]; - if (enum_count > sub_enum_count) return false; - if (sub != NULL) { - if (!upb_MiniTable_SetSubEnum(mt, f, sub)) return false; + case kUpb_DecodeOp_SubMessage: { + /* Append submessage / group. */ + upb_TaggedMessagePtr* target = UPB_PTR_AT( + _upb_array_ptr(arr), arr->UPB_PRIVATE(size) * sizeof(void*), + upb_TaggedMessagePtr); + upb_Message* submsg = _upb_Decoder_NewSubMessage(d, subs, field, target); + arr->UPB_PRIVATE(size)++; + if (UPB_UNLIKELY(field->UPB_PRIVATE(descriptortype) == + kUpb_FieldType_Group)) { + return _upb_Decoder_DecodeKnownGroup(d, ptr, submsg, subs, field); + } else { + return _upb_Decoder_DecodeSubMessage(d, ptr, submsg, subs, field, + val->size); } } + case OP_FIXPCK_LG2(2): + case OP_FIXPCK_LG2(3): + return _upb_Decoder_DecodeFixedPacked(d, ptr, arr, val, field, + op - OP_FIXPCK_LG2(0)); + case OP_VARPCK_LG2(0): + case OP_VARPCK_LG2(2): + case OP_VARPCK_LG2(3): + return _upb_Decoder_DecodeVarintPacked(d, ptr, arr, val, field, + op - OP_VARPCK_LG2(0)); + case kUpb_DecodeOp_Enum: + return _upb_Decoder_DecodeEnumArray(d, ptr, msg, arr, subs, field, val); + case kUpb_DecodeOp_PackedEnum: + return _upb_Decoder_DecodeEnumPacked(d, ptr, msg, arr, subs, field, val); + default: + UPB_UNREACHABLE(); } - - return true; } +upb_Map* _upb_Decoder_CreateMap(upb_Decoder* d, const upb_MiniTable* entry) { + /* Maps descriptor type -> upb map size. */ + static const uint8_t kSizeInMap[] = { + [0] = -1, // invalid descriptor type */ + [kUpb_FieldType_Double] = 8, + [kUpb_FieldType_Float] = 4, + [kUpb_FieldType_Int64] = 8, + [kUpb_FieldType_UInt64] = 8, + [kUpb_FieldType_Int32] = 4, + [kUpb_FieldType_Fixed64] = 8, + [kUpb_FieldType_Fixed32] = 4, + [kUpb_FieldType_Bool] = 1, + [kUpb_FieldType_String] = UPB_MAPTYPE_STRING, + [kUpb_FieldType_Group] = sizeof(void*), + [kUpb_FieldType_Message] = sizeof(void*), + [kUpb_FieldType_Bytes] = UPB_MAPTYPE_STRING, + [kUpb_FieldType_UInt32] = 4, + [kUpb_FieldType_Enum] = 4, + [kUpb_FieldType_SFixed32] = 4, + [kUpb_FieldType_SFixed64] = 8, + [kUpb_FieldType_SInt32] = 4, + [kUpb_FieldType_SInt64] = 8, + }; -#include -#include -#include - - -// Must be last. - -#define EXTREG_KEY_SIZE (sizeof(upb_MiniTable*) + sizeof(uint32_t)) - -struct upb_ExtensionRegistry { - upb_Arena* arena; - upb_strtable exts; // Key is upb_MiniTable* concatenated with fieldnum. -}; - -static void extreg_key(char* buf, const upb_MiniTable* l, uint32_t fieldnum) { - memcpy(buf, &l, sizeof(l)); - memcpy(buf + sizeof(l), &fieldnum, sizeof(fieldnum)); + const upb_MiniTableField* key_field = &entry->UPB_PRIVATE(fields)[0]; + const upb_MiniTableField* val_field = &entry->UPB_PRIVATE(fields)[1]; + char key_size = kSizeInMap[key_field->UPB_PRIVATE(descriptortype)]; + char val_size = kSizeInMap[val_field->UPB_PRIVATE(descriptortype)]; + UPB_ASSERT(key_field->UPB_PRIVATE(offset) == offsetof(upb_MapEntryData, k)); + UPB_ASSERT(val_field->UPB_PRIVATE(offset) == offsetof(upb_MapEntryData, v)); + upb_Map* ret = _upb_Map_New(&d->arena, key_size, val_size); + if (!ret) _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_OutOfMemory); + return ret; } -upb_ExtensionRegistry* upb_ExtensionRegistry_New(upb_Arena* arena) { - upb_ExtensionRegistry* r = upb_Arena_Malloc(arena, sizeof(*r)); - if (!r) return NULL; - r->arena = arena; - if (!upb_strtable_init(&r->exts, 8, arena)) return NULL; - return r; -} +static const char* _upb_Decoder_DecodeToMap(upb_Decoder* d, const char* ptr, + upb_Message* msg, + const upb_MiniTableSub* subs, + const upb_MiniTableField* field, + wireval* val) { + upb_Map** map_p = UPB_PTR_AT(msg, field->UPB_PRIVATE(offset), upb_Map*); + upb_Map* map = *map_p; + upb_MapEntry ent; + UPB_ASSERT(upb_MiniTableField_Type(field) == kUpb_FieldType_Message); + const upb_MiniTable* entry = _upb_MiniTableSubs_MessageByField(subs, field); -UPB_API bool upb_ExtensionRegistry_Add(upb_ExtensionRegistry* r, - const upb_MiniTableExtension* e) { - char buf[EXTREG_KEY_SIZE]; - extreg_key(buf, e->UPB_PRIVATE(extendee), upb_MiniTableExtension_Number(e)); - if (upb_strtable_lookup2(&r->exts, buf, EXTREG_KEY_SIZE, NULL)) return false; - return upb_strtable_insert(&r->exts, buf, EXTREG_KEY_SIZE, - upb_value_constptr(e), r->arena); -} + UPB_ASSERT(entry); + UPB_ASSERT(entry->UPB_PRIVATE(field_count) == 2); + UPB_ASSERT(upb_MiniTableField_IsScalar(&entry->UPB_PRIVATE(fields)[0])); + UPB_ASSERT(upb_MiniTableField_IsScalar(&entry->UPB_PRIVATE(fields)[1])); -bool upb_ExtensionRegistry_AddArray(upb_ExtensionRegistry* r, - const upb_MiniTableExtension** e, - size_t count) { - const upb_MiniTableExtension** start = e; - const upb_MiniTableExtension** end = UPB_PTRADD(e, count); - for (; e < end; e++) { - if (!upb_ExtensionRegistry_Add(r, *e)) goto failure; + if (!map) { + map = _upb_Decoder_CreateMap(d, entry); + *map_p = map; } - return true; -failure: - // Back out the entries previously added. - for (end = e, e = start; e < end; e++) { - const upb_MiniTableExtension* ext = *e; - char buf[EXTREG_KEY_SIZE]; - extreg_key(buf, ext->UPB_PRIVATE(extendee), - upb_MiniTableExtension_Number(ext)); - upb_strtable_remove2(&r->exts, buf, EXTREG_KEY_SIZE, NULL); + // Parse map entry. + memset(&ent, 0, sizeof(ent)); + + if (entry->UPB_PRIVATE(fields)[1].UPB_PRIVATE(descriptortype) == + kUpb_FieldType_Message || + entry->UPB_PRIVATE(fields)[1].UPB_PRIVATE(descriptortype) == + kUpb_FieldType_Group) { + // Create proactively to handle the case where it doesn't appear. + upb_TaggedMessagePtr msg; + _upb_Decoder_NewSubMessage(d, entry->UPB_PRIVATE(subs), + &entry->UPB_PRIVATE(fields)[1], &msg); + ent.data.v.val = upb_value_uintptr(msg); } - return false; -} -const upb_MiniTableExtension* upb_ExtensionRegistry_Lookup( - const upb_ExtensionRegistry* r, const upb_MiniTable* t, uint32_t num) { - char buf[EXTREG_KEY_SIZE]; - upb_value v; - extreg_key(buf, t, num); - if (upb_strtable_lookup2(&r->exts, buf, EXTREG_KEY_SIZE, &v)) { - return upb_value_getconstptr(v); + ptr = _upb_Decoder_DecodeSubMessage(d, ptr, (upb_Message*)&ent.data, subs, + field, val->size); + // check if ent had any unknown fields + size_t size; + upb_Message_GetUnknown((upb_Message*)&ent.data, &size); + if (size != 0) { + char* buf; + size_t size; + uint32_t tag = + ((uint32_t)field->UPB_PRIVATE(number) << 3) | kUpb_WireType_Delimited; + upb_EncodeStatus status = + upb_Encode((upb_Message*)&ent.data, entry, 0, &d->arena, &buf, &size); + if (status != kUpb_EncodeStatus_Ok) { + _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_OutOfMemory); + } + _upb_Decoder_AddUnknownVarints(d, msg, tag, size); + if (!UPB_PRIVATE(_upb_Message_AddUnknown)(msg, buf, size, &d->arena)) { + _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_OutOfMemory); + } } else { - return NULL; + if (_upb_Map_Insert(map, &ent.data.k, map->key_size, &ent.data.v, + map->val_size, + &d->arena) == kUpb_MapInsertStatus_OutOfMemory) { + _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_OutOfMemory); + } } + return ptr; } +static const char* _upb_Decoder_DecodeToSubMessage( + upb_Decoder* d, const char* ptr, upb_Message* msg, + const upb_MiniTableSub* subs, const upb_MiniTableField* field, wireval* val, + int op) { + void* mem = UPB_PTR_AT(msg, field->UPB_PRIVATE(offset), void); + int type = field->UPB_PRIVATE(descriptortype); -#include -#include -#include - - -// Must be last. - -const upb_MiniTableField* upb_MiniTable_FindFieldByNumber( - const upb_MiniTable* m, uint32_t number) { - const size_t i = ((size_t)number) - 1; // 0 wraps to SIZE_MAX - - // Ideal case: index into dense fields - if (i < m->UPB_PRIVATE(dense_below)) { - UPB_ASSERT(m->UPB_PRIVATE(fields)[i].UPB_PRIVATE(number) == number); - return &m->UPB_PRIVATE(fields)[i]; + if (UPB_UNLIKELY(op == kUpb_DecodeOp_Enum) && + !_upb_Decoder_CheckEnum(d, ptr, msg, + _upb_MiniTableSubs_EnumByField(subs, field), + field, val)) { + return ptr; } - // Slow case: binary search - int lo = m->UPB_PRIVATE(dense_below); - int hi = m->UPB_PRIVATE(field_count) - 1; - while (lo <= hi) { - int mid = (lo + hi) / 2; - uint32_t num = m->UPB_PRIVATE(fields)[mid].UPB_PRIVATE(number); - if (num < number) { - lo = mid + 1; - continue; + /* Set presence if necessary. */ + if (field->presence > 0) { + UPB_PRIVATE(_upb_Message_SetHasbit)(msg, field); + } else if (field->presence < 0) { + /* Oneof case */ + uint32_t* oneof_case = UPB_PRIVATE(_upb_Message_OneofCasePtr)(msg, field); + if (op == kUpb_DecodeOp_SubMessage && + *oneof_case != field->UPB_PRIVATE(number)) { + memset(mem, 0, sizeof(void*)); } - if (num > number) { - hi = mid - 1; - continue; + *oneof_case = field->UPB_PRIVATE(number); + } + + /* Store into message. */ + switch (op) { + case kUpb_DecodeOp_SubMessage: { + upb_TaggedMessagePtr* submsgp = mem; + upb_Message* submsg; + if (*submsgp) { + submsg = _upb_Decoder_ReuseSubMessage(d, subs, field, submsgp); + } else { + submsg = _upb_Decoder_NewSubMessage(d, subs, field, submsgp); + } + if (UPB_UNLIKELY(type == kUpb_FieldType_Group)) { + ptr = _upb_Decoder_DecodeKnownGroup(d, ptr, submsg, subs, field); + } else { + ptr = _upb_Decoder_DecodeSubMessage(d, ptr, submsg, subs, field, + val->size); + } + break; } - return &m->UPB_PRIVATE(fields)[mid]; + case kUpb_DecodeOp_String: + _upb_Decoder_VerifyUtf8(d, ptr, val->size); + /* Fallthrough. */ + case kUpb_DecodeOp_Bytes: + return _upb_Decoder_ReadString(d, ptr, val->size, mem); + case kUpb_DecodeOp_Scalar8Byte: + memcpy(mem, val, 8); + break; + case kUpb_DecodeOp_Enum: + case kUpb_DecodeOp_Scalar4Byte: + memcpy(mem, val, 4); + break; + case kUpb_DecodeOp_Scalar1Byte: + memcpy(mem, val, 1); + break; + default: + UPB_UNREACHABLE(); } - return NULL; + + return ptr; } -const upb_MiniTableField* upb_MiniTable_GetOneof(const upb_MiniTable* m, - const upb_MiniTableField* f) { - if (UPB_UNLIKELY(!upb_MiniTableField_IsInOneof(f))) { - return NULL; +UPB_NOINLINE +const char* _upb_Decoder_CheckRequired(upb_Decoder* d, const char* ptr, + const upb_Message* msg, + const upb_MiniTable* m) { + UPB_ASSERT(m->UPB_PRIVATE(required_count)); + if (UPB_LIKELY((d->options & kUpb_DecodeOption_CheckRequired) == 0)) { + return ptr; } - const upb_MiniTableField* ptr = &m->UPB_PRIVATE(fields)[0]; - const upb_MiniTableField* end = - &m->UPB_PRIVATE(fields)[m->UPB_PRIVATE(field_count)]; - for (; ptr < end; ptr++) { - if (ptr->presence == (*f).presence) { - return ptr; - } + uint64_t msg_head; + memcpy(&msg_head, msg, 8); + msg_head = UPB_PRIVATE(_upb_BigEndian64)(msg_head); + if (UPB_PRIVATE(_upb_MiniTable_RequiredMask)(m) & ~msg_head) { + d->missing_required = true; } - return NULL; + return ptr; } -bool upb_MiniTable_NextOneofField(const upb_MiniTable* m, - const upb_MiniTableField** f) { - const upb_MiniTableField* ptr = *f; - const upb_MiniTableField* end = - &m->UPB_PRIVATE(fields)[m->UPB_PRIVATE(field_count)]; - while (++ptr < end) { - if (ptr->presence == (*f)->presence) { - *f = ptr; - return true; - } +UPB_FORCEINLINE +static bool _upb_Decoder_TryFastDispatch(upb_Decoder* d, const char** ptr, + upb_Message* msg, + const upb_MiniTable* m) { +#if UPB_FASTTABLE + if (m && m->UPB_PRIVATE(table_mask) != (unsigned char)-1) { + uint16_t tag = _upb_FastDecoder_LoadTag(*ptr); + intptr_t table = decode_totable(m); + *ptr = _upb_FastDecoder_TagDispatch(d, *ptr, msg, table, 0, tag); + return true; } +#endif return false; } +static const char* upb_Decoder_SkipField(upb_Decoder* d, const char* ptr, + uint32_t tag) { + int field_number = tag >> 3; + int wire_type = tag & 7; + switch (wire_type) { + case kUpb_WireType_Varint: { + uint64_t val; + return _upb_Decoder_DecodeVarint(d, ptr, &val); + } + case kUpb_WireType_64Bit: + return ptr + 8; + case kUpb_WireType_32Bit: + return ptr + 4; + case kUpb_WireType_Delimited: { + uint32_t size; + ptr = upb_Decoder_DecodeSize(d, ptr, &size); + return ptr + size; + } + case kUpb_WireType_StartGroup: + return _upb_Decoder_DecodeUnknownGroup(d, ptr, field_number); + default: + _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_Malformed); + } +} -#include -#include +enum { + kStartItemTag = ((kUpb_MsgSet_Item << 3) | kUpb_WireType_StartGroup), + kEndItemTag = ((kUpb_MsgSet_Item << 3) | kUpb_WireType_EndGroup), + kTypeIdTag = ((kUpb_MsgSet_TypeId << 3) | kUpb_WireType_Varint), + kMessageTag = ((kUpb_MsgSet_Message << 3) | kUpb_WireType_Delimited), +}; +static void upb_Decoder_AddKnownMessageSetItem( + upb_Decoder* d, upb_Message* msg, const upb_MiniTableExtension* item_mt, + const char* data, uint32_t size) { + upb_Extension* ext = + _upb_Message_GetOrCreateExtension(msg, item_mt, &d->arena); + if (UPB_UNLIKELY(!ext)) { + _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_OutOfMemory); + } + upb_Message* submsg = _upb_Decoder_NewSubMessage( + d, &ext->ext->UPB_PRIVATE(sub), upb_MiniTableExtension_AsField(ext->ext), + (upb_TaggedMessagePtr*)&ext->data); + upb_DecodeStatus status = upb_Decode( + data, size, submsg, upb_MiniTableExtension_GetSubMessage(item_mt), + d->extreg, d->options, &d->arena); + if (status != kUpb_DecodeStatus_Ok) _upb_Decoder_ErrorJmp(d, status); +} -// Must be last. +static void upb_Decoder_AddUnknownMessageSetItem(upb_Decoder* d, + upb_Message* msg, + uint32_t type_id, + const char* message_data, + uint32_t message_size) { + char buf[60]; + char* ptr = buf; + ptr = upb_Decoder_EncodeVarint32(kStartItemTag, ptr); + ptr = upb_Decoder_EncodeVarint32(kTypeIdTag, ptr); + ptr = upb_Decoder_EncodeVarint32(type_id, ptr); + ptr = upb_Decoder_EncodeVarint32(kMessageTag, ptr); + ptr = upb_Decoder_EncodeVarint32(message_size, ptr); + char* split = ptr; -// Checks if source and target mini table fields are identical. -// -// If the field is a sub message and sub messages are identical we record -// the association in table. -// -// Hashing the source sub message mini table and it's equivalent in the table -// stops recursing when a cycle is detected and instead just checks if the -// destination table is equal. -static upb_MiniTableEquals_Status upb_deep_check(const upb_MiniTable* src, - const upb_MiniTable* dst, - upb_inttable* table, - upb_Arena** arena) { - if (src->UPB_PRIVATE(field_count) != dst->UPB_PRIVATE(field_count)) - return kUpb_MiniTableEquals_NotEqual; - bool marked_src = false; - for (int i = 0; i < upb_MiniTable_FieldCount(src); i++) { - const upb_MiniTableField* src_field = upb_MiniTable_GetFieldByIndex(src, i); - const upb_MiniTableField* dst_field = upb_MiniTable_FindFieldByNumber( - dst, upb_MiniTableField_Number(src_field)); + ptr = upb_Decoder_EncodeVarint32(kEndItemTag, ptr); + char* end = ptr; - if (upb_MiniTableField_CType(src_field) != - upb_MiniTableField_CType(dst_field)) - return false; - if (src_field->UPB_PRIVATE(mode) != dst_field->UPB_PRIVATE(mode)) - return false; - if (src_field->UPB_PRIVATE(offset) != dst_field->UPB_PRIVATE(offset)) - return false; - if (src_field->presence != dst_field->presence) return false; - if (src_field->UPB_PRIVATE(submsg_index) != - dst_field->UPB_PRIVATE(submsg_index)) - return kUpb_MiniTableEquals_NotEqual; + if (!UPB_PRIVATE(_upb_Message_AddUnknown)(msg, buf, split - buf, &d->arena) || + !UPB_PRIVATE(_upb_Message_AddUnknown)(msg, message_data, message_size, + &d->arena) || + !UPB_PRIVATE(_upb_Message_AddUnknown)(msg, split, end - split, + &d->arena)) { + _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_OutOfMemory); + } +} - // Go no further if we are only checking for compatibility. - if (!table) continue; +static void upb_Decoder_AddMessageSetItem(upb_Decoder* d, upb_Message* msg, + const upb_MiniTable* t, + uint32_t type_id, const char* data, + uint32_t size) { + const upb_MiniTableExtension* item_mt = + upb_ExtensionRegistry_Lookup(d->extreg, t, type_id); + if (item_mt) { + upb_Decoder_AddKnownMessageSetItem(d, msg, item_mt, data, size); + } else { + upb_Decoder_AddUnknownMessageSetItem(d, msg, type_id, data, size); + } +} - if (upb_MiniTableField_CType(src_field) == kUpb_CType_Message) { - if (!*arena) { - *arena = upb_Arena_New(); - if (!upb_inttable_init(table, *arena)) { - return kUpb_MiniTableEquals_OutOfMemory; - } - } - if (!marked_src) { - marked_src = true; - upb_value val; - val.val = (uint64_t)dst; - if (!upb_inttable_insert(table, (uintptr_t)src, val, *arena)) { - return kUpb_MiniTableEquals_OutOfMemory; +static const char* upb_Decoder_DecodeMessageSetItem( + upb_Decoder* d, const char* ptr, upb_Message* msg, + const upb_MiniTable* layout) { + uint32_t type_id = 0; + upb_StringView preserved = {NULL, 0}; + typedef enum { + kUpb_HaveId = 1 << 0, + kUpb_HavePayload = 1 << 1, + } StateMask; + StateMask state_mask = 0; + while (!_upb_Decoder_IsDone(d, &ptr)) { + uint32_t tag; + ptr = _upb_Decoder_DecodeTag(d, ptr, &tag); + switch (tag) { + case kEndItemTag: + return ptr; + case kTypeIdTag: { + uint64_t tmp; + ptr = _upb_Decoder_DecodeVarint(d, ptr, &tmp); + if (state_mask & kUpb_HaveId) break; // Ignore dup. + state_mask |= kUpb_HaveId; + type_id = tmp; + if (state_mask & kUpb_HavePayload) { + upb_Decoder_AddMessageSetItem(d, msg, layout, type_id, preserved.data, + preserved.size); } + break; } - const upb_MiniTable* sub_src = - upb_MiniTable_GetSubMessageTable(src, src_field); - const upb_MiniTable* sub_dst = - upb_MiniTable_GetSubMessageTable(dst, dst_field); - if (sub_src != NULL) { - upb_value cmp; - if (upb_inttable_lookup(table, (uintptr_t)sub_src, &cmp)) { - // We already compared this src before. Check if same dst. - if (cmp.val != (uint64_t)sub_dst) { - return kUpb_MiniTableEquals_NotEqual; - } + case kMessageTag: { + uint32_t size; + ptr = upb_Decoder_DecodeSize(d, ptr, &size); + const char* data = ptr; + ptr += size; + if (state_mask & kUpb_HavePayload) break; // Ignore dup. + state_mask |= kUpb_HavePayload; + if (state_mask & kUpb_HaveId) { + upb_Decoder_AddMessageSetItem(d, msg, layout, type_id, data, size); } else { - // Recurse if not already visited. - upb_MiniTableEquals_Status s = - upb_deep_check(sub_src, sub_dst, table, arena); - if (s != kUpb_MiniTableEquals_Equal) { - return s; - } + // Out of order, we must preserve the payload. + preserved.data = data; + preserved.size = size; } + break; } + default: + // We do not preserve unexpected fields inside a message set item. + ptr = upb_Decoder_SkipField(d, ptr, tag); + break; } } - return kUpb_MiniTableEquals_Equal; + _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_Malformed); } -bool upb_MiniTable_Compatible(const upb_MiniTable* src, - const upb_MiniTable* dst) { - return upb_deep_check(src, dst, NULL, NULL); -} +static const upb_MiniTableField* _upb_Decoder_FindField(upb_Decoder* d, + const upb_MiniTable* t, + uint32_t field_number, + int* last_field_index) { + static upb_MiniTableField none = { + 0, 0, 0, 0, kUpb_FakeFieldType_FieldNotFound, 0}; + if (t == NULL) return &none; -upb_MiniTableEquals_Status upb_MiniTable_Equals(const upb_MiniTable* src, - const upb_MiniTable* dst) { - // Arena allocated on demand for hash table. - upb_Arena* arena = NULL; - // Table to keep track of visited mini tables to guard against cycles. - upb_inttable table; - upb_MiniTableEquals_Status status = upb_deep_check(src, dst, &table, &arena); - if (arena) { - upb_Arena_Free(arena); + size_t idx = ((size_t)field_number) - 1; // 0 wraps to SIZE_MAX + if (idx < t->UPB_PRIVATE(dense_below)) { + /* Fastest case: index into dense fields. */ + goto found; } - return status; -} + if (t->UPB_PRIVATE(dense_below) < t->UPB_PRIVATE(field_count)) { + /* Linear search non-dense fields. Resume scanning from last_field_index + * since fields are usually in order. */ + size_t last = *last_field_index; + for (idx = last; idx < t->UPB_PRIVATE(field_count); idx++) { + if (t->UPB_PRIVATE(fields)[idx].UPB_PRIVATE(number) == field_number) { + goto found; + } + } + for (idx = t->UPB_PRIVATE(dense_below); idx < last; idx++) { + if (t->UPB_PRIVATE(fields)[idx].UPB_PRIVATE(number) == field_number) { + goto found; + } + } + } -// Must be last. + if (d->extreg) { + switch (t->UPB_PRIVATE(ext)) { + case kUpb_ExtMode_Extendable: { + const upb_MiniTableExtension* ext = + upb_ExtensionRegistry_Lookup(d->extreg, t, field_number); + if (ext) return upb_MiniTableExtension_AsField(ext); + break; + } + case kUpb_ExtMode_IsMessageSet: + if (field_number == kUpb_MsgSet_Item) { + static upb_MiniTableField item = { + 0, 0, 0, 0, kUpb_FakeFieldType_MessageSetItem, 0}; + return &item; + } + break; + } + } -struct upb_DefPool { - upb_Arena* arena; - upb_strtable syms; // full_name -> packed def ptr - upb_strtable files; // file_name -> (upb_FileDef*) - upb_inttable exts; // (upb_MiniTableExtension*) -> (upb_FieldDef*) - upb_ExtensionRegistry* extreg; - const UPB_DESC(FeatureSetDefaults) * feature_set_defaults; - upb_MiniTablePlatform platform; - void* scratch_data; - size_t scratch_size; - size_t bytes_loaded; -}; + return &none; /* Unknown field. */ -void upb_DefPool_Free(upb_DefPool* s) { - upb_Arena_Free(s->arena); - upb_gfree(s->scratch_data); - upb_gfree(s); +found: + UPB_ASSERT(t->UPB_PRIVATE(fields)[idx].UPB_PRIVATE(number) == field_number); + *last_field_index = idx; + return &t->UPB_PRIVATE(fields)[idx]; } -static const char serialized_defaults[] = UPB_INTERNAL_UPB_EDITION_DEFAULTS; - -upb_DefPool* upb_DefPool_New(void) { - upb_DefPool* s = upb_gmalloc(sizeof(*s)); - if (!s) return NULL; - - s->arena = upb_Arena_New(); - s->bytes_loaded = 0; - - s->scratch_size = 240; - s->scratch_data = upb_gmalloc(s->scratch_size); - if (!s->scratch_data) goto err; - - if (!upb_strtable_init(&s->syms, 32, s->arena)) goto err; - if (!upb_strtable_init(&s->files, 4, s->arena)) goto err; - if (!upb_inttable_init(&s->exts, s->arena)) goto err; - - s->extreg = upb_ExtensionRegistry_New(s->arena); - if (!s->extreg) goto err; +int _upb_Decoder_GetVarintOp(const upb_MiniTableField* field) { + static const int8_t kVarintOps[] = { + [kUpb_FakeFieldType_FieldNotFound] = kUpb_DecodeOp_UnknownField, + [kUpb_FieldType_Double] = kUpb_DecodeOp_UnknownField, + [kUpb_FieldType_Float] = kUpb_DecodeOp_UnknownField, + [kUpb_FieldType_Int64] = kUpb_DecodeOp_Scalar8Byte, + [kUpb_FieldType_UInt64] = kUpb_DecodeOp_Scalar8Byte, + [kUpb_FieldType_Int32] = kUpb_DecodeOp_Scalar4Byte, + [kUpb_FieldType_Fixed64] = kUpb_DecodeOp_UnknownField, + [kUpb_FieldType_Fixed32] = kUpb_DecodeOp_UnknownField, + [kUpb_FieldType_Bool] = kUpb_DecodeOp_Scalar1Byte, + [kUpb_FieldType_String] = kUpb_DecodeOp_UnknownField, + [kUpb_FieldType_Group] = kUpb_DecodeOp_UnknownField, + [kUpb_FieldType_Message] = kUpb_DecodeOp_UnknownField, + [kUpb_FieldType_Bytes] = kUpb_DecodeOp_UnknownField, + [kUpb_FieldType_UInt32] = kUpb_DecodeOp_Scalar4Byte, + [kUpb_FieldType_Enum] = kUpb_DecodeOp_Enum, + [kUpb_FieldType_SFixed32] = kUpb_DecodeOp_UnknownField, + [kUpb_FieldType_SFixed64] = kUpb_DecodeOp_UnknownField, + [kUpb_FieldType_SInt32] = kUpb_DecodeOp_Scalar4Byte, + [kUpb_FieldType_SInt64] = kUpb_DecodeOp_Scalar8Byte, + [kUpb_FakeFieldType_MessageSetItem] = kUpb_DecodeOp_UnknownField, + }; - s->platform = kUpb_MiniTablePlatform_Native; + return kVarintOps[field->UPB_PRIVATE(descriptortype)]; +} - upb_Status status; - if (!upb_DefPool_SetFeatureSetDefaults( - s, serialized_defaults, sizeof(serialized_defaults) - 1, &status)) { - goto err; +UPB_FORCEINLINE +static void _upb_Decoder_CheckUnlinked(upb_Decoder* d, const upb_MiniTable* mt, + const upb_MiniTableField* field, + int* op) { + // If sub-message is not linked, treat as unknown. + if (field->UPB_PRIVATE(mode) & kUpb_LabelFlags_IsExtension) return; + const upb_MiniTable* mt_sub = + _upb_MiniTableSubs_MessageByField(mt->UPB_PRIVATE(subs), field); + if ((d->options & kUpb_DecodeOption_ExperimentalAllowUnlinked) || + !UPB_PRIVATE(_upb_MiniTable_IsEmpty)(mt_sub)) { + return; } - - if (!s->feature_set_defaults) goto err; - - return s; - -err: - upb_DefPool_Free(s); - return NULL; +#ifndef NDEBUG + const upb_MiniTableField* oneof = upb_MiniTable_GetOneof(mt, field); + if (oneof) { + // All other members of the oneof must be message fields that are also + // unlinked. + do { + UPB_ASSERT(upb_MiniTableField_CType(oneof) == kUpb_CType_Message); + const upb_MiniTableSub* oneof_sub = + &mt->UPB_PRIVATE(subs)[oneof->UPB_PRIVATE(submsg_index)]; + UPB_ASSERT(!oneof_sub); + } while (upb_MiniTable_NextOneofField(mt, &oneof)); + } +#endif // NDEBUG + *op = kUpb_DecodeOp_UnknownField; } -const UPB_DESC(FeatureSetDefaults) * - upb_DefPool_FeatureSetDefaults(const upb_DefPool* s) { - return s->feature_set_defaults; -} +int _upb_Decoder_GetDelimitedOp(upb_Decoder* d, const upb_MiniTable* mt, + const upb_MiniTableField* field) { + enum { kRepeatedBase = 19 }; -bool upb_DefPool_SetFeatureSetDefaults(upb_DefPool* s, - const char* serialized_defaults, - size_t serialized_len, - upb_Status* status) { - const UPB_DESC(FeatureSetDefaults)* defaults = UPB_DESC( - FeatureSetDefaults_parse)(serialized_defaults, serialized_len, s->arena); - if (!defaults) { - upb_Status_SetErrorFormat(status, "Failed to parse defaults"); - return false; - } - if (upb_strtable_count(&s->files) > 0) { - upb_Status_SetErrorFormat(status, - "Feature set defaults can't be changed once the " - "pool has started building"); - return false; - } - int min_edition = UPB_DESC(FeatureSetDefaults_minimum_edition(defaults)); - int max_edition = UPB_DESC(FeatureSetDefaults_maximum_edition(defaults)); - if (min_edition > max_edition) { - upb_Status_SetErrorFormat(status, "Invalid edition range %s to %s", - upb_FileDef_EditionName(min_edition), - upb_FileDef_EditionName(max_edition)); - return false; - } - size_t size; - const UPB_DESC( - FeatureSetDefaults_FeatureSetEditionDefault)* const* default_list = - UPB_DESC(FeatureSetDefaults_defaults(defaults, &size)); - int prev_edition = UPB_DESC(EDITION_UNKNOWN); - for (size_t i = 0; i < size; ++i) { - int edition = UPB_DESC( - FeatureSetDefaults_FeatureSetEditionDefault_edition(default_list[i])); - if (edition == UPB_DESC(EDITION_UNKNOWN)) { - upb_Status_SetErrorFormat(status, "Invalid edition UNKNOWN specified"); - return false; - } - if (edition <= prev_edition) { - upb_Status_SetErrorFormat(status, - "Feature set defaults are not strictly " - "increasing, %s is greater than or equal to %s", - upb_FileDef_EditionName(prev_edition), - upb_FileDef_EditionName(edition)); - return false; - } - prev_edition = edition; - } - - // Copy the defaults into the pool. - s->feature_set_defaults = defaults; - return true; -} + static const int8_t kDelimitedOps[] = { + /* For non-repeated field type. */ + [kUpb_FakeFieldType_FieldNotFound] = + kUpb_DecodeOp_UnknownField, // Field not found. + [kUpb_FieldType_Double] = kUpb_DecodeOp_UnknownField, + [kUpb_FieldType_Float] = kUpb_DecodeOp_UnknownField, + [kUpb_FieldType_Int64] = kUpb_DecodeOp_UnknownField, + [kUpb_FieldType_UInt64] = kUpb_DecodeOp_UnknownField, + [kUpb_FieldType_Int32] = kUpb_DecodeOp_UnknownField, + [kUpb_FieldType_Fixed64] = kUpb_DecodeOp_UnknownField, + [kUpb_FieldType_Fixed32] = kUpb_DecodeOp_UnknownField, + [kUpb_FieldType_Bool] = kUpb_DecodeOp_UnknownField, + [kUpb_FieldType_String] = kUpb_DecodeOp_String, + [kUpb_FieldType_Group] = kUpb_DecodeOp_UnknownField, + [kUpb_FieldType_Message] = kUpb_DecodeOp_SubMessage, + [kUpb_FieldType_Bytes] = kUpb_DecodeOp_Bytes, + [kUpb_FieldType_UInt32] = kUpb_DecodeOp_UnknownField, + [kUpb_FieldType_Enum] = kUpb_DecodeOp_UnknownField, + [kUpb_FieldType_SFixed32] = kUpb_DecodeOp_UnknownField, + [kUpb_FieldType_SFixed64] = kUpb_DecodeOp_UnknownField, + [kUpb_FieldType_SInt32] = kUpb_DecodeOp_UnknownField, + [kUpb_FieldType_SInt64] = kUpb_DecodeOp_UnknownField, + [kUpb_FakeFieldType_MessageSetItem] = kUpb_DecodeOp_UnknownField, + // For repeated field type. */ + [kRepeatedBase + kUpb_FieldType_Double] = OP_FIXPCK_LG2(3), + [kRepeatedBase + kUpb_FieldType_Float] = OP_FIXPCK_LG2(2), + [kRepeatedBase + kUpb_FieldType_Int64] = OP_VARPCK_LG2(3), + [kRepeatedBase + kUpb_FieldType_UInt64] = OP_VARPCK_LG2(3), + [kRepeatedBase + kUpb_FieldType_Int32] = OP_VARPCK_LG2(2), + [kRepeatedBase + kUpb_FieldType_Fixed64] = OP_FIXPCK_LG2(3), + [kRepeatedBase + kUpb_FieldType_Fixed32] = OP_FIXPCK_LG2(2), + [kRepeatedBase + kUpb_FieldType_Bool] = OP_VARPCK_LG2(0), + [kRepeatedBase + kUpb_FieldType_String] = kUpb_DecodeOp_String, + [kRepeatedBase + kUpb_FieldType_Group] = kUpb_DecodeOp_SubMessage, + [kRepeatedBase + kUpb_FieldType_Message] = kUpb_DecodeOp_SubMessage, + [kRepeatedBase + kUpb_FieldType_Bytes] = kUpb_DecodeOp_Bytes, + [kRepeatedBase + kUpb_FieldType_UInt32] = OP_VARPCK_LG2(2), + [kRepeatedBase + kUpb_FieldType_Enum] = kUpb_DecodeOp_PackedEnum, + [kRepeatedBase + kUpb_FieldType_SFixed32] = OP_FIXPCK_LG2(2), + [kRepeatedBase + kUpb_FieldType_SFixed64] = OP_FIXPCK_LG2(3), + [kRepeatedBase + kUpb_FieldType_SInt32] = OP_VARPCK_LG2(2), + [kRepeatedBase + kUpb_FieldType_SInt64] = OP_VARPCK_LG2(3), + // Omitting kUpb_FakeFieldType_MessageSetItem, because we never emit a + // repeated msgset type + }; -bool _upb_DefPool_InsertExt(upb_DefPool* s, const upb_MiniTableExtension* ext, - const upb_FieldDef* f) { - return upb_inttable_insert(&s->exts, (uintptr_t)ext, upb_value_constptr(f), - s->arena); -} + int ndx = field->UPB_PRIVATE(descriptortype); + if (upb_MiniTableField_IsArray(field)) ndx += kRepeatedBase; + int op = kDelimitedOps[ndx]; -bool _upb_DefPool_InsertSym(upb_DefPool* s, upb_StringView sym, upb_value v, - upb_Status* status) { - // TODO: table should support an operation "tryinsert" to avoid the double - // lookup. - if (upb_strtable_lookup2(&s->syms, sym.data, sym.size, NULL)) { - upb_Status_SetErrorFormat(status, "duplicate symbol '%s'", sym.data); - return false; - } - if (!upb_strtable_insert(&s->syms, sym.data, sym.size, v, s->arena)) { - upb_Status_SetErrorMessage(status, "out of memory"); - return false; + if (op == kUpb_DecodeOp_SubMessage) { + _upb_Decoder_CheckUnlinked(d, mt, field, &op); } - return true; -} -static const void* _upb_DefPool_Unpack(const upb_DefPool* s, const char* sym, - size_t size, upb_deftype_t type) { - upb_value v; - return upb_strtable_lookup2(&s->syms, sym, size, &v) - ? _upb_DefType_Unpack(v, type) - : NULL; + return op; } -bool _upb_DefPool_LookupSym(const upb_DefPool* s, const char* sym, size_t size, - upb_value* v) { - return upb_strtable_lookup2(&s->syms, sym, size, v); -} +UPB_FORCEINLINE +static const char* _upb_Decoder_DecodeWireValue(upb_Decoder* d, const char* ptr, + const upb_MiniTable* mt, + const upb_MiniTableField* field, + int wire_type, wireval* val, + int* op) { + static const unsigned kFixed32OkMask = (1 << kUpb_FieldType_Float) | + (1 << kUpb_FieldType_Fixed32) | + (1 << kUpb_FieldType_SFixed32); -upb_ExtensionRegistry* _upb_DefPool_ExtReg(const upb_DefPool* s) { - return s->extreg; -} + static const unsigned kFixed64OkMask = (1 << kUpb_FieldType_Double) | + (1 << kUpb_FieldType_Fixed64) | + (1 << kUpb_FieldType_SFixed64); -void** _upb_DefPool_ScratchData(const upb_DefPool* s) { - return (void**)&s->scratch_data; + switch (wire_type) { + case kUpb_WireType_Varint: + ptr = _upb_Decoder_DecodeVarint(d, ptr, &val->uint64_val); + *op = _upb_Decoder_GetVarintOp(field); + _upb_Decoder_Munge(field->UPB_PRIVATE(descriptortype), val); + return ptr; + case kUpb_WireType_32Bit: + *op = kUpb_DecodeOp_Scalar4Byte; + if (((1 << field->UPB_PRIVATE(descriptortype)) & kFixed32OkMask) == 0) { + *op = kUpb_DecodeOp_UnknownField; + } + return upb_WireReader_ReadFixed32(ptr, &val->uint32_val); + case kUpb_WireType_64Bit: + *op = kUpb_DecodeOp_Scalar8Byte; + if (((1 << field->UPB_PRIVATE(descriptortype)) & kFixed64OkMask) == 0) { + *op = kUpb_DecodeOp_UnknownField; + } + return upb_WireReader_ReadFixed64(ptr, &val->uint64_val); + case kUpb_WireType_Delimited: + ptr = upb_Decoder_DecodeSize(d, ptr, &val->size); + *op = _upb_Decoder_GetDelimitedOp(d, mt, field); + return ptr; + case kUpb_WireType_StartGroup: + val->uint32_val = field->UPB_PRIVATE(number); + if (field->UPB_PRIVATE(descriptortype) == kUpb_FieldType_Group) { + *op = kUpb_DecodeOp_SubMessage; + _upb_Decoder_CheckUnlinked(d, mt, field, op); + } else if (field->UPB_PRIVATE(descriptortype) == + kUpb_FakeFieldType_MessageSetItem) { + *op = kUpb_DecodeOp_MessageSetItem; + } else { + *op = kUpb_DecodeOp_UnknownField; + } + return ptr; + default: + break; + } + _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_Malformed); } -size_t* _upb_DefPool_ScratchSize(const upb_DefPool* s) { - return (size_t*)&s->scratch_size; -} +UPB_FORCEINLINE +static const char* _upb_Decoder_DecodeKnownField( + upb_Decoder* d, const char* ptr, upb_Message* msg, + const upb_MiniTable* layout, const upb_MiniTableField* field, int op, + wireval* val) { + const upb_MiniTableSub* subs = layout->UPB_PRIVATE(subs); + uint8_t mode = field->UPB_PRIVATE(mode); -void _upb_DefPool_SetPlatform(upb_DefPool* s, upb_MiniTablePlatform platform) { - assert(upb_strtable_count(&s->files) == 0); - s->platform = platform; -} + if (UPB_UNLIKELY(mode & kUpb_LabelFlags_IsExtension)) { + const upb_MiniTableExtension* ext_layout = + (const upb_MiniTableExtension*)field; + upb_Extension* ext = + _upb_Message_GetOrCreateExtension(msg, ext_layout, &d->arena); + if (UPB_UNLIKELY(!ext)) { + _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_OutOfMemory); + } + d->unknown_msg = msg; + msg = (upb_Message*)&ext->data; + subs = &ext->ext->UPB_PRIVATE(sub); + } -const upb_MessageDef* upb_DefPool_FindMessageByName(const upb_DefPool* s, - const char* sym) { - return _upb_DefPool_Unpack(s, sym, strlen(sym), UPB_DEFTYPE_MSG); + switch (mode & kUpb_FieldMode_Mask) { + case kUpb_FieldMode_Array: + return _upb_Decoder_DecodeToArray(d, ptr, msg, subs, field, val, op); + case kUpb_FieldMode_Map: + return _upb_Decoder_DecodeToMap(d, ptr, msg, subs, field, val); + case kUpb_FieldMode_Scalar: + return _upb_Decoder_DecodeToSubMessage(d, ptr, msg, subs, field, val, op); + default: + UPB_UNREACHABLE(); + } } -const upb_MessageDef* upb_DefPool_FindMessageByNameWithSize( - const upb_DefPool* s, const char* sym, size_t len) { - return _upb_DefPool_Unpack(s, sym, len, UPB_DEFTYPE_MSG); +static const char* _upb_Decoder_ReverseSkipVarint(const char* ptr, + uint32_t val) { + uint32_t seen = 0; + do { + ptr--; + seen <<= 7; + seen |= *ptr & 0x7f; + } while (seen != val); + return ptr; } -const upb_EnumDef* upb_DefPool_FindEnumByName(const upb_DefPool* s, - const char* sym) { - return _upb_DefPool_Unpack(s, sym, strlen(sym), UPB_DEFTYPE_ENUM); -} +static const char* _upb_Decoder_DecodeUnknownField(upb_Decoder* d, + const char* ptr, + upb_Message* msg, + int field_number, + int wire_type, wireval val) { + if (field_number == 0) _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_Malformed); -const upb_EnumValueDef* upb_DefPool_FindEnumByNameval(const upb_DefPool* s, - const char* sym) { - return _upb_DefPool_Unpack(s, sym, strlen(sym), UPB_DEFTYPE_ENUMVAL); -} + // Since unknown fields are the uncommon case, we do a little extra work here + // to walk backwards through the buffer to find the field start. This frees + // up a register in the fast paths (when the field is known), which leads to + // significant speedups in benchmarks. + const char* start = ptr; -const upb_FileDef* upb_DefPool_FindFileByName(const upb_DefPool* s, - const char* name) { - upb_value v; - return upb_strtable_lookup(&s->files, name, &v) ? upb_value_getconstptr(v) - : NULL; -} + if (wire_type == kUpb_WireType_Delimited) ptr += val.size; + if (msg) { + switch (wire_type) { + case kUpb_WireType_Varint: + case kUpb_WireType_Delimited: + start--; + while (start[-1] & 0x80) start--; + break; + case kUpb_WireType_32Bit: + start -= 4; + break; + case kUpb_WireType_64Bit: + start -= 8; + break; + default: + break; + } -const upb_FileDef* upb_DefPool_FindFileByNameWithSize(const upb_DefPool* s, - const char* name, - size_t len) { - upb_value v; - return upb_strtable_lookup2(&s->files, name, len, &v) - ? upb_value_getconstptr(v) - : NULL; -} - -const upb_FieldDef* upb_DefPool_FindExtensionByNameWithSize( - const upb_DefPool* s, const char* name, size_t size) { - upb_value v; - if (!upb_strtable_lookup2(&s->syms, name, size, &v)) return NULL; + assert(start == d->debug_valstart); + uint32_t tag = ((uint32_t)field_number << 3) | wire_type; + start = _upb_Decoder_ReverseSkipVarint(start, tag); + assert(start == d->debug_tagstart); - switch (_upb_DefType_Type(v)) { - case UPB_DEFTYPE_FIELD: - return _upb_DefType_Unpack(v, UPB_DEFTYPE_FIELD); - case UPB_DEFTYPE_MSG: { - const upb_MessageDef* m = _upb_DefType_Unpack(v, UPB_DEFTYPE_MSG); - return _upb_MessageDef_InMessageSet(m) - ? upb_MessageDef_NestedExtension(m, 0) - : NULL; + if (wire_type == kUpb_WireType_StartGroup) { + d->unknown = start; + d->unknown_msg = msg; + ptr = _upb_Decoder_DecodeUnknownGroup(d, ptr, field_number); + start = d->unknown; + d->unknown = NULL; } - default: - break; + if (!UPB_PRIVATE(_upb_Message_AddUnknown)(msg, start, ptr - start, + &d->arena)) { + _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_OutOfMemory); + } + } else if (wire_type == kUpb_WireType_StartGroup) { + ptr = _upb_Decoder_DecodeUnknownGroup(d, ptr, field_number); } - - return NULL; + return ptr; } -const upb_FieldDef* upb_DefPool_FindExtensionByName(const upb_DefPool* s, - const char* sym) { - return upb_DefPool_FindExtensionByNameWithSize(s, sym, strlen(sym)); -} +UPB_NOINLINE +static const char* _upb_Decoder_DecodeMessage(upb_Decoder* d, const char* ptr, + upb_Message* msg, + const upb_MiniTable* layout) { + int last_field_index = 0; -const upb_ServiceDef* upb_DefPool_FindServiceByName(const upb_DefPool* s, - const char* name) { - return _upb_DefPool_Unpack(s, name, strlen(name), UPB_DEFTYPE_SERVICE); -} +#if UPB_FASTTABLE + // The first time we want to skip fast dispatch, because we may have just been + // invoked by the fast parser to handle a case that it bailed on. + if (!_upb_Decoder_IsDone(d, &ptr)) goto nofast; +#endif -const upb_ServiceDef* upb_DefPool_FindServiceByNameWithSize( - const upb_DefPool* s, const char* name, size_t size) { - return _upb_DefPool_Unpack(s, name, size, UPB_DEFTYPE_SERVICE); -} + while (!_upb_Decoder_IsDone(d, &ptr)) { + uint32_t tag; + const upb_MiniTableField* field; + int field_number; + int wire_type; + wireval val; + int op; -const upb_FileDef* upb_DefPool_FindFileContainingSymbol(const upb_DefPool* s, - const char* name) { - upb_value v; - // TODO: non-extension fields and oneofs. - if (upb_strtable_lookup(&s->syms, name, &v)) { - switch (_upb_DefType_Type(v)) { - case UPB_DEFTYPE_EXT: { - const upb_FieldDef* f = _upb_DefType_Unpack(v, UPB_DEFTYPE_EXT); - return upb_FieldDef_File(f); - } - case UPB_DEFTYPE_MSG: { - const upb_MessageDef* m = _upb_DefType_Unpack(v, UPB_DEFTYPE_MSG); - return upb_MessageDef_File(m); - } - case UPB_DEFTYPE_ENUM: { - const upb_EnumDef* e = _upb_DefType_Unpack(v, UPB_DEFTYPE_ENUM); - return upb_EnumDef_File(e); - } - case UPB_DEFTYPE_ENUMVAL: { - const upb_EnumValueDef* ev = - _upb_DefType_Unpack(v, UPB_DEFTYPE_ENUMVAL); - return upb_EnumDef_File(upb_EnumValueDef_Enum(ev)); - } - case UPB_DEFTYPE_SERVICE: { - const upb_ServiceDef* service = - _upb_DefType_Unpack(v, UPB_DEFTYPE_SERVICE); - return upb_ServiceDef_File(service); - } - default: - UPB_UNREACHABLE(); + if (_upb_Decoder_TryFastDispatch(d, &ptr, msg, layout)) break; + +#if UPB_FASTTABLE + nofast: +#endif + +#ifndef NDEBUG + d->debug_tagstart = ptr; +#endif + + UPB_ASSERT(ptr < d->input.limit_ptr); + ptr = _upb_Decoder_DecodeTag(d, ptr, &tag); + field_number = tag >> 3; + wire_type = tag & 7; + +#ifndef NDEBUG + d->debug_valstart = ptr; +#endif + + if (wire_type == kUpb_WireType_EndGroup) { + d->end_group = field_number; + return ptr; } - } - const char* last_dot = strrchr(name, '.'); - if (last_dot) { - const upb_MessageDef* parent = - upb_DefPool_FindMessageByNameWithSize(s, name, last_dot - name); - if (parent) { - const char* shortname = last_dot + 1; - if (upb_MessageDef_FindByNameWithSize(parent, shortname, - strlen(shortname), NULL, NULL)) { - return upb_MessageDef_File(parent); + field = _upb_Decoder_FindField(d, layout, field_number, &last_field_index); + ptr = _upb_Decoder_DecodeWireValue(d, ptr, layout, field, wire_type, &val, + &op); + + if (op >= 0) { + ptr = _upb_Decoder_DecodeKnownField(d, ptr, msg, layout, field, op, &val); + } else { + switch (op) { + case kUpb_DecodeOp_UnknownField: + ptr = _upb_Decoder_DecodeUnknownField(d, ptr, msg, field_number, + wire_type, val); + break; + case kUpb_DecodeOp_MessageSetItem: + ptr = upb_Decoder_DecodeMessageSetItem(d, ptr, msg, layout); + break; } } } - return NULL; + return UPB_UNLIKELY(layout && layout->UPB_PRIVATE(required_count)) + ? _upb_Decoder_CheckRequired(d, ptr, msg, layout) + : ptr; } -static void remove_filedef(upb_DefPool* s, upb_FileDef* file) { - intptr_t iter = UPB_INTTABLE_BEGIN; - upb_StringView key; - upb_value val; - while (upb_strtable_next2(&s->syms, &key, &val, &iter)) { - const upb_FileDef* f; - switch (_upb_DefType_Type(val)) { - case UPB_DEFTYPE_EXT: - f = upb_FieldDef_File(_upb_DefType_Unpack(val, UPB_DEFTYPE_EXT)); - break; - case UPB_DEFTYPE_MSG: - f = upb_MessageDef_File(_upb_DefType_Unpack(val, UPB_DEFTYPE_MSG)); - break; - case UPB_DEFTYPE_ENUM: - f = upb_EnumDef_File(_upb_DefType_Unpack(val, UPB_DEFTYPE_ENUM)); - break; - case UPB_DEFTYPE_ENUMVAL: - f = upb_EnumDef_File(upb_EnumValueDef_Enum( - _upb_DefType_Unpack(val, UPB_DEFTYPE_ENUMVAL))); - break; - case UPB_DEFTYPE_SERVICE: - f = upb_ServiceDef_File(_upb_DefType_Unpack(val, UPB_DEFTYPE_SERVICE)); - break; - default: - UPB_UNREACHABLE(); - } +const char* _upb_FastDecoder_DecodeGeneric(struct upb_Decoder* d, + const char* ptr, upb_Message* msg, + intptr_t table, uint64_t hasbits, + uint64_t data) { + (void)data; + *(uint32_t*)msg |= hasbits; + return _upb_Decoder_DecodeMessage(d, ptr, msg, decode_totablep(table)); +} - if (f == file) upb_strtable_removeiter(&s->syms, &iter); +static upb_DecodeStatus _upb_Decoder_DecodeTop(struct upb_Decoder* d, + const char* buf, void* msg, + const upb_MiniTable* l) { + if (!_upb_Decoder_TryFastDispatch(d, &buf, msg, l)) { + _upb_Decoder_DecodeMessage(d, buf, msg, l); } + if (d->end_group != DECODE_NOGROUP) return kUpb_DecodeStatus_Malformed; + if (d->missing_required) return kUpb_DecodeStatus_MissingRequired; + return kUpb_DecodeStatus_Ok; } -static const upb_FileDef* upb_DefBuilder_AddFileToPool( - upb_DefBuilder* const builder, upb_DefPool* const s, - const UPB_DESC(FileDescriptorProto) * const file_proto, - const upb_StringView name, upb_Status* const status) { - if (UPB_SETJMP(builder->err) != 0) { - UPB_ASSERT(!upb_Status_IsOk(status)); - if (builder->file) { - remove_filedef(s, builder->file); - builder->file = NULL; - } - } else if (!builder->arena || !builder->tmp_arena || - !upb_strtable_init(&builder->feature_cache, 16, - builder->tmp_arena) || - !(builder->legacy_features = - UPB_DESC(FeatureSet_new)(builder->tmp_arena))) { - _upb_DefBuilder_OomErr(builder); +UPB_NOINLINE +const char* _upb_Decoder_IsDoneFallback(upb_EpsCopyInputStream* e, + const char* ptr, int overrun) { + return _upb_EpsCopyInputStream_IsDoneFallbackInline( + e, ptr, overrun, _upb_Decoder_BufferFlipCallback); +} + +static upb_DecodeStatus upb_Decoder_Decode(upb_Decoder* const decoder, + const char* const buf, + void* const msg, + const upb_MiniTable* const l, + upb_Arena* const arena) { + if (UPB_SETJMP(decoder->err) == 0) { + decoder->status = _upb_Decoder_DecodeTop(decoder, buf, msg, l); } else { - _upb_FileDef_Create(builder, file_proto); - upb_strtable_insert(&s->files, name.data, name.size, - upb_value_constptr(builder->file), builder->arena); - UPB_ASSERT(upb_Status_IsOk(status)); - upb_Arena_Fuse(s->arena, builder->arena); + UPB_ASSERT(decoder->status != kUpb_DecodeStatus_Ok); } - if (builder->arena) upb_Arena_Free(builder->arena); - if (builder->tmp_arena) upb_Arena_Free(builder->tmp_arena); - return builder->file; + UPB_PRIVATE(_upb_Arena_SwapOut)(arena, &decoder->arena); + + return decoder->status; } -static const upb_FileDef* _upb_DefPool_AddFile( - upb_DefPool* s, const UPB_DESC(FileDescriptorProto) * file_proto, - const upb_MiniTableFile* layout, upb_Status* status) { - const upb_StringView name = UPB_DESC(FileDescriptorProto_name)(file_proto); +upb_DecodeStatus upb_Decode(const char* buf, size_t size, upb_Message* msg, + const upb_MiniTable* l, + const upb_ExtensionRegistry* extreg, int options, + upb_Arena* arena) { + upb_Decoder decoder; + unsigned depth = (unsigned)options >> 16; - // Determine whether we already know about this file. - { - upb_value v; - if (upb_strtable_lookup2(&s->files, name.data, name.size, &v)) { - upb_Status_SetErrorFormat(status, - "duplicate file name " UPB_STRINGVIEW_FORMAT, - UPB_STRINGVIEW_ARGS(name)); - return NULL; - } - } + upb_EpsCopyInputStream_Init(&decoder.input, &buf, size, + options & kUpb_DecodeOption_AliasString); - upb_DefBuilder ctx = { - .symtab = s, - .tmp_buf = NULL, - .tmp_buf_size = 0, - .layout = layout, - .platform = s->platform, - .msg_count = 0, - .enum_count = 0, - .ext_count = 0, - .status = status, - .file = NULL, - .arena = upb_Arena_New(), - .tmp_arena = upb_Arena_New(), - }; + decoder.extreg = extreg; + decoder.unknown = NULL; + decoder.depth = depth ? depth : kUpb_WireFormat_DefaultDepthLimit; + decoder.end_group = DECODE_NOGROUP; + decoder.options = (uint16_t)options; + decoder.missing_required = false; + decoder.status = kUpb_DecodeStatus_Ok; - return upb_DefBuilder_AddFileToPool(&ctx, s, file_proto, name, status); -} + // Violating the encapsulation of the arena for performance reasons. + // This is a temporary arena that we swap into and swap out of when we are + // done. The temporary arena only needs to be able to handle allocation, + // not fuse or free, so it does not need many of the members to be initialized + // (particularly parent_or_count). + UPB_PRIVATE(_upb_Arena_SwapIn)(&decoder.arena, arena); -const upb_FileDef* upb_DefPool_AddFile(upb_DefPool* s, - const UPB_DESC(FileDescriptorProto) * - file_proto, - upb_Status* status) { - return _upb_DefPool_AddFile(s, file_proto, NULL, status); + return upb_Decoder_Decode(&decoder, buf, msg, l, arena); } -bool _upb_DefPool_LoadDefInitEx(upb_DefPool* s, const _upb_DefPool_Init* init, - bool rebuild_minitable) { - /* Since this function should never fail (it would indicate a bug in upb) we - * print errors to stderr instead of returning error status to the user. */ - _upb_DefPool_Init** deps = init->deps; - UPB_DESC(FileDescriptorProto) * file; - upb_Arena* arena; - upb_Status status; - - upb_Status_Clear(&status); - - if (upb_DefPool_FindFileByName(s, init->filename)) { - return true; - } +#undef OP_FIXPCK_LG2 +#undef OP_VARPCK_LG2 - arena = upb_Arena_New(); +// We encode backwards, to avoid pre-computing lengths (one-pass encode). - for (; *deps; deps++) { - if (!_upb_DefPool_LoadDefInitEx(s, *deps, rebuild_minitable)) goto err; - } - file = UPB_DESC(FileDescriptorProto_parse_ex)( - init->descriptor.data, init->descriptor.size, NULL, - kUpb_DecodeOption_AliasString, arena); - s->bytes_loaded += init->descriptor.size; +#include +#include +#include +#include - if (!file) { - upb_Status_SetErrorFormat( - &status, - "Failed to parse compiled-in descriptor for file '%s'. This should " - "never happen.", - init->filename); - goto err; - } - const upb_MiniTableFile* mt = rebuild_minitable ? NULL : init->layout; - if (!_upb_DefPool_AddFile(s, file, mt, &status)) { - goto err; - } +// Must be last. - upb_Arena_Free(arena); - return true; +#define UPB_PB_VARINT_MAX_LEN 10 -err: - fprintf(stderr, - "Error loading compiled-in descriptor for file '%s' (this should " - "never happen): %s\n", - init->filename, upb_Status_ErrorMessage(&status)); - upb_Arena_Free(arena); - return false; +UPB_NOINLINE +static size_t encode_varint64(uint64_t val, char* buf) { + size_t i = 0; + do { + uint8_t byte = val & 0x7fU; + val >>= 7; + if (val) byte |= 0x80U; + buf[i++] = byte; + } while (val); + return i; } -size_t _upb_DefPool_BytesLoaded(const upb_DefPool* s) { - return s->bytes_loaded; +static uint32_t encode_zz32(int32_t n) { + return ((uint32_t)n << 1) ^ (n >> 31); +} +static uint64_t encode_zz64(int64_t n) { + return ((uint64_t)n << 1) ^ (n >> 63); } -upb_Arena* _upb_DefPool_Arena(const upb_DefPool* s) { return s->arena; } +typedef struct { + upb_EncodeStatus status; + jmp_buf err; + upb_Arena* arena; + char *buf, *ptr, *limit; + int options; + int depth; + _upb_mapsorter sorter; +} upb_encstate; -const upb_FieldDef* upb_DefPool_FindExtensionByMiniTable( - const upb_DefPool* s, const upb_MiniTableExtension* ext) { - upb_value v; - bool ok = upb_inttable_lookup(&s->exts, (uintptr_t)ext, &v); - UPB_ASSERT(ok); - return upb_value_getconstptr(v); +static size_t upb_roundup_pow2(size_t bytes) { + size_t ret = 128; + while (ret < bytes) { + ret *= 2; + } + return ret; } -const upb_FieldDef* upb_DefPool_FindExtensionByNumber(const upb_DefPool* s, - const upb_MessageDef* m, - int32_t fieldnum) { - const upb_MiniTable* t = upb_MessageDef_MiniTable(m); - const upb_MiniTableExtension* ext = - upb_ExtensionRegistry_Lookup(s->extreg, t, fieldnum); - return ext ? upb_DefPool_FindExtensionByMiniTable(s, ext) : NULL; +UPB_NORETURN static void encode_err(upb_encstate* e, upb_EncodeStatus s) { + UPB_ASSERT(s != kUpb_EncodeStatus_Ok); + e->status = s; + UPB_LONGJMP(e->err, 1); } -const upb_ExtensionRegistry* upb_DefPool_ExtensionRegistry( - const upb_DefPool* s) { - return s->extreg; -} +UPB_NOINLINE +static void encode_growbuffer(upb_encstate* e, size_t bytes) { + size_t old_size = e->limit - e->buf; + size_t new_size = upb_roundup_pow2(bytes + (e->limit - e->ptr)); + char* new_buf = upb_Arena_Realloc(e->arena, e->buf, old_size, new_size); -const upb_FieldDef** upb_DefPool_GetAllExtensions(const upb_DefPool* s, - const upb_MessageDef* m, - size_t* count) { - size_t n = 0; - intptr_t iter = UPB_INTTABLE_BEGIN; - uintptr_t key; - upb_value val; - // This is O(all exts) instead of O(exts for m). If we need this to be - // efficient we may need to make extreg into a two-level table, or have a - // second per-message index. - while (upb_inttable_next(&s->exts, &key, &val, &iter)) { - const upb_FieldDef* f = upb_value_getconstptr(val); - if (upb_FieldDef_ContainingType(f) == m) n++; - } - const upb_FieldDef** exts = upb_gmalloc(n * sizeof(*exts)); - iter = UPB_INTTABLE_BEGIN; - size_t i = 0; - while (upb_inttable_next(&s->exts, &key, &val, &iter)) { - const upb_FieldDef* f = upb_value_getconstptr(val); - if (upb_FieldDef_ContainingType(f) == m) exts[i++] = f; + if (!new_buf) encode_err(e, kUpb_EncodeStatus_OutOfMemory); + + // We want previous data at the end, realloc() put it at the beginning. + // TODO: This is somewhat inefficient since we are copying twice. + // Maybe create a realloc() that copies to the end of the new buffer? + if (old_size > 0) { + memmove(new_buf + new_size - old_size, e->buf, old_size); } - *count = n; - return exts; -} -bool _upb_DefPool_LoadDefInit(upb_DefPool* s, const _upb_DefPool_Init* init) { - return _upb_DefPool_LoadDefInitEx(s, init, false); -} + e->ptr = new_buf + new_size - (e->limit - e->ptr); + e->limit = new_buf + new_size; + e->buf = new_buf; + e->ptr -= bytes; +} -// Must be last. +/* Call to ensure that at least "bytes" bytes are available for writing at + * e->ptr. Returns false if the bytes could not be allocated. */ +UPB_FORCEINLINE +static void encode_reserve(upb_encstate* e, size_t bytes) { + if ((size_t)(e->ptr - e->buf) < bytes) { + encode_growbuffer(e, bytes); + return; + } -upb_deftype_t _upb_DefType_Type(upb_value v) { - const uintptr_t num = (uintptr_t)upb_value_getconstptr(v); - return num & UPB_DEFTYPE_MASK; + e->ptr -= bytes; } -upb_value _upb_DefType_Pack(const void* ptr, upb_deftype_t type) { - uintptr_t num = (uintptr_t)ptr; - UPB_ASSERT((num & UPB_DEFTYPE_MASK) == 0); - num |= type; - return upb_value_constptr((const void*)num); +/* Writes the given bytes to the buffer, handling reserve/advance. */ +static void encode_bytes(upb_encstate* e, const void* data, size_t len) { + if (len == 0) return; /* memcpy() with zero size is UB */ + encode_reserve(e, len); + memcpy(e->ptr, data, len); } -const void* _upb_DefType_Unpack(upb_value v, upb_deftype_t type) { - uintptr_t num = (uintptr_t)upb_value_getconstptr(v); - return (num & UPB_DEFTYPE_MASK) == type - ? (const void*)(num & ~UPB_DEFTYPE_MASK) - : NULL; +static void encode_fixed64(upb_encstate* e, uint64_t val) { + val = UPB_PRIVATE(_upb_BigEndian64)(val); + encode_bytes(e, &val, sizeof(uint64_t)); } +static void encode_fixed32(upb_encstate* e, uint32_t val) { + val = UPB_PRIVATE(_upb_BigEndian32)(val); + encode_bytes(e, &val, sizeof(uint32_t)); +} -// Must be last. - -bool _upb_DescState_Grow(upb_DescState* d, upb_Arena* a) { - const size_t oldbufsize = d->bufsize; - const int used = d->ptr - d->buf; +UPB_NOINLINE +static void encode_longvarint(upb_encstate* e, uint64_t val) { + size_t len; + char* start; - if (!d->buf) { - d->buf = upb_Arena_Malloc(a, d->bufsize); - if (!d->buf) return false; - d->ptr = d->buf; - d->e.end = d->buf + d->bufsize; - } + encode_reserve(e, UPB_PB_VARINT_MAX_LEN); + len = encode_varint64(val, e->ptr); + start = e->ptr + UPB_PB_VARINT_MAX_LEN - len; + memmove(start, e->ptr, len); + e->ptr = start; +} - if (oldbufsize - used < kUpb_MtDataEncoder_MinSize) { - d->bufsize *= 2; - d->buf = upb_Arena_Realloc(a, d->buf, oldbufsize, d->bufsize); - if (!d->buf) return false; - d->ptr = d->buf + used; - d->e.end = d->buf + d->bufsize; +UPB_FORCEINLINE +static void encode_varint(upb_encstate* e, uint64_t val) { + if (val < 128 && e->ptr != e->buf) { + --e->ptr; + *e->ptr = val; + } else { + encode_longvarint(e, val); } - - return true; } - -#include -#include -#include - - -// Must be last. - -struct upb_EnumDef { - const UPB_DESC(EnumOptions*) opts; - const UPB_DESC(FeatureSet*) resolved_features; - const upb_MiniTableEnum* layout; // Only for proto2. - const upb_FileDef* file; - const upb_MessageDef* containing_type; // Could be merged with "file". - const char* full_name; - upb_strtable ntoi; - upb_inttable iton; - const upb_EnumValueDef* values; - const upb_EnumReservedRange* res_ranges; - const upb_StringView* res_names; - int value_count; - int res_range_count; - int res_name_count; - int32_t defaultval; - bool is_sorted; // Whether all of the values are defined in ascending order. -#if UINTPTR_MAX == 0xffffffff - uint32_t padding; // Increase size to a multiple of 8. -#endif -}; - -upb_EnumDef* _upb_EnumDef_At(const upb_EnumDef* e, int i) { - return (upb_EnumDef*)&e[i]; -} - -const upb_MiniTableEnum* _upb_EnumDef_MiniTable(const upb_EnumDef* e) { - return e->layout; -} - -bool _upb_EnumDef_Insert(upb_EnumDef* e, upb_EnumValueDef* v, upb_Arena* a) { - const char* name = upb_EnumValueDef_Name(v); - const upb_value val = upb_value_constptr(v); - bool ok = upb_strtable_insert(&e->ntoi, name, strlen(name), val, a); - if (!ok) return false; - - // Multiple enumerators can have the same number, first one wins. - const int number = upb_EnumValueDef_Number(v); - if (!upb_inttable_lookup(&e->iton, number, NULL)) { - return upb_inttable_insert(&e->iton, number, val, a); - } - return true; +static void encode_double(upb_encstate* e, double d) { + uint64_t u64; + UPB_ASSERT(sizeof(double) == sizeof(uint64_t)); + memcpy(&u64, &d, sizeof(uint64_t)); + encode_fixed64(e, u64); } -const UPB_DESC(EnumOptions) * upb_EnumDef_Options(const upb_EnumDef* e) { - return e->opts; +static void encode_float(upb_encstate* e, float d) { + uint32_t u32; + UPB_ASSERT(sizeof(float) == sizeof(uint32_t)); + memcpy(&u32, &d, sizeof(uint32_t)); + encode_fixed32(e, u32); } -bool upb_EnumDef_HasOptions(const upb_EnumDef* e) { - return e->opts != (void*)kUpbDefOptDefault; +static void encode_tag(upb_encstate* e, uint32_t field_number, + uint8_t wire_type) { + encode_varint(e, (field_number << 3) | wire_type); } -const UPB_DESC(FeatureSet) * - upb_EnumDef_ResolvedFeatures(const upb_EnumDef* e) { - return e->resolved_features; -} +static void encode_fixedarray(upb_encstate* e, const upb_Array* arr, + size_t elem_size, uint32_t tag) { + size_t bytes = arr->UPB_PRIVATE(size) * elem_size; + const char* data = _upb_array_constptr(arr); + const char* ptr = data + bytes - elem_size; -const char* upb_EnumDef_FullName(const upb_EnumDef* e) { return e->full_name; } + if (tag || !UPB_PRIVATE(_upb_IsLittleEndian)()) { + while (true) { + if (elem_size == 4) { + uint32_t val; + memcpy(&val, ptr, sizeof(val)); + val = UPB_PRIVATE(_upb_BigEndian32)(val); + encode_bytes(e, &val, elem_size); + } else { + UPB_ASSERT(elem_size == 8); + uint64_t val; + memcpy(&val, ptr, sizeof(val)); + val = UPB_PRIVATE(_upb_BigEndian64)(val); + encode_bytes(e, &val, elem_size); + } -const char* upb_EnumDef_Name(const upb_EnumDef* e) { - return _upb_DefBuilder_FullToShort(e->full_name); + if (tag) encode_varint(e, tag); + if (ptr == data) break; + ptr -= elem_size; + } + } else { + encode_bytes(e, data, bytes); + } } -const upb_FileDef* upb_EnumDef_File(const upb_EnumDef* e) { return e->file; } - -const upb_MessageDef* upb_EnumDef_ContainingType(const upb_EnumDef* e) { - return e->containing_type; -} +static void encode_message(upb_encstate* e, const upb_Message* msg, + const upb_MiniTable* m, size_t* size); -int32_t upb_EnumDef_Default(const upb_EnumDef* e) { - UPB_ASSERT(upb_EnumDef_FindValueByNumber(e, e->defaultval)); - return e->defaultval; +static void encode_TaggedMessagePtr(upb_encstate* e, + upb_TaggedMessagePtr tagged, + const upb_MiniTable* m, size_t* size) { + if (upb_TaggedMessagePtr_IsEmpty(tagged)) { + m = UPB_PRIVATE(_upb_MiniTable_Empty)(); + } + encode_message(e, UPB_PRIVATE(_upb_TaggedMessagePtr_GetMessage)(tagged), m, + size); } -int upb_EnumDef_ReservedRangeCount(const upb_EnumDef* e) { - return e->res_range_count; -} +static void encode_scalar(upb_encstate* e, const void* _field_mem, + const upb_MiniTableSub* subs, + const upb_MiniTableField* f) { + const char* field_mem = _field_mem; + int wire_type; -const upb_EnumReservedRange* upb_EnumDef_ReservedRange(const upb_EnumDef* e, - int i) { - UPB_ASSERT(0 <= i && i < e->res_range_count); - return _upb_EnumReservedRange_At(e->res_ranges, i); -} +#define CASE(ctype, type, wtype, encodeval) \ + { \ + ctype val = *(ctype*)field_mem; \ + encode_##type(e, encodeval); \ + wire_type = wtype; \ + break; \ + } -int upb_EnumDef_ReservedNameCount(const upb_EnumDef* e) { - return e->res_name_count; -} + switch (f->UPB_PRIVATE(descriptortype)) { + case kUpb_FieldType_Double: + CASE(double, double, kUpb_WireType_64Bit, val); + case kUpb_FieldType_Float: + CASE(float, float, kUpb_WireType_32Bit, val); + case kUpb_FieldType_Int64: + case kUpb_FieldType_UInt64: + CASE(uint64_t, varint, kUpb_WireType_Varint, val); + case kUpb_FieldType_UInt32: + CASE(uint32_t, varint, kUpb_WireType_Varint, val); + case kUpb_FieldType_Int32: + case kUpb_FieldType_Enum: + CASE(int32_t, varint, kUpb_WireType_Varint, (int64_t)val); + case kUpb_FieldType_SFixed64: + case kUpb_FieldType_Fixed64: + CASE(uint64_t, fixed64, kUpb_WireType_64Bit, val); + case kUpb_FieldType_Fixed32: + case kUpb_FieldType_SFixed32: + CASE(uint32_t, fixed32, kUpb_WireType_32Bit, val); + case kUpb_FieldType_Bool: + CASE(bool, varint, kUpb_WireType_Varint, val); + case kUpb_FieldType_SInt32: + CASE(int32_t, varint, kUpb_WireType_Varint, encode_zz32(val)); + case kUpb_FieldType_SInt64: + CASE(int64_t, varint, kUpb_WireType_Varint, encode_zz64(val)); + case kUpb_FieldType_String: + case kUpb_FieldType_Bytes: { + upb_StringView view = *(upb_StringView*)field_mem; + encode_bytes(e, view.data, view.size); + encode_varint(e, view.size); + wire_type = kUpb_WireType_Delimited; + break; + } + case kUpb_FieldType_Group: { + size_t size; + upb_TaggedMessagePtr submsg = *(upb_TaggedMessagePtr*)field_mem; + const upb_MiniTable* subm = + upb_MiniTableSub_Message(subs[f->UPB_PRIVATE(submsg_index)]); + if (submsg == 0) { + return; + } + if (--e->depth == 0) encode_err(e, kUpb_EncodeStatus_MaxDepthExceeded); + encode_tag(e, f->UPB_PRIVATE(number), kUpb_WireType_EndGroup); + encode_TaggedMessagePtr(e, submsg, subm, &size); + wire_type = kUpb_WireType_StartGroup; + e->depth++; + break; + } + case kUpb_FieldType_Message: { + size_t size; + upb_TaggedMessagePtr submsg = *(upb_TaggedMessagePtr*)field_mem; + const upb_MiniTable* subm = + upb_MiniTableSub_Message(subs[f->UPB_PRIVATE(submsg_index)]); + if (submsg == 0) { + return; + } + if (--e->depth == 0) encode_err(e, kUpb_EncodeStatus_MaxDepthExceeded); + encode_TaggedMessagePtr(e, submsg, subm, &size); + encode_varint(e, size); + wire_type = kUpb_WireType_Delimited; + e->depth++; + break; + } + default: + UPB_UNREACHABLE(); + } +#undef CASE -upb_StringView upb_EnumDef_ReservedName(const upb_EnumDef* e, int i) { - UPB_ASSERT(0 <= i && i < e->res_name_count); - return e->res_names[i]; + encode_tag(e, f->UPB_PRIVATE(number), wire_type); } -int upb_EnumDef_ValueCount(const upb_EnumDef* e) { return e->value_count; } +static void encode_array(upb_encstate* e, const upb_Message* msg, + const upb_MiniTableSub* subs, + const upb_MiniTableField* f) { + const upb_Array* arr = *UPB_PTR_AT(msg, f->UPB_PRIVATE(offset), upb_Array*); + bool packed = upb_MiniTableField_IsPacked(f); + size_t pre_len = e->limit - e->ptr; -const upb_EnumValueDef* upb_EnumDef_FindValueByName(const upb_EnumDef* e, - const char* name) { - return upb_EnumDef_FindValueByNameWithSize(e, name, strlen(name)); -} + if (arr == NULL || arr->UPB_PRIVATE(size) == 0) { + return; + } -const upb_EnumValueDef* upb_EnumDef_FindValueByNameWithSize( - const upb_EnumDef* e, const char* name, size_t size) { - upb_value v; - return upb_strtable_lookup2(&e->ntoi, name, size, &v) - ? upb_value_getconstptr(v) - : NULL; -} +#define VARINT_CASE(ctype, encode) \ + { \ + const ctype* start = _upb_array_constptr(arr); \ + const ctype* ptr = start + arr->UPB_PRIVATE(size); \ + uint32_t tag = \ + packed ? 0 : (f->UPB_PRIVATE(number) << 3) | kUpb_WireType_Varint; \ + do { \ + ptr--; \ + encode_varint(e, encode); \ + if (tag) encode_varint(e, tag); \ + } while (ptr != start); \ + } \ + break; -const upb_EnumValueDef* upb_EnumDef_FindValueByNumber(const upb_EnumDef* e, - int32_t num) { - upb_value v; - return upb_inttable_lookup(&e->iton, num, &v) ? upb_value_getconstptr(v) - : NULL; -} +#define TAG(wire_type) (packed ? 0 : (f->UPB_PRIVATE(number) << 3 | wire_type)) -bool upb_EnumDef_CheckNumber(const upb_EnumDef* e, int32_t num) { - // We could use upb_EnumDef_FindValueByNumber(e, num) != NULL, but we expect - // this to be faster (especially for small numbers). - return upb_MiniTableEnum_CheckValue(e->layout, num); -} + switch (f->UPB_PRIVATE(descriptortype)) { + case kUpb_FieldType_Double: + encode_fixedarray(e, arr, sizeof(double), TAG(kUpb_WireType_64Bit)); + break; + case kUpb_FieldType_Float: + encode_fixedarray(e, arr, sizeof(float), TAG(kUpb_WireType_32Bit)); + break; + case kUpb_FieldType_SFixed64: + case kUpb_FieldType_Fixed64: + encode_fixedarray(e, arr, sizeof(uint64_t), TAG(kUpb_WireType_64Bit)); + break; + case kUpb_FieldType_Fixed32: + case kUpb_FieldType_SFixed32: + encode_fixedarray(e, arr, sizeof(uint32_t), TAG(kUpb_WireType_32Bit)); + break; + case kUpb_FieldType_Int64: + case kUpb_FieldType_UInt64: + VARINT_CASE(uint64_t, *ptr); + case kUpb_FieldType_UInt32: + VARINT_CASE(uint32_t, *ptr); + case kUpb_FieldType_Int32: + case kUpb_FieldType_Enum: + VARINT_CASE(int32_t, (int64_t)*ptr); + case kUpb_FieldType_Bool: + VARINT_CASE(bool, *ptr); + case kUpb_FieldType_SInt32: + VARINT_CASE(int32_t, encode_zz32(*ptr)); + case kUpb_FieldType_SInt64: + VARINT_CASE(int64_t, encode_zz64(*ptr)); + case kUpb_FieldType_String: + case kUpb_FieldType_Bytes: { + const upb_StringView* start = _upb_array_constptr(arr); + const upb_StringView* ptr = start + arr->UPB_PRIVATE(size); + do { + ptr--; + encode_bytes(e, ptr->data, ptr->size); + encode_varint(e, ptr->size); + encode_tag(e, f->UPB_PRIVATE(number), kUpb_WireType_Delimited); + } while (ptr != start); + return; + } + case kUpb_FieldType_Group: { + const upb_TaggedMessagePtr* start = _upb_array_constptr(arr); + const upb_TaggedMessagePtr* ptr = start + arr->UPB_PRIVATE(size); + const upb_MiniTable* subm = + upb_MiniTableSub_Message(subs[f->UPB_PRIVATE(submsg_index)]); + if (--e->depth == 0) encode_err(e, kUpb_EncodeStatus_MaxDepthExceeded); + do { + size_t size; + ptr--; + encode_tag(e, f->UPB_PRIVATE(number), kUpb_WireType_EndGroup); + encode_TaggedMessagePtr(e, *ptr, subm, &size); + encode_tag(e, f->UPB_PRIVATE(number), kUpb_WireType_StartGroup); + } while (ptr != start); + e->depth++; + return; + } + case kUpb_FieldType_Message: { + const upb_TaggedMessagePtr* start = _upb_array_constptr(arr); + const upb_TaggedMessagePtr* ptr = start + arr->UPB_PRIVATE(size); + const upb_MiniTable* subm = + upb_MiniTableSub_Message(subs[f->UPB_PRIVATE(submsg_index)]); + if (--e->depth == 0) encode_err(e, kUpb_EncodeStatus_MaxDepthExceeded); + do { + size_t size; + ptr--; + encode_TaggedMessagePtr(e, *ptr, subm, &size); + encode_varint(e, size); + encode_tag(e, f->UPB_PRIVATE(number), kUpb_WireType_Delimited); + } while (ptr != start); + e->depth++; + return; + } + } +#undef VARINT_CASE -const upb_EnumValueDef* upb_EnumDef_Value(const upb_EnumDef* e, int i) { - UPB_ASSERT(0 <= i && i < e->value_count); - return _upb_EnumValueDef_At(e->values, i); + if (packed) { + encode_varint(e, e->limit - e->ptr - pre_len); + encode_tag(e, f->UPB_PRIVATE(number), kUpb_WireType_Delimited); + } } -bool upb_EnumDef_IsClosed(const upb_EnumDef* e) { - if (UPB_TREAT_PROTO2_ENUMS_LIKE_PROTO3) return false; - return UPB_DESC(FeatureSet_enum_type)(e->resolved_features) == - UPB_DESC(FeatureSet_CLOSED); +static void encode_mapentry(upb_encstate* e, uint32_t number, + const upb_MiniTable* layout, + const upb_MapEntry* ent) { + const upb_MiniTableField* key_field = &layout->UPB_PRIVATE(fields)[0]; + const upb_MiniTableField* val_field = &layout->UPB_PRIVATE(fields)[1]; + size_t pre_len = e->limit - e->ptr; + size_t size; + encode_scalar(e, &ent->data.v, layout->UPB_PRIVATE(subs), val_field); + encode_scalar(e, &ent->data.k, layout->UPB_PRIVATE(subs), key_field); + size = (e->limit - e->ptr) - pre_len; + encode_varint(e, size); + encode_tag(e, number, kUpb_WireType_Delimited); } -bool upb_EnumDef_MiniDescriptorEncode(const upb_EnumDef* e, upb_Arena* a, - upb_StringView* out) { - upb_DescState s; - _upb_DescState_Init(&s); - - const upb_EnumValueDef** sorted = NULL; - if (!e->is_sorted) { - sorted = _upb_EnumValueDefs_Sorted(e->values, e->value_count, a); - if (!sorted) return false; - } - - if (!_upb_DescState_Grow(&s, a)) return false; - s.ptr = upb_MtDataEncoder_StartEnum(&s.e, s.ptr); - - // Duplicate values are allowed but we only encode each value once. - uint32_t previous = 0; +static void encode_map(upb_encstate* e, const upb_Message* msg, + const upb_MiniTableSub* subs, + const upb_MiniTableField* f) { + const upb_Map* map = *UPB_PTR_AT(msg, f->UPB_PRIVATE(offset), const upb_Map*); + const upb_MiniTable* layout = + upb_MiniTableSub_Message(subs[f->UPB_PRIVATE(submsg_index)]); + UPB_ASSERT(layout->UPB_PRIVATE(field_count) == 2); - for (int i = 0; i < e->value_count; i++) { - const uint32_t current = - upb_EnumValueDef_Number(sorted ? sorted[i] : upb_EnumDef_Value(e, i)); - if (i != 0 && previous == current) continue; + if (map == NULL) return; - if (!_upb_DescState_Grow(&s, a)) return false; - s.ptr = upb_MtDataEncoder_PutEnumValue(&s.e, s.ptr, current); - previous = current; + if (e->options & kUpb_EncodeOption_Deterministic) { + _upb_sortedmap sorted; + _upb_mapsorter_pushmap( + &e->sorter, layout->UPB_PRIVATE(fields)[0].UPB_PRIVATE(descriptortype), + map, &sorted); + upb_MapEntry ent; + while (_upb_sortedmap_next(&e->sorter, map, &sorted, &ent)) { + encode_mapentry(e, f->UPB_PRIVATE(number), layout, &ent); + } + _upb_mapsorter_popmap(&e->sorter, &sorted); + } else { + intptr_t iter = UPB_STRTABLE_BEGIN; + upb_StringView key; + upb_value val; + while (upb_strtable_next2(&map->table, &key, &val, &iter)) { + upb_MapEntry ent; + _upb_map_fromkey(key, &ent.data.k, map->key_size); + _upb_map_fromvalue(val, &ent.data.v, map->val_size); + encode_mapentry(e, f->UPB_PRIVATE(number), layout, &ent); + } } +} - if (!_upb_DescState_Grow(&s, a)) return false; - s.ptr = upb_MtDataEncoder_EndEnum(&s.e, s.ptr); - - // There will always be room for this '\0' in the encoder buffer because - // kUpb_MtDataEncoder_MinSize is overkill for upb_MtDataEncoder_EndEnum(). - UPB_ASSERT(s.ptr < s.buf + s.bufsize); - *s.ptr = '\0'; - - out->data = s.buf; - out->size = s.ptr - s.buf; - return true; +static bool encode_shouldencode(upb_encstate* e, const upb_Message* msg, + const upb_MiniTableSub* subs, + const upb_MiniTableField* f) { + if (f->presence == 0) { + // Proto3 presence or map/array. + const void* mem = UPB_PTR_AT(msg, f->UPB_PRIVATE(offset), void); + switch (UPB_PRIVATE(_upb_MiniTableField_GetRep)(f)) { + case kUpb_FieldRep_1Byte: { + char ch; + memcpy(&ch, mem, 1); + return ch != 0; + } + case kUpb_FieldRep_4Byte: { + uint32_t u32; + memcpy(&u32, mem, 4); + return u32 != 0; + } + case kUpb_FieldRep_8Byte: { + uint64_t u64; + memcpy(&u64, mem, 8); + return u64 != 0; + } + case kUpb_FieldRep_StringView: { + const upb_StringView* str = (const upb_StringView*)mem; + return str->size != 0; + } + default: + UPB_UNREACHABLE(); + } + } else if (f->presence > 0) { + // Proto2 presence: hasbit. + return UPB_PRIVATE(_upb_Message_GetHasbit)(msg, f); + } else { + // Field is in a oneof. + return UPB_PRIVATE(_upb_Message_GetOneofCase)(msg, f) == + f->UPB_PRIVATE(number); + } } -static upb_MiniTableEnum* create_enumlayout(upb_DefBuilder* ctx, - const upb_EnumDef* e) { - upb_StringView sv; - bool ok = upb_EnumDef_MiniDescriptorEncode(e, ctx->tmp_arena, &sv); - if (!ok) _upb_DefBuilder_Errf(ctx, "OOM while building enum MiniDescriptor"); +static void encode_field(upb_encstate* e, const upb_Message* msg, + const upb_MiniTableSub* subs, + const upb_MiniTableField* field) { + switch (UPB_PRIVATE(_upb_MiniTableField_Mode)(field)) { + case kUpb_FieldMode_Array: + encode_array(e, msg, subs, field); + break; + case kUpb_FieldMode_Map: + encode_map(e, msg, subs, field); + break; + case kUpb_FieldMode_Scalar: + encode_scalar(e, UPB_PTR_AT(msg, field->UPB_PRIVATE(offset), void), subs, + field); + break; + default: + UPB_UNREACHABLE(); + } +} - upb_Status status; - upb_MiniTableEnum* layout = - upb_MiniTableEnum_Build(sv.data, sv.size, ctx->arena, &status); - if (!layout) - _upb_DefBuilder_Errf(ctx, "Error building enum MiniTable: %s", status.msg); - return layout; +static void encode_msgset_item(upb_encstate* e, const upb_Extension* ext) { + size_t size; + encode_tag(e, kUpb_MsgSet_Item, kUpb_WireType_EndGroup); + encode_message(e, ext->data.ptr, + upb_MiniTableExtension_GetSubMessage(ext->ext), &size); + encode_varint(e, size); + encode_tag(e, kUpb_MsgSet_Message, kUpb_WireType_Delimited); + encode_varint(e, upb_MiniTableExtension_Number(ext->ext)); + encode_tag(e, kUpb_MsgSet_TypeId, kUpb_WireType_Varint); + encode_tag(e, kUpb_MsgSet_Item, kUpb_WireType_StartGroup); } -static upb_StringView* _upb_EnumReservedNames_New( - upb_DefBuilder* ctx, int n, const upb_StringView* protos) { - upb_StringView* sv = _upb_DefBuilder_Alloc(ctx, sizeof(upb_StringView) * n); - for (int i = 0; i < n; i++) { - sv[i].data = - upb_strdup2(protos[i].data, protos[i].size, _upb_DefBuilder_Arena(ctx)); - sv[i].size = protos[i].size; +static void encode_ext(upb_encstate* e, const upb_Extension* ext, + bool is_message_set) { + if (UPB_UNLIKELY(is_message_set)) { + encode_msgset_item(e, ext); + } else { + encode_field(e, (upb_Message*)&ext->data, &ext->ext->UPB_PRIVATE(sub), + &ext->ext->UPB_PRIVATE(field)); } - return sv; } -static void create_enumdef(upb_DefBuilder* ctx, const char* prefix, - const UPB_DESC(EnumDescriptorProto) * enum_proto, - const UPB_DESC(FeatureSet*) parent_features, - upb_EnumDef* e) { - const UPB_DESC(EnumValueDescriptorProto)* const* values; - const UPB_DESC(EnumDescriptorProto_EnumReservedRange)* const* res_ranges; - const upb_StringView* res_names; - upb_StringView name; - size_t n_value, n_res_range, n_res_name; - - UPB_DEF_SET_OPTIONS(e->opts, EnumDescriptorProto, EnumOptions, enum_proto); - e->resolved_features = _upb_DefBuilder_ResolveFeatures( - ctx, parent_features, UPB_DESC(EnumOptions_features)(e->opts)); - - // Must happen before _upb_DefBuilder_Add() - e->file = _upb_DefBuilder_File(ctx); - - name = UPB_DESC(EnumDescriptorProto_name)(enum_proto); - - e->full_name = _upb_DefBuilder_MakeFullName(ctx, prefix, name); - _upb_DefBuilder_Add(ctx, e->full_name, - _upb_DefType_Pack(e, UPB_DEFTYPE_ENUM)); - - values = UPB_DESC(EnumDescriptorProto_value)(enum_proto, &n_value); - - bool ok = upb_strtable_init(&e->ntoi, n_value, ctx->arena); - if (!ok) _upb_DefBuilder_OomErr(ctx); +static void encode_message(upb_encstate* e, const upb_Message* msg, + const upb_MiniTable* m, size_t* size) { + size_t pre_len = e->limit - e->ptr; - ok = upb_inttable_init(&e->iton, ctx->arena); - if (!ok) _upb_DefBuilder_OomErr(ctx); + if ((e->options & kUpb_EncodeOption_CheckRequired) && + m->UPB_PRIVATE(required_count)) { + uint64_t msg_head; + memcpy(&msg_head, msg, 8); + msg_head = UPB_PRIVATE(_upb_BigEndian64)(msg_head); + if (UPB_PRIVATE(_upb_MiniTable_RequiredMask)(m) & ~msg_head) { + encode_err(e, kUpb_EncodeStatus_MissingRequired); + } + } - e->defaultval = 0; - e->value_count = n_value; - e->values = _upb_EnumValueDefs_New(ctx, prefix, n_value, values, - e->resolved_features, e, &e->is_sorted); + if ((e->options & kUpb_EncodeOption_SkipUnknown) == 0) { + size_t unknown_size; + const char* unknown = upb_Message_GetUnknown(msg, &unknown_size); - if (n_value == 0) { - _upb_DefBuilder_Errf(ctx, "enums must contain at least one value (%s)", - e->full_name); + if (unknown) { + encode_bytes(e, unknown, unknown_size); + } } - res_ranges = - UPB_DESC(EnumDescriptorProto_reserved_range)(enum_proto, &n_res_range); - e->res_range_count = n_res_range; - e->res_ranges = _upb_EnumReservedRanges_New(ctx, n_res_range, res_ranges, e); + if (m->UPB_PRIVATE(ext) != kUpb_ExtMode_NonExtendable) { + /* Encode all extensions together. Unlike C++, we do not attempt to keep + * these in field number order relative to normal fields or even to each + * other. */ + size_t ext_count; + const upb_Extension* ext = + UPB_PRIVATE(_upb_Message_Getexts)(msg, &ext_count); + if (ext_count) { + if (e->options & kUpb_EncodeOption_Deterministic) { + _upb_sortedmap sorted; + _upb_mapsorter_pushexts(&e->sorter, ext, ext_count, &sorted); + while (_upb_sortedmap_nextext(&e->sorter, &sorted, &ext)) { + encode_ext(e, ext, m->UPB_PRIVATE(ext) == kUpb_ExtMode_IsMessageSet); + } + _upb_mapsorter_popmap(&e->sorter, &sorted); + } else { + const upb_Extension* end = ext + ext_count; + for (; ext != end; ext++) { + encode_ext(e, ext, m->UPB_PRIVATE(ext) == kUpb_ExtMode_IsMessageSet); + } + } + } + } - res_names = - UPB_DESC(EnumDescriptorProto_reserved_name)(enum_proto, &n_res_name); - e->res_name_count = n_res_name; - e->res_names = _upb_EnumReservedNames_New(ctx, n_res_name, res_names); + if (m->UPB_PRIVATE(field_count)) { + const upb_MiniTableField* f = + &m->UPB_PRIVATE(fields)[m->UPB_PRIVATE(field_count)]; + const upb_MiniTableField* first = &m->UPB_PRIVATE(fields)[0]; + while (f != first) { + f--; + if (encode_shouldencode(e, msg, m->UPB_PRIVATE(subs), f)) { + encode_field(e, msg, m->UPB_PRIVATE(subs), f); + } + } + } - upb_inttable_compact(&e->iton, ctx->arena); + *size = (e->limit - e->ptr) - pre_len; +} - if (upb_EnumDef_IsClosed(e)) { - if (ctx->layout) { - e->layout = upb_MiniTableFile_Enum(ctx->layout, ctx->enum_count++); +static upb_EncodeStatus upb_Encoder_Encode(upb_encstate* const encoder, + const upb_Message* const msg, + const upb_MiniTable* const l, + char** const buf, + size_t* const size) { + // Unfortunately we must continue to perform hackery here because there are + // code paths which blindly copy the returned pointer without bothering to + // check for errors until much later (b/235839510). So we still set *buf to + // NULL on error and we still set it to non-NULL on a successful empty result. + if (UPB_SETJMP(encoder->err) == 0) { + encode_message(encoder, msg, l, size); + *size = encoder->limit - encoder->ptr; + if (*size == 0) { + static char ch; + *buf = &ch; } else { - e->layout = create_enumlayout(ctx, e); + UPB_ASSERT(encoder->ptr); + *buf = encoder->ptr; } } else { - e->layout = NULL; + UPB_ASSERT(encoder->status != kUpb_EncodeStatus_Ok); + *buf = NULL; + *size = 0; } + + _upb_mapsorter_destroy(&encoder->sorter); + return encoder->status; } -upb_EnumDef* _upb_EnumDefs_New(upb_DefBuilder* ctx, int n, - const UPB_DESC(EnumDescriptorProto*) - const* protos, - const UPB_DESC(FeatureSet*) parent_features, - const upb_MessageDef* containing_type) { - _upb_DefType_CheckPadding(sizeof(upb_EnumDef)); +upb_EncodeStatus upb_Encode(const upb_Message* msg, const upb_MiniTable* l, + int options, upb_Arena* arena, char** buf, + size_t* size) { + upb_encstate e; + unsigned depth = (unsigned)options >> 16; - // If a containing type is defined then get the full name from that. - // Otherwise use the package name from the file def. - const char* name = containing_type ? upb_MessageDef_FullName(containing_type) - : _upb_FileDef_RawPackage(ctx->file); + e.status = kUpb_EncodeStatus_Ok; + e.arena = arena; + e.buf = NULL; + e.limit = NULL; + e.ptr = NULL; + e.depth = depth ? depth : kUpb_WireFormat_DefaultDepthLimit; + e.options = options; + _upb_mapsorter_init(&e.sorter); - upb_EnumDef* e = _upb_DefBuilder_Alloc(ctx, sizeof(upb_EnumDef) * n); - for (int i = 0; i < n; i++) { - create_enumdef(ctx, name, protos[i], parent_features, &e[i]); - e[i].containing_type = containing_type; - } - return e; + return upb_Encoder_Encode(&e, msg, l, buf, size); } +// Fast decoder: ~3x the speed of decode.c, but requires x86-64/ARM64. +// Also the table size grows by 2x. +// +// Could potentially be ported to other 64-bit archs that pass at least six +// arguments in registers and have 8 unused high bits in pointers. +// +// The overall design is to create specialized functions for every possible +// field type (eg. oneof boolean field with a 1 byte tag) and then dispatch +// to the specialized function as quickly as possible. + // Must be last. -struct upb_EnumReservedRange { - int32_t start; - int32_t end; -}; - -upb_EnumReservedRange* _upb_EnumReservedRange_At(const upb_EnumReservedRange* r, - int i) { - return (upb_EnumReservedRange*)&r[i]; -} +#if UPB_FASTTABLE -int32_t upb_EnumReservedRange_Start(const upb_EnumReservedRange* r) { - return r->start; -} -int32_t upb_EnumReservedRange_End(const upb_EnumReservedRange* r) { - return r->end; -} +// The standard set of arguments passed to each parsing function. +// Thanks to x86-64 calling conventions, these will stay in registers. +#define UPB_PARSE_PARAMS \ + upb_Decoder *d, const char *ptr, upb_Message *msg, intptr_t table, \ + uint64_t hasbits, uint64_t data -upb_EnumReservedRange* _upb_EnumReservedRanges_New( - upb_DefBuilder* ctx, int n, - const UPB_DESC(EnumDescriptorProto_EnumReservedRange) * const* protos, - const upb_EnumDef* e) { - upb_EnumReservedRange* r = - _upb_DefBuilder_Alloc(ctx, sizeof(upb_EnumReservedRange) * n); +#define UPB_PARSE_ARGS d, ptr, msg, table, hasbits, data - for (int i = 0; i < n; i++) { - const int32_t start = - UPB_DESC(EnumDescriptorProto_EnumReservedRange_start)(protos[i]); - const int32_t end = - UPB_DESC(EnumDescriptorProto_EnumReservedRange_end)(protos[i]); +#define RETURN_GENERIC(m) \ + /* Uncomment either of these for debugging purposes. */ \ + /* fprintf(stderr, m); */ \ + /*__builtin_trap(); */ \ + return _upb_FastDecoder_DecodeGeneric(d, ptr, msg, table, hasbits, 0); - // A full validation would also check that each range is disjoint, and that - // none of the fields overlap with the extension ranges, but we are just - // sanity checking here. +typedef enum { + CARD_s = 0, /* Singular (optional, non-repeated) */ + CARD_o = 1, /* Oneof */ + CARD_r = 2, /* Repeated */ + CARD_p = 3 /* Packed Repeated */ +} upb_card; - // Note: Not a typo! Unlike extension ranges and message reserved ranges, - // the end value of an enum reserved range is *inclusive*! - if (end < start) { - _upb_DefBuilder_Errf(ctx, "Reserved range (%d, %d) is invalid, enum=%s\n", - (int)start, (int)end, upb_EnumDef_FullName(e)); - } +UPB_NOINLINE +static const char* fastdecode_isdonefallback(UPB_PARSE_PARAMS) { + int overrun = data; + ptr = _upb_EpsCopyInputStream_IsDoneFallbackInline( + &d->input, ptr, overrun, _upb_Decoder_BufferFlipCallback); + data = _upb_FastDecoder_LoadTag(ptr); + UPB_MUSTTAIL return _upb_FastDecoder_TagDispatch(UPB_PARSE_ARGS); +} - r[i].start = start; - r[i].end = end; +UPB_FORCEINLINE +static const char* fastdecode_dispatch(UPB_PARSE_PARAMS) { + int overrun; + switch (upb_EpsCopyInputStream_IsDoneStatus(&d->input, ptr, &overrun)) { + case kUpb_IsDoneStatus_Done: + *(uint32_t*)msg |= hasbits; // Sync hasbits. + const upb_MiniTable* m = decode_totablep(table); + return UPB_UNLIKELY(m->UPB_PRIVATE(required_count)) + ? _upb_Decoder_CheckRequired(d, ptr, msg, m) + : ptr; + case kUpb_IsDoneStatus_NotDone: + break; + case kUpb_IsDoneStatus_NeedFallback: + data = overrun; + UPB_MUSTTAIL return fastdecode_isdonefallback(UPB_PARSE_ARGS); } - return r; + // Read two bytes of tag data (for a one-byte tag, the high byte is junk). + data = _upb_FastDecoder_LoadTag(ptr); + UPB_MUSTTAIL return _upb_FastDecoder_TagDispatch(UPB_PARSE_ARGS); } +UPB_FORCEINLINE +static bool fastdecode_checktag(uint16_t data, int tagbytes) { + if (tagbytes == 1) { + return (data & 0xff) == 0; + } else { + return data == 0; + } +} -#include - +UPB_FORCEINLINE +static const char* fastdecode_longsize(const char* ptr, int* size) { + int i; + UPB_ASSERT(*size & 0x80); + *size &= 0xff; + for (i = 0; i < 3; i++) { + ptr++; + size_t byte = (uint8_t)ptr[-1]; + *size += (byte - 1) << (7 + 7 * i); + if (UPB_LIKELY((byte & 0x80) == 0)) return ptr; + } + ptr++; + size_t byte = (uint8_t)ptr[-1]; + // len is limited by 2gb not 4gb, hence 8 and not 16 as normally expected + // for a 32 bit varint. + if (UPB_UNLIKELY(byte >= 8)) return NULL; + *size += (byte - 1) << 28; + return ptr; +} -// Must be last. +UPB_FORCEINLINE +static const char* fastdecode_delimited( + upb_Decoder* d, const char* ptr, + upb_EpsCopyInputStream_ParseDelimitedFunc* func, void* ctx) { + ptr++; -struct upb_EnumValueDef { - const UPB_DESC(EnumValueOptions*) opts; - const UPB_DESC(FeatureSet*) resolved_features; - const upb_EnumDef* parent; - const char* full_name; - int32_t number; -#if UINTPTR_MAX == 0xffffffff - uint32_t padding; // Increase size to a multiple of 8. -#endif -}; + // Sign-extend so varint greater than one byte becomes negative, causing + // fast delimited parse to fail. + int len = (int8_t)ptr[-1]; -upb_EnumValueDef* _upb_EnumValueDef_At(const upb_EnumValueDef* v, int i) { - return (upb_EnumValueDef*)&v[i]; + if (!upb_EpsCopyInputStream_TryParseDelimitedFast(&d->input, &ptr, len, func, + ctx)) { + // Slow case: Sub-message is >=128 bytes and/or exceeds the current buffer. + // If it exceeds the buffer limit, limit/limit_ptr will change during + // sub-message parsing, so we need to preserve delta, not limit. + if (UPB_UNLIKELY(len & 0x80)) { + // Size varint >1 byte (length >= 128). + ptr = fastdecode_longsize(ptr, &len); + if (!ptr) { + // Corrupt wire format: size exceeded INT_MAX. + return NULL; + } + } + if (!upb_EpsCopyInputStream_CheckSize(&d->input, ptr, len)) { + // Corrupt wire format: invalid limit. + return NULL; + } + int delta = upb_EpsCopyInputStream_PushLimit(&d->input, ptr, len); + ptr = func(&d->input, ptr, ctx); + upb_EpsCopyInputStream_PopLimit(&d->input, ptr, delta); + } + return ptr; } -static int _upb_EnumValueDef_Compare(const void* p1, const void* p2) { - const uint32_t v1 = (*(const upb_EnumValueDef**)p1)->number; - const uint32_t v2 = (*(const upb_EnumValueDef**)p2)->number; - return (v1 < v2) ? -1 : (v1 > v2); -} +/* singular, oneof, repeated field handling ***********************************/ -const upb_EnumValueDef** _upb_EnumValueDefs_Sorted(const upb_EnumValueDef* v, - int n, upb_Arena* a) { - // TODO: Try to replace this arena alloc with a persistent scratch buffer. - upb_EnumValueDef** out = - (upb_EnumValueDef**)upb_Arena_Malloc(a, n * sizeof(void*)); - if (!out) return NULL; +typedef struct { + upb_Array* arr; + void* end; +} fastdecode_arr; - for (int i = 0; i < n; i++) { - out[i] = (upb_EnumValueDef*)&v[i]; - } - qsort(out, n, sizeof(void*), _upb_EnumValueDef_Compare); +typedef enum { + FD_NEXT_ATLIMIT, + FD_NEXT_SAMEFIELD, + FD_NEXT_OTHERFIELD +} fastdecode_next; - return (const upb_EnumValueDef**)out; -} +typedef struct { + void* dst; + fastdecode_next next; + uint32_t tag; +} fastdecode_nextret; -const UPB_DESC(EnumValueOptions) * - upb_EnumValueDef_Options(const upb_EnumValueDef* v) { - return v->opts; +UPB_FORCEINLINE +static void* fastdecode_resizearr(upb_Decoder* d, void* dst, + fastdecode_arr* farr, int valbytes) { + if (UPB_UNLIKELY(dst == farr->end)) { + size_t old_capacity = farr->arr->UPB_PRIVATE(capacity); + size_t old_bytes = old_capacity * valbytes; + size_t new_capacity = old_capacity * 2; + size_t new_bytes = new_capacity * valbytes; + char* old_ptr = _upb_array_ptr(farr->arr); + char* new_ptr = upb_Arena_Realloc(&d->arena, old_ptr, old_bytes, new_bytes); + uint8_t elem_size_lg2 = __builtin_ctz(valbytes); + UPB_PRIVATE(_upb_Array_SetTaggedPtr)(farr->arr, new_ptr, elem_size_lg2); + farr->arr->UPB_PRIVATE(capacity) = new_capacity; + dst = (void*)(new_ptr + (old_capacity * valbytes)); + farr->end = (void*)(new_ptr + (new_capacity * valbytes)); + } + return dst; } -bool upb_EnumValueDef_HasOptions(const upb_EnumValueDef* v) { - return v->opts != (void*)kUpbDefOptDefault; +UPB_FORCEINLINE +static bool fastdecode_tagmatch(uint32_t tag, uint64_t data, int tagbytes) { + if (tagbytes == 1) { + return (uint8_t)tag == (uint8_t)data; + } else { + return (uint16_t)tag == (uint16_t)data; + } } -const UPB_DESC(FeatureSet) * - upb_EnumValueDef_ResolvedFeatures(const upb_EnumValueDef* e) { - return e->resolved_features; +UPB_FORCEINLINE +static void fastdecode_commitarr(void* dst, fastdecode_arr* farr, + int valbytes) { + farr->arr->UPB_PRIVATE(size) = + (size_t)((char*)dst - (char*)_upb_array_ptr(farr->arr)) / valbytes; } -const upb_EnumDef* upb_EnumValueDef_Enum(const upb_EnumValueDef* v) { - return v->parent; -} +UPB_FORCEINLINE +static fastdecode_nextret fastdecode_nextrepeated(upb_Decoder* d, void* dst, + const char** ptr, + fastdecode_arr* farr, + uint64_t data, int tagbytes, + int valbytes) { + fastdecode_nextret ret; + dst = (char*)dst + valbytes; -const char* upb_EnumValueDef_FullName(const upb_EnumValueDef* v) { - return v->full_name; -} + if (UPB_LIKELY(!_upb_Decoder_IsDone(d, ptr))) { + ret.tag = _upb_FastDecoder_LoadTag(*ptr); + if (fastdecode_tagmatch(ret.tag, data, tagbytes)) { + ret.next = FD_NEXT_SAMEFIELD; + } else { + fastdecode_commitarr(dst, farr, valbytes); + ret.next = FD_NEXT_OTHERFIELD; + } + } else { + fastdecode_commitarr(dst, farr, valbytes); + ret.next = FD_NEXT_ATLIMIT; + } -const char* upb_EnumValueDef_Name(const upb_EnumValueDef* v) { - return _upb_DefBuilder_FullToShort(v->full_name); + ret.dst = dst; + return ret; } -int32_t upb_EnumValueDef_Number(const upb_EnumValueDef* v) { return v->number; } - -uint32_t upb_EnumValueDef_Index(const upb_EnumValueDef* v) { - // Compute index in our parent's array. - return v - upb_EnumDef_Value(v->parent, 0); +UPB_FORCEINLINE +static void* fastdecode_fieldmem(upb_Message* msg, uint64_t data) { + size_t ofs = data >> 48; + return (char*)msg + ofs; } -static void create_enumvaldef(upb_DefBuilder* ctx, const char* prefix, - const UPB_DESC(EnumValueDescriptorProto*) - val_proto, - const UPB_DESC(FeatureSet*) parent_features, - upb_EnumDef* e, upb_EnumValueDef* v) { - UPB_DEF_SET_OPTIONS(v->opts, EnumValueDescriptorProto, EnumValueOptions, - val_proto); - v->resolved_features = _upb_DefBuilder_ResolveFeatures( - ctx, parent_features, UPB_DESC(EnumValueOptions_features)(v->opts)); - - upb_StringView name = UPB_DESC(EnumValueDescriptorProto_name)(val_proto); - - v->parent = e; // Must happen prior to _upb_DefBuilder_Add() - v->full_name = _upb_DefBuilder_MakeFullName(ctx, prefix, name); - v->number = UPB_DESC(EnumValueDescriptorProto_number)(val_proto); - _upb_DefBuilder_Add(ctx, v->full_name, - _upb_DefType_Pack(v, UPB_DEFTYPE_ENUMVAL)); - - bool ok = _upb_EnumDef_Insert(e, v, ctx->arena); - if (!ok) _upb_DefBuilder_OomErr(ctx); +UPB_FORCEINLINE +static void* fastdecode_getfield(upb_Decoder* d, const char* ptr, + upb_Message* msg, uint64_t* data, + uint64_t* hasbits, fastdecode_arr* farr, + int valbytes, upb_card card) { + switch (card) { + case CARD_s: { + uint8_t hasbit_index = *data >> 24; + // Set hasbit and return pointer to scalar field. + *hasbits |= 1ull << hasbit_index; + return fastdecode_fieldmem(msg, *data); + } + case CARD_o: { + uint16_t case_ofs = *data >> 32; + uint32_t* oneof_case = UPB_PTR_AT(msg, case_ofs, uint32_t); + uint8_t field_number = *data >> 24; + *oneof_case = field_number; + return fastdecode_fieldmem(msg, *data); + } + case CARD_r: { + // Get pointer to upb_Array and allocate/expand if necessary. + uint8_t elem_size_lg2 = __builtin_ctz(valbytes); + upb_Array** arr_p = fastdecode_fieldmem(msg, *data); + char* begin; + *(uint32_t*)msg |= *hasbits; + *hasbits = 0; + if (UPB_LIKELY(!*arr_p)) { + farr->arr = UPB_PRIVATE(_upb_Array_New)(&d->arena, 8, elem_size_lg2); + *arr_p = farr->arr; + } else { + farr->arr = *arr_p; + } + begin = _upb_array_ptr(farr->arr); + farr->end = begin + (farr->arr->UPB_PRIVATE(capacity) * valbytes); + *data = _upb_FastDecoder_LoadTag(ptr); + return begin + (farr->arr->UPB_PRIVATE(size) * valbytes); + } + default: + UPB_UNREACHABLE(); + } } -static void _upb_EnumValueDef_CheckZeroValue(upb_DefBuilder* ctx, - const upb_EnumDef* e, - const upb_EnumValueDef* v, int n) { - if (upb_EnumDef_IsClosed(e) || n == 0 || v[0].number == 0) return; +UPB_FORCEINLINE +static bool fastdecode_flippacked(uint64_t* data, int tagbytes) { + *data ^= (0x2 ^ 0x0); // Patch data to match packed wiretype. + return fastdecode_checktag(*data, tagbytes); +} - // When the special UPB_TREAT_PROTO2_ENUMS_LIKE_PROTO3 is enabled, we have to - // exempt proto2 enums from this check, even when we are treating them as - // open. - if (UPB_TREAT_PROTO2_ENUMS_LIKE_PROTO3 && - upb_FileDef_Syntax(upb_EnumDef_File(e)) == kUpb_Syntax_Proto2) { - return; +#define FASTDECODE_CHECKPACKED(tagbytes, card, func) \ + if (UPB_UNLIKELY(!fastdecode_checktag(data, tagbytes))) { \ + if (card == CARD_r && fastdecode_flippacked(&data, tagbytes)) { \ + UPB_MUSTTAIL return func(UPB_PARSE_ARGS); \ + } \ + RETURN_GENERIC("packed check tag mismatch\n"); \ } - _upb_DefBuilder_Errf(ctx, "for open enums, the first value must be zero (%s)", - upb_EnumDef_FullName(e)); -} +/* varint fields **************************************************************/ -// Allocate and initialize an array of |n| enum value defs owned by |e|. -upb_EnumValueDef* _upb_EnumValueDefs_New( - upb_DefBuilder* ctx, const char* prefix, int n, - const UPB_DESC(EnumValueDescriptorProto*) const* protos, - const UPB_DESC(FeatureSet*) parent_features, upb_EnumDef* e, - bool* is_sorted) { - _upb_DefType_CheckPadding(sizeof(upb_EnumValueDef)); - - upb_EnumValueDef* v = - _upb_DefBuilder_Alloc(ctx, sizeof(upb_EnumValueDef) * n); - - *is_sorted = true; - uint32_t previous = 0; - for (int i = 0; i < n; i++) { - create_enumvaldef(ctx, prefix, protos[i], parent_features, e, &v[i]); - - const uint32_t current = v[i].number; - if (previous > current) *is_sorted = false; - previous = current; +UPB_FORCEINLINE +static uint64_t fastdecode_munge(uint64_t val, int valbytes, bool zigzag) { + if (valbytes == 1) { + return val != 0; + } else if (zigzag) { + if (valbytes == 4) { + uint32_t n = val; + return (n >> 1) ^ -(int32_t)(n & 1); + } else if (valbytes == 8) { + return (val >> 1) ^ -(int64_t)(val & 1); + } + UPB_UNREACHABLE(); } - - _upb_EnumValueDef_CheckZeroValue(ctx, e, v, n); - - return v; + return val; } +UPB_FORCEINLINE +static const char* fastdecode_varint64(const char* ptr, uint64_t* val) { + ptr++; + *val = (uint8_t)ptr[-1]; + if (UPB_UNLIKELY(*val & 0x80)) { + int i; + for (i = 0; i < 8; i++) { + ptr++; + uint64_t byte = (uint8_t)ptr[-1]; + *val += (byte - 1) << (7 + 7 * i); + if (UPB_LIKELY((byte & 0x80) == 0)) goto done; + } + ptr++; + uint64_t byte = (uint8_t)ptr[-1]; + if (byte > 1) { + return NULL; + } + *val += (byte - 1) << 63; + } +done: + UPB_ASSUME(ptr != NULL); + return ptr; +} -#include - - -// Must be last. - -struct upb_ExtensionRange { - const UPB_DESC(ExtensionRangeOptions*) opts; - const UPB_DESC(FeatureSet*) resolved_features; - int32_t start; - int32_t end; -}; +#define FASTDECODE_UNPACKEDVARINT(d, ptr, msg, table, hasbits, data, tagbytes, \ + valbytes, card, zigzag, packed) \ + uint64_t val; \ + void* dst; \ + fastdecode_arr farr; \ + \ + FASTDECODE_CHECKPACKED(tagbytes, card, packed); \ + \ + dst = fastdecode_getfield(d, ptr, msg, &data, &hasbits, &farr, valbytes, \ + card); \ + if (card == CARD_r) { \ + if (UPB_UNLIKELY(!dst)) { \ + RETURN_GENERIC("need array resize\n"); \ + } \ + } \ + \ + again: \ + if (card == CARD_r) { \ + dst = fastdecode_resizearr(d, dst, &farr, valbytes); \ + } \ + \ + ptr += tagbytes; \ + ptr = fastdecode_varint64(ptr, &val); \ + if (ptr == NULL) _upb_FastDecoder_ErrorJmp(d, kUpb_DecodeStatus_Malformed); \ + val = fastdecode_munge(val, valbytes, zigzag); \ + memcpy(dst, &val, valbytes); \ + \ + if (card == CARD_r) { \ + fastdecode_nextret ret = fastdecode_nextrepeated( \ + d, dst, &ptr, &farr, data, tagbytes, valbytes); \ + switch (ret.next) { \ + case FD_NEXT_SAMEFIELD: \ + dst = ret.dst; \ + goto again; \ + case FD_NEXT_OTHERFIELD: \ + data = ret.tag; \ + UPB_MUSTTAIL return _upb_FastDecoder_TagDispatch(UPB_PARSE_ARGS); \ + case FD_NEXT_ATLIMIT: \ + return ptr; \ + } \ + } \ + \ + UPB_MUSTTAIL return fastdecode_dispatch(UPB_PARSE_ARGS); -upb_ExtensionRange* _upb_ExtensionRange_At(const upb_ExtensionRange* r, int i) { - return (upb_ExtensionRange*)&r[i]; -} +typedef struct { + uint8_t valbytes; + bool zigzag; + void* dst; + fastdecode_arr farr; +} fastdecode_varintdata; -const UPB_DESC(ExtensionRangeOptions) * - upb_ExtensionRange_Options(const upb_ExtensionRange* r) { - return r->opts; -} +UPB_FORCEINLINE +static const char* fastdecode_topackedvarint(upb_EpsCopyInputStream* e, + const char* ptr, void* ctx) { + upb_Decoder* d = (upb_Decoder*)e; + fastdecode_varintdata* data = ctx; + void* dst = data->dst; + uint64_t val; -bool upb_ExtensionRange_HasOptions(const upb_ExtensionRange* r) { - return r->opts != (void*)kUpbDefOptDefault; -} + while (!_upb_Decoder_IsDone(d, &ptr)) { + dst = fastdecode_resizearr(d, dst, &data->farr, data->valbytes); + ptr = fastdecode_varint64(ptr, &val); + if (ptr == NULL) return NULL; + val = fastdecode_munge(val, data->valbytes, data->zigzag); + memcpy(dst, &val, data->valbytes); + dst = (char*)dst + data->valbytes; + } -int32_t upb_ExtensionRange_Start(const upb_ExtensionRange* r) { - return r->start; + fastdecode_commitarr(dst, &data->farr, data->valbytes); + return ptr; } -int32_t upb_ExtensionRange_End(const upb_ExtensionRange* r) { return r->end; } - -upb_ExtensionRange* _upb_ExtensionRanges_New( - upb_DefBuilder* ctx, int n, - const UPB_DESC(DescriptorProto_ExtensionRange*) const* protos, - const UPB_DESC(FeatureSet*) parent_features, const upb_MessageDef* m) { - upb_ExtensionRange* r = - _upb_DefBuilder_Alloc(ctx, sizeof(upb_ExtensionRange) * n); +#define FASTDECODE_PACKEDVARINT(d, ptr, msg, table, hasbits, data, tagbytes, \ + valbytes, zigzag, unpacked) \ + fastdecode_varintdata ctx = {valbytes, zigzag}; \ + \ + FASTDECODE_CHECKPACKED(tagbytes, CARD_r, unpacked); \ + \ + ctx.dst = fastdecode_getfield(d, ptr, msg, &data, &hasbits, &ctx.farr, \ + valbytes, CARD_r); \ + if (UPB_UNLIKELY(!ctx.dst)) { \ + RETURN_GENERIC("need array resize\n"); \ + } \ + \ + ptr += tagbytes; \ + ptr = fastdecode_delimited(d, ptr, &fastdecode_topackedvarint, &ctx); \ + \ + if (UPB_UNLIKELY(ptr == NULL)) { \ + _upb_FastDecoder_ErrorJmp(d, kUpb_DecodeStatus_Malformed); \ + } \ + \ + UPB_MUSTTAIL return fastdecode_dispatch(d, ptr, msg, table, hasbits, 0); - for (int i = 0; i < n; i++) { - UPB_DEF_SET_OPTIONS(r[i].opts, DescriptorProto_ExtensionRange, - ExtensionRangeOptions, protos[i]); - r[i].resolved_features = _upb_DefBuilder_ResolveFeatures( - ctx, parent_features, - UPB_DESC(ExtensionRangeOptions_features)(r[i].opts)); +#define FASTDECODE_VARINT(d, ptr, msg, table, hasbits, data, tagbytes, \ + valbytes, card, zigzag, unpacked, packed) \ + if (card == CARD_p) { \ + FASTDECODE_PACKEDVARINT(d, ptr, msg, table, hasbits, data, tagbytes, \ + valbytes, zigzag, unpacked); \ + } else { \ + FASTDECODE_UNPACKEDVARINT(d, ptr, msg, table, hasbits, data, tagbytes, \ + valbytes, card, zigzag, packed); \ + } - const int32_t start = - UPB_DESC(DescriptorProto_ExtensionRange_start)(protos[i]); - const int32_t end = UPB_DESC(DescriptorProto_ExtensionRange_end)(protos[i]); - const int32_t max = UPB_DESC(MessageOptions_message_set_wire_format)( - upb_MessageDef_Options(m)) - ? INT32_MAX - : kUpb_MaxFieldNumber + 1; +#define z_ZZ true +#define b_ZZ false +#define v_ZZ false - // A full validation would also check that each range is disjoint, and that - // none of the fields overlap with the extension ranges, but we are just - // sanity checking here. - if (start < 1 || end <= start || end > max) { - _upb_DefBuilder_Errf(ctx, - "Extension range (%d, %d) is invalid, message=%s\n", - (int)start, (int)end, upb_MessageDef_FullName(m)); - } +/* Generate all combinations: + * {s,o,r,p} x {b1,v4,z4,v8,z8} x {1bt,2bt} */ - r[i].start = start; - r[i].end = end; +#define F(card, type, valbytes, tagbytes) \ + UPB_NOINLINE \ + const char* upb_p##card##type##valbytes##_##tagbytes##bt(UPB_PARSE_PARAMS) { \ + FASTDECODE_VARINT(d, ptr, msg, table, hasbits, data, tagbytes, valbytes, \ + CARD_##card, type##_ZZ, \ + upb_pr##type##valbytes##_##tagbytes##bt, \ + upb_pp##type##valbytes##_##tagbytes##bt); \ } - return r; -} - +#define TYPES(card, tagbytes) \ + F(card, b, 1, tagbytes) \ + F(card, v, 4, tagbytes) \ + F(card, v, 8, tagbytes) \ + F(card, z, 4, tagbytes) \ + F(card, z, 8, tagbytes) -#include -#include -#include -#include -#include -#include +#define TAGBYTES(card) \ + TYPES(card, 1) \ + TYPES(card, 2) +TAGBYTES(s) +TAGBYTES(o) +TAGBYTES(r) +TAGBYTES(p) -// Must be last. +#undef z_ZZ +#undef b_ZZ +#undef v_ZZ +#undef o_ONEOF +#undef s_ONEOF +#undef r_ONEOF +#undef F +#undef TYPES +#undef TAGBYTES +#undef FASTDECODE_UNPACKEDVARINT +#undef FASTDECODE_PACKEDVARINT +#undef FASTDECODE_VARINT -#define UPB_FIELD_TYPE_UNSPECIFIED 0 +/* fixed fields ***************************************************************/ -typedef struct { - size_t len; - char str[1]; // Null-terminated string data follows. -} str_t; - -struct upb_FieldDef { - const UPB_DESC(FieldOptions*) opts; - const UPB_DESC(FeatureSet*) resolved_features; - const upb_FileDef* file; - const upb_MessageDef* msgdef; - const char* full_name; - const char* json_name; - union { - int64_t sint; - uint64_t uint; - double dbl; - float flt; - bool boolean; - str_t* str; - void* msg; // Always NULL. - } defaultval; - union { - const upb_OneofDef* oneof; - const upb_MessageDef* extension_scope; - } scope; - union { - const upb_MessageDef* msgdef; - const upb_EnumDef* enumdef; - const UPB_DESC(FieldDescriptorProto) * unresolved; - } sub; - uint32_t number_; - uint16_t index_; - uint16_t layout_index; // Index into msgdef->layout->fields or file->exts - bool has_default; - bool has_json_name; - bool has_presence; - bool is_extension; - bool is_proto3_optional; - upb_FieldType type_; - upb_Label label_; -}; - -upb_FieldDef* _upb_FieldDef_At(const upb_FieldDef* f, int i) { - return (upb_FieldDef*)&f[i]; -} +#define FASTDECODE_UNPACKEDFIXED(d, ptr, msg, table, hasbits, data, tagbytes, \ + valbytes, card, packed) \ + void* dst; \ + fastdecode_arr farr; \ + \ + FASTDECODE_CHECKPACKED(tagbytes, card, packed) \ + \ + dst = fastdecode_getfield(d, ptr, msg, &data, &hasbits, &farr, valbytes, \ + card); \ + if (card == CARD_r) { \ + if (UPB_UNLIKELY(!dst)) { \ + RETURN_GENERIC("couldn't allocate array in arena\n"); \ + } \ + } \ + \ + again: \ + if (card == CARD_r) { \ + dst = fastdecode_resizearr(d, dst, &farr, valbytes); \ + } \ + \ + ptr += tagbytes; \ + memcpy(dst, ptr, valbytes); \ + ptr += valbytes; \ + \ + if (card == CARD_r) { \ + fastdecode_nextret ret = fastdecode_nextrepeated( \ + d, dst, &ptr, &farr, data, tagbytes, valbytes); \ + switch (ret.next) { \ + case FD_NEXT_SAMEFIELD: \ + dst = ret.dst; \ + goto again; \ + case FD_NEXT_OTHERFIELD: \ + data = ret.tag; \ + UPB_MUSTTAIL return _upb_FastDecoder_TagDispatch(UPB_PARSE_ARGS); \ + case FD_NEXT_ATLIMIT: \ + return ptr; \ + } \ + } \ + \ + UPB_MUSTTAIL return fastdecode_dispatch(UPB_PARSE_ARGS); -const UPB_DESC(FieldOptions) * upb_FieldDef_Options(const upb_FieldDef* f) { - return f->opts; -} +#define FASTDECODE_PACKEDFIXED(d, ptr, msg, table, hasbits, data, tagbytes, \ + valbytes, unpacked) \ + FASTDECODE_CHECKPACKED(tagbytes, CARD_r, unpacked) \ + \ + ptr += tagbytes; \ + int size = (uint8_t)ptr[0]; \ + ptr++; \ + if (size & 0x80) { \ + ptr = fastdecode_longsize(ptr, &size); \ + } \ + \ + if (UPB_UNLIKELY(!upb_EpsCopyInputStream_CheckDataSizeAvailable( \ + &d->input, ptr, size) || \ + (size % valbytes) != 0)) { \ + _upb_FastDecoder_ErrorJmp(d, kUpb_DecodeStatus_Malformed); \ + } \ + \ + upb_Array** arr_p = fastdecode_fieldmem(msg, data); \ + upb_Array* arr = *arr_p; \ + uint8_t elem_size_lg2 = __builtin_ctz(valbytes); \ + int elems = size / valbytes; \ + \ + if (UPB_LIKELY(!arr)) { \ + *arr_p = arr = \ + UPB_PRIVATE(_upb_Array_New)(&d->arena, elems, elem_size_lg2); \ + if (!arr) { \ + _upb_FastDecoder_ErrorJmp(d, kUpb_DecodeStatus_Malformed); \ + } \ + } else { \ + _upb_Array_ResizeUninitialized(arr, elems, &d->arena); \ + } \ + \ + char* dst = _upb_array_ptr(arr); \ + memcpy(dst, ptr, size); \ + arr->UPB_PRIVATE(size) = elems; \ + \ + ptr += size; \ + UPB_MUSTTAIL return fastdecode_dispatch(UPB_PARSE_ARGS); -bool upb_FieldDef_HasOptions(const upb_FieldDef* f) { - return f->opts != (void*)kUpbDefOptDefault; -} +#define FASTDECODE_FIXED(d, ptr, msg, table, hasbits, data, tagbytes, \ + valbytes, card, unpacked, packed) \ + if (card == CARD_p) { \ + FASTDECODE_PACKEDFIXED(d, ptr, msg, table, hasbits, data, tagbytes, \ + valbytes, unpacked); \ + } else { \ + FASTDECODE_UNPACKEDFIXED(d, ptr, msg, table, hasbits, data, tagbytes, \ + valbytes, card, packed); \ + } -const UPB_DESC(FeatureSet) * - upb_FieldDef_ResolvedFeatures(const upb_FieldDef* f) { - return f->resolved_features; -} +/* Generate all combinations: + * {s,o,r,p} x {f4,f8} x {1bt,2bt} */ -const char* upb_FieldDef_FullName(const upb_FieldDef* f) { - return f->full_name; -} +#define F(card, valbytes, tagbytes) \ + UPB_NOINLINE \ + const char* upb_p##card##f##valbytes##_##tagbytes##bt(UPB_PARSE_PARAMS) { \ + FASTDECODE_FIXED(d, ptr, msg, table, hasbits, data, tagbytes, valbytes, \ + CARD_##card, upb_ppf##valbytes##_##tagbytes##bt, \ + upb_prf##valbytes##_##tagbytes##bt); \ + } -upb_CType upb_FieldDef_CType(const upb_FieldDef* f) { - return upb_FieldType_CType(f->type_); -} +#define TYPES(card, tagbytes) \ + F(card, 4, tagbytes) \ + F(card, 8, tagbytes) -upb_FieldType upb_FieldDef_Type(const upb_FieldDef* f) { - // TODO: remove once we can deprecate kUpb_FieldType_Group. - if (f->type_ == kUpb_FieldType_Message && - UPB_DESC(FeatureSet_message_encoding)(f->resolved_features) == - UPB_DESC(FeatureSet_DELIMITED)) { - return kUpb_FieldType_Group; - } - return f->type_; -} +#define TAGBYTES(card) \ + TYPES(card, 1) \ + TYPES(card, 2) -uint32_t upb_FieldDef_Index(const upb_FieldDef* f) { return f->index_; } +TAGBYTES(s) +TAGBYTES(o) +TAGBYTES(r) +TAGBYTES(p) -upb_Label upb_FieldDef_Label(const upb_FieldDef* f) { - // TODO: remove once we can deprecate kUpb_Label_Required. - if (UPB_DESC(FeatureSet_field_presence)(f->resolved_features) == - UPB_DESC(FeatureSet_LEGACY_REQUIRED)) { - return kUpb_Label_Required; - } - return f->label_; -} +#undef F +#undef TYPES +#undef TAGBYTES +#undef FASTDECODE_UNPACKEDFIXED +#undef FASTDECODE_PACKEDFIXED -uint32_t upb_FieldDef_Number(const upb_FieldDef* f) { return f->number_; } +/* string fields **************************************************************/ -bool upb_FieldDef_IsExtension(const upb_FieldDef* f) { return f->is_extension; } +typedef const char* fastdecode_copystr_func(struct upb_Decoder* d, + const char* ptr, upb_Message* msg, + const upb_MiniTable* table, + uint64_t hasbits, + upb_StringView* dst); -bool _upb_FieldDef_IsPackable(const upb_FieldDef* f) { - return upb_FieldDef_IsRepeated(f) && upb_FieldDef_IsPrimitive(f); +UPB_NOINLINE +static const char* fastdecode_verifyutf8(upb_Decoder* d, const char* ptr, + upb_Message* msg, intptr_t table, + uint64_t hasbits, uint64_t data) { + upb_StringView* dst = (upb_StringView*)data; + if (!_upb_Decoder_VerifyUtf8Inline(dst->data, dst->size)) { + _upb_FastDecoder_ErrorJmp(d, kUpb_DecodeStatus_BadUtf8); + } + UPB_MUSTTAIL return fastdecode_dispatch(UPB_PARSE_ARGS); } -bool upb_FieldDef_IsPacked(const upb_FieldDef* f) { - return _upb_FieldDef_IsPackable(f) && - UPB_DESC(FeatureSet_repeated_field_encoding(f->resolved_features)) == - UPB_DESC(FeatureSet_PACKED); -} +#define FASTDECODE_LONGSTRING(d, ptr, msg, table, hasbits, dst, validate_utf8) \ + int size = (uint8_t)ptr[0]; /* Could plumb through hasbits. */ \ + ptr++; \ + if (size & 0x80) { \ + ptr = fastdecode_longsize(ptr, &size); \ + } \ + \ + if (UPB_UNLIKELY(!upb_EpsCopyInputStream_CheckSize(&d->input, ptr, size))) { \ + dst->size = 0; \ + _upb_FastDecoder_ErrorJmp(d, kUpb_DecodeStatus_Malformed); \ + } \ + \ + const char* s_ptr = ptr; \ + ptr = upb_EpsCopyInputStream_ReadString(&d->input, &s_ptr, size, &d->arena); \ + if (!ptr) _upb_FastDecoder_ErrorJmp(d, kUpb_DecodeStatus_OutOfMemory); \ + dst->data = s_ptr; \ + dst->size = size; \ + \ + if (validate_utf8) { \ + data = (uint64_t)dst; \ + UPB_MUSTTAIL return fastdecode_verifyutf8(UPB_PARSE_ARGS); \ + } else { \ + UPB_MUSTTAIL return fastdecode_dispatch(UPB_PARSE_ARGS); \ + } -const char* upb_FieldDef_Name(const upb_FieldDef* f) { - return _upb_DefBuilder_FullToShort(f->full_name); +UPB_NOINLINE +static const char* fastdecode_longstring_utf8(struct upb_Decoder* d, + const char* ptr, upb_Message* msg, + intptr_t table, uint64_t hasbits, + uint64_t data) { + upb_StringView* dst = (upb_StringView*)data; + FASTDECODE_LONGSTRING(d, ptr, msg, table, hasbits, dst, true); } -const char* upb_FieldDef_JsonName(const upb_FieldDef* f) { - return f->json_name; +UPB_NOINLINE +static const char* fastdecode_longstring_noutf8( + struct upb_Decoder* d, const char* ptr, upb_Message* msg, intptr_t table, + uint64_t hasbits, uint64_t data) { + upb_StringView* dst = (upb_StringView*)data; + FASTDECODE_LONGSTRING(d, ptr, msg, table, hasbits, dst, false); } -bool upb_FieldDef_HasJsonName(const upb_FieldDef* f) { - return f->has_json_name; +UPB_FORCEINLINE +static void fastdecode_docopy(upb_Decoder* d, const char* ptr, uint32_t size, + int copy, char* data, size_t data_offset, + upb_StringView* dst) { + d->arena.UPB_PRIVATE(ptr) += copy; + dst->data = data + data_offset; + UPB_UNPOISON_MEMORY_REGION(data, copy); + memcpy(data, ptr, copy); + UPB_POISON_MEMORY_REGION(data + data_offset + size, + copy - data_offset - size); +} + +#define FASTDECODE_COPYSTRING(d, ptr, msg, table, hasbits, data, tagbytes, \ + card, validate_utf8) \ + upb_StringView* dst; \ + fastdecode_arr farr; \ + int64_t size; \ + size_t arena_has; \ + size_t common_has; \ + char* buf; \ + \ + UPB_ASSERT(!upb_EpsCopyInputStream_AliasingAvailable(&d->input, ptr, 0)); \ + UPB_ASSERT(fastdecode_checktag(data, tagbytes)); \ + \ + dst = fastdecode_getfield(d, ptr, msg, &data, &hasbits, &farr, \ + sizeof(upb_StringView), card); \ + \ + again: \ + if (card == CARD_r) { \ + dst = fastdecode_resizearr(d, dst, &farr, sizeof(upb_StringView)); \ + } \ + \ + size = (uint8_t)ptr[tagbytes]; \ + ptr += tagbytes + 1; \ + dst->size = size; \ + \ + buf = d->arena.UPB_PRIVATE(ptr); \ + arena_has = UPB_PRIVATE(_upb_ArenaHas)(&d->arena); \ + common_has = UPB_MIN(arena_has, \ + upb_EpsCopyInputStream_BytesAvailable(&d->input, ptr)); \ + \ + if (UPB_LIKELY(size <= 15 - tagbytes)) { \ + if (arena_has < 16) goto longstr; \ + fastdecode_docopy(d, ptr - tagbytes - 1, size, 16, buf, tagbytes + 1, \ + dst); \ + } else if (UPB_LIKELY(size <= 32)) { \ + if (UPB_UNLIKELY(common_has < 32)) goto longstr; \ + fastdecode_docopy(d, ptr, size, 32, buf, 0, dst); \ + } else if (UPB_LIKELY(size <= 64)) { \ + if (UPB_UNLIKELY(common_has < 64)) goto longstr; \ + fastdecode_docopy(d, ptr, size, 64, buf, 0, dst); \ + } else if (UPB_LIKELY(size < 128)) { \ + if (UPB_UNLIKELY(common_has < 128)) goto longstr; \ + fastdecode_docopy(d, ptr, size, 128, buf, 0, dst); \ + } else { \ + goto longstr; \ + } \ + \ + ptr += size; \ + \ + if (card == CARD_r) { \ + if (validate_utf8 && \ + !_upb_Decoder_VerifyUtf8Inline(dst->data, dst->size)) { \ + _upb_FastDecoder_ErrorJmp(d, kUpb_DecodeStatus_BadUtf8); \ + } \ + fastdecode_nextret ret = fastdecode_nextrepeated( \ + d, dst, &ptr, &farr, data, tagbytes, sizeof(upb_StringView)); \ + switch (ret.next) { \ + case FD_NEXT_SAMEFIELD: \ + dst = ret.dst; \ + goto again; \ + case FD_NEXT_OTHERFIELD: \ + data = ret.tag; \ + UPB_MUSTTAIL return _upb_FastDecoder_TagDispatch(UPB_PARSE_ARGS); \ + case FD_NEXT_ATLIMIT: \ + return ptr; \ + } \ + } \ + \ + if (card != CARD_r && validate_utf8) { \ + data = (uint64_t)dst; \ + UPB_MUSTTAIL return fastdecode_verifyutf8(UPB_PARSE_ARGS); \ + } \ + \ + UPB_MUSTTAIL return fastdecode_dispatch(UPB_PARSE_ARGS); \ + \ + longstr: \ + if (card == CARD_r) { \ + fastdecode_commitarr(dst + 1, &farr, sizeof(upb_StringView)); \ + } \ + ptr--; \ + if (validate_utf8) { \ + UPB_MUSTTAIL return fastdecode_longstring_utf8(d, ptr, msg, table, \ + hasbits, (uint64_t)dst); \ + } else { \ + UPB_MUSTTAIL return fastdecode_longstring_noutf8(d, ptr, msg, table, \ + hasbits, (uint64_t)dst); \ + } + +#define FASTDECODE_STRING(d, ptr, msg, table, hasbits, data, tagbytes, card, \ + copyfunc, validate_utf8) \ + upb_StringView* dst; \ + fastdecode_arr farr; \ + int64_t size; \ + \ + if (UPB_UNLIKELY(!fastdecode_checktag(data, tagbytes))) { \ + RETURN_GENERIC("string field tag mismatch\n"); \ + } \ + \ + if (UPB_UNLIKELY( \ + !upb_EpsCopyInputStream_AliasingAvailable(&d->input, ptr, 0))) { \ + UPB_MUSTTAIL return copyfunc(UPB_PARSE_ARGS); \ + } \ + \ + dst = fastdecode_getfield(d, ptr, msg, &data, &hasbits, &farr, \ + sizeof(upb_StringView), card); \ + \ + again: \ + if (card == CARD_r) { \ + dst = fastdecode_resizearr(d, dst, &farr, sizeof(upb_StringView)); \ + } \ + \ + size = (int8_t)ptr[tagbytes]; \ + ptr += tagbytes + 1; \ + \ + if (UPB_UNLIKELY( \ + !upb_EpsCopyInputStream_AliasingAvailable(&d->input, ptr, size))) { \ + ptr--; \ + if (validate_utf8) { \ + return fastdecode_longstring_utf8(d, ptr, msg, table, hasbits, \ + (uint64_t)dst); \ + } else { \ + return fastdecode_longstring_noutf8(d, ptr, msg, table, hasbits, \ + (uint64_t)dst); \ + } \ + } \ + \ + dst->data = ptr; \ + dst->size = size; \ + ptr = upb_EpsCopyInputStream_ReadStringAliased(&d->input, &dst->data, \ + dst->size); \ + \ + if (card == CARD_r) { \ + if (validate_utf8 && \ + !_upb_Decoder_VerifyUtf8Inline(dst->data, dst->size)) { \ + _upb_FastDecoder_ErrorJmp(d, kUpb_DecodeStatus_BadUtf8); \ + } \ + fastdecode_nextret ret = fastdecode_nextrepeated( \ + d, dst, &ptr, &farr, data, tagbytes, sizeof(upb_StringView)); \ + switch (ret.next) { \ + case FD_NEXT_SAMEFIELD: \ + dst = ret.dst; \ + goto again; \ + case FD_NEXT_OTHERFIELD: \ + data = ret.tag; \ + UPB_MUSTTAIL return _upb_FastDecoder_TagDispatch(UPB_PARSE_ARGS); \ + case FD_NEXT_ATLIMIT: \ + return ptr; \ + } \ + } \ + \ + if (card != CARD_r && validate_utf8) { \ + data = (uint64_t)dst; \ + UPB_MUSTTAIL return fastdecode_verifyutf8(UPB_PARSE_ARGS); \ + } \ + \ + UPB_MUSTTAIL return fastdecode_dispatch(UPB_PARSE_ARGS); + +/* Generate all combinations: + * {p,c} x {s,o,r} x {s, b} x {1bt,2bt} */ + +#define s_VALIDATE true +#define b_VALIDATE false + +#define F(card, tagbytes, type) \ + UPB_NOINLINE \ + const char* upb_c##card##type##_##tagbytes##bt(UPB_PARSE_PARAMS) { \ + FASTDECODE_COPYSTRING(d, ptr, msg, table, hasbits, data, tagbytes, \ + CARD_##card, type##_VALIDATE); \ + } \ + const char* upb_p##card##type##_##tagbytes##bt(UPB_PARSE_PARAMS) { \ + FASTDECODE_STRING(d, ptr, msg, table, hasbits, data, tagbytes, \ + CARD_##card, upb_c##card##type##_##tagbytes##bt, \ + type##_VALIDATE); \ + } + +#define UTF8(card, tagbytes) \ + F(card, tagbytes, s) \ + F(card, tagbytes, b) + +#define TAGBYTES(card) \ + UTF8(card, 1) \ + UTF8(card, 2) + +TAGBYTES(s) +TAGBYTES(o) +TAGBYTES(r) + +#undef s_VALIDATE +#undef b_VALIDATE +#undef F +#undef TAGBYTES +#undef FASTDECODE_LONGSTRING +#undef FASTDECODE_COPYSTRING +#undef FASTDECODE_STRING + +/* message fields *************************************************************/ + +UPB_INLINE +upb_Message* decode_newmsg_ceil(upb_Decoder* d, const upb_MiniTable* m, + int msg_ceil_bytes) { + size_t size = m->UPB_PRIVATE(size) + sizeof(upb_Message_Internal); + char* msg_data; + if (UPB_LIKELY(msg_ceil_bytes > 0 && + UPB_PRIVATE(_upb_ArenaHas)(&d->arena) >= msg_ceil_bytes)) { + UPB_ASSERT(size <= (size_t)msg_ceil_bytes); + msg_data = d->arena.UPB_PRIVATE(ptr); + d->arena.UPB_PRIVATE(ptr) += size; + UPB_UNPOISON_MEMORY_REGION(msg_data, msg_ceil_bytes); + memset(msg_data, 0, msg_ceil_bytes); + UPB_POISON_MEMORY_REGION(msg_data + size, msg_ceil_bytes - size); + } else { + msg_data = (char*)upb_Arena_Malloc(&d->arena, size); + memset(msg_data, 0, size); + } + return msg_data + sizeof(upb_Message_Internal); +} + +typedef struct { + intptr_t table; + upb_Message* msg; +} fastdecode_submsgdata; + +UPB_FORCEINLINE +static const char* fastdecode_tosubmsg(upb_EpsCopyInputStream* e, + const char* ptr, void* ctx) { + upb_Decoder* d = (upb_Decoder*)e; + fastdecode_submsgdata* submsg = ctx; + ptr = fastdecode_dispatch(d, ptr, submsg->msg, submsg->table, 0, 0); + UPB_ASSUME(ptr != NULL); + return ptr; } -const upb_FileDef* upb_FieldDef_File(const upb_FieldDef* f) { return f->file; } +#define FASTDECODE_SUBMSG(d, ptr, msg, table, hasbits, data, tagbytes, \ + msg_ceil_bytes, card) \ + \ + if (UPB_UNLIKELY(!fastdecode_checktag(data, tagbytes))) { \ + RETURN_GENERIC("submessage field tag mismatch\n"); \ + } \ + \ + if (--d->depth == 0) { \ + _upb_FastDecoder_ErrorJmp(d, kUpb_DecodeStatus_MaxDepthExceeded); \ + } \ + \ + upb_Message** dst; \ + uint32_t submsg_idx = (data >> 16) & 0xff; \ + const upb_MiniTable* tablep = decode_totablep(table); \ + const upb_MiniTable* subtablep = upb_MiniTableSub_Message( \ + *UPB_PRIVATE(_upb_MiniTable_GetSubByIndex)(tablep, submsg_idx)); \ + fastdecode_submsgdata submsg = {decode_totable(subtablep)}; \ + fastdecode_arr farr; \ + \ + if (subtablep->UPB_PRIVATE(table_mask) == (uint8_t)-1) { \ + d->depth++; \ + RETURN_GENERIC("submessage doesn't have fast tables."); \ + } \ + \ + dst = fastdecode_getfield(d, ptr, msg, &data, &hasbits, &farr, \ + sizeof(upb_Message*), card); \ + \ + if (card == CARD_s) { \ + *(uint32_t*)msg |= hasbits; \ + hasbits = 0; \ + } \ + \ + again: \ + if (card == CARD_r) { \ + dst = fastdecode_resizearr(d, dst, &farr, sizeof(upb_Message*)); \ + } \ + \ + submsg.msg = *dst; \ + \ + if (card == CARD_r || UPB_LIKELY(!submsg.msg)) { \ + *dst = submsg.msg = decode_newmsg_ceil(d, subtablep, msg_ceil_bytes); \ + } \ + \ + ptr += tagbytes; \ + ptr = fastdecode_delimited(d, ptr, fastdecode_tosubmsg, &submsg); \ + \ + if (UPB_UNLIKELY(ptr == NULL || d->end_group != DECODE_NOGROUP)) { \ + _upb_FastDecoder_ErrorJmp(d, kUpb_DecodeStatus_Malformed); \ + } \ + \ + if (card == CARD_r) { \ + fastdecode_nextret ret = fastdecode_nextrepeated( \ + d, dst, &ptr, &farr, data, tagbytes, sizeof(upb_Message*)); \ + switch (ret.next) { \ + case FD_NEXT_SAMEFIELD: \ + dst = ret.dst; \ + goto again; \ + case FD_NEXT_OTHERFIELD: \ + d->depth++; \ + data = ret.tag; \ + UPB_MUSTTAIL return _upb_FastDecoder_TagDispatch(UPB_PARSE_ARGS); \ + case FD_NEXT_ATLIMIT: \ + d->depth++; \ + return ptr; \ + } \ + } \ + \ + d->depth++; \ + UPB_MUSTTAIL return fastdecode_dispatch(UPB_PARSE_ARGS); + +#define F(card, tagbytes, size_ceil, ceil_arg) \ + const char* upb_p##card##m_##tagbytes##bt_max##size_ceil##b( \ + UPB_PARSE_PARAMS) { \ + FASTDECODE_SUBMSG(d, ptr, msg, table, hasbits, data, tagbytes, ceil_arg, \ + CARD_##card); \ + } + +#define SIZES(card, tagbytes) \ + F(card, tagbytes, 64, 64) \ + F(card, tagbytes, 128, 128) \ + F(card, tagbytes, 192, 192) \ + F(card, tagbytes, 256, 256) \ + F(card, tagbytes, max, -1) + +#define TAGBYTES(card) \ + SIZES(card, 1) \ + SIZES(card, 2) -const upb_MessageDef* upb_FieldDef_ContainingType(const upb_FieldDef* f) { - return f->msgdef; -} +TAGBYTES(s) +TAGBYTES(o) +TAGBYTES(r) -const upb_MessageDef* upb_FieldDef_ExtensionScope(const upb_FieldDef* f) { - return f->is_extension ? f->scope.extension_scope : NULL; -} +#undef TAGBYTES +#undef SIZES +#undef F +#undef FASTDECODE_SUBMSG -const upb_OneofDef* upb_FieldDef_ContainingOneof(const upb_FieldDef* f) { - return f->is_extension ? NULL : f->scope.oneof; -} +#endif /* UPB_FASTTABLE */ -const upb_OneofDef* upb_FieldDef_RealContainingOneof(const upb_FieldDef* f) { - const upb_OneofDef* oneof = upb_FieldDef_ContainingOneof(f); - if (!oneof || upb_OneofDef_IsSynthetic(oneof)) return NULL; - return oneof; -} -upb_MessageValue upb_FieldDef_Default(const upb_FieldDef* f) { - upb_MessageValue ret; +#include +#include - if (upb_FieldDef_IsRepeated(f) || upb_FieldDef_IsSubMessage(f)) { - return (upb_MessageValue){.msg_val = NULL}; - } - switch (upb_FieldDef_CType(f)) { - case kUpb_CType_Bool: - return (upb_MessageValue){.bool_val = f->defaultval.boolean}; - case kUpb_CType_Int64: - return (upb_MessageValue){.int64_val = f->defaultval.sint}; - case kUpb_CType_UInt64: - return (upb_MessageValue){.uint64_val = f->defaultval.uint}; - case kUpb_CType_Enum: - case kUpb_CType_Int32: - return (upb_MessageValue){.int32_val = (int32_t)f->defaultval.sint}; - case kUpb_CType_UInt32: - return (upb_MessageValue){.uint32_val = (uint32_t)f->defaultval.uint}; - case kUpb_CType_Float: - return (upb_MessageValue){.float_val = f->defaultval.flt}; - case kUpb_CType_Double: - return (upb_MessageValue){.double_val = f->defaultval.dbl}; - case kUpb_CType_String: - case kUpb_CType_Bytes: { - str_t* str = f->defaultval.str; - if (str) { - return (upb_MessageValue){ - .str_val = (upb_StringView){.data = str->str, .size = str->len}}; - } else { - return (upb_MessageValue){ - .str_val = (upb_StringView){.data = NULL, .size = 0}}; - } +// Must be last. + +UPB_NOINLINE UPB_PRIVATE(_upb_WireReader_LongVarint) + UPB_PRIVATE(_upb_WireReader_ReadLongVarint)(const char* ptr, uint64_t val) { + UPB_PRIVATE(_upb_WireReader_LongVarint) ret = {NULL, 0}; + uint64_t byte; + int i; + for (i = 1; i < 10; i++) { + byte = (uint8_t)ptr[i]; + val += (byte - 1) << (i * 7); + if (!(byte & 0x80)) { + ret.ptr = ptr + i + 1; + ret.val = val; + return ret; } - default: - UPB_UNREACHABLE(); } - return ret; } -const upb_MessageDef* upb_FieldDef_MessageSubDef(const upb_FieldDef* f) { - return upb_FieldDef_CType(f) == kUpb_CType_Message ? f->sub.msgdef : NULL; -} - -const upb_EnumDef* upb_FieldDef_EnumSubDef(const upb_FieldDef* f) { - return upb_FieldDef_CType(f) == kUpb_CType_Enum ? f->sub.enumdef : NULL; -} - -const upb_MiniTableField* upb_FieldDef_MiniTable(const upb_FieldDef* f) { - if (upb_FieldDef_IsExtension(f)) { - const upb_FileDef* file = upb_FieldDef_File(f); - return (upb_MiniTableField*)_upb_FileDef_ExtensionMiniTable( - file, f->layout_index); - } else { - const upb_MiniTable* layout = upb_MessageDef_MiniTable(f->msgdef); - return &layout->UPB_PRIVATE(fields)[f->layout_index]; +const char* UPB_PRIVATE(_upb_WireReader_SkipGroup)( + const char* ptr, uint32_t tag, int depth_limit, + upb_EpsCopyInputStream* stream) { + if (--depth_limit == 0) return NULL; + uint32_t end_group_tag = (tag & ~7ULL) | kUpb_WireType_EndGroup; + while (!upb_EpsCopyInputStream_IsDone(stream, &ptr)) { + uint32_t tag; + ptr = upb_WireReader_ReadTag(ptr, &tag); + if (!ptr) return NULL; + if (tag == end_group_tag) return ptr; + ptr = _upb_WireReader_SkipValue(ptr, tag, depth_limit, stream); + if (!ptr) return NULL; } + return ptr; } -const upb_MiniTableExtension* _upb_FieldDef_ExtensionMiniTable( - const upb_FieldDef* f) { - UPB_ASSERT(upb_FieldDef_IsExtension(f)); - const upb_FileDef* file = upb_FieldDef_File(f); - return _upb_FileDef_ExtensionMiniTable(file, f->layout_index); -} +/* + * upb_table Implementation + * + * Implementation is heavily inspired by Lua's ltable.c. + */ -bool _upb_FieldDef_IsClosedEnum(const upb_FieldDef* f) { - if (f->type_ != kUpb_FieldType_Enum) return false; - return upb_EnumDef_IsClosed(f->sub.enumdef); -} +#include -bool _upb_FieldDef_IsProto3Optional(const upb_FieldDef* f) { - return f->is_proto3_optional; -} -int _upb_FieldDef_LayoutIndex(const upb_FieldDef* f) { return f->layout_index; } +// Must be last. -bool _upb_FieldDef_ValidateUtf8(const upb_FieldDef* f) { - if (upb_FieldDef_Type(f) != kUpb_FieldType_String) return false; - return UPB_DESC(FeatureSet_utf8_validation(f->resolved_features)) == - UPB_DESC(FeatureSet_VERIFY); -} +#define UPB_MAXARRSIZE 16 // 2**16 = 64k. -uint64_t _upb_FieldDef_Modifiers(const upb_FieldDef* f) { - uint64_t out = upb_FieldDef_IsPacked(f) ? kUpb_FieldModifier_IsPacked : 0; +// From Chromium. +#define ARRAY_SIZE(x) \ + ((sizeof(x) / sizeof(0 [x])) / ((size_t)(!(sizeof(x) % sizeof(0 [x]))))) - if (upb_FieldDef_IsRepeated(f)) { - out |= kUpb_FieldModifier_IsRepeated; - } else if (upb_FieldDef_IsRequired(f)) { - out |= kUpb_FieldModifier_IsRequired; - } else if (!upb_FieldDef_HasPresence(f)) { - out |= kUpb_FieldModifier_IsProto3Singular; - } +static const double MAX_LOAD = 0.85; - if (_upb_FieldDef_IsClosedEnum(f)) { - out |= kUpb_FieldModifier_IsClosedEnum; - } +/* The minimum utilization of the array part of a mixed hash/array table. This + * is a speed/memory-usage tradeoff (though it's not straightforward because of + * cache effects). The lower this is, the more memory we'll use. */ +static const double MIN_DENSITY = 0.1; - if (_upb_FieldDef_ValidateUtf8(f)) { - out |= kUpb_FieldModifier_ValidateUtf8; - } +static bool is_pow2(uint64_t v) { return v == 0 || (v & (v - 1)) == 0; } - return out; +static upb_value _upb_value_val(uint64_t val) { + upb_value ret; + _upb_value_setval(&ret, val); + return ret; } -bool upb_FieldDef_HasDefault(const upb_FieldDef* f) { return f->has_default; } -bool upb_FieldDef_HasPresence(const upb_FieldDef* f) { return f->has_presence; } - -bool upb_FieldDef_HasSubDef(const upb_FieldDef* f) { - return upb_FieldDef_IsSubMessage(f) || - upb_FieldDef_CType(f) == kUpb_CType_Enum; +static int log2ceil(uint64_t v) { + int ret = 0; + bool pow2 = is_pow2(v); + while (v >>= 1) ret++; + ret = pow2 ? ret : ret + 1; // Ceiling. + return UPB_MIN(UPB_MAXARRSIZE, ret); } -bool upb_FieldDef_IsMap(const upb_FieldDef* f) { - return upb_FieldDef_IsRepeated(f) && upb_FieldDef_IsSubMessage(f) && - upb_MessageDef_IsMapEntry(upb_FieldDef_MessageSubDef(f)); -} +/* A type to represent the lookup key of either a strtable or an inttable. */ +typedef union { + uintptr_t num; + struct { + const char* str; + size_t len; + } str; +} lookupkey_t; -bool upb_FieldDef_IsOptional(const upb_FieldDef* f) { - return upb_FieldDef_Label(f) == kUpb_Label_Optional; +static lookupkey_t strkey2(const char* str, size_t len) { + lookupkey_t k; + k.str.str = str; + k.str.len = len; + return k; } -bool upb_FieldDef_IsPrimitive(const upb_FieldDef* f) { - return !upb_FieldDef_IsString(f) && !upb_FieldDef_IsSubMessage(f); +static lookupkey_t intkey(uintptr_t key) { + lookupkey_t k; + k.num = key; + return k; } -bool upb_FieldDef_IsRepeated(const upb_FieldDef* f) { - return upb_FieldDef_Label(f) == kUpb_Label_Repeated; -} +typedef uint32_t hashfunc_t(upb_tabkey key); +typedef bool eqlfunc_t(upb_tabkey k1, lookupkey_t k2); -bool upb_FieldDef_IsRequired(const upb_FieldDef* f) { - return UPB_DESC(FeatureSet_field_presence)(f->resolved_features) == - UPB_DESC(FeatureSet_LEGACY_REQUIRED); -} +/* Base table (shared code) ***************************************************/ -bool upb_FieldDef_IsString(const upb_FieldDef* f) { - return upb_FieldDef_CType(f) == kUpb_CType_String || - upb_FieldDef_CType(f) == kUpb_CType_Bytes; -} +static uint32_t upb_inthash(uintptr_t key) { return (uint32_t)key; } -bool upb_FieldDef_IsSubMessage(const upb_FieldDef* f) { - return upb_FieldDef_CType(f) == kUpb_CType_Message; +static const upb_tabent* upb_getentry(const upb_table* t, uint32_t hash) { + return t->entries + (hash & t->mask); } -static bool between(int32_t x, int32_t low, int32_t high) { - return x >= low && x <= high; -} +static bool upb_arrhas(upb_tabval key) { return key.val != (uint64_t)-1; } -bool upb_FieldDef_checklabel(int32_t label) { return between(label, 1, 3); } -bool upb_FieldDef_checktype(int32_t type) { return between(type, 1, 11); } -bool upb_FieldDef_checkintfmt(int32_t fmt) { return between(fmt, 1, 3); } +static bool isfull(upb_table* t) { return t->count == t->max_count; } -bool upb_FieldDef_checkdescriptortype(int32_t type) { - return between(type, 1, 18); +static bool init(upb_table* t, uint8_t size_lg2, upb_Arena* a) { + size_t bytes; + + t->count = 0; + t->size_lg2 = size_lg2; + t->mask = upb_table_size(t) ? upb_table_size(t) - 1 : 0; + t->max_count = upb_table_size(t) * MAX_LOAD; + bytes = upb_table_size(t) * sizeof(upb_tabent); + if (bytes > 0) { + t->entries = upb_Arena_Malloc(a, bytes); + if (!t->entries) return false; + memset(t->entries, 0, bytes); + } else { + t->entries = NULL; + } + return true; +} + +static upb_tabent* emptyent(upb_table* t, upb_tabent* e) { + upb_tabent* begin = t->entries; + upb_tabent* end = begin + upb_table_size(t); + for (e = e + 1; e < end; e++) { + if (upb_tabent_isempty(e)) return e; + } + for (e = begin; e < end; e++) { + if (upb_tabent_isempty(e)) return e; + } + UPB_ASSERT(false); + return NULL; } -static bool streql2(const char* a, size_t n, const char* b) { - return n == strlen(b) && memcmp(a, b, n) == 0; +static upb_tabent* getentry_mutable(upb_table* t, uint32_t hash) { + return (upb_tabent*)upb_getentry(t, hash); } -// Implement the transformation as described in the spec: -// 1. upper case all letters after an underscore. -// 2. remove all underscores. -static char* make_json_name(const char* name, size_t size, upb_Arena* a) { - char* out = upb_Arena_Malloc(a, size + 1); // +1 is to add a trailing '\0' - if (out == NULL) return NULL; +static const upb_tabent* findentry(const upb_table* t, lookupkey_t key, + uint32_t hash, eqlfunc_t* eql) { + const upb_tabent* e; - bool ucase_next = false; - char* des = out; - for (size_t i = 0; i < size; i++) { - if (name[i] == '_') { - ucase_next = true; - } else { - *des++ = ucase_next ? toupper(name[i]) : name[i]; - ucase_next = false; - } + if (t->size_lg2 == 0) return NULL; + e = upb_getentry(t, hash); + if (upb_tabent_isempty(e)) return NULL; + while (1) { + if (eql(e->key, key)) return e; + if ((e = e->next) == NULL) return NULL; } - *des++ = '\0'; - return out; } -static str_t* newstr(upb_DefBuilder* ctx, const char* data, size_t len) { - str_t* ret = _upb_DefBuilder_Alloc(ctx, sizeof(*ret) + len); - if (!ret) _upb_DefBuilder_OomErr(ctx); - ret->len = len; - if (len) memcpy(ret->str, data, len); - ret->str[len] = '\0'; - return ret; +static upb_tabent* findentry_mutable(upb_table* t, lookupkey_t key, + uint32_t hash, eqlfunc_t* eql) { + return (upb_tabent*)findentry(t, key, hash, eql); } -static str_t* unescape(upb_DefBuilder* ctx, const upb_FieldDef* f, - const char* data, size_t len) { - // Size here is an upper bound; escape sequences could ultimately shrink it. - str_t* ret = _upb_DefBuilder_Alloc(ctx, sizeof(*ret) + len); - char* dst = &ret->str[0]; - const char* src = data; - const char* end = data + len; - - while (src < end) { - if (*src == '\\') { - src++; - *dst++ = _upb_DefBuilder_ParseEscape(ctx, f, &src, end); - } else { - *dst++ = *src++; +static bool lookup(const upb_table* t, lookupkey_t key, upb_value* v, + uint32_t hash, eqlfunc_t* eql) { + const upb_tabent* e = findentry(t, key, hash, eql); + if (e) { + if (v) { + _upb_value_setval(v, e->val.val); } + return true; + } else { + return false; } - - ret->len = dst - &ret->str[0]; - return ret; } -static void parse_default(upb_DefBuilder* ctx, const char* str, size_t len, - upb_FieldDef* f) { - char* end; - char nullz[64]; - errno = 0; +/* The given key must not already exist in the table. */ +static void insert(upb_table* t, lookupkey_t key, upb_tabkey tabkey, + upb_value val, uint32_t hash, hashfunc_t* hashfunc, + eqlfunc_t* eql) { + upb_tabent* mainpos_e; + upb_tabent* our_e; - switch (upb_FieldDef_CType(f)) { - case kUpb_CType_Int32: - case kUpb_CType_Int64: - case kUpb_CType_UInt32: - case kUpb_CType_UInt64: - case kUpb_CType_Double: - case kUpb_CType_Float: - // Standard C number parsing functions expect null-terminated strings. - if (len >= sizeof(nullz) - 1) { - _upb_DefBuilder_Errf(ctx, "Default too long: %.*s", (int)len, str); - } - memcpy(nullz, str, len); - nullz[len] = '\0'; - str = nullz; - break; - default: - break; - } + UPB_ASSERT(findentry(t, key, hash, eql) == NULL); - switch (upb_FieldDef_CType(f)) { - case kUpb_CType_Int32: { - long val = strtol(str, &end, 0); - if (val > INT32_MAX || val < INT32_MIN || errno == ERANGE || *end) { - goto invalid; - } - f->defaultval.sint = val; - break; - } - case kUpb_CType_Enum: { - const upb_EnumDef* e = f->sub.enumdef; - const upb_EnumValueDef* ev = - upb_EnumDef_FindValueByNameWithSize(e, str, len); - if (!ev) { - goto invalid; - } - f->defaultval.sint = upb_EnumValueDef_Number(ev); - break; - } - case kUpb_CType_Int64: { - long long val = strtoll(str, &end, 0); - if (val > INT64_MAX || val < INT64_MIN || errno == ERANGE || *end) { - goto invalid; - } - f->defaultval.sint = val; - break; - } - case kUpb_CType_UInt32: { - unsigned long val = strtoul(str, &end, 0); - if (val > UINT32_MAX || errno == ERANGE || *end) { - goto invalid; - } - f->defaultval.uint = val; - break; - } - case kUpb_CType_UInt64: { - unsigned long long val = strtoull(str, &end, 0); - if (val > UINT64_MAX || errno == ERANGE || *end) { - goto invalid; - } - f->defaultval.uint = val; - break; - } - case kUpb_CType_Double: { - double val = strtod(str, &end); - if (errno == ERANGE || *end) { - goto invalid; - } - f->defaultval.dbl = val; - break; - } - case kUpb_CType_Float: { - float val = strtof(str, &end); - if (errno == ERANGE || *end) { - goto invalid; - } - f->defaultval.flt = val; - break; - } - case kUpb_CType_Bool: { - if (streql2(str, len, "false")) { - f->defaultval.boolean = false; - } else if (streql2(str, len, "true")) { - f->defaultval.boolean = true; - } else { - goto invalid; + t->count++; + mainpos_e = getentry_mutable(t, hash); + our_e = mainpos_e; + + if (upb_tabent_isempty(mainpos_e)) { + /* Our main position is empty; use it. */ + our_e->next = NULL; + } else { + /* Collision. */ + upb_tabent* new_e = emptyent(t, mainpos_e); + /* Head of collider's chain. */ + upb_tabent* chain = getentry_mutable(t, hashfunc(mainpos_e->key)); + if (chain == mainpos_e) { + /* Existing ent is in its main position (it has the same hash as us, and + * is the head of our chain). Insert to new ent and append to this chain. + */ + new_e->next = mainpos_e->next; + mainpos_e->next = new_e; + our_e = new_e; + } else { + /* Existing ent is not in its main position (it is a node in some other + * chain). This implies that no existing ent in the table has our hash. + * Evict it (updating its chain) and use its ent for head of our chain. */ + *new_e = *mainpos_e; /* copies next. */ + while (chain->next != mainpos_e) { + chain = (upb_tabent*)chain->next; + UPB_ASSERT(chain); } - break; + chain->next = new_e; + our_e = mainpos_e; + our_e->next = NULL; } - case kUpb_CType_String: - f->defaultval.str = newstr(ctx, str, len); - break; - case kUpb_CType_Bytes: - f->defaultval.str = unescape(ctx, f, str, len); - break; - case kUpb_CType_Message: - /* Should not have a default value. */ - _upb_DefBuilder_Errf(ctx, "Message should not have a default (%s)", - upb_FieldDef_FullName(f)); } - - return; - -invalid: - _upb_DefBuilder_Errf(ctx, "Invalid default '%.*s' for field %s of type %d", - (int)len, str, upb_FieldDef_FullName(f), - (int)upb_FieldDef_Type(f)); + our_e->key = tabkey; + our_e->val.val = val.val; + UPB_ASSERT(findentry(t, key, hash, eql) == our_e); } -static void set_default_default(upb_DefBuilder* ctx, upb_FieldDef* f) { - switch (upb_FieldDef_CType(f)) { - case kUpb_CType_Int32: - case kUpb_CType_Int64: - f->defaultval.sint = 0; - break; - case kUpb_CType_UInt64: - case kUpb_CType_UInt32: - f->defaultval.uint = 0; - break; - case kUpb_CType_Double: - case kUpb_CType_Float: - f->defaultval.dbl = 0; - break; - case kUpb_CType_String: - case kUpb_CType_Bytes: - f->defaultval.str = newstr(ctx, NULL, 0); - break; - case kUpb_CType_Bool: - f->defaultval.boolean = false; - break; - case kUpb_CType_Enum: { - const upb_EnumValueDef* v = upb_EnumDef_Value(f->sub.enumdef, 0); - f->defaultval.sint = upb_EnumValueDef_Number(v); - break; +static bool rm(upb_table* t, lookupkey_t key, upb_value* val, + upb_tabkey* removed, uint32_t hash, eqlfunc_t* eql) { + upb_tabent* chain = getentry_mutable(t, hash); + if (upb_tabent_isempty(chain)) return false; + if (eql(chain->key, key)) { + /* Element to remove is at the head of its chain. */ + t->count--; + if (val) _upb_value_setval(val, chain->val.val); + if (removed) *removed = chain->key; + if (chain->next) { + upb_tabent* move = (upb_tabent*)chain->next; + *chain = *move; + move->key = 0; /* Make the slot empty. */ + } else { + chain->key = 0; /* Make the slot empty. */ + } + return true; + } else { + /* Element to remove is either in a non-head position or not in the + * table. */ + while (chain->next && !eql(chain->next->key, key)) { + chain = (upb_tabent*)chain->next; + } + if (chain->next) { + /* Found element to remove. */ + upb_tabent* rm = (upb_tabent*)chain->next; + t->count--; + if (val) _upb_value_setval(val, chain->next->val.val); + if (removed) *removed = rm->key; + rm->key = 0; /* Make the slot empty. */ + chain->next = rm->next; + return true; + } else { + /* Element to remove is not in the table. */ + return false; } - case kUpb_CType_Message: - break; } } -static bool _upb_FieldDef_InferLegacyFeatures( - upb_DefBuilder* ctx, upb_FieldDef* f, - const UPB_DESC(FieldDescriptorProto*) proto, - const UPB_DESC(FieldOptions*) options, upb_Syntax syntax, - UPB_DESC(FeatureSet*) features) { - bool ret = false; +static size_t next(const upb_table* t, size_t i) { + do { + if (++i >= upb_table_size(t)) return SIZE_MAX - 1; /* Distinct from -1. */ + } while (upb_tabent_isempty(&t->entries[i])); - if (UPB_DESC(FieldDescriptorProto_label)(proto) == kUpb_Label_Required) { - if (syntax == kUpb_Syntax_Proto3) { - _upb_DefBuilder_Errf(ctx, "proto3 fields cannot be required (%s)", - f->full_name); - } - int val = UPB_DESC(FeatureSet_LEGACY_REQUIRED); - UPB_DESC(FeatureSet_set_field_presence(features, val)); - ret = true; - } + return i; +} - if (UPB_DESC(FieldDescriptorProto_type)(proto) == kUpb_FieldType_Group) { - int val = UPB_DESC(FeatureSet_DELIMITED); - UPB_DESC(FeatureSet_set_message_encoding(features, val)); - ret = true; - } +static size_t begin(const upb_table* t) { return next(t, -1); } - if (UPB_DESC(FieldOptions_has_packed)(options)) { - int val = UPB_DESC(FieldOptions_packed)(options) - ? UPB_DESC(FeatureSet_PACKED) - : UPB_DESC(FeatureSet_EXPANDED); - UPB_DESC(FeatureSet_set_repeated_field_encoding(features, val)); - ret = true; - } +/* upb_strtable ***************************************************************/ -// begin:google_only -// #ifndef UPB_BOOTSTRAP_STAGE0 -// if (syntax == kUpb_Syntax_Proto3 && -// UPB_DESC(FieldOptions_has_enforce_utf8)(options) && -// !UPB_DESC(FieldOptions_enforce_utf8)(options)) { -// int val = UPB_DESC(FeatureSet_UNVERIFIED); -// UPB_DESC(FeatureSet_set_utf8_validation(features, val)); -// ret = true; -// } -// #endif -// // clang-format off -// end:google_only - // clang-format on +/* A simple "subclass" of upb_table that only adds a hash function for strings. + */ - return ret; +static upb_tabkey strcopy(lookupkey_t k2, upb_Arena* a) { + uint32_t len = (uint32_t)k2.str.len; + char* str = upb_Arena_Malloc(a, k2.str.len + sizeof(uint32_t) + 1); + if (str == NULL) return 0; + memcpy(str, &len, sizeof(uint32_t)); + if (k2.str.len) memcpy(str + sizeof(uint32_t), k2.str.str, k2.str.len); + str[sizeof(uint32_t) + k2.str.len] = '\0'; + return (uintptr_t)str; } -static void _upb_FieldDef_Create(upb_DefBuilder* ctx, const char* prefix, - const UPB_DESC(FeatureSet*) parent_features, - const UPB_DESC(FieldDescriptorProto*) - field_proto, - upb_MessageDef* m, upb_FieldDef* f) { - // Must happen before _upb_DefBuilder_Add() - f->file = _upb_DefBuilder_File(ctx); +/* Adapted from ABSL's wyhash. */ - const upb_StringView name = UPB_DESC(FieldDescriptorProto_name)(field_proto); - f->full_name = _upb_DefBuilder_MakeFullName(ctx, prefix, name); - f->label_ = (int)UPB_DESC(FieldDescriptorProto_label)(field_proto); - f->number_ = UPB_DESC(FieldDescriptorProto_number)(field_proto); - f->is_proto3_optional = - UPB_DESC(FieldDescriptorProto_proto3_optional)(field_proto); - f->msgdef = m; - f->scope.oneof = NULL; +static uint64_t UnalignedLoad64(const void* p) { + uint64_t val; + memcpy(&val, p, 8); + return val; +} - UPB_DEF_SET_OPTIONS(f->opts, FieldDescriptorProto, FieldOptions, field_proto); +static uint32_t UnalignedLoad32(const void* p) { + uint32_t val; + memcpy(&val, p, 4); + return val; +} - upb_Syntax syntax = upb_FileDef_Syntax(f->file); - const UPB_DESC(FeatureSet*) unresolved_features = - UPB_DESC(FieldOptions_features)(f->opts); - bool implicit = false; +#if defined(_MSC_VER) && defined(_M_X64) +#include +#endif - if (syntax != kUpb_Syntax_Editions) { - upb_Message_Clear(UPB_UPCAST(ctx->legacy_features), - UPB_DESC_MINITABLE(FeatureSet)); - if (_upb_FieldDef_InferLegacyFeatures(ctx, f, field_proto, f->opts, syntax, - ctx->legacy_features)) { - implicit = true; - unresolved_features = ctx->legacy_features; - } - } +/* Computes a * b, returning the low 64 bits of the result and storing the high + * 64 bits in |*high|. */ +static uint64_t upb_umul128(uint64_t v0, uint64_t v1, uint64_t* out_high) { +#ifdef __SIZEOF_INT128__ + __uint128_t p = v0; + p *= v1; + *out_high = (uint64_t)(p >> 64); + return (uint64_t)p; +#elif defined(_MSC_VER) && defined(_M_X64) + return _umul128(v0, v1, out_high); +#else + uint64_t a32 = v0 >> 32; + uint64_t a00 = v0 & 0xffffffff; + uint64_t b32 = v1 >> 32; + uint64_t b00 = v1 & 0xffffffff; + uint64_t high = a32 * b32; + uint64_t low = a00 * b00; + uint64_t mid1 = a32 * b00; + uint64_t mid2 = a00 * b32; + low += (mid1 << 32) + (mid2 << 32); + // Omit carry bit, for mixing we do not care about exact numerical precision. + high += (mid1 >> 32) + (mid2 >> 32); + *out_high = high; + return low; +#endif +} - if (UPB_DESC(FieldDescriptorProto_has_oneof_index)(field_proto)) { - int oneof_index = UPB_DESC(FieldDescriptorProto_oneof_index)(field_proto); +static uint64_t WyhashMix(uint64_t v0, uint64_t v1) { + uint64_t high; + uint64_t low = upb_umul128(v0, v1, &high); + return low ^ high; +} - if (!m) { - _upb_DefBuilder_Errf(ctx, "oneof field (%s) has no containing msg", - f->full_name); - } +static uint64_t Wyhash(const void* data, size_t len, uint64_t seed, + const uint64_t salt[]) { + const uint8_t* ptr = (const uint8_t*)data; + uint64_t starting_length = (uint64_t)len; + uint64_t current_state = seed ^ salt[0]; - if (oneof_index >= upb_MessageDef_OneofCount(m)) { - _upb_DefBuilder_Errf(ctx, "oneof_index out of range (%s)", f->full_name); - } + if (len > 64) { + // If we have more than 64 bytes, we're going to handle chunks of 64 + // bytes at a time. We're going to build up two separate hash states + // which we will then hash together. + uint64_t duplicated_state = current_state; - upb_OneofDef* oneof = (upb_OneofDef*)upb_MessageDef_Oneof(m, oneof_index); - f->scope.oneof = oneof; - parent_features = upb_OneofDef_ResolvedFeatures(oneof); + do { + uint64_t a = UnalignedLoad64(ptr); + uint64_t b = UnalignedLoad64(ptr + 8); + uint64_t c = UnalignedLoad64(ptr + 16); + uint64_t d = UnalignedLoad64(ptr + 24); + uint64_t e = UnalignedLoad64(ptr + 32); + uint64_t f = UnalignedLoad64(ptr + 40); + uint64_t g = UnalignedLoad64(ptr + 48); + uint64_t h = UnalignedLoad64(ptr + 56); - _upb_OneofDef_Insert(ctx, oneof, f, name.data, name.size); - } + uint64_t cs0 = WyhashMix(a ^ salt[1], b ^ current_state); + uint64_t cs1 = WyhashMix(c ^ salt[2], d ^ current_state); + current_state = (cs0 ^ cs1); - f->resolved_features = _upb_DefBuilder_DoResolveFeatures( - ctx, parent_features, unresolved_features, implicit); + uint64_t ds0 = WyhashMix(e ^ salt[3], f ^ duplicated_state); + uint64_t ds1 = WyhashMix(g ^ salt[4], h ^ duplicated_state); + duplicated_state = (ds0 ^ ds1); - if (!UPB_DESC(FieldDescriptorProto_has_name)(field_proto)) { - _upb_DefBuilder_Errf(ctx, "field has no name"); - } + ptr += 64; + len -= 64; + } while (len > 64); - f->has_json_name = UPB_DESC(FieldDescriptorProto_has_json_name)(field_proto); - if (f->has_json_name) { - const upb_StringView sv = - UPB_DESC(FieldDescriptorProto_json_name)(field_proto); - f->json_name = upb_strdup2(sv.data, sv.size, ctx->arena); - } else { - f->json_name = make_json_name(name.data, name.size, ctx->arena); + current_state = current_state ^ duplicated_state; } - if (!f->json_name) _upb_DefBuilder_OomErr(ctx); - const bool has_type = UPB_DESC(FieldDescriptorProto_has_type)(field_proto); - const bool has_type_name = - UPB_DESC(FieldDescriptorProto_has_type_name)(field_proto); + // We now have a data `ptr` with at most 64 bytes and the current state + // of the hashing state machine stored in current_state. + while (len > 16) { + uint64_t a = UnalignedLoad64(ptr); + uint64_t b = UnalignedLoad64(ptr + 8); - f->type_ = (int)UPB_DESC(FieldDescriptorProto_type)(field_proto); + current_state = WyhashMix(a ^ salt[1], b ^ current_state); - if (has_type) { - switch (f->type_) { - case kUpb_FieldType_Message: - case kUpb_FieldType_Group: - case kUpb_FieldType_Enum: - if (!has_type_name) { - _upb_DefBuilder_Errf(ctx, "field of type %d requires type name (%s)", - (int)f->type_, f->full_name); - } - break; - default: - if (has_type_name) { - _upb_DefBuilder_Errf( - ctx, "invalid type for field with type_name set (%s, %d)", - f->full_name, (int)f->type_); - } - } + ptr += 16; + len -= 16; } - if (!has_type && has_type_name) { - f->type_ = - UPB_FIELD_TYPE_UNSPECIFIED; // We'll assign this in resolve_subdef() + // We now have a data `ptr` with at most 16 bytes. + uint64_t a = 0; + uint64_t b = 0; + if (len > 8) { + // When we have at least 9 and at most 16 bytes, set A to the first 64 + // bits of the input and B to the last 64 bits of the input. Yes, they will + // overlap in the middle if we are working with less than the full 16 + // bytes. + a = UnalignedLoad64(ptr); + b = UnalignedLoad64(ptr + len - 8); + } else if (len > 3) { + // If we have at least 4 and at most 8 bytes, set A to the first 32 + // bits and B to the last 32 bits. + a = UnalignedLoad32(ptr); + b = UnalignedLoad32(ptr + len - 4); + } else if (len > 0) { + // If we have at least 1 and at most 3 bytes, read all of the provided + // bits into A, with some adjustments. + a = ((ptr[0] << 16) | (ptr[len >> 1] << 8) | ptr[len - 1]); + b = 0; } else { - if (f->type_ < kUpb_FieldType_Double || f->type_ > kUpb_FieldType_SInt64) { - _upb_DefBuilder_Errf(ctx, "invalid type for field %s (%d)", f->full_name, - f->type_); - } + a = 0; + b = 0; } - if (f->label_ < kUpb_Label_Optional || f->label_ > kUpb_Label_Repeated) { - _upb_DefBuilder_Errf(ctx, "invalid label for field %s (%d)", f->full_name, - f->label_); - } + uint64_t w = WyhashMix(a ^ salt[1], b ^ current_state); + uint64_t z = salt[1] ^ starting_length; + return WyhashMix(w, z); +} - /* We can't resolve the subdef or (in the case of extensions) the containing - * message yet, because it may not have been defined yet. We stash a pointer - * to the field_proto until later when we can properly resolve it. */ - f->sub.unresolved = field_proto; +const uint64_t kWyhashSalt[5] = { + 0x243F6A8885A308D3ULL, 0x13198A2E03707344ULL, 0xA4093822299F31D0ULL, + 0x082EFA98EC4E6C89ULL, 0x452821E638D01377ULL, +}; - if (UPB_DESC(FieldDescriptorProto_has_oneof_index)(field_proto)) { - if (upb_FieldDef_Label(f) != kUpb_Label_Optional) { - _upb_DefBuilder_Errf(ctx, "fields in oneof must have OPTIONAL label (%s)", - f->full_name); - } - } +uint32_t _upb_Hash(const void* p, size_t n, uint64_t seed) { + return Wyhash(p, n, seed, kWyhashSalt); +} - f->has_presence = - (!upb_FieldDef_IsRepeated(f)) && - (f->type_ == kUpb_FieldType_Message || f->type_ == kUpb_FieldType_Group || - upb_FieldDef_ContainingOneof(f) || - UPB_DESC(FeatureSet_field_presence)(f->resolved_features) != - UPB_DESC(FeatureSet_IMPLICIT)); +static uint32_t _upb_Hash_NoSeed(const char* p, size_t n) { + return _upb_Hash(p, n, 0); } -static void _upb_FieldDef_CreateExt(upb_DefBuilder* ctx, const char* prefix, - const UPB_DESC(FeatureSet*) parent_features, - const UPB_DESC(FieldDescriptorProto*) - field_proto, - upb_MessageDef* m, upb_FieldDef* f) { - f->is_extension = true; - _upb_FieldDef_Create(ctx, prefix, parent_features, field_proto, m, f); +static uint32_t strhash(upb_tabkey key) { + uint32_t len; + char* str = upb_tabstr(key, &len); + return _upb_Hash_NoSeed(str, len); +} - if (UPB_DESC(FieldDescriptorProto_has_oneof_index)(field_proto)) { - _upb_DefBuilder_Errf(ctx, "oneof_index provided for extension field (%s)", - f->full_name); - } +static bool streql(upb_tabkey k1, lookupkey_t k2) { + uint32_t len; + char* str = upb_tabstr(k1, &len); + return len == k2.str.len && (len == 0 || memcmp(str, k2.str.str, len) == 0); +} - f->scope.extension_scope = m; - _upb_DefBuilder_Add(ctx, f->full_name, _upb_DefType_Pack(f, UPB_DEFTYPE_EXT)); - f->layout_index = ctx->ext_count++; +bool upb_strtable_init(upb_strtable* t, size_t expected_size, upb_Arena* a) { + // Multiply by approximate reciprocal of MAX_LOAD (0.85), with pow2 + // denominator. + size_t need_entries = (expected_size + 1) * 1204 / 1024; + UPB_ASSERT(need_entries >= expected_size * 0.85); + int size_lg2 = upb_Log2Ceiling(need_entries); + return init(&t->t, size_lg2, a); +} - if (ctx->layout) { - UPB_ASSERT(upb_MiniTableExtension_Number( - _upb_FieldDef_ExtensionMiniTable(f)) == f->number_); +void upb_strtable_clear(upb_strtable* t) { + size_t bytes = upb_table_size(&t->t) * sizeof(upb_tabent); + t->t.count = 0; + memset((char*)t->t.entries, 0, bytes); +} + +bool upb_strtable_resize(upb_strtable* t, size_t size_lg2, upb_Arena* a) { + upb_strtable new_table; + if (!init(&new_table.t, size_lg2, a)) return false; + + intptr_t iter = UPB_STRTABLE_BEGIN; + upb_StringView key; + upb_value val; + while (upb_strtable_next2(t, &key, &val, &iter)) { + upb_strtable_insert(&new_table, key.data, key.size, val, a); } + *t = new_table; + return true; } -static void _upb_FieldDef_CreateNotExt(upb_DefBuilder* ctx, const char* prefix, - const UPB_DESC(FeatureSet*) - parent_features, - const UPB_DESC(FieldDescriptorProto*) - field_proto, - upb_MessageDef* m, upb_FieldDef* f) { - f->is_extension = false; - _upb_FieldDef_Create(ctx, prefix, parent_features, field_proto, m, f); +bool upb_strtable_insert(upb_strtable* t, const char* k, size_t len, + upb_value v, upb_Arena* a) { + lookupkey_t key; + upb_tabkey tabkey; + uint32_t hash; - if (!UPB_DESC(FieldDescriptorProto_has_oneof_index)(field_proto)) { - if (f->is_proto3_optional) { - _upb_DefBuilder_Errf( - ctx, - "non-extension field (%s) with proto3_optional was not in a oneof", - f->full_name); + if (isfull(&t->t)) { + /* Need to resize. New table of double the size, add old elements to it. */ + if (!upb_strtable_resize(t, t->t.size_lg2 + 1, a)) { + return false; } } - _upb_MessageDef_InsertField(ctx, m, f); + key = strkey2(k, len); + tabkey = strcopy(key, a); + if (tabkey == 0) return false; + + hash = _upb_Hash_NoSeed(key.str.str, key.str.len); + insert(&t->t, key, tabkey, v, hash, &strhash, &streql); + return true; } -upb_FieldDef* _upb_Extensions_New(upb_DefBuilder* ctx, int n, - const UPB_DESC(FieldDescriptorProto*) - const* protos, - const UPB_DESC(FeatureSet*) parent_features, - const char* prefix, upb_MessageDef* m) { - _upb_DefType_CheckPadding(sizeof(upb_FieldDef)); - upb_FieldDef* defs = - (upb_FieldDef*)_upb_DefBuilder_Alloc(ctx, sizeof(upb_FieldDef) * n); +bool upb_strtable_lookup2(const upb_strtable* t, const char* key, size_t len, + upb_value* v) { + uint32_t hash = _upb_Hash_NoSeed(key, len); + return lookup(&t->t, strkey2(key, len), v, hash, &streql); +} - for (int i = 0; i < n; i++) { - upb_FieldDef* f = &defs[i]; +bool upb_strtable_remove2(upb_strtable* t, const char* key, size_t len, + upb_value* val) { + uint32_t hash = _upb_Hash_NoSeed(key, len); + upb_tabkey tabkey; + return rm(&t->t, strkey2(key, len), val, &tabkey, hash, &streql); +} - _upb_FieldDef_CreateExt(ctx, prefix, parent_features, protos[i], m, f); - f->index_ = i; - } +/* Iteration */ - return defs; +void upb_strtable_begin(upb_strtable_iter* i, const upb_strtable* t) { + i->t = t; + i->index = begin(&t->t); } -upb_FieldDef* _upb_FieldDefs_New(upb_DefBuilder* ctx, int n, - const UPB_DESC(FieldDescriptorProto*) - const* protos, - const UPB_DESC(FeatureSet*) parent_features, - const char* prefix, upb_MessageDef* m, - bool* is_sorted) { - _upb_DefType_CheckPadding(sizeof(upb_FieldDef)); - upb_FieldDef* defs = - (upb_FieldDef*)_upb_DefBuilder_Alloc(ctx, sizeof(upb_FieldDef) * n); +void upb_strtable_next(upb_strtable_iter* i) { + i->index = next(&i->t->t, i->index); +} - uint32_t previous = 0; - for (int i = 0; i < n; i++) { - upb_FieldDef* f = &defs[i]; +bool upb_strtable_done(const upb_strtable_iter* i) { + if (!i->t) return true; + return i->index >= upb_table_size(&i->t->t) || + upb_tabent_isempty(str_tabent(i)); +} - _upb_FieldDef_CreateNotExt(ctx, prefix, parent_features, protos[i], m, f); - f->index_ = i; - if (!ctx->layout) { - // Speculate that the def fields are sorted. We will always sort the - // MiniTable fields, so if defs are sorted then indices will match. - // - // If this is incorrect, we will overwrite later. - f->layout_index = i; - } +upb_StringView upb_strtable_iter_key(const upb_strtable_iter* i) { + upb_StringView key; + uint32_t len; + UPB_ASSERT(!upb_strtable_done(i)); + key.data = upb_tabstr(str_tabent(i)->key, &len); + key.size = len; + return key; +} - const uint32_t current = f->number_; - if (previous > current) *is_sorted = false; - previous = current; - } +upb_value upb_strtable_iter_value(const upb_strtable_iter* i) { + UPB_ASSERT(!upb_strtable_done(i)); + return _upb_value_val(str_tabent(i)->val.val); +} - return defs; +void upb_strtable_iter_setdone(upb_strtable_iter* i) { + i->t = NULL; + i->index = SIZE_MAX; } -static void resolve_subdef(upb_DefBuilder* ctx, const char* prefix, - upb_FieldDef* f) { - const UPB_DESC(FieldDescriptorProto)* field_proto = f->sub.unresolved; - upb_StringView name = UPB_DESC(FieldDescriptorProto_type_name)(field_proto); - bool has_name = UPB_DESC(FieldDescriptorProto_has_type_name)(field_proto); - switch ((int)f->type_) { - case UPB_FIELD_TYPE_UNSPECIFIED: { - // Type was not specified and must be inferred. - UPB_ASSERT(has_name); - upb_deftype_t type; - const void* def = - _upb_DefBuilder_ResolveAny(ctx, f->full_name, prefix, name, &type); - switch (type) { - case UPB_DEFTYPE_ENUM: - f->sub.enumdef = def; - f->type_ = kUpb_FieldType_Enum; - break; - case UPB_DEFTYPE_MSG: - f->sub.msgdef = def; - f->type_ = kUpb_FieldType_Message; // It appears there is no way of - // this being a group. - f->has_presence = !upb_FieldDef_IsRepeated(f); - break; - default: - _upb_DefBuilder_Errf(ctx, "Couldn't resolve type name for field %s", - f->full_name); - } - break; - } - case kUpb_FieldType_Message: - case kUpb_FieldType_Group: - UPB_ASSERT(has_name); - f->sub.msgdef = _upb_DefBuilder_Resolve(ctx, f->full_name, prefix, name, - UPB_DEFTYPE_MSG); - break; - case kUpb_FieldType_Enum: - UPB_ASSERT(has_name); - f->sub.enumdef = _upb_DefBuilder_Resolve(ctx, f->full_name, prefix, name, - UPB_DEFTYPE_ENUM); - break; - default: - // No resolution necessary. - break; +bool upb_strtable_iter_isequal(const upb_strtable_iter* i1, + const upb_strtable_iter* i2) { + if (upb_strtable_done(i1) && upb_strtable_done(i2)) return true; + return i1->t == i2->t && i1->index == i2->index; +} + +/* upb_inttable ***************************************************************/ + +/* For inttables we use a hybrid structure where small keys are kept in an + * array and large keys are put in the hash table. */ + +static uint32_t inthash(upb_tabkey key) { return upb_inthash(key); } + +static bool inteql(upb_tabkey k1, lookupkey_t k2) { return k1 == k2.num; } + +static upb_tabval* mutable_array(upb_inttable* t) { + return (upb_tabval*)t->array; +} + +static upb_tabval* inttable_val(upb_inttable* t, uintptr_t key) { + if (key < t->array_size) { + return upb_arrhas(t->array[key]) ? &(mutable_array(t)[key]) : NULL; + } else { + upb_tabent* e = + findentry_mutable(&t->t, intkey(key), upb_inthash(key), &inteql); + return e ? &e->val : NULL; } } -static int _upb_FieldDef_Compare(const void* p1, const void* p2) { - const uint32_t v1 = (*(upb_FieldDef**)p1)->number_; - const uint32_t v2 = (*(upb_FieldDef**)p2)->number_; - return (v1 < v2) ? -1 : (v1 > v2); +static const upb_tabval* inttable_val_const(const upb_inttable* t, + uintptr_t key) { + return inttable_val((upb_inttable*)t, key); } -// _upb_FieldDefs_Sorted() is mostly a pure function of its inputs, but has one -// critical side effect that we depend on: it sets layout_index appropriately -// for non-sorted lists of fields. -const upb_FieldDef** _upb_FieldDefs_Sorted(const upb_FieldDef* f, int n, - upb_Arena* a) { - // TODO: Replace this arena alloc with a persistent scratch buffer. - upb_FieldDef** out = (upb_FieldDef**)upb_Arena_Malloc(a, n * sizeof(void*)); - if (!out) return NULL; +size_t upb_inttable_count(const upb_inttable* t) { + return t->t.count + t->array_count; +} - for (int i = 0; i < n; i++) { - out[i] = (upb_FieldDef*)&f[i]; +static void check(upb_inttable* t) { + UPB_UNUSED(t); +#if defined(UPB_DEBUG_TABLE) && !defined(NDEBUG) + { + // This check is very expensive (makes inserts/deletes O(N)). + size_t count = 0; + intptr_t iter = UPB_INTTABLE_BEGIN; + uintptr_t key; + upb_value val; + while (upb_inttable_next(t, &key, &val, &iter)) { + UPB_ASSERT(upb_inttable_lookup(t, key, NULL)); + } + UPB_ASSERT(count == upb_inttable_count(t)); } - qsort(out, n, sizeof(void*), _upb_FieldDef_Compare); +#endif +} - for (int i = 0; i < n; i++) { - out[i]->layout_index = i; +bool upb_inttable_sizedinit(upb_inttable* t, size_t asize, int hsize_lg2, + upb_Arena* a) { + size_t array_bytes; + + if (!init(&t->t, hsize_lg2, a)) return false; + /* Always make the array part at least 1 long, so that we know key 0 + * won't be in the hash part, which simplifies things. */ + t->array_size = UPB_MAX(1, asize); + t->array_count = 0; + array_bytes = t->array_size * sizeof(upb_value); + t->array = upb_Arena_Malloc(a, array_bytes); + if (!t->array) { + return false; } - return (const upb_FieldDef**)out; + memset(mutable_array(t), 0xff, array_bytes); + check(t); + return true; } -bool upb_FieldDef_MiniDescriptorEncode(const upb_FieldDef* f, upb_Arena* a, - upb_StringView* out) { - UPB_ASSERT(f->is_extension); +bool upb_inttable_init(upb_inttable* t, upb_Arena* a) { + return upb_inttable_sizedinit(t, 0, 4, a); +} - upb_DescState s; - _upb_DescState_Init(&s); +bool upb_inttable_insert(upb_inttable* t, uintptr_t key, upb_value val, + upb_Arena* a) { + upb_tabval tabval; + tabval.val = val.val; + UPB_ASSERT( + upb_arrhas(tabval)); /* This will reject (uint64_t)-1. Fix this. */ - const int number = upb_FieldDef_Number(f); - const uint64_t modifiers = _upb_FieldDef_Modifiers(f); + if (key < t->array_size) { + UPB_ASSERT(!upb_arrhas(t->array[key])); + t->array_count++; + mutable_array(t)[key].val = val.val; + } else { + if (isfull(&t->t)) { + /* Need to resize the hash part, but we re-use the array part. */ + size_t i; + upb_table new_table; - if (!_upb_DescState_Grow(&s, a)) return false; - s.ptr = upb_MtDataEncoder_EncodeExtension(&s.e, s.ptr, f->type_, number, - modifiers); - *s.ptr = '\0'; + if (!init(&new_table, t->t.size_lg2 + 1, a)) { + return false; + } - out->data = s.buf; - out->size = s.ptr - s.buf; - return true; -} + for (i = begin(&t->t); i < upb_table_size(&t->t); i = next(&t->t, i)) { + const upb_tabent* e = &t->t.entries[i]; + uint32_t hash; + upb_value v; -static void resolve_extension(upb_DefBuilder* ctx, const char* prefix, - upb_FieldDef* f, - const UPB_DESC(FieldDescriptorProto) * - field_proto) { - if (!UPB_DESC(FieldDescriptorProto_has_extendee)(field_proto)) { - _upb_DefBuilder_Errf(ctx, "extension for field '%s' had no extendee", - f->full_name); - } + _upb_value_setval(&v, e->val.val); + hash = upb_inthash(e->key); + insert(&new_table, intkey(e->key), e->key, v, hash, &inthash, &inteql); + } - upb_StringView name = UPB_DESC(FieldDescriptorProto_extendee)(field_proto); - const upb_MessageDef* m = - _upb_DefBuilder_Resolve(ctx, f->full_name, prefix, name, UPB_DEFTYPE_MSG); - f->msgdef = m; + UPB_ASSERT(t->t.count == new_table.count); - if (!_upb_MessageDef_IsValidExtensionNumber(m, f->number_)) { - _upb_DefBuilder_Errf( - ctx, - "field number %u in extension %s has no extension range in message %s", - (unsigned)f->number_, f->full_name, upb_MessageDef_FullName(m)); + t->t = new_table; + } + insert(&t->t, intkey(key), key, val, upb_inthash(key), &inthash, &inteql); } + check(t); + return true; } -void _upb_FieldDef_BuildMiniTableExtension(upb_DefBuilder* ctx, - const upb_FieldDef* f) { - const upb_MiniTableExtension* ext = _upb_FieldDef_ExtensionMiniTable(f); +bool upb_inttable_lookup(const upb_inttable* t, uintptr_t key, upb_value* v) { + const upb_tabval* table_v = inttable_val_const(t, key); + if (!table_v) return false; + if (v) _upb_value_setval(v, table_v->val); + return true; +} - if (ctx->layout) { - UPB_ASSERT(upb_FieldDef_Number(f) == upb_MiniTableExtension_Number(ext)); - } else { - upb_StringView desc; - if (!upb_FieldDef_MiniDescriptorEncode(f, ctx->tmp_arena, &desc)) { - _upb_DefBuilder_OomErr(ctx); - } +bool upb_inttable_replace(upb_inttable* t, uintptr_t key, upb_value val) { + upb_tabval* table_v = inttable_val(t, key); + if (!table_v) return false; + table_v->val = val.val; + return true; +} - upb_MiniTableExtension* mut_ext = (upb_MiniTableExtension*)ext; - upb_MiniTableSub sub = {NULL}; - if (upb_FieldDef_IsSubMessage(f)) { - const upb_MiniTable* submsg = upb_MessageDef_MiniTable(f->sub.msgdef); - sub = upb_MiniTableSub_FromMessage(submsg); - } else if (_upb_FieldDef_IsClosedEnum(f)) { - const upb_MiniTableEnum* subenum = _upb_EnumDef_MiniTable(f->sub.enumdef); - sub = upb_MiniTableSub_FromEnum(subenum); +bool upb_inttable_remove(upb_inttable* t, uintptr_t key, upb_value* val) { + bool success; + if (key < t->array_size) { + if (upb_arrhas(t->array[key])) { + upb_tabval empty = UPB_TABVALUE_EMPTY_INIT; + t->array_count--; + if (val) { + _upb_value_setval(val, t->array[key].val); + } + mutable_array(t)[key] = empty; + success = true; + } else { + success = false; } - bool ok2 = upb_MiniTableExtension_Init(desc.data, desc.size, mut_ext, - upb_MessageDef_MiniTable(f->msgdef), - sub, ctx->status); - if (!ok2) _upb_DefBuilder_Errf(ctx, "Could not build extension mini table"); + } else { + success = rm(&t->t, intkey(key), val, NULL, upb_inthash(key), &inteql); } - - bool ok = _upb_DefPool_InsertExt(ctx->symtab, ext, f); - if (!ok) _upb_DefBuilder_OomErr(ctx); + check(t); + return success; } -static void resolve_default(upb_DefBuilder* ctx, upb_FieldDef* f, - const UPB_DESC(FieldDescriptorProto) * - field_proto) { - // Have to delay resolving of the default value until now because of the enum - // case, since enum defaults are specified with a label. - if (UPB_DESC(FieldDescriptorProto_has_default_value)(field_proto)) { - upb_StringView defaultval = - UPB_DESC(FieldDescriptorProto_default_value)(field_proto); +void upb_inttable_compact(upb_inttable* t, upb_Arena* a) { + /* A power-of-two histogram of the table keys. */ + size_t counts[UPB_MAXARRSIZE + 1] = {0}; - if (upb_FileDef_Syntax(f->file) == kUpb_Syntax_Proto3) { - _upb_DefBuilder_Errf(ctx, - "proto3 fields cannot have explicit defaults (%s)", - f->full_name); + /* The max key in each bucket. */ + uintptr_t max[UPB_MAXARRSIZE + 1] = {0}; + + { + intptr_t iter = UPB_INTTABLE_BEGIN; + uintptr_t key; + upb_value val; + while (upb_inttable_next(t, &key, &val, &iter)) { + int bucket = log2ceil(key); + max[bucket] = UPB_MAX(max[bucket], key); + counts[bucket]++; } + } - if (upb_FieldDef_IsSubMessage(f)) { - _upb_DefBuilder_Errf(ctx, - "message fields cannot have explicit defaults (%s)", - f->full_name); + /* Find the largest power of two that satisfies the MIN_DENSITY + * definition (while actually having some keys). */ + size_t arr_count = upb_inttable_count(t); + int size_lg2; + upb_inttable new_t; + + for (size_lg2 = ARRAY_SIZE(counts) - 1; size_lg2 > 0; size_lg2--) { + if (counts[size_lg2] == 0) { + /* We can halve again without losing any entries. */ + continue; + } else if (arr_count >= (1 << size_lg2) * MIN_DENSITY) { + break; } - parse_default(ctx, defaultval.data, defaultval.size, f); - f->has_default = true; - } else { - set_default_default(ctx, f); - f->has_default = false; + arr_count -= counts[size_lg2]; } -} -void _upb_FieldDef_Resolve(upb_DefBuilder* ctx, const char* prefix, - upb_FieldDef* f) { - // We have to stash this away since resolve_subdef() may overwrite it. - const UPB_DESC(FieldDescriptorProto)* field_proto = f->sub.unresolved; + UPB_ASSERT(arr_count <= upb_inttable_count(t)); + + { + /* Insert all elements into new, perfectly-sized table. */ + size_t arr_size = max[size_lg2] + 1; /* +1 so arr[max] will fit. */ + size_t hash_count = upb_inttable_count(t) - arr_count; + size_t hash_size = hash_count ? (hash_count / MAX_LOAD) + 1 : 0; + int hashsize_lg2 = log2ceil(hash_size); + + upb_inttable_sizedinit(&new_t, arr_size, hashsize_lg2, a); - resolve_subdef(ctx, prefix, f); - resolve_default(ctx, f, field_proto); + { + intptr_t iter = UPB_INTTABLE_BEGIN; + uintptr_t key; + upb_value val; + while (upb_inttable_next(t, &key, &val, &iter)) { + upb_inttable_insert(&new_t, key, val, a); + } + } - if (f->is_extension) { - resolve_extension(ctx, prefix, f, field_proto); + UPB_ASSERT(new_t.array_size == arr_size); + UPB_ASSERT(new_t.t.size_lg2 == hashsize_lg2); } + *t = new_t; } +// Iteration. -#include -#include -#include +bool upb_inttable_next(const upb_inttable* t, uintptr_t* key, upb_value* val, + intptr_t* iter) { + intptr_t i = *iter; + if ((size_t)(i + 1) <= t->array_size) { + while ((size_t)++i < t->array_size) { + upb_tabval ent = t->array[i]; + if (upb_arrhas(ent)) { + *key = i; + *val = _upb_value_val(ent.val); + *iter = i; + return true; + } + } + i--; // Back up to exactly one position before the start of the table. + } + size_t tab_idx = next(&t->t, i - t->array_size); + if (tab_idx < upb_table_size(&t->t)) { + upb_tabent* ent = &t->t.entries[tab_idx]; + *key = ent->key; + *val = _upb_value_val(ent->val.val); + *iter = tab_idx + t->array_size; + return true; + } -// Must be last. + return false; +} -struct upb_FileDef { - const UPB_DESC(FileOptions*) opts; - const UPB_DESC(FeatureSet*) resolved_features; - const char* name; - const char* package; - UPB_DESC(Edition) edition; +void upb_inttable_removeiter(upb_inttable* t, intptr_t* iter) { + intptr_t i = *iter; + if ((size_t)i < t->array_size) { + t->array_count--; + mutable_array(t)[i].val = -1; + } else { + upb_tabent* ent = &t->t.entries[i - t->array_size]; + upb_tabent* prev = NULL; - const upb_FileDef** deps; - const int32_t* public_deps; - const int32_t* weak_deps; - const upb_MessageDef* top_lvl_msgs; - const upb_EnumDef* top_lvl_enums; - const upb_FieldDef* top_lvl_exts; - const upb_ServiceDef* services; - const upb_MiniTableExtension** ext_layouts; - const upb_DefPool* symtab; + // Linear search, not great. + upb_tabent* end = &t->t.entries[upb_table_size(&t->t)]; + for (upb_tabent* e = t->t.entries; e != end; e++) { + if (e->next == ent) { + prev = e; + break; + } + } - int dep_count; - int public_dep_count; - int weak_dep_count; - int top_lvl_msg_count; - int top_lvl_enum_count; - int top_lvl_ext_count; - int service_count; - int ext_count; // All exts in the file. - upb_Syntax syntax; -}; + if (prev) { + prev->next = ent->next; + } -UPB_API const char* upb_FileDef_EditionName(int edition) { - // TODO Synchronize this with descriptor.proto better. - switch (edition) { - case UPB_DESC(EDITION_PROTO2): - return "PROTO2"; - case UPB_DESC(EDITION_PROTO3): - return "PROTO3"; - case UPB_DESC(EDITION_2023): - return "2023"; - default: - return "UNKNOWN"; + t->t.count--; + ent->key = 0; + ent->next = NULL; } } -const UPB_DESC(FileOptions) * upb_FileDef_Options(const upb_FileDef* f) { - return f->opts; -} +bool upb_strtable_next2(const upb_strtable* t, upb_StringView* key, + upb_value* val, intptr_t* iter) { + size_t tab_idx = next(&t->t, *iter); + if (tab_idx < upb_table_size(&t->t)) { + upb_tabent* ent = &t->t.entries[tab_idx]; + uint32_t len; + key->data = upb_tabstr(ent->key, &len); + key->size = len; + *val = _upb_value_val(ent->val.val); + *iter = tab_idx; + return true; + } -const UPB_DESC(FeatureSet) * - upb_FileDef_ResolvedFeatures(const upb_FileDef* f) { - return f->resolved_features; + return false; } -bool upb_FileDef_HasOptions(const upb_FileDef* f) { - return f->opts != (void*)kUpbDefOptDefault; -} +void upb_strtable_removeiter(upb_strtable* t, intptr_t* iter) { + intptr_t i = *iter; + upb_tabent* ent = &t->t.entries[i]; + upb_tabent* prev = NULL; -const char* upb_FileDef_Name(const upb_FileDef* f) { return f->name; } + // Linear search, not great. + upb_tabent* end = &t->t.entries[upb_table_size(&t->t)]; + for (upb_tabent* e = t->t.entries; e != end; e++) { + if (e->next == ent) { + prev = e; + break; + } + } -const char* upb_FileDef_Package(const upb_FileDef* f) { - return f->package ? f->package : ""; -} + if (prev) { + prev->next = ent->next; + } -UPB_DESC(Edition) upb_FileDef_Edition(const upb_FileDef* f) { - return f->edition; + t->t.count--; + ent->key = 0; + ent->next = NULL; } -const char* _upb_FileDef_RawPackage(const upb_FileDef* f) { return f->package; } +void upb_strtable_setentryvalue(upb_strtable* t, intptr_t iter, upb_value v) { + upb_tabent* ent = &t->t.entries[iter]; + ent->val.val = v.val; +} -upb_Syntax upb_FileDef_Syntax(const upb_FileDef* f) { return f->syntax; } -int upb_FileDef_TopLevelMessageCount(const upb_FileDef* f) { - return f->top_lvl_msg_count; -} +// Must be last. -int upb_FileDef_DependencyCount(const upb_FileDef* f) { return f->dep_count; } +const char* upb_BufToUint64(const char* ptr, const char* end, uint64_t* val) { + uint64_t u64 = 0; + while (ptr < end) { + unsigned ch = *ptr - '0'; + if (ch >= 10) break; + if (u64 > UINT64_MAX / 10 || u64 * 10 > UINT64_MAX - ch) { + return NULL; // integer overflow + } + u64 *= 10; + u64 += ch; + ptr++; + } -int upb_FileDef_PublicDependencyCount(const upb_FileDef* f) { - return f->public_dep_count; + *val = u64; + return ptr; } -int upb_FileDef_WeakDependencyCount(const upb_FileDef* f) { - return f->weak_dep_count; -} +const char* upb_BufToInt64(const char* ptr, const char* end, int64_t* val, + bool* is_neg) { + bool neg = false; + uint64_t u64; -const int32_t* _upb_FileDef_PublicDependencyIndexes(const upb_FileDef* f) { - return f->public_deps; -} + if (ptr != end && *ptr == '-') { + ptr++; + neg = true; + } -const int32_t* _upb_FileDef_WeakDependencyIndexes(const upb_FileDef* f) { - return f->weak_deps; -} + ptr = upb_BufToUint64(ptr, end, &u64); + if (!ptr || u64 > (uint64_t)INT64_MAX + neg) { + return NULL; // integer overflow + } -int upb_FileDef_TopLevelEnumCount(const upb_FileDef* f) { - return f->top_lvl_enum_count; + *val = neg ? -u64 : u64; + if (is_neg) *is_neg = neg; + return ptr; } -int upb_FileDef_TopLevelExtensionCount(const upb_FileDef* f) { - return f->top_lvl_ext_count; -} -int upb_FileDef_ServiceCount(const upb_FileDef* f) { return f->service_count; } +#include +#include -const upb_FileDef* upb_FileDef_Dependency(const upb_FileDef* f, int i) { - UPB_ASSERT(0 <= i && i < f->dep_count); - return f->deps[i]; -} +// Must be last. -const upb_FileDef* upb_FileDef_PublicDependency(const upb_FileDef* f, int i) { - UPB_ASSERT(0 <= i && i < f->public_dep_count); - return f->deps[f->public_deps[i]]; +/* Miscellaneous utilities ****************************************************/ + +static void upb_FixLocale(char* p) { + /* printf() is dependent on locales; sadly there is no easy and portable way + * to avoid this. This little post-processing step will translate 1,2 -> 1.2 + * since JSON needs the latter. Arguably a hack, but it is simple and the + * alternatives are far more complicated, platform-dependent, and/or larger + * in code size. */ + for (; *p; p++) { + if (*p == ',') *p = '.'; + } } -const upb_FileDef* upb_FileDef_WeakDependency(const upb_FileDef* f, int i) { - UPB_ASSERT(0 <= i && i < f->public_dep_count); - return f->deps[f->weak_deps[i]]; +void _upb_EncodeRoundTripDouble(double val, char* buf, size_t size) { + assert(size >= kUpb_RoundTripBufferSize); + snprintf(buf, size, "%.*g", DBL_DIG, val); + if (strtod(buf, NULL) != val) { + snprintf(buf, size, "%.*g", DBL_DIG + 2, val); + assert(strtod(buf, NULL) == val); + } + upb_FixLocale(buf); } -const upb_MessageDef* upb_FileDef_TopLevelMessage(const upb_FileDef* f, int i) { - UPB_ASSERT(0 <= i && i < f->top_lvl_msg_count); - return _upb_MessageDef_At(f->top_lvl_msgs, i); +void _upb_EncodeRoundTripFloat(float val, char* buf, size_t size) { + assert(size >= kUpb_RoundTripBufferSize); + snprintf(buf, size, "%.*g", FLT_DIG, val); + if (strtof(buf, NULL) != val) { + snprintf(buf, size, "%.*g", FLT_DIG + 3, val); + assert(strtof(buf, NULL) == val); + } + upb_FixLocale(buf); } -const upb_EnumDef* upb_FileDef_TopLevelEnum(const upb_FileDef* f, int i) { - UPB_ASSERT(0 <= i && i < f->top_lvl_enum_count); - return _upb_EnumDef_At(f->top_lvl_enums, i); -} -const upb_FieldDef* upb_FileDef_TopLevelExtension(const upb_FileDef* f, int i) { - UPB_ASSERT(0 <= i && i < f->top_lvl_ext_count); - return _upb_FieldDef_At(f->top_lvl_exts, i); -} +#include +#include -const upb_ServiceDef* upb_FileDef_Service(const upb_FileDef* f, int i) { - UPB_ASSERT(0 <= i && i < f->service_count); - return _upb_ServiceDef_At(f->services, i); -} +// Must be last. -const upb_DefPool* upb_FileDef_Pool(const upb_FileDef* f) { return f->symtab; } +// Determine the locale-specific radix character by calling sprintf() to print +// the number 1.5, then stripping off the digits. As far as I can tell, this +// is the only portable, thread-safe way to get the C library to divulge the +// locale's radix character. No, localeconv() is NOT thread-safe. -const upb_MiniTableExtension* _upb_FileDef_ExtensionMiniTable( - const upb_FileDef* f, int i) { - return f->ext_layouts[i]; +static int GetLocaleRadix(char *data, size_t capacity) { + char temp[16]; + const int size = snprintf(temp, sizeof(temp), "%.1f", 1.5); + UPB_ASSERT(temp[0] == '1'); + UPB_ASSERT(temp[size - 1] == '5'); + UPB_ASSERT(size < capacity); + temp[size - 1] = '\0'; + strcpy(data, temp + 1); + return size - 2; } -static char* strviewdup(upb_DefBuilder* ctx, upb_StringView view) { - char* ret = upb_strdup2(view.data, view.size, _upb_DefBuilder_Arena(ctx)); - if (!ret) _upb_DefBuilder_OomErr(ctx); - return ret; -} +// Populates a string identical to *input except that the character pointed to +// by pos (which should be '.') is replaced with the locale-specific radix. -static bool streql_view(upb_StringView view, const char* b) { - return view.size == strlen(b) && memcmp(view.data, b, view.size) == 0; +static void LocalizeRadix(const char *input, const char *pos, char *output) { + const int len1 = pos - input; + + char radix[8]; + const int len2 = GetLocaleRadix(radix, sizeof(radix)); + + memcpy(output, input, len1); + memcpy(output + len1, radix, len2); + strcpy(output + len1 + len2, input + len1 + 1); } -static int count_exts_in_msg(const UPB_DESC(DescriptorProto) * msg_proto) { - size_t n; - UPB_DESC(DescriptorProto_extension)(msg_proto, &n); - int ext_count = n; +double _upb_NoLocaleStrtod(const char *str, char **endptr) { + // We cannot simply set the locale to "C" temporarily with setlocale() + // as this is not thread-safe. Instead, we try to parse in the current + // locale first. If parsing stops at a '.' character, then this is a + // pretty good hint that we're actually in some other locale in which + // '.' is not the radix character. - const UPB_DESC(DescriptorProto)* const* nested_msgs = - UPB_DESC(DescriptorProto_nested_type)(msg_proto, &n); - for (size_t i = 0; i < n; i++) { - ext_count += count_exts_in_msg(nested_msgs[i]); + char *temp_endptr; + double result = strtod(str, &temp_endptr); + if (endptr != NULL) *endptr = temp_endptr; + if (*temp_endptr != '.') return result; + + // Parsing halted on a '.'. Perhaps we're in a different locale? Let's + // try to replace the '.' with a locale-specific radix character and + // try again. + + char localized[80]; + LocalizeRadix(str, temp_endptr, localized); + char *localized_endptr; + result = strtod(localized, &localized_endptr); + if ((localized_endptr - &localized[0]) > (temp_endptr - str)) { + // This attempt got further, so replacing the decimal must have helped. + // Update endptr to point at the right location. + if (endptr != NULL) { + // size_diff is non-zero if the localized radix has multiple bytes. + int size_diff = strlen(localized) - strlen(str); + *endptr = (char *)str + (localized_endptr - &localized[0] - size_diff); + } } - return ext_count; + return result; } -const UPB_DESC(FeatureSet*) - _upb_FileDef_FindEdition(upb_DefBuilder* ctx, int edition) { - const UPB_DESC(FeatureSetDefaults)* defaults = - upb_DefPool_FeatureSetDefaults(ctx->symtab); - int min = UPB_DESC(FeatureSetDefaults_minimum_edition)(defaults); - int max = UPB_DESC(FeatureSetDefaults_maximum_edition)(defaults); - if (edition < min) { - _upb_DefBuilder_Errf(ctx, - "Edition %s is earlier than the minimum edition %s " - "given in the defaults", - upb_FileDef_EditionName(edition), - upb_FileDef_EditionName(min)); - return NULL; +// Must be last. + +int upb_Unicode_ToUTF8(uint32_t cp, char* out) { + if (cp <= 0x7f) { + out[0] = cp; + return 1; } - if (edition > max) { - _upb_DefBuilder_Errf(ctx, - "Edition %s is later than the maximum edition %s " - "given in the defaults", - upb_FileDef_EditionName(edition), - upb_FileDef_EditionName(max)); - return NULL; + if (cp <= 0x07ff) { + out[0] = (cp >> 6) | 0xc0; + out[1] = (cp & 0x3f) | 0x80; + return 2; } - - size_t n; - const UPB_DESC(FeatureSetDefaults_FeatureSetEditionDefault)* const* d = - UPB_DESC(FeatureSetDefaults_defaults)(defaults, &n); - const UPB_DESC(FeatureSet)* ret = NULL; - for (size_t i = 0; i < n; i++) { - if (UPB_DESC(FeatureSetDefaults_FeatureSetEditionDefault_edition)(d[i]) > - edition) { - break; - } - ret = UPB_DESC(FeatureSetDefaults_FeatureSetEditionDefault_features)(d[i]); + if (cp <= 0xffff) { + out[0] = (cp >> 12) | 0xe0; + out[1] = ((cp >> 6) & 0x3f) | 0x80; + out[2] = (cp & 0x3f) | 0x80; + return 3; } - if (ret == NULL) { - _upb_DefBuilder_Errf(ctx, "No valid default found for edition %s", - upb_FileDef_EditionName(edition)); - return NULL; + if (cp <= 0x10ffff) { + out[0] = (cp >> 18) | 0xf0; + out[1] = ((cp >> 12) & 0x3f) | 0x80; + out[2] = ((cp >> 6) & 0x3f) | 0x80; + out[3] = (cp & 0x3f) | 0x80; + return 4; } - return ret; + return 0; } -// Allocate and initialize one file def, and add it to the context object. -void _upb_FileDef_Create(upb_DefBuilder* ctx, - const UPB_DESC(FileDescriptorProto) * file_proto) { - upb_FileDef* file = _upb_DefBuilder_Alloc(ctx, sizeof(upb_FileDef)); - ctx->file = file; - const UPB_DESC(DescriptorProto)* const* msgs; - const UPB_DESC(EnumDescriptorProto)* const* enums; - const UPB_DESC(FieldDescriptorProto)* const* exts; - const UPB_DESC(ServiceDescriptorProto)* const* services; - const upb_StringView* strs; - const int32_t* public_deps; - const int32_t* weak_deps; - size_t n; +#include - file->symtab = ctx->symtab; - // Count all extensions in the file, to build a flat array of layouts. - UPB_DESC(FileDescriptorProto_extension)(file_proto, &n); - int ext_count = n; - msgs = UPB_DESC(FileDescriptorProto_message_type)(file_proto, &n); - for (size_t i = 0; i < n; i++) { - ext_count += count_exts_in_msg(msgs[i]); - } - file->ext_count = ext_count; +// Must be last. - if (ctx->layout) { - // We are using the ext layouts that were passed in. - file->ext_layouts = ctx->layout->UPB_PRIVATE(exts); - const int mt_ext_count = upb_MiniTableFile_ExtensionCount(ctx->layout); - if (mt_ext_count != file->ext_count) { - _upb_DefBuilder_Errf(ctx, - "Extension count did not match layout (%d vs %d)", - mt_ext_count, file->ext_count); - } - } else { - // We are building ext layouts from scratch. - file->ext_layouts = _upb_DefBuilder_Alloc( - ctx, sizeof(*file->ext_layouts) * file->ext_count); - upb_MiniTableExtension* ext = - _upb_DefBuilder_Alloc(ctx, sizeof(*ext) * file->ext_count); - for (int i = 0; i < file->ext_count; i++) { - file->ext_layouts[i] = &ext[i]; - } - } +const struct upb_Extension* _upb_Message_Getext( + const struct upb_Message* msg, const upb_MiniTableExtension* e) { + size_t n; + const struct upb_Extension* ext = UPB_PRIVATE(_upb_Message_Getexts)(msg, &n); - upb_StringView name = UPB_DESC(FileDescriptorProto_name)(file_proto); - file->name = strviewdup(ctx, name); - if (strlen(file->name) != name.size) { - _upb_DefBuilder_Errf(ctx, "File name contained embedded NULL"); + // For now we use linear search exclusively to find extensions. + // If this becomes an issue due to messages with lots of extensions, + // we can introduce a table of some sort. + for (size_t i = 0; i < n; i++) { + if (ext[i].ext == e) { + return &ext[i]; + } } - upb_StringView package = UPB_DESC(FileDescriptorProto_package)(file_proto); + return NULL; +} - if (package.size) { - _upb_DefBuilder_CheckIdentFull(ctx, package); - file->package = strviewdup(ctx, package); +const struct upb_Extension* UPB_PRIVATE(_upb_Message_Getexts)( + const struct upb_Message* msg, size_t* count) { + upb_Message_InternalData* in = upb_Message_GetInternalData(msg); + if (in) { + *count = (in->size - in->ext_begin) / sizeof(struct upb_Extension); + return UPB_PTR_AT(in, in->ext_begin, void); } else { - file->package = NULL; + *count = 0; + return NULL; } +} - // TODO: How should we validate this? - file->edition = UPB_DESC(FileDescriptorProto_edition)(file_proto); - - if (UPB_DESC(FileDescriptorProto_has_syntax)(file_proto)) { - upb_StringView syntax = UPB_DESC(FileDescriptorProto_syntax)(file_proto); - - if (streql_view(syntax, "proto2")) { - file->syntax = kUpb_Syntax_Proto2; - file->edition = UPB_DESC(EDITION_PROTO2); - } else if (streql_view(syntax, "proto3")) { - file->syntax = kUpb_Syntax_Proto3; - file->edition = UPB_DESC(EDITION_PROTO3); - } else if (streql_view(syntax, "editions")) { - file->syntax = kUpb_Syntax_Editions; - file->edition = UPB_DESC(FileDescriptorProto_edition)(file_proto); - } else { - _upb_DefBuilder_Errf(ctx, "Invalid syntax '" UPB_STRINGVIEW_FORMAT "'", - UPB_STRINGVIEW_ARGS(syntax)); - } - } else { - file->syntax = kUpb_Syntax_Proto2; - file->edition = UPB_DESC(EDITION_PROTO2); - } +struct upb_Extension* _upb_Message_GetOrCreateExtension( + struct upb_Message* msg, const upb_MiniTableExtension* e, upb_Arena* a) { + struct upb_Extension* ext = + (struct upb_Extension*)_upb_Message_Getext(msg, e); + if (ext) return ext; + if (!UPB_PRIVATE(_upb_Message_Realloc)(msg, sizeof(struct upb_Extension), a)) + return NULL; + upb_Message_InternalData* in = upb_Message_GetInternalData(msg); + in->ext_begin -= sizeof(struct upb_Extension); + ext = UPB_PTR_AT(in, in->ext_begin, void); + memset(ext, 0, sizeof(struct upb_Extension)); + ext->ext = e; + return ext; +} - // Read options. - UPB_DEF_SET_OPTIONS(file->opts, FileDescriptorProto, FileOptions, file_proto); - // Resolve features. - const UPB_DESC(FeatureSet*) edition_defaults = - _upb_FileDef_FindEdition(ctx, file->edition); - const UPB_DESC(FeatureSet*) unresolved = - UPB_DESC(FileOptions_features)(file->opts); - file->resolved_features = - _upb_DefBuilder_ResolveFeatures(ctx, edition_defaults, unresolved); +#include +#include - // Verify dependencies. - strs = UPB_DESC(FileDescriptorProto_dependency)(file_proto, &n); - file->dep_count = n; - file->deps = _upb_DefBuilder_Alloc(ctx, sizeof(*file->deps) * n); - for (size_t i = 0; i < n; i++) { - upb_StringView str = strs[i]; - file->deps[i] = - upb_DefPool_FindFileByNameWithSize(ctx->symtab, str.data, str.size); - if (!file->deps[i]) { - _upb_DefBuilder_Errf(ctx, - "Depends on file '" UPB_STRINGVIEW_FORMAT - "', but it has not been loaded", - UPB_STRINGVIEW_ARGS(str)); - } - } +// Must be last. - public_deps = UPB_DESC(FileDescriptorProto_public_dependency)(file_proto, &n); - file->public_dep_count = n; - file->public_deps = - _upb_DefBuilder_Alloc(ctx, sizeof(*file->public_deps) * n); - int32_t* mutable_public_deps = (int32_t*)file->public_deps; - for (size_t i = 0; i < n; i++) { - if (public_deps[i] >= file->dep_count) { - _upb_DefBuilder_Errf(ctx, "public_dep %d is out of range", - (int)public_deps[i]); - } - mutable_public_deps[i] = public_deps[i]; - } +const float kUpb_FltInfinity = INFINITY; +const double kUpb_Infinity = INFINITY; +const double kUpb_NaN = NAN; - weak_deps = UPB_DESC(FileDescriptorProto_weak_dependency)(file_proto, &n); - file->weak_dep_count = n; - file->weak_deps = _upb_DefBuilder_Alloc(ctx, sizeof(*file->weak_deps) * n); - int32_t* mutable_weak_deps = (int32_t*)file->weak_deps; - for (size_t i = 0; i < n; i++) { - if (weak_deps[i] >= file->dep_count) { - _upb_DefBuilder_Errf(ctx, "weak_dep %d is out of range", - (int)weak_deps[i]); +bool UPB_PRIVATE(_upb_Message_Realloc)(struct upb_Message* msg, size_t need, + upb_Arena* a) { + const size_t overhead = sizeof(upb_Message_InternalData); + + upb_Message_Internal* owner = upb_Message_Getinternal(msg); + upb_Message_InternalData* in = owner->internal; + if (!in) { + // No internal data, allocate from scratch. + size_t size = UPB_MAX(128, upb_Log2CeilingSize(need + overhead)); + in = upb_Arena_Malloc(a, size); + if (!in) return false; + + in->size = size; + in->unknown_end = overhead; + in->ext_begin = size; + owner->internal = in; + } else if (in->ext_begin - in->unknown_end < need) { + // Internal data is too small, reallocate. + size_t new_size = upb_Log2CeilingSize(in->size + need); + size_t ext_bytes = in->size - in->ext_begin; + size_t new_ext_begin = new_size - ext_bytes; + in = upb_Arena_Realloc(a, in, in->size, new_size); + if (!in) return false; + + if (ext_bytes) { + // Need to move extension data to the end. + char* ptr = (char*)in; + memmove(ptr + new_ext_begin, ptr + in->ext_begin, ext_bytes); } - mutable_weak_deps[i] = weak_deps[i]; + in->ext_begin = new_ext_begin; + in->size = new_size; + owner->internal = in; } - // Create enums. - enums = UPB_DESC(FileDescriptorProto_enum_type)(file_proto, &n); - file->top_lvl_enum_count = n; - file->top_lvl_enums = - _upb_EnumDefs_New(ctx, n, enums, file->resolved_features, NULL); + UPB_ASSERT(in->ext_begin - in->unknown_end >= need); + return true; +} - // Create extensions. - exts = UPB_DESC(FileDescriptorProto_extension)(file_proto, &n); - file->top_lvl_ext_count = n; - file->top_lvl_exts = _upb_Extensions_New( - ctx, n, exts, file->resolved_features, file->package, NULL); - // Create messages. - msgs = UPB_DESC(FileDescriptorProto_message_type)(file_proto, &n); - file->top_lvl_msg_count = n; - file->top_lvl_msgs = - _upb_MessageDefs_New(ctx, n, msgs, file->resolved_features, NULL); +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', '{', '|', '}', '~', +}; - // Create services. - services = UPB_DESC(FileDescriptorProto_service)(file_proto, &n); - file->service_count = n; - file->services = - _upb_ServiceDefs_New(ctx, n, services, file->resolved_features); +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, +}; - // Now that all names are in the table, build layouts and resolve refs. - for (int i = 0; i < file->top_lvl_msg_count; i++) { - upb_MessageDef* m = (upb_MessageDef*)upb_FileDef_TopLevelMessage(file, i); - _upb_MessageDef_Resolve(ctx, m); - } +#include +#include +#include - for (int i = 0; i < file->top_lvl_ext_count; i++) { - upb_FieldDef* f = (upb_FieldDef*)upb_FileDef_TopLevelExtension(file, i); - _upb_FieldDef_Resolve(ctx, file->package, f); - } - for (int i = 0; i < file->top_lvl_msg_count; i++) { - upb_MessageDef* m = (upb_MessageDef*)upb_FileDef_TopLevelMessage(file, i); - _upb_MessageDef_CreateMiniTable(ctx, (upb_MessageDef*)m); - } +// Must be last. - for (int i = 0; i < file->top_lvl_ext_count; i++) { - upb_FieldDef* f = (upb_FieldDef*)upb_FileDef_TopLevelExtension(file, i); - _upb_FieldDef_BuildMiniTableExtension(ctx, f); - } +typedef struct { + uint64_t present_values_mask; + uint32_t last_written_value; +} upb_MtDataEncoderInternal_EnumState; - for (int i = 0; i < file->top_lvl_msg_count; i++) { - upb_MessageDef* m = (upb_MessageDef*)upb_FileDef_TopLevelMessage(file, i); - _upb_MessageDef_LinkMiniTable(ctx, m); - } +typedef struct { + uint64_t msg_modifiers; + uint32_t last_field_num; + enum { + kUpb_OneofState_NotStarted, + kUpb_OneofState_StartedOneof, + kUpb_OneofState_EmittedOneofField, + } oneof_state; +} upb_MtDataEncoderInternal_MsgState; - if (file->ext_count) { - bool ok = upb_ExtensionRegistry_AddArray( - _upb_DefPool_ExtReg(ctx->symtab), file->ext_layouts, file->ext_count); - if (!ok) _upb_DefBuilder_OomErr(ctx); - } +typedef struct { + char* buf_start; // Only for checking kUpb_MtDataEncoder_MinSize. + union { + upb_MtDataEncoderInternal_EnumState enum_state; + upb_MtDataEncoderInternal_MsgState msg_state; + } state; +} upb_MtDataEncoderInternal; + +static upb_MtDataEncoderInternal* upb_MtDataEncoder_GetInternal( + upb_MtDataEncoder* e, char* buf_start) { + UPB_ASSERT(sizeof(upb_MtDataEncoderInternal) <= sizeof(e->internal)); + upb_MtDataEncoderInternal* ret = (upb_MtDataEncoderInternal*)e->internal; + ret->buf_start = buf_start; + return ret; } +static char* upb_MtDataEncoder_PutRaw(upb_MtDataEncoder* e, char* ptr, + char ch) { + upb_MtDataEncoderInternal* in = (upb_MtDataEncoderInternal*)e->internal; + UPB_ASSERT(ptr - in->buf_start < kUpb_MtDataEncoder_MinSize); + if (ptr == e->end) return NULL; + *ptr++ = ch; + return ptr; +} -#include +static char* upb_MtDataEncoder_Put(upb_MtDataEncoder* e, char* ptr, char ch) { + return upb_MtDataEncoder_PutRaw(e, ptr, _upb_ToBase92(ch)); +} +static char* upb_MtDataEncoder_PutBase92Varint(upb_MtDataEncoder* e, char* ptr, + uint32_t val, int min, int max) { + int shift = upb_Log2Ceiling(_upb_FromBase92(max) - _upb_FromBase92(min) + 1); + UPB_ASSERT(shift <= 6); + uint32_t mask = (1 << shift) - 1; + do { + uint32_t bits = val & mask; + ptr = upb_MtDataEncoder_Put(e, ptr, bits + _upb_FromBase92(min)); + if (!ptr) return NULL; + val >>= shift; + } while (val); + return ptr; +} -// Must be last. +char* upb_MtDataEncoder_PutModifier(upb_MtDataEncoder* e, char* ptr, + uint64_t mod) { + if (mod) { + ptr = upb_MtDataEncoder_PutBase92Varint(e, ptr, mod, + kUpb_EncodedValue_MinModifier, + kUpb_EncodedValue_MaxModifier); + } + return ptr; +} -/* The upb core does not generally have a concept of default instances. However - * for descriptor options we make an exception since the max size is known and - * modest (<200 bytes). All types can share a default instance since it is - * initialized to zeroes. - * - * We have to allocate an extra pointer for upb's internal metadata. */ -static UPB_ALIGN_AS(8) const - char opt_default_buf[_UPB_MAXOPT_SIZE + sizeof(void*)] = {0}; -const char* kUpbDefOptDefault = &opt_default_buf[sizeof(void*)]; +char* upb_MtDataEncoder_EncodeExtension(upb_MtDataEncoder* e, char* ptr, + upb_FieldType type, uint32_t field_num, + uint64_t field_mod) { + upb_MtDataEncoderInternal* in = upb_MtDataEncoder_GetInternal(e, ptr); + in->state.msg_state.msg_modifiers = 0; + in->state.msg_state.last_field_num = 0; + in->state.msg_state.oneof_state = kUpb_OneofState_NotStarted; -const char* _upb_DefBuilder_FullToShort(const char* fullname) { - const char* p; + ptr = upb_MtDataEncoder_PutRaw(e, ptr, kUpb_EncodedVersion_ExtensionV1); + if (!ptr) return NULL; - if (fullname == NULL) { - return NULL; - } else if ((p = strrchr(fullname, '.')) == NULL) { - /* No '.' in the name, return the full string. */ - return fullname; - } else { - /* Return one past the last '.'. */ - return p + 1; - } + return upb_MtDataEncoder_PutField(e, ptr, type, field_num, field_mod); } -void _upb_DefBuilder_FailJmp(upb_DefBuilder* ctx) { UPB_LONGJMP(ctx->err, 1); } +char* upb_MtDataEncoder_EncodeMap(upb_MtDataEncoder* e, char* ptr, + upb_FieldType key_type, + upb_FieldType value_type, uint64_t key_mod, + uint64_t value_mod) { + upb_MtDataEncoderInternal* in = upb_MtDataEncoder_GetInternal(e, ptr); + in->state.msg_state.msg_modifiers = 0; + in->state.msg_state.last_field_num = 0; + in->state.msg_state.oneof_state = kUpb_OneofState_NotStarted; + + ptr = upb_MtDataEncoder_PutRaw(e, ptr, kUpb_EncodedVersion_MapV1); + if (!ptr) return NULL; + + ptr = upb_MtDataEncoder_PutField(e, ptr, key_type, 1, key_mod); + if (!ptr) return NULL; -void _upb_DefBuilder_Errf(upb_DefBuilder* ctx, const char* fmt, ...) { - va_list argp; - va_start(argp, fmt); - upb_Status_VSetErrorFormat(ctx->status, fmt, argp); - va_end(argp); - _upb_DefBuilder_FailJmp(ctx); + return upb_MtDataEncoder_PutField(e, ptr, value_type, 2, value_mod); } -void _upb_DefBuilder_OomErr(upb_DefBuilder* ctx) { - upb_Status_SetErrorMessage(ctx->status, "out of memory"); - _upb_DefBuilder_FailJmp(ctx); +char* upb_MtDataEncoder_EncodeMessageSet(upb_MtDataEncoder* e, char* ptr) { + (void)upb_MtDataEncoder_GetInternal(e, ptr); + return upb_MtDataEncoder_PutRaw(e, ptr, kUpb_EncodedVersion_MessageSetV1); } -// Verify a relative identifier string. The loop is branchless for speed. -static void _upb_DefBuilder_CheckIdentNotFull(upb_DefBuilder* ctx, - upb_StringView name) { - bool good = name.size > 0; - - for (size_t i = 0; i < name.size; i++) { - const char c = name.data[i]; - const char d = c | 0x20; // force lowercase - const bool is_alpha = (('a' <= d) & (d <= 'z')) | (c == '_'); - const bool is_numer = ('0' <= c) & (c <= '9') & (i != 0); +char* upb_MtDataEncoder_StartMessage(upb_MtDataEncoder* e, char* ptr, + uint64_t msg_mod) { + upb_MtDataEncoderInternal* in = upb_MtDataEncoder_GetInternal(e, ptr); + in->state.msg_state.msg_modifiers = msg_mod; + in->state.msg_state.last_field_num = 0; + in->state.msg_state.oneof_state = kUpb_OneofState_NotStarted; - good &= is_alpha | is_numer; - } + ptr = upb_MtDataEncoder_PutRaw(e, ptr, kUpb_EncodedVersion_MessageV1); + if (!ptr) return NULL; - if (!good) _upb_DefBuilder_CheckIdentSlow(ctx, name, false); + return upb_MtDataEncoder_PutModifier(e, ptr, msg_mod); } -const char* _upb_DefBuilder_MakeFullName(upb_DefBuilder* ctx, - const char* prefix, - upb_StringView name) { - _upb_DefBuilder_CheckIdentNotFull(ctx, name); - if (prefix) { - // ret = prefix + '.' + name; - size_t n = strlen(prefix); - char* ret = _upb_DefBuilder_Alloc(ctx, n + name.size + 2); - strcpy(ret, prefix); - ret[n] = '.'; - memcpy(&ret[n + 1], name.data, name.size); - ret[n + 1 + name.size] = '\0'; - return ret; - } else { - char* ret = upb_strdup2(name.data, name.size, ctx->arena); - if (!ret) _upb_DefBuilder_OomErr(ctx); - return ret; +static char* _upb_MtDataEncoder_MaybePutFieldSkip(upb_MtDataEncoder* e, + char* ptr, + uint32_t field_num) { + upb_MtDataEncoderInternal* in = (upb_MtDataEncoderInternal*)e->internal; + if (field_num <= in->state.msg_state.last_field_num) return NULL; + if (in->state.msg_state.last_field_num + 1 != field_num) { + // Put skip. + UPB_ASSERT(field_num > in->state.msg_state.last_field_num); + uint32_t skip = field_num - in->state.msg_state.last_field_num; + ptr = upb_MtDataEncoder_PutBase92Varint( + e, ptr, skip, kUpb_EncodedValue_MinSkip, kUpb_EncodedValue_MaxSkip); + if (!ptr) return NULL; } + in->state.msg_state.last_field_num = field_num; + return ptr; } -static bool remove_component(char* base, size_t* len) { - if (*len == 0) return false; - - for (size_t i = *len - 1; i > 0; i--) { - if (base[i] == '.') { - *len = i; - return true; - } - } +static char* _upb_MtDataEncoder_PutFieldType(upb_MtDataEncoder* e, char* ptr, + upb_FieldType type, + uint64_t field_mod) { + static const char kUpb_TypeToEncoded[] = { + [kUpb_FieldType_Double] = kUpb_EncodedType_Double, + [kUpb_FieldType_Float] = kUpb_EncodedType_Float, + [kUpb_FieldType_Int64] = kUpb_EncodedType_Int64, + [kUpb_FieldType_UInt64] = kUpb_EncodedType_UInt64, + [kUpb_FieldType_Int32] = kUpb_EncodedType_Int32, + [kUpb_FieldType_Fixed64] = kUpb_EncodedType_Fixed64, + [kUpb_FieldType_Fixed32] = kUpb_EncodedType_Fixed32, + [kUpb_FieldType_Bool] = kUpb_EncodedType_Bool, + [kUpb_FieldType_String] = kUpb_EncodedType_String, + [kUpb_FieldType_Group] = kUpb_EncodedType_Group, + [kUpb_FieldType_Message] = kUpb_EncodedType_Message, + [kUpb_FieldType_Bytes] = kUpb_EncodedType_Bytes, + [kUpb_FieldType_UInt32] = kUpb_EncodedType_UInt32, + [kUpb_FieldType_Enum] = kUpb_EncodedType_OpenEnum, + [kUpb_FieldType_SFixed32] = kUpb_EncodedType_SFixed32, + [kUpb_FieldType_SFixed64] = kUpb_EncodedType_SFixed64, + [kUpb_FieldType_SInt32] = kUpb_EncodedType_SInt32, + [kUpb_FieldType_SInt64] = kUpb_EncodedType_SInt64, + }; - *len = 0; - return true; -} + int encoded_type = kUpb_TypeToEncoded[type]; -const void* _upb_DefBuilder_ResolveAny(upb_DefBuilder* ctx, - const char* from_name_dbg, - const char* base, upb_StringView sym, - upb_deftype_t* type) { - if (sym.size == 0) goto notfound; - upb_value v; - if (sym.data[0] == '.') { - // Symbols starting with '.' are absolute, so we do a single lookup. - // Slice to omit the leading '.' - if (!_upb_DefPool_LookupSym(ctx->symtab, sym.data + 1, sym.size - 1, &v)) { - goto notfound; - } - } else { - // Remove components from base until we find an entry or run out. - size_t baselen = base ? strlen(base) : 0; - char* tmp = upb_gmalloc(sym.size + baselen + 1); - while (1) { - char* p = tmp; - if (baselen) { - memcpy(p, base, baselen); - p[baselen] = '.'; - p += baselen + 1; - } - memcpy(p, sym.data, sym.size); - p += sym.size; - if (_upb_DefPool_LookupSym(ctx->symtab, tmp, p - tmp, &v)) { - break; - } - if (!remove_component(tmp, &baselen)) { - upb_gfree(tmp); - goto notfound; - } - } - upb_gfree(tmp); + if (field_mod & kUpb_FieldModifier_IsClosedEnum) { + UPB_ASSERT(type == kUpb_FieldType_Enum); + encoded_type = kUpb_EncodedType_ClosedEnum; } - *type = _upb_DefType_Type(v); - return _upb_DefType_Unpack(v, *type); + if (field_mod & kUpb_FieldModifier_IsRepeated) { + // Repeated fields shift the type number up (unlike other modifiers which + // are bit flags). + encoded_type += kUpb_EncodedType_RepeatedBase; + } -notfound: - _upb_DefBuilder_Errf(ctx, "couldn't resolve name '" UPB_STRINGVIEW_FORMAT "'", - UPB_STRINGVIEW_ARGS(sym)); + return upb_MtDataEncoder_Put(e, ptr, encoded_type); } -const void* _upb_DefBuilder_Resolve(upb_DefBuilder* ctx, - const char* from_name_dbg, const char* base, - upb_StringView sym, upb_deftype_t type) { - upb_deftype_t found_type; - const void* ret = - _upb_DefBuilder_ResolveAny(ctx, from_name_dbg, base, sym, &found_type); - if (ret && found_type != type) { - _upb_DefBuilder_Errf(ctx, - "type mismatch when resolving %s: couldn't find " - "name " UPB_STRINGVIEW_FORMAT " with type=%d", - from_name_dbg, UPB_STRINGVIEW_ARGS(sym), (int)type); +static char* _upb_MtDataEncoder_MaybePutModifiers(upb_MtDataEncoder* e, + char* ptr, upb_FieldType type, + uint64_t field_mod) { + upb_MtDataEncoderInternal* in = (upb_MtDataEncoderInternal*)e->internal; + uint32_t encoded_modifiers = 0; + if ((field_mod & kUpb_FieldModifier_IsRepeated) && + upb_FieldType_IsPackable(type)) { + bool field_is_packed = field_mod & kUpb_FieldModifier_IsPacked; + bool default_is_packed = in->state.msg_state.msg_modifiers & + kUpb_MessageModifier_DefaultIsPacked; + if (field_is_packed != default_is_packed) { + encoded_modifiers |= kUpb_EncodedFieldModifier_FlipPacked; + } } - return ret; -} -// Per ASCII this will lower-case a letter. If the result is a letter, the -// input was definitely a letter. If the output is not a letter, this may -// have transformed the character unpredictably. -static char upb_ascii_lower(char ch) { return ch | 0x20; } + if (type == kUpb_FieldType_String) { + bool field_validates_utf8 = field_mod & kUpb_FieldModifier_ValidateUtf8; + bool message_validates_utf8 = + in->state.msg_state.msg_modifiers & kUpb_MessageModifier_ValidateUtf8; + if (field_validates_utf8 != message_validates_utf8) { + // Old binaries do not recognize the field modifier. We need the failure + // mode to be too lax rather than too strict. Our caller should have + // handled this (see _upb_MessageDef_ValidateUtf8()). + assert(!message_validates_utf8); + encoded_modifiers |= kUpb_EncodedFieldModifier_FlipValidateUtf8; + } + } -// isalpha() etc. from are locale-dependent, which we don't want. -static bool upb_isbetween(uint8_t c, uint8_t low, uint8_t high) { - return low <= c && c <= high; -} + if (field_mod & kUpb_FieldModifier_IsProto3Singular) { + encoded_modifiers |= kUpb_EncodedFieldModifier_IsProto3Singular; + } -static bool upb_isletter(char c) { - char lower = upb_ascii_lower(c); - return upb_isbetween(lower, 'a', 'z') || c == '_'; -} + if (field_mod & kUpb_FieldModifier_IsRequired) { + encoded_modifiers |= kUpb_EncodedFieldModifier_IsRequired; + } -static bool upb_isalphanum(char c) { - return upb_isletter(c) || upb_isbetween(c, '0', '9'); + return upb_MtDataEncoder_PutModifier(e, ptr, encoded_modifiers); } -static bool TryGetChar(const char** src, const char* end, char* ch) { - if (*src == end) return false; - *ch = **src; - *src += 1; - return true; -} +char* upb_MtDataEncoder_PutField(upb_MtDataEncoder* e, char* ptr, + upb_FieldType type, uint32_t field_num, + uint64_t field_mod) { + upb_MtDataEncoder_GetInternal(e, ptr); -static int TryGetHexDigit(const char** src, const char* end) { - char ch; - if (!TryGetChar(src, end, &ch)) return -1; - if ('0' <= ch && ch <= '9') { - return ch - '0'; - } - ch = upb_ascii_lower(ch); - if ('a' <= ch && ch <= 'f') { - return ch - 'a' + 0xa; - } - *src -= 1; // Char wasn't actually a hex digit. - return -1; -} + ptr = _upb_MtDataEncoder_MaybePutFieldSkip(e, ptr, field_num); + if (!ptr) return NULL; -static char upb_DefBuilder_ParseHexEscape(upb_DefBuilder* ctx, - const upb_FieldDef* f, - const char** src, const char* end) { - int hex_digit = TryGetHexDigit(src, end); - if (hex_digit < 0) { - _upb_DefBuilder_Errf( - ctx, "\\x must be followed by at least one hex digit (field='%s')", - upb_FieldDef_FullName(f)); - return 0; - } - unsigned int ret = hex_digit; - while ((hex_digit = TryGetHexDigit(src, end)) >= 0) { - ret = (ret << 4) | hex_digit; - } - if (ret > 0xff) { - _upb_DefBuilder_Errf(ctx, "Value of hex escape in field %s exceeds 8 bits", - upb_FieldDef_FullName(f)); - return 0; - } - return ret; + ptr = _upb_MtDataEncoder_PutFieldType(e, ptr, type, field_mod); + if (!ptr) return NULL; + + return _upb_MtDataEncoder_MaybePutModifiers(e, ptr, type, field_mod); } -static char TryGetOctalDigit(const char** src, const char* end) { - char ch; - if (!TryGetChar(src, end, &ch)) return -1; - if ('0' <= ch && ch <= '7') { - return ch - '0'; +char* upb_MtDataEncoder_StartOneof(upb_MtDataEncoder* e, char* ptr) { + upb_MtDataEncoderInternal* in = upb_MtDataEncoder_GetInternal(e, ptr); + if (in->state.msg_state.oneof_state == kUpb_OneofState_NotStarted) { + ptr = upb_MtDataEncoder_Put(e, ptr, _upb_FromBase92(kUpb_EncodedValue_End)); + } else { + ptr = upb_MtDataEncoder_Put( + e, ptr, _upb_FromBase92(kUpb_EncodedValue_OneofSeparator)); } - *src -= 1; // Char wasn't actually an octal digit. - return -1; + in->state.msg_state.oneof_state = kUpb_OneofState_StartedOneof; + return ptr; } -static char upb_DefBuilder_ParseOctalEscape(upb_DefBuilder* ctx, - const upb_FieldDef* f, - const char** src, const char* end) { - char ch = 0; - for (int i = 0; i < 3; i++) { - char digit; - if ((digit = TryGetOctalDigit(src, end)) >= 0) { - ch = (ch << 3) | digit; - } +char* upb_MtDataEncoder_PutOneofField(upb_MtDataEncoder* e, char* ptr, + uint32_t field_num) { + upb_MtDataEncoderInternal* in = upb_MtDataEncoder_GetInternal(e, ptr); + if (in->state.msg_state.oneof_state == kUpb_OneofState_EmittedOneofField) { + ptr = upb_MtDataEncoder_Put( + e, ptr, _upb_FromBase92(kUpb_EncodedValue_FieldSeparator)); + if (!ptr) return NULL; } - return ch; + ptr = upb_MtDataEncoder_PutBase92Varint(e, ptr, field_num, _upb_ToBase92(0), + _upb_ToBase92(63)); + in->state.msg_state.oneof_state = kUpb_OneofState_EmittedOneofField; + return ptr; } -char _upb_DefBuilder_ParseEscape(upb_DefBuilder* ctx, const upb_FieldDef* f, - const char** src, const char* end) { - char ch; - if (!TryGetChar(src, end, &ch)) { - _upb_DefBuilder_Errf(ctx, "unterminated escape sequence in field %s", - upb_FieldDef_FullName(f)); - return 0; - } - switch (ch) { - case 'a': - return '\a'; - case 'b': - return '\b'; - case 'f': - return '\f'; - case 'n': - return '\n'; - case 'r': - return '\r'; - case 't': - return '\t'; - case 'v': - return '\v'; - case '\\': - return '\\'; - case '\'': - return '\''; - case '\"': - return '\"'; - case '?': - return '\?'; - case 'x': - case 'X': - return upb_DefBuilder_ParseHexEscape(ctx, f, src, end); - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - *src -= 1; - return upb_DefBuilder_ParseOctalEscape(ctx, f, src, end); - } - _upb_DefBuilder_Errf(ctx, "Unknown escape sequence: \\%c", ch); +char* upb_MtDataEncoder_StartEnum(upb_MtDataEncoder* e, char* ptr) { + upb_MtDataEncoderInternal* in = upb_MtDataEncoder_GetInternal(e, ptr); + in->state.enum_state.present_values_mask = 0; + in->state.enum_state.last_written_value = 0; + + return upb_MtDataEncoder_PutRaw(e, ptr, kUpb_EncodedVersion_EnumV1); } -void _upb_DefBuilder_CheckIdentSlow(upb_DefBuilder* ctx, upb_StringView name, - bool full) { - const char* str = name.data; - const size_t len = name.size; - bool start = true; - for (size_t i = 0; i < len; i++) { - const char c = str[i]; - if (c == '.') { - if (start || !full) { - _upb_DefBuilder_Errf( - ctx, "invalid name: unexpected '.' (" UPB_STRINGVIEW_FORMAT ")", - UPB_STRINGVIEW_ARGS(name)); - } - start = true; - } else if (start) { - if (!upb_isletter(c)) { - _upb_DefBuilder_Errf(ctx, - "invalid name: path components must start with a " - "letter (" UPB_STRINGVIEW_FORMAT ")", - UPB_STRINGVIEW_ARGS(name)); - } - start = false; - } else if (!upb_isalphanum(c)) { - _upb_DefBuilder_Errf( - ctx, - "invalid name: non-alphanumeric character (" UPB_STRINGVIEW_FORMAT - ")", - UPB_STRINGVIEW_ARGS(name)); +static char* upb_MtDataEncoder_FlushDenseEnumMask(upb_MtDataEncoder* e, + char* ptr) { + upb_MtDataEncoderInternal* in = (upb_MtDataEncoderInternal*)e->internal; + ptr = upb_MtDataEncoder_Put(e, ptr, in->state.enum_state.present_values_mask); + in->state.enum_state.present_values_mask = 0; + in->state.enum_state.last_written_value += 5; + return ptr; +} + +char* upb_MtDataEncoder_PutEnumValue(upb_MtDataEncoder* e, char* ptr, + uint32_t val) { + // TODO: optimize this encoding. + upb_MtDataEncoderInternal* in = upb_MtDataEncoder_GetInternal(e, ptr); + UPB_ASSERT(val >= in->state.enum_state.last_written_value); + uint32_t delta = val - in->state.enum_state.last_written_value; + if (delta >= 5 && in->state.enum_state.present_values_mask) { + ptr = upb_MtDataEncoder_FlushDenseEnumMask(e, ptr); + if (!ptr) { + return NULL; } + delta -= 5; } - if (start) { - _upb_DefBuilder_Errf(ctx, - "invalid name: empty part (" UPB_STRINGVIEW_FORMAT ")", - UPB_STRINGVIEW_ARGS(name)); + + if (delta >= 5) { + ptr = upb_MtDataEncoder_PutBase92Varint( + e, ptr, delta, kUpb_EncodedValue_MinSkip, kUpb_EncodedValue_MaxSkip); + in->state.enum_state.last_written_value += delta; + delta = 0; } - // We should never reach this point. - UPB_ASSERT(false); + UPB_ASSERT((in->state.enum_state.present_values_mask >> delta) == 0); + in->state.enum_state.present_values_mask |= 1ULL << delta; + return ptr; } -upb_StringView _upb_DefBuilder_MakeKey(upb_DefBuilder* ctx, - const UPB_DESC(FeatureSet*) parent, - upb_StringView key) { - size_t need = key.size + sizeof(void*); - if (ctx->tmp_buf_size < need) { - ctx->tmp_buf_size = UPB_MAX(64, upb_Log2Ceiling(need)); - ctx->tmp_buf = upb_Arena_Malloc(ctx->tmp_arena, ctx->tmp_buf_size); - if (!ctx->tmp_buf) _upb_DefBuilder_OomErr(ctx); - } - - memcpy(ctx->tmp_buf, &parent, sizeof(void*)); - memcpy(ctx->tmp_buf + sizeof(void*), key.data, key.size); - return upb_StringView_FromDataAndSize(ctx->tmp_buf, need); +char* upb_MtDataEncoder_EndEnum(upb_MtDataEncoder* e, char* ptr) { + upb_MtDataEncoderInternal* in = upb_MtDataEncoder_GetInternal(e, ptr); + if (!in->state.enum_state.present_values_mask) return ptr; + return upb_MtDataEncoder_FlushDenseEnumMask(e, ptr); } -bool _upb_DefBuilder_GetOrCreateFeatureSet(upb_DefBuilder* ctx, - const UPB_DESC(FeatureSet*) parent, - upb_StringView key, - UPB_DESC(FeatureSet**) set) { - upb_StringView k = _upb_DefBuilder_MakeKey(ctx, parent, key); - upb_value v; - if (upb_strtable_lookup2(&ctx->feature_cache, k.data, k.size, &v)) { - *set = upb_value_getptr(v); - return false; - } - *set = (UPB_DESC(FeatureSet*))upb_Message_DeepClone( - UPB_UPCAST(parent), UPB_DESC_MINITABLE(FeatureSet), ctx->arena); - if (!*set) _upb_DefBuilder_OomErr(ctx); +#include - v = upb_value_ptr(*set); - if (!upb_strtable_insert(&ctx->feature_cache, k.data, k.size, v, - ctx->tmp_arena)) { - _upb_DefBuilder_OomErr(ctx); - } +// Must be last. - return true; -} +// A MiniTable for an empty message, used for unlinked sub-messages. +const struct upb_MiniTable UPB_PRIVATE(_kUpb_MiniTable_Empty) = { + .UPB_PRIVATE(subs) = NULL, + .UPB_PRIVATE(fields) = NULL, + .UPB_PRIVATE(size) = 0, + .UPB_PRIVATE(field_count) = 0, + .UPB_PRIVATE(ext) = kUpb_ExtMode_NonExtendable, + .UPB_PRIVATE(dense_below) = 0, + .UPB_PRIVATE(table_mask) = -1, + .UPB_PRIVATE(required_count) = 0, +}; -const UPB_DESC(FeatureSet*) - _upb_DefBuilder_DoResolveFeatures(upb_DefBuilder* ctx, - const UPB_DESC(FeatureSet*) parent, - const UPB_DESC(FeatureSet*) child, - bool is_implicit) { - assert(parent); - if (!child) return parent; - if (child && !is_implicit && - upb_FileDef_Syntax(ctx->file) != kUpb_Syntax_Editions) { - _upb_DefBuilder_Errf(ctx, "Features can only be specified for editions"); - } - UPB_DESC(FeatureSet*) resolved; - size_t child_size; - const char* child_bytes = - UPB_DESC(FeatureSet_serialize)(child, ctx->tmp_arena, &child_size); - if (!child_bytes) _upb_DefBuilder_OomErr(ctx); +// Must be last. - upb_StringView key = upb_StringView_FromDataAndSize(child_bytes, child_size); - if (!_upb_DefBuilder_GetOrCreateFeatureSet(ctx, parent, key, &resolved)) { - return resolved; - } +struct upb_DefPool { + upb_Arena* arena; + upb_strtable syms; // full_name -> packed def ptr + upb_strtable files; // file_name -> (upb_FileDef*) + upb_inttable exts; // (upb_MiniTableExtension*) -> (upb_FieldDef*) + upb_ExtensionRegistry* extreg; + const UPB_DESC(FeatureSetDefaults) * feature_set_defaults; + upb_MiniTablePlatform platform; + void* scratch_data; + size_t scratch_size; + size_t bytes_loaded; +}; - upb_DecodeStatus dec_status = - upb_Decode(child_bytes, child_size, UPB_UPCAST(resolved), - UPB_DESC_MINITABLE(FeatureSet), NULL, 0, ctx->arena); - if (dec_status != kUpb_DecodeStatus_Ok) _upb_DefBuilder_OomErr(ctx); +void upb_DefPool_Free(upb_DefPool* s) { + upb_Arena_Free(s->arena); + upb_gfree(s->scratch_data); + upb_gfree(s); +} + +static const char serialized_defaults[] = UPB_INTERNAL_UPB_EDITION_DEFAULTS; + +upb_DefPool* upb_DefPool_New(void) { + upb_DefPool* s = upb_gmalloc(sizeof(*s)); + if (!s) return NULL; + + s->arena = upb_Arena_New(); + s->bytes_loaded = 0; - return resolved; -} + s->scratch_size = 240; + s->scratch_data = upb_gmalloc(s->scratch_size); + if (!s->scratch_data) goto err; + if (!upb_strtable_init(&s->syms, 32, s->arena)) goto err; + if (!upb_strtable_init(&s->files, 4, s->arena)) goto err; + if (!upb_inttable_init(&s->exts, s->arena)) goto err; -#include + s->extreg = upb_ExtensionRegistry_New(s->arena); + if (!s->extreg) goto err; + s->platform = kUpb_MiniTablePlatform_Native; -// Must be last. + upb_Status status; + if (!upb_DefPool_SetFeatureSetDefaults( + s, serialized_defaults, sizeof(serialized_defaults) - 1, &status)) { + goto err; + } -char* upb_strdup2(const char* s, size_t len, upb_Arena* a) { - size_t n; - char* p; + if (!s->feature_set_defaults) goto err; - // Prevent overflow errors. - if (len == SIZE_MAX) return NULL; + return s; - // Always null-terminate, even if binary data; but don't rely on the input to - // have a null-terminating byte since it may be a raw binary buffer. - n = len + 1; - p = upb_Arena_Malloc(a, n); - if (p) { - if (len != 0) memcpy(p, s, len); - p[len] = 0; - } - return p; +err: + upb_DefPool_Free(s); + return NULL; } +const UPB_DESC(FeatureSetDefaults) * + upb_DefPool_FeatureSetDefaults(const upb_DefPool* s) { + return s->feature_set_defaults; +} -#include -#include - +bool upb_DefPool_SetFeatureSetDefaults(upb_DefPool* s, + const char* serialized_defaults, + size_t serialized_len, + upb_Status* status) { + const UPB_DESC(FeatureSetDefaults)* defaults = UPB_DESC( + FeatureSetDefaults_parse)(serialized_defaults, serialized_len, s->arena); + if (!defaults) { + upb_Status_SetErrorFormat(status, "Failed to parse defaults"); + return false; + } + if (upb_strtable_count(&s->files) > 0) { + upb_Status_SetErrorFormat(status, + "Feature set defaults can't be changed once the " + "pool has started building"); + return false; + } + int min_edition = UPB_DESC(FeatureSetDefaults_minimum_edition(defaults)); + int max_edition = UPB_DESC(FeatureSetDefaults_maximum_edition(defaults)); + if (min_edition > max_edition) { + upb_Status_SetErrorFormat(status, "Invalid edition range %s to %s", + upb_FileDef_EditionName(min_edition), + upb_FileDef_EditionName(max_edition)); + return false; + } + size_t size; + const UPB_DESC( + FeatureSetDefaults_FeatureSetEditionDefault)* const* default_list = + UPB_DESC(FeatureSetDefaults_defaults(defaults, &size)); + int prev_edition = UPB_DESC(EDITION_UNKNOWN); + for (size_t i = 0; i < size; ++i) { + int edition = UPB_DESC( + FeatureSetDefaults_FeatureSetEditionDefault_edition(default_list[i])); + if (edition == UPB_DESC(EDITION_UNKNOWN)) { + upb_Status_SetErrorFormat(status, "Invalid edition UNKNOWN specified"); + return false; + } + if (edition <= prev_edition) { + upb_Status_SetErrorFormat(status, + "Feature set defaults are not strictly " + "increasing, %s is greater than or equal to %s", + upb_FileDef_EditionName(prev_edition), + upb_FileDef_EditionName(edition)); + return false; + } + prev_edition = edition; + } -// Must be last. + // Copy the defaults into the pool. + s->feature_set_defaults = defaults; + return true; +} -bool upb_Message_HasFieldByDef(const upb_Message* msg, const upb_FieldDef* f) { - UPB_ASSERT(upb_FieldDef_HasPresence(f)); - return upb_Message_HasField(msg, upb_FieldDef_MiniTable(f)); +bool _upb_DefPool_InsertExt(upb_DefPool* s, const upb_MiniTableExtension* ext, + const upb_FieldDef* f) { + return upb_inttable_insert(&s->exts, (uintptr_t)ext, upb_value_constptr(f), + s->arena); } -const upb_FieldDef* upb_Message_WhichOneof(const upb_Message* msg, - const upb_OneofDef* o) { - const upb_FieldDef* f = upb_OneofDef_Field(o, 0); - if (upb_OneofDef_IsSynthetic(o)) { - UPB_ASSERT(upb_OneofDef_FieldCount(o) == 1); - return upb_Message_HasFieldByDef(msg, f) ? f : NULL; - } else { - const upb_MiniTableField* field = upb_FieldDef_MiniTable(f); - uint32_t oneof_case = upb_Message_WhichOneofFieldNumber(msg, field); - f = oneof_case ? upb_OneofDef_LookupNumber(o, oneof_case) : NULL; - UPB_ASSERT((f != NULL) == (oneof_case != 0)); - return f; +bool _upb_DefPool_InsertSym(upb_DefPool* s, upb_StringView sym, upb_value v, + upb_Status* status) { + // TODO: table should support an operation "tryinsert" to avoid the double + // lookup. + if (upb_strtable_lookup2(&s->syms, sym.data, sym.size, NULL)) { + upb_Status_SetErrorFormat(status, "duplicate symbol '%s'", sym.data); + return false; + } + if (!upb_strtable_insert(&s->syms, sym.data, sym.size, v, s->arena)) { + upb_Status_SetErrorMessage(status, "out of memory"); + return false; } + return true; } -upb_MessageValue upb_Message_GetFieldByDef(const upb_Message* msg, - const upb_FieldDef* f) { - upb_MessageValue default_val = upb_FieldDef_Default(f); - return upb_Message_GetField(msg, upb_FieldDef_MiniTable(f), default_val); +static const void* _upb_DefPool_Unpack(const upb_DefPool* s, const char* sym, + size_t size, upb_deftype_t type) { + upb_value v; + return upb_strtable_lookup2(&s->syms, sym, size, &v) + ? _upb_DefType_Unpack(v, type) + : NULL; } -upb_MutableMessageValue upb_Message_Mutable(upb_Message* msg, - const upb_FieldDef* f, - upb_Arena* a) { - UPB_ASSERT(upb_FieldDef_IsSubMessage(f) || upb_FieldDef_IsRepeated(f)); - if (upb_FieldDef_HasPresence(f) && !upb_Message_HasFieldByDef(msg, f)) { - // We need to skip the upb_Message_GetFieldByDef() call in this case. - goto make; - } +bool _upb_DefPool_LookupSym(const upb_DefPool* s, const char* sym, size_t size, + upb_value* v) { + return upb_strtable_lookup2(&s->syms, sym, size, v); +} - upb_MessageValue val = upb_Message_GetFieldByDef(msg, f); - if (val.array_val) { - return (upb_MutableMessageValue){.array = (upb_Array*)val.array_val}; - } +upb_ExtensionRegistry* _upb_DefPool_ExtReg(const upb_DefPool* s) { + return s->extreg; +} - upb_MutableMessageValue ret; -make: - if (!a) return (upb_MutableMessageValue){.array = NULL}; - if (upb_FieldDef_IsMap(f)) { - const upb_MessageDef* entry = upb_FieldDef_MessageSubDef(f); - const upb_FieldDef* key = - upb_MessageDef_FindFieldByNumber(entry, kUpb_MapEntry_KeyFieldNumber); - const upb_FieldDef* value = - upb_MessageDef_FindFieldByNumber(entry, kUpb_MapEntry_ValueFieldNumber); - ret.map = - upb_Map_New(a, upb_FieldDef_CType(key), upb_FieldDef_CType(value)); - } else if (upb_FieldDef_IsRepeated(f)) { - ret.array = upb_Array_New(a, upb_FieldDef_CType(f)); - } else { - UPB_ASSERT(upb_FieldDef_IsSubMessage(f)); - const upb_MessageDef* m = upb_FieldDef_MessageSubDef(f); - ret.msg = upb_Message_New(upb_MessageDef_MiniTable(m), a); - } +void** _upb_DefPool_ScratchData(const upb_DefPool* s) { + return (void**)&s->scratch_data; +} - val.array_val = ret.array; - upb_Message_SetFieldByDef(msg, f, val, a); +size_t* _upb_DefPool_ScratchSize(const upb_DefPool* s) { + return (size_t*)&s->scratch_size; +} - return ret; +void _upb_DefPool_SetPlatform(upb_DefPool* s, upb_MiniTablePlatform platform) { + assert(upb_strtable_count(&s->files) == 0); + s->platform = platform; } -bool upb_Message_SetFieldByDef(upb_Message* msg, const upb_FieldDef* f, - upb_MessageValue val, upb_Arena* a) { - return upb_Message_SetField(msg, upb_FieldDef_MiniTable(f), val, a); +const upb_MessageDef* upb_DefPool_FindMessageByName(const upb_DefPool* s, + const char* sym) { + return _upb_DefPool_Unpack(s, sym, strlen(sym), UPB_DEFTYPE_MSG); } -void upb_Message_ClearFieldByDef(upb_Message* msg, const upb_FieldDef* f) { - upb_Message_ClearField(msg, upb_FieldDef_MiniTable(f)); +const upb_MessageDef* upb_DefPool_FindMessageByNameWithSize( + const upb_DefPool* s, const char* sym, size_t len) { + return _upb_DefPool_Unpack(s, sym, len, UPB_DEFTYPE_MSG); } -void upb_Message_ClearByDef(upb_Message* msg, const upb_MessageDef* m) { - upb_Message_Clear(msg, upb_MessageDef_MiniTable(m)); +const upb_EnumDef* upb_DefPool_FindEnumByName(const upb_DefPool* s, + const char* sym) { + return _upb_DefPool_Unpack(s, sym, strlen(sym), UPB_DEFTYPE_ENUM); } -bool upb_Message_Next(const upb_Message* msg, const upb_MessageDef* m, - const upb_DefPool* ext_pool, const upb_FieldDef** out_f, - upb_MessageValue* out_val, size_t* iter) { - size_t i = *iter; - size_t n = upb_MessageDef_FieldCount(m); - UPB_UNUSED(ext_pool); +const upb_EnumValueDef* upb_DefPool_FindEnumByNameval(const upb_DefPool* s, + const char* sym) { + return _upb_DefPool_Unpack(s, sym, strlen(sym), UPB_DEFTYPE_ENUMVAL); +} - // Iterate over normal fields, returning the first one that is set. - while (++i < n) { - const upb_FieldDef* f = upb_MessageDef_Field(m, i); - const upb_MiniTableField* field = upb_FieldDef_MiniTable(f); - upb_MessageValue val = upb_Message_GetFieldByDef(msg, f); +const upb_FileDef* upb_DefPool_FindFileByName(const upb_DefPool* s, + const char* name) { + upb_value v; + return upb_strtable_lookup(&s->files, name, &v) ? upb_value_getconstptr(v) + : NULL; +} - // Skip field if unset or empty. - if (upb_MiniTableField_HasPresence(field)) { - if (!upb_Message_HasFieldByDef(msg, f)) continue; - } else { - switch (UPB_PRIVATE(_upb_MiniTableField_Mode)(field)) { - case kUpb_FieldMode_Map: - if (!val.map_val || upb_Map_Size(val.map_val) == 0) continue; - break; - case kUpb_FieldMode_Array: - if (!val.array_val || upb_Array_Size(val.array_val) == 0) continue; - break; - case kUpb_FieldMode_Scalar: - if (UPB_PRIVATE(_upb_MiniTableField_DataIsZero)(field, &val)) - continue; - break; - } - } +const upb_FileDef* upb_DefPool_FindFileByNameWithSize(const upb_DefPool* s, + const char* name, + size_t len) { + upb_value v; + return upb_strtable_lookup2(&s->files, name, len, &v) + ? upb_value_getconstptr(v) + : NULL; +} - *out_val = val; - *out_f = f; - *iter = i; - return true; - } +const upb_FieldDef* upb_DefPool_FindExtensionByNameWithSize( + const upb_DefPool* s, const char* name, size_t size) { + upb_value v; + if (!upb_strtable_lookup2(&s->syms, name, size, &v)) return NULL; - if (ext_pool) { - // Return any extensions that are set. - size_t count; - const upb_Extension* ext = UPB_PRIVATE(_upb_Message_Getexts)(msg, &count); - if (i - n < count) { - ext += count - 1 - (i - n); - memcpy(out_val, &ext->data, sizeof(*out_val)); - *out_f = upb_DefPool_FindExtensionByMiniTable(ext_pool, ext->ext); - *iter = i; - return true; + switch (_upb_DefType_Type(v)) { + case UPB_DEFTYPE_FIELD: + return _upb_DefType_Unpack(v, UPB_DEFTYPE_FIELD); + case UPB_DEFTYPE_MSG: { + const upb_MessageDef* m = _upb_DefType_Unpack(v, UPB_DEFTYPE_MSG); + return _upb_MessageDef_InMessageSet(m) + ? upb_MessageDef_NestedExtension(m, 0) + : NULL; } + default: + break; } - *iter = i; - return false; + return NULL; } -bool _upb_Message_DiscardUnknown(upb_Message* msg, const upb_MessageDef* m, - int depth) { - size_t iter = kUpb_Message_Begin; - const upb_FieldDef* f; - upb_MessageValue val; - bool ret = true; - - if (--depth == 0) return false; - - _upb_Message_DiscardUnknown_shallow(msg); +const upb_FieldDef* upb_DefPool_FindExtensionByName(const upb_DefPool* s, + const char* sym) { + return upb_DefPool_FindExtensionByNameWithSize(s, sym, strlen(sym)); +} - while (upb_Message_Next(msg, m, NULL /*ext_pool*/, &f, &val, &iter)) { - const upb_MessageDef* subm = upb_FieldDef_MessageSubDef(f); - if (!subm) continue; - if (upb_FieldDef_IsMap(f)) { - const upb_FieldDef* val_f = upb_MessageDef_FindFieldByNumber(subm, 2); - const upb_MessageDef* val_m = upb_FieldDef_MessageSubDef(val_f); - upb_Map* map = (upb_Map*)val.map_val; - size_t iter = kUpb_Map_Begin; +const upb_ServiceDef* upb_DefPool_FindServiceByName(const upb_DefPool* s, + const char* name) { + return _upb_DefPool_Unpack(s, name, strlen(name), UPB_DEFTYPE_SERVICE); +} - if (!val_m) continue; +const upb_ServiceDef* upb_DefPool_FindServiceByNameWithSize( + const upb_DefPool* s, const char* name, size_t size) { + return _upb_DefPool_Unpack(s, name, size, UPB_DEFTYPE_SERVICE); +} - upb_MessageValue map_key, map_val; - while (upb_Map_Next(map, &map_key, &map_val, &iter)) { - if (!_upb_Message_DiscardUnknown((upb_Message*)map_val.msg_val, val_m, - depth)) { - ret = false; - } +const upb_FileDef* upb_DefPool_FindFileContainingSymbol(const upb_DefPool* s, + const char* name) { + upb_value v; + // TODO: non-extension fields and oneofs. + if (upb_strtable_lookup(&s->syms, name, &v)) { + switch (_upb_DefType_Type(v)) { + case UPB_DEFTYPE_EXT: { + const upb_FieldDef* f = _upb_DefType_Unpack(v, UPB_DEFTYPE_EXT); + return upb_FieldDef_File(f); } - } else if (upb_FieldDef_IsRepeated(f)) { - const upb_Array* arr = val.array_val; - size_t i, n = upb_Array_Size(arr); - for (i = 0; i < n; i++) { - upb_MessageValue elem = upb_Array_Get(arr, i); - if (!_upb_Message_DiscardUnknown((upb_Message*)elem.msg_val, subm, - depth)) { - ret = false; - } + case UPB_DEFTYPE_MSG: { + const upb_MessageDef* m = _upb_DefType_Unpack(v, UPB_DEFTYPE_MSG); + return upb_MessageDef_File(m); } - } else { - if (!_upb_Message_DiscardUnknown((upb_Message*)val.msg_val, subm, - depth)) { - ret = false; + case UPB_DEFTYPE_ENUM: { + const upb_EnumDef* e = _upb_DefType_Unpack(v, UPB_DEFTYPE_ENUM); + return upb_EnumDef_File(e); + } + case UPB_DEFTYPE_ENUMVAL: { + const upb_EnumValueDef* ev = + _upb_DefType_Unpack(v, UPB_DEFTYPE_ENUMVAL); + return upb_EnumDef_File(upb_EnumValueDef_Enum(ev)); + } + case UPB_DEFTYPE_SERVICE: { + const upb_ServiceDef* service = + _upb_DefType_Unpack(v, UPB_DEFTYPE_SERVICE); + return upb_ServiceDef_File(service); } + default: + UPB_UNREACHABLE(); } } - return ret; -} + const char* last_dot = strrchr(name, '.'); + if (last_dot) { + const upb_MessageDef* parent = + upb_DefPool_FindMessageByNameWithSize(s, name, last_dot - name); + if (parent) { + const char* shortname = last_dot + 1; + if (upb_MessageDef_FindByNameWithSize(parent, shortname, + strlen(shortname), NULL, NULL)) { + return upb_MessageDef_File(parent); + } + } + } -bool upb_Message_DiscardUnknown(upb_Message* msg, const upb_MessageDef* m, - int maxdepth) { - return _upb_Message_DiscardUnknown(msg, m, maxdepth); + return NULL; } +static void remove_filedef(upb_DefPool* s, upb_FileDef* file) { + intptr_t iter = UPB_INTTABLE_BEGIN; + upb_StringView key; + upb_value val; + while (upb_strtable_next2(&s->syms, &key, &val, &iter)) { + const upb_FileDef* f; + switch (_upb_DefType_Type(val)) { + case UPB_DEFTYPE_EXT: + f = upb_FieldDef_File(_upb_DefType_Unpack(val, UPB_DEFTYPE_EXT)); + break; + case UPB_DEFTYPE_MSG: + f = upb_MessageDef_File(_upb_DefType_Unpack(val, UPB_DEFTYPE_MSG)); + break; + case UPB_DEFTYPE_ENUM: + f = upb_EnumDef_File(_upb_DefType_Unpack(val, UPB_DEFTYPE_ENUM)); + break; + case UPB_DEFTYPE_ENUMVAL: + f = upb_EnumDef_File(upb_EnumValueDef_Enum( + _upb_DefType_Unpack(val, UPB_DEFTYPE_ENUMVAL))); + break; + case UPB_DEFTYPE_SERVICE: + f = upb_ServiceDef_File(_upb_DefType_Unpack(val, UPB_DEFTYPE_SERVICE)); + break; + default: + UPB_UNREACHABLE(); + } -#include -#include -#include - - -// Must be last. - -struct upb_MessageDef { - const UPB_DESC(MessageOptions*) opts; - const UPB_DESC(FeatureSet*) resolved_features; - const upb_MiniTable* layout; - const upb_FileDef* file; - const upb_MessageDef* containing_type; - const char* full_name; - - // Tables for looking up fields by number and name. - upb_inttable itof; - upb_strtable ntof; - - // Looking up fields by json name. - upb_strtable jtof; - - /* All nested defs. - * MEM: We could save some space here by putting nested defs in a contiguous - * region and calculating counts from offsets or vice-versa. */ - const upb_FieldDef* fields; - const upb_OneofDef* oneofs; - const upb_ExtensionRange* ext_ranges; - const upb_StringView* res_names; - const upb_MessageDef* nested_msgs; - const upb_MessageReservedRange* res_ranges; - const upb_EnumDef* nested_enums; - const upb_FieldDef* nested_exts; - - // TODO: These counters don't need anywhere near 32 bits. - int field_count; - int real_oneof_count; - int oneof_count; - int ext_range_count; - int res_range_count; - int res_name_count; - int nested_msg_count; - int nested_enum_count; - int nested_ext_count; - bool in_message_set; - bool is_sorted; - upb_WellKnown well_known_type; -#if UINTPTR_MAX == 0xffffffff - uint32_t padding; // Increase size to a multiple of 8. -#endif -}; - -static void assign_msg_wellknowntype(upb_MessageDef* m) { - const char* name = m->full_name; - if (name == NULL) { - m->well_known_type = kUpb_WellKnown_Unspecified; - return; + if (f == file) upb_strtable_removeiter(&s->syms, &iter); } - if (!strcmp(name, "google.protobuf.Any")) { - m->well_known_type = kUpb_WellKnown_Any; - } else if (!strcmp(name, "google.protobuf.FieldMask")) { - m->well_known_type = kUpb_WellKnown_FieldMask; - } else if (!strcmp(name, "google.protobuf.Duration")) { - m->well_known_type = kUpb_WellKnown_Duration; - } else if (!strcmp(name, "google.protobuf.Timestamp")) { - m->well_known_type = kUpb_WellKnown_Timestamp; - } else if (!strcmp(name, "google.protobuf.DoubleValue")) { - m->well_known_type = kUpb_WellKnown_DoubleValue; - } else if (!strcmp(name, "google.protobuf.FloatValue")) { - m->well_known_type = kUpb_WellKnown_FloatValue; - } else if (!strcmp(name, "google.protobuf.Int64Value")) { - m->well_known_type = kUpb_WellKnown_Int64Value; - } else if (!strcmp(name, "google.protobuf.UInt64Value")) { - m->well_known_type = kUpb_WellKnown_UInt64Value; - } else if (!strcmp(name, "google.protobuf.Int32Value")) { - m->well_known_type = kUpb_WellKnown_Int32Value; - } else if (!strcmp(name, "google.protobuf.UInt32Value")) { - m->well_known_type = kUpb_WellKnown_UInt32Value; - } else if (!strcmp(name, "google.protobuf.BoolValue")) { - m->well_known_type = kUpb_WellKnown_BoolValue; - } else if (!strcmp(name, "google.protobuf.StringValue")) { - m->well_known_type = kUpb_WellKnown_StringValue; - } else if (!strcmp(name, "google.protobuf.BytesValue")) { - m->well_known_type = kUpb_WellKnown_BytesValue; - } else if (!strcmp(name, "google.protobuf.Value")) { - m->well_known_type = kUpb_WellKnown_Value; - } else if (!strcmp(name, "google.protobuf.ListValue")) { - m->well_known_type = kUpb_WellKnown_ListValue; - } else if (!strcmp(name, "google.protobuf.Struct")) { - m->well_known_type = kUpb_WellKnown_Struct; +} + +static const upb_FileDef* upb_DefBuilder_AddFileToPool( + upb_DefBuilder* const builder, upb_DefPool* const s, + const UPB_DESC(FileDescriptorProto) * const file_proto, + const upb_StringView name, upb_Status* const status) { + if (UPB_SETJMP(builder->err) != 0) { + UPB_ASSERT(!upb_Status_IsOk(status)); + if (builder->file) { + remove_filedef(s, builder->file); + builder->file = NULL; + } + } else if (!builder->arena || !builder->tmp_arena || + !upb_strtable_init(&builder->feature_cache, 16, + builder->tmp_arena) || + !(builder->legacy_features = + UPB_DESC(FeatureSet_new)(builder->tmp_arena))) { + _upb_DefBuilder_OomErr(builder); } else { - m->well_known_type = kUpb_WellKnown_Unspecified; + _upb_FileDef_Create(builder, file_proto); + upb_strtable_insert(&s->files, name.data, name.size, + upb_value_constptr(builder->file), builder->arena); + UPB_ASSERT(upb_Status_IsOk(status)); + upb_Arena_Fuse(s->arena, builder->arena); } -} -upb_MessageDef* _upb_MessageDef_At(const upb_MessageDef* m, int i) { - return (upb_MessageDef*)&m[i]; + if (builder->arena) upb_Arena_Free(builder->arena); + if (builder->tmp_arena) upb_Arena_Free(builder->tmp_arena); + return builder->file; } -bool _upb_MessageDef_IsValidExtensionNumber(const upb_MessageDef* m, int n) { - for (int i = 0; i < m->ext_range_count; i++) { - const upb_ExtensionRange* r = upb_MessageDef_ExtensionRange(m, i); - if (upb_ExtensionRange_Start(r) <= n && n < upb_ExtensionRange_End(r)) { - return true; +static const upb_FileDef* _upb_DefPool_AddFile( + upb_DefPool* s, const UPB_DESC(FileDescriptorProto) * file_proto, + const upb_MiniTableFile* layout, upb_Status* status) { + const upb_StringView name = UPB_DESC(FileDescriptorProto_name)(file_proto); + + // Determine whether we already know about this file. + { + upb_value v; + if (upb_strtable_lookup2(&s->files, name.data, name.size, &v)) { + upb_Status_SetErrorFormat(status, + "duplicate file name " UPB_STRINGVIEW_FORMAT, + UPB_STRINGVIEW_ARGS(name)); + return NULL; } } - return false; -} -const UPB_DESC(MessageOptions) * - upb_MessageDef_Options(const upb_MessageDef* m) { - return m->opts; -} + upb_DefBuilder ctx = { + .symtab = s, + .tmp_buf = NULL, + .tmp_buf_size = 0, + .layout = layout, + .platform = s->platform, + .msg_count = 0, + .enum_count = 0, + .ext_count = 0, + .status = status, + .file = NULL, + .arena = upb_Arena_New(), + .tmp_arena = upb_Arena_New(), + }; -bool upb_MessageDef_HasOptions(const upb_MessageDef* m) { - return m->opts != (void*)kUpbDefOptDefault; + return upb_DefBuilder_AddFileToPool(&ctx, s, file_proto, name, status); } -const UPB_DESC(FeatureSet) * - upb_MessageDef_ResolvedFeatures(const upb_MessageDef* m) { - return m->resolved_features; +const upb_FileDef* upb_DefPool_AddFile(upb_DefPool* s, + const UPB_DESC(FileDescriptorProto) * + file_proto, + upb_Status* status) { + return _upb_DefPool_AddFile(s, file_proto, NULL, status); } -const char* upb_MessageDef_FullName(const upb_MessageDef* m) { - return m->full_name; -} +bool _upb_DefPool_LoadDefInitEx(upb_DefPool* s, const _upb_DefPool_Init* init, + bool rebuild_minitable) { + /* Since this function should never fail (it would indicate a bug in upb) we + * print errors to stderr instead of returning error status to the user. */ + _upb_DefPool_Init** deps = init->deps; + UPB_DESC(FileDescriptorProto) * file; + upb_Arena* arena; + upb_Status status; -const upb_FileDef* upb_MessageDef_File(const upb_MessageDef* m) { - return m->file; + upb_Status_Clear(&status); + + if (upb_DefPool_FindFileByName(s, init->filename)) { + return true; + } + + arena = upb_Arena_New(); + + for (; *deps; deps++) { + if (!_upb_DefPool_LoadDefInitEx(s, *deps, rebuild_minitable)) goto err; + } + + file = UPB_DESC(FileDescriptorProto_parse_ex)( + init->descriptor.data, init->descriptor.size, NULL, + kUpb_DecodeOption_AliasString, arena); + s->bytes_loaded += init->descriptor.size; + + if (!file) { + upb_Status_SetErrorFormat( + &status, + "Failed to parse compiled-in descriptor for file '%s'. This should " + "never happen.", + init->filename); + goto err; + } + + const upb_MiniTableFile* mt = rebuild_minitable ? NULL : init->layout; + if (!_upb_DefPool_AddFile(s, file, mt, &status)) { + goto err; + } + + upb_Arena_Free(arena); + return true; + +err: + fprintf(stderr, + "Error loading compiled-in descriptor for file '%s' (this should " + "never happen): %s\n", + init->filename, upb_Status_ErrorMessage(&status)); + upb_Arena_Free(arena); + return false; } -const upb_MessageDef* upb_MessageDef_ContainingType(const upb_MessageDef* m) { - return m->containing_type; +size_t _upb_DefPool_BytesLoaded(const upb_DefPool* s) { + return s->bytes_loaded; } -const char* upb_MessageDef_Name(const upb_MessageDef* m) { - return _upb_DefBuilder_FullToShort(m->full_name); +upb_Arena* _upb_DefPool_Arena(const upb_DefPool* s) { return s->arena; } + +const upb_FieldDef* upb_DefPool_FindExtensionByMiniTable( + const upb_DefPool* s, const upb_MiniTableExtension* ext) { + upb_value v; + bool ok = upb_inttable_lookup(&s->exts, (uintptr_t)ext, &v); + UPB_ASSERT(ok); + return upb_value_getconstptr(v); } -upb_Syntax upb_MessageDef_Syntax(const upb_MessageDef* m) { - return upb_FileDef_Syntax(m->file); +const upb_FieldDef* upb_DefPool_FindExtensionByNumber(const upb_DefPool* s, + const upb_MessageDef* m, + int32_t fieldnum) { + const upb_MiniTable* t = upb_MessageDef_MiniTable(m); + const upb_MiniTableExtension* ext = + upb_ExtensionRegistry_Lookup(s->extreg, t, fieldnum); + return ext ? upb_DefPool_FindExtensionByMiniTable(s, ext) : NULL; } -const upb_FieldDef* upb_MessageDef_FindFieldByNumber(const upb_MessageDef* m, - uint32_t i) { - upb_value val; - return upb_inttable_lookup(&m->itof, i, &val) ? upb_value_getconstptr(val) - : NULL; +const upb_ExtensionRegistry* upb_DefPool_ExtensionRegistry( + const upb_DefPool* s) { + return s->extreg; } -const upb_FieldDef* upb_MessageDef_FindFieldByNameWithSize( - const upb_MessageDef* m, const char* name, size_t size) { +const upb_FieldDef** upb_DefPool_GetAllExtensions(const upb_DefPool* s, + const upb_MessageDef* m, + size_t* count) { + size_t n = 0; + intptr_t iter = UPB_INTTABLE_BEGIN; + uintptr_t key; upb_value val; - - if (!upb_strtable_lookup2(&m->ntof, name, size, &val)) { - return NULL; + // This is O(all exts) instead of O(exts for m). If we need this to be + // efficient we may need to make extreg into a two-level table, or have a + // second per-message index. + while (upb_inttable_next(&s->exts, &key, &val, &iter)) { + const upb_FieldDef* f = upb_value_getconstptr(val); + if (upb_FieldDef_ContainingType(f) == m) n++; } + const upb_FieldDef** exts = upb_gmalloc(n * sizeof(*exts)); + iter = UPB_INTTABLE_BEGIN; + size_t i = 0; + while (upb_inttable_next(&s->exts, &key, &val, &iter)) { + const upb_FieldDef* f = upb_value_getconstptr(val); + if (upb_FieldDef_ContainingType(f) == m) exts[i++] = f; + } + *count = n; + return exts; +} - return _upb_DefType_Unpack(val, UPB_DEFTYPE_FIELD); +bool _upb_DefPool_LoadDefInit(upb_DefPool* s, const _upb_DefPool_Init* init) { + return _upb_DefPool_LoadDefInitEx(s, init, false); } -const upb_OneofDef* upb_MessageDef_FindOneofByNameWithSize( - const upb_MessageDef* m, const char* name, size_t size) { - upb_value val; - if (!upb_strtable_lookup2(&m->ntof, name, size, &val)) { - return NULL; - } +// Must be last. - return _upb_DefType_Unpack(val, UPB_DEFTYPE_ONEOF); +upb_deftype_t _upb_DefType_Type(upb_value v) { + const uintptr_t num = (uintptr_t)upb_value_getconstptr(v); + return num & UPB_DEFTYPE_MASK; } -bool _upb_MessageDef_Insert(upb_MessageDef* m, const char* name, size_t len, - upb_value v, upb_Arena* a) { - return upb_strtable_insert(&m->ntof, name, len, v, a); +upb_value _upb_DefType_Pack(const void* ptr, upb_deftype_t type) { + uintptr_t num = (uintptr_t)ptr; + UPB_ASSERT((num & UPB_DEFTYPE_MASK) == 0); + num |= type; + return upb_value_constptr((const void*)num); } -bool upb_MessageDef_FindByNameWithSize(const upb_MessageDef* m, - const char* name, size_t len, - const upb_FieldDef** out_f, - const upb_OneofDef** out_o) { - upb_value val; +const void* _upb_DefType_Unpack(upb_value v, upb_deftype_t type) { + uintptr_t num = (uintptr_t)upb_value_getconstptr(v); + return (num & UPB_DEFTYPE_MASK) == type + ? (const void*)(num & ~UPB_DEFTYPE_MASK) + : NULL; +} - if (!upb_strtable_lookup2(&m->ntof, name, len, &val)) { - return false; - } - const upb_FieldDef* f = _upb_DefType_Unpack(val, UPB_DEFTYPE_FIELD); - const upb_OneofDef* o = _upb_DefType_Unpack(val, UPB_DEFTYPE_ONEOF); - if (out_f) *out_f = f; - if (out_o) *out_o = o; - return f || o; /* False if this was a JSON name. */ -} +// Must be last. -const upb_FieldDef* upb_MessageDef_FindByJsonNameWithSize( - const upb_MessageDef* m, const char* name, size_t size) { - upb_value val; +bool _upb_DescState_Grow(upb_DescState* d, upb_Arena* a) { + const size_t oldbufsize = d->bufsize; + const int used = d->ptr - d->buf; - if (upb_strtable_lookup2(&m->jtof, name, size, &val)) { - return upb_value_getconstptr(val); + if (!d->buf) { + d->buf = upb_Arena_Malloc(a, d->bufsize); + if (!d->buf) return false; + d->ptr = d->buf; + d->e.end = d->buf + d->bufsize; } - if (!upb_strtable_lookup2(&m->ntof, name, size, &val)) { - return NULL; + if (oldbufsize - used < kUpb_MtDataEncoder_MinSize) { + d->bufsize *= 2; + d->buf = upb_Arena_Realloc(a, d->buf, oldbufsize, d->bufsize); + if (!d->buf) return false; + d->ptr = d->buf + used; + d->e.end = d->buf + d->bufsize; } - return _upb_DefType_Unpack(val, UPB_DEFTYPE_FIELD); + return true; } -int upb_MessageDef_ExtensionRangeCount(const upb_MessageDef* m) { - return m->ext_range_count; + +#include +#include +#include + + +// Must be last. + +struct upb_EnumDef { + const UPB_DESC(EnumOptions*) opts; + const UPB_DESC(FeatureSet*) resolved_features; + const upb_MiniTableEnum* layout; // Only for proto2. + const upb_FileDef* file; + const upb_MessageDef* containing_type; // Could be merged with "file". + const char* full_name; + upb_strtable ntoi; + upb_inttable iton; + const upb_EnumValueDef* values; + const upb_EnumReservedRange* res_ranges; + const upb_StringView* res_names; + int value_count; + int res_range_count; + int res_name_count; + int32_t defaultval; + bool is_sorted; // Whether all of the values are defined in ascending order. +#if UINTPTR_MAX == 0xffffffff + uint32_t padding; // Increase size to a multiple of 8. +#endif +}; + +upb_EnumDef* _upb_EnumDef_At(const upb_EnumDef* e, int i) { + return (upb_EnumDef*)&e[i]; } -int upb_MessageDef_ReservedRangeCount(const upb_MessageDef* m) { - return m->res_range_count; +const upb_MiniTableEnum* _upb_EnumDef_MiniTable(const upb_EnumDef* e) { + return e->layout; } -int upb_MessageDef_ReservedNameCount(const upb_MessageDef* m) { - return m->res_name_count; -} +bool _upb_EnumDef_Insert(upb_EnumDef* e, upb_EnumValueDef* v, upb_Arena* a) { + const char* name = upb_EnumValueDef_Name(v); + const upb_value val = upb_value_constptr(v); + bool ok = upb_strtable_insert(&e->ntoi, name, strlen(name), val, a); + if (!ok) return false; -int upb_MessageDef_FieldCount(const upb_MessageDef* m) { - return m->field_count; + // Multiple enumerators can have the same number, first one wins. + const int number = upb_EnumValueDef_Number(v); + if (!upb_inttable_lookup(&e->iton, number, NULL)) { + return upb_inttable_insert(&e->iton, number, val, a); + } + return true; } -int upb_MessageDef_OneofCount(const upb_MessageDef* m) { - return m->oneof_count; +const UPB_DESC(EnumOptions) * upb_EnumDef_Options(const upb_EnumDef* e) { + return e->opts; } -int upb_MessageDef_RealOneofCount(const upb_MessageDef* m) { - return m->real_oneof_count; +bool upb_EnumDef_HasOptions(const upb_EnumDef* e) { + return e->opts != (void*)kUpbDefOptDefault; } -int upb_MessageDef_NestedMessageCount(const upb_MessageDef* m) { - return m->nested_msg_count; +const UPB_DESC(FeatureSet) * + upb_EnumDef_ResolvedFeatures(const upb_EnumDef* e) { + return e->resolved_features; } -int upb_MessageDef_NestedEnumCount(const upb_MessageDef* m) { - return m->nested_enum_count; -} +const char* upb_EnumDef_FullName(const upb_EnumDef* e) { return e->full_name; } -int upb_MessageDef_NestedExtensionCount(const upb_MessageDef* m) { - return m->nested_ext_count; +const char* upb_EnumDef_Name(const upb_EnumDef* e) { + return _upb_DefBuilder_FullToShort(e->full_name); } -const upb_MiniTable* upb_MessageDef_MiniTable(const upb_MessageDef* m) { - return m->layout; -} +const upb_FileDef* upb_EnumDef_File(const upb_EnumDef* e) { return e->file; } -const upb_ExtensionRange* upb_MessageDef_ExtensionRange(const upb_MessageDef* m, - int i) { - UPB_ASSERT(0 <= i && i < m->ext_range_count); - return _upb_ExtensionRange_At(m->ext_ranges, i); +const upb_MessageDef* upb_EnumDef_ContainingType(const upb_EnumDef* e) { + return e->containing_type; } -const upb_MessageReservedRange* upb_MessageDef_ReservedRange( - const upb_MessageDef* m, int i) { - UPB_ASSERT(0 <= i && i < m->res_range_count); - return _upb_MessageReservedRange_At(m->res_ranges, i); +int32_t upb_EnumDef_Default(const upb_EnumDef* e) { + UPB_ASSERT(upb_EnumDef_FindValueByNumber(e, e->defaultval)); + return e->defaultval; } -upb_StringView upb_MessageDef_ReservedName(const upb_MessageDef* m, int i) { - UPB_ASSERT(0 <= i && i < m->res_name_count); - return m->res_names[i]; +int upb_EnumDef_ReservedRangeCount(const upb_EnumDef* e) { + return e->res_range_count; } -const upb_FieldDef* upb_MessageDef_Field(const upb_MessageDef* m, int i) { - UPB_ASSERT(0 <= i && i < m->field_count); - return _upb_FieldDef_At(m->fields, i); +const upb_EnumReservedRange* upb_EnumDef_ReservedRange(const upb_EnumDef* e, + int i) { + UPB_ASSERT(0 <= i && i < e->res_range_count); + return _upb_EnumReservedRange_At(e->res_ranges, i); } -const upb_OneofDef* upb_MessageDef_Oneof(const upb_MessageDef* m, int i) { - UPB_ASSERT(0 <= i && i < m->oneof_count); - return _upb_OneofDef_At(m->oneofs, i); +int upb_EnumDef_ReservedNameCount(const upb_EnumDef* e) { + return e->res_name_count; } -const upb_MessageDef* upb_MessageDef_NestedMessage(const upb_MessageDef* m, - int i) { - UPB_ASSERT(0 <= i && i < m->nested_msg_count); - return &m->nested_msgs[i]; +upb_StringView upb_EnumDef_ReservedName(const upb_EnumDef* e, int i) { + UPB_ASSERT(0 <= i && i < e->res_name_count); + return e->res_names[i]; } -const upb_EnumDef* upb_MessageDef_NestedEnum(const upb_MessageDef* m, int i) { - UPB_ASSERT(0 <= i && i < m->nested_enum_count); - return _upb_EnumDef_At(m->nested_enums, i); -} +int upb_EnumDef_ValueCount(const upb_EnumDef* e) { return e->value_count; } -const upb_FieldDef* upb_MessageDef_NestedExtension(const upb_MessageDef* m, - int i) { - UPB_ASSERT(0 <= i && i < m->nested_ext_count); - return _upb_FieldDef_At(m->nested_exts, i); +const upb_EnumValueDef* upb_EnumDef_FindValueByName(const upb_EnumDef* e, + const char* name) { + return upb_EnumDef_FindValueByNameWithSize(e, name, strlen(name)); } -upb_WellKnown upb_MessageDef_WellKnownType(const upb_MessageDef* m) { - return m->well_known_type; +const upb_EnumValueDef* upb_EnumDef_FindValueByNameWithSize( + const upb_EnumDef* e, const char* name, size_t size) { + upb_value v; + return upb_strtable_lookup2(&e->ntoi, name, size, &v) + ? upb_value_getconstptr(v) + : NULL; } -bool _upb_MessageDef_InMessageSet(const upb_MessageDef* m) { - return m->in_message_set; +const upb_EnumValueDef* upb_EnumDef_FindValueByNumber(const upb_EnumDef* e, + int32_t num) { + upb_value v; + return upb_inttable_lookup(&e->iton, num, &v) ? upb_value_getconstptr(v) + : NULL; } -const upb_FieldDef* upb_MessageDef_FindFieldByName(const upb_MessageDef* m, - const char* name) { - return upb_MessageDef_FindFieldByNameWithSize(m, name, strlen(name)); +bool upb_EnumDef_CheckNumber(const upb_EnumDef* e, int32_t num) { + // We could use upb_EnumDef_FindValueByNumber(e, num) != NULL, but we expect + // this to be faster (especially for small numbers). + return upb_MiniTableEnum_CheckValue(e->layout, num); } -const upb_OneofDef* upb_MessageDef_FindOneofByName(const upb_MessageDef* m, - const char* name) { - return upb_MessageDef_FindOneofByNameWithSize(m, name, strlen(name)); +const upb_EnumValueDef* upb_EnumDef_Value(const upb_EnumDef* e, int i) { + UPB_ASSERT(0 <= i && i < e->value_count); + return _upb_EnumValueDef_At(e->values, i); } -bool upb_MessageDef_IsMapEntry(const upb_MessageDef* m) { - return UPB_DESC(MessageOptions_map_entry)(m->opts); +bool upb_EnumDef_IsClosed(const upb_EnumDef* e) { + if (UPB_TREAT_PROTO2_ENUMS_LIKE_PROTO3) return false; + return UPB_DESC(FeatureSet_enum_type)(e->resolved_features) == + UPB_DESC(FeatureSet_CLOSED); } -bool upb_MessageDef_IsMessageSet(const upb_MessageDef* m) { - return UPB_DESC(MessageOptions_message_set_wire_format)(m->opts); -} +bool upb_EnumDef_MiniDescriptorEncode(const upb_EnumDef* e, upb_Arena* a, + upb_StringView* out) { + upb_DescState s; + _upb_DescState_Init(&s); -static upb_MiniTable* _upb_MessageDef_MakeMiniTable(upb_DefBuilder* ctx, - const upb_MessageDef* m) { - upb_StringView desc; - // Note: this will assign layout_index for fields, so upb_FieldDef_MiniTable() - // is safe to call only after this call. - bool ok = upb_MessageDef_MiniDescriptorEncode(m, ctx->tmp_arena, &desc); - if (!ok) _upb_DefBuilder_OomErr(ctx); + const upb_EnumValueDef** sorted = NULL; + if (!e->is_sorted) { + sorted = _upb_EnumValueDefs_Sorted(e->values, e->value_count, a); + if (!sorted) return false; + } - void** scratch_data = _upb_DefPool_ScratchData(ctx->symtab); - size_t* scratch_size = _upb_DefPool_ScratchSize(ctx->symtab); - upb_MiniTable* ret = upb_MiniTable_BuildWithBuf( - desc.data, desc.size, ctx->platform, ctx->arena, scratch_data, - scratch_size, ctx->status); - if (!ret) _upb_DefBuilder_FailJmp(ctx); + if (!_upb_DescState_Grow(&s, a)) return false; + s.ptr = upb_MtDataEncoder_StartEnum(&s.e, s.ptr); - return ret; -} + // Duplicate values are allowed but we only encode each value once. + uint32_t previous = 0; -void _upb_MessageDef_Resolve(upb_DefBuilder* ctx, upb_MessageDef* m) { - for (int i = 0; i < m->field_count; i++) { - upb_FieldDef* f = (upb_FieldDef*)upb_MessageDef_Field(m, i); - _upb_FieldDef_Resolve(ctx, m->full_name, f); - } + for (int i = 0; i < e->value_count; i++) { + const uint32_t current = + upb_EnumValueDef_Number(sorted ? sorted[i] : upb_EnumDef_Value(e, i)); + if (i != 0 && previous == current) continue; - m->in_message_set = false; - for (int i = 0; i < upb_MessageDef_NestedExtensionCount(m); i++) { - upb_FieldDef* ext = (upb_FieldDef*)upb_MessageDef_NestedExtension(m, i); - _upb_FieldDef_Resolve(ctx, m->full_name, ext); - if (upb_FieldDef_Type(ext) == kUpb_FieldType_Message && - upb_FieldDef_Label(ext) == kUpb_Label_Optional && - upb_FieldDef_MessageSubDef(ext) == m && - UPB_DESC(MessageOptions_message_set_wire_format)( - upb_MessageDef_Options(upb_FieldDef_ContainingType(ext)))) { - m->in_message_set = true; - } + if (!_upb_DescState_Grow(&s, a)) return false; + s.ptr = upb_MtDataEncoder_PutEnumValue(&s.e, s.ptr, current); + previous = current; } - for (int i = 0; i < upb_MessageDef_NestedMessageCount(m); i++) { - upb_MessageDef* n = (upb_MessageDef*)upb_MessageDef_NestedMessage(m, i); - _upb_MessageDef_Resolve(ctx, n); - } -} + if (!_upb_DescState_Grow(&s, a)) return false; + s.ptr = upb_MtDataEncoder_EndEnum(&s.e, s.ptr); -void _upb_MessageDef_InsertField(upb_DefBuilder* ctx, upb_MessageDef* m, - const upb_FieldDef* f) { - const int32_t field_number = upb_FieldDef_Number(f); + // There will always be room for this '\0' in the encoder buffer because + // kUpb_MtDataEncoder_MinSize is overkill for upb_MtDataEncoder_EndEnum(). + UPB_ASSERT(s.ptr < s.buf + s.bufsize); + *s.ptr = '\0'; - if (field_number <= 0 || field_number > kUpb_MaxFieldNumber) { - _upb_DefBuilder_Errf(ctx, "invalid field number (%u)", field_number); - } + out->data = s.buf; + out->size = s.ptr - s.buf; + return true; +} - const char* json_name = upb_FieldDef_JsonName(f); - const char* shortname = upb_FieldDef_Name(f); - const size_t shortnamelen = strlen(shortname); +static upb_MiniTableEnum* create_enumlayout(upb_DefBuilder* ctx, + const upb_EnumDef* e) { + upb_StringView sv; + bool ok = upb_EnumDef_MiniDescriptorEncode(e, ctx->tmp_arena, &sv); + if (!ok) _upb_DefBuilder_Errf(ctx, "OOM while building enum MiniDescriptor"); - upb_value v = upb_value_constptr(f); + upb_Status status; + upb_MiniTableEnum* layout = + upb_MiniTableEnum_Build(sv.data, sv.size, ctx->arena, &status); + if (!layout) + _upb_DefBuilder_Errf(ctx, "Error building enum MiniTable: %s", status.msg); + return layout; +} - upb_value existing_v; - if (upb_strtable_lookup(&m->ntof, shortname, &existing_v)) { - _upb_DefBuilder_Errf(ctx, "duplicate field name (%s)", shortname); +static upb_StringView* _upb_EnumReservedNames_New( + upb_DefBuilder* ctx, int n, const upb_StringView* protos) { + upb_StringView* sv = _upb_DefBuilder_Alloc(ctx, sizeof(upb_StringView) * n); + for (int i = 0; i < n; i++) { + sv[i].data = + upb_strdup2(protos[i].data, protos[i].size, _upb_DefBuilder_Arena(ctx)); + sv[i].size = protos[i].size; } + return sv; +} - const upb_value field_v = _upb_DefType_Pack(f, UPB_DEFTYPE_FIELD); - bool ok = - _upb_MessageDef_Insert(m, shortname, shortnamelen, field_v, ctx->arena); - if (!ok) _upb_DefBuilder_OomErr(ctx); +static void create_enumdef(upb_DefBuilder* ctx, const char* prefix, + const UPB_DESC(EnumDescriptorProto) * enum_proto, + const UPB_DESC(FeatureSet*) parent_features, + upb_EnumDef* e) { + const UPB_DESC(EnumValueDescriptorProto)* const* values; + const UPB_DESC(EnumDescriptorProto_EnumReservedRange)* const* res_ranges; + const upb_StringView* res_names; + upb_StringView name; + size_t n_value, n_res_range, n_res_name; - if (strcmp(shortname, json_name) != 0 && - UPB_DESC(FeatureSet_json_format)(m->resolved_features) == - UPB_DESC(FeatureSet_ALLOW) && - upb_strtable_lookup(&m->ntof, json_name, &v)) { - _upb_DefBuilder_Errf( - ctx, "duplicate json_name for (%s) with original field name (%s)", - shortname, json_name); - } + UPB_DEF_SET_OPTIONS(e->opts, EnumDescriptorProto, EnumOptions, enum_proto); + e->resolved_features = _upb_DefBuilder_ResolveFeatures( + ctx, parent_features, UPB_DESC(EnumOptions_features)(e->opts)); - if (upb_strtable_lookup(&m->jtof, json_name, &v)) { - _upb_DefBuilder_Errf(ctx, "duplicate json_name (%s)", json_name); - } + // Must happen before _upb_DefBuilder_Add() + e->file = _upb_DefBuilder_File(ctx); - const size_t json_size = strlen(json_name); - ok = upb_strtable_insert(&m->jtof, json_name, json_size, - upb_value_constptr(f), ctx->arena); - if (!ok) _upb_DefBuilder_OomErr(ctx); + name = UPB_DESC(EnumDescriptorProto_name)(enum_proto); - if (upb_inttable_lookup(&m->itof, field_number, NULL)) { - _upb_DefBuilder_Errf(ctx, "duplicate field number (%u)", field_number); - } + e->full_name = _upb_DefBuilder_MakeFullName(ctx, prefix, name); + _upb_DefBuilder_Add(ctx, e->full_name, + _upb_DefType_Pack(e, UPB_DEFTYPE_ENUM)); - ok = upb_inttable_insert(&m->itof, field_number, v, ctx->arena); - if (!ok) _upb_DefBuilder_OomErr(ctx); -} + values = UPB_DESC(EnumDescriptorProto_value)(enum_proto, &n_value); -void _upb_MessageDef_CreateMiniTable(upb_DefBuilder* ctx, upb_MessageDef* m) { - if (ctx->layout == NULL) { - m->layout = _upb_MessageDef_MakeMiniTable(ctx, m); - } else { - m->layout = upb_MiniTableFile_Message(ctx->layout, ctx->msg_count++); - UPB_ASSERT(m->field_count == m->layout->UPB_PRIVATE(field_count)); + bool ok = upb_strtable_init(&e->ntoi, n_value, ctx->arena); + if (!ok) _upb_DefBuilder_OomErr(ctx); - // We don't need the result of this call, but it will assign layout_index - // for all the fields in O(n lg n) time. - _upb_FieldDefs_Sorted(m->fields, m->field_count, ctx->tmp_arena); - } + ok = upb_inttable_init(&e->iton, ctx->arena); + if (!ok) _upb_DefBuilder_OomErr(ctx); - for (int i = 0; i < m->nested_msg_count; i++) { - upb_MessageDef* nested = - (upb_MessageDef*)upb_MessageDef_NestedMessage(m, i); - _upb_MessageDef_CreateMiniTable(ctx, nested); - } -} + e->defaultval = 0; + e->value_count = n_value; + e->values = _upb_EnumValueDefs_New(ctx, prefix, n_value, values, + e->resolved_features, e, &e->is_sorted); -void _upb_MessageDef_LinkMiniTable(upb_DefBuilder* ctx, - const upb_MessageDef* m) { - for (int i = 0; i < upb_MessageDef_NestedExtensionCount(m); i++) { - const upb_FieldDef* ext = upb_MessageDef_NestedExtension(m, i); - _upb_FieldDef_BuildMiniTableExtension(ctx, ext); + if (n_value == 0) { + _upb_DefBuilder_Errf(ctx, "enums must contain at least one value (%s)", + e->full_name); } - for (int i = 0; i < m->nested_msg_count; i++) { - _upb_MessageDef_LinkMiniTable(ctx, upb_MessageDef_NestedMessage(m, i)); - } + res_ranges = + UPB_DESC(EnumDescriptorProto_reserved_range)(enum_proto, &n_res_range); + e->res_range_count = n_res_range; + e->res_ranges = _upb_EnumReservedRanges_New(ctx, n_res_range, res_ranges, e); - if (ctx->layout) return; + res_names = + UPB_DESC(EnumDescriptorProto_reserved_name)(enum_proto, &n_res_name); + e->res_name_count = n_res_name; + e->res_names = _upb_EnumReservedNames_New(ctx, n_res_name, res_names); - for (int i = 0; i < m->field_count; i++) { - const upb_FieldDef* f = upb_MessageDef_Field(m, i); - const upb_MessageDef* sub_m = upb_FieldDef_MessageSubDef(f); - const upb_EnumDef* sub_e = upb_FieldDef_EnumSubDef(f); - const int layout_index = _upb_FieldDef_LayoutIndex(f); - upb_MiniTable* mt = (upb_MiniTable*)upb_MessageDef_MiniTable(m); + upb_inttable_compact(&e->iton, ctx->arena); - UPB_ASSERT(layout_index < m->field_count); - upb_MiniTableField* mt_f = - (upb_MiniTableField*)&m->layout->UPB_PRIVATE(fields)[layout_index]; - if (sub_m) { - if (!mt->UPB_PRIVATE(subs)) { - _upb_DefBuilder_Errf(ctx, "unexpected submsg for (%s)", m->full_name); - } - UPB_ASSERT(mt_f); - UPB_ASSERT(sub_m->layout); - if (UPB_UNLIKELY(!upb_MiniTable_SetSubMessage(mt, mt_f, sub_m->layout))) { - _upb_DefBuilder_Errf(ctx, "invalid submsg for (%s)", m->full_name); - } - } else if (_upb_FieldDef_IsClosedEnum(f)) { - const upb_MiniTableEnum* mt_e = _upb_EnumDef_MiniTable(sub_e); - if (UPB_UNLIKELY(!upb_MiniTable_SetSubEnum(mt, mt_f, mt_e))) { - _upb_DefBuilder_Errf(ctx, "invalid subenum for (%s)", m->full_name); - } + if (upb_EnumDef_IsClosed(e)) { + if (ctx->layout) { + e->layout = upb_MiniTableFile_Enum(ctx->layout, ctx->enum_count++); + } else { + e->layout = create_enumlayout(ctx, e); } + } else { + e->layout = NULL; } - -#ifndef NDEBUG - for (int i = 0; i < m->field_count; i++) { - const upb_FieldDef* f = upb_MessageDef_Field(m, i); - const int layout_index = _upb_FieldDef_LayoutIndex(f); - UPB_ASSERT(layout_index < m->layout->UPB_PRIVATE(field_count)); - const upb_MiniTableField* mt_f = - &m->layout->UPB_PRIVATE(fields)[layout_index]; - UPB_ASSERT(upb_FieldDef_Type(f) == upb_MiniTableField_Type(mt_f)); - UPB_ASSERT(upb_FieldDef_CType(f) == upb_MiniTableField_CType(mt_f)); - UPB_ASSERT(upb_FieldDef_HasPresence(f) == - upb_MiniTableField_HasPresence(mt_f)); - } -#endif } -static bool _upb_MessageDef_ValidateUtf8(const upb_MessageDef* m) { - bool has_string = false; - for (int i = 0; i < m->field_count; i++) { - const upb_FieldDef* f = upb_MessageDef_Field(m, i); - // Old binaries do not recognize the field-level "FlipValidateUtf8" wire - // modifier, so we do not actually have field-level control for old - // binaries. Given this, we judge that the better failure mode is to be - // more lax than intended, rather than more strict. To achieve this, we - // only mark the message with the ValidateUtf8 modifier if *all* fields - // validate UTF-8. - if (!_upb_FieldDef_ValidateUtf8(f)) return false; - if (upb_FieldDef_Type(f) == kUpb_FieldType_String) has_string = true; +upb_EnumDef* _upb_EnumDefs_New(upb_DefBuilder* ctx, int n, + const UPB_DESC(EnumDescriptorProto*) + const* protos, + const UPB_DESC(FeatureSet*) parent_features, + const upb_MessageDef* containing_type) { + _upb_DefType_CheckPadding(sizeof(upb_EnumDef)); + + // If a containing type is defined then get the full name from that. + // Otherwise use the package name from the file def. + const char* name = containing_type ? upb_MessageDef_FullName(containing_type) + : _upb_FileDef_RawPackage(ctx->file); + + upb_EnumDef* e = _upb_DefBuilder_Alloc(ctx, sizeof(upb_EnumDef) * n); + for (int i = 0; i < n; i++) { + create_enumdef(ctx, name, protos[i], parent_features, &e[i]); + e[i].containing_type = containing_type; } - return has_string; + return e; } -static uint64_t _upb_MessageDef_Modifiers(const upb_MessageDef* m) { - uint64_t out = 0; - if (UPB_DESC(FeatureSet_repeated_field_encoding(m->resolved_features)) == - UPB_DESC(FeatureSet_PACKED)) { - out |= kUpb_MessageModifier_DefaultIsPacked; - } - if (_upb_MessageDef_ValidateUtf8(m)) { - out |= kUpb_MessageModifier_ValidateUtf8; - } +// Must be last. - if (m->ext_range_count) { - out |= kUpb_MessageModifier_IsExtendable; - } +struct upb_EnumReservedRange { + int32_t start; + int32_t end; +}; - return out; +upb_EnumReservedRange* _upb_EnumReservedRange_At(const upb_EnumReservedRange* r, + int i) { + return (upb_EnumReservedRange*)&r[i]; } -static bool _upb_MessageDef_EncodeMap(upb_DescState* s, const upb_MessageDef* m, - upb_Arena* a) { - if (m->field_count != 2) return false; +int32_t upb_EnumReservedRange_Start(const upb_EnumReservedRange* r) { + return r->start; +} +int32_t upb_EnumReservedRange_End(const upb_EnumReservedRange* r) { + return r->end; +} - const upb_FieldDef* key_field = upb_MessageDef_Field(m, 0); - const upb_FieldDef* val_field = upb_MessageDef_Field(m, 1); - if (key_field == NULL || val_field == NULL) return false; +upb_EnumReservedRange* _upb_EnumReservedRanges_New( + upb_DefBuilder* ctx, int n, + const UPB_DESC(EnumDescriptorProto_EnumReservedRange) * const* protos, + const upb_EnumDef* e) { + upb_EnumReservedRange* r = + _upb_DefBuilder_Alloc(ctx, sizeof(upb_EnumReservedRange) * n); - UPB_ASSERT(_upb_FieldDef_LayoutIndex(key_field) == 0); - UPB_ASSERT(_upb_FieldDef_LayoutIndex(val_field) == 1); + for (int i = 0; i < n; i++) { + const int32_t start = + UPB_DESC(EnumDescriptorProto_EnumReservedRange_start)(protos[i]); + const int32_t end = + UPB_DESC(EnumDescriptorProto_EnumReservedRange_end)(protos[i]); - s->ptr = upb_MtDataEncoder_EncodeMap( - &s->e, s->ptr, upb_FieldDef_Type(key_field), upb_FieldDef_Type(val_field), - _upb_FieldDef_Modifiers(key_field), _upb_FieldDef_Modifiers(val_field)); - return true; -} + // A full validation would also check that each range is disjoint, and that + // none of the fields overlap with the extension ranges, but we are just + // sanity checking here. -static bool _upb_MessageDef_EncodeMessage(upb_DescState* s, - const upb_MessageDef* m, - upb_Arena* a) { - const upb_FieldDef** sorted = NULL; - if (!m->is_sorted) { - sorted = _upb_FieldDefs_Sorted(m->fields, m->field_count, a); - if (!sorted) return false; + // Note: Not a typo! Unlike extension ranges and message reserved ranges, + // the end value of an enum reserved range is *inclusive*! + if (end < start) { + _upb_DefBuilder_Errf(ctx, "Reserved range (%d, %d) is invalid, enum=%s\n", + (int)start, (int)end, upb_EnumDef_FullName(e)); + } + + r[i].start = start; + r[i].end = end; } - s->ptr = upb_MtDataEncoder_StartMessage(&s->e, s->ptr, - _upb_MessageDef_Modifiers(m)); + return r; +} - for (int i = 0; i < m->field_count; i++) { - const upb_FieldDef* f = sorted ? sorted[i] : upb_MessageDef_Field(m, i); - const upb_FieldType type = upb_FieldDef_Type(f); - const int number = upb_FieldDef_Number(f); - const uint64_t modifiers = _upb_FieldDef_Modifiers(f); - if (!_upb_DescState_Grow(s, a)) return false; - s->ptr = upb_MtDataEncoder_PutField(&s->e, s->ptr, type, number, modifiers); - } +#include - for (int i = 0; i < m->real_oneof_count; i++) { - if (!_upb_DescState_Grow(s, a)) return false; - s->ptr = upb_MtDataEncoder_StartOneof(&s->e, s->ptr); - const upb_OneofDef* o = upb_MessageDef_Oneof(m, i); - const int field_count = upb_OneofDef_FieldCount(o); - for (int j = 0; j < field_count; j++) { - const int number = upb_FieldDef_Number(upb_OneofDef_Field(o, j)); +// Must be last. - if (!_upb_DescState_Grow(s, a)) return false; - s->ptr = upb_MtDataEncoder_PutOneofField(&s->e, s->ptr, number); - } - } +struct upb_EnumValueDef { + const UPB_DESC(EnumValueOptions*) opts; + const UPB_DESC(FeatureSet*) resolved_features; + const upb_EnumDef* parent; + const char* full_name; + int32_t number; +#if UINTPTR_MAX == 0xffffffff + uint32_t padding; // Increase size to a multiple of 8. +#endif +}; - return true; +upb_EnumValueDef* _upb_EnumValueDef_At(const upb_EnumValueDef* v, int i) { + return (upb_EnumValueDef*)&v[i]; } -static bool _upb_MessageDef_EncodeMessageSet(upb_DescState* s, - const upb_MessageDef* m, - upb_Arena* a) { - s->ptr = upb_MtDataEncoder_EncodeMessageSet(&s->e, s->ptr); - - return true; +static int _upb_EnumValueDef_Compare(const void* p1, const void* p2) { + const uint32_t v1 = (*(const upb_EnumValueDef**)p1)->number; + const uint32_t v2 = (*(const upb_EnumValueDef**)p2)->number; + return (v1 < v2) ? -1 : (v1 > v2); } -bool upb_MessageDef_MiniDescriptorEncode(const upb_MessageDef* m, upb_Arena* a, - upb_StringView* out) { - upb_DescState s; - _upb_DescState_Init(&s); - - if (!_upb_DescState_Grow(&s, a)) return false; +const upb_EnumValueDef** _upb_EnumValueDefs_Sorted(const upb_EnumValueDef* v, + int n, upb_Arena* a) { + // TODO: Try to replace this arena alloc with a persistent scratch buffer. + upb_EnumValueDef** out = + (upb_EnumValueDef**)upb_Arena_Malloc(a, n * sizeof(void*)); + if (!out) return NULL; - if (upb_MessageDef_IsMapEntry(m)) { - if (!_upb_MessageDef_EncodeMap(&s, m, a)) return false; - } else if (UPB_DESC(MessageOptions_message_set_wire_format)(m->opts)) { - if (!_upb_MessageDef_EncodeMessageSet(&s, m, a)) return false; - } else { - if (!_upb_MessageDef_EncodeMessage(&s, m, a)) return false; + for (int i = 0; i < n; i++) { + out[i] = (upb_EnumValueDef*)&v[i]; } + qsort(out, n, sizeof(void*), _upb_EnumValueDef_Compare); - if (!_upb_DescState_Grow(&s, a)) return false; - *s.ptr = '\0'; + return (const upb_EnumValueDef**)out; +} - out->data = s.buf; - out->size = s.ptr - s.buf; - return true; +const UPB_DESC(EnumValueOptions) * + upb_EnumValueDef_Options(const upb_EnumValueDef* v) { + return v->opts; } -static upb_StringView* _upb_ReservedNames_New(upb_DefBuilder* ctx, int n, - const upb_StringView* protos) { - upb_StringView* sv = _upb_DefBuilder_Alloc(ctx, sizeof(upb_StringView) * n); - for (int i = 0; i < n; i++) { - sv[i].data = - upb_strdup2(protos[i].data, protos[i].size, _upb_DefBuilder_Arena(ctx)); - sv[i].size = protos[i].size; - } - return sv; +bool upb_EnumValueDef_HasOptions(const upb_EnumValueDef* v) { + return v->opts != (void*)kUpbDefOptDefault; } -static void create_msgdef(upb_DefBuilder* ctx, const char* prefix, - const UPB_DESC(DescriptorProto*) msg_proto, - const UPB_DESC(FeatureSet*) parent_features, - const upb_MessageDef* containing_type, - upb_MessageDef* m) { - const UPB_DESC(OneofDescriptorProto)* const* oneofs; - const UPB_DESC(FieldDescriptorProto)* const* fields; - const UPB_DESC(DescriptorProto_ExtensionRange)* const* ext_ranges; - const UPB_DESC(DescriptorProto_ReservedRange)* const* res_ranges; - const upb_StringView* res_names; - size_t n_oneof, n_field, n_enum, n_ext, n_msg; - size_t n_ext_range, n_res_range, n_res_name; - upb_StringView name; +const UPB_DESC(FeatureSet) * + upb_EnumValueDef_ResolvedFeatures(const upb_EnumValueDef* e) { + return e->resolved_features; +} - UPB_DEF_SET_OPTIONS(m->opts, DescriptorProto, MessageOptions, msg_proto); - m->resolved_features = _upb_DefBuilder_ResolveFeatures( - ctx, parent_features, UPB_DESC(MessageOptions_features)(m->opts)); +const upb_EnumDef* upb_EnumValueDef_Enum(const upb_EnumValueDef* v) { + return v->parent; +} - // Must happen before _upb_DefBuilder_Add() - m->file = _upb_DefBuilder_File(ctx); +const char* upb_EnumValueDef_FullName(const upb_EnumValueDef* v) { + return v->full_name; +} - m->containing_type = containing_type; - m->is_sorted = true; +const char* upb_EnumValueDef_Name(const upb_EnumValueDef* v) { + return _upb_DefBuilder_FullToShort(v->full_name); +} - name = UPB_DESC(DescriptorProto_name)(msg_proto); +int32_t upb_EnumValueDef_Number(const upb_EnumValueDef* v) { return v->number; } - m->full_name = _upb_DefBuilder_MakeFullName(ctx, prefix, name); - _upb_DefBuilder_Add(ctx, m->full_name, _upb_DefType_Pack(m, UPB_DEFTYPE_MSG)); +uint32_t upb_EnumValueDef_Index(const upb_EnumValueDef* v) { + // Compute index in our parent's array. + return v - upb_EnumDef_Value(v->parent, 0); +} - oneofs = UPB_DESC(DescriptorProto_oneof_decl)(msg_proto, &n_oneof); - fields = UPB_DESC(DescriptorProto_field)(msg_proto, &n_field); - ext_ranges = - UPB_DESC(DescriptorProto_extension_range)(msg_proto, &n_ext_range); - res_ranges = - UPB_DESC(DescriptorProto_reserved_range)(msg_proto, &n_res_range); - res_names = UPB_DESC(DescriptorProto_reserved_name)(msg_proto, &n_res_name); +static void create_enumvaldef(upb_DefBuilder* ctx, const char* prefix, + const UPB_DESC(EnumValueDescriptorProto*) + val_proto, + const UPB_DESC(FeatureSet*) parent_features, + upb_EnumDef* e, upb_EnumValueDef* v) { + UPB_DEF_SET_OPTIONS(v->opts, EnumValueDescriptorProto, EnumValueOptions, + val_proto); + v->resolved_features = _upb_DefBuilder_ResolveFeatures( + ctx, parent_features, UPB_DESC(EnumValueOptions_features)(v->opts)); - bool ok = upb_inttable_init(&m->itof, ctx->arena); - if (!ok) _upb_DefBuilder_OomErr(ctx); + upb_StringView name = UPB_DESC(EnumValueDescriptorProto_name)(val_proto); - ok = upb_strtable_init(&m->ntof, n_oneof + n_field, ctx->arena); - if (!ok) _upb_DefBuilder_OomErr(ctx); + v->parent = e; // Must happen prior to _upb_DefBuilder_Add() + v->full_name = _upb_DefBuilder_MakeFullName(ctx, prefix, name); + v->number = UPB_DESC(EnumValueDescriptorProto_number)(val_proto); + _upb_DefBuilder_Add(ctx, v->full_name, + _upb_DefType_Pack(v, UPB_DEFTYPE_ENUMVAL)); - ok = upb_strtable_init(&m->jtof, n_field, ctx->arena); + bool ok = _upb_EnumDef_Insert(e, v, ctx->arena); if (!ok) _upb_DefBuilder_OomErr(ctx); +} - m->oneof_count = n_oneof; - m->oneofs = _upb_OneofDefs_New(ctx, n_oneof, oneofs, m->resolved_features, m); - - m->field_count = n_field; - m->fields = _upb_FieldDefs_New(ctx, n_field, fields, m->resolved_features, - m->full_name, m, &m->is_sorted); +static void _upb_EnumValueDef_CheckZeroValue(upb_DefBuilder* ctx, + const upb_EnumDef* e, + const upb_EnumValueDef* v, int n) { + if (upb_EnumDef_IsClosed(e) || n == 0 || v[0].number == 0) return; - // Message Sets may not contain fields. - if (UPB_UNLIKELY(UPB_DESC(MessageOptions_message_set_wire_format)(m->opts))) { - if (UPB_UNLIKELY(n_field > 0)) { - _upb_DefBuilder_Errf(ctx, "invalid message set (%s)", m->full_name); - } + // When the special UPB_TREAT_PROTO2_ENUMS_LIKE_PROTO3 is enabled, we have to + // exempt proto2 enums from this check, even when we are treating them as + // open. + if (UPB_TREAT_PROTO2_ENUMS_LIKE_PROTO3 && + upb_FileDef_Syntax(upb_EnumDef_File(e)) == kUpb_Syntax_Proto2) { + return; } - m->ext_range_count = n_ext_range; - m->ext_ranges = _upb_ExtensionRanges_New(ctx, n_ext_range, ext_ranges, - m->resolved_features, m); - - m->res_range_count = n_res_range; - m->res_ranges = - _upb_MessageReservedRanges_New(ctx, n_res_range, res_ranges, m); + _upb_DefBuilder_Errf(ctx, "for open enums, the first value must be zero (%s)", + upb_EnumDef_FullName(e)); +} - m->res_name_count = n_res_name; - m->res_names = _upb_ReservedNames_New(ctx, n_res_name, res_names); +// Allocate and initialize an array of |n| enum value defs owned by |e|. +upb_EnumValueDef* _upb_EnumValueDefs_New( + upb_DefBuilder* ctx, const char* prefix, int n, + const UPB_DESC(EnumValueDescriptorProto*) const* protos, + const UPB_DESC(FeatureSet*) parent_features, upb_EnumDef* e, + bool* is_sorted) { + _upb_DefType_CheckPadding(sizeof(upb_EnumValueDef)); - const size_t synthetic_count = _upb_OneofDefs_Finalize(ctx, m); - m->real_oneof_count = m->oneof_count - synthetic_count; + upb_EnumValueDef* v = + _upb_DefBuilder_Alloc(ctx, sizeof(upb_EnumValueDef) * n); - assign_msg_wellknowntype(m); - upb_inttable_compact(&m->itof, ctx->arena); + *is_sorted = true; + uint32_t previous = 0; + for (int i = 0; i < n; i++) { + create_enumvaldef(ctx, prefix, protos[i], parent_features, e, &v[i]); - const UPB_DESC(EnumDescriptorProto)* const* enums = - UPB_DESC(DescriptorProto_enum_type)(msg_proto, &n_enum); - m->nested_enum_count = n_enum; - m->nested_enums = - _upb_EnumDefs_New(ctx, n_enum, enums, m->resolved_features, m); + const uint32_t current = v[i].number; + if (previous > current) *is_sorted = false; + previous = current; + } - const UPB_DESC(FieldDescriptorProto)* const* exts = - UPB_DESC(DescriptorProto_extension)(msg_proto, &n_ext); - m->nested_ext_count = n_ext; - m->nested_exts = _upb_Extensions_New(ctx, n_ext, exts, m->resolved_features, - m->full_name, m); + _upb_EnumValueDef_CheckZeroValue(ctx, e, v, n); - const UPB_DESC(DescriptorProto)* const* msgs = - UPB_DESC(DescriptorProto_nested_type)(msg_proto, &n_msg); - m->nested_msg_count = n_msg; - m->nested_msgs = - _upb_MessageDefs_New(ctx, n_msg, msgs, m->resolved_features, m); + return v; } -// Allocate and initialize an array of |n| message defs. -upb_MessageDef* _upb_MessageDefs_New(upb_DefBuilder* ctx, int n, - const UPB_DESC(DescriptorProto*) - const* protos, - const UPB_DESC(FeatureSet*) - parent_features, - const upb_MessageDef* containing_type) { - _upb_DefType_CheckPadding(sizeof(upb_MessageDef)); - - const char* name = containing_type ? containing_type->full_name - : _upb_FileDef_RawPackage(ctx->file); - upb_MessageDef* m = _upb_DefBuilder_Alloc(ctx, sizeof(upb_MessageDef) * n); - for (int i = 0; i < n; i++) { - create_msgdef(ctx, name, protos[i], parent_features, containing_type, - &m[i]); - } - return m; -} +#include // Must be last. -struct upb_MessageReservedRange { +struct upb_ExtensionRange { + const UPB_DESC(ExtensionRangeOptions*) opts; + const UPB_DESC(FeatureSet*) resolved_features; int32_t start; int32_t end; }; -upb_MessageReservedRange* _upb_MessageReservedRange_At( - const upb_MessageReservedRange* r, int i) { - return (upb_MessageReservedRange*)&r[i]; +upb_ExtensionRange* _upb_ExtensionRange_At(const upb_ExtensionRange* r, int i) { + return (upb_ExtensionRange*)&r[i]; } -int32_t upb_MessageReservedRange_Start(const upb_MessageReservedRange* r) { - return r->start; +const UPB_DESC(ExtensionRangeOptions) * + upb_ExtensionRange_Options(const upb_ExtensionRange* r) { + return r->opts; } -int32_t upb_MessageReservedRange_End(const upb_MessageReservedRange* r) { - return r->end; + +bool upb_ExtensionRange_HasOptions(const upb_ExtensionRange* r) { + return r->opts != (void*)kUpbDefOptDefault; } -upb_MessageReservedRange* _upb_MessageReservedRanges_New( +int32_t upb_ExtensionRange_Start(const upb_ExtensionRange* r) { + return r->start; +} + +int32_t upb_ExtensionRange_End(const upb_ExtensionRange* r) { return r->end; } + +upb_ExtensionRange* _upb_ExtensionRanges_New( upb_DefBuilder* ctx, int n, - const UPB_DESC(DescriptorProto_ReservedRange) * const* protos, - const upb_MessageDef* m) { - upb_MessageReservedRange* r = - _upb_DefBuilder_Alloc(ctx, sizeof(upb_MessageReservedRange) * n); + const UPB_DESC(DescriptorProto_ExtensionRange*) const* protos, + const UPB_DESC(FeatureSet*) parent_features, const upb_MessageDef* m) { + upb_ExtensionRange* r = + _upb_DefBuilder_Alloc(ctx, sizeof(upb_ExtensionRange) * n); + + for (int i = 0; i < n; i++) { + UPB_DEF_SET_OPTIONS(r[i].opts, DescriptorProto_ExtensionRange, + ExtensionRangeOptions, protos[i]); + r[i].resolved_features = _upb_DefBuilder_ResolveFeatures( + ctx, parent_features, + UPB_DESC(ExtensionRangeOptions_features)(r[i].opts)); - for (int i = 0; i < n; i++) { const int32_t start = - UPB_DESC(DescriptorProto_ReservedRange_start)(protos[i]); - const int32_t end = UPB_DESC(DescriptorProto_ReservedRange_end)(protos[i]); - const int32_t max = kUpb_MaxFieldNumber + 1; + UPB_DESC(DescriptorProto_ExtensionRange_start)(protos[i]); + const int32_t end = UPB_DESC(DescriptorProto_ExtensionRange_end)(protos[i]); + const int32_t max = UPB_DESC(MessageOptions_message_set_wire_format)( + upb_MessageDef_Options(m)) + ? INT32_MAX + : kUpb_MaxFieldNumber + 1; // A full validation would also check that each range is disjoint, and that // none of the fields overlap with the extension ranges, but we are just // sanity checking here. if (start < 1 || end <= start || end > max) { _upb_DefBuilder_Errf(ctx, - "Reserved range (%d, %d) is invalid, message=%s\n", + "Extension range (%d, %d) is invalid, message=%s\n", (int)start, (int)end, upb_MessageDef_FullName(m)); } @@ -12071,3865 +12735,3201 @@ upb_MessageReservedRange* _upb_MessageReservedRanges_New( } +#include +#include +#include +#include +#include +#include + // Must be last. -struct upb_MethodDef { - const UPB_DESC(MethodOptions*) opts; +#define UPB_FIELD_TYPE_UNSPECIFIED 0 + +typedef struct { + size_t len; + char str[1]; // Null-terminated string data follows. +} str_t; + +struct upb_FieldDef { + const UPB_DESC(FieldOptions*) opts; const UPB_DESC(FeatureSet*) resolved_features; - upb_ServiceDef* service; + const upb_FileDef* file; + const upb_MessageDef* msgdef; const char* full_name; - const upb_MessageDef* input_type; - const upb_MessageDef* output_type; - int index; - bool client_streaming; - bool server_streaming; + const char* json_name; + union { + int64_t sint; + uint64_t uint; + double dbl; + float flt; + bool boolean; + str_t* str; + void* msg; // Always NULL. + } defaultval; + union { + const upb_OneofDef* oneof; + const upb_MessageDef* extension_scope; + } scope; + union { + const upb_MessageDef* msgdef; + const upb_EnumDef* enumdef; + const UPB_DESC(FieldDescriptorProto) * unresolved; + } sub; + uint32_t number_; + uint16_t index_; + uint16_t layout_index; // Index into msgdef->layout->fields or file->exts + bool has_default; + bool has_json_name; + bool has_presence; + bool is_extension; + bool is_proto3_optional; + upb_FieldType type_; + upb_Label label_; }; -upb_MethodDef* _upb_MethodDef_At(const upb_MethodDef* m, int i) { - return (upb_MethodDef*)&m[i]; +upb_FieldDef* _upb_FieldDef_At(const upb_FieldDef* f, int i) { + return (upb_FieldDef*)&f[i]; } -const upb_ServiceDef* upb_MethodDef_Service(const upb_MethodDef* m) { - return m->service; +const UPB_DESC(FieldOptions) * upb_FieldDef_Options(const upb_FieldDef* f) { + return f->opts; } -const UPB_DESC(MethodOptions) * upb_MethodDef_Options(const upb_MethodDef* m) { - return m->opts; +bool upb_FieldDef_HasOptions(const upb_FieldDef* f) { + return f->opts != (void*)kUpbDefOptDefault; } -bool upb_MethodDef_HasOptions(const upb_MethodDef* m) { - return m->opts != (void*)kUpbDefOptDefault; +const UPB_DESC(FeatureSet) * + upb_FieldDef_ResolvedFeatures(const upb_FieldDef* f) { + return f->resolved_features; } -const UPB_DESC(FeatureSet) * - upb_MethodDef_ResolvedFeatures(const upb_MethodDef* m) { - return m->resolved_features; +const char* upb_FieldDef_FullName(const upb_FieldDef* f) { + return f->full_name; } -const char* upb_MethodDef_FullName(const upb_MethodDef* m) { - return m->full_name; +upb_CType upb_FieldDef_CType(const upb_FieldDef* f) { + return upb_FieldType_CType(f->type_); } -const char* upb_MethodDef_Name(const upb_MethodDef* m) { - return _upb_DefBuilder_FullToShort(m->full_name); +upb_FieldType upb_FieldDef_Type(const upb_FieldDef* f) { + // TODO: remove once we can deprecate kUpb_FieldType_Group. + if (f->type_ == kUpb_FieldType_Message && + UPB_DESC(FeatureSet_message_encoding)(f->resolved_features) == + UPB_DESC(FeatureSet_DELIMITED)) { + return kUpb_FieldType_Group; + } + return f->type_; } -int upb_MethodDef_Index(const upb_MethodDef* m) { return m->index; } +uint32_t upb_FieldDef_Index(const upb_FieldDef* f) { return f->index_; } -const upb_MessageDef* upb_MethodDef_InputType(const upb_MethodDef* m) { - return m->input_type; +upb_Label upb_FieldDef_Label(const upb_FieldDef* f) { + // TODO: remove once we can deprecate kUpb_Label_Required. + if (UPB_DESC(FeatureSet_field_presence)(f->resolved_features) == + UPB_DESC(FeatureSet_LEGACY_REQUIRED)) { + return kUpb_Label_Required; + } + return f->label_; } -const upb_MessageDef* upb_MethodDef_OutputType(const upb_MethodDef* m) { - return m->output_type; +uint32_t upb_FieldDef_Number(const upb_FieldDef* f) { return f->number_; } + +bool upb_FieldDef_IsExtension(const upb_FieldDef* f) { return f->is_extension; } + +bool _upb_FieldDef_IsPackable(const upb_FieldDef* f) { + return upb_FieldDef_IsRepeated(f) && upb_FieldDef_IsPrimitive(f); } -bool upb_MethodDef_ClientStreaming(const upb_MethodDef* m) { - return m->client_streaming; +bool upb_FieldDef_IsPacked(const upb_FieldDef* f) { + return _upb_FieldDef_IsPackable(f) && + UPB_DESC(FeatureSet_repeated_field_encoding(f->resolved_features)) == + UPB_DESC(FeatureSet_PACKED); } -bool upb_MethodDef_ServerStreaming(const upb_MethodDef* m) { - return m->server_streaming; +const char* upb_FieldDef_Name(const upb_FieldDef* f) { + return _upb_DefBuilder_FullToShort(f->full_name); } -static void create_method(upb_DefBuilder* ctx, - const UPB_DESC(MethodDescriptorProto*) method_proto, - const UPB_DESC(FeatureSet*) parent_features, - upb_ServiceDef* s, upb_MethodDef* m) { - UPB_DEF_SET_OPTIONS(m->opts, MethodDescriptorProto, MethodOptions, - method_proto); - m->resolved_features = _upb_DefBuilder_ResolveFeatures( - ctx, parent_features, UPB_DESC(MethodOptions_features)(m->opts)); +const char* upb_FieldDef_JsonName(const upb_FieldDef* f) { + return f->json_name; +} + +bool upb_FieldDef_HasJsonName(const upb_FieldDef* f) { + return f->has_json_name; +} + +const upb_FileDef* upb_FieldDef_File(const upb_FieldDef* f) { return f->file; } + +const upb_MessageDef* upb_FieldDef_ContainingType(const upb_FieldDef* f) { + return f->msgdef; +} + +const upb_MessageDef* upb_FieldDef_ExtensionScope(const upb_FieldDef* f) { + return f->is_extension ? f->scope.extension_scope : NULL; +} + +const upb_OneofDef* upb_FieldDef_ContainingOneof(const upb_FieldDef* f) { + return f->is_extension ? NULL : f->scope.oneof; +} + +const upb_OneofDef* upb_FieldDef_RealContainingOneof(const upb_FieldDef* f) { + const upb_OneofDef* oneof = upb_FieldDef_ContainingOneof(f); + if (!oneof || upb_OneofDef_IsSynthetic(oneof)) return NULL; + return oneof; +} + +upb_MessageValue upb_FieldDef_Default(const upb_FieldDef* f) { + upb_MessageValue ret; + + if (upb_FieldDef_IsRepeated(f) || upb_FieldDef_IsSubMessage(f)) { + return (upb_MessageValue){.msg_val = NULL}; + } + + switch (upb_FieldDef_CType(f)) { + case kUpb_CType_Bool: + return (upb_MessageValue){.bool_val = f->defaultval.boolean}; + case kUpb_CType_Int64: + return (upb_MessageValue){.int64_val = f->defaultval.sint}; + case kUpb_CType_UInt64: + return (upb_MessageValue){.uint64_val = f->defaultval.uint}; + case kUpb_CType_Enum: + case kUpb_CType_Int32: + return (upb_MessageValue){.int32_val = (int32_t)f->defaultval.sint}; + case kUpb_CType_UInt32: + return (upb_MessageValue){.uint32_val = (uint32_t)f->defaultval.uint}; + case kUpb_CType_Float: + return (upb_MessageValue){.float_val = f->defaultval.flt}; + case kUpb_CType_Double: + return (upb_MessageValue){.double_val = f->defaultval.dbl}; + case kUpb_CType_String: + case kUpb_CType_Bytes: { + str_t* str = f->defaultval.str; + if (str) { + return (upb_MessageValue){ + .str_val = (upb_StringView){.data = str->str, .size = str->len}}; + } else { + return (upb_MessageValue){ + .str_val = (upb_StringView){.data = NULL, .size = 0}}; + } + } + default: + UPB_UNREACHABLE(); + } + + return ret; +} + +const upb_MessageDef* upb_FieldDef_MessageSubDef(const upb_FieldDef* f) { + return upb_FieldDef_CType(f) == kUpb_CType_Message ? f->sub.msgdef : NULL; +} + +const upb_EnumDef* upb_FieldDef_EnumSubDef(const upb_FieldDef* f) { + return upb_FieldDef_CType(f) == kUpb_CType_Enum ? f->sub.enumdef : NULL; +} + +const upb_MiniTableField* upb_FieldDef_MiniTable(const upb_FieldDef* f) { + if (upb_FieldDef_IsExtension(f)) { + const upb_FileDef* file = upb_FieldDef_File(f); + return (upb_MiniTableField*)_upb_FileDef_ExtensionMiniTable( + file, f->layout_index); + } else { + const upb_MiniTable* layout = upb_MessageDef_MiniTable(f->msgdef); + return &layout->UPB_PRIVATE(fields)[f->layout_index]; + } +} + +const upb_MiniTableExtension* _upb_FieldDef_ExtensionMiniTable( + const upb_FieldDef* f) { + UPB_ASSERT(upb_FieldDef_IsExtension(f)); + const upb_FileDef* file = upb_FieldDef_File(f); + return _upb_FileDef_ExtensionMiniTable(file, f->layout_index); +} + +bool _upb_FieldDef_IsClosedEnum(const upb_FieldDef* f) { + if (f->type_ != kUpb_FieldType_Enum) return false; + return upb_EnumDef_IsClosed(f->sub.enumdef); +} + +bool _upb_FieldDef_IsProto3Optional(const upb_FieldDef* f) { + return f->is_proto3_optional; +} + +int _upb_FieldDef_LayoutIndex(const upb_FieldDef* f) { return f->layout_index; } + +bool _upb_FieldDef_ValidateUtf8(const upb_FieldDef* f) { + if (upb_FieldDef_Type(f) != kUpb_FieldType_String) return false; + return UPB_DESC(FeatureSet_utf8_validation(f->resolved_features)) == + UPB_DESC(FeatureSet_VERIFY); +} + +uint64_t _upb_FieldDef_Modifiers(const upb_FieldDef* f) { + uint64_t out = upb_FieldDef_IsPacked(f) ? kUpb_FieldModifier_IsPacked : 0; - upb_StringView name = UPB_DESC(MethodDescriptorProto_name)(method_proto); + if (upb_FieldDef_IsRepeated(f)) { + out |= kUpb_FieldModifier_IsRepeated; + } else if (upb_FieldDef_IsRequired(f)) { + out |= kUpb_FieldModifier_IsRequired; + } else if (!upb_FieldDef_HasPresence(f)) { + out |= kUpb_FieldModifier_IsProto3Singular; + } - m->service = s; - m->full_name = - _upb_DefBuilder_MakeFullName(ctx, upb_ServiceDef_FullName(s), name); - m->client_streaming = - UPB_DESC(MethodDescriptorProto_client_streaming)(method_proto); - m->server_streaming = - UPB_DESC(MethodDescriptorProto_server_streaming)(method_proto); - m->input_type = _upb_DefBuilder_Resolve( - ctx, m->full_name, m->full_name, - UPB_DESC(MethodDescriptorProto_input_type)(method_proto), - UPB_DEFTYPE_MSG); - m->output_type = _upb_DefBuilder_Resolve( - ctx, m->full_name, m->full_name, - UPB_DESC(MethodDescriptorProto_output_type)(method_proto), - UPB_DEFTYPE_MSG); -} + if (_upb_FieldDef_IsClosedEnum(f)) { + out |= kUpb_FieldModifier_IsClosedEnum; + } -// Allocate and initialize an array of |n| method defs belonging to |s|. -upb_MethodDef* _upb_MethodDefs_New(upb_DefBuilder* ctx, int n, - const UPB_DESC(MethodDescriptorProto*) - const* protos, - const UPB_DESC(FeatureSet*) parent_features, - upb_ServiceDef* s) { - upb_MethodDef* m = _upb_DefBuilder_Alloc(ctx, sizeof(upb_MethodDef) * n); - for (int i = 0; i < n; i++) { - create_method(ctx, protos[i], parent_features, s, &m[i]); - m[i].index = i; + if (_upb_FieldDef_ValidateUtf8(f)) { + out |= kUpb_FieldModifier_ValidateUtf8; } - return m; + + return out; } +bool upb_FieldDef_HasDefault(const upb_FieldDef* f) { return f->has_default; } +bool upb_FieldDef_HasPresence(const upb_FieldDef* f) { return f->has_presence; } -#include -#include -#include +bool upb_FieldDef_HasSubDef(const upb_FieldDef* f) { + return upb_FieldDef_IsSubMessage(f) || + upb_FieldDef_CType(f) == kUpb_CType_Enum; +} +bool upb_FieldDef_IsMap(const upb_FieldDef* f) { + return upb_FieldDef_IsRepeated(f) && upb_FieldDef_IsSubMessage(f) && + upb_MessageDef_IsMapEntry(upb_FieldDef_MessageSubDef(f)); +} -// Must be last. +bool upb_FieldDef_IsOptional(const upb_FieldDef* f) { + return upb_FieldDef_Label(f) == kUpb_Label_Optional; +} -struct upb_OneofDef { - const UPB_DESC(OneofOptions*) opts; - const UPB_DESC(FeatureSet*) resolved_features; - const upb_MessageDef* parent; - const char* full_name; - int field_count; - bool synthetic; - const upb_FieldDef** fields; - upb_strtable ntof; // lookup a field by name - upb_inttable itof; // lookup a field by number (index) -}; +bool upb_FieldDef_IsPrimitive(const upb_FieldDef* f) { + return !upb_FieldDef_IsString(f) && !upb_FieldDef_IsSubMessage(f); +} -upb_OneofDef* _upb_OneofDef_At(const upb_OneofDef* o, int i) { - return (upb_OneofDef*)&o[i]; +bool upb_FieldDef_IsRepeated(const upb_FieldDef* f) { + return upb_FieldDef_Label(f) == kUpb_Label_Repeated; } -const UPB_DESC(OneofOptions) * upb_OneofDef_Options(const upb_OneofDef* o) { - return o->opts; +bool upb_FieldDef_IsRequired(const upb_FieldDef* f) { + return UPB_DESC(FeatureSet_field_presence)(f->resolved_features) == + UPB_DESC(FeatureSet_LEGACY_REQUIRED); } -bool upb_OneofDef_HasOptions(const upb_OneofDef* o) { - return o->opts != (void*)kUpbDefOptDefault; +bool upb_FieldDef_IsString(const upb_FieldDef* f) { + return upb_FieldDef_CType(f) == kUpb_CType_String || + upb_FieldDef_CType(f) == kUpb_CType_Bytes; } -const UPB_DESC(FeatureSet) * - upb_OneofDef_ResolvedFeatures(const upb_OneofDef* o) { - return o->resolved_features; +bool upb_FieldDef_IsSubMessage(const upb_FieldDef* f) { + return upb_FieldDef_CType(f) == kUpb_CType_Message; } -const char* upb_OneofDef_FullName(const upb_OneofDef* o) { - return o->full_name; +static bool between(int32_t x, int32_t low, int32_t high) { + return x >= low && x <= high; } -const char* upb_OneofDef_Name(const upb_OneofDef* o) { - return _upb_DefBuilder_FullToShort(o->full_name); +bool upb_FieldDef_checklabel(int32_t label) { return between(label, 1, 3); } +bool upb_FieldDef_checktype(int32_t type) { return between(type, 1, 11); } +bool upb_FieldDef_checkintfmt(int32_t fmt) { return between(fmt, 1, 3); } + +bool upb_FieldDef_checkdescriptortype(int32_t type) { + return between(type, 1, 18); } -const upb_MessageDef* upb_OneofDef_ContainingType(const upb_OneofDef* o) { - return o->parent; +static bool streql2(const char* a, size_t n, const char* b) { + return n == strlen(b) && memcmp(a, b, n) == 0; } -int upb_OneofDef_FieldCount(const upb_OneofDef* o) { return o->field_count; } +// Implement the transformation as described in the spec: +// 1. upper case all letters after an underscore. +// 2. remove all underscores. +static char* make_json_name(const char* name, size_t size, upb_Arena* a) { + char* out = upb_Arena_Malloc(a, size + 1); // +1 is to add a trailing '\0' + if (out == NULL) return NULL; -const upb_FieldDef* upb_OneofDef_Field(const upb_OneofDef* o, int i) { - UPB_ASSERT(i < o->field_count); - return o->fields[i]; + bool ucase_next = false; + char* des = out; + for (size_t i = 0; i < size; i++) { + if (name[i] == '_') { + ucase_next = true; + } else { + *des++ = ucase_next ? toupper(name[i]) : name[i]; + ucase_next = false; + } + } + *des++ = '\0'; + return out; } -int upb_OneofDef_numfields(const upb_OneofDef* o) { return o->field_count; } - -uint32_t upb_OneofDef_Index(const upb_OneofDef* o) { - // Compute index in our parent's array. - return o - upb_MessageDef_Oneof(o->parent, 0); +static str_t* newstr(upb_DefBuilder* ctx, const char* data, size_t len) { + str_t* ret = _upb_DefBuilder_Alloc(ctx, sizeof(*ret) + len); + if (!ret) _upb_DefBuilder_OomErr(ctx); + ret->len = len; + if (len) memcpy(ret->str, data, len); + ret->str[len] = '\0'; + return ret; } -bool upb_OneofDef_IsSynthetic(const upb_OneofDef* o) { return o->synthetic; } +static str_t* unescape(upb_DefBuilder* ctx, const upb_FieldDef* f, + const char* data, size_t len) { + // Size here is an upper bound; escape sequences could ultimately shrink it. + str_t* ret = _upb_DefBuilder_Alloc(ctx, sizeof(*ret) + len); + char* dst = &ret->str[0]; + const char* src = data; + const char* end = data + len; -const upb_FieldDef* upb_OneofDef_LookupNameWithSize(const upb_OneofDef* o, - const char* name, - size_t size) { - upb_value val; - return upb_strtable_lookup2(&o->ntof, name, size, &val) - ? upb_value_getptr(val) - : NULL; + while (src < end) { + if (*src == '\\') { + src++; + *dst++ = _upb_DefBuilder_ParseEscape(ctx, f, &src, end); + } else { + *dst++ = *src++; + } + } + + ret->len = dst - &ret->str[0]; + return ret; } -const upb_FieldDef* upb_OneofDef_LookupName(const upb_OneofDef* o, - const char* name) { - return upb_OneofDef_LookupNameWithSize(o, name, strlen(name)); -} +static void parse_default(upb_DefBuilder* ctx, const char* str, size_t len, + upb_FieldDef* f) { + char* end; + char nullz[64]; + errno = 0; + + switch (upb_FieldDef_CType(f)) { + case kUpb_CType_Int32: + case kUpb_CType_Int64: + case kUpb_CType_UInt32: + case kUpb_CType_UInt64: + case kUpb_CType_Double: + case kUpb_CType_Float: + // Standard C number parsing functions expect null-terminated strings. + if (len >= sizeof(nullz) - 1) { + _upb_DefBuilder_Errf(ctx, "Default too long: %.*s", (int)len, str); + } + memcpy(nullz, str, len); + nullz[len] = '\0'; + str = nullz; + break; + default: + break; + } + + switch (upb_FieldDef_CType(f)) { + case kUpb_CType_Int32: { + long val = strtol(str, &end, 0); + if (val > INT32_MAX || val < INT32_MIN || errno == ERANGE || *end) { + goto invalid; + } + f->defaultval.sint = val; + break; + } + case kUpb_CType_Enum: { + const upb_EnumDef* e = f->sub.enumdef; + const upb_EnumValueDef* ev = + upb_EnumDef_FindValueByNameWithSize(e, str, len); + if (!ev) { + goto invalid; + } + f->defaultval.sint = upb_EnumValueDef_Number(ev); + break; + } + case kUpb_CType_Int64: { + long long val = strtoll(str, &end, 0); + if (val > INT64_MAX || val < INT64_MIN || errno == ERANGE || *end) { + goto invalid; + } + f->defaultval.sint = val; + break; + } + case kUpb_CType_UInt32: { + unsigned long val = strtoul(str, &end, 0); + if (val > UINT32_MAX || errno == ERANGE || *end) { + goto invalid; + } + f->defaultval.uint = val; + break; + } + case kUpb_CType_UInt64: { + unsigned long long val = strtoull(str, &end, 0); + if (val > UINT64_MAX || errno == ERANGE || *end) { + goto invalid; + } + f->defaultval.uint = val; + break; + } + case kUpb_CType_Double: { + double val = strtod(str, &end); + if (errno == ERANGE || *end) { + goto invalid; + } + f->defaultval.dbl = val; + break; + } + case kUpb_CType_Float: { + float val = strtof(str, &end); + if (errno == ERANGE || *end) { + goto invalid; + } + f->defaultval.flt = val; + break; + } + case kUpb_CType_Bool: { + if (streql2(str, len, "false")) { + f->defaultval.boolean = false; + } else if (streql2(str, len, "true")) { + f->defaultval.boolean = true; + } else { + goto invalid; + } + break; + } + case kUpb_CType_String: + f->defaultval.str = newstr(ctx, str, len); + break; + case kUpb_CType_Bytes: + f->defaultval.str = unescape(ctx, f, str, len); + break; + case kUpb_CType_Message: + /* Should not have a default value. */ + _upb_DefBuilder_Errf(ctx, "Message should not have a default (%s)", + upb_FieldDef_FullName(f)); + } + + return; -const upb_FieldDef* upb_OneofDef_LookupNumber(const upb_OneofDef* o, - uint32_t num) { - upb_value val; - return upb_inttable_lookup(&o->itof, num, &val) ? upb_value_getptr(val) - : NULL; +invalid: + _upb_DefBuilder_Errf(ctx, "Invalid default '%.*s' for field %s of type %d", + (int)len, str, upb_FieldDef_FullName(f), + (int)upb_FieldDef_Type(f)); } -void _upb_OneofDef_Insert(upb_DefBuilder* ctx, upb_OneofDef* o, - const upb_FieldDef* f, const char* name, - size_t size) { - o->field_count++; - if (_upb_FieldDef_IsProto3Optional(f)) o->synthetic = true; - - const int number = upb_FieldDef_Number(f); - const upb_value v = upb_value_constptr(f); - - // TODO: This lookup is unfortunate because we also perform it when - // inserting into the message's table. Unfortunately that step occurs after - // this one and moving things around could be tricky so let's leave it for - // a future refactoring. - const bool number_exists = upb_inttable_lookup(&o->itof, number, NULL); - if (UPB_UNLIKELY(number_exists)) { - _upb_DefBuilder_Errf(ctx, "oneof fields have the same number (%d)", number); - } - - // TODO: More redundant work happening here. - const bool name_exists = upb_strtable_lookup2(&o->ntof, name, size, NULL); - if (UPB_UNLIKELY(name_exists)) { - _upb_DefBuilder_Errf(ctx, "oneof fields have the same name (%.*s)", - (int)size, name); - } - - const bool ok = upb_inttable_insert(&o->itof, number, v, ctx->arena) && - upb_strtable_insert(&o->ntof, name, size, v, ctx->arena); - if (UPB_UNLIKELY(!ok)) { - _upb_DefBuilder_OomErr(ctx); +static void set_default_default(upb_DefBuilder* ctx, upb_FieldDef* f) { + switch (upb_FieldDef_CType(f)) { + case kUpb_CType_Int32: + case kUpb_CType_Int64: + f->defaultval.sint = 0; + break; + case kUpb_CType_UInt64: + case kUpb_CType_UInt32: + f->defaultval.uint = 0; + break; + case kUpb_CType_Double: + case kUpb_CType_Float: + f->defaultval.dbl = 0; + break; + case kUpb_CType_String: + case kUpb_CType_Bytes: + f->defaultval.str = newstr(ctx, NULL, 0); + break; + case kUpb_CType_Bool: + f->defaultval.boolean = false; + break; + case kUpb_CType_Enum: { + const upb_EnumValueDef* v = upb_EnumDef_Value(f->sub.enumdef, 0); + f->defaultval.sint = upb_EnumValueDef_Number(v); + break; + } + case kUpb_CType_Message: + break; } } -// Returns the synthetic count. -size_t _upb_OneofDefs_Finalize(upb_DefBuilder* ctx, upb_MessageDef* m) { - int synthetic_count = 0; - - for (int i = 0; i < upb_MessageDef_OneofCount(m); i++) { - upb_OneofDef* o = (upb_OneofDef*)upb_MessageDef_Oneof(m, i); - - if (o->synthetic && o->field_count != 1) { - _upb_DefBuilder_Errf(ctx, - "Synthetic oneofs must have one field, not %d: %s", - o->field_count, upb_OneofDef_Name(o)); - } +static bool _upb_FieldDef_InferLegacyFeatures( + upb_DefBuilder* ctx, upb_FieldDef* f, + const UPB_DESC(FieldDescriptorProto*) proto, + const UPB_DESC(FieldOptions*) options, upb_Syntax syntax, + UPB_DESC(FeatureSet*) features) { + bool ret = false; - if (o->synthetic) { - synthetic_count++; - } else if (synthetic_count != 0) { - _upb_DefBuilder_Errf( - ctx, "Synthetic oneofs must be after all other oneofs: %s", - upb_OneofDef_Name(o)); + if (UPB_DESC(FieldDescriptorProto_label)(proto) == kUpb_Label_Required) { + if (syntax == kUpb_Syntax_Proto3) { + _upb_DefBuilder_Errf(ctx, "proto3 fields cannot be required (%s)", + f->full_name); } - - o->fields = - _upb_DefBuilder_Alloc(ctx, sizeof(upb_FieldDef*) * o->field_count); - o->field_count = 0; + int val = UPB_DESC(FeatureSet_LEGACY_REQUIRED); + UPB_DESC(FeatureSet_set_field_presence(features, val)); + ret = true; } - for (int i = 0; i < upb_MessageDef_FieldCount(m); i++) { - const upb_FieldDef* f = upb_MessageDef_Field(m, i); - upb_OneofDef* o = (upb_OneofDef*)upb_FieldDef_ContainingOneof(f); - if (o) { - o->fields[o->field_count++] = f; - } + if (UPB_DESC(FieldDescriptorProto_type)(proto) == kUpb_FieldType_Group) { + int val = UPB_DESC(FeatureSet_DELIMITED); + UPB_DESC(FeatureSet_set_message_encoding(features, val)); + ret = true; } - return synthetic_count; -} - -static void create_oneofdef(upb_DefBuilder* ctx, upb_MessageDef* m, - const UPB_DESC(OneofDescriptorProto*) oneof_proto, - const UPB_DESC(FeatureSet*) parent_features, - const upb_OneofDef* _o) { - upb_OneofDef* o = (upb_OneofDef*)_o; - - UPB_DEF_SET_OPTIONS(o->opts, OneofDescriptorProto, OneofOptions, oneof_proto); - o->resolved_features = _upb_DefBuilder_ResolveFeatures( - ctx, parent_features, UPB_DESC(OneofOptions_features)(o->opts)); - - upb_StringView name = UPB_DESC(OneofDescriptorProto_name)(oneof_proto); - - o->parent = m; - o->full_name = - _upb_DefBuilder_MakeFullName(ctx, upb_MessageDef_FullName(m), name); - o->field_count = 0; - o->synthetic = false; - - if (upb_MessageDef_FindByNameWithSize(m, name.data, name.size, NULL, NULL)) { - _upb_DefBuilder_Errf(ctx, "duplicate oneof name (%s)", o->full_name); + if (UPB_DESC(FieldOptions_has_packed)(options)) { + int val = UPB_DESC(FieldOptions_packed)(options) + ? UPB_DESC(FeatureSet_PACKED) + : UPB_DESC(FeatureSet_EXPANDED); + UPB_DESC(FeatureSet_set_repeated_field_encoding(features, val)); + ret = true; } - upb_value v = _upb_DefType_Pack(o, UPB_DEFTYPE_ONEOF); - bool ok = _upb_MessageDef_Insert(m, name.data, name.size, v, ctx->arena); - if (!ok) _upb_DefBuilder_OomErr(ctx); - - ok = upb_inttable_init(&o->itof, ctx->arena); - if (!ok) _upb_DefBuilder_OomErr(ctx); +// begin:google_only +// #ifndef UPB_BOOTSTRAP_STAGE0 +// if (syntax == kUpb_Syntax_Proto3 && +// UPB_DESC(FieldOptions_has_enforce_utf8)(options) && +// !UPB_DESC(FieldOptions_enforce_utf8)(options)) { +// int val = UPB_DESC(FeatureSet_UNVERIFIED); +// UPB_DESC(FeatureSet_set_utf8_validation(features, val)); +// ret = true; +// } +// #endif +// // clang-format off +// end:google_only + // clang-format on - ok = upb_strtable_init(&o->ntof, 4, ctx->arena); - if (!ok) _upb_DefBuilder_OomErr(ctx); + return ret; } -// Allocate and initialize an array of |n| oneof defs. -upb_OneofDef* _upb_OneofDefs_New(upb_DefBuilder* ctx, int n, - const UPB_DESC(OneofDescriptorProto*) - const* protos, +static void _upb_FieldDef_Create(upb_DefBuilder* ctx, const char* prefix, const UPB_DESC(FeatureSet*) parent_features, - upb_MessageDef* m) { - _upb_DefType_CheckPadding(sizeof(upb_OneofDef)); - - upb_OneofDef* o = _upb_DefBuilder_Alloc(ctx, sizeof(upb_OneofDef) * n); - for (int i = 0; i < n; i++) { - create_oneofdef(ctx, m, protos[i], parent_features, &o[i]); - } - return o; -} - - - -// Must be last. - -struct upb_ServiceDef { - const UPB_DESC(ServiceOptions*) opts; - const UPB_DESC(FeatureSet*) resolved_features; - const upb_FileDef* file; - const char* full_name; - upb_MethodDef* methods; - int method_count; - int index; -#if UINTPTR_MAX == 0xffffffff - uint32_t padding; // Increase size to a multiple of 8. -#endif -}; + const UPB_DESC(FieldDescriptorProto*) + field_proto, + upb_MessageDef* m, upb_FieldDef* f) { + // Must happen before _upb_DefBuilder_Add() + f->file = _upb_DefBuilder_File(ctx); -upb_ServiceDef* _upb_ServiceDef_At(const upb_ServiceDef* s, int index) { - return (upb_ServiceDef*)&s[index]; -} + const upb_StringView name = UPB_DESC(FieldDescriptorProto_name)(field_proto); + f->full_name = _upb_DefBuilder_MakeFullName(ctx, prefix, name); + f->label_ = (int)UPB_DESC(FieldDescriptorProto_label)(field_proto); + f->number_ = UPB_DESC(FieldDescriptorProto_number)(field_proto); + f->is_proto3_optional = + UPB_DESC(FieldDescriptorProto_proto3_optional)(field_proto); + f->msgdef = m; + f->scope.oneof = NULL; -const UPB_DESC(ServiceOptions) * - upb_ServiceDef_Options(const upb_ServiceDef* s) { - return s->opts; -} + UPB_DEF_SET_OPTIONS(f->opts, FieldDescriptorProto, FieldOptions, field_proto); -bool upb_ServiceDef_HasOptions(const upb_ServiceDef* s) { - return s->opts != (void*)kUpbDefOptDefault; -} + upb_Syntax syntax = upb_FileDef_Syntax(f->file); + const UPB_DESC(FeatureSet*) unresolved_features = + UPB_DESC(FieldOptions_features)(f->opts); + bool implicit = false; -const UPB_DESC(FeatureSet) * - upb_ServiceDef_ResolvedFeatures(const upb_ServiceDef* s) { - return s->resolved_features; -} + if (syntax != kUpb_Syntax_Editions) { + upb_Message_Clear(UPB_UPCAST(ctx->legacy_features), + UPB_DESC_MINITABLE(FeatureSet)); + if (_upb_FieldDef_InferLegacyFeatures(ctx, f, field_proto, f->opts, syntax, + ctx->legacy_features)) { + implicit = true; + unresolved_features = ctx->legacy_features; + } + } -const char* upb_ServiceDef_FullName(const upb_ServiceDef* s) { - return s->full_name; -} + if (UPB_DESC(FieldDescriptorProto_has_oneof_index)(field_proto)) { + int oneof_index = UPB_DESC(FieldDescriptorProto_oneof_index)(field_proto); -const char* upb_ServiceDef_Name(const upb_ServiceDef* s) { - return _upb_DefBuilder_FullToShort(s->full_name); -} + if (!m) { + _upb_DefBuilder_Errf(ctx, "oneof field (%s) has no containing msg", + f->full_name); + } -int upb_ServiceDef_Index(const upb_ServiceDef* s) { return s->index; } + if (oneof_index >= upb_MessageDef_OneofCount(m)) { + _upb_DefBuilder_Errf(ctx, "oneof_index out of range (%s)", f->full_name); + } -const upb_FileDef* upb_ServiceDef_File(const upb_ServiceDef* s) { - return s->file; -} + upb_OneofDef* oneof = (upb_OneofDef*)upb_MessageDef_Oneof(m, oneof_index); + f->scope.oneof = oneof; + parent_features = upb_OneofDef_ResolvedFeatures(oneof); -int upb_ServiceDef_MethodCount(const upb_ServiceDef* s) { - return s->method_count; -} + _upb_OneofDef_Insert(ctx, oneof, f, name.data, name.size); + } -const upb_MethodDef* upb_ServiceDef_Method(const upb_ServiceDef* s, int i) { - return (i < 0 || i >= s->method_count) ? NULL - : _upb_MethodDef_At(s->methods, i); -} + f->resolved_features = _upb_DefBuilder_DoResolveFeatures( + ctx, parent_features, unresolved_features, implicit); -const upb_MethodDef* upb_ServiceDef_FindMethodByName(const upb_ServiceDef* s, - const char* name) { - for (int i = 0; i < s->method_count; i++) { - const upb_MethodDef* m = _upb_MethodDef_At(s->methods, i); - if (strcmp(name, upb_MethodDef_Name(m)) == 0) { - return m; - } + if (!UPB_DESC(FieldDescriptorProto_has_name)(field_proto)) { + _upb_DefBuilder_Errf(ctx, "field has no name"); } - return NULL; -} -static void create_service(upb_DefBuilder* ctx, - const UPB_DESC(ServiceDescriptorProto*) svc_proto, - const UPB_DESC(FeatureSet*) parent_features, - upb_ServiceDef* s) { - UPB_DEF_SET_OPTIONS(s->opts, ServiceDescriptorProto, ServiceOptions, - svc_proto); - s->resolved_features = _upb_DefBuilder_ResolveFeatures( - ctx, parent_features, UPB_DESC(ServiceOptions_features)(s->opts)); + f->has_json_name = UPB_DESC(FieldDescriptorProto_has_json_name)(field_proto); + if (f->has_json_name) { + const upb_StringView sv = + UPB_DESC(FieldDescriptorProto_json_name)(field_proto); + f->json_name = upb_strdup2(sv.data, sv.size, ctx->arena); + } else { + f->json_name = make_json_name(name.data, name.size, ctx->arena); + } + if (!f->json_name) _upb_DefBuilder_OomErr(ctx); - // Must happen before _upb_DefBuilder_Add() - s->file = _upb_DefBuilder_File(ctx); + const bool has_type = UPB_DESC(FieldDescriptorProto_has_type)(field_proto); + const bool has_type_name = + UPB_DESC(FieldDescriptorProto_has_type_name)(field_proto); - upb_StringView name = UPB_DESC(ServiceDescriptorProto_name)(svc_proto); - const char* package = _upb_FileDef_RawPackage(s->file); - s->full_name = _upb_DefBuilder_MakeFullName(ctx, package, name); - _upb_DefBuilder_Add(ctx, s->full_name, - _upb_DefType_Pack(s, UPB_DEFTYPE_SERVICE)); + f->type_ = (int)UPB_DESC(FieldDescriptorProto_type)(field_proto); - size_t n; - const UPB_DESC(MethodDescriptorProto)* const* methods = - UPB_DESC(ServiceDescriptorProto_method)(svc_proto, &n); - s->method_count = n; - s->methods = _upb_MethodDefs_New(ctx, n, methods, s->resolved_features, s); -} + if (has_type) { + switch (f->type_) { + case kUpb_FieldType_Message: + case kUpb_FieldType_Group: + case kUpb_FieldType_Enum: + if (!has_type_name) { + _upb_DefBuilder_Errf(ctx, "field of type %d requires type name (%s)", + (int)f->type_, f->full_name); + } + break; + default: + if (has_type_name) { + _upb_DefBuilder_Errf( + ctx, "invalid type for field with type_name set (%s, %d)", + f->full_name, (int)f->type_); + } + } + } -upb_ServiceDef* _upb_ServiceDefs_New(upb_DefBuilder* ctx, int n, - const UPB_DESC(ServiceDescriptorProto*) - const* protos, - const UPB_DESC(FeatureSet*) - parent_features) { - _upb_DefType_CheckPadding(sizeof(upb_ServiceDef)); + if (!has_type && has_type_name) { + f->type_ = + UPB_FIELD_TYPE_UNSPECIFIED; // We'll assign this in resolve_subdef() + } else { + if (f->type_ < kUpb_FieldType_Double || f->type_ > kUpb_FieldType_SInt64) { + _upb_DefBuilder_Errf(ctx, "invalid type for field %s (%d)", f->full_name, + f->type_); + } + } - upb_ServiceDef* s = _upb_DefBuilder_Alloc(ctx, sizeof(upb_ServiceDef) * n); - for (int i = 0; i < n; i++) { - create_service(ctx, protos[i], parent_features, &s[i]); - s[i].index = i; + if (f->label_ < kUpb_Label_Optional || f->label_ > kUpb_Label_Repeated) { + _upb_DefBuilder_Errf(ctx, "invalid label for field %s (%d)", f->full_name, + f->label_); } - return s; -} + /* We can't resolve the subdef or (in the case of extensions) the containing + * message yet, because it may not have been defined yet. We stash a pointer + * to the field_proto until later when we can properly resolve it. */ + f->sub.unresolved = field_proto; -#include -#include -#include -#include -#include + if (UPB_DESC(FieldDescriptorProto_has_oneof_index)(field_proto)) { + if (upb_FieldDef_Label(f) != kUpb_Label_Optional) { + _upb_DefBuilder_Errf(ctx, "fields in oneof must have OPTIONAL label (%s)", + f->full_name); + } + } + f->has_presence = + (!upb_FieldDef_IsRepeated(f)) && + (f->type_ == kUpb_FieldType_Message || f->type_ == kUpb_FieldType_Group || + upb_FieldDef_ContainingOneof(f) || + UPB_DESC(FeatureSet_field_presence)(f->resolved_features) != + UPB_DESC(FeatureSet_IMPLICIT)); +} -// Must be last. +static void _upb_FieldDef_CreateExt(upb_DefBuilder* ctx, const char* prefix, + const UPB_DESC(FeatureSet*) parent_features, + const UPB_DESC(FieldDescriptorProto*) + field_proto, + upb_MessageDef* m, upb_FieldDef* f) { + f->is_extension = true; + _upb_FieldDef_Create(ctx, prefix, parent_features, field_proto, m, f); -// A few fake field types for our tables. -enum { - kUpb_FakeFieldType_FieldNotFound = 0, - kUpb_FakeFieldType_MessageSetItem = 19, -}; + if (UPB_DESC(FieldDescriptorProto_has_oneof_index)(field_proto)) { + _upb_DefBuilder_Errf(ctx, "oneof_index provided for extension field (%s)", + f->full_name); + } -// DecodeOp: an action to be performed for a wire-type/field-type combination. -enum { - // Special ops: we don't write data to regular fields for these. - kUpb_DecodeOp_UnknownField = -1, - kUpb_DecodeOp_MessageSetItem = -2, + f->scope.extension_scope = m; + _upb_DefBuilder_Add(ctx, f->full_name, _upb_DefType_Pack(f, UPB_DEFTYPE_EXT)); + f->layout_index = ctx->ext_count++; - // Scalar-only ops. - kUpb_DecodeOp_Scalar1Byte = 0, - kUpb_DecodeOp_Scalar4Byte = 2, - kUpb_DecodeOp_Scalar8Byte = 3, - kUpb_DecodeOp_Enum = 1, + if (ctx->layout) { + UPB_ASSERT(upb_MiniTableExtension_Number( + _upb_FieldDef_ExtensionMiniTable(f)) == f->number_); + } +} - // Scalar/repeated ops. - kUpb_DecodeOp_String = 4, - kUpb_DecodeOp_Bytes = 5, - kUpb_DecodeOp_SubMessage = 6, +static void _upb_FieldDef_CreateNotExt(upb_DefBuilder* ctx, const char* prefix, + const UPB_DESC(FeatureSet*) + parent_features, + const UPB_DESC(FieldDescriptorProto*) + field_proto, + upb_MessageDef* m, upb_FieldDef* f) { + f->is_extension = false; + _upb_FieldDef_Create(ctx, prefix, parent_features, field_proto, m, f); - // Repeated-only ops (also see macros below). - kUpb_DecodeOp_PackedEnum = 13, -}; + if (!UPB_DESC(FieldDescriptorProto_has_oneof_index)(field_proto)) { + if (f->is_proto3_optional) { + _upb_DefBuilder_Errf( + ctx, + "non-extension field (%s) with proto3_optional was not in a oneof", + f->full_name); + } + } -// For packed fields it is helpful to be able to recover the lg2 of the data -// size from the op. -#define OP_FIXPCK_LG2(n) (n + 5) /* n in [2, 3] => op in [7, 8] */ -#define OP_VARPCK_LG2(n) (n + 9) /* n in [0, 2, 3] => op in [9, 11, 12] */ + _upb_MessageDef_InsertField(ctx, m, f); +} -typedef union { - bool bool_val; - uint32_t uint32_val; - uint64_t uint64_val; - uint32_t size; -} wireval; +upb_FieldDef* _upb_Extensions_New(upb_DefBuilder* ctx, int n, + const UPB_DESC(FieldDescriptorProto*) + const* protos, + const UPB_DESC(FeatureSet*) parent_features, + const char* prefix, upb_MessageDef* m) { + _upb_DefType_CheckPadding(sizeof(upb_FieldDef)); + upb_FieldDef* defs = + (upb_FieldDef*)_upb_DefBuilder_Alloc(ctx, sizeof(upb_FieldDef) * n); -// Ideally these two functions should take the owning MiniTable pointer as a -// first argument, then we could just put them in mini_table/message.h as nice -// clean getters. But we don't have that so instead we gotta write these -// Frankenfunctions that take an array of subtables. -// TODO: Move these to mini_table/ anyway since there are other places -// that could use them. + for (int i = 0; i < n; i++) { + upb_FieldDef* f = &defs[i]; -// Returns the MiniTable corresponding to a given MiniTableField -// from an array of MiniTableSubs. -static const upb_MiniTable* _upb_MiniTableSubs_MessageByField( - const upb_MiniTableSub* subs, const upb_MiniTableField* field) { - return upb_MiniTableSub_Message(subs[field->UPB_PRIVATE(submsg_index)]); -} + _upb_FieldDef_CreateExt(ctx, prefix, parent_features, protos[i], m, f); + f->index_ = i; + } -// Returns the MiniTableEnum corresponding to a given MiniTableField -// from an array of MiniTableSub. -static const upb_MiniTableEnum* _upb_MiniTableSubs_EnumByField( - const upb_MiniTableSub* subs, const upb_MiniTableField* field) { - return upb_MiniTableSub_Enum(subs[field->UPB_PRIVATE(submsg_index)]); + return defs; } -static const char* _upb_Decoder_DecodeMessage(upb_Decoder* d, const char* ptr, - upb_Message* msg, - const upb_MiniTable* layout); +upb_FieldDef* _upb_FieldDefs_New(upb_DefBuilder* ctx, int n, + const UPB_DESC(FieldDescriptorProto*) + const* protos, + const UPB_DESC(FeatureSet*) parent_features, + const char* prefix, upb_MessageDef* m, + bool* is_sorted) { + _upb_DefType_CheckPadding(sizeof(upb_FieldDef)); + upb_FieldDef* defs = + (upb_FieldDef*)_upb_DefBuilder_Alloc(ctx, sizeof(upb_FieldDef) * n); + + uint32_t previous = 0; + for (int i = 0; i < n; i++) { + upb_FieldDef* f = &defs[i]; + + _upb_FieldDef_CreateNotExt(ctx, prefix, parent_features, protos[i], m, f); + f->index_ = i; + if (!ctx->layout) { + // Speculate that the def fields are sorted. We will always sort the + // MiniTable fields, so if defs are sorted then indices will match. + // + // If this is incorrect, we will overwrite later. + f->layout_index = i; + } -UPB_NORETURN static void* _upb_Decoder_ErrorJmp(upb_Decoder* d, - upb_DecodeStatus status) { - UPB_ASSERT(status != kUpb_DecodeStatus_Ok); - d->status = status; - UPB_LONGJMP(d->err, 1); -} + const uint32_t current = f->number_; + if (previous > current) *is_sorted = false; + previous = current; + } -const char* _upb_FastDecoder_ErrorJmp(upb_Decoder* d, int status) { - UPB_ASSERT(status != kUpb_DecodeStatus_Ok); - d->status = status; - UPB_LONGJMP(d->err, 1); - return NULL; + return defs; } -static void _upb_Decoder_VerifyUtf8(upb_Decoder* d, const char* buf, int len) { - if (!_upb_Decoder_VerifyUtf8Inline(buf, len)) { - _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_BadUtf8); +static void resolve_subdef(upb_DefBuilder* ctx, const char* prefix, + upb_FieldDef* f) { + const UPB_DESC(FieldDescriptorProto)* field_proto = f->sub.unresolved; + upb_StringView name = UPB_DESC(FieldDescriptorProto_type_name)(field_proto); + bool has_name = UPB_DESC(FieldDescriptorProto_has_type_name)(field_proto); + switch ((int)f->type_) { + case UPB_FIELD_TYPE_UNSPECIFIED: { + // Type was not specified and must be inferred. + UPB_ASSERT(has_name); + upb_deftype_t type; + const void* def = + _upb_DefBuilder_ResolveAny(ctx, f->full_name, prefix, name, &type); + switch (type) { + case UPB_DEFTYPE_ENUM: + f->sub.enumdef = def; + f->type_ = kUpb_FieldType_Enum; + break; + case UPB_DEFTYPE_MSG: + f->sub.msgdef = def; + f->type_ = kUpb_FieldType_Message; // It appears there is no way of + // this being a group. + f->has_presence = !upb_FieldDef_IsRepeated(f); + break; + default: + _upb_DefBuilder_Errf(ctx, "Couldn't resolve type name for field %s", + f->full_name); + } + break; + } + case kUpb_FieldType_Message: + case kUpb_FieldType_Group: + UPB_ASSERT(has_name); + f->sub.msgdef = _upb_DefBuilder_Resolve(ctx, f->full_name, prefix, name, + UPB_DEFTYPE_MSG); + break; + case kUpb_FieldType_Enum: + UPB_ASSERT(has_name); + f->sub.enumdef = _upb_DefBuilder_Resolve(ctx, f->full_name, prefix, name, + UPB_DEFTYPE_ENUM); + break; + default: + // No resolution necessary. + break; } } -static bool _upb_Decoder_Reserve(upb_Decoder* d, upb_Array* arr, size_t elem) { - bool need_realloc = - arr->UPB_PRIVATE(capacity) - arr->UPB_PRIVATE(size) < elem; - if (need_realloc && !UPB_PRIVATE(_upb_Array_Realloc)( - arr, arr->UPB_PRIVATE(size) + elem, &d->arena)) { - _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_OutOfMemory); - } - return need_realloc; +static int _upb_FieldDef_Compare(const void* p1, const void* p2) { + const uint32_t v1 = (*(upb_FieldDef**)p1)->number_; + const uint32_t v2 = (*(upb_FieldDef**)p2)->number_; + return (v1 < v2) ? -1 : (v1 > v2); } -typedef struct { - const char* ptr; - uint64_t val; -} _upb_DecodeLongVarintReturn; +// _upb_FieldDefs_Sorted() is mostly a pure function of its inputs, but has one +// critical side effect that we depend on: it sets layout_index appropriately +// for non-sorted lists of fields. +const upb_FieldDef** _upb_FieldDefs_Sorted(const upb_FieldDef* f, int n, + upb_Arena* a) { + // TODO: Replace this arena alloc with a persistent scratch buffer. + upb_FieldDef** out = (upb_FieldDef**)upb_Arena_Malloc(a, n * sizeof(void*)); + if (!out) return NULL; -UPB_NOINLINE -static _upb_DecodeLongVarintReturn _upb_Decoder_DecodeLongVarint( - const char* ptr, uint64_t val) { - _upb_DecodeLongVarintReturn ret = {NULL, 0}; - uint64_t byte; - int i; - for (i = 1; i < 10; i++) { - byte = (uint8_t)ptr[i]; - val += (byte - 1) << (i * 7); - if (!(byte & 0x80)) { - ret.ptr = ptr + i + 1; - ret.val = val; - return ret; - } + for (int i = 0; i < n; i++) { + out[i] = (upb_FieldDef*)&f[i]; } - return ret; -} + qsort(out, n, sizeof(void*), _upb_FieldDef_Compare); -UPB_FORCEINLINE -static const char* _upb_Decoder_DecodeVarint(upb_Decoder* d, const char* ptr, - uint64_t* val) { - uint64_t byte = (uint8_t)*ptr; - if (UPB_LIKELY((byte & 0x80) == 0)) { - *val = byte; - return ptr + 1; - } else { - _upb_DecodeLongVarintReturn res = _upb_Decoder_DecodeLongVarint(ptr, byte); - if (!res.ptr) _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_Malformed); - *val = res.val; - return res.ptr; + for (int i = 0; i < n; i++) { + out[i]->layout_index = i; } + return (const upb_FieldDef**)out; } -UPB_FORCEINLINE -static const char* _upb_Decoder_DecodeTag(upb_Decoder* d, const char* ptr, - uint32_t* val) { - uint64_t byte = (uint8_t)*ptr; - if (UPB_LIKELY((byte & 0x80) == 0)) { - *val = byte; - return ptr + 1; - } else { - const char* start = ptr; - _upb_DecodeLongVarintReturn res = _upb_Decoder_DecodeLongVarint(ptr, byte); - if (!res.ptr || res.ptr - start > 5 || res.val > UINT32_MAX) { - _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_Malformed); - } - *val = res.val; - return res.ptr; - } -} +bool upb_FieldDef_MiniDescriptorEncode(const upb_FieldDef* f, upb_Arena* a, + upb_StringView* out) { + UPB_ASSERT(f->is_extension); -UPB_FORCEINLINE -static const char* upb_Decoder_DecodeSize(upb_Decoder* d, const char* ptr, - uint32_t* size) { - uint64_t size64; - ptr = _upb_Decoder_DecodeVarint(d, ptr, &size64); - if (size64 >= INT32_MAX || - !upb_EpsCopyInputStream_CheckSize(&d->input, ptr, (int)size64)) { - _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_Malformed); - } - *size = size64; - return ptr; + upb_DescState s; + _upb_DescState_Init(&s); + + const int number = upb_FieldDef_Number(f); + const uint64_t modifiers = _upb_FieldDef_Modifiers(f); + + if (!_upb_DescState_Grow(&s, a)) return false; + s.ptr = upb_MtDataEncoder_EncodeExtension(&s.e, s.ptr, f->type_, number, + modifiers); + *s.ptr = '\0'; + + out->data = s.buf; + out->size = s.ptr - s.buf; + return true; } -static void _upb_Decoder_MungeInt32(wireval* val) { - if (!UPB_PRIVATE(_upb_IsLittleEndian)()) { - /* The next stage will memcpy(dst, &val, 4) */ - val->uint32_val = val->uint64_val; +static void resolve_extension(upb_DefBuilder* ctx, const char* prefix, + upb_FieldDef* f, + const UPB_DESC(FieldDescriptorProto) * + field_proto) { + if (!UPB_DESC(FieldDescriptorProto_has_extendee)(field_proto)) { + _upb_DefBuilder_Errf(ctx, "extension for field '%s' had no extendee", + f->full_name); } -} -static void _upb_Decoder_Munge(int type, wireval* val) { - switch (type) { - case kUpb_FieldType_Bool: - val->bool_val = val->uint64_val != 0; - break; - case kUpb_FieldType_SInt32: { - uint32_t n = val->uint64_val; - val->uint32_val = (n >> 1) ^ -(int32_t)(n & 1); - break; - } - case kUpb_FieldType_SInt64: { - uint64_t n = val->uint64_val; - val->uint64_val = (n >> 1) ^ -(int64_t)(n & 1); - break; - } - case kUpb_FieldType_Int32: - case kUpb_FieldType_UInt32: - case kUpb_FieldType_Enum: - _upb_Decoder_MungeInt32(val); - break; + upb_StringView name = UPB_DESC(FieldDescriptorProto_extendee)(field_proto); + const upb_MessageDef* m = + _upb_DefBuilder_Resolve(ctx, f->full_name, prefix, name, UPB_DEFTYPE_MSG); + f->msgdef = m; + + if (!_upb_MessageDef_IsValidExtensionNumber(m, f->number_)) { + _upb_DefBuilder_Errf( + ctx, + "field number %u in extension %s has no extension range in message %s", + (unsigned)f->number_, f->full_name, upb_MessageDef_FullName(m)); } } -static upb_Message* _upb_Decoder_NewSubMessage(upb_Decoder* d, - const upb_MiniTableSub* subs, - const upb_MiniTableField* field, - upb_TaggedMessagePtr* target) { - const upb_MiniTable* subl = _upb_MiniTableSubs_MessageByField(subs, field); - UPB_ASSERT(subl); - upb_Message* msg = _upb_Message_New(subl, &d->arena); - if (!msg) _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_OutOfMemory); +void _upb_FieldDef_BuildMiniTableExtension(upb_DefBuilder* ctx, + const upb_FieldDef* f) { + const upb_MiniTableExtension* ext = _upb_FieldDef_ExtensionMiniTable(f); - // Extensions should not be unlinked. A message extension should not be - // registered until its sub-message type is available to be linked. - bool is_empty = UPB_PRIVATE(_upb_MiniTable_IsEmpty)(subl); - bool is_extension = field->UPB_PRIVATE(mode) & kUpb_LabelFlags_IsExtension; - UPB_ASSERT(!(is_empty && is_extension)); + if (ctx->layout) { + UPB_ASSERT(upb_FieldDef_Number(f) == upb_MiniTableExtension_Number(ext)); + } else { + upb_StringView desc; + if (!upb_FieldDef_MiniDescriptorEncode(f, ctx->tmp_arena, &desc)) { + _upb_DefBuilder_OomErr(ctx); + } - if (is_empty && !(d->options & kUpb_DecodeOption_ExperimentalAllowUnlinked)) { - _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_UnlinkedSubMessage); + upb_MiniTableExtension* mut_ext = (upb_MiniTableExtension*)ext; + upb_MiniTableSub sub = {NULL}; + if (upb_FieldDef_IsSubMessage(f)) { + const upb_MiniTable* submsg = upb_MessageDef_MiniTable(f->sub.msgdef); + sub = upb_MiniTableSub_FromMessage(submsg); + } else if (_upb_FieldDef_IsClosedEnum(f)) { + const upb_MiniTableEnum* subenum = _upb_EnumDef_MiniTable(f->sub.enumdef); + sub = upb_MiniTableSub_FromEnum(subenum); + } + bool ok2 = upb_MiniTableExtension_Init(desc.data, desc.size, mut_ext, + upb_MessageDef_MiniTable(f->msgdef), + sub, ctx->status); + if (!ok2) _upb_DefBuilder_Errf(ctx, "Could not build extension mini table"); } - upb_TaggedMessagePtr tagged = - UPB_PRIVATE(_upb_TaggedMessagePtr_Pack)(msg, is_empty); - memcpy(target, &tagged, sizeof(tagged)); - return msg; + bool ok = _upb_DefPool_InsertExt(ctx->symtab, ext, f); + if (!ok) _upb_DefBuilder_OomErr(ctx); } -static upb_Message* _upb_Decoder_ReuseSubMessage( - upb_Decoder* d, const upb_MiniTableSub* subs, - const upb_MiniTableField* field, upb_TaggedMessagePtr* target) { - upb_TaggedMessagePtr tagged = *target; - const upb_MiniTable* subl = _upb_MiniTableSubs_MessageByField(subs, field); - UPB_ASSERT(subl); - if (!upb_TaggedMessagePtr_IsEmpty(tagged) || - UPB_PRIVATE(_upb_MiniTable_IsEmpty)(subl)) { - return UPB_PRIVATE(_upb_TaggedMessagePtr_GetMessage)(tagged); - } +static void resolve_default(upb_DefBuilder* ctx, upb_FieldDef* f, + const UPB_DESC(FieldDescriptorProto) * + field_proto) { + // Have to delay resolving of the default value until now because of the enum + // case, since enum defaults are specified with a label. + if (UPB_DESC(FieldDescriptorProto_has_default_value)(field_proto)) { + upb_StringView defaultval = + UPB_DESC(FieldDescriptorProto_default_value)(field_proto); - // We found an empty message from a previous parse that was performed before - // this field was linked. But it is linked now, so we want to allocate a new - // message of the correct type and promote data into it before continuing. - upb_Message* existing = - UPB_PRIVATE(_upb_TaggedMessagePtr_GetEmptyMessage)(tagged); - upb_Message* promoted = _upb_Decoder_NewSubMessage(d, subs, field, target); - size_t size; - const char* unknown = upb_Message_GetUnknown(existing, &size); - upb_DecodeStatus status = upb_Decode(unknown, size, promoted, subl, d->extreg, - d->options, &d->arena); - if (status != kUpb_DecodeStatus_Ok) _upb_Decoder_ErrorJmp(d, status); - return promoted; -} + if (upb_FileDef_Syntax(f->file) == kUpb_Syntax_Proto3) { + _upb_DefBuilder_Errf(ctx, + "proto3 fields cannot have explicit defaults (%s)", + f->full_name); + } -static const char* _upb_Decoder_ReadString(upb_Decoder* d, const char* ptr, - int size, upb_StringView* str) { - const char* str_ptr = ptr; - ptr = upb_EpsCopyInputStream_ReadString(&d->input, &str_ptr, size, &d->arena); - if (!ptr) _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_OutOfMemory); - str->data = str_ptr; - str->size = size; - return ptr; -} + if (upb_FieldDef_IsSubMessage(f)) { + _upb_DefBuilder_Errf(ctx, + "message fields cannot have explicit defaults (%s)", + f->full_name); + } -UPB_FORCEINLINE -static const char* _upb_Decoder_RecurseSubMessage(upb_Decoder* d, - const char* ptr, - upb_Message* submsg, - const upb_MiniTable* subl, - uint32_t expected_end_group) { - if (--d->depth < 0) { - _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_MaxDepthExceeded); - } - ptr = _upb_Decoder_DecodeMessage(d, ptr, submsg, subl); - d->depth++; - if (d->end_group != expected_end_group) { - _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_Malformed); + parse_default(ctx, defaultval.data, defaultval.size, f); + f->has_default = true; + } else { + set_default_default(ctx, f); + f->has_default = false; } - return ptr; } -UPB_FORCEINLINE -static const char* _upb_Decoder_DecodeSubMessage( - upb_Decoder* d, const char* ptr, upb_Message* submsg, - const upb_MiniTableSub* subs, const upb_MiniTableField* field, int size) { - int saved_delta = upb_EpsCopyInputStream_PushLimit(&d->input, ptr, size); - const upb_MiniTable* subl = _upb_MiniTableSubs_MessageByField(subs, field); - UPB_ASSERT(subl); - ptr = _upb_Decoder_RecurseSubMessage(d, ptr, submsg, subl, DECODE_NOGROUP); - upb_EpsCopyInputStream_PopLimit(&d->input, ptr, saved_delta); - return ptr; -} +void _upb_FieldDef_Resolve(upb_DefBuilder* ctx, const char* prefix, + upb_FieldDef* f) { + // We have to stash this away since resolve_subdef() may overwrite it. + const UPB_DESC(FieldDescriptorProto)* field_proto = f->sub.unresolved; -UPB_FORCEINLINE -static const char* _upb_Decoder_DecodeGroup(upb_Decoder* d, const char* ptr, - upb_Message* submsg, - const upb_MiniTable* subl, - uint32_t number) { - if (_upb_Decoder_IsDone(d, &ptr)) { - _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_Malformed); + resolve_subdef(ctx, prefix, f); + resolve_default(ctx, f, field_proto); + + if (f->is_extension) { + resolve_extension(ctx, prefix, f, field_proto); } - ptr = _upb_Decoder_RecurseSubMessage(d, ptr, submsg, subl, number); - d->end_group = DECODE_NOGROUP; - return ptr; } -UPB_FORCEINLINE -static const char* _upb_Decoder_DecodeUnknownGroup(upb_Decoder* d, - const char* ptr, - uint32_t number) { - return _upb_Decoder_DecodeGroup(d, ptr, NULL, NULL, number); -} -UPB_FORCEINLINE -static const char* _upb_Decoder_DecodeKnownGroup( - upb_Decoder* d, const char* ptr, upb_Message* submsg, - const upb_MiniTableSub* subs, const upb_MiniTableField* field) { - const upb_MiniTable* subl = _upb_MiniTableSubs_MessageByField(subs, field); - UPB_ASSERT(subl); - return _upb_Decoder_DecodeGroup(d, ptr, submsg, subl, - field->UPB_PRIVATE(number)); -} +#include +#include +#include -static char* upb_Decoder_EncodeVarint32(uint32_t val, char* ptr) { - do { - uint8_t byte = val & 0x7fU; - val >>= 7; - if (val) byte |= 0x80U; - *(ptr++) = byte; - } while (val); - return ptr; -} -static void _upb_Decoder_AddUnknownVarints(upb_Decoder* d, upb_Message* msg, - uint32_t val1, uint32_t val2) { - char buf[20]; - char* end = buf; - end = upb_Decoder_EncodeVarint32(val1, end); - end = upb_Decoder_EncodeVarint32(val2, end); +// Must be last. - if (!UPB_PRIVATE(_upb_Message_AddUnknown)(msg, buf, end - buf, &d->arena)) { - _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_OutOfMemory); +struct upb_FileDef { + const UPB_DESC(FileOptions*) opts; + const UPB_DESC(FeatureSet*) resolved_features; + const char* name; + const char* package; + UPB_DESC(Edition) edition; + + const upb_FileDef** deps; + const int32_t* public_deps; + const int32_t* weak_deps; + const upb_MessageDef* top_lvl_msgs; + const upb_EnumDef* top_lvl_enums; + const upb_FieldDef* top_lvl_exts; + const upb_ServiceDef* services; + const upb_MiniTableExtension** ext_layouts; + const upb_DefPool* symtab; + + int dep_count; + int public_dep_count; + int weak_dep_count; + int top_lvl_msg_count; + int top_lvl_enum_count; + int top_lvl_ext_count; + int service_count; + int ext_count; // All exts in the file. + upb_Syntax syntax; +}; + +UPB_API const char* upb_FileDef_EditionName(int edition) { + // TODO Synchronize this with descriptor.proto better. + switch (edition) { + case UPB_DESC(EDITION_PROTO2): + return "PROTO2"; + case UPB_DESC(EDITION_PROTO3): + return "PROTO3"; + case UPB_DESC(EDITION_2023): + return "2023"; + default: + return "UNKNOWN"; } } -UPB_FORCEINLINE -static bool _upb_Decoder_CheckEnum(upb_Decoder* d, const char* ptr, - upb_Message* msg, const upb_MiniTableEnum* e, - const upb_MiniTableField* field, - wireval* val) { - const uint32_t v = val->uint32_val; - - if (UPB_LIKELY(upb_MiniTableEnum_CheckValue(e, v))) return true; +const UPB_DESC(FileOptions) * upb_FileDef_Options(const upb_FileDef* f) { + return f->opts; +} - // Unrecognized enum goes into unknown fields. - // For packed fields the tag could be arbitrarily far in the past, - // so we just re-encode the tag and value here. - const uint32_t tag = - ((uint32_t)field->UPB_PRIVATE(number) << 3) | kUpb_WireType_Varint; - upb_Message* unknown_msg = - field->UPB_PRIVATE(mode) & kUpb_LabelFlags_IsExtension ? d->unknown_msg - : msg; - _upb_Decoder_AddUnknownVarints(d, unknown_msg, tag, v); - return false; +const UPB_DESC(FeatureSet) * + upb_FileDef_ResolvedFeatures(const upb_FileDef* f) { + return f->resolved_features; } -UPB_NOINLINE -static const char* _upb_Decoder_DecodeEnumArray(upb_Decoder* d, const char* ptr, - upb_Message* msg, - upb_Array* arr, - const upb_MiniTableSub* subs, - const upb_MiniTableField* field, - wireval* val) { - const upb_MiniTableEnum* e = _upb_MiniTableSubs_EnumByField(subs, field); - if (!_upb_Decoder_CheckEnum(d, ptr, msg, e, field, val)) return ptr; - void* mem = UPB_PTR_AT(_upb_array_ptr(arr), arr->UPB_PRIVATE(size) * 4, void); - arr->UPB_PRIVATE(size)++; - memcpy(mem, val, 4); - return ptr; +bool upb_FileDef_HasOptions(const upb_FileDef* f) { + return f->opts != (void*)kUpbDefOptDefault; } -UPB_FORCEINLINE -static const char* _upb_Decoder_DecodeFixedPacked( - upb_Decoder* d, const char* ptr, upb_Array* arr, wireval* val, - const upb_MiniTableField* field, int lg2) { - int mask = (1 << lg2) - 1; - size_t count = val->size >> lg2; - if ((val->size & mask) != 0) { - // Length isn't a round multiple of elem size. - _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_Malformed); - } - _upb_Decoder_Reserve(d, arr, count); - void* mem = - UPB_PTR_AT(_upb_array_ptr(arr), arr->UPB_PRIVATE(size) << lg2, void); - arr->UPB_PRIVATE(size) += count; - // Note: if/when the decoder supports multi-buffer input, we will need to - // handle buffer seams here. - if (UPB_PRIVATE(_upb_IsLittleEndian)()) { - ptr = upb_EpsCopyInputStream_Copy(&d->input, ptr, mem, val->size); - } else { - int delta = upb_EpsCopyInputStream_PushLimit(&d->input, ptr, val->size); - char* dst = mem; - while (!_upb_Decoder_IsDone(d, &ptr)) { - if (lg2 == 2) { - ptr = upb_WireReader_ReadFixed32(ptr, dst); - dst += 4; - } else { - UPB_ASSERT(lg2 == 3); - ptr = upb_WireReader_ReadFixed64(ptr, dst); - dst += 8; - } - } - upb_EpsCopyInputStream_PopLimit(&d->input, ptr, delta); - } +const char* upb_FileDef_Name(const upb_FileDef* f) { return f->name; } - return ptr; +const char* upb_FileDef_Package(const upb_FileDef* f) { + return f->package ? f->package : ""; } -UPB_FORCEINLINE -static const char* _upb_Decoder_DecodeVarintPacked( - upb_Decoder* d, const char* ptr, upb_Array* arr, wireval* val, - const upb_MiniTableField* field, int lg2) { - int scale = 1 << lg2; - int saved_limit = upb_EpsCopyInputStream_PushLimit(&d->input, ptr, val->size); - char* out = - UPB_PTR_AT(_upb_array_ptr(arr), arr->UPB_PRIVATE(size) << lg2, void); - while (!_upb_Decoder_IsDone(d, &ptr)) { - wireval elem; - ptr = _upb_Decoder_DecodeVarint(d, ptr, &elem.uint64_val); - _upb_Decoder_Munge(field->UPB_PRIVATE(descriptortype), &elem); - if (_upb_Decoder_Reserve(d, arr, 1)) { - out = - UPB_PTR_AT(_upb_array_ptr(arr), arr->UPB_PRIVATE(size) << lg2, void); - } - arr->UPB_PRIVATE(size)++; - memcpy(out, &elem, scale); - out += scale; - } - upb_EpsCopyInputStream_PopLimit(&d->input, ptr, saved_limit); - return ptr; +UPB_DESC(Edition) upb_FileDef_Edition(const upb_FileDef* f) { + return f->edition; } -UPB_NOINLINE -static const char* _upb_Decoder_DecodeEnumPacked( - upb_Decoder* d, const char* ptr, upb_Message* msg, upb_Array* arr, - const upb_MiniTableSub* subs, const upb_MiniTableField* field, - wireval* val) { - const upb_MiniTableEnum* e = _upb_MiniTableSubs_EnumByField(subs, field); - int saved_limit = upb_EpsCopyInputStream_PushLimit(&d->input, ptr, val->size); - char* out = UPB_PTR_AT(_upb_array_ptr(arr), arr->UPB_PRIVATE(size) * 4, void); - while (!_upb_Decoder_IsDone(d, &ptr)) { - wireval elem; - ptr = _upb_Decoder_DecodeVarint(d, ptr, &elem.uint64_val); - _upb_Decoder_MungeInt32(&elem); - if (!_upb_Decoder_CheckEnum(d, ptr, msg, e, field, &elem)) { - continue; - } - if (_upb_Decoder_Reserve(d, arr, 1)) { - out = UPB_PTR_AT(_upb_array_ptr(arr), arr->UPB_PRIVATE(size) * 4, void); - } - arr->UPB_PRIVATE(size)++; - memcpy(out, &elem, 4); - out += 4; - } - upb_EpsCopyInputStream_PopLimit(&d->input, ptr, saved_limit); - return ptr; +const char* _upb_FileDef_RawPackage(const upb_FileDef* f) { return f->package; } + +upb_Syntax upb_FileDef_Syntax(const upb_FileDef* f) { return f->syntax; } + +int upb_FileDef_TopLevelMessageCount(const upb_FileDef* f) { + return f->top_lvl_msg_count; } -upb_Array* _upb_Decoder_CreateArray(upb_Decoder* d, - const upb_MiniTableField* field) { - const upb_FieldType field_type = field->UPB_PRIVATE(descriptortype); - const size_t lg2 = UPB_PRIVATE(_upb_FieldType_SizeLg2)(field_type); - upb_Array* ret = UPB_PRIVATE(_upb_Array_New)(&d->arena, 4, lg2); - if (!ret) _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_OutOfMemory); - return ret; +int upb_FileDef_DependencyCount(const upb_FileDef* f) { return f->dep_count; } + +int upb_FileDef_PublicDependencyCount(const upb_FileDef* f) { + return f->public_dep_count; } -static const char* _upb_Decoder_DecodeToArray(upb_Decoder* d, const char* ptr, - upb_Message* msg, - const upb_MiniTableSub* subs, - const upb_MiniTableField* field, - wireval* val, int op) { - upb_Array** arrp = UPB_PTR_AT(msg, field->UPB_PRIVATE(offset), void); - upb_Array* arr = *arrp; - void* mem; +int upb_FileDef_WeakDependencyCount(const upb_FileDef* f) { + return f->weak_dep_count; +} - if (arr) { - _upb_Decoder_Reserve(d, arr, 1); - } else { - arr = _upb_Decoder_CreateArray(d, field); - *arrp = arr; - } +const int32_t* _upb_FileDef_PublicDependencyIndexes(const upb_FileDef* f) { + return f->public_deps; +} - switch (op) { - case kUpb_DecodeOp_Scalar1Byte: - case kUpb_DecodeOp_Scalar4Byte: - case kUpb_DecodeOp_Scalar8Byte: - /* Append scalar value. */ - mem = UPB_PTR_AT(_upb_array_ptr(arr), arr->UPB_PRIVATE(size) << op, void); - arr->UPB_PRIVATE(size)++; - memcpy(mem, val, 1 << op); - return ptr; - case kUpb_DecodeOp_String: - _upb_Decoder_VerifyUtf8(d, ptr, val->size); - /* Fallthrough. */ - case kUpb_DecodeOp_Bytes: { - /* Append bytes. */ - upb_StringView* str = - (upb_StringView*)_upb_array_ptr(arr) + arr->UPB_PRIVATE(size); - arr->UPB_PRIVATE(size)++; - return _upb_Decoder_ReadString(d, ptr, val->size, str); - } - case kUpb_DecodeOp_SubMessage: { - /* Append submessage / group. */ - upb_TaggedMessagePtr* target = UPB_PTR_AT( - _upb_array_ptr(arr), arr->UPB_PRIVATE(size) * sizeof(void*), - upb_TaggedMessagePtr); - upb_Message* submsg = _upb_Decoder_NewSubMessage(d, subs, field, target); - arr->UPB_PRIVATE(size)++; - if (UPB_UNLIKELY(field->UPB_PRIVATE(descriptortype) == - kUpb_FieldType_Group)) { - return _upb_Decoder_DecodeKnownGroup(d, ptr, submsg, subs, field); - } else { - return _upb_Decoder_DecodeSubMessage(d, ptr, submsg, subs, field, - val->size); - } - } - case OP_FIXPCK_LG2(2): - case OP_FIXPCK_LG2(3): - return _upb_Decoder_DecodeFixedPacked(d, ptr, arr, val, field, - op - OP_FIXPCK_LG2(0)); - case OP_VARPCK_LG2(0): - case OP_VARPCK_LG2(2): - case OP_VARPCK_LG2(3): - return _upb_Decoder_DecodeVarintPacked(d, ptr, arr, val, field, - op - OP_VARPCK_LG2(0)); - case kUpb_DecodeOp_Enum: - return _upb_Decoder_DecodeEnumArray(d, ptr, msg, arr, subs, field, val); - case kUpb_DecodeOp_PackedEnum: - return _upb_Decoder_DecodeEnumPacked(d, ptr, msg, arr, subs, field, val); - default: - UPB_UNREACHABLE(); - } +const int32_t* _upb_FileDef_WeakDependencyIndexes(const upb_FileDef* f) { + return f->weak_deps; } -upb_Map* _upb_Decoder_CreateMap(upb_Decoder* d, const upb_MiniTable* entry) { - /* Maps descriptor type -> upb map size. */ - static const uint8_t kSizeInMap[] = { - [0] = -1, // invalid descriptor type */ - [kUpb_FieldType_Double] = 8, - [kUpb_FieldType_Float] = 4, - [kUpb_FieldType_Int64] = 8, - [kUpb_FieldType_UInt64] = 8, - [kUpb_FieldType_Int32] = 4, - [kUpb_FieldType_Fixed64] = 8, - [kUpb_FieldType_Fixed32] = 4, - [kUpb_FieldType_Bool] = 1, - [kUpb_FieldType_String] = UPB_MAPTYPE_STRING, - [kUpb_FieldType_Group] = sizeof(void*), - [kUpb_FieldType_Message] = sizeof(void*), - [kUpb_FieldType_Bytes] = UPB_MAPTYPE_STRING, - [kUpb_FieldType_UInt32] = 4, - [kUpb_FieldType_Enum] = 4, - [kUpb_FieldType_SFixed32] = 4, - [kUpb_FieldType_SFixed64] = 8, - [kUpb_FieldType_SInt32] = 4, - [kUpb_FieldType_SInt64] = 8, - }; +int upb_FileDef_TopLevelEnumCount(const upb_FileDef* f) { + return f->top_lvl_enum_count; +} - const upb_MiniTableField* key_field = &entry->UPB_PRIVATE(fields)[0]; - const upb_MiniTableField* val_field = &entry->UPB_PRIVATE(fields)[1]; - char key_size = kSizeInMap[key_field->UPB_PRIVATE(descriptortype)]; - char val_size = kSizeInMap[val_field->UPB_PRIVATE(descriptortype)]; - UPB_ASSERT(key_field->UPB_PRIVATE(offset) == offsetof(upb_MapEntryData, k)); - UPB_ASSERT(val_field->UPB_PRIVATE(offset) == offsetof(upb_MapEntryData, v)); - upb_Map* ret = _upb_Map_New(&d->arena, key_size, val_size); - if (!ret) _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_OutOfMemory); - return ret; +int upb_FileDef_TopLevelExtensionCount(const upb_FileDef* f) { + return f->top_lvl_ext_count; } -static const char* _upb_Decoder_DecodeToMap(upb_Decoder* d, const char* ptr, - upb_Message* msg, - const upb_MiniTableSub* subs, - const upb_MiniTableField* field, - wireval* val) { - upb_Map** map_p = UPB_PTR_AT(msg, field->UPB_PRIVATE(offset), upb_Map*); - upb_Map* map = *map_p; - upb_MapEntry ent; - UPB_ASSERT(upb_MiniTableField_Type(field) == kUpb_FieldType_Message); - const upb_MiniTable* entry = _upb_MiniTableSubs_MessageByField(subs, field); +int upb_FileDef_ServiceCount(const upb_FileDef* f) { return f->service_count; } - UPB_ASSERT(entry); - UPB_ASSERT(entry->UPB_PRIVATE(field_count) == 2); - UPB_ASSERT(upb_MiniTableField_IsScalar(&entry->UPB_PRIVATE(fields)[0])); - UPB_ASSERT(upb_MiniTableField_IsScalar(&entry->UPB_PRIVATE(fields)[1])); +const upb_FileDef* upb_FileDef_Dependency(const upb_FileDef* f, int i) { + UPB_ASSERT(0 <= i && i < f->dep_count); + return f->deps[i]; +} - if (!map) { - map = _upb_Decoder_CreateMap(d, entry); - *map_p = map; - } +const upb_FileDef* upb_FileDef_PublicDependency(const upb_FileDef* f, int i) { + UPB_ASSERT(0 <= i && i < f->public_dep_count); + return f->deps[f->public_deps[i]]; +} - // Parse map entry. - memset(&ent, 0, sizeof(ent)); +const upb_FileDef* upb_FileDef_WeakDependency(const upb_FileDef* f, int i) { + UPB_ASSERT(0 <= i && i < f->public_dep_count); + return f->deps[f->weak_deps[i]]; +} - if (entry->UPB_PRIVATE(fields)[1].UPB_PRIVATE(descriptortype) == - kUpb_FieldType_Message || - entry->UPB_PRIVATE(fields)[1].UPB_PRIVATE(descriptortype) == - kUpb_FieldType_Group) { - // Create proactively to handle the case where it doesn't appear. - upb_TaggedMessagePtr msg; - _upb_Decoder_NewSubMessage(d, entry->UPB_PRIVATE(subs), - &entry->UPB_PRIVATE(fields)[1], &msg); - ent.data.v.val = upb_value_uintptr(msg); - } +const upb_MessageDef* upb_FileDef_TopLevelMessage(const upb_FileDef* f, int i) { + UPB_ASSERT(0 <= i && i < f->top_lvl_msg_count); + return _upb_MessageDef_At(f->top_lvl_msgs, i); +} - ptr = _upb_Decoder_DecodeSubMessage(d, ptr, (upb_Message*)&ent.data, subs, - field, val->size); - // check if ent had any unknown fields - size_t size; - upb_Message_GetUnknown((upb_Message*)&ent.data, &size); - if (size != 0) { - char* buf; - size_t size; - uint32_t tag = - ((uint32_t)field->UPB_PRIVATE(number) << 3) | kUpb_WireType_Delimited; - upb_EncodeStatus status = - upb_Encode((upb_Message*)&ent.data, entry, 0, &d->arena, &buf, &size); - if (status != kUpb_EncodeStatus_Ok) { - _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_OutOfMemory); - } - _upb_Decoder_AddUnknownVarints(d, msg, tag, size); - if (!UPB_PRIVATE(_upb_Message_AddUnknown)(msg, buf, size, &d->arena)) { - _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_OutOfMemory); - } - } else { - if (_upb_Map_Insert(map, &ent.data.k, map->key_size, &ent.data.v, - map->val_size, - &d->arena) == kUpb_MapInsertStatus_OutOfMemory) { - _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_OutOfMemory); - } - } - return ptr; +const upb_EnumDef* upb_FileDef_TopLevelEnum(const upb_FileDef* f, int i) { + UPB_ASSERT(0 <= i && i < f->top_lvl_enum_count); + return _upb_EnumDef_At(f->top_lvl_enums, i); +} + +const upb_FieldDef* upb_FileDef_TopLevelExtension(const upb_FileDef* f, int i) { + UPB_ASSERT(0 <= i && i < f->top_lvl_ext_count); + return _upb_FieldDef_At(f->top_lvl_exts, i); } -static const char* _upb_Decoder_DecodeToSubMessage( - upb_Decoder* d, const char* ptr, upb_Message* msg, - const upb_MiniTableSub* subs, const upb_MiniTableField* field, wireval* val, - int op) { - void* mem = UPB_PTR_AT(msg, field->UPB_PRIVATE(offset), void); - int type = field->UPB_PRIVATE(descriptortype); +const upb_ServiceDef* upb_FileDef_Service(const upb_FileDef* f, int i) { + UPB_ASSERT(0 <= i && i < f->service_count); + return _upb_ServiceDef_At(f->services, i); +} - if (UPB_UNLIKELY(op == kUpb_DecodeOp_Enum) && - !_upb_Decoder_CheckEnum(d, ptr, msg, - _upb_MiniTableSubs_EnumByField(subs, field), - field, val)) { - return ptr; - } +const upb_DefPool* upb_FileDef_Pool(const upb_FileDef* f) { return f->symtab; } - /* Set presence if necessary. */ - if (field->presence > 0) { - UPB_PRIVATE(_upb_Message_SetHasbit)(msg, field); - } else if (field->presence < 0) { - /* Oneof case */ - uint32_t* oneof_case = UPB_PRIVATE(_upb_Message_OneofCasePtr)(msg, field); - if (op == kUpb_DecodeOp_SubMessage && - *oneof_case != field->UPB_PRIVATE(number)) { - memset(mem, 0, sizeof(void*)); - } - *oneof_case = field->UPB_PRIVATE(number); - } +const upb_MiniTableExtension* _upb_FileDef_ExtensionMiniTable( + const upb_FileDef* f, int i) { + return f->ext_layouts[i]; +} - /* Store into message. */ - switch (op) { - case kUpb_DecodeOp_SubMessage: { - upb_TaggedMessagePtr* submsgp = mem; - upb_Message* submsg; - if (*submsgp) { - submsg = _upb_Decoder_ReuseSubMessage(d, subs, field, submsgp); - } else { - submsg = _upb_Decoder_NewSubMessage(d, subs, field, submsgp); - } - if (UPB_UNLIKELY(type == kUpb_FieldType_Group)) { - ptr = _upb_Decoder_DecodeKnownGroup(d, ptr, submsg, subs, field); - } else { - ptr = _upb_Decoder_DecodeSubMessage(d, ptr, submsg, subs, field, - val->size); - } - break; - } - case kUpb_DecodeOp_String: - _upb_Decoder_VerifyUtf8(d, ptr, val->size); - /* Fallthrough. */ - case kUpb_DecodeOp_Bytes: - return _upb_Decoder_ReadString(d, ptr, val->size, mem); - case kUpb_DecodeOp_Scalar8Byte: - memcpy(mem, val, 8); - break; - case kUpb_DecodeOp_Enum: - case kUpb_DecodeOp_Scalar4Byte: - memcpy(mem, val, 4); - break; - case kUpb_DecodeOp_Scalar1Byte: - memcpy(mem, val, 1); - break; - default: - UPB_UNREACHABLE(); - } +static char* strviewdup(upb_DefBuilder* ctx, upb_StringView view) { + char* ret = upb_strdup2(view.data, view.size, _upb_DefBuilder_Arena(ctx)); + if (!ret) _upb_DefBuilder_OomErr(ctx); + return ret; +} - return ptr; +static bool streql_view(upb_StringView view, const char* b) { + return view.size == strlen(b) && memcmp(view.data, b, view.size) == 0; } -UPB_NOINLINE -const char* _upb_Decoder_CheckRequired(upb_Decoder* d, const char* ptr, - const upb_Message* msg, - const upb_MiniTable* m) { - UPB_ASSERT(m->UPB_PRIVATE(required_count)); - if (UPB_LIKELY((d->options & kUpb_DecodeOption_CheckRequired) == 0)) { - return ptr; - } - uint64_t msg_head; - memcpy(&msg_head, msg, 8); - msg_head = UPB_PRIVATE(_upb_BigEndian64)(msg_head); - if (UPB_PRIVATE(_upb_MiniTable_RequiredMask)(m) & ~msg_head) { - d->missing_required = true; +static int count_exts_in_msg(const UPB_DESC(DescriptorProto) * msg_proto) { + size_t n; + UPB_DESC(DescriptorProto_extension)(msg_proto, &n); + int ext_count = n; + + const UPB_DESC(DescriptorProto)* const* nested_msgs = + UPB_DESC(DescriptorProto_nested_type)(msg_proto, &n); + for (size_t i = 0; i < n; i++) { + ext_count += count_exts_in_msg(nested_msgs[i]); } - return ptr; + + return ext_count; } -UPB_FORCEINLINE -static bool _upb_Decoder_TryFastDispatch(upb_Decoder* d, const char** ptr, - upb_Message* msg, - const upb_MiniTable* m) { -#if UPB_FASTTABLE - if (m && m->UPB_PRIVATE(table_mask) != (unsigned char)-1) { - uint16_t tag = _upb_FastDecoder_LoadTag(*ptr); - intptr_t table = decode_totable(m); - *ptr = _upb_FastDecoder_TagDispatch(d, *ptr, msg, table, 0, tag); - return true; +const UPB_DESC(FeatureSet*) + _upb_FileDef_FindEdition(upb_DefBuilder* ctx, int edition) { + const UPB_DESC(FeatureSetDefaults)* defaults = + upb_DefPool_FeatureSetDefaults(ctx->symtab); + + int min = UPB_DESC(FeatureSetDefaults_minimum_edition)(defaults); + int max = UPB_DESC(FeatureSetDefaults_maximum_edition)(defaults); + if (edition < min) { + _upb_DefBuilder_Errf(ctx, + "Edition %s is earlier than the minimum edition %s " + "given in the defaults", + upb_FileDef_EditionName(edition), + upb_FileDef_EditionName(min)); + return NULL; + } + if (edition > max) { + _upb_DefBuilder_Errf(ctx, + "Edition %s is later than the maximum edition %s " + "given in the defaults", + upb_FileDef_EditionName(edition), + upb_FileDef_EditionName(max)); + return NULL; } -#endif - return false; -} -static const char* upb_Decoder_SkipField(upb_Decoder* d, const char* ptr, - uint32_t tag) { - int field_number = tag >> 3; - int wire_type = tag & 7; - switch (wire_type) { - case kUpb_WireType_Varint: { - uint64_t val; - return _upb_Decoder_DecodeVarint(d, ptr, &val); - } - case kUpb_WireType_64Bit: - return ptr + 8; - case kUpb_WireType_32Bit: - return ptr + 4; - case kUpb_WireType_Delimited: { - uint32_t size; - ptr = upb_Decoder_DecodeSize(d, ptr, &size); - return ptr + size; + size_t n; + const UPB_DESC(FeatureSetDefaults_FeatureSetEditionDefault)* const* d = + UPB_DESC(FeatureSetDefaults_defaults)(defaults, &n); + const UPB_DESC(FeatureSet)* ret = NULL; + for (size_t i = 0; i < n; i++) { + if (UPB_DESC(FeatureSetDefaults_FeatureSetEditionDefault_edition)(d[i]) > + edition) { + break; } - case kUpb_WireType_StartGroup: - return _upb_Decoder_DecodeUnknownGroup(d, ptr, field_number); - default: - _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_Malformed); + ret = UPB_DESC(FeatureSetDefaults_FeatureSetEditionDefault_features)(d[i]); + } + if (ret == NULL) { + _upb_DefBuilder_Errf(ctx, "No valid default found for edition %s", + upb_FileDef_EditionName(edition)); + return NULL; } + return ret; } -enum { - kStartItemTag = ((kUpb_MsgSet_Item << 3) | kUpb_WireType_StartGroup), - kEndItemTag = ((kUpb_MsgSet_Item << 3) | kUpb_WireType_EndGroup), - kTypeIdTag = ((kUpb_MsgSet_TypeId << 3) | kUpb_WireType_Varint), - kMessageTag = ((kUpb_MsgSet_Message << 3) | kUpb_WireType_Delimited), -}; +// Allocate and initialize one file def, and add it to the context object. +void _upb_FileDef_Create(upb_DefBuilder* ctx, + const UPB_DESC(FileDescriptorProto) * file_proto) { + upb_FileDef* file = _upb_DefBuilder_Alloc(ctx, sizeof(upb_FileDef)); + ctx->file = file; -static void upb_Decoder_AddKnownMessageSetItem( - upb_Decoder* d, upb_Message* msg, const upb_MiniTableExtension* item_mt, - const char* data, uint32_t size) { - upb_Extension* ext = - _upb_Message_GetOrCreateExtension(msg, item_mt, &d->arena); - if (UPB_UNLIKELY(!ext)) { - _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_OutOfMemory); - } - upb_Message* submsg = _upb_Decoder_NewSubMessage( - d, &ext->ext->UPB_PRIVATE(sub), upb_MiniTableExtension_AsField(ext->ext), - (upb_TaggedMessagePtr*)&ext->data); - upb_DecodeStatus status = upb_Decode( - data, size, submsg, upb_MiniTableExtension_GetSubMessage(item_mt), - d->extreg, d->options, &d->arena); - if (status != kUpb_DecodeStatus_Ok) _upb_Decoder_ErrorJmp(d, status); -} + const UPB_DESC(DescriptorProto)* const* msgs; + const UPB_DESC(EnumDescriptorProto)* const* enums; + const UPB_DESC(FieldDescriptorProto)* const* exts; + const UPB_DESC(ServiceDescriptorProto)* const* services; + const upb_StringView* strs; + const int32_t* public_deps; + const int32_t* weak_deps; + size_t n; -static void upb_Decoder_AddUnknownMessageSetItem(upb_Decoder* d, - upb_Message* msg, - uint32_t type_id, - const char* message_data, - uint32_t message_size) { - char buf[60]; - char* ptr = buf; - ptr = upb_Decoder_EncodeVarint32(kStartItemTag, ptr); - ptr = upb_Decoder_EncodeVarint32(kTypeIdTag, ptr); - ptr = upb_Decoder_EncodeVarint32(type_id, ptr); - ptr = upb_Decoder_EncodeVarint32(kMessageTag, ptr); - ptr = upb_Decoder_EncodeVarint32(message_size, ptr); - char* split = ptr; + file->symtab = ctx->symtab; - ptr = upb_Decoder_EncodeVarint32(kEndItemTag, ptr); - char* end = ptr; + // Count all extensions in the file, to build a flat array of layouts. + UPB_DESC(FileDescriptorProto_extension)(file_proto, &n); + int ext_count = n; + msgs = UPB_DESC(FileDescriptorProto_message_type)(file_proto, &n); + for (size_t i = 0; i < n; i++) { + ext_count += count_exts_in_msg(msgs[i]); + } + file->ext_count = ext_count; - if (!UPB_PRIVATE(_upb_Message_AddUnknown)(msg, buf, split - buf, &d->arena) || - !UPB_PRIVATE(_upb_Message_AddUnknown)(msg, message_data, message_size, - &d->arena) || - !UPB_PRIVATE(_upb_Message_AddUnknown)(msg, split, end - split, - &d->arena)) { - _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_OutOfMemory); + if (ctx->layout) { + // We are using the ext layouts that were passed in. + file->ext_layouts = ctx->layout->UPB_PRIVATE(exts); + const int mt_ext_count = upb_MiniTableFile_ExtensionCount(ctx->layout); + if (mt_ext_count != file->ext_count) { + _upb_DefBuilder_Errf(ctx, + "Extension count did not match layout (%d vs %d)", + mt_ext_count, file->ext_count); + } + } else { + // We are building ext layouts from scratch. + file->ext_layouts = _upb_DefBuilder_Alloc( + ctx, sizeof(*file->ext_layouts) * file->ext_count); + upb_MiniTableExtension* ext = + _upb_DefBuilder_Alloc(ctx, sizeof(*ext) * file->ext_count); + for (int i = 0; i < file->ext_count; i++) { + file->ext_layouts[i] = &ext[i]; + } } -} -static void upb_Decoder_AddMessageSetItem(upb_Decoder* d, upb_Message* msg, - const upb_MiniTable* t, - uint32_t type_id, const char* data, - uint32_t size) { - const upb_MiniTableExtension* item_mt = - upb_ExtensionRegistry_Lookup(d->extreg, t, type_id); - if (item_mt) { - upb_Decoder_AddKnownMessageSetItem(d, msg, item_mt, data, size); + upb_StringView name = UPB_DESC(FileDescriptorProto_name)(file_proto); + file->name = strviewdup(ctx, name); + if (strlen(file->name) != name.size) { + _upb_DefBuilder_Errf(ctx, "File name contained embedded NULL"); + } + + upb_StringView package = UPB_DESC(FileDescriptorProto_package)(file_proto); + + if (package.size) { + _upb_DefBuilder_CheckIdentFull(ctx, package); + file->package = strviewdup(ctx, package); } else { - upb_Decoder_AddUnknownMessageSetItem(d, msg, type_id, data, size); + file->package = NULL; } -} -static const char* upb_Decoder_DecodeMessageSetItem( - upb_Decoder* d, const char* ptr, upb_Message* msg, - const upb_MiniTable* layout) { - uint32_t type_id = 0; - upb_StringView preserved = {NULL, 0}; - typedef enum { - kUpb_HaveId = 1 << 0, - kUpb_HavePayload = 1 << 1, - } StateMask; - StateMask state_mask = 0; - while (!_upb_Decoder_IsDone(d, &ptr)) { - uint32_t tag; - ptr = _upb_Decoder_DecodeTag(d, ptr, &tag); - switch (tag) { - case kEndItemTag: - return ptr; - case kTypeIdTag: { - uint64_t tmp; - ptr = _upb_Decoder_DecodeVarint(d, ptr, &tmp); - if (state_mask & kUpb_HaveId) break; // Ignore dup. - state_mask |= kUpb_HaveId; - type_id = tmp; - if (state_mask & kUpb_HavePayload) { - upb_Decoder_AddMessageSetItem(d, msg, layout, type_id, preserved.data, - preserved.size); - } - break; - } - case kMessageTag: { - uint32_t size; - ptr = upb_Decoder_DecodeSize(d, ptr, &size); - const char* data = ptr; - ptr += size; - if (state_mask & kUpb_HavePayload) break; // Ignore dup. - state_mask |= kUpb_HavePayload; - if (state_mask & kUpb_HaveId) { - upb_Decoder_AddMessageSetItem(d, msg, layout, type_id, data, size); - } else { - // Out of order, we must preserve the payload. - preserved.data = data; - preserved.size = size; - } - break; - } - default: - // We do not preserve unexpected fields inside a message set item. - ptr = upb_Decoder_SkipField(d, ptr, tag); - break; + // TODO: How should we validate this? + file->edition = UPB_DESC(FileDescriptorProto_edition)(file_proto); + + if (UPB_DESC(FileDescriptorProto_has_syntax)(file_proto)) { + upb_StringView syntax = UPB_DESC(FileDescriptorProto_syntax)(file_proto); + + if (streql_view(syntax, "proto2")) { + file->syntax = kUpb_Syntax_Proto2; + file->edition = UPB_DESC(EDITION_PROTO2); + } else if (streql_view(syntax, "proto3")) { + file->syntax = kUpb_Syntax_Proto3; + file->edition = UPB_DESC(EDITION_PROTO3); + } else if (streql_view(syntax, "editions")) { + file->syntax = kUpb_Syntax_Editions; + file->edition = UPB_DESC(FileDescriptorProto_edition)(file_proto); + } else { + _upb_DefBuilder_Errf(ctx, "Invalid syntax '" UPB_STRINGVIEW_FORMAT "'", + UPB_STRINGVIEW_ARGS(syntax)); } + } else { + file->syntax = kUpb_Syntax_Proto2; + file->edition = UPB_DESC(EDITION_PROTO2); } - _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_Malformed); -} -static const upb_MiniTableField* _upb_Decoder_FindField(upb_Decoder* d, - const upb_MiniTable* t, - uint32_t field_number, - int* last_field_index) { - static upb_MiniTableField none = { - 0, 0, 0, 0, kUpb_FakeFieldType_FieldNotFound, 0}; - if (t == NULL) return &none; + // Read options. + UPB_DEF_SET_OPTIONS(file->opts, FileDescriptorProto, FileOptions, file_proto); - size_t idx = ((size_t)field_number) - 1; // 0 wraps to SIZE_MAX - if (idx < t->UPB_PRIVATE(dense_below)) { - /* Fastest case: index into dense fields. */ - goto found; - } + // Resolve features. + const UPB_DESC(FeatureSet*) edition_defaults = + _upb_FileDef_FindEdition(ctx, file->edition); + const UPB_DESC(FeatureSet*) unresolved = + UPB_DESC(FileOptions_features)(file->opts); + file->resolved_features = + _upb_DefBuilder_ResolveFeatures(ctx, edition_defaults, unresolved); - if (t->UPB_PRIVATE(dense_below) < t->UPB_PRIVATE(field_count)) { - /* Linear search non-dense fields. Resume scanning from last_field_index - * since fields are usually in order. */ - size_t last = *last_field_index; - for (idx = last; idx < t->UPB_PRIVATE(field_count); idx++) { - if (t->UPB_PRIVATE(fields)[idx].UPB_PRIVATE(number) == field_number) { - goto found; - } + // Verify dependencies. + strs = UPB_DESC(FileDescriptorProto_dependency)(file_proto, &n); + file->dep_count = n; + file->deps = _upb_DefBuilder_Alloc(ctx, sizeof(*file->deps) * n); + + for (size_t i = 0; i < n; i++) { + upb_StringView str = strs[i]; + file->deps[i] = + upb_DefPool_FindFileByNameWithSize(ctx->symtab, str.data, str.size); + if (!file->deps[i]) { + _upb_DefBuilder_Errf(ctx, + "Depends on file '" UPB_STRINGVIEW_FORMAT + "', but it has not been loaded", + UPB_STRINGVIEW_ARGS(str)); } + } - for (idx = t->UPB_PRIVATE(dense_below); idx < last; idx++) { - if (t->UPB_PRIVATE(fields)[idx].UPB_PRIVATE(number) == field_number) { - goto found; - } + public_deps = UPB_DESC(FileDescriptorProto_public_dependency)(file_proto, &n); + file->public_dep_count = n; + file->public_deps = + _upb_DefBuilder_Alloc(ctx, sizeof(*file->public_deps) * n); + int32_t* mutable_public_deps = (int32_t*)file->public_deps; + for (size_t i = 0; i < n; i++) { + if (public_deps[i] >= file->dep_count) { + _upb_DefBuilder_Errf(ctx, "public_dep %d is out of range", + (int)public_deps[i]); } + mutable_public_deps[i] = public_deps[i]; } - if (d->extreg) { - switch (t->UPB_PRIVATE(ext)) { - case kUpb_ExtMode_Extendable: { - const upb_MiniTableExtension* ext = - upb_ExtensionRegistry_Lookup(d->extreg, t, field_number); - if (ext) return upb_MiniTableExtension_AsField(ext); - break; - } - case kUpb_ExtMode_IsMessageSet: - if (field_number == kUpb_MsgSet_Item) { - static upb_MiniTableField item = { - 0, 0, 0, 0, kUpb_FakeFieldType_MessageSetItem, 0}; - return &item; - } - break; + weak_deps = UPB_DESC(FileDescriptorProto_weak_dependency)(file_proto, &n); + file->weak_dep_count = n; + file->weak_deps = _upb_DefBuilder_Alloc(ctx, sizeof(*file->weak_deps) * n); + int32_t* mutable_weak_deps = (int32_t*)file->weak_deps; + for (size_t i = 0; i < n; i++) { + if (weak_deps[i] >= file->dep_count) { + _upb_DefBuilder_Errf(ctx, "weak_dep %d is out of range", + (int)weak_deps[i]); } + mutable_weak_deps[i] = weak_deps[i]; } - return &none; /* Unknown field. */ + // Create enums. + enums = UPB_DESC(FileDescriptorProto_enum_type)(file_proto, &n); + file->top_lvl_enum_count = n; + file->top_lvl_enums = + _upb_EnumDefs_New(ctx, n, enums, file->resolved_features, NULL); -found: - UPB_ASSERT(t->UPB_PRIVATE(fields)[idx].UPB_PRIVATE(number) == field_number); - *last_field_index = idx; - return &t->UPB_PRIVATE(fields)[idx]; -} + // Create extensions. + exts = UPB_DESC(FileDescriptorProto_extension)(file_proto, &n); + file->top_lvl_ext_count = n; + file->top_lvl_exts = _upb_Extensions_New( + ctx, n, exts, file->resolved_features, file->package, NULL); -int _upb_Decoder_GetVarintOp(const upb_MiniTableField* field) { - static const int8_t kVarintOps[] = { - [kUpb_FakeFieldType_FieldNotFound] = kUpb_DecodeOp_UnknownField, - [kUpb_FieldType_Double] = kUpb_DecodeOp_UnknownField, - [kUpb_FieldType_Float] = kUpb_DecodeOp_UnknownField, - [kUpb_FieldType_Int64] = kUpb_DecodeOp_Scalar8Byte, - [kUpb_FieldType_UInt64] = kUpb_DecodeOp_Scalar8Byte, - [kUpb_FieldType_Int32] = kUpb_DecodeOp_Scalar4Byte, - [kUpb_FieldType_Fixed64] = kUpb_DecodeOp_UnknownField, - [kUpb_FieldType_Fixed32] = kUpb_DecodeOp_UnknownField, - [kUpb_FieldType_Bool] = kUpb_DecodeOp_Scalar1Byte, - [kUpb_FieldType_String] = kUpb_DecodeOp_UnknownField, - [kUpb_FieldType_Group] = kUpb_DecodeOp_UnknownField, - [kUpb_FieldType_Message] = kUpb_DecodeOp_UnknownField, - [kUpb_FieldType_Bytes] = kUpb_DecodeOp_UnknownField, - [kUpb_FieldType_UInt32] = kUpb_DecodeOp_Scalar4Byte, - [kUpb_FieldType_Enum] = kUpb_DecodeOp_Enum, - [kUpb_FieldType_SFixed32] = kUpb_DecodeOp_UnknownField, - [kUpb_FieldType_SFixed64] = kUpb_DecodeOp_UnknownField, - [kUpb_FieldType_SInt32] = kUpb_DecodeOp_Scalar4Byte, - [kUpb_FieldType_SInt64] = kUpb_DecodeOp_Scalar8Byte, - [kUpb_FakeFieldType_MessageSetItem] = kUpb_DecodeOp_UnknownField, - }; + // Create messages. + msgs = UPB_DESC(FileDescriptorProto_message_type)(file_proto, &n); + file->top_lvl_msg_count = n; + file->top_lvl_msgs = + _upb_MessageDefs_New(ctx, n, msgs, file->resolved_features, NULL); - return kVarintOps[field->UPB_PRIVATE(descriptortype)]; -} + // Create services. + services = UPB_DESC(FileDescriptorProto_service)(file_proto, &n); + file->service_count = n; + file->services = + _upb_ServiceDefs_New(ctx, n, services, file->resolved_features); -UPB_FORCEINLINE -static void _upb_Decoder_CheckUnlinked(upb_Decoder* d, const upb_MiniTable* mt, - const upb_MiniTableField* field, - int* op) { - // If sub-message is not linked, treat as unknown. - if (field->UPB_PRIVATE(mode) & kUpb_LabelFlags_IsExtension) return; - const upb_MiniTable* mt_sub = - _upb_MiniTableSubs_MessageByField(mt->UPB_PRIVATE(subs), field); - if ((d->options & kUpb_DecodeOption_ExperimentalAllowUnlinked) || - !UPB_PRIVATE(_upb_MiniTable_IsEmpty)(mt_sub)) { - return; - } -#ifndef NDEBUG - const upb_MiniTableField* oneof = upb_MiniTable_GetOneof(mt, field); - if (oneof) { - // All other members of the oneof must be message fields that are also - // unlinked. - do { - UPB_ASSERT(upb_MiniTableField_CType(oneof) == kUpb_CType_Message); - const upb_MiniTableSub* oneof_sub = - &mt->UPB_PRIVATE(subs)[oneof->UPB_PRIVATE(submsg_index)]; - UPB_ASSERT(!oneof_sub); - } while (upb_MiniTable_NextOneofField(mt, &oneof)); + // Now that all names are in the table, build layouts and resolve refs. + + for (int i = 0; i < file->top_lvl_msg_count; i++) { + upb_MessageDef* m = (upb_MessageDef*)upb_FileDef_TopLevelMessage(file, i); + _upb_MessageDef_Resolve(ctx, m); } -#endif // NDEBUG - *op = kUpb_DecodeOp_UnknownField; -} -int _upb_Decoder_GetDelimitedOp(upb_Decoder* d, const upb_MiniTable* mt, - const upb_MiniTableField* field) { - enum { kRepeatedBase = 19 }; + for (int i = 0; i < file->top_lvl_ext_count; i++) { + upb_FieldDef* f = (upb_FieldDef*)upb_FileDef_TopLevelExtension(file, i); + _upb_FieldDef_Resolve(ctx, file->package, f); + } - static const int8_t kDelimitedOps[] = { - /* For non-repeated field type. */ - [kUpb_FakeFieldType_FieldNotFound] = - kUpb_DecodeOp_UnknownField, // Field not found. - [kUpb_FieldType_Double] = kUpb_DecodeOp_UnknownField, - [kUpb_FieldType_Float] = kUpb_DecodeOp_UnknownField, - [kUpb_FieldType_Int64] = kUpb_DecodeOp_UnknownField, - [kUpb_FieldType_UInt64] = kUpb_DecodeOp_UnknownField, - [kUpb_FieldType_Int32] = kUpb_DecodeOp_UnknownField, - [kUpb_FieldType_Fixed64] = kUpb_DecodeOp_UnknownField, - [kUpb_FieldType_Fixed32] = kUpb_DecodeOp_UnknownField, - [kUpb_FieldType_Bool] = kUpb_DecodeOp_UnknownField, - [kUpb_FieldType_String] = kUpb_DecodeOp_String, - [kUpb_FieldType_Group] = kUpb_DecodeOp_UnknownField, - [kUpb_FieldType_Message] = kUpb_DecodeOp_SubMessage, - [kUpb_FieldType_Bytes] = kUpb_DecodeOp_Bytes, - [kUpb_FieldType_UInt32] = kUpb_DecodeOp_UnknownField, - [kUpb_FieldType_Enum] = kUpb_DecodeOp_UnknownField, - [kUpb_FieldType_SFixed32] = kUpb_DecodeOp_UnknownField, - [kUpb_FieldType_SFixed64] = kUpb_DecodeOp_UnknownField, - [kUpb_FieldType_SInt32] = kUpb_DecodeOp_UnknownField, - [kUpb_FieldType_SInt64] = kUpb_DecodeOp_UnknownField, - [kUpb_FakeFieldType_MessageSetItem] = kUpb_DecodeOp_UnknownField, - // For repeated field type. */ - [kRepeatedBase + kUpb_FieldType_Double] = OP_FIXPCK_LG2(3), - [kRepeatedBase + kUpb_FieldType_Float] = OP_FIXPCK_LG2(2), - [kRepeatedBase + kUpb_FieldType_Int64] = OP_VARPCK_LG2(3), - [kRepeatedBase + kUpb_FieldType_UInt64] = OP_VARPCK_LG2(3), - [kRepeatedBase + kUpb_FieldType_Int32] = OP_VARPCK_LG2(2), - [kRepeatedBase + kUpb_FieldType_Fixed64] = OP_FIXPCK_LG2(3), - [kRepeatedBase + kUpb_FieldType_Fixed32] = OP_FIXPCK_LG2(2), - [kRepeatedBase + kUpb_FieldType_Bool] = OP_VARPCK_LG2(0), - [kRepeatedBase + kUpb_FieldType_String] = kUpb_DecodeOp_String, - [kRepeatedBase + kUpb_FieldType_Group] = kUpb_DecodeOp_SubMessage, - [kRepeatedBase + kUpb_FieldType_Message] = kUpb_DecodeOp_SubMessage, - [kRepeatedBase + kUpb_FieldType_Bytes] = kUpb_DecodeOp_Bytes, - [kRepeatedBase + kUpb_FieldType_UInt32] = OP_VARPCK_LG2(2), - [kRepeatedBase + kUpb_FieldType_Enum] = kUpb_DecodeOp_PackedEnum, - [kRepeatedBase + kUpb_FieldType_SFixed32] = OP_FIXPCK_LG2(2), - [kRepeatedBase + kUpb_FieldType_SFixed64] = OP_FIXPCK_LG2(3), - [kRepeatedBase + kUpb_FieldType_SInt32] = OP_VARPCK_LG2(2), - [kRepeatedBase + kUpb_FieldType_SInt64] = OP_VARPCK_LG2(3), - // Omitting kUpb_FakeFieldType_MessageSetItem, because we never emit a - // repeated msgset type - }; + for (int i = 0; i < file->top_lvl_msg_count; i++) { + upb_MessageDef* m = (upb_MessageDef*)upb_FileDef_TopLevelMessage(file, i); + _upb_MessageDef_CreateMiniTable(ctx, (upb_MessageDef*)m); + } - int ndx = field->UPB_PRIVATE(descriptortype); - if (upb_MiniTableField_IsArray(field)) ndx += kRepeatedBase; - int op = kDelimitedOps[ndx]; + for (int i = 0; i < file->top_lvl_ext_count; i++) { + upb_FieldDef* f = (upb_FieldDef*)upb_FileDef_TopLevelExtension(file, i); + _upb_FieldDef_BuildMiniTableExtension(ctx, f); + } - if (op == kUpb_DecodeOp_SubMessage) { - _upb_Decoder_CheckUnlinked(d, mt, field, &op); + for (int i = 0; i < file->top_lvl_msg_count; i++) { + upb_MessageDef* m = (upb_MessageDef*)upb_FileDef_TopLevelMessage(file, i); + _upb_MessageDef_LinkMiniTable(ctx, m); } - return op; + if (file->ext_count) { + bool ok = upb_ExtensionRegistry_AddArray( + _upb_DefPool_ExtReg(ctx->symtab), file->ext_layouts, file->ext_count); + if (!ok) _upb_DefBuilder_OomErr(ctx); + } } -UPB_FORCEINLINE -static const char* _upb_Decoder_DecodeWireValue(upb_Decoder* d, const char* ptr, - const upb_MiniTable* mt, - const upb_MiniTableField* field, - int wire_type, wireval* val, - int* op) { - static const unsigned kFixed32OkMask = (1 << kUpb_FieldType_Float) | - (1 << kUpb_FieldType_Fixed32) | - (1 << kUpb_FieldType_SFixed32); - static const unsigned kFixed64OkMask = (1 << kUpb_FieldType_Double) | - (1 << kUpb_FieldType_Fixed64) | - (1 << kUpb_FieldType_SFixed64); +#include - switch (wire_type) { - case kUpb_WireType_Varint: - ptr = _upb_Decoder_DecodeVarint(d, ptr, &val->uint64_val); - *op = _upb_Decoder_GetVarintOp(field); - _upb_Decoder_Munge(field->UPB_PRIVATE(descriptortype), val); - return ptr; - case kUpb_WireType_32Bit: - *op = kUpb_DecodeOp_Scalar4Byte; - if (((1 << field->UPB_PRIVATE(descriptortype)) & kFixed32OkMask) == 0) { - *op = kUpb_DecodeOp_UnknownField; - } - return upb_WireReader_ReadFixed32(ptr, &val->uint32_val); - case kUpb_WireType_64Bit: - *op = kUpb_DecodeOp_Scalar8Byte; - if (((1 << field->UPB_PRIVATE(descriptortype)) & kFixed64OkMask) == 0) { - *op = kUpb_DecodeOp_UnknownField; - } - return upb_WireReader_ReadFixed64(ptr, &val->uint64_val); - case kUpb_WireType_Delimited: - ptr = upb_Decoder_DecodeSize(d, ptr, &val->size); - *op = _upb_Decoder_GetDelimitedOp(d, mt, field); - return ptr; - case kUpb_WireType_StartGroup: - val->uint32_val = field->UPB_PRIVATE(number); - if (field->UPB_PRIVATE(descriptortype) == kUpb_FieldType_Group) { - *op = kUpb_DecodeOp_SubMessage; - _upb_Decoder_CheckUnlinked(d, mt, field, op); - } else if (field->UPB_PRIVATE(descriptortype) == - kUpb_FakeFieldType_MessageSetItem) { - *op = kUpb_DecodeOp_MessageSetItem; - } else { - *op = kUpb_DecodeOp_UnknownField; - } - return ptr; - default: - break; - } - _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_Malformed); -} -UPB_FORCEINLINE -static const char* _upb_Decoder_DecodeKnownField( - upb_Decoder* d, const char* ptr, upb_Message* msg, - const upb_MiniTable* layout, const upb_MiniTableField* field, int op, - wireval* val) { - const upb_MiniTableSub* subs = layout->UPB_PRIVATE(subs); - uint8_t mode = field->UPB_PRIVATE(mode); +// Must be last. - if (UPB_UNLIKELY(mode & kUpb_LabelFlags_IsExtension)) { - const upb_MiniTableExtension* ext_layout = - (const upb_MiniTableExtension*)field; - upb_Extension* ext = - _upb_Message_GetOrCreateExtension(msg, ext_layout, &d->arena); - if (UPB_UNLIKELY(!ext)) { - _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_OutOfMemory); - } - d->unknown_msg = msg; - msg = (upb_Message*)&ext->data; - subs = &ext->ext->UPB_PRIVATE(sub); - } +/* The upb core does not generally have a concept of default instances. However + * for descriptor options we make an exception since the max size is known and + * modest (<200 bytes). All types can share a default instance since it is + * initialized to zeroes. + * + * We have to allocate an extra pointer for upb's internal metadata. */ +static UPB_ALIGN_AS(8) const + char opt_default_buf[_UPB_MAXOPT_SIZE + sizeof(void*)] = {0}; +const char* kUpbDefOptDefault = &opt_default_buf[sizeof(void*)]; - switch (mode & kUpb_FieldMode_Mask) { - case kUpb_FieldMode_Array: - return _upb_Decoder_DecodeToArray(d, ptr, msg, subs, field, val, op); - case kUpb_FieldMode_Map: - return _upb_Decoder_DecodeToMap(d, ptr, msg, subs, field, val); - case kUpb_FieldMode_Scalar: - return _upb_Decoder_DecodeToSubMessage(d, ptr, msg, subs, field, val, op); - default: - UPB_UNREACHABLE(); +const char* _upb_DefBuilder_FullToShort(const char* fullname) { + const char* p; + + if (fullname == NULL) { + return NULL; + } else if ((p = strrchr(fullname, '.')) == NULL) { + /* No '.' in the name, return the full string. */ + return fullname; + } else { + /* Return one past the last '.'. */ + return p + 1; } } -static const char* _upb_Decoder_ReverseSkipVarint(const char* ptr, - uint32_t val) { - uint32_t seen = 0; - do { - ptr--; - seen <<= 7; - seen |= *ptr & 0x7f; - } while (seen != val); - return ptr; +void _upb_DefBuilder_FailJmp(upb_DefBuilder* ctx) { UPB_LONGJMP(ctx->err, 1); } + +void _upb_DefBuilder_Errf(upb_DefBuilder* ctx, const char* fmt, ...) { + va_list argp; + va_start(argp, fmt); + upb_Status_VSetErrorFormat(ctx->status, fmt, argp); + va_end(argp); + _upb_DefBuilder_FailJmp(ctx); } -static const char* _upb_Decoder_DecodeUnknownField(upb_Decoder* d, - const char* ptr, - upb_Message* msg, - int field_number, - int wire_type, wireval val) { - if (field_number == 0) _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_Malformed); +void _upb_DefBuilder_OomErr(upb_DefBuilder* ctx) { + upb_Status_SetErrorMessage(ctx->status, "out of memory"); + _upb_DefBuilder_FailJmp(ctx); +} - // Since unknown fields are the uncommon case, we do a little extra work here - // to walk backwards through the buffer to find the field start. This frees - // up a register in the fast paths (when the field is known), which leads to - // significant speedups in benchmarks. - const char* start = ptr; +// Verify a relative identifier string. The loop is branchless for speed. +static void _upb_DefBuilder_CheckIdentNotFull(upb_DefBuilder* ctx, + upb_StringView name) { + bool good = name.size > 0; - if (wire_type == kUpb_WireType_Delimited) ptr += val.size; - if (msg) { - switch (wire_type) { - case kUpb_WireType_Varint: - case kUpb_WireType_Delimited: - start--; - while (start[-1] & 0x80) start--; - break; - case kUpb_WireType_32Bit: - start -= 4; - break; - case kUpb_WireType_64Bit: - start -= 8; - break; - default: - break; + for (size_t i = 0; i < name.size; i++) { + const char c = name.data[i]; + const char d = c | 0x20; // force lowercase + const bool is_alpha = (('a' <= d) & (d <= 'z')) | (c == '_'); + const bool is_numer = ('0' <= c) & (c <= '9') & (i != 0); + + good &= is_alpha | is_numer; + } + + if (!good) _upb_DefBuilder_CheckIdentSlow(ctx, name, false); +} + +const char* _upb_DefBuilder_MakeFullName(upb_DefBuilder* ctx, + const char* prefix, + upb_StringView name) { + _upb_DefBuilder_CheckIdentNotFull(ctx, name); + if (prefix) { + // ret = prefix + '.' + name; + size_t n = strlen(prefix); + char* ret = _upb_DefBuilder_Alloc(ctx, n + name.size + 2); + strcpy(ret, prefix); + ret[n] = '.'; + memcpy(&ret[n + 1], name.data, name.size); + ret[n + 1 + name.size] = '\0'; + return ret; + } else { + char* ret = upb_strdup2(name.data, name.size, ctx->arena); + if (!ret) _upb_DefBuilder_OomErr(ctx); + return ret; + } +} + +static bool remove_component(char* base, size_t* len) { + if (*len == 0) return false; + + for (size_t i = *len - 1; i > 0; i--) { + if (base[i] == '.') { + *len = i; + return true; } + } - assert(start == d->debug_valstart); - uint32_t tag = ((uint32_t)field_number << 3) | wire_type; - start = _upb_Decoder_ReverseSkipVarint(start, tag); - assert(start == d->debug_tagstart); + *len = 0; + return true; +} - if (wire_type == kUpb_WireType_StartGroup) { - d->unknown = start; - d->unknown_msg = msg; - ptr = _upb_Decoder_DecodeUnknownGroup(d, ptr, field_number); - start = d->unknown; - d->unknown = NULL; +const void* _upb_DefBuilder_ResolveAny(upb_DefBuilder* ctx, + const char* from_name_dbg, + const char* base, upb_StringView sym, + upb_deftype_t* type) { + if (sym.size == 0) goto notfound; + upb_value v; + if (sym.data[0] == '.') { + // Symbols starting with '.' are absolute, so we do a single lookup. + // Slice to omit the leading '.' + if (!_upb_DefPool_LookupSym(ctx->symtab, sym.data + 1, sym.size - 1, &v)) { + goto notfound; } - if (!UPB_PRIVATE(_upb_Message_AddUnknown)(msg, start, ptr - start, - &d->arena)) { - _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_OutOfMemory); + } else { + // Remove components from base until we find an entry or run out. + size_t baselen = base ? strlen(base) : 0; + char* tmp = upb_gmalloc(sym.size + baselen + 1); + while (1) { + char* p = tmp; + if (baselen) { + memcpy(p, base, baselen); + p[baselen] = '.'; + p += baselen + 1; + } + memcpy(p, sym.data, sym.size); + p += sym.size; + if (_upb_DefPool_LookupSym(ctx->symtab, tmp, p - tmp, &v)) { + break; + } + if (!remove_component(tmp, &baselen)) { + upb_gfree(tmp); + goto notfound; + } } - } else if (wire_type == kUpb_WireType_StartGroup) { - ptr = _upb_Decoder_DecodeUnknownGroup(d, ptr, field_number); + upb_gfree(tmp); } - return ptr; -} -UPB_NOINLINE -static const char* _upb_Decoder_DecodeMessage(upb_Decoder* d, const char* ptr, - upb_Message* msg, - const upb_MiniTable* layout) { - int last_field_index = 0; + *type = _upb_DefType_Type(v); + return _upb_DefType_Unpack(v, *type); -#if UPB_FASTTABLE - // The first time we want to skip fast dispatch, because we may have just been - // invoked by the fast parser to handle a case that it bailed on. - if (!_upb_Decoder_IsDone(d, &ptr)) goto nofast; -#endif +notfound: + _upb_DefBuilder_Errf(ctx, "couldn't resolve name '" UPB_STRINGVIEW_FORMAT "'", + UPB_STRINGVIEW_ARGS(sym)); +} - while (!_upb_Decoder_IsDone(d, &ptr)) { - uint32_t tag; - const upb_MiniTableField* field; - int field_number; - int wire_type; - wireval val; - int op; +const void* _upb_DefBuilder_Resolve(upb_DefBuilder* ctx, + const char* from_name_dbg, const char* base, + upb_StringView sym, upb_deftype_t type) { + upb_deftype_t found_type; + const void* ret = + _upb_DefBuilder_ResolveAny(ctx, from_name_dbg, base, sym, &found_type); + if (ret && found_type != type) { + _upb_DefBuilder_Errf(ctx, + "type mismatch when resolving %s: couldn't find " + "name " UPB_STRINGVIEW_FORMAT " with type=%d", + from_name_dbg, UPB_STRINGVIEW_ARGS(sym), (int)type); + } + return ret; +} - if (_upb_Decoder_TryFastDispatch(d, &ptr, msg, layout)) break; +// Per ASCII this will lower-case a letter. If the result is a letter, the +// input was definitely a letter. If the output is not a letter, this may +// have transformed the character unpredictably. +static char upb_ascii_lower(char ch) { return ch | 0x20; } -#if UPB_FASTTABLE - nofast: -#endif +// isalpha() etc. from are locale-dependent, which we don't want. +static bool upb_isbetween(uint8_t c, uint8_t low, uint8_t high) { + return low <= c && c <= high; +} -#ifndef NDEBUG - d->debug_tagstart = ptr; -#endif +static bool upb_isletter(char c) { + char lower = upb_ascii_lower(c); + return upb_isbetween(lower, 'a', 'z') || c == '_'; +} - UPB_ASSERT(ptr < d->input.limit_ptr); - ptr = _upb_Decoder_DecodeTag(d, ptr, &tag); - field_number = tag >> 3; - wire_type = tag & 7; +static bool upb_isalphanum(char c) { + return upb_isletter(c) || upb_isbetween(c, '0', '9'); +} -#ifndef NDEBUG - d->debug_valstart = ptr; -#endif +static bool TryGetChar(const char** src, const char* end, char* ch) { + if (*src == end) return false; + *ch = **src; + *src += 1; + return true; +} - if (wire_type == kUpb_WireType_EndGroup) { - d->end_group = field_number; - return ptr; - } +static int TryGetHexDigit(const char** src, const char* end) { + char ch; + if (!TryGetChar(src, end, &ch)) return -1; + if ('0' <= ch && ch <= '9') { + return ch - '0'; + } + ch = upb_ascii_lower(ch); + if ('a' <= ch && ch <= 'f') { + return ch - 'a' + 0xa; + } + *src -= 1; // Char wasn't actually a hex digit. + return -1; +} - field = _upb_Decoder_FindField(d, layout, field_number, &last_field_index); - ptr = _upb_Decoder_DecodeWireValue(d, ptr, layout, field, wire_type, &val, - &op); +static char upb_DefBuilder_ParseHexEscape(upb_DefBuilder* ctx, + const upb_FieldDef* f, + const char** src, const char* end) { + int hex_digit = TryGetHexDigit(src, end); + if (hex_digit < 0) { + _upb_DefBuilder_Errf( + ctx, "\\x must be followed by at least one hex digit (field='%s')", + upb_FieldDef_FullName(f)); + return 0; + } + unsigned int ret = hex_digit; + while ((hex_digit = TryGetHexDigit(src, end)) >= 0) { + ret = (ret << 4) | hex_digit; + } + if (ret > 0xff) { + _upb_DefBuilder_Errf(ctx, "Value of hex escape in field %s exceeds 8 bits", + upb_FieldDef_FullName(f)); + return 0; + } + return ret; +} - if (op >= 0) { - ptr = _upb_Decoder_DecodeKnownField(d, ptr, msg, layout, field, op, &val); - } else { - switch (op) { - case kUpb_DecodeOp_UnknownField: - ptr = _upb_Decoder_DecodeUnknownField(d, ptr, msg, field_number, - wire_type, val); - break; - case kUpb_DecodeOp_MessageSetItem: - ptr = upb_Decoder_DecodeMessageSetItem(d, ptr, msg, layout); - break; - } +static char TryGetOctalDigit(const char** src, const char* end) { + char ch; + if (!TryGetChar(src, end, &ch)) return -1; + if ('0' <= ch && ch <= '7') { + return ch - '0'; + } + *src -= 1; // Char wasn't actually an octal digit. + return -1; +} + +static char upb_DefBuilder_ParseOctalEscape(upb_DefBuilder* ctx, + const upb_FieldDef* f, + const char** src, const char* end) { + char ch = 0; + for (int i = 0; i < 3; i++) { + char digit; + if ((digit = TryGetOctalDigit(src, end)) >= 0) { + ch = (ch << 3) | digit; } } - - return UPB_UNLIKELY(layout && layout->UPB_PRIVATE(required_count)) - ? _upb_Decoder_CheckRequired(d, ptr, msg, layout) - : ptr; -} - -const char* _upb_FastDecoder_DecodeGeneric(struct upb_Decoder* d, - const char* ptr, upb_Message* msg, - intptr_t table, uint64_t hasbits, - uint64_t data) { - (void)data; - *(uint32_t*)msg |= hasbits; - return _upb_Decoder_DecodeMessage(d, ptr, msg, decode_totablep(table)); + return ch; +} + +char _upb_DefBuilder_ParseEscape(upb_DefBuilder* ctx, const upb_FieldDef* f, + const char** src, const char* end) { + char ch; + if (!TryGetChar(src, end, &ch)) { + _upb_DefBuilder_Errf(ctx, "unterminated escape sequence in field %s", + upb_FieldDef_FullName(f)); + return 0; + } + switch (ch) { + case 'a': + return '\a'; + case 'b': + return '\b'; + case 'f': + return '\f'; + case 'n': + return '\n'; + case 'r': + return '\r'; + case 't': + return '\t'; + case 'v': + return '\v'; + case '\\': + return '\\'; + case '\'': + return '\''; + case '\"': + return '\"'; + case '?': + return '\?'; + case 'x': + case 'X': + return upb_DefBuilder_ParseHexEscape(ctx, f, src, end); + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + *src -= 1; + return upb_DefBuilder_ParseOctalEscape(ctx, f, src, end); + } + _upb_DefBuilder_Errf(ctx, "Unknown escape sequence: \\%c", ch); } -static upb_DecodeStatus _upb_Decoder_DecodeTop(struct upb_Decoder* d, - const char* buf, void* msg, - const upb_MiniTable* l) { - if (!_upb_Decoder_TryFastDispatch(d, &buf, msg, l)) { - _upb_Decoder_DecodeMessage(d, buf, msg, l); +void _upb_DefBuilder_CheckIdentSlow(upb_DefBuilder* ctx, upb_StringView name, + bool full) { + const char* str = name.data; + const size_t len = name.size; + bool start = true; + for (size_t i = 0; i < len; i++) { + const char c = str[i]; + if (c == '.') { + if (start || !full) { + _upb_DefBuilder_Errf( + ctx, "invalid name: unexpected '.' (" UPB_STRINGVIEW_FORMAT ")", + UPB_STRINGVIEW_ARGS(name)); + } + start = true; + } else if (start) { + if (!upb_isletter(c)) { + _upb_DefBuilder_Errf(ctx, + "invalid name: path components must start with a " + "letter (" UPB_STRINGVIEW_FORMAT ")", + UPB_STRINGVIEW_ARGS(name)); + } + start = false; + } else if (!upb_isalphanum(c)) { + _upb_DefBuilder_Errf( + ctx, + "invalid name: non-alphanumeric character (" UPB_STRINGVIEW_FORMAT + ")", + UPB_STRINGVIEW_ARGS(name)); + } + } + if (start) { + _upb_DefBuilder_Errf(ctx, + "invalid name: empty part (" UPB_STRINGVIEW_FORMAT ")", + UPB_STRINGVIEW_ARGS(name)); } - if (d->end_group != DECODE_NOGROUP) return kUpb_DecodeStatus_Malformed; - if (d->missing_required) return kUpb_DecodeStatus_MissingRequired; - return kUpb_DecodeStatus_Ok; -} -UPB_NOINLINE -const char* _upb_Decoder_IsDoneFallback(upb_EpsCopyInputStream* e, - const char* ptr, int overrun) { - return _upb_EpsCopyInputStream_IsDoneFallbackInline( - e, ptr, overrun, _upb_Decoder_BufferFlipCallback); + // We should never reach this point. + UPB_ASSERT(false); } -static upb_DecodeStatus upb_Decoder_Decode(upb_Decoder* const decoder, - const char* const buf, - void* const msg, - const upb_MiniTable* const l, - upb_Arena* const arena) { - if (UPB_SETJMP(decoder->err) == 0) { - decoder->status = _upb_Decoder_DecodeTop(decoder, buf, msg, l); - } else { - UPB_ASSERT(decoder->status != kUpb_DecodeStatus_Ok); +upb_StringView _upb_DefBuilder_MakeKey(upb_DefBuilder* ctx, + const UPB_DESC(FeatureSet*) parent, + upb_StringView key) { + size_t need = key.size + sizeof(void*); + if (ctx->tmp_buf_size < need) { + ctx->tmp_buf_size = UPB_MAX(64, upb_Log2Ceiling(need)); + ctx->tmp_buf = upb_Arena_Malloc(ctx->tmp_arena, ctx->tmp_buf_size); + if (!ctx->tmp_buf) _upb_DefBuilder_OomErr(ctx); } - UPB_PRIVATE(_upb_Arena_SwapOut)(arena, &decoder->arena); - - return decoder->status; + memcpy(ctx->tmp_buf, &parent, sizeof(void*)); + memcpy(ctx->tmp_buf + sizeof(void*), key.data, key.size); + return upb_StringView_FromDataAndSize(ctx->tmp_buf, need); } -upb_DecodeStatus upb_Decode(const char* buf, size_t size, upb_Message* msg, - const upb_MiniTable* l, - const upb_ExtensionRegistry* extreg, int options, - upb_Arena* arena) { - upb_Decoder decoder; - unsigned depth = (unsigned)options >> 16; - - upb_EpsCopyInputStream_Init(&decoder.input, &buf, size, - options & kUpb_DecodeOption_AliasString); +bool _upb_DefBuilder_GetOrCreateFeatureSet(upb_DefBuilder* ctx, + const UPB_DESC(FeatureSet*) parent, + upb_StringView key, + UPB_DESC(FeatureSet**) set) { + upb_StringView k = _upb_DefBuilder_MakeKey(ctx, parent, key); + upb_value v; + if (upb_strtable_lookup2(&ctx->feature_cache, k.data, k.size, &v)) { + *set = upb_value_getptr(v); + return false; + } - decoder.extreg = extreg; - decoder.unknown = NULL; - decoder.depth = depth ? depth : kUpb_WireFormat_DefaultDepthLimit; - decoder.end_group = DECODE_NOGROUP; - decoder.options = (uint16_t)options; - decoder.missing_required = false; - decoder.status = kUpb_DecodeStatus_Ok; + *set = (UPB_DESC(FeatureSet*))upb_Message_DeepClone( + UPB_UPCAST(parent), UPB_DESC_MINITABLE(FeatureSet), ctx->arena); + if (!*set) _upb_DefBuilder_OomErr(ctx); - // Violating the encapsulation of the arena for performance reasons. - // This is a temporary arena that we swap into and swap out of when we are - // done. The temporary arena only needs to be able to handle allocation, - // not fuse or free, so it does not need many of the members to be initialized - // (particularly parent_or_count). - UPB_PRIVATE(_upb_Arena_SwapIn)(&decoder.arena, arena); + v = upb_value_ptr(*set); + if (!upb_strtable_insert(&ctx->feature_cache, k.data, k.size, v, + ctx->tmp_arena)) { + _upb_DefBuilder_OomErr(ctx); + } - return upb_Decoder_Decode(&decoder, buf, msg, l, arena); + return true; } -#undef OP_FIXPCK_LG2 -#undef OP_VARPCK_LG2 - -// We encode backwards, to avoid pre-computing lengths (one-pass encode). - - -#include -#include -#include -#include - - -// Must be last. - -#define UPB_PB_VARINT_MAX_LEN 10 - -UPB_NOINLINE -static size_t encode_varint64(uint64_t val, char* buf) { - size_t i = 0; - do { - uint8_t byte = val & 0x7fU; - val >>= 7; - if (val) byte |= 0x80U; - buf[i++] = byte; - } while (val); - return i; -} +const UPB_DESC(FeatureSet*) + _upb_DefBuilder_DoResolveFeatures(upb_DefBuilder* ctx, + const UPB_DESC(FeatureSet*) parent, + const UPB_DESC(FeatureSet*) child, + bool is_implicit) { + assert(parent); + if (!child) return parent; -static uint32_t encode_zz32(int32_t n) { - return ((uint32_t)n << 1) ^ (n >> 31); -} -static uint64_t encode_zz64(int64_t n) { - return ((uint64_t)n << 1) ^ (n >> 63); -} + if (child && !is_implicit && + upb_FileDef_Syntax(ctx->file) != kUpb_Syntax_Editions) { + _upb_DefBuilder_Errf(ctx, "Features can only be specified for editions"); + } -typedef struct { - upb_EncodeStatus status; - jmp_buf err; - upb_Arena* arena; - char *buf, *ptr, *limit; - int options; - int depth; - _upb_mapsorter sorter; -} upb_encstate; + UPB_DESC(FeatureSet*) resolved; + size_t child_size; + const char* child_bytes = + UPB_DESC(FeatureSet_serialize)(child, ctx->tmp_arena, &child_size); + if (!child_bytes) _upb_DefBuilder_OomErr(ctx); -static size_t upb_roundup_pow2(size_t bytes) { - size_t ret = 128; - while (ret < bytes) { - ret *= 2; + upb_StringView key = upb_StringView_FromDataAndSize(child_bytes, child_size); + if (!_upb_DefBuilder_GetOrCreateFeatureSet(ctx, parent, key, &resolved)) { + return resolved; } - return ret; -} -UPB_NORETURN static void encode_err(upb_encstate* e, upb_EncodeStatus s) { - UPB_ASSERT(s != kUpb_EncodeStatus_Ok); - e->status = s; - UPB_LONGJMP(e->err, 1); -} + upb_DecodeStatus dec_status = + upb_Decode(child_bytes, child_size, UPB_UPCAST(resolved), + UPB_DESC_MINITABLE(FeatureSet), NULL, 0, ctx->arena); + if (dec_status != kUpb_DecodeStatus_Ok) _upb_DefBuilder_OomErr(ctx); -UPB_NOINLINE -static void encode_growbuffer(upb_encstate* e, size_t bytes) { - size_t old_size = e->limit - e->buf; - size_t new_size = upb_roundup_pow2(bytes + (e->limit - e->ptr)); - char* new_buf = upb_Arena_Realloc(e->arena, e->buf, old_size, new_size); + return resolved; +} - if (!new_buf) encode_err(e, kUpb_EncodeStatus_OutOfMemory); - // We want previous data at the end, realloc() put it at the beginning. - // TODO: This is somewhat inefficient since we are copying twice. - // Maybe create a realloc() that copies to the end of the new buffer? - if (old_size > 0) { - memmove(new_buf + new_size - old_size, e->buf, old_size); - } +#include - e->ptr = new_buf + new_size - (e->limit - e->ptr); - e->limit = new_buf + new_size; - e->buf = new_buf; - e->ptr -= bytes; -} +// Must be last. -/* Call to ensure that at least "bytes" bytes are available for writing at - * e->ptr. Returns false if the bytes could not be allocated. */ -UPB_FORCEINLINE -static void encode_reserve(upb_encstate* e, size_t bytes) { - if ((size_t)(e->ptr - e->buf) < bytes) { - encode_growbuffer(e, bytes); - return; - } +char* upb_strdup2(const char* s, size_t len, upb_Arena* a) { + size_t n; + char* p; - e->ptr -= bytes; -} + // Prevent overflow errors. + if (len == SIZE_MAX) return NULL; -/* Writes the given bytes to the buffer, handling reserve/advance. */ -static void encode_bytes(upb_encstate* e, const void* data, size_t len) { - if (len == 0) return; /* memcpy() with zero size is UB */ - encode_reserve(e, len); - memcpy(e->ptr, data, len); + // Always null-terminate, even if binary data; but don't rely on the input to + // have a null-terminating byte since it may be a raw binary buffer. + n = len + 1; + p = upb_Arena_Malloc(a, n); + if (p) { + if (len != 0) memcpy(p, s, len); + p[len] = 0; + } + return p; } -static void encode_fixed64(upb_encstate* e, uint64_t val) { - val = UPB_PRIVATE(_upb_BigEndian64)(val); - encode_bytes(e, &val, sizeof(uint64_t)); -} -static void encode_fixed32(upb_encstate* e, uint32_t val) { - val = UPB_PRIVATE(_upb_BigEndian32)(val); - encode_bytes(e, &val, sizeof(uint32_t)); -} +#include +#include -UPB_NOINLINE -static void encode_longvarint(upb_encstate* e, uint64_t val) { - size_t len; - char* start; - encode_reserve(e, UPB_PB_VARINT_MAX_LEN); - len = encode_varint64(val, e->ptr); - start = e->ptr + UPB_PB_VARINT_MAX_LEN - len; - memmove(start, e->ptr, len); - e->ptr = start; +// Must be last. + +bool upb_Message_HasFieldByDef(const upb_Message* msg, const upb_FieldDef* f) { + UPB_ASSERT(upb_FieldDef_HasPresence(f)); + return upb_Message_HasField(msg, upb_FieldDef_MiniTable(f)); } -UPB_FORCEINLINE -static void encode_varint(upb_encstate* e, uint64_t val) { - if (val < 128 && e->ptr != e->buf) { - --e->ptr; - *e->ptr = val; +const upb_FieldDef* upb_Message_WhichOneof(const upb_Message* msg, + const upb_OneofDef* o) { + const upb_FieldDef* f = upb_OneofDef_Field(o, 0); + if (upb_OneofDef_IsSynthetic(o)) { + UPB_ASSERT(upb_OneofDef_FieldCount(o) == 1); + return upb_Message_HasFieldByDef(msg, f) ? f : NULL; } else { - encode_longvarint(e, val); + const upb_MiniTableField* field = upb_FieldDef_MiniTable(f); + uint32_t oneof_case = upb_Message_WhichOneofFieldNumber(msg, field); + f = oneof_case ? upb_OneofDef_LookupNumber(o, oneof_case) : NULL; + UPB_ASSERT((f != NULL) == (oneof_case != 0)); + return f; } } -static void encode_double(upb_encstate* e, double d) { - uint64_t u64; - UPB_ASSERT(sizeof(double) == sizeof(uint64_t)); - memcpy(&u64, &d, sizeof(uint64_t)); - encode_fixed64(e, u64); -} - -static void encode_float(upb_encstate* e, float d) { - uint32_t u32; - UPB_ASSERT(sizeof(float) == sizeof(uint32_t)); - memcpy(&u32, &d, sizeof(uint32_t)); - encode_fixed32(e, u32); -} - -static void encode_tag(upb_encstate* e, uint32_t field_number, - uint8_t wire_type) { - encode_varint(e, (field_number << 3) | wire_type); +upb_MessageValue upb_Message_GetFieldByDef(const upb_Message* msg, + const upb_FieldDef* f) { + upb_MessageValue default_val = upb_FieldDef_Default(f); + return upb_Message_GetField(msg, upb_FieldDef_MiniTable(f), default_val); } -static void encode_fixedarray(upb_encstate* e, const upb_Array* arr, - size_t elem_size, uint32_t tag) { - size_t bytes = arr->UPB_PRIVATE(size) * elem_size; - const char* data = _upb_array_constptr(arr); - const char* ptr = data + bytes - elem_size; +upb_MutableMessageValue upb_Message_Mutable(upb_Message* msg, + const upb_FieldDef* f, + upb_Arena* a) { + UPB_ASSERT(upb_FieldDef_IsSubMessage(f) || upb_FieldDef_IsRepeated(f)); + if (upb_FieldDef_HasPresence(f) && !upb_Message_HasFieldByDef(msg, f)) { + // We need to skip the upb_Message_GetFieldByDef() call in this case. + goto make; + } - if (tag || !UPB_PRIVATE(_upb_IsLittleEndian)()) { - while (true) { - if (elem_size == 4) { - uint32_t val; - memcpy(&val, ptr, sizeof(val)); - val = UPB_PRIVATE(_upb_BigEndian32)(val); - encode_bytes(e, &val, elem_size); - } else { - UPB_ASSERT(elem_size == 8); - uint64_t val; - memcpy(&val, ptr, sizeof(val)); - val = UPB_PRIVATE(_upb_BigEndian64)(val); - encode_bytes(e, &val, elem_size); - } + upb_MessageValue val = upb_Message_GetFieldByDef(msg, f); + if (val.array_val) { + return (upb_MutableMessageValue){.array = (upb_Array*)val.array_val}; + } - if (tag) encode_varint(e, tag); - if (ptr == data) break; - ptr -= elem_size; - } + upb_MutableMessageValue ret; +make: + if (!a) return (upb_MutableMessageValue){.array = NULL}; + if (upb_FieldDef_IsMap(f)) { + const upb_MessageDef* entry = upb_FieldDef_MessageSubDef(f); + const upb_FieldDef* key = + upb_MessageDef_FindFieldByNumber(entry, kUpb_MapEntry_KeyFieldNumber); + const upb_FieldDef* value = + upb_MessageDef_FindFieldByNumber(entry, kUpb_MapEntry_ValueFieldNumber); + ret.map = + upb_Map_New(a, upb_FieldDef_CType(key), upb_FieldDef_CType(value)); + } else if (upb_FieldDef_IsRepeated(f)) { + ret.array = upb_Array_New(a, upb_FieldDef_CType(f)); } else { - encode_bytes(e, data, bytes); + UPB_ASSERT(upb_FieldDef_IsSubMessage(f)); + const upb_MessageDef* m = upb_FieldDef_MessageSubDef(f); + ret.msg = upb_Message_New(upb_MessageDef_MiniTable(m), a); } + + val.array_val = ret.array; + upb_Message_SetFieldByDef(msg, f, val, a); + + return ret; } -static void encode_message(upb_encstate* e, const upb_Message* msg, - const upb_MiniTable* m, size_t* size); +bool upb_Message_SetFieldByDef(upb_Message* msg, const upb_FieldDef* f, + upb_MessageValue val, upb_Arena* a) { + return upb_Message_SetField(msg, upb_FieldDef_MiniTable(f), val, a); +} -static void encode_TaggedMessagePtr(upb_encstate* e, - upb_TaggedMessagePtr tagged, - const upb_MiniTable* m, size_t* size) { - if (upb_TaggedMessagePtr_IsEmpty(tagged)) { - m = UPB_PRIVATE(_upb_MiniTable_Empty)(); - } - encode_message(e, UPB_PRIVATE(_upb_TaggedMessagePtr_GetMessage)(tagged), m, - size); +void upb_Message_ClearFieldByDef(upb_Message* msg, const upb_FieldDef* f) { + upb_Message_ClearField(msg, upb_FieldDef_MiniTable(f)); } -static void encode_scalar(upb_encstate* e, const void* _field_mem, - const upb_MiniTableSub* subs, - const upb_MiniTableField* f) { - const char* field_mem = _field_mem; - int wire_type; +void upb_Message_ClearByDef(upb_Message* msg, const upb_MessageDef* m) { + upb_Message_Clear(msg, upb_MessageDef_MiniTable(m)); +} -#define CASE(ctype, type, wtype, encodeval) \ - { \ - ctype val = *(ctype*)field_mem; \ - encode_##type(e, encodeval); \ - wire_type = wtype; \ - break; \ - } +bool upb_Message_Next(const upb_Message* msg, const upb_MessageDef* m, + const upb_DefPool* ext_pool, const upb_FieldDef** out_f, + upb_MessageValue* out_val, size_t* iter) { + size_t i = *iter; + size_t n = upb_MessageDef_FieldCount(m); + UPB_UNUSED(ext_pool); - switch (f->UPB_PRIVATE(descriptortype)) { - case kUpb_FieldType_Double: - CASE(double, double, kUpb_WireType_64Bit, val); - case kUpb_FieldType_Float: - CASE(float, float, kUpb_WireType_32Bit, val); - case kUpb_FieldType_Int64: - case kUpb_FieldType_UInt64: - CASE(uint64_t, varint, kUpb_WireType_Varint, val); - case kUpb_FieldType_UInt32: - CASE(uint32_t, varint, kUpb_WireType_Varint, val); - case kUpb_FieldType_Int32: - case kUpb_FieldType_Enum: - CASE(int32_t, varint, kUpb_WireType_Varint, (int64_t)val); - case kUpb_FieldType_SFixed64: - case kUpb_FieldType_Fixed64: - CASE(uint64_t, fixed64, kUpb_WireType_64Bit, val); - case kUpb_FieldType_Fixed32: - case kUpb_FieldType_SFixed32: - CASE(uint32_t, fixed32, kUpb_WireType_32Bit, val); - case kUpb_FieldType_Bool: - CASE(bool, varint, kUpb_WireType_Varint, val); - case kUpb_FieldType_SInt32: - CASE(int32_t, varint, kUpb_WireType_Varint, encode_zz32(val)); - case kUpb_FieldType_SInt64: - CASE(int64_t, varint, kUpb_WireType_Varint, encode_zz64(val)); - case kUpb_FieldType_String: - case kUpb_FieldType_Bytes: { - upb_StringView view = *(upb_StringView*)field_mem; - encode_bytes(e, view.data, view.size); - encode_varint(e, view.size); - wire_type = kUpb_WireType_Delimited; - break; - } - case kUpb_FieldType_Group: { - size_t size; - upb_TaggedMessagePtr submsg = *(upb_TaggedMessagePtr*)field_mem; - const upb_MiniTable* subm = - upb_MiniTableSub_Message(subs[f->UPB_PRIVATE(submsg_index)]); - if (submsg == 0) { - return; + // Iterate over normal fields, returning the first one that is set. + while (++i < n) { + const upb_FieldDef* f = upb_MessageDef_Field(m, i); + const upb_MiniTableField* field = upb_FieldDef_MiniTable(f); + upb_MessageValue val = upb_Message_GetFieldByDef(msg, f); + + // Skip field if unset or empty. + if (upb_MiniTableField_HasPresence(field)) { + if (!upb_Message_HasFieldByDef(msg, f)) continue; + } else { + switch (UPB_PRIVATE(_upb_MiniTableField_Mode)(field)) { + case kUpb_FieldMode_Map: + if (!val.map_val || upb_Map_Size(val.map_val) == 0) continue; + break; + case kUpb_FieldMode_Array: + if (!val.array_val || upb_Array_Size(val.array_val) == 0) continue; + break; + case kUpb_FieldMode_Scalar: + if (UPB_PRIVATE(_upb_MiniTableField_DataIsZero)(field, &val)) + continue; + break; } - if (--e->depth == 0) encode_err(e, kUpb_EncodeStatus_MaxDepthExceeded); - encode_tag(e, f->UPB_PRIVATE(number), kUpb_WireType_EndGroup); - encode_TaggedMessagePtr(e, submsg, subm, &size); - wire_type = kUpb_WireType_StartGroup; - e->depth++; - break; } - case kUpb_FieldType_Message: { - size_t size; - upb_TaggedMessagePtr submsg = *(upb_TaggedMessagePtr*)field_mem; - const upb_MiniTable* subm = - upb_MiniTableSub_Message(subs[f->UPB_PRIVATE(submsg_index)]); - if (submsg == 0) { - return; - } - if (--e->depth == 0) encode_err(e, kUpb_EncodeStatus_MaxDepthExceeded); - encode_TaggedMessagePtr(e, submsg, subm, &size); - encode_varint(e, size); - wire_type = kUpb_WireType_Delimited; - e->depth++; - break; + + *out_val = val; + *out_f = f; + *iter = i; + return true; + } + + if (ext_pool) { + // Return any extensions that are set. + size_t count; + const upb_Extension* ext = UPB_PRIVATE(_upb_Message_Getexts)(msg, &count); + if (i - n < count) { + ext += count - 1 - (i - n); + memcpy(out_val, &ext->data, sizeof(*out_val)); + *out_f = upb_DefPool_FindExtensionByMiniTable(ext_pool, ext->ext); + *iter = i; + return true; } - default: - UPB_UNREACHABLE(); } -#undef CASE - encode_tag(e, f->UPB_PRIVATE(number), wire_type); + *iter = i; + return false; } -static void encode_array(upb_encstate* e, const upb_Message* msg, - const upb_MiniTableSub* subs, - const upb_MiniTableField* f) { - const upb_Array* arr = *UPB_PTR_AT(msg, f->UPB_PRIVATE(offset), upb_Array*); - bool packed = upb_MiniTableField_IsPacked(f); - size_t pre_len = e->limit - e->ptr; +bool _upb_Message_DiscardUnknown(upb_Message* msg, const upb_MessageDef* m, + int depth) { + size_t iter = kUpb_Message_Begin; + const upb_FieldDef* f; + upb_MessageValue val; + bool ret = true; - if (arr == NULL || arr->UPB_PRIVATE(size) == 0) { - return; - } + if (--depth == 0) return false; -#define VARINT_CASE(ctype, encode) \ - { \ - const ctype* start = _upb_array_constptr(arr); \ - const ctype* ptr = start + arr->UPB_PRIVATE(size); \ - uint32_t tag = \ - packed ? 0 : (f->UPB_PRIVATE(number) << 3) | kUpb_WireType_Varint; \ - do { \ - ptr--; \ - encode_varint(e, encode); \ - if (tag) encode_varint(e, tag); \ - } while (ptr != start); \ - } \ - break; + _upb_Message_DiscardUnknown_shallow(msg); -#define TAG(wire_type) (packed ? 0 : (f->UPB_PRIVATE(number) << 3 | wire_type)) + while (upb_Message_Next(msg, m, NULL /*ext_pool*/, &f, &val, &iter)) { + const upb_MessageDef* subm = upb_FieldDef_MessageSubDef(f); + if (!subm) continue; + if (upb_FieldDef_IsMap(f)) { + const upb_FieldDef* val_f = upb_MessageDef_FindFieldByNumber(subm, 2); + const upb_MessageDef* val_m = upb_FieldDef_MessageSubDef(val_f); + upb_Map* map = (upb_Map*)val.map_val; + size_t iter = kUpb_Map_Begin; - switch (f->UPB_PRIVATE(descriptortype)) { - case kUpb_FieldType_Double: - encode_fixedarray(e, arr, sizeof(double), TAG(kUpb_WireType_64Bit)); - break; - case kUpb_FieldType_Float: - encode_fixedarray(e, arr, sizeof(float), TAG(kUpb_WireType_32Bit)); - break; - case kUpb_FieldType_SFixed64: - case kUpb_FieldType_Fixed64: - encode_fixedarray(e, arr, sizeof(uint64_t), TAG(kUpb_WireType_64Bit)); - break; - case kUpb_FieldType_Fixed32: - case kUpb_FieldType_SFixed32: - encode_fixedarray(e, arr, sizeof(uint32_t), TAG(kUpb_WireType_32Bit)); - break; - case kUpb_FieldType_Int64: - case kUpb_FieldType_UInt64: - VARINT_CASE(uint64_t, *ptr); - case kUpb_FieldType_UInt32: - VARINT_CASE(uint32_t, *ptr); - case kUpb_FieldType_Int32: - case kUpb_FieldType_Enum: - VARINT_CASE(int32_t, (int64_t)*ptr); - case kUpb_FieldType_Bool: - VARINT_CASE(bool, *ptr); - case kUpb_FieldType_SInt32: - VARINT_CASE(int32_t, encode_zz32(*ptr)); - case kUpb_FieldType_SInt64: - VARINT_CASE(int64_t, encode_zz64(*ptr)); - case kUpb_FieldType_String: - case kUpb_FieldType_Bytes: { - const upb_StringView* start = _upb_array_constptr(arr); - const upb_StringView* ptr = start + arr->UPB_PRIVATE(size); - do { - ptr--; - encode_bytes(e, ptr->data, ptr->size); - encode_varint(e, ptr->size); - encode_tag(e, f->UPB_PRIVATE(number), kUpb_WireType_Delimited); - } while (ptr != start); - return; - } - case kUpb_FieldType_Group: { - const upb_TaggedMessagePtr* start = _upb_array_constptr(arr); - const upb_TaggedMessagePtr* ptr = start + arr->UPB_PRIVATE(size); - const upb_MiniTable* subm = - upb_MiniTableSub_Message(subs[f->UPB_PRIVATE(submsg_index)]); - if (--e->depth == 0) encode_err(e, kUpb_EncodeStatus_MaxDepthExceeded); - do { - size_t size; - ptr--; - encode_tag(e, f->UPB_PRIVATE(number), kUpb_WireType_EndGroup); - encode_TaggedMessagePtr(e, *ptr, subm, &size); - encode_tag(e, f->UPB_PRIVATE(number), kUpb_WireType_StartGroup); - } while (ptr != start); - e->depth++; - return; - } - case kUpb_FieldType_Message: { - const upb_TaggedMessagePtr* start = _upb_array_constptr(arr); - const upb_TaggedMessagePtr* ptr = start + arr->UPB_PRIVATE(size); - const upb_MiniTable* subm = - upb_MiniTableSub_Message(subs[f->UPB_PRIVATE(submsg_index)]); - if (--e->depth == 0) encode_err(e, kUpb_EncodeStatus_MaxDepthExceeded); - do { - size_t size; - ptr--; - encode_TaggedMessagePtr(e, *ptr, subm, &size); - encode_varint(e, size); - encode_tag(e, f->UPB_PRIVATE(number), kUpb_WireType_Delimited); - } while (ptr != start); - e->depth++; - return; + if (!val_m) continue; + + upb_MessageValue map_key, map_val; + while (upb_Map_Next(map, &map_key, &map_val, &iter)) { + if (!_upb_Message_DiscardUnknown((upb_Message*)map_val.msg_val, val_m, + depth)) { + ret = false; + } + } + } else if (upb_FieldDef_IsRepeated(f)) { + const upb_Array* arr = val.array_val; + size_t i, n = upb_Array_Size(arr); + for (i = 0; i < n; i++) { + upb_MessageValue elem = upb_Array_Get(arr, i); + if (!_upb_Message_DiscardUnknown((upb_Message*)elem.msg_val, subm, + depth)) { + ret = false; + } + } + } else { + if (!_upb_Message_DiscardUnknown((upb_Message*)val.msg_val, subm, + depth)) { + ret = false; + } } } -#undef VARINT_CASE - if (packed) { - encode_varint(e, e->limit - e->ptr - pre_len); - encode_tag(e, f->UPB_PRIVATE(number), kUpb_WireType_Delimited); - } + return ret; } -static void encode_mapentry(upb_encstate* e, uint32_t number, - const upb_MiniTable* layout, - const upb_MapEntry* ent) { - const upb_MiniTableField* key_field = &layout->UPB_PRIVATE(fields)[0]; - const upb_MiniTableField* val_field = &layout->UPB_PRIVATE(fields)[1]; - size_t pre_len = e->limit - e->ptr; - size_t size; - encode_scalar(e, &ent->data.v, layout->UPB_PRIVATE(subs), val_field); - encode_scalar(e, &ent->data.k, layout->UPB_PRIVATE(subs), key_field); - size = (e->limit - e->ptr) - pre_len; - encode_varint(e, size); - encode_tag(e, number, kUpb_WireType_Delimited); +bool upb_Message_DiscardUnknown(upb_Message* msg, const upb_MessageDef* m, + int maxdepth) { + return _upb_Message_DiscardUnknown(msg, m, maxdepth); } -static void encode_map(upb_encstate* e, const upb_Message* msg, - const upb_MiniTableSub* subs, - const upb_MiniTableField* f) { - const upb_Map* map = *UPB_PTR_AT(msg, f->UPB_PRIVATE(offset), const upb_Map*); - const upb_MiniTable* layout = - upb_MiniTableSub_Message(subs[f->UPB_PRIVATE(submsg_index)]); - UPB_ASSERT(layout->UPB_PRIVATE(field_count) == 2); - if (map == NULL) return; +#include +#include +#include - if (e->options & kUpb_EncodeOption_Deterministic) { - _upb_sortedmap sorted; - _upb_mapsorter_pushmap( - &e->sorter, layout->UPB_PRIVATE(fields)[0].UPB_PRIVATE(descriptortype), - map, &sorted); - upb_MapEntry ent; - while (_upb_sortedmap_next(&e->sorter, map, &sorted, &ent)) { - encode_mapentry(e, f->UPB_PRIVATE(number), layout, &ent); - } - _upb_mapsorter_popmap(&e->sorter, &sorted); + +// Must be last. + +struct upb_MessageDef { + const UPB_DESC(MessageOptions*) opts; + const UPB_DESC(FeatureSet*) resolved_features; + const upb_MiniTable* layout; + const upb_FileDef* file; + const upb_MessageDef* containing_type; + const char* full_name; + + // Tables for looking up fields by number and name. + upb_inttable itof; + upb_strtable ntof; + + // Looking up fields by json name. + upb_strtable jtof; + + /* All nested defs. + * MEM: We could save some space here by putting nested defs in a contiguous + * region and calculating counts from offsets or vice-versa. */ + const upb_FieldDef* fields; + const upb_OneofDef* oneofs; + const upb_ExtensionRange* ext_ranges; + const upb_StringView* res_names; + const upb_MessageDef* nested_msgs; + const upb_MessageReservedRange* res_ranges; + const upb_EnumDef* nested_enums; + const upb_FieldDef* nested_exts; + + // TODO: These counters don't need anywhere near 32 bits. + int field_count; + int real_oneof_count; + int oneof_count; + int ext_range_count; + int res_range_count; + int res_name_count; + int nested_msg_count; + int nested_enum_count; + int nested_ext_count; + bool in_message_set; + bool is_sorted; + upb_WellKnown well_known_type; +#if UINTPTR_MAX == 0xffffffff + uint32_t padding; // Increase size to a multiple of 8. +#endif +}; + +static void assign_msg_wellknowntype(upb_MessageDef* m) { + const char* name = m->full_name; + if (name == NULL) { + m->well_known_type = kUpb_WellKnown_Unspecified; + return; + } + if (!strcmp(name, "google.protobuf.Any")) { + m->well_known_type = kUpb_WellKnown_Any; + } else if (!strcmp(name, "google.protobuf.FieldMask")) { + m->well_known_type = kUpb_WellKnown_FieldMask; + } else if (!strcmp(name, "google.protobuf.Duration")) { + m->well_known_type = kUpb_WellKnown_Duration; + } else if (!strcmp(name, "google.protobuf.Timestamp")) { + m->well_known_type = kUpb_WellKnown_Timestamp; + } else if (!strcmp(name, "google.protobuf.DoubleValue")) { + m->well_known_type = kUpb_WellKnown_DoubleValue; + } else if (!strcmp(name, "google.protobuf.FloatValue")) { + m->well_known_type = kUpb_WellKnown_FloatValue; + } else if (!strcmp(name, "google.protobuf.Int64Value")) { + m->well_known_type = kUpb_WellKnown_Int64Value; + } else if (!strcmp(name, "google.protobuf.UInt64Value")) { + m->well_known_type = kUpb_WellKnown_UInt64Value; + } else if (!strcmp(name, "google.protobuf.Int32Value")) { + m->well_known_type = kUpb_WellKnown_Int32Value; + } else if (!strcmp(name, "google.protobuf.UInt32Value")) { + m->well_known_type = kUpb_WellKnown_UInt32Value; + } else if (!strcmp(name, "google.protobuf.BoolValue")) { + m->well_known_type = kUpb_WellKnown_BoolValue; + } else if (!strcmp(name, "google.protobuf.StringValue")) { + m->well_known_type = kUpb_WellKnown_StringValue; + } else if (!strcmp(name, "google.protobuf.BytesValue")) { + m->well_known_type = kUpb_WellKnown_BytesValue; + } else if (!strcmp(name, "google.protobuf.Value")) { + m->well_known_type = kUpb_WellKnown_Value; + } else if (!strcmp(name, "google.protobuf.ListValue")) { + m->well_known_type = kUpb_WellKnown_ListValue; + } else if (!strcmp(name, "google.protobuf.Struct")) { + m->well_known_type = kUpb_WellKnown_Struct; } else { - intptr_t iter = UPB_STRTABLE_BEGIN; - upb_StringView key; - upb_value val; - while (upb_strtable_next2(&map->table, &key, &val, &iter)) { - upb_MapEntry ent; - _upb_map_fromkey(key, &ent.data.k, map->key_size); - _upb_map_fromvalue(val, &ent.data.v, map->val_size); - encode_mapentry(e, f->UPB_PRIVATE(number), layout, &ent); - } + m->well_known_type = kUpb_WellKnown_Unspecified; } } -static bool encode_shouldencode(upb_encstate* e, const upb_Message* msg, - const upb_MiniTableSub* subs, - const upb_MiniTableField* f) { - if (f->presence == 0) { - // Proto3 presence or map/array. - const void* mem = UPB_PTR_AT(msg, f->UPB_PRIVATE(offset), void); - switch (UPB_PRIVATE(_upb_MiniTableField_GetRep)(f)) { - case kUpb_FieldRep_1Byte: { - char ch; - memcpy(&ch, mem, 1); - return ch != 0; - } - case kUpb_FieldRep_4Byte: { - uint32_t u32; - memcpy(&u32, mem, 4); - return u32 != 0; - } - case kUpb_FieldRep_8Byte: { - uint64_t u64; - memcpy(&u64, mem, 8); - return u64 != 0; - } - case kUpb_FieldRep_StringView: { - const upb_StringView* str = (const upb_StringView*)mem; - return str->size != 0; - } - default: - UPB_UNREACHABLE(); +upb_MessageDef* _upb_MessageDef_At(const upb_MessageDef* m, int i) { + return (upb_MessageDef*)&m[i]; +} + +bool _upb_MessageDef_IsValidExtensionNumber(const upb_MessageDef* m, int n) { + for (int i = 0; i < m->ext_range_count; i++) { + const upb_ExtensionRange* r = upb_MessageDef_ExtensionRange(m, i); + if (upb_ExtensionRange_Start(r) <= n && n < upb_ExtensionRange_End(r)) { + return true; } - } else if (f->presence > 0) { - // Proto2 presence: hasbit. - return UPB_PRIVATE(_upb_Message_GetHasbit)(msg, f); - } else { - // Field is in a oneof. - return UPB_PRIVATE(_upb_Message_GetOneofCase)(msg, f) == - f->UPB_PRIVATE(number); } + return false; } -static void encode_field(upb_encstate* e, const upb_Message* msg, - const upb_MiniTableSub* subs, - const upb_MiniTableField* field) { - switch (UPB_PRIVATE(_upb_MiniTableField_Mode)(field)) { - case kUpb_FieldMode_Array: - encode_array(e, msg, subs, field); - break; - case kUpb_FieldMode_Map: - encode_map(e, msg, subs, field); - break; - case kUpb_FieldMode_Scalar: - encode_scalar(e, UPB_PTR_AT(msg, field->UPB_PRIVATE(offset), void), subs, - field); - break; - default: - UPB_UNREACHABLE(); - } +const UPB_DESC(MessageOptions) * + upb_MessageDef_Options(const upb_MessageDef* m) { + return m->opts; } -static void encode_msgset_item(upb_encstate* e, const upb_Extension* ext) { - size_t size; - encode_tag(e, kUpb_MsgSet_Item, kUpb_WireType_EndGroup); - encode_message(e, ext->data.ptr, - upb_MiniTableExtension_GetSubMessage(ext->ext), &size); - encode_varint(e, size); - encode_tag(e, kUpb_MsgSet_Message, kUpb_WireType_Delimited); - encode_varint(e, upb_MiniTableExtension_Number(ext->ext)); - encode_tag(e, kUpb_MsgSet_TypeId, kUpb_WireType_Varint); - encode_tag(e, kUpb_MsgSet_Item, kUpb_WireType_StartGroup); +bool upb_MessageDef_HasOptions(const upb_MessageDef* m) { + return m->opts != (void*)kUpbDefOptDefault; } -static void encode_ext(upb_encstate* e, const upb_Extension* ext, - bool is_message_set) { - if (UPB_UNLIKELY(is_message_set)) { - encode_msgset_item(e, ext); - } else { - encode_field(e, (upb_Message*)&ext->data, &ext->ext->UPB_PRIVATE(sub), - &ext->ext->UPB_PRIVATE(field)); - } +const UPB_DESC(FeatureSet) * + upb_MessageDef_ResolvedFeatures(const upb_MessageDef* m) { + return m->resolved_features; } -static void encode_message(upb_encstate* e, const upb_Message* msg, - const upb_MiniTable* m, size_t* size) { - size_t pre_len = e->limit - e->ptr; +const char* upb_MessageDef_FullName(const upb_MessageDef* m) { + return m->full_name; +} - if ((e->options & kUpb_EncodeOption_CheckRequired) && - m->UPB_PRIVATE(required_count)) { - uint64_t msg_head; - memcpy(&msg_head, msg, 8); - msg_head = UPB_PRIVATE(_upb_BigEndian64)(msg_head); - if (UPB_PRIVATE(_upb_MiniTable_RequiredMask)(m) & ~msg_head) { - encode_err(e, kUpb_EncodeStatus_MissingRequired); - } - } +const upb_FileDef* upb_MessageDef_File(const upb_MessageDef* m) { + return m->file; +} - if ((e->options & kUpb_EncodeOption_SkipUnknown) == 0) { - size_t unknown_size; - const char* unknown = upb_Message_GetUnknown(msg, &unknown_size); +const upb_MessageDef* upb_MessageDef_ContainingType(const upb_MessageDef* m) { + return m->containing_type; +} - if (unknown) { - encode_bytes(e, unknown, unknown_size); - } - } +const char* upb_MessageDef_Name(const upb_MessageDef* m) { + return _upb_DefBuilder_FullToShort(m->full_name); +} - if (m->UPB_PRIVATE(ext) != kUpb_ExtMode_NonExtendable) { - /* Encode all extensions together. Unlike C++, we do not attempt to keep - * these in field number order relative to normal fields or even to each - * other. */ - size_t ext_count; - const upb_Extension* ext = - UPB_PRIVATE(_upb_Message_Getexts)(msg, &ext_count); - if (ext_count) { - if (e->options & kUpb_EncodeOption_Deterministic) { - _upb_sortedmap sorted; - _upb_mapsorter_pushexts(&e->sorter, ext, ext_count, &sorted); - while (_upb_sortedmap_nextext(&e->sorter, &sorted, &ext)) { - encode_ext(e, ext, m->UPB_PRIVATE(ext) == kUpb_ExtMode_IsMessageSet); - } - _upb_mapsorter_popmap(&e->sorter, &sorted); - } else { - const upb_Extension* end = ext + ext_count; - for (; ext != end; ext++) { - encode_ext(e, ext, m->UPB_PRIVATE(ext) == kUpb_ExtMode_IsMessageSet); - } - } - } - } +upb_Syntax upb_MessageDef_Syntax(const upb_MessageDef* m) { + return upb_FileDef_Syntax(m->file); +} - if (m->UPB_PRIVATE(field_count)) { - const upb_MiniTableField* f = - &m->UPB_PRIVATE(fields)[m->UPB_PRIVATE(field_count)]; - const upb_MiniTableField* first = &m->UPB_PRIVATE(fields)[0]; - while (f != first) { - f--; - if (encode_shouldencode(e, msg, m->UPB_PRIVATE(subs), f)) { - encode_field(e, msg, m->UPB_PRIVATE(subs), f); - } - } +const upb_FieldDef* upb_MessageDef_FindFieldByNumber(const upb_MessageDef* m, + uint32_t i) { + upb_value val; + return upb_inttable_lookup(&m->itof, i, &val) ? upb_value_getconstptr(val) + : NULL; +} + +const upb_FieldDef* upb_MessageDef_FindFieldByNameWithSize( + const upb_MessageDef* m, const char* name, size_t size) { + upb_value val; + + if (!upb_strtable_lookup2(&m->ntof, name, size, &val)) { + return NULL; } - *size = (e->limit - e->ptr) - pre_len; + return _upb_DefType_Unpack(val, UPB_DEFTYPE_FIELD); } -static upb_EncodeStatus upb_Encoder_Encode(upb_encstate* const encoder, - const upb_Message* const msg, - const upb_MiniTable* const l, - char** const buf, - size_t* const size) { - // Unfortunately we must continue to perform hackery here because there are - // code paths which blindly copy the returned pointer without bothering to - // check for errors until much later (b/235839510). So we still set *buf to - // NULL on error and we still set it to non-NULL on a successful empty result. - if (UPB_SETJMP(encoder->err) == 0) { - encode_message(encoder, msg, l, size); - *size = encoder->limit - encoder->ptr; - if (*size == 0) { - static char ch; - *buf = &ch; - } else { - UPB_ASSERT(encoder->ptr); - *buf = encoder->ptr; - } - } else { - UPB_ASSERT(encoder->status != kUpb_EncodeStatus_Ok); - *buf = NULL; - *size = 0; +const upb_OneofDef* upb_MessageDef_FindOneofByNameWithSize( + const upb_MessageDef* m, const char* name, size_t size) { + upb_value val; + + if (!upb_strtable_lookup2(&m->ntof, name, size, &val)) { + return NULL; } - _upb_mapsorter_destroy(&encoder->sorter); - return encoder->status; + return _upb_DefType_Unpack(val, UPB_DEFTYPE_ONEOF); } -upb_EncodeStatus upb_Encode(const upb_Message* msg, const upb_MiniTable* l, - int options, upb_Arena* arena, char** buf, - size_t* size) { - upb_encstate e; - unsigned depth = (unsigned)options >> 16; +bool _upb_MessageDef_Insert(upb_MessageDef* m, const char* name, size_t len, + upb_value v, upb_Arena* a) { + return upb_strtable_insert(&m->ntof, name, len, v, a); +} - e.status = kUpb_EncodeStatus_Ok; - e.arena = arena; - e.buf = NULL; - e.limit = NULL; - e.ptr = NULL; - e.depth = depth ? depth : kUpb_WireFormat_DefaultDepthLimit; - e.options = options; - _upb_mapsorter_init(&e.sorter); +bool upb_MessageDef_FindByNameWithSize(const upb_MessageDef* m, + const char* name, size_t len, + const upb_FieldDef** out_f, + const upb_OneofDef** out_o) { + upb_value val; - return upb_Encoder_Encode(&e, msg, l, buf, size); + if (!upb_strtable_lookup2(&m->ntof, name, len, &val)) { + return false; + } + + const upb_FieldDef* f = _upb_DefType_Unpack(val, UPB_DEFTYPE_FIELD); + const upb_OneofDef* o = _upb_DefType_Unpack(val, UPB_DEFTYPE_ONEOF); + if (out_f) *out_f = f; + if (out_o) *out_o = o; + return f || o; /* False if this was a JSON name. */ } -// Fast decoder: ~3x the speed of decode.c, but requires x86-64/ARM64. -// Also the table size grows by 2x. -// -// Could potentially be ported to other 64-bit archs that pass at least six -// arguments in registers and have 8 unused high bits in pointers. -// -// The overall design is to create specialized functions for every possible -// field type (eg. oneof boolean field with a 1 byte tag) and then dispatch -// to the specialized function as quickly as possible. - +const upb_FieldDef* upb_MessageDef_FindByJsonNameWithSize( + const upb_MessageDef* m, const char* name, size_t size) { + upb_value val; + if (upb_strtable_lookup2(&m->jtof, name, size, &val)) { + return upb_value_getconstptr(val); + } -// Must be last. + if (!upb_strtable_lookup2(&m->ntof, name, size, &val)) { + return NULL; + } -#if UPB_FASTTABLE + return _upb_DefType_Unpack(val, UPB_DEFTYPE_FIELD); +} -// The standard set of arguments passed to each parsing function. -// Thanks to x86-64 calling conventions, these will stay in registers. -#define UPB_PARSE_PARAMS \ - upb_Decoder *d, const char *ptr, upb_Message *msg, intptr_t table, \ - uint64_t hasbits, uint64_t data +int upb_MessageDef_ExtensionRangeCount(const upb_MessageDef* m) { + return m->ext_range_count; +} -#define UPB_PARSE_ARGS d, ptr, msg, table, hasbits, data +int upb_MessageDef_ReservedRangeCount(const upb_MessageDef* m) { + return m->res_range_count; +} -#define RETURN_GENERIC(m) \ - /* Uncomment either of these for debugging purposes. */ \ - /* fprintf(stderr, m); */ \ - /*__builtin_trap(); */ \ - return _upb_FastDecoder_DecodeGeneric(d, ptr, msg, table, hasbits, 0); +int upb_MessageDef_ReservedNameCount(const upb_MessageDef* m) { + return m->res_name_count; +} -typedef enum { - CARD_s = 0, /* Singular (optional, non-repeated) */ - CARD_o = 1, /* Oneof */ - CARD_r = 2, /* Repeated */ - CARD_p = 3 /* Packed Repeated */ -} upb_card; +int upb_MessageDef_FieldCount(const upb_MessageDef* m) { + return m->field_count; +} -UPB_NOINLINE -static const char* fastdecode_isdonefallback(UPB_PARSE_PARAMS) { - int overrun = data; - ptr = _upb_EpsCopyInputStream_IsDoneFallbackInline( - &d->input, ptr, overrun, _upb_Decoder_BufferFlipCallback); - data = _upb_FastDecoder_LoadTag(ptr); - UPB_MUSTTAIL return _upb_FastDecoder_TagDispatch(UPB_PARSE_ARGS); +int upb_MessageDef_OneofCount(const upb_MessageDef* m) { + return m->oneof_count; } -UPB_FORCEINLINE -static const char* fastdecode_dispatch(UPB_PARSE_PARAMS) { - int overrun; - switch (upb_EpsCopyInputStream_IsDoneStatus(&d->input, ptr, &overrun)) { - case kUpb_IsDoneStatus_Done: - *(uint32_t*)msg |= hasbits; // Sync hasbits. - const upb_MiniTable* m = decode_totablep(table); - return UPB_UNLIKELY(m->UPB_PRIVATE(required_count)) - ? _upb_Decoder_CheckRequired(d, ptr, msg, m) - : ptr; - case kUpb_IsDoneStatus_NotDone: - break; - case kUpb_IsDoneStatus_NeedFallback: - data = overrun; - UPB_MUSTTAIL return fastdecode_isdonefallback(UPB_PARSE_ARGS); - } +int upb_MessageDef_RealOneofCount(const upb_MessageDef* m) { + return m->real_oneof_count; +} - // Read two bytes of tag data (for a one-byte tag, the high byte is junk). - data = _upb_FastDecoder_LoadTag(ptr); - UPB_MUSTTAIL return _upb_FastDecoder_TagDispatch(UPB_PARSE_ARGS); +int upb_MessageDef_NestedMessageCount(const upb_MessageDef* m) { + return m->nested_msg_count; } -UPB_FORCEINLINE -static bool fastdecode_checktag(uint16_t data, int tagbytes) { - if (tagbytes == 1) { - return (data & 0xff) == 0; - } else { - return data == 0; - } +int upb_MessageDef_NestedEnumCount(const upb_MessageDef* m) { + return m->nested_enum_count; } -UPB_FORCEINLINE -static const char* fastdecode_longsize(const char* ptr, int* size) { - int i; - UPB_ASSERT(*size & 0x80); - *size &= 0xff; - for (i = 0; i < 3; i++) { - ptr++; - size_t byte = (uint8_t)ptr[-1]; - *size += (byte - 1) << (7 + 7 * i); - if (UPB_LIKELY((byte & 0x80) == 0)) return ptr; - } - ptr++; - size_t byte = (uint8_t)ptr[-1]; - // len is limited by 2gb not 4gb, hence 8 and not 16 as normally expected - // for a 32 bit varint. - if (UPB_UNLIKELY(byte >= 8)) return NULL; - *size += (byte - 1) << 28; - return ptr; +int upb_MessageDef_NestedExtensionCount(const upb_MessageDef* m) { + return m->nested_ext_count; } -UPB_FORCEINLINE -static const char* fastdecode_delimited( - upb_Decoder* d, const char* ptr, - upb_EpsCopyInputStream_ParseDelimitedFunc* func, void* ctx) { - ptr++; +const upb_MiniTable* upb_MessageDef_MiniTable(const upb_MessageDef* m) { + return m->layout; +} - // Sign-extend so varint greater than one byte becomes negative, causing - // fast delimited parse to fail. - int len = (int8_t)ptr[-1]; +const upb_ExtensionRange* upb_MessageDef_ExtensionRange(const upb_MessageDef* m, + int i) { + UPB_ASSERT(0 <= i && i < m->ext_range_count); + return _upb_ExtensionRange_At(m->ext_ranges, i); +} - if (!upb_EpsCopyInputStream_TryParseDelimitedFast(&d->input, &ptr, len, func, - ctx)) { - // Slow case: Sub-message is >=128 bytes and/or exceeds the current buffer. - // If it exceeds the buffer limit, limit/limit_ptr will change during - // sub-message parsing, so we need to preserve delta, not limit. - if (UPB_UNLIKELY(len & 0x80)) { - // Size varint >1 byte (length >= 128). - ptr = fastdecode_longsize(ptr, &len); - if (!ptr) { - // Corrupt wire format: size exceeded INT_MAX. - return NULL; - } - } - if (!upb_EpsCopyInputStream_CheckSize(&d->input, ptr, len)) { - // Corrupt wire format: invalid limit. - return NULL; - } - int delta = upb_EpsCopyInputStream_PushLimit(&d->input, ptr, len); - ptr = func(&d->input, ptr, ctx); - upb_EpsCopyInputStream_PopLimit(&d->input, ptr, delta); - } - return ptr; +const upb_MessageReservedRange* upb_MessageDef_ReservedRange( + const upb_MessageDef* m, int i) { + UPB_ASSERT(0 <= i && i < m->res_range_count); + return _upb_MessageReservedRange_At(m->res_ranges, i); } -/* singular, oneof, repeated field handling ***********************************/ +upb_StringView upb_MessageDef_ReservedName(const upb_MessageDef* m, int i) { + UPB_ASSERT(0 <= i && i < m->res_name_count); + return m->res_names[i]; +} -typedef struct { - upb_Array* arr; - void* end; -} fastdecode_arr; +const upb_FieldDef* upb_MessageDef_Field(const upb_MessageDef* m, int i) { + UPB_ASSERT(0 <= i && i < m->field_count); + return _upb_FieldDef_At(m->fields, i); +} -typedef enum { - FD_NEXT_ATLIMIT, - FD_NEXT_SAMEFIELD, - FD_NEXT_OTHERFIELD -} fastdecode_next; +const upb_OneofDef* upb_MessageDef_Oneof(const upb_MessageDef* m, int i) { + UPB_ASSERT(0 <= i && i < m->oneof_count); + return _upb_OneofDef_At(m->oneofs, i); +} -typedef struct { - void* dst; - fastdecode_next next; - uint32_t tag; -} fastdecode_nextret; +const upb_MessageDef* upb_MessageDef_NestedMessage(const upb_MessageDef* m, + int i) { + UPB_ASSERT(0 <= i && i < m->nested_msg_count); + return &m->nested_msgs[i]; +} -UPB_FORCEINLINE -static void* fastdecode_resizearr(upb_Decoder* d, void* dst, - fastdecode_arr* farr, int valbytes) { - if (UPB_UNLIKELY(dst == farr->end)) { - size_t old_capacity = farr->arr->UPB_PRIVATE(capacity); - size_t old_bytes = old_capacity * valbytes; - size_t new_capacity = old_capacity * 2; - size_t new_bytes = new_capacity * valbytes; - char* old_ptr = _upb_array_ptr(farr->arr); - char* new_ptr = upb_Arena_Realloc(&d->arena, old_ptr, old_bytes, new_bytes); - uint8_t elem_size_lg2 = __builtin_ctz(valbytes); - UPB_PRIVATE(_upb_Array_SetTaggedPtr)(farr->arr, new_ptr, elem_size_lg2); - farr->arr->UPB_PRIVATE(capacity) = new_capacity; - dst = (void*)(new_ptr + (old_capacity * valbytes)); - farr->end = (void*)(new_ptr + (new_capacity * valbytes)); - } - return dst; +const upb_EnumDef* upb_MessageDef_NestedEnum(const upb_MessageDef* m, int i) { + UPB_ASSERT(0 <= i && i < m->nested_enum_count); + return _upb_EnumDef_At(m->nested_enums, i); } -UPB_FORCEINLINE -static bool fastdecode_tagmatch(uint32_t tag, uint64_t data, int tagbytes) { - if (tagbytes == 1) { - return (uint8_t)tag == (uint8_t)data; - } else { - return (uint16_t)tag == (uint16_t)data; - } +const upb_FieldDef* upb_MessageDef_NestedExtension(const upb_MessageDef* m, + int i) { + UPB_ASSERT(0 <= i && i < m->nested_ext_count); + return _upb_FieldDef_At(m->nested_exts, i); } -UPB_FORCEINLINE -static void fastdecode_commitarr(void* dst, fastdecode_arr* farr, - int valbytes) { - farr->arr->UPB_PRIVATE(size) = - (size_t)((char*)dst - (char*)_upb_array_ptr(farr->arr)) / valbytes; +upb_WellKnown upb_MessageDef_WellKnownType(const upb_MessageDef* m) { + return m->well_known_type; } -UPB_FORCEINLINE -static fastdecode_nextret fastdecode_nextrepeated(upb_Decoder* d, void* dst, - const char** ptr, - fastdecode_arr* farr, - uint64_t data, int tagbytes, - int valbytes) { - fastdecode_nextret ret; - dst = (char*)dst + valbytes; +bool _upb_MessageDef_InMessageSet(const upb_MessageDef* m) { + return m->in_message_set; +} - if (UPB_LIKELY(!_upb_Decoder_IsDone(d, ptr))) { - ret.tag = _upb_FastDecoder_LoadTag(*ptr); - if (fastdecode_tagmatch(ret.tag, data, tagbytes)) { - ret.next = FD_NEXT_SAMEFIELD; - } else { - fastdecode_commitarr(dst, farr, valbytes); - ret.next = FD_NEXT_OTHERFIELD; - } - } else { - fastdecode_commitarr(dst, farr, valbytes); - ret.next = FD_NEXT_ATLIMIT; - } +const upb_FieldDef* upb_MessageDef_FindFieldByName(const upb_MessageDef* m, + const char* name) { + return upb_MessageDef_FindFieldByNameWithSize(m, name, strlen(name)); +} - ret.dst = dst; - return ret; +const upb_OneofDef* upb_MessageDef_FindOneofByName(const upb_MessageDef* m, + const char* name) { + return upb_MessageDef_FindOneofByNameWithSize(m, name, strlen(name)); } -UPB_FORCEINLINE -static void* fastdecode_fieldmem(upb_Message* msg, uint64_t data) { - size_t ofs = data >> 48; - return (char*)msg + ofs; +bool upb_MessageDef_IsMapEntry(const upb_MessageDef* m) { + return UPB_DESC(MessageOptions_map_entry)(m->opts); } -UPB_FORCEINLINE -static void* fastdecode_getfield(upb_Decoder* d, const char* ptr, - upb_Message* msg, uint64_t* data, - uint64_t* hasbits, fastdecode_arr* farr, - int valbytes, upb_card card) { - switch (card) { - case CARD_s: { - uint8_t hasbit_index = *data >> 24; - // Set hasbit and return pointer to scalar field. - *hasbits |= 1ull << hasbit_index; - return fastdecode_fieldmem(msg, *data); - } - case CARD_o: { - uint16_t case_ofs = *data >> 32; - uint32_t* oneof_case = UPB_PTR_AT(msg, case_ofs, uint32_t); - uint8_t field_number = *data >> 24; - *oneof_case = field_number; - return fastdecode_fieldmem(msg, *data); - } - case CARD_r: { - // Get pointer to upb_Array and allocate/expand if necessary. - uint8_t elem_size_lg2 = __builtin_ctz(valbytes); - upb_Array** arr_p = fastdecode_fieldmem(msg, *data); - char* begin; - *(uint32_t*)msg |= *hasbits; - *hasbits = 0; - if (UPB_LIKELY(!*arr_p)) { - farr->arr = UPB_PRIVATE(_upb_Array_New)(&d->arena, 8, elem_size_lg2); - *arr_p = farr->arr; - } else { - farr->arr = *arr_p; - } - begin = _upb_array_ptr(farr->arr); - farr->end = begin + (farr->arr->UPB_PRIVATE(capacity) * valbytes); - *data = _upb_FastDecoder_LoadTag(ptr); - return begin + (farr->arr->UPB_PRIVATE(size) * valbytes); - } - default: - UPB_UNREACHABLE(); - } +bool upb_MessageDef_IsMessageSet(const upb_MessageDef* m) { + return UPB_DESC(MessageOptions_message_set_wire_format)(m->opts); } -UPB_FORCEINLINE -static bool fastdecode_flippacked(uint64_t* data, int tagbytes) { - *data ^= (0x2 ^ 0x0); // Patch data to match packed wiretype. - return fastdecode_checktag(*data, tagbytes); +static upb_MiniTable* _upb_MessageDef_MakeMiniTable(upb_DefBuilder* ctx, + const upb_MessageDef* m) { + upb_StringView desc; + // Note: this will assign layout_index for fields, so upb_FieldDef_MiniTable() + // is safe to call only after this call. + bool ok = upb_MessageDef_MiniDescriptorEncode(m, ctx->tmp_arena, &desc); + if (!ok) _upb_DefBuilder_OomErr(ctx); + + void** scratch_data = _upb_DefPool_ScratchData(ctx->symtab); + size_t* scratch_size = _upb_DefPool_ScratchSize(ctx->symtab); + upb_MiniTable* ret = upb_MiniTable_BuildWithBuf( + desc.data, desc.size, ctx->platform, ctx->arena, scratch_data, + scratch_size, ctx->status); + if (!ret) _upb_DefBuilder_FailJmp(ctx); + + return ret; } -#define FASTDECODE_CHECKPACKED(tagbytes, card, func) \ - if (UPB_UNLIKELY(!fastdecode_checktag(data, tagbytes))) { \ - if (card == CARD_r && fastdecode_flippacked(&data, tagbytes)) { \ - UPB_MUSTTAIL return func(UPB_PARSE_ARGS); \ - } \ - RETURN_GENERIC("packed check tag mismatch\n"); \ +void _upb_MessageDef_Resolve(upb_DefBuilder* ctx, upb_MessageDef* m) { + for (int i = 0; i < m->field_count; i++) { + upb_FieldDef* f = (upb_FieldDef*)upb_MessageDef_Field(m, i); + _upb_FieldDef_Resolve(ctx, m->full_name, f); } -/* varint fields **************************************************************/ - -UPB_FORCEINLINE -static uint64_t fastdecode_munge(uint64_t val, int valbytes, bool zigzag) { - if (valbytes == 1) { - return val != 0; - } else if (zigzag) { - if (valbytes == 4) { - uint32_t n = val; - return (n >> 1) ^ -(int32_t)(n & 1); - } else if (valbytes == 8) { - return (val >> 1) ^ -(int64_t)(val & 1); + m->in_message_set = false; + for (int i = 0; i < upb_MessageDef_NestedExtensionCount(m); i++) { + upb_FieldDef* ext = (upb_FieldDef*)upb_MessageDef_NestedExtension(m, i); + _upb_FieldDef_Resolve(ctx, m->full_name, ext); + if (upb_FieldDef_Type(ext) == kUpb_FieldType_Message && + upb_FieldDef_Label(ext) == kUpb_Label_Optional && + upb_FieldDef_MessageSubDef(ext) == m && + UPB_DESC(MessageOptions_message_set_wire_format)( + upb_MessageDef_Options(upb_FieldDef_ContainingType(ext)))) { + m->in_message_set = true; } - UPB_UNREACHABLE(); } - return val; -} -UPB_FORCEINLINE -static const char* fastdecode_varint64(const char* ptr, uint64_t* val) { - ptr++; - *val = (uint8_t)ptr[-1]; - if (UPB_UNLIKELY(*val & 0x80)) { - int i; - for (i = 0; i < 8; i++) { - ptr++; - uint64_t byte = (uint8_t)ptr[-1]; - *val += (byte - 1) << (7 + 7 * i); - if (UPB_LIKELY((byte & 0x80) == 0)) goto done; - } - ptr++; - uint64_t byte = (uint8_t)ptr[-1]; - if (byte > 1) { - return NULL; - } - *val += (byte - 1) << 63; + for (int i = 0; i < upb_MessageDef_NestedMessageCount(m); i++) { + upb_MessageDef* n = (upb_MessageDef*)upb_MessageDef_NestedMessage(m, i); + _upb_MessageDef_Resolve(ctx, n); } -done: - UPB_ASSUME(ptr != NULL); - return ptr; } -#define FASTDECODE_UNPACKEDVARINT(d, ptr, msg, table, hasbits, data, tagbytes, \ - valbytes, card, zigzag, packed) \ - uint64_t val; \ - void* dst; \ - fastdecode_arr farr; \ - \ - FASTDECODE_CHECKPACKED(tagbytes, card, packed); \ - \ - dst = fastdecode_getfield(d, ptr, msg, &data, &hasbits, &farr, valbytes, \ - card); \ - if (card == CARD_r) { \ - if (UPB_UNLIKELY(!dst)) { \ - RETURN_GENERIC("need array resize\n"); \ - } \ - } \ - \ - again: \ - if (card == CARD_r) { \ - dst = fastdecode_resizearr(d, dst, &farr, valbytes); \ - } \ - \ - ptr += tagbytes; \ - ptr = fastdecode_varint64(ptr, &val); \ - if (ptr == NULL) _upb_FastDecoder_ErrorJmp(d, kUpb_DecodeStatus_Malformed); \ - val = fastdecode_munge(val, valbytes, zigzag); \ - memcpy(dst, &val, valbytes); \ - \ - if (card == CARD_r) { \ - fastdecode_nextret ret = fastdecode_nextrepeated( \ - d, dst, &ptr, &farr, data, tagbytes, valbytes); \ - switch (ret.next) { \ - case FD_NEXT_SAMEFIELD: \ - dst = ret.dst; \ - goto again; \ - case FD_NEXT_OTHERFIELD: \ - data = ret.tag; \ - UPB_MUSTTAIL return _upb_FastDecoder_TagDispatch(UPB_PARSE_ARGS); \ - case FD_NEXT_ATLIMIT: \ - return ptr; \ - } \ - } \ - \ - UPB_MUSTTAIL return fastdecode_dispatch(UPB_PARSE_ARGS); - -typedef struct { - uint8_t valbytes; - bool zigzag; - void* dst; - fastdecode_arr farr; -} fastdecode_varintdata; - -UPB_FORCEINLINE -static const char* fastdecode_topackedvarint(upb_EpsCopyInputStream* e, - const char* ptr, void* ctx) { - upb_Decoder* d = (upb_Decoder*)e; - fastdecode_varintdata* data = ctx; - void* dst = data->dst; - uint64_t val; +void _upb_MessageDef_InsertField(upb_DefBuilder* ctx, upb_MessageDef* m, + const upb_FieldDef* f) { + const int32_t field_number = upb_FieldDef_Number(f); - while (!_upb_Decoder_IsDone(d, &ptr)) { - dst = fastdecode_resizearr(d, dst, &data->farr, data->valbytes); - ptr = fastdecode_varint64(ptr, &val); - if (ptr == NULL) return NULL; - val = fastdecode_munge(val, data->valbytes, data->zigzag); - memcpy(dst, &val, data->valbytes); - dst = (char*)dst + data->valbytes; + if (field_number <= 0 || field_number > kUpb_MaxFieldNumber) { + _upb_DefBuilder_Errf(ctx, "invalid field number (%u)", field_number); } - fastdecode_commitarr(dst, &data->farr, data->valbytes); - return ptr; -} + const char* json_name = upb_FieldDef_JsonName(f); + const char* shortname = upb_FieldDef_Name(f); + const size_t shortnamelen = strlen(shortname); -#define FASTDECODE_PACKEDVARINT(d, ptr, msg, table, hasbits, data, tagbytes, \ - valbytes, zigzag, unpacked) \ - fastdecode_varintdata ctx = {valbytes, zigzag}; \ - \ - FASTDECODE_CHECKPACKED(tagbytes, CARD_r, unpacked); \ - \ - ctx.dst = fastdecode_getfield(d, ptr, msg, &data, &hasbits, &ctx.farr, \ - valbytes, CARD_r); \ - if (UPB_UNLIKELY(!ctx.dst)) { \ - RETURN_GENERIC("need array resize\n"); \ - } \ - \ - ptr += tagbytes; \ - ptr = fastdecode_delimited(d, ptr, &fastdecode_topackedvarint, &ctx); \ - \ - if (UPB_UNLIKELY(ptr == NULL)) { \ - _upb_FastDecoder_ErrorJmp(d, kUpb_DecodeStatus_Malformed); \ - } \ - \ - UPB_MUSTTAIL return fastdecode_dispatch(d, ptr, msg, table, hasbits, 0); + upb_value v = upb_value_constptr(f); -#define FASTDECODE_VARINT(d, ptr, msg, table, hasbits, data, tagbytes, \ - valbytes, card, zigzag, unpacked, packed) \ - if (card == CARD_p) { \ - FASTDECODE_PACKEDVARINT(d, ptr, msg, table, hasbits, data, tagbytes, \ - valbytes, zigzag, unpacked); \ - } else { \ - FASTDECODE_UNPACKEDVARINT(d, ptr, msg, table, hasbits, data, tagbytes, \ - valbytes, card, zigzag, packed); \ + upb_value existing_v; + if (upb_strtable_lookup(&m->ntof, shortname, &existing_v)) { + _upb_DefBuilder_Errf(ctx, "duplicate field name (%s)", shortname); } -#define z_ZZ true -#define b_ZZ false -#define v_ZZ false - -/* Generate all combinations: - * {s,o,r,p} x {b1,v4,z4,v8,z8} x {1bt,2bt} */ + const upb_value field_v = _upb_DefType_Pack(f, UPB_DEFTYPE_FIELD); + bool ok = + _upb_MessageDef_Insert(m, shortname, shortnamelen, field_v, ctx->arena); + if (!ok) _upb_DefBuilder_OomErr(ctx); -#define F(card, type, valbytes, tagbytes) \ - UPB_NOINLINE \ - const char* upb_p##card##type##valbytes##_##tagbytes##bt(UPB_PARSE_PARAMS) { \ - FASTDECODE_VARINT(d, ptr, msg, table, hasbits, data, tagbytes, valbytes, \ - CARD_##card, type##_ZZ, \ - upb_pr##type##valbytes##_##tagbytes##bt, \ - upb_pp##type##valbytes##_##tagbytes##bt); \ + if (strcmp(shortname, json_name) != 0 && + UPB_DESC(FeatureSet_json_format)(m->resolved_features) == + UPB_DESC(FeatureSet_ALLOW) && + upb_strtable_lookup(&m->ntof, json_name, &v)) { + _upb_DefBuilder_Errf( + ctx, "duplicate json_name for (%s) with original field name (%s)", + shortname, json_name); } -#define TYPES(card, tagbytes) \ - F(card, b, 1, tagbytes) \ - F(card, v, 4, tagbytes) \ - F(card, v, 8, tagbytes) \ - F(card, z, 4, tagbytes) \ - F(card, z, 8, tagbytes) - -#define TAGBYTES(card) \ - TYPES(card, 1) \ - TYPES(card, 2) + if (upb_strtable_lookup(&m->jtof, json_name, &v)) { + _upb_DefBuilder_Errf(ctx, "duplicate json_name (%s)", json_name); + } -TAGBYTES(s) -TAGBYTES(o) -TAGBYTES(r) -TAGBYTES(p) + const size_t json_size = strlen(json_name); + ok = upb_strtable_insert(&m->jtof, json_name, json_size, + upb_value_constptr(f), ctx->arena); + if (!ok) _upb_DefBuilder_OomErr(ctx); -#undef z_ZZ -#undef b_ZZ -#undef v_ZZ -#undef o_ONEOF -#undef s_ONEOF -#undef r_ONEOF -#undef F -#undef TYPES -#undef TAGBYTES -#undef FASTDECODE_UNPACKEDVARINT -#undef FASTDECODE_PACKEDVARINT -#undef FASTDECODE_VARINT + if (upb_inttable_lookup(&m->itof, field_number, NULL)) { + _upb_DefBuilder_Errf(ctx, "duplicate field number (%u)", field_number); + } -/* fixed fields ***************************************************************/ + ok = upb_inttable_insert(&m->itof, field_number, v, ctx->arena); + if (!ok) _upb_DefBuilder_OomErr(ctx); +} -#define FASTDECODE_UNPACKEDFIXED(d, ptr, msg, table, hasbits, data, tagbytes, \ - valbytes, card, packed) \ - void* dst; \ - fastdecode_arr farr; \ - \ - FASTDECODE_CHECKPACKED(tagbytes, card, packed) \ - \ - dst = fastdecode_getfield(d, ptr, msg, &data, &hasbits, &farr, valbytes, \ - card); \ - if (card == CARD_r) { \ - if (UPB_UNLIKELY(!dst)) { \ - RETURN_GENERIC("couldn't allocate array in arena\n"); \ - } \ - } \ - \ - again: \ - if (card == CARD_r) { \ - dst = fastdecode_resizearr(d, dst, &farr, valbytes); \ - } \ - \ - ptr += tagbytes; \ - memcpy(dst, ptr, valbytes); \ - ptr += valbytes; \ - \ - if (card == CARD_r) { \ - fastdecode_nextret ret = fastdecode_nextrepeated( \ - d, dst, &ptr, &farr, data, tagbytes, valbytes); \ - switch (ret.next) { \ - case FD_NEXT_SAMEFIELD: \ - dst = ret.dst; \ - goto again; \ - case FD_NEXT_OTHERFIELD: \ - data = ret.tag; \ - UPB_MUSTTAIL return _upb_FastDecoder_TagDispatch(UPB_PARSE_ARGS); \ - case FD_NEXT_ATLIMIT: \ - return ptr; \ - } \ - } \ - \ - UPB_MUSTTAIL return fastdecode_dispatch(UPB_PARSE_ARGS); +void _upb_MessageDef_CreateMiniTable(upb_DefBuilder* ctx, upb_MessageDef* m) { + if (ctx->layout == NULL) { + m->layout = _upb_MessageDef_MakeMiniTable(ctx, m); + } else { + m->layout = upb_MiniTableFile_Message(ctx->layout, ctx->msg_count++); + UPB_ASSERT(m->field_count == m->layout->UPB_PRIVATE(field_count)); -#define FASTDECODE_PACKEDFIXED(d, ptr, msg, table, hasbits, data, tagbytes, \ - valbytes, unpacked) \ - FASTDECODE_CHECKPACKED(tagbytes, CARD_r, unpacked) \ - \ - ptr += tagbytes; \ - int size = (uint8_t)ptr[0]; \ - ptr++; \ - if (size & 0x80) { \ - ptr = fastdecode_longsize(ptr, &size); \ - } \ - \ - if (UPB_UNLIKELY(!upb_EpsCopyInputStream_CheckDataSizeAvailable( \ - &d->input, ptr, size) || \ - (size % valbytes) != 0)) { \ - _upb_FastDecoder_ErrorJmp(d, kUpb_DecodeStatus_Malformed); \ - } \ - \ - upb_Array** arr_p = fastdecode_fieldmem(msg, data); \ - upb_Array* arr = *arr_p; \ - uint8_t elem_size_lg2 = __builtin_ctz(valbytes); \ - int elems = size / valbytes; \ - \ - if (UPB_LIKELY(!arr)) { \ - *arr_p = arr = \ - UPB_PRIVATE(_upb_Array_New)(&d->arena, elems, elem_size_lg2); \ - if (!arr) { \ - _upb_FastDecoder_ErrorJmp(d, kUpb_DecodeStatus_Malformed); \ - } \ - } else { \ - _upb_Array_ResizeUninitialized(arr, elems, &d->arena); \ - } \ - \ - char* dst = _upb_array_ptr(arr); \ - memcpy(dst, ptr, size); \ - arr->UPB_PRIVATE(size) = elems; \ - \ - ptr += size; \ - UPB_MUSTTAIL return fastdecode_dispatch(UPB_PARSE_ARGS); + // We don't need the result of this call, but it will assign layout_index + // for all the fields in O(n lg n) time. + _upb_FieldDefs_Sorted(m->fields, m->field_count, ctx->tmp_arena); + } -#define FASTDECODE_FIXED(d, ptr, msg, table, hasbits, data, tagbytes, \ - valbytes, card, unpacked, packed) \ - if (card == CARD_p) { \ - FASTDECODE_PACKEDFIXED(d, ptr, msg, table, hasbits, data, tagbytes, \ - valbytes, unpacked); \ - } else { \ - FASTDECODE_UNPACKEDFIXED(d, ptr, msg, table, hasbits, data, tagbytes, \ - valbytes, card, packed); \ + for (int i = 0; i < m->nested_msg_count; i++) { + upb_MessageDef* nested = + (upb_MessageDef*)upb_MessageDef_NestedMessage(m, i); + _upb_MessageDef_CreateMiniTable(ctx, nested); } +} -/* Generate all combinations: - * {s,o,r,p} x {f4,f8} x {1bt,2bt} */ +void _upb_MessageDef_LinkMiniTable(upb_DefBuilder* ctx, + const upb_MessageDef* m) { + for (int i = 0; i < upb_MessageDef_NestedExtensionCount(m); i++) { + const upb_FieldDef* ext = upb_MessageDef_NestedExtension(m, i); + _upb_FieldDef_BuildMiniTableExtension(ctx, ext); + } -#define F(card, valbytes, tagbytes) \ - UPB_NOINLINE \ - const char* upb_p##card##f##valbytes##_##tagbytes##bt(UPB_PARSE_PARAMS) { \ - FASTDECODE_FIXED(d, ptr, msg, table, hasbits, data, tagbytes, valbytes, \ - CARD_##card, upb_ppf##valbytes##_##tagbytes##bt, \ - upb_prf##valbytes##_##tagbytes##bt); \ + for (int i = 0; i < m->nested_msg_count; i++) { + _upb_MessageDef_LinkMiniTable(ctx, upb_MessageDef_NestedMessage(m, i)); } -#define TYPES(card, tagbytes) \ - F(card, 4, tagbytes) \ - F(card, 8, tagbytes) + if (ctx->layout) return; -#define TAGBYTES(card) \ - TYPES(card, 1) \ - TYPES(card, 2) + for (int i = 0; i < m->field_count; i++) { + const upb_FieldDef* f = upb_MessageDef_Field(m, i); + const upb_MessageDef* sub_m = upb_FieldDef_MessageSubDef(f); + const upb_EnumDef* sub_e = upb_FieldDef_EnumSubDef(f); + const int layout_index = _upb_FieldDef_LayoutIndex(f); + upb_MiniTable* mt = (upb_MiniTable*)upb_MessageDef_MiniTable(m); -TAGBYTES(s) -TAGBYTES(o) -TAGBYTES(r) -TAGBYTES(p) + UPB_ASSERT(layout_index < m->field_count); + upb_MiniTableField* mt_f = + (upb_MiniTableField*)&m->layout->UPB_PRIVATE(fields)[layout_index]; + if (sub_m) { + if (!mt->UPB_PRIVATE(subs)) { + _upb_DefBuilder_Errf(ctx, "unexpected submsg for (%s)", m->full_name); + } + UPB_ASSERT(mt_f); + UPB_ASSERT(sub_m->layout); + if (UPB_UNLIKELY(!upb_MiniTable_SetSubMessage(mt, mt_f, sub_m->layout))) { + _upb_DefBuilder_Errf(ctx, "invalid submsg for (%s)", m->full_name); + } + } else if (_upb_FieldDef_IsClosedEnum(f)) { + const upb_MiniTableEnum* mt_e = _upb_EnumDef_MiniTable(sub_e); + if (UPB_UNLIKELY(!upb_MiniTable_SetSubEnum(mt, mt_f, mt_e))) { + _upb_DefBuilder_Errf(ctx, "invalid subenum for (%s)", m->full_name); + } + } + } -#undef F -#undef TYPES -#undef TAGBYTES -#undef FASTDECODE_UNPACKEDFIXED -#undef FASTDECODE_PACKEDFIXED +#ifndef NDEBUG + for (int i = 0; i < m->field_count; i++) { + const upb_FieldDef* f = upb_MessageDef_Field(m, i); + const int layout_index = _upb_FieldDef_LayoutIndex(f); + UPB_ASSERT(layout_index < m->layout->UPB_PRIVATE(field_count)); + const upb_MiniTableField* mt_f = + &m->layout->UPB_PRIVATE(fields)[layout_index]; + UPB_ASSERT(upb_FieldDef_Type(f) == upb_MiniTableField_Type(mt_f)); + UPB_ASSERT(upb_FieldDef_CType(f) == upb_MiniTableField_CType(mt_f)); + UPB_ASSERT(upb_FieldDef_HasPresence(f) == + upb_MiniTableField_HasPresence(mt_f)); + } +#endif +} -/* string fields **************************************************************/ +static bool _upb_MessageDef_ValidateUtf8(const upb_MessageDef* m) { + bool has_string = false; + for (int i = 0; i < m->field_count; i++) { + const upb_FieldDef* f = upb_MessageDef_Field(m, i); + // Old binaries do not recognize the field-level "FlipValidateUtf8" wire + // modifier, so we do not actually have field-level control for old + // binaries. Given this, we judge that the better failure mode is to be + // more lax than intended, rather than more strict. To achieve this, we + // only mark the message with the ValidateUtf8 modifier if *all* fields + // validate UTF-8. + if (!_upb_FieldDef_ValidateUtf8(f)) return false; + if (upb_FieldDef_Type(f) == kUpb_FieldType_String) has_string = true; + } + return has_string; +} -typedef const char* fastdecode_copystr_func(struct upb_Decoder* d, - const char* ptr, upb_Message* msg, - const upb_MiniTable* table, - uint64_t hasbits, - upb_StringView* dst); +static uint64_t _upb_MessageDef_Modifiers(const upb_MessageDef* m) { + uint64_t out = 0; -UPB_NOINLINE -static const char* fastdecode_verifyutf8(upb_Decoder* d, const char* ptr, - upb_Message* msg, intptr_t table, - uint64_t hasbits, uint64_t data) { - upb_StringView* dst = (upb_StringView*)data; - if (!_upb_Decoder_VerifyUtf8Inline(dst->data, dst->size)) { - _upb_FastDecoder_ErrorJmp(d, kUpb_DecodeStatus_BadUtf8); + if (UPB_DESC(FeatureSet_repeated_field_encoding(m->resolved_features)) == + UPB_DESC(FeatureSet_PACKED)) { + out |= kUpb_MessageModifier_DefaultIsPacked; + } + + if (_upb_MessageDef_ValidateUtf8(m)) { + out |= kUpb_MessageModifier_ValidateUtf8; } - UPB_MUSTTAIL return fastdecode_dispatch(UPB_PARSE_ARGS); -} -#define FASTDECODE_LONGSTRING(d, ptr, msg, table, hasbits, dst, validate_utf8) \ - int size = (uint8_t)ptr[0]; /* Could plumb through hasbits. */ \ - ptr++; \ - if (size & 0x80) { \ - ptr = fastdecode_longsize(ptr, &size); \ - } \ - \ - if (UPB_UNLIKELY(!upb_EpsCopyInputStream_CheckSize(&d->input, ptr, size))) { \ - dst->size = 0; \ - _upb_FastDecoder_ErrorJmp(d, kUpb_DecodeStatus_Malformed); \ - } \ - \ - const char* s_ptr = ptr; \ - ptr = upb_EpsCopyInputStream_ReadString(&d->input, &s_ptr, size, &d->arena); \ - if (!ptr) _upb_FastDecoder_ErrorJmp(d, kUpb_DecodeStatus_OutOfMemory); \ - dst->data = s_ptr; \ - dst->size = size; \ - \ - if (validate_utf8) { \ - data = (uint64_t)dst; \ - UPB_MUSTTAIL return fastdecode_verifyutf8(UPB_PARSE_ARGS); \ - } else { \ - UPB_MUSTTAIL return fastdecode_dispatch(UPB_PARSE_ARGS); \ + if (m->ext_range_count) { + out |= kUpb_MessageModifier_IsExtendable; } -UPB_NOINLINE -static const char* fastdecode_longstring_utf8(struct upb_Decoder* d, - const char* ptr, upb_Message* msg, - intptr_t table, uint64_t hasbits, - uint64_t data) { - upb_StringView* dst = (upb_StringView*)data; - FASTDECODE_LONGSTRING(d, ptr, msg, table, hasbits, dst, true); + return out; } -UPB_NOINLINE -static const char* fastdecode_longstring_noutf8( - struct upb_Decoder* d, const char* ptr, upb_Message* msg, intptr_t table, - uint64_t hasbits, uint64_t data) { - upb_StringView* dst = (upb_StringView*)data; - FASTDECODE_LONGSTRING(d, ptr, msg, table, hasbits, dst, false); -} +static bool _upb_MessageDef_EncodeMap(upb_DescState* s, const upb_MessageDef* m, + upb_Arena* a) { + if (m->field_count != 2) return false; -UPB_FORCEINLINE -static void fastdecode_docopy(upb_Decoder* d, const char* ptr, uint32_t size, - int copy, char* data, size_t data_offset, - upb_StringView* dst) { - d->arena.UPB_PRIVATE(ptr) += copy; - dst->data = data + data_offset; - UPB_UNPOISON_MEMORY_REGION(data, copy); - memcpy(data, ptr, copy); - UPB_POISON_MEMORY_REGION(data + data_offset + size, - copy - data_offset - size); + const upb_FieldDef* key_field = upb_MessageDef_Field(m, 0); + const upb_FieldDef* val_field = upb_MessageDef_Field(m, 1); + if (key_field == NULL || val_field == NULL) return false; + + UPB_ASSERT(_upb_FieldDef_LayoutIndex(key_field) == 0); + UPB_ASSERT(_upb_FieldDef_LayoutIndex(val_field) == 1); + + s->ptr = upb_MtDataEncoder_EncodeMap( + &s->e, s->ptr, upb_FieldDef_Type(key_field), upb_FieldDef_Type(val_field), + _upb_FieldDef_Modifiers(key_field), _upb_FieldDef_Modifiers(val_field)); + return true; } -#define FASTDECODE_COPYSTRING(d, ptr, msg, table, hasbits, data, tagbytes, \ - card, validate_utf8) \ - upb_StringView* dst; \ - fastdecode_arr farr; \ - int64_t size; \ - size_t arena_has; \ - size_t common_has; \ - char* buf; \ - \ - UPB_ASSERT(!upb_EpsCopyInputStream_AliasingAvailable(&d->input, ptr, 0)); \ - UPB_ASSERT(fastdecode_checktag(data, tagbytes)); \ - \ - dst = fastdecode_getfield(d, ptr, msg, &data, &hasbits, &farr, \ - sizeof(upb_StringView), card); \ - \ - again: \ - if (card == CARD_r) { \ - dst = fastdecode_resizearr(d, dst, &farr, sizeof(upb_StringView)); \ - } \ - \ - size = (uint8_t)ptr[tagbytes]; \ - ptr += tagbytes + 1; \ - dst->size = size; \ - \ - buf = d->arena.UPB_PRIVATE(ptr); \ - arena_has = UPB_PRIVATE(_upb_ArenaHas)(&d->arena); \ - common_has = UPB_MIN(arena_has, \ - upb_EpsCopyInputStream_BytesAvailable(&d->input, ptr)); \ - \ - if (UPB_LIKELY(size <= 15 - tagbytes)) { \ - if (arena_has < 16) goto longstr; \ - fastdecode_docopy(d, ptr - tagbytes - 1, size, 16, buf, tagbytes + 1, \ - dst); \ - } else if (UPB_LIKELY(size <= 32)) { \ - if (UPB_UNLIKELY(common_has < 32)) goto longstr; \ - fastdecode_docopy(d, ptr, size, 32, buf, 0, dst); \ - } else if (UPB_LIKELY(size <= 64)) { \ - if (UPB_UNLIKELY(common_has < 64)) goto longstr; \ - fastdecode_docopy(d, ptr, size, 64, buf, 0, dst); \ - } else if (UPB_LIKELY(size < 128)) { \ - if (UPB_UNLIKELY(common_has < 128)) goto longstr; \ - fastdecode_docopy(d, ptr, size, 128, buf, 0, dst); \ - } else { \ - goto longstr; \ - } \ - \ - ptr += size; \ - \ - if (card == CARD_r) { \ - if (validate_utf8 && \ - !_upb_Decoder_VerifyUtf8Inline(dst->data, dst->size)) { \ - _upb_FastDecoder_ErrorJmp(d, kUpb_DecodeStatus_BadUtf8); \ - } \ - fastdecode_nextret ret = fastdecode_nextrepeated( \ - d, dst, &ptr, &farr, data, tagbytes, sizeof(upb_StringView)); \ - switch (ret.next) { \ - case FD_NEXT_SAMEFIELD: \ - dst = ret.dst; \ - goto again; \ - case FD_NEXT_OTHERFIELD: \ - data = ret.tag; \ - UPB_MUSTTAIL return _upb_FastDecoder_TagDispatch(UPB_PARSE_ARGS); \ - case FD_NEXT_ATLIMIT: \ - return ptr; \ - } \ - } \ - \ - if (card != CARD_r && validate_utf8) { \ - data = (uint64_t)dst; \ - UPB_MUSTTAIL return fastdecode_verifyutf8(UPB_PARSE_ARGS); \ - } \ - \ - UPB_MUSTTAIL return fastdecode_dispatch(UPB_PARSE_ARGS); \ - \ - longstr: \ - if (card == CARD_r) { \ - fastdecode_commitarr(dst + 1, &farr, sizeof(upb_StringView)); \ - } \ - ptr--; \ - if (validate_utf8) { \ - UPB_MUSTTAIL return fastdecode_longstring_utf8(d, ptr, msg, table, \ - hasbits, (uint64_t)dst); \ - } else { \ - UPB_MUSTTAIL return fastdecode_longstring_noutf8(d, ptr, msg, table, \ - hasbits, (uint64_t)dst); \ +static bool _upb_MessageDef_EncodeMessage(upb_DescState* s, + const upb_MessageDef* m, + upb_Arena* a) { + const upb_FieldDef** sorted = NULL; + if (!m->is_sorted) { + sorted = _upb_FieldDefs_Sorted(m->fields, m->field_count, a); + if (!sorted) return false; } -#define FASTDECODE_STRING(d, ptr, msg, table, hasbits, data, tagbytes, card, \ - copyfunc, validate_utf8) \ - upb_StringView* dst; \ - fastdecode_arr farr; \ - int64_t size; \ - \ - if (UPB_UNLIKELY(!fastdecode_checktag(data, tagbytes))) { \ - RETURN_GENERIC("string field tag mismatch\n"); \ - } \ - \ - if (UPB_UNLIKELY( \ - !upb_EpsCopyInputStream_AliasingAvailable(&d->input, ptr, 0))) { \ - UPB_MUSTTAIL return copyfunc(UPB_PARSE_ARGS); \ - } \ - \ - dst = fastdecode_getfield(d, ptr, msg, &data, &hasbits, &farr, \ - sizeof(upb_StringView), card); \ - \ - again: \ - if (card == CARD_r) { \ - dst = fastdecode_resizearr(d, dst, &farr, sizeof(upb_StringView)); \ - } \ - \ - size = (int8_t)ptr[tagbytes]; \ - ptr += tagbytes + 1; \ - \ - if (UPB_UNLIKELY( \ - !upb_EpsCopyInputStream_AliasingAvailable(&d->input, ptr, size))) { \ - ptr--; \ - if (validate_utf8) { \ - return fastdecode_longstring_utf8(d, ptr, msg, table, hasbits, \ - (uint64_t)dst); \ - } else { \ - return fastdecode_longstring_noutf8(d, ptr, msg, table, hasbits, \ - (uint64_t)dst); \ - } \ - } \ - \ - dst->data = ptr; \ - dst->size = size; \ - ptr = upb_EpsCopyInputStream_ReadStringAliased(&d->input, &dst->data, \ - dst->size); \ - \ - if (card == CARD_r) { \ - if (validate_utf8 && \ - !_upb_Decoder_VerifyUtf8Inline(dst->data, dst->size)) { \ - _upb_FastDecoder_ErrorJmp(d, kUpb_DecodeStatus_BadUtf8); \ - } \ - fastdecode_nextret ret = fastdecode_nextrepeated( \ - d, dst, &ptr, &farr, data, tagbytes, sizeof(upb_StringView)); \ - switch (ret.next) { \ - case FD_NEXT_SAMEFIELD: \ - dst = ret.dst; \ - goto again; \ - case FD_NEXT_OTHERFIELD: \ - data = ret.tag; \ - UPB_MUSTTAIL return _upb_FastDecoder_TagDispatch(UPB_PARSE_ARGS); \ - case FD_NEXT_ATLIMIT: \ - return ptr; \ - } \ - } \ - \ - if (card != CARD_r && validate_utf8) { \ - data = (uint64_t)dst; \ - UPB_MUSTTAIL return fastdecode_verifyutf8(UPB_PARSE_ARGS); \ - } \ - \ - UPB_MUSTTAIL return fastdecode_dispatch(UPB_PARSE_ARGS); + s->ptr = upb_MtDataEncoder_StartMessage(&s->e, s->ptr, + _upb_MessageDef_Modifiers(m)); -/* Generate all combinations: - * {p,c} x {s,o,r} x {s, b} x {1bt,2bt} */ + for (int i = 0; i < m->field_count; i++) { + const upb_FieldDef* f = sorted ? sorted[i] : upb_MessageDef_Field(m, i); + const upb_FieldType type = upb_FieldDef_Type(f); + const int number = upb_FieldDef_Number(f); + const uint64_t modifiers = _upb_FieldDef_Modifiers(f); -#define s_VALIDATE true -#define b_VALIDATE false + if (!_upb_DescState_Grow(s, a)) return false; + s->ptr = upb_MtDataEncoder_PutField(&s->e, s->ptr, type, number, modifiers); + } -#define F(card, tagbytes, type) \ - UPB_NOINLINE \ - const char* upb_c##card##type##_##tagbytes##bt(UPB_PARSE_PARAMS) { \ - FASTDECODE_COPYSTRING(d, ptr, msg, table, hasbits, data, tagbytes, \ - CARD_##card, type##_VALIDATE); \ - } \ - const char* upb_p##card##type##_##tagbytes##bt(UPB_PARSE_PARAMS) { \ - FASTDECODE_STRING(d, ptr, msg, table, hasbits, data, tagbytes, \ - CARD_##card, upb_c##card##type##_##tagbytes##bt, \ - type##_VALIDATE); \ + for (int i = 0; i < m->real_oneof_count; i++) { + if (!_upb_DescState_Grow(s, a)) return false; + s->ptr = upb_MtDataEncoder_StartOneof(&s->e, s->ptr); + + const upb_OneofDef* o = upb_MessageDef_Oneof(m, i); + const int field_count = upb_OneofDef_FieldCount(o); + for (int j = 0; j < field_count; j++) { + const int number = upb_FieldDef_Number(upb_OneofDef_Field(o, j)); + + if (!_upb_DescState_Grow(s, a)) return false; + s->ptr = upb_MtDataEncoder_PutOneofField(&s->e, s->ptr, number); + } } -#define UTF8(card, tagbytes) \ - F(card, tagbytes, s) \ - F(card, tagbytes, b) + return true; +} -#define TAGBYTES(card) \ - UTF8(card, 1) \ - UTF8(card, 2) +static bool _upb_MessageDef_EncodeMessageSet(upb_DescState* s, + const upb_MessageDef* m, + upb_Arena* a) { + s->ptr = upb_MtDataEncoder_EncodeMessageSet(&s->e, s->ptr); -TAGBYTES(s) -TAGBYTES(o) -TAGBYTES(r) + return true; +} -#undef s_VALIDATE -#undef b_VALIDATE -#undef F -#undef TAGBYTES -#undef FASTDECODE_LONGSTRING -#undef FASTDECODE_COPYSTRING -#undef FASTDECODE_STRING +bool upb_MessageDef_MiniDescriptorEncode(const upb_MessageDef* m, upb_Arena* a, + upb_StringView* out) { + upb_DescState s; + _upb_DescState_Init(&s); -/* message fields *************************************************************/ + if (!_upb_DescState_Grow(&s, a)) return false; -UPB_INLINE -upb_Message* decode_newmsg_ceil(upb_Decoder* d, const upb_MiniTable* m, - int msg_ceil_bytes) { - size_t size = m->UPB_PRIVATE(size) + sizeof(upb_Message_Internal); - char* msg_data; - if (UPB_LIKELY(msg_ceil_bytes > 0 && - UPB_PRIVATE(_upb_ArenaHas)(&d->arena) >= msg_ceil_bytes)) { - UPB_ASSERT(size <= (size_t)msg_ceil_bytes); - msg_data = d->arena.UPB_PRIVATE(ptr); - d->arena.UPB_PRIVATE(ptr) += size; - UPB_UNPOISON_MEMORY_REGION(msg_data, msg_ceil_bytes); - memset(msg_data, 0, msg_ceil_bytes); - UPB_POISON_MEMORY_REGION(msg_data + size, msg_ceil_bytes - size); + if (upb_MessageDef_IsMapEntry(m)) { + if (!_upb_MessageDef_EncodeMap(&s, m, a)) return false; + } else if (UPB_DESC(MessageOptions_message_set_wire_format)(m->opts)) { + if (!_upb_MessageDef_EncodeMessageSet(&s, m, a)) return false; } else { - msg_data = (char*)upb_Arena_Malloc(&d->arena, size); - memset(msg_data, 0, size); + if (!_upb_MessageDef_EncodeMessage(&s, m, a)) return false; } - return msg_data + sizeof(upb_Message_Internal); -} -typedef struct { - intptr_t table; - upb_Message* msg; -} fastdecode_submsgdata; + if (!_upb_DescState_Grow(&s, a)) return false; + *s.ptr = '\0'; -UPB_FORCEINLINE -static const char* fastdecode_tosubmsg(upb_EpsCopyInputStream* e, - const char* ptr, void* ctx) { - upb_Decoder* d = (upb_Decoder*)e; - fastdecode_submsgdata* submsg = ctx; - ptr = fastdecode_dispatch(d, ptr, submsg->msg, submsg->table, 0, 0); - UPB_ASSUME(ptr != NULL); - return ptr; + out->data = s.buf; + out->size = s.ptr - s.buf; + return true; } -#define FASTDECODE_SUBMSG(d, ptr, msg, table, hasbits, data, tagbytes, \ - msg_ceil_bytes, card) \ - \ - if (UPB_UNLIKELY(!fastdecode_checktag(data, tagbytes))) { \ - RETURN_GENERIC("submessage field tag mismatch\n"); \ - } \ - \ - if (--d->depth == 0) { \ - _upb_FastDecoder_ErrorJmp(d, kUpb_DecodeStatus_MaxDepthExceeded); \ - } \ - \ - upb_Message** dst; \ - uint32_t submsg_idx = (data >> 16) & 0xff; \ - const upb_MiniTable* tablep = decode_totablep(table); \ - const upb_MiniTable* subtablep = upb_MiniTableSub_Message( \ - *UPB_PRIVATE(_upb_MiniTable_GetSubByIndex)(tablep, submsg_idx)); \ - fastdecode_submsgdata submsg = {decode_totable(subtablep)}; \ - fastdecode_arr farr; \ - \ - if (subtablep->UPB_PRIVATE(table_mask) == (uint8_t)-1) { \ - d->depth++; \ - RETURN_GENERIC("submessage doesn't have fast tables."); \ - } \ - \ - dst = fastdecode_getfield(d, ptr, msg, &data, &hasbits, &farr, \ - sizeof(upb_Message*), card); \ - \ - if (card == CARD_s) { \ - *(uint32_t*)msg |= hasbits; \ - hasbits = 0; \ - } \ - \ - again: \ - if (card == CARD_r) { \ - dst = fastdecode_resizearr(d, dst, &farr, sizeof(upb_Message*)); \ - } \ - \ - submsg.msg = *dst; \ - \ - if (card == CARD_r || UPB_LIKELY(!submsg.msg)) { \ - *dst = submsg.msg = decode_newmsg_ceil(d, subtablep, msg_ceil_bytes); \ - } \ - \ - ptr += tagbytes; \ - ptr = fastdecode_delimited(d, ptr, fastdecode_tosubmsg, &submsg); \ - \ - if (UPB_UNLIKELY(ptr == NULL || d->end_group != DECODE_NOGROUP)) { \ - _upb_FastDecoder_ErrorJmp(d, kUpb_DecodeStatus_Malformed); \ - } \ - \ - if (card == CARD_r) { \ - fastdecode_nextret ret = fastdecode_nextrepeated( \ - d, dst, &ptr, &farr, data, tagbytes, sizeof(upb_Message*)); \ - switch (ret.next) { \ - case FD_NEXT_SAMEFIELD: \ - dst = ret.dst; \ - goto again; \ - case FD_NEXT_OTHERFIELD: \ - d->depth++; \ - data = ret.tag; \ - UPB_MUSTTAIL return _upb_FastDecoder_TagDispatch(UPB_PARSE_ARGS); \ - case FD_NEXT_ATLIMIT: \ - d->depth++; \ - return ptr; \ - } \ - } \ - \ - d->depth++; \ - UPB_MUSTTAIL return fastdecode_dispatch(UPB_PARSE_ARGS); +static upb_StringView* _upb_ReservedNames_New(upb_DefBuilder* ctx, int n, + const upb_StringView* protos) { + upb_StringView* sv = _upb_DefBuilder_Alloc(ctx, sizeof(upb_StringView) * n); + for (int i = 0; i < n; i++) { + sv[i].data = + upb_strdup2(protos[i].data, protos[i].size, _upb_DefBuilder_Arena(ctx)); + sv[i].size = protos[i].size; + } + return sv; +} -#define F(card, tagbytes, size_ceil, ceil_arg) \ - const char* upb_p##card##m_##tagbytes##bt_max##size_ceil##b( \ - UPB_PARSE_PARAMS) { \ - FASTDECODE_SUBMSG(d, ptr, msg, table, hasbits, data, tagbytes, ceil_arg, \ - CARD_##card); \ +static void create_msgdef(upb_DefBuilder* ctx, const char* prefix, + const UPB_DESC(DescriptorProto*) msg_proto, + const UPB_DESC(FeatureSet*) parent_features, + const upb_MessageDef* containing_type, + upb_MessageDef* m) { + const UPB_DESC(OneofDescriptorProto)* const* oneofs; + const UPB_DESC(FieldDescriptorProto)* const* fields; + const UPB_DESC(DescriptorProto_ExtensionRange)* const* ext_ranges; + const UPB_DESC(DescriptorProto_ReservedRange)* const* res_ranges; + const upb_StringView* res_names; + size_t n_oneof, n_field, n_enum, n_ext, n_msg; + size_t n_ext_range, n_res_range, n_res_name; + upb_StringView name; + + UPB_DEF_SET_OPTIONS(m->opts, DescriptorProto, MessageOptions, msg_proto); + m->resolved_features = _upb_DefBuilder_ResolveFeatures( + ctx, parent_features, UPB_DESC(MessageOptions_features)(m->opts)); + + // Must happen before _upb_DefBuilder_Add() + m->file = _upb_DefBuilder_File(ctx); + + m->containing_type = containing_type; + m->is_sorted = true; + + name = UPB_DESC(DescriptorProto_name)(msg_proto); + + m->full_name = _upb_DefBuilder_MakeFullName(ctx, prefix, name); + _upb_DefBuilder_Add(ctx, m->full_name, _upb_DefType_Pack(m, UPB_DEFTYPE_MSG)); + + oneofs = UPB_DESC(DescriptorProto_oneof_decl)(msg_proto, &n_oneof); + fields = UPB_DESC(DescriptorProto_field)(msg_proto, &n_field); + ext_ranges = + UPB_DESC(DescriptorProto_extension_range)(msg_proto, &n_ext_range); + res_ranges = + UPB_DESC(DescriptorProto_reserved_range)(msg_proto, &n_res_range); + res_names = UPB_DESC(DescriptorProto_reserved_name)(msg_proto, &n_res_name); + + bool ok = upb_inttable_init(&m->itof, ctx->arena); + if (!ok) _upb_DefBuilder_OomErr(ctx); + + ok = upb_strtable_init(&m->ntof, n_oneof + n_field, ctx->arena); + if (!ok) _upb_DefBuilder_OomErr(ctx); + + ok = upb_strtable_init(&m->jtof, n_field, ctx->arena); + if (!ok) _upb_DefBuilder_OomErr(ctx); + + m->oneof_count = n_oneof; + m->oneofs = _upb_OneofDefs_New(ctx, n_oneof, oneofs, m->resolved_features, m); + + m->field_count = n_field; + m->fields = _upb_FieldDefs_New(ctx, n_field, fields, m->resolved_features, + m->full_name, m, &m->is_sorted); + + // Message Sets may not contain fields. + if (UPB_UNLIKELY(UPB_DESC(MessageOptions_message_set_wire_format)(m->opts))) { + if (UPB_UNLIKELY(n_field > 0)) { + _upb_DefBuilder_Errf(ctx, "invalid message set (%s)", m->full_name); + } } -#define SIZES(card, tagbytes) \ - F(card, tagbytes, 64, 64) \ - F(card, tagbytes, 128, 128) \ - F(card, tagbytes, 192, 192) \ - F(card, tagbytes, 256, 256) \ - F(card, tagbytes, max, -1) + m->ext_range_count = n_ext_range; + m->ext_ranges = _upb_ExtensionRanges_New(ctx, n_ext_range, ext_ranges, + m->resolved_features, m); + + m->res_range_count = n_res_range; + m->res_ranges = + _upb_MessageReservedRanges_New(ctx, n_res_range, res_ranges, m); + + m->res_name_count = n_res_name; + m->res_names = _upb_ReservedNames_New(ctx, n_res_name, res_names); + + const size_t synthetic_count = _upb_OneofDefs_Finalize(ctx, m); + m->real_oneof_count = m->oneof_count - synthetic_count; + + assign_msg_wellknowntype(m); + upb_inttable_compact(&m->itof, ctx->arena); + + const UPB_DESC(EnumDescriptorProto)* const* enums = + UPB_DESC(DescriptorProto_enum_type)(msg_proto, &n_enum); + m->nested_enum_count = n_enum; + m->nested_enums = + _upb_EnumDefs_New(ctx, n_enum, enums, m->resolved_features, m); + + const UPB_DESC(FieldDescriptorProto)* const* exts = + UPB_DESC(DescriptorProto_extension)(msg_proto, &n_ext); + m->nested_ext_count = n_ext; + m->nested_exts = _upb_Extensions_New(ctx, n_ext, exts, m->resolved_features, + m->full_name, m); + + const UPB_DESC(DescriptorProto)* const* msgs = + UPB_DESC(DescriptorProto_nested_type)(msg_proto, &n_msg); + m->nested_msg_count = n_msg; + m->nested_msgs = + _upb_MessageDefs_New(ctx, n_msg, msgs, m->resolved_features, m); +} + +// Allocate and initialize an array of |n| message defs. +upb_MessageDef* _upb_MessageDefs_New(upb_DefBuilder* ctx, int n, + const UPB_DESC(DescriptorProto*) + const* protos, + const UPB_DESC(FeatureSet*) + parent_features, + const upb_MessageDef* containing_type) { + _upb_DefType_CheckPadding(sizeof(upb_MessageDef)); + + const char* name = containing_type ? containing_type->full_name + : _upb_FileDef_RawPackage(ctx->file); -#define TAGBYTES(card) \ - SIZES(card, 1) \ - SIZES(card, 2) + upb_MessageDef* m = _upb_DefBuilder_Alloc(ctx, sizeof(upb_MessageDef) * n); + for (int i = 0; i < n; i++) { + create_msgdef(ctx, name, protos[i], parent_features, containing_type, + &m[i]); + } + return m; +} -TAGBYTES(s) -TAGBYTES(o) -TAGBYTES(r) -#undef TAGBYTES -#undef SIZES -#undef F -#undef FASTDECODE_SUBMSG +// Must be last. -#endif /* UPB_FASTTABLE */ +struct upb_MessageReservedRange { + int32_t start; + int32_t end; +}; +upb_MessageReservedRange* _upb_MessageReservedRange_At( + const upb_MessageReservedRange* r, int i) { + return (upb_MessageReservedRange*)&r[i]; +} -#include -#include +int32_t upb_MessageReservedRange_Start(const upb_MessageReservedRange* r) { + return r->start; +} +int32_t upb_MessageReservedRange_End(const upb_MessageReservedRange* r) { + return r->end; +} +upb_MessageReservedRange* _upb_MessageReservedRanges_New( + upb_DefBuilder* ctx, int n, + const UPB_DESC(DescriptorProto_ReservedRange) * const* protos, + const upb_MessageDef* m) { + upb_MessageReservedRange* r = + _upb_DefBuilder_Alloc(ctx, sizeof(upb_MessageReservedRange) * n); -// Must be last. + for (int i = 0; i < n; i++) { + const int32_t start = + UPB_DESC(DescriptorProto_ReservedRange_start)(protos[i]); + const int32_t end = UPB_DESC(DescriptorProto_ReservedRange_end)(protos[i]); + const int32_t max = kUpb_MaxFieldNumber + 1; -UPB_NOINLINE UPB_PRIVATE(_upb_WireReader_LongVarint) - UPB_PRIVATE(_upb_WireReader_ReadLongVarint)(const char* ptr, uint64_t val) { - UPB_PRIVATE(_upb_WireReader_LongVarint) ret = {NULL, 0}; - uint64_t byte; - int i; - for (i = 1; i < 10; i++) { - byte = (uint8_t)ptr[i]; - val += (byte - 1) << (i * 7); - if (!(byte & 0x80)) { - ret.ptr = ptr + i + 1; - ret.val = val; - return ret; + // A full validation would also check that each range is disjoint, and that + // none of the fields overlap with the extension ranges, but we are just + // sanity checking here. + if (start < 1 || end <= start || end > max) { + _upb_DefBuilder_Errf(ctx, + "Reserved range (%d, %d) is invalid, message=%s\n", + (int)start, (int)end, upb_MessageDef_FullName(m)); } - } - return ret; -} -const char* UPB_PRIVATE(_upb_WireReader_SkipGroup)( - const char* ptr, uint32_t tag, int depth_limit, - upb_EpsCopyInputStream* stream) { - if (--depth_limit == 0) return NULL; - uint32_t end_group_tag = (tag & ~7ULL) | kUpb_WireType_EndGroup; - while (!upb_EpsCopyInputStream_IsDone(stream, &ptr)) { - uint32_t tag; - ptr = upb_WireReader_ReadTag(ptr, &tag); - if (!ptr) return NULL; - if (tag == end_group_tag) return ptr; - ptr = _upb_WireReader_SkipValue(ptr, tag, depth_limit, stream); - if (!ptr) return NULL; + r[i].start = start; + r[i].end = end; } - return ptr; -} + return r; +} -#include // Must be last. -const struct upb_Extension* _upb_Message_Getext( - const struct upb_Message* msg, const upb_MiniTableExtension* e) { - size_t n; - const struct upb_Extension* ext = UPB_PRIVATE(_upb_Message_Getexts)(msg, &n); - - // For now we use linear search exclusively to find extensions. - // If this becomes an issue due to messages with lots of extensions, - // we can introduce a table of some sort. - for (size_t i = 0; i < n; i++) { - if (ext[i].ext == e) { - return &ext[i]; - } - } +struct upb_MethodDef { + const UPB_DESC(MethodOptions*) opts; + const UPB_DESC(FeatureSet*) resolved_features; + upb_ServiceDef* service; + const char* full_name; + const upb_MessageDef* input_type; + const upb_MessageDef* output_type; + int index; + bool client_streaming; + bool server_streaming; +}; - return NULL; +upb_MethodDef* _upb_MethodDef_At(const upb_MethodDef* m, int i) { + return (upb_MethodDef*)&m[i]; } -const struct upb_Extension* UPB_PRIVATE(_upb_Message_Getexts)( - const struct upb_Message* msg, size_t* count) { - upb_Message_InternalData* in = upb_Message_GetInternalData(msg); - if (in) { - *count = (in->size - in->ext_begin) / sizeof(struct upb_Extension); - return UPB_PTR_AT(in, in->ext_begin, void); - } else { - *count = 0; - return NULL; - } +const upb_ServiceDef* upb_MethodDef_Service(const upb_MethodDef* m) { + return m->service; } -struct upb_Extension* _upb_Message_GetOrCreateExtension( - struct upb_Message* msg, const upb_MiniTableExtension* e, upb_Arena* a) { - struct upb_Extension* ext = - (struct upb_Extension*)_upb_Message_Getext(msg, e); - if (ext) return ext; - if (!UPB_PRIVATE(_upb_Message_Realloc)(msg, sizeof(struct upb_Extension), a)) - return NULL; - upb_Message_InternalData* in = upb_Message_GetInternalData(msg); - in->ext_begin -= sizeof(struct upb_Extension); - ext = UPB_PTR_AT(in, in->ext_begin, void); - memset(ext, 0, sizeof(struct upb_Extension)); - ext->ext = e; - return ext; +const UPB_DESC(MethodOptions) * upb_MethodDef_Options(const upb_MethodDef* m) { + return m->opts; } +bool upb_MethodDef_HasOptions(const upb_MethodDef* m) { + return m->opts != (void*)kUpbDefOptDefault; +} -#include -#include - +const UPB_DESC(FeatureSet) * + upb_MethodDef_ResolvedFeatures(const upb_MethodDef* m) { + return m->resolved_features; +} -// Must be last. +const char* upb_MethodDef_FullName(const upb_MethodDef* m) { + return m->full_name; +} -const float kUpb_FltInfinity = INFINITY; -const double kUpb_Infinity = INFINITY; -const double kUpb_NaN = NAN; +const char* upb_MethodDef_Name(const upb_MethodDef* m) { + return _upb_DefBuilder_FullToShort(m->full_name); +} -bool UPB_PRIVATE(_upb_Message_Realloc)(struct upb_Message* msg, size_t need, - upb_Arena* a) { - const size_t overhead = sizeof(upb_Message_InternalData); +int upb_MethodDef_Index(const upb_MethodDef* m) { return m->index; } - upb_Message_Internal* owner = upb_Message_Getinternal(msg); - upb_Message_InternalData* in = owner->internal; - if (!in) { - // No internal data, allocate from scratch. - size_t size = UPB_MAX(128, upb_Log2CeilingSize(need + overhead)); - in = upb_Arena_Malloc(a, size); - if (!in) return false; +const upb_MessageDef* upb_MethodDef_InputType(const upb_MethodDef* m) { + return m->input_type; +} - in->size = size; - in->unknown_end = overhead; - in->ext_begin = size; - owner->internal = in; - } else if (in->ext_begin - in->unknown_end < need) { - // Internal data is too small, reallocate. - size_t new_size = upb_Log2CeilingSize(in->size + need); - size_t ext_bytes = in->size - in->ext_begin; - size_t new_ext_begin = new_size - ext_bytes; - in = upb_Arena_Realloc(a, in, in->size, new_size); - if (!in) return false; +const upb_MessageDef* upb_MethodDef_OutputType(const upb_MethodDef* m) { + return m->output_type; +} - if (ext_bytes) { - // Need to move extension data to the end. - char* ptr = (char*)in; - memmove(ptr + new_ext_begin, ptr + in->ext_begin, ext_bytes); - } - in->ext_begin = new_ext_begin; - in->size = new_size; - owner->internal = in; - } +bool upb_MethodDef_ClientStreaming(const upb_MethodDef* m) { + return m->client_streaming; +} - UPB_ASSERT(in->ext_begin - in->unknown_end >= need); - return true; +bool upb_MethodDef_ServerStreaming(const upb_MethodDef* m) { + return m->server_streaming; } +static void create_method(upb_DefBuilder* ctx, + const UPB_DESC(MethodDescriptorProto*) method_proto, + const UPB_DESC(FeatureSet*) parent_features, + upb_ServiceDef* s, upb_MethodDef* m) { + UPB_DEF_SET_OPTIONS(m->opts, MethodDescriptorProto, MethodOptions, + method_proto); + m->resolved_features = _upb_DefBuilder_ResolveFeatures( + ctx, parent_features, UPB_DESC(MethodOptions_features)(m->opts)); -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', '{', '|', '}', '~', -}; + upb_StringView name = UPB_DESC(MethodDescriptorProto_name)(method_proto); -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, -}; + m->service = s; + m->full_name = + _upb_DefBuilder_MakeFullName(ctx, upb_ServiceDef_FullName(s), name); + m->client_streaming = + UPB_DESC(MethodDescriptorProto_client_streaming)(method_proto); + m->server_streaming = + UPB_DESC(MethodDescriptorProto_server_streaming)(method_proto); + m->input_type = _upb_DefBuilder_Resolve( + ctx, m->full_name, m->full_name, + UPB_DESC(MethodDescriptorProto_input_type)(method_proto), + UPB_DEFTYPE_MSG); + m->output_type = _upb_DefBuilder_Resolve( + ctx, m->full_name, m->full_name, + UPB_DESC(MethodDescriptorProto_output_type)(method_proto), + UPB_DEFTYPE_MSG); +} + +// Allocate and initialize an array of |n| method defs belonging to |s|. +upb_MethodDef* _upb_MethodDefs_New(upb_DefBuilder* ctx, int n, + const UPB_DESC(MethodDescriptorProto*) + const* protos, + const UPB_DESC(FeatureSet*) parent_features, + upb_ServiceDef* s) { + upb_MethodDef* m = _upb_DefBuilder_Alloc(ctx, sizeof(upb_MethodDef) * n); + for (int i = 0; i < n; i++) { + create_method(ctx, protos[i], parent_features, s, &m[i]); + m[i].index = i; + } + return m; +} -#include -#include -#include +#include +#include +#include // Must be last. -typedef struct { - uint64_t present_values_mask; - uint32_t last_written_value; -} upb_MtDataEncoderInternal_EnumState; - -typedef struct { - uint64_t msg_modifiers; - uint32_t last_field_num; - enum { - kUpb_OneofState_NotStarted, - kUpb_OneofState_StartedOneof, - kUpb_OneofState_EmittedOneofField, - } oneof_state; -} upb_MtDataEncoderInternal_MsgState; +struct upb_OneofDef { + const UPB_DESC(OneofOptions*) opts; + const UPB_DESC(FeatureSet*) resolved_features; + const upb_MessageDef* parent; + const char* full_name; + int field_count; + bool synthetic; + const upb_FieldDef** fields; + upb_strtable ntof; // lookup a field by name + upb_inttable itof; // lookup a field by number (index) +}; -typedef struct { - char* buf_start; // Only for checking kUpb_MtDataEncoder_MinSize. - union { - upb_MtDataEncoderInternal_EnumState enum_state; - upb_MtDataEncoderInternal_MsgState msg_state; - } state; -} upb_MtDataEncoderInternal; +upb_OneofDef* _upb_OneofDef_At(const upb_OneofDef* o, int i) { + return (upb_OneofDef*)&o[i]; +} -static upb_MtDataEncoderInternal* upb_MtDataEncoder_GetInternal( - upb_MtDataEncoder* e, char* buf_start) { - UPB_ASSERT(sizeof(upb_MtDataEncoderInternal) <= sizeof(e->internal)); - upb_MtDataEncoderInternal* ret = (upb_MtDataEncoderInternal*)e->internal; - ret->buf_start = buf_start; - return ret; +const UPB_DESC(OneofOptions) * upb_OneofDef_Options(const upb_OneofDef* o) { + return o->opts; } -static char* upb_MtDataEncoder_PutRaw(upb_MtDataEncoder* e, char* ptr, - char ch) { - upb_MtDataEncoderInternal* in = (upb_MtDataEncoderInternal*)e->internal; - UPB_ASSERT(ptr - in->buf_start < kUpb_MtDataEncoder_MinSize); - if (ptr == e->end) return NULL; - *ptr++ = ch; - return ptr; +bool upb_OneofDef_HasOptions(const upb_OneofDef* o) { + return o->opts != (void*)kUpbDefOptDefault; } -static char* upb_MtDataEncoder_Put(upb_MtDataEncoder* e, char* ptr, char ch) { - return upb_MtDataEncoder_PutRaw(e, ptr, _upb_ToBase92(ch)); +const UPB_DESC(FeatureSet) * + upb_OneofDef_ResolvedFeatures(const upb_OneofDef* o) { + return o->resolved_features; } -static char* upb_MtDataEncoder_PutBase92Varint(upb_MtDataEncoder* e, char* ptr, - uint32_t val, int min, int max) { - int shift = upb_Log2Ceiling(_upb_FromBase92(max) - _upb_FromBase92(min) + 1); - UPB_ASSERT(shift <= 6); - uint32_t mask = (1 << shift) - 1; - do { - uint32_t bits = val & mask; - ptr = upb_MtDataEncoder_Put(e, ptr, bits + _upb_FromBase92(min)); - if (!ptr) return NULL; - val >>= shift; - } while (val); - return ptr; +const char* upb_OneofDef_FullName(const upb_OneofDef* o) { + return o->full_name; } -char* upb_MtDataEncoder_PutModifier(upb_MtDataEncoder* e, char* ptr, - uint64_t mod) { - if (mod) { - ptr = upb_MtDataEncoder_PutBase92Varint(e, ptr, mod, - kUpb_EncodedValue_MinModifier, - kUpb_EncodedValue_MaxModifier); - } - return ptr; +const char* upb_OneofDef_Name(const upb_OneofDef* o) { + return _upb_DefBuilder_FullToShort(o->full_name); } -char* upb_MtDataEncoder_EncodeExtension(upb_MtDataEncoder* e, char* ptr, - upb_FieldType type, uint32_t field_num, - uint64_t field_mod) { - upb_MtDataEncoderInternal* in = upb_MtDataEncoder_GetInternal(e, ptr); - in->state.msg_state.msg_modifiers = 0; - in->state.msg_state.last_field_num = 0; - in->state.msg_state.oneof_state = kUpb_OneofState_NotStarted; +const upb_MessageDef* upb_OneofDef_ContainingType(const upb_OneofDef* o) { + return o->parent; +} - ptr = upb_MtDataEncoder_PutRaw(e, ptr, kUpb_EncodedVersion_ExtensionV1); - if (!ptr) return NULL; +int upb_OneofDef_FieldCount(const upb_OneofDef* o) { return o->field_count; } - return upb_MtDataEncoder_PutField(e, ptr, type, field_num, field_mod); +const upb_FieldDef* upb_OneofDef_Field(const upb_OneofDef* o, int i) { + UPB_ASSERT(i < o->field_count); + return o->fields[i]; } -char* upb_MtDataEncoder_EncodeMap(upb_MtDataEncoder* e, char* ptr, - upb_FieldType key_type, - upb_FieldType value_type, uint64_t key_mod, - uint64_t value_mod) { - upb_MtDataEncoderInternal* in = upb_MtDataEncoder_GetInternal(e, ptr); - in->state.msg_state.msg_modifiers = 0; - in->state.msg_state.last_field_num = 0; - in->state.msg_state.oneof_state = kUpb_OneofState_NotStarted; +int upb_OneofDef_numfields(const upb_OneofDef* o) { return o->field_count; } - ptr = upb_MtDataEncoder_PutRaw(e, ptr, kUpb_EncodedVersion_MapV1); - if (!ptr) return NULL; +uint32_t upb_OneofDef_Index(const upb_OneofDef* o) { + // Compute index in our parent's array. + return o - upb_MessageDef_Oneof(o->parent, 0); +} - ptr = upb_MtDataEncoder_PutField(e, ptr, key_type, 1, key_mod); - if (!ptr) return NULL; +bool upb_OneofDef_IsSynthetic(const upb_OneofDef* o) { return o->synthetic; } - return upb_MtDataEncoder_PutField(e, ptr, value_type, 2, value_mod); +const upb_FieldDef* upb_OneofDef_LookupNameWithSize(const upb_OneofDef* o, + const char* name, + size_t size) { + upb_value val; + return upb_strtable_lookup2(&o->ntof, name, size, &val) + ? upb_value_getptr(val) + : NULL; } -char* upb_MtDataEncoder_EncodeMessageSet(upb_MtDataEncoder* e, char* ptr) { - (void)upb_MtDataEncoder_GetInternal(e, ptr); - return upb_MtDataEncoder_PutRaw(e, ptr, kUpb_EncodedVersion_MessageSetV1); +const upb_FieldDef* upb_OneofDef_LookupName(const upb_OneofDef* o, + const char* name) { + return upb_OneofDef_LookupNameWithSize(o, name, strlen(name)); } -char* upb_MtDataEncoder_StartMessage(upb_MtDataEncoder* e, char* ptr, - uint64_t msg_mod) { - upb_MtDataEncoderInternal* in = upb_MtDataEncoder_GetInternal(e, ptr); - in->state.msg_state.msg_modifiers = msg_mod; - in->state.msg_state.last_field_num = 0; - in->state.msg_state.oneof_state = kUpb_OneofState_NotStarted; +const upb_FieldDef* upb_OneofDef_LookupNumber(const upb_OneofDef* o, + uint32_t num) { + upb_value val; + return upb_inttable_lookup(&o->itof, num, &val) ? upb_value_getptr(val) + : NULL; +} - ptr = upb_MtDataEncoder_PutRaw(e, ptr, kUpb_EncodedVersion_MessageV1); - if (!ptr) return NULL; +void _upb_OneofDef_Insert(upb_DefBuilder* ctx, upb_OneofDef* o, + const upb_FieldDef* f, const char* name, + size_t size) { + o->field_count++; + if (_upb_FieldDef_IsProto3Optional(f)) o->synthetic = true; - return upb_MtDataEncoder_PutModifier(e, ptr, msg_mod); -} + const int number = upb_FieldDef_Number(f); + const upb_value v = upb_value_constptr(f); -static char* _upb_MtDataEncoder_MaybePutFieldSkip(upb_MtDataEncoder* e, - char* ptr, - uint32_t field_num) { - upb_MtDataEncoderInternal* in = (upb_MtDataEncoderInternal*)e->internal; - if (field_num <= in->state.msg_state.last_field_num) return NULL; - if (in->state.msg_state.last_field_num + 1 != field_num) { - // Put skip. - UPB_ASSERT(field_num > in->state.msg_state.last_field_num); - uint32_t skip = field_num - in->state.msg_state.last_field_num; - ptr = upb_MtDataEncoder_PutBase92Varint( - e, ptr, skip, kUpb_EncodedValue_MinSkip, kUpb_EncodedValue_MaxSkip); - if (!ptr) return NULL; + // TODO: This lookup is unfortunate because we also perform it when + // inserting into the message's table. Unfortunately that step occurs after + // this one and moving things around could be tricky so let's leave it for + // a future refactoring. + const bool number_exists = upb_inttable_lookup(&o->itof, number, NULL); + if (UPB_UNLIKELY(number_exists)) { + _upb_DefBuilder_Errf(ctx, "oneof fields have the same number (%d)", number); + } + + // TODO: More redundant work happening here. + const bool name_exists = upb_strtable_lookup2(&o->ntof, name, size, NULL); + if (UPB_UNLIKELY(name_exists)) { + _upb_DefBuilder_Errf(ctx, "oneof fields have the same name (%.*s)", + (int)size, name); + } + + const bool ok = upb_inttable_insert(&o->itof, number, v, ctx->arena) && + upb_strtable_insert(&o->ntof, name, size, v, ctx->arena); + if (UPB_UNLIKELY(!ok)) { + _upb_DefBuilder_OomErr(ctx); } - in->state.msg_state.last_field_num = field_num; - return ptr; } -static char* _upb_MtDataEncoder_PutFieldType(upb_MtDataEncoder* e, char* ptr, - upb_FieldType type, - uint64_t field_mod) { - static const char kUpb_TypeToEncoded[] = { - [kUpb_FieldType_Double] = kUpb_EncodedType_Double, - [kUpb_FieldType_Float] = kUpb_EncodedType_Float, - [kUpb_FieldType_Int64] = kUpb_EncodedType_Int64, - [kUpb_FieldType_UInt64] = kUpb_EncodedType_UInt64, - [kUpb_FieldType_Int32] = kUpb_EncodedType_Int32, - [kUpb_FieldType_Fixed64] = kUpb_EncodedType_Fixed64, - [kUpb_FieldType_Fixed32] = kUpb_EncodedType_Fixed32, - [kUpb_FieldType_Bool] = kUpb_EncodedType_Bool, - [kUpb_FieldType_String] = kUpb_EncodedType_String, - [kUpb_FieldType_Group] = kUpb_EncodedType_Group, - [kUpb_FieldType_Message] = kUpb_EncodedType_Message, - [kUpb_FieldType_Bytes] = kUpb_EncodedType_Bytes, - [kUpb_FieldType_UInt32] = kUpb_EncodedType_UInt32, - [kUpb_FieldType_Enum] = kUpb_EncodedType_OpenEnum, - [kUpb_FieldType_SFixed32] = kUpb_EncodedType_SFixed32, - [kUpb_FieldType_SFixed64] = kUpb_EncodedType_SFixed64, - [kUpb_FieldType_SInt32] = kUpb_EncodedType_SInt32, - [kUpb_FieldType_SInt64] = kUpb_EncodedType_SInt64, - }; +// Returns the synthetic count. +size_t _upb_OneofDefs_Finalize(upb_DefBuilder* ctx, upb_MessageDef* m) { + int synthetic_count = 0; - int encoded_type = kUpb_TypeToEncoded[type]; + for (int i = 0; i < upb_MessageDef_OneofCount(m); i++) { + upb_OneofDef* o = (upb_OneofDef*)upb_MessageDef_Oneof(m, i); - if (field_mod & kUpb_FieldModifier_IsClosedEnum) { - UPB_ASSERT(type == kUpb_FieldType_Enum); - encoded_type = kUpb_EncodedType_ClosedEnum; + if (o->synthetic && o->field_count != 1) { + _upb_DefBuilder_Errf(ctx, + "Synthetic oneofs must have one field, not %d: %s", + o->field_count, upb_OneofDef_Name(o)); + } + + if (o->synthetic) { + synthetic_count++; + } else if (synthetic_count != 0) { + _upb_DefBuilder_Errf( + ctx, "Synthetic oneofs must be after all other oneofs: %s", + upb_OneofDef_Name(o)); + } + + o->fields = + _upb_DefBuilder_Alloc(ctx, sizeof(upb_FieldDef*) * o->field_count); + o->field_count = 0; } - if (field_mod & kUpb_FieldModifier_IsRepeated) { - // Repeated fields shift the type number up (unlike other modifiers which - // are bit flags). - encoded_type += kUpb_EncodedType_RepeatedBase; + for (int i = 0; i < upb_MessageDef_FieldCount(m); i++) { + const upb_FieldDef* f = upb_MessageDef_Field(m, i); + upb_OneofDef* o = (upb_OneofDef*)upb_FieldDef_ContainingOneof(f); + if (o) { + o->fields[o->field_count++] = f; + } } - return upb_MtDataEncoder_Put(e, ptr, encoded_type); + return synthetic_count; } -static char* _upb_MtDataEncoder_MaybePutModifiers(upb_MtDataEncoder* e, - char* ptr, upb_FieldType type, - uint64_t field_mod) { - upb_MtDataEncoderInternal* in = (upb_MtDataEncoderInternal*)e->internal; - uint32_t encoded_modifiers = 0; - if ((field_mod & kUpb_FieldModifier_IsRepeated) && - upb_FieldType_IsPackable(type)) { - bool field_is_packed = field_mod & kUpb_FieldModifier_IsPacked; - bool default_is_packed = in->state.msg_state.msg_modifiers & - kUpb_MessageModifier_DefaultIsPacked; - if (field_is_packed != default_is_packed) { - encoded_modifiers |= kUpb_EncodedFieldModifier_FlipPacked; - } - } +static void create_oneofdef(upb_DefBuilder* ctx, upb_MessageDef* m, + const UPB_DESC(OneofDescriptorProto*) oneof_proto, + const UPB_DESC(FeatureSet*) parent_features, + const upb_OneofDef* _o) { + upb_OneofDef* o = (upb_OneofDef*)_o; - if (type == kUpb_FieldType_String) { - bool field_validates_utf8 = field_mod & kUpb_FieldModifier_ValidateUtf8; - bool message_validates_utf8 = - in->state.msg_state.msg_modifiers & kUpb_MessageModifier_ValidateUtf8; - if (field_validates_utf8 != message_validates_utf8) { - // Old binaries do not recognize the field modifier. We need the failure - // mode to be too lax rather than too strict. Our caller should have - // handled this (see _upb_MessageDef_ValidateUtf8()). - assert(!message_validates_utf8); - encoded_modifiers |= kUpb_EncodedFieldModifier_FlipValidateUtf8; - } - } + UPB_DEF_SET_OPTIONS(o->opts, OneofDescriptorProto, OneofOptions, oneof_proto); + o->resolved_features = _upb_DefBuilder_ResolveFeatures( + ctx, parent_features, UPB_DESC(OneofOptions_features)(o->opts)); - if (field_mod & kUpb_FieldModifier_IsProto3Singular) { - encoded_modifiers |= kUpb_EncodedFieldModifier_IsProto3Singular; - } + upb_StringView name = UPB_DESC(OneofDescriptorProto_name)(oneof_proto); - if (field_mod & kUpb_FieldModifier_IsRequired) { - encoded_modifiers |= kUpb_EncodedFieldModifier_IsRequired; + o->parent = m; + o->full_name = + _upb_DefBuilder_MakeFullName(ctx, upb_MessageDef_FullName(m), name); + o->field_count = 0; + o->synthetic = false; + + if (upb_MessageDef_FindByNameWithSize(m, name.data, name.size, NULL, NULL)) { + _upb_DefBuilder_Errf(ctx, "duplicate oneof name (%s)", o->full_name); } - return upb_MtDataEncoder_PutModifier(e, ptr, encoded_modifiers); + upb_value v = _upb_DefType_Pack(o, UPB_DEFTYPE_ONEOF); + bool ok = _upb_MessageDef_Insert(m, name.data, name.size, v, ctx->arena); + if (!ok) _upb_DefBuilder_OomErr(ctx); + + ok = upb_inttable_init(&o->itof, ctx->arena); + if (!ok) _upb_DefBuilder_OomErr(ctx); + + ok = upb_strtable_init(&o->ntof, 4, ctx->arena); + if (!ok) _upb_DefBuilder_OomErr(ctx); } -char* upb_MtDataEncoder_PutField(upb_MtDataEncoder* e, char* ptr, - upb_FieldType type, uint32_t field_num, - uint64_t field_mod) { - upb_MtDataEncoder_GetInternal(e, ptr); +// Allocate and initialize an array of |n| oneof defs. +upb_OneofDef* _upb_OneofDefs_New(upb_DefBuilder* ctx, int n, + const UPB_DESC(OneofDescriptorProto*) + const* protos, + const UPB_DESC(FeatureSet*) parent_features, + upb_MessageDef* m) { + _upb_DefType_CheckPadding(sizeof(upb_OneofDef)); - ptr = _upb_MtDataEncoder_MaybePutFieldSkip(e, ptr, field_num); - if (!ptr) return NULL; + upb_OneofDef* o = _upb_DefBuilder_Alloc(ctx, sizeof(upb_OneofDef) * n); + for (int i = 0; i < n; i++) { + create_oneofdef(ctx, m, protos[i], parent_features, &o[i]); + } + return o; +} - ptr = _upb_MtDataEncoder_PutFieldType(e, ptr, type, field_mod); - if (!ptr) return NULL; - return _upb_MtDataEncoder_MaybePutModifiers(e, ptr, type, field_mod); + +// Must be last. + +struct upb_ServiceDef { + const UPB_DESC(ServiceOptions*) opts; + const UPB_DESC(FeatureSet*) resolved_features; + const upb_FileDef* file; + const char* full_name; + upb_MethodDef* methods; + int method_count; + int index; +#if UINTPTR_MAX == 0xffffffff + uint32_t padding; // Increase size to a multiple of 8. +#endif +}; + +upb_ServiceDef* _upb_ServiceDef_At(const upb_ServiceDef* s, int index) { + return (upb_ServiceDef*)&s[index]; } -char* upb_MtDataEncoder_StartOneof(upb_MtDataEncoder* e, char* ptr) { - upb_MtDataEncoderInternal* in = upb_MtDataEncoder_GetInternal(e, ptr); - if (in->state.msg_state.oneof_state == kUpb_OneofState_NotStarted) { - ptr = upb_MtDataEncoder_Put(e, ptr, _upb_FromBase92(kUpb_EncodedValue_End)); - } else { - ptr = upb_MtDataEncoder_Put( - e, ptr, _upb_FromBase92(kUpb_EncodedValue_OneofSeparator)); - } - in->state.msg_state.oneof_state = kUpb_OneofState_StartedOneof; - return ptr; +const UPB_DESC(ServiceOptions) * + upb_ServiceDef_Options(const upb_ServiceDef* s) { + return s->opts; } -char* upb_MtDataEncoder_PutOneofField(upb_MtDataEncoder* e, char* ptr, - uint32_t field_num) { - upb_MtDataEncoderInternal* in = upb_MtDataEncoder_GetInternal(e, ptr); - if (in->state.msg_state.oneof_state == kUpb_OneofState_EmittedOneofField) { - ptr = upb_MtDataEncoder_Put( - e, ptr, _upb_FromBase92(kUpb_EncodedValue_FieldSeparator)); - if (!ptr) return NULL; - } - ptr = upb_MtDataEncoder_PutBase92Varint(e, ptr, field_num, _upb_ToBase92(0), - _upb_ToBase92(63)); - in->state.msg_state.oneof_state = kUpb_OneofState_EmittedOneofField; - return ptr; +bool upb_ServiceDef_HasOptions(const upb_ServiceDef* s) { + return s->opts != (void*)kUpbDefOptDefault; } -char* upb_MtDataEncoder_StartEnum(upb_MtDataEncoder* e, char* ptr) { - upb_MtDataEncoderInternal* in = upb_MtDataEncoder_GetInternal(e, ptr); - in->state.enum_state.present_values_mask = 0; - in->state.enum_state.last_written_value = 0; +const UPB_DESC(FeatureSet) * + upb_ServiceDef_ResolvedFeatures(const upb_ServiceDef* s) { + return s->resolved_features; +} - return upb_MtDataEncoder_PutRaw(e, ptr, kUpb_EncodedVersion_EnumV1); +const char* upb_ServiceDef_FullName(const upb_ServiceDef* s) { + return s->full_name; } -static char* upb_MtDataEncoder_FlushDenseEnumMask(upb_MtDataEncoder* e, - char* ptr) { - upb_MtDataEncoderInternal* in = (upb_MtDataEncoderInternal*)e->internal; - ptr = upb_MtDataEncoder_Put(e, ptr, in->state.enum_state.present_values_mask); - in->state.enum_state.present_values_mask = 0; - in->state.enum_state.last_written_value += 5; - return ptr; +const char* upb_ServiceDef_Name(const upb_ServiceDef* s) { + return _upb_DefBuilder_FullToShort(s->full_name); } -char* upb_MtDataEncoder_PutEnumValue(upb_MtDataEncoder* e, char* ptr, - uint32_t val) { - // TODO: optimize this encoding. - upb_MtDataEncoderInternal* in = upb_MtDataEncoder_GetInternal(e, ptr); - UPB_ASSERT(val >= in->state.enum_state.last_written_value); - uint32_t delta = val - in->state.enum_state.last_written_value; - if (delta >= 5 && in->state.enum_state.present_values_mask) { - ptr = upb_MtDataEncoder_FlushDenseEnumMask(e, ptr); - if (!ptr) { - return NULL; - } - delta -= 5; - } +int upb_ServiceDef_Index(const upb_ServiceDef* s) { return s->index; } - if (delta >= 5) { - ptr = upb_MtDataEncoder_PutBase92Varint( - e, ptr, delta, kUpb_EncodedValue_MinSkip, kUpb_EncodedValue_MaxSkip); - in->state.enum_state.last_written_value += delta; - delta = 0; - } +const upb_FileDef* upb_ServiceDef_File(const upb_ServiceDef* s) { + return s->file; +} - UPB_ASSERT((in->state.enum_state.present_values_mask >> delta) == 0); - in->state.enum_state.present_values_mask |= 1ULL << delta; - return ptr; +int upb_ServiceDef_MethodCount(const upb_ServiceDef* s) { + return s->method_count; } -char* upb_MtDataEncoder_EndEnum(upb_MtDataEncoder* e, char* ptr) { - upb_MtDataEncoderInternal* in = upb_MtDataEncoder_GetInternal(e, ptr); - if (!in->state.enum_state.present_values_mask) return ptr; - return upb_MtDataEncoder_FlushDenseEnumMask(e, ptr); +const upb_MethodDef* upb_ServiceDef_Method(const upb_ServiceDef* s, int i) { + return (i < 0 || i >= s->method_count) ? NULL + : _upb_MethodDef_At(s->methods, i); } +const upb_MethodDef* upb_ServiceDef_FindMethodByName(const upb_ServiceDef* s, + const char* name) { + for (int i = 0; i < s->method_count; i++) { + const upb_MethodDef* m = _upb_MethodDef_At(s->methods, i); + if (strcmp(name, upb_MethodDef_Name(m)) == 0) { + return m; + } + } + return NULL; +} -#include +static void create_service(upb_DefBuilder* ctx, + const UPB_DESC(ServiceDescriptorProto*) svc_proto, + const UPB_DESC(FeatureSet*) parent_features, + upb_ServiceDef* s) { + UPB_DEF_SET_OPTIONS(s->opts, ServiceDescriptorProto, ServiceOptions, + svc_proto); + s->resolved_features = _upb_DefBuilder_ResolveFeatures( + ctx, parent_features, UPB_DESC(ServiceOptions_features)(s->opts)); -// Must be last. + // Must happen before _upb_DefBuilder_Add() + s->file = _upb_DefBuilder_File(ctx); -// A MiniTable for an empty message, used for unlinked sub-messages. -const struct upb_MiniTable UPB_PRIVATE(_kUpb_MiniTable_Empty) = { - .UPB_PRIVATE(subs) = NULL, - .UPB_PRIVATE(fields) = NULL, - .UPB_PRIVATE(size) = 0, - .UPB_PRIVATE(field_count) = 0, - .UPB_PRIVATE(ext) = kUpb_ExtMode_NonExtendable, - .UPB_PRIVATE(dense_below) = 0, - .UPB_PRIVATE(table_mask) = -1, - .UPB_PRIVATE(required_count) = 0, -}; + upb_StringView name = UPB_DESC(ServiceDescriptorProto_name)(svc_proto); + const char* package = _upb_FileDef_RawPackage(s->file); + s->full_name = _upb_DefBuilder_MakeFullName(ctx, package, name); + _upb_DefBuilder_Add(ctx, s->full_name, + _upb_DefType_Pack(s, UPB_DEFTYPE_SERVICE)); + + size_t n; + const UPB_DESC(MethodDescriptorProto)* const* methods = + UPB_DESC(ServiceDescriptorProto_method)(svc_proto, &n); + s->method_count = n; + s->methods = _upb_MethodDefs_New(ctx, n, methods, s->resolved_features, s); +} + +upb_ServiceDef* _upb_ServiceDefs_New(upb_DefBuilder* ctx, int n, + const UPB_DESC(ServiceDescriptorProto*) + const* protos, + const UPB_DESC(FeatureSet*) + parent_features) { + _upb_DefType_CheckPadding(sizeof(upb_ServiceDef)); + + upb_ServiceDef* s = _upb_DefBuilder_Alloc(ctx, sizeof(upb_ServiceDef) * n); + for (int i = 0; i < n; i++) { + create_service(ctx, protos[i], parent_features, &s[i]); + s[i].index = i; + } + return s; +} // This should #undef all macros #defined in def.inc diff --git a/php/ext/google/protobuf/php-upb.h b/php/ext/google/protobuf/php-upb.h index a533b97709c24..0d3b3539b40ba 100644 --- a/php/ext/google/protobuf/php-upb.h +++ b/php/ext/google/protobuf/php-upb.h @@ -12067,108 +12067,6 @@ static UPB_FORCEINLINE bool upb_EpsCopyInputStream_TryParseDelimitedFast( #endif // UPB_WIRE_EPS_COPY_INPUT_STREAM_H_ -#ifndef UPB_BASE_INTERNAL_LOG2_H_ -#define UPB_BASE_INTERNAL_LOG2_H_ - -// Must be last. - -#ifdef __cplusplus -extern "C" { -#endif - -UPB_INLINE int upb_Log2Ceiling(int x) { - if (x <= 1) return 0; -#ifdef __GNUC__ - return 32 - __builtin_clz(x - 1); -#else - int lg2 = 0; - while ((1 << lg2) < x) lg2++; - return lg2; -#endif -} - -UPB_INLINE int upb_Log2CeilingSize(int x) { return 1 << upb_Log2Ceiling(x); } - -#ifdef __cplusplus -} /* extern "C" */ -#endif - - -#endif /* UPB_BASE_INTERNAL_LOG2_H_ */ - -#ifndef UPB_HASH_INT_TABLE_H_ -#define UPB_HASH_INT_TABLE_H_ - - -// Must be last. - -typedef struct { - upb_table t; // For entries that don't fit in the array part. - const upb_tabval* array; // Array part of the table. See const note above. - size_t array_size; // Array part size. - size_t array_count; // Array part number of elements. -} upb_inttable; - -#ifdef __cplusplus -extern "C" { -#endif - -// Initialize a table. If memory allocation failed, false is returned and -// the table is uninitialized. -bool upb_inttable_init(upb_inttable* table, upb_Arena* a); - -// Returns the number of values in the table. -size_t upb_inttable_count(const upb_inttable* t); - -// Inserts the given key into the hashtable with the given value. -// The key must not already exist in the hash table. -// The value must not be UINTPTR_MAX. -// -// If a table resize was required but memory allocation failed, false is -// returned and the table is unchanged. -bool upb_inttable_insert(upb_inttable* t, uintptr_t key, upb_value val, - upb_Arena* a); - -// Looks up key in this table, returning "true" if the key was found. -// If v is non-NULL, copies the value for this key into *v. -bool upb_inttable_lookup(const upb_inttable* t, uintptr_t key, upb_value* v); - -// Removes an item from the table. Returns true if the remove was successful, -// and stores the removed item in *val if non-NULL. -bool upb_inttable_remove(upb_inttable* t, uintptr_t key, upb_value* val); - -// Updates an existing entry in an inttable. -// If the entry does not exist, returns false and does nothing. -// Unlike insert/remove, this does not invalidate iterators. -bool upb_inttable_replace(upb_inttable* t, uintptr_t key, upb_value val); - -// Optimizes the table for the current set of entries, for both memory use and -// lookup time. Client should call this after all entries have been inserted; -// inserting more entries is legal, but will likely require a table resize. -void upb_inttable_compact(upb_inttable* t, upb_Arena* a); - -// Iteration over inttable: -// -// intptr_t iter = UPB_INTTABLE_BEGIN; -// uintptr_t key; -// upb_value val; -// while (upb_inttable_next(t, &key, &val, &iter)) { -// // ... -// } - -#define UPB_INTTABLE_BEGIN -1 - -bool upb_inttable_next(const upb_inttable* t, uintptr_t* key, upb_value* val, - intptr_t* iter); -void upb_inttable_removeiter(upb_inttable* t, intptr_t* iter); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - - -#endif /* UPB_HASH_INT_TABLE_H_ */ - #ifndef UPB_JSON_DECODE_H_ #define UPB_JSON_DECODE_H_ @@ -12436,24 +12334,6 @@ UPB_INLINE int _upb_vsnprintf(char* buf, size_t size, const char* fmt, #endif // UPB_PORT_VSNPRINTF_COMPAT_H_ -#ifndef UPB_LEX_STRTOD_H_ -#define UPB_LEX_STRTOD_H_ - -// Must be last. - -#ifdef __cplusplus -extern "C" { -#endif - -double _upb_NoLocaleStrtod(const char *str, char **endptr); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - - -#endif /* UPB_LEX_STRTOD_H_ */ - #ifndef UPB_PORT_ATOMIC_H_ #define UPB_PORT_ATOMIC_H_ @@ -12675,6 +12555,35 @@ bool _upb_mapsorter_pushexts(_upb_mapsorter* s, #endif /* UPB_MESSAGE_INTERNAL_MAP_SORTER_H_ */ +#ifndef UPB_BASE_INTERNAL_LOG2_H_ +#define UPB_BASE_INTERNAL_LOG2_H_ + +// Must be last. + +#ifdef __cplusplus +extern "C" { +#endif + +UPB_INLINE int upb_Log2Ceiling(int x) { + if (x <= 1) return 0; +#ifdef __GNUC__ + return 32 - __builtin_clz(x - 1); +#else + int lg2 = 0; + while ((1 << lg2) < x) lg2++; + return lg2; +#endif +} + +UPB_INLINE int upb_Log2CeilingSize(int x) { return 1 << upb_Log2Ceiling(x); } + +#ifdef __cplusplus +} /* extern "C" */ +#endif + + +#endif /* UPB_BASE_INTERNAL_LOG2_H_ */ + #ifndef UPB_MESSAGE_COMPARE_H_ #define UPB_MESSAGE_COMPARE_H_ @@ -12960,84 +12869,665 @@ upb_MiniTableEquals_Status upb_MiniTable_Equals(const upb_MiniTable* src, #endif /* UPB_MINI_TABLE_COMPAT_H_ */ -#ifndef UPB_REFLECTION_DEF_BUILDER_INTERNAL_H_ -#define UPB_REFLECTION_DEF_BUILDER_INTERNAL_H_ +#ifndef UPB_HASH_INT_TABLE_H_ +#define UPB_HASH_INT_TABLE_H_ // Must be last. -// We want to copy the options verbatim into the destination options proto. -// We use serialize+parse as our deep copy. -#define UPB_DEF_SET_OPTIONS(target, desc_type, options_type, proto) \ - if (UPB_DESC(desc_type##_has_options)(proto)) { \ - size_t size; \ - char* pb = UPB_DESC(options_type##_serialize)( \ - UPB_DESC(desc_type##_options)(proto), ctx->tmp_arena, &size); \ - if (!pb) _upb_DefBuilder_OomErr(ctx); \ - target = \ - UPB_DESC(options_type##_parse)(pb, size, _upb_DefBuilder_Arena(ctx)); \ - if (!target) _upb_DefBuilder_OomErr(ctx); \ - } else { \ - target = (const UPB_DESC(options_type)*)kUpbDefOptDefault; \ - } +typedef struct { + upb_table t; // For entries that don't fit in the array part. + const upb_tabval* array; // Array part of the table. See const note above. + size_t array_size; // Array part size. + size_t array_count; // Array part number of elements. +} upb_inttable; #ifdef __cplusplus extern "C" { #endif -struct upb_DefBuilder { - upb_DefPool* symtab; - upb_strtable feature_cache; // Caches features by identity. - UPB_DESC(FeatureSet*) legacy_features; // For computing legacy features. - char* tmp_buf; // Temporary buffer in tmp_arena. - size_t tmp_buf_size; // Size of temporary buffer. - upb_FileDef* file; // File we are building. - upb_Arena* arena; // Allocate defs here. - upb_Arena* tmp_arena; // For temporary allocations. - upb_Status* status; // Record errors here. - const upb_MiniTableFile* layout; // NULL if we should build layouts. - upb_MiniTablePlatform platform; // Platform we are targeting. - int enum_count; // Count of enums built so far. - int msg_count; // Count of messages built so far. - int ext_count; // Count of extensions built so far. - jmp_buf err; // longjmp() on error. -}; +// Initialize a table. If memory allocation failed, false is returned and +// the table is uninitialized. +bool upb_inttable_init(upb_inttable* table, upb_Arena* a); -extern const char* kUpbDefOptDefault; +// Returns the number of values in the table. +size_t upb_inttable_count(const upb_inttable* t); -// ctx->status has already been set elsewhere so just fail/longjmp() -UPB_NORETURN void _upb_DefBuilder_FailJmp(upb_DefBuilder* ctx); +// Inserts the given key into the hashtable with the given value. +// The key must not already exist in the hash table. +// The value must not be UINTPTR_MAX. +// +// If a table resize was required but memory allocation failed, false is +// returned and the table is unchanged. +bool upb_inttable_insert(upb_inttable* t, uintptr_t key, upb_value val, + upb_Arena* a); -UPB_NORETURN void _upb_DefBuilder_Errf(upb_DefBuilder* ctx, const char* fmt, - ...) UPB_PRINTF(2, 3); -UPB_NORETURN void _upb_DefBuilder_OomErr(upb_DefBuilder* ctx); +// Looks up key in this table, returning "true" if the key was found. +// If v is non-NULL, copies the value for this key into *v. +bool upb_inttable_lookup(const upb_inttable* t, uintptr_t key, upb_value* v); -const char* _upb_DefBuilder_MakeFullName(upb_DefBuilder* ctx, - const char* prefix, - upb_StringView name); +// Removes an item from the table. Returns true if the remove was successful, +// and stores the removed item in *val if non-NULL. +bool upb_inttable_remove(upb_inttable* t, uintptr_t key, upb_value* val); -// Given a symbol and the base symbol inside which it is defined, -// find the symbol's definition. -const void* _upb_DefBuilder_ResolveAny(upb_DefBuilder* ctx, - const char* from_name_dbg, - const char* base, upb_StringView sym, - upb_deftype_t* type); +// Updates an existing entry in an inttable. +// If the entry does not exist, returns false and does nothing. +// Unlike insert/remove, this does not invalidate iterators. +bool upb_inttable_replace(upb_inttable* t, uintptr_t key, upb_value val); -const void* _upb_DefBuilder_Resolve(upb_DefBuilder* ctx, - const char* from_name_dbg, const char* base, - upb_StringView sym, upb_deftype_t type); +// Optimizes the table for the current set of entries, for both memory use and +// lookup time. Client should call this after all entries have been inserted; +// inserting more entries is legal, but will likely require a table resize. +void upb_inttable_compact(upb_inttable* t, upb_Arena* a); -char _upb_DefBuilder_ParseEscape(upb_DefBuilder* ctx, const upb_FieldDef* f, - const char** src, const char* end); +// Iteration over inttable: +// +// intptr_t iter = UPB_INTTABLE_BEGIN; +// uintptr_t key; +// upb_value val; +// while (upb_inttable_next(t, &key, &val, &iter)) { +// // ... +// } -const char* _upb_DefBuilder_FullToShort(const char* fullname); +#define UPB_INTTABLE_BEGIN -1 -UPB_INLINE void* _upb_DefBuilder_Alloc(upb_DefBuilder* ctx, size_t bytes) { - if (bytes == 0) return NULL; - void* ret = upb_Arena_Malloc(ctx->arena, bytes); - if (!ret) _upb_DefBuilder_OomErr(ctx); - return ret; -} +bool upb_inttable_next(const upb_inttable* t, uintptr_t* key, upb_value* val, + intptr_t* iter); +void upb_inttable_removeiter(upb_inttable* t, intptr_t* iter); + +#ifdef __cplusplus +} /* extern "C" */ +#endif + + +#endif /* UPB_HASH_INT_TABLE_H_ */ + +#ifndef UPB_WIRE_INTERNAL_CONSTANTS_H_ +#define UPB_WIRE_INTERNAL_CONSTANTS_H_ + +#define kUpb_WireFormat_DefaultDepthLimit 100 + +// MessageSet wire format is: +// message MessageSet { +// repeated group Item = 1 { +// required int32 type_id = 2; +// required bytes message = 3; +// } +// } + +enum { + kUpb_MsgSet_Item = 1, + kUpb_MsgSet_TypeId = 2, + kUpb_MsgSet_Message = 3, +}; + +#endif /* UPB_WIRE_INTERNAL_CONSTANTS_H_ */ + +/* + * Internal implementation details of the decoder that are shared between + * decode.c and decode_fast.c. + */ + +#ifndef UPB_WIRE_INTERNAL_DECODER_H_ +#define UPB_WIRE_INTERNAL_DECODER_H_ + +#include "utf8_range.h" + +// Must be last. + +#define DECODE_NOGROUP (uint32_t) - 1 + +typedef struct upb_Decoder { + upb_EpsCopyInputStream input; + const upb_ExtensionRegistry* extreg; + const char* unknown; // Start of unknown data, preserve at buffer flip + upb_Message* unknown_msg; // Pointer to preserve data to + int depth; // Tracks recursion depth to bound stack usage. + uint32_t end_group; // field number of END_GROUP tag, else DECODE_NOGROUP. + uint16_t options; + bool missing_required; + union { + upb_Arena arena; + void* foo[UPB_ARENA_SIZE_HACK]; + }; + upb_DecodeStatus status; + jmp_buf err; + +#ifndef NDEBUG + const char* debug_tagstart; + const char* debug_valstart; +#endif +} upb_Decoder; + +/* Error function that will abort decoding with longjmp(). We can't declare this + * UPB_NORETURN, even though it is appropriate, because if we do then compilers + * will "helpfully" refuse to tailcall to it + * (see: https://stackoverflow.com/a/55657013), which will defeat a major goal + * of our optimizations. That is also why we must declare it in a separate file, + * otherwise the compiler will see that it calls longjmp() and deduce that it is + * noreturn. */ +const char* _upb_FastDecoder_ErrorJmp(upb_Decoder* d, int status); + +extern const uint8_t upb_utf8_offsets[]; + +UPB_INLINE +bool _upb_Decoder_VerifyUtf8Inline(const char* ptr, int len) { + return utf8_range_IsValid(ptr, len); +} + +const char* _upb_Decoder_CheckRequired(upb_Decoder* d, const char* ptr, + const upb_Message* msg, + const upb_MiniTable* m); + +/* x86-64 pointers always have the high 16 bits matching. So we can shift + * left 8 and right 8 without loss of information. */ +UPB_INLINE intptr_t decode_totable(const upb_MiniTable* tablep) { + return ((intptr_t)tablep << 8) | tablep->UPB_PRIVATE(table_mask); +} + +UPB_INLINE const upb_MiniTable* decode_totablep(intptr_t table) { + return (const upb_MiniTable*)(table >> 8); +} + +const char* _upb_Decoder_IsDoneFallback(upb_EpsCopyInputStream* e, + const char* ptr, int overrun); + +UPB_INLINE bool _upb_Decoder_IsDone(upb_Decoder* d, const char** ptr) { + return upb_EpsCopyInputStream_IsDoneWithCallback( + &d->input, ptr, &_upb_Decoder_IsDoneFallback); +} + +UPB_INLINE const char* _upb_Decoder_BufferFlipCallback( + upb_EpsCopyInputStream* e, const char* old_end, const char* new_start) { + upb_Decoder* d = (upb_Decoder*)e; + if (!old_end) _upb_FastDecoder_ErrorJmp(d, kUpb_DecodeStatus_Malformed); + + if (d->unknown) { + if (!UPB_PRIVATE(_upb_Message_AddUnknown)( + d->unknown_msg, d->unknown, old_end - d->unknown, &d->arena)) { + _upb_FastDecoder_ErrorJmp(d, kUpb_DecodeStatus_OutOfMemory); + } + d->unknown = new_start; + } + return new_start; +} + +#if UPB_FASTTABLE +UPB_INLINE +const char* _upb_FastDecoder_TagDispatch(upb_Decoder* d, const char* ptr, + upb_Message* msg, intptr_t table, + uint64_t hasbits, uint64_t tag) { + const upb_MiniTable* table_p = decode_totablep(table); + uint8_t mask = table; + uint64_t data; + size_t idx = tag & mask; + UPB_ASSUME((idx & 7) == 0); + idx >>= 3; + data = table_p->UPB_PRIVATE(fasttable)[idx].field_data ^ tag; + UPB_MUSTTAIL return table_p->UPB_PRIVATE(fasttable)[idx].field_parser( + d, ptr, msg, table, hasbits, data); +} +#endif + +UPB_INLINE uint32_t _upb_FastDecoder_LoadTag(const char* ptr) { + uint16_t tag; + memcpy(&tag, ptr, 2); + return tag; +} + + +#endif /* UPB_WIRE_INTERNAL_DECODER_H_ */ + +#ifndef UPB_WIRE_INTERNAL_ENDIAN_H_ +#define UPB_WIRE_INTERNAL_ENDIAN_H_ + +#include + +// Must be last. + +#ifdef __cplusplus +extern "C" { +#endif + +UPB_INLINE bool UPB_PRIVATE(_upb_IsLittleEndian)(void) { + const int x = 1; + return *(char*)&x == 1; +} + +UPB_INLINE uint32_t UPB_PRIVATE(_upb_BigEndian32)(uint32_t val) { + if (UPB_PRIVATE(_upb_IsLittleEndian)()) return val; + + return ((val & 0xff) << 24) | ((val & 0xff00) << 8) | + ((val & 0xff0000) >> 8) | ((val & 0xff000000) >> 24); +} + +UPB_INLINE uint64_t UPB_PRIVATE(_upb_BigEndian64)(uint64_t val) { + if (UPB_PRIVATE(_upb_IsLittleEndian)()) return val; + + return ((uint64_t)UPB_PRIVATE(_upb_BigEndian32)((uint32_t)val) << 32) | + UPB_PRIVATE(_upb_BigEndian32)((uint32_t)(val >> 32)); +} + +#ifdef __cplusplus +} /* extern "C" */ +#endif + + +#endif /* UPB_WIRE_INTERNAL_ENDIAN_H_ */ + +#ifndef UPB_WIRE_READER_H_ +#define UPB_WIRE_READER_H_ + + +#ifndef UPB_WIRE_INTERNAL_READER_H_ +#define UPB_WIRE_INTERNAL_READER_H_ + +// Must be last. + +#define kUpb_WireReader_WireTypeBits 3 +#define kUpb_WireReader_WireTypeMask 7 + +typedef struct { + const char* ptr; + uint64_t val; +} UPB_PRIVATE(_upb_WireReader_LongVarint); + +#ifdef __cplusplus +extern "C" { +#endif + +UPB_PRIVATE(_upb_WireReader_LongVarint) +UPB_PRIVATE(_upb_WireReader_ReadLongVarint)(const char* ptr, uint64_t val); + +static UPB_FORCEINLINE const char* UPB_PRIVATE(_upb_WireReader_ReadVarint)( + const char* ptr, uint64_t* val, int maxlen, uint64_t maxval) { + uint64_t byte = (uint8_t)*ptr; + if (UPB_LIKELY((byte & 0x80) == 0)) { + *val = (uint32_t)byte; + return ptr + 1; + } + const char* start = ptr; + UPB_PRIVATE(_upb_WireReader_LongVarint) + res = UPB_PRIVATE(_upb_WireReader_ReadLongVarint)(ptr, byte); + if (!res.ptr || (maxlen < 10 && res.ptr - start > maxlen) || + res.val > maxval) { + return NULL; // Malformed. + } + *val = res.val; + return res.ptr; +} + +UPB_INLINE uint32_t UPB_PRIVATE(_upb_WireReader_GetFieldNumber)(uint32_t tag) { + return tag >> kUpb_WireReader_WireTypeBits; +} + +UPB_INLINE uint8_t UPB_PRIVATE(_upb_WireReader_GetWireType)(uint32_t tag) { + return tag & kUpb_WireReader_WireTypeMask; +} + +#ifdef __cplusplus +} /* extern "C" */ +#endif + + +#endif // UPB_WIRE_INTERNAL_READER_H_ + +#ifndef UPB_WIRE_TYPES_H_ +#define UPB_WIRE_TYPES_H_ + +// A list of types as they are encoded on the wire. +typedef enum { + kUpb_WireType_Varint = 0, + kUpb_WireType_64Bit = 1, + kUpb_WireType_Delimited = 2, + kUpb_WireType_StartGroup = 3, + kUpb_WireType_EndGroup = 4, + kUpb_WireType_32Bit = 5 +} upb_WireType; + +#endif /* UPB_WIRE_TYPES_H_ */ + +// Must be last. + +// The upb_WireReader interface is suitable for general-purpose parsing of +// protobuf binary wire format. It is designed to be used along with +// upb_EpsCopyInputStream for buffering, and all parsing routines in this file +// assume that at least kUpb_EpsCopyInputStream_SlopBytes worth of data is +// available to read without any bounds checks. + +#ifdef __cplusplus +extern "C" { +#endif + +// Parses a tag into `tag`, and returns a pointer past the end of the tag, or +// NULL if there was an error in the tag data. +// +// REQUIRES: there must be at least 10 bytes of data available at `ptr`. +// Bounds checks must be performed before calling this function, preferably +// by calling upb_EpsCopyInputStream_IsDone(). +static UPB_FORCEINLINE const char* upb_WireReader_ReadTag(const char* ptr, + uint32_t* tag) { + uint64_t val; + ptr = UPB_PRIVATE(_upb_WireReader_ReadVarint)(ptr, &val, 5, UINT32_MAX); + if (!ptr) return NULL; + *tag = val; + return ptr; +} + +// Given a tag, returns the field number. +UPB_INLINE uint32_t upb_WireReader_GetFieldNumber(uint32_t tag) { + return UPB_PRIVATE(_upb_WireReader_GetFieldNumber)(tag); +} + +// Given a tag, returns the wire type. +UPB_INLINE uint8_t upb_WireReader_GetWireType(uint32_t tag) { + return UPB_PRIVATE(_upb_WireReader_GetWireType)(tag); +} + +UPB_INLINE const char* upb_WireReader_ReadVarint(const char* ptr, + uint64_t* val) { + return UPB_PRIVATE(_upb_WireReader_ReadVarint)(ptr, val, 10, UINT64_MAX); +} + +// Skips data for a varint, returning a pointer past the end of the varint, or +// NULL if there was an error in the varint data. +// +// REQUIRES: there must be at least 10 bytes of data available at `ptr`. +// Bounds checks must be performed before calling this function, preferably +// by calling upb_EpsCopyInputStream_IsDone(). +UPB_INLINE const char* upb_WireReader_SkipVarint(const char* ptr) { + uint64_t val; + return upb_WireReader_ReadVarint(ptr, &val); +} + +// Reads a varint indicating the size of a delimited field into `size`, or +// NULL if there was an error in the varint data. +// +// REQUIRES: there must be at least 10 bytes of data available at `ptr`. +// Bounds checks must be performed before calling this function, preferably +// by calling upb_EpsCopyInputStream_IsDone(). +UPB_INLINE const char* upb_WireReader_ReadSize(const char* ptr, int* size) { + uint64_t size64; + ptr = upb_WireReader_ReadVarint(ptr, &size64); + if (!ptr || size64 >= INT32_MAX) return NULL; + *size = size64; + return ptr; +} + +// Reads a fixed32 field, performing byte swapping if necessary. +// +// REQUIRES: there must be at least 4 bytes of data available at `ptr`. +// Bounds checks must be performed before calling this function, preferably +// by calling upb_EpsCopyInputStream_IsDone(). +UPB_INLINE const char* upb_WireReader_ReadFixed32(const char* ptr, void* val) { + uint32_t uval; + memcpy(&uval, ptr, 4); + uval = UPB_PRIVATE(_upb_BigEndian32)(uval); + memcpy(val, &uval, 4); + return ptr + 4; +} + +// Reads a fixed64 field, performing byte swapping if necessary. +// +// REQUIRES: there must be at least 4 bytes of data available at `ptr`. +// Bounds checks must be performed before calling this function, preferably +// by calling upb_EpsCopyInputStream_IsDone(). +UPB_INLINE const char* upb_WireReader_ReadFixed64(const char* ptr, void* val) { + uint64_t uval; + memcpy(&uval, ptr, 8); + uval = UPB_PRIVATE(_upb_BigEndian64)(uval); + memcpy(val, &uval, 8); + return ptr + 8; +} + +const char* UPB_PRIVATE(_upb_WireReader_SkipGroup)( + const char* ptr, uint32_t tag, int depth_limit, + upb_EpsCopyInputStream* stream); + +// Skips data for a group, returning a pointer past the end of the group, or +// NULL if there was an error parsing the group. The `tag` argument should be +// the start group tag that begins the group. The `depth_limit` argument +// indicates how many levels of recursion the group is allowed to have before +// reporting a parse error (this limit exists to protect against stack +// overflow). +// +// TODO: evaluate how the depth_limit should be specified. Do users need +// control over this? +UPB_INLINE const char* upb_WireReader_SkipGroup( + const char* ptr, uint32_t tag, upb_EpsCopyInputStream* stream) { + return UPB_PRIVATE(_upb_WireReader_SkipGroup)(ptr, tag, 100, stream); +} + +UPB_INLINE const char* _upb_WireReader_SkipValue( + const char* ptr, uint32_t tag, int depth_limit, + upb_EpsCopyInputStream* stream) { + switch (upb_WireReader_GetWireType(tag)) { + case kUpb_WireType_Varint: + return upb_WireReader_SkipVarint(ptr); + case kUpb_WireType_32Bit: + return ptr + 4; + case kUpb_WireType_64Bit: + return ptr + 8; + case kUpb_WireType_Delimited: { + int size; + ptr = upb_WireReader_ReadSize(ptr, &size); + if (!ptr) return NULL; + ptr += size; + return ptr; + } + case kUpb_WireType_StartGroup: + return UPB_PRIVATE(_upb_WireReader_SkipGroup)(ptr, tag, depth_limit, + stream); + case kUpb_WireType_EndGroup: + return NULL; // Should be handled before now. + default: + return NULL; // Unknown wire type. + } +} + +// Skips data for a wire value of any type, returning a pointer past the end of +// the data, or NULL if there was an error parsing the group. The `tag` argument +// should be the tag that was just parsed. The `depth_limit` argument indicates +// how many levels of recursion a group is allowed to have before reporting a +// parse error (this limit exists to protect against stack overflow). +// +// REQUIRES: there must be at least 10 bytes of data available at `ptr`. +// Bounds checks must be performed before calling this function, preferably +// by calling upb_EpsCopyInputStream_IsDone(). +// +// TODO: evaluate how the depth_limit should be specified. Do users need +// control over this? +UPB_INLINE const char* upb_WireReader_SkipValue( + const char* ptr, uint32_t tag, upb_EpsCopyInputStream* stream) { + return _upb_WireReader_SkipValue(ptr, tag, 100, stream); +} + +#ifdef __cplusplus +} /* extern "C" */ +#endif + + +#endif // UPB_WIRE_READER_H_ + +#ifndef UPB_LEX_STRTOD_H_ +#define UPB_LEX_STRTOD_H_ + +// Must be last. + +#ifdef __cplusplus +extern "C" { +#endif + +double _upb_NoLocaleStrtod(const char *str, char **endptr); + +#ifdef __cplusplus +} /* extern "C" */ +#endif + + +#endif /* UPB_LEX_STRTOD_H_ */ + +#ifndef UPB_MINI_DESCRIPTOR_INTERNAL_ENCODE_H_ +#define UPB_MINI_DESCRIPTOR_INTERNAL_ENCODE_H_ + +#include + + +// Must be last. + +// If the input buffer has at least this many bytes available, the encoder call +// is guaranteed to succeed (as long as field number order is maintained). +#define kUpb_MtDataEncoder_MinSize 16 + +typedef struct { + char* end; // Limit of the buffer passed as a parameter. + // Aliased to internal-only members in .cc. + char internal[32]; +} upb_MtDataEncoder; + +#ifdef __cplusplus +extern "C" { +#endif + +// Encodes field/oneof information for a given message. The sequence of calls +// should look like: +// +// upb_MtDataEncoder e; +// char buf[256]; +// char* ptr = buf; +// e.end = ptr + sizeof(buf); +// unit64_t msg_mod = ...; // bitwise & of kUpb_MessageModifiers or zero +// ptr = upb_MtDataEncoder_StartMessage(&e, ptr, msg_mod); +// // Fields *must* be in field number order. +// ptr = upb_MtDataEncoder_PutField(&e, ptr, ...); +// ptr = upb_MtDataEncoder_PutField(&e, ptr, ...); +// ptr = upb_MtDataEncoder_PutField(&e, ptr, ...); +// +// // If oneofs are present. Oneofs must be encoded after regular fields. +// ptr = upb_MiniTable_StartOneof(&e, ptr) +// ptr = upb_MiniTable_PutOneofField(&e, ptr, ...); +// ptr = upb_MiniTable_PutOneofField(&e, ptr, ...); +// +// ptr = upb_MiniTable_StartOneof(&e, ptr); +// ptr = upb_MiniTable_PutOneofField(&e, ptr, ...); +// ptr = upb_MiniTable_PutOneofField(&e, ptr, ...); +// +// Oneofs must be encoded after all regular fields. +char* upb_MtDataEncoder_StartMessage(upb_MtDataEncoder* e, char* ptr, + uint64_t msg_mod); +char* upb_MtDataEncoder_PutField(upb_MtDataEncoder* e, char* ptr, + upb_FieldType type, uint32_t field_num, + uint64_t field_mod); +char* upb_MtDataEncoder_StartOneof(upb_MtDataEncoder* e, char* ptr); +char* upb_MtDataEncoder_PutOneofField(upb_MtDataEncoder* e, char* ptr, + uint32_t field_num); + +// Encodes the set of values for a given enum. The values must be given in +// order (after casting to uint32_t), and repeats are not allowed. +char* upb_MtDataEncoder_StartEnum(upb_MtDataEncoder* e, char* ptr); +char* upb_MtDataEncoder_PutEnumValue(upb_MtDataEncoder* e, char* ptr, + uint32_t val); +char* upb_MtDataEncoder_EndEnum(upb_MtDataEncoder* e, char* ptr); + +// Encodes an entire mini descriptor for an extension. +char* upb_MtDataEncoder_EncodeExtension(upb_MtDataEncoder* e, char* ptr, + upb_FieldType type, uint32_t field_num, + uint64_t field_mod); + +// Encodes an entire mini descriptor for a map. +char* upb_MtDataEncoder_EncodeMap(upb_MtDataEncoder* e, char* ptr, + upb_FieldType key_type, + upb_FieldType value_type, uint64_t key_mod, + uint64_t value_mod); + +// Encodes an entire mini descriptor for a message set. +char* upb_MtDataEncoder_EncodeMessageSet(upb_MtDataEncoder* e, char* ptr); + +#ifdef __cplusplus +} /* extern "C" */ +#endif + + +#endif /* UPB_MINI_DESCRIPTOR_INTERNAL_ENCODE_H_ */ + +#ifndef UPB_REFLECTION_DEF_BUILDER_INTERNAL_H_ +#define UPB_REFLECTION_DEF_BUILDER_INTERNAL_H_ + + +// Must be last. + +// We want to copy the options verbatim into the destination options proto. +// We use serialize+parse as our deep copy. +#define UPB_DEF_SET_OPTIONS(target, desc_type, options_type, proto) \ + if (UPB_DESC(desc_type##_has_options)(proto)) { \ + size_t size; \ + char* pb = UPB_DESC(options_type##_serialize)( \ + UPB_DESC(desc_type##_options)(proto), ctx->tmp_arena, &size); \ + if (!pb) _upb_DefBuilder_OomErr(ctx); \ + target = \ + UPB_DESC(options_type##_parse)(pb, size, _upb_DefBuilder_Arena(ctx)); \ + if (!target) _upb_DefBuilder_OomErr(ctx); \ + } else { \ + target = (const UPB_DESC(options_type)*)kUpbDefOptDefault; \ + } + +#ifdef __cplusplus +extern "C" { +#endif + +struct upb_DefBuilder { + upb_DefPool* symtab; + upb_strtable feature_cache; // Caches features by identity. + UPB_DESC(FeatureSet*) legacy_features; // For computing legacy features. + char* tmp_buf; // Temporary buffer in tmp_arena. + size_t tmp_buf_size; // Size of temporary buffer. + upb_FileDef* file; // File we are building. + upb_Arena* arena; // Allocate defs here. + upb_Arena* tmp_arena; // For temporary allocations. + upb_Status* status; // Record errors here. + const upb_MiniTableFile* layout; // NULL if we should build layouts. + upb_MiniTablePlatform platform; // Platform we are targeting. + int enum_count; // Count of enums built so far. + int msg_count; // Count of messages built so far. + int ext_count; // Count of extensions built so far. + jmp_buf err; // longjmp() on error. +}; + +extern const char* kUpbDefOptDefault; + +// ctx->status has already been set elsewhere so just fail/longjmp() +UPB_NORETURN void _upb_DefBuilder_FailJmp(upb_DefBuilder* ctx); + +UPB_NORETURN void _upb_DefBuilder_Errf(upb_DefBuilder* ctx, const char* fmt, + ...) UPB_PRINTF(2, 3); +UPB_NORETURN void _upb_DefBuilder_OomErr(upb_DefBuilder* ctx); + +const char* _upb_DefBuilder_MakeFullName(upb_DefBuilder* ctx, + const char* prefix, + upb_StringView name); + +// Given a symbol and the base symbol inside which it is defined, +// find the symbol's definition. +const void* _upb_DefBuilder_ResolveAny(upb_DefBuilder* ctx, + const char* from_name_dbg, + const char* base, upb_StringView sym, + upb_deftype_t* type); + +const void* _upb_DefBuilder_Resolve(upb_DefBuilder* ctx, + const char* from_name_dbg, const char* base, + upb_StringView sym, upb_deftype_t type); + +char _upb_DefBuilder_ParseEscape(upb_DefBuilder* ctx, const upb_FieldDef* f, + const char** src, const char* end); + +const char* _upb_DefBuilder_FullToShort(const char* fullname); + +UPB_INLINE void* _upb_DefBuilder_Alloc(upb_DefBuilder* ctx, size_t bytes) { + if (bytes == 0) return NULL; + void* ret = upb_Arena_Malloc(ctx->arena, bytes); + if (!ret) _upb_DefBuilder_OomErr(ctx); + return ret; +} // Adds a symbol |v| to the symtab, which must be a def pointer previously // packed with pack_def(). The def's pointer to upb_FileDef* must be set before @@ -13310,103 +13800,20 @@ upb_ServiceDef* _upb_ServiceDefs_New(upb_DefBuilder* ctx, int n, #ifndef UPB_REFLECTION_UPB_EDITION_DEFAULTS_H_ #define UPB_REFLECTION_UPB_EDITION_DEFAULTS_H_ -// This file contains the serialized FeatureSetDefaults object for -// language-independent features and (possibly at some point) for upb-specific -// features. This is used for feature resolution under Editions. -// NOLINTBEGIN -// clang-format off -#define UPB_INTERNAL_UPB_EDITION_DEFAULTS "\n\021\022\014\010\001\020\002\030\002 \003(\0010\002\030\346\007\n\021\022\014\010\002\020\001\030\001 \002(\0010\001\030\347\007\n\021\022\014\010\001\020\001\030\001 \002(\0010\001\030\350\007 \346\007(\350\007" -// clang-format on -// NOLINTEND - -#endif // UPB_REFLECTION_UPB_EDITION_DEFAULTS_H_ - -#ifndef UPB_REFLECTION_DESC_STATE_INTERNAL_H_ -#define UPB_REFLECTION_DESC_STATE_INTERNAL_H_ - - -#ifndef UPB_MINI_DESCRIPTOR_INTERNAL_ENCODE_H_ -#define UPB_MINI_DESCRIPTOR_INTERNAL_ENCODE_H_ - -#include - - -// Must be last. - -// If the input buffer has at least this many bytes available, the encoder call -// is guaranteed to succeed (as long as field number order is maintained). -#define kUpb_MtDataEncoder_MinSize 16 - -typedef struct { - char* end; // Limit of the buffer passed as a parameter. - // Aliased to internal-only members in .cc. - char internal[32]; -} upb_MtDataEncoder; - -#ifdef __cplusplus -extern "C" { -#endif - -// Encodes field/oneof information for a given message. The sequence of calls -// should look like: -// -// upb_MtDataEncoder e; -// char buf[256]; -// char* ptr = buf; -// e.end = ptr + sizeof(buf); -// unit64_t msg_mod = ...; // bitwise & of kUpb_MessageModifiers or zero -// ptr = upb_MtDataEncoder_StartMessage(&e, ptr, msg_mod); -// // Fields *must* be in field number order. -// ptr = upb_MtDataEncoder_PutField(&e, ptr, ...); -// ptr = upb_MtDataEncoder_PutField(&e, ptr, ...); -// ptr = upb_MtDataEncoder_PutField(&e, ptr, ...); -// -// // If oneofs are present. Oneofs must be encoded after regular fields. -// ptr = upb_MiniTable_StartOneof(&e, ptr) -// ptr = upb_MiniTable_PutOneofField(&e, ptr, ...); -// ptr = upb_MiniTable_PutOneofField(&e, ptr, ...); -// -// ptr = upb_MiniTable_StartOneof(&e, ptr); -// ptr = upb_MiniTable_PutOneofField(&e, ptr, ...); -// ptr = upb_MiniTable_PutOneofField(&e, ptr, ...); -// -// Oneofs must be encoded after all regular fields. -char* upb_MtDataEncoder_StartMessage(upb_MtDataEncoder* e, char* ptr, - uint64_t msg_mod); -char* upb_MtDataEncoder_PutField(upb_MtDataEncoder* e, char* ptr, - upb_FieldType type, uint32_t field_num, - uint64_t field_mod); -char* upb_MtDataEncoder_StartOneof(upb_MtDataEncoder* e, char* ptr); -char* upb_MtDataEncoder_PutOneofField(upb_MtDataEncoder* e, char* ptr, - uint32_t field_num); - -// Encodes the set of values for a given enum. The values must be given in -// order (after casting to uint32_t), and repeats are not allowed. -char* upb_MtDataEncoder_StartEnum(upb_MtDataEncoder* e, char* ptr); -char* upb_MtDataEncoder_PutEnumValue(upb_MtDataEncoder* e, char* ptr, - uint32_t val); -char* upb_MtDataEncoder_EndEnum(upb_MtDataEncoder* e, char* ptr); - -// Encodes an entire mini descriptor for an extension. -char* upb_MtDataEncoder_EncodeExtension(upb_MtDataEncoder* e, char* ptr, - upb_FieldType type, uint32_t field_num, - uint64_t field_mod); - -// Encodes an entire mini descriptor for a map. -char* upb_MtDataEncoder_EncodeMap(upb_MtDataEncoder* e, char* ptr, - upb_FieldType key_type, - upb_FieldType value_type, uint64_t key_mod, - uint64_t value_mod); - -// Encodes an entire mini descriptor for a message set. -char* upb_MtDataEncoder_EncodeMessageSet(upb_MtDataEncoder* e, char* ptr); +// This file contains the serialized FeatureSetDefaults object for +// language-independent features and (possibly at some point) for upb-specific +// features. This is used for feature resolution under Editions. +// NOLINTBEGIN +// clang-format off +#define UPB_INTERNAL_UPB_EDITION_DEFAULTS "\n\021\022\014\010\001\020\002\030\002 \003(\0010\002\030\346\007\n\021\022\014\010\002\020\001\030\001 \002(\0010\001\030\347\007\n\021\022\014\010\001\020\001\030\001 \002(\0010\001\030\350\007 \346\007(\350\007" +// clang-format on +// NOLINTEND -#ifdef __cplusplus -} /* extern "C" */ -#endif +#endif // UPB_REFLECTION_UPB_EDITION_DEFAULTS_H_ +#ifndef UPB_REFLECTION_DESC_STATE_INTERNAL_H_ +#define UPB_REFLECTION_DESC_STATE_INTERNAL_H_ -#endif /* UPB_MINI_DESCRIPTOR_INTERNAL_ENCODE_H_ */ // Must be last. @@ -13544,506 +13951,99 @@ upb_ExtensionRange* _upb_ExtensionRanges_New( extern "C" { #endif -upb_OneofDef* _upb_OneofDef_At(const upb_OneofDef* o, int i); -void _upb_OneofDef_Insert(upb_DefBuilder* ctx, upb_OneofDef* o, - const upb_FieldDef* f, const char* name, size_t size); - -// Allocate and initialize an array of |n| oneof defs owned by |m|. -upb_OneofDef* _upb_OneofDefs_New(upb_DefBuilder* ctx, int n, - const UPB_DESC(OneofDescriptorProto*) - const* protos, - const UPB_DESC(FeatureSet*) parent_features, - upb_MessageDef* m); - -size_t _upb_OneofDefs_Finalize(upb_DefBuilder* ctx, upb_MessageDef* m); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - - -#endif /* UPB_REFLECTION_ONEOF_DEF_INTERNAL_H_ */ - -#ifndef UPB_REFLECTION_MESSAGE_RESERVED_RANGE_INTERNAL_H_ -#define UPB_REFLECTION_MESSAGE_RESERVED_RANGE_INTERNAL_H_ - - -// IWYU pragma: private, include "upb/reflection/def.h" - -#ifndef UPB_REFLECTION_MESSAGE_RESERVED_RANGE_H_ -#define UPB_REFLECTION_MESSAGE_RESERVED_RANGE_H_ - - -// Must be last. - -#ifdef __cplusplus -extern "C" { -#endif - -int32_t upb_MessageReservedRange_Start(const upb_MessageReservedRange* r); -int32_t upb_MessageReservedRange_End(const upb_MessageReservedRange* r); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - - -#endif /* UPB_REFLECTION_MESSAGE_RESERVED_RANGE_H_ */ - -// Must be last. - -#ifdef __cplusplus -extern "C" { -#endif - -upb_MessageReservedRange* _upb_MessageReservedRange_At( - const upb_MessageReservedRange* r, int i); - -// Allocate and initialize an array of |n| reserved ranges owned by |m|. -upb_MessageReservedRange* _upb_MessageReservedRanges_New( - upb_DefBuilder* ctx, int n, - const UPB_DESC(DescriptorProto_ReservedRange) * const* protos, - const upb_MessageDef* m); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - - -#endif /* UPB_REFLECTION_MESSAGE_RESERVED_RANGE_INTERNAL_H_ */ - -#ifndef UPB_REFLECTION_METHOD_DEF_INTERNAL_H_ -#define UPB_REFLECTION_METHOD_DEF_INTERNAL_H_ - - -// Must be last. - -#ifdef __cplusplus -extern "C" { -#endif - -upb_MethodDef* _upb_MethodDef_At(const upb_MethodDef* m, int i); - -// Allocate and initialize an array of |n| method defs owned by |s|. -upb_MethodDef* _upb_MethodDefs_New(upb_DefBuilder* ctx, int n, - const UPB_DESC(MethodDescriptorProto*) - const* protos, - const UPB_DESC(FeatureSet*) parent_features, - upb_ServiceDef* s); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - - -#endif /* UPB_REFLECTION_METHOD_DEF_INTERNAL_H_ */ - -#ifndef UPB_WIRE_INTERNAL_CONSTANTS_H_ -#define UPB_WIRE_INTERNAL_CONSTANTS_H_ - -#define kUpb_WireFormat_DefaultDepthLimit 100 - -// MessageSet wire format is: -// message MessageSet { -// repeated group Item = 1 { -// required int32 type_id = 2; -// required bytes message = 3; -// } -// } - -enum { - kUpb_MsgSet_Item = 1, - kUpb_MsgSet_TypeId = 2, - kUpb_MsgSet_Message = 3, -}; - -#endif /* UPB_WIRE_INTERNAL_CONSTANTS_H_ */ - -/* - * Internal implementation details of the decoder that are shared between - * decode.c and decode_fast.c. - */ - -#ifndef UPB_WIRE_INTERNAL_DECODER_H_ -#define UPB_WIRE_INTERNAL_DECODER_H_ - -#include "utf8_range.h" - -// Must be last. - -#define DECODE_NOGROUP (uint32_t) - 1 - -typedef struct upb_Decoder { - upb_EpsCopyInputStream input; - const upb_ExtensionRegistry* extreg; - const char* unknown; // Start of unknown data, preserve at buffer flip - upb_Message* unknown_msg; // Pointer to preserve data to - int depth; // Tracks recursion depth to bound stack usage. - uint32_t end_group; // field number of END_GROUP tag, else DECODE_NOGROUP. - uint16_t options; - bool missing_required; - union { - upb_Arena arena; - void* foo[UPB_ARENA_SIZE_HACK]; - }; - upb_DecodeStatus status; - jmp_buf err; - -#ifndef NDEBUG - const char* debug_tagstart; - const char* debug_valstart; -#endif -} upb_Decoder; - -/* Error function that will abort decoding with longjmp(). We can't declare this - * UPB_NORETURN, even though it is appropriate, because if we do then compilers - * will "helpfully" refuse to tailcall to it - * (see: https://stackoverflow.com/a/55657013), which will defeat a major goal - * of our optimizations. That is also why we must declare it in a separate file, - * otherwise the compiler will see that it calls longjmp() and deduce that it is - * noreturn. */ -const char* _upb_FastDecoder_ErrorJmp(upb_Decoder* d, int status); - -extern const uint8_t upb_utf8_offsets[]; - -UPB_INLINE -bool _upb_Decoder_VerifyUtf8Inline(const char* ptr, int len) { - return utf8_range_IsValid(ptr, len); -} - -const char* _upb_Decoder_CheckRequired(upb_Decoder* d, const char* ptr, - const upb_Message* msg, - const upb_MiniTable* m); - -/* x86-64 pointers always have the high 16 bits matching. So we can shift - * left 8 and right 8 without loss of information. */ -UPB_INLINE intptr_t decode_totable(const upb_MiniTable* tablep) { - return ((intptr_t)tablep << 8) | tablep->UPB_PRIVATE(table_mask); -} - -UPB_INLINE const upb_MiniTable* decode_totablep(intptr_t table) { - return (const upb_MiniTable*)(table >> 8); -} - -const char* _upb_Decoder_IsDoneFallback(upb_EpsCopyInputStream* e, - const char* ptr, int overrun); - -UPB_INLINE bool _upb_Decoder_IsDone(upb_Decoder* d, const char** ptr) { - return upb_EpsCopyInputStream_IsDoneWithCallback( - &d->input, ptr, &_upb_Decoder_IsDoneFallback); -} - -UPB_INLINE const char* _upb_Decoder_BufferFlipCallback( - upb_EpsCopyInputStream* e, const char* old_end, const char* new_start) { - upb_Decoder* d = (upb_Decoder*)e; - if (!old_end) _upb_FastDecoder_ErrorJmp(d, kUpb_DecodeStatus_Malformed); - - if (d->unknown) { - if (!UPB_PRIVATE(_upb_Message_AddUnknown)( - d->unknown_msg, d->unknown, old_end - d->unknown, &d->arena)) { - _upb_FastDecoder_ErrorJmp(d, kUpb_DecodeStatus_OutOfMemory); - } - d->unknown = new_start; - } - return new_start; -} - -#if UPB_FASTTABLE -UPB_INLINE -const char* _upb_FastDecoder_TagDispatch(upb_Decoder* d, const char* ptr, - upb_Message* msg, intptr_t table, - uint64_t hasbits, uint64_t tag) { - const upb_MiniTable* table_p = decode_totablep(table); - uint8_t mask = table; - uint64_t data; - size_t idx = tag & mask; - UPB_ASSUME((idx & 7) == 0); - idx >>= 3; - data = table_p->UPB_PRIVATE(fasttable)[idx].field_data ^ tag; - UPB_MUSTTAIL return table_p->UPB_PRIVATE(fasttable)[idx].field_parser( - d, ptr, msg, table, hasbits, data); -} -#endif - -UPB_INLINE uint32_t _upb_FastDecoder_LoadTag(const char* ptr) { - uint16_t tag; - memcpy(&tag, ptr, 2); - return tag; -} - - -#endif /* UPB_WIRE_INTERNAL_DECODER_H_ */ - -#ifndef UPB_WIRE_INTERNAL_ENDIAN_H_ -#define UPB_WIRE_INTERNAL_ENDIAN_H_ - -#include - -// Must be last. - -#ifdef __cplusplus -extern "C" { -#endif - -UPB_INLINE bool UPB_PRIVATE(_upb_IsLittleEndian)(void) { - const int x = 1; - return *(char*)&x == 1; -} - -UPB_INLINE uint32_t UPB_PRIVATE(_upb_BigEndian32)(uint32_t val) { - if (UPB_PRIVATE(_upb_IsLittleEndian)()) return val; - - return ((val & 0xff) << 24) | ((val & 0xff00) << 8) | - ((val & 0xff0000) >> 8) | ((val & 0xff000000) >> 24); -} +upb_OneofDef* _upb_OneofDef_At(const upb_OneofDef* o, int i); +void _upb_OneofDef_Insert(upb_DefBuilder* ctx, upb_OneofDef* o, + const upb_FieldDef* f, const char* name, size_t size); -UPB_INLINE uint64_t UPB_PRIVATE(_upb_BigEndian64)(uint64_t val) { - if (UPB_PRIVATE(_upb_IsLittleEndian)()) return val; +// Allocate and initialize an array of |n| oneof defs owned by |m|. +upb_OneofDef* _upb_OneofDefs_New(upb_DefBuilder* ctx, int n, + const UPB_DESC(OneofDescriptorProto*) + const* protos, + const UPB_DESC(FeatureSet*) parent_features, + upb_MessageDef* m); - return ((uint64_t)UPB_PRIVATE(_upb_BigEndian32)((uint32_t)val) << 32) | - UPB_PRIVATE(_upb_BigEndian32)((uint32_t)(val >> 32)); -} +size_t _upb_OneofDefs_Finalize(upb_DefBuilder* ctx, upb_MessageDef* m); #ifdef __cplusplus } /* extern "C" */ #endif -#endif /* UPB_WIRE_INTERNAL_ENDIAN_H_ */ +#endif /* UPB_REFLECTION_ONEOF_DEF_INTERNAL_H_ */ -#ifndef UPB_WIRE_READER_H_ -#define UPB_WIRE_READER_H_ +#ifndef UPB_REFLECTION_MESSAGE_RESERVED_RANGE_INTERNAL_H_ +#define UPB_REFLECTION_MESSAGE_RESERVED_RANGE_INTERNAL_H_ -#ifndef UPB_WIRE_INTERNAL_READER_H_ -#define UPB_WIRE_INTERNAL_READER_H_ +// IWYU pragma: private, include "upb/reflection/def.h" -// Must be last. +#ifndef UPB_REFLECTION_MESSAGE_RESERVED_RANGE_H_ +#define UPB_REFLECTION_MESSAGE_RESERVED_RANGE_H_ -#define kUpb_WireReader_WireTypeBits 3 -#define kUpb_WireReader_WireTypeMask 7 -typedef struct { - const char* ptr; - uint64_t val; -} UPB_PRIVATE(_upb_WireReader_LongVarint); +// Must be last. #ifdef __cplusplus extern "C" { #endif -UPB_PRIVATE(_upb_WireReader_LongVarint) -UPB_PRIVATE(_upb_WireReader_ReadLongVarint)(const char* ptr, uint64_t val); - -static UPB_FORCEINLINE const char* UPB_PRIVATE(_upb_WireReader_ReadVarint)( - const char* ptr, uint64_t* val, int maxlen, uint64_t maxval) { - uint64_t byte = (uint8_t)*ptr; - if (UPB_LIKELY((byte & 0x80) == 0)) { - *val = (uint32_t)byte; - return ptr + 1; - } - const char* start = ptr; - UPB_PRIVATE(_upb_WireReader_LongVarint) - res = UPB_PRIVATE(_upb_WireReader_ReadLongVarint)(ptr, byte); - if (!res.ptr || (maxlen < 10 && res.ptr - start > maxlen) || - res.val > maxval) { - return NULL; // Malformed. - } - *val = res.val; - return res.ptr; -} - -UPB_INLINE uint32_t UPB_PRIVATE(_upb_WireReader_GetFieldNumber)(uint32_t tag) { - return tag >> kUpb_WireReader_WireTypeBits; -} - -UPB_INLINE uint8_t UPB_PRIVATE(_upb_WireReader_GetWireType)(uint32_t tag) { - return tag & kUpb_WireReader_WireTypeMask; -} +int32_t upb_MessageReservedRange_Start(const upb_MessageReservedRange* r); +int32_t upb_MessageReservedRange_End(const upb_MessageReservedRange* r); #ifdef __cplusplus } /* extern "C" */ #endif -#endif // UPB_WIRE_INTERNAL_READER_H_ - -#ifndef UPB_WIRE_TYPES_H_ -#define UPB_WIRE_TYPES_H_ - -// A list of types as they are encoded on the wire. -typedef enum { - kUpb_WireType_Varint = 0, - kUpb_WireType_64Bit = 1, - kUpb_WireType_Delimited = 2, - kUpb_WireType_StartGroup = 3, - kUpb_WireType_EndGroup = 4, - kUpb_WireType_32Bit = 5 -} upb_WireType; - -#endif /* UPB_WIRE_TYPES_H_ */ +#endif /* UPB_REFLECTION_MESSAGE_RESERVED_RANGE_H_ */ // Must be last. -// The upb_WireReader interface is suitable for general-purpose parsing of -// protobuf binary wire format. It is designed to be used along with -// upb_EpsCopyInputStream for buffering, and all parsing routines in this file -// assume that at least kUpb_EpsCopyInputStream_SlopBytes worth of data is -// available to read without any bounds checks. - #ifdef __cplusplus extern "C" { #endif -// Parses a tag into `tag`, and returns a pointer past the end of the tag, or -// NULL if there was an error in the tag data. -// -// REQUIRES: there must be at least 10 bytes of data available at `ptr`. -// Bounds checks must be performed before calling this function, preferably -// by calling upb_EpsCopyInputStream_IsDone(). -static UPB_FORCEINLINE const char* upb_WireReader_ReadTag(const char* ptr, - uint32_t* tag) { - uint64_t val; - ptr = UPB_PRIVATE(_upb_WireReader_ReadVarint)(ptr, &val, 5, UINT32_MAX); - if (!ptr) return NULL; - *tag = val; - return ptr; -} - -// Given a tag, returns the field number. -UPB_INLINE uint32_t upb_WireReader_GetFieldNumber(uint32_t tag) { - return UPB_PRIVATE(_upb_WireReader_GetFieldNumber)(tag); -} +upb_MessageReservedRange* _upb_MessageReservedRange_At( + const upb_MessageReservedRange* r, int i); -// Given a tag, returns the wire type. -UPB_INLINE uint8_t upb_WireReader_GetWireType(uint32_t tag) { - return UPB_PRIVATE(_upb_WireReader_GetWireType)(tag); -} +// Allocate and initialize an array of |n| reserved ranges owned by |m|. +upb_MessageReservedRange* _upb_MessageReservedRanges_New( + upb_DefBuilder* ctx, int n, + const UPB_DESC(DescriptorProto_ReservedRange) * const* protos, + const upb_MessageDef* m); -UPB_INLINE const char* upb_WireReader_ReadVarint(const char* ptr, - uint64_t* val) { - return UPB_PRIVATE(_upb_WireReader_ReadVarint)(ptr, val, 10, UINT64_MAX); -} +#ifdef __cplusplus +} /* extern "C" */ +#endif -// Skips data for a varint, returning a pointer past the end of the varint, or -// NULL if there was an error in the varint data. -// -// REQUIRES: there must be at least 10 bytes of data available at `ptr`. -// Bounds checks must be performed before calling this function, preferably -// by calling upb_EpsCopyInputStream_IsDone(). -UPB_INLINE const char* upb_WireReader_SkipVarint(const char* ptr) { - uint64_t val; - return upb_WireReader_ReadVarint(ptr, &val); -} -// Reads a varint indicating the size of a delimited field into `size`, or -// NULL if there was an error in the varint data. -// -// REQUIRES: there must be at least 10 bytes of data available at `ptr`. -// Bounds checks must be performed before calling this function, preferably -// by calling upb_EpsCopyInputStream_IsDone(). -UPB_INLINE const char* upb_WireReader_ReadSize(const char* ptr, int* size) { - uint64_t size64; - ptr = upb_WireReader_ReadVarint(ptr, &size64); - if (!ptr || size64 >= INT32_MAX) return NULL; - *size = size64; - return ptr; -} +#endif /* UPB_REFLECTION_MESSAGE_RESERVED_RANGE_INTERNAL_H_ */ -// Reads a fixed32 field, performing byte swapping if necessary. -// -// REQUIRES: there must be at least 4 bytes of data available at `ptr`. -// Bounds checks must be performed before calling this function, preferably -// by calling upb_EpsCopyInputStream_IsDone(). -UPB_INLINE const char* upb_WireReader_ReadFixed32(const char* ptr, void* val) { - uint32_t uval; - memcpy(&uval, ptr, 4); - uval = UPB_PRIVATE(_upb_BigEndian32)(uval); - memcpy(val, &uval, 4); - return ptr + 4; -} +#ifndef UPB_REFLECTION_METHOD_DEF_INTERNAL_H_ +#define UPB_REFLECTION_METHOD_DEF_INTERNAL_H_ -// Reads a fixed64 field, performing byte swapping if necessary. -// -// REQUIRES: there must be at least 4 bytes of data available at `ptr`. -// Bounds checks must be performed before calling this function, preferably -// by calling upb_EpsCopyInputStream_IsDone(). -UPB_INLINE const char* upb_WireReader_ReadFixed64(const char* ptr, void* val) { - uint64_t uval; - memcpy(&uval, ptr, 8); - uval = UPB_PRIVATE(_upb_BigEndian64)(uval); - memcpy(val, &uval, 8); - return ptr + 8; -} -const char* UPB_PRIVATE(_upb_WireReader_SkipGroup)( - const char* ptr, uint32_t tag, int depth_limit, - upb_EpsCopyInputStream* stream); +// Must be last. -// Skips data for a group, returning a pointer past the end of the group, or -// NULL if there was an error parsing the group. The `tag` argument should be -// the start group tag that begins the group. The `depth_limit` argument -// indicates how many levels of recursion the group is allowed to have before -// reporting a parse error (this limit exists to protect against stack -// overflow). -// -// TODO: evaluate how the depth_limit should be specified. Do users need -// control over this? -UPB_INLINE const char* upb_WireReader_SkipGroup( - const char* ptr, uint32_t tag, upb_EpsCopyInputStream* stream) { - return UPB_PRIVATE(_upb_WireReader_SkipGroup)(ptr, tag, 100, stream); -} +#ifdef __cplusplus +extern "C" { +#endif -UPB_INLINE const char* _upb_WireReader_SkipValue( - const char* ptr, uint32_t tag, int depth_limit, - upb_EpsCopyInputStream* stream) { - switch (upb_WireReader_GetWireType(tag)) { - case kUpb_WireType_Varint: - return upb_WireReader_SkipVarint(ptr); - case kUpb_WireType_32Bit: - return ptr + 4; - case kUpb_WireType_64Bit: - return ptr + 8; - case kUpb_WireType_Delimited: { - int size; - ptr = upb_WireReader_ReadSize(ptr, &size); - if (!ptr) return NULL; - ptr += size; - return ptr; - } - case kUpb_WireType_StartGroup: - return UPB_PRIVATE(_upb_WireReader_SkipGroup)(ptr, tag, depth_limit, - stream); - case kUpb_WireType_EndGroup: - return NULL; // Should be handled before now. - default: - return NULL; // Unknown wire type. - } -} +upb_MethodDef* _upb_MethodDef_At(const upb_MethodDef* m, int i); -// Skips data for a wire value of any type, returning a pointer past the end of -// the data, or NULL if there was an error parsing the group. The `tag` argument -// should be the tag that was just parsed. The `depth_limit` argument indicates -// how many levels of recursion a group is allowed to have before reporting a -// parse error (this limit exists to protect against stack overflow). -// -// REQUIRES: there must be at least 10 bytes of data available at `ptr`. -// Bounds checks must be performed before calling this function, preferably -// by calling upb_EpsCopyInputStream_IsDone(). -// -// TODO: evaluate how the depth_limit should be specified. Do users need -// control over this? -UPB_INLINE const char* upb_WireReader_SkipValue( - const char* ptr, uint32_t tag, upb_EpsCopyInputStream* stream) { - return _upb_WireReader_SkipValue(ptr, tag, 100, stream); -} +// Allocate and initialize an array of |n| method defs owned by |s|. +upb_MethodDef* _upb_MethodDefs_New(upb_DefBuilder* ctx, int n, + const UPB_DESC(MethodDescriptorProto*) + const* protos, + const UPB_DESC(FeatureSet*) parent_features, + upb_ServiceDef* s); #ifdef __cplusplus } /* extern "C" */ #endif -#endif // UPB_WIRE_READER_H_ +#endif /* UPB_REFLECTION_METHOD_DEF_INTERNAL_H_ */ // This should #undef all macros #defined in def.inc diff --git a/ruby/ext/google/protobuf_c/ruby-upb.c b/ruby/ext/google/protobuf_c/ruby-upb.c index e2dbc47fe486a..87f95d0ab10e6 100644 --- a/ruby/ext/google/protobuf_c/ruby-upb.c +++ b/ruby/ext/google/protobuf_c/ruby-upb.c @@ -1760,2284 +1760,2056 @@ const char* _upb_EpsCopyInputStream_IsDoneFallbackNoCallback( e, ptr, overrun, _upb_EpsCopyInputStream_NoOpCallback); } -/* - * upb_table Implementation - * - * Implementation is heavily inspired by Lua's ltable.c. - */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include // Must be last. -#define UPB_MAXARRSIZE 16 // 2**16 = 64k. - -// From Chromium. -#define ARRAY_SIZE(x) \ - ((sizeof(x) / sizeof(0 [x])) / ((size_t)(!(sizeof(x) % sizeof(0 [x]))))) +typedef struct { + const char *ptr, *end; + upb_Arena* arena; /* TODO: should we have a tmp arena for tmp data? */ + const upb_DefPool* symtab; + int depth; + upb_Status* status; + jmp_buf err; + int line; + const char* line_begin; + bool is_first; + int options; + const upb_FieldDef* debug_field; +} jsondec; -static const double MAX_LOAD = 0.85; +typedef struct { + upb_MessageValue value; + bool ignore; +} upb_JsonMessageValue; -/* The minimum utilization of the array part of a mixed hash/array table. This - * is a speed/memory-usage tradeoff (though it's not straightforward because of - * cache effects). The lower this is, the more memory we'll use. */ -static const double MIN_DENSITY = 0.1; +enum { JD_OBJECT, JD_ARRAY, JD_STRING, JD_NUMBER, JD_TRUE, JD_FALSE, JD_NULL }; -static bool is_pow2(uint64_t v) { return v == 0 || (v & (v - 1)) == 0; } +/* Forward declarations of mutually-recursive functions. */ +static void jsondec_wellknown(jsondec* d, upb_Message* msg, + const upb_MessageDef* m); +static upb_JsonMessageValue jsondec_value(jsondec* d, const upb_FieldDef* f); +static void jsondec_wellknownvalue(jsondec* d, upb_Message* msg, + const upb_MessageDef* m); +static void jsondec_object(jsondec* d, upb_Message* msg, + const upb_MessageDef* m); -static upb_value _upb_value_val(uint64_t val) { - upb_value ret; - _upb_value_setval(&ret, val); - return ret; +static bool jsondec_streql(upb_StringView str, const char* lit) { + return str.size == strlen(lit) && memcmp(str.data, lit, str.size) == 0; } -static int log2ceil(uint64_t v) { - int ret = 0; - bool pow2 = is_pow2(v); - while (v >>= 1) ret++; - ret = pow2 ? ret : ret + 1; // Ceiling. - return UPB_MIN(UPB_MAXARRSIZE, ret); +static bool jsondec_isnullvalue(const upb_FieldDef* f) { + return upb_FieldDef_CType(f) == kUpb_CType_Enum && + strcmp(upb_EnumDef_FullName(upb_FieldDef_EnumSubDef(f)), + "google.protobuf.NullValue") == 0; } -/* A type to represent the lookup key of either a strtable or an inttable. */ -typedef union { - uintptr_t num; - struct { - const char* str; - size_t len; - } str; -} lookupkey_t; - -static lookupkey_t strkey2(const char* str, size_t len) { - lookupkey_t k; - k.str.str = str; - k.str.len = len; - return k; +static bool jsondec_isvalue(const upb_FieldDef* f) { + return (upb_FieldDef_CType(f) == kUpb_CType_Message && + upb_MessageDef_WellKnownType(upb_FieldDef_MessageSubDef(f)) == + kUpb_WellKnown_Value) || + jsondec_isnullvalue(f); } -static lookupkey_t intkey(uintptr_t key) { - lookupkey_t k; - k.num = key; - return k; +static void jsondec_seterrmsg(jsondec* d, const char* msg) { + upb_Status_SetErrorFormat(d->status, "Error parsing JSON @%d:%d: %s", d->line, + (int)(d->ptr - d->line_begin), msg); } -typedef uint32_t hashfunc_t(upb_tabkey key); -typedef bool eqlfunc_t(upb_tabkey k1, lookupkey_t k2); - -/* Base table (shared code) ***************************************************/ - -static uint32_t upb_inthash(uintptr_t key) { return (uint32_t)key; } - -static const upb_tabent* upb_getentry(const upb_table* t, uint32_t hash) { - return t->entries + (hash & t->mask); +UPB_NORETURN static void jsondec_err(jsondec* d, const char* msg) { + jsondec_seterrmsg(d, msg); + UPB_LONGJMP(d->err, 1); } -static bool upb_arrhas(upb_tabval key) { return key.val != (uint64_t)-1; } - -static bool isfull(upb_table* t) { return t->count == t->max_count; } - -static bool init(upb_table* t, uint8_t size_lg2, upb_Arena* a) { - size_t bytes; +UPB_PRINTF(2, 3) +UPB_NORETURN static void jsondec_errf(jsondec* d, const char* fmt, ...) { + va_list argp; + upb_Status_SetErrorFormat(d->status, "Error parsing JSON @%d:%d: ", d->line, + (int)(d->ptr - d->line_begin)); + va_start(argp, fmt); + upb_Status_VAppendErrorFormat(d->status, fmt, argp); + va_end(argp); + UPB_LONGJMP(d->err, 1); +} - t->count = 0; - t->size_lg2 = size_lg2; - t->mask = upb_table_size(t) ? upb_table_size(t) - 1 : 0; - t->max_count = upb_table_size(t) * MAX_LOAD; - bytes = upb_table_size(t) * sizeof(upb_tabent); - if (bytes > 0) { - t->entries = upb_Arena_Malloc(a, bytes); - if (!t->entries) return false; - memset(t->entries, 0, bytes); - } else { - t->entries = NULL; +// Advances d->ptr until the next non-whitespace character or to the end of +// the buffer. +static void jsondec_consumews(jsondec* d) { + while (d->ptr != d->end) { + switch (*d->ptr) { + case '\n': + d->line++; + d->line_begin = d->ptr; + /* Fallthrough. */ + case '\r': + case '\t': + case ' ': + d->ptr++; + break; + default: + return; + } } - return true; } -static upb_tabent* emptyent(upb_table* t, upb_tabent* e) { - upb_tabent* begin = t->entries; - upb_tabent* end = begin + upb_table_size(t); - for (e = e + 1; e < end; e++) { - if (upb_tabent_isempty(e)) return e; - } - for (e = begin; e < end; e++) { - if (upb_tabent_isempty(e)) return e; +// Advances d->ptr until the next non-whitespace character. Postcondition that +// d->ptr is pointing at a valid non-whitespace character (will err if end of +// buffer is reached). +static void jsondec_skipws(jsondec* d) { + jsondec_consumews(d); + if (d->ptr == d->end) { + jsondec_err(d, "Unexpected EOF"); } - UPB_ASSERT(false); - return NULL; } -static upb_tabent* getentry_mutable(upb_table* t, uint32_t hash) { - return (upb_tabent*)upb_getentry(t, hash); +static bool jsondec_tryparsech(jsondec* d, char ch) { + if (d->ptr == d->end || *d->ptr != ch) return false; + d->ptr++; + return true; } -static const upb_tabent* findentry(const upb_table* t, lookupkey_t key, - uint32_t hash, eqlfunc_t* eql) { - const upb_tabent* e; +static void jsondec_parselit(jsondec* d, const char* lit) { + size_t avail = d->end - d->ptr; + size_t len = strlen(lit); + if (avail < len || memcmp(d->ptr, lit, len) != 0) { + jsondec_errf(d, "Expected: '%s'", lit); + } + d->ptr += len; +} - if (t->size_lg2 == 0) return NULL; - e = upb_getentry(t, hash); - if (upb_tabent_isempty(e)) return NULL; - while (1) { - if (eql(e->key, key)) return e; - if ((e = e->next) == NULL) return NULL; +static void jsondec_wsch(jsondec* d, char ch) { + jsondec_skipws(d); + if (!jsondec_tryparsech(d, ch)) { + jsondec_errf(d, "Expected: '%c'", ch); } } -static upb_tabent* findentry_mutable(upb_table* t, lookupkey_t key, - uint32_t hash, eqlfunc_t* eql) { - return (upb_tabent*)findentry(t, key, hash, eql); +static void jsondec_true(jsondec* d) { jsondec_parselit(d, "true"); } +static void jsondec_false(jsondec* d) { jsondec_parselit(d, "false"); } +static void jsondec_null(jsondec* d) { jsondec_parselit(d, "null"); } + +static void jsondec_entrysep(jsondec* d) { + jsondec_skipws(d); + jsondec_parselit(d, ":"); } -static bool lookup(const upb_table* t, lookupkey_t key, upb_value* v, - uint32_t hash, eqlfunc_t* eql) { - const upb_tabent* e = findentry(t, key, hash, eql); - if (e) { - if (v) { - _upb_value_setval(v, e->val.val); - } - return true; - } else { - return false; +static int jsondec_rawpeek(jsondec* d) { + if (d->ptr == d->end) { + jsondec_err(d, "Unexpected EOF"); } -} -/* The given key must not already exist in the table. */ -static void insert(upb_table* t, lookupkey_t key, upb_tabkey tabkey, - upb_value val, uint32_t hash, hashfunc_t* hashfunc, - eqlfunc_t* eql) { - upb_tabent* mainpos_e; - upb_tabent* our_e; + switch (*d->ptr) { + case '{': + return JD_OBJECT; + case '[': + return JD_ARRAY; + case '"': + return JD_STRING; + case '-': + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + return JD_NUMBER; + case 't': + return JD_TRUE; + case 'f': + return JD_FALSE; + case 'n': + return JD_NULL; + default: + jsondec_errf(d, "Unexpected character: '%c'", *d->ptr); + } +} - UPB_ASSERT(findentry(t, key, hash, eql) == NULL); +/* JSON object/array **********************************************************/ - t->count++; - mainpos_e = getentry_mutable(t, hash); - our_e = mainpos_e; +/* These are used like so: + * + * jsondec_objstart(d); + * while (jsondec_objnext(d)) { + * ... + * } + * jsondec_objend(d) */ - if (upb_tabent_isempty(mainpos_e)) { - /* Our main position is empty; use it. */ - our_e->next = NULL; - } else { - /* Collision. */ - upb_tabent* new_e = emptyent(t, mainpos_e); - /* Head of collider's chain. */ - upb_tabent* chain = getentry_mutable(t, hashfunc(mainpos_e->key)); - if (chain == mainpos_e) { - /* Existing ent is in its main position (it has the same hash as us, and - * is the head of our chain). Insert to new ent and append to this chain. - */ - new_e->next = mainpos_e->next; - mainpos_e->next = new_e; - our_e = new_e; - } else { - /* Existing ent is not in its main position (it is a node in some other - * chain). This implies that no existing ent in the table has our hash. - * Evict it (updating its chain) and use its ent for head of our chain. */ - *new_e = *mainpos_e; /* copies next. */ - while (chain->next != mainpos_e) { - chain = (upb_tabent*)chain->next; - UPB_ASSERT(chain); - } - chain->next = new_e; - our_e = mainpos_e; - our_e->next = NULL; - } - } - our_e->key = tabkey; - our_e->val.val = val.val; - UPB_ASSERT(findentry(t, key, hash, eql) == our_e); +static int jsondec_peek(jsondec* d) { + jsondec_skipws(d); + return jsondec_rawpeek(d); } -static bool rm(upb_table* t, lookupkey_t key, upb_value* val, - upb_tabkey* removed, uint32_t hash, eqlfunc_t* eql) { - upb_tabent* chain = getentry_mutable(t, hash); - if (upb_tabent_isempty(chain)) return false; - if (eql(chain->key, key)) { - /* Element to remove is at the head of its chain. */ - t->count--; - if (val) _upb_value_setval(val, chain->val.val); - if (removed) *removed = chain->key; - if (chain->next) { - upb_tabent* move = (upb_tabent*)chain->next; - *chain = *move; - move->key = 0; /* Make the slot empty. */ - } else { - chain->key = 0; /* Make the slot empty. */ - } - return true; - } else { - /* Element to remove is either in a non-head position or not in the - * table. */ - while (chain->next && !eql(chain->next->key, key)) { - chain = (upb_tabent*)chain->next; - } - if (chain->next) { - /* Found element to remove. */ - upb_tabent* rm = (upb_tabent*)chain->next; - t->count--; - if (val) _upb_value_setval(val, chain->next->val.val); - if (removed) *removed = rm->key; - rm->key = 0; /* Make the slot empty. */ - chain->next = rm->next; - return true; - } else { - /* Element to remove is not in the table. */ - return false; - } +static void jsondec_push(jsondec* d) { + if (--d->depth < 0) { + jsondec_err(d, "Recursion limit exceeded"); } + d->is_first = true; } -static size_t next(const upb_table* t, size_t i) { - do { - if (++i >= upb_table_size(t)) return SIZE_MAX - 1; /* Distinct from -1. */ - } while (upb_tabent_isempty(&t->entries[i])); - - return i; +static bool jsondec_seqnext(jsondec* d, char end_ch) { + bool is_first = d->is_first; + d->is_first = false; + jsondec_skipws(d); + if (*d->ptr == end_ch) return false; + if (!is_first) jsondec_parselit(d, ","); + return true; } -static size_t begin(const upb_table* t) { return next(t, -1); } - -/* upb_strtable ***************************************************************/ - -/* A simple "subclass" of upb_table that only adds a hash function for strings. - */ +static void jsondec_arrstart(jsondec* d) { + jsondec_push(d); + jsondec_wsch(d, '['); +} -static upb_tabkey strcopy(lookupkey_t k2, upb_Arena* a) { - uint32_t len = (uint32_t)k2.str.len; - char* str = upb_Arena_Malloc(a, k2.str.len + sizeof(uint32_t) + 1); - if (str == NULL) return 0; - memcpy(str, &len, sizeof(uint32_t)); - if (k2.str.len) memcpy(str + sizeof(uint32_t), k2.str.str, k2.str.len); - str[sizeof(uint32_t) + k2.str.len] = '\0'; - return (uintptr_t)str; +static void jsondec_arrend(jsondec* d) { + d->depth++; + jsondec_wsch(d, ']'); } -/* Adapted from ABSL's wyhash. */ +static bool jsondec_arrnext(jsondec* d) { return jsondec_seqnext(d, ']'); } -static uint64_t UnalignedLoad64(const void* p) { - uint64_t val; - memcpy(&val, p, 8); - return val; +static void jsondec_objstart(jsondec* d) { + jsondec_push(d); + jsondec_wsch(d, '{'); } -static uint32_t UnalignedLoad32(const void* p) { - uint32_t val; - memcpy(&val, p, 4); - return val; +static void jsondec_objend(jsondec* d) { + d->depth++; + jsondec_wsch(d, '}'); } -#if defined(_MSC_VER) && defined(_M_X64) -#include -#endif - -/* Computes a * b, returning the low 64 bits of the result and storing the high - * 64 bits in |*high|. */ -static uint64_t upb_umul128(uint64_t v0, uint64_t v1, uint64_t* out_high) { -#ifdef __SIZEOF_INT128__ - __uint128_t p = v0; - p *= v1; - *out_high = (uint64_t)(p >> 64); - return (uint64_t)p; -#elif defined(_MSC_VER) && defined(_M_X64) - return _umul128(v0, v1, out_high); -#else - uint64_t a32 = v0 >> 32; - uint64_t a00 = v0 & 0xffffffff; - uint64_t b32 = v1 >> 32; - uint64_t b00 = v1 & 0xffffffff; - uint64_t high = a32 * b32; - uint64_t low = a00 * b00; - uint64_t mid1 = a32 * b00; - uint64_t mid2 = a00 * b32; - low += (mid1 << 32) + (mid2 << 32); - // Omit carry bit, for mixing we do not care about exact numerical precision. - high += (mid1 >> 32) + (mid2 >> 32); - *out_high = high; - return low; -#endif +static bool jsondec_objnext(jsondec* d) { + if (!jsondec_seqnext(d, '}')) return false; + if (jsondec_peek(d) != JD_STRING) { + jsondec_err(d, "Object must start with string"); + } + return true; } -static uint64_t WyhashMix(uint64_t v0, uint64_t v1) { - uint64_t high; - uint64_t low = upb_umul128(v0, v1, &high); - return low ^ high; -} +/* JSON number ****************************************************************/ -static uint64_t Wyhash(const void* data, size_t len, uint64_t seed, - const uint64_t salt[]) { - const uint8_t* ptr = (const uint8_t*)data; - uint64_t starting_length = (uint64_t)len; - uint64_t current_state = seed ^ salt[0]; +static bool jsondec_tryskipdigits(jsondec* d) { + const char* start = d->ptr; - if (len > 64) { - // If we have more than 64 bytes, we're going to handle chunks of 64 - // bytes at a time. We're going to build up two separate hash states - // which we will then hash together. - uint64_t duplicated_state = current_state; + while (d->ptr < d->end) { + if (*d->ptr < '0' || *d->ptr > '9') { + break; + } + d->ptr++; + } - do { - uint64_t a = UnalignedLoad64(ptr); - uint64_t b = UnalignedLoad64(ptr + 8); - uint64_t c = UnalignedLoad64(ptr + 16); - uint64_t d = UnalignedLoad64(ptr + 24); - uint64_t e = UnalignedLoad64(ptr + 32); - uint64_t f = UnalignedLoad64(ptr + 40); - uint64_t g = UnalignedLoad64(ptr + 48); - uint64_t h = UnalignedLoad64(ptr + 56); + return d->ptr != start; +} - uint64_t cs0 = WyhashMix(a ^ salt[1], b ^ current_state); - uint64_t cs1 = WyhashMix(c ^ salt[2], d ^ current_state); - current_state = (cs0 ^ cs1); +static void jsondec_skipdigits(jsondec* d) { + if (!jsondec_tryskipdigits(d)) { + jsondec_err(d, "Expected one or more digits"); + } +} - uint64_t ds0 = WyhashMix(e ^ salt[3], f ^ duplicated_state); - uint64_t ds1 = WyhashMix(g ^ salt[4], h ^ duplicated_state); - duplicated_state = (ds0 ^ ds1); +static double jsondec_number(jsondec* d) { + const char* start = d->ptr; - ptr += 64; - len -= 64; - } while (len > 64); + UPB_ASSERT(jsondec_rawpeek(d) == JD_NUMBER); - current_state = current_state ^ duplicated_state; - } + /* Skip over the syntax of a number, as specified by JSON. */ + if (*d->ptr == '-') d->ptr++; - // We now have a data `ptr` with at most 64 bytes and the current state - // of the hashing state machine stored in current_state. - while (len > 16) { - uint64_t a = UnalignedLoad64(ptr); - uint64_t b = UnalignedLoad64(ptr + 8); + if (jsondec_tryparsech(d, '0')) { + if (jsondec_tryskipdigits(d)) { + jsondec_err(d, "number cannot have leading zero"); + } + } else { + jsondec_skipdigits(d); + } - current_state = WyhashMix(a ^ salt[1], b ^ current_state); + if (d->ptr == d->end) goto parse; + if (jsondec_tryparsech(d, '.')) { + jsondec_skipdigits(d); + } + if (d->ptr == d->end) goto parse; - ptr += 16; - len -= 16; + if (*d->ptr == 'e' || *d->ptr == 'E') { + d->ptr++; + if (d->ptr == d->end) { + jsondec_err(d, "Unexpected EOF in number"); + } + if (*d->ptr == '+' || *d->ptr == '-') { + d->ptr++; + } + jsondec_skipdigits(d); } - // We now have a data `ptr` with at most 16 bytes. - uint64_t a = 0; - uint64_t b = 0; - if (len > 8) { - // When we have at least 9 and at most 16 bytes, set A to the first 64 - // bits of the input and B to the last 64 bits of the input. Yes, they will - // overlap in the middle if we are working with less than the full 16 - // bytes. - a = UnalignedLoad64(ptr); - b = UnalignedLoad64(ptr + len - 8); - } else if (len > 3) { - // If we have at least 4 and at most 8 bytes, set A to the first 32 - // bits and B to the last 32 bits. - a = UnalignedLoad32(ptr); - b = UnalignedLoad32(ptr + len - 4); - } else if (len > 0) { - // If we have at least 1 and at most 3 bytes, read all of the provided - // bits into A, with some adjustments. - a = ((ptr[0] << 16) | (ptr[len >> 1] << 8) | ptr[len - 1]); - b = 0; - } else { - a = 0; - b = 0; - } - - uint64_t w = WyhashMix(a ^ salt[1], b ^ current_state); - uint64_t z = salt[1] ^ starting_length; - return WyhashMix(w, z); -} - -const uint64_t kWyhashSalt[5] = { - 0x243F6A8885A308D3ULL, 0x13198A2E03707344ULL, 0xA4093822299F31D0ULL, - 0x082EFA98EC4E6C89ULL, 0x452821E638D01377ULL, -}; +parse: + /* Having verified the syntax of a JSON number, use strtod() to parse + * (strtod() accepts a superset of JSON syntax). */ + errno = 0; + { + // Copy the number into a null-terminated scratch buffer since strtod + // expects a null-terminated string. + char nullz[64]; + ptrdiff_t len = d->ptr - start; + if (len > (ptrdiff_t)(sizeof(nullz) - 1)) { + jsondec_err(d, "excessively long number"); + } + memcpy(nullz, start, len); + nullz[len] = '\0'; -uint32_t _upb_Hash(const void* p, size_t n, uint64_t seed) { - return Wyhash(p, n, seed, kWyhashSalt); -} + char* end; + double val = strtod(nullz, &end); + UPB_ASSERT(end - nullz == len); -static uint32_t _upb_Hash_NoSeed(const char* p, size_t n) { - return _upb_Hash(p, n, 0); -} + /* Currently the min/max-val conformance tests fail if we check this. Does + * this mean the conformance tests are wrong or strtod() is wrong, or + * something else? Investigate further. */ + /* + if (errno == ERANGE) { + jsondec_err(d, "Number out of range"); + } + */ -static uint32_t strhash(upb_tabkey key) { - uint32_t len; - char* str = upb_tabstr(key, &len); - return _upb_Hash_NoSeed(str, len); -} + if (val > DBL_MAX || val < -DBL_MAX) { + jsondec_err(d, "Number out of range"); + } -static bool streql(upb_tabkey k1, lookupkey_t k2) { - uint32_t len; - char* str = upb_tabstr(k1, &len); - return len == k2.str.len && (len == 0 || memcmp(str, k2.str.str, len) == 0); + return val; + } } -bool upb_strtable_init(upb_strtable* t, size_t expected_size, upb_Arena* a) { - // Multiply by approximate reciprocal of MAX_LOAD (0.85), with pow2 - // denominator. - size_t need_entries = (expected_size + 1) * 1204 / 1024; - UPB_ASSERT(need_entries >= expected_size * 0.85); - int size_lg2 = upb_Log2Ceiling(need_entries); - return init(&t->t, size_lg2, a); -} +/* JSON string ****************************************************************/ -void upb_strtable_clear(upb_strtable* t) { - size_t bytes = upb_table_size(&t->t) * sizeof(upb_tabent); - t->t.count = 0; - memset((char*)t->t.entries, 0, bytes); +static char jsondec_escape(jsondec* d) { + switch (*d->ptr++) { + case '"': + return '\"'; + case '\\': + return '\\'; + case '/': + return '/'; + case 'b': + return '\b'; + case 'f': + return '\f'; + case 'n': + return '\n'; + case 'r': + return '\r'; + case 't': + return '\t'; + default: + jsondec_err(d, "Invalid escape char"); + } } -bool upb_strtable_resize(upb_strtable* t, size_t size_lg2, upb_Arena* a) { - upb_strtable new_table; - if (!init(&new_table.t, size_lg2, a)) return false; +static uint32_t jsondec_codepoint(jsondec* d) { + uint32_t cp = 0; + const char* end; - intptr_t iter = UPB_STRTABLE_BEGIN; - upb_StringView key; - upb_value val; - while (upb_strtable_next2(t, &key, &val, &iter)) { - upb_strtable_insert(&new_table, key.data, key.size, val, a); + if (d->end - d->ptr < 4) { + jsondec_err(d, "EOF inside string"); } - *t = new_table; - return true; -} -bool upb_strtable_insert(upb_strtable* t, const char* k, size_t len, - upb_value v, upb_Arena* a) { - lookupkey_t key; - upb_tabkey tabkey; - uint32_t hash; - - if (isfull(&t->t)) { - /* Need to resize. New table of double the size, add old elements to it. */ - if (!upb_strtable_resize(t, t->t.size_lg2 + 1, a)) { - return false; + end = d->ptr + 4; + while (d->ptr < end) { + char ch = *d->ptr++; + if (ch >= '0' && ch <= '9') { + ch -= '0'; + } else if (ch >= 'a' && ch <= 'f') { + ch = ch - 'a' + 10; + } else if (ch >= 'A' && ch <= 'F') { + ch = ch - 'A' + 10; + } else { + jsondec_err(d, "Invalid hex digit"); } + cp = (cp << 4) | ch; } - key = strkey2(k, len); - tabkey = strcopy(key, a); - if (tabkey == 0) return false; - - hash = _upb_Hash_NoSeed(key.str.str, key.str.len); - insert(&t->t, key, tabkey, v, hash, &strhash, &streql); - return true; -} - -bool upb_strtable_lookup2(const upb_strtable* t, const char* key, size_t len, - upb_value* v) { - uint32_t hash = _upb_Hash_NoSeed(key, len); - return lookup(&t->t, strkey2(key, len), v, hash, &streql); -} - -bool upb_strtable_remove2(upb_strtable* t, const char* key, size_t len, - upb_value* val) { - uint32_t hash = _upb_Hash_NoSeed(key, len); - upb_tabkey tabkey; - return rm(&t->t, strkey2(key, len), val, &tabkey, hash, &streql); -} - -/* Iteration */ - -void upb_strtable_begin(upb_strtable_iter* i, const upb_strtable* t) { - i->t = t; - i->index = begin(&t->t); -} - -void upb_strtable_next(upb_strtable_iter* i) { - i->index = next(&i->t->t, i->index); + return cp; } -bool upb_strtable_done(const upb_strtable_iter* i) { - if (!i->t) return true; - return i->index >= upb_table_size(&i->t->t) || - upb_tabent_isempty(str_tabent(i)); -} +/* Parses a \uXXXX unicode escape (possibly a surrogate pair). */ +static size_t jsondec_unicode(jsondec* d, char* out) { + uint32_t cp = jsondec_codepoint(d); + if (upb_Unicode_IsHigh(cp)) { + /* Surrogate pair: two 16-bit codepoints become a 32-bit codepoint. */ + jsondec_parselit(d, "\\u"); + uint32_t low = jsondec_codepoint(d); + if (!upb_Unicode_IsLow(low)) jsondec_err(d, "Invalid low surrogate"); + cp = upb_Unicode_FromPair(cp, low); + } else if (upb_Unicode_IsLow(cp)) { + jsondec_err(d, "Unpaired low surrogate"); + } -upb_StringView upb_strtable_iter_key(const upb_strtable_iter* i) { - upb_StringView key; - uint32_t len; - UPB_ASSERT(!upb_strtable_done(i)); - key.data = upb_tabstr(str_tabent(i)->key, &len); - key.size = len; - return key; + /* Write to UTF-8 */ + int bytes = upb_Unicode_ToUTF8(cp, out); + if (bytes == 0) jsondec_err(d, "Invalid codepoint"); + return bytes; } -upb_value upb_strtable_iter_value(const upb_strtable_iter* i) { - UPB_ASSERT(!upb_strtable_done(i)); - return _upb_value_val(str_tabent(i)->val.val); -} +static void jsondec_resize(jsondec* d, char** buf, char** end, char** buf_end) { + size_t oldsize = *buf_end - *buf; + size_t len = *end - *buf; + size_t size = UPB_MAX(8, 2 * oldsize); -void upb_strtable_iter_setdone(upb_strtable_iter* i) { - i->t = NULL; - i->index = SIZE_MAX; -} + *buf = upb_Arena_Realloc(d->arena, *buf, len, size); + if (!*buf) jsondec_err(d, "Out of memory"); -bool upb_strtable_iter_isequal(const upb_strtable_iter* i1, - const upb_strtable_iter* i2) { - if (upb_strtable_done(i1) && upb_strtable_done(i2)) return true; - return i1->t == i2->t && i1->index == i2->index; + *end = *buf + len; + *buf_end = *buf + size; } -/* upb_inttable ***************************************************************/ +static upb_StringView jsondec_string(jsondec* d) { + char* buf = NULL; + char* end = NULL; + char* buf_end = NULL; -/* For inttables we use a hybrid structure where small keys are kept in an - * array and large keys are put in the hash table. */ + jsondec_skipws(d); -static uint32_t inthash(upb_tabkey key) { return upb_inthash(key); } + if (*d->ptr++ != '"') { + jsondec_err(d, "Expected string"); + } -static bool inteql(upb_tabkey k1, lookupkey_t k2) { return k1 == k2.num; } + while (d->ptr < d->end) { + char ch = *d->ptr++; -static upb_tabval* mutable_array(upb_inttable* t) { - return (upb_tabval*)t->array; -} + if (end == buf_end) { + jsondec_resize(d, &buf, &end, &buf_end); + } -static upb_tabval* inttable_val(upb_inttable* t, uintptr_t key) { - if (key < t->array_size) { - return upb_arrhas(t->array[key]) ? &(mutable_array(t)[key]) : NULL; - } else { - upb_tabent* e = - findentry_mutable(&t->t, intkey(key), upb_inthash(key), &inteql); - return e ? &e->val : NULL; + switch (ch) { + case '"': { + upb_StringView ret; + ret.data = buf; + ret.size = end - buf; + *end = '\0'; /* Needed for possible strtod(). */ + return ret; + } + case '\\': + if (d->ptr == d->end) goto eof; + if (*d->ptr == 'u') { + d->ptr++; + if (buf_end - end < 4) { + /* Allow space for maximum-sized codepoint (4 bytes). */ + jsondec_resize(d, &buf, &end, &buf_end); + } + end += jsondec_unicode(d, end); + } else { + *end++ = jsondec_escape(d); + } + break; + default: + if ((unsigned char)ch < 0x20) { + jsondec_err(d, "Invalid char in JSON string"); + } + *end++ = ch; + break; + } } -} - -static const upb_tabval* inttable_val_const(const upb_inttable* t, - uintptr_t key) { - return inttable_val((upb_inttable*)t, key); -} -size_t upb_inttable_count(const upb_inttable* t) { - return t->t.count + t->array_count; +eof: + jsondec_err(d, "EOF inside string"); } -static void check(upb_inttable* t) { - UPB_UNUSED(t); -#if defined(UPB_DEBUG_TABLE) && !defined(NDEBUG) - { - // This check is very expensive (makes inserts/deletes O(N)). - size_t count = 0; - intptr_t iter = UPB_INTTABLE_BEGIN; - uintptr_t key; - upb_value val; - while (upb_inttable_next(t, &key, &val, &iter)) { - UPB_ASSERT(upb_inttable_lookup(t, key, NULL)); - } - UPB_ASSERT(count == upb_inttable_count(t)); +static void jsondec_skipval(jsondec* d) { + switch (jsondec_peek(d)) { + case JD_OBJECT: + jsondec_objstart(d); + while (jsondec_objnext(d)) { + jsondec_string(d); + jsondec_entrysep(d); + jsondec_skipval(d); + } + jsondec_objend(d); + break; + case JD_ARRAY: + jsondec_arrstart(d); + while (jsondec_arrnext(d)) { + jsondec_skipval(d); + } + jsondec_arrend(d); + break; + case JD_TRUE: + jsondec_true(d); + break; + case JD_FALSE: + jsondec_false(d); + break; + case JD_NULL: + jsondec_null(d); + break; + case JD_STRING: + jsondec_string(d); + break; + case JD_NUMBER: + jsondec_number(d); + break; } -#endif } -bool upb_inttable_sizedinit(upb_inttable* t, size_t asize, int hsize_lg2, - upb_Arena* a) { - size_t array_bytes; +/* Base64 decoding for bytes fields. ******************************************/ - if (!init(&t->t, hsize_lg2, a)) return false; - /* Always make the array part at least 1 long, so that we know key 0 - * won't be in the hash part, which simplifies things. */ - t->array_size = UPB_MAX(1, asize); - t->array_count = 0; - array_bytes = t->array_size * sizeof(upb_value); - t->array = upb_Arena_Malloc(a, array_bytes); - if (!t->array) { - return false; - } - memset(mutable_array(t), 0xff, array_bytes); - check(t); - return true; -} +static unsigned int jsondec_base64_tablelookup(const char ch) { + /* Table includes the normal base64 chars plus the URL-safe variant. */ + const signed char table[256] = { + -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, + -1, 62 /*+*/, -1, 62 /*-*/, -1, 63 /*/ */, 52 /*0*/, + 53 /*1*/, 54 /*2*/, 55 /*3*/, 56 /*4*/, 57 /*5*/, 58 /*6*/, 59 /*7*/, + 60 /*8*/, 61 /*9*/, -1, -1, -1, -1, -1, + -1, -1, 0 /*A*/, 1 /*B*/, 2 /*C*/, 3 /*D*/, 4 /*E*/, + 5 /*F*/, 6 /*G*/, 07 /*H*/, 8 /*I*/, 9 /*J*/, 10 /*K*/, 11 /*L*/, + 12 /*M*/, 13 /*N*/, 14 /*O*/, 15 /*P*/, 16 /*Q*/, 17 /*R*/, 18 /*S*/, + 19 /*T*/, 20 /*U*/, 21 /*V*/, 22 /*W*/, 23 /*X*/, 24 /*Y*/, 25 /*Z*/, + -1, -1, -1, -1, 63 /*_*/, -1, 26 /*a*/, + 27 /*b*/, 28 /*c*/, 29 /*d*/, 30 /*e*/, 31 /*f*/, 32 /*g*/, 33 /*h*/, + 34 /*i*/, 35 /*j*/, 36 /*k*/, 37 /*l*/, 38 /*m*/, 39 /*n*/, 40 /*o*/, + 41 /*p*/, 42 /*q*/, 43 /*r*/, 44 /*s*/, 45 /*t*/, 46 /*u*/, 47 /*v*/, + 48 /*w*/, 49 /*x*/, 50 /*y*/, 51 /*z*/, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1}; -bool upb_inttable_init(upb_inttable* t, upb_Arena* a) { - return upb_inttable_sizedinit(t, 0, 4, a); + /* Sign-extend return value so high bit will be set on any unexpected char. */ + return table[(unsigned)ch]; } -bool upb_inttable_insert(upb_inttable* t, uintptr_t key, upb_value val, - upb_Arena* a) { - upb_tabval tabval; - tabval.val = val.val; - UPB_ASSERT( - upb_arrhas(tabval)); /* This will reject (uint64_t)-1. Fix this. */ +static char* jsondec_partialbase64(jsondec* d, const char* ptr, const char* end, + char* out) { + int32_t val = -1; - if (key < t->array_size) { - UPB_ASSERT(!upb_arrhas(t->array[key])); - t->array_count++; - mutable_array(t)[key].val = val.val; - } else { - if (isfull(&t->t)) { - /* Need to resize the hash part, but we re-use the array part. */ - size_t i; - upb_table new_table; + switch (end - ptr) { + case 2: + val = jsondec_base64_tablelookup(ptr[0]) << 18 | + jsondec_base64_tablelookup(ptr[1]) << 12; + out[0] = val >> 16; + out += 1; + break; + case 3: + val = jsondec_base64_tablelookup(ptr[0]) << 18 | + jsondec_base64_tablelookup(ptr[1]) << 12 | + jsondec_base64_tablelookup(ptr[2]) << 6; + out[0] = val >> 16; + out[1] = (val >> 8) & 0xff; + out += 2; + break; + } - if (!init(&new_table, t->t.size_lg2 + 1, a)) { - return false; - } + if (val < 0) { + jsondec_err(d, "Corrupt base64"); + } - for (i = begin(&t->t); i < upb_table_size(&t->t); i = next(&t->t, i)) { - const upb_tabent* e = &t->t.entries[i]; - uint32_t hash; - upb_value v; + return out; +} - _upb_value_setval(&v, e->val.val); - hash = upb_inthash(e->key); - insert(&new_table, intkey(e->key), e->key, v, hash, &inthash, &inteql); - } +static size_t jsondec_base64(jsondec* d, upb_StringView str) { + /* We decode in place. This is safe because this is a new buffer (not + * aliasing the input) and because base64 decoding shrinks 4 bytes into 3. */ + char* out = (char*)str.data; + const char* ptr = str.data; + const char* end = ptr + str.size; + const char* end4 = ptr + (str.size & -4); /* Round down to multiple of 4. */ - UPB_ASSERT(t->t.count == new_table.count); + for (; ptr < end4; ptr += 4, out += 3) { + int val = jsondec_base64_tablelookup(ptr[0]) << 18 | + jsondec_base64_tablelookup(ptr[1]) << 12 | + jsondec_base64_tablelookup(ptr[2]) << 6 | + jsondec_base64_tablelookup(ptr[3]) << 0; - t->t = new_table; + if (val < 0) { + /* Junk chars or padding. Remove trailing padding, if any. */ + if (end - ptr == 4 && ptr[3] == '=') { + if (ptr[2] == '=') { + end -= 2; + } else { + end -= 1; + } + } + break; } - insert(&t->t, intkey(key), key, val, upb_inthash(key), &inthash, &inteql); + + out[0] = val >> 16; + out[1] = (val >> 8) & 0xff; + out[2] = val & 0xff; } - check(t); - return true; -} -bool upb_inttable_lookup(const upb_inttable* t, uintptr_t key, upb_value* v) { - const upb_tabval* table_v = inttable_val_const(t, key); - if (!table_v) return false; - if (v) _upb_value_setval(v, table_v->val); - return true; + if (ptr < end) { + /* Process remaining chars. We do not require padding. */ + out = jsondec_partialbase64(d, ptr, end, out); + } + + return out - str.data; } -bool upb_inttable_replace(upb_inttable* t, uintptr_t key, upb_value val) { - upb_tabval* table_v = inttable_val(t, key); - if (!table_v) return false; - table_v->val = val.val; - return true; +/* Low-level integer parsing **************************************************/ + +static const char* jsondec_buftouint64(jsondec* d, const char* ptr, + const char* end, uint64_t* val) { + const char* out = upb_BufToUint64(ptr, end, val); + if (!out) jsondec_err(d, "Integer overflow"); + return out; } -bool upb_inttable_remove(upb_inttable* t, uintptr_t key, upb_value* val) { - bool success; - if (key < t->array_size) { - if (upb_arrhas(t->array[key])) { - upb_tabval empty = UPB_TABVALUE_EMPTY_INIT; - t->array_count--; - if (val) { - _upb_value_setval(val, t->array[key].val); - } - mutable_array(t)[key] = empty; - success = true; - } else { - success = false; - } - } else { - success = rm(&t->t, intkey(key), val, NULL, upb_inthash(key), &inteql); - } - check(t); - return success; +static const char* jsondec_buftoint64(jsondec* d, const char* ptr, + const char* end, int64_t* val, + bool* is_neg) { + const char* out = upb_BufToInt64(ptr, end, val, is_neg); + if (!out) jsondec_err(d, "Integer overflow"); + return out; } -void upb_inttable_compact(upb_inttable* t, upb_Arena* a) { - /* A power-of-two histogram of the table keys. */ - size_t counts[UPB_MAXARRSIZE + 1] = {0}; - - /* The max key in each bucket. */ - uintptr_t max[UPB_MAXARRSIZE + 1] = {0}; - - { - intptr_t iter = UPB_INTTABLE_BEGIN; - uintptr_t key; - upb_value val; - while (upb_inttable_next(t, &key, &val, &iter)) { - int bucket = log2ceil(key); - max[bucket] = UPB_MAX(max[bucket], key); - counts[bucket]++; - } +static uint64_t jsondec_strtouint64(jsondec* d, upb_StringView str) { + const char* end = str.data + str.size; + uint64_t ret; + if (jsondec_buftouint64(d, str.data, end, &ret) != end) { + jsondec_err(d, "Non-number characters in quoted integer"); } + return ret; +} - /* Find the largest power of two that satisfies the MIN_DENSITY - * definition (while actually having some keys). */ - size_t arr_count = upb_inttable_count(t); - int size_lg2; - upb_inttable new_t; - - for (size_lg2 = ARRAY_SIZE(counts) - 1; size_lg2 > 0; size_lg2--) { - if (counts[size_lg2] == 0) { - /* We can halve again without losing any entries. */ - continue; - } else if (arr_count >= (1 << size_lg2) * MIN_DENSITY) { - break; - } - - arr_count -= counts[size_lg2]; +static int64_t jsondec_strtoint64(jsondec* d, upb_StringView str) { + const char* end = str.data + str.size; + int64_t ret; + if (jsondec_buftoint64(d, str.data, end, &ret, NULL) != end) { + jsondec_err(d, "Non-number characters in quoted integer"); } + return ret; +} - UPB_ASSERT(arr_count <= upb_inttable_count(t)); - - { - /* Insert all elements into new, perfectly-sized table. */ - size_t arr_size = max[size_lg2] + 1; /* +1 so arr[max] will fit. */ - size_t hash_count = upb_inttable_count(t) - arr_count; - size_t hash_size = hash_count ? (hash_count / MAX_LOAD) + 1 : 0; - int hashsize_lg2 = log2ceil(hash_size); +/* Primitive value types ******************************************************/ - upb_inttable_sizedinit(&new_t, arr_size, hashsize_lg2, a); +/* Parse INT32 or INT64 value. */ +static upb_MessageValue jsondec_int(jsondec* d, const upb_FieldDef* f) { + upb_MessageValue val; - { - intptr_t iter = UPB_INTTABLE_BEGIN; - uintptr_t key; - upb_value val; - while (upb_inttable_next(t, &key, &val, &iter)) { - upb_inttable_insert(&new_t, key, val, a); + switch (jsondec_peek(d)) { + case JD_NUMBER: { + double dbl = jsondec_number(d); + if (dbl > 9223372036854774784.0 || dbl < -9223372036854775808.0) { + jsondec_err(d, "JSON number is out of range."); } - } - - UPB_ASSERT(new_t.array_size == arr_size); - UPB_ASSERT(new_t.t.size_lg2 == hashsize_lg2); - } - *t = new_t; -} - -// Iteration. - -bool upb_inttable_next(const upb_inttable* t, uintptr_t* key, upb_value* val, - intptr_t* iter) { - intptr_t i = *iter; - if ((size_t)(i + 1) <= t->array_size) { - while ((size_t)++i < t->array_size) { - upb_tabval ent = t->array[i]; - if (upb_arrhas(ent)) { - *key = i; - *val = _upb_value_val(ent.val); - *iter = i; - return true; + val.int64_val = dbl; /* must be guarded, overflow here is UB */ + if (val.int64_val != dbl) { + jsondec_errf(d, "JSON number was not integral (%f != %" PRId64 ")", dbl, + val.int64_val); } + break; } - i--; // Back up to exactly one position before the start of the table. + case JD_STRING: { + upb_StringView str = jsondec_string(d); + val.int64_val = jsondec_strtoint64(d, str); + break; + } + default: + jsondec_err(d, "Expected number or string"); } - size_t tab_idx = next(&t->t, i - t->array_size); - if (tab_idx < upb_table_size(&t->t)) { - upb_tabent* ent = &t->t.entries[tab_idx]; - *key = ent->key; - *val = _upb_value_val(ent->val.val); - *iter = tab_idx + t->array_size; - return true; + if (upb_FieldDef_CType(f) == kUpb_CType_Int32 || + upb_FieldDef_CType(f) == kUpb_CType_Enum) { + if (val.int64_val > INT32_MAX || val.int64_val < INT32_MIN) { + jsondec_err(d, "Integer out of range."); + } + val.int32_val = (int32_t)val.int64_val; } - return false; + return val; } -void upb_inttable_removeiter(upb_inttable* t, intptr_t* iter) { - intptr_t i = *iter; - if ((size_t)i < t->array_size) { - t->array_count--; - mutable_array(t)[i].val = -1; - } else { - upb_tabent* ent = &t->t.entries[i - t->array_size]; - upb_tabent* prev = NULL; +/* Parse UINT32 or UINT64 value. */ +static upb_MessageValue jsondec_uint(jsondec* d, const upb_FieldDef* f) { + upb_MessageValue val = {0}; - // Linear search, not great. - upb_tabent* end = &t->t.entries[upb_table_size(&t->t)]; - for (upb_tabent* e = t->t.entries; e != end; e++) { - if (e->next == ent) { - prev = e; - break; + switch (jsondec_peek(d)) { + case JD_NUMBER: { + double dbl = jsondec_number(d); + if (dbl > 18446744073709549568.0 || dbl < 0) { + jsondec_err(d, "JSON number is out of range."); + } + val.uint64_val = dbl; /* must be guarded, overflow here is UB */ + if (val.uint64_val != dbl) { + jsondec_errf(d, "JSON number was not integral (%f != %" PRIu64 ")", dbl, + val.uint64_val); } + break; } - - if (prev) { - prev->next = ent->next; + case JD_STRING: { + upb_StringView str = jsondec_string(d); + val.uint64_val = jsondec_strtouint64(d, str); + break; } - - t->t.count--; - ent->key = 0; - ent->next = NULL; + default: + jsondec_err(d, "Expected number or string"); } -} -bool upb_strtable_next2(const upb_strtable* t, upb_StringView* key, - upb_value* val, intptr_t* iter) { - size_t tab_idx = next(&t->t, *iter); - if (tab_idx < upb_table_size(&t->t)) { - upb_tabent* ent = &t->t.entries[tab_idx]; - uint32_t len; - key->data = upb_tabstr(ent->key, &len); - key->size = len; - *val = _upb_value_val(ent->val.val); - *iter = tab_idx; - return true; + if (upb_FieldDef_CType(f) == kUpb_CType_UInt32) { + if (val.uint64_val > UINT32_MAX) { + jsondec_err(d, "Integer out of range."); + } + val.uint32_val = (uint32_t)val.uint64_val; } - return false; + return val; } -void upb_strtable_removeiter(upb_strtable* t, intptr_t* iter) { - intptr_t i = *iter; - upb_tabent* ent = &t->t.entries[i]; - upb_tabent* prev = NULL; +/* Parse DOUBLE or FLOAT value. */ +static upb_MessageValue jsondec_double(jsondec* d, const upb_FieldDef* f) { + upb_StringView str; + upb_MessageValue val = {0}; - // Linear search, not great. - upb_tabent* end = &t->t.entries[upb_table_size(&t->t)]; - for (upb_tabent* e = t->t.entries; e != end; e++) { - if (e->next == ent) { - prev = e; + switch (jsondec_peek(d)) { + case JD_NUMBER: + val.double_val = jsondec_number(d); break; - } + case JD_STRING: + str = jsondec_string(d); + if (jsondec_streql(str, "NaN")) { + val.double_val = NAN; + } else if (jsondec_streql(str, "Infinity")) { + val.double_val = INFINITY; + } else if (jsondec_streql(str, "-Infinity")) { + val.double_val = -INFINITY; + } else { + val.double_val = strtod(str.data, NULL); + } + break; + default: + jsondec_err(d, "Expected number or string"); } - if (prev) { - prev->next = ent->next; + if (upb_FieldDef_CType(f) == kUpb_CType_Float) { + float f = val.double_val; + if (val.double_val != INFINITY && val.double_val != -INFINITY) { + if (f == INFINITY || f == -INFINITY) jsondec_err(d, "Float out of range"); + } + val.float_val = f; } - t->t.count--; - ent->key = 0; - ent->next = NULL; + return val; } -void upb_strtable_setentryvalue(upb_strtable* t, intptr_t iter, upb_value v) { - upb_tabent* ent = &t->t.entries[iter]; - ent->val.val = v.val; +/* Parse STRING or BYTES value. */ +static upb_MessageValue jsondec_strfield(jsondec* d, const upb_FieldDef* f) { + upb_MessageValue val; + val.str_val = jsondec_string(d); + if (upb_FieldDef_CType(f) == kUpb_CType_Bytes) { + val.str_val.size = jsondec_base64(d, val.str_val); + } + return val; } +static upb_JsonMessageValue jsondec_enum(jsondec* d, const upb_FieldDef* f) { + switch (jsondec_peek(d)) { + case JD_STRING: { + upb_StringView str = jsondec_string(d); + const upb_EnumDef* e = upb_FieldDef_EnumSubDef(f); + const upb_EnumValueDef* ev = + upb_EnumDef_FindValueByNameWithSize(e, str.data, str.size); + upb_JsonMessageValue val = {.ignore = false}; + if (ev) { + val.value.int32_val = upb_EnumValueDef_Number(ev); + } else { + if (d->options & upb_JsonDecode_IgnoreUnknown) { + val.ignore = true; + } else { + jsondec_errf(d, "Unknown enumerator: '" UPB_STRINGVIEW_FORMAT "'", + UPB_STRINGVIEW_ARGS(str)); + } + } + return val; + } + case JD_NULL: { + if (jsondec_isnullvalue(f)) { + upb_JsonMessageValue val = {.ignore = false}; + jsondec_null(d); + val.value.int32_val = 0; + return val; + } + } + /* Fallthrough. */ + default: + return (upb_JsonMessageValue){.value = jsondec_int(d, f), + .ignore = false}; + } +} -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - - -// Must be last. +static upb_MessageValue jsondec_bool(jsondec* d, const upb_FieldDef* f) { + bool is_map_key = upb_FieldDef_Number(f) == 1 && + upb_MessageDef_IsMapEntry(upb_FieldDef_ContainingType(f)); + upb_MessageValue val; -typedef struct { - const char *ptr, *end; - upb_Arena* arena; /* TODO: should we have a tmp arena for tmp data? */ - const upb_DefPool* symtab; - int depth; - upb_Status* status; - jmp_buf err; - int line; - const char* line_begin; - bool is_first; - int options; - const upb_FieldDef* debug_field; -} jsondec; + if (is_map_key) { + upb_StringView str = jsondec_string(d); + if (jsondec_streql(str, "true")) { + val.bool_val = true; + } else if (jsondec_streql(str, "false")) { + val.bool_val = false; + } else { + jsondec_err(d, "Invalid boolean map key"); + } + } else { + switch (jsondec_peek(d)) { + case JD_TRUE: + val.bool_val = true; + jsondec_true(d); + break; + case JD_FALSE: + val.bool_val = false; + jsondec_false(d); + break; + default: + jsondec_err(d, "Expected true or false"); + } + } -typedef struct { - upb_MessageValue value; - bool ignore; -} upb_JsonMessageValue; + return val; +} -enum { JD_OBJECT, JD_ARRAY, JD_STRING, JD_NUMBER, JD_TRUE, JD_FALSE, JD_NULL }; +/* Composite types (array/message/map) ****************************************/ -/* Forward declarations of mutually-recursive functions. */ -static void jsondec_wellknown(jsondec* d, upb_Message* msg, - const upb_MessageDef* m); -static upb_JsonMessageValue jsondec_value(jsondec* d, const upb_FieldDef* f); -static void jsondec_wellknownvalue(jsondec* d, upb_Message* msg, - const upb_MessageDef* m); -static void jsondec_object(jsondec* d, upb_Message* msg, - const upb_MessageDef* m); +static void jsondec_array(jsondec* d, upb_Message* msg, const upb_FieldDef* f) { + upb_Array* arr = upb_Message_Mutable(msg, f, d->arena).array; -static bool jsondec_streql(upb_StringView str, const char* lit) { - return str.size == strlen(lit) && memcmp(str.data, lit, str.size) == 0; + jsondec_arrstart(d); + while (jsondec_arrnext(d)) { + upb_JsonMessageValue elem = jsondec_value(d, f); + if (!elem.ignore) { + upb_Array_Append(arr, elem.value, d->arena); + } + } + jsondec_arrend(d); } -static bool jsondec_isnullvalue(const upb_FieldDef* f) { - return upb_FieldDef_CType(f) == kUpb_CType_Enum && - strcmp(upb_EnumDef_FullName(upb_FieldDef_EnumSubDef(f)), - "google.protobuf.NullValue") == 0; -} +static void jsondec_map(jsondec* d, upb_Message* msg, const upb_FieldDef* f) { + upb_Map* map = upb_Message_Mutable(msg, f, d->arena).map; + const upb_MessageDef* entry = upb_FieldDef_MessageSubDef(f); + const upb_FieldDef* key_f = upb_MessageDef_FindFieldByNumber(entry, 1); + const upb_FieldDef* val_f = upb_MessageDef_FindFieldByNumber(entry, 2); -static bool jsondec_isvalue(const upb_FieldDef* f) { - return (upb_FieldDef_CType(f) == kUpb_CType_Message && - upb_MessageDef_WellKnownType(upb_FieldDef_MessageSubDef(f)) == - kUpb_WellKnown_Value) || - jsondec_isnullvalue(f); + jsondec_objstart(d); + while (jsondec_objnext(d)) { + upb_JsonMessageValue key, val; + key = jsondec_value(d, key_f); + UPB_ASSUME(!key.ignore); // Map key cannot be enum. + jsondec_entrysep(d); + val = jsondec_value(d, val_f); + if (!val.ignore) { + upb_Map_Set(map, key.value, val.value, d->arena); + } + } + jsondec_objend(d); } -static void jsondec_seterrmsg(jsondec* d, const char* msg) { - upb_Status_SetErrorFormat(d->status, "Error parsing JSON @%d:%d: %s", d->line, - (int)(d->ptr - d->line_begin), msg); +static void jsondec_tomsg(jsondec* d, upb_Message* msg, + const upb_MessageDef* m) { + if (upb_MessageDef_WellKnownType(m) == kUpb_WellKnown_Unspecified) { + jsondec_object(d, msg, m); + } else { + jsondec_wellknown(d, msg, m); + } } -UPB_NORETURN static void jsondec_err(jsondec* d, const char* msg) { - jsondec_seterrmsg(d, msg); - UPB_LONGJMP(d->err, 1); -} +static upb_MessageValue jsondec_msg(jsondec* d, const upb_FieldDef* f) { + const upb_MessageDef* m = upb_FieldDef_MessageSubDef(f); + const upb_MiniTable* layout = upb_MessageDef_MiniTable(m); + upb_Message* msg = upb_Message_New(layout, d->arena); + upb_MessageValue val; -UPB_PRINTF(2, 3) -UPB_NORETURN static void jsondec_errf(jsondec* d, const char* fmt, ...) { - va_list argp; - upb_Status_SetErrorFormat(d->status, "Error parsing JSON @%d:%d: ", d->line, - (int)(d->ptr - d->line_begin)); - va_start(argp, fmt); - upb_Status_VAppendErrorFormat(d->status, fmt, argp); - va_end(argp); - UPB_LONGJMP(d->err, 1); + jsondec_tomsg(d, msg, m); + val.msg_val = msg; + return val; } -// Advances d->ptr until the next non-whitespace character or to the end of -// the buffer. -static void jsondec_consumews(jsondec* d) { - while (d->ptr != d->end) { - switch (*d->ptr) { - case '\n': - d->line++; - d->line_begin = d->ptr; - /* Fallthrough. */ - case '\r': - case '\t': - case ' ': - d->ptr++; - break; - default: - return; +static void jsondec_field(jsondec* d, upb_Message* msg, + const upb_MessageDef* m) { + upb_StringView name; + const upb_FieldDef* f; + const upb_FieldDef* preserved; + + name = jsondec_string(d); + jsondec_entrysep(d); + + if (name.size >= 2 && name.data[0] == '[' && + name.data[name.size - 1] == ']') { + f = upb_DefPool_FindExtensionByNameWithSize(d->symtab, name.data + 1, + name.size - 2); + if (f && upb_FieldDef_ContainingType(f) != m) { + jsondec_errf( + d, "Extension %s extends message %s, but was seen in message %s", + upb_FieldDef_FullName(f), + upb_MessageDef_FullName(upb_FieldDef_ContainingType(f)), + upb_MessageDef_FullName(m)); } + } else { + f = upb_MessageDef_FindByJsonNameWithSize(m, name.data, name.size); } -} -// Advances d->ptr until the next non-whitespace character. Postcondition that -// d->ptr is pointing at a valid non-whitespace character (will err if end of -// buffer is reached). -static void jsondec_skipws(jsondec* d) { - jsondec_consumews(d); - if (d->ptr == d->end) { - jsondec_err(d, "Unexpected EOF"); + if (!f) { + if ((d->options & upb_JsonDecode_IgnoreUnknown) == 0) { + jsondec_errf(d, "No such field: " UPB_STRINGVIEW_FORMAT, + UPB_STRINGVIEW_ARGS(name)); + } + jsondec_skipval(d); + return; } -} - -static bool jsondec_tryparsech(jsondec* d, char ch) { - if (d->ptr == d->end || *d->ptr != ch) return false; - d->ptr++; - return true; -} -static void jsondec_parselit(jsondec* d, const char* lit) { - size_t avail = d->end - d->ptr; - size_t len = strlen(lit); - if (avail < len || memcmp(d->ptr, lit, len) != 0) { - jsondec_errf(d, "Expected: '%s'", lit); + if (jsondec_peek(d) == JD_NULL && !jsondec_isvalue(f)) { + /* JSON "null" indicates a default value, so no need to set anything. */ + jsondec_null(d); + return; } - d->ptr += len; -} -static void jsondec_wsch(jsondec* d, char ch) { - jsondec_skipws(d); - if (!jsondec_tryparsech(d, ch)) { - jsondec_errf(d, "Expected: '%c'", ch); + if (upb_FieldDef_RealContainingOneof(f) && + upb_Message_WhichOneof(msg, upb_FieldDef_ContainingOneof(f))) { + jsondec_err(d, "More than one field for this oneof."); } -} -static void jsondec_true(jsondec* d) { jsondec_parselit(d, "true"); } -static void jsondec_false(jsondec* d) { jsondec_parselit(d, "false"); } -static void jsondec_null(jsondec* d) { jsondec_parselit(d, "null"); } + preserved = d->debug_field; + d->debug_field = f; -static void jsondec_entrysep(jsondec* d) { - jsondec_skipws(d); - jsondec_parselit(d, ":"); + if (upb_FieldDef_IsMap(f)) { + jsondec_map(d, msg, f); + } else if (upb_FieldDef_IsRepeated(f)) { + jsondec_array(d, msg, f); + } else if (upb_FieldDef_IsSubMessage(f)) { + upb_Message* submsg = upb_Message_Mutable(msg, f, d->arena).msg; + const upb_MessageDef* subm = upb_FieldDef_MessageSubDef(f); + jsondec_tomsg(d, submsg, subm); + } else { + upb_JsonMessageValue val = jsondec_value(d, f); + if (!val.ignore) { + upb_Message_SetFieldByDef(msg, f, val.value, d->arena); + } + } + + d->debug_field = preserved; } -static int jsondec_rawpeek(jsondec* d) { - if (d->ptr == d->end) { - jsondec_err(d, "Unexpected EOF"); +static void jsondec_object(jsondec* d, upb_Message* msg, + const upb_MessageDef* m) { + jsondec_objstart(d); + while (jsondec_objnext(d)) { + jsondec_field(d, msg, m); } + jsondec_objend(d); +} - switch (*d->ptr) { - case '{': - return JD_OBJECT; - case '[': - return JD_ARRAY; - case '"': - return JD_STRING; - case '-': - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - return JD_NUMBER; - case 't': - return JD_TRUE; - case 'f': - return JD_FALSE; - case 'n': - return JD_NULL; +static upb_MessageValue jsondec_nonenum(jsondec* d, const upb_FieldDef* f) { + switch (upb_FieldDef_CType(f)) { + case kUpb_CType_Bool: + return jsondec_bool(d, f); + case kUpb_CType_Float: + case kUpb_CType_Double: + return jsondec_double(d, f); + case kUpb_CType_UInt32: + case kUpb_CType_UInt64: + return jsondec_uint(d, f); + case kUpb_CType_Int32: + case kUpb_CType_Int64: + return jsondec_int(d, f); + case kUpb_CType_String: + case kUpb_CType_Bytes: + return jsondec_strfield(d, f); + case kUpb_CType_Message: + return jsondec_msg(d, f); + case kUpb_CType_Enum: default: - jsondec_errf(d, "Unexpected character: '%c'", *d->ptr); + UPB_UNREACHABLE(); } } -/* JSON object/array **********************************************************/ +static upb_JsonMessageValue jsondec_value(jsondec* d, const upb_FieldDef* f) { + if (upb_FieldDef_CType(f) == kUpb_CType_Enum) { + return jsondec_enum(d, f); + } else { + return (upb_JsonMessageValue){.value = jsondec_nonenum(d, f), + .ignore = false}; + } +} -/* These are used like so: - * - * jsondec_objstart(d); - * while (jsondec_objnext(d)) { - * ... - * } - * jsondec_objend(d) */ +/* Well-known types ***********************************************************/ -static int jsondec_peek(jsondec* d) { - jsondec_skipws(d); - return jsondec_rawpeek(d); -} +static int jsondec_tsdigits(jsondec* d, const char** ptr, size_t digits, + const char* after) { + uint64_t val; + const char* p = *ptr; + const char* end = p + digits; + size_t after_len = after ? strlen(after) : 0; -static void jsondec_push(jsondec* d) { - if (--d->depth < 0) { - jsondec_err(d, "Recursion limit exceeded"); + UPB_ASSERT(digits <= 9); /* int can't overflow. */ + + if (jsondec_buftouint64(d, p, end, &val) != end || + (after_len && memcmp(end, after, after_len) != 0)) { + jsondec_err(d, "Malformed timestamp"); } - d->is_first = true; -} -static bool jsondec_seqnext(jsondec* d, char end_ch) { - bool is_first = d->is_first; - d->is_first = false; - jsondec_skipws(d); - if (*d->ptr == end_ch) return false; - if (!is_first) jsondec_parselit(d, ","); - return true; -} + UPB_ASSERT(val < INT_MAX); -static void jsondec_arrstart(jsondec* d) { - jsondec_push(d); - jsondec_wsch(d, '['); + *ptr = end + after_len; + return (int)val; } -static void jsondec_arrend(jsondec* d) { - d->depth++; - jsondec_wsch(d, ']'); -} +static int jsondec_nanos(jsondec* d, const char** ptr, const char* end) { + uint64_t nanos = 0; + const char* p = *ptr; -static bool jsondec_arrnext(jsondec* d) { return jsondec_seqnext(d, ']'); } + if (p != end && *p == '.') { + const char* nano_end = jsondec_buftouint64(d, p + 1, end, &nanos); + int digits = (int)(nano_end - p - 1); + int exp_lg10 = 9 - digits; + if (digits > 9) { + jsondec_err(d, "Too many digits for partial seconds"); + } + while (exp_lg10--) nanos *= 10; + *ptr = nano_end; + } -static void jsondec_objstart(jsondec* d) { - jsondec_push(d); - jsondec_wsch(d, '{'); -} + UPB_ASSERT(nanos < INT_MAX); -static void jsondec_objend(jsondec* d) { - d->depth++; - jsondec_wsch(d, '}'); + return (int)nanos; } -static bool jsondec_objnext(jsondec* d) { - if (!jsondec_seqnext(d, '}')) return false; - if (jsondec_peek(d) != JD_STRING) { - jsondec_err(d, "Object must start with string"); - } - return true; +/* jsondec_epochdays(1970, 1, 1) == 1970-01-01 == 0. */ +int jsondec_epochdays(int y, int m, int d) { + const uint32_t year_base = 4800; /* Before min year, multiple of 400. */ + const uint32_t m_adj = m - 3; /* March-based month. */ + const uint32_t carry = m_adj > (uint32_t)m ? 1 : 0; + const uint32_t adjust = carry ? 12 : 0; + const uint32_t y_adj = y + year_base - carry; + const uint32_t month_days = ((m_adj + adjust) * 62719 + 769) / 2048; + const uint32_t leap_days = y_adj / 4 - y_adj / 100 + y_adj / 400; + return y_adj * 365 + leap_days + month_days + (d - 1) - 2472632; } -/* JSON number ****************************************************************/ +static int64_t jsondec_unixtime(int y, int m, int d, int h, int min, int s) { + return (int64_t)jsondec_epochdays(y, m, d) * 86400 + h * 3600 + min * 60 + s; +} -static bool jsondec_tryskipdigits(jsondec* d) { - const char* start = d->ptr; +static void jsondec_timestamp(jsondec* d, upb_Message* msg, + const upb_MessageDef* m) { + upb_MessageValue seconds; + upb_MessageValue nanos; + upb_StringView str = jsondec_string(d); + const char* ptr = str.data; + const char* end = ptr + str.size; - while (d->ptr < d->end) { - if (*d->ptr < '0' || *d->ptr > '9') { - break; - } - d->ptr++; - } + if (str.size < 20) goto malformed; - return d->ptr != start; -} + { + /* 1972-01-01T01:00:00 */ + int year = jsondec_tsdigits(d, &ptr, 4, "-"); + int mon = jsondec_tsdigits(d, &ptr, 2, "-"); + int day = jsondec_tsdigits(d, &ptr, 2, "T"); + int hour = jsondec_tsdigits(d, &ptr, 2, ":"); + int min = jsondec_tsdigits(d, &ptr, 2, ":"); + int sec = jsondec_tsdigits(d, &ptr, 2, NULL); -static void jsondec_skipdigits(jsondec* d) { - if (!jsondec_tryskipdigits(d)) { - jsondec_err(d, "Expected one or more digits"); + seconds.int64_val = jsondec_unixtime(year, mon, day, hour, min, sec); } -} -static double jsondec_number(jsondec* d) { - const char* start = d->ptr; + nanos.int32_val = jsondec_nanos(d, &ptr, end); - UPB_ASSERT(jsondec_rawpeek(d) == JD_NUMBER); + { + /* [+-]08:00 or Z */ + int ofs_hour = 0; + int ofs_min = 0; + bool neg = false; - /* Skip over the syntax of a number, as specified by JSON. */ - if (*d->ptr == '-') d->ptr++; + if (ptr == end) goto malformed; - if (jsondec_tryparsech(d, '0')) { - if (jsondec_tryskipdigits(d)) { - jsondec_err(d, "number cannot have leading zero"); + switch (*ptr++) { + case '-': + neg = true; + /* fallthrough */ + case '+': + if ((end - ptr) != 5) goto malformed; + ofs_hour = jsondec_tsdigits(d, &ptr, 2, ":"); + ofs_min = jsondec_tsdigits(d, &ptr, 2, NULL); + ofs_min = ((ofs_hour * 60) + ofs_min) * 60; + seconds.int64_val += (neg ? ofs_min : -ofs_min); + break; + case 'Z': + if (ptr != end) goto malformed; + break; + default: + goto malformed; } - } else { - jsondec_skipdigits(d); - } - - if (d->ptr == d->end) goto parse; - if (jsondec_tryparsech(d, '.')) { - jsondec_skipdigits(d); } - if (d->ptr == d->end) goto parse; - if (*d->ptr == 'e' || *d->ptr == 'E') { - d->ptr++; - if (d->ptr == d->end) { - jsondec_err(d, "Unexpected EOF in number"); - } - if (*d->ptr == '+' || *d->ptr == '-') { - d->ptr++; - } - jsondec_skipdigits(d); + if (seconds.int64_val < -62135596800) { + jsondec_err(d, "Timestamp out of range"); } -parse: - /* Having verified the syntax of a JSON number, use strtod() to parse - * (strtod() accepts a superset of JSON syntax). */ - errno = 0; - { - // Copy the number into a null-terminated scratch buffer since strtod - // expects a null-terminated string. - char nullz[64]; - ptrdiff_t len = d->ptr - start; - if (len > (ptrdiff_t)(sizeof(nullz) - 1)) { - jsondec_err(d, "excessively long number"); - } - memcpy(nullz, start, len); - nullz[len] = '\0'; - - char* end; - double val = strtod(nullz, &end); - UPB_ASSERT(end - nullz == len); - - /* Currently the min/max-val conformance tests fail if we check this. Does - * this mean the conformance tests are wrong or strtod() is wrong, or - * something else? Investigate further. */ - /* - if (errno == ERANGE) { - jsondec_err(d, "Number out of range"); - } - */ - - if (val > DBL_MAX || val < -DBL_MAX) { - jsondec_err(d, "Number out of range"); - } + upb_Message_SetFieldByDef(msg, upb_MessageDef_FindFieldByNumber(m, 1), + seconds, d->arena); + upb_Message_SetFieldByDef(msg, upb_MessageDef_FindFieldByNumber(m, 2), nanos, + d->arena); + return; - return val; - } +malformed: + jsondec_err(d, "Malformed timestamp"); } -/* JSON string ****************************************************************/ - -static char jsondec_escape(jsondec* d) { - switch (*d->ptr++) { - case '"': - return '\"'; - case '\\': - return '\\'; - case '/': - return '/'; - case 'b': - return '\b'; - case 'f': - return '\f'; - case 'n': - return '\n'; - case 'r': - return '\r'; - case 't': - return '\t'; - default: - jsondec_err(d, "Invalid escape char"); - } -} +static void jsondec_duration(jsondec* d, upb_Message* msg, + const upb_MessageDef* m) { + upb_MessageValue seconds; + upb_MessageValue nanos; + upb_StringView str = jsondec_string(d); + const char* ptr = str.data; + const char* end = ptr + str.size; + const int64_t max = (uint64_t)3652500 * 86400; + bool neg = false; -static uint32_t jsondec_codepoint(jsondec* d) { - uint32_t cp = 0; - const char* end; + /* "3.000000001s", "3s", etc. */ + ptr = jsondec_buftoint64(d, ptr, end, &seconds.int64_val, &neg); + nanos.int32_val = jsondec_nanos(d, &ptr, end); - if (d->end - d->ptr < 4) { - jsondec_err(d, "EOF inside string"); + if (end - ptr != 1 || *ptr != 's') { + jsondec_err(d, "Malformed duration"); } - end = d->ptr + 4; - while (d->ptr < end) { - char ch = *d->ptr++; - if (ch >= '0' && ch <= '9') { - ch -= '0'; - } else if (ch >= 'a' && ch <= 'f') { - ch = ch - 'a' + 10; - } else if (ch >= 'A' && ch <= 'F') { - ch = ch - 'A' + 10; - } else { - jsondec_err(d, "Invalid hex digit"); - } - cp = (cp << 4) | ch; + if (seconds.int64_val < -max || seconds.int64_val > max) { + jsondec_err(d, "Duration out of range"); } - return cp; -} - -/* Parses a \uXXXX unicode escape (possibly a surrogate pair). */ -static size_t jsondec_unicode(jsondec* d, char* out) { - uint32_t cp = jsondec_codepoint(d); - if (upb_Unicode_IsHigh(cp)) { - /* Surrogate pair: two 16-bit codepoints become a 32-bit codepoint. */ - jsondec_parselit(d, "\\u"); - uint32_t low = jsondec_codepoint(d); - if (!upb_Unicode_IsLow(low)) jsondec_err(d, "Invalid low surrogate"); - cp = upb_Unicode_FromPair(cp, low); - } else if (upb_Unicode_IsLow(cp)) { - jsondec_err(d, "Unpaired low surrogate"); + if (neg) { + nanos.int32_val = -nanos.int32_val; } - /* Write to UTF-8 */ - int bytes = upb_Unicode_ToUTF8(cp, out); - if (bytes == 0) jsondec_err(d, "Invalid codepoint"); - return bytes; -} - -static void jsondec_resize(jsondec* d, char** buf, char** end, char** buf_end) { - size_t oldsize = *buf_end - *buf; - size_t len = *end - *buf; - size_t size = UPB_MAX(8, 2 * oldsize); - - *buf = upb_Arena_Realloc(d->arena, *buf, len, size); - if (!*buf) jsondec_err(d, "Out of memory"); - - *end = *buf + len; - *buf_end = *buf + size; + upb_Message_SetFieldByDef(msg, upb_MessageDef_FindFieldByNumber(m, 1), + seconds, d->arena); + upb_Message_SetFieldByDef(msg, upb_MessageDef_FindFieldByNumber(m, 2), nanos, + d->arena); } -static upb_StringView jsondec_string(jsondec* d) { - char* buf = NULL; - char* end = NULL; - char* buf_end = NULL; - - jsondec_skipws(d); +static void jsondec_listvalue(jsondec* d, upb_Message* msg, + const upb_MessageDef* m) { + const upb_FieldDef* values_f = upb_MessageDef_FindFieldByNumber(m, 1); + const upb_MessageDef* value_m = upb_FieldDef_MessageSubDef(values_f); + const upb_MiniTable* value_layout = upb_MessageDef_MiniTable(value_m); + upb_Array* values = upb_Message_Mutable(msg, values_f, d->arena).array; - if (*d->ptr++ != '"') { - jsondec_err(d, "Expected string"); + jsondec_arrstart(d); + while (jsondec_arrnext(d)) { + upb_Message* value_msg = upb_Message_New(value_layout, d->arena); + upb_MessageValue value; + value.msg_val = value_msg; + upb_Array_Append(values, value, d->arena); + jsondec_wellknownvalue(d, value_msg, value_m); } + jsondec_arrend(d); +} - while (d->ptr < d->end) { - char ch = *d->ptr++; - - if (end == buf_end) { - jsondec_resize(d, &buf, &end, &buf_end); - } +static void jsondec_struct(jsondec* d, upb_Message* msg, + const upb_MessageDef* m) { + const upb_FieldDef* fields_f = upb_MessageDef_FindFieldByNumber(m, 1); + const upb_MessageDef* entry_m = upb_FieldDef_MessageSubDef(fields_f); + const upb_FieldDef* value_f = upb_MessageDef_FindFieldByNumber(entry_m, 2); + const upb_MessageDef* value_m = upb_FieldDef_MessageSubDef(value_f); + const upb_MiniTable* value_layout = upb_MessageDef_MiniTable(value_m); + upb_Map* fields = upb_Message_Mutable(msg, fields_f, d->arena).map; - switch (ch) { - case '"': { - upb_StringView ret; - ret.data = buf; - ret.size = end - buf; - *end = '\0'; /* Needed for possible strtod(). */ - return ret; - } - case '\\': - if (d->ptr == d->end) goto eof; - if (*d->ptr == 'u') { - d->ptr++; - if (buf_end - end < 4) { - /* Allow space for maximum-sized codepoint (4 bytes). */ - jsondec_resize(d, &buf, &end, &buf_end); - } - end += jsondec_unicode(d, end); - } else { - *end++ = jsondec_escape(d); - } - break; - default: - if ((unsigned char)ch < 0x20) { - jsondec_err(d, "Invalid char in JSON string"); - } - *end++ = ch; - break; - } + jsondec_objstart(d); + while (jsondec_objnext(d)) { + upb_MessageValue key, value; + upb_Message* value_msg = upb_Message_New(value_layout, d->arena); + key.str_val = jsondec_string(d); + value.msg_val = value_msg; + upb_Map_Set(fields, key, value, d->arena); + jsondec_entrysep(d); + jsondec_wellknownvalue(d, value_msg, value_m); } - -eof: - jsondec_err(d, "EOF inside string"); + jsondec_objend(d); } -static void jsondec_skipval(jsondec* d) { +static void jsondec_wellknownvalue(jsondec* d, upb_Message* msg, + const upb_MessageDef* m) { + upb_MessageValue val; + const upb_FieldDef* f; + upb_Message* submsg; + switch (jsondec_peek(d)) { - case JD_OBJECT: - jsondec_objstart(d); - while (jsondec_objnext(d)) { - jsondec_string(d); - jsondec_entrysep(d); - jsondec_skipval(d); - } - jsondec_objend(d); - break; - case JD_ARRAY: - jsondec_arrstart(d); - while (jsondec_arrnext(d)) { - jsondec_skipval(d); - } - jsondec_arrend(d); + case JD_NUMBER: + /* double number_value = 2; */ + f = upb_MessageDef_FindFieldByNumber(m, 2); + val.double_val = jsondec_number(d); break; - case JD_TRUE: - jsondec_true(d); + case JD_STRING: + /* string string_value = 3; */ + f = upb_MessageDef_FindFieldByNumber(m, 3); + val.str_val = jsondec_string(d); break; case JD_FALSE: + /* bool bool_value = 4; */ + f = upb_MessageDef_FindFieldByNumber(m, 4); + val.bool_val = false; jsondec_false(d); break; + case JD_TRUE: + /* bool bool_value = 4; */ + f = upb_MessageDef_FindFieldByNumber(m, 4); + val.bool_val = true; + jsondec_true(d); + break; case JD_NULL: + /* NullValue null_value = 1; */ + f = upb_MessageDef_FindFieldByNumber(m, 1); + val.int32_val = 0; jsondec_null(d); break; - case JD_STRING: - jsondec_string(d); - break; - case JD_NUMBER: - jsondec_number(d); - break; + /* Note: these cases return, because upb_Message_Mutable() is enough. */ + case JD_OBJECT: + /* Struct struct_value = 5; */ + f = upb_MessageDef_FindFieldByNumber(m, 5); + submsg = upb_Message_Mutable(msg, f, d->arena).msg; + jsondec_struct(d, submsg, upb_FieldDef_MessageSubDef(f)); + return; + case JD_ARRAY: + /* ListValue list_value = 6; */ + f = upb_MessageDef_FindFieldByNumber(m, 6); + submsg = upb_Message_Mutable(msg, f, d->arena).msg; + jsondec_listvalue(d, submsg, upb_FieldDef_MessageSubDef(f)); + return; + default: + UPB_UNREACHABLE(); } -} - -/* Base64 decoding for bytes fields. ******************************************/ - -static unsigned int jsondec_base64_tablelookup(const char ch) { - /* Table includes the normal base64 chars plus the URL-safe variant. */ - const signed char table[256] = { - -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, - -1, 62 /*+*/, -1, 62 /*-*/, -1, 63 /*/ */, 52 /*0*/, - 53 /*1*/, 54 /*2*/, 55 /*3*/, 56 /*4*/, 57 /*5*/, 58 /*6*/, 59 /*7*/, - 60 /*8*/, 61 /*9*/, -1, -1, -1, -1, -1, - -1, -1, 0 /*A*/, 1 /*B*/, 2 /*C*/, 3 /*D*/, 4 /*E*/, - 5 /*F*/, 6 /*G*/, 07 /*H*/, 8 /*I*/, 9 /*J*/, 10 /*K*/, 11 /*L*/, - 12 /*M*/, 13 /*N*/, 14 /*O*/, 15 /*P*/, 16 /*Q*/, 17 /*R*/, 18 /*S*/, - 19 /*T*/, 20 /*U*/, 21 /*V*/, 22 /*W*/, 23 /*X*/, 24 /*Y*/, 25 /*Z*/, - -1, -1, -1, -1, 63 /*_*/, -1, 26 /*a*/, - 27 /*b*/, 28 /*c*/, 29 /*d*/, 30 /*e*/, 31 /*f*/, 32 /*g*/, 33 /*h*/, - 34 /*i*/, 35 /*j*/, 36 /*k*/, 37 /*l*/, 38 /*m*/, 39 /*n*/, 40 /*o*/, - 41 /*p*/, 42 /*q*/, 43 /*r*/, 44 /*s*/, 45 /*t*/, 46 /*u*/, 47 /*v*/, - 48 /*w*/, 49 /*x*/, 50 /*y*/, 51 /*z*/, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1}; - /* Sign-extend return value so high bit will be set on any unexpected char. */ - return table[(unsigned)ch]; + upb_Message_SetFieldByDef(msg, f, val, d->arena); } -static char* jsondec_partialbase64(jsondec* d, const char* ptr, const char* end, - char* out) { - int32_t val = -1; +static upb_StringView jsondec_mask(jsondec* d, const char* buf, + const char* end) { + /* FieldMask fields grow due to inserted '_' characters, so we can't do the + * transform in place. */ + const char* ptr = buf; + upb_StringView ret; + char* out; - switch (end - ptr) { - case 2: - val = jsondec_base64_tablelookup(ptr[0]) << 18 | - jsondec_base64_tablelookup(ptr[1]) << 12; - out[0] = val >> 16; - out += 1; - break; - case 3: - val = jsondec_base64_tablelookup(ptr[0]) << 18 | - jsondec_base64_tablelookup(ptr[1]) << 12 | - jsondec_base64_tablelookup(ptr[2]) << 6; - out[0] = val >> 16; - out[1] = (val >> 8) & 0xff; - out += 2; - break; + ret.size = end - ptr; + while (ptr < end) { + ret.size += (*ptr >= 'A' && *ptr <= 'Z'); + ptr++; } - if (val < 0) { - jsondec_err(d, "Corrupt base64"); + out = upb_Arena_Malloc(d->arena, ret.size); + ptr = buf; + ret.data = out; + + while (ptr < end) { + char ch = *ptr++; + if (ch >= 'A' && ch <= 'Z') { + *out++ = '_'; + *out++ = ch + 32; + } else if (ch == '_') { + jsondec_err(d, "field mask may not contain '_'"); + } else { + *out++ = ch; + } } - return out; + return ret; } -static size_t jsondec_base64(jsondec* d, upb_StringView str) { - /* We decode in place. This is safe because this is a new buffer (not - * aliasing the input) and because base64 decoding shrinks 4 bytes into 3. */ - char* out = (char*)str.data; +static void jsondec_fieldmask(jsondec* d, upb_Message* msg, + const upb_MessageDef* m) { + /* repeated string paths = 1; */ + const upb_FieldDef* paths_f = upb_MessageDef_FindFieldByNumber(m, 1); + upb_Array* arr = upb_Message_Mutable(msg, paths_f, d->arena).array; + upb_StringView str = jsondec_string(d); const char* ptr = str.data; const char* end = ptr + str.size; - const char* end4 = ptr + (str.size & -4); /* Round down to multiple of 4. */ - - for (; ptr < end4; ptr += 4, out += 3) { - int val = jsondec_base64_tablelookup(ptr[0]) << 18 | - jsondec_base64_tablelookup(ptr[1]) << 12 | - jsondec_base64_tablelookup(ptr[2]) << 6 | - jsondec_base64_tablelookup(ptr[3]) << 0; + upb_MessageValue val; - if (val < 0) { - /* Junk chars or padding. Remove trailing padding, if any. */ - if (end - ptr == 4 && ptr[3] == '=') { - if (ptr[2] == '=') { - end -= 2; - } else { - end -= 1; - } - } - break; + while (ptr < end) { + const char* elem_end = memchr(ptr, ',', end - ptr); + if (elem_end) { + val.str_val = jsondec_mask(d, ptr, elem_end); + ptr = elem_end + 1; + } else { + val.str_val = jsondec_mask(d, ptr, end); + ptr = end; } - - out[0] = val >> 16; - out[1] = (val >> 8) & 0xff; - out[2] = val & 0xff; + upb_Array_Append(arr, val, d->arena); } +} - if (ptr < end) { - /* Process remaining chars. We do not require padding. */ - out = jsondec_partialbase64(d, ptr, end, out); +static void jsondec_anyfield(jsondec* d, upb_Message* msg, + const upb_MessageDef* m) { + if (upb_MessageDef_WellKnownType(m) == kUpb_WellKnown_Unspecified) { + /* For regular types: {"@type": "[user type]", "f1": , "f2": } + * where f1, f2, etc. are the normal fields of this type. */ + jsondec_field(d, msg, m); + } else { + /* For well-known types: {"@type": "[well-known type]", "value": } + * where is whatever encoding the WKT normally uses. */ + upb_StringView str = jsondec_string(d); + jsondec_entrysep(d); + if (!jsondec_streql(str, "value")) { + jsondec_err(d, "Key for well-known type must be 'value'"); + } + jsondec_wellknown(d, msg, m); } - - return out - str.data; } -/* Low-level integer parsing **************************************************/ +static const upb_MessageDef* jsondec_typeurl(jsondec* d, upb_Message* msg, + const upb_MessageDef* m) { + const upb_FieldDef* type_url_f = upb_MessageDef_FindFieldByNumber(m, 1); + const upb_MessageDef* type_m; + upb_StringView type_url = jsondec_string(d); + const char* end = type_url.data + type_url.size; + const char* ptr = end; + upb_MessageValue val; -static const char* jsondec_buftouint64(jsondec* d, const char* ptr, - const char* end, uint64_t* val) { - const char* out = upb_BufToUint64(ptr, end, val); - if (!out) jsondec_err(d, "Integer overflow"); - return out; -} + val.str_val = type_url; + upb_Message_SetFieldByDef(msg, type_url_f, val, d->arena); -static const char* jsondec_buftoint64(jsondec* d, const char* ptr, - const char* end, int64_t* val, - bool* is_neg) { - const char* out = upb_BufToInt64(ptr, end, val, is_neg); - if (!out) jsondec_err(d, "Integer overflow"); - return out; -} + /* Find message name after the last '/' */ + while (ptr > type_url.data && *--ptr != '/') { + } -static uint64_t jsondec_strtouint64(jsondec* d, upb_StringView str) { - const char* end = str.data + str.size; - uint64_t ret; - if (jsondec_buftouint64(d, str.data, end, &ret) != end) { - jsondec_err(d, "Non-number characters in quoted integer"); + if (ptr == type_url.data || ptr == end) { + jsondec_err(d, "Type url must have at least one '/' and non-empty host"); } - return ret; -} -static int64_t jsondec_strtoint64(jsondec* d, upb_StringView str) { - const char* end = str.data + str.size; - int64_t ret; - if (jsondec_buftoint64(d, str.data, end, &ret, NULL) != end) { - jsondec_err(d, "Non-number characters in quoted integer"); + ptr++; + type_m = upb_DefPool_FindMessageByNameWithSize(d->symtab, ptr, end - ptr); + + if (!type_m) { + jsondec_err(d, "Type was not found"); } - return ret; + + return type_m; } -/* Primitive value types ******************************************************/ +static void jsondec_any(jsondec* d, upb_Message* msg, const upb_MessageDef* m) { + /* string type_url = 1; + * bytes value = 2; */ + const upb_FieldDef* value_f = upb_MessageDef_FindFieldByNumber(m, 2); + upb_Message* any_msg; + const upb_MessageDef* any_m = NULL; + const char* pre_type_data = NULL; + const char* pre_type_end = NULL; + upb_MessageValue encoded; -/* Parse INT32 or INT64 value. */ -static upb_MessageValue jsondec_int(jsondec* d, const upb_FieldDef* f) { - upb_MessageValue val; + jsondec_objstart(d); - switch (jsondec_peek(d)) { - case JD_NUMBER: { - double dbl = jsondec_number(d); - if (dbl > 9223372036854774784.0 || dbl < -9223372036854775808.0) { - jsondec_err(d, "JSON number is out of range."); + /* Scan looking for "@type", which is not necessarily first. */ + while (!any_m && jsondec_objnext(d)) { + const char* start = d->ptr; + upb_StringView name = jsondec_string(d); + jsondec_entrysep(d); + if (jsondec_streql(name, "@type")) { + any_m = jsondec_typeurl(d, msg, m); + if (pre_type_data) { + pre_type_end = start; + while (*pre_type_end != ',') pre_type_end--; } - val.int64_val = dbl; /* must be guarded, overflow here is UB */ - if (val.int64_val != dbl) { - jsondec_errf(d, "JSON number was not integral (%f != %" PRId64 ")", dbl, - val.int64_val); - } - break; - } - case JD_STRING: { - upb_StringView str = jsondec_string(d); - val.int64_val = jsondec_strtoint64(d, str); - break; + } else { + if (!pre_type_data) pre_type_data = start; + jsondec_skipval(d); } - default: - jsondec_err(d, "Expected number or string"); } - if (upb_FieldDef_CType(f) == kUpb_CType_Int32 || - upb_FieldDef_CType(f) == kUpb_CType_Enum) { - if (val.int64_val > INT32_MAX || val.int64_val < INT32_MIN) { - jsondec_err(d, "Integer out of range."); - } - val.int32_val = (int32_t)val.int64_val; + if (!any_m) { + jsondec_err(d, "Any object didn't contain a '@type' field"); } - return val; -} - -/* Parse UINT32 or UINT64 value. */ -static upb_MessageValue jsondec_uint(jsondec* d, const upb_FieldDef* f) { - upb_MessageValue val = {0}; + const upb_MiniTable* any_layout = upb_MessageDef_MiniTable(any_m); + any_msg = upb_Message_New(any_layout, d->arena); - switch (jsondec_peek(d)) { - case JD_NUMBER: { - double dbl = jsondec_number(d); - if (dbl > 18446744073709549568.0 || dbl < 0) { - jsondec_err(d, "JSON number is out of range."); - } - val.uint64_val = dbl; /* must be guarded, overflow here is UB */ - if (val.uint64_val != dbl) { - jsondec_errf(d, "JSON number was not integral (%f != %" PRIu64 ")", dbl, - val.uint64_val); - } - break; - } - case JD_STRING: { - upb_StringView str = jsondec_string(d); - val.uint64_val = jsondec_strtouint64(d, str); - break; + if (pre_type_data) { + size_t len = pre_type_end - pre_type_data + 1; + char* tmp = upb_Arena_Malloc(d->arena, len); + const char* saved_ptr = d->ptr; + const char* saved_end = d->end; + memcpy(tmp, pre_type_data, len - 1); + tmp[len - 1] = '}'; + d->ptr = tmp; + d->end = tmp + len; + d->is_first = true; + while (jsondec_objnext(d)) { + jsondec_anyfield(d, any_msg, any_m); } - default: - jsondec_err(d, "Expected number or string"); + d->ptr = saved_ptr; + d->end = saved_end; } - if (upb_FieldDef_CType(f) == kUpb_CType_UInt32) { - if (val.uint64_val > UINT32_MAX) { - jsondec_err(d, "Integer out of range."); - } - val.uint32_val = (uint32_t)val.uint64_val; + while (jsondec_objnext(d)) { + jsondec_anyfield(d, any_msg, any_m); } - return val; + jsondec_objend(d); + + upb_EncodeStatus status = + upb_Encode(any_msg, upb_MessageDef_MiniTable(any_m), 0, d->arena, + (char**)&encoded.str_val.data, &encoded.str_val.size); + // TODO: We should fail gracefully here on a bad return status. + UPB_ASSERT(status == kUpb_EncodeStatus_Ok); + upb_Message_SetFieldByDef(msg, value_f, encoded, d->arena); } -/* Parse DOUBLE or FLOAT value. */ -static upb_MessageValue jsondec_double(jsondec* d, const upb_FieldDef* f) { - upb_StringView str; - upb_MessageValue val = {0}; +static void jsondec_wrapper(jsondec* d, upb_Message* msg, + const upb_MessageDef* m) { + const upb_FieldDef* value_f = upb_MessageDef_FindFieldByNumber(m, 1); + upb_JsonMessageValue val = jsondec_value(d, value_f); + UPB_ASSUME(val.ignore == false); // Wrapper cannot be an enum. + upb_Message_SetFieldByDef(msg, value_f, val.value, d->arena); +} - switch (jsondec_peek(d)) { - case JD_NUMBER: - val.double_val = jsondec_number(d); +static void jsondec_wellknown(jsondec* d, upb_Message* msg, + const upb_MessageDef* m) { + switch (upb_MessageDef_WellKnownType(m)) { + case kUpb_WellKnown_Any: + jsondec_any(d, msg, m); break; - case JD_STRING: - str = jsondec_string(d); - if (jsondec_streql(str, "NaN")) { - val.double_val = NAN; - } else if (jsondec_streql(str, "Infinity")) { - val.double_val = INFINITY; - } else if (jsondec_streql(str, "-Infinity")) { - val.double_val = -INFINITY; - } else { - val.double_val = strtod(str.data, NULL); - } + case kUpb_WellKnown_FieldMask: + jsondec_fieldmask(d, msg, m); + break; + case kUpb_WellKnown_Duration: + jsondec_duration(d, msg, m); + break; + case kUpb_WellKnown_Timestamp: + jsondec_timestamp(d, msg, m); + break; + case kUpb_WellKnown_Value: + jsondec_wellknownvalue(d, msg, m); + break; + case kUpb_WellKnown_ListValue: + jsondec_listvalue(d, msg, m); + break; + case kUpb_WellKnown_Struct: + jsondec_struct(d, msg, m); + break; + case kUpb_WellKnown_DoubleValue: + case kUpb_WellKnown_FloatValue: + case kUpb_WellKnown_Int64Value: + case kUpb_WellKnown_UInt64Value: + case kUpb_WellKnown_Int32Value: + case kUpb_WellKnown_UInt32Value: + case kUpb_WellKnown_StringValue: + case kUpb_WellKnown_BytesValue: + case kUpb_WellKnown_BoolValue: + jsondec_wrapper(d, msg, m); break; default: - jsondec_err(d, "Expected number or string"); + UPB_UNREACHABLE(); } +} - if (upb_FieldDef_CType(f) == kUpb_CType_Float) { - float f = val.double_val; - if (val.double_val != INFINITY && val.double_val != -INFINITY) { - if (f == INFINITY || f == -INFINITY) jsondec_err(d, "Float out of range"); - } - val.float_val = f; - } +static bool upb_JsonDecoder_Decode(jsondec* const d, upb_Message* const msg, + const upb_MessageDef* const m) { + if (UPB_SETJMP(d->err)) return false; - return val; -} + jsondec_tomsg(d, msg, m); -/* Parse STRING or BYTES value. */ -static upb_MessageValue jsondec_strfield(jsondec* d, const upb_FieldDef* f) { - upb_MessageValue val; - val.str_val = jsondec_string(d); - if (upb_FieldDef_CType(f) == kUpb_CType_Bytes) { - val.str_val.size = jsondec_base64(d, val.str_val); - } - return val; -} + // Consume any trailing whitespace before checking if we read the entire + // input. + jsondec_consumews(d); -static upb_JsonMessageValue jsondec_enum(jsondec* d, const upb_FieldDef* f) { - switch (jsondec_peek(d)) { - case JD_STRING: { - upb_StringView str = jsondec_string(d); - const upb_EnumDef* e = upb_FieldDef_EnumSubDef(f); - const upb_EnumValueDef* ev = - upb_EnumDef_FindValueByNameWithSize(e, str.data, str.size); - upb_JsonMessageValue val = {.ignore = false}; - if (ev) { - val.value.int32_val = upb_EnumValueDef_Number(ev); - } else { - if (d->options & upb_JsonDecode_IgnoreUnknown) { - val.ignore = true; - } else { - jsondec_errf(d, "Unknown enumerator: '" UPB_STRINGVIEW_FORMAT "'", - UPB_STRINGVIEW_ARGS(str)); - } - } - return val; - } - case JD_NULL: { - if (jsondec_isnullvalue(f)) { - upb_JsonMessageValue val = {.ignore = false}; - jsondec_null(d); - val.value.int32_val = 0; - return val; - } - } - /* Fallthrough. */ - default: - return (upb_JsonMessageValue){.value = jsondec_int(d, f), - .ignore = false}; + if (d->ptr == d->end) { + return true; + } else { + jsondec_seterrmsg(d, "unexpected trailing characters"); + return false; } } -static upb_MessageValue jsondec_bool(jsondec* d, const upb_FieldDef* f) { - bool is_map_key = upb_FieldDef_Number(f) == 1 && - upb_MessageDef_IsMapEntry(upb_FieldDef_ContainingType(f)); - upb_MessageValue val; +bool upb_JsonDecode(const char* buf, size_t size, upb_Message* msg, + const upb_MessageDef* m, const upb_DefPool* symtab, + int options, upb_Arena* arena, upb_Status* status) { + jsondec d; - if (is_map_key) { - upb_StringView str = jsondec_string(d); - if (jsondec_streql(str, "true")) { - val.bool_val = true; - } else if (jsondec_streql(str, "false")) { - val.bool_val = false; - } else { - jsondec_err(d, "Invalid boolean map key"); - } - } else { - switch (jsondec_peek(d)) { - case JD_TRUE: - val.bool_val = true; - jsondec_true(d); - break; - case JD_FALSE: - val.bool_val = false; - jsondec_false(d); - break; - default: - jsondec_err(d, "Expected true or false"); - } - } + if (size == 0) return true; - return val; + d.ptr = buf; + d.end = buf + size; + d.arena = arena; + d.symtab = symtab; + d.status = status; + d.options = options; + d.depth = 64; + d.line = 1; + d.line_begin = d.ptr; + d.debug_field = NULL; + d.is_first = false; + + return upb_JsonDecoder_Decode(&d, msg, m); } -/* Composite types (array/message/map) ****************************************/ -static void jsondec_array(jsondec* d, upb_Message* msg, const upb_FieldDef* f) { - upb_Array* arr = upb_Message_Mutable(msg, f, d->arena).array; +#include +#include +#include +#include +#include +#include - jsondec_arrstart(d); - while (jsondec_arrnext(d)) { - upb_JsonMessageValue elem = jsondec_value(d, f); - if (!elem.ignore) { - upb_Array_Append(arr, elem.value, d->arena); - } - } - jsondec_arrend(d); + +// Must be last. + +typedef struct { + char *buf, *ptr, *end; + size_t overflow; + int indent_depth; + int options; + const upb_DefPool* ext_pool; + jmp_buf err; + upb_Status* status; + upb_Arena* arena; +} jsonenc; + +static void jsonenc_msg(jsonenc* e, const upb_Message* msg, + const upb_MessageDef* m); +static void jsonenc_scalar(jsonenc* e, upb_MessageValue val, + const upb_FieldDef* f); +static void jsonenc_msgfield(jsonenc* e, const upb_Message* msg, + const upb_MessageDef* m); +static void jsonenc_msgfields(jsonenc* e, const upb_Message* msg, + const upb_MessageDef* m, bool first); +static void jsonenc_value(jsonenc* e, const upb_Message* msg, + const upb_MessageDef* m); + +UPB_NORETURN static void jsonenc_err(jsonenc* e, const char* msg) { + upb_Status_SetErrorMessage(e->status, msg); + longjmp(e->err, 1); } -static void jsondec_map(jsondec* d, upb_Message* msg, const upb_FieldDef* f) { - upb_Map* map = upb_Message_Mutable(msg, f, d->arena).map; - const upb_MessageDef* entry = upb_FieldDef_MessageSubDef(f); - const upb_FieldDef* key_f = upb_MessageDef_FindFieldByNumber(entry, 1); - const upb_FieldDef* val_f = upb_MessageDef_FindFieldByNumber(entry, 2); +UPB_PRINTF(2, 3) +UPB_NORETURN static void jsonenc_errf(jsonenc* e, const char* fmt, ...) { + va_list argp; + va_start(argp, fmt); + upb_Status_VSetErrorFormat(e->status, fmt, argp); + va_end(argp); + longjmp(e->err, 1); +} - jsondec_objstart(d); - while (jsondec_objnext(d)) { - upb_JsonMessageValue key, val; - key = jsondec_value(d, key_f); - UPB_ASSUME(!key.ignore); // Map key cannot be enum. - jsondec_entrysep(d); - val = jsondec_value(d, val_f); - if (!val.ignore) { - upb_Map_Set(map, key.value, val.value, d->arena); - } +static upb_Arena* jsonenc_arena(jsonenc* e) { + /* Create lazily, since it's only needed for Any */ + if (!e->arena) { + e->arena = upb_Arena_New(); } - jsondec_objend(d); + return e->arena; } -static void jsondec_tomsg(jsondec* d, upb_Message* msg, - const upb_MessageDef* m) { - if (upb_MessageDef_WellKnownType(m) == kUpb_WellKnown_Unspecified) { - jsondec_object(d, msg, m); +static void jsonenc_putbytes(jsonenc* e, const void* data, size_t len) { + size_t have = e->end - e->ptr; + if (UPB_LIKELY(have >= len)) { + memcpy(e->ptr, data, len); + e->ptr += len; } else { - jsondec_wellknown(d, msg, m); + if (have) { + memcpy(e->ptr, data, have); + e->ptr += have; + } + e->overflow += (len - have); } } -static upb_MessageValue jsondec_msg(jsondec* d, const upb_FieldDef* f) { - const upb_MessageDef* m = upb_FieldDef_MessageSubDef(f); - const upb_MiniTable* layout = upb_MessageDef_MiniTable(m); - upb_Message* msg = upb_Message_New(layout, d->arena); - upb_MessageValue val; - - jsondec_tomsg(d, msg, m); - val.msg_val = msg; - return val; +static void jsonenc_putstr(jsonenc* e, const char* str) { + jsonenc_putbytes(e, str, strlen(str)); } -static void jsondec_field(jsondec* d, upb_Message* msg, - const upb_MessageDef* m) { - upb_StringView name; - const upb_FieldDef* f; - const upb_FieldDef* preserved; +UPB_PRINTF(2, 3) +static void jsonenc_printf(jsonenc* e, const char* fmt, ...) { + size_t n; + size_t have = e->end - e->ptr; + va_list args; - name = jsondec_string(d); - jsondec_entrysep(d); + va_start(args, fmt); + n = _upb_vsnprintf(e->ptr, have, fmt, args); + va_end(args); - if (name.size >= 2 && name.data[0] == '[' && - name.data[name.size - 1] == ']') { - f = upb_DefPool_FindExtensionByNameWithSize(d->symtab, name.data + 1, - name.size - 2); - if (f && upb_FieldDef_ContainingType(f) != m) { - jsondec_errf( - d, "Extension %s extends message %s, but was seen in message %s", - upb_FieldDef_FullName(f), - upb_MessageDef_FullName(upb_FieldDef_ContainingType(f)), - upb_MessageDef_FullName(m)); - } + if (UPB_LIKELY(have > n)) { + e->ptr += n; } else { - f = upb_MessageDef_FindByJsonNameWithSize(m, name.data, name.size); - } - - if (!f) { - if ((d->options & upb_JsonDecode_IgnoreUnknown) == 0) { - jsondec_errf(d, "No such field: " UPB_STRINGVIEW_FORMAT, - UPB_STRINGVIEW_ARGS(name)); - } - jsondec_skipval(d); - return; + e->ptr = UPB_PTRADD(e->ptr, have); + e->overflow += (n - have); } +} - if (jsondec_peek(d) == JD_NULL && !jsondec_isvalue(f)) { - /* JSON "null" indicates a default value, so no need to set anything. */ - jsondec_null(d); - return; - } +static void jsonenc_nanos(jsonenc* e, int32_t nanos) { + int digits = 9; - if (upb_FieldDef_RealContainingOneof(f) && - upb_Message_WhichOneof(msg, upb_FieldDef_ContainingOneof(f))) { - jsondec_err(d, "More than one field for this oneof."); + if (nanos == 0) return; + if (nanos < 0 || nanos >= 1000000000) { + jsonenc_err(e, "error formatting timestamp as JSON: invalid nanos"); } - preserved = d->debug_field; - d->debug_field = f; - - if (upb_FieldDef_IsMap(f)) { - jsondec_map(d, msg, f); - } else if (upb_FieldDef_IsRepeated(f)) { - jsondec_array(d, msg, f); - } else if (upb_FieldDef_IsSubMessage(f)) { - upb_Message* submsg = upb_Message_Mutable(msg, f, d->arena).msg; - const upb_MessageDef* subm = upb_FieldDef_MessageSubDef(f); - jsondec_tomsg(d, submsg, subm); - } else { - upb_JsonMessageValue val = jsondec_value(d, f); - if (!val.ignore) { - upb_Message_SetFieldByDef(msg, f, val.value, d->arena); - } + while (nanos % 1000 == 0) { + nanos /= 1000; + digits -= 3; } - d->debug_field = preserved; + jsonenc_printf(e, ".%.*" PRId32, digits, nanos); } -static void jsondec_object(jsondec* d, upb_Message* msg, - const upb_MessageDef* m) { - jsondec_objstart(d); - while (jsondec_objnext(d)) { - jsondec_field(d, msg, m); - } - jsondec_objend(d); -} +static void jsonenc_timestamp(jsonenc* e, const upb_Message* msg, + const upb_MessageDef* m) { + const upb_FieldDef* seconds_f = upb_MessageDef_FindFieldByNumber(m, 1); + const upb_FieldDef* nanos_f = upb_MessageDef_FindFieldByNumber(m, 2); + int64_t seconds = upb_Message_GetFieldByDef(msg, seconds_f).int64_val; + int32_t nanos = upb_Message_GetFieldByDef(msg, nanos_f).int32_val; + int L, N, I, J, K, hour, min, sec; -static upb_MessageValue jsondec_nonenum(jsondec* d, const upb_FieldDef* f) { - switch (upb_FieldDef_CType(f)) { - case kUpb_CType_Bool: - return jsondec_bool(d, f); - case kUpb_CType_Float: - case kUpb_CType_Double: - return jsondec_double(d, f); - case kUpb_CType_UInt32: - case kUpb_CType_UInt64: - return jsondec_uint(d, f); - case kUpb_CType_Int32: - case kUpb_CType_Int64: - return jsondec_int(d, f); - case kUpb_CType_String: - case kUpb_CType_Bytes: - return jsondec_strfield(d, f); - case kUpb_CType_Message: - return jsondec_msg(d, f); - case kUpb_CType_Enum: - default: - UPB_UNREACHABLE(); + if (seconds < -62135596800) { + jsonenc_err(e, + "error formatting timestamp as JSON: minimum acceptable value " + "is 0001-01-01T00:00:00Z"); + } else if (seconds > 253402300799) { + jsonenc_err(e, + "error formatting timestamp as JSON: maximum acceptable value " + "is 9999-12-31T23:59:59Z"); } -} -static upb_JsonMessageValue jsondec_value(jsondec* d, const upb_FieldDef* f) { - if (upb_FieldDef_CType(f) == kUpb_CType_Enum) { - return jsondec_enum(d, f); - } else { - return (upb_JsonMessageValue){.value = jsondec_nonenum(d, f), - .ignore = false}; - } -} + /* Julian Day -> Y/M/D, Algorithm from: + * Fliegel, H. F., and Van Flandern, T. C., "A Machine Algorithm for + * Processing Calendar Dates," Communications of the Association of + * Computing Machines, vol. 11 (1968), p. 657. */ + seconds += 62135596800; // Ensure seconds is positive. + L = (int)(seconds / 86400) - 719162 + 68569 + 2440588; + N = 4 * L / 146097; + L = L - (146097 * N + 3) / 4; + I = 4000 * (L + 1) / 1461001; + L = L - 1461 * I / 4 + 31; + J = 80 * L / 2447; + K = L - 2447 * J / 80; + L = J / 11; + J = J + 2 - 12 * L; + I = 100 * (N - 49) + I + L; -/* Well-known types ***********************************************************/ + sec = seconds % 60; + min = (seconds / 60) % 60; + hour = (seconds / 3600) % 24; -static int jsondec_tsdigits(jsondec* d, const char** ptr, size_t digits, - const char* after) { - uint64_t val; - const char* p = *ptr; - const char* end = p + digits; - size_t after_len = after ? strlen(after) : 0; + jsonenc_printf(e, "\"%04d-%02d-%02dT%02d:%02d:%02d", I, J, K, hour, min, sec); + jsonenc_nanos(e, nanos); + jsonenc_putstr(e, "Z\""); +} - UPB_ASSERT(digits <= 9); /* int can't overflow. */ +static void jsonenc_duration(jsonenc* e, const upb_Message* msg, + const upb_MessageDef* m) { + const upb_FieldDef* seconds_f = upb_MessageDef_FindFieldByNumber(m, 1); + const upb_FieldDef* nanos_f = upb_MessageDef_FindFieldByNumber(m, 2); + int64_t seconds = upb_Message_GetFieldByDef(msg, seconds_f).int64_val; + int32_t nanos = upb_Message_GetFieldByDef(msg, nanos_f).int32_val; + bool negative = false; - if (jsondec_buftouint64(d, p, end, &val) != end || - (after_len && memcmp(end, after, after_len) != 0)) { - jsondec_err(d, "Malformed timestamp"); + if (seconds > 315576000000 || seconds < -315576000000 || + (seconds != 0 && nanos != 0 && (seconds < 0) != (nanos < 0))) { + jsonenc_err(e, "bad duration"); } - UPB_ASSERT(val < INT_MAX); + if (seconds < 0) { + negative = true; + seconds = -seconds; + } + if (nanos < 0) { + negative = true; + nanos = -nanos; + } - *ptr = end + after_len; - return (int)val; + jsonenc_putstr(e, "\""); + if (negative) { + jsonenc_putstr(e, "-"); + } + jsonenc_printf(e, "%" PRId64, seconds); + jsonenc_nanos(e, nanos); + jsonenc_putstr(e, "s\""); } -static int jsondec_nanos(jsondec* d, const char** ptr, const char* end) { - uint64_t nanos = 0; - const char* p = *ptr; +static void jsonenc_enum(int32_t val, const upb_FieldDef* f, jsonenc* e) { + const upb_EnumDef* e_def = upb_FieldDef_EnumSubDef(f); - if (p != end && *p == '.') { - const char* nano_end = jsondec_buftouint64(d, p + 1, end, &nanos); - int digits = (int)(nano_end - p - 1); - int exp_lg10 = 9 - digits; - if (digits > 9) { - jsondec_err(d, "Too many digits for partial seconds"); + if (strcmp(upb_EnumDef_FullName(e_def), "google.protobuf.NullValue") == 0) { + jsonenc_putstr(e, "null"); + } else { + const upb_EnumValueDef* ev = + (e->options & upb_JsonEncode_FormatEnumsAsIntegers) + ? NULL + : upb_EnumDef_FindValueByNumber(e_def, val); + + if (ev) { + jsonenc_printf(e, "\"%s\"", upb_EnumValueDef_Name(ev)); + } else { + jsonenc_printf(e, "%" PRId32, val); } - while (exp_lg10--) nanos *= 10; - *ptr = nano_end; } - - UPB_ASSERT(nanos < INT_MAX); - - return (int)nanos; -} - -/* jsondec_epochdays(1970, 1, 1) == 1970-01-01 == 0. */ -int jsondec_epochdays(int y, int m, int d) { - const uint32_t year_base = 4800; /* Before min year, multiple of 400. */ - const uint32_t m_adj = m - 3; /* March-based month. */ - const uint32_t carry = m_adj > (uint32_t)m ? 1 : 0; - const uint32_t adjust = carry ? 12 : 0; - const uint32_t y_adj = y + year_base - carry; - const uint32_t month_days = ((m_adj + adjust) * 62719 + 769) / 2048; - const uint32_t leap_days = y_adj / 4 - y_adj / 100 + y_adj / 400; - return y_adj * 365 + leap_days + month_days + (d - 1) - 2472632; -} - -static int64_t jsondec_unixtime(int y, int m, int d, int h, int min, int s) { - return (int64_t)jsondec_epochdays(y, m, d) * 86400 + h * 3600 + min * 60 + s; } -static void jsondec_timestamp(jsondec* d, upb_Message* msg, - const upb_MessageDef* m) { - upb_MessageValue seconds; - upb_MessageValue nanos; - upb_StringView str = jsondec_string(d); - const char* ptr = str.data; - const char* end = ptr + str.size; - - if (str.size < 20) goto malformed; +static void jsonenc_bytes(jsonenc* e, upb_StringView str) { + /* This is the regular base64, not the "web-safe" version. */ + static const char base64[] = + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; + const unsigned char* ptr = (unsigned char*)str.data; + const unsigned char* end = UPB_PTRADD(ptr, str.size); + char buf[4]; - { - /* 1972-01-01T01:00:00 */ - int year = jsondec_tsdigits(d, &ptr, 4, "-"); - int mon = jsondec_tsdigits(d, &ptr, 2, "-"); - int day = jsondec_tsdigits(d, &ptr, 2, "T"); - int hour = jsondec_tsdigits(d, &ptr, 2, ":"); - int min = jsondec_tsdigits(d, &ptr, 2, ":"); - int sec = jsondec_tsdigits(d, &ptr, 2, NULL); + jsonenc_putstr(e, "\""); - seconds.int64_val = jsondec_unixtime(year, mon, day, hour, min, sec); + while (end - ptr >= 3) { + buf[0] = base64[ptr[0] >> 2]; + buf[1] = base64[((ptr[0] & 0x3) << 4) | (ptr[1] >> 4)]; + buf[2] = base64[((ptr[1] & 0xf) << 2) | (ptr[2] >> 6)]; + buf[3] = base64[ptr[2] & 0x3f]; + jsonenc_putbytes(e, buf, 4); + ptr += 3; } - nanos.int32_val = jsondec_nanos(d, &ptr, end); + switch (end - ptr) { + case 2: + buf[0] = base64[ptr[0] >> 2]; + buf[1] = base64[((ptr[0] & 0x3) << 4) | (ptr[1] >> 4)]; + buf[2] = base64[(ptr[1] & 0xf) << 2]; + buf[3] = '='; + jsonenc_putbytes(e, buf, 4); + break; + case 1: + buf[0] = base64[ptr[0] >> 2]; + buf[1] = base64[((ptr[0] & 0x3) << 4)]; + buf[2] = '='; + buf[3] = '='; + jsonenc_putbytes(e, buf, 4); + break; + } - { - /* [+-]08:00 or Z */ - int ofs_hour = 0; - int ofs_min = 0; - bool neg = false; + jsonenc_putstr(e, "\""); +} - if (ptr == end) goto malformed; +static void jsonenc_stringbody(jsonenc* e, upb_StringView str) { + const char* ptr = str.data; + const char* end = UPB_PTRADD(ptr, str.size); - switch (*ptr++) { - case '-': - neg = true; - /* fallthrough */ - case '+': - if ((end - ptr) != 5) goto malformed; - ofs_hour = jsondec_tsdigits(d, &ptr, 2, ":"); - ofs_min = jsondec_tsdigits(d, &ptr, 2, NULL); - ofs_min = ((ofs_hour * 60) + ofs_min) * 60; - seconds.int64_val += (neg ? ofs_min : -ofs_min); + while (ptr < end) { + switch (*ptr) { + case '\n': + jsonenc_putstr(e, "\\n"); break; - case 'Z': - if (ptr != end) goto malformed; + case '\r': + jsonenc_putstr(e, "\\r"); + break; + case '\t': + jsonenc_putstr(e, "\\t"); + break; + case '\"': + jsonenc_putstr(e, "\\\""); + break; + case '\f': + jsonenc_putstr(e, "\\f"); + break; + case '\b': + jsonenc_putstr(e, "\\b"); + break; + case '\\': + jsonenc_putstr(e, "\\\\"); break; default: - goto malformed; + if ((uint8_t)*ptr < 0x20) { + jsonenc_printf(e, "\\u%04x", (int)(uint8_t)*ptr); + } else { + /* This could be a non-ASCII byte. We rely on the string being valid + * UTF-8. */ + jsonenc_putbytes(e, ptr, 1); + } + break; } + ptr++; } +} - if (seconds.int64_val < -62135596800) { - jsondec_err(d, "Timestamp out of range"); +static void jsonenc_string(jsonenc* e, upb_StringView str) { + jsonenc_putstr(e, "\""); + jsonenc_stringbody(e, str); + jsonenc_putstr(e, "\""); +} + +static bool upb_JsonEncode_HandleSpecialDoubles(jsonenc* e, double val) { + if (val == INFINITY) { + jsonenc_putstr(e, "\"Infinity\""); + } else if (val == -INFINITY) { + jsonenc_putstr(e, "\"-Infinity\""); + } else if (val != val) { + jsonenc_putstr(e, "\"NaN\""); + } else { + return false; } + return true; +} - upb_Message_SetFieldByDef(msg, upb_MessageDef_FindFieldByNumber(m, 1), - seconds, d->arena); - upb_Message_SetFieldByDef(msg, upb_MessageDef_FindFieldByNumber(m, 2), nanos, - d->arena); - return; +static void upb_JsonEncode_Double(jsonenc* e, double val) { + if (upb_JsonEncode_HandleSpecialDoubles(e, val)) return; + char buf[32]; + _upb_EncodeRoundTripDouble(val, buf, sizeof(buf)); + jsonenc_putstr(e, buf); +} -malformed: - jsondec_err(d, "Malformed timestamp"); +static void upb_JsonEncode_Float(jsonenc* e, float val) { + if (upb_JsonEncode_HandleSpecialDoubles(e, val)) return; + char buf[32]; + _upb_EncodeRoundTripFloat(val, buf, sizeof(buf)); + jsonenc_putstr(e, buf); } -static void jsondec_duration(jsondec* d, upb_Message* msg, - const upb_MessageDef* m) { - upb_MessageValue seconds; - upb_MessageValue nanos; - upb_StringView str = jsondec_string(d); - const char* ptr = str.data; - const char* end = ptr + str.size; - const int64_t max = (uint64_t)3652500 * 86400; - bool neg = false; +static void jsonenc_wrapper(jsonenc* e, const upb_Message* msg, + const upb_MessageDef* m) { + const upb_FieldDef* val_f = upb_MessageDef_FindFieldByNumber(m, 1); + upb_MessageValue val = upb_Message_GetFieldByDef(msg, val_f); + jsonenc_scalar(e, val, val_f); +} - /* "3.000000001s", "3s", etc. */ - ptr = jsondec_buftoint64(d, ptr, end, &seconds.int64_val, &neg); - nanos.int32_val = jsondec_nanos(d, &ptr, end); +static const upb_MessageDef* jsonenc_getanymsg(jsonenc* e, + upb_StringView type_url) { + /* Find last '/', if any. */ + const char* end = type_url.data + type_url.size; + const char* ptr = end; + const upb_MessageDef* ret; - if (end - ptr != 1 || *ptr != 's') { - jsondec_err(d, "Malformed duration"); + if (!e->ext_pool) { + jsonenc_err(e, "Tried to encode Any, but no symtab was provided"); } - if (seconds.int64_val < -max || seconds.int64_val > max) { - jsondec_err(d, "Duration out of range"); - } + if (type_url.size == 0) goto badurl; - if (neg) { - nanos.int32_val = -nanos.int32_val; + while (true) { + if (--ptr == type_url.data) { + /* Type URL must contain at least one '/', with host before. */ + goto badurl; + } + if (*ptr == '/') { + ptr++; + break; + } } - upb_Message_SetFieldByDef(msg, upb_MessageDef_FindFieldByNumber(m, 1), - seconds, d->arena); - upb_Message_SetFieldByDef(msg, upb_MessageDef_FindFieldByNumber(m, 2), nanos, - d->arena); -} - -static void jsondec_listvalue(jsondec* d, upb_Message* msg, - const upb_MessageDef* m) { - const upb_FieldDef* values_f = upb_MessageDef_FindFieldByNumber(m, 1); - const upb_MessageDef* value_m = upb_FieldDef_MessageSubDef(values_f); - const upb_MiniTable* value_layout = upb_MessageDef_MiniTable(value_m); - upb_Array* values = upb_Message_Mutable(msg, values_f, d->arena).array; + ret = upb_DefPool_FindMessageByNameWithSize(e->ext_pool, ptr, end - ptr); - jsondec_arrstart(d); - while (jsondec_arrnext(d)) { - upb_Message* value_msg = upb_Message_New(value_layout, d->arena); - upb_MessageValue value; - value.msg_val = value_msg; - upb_Array_Append(values, value, d->arena); - jsondec_wellknownvalue(d, value_msg, value_m); + if (!ret) { + jsonenc_errf(e, "Couldn't find Any type: %.*s", (int)(end - ptr), ptr); } - jsondec_arrend(d); + + return ret; + +badurl: + jsonenc_errf(e, "Bad type URL: " UPB_STRINGVIEW_FORMAT, + UPB_STRINGVIEW_ARGS(type_url)); } -static void jsondec_struct(jsondec* d, upb_Message* msg, - const upb_MessageDef* m) { - const upb_FieldDef* fields_f = upb_MessageDef_FindFieldByNumber(m, 1); - const upb_MessageDef* entry_m = upb_FieldDef_MessageSubDef(fields_f); - const upb_FieldDef* value_f = upb_MessageDef_FindFieldByNumber(entry_m, 2); - const upb_MessageDef* value_m = upb_FieldDef_MessageSubDef(value_f); - const upb_MiniTable* value_layout = upb_MessageDef_MiniTable(value_m); - upb_Map* fields = upb_Message_Mutable(msg, fields_f, d->arena).map; +static void jsonenc_any(jsonenc* e, const upb_Message* msg, + const upb_MessageDef* m) { + const upb_FieldDef* type_url_f = upb_MessageDef_FindFieldByNumber(m, 1); + const upb_FieldDef* value_f = upb_MessageDef_FindFieldByNumber(m, 2); + upb_StringView type_url = upb_Message_GetFieldByDef(msg, type_url_f).str_val; + upb_StringView value = upb_Message_GetFieldByDef(msg, value_f).str_val; + const upb_MessageDef* any_m = jsonenc_getanymsg(e, type_url); + const upb_MiniTable* any_layout = upb_MessageDef_MiniTable(any_m); + upb_Arena* arena = jsonenc_arena(e); + upb_Message* any = upb_Message_New(any_layout, arena); - jsondec_objstart(d); - while (jsondec_objnext(d)) { - upb_MessageValue key, value; - upb_Message* value_msg = upb_Message_New(value_layout, d->arena); - key.str_val = jsondec_string(d); - value.msg_val = value_msg; - upb_Map_Set(fields, key, value, d->arena); - jsondec_entrysep(d); - jsondec_wellknownvalue(d, value_msg, value_m); + if (upb_Decode(value.data, value.size, any, any_layout, NULL, 0, arena) != + kUpb_DecodeStatus_Ok) { + jsonenc_err(e, "Error decoding message in Any"); } - jsondec_objend(d); -} -static void jsondec_wellknownvalue(jsondec* d, upb_Message* msg, - const upb_MessageDef* m) { - upb_MessageValue val; - const upb_FieldDef* f; - upb_Message* submsg; + jsonenc_putstr(e, "{\"@type\":"); + jsonenc_string(e, type_url); - switch (jsondec_peek(d)) { - case JD_NUMBER: - /* double number_value = 2; */ - f = upb_MessageDef_FindFieldByNumber(m, 2); - val.double_val = jsondec_number(d); - break; - case JD_STRING: - /* string string_value = 3; */ - f = upb_MessageDef_FindFieldByNumber(m, 3); - val.str_val = jsondec_string(d); - break; - case JD_FALSE: - /* bool bool_value = 4; */ - f = upb_MessageDef_FindFieldByNumber(m, 4); - val.bool_val = false; - jsondec_false(d); - break; - case JD_TRUE: - /* bool bool_value = 4; */ - f = upb_MessageDef_FindFieldByNumber(m, 4); - val.bool_val = true; - jsondec_true(d); - break; - case JD_NULL: - /* NullValue null_value = 1; */ - f = upb_MessageDef_FindFieldByNumber(m, 1); - val.int32_val = 0; - jsondec_null(d); - break; - /* Note: these cases return, because upb_Message_Mutable() is enough. */ - case JD_OBJECT: - /* Struct struct_value = 5; */ - f = upb_MessageDef_FindFieldByNumber(m, 5); - submsg = upb_Message_Mutable(msg, f, d->arena).msg; - jsondec_struct(d, submsg, upb_FieldDef_MessageSubDef(f)); - return; - case JD_ARRAY: - /* ListValue list_value = 6; */ - f = upb_MessageDef_FindFieldByNumber(m, 6); - submsg = upb_Message_Mutable(msg, f, d->arena).msg; - jsondec_listvalue(d, submsg, upb_FieldDef_MessageSubDef(f)); - return; - default: - UPB_UNREACHABLE(); + if (upb_MessageDef_WellKnownType(any_m) == kUpb_WellKnown_Unspecified) { + /* Regular messages: {"@type": "...","foo": 1, "bar": 2} */ + jsonenc_msgfields(e, any, any_m, false); + } else { + /* Well-known type: {"@type": "...","value": } */ + jsonenc_putstr(e, ",\"value\":"); + jsonenc_msgfield(e, any, any_m); } - upb_Message_SetFieldByDef(msg, f, val, d->arena); + jsonenc_putstr(e, "}"); } -static upb_StringView jsondec_mask(jsondec* d, const char* buf, - const char* end) { - /* FieldMask fields grow due to inserted '_' characters, so we can't do the - * transform in place. */ - const char* ptr = buf; - upb_StringView ret; - char* out; - - ret.size = end - ptr; - while (ptr < end) { - ret.size += (*ptr >= 'A' && *ptr <= 'Z'); - ptr++; +static void jsonenc_putsep(jsonenc* e, const char* str, bool* first) { + if (*first) { + *first = false; + } else { + jsonenc_putstr(e, str); } +} - out = upb_Arena_Malloc(d->arena, ret.size); - ptr = buf; - ret.data = out; +static void jsonenc_fieldpath(jsonenc* e, upb_StringView path) { + const char* ptr = path.data; + const char* end = ptr + path.size; while (ptr < end) { - char ch = *ptr++; + char ch = *ptr; + if (ch >= 'A' && ch <= 'Z') { - *out++ = '_'; - *out++ = ch + 32; + jsonenc_err(e, "Field mask element may not have upper-case letter."); } else if (ch == '_') { - jsondec_err(d, "field mask may not contain '_'"); - } else { - *out++ = ch; + if (ptr == end - 1 || *(ptr + 1) < 'a' || *(ptr + 1) > 'z') { + jsonenc_err(e, "Underscore must be followed by a lowercase letter."); + } + ch = *++ptr - 32; } - } - return ret; + jsonenc_putbytes(e, &ch, 1); + ptr++; + } } -static void jsondec_fieldmask(jsondec* d, upb_Message* msg, +static void jsonenc_fieldmask(jsonenc* e, const upb_Message* msg, const upb_MessageDef* m) { - /* repeated string paths = 1; */ const upb_FieldDef* paths_f = upb_MessageDef_FindFieldByNumber(m, 1); - upb_Array* arr = upb_Message_Mutable(msg, paths_f, d->arena).array; - upb_StringView str = jsondec_string(d); - const char* ptr = str.data; - const char* end = ptr + str.size; - upb_MessageValue val; + const upb_Array* paths = upb_Message_GetFieldByDef(msg, paths_f).array_val; + bool first = true; + size_t i, n = 0; - while (ptr < end) { - const char* elem_end = memchr(ptr, ',', end - ptr); - if (elem_end) { - val.str_val = jsondec_mask(d, ptr, elem_end); - ptr = elem_end + 1; - } else { - val.str_val = jsondec_mask(d, ptr, end); - ptr = end; - } - upb_Array_Append(arr, val, d->arena); - } -} + if (paths) n = upb_Array_Size(paths); -static void jsondec_anyfield(jsondec* d, upb_Message* msg, - const upb_MessageDef* m) { - if (upb_MessageDef_WellKnownType(m) == kUpb_WellKnown_Unspecified) { - /* For regular types: {"@type": "[user type]", "f1": , "f2": } - * where f1, f2, etc. are the normal fields of this type. */ - jsondec_field(d, msg, m); - } else { - /* For well-known types: {"@type": "[well-known type]", "value": } - * where is whatever encoding the WKT normally uses. */ - upb_StringView str = jsondec_string(d); - jsondec_entrysep(d); - if (!jsondec_streql(str, "value")) { - jsondec_err(d, "Key for well-known type must be 'value'"); - } - jsondec_wellknown(d, msg, m); + jsonenc_putstr(e, "\""); + + for (i = 0; i < n; i++) { + jsonenc_putsep(e, ",", &first); + jsonenc_fieldpath(e, upb_Array_Get(paths, i).str_val); } -} -static const upb_MessageDef* jsondec_typeurl(jsondec* d, upb_Message* msg, - const upb_MessageDef* m) { - const upb_FieldDef* type_url_f = upb_MessageDef_FindFieldByNumber(m, 1); - const upb_MessageDef* type_m; - upb_StringView type_url = jsondec_string(d); - const char* end = type_url.data + type_url.size; - const char* ptr = end; - upb_MessageValue val; + jsonenc_putstr(e, "\""); +} - val.str_val = type_url; - upb_Message_SetFieldByDef(msg, type_url_f, val, d->arena); +static void jsonenc_struct(jsonenc* e, const upb_Message* msg, + const upb_MessageDef* m) { + jsonenc_putstr(e, "{"); - /* Find message name after the last '/' */ - while (ptr > type_url.data && *--ptr != '/') { - } + const upb_FieldDef* fields_f = upb_MessageDef_FindFieldByNumber(m, 1); + const upb_Map* fields = upb_Message_GetFieldByDef(msg, fields_f).map_val; - if (ptr == type_url.data || ptr == end) { - jsondec_err(d, "Type url must have at least one '/' and non-empty host"); - } + if (fields) { + const upb_MessageDef* entry_m = upb_FieldDef_MessageSubDef(fields_f); + const upb_FieldDef* value_f = upb_MessageDef_FindFieldByNumber(entry_m, 2); - ptr++; - type_m = upb_DefPool_FindMessageByNameWithSize(d->symtab, ptr, end - ptr); + size_t iter = kUpb_Map_Begin; + bool first = true; - if (!type_m) { - jsondec_err(d, "Type was not found"); + upb_MessageValue key, val; + while (upb_Map_Next(fields, &key, &val, &iter)) { + jsonenc_putsep(e, ",", &first); + jsonenc_string(e, key.str_val); + jsonenc_putstr(e, ":"); + jsonenc_value(e, val.msg_val, upb_FieldDef_MessageSubDef(value_f)); + } } - return type_m; + jsonenc_putstr(e, "}"); } -static void jsondec_any(jsondec* d, upb_Message* msg, const upb_MessageDef* m) { - /* string type_url = 1; - * bytes value = 2; */ - const upb_FieldDef* value_f = upb_MessageDef_FindFieldByNumber(m, 2); - upb_Message* any_msg; - const upb_MessageDef* any_m = NULL; - const char* pre_type_data = NULL; - const char* pre_type_end = NULL; - upb_MessageValue encoded; +static void jsonenc_listvalue(jsonenc* e, const upb_Message* msg, + const upb_MessageDef* m) { + const upb_FieldDef* values_f = upb_MessageDef_FindFieldByNumber(m, 1); + const upb_MessageDef* values_m = upb_FieldDef_MessageSubDef(values_f); + const upb_Array* values = upb_Message_GetFieldByDef(msg, values_f).array_val; + size_t i; + bool first = true; - jsondec_objstart(d); + jsonenc_putstr(e, "["); - /* Scan looking for "@type", which is not necessarily first. */ - while (!any_m && jsondec_objnext(d)) { - const char* start = d->ptr; - upb_StringView name = jsondec_string(d); - jsondec_entrysep(d); - if (jsondec_streql(name, "@type")) { - any_m = jsondec_typeurl(d, msg, m); - if (pre_type_data) { - pre_type_end = start; - while (*pre_type_end != ',') pre_type_end--; - } - } else { - if (!pre_type_data) pre_type_data = start; - jsondec_skipval(d); + if (values) { + const size_t size = upb_Array_Size(values); + for (i = 0; i < size; i++) { + upb_MessageValue elem = upb_Array_Get(values, i); + + jsonenc_putsep(e, ",", &first); + jsonenc_value(e, elem.msg_val, values_m); } } - if (!any_m) { - jsondec_err(d, "Any object didn't contain a '@type' field"); - } + jsonenc_putstr(e, "]"); +} - const upb_MiniTable* any_layout = upb_MessageDef_MiniTable(any_m); - any_msg = upb_Message_New(any_layout, d->arena); +static void jsonenc_value(jsonenc* e, const upb_Message* msg, + const upb_MessageDef* m) { + /* TODO: do we want a reflection method to get oneof case? */ + size_t iter = kUpb_Message_Begin; + const upb_FieldDef* f; + upb_MessageValue val; - if (pre_type_data) { - size_t len = pre_type_end - pre_type_data + 1; - char* tmp = upb_Arena_Malloc(d->arena, len); - const char* saved_ptr = d->ptr; - const char* saved_end = d->end; - memcpy(tmp, pre_type_data, len - 1); - tmp[len - 1] = '}'; - d->ptr = tmp; - d->end = tmp + len; - d->is_first = true; - while (jsondec_objnext(d)) { - jsondec_anyfield(d, any_msg, any_m); - } - d->ptr = saved_ptr; - d->end = saved_end; + if (!upb_Message_Next(msg, m, NULL, &f, &val, &iter)) { + jsonenc_err(e, "No value set in Value proto"); } - while (jsondec_objnext(d)) { - jsondec_anyfield(d, any_msg, any_m); + switch (upb_FieldDef_Number(f)) { + case 1: + jsonenc_putstr(e, "null"); + break; + case 2: + if (upb_JsonEncode_HandleSpecialDoubles(e, val.double_val)) { + jsonenc_err( + e, + "google.protobuf.Value cannot encode double values for " + "infinity or nan, because they would be parsed as a string"); + } + upb_JsonEncode_Double(e, val.double_val); + break; + case 3: + jsonenc_string(e, val.str_val); + break; + case 4: + jsonenc_putstr(e, val.bool_val ? "true" : "false"); + break; + case 5: + jsonenc_struct(e, val.msg_val, upb_FieldDef_MessageSubDef(f)); + break; + case 6: + jsonenc_listvalue(e, val.msg_val, upb_FieldDef_MessageSubDef(f)); + break; } - - jsondec_objend(d); - - upb_EncodeStatus status = - upb_Encode(any_msg, upb_MessageDef_MiniTable(any_m), 0, d->arena, - (char**)&encoded.str_val.data, &encoded.str_val.size); - // TODO: We should fail gracefully here on a bad return status. - UPB_ASSERT(status == kUpb_EncodeStatus_Ok); - upb_Message_SetFieldByDef(msg, value_f, encoded, d->arena); } -static void jsondec_wrapper(jsondec* d, upb_Message* msg, - const upb_MessageDef* m) { - const upb_FieldDef* value_f = upb_MessageDef_FindFieldByNumber(m, 1); - upb_JsonMessageValue val = jsondec_value(d, value_f); - UPB_ASSUME(val.ignore == false); // Wrapper cannot be an enum. - upb_Message_SetFieldByDef(msg, value_f, val.value, d->arena); -} - -static void jsondec_wellknown(jsondec* d, upb_Message* msg, - const upb_MessageDef* m) { +static void jsonenc_msgfield(jsonenc* e, const upb_Message* msg, + const upb_MessageDef* m) { switch (upb_MessageDef_WellKnownType(m)) { + case kUpb_WellKnown_Unspecified: + jsonenc_msg(e, msg, m); + break; case kUpb_WellKnown_Any: - jsondec_any(d, msg, m); + jsonenc_any(e, msg, m); break; case kUpb_WellKnown_FieldMask: - jsondec_fieldmask(d, msg, m); + jsonenc_fieldmask(e, msg, m); break; case kUpb_WellKnown_Duration: - jsondec_duration(d, msg, m); + jsonenc_duration(e, msg, m); break; case kUpb_WellKnown_Timestamp: - jsondec_timestamp(d, msg, m); - break; - case kUpb_WellKnown_Value: - jsondec_wellknownvalue(d, msg, m); - break; - case kUpb_WellKnown_ListValue: - jsondec_listvalue(d, msg, m); - break; - case kUpb_WellKnown_Struct: - jsondec_struct(d, msg, m); + jsonenc_timestamp(e, msg, m); break; case kUpb_WellKnown_DoubleValue: case kUpb_WellKnown_FloatValue: @@ -4048,2319 +3820,2531 @@ static void jsondec_wellknown(jsondec* d, upb_Message* msg, case kUpb_WellKnown_StringValue: case kUpb_WellKnown_BytesValue: case kUpb_WellKnown_BoolValue: - jsondec_wrapper(d, msg, m); + jsonenc_wrapper(e, msg, m); + break; + case kUpb_WellKnown_Value: + jsonenc_value(e, msg, m); + break; + case kUpb_WellKnown_ListValue: + jsonenc_listvalue(e, msg, m); + break; + case kUpb_WellKnown_Struct: + jsonenc_struct(e, msg, m); break; - default: - UPB_UNREACHABLE(); } } -static bool upb_JsonDecoder_Decode(jsondec* const d, upb_Message* const msg, - const upb_MessageDef* const m) { - if (UPB_SETJMP(d->err)) return false; - - jsondec_tomsg(d, msg, m); - - // Consume any trailing whitespace before checking if we read the entire - // input. - jsondec_consumews(d); - - if (d->ptr == d->end) { - return true; - } else { - jsondec_seterrmsg(d, "unexpected trailing characters"); - return false; +static void jsonenc_scalar(jsonenc* e, upb_MessageValue val, + const upb_FieldDef* f) { + switch (upb_FieldDef_CType(f)) { + case kUpb_CType_Bool: + jsonenc_putstr(e, val.bool_val ? "true" : "false"); + break; + case kUpb_CType_Float: + upb_JsonEncode_Float(e, val.float_val); + break; + case kUpb_CType_Double: + upb_JsonEncode_Double(e, val.double_val); + break; + case kUpb_CType_Int32: + jsonenc_printf(e, "%" PRId32, val.int32_val); + break; + case kUpb_CType_UInt32: + jsonenc_printf(e, "%" PRIu32, val.uint32_val); + break; + case kUpb_CType_Int64: + jsonenc_printf(e, "\"%" PRId64 "\"", val.int64_val); + break; + case kUpb_CType_UInt64: + jsonenc_printf(e, "\"%" PRIu64 "\"", val.uint64_val); + break; + case kUpb_CType_String: + jsonenc_string(e, val.str_val); + break; + case kUpb_CType_Bytes: + jsonenc_bytes(e, val.str_val); + break; + case kUpb_CType_Enum: + jsonenc_enum(val.int32_val, f, e); + break; + case kUpb_CType_Message: + jsonenc_msgfield(e, val.msg_val, upb_FieldDef_MessageSubDef(f)); + break; } } -bool upb_JsonDecode(const char* buf, size_t size, upb_Message* msg, - const upb_MessageDef* m, const upb_DefPool* symtab, - int options, upb_Arena* arena, upb_Status* status) { - jsondec d; - - if (size == 0) return true; +static void jsonenc_mapkey(jsonenc* e, upb_MessageValue val, + const upb_FieldDef* f) { + jsonenc_putstr(e, "\""); - d.ptr = buf; - d.end = buf + size; - d.arena = arena; - d.symtab = symtab; - d.status = status; - d.options = options; - d.depth = 64; - d.line = 1; - d.line_begin = d.ptr; - d.debug_field = NULL; - d.is_first = false; + switch (upb_FieldDef_CType(f)) { + case kUpb_CType_Bool: + jsonenc_putstr(e, val.bool_val ? "true" : "false"); + break; + case kUpb_CType_Int32: + jsonenc_printf(e, "%" PRId32, val.int32_val); + break; + case kUpb_CType_UInt32: + jsonenc_printf(e, "%" PRIu32, val.uint32_val); + break; + case kUpb_CType_Int64: + jsonenc_printf(e, "%" PRId64, val.int64_val); + break; + case kUpb_CType_UInt64: + jsonenc_printf(e, "%" PRIu64, val.uint64_val); + break; + case kUpb_CType_String: + jsonenc_stringbody(e, val.str_val); + break; + default: + UPB_UNREACHABLE(); + } - return upb_JsonDecoder_Decode(&d, msg, m); + jsonenc_putstr(e, "\":"); } +static void jsonenc_array(jsonenc* e, const upb_Array* arr, + const upb_FieldDef* f) { + size_t i; + size_t size = arr ? upb_Array_Size(arr) : 0; + bool first = true; -#include -#include -#include -#include -#include -#include + jsonenc_putstr(e, "["); + for (i = 0; i < size; i++) { + jsonenc_putsep(e, ",", &first); + jsonenc_scalar(e, upb_Array_Get(arr, i), f); + } -// Must be last. + jsonenc_putstr(e, "]"); +} -typedef struct { - char *buf, *ptr, *end; - size_t overflow; - int indent_depth; - int options; - const upb_DefPool* ext_pool; - jmp_buf err; - upb_Status* status; - upb_Arena* arena; -} jsonenc; - -static void jsonenc_msg(jsonenc* e, const upb_Message* msg, - const upb_MessageDef* m); -static void jsonenc_scalar(jsonenc* e, upb_MessageValue val, - const upb_FieldDef* f); -static void jsonenc_msgfield(jsonenc* e, const upb_Message* msg, - const upb_MessageDef* m); -static void jsonenc_msgfields(jsonenc* e, const upb_Message* msg, - const upb_MessageDef* m, bool first); -static void jsonenc_value(jsonenc* e, const upb_Message* msg, - const upb_MessageDef* m); +static void jsonenc_map(jsonenc* e, const upb_Map* map, const upb_FieldDef* f) { + jsonenc_putstr(e, "{"); -UPB_NORETURN static void jsonenc_err(jsonenc* e, const char* msg) { - upb_Status_SetErrorMessage(e->status, msg); - longjmp(e->err, 1); -} + const upb_MessageDef* entry = upb_FieldDef_MessageSubDef(f); + const upb_FieldDef* key_f = upb_MessageDef_FindFieldByNumber(entry, 1); + const upb_FieldDef* val_f = upb_MessageDef_FindFieldByNumber(entry, 2); -UPB_PRINTF(2, 3) -UPB_NORETURN static void jsonenc_errf(jsonenc* e, const char* fmt, ...) { - va_list argp; - va_start(argp, fmt); - upb_Status_VSetErrorFormat(e->status, fmt, argp); - va_end(argp); - longjmp(e->err, 1); -} + if (map) { + size_t iter = kUpb_Map_Begin; + bool first = true; -static upb_Arena* jsonenc_arena(jsonenc* e) { - /* Create lazily, since it's only needed for Any */ - if (!e->arena) { - e->arena = upb_Arena_New(); + upb_MessageValue key, val; + while (upb_Map_Next(map, &key, &val, &iter)) { + jsonenc_putsep(e, ",", &first); + jsonenc_mapkey(e, key, key_f); + jsonenc_scalar(e, val, val_f); + } } - return e->arena; + + jsonenc_putstr(e, "}"); } -static void jsonenc_putbytes(jsonenc* e, const void* data, size_t len) { - size_t have = e->end - e->ptr; - if (UPB_LIKELY(have >= len)) { - memcpy(e->ptr, data, len); - e->ptr += len; +static void jsonenc_fieldval(jsonenc* e, const upb_FieldDef* f, + upb_MessageValue val, bool* first) { + const char* name; + + jsonenc_putsep(e, ",", first); + + if (upb_FieldDef_IsExtension(f)) { + // TODO: For MessageSet, I would have expected this to print the message + // name here, but Python doesn't appear to do this. We should do more + // research here about what various implementations do. + jsonenc_printf(e, "\"[%s]\":", upb_FieldDef_FullName(f)); } else { - if (have) { - memcpy(e->ptr, data, have); - e->ptr += have; + if (e->options & upb_JsonEncode_UseProtoNames) { + name = upb_FieldDef_Name(f); + } else { + name = upb_FieldDef_JsonName(f); } - e->overflow += (len - have); + jsonenc_printf(e, "\"%s\":", name); } -} -static void jsonenc_putstr(jsonenc* e, const char* str) { - jsonenc_putbytes(e, str, strlen(str)); + if (upb_FieldDef_IsMap(f)) { + jsonenc_map(e, val.map_val, f); + } else if (upb_FieldDef_IsRepeated(f)) { + jsonenc_array(e, val.array_val, f); + } else { + jsonenc_scalar(e, val, f); + } } -UPB_PRINTF(2, 3) -static void jsonenc_printf(jsonenc* e, const char* fmt, ...) { - size_t n; - size_t have = e->end - e->ptr; - va_list args; - - va_start(args, fmt); - n = _upb_vsnprintf(e->ptr, have, fmt, args); - va_end(args); +static void jsonenc_msgfields(jsonenc* e, const upb_Message* msg, + const upb_MessageDef* m, bool first) { + upb_MessageValue val; + const upb_FieldDef* f; - if (UPB_LIKELY(have > n)) { - e->ptr += n; + if (e->options & upb_JsonEncode_EmitDefaults) { + /* Iterate over all fields. */ + int i = 0; + int n = upb_MessageDef_FieldCount(m); + for (i = 0; i < n; i++) { + f = upb_MessageDef_Field(m, i); + if (!upb_FieldDef_HasPresence(f) || upb_Message_HasFieldByDef(msg, f)) { + jsonenc_fieldval(e, f, upb_Message_GetFieldByDef(msg, f), &first); + } + } } else { - e->ptr = UPB_PTRADD(e->ptr, have); - e->overflow += (n - have); + /* Iterate over non-empty fields. */ + size_t iter = kUpb_Message_Begin; + while (upb_Message_Next(msg, m, e->ext_pool, &f, &val, &iter)) { + jsonenc_fieldval(e, f, val, &first); + } } } -static void jsonenc_nanos(jsonenc* e, int32_t nanos) { - int digits = 9; +static void jsonenc_msg(jsonenc* e, const upb_Message* msg, + const upb_MessageDef* m) { + jsonenc_putstr(e, "{"); + jsonenc_msgfields(e, msg, m, true); + jsonenc_putstr(e, "}"); +} - if (nanos == 0) return; - if (nanos < 0 || nanos >= 1000000000) { - jsonenc_err(e, "error formatting timestamp as JSON: invalid nanos"); - } +static size_t jsonenc_nullz(jsonenc* e, size_t size) { + size_t ret = e->ptr - e->buf + e->overflow; - while (nanos % 1000 == 0) { - nanos /= 1000; - digits -= 3; + if (size > 0) { + if (e->ptr == e->end) e->ptr--; + *e->ptr = '\0'; } - jsonenc_printf(e, ".%.*" PRId32, digits, nanos); + return ret; } -static void jsonenc_timestamp(jsonenc* e, const upb_Message* msg, - const upb_MessageDef* m) { - const upb_FieldDef* seconds_f = upb_MessageDef_FindFieldByNumber(m, 1); - const upb_FieldDef* nanos_f = upb_MessageDef_FindFieldByNumber(m, 2); - int64_t seconds = upb_Message_GetFieldByDef(msg, seconds_f).int64_val; - int32_t nanos = upb_Message_GetFieldByDef(msg, nanos_f).int32_val; - int L, N, I, J, K, hour, min, sec; +static size_t upb_JsonEncoder_Encode(jsonenc* const e, + const upb_Message* const msg, + const upb_MessageDef* const m, + const size_t size) { + if (UPB_SETJMP(e->err) != 0) return -1; - if (seconds < -62135596800) { - jsonenc_err(e, - "error formatting timestamp as JSON: minimum acceptable value " - "is 0001-01-01T00:00:00Z"); - } else if (seconds > 253402300799) { - jsonenc_err(e, - "error formatting timestamp as JSON: maximum acceptable value " - "is 9999-12-31T23:59:59Z"); - } + jsonenc_msgfield(e, msg, m); + if (e->arena) upb_Arena_Free(e->arena); + return jsonenc_nullz(e, size); +} - /* Julian Day -> Y/M/D, Algorithm from: - * Fliegel, H. F., and Van Flandern, T. C., "A Machine Algorithm for - * Processing Calendar Dates," Communications of the Association of - * Computing Machines, vol. 11 (1968), p. 657. */ - seconds += 62135596800; // Ensure seconds is positive. - L = (int)(seconds / 86400) - 719162 + 68569 + 2440588; - N = 4 * L / 146097; - L = L - (146097 * N + 3) / 4; - I = 4000 * (L + 1) / 1461001; - L = L - 1461 * I / 4 + 31; - J = 80 * L / 2447; - K = L - 2447 * J / 80; - L = J / 11; - J = J + 2 - 12 * L; - I = 100 * (N - 49) + I + L; +size_t upb_JsonEncode(const upb_Message* msg, const upb_MessageDef* m, + const upb_DefPool* ext_pool, int options, char* buf, + size_t size, upb_Status* status) { + jsonenc e; - sec = seconds % 60; - min = (seconds / 60) % 60; - hour = (seconds / 3600) % 24; + e.buf = buf; + e.ptr = buf; + e.end = UPB_PTRADD(buf, size); + e.overflow = 0; + e.options = options; + e.ext_pool = ext_pool; + e.status = status; + e.arena = NULL; - jsonenc_printf(e, "\"%04d-%02d-%02dT%02d:%02d:%02d", I, J, K, hour, min, sec); - jsonenc_nanos(e, nanos); - jsonenc_putstr(e, "Z\""); + return upb_JsonEncoder_Encode(&e, msg, m, size); } -static void jsonenc_duration(jsonenc* e, const upb_Message* msg, - const upb_MessageDef* m) { - const upb_FieldDef* seconds_f = upb_MessageDef_FindFieldByNumber(m, 1); - const upb_FieldDef* nanos_f = upb_MessageDef_FindFieldByNumber(m, 2); - int64_t seconds = upb_Message_GetFieldByDef(msg, seconds_f).int64_val; - int32_t nanos = upb_Message_GetFieldByDef(msg, nanos_f).int32_val; - bool negative = false; - if (seconds > 315576000000 || seconds < -315576000000 || - (seconds != 0 && nanos != 0 && (seconds < 0) != (nanos < 0))) { - jsonenc_err(e, "bad duration"); - } +#include - if (seconds < 0) { - negative = true; - seconds = -seconds; - } - if (nanos < 0) { - negative = true; - nanos = -nanos; - } +// Must be last. - jsonenc_putstr(e, "\""); - if (negative) { - jsonenc_putstr(e, "-"); +static void* upb_global_allocfunc(upb_alloc* alloc, void* ptr, size_t oldsize, + size_t size) { + UPB_UNUSED(alloc); + UPB_UNUSED(oldsize); + if (size == 0) { + free(ptr); + return NULL; + } else { + return realloc(ptr, size); } - jsonenc_printf(e, "%" PRId64, seconds); - jsonenc_nanos(e, nanos); - jsonenc_putstr(e, "s\""); } -static void jsonenc_enum(int32_t val, const upb_FieldDef* f, jsonenc* e) { - const upb_EnumDef* e_def = upb_FieldDef_EnumSubDef(f); +upb_alloc upb_alloc_global = {&upb_global_allocfunc}; - if (strcmp(upb_EnumDef_FullName(e_def), "google.protobuf.NullValue") == 0) { - jsonenc_putstr(e, "null"); - } else { - const upb_EnumValueDef* ev = - (e->options & upb_JsonEncode_FormatEnumsAsIntegers) - ? NULL - : upb_EnumDef_FindValueByNumber(e_def, val); - if (ev) { - jsonenc_printf(e, "\"%s\"", upb_EnumValueDef_Name(ev)); - } else { - jsonenc_printf(e, "%" PRId32, val); - } - } -} +#include +#include -static void jsonenc_bytes(jsonenc* e, upb_StringView str) { - /* This is the regular base64, not the "web-safe" version. */ - static const char base64[] = - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; - const unsigned char* ptr = (unsigned char*)str.data; - const unsigned char* end = UPB_PTRADD(ptr, str.size); - char buf[4]; - jsonenc_putstr(e, "\""); +// Must be last. - while (end - ptr >= 3) { - buf[0] = base64[ptr[0] >> 2]; - buf[1] = base64[((ptr[0] & 0x3) << 4) | (ptr[1] >> 4)]; - buf[2] = base64[((ptr[1] & 0xf) << 2) | (ptr[2] >> 6)]; - buf[3] = base64[ptr[2] & 0x3f]; - jsonenc_putbytes(e, buf, 4); - ptr += 3; - } +typedef struct upb_MemBlock { + // Atomic only for the benefit of SpaceAllocated(). + UPB_ATOMIC(struct upb_MemBlock*) next; + uint32_t size; + // Data follows. +} upb_MemBlock; - switch (end - ptr) { - case 2: - buf[0] = base64[ptr[0] >> 2]; - buf[1] = base64[((ptr[0] & 0x3) << 4) | (ptr[1] >> 4)]; - buf[2] = base64[(ptr[1] & 0xf) << 2]; - buf[3] = '='; - jsonenc_putbytes(e, buf, 4); - break; - case 1: - buf[0] = base64[ptr[0] >> 2]; - buf[1] = base64[((ptr[0] & 0x3) << 4)]; - buf[2] = '='; - buf[3] = '='; - jsonenc_putbytes(e, buf, 4); - break; - } +typedef struct upb_ArenaInternal { + // upb_alloc* together with a low bit which signals if there is an initial + // block. + uintptr_t block_alloc; - jsonenc_putstr(e, "\""); + // When multiple arenas are fused together, each arena points to a parent + // arena (root points to itself). The root tracks how many live arenas + // reference it. + + // The low bit is tagged: + // 0: pointer to parent + // 1: count, left shifted by one + UPB_ATOMIC(uintptr_t) parent_or_count; + + // All nodes that are fused together are in a singly-linked list. + // == NULL at end of list. + UPB_ATOMIC(struct upb_ArenaInternal*) next; + + // The last element of the linked list. This is present only as an + // optimization, so that we do not have to iterate over all members for every + // fuse. Only significant for an arena root. In other cases it is ignored. + // == self when no other list members. + UPB_ATOMIC(struct upb_ArenaInternal*) tail; + + // Linked list of blocks to free/cleanup. Atomic only for the benefit of + // upb_Arena_SpaceAllocated(). + UPB_ATOMIC(upb_MemBlock*) blocks; +} upb_ArenaInternal; + +// All public + private state for an arena. +typedef struct { + upb_Arena head; + upb_ArenaInternal body; +} upb_ArenaState; + +typedef struct { + upb_ArenaInternal* root; + uintptr_t tagged_count; +} upb_ArenaRoot; + +static const size_t kUpb_MemblockReserve = + UPB_ALIGN_UP(sizeof(upb_MemBlock), UPB_MALLOC_ALIGN); + +// Extracts the (upb_ArenaInternal*) from a (upb_Arena*) +static upb_ArenaInternal* upb_Arena_Internal(const upb_Arena* a) { + return &((upb_ArenaState*)a)->body; } -static void jsonenc_stringbody(jsonenc* e, upb_StringView str) { - const char* ptr = str.data; - const char* end = UPB_PTRADD(ptr, str.size); +static bool _upb_Arena_IsTaggedRefcount(uintptr_t parent_or_count) { + return (parent_or_count & 1) == 1; +} - while (ptr < end) { - switch (*ptr) { - case '\n': - jsonenc_putstr(e, "\\n"); - break; - case '\r': - jsonenc_putstr(e, "\\r"); - break; - case '\t': - jsonenc_putstr(e, "\\t"); - break; - case '\"': - jsonenc_putstr(e, "\\\""); - break; - case '\f': - jsonenc_putstr(e, "\\f"); - break; - case '\b': - jsonenc_putstr(e, "\\b"); - break; - case '\\': - jsonenc_putstr(e, "\\\\"); - break; - default: - if ((uint8_t)*ptr < 0x20) { - jsonenc_printf(e, "\\u%04x", (int)(uint8_t)*ptr); - } else { - /* This could be a non-ASCII byte. We rely on the string being valid - * UTF-8. */ - jsonenc_putbytes(e, ptr, 1); - } - break; - } - ptr++; - } +static bool _upb_Arena_IsTaggedPointer(uintptr_t parent_or_count) { + return (parent_or_count & 1) == 0; } -static void jsonenc_string(jsonenc* e, upb_StringView str) { - jsonenc_putstr(e, "\""); - jsonenc_stringbody(e, str); - jsonenc_putstr(e, "\""); +static uintptr_t _upb_Arena_RefCountFromTagged(uintptr_t parent_or_count) { + UPB_ASSERT(_upb_Arena_IsTaggedRefcount(parent_or_count)); + return parent_or_count >> 1; } -static bool upb_JsonEncode_HandleSpecialDoubles(jsonenc* e, double val) { - if (val == INFINITY) { - jsonenc_putstr(e, "\"Infinity\""); - } else if (val == -INFINITY) { - jsonenc_putstr(e, "\"-Infinity\""); - } else if (val != val) { - jsonenc_putstr(e, "\"NaN\""); - } else { - return false; - } - return true; +static uintptr_t _upb_Arena_TaggedFromRefcount(uintptr_t refcount) { + uintptr_t parent_or_count = (refcount << 1) | 1; + UPB_ASSERT(_upb_Arena_IsTaggedRefcount(parent_or_count)); + return parent_or_count; } -static void upb_JsonEncode_Double(jsonenc* e, double val) { - if (upb_JsonEncode_HandleSpecialDoubles(e, val)) return; - char buf[32]; - _upb_EncodeRoundTripDouble(val, buf, sizeof(buf)); - jsonenc_putstr(e, buf); +static upb_ArenaInternal* _upb_Arena_PointerFromTagged( + uintptr_t parent_or_count) { + UPB_ASSERT(_upb_Arena_IsTaggedPointer(parent_or_count)); + return (upb_ArenaInternal*)parent_or_count; } -static void upb_JsonEncode_Float(jsonenc* e, float val) { - if (upb_JsonEncode_HandleSpecialDoubles(e, val)) return; - char buf[32]; - _upb_EncodeRoundTripFloat(val, buf, sizeof(buf)); - jsonenc_putstr(e, buf); +static uintptr_t _upb_Arena_TaggedFromPointer(upb_ArenaInternal* ai) { + uintptr_t parent_or_count = (uintptr_t)ai; + UPB_ASSERT(_upb_Arena_IsTaggedPointer(parent_or_count)); + return parent_or_count; } -static void jsonenc_wrapper(jsonenc* e, const upb_Message* msg, - const upb_MessageDef* m) { - const upb_FieldDef* val_f = upb_MessageDef_FindFieldByNumber(m, 1); - upb_MessageValue val = upb_Message_GetFieldByDef(msg, val_f); - jsonenc_scalar(e, val, val_f); +static upb_alloc* _upb_ArenaInternal_BlockAlloc(upb_ArenaInternal* ai) { + return (upb_alloc*)(ai->block_alloc & ~0x1); } -static const upb_MessageDef* jsonenc_getanymsg(jsonenc* e, - upb_StringView type_url) { - /* Find last '/', if any. */ - const char* end = type_url.data + type_url.size; - const char* ptr = end; - const upb_MessageDef* ret; +static uintptr_t _upb_Arena_MakeBlockAlloc(upb_alloc* alloc, bool has_initial) { + uintptr_t alloc_uint = (uintptr_t)alloc; + UPB_ASSERT((alloc_uint & 1) == 0); + return alloc_uint | (has_initial ? 1 : 0); +} - if (!e->ext_pool) { - jsonenc_err(e, "Tried to encode Any, but no symtab was provided"); - } +static bool _upb_ArenaInternal_HasInitialBlock(upb_ArenaInternal* ai) { + return ai->block_alloc & 0x1; +} - if (type_url.size == 0) goto badurl; +static upb_ArenaRoot _upb_Arena_FindRoot(upb_Arena* a) { + upb_ArenaInternal* ai = upb_Arena_Internal(a); + uintptr_t poc = upb_Atomic_Load(&ai->parent_or_count, memory_order_acquire); + while (_upb_Arena_IsTaggedPointer(poc)) { + upb_ArenaInternal* next = _upb_Arena_PointerFromTagged(poc); + UPB_ASSERT(ai != next); + uintptr_t next_poc = + upb_Atomic_Load(&next->parent_or_count, memory_order_acquire); - while (true) { - if (--ptr == type_url.data) { - /* Type URL must contain at least one '/', with host before. */ - goto badurl; - } - if (*ptr == '/') { - ptr++; - break; + if (_upb_Arena_IsTaggedPointer(next_poc)) { + // To keep complexity down, we lazily collapse levels of the tree. This + // keeps it flat in the final case, but doesn't cost much incrementally. + // + // Path splitting keeps time complexity down, see: + // https://en.wikipedia.org/wiki/Disjoint-set_data_structure + // + // We can safely use a relaxed atomic here because all threads doing this + // will converge on the same value and we don't need memory orderings to + // be visible. + // + // This is true because: + // - If no fuses occur, this will eventually become the root. + // - If fuses are actively occurring, the root may change, but the + // invariant is that `parent_or_count` merely points to *a* parent. + // + // In other words, it is moving towards "the" root, and that root may move + // further away over time, but the path towards that root will continue to + // be valid and the creation of the path carries all the memory orderings + // required. + UPB_ASSERT(ai != _upb_Arena_PointerFromTagged(next_poc)); + upb_Atomic_Store(&ai->parent_or_count, next_poc, memory_order_relaxed); } + ai = next; + poc = next_poc; } + return (upb_ArenaRoot){.root = ai, .tagged_count = poc}; +} - ret = upb_DefPool_FindMessageByNameWithSize(e->ext_pool, ptr, end - ptr); +size_t upb_Arena_SpaceAllocated(upb_Arena* arena) { + upb_ArenaInternal* ai = _upb_Arena_FindRoot(arena).root; + size_t memsize = 0; - if (!ret) { - jsonenc_errf(e, "Couldn't find Any type: %.*s", (int)(end - ptr), ptr); + while (ai != NULL) { + upb_MemBlock* block = upb_Atomic_Load(&ai->blocks, memory_order_relaxed); + while (block != NULL) { + memsize += sizeof(upb_MemBlock) + block->size; + block = upb_Atomic_Load(&block->next, memory_order_relaxed); + } + ai = upb_Atomic_Load(&ai->next, memory_order_relaxed); } - return ret; - -badurl: - jsonenc_errf(e, "Bad type URL: " UPB_STRINGVIEW_FORMAT, - UPB_STRINGVIEW_ARGS(type_url)); + return memsize; } -static void jsonenc_any(jsonenc* e, const upb_Message* msg, - const upb_MessageDef* m) { - const upb_FieldDef* type_url_f = upb_MessageDef_FindFieldByNumber(m, 1); - const upb_FieldDef* value_f = upb_MessageDef_FindFieldByNumber(m, 2); - upb_StringView type_url = upb_Message_GetFieldByDef(msg, type_url_f).str_val; - upb_StringView value = upb_Message_GetFieldByDef(msg, value_f).str_val; - const upb_MessageDef* any_m = jsonenc_getanymsg(e, type_url); - const upb_MiniTable* any_layout = upb_MessageDef_MiniTable(any_m); - upb_Arena* arena = jsonenc_arena(e); - upb_Message* any = upb_Message_New(any_layout, arena); - - if (upb_Decode(value.data, value.size, any, any_layout, NULL, 0, arena) != - kUpb_DecodeStatus_Ok) { - jsonenc_err(e, "Error decoding message in Any"); +uint32_t upb_Arena_DebugRefCount(upb_Arena* a) { + upb_ArenaInternal* ai = upb_Arena_Internal(a); + // These loads could probably be relaxed, but given that this is debug-only, + // it's not worth introducing a new variant for it. + uintptr_t poc = upb_Atomic_Load(&ai->parent_or_count, memory_order_acquire); + while (_upb_Arena_IsTaggedPointer(poc)) { + ai = _upb_Arena_PointerFromTagged(poc); + poc = upb_Atomic_Load(&ai->parent_or_count, memory_order_acquire); } + return _upb_Arena_RefCountFromTagged(poc); +} - jsonenc_putstr(e, "{\"@type\":"); - jsonenc_string(e, type_url); +static void _upb_Arena_AddBlock(upb_Arena* a, void* ptr, size_t size) { + upb_ArenaInternal* ai = upb_Arena_Internal(a); + upb_MemBlock* block = ptr; - if (upb_MessageDef_WellKnownType(any_m) == kUpb_WellKnown_Unspecified) { - /* Regular messages: {"@type": "...","foo": 1, "bar": 2} */ - jsonenc_msgfields(e, any, any_m, false); - } else { - /* Well-known type: {"@type": "...","value": } */ - jsonenc_putstr(e, ",\"value\":"); - jsonenc_msgfield(e, any, any_m); - } + // Insert into linked list. + block->size = (uint32_t)size; + upb_Atomic_Init(&block->next, ai->blocks); + upb_Atomic_Store(&ai->blocks, block, memory_order_release); - jsonenc_putstr(e, "}"); -} + a->UPB_PRIVATE(ptr) = UPB_PTR_AT(block, kUpb_MemblockReserve, char); + a->UPB_PRIVATE(end) = UPB_PTR_AT(block, size, char); -static void jsonenc_putsep(jsonenc* e, const char* str, bool* first) { - if (*first) { - *first = false; - } else { - jsonenc_putstr(e, str); - } + UPB_POISON_MEMORY_REGION(a->UPB_PRIVATE(ptr), + a->UPB_PRIVATE(end) - a->UPB_PRIVATE(ptr)); } -static void jsonenc_fieldpath(jsonenc* e, upb_StringView path) { - const char* ptr = path.data; - const char* end = ptr + path.size; - - while (ptr < end) { - char ch = *ptr; +static bool _upb_Arena_AllocBlock(upb_Arena* a, size_t size) { + upb_ArenaInternal* ai = upb_Arena_Internal(a); + if (!ai->block_alloc) return false; + upb_MemBlock* last_block = upb_Atomic_Load(&ai->blocks, memory_order_acquire); + size_t last_size = last_block != NULL ? last_block->size : 128; + size_t block_size = UPB_MAX(size, last_size * 2) + kUpb_MemblockReserve; + upb_MemBlock* block = + upb_malloc(_upb_ArenaInternal_BlockAlloc(ai), block_size); - if (ch >= 'A' && ch <= 'Z') { - jsonenc_err(e, "Field mask element may not have upper-case letter."); - } else if (ch == '_') { - if (ptr == end - 1 || *(ptr + 1) < 'a' || *(ptr + 1) > 'z') { - jsonenc_err(e, "Underscore must be followed by a lowercase letter."); - } - ch = *++ptr - 32; - } + if (!block) return false; + _upb_Arena_AddBlock(a, block, block_size); + UPB_ASSERT(UPB_PRIVATE(_upb_ArenaHas)(a) >= size); + return true; +} - jsonenc_putbytes(e, &ch, 1); - ptr++; - } +void* UPB_PRIVATE(_upb_Arena_SlowMalloc)(upb_Arena* a, size_t size) { + if (!_upb_Arena_AllocBlock(a, size)) return NULL; // OOM + return upb_Arena_Malloc(a, size - UPB_ASAN_GUARD_SIZE); } -static void jsonenc_fieldmask(jsonenc* e, const upb_Message* msg, - const upb_MessageDef* m) { - const upb_FieldDef* paths_f = upb_MessageDef_FindFieldByNumber(m, 1); - const upb_Array* paths = upb_Message_GetFieldByDef(msg, paths_f).array_val; - bool first = true; - size_t i, n = 0; +static upb_Arena* _upb_Arena_InitSlow(upb_alloc* alloc) { + const size_t first_block_overhead = + sizeof(upb_ArenaState) + kUpb_MemblockReserve; + upb_ArenaState* a; - if (paths) n = upb_Array_Size(paths); + // We need to malloc the initial block. + char* mem; + size_t n = first_block_overhead + 256; + if (!alloc || !(mem = upb_malloc(alloc, n))) { + return NULL; + } - jsonenc_putstr(e, "\""); + a = UPB_PTR_AT(mem, n - sizeof(upb_ArenaState), upb_ArenaState); + n -= sizeof(upb_ArenaState); - for (i = 0; i < n; i++) { - jsonenc_putsep(e, ",", &first); - jsonenc_fieldpath(e, upb_Array_Get(paths, i).str_val); - } + a->body.block_alloc = _upb_Arena_MakeBlockAlloc(alloc, 0); + upb_Atomic_Init(&a->body.parent_or_count, _upb_Arena_TaggedFromRefcount(1)); + upb_Atomic_Init(&a->body.next, NULL); + upb_Atomic_Init(&a->body.tail, &a->body); + upb_Atomic_Init(&a->body.blocks, NULL); - jsonenc_putstr(e, "\""); -} + _upb_Arena_AddBlock(&a->head, mem, n); -static void jsonenc_struct(jsonenc* e, const upb_Message* msg, - const upb_MessageDef* m) { - jsonenc_putstr(e, "{"); + return &a->head; +} - const upb_FieldDef* fields_f = upb_MessageDef_FindFieldByNumber(m, 1); - const upb_Map* fields = upb_Message_GetFieldByDef(msg, fields_f).map_val; +upb_Arena* upb_Arena_Init(void* mem, size_t n, upb_alloc* alloc) { + UPB_ASSERT(sizeof(void*) * UPB_ARENA_SIZE_HACK >= sizeof(upb_ArenaState)); + upb_ArenaState* a; - if (fields) { - const upb_MessageDef* entry_m = upb_FieldDef_MessageSubDef(fields_f); - const upb_FieldDef* value_f = upb_MessageDef_FindFieldByNumber(entry_m, 2); + if (n) { + /* Align initial pointer up so that we return properly-aligned pointers. */ + void* aligned = (void*)UPB_ALIGN_UP((uintptr_t)mem, UPB_MALLOC_ALIGN); + size_t delta = (uintptr_t)aligned - (uintptr_t)mem; + n = delta <= n ? n - delta : 0; + mem = aligned; + } - size_t iter = kUpb_Map_Begin; - bool first = true; + /* Round block size down to alignof(*a) since we will allocate the arena + * itself at the end. */ + n = UPB_ALIGN_DOWN(n, UPB_ALIGN_OF(upb_ArenaState)); - upb_MessageValue key, val; - while (upb_Map_Next(fields, &key, &val, &iter)) { - jsonenc_putsep(e, ",", &first); - jsonenc_string(e, key.str_val); - jsonenc_putstr(e, ":"); - jsonenc_value(e, val.msg_val, upb_FieldDef_MessageSubDef(value_f)); - } + if (UPB_UNLIKELY(n < sizeof(upb_ArenaState))) { + return _upb_Arena_InitSlow(alloc); } - jsonenc_putstr(e, "}"); -} + a = UPB_PTR_AT(mem, n - sizeof(upb_ArenaState), upb_ArenaState); -static void jsonenc_listvalue(jsonenc* e, const upb_Message* msg, - const upb_MessageDef* m) { - const upb_FieldDef* values_f = upb_MessageDef_FindFieldByNumber(m, 1); - const upb_MessageDef* values_m = upb_FieldDef_MessageSubDef(values_f); - const upb_Array* values = upb_Message_GetFieldByDef(msg, values_f).array_val; - size_t i; - bool first = true; + upb_Atomic_Init(&a->body.parent_or_count, _upb_Arena_TaggedFromRefcount(1)); + upb_Atomic_Init(&a->body.next, NULL); + upb_Atomic_Init(&a->body.tail, &a->body); + upb_Atomic_Init(&a->body.blocks, NULL); - jsonenc_putstr(e, "["); + a->body.block_alloc = _upb_Arena_MakeBlockAlloc(alloc, 1); + a->head.UPB_PRIVATE(ptr) = mem; + a->head.UPB_PRIVATE(end) = UPB_PTR_AT(mem, n - sizeof(upb_ArenaState), char); - if (values) { - const size_t size = upb_Array_Size(values); - for (i = 0; i < size; i++) { - upb_MessageValue elem = upb_Array_Get(values, i); + return &a->head; +} - jsonenc_putsep(e, ",", &first); - jsonenc_value(e, elem.msg_val, values_m); +static void _upb_Arena_DoFree(upb_ArenaInternal* ai) { + UPB_ASSERT(_upb_Arena_RefCountFromTagged(ai->parent_or_count) == 1); + + while (ai != NULL) { + // Load first since arena itself is likely from one of its blocks. + upb_ArenaInternal* next_arena = + (upb_ArenaInternal*)upb_Atomic_Load(&ai->next, memory_order_acquire); + upb_alloc* block_alloc = _upb_ArenaInternal_BlockAlloc(ai); + upb_MemBlock* block = upb_Atomic_Load(&ai->blocks, memory_order_acquire); + while (block != NULL) { + // Load first since we are deleting block. + upb_MemBlock* next_block = + upb_Atomic_Load(&block->next, memory_order_acquire); + upb_free(block_alloc, block); + block = next_block; } + ai = next_arena; } - - jsonenc_putstr(e, "]"); } -static void jsonenc_value(jsonenc* e, const upb_Message* msg, - const upb_MessageDef* m) { - /* TODO: do we want a reflection method to get oneof case? */ - size_t iter = kUpb_Message_Begin; - const upb_FieldDef* f; - upb_MessageValue val; +void upb_Arena_Free(upb_Arena* a) { + upb_ArenaInternal* ai = upb_Arena_Internal(a); + uintptr_t poc = upb_Atomic_Load(&ai->parent_or_count, memory_order_acquire); +retry: + while (_upb_Arena_IsTaggedPointer(poc)) { + ai = _upb_Arena_PointerFromTagged(poc); + poc = upb_Atomic_Load(&ai->parent_or_count, memory_order_acquire); + } - if (!upb_Message_Next(msg, m, NULL, &f, &val, &iter)) { - jsonenc_err(e, "No value set in Value proto"); + // compare_exchange or fetch_sub are RMW operations, which are more + // expensive then direct loads. As an optimization, we only do RMW ops + // when we need to update things for other threads to see. + if (poc == _upb_Arena_TaggedFromRefcount(1)) { + _upb_Arena_DoFree(ai); + return; } - switch (upb_FieldDef_Number(f)) { - case 1: - jsonenc_putstr(e, "null"); - break; - case 2: - if (upb_JsonEncode_HandleSpecialDoubles(e, val.double_val)) { - jsonenc_err( - e, - "google.protobuf.Value cannot encode double values for " - "infinity or nan, because they would be parsed as a string"); - } - upb_JsonEncode_Double(e, val.double_val); - break; - case 3: - jsonenc_string(e, val.str_val); - break; - case 4: - jsonenc_putstr(e, val.bool_val ? "true" : "false"); - break; - case 5: - jsonenc_struct(e, val.msg_val, upb_FieldDef_MessageSubDef(f)); - break; - case 6: - jsonenc_listvalue(e, val.msg_val, upb_FieldDef_MessageSubDef(f)); - break; + if (upb_Atomic_CompareExchangeWeak( + &ai->parent_or_count, &poc, + _upb_Arena_TaggedFromRefcount(_upb_Arena_RefCountFromTagged(poc) - 1), + memory_order_release, memory_order_acquire)) { + // We were >1 and we decremented it successfully, so we are done. + return; } + + // We failed our update, so someone has done something, retry the whole + // process, but the failed exchange reloaded `poc` for us. + goto retry; } -static void jsonenc_msgfield(jsonenc* e, const upb_Message* msg, - const upb_MessageDef* m) { - switch (upb_MessageDef_WellKnownType(m)) { - case kUpb_WellKnown_Unspecified: - jsonenc_msg(e, msg, m); - break; - case kUpb_WellKnown_Any: - jsonenc_any(e, msg, m); - break; - case kUpb_WellKnown_FieldMask: - jsonenc_fieldmask(e, msg, m); - break; - case kUpb_WellKnown_Duration: - jsonenc_duration(e, msg, m); - break; - case kUpb_WellKnown_Timestamp: - jsonenc_timestamp(e, msg, m); - break; - case kUpb_WellKnown_DoubleValue: - case kUpb_WellKnown_FloatValue: - case kUpb_WellKnown_Int64Value: - case kUpb_WellKnown_UInt64Value: - case kUpb_WellKnown_Int32Value: - case kUpb_WellKnown_UInt32Value: - case kUpb_WellKnown_StringValue: - case kUpb_WellKnown_BytesValue: - case kUpb_WellKnown_BoolValue: - jsonenc_wrapper(e, msg, m); - break; - case kUpb_WellKnown_Value: - jsonenc_value(e, msg, m); - break; - case kUpb_WellKnown_ListValue: - jsonenc_listvalue(e, msg, m); - break; - case kUpb_WellKnown_Struct: - jsonenc_struct(e, msg, m); - break; - } -} +static void _upb_Arena_DoFuseArenaLists(upb_ArenaInternal* const parent, + upb_ArenaInternal* child) { + upb_ArenaInternal* parent_tail = + upb_Atomic_Load(&parent->tail, memory_order_relaxed); -static void jsonenc_scalar(jsonenc* e, upb_MessageValue val, - const upb_FieldDef* f) { - switch (upb_FieldDef_CType(f)) { - case kUpb_CType_Bool: - jsonenc_putstr(e, val.bool_val ? "true" : "false"); - break; - case kUpb_CType_Float: - upb_JsonEncode_Float(e, val.float_val); - break; - case kUpb_CType_Double: - upb_JsonEncode_Double(e, val.double_val); - break; - case kUpb_CType_Int32: - jsonenc_printf(e, "%" PRId32, val.int32_val); - break; - case kUpb_CType_UInt32: - jsonenc_printf(e, "%" PRIu32, val.uint32_val); - break; - case kUpb_CType_Int64: - jsonenc_printf(e, "\"%" PRId64 "\"", val.int64_val); - break; - case kUpb_CType_UInt64: - jsonenc_printf(e, "\"%" PRIu64 "\"", val.uint64_val); - break; - case kUpb_CType_String: - jsonenc_string(e, val.str_val); - break; - case kUpb_CType_Bytes: - jsonenc_bytes(e, val.str_val); - break; - case kUpb_CType_Enum: - jsonenc_enum(val.int32_val, f, e); - break; - case kUpb_CType_Message: - jsonenc_msgfield(e, val.msg_val, upb_FieldDef_MessageSubDef(f)); - break; - } -} + do { + // Our tail might be stale, but it will always converge to the true tail. + upb_ArenaInternal* parent_tail_next = + upb_Atomic_Load(&parent_tail->next, memory_order_relaxed); + while (parent_tail_next != NULL) { + parent_tail = parent_tail_next; + parent_tail_next = + upb_Atomic_Load(&parent_tail->next, memory_order_relaxed); + } -static void jsonenc_mapkey(jsonenc* e, upb_MessageValue val, - const upb_FieldDef* f) { - jsonenc_putstr(e, "\""); + upb_ArenaInternal* displaced = + upb_Atomic_Exchange(&parent_tail->next, child, memory_order_relaxed); + parent_tail = upb_Atomic_Load(&child->tail, memory_order_relaxed); - switch (upb_FieldDef_CType(f)) { - case kUpb_CType_Bool: - jsonenc_putstr(e, val.bool_val ? "true" : "false"); - break; - case kUpb_CType_Int32: - jsonenc_printf(e, "%" PRId32, val.int32_val); - break; - case kUpb_CType_UInt32: - jsonenc_printf(e, "%" PRIu32, val.uint32_val); - break; - case kUpb_CType_Int64: - jsonenc_printf(e, "%" PRId64, val.int64_val); - break; - case kUpb_CType_UInt64: - jsonenc_printf(e, "%" PRIu64, val.uint64_val); - break; - case kUpb_CType_String: - jsonenc_stringbody(e, val.str_val); - break; - default: - UPB_UNREACHABLE(); - } + // If we displaced something that got installed racily, we can simply + // reinstall it on our new tail. + child = displaced; + } while (child != NULL); - jsonenc_putstr(e, "\":"); + upb_Atomic_Store(&parent->tail, parent_tail, memory_order_relaxed); } -static void jsonenc_array(jsonenc* e, const upb_Array* arr, - const upb_FieldDef* f) { - size_t i; - size_t size = arr ? upb_Array_Size(arr) : 0; - bool first = true; +static upb_ArenaInternal* _upb_Arena_DoFuse(upb_Arena* a1, upb_Arena* a2, + uintptr_t* ref_delta) { + // `parent_or_count` has two disctint modes + // - parent pointer mode + // - refcount mode + // + // In parent pointer mode, it may change what pointer it refers to in the + // tree, but it will always approach a root. Any operation that walks the + // tree to the root may collapse levels of the tree concurrently. + upb_ArenaRoot r1 = _upb_Arena_FindRoot(a1); + upb_ArenaRoot r2 = _upb_Arena_FindRoot(a2); - jsonenc_putstr(e, "["); + if (r1.root == r2.root) return r1.root; // Already fused. - for (i = 0; i < size; i++) { - jsonenc_putsep(e, ",", &first); - jsonenc_scalar(e, upb_Array_Get(arr, i), f); + // Avoid cycles by always fusing into the root with the lower address. + if ((uintptr_t)r1.root > (uintptr_t)r2.root) { + upb_ArenaRoot tmp = r1; + r1 = r2; + r2 = tmp; } - jsonenc_putstr(e, "]"); -} - -static void jsonenc_map(jsonenc* e, const upb_Map* map, const upb_FieldDef* f) { - jsonenc_putstr(e, "{"); - - const upb_MessageDef* entry = upb_FieldDef_MessageSubDef(f); - const upb_FieldDef* key_f = upb_MessageDef_FindFieldByNumber(entry, 1); - const upb_FieldDef* val_f = upb_MessageDef_FindFieldByNumber(entry, 2); - - if (map) { - size_t iter = kUpb_Map_Begin; - bool first = true; + // The moment we install `r1` as the parent for `r2` all racing frees may + // immediately begin decrementing `r1`'s refcount (including pending + // increments to that refcount and their frees!). We need to add `r2`'s refs + // now, so that `r1` can withstand any unrefs that come from r2. + // + // Note that while it is possible for `r2`'s refcount to increase + // asynchronously, we will not actually do the reparenting operation below + // unless `r2`'s refcount is unchanged from when we read it. + // + // Note that we may have done this previously, either to this node or a + // different node, during a previous and failed DoFuse() attempt. But we will + // not lose track of these refs because we always add them to our overall + // delta. + uintptr_t r2_untagged_count = r2.tagged_count & ~1; + uintptr_t with_r2_refs = r1.tagged_count + r2_untagged_count; + if (!upb_Atomic_CompareExchangeStrong( + &r1.root->parent_or_count, &r1.tagged_count, with_r2_refs, + memory_order_release, memory_order_acquire)) { + return NULL; + } - upb_MessageValue key, val; - while (upb_Map_Next(map, &key, &val, &iter)) { - jsonenc_putsep(e, ",", &first); - jsonenc_mapkey(e, key, key_f); - jsonenc_scalar(e, val, val_f); - } + // Perform the actual fuse by removing the refs from `r2` and swapping in the + // parent pointer. + if (!upb_Atomic_CompareExchangeStrong( + &r2.root->parent_or_count, &r2.tagged_count, + _upb_Arena_TaggedFromPointer(r1.root), memory_order_release, + memory_order_acquire)) { + // We'll need to remove the excess refs we added to r1 previously. + *ref_delta += r2_untagged_count; + return NULL; } - jsonenc_putstr(e, "}"); + // Now that the fuse has been performed (and can no longer fail) we need to + // append `r2` to `r1`'s linked list. + _upb_Arena_DoFuseArenaLists(r1.root, r2.root); + return r1.root; } -static void jsonenc_fieldval(jsonenc* e, const upb_FieldDef* f, - upb_MessageValue val, bool* first) { - const char* name; +static bool _upb_Arena_FixupRefs(upb_ArenaInternal* new_root, + uintptr_t ref_delta) { + if (ref_delta == 0) return true; // No fixup required. + uintptr_t poc = + upb_Atomic_Load(&new_root->parent_or_count, memory_order_relaxed); + if (_upb_Arena_IsTaggedPointer(poc)) return false; + uintptr_t with_refs = poc - ref_delta; + UPB_ASSERT(!_upb_Arena_IsTaggedPointer(with_refs)); + return upb_Atomic_CompareExchangeStrong(&new_root->parent_or_count, &poc, + with_refs, memory_order_relaxed, + memory_order_relaxed); +} - jsonenc_putsep(e, ",", first); +bool upb_Arena_Fuse(upb_Arena* a1, upb_Arena* a2) { + if (a1 == a2) return true; // trivial fuse - if (upb_FieldDef_IsExtension(f)) { - // TODO: For MessageSet, I would have expected this to print the message - // name here, but Python doesn't appear to do this. We should do more - // research here about what various implementations do. - jsonenc_printf(e, "\"[%s]\":", upb_FieldDef_FullName(f)); - } else { - if (e->options & upb_JsonEncode_UseProtoNames) { - name = upb_FieldDef_Name(f); - } else { - name = upb_FieldDef_JsonName(f); - } - jsonenc_printf(e, "\"%s\":", name); + upb_ArenaInternal* ai1 = upb_Arena_Internal(a1); + upb_ArenaInternal* ai2 = upb_Arena_Internal(a2); + + // Do not fuse initial blocks since we cannot lifetime extend them. + // Any other fuse scenario is allowed. + if (_upb_ArenaInternal_HasInitialBlock(ai1) || + _upb_ArenaInternal_HasInitialBlock(ai2)) { + return false; } - if (upb_FieldDef_IsMap(f)) { - jsonenc_map(e, val.map_val, f); - } else if (upb_FieldDef_IsRepeated(f)) { - jsonenc_array(e, val.array_val, f); - } else { - jsonenc_scalar(e, val, f); + // The number of refs we ultimately need to transfer to the new root. + uintptr_t ref_delta = 0; + while (true) { + upb_ArenaInternal* new_root = _upb_Arena_DoFuse(a1, a2, &ref_delta); + if (new_root != NULL && _upb_Arena_FixupRefs(new_root, ref_delta)) { + return true; + } } } -static void jsonenc_msgfields(jsonenc* e, const upb_Message* msg, - const upb_MessageDef* m, bool first) { - upb_MessageValue val; - const upb_FieldDef* f; - - if (e->options & upb_JsonEncode_EmitDefaults) { - /* Iterate over all fields. */ - int i = 0; - int n = upb_MessageDef_FieldCount(m); - for (i = 0; i < n; i++) { - f = upb_MessageDef_Field(m, i); - if (!upb_FieldDef_HasPresence(f) || upb_Message_HasFieldByDef(msg, f)) { - jsonenc_fieldval(e, f, upb_Message_GetFieldByDef(msg, f), &first); - } - } - } else { - /* Iterate over non-empty fields. */ - size_t iter = kUpb_Message_Begin; - while (upb_Message_Next(msg, m, e->ext_pool, &f, &val, &iter)) { - jsonenc_fieldval(e, f, val, &first); - } - } -} +bool upb_Arena_IncRefFor(upb_Arena* a, const void* owner) { + upb_ArenaInternal* ai = upb_Arena_Internal(a); + if (_upb_ArenaInternal_HasInitialBlock(ai)) return false; + upb_ArenaRoot r; -static void jsonenc_msg(jsonenc* e, const upb_Message* msg, - const upb_MessageDef* m) { - jsonenc_putstr(e, "{"); - jsonenc_msgfields(e, msg, m, true); - jsonenc_putstr(e, "}"); +retry: + r = _upb_Arena_FindRoot(a); + if (upb_Atomic_CompareExchangeWeak( + &r.root->parent_or_count, &r.tagged_count, + _upb_Arena_TaggedFromRefcount( + _upb_Arena_RefCountFromTagged(r.tagged_count) + 1), + memory_order_release, memory_order_acquire)) { + // We incremented it successfully, so we are done. + return true; + } + // We failed update due to parent switching on the arena. + goto retry; } -static size_t jsonenc_nullz(jsonenc* e, size_t size) { - size_t ret = e->ptr - e->buf + e->overflow; +void upb_Arena_DecRefFor(upb_Arena* a, const void* owner) { upb_Arena_Free(a); } - if (size > 0) { - if (e->ptr == e->end) e->ptr--; - *e->ptr = '\0'; - } +void UPB_PRIVATE(_upb_Arena_SwapIn)(upb_Arena* des, const upb_Arena* src) { + upb_ArenaInternal* desi = upb_Arena_Internal(des); + upb_ArenaInternal* srci = upb_Arena_Internal(src); - return ret; + *des = *src; + desi->block_alloc = srci->block_alloc; + upb_MemBlock* blocks = upb_Atomic_Load(&srci->blocks, memory_order_relaxed); + upb_Atomic_Init(&desi->blocks, blocks); } -static size_t upb_JsonEncoder_Encode(jsonenc* const e, - const upb_Message* const msg, - const upb_MessageDef* const m, - const size_t size) { - if (UPB_SETJMP(e->err) != 0) return -1; +void UPB_PRIVATE(_upb_Arena_SwapOut)(upb_Arena* des, const upb_Arena* src) { + upb_ArenaInternal* desi = upb_Arena_Internal(des); + upb_ArenaInternal* srci = upb_Arena_Internal(src); - jsonenc_msgfield(e, msg, m); - if (e->arena) upb_Arena_Free(e->arena); - return jsonenc_nullz(e, size); + *des = *src; + upb_MemBlock* blocks = upb_Atomic_Load(&srci->blocks, memory_order_relaxed); + upb_Atomic_Store(&desi->blocks, blocks, memory_order_relaxed); } -size_t upb_JsonEncode(const upb_Message* msg, const upb_MessageDef* m, - const upb_DefPool* ext_pool, int options, char* buf, - size_t size, upb_Status* status) { - jsonenc e; - - e.buf = buf; - e.ptr = buf; - e.end = UPB_PTRADD(buf, size); - e.overflow = 0; - e.options = options; - e.ext_pool = ext_pool; - e.status = status; - e.arena = NULL; - return upb_JsonEncoder_Encode(&e, msg, m, size); -} +#include +#include // Must be last. -const char* upb_BufToUint64(const char* ptr, const char* end, uint64_t* val) { - uint64_t u64 = 0; - while (ptr < end) { - unsigned ch = *ptr - '0'; - if (ch >= 10) break; - if (u64 > UINT64_MAX / 10 || u64 * 10 > UINT64_MAX - ch) { - return NULL; // integer overflow - } - u64 *= 10; - u64 += ch; - ptr++; - } - - *val = u64; - return ptr; +upb_Array* upb_Array_New(upb_Arena* a, upb_CType type) { + const int lg2 = UPB_PRIVATE(_upb_CType_SizeLg2)(type); + return UPB_PRIVATE(_upb_Array_New)(a, 4, lg2); } -const char* upb_BufToInt64(const char* ptr, const char* end, int64_t* val, - bool* is_neg) { - bool neg = false; - uint64_t u64; +const void* upb_Array_DataPtr(const upb_Array* arr) { + return _upb_array_ptr((upb_Array*)arr); +} - if (ptr != end && *ptr == '-') { - ptr++; - neg = true; - } +void* upb_Array_MutableDataPtr(upb_Array* arr) { return _upb_array_ptr(arr); } - ptr = upb_BufToUint64(ptr, end, &u64); - if (!ptr || u64 > (uint64_t)INT64_MAX + neg) { - return NULL; // integer overflow - } +size_t upb_Array_Size(const upb_Array* arr) { return arr->UPB_PRIVATE(size); } - *val = neg ? -u64 : u64; - if (is_neg) *is_neg = neg; - return ptr; +upb_MessageValue upb_Array_Get(const upb_Array* arr, size_t i) { + upb_MessageValue ret; + const char* data = _upb_array_constptr(arr); + const int lg2 = UPB_PRIVATE(_upb_Array_ElemSizeLg2)(arr); + UPB_ASSERT(i < arr->UPB_PRIVATE(size)); + memcpy(&ret, data + (i << lg2), 1 << lg2); + return ret; } +void upb_Array_Set(upb_Array* arr, size_t i, upb_MessageValue val) { + char* data = _upb_array_ptr(arr); + const int lg2 = UPB_PRIVATE(_upb_Array_ElemSizeLg2)(arr); + UPB_ASSERT(i < arr->UPB_PRIVATE(size)); + memcpy(data + (i << lg2), &val, 1 << lg2); +} -#include -#include - -// Must be last. +bool upb_Array_Append(upb_Array* arr, upb_MessageValue val, upb_Arena* arena) { + UPB_ASSERT(arena); + if (!_upb_Array_ResizeUninitialized(arr, arr->UPB_PRIVATE(size) + 1, arena)) { + return false; + } + upb_Array_Set(arr, arr->UPB_PRIVATE(size) - 1, val); + return true; +} -/* Miscellaneous utilities ****************************************************/ +void upb_Array_Move(upb_Array* arr, size_t dst_idx, size_t src_idx, + size_t count) { + const int lg2 = UPB_PRIVATE(_upb_Array_ElemSizeLg2)(arr); + char* data = _upb_array_ptr(arr); + memmove(&data[dst_idx << lg2], &data[src_idx << lg2], count << lg2); +} -static void upb_FixLocale(char* p) { - /* printf() is dependent on locales; sadly there is no easy and portable way - * to avoid this. This little post-processing step will translate 1,2 -> 1.2 - * since JSON needs the latter. Arguably a hack, but it is simple and the - * alternatives are far more complicated, platform-dependent, and/or larger - * in code size. */ - for (; *p; p++) { - if (*p == ',') *p = '.'; +bool upb_Array_Insert(upb_Array* arr, size_t i, size_t count, + upb_Arena* arena) { + UPB_ASSERT(arena); + UPB_ASSERT(i <= arr->UPB_PRIVATE(size)); + UPB_ASSERT(count + arr->UPB_PRIVATE(size) >= count); + const size_t oldsize = arr->UPB_PRIVATE(size); + if (!_upb_Array_ResizeUninitialized(arr, arr->UPB_PRIVATE(size) + count, + arena)) { + return false; } + upb_Array_Move(arr, i + count, i, oldsize - i); + return true; } -void _upb_EncodeRoundTripDouble(double val, char* buf, size_t size) { - assert(size >= kUpb_RoundTripBufferSize); - snprintf(buf, size, "%.*g", DBL_DIG, val); - if (strtod(buf, NULL) != val) { - snprintf(buf, size, "%.*g", DBL_DIG + 2, val); - assert(strtod(buf, NULL) == val); - } - upb_FixLocale(buf); +/* + * i end arr->size + * |------------|XXXXXXXX|--------| + */ +void upb_Array_Delete(upb_Array* arr, size_t i, size_t count) { + const size_t end = i + count; + UPB_ASSERT(i <= end); + UPB_ASSERT(end <= arr->UPB_PRIVATE(size)); + upb_Array_Move(arr, i, end, arr->UPB_PRIVATE(size) - end); + arr->UPB_PRIVATE(size) -= count; } -void _upb_EncodeRoundTripFloat(float val, char* buf, size_t size) { - assert(size >= kUpb_RoundTripBufferSize); - snprintf(buf, size, "%.*g", FLT_DIG, val); - if (strtof(buf, NULL) != val) { - snprintf(buf, size, "%.*g", FLT_DIG + 3, val); - assert(strtof(buf, NULL) == val); +bool upb_Array_Resize(upb_Array* arr, size_t size, upb_Arena* arena) { + const size_t oldsize = arr->UPB_PRIVATE(size); + if (UPB_UNLIKELY(!_upb_Array_ResizeUninitialized(arr, size, arena))) { + return false; } - upb_FixLocale(buf); + const size_t newsize = arr->UPB_PRIVATE(size); + if (newsize > oldsize) { + const int lg2 = UPB_PRIVATE(_upb_Array_ElemSizeLg2)(arr); + char* data = _upb_array_ptr(arr); + memset(data + (oldsize << lg2), 0, (newsize - oldsize) << lg2); + } + return true; } +bool UPB_PRIVATE(_upb_Array_Realloc)(upb_Array* array, size_t min_capacity, + upb_Arena* arena) { + size_t new_capacity = UPB_MAX(array->UPB_PRIVATE(capacity), 4); + const int lg2 = UPB_PRIVATE(_upb_Array_ElemSizeLg2)(array); + size_t old_bytes = array->UPB_PRIVATE(capacity) << lg2; + void* ptr = _upb_array_ptr(array); -#include -#include - -// Must be last. + // Log2 ceiling of size. + while (new_capacity < min_capacity) new_capacity *= 2; -// Determine the locale-specific radix character by calling sprintf() to print -// the number 1.5, then stripping off the digits. As far as I can tell, this -// is the only portable, thread-safe way to get the C library to divulge the -// locale's radix character. No, localeconv() is NOT thread-safe. + const size_t new_bytes = new_capacity << lg2; + ptr = upb_Arena_Realloc(arena, ptr, old_bytes, new_bytes); + if (!ptr) return false; -static int GetLocaleRadix(char *data, size_t capacity) { - char temp[16]; - const int size = snprintf(temp, sizeof(temp), "%.1f", 1.5); - UPB_ASSERT(temp[0] == '1'); - UPB_ASSERT(temp[size - 1] == '5'); - UPB_ASSERT(size < capacity); - temp[size - 1] = '\0'; - strcpy(data, temp + 1); - return size - 2; + UPB_PRIVATE(_upb_Array_SetTaggedPtr)(array, ptr, lg2); + array->UPB_PRIVATE(capacity) = new_capacity; + return true; } -// Populates a string identical to *input except that the character pointed to -// by pos (which should be '.') is replaced with the locale-specific radix. -static void LocalizeRadix(const char *input, const char *pos, char *output) { - const int len1 = pos - input; +#include +#include - char radix[8]; - const int len2 = GetLocaleRadix(radix, sizeof(radix)); - memcpy(output, input, len1); - memcpy(output + len1, radix, len2); - strcpy(output + len1 + len2, input + len1 + 1); -} +// Must be last. -double _upb_NoLocaleStrtod(const char *str, char **endptr) { - // We cannot simply set the locale to "C" temporarily with setlocale() - // as this is not thread-safe. Instead, we try to parse in the current - // locale first. If parsing stops at a '.' character, then this is a - // pretty good hint that we're actually in some other locale in which - // '.' is not the radix character. +const upb_Extension* upb_Message_ExtensionByIndex(const upb_Message* msg, + size_t index) { + size_t count; + const upb_Extension* ext = UPB_PRIVATE(_upb_Message_Getexts)(msg, &count); - char *temp_endptr; - double result = strtod(str, &temp_endptr); - if (endptr != NULL) *endptr = temp_endptr; - if (*temp_endptr != '.') return result; + UPB_ASSERT(index < count); + return &ext[index]; +} - // Parsing halted on a '.'. Perhaps we're in a different locale? Let's - // try to replace the '.' with a locale-specific radix character and - // try again. +const upb_Extension* upb_Message_FindExtensionByNumber(const upb_Message* msg, + uint32_t field_number) { + size_t count; + const upb_Extension* ext = UPB_PRIVATE(_upb_Message_Getexts)(msg, &count); - char localized[80]; - LocalizeRadix(str, temp_endptr, localized); - char *localized_endptr; - result = strtod(localized, &localized_endptr); - if ((localized_endptr - &localized[0]) > (temp_endptr - str)) { - // This attempt got further, so replacing the decimal must have helped. - // Update endptr to point at the right location. - if (endptr != NULL) { - // size_diff is non-zero if the localized radix has multiple bytes. - int size_diff = strlen(localized) - strlen(str); - *endptr = (char *)str + (localized_endptr - &localized[0] - size_diff); - } + while (count--) { + if (upb_MiniTableExtension_Number(ext->ext) == field_number) return ext; + ext++; } - - return result; + return NULL; } +#include + + // Must be last. -int upb_Unicode_ToUTF8(uint32_t cp, char* out) { - if (cp <= 0x7f) { - out[0] = cp; - return 1; - } - if (cp <= 0x07ff) { - out[0] = (cp >> 6) | 0xc0; - out[1] = (cp & 0x3f) | 0x80; - return 2; - } - if (cp <= 0xffff) { - out[0] = (cp >> 12) | 0xe0; - out[1] = ((cp >> 6) & 0x3f) | 0x80; - out[2] = (cp & 0x3f) | 0x80; - return 3; - } - if (cp <= 0x10ffff) { - out[0] = (cp >> 18) | 0xf0; - out[1] = ((cp >> 12) & 0x3f) | 0x80; - out[2] = ((cp >> 6) & 0x3f) | 0x80; - out[3] = (cp & 0x3f) | 0x80; - return 4; - } - return 0; +// Strings/bytes are special-cased in maps. +char _upb_Map_CTypeSizeTable[12] = { + [kUpb_CType_Bool] = 1, + [kUpb_CType_Float] = 4, + [kUpb_CType_Int32] = 4, + [kUpb_CType_UInt32] = 4, + [kUpb_CType_Enum] = 4, + [kUpb_CType_Message] = sizeof(void*), + [kUpb_CType_Double] = 8, + [kUpb_CType_Int64] = 8, + [kUpb_CType_UInt64] = 8, + [kUpb_CType_String] = UPB_MAPTYPE_STRING, + [kUpb_CType_Bytes] = UPB_MAPTYPE_STRING, +}; + +upb_Map* upb_Map_New(upb_Arena* a, upb_CType key_type, upb_CType value_type) { + return _upb_Map_New(a, _upb_Map_CTypeSize(key_type), + _upb_Map_CTypeSize(value_type)); } +size_t upb_Map_Size(const upb_Map* map) { return _upb_Map_Size(map); } -#include +bool upb_Map_Get(const upb_Map* map, upb_MessageValue key, + upb_MessageValue* val) { + return _upb_Map_Get(map, &key, map->key_size, val, map->val_size); +} -// Must be last. +void upb_Map_Clear(upb_Map* map) { _upb_Map_Clear(map); } -static void* upb_global_allocfunc(upb_alloc* alloc, void* ptr, size_t oldsize, - size_t size) { - UPB_UNUSED(alloc); - UPB_UNUSED(oldsize); - if (size == 0) { - free(ptr); - return NULL; - } else { - return realloc(ptr, size); - } +upb_MapInsertStatus upb_Map_Insert(upb_Map* map, upb_MessageValue key, + upb_MessageValue val, upb_Arena* arena) { + UPB_ASSERT(arena); + return (upb_MapInsertStatus)_upb_Map_Insert(map, &key, map->key_size, &val, + map->val_size, arena); } -upb_alloc upb_alloc_global = {&upb_global_allocfunc}; +bool upb_Map_Delete(upb_Map* map, upb_MessageValue key, upb_MessageValue* val) { + upb_value v; + const bool removed = _upb_Map_Delete(map, &key, map->key_size, &v); + if (val) _upb_map_fromvalue(v, val, map->val_size); + return removed; +} +bool upb_Map_Next(const upb_Map* map, upb_MessageValue* key, + upb_MessageValue* val, size_t* iter) { + upb_StringView k; + upb_value v; + const bool ok = upb_strtable_next2(&map->table, &k, &v, (intptr_t*)iter); + if (ok) { + _upb_map_fromkey(k, key, map->key_size); + _upb_map_fromvalue(v, val, map->val_size); + } + return ok; +} -#include -#include +UPB_API void upb_Map_SetEntryValue(upb_Map* map, size_t iter, + upb_MessageValue val) { + upb_value v; + _upb_map_tovalue(&val, map->val_size, &v, NULL); + upb_strtable_setentryvalue(&map->table, iter, v); +} +bool upb_MapIterator_Next(const upb_Map* map, size_t* iter) { + return _upb_map_next(map, iter); +} -// Must be last. +bool upb_MapIterator_Done(const upb_Map* map, size_t iter) { + upb_strtable_iter i; + UPB_ASSERT(iter != kUpb_Map_Begin); + i.t = &map->table; + i.index = iter; + return upb_strtable_done(&i); +} -typedef struct upb_MemBlock { - // Atomic only for the benefit of SpaceAllocated(). - UPB_ATOMIC(struct upb_MemBlock*) next; - uint32_t size; - // Data follows. -} upb_MemBlock; +// Returns the key and value for this entry of the map. +upb_MessageValue upb_MapIterator_Key(const upb_Map* map, size_t iter) { + upb_strtable_iter i; + upb_MessageValue ret; + i.t = &map->table; + i.index = iter; + _upb_map_fromkey(upb_strtable_iter_key(&i), &ret, map->key_size); + return ret; +} -typedef struct upb_ArenaInternal { - // upb_alloc* together with a low bit which signals if there is an initial - // block. - uintptr_t block_alloc; +upb_MessageValue upb_MapIterator_Value(const upb_Map* map, size_t iter) { + upb_strtable_iter i; + upb_MessageValue ret; + i.t = &map->table; + i.index = iter; + _upb_map_fromvalue(upb_strtable_iter_value(&i), &ret, map->val_size); + return ret; +} - // When multiple arenas are fused together, each arena points to a parent - // arena (root points to itself). The root tracks how many live arenas - // reference it. +// EVERYTHING BELOW THIS LINE IS INTERNAL - DO NOT USE ///////////////////////// - // The low bit is tagged: - // 0: pointer to parent - // 1: count, left shifted by one - UPB_ATOMIC(uintptr_t) parent_or_count; +upb_Map* _upb_Map_New(upb_Arena* a, size_t key_size, size_t value_size) { + upb_Map* map = upb_Arena_Malloc(a, sizeof(upb_Map)); + if (!map) return NULL; - // All nodes that are fused together are in a singly-linked list. - // == NULL at end of list. - UPB_ATOMIC(struct upb_ArenaInternal*) next; + upb_strtable_init(&map->table, 4, a); + map->key_size = key_size; + map->val_size = value_size; - // The last element of the linked list. This is present only as an - // optimization, so that we do not have to iterate over all members for every - // fuse. Only significant for an arena root. In other cases it is ignored. - // == self when no other list members. - UPB_ATOMIC(struct upb_ArenaInternal*) tail; + return map; +} - // Linked list of blocks to free/cleanup. Atomic only for the benefit of - // upb_Arena_SpaceAllocated(). - UPB_ATOMIC(upb_MemBlock*) blocks; -} upb_ArenaInternal; -// All public + private state for an arena. -typedef struct { - upb_Arena head; - upb_ArenaInternal body; -} upb_ArenaState; +#include +#include -typedef struct { - upb_ArenaInternal* root; - uintptr_t tagged_count; -} upb_ArenaRoot; -static const size_t kUpb_MemblockReserve = - UPB_ALIGN_UP(sizeof(upb_MemBlock), UPB_MALLOC_ALIGN); +// Must be last. -// Extracts the (upb_ArenaInternal*) from a (upb_Arena*) -static upb_ArenaInternal* upb_Arena_Internal(const upb_Arena* a) { - return &((upb_ArenaState*)a)->body; +static void _upb_mapsorter_getkeys(const void* _a, const void* _b, void* a_key, + void* b_key, size_t size) { + const upb_tabent* const* a = _a; + const upb_tabent* const* b = _b; + upb_StringView a_tabkey = upb_tabstrview((*a)->key); + upb_StringView b_tabkey = upb_tabstrview((*b)->key); + _upb_map_fromkey(a_tabkey, a_key, size); + _upb_map_fromkey(b_tabkey, b_key, size); } -static bool _upb_Arena_IsTaggedRefcount(uintptr_t parent_or_count) { - return (parent_or_count & 1) == 1; +static int _upb_mapsorter_cmpi64(const void* _a, const void* _b) { + int64_t a, b; + _upb_mapsorter_getkeys(_a, _b, &a, &b, 8); + return a < b ? -1 : a > b; } -static bool _upb_Arena_IsTaggedPointer(uintptr_t parent_or_count) { - return (parent_or_count & 1) == 0; +static int _upb_mapsorter_cmpu64(const void* _a, const void* _b) { + uint64_t a, b; + _upb_mapsorter_getkeys(_a, _b, &a, &b, 8); + return a < b ? -1 : a > b; } -static uintptr_t _upb_Arena_RefCountFromTagged(uintptr_t parent_or_count) { - UPB_ASSERT(_upb_Arena_IsTaggedRefcount(parent_or_count)); - return parent_or_count >> 1; +static int _upb_mapsorter_cmpi32(const void* _a, const void* _b) { + int32_t a, b; + _upb_mapsorter_getkeys(_a, _b, &a, &b, 4); + return a < b ? -1 : a > b; } -static uintptr_t _upb_Arena_TaggedFromRefcount(uintptr_t refcount) { - uintptr_t parent_or_count = (refcount << 1) | 1; - UPB_ASSERT(_upb_Arena_IsTaggedRefcount(parent_or_count)); - return parent_or_count; +static int _upb_mapsorter_cmpu32(const void* _a, const void* _b) { + uint32_t a, b; + _upb_mapsorter_getkeys(_a, _b, &a, &b, 4); + return a < b ? -1 : a > b; } -static upb_ArenaInternal* _upb_Arena_PointerFromTagged( - uintptr_t parent_or_count) { - UPB_ASSERT(_upb_Arena_IsTaggedPointer(parent_or_count)); - return (upb_ArenaInternal*)parent_or_count; -} - -static uintptr_t _upb_Arena_TaggedFromPointer(upb_ArenaInternal* ai) { - uintptr_t parent_or_count = (uintptr_t)ai; - UPB_ASSERT(_upb_Arena_IsTaggedPointer(parent_or_count)); - return parent_or_count; +static int _upb_mapsorter_cmpbool(const void* _a, const void* _b) { + bool a, b; + _upb_mapsorter_getkeys(_a, _b, &a, &b, 1); + return a < b ? -1 : a > b; } -static upb_alloc* _upb_ArenaInternal_BlockAlloc(upb_ArenaInternal* ai) { - return (upb_alloc*)(ai->block_alloc & ~0x1); +static int _upb_mapsorter_cmpstr(const void* _a, const void* _b) { + upb_StringView a, b; + _upb_mapsorter_getkeys(_a, _b, &a, &b, UPB_MAPTYPE_STRING); + size_t common_size = UPB_MIN(a.size, b.size); + int cmp = memcmp(a.data, b.data, common_size); + if (cmp) return -cmp; + return a.size < b.size ? -1 : a.size > b.size; } -static uintptr_t _upb_Arena_MakeBlockAlloc(upb_alloc* alloc, bool has_initial) { - uintptr_t alloc_uint = (uintptr_t)alloc; - UPB_ASSERT((alloc_uint & 1) == 0); - return alloc_uint | (has_initial ? 1 : 0); -} +static int (*const compar[kUpb_FieldType_SizeOf])(const void*, const void*) = { + [kUpb_FieldType_Int64] = _upb_mapsorter_cmpi64, + [kUpb_FieldType_SFixed64] = _upb_mapsorter_cmpi64, + [kUpb_FieldType_SInt64] = _upb_mapsorter_cmpi64, -static bool _upb_ArenaInternal_HasInitialBlock(upb_ArenaInternal* ai) { - return ai->block_alloc & 0x1; -} + [kUpb_FieldType_UInt64] = _upb_mapsorter_cmpu64, + [kUpb_FieldType_Fixed64] = _upb_mapsorter_cmpu64, -static upb_ArenaRoot _upb_Arena_FindRoot(upb_Arena* a) { - upb_ArenaInternal* ai = upb_Arena_Internal(a); - uintptr_t poc = upb_Atomic_Load(&ai->parent_or_count, memory_order_acquire); - while (_upb_Arena_IsTaggedPointer(poc)) { - upb_ArenaInternal* next = _upb_Arena_PointerFromTagged(poc); - UPB_ASSERT(ai != next); - uintptr_t next_poc = - upb_Atomic_Load(&next->parent_or_count, memory_order_acquire); + [kUpb_FieldType_Int32] = _upb_mapsorter_cmpi32, + [kUpb_FieldType_SInt32] = _upb_mapsorter_cmpi32, + [kUpb_FieldType_SFixed32] = _upb_mapsorter_cmpi32, + [kUpb_FieldType_Enum] = _upb_mapsorter_cmpi32, - if (_upb_Arena_IsTaggedPointer(next_poc)) { - // To keep complexity down, we lazily collapse levels of the tree. This - // keeps it flat in the final case, but doesn't cost much incrementally. - // - // Path splitting keeps time complexity down, see: - // https://en.wikipedia.org/wiki/Disjoint-set_data_structure - // - // We can safely use a relaxed atomic here because all threads doing this - // will converge on the same value and we don't need memory orderings to - // be visible. - // - // This is true because: - // - If no fuses occur, this will eventually become the root. - // - If fuses are actively occurring, the root may change, but the - // invariant is that `parent_or_count` merely points to *a* parent. - // - // In other words, it is moving towards "the" root, and that root may move - // further away over time, but the path towards that root will continue to - // be valid and the creation of the path carries all the memory orderings - // required. - UPB_ASSERT(ai != _upb_Arena_PointerFromTagged(next_poc)); - upb_Atomic_Store(&ai->parent_or_count, next_poc, memory_order_relaxed); - } - ai = next; - poc = next_poc; + [kUpb_FieldType_UInt32] = _upb_mapsorter_cmpu32, + [kUpb_FieldType_Fixed32] = _upb_mapsorter_cmpu32, + + [kUpb_FieldType_Bool] = _upb_mapsorter_cmpbool, + + [kUpb_FieldType_String] = _upb_mapsorter_cmpstr, + [kUpb_FieldType_Bytes] = _upb_mapsorter_cmpstr, +}; + +static bool _upb_mapsorter_resize(_upb_mapsorter* s, _upb_sortedmap* sorted, + int size) { + sorted->start = s->size; + sorted->pos = sorted->start; + sorted->end = sorted->start + size; + + if (sorted->end > s->cap) { + const int oldsize = s->cap * sizeof(*s->entries); + s->cap = upb_Log2CeilingSize(sorted->end); + const int newsize = s->cap * sizeof(*s->entries); + s->entries = upb_grealloc(s->entries, oldsize, newsize); + if (!s->entries) return false; } - return (upb_ArenaRoot){.root = ai, .tagged_count = poc}; + + s->size = sorted->end; + return true; } -size_t upb_Arena_SpaceAllocated(upb_Arena* arena) { - upb_ArenaInternal* ai = _upb_Arena_FindRoot(arena).root; - size_t memsize = 0; +bool _upb_mapsorter_pushmap(_upb_mapsorter* s, upb_FieldType key_type, + const upb_Map* map, _upb_sortedmap* sorted) { + int map_size = _upb_Map_Size(map); - while (ai != NULL) { - upb_MemBlock* block = upb_Atomic_Load(&ai->blocks, memory_order_relaxed); - while (block != NULL) { - memsize += sizeof(upb_MemBlock) + block->size; - block = upb_Atomic_Load(&block->next, memory_order_relaxed); + if (!_upb_mapsorter_resize(s, sorted, map_size)) return false; + + // Copy non-empty entries from the table to s->entries. + const void** dst = &s->entries[sorted->start]; + const upb_tabent* src = map->table.t.entries; + const upb_tabent* end = src + upb_table_size(&map->table.t); + for (; src < end; src++) { + if (!upb_tabent_isempty(src)) { + *dst = src; + dst++; } - ai = upb_Atomic_Load(&ai->next, memory_order_relaxed); } + UPB_ASSERT(dst == &s->entries[sorted->end]); - return memsize; + // Sort entries according to the key type. + qsort(&s->entries[sorted->start], map_size, sizeof(*s->entries), + compar[key_type]); + return true; } -uint32_t upb_Arena_DebugRefCount(upb_Arena* a) { - upb_ArenaInternal* ai = upb_Arena_Internal(a); - // These loads could probably be relaxed, but given that this is debug-only, - // it's not worth introducing a new variant for it. - uintptr_t poc = upb_Atomic_Load(&ai->parent_or_count, memory_order_acquire); - while (_upb_Arena_IsTaggedPointer(poc)) { - ai = _upb_Arena_PointerFromTagged(poc); - poc = upb_Atomic_Load(&ai->parent_or_count, memory_order_acquire); +static int _upb_mapsorter_cmpext(const void* _a, const void* _b) { + const upb_Extension* const* a = _a; + const upb_Extension* const* b = _b; + uint32_t a_num = upb_MiniTableExtension_Number((*a)->ext); + uint32_t b_num = upb_MiniTableExtension_Number((*b)->ext); + assert(a_num != b_num); + return a_num < b_num ? -1 : 1; +} + +bool _upb_mapsorter_pushexts(_upb_mapsorter* s, const upb_Extension* exts, + size_t count, _upb_sortedmap* sorted) { + if (!_upb_mapsorter_resize(s, sorted, count)) return false; + + for (size_t i = 0; i < count; i++) { + s->entries[sorted->start + i] = &exts[i]; } - return _upb_Arena_RefCountFromTagged(poc); + + qsort(&s->entries[sorted->start], count, sizeof(*s->entries), + _upb_mapsorter_cmpext); + return true; } -static void _upb_Arena_AddBlock(upb_Arena* a, void* ptr, size_t size) { - upb_ArenaInternal* ai = upb_Arena_Internal(a); - upb_MemBlock* block = ptr; - // Insert into linked list. - block->size = (uint32_t)size; - upb_Atomic_Init(&block->next, ai->blocks); - upb_Atomic_Store(&ai->blocks, block, memory_order_release); +#include +#include +#include - a->UPB_PRIVATE(ptr) = UPB_PTR_AT(block, kUpb_MemblockReserve, char); - a->UPB_PRIVATE(end) = UPB_PTR_AT(block, size, char); - UPB_POISON_MEMORY_REGION(a->UPB_PRIVATE(ptr), - a->UPB_PRIVATE(end) - a->UPB_PRIVATE(ptr)); -} +// Must be last. -static bool _upb_Arena_AllocBlock(upb_Arena* a, size_t size) { - upb_ArenaInternal* ai = upb_Arena_Internal(a); - if (!ai->block_alloc) return false; - upb_MemBlock* last_block = upb_Atomic_Load(&ai->blocks, memory_order_acquire); - size_t last_size = last_block != NULL ? last_block->size : 128; - size_t block_size = UPB_MAX(size, last_size * 2) + kUpb_MemblockReserve; - upb_MemBlock* block = - upb_malloc(_upb_ArenaInternal_BlockAlloc(ai), block_size); +static const size_t message_overhead = sizeof(upb_Message_InternalData); - if (!block) return false; - _upb_Arena_AddBlock(a, block, block_size); - UPB_ASSERT(UPB_PRIVATE(_upb_ArenaHas)(a) >= size); - return true; +upb_Message* upb_Message_New(const upb_MiniTable* m, upb_Arena* a) { + return _upb_Message_New(m, a); } -void* UPB_PRIVATE(_upb_Arena_SlowMalloc)(upb_Arena* a, size_t size) { - if (!_upb_Arena_AllocBlock(a, size)) return NULL; // OOM - return upb_Arena_Malloc(a, size - UPB_ASAN_GUARD_SIZE); +bool UPB_PRIVATE(_upb_Message_AddUnknown)(upb_Message* msg, const char* data, + size_t len, upb_Arena* arena) { + if (!UPB_PRIVATE(_upb_Message_Realloc)(msg, len, arena)) return false; + upb_Message_Internal* owner = upb_Message_Getinternal(msg); + upb_Message_InternalData* in = owner->internal; + memcpy(UPB_PTR_AT(in, in->unknown_end, char), data, len); + in->unknown_end += len; + return true; } -static upb_Arena* _upb_Arena_InitSlow(upb_alloc* alloc) { - const size_t first_block_overhead = - sizeof(upb_ArenaState) + kUpb_MemblockReserve; - upb_ArenaState* a; +void _upb_Message_DiscardUnknown_shallow(upb_Message* msg) { + upb_Message_Internal* owner = upb_Message_Getinternal(msg); + upb_Message_InternalData* in = owner->internal; + if (in) { + in->unknown_end = message_overhead; + } +} - // We need to malloc the initial block. - char* mem; - size_t n = first_block_overhead + 256; - if (!alloc || !(mem = upb_malloc(alloc, n))) { +const char* upb_Message_GetUnknown(const upb_Message* msg, size_t* len) { + upb_Message_Internal* owner = upb_Message_Getinternal(msg); + upb_Message_InternalData* in = owner->internal; + if (in) { + *len = in->unknown_end - message_overhead; + return (char*)(in + 1); + } else { + *len = 0; return NULL; } +} - a = UPB_PTR_AT(mem, n - sizeof(upb_ArenaState), upb_ArenaState); - n -= sizeof(upb_ArenaState); +void upb_Message_DeleteUnknown(upb_Message* msg, const char* data, size_t len) { + upb_Message_Internal* owner = upb_Message_Getinternal(msg); + upb_Message_InternalData* in = owner->internal; + const char* internal_unknown_end = UPB_PTR_AT(in, in->unknown_end, char); - a->body.block_alloc = _upb_Arena_MakeBlockAlloc(alloc, 0); - upb_Atomic_Init(&a->body.parent_or_count, _upb_Arena_TaggedFromRefcount(1)); - upb_Atomic_Init(&a->body.next, NULL); - upb_Atomic_Init(&a->body.tail, &a->body); - upb_Atomic_Init(&a->body.blocks, NULL); +#ifndef NDEBUG + size_t full_unknown_size; + const char* full_unknown = upb_Message_GetUnknown(msg, &full_unknown_size); + UPB_ASSERT((uintptr_t)data >= (uintptr_t)full_unknown); + UPB_ASSERT((uintptr_t)data < (uintptr_t)(full_unknown + full_unknown_size)); + UPB_ASSERT((uintptr_t)(data + len) > (uintptr_t)data); + UPB_ASSERT((uintptr_t)(data + len) <= (uintptr_t)internal_unknown_end); +#endif - _upb_Arena_AddBlock(&a->head, mem, n); + if ((data + len) != internal_unknown_end) { + memmove((char*)data, data + len, internal_unknown_end - data - len); + } + in->unknown_end -= len; +} - return &a->head; +size_t upb_Message_ExtensionCount(const upb_Message* msg) { + size_t count; + UPB_PRIVATE(_upb_Message_Getexts)(msg, &count); + return count; } -upb_Arena* upb_Arena_Init(void* mem, size_t n, upb_alloc* alloc) { - UPB_ASSERT(sizeof(void*) * UPB_ARENA_SIZE_HACK >= sizeof(upb_ArenaState)); - upb_ArenaState* a; - if (n) { - /* Align initial pointer up so that we return properly-aligned pointers. */ - void* aligned = (void*)UPB_ALIGN_UP((uintptr_t)mem, UPB_MALLOC_ALIGN); - size_t delta = (uintptr_t)aligned - (uintptr_t)mem; - n = delta <= n ? n - delta : 0; - mem = aligned; - } +#include - /* Round block size down to alignof(*a) since we will allocate the arena - * itself at the end. */ - n = UPB_ALIGN_DOWN(n, UPB_ALIGN_OF(upb_ArenaState)); - if (UPB_UNLIKELY(n < sizeof(upb_ArenaState))) { - return _upb_Arena_InitSlow(alloc); - } +// Must be last. - a = UPB_PTR_AT(mem, n - sizeof(upb_ArenaState), upb_ArenaState); +bool upb_Message_SetMapEntry(upb_Map* map, const upb_MiniTable* mini_table, + const upb_MiniTableField* f, + upb_Message* map_entry_message, upb_Arena* arena) { + // TODO: use a variant of upb_MiniTable_GetSubMessageTable() here. + const upb_MiniTable* map_entry_mini_table = upb_MiniTableSub_Message( + mini_table->UPB_PRIVATE(subs)[f->UPB_PRIVATE(submsg_index)]); + UPB_ASSERT(map_entry_mini_table); + UPB_ASSERT(map_entry_mini_table->UPB_PRIVATE(field_count) == 2); + const upb_MiniTableField* map_entry_key_field = + &map_entry_mini_table->UPB_PRIVATE(fields)[0]; + const upb_MiniTableField* map_entry_value_field = + &map_entry_mini_table->UPB_PRIVATE(fields)[1]; + // Map key/value cannot have explicit defaults, + // hence assuming a zero default is valid. + upb_MessageValue default_val; + memset(&default_val, 0, sizeof(upb_MessageValue)); + upb_MessageValue map_entry_key = + upb_Message_GetField(map_entry_message, map_entry_key_field, default_val); + upb_MessageValue map_entry_value = upb_Message_GetField( + map_entry_message, map_entry_value_field, default_val); + return upb_Map_Set(map, map_entry_key, map_entry_value, arena); +} - upb_Atomic_Init(&a->body.parent_or_count, _upb_Arena_TaggedFromRefcount(1)); - upb_Atomic_Init(&a->body.next, NULL); - upb_Atomic_Init(&a->body.tail, &a->body); - upb_Atomic_Init(&a->body.blocks, NULL); - a->body.block_alloc = _upb_Arena_MakeBlockAlloc(alloc, 1); - a->head.UPB_PRIVATE(ptr) = mem; - a->head.UPB_PRIVATE(end) = UPB_PTR_AT(mem, n - sizeof(upb_ArenaState), char); +#include - return &a->head; -} -static void _upb_Arena_DoFree(upb_ArenaInternal* ai) { - UPB_ASSERT(_upb_Arena_RefCountFromTagged(ai->parent_or_count) == 1); +// Must be last. - while (ai != NULL) { - // Load first since arena itself is likely from one of its blocks. - upb_ArenaInternal* next_arena = - (upb_ArenaInternal*)upb_Atomic_Load(&ai->next, memory_order_acquire); - upb_alloc* block_alloc = _upb_ArenaInternal_BlockAlloc(ai); - upb_MemBlock* block = upb_Atomic_Load(&ai->blocks, memory_order_acquire); - while (block != NULL) { - // Load first since we are deleting block. - upb_MemBlock* next_block = - upb_Atomic_Load(&block->next, memory_order_acquire); - upb_free(block_alloc, block); - block = next_block; - } - ai = next_arena; - } -} +bool upb_Message_IsExactlyEqual(const upb_Message* msg1, + const upb_Message* msg2, + const upb_MiniTable* m) { + if (msg1 == msg2) return true; -void upb_Arena_Free(upb_Arena* a) { - upb_ArenaInternal* ai = upb_Arena_Internal(a); - uintptr_t poc = upb_Atomic_Load(&ai->parent_or_count, memory_order_acquire); -retry: - while (_upb_Arena_IsTaggedPointer(poc)) { - ai = _upb_Arena_PointerFromTagged(poc); - poc = upb_Atomic_Load(&ai->parent_or_count, memory_order_acquire); - } + int opts = kUpb_EncodeOption_SkipUnknown | kUpb_EncodeOption_Deterministic; + upb_Arena* a = upb_Arena_New(); - // compare_exchange or fetch_sub are RMW operations, which are more - // expensive then direct loads. As an optimization, we only do RMW ops - // when we need to update things for other threads to see. - if (poc == _upb_Arena_TaggedFromRefcount(1)) { - _upb_Arena_DoFree(ai); - return; - } + // Compare deterministically serialized payloads with no unknown fields. + size_t size1, size2; + char *data1, *data2; + upb_EncodeStatus status1 = upb_Encode(msg1, m, opts, a, &data1, &size1); + upb_EncodeStatus status2 = upb_Encode(msg2, m, opts, a, &data2, &size2); - if (upb_Atomic_CompareExchangeWeak( - &ai->parent_or_count, &poc, - _upb_Arena_TaggedFromRefcount(_upb_Arena_RefCountFromTagged(poc) - 1), - memory_order_release, memory_order_acquire)) { - // We were >1 and we decremented it successfully, so we are done. - return; + if (status1 != kUpb_EncodeStatus_Ok || status2 != kUpb_EncodeStatus_Ok) { + // TODO: How should we fail here? (In Ruby we throw an exception.) + upb_Arena_Free(a); + return false; } - // We failed our update, so someone has done something, retry the whole - // process, but the failed exchange reloaded `poc` for us. - goto retry; + const bool ret = (size1 == size2) && (memcmp(data1, data2, size1) == 0); + upb_Arena_Free(a); + return ret; } -static void _upb_Arena_DoFuseArenaLists(upb_ArenaInternal* const parent, - upb_ArenaInternal* child) { - upb_ArenaInternal* parent_tail = - upb_Atomic_Load(&parent->tail, memory_order_relaxed); - do { - // Our tail might be stale, but it will always converge to the true tail. - upb_ArenaInternal* parent_tail_next = - upb_Atomic_Load(&parent_tail->next, memory_order_relaxed); - while (parent_tail_next != NULL) { - parent_tail = parent_tail_next; - parent_tail_next = - upb_Atomic_Load(&parent_tail->next, memory_order_relaxed); - } +#include +#include - upb_ArenaInternal* displaced = - upb_Atomic_Exchange(&parent_tail->next, child, memory_order_relaxed); - parent_tail = upb_Atomic_Load(&child->tail, memory_order_relaxed); - // If we displaced something that got installed racily, we can simply - // reinstall it on our new tail. - child = displaced; - } while (child != NULL); +// Must be last. - upb_Atomic_Store(&parent->tail, parent_tail, memory_order_relaxed); +static upb_StringView upb_Clone_StringView(upb_StringView str, + upb_Arena* arena) { + if (str.size == 0) { + return upb_StringView_FromDataAndSize(NULL, 0); + } + void* cloned_data = upb_Arena_Malloc(arena, str.size); + upb_StringView cloned_str = + upb_StringView_FromDataAndSize(cloned_data, str.size); + memcpy(cloned_data, str.data, str.size); + return cloned_str; } -static upb_ArenaInternal* _upb_Arena_DoFuse(upb_Arena* a1, upb_Arena* a2, - uintptr_t* ref_delta) { - // `parent_or_count` has two disctint modes - // - parent pointer mode - // - refcount mode - // - // In parent pointer mode, it may change what pointer it refers to in the - // tree, but it will always approach a root. Any operation that walks the - // tree to the root may collapse levels of the tree concurrently. - upb_ArenaRoot r1 = _upb_Arena_FindRoot(a1); - upb_ArenaRoot r2 = _upb_Arena_FindRoot(a2); - - if (r1.root == r2.root) return r1.root; // Already fused. - - // Avoid cycles by always fusing into the root with the lower address. - if ((uintptr_t)r1.root > (uintptr_t)r2.root) { - upb_ArenaRoot tmp = r1; - r1 = r2; - r2 = tmp; +static bool upb_Clone_MessageValue(void* value, upb_CType value_type, + const upb_MiniTable* sub, upb_Arena* arena) { + switch (value_type) { + case kUpb_CType_Bool: + case kUpb_CType_Float: + case kUpb_CType_Int32: + case kUpb_CType_UInt32: + case kUpb_CType_Enum: + case kUpb_CType_Double: + case kUpb_CType_Int64: + case kUpb_CType_UInt64: + return true; + case kUpb_CType_String: + case kUpb_CType_Bytes: { + upb_StringView source = *(upb_StringView*)value; + int size = source.size; + void* cloned_data = upb_Arena_Malloc(arena, size); + if (cloned_data == NULL) { + return false; + } + *(upb_StringView*)value = + upb_StringView_FromDataAndSize(cloned_data, size); + memcpy(cloned_data, source.data, size); + return true; + } break; + case kUpb_CType_Message: { + const upb_TaggedMessagePtr source = *(upb_TaggedMessagePtr*)value; + bool is_empty = upb_TaggedMessagePtr_IsEmpty(source); + if (is_empty) sub = UPB_PRIVATE(_upb_MiniTable_Empty)(); + UPB_ASSERT(source); + upb_Message* clone = upb_Message_DeepClone( + UPB_PRIVATE(_upb_TaggedMessagePtr_GetMessage)(source), sub, arena); + *(upb_TaggedMessagePtr*)value = + UPB_PRIVATE(_upb_TaggedMessagePtr_Pack)(clone, is_empty); + return clone != NULL; + } break; } + UPB_UNREACHABLE(); +} - // The moment we install `r1` as the parent for `r2` all racing frees may - // immediately begin decrementing `r1`'s refcount (including pending - // increments to that refcount and their frees!). We need to add `r2`'s refs - // now, so that `r1` can withstand any unrefs that come from r2. - // - // Note that while it is possible for `r2`'s refcount to increase - // asynchronously, we will not actually do the reparenting operation below - // unless `r2`'s refcount is unchanged from when we read it. - // - // Note that we may have done this previously, either to this node or a - // different node, during a previous and failed DoFuse() attempt. But we will - // not lose track of these refs because we always add them to our overall - // delta. - uintptr_t r2_untagged_count = r2.tagged_count & ~1; - uintptr_t with_r2_refs = r1.tagged_count + r2_untagged_count; - if (!upb_Atomic_CompareExchangeStrong( - &r1.root->parent_or_count, &r1.tagged_count, with_r2_refs, - memory_order_release, memory_order_acquire)) { +upb_Map* upb_Map_DeepClone(const upb_Map* map, upb_CType key_type, + upb_CType value_type, + const upb_MiniTable* map_entry_table, + upb_Arena* arena) { + upb_Map* cloned_map = _upb_Map_New(arena, map->key_size, map->val_size); + if (cloned_map == NULL) { return NULL; } - - // Perform the actual fuse by removing the refs from `r2` and swapping in the - // parent pointer. - if (!upb_Atomic_CompareExchangeStrong( - &r2.root->parent_or_count, &r2.tagged_count, - _upb_Arena_TaggedFromPointer(r1.root), memory_order_release, - memory_order_acquire)) { - // We'll need to remove the excess refs we added to r1 previously. - *ref_delta += r2_untagged_count; - return NULL; + upb_MessageValue key, val; + size_t iter = kUpb_Map_Begin; + while (upb_Map_Next(map, &key, &val, &iter)) { + const upb_MiniTableField* value_field = + &map_entry_table->UPB_PRIVATE(fields)[1]; + const upb_MiniTable* value_sub = + (value_field->UPB_PRIVATE(submsg_index) != kUpb_NoSub) + ? upb_MiniTable_GetSubMessageTable(map_entry_table, value_field) + : NULL; + upb_CType value_field_type = upb_MiniTableField_CType(value_field); + if (!upb_Clone_MessageValue(&val, value_field_type, value_sub, arena)) { + return NULL; + } + if (!upb_Map_Set(cloned_map, key, val, arena)) { + return NULL; + } } - - // Now that the fuse has been performed (and can no longer fail) we need to - // append `r2` to `r1`'s linked list. - _upb_Arena_DoFuseArenaLists(r1.root, r2.root); - return r1.root; + return cloned_map; } -static bool _upb_Arena_FixupRefs(upb_ArenaInternal* new_root, - uintptr_t ref_delta) { - if (ref_delta == 0) return true; // No fixup required. - uintptr_t poc = - upb_Atomic_Load(&new_root->parent_or_count, memory_order_relaxed); - if (_upb_Arena_IsTaggedPointer(poc)) return false; - uintptr_t with_refs = poc - ref_delta; - UPB_ASSERT(!_upb_Arena_IsTaggedPointer(with_refs)); - return upb_Atomic_CompareExchangeStrong(&new_root->parent_or_count, &poc, - with_refs, memory_order_relaxed, - memory_order_relaxed); -} - -bool upb_Arena_Fuse(upb_Arena* a1, upb_Arena* a2) { - if (a1 == a2) return true; // trivial fuse +static upb_Map* upb_Message_Map_DeepClone(const upb_Map* map, + const upb_MiniTable* mini_table, + const upb_MiniTableField* f, + upb_Message* clone, + upb_Arena* arena) { + // TODO: use a variant of upb_MiniTable_GetSubMessageTable() here. + const upb_MiniTable* map_entry_table = upb_MiniTableSub_Message( + mini_table->UPB_PRIVATE(subs)[f->UPB_PRIVATE(submsg_index)]); + UPB_ASSERT(map_entry_table); - upb_ArenaInternal* ai1 = upb_Arena_Internal(a1); - upb_ArenaInternal* ai2 = upb_Arena_Internal(a2); + const upb_MiniTableField* key_field = + &map_entry_table->UPB_PRIVATE(fields)[0]; + const upb_MiniTableField* value_field = + &map_entry_table->UPB_PRIVATE(fields)[1]; - // Do not fuse initial blocks since we cannot lifetime extend them. - // Any other fuse scenario is allowed. - if (_upb_ArenaInternal_HasInitialBlock(ai1) || - _upb_ArenaInternal_HasInitialBlock(ai2)) { - return false; + upb_Map* cloned_map = upb_Map_DeepClone( + map, upb_MiniTableField_CType(key_field), + upb_MiniTableField_CType(value_field), map_entry_table, arena); + if (!cloned_map) { + return NULL; } + _upb_Message_SetNonExtensionField(clone, f, &cloned_map); + return cloned_map; +} - // The number of refs we ultimately need to transfer to the new root. - uintptr_t ref_delta = 0; - while (true) { - upb_ArenaInternal* new_root = _upb_Arena_DoFuse(a1, a2, &ref_delta); - if (new_root != NULL && _upb_Arena_FixupRefs(new_root, ref_delta)) { - return true; +upb_Array* upb_Array_DeepClone(const upb_Array* array, upb_CType value_type, + const upb_MiniTable* sub, upb_Arena* arena) { + const size_t size = array->UPB_PRIVATE(size); + const int lg2 = UPB_PRIVATE(_upb_CType_SizeLg2)(value_type); + upb_Array* cloned_array = UPB_PRIVATE(_upb_Array_New)(arena, size, lg2); + if (!cloned_array) { + return NULL; + } + if (!_upb_Array_ResizeUninitialized(cloned_array, size, arena)) { + return NULL; + } + for (size_t i = 0; i < size; ++i) { + upb_MessageValue val = upb_Array_Get(array, i); + if (!upb_Clone_MessageValue(&val, value_type, sub, arena)) { + return false; } + upb_Array_Set(cloned_array, i, val); } + return cloned_array; } -bool upb_Arena_IncRefFor(upb_Arena* a, const void* owner) { - upb_ArenaInternal* ai = upb_Arena_Internal(a); - if (_upb_ArenaInternal_HasInitialBlock(ai)) return false; - upb_ArenaRoot r; +static bool upb_Message_Array_DeepClone(const upb_Array* array, + const upb_MiniTable* mini_table, + const upb_MiniTableField* field, + upb_Message* clone, upb_Arena* arena) { + UPB_PRIVATE(_upb_MiniTableField_CheckIsArray)(field); + upb_Array* cloned_array = upb_Array_DeepClone( + array, upb_MiniTableField_CType(field), + upb_MiniTableField_CType(field) == kUpb_CType_Message && + field->UPB_PRIVATE(submsg_index) != kUpb_NoSub + ? upb_MiniTable_GetSubMessageTable(mini_table, field) + : NULL, + arena); -retry: - r = _upb_Arena_FindRoot(a); - if (upb_Atomic_CompareExchangeWeak( - &r.root->parent_or_count, &r.tagged_count, - _upb_Arena_TaggedFromRefcount( - _upb_Arena_RefCountFromTagged(r.tagged_count) + 1), - memory_order_release, memory_order_acquire)) { - // We incremented it successfully, so we are done. - return true; - } - // We failed update due to parent switching on the arena. - goto retry; + // Clear out upb_Array* due to parent memcpy. + _upb_Message_SetNonExtensionField(clone, field, &cloned_array); + return true; } -void upb_Arena_DecRefFor(upb_Arena* a, const void* owner) { upb_Arena_Free(a); } - -void UPB_PRIVATE(_upb_Arena_SwapIn)(upb_Arena* des, const upb_Arena* src) { - upb_ArenaInternal* desi = upb_Arena_Internal(des); - upb_ArenaInternal* srci = upb_Arena_Internal(src); - - *des = *src; - desi->block_alloc = srci->block_alloc; - upb_MemBlock* blocks = upb_Atomic_Load(&srci->blocks, memory_order_relaxed); - upb_Atomic_Init(&desi->blocks, blocks); +static bool upb_Clone_ExtensionValue( + const upb_MiniTableExtension* mini_table_ext, const upb_Extension* source, + upb_Extension* dest, upb_Arena* arena) { + dest->data = source->data; + return upb_Clone_MessageValue( + &dest->data, + upb_MiniTableField_CType(&mini_table_ext->UPB_PRIVATE(field)), + upb_MiniTableExtension_GetSubMessage(mini_table_ext), arena); } -void UPB_PRIVATE(_upb_Arena_SwapOut)(upb_Arena* des, const upb_Arena* src) { - upb_ArenaInternal* desi = upb_Arena_Internal(des); - upb_ArenaInternal* srci = upb_Arena_Internal(src); +upb_Message* _upb_Message_Copy(upb_Message* dst, const upb_Message* src, + const upb_MiniTable* mini_table, + upb_Arena* arena) { + upb_StringView empty_string = upb_StringView_FromDataAndSize(NULL, 0); + // Only copy message area skipping upb_Message_Internal. + memcpy(dst, src, mini_table->UPB_PRIVATE(size)); + for (size_t i = 0; i < mini_table->UPB_PRIVATE(field_count); ++i) { + const upb_MiniTableField* field = &mini_table->UPB_PRIVATE(fields)[i]; + if (upb_MiniTableField_IsScalar(field)) { + switch (upb_MiniTableField_CType(field)) { + case kUpb_CType_Message: { + upb_TaggedMessagePtr tagged = + upb_Message_GetTaggedMessagePtr(src, field, NULL); + const upb_Message* sub_message = + UPB_PRIVATE(_upb_TaggedMessagePtr_GetMessage)(tagged); + if (sub_message != NULL) { + // If the message is currently in an unlinked, "empty" state we keep + // it that way, because we don't want to deal with decode options, + // decode status, or possible parse failure here. + bool is_empty = upb_TaggedMessagePtr_IsEmpty(tagged); + const upb_MiniTable* sub_message_table = + is_empty ? UPB_PRIVATE(_upb_MiniTable_Empty)() + : upb_MiniTable_GetSubMessageTable(mini_table, field); + upb_Message* dst_sub_message = + upb_Message_DeepClone(sub_message, sub_message_table, arena); + if (dst_sub_message == NULL) { + return NULL; + } + _upb_Message_SetTaggedMessagePtr( + dst, mini_table, field, + UPB_PRIVATE(_upb_TaggedMessagePtr_Pack)(dst_sub_message, + is_empty)); + } + } break; + case kUpb_CType_String: + case kUpb_CType_Bytes: { + upb_StringView str = upb_Message_GetString(src, field, empty_string); + if (str.size != 0) { + if (!upb_Message_SetString( + dst, field, upb_Clone_StringView(str, arena), arena)) { + return NULL; + } + } + } break; + default: + // Scalar, already copied. + break; + } + } else { + if (upb_MiniTableField_IsMap(field)) { + const upb_Map* map = upb_Message_GetMap(src, field); + if (map != NULL) { + if (!upb_Message_Map_DeepClone(map, mini_table, field, dst, arena)) { + return NULL; + } + } + } else { + const upb_Array* array = upb_Message_GetArray(src, field); + if (array != NULL) { + if (!upb_Message_Array_DeepClone(array, mini_table, field, dst, + arena)) { + return NULL; + } + } + } + } + } + // Clone extensions. + size_t ext_count; + const upb_Extension* ext = UPB_PRIVATE(_upb_Message_Getexts)(src, &ext_count); + for (size_t i = 0; i < ext_count; ++i) { + const upb_Extension* msg_ext = &ext[i]; + const upb_MiniTableField* field = &msg_ext->ext->UPB_PRIVATE(field); + upb_Extension* dst_ext = + _upb_Message_GetOrCreateExtension(dst, msg_ext->ext, arena); + if (!dst_ext) return NULL; + if (upb_MiniTableField_IsScalar(field)) { + if (!upb_Clone_ExtensionValue(msg_ext->ext, msg_ext, dst_ext, arena)) { + return NULL; + } + } else { + upb_Array* msg_array = (upb_Array*)msg_ext->data.ptr; + UPB_ASSERT(msg_array); + upb_Array* cloned_array = upb_Array_DeepClone( + msg_array, upb_MiniTableField_CType(field), + upb_MiniTableExtension_GetSubMessage(msg_ext->ext), arena); + if (!cloned_array) { + return NULL; + } + dst_ext->data.ptr = (void*)cloned_array; + } + } - *des = *src; - upb_MemBlock* blocks = upb_Atomic_Load(&srci->blocks, memory_order_relaxed); - upb_Atomic_Store(&desi->blocks, blocks, memory_order_relaxed); + // Clone unknowns. + size_t unknown_size = 0; + const char* ptr = upb_Message_GetUnknown(src, &unknown_size); + if (unknown_size != 0) { + UPB_ASSERT(ptr); + // Make a copy into destination arena. + if (!UPB_PRIVATE(_upb_Message_AddUnknown)(dst, ptr, unknown_size, arena)) { + return NULL; + } + } + return dst; } +bool upb_Message_DeepCopy(upb_Message* dst, const upb_Message* src, + const upb_MiniTable* mini_table, upb_Arena* arena) { + upb_Message_Clear(dst, mini_table); + return _upb_Message_Copy(dst, src, mini_table, arena) != NULL; +} -#include -#include - - -// Must be last. +// Deep clones a message using the provided target arena. +// +// Returns NULL on failure. +upb_Message* upb_Message_DeepClone(const upb_Message* msg, + const upb_MiniTable* m, upb_Arena* arena) { + upb_Message* clone = upb_Message_New(m, arena); + return _upb_Message_Copy(clone, msg, m, arena); +} -upb_Array* upb_Array_New(upb_Arena* a, upb_CType type) { - const int lg2 = UPB_PRIVATE(_upb_CType_SizeLg2)(type); - return UPB_PRIVATE(_upb_Array_New)(a, 4, lg2); +// Performs a shallow copy. TODO: Extend to handle unknown fields. +void upb_Message_ShallowCopy(upb_Message* dst, const upb_Message* src, + const upb_MiniTable* m) { + memcpy(dst, src, m->UPB_PRIVATE(size)); } -const void* upb_Array_DataPtr(const upb_Array* arr) { - return _upb_array_ptr((upb_Array*)arr); +// Performs a shallow clone. Ignores unknown fields. +upb_Message* upb_Message_ShallowClone(const upb_Message* msg, + const upb_MiniTable* m, + upb_Arena* arena) { + upb_Message* clone = upb_Message_New(m, arena); + upb_Message_ShallowCopy(clone, msg, m); + return clone; } -void* upb_Array_MutableDataPtr(upb_Array* arr) { return _upb_array_ptr(arr); } -size_t upb_Array_Size(const upb_Array* arr) { return arr->UPB_PRIVATE(size); } +#include +#include -upb_MessageValue upb_Array_Get(const upb_Array* arr, size_t i) { - upb_MessageValue ret; - const char* data = _upb_array_constptr(arr); - const int lg2 = UPB_PRIVATE(_upb_Array_ElemSizeLg2)(arr); - UPB_ASSERT(i < arr->UPB_PRIVATE(size)); - memcpy(&ret, data + (i << lg2), 1 << lg2); - return ret; -} -void upb_Array_Set(upb_Array* arr, size_t i, upb_MessageValue val) { - char* data = _upb_array_ptr(arr); - const int lg2 = UPB_PRIVATE(_upb_Array_ElemSizeLg2)(arr); - UPB_ASSERT(i < arr->UPB_PRIVATE(size)); - memcpy(data + (i << lg2), &val, 1 << lg2); -} +// Must be last. -bool upb_Array_Append(upb_Array* arr, upb_MessageValue val, upb_Arena* arena) { - UPB_ASSERT(arena); - if (!_upb_Array_ResizeUninitialized(arr, arr->UPB_PRIVATE(size) + 1, arena)) { - return false; - } - upb_Array_Set(arr, arr->UPB_PRIVATE(size) - 1, val); - return true; -} +typedef struct { + upb_MdDecoder base; + upb_Arena* arena; + upb_MiniTableEnum* enum_table; + uint32_t enum_value_count; + uint32_t enum_data_count; + uint32_t enum_data_capacity; +} upb_MdEnumDecoder; -void upb_Array_Move(upb_Array* arr, size_t dst_idx, size_t src_idx, - size_t count) { - const int lg2 = UPB_PRIVATE(_upb_Array_ElemSizeLg2)(arr); - char* data = _upb_array_ptr(arr); - memmove(&data[dst_idx << lg2], &data[src_idx << lg2], count << lg2); +static size_t upb_MiniTableEnum_Size(size_t count) { + return sizeof(upb_MiniTableEnum) + count * sizeof(uint32_t); } -bool upb_Array_Insert(upb_Array* arr, size_t i, size_t count, - upb_Arena* arena) { - UPB_ASSERT(arena); - UPB_ASSERT(i <= arr->UPB_PRIVATE(size)); - UPB_ASSERT(count + arr->UPB_PRIVATE(size) >= count); - const size_t oldsize = arr->UPB_PRIVATE(size); - if (!_upb_Array_ResizeUninitialized(arr, arr->UPB_PRIVATE(size) + count, - arena)) { - return false; +static upb_MiniTableEnum* _upb_MiniTable_AddEnumDataMember(upb_MdEnumDecoder* d, + uint32_t val) { + if (d->enum_data_count == d->enum_data_capacity) { + size_t old_sz = upb_MiniTableEnum_Size(d->enum_data_capacity); + d->enum_data_capacity = UPB_MAX(2, d->enum_data_capacity * 2); + size_t new_sz = upb_MiniTableEnum_Size(d->enum_data_capacity); + d->enum_table = upb_Arena_Realloc(d->arena, d->enum_table, old_sz, new_sz); + upb_MdDecoder_CheckOutOfMemory(&d->base, d->enum_table); } - upb_Array_Move(arr, i + count, i, oldsize - i); - return true; -} - -/* - * i end arr->size - * |------------|XXXXXXXX|--------| - */ -void upb_Array_Delete(upb_Array* arr, size_t i, size_t count) { - const size_t end = i + count; - UPB_ASSERT(i <= end); - UPB_ASSERT(end <= arr->UPB_PRIVATE(size)); - upb_Array_Move(arr, i, end, arr->UPB_PRIVATE(size) - end); - arr->UPB_PRIVATE(size) -= count; + d->enum_table->UPB_PRIVATE(data)[d->enum_data_count++] = val; + return d->enum_table; } -bool upb_Array_Resize(upb_Array* arr, size_t size, upb_Arena* arena) { - const size_t oldsize = arr->UPB_PRIVATE(size); - if (UPB_UNLIKELY(!_upb_Array_ResizeUninitialized(arr, size, arena))) { - return false; - } - const size_t newsize = arr->UPB_PRIVATE(size); - if (newsize > oldsize) { - const int lg2 = UPB_PRIVATE(_upb_Array_ElemSizeLg2)(arr); - char* data = _upb_array_ptr(arr); - memset(data + (oldsize << lg2), 0, (newsize - oldsize) << lg2); +static void upb_MiniTableEnum_BuildValue(upb_MdEnumDecoder* d, uint32_t val) { + upb_MiniTableEnum* table = d->enum_table; + d->enum_value_count++; + if (table->UPB_PRIVATE(value_count) || + (val > 512 && d->enum_value_count < val / 32)) { + if (table->UPB_PRIVATE(value_count) == 0) { + UPB_ASSERT(d->enum_data_count == table->UPB_PRIVATE(mask_limit) / 32); + } + table = _upb_MiniTable_AddEnumDataMember(d, val); + table->UPB_PRIVATE(value_count)++; + } else { + uint32_t new_mask_limit = ((val / 32) + 1) * 32; + while (table->UPB_PRIVATE(mask_limit) < new_mask_limit) { + table = _upb_MiniTable_AddEnumDataMember(d, 0); + table->UPB_PRIVATE(mask_limit) += 32; + } + table->UPB_PRIVATE(data)[val / 32] |= 1ULL << (val % 32); } - return true; } -bool UPB_PRIVATE(_upb_Array_Realloc)(upb_Array* array, size_t min_capacity, - upb_Arena* arena) { - size_t new_capacity = UPB_MAX(array->UPB_PRIVATE(capacity), 4); - const int lg2 = UPB_PRIVATE(_upb_Array_ElemSizeLg2)(array); - size_t old_bytes = array->UPB_PRIVATE(capacity) << lg2; - void* ptr = _upb_array_ptr(array); - - // Log2 ceiling of size. - while (new_capacity < min_capacity) new_capacity *= 2; - - const size_t new_bytes = new_capacity << lg2; - ptr = upb_Arena_Realloc(arena, ptr, old_bytes, new_bytes); - if (!ptr) return false; +static upb_MiniTableEnum* upb_MtDecoder_DoBuildMiniTableEnum( + upb_MdEnumDecoder* d, const char* data, size_t len) { + // If the string is non-empty then it must begin with a version tag. + if (len) { + if (*data != kUpb_EncodedVersion_EnumV1) { + upb_MdDecoder_ErrorJmp(&d->base, "Invalid enum version: %c", *data); + } + data++; + len--; + } - UPB_PRIVATE(_upb_Array_SetTaggedPtr)(array, ptr, lg2); - array->UPB_PRIVATE(capacity) = new_capacity; - return true; -} + upb_MdDecoder_CheckOutOfMemory(&d->base, d->enum_table); + // Guarantee at least 64 bits of mask without checking mask size. + d->enum_table->UPB_PRIVATE(mask_limit) = 64; + d->enum_table = _upb_MiniTable_AddEnumDataMember(d, 0); + d->enum_table = _upb_MiniTable_AddEnumDataMember(d, 0); -#include -#include + d->enum_table->UPB_PRIVATE(value_count) = 0; + const char* ptr = data; + uint32_t base = 0; -// Must be last. + while (ptr < d->base.end) { + char ch = *ptr++; + if (ch <= kUpb_EncodedValue_MaxEnumMask) { + uint32_t mask = _upb_FromBase92(ch); + for (int i = 0; i < 5; i++, base++, mask >>= 1) { + if (mask & 1) upb_MiniTableEnum_BuildValue(d, base); + } + } else if (kUpb_EncodedValue_MinSkip <= ch && + ch <= kUpb_EncodedValue_MaxSkip) { + uint32_t skip; + ptr = upb_MdDecoder_DecodeBase92Varint(&d->base, ptr, ch, + kUpb_EncodedValue_MinSkip, + kUpb_EncodedValue_MaxSkip, &skip); + base += skip; + } else { + upb_MdDecoder_ErrorJmp(&d->base, "Unexpected character: %c", ch); + } + } -const upb_Extension* upb_Message_ExtensionByIndex(const upb_Message* msg, - size_t index) { - size_t count; - const upb_Extension* ext = UPB_PRIVATE(_upb_Message_Getexts)(msg, &count); + return d->enum_table; +} - UPB_ASSERT(index < count); - return &ext[index]; +static upb_MiniTableEnum* upb_MtDecoder_BuildMiniTableEnum( + upb_MdEnumDecoder* const decoder, const char* const data, + size_t const len) { + if (UPB_SETJMP(decoder->base.err) != 0) return NULL; + return upb_MtDecoder_DoBuildMiniTableEnum(decoder, data, len); } -const upb_Extension* upb_Message_FindExtensionByNumber(const upb_Message* msg, - uint32_t field_number) { - size_t count; - const upb_Extension* ext = UPB_PRIVATE(_upb_Message_Getexts)(msg, &count); +upb_MiniTableEnum* upb_MiniDescriptor_BuildEnum(const char* data, size_t len, + upb_Arena* arena, + upb_Status* status) { + upb_MdEnumDecoder decoder = { + .base = + { + .end = UPB_PTRADD(data, len), + .status = status, + }, + .arena = arena, + .enum_table = upb_Arena_Malloc(arena, upb_MiniTableEnum_Size(2)), + .enum_value_count = 0, + .enum_data_count = 0, + .enum_data_capacity = 1, + }; - while (count--) { - if (upb_MiniTableExtension_Number(ext->ext) == field_number) return ext; - ext++; - } - return NULL; + return upb_MtDecoder_BuildMiniTableEnum(&decoder, data, len); } -#include +#include +#include +#include // Must be last. -// Strings/bytes are special-cased in maps. -char _upb_Map_CTypeSizeTable[12] = { - [kUpb_CType_Bool] = 1, - [kUpb_CType_Float] = 4, - [kUpb_CType_Int32] = 4, - [kUpb_CType_UInt32] = 4, - [kUpb_CType_Enum] = 4, - [kUpb_CType_Message] = sizeof(void*), - [kUpb_CType_Double] = 8, - [kUpb_CType_Int64] = 8, - [kUpb_CType_UInt64] = 8, - [kUpb_CType_String] = UPB_MAPTYPE_STRING, - [kUpb_CType_Bytes] = UPB_MAPTYPE_STRING, -}; +// Note: we sort by this number when calculating layout order. +typedef enum { + kUpb_LayoutItemType_OneofCase, // Oneof case. + kUpb_LayoutItemType_OneofField, // Oneof field data. + kUpb_LayoutItemType_Field, // Non-oneof field data. -upb_Map* upb_Map_New(upb_Arena* a, upb_CType key_type, upb_CType value_type) { - return _upb_Map_New(a, _upb_Map_CTypeSize(key_type), - _upb_Map_CTypeSize(value_type)); -} + kUpb_LayoutItemType_Max = kUpb_LayoutItemType_Field, +} upb_LayoutItemType; -size_t upb_Map_Size(const upb_Map* map) { return _upb_Map_Size(map); } +#define kUpb_LayoutItem_IndexSentinel ((uint16_t)-1) -bool upb_Map_Get(const upb_Map* map, upb_MessageValue key, - upb_MessageValue* val) { - return _upb_Map_Get(map, &key, map->key_size, val, map->val_size); -} +typedef struct { + // Index of the corresponding field. When this is a oneof field, the field's + // offset will be the index of the next field in a linked list. + uint16_t field_index; + uint16_t offset; + upb_FieldRep rep; + upb_LayoutItemType type; +} upb_LayoutItem; -void upb_Map_Clear(upb_Map* map) { _upb_Map_Clear(map); } +typedef struct { + upb_LayoutItem* data; + size_t size; + size_t capacity; +} upb_LayoutItemVector; -upb_MapInsertStatus upb_Map_Insert(upb_Map* map, upb_MessageValue key, - upb_MessageValue val, upb_Arena* arena) { - UPB_ASSERT(arena); - return (upb_MapInsertStatus)_upb_Map_Insert(map, &key, map->key_size, &val, - map->val_size, arena); -} +typedef struct { + upb_MdDecoder base; + upb_MiniTable* table; + upb_MiniTableField* fields; + upb_MiniTablePlatform platform; + upb_LayoutItemVector vec; + upb_Arena* arena; +} upb_MtDecoder; -bool upb_Map_Delete(upb_Map* map, upb_MessageValue key, upb_MessageValue* val) { - upb_value v; - const bool removed = _upb_Map_Delete(map, &key, map->key_size, &v); - if (val) _upb_map_fromvalue(v, val, map->val_size); - return removed; -} +// In each field's offset, we temporarily store a presence classifier: +enum PresenceClass { + kNoPresence = 0, + kHasbitPresence = 1, + kRequiredPresence = 2, + kOneofBase = 3, + // Negative values refer to a specific oneof with that number. Positive + // values >= kOneofBase indicate that this field is in a oneof, and specify + // the next field in this oneof's linked list. +}; -bool upb_Map_Next(const upb_Map* map, upb_MessageValue* key, - upb_MessageValue* val, size_t* iter) { - upb_StringView k; - upb_value v; - const bool ok = upb_strtable_next2(&map->table, &k, &v, (intptr_t*)iter); - if (ok) { - _upb_map_fromkey(k, key, map->key_size); - _upb_map_fromvalue(v, val, map->val_size); - } - return ok; +static bool upb_MtDecoder_FieldIsPackable(upb_MiniTableField* field) { + return (field->UPB_PRIVATE(mode) & kUpb_FieldMode_Array) && + upb_FieldType_IsPackable(field->UPB_PRIVATE(descriptortype)); } -UPB_API void upb_Map_SetEntryValue(upb_Map* map, size_t iter, - upb_MessageValue val) { - upb_value v; - _upb_map_tovalue(&val, map->val_size, &v, NULL); - upb_strtable_setentryvalue(&map->table, iter, v); -} +typedef struct { + uint16_t submsg_count; + uint16_t subenum_count; +} upb_SubCounts; -bool upb_MapIterator_Next(const upb_Map* map, size_t* iter) { - return _upb_map_next(map, iter); -} +static void upb_MiniTable_SetTypeAndSub(upb_MiniTableField* field, + upb_FieldType type, + upb_SubCounts* sub_counts, + uint64_t msg_modifiers, + bool is_proto3_enum) { + if (is_proto3_enum) { + UPB_ASSERT(type == kUpb_FieldType_Enum); + type = kUpb_FieldType_Int32; + field->UPB_PRIVATE(mode) |= kUpb_LabelFlags_IsAlternate; + } else if (type == kUpb_FieldType_String && + !(msg_modifiers & kUpb_MessageModifier_ValidateUtf8)) { + type = kUpb_FieldType_Bytes; + field->UPB_PRIVATE(mode) |= kUpb_LabelFlags_IsAlternate; + } -bool upb_MapIterator_Done(const upb_Map* map, size_t iter) { - upb_strtable_iter i; - UPB_ASSERT(iter != kUpb_Map_Begin); - i.t = &map->table; - i.index = iter; - return upb_strtable_done(&i); -} + field->UPB_PRIVATE(descriptortype) = type; -// Returns the key and value for this entry of the map. -upb_MessageValue upb_MapIterator_Key(const upb_Map* map, size_t iter) { - upb_strtable_iter i; - upb_MessageValue ret; - i.t = &map->table; - i.index = iter; - _upb_map_fromkey(upb_strtable_iter_key(&i), &ret, map->key_size); - return ret; -} + if (upb_MtDecoder_FieldIsPackable(field) && + (msg_modifiers & kUpb_MessageModifier_DefaultIsPacked)) { + field->UPB_PRIVATE(mode) |= kUpb_LabelFlags_IsPacked; + } -upb_MessageValue upb_MapIterator_Value(const upb_Map* map, size_t iter) { - upb_strtable_iter i; - upb_MessageValue ret; - i.t = &map->table; - i.index = iter; - _upb_map_fromvalue(upb_strtable_iter_value(&i), &ret, map->val_size); - return ret; + if (type == kUpb_FieldType_Message || type == kUpb_FieldType_Group) { + field->UPB_PRIVATE(submsg_index) = sub_counts->submsg_count++; + } else if (type == kUpb_FieldType_Enum) { + // We will need to update this later once we know the total number of + // submsg fields. + field->UPB_PRIVATE(submsg_index) = sub_counts->subenum_count++; + } else { + field->UPB_PRIVATE(submsg_index) = kUpb_NoSub; + } } -// EVERYTHING BELOW THIS LINE IS INTERNAL - DO NOT USE ///////////////////////// +static const char kUpb_EncodedToType[] = { + [kUpb_EncodedType_Double] = kUpb_FieldType_Double, + [kUpb_EncodedType_Float] = kUpb_FieldType_Float, + [kUpb_EncodedType_Int64] = kUpb_FieldType_Int64, + [kUpb_EncodedType_UInt64] = kUpb_FieldType_UInt64, + [kUpb_EncodedType_Int32] = kUpb_FieldType_Int32, + [kUpb_EncodedType_Fixed64] = kUpb_FieldType_Fixed64, + [kUpb_EncodedType_Fixed32] = kUpb_FieldType_Fixed32, + [kUpb_EncodedType_Bool] = kUpb_FieldType_Bool, + [kUpb_EncodedType_String] = kUpb_FieldType_String, + [kUpb_EncodedType_Group] = kUpb_FieldType_Group, + [kUpb_EncodedType_Message] = kUpb_FieldType_Message, + [kUpb_EncodedType_Bytes] = kUpb_FieldType_Bytes, + [kUpb_EncodedType_UInt32] = kUpb_FieldType_UInt32, + [kUpb_EncodedType_OpenEnum] = kUpb_FieldType_Enum, + [kUpb_EncodedType_SFixed32] = kUpb_FieldType_SFixed32, + [kUpb_EncodedType_SFixed64] = kUpb_FieldType_SFixed64, + [kUpb_EncodedType_SInt32] = kUpb_FieldType_SInt32, + [kUpb_EncodedType_SInt64] = kUpb_FieldType_SInt64, + [kUpb_EncodedType_ClosedEnum] = kUpb_FieldType_Enum, +}; -upb_Map* _upb_Map_New(upb_Arena* a, size_t key_size, size_t value_size) { - upb_Map* map = upb_Arena_Malloc(a, sizeof(upb_Map)); - if (!map) return NULL; +static void upb_MiniTable_SetField(upb_MtDecoder* d, uint8_t ch, + upb_MiniTableField* field, + uint64_t msg_modifiers, + upb_SubCounts* sub_counts) { + static const char kUpb_EncodedToFieldRep[] = { + [kUpb_EncodedType_Double] = kUpb_FieldRep_8Byte, + [kUpb_EncodedType_Float] = kUpb_FieldRep_4Byte, + [kUpb_EncodedType_Int64] = kUpb_FieldRep_8Byte, + [kUpb_EncodedType_UInt64] = kUpb_FieldRep_8Byte, + [kUpb_EncodedType_Int32] = kUpb_FieldRep_4Byte, + [kUpb_EncodedType_Fixed64] = kUpb_FieldRep_8Byte, + [kUpb_EncodedType_Fixed32] = kUpb_FieldRep_4Byte, + [kUpb_EncodedType_Bool] = kUpb_FieldRep_1Byte, + [kUpb_EncodedType_String] = kUpb_FieldRep_StringView, + [kUpb_EncodedType_Bytes] = kUpb_FieldRep_StringView, + [kUpb_EncodedType_UInt32] = kUpb_FieldRep_4Byte, + [kUpb_EncodedType_OpenEnum] = kUpb_FieldRep_4Byte, + [kUpb_EncodedType_SFixed32] = kUpb_FieldRep_4Byte, + [kUpb_EncodedType_SFixed64] = kUpb_FieldRep_8Byte, + [kUpb_EncodedType_SInt32] = kUpb_FieldRep_4Byte, + [kUpb_EncodedType_SInt64] = kUpb_FieldRep_8Byte, + [kUpb_EncodedType_ClosedEnum] = kUpb_FieldRep_4Byte, + }; - upb_strtable_init(&map->table, 4, a); - map->key_size = key_size; - map->val_size = value_size; + char pointer_rep = d->platform == kUpb_MiniTablePlatform_32Bit + ? kUpb_FieldRep_4Byte + : kUpb_FieldRep_8Byte; - return map; + int8_t type = _upb_FromBase92(ch); + if (ch >= _upb_ToBase92(kUpb_EncodedType_RepeatedBase)) { + type -= kUpb_EncodedType_RepeatedBase; + field->UPB_PRIVATE(mode) = kUpb_FieldMode_Array; + field->UPB_PRIVATE(mode) |= pointer_rep << kUpb_FieldRep_Shift; + field->UPB_PRIVATE(offset) = kNoPresence; + } else { + field->UPB_PRIVATE(mode) = kUpb_FieldMode_Scalar; + field->UPB_PRIVATE(offset) = kHasbitPresence; + if (type == kUpb_EncodedType_Group || type == kUpb_EncodedType_Message) { + field->UPB_PRIVATE(mode) |= pointer_rep << kUpb_FieldRep_Shift; + } else if ((unsigned long)type >= sizeof(kUpb_EncodedToFieldRep)) { + upb_MdDecoder_ErrorJmp(&d->base, "Invalid field type: %d", (int)type); + } else { + field->UPB_PRIVATE(mode) |= kUpb_EncodedToFieldRep[type] + << kUpb_FieldRep_Shift; + } + } + if ((unsigned long)type >= sizeof(kUpb_EncodedToType)) { + upb_MdDecoder_ErrorJmp(&d->base, "Invalid field type: %d", (int)type); + } + upb_MiniTable_SetTypeAndSub(field, kUpb_EncodedToType[type], sub_counts, + msg_modifiers, type == kUpb_EncodedType_OpenEnum); } +static void upb_MtDecoder_ModifyField(upb_MtDecoder* d, + uint32_t message_modifiers, + uint32_t field_modifiers, + upb_MiniTableField* field) { + if (field_modifiers & kUpb_EncodedFieldModifier_FlipPacked) { + if (!upb_MtDecoder_FieldIsPackable(field)) { + upb_MdDecoder_ErrorJmp(&d->base, + "Cannot flip packed on unpackable field %" PRIu32, + upb_MiniTableField_Number(field)); + } + field->UPB_PRIVATE(mode) ^= kUpb_LabelFlags_IsPacked; + } -#include -#include + if (field_modifiers & kUpb_EncodedFieldModifier_FlipValidateUtf8) { + if (field->UPB_PRIVATE(descriptortype) != kUpb_FieldType_Bytes || + !(field->UPB_PRIVATE(mode) & kUpb_LabelFlags_IsAlternate)) { + upb_MdDecoder_ErrorJmp(&d->base, + "Cannot flip ValidateUtf8 on field %" PRIu32 + ", type=%d, mode=%d", + upb_MiniTableField_Number(field), + (int)field->UPB_PRIVATE(descriptortype), + (int)field->UPB_PRIVATE(mode)); + } + field->UPB_PRIVATE(descriptortype) = kUpb_FieldType_String; + field->UPB_PRIVATE(mode) &= ~kUpb_LabelFlags_IsAlternate; + } + bool singular = field_modifiers & kUpb_EncodedFieldModifier_IsProto3Singular; + bool required = field_modifiers & kUpb_EncodedFieldModifier_IsRequired; -// Must be last. + // Validate. + if ((singular || required) && field->UPB_PRIVATE(offset) != kHasbitPresence) { + upb_MdDecoder_ErrorJmp(&d->base, + "Invalid modifier(s) for repeated field %" PRIu32, + upb_MiniTableField_Number(field)); + } + if (singular && required) { + upb_MdDecoder_ErrorJmp( + &d->base, "Field %" PRIu32 " cannot be both singular and required", + upb_MiniTableField_Number(field)); + } -static void _upb_mapsorter_getkeys(const void* _a, const void* _b, void* a_key, - void* b_key, size_t size) { - const upb_tabent* const* a = _a; - const upb_tabent* const* b = _b; - upb_StringView a_tabkey = upb_tabstrview((*a)->key); - upb_StringView b_tabkey = upb_tabstrview((*b)->key); - _upb_map_fromkey(a_tabkey, a_key, size); - _upb_map_fromkey(b_tabkey, b_key, size); + if (singular) field->UPB_PRIVATE(offset) = kNoPresence; + if (required) { + field->UPB_PRIVATE(offset) = kRequiredPresence; + } } -static int _upb_mapsorter_cmpi64(const void* _a, const void* _b) { - int64_t a, b; - _upb_mapsorter_getkeys(_a, _b, &a, &b, 8); - return a < b ? -1 : a > b; +static void upb_MtDecoder_PushItem(upb_MtDecoder* d, upb_LayoutItem item) { + if (d->vec.size == d->vec.capacity) { + size_t new_cap = UPB_MAX(8, d->vec.size * 2); + d->vec.data = realloc(d->vec.data, new_cap * sizeof(*d->vec.data)); + upb_MdDecoder_CheckOutOfMemory(&d->base, d->vec.data); + d->vec.capacity = new_cap; + } + d->vec.data[d->vec.size++] = item; } -static int _upb_mapsorter_cmpu64(const void* _a, const void* _b) { - uint64_t a, b; - _upb_mapsorter_getkeys(_a, _b, &a, &b, 8); - return a < b ? -1 : a > b; -} +static void upb_MtDecoder_PushOneof(upb_MtDecoder* d, upb_LayoutItem item) { + if (item.field_index == kUpb_LayoutItem_IndexSentinel) { + upb_MdDecoder_ErrorJmp(&d->base, "Empty oneof"); + } + item.field_index -= kOneofBase; -static int _upb_mapsorter_cmpi32(const void* _a, const void* _b) { - int32_t a, b; - _upb_mapsorter_getkeys(_a, _b, &a, &b, 4); - return a < b ? -1 : a > b; -} + // Push oneof data. + item.type = kUpb_LayoutItemType_OneofField; + upb_MtDecoder_PushItem(d, item); -static int _upb_mapsorter_cmpu32(const void* _a, const void* _b) { - uint32_t a, b; - _upb_mapsorter_getkeys(_a, _b, &a, &b, 4); - return a < b ? -1 : a > b; + // Push oneof case. + item.rep = kUpb_FieldRep_4Byte; // Field Number. + item.type = kUpb_LayoutItemType_OneofCase; + upb_MtDecoder_PushItem(d, item); } -static int _upb_mapsorter_cmpbool(const void* _a, const void* _b) { - bool a, b; - _upb_mapsorter_getkeys(_a, _b, &a, &b, 1); - return a < b ? -1 : a > b; +size_t upb_MtDecoder_SizeOfRep(upb_FieldRep rep, + upb_MiniTablePlatform platform) { + static const uint8_t kRepToSize32[] = { + [kUpb_FieldRep_1Byte] = 1, + [kUpb_FieldRep_4Byte] = 4, + [kUpb_FieldRep_StringView] = 8, + [kUpb_FieldRep_8Byte] = 8, + }; + static const uint8_t kRepToSize64[] = { + [kUpb_FieldRep_1Byte] = 1, + [kUpb_FieldRep_4Byte] = 4, + [kUpb_FieldRep_StringView] = 16, + [kUpb_FieldRep_8Byte] = 8, + }; + UPB_ASSERT(sizeof(upb_StringView) == + UPB_SIZE(kRepToSize32, kRepToSize64)[kUpb_FieldRep_StringView]); + return platform == kUpb_MiniTablePlatform_32Bit ? kRepToSize32[rep] + : kRepToSize64[rep]; } -static int _upb_mapsorter_cmpstr(const void* _a, const void* _b) { - upb_StringView a, b; - _upb_mapsorter_getkeys(_a, _b, &a, &b, UPB_MAPTYPE_STRING); - size_t common_size = UPB_MIN(a.size, b.size); - int cmp = memcmp(a.data, b.data, common_size); - if (cmp) return -cmp; - return a.size < b.size ? -1 : a.size > b.size; +size_t upb_MtDecoder_AlignOfRep(upb_FieldRep rep, + upb_MiniTablePlatform platform) { + static const uint8_t kRepToAlign32[] = { + [kUpb_FieldRep_1Byte] = 1, + [kUpb_FieldRep_4Byte] = 4, + [kUpb_FieldRep_StringView] = 4, + [kUpb_FieldRep_8Byte] = 8, + }; + static const uint8_t kRepToAlign64[] = { + [kUpb_FieldRep_1Byte] = 1, + [kUpb_FieldRep_4Byte] = 4, + [kUpb_FieldRep_StringView] = 8, + [kUpb_FieldRep_8Byte] = 8, + }; + UPB_ASSERT(UPB_ALIGN_OF(upb_StringView) == + UPB_SIZE(kRepToAlign32, kRepToAlign64)[kUpb_FieldRep_StringView]); + return platform == kUpb_MiniTablePlatform_32Bit ? kRepToAlign32[rep] + : kRepToAlign64[rep]; } -static int (*const compar[kUpb_FieldType_SizeOf])(const void*, const void*) = { - [kUpb_FieldType_Int64] = _upb_mapsorter_cmpi64, - [kUpb_FieldType_SFixed64] = _upb_mapsorter_cmpi64, - [kUpb_FieldType_SInt64] = _upb_mapsorter_cmpi64, - - [kUpb_FieldType_UInt64] = _upb_mapsorter_cmpu64, - [kUpb_FieldType_Fixed64] = _upb_mapsorter_cmpu64, - - [kUpb_FieldType_Int32] = _upb_mapsorter_cmpi32, - [kUpb_FieldType_SInt32] = _upb_mapsorter_cmpi32, - [kUpb_FieldType_SFixed32] = _upb_mapsorter_cmpi32, - [kUpb_FieldType_Enum] = _upb_mapsorter_cmpi32, - - [kUpb_FieldType_UInt32] = _upb_mapsorter_cmpu32, - [kUpb_FieldType_Fixed32] = _upb_mapsorter_cmpu32, - - [kUpb_FieldType_Bool] = _upb_mapsorter_cmpbool, - - [kUpb_FieldType_String] = _upb_mapsorter_cmpstr, - [kUpb_FieldType_Bytes] = _upb_mapsorter_cmpstr, -}; - -static bool _upb_mapsorter_resize(_upb_mapsorter* s, _upb_sortedmap* sorted, - int size) { - sorted->start = s->size; - sorted->pos = sorted->start; - sorted->end = sorted->start + size; +static const char* upb_MtDecoder_DecodeOneofField(upb_MtDecoder* d, + const char* ptr, + char first_ch, + upb_LayoutItem* item) { + uint32_t field_num; + ptr = upb_MdDecoder_DecodeBase92Varint( + &d->base, ptr, first_ch, kUpb_EncodedValue_MinOneofField, + kUpb_EncodedValue_MaxOneofField, &field_num); + upb_MiniTableField* f = + (void*)upb_MiniTable_FindFieldByNumber(d->table, field_num); - if (sorted->end > s->cap) { - const int oldsize = s->cap * sizeof(*s->entries); - s->cap = upb_Log2CeilingSize(sorted->end); - const int newsize = s->cap * sizeof(*s->entries); - s->entries = upb_grealloc(s->entries, oldsize, newsize); - if (!s->entries) return false; + if (!f) { + upb_MdDecoder_ErrorJmp(&d->base, + "Couldn't add field number %" PRIu32 + " to oneof, no such field number.", + field_num); + } + if (f->UPB_PRIVATE(offset) != kHasbitPresence) { + upb_MdDecoder_ErrorJmp( + &d->base, + "Cannot add repeated, required, or singular field %" PRIu32 + " to oneof.", + field_num); } - s->size = sorted->end; - return true; + // Oneof storage must be large enough to accommodate the largest member. + int rep = f->UPB_PRIVATE(mode) >> kUpb_FieldRep_Shift; + if (upb_MtDecoder_SizeOfRep(rep, d->platform) > + upb_MtDecoder_SizeOfRep(item->rep, d->platform)) { + item->rep = rep; + } + // Prepend this field to the linked list. + f->UPB_PRIVATE(offset) = item->field_index; + item->field_index = (f - d->fields) + kOneofBase; + return ptr; } -bool _upb_mapsorter_pushmap(_upb_mapsorter* s, upb_FieldType key_type, - const upb_Map* map, _upb_sortedmap* sorted) { - int map_size = _upb_Map_Size(map); - - if (!_upb_mapsorter_resize(s, sorted, map_size)) return false; - - // Copy non-empty entries from the table to s->entries. - const void** dst = &s->entries[sorted->start]; - const upb_tabent* src = map->table.t.entries; - const upb_tabent* end = src + upb_table_size(&map->table.t); - for (; src < end; src++) { - if (!upb_tabent_isempty(src)) { - *dst = src; - dst++; +static const char* upb_MtDecoder_DecodeOneofs(upb_MtDecoder* d, + const char* ptr) { + upb_LayoutItem item = {.rep = 0, + .field_index = kUpb_LayoutItem_IndexSentinel}; + while (ptr < d->base.end) { + char ch = *ptr++; + if (ch == kUpb_EncodedValue_FieldSeparator) { + // Field separator, no action needed. + } else if (ch == kUpb_EncodedValue_OneofSeparator) { + // End of oneof. + upb_MtDecoder_PushOneof(d, item); + item.field_index = kUpb_LayoutItem_IndexSentinel; // Move to next oneof. + } else { + ptr = upb_MtDecoder_DecodeOneofField(d, ptr, ch, &item); } } - UPB_ASSERT(dst == &s->entries[sorted->end]); - - // Sort entries according to the key type. - qsort(&s->entries[sorted->start], map_size, sizeof(*s->entries), - compar[key_type]); - return true; -} -static int _upb_mapsorter_cmpext(const void* _a, const void* _b) { - const upb_Extension* const* a = _a; - const upb_Extension* const* b = _b; - uint32_t a_num = upb_MiniTableExtension_Number((*a)->ext); - uint32_t b_num = upb_MiniTableExtension_Number((*b)->ext); - assert(a_num != b_num); - return a_num < b_num ? -1 : 1; + // Push final oneof. + upb_MtDecoder_PushOneof(d, item); + return ptr; } -bool _upb_mapsorter_pushexts(_upb_mapsorter* s, const upb_Extension* exts, - size_t count, _upb_sortedmap* sorted) { - if (!_upb_mapsorter_resize(s, sorted, count)) return false; - - for (size_t i = 0; i < count; i++) { - s->entries[sorted->start + i] = &exts[i]; +static const char* upb_MtDecoder_ParseModifier(upb_MtDecoder* d, + const char* ptr, char first_ch, + upb_MiniTableField* last_field, + uint64_t* msg_modifiers) { + uint32_t mod; + ptr = upb_MdDecoder_DecodeBase92Varint(&d->base, ptr, first_ch, + kUpb_EncodedValue_MinModifier, + kUpb_EncodedValue_MaxModifier, &mod); + if (last_field) { + upb_MtDecoder_ModifyField(d, *msg_modifiers, mod, last_field); + } else { + if (!d->table) { + upb_MdDecoder_ErrorJmp(&d->base, + "Extensions cannot have message modifiers"); + } + *msg_modifiers = mod; } - qsort(&s->entries[sorted->start], count, sizeof(*s->entries), - _upb_mapsorter_cmpext); - return true; -} - - -#include -#include -#include - - -// Must be last. - -static const size_t message_overhead = sizeof(upb_Message_InternalData); - -upb_Message* upb_Message_New(const upb_MiniTable* m, upb_Arena* a) { - return _upb_Message_New(m, a); -} - -bool UPB_PRIVATE(_upb_Message_AddUnknown)(upb_Message* msg, const char* data, - size_t len, upb_Arena* arena) { - if (!UPB_PRIVATE(_upb_Message_Realloc)(msg, len, arena)) return false; - upb_Message_Internal* owner = upb_Message_Getinternal(msg); - upb_Message_InternalData* in = owner->internal; - memcpy(UPB_PTR_AT(in, in->unknown_end, char), data, len); - in->unknown_end += len; - return true; + return ptr; } -void _upb_Message_DiscardUnknown_shallow(upb_Message* msg) { - upb_Message_Internal* owner = upb_Message_Getinternal(msg); - upb_Message_InternalData* in = owner->internal; - if (in) { - in->unknown_end = message_overhead; +static void upb_MtDecoder_AllocateSubs(upb_MtDecoder* d, + upb_SubCounts sub_counts) { + uint32_t total_count = sub_counts.submsg_count + sub_counts.subenum_count; + size_t subs_bytes = sizeof(*d->table->UPB_PRIVATE(subs)) * total_count; + upb_MiniTableSub* subs = upb_Arena_Malloc(d->arena, subs_bytes); + upb_MdDecoder_CheckOutOfMemory(&d->base, subs); + uint32_t i = 0; + for (; i < sub_counts.submsg_count; i++) { + subs[i].UPB_PRIVATE(submsg) = UPB_PRIVATE(_upb_MiniTable_Empty)(); } -} - -const char* upb_Message_GetUnknown(const upb_Message* msg, size_t* len) { - upb_Message_Internal* owner = upb_Message_Getinternal(msg); - upb_Message_InternalData* in = owner->internal; - if (in) { - *len = in->unknown_end - message_overhead; - return (char*)(in + 1); - } else { - *len = 0; - return NULL; + if (sub_counts.subenum_count) { + upb_MiniTableField* f = d->fields; + upb_MiniTableField* end_f = f + d->table->UPB_PRIVATE(field_count); + for (; f < end_f; f++) { + if (f->UPB_PRIVATE(descriptortype) == kUpb_FieldType_Enum) { + f->UPB_PRIVATE(submsg_index) += sub_counts.submsg_count; + } + } + for (; i < sub_counts.submsg_count + sub_counts.subenum_count; i++) { + subs[i].UPB_PRIVATE(subenum) = NULL; + } } + d->table->UPB_PRIVATE(subs) = subs; } -void upb_Message_DeleteUnknown(upb_Message* msg, const char* data, size_t len) { - upb_Message_Internal* owner = upb_Message_Getinternal(msg); - upb_Message_InternalData* in = owner->internal; - const char* internal_unknown_end = UPB_PTR_AT(in, in->unknown_end, char); - -#ifndef NDEBUG - size_t full_unknown_size; - const char* full_unknown = upb_Message_GetUnknown(msg, &full_unknown_size); - UPB_ASSERT((uintptr_t)data >= (uintptr_t)full_unknown); - UPB_ASSERT((uintptr_t)data < (uintptr_t)(full_unknown + full_unknown_size)); - UPB_ASSERT((uintptr_t)(data + len) > (uintptr_t)data); - UPB_ASSERT((uintptr_t)(data + len) <= (uintptr_t)internal_unknown_end); -#endif +static const char* upb_MtDecoder_Parse(upb_MtDecoder* d, const char* ptr, + size_t len, void* fields, + size_t field_size, uint16_t* field_count, + upb_SubCounts* sub_counts) { + uint64_t msg_modifiers = 0; + uint32_t last_field_number = 0; + upb_MiniTableField* last_field = NULL; + bool need_dense_below = d->table != NULL; - if ((data + len) != internal_unknown_end) { - memmove((char*)data, data + len, internal_unknown_end - data - len); + d->base.end = UPB_PTRADD(ptr, len); + + while (ptr < d->base.end) { + char ch = *ptr++; + if (ch <= kUpb_EncodedValue_MaxField) { + if (!d->table && last_field) { + // For extensions, consume only a single field and then return. + return --ptr; + } + upb_MiniTableField* field = fields; + *field_count += 1; + fields = (char*)fields + field_size; + field->UPB_PRIVATE(number) = ++last_field_number; + last_field = field; + upb_MiniTable_SetField(d, ch, field, msg_modifiers, sub_counts); + } else if (kUpb_EncodedValue_MinModifier <= ch && + ch <= kUpb_EncodedValue_MaxModifier) { + ptr = upb_MtDecoder_ParseModifier(d, ptr, ch, last_field, &msg_modifiers); + if (msg_modifiers & kUpb_MessageModifier_IsExtendable) { + d->table->UPB_PRIVATE(ext) |= kUpb_ExtMode_Extendable; + } + } else if (ch == kUpb_EncodedValue_End) { + if (!d->table) { + upb_MdDecoder_ErrorJmp(&d->base, "Extensions cannot have oneofs."); + } + ptr = upb_MtDecoder_DecodeOneofs(d, ptr); + } else if (kUpb_EncodedValue_MinSkip <= ch && + ch <= kUpb_EncodedValue_MaxSkip) { + if (need_dense_below) { + d->table->UPB_PRIVATE(dense_below) = d->table->UPB_PRIVATE(field_count); + need_dense_below = false; + } + uint32_t skip; + ptr = upb_MdDecoder_DecodeBase92Varint(&d->base, ptr, ch, + kUpb_EncodedValue_MinSkip, + kUpb_EncodedValue_MaxSkip, &skip); + last_field_number += skip; + last_field_number--; // Next field seen will increment. + } else { + upb_MdDecoder_ErrorJmp(&d->base, "Invalid char: %c", ch); + } } - in->unknown_end -= len; -} -size_t upb_Message_ExtensionCount(const upb_Message* msg) { - size_t count; - UPB_PRIVATE(_upb_Message_Getexts)(msg, &count); - return count; -} + if (need_dense_below) { + d->table->UPB_PRIVATE(dense_below) = d->table->UPB_PRIVATE(field_count); + } + return ptr; +} -#include +static void upb_MtDecoder_ParseMessage(upb_MtDecoder* d, const char* data, + size_t len) { + // Buffer length is an upper bound on the number of fields. We will return + // what we don't use. + d->fields = upb_Arena_Malloc(d->arena, sizeof(*d->fields) * len); + upb_MdDecoder_CheckOutOfMemory(&d->base, d->fields); + upb_SubCounts sub_counts = {0, 0}; + d->table->UPB_PRIVATE(field_count) = 0; + d->table->UPB_PRIVATE(fields) = d->fields; + upb_MtDecoder_Parse(d, data, len, d->fields, sizeof(*d->fields), + &d->table->UPB_PRIVATE(field_count), &sub_counts); -// Must be last. + upb_Arena_ShrinkLast(d->arena, d->fields, sizeof(*d->fields) * len, + sizeof(*d->fields) * d->table->UPB_PRIVATE(field_count)); + d->table->UPB_PRIVATE(fields) = d->fields; + upb_MtDecoder_AllocateSubs(d, sub_counts); +} -bool upb_Message_SetMapEntry(upb_Map* map, const upb_MiniTable* mini_table, - const upb_MiniTableField* f, - upb_Message* map_entry_message, upb_Arena* arena) { - // TODO: use a variant of upb_MiniTable_GetSubMessageTable() here. - const upb_MiniTable* map_entry_mini_table = upb_MiniTableSub_Message( - mini_table->UPB_PRIVATE(subs)[f->UPB_PRIVATE(submsg_index)]); - UPB_ASSERT(map_entry_mini_table); - UPB_ASSERT(map_entry_mini_table->UPB_PRIVATE(field_count) == 2); - const upb_MiniTableField* map_entry_key_field = - &map_entry_mini_table->UPB_PRIVATE(fields)[0]; - const upb_MiniTableField* map_entry_value_field = - &map_entry_mini_table->UPB_PRIVATE(fields)[1]; - // Map key/value cannot have explicit defaults, - // hence assuming a zero default is valid. - upb_MessageValue default_val; - memset(&default_val, 0, sizeof(upb_MessageValue)); - upb_MessageValue map_entry_key = - upb_Message_GetField(map_entry_message, map_entry_key_field, default_val); - upb_MessageValue map_entry_value = upb_Message_GetField( - map_entry_message, map_entry_value_field, default_val); - return upb_Map_Set(map, map_entry_key, map_entry_value, arena); +int upb_MtDecoder_CompareFields(const void* _a, const void* _b) { + const upb_LayoutItem* a = _a; + const upb_LayoutItem* b = _b; + // Currently we just sort by: + // 1. rep (smallest fields first) + // 2. type (oneof cases first) + // 2. field_index (smallest numbers first) + // The main goal of this is to reduce space lost to padding. + // Later we may have more subtle reasons to prefer a different ordering. + const int rep_bits = upb_Log2Ceiling(kUpb_FieldRep_Max); + const int type_bits = upb_Log2Ceiling(kUpb_LayoutItemType_Max); + const int idx_bits = (sizeof(a->field_index) * 8); + UPB_ASSERT(idx_bits + rep_bits + type_bits < 32); +#define UPB_COMBINE(rep, ty, idx) (((rep << type_bits) | ty) << idx_bits) | idx + uint32_t a_packed = UPB_COMBINE(a->rep, a->type, a->field_index); + uint32_t b_packed = UPB_COMBINE(b->rep, b->type, b->field_index); + UPB_ASSERT(a_packed != b_packed); +#undef UPB_COMBINE + return a_packed < b_packed ? -1 : 1; } +static bool upb_MtDecoder_SortLayoutItems(upb_MtDecoder* d) { + // Add items for all non-oneof fields (oneofs were already added). + int n = d->table->UPB_PRIVATE(field_count); + for (int i = 0; i < n; i++) { + upb_MiniTableField* f = &d->fields[i]; + if (f->UPB_PRIVATE(offset) >= kOneofBase) continue; + upb_LayoutItem item = {.field_index = i, + .rep = f->UPB_PRIVATE(mode) >> kUpb_FieldRep_Shift, + .type = kUpb_LayoutItemType_Field}; + upb_MtDecoder_PushItem(d, item); + } -#include + if (d->vec.size) { + qsort(d->vec.data, d->vec.size, sizeof(*d->vec.data), + upb_MtDecoder_CompareFields); + } + return true; +} -// Must be last. +static size_t upb_MiniTable_DivideRoundUp(size_t n, size_t d) { + return (n + d - 1) / d; +} -bool upb_Message_IsExactlyEqual(const upb_Message* msg1, - const upb_Message* msg2, - const upb_MiniTable* m) { - if (msg1 == msg2) return true; +static void upb_MtDecoder_AssignHasbits(upb_MtDecoder* d) { + upb_MiniTable* ret = d->table; + int n = ret->UPB_PRIVATE(field_count); + int last_hasbit = 0; // 0 cannot be used. - int opts = kUpb_EncodeOption_SkipUnknown | kUpb_EncodeOption_Deterministic; - upb_Arena* a = upb_Arena_New(); + // First assign required fields, which must have the lowest hasbits. + for (int i = 0; i < n; i++) { + upb_MiniTableField* field = + (upb_MiniTableField*)&ret->UPB_PRIVATE(fields)[i]; + if (field->UPB_PRIVATE(offset) == kRequiredPresence) { + field->presence = ++last_hasbit; + } else if (field->UPB_PRIVATE(offset) == kNoPresence) { + field->presence = 0; + } + } + if (last_hasbit > 63) { + upb_MdDecoder_ErrorJmp(&d->base, "Too many required fields"); + } - // Compare deterministically serialized payloads with no unknown fields. - size_t size1, size2; - char *data1, *data2; - upb_EncodeStatus status1 = upb_Encode(msg1, m, opts, a, &data1, &size1); - upb_EncodeStatus status2 = upb_Encode(msg2, m, opts, a, &data2, &size2); + ret->UPB_PRIVATE(required_count) = last_hasbit; - if (status1 != kUpb_EncodeStatus_Ok || status2 != kUpb_EncodeStatus_Ok) { - // TODO: How should we fail here? (In Ruby we throw an exception.) - upb_Arena_Free(a); - return false; + // Next assign non-required hasbit fields. + for (int i = 0; i < n; i++) { + upb_MiniTableField* field = + (upb_MiniTableField*)&ret->UPB_PRIVATE(fields)[i]; + if (field->UPB_PRIVATE(offset) == kHasbitPresence) { + field->presence = ++last_hasbit; + } } - const bool ret = (size1 == size2) && (memcmp(data1, data2, size1) == 0); - upb_Arena_Free(a); - return ret; + ret->UPB_PRIVATE(size) = + last_hasbit ? upb_MiniTable_DivideRoundUp(last_hasbit + 1, 8) : 0; } +size_t upb_MtDecoder_Place(upb_MtDecoder* d, upb_FieldRep rep) { + size_t size = upb_MtDecoder_SizeOfRep(rep, d->platform); + size_t align = upb_MtDecoder_AlignOfRep(rep, d->platform); + size_t ret = UPB_ALIGN_UP(d->table->UPB_PRIVATE(size), align); + static const size_t max = UINT16_MAX; + size_t new_size = ret + size; + if (new_size > max) { + upb_MdDecoder_ErrorJmp( + &d->base, "Message size exceeded maximum size of %zu bytes", max); + } + d->table->UPB_PRIVATE(size) = new_size; + return ret; +} -#include -#include - +static void upb_MtDecoder_AssignOffsets(upb_MtDecoder* d) { + upb_LayoutItem* end = UPB_PTRADD(d->vec.data, d->vec.size); -// Must be last. + // Compute offsets. + for (upb_LayoutItem* item = d->vec.data; item < end; item++) { + item->offset = upb_MtDecoder_Place(d, item->rep); + } -static upb_StringView upb_Clone_StringView(upb_StringView str, - upb_Arena* arena) { - if (str.size == 0) { - return upb_StringView_FromDataAndSize(NULL, 0); + // Assign oneof case offsets. We must do these first, since assigning + // actual offsets will overwrite the links of the linked list. + for (upb_LayoutItem* item = d->vec.data; item < end; item++) { + if (item->type != kUpb_LayoutItemType_OneofCase) continue; + upb_MiniTableField* f = &d->fields[item->field_index]; + while (true) { + f->presence = ~item->offset; + if (f->UPB_PRIVATE(offset) == kUpb_LayoutItem_IndexSentinel) break; + UPB_ASSERT(f->UPB_PRIVATE(offset) - kOneofBase < + d->table->UPB_PRIVATE(field_count)); + f = &d->fields[f->UPB_PRIVATE(offset) - kOneofBase]; + } } - void* cloned_data = upb_Arena_Malloc(arena, str.size); - upb_StringView cloned_str = - upb_StringView_FromDataAndSize(cloned_data, str.size); - memcpy(cloned_data, str.data, str.size); - return cloned_str; -} -static bool upb_Clone_MessageValue(void* value, upb_CType value_type, - const upb_MiniTable* sub, upb_Arena* arena) { - switch (value_type) { - case kUpb_CType_Bool: - case kUpb_CType_Float: - case kUpb_CType_Int32: - case kUpb_CType_UInt32: - case kUpb_CType_Enum: - case kUpb_CType_Double: - case kUpb_CType_Int64: - case kUpb_CType_UInt64: - return true; - case kUpb_CType_String: - case kUpb_CType_Bytes: { - upb_StringView source = *(upb_StringView*)value; - int size = source.size; - void* cloned_data = upb_Arena_Malloc(arena, size); - if (cloned_data == NULL) { - return false; - } - *(upb_StringView*)value = - upb_StringView_FromDataAndSize(cloned_data, size); - memcpy(cloned_data, source.data, size); - return true; - } break; - case kUpb_CType_Message: { - const upb_TaggedMessagePtr source = *(upb_TaggedMessagePtr*)value; - bool is_empty = upb_TaggedMessagePtr_IsEmpty(source); - if (is_empty) sub = UPB_PRIVATE(_upb_MiniTable_Empty)(); - UPB_ASSERT(source); - upb_Message* clone = upb_Message_DeepClone( - UPB_PRIVATE(_upb_TaggedMessagePtr_GetMessage)(source), sub, arena); - *(upb_TaggedMessagePtr*)value = - UPB_PRIVATE(_upb_TaggedMessagePtr_Pack)(clone, is_empty); - return clone != NULL; - } break; + // Assign offsets. + for (upb_LayoutItem* item = d->vec.data; item < end; item++) { + upb_MiniTableField* f = &d->fields[item->field_index]; + switch (item->type) { + case kUpb_LayoutItemType_OneofField: + while (true) { + uint16_t next_offset = f->UPB_PRIVATE(offset); + f->UPB_PRIVATE(offset) = item->offset; + if (next_offset == kUpb_LayoutItem_IndexSentinel) break; + f = &d->fields[next_offset - kOneofBase]; + } + break; + case kUpb_LayoutItemType_Field: + f->UPB_PRIVATE(offset) = item->offset; + break; + default: + break; + } } - UPB_UNREACHABLE(); + + // The fasttable parser (supported on 64-bit only) depends on this being a + // multiple of 8 in order to satisfy UPB_MALLOC_ALIGN, which is also 8. + // + // On 32-bit we could potentially make this smaller, but there is no + // compelling reason to optimize this right now. + d->table->UPB_PRIVATE(size) = UPB_ALIGN_UP(d->table->UPB_PRIVATE(size), 8); } -upb_Map* upb_Map_DeepClone(const upb_Map* map, upb_CType key_type, - upb_CType value_type, - const upb_MiniTable* map_entry_table, - upb_Arena* arena) { - upb_Map* cloned_map = _upb_Map_New(arena, map->key_size, map->val_size); - if (cloned_map == NULL) { - return NULL; - } - upb_MessageValue key, val; - size_t iter = kUpb_Map_Begin; - while (upb_Map_Next(map, &key, &val, &iter)) { - const upb_MiniTableField* value_field = - &map_entry_table->UPB_PRIVATE(fields)[1]; - const upb_MiniTable* value_sub = - (value_field->UPB_PRIVATE(submsg_index) != kUpb_NoSub) - ? upb_MiniTable_GetSubMessageTable(map_entry_table, value_field) - : NULL; - upb_CType value_field_type = upb_MiniTableField_CType(value_field); - if (!upb_Clone_MessageValue(&val, value_field_type, value_sub, arena)) { - return NULL; - } - if (!upb_Map_Set(cloned_map, key, val, arena)) { - return NULL; - } +static void upb_MtDecoder_ValidateEntryField(upb_MtDecoder* d, + const upb_MiniTableField* f, + uint32_t expected_num) { + const char* name = expected_num == 1 ? "key" : "val"; + const uint32_t f_number = upb_MiniTableField_Number(f); + if (f_number != expected_num) { + upb_MdDecoder_ErrorJmp(&d->base, + "map %s did not have expected number (%d vs %d)", + name, expected_num, f_number); } - return cloned_map; -} -static upb_Map* upb_Message_Map_DeepClone(const upb_Map* map, - const upb_MiniTable* mini_table, - const upb_MiniTableField* f, - upb_Message* clone, - upb_Arena* arena) { - // TODO: use a variant of upb_MiniTable_GetSubMessageTable() here. - const upb_MiniTable* map_entry_table = upb_MiniTableSub_Message( - mini_table->UPB_PRIVATE(subs)[f->UPB_PRIVATE(submsg_index)]); - UPB_ASSERT(map_entry_table); + if (!upb_MiniTableField_IsScalar(f)) { + upb_MdDecoder_ErrorJmp( + &d->base, "map %s cannot be repeated or map, or be in oneof", name); + } - const upb_MiniTableField* key_field = - &map_entry_table->UPB_PRIVATE(fields)[0]; - const upb_MiniTableField* value_field = - &map_entry_table->UPB_PRIVATE(fields)[1]; + uint32_t not_ok_types; + if (expected_num == 1) { + not_ok_types = (1 << kUpb_FieldType_Float) | (1 << kUpb_FieldType_Double) | + (1 << kUpb_FieldType_Message) | (1 << kUpb_FieldType_Group) | + (1 << kUpb_FieldType_Bytes) | (1 << kUpb_FieldType_Enum); + } else { + not_ok_types = 1 << kUpb_FieldType_Group; + } - upb_Map* cloned_map = upb_Map_DeepClone( - map, upb_MiniTableField_CType(key_field), - upb_MiniTableField_CType(value_field), map_entry_table, arena); - if (!cloned_map) { - return NULL; + if ((1 << upb_MiniTableField_Type(f)) & not_ok_types) { + upb_MdDecoder_ErrorJmp(&d->base, "map %s cannot have type %d", name, + (int)f->UPB_PRIVATE(descriptortype)); } - _upb_Message_SetNonExtensionField(clone, f, &cloned_map); - return cloned_map; } -upb_Array* upb_Array_DeepClone(const upb_Array* array, upb_CType value_type, - const upb_MiniTable* sub, upb_Arena* arena) { - const size_t size = array->UPB_PRIVATE(size); - const int lg2 = UPB_PRIVATE(_upb_CType_SizeLg2)(value_type); - upb_Array* cloned_array = UPB_PRIVATE(_upb_Array_New)(arena, size, lg2); - if (!cloned_array) { - return NULL; - } - if (!_upb_Array_ResizeUninitialized(cloned_array, size, arena)) { - return NULL; +static void upb_MtDecoder_ParseMap(upb_MtDecoder* d, const char* data, + size_t len) { + upb_MtDecoder_ParseMessage(d, data, len); + upb_MtDecoder_AssignHasbits(d); + + if (UPB_UNLIKELY(d->table->UPB_PRIVATE(field_count) != 2)) { + upb_MdDecoder_ErrorJmp(&d->base, "%hu fields in map", + d->table->UPB_PRIVATE(field_count)); + UPB_UNREACHABLE(); } - for (size_t i = 0; i < size; ++i) { - upb_MessageValue val = upb_Array_Get(array, i); - if (!upb_Clone_MessageValue(&val, value_type, sub, arena)) { - return false; + + upb_LayoutItem* end = UPB_PTRADD(d->vec.data, d->vec.size); + for (upb_LayoutItem* item = d->vec.data; item < end; item++) { + if (item->type == kUpb_LayoutItemType_OneofCase) { + upb_MdDecoder_ErrorJmp(&d->base, "Map entry cannot have oneof"); } - upb_Array_Set(cloned_array, i, val); } - return cloned_array; + + upb_MtDecoder_ValidateEntryField(d, &d->table->UPB_PRIVATE(fields)[0], 1); + upb_MtDecoder_ValidateEntryField(d, &d->table->UPB_PRIVATE(fields)[1], 2); + + // Map entries have a pre-determined layout, regardless of types. + // NOTE: sync with mini_table/message_internal.h. + const size_t kv_size = d->platform == kUpb_MiniTablePlatform_32Bit ? 8 : 16; + const size_t hasbit_size = 8; + d->fields[0].UPB_PRIVATE(offset) = hasbit_size; + d->fields[1].UPB_PRIVATE(offset) = hasbit_size + kv_size; + d->table->UPB_PRIVATE(size) = + UPB_ALIGN_UP(hasbit_size + kv_size + kv_size, 8); + + // Map entries have a special bit set to signal it's a map entry, used in + // upb_MiniTable_SetSubMessage() below. + d->table->UPB_PRIVATE(ext) |= kUpb_ExtMode_IsMapEntry; } -static bool upb_Message_Array_DeepClone(const upb_Array* array, - const upb_MiniTable* mini_table, - const upb_MiniTableField* field, - upb_Message* clone, upb_Arena* arena) { - UPB_PRIVATE(_upb_MiniTableField_CheckIsArray)(field); - upb_Array* cloned_array = upb_Array_DeepClone( - array, upb_MiniTableField_CType(field), - upb_MiniTableField_CType(field) == kUpb_CType_Message && - field->UPB_PRIVATE(submsg_index) != kUpb_NoSub - ? upb_MiniTable_GetSubMessageTable(mini_table, field) - : NULL, - arena); +static void upb_MtDecoder_ParseMessageSet(upb_MtDecoder* d, const char* data, + size_t len) { + if (len > 0) { + upb_MdDecoder_ErrorJmp(&d->base, "Invalid message set encode length: %zu", + len); + } - // Clear out upb_Array* due to parent memcpy. - _upb_Message_SetNonExtensionField(clone, field, &cloned_array); - return true; + upb_MiniTable* ret = d->table; + ret->UPB_PRIVATE(size) = 0; + ret->UPB_PRIVATE(field_count) = 0; + ret->UPB_PRIVATE(ext) = kUpb_ExtMode_IsMessageSet; + ret->UPB_PRIVATE(dense_below) = 0; + ret->UPB_PRIVATE(table_mask) = -1; + ret->UPB_PRIVATE(required_count) = 0; } -static bool upb_Clone_ExtensionValue( - const upb_MiniTableExtension* mini_table_ext, const upb_Extension* source, - upb_Extension* dest, upb_Arena* arena) { - dest->data = source->data; - return upb_Clone_MessageValue( - &dest->data, - upb_MiniTableField_CType(&mini_table_ext->UPB_PRIVATE(field)), - upb_MiniTableExtension_GetSubMessage(mini_table_ext), arena); +static upb_MiniTable* upb_MtDecoder_DoBuildMiniTableWithBuf( + upb_MtDecoder* decoder, const char* data, size_t len, void** buf, + size_t* buf_size) { + upb_MdDecoder_CheckOutOfMemory(&decoder->base, decoder->table); + + decoder->table->UPB_PRIVATE(size) = 0; + decoder->table->UPB_PRIVATE(field_count) = 0; + decoder->table->UPB_PRIVATE(ext) = kUpb_ExtMode_NonExtendable; + decoder->table->UPB_PRIVATE(dense_below) = 0; + decoder->table->UPB_PRIVATE(table_mask) = -1; + decoder->table->UPB_PRIVATE(required_count) = 0; + + // Strip off and verify the version tag. + if (!len--) goto done; + const char vers = *data++; + + switch (vers) { + case kUpb_EncodedVersion_MapV1: + upb_MtDecoder_ParseMap(decoder, data, len); + break; + + case kUpb_EncodedVersion_MessageV1: + upb_MtDecoder_ParseMessage(decoder, data, len); + upb_MtDecoder_AssignHasbits(decoder); + upb_MtDecoder_SortLayoutItems(decoder); + upb_MtDecoder_AssignOffsets(decoder); + break; + + case kUpb_EncodedVersion_MessageSetV1: + upb_MtDecoder_ParseMessageSet(decoder, data, len); + break; + + default: + upb_MdDecoder_ErrorJmp(&decoder->base, "Invalid message version: %c", + vers); + } + +done: + *buf = decoder->vec.data; + *buf_size = decoder->vec.capacity * sizeof(*decoder->vec.data); + return decoder->table; } -upb_Message* _upb_Message_Copy(upb_Message* dst, const upb_Message* src, - const upb_MiniTable* mini_table, - upb_Arena* arena) { - upb_StringView empty_string = upb_StringView_FromDataAndSize(NULL, 0); - // Only copy message area skipping upb_Message_Internal. - memcpy(dst, src, mini_table->UPB_PRIVATE(size)); - for (size_t i = 0; i < mini_table->UPB_PRIVATE(field_count); ++i) { - const upb_MiniTableField* field = &mini_table->UPB_PRIVATE(fields)[i]; - if (upb_MiniTableField_IsScalar(field)) { - switch (upb_MiniTableField_CType(field)) { - case kUpb_CType_Message: { - upb_TaggedMessagePtr tagged = - upb_Message_GetTaggedMessagePtr(src, field, NULL); - const upb_Message* sub_message = - UPB_PRIVATE(_upb_TaggedMessagePtr_GetMessage)(tagged); - if (sub_message != NULL) { - // If the message is currently in an unlinked, "empty" state we keep - // it that way, because we don't want to deal with decode options, - // decode status, or possible parse failure here. - bool is_empty = upb_TaggedMessagePtr_IsEmpty(tagged); - const upb_MiniTable* sub_message_table = - is_empty ? UPB_PRIVATE(_upb_MiniTable_Empty)() - : upb_MiniTable_GetSubMessageTable(mini_table, field); - upb_Message* dst_sub_message = - upb_Message_DeepClone(sub_message, sub_message_table, arena); - if (dst_sub_message == NULL) { - return NULL; - } - _upb_Message_SetTaggedMessagePtr( - dst, mini_table, field, - UPB_PRIVATE(_upb_TaggedMessagePtr_Pack)(dst_sub_message, - is_empty)); - } - } break; - case kUpb_CType_String: - case kUpb_CType_Bytes: { - upb_StringView str = upb_Message_GetString(src, field, empty_string); - if (str.size != 0) { - if (!upb_Message_SetString( - dst, field, upb_Clone_StringView(str, arena), arena)) { - return NULL; - } - } - } break; - default: - // Scalar, already copied. - break; - } - } else { - if (upb_MiniTableField_IsMap(field)) { - const upb_Map* map = upb_Message_GetMap(src, field); - if (map != NULL) { - if (!upb_Message_Map_DeepClone(map, mini_table, field, dst, arena)) { - return NULL; - } - } - } else { - const upb_Array* array = upb_Message_GetArray(src, field); - if (array != NULL) { - if (!upb_Message_Array_DeepClone(array, mini_table, field, dst, - arena)) { - return NULL; - } - } - } - } +static upb_MiniTable* upb_MtDecoder_BuildMiniTableWithBuf( + upb_MtDecoder* const decoder, const char* const data, const size_t len, + void** const buf, size_t* const buf_size) { + if (UPB_SETJMP(decoder->base.err) != 0) { + *buf = decoder->vec.data; + *buf_size = decoder->vec.capacity * sizeof(*decoder->vec.data); + return NULL; } - // Clone extensions. - size_t ext_count; - const upb_Extension* ext = UPB_PRIVATE(_upb_Message_Getexts)(src, &ext_count); - for (size_t i = 0; i < ext_count; ++i) { - const upb_Extension* msg_ext = &ext[i]; - const upb_MiniTableField* field = &msg_ext->ext->UPB_PRIVATE(field); - upb_Extension* dst_ext = - _upb_Message_GetOrCreateExtension(dst, msg_ext->ext, arena); - if (!dst_ext) return NULL; - if (upb_MiniTableField_IsScalar(field)) { - if (!upb_Clone_ExtensionValue(msg_ext->ext, msg_ext, dst_ext, arena)) { - return NULL; - } - } else { - upb_Array* msg_array = (upb_Array*)msg_ext->data.ptr; - UPB_ASSERT(msg_array); - upb_Array* cloned_array = upb_Array_DeepClone( - msg_array, upb_MiniTableField_CType(field), - upb_MiniTableExtension_GetSubMessage(msg_ext->ext), arena); - if (!cloned_array) { - return NULL; - } - dst_ext->data.ptr = (void*)cloned_array; + + return upb_MtDecoder_DoBuildMiniTableWithBuf(decoder, data, len, buf, + buf_size); +} + +upb_MiniTable* upb_MiniTable_BuildWithBuf(const char* data, size_t len, + upb_MiniTablePlatform platform, + upb_Arena* arena, void** buf, + size_t* buf_size, + upb_Status* status) { + upb_MtDecoder decoder = { + .base = {.status = status}, + .platform = platform, + .vec = + { + .data = *buf, + .capacity = *buf_size / sizeof(*decoder.vec.data), + .size = 0, + }, + .arena = arena, + .table = upb_Arena_Malloc(arena, sizeof(*decoder.table)), + }; + + return upb_MtDecoder_BuildMiniTableWithBuf(&decoder, data, len, buf, + buf_size); +} + +static const char* upb_MtDecoder_DoBuildMiniTableExtension( + upb_MtDecoder* decoder, const char* data, size_t len, + upb_MiniTableExtension* ext, const upb_MiniTable* extendee, + upb_MiniTableSub sub) { + // If the string is non-empty then it must begin with a version tag. + if (len) { + if (*data != kUpb_EncodedVersion_ExtensionV1) { + upb_MdDecoder_ErrorJmp(&decoder->base, "Invalid ext version: %c", *data); } + data++; + len--; } - // Clone unknowns. - size_t unknown_size = 0; - const char* ptr = upb_Message_GetUnknown(src, &unknown_size); - if (unknown_size != 0) { - UPB_ASSERT(ptr); - // Make a copy into destination arena. - if (!UPB_PRIVATE(_upb_Message_AddUnknown)(dst, ptr, unknown_size, arena)) { - return NULL; - } + uint16_t count = 0; + upb_SubCounts sub_counts = {0, 0}; + const char* ret = upb_MtDecoder_Parse(decoder, data, len, ext, sizeof(*ext), + &count, &sub_counts); + if (!ret || count != 1) return NULL; + + upb_MiniTableField* f = &ext->UPB_PRIVATE(field); + + f->UPB_PRIVATE(mode) |= kUpb_LabelFlags_IsExtension; + f->UPB_PRIVATE(offset) = 0; + f->presence = 0; + + if (extendee->UPB_PRIVATE(ext) & kUpb_ExtMode_IsMessageSet) { + // Extensions of MessageSet must be messages. + if (!upb_MiniTableField_IsSubMessage(f)) return NULL; + + // Extensions of MessageSet must be non-repeating. + if (upb_MiniTableField_IsArray(f)) return NULL; } - return dst; + + ext->UPB_PRIVATE(extendee) = extendee; + ext->UPB_PRIVATE(sub) = sub; + + return ret; } -bool upb_Message_DeepCopy(upb_Message* dst, const upb_Message* src, - const upb_MiniTable* mini_table, upb_Arena* arena) { - upb_Message_Clear(dst, mini_table); - return _upb_Message_Copy(dst, src, mini_table, arena) != NULL; +static const char* upb_MtDecoder_BuildMiniTableExtension( + upb_MtDecoder* const decoder, const char* const data, const size_t len, + upb_MiniTableExtension* const ext, const upb_MiniTable* const extendee, + const upb_MiniTableSub sub) { + if (UPB_SETJMP(decoder->base.err) != 0) return NULL; + return upb_MtDecoder_DoBuildMiniTableExtension(decoder, data, len, ext, + extendee, sub); } -// Deep clones a message using the provided target arena. -// -// Returns NULL on failure. -upb_Message* upb_Message_DeepClone(const upb_Message* msg, - const upb_MiniTable* m, upb_Arena* arena) { - upb_Message* clone = upb_Message_New(m, arena); - return _upb_Message_Copy(clone, msg, m, arena); +const char* _upb_MiniTableExtension_Init(const char* data, size_t len, + upb_MiniTableExtension* ext, + const upb_MiniTable* extendee, + upb_MiniTableSub sub, + upb_MiniTablePlatform platform, + upb_Status* status) { + upb_MtDecoder decoder = { + .base = {.status = status}, + .arena = NULL, + .table = NULL, + .platform = platform, + }; + + return upb_MtDecoder_BuildMiniTableExtension(&decoder, data, len, ext, + extendee, sub); } -// Performs a shallow copy. TODO: Extend to handle unknown fields. -void upb_Message_ShallowCopy(upb_Message* dst, const upb_Message* src, - const upb_MiniTable* m) { - memcpy(dst, src, m->UPB_PRIVATE(size)); +upb_MiniTableExtension* _upb_MiniTableExtension_Build( + const char* data, size_t len, const upb_MiniTable* extendee, + upb_MiniTableSub sub, upb_MiniTablePlatform platform, upb_Arena* arena, + upb_Status* status) { + upb_MiniTableExtension* ext = + upb_Arena_Malloc(arena, sizeof(upb_MiniTableExtension)); + if (UPB_UNLIKELY(!ext)) return NULL; + + const char* ptr = _upb_MiniTableExtension_Init(data, len, ext, extendee, sub, + platform, status); + if (UPB_UNLIKELY(!ptr)) return NULL; + + return ext; } -// Performs a shallow clone. Ignores unknown fields. -upb_Message* upb_Message_ShallowClone(const upb_Message* msg, - const upb_MiniTable* m, - upb_Arena* arena) { - upb_Message* clone = upb_Message_New(m, arena); - upb_Message_ShallowCopy(clone, msg, m); - return clone; +upb_MiniTable* _upb_MiniTable_Build(const char* data, size_t len, + upb_MiniTablePlatform platform, + upb_Arena* arena, upb_Status* status) { + void* buf = NULL; + size_t size = 0; + upb_MiniTable* ret = upb_MiniTable_BuildWithBuf(data, len, platform, arena, + &buf, &size, status); + free(buf); + return ret; } @@ -6370,5212 +6354,5892 @@ upb_Message* upb_Message_ShallowClone(const upb_Message* msg, // Must be last. -typedef struct { - upb_MdDecoder base; - upb_Arena* arena; - upb_MiniTableEnum* enum_table; - uint32_t enum_value_count; - uint32_t enum_data_count; - uint32_t enum_data_capacity; -} upb_MdEnumDecoder; +bool upb_MiniTable_SetSubMessage(upb_MiniTable* table, + upb_MiniTableField* field, + const upb_MiniTable* sub) { + UPB_ASSERT((uintptr_t)table->UPB_PRIVATE(fields) <= (uintptr_t)field && + (uintptr_t)field < (uintptr_t)(table->UPB_PRIVATE(fields) + + table->UPB_PRIVATE(field_count))); + UPB_ASSERT(sub); -static size_t upb_MiniTableEnum_Size(size_t count) { - return sizeof(upb_MiniTableEnum) + count * sizeof(uint32_t); -} + const bool sub_is_map = sub->UPB_PRIVATE(ext) & kUpb_ExtMode_IsMapEntry; -static upb_MiniTableEnum* _upb_MiniTable_AddEnumDataMember(upb_MdEnumDecoder* d, - uint32_t val) { - if (d->enum_data_count == d->enum_data_capacity) { - size_t old_sz = upb_MiniTableEnum_Size(d->enum_data_capacity); - d->enum_data_capacity = UPB_MAX(2, d->enum_data_capacity * 2); - size_t new_sz = upb_MiniTableEnum_Size(d->enum_data_capacity); - d->enum_table = upb_Arena_Realloc(d->arena, d->enum_table, old_sz, new_sz); - upb_MdDecoder_CheckOutOfMemory(&d->base, d->enum_table); - } - d->enum_table->UPB_PRIVATE(data)[d->enum_data_count++] = val; - return d->enum_table; -} + switch (field->UPB_PRIVATE(descriptortype)) { + case kUpb_FieldType_Message: + if (sub_is_map) { + const bool table_is_map = + table->UPB_PRIVATE(ext) & kUpb_ExtMode_IsMapEntry; + if (UPB_UNLIKELY(table_is_map)) return false; -static void upb_MiniTableEnum_BuildValue(upb_MdEnumDecoder* d, uint32_t val) { - upb_MiniTableEnum* table = d->enum_table; - d->enum_value_count++; - if (table->UPB_PRIVATE(value_count) || - (val > 512 && d->enum_value_count < val / 32)) { - if (table->UPB_PRIVATE(value_count) == 0) { - UPB_ASSERT(d->enum_data_count == table->UPB_PRIVATE(mask_limit) / 32); - } - table = _upb_MiniTable_AddEnumDataMember(d, val); - table->UPB_PRIVATE(value_count)++; - } else { - uint32_t new_mask_limit = ((val / 32) + 1) * 32; - while (table->UPB_PRIVATE(mask_limit) < new_mask_limit) { - table = _upb_MiniTable_AddEnumDataMember(d, 0); - table->UPB_PRIVATE(mask_limit) += 32; - } - table->UPB_PRIVATE(data)[val / 32] |= 1ULL << (val % 32); - } -} + field->UPB_PRIVATE(mode) = + (field->UPB_PRIVATE(mode) & ~kUpb_FieldMode_Mask) | + kUpb_FieldMode_Map; + } + break; -static upb_MiniTableEnum* upb_MtDecoder_DoBuildMiniTableEnum( - upb_MdEnumDecoder* d, const char* data, size_t len) { - // If the string is non-empty then it must begin with a version tag. - if (len) { - if (*data != kUpb_EncodedVersion_EnumV1) { - upb_MdDecoder_ErrorJmp(&d->base, "Invalid enum version: %c", *data); - } - data++; - len--; + case kUpb_FieldType_Group: + if (UPB_UNLIKELY(sub_is_map)) return false; + break; + + default: + return false; } - upb_MdDecoder_CheckOutOfMemory(&d->base, d->enum_table); + upb_MiniTableSub* table_sub = + (void*)&table->UPB_PRIVATE(subs)[field->UPB_PRIVATE(submsg_index)]; + // TODO: Add this assert back once YouTube is updated to not call + // this function repeatedly. + // UPB_ASSERT(UPB_PRIVATE(_upb_MiniTable_IsEmpty)(table_sub->submsg)); + *table_sub = upb_MiniTableSub_FromMessage(sub); + return true; +} - // Guarantee at least 64 bits of mask without checking mask size. - d->enum_table->UPB_PRIVATE(mask_limit) = 64; - d->enum_table = _upb_MiniTable_AddEnumDataMember(d, 0); - d->enum_table = _upb_MiniTable_AddEnumDataMember(d, 0); +bool upb_MiniTable_SetSubEnum(upb_MiniTable* table, upb_MiniTableField* field, + const upb_MiniTableEnum* sub) { + UPB_ASSERT((uintptr_t)table->UPB_PRIVATE(fields) <= (uintptr_t)field && + (uintptr_t)field < (uintptr_t)(table->UPB_PRIVATE(fields) + + table->UPB_PRIVATE(field_count))); + UPB_ASSERT(sub); - d->enum_table->UPB_PRIVATE(value_count) = 0; + upb_MiniTableSub* table_sub = + (void*)&table->UPB_PRIVATE(subs)[field->UPB_PRIVATE(submsg_index)]; + *table_sub = upb_MiniTableSub_FromEnum(sub); + return true; +} - const char* ptr = data; - uint32_t base = 0; +uint32_t upb_MiniTable_GetSubList(const upb_MiniTable* mt, + const upb_MiniTableField** subs) { + uint32_t msg_count = 0; + uint32_t enum_count = 0; - while (ptr < d->base.end) { - char ch = *ptr++; - if (ch <= kUpb_EncodedValue_MaxEnumMask) { - uint32_t mask = _upb_FromBase92(ch); - for (int i = 0; i < 5; i++, base++, mask >>= 1) { - if (mask & 1) upb_MiniTableEnum_BuildValue(d, base); - } - } else if (kUpb_EncodedValue_MinSkip <= ch && - ch <= kUpb_EncodedValue_MaxSkip) { - uint32_t skip; - ptr = upb_MdDecoder_DecodeBase92Varint(&d->base, ptr, ch, - kUpb_EncodedValue_MinSkip, - kUpb_EncodedValue_MaxSkip, &skip); - base += skip; - } else { - upb_MdDecoder_ErrorJmp(&d->base, "Unexpected character: %c", ch); + for (int i = 0; i < mt->UPB_PRIVATE(field_count); i++) { + const upb_MiniTableField* f = &mt->UPB_PRIVATE(fields)[i]; + if (upb_MiniTableField_CType(f) == kUpb_CType_Message) { + *subs = f; + ++subs; + msg_count++; } } - return d->enum_table; -} + for (int i = 0; i < mt->UPB_PRIVATE(field_count); i++) { + const upb_MiniTableField* f = &mt->UPB_PRIVATE(fields)[i]; + if (upb_MiniTableField_CType(f) == kUpb_CType_Enum) { + *subs = f; + ++subs; + enum_count++; + } + } -static upb_MiniTableEnum* upb_MtDecoder_BuildMiniTableEnum( - upb_MdEnumDecoder* const decoder, const char* const data, - size_t const len) { - if (UPB_SETJMP(decoder->base.err) != 0) return NULL; - return upb_MtDecoder_DoBuildMiniTableEnum(decoder, data, len); + return (msg_count << 16) | enum_count; } -upb_MiniTableEnum* upb_MiniDescriptor_BuildEnum(const char* data, size_t len, - upb_Arena* arena, - upb_Status* status) { - upb_MdEnumDecoder decoder = { - .base = - { - .end = UPB_PTRADD(data, len), - .status = status, - }, - .arena = arena, - .enum_table = upb_Arena_Malloc(arena, upb_MiniTableEnum_Size(2)), - .enum_value_count = 0, - .enum_data_count = 0, - .enum_data_capacity = 1, - }; +// The list of sub_tables and sub_enums must exactly match the number and order +// of sub-message fields and sub-enum fields given by upb_MiniTable_GetSubList() +// above. +bool upb_MiniTable_Link(upb_MiniTable* mt, const upb_MiniTable** sub_tables, + size_t sub_table_count, + const upb_MiniTableEnum** sub_enums, + size_t sub_enum_count) { + uint32_t msg_count = 0; + uint32_t enum_count = 0; - return upb_MtDecoder_BuildMiniTableEnum(&decoder, data, len); + for (int i = 0; i < mt->UPB_PRIVATE(field_count); i++) { + upb_MiniTableField* f = (upb_MiniTableField*)&mt->UPB_PRIVATE(fields)[i]; + if (upb_MiniTableField_CType(f) == kUpb_CType_Message) { + const upb_MiniTable* sub = sub_tables[msg_count++]; + if (msg_count > sub_table_count) return false; + if (sub != NULL) { + if (!upb_MiniTable_SetSubMessage(mt, f, sub)) return false; + } + } + } + + for (int i = 0; i < mt->UPB_PRIVATE(field_count); i++) { + upb_MiniTableField* f = (upb_MiniTableField*)&mt->UPB_PRIVATE(fields)[i]; + if (upb_MiniTableField_IsClosedEnum(f)) { + const upb_MiniTableEnum* sub = sub_enums[enum_count++]; + if (enum_count > sub_enum_count) return false; + if (sub != NULL) { + if (!upb_MiniTable_SetSubEnum(mt, f, sub)) return false; + } + } + } + + return true; } -#include +#include #include -#include +#include // Must be last. -// Note: we sort by this number when calculating layout order. -typedef enum { - kUpb_LayoutItemType_OneofCase, // Oneof case. - kUpb_LayoutItemType_OneofField, // Oneof field data. - kUpb_LayoutItemType_Field, // Non-oneof field data. - - kUpb_LayoutItemType_Max = kUpb_LayoutItemType_Field, -} upb_LayoutItemType; - -#define kUpb_LayoutItem_IndexSentinel ((uint16_t)-1) - -typedef struct { - // Index of the corresponding field. When this is a oneof field, the field's - // offset will be the index of the next field in a linked list. - uint16_t field_index; - uint16_t offset; - upb_FieldRep rep; - upb_LayoutItemType type; -} upb_LayoutItem; - -typedef struct { - upb_LayoutItem* data; - size_t size; - size_t capacity; -} upb_LayoutItemVector; +#define EXTREG_KEY_SIZE (sizeof(upb_MiniTable*) + sizeof(uint32_t)) -typedef struct { - upb_MdDecoder base; - upb_MiniTable* table; - upb_MiniTableField* fields; - upb_MiniTablePlatform platform; - upb_LayoutItemVector vec; +struct upb_ExtensionRegistry { upb_Arena* arena; -} upb_MtDecoder; - -// In each field's offset, we temporarily store a presence classifier: -enum PresenceClass { - kNoPresence = 0, - kHasbitPresence = 1, - kRequiredPresence = 2, - kOneofBase = 3, - // Negative values refer to a specific oneof with that number. Positive - // values >= kOneofBase indicate that this field is in a oneof, and specify - // the next field in this oneof's linked list. + upb_strtable exts; // Key is upb_MiniTable* concatenated with fieldnum. }; -static bool upb_MtDecoder_FieldIsPackable(upb_MiniTableField* field) { - return (field->UPB_PRIVATE(mode) & kUpb_FieldMode_Array) && - upb_FieldType_IsPackable(field->UPB_PRIVATE(descriptortype)); +static void extreg_key(char* buf, const upb_MiniTable* l, uint32_t fieldnum) { + memcpy(buf, &l, sizeof(l)); + memcpy(buf + sizeof(l), &fieldnum, sizeof(fieldnum)); } -typedef struct { - uint16_t submsg_count; - uint16_t subenum_count; -} upb_SubCounts; - -static void upb_MiniTable_SetTypeAndSub(upb_MiniTableField* field, - upb_FieldType type, - upb_SubCounts* sub_counts, - uint64_t msg_modifiers, - bool is_proto3_enum) { - if (is_proto3_enum) { - UPB_ASSERT(type == kUpb_FieldType_Enum); - type = kUpb_FieldType_Int32; - field->UPB_PRIVATE(mode) |= kUpb_LabelFlags_IsAlternate; - } else if (type == kUpb_FieldType_String && - !(msg_modifiers & kUpb_MessageModifier_ValidateUtf8)) { - type = kUpb_FieldType_Bytes; - field->UPB_PRIVATE(mode) |= kUpb_LabelFlags_IsAlternate; - } +upb_ExtensionRegistry* upb_ExtensionRegistry_New(upb_Arena* arena) { + upb_ExtensionRegistry* r = upb_Arena_Malloc(arena, sizeof(*r)); + if (!r) return NULL; + r->arena = arena; + if (!upb_strtable_init(&r->exts, 8, arena)) return NULL; + return r; +} - field->UPB_PRIVATE(descriptortype) = type; +UPB_API bool upb_ExtensionRegistry_Add(upb_ExtensionRegistry* r, + const upb_MiniTableExtension* e) { + char buf[EXTREG_KEY_SIZE]; + extreg_key(buf, e->UPB_PRIVATE(extendee), upb_MiniTableExtension_Number(e)); + if (upb_strtable_lookup2(&r->exts, buf, EXTREG_KEY_SIZE, NULL)) return false; + return upb_strtable_insert(&r->exts, buf, EXTREG_KEY_SIZE, + upb_value_constptr(e), r->arena); +} - if (upb_MtDecoder_FieldIsPackable(field) && - (msg_modifiers & kUpb_MessageModifier_DefaultIsPacked)) { - field->UPB_PRIVATE(mode) |= kUpb_LabelFlags_IsPacked; +bool upb_ExtensionRegistry_AddArray(upb_ExtensionRegistry* r, + const upb_MiniTableExtension** e, + size_t count) { + const upb_MiniTableExtension** start = e; + const upb_MiniTableExtension** end = UPB_PTRADD(e, count); + for (; e < end; e++) { + if (!upb_ExtensionRegistry_Add(r, *e)) goto failure; } + return true; - if (type == kUpb_FieldType_Message || type == kUpb_FieldType_Group) { - field->UPB_PRIVATE(submsg_index) = sub_counts->submsg_count++; - } else if (type == kUpb_FieldType_Enum) { - // We will need to update this later once we know the total number of - // submsg fields. - field->UPB_PRIVATE(submsg_index) = sub_counts->subenum_count++; - } else { - field->UPB_PRIVATE(submsg_index) = kUpb_NoSub; +failure: + // Back out the entries previously added. + for (end = e, e = start; e < end; e++) { + const upb_MiniTableExtension* ext = *e; + char buf[EXTREG_KEY_SIZE]; + extreg_key(buf, ext->UPB_PRIVATE(extendee), + upb_MiniTableExtension_Number(ext)); + upb_strtable_remove2(&r->exts, buf, EXTREG_KEY_SIZE, NULL); } + return false; } -static const char kUpb_EncodedToType[] = { - [kUpb_EncodedType_Double] = kUpb_FieldType_Double, - [kUpb_EncodedType_Float] = kUpb_FieldType_Float, - [kUpb_EncodedType_Int64] = kUpb_FieldType_Int64, - [kUpb_EncodedType_UInt64] = kUpb_FieldType_UInt64, - [kUpb_EncodedType_Int32] = kUpb_FieldType_Int32, - [kUpb_EncodedType_Fixed64] = kUpb_FieldType_Fixed64, - [kUpb_EncodedType_Fixed32] = kUpb_FieldType_Fixed32, - [kUpb_EncodedType_Bool] = kUpb_FieldType_Bool, - [kUpb_EncodedType_String] = kUpb_FieldType_String, - [kUpb_EncodedType_Group] = kUpb_FieldType_Group, - [kUpb_EncodedType_Message] = kUpb_FieldType_Message, - [kUpb_EncodedType_Bytes] = kUpb_FieldType_Bytes, - [kUpb_EncodedType_UInt32] = kUpb_FieldType_UInt32, - [kUpb_EncodedType_OpenEnum] = kUpb_FieldType_Enum, - [kUpb_EncodedType_SFixed32] = kUpb_FieldType_SFixed32, - [kUpb_EncodedType_SFixed64] = kUpb_FieldType_SFixed64, - [kUpb_EncodedType_SInt32] = kUpb_FieldType_SInt32, - [kUpb_EncodedType_SInt64] = kUpb_FieldType_SInt64, - [kUpb_EncodedType_ClosedEnum] = kUpb_FieldType_Enum, -}; - -static void upb_MiniTable_SetField(upb_MtDecoder* d, uint8_t ch, - upb_MiniTableField* field, - uint64_t msg_modifiers, - upb_SubCounts* sub_counts) { - static const char kUpb_EncodedToFieldRep[] = { - [kUpb_EncodedType_Double] = kUpb_FieldRep_8Byte, - [kUpb_EncodedType_Float] = kUpb_FieldRep_4Byte, - [kUpb_EncodedType_Int64] = kUpb_FieldRep_8Byte, - [kUpb_EncodedType_UInt64] = kUpb_FieldRep_8Byte, - [kUpb_EncodedType_Int32] = kUpb_FieldRep_4Byte, - [kUpb_EncodedType_Fixed64] = kUpb_FieldRep_8Byte, - [kUpb_EncodedType_Fixed32] = kUpb_FieldRep_4Byte, - [kUpb_EncodedType_Bool] = kUpb_FieldRep_1Byte, - [kUpb_EncodedType_String] = kUpb_FieldRep_StringView, - [kUpb_EncodedType_Bytes] = kUpb_FieldRep_StringView, - [kUpb_EncodedType_UInt32] = kUpb_FieldRep_4Byte, - [kUpb_EncodedType_OpenEnum] = kUpb_FieldRep_4Byte, - [kUpb_EncodedType_SFixed32] = kUpb_FieldRep_4Byte, - [kUpb_EncodedType_SFixed64] = kUpb_FieldRep_8Byte, - [kUpb_EncodedType_SInt32] = kUpb_FieldRep_4Byte, - [kUpb_EncodedType_SInt64] = kUpb_FieldRep_8Byte, - [kUpb_EncodedType_ClosedEnum] = kUpb_FieldRep_4Byte, - }; - - char pointer_rep = d->platform == kUpb_MiniTablePlatform_32Bit - ? kUpb_FieldRep_4Byte - : kUpb_FieldRep_8Byte; - - int8_t type = _upb_FromBase92(ch); - if (ch >= _upb_ToBase92(kUpb_EncodedType_RepeatedBase)) { - type -= kUpb_EncodedType_RepeatedBase; - field->UPB_PRIVATE(mode) = kUpb_FieldMode_Array; - field->UPB_PRIVATE(mode) |= pointer_rep << kUpb_FieldRep_Shift; - field->UPB_PRIVATE(offset) = kNoPresence; +const upb_MiniTableExtension* upb_ExtensionRegistry_Lookup( + const upb_ExtensionRegistry* r, const upb_MiniTable* t, uint32_t num) { + char buf[EXTREG_KEY_SIZE]; + upb_value v; + extreg_key(buf, t, num); + if (upb_strtable_lookup2(&r->exts, buf, EXTREG_KEY_SIZE, &v)) { + return upb_value_getconstptr(v); } else { - field->UPB_PRIVATE(mode) = kUpb_FieldMode_Scalar; - field->UPB_PRIVATE(offset) = kHasbitPresence; - if (type == kUpb_EncodedType_Group || type == kUpb_EncodedType_Message) { - field->UPB_PRIVATE(mode) |= pointer_rep << kUpb_FieldRep_Shift; - } else if ((unsigned long)type >= sizeof(kUpb_EncodedToFieldRep)) { - upb_MdDecoder_ErrorJmp(&d->base, "Invalid field type: %d", (int)type); - } else { - field->UPB_PRIVATE(mode) |= kUpb_EncodedToFieldRep[type] - << kUpb_FieldRep_Shift; - } - } - if ((unsigned long)type >= sizeof(kUpb_EncodedToType)) { - upb_MdDecoder_ErrorJmp(&d->base, "Invalid field type: %d", (int)type); + return NULL; } - upb_MiniTable_SetTypeAndSub(field, kUpb_EncodedToType[type], sub_counts, - msg_modifiers, type == kUpb_EncodedType_OpenEnum); } -static void upb_MtDecoder_ModifyField(upb_MtDecoder* d, - uint32_t message_modifiers, - uint32_t field_modifiers, - upb_MiniTableField* field) { - if (field_modifiers & kUpb_EncodedFieldModifier_FlipPacked) { - if (!upb_MtDecoder_FieldIsPackable(field)) { - upb_MdDecoder_ErrorJmp(&d->base, - "Cannot flip packed on unpackable field %" PRIu32, - upb_MiniTableField_Number(field)); - } - field->UPB_PRIVATE(mode) ^= kUpb_LabelFlags_IsPacked; - } - if (field_modifiers & kUpb_EncodedFieldModifier_FlipValidateUtf8) { - if (field->UPB_PRIVATE(descriptortype) != kUpb_FieldType_Bytes || - !(field->UPB_PRIVATE(mode) & kUpb_LabelFlags_IsAlternate)) { - upb_MdDecoder_ErrorJmp(&d->base, - "Cannot flip ValidateUtf8 on field %" PRIu32 - ", type=%d, mode=%d", - upb_MiniTableField_Number(field), - (int)field->UPB_PRIVATE(descriptortype), - (int)field->UPB_PRIVATE(mode)); - } - field->UPB_PRIVATE(descriptortype) = kUpb_FieldType_String; - field->UPB_PRIVATE(mode) &= ~kUpb_LabelFlags_IsAlternate; - } +#include +#include +#include - bool singular = field_modifiers & kUpb_EncodedFieldModifier_IsProto3Singular; - bool required = field_modifiers & kUpb_EncodedFieldModifier_IsRequired; - // Validate. - if ((singular || required) && field->UPB_PRIVATE(offset) != kHasbitPresence) { - upb_MdDecoder_ErrorJmp(&d->base, - "Invalid modifier(s) for repeated field %" PRIu32, - upb_MiniTableField_Number(field)); - } - if (singular && required) { - upb_MdDecoder_ErrorJmp( - &d->base, "Field %" PRIu32 " cannot be both singular and required", - upb_MiniTableField_Number(field)); +// Must be last. + +const upb_MiniTableField* upb_MiniTable_FindFieldByNumber( + const upb_MiniTable* m, uint32_t number) { + const size_t i = ((size_t)number) - 1; // 0 wraps to SIZE_MAX + + // Ideal case: index into dense fields + if (i < m->UPB_PRIVATE(dense_below)) { + UPB_ASSERT(m->UPB_PRIVATE(fields)[i].UPB_PRIVATE(number) == number); + return &m->UPB_PRIVATE(fields)[i]; } - if (singular) field->UPB_PRIVATE(offset) = kNoPresence; - if (required) { - field->UPB_PRIVATE(offset) = kRequiredPresence; + // Slow case: binary search + int lo = m->UPB_PRIVATE(dense_below); + int hi = m->UPB_PRIVATE(field_count) - 1; + while (lo <= hi) { + int mid = (lo + hi) / 2; + uint32_t num = m->UPB_PRIVATE(fields)[mid].UPB_PRIVATE(number); + if (num < number) { + lo = mid + 1; + continue; + } + if (num > number) { + hi = mid - 1; + continue; + } + return &m->UPB_PRIVATE(fields)[mid]; } + return NULL; } -static void upb_MtDecoder_PushItem(upb_MtDecoder* d, upb_LayoutItem item) { - if (d->vec.size == d->vec.capacity) { - size_t new_cap = UPB_MAX(8, d->vec.size * 2); - d->vec.data = realloc(d->vec.data, new_cap * sizeof(*d->vec.data)); - upb_MdDecoder_CheckOutOfMemory(&d->base, d->vec.data); - d->vec.capacity = new_cap; +const upb_MiniTableField* upb_MiniTable_GetOneof(const upb_MiniTable* m, + const upb_MiniTableField* f) { + if (UPB_UNLIKELY(!upb_MiniTableField_IsInOneof(f))) { + return NULL; } - d->vec.data[d->vec.size++] = item; + const upb_MiniTableField* ptr = &m->UPB_PRIVATE(fields)[0]; + const upb_MiniTableField* end = + &m->UPB_PRIVATE(fields)[m->UPB_PRIVATE(field_count)]; + for (; ptr < end; ptr++) { + if (ptr->presence == (*f).presence) { + return ptr; + } + } + return NULL; } -static void upb_MtDecoder_PushOneof(upb_MtDecoder* d, upb_LayoutItem item) { - if (item.field_index == kUpb_LayoutItem_IndexSentinel) { - upb_MdDecoder_ErrorJmp(&d->base, "Empty oneof"); +bool upb_MiniTable_NextOneofField(const upb_MiniTable* m, + const upb_MiniTableField** f) { + const upb_MiniTableField* ptr = *f; + const upb_MiniTableField* end = + &m->UPB_PRIVATE(fields)[m->UPB_PRIVATE(field_count)]; + while (++ptr < end) { + if (ptr->presence == (*f)->presence) { + *f = ptr; + return true; + } } - item.field_index -= kOneofBase; + return false; +} - // Push oneof data. - item.type = kUpb_LayoutItemType_OneofField; - upb_MtDecoder_PushItem(d, item); - // Push oneof case. - item.rep = kUpb_FieldRep_4Byte; // Field Number. - item.type = kUpb_LayoutItemType_OneofCase; - upb_MtDecoder_PushItem(d, item); -} +#include +#include -size_t upb_MtDecoder_SizeOfRep(upb_FieldRep rep, - upb_MiniTablePlatform platform) { - static const uint8_t kRepToSize32[] = { - [kUpb_FieldRep_1Byte] = 1, - [kUpb_FieldRep_4Byte] = 4, - [kUpb_FieldRep_StringView] = 8, - [kUpb_FieldRep_8Byte] = 8, - }; - static const uint8_t kRepToSize64[] = { - [kUpb_FieldRep_1Byte] = 1, - [kUpb_FieldRep_4Byte] = 4, - [kUpb_FieldRep_StringView] = 16, - [kUpb_FieldRep_8Byte] = 8, - }; - UPB_ASSERT(sizeof(upb_StringView) == - UPB_SIZE(kRepToSize32, kRepToSize64)[kUpb_FieldRep_StringView]); - return platform == kUpb_MiniTablePlatform_32Bit ? kRepToSize32[rep] - : kRepToSize64[rep]; -} -size_t upb_MtDecoder_AlignOfRep(upb_FieldRep rep, - upb_MiniTablePlatform platform) { - static const uint8_t kRepToAlign32[] = { - [kUpb_FieldRep_1Byte] = 1, - [kUpb_FieldRep_4Byte] = 4, - [kUpb_FieldRep_StringView] = 4, - [kUpb_FieldRep_8Byte] = 8, - }; - static const uint8_t kRepToAlign64[] = { - [kUpb_FieldRep_1Byte] = 1, - [kUpb_FieldRep_4Byte] = 4, - [kUpb_FieldRep_StringView] = 8, - [kUpb_FieldRep_8Byte] = 8, - }; - UPB_ASSERT(UPB_ALIGN_OF(upb_StringView) == - UPB_SIZE(kRepToAlign32, kRepToAlign64)[kUpb_FieldRep_StringView]); - return platform == kUpb_MiniTablePlatform_32Bit ? kRepToAlign32[rep] - : kRepToAlign64[rep]; -} +// Must be last. -static const char* upb_MtDecoder_DecodeOneofField(upb_MtDecoder* d, - const char* ptr, - char first_ch, - upb_LayoutItem* item) { - uint32_t field_num; - ptr = upb_MdDecoder_DecodeBase92Varint( - &d->base, ptr, first_ch, kUpb_EncodedValue_MinOneofField, - kUpb_EncodedValue_MaxOneofField, &field_num); - upb_MiniTableField* f = - (void*)upb_MiniTable_FindFieldByNumber(d->table, field_num); +// Checks if source and target mini table fields are identical. +// +// If the field is a sub message and sub messages are identical we record +// the association in table. +// +// Hashing the source sub message mini table and it's equivalent in the table +// stops recursing when a cycle is detected and instead just checks if the +// destination table is equal. +static upb_MiniTableEquals_Status upb_deep_check(const upb_MiniTable* src, + const upb_MiniTable* dst, + upb_inttable* table, + upb_Arena** arena) { + if (src->UPB_PRIVATE(field_count) != dst->UPB_PRIVATE(field_count)) + return kUpb_MiniTableEquals_NotEqual; + bool marked_src = false; + for (int i = 0; i < upb_MiniTable_FieldCount(src); i++) { + const upb_MiniTableField* src_field = upb_MiniTable_GetFieldByIndex(src, i); + const upb_MiniTableField* dst_field = upb_MiniTable_FindFieldByNumber( + dst, upb_MiniTableField_Number(src_field)); - if (!f) { - upb_MdDecoder_ErrorJmp(&d->base, - "Couldn't add field number %" PRIu32 - " to oneof, no such field number.", - field_num); - } - if (f->UPB_PRIVATE(offset) != kHasbitPresence) { - upb_MdDecoder_ErrorJmp( - &d->base, - "Cannot add repeated, required, or singular field %" PRIu32 - " to oneof.", - field_num); - } + if (upb_MiniTableField_CType(src_field) != + upb_MiniTableField_CType(dst_field)) + return false; + if (src_field->UPB_PRIVATE(mode) != dst_field->UPB_PRIVATE(mode)) + return false; + if (src_field->UPB_PRIVATE(offset) != dst_field->UPB_PRIVATE(offset)) + return false; + if (src_field->presence != dst_field->presence) return false; + if (src_field->UPB_PRIVATE(submsg_index) != + dst_field->UPB_PRIVATE(submsg_index)) + return kUpb_MiniTableEquals_NotEqual; - // Oneof storage must be large enough to accommodate the largest member. - int rep = f->UPB_PRIVATE(mode) >> kUpb_FieldRep_Shift; - if (upb_MtDecoder_SizeOfRep(rep, d->platform) > - upb_MtDecoder_SizeOfRep(item->rep, d->platform)) { - item->rep = rep; - } - // Prepend this field to the linked list. - f->UPB_PRIVATE(offset) = item->field_index; - item->field_index = (f - d->fields) + kOneofBase; - return ptr; -} + // Go no further if we are only checking for compatibility. + if (!table) continue; -static const char* upb_MtDecoder_DecodeOneofs(upb_MtDecoder* d, - const char* ptr) { - upb_LayoutItem item = {.rep = 0, - .field_index = kUpb_LayoutItem_IndexSentinel}; - while (ptr < d->base.end) { - char ch = *ptr++; - if (ch == kUpb_EncodedValue_FieldSeparator) { - // Field separator, no action needed. - } else if (ch == kUpb_EncodedValue_OneofSeparator) { - // End of oneof. - upb_MtDecoder_PushOneof(d, item); - item.field_index = kUpb_LayoutItem_IndexSentinel; // Move to next oneof. - } else { - ptr = upb_MtDecoder_DecodeOneofField(d, ptr, ch, &item); + if (upb_MiniTableField_CType(src_field) == kUpb_CType_Message) { + if (!*arena) { + *arena = upb_Arena_New(); + if (!upb_inttable_init(table, *arena)) { + return kUpb_MiniTableEquals_OutOfMemory; + } + } + if (!marked_src) { + marked_src = true; + upb_value val; + val.val = (uint64_t)dst; + if (!upb_inttable_insert(table, (uintptr_t)src, val, *arena)) { + return kUpb_MiniTableEquals_OutOfMemory; + } + } + const upb_MiniTable* sub_src = + upb_MiniTable_GetSubMessageTable(src, src_field); + const upb_MiniTable* sub_dst = + upb_MiniTable_GetSubMessageTable(dst, dst_field); + if (sub_src != NULL) { + upb_value cmp; + if (upb_inttable_lookup(table, (uintptr_t)sub_src, &cmp)) { + // We already compared this src before. Check if same dst. + if (cmp.val != (uint64_t)sub_dst) { + return kUpb_MiniTableEquals_NotEqual; + } + } else { + // Recurse if not already visited. + upb_MiniTableEquals_Status s = + upb_deep_check(sub_src, sub_dst, table, arena); + if (s != kUpb_MiniTableEquals_Equal) { + return s; + } + } + } } } - - // Push final oneof. - upb_MtDecoder_PushOneof(d, item); - return ptr; + return kUpb_MiniTableEquals_Equal; } -static const char* upb_MtDecoder_ParseModifier(upb_MtDecoder* d, - const char* ptr, char first_ch, - upb_MiniTableField* last_field, - uint64_t* msg_modifiers) { - uint32_t mod; - ptr = upb_MdDecoder_DecodeBase92Varint(&d->base, ptr, first_ch, - kUpb_EncodedValue_MinModifier, - kUpb_EncodedValue_MaxModifier, &mod); - if (last_field) { - upb_MtDecoder_ModifyField(d, *msg_modifiers, mod, last_field); - } else { - if (!d->table) { - upb_MdDecoder_ErrorJmp(&d->base, - "Extensions cannot have message modifiers"); - } - *msg_modifiers = mod; - } - - return ptr; +bool upb_MiniTable_Compatible(const upb_MiniTable* src, + const upb_MiniTable* dst) { + return upb_deep_check(src, dst, NULL, NULL); } -static void upb_MtDecoder_AllocateSubs(upb_MtDecoder* d, - upb_SubCounts sub_counts) { - uint32_t total_count = sub_counts.submsg_count + sub_counts.subenum_count; - size_t subs_bytes = sizeof(*d->table->UPB_PRIVATE(subs)) * total_count; - upb_MiniTableSub* subs = upb_Arena_Malloc(d->arena, subs_bytes); - upb_MdDecoder_CheckOutOfMemory(&d->base, subs); - uint32_t i = 0; - for (; i < sub_counts.submsg_count; i++) { - subs[i].UPB_PRIVATE(submsg) = UPB_PRIVATE(_upb_MiniTable_Empty)(); - } - if (sub_counts.subenum_count) { - upb_MiniTableField* f = d->fields; - upb_MiniTableField* end_f = f + d->table->UPB_PRIVATE(field_count); - for (; f < end_f; f++) { - if (f->UPB_PRIVATE(descriptortype) == kUpb_FieldType_Enum) { - f->UPB_PRIVATE(submsg_index) += sub_counts.submsg_count; - } - } - for (; i < sub_counts.submsg_count + sub_counts.subenum_count; i++) { - subs[i].UPB_PRIVATE(subenum) = NULL; - } +upb_MiniTableEquals_Status upb_MiniTable_Equals(const upb_MiniTable* src, + const upb_MiniTable* dst) { + // Arena allocated on demand for hash table. + upb_Arena* arena = NULL; + // Table to keep track of visited mini tables to guard against cycles. + upb_inttable table; + upb_MiniTableEquals_Status status = upb_deep_check(src, dst, &table, &arena); + if (arena) { + upb_Arena_Free(arena); } - d->table->UPB_PRIVATE(subs) = subs; + return status; } -static const char* upb_MtDecoder_Parse(upb_MtDecoder* d, const char* ptr, - size_t len, void* fields, - size_t field_size, uint16_t* field_count, - upb_SubCounts* sub_counts) { - uint64_t msg_modifiers = 0; - uint32_t last_field_number = 0; - upb_MiniTableField* last_field = NULL; - bool need_dense_below = d->table != NULL; - d->base.end = UPB_PTRADD(ptr, len); +#include +#include +#include +#include +#include - while (ptr < d->base.end) { - char ch = *ptr++; - if (ch <= kUpb_EncodedValue_MaxField) { - if (!d->table && last_field) { - // For extensions, consume only a single field and then return. - return --ptr; - } - upb_MiniTableField* field = fields; - *field_count += 1; - fields = (char*)fields + field_size; - field->UPB_PRIVATE(number) = ++last_field_number; - last_field = field; - upb_MiniTable_SetField(d, ch, field, msg_modifiers, sub_counts); - } else if (kUpb_EncodedValue_MinModifier <= ch && - ch <= kUpb_EncodedValue_MaxModifier) { - ptr = upb_MtDecoder_ParseModifier(d, ptr, ch, last_field, &msg_modifiers); - if (msg_modifiers & kUpb_MessageModifier_IsExtendable) { - d->table->UPB_PRIVATE(ext) |= kUpb_ExtMode_Extendable; - } - } else if (ch == kUpb_EncodedValue_End) { - if (!d->table) { - upb_MdDecoder_ErrorJmp(&d->base, "Extensions cannot have oneofs."); - } - ptr = upb_MtDecoder_DecodeOneofs(d, ptr); - } else if (kUpb_EncodedValue_MinSkip <= ch && - ch <= kUpb_EncodedValue_MaxSkip) { - if (need_dense_below) { - d->table->UPB_PRIVATE(dense_below) = d->table->UPB_PRIVATE(field_count); - need_dense_below = false; - } - uint32_t skip; - ptr = upb_MdDecoder_DecodeBase92Varint(&d->base, ptr, ch, - kUpb_EncodedValue_MinSkip, - kUpb_EncodedValue_MaxSkip, &skip); - last_field_number += skip; - last_field_number--; // Next field seen will increment. - } else { - upb_MdDecoder_ErrorJmp(&d->base, "Invalid char: %c", ch); - } - } - if (need_dense_below) { - d->table->UPB_PRIVATE(dense_below) = d->table->UPB_PRIVATE(field_count); - } +// Must be last. - return ptr; -} +// A few fake field types for our tables. +enum { + kUpb_FakeFieldType_FieldNotFound = 0, + kUpb_FakeFieldType_MessageSetItem = 19, +}; -static void upb_MtDecoder_ParseMessage(upb_MtDecoder* d, const char* data, - size_t len) { - // Buffer length is an upper bound on the number of fields. We will return - // what we don't use. - d->fields = upb_Arena_Malloc(d->arena, sizeof(*d->fields) * len); - upb_MdDecoder_CheckOutOfMemory(&d->base, d->fields); +// DecodeOp: an action to be performed for a wire-type/field-type combination. +enum { + // Special ops: we don't write data to regular fields for these. + kUpb_DecodeOp_UnknownField = -1, + kUpb_DecodeOp_MessageSetItem = -2, - upb_SubCounts sub_counts = {0, 0}; - d->table->UPB_PRIVATE(field_count) = 0; - d->table->UPB_PRIVATE(fields) = d->fields; - upb_MtDecoder_Parse(d, data, len, d->fields, sizeof(*d->fields), - &d->table->UPB_PRIVATE(field_count), &sub_counts); + // Scalar-only ops. + kUpb_DecodeOp_Scalar1Byte = 0, + kUpb_DecodeOp_Scalar4Byte = 2, + kUpb_DecodeOp_Scalar8Byte = 3, + kUpb_DecodeOp_Enum = 1, - upb_Arena_ShrinkLast(d->arena, d->fields, sizeof(*d->fields) * len, - sizeof(*d->fields) * d->table->UPB_PRIVATE(field_count)); - d->table->UPB_PRIVATE(fields) = d->fields; - upb_MtDecoder_AllocateSubs(d, sub_counts); -} + // Scalar/repeated ops. + kUpb_DecodeOp_String = 4, + kUpb_DecodeOp_Bytes = 5, + kUpb_DecodeOp_SubMessage = 6, -int upb_MtDecoder_CompareFields(const void* _a, const void* _b) { - const upb_LayoutItem* a = _a; - const upb_LayoutItem* b = _b; - // Currently we just sort by: - // 1. rep (smallest fields first) - // 2. type (oneof cases first) - // 2. field_index (smallest numbers first) - // The main goal of this is to reduce space lost to padding. - // Later we may have more subtle reasons to prefer a different ordering. - const int rep_bits = upb_Log2Ceiling(kUpb_FieldRep_Max); - const int type_bits = upb_Log2Ceiling(kUpb_LayoutItemType_Max); - const int idx_bits = (sizeof(a->field_index) * 8); - UPB_ASSERT(idx_bits + rep_bits + type_bits < 32); -#define UPB_COMBINE(rep, ty, idx) (((rep << type_bits) | ty) << idx_bits) | idx - uint32_t a_packed = UPB_COMBINE(a->rep, a->type, a->field_index); - uint32_t b_packed = UPB_COMBINE(b->rep, b->type, b->field_index); - UPB_ASSERT(a_packed != b_packed); -#undef UPB_COMBINE - return a_packed < b_packed ? -1 : 1; -} + // Repeated-only ops (also see macros below). + kUpb_DecodeOp_PackedEnum = 13, +}; -static bool upb_MtDecoder_SortLayoutItems(upb_MtDecoder* d) { - // Add items for all non-oneof fields (oneofs were already added). - int n = d->table->UPB_PRIVATE(field_count); - for (int i = 0; i < n; i++) { - upb_MiniTableField* f = &d->fields[i]; - if (f->UPB_PRIVATE(offset) >= kOneofBase) continue; - upb_LayoutItem item = {.field_index = i, - .rep = f->UPB_PRIVATE(mode) >> kUpb_FieldRep_Shift, - .type = kUpb_LayoutItemType_Field}; - upb_MtDecoder_PushItem(d, item); - } +// For packed fields it is helpful to be able to recover the lg2 of the data +// size from the op. +#define OP_FIXPCK_LG2(n) (n + 5) /* n in [2, 3] => op in [7, 8] */ +#define OP_VARPCK_LG2(n) (n + 9) /* n in [0, 2, 3] => op in [9, 11, 12] */ - if (d->vec.size) { - qsort(d->vec.data, d->vec.size, sizeof(*d->vec.data), - upb_MtDecoder_CompareFields); - } +typedef union { + bool bool_val; + uint32_t uint32_val; + uint64_t uint64_val; + uint32_t size; +} wireval; - return true; +// Ideally these two functions should take the owning MiniTable pointer as a +// first argument, then we could just put them in mini_table/message.h as nice +// clean getters. But we don't have that so instead we gotta write these +// Frankenfunctions that take an array of subtables. +// TODO: Move these to mini_table/ anyway since there are other places +// that could use them. + +// Returns the MiniTable corresponding to a given MiniTableField +// from an array of MiniTableSubs. +static const upb_MiniTable* _upb_MiniTableSubs_MessageByField( + const upb_MiniTableSub* subs, const upb_MiniTableField* field) { + return upb_MiniTableSub_Message(subs[field->UPB_PRIVATE(submsg_index)]); } -static size_t upb_MiniTable_DivideRoundUp(size_t n, size_t d) { - return (n + d - 1) / d; +// Returns the MiniTableEnum corresponding to a given MiniTableField +// from an array of MiniTableSub. +static const upb_MiniTableEnum* _upb_MiniTableSubs_EnumByField( + const upb_MiniTableSub* subs, const upb_MiniTableField* field) { + return upb_MiniTableSub_Enum(subs[field->UPB_PRIVATE(submsg_index)]); } -static void upb_MtDecoder_AssignHasbits(upb_MtDecoder* d) { - upb_MiniTable* ret = d->table; - int n = ret->UPB_PRIVATE(field_count); - int last_hasbit = 0; // 0 cannot be used. +static const char* _upb_Decoder_DecodeMessage(upb_Decoder* d, const char* ptr, + upb_Message* msg, + const upb_MiniTable* layout); - // First assign required fields, which must have the lowest hasbits. - for (int i = 0; i < n; i++) { - upb_MiniTableField* field = - (upb_MiniTableField*)&ret->UPB_PRIVATE(fields)[i]; - if (field->UPB_PRIVATE(offset) == kRequiredPresence) { - field->presence = ++last_hasbit; - } else if (field->UPB_PRIVATE(offset) == kNoPresence) { - field->presence = 0; - } - } - if (last_hasbit > 63) { - upb_MdDecoder_ErrorJmp(&d->base, "Too many required fields"); - } +UPB_NORETURN static void* _upb_Decoder_ErrorJmp(upb_Decoder* d, + upb_DecodeStatus status) { + UPB_ASSERT(status != kUpb_DecodeStatus_Ok); + d->status = status; + UPB_LONGJMP(d->err, 1); +} - ret->UPB_PRIVATE(required_count) = last_hasbit; +const char* _upb_FastDecoder_ErrorJmp(upb_Decoder* d, int status) { + UPB_ASSERT(status != kUpb_DecodeStatus_Ok); + d->status = status; + UPB_LONGJMP(d->err, 1); + return NULL; +} - // Next assign non-required hasbit fields. - for (int i = 0; i < n; i++) { - upb_MiniTableField* field = - (upb_MiniTableField*)&ret->UPB_PRIVATE(fields)[i]; - if (field->UPB_PRIVATE(offset) == kHasbitPresence) { - field->presence = ++last_hasbit; - } +static void _upb_Decoder_VerifyUtf8(upb_Decoder* d, const char* buf, int len) { + if (!_upb_Decoder_VerifyUtf8Inline(buf, len)) { + _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_BadUtf8); } - - ret->UPB_PRIVATE(size) = - last_hasbit ? upb_MiniTable_DivideRoundUp(last_hasbit + 1, 8) : 0; } -size_t upb_MtDecoder_Place(upb_MtDecoder* d, upb_FieldRep rep) { - size_t size = upb_MtDecoder_SizeOfRep(rep, d->platform); - size_t align = upb_MtDecoder_AlignOfRep(rep, d->platform); - size_t ret = UPB_ALIGN_UP(d->table->UPB_PRIVATE(size), align); - static const size_t max = UINT16_MAX; - size_t new_size = ret + size; - if (new_size > max) { - upb_MdDecoder_ErrorJmp( - &d->base, "Message size exceeded maximum size of %zu bytes", max); +static bool _upb_Decoder_Reserve(upb_Decoder* d, upb_Array* arr, size_t elem) { + bool need_realloc = + arr->UPB_PRIVATE(capacity) - arr->UPB_PRIVATE(size) < elem; + if (need_realloc && !UPB_PRIVATE(_upb_Array_Realloc)( + arr, arr->UPB_PRIVATE(size) + elem, &d->arena)) { + _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_OutOfMemory); } - d->table->UPB_PRIVATE(size) = new_size; - return ret; + return need_realloc; } -static void upb_MtDecoder_AssignOffsets(upb_MtDecoder* d) { - upb_LayoutItem* end = UPB_PTRADD(d->vec.data, d->vec.size); +typedef struct { + const char* ptr; + uint64_t val; +} _upb_DecodeLongVarintReturn; - // Compute offsets. - for (upb_LayoutItem* item = d->vec.data; item < end; item++) { - item->offset = upb_MtDecoder_Place(d, item->rep); +UPB_NOINLINE +static _upb_DecodeLongVarintReturn _upb_Decoder_DecodeLongVarint( + const char* ptr, uint64_t val) { + _upb_DecodeLongVarintReturn ret = {NULL, 0}; + uint64_t byte; + int i; + for (i = 1; i < 10; i++) { + byte = (uint8_t)ptr[i]; + val += (byte - 1) << (i * 7); + if (!(byte & 0x80)) { + ret.ptr = ptr + i + 1; + ret.val = val; + return ret; + } } + return ret; +} - // Assign oneof case offsets. We must do these first, since assigning - // actual offsets will overwrite the links of the linked list. - for (upb_LayoutItem* item = d->vec.data; item < end; item++) { - if (item->type != kUpb_LayoutItemType_OneofCase) continue; - upb_MiniTableField* f = &d->fields[item->field_index]; - while (true) { - f->presence = ~item->offset; - if (f->UPB_PRIVATE(offset) == kUpb_LayoutItem_IndexSentinel) break; - UPB_ASSERT(f->UPB_PRIVATE(offset) - kOneofBase < - d->table->UPB_PRIVATE(field_count)); - f = &d->fields[f->UPB_PRIVATE(offset) - kOneofBase]; - } +UPB_FORCEINLINE +static const char* _upb_Decoder_DecodeVarint(upb_Decoder* d, const char* ptr, + uint64_t* val) { + uint64_t byte = (uint8_t)*ptr; + if (UPB_LIKELY((byte & 0x80) == 0)) { + *val = byte; + return ptr + 1; + } else { + _upb_DecodeLongVarintReturn res = _upb_Decoder_DecodeLongVarint(ptr, byte); + if (!res.ptr) _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_Malformed); + *val = res.val; + return res.ptr; } +} - // Assign offsets. - for (upb_LayoutItem* item = d->vec.data; item < end; item++) { - upb_MiniTableField* f = &d->fields[item->field_index]; - switch (item->type) { - case kUpb_LayoutItemType_OneofField: - while (true) { - uint16_t next_offset = f->UPB_PRIVATE(offset); - f->UPB_PRIVATE(offset) = item->offset; - if (next_offset == kUpb_LayoutItem_IndexSentinel) break; - f = &d->fields[next_offset - kOneofBase]; - } - break; - case kUpb_LayoutItemType_Field: - f->UPB_PRIVATE(offset) = item->offset; - break; - default: - break; +UPB_FORCEINLINE +static const char* _upb_Decoder_DecodeTag(upb_Decoder* d, const char* ptr, + uint32_t* val) { + uint64_t byte = (uint8_t)*ptr; + if (UPB_LIKELY((byte & 0x80) == 0)) { + *val = byte; + return ptr + 1; + } else { + const char* start = ptr; + _upb_DecodeLongVarintReturn res = _upb_Decoder_DecodeLongVarint(ptr, byte); + if (!res.ptr || res.ptr - start > 5 || res.val > UINT32_MAX) { + _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_Malformed); } + *val = res.val; + return res.ptr; } - - // The fasttable parser (supported on 64-bit only) depends on this being a - // multiple of 8 in order to satisfy UPB_MALLOC_ALIGN, which is also 8. - // - // On 32-bit we could potentially make this smaller, but there is no - // compelling reason to optimize this right now. - d->table->UPB_PRIVATE(size) = UPB_ALIGN_UP(d->table->UPB_PRIVATE(size), 8); } -static void upb_MtDecoder_ValidateEntryField(upb_MtDecoder* d, - const upb_MiniTableField* f, - uint32_t expected_num) { - const char* name = expected_num == 1 ? "key" : "val"; - const uint32_t f_number = upb_MiniTableField_Number(f); - if (f_number != expected_num) { - upb_MdDecoder_ErrorJmp(&d->base, - "map %s did not have expected number (%d vs %d)", - name, expected_num, f_number); +UPB_FORCEINLINE +static const char* upb_Decoder_DecodeSize(upb_Decoder* d, const char* ptr, + uint32_t* size) { + uint64_t size64; + ptr = _upb_Decoder_DecodeVarint(d, ptr, &size64); + if (size64 >= INT32_MAX || + !upb_EpsCopyInputStream_CheckSize(&d->input, ptr, (int)size64)) { + _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_Malformed); } + *size = size64; + return ptr; +} - if (!upb_MiniTableField_IsScalar(f)) { - upb_MdDecoder_ErrorJmp( - &d->base, "map %s cannot be repeated or map, or be in oneof", name); +static void _upb_Decoder_MungeInt32(wireval* val) { + if (!UPB_PRIVATE(_upb_IsLittleEndian)()) { + /* The next stage will memcpy(dst, &val, 4) */ + val->uint32_val = val->uint64_val; } +} - uint32_t not_ok_types; - if (expected_num == 1) { - not_ok_types = (1 << kUpb_FieldType_Float) | (1 << kUpb_FieldType_Double) | - (1 << kUpb_FieldType_Message) | (1 << kUpb_FieldType_Group) | - (1 << kUpb_FieldType_Bytes) | (1 << kUpb_FieldType_Enum); - } else { - not_ok_types = 1 << kUpb_FieldType_Group; - } - - if ((1 << upb_MiniTableField_Type(f)) & not_ok_types) { - upb_MdDecoder_ErrorJmp(&d->base, "map %s cannot have type %d", name, - (int)f->UPB_PRIVATE(descriptortype)); +static void _upb_Decoder_Munge(int type, wireval* val) { + switch (type) { + case kUpb_FieldType_Bool: + val->bool_val = val->uint64_val != 0; + break; + case kUpb_FieldType_SInt32: { + uint32_t n = val->uint64_val; + val->uint32_val = (n >> 1) ^ -(int32_t)(n & 1); + break; + } + case kUpb_FieldType_SInt64: { + uint64_t n = val->uint64_val; + val->uint64_val = (n >> 1) ^ -(int64_t)(n & 1); + break; + } + case kUpb_FieldType_Int32: + case kUpb_FieldType_UInt32: + case kUpb_FieldType_Enum: + _upb_Decoder_MungeInt32(val); + break; } } -static void upb_MtDecoder_ParseMap(upb_MtDecoder* d, const char* data, - size_t len) { - upb_MtDecoder_ParseMessage(d, data, len); - upb_MtDecoder_AssignHasbits(d); +static upb_Message* _upb_Decoder_NewSubMessage(upb_Decoder* d, + const upb_MiniTableSub* subs, + const upb_MiniTableField* field, + upb_TaggedMessagePtr* target) { + const upb_MiniTable* subl = _upb_MiniTableSubs_MessageByField(subs, field); + UPB_ASSERT(subl); + upb_Message* msg = _upb_Message_New(subl, &d->arena); + if (!msg) _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_OutOfMemory); - if (UPB_UNLIKELY(d->table->UPB_PRIVATE(field_count) != 2)) { - upb_MdDecoder_ErrorJmp(&d->base, "%hu fields in map", - d->table->UPB_PRIVATE(field_count)); - UPB_UNREACHABLE(); - } + // Extensions should not be unlinked. A message extension should not be + // registered until its sub-message type is available to be linked. + bool is_empty = UPB_PRIVATE(_upb_MiniTable_IsEmpty)(subl); + bool is_extension = field->UPB_PRIVATE(mode) & kUpb_LabelFlags_IsExtension; + UPB_ASSERT(!(is_empty && is_extension)); - upb_LayoutItem* end = UPB_PTRADD(d->vec.data, d->vec.size); - for (upb_LayoutItem* item = d->vec.data; item < end; item++) { - if (item->type == kUpb_LayoutItemType_OneofCase) { - upb_MdDecoder_ErrorJmp(&d->base, "Map entry cannot have oneof"); - } + if (is_empty && !(d->options & kUpb_DecodeOption_ExperimentalAllowUnlinked)) { + _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_UnlinkedSubMessage); } - upb_MtDecoder_ValidateEntryField(d, &d->table->UPB_PRIVATE(fields)[0], 1); - upb_MtDecoder_ValidateEntryField(d, &d->table->UPB_PRIVATE(fields)[1], 2); - - // Map entries have a pre-determined layout, regardless of types. - // NOTE: sync with mini_table/message_internal.h. - const size_t kv_size = d->platform == kUpb_MiniTablePlatform_32Bit ? 8 : 16; - const size_t hasbit_size = 8; - d->fields[0].UPB_PRIVATE(offset) = hasbit_size; - d->fields[1].UPB_PRIVATE(offset) = hasbit_size + kv_size; - d->table->UPB_PRIVATE(size) = - UPB_ALIGN_UP(hasbit_size + kv_size + kv_size, 8); - - // Map entries have a special bit set to signal it's a map entry, used in - // upb_MiniTable_SetSubMessage() below. - d->table->UPB_PRIVATE(ext) |= kUpb_ExtMode_IsMapEntry; + upb_TaggedMessagePtr tagged = + UPB_PRIVATE(_upb_TaggedMessagePtr_Pack)(msg, is_empty); + memcpy(target, &tagged, sizeof(tagged)); + return msg; } -static void upb_MtDecoder_ParseMessageSet(upb_MtDecoder* d, const char* data, - size_t len) { - if (len > 0) { - upb_MdDecoder_ErrorJmp(&d->base, "Invalid message set encode length: %zu", - len); +static upb_Message* _upb_Decoder_ReuseSubMessage( + upb_Decoder* d, const upb_MiniTableSub* subs, + const upb_MiniTableField* field, upb_TaggedMessagePtr* target) { + upb_TaggedMessagePtr tagged = *target; + const upb_MiniTable* subl = _upb_MiniTableSubs_MessageByField(subs, field); + UPB_ASSERT(subl); + if (!upb_TaggedMessagePtr_IsEmpty(tagged) || + UPB_PRIVATE(_upb_MiniTable_IsEmpty)(subl)) { + return UPB_PRIVATE(_upb_TaggedMessagePtr_GetMessage)(tagged); } - upb_MiniTable* ret = d->table; - ret->UPB_PRIVATE(size) = 0; - ret->UPB_PRIVATE(field_count) = 0; - ret->UPB_PRIVATE(ext) = kUpb_ExtMode_IsMessageSet; - ret->UPB_PRIVATE(dense_below) = 0; - ret->UPB_PRIVATE(table_mask) = -1; - ret->UPB_PRIVATE(required_count) = 0; + // We found an empty message from a previous parse that was performed before + // this field was linked. But it is linked now, so we want to allocate a new + // message of the correct type and promote data into it before continuing. + upb_Message* existing = + UPB_PRIVATE(_upb_TaggedMessagePtr_GetEmptyMessage)(tagged); + upb_Message* promoted = _upb_Decoder_NewSubMessage(d, subs, field, target); + size_t size; + const char* unknown = upb_Message_GetUnknown(existing, &size); + upb_DecodeStatus status = upb_Decode(unknown, size, promoted, subl, d->extreg, + d->options, &d->arena); + if (status != kUpb_DecodeStatus_Ok) _upb_Decoder_ErrorJmp(d, status); + return promoted; } -static upb_MiniTable* upb_MtDecoder_DoBuildMiniTableWithBuf( - upb_MtDecoder* decoder, const char* data, size_t len, void** buf, - size_t* buf_size) { - upb_MdDecoder_CheckOutOfMemory(&decoder->base, decoder->table); - - decoder->table->UPB_PRIVATE(size) = 0; - decoder->table->UPB_PRIVATE(field_count) = 0; - decoder->table->UPB_PRIVATE(ext) = kUpb_ExtMode_NonExtendable; - decoder->table->UPB_PRIVATE(dense_below) = 0; - decoder->table->UPB_PRIVATE(table_mask) = -1; - decoder->table->UPB_PRIVATE(required_count) = 0; - - // Strip off and verify the version tag. - if (!len--) goto done; - const char vers = *data++; - - switch (vers) { - case kUpb_EncodedVersion_MapV1: - upb_MtDecoder_ParseMap(decoder, data, len); - break; +static const char* _upb_Decoder_ReadString(upb_Decoder* d, const char* ptr, + int size, upb_StringView* str) { + const char* str_ptr = ptr; + ptr = upb_EpsCopyInputStream_ReadString(&d->input, &str_ptr, size, &d->arena); + if (!ptr) _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_OutOfMemory); + str->data = str_ptr; + str->size = size; + return ptr; +} - case kUpb_EncodedVersion_MessageV1: - upb_MtDecoder_ParseMessage(decoder, data, len); - upb_MtDecoder_AssignHasbits(decoder); - upb_MtDecoder_SortLayoutItems(decoder); - upb_MtDecoder_AssignOffsets(decoder); - break; +UPB_FORCEINLINE +static const char* _upb_Decoder_RecurseSubMessage(upb_Decoder* d, + const char* ptr, + upb_Message* submsg, + const upb_MiniTable* subl, + uint32_t expected_end_group) { + if (--d->depth < 0) { + _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_MaxDepthExceeded); + } + ptr = _upb_Decoder_DecodeMessage(d, ptr, submsg, subl); + d->depth++; + if (d->end_group != expected_end_group) { + _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_Malformed); + } + return ptr; +} - case kUpb_EncodedVersion_MessageSetV1: - upb_MtDecoder_ParseMessageSet(decoder, data, len); - break; +UPB_FORCEINLINE +static const char* _upb_Decoder_DecodeSubMessage( + upb_Decoder* d, const char* ptr, upb_Message* submsg, + const upb_MiniTableSub* subs, const upb_MiniTableField* field, int size) { + int saved_delta = upb_EpsCopyInputStream_PushLimit(&d->input, ptr, size); + const upb_MiniTable* subl = _upb_MiniTableSubs_MessageByField(subs, field); + UPB_ASSERT(subl); + ptr = _upb_Decoder_RecurseSubMessage(d, ptr, submsg, subl, DECODE_NOGROUP); + upb_EpsCopyInputStream_PopLimit(&d->input, ptr, saved_delta); + return ptr; +} - default: - upb_MdDecoder_ErrorJmp(&decoder->base, "Invalid message version: %c", - vers); +UPB_FORCEINLINE +static const char* _upb_Decoder_DecodeGroup(upb_Decoder* d, const char* ptr, + upb_Message* submsg, + const upb_MiniTable* subl, + uint32_t number) { + if (_upb_Decoder_IsDone(d, &ptr)) { + _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_Malformed); } + ptr = _upb_Decoder_RecurseSubMessage(d, ptr, submsg, subl, number); + d->end_group = DECODE_NOGROUP; + return ptr; +} -done: - *buf = decoder->vec.data; - *buf_size = decoder->vec.capacity * sizeof(*decoder->vec.data); - return decoder->table; +UPB_FORCEINLINE +static const char* _upb_Decoder_DecodeUnknownGroup(upb_Decoder* d, + const char* ptr, + uint32_t number) { + return _upb_Decoder_DecodeGroup(d, ptr, NULL, NULL, number); } -static upb_MiniTable* upb_MtDecoder_BuildMiniTableWithBuf( - upb_MtDecoder* const decoder, const char* const data, const size_t len, - void** const buf, size_t* const buf_size) { - if (UPB_SETJMP(decoder->base.err) != 0) { - *buf = decoder->vec.data; - *buf_size = decoder->vec.capacity * sizeof(*decoder->vec.data); - return NULL; - } +UPB_FORCEINLINE +static const char* _upb_Decoder_DecodeKnownGroup( + upb_Decoder* d, const char* ptr, upb_Message* submsg, + const upb_MiniTableSub* subs, const upb_MiniTableField* field) { + const upb_MiniTable* subl = _upb_MiniTableSubs_MessageByField(subs, field); + UPB_ASSERT(subl); + return _upb_Decoder_DecodeGroup(d, ptr, submsg, subl, + field->UPB_PRIVATE(number)); +} - return upb_MtDecoder_DoBuildMiniTableWithBuf(decoder, data, len, buf, - buf_size); +static char* upb_Decoder_EncodeVarint32(uint32_t val, char* ptr) { + do { + uint8_t byte = val & 0x7fU; + val >>= 7; + if (val) byte |= 0x80U; + *(ptr++) = byte; + } while (val); + return ptr; } -upb_MiniTable* upb_MiniTable_BuildWithBuf(const char* data, size_t len, - upb_MiniTablePlatform platform, - upb_Arena* arena, void** buf, - size_t* buf_size, - upb_Status* status) { - upb_MtDecoder decoder = { - .base = {.status = status}, - .platform = platform, - .vec = - { - .data = *buf, - .capacity = *buf_size / sizeof(*decoder.vec.data), - .size = 0, - }, - .arena = arena, - .table = upb_Arena_Malloc(arena, sizeof(*decoder.table)), - }; +static void _upb_Decoder_AddUnknownVarints(upb_Decoder* d, upb_Message* msg, + uint32_t val1, uint32_t val2) { + char buf[20]; + char* end = buf; + end = upb_Decoder_EncodeVarint32(val1, end); + end = upb_Decoder_EncodeVarint32(val2, end); - return upb_MtDecoder_BuildMiniTableWithBuf(&decoder, data, len, buf, - buf_size); + if (!UPB_PRIVATE(_upb_Message_AddUnknown)(msg, buf, end - buf, &d->arena)) { + _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_OutOfMemory); + } } -static const char* upb_MtDecoder_DoBuildMiniTableExtension( - upb_MtDecoder* decoder, const char* data, size_t len, - upb_MiniTableExtension* ext, const upb_MiniTable* extendee, - upb_MiniTableSub sub) { - // If the string is non-empty then it must begin with a version tag. - if (len) { - if (*data != kUpb_EncodedVersion_ExtensionV1) { - upb_MdDecoder_ErrorJmp(&decoder->base, "Invalid ext version: %c", *data); - } - data++; - len--; - } - - uint16_t count = 0; - upb_SubCounts sub_counts = {0, 0}; - const char* ret = upb_MtDecoder_Parse(decoder, data, len, ext, sizeof(*ext), - &count, &sub_counts); - if (!ret || count != 1) return NULL; - - upb_MiniTableField* f = &ext->UPB_PRIVATE(field); - - f->UPB_PRIVATE(mode) |= kUpb_LabelFlags_IsExtension; - f->UPB_PRIVATE(offset) = 0; - f->presence = 0; - - if (extendee->UPB_PRIVATE(ext) & kUpb_ExtMode_IsMessageSet) { - // Extensions of MessageSet must be messages. - if (!upb_MiniTableField_IsSubMessage(f)) return NULL; - - // Extensions of MessageSet must be non-repeating. - if (upb_MiniTableField_IsArray(f)) return NULL; - } +UPB_FORCEINLINE +static bool _upb_Decoder_CheckEnum(upb_Decoder* d, const char* ptr, + upb_Message* msg, const upb_MiniTableEnum* e, + const upb_MiniTableField* field, + wireval* val) { + const uint32_t v = val->uint32_val; - ext->UPB_PRIVATE(extendee) = extendee; - ext->UPB_PRIVATE(sub) = sub; + if (UPB_LIKELY(upb_MiniTableEnum_CheckValue(e, v))) return true; - return ret; + // Unrecognized enum goes into unknown fields. + // For packed fields the tag could be arbitrarily far in the past, + // so we just re-encode the tag and value here. + const uint32_t tag = + ((uint32_t)field->UPB_PRIVATE(number) << 3) | kUpb_WireType_Varint; + upb_Message* unknown_msg = + field->UPB_PRIVATE(mode) & kUpb_LabelFlags_IsExtension ? d->unknown_msg + : msg; + _upb_Decoder_AddUnknownVarints(d, unknown_msg, tag, v); + return false; } -static const char* upb_MtDecoder_BuildMiniTableExtension( - upb_MtDecoder* const decoder, const char* const data, const size_t len, - upb_MiniTableExtension* const ext, const upb_MiniTable* const extendee, - const upb_MiniTableSub sub) { - if (UPB_SETJMP(decoder->base.err) != 0) return NULL; - return upb_MtDecoder_DoBuildMiniTableExtension(decoder, data, len, ext, - extendee, sub); +UPB_NOINLINE +static const char* _upb_Decoder_DecodeEnumArray(upb_Decoder* d, const char* ptr, + upb_Message* msg, + upb_Array* arr, + const upb_MiniTableSub* subs, + const upb_MiniTableField* field, + wireval* val) { + const upb_MiniTableEnum* e = _upb_MiniTableSubs_EnumByField(subs, field); + if (!_upb_Decoder_CheckEnum(d, ptr, msg, e, field, val)) return ptr; + void* mem = UPB_PTR_AT(_upb_array_ptr(arr), arr->UPB_PRIVATE(size) * 4, void); + arr->UPB_PRIVATE(size)++; + memcpy(mem, val, 4); + return ptr; } -const char* _upb_MiniTableExtension_Init(const char* data, size_t len, - upb_MiniTableExtension* ext, - const upb_MiniTable* extendee, - upb_MiniTableSub sub, - upb_MiniTablePlatform platform, - upb_Status* status) { - upb_MtDecoder decoder = { - .base = {.status = status}, - .arena = NULL, - .table = NULL, - .platform = platform, - }; +UPB_FORCEINLINE +static const char* _upb_Decoder_DecodeFixedPacked( + upb_Decoder* d, const char* ptr, upb_Array* arr, wireval* val, + const upb_MiniTableField* field, int lg2) { + int mask = (1 << lg2) - 1; + size_t count = val->size >> lg2; + if ((val->size & mask) != 0) { + // Length isn't a round multiple of elem size. + _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_Malformed); + } + _upb_Decoder_Reserve(d, arr, count); + void* mem = + UPB_PTR_AT(_upb_array_ptr(arr), arr->UPB_PRIVATE(size) << lg2, void); + arr->UPB_PRIVATE(size) += count; + // Note: if/when the decoder supports multi-buffer input, we will need to + // handle buffer seams here. + if (UPB_PRIVATE(_upb_IsLittleEndian)()) { + ptr = upb_EpsCopyInputStream_Copy(&d->input, ptr, mem, val->size); + } else { + int delta = upb_EpsCopyInputStream_PushLimit(&d->input, ptr, val->size); + char* dst = mem; + while (!_upb_Decoder_IsDone(d, &ptr)) { + if (lg2 == 2) { + ptr = upb_WireReader_ReadFixed32(ptr, dst); + dst += 4; + } else { + UPB_ASSERT(lg2 == 3); + ptr = upb_WireReader_ReadFixed64(ptr, dst); + dst += 8; + } + } + upb_EpsCopyInputStream_PopLimit(&d->input, ptr, delta); + } - return upb_MtDecoder_BuildMiniTableExtension(&decoder, data, len, ext, - extendee, sub); + return ptr; } -upb_MiniTableExtension* _upb_MiniTableExtension_Build( - const char* data, size_t len, const upb_MiniTable* extendee, - upb_MiniTableSub sub, upb_MiniTablePlatform platform, upb_Arena* arena, - upb_Status* status) { - upb_MiniTableExtension* ext = - upb_Arena_Malloc(arena, sizeof(upb_MiniTableExtension)); - if (UPB_UNLIKELY(!ext)) return NULL; - - const char* ptr = _upb_MiniTableExtension_Init(data, len, ext, extendee, sub, - platform, status); - if (UPB_UNLIKELY(!ptr)) return NULL; +UPB_FORCEINLINE +static const char* _upb_Decoder_DecodeVarintPacked( + upb_Decoder* d, const char* ptr, upb_Array* arr, wireval* val, + const upb_MiniTableField* field, int lg2) { + int scale = 1 << lg2; + int saved_limit = upb_EpsCopyInputStream_PushLimit(&d->input, ptr, val->size); + char* out = + UPB_PTR_AT(_upb_array_ptr(arr), arr->UPB_PRIVATE(size) << lg2, void); + while (!_upb_Decoder_IsDone(d, &ptr)) { + wireval elem; + ptr = _upb_Decoder_DecodeVarint(d, ptr, &elem.uint64_val); + _upb_Decoder_Munge(field->UPB_PRIVATE(descriptortype), &elem); + if (_upb_Decoder_Reserve(d, arr, 1)) { + out = + UPB_PTR_AT(_upb_array_ptr(arr), arr->UPB_PRIVATE(size) << lg2, void); + } + arr->UPB_PRIVATE(size)++; + memcpy(out, &elem, scale); + out += scale; + } + upb_EpsCopyInputStream_PopLimit(&d->input, ptr, saved_limit); + return ptr; +} - return ext; +UPB_NOINLINE +static const char* _upb_Decoder_DecodeEnumPacked( + upb_Decoder* d, const char* ptr, upb_Message* msg, upb_Array* arr, + const upb_MiniTableSub* subs, const upb_MiniTableField* field, + wireval* val) { + const upb_MiniTableEnum* e = _upb_MiniTableSubs_EnumByField(subs, field); + int saved_limit = upb_EpsCopyInputStream_PushLimit(&d->input, ptr, val->size); + char* out = UPB_PTR_AT(_upb_array_ptr(arr), arr->UPB_PRIVATE(size) * 4, void); + while (!_upb_Decoder_IsDone(d, &ptr)) { + wireval elem; + ptr = _upb_Decoder_DecodeVarint(d, ptr, &elem.uint64_val); + _upb_Decoder_MungeInt32(&elem); + if (!_upb_Decoder_CheckEnum(d, ptr, msg, e, field, &elem)) { + continue; + } + if (_upb_Decoder_Reserve(d, arr, 1)) { + out = UPB_PTR_AT(_upb_array_ptr(arr), arr->UPB_PRIVATE(size) * 4, void); + } + arr->UPB_PRIVATE(size)++; + memcpy(out, &elem, 4); + out += 4; + } + upb_EpsCopyInputStream_PopLimit(&d->input, ptr, saved_limit); + return ptr; } -upb_MiniTable* _upb_MiniTable_Build(const char* data, size_t len, - upb_MiniTablePlatform platform, - upb_Arena* arena, upb_Status* status) { - void* buf = NULL; - size_t size = 0; - upb_MiniTable* ret = upb_MiniTable_BuildWithBuf(data, len, platform, arena, - &buf, &size, status); - free(buf); +upb_Array* _upb_Decoder_CreateArray(upb_Decoder* d, + const upb_MiniTableField* field) { + const upb_FieldType field_type = field->UPB_PRIVATE(descriptortype); + const size_t lg2 = UPB_PRIVATE(_upb_FieldType_SizeLg2)(field_type); + upb_Array* ret = UPB_PRIVATE(_upb_Array_New)(&d->arena, 4, lg2); + if (!ret) _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_OutOfMemory); return ret; } +static const char* _upb_Decoder_DecodeToArray(upb_Decoder* d, const char* ptr, + upb_Message* msg, + const upb_MiniTableSub* subs, + const upb_MiniTableField* field, + wireval* val, int op) { + upb_Array** arrp = UPB_PTR_AT(msg, field->UPB_PRIVATE(offset), void); + upb_Array* arr = *arrp; + void* mem; -#include -#include - - -// Must be last. - -bool upb_MiniTable_SetSubMessage(upb_MiniTable* table, - upb_MiniTableField* field, - const upb_MiniTable* sub) { - UPB_ASSERT((uintptr_t)table->UPB_PRIVATE(fields) <= (uintptr_t)field && - (uintptr_t)field < (uintptr_t)(table->UPB_PRIVATE(fields) + - table->UPB_PRIVATE(field_count))); - UPB_ASSERT(sub); - - const bool sub_is_map = sub->UPB_PRIVATE(ext) & kUpb_ExtMode_IsMapEntry; - - switch (field->UPB_PRIVATE(descriptortype)) { - case kUpb_FieldType_Message: - if (sub_is_map) { - const bool table_is_map = - table->UPB_PRIVATE(ext) & kUpb_ExtMode_IsMapEntry; - if (UPB_UNLIKELY(table_is_map)) return false; - - field->UPB_PRIVATE(mode) = - (field->UPB_PRIVATE(mode) & ~kUpb_FieldMode_Mask) | - kUpb_FieldMode_Map; - } - break; - - case kUpb_FieldType_Group: - if (UPB_UNLIKELY(sub_is_map)) return false; - break; - - default: - return false; + if (arr) { + _upb_Decoder_Reserve(d, arr, 1); + } else { + arr = _upb_Decoder_CreateArray(d, field); + *arrp = arr; } - upb_MiniTableSub* table_sub = - (void*)&table->UPB_PRIVATE(subs)[field->UPB_PRIVATE(submsg_index)]; - // TODO: Add this assert back once YouTube is updated to not call - // this function repeatedly. - // UPB_ASSERT(UPB_PRIVATE(_upb_MiniTable_IsEmpty)(table_sub->submsg)); - *table_sub = upb_MiniTableSub_FromMessage(sub); - return true; -} - -bool upb_MiniTable_SetSubEnum(upb_MiniTable* table, upb_MiniTableField* field, - const upb_MiniTableEnum* sub) { - UPB_ASSERT((uintptr_t)table->UPB_PRIVATE(fields) <= (uintptr_t)field && - (uintptr_t)field < (uintptr_t)(table->UPB_PRIVATE(fields) + - table->UPB_PRIVATE(field_count))); - UPB_ASSERT(sub); - - upb_MiniTableSub* table_sub = - (void*)&table->UPB_PRIVATE(subs)[field->UPB_PRIVATE(submsg_index)]; - *table_sub = upb_MiniTableSub_FromEnum(sub); - return true; -} - -uint32_t upb_MiniTable_GetSubList(const upb_MiniTable* mt, - const upb_MiniTableField** subs) { - uint32_t msg_count = 0; - uint32_t enum_count = 0; - - for (int i = 0; i < mt->UPB_PRIVATE(field_count); i++) { - const upb_MiniTableField* f = &mt->UPB_PRIVATE(fields)[i]; - if (upb_MiniTableField_CType(f) == kUpb_CType_Message) { - *subs = f; - ++subs; - msg_count++; - } - } - - for (int i = 0; i < mt->UPB_PRIVATE(field_count); i++) { - const upb_MiniTableField* f = &mt->UPB_PRIVATE(fields)[i]; - if (upb_MiniTableField_CType(f) == kUpb_CType_Enum) { - *subs = f; - ++subs; - enum_count++; - } - } - - return (msg_count << 16) | enum_count; -} - -// The list of sub_tables and sub_enums must exactly match the number and order -// of sub-message fields and sub-enum fields given by upb_MiniTable_GetSubList() -// above. -bool upb_MiniTable_Link(upb_MiniTable* mt, const upb_MiniTable** sub_tables, - size_t sub_table_count, - const upb_MiniTableEnum** sub_enums, - size_t sub_enum_count) { - uint32_t msg_count = 0; - uint32_t enum_count = 0; - - for (int i = 0; i < mt->UPB_PRIVATE(field_count); i++) { - upb_MiniTableField* f = (upb_MiniTableField*)&mt->UPB_PRIVATE(fields)[i]; - if (upb_MiniTableField_CType(f) == kUpb_CType_Message) { - const upb_MiniTable* sub = sub_tables[msg_count++]; - if (msg_count > sub_table_count) return false; - if (sub != NULL) { - if (!upb_MiniTable_SetSubMessage(mt, f, sub)) return false; - } + switch (op) { + case kUpb_DecodeOp_Scalar1Byte: + case kUpb_DecodeOp_Scalar4Byte: + case kUpb_DecodeOp_Scalar8Byte: + /* Append scalar value. */ + mem = UPB_PTR_AT(_upb_array_ptr(arr), arr->UPB_PRIVATE(size) << op, void); + arr->UPB_PRIVATE(size)++; + memcpy(mem, val, 1 << op); + return ptr; + case kUpb_DecodeOp_String: + _upb_Decoder_VerifyUtf8(d, ptr, val->size); + /* Fallthrough. */ + case kUpb_DecodeOp_Bytes: { + /* Append bytes. */ + upb_StringView* str = + (upb_StringView*)_upb_array_ptr(arr) + arr->UPB_PRIVATE(size); + arr->UPB_PRIVATE(size)++; + return _upb_Decoder_ReadString(d, ptr, val->size, str); } - } - - for (int i = 0; i < mt->UPB_PRIVATE(field_count); i++) { - upb_MiniTableField* f = (upb_MiniTableField*)&mt->UPB_PRIVATE(fields)[i]; - if (upb_MiniTableField_IsClosedEnum(f)) { - const upb_MiniTableEnum* sub = sub_enums[enum_count++]; - if (enum_count > sub_enum_count) return false; - if (sub != NULL) { - if (!upb_MiniTable_SetSubEnum(mt, f, sub)) return false; + case kUpb_DecodeOp_SubMessage: { + /* Append submessage / group. */ + upb_TaggedMessagePtr* target = UPB_PTR_AT( + _upb_array_ptr(arr), arr->UPB_PRIVATE(size) * sizeof(void*), + upb_TaggedMessagePtr); + upb_Message* submsg = _upb_Decoder_NewSubMessage(d, subs, field, target); + arr->UPB_PRIVATE(size)++; + if (UPB_UNLIKELY(field->UPB_PRIVATE(descriptortype) == + kUpb_FieldType_Group)) { + return _upb_Decoder_DecodeKnownGroup(d, ptr, submsg, subs, field); + } else { + return _upb_Decoder_DecodeSubMessage(d, ptr, submsg, subs, field, + val->size); } } + case OP_FIXPCK_LG2(2): + case OP_FIXPCK_LG2(3): + return _upb_Decoder_DecodeFixedPacked(d, ptr, arr, val, field, + op - OP_FIXPCK_LG2(0)); + case OP_VARPCK_LG2(0): + case OP_VARPCK_LG2(2): + case OP_VARPCK_LG2(3): + return _upb_Decoder_DecodeVarintPacked(d, ptr, arr, val, field, + op - OP_VARPCK_LG2(0)); + case kUpb_DecodeOp_Enum: + return _upb_Decoder_DecodeEnumArray(d, ptr, msg, arr, subs, field, val); + case kUpb_DecodeOp_PackedEnum: + return _upb_Decoder_DecodeEnumPacked(d, ptr, msg, arr, subs, field, val); + default: + UPB_UNREACHABLE(); } - - return true; } +upb_Map* _upb_Decoder_CreateMap(upb_Decoder* d, const upb_MiniTable* entry) { + /* Maps descriptor type -> upb map size. */ + static const uint8_t kSizeInMap[] = { + [0] = -1, // invalid descriptor type */ + [kUpb_FieldType_Double] = 8, + [kUpb_FieldType_Float] = 4, + [kUpb_FieldType_Int64] = 8, + [kUpb_FieldType_UInt64] = 8, + [kUpb_FieldType_Int32] = 4, + [kUpb_FieldType_Fixed64] = 8, + [kUpb_FieldType_Fixed32] = 4, + [kUpb_FieldType_Bool] = 1, + [kUpb_FieldType_String] = UPB_MAPTYPE_STRING, + [kUpb_FieldType_Group] = sizeof(void*), + [kUpb_FieldType_Message] = sizeof(void*), + [kUpb_FieldType_Bytes] = UPB_MAPTYPE_STRING, + [kUpb_FieldType_UInt32] = 4, + [kUpb_FieldType_Enum] = 4, + [kUpb_FieldType_SFixed32] = 4, + [kUpb_FieldType_SFixed64] = 8, + [kUpb_FieldType_SInt32] = 4, + [kUpb_FieldType_SInt64] = 8, + }; -#include -#include -#include - - -// Must be last. - -#define EXTREG_KEY_SIZE (sizeof(upb_MiniTable*) + sizeof(uint32_t)) - -struct upb_ExtensionRegistry { - upb_Arena* arena; - upb_strtable exts; // Key is upb_MiniTable* concatenated with fieldnum. -}; - -static void extreg_key(char* buf, const upb_MiniTable* l, uint32_t fieldnum) { - memcpy(buf, &l, sizeof(l)); - memcpy(buf + sizeof(l), &fieldnum, sizeof(fieldnum)); + const upb_MiniTableField* key_field = &entry->UPB_PRIVATE(fields)[0]; + const upb_MiniTableField* val_field = &entry->UPB_PRIVATE(fields)[1]; + char key_size = kSizeInMap[key_field->UPB_PRIVATE(descriptortype)]; + char val_size = kSizeInMap[val_field->UPB_PRIVATE(descriptortype)]; + UPB_ASSERT(key_field->UPB_PRIVATE(offset) == offsetof(upb_MapEntryData, k)); + UPB_ASSERT(val_field->UPB_PRIVATE(offset) == offsetof(upb_MapEntryData, v)); + upb_Map* ret = _upb_Map_New(&d->arena, key_size, val_size); + if (!ret) _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_OutOfMemory); + return ret; } -upb_ExtensionRegistry* upb_ExtensionRegistry_New(upb_Arena* arena) { - upb_ExtensionRegistry* r = upb_Arena_Malloc(arena, sizeof(*r)); - if (!r) return NULL; - r->arena = arena; - if (!upb_strtable_init(&r->exts, 8, arena)) return NULL; - return r; -} +static const char* _upb_Decoder_DecodeToMap(upb_Decoder* d, const char* ptr, + upb_Message* msg, + const upb_MiniTableSub* subs, + const upb_MiniTableField* field, + wireval* val) { + upb_Map** map_p = UPB_PTR_AT(msg, field->UPB_PRIVATE(offset), upb_Map*); + upb_Map* map = *map_p; + upb_MapEntry ent; + UPB_ASSERT(upb_MiniTableField_Type(field) == kUpb_FieldType_Message); + const upb_MiniTable* entry = _upb_MiniTableSubs_MessageByField(subs, field); -UPB_API bool upb_ExtensionRegistry_Add(upb_ExtensionRegistry* r, - const upb_MiniTableExtension* e) { - char buf[EXTREG_KEY_SIZE]; - extreg_key(buf, e->UPB_PRIVATE(extendee), upb_MiniTableExtension_Number(e)); - if (upb_strtable_lookup2(&r->exts, buf, EXTREG_KEY_SIZE, NULL)) return false; - return upb_strtable_insert(&r->exts, buf, EXTREG_KEY_SIZE, - upb_value_constptr(e), r->arena); -} + UPB_ASSERT(entry); + UPB_ASSERT(entry->UPB_PRIVATE(field_count) == 2); + UPB_ASSERT(upb_MiniTableField_IsScalar(&entry->UPB_PRIVATE(fields)[0])); + UPB_ASSERT(upb_MiniTableField_IsScalar(&entry->UPB_PRIVATE(fields)[1])); -bool upb_ExtensionRegistry_AddArray(upb_ExtensionRegistry* r, - const upb_MiniTableExtension** e, - size_t count) { - const upb_MiniTableExtension** start = e; - const upb_MiniTableExtension** end = UPB_PTRADD(e, count); - for (; e < end; e++) { - if (!upb_ExtensionRegistry_Add(r, *e)) goto failure; + if (!map) { + map = _upb_Decoder_CreateMap(d, entry); + *map_p = map; } - return true; -failure: - // Back out the entries previously added. - for (end = e, e = start; e < end; e++) { - const upb_MiniTableExtension* ext = *e; - char buf[EXTREG_KEY_SIZE]; - extreg_key(buf, ext->UPB_PRIVATE(extendee), - upb_MiniTableExtension_Number(ext)); - upb_strtable_remove2(&r->exts, buf, EXTREG_KEY_SIZE, NULL); + // Parse map entry. + memset(&ent, 0, sizeof(ent)); + + if (entry->UPB_PRIVATE(fields)[1].UPB_PRIVATE(descriptortype) == + kUpb_FieldType_Message || + entry->UPB_PRIVATE(fields)[1].UPB_PRIVATE(descriptortype) == + kUpb_FieldType_Group) { + // Create proactively to handle the case where it doesn't appear. + upb_TaggedMessagePtr msg; + _upb_Decoder_NewSubMessage(d, entry->UPB_PRIVATE(subs), + &entry->UPB_PRIVATE(fields)[1], &msg); + ent.data.v.val = upb_value_uintptr(msg); } - return false; -} -const upb_MiniTableExtension* upb_ExtensionRegistry_Lookup( - const upb_ExtensionRegistry* r, const upb_MiniTable* t, uint32_t num) { - char buf[EXTREG_KEY_SIZE]; - upb_value v; - extreg_key(buf, t, num); - if (upb_strtable_lookup2(&r->exts, buf, EXTREG_KEY_SIZE, &v)) { - return upb_value_getconstptr(v); + ptr = _upb_Decoder_DecodeSubMessage(d, ptr, (upb_Message*)&ent.data, subs, + field, val->size); + // check if ent had any unknown fields + size_t size; + upb_Message_GetUnknown((upb_Message*)&ent.data, &size); + if (size != 0) { + char* buf; + size_t size; + uint32_t tag = + ((uint32_t)field->UPB_PRIVATE(number) << 3) | kUpb_WireType_Delimited; + upb_EncodeStatus status = + upb_Encode((upb_Message*)&ent.data, entry, 0, &d->arena, &buf, &size); + if (status != kUpb_EncodeStatus_Ok) { + _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_OutOfMemory); + } + _upb_Decoder_AddUnknownVarints(d, msg, tag, size); + if (!UPB_PRIVATE(_upb_Message_AddUnknown)(msg, buf, size, &d->arena)) { + _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_OutOfMemory); + } } else { - return NULL; + if (_upb_Map_Insert(map, &ent.data.k, map->key_size, &ent.data.v, + map->val_size, + &d->arena) == kUpb_MapInsertStatus_OutOfMemory) { + _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_OutOfMemory); + } } + return ptr; } +static const char* _upb_Decoder_DecodeToSubMessage( + upb_Decoder* d, const char* ptr, upb_Message* msg, + const upb_MiniTableSub* subs, const upb_MiniTableField* field, wireval* val, + int op) { + void* mem = UPB_PTR_AT(msg, field->UPB_PRIVATE(offset), void); + int type = field->UPB_PRIVATE(descriptortype); -#include -#include -#include - - -// Must be last. - -const upb_MiniTableField* upb_MiniTable_FindFieldByNumber( - const upb_MiniTable* m, uint32_t number) { - const size_t i = ((size_t)number) - 1; // 0 wraps to SIZE_MAX - - // Ideal case: index into dense fields - if (i < m->UPB_PRIVATE(dense_below)) { - UPB_ASSERT(m->UPB_PRIVATE(fields)[i].UPB_PRIVATE(number) == number); - return &m->UPB_PRIVATE(fields)[i]; + if (UPB_UNLIKELY(op == kUpb_DecodeOp_Enum) && + !_upb_Decoder_CheckEnum(d, ptr, msg, + _upb_MiniTableSubs_EnumByField(subs, field), + field, val)) { + return ptr; } - // Slow case: binary search - int lo = m->UPB_PRIVATE(dense_below); - int hi = m->UPB_PRIVATE(field_count) - 1; - while (lo <= hi) { - int mid = (lo + hi) / 2; - uint32_t num = m->UPB_PRIVATE(fields)[mid].UPB_PRIVATE(number); - if (num < number) { - lo = mid + 1; - continue; + /* Set presence if necessary. */ + if (field->presence > 0) { + UPB_PRIVATE(_upb_Message_SetHasbit)(msg, field); + } else if (field->presence < 0) { + /* Oneof case */ + uint32_t* oneof_case = UPB_PRIVATE(_upb_Message_OneofCasePtr)(msg, field); + if (op == kUpb_DecodeOp_SubMessage && + *oneof_case != field->UPB_PRIVATE(number)) { + memset(mem, 0, sizeof(void*)); } - if (num > number) { - hi = mid - 1; - continue; + *oneof_case = field->UPB_PRIVATE(number); + } + + /* Store into message. */ + switch (op) { + case kUpb_DecodeOp_SubMessage: { + upb_TaggedMessagePtr* submsgp = mem; + upb_Message* submsg; + if (*submsgp) { + submsg = _upb_Decoder_ReuseSubMessage(d, subs, field, submsgp); + } else { + submsg = _upb_Decoder_NewSubMessage(d, subs, field, submsgp); + } + if (UPB_UNLIKELY(type == kUpb_FieldType_Group)) { + ptr = _upb_Decoder_DecodeKnownGroup(d, ptr, submsg, subs, field); + } else { + ptr = _upb_Decoder_DecodeSubMessage(d, ptr, submsg, subs, field, + val->size); + } + break; } - return &m->UPB_PRIVATE(fields)[mid]; + case kUpb_DecodeOp_String: + _upb_Decoder_VerifyUtf8(d, ptr, val->size); + /* Fallthrough. */ + case kUpb_DecodeOp_Bytes: + return _upb_Decoder_ReadString(d, ptr, val->size, mem); + case kUpb_DecodeOp_Scalar8Byte: + memcpy(mem, val, 8); + break; + case kUpb_DecodeOp_Enum: + case kUpb_DecodeOp_Scalar4Byte: + memcpy(mem, val, 4); + break; + case kUpb_DecodeOp_Scalar1Byte: + memcpy(mem, val, 1); + break; + default: + UPB_UNREACHABLE(); } - return NULL; + + return ptr; } -const upb_MiniTableField* upb_MiniTable_GetOneof(const upb_MiniTable* m, - const upb_MiniTableField* f) { - if (UPB_UNLIKELY(!upb_MiniTableField_IsInOneof(f))) { - return NULL; +UPB_NOINLINE +const char* _upb_Decoder_CheckRequired(upb_Decoder* d, const char* ptr, + const upb_Message* msg, + const upb_MiniTable* m) { + UPB_ASSERT(m->UPB_PRIVATE(required_count)); + if (UPB_LIKELY((d->options & kUpb_DecodeOption_CheckRequired) == 0)) { + return ptr; } - const upb_MiniTableField* ptr = &m->UPB_PRIVATE(fields)[0]; - const upb_MiniTableField* end = - &m->UPB_PRIVATE(fields)[m->UPB_PRIVATE(field_count)]; - for (; ptr < end; ptr++) { - if (ptr->presence == (*f).presence) { - return ptr; - } + uint64_t msg_head; + memcpy(&msg_head, msg, 8); + msg_head = UPB_PRIVATE(_upb_BigEndian64)(msg_head); + if (UPB_PRIVATE(_upb_MiniTable_RequiredMask)(m) & ~msg_head) { + d->missing_required = true; } - return NULL; + return ptr; } -bool upb_MiniTable_NextOneofField(const upb_MiniTable* m, - const upb_MiniTableField** f) { - const upb_MiniTableField* ptr = *f; - const upb_MiniTableField* end = - &m->UPB_PRIVATE(fields)[m->UPB_PRIVATE(field_count)]; - while (++ptr < end) { - if (ptr->presence == (*f)->presence) { - *f = ptr; - return true; - } +UPB_FORCEINLINE +static bool _upb_Decoder_TryFastDispatch(upb_Decoder* d, const char** ptr, + upb_Message* msg, + const upb_MiniTable* m) { +#if UPB_FASTTABLE + if (m && m->UPB_PRIVATE(table_mask) != (unsigned char)-1) { + uint16_t tag = _upb_FastDecoder_LoadTag(*ptr); + intptr_t table = decode_totable(m); + *ptr = _upb_FastDecoder_TagDispatch(d, *ptr, msg, table, 0, tag); + return true; } +#endif return false; } +static const char* upb_Decoder_SkipField(upb_Decoder* d, const char* ptr, + uint32_t tag) { + int field_number = tag >> 3; + int wire_type = tag & 7; + switch (wire_type) { + case kUpb_WireType_Varint: { + uint64_t val; + return _upb_Decoder_DecodeVarint(d, ptr, &val); + } + case kUpb_WireType_64Bit: + return ptr + 8; + case kUpb_WireType_32Bit: + return ptr + 4; + case kUpb_WireType_Delimited: { + uint32_t size; + ptr = upb_Decoder_DecodeSize(d, ptr, &size); + return ptr + size; + } + case kUpb_WireType_StartGroup: + return _upb_Decoder_DecodeUnknownGroup(d, ptr, field_number); + default: + _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_Malformed); + } +} -#include -#include +enum { + kStartItemTag = ((kUpb_MsgSet_Item << 3) | kUpb_WireType_StartGroup), + kEndItemTag = ((kUpb_MsgSet_Item << 3) | kUpb_WireType_EndGroup), + kTypeIdTag = ((kUpb_MsgSet_TypeId << 3) | kUpb_WireType_Varint), + kMessageTag = ((kUpb_MsgSet_Message << 3) | kUpb_WireType_Delimited), +}; +static void upb_Decoder_AddKnownMessageSetItem( + upb_Decoder* d, upb_Message* msg, const upb_MiniTableExtension* item_mt, + const char* data, uint32_t size) { + upb_Extension* ext = + _upb_Message_GetOrCreateExtension(msg, item_mt, &d->arena); + if (UPB_UNLIKELY(!ext)) { + _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_OutOfMemory); + } + upb_Message* submsg = _upb_Decoder_NewSubMessage( + d, &ext->ext->UPB_PRIVATE(sub), upb_MiniTableExtension_AsField(ext->ext), + (upb_TaggedMessagePtr*)&ext->data); + upb_DecodeStatus status = upb_Decode( + data, size, submsg, upb_MiniTableExtension_GetSubMessage(item_mt), + d->extreg, d->options, &d->arena); + if (status != kUpb_DecodeStatus_Ok) _upb_Decoder_ErrorJmp(d, status); +} -// Must be last. +static void upb_Decoder_AddUnknownMessageSetItem(upb_Decoder* d, + upb_Message* msg, + uint32_t type_id, + const char* message_data, + uint32_t message_size) { + char buf[60]; + char* ptr = buf; + ptr = upb_Decoder_EncodeVarint32(kStartItemTag, ptr); + ptr = upb_Decoder_EncodeVarint32(kTypeIdTag, ptr); + ptr = upb_Decoder_EncodeVarint32(type_id, ptr); + ptr = upb_Decoder_EncodeVarint32(kMessageTag, ptr); + ptr = upb_Decoder_EncodeVarint32(message_size, ptr); + char* split = ptr; -// Checks if source and target mini table fields are identical. -// -// If the field is a sub message and sub messages are identical we record -// the association in table. -// -// Hashing the source sub message mini table and it's equivalent in the table -// stops recursing when a cycle is detected and instead just checks if the -// destination table is equal. -static upb_MiniTableEquals_Status upb_deep_check(const upb_MiniTable* src, - const upb_MiniTable* dst, - upb_inttable* table, - upb_Arena** arena) { - if (src->UPB_PRIVATE(field_count) != dst->UPB_PRIVATE(field_count)) - return kUpb_MiniTableEquals_NotEqual; - bool marked_src = false; - for (int i = 0; i < upb_MiniTable_FieldCount(src); i++) { - const upb_MiniTableField* src_field = upb_MiniTable_GetFieldByIndex(src, i); - const upb_MiniTableField* dst_field = upb_MiniTable_FindFieldByNumber( - dst, upb_MiniTableField_Number(src_field)); + ptr = upb_Decoder_EncodeVarint32(kEndItemTag, ptr); + char* end = ptr; - if (upb_MiniTableField_CType(src_field) != - upb_MiniTableField_CType(dst_field)) - return false; - if (src_field->UPB_PRIVATE(mode) != dst_field->UPB_PRIVATE(mode)) - return false; - if (src_field->UPB_PRIVATE(offset) != dst_field->UPB_PRIVATE(offset)) - return false; - if (src_field->presence != dst_field->presence) return false; - if (src_field->UPB_PRIVATE(submsg_index) != - dst_field->UPB_PRIVATE(submsg_index)) - return kUpb_MiniTableEquals_NotEqual; + if (!UPB_PRIVATE(_upb_Message_AddUnknown)(msg, buf, split - buf, &d->arena) || + !UPB_PRIVATE(_upb_Message_AddUnknown)(msg, message_data, message_size, + &d->arena) || + !UPB_PRIVATE(_upb_Message_AddUnknown)(msg, split, end - split, + &d->arena)) { + _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_OutOfMemory); + } +} - // Go no further if we are only checking for compatibility. - if (!table) continue; +static void upb_Decoder_AddMessageSetItem(upb_Decoder* d, upb_Message* msg, + const upb_MiniTable* t, + uint32_t type_id, const char* data, + uint32_t size) { + const upb_MiniTableExtension* item_mt = + upb_ExtensionRegistry_Lookup(d->extreg, t, type_id); + if (item_mt) { + upb_Decoder_AddKnownMessageSetItem(d, msg, item_mt, data, size); + } else { + upb_Decoder_AddUnknownMessageSetItem(d, msg, type_id, data, size); + } +} - if (upb_MiniTableField_CType(src_field) == kUpb_CType_Message) { - if (!*arena) { - *arena = upb_Arena_New(); - if (!upb_inttable_init(table, *arena)) { - return kUpb_MiniTableEquals_OutOfMemory; - } - } - if (!marked_src) { - marked_src = true; - upb_value val; - val.val = (uint64_t)dst; - if (!upb_inttable_insert(table, (uintptr_t)src, val, *arena)) { - return kUpb_MiniTableEquals_OutOfMemory; +static const char* upb_Decoder_DecodeMessageSetItem( + upb_Decoder* d, const char* ptr, upb_Message* msg, + const upb_MiniTable* layout) { + uint32_t type_id = 0; + upb_StringView preserved = {NULL, 0}; + typedef enum { + kUpb_HaveId = 1 << 0, + kUpb_HavePayload = 1 << 1, + } StateMask; + StateMask state_mask = 0; + while (!_upb_Decoder_IsDone(d, &ptr)) { + uint32_t tag; + ptr = _upb_Decoder_DecodeTag(d, ptr, &tag); + switch (tag) { + case kEndItemTag: + return ptr; + case kTypeIdTag: { + uint64_t tmp; + ptr = _upb_Decoder_DecodeVarint(d, ptr, &tmp); + if (state_mask & kUpb_HaveId) break; // Ignore dup. + state_mask |= kUpb_HaveId; + type_id = tmp; + if (state_mask & kUpb_HavePayload) { + upb_Decoder_AddMessageSetItem(d, msg, layout, type_id, preserved.data, + preserved.size); } + break; } - const upb_MiniTable* sub_src = - upb_MiniTable_GetSubMessageTable(src, src_field); - const upb_MiniTable* sub_dst = - upb_MiniTable_GetSubMessageTable(dst, dst_field); - if (sub_src != NULL) { - upb_value cmp; - if (upb_inttable_lookup(table, (uintptr_t)sub_src, &cmp)) { - // We already compared this src before. Check if same dst. - if (cmp.val != (uint64_t)sub_dst) { - return kUpb_MiniTableEquals_NotEqual; - } + case kMessageTag: { + uint32_t size; + ptr = upb_Decoder_DecodeSize(d, ptr, &size); + const char* data = ptr; + ptr += size; + if (state_mask & kUpb_HavePayload) break; // Ignore dup. + state_mask |= kUpb_HavePayload; + if (state_mask & kUpb_HaveId) { + upb_Decoder_AddMessageSetItem(d, msg, layout, type_id, data, size); } else { - // Recurse if not already visited. - upb_MiniTableEquals_Status s = - upb_deep_check(sub_src, sub_dst, table, arena); - if (s != kUpb_MiniTableEquals_Equal) { - return s; - } + // Out of order, we must preserve the payload. + preserved.data = data; + preserved.size = size; } + break; } + default: + // We do not preserve unexpected fields inside a message set item. + ptr = upb_Decoder_SkipField(d, ptr, tag); + break; } } - return kUpb_MiniTableEquals_Equal; + _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_Malformed); } -bool upb_MiniTable_Compatible(const upb_MiniTable* src, - const upb_MiniTable* dst) { - return upb_deep_check(src, dst, NULL, NULL); -} +static const upb_MiniTableField* _upb_Decoder_FindField(upb_Decoder* d, + const upb_MiniTable* t, + uint32_t field_number, + int* last_field_index) { + static upb_MiniTableField none = { + 0, 0, 0, 0, kUpb_FakeFieldType_FieldNotFound, 0}; + if (t == NULL) return &none; -upb_MiniTableEquals_Status upb_MiniTable_Equals(const upb_MiniTable* src, - const upb_MiniTable* dst) { - // Arena allocated on demand for hash table. - upb_Arena* arena = NULL; - // Table to keep track of visited mini tables to guard against cycles. - upb_inttable table; - upb_MiniTableEquals_Status status = upb_deep_check(src, dst, &table, &arena); - if (arena) { - upb_Arena_Free(arena); + size_t idx = ((size_t)field_number) - 1; // 0 wraps to SIZE_MAX + if (idx < t->UPB_PRIVATE(dense_below)) { + /* Fastest case: index into dense fields. */ + goto found; } - return status; -} + if (t->UPB_PRIVATE(dense_below) < t->UPB_PRIVATE(field_count)) { + /* Linear search non-dense fields. Resume scanning from last_field_index + * since fields are usually in order. */ + size_t last = *last_field_index; + for (idx = last; idx < t->UPB_PRIVATE(field_count); idx++) { + if (t->UPB_PRIVATE(fields)[idx].UPB_PRIVATE(number) == field_number) { + goto found; + } + } + for (idx = t->UPB_PRIVATE(dense_below); idx < last; idx++) { + if (t->UPB_PRIVATE(fields)[idx].UPB_PRIVATE(number) == field_number) { + goto found; + } + } + } -// Must be last. + if (d->extreg) { + switch (t->UPB_PRIVATE(ext)) { + case kUpb_ExtMode_Extendable: { + const upb_MiniTableExtension* ext = + upb_ExtensionRegistry_Lookup(d->extreg, t, field_number); + if (ext) return upb_MiniTableExtension_AsField(ext); + break; + } + case kUpb_ExtMode_IsMessageSet: + if (field_number == kUpb_MsgSet_Item) { + static upb_MiniTableField item = { + 0, 0, 0, 0, kUpb_FakeFieldType_MessageSetItem, 0}; + return &item; + } + break; + } + } -struct upb_DefPool { - upb_Arena* arena; - upb_strtable syms; // full_name -> packed def ptr - upb_strtable files; // file_name -> (upb_FileDef*) - upb_inttable exts; // (upb_MiniTableExtension*) -> (upb_FieldDef*) - upb_ExtensionRegistry* extreg; - const UPB_DESC(FeatureSetDefaults) * feature_set_defaults; - upb_MiniTablePlatform platform; - void* scratch_data; - size_t scratch_size; - size_t bytes_loaded; -}; + return &none; /* Unknown field. */ -void upb_DefPool_Free(upb_DefPool* s) { - upb_Arena_Free(s->arena); - upb_gfree(s->scratch_data); - upb_gfree(s); +found: + UPB_ASSERT(t->UPB_PRIVATE(fields)[idx].UPB_PRIVATE(number) == field_number); + *last_field_index = idx; + return &t->UPB_PRIVATE(fields)[idx]; } -static const char serialized_defaults[] = UPB_INTERNAL_UPB_EDITION_DEFAULTS; - -upb_DefPool* upb_DefPool_New(void) { - upb_DefPool* s = upb_gmalloc(sizeof(*s)); - if (!s) return NULL; - - s->arena = upb_Arena_New(); - s->bytes_loaded = 0; - - s->scratch_size = 240; - s->scratch_data = upb_gmalloc(s->scratch_size); - if (!s->scratch_data) goto err; - - if (!upb_strtable_init(&s->syms, 32, s->arena)) goto err; - if (!upb_strtable_init(&s->files, 4, s->arena)) goto err; - if (!upb_inttable_init(&s->exts, s->arena)) goto err; - - s->extreg = upb_ExtensionRegistry_New(s->arena); - if (!s->extreg) goto err; +int _upb_Decoder_GetVarintOp(const upb_MiniTableField* field) { + static const int8_t kVarintOps[] = { + [kUpb_FakeFieldType_FieldNotFound] = kUpb_DecodeOp_UnknownField, + [kUpb_FieldType_Double] = kUpb_DecodeOp_UnknownField, + [kUpb_FieldType_Float] = kUpb_DecodeOp_UnknownField, + [kUpb_FieldType_Int64] = kUpb_DecodeOp_Scalar8Byte, + [kUpb_FieldType_UInt64] = kUpb_DecodeOp_Scalar8Byte, + [kUpb_FieldType_Int32] = kUpb_DecodeOp_Scalar4Byte, + [kUpb_FieldType_Fixed64] = kUpb_DecodeOp_UnknownField, + [kUpb_FieldType_Fixed32] = kUpb_DecodeOp_UnknownField, + [kUpb_FieldType_Bool] = kUpb_DecodeOp_Scalar1Byte, + [kUpb_FieldType_String] = kUpb_DecodeOp_UnknownField, + [kUpb_FieldType_Group] = kUpb_DecodeOp_UnknownField, + [kUpb_FieldType_Message] = kUpb_DecodeOp_UnknownField, + [kUpb_FieldType_Bytes] = kUpb_DecodeOp_UnknownField, + [kUpb_FieldType_UInt32] = kUpb_DecodeOp_Scalar4Byte, + [kUpb_FieldType_Enum] = kUpb_DecodeOp_Enum, + [kUpb_FieldType_SFixed32] = kUpb_DecodeOp_UnknownField, + [kUpb_FieldType_SFixed64] = kUpb_DecodeOp_UnknownField, + [kUpb_FieldType_SInt32] = kUpb_DecodeOp_Scalar4Byte, + [kUpb_FieldType_SInt64] = kUpb_DecodeOp_Scalar8Byte, + [kUpb_FakeFieldType_MessageSetItem] = kUpb_DecodeOp_UnknownField, + }; - s->platform = kUpb_MiniTablePlatform_Native; + return kVarintOps[field->UPB_PRIVATE(descriptortype)]; +} - upb_Status status; - if (!upb_DefPool_SetFeatureSetDefaults( - s, serialized_defaults, sizeof(serialized_defaults) - 1, &status)) { - goto err; +UPB_FORCEINLINE +static void _upb_Decoder_CheckUnlinked(upb_Decoder* d, const upb_MiniTable* mt, + const upb_MiniTableField* field, + int* op) { + // If sub-message is not linked, treat as unknown. + if (field->UPB_PRIVATE(mode) & kUpb_LabelFlags_IsExtension) return; + const upb_MiniTable* mt_sub = + _upb_MiniTableSubs_MessageByField(mt->UPB_PRIVATE(subs), field); + if ((d->options & kUpb_DecodeOption_ExperimentalAllowUnlinked) || + !UPB_PRIVATE(_upb_MiniTable_IsEmpty)(mt_sub)) { + return; } - - if (!s->feature_set_defaults) goto err; - - return s; - -err: - upb_DefPool_Free(s); - return NULL; +#ifndef NDEBUG + const upb_MiniTableField* oneof = upb_MiniTable_GetOneof(mt, field); + if (oneof) { + // All other members of the oneof must be message fields that are also + // unlinked. + do { + UPB_ASSERT(upb_MiniTableField_CType(oneof) == kUpb_CType_Message); + const upb_MiniTableSub* oneof_sub = + &mt->UPB_PRIVATE(subs)[oneof->UPB_PRIVATE(submsg_index)]; + UPB_ASSERT(!oneof_sub); + } while (upb_MiniTable_NextOneofField(mt, &oneof)); + } +#endif // NDEBUG + *op = kUpb_DecodeOp_UnknownField; } -const UPB_DESC(FeatureSetDefaults) * - upb_DefPool_FeatureSetDefaults(const upb_DefPool* s) { - return s->feature_set_defaults; -} +int _upb_Decoder_GetDelimitedOp(upb_Decoder* d, const upb_MiniTable* mt, + const upb_MiniTableField* field) { + enum { kRepeatedBase = 19 }; -bool upb_DefPool_SetFeatureSetDefaults(upb_DefPool* s, - const char* serialized_defaults, - size_t serialized_len, - upb_Status* status) { - const UPB_DESC(FeatureSetDefaults)* defaults = UPB_DESC( - FeatureSetDefaults_parse)(serialized_defaults, serialized_len, s->arena); - if (!defaults) { - upb_Status_SetErrorFormat(status, "Failed to parse defaults"); - return false; - } - if (upb_strtable_count(&s->files) > 0) { - upb_Status_SetErrorFormat(status, - "Feature set defaults can't be changed once the " - "pool has started building"); - return false; - } - int min_edition = UPB_DESC(FeatureSetDefaults_minimum_edition(defaults)); - int max_edition = UPB_DESC(FeatureSetDefaults_maximum_edition(defaults)); - if (min_edition > max_edition) { - upb_Status_SetErrorFormat(status, "Invalid edition range %s to %s", - upb_FileDef_EditionName(min_edition), - upb_FileDef_EditionName(max_edition)); - return false; - } - size_t size; - const UPB_DESC( - FeatureSetDefaults_FeatureSetEditionDefault)* const* default_list = - UPB_DESC(FeatureSetDefaults_defaults(defaults, &size)); - int prev_edition = UPB_DESC(EDITION_UNKNOWN); - for (size_t i = 0; i < size; ++i) { - int edition = UPB_DESC( - FeatureSetDefaults_FeatureSetEditionDefault_edition(default_list[i])); - if (edition == UPB_DESC(EDITION_UNKNOWN)) { - upb_Status_SetErrorFormat(status, "Invalid edition UNKNOWN specified"); - return false; - } - if (edition <= prev_edition) { - upb_Status_SetErrorFormat(status, - "Feature set defaults are not strictly " - "increasing, %s is greater than or equal to %s", - upb_FileDef_EditionName(prev_edition), - upb_FileDef_EditionName(edition)); - return false; - } - prev_edition = edition; - } - - // Copy the defaults into the pool. - s->feature_set_defaults = defaults; - return true; -} + static const int8_t kDelimitedOps[] = { + /* For non-repeated field type. */ + [kUpb_FakeFieldType_FieldNotFound] = + kUpb_DecodeOp_UnknownField, // Field not found. + [kUpb_FieldType_Double] = kUpb_DecodeOp_UnknownField, + [kUpb_FieldType_Float] = kUpb_DecodeOp_UnknownField, + [kUpb_FieldType_Int64] = kUpb_DecodeOp_UnknownField, + [kUpb_FieldType_UInt64] = kUpb_DecodeOp_UnknownField, + [kUpb_FieldType_Int32] = kUpb_DecodeOp_UnknownField, + [kUpb_FieldType_Fixed64] = kUpb_DecodeOp_UnknownField, + [kUpb_FieldType_Fixed32] = kUpb_DecodeOp_UnknownField, + [kUpb_FieldType_Bool] = kUpb_DecodeOp_UnknownField, + [kUpb_FieldType_String] = kUpb_DecodeOp_String, + [kUpb_FieldType_Group] = kUpb_DecodeOp_UnknownField, + [kUpb_FieldType_Message] = kUpb_DecodeOp_SubMessage, + [kUpb_FieldType_Bytes] = kUpb_DecodeOp_Bytes, + [kUpb_FieldType_UInt32] = kUpb_DecodeOp_UnknownField, + [kUpb_FieldType_Enum] = kUpb_DecodeOp_UnknownField, + [kUpb_FieldType_SFixed32] = kUpb_DecodeOp_UnknownField, + [kUpb_FieldType_SFixed64] = kUpb_DecodeOp_UnknownField, + [kUpb_FieldType_SInt32] = kUpb_DecodeOp_UnknownField, + [kUpb_FieldType_SInt64] = kUpb_DecodeOp_UnknownField, + [kUpb_FakeFieldType_MessageSetItem] = kUpb_DecodeOp_UnknownField, + // For repeated field type. */ + [kRepeatedBase + kUpb_FieldType_Double] = OP_FIXPCK_LG2(3), + [kRepeatedBase + kUpb_FieldType_Float] = OP_FIXPCK_LG2(2), + [kRepeatedBase + kUpb_FieldType_Int64] = OP_VARPCK_LG2(3), + [kRepeatedBase + kUpb_FieldType_UInt64] = OP_VARPCK_LG2(3), + [kRepeatedBase + kUpb_FieldType_Int32] = OP_VARPCK_LG2(2), + [kRepeatedBase + kUpb_FieldType_Fixed64] = OP_FIXPCK_LG2(3), + [kRepeatedBase + kUpb_FieldType_Fixed32] = OP_FIXPCK_LG2(2), + [kRepeatedBase + kUpb_FieldType_Bool] = OP_VARPCK_LG2(0), + [kRepeatedBase + kUpb_FieldType_String] = kUpb_DecodeOp_String, + [kRepeatedBase + kUpb_FieldType_Group] = kUpb_DecodeOp_SubMessage, + [kRepeatedBase + kUpb_FieldType_Message] = kUpb_DecodeOp_SubMessage, + [kRepeatedBase + kUpb_FieldType_Bytes] = kUpb_DecodeOp_Bytes, + [kRepeatedBase + kUpb_FieldType_UInt32] = OP_VARPCK_LG2(2), + [kRepeatedBase + kUpb_FieldType_Enum] = kUpb_DecodeOp_PackedEnum, + [kRepeatedBase + kUpb_FieldType_SFixed32] = OP_FIXPCK_LG2(2), + [kRepeatedBase + kUpb_FieldType_SFixed64] = OP_FIXPCK_LG2(3), + [kRepeatedBase + kUpb_FieldType_SInt32] = OP_VARPCK_LG2(2), + [kRepeatedBase + kUpb_FieldType_SInt64] = OP_VARPCK_LG2(3), + // Omitting kUpb_FakeFieldType_MessageSetItem, because we never emit a + // repeated msgset type + }; -bool _upb_DefPool_InsertExt(upb_DefPool* s, const upb_MiniTableExtension* ext, - const upb_FieldDef* f) { - return upb_inttable_insert(&s->exts, (uintptr_t)ext, upb_value_constptr(f), - s->arena); -} + int ndx = field->UPB_PRIVATE(descriptortype); + if (upb_MiniTableField_IsArray(field)) ndx += kRepeatedBase; + int op = kDelimitedOps[ndx]; -bool _upb_DefPool_InsertSym(upb_DefPool* s, upb_StringView sym, upb_value v, - upb_Status* status) { - // TODO: table should support an operation "tryinsert" to avoid the double - // lookup. - if (upb_strtable_lookup2(&s->syms, sym.data, sym.size, NULL)) { - upb_Status_SetErrorFormat(status, "duplicate symbol '%s'", sym.data); - return false; - } - if (!upb_strtable_insert(&s->syms, sym.data, sym.size, v, s->arena)) { - upb_Status_SetErrorMessage(status, "out of memory"); - return false; + if (op == kUpb_DecodeOp_SubMessage) { + _upb_Decoder_CheckUnlinked(d, mt, field, &op); } - return true; -} -static const void* _upb_DefPool_Unpack(const upb_DefPool* s, const char* sym, - size_t size, upb_deftype_t type) { - upb_value v; - return upb_strtable_lookup2(&s->syms, sym, size, &v) - ? _upb_DefType_Unpack(v, type) - : NULL; + return op; } -bool _upb_DefPool_LookupSym(const upb_DefPool* s, const char* sym, size_t size, - upb_value* v) { - return upb_strtable_lookup2(&s->syms, sym, size, v); -} +UPB_FORCEINLINE +static const char* _upb_Decoder_DecodeWireValue(upb_Decoder* d, const char* ptr, + const upb_MiniTable* mt, + const upb_MiniTableField* field, + int wire_type, wireval* val, + int* op) { + static const unsigned kFixed32OkMask = (1 << kUpb_FieldType_Float) | + (1 << kUpb_FieldType_Fixed32) | + (1 << kUpb_FieldType_SFixed32); -upb_ExtensionRegistry* _upb_DefPool_ExtReg(const upb_DefPool* s) { - return s->extreg; -} + static const unsigned kFixed64OkMask = (1 << kUpb_FieldType_Double) | + (1 << kUpb_FieldType_Fixed64) | + (1 << kUpb_FieldType_SFixed64); -void** _upb_DefPool_ScratchData(const upb_DefPool* s) { - return (void**)&s->scratch_data; + switch (wire_type) { + case kUpb_WireType_Varint: + ptr = _upb_Decoder_DecodeVarint(d, ptr, &val->uint64_val); + *op = _upb_Decoder_GetVarintOp(field); + _upb_Decoder_Munge(field->UPB_PRIVATE(descriptortype), val); + return ptr; + case kUpb_WireType_32Bit: + *op = kUpb_DecodeOp_Scalar4Byte; + if (((1 << field->UPB_PRIVATE(descriptortype)) & kFixed32OkMask) == 0) { + *op = kUpb_DecodeOp_UnknownField; + } + return upb_WireReader_ReadFixed32(ptr, &val->uint32_val); + case kUpb_WireType_64Bit: + *op = kUpb_DecodeOp_Scalar8Byte; + if (((1 << field->UPB_PRIVATE(descriptortype)) & kFixed64OkMask) == 0) { + *op = kUpb_DecodeOp_UnknownField; + } + return upb_WireReader_ReadFixed64(ptr, &val->uint64_val); + case kUpb_WireType_Delimited: + ptr = upb_Decoder_DecodeSize(d, ptr, &val->size); + *op = _upb_Decoder_GetDelimitedOp(d, mt, field); + return ptr; + case kUpb_WireType_StartGroup: + val->uint32_val = field->UPB_PRIVATE(number); + if (field->UPB_PRIVATE(descriptortype) == kUpb_FieldType_Group) { + *op = kUpb_DecodeOp_SubMessage; + _upb_Decoder_CheckUnlinked(d, mt, field, op); + } else if (field->UPB_PRIVATE(descriptortype) == + kUpb_FakeFieldType_MessageSetItem) { + *op = kUpb_DecodeOp_MessageSetItem; + } else { + *op = kUpb_DecodeOp_UnknownField; + } + return ptr; + default: + break; + } + _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_Malformed); } -size_t* _upb_DefPool_ScratchSize(const upb_DefPool* s) { - return (size_t*)&s->scratch_size; -} +UPB_FORCEINLINE +static const char* _upb_Decoder_DecodeKnownField( + upb_Decoder* d, const char* ptr, upb_Message* msg, + const upb_MiniTable* layout, const upb_MiniTableField* field, int op, + wireval* val) { + const upb_MiniTableSub* subs = layout->UPB_PRIVATE(subs); + uint8_t mode = field->UPB_PRIVATE(mode); -void _upb_DefPool_SetPlatform(upb_DefPool* s, upb_MiniTablePlatform platform) { - assert(upb_strtable_count(&s->files) == 0); - s->platform = platform; -} + if (UPB_UNLIKELY(mode & kUpb_LabelFlags_IsExtension)) { + const upb_MiniTableExtension* ext_layout = + (const upb_MiniTableExtension*)field; + upb_Extension* ext = + _upb_Message_GetOrCreateExtension(msg, ext_layout, &d->arena); + if (UPB_UNLIKELY(!ext)) { + _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_OutOfMemory); + } + d->unknown_msg = msg; + msg = (upb_Message*)&ext->data; + subs = &ext->ext->UPB_PRIVATE(sub); + } -const upb_MessageDef* upb_DefPool_FindMessageByName(const upb_DefPool* s, - const char* sym) { - return _upb_DefPool_Unpack(s, sym, strlen(sym), UPB_DEFTYPE_MSG); + switch (mode & kUpb_FieldMode_Mask) { + case kUpb_FieldMode_Array: + return _upb_Decoder_DecodeToArray(d, ptr, msg, subs, field, val, op); + case kUpb_FieldMode_Map: + return _upb_Decoder_DecodeToMap(d, ptr, msg, subs, field, val); + case kUpb_FieldMode_Scalar: + return _upb_Decoder_DecodeToSubMessage(d, ptr, msg, subs, field, val, op); + default: + UPB_UNREACHABLE(); + } } -const upb_MessageDef* upb_DefPool_FindMessageByNameWithSize( - const upb_DefPool* s, const char* sym, size_t len) { - return _upb_DefPool_Unpack(s, sym, len, UPB_DEFTYPE_MSG); +static const char* _upb_Decoder_ReverseSkipVarint(const char* ptr, + uint32_t val) { + uint32_t seen = 0; + do { + ptr--; + seen <<= 7; + seen |= *ptr & 0x7f; + } while (seen != val); + return ptr; } -const upb_EnumDef* upb_DefPool_FindEnumByName(const upb_DefPool* s, - const char* sym) { - return _upb_DefPool_Unpack(s, sym, strlen(sym), UPB_DEFTYPE_ENUM); -} +static const char* _upb_Decoder_DecodeUnknownField(upb_Decoder* d, + const char* ptr, + upb_Message* msg, + int field_number, + int wire_type, wireval val) { + if (field_number == 0) _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_Malformed); -const upb_EnumValueDef* upb_DefPool_FindEnumByNameval(const upb_DefPool* s, - const char* sym) { - return _upb_DefPool_Unpack(s, sym, strlen(sym), UPB_DEFTYPE_ENUMVAL); -} + // Since unknown fields are the uncommon case, we do a little extra work here + // to walk backwards through the buffer to find the field start. This frees + // up a register in the fast paths (when the field is known), which leads to + // significant speedups in benchmarks. + const char* start = ptr; -const upb_FileDef* upb_DefPool_FindFileByName(const upb_DefPool* s, - const char* name) { - upb_value v; - return upb_strtable_lookup(&s->files, name, &v) ? upb_value_getconstptr(v) - : NULL; -} + if (wire_type == kUpb_WireType_Delimited) ptr += val.size; + if (msg) { + switch (wire_type) { + case kUpb_WireType_Varint: + case kUpb_WireType_Delimited: + start--; + while (start[-1] & 0x80) start--; + break; + case kUpb_WireType_32Bit: + start -= 4; + break; + case kUpb_WireType_64Bit: + start -= 8; + break; + default: + break; + } -const upb_FileDef* upb_DefPool_FindFileByNameWithSize(const upb_DefPool* s, - const char* name, - size_t len) { - upb_value v; - return upb_strtable_lookup2(&s->files, name, len, &v) - ? upb_value_getconstptr(v) - : NULL; -} - -const upb_FieldDef* upb_DefPool_FindExtensionByNameWithSize( - const upb_DefPool* s, const char* name, size_t size) { - upb_value v; - if (!upb_strtable_lookup2(&s->syms, name, size, &v)) return NULL; + assert(start == d->debug_valstart); + uint32_t tag = ((uint32_t)field_number << 3) | wire_type; + start = _upb_Decoder_ReverseSkipVarint(start, tag); + assert(start == d->debug_tagstart); - switch (_upb_DefType_Type(v)) { - case UPB_DEFTYPE_FIELD: - return _upb_DefType_Unpack(v, UPB_DEFTYPE_FIELD); - case UPB_DEFTYPE_MSG: { - const upb_MessageDef* m = _upb_DefType_Unpack(v, UPB_DEFTYPE_MSG); - return _upb_MessageDef_InMessageSet(m) - ? upb_MessageDef_NestedExtension(m, 0) - : NULL; + if (wire_type == kUpb_WireType_StartGroup) { + d->unknown = start; + d->unknown_msg = msg; + ptr = _upb_Decoder_DecodeUnknownGroup(d, ptr, field_number); + start = d->unknown; + d->unknown = NULL; } - default: - break; + if (!UPB_PRIVATE(_upb_Message_AddUnknown)(msg, start, ptr - start, + &d->arena)) { + _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_OutOfMemory); + } + } else if (wire_type == kUpb_WireType_StartGroup) { + ptr = _upb_Decoder_DecodeUnknownGroup(d, ptr, field_number); } - - return NULL; + return ptr; } -const upb_FieldDef* upb_DefPool_FindExtensionByName(const upb_DefPool* s, - const char* sym) { - return upb_DefPool_FindExtensionByNameWithSize(s, sym, strlen(sym)); -} +UPB_NOINLINE +static const char* _upb_Decoder_DecodeMessage(upb_Decoder* d, const char* ptr, + upb_Message* msg, + const upb_MiniTable* layout) { + int last_field_index = 0; -const upb_ServiceDef* upb_DefPool_FindServiceByName(const upb_DefPool* s, - const char* name) { - return _upb_DefPool_Unpack(s, name, strlen(name), UPB_DEFTYPE_SERVICE); -} +#if UPB_FASTTABLE + // The first time we want to skip fast dispatch, because we may have just been + // invoked by the fast parser to handle a case that it bailed on. + if (!_upb_Decoder_IsDone(d, &ptr)) goto nofast; +#endif -const upb_ServiceDef* upb_DefPool_FindServiceByNameWithSize( - const upb_DefPool* s, const char* name, size_t size) { - return _upb_DefPool_Unpack(s, name, size, UPB_DEFTYPE_SERVICE); -} + while (!_upb_Decoder_IsDone(d, &ptr)) { + uint32_t tag; + const upb_MiniTableField* field; + int field_number; + int wire_type; + wireval val; + int op; -const upb_FileDef* upb_DefPool_FindFileContainingSymbol(const upb_DefPool* s, - const char* name) { - upb_value v; - // TODO: non-extension fields and oneofs. - if (upb_strtable_lookup(&s->syms, name, &v)) { - switch (_upb_DefType_Type(v)) { - case UPB_DEFTYPE_EXT: { - const upb_FieldDef* f = _upb_DefType_Unpack(v, UPB_DEFTYPE_EXT); - return upb_FieldDef_File(f); - } - case UPB_DEFTYPE_MSG: { - const upb_MessageDef* m = _upb_DefType_Unpack(v, UPB_DEFTYPE_MSG); - return upb_MessageDef_File(m); - } - case UPB_DEFTYPE_ENUM: { - const upb_EnumDef* e = _upb_DefType_Unpack(v, UPB_DEFTYPE_ENUM); - return upb_EnumDef_File(e); - } - case UPB_DEFTYPE_ENUMVAL: { - const upb_EnumValueDef* ev = - _upb_DefType_Unpack(v, UPB_DEFTYPE_ENUMVAL); - return upb_EnumDef_File(upb_EnumValueDef_Enum(ev)); - } - case UPB_DEFTYPE_SERVICE: { - const upb_ServiceDef* service = - _upb_DefType_Unpack(v, UPB_DEFTYPE_SERVICE); - return upb_ServiceDef_File(service); - } - default: - UPB_UNREACHABLE(); + if (_upb_Decoder_TryFastDispatch(d, &ptr, msg, layout)) break; + +#if UPB_FASTTABLE + nofast: +#endif + +#ifndef NDEBUG + d->debug_tagstart = ptr; +#endif + + UPB_ASSERT(ptr < d->input.limit_ptr); + ptr = _upb_Decoder_DecodeTag(d, ptr, &tag); + field_number = tag >> 3; + wire_type = tag & 7; + +#ifndef NDEBUG + d->debug_valstart = ptr; +#endif + + if (wire_type == kUpb_WireType_EndGroup) { + d->end_group = field_number; + return ptr; } - } - const char* last_dot = strrchr(name, '.'); - if (last_dot) { - const upb_MessageDef* parent = - upb_DefPool_FindMessageByNameWithSize(s, name, last_dot - name); - if (parent) { - const char* shortname = last_dot + 1; - if (upb_MessageDef_FindByNameWithSize(parent, shortname, - strlen(shortname), NULL, NULL)) { - return upb_MessageDef_File(parent); + field = _upb_Decoder_FindField(d, layout, field_number, &last_field_index); + ptr = _upb_Decoder_DecodeWireValue(d, ptr, layout, field, wire_type, &val, + &op); + + if (op >= 0) { + ptr = _upb_Decoder_DecodeKnownField(d, ptr, msg, layout, field, op, &val); + } else { + switch (op) { + case kUpb_DecodeOp_UnknownField: + ptr = _upb_Decoder_DecodeUnknownField(d, ptr, msg, field_number, + wire_type, val); + break; + case kUpb_DecodeOp_MessageSetItem: + ptr = upb_Decoder_DecodeMessageSetItem(d, ptr, msg, layout); + break; } } } - return NULL; + return UPB_UNLIKELY(layout && layout->UPB_PRIVATE(required_count)) + ? _upb_Decoder_CheckRequired(d, ptr, msg, layout) + : ptr; } -static void remove_filedef(upb_DefPool* s, upb_FileDef* file) { - intptr_t iter = UPB_INTTABLE_BEGIN; - upb_StringView key; - upb_value val; - while (upb_strtable_next2(&s->syms, &key, &val, &iter)) { - const upb_FileDef* f; - switch (_upb_DefType_Type(val)) { - case UPB_DEFTYPE_EXT: - f = upb_FieldDef_File(_upb_DefType_Unpack(val, UPB_DEFTYPE_EXT)); - break; - case UPB_DEFTYPE_MSG: - f = upb_MessageDef_File(_upb_DefType_Unpack(val, UPB_DEFTYPE_MSG)); - break; - case UPB_DEFTYPE_ENUM: - f = upb_EnumDef_File(_upb_DefType_Unpack(val, UPB_DEFTYPE_ENUM)); - break; - case UPB_DEFTYPE_ENUMVAL: - f = upb_EnumDef_File(upb_EnumValueDef_Enum( - _upb_DefType_Unpack(val, UPB_DEFTYPE_ENUMVAL))); - break; - case UPB_DEFTYPE_SERVICE: - f = upb_ServiceDef_File(_upb_DefType_Unpack(val, UPB_DEFTYPE_SERVICE)); - break; - default: - UPB_UNREACHABLE(); - } +const char* _upb_FastDecoder_DecodeGeneric(struct upb_Decoder* d, + const char* ptr, upb_Message* msg, + intptr_t table, uint64_t hasbits, + uint64_t data) { + (void)data; + *(uint32_t*)msg |= hasbits; + return _upb_Decoder_DecodeMessage(d, ptr, msg, decode_totablep(table)); +} - if (f == file) upb_strtable_removeiter(&s->syms, &iter); +static upb_DecodeStatus _upb_Decoder_DecodeTop(struct upb_Decoder* d, + const char* buf, void* msg, + const upb_MiniTable* l) { + if (!_upb_Decoder_TryFastDispatch(d, &buf, msg, l)) { + _upb_Decoder_DecodeMessage(d, buf, msg, l); } + if (d->end_group != DECODE_NOGROUP) return kUpb_DecodeStatus_Malformed; + if (d->missing_required) return kUpb_DecodeStatus_MissingRequired; + return kUpb_DecodeStatus_Ok; } -static const upb_FileDef* upb_DefBuilder_AddFileToPool( - upb_DefBuilder* const builder, upb_DefPool* const s, - const UPB_DESC(FileDescriptorProto) * const file_proto, - const upb_StringView name, upb_Status* const status) { - if (UPB_SETJMP(builder->err) != 0) { - UPB_ASSERT(!upb_Status_IsOk(status)); - if (builder->file) { - remove_filedef(s, builder->file); - builder->file = NULL; - } - } else if (!builder->arena || !builder->tmp_arena || - !upb_strtable_init(&builder->feature_cache, 16, - builder->tmp_arena) || - !(builder->legacy_features = - UPB_DESC(FeatureSet_new)(builder->tmp_arena))) { - _upb_DefBuilder_OomErr(builder); +UPB_NOINLINE +const char* _upb_Decoder_IsDoneFallback(upb_EpsCopyInputStream* e, + const char* ptr, int overrun) { + return _upb_EpsCopyInputStream_IsDoneFallbackInline( + e, ptr, overrun, _upb_Decoder_BufferFlipCallback); +} + +static upb_DecodeStatus upb_Decoder_Decode(upb_Decoder* const decoder, + const char* const buf, + void* const msg, + const upb_MiniTable* const l, + upb_Arena* const arena) { + if (UPB_SETJMP(decoder->err) == 0) { + decoder->status = _upb_Decoder_DecodeTop(decoder, buf, msg, l); } else { - _upb_FileDef_Create(builder, file_proto); - upb_strtable_insert(&s->files, name.data, name.size, - upb_value_constptr(builder->file), builder->arena); - UPB_ASSERT(upb_Status_IsOk(status)); - upb_Arena_Fuse(s->arena, builder->arena); + UPB_ASSERT(decoder->status != kUpb_DecodeStatus_Ok); } - if (builder->arena) upb_Arena_Free(builder->arena); - if (builder->tmp_arena) upb_Arena_Free(builder->tmp_arena); - return builder->file; + UPB_PRIVATE(_upb_Arena_SwapOut)(arena, &decoder->arena); + + return decoder->status; } -static const upb_FileDef* _upb_DefPool_AddFile( - upb_DefPool* s, const UPB_DESC(FileDescriptorProto) * file_proto, - const upb_MiniTableFile* layout, upb_Status* status) { - const upb_StringView name = UPB_DESC(FileDescriptorProto_name)(file_proto); +upb_DecodeStatus upb_Decode(const char* buf, size_t size, upb_Message* msg, + const upb_MiniTable* l, + const upb_ExtensionRegistry* extreg, int options, + upb_Arena* arena) { + upb_Decoder decoder; + unsigned depth = (unsigned)options >> 16; - // Determine whether we already know about this file. - { - upb_value v; - if (upb_strtable_lookup2(&s->files, name.data, name.size, &v)) { - upb_Status_SetErrorFormat(status, - "duplicate file name " UPB_STRINGVIEW_FORMAT, - UPB_STRINGVIEW_ARGS(name)); - return NULL; - } - } + upb_EpsCopyInputStream_Init(&decoder.input, &buf, size, + options & kUpb_DecodeOption_AliasString); - upb_DefBuilder ctx = { - .symtab = s, - .tmp_buf = NULL, - .tmp_buf_size = 0, - .layout = layout, - .platform = s->platform, - .msg_count = 0, - .enum_count = 0, - .ext_count = 0, - .status = status, - .file = NULL, - .arena = upb_Arena_New(), - .tmp_arena = upb_Arena_New(), - }; + decoder.extreg = extreg; + decoder.unknown = NULL; + decoder.depth = depth ? depth : kUpb_WireFormat_DefaultDepthLimit; + decoder.end_group = DECODE_NOGROUP; + decoder.options = (uint16_t)options; + decoder.missing_required = false; + decoder.status = kUpb_DecodeStatus_Ok; - return upb_DefBuilder_AddFileToPool(&ctx, s, file_proto, name, status); -} + // Violating the encapsulation of the arena for performance reasons. + // This is a temporary arena that we swap into and swap out of when we are + // done. The temporary arena only needs to be able to handle allocation, + // not fuse or free, so it does not need many of the members to be initialized + // (particularly parent_or_count). + UPB_PRIVATE(_upb_Arena_SwapIn)(&decoder.arena, arena); -const upb_FileDef* upb_DefPool_AddFile(upb_DefPool* s, - const UPB_DESC(FileDescriptorProto) * - file_proto, - upb_Status* status) { - return _upb_DefPool_AddFile(s, file_proto, NULL, status); + return upb_Decoder_Decode(&decoder, buf, msg, l, arena); } -bool _upb_DefPool_LoadDefInitEx(upb_DefPool* s, const _upb_DefPool_Init* init, - bool rebuild_minitable) { - /* Since this function should never fail (it would indicate a bug in upb) we - * print errors to stderr instead of returning error status to the user. */ - _upb_DefPool_Init** deps = init->deps; - UPB_DESC(FileDescriptorProto) * file; - upb_Arena* arena; - upb_Status status; - - upb_Status_Clear(&status); - - if (upb_DefPool_FindFileByName(s, init->filename)) { - return true; - } +#undef OP_FIXPCK_LG2 +#undef OP_VARPCK_LG2 - arena = upb_Arena_New(); +// We encode backwards, to avoid pre-computing lengths (one-pass encode). - for (; *deps; deps++) { - if (!_upb_DefPool_LoadDefInitEx(s, *deps, rebuild_minitable)) goto err; - } - file = UPB_DESC(FileDescriptorProto_parse_ex)( - init->descriptor.data, init->descriptor.size, NULL, - kUpb_DecodeOption_AliasString, arena); - s->bytes_loaded += init->descriptor.size; +#include +#include +#include +#include - if (!file) { - upb_Status_SetErrorFormat( - &status, - "Failed to parse compiled-in descriptor for file '%s'. This should " - "never happen.", - init->filename); - goto err; - } - const upb_MiniTableFile* mt = rebuild_minitable ? NULL : init->layout; - if (!_upb_DefPool_AddFile(s, file, mt, &status)) { - goto err; - } +// Must be last. - upb_Arena_Free(arena); - return true; +#define UPB_PB_VARINT_MAX_LEN 10 -err: - fprintf(stderr, - "Error loading compiled-in descriptor for file '%s' (this should " - "never happen): %s\n", - init->filename, upb_Status_ErrorMessage(&status)); - upb_Arena_Free(arena); - return false; +UPB_NOINLINE +static size_t encode_varint64(uint64_t val, char* buf) { + size_t i = 0; + do { + uint8_t byte = val & 0x7fU; + val >>= 7; + if (val) byte |= 0x80U; + buf[i++] = byte; + } while (val); + return i; } -size_t _upb_DefPool_BytesLoaded(const upb_DefPool* s) { - return s->bytes_loaded; +static uint32_t encode_zz32(int32_t n) { + return ((uint32_t)n << 1) ^ (n >> 31); +} +static uint64_t encode_zz64(int64_t n) { + return ((uint64_t)n << 1) ^ (n >> 63); } -upb_Arena* _upb_DefPool_Arena(const upb_DefPool* s) { return s->arena; } +typedef struct { + upb_EncodeStatus status; + jmp_buf err; + upb_Arena* arena; + char *buf, *ptr, *limit; + int options; + int depth; + _upb_mapsorter sorter; +} upb_encstate; -const upb_FieldDef* upb_DefPool_FindExtensionByMiniTable( - const upb_DefPool* s, const upb_MiniTableExtension* ext) { - upb_value v; - bool ok = upb_inttable_lookup(&s->exts, (uintptr_t)ext, &v); - UPB_ASSERT(ok); - return upb_value_getconstptr(v); +static size_t upb_roundup_pow2(size_t bytes) { + size_t ret = 128; + while (ret < bytes) { + ret *= 2; + } + return ret; } -const upb_FieldDef* upb_DefPool_FindExtensionByNumber(const upb_DefPool* s, - const upb_MessageDef* m, - int32_t fieldnum) { - const upb_MiniTable* t = upb_MessageDef_MiniTable(m); - const upb_MiniTableExtension* ext = - upb_ExtensionRegistry_Lookup(s->extreg, t, fieldnum); - return ext ? upb_DefPool_FindExtensionByMiniTable(s, ext) : NULL; +UPB_NORETURN static void encode_err(upb_encstate* e, upb_EncodeStatus s) { + UPB_ASSERT(s != kUpb_EncodeStatus_Ok); + e->status = s; + UPB_LONGJMP(e->err, 1); } -const upb_ExtensionRegistry* upb_DefPool_ExtensionRegistry( - const upb_DefPool* s) { - return s->extreg; -} +UPB_NOINLINE +static void encode_growbuffer(upb_encstate* e, size_t bytes) { + size_t old_size = e->limit - e->buf; + size_t new_size = upb_roundup_pow2(bytes + (e->limit - e->ptr)); + char* new_buf = upb_Arena_Realloc(e->arena, e->buf, old_size, new_size); -const upb_FieldDef** upb_DefPool_GetAllExtensions(const upb_DefPool* s, - const upb_MessageDef* m, - size_t* count) { - size_t n = 0; - intptr_t iter = UPB_INTTABLE_BEGIN; - uintptr_t key; - upb_value val; - // This is O(all exts) instead of O(exts for m). If we need this to be - // efficient we may need to make extreg into a two-level table, or have a - // second per-message index. - while (upb_inttable_next(&s->exts, &key, &val, &iter)) { - const upb_FieldDef* f = upb_value_getconstptr(val); - if (upb_FieldDef_ContainingType(f) == m) n++; - } - const upb_FieldDef** exts = upb_gmalloc(n * sizeof(*exts)); - iter = UPB_INTTABLE_BEGIN; - size_t i = 0; - while (upb_inttable_next(&s->exts, &key, &val, &iter)) { - const upb_FieldDef* f = upb_value_getconstptr(val); - if (upb_FieldDef_ContainingType(f) == m) exts[i++] = f; + if (!new_buf) encode_err(e, kUpb_EncodeStatus_OutOfMemory); + + // We want previous data at the end, realloc() put it at the beginning. + // TODO: This is somewhat inefficient since we are copying twice. + // Maybe create a realloc() that copies to the end of the new buffer? + if (old_size > 0) { + memmove(new_buf + new_size - old_size, e->buf, old_size); } - *count = n; - return exts; -} -bool _upb_DefPool_LoadDefInit(upb_DefPool* s, const _upb_DefPool_Init* init) { - return _upb_DefPool_LoadDefInitEx(s, init, false); -} + e->ptr = new_buf + new_size - (e->limit - e->ptr); + e->limit = new_buf + new_size; + e->buf = new_buf; + e->ptr -= bytes; +} -// Must be last. +/* Call to ensure that at least "bytes" bytes are available for writing at + * e->ptr. Returns false if the bytes could not be allocated. */ +UPB_FORCEINLINE +static void encode_reserve(upb_encstate* e, size_t bytes) { + if ((size_t)(e->ptr - e->buf) < bytes) { + encode_growbuffer(e, bytes); + return; + } -upb_deftype_t _upb_DefType_Type(upb_value v) { - const uintptr_t num = (uintptr_t)upb_value_getconstptr(v); - return num & UPB_DEFTYPE_MASK; + e->ptr -= bytes; } -upb_value _upb_DefType_Pack(const void* ptr, upb_deftype_t type) { - uintptr_t num = (uintptr_t)ptr; - UPB_ASSERT((num & UPB_DEFTYPE_MASK) == 0); - num |= type; - return upb_value_constptr((const void*)num); +/* Writes the given bytes to the buffer, handling reserve/advance. */ +static void encode_bytes(upb_encstate* e, const void* data, size_t len) { + if (len == 0) return; /* memcpy() with zero size is UB */ + encode_reserve(e, len); + memcpy(e->ptr, data, len); } -const void* _upb_DefType_Unpack(upb_value v, upb_deftype_t type) { - uintptr_t num = (uintptr_t)upb_value_getconstptr(v); - return (num & UPB_DEFTYPE_MASK) == type - ? (const void*)(num & ~UPB_DEFTYPE_MASK) - : NULL; +static void encode_fixed64(upb_encstate* e, uint64_t val) { + val = UPB_PRIVATE(_upb_BigEndian64)(val); + encode_bytes(e, &val, sizeof(uint64_t)); } +static void encode_fixed32(upb_encstate* e, uint32_t val) { + val = UPB_PRIVATE(_upb_BigEndian32)(val); + encode_bytes(e, &val, sizeof(uint32_t)); +} -// Must be last. - -bool _upb_DescState_Grow(upb_DescState* d, upb_Arena* a) { - const size_t oldbufsize = d->bufsize; - const int used = d->ptr - d->buf; +UPB_NOINLINE +static void encode_longvarint(upb_encstate* e, uint64_t val) { + size_t len; + char* start; - if (!d->buf) { - d->buf = upb_Arena_Malloc(a, d->bufsize); - if (!d->buf) return false; - d->ptr = d->buf; - d->e.end = d->buf + d->bufsize; - } + encode_reserve(e, UPB_PB_VARINT_MAX_LEN); + len = encode_varint64(val, e->ptr); + start = e->ptr + UPB_PB_VARINT_MAX_LEN - len; + memmove(start, e->ptr, len); + e->ptr = start; +} - if (oldbufsize - used < kUpb_MtDataEncoder_MinSize) { - d->bufsize *= 2; - d->buf = upb_Arena_Realloc(a, d->buf, oldbufsize, d->bufsize); - if (!d->buf) return false; - d->ptr = d->buf + used; - d->e.end = d->buf + d->bufsize; +UPB_FORCEINLINE +static void encode_varint(upb_encstate* e, uint64_t val) { + if (val < 128 && e->ptr != e->buf) { + --e->ptr; + *e->ptr = val; + } else { + encode_longvarint(e, val); } - - return true; } - -#include -#include -#include - - -// Must be last. - -struct upb_EnumDef { - const UPB_DESC(EnumOptions*) opts; - const UPB_DESC(FeatureSet*) resolved_features; - const upb_MiniTableEnum* layout; // Only for proto2. - const upb_FileDef* file; - const upb_MessageDef* containing_type; // Could be merged with "file". - const char* full_name; - upb_strtable ntoi; - upb_inttable iton; - const upb_EnumValueDef* values; - const upb_EnumReservedRange* res_ranges; - const upb_StringView* res_names; - int value_count; - int res_range_count; - int res_name_count; - int32_t defaultval; - bool is_sorted; // Whether all of the values are defined in ascending order. -#if UINTPTR_MAX == 0xffffffff - uint32_t padding; // Increase size to a multiple of 8. -#endif -}; - -upb_EnumDef* _upb_EnumDef_At(const upb_EnumDef* e, int i) { - return (upb_EnumDef*)&e[i]; -} - -const upb_MiniTableEnum* _upb_EnumDef_MiniTable(const upb_EnumDef* e) { - return e->layout; -} - -bool _upb_EnumDef_Insert(upb_EnumDef* e, upb_EnumValueDef* v, upb_Arena* a) { - const char* name = upb_EnumValueDef_Name(v); - const upb_value val = upb_value_constptr(v); - bool ok = upb_strtable_insert(&e->ntoi, name, strlen(name), val, a); - if (!ok) return false; - - // Multiple enumerators can have the same number, first one wins. - const int number = upb_EnumValueDef_Number(v); - if (!upb_inttable_lookup(&e->iton, number, NULL)) { - return upb_inttable_insert(&e->iton, number, val, a); - } - return true; +static void encode_double(upb_encstate* e, double d) { + uint64_t u64; + UPB_ASSERT(sizeof(double) == sizeof(uint64_t)); + memcpy(&u64, &d, sizeof(uint64_t)); + encode_fixed64(e, u64); } -const UPB_DESC(EnumOptions) * upb_EnumDef_Options(const upb_EnumDef* e) { - return e->opts; +static void encode_float(upb_encstate* e, float d) { + uint32_t u32; + UPB_ASSERT(sizeof(float) == sizeof(uint32_t)); + memcpy(&u32, &d, sizeof(uint32_t)); + encode_fixed32(e, u32); } -bool upb_EnumDef_HasOptions(const upb_EnumDef* e) { - return e->opts != (void*)kUpbDefOptDefault; +static void encode_tag(upb_encstate* e, uint32_t field_number, + uint8_t wire_type) { + encode_varint(e, (field_number << 3) | wire_type); } -const UPB_DESC(FeatureSet) * - upb_EnumDef_ResolvedFeatures(const upb_EnumDef* e) { - return e->resolved_features; -} +static void encode_fixedarray(upb_encstate* e, const upb_Array* arr, + size_t elem_size, uint32_t tag) { + size_t bytes = arr->UPB_PRIVATE(size) * elem_size; + const char* data = _upb_array_constptr(arr); + const char* ptr = data + bytes - elem_size; -const char* upb_EnumDef_FullName(const upb_EnumDef* e) { return e->full_name; } + if (tag || !UPB_PRIVATE(_upb_IsLittleEndian)()) { + while (true) { + if (elem_size == 4) { + uint32_t val; + memcpy(&val, ptr, sizeof(val)); + val = UPB_PRIVATE(_upb_BigEndian32)(val); + encode_bytes(e, &val, elem_size); + } else { + UPB_ASSERT(elem_size == 8); + uint64_t val; + memcpy(&val, ptr, sizeof(val)); + val = UPB_PRIVATE(_upb_BigEndian64)(val); + encode_bytes(e, &val, elem_size); + } -const char* upb_EnumDef_Name(const upb_EnumDef* e) { - return _upb_DefBuilder_FullToShort(e->full_name); + if (tag) encode_varint(e, tag); + if (ptr == data) break; + ptr -= elem_size; + } + } else { + encode_bytes(e, data, bytes); + } } -const upb_FileDef* upb_EnumDef_File(const upb_EnumDef* e) { return e->file; } - -const upb_MessageDef* upb_EnumDef_ContainingType(const upb_EnumDef* e) { - return e->containing_type; -} +static void encode_message(upb_encstate* e, const upb_Message* msg, + const upb_MiniTable* m, size_t* size); -int32_t upb_EnumDef_Default(const upb_EnumDef* e) { - UPB_ASSERT(upb_EnumDef_FindValueByNumber(e, e->defaultval)); - return e->defaultval; +static void encode_TaggedMessagePtr(upb_encstate* e, + upb_TaggedMessagePtr tagged, + const upb_MiniTable* m, size_t* size) { + if (upb_TaggedMessagePtr_IsEmpty(tagged)) { + m = UPB_PRIVATE(_upb_MiniTable_Empty)(); + } + encode_message(e, UPB_PRIVATE(_upb_TaggedMessagePtr_GetMessage)(tagged), m, + size); } -int upb_EnumDef_ReservedRangeCount(const upb_EnumDef* e) { - return e->res_range_count; -} +static void encode_scalar(upb_encstate* e, const void* _field_mem, + const upb_MiniTableSub* subs, + const upb_MiniTableField* f) { + const char* field_mem = _field_mem; + int wire_type; -const upb_EnumReservedRange* upb_EnumDef_ReservedRange(const upb_EnumDef* e, - int i) { - UPB_ASSERT(0 <= i && i < e->res_range_count); - return _upb_EnumReservedRange_At(e->res_ranges, i); -} +#define CASE(ctype, type, wtype, encodeval) \ + { \ + ctype val = *(ctype*)field_mem; \ + encode_##type(e, encodeval); \ + wire_type = wtype; \ + break; \ + } -int upb_EnumDef_ReservedNameCount(const upb_EnumDef* e) { - return e->res_name_count; -} + switch (f->UPB_PRIVATE(descriptortype)) { + case kUpb_FieldType_Double: + CASE(double, double, kUpb_WireType_64Bit, val); + case kUpb_FieldType_Float: + CASE(float, float, kUpb_WireType_32Bit, val); + case kUpb_FieldType_Int64: + case kUpb_FieldType_UInt64: + CASE(uint64_t, varint, kUpb_WireType_Varint, val); + case kUpb_FieldType_UInt32: + CASE(uint32_t, varint, kUpb_WireType_Varint, val); + case kUpb_FieldType_Int32: + case kUpb_FieldType_Enum: + CASE(int32_t, varint, kUpb_WireType_Varint, (int64_t)val); + case kUpb_FieldType_SFixed64: + case kUpb_FieldType_Fixed64: + CASE(uint64_t, fixed64, kUpb_WireType_64Bit, val); + case kUpb_FieldType_Fixed32: + case kUpb_FieldType_SFixed32: + CASE(uint32_t, fixed32, kUpb_WireType_32Bit, val); + case kUpb_FieldType_Bool: + CASE(bool, varint, kUpb_WireType_Varint, val); + case kUpb_FieldType_SInt32: + CASE(int32_t, varint, kUpb_WireType_Varint, encode_zz32(val)); + case kUpb_FieldType_SInt64: + CASE(int64_t, varint, kUpb_WireType_Varint, encode_zz64(val)); + case kUpb_FieldType_String: + case kUpb_FieldType_Bytes: { + upb_StringView view = *(upb_StringView*)field_mem; + encode_bytes(e, view.data, view.size); + encode_varint(e, view.size); + wire_type = kUpb_WireType_Delimited; + break; + } + case kUpb_FieldType_Group: { + size_t size; + upb_TaggedMessagePtr submsg = *(upb_TaggedMessagePtr*)field_mem; + const upb_MiniTable* subm = + upb_MiniTableSub_Message(subs[f->UPB_PRIVATE(submsg_index)]); + if (submsg == 0) { + return; + } + if (--e->depth == 0) encode_err(e, kUpb_EncodeStatus_MaxDepthExceeded); + encode_tag(e, f->UPB_PRIVATE(number), kUpb_WireType_EndGroup); + encode_TaggedMessagePtr(e, submsg, subm, &size); + wire_type = kUpb_WireType_StartGroup; + e->depth++; + break; + } + case kUpb_FieldType_Message: { + size_t size; + upb_TaggedMessagePtr submsg = *(upb_TaggedMessagePtr*)field_mem; + const upb_MiniTable* subm = + upb_MiniTableSub_Message(subs[f->UPB_PRIVATE(submsg_index)]); + if (submsg == 0) { + return; + } + if (--e->depth == 0) encode_err(e, kUpb_EncodeStatus_MaxDepthExceeded); + encode_TaggedMessagePtr(e, submsg, subm, &size); + encode_varint(e, size); + wire_type = kUpb_WireType_Delimited; + e->depth++; + break; + } + default: + UPB_UNREACHABLE(); + } +#undef CASE -upb_StringView upb_EnumDef_ReservedName(const upb_EnumDef* e, int i) { - UPB_ASSERT(0 <= i && i < e->res_name_count); - return e->res_names[i]; + encode_tag(e, f->UPB_PRIVATE(number), wire_type); } -int upb_EnumDef_ValueCount(const upb_EnumDef* e) { return e->value_count; } +static void encode_array(upb_encstate* e, const upb_Message* msg, + const upb_MiniTableSub* subs, + const upb_MiniTableField* f) { + const upb_Array* arr = *UPB_PTR_AT(msg, f->UPB_PRIVATE(offset), upb_Array*); + bool packed = upb_MiniTableField_IsPacked(f); + size_t pre_len = e->limit - e->ptr; -const upb_EnumValueDef* upb_EnumDef_FindValueByName(const upb_EnumDef* e, - const char* name) { - return upb_EnumDef_FindValueByNameWithSize(e, name, strlen(name)); -} + if (arr == NULL || arr->UPB_PRIVATE(size) == 0) { + return; + } -const upb_EnumValueDef* upb_EnumDef_FindValueByNameWithSize( - const upb_EnumDef* e, const char* name, size_t size) { - upb_value v; - return upb_strtable_lookup2(&e->ntoi, name, size, &v) - ? upb_value_getconstptr(v) - : NULL; -} +#define VARINT_CASE(ctype, encode) \ + { \ + const ctype* start = _upb_array_constptr(arr); \ + const ctype* ptr = start + arr->UPB_PRIVATE(size); \ + uint32_t tag = \ + packed ? 0 : (f->UPB_PRIVATE(number) << 3) | kUpb_WireType_Varint; \ + do { \ + ptr--; \ + encode_varint(e, encode); \ + if (tag) encode_varint(e, tag); \ + } while (ptr != start); \ + } \ + break; -const upb_EnumValueDef* upb_EnumDef_FindValueByNumber(const upb_EnumDef* e, - int32_t num) { - upb_value v; - return upb_inttable_lookup(&e->iton, num, &v) ? upb_value_getconstptr(v) - : NULL; -} +#define TAG(wire_type) (packed ? 0 : (f->UPB_PRIVATE(number) << 3 | wire_type)) -bool upb_EnumDef_CheckNumber(const upb_EnumDef* e, int32_t num) { - // We could use upb_EnumDef_FindValueByNumber(e, num) != NULL, but we expect - // this to be faster (especially for small numbers). - return upb_MiniTableEnum_CheckValue(e->layout, num); -} + switch (f->UPB_PRIVATE(descriptortype)) { + case kUpb_FieldType_Double: + encode_fixedarray(e, arr, sizeof(double), TAG(kUpb_WireType_64Bit)); + break; + case kUpb_FieldType_Float: + encode_fixedarray(e, arr, sizeof(float), TAG(kUpb_WireType_32Bit)); + break; + case kUpb_FieldType_SFixed64: + case kUpb_FieldType_Fixed64: + encode_fixedarray(e, arr, sizeof(uint64_t), TAG(kUpb_WireType_64Bit)); + break; + case kUpb_FieldType_Fixed32: + case kUpb_FieldType_SFixed32: + encode_fixedarray(e, arr, sizeof(uint32_t), TAG(kUpb_WireType_32Bit)); + break; + case kUpb_FieldType_Int64: + case kUpb_FieldType_UInt64: + VARINT_CASE(uint64_t, *ptr); + case kUpb_FieldType_UInt32: + VARINT_CASE(uint32_t, *ptr); + case kUpb_FieldType_Int32: + case kUpb_FieldType_Enum: + VARINT_CASE(int32_t, (int64_t)*ptr); + case kUpb_FieldType_Bool: + VARINT_CASE(bool, *ptr); + case kUpb_FieldType_SInt32: + VARINT_CASE(int32_t, encode_zz32(*ptr)); + case kUpb_FieldType_SInt64: + VARINT_CASE(int64_t, encode_zz64(*ptr)); + case kUpb_FieldType_String: + case kUpb_FieldType_Bytes: { + const upb_StringView* start = _upb_array_constptr(arr); + const upb_StringView* ptr = start + arr->UPB_PRIVATE(size); + do { + ptr--; + encode_bytes(e, ptr->data, ptr->size); + encode_varint(e, ptr->size); + encode_tag(e, f->UPB_PRIVATE(number), kUpb_WireType_Delimited); + } while (ptr != start); + return; + } + case kUpb_FieldType_Group: { + const upb_TaggedMessagePtr* start = _upb_array_constptr(arr); + const upb_TaggedMessagePtr* ptr = start + arr->UPB_PRIVATE(size); + const upb_MiniTable* subm = + upb_MiniTableSub_Message(subs[f->UPB_PRIVATE(submsg_index)]); + if (--e->depth == 0) encode_err(e, kUpb_EncodeStatus_MaxDepthExceeded); + do { + size_t size; + ptr--; + encode_tag(e, f->UPB_PRIVATE(number), kUpb_WireType_EndGroup); + encode_TaggedMessagePtr(e, *ptr, subm, &size); + encode_tag(e, f->UPB_PRIVATE(number), kUpb_WireType_StartGroup); + } while (ptr != start); + e->depth++; + return; + } + case kUpb_FieldType_Message: { + const upb_TaggedMessagePtr* start = _upb_array_constptr(arr); + const upb_TaggedMessagePtr* ptr = start + arr->UPB_PRIVATE(size); + const upb_MiniTable* subm = + upb_MiniTableSub_Message(subs[f->UPB_PRIVATE(submsg_index)]); + if (--e->depth == 0) encode_err(e, kUpb_EncodeStatus_MaxDepthExceeded); + do { + size_t size; + ptr--; + encode_TaggedMessagePtr(e, *ptr, subm, &size); + encode_varint(e, size); + encode_tag(e, f->UPB_PRIVATE(number), kUpb_WireType_Delimited); + } while (ptr != start); + e->depth++; + return; + } + } +#undef VARINT_CASE -const upb_EnumValueDef* upb_EnumDef_Value(const upb_EnumDef* e, int i) { - UPB_ASSERT(0 <= i && i < e->value_count); - return _upb_EnumValueDef_At(e->values, i); + if (packed) { + encode_varint(e, e->limit - e->ptr - pre_len); + encode_tag(e, f->UPB_PRIVATE(number), kUpb_WireType_Delimited); + } } -bool upb_EnumDef_IsClosed(const upb_EnumDef* e) { - if (UPB_TREAT_PROTO2_ENUMS_LIKE_PROTO3) return false; - return UPB_DESC(FeatureSet_enum_type)(e->resolved_features) == - UPB_DESC(FeatureSet_CLOSED); +static void encode_mapentry(upb_encstate* e, uint32_t number, + const upb_MiniTable* layout, + const upb_MapEntry* ent) { + const upb_MiniTableField* key_field = &layout->UPB_PRIVATE(fields)[0]; + const upb_MiniTableField* val_field = &layout->UPB_PRIVATE(fields)[1]; + size_t pre_len = e->limit - e->ptr; + size_t size; + encode_scalar(e, &ent->data.v, layout->UPB_PRIVATE(subs), val_field); + encode_scalar(e, &ent->data.k, layout->UPB_PRIVATE(subs), key_field); + size = (e->limit - e->ptr) - pre_len; + encode_varint(e, size); + encode_tag(e, number, kUpb_WireType_Delimited); } -bool upb_EnumDef_MiniDescriptorEncode(const upb_EnumDef* e, upb_Arena* a, - upb_StringView* out) { - upb_DescState s; - _upb_DescState_Init(&s); - - const upb_EnumValueDef** sorted = NULL; - if (!e->is_sorted) { - sorted = _upb_EnumValueDefs_Sorted(e->values, e->value_count, a); - if (!sorted) return false; - } - - if (!_upb_DescState_Grow(&s, a)) return false; - s.ptr = upb_MtDataEncoder_StartEnum(&s.e, s.ptr); - - // Duplicate values are allowed but we only encode each value once. - uint32_t previous = 0; +static void encode_map(upb_encstate* e, const upb_Message* msg, + const upb_MiniTableSub* subs, + const upb_MiniTableField* f) { + const upb_Map* map = *UPB_PTR_AT(msg, f->UPB_PRIVATE(offset), const upb_Map*); + const upb_MiniTable* layout = + upb_MiniTableSub_Message(subs[f->UPB_PRIVATE(submsg_index)]); + UPB_ASSERT(layout->UPB_PRIVATE(field_count) == 2); - for (int i = 0; i < e->value_count; i++) { - const uint32_t current = - upb_EnumValueDef_Number(sorted ? sorted[i] : upb_EnumDef_Value(e, i)); - if (i != 0 && previous == current) continue; + if (map == NULL) return; - if (!_upb_DescState_Grow(&s, a)) return false; - s.ptr = upb_MtDataEncoder_PutEnumValue(&s.e, s.ptr, current); - previous = current; + if (e->options & kUpb_EncodeOption_Deterministic) { + _upb_sortedmap sorted; + _upb_mapsorter_pushmap( + &e->sorter, layout->UPB_PRIVATE(fields)[0].UPB_PRIVATE(descriptortype), + map, &sorted); + upb_MapEntry ent; + while (_upb_sortedmap_next(&e->sorter, map, &sorted, &ent)) { + encode_mapentry(e, f->UPB_PRIVATE(number), layout, &ent); + } + _upb_mapsorter_popmap(&e->sorter, &sorted); + } else { + intptr_t iter = UPB_STRTABLE_BEGIN; + upb_StringView key; + upb_value val; + while (upb_strtable_next2(&map->table, &key, &val, &iter)) { + upb_MapEntry ent; + _upb_map_fromkey(key, &ent.data.k, map->key_size); + _upb_map_fromvalue(val, &ent.data.v, map->val_size); + encode_mapentry(e, f->UPB_PRIVATE(number), layout, &ent); + } } +} - if (!_upb_DescState_Grow(&s, a)) return false; - s.ptr = upb_MtDataEncoder_EndEnum(&s.e, s.ptr); - - // There will always be room for this '\0' in the encoder buffer because - // kUpb_MtDataEncoder_MinSize is overkill for upb_MtDataEncoder_EndEnum(). - UPB_ASSERT(s.ptr < s.buf + s.bufsize); - *s.ptr = '\0'; - - out->data = s.buf; - out->size = s.ptr - s.buf; - return true; +static bool encode_shouldencode(upb_encstate* e, const upb_Message* msg, + const upb_MiniTableSub* subs, + const upb_MiniTableField* f) { + if (f->presence == 0) { + // Proto3 presence or map/array. + const void* mem = UPB_PTR_AT(msg, f->UPB_PRIVATE(offset), void); + switch (UPB_PRIVATE(_upb_MiniTableField_GetRep)(f)) { + case kUpb_FieldRep_1Byte: { + char ch; + memcpy(&ch, mem, 1); + return ch != 0; + } + case kUpb_FieldRep_4Byte: { + uint32_t u32; + memcpy(&u32, mem, 4); + return u32 != 0; + } + case kUpb_FieldRep_8Byte: { + uint64_t u64; + memcpy(&u64, mem, 8); + return u64 != 0; + } + case kUpb_FieldRep_StringView: { + const upb_StringView* str = (const upb_StringView*)mem; + return str->size != 0; + } + default: + UPB_UNREACHABLE(); + } + } else if (f->presence > 0) { + // Proto2 presence: hasbit. + return UPB_PRIVATE(_upb_Message_GetHasbit)(msg, f); + } else { + // Field is in a oneof. + return UPB_PRIVATE(_upb_Message_GetOneofCase)(msg, f) == + f->UPB_PRIVATE(number); + } } -static upb_MiniTableEnum* create_enumlayout(upb_DefBuilder* ctx, - const upb_EnumDef* e) { - upb_StringView sv; - bool ok = upb_EnumDef_MiniDescriptorEncode(e, ctx->tmp_arena, &sv); - if (!ok) _upb_DefBuilder_Errf(ctx, "OOM while building enum MiniDescriptor"); +static void encode_field(upb_encstate* e, const upb_Message* msg, + const upb_MiniTableSub* subs, + const upb_MiniTableField* field) { + switch (UPB_PRIVATE(_upb_MiniTableField_Mode)(field)) { + case kUpb_FieldMode_Array: + encode_array(e, msg, subs, field); + break; + case kUpb_FieldMode_Map: + encode_map(e, msg, subs, field); + break; + case kUpb_FieldMode_Scalar: + encode_scalar(e, UPB_PTR_AT(msg, field->UPB_PRIVATE(offset), void), subs, + field); + break; + default: + UPB_UNREACHABLE(); + } +} - upb_Status status; - upb_MiniTableEnum* layout = - upb_MiniTableEnum_Build(sv.data, sv.size, ctx->arena, &status); - if (!layout) - _upb_DefBuilder_Errf(ctx, "Error building enum MiniTable: %s", status.msg); - return layout; +static void encode_msgset_item(upb_encstate* e, const upb_Extension* ext) { + size_t size; + encode_tag(e, kUpb_MsgSet_Item, kUpb_WireType_EndGroup); + encode_message(e, ext->data.ptr, + upb_MiniTableExtension_GetSubMessage(ext->ext), &size); + encode_varint(e, size); + encode_tag(e, kUpb_MsgSet_Message, kUpb_WireType_Delimited); + encode_varint(e, upb_MiniTableExtension_Number(ext->ext)); + encode_tag(e, kUpb_MsgSet_TypeId, kUpb_WireType_Varint); + encode_tag(e, kUpb_MsgSet_Item, kUpb_WireType_StartGroup); } -static upb_StringView* _upb_EnumReservedNames_New( - upb_DefBuilder* ctx, int n, const upb_StringView* protos) { - upb_StringView* sv = _upb_DefBuilder_Alloc(ctx, sizeof(upb_StringView) * n); - for (int i = 0; i < n; i++) { - sv[i].data = - upb_strdup2(protos[i].data, protos[i].size, _upb_DefBuilder_Arena(ctx)); - sv[i].size = protos[i].size; +static void encode_ext(upb_encstate* e, const upb_Extension* ext, + bool is_message_set) { + if (UPB_UNLIKELY(is_message_set)) { + encode_msgset_item(e, ext); + } else { + encode_field(e, (upb_Message*)&ext->data, &ext->ext->UPB_PRIVATE(sub), + &ext->ext->UPB_PRIVATE(field)); } - return sv; } -static void create_enumdef(upb_DefBuilder* ctx, const char* prefix, - const UPB_DESC(EnumDescriptorProto) * enum_proto, - const UPB_DESC(FeatureSet*) parent_features, - upb_EnumDef* e) { - const UPB_DESC(EnumValueDescriptorProto)* const* values; - const UPB_DESC(EnumDescriptorProto_EnumReservedRange)* const* res_ranges; - const upb_StringView* res_names; - upb_StringView name; - size_t n_value, n_res_range, n_res_name; - - UPB_DEF_SET_OPTIONS(e->opts, EnumDescriptorProto, EnumOptions, enum_proto); - e->resolved_features = _upb_DefBuilder_ResolveFeatures( - ctx, parent_features, UPB_DESC(EnumOptions_features)(e->opts)); - - // Must happen before _upb_DefBuilder_Add() - e->file = _upb_DefBuilder_File(ctx); - - name = UPB_DESC(EnumDescriptorProto_name)(enum_proto); - - e->full_name = _upb_DefBuilder_MakeFullName(ctx, prefix, name); - _upb_DefBuilder_Add(ctx, e->full_name, - _upb_DefType_Pack(e, UPB_DEFTYPE_ENUM)); - - values = UPB_DESC(EnumDescriptorProto_value)(enum_proto, &n_value); - - bool ok = upb_strtable_init(&e->ntoi, n_value, ctx->arena); - if (!ok) _upb_DefBuilder_OomErr(ctx); +static void encode_message(upb_encstate* e, const upb_Message* msg, + const upb_MiniTable* m, size_t* size) { + size_t pre_len = e->limit - e->ptr; - ok = upb_inttable_init(&e->iton, ctx->arena); - if (!ok) _upb_DefBuilder_OomErr(ctx); + if ((e->options & kUpb_EncodeOption_CheckRequired) && + m->UPB_PRIVATE(required_count)) { + uint64_t msg_head; + memcpy(&msg_head, msg, 8); + msg_head = UPB_PRIVATE(_upb_BigEndian64)(msg_head); + if (UPB_PRIVATE(_upb_MiniTable_RequiredMask)(m) & ~msg_head) { + encode_err(e, kUpb_EncodeStatus_MissingRequired); + } + } - e->defaultval = 0; - e->value_count = n_value; - e->values = _upb_EnumValueDefs_New(ctx, prefix, n_value, values, - e->resolved_features, e, &e->is_sorted); + if ((e->options & kUpb_EncodeOption_SkipUnknown) == 0) { + size_t unknown_size; + const char* unknown = upb_Message_GetUnknown(msg, &unknown_size); - if (n_value == 0) { - _upb_DefBuilder_Errf(ctx, "enums must contain at least one value (%s)", - e->full_name); + if (unknown) { + encode_bytes(e, unknown, unknown_size); + } } - res_ranges = - UPB_DESC(EnumDescriptorProto_reserved_range)(enum_proto, &n_res_range); - e->res_range_count = n_res_range; - e->res_ranges = _upb_EnumReservedRanges_New(ctx, n_res_range, res_ranges, e); + if (m->UPB_PRIVATE(ext) != kUpb_ExtMode_NonExtendable) { + /* Encode all extensions together. Unlike C++, we do not attempt to keep + * these in field number order relative to normal fields or even to each + * other. */ + size_t ext_count; + const upb_Extension* ext = + UPB_PRIVATE(_upb_Message_Getexts)(msg, &ext_count); + if (ext_count) { + if (e->options & kUpb_EncodeOption_Deterministic) { + _upb_sortedmap sorted; + _upb_mapsorter_pushexts(&e->sorter, ext, ext_count, &sorted); + while (_upb_sortedmap_nextext(&e->sorter, &sorted, &ext)) { + encode_ext(e, ext, m->UPB_PRIVATE(ext) == kUpb_ExtMode_IsMessageSet); + } + _upb_mapsorter_popmap(&e->sorter, &sorted); + } else { + const upb_Extension* end = ext + ext_count; + for (; ext != end; ext++) { + encode_ext(e, ext, m->UPB_PRIVATE(ext) == kUpb_ExtMode_IsMessageSet); + } + } + } + } - res_names = - UPB_DESC(EnumDescriptorProto_reserved_name)(enum_proto, &n_res_name); - e->res_name_count = n_res_name; - e->res_names = _upb_EnumReservedNames_New(ctx, n_res_name, res_names); + if (m->UPB_PRIVATE(field_count)) { + const upb_MiniTableField* f = + &m->UPB_PRIVATE(fields)[m->UPB_PRIVATE(field_count)]; + const upb_MiniTableField* first = &m->UPB_PRIVATE(fields)[0]; + while (f != first) { + f--; + if (encode_shouldencode(e, msg, m->UPB_PRIVATE(subs), f)) { + encode_field(e, msg, m->UPB_PRIVATE(subs), f); + } + } + } - upb_inttable_compact(&e->iton, ctx->arena); + *size = (e->limit - e->ptr) - pre_len; +} - if (upb_EnumDef_IsClosed(e)) { - if (ctx->layout) { - e->layout = upb_MiniTableFile_Enum(ctx->layout, ctx->enum_count++); +static upb_EncodeStatus upb_Encoder_Encode(upb_encstate* const encoder, + const upb_Message* const msg, + const upb_MiniTable* const l, + char** const buf, + size_t* const size) { + // Unfortunately we must continue to perform hackery here because there are + // code paths which blindly copy the returned pointer without bothering to + // check for errors until much later (b/235839510). So we still set *buf to + // NULL on error and we still set it to non-NULL on a successful empty result. + if (UPB_SETJMP(encoder->err) == 0) { + encode_message(encoder, msg, l, size); + *size = encoder->limit - encoder->ptr; + if (*size == 0) { + static char ch; + *buf = &ch; } else { - e->layout = create_enumlayout(ctx, e); + UPB_ASSERT(encoder->ptr); + *buf = encoder->ptr; } } else { - e->layout = NULL; + UPB_ASSERT(encoder->status != kUpb_EncodeStatus_Ok); + *buf = NULL; + *size = 0; } + + _upb_mapsorter_destroy(&encoder->sorter); + return encoder->status; } -upb_EnumDef* _upb_EnumDefs_New(upb_DefBuilder* ctx, int n, - const UPB_DESC(EnumDescriptorProto*) - const* protos, - const UPB_DESC(FeatureSet*) parent_features, - const upb_MessageDef* containing_type) { - _upb_DefType_CheckPadding(sizeof(upb_EnumDef)); +upb_EncodeStatus upb_Encode(const upb_Message* msg, const upb_MiniTable* l, + int options, upb_Arena* arena, char** buf, + size_t* size) { + upb_encstate e; + unsigned depth = (unsigned)options >> 16; - // If a containing type is defined then get the full name from that. - // Otherwise use the package name from the file def. - const char* name = containing_type ? upb_MessageDef_FullName(containing_type) - : _upb_FileDef_RawPackage(ctx->file); + e.status = kUpb_EncodeStatus_Ok; + e.arena = arena; + e.buf = NULL; + e.limit = NULL; + e.ptr = NULL; + e.depth = depth ? depth : kUpb_WireFormat_DefaultDepthLimit; + e.options = options; + _upb_mapsorter_init(&e.sorter); - upb_EnumDef* e = _upb_DefBuilder_Alloc(ctx, sizeof(upb_EnumDef) * n); - for (int i = 0; i < n; i++) { - create_enumdef(ctx, name, protos[i], parent_features, &e[i]); - e[i].containing_type = containing_type; - } - return e; + return upb_Encoder_Encode(&e, msg, l, buf, size); } +// Fast decoder: ~3x the speed of decode.c, but requires x86-64/ARM64. +// Also the table size grows by 2x. +// +// Could potentially be ported to other 64-bit archs that pass at least six +// arguments in registers and have 8 unused high bits in pointers. +// +// The overall design is to create specialized functions for every possible +// field type (eg. oneof boolean field with a 1 byte tag) and then dispatch +// to the specialized function as quickly as possible. + // Must be last. -struct upb_EnumReservedRange { - int32_t start; - int32_t end; -}; - -upb_EnumReservedRange* _upb_EnumReservedRange_At(const upb_EnumReservedRange* r, - int i) { - return (upb_EnumReservedRange*)&r[i]; -} +#if UPB_FASTTABLE -int32_t upb_EnumReservedRange_Start(const upb_EnumReservedRange* r) { - return r->start; -} -int32_t upb_EnumReservedRange_End(const upb_EnumReservedRange* r) { - return r->end; -} +// The standard set of arguments passed to each parsing function. +// Thanks to x86-64 calling conventions, these will stay in registers. +#define UPB_PARSE_PARAMS \ + upb_Decoder *d, const char *ptr, upb_Message *msg, intptr_t table, \ + uint64_t hasbits, uint64_t data -upb_EnumReservedRange* _upb_EnumReservedRanges_New( - upb_DefBuilder* ctx, int n, - const UPB_DESC(EnumDescriptorProto_EnumReservedRange) * const* protos, - const upb_EnumDef* e) { - upb_EnumReservedRange* r = - _upb_DefBuilder_Alloc(ctx, sizeof(upb_EnumReservedRange) * n); +#define UPB_PARSE_ARGS d, ptr, msg, table, hasbits, data - for (int i = 0; i < n; i++) { - const int32_t start = - UPB_DESC(EnumDescriptorProto_EnumReservedRange_start)(protos[i]); - const int32_t end = - UPB_DESC(EnumDescriptorProto_EnumReservedRange_end)(protos[i]); +#define RETURN_GENERIC(m) \ + /* Uncomment either of these for debugging purposes. */ \ + /* fprintf(stderr, m); */ \ + /*__builtin_trap(); */ \ + return _upb_FastDecoder_DecodeGeneric(d, ptr, msg, table, hasbits, 0); - // A full validation would also check that each range is disjoint, and that - // none of the fields overlap with the extension ranges, but we are just - // sanity checking here. +typedef enum { + CARD_s = 0, /* Singular (optional, non-repeated) */ + CARD_o = 1, /* Oneof */ + CARD_r = 2, /* Repeated */ + CARD_p = 3 /* Packed Repeated */ +} upb_card; - // Note: Not a typo! Unlike extension ranges and message reserved ranges, - // the end value of an enum reserved range is *inclusive*! - if (end < start) { - _upb_DefBuilder_Errf(ctx, "Reserved range (%d, %d) is invalid, enum=%s\n", - (int)start, (int)end, upb_EnumDef_FullName(e)); - } +UPB_NOINLINE +static const char* fastdecode_isdonefallback(UPB_PARSE_PARAMS) { + int overrun = data; + ptr = _upb_EpsCopyInputStream_IsDoneFallbackInline( + &d->input, ptr, overrun, _upb_Decoder_BufferFlipCallback); + data = _upb_FastDecoder_LoadTag(ptr); + UPB_MUSTTAIL return _upb_FastDecoder_TagDispatch(UPB_PARSE_ARGS); +} - r[i].start = start; - r[i].end = end; +UPB_FORCEINLINE +static const char* fastdecode_dispatch(UPB_PARSE_PARAMS) { + int overrun; + switch (upb_EpsCopyInputStream_IsDoneStatus(&d->input, ptr, &overrun)) { + case kUpb_IsDoneStatus_Done: + *(uint32_t*)msg |= hasbits; // Sync hasbits. + const upb_MiniTable* m = decode_totablep(table); + return UPB_UNLIKELY(m->UPB_PRIVATE(required_count)) + ? _upb_Decoder_CheckRequired(d, ptr, msg, m) + : ptr; + case kUpb_IsDoneStatus_NotDone: + break; + case kUpb_IsDoneStatus_NeedFallback: + data = overrun; + UPB_MUSTTAIL return fastdecode_isdonefallback(UPB_PARSE_ARGS); } - return r; + // Read two bytes of tag data (for a one-byte tag, the high byte is junk). + data = _upb_FastDecoder_LoadTag(ptr); + UPB_MUSTTAIL return _upb_FastDecoder_TagDispatch(UPB_PARSE_ARGS); } +UPB_FORCEINLINE +static bool fastdecode_checktag(uint16_t data, int tagbytes) { + if (tagbytes == 1) { + return (data & 0xff) == 0; + } else { + return data == 0; + } +} -#include - +UPB_FORCEINLINE +static const char* fastdecode_longsize(const char* ptr, int* size) { + int i; + UPB_ASSERT(*size & 0x80); + *size &= 0xff; + for (i = 0; i < 3; i++) { + ptr++; + size_t byte = (uint8_t)ptr[-1]; + *size += (byte - 1) << (7 + 7 * i); + if (UPB_LIKELY((byte & 0x80) == 0)) return ptr; + } + ptr++; + size_t byte = (uint8_t)ptr[-1]; + // len is limited by 2gb not 4gb, hence 8 and not 16 as normally expected + // for a 32 bit varint. + if (UPB_UNLIKELY(byte >= 8)) return NULL; + *size += (byte - 1) << 28; + return ptr; +} -// Must be last. +UPB_FORCEINLINE +static const char* fastdecode_delimited( + upb_Decoder* d, const char* ptr, + upb_EpsCopyInputStream_ParseDelimitedFunc* func, void* ctx) { + ptr++; -struct upb_EnumValueDef { - const UPB_DESC(EnumValueOptions*) opts; - const UPB_DESC(FeatureSet*) resolved_features; - const upb_EnumDef* parent; - const char* full_name; - int32_t number; -#if UINTPTR_MAX == 0xffffffff - uint32_t padding; // Increase size to a multiple of 8. -#endif -}; + // Sign-extend so varint greater than one byte becomes negative, causing + // fast delimited parse to fail. + int len = (int8_t)ptr[-1]; -upb_EnumValueDef* _upb_EnumValueDef_At(const upb_EnumValueDef* v, int i) { - return (upb_EnumValueDef*)&v[i]; + if (!upb_EpsCopyInputStream_TryParseDelimitedFast(&d->input, &ptr, len, func, + ctx)) { + // Slow case: Sub-message is >=128 bytes and/or exceeds the current buffer. + // If it exceeds the buffer limit, limit/limit_ptr will change during + // sub-message parsing, so we need to preserve delta, not limit. + if (UPB_UNLIKELY(len & 0x80)) { + // Size varint >1 byte (length >= 128). + ptr = fastdecode_longsize(ptr, &len); + if (!ptr) { + // Corrupt wire format: size exceeded INT_MAX. + return NULL; + } + } + if (!upb_EpsCopyInputStream_CheckSize(&d->input, ptr, len)) { + // Corrupt wire format: invalid limit. + return NULL; + } + int delta = upb_EpsCopyInputStream_PushLimit(&d->input, ptr, len); + ptr = func(&d->input, ptr, ctx); + upb_EpsCopyInputStream_PopLimit(&d->input, ptr, delta); + } + return ptr; } -static int _upb_EnumValueDef_Compare(const void* p1, const void* p2) { - const uint32_t v1 = (*(const upb_EnumValueDef**)p1)->number; - const uint32_t v2 = (*(const upb_EnumValueDef**)p2)->number; - return (v1 < v2) ? -1 : (v1 > v2); -} +/* singular, oneof, repeated field handling ***********************************/ -const upb_EnumValueDef** _upb_EnumValueDefs_Sorted(const upb_EnumValueDef* v, - int n, upb_Arena* a) { - // TODO: Try to replace this arena alloc with a persistent scratch buffer. - upb_EnumValueDef** out = - (upb_EnumValueDef**)upb_Arena_Malloc(a, n * sizeof(void*)); - if (!out) return NULL; +typedef struct { + upb_Array* arr; + void* end; +} fastdecode_arr; - for (int i = 0; i < n; i++) { - out[i] = (upb_EnumValueDef*)&v[i]; - } - qsort(out, n, sizeof(void*), _upb_EnumValueDef_Compare); +typedef enum { + FD_NEXT_ATLIMIT, + FD_NEXT_SAMEFIELD, + FD_NEXT_OTHERFIELD +} fastdecode_next; - return (const upb_EnumValueDef**)out; -} +typedef struct { + void* dst; + fastdecode_next next; + uint32_t tag; +} fastdecode_nextret; -const UPB_DESC(EnumValueOptions) * - upb_EnumValueDef_Options(const upb_EnumValueDef* v) { - return v->opts; +UPB_FORCEINLINE +static void* fastdecode_resizearr(upb_Decoder* d, void* dst, + fastdecode_arr* farr, int valbytes) { + if (UPB_UNLIKELY(dst == farr->end)) { + size_t old_capacity = farr->arr->UPB_PRIVATE(capacity); + size_t old_bytes = old_capacity * valbytes; + size_t new_capacity = old_capacity * 2; + size_t new_bytes = new_capacity * valbytes; + char* old_ptr = _upb_array_ptr(farr->arr); + char* new_ptr = upb_Arena_Realloc(&d->arena, old_ptr, old_bytes, new_bytes); + uint8_t elem_size_lg2 = __builtin_ctz(valbytes); + UPB_PRIVATE(_upb_Array_SetTaggedPtr)(farr->arr, new_ptr, elem_size_lg2); + farr->arr->UPB_PRIVATE(capacity) = new_capacity; + dst = (void*)(new_ptr + (old_capacity * valbytes)); + farr->end = (void*)(new_ptr + (new_capacity * valbytes)); + } + return dst; } -bool upb_EnumValueDef_HasOptions(const upb_EnumValueDef* v) { - return v->opts != (void*)kUpbDefOptDefault; +UPB_FORCEINLINE +static bool fastdecode_tagmatch(uint32_t tag, uint64_t data, int tagbytes) { + if (tagbytes == 1) { + return (uint8_t)tag == (uint8_t)data; + } else { + return (uint16_t)tag == (uint16_t)data; + } } -const UPB_DESC(FeatureSet) * - upb_EnumValueDef_ResolvedFeatures(const upb_EnumValueDef* e) { - return e->resolved_features; +UPB_FORCEINLINE +static void fastdecode_commitarr(void* dst, fastdecode_arr* farr, + int valbytes) { + farr->arr->UPB_PRIVATE(size) = + (size_t)((char*)dst - (char*)_upb_array_ptr(farr->arr)) / valbytes; } -const upb_EnumDef* upb_EnumValueDef_Enum(const upb_EnumValueDef* v) { - return v->parent; -} +UPB_FORCEINLINE +static fastdecode_nextret fastdecode_nextrepeated(upb_Decoder* d, void* dst, + const char** ptr, + fastdecode_arr* farr, + uint64_t data, int tagbytes, + int valbytes) { + fastdecode_nextret ret; + dst = (char*)dst + valbytes; -const char* upb_EnumValueDef_FullName(const upb_EnumValueDef* v) { - return v->full_name; -} + if (UPB_LIKELY(!_upb_Decoder_IsDone(d, ptr))) { + ret.tag = _upb_FastDecoder_LoadTag(*ptr); + if (fastdecode_tagmatch(ret.tag, data, tagbytes)) { + ret.next = FD_NEXT_SAMEFIELD; + } else { + fastdecode_commitarr(dst, farr, valbytes); + ret.next = FD_NEXT_OTHERFIELD; + } + } else { + fastdecode_commitarr(dst, farr, valbytes); + ret.next = FD_NEXT_ATLIMIT; + } -const char* upb_EnumValueDef_Name(const upb_EnumValueDef* v) { - return _upb_DefBuilder_FullToShort(v->full_name); + ret.dst = dst; + return ret; } -int32_t upb_EnumValueDef_Number(const upb_EnumValueDef* v) { return v->number; } - -uint32_t upb_EnumValueDef_Index(const upb_EnumValueDef* v) { - // Compute index in our parent's array. - return v - upb_EnumDef_Value(v->parent, 0); +UPB_FORCEINLINE +static void* fastdecode_fieldmem(upb_Message* msg, uint64_t data) { + size_t ofs = data >> 48; + return (char*)msg + ofs; } -static void create_enumvaldef(upb_DefBuilder* ctx, const char* prefix, - const UPB_DESC(EnumValueDescriptorProto*) - val_proto, - const UPB_DESC(FeatureSet*) parent_features, - upb_EnumDef* e, upb_EnumValueDef* v) { - UPB_DEF_SET_OPTIONS(v->opts, EnumValueDescriptorProto, EnumValueOptions, - val_proto); - v->resolved_features = _upb_DefBuilder_ResolveFeatures( - ctx, parent_features, UPB_DESC(EnumValueOptions_features)(v->opts)); - - upb_StringView name = UPB_DESC(EnumValueDescriptorProto_name)(val_proto); - - v->parent = e; // Must happen prior to _upb_DefBuilder_Add() - v->full_name = _upb_DefBuilder_MakeFullName(ctx, prefix, name); - v->number = UPB_DESC(EnumValueDescriptorProto_number)(val_proto); - _upb_DefBuilder_Add(ctx, v->full_name, - _upb_DefType_Pack(v, UPB_DEFTYPE_ENUMVAL)); - - bool ok = _upb_EnumDef_Insert(e, v, ctx->arena); - if (!ok) _upb_DefBuilder_OomErr(ctx); +UPB_FORCEINLINE +static void* fastdecode_getfield(upb_Decoder* d, const char* ptr, + upb_Message* msg, uint64_t* data, + uint64_t* hasbits, fastdecode_arr* farr, + int valbytes, upb_card card) { + switch (card) { + case CARD_s: { + uint8_t hasbit_index = *data >> 24; + // Set hasbit and return pointer to scalar field. + *hasbits |= 1ull << hasbit_index; + return fastdecode_fieldmem(msg, *data); + } + case CARD_o: { + uint16_t case_ofs = *data >> 32; + uint32_t* oneof_case = UPB_PTR_AT(msg, case_ofs, uint32_t); + uint8_t field_number = *data >> 24; + *oneof_case = field_number; + return fastdecode_fieldmem(msg, *data); + } + case CARD_r: { + // Get pointer to upb_Array and allocate/expand if necessary. + uint8_t elem_size_lg2 = __builtin_ctz(valbytes); + upb_Array** arr_p = fastdecode_fieldmem(msg, *data); + char* begin; + *(uint32_t*)msg |= *hasbits; + *hasbits = 0; + if (UPB_LIKELY(!*arr_p)) { + farr->arr = UPB_PRIVATE(_upb_Array_New)(&d->arena, 8, elem_size_lg2); + *arr_p = farr->arr; + } else { + farr->arr = *arr_p; + } + begin = _upb_array_ptr(farr->arr); + farr->end = begin + (farr->arr->UPB_PRIVATE(capacity) * valbytes); + *data = _upb_FastDecoder_LoadTag(ptr); + return begin + (farr->arr->UPB_PRIVATE(size) * valbytes); + } + default: + UPB_UNREACHABLE(); + } } -static void _upb_EnumValueDef_CheckZeroValue(upb_DefBuilder* ctx, - const upb_EnumDef* e, - const upb_EnumValueDef* v, int n) { - if (upb_EnumDef_IsClosed(e) || n == 0 || v[0].number == 0) return; +UPB_FORCEINLINE +static bool fastdecode_flippacked(uint64_t* data, int tagbytes) { + *data ^= (0x2 ^ 0x0); // Patch data to match packed wiretype. + return fastdecode_checktag(*data, tagbytes); +} - // When the special UPB_TREAT_PROTO2_ENUMS_LIKE_PROTO3 is enabled, we have to - // exempt proto2 enums from this check, even when we are treating them as - // open. - if (UPB_TREAT_PROTO2_ENUMS_LIKE_PROTO3 && - upb_FileDef_Syntax(upb_EnumDef_File(e)) == kUpb_Syntax_Proto2) { - return; +#define FASTDECODE_CHECKPACKED(tagbytes, card, func) \ + if (UPB_UNLIKELY(!fastdecode_checktag(data, tagbytes))) { \ + if (card == CARD_r && fastdecode_flippacked(&data, tagbytes)) { \ + UPB_MUSTTAIL return func(UPB_PARSE_ARGS); \ + } \ + RETURN_GENERIC("packed check tag mismatch\n"); \ } - _upb_DefBuilder_Errf(ctx, "for open enums, the first value must be zero (%s)", - upb_EnumDef_FullName(e)); -} +/* varint fields **************************************************************/ -// Allocate and initialize an array of |n| enum value defs owned by |e|. -upb_EnumValueDef* _upb_EnumValueDefs_New( - upb_DefBuilder* ctx, const char* prefix, int n, - const UPB_DESC(EnumValueDescriptorProto*) const* protos, - const UPB_DESC(FeatureSet*) parent_features, upb_EnumDef* e, - bool* is_sorted) { - _upb_DefType_CheckPadding(sizeof(upb_EnumValueDef)); - - upb_EnumValueDef* v = - _upb_DefBuilder_Alloc(ctx, sizeof(upb_EnumValueDef) * n); - - *is_sorted = true; - uint32_t previous = 0; - for (int i = 0; i < n; i++) { - create_enumvaldef(ctx, prefix, protos[i], parent_features, e, &v[i]); - - const uint32_t current = v[i].number; - if (previous > current) *is_sorted = false; - previous = current; +UPB_FORCEINLINE +static uint64_t fastdecode_munge(uint64_t val, int valbytes, bool zigzag) { + if (valbytes == 1) { + return val != 0; + } else if (zigzag) { + if (valbytes == 4) { + uint32_t n = val; + return (n >> 1) ^ -(int32_t)(n & 1); + } else if (valbytes == 8) { + return (val >> 1) ^ -(int64_t)(val & 1); + } + UPB_UNREACHABLE(); } - - _upb_EnumValueDef_CheckZeroValue(ctx, e, v, n); - - return v; + return val; } +UPB_FORCEINLINE +static const char* fastdecode_varint64(const char* ptr, uint64_t* val) { + ptr++; + *val = (uint8_t)ptr[-1]; + if (UPB_UNLIKELY(*val & 0x80)) { + int i; + for (i = 0; i < 8; i++) { + ptr++; + uint64_t byte = (uint8_t)ptr[-1]; + *val += (byte - 1) << (7 + 7 * i); + if (UPB_LIKELY((byte & 0x80) == 0)) goto done; + } + ptr++; + uint64_t byte = (uint8_t)ptr[-1]; + if (byte > 1) { + return NULL; + } + *val += (byte - 1) << 63; + } +done: + UPB_ASSUME(ptr != NULL); + return ptr; +} -#include - - -// Must be last. - -struct upb_ExtensionRange { - const UPB_DESC(ExtensionRangeOptions*) opts; - const UPB_DESC(FeatureSet*) resolved_features; - int32_t start; - int32_t end; -}; +#define FASTDECODE_UNPACKEDVARINT(d, ptr, msg, table, hasbits, data, tagbytes, \ + valbytes, card, zigzag, packed) \ + uint64_t val; \ + void* dst; \ + fastdecode_arr farr; \ + \ + FASTDECODE_CHECKPACKED(tagbytes, card, packed); \ + \ + dst = fastdecode_getfield(d, ptr, msg, &data, &hasbits, &farr, valbytes, \ + card); \ + if (card == CARD_r) { \ + if (UPB_UNLIKELY(!dst)) { \ + RETURN_GENERIC("need array resize\n"); \ + } \ + } \ + \ + again: \ + if (card == CARD_r) { \ + dst = fastdecode_resizearr(d, dst, &farr, valbytes); \ + } \ + \ + ptr += tagbytes; \ + ptr = fastdecode_varint64(ptr, &val); \ + if (ptr == NULL) _upb_FastDecoder_ErrorJmp(d, kUpb_DecodeStatus_Malformed); \ + val = fastdecode_munge(val, valbytes, zigzag); \ + memcpy(dst, &val, valbytes); \ + \ + if (card == CARD_r) { \ + fastdecode_nextret ret = fastdecode_nextrepeated( \ + d, dst, &ptr, &farr, data, tagbytes, valbytes); \ + switch (ret.next) { \ + case FD_NEXT_SAMEFIELD: \ + dst = ret.dst; \ + goto again; \ + case FD_NEXT_OTHERFIELD: \ + data = ret.tag; \ + UPB_MUSTTAIL return _upb_FastDecoder_TagDispatch(UPB_PARSE_ARGS); \ + case FD_NEXT_ATLIMIT: \ + return ptr; \ + } \ + } \ + \ + UPB_MUSTTAIL return fastdecode_dispatch(UPB_PARSE_ARGS); -upb_ExtensionRange* _upb_ExtensionRange_At(const upb_ExtensionRange* r, int i) { - return (upb_ExtensionRange*)&r[i]; -} +typedef struct { + uint8_t valbytes; + bool zigzag; + void* dst; + fastdecode_arr farr; +} fastdecode_varintdata; -const UPB_DESC(ExtensionRangeOptions) * - upb_ExtensionRange_Options(const upb_ExtensionRange* r) { - return r->opts; -} +UPB_FORCEINLINE +static const char* fastdecode_topackedvarint(upb_EpsCopyInputStream* e, + const char* ptr, void* ctx) { + upb_Decoder* d = (upb_Decoder*)e; + fastdecode_varintdata* data = ctx; + void* dst = data->dst; + uint64_t val; -bool upb_ExtensionRange_HasOptions(const upb_ExtensionRange* r) { - return r->opts != (void*)kUpbDefOptDefault; -} + while (!_upb_Decoder_IsDone(d, &ptr)) { + dst = fastdecode_resizearr(d, dst, &data->farr, data->valbytes); + ptr = fastdecode_varint64(ptr, &val); + if (ptr == NULL) return NULL; + val = fastdecode_munge(val, data->valbytes, data->zigzag); + memcpy(dst, &val, data->valbytes); + dst = (char*)dst + data->valbytes; + } -int32_t upb_ExtensionRange_Start(const upb_ExtensionRange* r) { - return r->start; + fastdecode_commitarr(dst, &data->farr, data->valbytes); + return ptr; } -int32_t upb_ExtensionRange_End(const upb_ExtensionRange* r) { return r->end; } - -upb_ExtensionRange* _upb_ExtensionRanges_New( - upb_DefBuilder* ctx, int n, - const UPB_DESC(DescriptorProto_ExtensionRange*) const* protos, - const UPB_DESC(FeatureSet*) parent_features, const upb_MessageDef* m) { - upb_ExtensionRange* r = - _upb_DefBuilder_Alloc(ctx, sizeof(upb_ExtensionRange) * n); +#define FASTDECODE_PACKEDVARINT(d, ptr, msg, table, hasbits, data, tagbytes, \ + valbytes, zigzag, unpacked) \ + fastdecode_varintdata ctx = {valbytes, zigzag}; \ + \ + FASTDECODE_CHECKPACKED(tagbytes, CARD_r, unpacked); \ + \ + ctx.dst = fastdecode_getfield(d, ptr, msg, &data, &hasbits, &ctx.farr, \ + valbytes, CARD_r); \ + if (UPB_UNLIKELY(!ctx.dst)) { \ + RETURN_GENERIC("need array resize\n"); \ + } \ + \ + ptr += tagbytes; \ + ptr = fastdecode_delimited(d, ptr, &fastdecode_topackedvarint, &ctx); \ + \ + if (UPB_UNLIKELY(ptr == NULL)) { \ + _upb_FastDecoder_ErrorJmp(d, kUpb_DecodeStatus_Malformed); \ + } \ + \ + UPB_MUSTTAIL return fastdecode_dispatch(d, ptr, msg, table, hasbits, 0); - for (int i = 0; i < n; i++) { - UPB_DEF_SET_OPTIONS(r[i].opts, DescriptorProto_ExtensionRange, - ExtensionRangeOptions, protos[i]); - r[i].resolved_features = _upb_DefBuilder_ResolveFeatures( - ctx, parent_features, - UPB_DESC(ExtensionRangeOptions_features)(r[i].opts)); +#define FASTDECODE_VARINT(d, ptr, msg, table, hasbits, data, tagbytes, \ + valbytes, card, zigzag, unpacked, packed) \ + if (card == CARD_p) { \ + FASTDECODE_PACKEDVARINT(d, ptr, msg, table, hasbits, data, tagbytes, \ + valbytes, zigzag, unpacked); \ + } else { \ + FASTDECODE_UNPACKEDVARINT(d, ptr, msg, table, hasbits, data, tagbytes, \ + valbytes, card, zigzag, packed); \ + } - const int32_t start = - UPB_DESC(DescriptorProto_ExtensionRange_start)(protos[i]); - const int32_t end = UPB_DESC(DescriptorProto_ExtensionRange_end)(protos[i]); - const int32_t max = UPB_DESC(MessageOptions_message_set_wire_format)( - upb_MessageDef_Options(m)) - ? INT32_MAX - : kUpb_MaxFieldNumber + 1; +#define z_ZZ true +#define b_ZZ false +#define v_ZZ false - // A full validation would also check that each range is disjoint, and that - // none of the fields overlap with the extension ranges, but we are just - // sanity checking here. - if (start < 1 || end <= start || end > max) { - _upb_DefBuilder_Errf(ctx, - "Extension range (%d, %d) is invalid, message=%s\n", - (int)start, (int)end, upb_MessageDef_FullName(m)); - } +/* Generate all combinations: + * {s,o,r,p} x {b1,v4,z4,v8,z8} x {1bt,2bt} */ - r[i].start = start; - r[i].end = end; +#define F(card, type, valbytes, tagbytes) \ + UPB_NOINLINE \ + const char* upb_p##card##type##valbytes##_##tagbytes##bt(UPB_PARSE_PARAMS) { \ + FASTDECODE_VARINT(d, ptr, msg, table, hasbits, data, tagbytes, valbytes, \ + CARD_##card, type##_ZZ, \ + upb_pr##type##valbytes##_##tagbytes##bt, \ + upb_pp##type##valbytes##_##tagbytes##bt); \ } - return r; -} - +#define TYPES(card, tagbytes) \ + F(card, b, 1, tagbytes) \ + F(card, v, 4, tagbytes) \ + F(card, v, 8, tagbytes) \ + F(card, z, 4, tagbytes) \ + F(card, z, 8, tagbytes) -#include -#include -#include -#include -#include -#include +#define TAGBYTES(card) \ + TYPES(card, 1) \ + TYPES(card, 2) +TAGBYTES(s) +TAGBYTES(o) +TAGBYTES(r) +TAGBYTES(p) -// Must be last. +#undef z_ZZ +#undef b_ZZ +#undef v_ZZ +#undef o_ONEOF +#undef s_ONEOF +#undef r_ONEOF +#undef F +#undef TYPES +#undef TAGBYTES +#undef FASTDECODE_UNPACKEDVARINT +#undef FASTDECODE_PACKEDVARINT +#undef FASTDECODE_VARINT -#define UPB_FIELD_TYPE_UNSPECIFIED 0 +/* fixed fields ***************************************************************/ -typedef struct { - size_t len; - char str[1]; // Null-terminated string data follows. -} str_t; - -struct upb_FieldDef { - const UPB_DESC(FieldOptions*) opts; - const UPB_DESC(FeatureSet*) resolved_features; - const upb_FileDef* file; - const upb_MessageDef* msgdef; - const char* full_name; - const char* json_name; - union { - int64_t sint; - uint64_t uint; - double dbl; - float flt; - bool boolean; - str_t* str; - void* msg; // Always NULL. - } defaultval; - union { - const upb_OneofDef* oneof; - const upb_MessageDef* extension_scope; - } scope; - union { - const upb_MessageDef* msgdef; - const upb_EnumDef* enumdef; - const UPB_DESC(FieldDescriptorProto) * unresolved; - } sub; - uint32_t number_; - uint16_t index_; - uint16_t layout_index; // Index into msgdef->layout->fields or file->exts - bool has_default; - bool has_json_name; - bool has_presence; - bool is_extension; - bool is_proto3_optional; - upb_FieldType type_; - upb_Label label_; -}; - -upb_FieldDef* _upb_FieldDef_At(const upb_FieldDef* f, int i) { - return (upb_FieldDef*)&f[i]; -} +#define FASTDECODE_UNPACKEDFIXED(d, ptr, msg, table, hasbits, data, tagbytes, \ + valbytes, card, packed) \ + void* dst; \ + fastdecode_arr farr; \ + \ + FASTDECODE_CHECKPACKED(tagbytes, card, packed) \ + \ + dst = fastdecode_getfield(d, ptr, msg, &data, &hasbits, &farr, valbytes, \ + card); \ + if (card == CARD_r) { \ + if (UPB_UNLIKELY(!dst)) { \ + RETURN_GENERIC("couldn't allocate array in arena\n"); \ + } \ + } \ + \ + again: \ + if (card == CARD_r) { \ + dst = fastdecode_resizearr(d, dst, &farr, valbytes); \ + } \ + \ + ptr += tagbytes; \ + memcpy(dst, ptr, valbytes); \ + ptr += valbytes; \ + \ + if (card == CARD_r) { \ + fastdecode_nextret ret = fastdecode_nextrepeated( \ + d, dst, &ptr, &farr, data, tagbytes, valbytes); \ + switch (ret.next) { \ + case FD_NEXT_SAMEFIELD: \ + dst = ret.dst; \ + goto again; \ + case FD_NEXT_OTHERFIELD: \ + data = ret.tag; \ + UPB_MUSTTAIL return _upb_FastDecoder_TagDispatch(UPB_PARSE_ARGS); \ + case FD_NEXT_ATLIMIT: \ + return ptr; \ + } \ + } \ + \ + UPB_MUSTTAIL return fastdecode_dispatch(UPB_PARSE_ARGS); -const UPB_DESC(FieldOptions) * upb_FieldDef_Options(const upb_FieldDef* f) { - return f->opts; -} +#define FASTDECODE_PACKEDFIXED(d, ptr, msg, table, hasbits, data, tagbytes, \ + valbytes, unpacked) \ + FASTDECODE_CHECKPACKED(tagbytes, CARD_r, unpacked) \ + \ + ptr += tagbytes; \ + int size = (uint8_t)ptr[0]; \ + ptr++; \ + if (size & 0x80) { \ + ptr = fastdecode_longsize(ptr, &size); \ + } \ + \ + if (UPB_UNLIKELY(!upb_EpsCopyInputStream_CheckDataSizeAvailable( \ + &d->input, ptr, size) || \ + (size % valbytes) != 0)) { \ + _upb_FastDecoder_ErrorJmp(d, kUpb_DecodeStatus_Malformed); \ + } \ + \ + upb_Array** arr_p = fastdecode_fieldmem(msg, data); \ + upb_Array* arr = *arr_p; \ + uint8_t elem_size_lg2 = __builtin_ctz(valbytes); \ + int elems = size / valbytes; \ + \ + if (UPB_LIKELY(!arr)) { \ + *arr_p = arr = \ + UPB_PRIVATE(_upb_Array_New)(&d->arena, elems, elem_size_lg2); \ + if (!arr) { \ + _upb_FastDecoder_ErrorJmp(d, kUpb_DecodeStatus_Malformed); \ + } \ + } else { \ + _upb_Array_ResizeUninitialized(arr, elems, &d->arena); \ + } \ + \ + char* dst = _upb_array_ptr(arr); \ + memcpy(dst, ptr, size); \ + arr->UPB_PRIVATE(size) = elems; \ + \ + ptr += size; \ + UPB_MUSTTAIL return fastdecode_dispatch(UPB_PARSE_ARGS); -bool upb_FieldDef_HasOptions(const upb_FieldDef* f) { - return f->opts != (void*)kUpbDefOptDefault; -} +#define FASTDECODE_FIXED(d, ptr, msg, table, hasbits, data, tagbytes, \ + valbytes, card, unpacked, packed) \ + if (card == CARD_p) { \ + FASTDECODE_PACKEDFIXED(d, ptr, msg, table, hasbits, data, tagbytes, \ + valbytes, unpacked); \ + } else { \ + FASTDECODE_UNPACKEDFIXED(d, ptr, msg, table, hasbits, data, tagbytes, \ + valbytes, card, packed); \ + } -const UPB_DESC(FeatureSet) * - upb_FieldDef_ResolvedFeatures(const upb_FieldDef* f) { - return f->resolved_features; -} +/* Generate all combinations: + * {s,o,r,p} x {f4,f8} x {1bt,2bt} */ -const char* upb_FieldDef_FullName(const upb_FieldDef* f) { - return f->full_name; -} +#define F(card, valbytes, tagbytes) \ + UPB_NOINLINE \ + const char* upb_p##card##f##valbytes##_##tagbytes##bt(UPB_PARSE_PARAMS) { \ + FASTDECODE_FIXED(d, ptr, msg, table, hasbits, data, tagbytes, valbytes, \ + CARD_##card, upb_ppf##valbytes##_##tagbytes##bt, \ + upb_prf##valbytes##_##tagbytes##bt); \ + } -upb_CType upb_FieldDef_CType(const upb_FieldDef* f) { - return upb_FieldType_CType(f->type_); -} +#define TYPES(card, tagbytes) \ + F(card, 4, tagbytes) \ + F(card, 8, tagbytes) -upb_FieldType upb_FieldDef_Type(const upb_FieldDef* f) { - // TODO: remove once we can deprecate kUpb_FieldType_Group. - if (f->type_ == kUpb_FieldType_Message && - UPB_DESC(FeatureSet_message_encoding)(f->resolved_features) == - UPB_DESC(FeatureSet_DELIMITED)) { - return kUpb_FieldType_Group; - } - return f->type_; -} +#define TAGBYTES(card) \ + TYPES(card, 1) \ + TYPES(card, 2) -uint32_t upb_FieldDef_Index(const upb_FieldDef* f) { return f->index_; } +TAGBYTES(s) +TAGBYTES(o) +TAGBYTES(r) +TAGBYTES(p) -upb_Label upb_FieldDef_Label(const upb_FieldDef* f) { - // TODO: remove once we can deprecate kUpb_Label_Required. - if (UPB_DESC(FeatureSet_field_presence)(f->resolved_features) == - UPB_DESC(FeatureSet_LEGACY_REQUIRED)) { - return kUpb_Label_Required; - } - return f->label_; -} +#undef F +#undef TYPES +#undef TAGBYTES +#undef FASTDECODE_UNPACKEDFIXED +#undef FASTDECODE_PACKEDFIXED -uint32_t upb_FieldDef_Number(const upb_FieldDef* f) { return f->number_; } +/* string fields **************************************************************/ -bool upb_FieldDef_IsExtension(const upb_FieldDef* f) { return f->is_extension; } +typedef const char* fastdecode_copystr_func(struct upb_Decoder* d, + const char* ptr, upb_Message* msg, + const upb_MiniTable* table, + uint64_t hasbits, + upb_StringView* dst); -bool _upb_FieldDef_IsPackable(const upb_FieldDef* f) { - return upb_FieldDef_IsRepeated(f) && upb_FieldDef_IsPrimitive(f); +UPB_NOINLINE +static const char* fastdecode_verifyutf8(upb_Decoder* d, const char* ptr, + upb_Message* msg, intptr_t table, + uint64_t hasbits, uint64_t data) { + upb_StringView* dst = (upb_StringView*)data; + if (!_upb_Decoder_VerifyUtf8Inline(dst->data, dst->size)) { + _upb_FastDecoder_ErrorJmp(d, kUpb_DecodeStatus_BadUtf8); + } + UPB_MUSTTAIL return fastdecode_dispatch(UPB_PARSE_ARGS); } -bool upb_FieldDef_IsPacked(const upb_FieldDef* f) { - return _upb_FieldDef_IsPackable(f) && - UPB_DESC(FeatureSet_repeated_field_encoding(f->resolved_features)) == - UPB_DESC(FeatureSet_PACKED); -} +#define FASTDECODE_LONGSTRING(d, ptr, msg, table, hasbits, dst, validate_utf8) \ + int size = (uint8_t)ptr[0]; /* Could plumb through hasbits. */ \ + ptr++; \ + if (size & 0x80) { \ + ptr = fastdecode_longsize(ptr, &size); \ + } \ + \ + if (UPB_UNLIKELY(!upb_EpsCopyInputStream_CheckSize(&d->input, ptr, size))) { \ + dst->size = 0; \ + _upb_FastDecoder_ErrorJmp(d, kUpb_DecodeStatus_Malformed); \ + } \ + \ + const char* s_ptr = ptr; \ + ptr = upb_EpsCopyInputStream_ReadString(&d->input, &s_ptr, size, &d->arena); \ + if (!ptr) _upb_FastDecoder_ErrorJmp(d, kUpb_DecodeStatus_OutOfMemory); \ + dst->data = s_ptr; \ + dst->size = size; \ + \ + if (validate_utf8) { \ + data = (uint64_t)dst; \ + UPB_MUSTTAIL return fastdecode_verifyutf8(UPB_PARSE_ARGS); \ + } else { \ + UPB_MUSTTAIL return fastdecode_dispatch(UPB_PARSE_ARGS); \ + } -const char* upb_FieldDef_Name(const upb_FieldDef* f) { - return _upb_DefBuilder_FullToShort(f->full_name); +UPB_NOINLINE +static const char* fastdecode_longstring_utf8(struct upb_Decoder* d, + const char* ptr, upb_Message* msg, + intptr_t table, uint64_t hasbits, + uint64_t data) { + upb_StringView* dst = (upb_StringView*)data; + FASTDECODE_LONGSTRING(d, ptr, msg, table, hasbits, dst, true); } -const char* upb_FieldDef_JsonName(const upb_FieldDef* f) { - return f->json_name; +UPB_NOINLINE +static const char* fastdecode_longstring_noutf8( + struct upb_Decoder* d, const char* ptr, upb_Message* msg, intptr_t table, + uint64_t hasbits, uint64_t data) { + upb_StringView* dst = (upb_StringView*)data; + FASTDECODE_LONGSTRING(d, ptr, msg, table, hasbits, dst, false); } -bool upb_FieldDef_HasJsonName(const upb_FieldDef* f) { - return f->has_json_name; +UPB_FORCEINLINE +static void fastdecode_docopy(upb_Decoder* d, const char* ptr, uint32_t size, + int copy, char* data, size_t data_offset, + upb_StringView* dst) { + d->arena.UPB_PRIVATE(ptr) += copy; + dst->data = data + data_offset; + UPB_UNPOISON_MEMORY_REGION(data, copy); + memcpy(data, ptr, copy); + UPB_POISON_MEMORY_REGION(data + data_offset + size, + copy - data_offset - size); +} + +#define FASTDECODE_COPYSTRING(d, ptr, msg, table, hasbits, data, tagbytes, \ + card, validate_utf8) \ + upb_StringView* dst; \ + fastdecode_arr farr; \ + int64_t size; \ + size_t arena_has; \ + size_t common_has; \ + char* buf; \ + \ + UPB_ASSERT(!upb_EpsCopyInputStream_AliasingAvailable(&d->input, ptr, 0)); \ + UPB_ASSERT(fastdecode_checktag(data, tagbytes)); \ + \ + dst = fastdecode_getfield(d, ptr, msg, &data, &hasbits, &farr, \ + sizeof(upb_StringView), card); \ + \ + again: \ + if (card == CARD_r) { \ + dst = fastdecode_resizearr(d, dst, &farr, sizeof(upb_StringView)); \ + } \ + \ + size = (uint8_t)ptr[tagbytes]; \ + ptr += tagbytes + 1; \ + dst->size = size; \ + \ + buf = d->arena.UPB_PRIVATE(ptr); \ + arena_has = UPB_PRIVATE(_upb_ArenaHas)(&d->arena); \ + common_has = UPB_MIN(arena_has, \ + upb_EpsCopyInputStream_BytesAvailable(&d->input, ptr)); \ + \ + if (UPB_LIKELY(size <= 15 - tagbytes)) { \ + if (arena_has < 16) goto longstr; \ + fastdecode_docopy(d, ptr - tagbytes - 1, size, 16, buf, tagbytes + 1, \ + dst); \ + } else if (UPB_LIKELY(size <= 32)) { \ + if (UPB_UNLIKELY(common_has < 32)) goto longstr; \ + fastdecode_docopy(d, ptr, size, 32, buf, 0, dst); \ + } else if (UPB_LIKELY(size <= 64)) { \ + if (UPB_UNLIKELY(common_has < 64)) goto longstr; \ + fastdecode_docopy(d, ptr, size, 64, buf, 0, dst); \ + } else if (UPB_LIKELY(size < 128)) { \ + if (UPB_UNLIKELY(common_has < 128)) goto longstr; \ + fastdecode_docopy(d, ptr, size, 128, buf, 0, dst); \ + } else { \ + goto longstr; \ + } \ + \ + ptr += size; \ + \ + if (card == CARD_r) { \ + if (validate_utf8 && \ + !_upb_Decoder_VerifyUtf8Inline(dst->data, dst->size)) { \ + _upb_FastDecoder_ErrorJmp(d, kUpb_DecodeStatus_BadUtf8); \ + } \ + fastdecode_nextret ret = fastdecode_nextrepeated( \ + d, dst, &ptr, &farr, data, tagbytes, sizeof(upb_StringView)); \ + switch (ret.next) { \ + case FD_NEXT_SAMEFIELD: \ + dst = ret.dst; \ + goto again; \ + case FD_NEXT_OTHERFIELD: \ + data = ret.tag; \ + UPB_MUSTTAIL return _upb_FastDecoder_TagDispatch(UPB_PARSE_ARGS); \ + case FD_NEXT_ATLIMIT: \ + return ptr; \ + } \ + } \ + \ + if (card != CARD_r && validate_utf8) { \ + data = (uint64_t)dst; \ + UPB_MUSTTAIL return fastdecode_verifyutf8(UPB_PARSE_ARGS); \ + } \ + \ + UPB_MUSTTAIL return fastdecode_dispatch(UPB_PARSE_ARGS); \ + \ + longstr: \ + if (card == CARD_r) { \ + fastdecode_commitarr(dst + 1, &farr, sizeof(upb_StringView)); \ + } \ + ptr--; \ + if (validate_utf8) { \ + UPB_MUSTTAIL return fastdecode_longstring_utf8(d, ptr, msg, table, \ + hasbits, (uint64_t)dst); \ + } else { \ + UPB_MUSTTAIL return fastdecode_longstring_noutf8(d, ptr, msg, table, \ + hasbits, (uint64_t)dst); \ + } + +#define FASTDECODE_STRING(d, ptr, msg, table, hasbits, data, tagbytes, card, \ + copyfunc, validate_utf8) \ + upb_StringView* dst; \ + fastdecode_arr farr; \ + int64_t size; \ + \ + if (UPB_UNLIKELY(!fastdecode_checktag(data, tagbytes))) { \ + RETURN_GENERIC("string field tag mismatch\n"); \ + } \ + \ + if (UPB_UNLIKELY( \ + !upb_EpsCopyInputStream_AliasingAvailable(&d->input, ptr, 0))) { \ + UPB_MUSTTAIL return copyfunc(UPB_PARSE_ARGS); \ + } \ + \ + dst = fastdecode_getfield(d, ptr, msg, &data, &hasbits, &farr, \ + sizeof(upb_StringView), card); \ + \ + again: \ + if (card == CARD_r) { \ + dst = fastdecode_resizearr(d, dst, &farr, sizeof(upb_StringView)); \ + } \ + \ + size = (int8_t)ptr[tagbytes]; \ + ptr += tagbytes + 1; \ + \ + if (UPB_UNLIKELY( \ + !upb_EpsCopyInputStream_AliasingAvailable(&d->input, ptr, size))) { \ + ptr--; \ + if (validate_utf8) { \ + return fastdecode_longstring_utf8(d, ptr, msg, table, hasbits, \ + (uint64_t)dst); \ + } else { \ + return fastdecode_longstring_noutf8(d, ptr, msg, table, hasbits, \ + (uint64_t)dst); \ + } \ + } \ + \ + dst->data = ptr; \ + dst->size = size; \ + ptr = upb_EpsCopyInputStream_ReadStringAliased(&d->input, &dst->data, \ + dst->size); \ + \ + if (card == CARD_r) { \ + if (validate_utf8 && \ + !_upb_Decoder_VerifyUtf8Inline(dst->data, dst->size)) { \ + _upb_FastDecoder_ErrorJmp(d, kUpb_DecodeStatus_BadUtf8); \ + } \ + fastdecode_nextret ret = fastdecode_nextrepeated( \ + d, dst, &ptr, &farr, data, tagbytes, sizeof(upb_StringView)); \ + switch (ret.next) { \ + case FD_NEXT_SAMEFIELD: \ + dst = ret.dst; \ + goto again; \ + case FD_NEXT_OTHERFIELD: \ + data = ret.tag; \ + UPB_MUSTTAIL return _upb_FastDecoder_TagDispatch(UPB_PARSE_ARGS); \ + case FD_NEXT_ATLIMIT: \ + return ptr; \ + } \ + } \ + \ + if (card != CARD_r && validate_utf8) { \ + data = (uint64_t)dst; \ + UPB_MUSTTAIL return fastdecode_verifyutf8(UPB_PARSE_ARGS); \ + } \ + \ + UPB_MUSTTAIL return fastdecode_dispatch(UPB_PARSE_ARGS); + +/* Generate all combinations: + * {p,c} x {s,o,r} x {s, b} x {1bt,2bt} */ + +#define s_VALIDATE true +#define b_VALIDATE false + +#define F(card, tagbytes, type) \ + UPB_NOINLINE \ + const char* upb_c##card##type##_##tagbytes##bt(UPB_PARSE_PARAMS) { \ + FASTDECODE_COPYSTRING(d, ptr, msg, table, hasbits, data, tagbytes, \ + CARD_##card, type##_VALIDATE); \ + } \ + const char* upb_p##card##type##_##tagbytes##bt(UPB_PARSE_PARAMS) { \ + FASTDECODE_STRING(d, ptr, msg, table, hasbits, data, tagbytes, \ + CARD_##card, upb_c##card##type##_##tagbytes##bt, \ + type##_VALIDATE); \ + } + +#define UTF8(card, tagbytes) \ + F(card, tagbytes, s) \ + F(card, tagbytes, b) + +#define TAGBYTES(card) \ + UTF8(card, 1) \ + UTF8(card, 2) + +TAGBYTES(s) +TAGBYTES(o) +TAGBYTES(r) + +#undef s_VALIDATE +#undef b_VALIDATE +#undef F +#undef TAGBYTES +#undef FASTDECODE_LONGSTRING +#undef FASTDECODE_COPYSTRING +#undef FASTDECODE_STRING + +/* message fields *************************************************************/ + +UPB_INLINE +upb_Message* decode_newmsg_ceil(upb_Decoder* d, const upb_MiniTable* m, + int msg_ceil_bytes) { + size_t size = m->UPB_PRIVATE(size) + sizeof(upb_Message_Internal); + char* msg_data; + if (UPB_LIKELY(msg_ceil_bytes > 0 && + UPB_PRIVATE(_upb_ArenaHas)(&d->arena) >= msg_ceil_bytes)) { + UPB_ASSERT(size <= (size_t)msg_ceil_bytes); + msg_data = d->arena.UPB_PRIVATE(ptr); + d->arena.UPB_PRIVATE(ptr) += size; + UPB_UNPOISON_MEMORY_REGION(msg_data, msg_ceil_bytes); + memset(msg_data, 0, msg_ceil_bytes); + UPB_POISON_MEMORY_REGION(msg_data + size, msg_ceil_bytes - size); + } else { + msg_data = (char*)upb_Arena_Malloc(&d->arena, size); + memset(msg_data, 0, size); + } + return msg_data + sizeof(upb_Message_Internal); +} + +typedef struct { + intptr_t table; + upb_Message* msg; +} fastdecode_submsgdata; + +UPB_FORCEINLINE +static const char* fastdecode_tosubmsg(upb_EpsCopyInputStream* e, + const char* ptr, void* ctx) { + upb_Decoder* d = (upb_Decoder*)e; + fastdecode_submsgdata* submsg = ctx; + ptr = fastdecode_dispatch(d, ptr, submsg->msg, submsg->table, 0, 0); + UPB_ASSUME(ptr != NULL); + return ptr; } -const upb_FileDef* upb_FieldDef_File(const upb_FieldDef* f) { return f->file; } +#define FASTDECODE_SUBMSG(d, ptr, msg, table, hasbits, data, tagbytes, \ + msg_ceil_bytes, card) \ + \ + if (UPB_UNLIKELY(!fastdecode_checktag(data, tagbytes))) { \ + RETURN_GENERIC("submessage field tag mismatch\n"); \ + } \ + \ + if (--d->depth == 0) { \ + _upb_FastDecoder_ErrorJmp(d, kUpb_DecodeStatus_MaxDepthExceeded); \ + } \ + \ + upb_Message** dst; \ + uint32_t submsg_idx = (data >> 16) & 0xff; \ + const upb_MiniTable* tablep = decode_totablep(table); \ + const upb_MiniTable* subtablep = upb_MiniTableSub_Message( \ + *UPB_PRIVATE(_upb_MiniTable_GetSubByIndex)(tablep, submsg_idx)); \ + fastdecode_submsgdata submsg = {decode_totable(subtablep)}; \ + fastdecode_arr farr; \ + \ + if (subtablep->UPB_PRIVATE(table_mask) == (uint8_t)-1) { \ + d->depth++; \ + RETURN_GENERIC("submessage doesn't have fast tables."); \ + } \ + \ + dst = fastdecode_getfield(d, ptr, msg, &data, &hasbits, &farr, \ + sizeof(upb_Message*), card); \ + \ + if (card == CARD_s) { \ + *(uint32_t*)msg |= hasbits; \ + hasbits = 0; \ + } \ + \ + again: \ + if (card == CARD_r) { \ + dst = fastdecode_resizearr(d, dst, &farr, sizeof(upb_Message*)); \ + } \ + \ + submsg.msg = *dst; \ + \ + if (card == CARD_r || UPB_LIKELY(!submsg.msg)) { \ + *dst = submsg.msg = decode_newmsg_ceil(d, subtablep, msg_ceil_bytes); \ + } \ + \ + ptr += tagbytes; \ + ptr = fastdecode_delimited(d, ptr, fastdecode_tosubmsg, &submsg); \ + \ + if (UPB_UNLIKELY(ptr == NULL || d->end_group != DECODE_NOGROUP)) { \ + _upb_FastDecoder_ErrorJmp(d, kUpb_DecodeStatus_Malformed); \ + } \ + \ + if (card == CARD_r) { \ + fastdecode_nextret ret = fastdecode_nextrepeated( \ + d, dst, &ptr, &farr, data, tagbytes, sizeof(upb_Message*)); \ + switch (ret.next) { \ + case FD_NEXT_SAMEFIELD: \ + dst = ret.dst; \ + goto again; \ + case FD_NEXT_OTHERFIELD: \ + d->depth++; \ + data = ret.tag; \ + UPB_MUSTTAIL return _upb_FastDecoder_TagDispatch(UPB_PARSE_ARGS); \ + case FD_NEXT_ATLIMIT: \ + d->depth++; \ + return ptr; \ + } \ + } \ + \ + d->depth++; \ + UPB_MUSTTAIL return fastdecode_dispatch(UPB_PARSE_ARGS); + +#define F(card, tagbytes, size_ceil, ceil_arg) \ + const char* upb_p##card##m_##tagbytes##bt_max##size_ceil##b( \ + UPB_PARSE_PARAMS) { \ + FASTDECODE_SUBMSG(d, ptr, msg, table, hasbits, data, tagbytes, ceil_arg, \ + CARD_##card); \ + } + +#define SIZES(card, tagbytes) \ + F(card, tagbytes, 64, 64) \ + F(card, tagbytes, 128, 128) \ + F(card, tagbytes, 192, 192) \ + F(card, tagbytes, 256, 256) \ + F(card, tagbytes, max, -1) + +#define TAGBYTES(card) \ + SIZES(card, 1) \ + SIZES(card, 2) -const upb_MessageDef* upb_FieldDef_ContainingType(const upb_FieldDef* f) { - return f->msgdef; -} +TAGBYTES(s) +TAGBYTES(o) +TAGBYTES(r) -const upb_MessageDef* upb_FieldDef_ExtensionScope(const upb_FieldDef* f) { - return f->is_extension ? f->scope.extension_scope : NULL; -} +#undef TAGBYTES +#undef SIZES +#undef F +#undef FASTDECODE_SUBMSG -const upb_OneofDef* upb_FieldDef_ContainingOneof(const upb_FieldDef* f) { - return f->is_extension ? NULL : f->scope.oneof; -} +#endif /* UPB_FASTTABLE */ -const upb_OneofDef* upb_FieldDef_RealContainingOneof(const upb_FieldDef* f) { - const upb_OneofDef* oneof = upb_FieldDef_ContainingOneof(f); - if (!oneof || upb_OneofDef_IsSynthetic(oneof)) return NULL; - return oneof; -} -upb_MessageValue upb_FieldDef_Default(const upb_FieldDef* f) { - upb_MessageValue ret; +#include +#include - if (upb_FieldDef_IsRepeated(f) || upb_FieldDef_IsSubMessage(f)) { - return (upb_MessageValue){.msg_val = NULL}; - } - switch (upb_FieldDef_CType(f)) { - case kUpb_CType_Bool: - return (upb_MessageValue){.bool_val = f->defaultval.boolean}; - case kUpb_CType_Int64: - return (upb_MessageValue){.int64_val = f->defaultval.sint}; - case kUpb_CType_UInt64: - return (upb_MessageValue){.uint64_val = f->defaultval.uint}; - case kUpb_CType_Enum: - case kUpb_CType_Int32: - return (upb_MessageValue){.int32_val = (int32_t)f->defaultval.sint}; - case kUpb_CType_UInt32: - return (upb_MessageValue){.uint32_val = (uint32_t)f->defaultval.uint}; - case kUpb_CType_Float: - return (upb_MessageValue){.float_val = f->defaultval.flt}; - case kUpb_CType_Double: - return (upb_MessageValue){.double_val = f->defaultval.dbl}; - case kUpb_CType_String: - case kUpb_CType_Bytes: { - str_t* str = f->defaultval.str; - if (str) { - return (upb_MessageValue){ - .str_val = (upb_StringView){.data = str->str, .size = str->len}}; - } else { - return (upb_MessageValue){ - .str_val = (upb_StringView){.data = NULL, .size = 0}}; - } +// Must be last. + +UPB_NOINLINE UPB_PRIVATE(_upb_WireReader_LongVarint) + UPB_PRIVATE(_upb_WireReader_ReadLongVarint)(const char* ptr, uint64_t val) { + UPB_PRIVATE(_upb_WireReader_LongVarint) ret = {NULL, 0}; + uint64_t byte; + int i; + for (i = 1; i < 10; i++) { + byte = (uint8_t)ptr[i]; + val += (byte - 1) << (i * 7); + if (!(byte & 0x80)) { + ret.ptr = ptr + i + 1; + ret.val = val; + return ret; } - default: - UPB_UNREACHABLE(); } - return ret; } -const upb_MessageDef* upb_FieldDef_MessageSubDef(const upb_FieldDef* f) { - return upb_FieldDef_CType(f) == kUpb_CType_Message ? f->sub.msgdef : NULL; -} - -const upb_EnumDef* upb_FieldDef_EnumSubDef(const upb_FieldDef* f) { - return upb_FieldDef_CType(f) == kUpb_CType_Enum ? f->sub.enumdef : NULL; -} - -const upb_MiniTableField* upb_FieldDef_MiniTable(const upb_FieldDef* f) { - if (upb_FieldDef_IsExtension(f)) { - const upb_FileDef* file = upb_FieldDef_File(f); - return (upb_MiniTableField*)_upb_FileDef_ExtensionMiniTable( - file, f->layout_index); - } else { - const upb_MiniTable* layout = upb_MessageDef_MiniTable(f->msgdef); - return &layout->UPB_PRIVATE(fields)[f->layout_index]; +const char* UPB_PRIVATE(_upb_WireReader_SkipGroup)( + const char* ptr, uint32_t tag, int depth_limit, + upb_EpsCopyInputStream* stream) { + if (--depth_limit == 0) return NULL; + uint32_t end_group_tag = (tag & ~7ULL) | kUpb_WireType_EndGroup; + while (!upb_EpsCopyInputStream_IsDone(stream, &ptr)) { + uint32_t tag; + ptr = upb_WireReader_ReadTag(ptr, &tag); + if (!ptr) return NULL; + if (tag == end_group_tag) return ptr; + ptr = _upb_WireReader_SkipValue(ptr, tag, depth_limit, stream); + if (!ptr) return NULL; } + return ptr; } -const upb_MiniTableExtension* _upb_FieldDef_ExtensionMiniTable( - const upb_FieldDef* f) { - UPB_ASSERT(upb_FieldDef_IsExtension(f)); - const upb_FileDef* file = upb_FieldDef_File(f); - return _upb_FileDef_ExtensionMiniTable(file, f->layout_index); -} +/* + * upb_table Implementation + * + * Implementation is heavily inspired by Lua's ltable.c. + */ -bool _upb_FieldDef_IsClosedEnum(const upb_FieldDef* f) { - if (f->type_ != kUpb_FieldType_Enum) return false; - return upb_EnumDef_IsClosed(f->sub.enumdef); -} +#include -bool _upb_FieldDef_IsProto3Optional(const upb_FieldDef* f) { - return f->is_proto3_optional; -} -int _upb_FieldDef_LayoutIndex(const upb_FieldDef* f) { return f->layout_index; } +// Must be last. -bool _upb_FieldDef_ValidateUtf8(const upb_FieldDef* f) { - if (upb_FieldDef_Type(f) != kUpb_FieldType_String) return false; - return UPB_DESC(FeatureSet_utf8_validation(f->resolved_features)) == - UPB_DESC(FeatureSet_VERIFY); -} +#define UPB_MAXARRSIZE 16 // 2**16 = 64k. -uint64_t _upb_FieldDef_Modifiers(const upb_FieldDef* f) { - uint64_t out = upb_FieldDef_IsPacked(f) ? kUpb_FieldModifier_IsPacked : 0; +// From Chromium. +#define ARRAY_SIZE(x) \ + ((sizeof(x) / sizeof(0 [x])) / ((size_t)(!(sizeof(x) % sizeof(0 [x]))))) - if (upb_FieldDef_IsRepeated(f)) { - out |= kUpb_FieldModifier_IsRepeated; - } else if (upb_FieldDef_IsRequired(f)) { - out |= kUpb_FieldModifier_IsRequired; - } else if (!upb_FieldDef_HasPresence(f)) { - out |= kUpb_FieldModifier_IsProto3Singular; - } +static const double MAX_LOAD = 0.85; - if (_upb_FieldDef_IsClosedEnum(f)) { - out |= kUpb_FieldModifier_IsClosedEnum; - } +/* The minimum utilization of the array part of a mixed hash/array table. This + * is a speed/memory-usage tradeoff (though it's not straightforward because of + * cache effects). The lower this is, the more memory we'll use. */ +static const double MIN_DENSITY = 0.1; - if (_upb_FieldDef_ValidateUtf8(f)) { - out |= kUpb_FieldModifier_ValidateUtf8; - } +static bool is_pow2(uint64_t v) { return v == 0 || (v & (v - 1)) == 0; } - return out; +static upb_value _upb_value_val(uint64_t val) { + upb_value ret; + _upb_value_setval(&ret, val); + return ret; } -bool upb_FieldDef_HasDefault(const upb_FieldDef* f) { return f->has_default; } -bool upb_FieldDef_HasPresence(const upb_FieldDef* f) { return f->has_presence; } - -bool upb_FieldDef_HasSubDef(const upb_FieldDef* f) { - return upb_FieldDef_IsSubMessage(f) || - upb_FieldDef_CType(f) == kUpb_CType_Enum; +static int log2ceil(uint64_t v) { + int ret = 0; + bool pow2 = is_pow2(v); + while (v >>= 1) ret++; + ret = pow2 ? ret : ret + 1; // Ceiling. + return UPB_MIN(UPB_MAXARRSIZE, ret); } -bool upb_FieldDef_IsMap(const upb_FieldDef* f) { - return upb_FieldDef_IsRepeated(f) && upb_FieldDef_IsSubMessage(f) && - upb_MessageDef_IsMapEntry(upb_FieldDef_MessageSubDef(f)); -} +/* A type to represent the lookup key of either a strtable or an inttable. */ +typedef union { + uintptr_t num; + struct { + const char* str; + size_t len; + } str; +} lookupkey_t; -bool upb_FieldDef_IsOptional(const upb_FieldDef* f) { - return upb_FieldDef_Label(f) == kUpb_Label_Optional; +static lookupkey_t strkey2(const char* str, size_t len) { + lookupkey_t k; + k.str.str = str; + k.str.len = len; + return k; } -bool upb_FieldDef_IsPrimitive(const upb_FieldDef* f) { - return !upb_FieldDef_IsString(f) && !upb_FieldDef_IsSubMessage(f); +static lookupkey_t intkey(uintptr_t key) { + lookupkey_t k; + k.num = key; + return k; } -bool upb_FieldDef_IsRepeated(const upb_FieldDef* f) { - return upb_FieldDef_Label(f) == kUpb_Label_Repeated; -} +typedef uint32_t hashfunc_t(upb_tabkey key); +typedef bool eqlfunc_t(upb_tabkey k1, lookupkey_t k2); -bool upb_FieldDef_IsRequired(const upb_FieldDef* f) { - return UPB_DESC(FeatureSet_field_presence)(f->resolved_features) == - UPB_DESC(FeatureSet_LEGACY_REQUIRED); -} +/* Base table (shared code) ***************************************************/ -bool upb_FieldDef_IsString(const upb_FieldDef* f) { - return upb_FieldDef_CType(f) == kUpb_CType_String || - upb_FieldDef_CType(f) == kUpb_CType_Bytes; -} +static uint32_t upb_inthash(uintptr_t key) { return (uint32_t)key; } -bool upb_FieldDef_IsSubMessage(const upb_FieldDef* f) { - return upb_FieldDef_CType(f) == kUpb_CType_Message; +static const upb_tabent* upb_getentry(const upb_table* t, uint32_t hash) { + return t->entries + (hash & t->mask); } -static bool between(int32_t x, int32_t low, int32_t high) { - return x >= low && x <= high; -} +static bool upb_arrhas(upb_tabval key) { return key.val != (uint64_t)-1; } -bool upb_FieldDef_checklabel(int32_t label) { return between(label, 1, 3); } -bool upb_FieldDef_checktype(int32_t type) { return between(type, 1, 11); } -bool upb_FieldDef_checkintfmt(int32_t fmt) { return between(fmt, 1, 3); } +static bool isfull(upb_table* t) { return t->count == t->max_count; } -bool upb_FieldDef_checkdescriptortype(int32_t type) { - return between(type, 1, 18); +static bool init(upb_table* t, uint8_t size_lg2, upb_Arena* a) { + size_t bytes; + + t->count = 0; + t->size_lg2 = size_lg2; + t->mask = upb_table_size(t) ? upb_table_size(t) - 1 : 0; + t->max_count = upb_table_size(t) * MAX_LOAD; + bytes = upb_table_size(t) * sizeof(upb_tabent); + if (bytes > 0) { + t->entries = upb_Arena_Malloc(a, bytes); + if (!t->entries) return false; + memset(t->entries, 0, bytes); + } else { + t->entries = NULL; + } + return true; +} + +static upb_tabent* emptyent(upb_table* t, upb_tabent* e) { + upb_tabent* begin = t->entries; + upb_tabent* end = begin + upb_table_size(t); + for (e = e + 1; e < end; e++) { + if (upb_tabent_isempty(e)) return e; + } + for (e = begin; e < end; e++) { + if (upb_tabent_isempty(e)) return e; + } + UPB_ASSERT(false); + return NULL; } -static bool streql2(const char* a, size_t n, const char* b) { - return n == strlen(b) && memcmp(a, b, n) == 0; +static upb_tabent* getentry_mutable(upb_table* t, uint32_t hash) { + return (upb_tabent*)upb_getentry(t, hash); } -// Implement the transformation as described in the spec: -// 1. upper case all letters after an underscore. -// 2. remove all underscores. -static char* make_json_name(const char* name, size_t size, upb_Arena* a) { - char* out = upb_Arena_Malloc(a, size + 1); // +1 is to add a trailing '\0' - if (out == NULL) return NULL; +static const upb_tabent* findentry(const upb_table* t, lookupkey_t key, + uint32_t hash, eqlfunc_t* eql) { + const upb_tabent* e; - bool ucase_next = false; - char* des = out; - for (size_t i = 0; i < size; i++) { - if (name[i] == '_') { - ucase_next = true; - } else { - *des++ = ucase_next ? toupper(name[i]) : name[i]; - ucase_next = false; - } + if (t->size_lg2 == 0) return NULL; + e = upb_getentry(t, hash); + if (upb_tabent_isempty(e)) return NULL; + while (1) { + if (eql(e->key, key)) return e; + if ((e = e->next) == NULL) return NULL; } - *des++ = '\0'; - return out; } -static str_t* newstr(upb_DefBuilder* ctx, const char* data, size_t len) { - str_t* ret = _upb_DefBuilder_Alloc(ctx, sizeof(*ret) + len); - if (!ret) _upb_DefBuilder_OomErr(ctx); - ret->len = len; - if (len) memcpy(ret->str, data, len); - ret->str[len] = '\0'; - return ret; +static upb_tabent* findentry_mutable(upb_table* t, lookupkey_t key, + uint32_t hash, eqlfunc_t* eql) { + return (upb_tabent*)findentry(t, key, hash, eql); } -static str_t* unescape(upb_DefBuilder* ctx, const upb_FieldDef* f, - const char* data, size_t len) { - // Size here is an upper bound; escape sequences could ultimately shrink it. - str_t* ret = _upb_DefBuilder_Alloc(ctx, sizeof(*ret) + len); - char* dst = &ret->str[0]; - const char* src = data; - const char* end = data + len; - - while (src < end) { - if (*src == '\\') { - src++; - *dst++ = _upb_DefBuilder_ParseEscape(ctx, f, &src, end); - } else { - *dst++ = *src++; +static bool lookup(const upb_table* t, lookupkey_t key, upb_value* v, + uint32_t hash, eqlfunc_t* eql) { + const upb_tabent* e = findentry(t, key, hash, eql); + if (e) { + if (v) { + _upb_value_setval(v, e->val.val); } + return true; + } else { + return false; } - - ret->len = dst - &ret->str[0]; - return ret; } -static void parse_default(upb_DefBuilder* ctx, const char* str, size_t len, - upb_FieldDef* f) { - char* end; - char nullz[64]; - errno = 0; +/* The given key must not already exist in the table. */ +static void insert(upb_table* t, lookupkey_t key, upb_tabkey tabkey, + upb_value val, uint32_t hash, hashfunc_t* hashfunc, + eqlfunc_t* eql) { + upb_tabent* mainpos_e; + upb_tabent* our_e; - switch (upb_FieldDef_CType(f)) { - case kUpb_CType_Int32: - case kUpb_CType_Int64: - case kUpb_CType_UInt32: - case kUpb_CType_UInt64: - case kUpb_CType_Double: - case kUpb_CType_Float: - // Standard C number parsing functions expect null-terminated strings. - if (len >= sizeof(nullz) - 1) { - _upb_DefBuilder_Errf(ctx, "Default too long: %.*s", (int)len, str); - } - memcpy(nullz, str, len); - nullz[len] = '\0'; - str = nullz; - break; - default: - break; - } + UPB_ASSERT(findentry(t, key, hash, eql) == NULL); - switch (upb_FieldDef_CType(f)) { - case kUpb_CType_Int32: { - long val = strtol(str, &end, 0); - if (val > INT32_MAX || val < INT32_MIN || errno == ERANGE || *end) { - goto invalid; - } - f->defaultval.sint = val; - break; - } - case kUpb_CType_Enum: { - const upb_EnumDef* e = f->sub.enumdef; - const upb_EnumValueDef* ev = - upb_EnumDef_FindValueByNameWithSize(e, str, len); - if (!ev) { - goto invalid; - } - f->defaultval.sint = upb_EnumValueDef_Number(ev); - break; - } - case kUpb_CType_Int64: { - long long val = strtoll(str, &end, 0); - if (val > INT64_MAX || val < INT64_MIN || errno == ERANGE || *end) { - goto invalid; - } - f->defaultval.sint = val; - break; - } - case kUpb_CType_UInt32: { - unsigned long val = strtoul(str, &end, 0); - if (val > UINT32_MAX || errno == ERANGE || *end) { - goto invalid; - } - f->defaultval.uint = val; - break; - } - case kUpb_CType_UInt64: { - unsigned long long val = strtoull(str, &end, 0); - if (val > UINT64_MAX || errno == ERANGE || *end) { - goto invalid; - } - f->defaultval.uint = val; - break; - } - case kUpb_CType_Double: { - double val = strtod(str, &end); - if (errno == ERANGE || *end) { - goto invalid; - } - f->defaultval.dbl = val; - break; - } - case kUpb_CType_Float: { - float val = strtof(str, &end); - if (errno == ERANGE || *end) { - goto invalid; - } - f->defaultval.flt = val; - break; - } - case kUpb_CType_Bool: { - if (streql2(str, len, "false")) { - f->defaultval.boolean = false; - } else if (streql2(str, len, "true")) { - f->defaultval.boolean = true; - } else { - goto invalid; + t->count++; + mainpos_e = getentry_mutable(t, hash); + our_e = mainpos_e; + + if (upb_tabent_isempty(mainpos_e)) { + /* Our main position is empty; use it. */ + our_e->next = NULL; + } else { + /* Collision. */ + upb_tabent* new_e = emptyent(t, mainpos_e); + /* Head of collider's chain. */ + upb_tabent* chain = getentry_mutable(t, hashfunc(mainpos_e->key)); + if (chain == mainpos_e) { + /* Existing ent is in its main position (it has the same hash as us, and + * is the head of our chain). Insert to new ent and append to this chain. + */ + new_e->next = mainpos_e->next; + mainpos_e->next = new_e; + our_e = new_e; + } else { + /* Existing ent is not in its main position (it is a node in some other + * chain). This implies that no existing ent in the table has our hash. + * Evict it (updating its chain) and use its ent for head of our chain. */ + *new_e = *mainpos_e; /* copies next. */ + while (chain->next != mainpos_e) { + chain = (upb_tabent*)chain->next; + UPB_ASSERT(chain); } - break; + chain->next = new_e; + our_e = mainpos_e; + our_e->next = NULL; } - case kUpb_CType_String: - f->defaultval.str = newstr(ctx, str, len); - break; - case kUpb_CType_Bytes: - f->defaultval.str = unescape(ctx, f, str, len); - break; - case kUpb_CType_Message: - /* Should not have a default value. */ - _upb_DefBuilder_Errf(ctx, "Message should not have a default (%s)", - upb_FieldDef_FullName(f)); } - - return; - -invalid: - _upb_DefBuilder_Errf(ctx, "Invalid default '%.*s' for field %s of type %d", - (int)len, str, upb_FieldDef_FullName(f), - (int)upb_FieldDef_Type(f)); + our_e->key = tabkey; + our_e->val.val = val.val; + UPB_ASSERT(findentry(t, key, hash, eql) == our_e); } -static void set_default_default(upb_DefBuilder* ctx, upb_FieldDef* f) { - switch (upb_FieldDef_CType(f)) { - case kUpb_CType_Int32: - case kUpb_CType_Int64: - f->defaultval.sint = 0; - break; - case kUpb_CType_UInt64: - case kUpb_CType_UInt32: - f->defaultval.uint = 0; - break; - case kUpb_CType_Double: - case kUpb_CType_Float: - f->defaultval.dbl = 0; - break; - case kUpb_CType_String: - case kUpb_CType_Bytes: - f->defaultval.str = newstr(ctx, NULL, 0); - break; - case kUpb_CType_Bool: - f->defaultval.boolean = false; - break; - case kUpb_CType_Enum: { - const upb_EnumValueDef* v = upb_EnumDef_Value(f->sub.enumdef, 0); - f->defaultval.sint = upb_EnumValueDef_Number(v); - break; +static bool rm(upb_table* t, lookupkey_t key, upb_value* val, + upb_tabkey* removed, uint32_t hash, eqlfunc_t* eql) { + upb_tabent* chain = getentry_mutable(t, hash); + if (upb_tabent_isempty(chain)) return false; + if (eql(chain->key, key)) { + /* Element to remove is at the head of its chain. */ + t->count--; + if (val) _upb_value_setval(val, chain->val.val); + if (removed) *removed = chain->key; + if (chain->next) { + upb_tabent* move = (upb_tabent*)chain->next; + *chain = *move; + move->key = 0; /* Make the slot empty. */ + } else { + chain->key = 0; /* Make the slot empty. */ + } + return true; + } else { + /* Element to remove is either in a non-head position or not in the + * table. */ + while (chain->next && !eql(chain->next->key, key)) { + chain = (upb_tabent*)chain->next; + } + if (chain->next) { + /* Found element to remove. */ + upb_tabent* rm = (upb_tabent*)chain->next; + t->count--; + if (val) _upb_value_setval(val, chain->next->val.val); + if (removed) *removed = rm->key; + rm->key = 0; /* Make the slot empty. */ + chain->next = rm->next; + return true; + } else { + /* Element to remove is not in the table. */ + return false; } - case kUpb_CType_Message: - break; } } -static bool _upb_FieldDef_InferLegacyFeatures( - upb_DefBuilder* ctx, upb_FieldDef* f, - const UPB_DESC(FieldDescriptorProto*) proto, - const UPB_DESC(FieldOptions*) options, upb_Syntax syntax, - UPB_DESC(FeatureSet*) features) { - bool ret = false; +static size_t next(const upb_table* t, size_t i) { + do { + if (++i >= upb_table_size(t)) return SIZE_MAX - 1; /* Distinct from -1. */ + } while (upb_tabent_isempty(&t->entries[i])); - if (UPB_DESC(FieldDescriptorProto_label)(proto) == kUpb_Label_Required) { - if (syntax == kUpb_Syntax_Proto3) { - _upb_DefBuilder_Errf(ctx, "proto3 fields cannot be required (%s)", - f->full_name); - } - int val = UPB_DESC(FeatureSet_LEGACY_REQUIRED); - UPB_DESC(FeatureSet_set_field_presence(features, val)); - ret = true; - } + return i; +} - if (UPB_DESC(FieldDescriptorProto_type)(proto) == kUpb_FieldType_Group) { - int val = UPB_DESC(FeatureSet_DELIMITED); - UPB_DESC(FeatureSet_set_message_encoding(features, val)); - ret = true; - } +static size_t begin(const upb_table* t) { return next(t, -1); } - if (UPB_DESC(FieldOptions_has_packed)(options)) { - int val = UPB_DESC(FieldOptions_packed)(options) - ? UPB_DESC(FeatureSet_PACKED) - : UPB_DESC(FeatureSet_EXPANDED); - UPB_DESC(FeatureSet_set_repeated_field_encoding(features, val)); - ret = true; - } +/* upb_strtable ***************************************************************/ -// begin:google_only -// #ifndef UPB_BOOTSTRAP_STAGE0 -// if (syntax == kUpb_Syntax_Proto3 && -// UPB_DESC(FieldOptions_has_enforce_utf8)(options) && -// !UPB_DESC(FieldOptions_enforce_utf8)(options)) { -// int val = UPB_DESC(FeatureSet_UNVERIFIED); -// UPB_DESC(FeatureSet_set_utf8_validation(features, val)); -// ret = true; -// } -// #endif -// // clang-format off -// end:google_only - // clang-format on +/* A simple "subclass" of upb_table that only adds a hash function for strings. + */ - return ret; +static upb_tabkey strcopy(lookupkey_t k2, upb_Arena* a) { + uint32_t len = (uint32_t)k2.str.len; + char* str = upb_Arena_Malloc(a, k2.str.len + sizeof(uint32_t) + 1); + if (str == NULL) return 0; + memcpy(str, &len, sizeof(uint32_t)); + if (k2.str.len) memcpy(str + sizeof(uint32_t), k2.str.str, k2.str.len); + str[sizeof(uint32_t) + k2.str.len] = '\0'; + return (uintptr_t)str; } -static void _upb_FieldDef_Create(upb_DefBuilder* ctx, const char* prefix, - const UPB_DESC(FeatureSet*) parent_features, - const UPB_DESC(FieldDescriptorProto*) - field_proto, - upb_MessageDef* m, upb_FieldDef* f) { - // Must happen before _upb_DefBuilder_Add() - f->file = _upb_DefBuilder_File(ctx); +/* Adapted from ABSL's wyhash. */ - const upb_StringView name = UPB_DESC(FieldDescriptorProto_name)(field_proto); - f->full_name = _upb_DefBuilder_MakeFullName(ctx, prefix, name); - f->label_ = (int)UPB_DESC(FieldDescriptorProto_label)(field_proto); - f->number_ = UPB_DESC(FieldDescriptorProto_number)(field_proto); - f->is_proto3_optional = - UPB_DESC(FieldDescriptorProto_proto3_optional)(field_proto); - f->msgdef = m; - f->scope.oneof = NULL; +static uint64_t UnalignedLoad64(const void* p) { + uint64_t val; + memcpy(&val, p, 8); + return val; +} - UPB_DEF_SET_OPTIONS(f->opts, FieldDescriptorProto, FieldOptions, field_proto); +static uint32_t UnalignedLoad32(const void* p) { + uint32_t val; + memcpy(&val, p, 4); + return val; +} - upb_Syntax syntax = upb_FileDef_Syntax(f->file); - const UPB_DESC(FeatureSet*) unresolved_features = - UPB_DESC(FieldOptions_features)(f->opts); - bool implicit = false; +#if defined(_MSC_VER) && defined(_M_X64) +#include +#endif - if (syntax != kUpb_Syntax_Editions) { - upb_Message_Clear(UPB_UPCAST(ctx->legacy_features), - UPB_DESC_MINITABLE(FeatureSet)); - if (_upb_FieldDef_InferLegacyFeatures(ctx, f, field_proto, f->opts, syntax, - ctx->legacy_features)) { - implicit = true; - unresolved_features = ctx->legacy_features; - } - } +/* Computes a * b, returning the low 64 bits of the result and storing the high + * 64 bits in |*high|. */ +static uint64_t upb_umul128(uint64_t v0, uint64_t v1, uint64_t* out_high) { +#ifdef __SIZEOF_INT128__ + __uint128_t p = v0; + p *= v1; + *out_high = (uint64_t)(p >> 64); + return (uint64_t)p; +#elif defined(_MSC_VER) && defined(_M_X64) + return _umul128(v0, v1, out_high); +#else + uint64_t a32 = v0 >> 32; + uint64_t a00 = v0 & 0xffffffff; + uint64_t b32 = v1 >> 32; + uint64_t b00 = v1 & 0xffffffff; + uint64_t high = a32 * b32; + uint64_t low = a00 * b00; + uint64_t mid1 = a32 * b00; + uint64_t mid2 = a00 * b32; + low += (mid1 << 32) + (mid2 << 32); + // Omit carry bit, for mixing we do not care about exact numerical precision. + high += (mid1 >> 32) + (mid2 >> 32); + *out_high = high; + return low; +#endif +} - if (UPB_DESC(FieldDescriptorProto_has_oneof_index)(field_proto)) { - int oneof_index = UPB_DESC(FieldDescriptorProto_oneof_index)(field_proto); +static uint64_t WyhashMix(uint64_t v0, uint64_t v1) { + uint64_t high; + uint64_t low = upb_umul128(v0, v1, &high); + return low ^ high; +} - if (!m) { - _upb_DefBuilder_Errf(ctx, "oneof field (%s) has no containing msg", - f->full_name); - } +static uint64_t Wyhash(const void* data, size_t len, uint64_t seed, + const uint64_t salt[]) { + const uint8_t* ptr = (const uint8_t*)data; + uint64_t starting_length = (uint64_t)len; + uint64_t current_state = seed ^ salt[0]; - if (oneof_index >= upb_MessageDef_OneofCount(m)) { - _upb_DefBuilder_Errf(ctx, "oneof_index out of range (%s)", f->full_name); - } + if (len > 64) { + // If we have more than 64 bytes, we're going to handle chunks of 64 + // bytes at a time. We're going to build up two separate hash states + // which we will then hash together. + uint64_t duplicated_state = current_state; - upb_OneofDef* oneof = (upb_OneofDef*)upb_MessageDef_Oneof(m, oneof_index); - f->scope.oneof = oneof; - parent_features = upb_OneofDef_ResolvedFeatures(oneof); + do { + uint64_t a = UnalignedLoad64(ptr); + uint64_t b = UnalignedLoad64(ptr + 8); + uint64_t c = UnalignedLoad64(ptr + 16); + uint64_t d = UnalignedLoad64(ptr + 24); + uint64_t e = UnalignedLoad64(ptr + 32); + uint64_t f = UnalignedLoad64(ptr + 40); + uint64_t g = UnalignedLoad64(ptr + 48); + uint64_t h = UnalignedLoad64(ptr + 56); - _upb_OneofDef_Insert(ctx, oneof, f, name.data, name.size); - } + uint64_t cs0 = WyhashMix(a ^ salt[1], b ^ current_state); + uint64_t cs1 = WyhashMix(c ^ salt[2], d ^ current_state); + current_state = (cs0 ^ cs1); - f->resolved_features = _upb_DefBuilder_DoResolveFeatures( - ctx, parent_features, unresolved_features, implicit); + uint64_t ds0 = WyhashMix(e ^ salt[3], f ^ duplicated_state); + uint64_t ds1 = WyhashMix(g ^ salt[4], h ^ duplicated_state); + duplicated_state = (ds0 ^ ds1); - if (!UPB_DESC(FieldDescriptorProto_has_name)(field_proto)) { - _upb_DefBuilder_Errf(ctx, "field has no name"); - } + ptr += 64; + len -= 64; + } while (len > 64); - f->has_json_name = UPB_DESC(FieldDescriptorProto_has_json_name)(field_proto); - if (f->has_json_name) { - const upb_StringView sv = - UPB_DESC(FieldDescriptorProto_json_name)(field_proto); - f->json_name = upb_strdup2(sv.data, sv.size, ctx->arena); - } else { - f->json_name = make_json_name(name.data, name.size, ctx->arena); + current_state = current_state ^ duplicated_state; } - if (!f->json_name) _upb_DefBuilder_OomErr(ctx); - const bool has_type = UPB_DESC(FieldDescriptorProto_has_type)(field_proto); - const bool has_type_name = - UPB_DESC(FieldDescriptorProto_has_type_name)(field_proto); + // We now have a data `ptr` with at most 64 bytes and the current state + // of the hashing state machine stored in current_state. + while (len > 16) { + uint64_t a = UnalignedLoad64(ptr); + uint64_t b = UnalignedLoad64(ptr + 8); - f->type_ = (int)UPB_DESC(FieldDescriptorProto_type)(field_proto); + current_state = WyhashMix(a ^ salt[1], b ^ current_state); - if (has_type) { - switch (f->type_) { - case kUpb_FieldType_Message: - case kUpb_FieldType_Group: - case kUpb_FieldType_Enum: - if (!has_type_name) { - _upb_DefBuilder_Errf(ctx, "field of type %d requires type name (%s)", - (int)f->type_, f->full_name); - } - break; - default: - if (has_type_name) { - _upb_DefBuilder_Errf( - ctx, "invalid type for field with type_name set (%s, %d)", - f->full_name, (int)f->type_); - } - } + ptr += 16; + len -= 16; } - if (!has_type && has_type_name) { - f->type_ = - UPB_FIELD_TYPE_UNSPECIFIED; // We'll assign this in resolve_subdef() + // We now have a data `ptr` with at most 16 bytes. + uint64_t a = 0; + uint64_t b = 0; + if (len > 8) { + // When we have at least 9 and at most 16 bytes, set A to the first 64 + // bits of the input and B to the last 64 bits of the input. Yes, they will + // overlap in the middle if we are working with less than the full 16 + // bytes. + a = UnalignedLoad64(ptr); + b = UnalignedLoad64(ptr + len - 8); + } else if (len > 3) { + // If we have at least 4 and at most 8 bytes, set A to the first 32 + // bits and B to the last 32 bits. + a = UnalignedLoad32(ptr); + b = UnalignedLoad32(ptr + len - 4); + } else if (len > 0) { + // If we have at least 1 and at most 3 bytes, read all of the provided + // bits into A, with some adjustments. + a = ((ptr[0] << 16) | (ptr[len >> 1] << 8) | ptr[len - 1]); + b = 0; } else { - if (f->type_ < kUpb_FieldType_Double || f->type_ > kUpb_FieldType_SInt64) { - _upb_DefBuilder_Errf(ctx, "invalid type for field %s (%d)", f->full_name, - f->type_); - } + a = 0; + b = 0; } - if (f->label_ < kUpb_Label_Optional || f->label_ > kUpb_Label_Repeated) { - _upb_DefBuilder_Errf(ctx, "invalid label for field %s (%d)", f->full_name, - f->label_); - } + uint64_t w = WyhashMix(a ^ salt[1], b ^ current_state); + uint64_t z = salt[1] ^ starting_length; + return WyhashMix(w, z); +} - /* We can't resolve the subdef or (in the case of extensions) the containing - * message yet, because it may not have been defined yet. We stash a pointer - * to the field_proto until later when we can properly resolve it. */ - f->sub.unresolved = field_proto; +const uint64_t kWyhashSalt[5] = { + 0x243F6A8885A308D3ULL, 0x13198A2E03707344ULL, 0xA4093822299F31D0ULL, + 0x082EFA98EC4E6C89ULL, 0x452821E638D01377ULL, +}; - if (UPB_DESC(FieldDescriptorProto_has_oneof_index)(field_proto)) { - if (upb_FieldDef_Label(f) != kUpb_Label_Optional) { - _upb_DefBuilder_Errf(ctx, "fields in oneof must have OPTIONAL label (%s)", - f->full_name); - } - } +uint32_t _upb_Hash(const void* p, size_t n, uint64_t seed) { + return Wyhash(p, n, seed, kWyhashSalt); +} - f->has_presence = - (!upb_FieldDef_IsRepeated(f)) && - (f->type_ == kUpb_FieldType_Message || f->type_ == kUpb_FieldType_Group || - upb_FieldDef_ContainingOneof(f) || - UPB_DESC(FeatureSet_field_presence)(f->resolved_features) != - UPB_DESC(FeatureSet_IMPLICIT)); +static uint32_t _upb_Hash_NoSeed(const char* p, size_t n) { + return _upb_Hash(p, n, 0); } -static void _upb_FieldDef_CreateExt(upb_DefBuilder* ctx, const char* prefix, - const UPB_DESC(FeatureSet*) parent_features, - const UPB_DESC(FieldDescriptorProto*) - field_proto, - upb_MessageDef* m, upb_FieldDef* f) { - f->is_extension = true; - _upb_FieldDef_Create(ctx, prefix, parent_features, field_proto, m, f); +static uint32_t strhash(upb_tabkey key) { + uint32_t len; + char* str = upb_tabstr(key, &len); + return _upb_Hash_NoSeed(str, len); +} - if (UPB_DESC(FieldDescriptorProto_has_oneof_index)(field_proto)) { - _upb_DefBuilder_Errf(ctx, "oneof_index provided for extension field (%s)", - f->full_name); - } +static bool streql(upb_tabkey k1, lookupkey_t k2) { + uint32_t len; + char* str = upb_tabstr(k1, &len); + return len == k2.str.len && (len == 0 || memcmp(str, k2.str.str, len) == 0); +} - f->scope.extension_scope = m; - _upb_DefBuilder_Add(ctx, f->full_name, _upb_DefType_Pack(f, UPB_DEFTYPE_EXT)); - f->layout_index = ctx->ext_count++; +bool upb_strtable_init(upb_strtable* t, size_t expected_size, upb_Arena* a) { + // Multiply by approximate reciprocal of MAX_LOAD (0.85), with pow2 + // denominator. + size_t need_entries = (expected_size + 1) * 1204 / 1024; + UPB_ASSERT(need_entries >= expected_size * 0.85); + int size_lg2 = upb_Log2Ceiling(need_entries); + return init(&t->t, size_lg2, a); +} - if (ctx->layout) { - UPB_ASSERT(upb_MiniTableExtension_Number( - _upb_FieldDef_ExtensionMiniTable(f)) == f->number_); +void upb_strtable_clear(upb_strtable* t) { + size_t bytes = upb_table_size(&t->t) * sizeof(upb_tabent); + t->t.count = 0; + memset((char*)t->t.entries, 0, bytes); +} + +bool upb_strtable_resize(upb_strtable* t, size_t size_lg2, upb_Arena* a) { + upb_strtable new_table; + if (!init(&new_table.t, size_lg2, a)) return false; + + intptr_t iter = UPB_STRTABLE_BEGIN; + upb_StringView key; + upb_value val; + while (upb_strtable_next2(t, &key, &val, &iter)) { + upb_strtable_insert(&new_table, key.data, key.size, val, a); } + *t = new_table; + return true; } -static void _upb_FieldDef_CreateNotExt(upb_DefBuilder* ctx, const char* prefix, - const UPB_DESC(FeatureSet*) - parent_features, - const UPB_DESC(FieldDescriptorProto*) - field_proto, - upb_MessageDef* m, upb_FieldDef* f) { - f->is_extension = false; - _upb_FieldDef_Create(ctx, prefix, parent_features, field_proto, m, f); +bool upb_strtable_insert(upb_strtable* t, const char* k, size_t len, + upb_value v, upb_Arena* a) { + lookupkey_t key; + upb_tabkey tabkey; + uint32_t hash; - if (!UPB_DESC(FieldDescriptorProto_has_oneof_index)(field_proto)) { - if (f->is_proto3_optional) { - _upb_DefBuilder_Errf( - ctx, - "non-extension field (%s) with proto3_optional was not in a oneof", - f->full_name); + if (isfull(&t->t)) { + /* Need to resize. New table of double the size, add old elements to it. */ + if (!upb_strtable_resize(t, t->t.size_lg2 + 1, a)) { + return false; } } - _upb_MessageDef_InsertField(ctx, m, f); + key = strkey2(k, len); + tabkey = strcopy(key, a); + if (tabkey == 0) return false; + + hash = _upb_Hash_NoSeed(key.str.str, key.str.len); + insert(&t->t, key, tabkey, v, hash, &strhash, &streql); + return true; } -upb_FieldDef* _upb_Extensions_New(upb_DefBuilder* ctx, int n, - const UPB_DESC(FieldDescriptorProto*) - const* protos, - const UPB_DESC(FeatureSet*) parent_features, - const char* prefix, upb_MessageDef* m) { - _upb_DefType_CheckPadding(sizeof(upb_FieldDef)); - upb_FieldDef* defs = - (upb_FieldDef*)_upb_DefBuilder_Alloc(ctx, sizeof(upb_FieldDef) * n); +bool upb_strtable_lookup2(const upb_strtable* t, const char* key, size_t len, + upb_value* v) { + uint32_t hash = _upb_Hash_NoSeed(key, len); + return lookup(&t->t, strkey2(key, len), v, hash, &streql); +} - for (int i = 0; i < n; i++) { - upb_FieldDef* f = &defs[i]; +bool upb_strtable_remove2(upb_strtable* t, const char* key, size_t len, + upb_value* val) { + uint32_t hash = _upb_Hash_NoSeed(key, len); + upb_tabkey tabkey; + return rm(&t->t, strkey2(key, len), val, &tabkey, hash, &streql); +} - _upb_FieldDef_CreateExt(ctx, prefix, parent_features, protos[i], m, f); - f->index_ = i; - } +/* Iteration */ - return defs; +void upb_strtable_begin(upb_strtable_iter* i, const upb_strtable* t) { + i->t = t; + i->index = begin(&t->t); } -upb_FieldDef* _upb_FieldDefs_New(upb_DefBuilder* ctx, int n, - const UPB_DESC(FieldDescriptorProto*) - const* protos, - const UPB_DESC(FeatureSet*) parent_features, - const char* prefix, upb_MessageDef* m, - bool* is_sorted) { - _upb_DefType_CheckPadding(sizeof(upb_FieldDef)); - upb_FieldDef* defs = - (upb_FieldDef*)_upb_DefBuilder_Alloc(ctx, sizeof(upb_FieldDef) * n); +void upb_strtable_next(upb_strtable_iter* i) { + i->index = next(&i->t->t, i->index); +} - uint32_t previous = 0; - for (int i = 0; i < n; i++) { - upb_FieldDef* f = &defs[i]; +bool upb_strtable_done(const upb_strtable_iter* i) { + if (!i->t) return true; + return i->index >= upb_table_size(&i->t->t) || + upb_tabent_isempty(str_tabent(i)); +} - _upb_FieldDef_CreateNotExt(ctx, prefix, parent_features, protos[i], m, f); - f->index_ = i; - if (!ctx->layout) { - // Speculate that the def fields are sorted. We will always sort the - // MiniTable fields, so if defs are sorted then indices will match. - // - // If this is incorrect, we will overwrite later. - f->layout_index = i; - } +upb_StringView upb_strtable_iter_key(const upb_strtable_iter* i) { + upb_StringView key; + uint32_t len; + UPB_ASSERT(!upb_strtable_done(i)); + key.data = upb_tabstr(str_tabent(i)->key, &len); + key.size = len; + return key; +} - const uint32_t current = f->number_; - if (previous > current) *is_sorted = false; - previous = current; - } +upb_value upb_strtable_iter_value(const upb_strtable_iter* i) { + UPB_ASSERT(!upb_strtable_done(i)); + return _upb_value_val(str_tabent(i)->val.val); +} - return defs; +void upb_strtable_iter_setdone(upb_strtable_iter* i) { + i->t = NULL; + i->index = SIZE_MAX; } -static void resolve_subdef(upb_DefBuilder* ctx, const char* prefix, - upb_FieldDef* f) { - const UPB_DESC(FieldDescriptorProto)* field_proto = f->sub.unresolved; - upb_StringView name = UPB_DESC(FieldDescriptorProto_type_name)(field_proto); - bool has_name = UPB_DESC(FieldDescriptorProto_has_type_name)(field_proto); - switch ((int)f->type_) { - case UPB_FIELD_TYPE_UNSPECIFIED: { - // Type was not specified and must be inferred. - UPB_ASSERT(has_name); - upb_deftype_t type; - const void* def = - _upb_DefBuilder_ResolveAny(ctx, f->full_name, prefix, name, &type); - switch (type) { - case UPB_DEFTYPE_ENUM: - f->sub.enumdef = def; - f->type_ = kUpb_FieldType_Enum; - break; - case UPB_DEFTYPE_MSG: - f->sub.msgdef = def; - f->type_ = kUpb_FieldType_Message; // It appears there is no way of - // this being a group. - f->has_presence = !upb_FieldDef_IsRepeated(f); - break; - default: - _upb_DefBuilder_Errf(ctx, "Couldn't resolve type name for field %s", - f->full_name); - } - break; - } - case kUpb_FieldType_Message: - case kUpb_FieldType_Group: - UPB_ASSERT(has_name); - f->sub.msgdef = _upb_DefBuilder_Resolve(ctx, f->full_name, prefix, name, - UPB_DEFTYPE_MSG); - break; - case kUpb_FieldType_Enum: - UPB_ASSERT(has_name); - f->sub.enumdef = _upb_DefBuilder_Resolve(ctx, f->full_name, prefix, name, - UPB_DEFTYPE_ENUM); - break; - default: - // No resolution necessary. - break; +bool upb_strtable_iter_isequal(const upb_strtable_iter* i1, + const upb_strtable_iter* i2) { + if (upb_strtable_done(i1) && upb_strtable_done(i2)) return true; + return i1->t == i2->t && i1->index == i2->index; +} + +/* upb_inttable ***************************************************************/ + +/* For inttables we use a hybrid structure where small keys are kept in an + * array and large keys are put in the hash table. */ + +static uint32_t inthash(upb_tabkey key) { return upb_inthash(key); } + +static bool inteql(upb_tabkey k1, lookupkey_t k2) { return k1 == k2.num; } + +static upb_tabval* mutable_array(upb_inttable* t) { + return (upb_tabval*)t->array; +} + +static upb_tabval* inttable_val(upb_inttable* t, uintptr_t key) { + if (key < t->array_size) { + return upb_arrhas(t->array[key]) ? &(mutable_array(t)[key]) : NULL; + } else { + upb_tabent* e = + findentry_mutable(&t->t, intkey(key), upb_inthash(key), &inteql); + return e ? &e->val : NULL; } } -static int _upb_FieldDef_Compare(const void* p1, const void* p2) { - const uint32_t v1 = (*(upb_FieldDef**)p1)->number_; - const uint32_t v2 = (*(upb_FieldDef**)p2)->number_; - return (v1 < v2) ? -1 : (v1 > v2); +static const upb_tabval* inttable_val_const(const upb_inttable* t, + uintptr_t key) { + return inttable_val((upb_inttable*)t, key); } -// _upb_FieldDefs_Sorted() is mostly a pure function of its inputs, but has one -// critical side effect that we depend on: it sets layout_index appropriately -// for non-sorted lists of fields. -const upb_FieldDef** _upb_FieldDefs_Sorted(const upb_FieldDef* f, int n, - upb_Arena* a) { - // TODO: Replace this arena alloc with a persistent scratch buffer. - upb_FieldDef** out = (upb_FieldDef**)upb_Arena_Malloc(a, n * sizeof(void*)); - if (!out) return NULL; +size_t upb_inttable_count(const upb_inttable* t) { + return t->t.count + t->array_count; +} - for (int i = 0; i < n; i++) { - out[i] = (upb_FieldDef*)&f[i]; +static void check(upb_inttable* t) { + UPB_UNUSED(t); +#if defined(UPB_DEBUG_TABLE) && !defined(NDEBUG) + { + // This check is very expensive (makes inserts/deletes O(N)). + size_t count = 0; + intptr_t iter = UPB_INTTABLE_BEGIN; + uintptr_t key; + upb_value val; + while (upb_inttable_next(t, &key, &val, &iter)) { + UPB_ASSERT(upb_inttable_lookup(t, key, NULL)); + } + UPB_ASSERT(count == upb_inttable_count(t)); } - qsort(out, n, sizeof(void*), _upb_FieldDef_Compare); +#endif +} - for (int i = 0; i < n; i++) { - out[i]->layout_index = i; +bool upb_inttable_sizedinit(upb_inttable* t, size_t asize, int hsize_lg2, + upb_Arena* a) { + size_t array_bytes; + + if (!init(&t->t, hsize_lg2, a)) return false; + /* Always make the array part at least 1 long, so that we know key 0 + * won't be in the hash part, which simplifies things. */ + t->array_size = UPB_MAX(1, asize); + t->array_count = 0; + array_bytes = t->array_size * sizeof(upb_value); + t->array = upb_Arena_Malloc(a, array_bytes); + if (!t->array) { + return false; } - return (const upb_FieldDef**)out; + memset(mutable_array(t), 0xff, array_bytes); + check(t); + return true; } -bool upb_FieldDef_MiniDescriptorEncode(const upb_FieldDef* f, upb_Arena* a, - upb_StringView* out) { - UPB_ASSERT(f->is_extension); +bool upb_inttable_init(upb_inttable* t, upb_Arena* a) { + return upb_inttable_sizedinit(t, 0, 4, a); +} - upb_DescState s; - _upb_DescState_Init(&s); +bool upb_inttable_insert(upb_inttable* t, uintptr_t key, upb_value val, + upb_Arena* a) { + upb_tabval tabval; + tabval.val = val.val; + UPB_ASSERT( + upb_arrhas(tabval)); /* This will reject (uint64_t)-1. Fix this. */ - const int number = upb_FieldDef_Number(f); - const uint64_t modifiers = _upb_FieldDef_Modifiers(f); + if (key < t->array_size) { + UPB_ASSERT(!upb_arrhas(t->array[key])); + t->array_count++; + mutable_array(t)[key].val = val.val; + } else { + if (isfull(&t->t)) { + /* Need to resize the hash part, but we re-use the array part. */ + size_t i; + upb_table new_table; - if (!_upb_DescState_Grow(&s, a)) return false; - s.ptr = upb_MtDataEncoder_EncodeExtension(&s.e, s.ptr, f->type_, number, - modifiers); - *s.ptr = '\0'; + if (!init(&new_table, t->t.size_lg2 + 1, a)) { + return false; + } - out->data = s.buf; - out->size = s.ptr - s.buf; - return true; -} + for (i = begin(&t->t); i < upb_table_size(&t->t); i = next(&t->t, i)) { + const upb_tabent* e = &t->t.entries[i]; + uint32_t hash; + upb_value v; -static void resolve_extension(upb_DefBuilder* ctx, const char* prefix, - upb_FieldDef* f, - const UPB_DESC(FieldDescriptorProto) * - field_proto) { - if (!UPB_DESC(FieldDescriptorProto_has_extendee)(field_proto)) { - _upb_DefBuilder_Errf(ctx, "extension for field '%s' had no extendee", - f->full_name); - } + _upb_value_setval(&v, e->val.val); + hash = upb_inthash(e->key); + insert(&new_table, intkey(e->key), e->key, v, hash, &inthash, &inteql); + } - upb_StringView name = UPB_DESC(FieldDescriptorProto_extendee)(field_proto); - const upb_MessageDef* m = - _upb_DefBuilder_Resolve(ctx, f->full_name, prefix, name, UPB_DEFTYPE_MSG); - f->msgdef = m; + UPB_ASSERT(t->t.count == new_table.count); - if (!_upb_MessageDef_IsValidExtensionNumber(m, f->number_)) { - _upb_DefBuilder_Errf( - ctx, - "field number %u in extension %s has no extension range in message %s", - (unsigned)f->number_, f->full_name, upb_MessageDef_FullName(m)); + t->t = new_table; + } + insert(&t->t, intkey(key), key, val, upb_inthash(key), &inthash, &inteql); } + check(t); + return true; } -void _upb_FieldDef_BuildMiniTableExtension(upb_DefBuilder* ctx, - const upb_FieldDef* f) { - const upb_MiniTableExtension* ext = _upb_FieldDef_ExtensionMiniTable(f); +bool upb_inttable_lookup(const upb_inttable* t, uintptr_t key, upb_value* v) { + const upb_tabval* table_v = inttable_val_const(t, key); + if (!table_v) return false; + if (v) _upb_value_setval(v, table_v->val); + return true; +} - if (ctx->layout) { - UPB_ASSERT(upb_FieldDef_Number(f) == upb_MiniTableExtension_Number(ext)); - } else { - upb_StringView desc; - if (!upb_FieldDef_MiniDescriptorEncode(f, ctx->tmp_arena, &desc)) { - _upb_DefBuilder_OomErr(ctx); - } +bool upb_inttable_replace(upb_inttable* t, uintptr_t key, upb_value val) { + upb_tabval* table_v = inttable_val(t, key); + if (!table_v) return false; + table_v->val = val.val; + return true; +} - upb_MiniTableExtension* mut_ext = (upb_MiniTableExtension*)ext; - upb_MiniTableSub sub = {NULL}; - if (upb_FieldDef_IsSubMessage(f)) { - const upb_MiniTable* submsg = upb_MessageDef_MiniTable(f->sub.msgdef); - sub = upb_MiniTableSub_FromMessage(submsg); - } else if (_upb_FieldDef_IsClosedEnum(f)) { - const upb_MiniTableEnum* subenum = _upb_EnumDef_MiniTable(f->sub.enumdef); - sub = upb_MiniTableSub_FromEnum(subenum); +bool upb_inttable_remove(upb_inttable* t, uintptr_t key, upb_value* val) { + bool success; + if (key < t->array_size) { + if (upb_arrhas(t->array[key])) { + upb_tabval empty = UPB_TABVALUE_EMPTY_INIT; + t->array_count--; + if (val) { + _upb_value_setval(val, t->array[key].val); + } + mutable_array(t)[key] = empty; + success = true; + } else { + success = false; } - bool ok2 = upb_MiniTableExtension_Init(desc.data, desc.size, mut_ext, - upb_MessageDef_MiniTable(f->msgdef), - sub, ctx->status); - if (!ok2) _upb_DefBuilder_Errf(ctx, "Could not build extension mini table"); + } else { + success = rm(&t->t, intkey(key), val, NULL, upb_inthash(key), &inteql); } - - bool ok = _upb_DefPool_InsertExt(ctx->symtab, ext, f); - if (!ok) _upb_DefBuilder_OomErr(ctx); + check(t); + return success; } -static void resolve_default(upb_DefBuilder* ctx, upb_FieldDef* f, - const UPB_DESC(FieldDescriptorProto) * - field_proto) { - // Have to delay resolving of the default value until now because of the enum - // case, since enum defaults are specified with a label. - if (UPB_DESC(FieldDescriptorProto_has_default_value)(field_proto)) { - upb_StringView defaultval = - UPB_DESC(FieldDescriptorProto_default_value)(field_proto); +void upb_inttable_compact(upb_inttable* t, upb_Arena* a) { + /* A power-of-two histogram of the table keys. */ + size_t counts[UPB_MAXARRSIZE + 1] = {0}; - if (upb_FileDef_Syntax(f->file) == kUpb_Syntax_Proto3) { - _upb_DefBuilder_Errf(ctx, - "proto3 fields cannot have explicit defaults (%s)", - f->full_name); + /* The max key in each bucket. */ + uintptr_t max[UPB_MAXARRSIZE + 1] = {0}; + + { + intptr_t iter = UPB_INTTABLE_BEGIN; + uintptr_t key; + upb_value val; + while (upb_inttable_next(t, &key, &val, &iter)) { + int bucket = log2ceil(key); + max[bucket] = UPB_MAX(max[bucket], key); + counts[bucket]++; } + } - if (upb_FieldDef_IsSubMessage(f)) { - _upb_DefBuilder_Errf(ctx, - "message fields cannot have explicit defaults (%s)", - f->full_name); + /* Find the largest power of two that satisfies the MIN_DENSITY + * definition (while actually having some keys). */ + size_t arr_count = upb_inttable_count(t); + int size_lg2; + upb_inttable new_t; + + for (size_lg2 = ARRAY_SIZE(counts) - 1; size_lg2 > 0; size_lg2--) { + if (counts[size_lg2] == 0) { + /* We can halve again without losing any entries. */ + continue; + } else if (arr_count >= (1 << size_lg2) * MIN_DENSITY) { + break; } - parse_default(ctx, defaultval.data, defaultval.size, f); - f->has_default = true; - } else { - set_default_default(ctx, f); - f->has_default = false; + arr_count -= counts[size_lg2]; } -} -void _upb_FieldDef_Resolve(upb_DefBuilder* ctx, const char* prefix, - upb_FieldDef* f) { - // We have to stash this away since resolve_subdef() may overwrite it. - const UPB_DESC(FieldDescriptorProto)* field_proto = f->sub.unresolved; + UPB_ASSERT(arr_count <= upb_inttable_count(t)); + + { + /* Insert all elements into new, perfectly-sized table. */ + size_t arr_size = max[size_lg2] + 1; /* +1 so arr[max] will fit. */ + size_t hash_count = upb_inttable_count(t) - arr_count; + size_t hash_size = hash_count ? (hash_count / MAX_LOAD) + 1 : 0; + int hashsize_lg2 = log2ceil(hash_size); + + upb_inttable_sizedinit(&new_t, arr_size, hashsize_lg2, a); - resolve_subdef(ctx, prefix, f); - resolve_default(ctx, f, field_proto); + { + intptr_t iter = UPB_INTTABLE_BEGIN; + uintptr_t key; + upb_value val; + while (upb_inttable_next(t, &key, &val, &iter)) { + upb_inttable_insert(&new_t, key, val, a); + } + } - if (f->is_extension) { - resolve_extension(ctx, prefix, f, field_proto); + UPB_ASSERT(new_t.array_size == arr_size); + UPB_ASSERT(new_t.t.size_lg2 == hashsize_lg2); } + *t = new_t; } +// Iteration. -#include -#include -#include +bool upb_inttable_next(const upb_inttable* t, uintptr_t* key, upb_value* val, + intptr_t* iter) { + intptr_t i = *iter; + if ((size_t)(i + 1) <= t->array_size) { + while ((size_t)++i < t->array_size) { + upb_tabval ent = t->array[i]; + if (upb_arrhas(ent)) { + *key = i; + *val = _upb_value_val(ent.val); + *iter = i; + return true; + } + } + i--; // Back up to exactly one position before the start of the table. + } + size_t tab_idx = next(&t->t, i - t->array_size); + if (tab_idx < upb_table_size(&t->t)) { + upb_tabent* ent = &t->t.entries[tab_idx]; + *key = ent->key; + *val = _upb_value_val(ent->val.val); + *iter = tab_idx + t->array_size; + return true; + } -// Must be last. + return false; +} -struct upb_FileDef { - const UPB_DESC(FileOptions*) opts; - const UPB_DESC(FeatureSet*) resolved_features; - const char* name; - const char* package; - UPB_DESC(Edition) edition; +void upb_inttable_removeiter(upb_inttable* t, intptr_t* iter) { + intptr_t i = *iter; + if ((size_t)i < t->array_size) { + t->array_count--; + mutable_array(t)[i].val = -1; + } else { + upb_tabent* ent = &t->t.entries[i - t->array_size]; + upb_tabent* prev = NULL; - const upb_FileDef** deps; - const int32_t* public_deps; - const int32_t* weak_deps; - const upb_MessageDef* top_lvl_msgs; - const upb_EnumDef* top_lvl_enums; - const upb_FieldDef* top_lvl_exts; - const upb_ServiceDef* services; - const upb_MiniTableExtension** ext_layouts; - const upb_DefPool* symtab; + // Linear search, not great. + upb_tabent* end = &t->t.entries[upb_table_size(&t->t)]; + for (upb_tabent* e = t->t.entries; e != end; e++) { + if (e->next == ent) { + prev = e; + break; + } + } - int dep_count; - int public_dep_count; - int weak_dep_count; - int top_lvl_msg_count; - int top_lvl_enum_count; - int top_lvl_ext_count; - int service_count; - int ext_count; // All exts in the file. - upb_Syntax syntax; -}; + if (prev) { + prev->next = ent->next; + } -UPB_API const char* upb_FileDef_EditionName(int edition) { - // TODO Synchronize this with descriptor.proto better. - switch (edition) { - case UPB_DESC(EDITION_PROTO2): - return "PROTO2"; - case UPB_DESC(EDITION_PROTO3): - return "PROTO3"; - case UPB_DESC(EDITION_2023): - return "2023"; - default: - return "UNKNOWN"; + t->t.count--; + ent->key = 0; + ent->next = NULL; } } -const UPB_DESC(FileOptions) * upb_FileDef_Options(const upb_FileDef* f) { - return f->opts; -} +bool upb_strtable_next2(const upb_strtable* t, upb_StringView* key, + upb_value* val, intptr_t* iter) { + size_t tab_idx = next(&t->t, *iter); + if (tab_idx < upb_table_size(&t->t)) { + upb_tabent* ent = &t->t.entries[tab_idx]; + uint32_t len; + key->data = upb_tabstr(ent->key, &len); + key->size = len; + *val = _upb_value_val(ent->val.val); + *iter = tab_idx; + return true; + } -const UPB_DESC(FeatureSet) * - upb_FileDef_ResolvedFeatures(const upb_FileDef* f) { - return f->resolved_features; + return false; } -bool upb_FileDef_HasOptions(const upb_FileDef* f) { - return f->opts != (void*)kUpbDefOptDefault; -} +void upb_strtable_removeiter(upb_strtable* t, intptr_t* iter) { + intptr_t i = *iter; + upb_tabent* ent = &t->t.entries[i]; + upb_tabent* prev = NULL; -const char* upb_FileDef_Name(const upb_FileDef* f) { return f->name; } + // Linear search, not great. + upb_tabent* end = &t->t.entries[upb_table_size(&t->t)]; + for (upb_tabent* e = t->t.entries; e != end; e++) { + if (e->next == ent) { + prev = e; + break; + } + } -const char* upb_FileDef_Package(const upb_FileDef* f) { - return f->package ? f->package : ""; -} + if (prev) { + prev->next = ent->next; + } -UPB_DESC(Edition) upb_FileDef_Edition(const upb_FileDef* f) { - return f->edition; + t->t.count--; + ent->key = 0; + ent->next = NULL; } -const char* _upb_FileDef_RawPackage(const upb_FileDef* f) { return f->package; } +void upb_strtable_setentryvalue(upb_strtable* t, intptr_t iter, upb_value v) { + upb_tabent* ent = &t->t.entries[iter]; + ent->val.val = v.val; +} -upb_Syntax upb_FileDef_Syntax(const upb_FileDef* f) { return f->syntax; } -int upb_FileDef_TopLevelMessageCount(const upb_FileDef* f) { - return f->top_lvl_msg_count; -} +// Must be last. -int upb_FileDef_DependencyCount(const upb_FileDef* f) { return f->dep_count; } +const char* upb_BufToUint64(const char* ptr, const char* end, uint64_t* val) { + uint64_t u64 = 0; + while (ptr < end) { + unsigned ch = *ptr - '0'; + if (ch >= 10) break; + if (u64 > UINT64_MAX / 10 || u64 * 10 > UINT64_MAX - ch) { + return NULL; // integer overflow + } + u64 *= 10; + u64 += ch; + ptr++; + } -int upb_FileDef_PublicDependencyCount(const upb_FileDef* f) { - return f->public_dep_count; + *val = u64; + return ptr; } -int upb_FileDef_WeakDependencyCount(const upb_FileDef* f) { - return f->weak_dep_count; -} +const char* upb_BufToInt64(const char* ptr, const char* end, int64_t* val, + bool* is_neg) { + bool neg = false; + uint64_t u64; -const int32_t* _upb_FileDef_PublicDependencyIndexes(const upb_FileDef* f) { - return f->public_deps; -} + if (ptr != end && *ptr == '-') { + ptr++; + neg = true; + } -const int32_t* _upb_FileDef_WeakDependencyIndexes(const upb_FileDef* f) { - return f->weak_deps; -} + ptr = upb_BufToUint64(ptr, end, &u64); + if (!ptr || u64 > (uint64_t)INT64_MAX + neg) { + return NULL; // integer overflow + } -int upb_FileDef_TopLevelEnumCount(const upb_FileDef* f) { - return f->top_lvl_enum_count; + *val = neg ? -u64 : u64; + if (is_neg) *is_neg = neg; + return ptr; } -int upb_FileDef_TopLevelExtensionCount(const upb_FileDef* f) { - return f->top_lvl_ext_count; -} -int upb_FileDef_ServiceCount(const upb_FileDef* f) { return f->service_count; } +#include +#include -const upb_FileDef* upb_FileDef_Dependency(const upb_FileDef* f, int i) { - UPB_ASSERT(0 <= i && i < f->dep_count); - return f->deps[i]; -} +// Must be last. -const upb_FileDef* upb_FileDef_PublicDependency(const upb_FileDef* f, int i) { - UPB_ASSERT(0 <= i && i < f->public_dep_count); - return f->deps[f->public_deps[i]]; +/* Miscellaneous utilities ****************************************************/ + +static void upb_FixLocale(char* p) { + /* printf() is dependent on locales; sadly there is no easy and portable way + * to avoid this. This little post-processing step will translate 1,2 -> 1.2 + * since JSON needs the latter. Arguably a hack, but it is simple and the + * alternatives are far more complicated, platform-dependent, and/or larger + * in code size. */ + for (; *p; p++) { + if (*p == ',') *p = '.'; + } } -const upb_FileDef* upb_FileDef_WeakDependency(const upb_FileDef* f, int i) { - UPB_ASSERT(0 <= i && i < f->public_dep_count); - return f->deps[f->weak_deps[i]]; +void _upb_EncodeRoundTripDouble(double val, char* buf, size_t size) { + assert(size >= kUpb_RoundTripBufferSize); + snprintf(buf, size, "%.*g", DBL_DIG, val); + if (strtod(buf, NULL) != val) { + snprintf(buf, size, "%.*g", DBL_DIG + 2, val); + assert(strtod(buf, NULL) == val); + } + upb_FixLocale(buf); } -const upb_MessageDef* upb_FileDef_TopLevelMessage(const upb_FileDef* f, int i) { - UPB_ASSERT(0 <= i && i < f->top_lvl_msg_count); - return _upb_MessageDef_At(f->top_lvl_msgs, i); +void _upb_EncodeRoundTripFloat(float val, char* buf, size_t size) { + assert(size >= kUpb_RoundTripBufferSize); + snprintf(buf, size, "%.*g", FLT_DIG, val); + if (strtof(buf, NULL) != val) { + snprintf(buf, size, "%.*g", FLT_DIG + 3, val); + assert(strtof(buf, NULL) == val); + } + upb_FixLocale(buf); } -const upb_EnumDef* upb_FileDef_TopLevelEnum(const upb_FileDef* f, int i) { - UPB_ASSERT(0 <= i && i < f->top_lvl_enum_count); - return _upb_EnumDef_At(f->top_lvl_enums, i); -} -const upb_FieldDef* upb_FileDef_TopLevelExtension(const upb_FileDef* f, int i) { - UPB_ASSERT(0 <= i && i < f->top_lvl_ext_count); - return _upb_FieldDef_At(f->top_lvl_exts, i); -} +#include +#include -const upb_ServiceDef* upb_FileDef_Service(const upb_FileDef* f, int i) { - UPB_ASSERT(0 <= i && i < f->service_count); - return _upb_ServiceDef_At(f->services, i); -} +// Must be last. -const upb_DefPool* upb_FileDef_Pool(const upb_FileDef* f) { return f->symtab; } +// Determine the locale-specific radix character by calling sprintf() to print +// the number 1.5, then stripping off the digits. As far as I can tell, this +// is the only portable, thread-safe way to get the C library to divulge the +// locale's radix character. No, localeconv() is NOT thread-safe. -const upb_MiniTableExtension* _upb_FileDef_ExtensionMiniTable( - const upb_FileDef* f, int i) { - return f->ext_layouts[i]; +static int GetLocaleRadix(char *data, size_t capacity) { + char temp[16]; + const int size = snprintf(temp, sizeof(temp), "%.1f", 1.5); + UPB_ASSERT(temp[0] == '1'); + UPB_ASSERT(temp[size - 1] == '5'); + UPB_ASSERT(size < capacity); + temp[size - 1] = '\0'; + strcpy(data, temp + 1); + return size - 2; } -static char* strviewdup(upb_DefBuilder* ctx, upb_StringView view) { - char* ret = upb_strdup2(view.data, view.size, _upb_DefBuilder_Arena(ctx)); - if (!ret) _upb_DefBuilder_OomErr(ctx); - return ret; -} +// Populates a string identical to *input except that the character pointed to +// by pos (which should be '.') is replaced with the locale-specific radix. -static bool streql_view(upb_StringView view, const char* b) { - return view.size == strlen(b) && memcmp(view.data, b, view.size) == 0; +static void LocalizeRadix(const char *input, const char *pos, char *output) { + const int len1 = pos - input; + + char radix[8]; + const int len2 = GetLocaleRadix(radix, sizeof(radix)); + + memcpy(output, input, len1); + memcpy(output + len1, radix, len2); + strcpy(output + len1 + len2, input + len1 + 1); } -static int count_exts_in_msg(const UPB_DESC(DescriptorProto) * msg_proto) { - size_t n; - UPB_DESC(DescriptorProto_extension)(msg_proto, &n); - int ext_count = n; +double _upb_NoLocaleStrtod(const char *str, char **endptr) { + // We cannot simply set the locale to "C" temporarily with setlocale() + // as this is not thread-safe. Instead, we try to parse in the current + // locale first. If parsing stops at a '.' character, then this is a + // pretty good hint that we're actually in some other locale in which + // '.' is not the radix character. - const UPB_DESC(DescriptorProto)* const* nested_msgs = - UPB_DESC(DescriptorProto_nested_type)(msg_proto, &n); - for (size_t i = 0; i < n; i++) { - ext_count += count_exts_in_msg(nested_msgs[i]); + char *temp_endptr; + double result = strtod(str, &temp_endptr); + if (endptr != NULL) *endptr = temp_endptr; + if (*temp_endptr != '.') return result; + + // Parsing halted on a '.'. Perhaps we're in a different locale? Let's + // try to replace the '.' with a locale-specific radix character and + // try again. + + char localized[80]; + LocalizeRadix(str, temp_endptr, localized); + char *localized_endptr; + result = strtod(localized, &localized_endptr); + if ((localized_endptr - &localized[0]) > (temp_endptr - str)) { + // This attempt got further, so replacing the decimal must have helped. + // Update endptr to point at the right location. + if (endptr != NULL) { + // size_diff is non-zero if the localized radix has multiple bytes. + int size_diff = strlen(localized) - strlen(str); + *endptr = (char *)str + (localized_endptr - &localized[0] - size_diff); + } } - return ext_count; + return result; } -const UPB_DESC(FeatureSet*) - _upb_FileDef_FindEdition(upb_DefBuilder* ctx, int edition) { - const UPB_DESC(FeatureSetDefaults)* defaults = - upb_DefPool_FeatureSetDefaults(ctx->symtab); - int min = UPB_DESC(FeatureSetDefaults_minimum_edition)(defaults); - int max = UPB_DESC(FeatureSetDefaults_maximum_edition)(defaults); - if (edition < min) { - _upb_DefBuilder_Errf(ctx, - "Edition %s is earlier than the minimum edition %s " - "given in the defaults", - upb_FileDef_EditionName(edition), - upb_FileDef_EditionName(min)); - return NULL; +// Must be last. + +int upb_Unicode_ToUTF8(uint32_t cp, char* out) { + if (cp <= 0x7f) { + out[0] = cp; + return 1; } - if (edition > max) { - _upb_DefBuilder_Errf(ctx, - "Edition %s is later than the maximum edition %s " - "given in the defaults", - upb_FileDef_EditionName(edition), - upb_FileDef_EditionName(max)); - return NULL; + if (cp <= 0x07ff) { + out[0] = (cp >> 6) | 0xc0; + out[1] = (cp & 0x3f) | 0x80; + return 2; } - - size_t n; - const UPB_DESC(FeatureSetDefaults_FeatureSetEditionDefault)* const* d = - UPB_DESC(FeatureSetDefaults_defaults)(defaults, &n); - const UPB_DESC(FeatureSet)* ret = NULL; - for (size_t i = 0; i < n; i++) { - if (UPB_DESC(FeatureSetDefaults_FeatureSetEditionDefault_edition)(d[i]) > - edition) { - break; - } - ret = UPB_DESC(FeatureSetDefaults_FeatureSetEditionDefault_features)(d[i]); + if (cp <= 0xffff) { + out[0] = (cp >> 12) | 0xe0; + out[1] = ((cp >> 6) & 0x3f) | 0x80; + out[2] = (cp & 0x3f) | 0x80; + return 3; } - if (ret == NULL) { - _upb_DefBuilder_Errf(ctx, "No valid default found for edition %s", - upb_FileDef_EditionName(edition)); - return NULL; + if (cp <= 0x10ffff) { + out[0] = (cp >> 18) | 0xf0; + out[1] = ((cp >> 12) & 0x3f) | 0x80; + out[2] = ((cp >> 6) & 0x3f) | 0x80; + out[3] = (cp & 0x3f) | 0x80; + return 4; } - return ret; + return 0; } -// Allocate and initialize one file def, and add it to the context object. -void _upb_FileDef_Create(upb_DefBuilder* ctx, - const UPB_DESC(FileDescriptorProto) * file_proto) { - upb_FileDef* file = _upb_DefBuilder_Alloc(ctx, sizeof(upb_FileDef)); - ctx->file = file; - const UPB_DESC(DescriptorProto)* const* msgs; - const UPB_DESC(EnumDescriptorProto)* const* enums; - const UPB_DESC(FieldDescriptorProto)* const* exts; - const UPB_DESC(ServiceDescriptorProto)* const* services; - const upb_StringView* strs; - const int32_t* public_deps; - const int32_t* weak_deps; - size_t n; +#include - file->symtab = ctx->symtab; - // Count all extensions in the file, to build a flat array of layouts. - UPB_DESC(FileDescriptorProto_extension)(file_proto, &n); - int ext_count = n; - msgs = UPB_DESC(FileDescriptorProto_message_type)(file_proto, &n); - for (size_t i = 0; i < n; i++) { - ext_count += count_exts_in_msg(msgs[i]); - } - file->ext_count = ext_count; +// Must be last. - if (ctx->layout) { - // We are using the ext layouts that were passed in. - file->ext_layouts = ctx->layout->UPB_PRIVATE(exts); - const int mt_ext_count = upb_MiniTableFile_ExtensionCount(ctx->layout); - if (mt_ext_count != file->ext_count) { - _upb_DefBuilder_Errf(ctx, - "Extension count did not match layout (%d vs %d)", - mt_ext_count, file->ext_count); - } - } else { - // We are building ext layouts from scratch. - file->ext_layouts = _upb_DefBuilder_Alloc( - ctx, sizeof(*file->ext_layouts) * file->ext_count); - upb_MiniTableExtension* ext = - _upb_DefBuilder_Alloc(ctx, sizeof(*ext) * file->ext_count); - for (int i = 0; i < file->ext_count; i++) { - file->ext_layouts[i] = &ext[i]; - } - } +const struct upb_Extension* _upb_Message_Getext( + const struct upb_Message* msg, const upb_MiniTableExtension* e) { + size_t n; + const struct upb_Extension* ext = UPB_PRIVATE(_upb_Message_Getexts)(msg, &n); - upb_StringView name = UPB_DESC(FileDescriptorProto_name)(file_proto); - file->name = strviewdup(ctx, name); - if (strlen(file->name) != name.size) { - _upb_DefBuilder_Errf(ctx, "File name contained embedded NULL"); + // For now we use linear search exclusively to find extensions. + // If this becomes an issue due to messages with lots of extensions, + // we can introduce a table of some sort. + for (size_t i = 0; i < n; i++) { + if (ext[i].ext == e) { + return &ext[i]; + } } - upb_StringView package = UPB_DESC(FileDescriptorProto_package)(file_proto); + return NULL; +} - if (package.size) { - _upb_DefBuilder_CheckIdentFull(ctx, package); - file->package = strviewdup(ctx, package); +const struct upb_Extension* UPB_PRIVATE(_upb_Message_Getexts)( + const struct upb_Message* msg, size_t* count) { + upb_Message_InternalData* in = upb_Message_GetInternalData(msg); + if (in) { + *count = (in->size - in->ext_begin) / sizeof(struct upb_Extension); + return UPB_PTR_AT(in, in->ext_begin, void); } else { - file->package = NULL; + *count = 0; + return NULL; } +} - // TODO: How should we validate this? - file->edition = UPB_DESC(FileDescriptorProto_edition)(file_proto); - - if (UPB_DESC(FileDescriptorProto_has_syntax)(file_proto)) { - upb_StringView syntax = UPB_DESC(FileDescriptorProto_syntax)(file_proto); - - if (streql_view(syntax, "proto2")) { - file->syntax = kUpb_Syntax_Proto2; - file->edition = UPB_DESC(EDITION_PROTO2); - } else if (streql_view(syntax, "proto3")) { - file->syntax = kUpb_Syntax_Proto3; - file->edition = UPB_DESC(EDITION_PROTO3); - } else if (streql_view(syntax, "editions")) { - file->syntax = kUpb_Syntax_Editions; - file->edition = UPB_DESC(FileDescriptorProto_edition)(file_proto); - } else { - _upb_DefBuilder_Errf(ctx, "Invalid syntax '" UPB_STRINGVIEW_FORMAT "'", - UPB_STRINGVIEW_ARGS(syntax)); - } - } else { - file->syntax = kUpb_Syntax_Proto2; - file->edition = UPB_DESC(EDITION_PROTO2); - } +struct upb_Extension* _upb_Message_GetOrCreateExtension( + struct upb_Message* msg, const upb_MiniTableExtension* e, upb_Arena* a) { + struct upb_Extension* ext = + (struct upb_Extension*)_upb_Message_Getext(msg, e); + if (ext) return ext; + if (!UPB_PRIVATE(_upb_Message_Realloc)(msg, sizeof(struct upb_Extension), a)) + return NULL; + upb_Message_InternalData* in = upb_Message_GetInternalData(msg); + in->ext_begin -= sizeof(struct upb_Extension); + ext = UPB_PTR_AT(in, in->ext_begin, void); + memset(ext, 0, sizeof(struct upb_Extension)); + ext->ext = e; + return ext; +} - // Read options. - UPB_DEF_SET_OPTIONS(file->opts, FileDescriptorProto, FileOptions, file_proto); - // Resolve features. - const UPB_DESC(FeatureSet*) edition_defaults = - _upb_FileDef_FindEdition(ctx, file->edition); - const UPB_DESC(FeatureSet*) unresolved = - UPB_DESC(FileOptions_features)(file->opts); - file->resolved_features = - _upb_DefBuilder_ResolveFeatures(ctx, edition_defaults, unresolved); +#include +#include - // Verify dependencies. - strs = UPB_DESC(FileDescriptorProto_dependency)(file_proto, &n); - file->dep_count = n; - file->deps = _upb_DefBuilder_Alloc(ctx, sizeof(*file->deps) * n); - for (size_t i = 0; i < n; i++) { - upb_StringView str = strs[i]; - file->deps[i] = - upb_DefPool_FindFileByNameWithSize(ctx->symtab, str.data, str.size); - if (!file->deps[i]) { - _upb_DefBuilder_Errf(ctx, - "Depends on file '" UPB_STRINGVIEW_FORMAT - "', but it has not been loaded", - UPB_STRINGVIEW_ARGS(str)); - } - } +// Must be last. - public_deps = UPB_DESC(FileDescriptorProto_public_dependency)(file_proto, &n); - file->public_dep_count = n; - file->public_deps = - _upb_DefBuilder_Alloc(ctx, sizeof(*file->public_deps) * n); - int32_t* mutable_public_deps = (int32_t*)file->public_deps; - for (size_t i = 0; i < n; i++) { - if (public_deps[i] >= file->dep_count) { - _upb_DefBuilder_Errf(ctx, "public_dep %d is out of range", - (int)public_deps[i]); - } - mutable_public_deps[i] = public_deps[i]; - } +const float kUpb_FltInfinity = INFINITY; +const double kUpb_Infinity = INFINITY; +const double kUpb_NaN = NAN; - weak_deps = UPB_DESC(FileDescriptorProto_weak_dependency)(file_proto, &n); - file->weak_dep_count = n; - file->weak_deps = _upb_DefBuilder_Alloc(ctx, sizeof(*file->weak_deps) * n); - int32_t* mutable_weak_deps = (int32_t*)file->weak_deps; - for (size_t i = 0; i < n; i++) { - if (weak_deps[i] >= file->dep_count) { - _upb_DefBuilder_Errf(ctx, "weak_dep %d is out of range", - (int)weak_deps[i]); +bool UPB_PRIVATE(_upb_Message_Realloc)(struct upb_Message* msg, size_t need, + upb_Arena* a) { + const size_t overhead = sizeof(upb_Message_InternalData); + + upb_Message_Internal* owner = upb_Message_Getinternal(msg); + upb_Message_InternalData* in = owner->internal; + if (!in) { + // No internal data, allocate from scratch. + size_t size = UPB_MAX(128, upb_Log2CeilingSize(need + overhead)); + in = upb_Arena_Malloc(a, size); + if (!in) return false; + + in->size = size; + in->unknown_end = overhead; + in->ext_begin = size; + owner->internal = in; + } else if (in->ext_begin - in->unknown_end < need) { + // Internal data is too small, reallocate. + size_t new_size = upb_Log2CeilingSize(in->size + need); + size_t ext_bytes = in->size - in->ext_begin; + size_t new_ext_begin = new_size - ext_bytes; + in = upb_Arena_Realloc(a, in, in->size, new_size); + if (!in) return false; + + if (ext_bytes) { + // Need to move extension data to the end. + char* ptr = (char*)in; + memmove(ptr + new_ext_begin, ptr + in->ext_begin, ext_bytes); } - mutable_weak_deps[i] = weak_deps[i]; + in->ext_begin = new_ext_begin; + in->size = new_size; + owner->internal = in; } - // Create enums. - enums = UPB_DESC(FileDescriptorProto_enum_type)(file_proto, &n); - file->top_lvl_enum_count = n; - file->top_lvl_enums = - _upb_EnumDefs_New(ctx, n, enums, file->resolved_features, NULL); + UPB_ASSERT(in->ext_begin - in->unknown_end >= need); + return true; +} - // Create extensions. - exts = UPB_DESC(FileDescriptorProto_extension)(file_proto, &n); - file->top_lvl_ext_count = n; - file->top_lvl_exts = _upb_Extensions_New( - ctx, n, exts, file->resolved_features, file->package, NULL); - // Create messages. - msgs = UPB_DESC(FileDescriptorProto_message_type)(file_proto, &n); - file->top_lvl_msg_count = n; - file->top_lvl_msgs = - _upb_MessageDefs_New(ctx, n, msgs, file->resolved_features, NULL); +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', '{', '|', '}', '~', +}; - // Create services. - services = UPB_DESC(FileDescriptorProto_service)(file_proto, &n); - file->service_count = n; - file->services = - _upb_ServiceDefs_New(ctx, n, services, file->resolved_features); +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, +}; - // Now that all names are in the table, build layouts and resolve refs. - for (int i = 0; i < file->top_lvl_msg_count; i++) { - upb_MessageDef* m = (upb_MessageDef*)upb_FileDef_TopLevelMessage(file, i); - _upb_MessageDef_Resolve(ctx, m); - } +#include +#include +#include - for (int i = 0; i < file->top_lvl_ext_count; i++) { - upb_FieldDef* f = (upb_FieldDef*)upb_FileDef_TopLevelExtension(file, i); - _upb_FieldDef_Resolve(ctx, file->package, f); - } - for (int i = 0; i < file->top_lvl_msg_count; i++) { - upb_MessageDef* m = (upb_MessageDef*)upb_FileDef_TopLevelMessage(file, i); - _upb_MessageDef_CreateMiniTable(ctx, (upb_MessageDef*)m); - } +// Must be last. - for (int i = 0; i < file->top_lvl_ext_count; i++) { - upb_FieldDef* f = (upb_FieldDef*)upb_FileDef_TopLevelExtension(file, i); - _upb_FieldDef_BuildMiniTableExtension(ctx, f); - } +typedef struct { + uint64_t present_values_mask; + uint32_t last_written_value; +} upb_MtDataEncoderInternal_EnumState; - for (int i = 0; i < file->top_lvl_msg_count; i++) { - upb_MessageDef* m = (upb_MessageDef*)upb_FileDef_TopLevelMessage(file, i); - _upb_MessageDef_LinkMiniTable(ctx, m); - } +typedef struct { + uint64_t msg_modifiers; + uint32_t last_field_num; + enum { + kUpb_OneofState_NotStarted, + kUpb_OneofState_StartedOneof, + kUpb_OneofState_EmittedOneofField, + } oneof_state; +} upb_MtDataEncoderInternal_MsgState; - if (file->ext_count) { - bool ok = upb_ExtensionRegistry_AddArray( - _upb_DefPool_ExtReg(ctx->symtab), file->ext_layouts, file->ext_count); - if (!ok) _upb_DefBuilder_OomErr(ctx); - } +typedef struct { + char* buf_start; // Only for checking kUpb_MtDataEncoder_MinSize. + union { + upb_MtDataEncoderInternal_EnumState enum_state; + upb_MtDataEncoderInternal_MsgState msg_state; + } state; +} upb_MtDataEncoderInternal; + +static upb_MtDataEncoderInternal* upb_MtDataEncoder_GetInternal( + upb_MtDataEncoder* e, char* buf_start) { + UPB_ASSERT(sizeof(upb_MtDataEncoderInternal) <= sizeof(e->internal)); + upb_MtDataEncoderInternal* ret = (upb_MtDataEncoderInternal*)e->internal; + ret->buf_start = buf_start; + return ret; } +static char* upb_MtDataEncoder_PutRaw(upb_MtDataEncoder* e, char* ptr, + char ch) { + upb_MtDataEncoderInternal* in = (upb_MtDataEncoderInternal*)e->internal; + UPB_ASSERT(ptr - in->buf_start < kUpb_MtDataEncoder_MinSize); + if (ptr == e->end) return NULL; + *ptr++ = ch; + return ptr; +} -#include +static char* upb_MtDataEncoder_Put(upb_MtDataEncoder* e, char* ptr, char ch) { + return upb_MtDataEncoder_PutRaw(e, ptr, _upb_ToBase92(ch)); +} +static char* upb_MtDataEncoder_PutBase92Varint(upb_MtDataEncoder* e, char* ptr, + uint32_t val, int min, int max) { + int shift = upb_Log2Ceiling(_upb_FromBase92(max) - _upb_FromBase92(min) + 1); + UPB_ASSERT(shift <= 6); + uint32_t mask = (1 << shift) - 1; + do { + uint32_t bits = val & mask; + ptr = upb_MtDataEncoder_Put(e, ptr, bits + _upb_FromBase92(min)); + if (!ptr) return NULL; + val >>= shift; + } while (val); + return ptr; +} -// Must be last. +char* upb_MtDataEncoder_PutModifier(upb_MtDataEncoder* e, char* ptr, + uint64_t mod) { + if (mod) { + ptr = upb_MtDataEncoder_PutBase92Varint(e, ptr, mod, + kUpb_EncodedValue_MinModifier, + kUpb_EncodedValue_MaxModifier); + } + return ptr; +} -/* The upb core does not generally have a concept of default instances. However - * for descriptor options we make an exception since the max size is known and - * modest (<200 bytes). All types can share a default instance since it is - * initialized to zeroes. - * - * We have to allocate an extra pointer for upb's internal metadata. */ -static UPB_ALIGN_AS(8) const - char opt_default_buf[_UPB_MAXOPT_SIZE + sizeof(void*)] = {0}; -const char* kUpbDefOptDefault = &opt_default_buf[sizeof(void*)]; +char* upb_MtDataEncoder_EncodeExtension(upb_MtDataEncoder* e, char* ptr, + upb_FieldType type, uint32_t field_num, + uint64_t field_mod) { + upb_MtDataEncoderInternal* in = upb_MtDataEncoder_GetInternal(e, ptr); + in->state.msg_state.msg_modifiers = 0; + in->state.msg_state.last_field_num = 0; + in->state.msg_state.oneof_state = kUpb_OneofState_NotStarted; -const char* _upb_DefBuilder_FullToShort(const char* fullname) { - const char* p; + ptr = upb_MtDataEncoder_PutRaw(e, ptr, kUpb_EncodedVersion_ExtensionV1); + if (!ptr) return NULL; - if (fullname == NULL) { - return NULL; - } else if ((p = strrchr(fullname, '.')) == NULL) { - /* No '.' in the name, return the full string. */ - return fullname; - } else { - /* Return one past the last '.'. */ - return p + 1; - } + return upb_MtDataEncoder_PutField(e, ptr, type, field_num, field_mod); } -void _upb_DefBuilder_FailJmp(upb_DefBuilder* ctx) { UPB_LONGJMP(ctx->err, 1); } +char* upb_MtDataEncoder_EncodeMap(upb_MtDataEncoder* e, char* ptr, + upb_FieldType key_type, + upb_FieldType value_type, uint64_t key_mod, + uint64_t value_mod) { + upb_MtDataEncoderInternal* in = upb_MtDataEncoder_GetInternal(e, ptr); + in->state.msg_state.msg_modifiers = 0; + in->state.msg_state.last_field_num = 0; + in->state.msg_state.oneof_state = kUpb_OneofState_NotStarted; + + ptr = upb_MtDataEncoder_PutRaw(e, ptr, kUpb_EncodedVersion_MapV1); + if (!ptr) return NULL; + + ptr = upb_MtDataEncoder_PutField(e, ptr, key_type, 1, key_mod); + if (!ptr) return NULL; -void _upb_DefBuilder_Errf(upb_DefBuilder* ctx, const char* fmt, ...) { - va_list argp; - va_start(argp, fmt); - upb_Status_VSetErrorFormat(ctx->status, fmt, argp); - va_end(argp); - _upb_DefBuilder_FailJmp(ctx); + return upb_MtDataEncoder_PutField(e, ptr, value_type, 2, value_mod); } -void _upb_DefBuilder_OomErr(upb_DefBuilder* ctx) { - upb_Status_SetErrorMessage(ctx->status, "out of memory"); - _upb_DefBuilder_FailJmp(ctx); +char* upb_MtDataEncoder_EncodeMessageSet(upb_MtDataEncoder* e, char* ptr) { + (void)upb_MtDataEncoder_GetInternal(e, ptr); + return upb_MtDataEncoder_PutRaw(e, ptr, kUpb_EncodedVersion_MessageSetV1); } -// Verify a relative identifier string. The loop is branchless for speed. -static void _upb_DefBuilder_CheckIdentNotFull(upb_DefBuilder* ctx, - upb_StringView name) { - bool good = name.size > 0; - - for (size_t i = 0; i < name.size; i++) { - const char c = name.data[i]; - const char d = c | 0x20; // force lowercase - const bool is_alpha = (('a' <= d) & (d <= 'z')) | (c == '_'); - const bool is_numer = ('0' <= c) & (c <= '9') & (i != 0); +char* upb_MtDataEncoder_StartMessage(upb_MtDataEncoder* e, char* ptr, + uint64_t msg_mod) { + upb_MtDataEncoderInternal* in = upb_MtDataEncoder_GetInternal(e, ptr); + in->state.msg_state.msg_modifiers = msg_mod; + in->state.msg_state.last_field_num = 0; + in->state.msg_state.oneof_state = kUpb_OneofState_NotStarted; - good &= is_alpha | is_numer; - } + ptr = upb_MtDataEncoder_PutRaw(e, ptr, kUpb_EncodedVersion_MessageV1); + if (!ptr) return NULL; - if (!good) _upb_DefBuilder_CheckIdentSlow(ctx, name, false); + return upb_MtDataEncoder_PutModifier(e, ptr, msg_mod); } -const char* _upb_DefBuilder_MakeFullName(upb_DefBuilder* ctx, - const char* prefix, - upb_StringView name) { - _upb_DefBuilder_CheckIdentNotFull(ctx, name); - if (prefix) { - // ret = prefix + '.' + name; - size_t n = strlen(prefix); - char* ret = _upb_DefBuilder_Alloc(ctx, n + name.size + 2); - strcpy(ret, prefix); - ret[n] = '.'; - memcpy(&ret[n + 1], name.data, name.size); - ret[n + 1 + name.size] = '\0'; - return ret; - } else { - char* ret = upb_strdup2(name.data, name.size, ctx->arena); - if (!ret) _upb_DefBuilder_OomErr(ctx); - return ret; +static char* _upb_MtDataEncoder_MaybePutFieldSkip(upb_MtDataEncoder* e, + char* ptr, + uint32_t field_num) { + upb_MtDataEncoderInternal* in = (upb_MtDataEncoderInternal*)e->internal; + if (field_num <= in->state.msg_state.last_field_num) return NULL; + if (in->state.msg_state.last_field_num + 1 != field_num) { + // Put skip. + UPB_ASSERT(field_num > in->state.msg_state.last_field_num); + uint32_t skip = field_num - in->state.msg_state.last_field_num; + ptr = upb_MtDataEncoder_PutBase92Varint( + e, ptr, skip, kUpb_EncodedValue_MinSkip, kUpb_EncodedValue_MaxSkip); + if (!ptr) return NULL; } + in->state.msg_state.last_field_num = field_num; + return ptr; } -static bool remove_component(char* base, size_t* len) { - if (*len == 0) return false; - - for (size_t i = *len - 1; i > 0; i--) { - if (base[i] == '.') { - *len = i; - return true; - } - } +static char* _upb_MtDataEncoder_PutFieldType(upb_MtDataEncoder* e, char* ptr, + upb_FieldType type, + uint64_t field_mod) { + static const char kUpb_TypeToEncoded[] = { + [kUpb_FieldType_Double] = kUpb_EncodedType_Double, + [kUpb_FieldType_Float] = kUpb_EncodedType_Float, + [kUpb_FieldType_Int64] = kUpb_EncodedType_Int64, + [kUpb_FieldType_UInt64] = kUpb_EncodedType_UInt64, + [kUpb_FieldType_Int32] = kUpb_EncodedType_Int32, + [kUpb_FieldType_Fixed64] = kUpb_EncodedType_Fixed64, + [kUpb_FieldType_Fixed32] = kUpb_EncodedType_Fixed32, + [kUpb_FieldType_Bool] = kUpb_EncodedType_Bool, + [kUpb_FieldType_String] = kUpb_EncodedType_String, + [kUpb_FieldType_Group] = kUpb_EncodedType_Group, + [kUpb_FieldType_Message] = kUpb_EncodedType_Message, + [kUpb_FieldType_Bytes] = kUpb_EncodedType_Bytes, + [kUpb_FieldType_UInt32] = kUpb_EncodedType_UInt32, + [kUpb_FieldType_Enum] = kUpb_EncodedType_OpenEnum, + [kUpb_FieldType_SFixed32] = kUpb_EncodedType_SFixed32, + [kUpb_FieldType_SFixed64] = kUpb_EncodedType_SFixed64, + [kUpb_FieldType_SInt32] = kUpb_EncodedType_SInt32, + [kUpb_FieldType_SInt64] = kUpb_EncodedType_SInt64, + }; - *len = 0; - return true; -} + int encoded_type = kUpb_TypeToEncoded[type]; -const void* _upb_DefBuilder_ResolveAny(upb_DefBuilder* ctx, - const char* from_name_dbg, - const char* base, upb_StringView sym, - upb_deftype_t* type) { - if (sym.size == 0) goto notfound; - upb_value v; - if (sym.data[0] == '.') { - // Symbols starting with '.' are absolute, so we do a single lookup. - // Slice to omit the leading '.' - if (!_upb_DefPool_LookupSym(ctx->symtab, sym.data + 1, sym.size - 1, &v)) { - goto notfound; - } - } else { - // Remove components from base until we find an entry or run out. - size_t baselen = base ? strlen(base) : 0; - char* tmp = upb_gmalloc(sym.size + baselen + 1); - while (1) { - char* p = tmp; - if (baselen) { - memcpy(p, base, baselen); - p[baselen] = '.'; - p += baselen + 1; - } - memcpy(p, sym.data, sym.size); - p += sym.size; - if (_upb_DefPool_LookupSym(ctx->symtab, tmp, p - tmp, &v)) { - break; - } - if (!remove_component(tmp, &baselen)) { - upb_gfree(tmp); - goto notfound; - } - } - upb_gfree(tmp); + if (field_mod & kUpb_FieldModifier_IsClosedEnum) { + UPB_ASSERT(type == kUpb_FieldType_Enum); + encoded_type = kUpb_EncodedType_ClosedEnum; } - *type = _upb_DefType_Type(v); - return _upb_DefType_Unpack(v, *type); + if (field_mod & kUpb_FieldModifier_IsRepeated) { + // Repeated fields shift the type number up (unlike other modifiers which + // are bit flags). + encoded_type += kUpb_EncodedType_RepeatedBase; + } -notfound: - _upb_DefBuilder_Errf(ctx, "couldn't resolve name '" UPB_STRINGVIEW_FORMAT "'", - UPB_STRINGVIEW_ARGS(sym)); + return upb_MtDataEncoder_Put(e, ptr, encoded_type); } -const void* _upb_DefBuilder_Resolve(upb_DefBuilder* ctx, - const char* from_name_dbg, const char* base, - upb_StringView sym, upb_deftype_t type) { - upb_deftype_t found_type; - const void* ret = - _upb_DefBuilder_ResolveAny(ctx, from_name_dbg, base, sym, &found_type); - if (ret && found_type != type) { - _upb_DefBuilder_Errf(ctx, - "type mismatch when resolving %s: couldn't find " - "name " UPB_STRINGVIEW_FORMAT " with type=%d", - from_name_dbg, UPB_STRINGVIEW_ARGS(sym), (int)type); +static char* _upb_MtDataEncoder_MaybePutModifiers(upb_MtDataEncoder* e, + char* ptr, upb_FieldType type, + uint64_t field_mod) { + upb_MtDataEncoderInternal* in = (upb_MtDataEncoderInternal*)e->internal; + uint32_t encoded_modifiers = 0; + if ((field_mod & kUpb_FieldModifier_IsRepeated) && + upb_FieldType_IsPackable(type)) { + bool field_is_packed = field_mod & kUpb_FieldModifier_IsPacked; + bool default_is_packed = in->state.msg_state.msg_modifiers & + kUpb_MessageModifier_DefaultIsPacked; + if (field_is_packed != default_is_packed) { + encoded_modifiers |= kUpb_EncodedFieldModifier_FlipPacked; + } } - return ret; -} -// Per ASCII this will lower-case a letter. If the result is a letter, the -// input was definitely a letter. If the output is not a letter, this may -// have transformed the character unpredictably. -static char upb_ascii_lower(char ch) { return ch | 0x20; } + if (type == kUpb_FieldType_String) { + bool field_validates_utf8 = field_mod & kUpb_FieldModifier_ValidateUtf8; + bool message_validates_utf8 = + in->state.msg_state.msg_modifiers & kUpb_MessageModifier_ValidateUtf8; + if (field_validates_utf8 != message_validates_utf8) { + // Old binaries do not recognize the field modifier. We need the failure + // mode to be too lax rather than too strict. Our caller should have + // handled this (see _upb_MessageDef_ValidateUtf8()). + assert(!message_validates_utf8); + encoded_modifiers |= kUpb_EncodedFieldModifier_FlipValidateUtf8; + } + } -// isalpha() etc. from are locale-dependent, which we don't want. -static bool upb_isbetween(uint8_t c, uint8_t low, uint8_t high) { - return low <= c && c <= high; -} + if (field_mod & kUpb_FieldModifier_IsProto3Singular) { + encoded_modifiers |= kUpb_EncodedFieldModifier_IsProto3Singular; + } -static bool upb_isletter(char c) { - char lower = upb_ascii_lower(c); - return upb_isbetween(lower, 'a', 'z') || c == '_'; -} + if (field_mod & kUpb_FieldModifier_IsRequired) { + encoded_modifiers |= kUpb_EncodedFieldModifier_IsRequired; + } -static bool upb_isalphanum(char c) { - return upb_isletter(c) || upb_isbetween(c, '0', '9'); + return upb_MtDataEncoder_PutModifier(e, ptr, encoded_modifiers); } -static bool TryGetChar(const char** src, const char* end, char* ch) { - if (*src == end) return false; - *ch = **src; - *src += 1; - return true; -} +char* upb_MtDataEncoder_PutField(upb_MtDataEncoder* e, char* ptr, + upb_FieldType type, uint32_t field_num, + uint64_t field_mod) { + upb_MtDataEncoder_GetInternal(e, ptr); -static int TryGetHexDigit(const char** src, const char* end) { - char ch; - if (!TryGetChar(src, end, &ch)) return -1; - if ('0' <= ch && ch <= '9') { - return ch - '0'; - } - ch = upb_ascii_lower(ch); - if ('a' <= ch && ch <= 'f') { - return ch - 'a' + 0xa; - } - *src -= 1; // Char wasn't actually a hex digit. - return -1; -} + ptr = _upb_MtDataEncoder_MaybePutFieldSkip(e, ptr, field_num); + if (!ptr) return NULL; -static char upb_DefBuilder_ParseHexEscape(upb_DefBuilder* ctx, - const upb_FieldDef* f, - const char** src, const char* end) { - int hex_digit = TryGetHexDigit(src, end); - if (hex_digit < 0) { - _upb_DefBuilder_Errf( - ctx, "\\x must be followed by at least one hex digit (field='%s')", - upb_FieldDef_FullName(f)); - return 0; - } - unsigned int ret = hex_digit; - while ((hex_digit = TryGetHexDigit(src, end)) >= 0) { - ret = (ret << 4) | hex_digit; - } - if (ret > 0xff) { - _upb_DefBuilder_Errf(ctx, "Value of hex escape in field %s exceeds 8 bits", - upb_FieldDef_FullName(f)); - return 0; - } - return ret; + ptr = _upb_MtDataEncoder_PutFieldType(e, ptr, type, field_mod); + if (!ptr) return NULL; + + return _upb_MtDataEncoder_MaybePutModifiers(e, ptr, type, field_mod); } -static char TryGetOctalDigit(const char** src, const char* end) { - char ch; - if (!TryGetChar(src, end, &ch)) return -1; - if ('0' <= ch && ch <= '7') { - return ch - '0'; +char* upb_MtDataEncoder_StartOneof(upb_MtDataEncoder* e, char* ptr) { + upb_MtDataEncoderInternal* in = upb_MtDataEncoder_GetInternal(e, ptr); + if (in->state.msg_state.oneof_state == kUpb_OneofState_NotStarted) { + ptr = upb_MtDataEncoder_Put(e, ptr, _upb_FromBase92(kUpb_EncodedValue_End)); + } else { + ptr = upb_MtDataEncoder_Put( + e, ptr, _upb_FromBase92(kUpb_EncodedValue_OneofSeparator)); } - *src -= 1; // Char wasn't actually an octal digit. - return -1; + in->state.msg_state.oneof_state = kUpb_OneofState_StartedOneof; + return ptr; } -static char upb_DefBuilder_ParseOctalEscape(upb_DefBuilder* ctx, - const upb_FieldDef* f, - const char** src, const char* end) { - char ch = 0; - for (int i = 0; i < 3; i++) { - char digit; - if ((digit = TryGetOctalDigit(src, end)) >= 0) { - ch = (ch << 3) | digit; - } +char* upb_MtDataEncoder_PutOneofField(upb_MtDataEncoder* e, char* ptr, + uint32_t field_num) { + upb_MtDataEncoderInternal* in = upb_MtDataEncoder_GetInternal(e, ptr); + if (in->state.msg_state.oneof_state == kUpb_OneofState_EmittedOneofField) { + ptr = upb_MtDataEncoder_Put( + e, ptr, _upb_FromBase92(kUpb_EncodedValue_FieldSeparator)); + if (!ptr) return NULL; } - return ch; + ptr = upb_MtDataEncoder_PutBase92Varint(e, ptr, field_num, _upb_ToBase92(0), + _upb_ToBase92(63)); + in->state.msg_state.oneof_state = kUpb_OneofState_EmittedOneofField; + return ptr; } -char _upb_DefBuilder_ParseEscape(upb_DefBuilder* ctx, const upb_FieldDef* f, - const char** src, const char* end) { - char ch; - if (!TryGetChar(src, end, &ch)) { - _upb_DefBuilder_Errf(ctx, "unterminated escape sequence in field %s", - upb_FieldDef_FullName(f)); - return 0; - } - switch (ch) { - case 'a': - return '\a'; - case 'b': - return '\b'; - case 'f': - return '\f'; - case 'n': - return '\n'; - case 'r': - return '\r'; - case 't': - return '\t'; - case 'v': - return '\v'; - case '\\': - return '\\'; - case '\'': - return '\''; - case '\"': - return '\"'; - case '?': - return '\?'; - case 'x': - case 'X': - return upb_DefBuilder_ParseHexEscape(ctx, f, src, end); - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - *src -= 1; - return upb_DefBuilder_ParseOctalEscape(ctx, f, src, end); - } - _upb_DefBuilder_Errf(ctx, "Unknown escape sequence: \\%c", ch); +char* upb_MtDataEncoder_StartEnum(upb_MtDataEncoder* e, char* ptr) { + upb_MtDataEncoderInternal* in = upb_MtDataEncoder_GetInternal(e, ptr); + in->state.enum_state.present_values_mask = 0; + in->state.enum_state.last_written_value = 0; + + return upb_MtDataEncoder_PutRaw(e, ptr, kUpb_EncodedVersion_EnumV1); } -void _upb_DefBuilder_CheckIdentSlow(upb_DefBuilder* ctx, upb_StringView name, - bool full) { - const char* str = name.data; - const size_t len = name.size; - bool start = true; - for (size_t i = 0; i < len; i++) { - const char c = str[i]; - if (c == '.') { - if (start || !full) { - _upb_DefBuilder_Errf( - ctx, "invalid name: unexpected '.' (" UPB_STRINGVIEW_FORMAT ")", - UPB_STRINGVIEW_ARGS(name)); - } - start = true; - } else if (start) { - if (!upb_isletter(c)) { - _upb_DefBuilder_Errf(ctx, - "invalid name: path components must start with a " - "letter (" UPB_STRINGVIEW_FORMAT ")", - UPB_STRINGVIEW_ARGS(name)); - } - start = false; - } else if (!upb_isalphanum(c)) { - _upb_DefBuilder_Errf( - ctx, - "invalid name: non-alphanumeric character (" UPB_STRINGVIEW_FORMAT - ")", - UPB_STRINGVIEW_ARGS(name)); +static char* upb_MtDataEncoder_FlushDenseEnumMask(upb_MtDataEncoder* e, + char* ptr) { + upb_MtDataEncoderInternal* in = (upb_MtDataEncoderInternal*)e->internal; + ptr = upb_MtDataEncoder_Put(e, ptr, in->state.enum_state.present_values_mask); + in->state.enum_state.present_values_mask = 0; + in->state.enum_state.last_written_value += 5; + return ptr; +} + +char* upb_MtDataEncoder_PutEnumValue(upb_MtDataEncoder* e, char* ptr, + uint32_t val) { + // TODO: optimize this encoding. + upb_MtDataEncoderInternal* in = upb_MtDataEncoder_GetInternal(e, ptr); + UPB_ASSERT(val >= in->state.enum_state.last_written_value); + uint32_t delta = val - in->state.enum_state.last_written_value; + if (delta >= 5 && in->state.enum_state.present_values_mask) { + ptr = upb_MtDataEncoder_FlushDenseEnumMask(e, ptr); + if (!ptr) { + return NULL; } + delta -= 5; } - if (start) { - _upb_DefBuilder_Errf(ctx, - "invalid name: empty part (" UPB_STRINGVIEW_FORMAT ")", - UPB_STRINGVIEW_ARGS(name)); + + if (delta >= 5) { + ptr = upb_MtDataEncoder_PutBase92Varint( + e, ptr, delta, kUpb_EncodedValue_MinSkip, kUpb_EncodedValue_MaxSkip); + in->state.enum_state.last_written_value += delta; + delta = 0; } - // We should never reach this point. - UPB_ASSERT(false); + UPB_ASSERT((in->state.enum_state.present_values_mask >> delta) == 0); + in->state.enum_state.present_values_mask |= 1ULL << delta; + return ptr; } -upb_StringView _upb_DefBuilder_MakeKey(upb_DefBuilder* ctx, - const UPB_DESC(FeatureSet*) parent, - upb_StringView key) { - size_t need = key.size + sizeof(void*); - if (ctx->tmp_buf_size < need) { - ctx->tmp_buf_size = UPB_MAX(64, upb_Log2Ceiling(need)); - ctx->tmp_buf = upb_Arena_Malloc(ctx->tmp_arena, ctx->tmp_buf_size); - if (!ctx->tmp_buf) _upb_DefBuilder_OomErr(ctx); - } - - memcpy(ctx->tmp_buf, &parent, sizeof(void*)); - memcpy(ctx->tmp_buf + sizeof(void*), key.data, key.size); - return upb_StringView_FromDataAndSize(ctx->tmp_buf, need); +char* upb_MtDataEncoder_EndEnum(upb_MtDataEncoder* e, char* ptr) { + upb_MtDataEncoderInternal* in = upb_MtDataEncoder_GetInternal(e, ptr); + if (!in->state.enum_state.present_values_mask) return ptr; + return upb_MtDataEncoder_FlushDenseEnumMask(e, ptr); } -bool _upb_DefBuilder_GetOrCreateFeatureSet(upb_DefBuilder* ctx, - const UPB_DESC(FeatureSet*) parent, - upb_StringView key, - UPB_DESC(FeatureSet**) set) { - upb_StringView k = _upb_DefBuilder_MakeKey(ctx, parent, key); - upb_value v; - if (upb_strtable_lookup2(&ctx->feature_cache, k.data, k.size, &v)) { - *set = upb_value_getptr(v); - return false; - } - *set = (UPB_DESC(FeatureSet*))upb_Message_DeepClone( - UPB_UPCAST(parent), UPB_DESC_MINITABLE(FeatureSet), ctx->arena); - if (!*set) _upb_DefBuilder_OomErr(ctx); +#include - v = upb_value_ptr(*set); - if (!upb_strtable_insert(&ctx->feature_cache, k.data, k.size, v, - ctx->tmp_arena)) { - _upb_DefBuilder_OomErr(ctx); - } +// Must be last. - return true; -} +// A MiniTable for an empty message, used for unlinked sub-messages. +const struct upb_MiniTable UPB_PRIVATE(_kUpb_MiniTable_Empty) = { + .UPB_PRIVATE(subs) = NULL, + .UPB_PRIVATE(fields) = NULL, + .UPB_PRIVATE(size) = 0, + .UPB_PRIVATE(field_count) = 0, + .UPB_PRIVATE(ext) = kUpb_ExtMode_NonExtendable, + .UPB_PRIVATE(dense_below) = 0, + .UPB_PRIVATE(table_mask) = -1, + .UPB_PRIVATE(required_count) = 0, +}; -const UPB_DESC(FeatureSet*) - _upb_DefBuilder_DoResolveFeatures(upb_DefBuilder* ctx, - const UPB_DESC(FeatureSet*) parent, - const UPB_DESC(FeatureSet*) child, - bool is_implicit) { - assert(parent); - if (!child) return parent; - if (child && !is_implicit && - upb_FileDef_Syntax(ctx->file) != kUpb_Syntax_Editions) { - _upb_DefBuilder_Errf(ctx, "Features can only be specified for editions"); - } - UPB_DESC(FeatureSet*) resolved; - size_t child_size; - const char* child_bytes = - UPB_DESC(FeatureSet_serialize)(child, ctx->tmp_arena, &child_size); - if (!child_bytes) _upb_DefBuilder_OomErr(ctx); +// Must be last. - upb_StringView key = upb_StringView_FromDataAndSize(child_bytes, child_size); - if (!_upb_DefBuilder_GetOrCreateFeatureSet(ctx, parent, key, &resolved)) { - return resolved; - } +struct upb_DefPool { + upb_Arena* arena; + upb_strtable syms; // full_name -> packed def ptr + upb_strtable files; // file_name -> (upb_FileDef*) + upb_inttable exts; // (upb_MiniTableExtension*) -> (upb_FieldDef*) + upb_ExtensionRegistry* extreg; + const UPB_DESC(FeatureSetDefaults) * feature_set_defaults; + upb_MiniTablePlatform platform; + void* scratch_data; + size_t scratch_size; + size_t bytes_loaded; +}; - upb_DecodeStatus dec_status = - upb_Decode(child_bytes, child_size, UPB_UPCAST(resolved), - UPB_DESC_MINITABLE(FeatureSet), NULL, 0, ctx->arena); - if (dec_status != kUpb_DecodeStatus_Ok) _upb_DefBuilder_OomErr(ctx); +void upb_DefPool_Free(upb_DefPool* s) { + upb_Arena_Free(s->arena); + upb_gfree(s->scratch_data); + upb_gfree(s); +} + +static const char serialized_defaults[] = UPB_INTERNAL_UPB_EDITION_DEFAULTS; + +upb_DefPool* upb_DefPool_New(void) { + upb_DefPool* s = upb_gmalloc(sizeof(*s)); + if (!s) return NULL; + + s->arena = upb_Arena_New(); + s->bytes_loaded = 0; - return resolved; -} + s->scratch_size = 240; + s->scratch_data = upb_gmalloc(s->scratch_size); + if (!s->scratch_data) goto err; + if (!upb_strtable_init(&s->syms, 32, s->arena)) goto err; + if (!upb_strtable_init(&s->files, 4, s->arena)) goto err; + if (!upb_inttable_init(&s->exts, s->arena)) goto err; -#include + s->extreg = upb_ExtensionRegistry_New(s->arena); + if (!s->extreg) goto err; + s->platform = kUpb_MiniTablePlatform_Native; -// Must be last. + upb_Status status; + if (!upb_DefPool_SetFeatureSetDefaults( + s, serialized_defaults, sizeof(serialized_defaults) - 1, &status)) { + goto err; + } -char* upb_strdup2(const char* s, size_t len, upb_Arena* a) { - size_t n; - char* p; + if (!s->feature_set_defaults) goto err; - // Prevent overflow errors. - if (len == SIZE_MAX) return NULL; + return s; - // Always null-terminate, even if binary data; but don't rely on the input to - // have a null-terminating byte since it may be a raw binary buffer. - n = len + 1; - p = upb_Arena_Malloc(a, n); - if (p) { - if (len != 0) memcpy(p, s, len); - p[len] = 0; - } - return p; +err: + upb_DefPool_Free(s); + return NULL; } +const UPB_DESC(FeatureSetDefaults) * + upb_DefPool_FeatureSetDefaults(const upb_DefPool* s) { + return s->feature_set_defaults; +} -#include -#include - +bool upb_DefPool_SetFeatureSetDefaults(upb_DefPool* s, + const char* serialized_defaults, + size_t serialized_len, + upb_Status* status) { + const UPB_DESC(FeatureSetDefaults)* defaults = UPB_DESC( + FeatureSetDefaults_parse)(serialized_defaults, serialized_len, s->arena); + if (!defaults) { + upb_Status_SetErrorFormat(status, "Failed to parse defaults"); + return false; + } + if (upb_strtable_count(&s->files) > 0) { + upb_Status_SetErrorFormat(status, + "Feature set defaults can't be changed once the " + "pool has started building"); + return false; + } + int min_edition = UPB_DESC(FeatureSetDefaults_minimum_edition(defaults)); + int max_edition = UPB_DESC(FeatureSetDefaults_maximum_edition(defaults)); + if (min_edition > max_edition) { + upb_Status_SetErrorFormat(status, "Invalid edition range %s to %s", + upb_FileDef_EditionName(min_edition), + upb_FileDef_EditionName(max_edition)); + return false; + } + size_t size; + const UPB_DESC( + FeatureSetDefaults_FeatureSetEditionDefault)* const* default_list = + UPB_DESC(FeatureSetDefaults_defaults(defaults, &size)); + int prev_edition = UPB_DESC(EDITION_UNKNOWN); + for (size_t i = 0; i < size; ++i) { + int edition = UPB_DESC( + FeatureSetDefaults_FeatureSetEditionDefault_edition(default_list[i])); + if (edition == UPB_DESC(EDITION_UNKNOWN)) { + upb_Status_SetErrorFormat(status, "Invalid edition UNKNOWN specified"); + return false; + } + if (edition <= prev_edition) { + upb_Status_SetErrorFormat(status, + "Feature set defaults are not strictly " + "increasing, %s is greater than or equal to %s", + upb_FileDef_EditionName(prev_edition), + upb_FileDef_EditionName(edition)); + return false; + } + prev_edition = edition; + } -// Must be last. + // Copy the defaults into the pool. + s->feature_set_defaults = defaults; + return true; +} -bool upb_Message_HasFieldByDef(const upb_Message* msg, const upb_FieldDef* f) { - UPB_ASSERT(upb_FieldDef_HasPresence(f)); - return upb_Message_HasField(msg, upb_FieldDef_MiniTable(f)); +bool _upb_DefPool_InsertExt(upb_DefPool* s, const upb_MiniTableExtension* ext, + const upb_FieldDef* f) { + return upb_inttable_insert(&s->exts, (uintptr_t)ext, upb_value_constptr(f), + s->arena); } -const upb_FieldDef* upb_Message_WhichOneof(const upb_Message* msg, - const upb_OneofDef* o) { - const upb_FieldDef* f = upb_OneofDef_Field(o, 0); - if (upb_OneofDef_IsSynthetic(o)) { - UPB_ASSERT(upb_OneofDef_FieldCount(o) == 1); - return upb_Message_HasFieldByDef(msg, f) ? f : NULL; - } else { - const upb_MiniTableField* field = upb_FieldDef_MiniTable(f); - uint32_t oneof_case = upb_Message_WhichOneofFieldNumber(msg, field); - f = oneof_case ? upb_OneofDef_LookupNumber(o, oneof_case) : NULL; - UPB_ASSERT((f != NULL) == (oneof_case != 0)); - return f; +bool _upb_DefPool_InsertSym(upb_DefPool* s, upb_StringView sym, upb_value v, + upb_Status* status) { + // TODO: table should support an operation "tryinsert" to avoid the double + // lookup. + if (upb_strtable_lookup2(&s->syms, sym.data, sym.size, NULL)) { + upb_Status_SetErrorFormat(status, "duplicate symbol '%s'", sym.data); + return false; + } + if (!upb_strtable_insert(&s->syms, sym.data, sym.size, v, s->arena)) { + upb_Status_SetErrorMessage(status, "out of memory"); + return false; } + return true; } -upb_MessageValue upb_Message_GetFieldByDef(const upb_Message* msg, - const upb_FieldDef* f) { - upb_MessageValue default_val = upb_FieldDef_Default(f); - return upb_Message_GetField(msg, upb_FieldDef_MiniTable(f), default_val); +static const void* _upb_DefPool_Unpack(const upb_DefPool* s, const char* sym, + size_t size, upb_deftype_t type) { + upb_value v; + return upb_strtable_lookup2(&s->syms, sym, size, &v) + ? _upb_DefType_Unpack(v, type) + : NULL; } -upb_MutableMessageValue upb_Message_Mutable(upb_Message* msg, - const upb_FieldDef* f, - upb_Arena* a) { - UPB_ASSERT(upb_FieldDef_IsSubMessage(f) || upb_FieldDef_IsRepeated(f)); - if (upb_FieldDef_HasPresence(f) && !upb_Message_HasFieldByDef(msg, f)) { - // We need to skip the upb_Message_GetFieldByDef() call in this case. - goto make; - } +bool _upb_DefPool_LookupSym(const upb_DefPool* s, const char* sym, size_t size, + upb_value* v) { + return upb_strtable_lookup2(&s->syms, sym, size, v); +} - upb_MessageValue val = upb_Message_GetFieldByDef(msg, f); - if (val.array_val) { - return (upb_MutableMessageValue){.array = (upb_Array*)val.array_val}; - } +upb_ExtensionRegistry* _upb_DefPool_ExtReg(const upb_DefPool* s) { + return s->extreg; +} - upb_MutableMessageValue ret; -make: - if (!a) return (upb_MutableMessageValue){.array = NULL}; - if (upb_FieldDef_IsMap(f)) { - const upb_MessageDef* entry = upb_FieldDef_MessageSubDef(f); - const upb_FieldDef* key = - upb_MessageDef_FindFieldByNumber(entry, kUpb_MapEntry_KeyFieldNumber); - const upb_FieldDef* value = - upb_MessageDef_FindFieldByNumber(entry, kUpb_MapEntry_ValueFieldNumber); - ret.map = - upb_Map_New(a, upb_FieldDef_CType(key), upb_FieldDef_CType(value)); - } else if (upb_FieldDef_IsRepeated(f)) { - ret.array = upb_Array_New(a, upb_FieldDef_CType(f)); - } else { - UPB_ASSERT(upb_FieldDef_IsSubMessage(f)); - const upb_MessageDef* m = upb_FieldDef_MessageSubDef(f); - ret.msg = upb_Message_New(upb_MessageDef_MiniTable(m), a); - } +void** _upb_DefPool_ScratchData(const upb_DefPool* s) { + return (void**)&s->scratch_data; +} - val.array_val = ret.array; - upb_Message_SetFieldByDef(msg, f, val, a); +size_t* _upb_DefPool_ScratchSize(const upb_DefPool* s) { + return (size_t*)&s->scratch_size; +} - return ret; +void _upb_DefPool_SetPlatform(upb_DefPool* s, upb_MiniTablePlatform platform) { + assert(upb_strtable_count(&s->files) == 0); + s->platform = platform; } -bool upb_Message_SetFieldByDef(upb_Message* msg, const upb_FieldDef* f, - upb_MessageValue val, upb_Arena* a) { - return upb_Message_SetField(msg, upb_FieldDef_MiniTable(f), val, a); +const upb_MessageDef* upb_DefPool_FindMessageByName(const upb_DefPool* s, + const char* sym) { + return _upb_DefPool_Unpack(s, sym, strlen(sym), UPB_DEFTYPE_MSG); } -void upb_Message_ClearFieldByDef(upb_Message* msg, const upb_FieldDef* f) { - upb_Message_ClearField(msg, upb_FieldDef_MiniTable(f)); +const upb_MessageDef* upb_DefPool_FindMessageByNameWithSize( + const upb_DefPool* s, const char* sym, size_t len) { + return _upb_DefPool_Unpack(s, sym, len, UPB_DEFTYPE_MSG); } -void upb_Message_ClearByDef(upb_Message* msg, const upb_MessageDef* m) { - upb_Message_Clear(msg, upb_MessageDef_MiniTable(m)); +const upb_EnumDef* upb_DefPool_FindEnumByName(const upb_DefPool* s, + const char* sym) { + return _upb_DefPool_Unpack(s, sym, strlen(sym), UPB_DEFTYPE_ENUM); } -bool upb_Message_Next(const upb_Message* msg, const upb_MessageDef* m, - const upb_DefPool* ext_pool, const upb_FieldDef** out_f, - upb_MessageValue* out_val, size_t* iter) { - size_t i = *iter; - size_t n = upb_MessageDef_FieldCount(m); - UPB_UNUSED(ext_pool); +const upb_EnumValueDef* upb_DefPool_FindEnumByNameval(const upb_DefPool* s, + const char* sym) { + return _upb_DefPool_Unpack(s, sym, strlen(sym), UPB_DEFTYPE_ENUMVAL); +} - // Iterate over normal fields, returning the first one that is set. - while (++i < n) { - const upb_FieldDef* f = upb_MessageDef_Field(m, i); - const upb_MiniTableField* field = upb_FieldDef_MiniTable(f); - upb_MessageValue val = upb_Message_GetFieldByDef(msg, f); +const upb_FileDef* upb_DefPool_FindFileByName(const upb_DefPool* s, + const char* name) { + upb_value v; + return upb_strtable_lookup(&s->files, name, &v) ? upb_value_getconstptr(v) + : NULL; +} - // Skip field if unset or empty. - if (upb_MiniTableField_HasPresence(field)) { - if (!upb_Message_HasFieldByDef(msg, f)) continue; - } else { - switch (UPB_PRIVATE(_upb_MiniTableField_Mode)(field)) { - case kUpb_FieldMode_Map: - if (!val.map_val || upb_Map_Size(val.map_val) == 0) continue; - break; - case kUpb_FieldMode_Array: - if (!val.array_val || upb_Array_Size(val.array_val) == 0) continue; - break; - case kUpb_FieldMode_Scalar: - if (UPB_PRIVATE(_upb_MiniTableField_DataIsZero)(field, &val)) - continue; - break; - } - } +const upb_FileDef* upb_DefPool_FindFileByNameWithSize(const upb_DefPool* s, + const char* name, + size_t len) { + upb_value v; + return upb_strtable_lookup2(&s->files, name, len, &v) + ? upb_value_getconstptr(v) + : NULL; +} - *out_val = val; - *out_f = f; - *iter = i; - return true; - } +const upb_FieldDef* upb_DefPool_FindExtensionByNameWithSize( + const upb_DefPool* s, const char* name, size_t size) { + upb_value v; + if (!upb_strtable_lookup2(&s->syms, name, size, &v)) return NULL; - if (ext_pool) { - // Return any extensions that are set. - size_t count; - const upb_Extension* ext = UPB_PRIVATE(_upb_Message_Getexts)(msg, &count); - if (i - n < count) { - ext += count - 1 - (i - n); - memcpy(out_val, &ext->data, sizeof(*out_val)); - *out_f = upb_DefPool_FindExtensionByMiniTable(ext_pool, ext->ext); - *iter = i; - return true; + switch (_upb_DefType_Type(v)) { + case UPB_DEFTYPE_FIELD: + return _upb_DefType_Unpack(v, UPB_DEFTYPE_FIELD); + case UPB_DEFTYPE_MSG: { + const upb_MessageDef* m = _upb_DefType_Unpack(v, UPB_DEFTYPE_MSG); + return _upb_MessageDef_InMessageSet(m) + ? upb_MessageDef_NestedExtension(m, 0) + : NULL; } + default: + break; } - *iter = i; - return false; + return NULL; } -bool _upb_Message_DiscardUnknown(upb_Message* msg, const upb_MessageDef* m, - int depth) { - size_t iter = kUpb_Message_Begin; - const upb_FieldDef* f; - upb_MessageValue val; - bool ret = true; - - if (--depth == 0) return false; - - _upb_Message_DiscardUnknown_shallow(msg); +const upb_FieldDef* upb_DefPool_FindExtensionByName(const upb_DefPool* s, + const char* sym) { + return upb_DefPool_FindExtensionByNameWithSize(s, sym, strlen(sym)); +} - while (upb_Message_Next(msg, m, NULL /*ext_pool*/, &f, &val, &iter)) { - const upb_MessageDef* subm = upb_FieldDef_MessageSubDef(f); - if (!subm) continue; - if (upb_FieldDef_IsMap(f)) { - const upb_FieldDef* val_f = upb_MessageDef_FindFieldByNumber(subm, 2); - const upb_MessageDef* val_m = upb_FieldDef_MessageSubDef(val_f); - upb_Map* map = (upb_Map*)val.map_val; - size_t iter = kUpb_Map_Begin; +const upb_ServiceDef* upb_DefPool_FindServiceByName(const upb_DefPool* s, + const char* name) { + return _upb_DefPool_Unpack(s, name, strlen(name), UPB_DEFTYPE_SERVICE); +} - if (!val_m) continue; +const upb_ServiceDef* upb_DefPool_FindServiceByNameWithSize( + const upb_DefPool* s, const char* name, size_t size) { + return _upb_DefPool_Unpack(s, name, size, UPB_DEFTYPE_SERVICE); +} - upb_MessageValue map_key, map_val; - while (upb_Map_Next(map, &map_key, &map_val, &iter)) { - if (!_upb_Message_DiscardUnknown((upb_Message*)map_val.msg_val, val_m, - depth)) { - ret = false; - } +const upb_FileDef* upb_DefPool_FindFileContainingSymbol(const upb_DefPool* s, + const char* name) { + upb_value v; + // TODO: non-extension fields and oneofs. + if (upb_strtable_lookup(&s->syms, name, &v)) { + switch (_upb_DefType_Type(v)) { + case UPB_DEFTYPE_EXT: { + const upb_FieldDef* f = _upb_DefType_Unpack(v, UPB_DEFTYPE_EXT); + return upb_FieldDef_File(f); } - } else if (upb_FieldDef_IsRepeated(f)) { - const upb_Array* arr = val.array_val; - size_t i, n = upb_Array_Size(arr); - for (i = 0; i < n; i++) { - upb_MessageValue elem = upb_Array_Get(arr, i); - if (!_upb_Message_DiscardUnknown((upb_Message*)elem.msg_val, subm, - depth)) { - ret = false; - } + case UPB_DEFTYPE_MSG: { + const upb_MessageDef* m = _upb_DefType_Unpack(v, UPB_DEFTYPE_MSG); + return upb_MessageDef_File(m); } - } else { - if (!_upb_Message_DiscardUnknown((upb_Message*)val.msg_val, subm, - depth)) { - ret = false; + case UPB_DEFTYPE_ENUM: { + const upb_EnumDef* e = _upb_DefType_Unpack(v, UPB_DEFTYPE_ENUM); + return upb_EnumDef_File(e); + } + case UPB_DEFTYPE_ENUMVAL: { + const upb_EnumValueDef* ev = + _upb_DefType_Unpack(v, UPB_DEFTYPE_ENUMVAL); + return upb_EnumDef_File(upb_EnumValueDef_Enum(ev)); + } + case UPB_DEFTYPE_SERVICE: { + const upb_ServiceDef* service = + _upb_DefType_Unpack(v, UPB_DEFTYPE_SERVICE); + return upb_ServiceDef_File(service); } + default: + UPB_UNREACHABLE(); } } - return ret; -} + const char* last_dot = strrchr(name, '.'); + if (last_dot) { + const upb_MessageDef* parent = + upb_DefPool_FindMessageByNameWithSize(s, name, last_dot - name); + if (parent) { + const char* shortname = last_dot + 1; + if (upb_MessageDef_FindByNameWithSize(parent, shortname, + strlen(shortname), NULL, NULL)) { + return upb_MessageDef_File(parent); + } + } + } -bool upb_Message_DiscardUnknown(upb_Message* msg, const upb_MessageDef* m, - int maxdepth) { - return _upb_Message_DiscardUnknown(msg, m, maxdepth); + return NULL; } +static void remove_filedef(upb_DefPool* s, upb_FileDef* file) { + intptr_t iter = UPB_INTTABLE_BEGIN; + upb_StringView key; + upb_value val; + while (upb_strtable_next2(&s->syms, &key, &val, &iter)) { + const upb_FileDef* f; + switch (_upb_DefType_Type(val)) { + case UPB_DEFTYPE_EXT: + f = upb_FieldDef_File(_upb_DefType_Unpack(val, UPB_DEFTYPE_EXT)); + break; + case UPB_DEFTYPE_MSG: + f = upb_MessageDef_File(_upb_DefType_Unpack(val, UPB_DEFTYPE_MSG)); + break; + case UPB_DEFTYPE_ENUM: + f = upb_EnumDef_File(_upb_DefType_Unpack(val, UPB_DEFTYPE_ENUM)); + break; + case UPB_DEFTYPE_ENUMVAL: + f = upb_EnumDef_File(upb_EnumValueDef_Enum( + _upb_DefType_Unpack(val, UPB_DEFTYPE_ENUMVAL))); + break; + case UPB_DEFTYPE_SERVICE: + f = upb_ServiceDef_File(_upb_DefType_Unpack(val, UPB_DEFTYPE_SERVICE)); + break; + default: + UPB_UNREACHABLE(); + } -#include -#include -#include - - -// Must be last. - -struct upb_MessageDef { - const UPB_DESC(MessageOptions*) opts; - const UPB_DESC(FeatureSet*) resolved_features; - const upb_MiniTable* layout; - const upb_FileDef* file; - const upb_MessageDef* containing_type; - const char* full_name; - - // Tables for looking up fields by number and name. - upb_inttable itof; - upb_strtable ntof; - - // Looking up fields by json name. - upb_strtable jtof; - - /* All nested defs. - * MEM: We could save some space here by putting nested defs in a contiguous - * region and calculating counts from offsets or vice-versa. */ - const upb_FieldDef* fields; - const upb_OneofDef* oneofs; - const upb_ExtensionRange* ext_ranges; - const upb_StringView* res_names; - const upb_MessageDef* nested_msgs; - const upb_MessageReservedRange* res_ranges; - const upb_EnumDef* nested_enums; - const upb_FieldDef* nested_exts; - - // TODO: These counters don't need anywhere near 32 bits. - int field_count; - int real_oneof_count; - int oneof_count; - int ext_range_count; - int res_range_count; - int res_name_count; - int nested_msg_count; - int nested_enum_count; - int nested_ext_count; - bool in_message_set; - bool is_sorted; - upb_WellKnown well_known_type; -#if UINTPTR_MAX == 0xffffffff - uint32_t padding; // Increase size to a multiple of 8. -#endif -}; - -static void assign_msg_wellknowntype(upb_MessageDef* m) { - const char* name = m->full_name; - if (name == NULL) { - m->well_known_type = kUpb_WellKnown_Unspecified; - return; + if (f == file) upb_strtable_removeiter(&s->syms, &iter); } - if (!strcmp(name, "google.protobuf.Any")) { - m->well_known_type = kUpb_WellKnown_Any; - } else if (!strcmp(name, "google.protobuf.FieldMask")) { - m->well_known_type = kUpb_WellKnown_FieldMask; - } else if (!strcmp(name, "google.protobuf.Duration")) { - m->well_known_type = kUpb_WellKnown_Duration; - } else if (!strcmp(name, "google.protobuf.Timestamp")) { - m->well_known_type = kUpb_WellKnown_Timestamp; - } else if (!strcmp(name, "google.protobuf.DoubleValue")) { - m->well_known_type = kUpb_WellKnown_DoubleValue; - } else if (!strcmp(name, "google.protobuf.FloatValue")) { - m->well_known_type = kUpb_WellKnown_FloatValue; - } else if (!strcmp(name, "google.protobuf.Int64Value")) { - m->well_known_type = kUpb_WellKnown_Int64Value; - } else if (!strcmp(name, "google.protobuf.UInt64Value")) { - m->well_known_type = kUpb_WellKnown_UInt64Value; - } else if (!strcmp(name, "google.protobuf.Int32Value")) { - m->well_known_type = kUpb_WellKnown_Int32Value; - } else if (!strcmp(name, "google.protobuf.UInt32Value")) { - m->well_known_type = kUpb_WellKnown_UInt32Value; - } else if (!strcmp(name, "google.protobuf.BoolValue")) { - m->well_known_type = kUpb_WellKnown_BoolValue; - } else if (!strcmp(name, "google.protobuf.StringValue")) { - m->well_known_type = kUpb_WellKnown_StringValue; - } else if (!strcmp(name, "google.protobuf.BytesValue")) { - m->well_known_type = kUpb_WellKnown_BytesValue; - } else if (!strcmp(name, "google.protobuf.Value")) { - m->well_known_type = kUpb_WellKnown_Value; - } else if (!strcmp(name, "google.protobuf.ListValue")) { - m->well_known_type = kUpb_WellKnown_ListValue; - } else if (!strcmp(name, "google.protobuf.Struct")) { - m->well_known_type = kUpb_WellKnown_Struct; +} + +static const upb_FileDef* upb_DefBuilder_AddFileToPool( + upb_DefBuilder* const builder, upb_DefPool* const s, + const UPB_DESC(FileDescriptorProto) * const file_proto, + const upb_StringView name, upb_Status* const status) { + if (UPB_SETJMP(builder->err) != 0) { + UPB_ASSERT(!upb_Status_IsOk(status)); + if (builder->file) { + remove_filedef(s, builder->file); + builder->file = NULL; + } + } else if (!builder->arena || !builder->tmp_arena || + !upb_strtable_init(&builder->feature_cache, 16, + builder->tmp_arena) || + !(builder->legacy_features = + UPB_DESC(FeatureSet_new)(builder->tmp_arena))) { + _upb_DefBuilder_OomErr(builder); } else { - m->well_known_type = kUpb_WellKnown_Unspecified; + _upb_FileDef_Create(builder, file_proto); + upb_strtable_insert(&s->files, name.data, name.size, + upb_value_constptr(builder->file), builder->arena); + UPB_ASSERT(upb_Status_IsOk(status)); + upb_Arena_Fuse(s->arena, builder->arena); } -} -upb_MessageDef* _upb_MessageDef_At(const upb_MessageDef* m, int i) { - return (upb_MessageDef*)&m[i]; + if (builder->arena) upb_Arena_Free(builder->arena); + if (builder->tmp_arena) upb_Arena_Free(builder->tmp_arena); + return builder->file; } -bool _upb_MessageDef_IsValidExtensionNumber(const upb_MessageDef* m, int n) { - for (int i = 0; i < m->ext_range_count; i++) { - const upb_ExtensionRange* r = upb_MessageDef_ExtensionRange(m, i); - if (upb_ExtensionRange_Start(r) <= n && n < upb_ExtensionRange_End(r)) { - return true; +static const upb_FileDef* _upb_DefPool_AddFile( + upb_DefPool* s, const UPB_DESC(FileDescriptorProto) * file_proto, + const upb_MiniTableFile* layout, upb_Status* status) { + const upb_StringView name = UPB_DESC(FileDescriptorProto_name)(file_proto); + + // Determine whether we already know about this file. + { + upb_value v; + if (upb_strtable_lookup2(&s->files, name.data, name.size, &v)) { + upb_Status_SetErrorFormat(status, + "duplicate file name " UPB_STRINGVIEW_FORMAT, + UPB_STRINGVIEW_ARGS(name)); + return NULL; } } - return false; -} -const UPB_DESC(MessageOptions) * - upb_MessageDef_Options(const upb_MessageDef* m) { - return m->opts; -} + upb_DefBuilder ctx = { + .symtab = s, + .tmp_buf = NULL, + .tmp_buf_size = 0, + .layout = layout, + .platform = s->platform, + .msg_count = 0, + .enum_count = 0, + .ext_count = 0, + .status = status, + .file = NULL, + .arena = upb_Arena_New(), + .tmp_arena = upb_Arena_New(), + }; -bool upb_MessageDef_HasOptions(const upb_MessageDef* m) { - return m->opts != (void*)kUpbDefOptDefault; + return upb_DefBuilder_AddFileToPool(&ctx, s, file_proto, name, status); } -const UPB_DESC(FeatureSet) * - upb_MessageDef_ResolvedFeatures(const upb_MessageDef* m) { - return m->resolved_features; +const upb_FileDef* upb_DefPool_AddFile(upb_DefPool* s, + const UPB_DESC(FileDescriptorProto) * + file_proto, + upb_Status* status) { + return _upb_DefPool_AddFile(s, file_proto, NULL, status); } -const char* upb_MessageDef_FullName(const upb_MessageDef* m) { - return m->full_name; -} +bool _upb_DefPool_LoadDefInitEx(upb_DefPool* s, const _upb_DefPool_Init* init, + bool rebuild_minitable) { + /* Since this function should never fail (it would indicate a bug in upb) we + * print errors to stderr instead of returning error status to the user. */ + _upb_DefPool_Init** deps = init->deps; + UPB_DESC(FileDescriptorProto) * file; + upb_Arena* arena; + upb_Status status; -const upb_FileDef* upb_MessageDef_File(const upb_MessageDef* m) { - return m->file; + upb_Status_Clear(&status); + + if (upb_DefPool_FindFileByName(s, init->filename)) { + return true; + } + + arena = upb_Arena_New(); + + for (; *deps; deps++) { + if (!_upb_DefPool_LoadDefInitEx(s, *deps, rebuild_minitable)) goto err; + } + + file = UPB_DESC(FileDescriptorProto_parse_ex)( + init->descriptor.data, init->descriptor.size, NULL, + kUpb_DecodeOption_AliasString, arena); + s->bytes_loaded += init->descriptor.size; + + if (!file) { + upb_Status_SetErrorFormat( + &status, + "Failed to parse compiled-in descriptor for file '%s'. This should " + "never happen.", + init->filename); + goto err; + } + + const upb_MiniTableFile* mt = rebuild_minitable ? NULL : init->layout; + if (!_upb_DefPool_AddFile(s, file, mt, &status)) { + goto err; + } + + upb_Arena_Free(arena); + return true; + +err: + fprintf(stderr, + "Error loading compiled-in descriptor for file '%s' (this should " + "never happen): %s\n", + init->filename, upb_Status_ErrorMessage(&status)); + upb_Arena_Free(arena); + return false; } -const upb_MessageDef* upb_MessageDef_ContainingType(const upb_MessageDef* m) { - return m->containing_type; +size_t _upb_DefPool_BytesLoaded(const upb_DefPool* s) { + return s->bytes_loaded; } -const char* upb_MessageDef_Name(const upb_MessageDef* m) { - return _upb_DefBuilder_FullToShort(m->full_name); +upb_Arena* _upb_DefPool_Arena(const upb_DefPool* s) { return s->arena; } + +const upb_FieldDef* upb_DefPool_FindExtensionByMiniTable( + const upb_DefPool* s, const upb_MiniTableExtension* ext) { + upb_value v; + bool ok = upb_inttable_lookup(&s->exts, (uintptr_t)ext, &v); + UPB_ASSERT(ok); + return upb_value_getconstptr(v); } -upb_Syntax upb_MessageDef_Syntax(const upb_MessageDef* m) { - return upb_FileDef_Syntax(m->file); +const upb_FieldDef* upb_DefPool_FindExtensionByNumber(const upb_DefPool* s, + const upb_MessageDef* m, + int32_t fieldnum) { + const upb_MiniTable* t = upb_MessageDef_MiniTable(m); + const upb_MiniTableExtension* ext = + upb_ExtensionRegistry_Lookup(s->extreg, t, fieldnum); + return ext ? upb_DefPool_FindExtensionByMiniTable(s, ext) : NULL; } -const upb_FieldDef* upb_MessageDef_FindFieldByNumber(const upb_MessageDef* m, - uint32_t i) { - upb_value val; - return upb_inttable_lookup(&m->itof, i, &val) ? upb_value_getconstptr(val) - : NULL; +const upb_ExtensionRegistry* upb_DefPool_ExtensionRegistry( + const upb_DefPool* s) { + return s->extreg; } -const upb_FieldDef* upb_MessageDef_FindFieldByNameWithSize( - const upb_MessageDef* m, const char* name, size_t size) { +const upb_FieldDef** upb_DefPool_GetAllExtensions(const upb_DefPool* s, + const upb_MessageDef* m, + size_t* count) { + size_t n = 0; + intptr_t iter = UPB_INTTABLE_BEGIN; + uintptr_t key; upb_value val; - - if (!upb_strtable_lookup2(&m->ntof, name, size, &val)) { - return NULL; + // This is O(all exts) instead of O(exts for m). If we need this to be + // efficient we may need to make extreg into a two-level table, or have a + // second per-message index. + while (upb_inttable_next(&s->exts, &key, &val, &iter)) { + const upb_FieldDef* f = upb_value_getconstptr(val); + if (upb_FieldDef_ContainingType(f) == m) n++; } + const upb_FieldDef** exts = upb_gmalloc(n * sizeof(*exts)); + iter = UPB_INTTABLE_BEGIN; + size_t i = 0; + while (upb_inttable_next(&s->exts, &key, &val, &iter)) { + const upb_FieldDef* f = upb_value_getconstptr(val); + if (upb_FieldDef_ContainingType(f) == m) exts[i++] = f; + } + *count = n; + return exts; +} - return _upb_DefType_Unpack(val, UPB_DEFTYPE_FIELD); +bool _upb_DefPool_LoadDefInit(upb_DefPool* s, const _upb_DefPool_Init* init) { + return _upb_DefPool_LoadDefInitEx(s, init, false); } -const upb_OneofDef* upb_MessageDef_FindOneofByNameWithSize( - const upb_MessageDef* m, const char* name, size_t size) { - upb_value val; - if (!upb_strtable_lookup2(&m->ntof, name, size, &val)) { - return NULL; - } +// Must be last. - return _upb_DefType_Unpack(val, UPB_DEFTYPE_ONEOF); +upb_deftype_t _upb_DefType_Type(upb_value v) { + const uintptr_t num = (uintptr_t)upb_value_getconstptr(v); + return num & UPB_DEFTYPE_MASK; } -bool _upb_MessageDef_Insert(upb_MessageDef* m, const char* name, size_t len, - upb_value v, upb_Arena* a) { - return upb_strtable_insert(&m->ntof, name, len, v, a); +upb_value _upb_DefType_Pack(const void* ptr, upb_deftype_t type) { + uintptr_t num = (uintptr_t)ptr; + UPB_ASSERT((num & UPB_DEFTYPE_MASK) == 0); + num |= type; + return upb_value_constptr((const void*)num); } -bool upb_MessageDef_FindByNameWithSize(const upb_MessageDef* m, - const char* name, size_t len, - const upb_FieldDef** out_f, - const upb_OneofDef** out_o) { - upb_value val; +const void* _upb_DefType_Unpack(upb_value v, upb_deftype_t type) { + uintptr_t num = (uintptr_t)upb_value_getconstptr(v); + return (num & UPB_DEFTYPE_MASK) == type + ? (const void*)(num & ~UPB_DEFTYPE_MASK) + : NULL; +} - if (!upb_strtable_lookup2(&m->ntof, name, len, &val)) { - return false; - } - const upb_FieldDef* f = _upb_DefType_Unpack(val, UPB_DEFTYPE_FIELD); - const upb_OneofDef* o = _upb_DefType_Unpack(val, UPB_DEFTYPE_ONEOF); - if (out_f) *out_f = f; - if (out_o) *out_o = o; - return f || o; /* False if this was a JSON name. */ -} +// Must be last. -const upb_FieldDef* upb_MessageDef_FindByJsonNameWithSize( - const upb_MessageDef* m, const char* name, size_t size) { - upb_value val; +bool _upb_DescState_Grow(upb_DescState* d, upb_Arena* a) { + const size_t oldbufsize = d->bufsize; + const int used = d->ptr - d->buf; - if (upb_strtable_lookup2(&m->jtof, name, size, &val)) { - return upb_value_getconstptr(val); + if (!d->buf) { + d->buf = upb_Arena_Malloc(a, d->bufsize); + if (!d->buf) return false; + d->ptr = d->buf; + d->e.end = d->buf + d->bufsize; } - if (!upb_strtable_lookup2(&m->ntof, name, size, &val)) { - return NULL; + if (oldbufsize - used < kUpb_MtDataEncoder_MinSize) { + d->bufsize *= 2; + d->buf = upb_Arena_Realloc(a, d->buf, oldbufsize, d->bufsize); + if (!d->buf) return false; + d->ptr = d->buf + used; + d->e.end = d->buf + d->bufsize; } - return _upb_DefType_Unpack(val, UPB_DEFTYPE_FIELD); + return true; } -int upb_MessageDef_ExtensionRangeCount(const upb_MessageDef* m) { - return m->ext_range_count; + +#include +#include +#include + + +// Must be last. + +struct upb_EnumDef { + const UPB_DESC(EnumOptions*) opts; + const UPB_DESC(FeatureSet*) resolved_features; + const upb_MiniTableEnum* layout; // Only for proto2. + const upb_FileDef* file; + const upb_MessageDef* containing_type; // Could be merged with "file". + const char* full_name; + upb_strtable ntoi; + upb_inttable iton; + const upb_EnumValueDef* values; + const upb_EnumReservedRange* res_ranges; + const upb_StringView* res_names; + int value_count; + int res_range_count; + int res_name_count; + int32_t defaultval; + bool is_sorted; // Whether all of the values are defined in ascending order. +#if UINTPTR_MAX == 0xffffffff + uint32_t padding; // Increase size to a multiple of 8. +#endif +}; + +upb_EnumDef* _upb_EnumDef_At(const upb_EnumDef* e, int i) { + return (upb_EnumDef*)&e[i]; } -int upb_MessageDef_ReservedRangeCount(const upb_MessageDef* m) { - return m->res_range_count; +const upb_MiniTableEnum* _upb_EnumDef_MiniTable(const upb_EnumDef* e) { + return e->layout; } -int upb_MessageDef_ReservedNameCount(const upb_MessageDef* m) { - return m->res_name_count; -} +bool _upb_EnumDef_Insert(upb_EnumDef* e, upb_EnumValueDef* v, upb_Arena* a) { + const char* name = upb_EnumValueDef_Name(v); + const upb_value val = upb_value_constptr(v); + bool ok = upb_strtable_insert(&e->ntoi, name, strlen(name), val, a); + if (!ok) return false; -int upb_MessageDef_FieldCount(const upb_MessageDef* m) { - return m->field_count; + // Multiple enumerators can have the same number, first one wins. + const int number = upb_EnumValueDef_Number(v); + if (!upb_inttable_lookup(&e->iton, number, NULL)) { + return upb_inttable_insert(&e->iton, number, val, a); + } + return true; } -int upb_MessageDef_OneofCount(const upb_MessageDef* m) { - return m->oneof_count; +const UPB_DESC(EnumOptions) * upb_EnumDef_Options(const upb_EnumDef* e) { + return e->opts; } -int upb_MessageDef_RealOneofCount(const upb_MessageDef* m) { - return m->real_oneof_count; +bool upb_EnumDef_HasOptions(const upb_EnumDef* e) { + return e->opts != (void*)kUpbDefOptDefault; } -int upb_MessageDef_NestedMessageCount(const upb_MessageDef* m) { - return m->nested_msg_count; +const UPB_DESC(FeatureSet) * + upb_EnumDef_ResolvedFeatures(const upb_EnumDef* e) { + return e->resolved_features; } -int upb_MessageDef_NestedEnumCount(const upb_MessageDef* m) { - return m->nested_enum_count; -} +const char* upb_EnumDef_FullName(const upb_EnumDef* e) { return e->full_name; } -int upb_MessageDef_NestedExtensionCount(const upb_MessageDef* m) { - return m->nested_ext_count; +const char* upb_EnumDef_Name(const upb_EnumDef* e) { + return _upb_DefBuilder_FullToShort(e->full_name); } -const upb_MiniTable* upb_MessageDef_MiniTable(const upb_MessageDef* m) { - return m->layout; -} +const upb_FileDef* upb_EnumDef_File(const upb_EnumDef* e) { return e->file; } -const upb_ExtensionRange* upb_MessageDef_ExtensionRange(const upb_MessageDef* m, - int i) { - UPB_ASSERT(0 <= i && i < m->ext_range_count); - return _upb_ExtensionRange_At(m->ext_ranges, i); +const upb_MessageDef* upb_EnumDef_ContainingType(const upb_EnumDef* e) { + return e->containing_type; } -const upb_MessageReservedRange* upb_MessageDef_ReservedRange( - const upb_MessageDef* m, int i) { - UPB_ASSERT(0 <= i && i < m->res_range_count); - return _upb_MessageReservedRange_At(m->res_ranges, i); +int32_t upb_EnumDef_Default(const upb_EnumDef* e) { + UPB_ASSERT(upb_EnumDef_FindValueByNumber(e, e->defaultval)); + return e->defaultval; } -upb_StringView upb_MessageDef_ReservedName(const upb_MessageDef* m, int i) { - UPB_ASSERT(0 <= i && i < m->res_name_count); - return m->res_names[i]; +int upb_EnumDef_ReservedRangeCount(const upb_EnumDef* e) { + return e->res_range_count; } -const upb_FieldDef* upb_MessageDef_Field(const upb_MessageDef* m, int i) { - UPB_ASSERT(0 <= i && i < m->field_count); - return _upb_FieldDef_At(m->fields, i); +const upb_EnumReservedRange* upb_EnumDef_ReservedRange(const upb_EnumDef* e, + int i) { + UPB_ASSERT(0 <= i && i < e->res_range_count); + return _upb_EnumReservedRange_At(e->res_ranges, i); } -const upb_OneofDef* upb_MessageDef_Oneof(const upb_MessageDef* m, int i) { - UPB_ASSERT(0 <= i && i < m->oneof_count); - return _upb_OneofDef_At(m->oneofs, i); +int upb_EnumDef_ReservedNameCount(const upb_EnumDef* e) { + return e->res_name_count; } -const upb_MessageDef* upb_MessageDef_NestedMessage(const upb_MessageDef* m, - int i) { - UPB_ASSERT(0 <= i && i < m->nested_msg_count); - return &m->nested_msgs[i]; +upb_StringView upb_EnumDef_ReservedName(const upb_EnumDef* e, int i) { + UPB_ASSERT(0 <= i && i < e->res_name_count); + return e->res_names[i]; } -const upb_EnumDef* upb_MessageDef_NestedEnum(const upb_MessageDef* m, int i) { - UPB_ASSERT(0 <= i && i < m->nested_enum_count); - return _upb_EnumDef_At(m->nested_enums, i); -} +int upb_EnumDef_ValueCount(const upb_EnumDef* e) { return e->value_count; } -const upb_FieldDef* upb_MessageDef_NestedExtension(const upb_MessageDef* m, - int i) { - UPB_ASSERT(0 <= i && i < m->nested_ext_count); - return _upb_FieldDef_At(m->nested_exts, i); +const upb_EnumValueDef* upb_EnumDef_FindValueByName(const upb_EnumDef* e, + const char* name) { + return upb_EnumDef_FindValueByNameWithSize(e, name, strlen(name)); } -upb_WellKnown upb_MessageDef_WellKnownType(const upb_MessageDef* m) { - return m->well_known_type; +const upb_EnumValueDef* upb_EnumDef_FindValueByNameWithSize( + const upb_EnumDef* e, const char* name, size_t size) { + upb_value v; + return upb_strtable_lookup2(&e->ntoi, name, size, &v) + ? upb_value_getconstptr(v) + : NULL; } -bool _upb_MessageDef_InMessageSet(const upb_MessageDef* m) { - return m->in_message_set; +const upb_EnumValueDef* upb_EnumDef_FindValueByNumber(const upb_EnumDef* e, + int32_t num) { + upb_value v; + return upb_inttable_lookup(&e->iton, num, &v) ? upb_value_getconstptr(v) + : NULL; } -const upb_FieldDef* upb_MessageDef_FindFieldByName(const upb_MessageDef* m, - const char* name) { - return upb_MessageDef_FindFieldByNameWithSize(m, name, strlen(name)); +bool upb_EnumDef_CheckNumber(const upb_EnumDef* e, int32_t num) { + // We could use upb_EnumDef_FindValueByNumber(e, num) != NULL, but we expect + // this to be faster (especially for small numbers). + return upb_MiniTableEnum_CheckValue(e->layout, num); } -const upb_OneofDef* upb_MessageDef_FindOneofByName(const upb_MessageDef* m, - const char* name) { - return upb_MessageDef_FindOneofByNameWithSize(m, name, strlen(name)); +const upb_EnumValueDef* upb_EnumDef_Value(const upb_EnumDef* e, int i) { + UPB_ASSERT(0 <= i && i < e->value_count); + return _upb_EnumValueDef_At(e->values, i); } -bool upb_MessageDef_IsMapEntry(const upb_MessageDef* m) { - return UPB_DESC(MessageOptions_map_entry)(m->opts); +bool upb_EnumDef_IsClosed(const upb_EnumDef* e) { + if (UPB_TREAT_PROTO2_ENUMS_LIKE_PROTO3) return false; + return UPB_DESC(FeatureSet_enum_type)(e->resolved_features) == + UPB_DESC(FeatureSet_CLOSED); } -bool upb_MessageDef_IsMessageSet(const upb_MessageDef* m) { - return UPB_DESC(MessageOptions_message_set_wire_format)(m->opts); -} +bool upb_EnumDef_MiniDescriptorEncode(const upb_EnumDef* e, upb_Arena* a, + upb_StringView* out) { + upb_DescState s; + _upb_DescState_Init(&s); -static upb_MiniTable* _upb_MessageDef_MakeMiniTable(upb_DefBuilder* ctx, - const upb_MessageDef* m) { - upb_StringView desc; - // Note: this will assign layout_index for fields, so upb_FieldDef_MiniTable() - // is safe to call only after this call. - bool ok = upb_MessageDef_MiniDescriptorEncode(m, ctx->tmp_arena, &desc); - if (!ok) _upb_DefBuilder_OomErr(ctx); + const upb_EnumValueDef** sorted = NULL; + if (!e->is_sorted) { + sorted = _upb_EnumValueDefs_Sorted(e->values, e->value_count, a); + if (!sorted) return false; + } - void** scratch_data = _upb_DefPool_ScratchData(ctx->symtab); - size_t* scratch_size = _upb_DefPool_ScratchSize(ctx->symtab); - upb_MiniTable* ret = upb_MiniTable_BuildWithBuf( - desc.data, desc.size, ctx->platform, ctx->arena, scratch_data, - scratch_size, ctx->status); - if (!ret) _upb_DefBuilder_FailJmp(ctx); + if (!_upb_DescState_Grow(&s, a)) return false; + s.ptr = upb_MtDataEncoder_StartEnum(&s.e, s.ptr); - return ret; -} + // Duplicate values are allowed but we only encode each value once. + uint32_t previous = 0; -void _upb_MessageDef_Resolve(upb_DefBuilder* ctx, upb_MessageDef* m) { - for (int i = 0; i < m->field_count; i++) { - upb_FieldDef* f = (upb_FieldDef*)upb_MessageDef_Field(m, i); - _upb_FieldDef_Resolve(ctx, m->full_name, f); - } + for (int i = 0; i < e->value_count; i++) { + const uint32_t current = + upb_EnumValueDef_Number(sorted ? sorted[i] : upb_EnumDef_Value(e, i)); + if (i != 0 && previous == current) continue; - m->in_message_set = false; - for (int i = 0; i < upb_MessageDef_NestedExtensionCount(m); i++) { - upb_FieldDef* ext = (upb_FieldDef*)upb_MessageDef_NestedExtension(m, i); - _upb_FieldDef_Resolve(ctx, m->full_name, ext); - if (upb_FieldDef_Type(ext) == kUpb_FieldType_Message && - upb_FieldDef_Label(ext) == kUpb_Label_Optional && - upb_FieldDef_MessageSubDef(ext) == m && - UPB_DESC(MessageOptions_message_set_wire_format)( - upb_MessageDef_Options(upb_FieldDef_ContainingType(ext)))) { - m->in_message_set = true; - } + if (!_upb_DescState_Grow(&s, a)) return false; + s.ptr = upb_MtDataEncoder_PutEnumValue(&s.e, s.ptr, current); + previous = current; } - for (int i = 0; i < upb_MessageDef_NestedMessageCount(m); i++) { - upb_MessageDef* n = (upb_MessageDef*)upb_MessageDef_NestedMessage(m, i); - _upb_MessageDef_Resolve(ctx, n); - } -} + if (!_upb_DescState_Grow(&s, a)) return false; + s.ptr = upb_MtDataEncoder_EndEnum(&s.e, s.ptr); -void _upb_MessageDef_InsertField(upb_DefBuilder* ctx, upb_MessageDef* m, - const upb_FieldDef* f) { - const int32_t field_number = upb_FieldDef_Number(f); + // There will always be room for this '\0' in the encoder buffer because + // kUpb_MtDataEncoder_MinSize is overkill for upb_MtDataEncoder_EndEnum(). + UPB_ASSERT(s.ptr < s.buf + s.bufsize); + *s.ptr = '\0'; - if (field_number <= 0 || field_number > kUpb_MaxFieldNumber) { - _upb_DefBuilder_Errf(ctx, "invalid field number (%u)", field_number); - } + out->data = s.buf; + out->size = s.ptr - s.buf; + return true; +} - const char* json_name = upb_FieldDef_JsonName(f); - const char* shortname = upb_FieldDef_Name(f); - const size_t shortnamelen = strlen(shortname); +static upb_MiniTableEnum* create_enumlayout(upb_DefBuilder* ctx, + const upb_EnumDef* e) { + upb_StringView sv; + bool ok = upb_EnumDef_MiniDescriptorEncode(e, ctx->tmp_arena, &sv); + if (!ok) _upb_DefBuilder_Errf(ctx, "OOM while building enum MiniDescriptor"); - upb_value v = upb_value_constptr(f); + upb_Status status; + upb_MiniTableEnum* layout = + upb_MiniTableEnum_Build(sv.data, sv.size, ctx->arena, &status); + if (!layout) + _upb_DefBuilder_Errf(ctx, "Error building enum MiniTable: %s", status.msg); + return layout; +} - upb_value existing_v; - if (upb_strtable_lookup(&m->ntof, shortname, &existing_v)) { - _upb_DefBuilder_Errf(ctx, "duplicate field name (%s)", shortname); +static upb_StringView* _upb_EnumReservedNames_New( + upb_DefBuilder* ctx, int n, const upb_StringView* protos) { + upb_StringView* sv = _upb_DefBuilder_Alloc(ctx, sizeof(upb_StringView) * n); + for (int i = 0; i < n; i++) { + sv[i].data = + upb_strdup2(protos[i].data, protos[i].size, _upb_DefBuilder_Arena(ctx)); + sv[i].size = protos[i].size; } + return sv; +} - const upb_value field_v = _upb_DefType_Pack(f, UPB_DEFTYPE_FIELD); - bool ok = - _upb_MessageDef_Insert(m, shortname, shortnamelen, field_v, ctx->arena); - if (!ok) _upb_DefBuilder_OomErr(ctx); +static void create_enumdef(upb_DefBuilder* ctx, const char* prefix, + const UPB_DESC(EnumDescriptorProto) * enum_proto, + const UPB_DESC(FeatureSet*) parent_features, + upb_EnumDef* e) { + const UPB_DESC(EnumValueDescriptorProto)* const* values; + const UPB_DESC(EnumDescriptorProto_EnumReservedRange)* const* res_ranges; + const upb_StringView* res_names; + upb_StringView name; + size_t n_value, n_res_range, n_res_name; - if (strcmp(shortname, json_name) != 0 && - UPB_DESC(FeatureSet_json_format)(m->resolved_features) == - UPB_DESC(FeatureSet_ALLOW) && - upb_strtable_lookup(&m->ntof, json_name, &v)) { - _upb_DefBuilder_Errf( - ctx, "duplicate json_name for (%s) with original field name (%s)", - shortname, json_name); - } + UPB_DEF_SET_OPTIONS(e->opts, EnumDescriptorProto, EnumOptions, enum_proto); + e->resolved_features = _upb_DefBuilder_ResolveFeatures( + ctx, parent_features, UPB_DESC(EnumOptions_features)(e->opts)); - if (upb_strtable_lookup(&m->jtof, json_name, &v)) { - _upb_DefBuilder_Errf(ctx, "duplicate json_name (%s)", json_name); - } + // Must happen before _upb_DefBuilder_Add() + e->file = _upb_DefBuilder_File(ctx); - const size_t json_size = strlen(json_name); - ok = upb_strtable_insert(&m->jtof, json_name, json_size, - upb_value_constptr(f), ctx->arena); - if (!ok) _upb_DefBuilder_OomErr(ctx); + name = UPB_DESC(EnumDescriptorProto_name)(enum_proto); - if (upb_inttable_lookup(&m->itof, field_number, NULL)) { - _upb_DefBuilder_Errf(ctx, "duplicate field number (%u)", field_number); - } + e->full_name = _upb_DefBuilder_MakeFullName(ctx, prefix, name); + _upb_DefBuilder_Add(ctx, e->full_name, + _upb_DefType_Pack(e, UPB_DEFTYPE_ENUM)); - ok = upb_inttable_insert(&m->itof, field_number, v, ctx->arena); - if (!ok) _upb_DefBuilder_OomErr(ctx); -} + values = UPB_DESC(EnumDescriptorProto_value)(enum_proto, &n_value); -void _upb_MessageDef_CreateMiniTable(upb_DefBuilder* ctx, upb_MessageDef* m) { - if (ctx->layout == NULL) { - m->layout = _upb_MessageDef_MakeMiniTable(ctx, m); - } else { - m->layout = upb_MiniTableFile_Message(ctx->layout, ctx->msg_count++); - UPB_ASSERT(m->field_count == m->layout->UPB_PRIVATE(field_count)); + bool ok = upb_strtable_init(&e->ntoi, n_value, ctx->arena); + if (!ok) _upb_DefBuilder_OomErr(ctx); - // We don't need the result of this call, but it will assign layout_index - // for all the fields in O(n lg n) time. - _upb_FieldDefs_Sorted(m->fields, m->field_count, ctx->tmp_arena); - } + ok = upb_inttable_init(&e->iton, ctx->arena); + if (!ok) _upb_DefBuilder_OomErr(ctx); - for (int i = 0; i < m->nested_msg_count; i++) { - upb_MessageDef* nested = - (upb_MessageDef*)upb_MessageDef_NestedMessage(m, i); - _upb_MessageDef_CreateMiniTable(ctx, nested); - } -} + e->defaultval = 0; + e->value_count = n_value; + e->values = _upb_EnumValueDefs_New(ctx, prefix, n_value, values, + e->resolved_features, e, &e->is_sorted); -void _upb_MessageDef_LinkMiniTable(upb_DefBuilder* ctx, - const upb_MessageDef* m) { - for (int i = 0; i < upb_MessageDef_NestedExtensionCount(m); i++) { - const upb_FieldDef* ext = upb_MessageDef_NestedExtension(m, i); - _upb_FieldDef_BuildMiniTableExtension(ctx, ext); + if (n_value == 0) { + _upb_DefBuilder_Errf(ctx, "enums must contain at least one value (%s)", + e->full_name); } - for (int i = 0; i < m->nested_msg_count; i++) { - _upb_MessageDef_LinkMiniTable(ctx, upb_MessageDef_NestedMessage(m, i)); - } + res_ranges = + UPB_DESC(EnumDescriptorProto_reserved_range)(enum_proto, &n_res_range); + e->res_range_count = n_res_range; + e->res_ranges = _upb_EnumReservedRanges_New(ctx, n_res_range, res_ranges, e); - if (ctx->layout) return; + res_names = + UPB_DESC(EnumDescriptorProto_reserved_name)(enum_proto, &n_res_name); + e->res_name_count = n_res_name; + e->res_names = _upb_EnumReservedNames_New(ctx, n_res_name, res_names); - for (int i = 0; i < m->field_count; i++) { - const upb_FieldDef* f = upb_MessageDef_Field(m, i); - const upb_MessageDef* sub_m = upb_FieldDef_MessageSubDef(f); - const upb_EnumDef* sub_e = upb_FieldDef_EnumSubDef(f); - const int layout_index = _upb_FieldDef_LayoutIndex(f); - upb_MiniTable* mt = (upb_MiniTable*)upb_MessageDef_MiniTable(m); + upb_inttable_compact(&e->iton, ctx->arena); - UPB_ASSERT(layout_index < m->field_count); - upb_MiniTableField* mt_f = - (upb_MiniTableField*)&m->layout->UPB_PRIVATE(fields)[layout_index]; - if (sub_m) { - if (!mt->UPB_PRIVATE(subs)) { - _upb_DefBuilder_Errf(ctx, "unexpected submsg for (%s)", m->full_name); - } - UPB_ASSERT(mt_f); - UPB_ASSERT(sub_m->layout); - if (UPB_UNLIKELY(!upb_MiniTable_SetSubMessage(mt, mt_f, sub_m->layout))) { - _upb_DefBuilder_Errf(ctx, "invalid submsg for (%s)", m->full_name); - } - } else if (_upb_FieldDef_IsClosedEnum(f)) { - const upb_MiniTableEnum* mt_e = _upb_EnumDef_MiniTable(sub_e); - if (UPB_UNLIKELY(!upb_MiniTable_SetSubEnum(mt, mt_f, mt_e))) { - _upb_DefBuilder_Errf(ctx, "invalid subenum for (%s)", m->full_name); - } + if (upb_EnumDef_IsClosed(e)) { + if (ctx->layout) { + e->layout = upb_MiniTableFile_Enum(ctx->layout, ctx->enum_count++); + } else { + e->layout = create_enumlayout(ctx, e); } + } else { + e->layout = NULL; } - -#ifndef NDEBUG - for (int i = 0; i < m->field_count; i++) { - const upb_FieldDef* f = upb_MessageDef_Field(m, i); - const int layout_index = _upb_FieldDef_LayoutIndex(f); - UPB_ASSERT(layout_index < m->layout->UPB_PRIVATE(field_count)); - const upb_MiniTableField* mt_f = - &m->layout->UPB_PRIVATE(fields)[layout_index]; - UPB_ASSERT(upb_FieldDef_Type(f) == upb_MiniTableField_Type(mt_f)); - UPB_ASSERT(upb_FieldDef_CType(f) == upb_MiniTableField_CType(mt_f)); - UPB_ASSERT(upb_FieldDef_HasPresence(f) == - upb_MiniTableField_HasPresence(mt_f)); - } -#endif } -static bool _upb_MessageDef_ValidateUtf8(const upb_MessageDef* m) { - bool has_string = false; - for (int i = 0; i < m->field_count; i++) { - const upb_FieldDef* f = upb_MessageDef_Field(m, i); - // Old binaries do not recognize the field-level "FlipValidateUtf8" wire - // modifier, so we do not actually have field-level control for old - // binaries. Given this, we judge that the better failure mode is to be - // more lax than intended, rather than more strict. To achieve this, we - // only mark the message with the ValidateUtf8 modifier if *all* fields - // validate UTF-8. - if (!_upb_FieldDef_ValidateUtf8(f)) return false; - if (upb_FieldDef_Type(f) == kUpb_FieldType_String) has_string = true; +upb_EnumDef* _upb_EnumDefs_New(upb_DefBuilder* ctx, int n, + const UPB_DESC(EnumDescriptorProto*) + const* protos, + const UPB_DESC(FeatureSet*) parent_features, + const upb_MessageDef* containing_type) { + _upb_DefType_CheckPadding(sizeof(upb_EnumDef)); + + // If a containing type is defined then get the full name from that. + // Otherwise use the package name from the file def. + const char* name = containing_type ? upb_MessageDef_FullName(containing_type) + : _upb_FileDef_RawPackage(ctx->file); + + upb_EnumDef* e = _upb_DefBuilder_Alloc(ctx, sizeof(upb_EnumDef) * n); + for (int i = 0; i < n; i++) { + create_enumdef(ctx, name, protos[i], parent_features, &e[i]); + e[i].containing_type = containing_type; } - return has_string; + return e; } -static uint64_t _upb_MessageDef_Modifiers(const upb_MessageDef* m) { - uint64_t out = 0; - if (UPB_DESC(FeatureSet_repeated_field_encoding(m->resolved_features)) == - UPB_DESC(FeatureSet_PACKED)) { - out |= kUpb_MessageModifier_DefaultIsPacked; - } - if (_upb_MessageDef_ValidateUtf8(m)) { - out |= kUpb_MessageModifier_ValidateUtf8; - } +// Must be last. - if (m->ext_range_count) { - out |= kUpb_MessageModifier_IsExtendable; - } +struct upb_EnumReservedRange { + int32_t start; + int32_t end; +}; - return out; +upb_EnumReservedRange* _upb_EnumReservedRange_At(const upb_EnumReservedRange* r, + int i) { + return (upb_EnumReservedRange*)&r[i]; } -static bool _upb_MessageDef_EncodeMap(upb_DescState* s, const upb_MessageDef* m, - upb_Arena* a) { - if (m->field_count != 2) return false; +int32_t upb_EnumReservedRange_Start(const upb_EnumReservedRange* r) { + return r->start; +} +int32_t upb_EnumReservedRange_End(const upb_EnumReservedRange* r) { + return r->end; +} - const upb_FieldDef* key_field = upb_MessageDef_Field(m, 0); - const upb_FieldDef* val_field = upb_MessageDef_Field(m, 1); - if (key_field == NULL || val_field == NULL) return false; +upb_EnumReservedRange* _upb_EnumReservedRanges_New( + upb_DefBuilder* ctx, int n, + const UPB_DESC(EnumDescriptorProto_EnumReservedRange) * const* protos, + const upb_EnumDef* e) { + upb_EnumReservedRange* r = + _upb_DefBuilder_Alloc(ctx, sizeof(upb_EnumReservedRange) * n); - UPB_ASSERT(_upb_FieldDef_LayoutIndex(key_field) == 0); - UPB_ASSERT(_upb_FieldDef_LayoutIndex(val_field) == 1); + for (int i = 0; i < n; i++) { + const int32_t start = + UPB_DESC(EnumDescriptorProto_EnumReservedRange_start)(protos[i]); + const int32_t end = + UPB_DESC(EnumDescriptorProto_EnumReservedRange_end)(protos[i]); - s->ptr = upb_MtDataEncoder_EncodeMap( - &s->e, s->ptr, upb_FieldDef_Type(key_field), upb_FieldDef_Type(val_field), - _upb_FieldDef_Modifiers(key_field), _upb_FieldDef_Modifiers(val_field)); - return true; -} + // A full validation would also check that each range is disjoint, and that + // none of the fields overlap with the extension ranges, but we are just + // sanity checking here. -static bool _upb_MessageDef_EncodeMessage(upb_DescState* s, - const upb_MessageDef* m, - upb_Arena* a) { - const upb_FieldDef** sorted = NULL; - if (!m->is_sorted) { - sorted = _upb_FieldDefs_Sorted(m->fields, m->field_count, a); - if (!sorted) return false; + // Note: Not a typo! Unlike extension ranges and message reserved ranges, + // the end value of an enum reserved range is *inclusive*! + if (end < start) { + _upb_DefBuilder_Errf(ctx, "Reserved range (%d, %d) is invalid, enum=%s\n", + (int)start, (int)end, upb_EnumDef_FullName(e)); + } + + r[i].start = start; + r[i].end = end; } - s->ptr = upb_MtDataEncoder_StartMessage(&s->e, s->ptr, - _upb_MessageDef_Modifiers(m)); + return r; +} - for (int i = 0; i < m->field_count; i++) { - const upb_FieldDef* f = sorted ? sorted[i] : upb_MessageDef_Field(m, i); - const upb_FieldType type = upb_FieldDef_Type(f); - const int number = upb_FieldDef_Number(f); - const uint64_t modifiers = _upb_FieldDef_Modifiers(f); - if (!_upb_DescState_Grow(s, a)) return false; - s->ptr = upb_MtDataEncoder_PutField(&s->e, s->ptr, type, number, modifiers); - } +#include - for (int i = 0; i < m->real_oneof_count; i++) { - if (!_upb_DescState_Grow(s, a)) return false; - s->ptr = upb_MtDataEncoder_StartOneof(&s->e, s->ptr); - const upb_OneofDef* o = upb_MessageDef_Oneof(m, i); - const int field_count = upb_OneofDef_FieldCount(o); - for (int j = 0; j < field_count; j++) { - const int number = upb_FieldDef_Number(upb_OneofDef_Field(o, j)); +// Must be last. - if (!_upb_DescState_Grow(s, a)) return false; - s->ptr = upb_MtDataEncoder_PutOneofField(&s->e, s->ptr, number); - } - } +struct upb_EnumValueDef { + const UPB_DESC(EnumValueOptions*) opts; + const UPB_DESC(FeatureSet*) resolved_features; + const upb_EnumDef* parent; + const char* full_name; + int32_t number; +#if UINTPTR_MAX == 0xffffffff + uint32_t padding; // Increase size to a multiple of 8. +#endif +}; - return true; +upb_EnumValueDef* _upb_EnumValueDef_At(const upb_EnumValueDef* v, int i) { + return (upb_EnumValueDef*)&v[i]; } -static bool _upb_MessageDef_EncodeMessageSet(upb_DescState* s, - const upb_MessageDef* m, - upb_Arena* a) { - s->ptr = upb_MtDataEncoder_EncodeMessageSet(&s->e, s->ptr); - - return true; +static int _upb_EnumValueDef_Compare(const void* p1, const void* p2) { + const uint32_t v1 = (*(const upb_EnumValueDef**)p1)->number; + const uint32_t v2 = (*(const upb_EnumValueDef**)p2)->number; + return (v1 < v2) ? -1 : (v1 > v2); } -bool upb_MessageDef_MiniDescriptorEncode(const upb_MessageDef* m, upb_Arena* a, - upb_StringView* out) { - upb_DescState s; - _upb_DescState_Init(&s); - - if (!_upb_DescState_Grow(&s, a)) return false; +const upb_EnumValueDef** _upb_EnumValueDefs_Sorted(const upb_EnumValueDef* v, + int n, upb_Arena* a) { + // TODO: Try to replace this arena alloc with a persistent scratch buffer. + upb_EnumValueDef** out = + (upb_EnumValueDef**)upb_Arena_Malloc(a, n * sizeof(void*)); + if (!out) return NULL; - if (upb_MessageDef_IsMapEntry(m)) { - if (!_upb_MessageDef_EncodeMap(&s, m, a)) return false; - } else if (UPB_DESC(MessageOptions_message_set_wire_format)(m->opts)) { - if (!_upb_MessageDef_EncodeMessageSet(&s, m, a)) return false; - } else { - if (!_upb_MessageDef_EncodeMessage(&s, m, a)) return false; + for (int i = 0; i < n; i++) { + out[i] = (upb_EnumValueDef*)&v[i]; } + qsort(out, n, sizeof(void*), _upb_EnumValueDef_Compare); - if (!_upb_DescState_Grow(&s, a)) return false; - *s.ptr = '\0'; + return (const upb_EnumValueDef**)out; +} - out->data = s.buf; - out->size = s.ptr - s.buf; - return true; +const UPB_DESC(EnumValueOptions) * + upb_EnumValueDef_Options(const upb_EnumValueDef* v) { + return v->opts; } -static upb_StringView* _upb_ReservedNames_New(upb_DefBuilder* ctx, int n, - const upb_StringView* protos) { - upb_StringView* sv = _upb_DefBuilder_Alloc(ctx, sizeof(upb_StringView) * n); - for (int i = 0; i < n; i++) { - sv[i].data = - upb_strdup2(protos[i].data, protos[i].size, _upb_DefBuilder_Arena(ctx)); - sv[i].size = protos[i].size; - } - return sv; +bool upb_EnumValueDef_HasOptions(const upb_EnumValueDef* v) { + return v->opts != (void*)kUpbDefOptDefault; } -static void create_msgdef(upb_DefBuilder* ctx, const char* prefix, - const UPB_DESC(DescriptorProto*) msg_proto, - const UPB_DESC(FeatureSet*) parent_features, - const upb_MessageDef* containing_type, - upb_MessageDef* m) { - const UPB_DESC(OneofDescriptorProto)* const* oneofs; - const UPB_DESC(FieldDescriptorProto)* const* fields; - const UPB_DESC(DescriptorProto_ExtensionRange)* const* ext_ranges; - const UPB_DESC(DescriptorProto_ReservedRange)* const* res_ranges; - const upb_StringView* res_names; - size_t n_oneof, n_field, n_enum, n_ext, n_msg; - size_t n_ext_range, n_res_range, n_res_name; - upb_StringView name; +const UPB_DESC(FeatureSet) * + upb_EnumValueDef_ResolvedFeatures(const upb_EnumValueDef* e) { + return e->resolved_features; +} - UPB_DEF_SET_OPTIONS(m->opts, DescriptorProto, MessageOptions, msg_proto); - m->resolved_features = _upb_DefBuilder_ResolveFeatures( - ctx, parent_features, UPB_DESC(MessageOptions_features)(m->opts)); +const upb_EnumDef* upb_EnumValueDef_Enum(const upb_EnumValueDef* v) { + return v->parent; +} - // Must happen before _upb_DefBuilder_Add() - m->file = _upb_DefBuilder_File(ctx); +const char* upb_EnumValueDef_FullName(const upb_EnumValueDef* v) { + return v->full_name; +} - m->containing_type = containing_type; - m->is_sorted = true; +const char* upb_EnumValueDef_Name(const upb_EnumValueDef* v) { + return _upb_DefBuilder_FullToShort(v->full_name); +} - name = UPB_DESC(DescriptorProto_name)(msg_proto); +int32_t upb_EnumValueDef_Number(const upb_EnumValueDef* v) { return v->number; } - m->full_name = _upb_DefBuilder_MakeFullName(ctx, prefix, name); - _upb_DefBuilder_Add(ctx, m->full_name, _upb_DefType_Pack(m, UPB_DEFTYPE_MSG)); +uint32_t upb_EnumValueDef_Index(const upb_EnumValueDef* v) { + // Compute index in our parent's array. + return v - upb_EnumDef_Value(v->parent, 0); +} - oneofs = UPB_DESC(DescriptorProto_oneof_decl)(msg_proto, &n_oneof); - fields = UPB_DESC(DescriptorProto_field)(msg_proto, &n_field); - ext_ranges = - UPB_DESC(DescriptorProto_extension_range)(msg_proto, &n_ext_range); - res_ranges = - UPB_DESC(DescriptorProto_reserved_range)(msg_proto, &n_res_range); - res_names = UPB_DESC(DescriptorProto_reserved_name)(msg_proto, &n_res_name); +static void create_enumvaldef(upb_DefBuilder* ctx, const char* prefix, + const UPB_DESC(EnumValueDescriptorProto*) + val_proto, + const UPB_DESC(FeatureSet*) parent_features, + upb_EnumDef* e, upb_EnumValueDef* v) { + UPB_DEF_SET_OPTIONS(v->opts, EnumValueDescriptorProto, EnumValueOptions, + val_proto); + v->resolved_features = _upb_DefBuilder_ResolveFeatures( + ctx, parent_features, UPB_DESC(EnumValueOptions_features)(v->opts)); - bool ok = upb_inttable_init(&m->itof, ctx->arena); - if (!ok) _upb_DefBuilder_OomErr(ctx); + upb_StringView name = UPB_DESC(EnumValueDescriptorProto_name)(val_proto); - ok = upb_strtable_init(&m->ntof, n_oneof + n_field, ctx->arena); - if (!ok) _upb_DefBuilder_OomErr(ctx); + v->parent = e; // Must happen prior to _upb_DefBuilder_Add() + v->full_name = _upb_DefBuilder_MakeFullName(ctx, prefix, name); + v->number = UPB_DESC(EnumValueDescriptorProto_number)(val_proto); + _upb_DefBuilder_Add(ctx, v->full_name, + _upb_DefType_Pack(v, UPB_DEFTYPE_ENUMVAL)); - ok = upb_strtable_init(&m->jtof, n_field, ctx->arena); + bool ok = _upb_EnumDef_Insert(e, v, ctx->arena); if (!ok) _upb_DefBuilder_OomErr(ctx); +} - m->oneof_count = n_oneof; - m->oneofs = _upb_OneofDefs_New(ctx, n_oneof, oneofs, m->resolved_features, m); - - m->field_count = n_field; - m->fields = _upb_FieldDefs_New(ctx, n_field, fields, m->resolved_features, - m->full_name, m, &m->is_sorted); +static void _upb_EnumValueDef_CheckZeroValue(upb_DefBuilder* ctx, + const upb_EnumDef* e, + const upb_EnumValueDef* v, int n) { + if (upb_EnumDef_IsClosed(e) || n == 0 || v[0].number == 0) return; - // Message Sets may not contain fields. - if (UPB_UNLIKELY(UPB_DESC(MessageOptions_message_set_wire_format)(m->opts))) { - if (UPB_UNLIKELY(n_field > 0)) { - _upb_DefBuilder_Errf(ctx, "invalid message set (%s)", m->full_name); - } + // When the special UPB_TREAT_PROTO2_ENUMS_LIKE_PROTO3 is enabled, we have to + // exempt proto2 enums from this check, even when we are treating them as + // open. + if (UPB_TREAT_PROTO2_ENUMS_LIKE_PROTO3 && + upb_FileDef_Syntax(upb_EnumDef_File(e)) == kUpb_Syntax_Proto2) { + return; } - m->ext_range_count = n_ext_range; - m->ext_ranges = _upb_ExtensionRanges_New(ctx, n_ext_range, ext_ranges, - m->resolved_features, m); - - m->res_range_count = n_res_range; - m->res_ranges = - _upb_MessageReservedRanges_New(ctx, n_res_range, res_ranges, m); + _upb_DefBuilder_Errf(ctx, "for open enums, the first value must be zero (%s)", + upb_EnumDef_FullName(e)); +} - m->res_name_count = n_res_name; - m->res_names = _upb_ReservedNames_New(ctx, n_res_name, res_names); +// Allocate and initialize an array of |n| enum value defs owned by |e|. +upb_EnumValueDef* _upb_EnumValueDefs_New( + upb_DefBuilder* ctx, const char* prefix, int n, + const UPB_DESC(EnumValueDescriptorProto*) const* protos, + const UPB_DESC(FeatureSet*) parent_features, upb_EnumDef* e, + bool* is_sorted) { + _upb_DefType_CheckPadding(sizeof(upb_EnumValueDef)); - const size_t synthetic_count = _upb_OneofDefs_Finalize(ctx, m); - m->real_oneof_count = m->oneof_count - synthetic_count; + upb_EnumValueDef* v = + _upb_DefBuilder_Alloc(ctx, sizeof(upb_EnumValueDef) * n); - assign_msg_wellknowntype(m); - upb_inttable_compact(&m->itof, ctx->arena); + *is_sorted = true; + uint32_t previous = 0; + for (int i = 0; i < n; i++) { + create_enumvaldef(ctx, prefix, protos[i], parent_features, e, &v[i]); - const UPB_DESC(EnumDescriptorProto)* const* enums = - UPB_DESC(DescriptorProto_enum_type)(msg_proto, &n_enum); - m->nested_enum_count = n_enum; - m->nested_enums = - _upb_EnumDefs_New(ctx, n_enum, enums, m->resolved_features, m); + const uint32_t current = v[i].number; + if (previous > current) *is_sorted = false; + previous = current; + } - const UPB_DESC(FieldDescriptorProto)* const* exts = - UPB_DESC(DescriptorProto_extension)(msg_proto, &n_ext); - m->nested_ext_count = n_ext; - m->nested_exts = _upb_Extensions_New(ctx, n_ext, exts, m->resolved_features, - m->full_name, m); + _upb_EnumValueDef_CheckZeroValue(ctx, e, v, n); - const UPB_DESC(DescriptorProto)* const* msgs = - UPB_DESC(DescriptorProto_nested_type)(msg_proto, &n_msg); - m->nested_msg_count = n_msg; - m->nested_msgs = - _upb_MessageDefs_New(ctx, n_msg, msgs, m->resolved_features, m); + return v; } -// Allocate and initialize an array of |n| message defs. -upb_MessageDef* _upb_MessageDefs_New(upb_DefBuilder* ctx, int n, - const UPB_DESC(DescriptorProto*) - const* protos, - const UPB_DESC(FeatureSet*) - parent_features, - const upb_MessageDef* containing_type) { - _upb_DefType_CheckPadding(sizeof(upb_MessageDef)); - - const char* name = containing_type ? containing_type->full_name - : _upb_FileDef_RawPackage(ctx->file); - upb_MessageDef* m = _upb_DefBuilder_Alloc(ctx, sizeof(upb_MessageDef) * n); - for (int i = 0; i < n; i++) { - create_msgdef(ctx, name, protos[i], parent_features, containing_type, - &m[i]); - } - return m; -} +#include // Must be last. -struct upb_MessageReservedRange { +struct upb_ExtensionRange { + const UPB_DESC(ExtensionRangeOptions*) opts; + const UPB_DESC(FeatureSet*) resolved_features; int32_t start; int32_t end; }; -upb_MessageReservedRange* _upb_MessageReservedRange_At( - const upb_MessageReservedRange* r, int i) { - return (upb_MessageReservedRange*)&r[i]; +upb_ExtensionRange* _upb_ExtensionRange_At(const upb_ExtensionRange* r, int i) { + return (upb_ExtensionRange*)&r[i]; } -int32_t upb_MessageReservedRange_Start(const upb_MessageReservedRange* r) { - return r->start; +const UPB_DESC(ExtensionRangeOptions) * + upb_ExtensionRange_Options(const upb_ExtensionRange* r) { + return r->opts; } -int32_t upb_MessageReservedRange_End(const upb_MessageReservedRange* r) { - return r->end; + +bool upb_ExtensionRange_HasOptions(const upb_ExtensionRange* r) { + return r->opts != (void*)kUpbDefOptDefault; } -upb_MessageReservedRange* _upb_MessageReservedRanges_New( +int32_t upb_ExtensionRange_Start(const upb_ExtensionRange* r) { + return r->start; +} + +int32_t upb_ExtensionRange_End(const upb_ExtensionRange* r) { return r->end; } + +upb_ExtensionRange* _upb_ExtensionRanges_New( upb_DefBuilder* ctx, int n, - const UPB_DESC(DescriptorProto_ReservedRange) * const* protos, - const upb_MessageDef* m) { - upb_MessageReservedRange* r = - _upb_DefBuilder_Alloc(ctx, sizeof(upb_MessageReservedRange) * n); + const UPB_DESC(DescriptorProto_ExtensionRange*) const* protos, + const UPB_DESC(FeatureSet*) parent_features, const upb_MessageDef* m) { + upb_ExtensionRange* r = + _upb_DefBuilder_Alloc(ctx, sizeof(upb_ExtensionRange) * n); + + for (int i = 0; i < n; i++) { + UPB_DEF_SET_OPTIONS(r[i].opts, DescriptorProto_ExtensionRange, + ExtensionRangeOptions, protos[i]); + r[i].resolved_features = _upb_DefBuilder_ResolveFeatures( + ctx, parent_features, + UPB_DESC(ExtensionRangeOptions_features)(r[i].opts)); - for (int i = 0; i < n; i++) { const int32_t start = - UPB_DESC(DescriptorProto_ReservedRange_start)(protos[i]); - const int32_t end = UPB_DESC(DescriptorProto_ReservedRange_end)(protos[i]); - const int32_t max = kUpb_MaxFieldNumber + 1; + UPB_DESC(DescriptorProto_ExtensionRange_start)(protos[i]); + const int32_t end = UPB_DESC(DescriptorProto_ExtensionRange_end)(protos[i]); + const int32_t max = UPB_DESC(MessageOptions_message_set_wire_format)( + upb_MessageDef_Options(m)) + ? INT32_MAX + : kUpb_MaxFieldNumber + 1; // A full validation would also check that each range is disjoint, and that // none of the fields overlap with the extension ranges, but we are just // sanity checking here. if (start < 1 || end <= start || end > max) { _upb_DefBuilder_Errf(ctx, - "Reserved range (%d, %d) is invalid, message=%s\n", + "Extension range (%d, %d) is invalid, message=%s\n", (int)start, (int)end, upb_MessageDef_FullName(m)); } @@ -11587,3865 +12251,3201 @@ upb_MessageReservedRange* _upb_MessageReservedRanges_New( } +#include +#include +#include +#include +#include +#include + // Must be last. -struct upb_MethodDef { - const UPB_DESC(MethodOptions*) opts; +#define UPB_FIELD_TYPE_UNSPECIFIED 0 + +typedef struct { + size_t len; + char str[1]; // Null-terminated string data follows. +} str_t; + +struct upb_FieldDef { + const UPB_DESC(FieldOptions*) opts; const UPB_DESC(FeatureSet*) resolved_features; - upb_ServiceDef* service; + const upb_FileDef* file; + const upb_MessageDef* msgdef; const char* full_name; - const upb_MessageDef* input_type; - const upb_MessageDef* output_type; - int index; - bool client_streaming; - bool server_streaming; + const char* json_name; + union { + int64_t sint; + uint64_t uint; + double dbl; + float flt; + bool boolean; + str_t* str; + void* msg; // Always NULL. + } defaultval; + union { + const upb_OneofDef* oneof; + const upb_MessageDef* extension_scope; + } scope; + union { + const upb_MessageDef* msgdef; + const upb_EnumDef* enumdef; + const UPB_DESC(FieldDescriptorProto) * unresolved; + } sub; + uint32_t number_; + uint16_t index_; + uint16_t layout_index; // Index into msgdef->layout->fields or file->exts + bool has_default; + bool has_json_name; + bool has_presence; + bool is_extension; + bool is_proto3_optional; + upb_FieldType type_; + upb_Label label_; }; -upb_MethodDef* _upb_MethodDef_At(const upb_MethodDef* m, int i) { - return (upb_MethodDef*)&m[i]; +upb_FieldDef* _upb_FieldDef_At(const upb_FieldDef* f, int i) { + return (upb_FieldDef*)&f[i]; } -const upb_ServiceDef* upb_MethodDef_Service(const upb_MethodDef* m) { - return m->service; +const UPB_DESC(FieldOptions) * upb_FieldDef_Options(const upb_FieldDef* f) { + return f->opts; } -const UPB_DESC(MethodOptions) * upb_MethodDef_Options(const upb_MethodDef* m) { - return m->opts; +bool upb_FieldDef_HasOptions(const upb_FieldDef* f) { + return f->opts != (void*)kUpbDefOptDefault; } -bool upb_MethodDef_HasOptions(const upb_MethodDef* m) { - return m->opts != (void*)kUpbDefOptDefault; +const UPB_DESC(FeatureSet) * + upb_FieldDef_ResolvedFeatures(const upb_FieldDef* f) { + return f->resolved_features; } -const UPB_DESC(FeatureSet) * - upb_MethodDef_ResolvedFeatures(const upb_MethodDef* m) { - return m->resolved_features; +const char* upb_FieldDef_FullName(const upb_FieldDef* f) { + return f->full_name; } -const char* upb_MethodDef_FullName(const upb_MethodDef* m) { - return m->full_name; +upb_CType upb_FieldDef_CType(const upb_FieldDef* f) { + return upb_FieldType_CType(f->type_); } -const char* upb_MethodDef_Name(const upb_MethodDef* m) { - return _upb_DefBuilder_FullToShort(m->full_name); +upb_FieldType upb_FieldDef_Type(const upb_FieldDef* f) { + // TODO: remove once we can deprecate kUpb_FieldType_Group. + if (f->type_ == kUpb_FieldType_Message && + UPB_DESC(FeatureSet_message_encoding)(f->resolved_features) == + UPB_DESC(FeatureSet_DELIMITED)) { + return kUpb_FieldType_Group; + } + return f->type_; } -int upb_MethodDef_Index(const upb_MethodDef* m) { return m->index; } +uint32_t upb_FieldDef_Index(const upb_FieldDef* f) { return f->index_; } -const upb_MessageDef* upb_MethodDef_InputType(const upb_MethodDef* m) { - return m->input_type; +upb_Label upb_FieldDef_Label(const upb_FieldDef* f) { + // TODO: remove once we can deprecate kUpb_Label_Required. + if (UPB_DESC(FeatureSet_field_presence)(f->resolved_features) == + UPB_DESC(FeatureSet_LEGACY_REQUIRED)) { + return kUpb_Label_Required; + } + return f->label_; } -const upb_MessageDef* upb_MethodDef_OutputType(const upb_MethodDef* m) { - return m->output_type; +uint32_t upb_FieldDef_Number(const upb_FieldDef* f) { return f->number_; } + +bool upb_FieldDef_IsExtension(const upb_FieldDef* f) { return f->is_extension; } + +bool _upb_FieldDef_IsPackable(const upb_FieldDef* f) { + return upb_FieldDef_IsRepeated(f) && upb_FieldDef_IsPrimitive(f); } -bool upb_MethodDef_ClientStreaming(const upb_MethodDef* m) { - return m->client_streaming; +bool upb_FieldDef_IsPacked(const upb_FieldDef* f) { + return _upb_FieldDef_IsPackable(f) && + UPB_DESC(FeatureSet_repeated_field_encoding(f->resolved_features)) == + UPB_DESC(FeatureSet_PACKED); } -bool upb_MethodDef_ServerStreaming(const upb_MethodDef* m) { - return m->server_streaming; +const char* upb_FieldDef_Name(const upb_FieldDef* f) { + return _upb_DefBuilder_FullToShort(f->full_name); } -static void create_method(upb_DefBuilder* ctx, - const UPB_DESC(MethodDescriptorProto*) method_proto, - const UPB_DESC(FeatureSet*) parent_features, - upb_ServiceDef* s, upb_MethodDef* m) { - UPB_DEF_SET_OPTIONS(m->opts, MethodDescriptorProto, MethodOptions, - method_proto); - m->resolved_features = _upb_DefBuilder_ResolveFeatures( - ctx, parent_features, UPB_DESC(MethodOptions_features)(m->opts)); +const char* upb_FieldDef_JsonName(const upb_FieldDef* f) { + return f->json_name; +} + +bool upb_FieldDef_HasJsonName(const upb_FieldDef* f) { + return f->has_json_name; +} + +const upb_FileDef* upb_FieldDef_File(const upb_FieldDef* f) { return f->file; } + +const upb_MessageDef* upb_FieldDef_ContainingType(const upb_FieldDef* f) { + return f->msgdef; +} + +const upb_MessageDef* upb_FieldDef_ExtensionScope(const upb_FieldDef* f) { + return f->is_extension ? f->scope.extension_scope : NULL; +} + +const upb_OneofDef* upb_FieldDef_ContainingOneof(const upb_FieldDef* f) { + return f->is_extension ? NULL : f->scope.oneof; +} + +const upb_OneofDef* upb_FieldDef_RealContainingOneof(const upb_FieldDef* f) { + const upb_OneofDef* oneof = upb_FieldDef_ContainingOneof(f); + if (!oneof || upb_OneofDef_IsSynthetic(oneof)) return NULL; + return oneof; +} + +upb_MessageValue upb_FieldDef_Default(const upb_FieldDef* f) { + upb_MessageValue ret; + + if (upb_FieldDef_IsRepeated(f) || upb_FieldDef_IsSubMessage(f)) { + return (upb_MessageValue){.msg_val = NULL}; + } + + switch (upb_FieldDef_CType(f)) { + case kUpb_CType_Bool: + return (upb_MessageValue){.bool_val = f->defaultval.boolean}; + case kUpb_CType_Int64: + return (upb_MessageValue){.int64_val = f->defaultval.sint}; + case kUpb_CType_UInt64: + return (upb_MessageValue){.uint64_val = f->defaultval.uint}; + case kUpb_CType_Enum: + case kUpb_CType_Int32: + return (upb_MessageValue){.int32_val = (int32_t)f->defaultval.sint}; + case kUpb_CType_UInt32: + return (upb_MessageValue){.uint32_val = (uint32_t)f->defaultval.uint}; + case kUpb_CType_Float: + return (upb_MessageValue){.float_val = f->defaultval.flt}; + case kUpb_CType_Double: + return (upb_MessageValue){.double_val = f->defaultval.dbl}; + case kUpb_CType_String: + case kUpb_CType_Bytes: { + str_t* str = f->defaultval.str; + if (str) { + return (upb_MessageValue){ + .str_val = (upb_StringView){.data = str->str, .size = str->len}}; + } else { + return (upb_MessageValue){ + .str_val = (upb_StringView){.data = NULL, .size = 0}}; + } + } + default: + UPB_UNREACHABLE(); + } + + return ret; +} + +const upb_MessageDef* upb_FieldDef_MessageSubDef(const upb_FieldDef* f) { + return upb_FieldDef_CType(f) == kUpb_CType_Message ? f->sub.msgdef : NULL; +} + +const upb_EnumDef* upb_FieldDef_EnumSubDef(const upb_FieldDef* f) { + return upb_FieldDef_CType(f) == kUpb_CType_Enum ? f->sub.enumdef : NULL; +} + +const upb_MiniTableField* upb_FieldDef_MiniTable(const upb_FieldDef* f) { + if (upb_FieldDef_IsExtension(f)) { + const upb_FileDef* file = upb_FieldDef_File(f); + return (upb_MiniTableField*)_upb_FileDef_ExtensionMiniTable( + file, f->layout_index); + } else { + const upb_MiniTable* layout = upb_MessageDef_MiniTable(f->msgdef); + return &layout->UPB_PRIVATE(fields)[f->layout_index]; + } +} + +const upb_MiniTableExtension* _upb_FieldDef_ExtensionMiniTable( + const upb_FieldDef* f) { + UPB_ASSERT(upb_FieldDef_IsExtension(f)); + const upb_FileDef* file = upb_FieldDef_File(f); + return _upb_FileDef_ExtensionMiniTable(file, f->layout_index); +} + +bool _upb_FieldDef_IsClosedEnum(const upb_FieldDef* f) { + if (f->type_ != kUpb_FieldType_Enum) return false; + return upb_EnumDef_IsClosed(f->sub.enumdef); +} + +bool _upb_FieldDef_IsProto3Optional(const upb_FieldDef* f) { + return f->is_proto3_optional; +} + +int _upb_FieldDef_LayoutIndex(const upb_FieldDef* f) { return f->layout_index; } + +bool _upb_FieldDef_ValidateUtf8(const upb_FieldDef* f) { + if (upb_FieldDef_Type(f) != kUpb_FieldType_String) return false; + return UPB_DESC(FeatureSet_utf8_validation(f->resolved_features)) == + UPB_DESC(FeatureSet_VERIFY); +} + +uint64_t _upb_FieldDef_Modifiers(const upb_FieldDef* f) { + uint64_t out = upb_FieldDef_IsPacked(f) ? kUpb_FieldModifier_IsPacked : 0; - upb_StringView name = UPB_DESC(MethodDescriptorProto_name)(method_proto); + if (upb_FieldDef_IsRepeated(f)) { + out |= kUpb_FieldModifier_IsRepeated; + } else if (upb_FieldDef_IsRequired(f)) { + out |= kUpb_FieldModifier_IsRequired; + } else if (!upb_FieldDef_HasPresence(f)) { + out |= kUpb_FieldModifier_IsProto3Singular; + } - m->service = s; - m->full_name = - _upb_DefBuilder_MakeFullName(ctx, upb_ServiceDef_FullName(s), name); - m->client_streaming = - UPB_DESC(MethodDescriptorProto_client_streaming)(method_proto); - m->server_streaming = - UPB_DESC(MethodDescriptorProto_server_streaming)(method_proto); - m->input_type = _upb_DefBuilder_Resolve( - ctx, m->full_name, m->full_name, - UPB_DESC(MethodDescriptorProto_input_type)(method_proto), - UPB_DEFTYPE_MSG); - m->output_type = _upb_DefBuilder_Resolve( - ctx, m->full_name, m->full_name, - UPB_DESC(MethodDescriptorProto_output_type)(method_proto), - UPB_DEFTYPE_MSG); -} + if (_upb_FieldDef_IsClosedEnum(f)) { + out |= kUpb_FieldModifier_IsClosedEnum; + } -// Allocate and initialize an array of |n| method defs belonging to |s|. -upb_MethodDef* _upb_MethodDefs_New(upb_DefBuilder* ctx, int n, - const UPB_DESC(MethodDescriptorProto*) - const* protos, - const UPB_DESC(FeatureSet*) parent_features, - upb_ServiceDef* s) { - upb_MethodDef* m = _upb_DefBuilder_Alloc(ctx, sizeof(upb_MethodDef) * n); - for (int i = 0; i < n; i++) { - create_method(ctx, protos[i], parent_features, s, &m[i]); - m[i].index = i; + if (_upb_FieldDef_ValidateUtf8(f)) { + out |= kUpb_FieldModifier_ValidateUtf8; } - return m; + + return out; } +bool upb_FieldDef_HasDefault(const upb_FieldDef* f) { return f->has_default; } +bool upb_FieldDef_HasPresence(const upb_FieldDef* f) { return f->has_presence; } -#include -#include -#include +bool upb_FieldDef_HasSubDef(const upb_FieldDef* f) { + return upb_FieldDef_IsSubMessage(f) || + upb_FieldDef_CType(f) == kUpb_CType_Enum; +} +bool upb_FieldDef_IsMap(const upb_FieldDef* f) { + return upb_FieldDef_IsRepeated(f) && upb_FieldDef_IsSubMessage(f) && + upb_MessageDef_IsMapEntry(upb_FieldDef_MessageSubDef(f)); +} -// Must be last. +bool upb_FieldDef_IsOptional(const upb_FieldDef* f) { + return upb_FieldDef_Label(f) == kUpb_Label_Optional; +} -struct upb_OneofDef { - const UPB_DESC(OneofOptions*) opts; - const UPB_DESC(FeatureSet*) resolved_features; - const upb_MessageDef* parent; - const char* full_name; - int field_count; - bool synthetic; - const upb_FieldDef** fields; - upb_strtable ntof; // lookup a field by name - upb_inttable itof; // lookup a field by number (index) -}; +bool upb_FieldDef_IsPrimitive(const upb_FieldDef* f) { + return !upb_FieldDef_IsString(f) && !upb_FieldDef_IsSubMessage(f); +} -upb_OneofDef* _upb_OneofDef_At(const upb_OneofDef* o, int i) { - return (upb_OneofDef*)&o[i]; +bool upb_FieldDef_IsRepeated(const upb_FieldDef* f) { + return upb_FieldDef_Label(f) == kUpb_Label_Repeated; } -const UPB_DESC(OneofOptions) * upb_OneofDef_Options(const upb_OneofDef* o) { - return o->opts; +bool upb_FieldDef_IsRequired(const upb_FieldDef* f) { + return UPB_DESC(FeatureSet_field_presence)(f->resolved_features) == + UPB_DESC(FeatureSet_LEGACY_REQUIRED); } -bool upb_OneofDef_HasOptions(const upb_OneofDef* o) { - return o->opts != (void*)kUpbDefOptDefault; +bool upb_FieldDef_IsString(const upb_FieldDef* f) { + return upb_FieldDef_CType(f) == kUpb_CType_String || + upb_FieldDef_CType(f) == kUpb_CType_Bytes; } -const UPB_DESC(FeatureSet) * - upb_OneofDef_ResolvedFeatures(const upb_OneofDef* o) { - return o->resolved_features; +bool upb_FieldDef_IsSubMessage(const upb_FieldDef* f) { + return upb_FieldDef_CType(f) == kUpb_CType_Message; } -const char* upb_OneofDef_FullName(const upb_OneofDef* o) { - return o->full_name; +static bool between(int32_t x, int32_t low, int32_t high) { + return x >= low && x <= high; } -const char* upb_OneofDef_Name(const upb_OneofDef* o) { - return _upb_DefBuilder_FullToShort(o->full_name); +bool upb_FieldDef_checklabel(int32_t label) { return between(label, 1, 3); } +bool upb_FieldDef_checktype(int32_t type) { return between(type, 1, 11); } +bool upb_FieldDef_checkintfmt(int32_t fmt) { return between(fmt, 1, 3); } + +bool upb_FieldDef_checkdescriptortype(int32_t type) { + return between(type, 1, 18); } -const upb_MessageDef* upb_OneofDef_ContainingType(const upb_OneofDef* o) { - return o->parent; +static bool streql2(const char* a, size_t n, const char* b) { + return n == strlen(b) && memcmp(a, b, n) == 0; } -int upb_OneofDef_FieldCount(const upb_OneofDef* o) { return o->field_count; } +// Implement the transformation as described in the spec: +// 1. upper case all letters after an underscore. +// 2. remove all underscores. +static char* make_json_name(const char* name, size_t size, upb_Arena* a) { + char* out = upb_Arena_Malloc(a, size + 1); // +1 is to add a trailing '\0' + if (out == NULL) return NULL; -const upb_FieldDef* upb_OneofDef_Field(const upb_OneofDef* o, int i) { - UPB_ASSERT(i < o->field_count); - return o->fields[i]; + bool ucase_next = false; + char* des = out; + for (size_t i = 0; i < size; i++) { + if (name[i] == '_') { + ucase_next = true; + } else { + *des++ = ucase_next ? toupper(name[i]) : name[i]; + ucase_next = false; + } + } + *des++ = '\0'; + return out; } -int upb_OneofDef_numfields(const upb_OneofDef* o) { return o->field_count; } - -uint32_t upb_OneofDef_Index(const upb_OneofDef* o) { - // Compute index in our parent's array. - return o - upb_MessageDef_Oneof(o->parent, 0); +static str_t* newstr(upb_DefBuilder* ctx, const char* data, size_t len) { + str_t* ret = _upb_DefBuilder_Alloc(ctx, sizeof(*ret) + len); + if (!ret) _upb_DefBuilder_OomErr(ctx); + ret->len = len; + if (len) memcpy(ret->str, data, len); + ret->str[len] = '\0'; + return ret; } -bool upb_OneofDef_IsSynthetic(const upb_OneofDef* o) { return o->synthetic; } +static str_t* unescape(upb_DefBuilder* ctx, const upb_FieldDef* f, + const char* data, size_t len) { + // Size here is an upper bound; escape sequences could ultimately shrink it. + str_t* ret = _upb_DefBuilder_Alloc(ctx, sizeof(*ret) + len); + char* dst = &ret->str[0]; + const char* src = data; + const char* end = data + len; -const upb_FieldDef* upb_OneofDef_LookupNameWithSize(const upb_OneofDef* o, - const char* name, - size_t size) { - upb_value val; - return upb_strtable_lookup2(&o->ntof, name, size, &val) - ? upb_value_getptr(val) - : NULL; + while (src < end) { + if (*src == '\\') { + src++; + *dst++ = _upb_DefBuilder_ParseEscape(ctx, f, &src, end); + } else { + *dst++ = *src++; + } + } + + ret->len = dst - &ret->str[0]; + return ret; } -const upb_FieldDef* upb_OneofDef_LookupName(const upb_OneofDef* o, - const char* name) { - return upb_OneofDef_LookupNameWithSize(o, name, strlen(name)); -} +static void parse_default(upb_DefBuilder* ctx, const char* str, size_t len, + upb_FieldDef* f) { + char* end; + char nullz[64]; + errno = 0; + + switch (upb_FieldDef_CType(f)) { + case kUpb_CType_Int32: + case kUpb_CType_Int64: + case kUpb_CType_UInt32: + case kUpb_CType_UInt64: + case kUpb_CType_Double: + case kUpb_CType_Float: + // Standard C number parsing functions expect null-terminated strings. + if (len >= sizeof(nullz) - 1) { + _upb_DefBuilder_Errf(ctx, "Default too long: %.*s", (int)len, str); + } + memcpy(nullz, str, len); + nullz[len] = '\0'; + str = nullz; + break; + default: + break; + } + + switch (upb_FieldDef_CType(f)) { + case kUpb_CType_Int32: { + long val = strtol(str, &end, 0); + if (val > INT32_MAX || val < INT32_MIN || errno == ERANGE || *end) { + goto invalid; + } + f->defaultval.sint = val; + break; + } + case kUpb_CType_Enum: { + const upb_EnumDef* e = f->sub.enumdef; + const upb_EnumValueDef* ev = + upb_EnumDef_FindValueByNameWithSize(e, str, len); + if (!ev) { + goto invalid; + } + f->defaultval.sint = upb_EnumValueDef_Number(ev); + break; + } + case kUpb_CType_Int64: { + long long val = strtoll(str, &end, 0); + if (val > INT64_MAX || val < INT64_MIN || errno == ERANGE || *end) { + goto invalid; + } + f->defaultval.sint = val; + break; + } + case kUpb_CType_UInt32: { + unsigned long val = strtoul(str, &end, 0); + if (val > UINT32_MAX || errno == ERANGE || *end) { + goto invalid; + } + f->defaultval.uint = val; + break; + } + case kUpb_CType_UInt64: { + unsigned long long val = strtoull(str, &end, 0); + if (val > UINT64_MAX || errno == ERANGE || *end) { + goto invalid; + } + f->defaultval.uint = val; + break; + } + case kUpb_CType_Double: { + double val = strtod(str, &end); + if (errno == ERANGE || *end) { + goto invalid; + } + f->defaultval.dbl = val; + break; + } + case kUpb_CType_Float: { + float val = strtof(str, &end); + if (errno == ERANGE || *end) { + goto invalid; + } + f->defaultval.flt = val; + break; + } + case kUpb_CType_Bool: { + if (streql2(str, len, "false")) { + f->defaultval.boolean = false; + } else if (streql2(str, len, "true")) { + f->defaultval.boolean = true; + } else { + goto invalid; + } + break; + } + case kUpb_CType_String: + f->defaultval.str = newstr(ctx, str, len); + break; + case kUpb_CType_Bytes: + f->defaultval.str = unescape(ctx, f, str, len); + break; + case kUpb_CType_Message: + /* Should not have a default value. */ + _upb_DefBuilder_Errf(ctx, "Message should not have a default (%s)", + upb_FieldDef_FullName(f)); + } + + return; -const upb_FieldDef* upb_OneofDef_LookupNumber(const upb_OneofDef* o, - uint32_t num) { - upb_value val; - return upb_inttable_lookup(&o->itof, num, &val) ? upb_value_getptr(val) - : NULL; +invalid: + _upb_DefBuilder_Errf(ctx, "Invalid default '%.*s' for field %s of type %d", + (int)len, str, upb_FieldDef_FullName(f), + (int)upb_FieldDef_Type(f)); } -void _upb_OneofDef_Insert(upb_DefBuilder* ctx, upb_OneofDef* o, - const upb_FieldDef* f, const char* name, - size_t size) { - o->field_count++; - if (_upb_FieldDef_IsProto3Optional(f)) o->synthetic = true; - - const int number = upb_FieldDef_Number(f); - const upb_value v = upb_value_constptr(f); - - // TODO: This lookup is unfortunate because we also perform it when - // inserting into the message's table. Unfortunately that step occurs after - // this one and moving things around could be tricky so let's leave it for - // a future refactoring. - const bool number_exists = upb_inttable_lookup(&o->itof, number, NULL); - if (UPB_UNLIKELY(number_exists)) { - _upb_DefBuilder_Errf(ctx, "oneof fields have the same number (%d)", number); - } - - // TODO: More redundant work happening here. - const bool name_exists = upb_strtable_lookup2(&o->ntof, name, size, NULL); - if (UPB_UNLIKELY(name_exists)) { - _upb_DefBuilder_Errf(ctx, "oneof fields have the same name (%.*s)", - (int)size, name); - } - - const bool ok = upb_inttable_insert(&o->itof, number, v, ctx->arena) && - upb_strtable_insert(&o->ntof, name, size, v, ctx->arena); - if (UPB_UNLIKELY(!ok)) { - _upb_DefBuilder_OomErr(ctx); +static void set_default_default(upb_DefBuilder* ctx, upb_FieldDef* f) { + switch (upb_FieldDef_CType(f)) { + case kUpb_CType_Int32: + case kUpb_CType_Int64: + f->defaultval.sint = 0; + break; + case kUpb_CType_UInt64: + case kUpb_CType_UInt32: + f->defaultval.uint = 0; + break; + case kUpb_CType_Double: + case kUpb_CType_Float: + f->defaultval.dbl = 0; + break; + case kUpb_CType_String: + case kUpb_CType_Bytes: + f->defaultval.str = newstr(ctx, NULL, 0); + break; + case kUpb_CType_Bool: + f->defaultval.boolean = false; + break; + case kUpb_CType_Enum: { + const upb_EnumValueDef* v = upb_EnumDef_Value(f->sub.enumdef, 0); + f->defaultval.sint = upb_EnumValueDef_Number(v); + break; + } + case kUpb_CType_Message: + break; } } -// Returns the synthetic count. -size_t _upb_OneofDefs_Finalize(upb_DefBuilder* ctx, upb_MessageDef* m) { - int synthetic_count = 0; - - for (int i = 0; i < upb_MessageDef_OneofCount(m); i++) { - upb_OneofDef* o = (upb_OneofDef*)upb_MessageDef_Oneof(m, i); - - if (o->synthetic && o->field_count != 1) { - _upb_DefBuilder_Errf(ctx, - "Synthetic oneofs must have one field, not %d: %s", - o->field_count, upb_OneofDef_Name(o)); - } +static bool _upb_FieldDef_InferLegacyFeatures( + upb_DefBuilder* ctx, upb_FieldDef* f, + const UPB_DESC(FieldDescriptorProto*) proto, + const UPB_DESC(FieldOptions*) options, upb_Syntax syntax, + UPB_DESC(FeatureSet*) features) { + bool ret = false; - if (o->synthetic) { - synthetic_count++; - } else if (synthetic_count != 0) { - _upb_DefBuilder_Errf( - ctx, "Synthetic oneofs must be after all other oneofs: %s", - upb_OneofDef_Name(o)); + if (UPB_DESC(FieldDescriptorProto_label)(proto) == kUpb_Label_Required) { + if (syntax == kUpb_Syntax_Proto3) { + _upb_DefBuilder_Errf(ctx, "proto3 fields cannot be required (%s)", + f->full_name); } - - o->fields = - _upb_DefBuilder_Alloc(ctx, sizeof(upb_FieldDef*) * o->field_count); - o->field_count = 0; + int val = UPB_DESC(FeatureSet_LEGACY_REQUIRED); + UPB_DESC(FeatureSet_set_field_presence(features, val)); + ret = true; } - for (int i = 0; i < upb_MessageDef_FieldCount(m); i++) { - const upb_FieldDef* f = upb_MessageDef_Field(m, i); - upb_OneofDef* o = (upb_OneofDef*)upb_FieldDef_ContainingOneof(f); - if (o) { - o->fields[o->field_count++] = f; - } + if (UPB_DESC(FieldDescriptorProto_type)(proto) == kUpb_FieldType_Group) { + int val = UPB_DESC(FeatureSet_DELIMITED); + UPB_DESC(FeatureSet_set_message_encoding(features, val)); + ret = true; } - return synthetic_count; -} - -static void create_oneofdef(upb_DefBuilder* ctx, upb_MessageDef* m, - const UPB_DESC(OneofDescriptorProto*) oneof_proto, - const UPB_DESC(FeatureSet*) parent_features, - const upb_OneofDef* _o) { - upb_OneofDef* o = (upb_OneofDef*)_o; - - UPB_DEF_SET_OPTIONS(o->opts, OneofDescriptorProto, OneofOptions, oneof_proto); - o->resolved_features = _upb_DefBuilder_ResolveFeatures( - ctx, parent_features, UPB_DESC(OneofOptions_features)(o->opts)); - - upb_StringView name = UPB_DESC(OneofDescriptorProto_name)(oneof_proto); - - o->parent = m; - o->full_name = - _upb_DefBuilder_MakeFullName(ctx, upb_MessageDef_FullName(m), name); - o->field_count = 0; - o->synthetic = false; - - if (upb_MessageDef_FindByNameWithSize(m, name.data, name.size, NULL, NULL)) { - _upb_DefBuilder_Errf(ctx, "duplicate oneof name (%s)", o->full_name); + if (UPB_DESC(FieldOptions_has_packed)(options)) { + int val = UPB_DESC(FieldOptions_packed)(options) + ? UPB_DESC(FeatureSet_PACKED) + : UPB_DESC(FeatureSet_EXPANDED); + UPB_DESC(FeatureSet_set_repeated_field_encoding(features, val)); + ret = true; } - upb_value v = _upb_DefType_Pack(o, UPB_DEFTYPE_ONEOF); - bool ok = _upb_MessageDef_Insert(m, name.data, name.size, v, ctx->arena); - if (!ok) _upb_DefBuilder_OomErr(ctx); - - ok = upb_inttable_init(&o->itof, ctx->arena); - if (!ok) _upb_DefBuilder_OomErr(ctx); +// begin:google_only +// #ifndef UPB_BOOTSTRAP_STAGE0 +// if (syntax == kUpb_Syntax_Proto3 && +// UPB_DESC(FieldOptions_has_enforce_utf8)(options) && +// !UPB_DESC(FieldOptions_enforce_utf8)(options)) { +// int val = UPB_DESC(FeatureSet_UNVERIFIED); +// UPB_DESC(FeatureSet_set_utf8_validation(features, val)); +// ret = true; +// } +// #endif +// // clang-format off +// end:google_only + // clang-format on - ok = upb_strtable_init(&o->ntof, 4, ctx->arena); - if (!ok) _upb_DefBuilder_OomErr(ctx); + return ret; } -// Allocate and initialize an array of |n| oneof defs. -upb_OneofDef* _upb_OneofDefs_New(upb_DefBuilder* ctx, int n, - const UPB_DESC(OneofDescriptorProto*) - const* protos, +static void _upb_FieldDef_Create(upb_DefBuilder* ctx, const char* prefix, const UPB_DESC(FeatureSet*) parent_features, - upb_MessageDef* m) { - _upb_DefType_CheckPadding(sizeof(upb_OneofDef)); - - upb_OneofDef* o = _upb_DefBuilder_Alloc(ctx, sizeof(upb_OneofDef) * n); - for (int i = 0; i < n; i++) { - create_oneofdef(ctx, m, protos[i], parent_features, &o[i]); - } - return o; -} - - - -// Must be last. - -struct upb_ServiceDef { - const UPB_DESC(ServiceOptions*) opts; - const UPB_DESC(FeatureSet*) resolved_features; - const upb_FileDef* file; - const char* full_name; - upb_MethodDef* methods; - int method_count; - int index; -#if UINTPTR_MAX == 0xffffffff - uint32_t padding; // Increase size to a multiple of 8. -#endif -}; + const UPB_DESC(FieldDescriptorProto*) + field_proto, + upb_MessageDef* m, upb_FieldDef* f) { + // Must happen before _upb_DefBuilder_Add() + f->file = _upb_DefBuilder_File(ctx); -upb_ServiceDef* _upb_ServiceDef_At(const upb_ServiceDef* s, int index) { - return (upb_ServiceDef*)&s[index]; -} + const upb_StringView name = UPB_DESC(FieldDescriptorProto_name)(field_proto); + f->full_name = _upb_DefBuilder_MakeFullName(ctx, prefix, name); + f->label_ = (int)UPB_DESC(FieldDescriptorProto_label)(field_proto); + f->number_ = UPB_DESC(FieldDescriptorProto_number)(field_proto); + f->is_proto3_optional = + UPB_DESC(FieldDescriptorProto_proto3_optional)(field_proto); + f->msgdef = m; + f->scope.oneof = NULL; -const UPB_DESC(ServiceOptions) * - upb_ServiceDef_Options(const upb_ServiceDef* s) { - return s->opts; -} + UPB_DEF_SET_OPTIONS(f->opts, FieldDescriptorProto, FieldOptions, field_proto); -bool upb_ServiceDef_HasOptions(const upb_ServiceDef* s) { - return s->opts != (void*)kUpbDefOptDefault; -} + upb_Syntax syntax = upb_FileDef_Syntax(f->file); + const UPB_DESC(FeatureSet*) unresolved_features = + UPB_DESC(FieldOptions_features)(f->opts); + bool implicit = false; -const UPB_DESC(FeatureSet) * - upb_ServiceDef_ResolvedFeatures(const upb_ServiceDef* s) { - return s->resolved_features; -} + if (syntax != kUpb_Syntax_Editions) { + upb_Message_Clear(UPB_UPCAST(ctx->legacy_features), + UPB_DESC_MINITABLE(FeatureSet)); + if (_upb_FieldDef_InferLegacyFeatures(ctx, f, field_proto, f->opts, syntax, + ctx->legacy_features)) { + implicit = true; + unresolved_features = ctx->legacy_features; + } + } -const char* upb_ServiceDef_FullName(const upb_ServiceDef* s) { - return s->full_name; -} + if (UPB_DESC(FieldDescriptorProto_has_oneof_index)(field_proto)) { + int oneof_index = UPB_DESC(FieldDescriptorProto_oneof_index)(field_proto); -const char* upb_ServiceDef_Name(const upb_ServiceDef* s) { - return _upb_DefBuilder_FullToShort(s->full_name); -} + if (!m) { + _upb_DefBuilder_Errf(ctx, "oneof field (%s) has no containing msg", + f->full_name); + } -int upb_ServiceDef_Index(const upb_ServiceDef* s) { return s->index; } + if (oneof_index >= upb_MessageDef_OneofCount(m)) { + _upb_DefBuilder_Errf(ctx, "oneof_index out of range (%s)", f->full_name); + } -const upb_FileDef* upb_ServiceDef_File(const upb_ServiceDef* s) { - return s->file; -} + upb_OneofDef* oneof = (upb_OneofDef*)upb_MessageDef_Oneof(m, oneof_index); + f->scope.oneof = oneof; + parent_features = upb_OneofDef_ResolvedFeatures(oneof); -int upb_ServiceDef_MethodCount(const upb_ServiceDef* s) { - return s->method_count; -} + _upb_OneofDef_Insert(ctx, oneof, f, name.data, name.size); + } -const upb_MethodDef* upb_ServiceDef_Method(const upb_ServiceDef* s, int i) { - return (i < 0 || i >= s->method_count) ? NULL - : _upb_MethodDef_At(s->methods, i); -} + f->resolved_features = _upb_DefBuilder_DoResolveFeatures( + ctx, parent_features, unresolved_features, implicit); -const upb_MethodDef* upb_ServiceDef_FindMethodByName(const upb_ServiceDef* s, - const char* name) { - for (int i = 0; i < s->method_count; i++) { - const upb_MethodDef* m = _upb_MethodDef_At(s->methods, i); - if (strcmp(name, upb_MethodDef_Name(m)) == 0) { - return m; - } + if (!UPB_DESC(FieldDescriptorProto_has_name)(field_proto)) { + _upb_DefBuilder_Errf(ctx, "field has no name"); } - return NULL; -} -static void create_service(upb_DefBuilder* ctx, - const UPB_DESC(ServiceDescriptorProto*) svc_proto, - const UPB_DESC(FeatureSet*) parent_features, - upb_ServiceDef* s) { - UPB_DEF_SET_OPTIONS(s->opts, ServiceDescriptorProto, ServiceOptions, - svc_proto); - s->resolved_features = _upb_DefBuilder_ResolveFeatures( - ctx, parent_features, UPB_DESC(ServiceOptions_features)(s->opts)); + f->has_json_name = UPB_DESC(FieldDescriptorProto_has_json_name)(field_proto); + if (f->has_json_name) { + const upb_StringView sv = + UPB_DESC(FieldDescriptorProto_json_name)(field_proto); + f->json_name = upb_strdup2(sv.data, sv.size, ctx->arena); + } else { + f->json_name = make_json_name(name.data, name.size, ctx->arena); + } + if (!f->json_name) _upb_DefBuilder_OomErr(ctx); - // Must happen before _upb_DefBuilder_Add() - s->file = _upb_DefBuilder_File(ctx); + const bool has_type = UPB_DESC(FieldDescriptorProto_has_type)(field_proto); + const bool has_type_name = + UPB_DESC(FieldDescriptorProto_has_type_name)(field_proto); - upb_StringView name = UPB_DESC(ServiceDescriptorProto_name)(svc_proto); - const char* package = _upb_FileDef_RawPackage(s->file); - s->full_name = _upb_DefBuilder_MakeFullName(ctx, package, name); - _upb_DefBuilder_Add(ctx, s->full_name, - _upb_DefType_Pack(s, UPB_DEFTYPE_SERVICE)); + f->type_ = (int)UPB_DESC(FieldDescriptorProto_type)(field_proto); - size_t n; - const UPB_DESC(MethodDescriptorProto)* const* methods = - UPB_DESC(ServiceDescriptorProto_method)(svc_proto, &n); - s->method_count = n; - s->methods = _upb_MethodDefs_New(ctx, n, methods, s->resolved_features, s); -} + if (has_type) { + switch (f->type_) { + case kUpb_FieldType_Message: + case kUpb_FieldType_Group: + case kUpb_FieldType_Enum: + if (!has_type_name) { + _upb_DefBuilder_Errf(ctx, "field of type %d requires type name (%s)", + (int)f->type_, f->full_name); + } + break; + default: + if (has_type_name) { + _upb_DefBuilder_Errf( + ctx, "invalid type for field with type_name set (%s, %d)", + f->full_name, (int)f->type_); + } + } + } -upb_ServiceDef* _upb_ServiceDefs_New(upb_DefBuilder* ctx, int n, - const UPB_DESC(ServiceDescriptorProto*) - const* protos, - const UPB_DESC(FeatureSet*) - parent_features) { - _upb_DefType_CheckPadding(sizeof(upb_ServiceDef)); + if (!has_type && has_type_name) { + f->type_ = + UPB_FIELD_TYPE_UNSPECIFIED; // We'll assign this in resolve_subdef() + } else { + if (f->type_ < kUpb_FieldType_Double || f->type_ > kUpb_FieldType_SInt64) { + _upb_DefBuilder_Errf(ctx, "invalid type for field %s (%d)", f->full_name, + f->type_); + } + } - upb_ServiceDef* s = _upb_DefBuilder_Alloc(ctx, sizeof(upb_ServiceDef) * n); - for (int i = 0; i < n; i++) { - create_service(ctx, protos[i], parent_features, &s[i]); - s[i].index = i; + if (f->label_ < kUpb_Label_Optional || f->label_ > kUpb_Label_Repeated) { + _upb_DefBuilder_Errf(ctx, "invalid label for field %s (%d)", f->full_name, + f->label_); } - return s; -} + /* We can't resolve the subdef or (in the case of extensions) the containing + * message yet, because it may not have been defined yet. We stash a pointer + * to the field_proto until later when we can properly resolve it. */ + f->sub.unresolved = field_proto; -#include -#include -#include -#include -#include + if (UPB_DESC(FieldDescriptorProto_has_oneof_index)(field_proto)) { + if (upb_FieldDef_Label(f) != kUpb_Label_Optional) { + _upb_DefBuilder_Errf(ctx, "fields in oneof must have OPTIONAL label (%s)", + f->full_name); + } + } + f->has_presence = + (!upb_FieldDef_IsRepeated(f)) && + (f->type_ == kUpb_FieldType_Message || f->type_ == kUpb_FieldType_Group || + upb_FieldDef_ContainingOneof(f) || + UPB_DESC(FeatureSet_field_presence)(f->resolved_features) != + UPB_DESC(FeatureSet_IMPLICIT)); +} -// Must be last. +static void _upb_FieldDef_CreateExt(upb_DefBuilder* ctx, const char* prefix, + const UPB_DESC(FeatureSet*) parent_features, + const UPB_DESC(FieldDescriptorProto*) + field_proto, + upb_MessageDef* m, upb_FieldDef* f) { + f->is_extension = true; + _upb_FieldDef_Create(ctx, prefix, parent_features, field_proto, m, f); -// A few fake field types for our tables. -enum { - kUpb_FakeFieldType_FieldNotFound = 0, - kUpb_FakeFieldType_MessageSetItem = 19, -}; + if (UPB_DESC(FieldDescriptorProto_has_oneof_index)(field_proto)) { + _upb_DefBuilder_Errf(ctx, "oneof_index provided for extension field (%s)", + f->full_name); + } -// DecodeOp: an action to be performed for a wire-type/field-type combination. -enum { - // Special ops: we don't write data to regular fields for these. - kUpb_DecodeOp_UnknownField = -1, - kUpb_DecodeOp_MessageSetItem = -2, + f->scope.extension_scope = m; + _upb_DefBuilder_Add(ctx, f->full_name, _upb_DefType_Pack(f, UPB_DEFTYPE_EXT)); + f->layout_index = ctx->ext_count++; - // Scalar-only ops. - kUpb_DecodeOp_Scalar1Byte = 0, - kUpb_DecodeOp_Scalar4Byte = 2, - kUpb_DecodeOp_Scalar8Byte = 3, - kUpb_DecodeOp_Enum = 1, + if (ctx->layout) { + UPB_ASSERT(upb_MiniTableExtension_Number( + _upb_FieldDef_ExtensionMiniTable(f)) == f->number_); + } +} - // Scalar/repeated ops. - kUpb_DecodeOp_String = 4, - kUpb_DecodeOp_Bytes = 5, - kUpb_DecodeOp_SubMessage = 6, +static void _upb_FieldDef_CreateNotExt(upb_DefBuilder* ctx, const char* prefix, + const UPB_DESC(FeatureSet*) + parent_features, + const UPB_DESC(FieldDescriptorProto*) + field_proto, + upb_MessageDef* m, upb_FieldDef* f) { + f->is_extension = false; + _upb_FieldDef_Create(ctx, prefix, parent_features, field_proto, m, f); - // Repeated-only ops (also see macros below). - kUpb_DecodeOp_PackedEnum = 13, -}; + if (!UPB_DESC(FieldDescriptorProto_has_oneof_index)(field_proto)) { + if (f->is_proto3_optional) { + _upb_DefBuilder_Errf( + ctx, + "non-extension field (%s) with proto3_optional was not in a oneof", + f->full_name); + } + } -// For packed fields it is helpful to be able to recover the lg2 of the data -// size from the op. -#define OP_FIXPCK_LG2(n) (n + 5) /* n in [2, 3] => op in [7, 8] */ -#define OP_VARPCK_LG2(n) (n + 9) /* n in [0, 2, 3] => op in [9, 11, 12] */ + _upb_MessageDef_InsertField(ctx, m, f); +} -typedef union { - bool bool_val; - uint32_t uint32_val; - uint64_t uint64_val; - uint32_t size; -} wireval; +upb_FieldDef* _upb_Extensions_New(upb_DefBuilder* ctx, int n, + const UPB_DESC(FieldDescriptorProto*) + const* protos, + const UPB_DESC(FeatureSet*) parent_features, + const char* prefix, upb_MessageDef* m) { + _upb_DefType_CheckPadding(sizeof(upb_FieldDef)); + upb_FieldDef* defs = + (upb_FieldDef*)_upb_DefBuilder_Alloc(ctx, sizeof(upb_FieldDef) * n); -// Ideally these two functions should take the owning MiniTable pointer as a -// first argument, then we could just put them in mini_table/message.h as nice -// clean getters. But we don't have that so instead we gotta write these -// Frankenfunctions that take an array of subtables. -// TODO: Move these to mini_table/ anyway since there are other places -// that could use them. + for (int i = 0; i < n; i++) { + upb_FieldDef* f = &defs[i]; -// Returns the MiniTable corresponding to a given MiniTableField -// from an array of MiniTableSubs. -static const upb_MiniTable* _upb_MiniTableSubs_MessageByField( - const upb_MiniTableSub* subs, const upb_MiniTableField* field) { - return upb_MiniTableSub_Message(subs[field->UPB_PRIVATE(submsg_index)]); -} + _upb_FieldDef_CreateExt(ctx, prefix, parent_features, protos[i], m, f); + f->index_ = i; + } -// Returns the MiniTableEnum corresponding to a given MiniTableField -// from an array of MiniTableSub. -static const upb_MiniTableEnum* _upb_MiniTableSubs_EnumByField( - const upb_MiniTableSub* subs, const upb_MiniTableField* field) { - return upb_MiniTableSub_Enum(subs[field->UPB_PRIVATE(submsg_index)]); + return defs; } -static const char* _upb_Decoder_DecodeMessage(upb_Decoder* d, const char* ptr, - upb_Message* msg, - const upb_MiniTable* layout); +upb_FieldDef* _upb_FieldDefs_New(upb_DefBuilder* ctx, int n, + const UPB_DESC(FieldDescriptorProto*) + const* protos, + const UPB_DESC(FeatureSet*) parent_features, + const char* prefix, upb_MessageDef* m, + bool* is_sorted) { + _upb_DefType_CheckPadding(sizeof(upb_FieldDef)); + upb_FieldDef* defs = + (upb_FieldDef*)_upb_DefBuilder_Alloc(ctx, sizeof(upb_FieldDef) * n); + + uint32_t previous = 0; + for (int i = 0; i < n; i++) { + upb_FieldDef* f = &defs[i]; + + _upb_FieldDef_CreateNotExt(ctx, prefix, parent_features, protos[i], m, f); + f->index_ = i; + if (!ctx->layout) { + // Speculate that the def fields are sorted. We will always sort the + // MiniTable fields, so if defs are sorted then indices will match. + // + // If this is incorrect, we will overwrite later. + f->layout_index = i; + } -UPB_NORETURN static void* _upb_Decoder_ErrorJmp(upb_Decoder* d, - upb_DecodeStatus status) { - UPB_ASSERT(status != kUpb_DecodeStatus_Ok); - d->status = status; - UPB_LONGJMP(d->err, 1); -} + const uint32_t current = f->number_; + if (previous > current) *is_sorted = false; + previous = current; + } -const char* _upb_FastDecoder_ErrorJmp(upb_Decoder* d, int status) { - UPB_ASSERT(status != kUpb_DecodeStatus_Ok); - d->status = status; - UPB_LONGJMP(d->err, 1); - return NULL; + return defs; } -static void _upb_Decoder_VerifyUtf8(upb_Decoder* d, const char* buf, int len) { - if (!_upb_Decoder_VerifyUtf8Inline(buf, len)) { - _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_BadUtf8); +static void resolve_subdef(upb_DefBuilder* ctx, const char* prefix, + upb_FieldDef* f) { + const UPB_DESC(FieldDescriptorProto)* field_proto = f->sub.unresolved; + upb_StringView name = UPB_DESC(FieldDescriptorProto_type_name)(field_proto); + bool has_name = UPB_DESC(FieldDescriptorProto_has_type_name)(field_proto); + switch ((int)f->type_) { + case UPB_FIELD_TYPE_UNSPECIFIED: { + // Type was not specified and must be inferred. + UPB_ASSERT(has_name); + upb_deftype_t type; + const void* def = + _upb_DefBuilder_ResolveAny(ctx, f->full_name, prefix, name, &type); + switch (type) { + case UPB_DEFTYPE_ENUM: + f->sub.enumdef = def; + f->type_ = kUpb_FieldType_Enum; + break; + case UPB_DEFTYPE_MSG: + f->sub.msgdef = def; + f->type_ = kUpb_FieldType_Message; // It appears there is no way of + // this being a group. + f->has_presence = !upb_FieldDef_IsRepeated(f); + break; + default: + _upb_DefBuilder_Errf(ctx, "Couldn't resolve type name for field %s", + f->full_name); + } + break; + } + case kUpb_FieldType_Message: + case kUpb_FieldType_Group: + UPB_ASSERT(has_name); + f->sub.msgdef = _upb_DefBuilder_Resolve(ctx, f->full_name, prefix, name, + UPB_DEFTYPE_MSG); + break; + case kUpb_FieldType_Enum: + UPB_ASSERT(has_name); + f->sub.enumdef = _upb_DefBuilder_Resolve(ctx, f->full_name, prefix, name, + UPB_DEFTYPE_ENUM); + break; + default: + // No resolution necessary. + break; } } -static bool _upb_Decoder_Reserve(upb_Decoder* d, upb_Array* arr, size_t elem) { - bool need_realloc = - arr->UPB_PRIVATE(capacity) - arr->UPB_PRIVATE(size) < elem; - if (need_realloc && !UPB_PRIVATE(_upb_Array_Realloc)( - arr, arr->UPB_PRIVATE(size) + elem, &d->arena)) { - _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_OutOfMemory); - } - return need_realloc; +static int _upb_FieldDef_Compare(const void* p1, const void* p2) { + const uint32_t v1 = (*(upb_FieldDef**)p1)->number_; + const uint32_t v2 = (*(upb_FieldDef**)p2)->number_; + return (v1 < v2) ? -1 : (v1 > v2); } -typedef struct { - const char* ptr; - uint64_t val; -} _upb_DecodeLongVarintReturn; +// _upb_FieldDefs_Sorted() is mostly a pure function of its inputs, but has one +// critical side effect that we depend on: it sets layout_index appropriately +// for non-sorted lists of fields. +const upb_FieldDef** _upb_FieldDefs_Sorted(const upb_FieldDef* f, int n, + upb_Arena* a) { + // TODO: Replace this arena alloc with a persistent scratch buffer. + upb_FieldDef** out = (upb_FieldDef**)upb_Arena_Malloc(a, n * sizeof(void*)); + if (!out) return NULL; -UPB_NOINLINE -static _upb_DecodeLongVarintReturn _upb_Decoder_DecodeLongVarint( - const char* ptr, uint64_t val) { - _upb_DecodeLongVarintReturn ret = {NULL, 0}; - uint64_t byte; - int i; - for (i = 1; i < 10; i++) { - byte = (uint8_t)ptr[i]; - val += (byte - 1) << (i * 7); - if (!(byte & 0x80)) { - ret.ptr = ptr + i + 1; - ret.val = val; - return ret; - } + for (int i = 0; i < n; i++) { + out[i] = (upb_FieldDef*)&f[i]; } - return ret; -} + qsort(out, n, sizeof(void*), _upb_FieldDef_Compare); -UPB_FORCEINLINE -static const char* _upb_Decoder_DecodeVarint(upb_Decoder* d, const char* ptr, - uint64_t* val) { - uint64_t byte = (uint8_t)*ptr; - if (UPB_LIKELY((byte & 0x80) == 0)) { - *val = byte; - return ptr + 1; - } else { - _upb_DecodeLongVarintReturn res = _upb_Decoder_DecodeLongVarint(ptr, byte); - if (!res.ptr) _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_Malformed); - *val = res.val; - return res.ptr; + for (int i = 0; i < n; i++) { + out[i]->layout_index = i; } + return (const upb_FieldDef**)out; } -UPB_FORCEINLINE -static const char* _upb_Decoder_DecodeTag(upb_Decoder* d, const char* ptr, - uint32_t* val) { - uint64_t byte = (uint8_t)*ptr; - if (UPB_LIKELY((byte & 0x80) == 0)) { - *val = byte; - return ptr + 1; - } else { - const char* start = ptr; - _upb_DecodeLongVarintReturn res = _upb_Decoder_DecodeLongVarint(ptr, byte); - if (!res.ptr || res.ptr - start > 5 || res.val > UINT32_MAX) { - _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_Malformed); - } - *val = res.val; - return res.ptr; - } -} +bool upb_FieldDef_MiniDescriptorEncode(const upb_FieldDef* f, upb_Arena* a, + upb_StringView* out) { + UPB_ASSERT(f->is_extension); -UPB_FORCEINLINE -static const char* upb_Decoder_DecodeSize(upb_Decoder* d, const char* ptr, - uint32_t* size) { - uint64_t size64; - ptr = _upb_Decoder_DecodeVarint(d, ptr, &size64); - if (size64 >= INT32_MAX || - !upb_EpsCopyInputStream_CheckSize(&d->input, ptr, (int)size64)) { - _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_Malformed); - } - *size = size64; - return ptr; + upb_DescState s; + _upb_DescState_Init(&s); + + const int number = upb_FieldDef_Number(f); + const uint64_t modifiers = _upb_FieldDef_Modifiers(f); + + if (!_upb_DescState_Grow(&s, a)) return false; + s.ptr = upb_MtDataEncoder_EncodeExtension(&s.e, s.ptr, f->type_, number, + modifiers); + *s.ptr = '\0'; + + out->data = s.buf; + out->size = s.ptr - s.buf; + return true; } -static void _upb_Decoder_MungeInt32(wireval* val) { - if (!UPB_PRIVATE(_upb_IsLittleEndian)()) { - /* The next stage will memcpy(dst, &val, 4) */ - val->uint32_val = val->uint64_val; +static void resolve_extension(upb_DefBuilder* ctx, const char* prefix, + upb_FieldDef* f, + const UPB_DESC(FieldDescriptorProto) * + field_proto) { + if (!UPB_DESC(FieldDescriptorProto_has_extendee)(field_proto)) { + _upb_DefBuilder_Errf(ctx, "extension for field '%s' had no extendee", + f->full_name); } -} -static void _upb_Decoder_Munge(int type, wireval* val) { - switch (type) { - case kUpb_FieldType_Bool: - val->bool_val = val->uint64_val != 0; - break; - case kUpb_FieldType_SInt32: { - uint32_t n = val->uint64_val; - val->uint32_val = (n >> 1) ^ -(int32_t)(n & 1); - break; - } - case kUpb_FieldType_SInt64: { - uint64_t n = val->uint64_val; - val->uint64_val = (n >> 1) ^ -(int64_t)(n & 1); - break; - } - case kUpb_FieldType_Int32: - case kUpb_FieldType_UInt32: - case kUpb_FieldType_Enum: - _upb_Decoder_MungeInt32(val); - break; + upb_StringView name = UPB_DESC(FieldDescriptorProto_extendee)(field_proto); + const upb_MessageDef* m = + _upb_DefBuilder_Resolve(ctx, f->full_name, prefix, name, UPB_DEFTYPE_MSG); + f->msgdef = m; + + if (!_upb_MessageDef_IsValidExtensionNumber(m, f->number_)) { + _upb_DefBuilder_Errf( + ctx, + "field number %u in extension %s has no extension range in message %s", + (unsigned)f->number_, f->full_name, upb_MessageDef_FullName(m)); } } -static upb_Message* _upb_Decoder_NewSubMessage(upb_Decoder* d, - const upb_MiniTableSub* subs, - const upb_MiniTableField* field, - upb_TaggedMessagePtr* target) { - const upb_MiniTable* subl = _upb_MiniTableSubs_MessageByField(subs, field); - UPB_ASSERT(subl); - upb_Message* msg = _upb_Message_New(subl, &d->arena); - if (!msg) _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_OutOfMemory); +void _upb_FieldDef_BuildMiniTableExtension(upb_DefBuilder* ctx, + const upb_FieldDef* f) { + const upb_MiniTableExtension* ext = _upb_FieldDef_ExtensionMiniTable(f); - // Extensions should not be unlinked. A message extension should not be - // registered until its sub-message type is available to be linked. - bool is_empty = UPB_PRIVATE(_upb_MiniTable_IsEmpty)(subl); - bool is_extension = field->UPB_PRIVATE(mode) & kUpb_LabelFlags_IsExtension; - UPB_ASSERT(!(is_empty && is_extension)); + if (ctx->layout) { + UPB_ASSERT(upb_FieldDef_Number(f) == upb_MiniTableExtension_Number(ext)); + } else { + upb_StringView desc; + if (!upb_FieldDef_MiniDescriptorEncode(f, ctx->tmp_arena, &desc)) { + _upb_DefBuilder_OomErr(ctx); + } - if (is_empty && !(d->options & kUpb_DecodeOption_ExperimentalAllowUnlinked)) { - _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_UnlinkedSubMessage); + upb_MiniTableExtension* mut_ext = (upb_MiniTableExtension*)ext; + upb_MiniTableSub sub = {NULL}; + if (upb_FieldDef_IsSubMessage(f)) { + const upb_MiniTable* submsg = upb_MessageDef_MiniTable(f->sub.msgdef); + sub = upb_MiniTableSub_FromMessage(submsg); + } else if (_upb_FieldDef_IsClosedEnum(f)) { + const upb_MiniTableEnum* subenum = _upb_EnumDef_MiniTable(f->sub.enumdef); + sub = upb_MiniTableSub_FromEnum(subenum); + } + bool ok2 = upb_MiniTableExtension_Init(desc.data, desc.size, mut_ext, + upb_MessageDef_MiniTable(f->msgdef), + sub, ctx->status); + if (!ok2) _upb_DefBuilder_Errf(ctx, "Could not build extension mini table"); } - upb_TaggedMessagePtr tagged = - UPB_PRIVATE(_upb_TaggedMessagePtr_Pack)(msg, is_empty); - memcpy(target, &tagged, sizeof(tagged)); - return msg; + bool ok = _upb_DefPool_InsertExt(ctx->symtab, ext, f); + if (!ok) _upb_DefBuilder_OomErr(ctx); } -static upb_Message* _upb_Decoder_ReuseSubMessage( - upb_Decoder* d, const upb_MiniTableSub* subs, - const upb_MiniTableField* field, upb_TaggedMessagePtr* target) { - upb_TaggedMessagePtr tagged = *target; - const upb_MiniTable* subl = _upb_MiniTableSubs_MessageByField(subs, field); - UPB_ASSERT(subl); - if (!upb_TaggedMessagePtr_IsEmpty(tagged) || - UPB_PRIVATE(_upb_MiniTable_IsEmpty)(subl)) { - return UPB_PRIVATE(_upb_TaggedMessagePtr_GetMessage)(tagged); - } +static void resolve_default(upb_DefBuilder* ctx, upb_FieldDef* f, + const UPB_DESC(FieldDescriptorProto) * + field_proto) { + // Have to delay resolving of the default value until now because of the enum + // case, since enum defaults are specified with a label. + if (UPB_DESC(FieldDescriptorProto_has_default_value)(field_proto)) { + upb_StringView defaultval = + UPB_DESC(FieldDescriptorProto_default_value)(field_proto); - // We found an empty message from a previous parse that was performed before - // this field was linked. But it is linked now, so we want to allocate a new - // message of the correct type and promote data into it before continuing. - upb_Message* existing = - UPB_PRIVATE(_upb_TaggedMessagePtr_GetEmptyMessage)(tagged); - upb_Message* promoted = _upb_Decoder_NewSubMessage(d, subs, field, target); - size_t size; - const char* unknown = upb_Message_GetUnknown(existing, &size); - upb_DecodeStatus status = upb_Decode(unknown, size, promoted, subl, d->extreg, - d->options, &d->arena); - if (status != kUpb_DecodeStatus_Ok) _upb_Decoder_ErrorJmp(d, status); - return promoted; -} + if (upb_FileDef_Syntax(f->file) == kUpb_Syntax_Proto3) { + _upb_DefBuilder_Errf(ctx, + "proto3 fields cannot have explicit defaults (%s)", + f->full_name); + } -static const char* _upb_Decoder_ReadString(upb_Decoder* d, const char* ptr, - int size, upb_StringView* str) { - const char* str_ptr = ptr; - ptr = upb_EpsCopyInputStream_ReadString(&d->input, &str_ptr, size, &d->arena); - if (!ptr) _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_OutOfMemory); - str->data = str_ptr; - str->size = size; - return ptr; -} + if (upb_FieldDef_IsSubMessage(f)) { + _upb_DefBuilder_Errf(ctx, + "message fields cannot have explicit defaults (%s)", + f->full_name); + } -UPB_FORCEINLINE -static const char* _upb_Decoder_RecurseSubMessage(upb_Decoder* d, - const char* ptr, - upb_Message* submsg, - const upb_MiniTable* subl, - uint32_t expected_end_group) { - if (--d->depth < 0) { - _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_MaxDepthExceeded); - } - ptr = _upb_Decoder_DecodeMessage(d, ptr, submsg, subl); - d->depth++; - if (d->end_group != expected_end_group) { - _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_Malformed); + parse_default(ctx, defaultval.data, defaultval.size, f); + f->has_default = true; + } else { + set_default_default(ctx, f); + f->has_default = false; } - return ptr; } -UPB_FORCEINLINE -static const char* _upb_Decoder_DecodeSubMessage( - upb_Decoder* d, const char* ptr, upb_Message* submsg, - const upb_MiniTableSub* subs, const upb_MiniTableField* field, int size) { - int saved_delta = upb_EpsCopyInputStream_PushLimit(&d->input, ptr, size); - const upb_MiniTable* subl = _upb_MiniTableSubs_MessageByField(subs, field); - UPB_ASSERT(subl); - ptr = _upb_Decoder_RecurseSubMessage(d, ptr, submsg, subl, DECODE_NOGROUP); - upb_EpsCopyInputStream_PopLimit(&d->input, ptr, saved_delta); - return ptr; -} +void _upb_FieldDef_Resolve(upb_DefBuilder* ctx, const char* prefix, + upb_FieldDef* f) { + // We have to stash this away since resolve_subdef() may overwrite it. + const UPB_DESC(FieldDescriptorProto)* field_proto = f->sub.unresolved; -UPB_FORCEINLINE -static const char* _upb_Decoder_DecodeGroup(upb_Decoder* d, const char* ptr, - upb_Message* submsg, - const upb_MiniTable* subl, - uint32_t number) { - if (_upb_Decoder_IsDone(d, &ptr)) { - _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_Malformed); + resolve_subdef(ctx, prefix, f); + resolve_default(ctx, f, field_proto); + + if (f->is_extension) { + resolve_extension(ctx, prefix, f, field_proto); } - ptr = _upb_Decoder_RecurseSubMessage(d, ptr, submsg, subl, number); - d->end_group = DECODE_NOGROUP; - return ptr; } -UPB_FORCEINLINE -static const char* _upb_Decoder_DecodeUnknownGroup(upb_Decoder* d, - const char* ptr, - uint32_t number) { - return _upb_Decoder_DecodeGroup(d, ptr, NULL, NULL, number); -} -UPB_FORCEINLINE -static const char* _upb_Decoder_DecodeKnownGroup( - upb_Decoder* d, const char* ptr, upb_Message* submsg, - const upb_MiniTableSub* subs, const upb_MiniTableField* field) { - const upb_MiniTable* subl = _upb_MiniTableSubs_MessageByField(subs, field); - UPB_ASSERT(subl); - return _upb_Decoder_DecodeGroup(d, ptr, submsg, subl, - field->UPB_PRIVATE(number)); -} +#include +#include +#include -static char* upb_Decoder_EncodeVarint32(uint32_t val, char* ptr) { - do { - uint8_t byte = val & 0x7fU; - val >>= 7; - if (val) byte |= 0x80U; - *(ptr++) = byte; - } while (val); - return ptr; -} -static void _upb_Decoder_AddUnknownVarints(upb_Decoder* d, upb_Message* msg, - uint32_t val1, uint32_t val2) { - char buf[20]; - char* end = buf; - end = upb_Decoder_EncodeVarint32(val1, end); - end = upb_Decoder_EncodeVarint32(val2, end); +// Must be last. - if (!UPB_PRIVATE(_upb_Message_AddUnknown)(msg, buf, end - buf, &d->arena)) { - _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_OutOfMemory); +struct upb_FileDef { + const UPB_DESC(FileOptions*) opts; + const UPB_DESC(FeatureSet*) resolved_features; + const char* name; + const char* package; + UPB_DESC(Edition) edition; + + const upb_FileDef** deps; + const int32_t* public_deps; + const int32_t* weak_deps; + const upb_MessageDef* top_lvl_msgs; + const upb_EnumDef* top_lvl_enums; + const upb_FieldDef* top_lvl_exts; + const upb_ServiceDef* services; + const upb_MiniTableExtension** ext_layouts; + const upb_DefPool* symtab; + + int dep_count; + int public_dep_count; + int weak_dep_count; + int top_lvl_msg_count; + int top_lvl_enum_count; + int top_lvl_ext_count; + int service_count; + int ext_count; // All exts in the file. + upb_Syntax syntax; +}; + +UPB_API const char* upb_FileDef_EditionName(int edition) { + // TODO Synchronize this with descriptor.proto better. + switch (edition) { + case UPB_DESC(EDITION_PROTO2): + return "PROTO2"; + case UPB_DESC(EDITION_PROTO3): + return "PROTO3"; + case UPB_DESC(EDITION_2023): + return "2023"; + default: + return "UNKNOWN"; } } -UPB_FORCEINLINE -static bool _upb_Decoder_CheckEnum(upb_Decoder* d, const char* ptr, - upb_Message* msg, const upb_MiniTableEnum* e, - const upb_MiniTableField* field, - wireval* val) { - const uint32_t v = val->uint32_val; - - if (UPB_LIKELY(upb_MiniTableEnum_CheckValue(e, v))) return true; +const UPB_DESC(FileOptions) * upb_FileDef_Options(const upb_FileDef* f) { + return f->opts; +} - // Unrecognized enum goes into unknown fields. - // For packed fields the tag could be arbitrarily far in the past, - // so we just re-encode the tag and value here. - const uint32_t tag = - ((uint32_t)field->UPB_PRIVATE(number) << 3) | kUpb_WireType_Varint; - upb_Message* unknown_msg = - field->UPB_PRIVATE(mode) & kUpb_LabelFlags_IsExtension ? d->unknown_msg - : msg; - _upb_Decoder_AddUnknownVarints(d, unknown_msg, tag, v); - return false; +const UPB_DESC(FeatureSet) * + upb_FileDef_ResolvedFeatures(const upb_FileDef* f) { + return f->resolved_features; } -UPB_NOINLINE -static const char* _upb_Decoder_DecodeEnumArray(upb_Decoder* d, const char* ptr, - upb_Message* msg, - upb_Array* arr, - const upb_MiniTableSub* subs, - const upb_MiniTableField* field, - wireval* val) { - const upb_MiniTableEnum* e = _upb_MiniTableSubs_EnumByField(subs, field); - if (!_upb_Decoder_CheckEnum(d, ptr, msg, e, field, val)) return ptr; - void* mem = UPB_PTR_AT(_upb_array_ptr(arr), arr->UPB_PRIVATE(size) * 4, void); - arr->UPB_PRIVATE(size)++; - memcpy(mem, val, 4); - return ptr; +bool upb_FileDef_HasOptions(const upb_FileDef* f) { + return f->opts != (void*)kUpbDefOptDefault; } -UPB_FORCEINLINE -static const char* _upb_Decoder_DecodeFixedPacked( - upb_Decoder* d, const char* ptr, upb_Array* arr, wireval* val, - const upb_MiniTableField* field, int lg2) { - int mask = (1 << lg2) - 1; - size_t count = val->size >> lg2; - if ((val->size & mask) != 0) { - // Length isn't a round multiple of elem size. - _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_Malformed); - } - _upb_Decoder_Reserve(d, arr, count); - void* mem = - UPB_PTR_AT(_upb_array_ptr(arr), arr->UPB_PRIVATE(size) << lg2, void); - arr->UPB_PRIVATE(size) += count; - // Note: if/when the decoder supports multi-buffer input, we will need to - // handle buffer seams here. - if (UPB_PRIVATE(_upb_IsLittleEndian)()) { - ptr = upb_EpsCopyInputStream_Copy(&d->input, ptr, mem, val->size); - } else { - int delta = upb_EpsCopyInputStream_PushLimit(&d->input, ptr, val->size); - char* dst = mem; - while (!_upb_Decoder_IsDone(d, &ptr)) { - if (lg2 == 2) { - ptr = upb_WireReader_ReadFixed32(ptr, dst); - dst += 4; - } else { - UPB_ASSERT(lg2 == 3); - ptr = upb_WireReader_ReadFixed64(ptr, dst); - dst += 8; - } - } - upb_EpsCopyInputStream_PopLimit(&d->input, ptr, delta); - } +const char* upb_FileDef_Name(const upb_FileDef* f) { return f->name; } - return ptr; +const char* upb_FileDef_Package(const upb_FileDef* f) { + return f->package ? f->package : ""; } -UPB_FORCEINLINE -static const char* _upb_Decoder_DecodeVarintPacked( - upb_Decoder* d, const char* ptr, upb_Array* arr, wireval* val, - const upb_MiniTableField* field, int lg2) { - int scale = 1 << lg2; - int saved_limit = upb_EpsCopyInputStream_PushLimit(&d->input, ptr, val->size); - char* out = - UPB_PTR_AT(_upb_array_ptr(arr), arr->UPB_PRIVATE(size) << lg2, void); - while (!_upb_Decoder_IsDone(d, &ptr)) { - wireval elem; - ptr = _upb_Decoder_DecodeVarint(d, ptr, &elem.uint64_val); - _upb_Decoder_Munge(field->UPB_PRIVATE(descriptortype), &elem); - if (_upb_Decoder_Reserve(d, arr, 1)) { - out = - UPB_PTR_AT(_upb_array_ptr(arr), arr->UPB_PRIVATE(size) << lg2, void); - } - arr->UPB_PRIVATE(size)++; - memcpy(out, &elem, scale); - out += scale; - } - upb_EpsCopyInputStream_PopLimit(&d->input, ptr, saved_limit); - return ptr; +UPB_DESC(Edition) upb_FileDef_Edition(const upb_FileDef* f) { + return f->edition; } -UPB_NOINLINE -static const char* _upb_Decoder_DecodeEnumPacked( - upb_Decoder* d, const char* ptr, upb_Message* msg, upb_Array* arr, - const upb_MiniTableSub* subs, const upb_MiniTableField* field, - wireval* val) { - const upb_MiniTableEnum* e = _upb_MiniTableSubs_EnumByField(subs, field); - int saved_limit = upb_EpsCopyInputStream_PushLimit(&d->input, ptr, val->size); - char* out = UPB_PTR_AT(_upb_array_ptr(arr), arr->UPB_PRIVATE(size) * 4, void); - while (!_upb_Decoder_IsDone(d, &ptr)) { - wireval elem; - ptr = _upb_Decoder_DecodeVarint(d, ptr, &elem.uint64_val); - _upb_Decoder_MungeInt32(&elem); - if (!_upb_Decoder_CheckEnum(d, ptr, msg, e, field, &elem)) { - continue; - } - if (_upb_Decoder_Reserve(d, arr, 1)) { - out = UPB_PTR_AT(_upb_array_ptr(arr), arr->UPB_PRIVATE(size) * 4, void); - } - arr->UPB_PRIVATE(size)++; - memcpy(out, &elem, 4); - out += 4; - } - upb_EpsCopyInputStream_PopLimit(&d->input, ptr, saved_limit); - return ptr; +const char* _upb_FileDef_RawPackage(const upb_FileDef* f) { return f->package; } + +upb_Syntax upb_FileDef_Syntax(const upb_FileDef* f) { return f->syntax; } + +int upb_FileDef_TopLevelMessageCount(const upb_FileDef* f) { + return f->top_lvl_msg_count; } -upb_Array* _upb_Decoder_CreateArray(upb_Decoder* d, - const upb_MiniTableField* field) { - const upb_FieldType field_type = field->UPB_PRIVATE(descriptortype); - const size_t lg2 = UPB_PRIVATE(_upb_FieldType_SizeLg2)(field_type); - upb_Array* ret = UPB_PRIVATE(_upb_Array_New)(&d->arena, 4, lg2); - if (!ret) _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_OutOfMemory); - return ret; +int upb_FileDef_DependencyCount(const upb_FileDef* f) { return f->dep_count; } + +int upb_FileDef_PublicDependencyCount(const upb_FileDef* f) { + return f->public_dep_count; } -static const char* _upb_Decoder_DecodeToArray(upb_Decoder* d, const char* ptr, - upb_Message* msg, - const upb_MiniTableSub* subs, - const upb_MiniTableField* field, - wireval* val, int op) { - upb_Array** arrp = UPB_PTR_AT(msg, field->UPB_PRIVATE(offset), void); - upb_Array* arr = *arrp; - void* mem; +int upb_FileDef_WeakDependencyCount(const upb_FileDef* f) { + return f->weak_dep_count; +} - if (arr) { - _upb_Decoder_Reserve(d, arr, 1); - } else { - arr = _upb_Decoder_CreateArray(d, field); - *arrp = arr; - } +const int32_t* _upb_FileDef_PublicDependencyIndexes(const upb_FileDef* f) { + return f->public_deps; +} - switch (op) { - case kUpb_DecodeOp_Scalar1Byte: - case kUpb_DecodeOp_Scalar4Byte: - case kUpb_DecodeOp_Scalar8Byte: - /* Append scalar value. */ - mem = UPB_PTR_AT(_upb_array_ptr(arr), arr->UPB_PRIVATE(size) << op, void); - arr->UPB_PRIVATE(size)++; - memcpy(mem, val, 1 << op); - return ptr; - case kUpb_DecodeOp_String: - _upb_Decoder_VerifyUtf8(d, ptr, val->size); - /* Fallthrough. */ - case kUpb_DecodeOp_Bytes: { - /* Append bytes. */ - upb_StringView* str = - (upb_StringView*)_upb_array_ptr(arr) + arr->UPB_PRIVATE(size); - arr->UPB_PRIVATE(size)++; - return _upb_Decoder_ReadString(d, ptr, val->size, str); - } - case kUpb_DecodeOp_SubMessage: { - /* Append submessage / group. */ - upb_TaggedMessagePtr* target = UPB_PTR_AT( - _upb_array_ptr(arr), arr->UPB_PRIVATE(size) * sizeof(void*), - upb_TaggedMessagePtr); - upb_Message* submsg = _upb_Decoder_NewSubMessage(d, subs, field, target); - arr->UPB_PRIVATE(size)++; - if (UPB_UNLIKELY(field->UPB_PRIVATE(descriptortype) == - kUpb_FieldType_Group)) { - return _upb_Decoder_DecodeKnownGroup(d, ptr, submsg, subs, field); - } else { - return _upb_Decoder_DecodeSubMessage(d, ptr, submsg, subs, field, - val->size); - } - } - case OP_FIXPCK_LG2(2): - case OP_FIXPCK_LG2(3): - return _upb_Decoder_DecodeFixedPacked(d, ptr, arr, val, field, - op - OP_FIXPCK_LG2(0)); - case OP_VARPCK_LG2(0): - case OP_VARPCK_LG2(2): - case OP_VARPCK_LG2(3): - return _upb_Decoder_DecodeVarintPacked(d, ptr, arr, val, field, - op - OP_VARPCK_LG2(0)); - case kUpb_DecodeOp_Enum: - return _upb_Decoder_DecodeEnumArray(d, ptr, msg, arr, subs, field, val); - case kUpb_DecodeOp_PackedEnum: - return _upb_Decoder_DecodeEnumPacked(d, ptr, msg, arr, subs, field, val); - default: - UPB_UNREACHABLE(); - } +const int32_t* _upb_FileDef_WeakDependencyIndexes(const upb_FileDef* f) { + return f->weak_deps; } -upb_Map* _upb_Decoder_CreateMap(upb_Decoder* d, const upb_MiniTable* entry) { - /* Maps descriptor type -> upb map size. */ - static const uint8_t kSizeInMap[] = { - [0] = -1, // invalid descriptor type */ - [kUpb_FieldType_Double] = 8, - [kUpb_FieldType_Float] = 4, - [kUpb_FieldType_Int64] = 8, - [kUpb_FieldType_UInt64] = 8, - [kUpb_FieldType_Int32] = 4, - [kUpb_FieldType_Fixed64] = 8, - [kUpb_FieldType_Fixed32] = 4, - [kUpb_FieldType_Bool] = 1, - [kUpb_FieldType_String] = UPB_MAPTYPE_STRING, - [kUpb_FieldType_Group] = sizeof(void*), - [kUpb_FieldType_Message] = sizeof(void*), - [kUpb_FieldType_Bytes] = UPB_MAPTYPE_STRING, - [kUpb_FieldType_UInt32] = 4, - [kUpb_FieldType_Enum] = 4, - [kUpb_FieldType_SFixed32] = 4, - [kUpb_FieldType_SFixed64] = 8, - [kUpb_FieldType_SInt32] = 4, - [kUpb_FieldType_SInt64] = 8, - }; +int upb_FileDef_TopLevelEnumCount(const upb_FileDef* f) { + return f->top_lvl_enum_count; +} - const upb_MiniTableField* key_field = &entry->UPB_PRIVATE(fields)[0]; - const upb_MiniTableField* val_field = &entry->UPB_PRIVATE(fields)[1]; - char key_size = kSizeInMap[key_field->UPB_PRIVATE(descriptortype)]; - char val_size = kSizeInMap[val_field->UPB_PRIVATE(descriptortype)]; - UPB_ASSERT(key_field->UPB_PRIVATE(offset) == offsetof(upb_MapEntryData, k)); - UPB_ASSERT(val_field->UPB_PRIVATE(offset) == offsetof(upb_MapEntryData, v)); - upb_Map* ret = _upb_Map_New(&d->arena, key_size, val_size); - if (!ret) _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_OutOfMemory); - return ret; +int upb_FileDef_TopLevelExtensionCount(const upb_FileDef* f) { + return f->top_lvl_ext_count; } -static const char* _upb_Decoder_DecodeToMap(upb_Decoder* d, const char* ptr, - upb_Message* msg, - const upb_MiniTableSub* subs, - const upb_MiniTableField* field, - wireval* val) { - upb_Map** map_p = UPB_PTR_AT(msg, field->UPB_PRIVATE(offset), upb_Map*); - upb_Map* map = *map_p; - upb_MapEntry ent; - UPB_ASSERT(upb_MiniTableField_Type(field) == kUpb_FieldType_Message); - const upb_MiniTable* entry = _upb_MiniTableSubs_MessageByField(subs, field); +int upb_FileDef_ServiceCount(const upb_FileDef* f) { return f->service_count; } - UPB_ASSERT(entry); - UPB_ASSERT(entry->UPB_PRIVATE(field_count) == 2); - UPB_ASSERT(upb_MiniTableField_IsScalar(&entry->UPB_PRIVATE(fields)[0])); - UPB_ASSERT(upb_MiniTableField_IsScalar(&entry->UPB_PRIVATE(fields)[1])); +const upb_FileDef* upb_FileDef_Dependency(const upb_FileDef* f, int i) { + UPB_ASSERT(0 <= i && i < f->dep_count); + return f->deps[i]; +} - if (!map) { - map = _upb_Decoder_CreateMap(d, entry); - *map_p = map; - } +const upb_FileDef* upb_FileDef_PublicDependency(const upb_FileDef* f, int i) { + UPB_ASSERT(0 <= i && i < f->public_dep_count); + return f->deps[f->public_deps[i]]; +} - // Parse map entry. - memset(&ent, 0, sizeof(ent)); +const upb_FileDef* upb_FileDef_WeakDependency(const upb_FileDef* f, int i) { + UPB_ASSERT(0 <= i && i < f->public_dep_count); + return f->deps[f->weak_deps[i]]; +} - if (entry->UPB_PRIVATE(fields)[1].UPB_PRIVATE(descriptortype) == - kUpb_FieldType_Message || - entry->UPB_PRIVATE(fields)[1].UPB_PRIVATE(descriptortype) == - kUpb_FieldType_Group) { - // Create proactively to handle the case where it doesn't appear. - upb_TaggedMessagePtr msg; - _upb_Decoder_NewSubMessage(d, entry->UPB_PRIVATE(subs), - &entry->UPB_PRIVATE(fields)[1], &msg); - ent.data.v.val = upb_value_uintptr(msg); - } +const upb_MessageDef* upb_FileDef_TopLevelMessage(const upb_FileDef* f, int i) { + UPB_ASSERT(0 <= i && i < f->top_lvl_msg_count); + return _upb_MessageDef_At(f->top_lvl_msgs, i); +} - ptr = _upb_Decoder_DecodeSubMessage(d, ptr, (upb_Message*)&ent.data, subs, - field, val->size); - // check if ent had any unknown fields - size_t size; - upb_Message_GetUnknown((upb_Message*)&ent.data, &size); - if (size != 0) { - char* buf; - size_t size; - uint32_t tag = - ((uint32_t)field->UPB_PRIVATE(number) << 3) | kUpb_WireType_Delimited; - upb_EncodeStatus status = - upb_Encode((upb_Message*)&ent.data, entry, 0, &d->arena, &buf, &size); - if (status != kUpb_EncodeStatus_Ok) { - _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_OutOfMemory); - } - _upb_Decoder_AddUnknownVarints(d, msg, tag, size); - if (!UPB_PRIVATE(_upb_Message_AddUnknown)(msg, buf, size, &d->arena)) { - _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_OutOfMemory); - } - } else { - if (_upb_Map_Insert(map, &ent.data.k, map->key_size, &ent.data.v, - map->val_size, - &d->arena) == kUpb_MapInsertStatus_OutOfMemory) { - _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_OutOfMemory); - } - } - return ptr; +const upb_EnumDef* upb_FileDef_TopLevelEnum(const upb_FileDef* f, int i) { + UPB_ASSERT(0 <= i && i < f->top_lvl_enum_count); + return _upb_EnumDef_At(f->top_lvl_enums, i); +} + +const upb_FieldDef* upb_FileDef_TopLevelExtension(const upb_FileDef* f, int i) { + UPB_ASSERT(0 <= i && i < f->top_lvl_ext_count); + return _upb_FieldDef_At(f->top_lvl_exts, i); } -static const char* _upb_Decoder_DecodeToSubMessage( - upb_Decoder* d, const char* ptr, upb_Message* msg, - const upb_MiniTableSub* subs, const upb_MiniTableField* field, wireval* val, - int op) { - void* mem = UPB_PTR_AT(msg, field->UPB_PRIVATE(offset), void); - int type = field->UPB_PRIVATE(descriptortype); +const upb_ServiceDef* upb_FileDef_Service(const upb_FileDef* f, int i) { + UPB_ASSERT(0 <= i && i < f->service_count); + return _upb_ServiceDef_At(f->services, i); +} - if (UPB_UNLIKELY(op == kUpb_DecodeOp_Enum) && - !_upb_Decoder_CheckEnum(d, ptr, msg, - _upb_MiniTableSubs_EnumByField(subs, field), - field, val)) { - return ptr; - } +const upb_DefPool* upb_FileDef_Pool(const upb_FileDef* f) { return f->symtab; } - /* Set presence if necessary. */ - if (field->presence > 0) { - UPB_PRIVATE(_upb_Message_SetHasbit)(msg, field); - } else if (field->presence < 0) { - /* Oneof case */ - uint32_t* oneof_case = UPB_PRIVATE(_upb_Message_OneofCasePtr)(msg, field); - if (op == kUpb_DecodeOp_SubMessage && - *oneof_case != field->UPB_PRIVATE(number)) { - memset(mem, 0, sizeof(void*)); - } - *oneof_case = field->UPB_PRIVATE(number); - } +const upb_MiniTableExtension* _upb_FileDef_ExtensionMiniTable( + const upb_FileDef* f, int i) { + return f->ext_layouts[i]; +} - /* Store into message. */ - switch (op) { - case kUpb_DecodeOp_SubMessage: { - upb_TaggedMessagePtr* submsgp = mem; - upb_Message* submsg; - if (*submsgp) { - submsg = _upb_Decoder_ReuseSubMessage(d, subs, field, submsgp); - } else { - submsg = _upb_Decoder_NewSubMessage(d, subs, field, submsgp); - } - if (UPB_UNLIKELY(type == kUpb_FieldType_Group)) { - ptr = _upb_Decoder_DecodeKnownGroup(d, ptr, submsg, subs, field); - } else { - ptr = _upb_Decoder_DecodeSubMessage(d, ptr, submsg, subs, field, - val->size); - } - break; - } - case kUpb_DecodeOp_String: - _upb_Decoder_VerifyUtf8(d, ptr, val->size); - /* Fallthrough. */ - case kUpb_DecodeOp_Bytes: - return _upb_Decoder_ReadString(d, ptr, val->size, mem); - case kUpb_DecodeOp_Scalar8Byte: - memcpy(mem, val, 8); - break; - case kUpb_DecodeOp_Enum: - case kUpb_DecodeOp_Scalar4Byte: - memcpy(mem, val, 4); - break; - case kUpb_DecodeOp_Scalar1Byte: - memcpy(mem, val, 1); - break; - default: - UPB_UNREACHABLE(); - } +static char* strviewdup(upb_DefBuilder* ctx, upb_StringView view) { + char* ret = upb_strdup2(view.data, view.size, _upb_DefBuilder_Arena(ctx)); + if (!ret) _upb_DefBuilder_OomErr(ctx); + return ret; +} - return ptr; +static bool streql_view(upb_StringView view, const char* b) { + return view.size == strlen(b) && memcmp(view.data, b, view.size) == 0; } -UPB_NOINLINE -const char* _upb_Decoder_CheckRequired(upb_Decoder* d, const char* ptr, - const upb_Message* msg, - const upb_MiniTable* m) { - UPB_ASSERT(m->UPB_PRIVATE(required_count)); - if (UPB_LIKELY((d->options & kUpb_DecodeOption_CheckRequired) == 0)) { - return ptr; - } - uint64_t msg_head; - memcpy(&msg_head, msg, 8); - msg_head = UPB_PRIVATE(_upb_BigEndian64)(msg_head); - if (UPB_PRIVATE(_upb_MiniTable_RequiredMask)(m) & ~msg_head) { - d->missing_required = true; +static int count_exts_in_msg(const UPB_DESC(DescriptorProto) * msg_proto) { + size_t n; + UPB_DESC(DescriptorProto_extension)(msg_proto, &n); + int ext_count = n; + + const UPB_DESC(DescriptorProto)* const* nested_msgs = + UPB_DESC(DescriptorProto_nested_type)(msg_proto, &n); + for (size_t i = 0; i < n; i++) { + ext_count += count_exts_in_msg(nested_msgs[i]); } - return ptr; + + return ext_count; } -UPB_FORCEINLINE -static bool _upb_Decoder_TryFastDispatch(upb_Decoder* d, const char** ptr, - upb_Message* msg, - const upb_MiniTable* m) { -#if UPB_FASTTABLE - if (m && m->UPB_PRIVATE(table_mask) != (unsigned char)-1) { - uint16_t tag = _upb_FastDecoder_LoadTag(*ptr); - intptr_t table = decode_totable(m); - *ptr = _upb_FastDecoder_TagDispatch(d, *ptr, msg, table, 0, tag); - return true; +const UPB_DESC(FeatureSet*) + _upb_FileDef_FindEdition(upb_DefBuilder* ctx, int edition) { + const UPB_DESC(FeatureSetDefaults)* defaults = + upb_DefPool_FeatureSetDefaults(ctx->symtab); + + int min = UPB_DESC(FeatureSetDefaults_minimum_edition)(defaults); + int max = UPB_DESC(FeatureSetDefaults_maximum_edition)(defaults); + if (edition < min) { + _upb_DefBuilder_Errf(ctx, + "Edition %s is earlier than the minimum edition %s " + "given in the defaults", + upb_FileDef_EditionName(edition), + upb_FileDef_EditionName(min)); + return NULL; + } + if (edition > max) { + _upb_DefBuilder_Errf(ctx, + "Edition %s is later than the maximum edition %s " + "given in the defaults", + upb_FileDef_EditionName(edition), + upb_FileDef_EditionName(max)); + return NULL; } -#endif - return false; -} -static const char* upb_Decoder_SkipField(upb_Decoder* d, const char* ptr, - uint32_t tag) { - int field_number = tag >> 3; - int wire_type = tag & 7; - switch (wire_type) { - case kUpb_WireType_Varint: { - uint64_t val; - return _upb_Decoder_DecodeVarint(d, ptr, &val); - } - case kUpb_WireType_64Bit: - return ptr + 8; - case kUpb_WireType_32Bit: - return ptr + 4; - case kUpb_WireType_Delimited: { - uint32_t size; - ptr = upb_Decoder_DecodeSize(d, ptr, &size); - return ptr + size; + size_t n; + const UPB_DESC(FeatureSetDefaults_FeatureSetEditionDefault)* const* d = + UPB_DESC(FeatureSetDefaults_defaults)(defaults, &n); + const UPB_DESC(FeatureSet)* ret = NULL; + for (size_t i = 0; i < n; i++) { + if (UPB_DESC(FeatureSetDefaults_FeatureSetEditionDefault_edition)(d[i]) > + edition) { + break; } - case kUpb_WireType_StartGroup: - return _upb_Decoder_DecodeUnknownGroup(d, ptr, field_number); - default: - _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_Malformed); + ret = UPB_DESC(FeatureSetDefaults_FeatureSetEditionDefault_features)(d[i]); + } + if (ret == NULL) { + _upb_DefBuilder_Errf(ctx, "No valid default found for edition %s", + upb_FileDef_EditionName(edition)); + return NULL; } + return ret; } -enum { - kStartItemTag = ((kUpb_MsgSet_Item << 3) | kUpb_WireType_StartGroup), - kEndItemTag = ((kUpb_MsgSet_Item << 3) | kUpb_WireType_EndGroup), - kTypeIdTag = ((kUpb_MsgSet_TypeId << 3) | kUpb_WireType_Varint), - kMessageTag = ((kUpb_MsgSet_Message << 3) | kUpb_WireType_Delimited), -}; +// Allocate and initialize one file def, and add it to the context object. +void _upb_FileDef_Create(upb_DefBuilder* ctx, + const UPB_DESC(FileDescriptorProto) * file_proto) { + upb_FileDef* file = _upb_DefBuilder_Alloc(ctx, sizeof(upb_FileDef)); + ctx->file = file; -static void upb_Decoder_AddKnownMessageSetItem( - upb_Decoder* d, upb_Message* msg, const upb_MiniTableExtension* item_mt, - const char* data, uint32_t size) { - upb_Extension* ext = - _upb_Message_GetOrCreateExtension(msg, item_mt, &d->arena); - if (UPB_UNLIKELY(!ext)) { - _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_OutOfMemory); - } - upb_Message* submsg = _upb_Decoder_NewSubMessage( - d, &ext->ext->UPB_PRIVATE(sub), upb_MiniTableExtension_AsField(ext->ext), - (upb_TaggedMessagePtr*)&ext->data); - upb_DecodeStatus status = upb_Decode( - data, size, submsg, upb_MiniTableExtension_GetSubMessage(item_mt), - d->extreg, d->options, &d->arena); - if (status != kUpb_DecodeStatus_Ok) _upb_Decoder_ErrorJmp(d, status); -} + const UPB_DESC(DescriptorProto)* const* msgs; + const UPB_DESC(EnumDescriptorProto)* const* enums; + const UPB_DESC(FieldDescriptorProto)* const* exts; + const UPB_DESC(ServiceDescriptorProto)* const* services; + const upb_StringView* strs; + const int32_t* public_deps; + const int32_t* weak_deps; + size_t n; -static void upb_Decoder_AddUnknownMessageSetItem(upb_Decoder* d, - upb_Message* msg, - uint32_t type_id, - const char* message_data, - uint32_t message_size) { - char buf[60]; - char* ptr = buf; - ptr = upb_Decoder_EncodeVarint32(kStartItemTag, ptr); - ptr = upb_Decoder_EncodeVarint32(kTypeIdTag, ptr); - ptr = upb_Decoder_EncodeVarint32(type_id, ptr); - ptr = upb_Decoder_EncodeVarint32(kMessageTag, ptr); - ptr = upb_Decoder_EncodeVarint32(message_size, ptr); - char* split = ptr; + file->symtab = ctx->symtab; - ptr = upb_Decoder_EncodeVarint32(kEndItemTag, ptr); - char* end = ptr; + // Count all extensions in the file, to build a flat array of layouts. + UPB_DESC(FileDescriptorProto_extension)(file_proto, &n); + int ext_count = n; + msgs = UPB_DESC(FileDescriptorProto_message_type)(file_proto, &n); + for (size_t i = 0; i < n; i++) { + ext_count += count_exts_in_msg(msgs[i]); + } + file->ext_count = ext_count; - if (!UPB_PRIVATE(_upb_Message_AddUnknown)(msg, buf, split - buf, &d->arena) || - !UPB_PRIVATE(_upb_Message_AddUnknown)(msg, message_data, message_size, - &d->arena) || - !UPB_PRIVATE(_upb_Message_AddUnknown)(msg, split, end - split, - &d->arena)) { - _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_OutOfMemory); + if (ctx->layout) { + // We are using the ext layouts that were passed in. + file->ext_layouts = ctx->layout->UPB_PRIVATE(exts); + const int mt_ext_count = upb_MiniTableFile_ExtensionCount(ctx->layout); + if (mt_ext_count != file->ext_count) { + _upb_DefBuilder_Errf(ctx, + "Extension count did not match layout (%d vs %d)", + mt_ext_count, file->ext_count); + } + } else { + // We are building ext layouts from scratch. + file->ext_layouts = _upb_DefBuilder_Alloc( + ctx, sizeof(*file->ext_layouts) * file->ext_count); + upb_MiniTableExtension* ext = + _upb_DefBuilder_Alloc(ctx, sizeof(*ext) * file->ext_count); + for (int i = 0; i < file->ext_count; i++) { + file->ext_layouts[i] = &ext[i]; + } } -} -static void upb_Decoder_AddMessageSetItem(upb_Decoder* d, upb_Message* msg, - const upb_MiniTable* t, - uint32_t type_id, const char* data, - uint32_t size) { - const upb_MiniTableExtension* item_mt = - upb_ExtensionRegistry_Lookup(d->extreg, t, type_id); - if (item_mt) { - upb_Decoder_AddKnownMessageSetItem(d, msg, item_mt, data, size); + upb_StringView name = UPB_DESC(FileDescriptorProto_name)(file_proto); + file->name = strviewdup(ctx, name); + if (strlen(file->name) != name.size) { + _upb_DefBuilder_Errf(ctx, "File name contained embedded NULL"); + } + + upb_StringView package = UPB_DESC(FileDescriptorProto_package)(file_proto); + + if (package.size) { + _upb_DefBuilder_CheckIdentFull(ctx, package); + file->package = strviewdup(ctx, package); } else { - upb_Decoder_AddUnknownMessageSetItem(d, msg, type_id, data, size); + file->package = NULL; } -} -static const char* upb_Decoder_DecodeMessageSetItem( - upb_Decoder* d, const char* ptr, upb_Message* msg, - const upb_MiniTable* layout) { - uint32_t type_id = 0; - upb_StringView preserved = {NULL, 0}; - typedef enum { - kUpb_HaveId = 1 << 0, - kUpb_HavePayload = 1 << 1, - } StateMask; - StateMask state_mask = 0; - while (!_upb_Decoder_IsDone(d, &ptr)) { - uint32_t tag; - ptr = _upb_Decoder_DecodeTag(d, ptr, &tag); - switch (tag) { - case kEndItemTag: - return ptr; - case kTypeIdTag: { - uint64_t tmp; - ptr = _upb_Decoder_DecodeVarint(d, ptr, &tmp); - if (state_mask & kUpb_HaveId) break; // Ignore dup. - state_mask |= kUpb_HaveId; - type_id = tmp; - if (state_mask & kUpb_HavePayload) { - upb_Decoder_AddMessageSetItem(d, msg, layout, type_id, preserved.data, - preserved.size); - } - break; - } - case kMessageTag: { - uint32_t size; - ptr = upb_Decoder_DecodeSize(d, ptr, &size); - const char* data = ptr; - ptr += size; - if (state_mask & kUpb_HavePayload) break; // Ignore dup. - state_mask |= kUpb_HavePayload; - if (state_mask & kUpb_HaveId) { - upb_Decoder_AddMessageSetItem(d, msg, layout, type_id, data, size); - } else { - // Out of order, we must preserve the payload. - preserved.data = data; - preserved.size = size; - } - break; - } - default: - // We do not preserve unexpected fields inside a message set item. - ptr = upb_Decoder_SkipField(d, ptr, tag); - break; + // TODO: How should we validate this? + file->edition = UPB_DESC(FileDescriptorProto_edition)(file_proto); + + if (UPB_DESC(FileDescriptorProto_has_syntax)(file_proto)) { + upb_StringView syntax = UPB_DESC(FileDescriptorProto_syntax)(file_proto); + + if (streql_view(syntax, "proto2")) { + file->syntax = kUpb_Syntax_Proto2; + file->edition = UPB_DESC(EDITION_PROTO2); + } else if (streql_view(syntax, "proto3")) { + file->syntax = kUpb_Syntax_Proto3; + file->edition = UPB_DESC(EDITION_PROTO3); + } else if (streql_view(syntax, "editions")) { + file->syntax = kUpb_Syntax_Editions; + file->edition = UPB_DESC(FileDescriptorProto_edition)(file_proto); + } else { + _upb_DefBuilder_Errf(ctx, "Invalid syntax '" UPB_STRINGVIEW_FORMAT "'", + UPB_STRINGVIEW_ARGS(syntax)); } + } else { + file->syntax = kUpb_Syntax_Proto2; + file->edition = UPB_DESC(EDITION_PROTO2); } - _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_Malformed); -} -static const upb_MiniTableField* _upb_Decoder_FindField(upb_Decoder* d, - const upb_MiniTable* t, - uint32_t field_number, - int* last_field_index) { - static upb_MiniTableField none = { - 0, 0, 0, 0, kUpb_FakeFieldType_FieldNotFound, 0}; - if (t == NULL) return &none; + // Read options. + UPB_DEF_SET_OPTIONS(file->opts, FileDescriptorProto, FileOptions, file_proto); - size_t idx = ((size_t)field_number) - 1; // 0 wraps to SIZE_MAX - if (idx < t->UPB_PRIVATE(dense_below)) { - /* Fastest case: index into dense fields. */ - goto found; - } + // Resolve features. + const UPB_DESC(FeatureSet*) edition_defaults = + _upb_FileDef_FindEdition(ctx, file->edition); + const UPB_DESC(FeatureSet*) unresolved = + UPB_DESC(FileOptions_features)(file->opts); + file->resolved_features = + _upb_DefBuilder_ResolveFeatures(ctx, edition_defaults, unresolved); - if (t->UPB_PRIVATE(dense_below) < t->UPB_PRIVATE(field_count)) { - /* Linear search non-dense fields. Resume scanning from last_field_index - * since fields are usually in order. */ - size_t last = *last_field_index; - for (idx = last; idx < t->UPB_PRIVATE(field_count); idx++) { - if (t->UPB_PRIVATE(fields)[idx].UPB_PRIVATE(number) == field_number) { - goto found; - } + // Verify dependencies. + strs = UPB_DESC(FileDescriptorProto_dependency)(file_proto, &n); + file->dep_count = n; + file->deps = _upb_DefBuilder_Alloc(ctx, sizeof(*file->deps) * n); + + for (size_t i = 0; i < n; i++) { + upb_StringView str = strs[i]; + file->deps[i] = + upb_DefPool_FindFileByNameWithSize(ctx->symtab, str.data, str.size); + if (!file->deps[i]) { + _upb_DefBuilder_Errf(ctx, + "Depends on file '" UPB_STRINGVIEW_FORMAT + "', but it has not been loaded", + UPB_STRINGVIEW_ARGS(str)); } + } - for (idx = t->UPB_PRIVATE(dense_below); idx < last; idx++) { - if (t->UPB_PRIVATE(fields)[idx].UPB_PRIVATE(number) == field_number) { - goto found; - } + public_deps = UPB_DESC(FileDescriptorProto_public_dependency)(file_proto, &n); + file->public_dep_count = n; + file->public_deps = + _upb_DefBuilder_Alloc(ctx, sizeof(*file->public_deps) * n); + int32_t* mutable_public_deps = (int32_t*)file->public_deps; + for (size_t i = 0; i < n; i++) { + if (public_deps[i] >= file->dep_count) { + _upb_DefBuilder_Errf(ctx, "public_dep %d is out of range", + (int)public_deps[i]); } + mutable_public_deps[i] = public_deps[i]; } - if (d->extreg) { - switch (t->UPB_PRIVATE(ext)) { - case kUpb_ExtMode_Extendable: { - const upb_MiniTableExtension* ext = - upb_ExtensionRegistry_Lookup(d->extreg, t, field_number); - if (ext) return upb_MiniTableExtension_AsField(ext); - break; - } - case kUpb_ExtMode_IsMessageSet: - if (field_number == kUpb_MsgSet_Item) { - static upb_MiniTableField item = { - 0, 0, 0, 0, kUpb_FakeFieldType_MessageSetItem, 0}; - return &item; - } - break; + weak_deps = UPB_DESC(FileDescriptorProto_weak_dependency)(file_proto, &n); + file->weak_dep_count = n; + file->weak_deps = _upb_DefBuilder_Alloc(ctx, sizeof(*file->weak_deps) * n); + int32_t* mutable_weak_deps = (int32_t*)file->weak_deps; + for (size_t i = 0; i < n; i++) { + if (weak_deps[i] >= file->dep_count) { + _upb_DefBuilder_Errf(ctx, "weak_dep %d is out of range", + (int)weak_deps[i]); } + mutable_weak_deps[i] = weak_deps[i]; } - return &none; /* Unknown field. */ + // Create enums. + enums = UPB_DESC(FileDescriptorProto_enum_type)(file_proto, &n); + file->top_lvl_enum_count = n; + file->top_lvl_enums = + _upb_EnumDefs_New(ctx, n, enums, file->resolved_features, NULL); -found: - UPB_ASSERT(t->UPB_PRIVATE(fields)[idx].UPB_PRIVATE(number) == field_number); - *last_field_index = idx; - return &t->UPB_PRIVATE(fields)[idx]; -} + // Create extensions. + exts = UPB_DESC(FileDescriptorProto_extension)(file_proto, &n); + file->top_lvl_ext_count = n; + file->top_lvl_exts = _upb_Extensions_New( + ctx, n, exts, file->resolved_features, file->package, NULL); -int _upb_Decoder_GetVarintOp(const upb_MiniTableField* field) { - static const int8_t kVarintOps[] = { - [kUpb_FakeFieldType_FieldNotFound] = kUpb_DecodeOp_UnknownField, - [kUpb_FieldType_Double] = kUpb_DecodeOp_UnknownField, - [kUpb_FieldType_Float] = kUpb_DecodeOp_UnknownField, - [kUpb_FieldType_Int64] = kUpb_DecodeOp_Scalar8Byte, - [kUpb_FieldType_UInt64] = kUpb_DecodeOp_Scalar8Byte, - [kUpb_FieldType_Int32] = kUpb_DecodeOp_Scalar4Byte, - [kUpb_FieldType_Fixed64] = kUpb_DecodeOp_UnknownField, - [kUpb_FieldType_Fixed32] = kUpb_DecodeOp_UnknownField, - [kUpb_FieldType_Bool] = kUpb_DecodeOp_Scalar1Byte, - [kUpb_FieldType_String] = kUpb_DecodeOp_UnknownField, - [kUpb_FieldType_Group] = kUpb_DecodeOp_UnknownField, - [kUpb_FieldType_Message] = kUpb_DecodeOp_UnknownField, - [kUpb_FieldType_Bytes] = kUpb_DecodeOp_UnknownField, - [kUpb_FieldType_UInt32] = kUpb_DecodeOp_Scalar4Byte, - [kUpb_FieldType_Enum] = kUpb_DecodeOp_Enum, - [kUpb_FieldType_SFixed32] = kUpb_DecodeOp_UnknownField, - [kUpb_FieldType_SFixed64] = kUpb_DecodeOp_UnknownField, - [kUpb_FieldType_SInt32] = kUpb_DecodeOp_Scalar4Byte, - [kUpb_FieldType_SInt64] = kUpb_DecodeOp_Scalar8Byte, - [kUpb_FakeFieldType_MessageSetItem] = kUpb_DecodeOp_UnknownField, - }; + // Create messages. + msgs = UPB_DESC(FileDescriptorProto_message_type)(file_proto, &n); + file->top_lvl_msg_count = n; + file->top_lvl_msgs = + _upb_MessageDefs_New(ctx, n, msgs, file->resolved_features, NULL); - return kVarintOps[field->UPB_PRIVATE(descriptortype)]; -} + // Create services. + services = UPB_DESC(FileDescriptorProto_service)(file_proto, &n); + file->service_count = n; + file->services = + _upb_ServiceDefs_New(ctx, n, services, file->resolved_features); -UPB_FORCEINLINE -static void _upb_Decoder_CheckUnlinked(upb_Decoder* d, const upb_MiniTable* mt, - const upb_MiniTableField* field, - int* op) { - // If sub-message is not linked, treat as unknown. - if (field->UPB_PRIVATE(mode) & kUpb_LabelFlags_IsExtension) return; - const upb_MiniTable* mt_sub = - _upb_MiniTableSubs_MessageByField(mt->UPB_PRIVATE(subs), field); - if ((d->options & kUpb_DecodeOption_ExperimentalAllowUnlinked) || - !UPB_PRIVATE(_upb_MiniTable_IsEmpty)(mt_sub)) { - return; - } -#ifndef NDEBUG - const upb_MiniTableField* oneof = upb_MiniTable_GetOneof(mt, field); - if (oneof) { - // All other members of the oneof must be message fields that are also - // unlinked. - do { - UPB_ASSERT(upb_MiniTableField_CType(oneof) == kUpb_CType_Message); - const upb_MiniTableSub* oneof_sub = - &mt->UPB_PRIVATE(subs)[oneof->UPB_PRIVATE(submsg_index)]; - UPB_ASSERT(!oneof_sub); - } while (upb_MiniTable_NextOneofField(mt, &oneof)); + // Now that all names are in the table, build layouts and resolve refs. + + for (int i = 0; i < file->top_lvl_msg_count; i++) { + upb_MessageDef* m = (upb_MessageDef*)upb_FileDef_TopLevelMessage(file, i); + _upb_MessageDef_Resolve(ctx, m); } -#endif // NDEBUG - *op = kUpb_DecodeOp_UnknownField; -} -int _upb_Decoder_GetDelimitedOp(upb_Decoder* d, const upb_MiniTable* mt, - const upb_MiniTableField* field) { - enum { kRepeatedBase = 19 }; + for (int i = 0; i < file->top_lvl_ext_count; i++) { + upb_FieldDef* f = (upb_FieldDef*)upb_FileDef_TopLevelExtension(file, i); + _upb_FieldDef_Resolve(ctx, file->package, f); + } - static const int8_t kDelimitedOps[] = { - /* For non-repeated field type. */ - [kUpb_FakeFieldType_FieldNotFound] = - kUpb_DecodeOp_UnknownField, // Field not found. - [kUpb_FieldType_Double] = kUpb_DecodeOp_UnknownField, - [kUpb_FieldType_Float] = kUpb_DecodeOp_UnknownField, - [kUpb_FieldType_Int64] = kUpb_DecodeOp_UnknownField, - [kUpb_FieldType_UInt64] = kUpb_DecodeOp_UnknownField, - [kUpb_FieldType_Int32] = kUpb_DecodeOp_UnknownField, - [kUpb_FieldType_Fixed64] = kUpb_DecodeOp_UnknownField, - [kUpb_FieldType_Fixed32] = kUpb_DecodeOp_UnknownField, - [kUpb_FieldType_Bool] = kUpb_DecodeOp_UnknownField, - [kUpb_FieldType_String] = kUpb_DecodeOp_String, - [kUpb_FieldType_Group] = kUpb_DecodeOp_UnknownField, - [kUpb_FieldType_Message] = kUpb_DecodeOp_SubMessage, - [kUpb_FieldType_Bytes] = kUpb_DecodeOp_Bytes, - [kUpb_FieldType_UInt32] = kUpb_DecodeOp_UnknownField, - [kUpb_FieldType_Enum] = kUpb_DecodeOp_UnknownField, - [kUpb_FieldType_SFixed32] = kUpb_DecodeOp_UnknownField, - [kUpb_FieldType_SFixed64] = kUpb_DecodeOp_UnknownField, - [kUpb_FieldType_SInt32] = kUpb_DecodeOp_UnknownField, - [kUpb_FieldType_SInt64] = kUpb_DecodeOp_UnknownField, - [kUpb_FakeFieldType_MessageSetItem] = kUpb_DecodeOp_UnknownField, - // For repeated field type. */ - [kRepeatedBase + kUpb_FieldType_Double] = OP_FIXPCK_LG2(3), - [kRepeatedBase + kUpb_FieldType_Float] = OP_FIXPCK_LG2(2), - [kRepeatedBase + kUpb_FieldType_Int64] = OP_VARPCK_LG2(3), - [kRepeatedBase + kUpb_FieldType_UInt64] = OP_VARPCK_LG2(3), - [kRepeatedBase + kUpb_FieldType_Int32] = OP_VARPCK_LG2(2), - [kRepeatedBase + kUpb_FieldType_Fixed64] = OP_FIXPCK_LG2(3), - [kRepeatedBase + kUpb_FieldType_Fixed32] = OP_FIXPCK_LG2(2), - [kRepeatedBase + kUpb_FieldType_Bool] = OP_VARPCK_LG2(0), - [kRepeatedBase + kUpb_FieldType_String] = kUpb_DecodeOp_String, - [kRepeatedBase + kUpb_FieldType_Group] = kUpb_DecodeOp_SubMessage, - [kRepeatedBase + kUpb_FieldType_Message] = kUpb_DecodeOp_SubMessage, - [kRepeatedBase + kUpb_FieldType_Bytes] = kUpb_DecodeOp_Bytes, - [kRepeatedBase + kUpb_FieldType_UInt32] = OP_VARPCK_LG2(2), - [kRepeatedBase + kUpb_FieldType_Enum] = kUpb_DecodeOp_PackedEnum, - [kRepeatedBase + kUpb_FieldType_SFixed32] = OP_FIXPCK_LG2(2), - [kRepeatedBase + kUpb_FieldType_SFixed64] = OP_FIXPCK_LG2(3), - [kRepeatedBase + kUpb_FieldType_SInt32] = OP_VARPCK_LG2(2), - [kRepeatedBase + kUpb_FieldType_SInt64] = OP_VARPCK_LG2(3), - // Omitting kUpb_FakeFieldType_MessageSetItem, because we never emit a - // repeated msgset type - }; + for (int i = 0; i < file->top_lvl_msg_count; i++) { + upb_MessageDef* m = (upb_MessageDef*)upb_FileDef_TopLevelMessage(file, i); + _upb_MessageDef_CreateMiniTable(ctx, (upb_MessageDef*)m); + } - int ndx = field->UPB_PRIVATE(descriptortype); - if (upb_MiniTableField_IsArray(field)) ndx += kRepeatedBase; - int op = kDelimitedOps[ndx]; + for (int i = 0; i < file->top_lvl_ext_count; i++) { + upb_FieldDef* f = (upb_FieldDef*)upb_FileDef_TopLevelExtension(file, i); + _upb_FieldDef_BuildMiniTableExtension(ctx, f); + } - if (op == kUpb_DecodeOp_SubMessage) { - _upb_Decoder_CheckUnlinked(d, mt, field, &op); + for (int i = 0; i < file->top_lvl_msg_count; i++) { + upb_MessageDef* m = (upb_MessageDef*)upb_FileDef_TopLevelMessage(file, i); + _upb_MessageDef_LinkMiniTable(ctx, m); } - return op; + if (file->ext_count) { + bool ok = upb_ExtensionRegistry_AddArray( + _upb_DefPool_ExtReg(ctx->symtab), file->ext_layouts, file->ext_count); + if (!ok) _upb_DefBuilder_OomErr(ctx); + } } -UPB_FORCEINLINE -static const char* _upb_Decoder_DecodeWireValue(upb_Decoder* d, const char* ptr, - const upb_MiniTable* mt, - const upb_MiniTableField* field, - int wire_type, wireval* val, - int* op) { - static const unsigned kFixed32OkMask = (1 << kUpb_FieldType_Float) | - (1 << kUpb_FieldType_Fixed32) | - (1 << kUpb_FieldType_SFixed32); - static const unsigned kFixed64OkMask = (1 << kUpb_FieldType_Double) | - (1 << kUpb_FieldType_Fixed64) | - (1 << kUpb_FieldType_SFixed64); +#include - switch (wire_type) { - case kUpb_WireType_Varint: - ptr = _upb_Decoder_DecodeVarint(d, ptr, &val->uint64_val); - *op = _upb_Decoder_GetVarintOp(field); - _upb_Decoder_Munge(field->UPB_PRIVATE(descriptortype), val); - return ptr; - case kUpb_WireType_32Bit: - *op = kUpb_DecodeOp_Scalar4Byte; - if (((1 << field->UPB_PRIVATE(descriptortype)) & kFixed32OkMask) == 0) { - *op = kUpb_DecodeOp_UnknownField; - } - return upb_WireReader_ReadFixed32(ptr, &val->uint32_val); - case kUpb_WireType_64Bit: - *op = kUpb_DecodeOp_Scalar8Byte; - if (((1 << field->UPB_PRIVATE(descriptortype)) & kFixed64OkMask) == 0) { - *op = kUpb_DecodeOp_UnknownField; - } - return upb_WireReader_ReadFixed64(ptr, &val->uint64_val); - case kUpb_WireType_Delimited: - ptr = upb_Decoder_DecodeSize(d, ptr, &val->size); - *op = _upb_Decoder_GetDelimitedOp(d, mt, field); - return ptr; - case kUpb_WireType_StartGroup: - val->uint32_val = field->UPB_PRIVATE(number); - if (field->UPB_PRIVATE(descriptortype) == kUpb_FieldType_Group) { - *op = kUpb_DecodeOp_SubMessage; - _upb_Decoder_CheckUnlinked(d, mt, field, op); - } else if (field->UPB_PRIVATE(descriptortype) == - kUpb_FakeFieldType_MessageSetItem) { - *op = kUpb_DecodeOp_MessageSetItem; - } else { - *op = kUpb_DecodeOp_UnknownField; - } - return ptr; - default: - break; - } - _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_Malformed); -} -UPB_FORCEINLINE -static const char* _upb_Decoder_DecodeKnownField( - upb_Decoder* d, const char* ptr, upb_Message* msg, - const upb_MiniTable* layout, const upb_MiniTableField* field, int op, - wireval* val) { - const upb_MiniTableSub* subs = layout->UPB_PRIVATE(subs); - uint8_t mode = field->UPB_PRIVATE(mode); +// Must be last. - if (UPB_UNLIKELY(mode & kUpb_LabelFlags_IsExtension)) { - const upb_MiniTableExtension* ext_layout = - (const upb_MiniTableExtension*)field; - upb_Extension* ext = - _upb_Message_GetOrCreateExtension(msg, ext_layout, &d->arena); - if (UPB_UNLIKELY(!ext)) { - _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_OutOfMemory); - } - d->unknown_msg = msg; - msg = (upb_Message*)&ext->data; - subs = &ext->ext->UPB_PRIVATE(sub); - } +/* The upb core does not generally have a concept of default instances. However + * for descriptor options we make an exception since the max size is known and + * modest (<200 bytes). All types can share a default instance since it is + * initialized to zeroes. + * + * We have to allocate an extra pointer for upb's internal metadata. */ +static UPB_ALIGN_AS(8) const + char opt_default_buf[_UPB_MAXOPT_SIZE + sizeof(void*)] = {0}; +const char* kUpbDefOptDefault = &opt_default_buf[sizeof(void*)]; - switch (mode & kUpb_FieldMode_Mask) { - case kUpb_FieldMode_Array: - return _upb_Decoder_DecodeToArray(d, ptr, msg, subs, field, val, op); - case kUpb_FieldMode_Map: - return _upb_Decoder_DecodeToMap(d, ptr, msg, subs, field, val); - case kUpb_FieldMode_Scalar: - return _upb_Decoder_DecodeToSubMessage(d, ptr, msg, subs, field, val, op); - default: - UPB_UNREACHABLE(); +const char* _upb_DefBuilder_FullToShort(const char* fullname) { + const char* p; + + if (fullname == NULL) { + return NULL; + } else if ((p = strrchr(fullname, '.')) == NULL) { + /* No '.' in the name, return the full string. */ + return fullname; + } else { + /* Return one past the last '.'. */ + return p + 1; } } -static const char* _upb_Decoder_ReverseSkipVarint(const char* ptr, - uint32_t val) { - uint32_t seen = 0; - do { - ptr--; - seen <<= 7; - seen |= *ptr & 0x7f; - } while (seen != val); - return ptr; +void _upb_DefBuilder_FailJmp(upb_DefBuilder* ctx) { UPB_LONGJMP(ctx->err, 1); } + +void _upb_DefBuilder_Errf(upb_DefBuilder* ctx, const char* fmt, ...) { + va_list argp; + va_start(argp, fmt); + upb_Status_VSetErrorFormat(ctx->status, fmt, argp); + va_end(argp); + _upb_DefBuilder_FailJmp(ctx); } -static const char* _upb_Decoder_DecodeUnknownField(upb_Decoder* d, - const char* ptr, - upb_Message* msg, - int field_number, - int wire_type, wireval val) { - if (field_number == 0) _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_Malformed); +void _upb_DefBuilder_OomErr(upb_DefBuilder* ctx) { + upb_Status_SetErrorMessage(ctx->status, "out of memory"); + _upb_DefBuilder_FailJmp(ctx); +} - // Since unknown fields are the uncommon case, we do a little extra work here - // to walk backwards through the buffer to find the field start. This frees - // up a register in the fast paths (when the field is known), which leads to - // significant speedups in benchmarks. - const char* start = ptr; +// Verify a relative identifier string. The loop is branchless for speed. +static void _upb_DefBuilder_CheckIdentNotFull(upb_DefBuilder* ctx, + upb_StringView name) { + bool good = name.size > 0; - if (wire_type == kUpb_WireType_Delimited) ptr += val.size; - if (msg) { - switch (wire_type) { - case kUpb_WireType_Varint: - case kUpb_WireType_Delimited: - start--; - while (start[-1] & 0x80) start--; - break; - case kUpb_WireType_32Bit: - start -= 4; - break; - case kUpb_WireType_64Bit: - start -= 8; - break; - default: - break; + for (size_t i = 0; i < name.size; i++) { + const char c = name.data[i]; + const char d = c | 0x20; // force lowercase + const bool is_alpha = (('a' <= d) & (d <= 'z')) | (c == '_'); + const bool is_numer = ('0' <= c) & (c <= '9') & (i != 0); + + good &= is_alpha | is_numer; + } + + if (!good) _upb_DefBuilder_CheckIdentSlow(ctx, name, false); +} + +const char* _upb_DefBuilder_MakeFullName(upb_DefBuilder* ctx, + const char* prefix, + upb_StringView name) { + _upb_DefBuilder_CheckIdentNotFull(ctx, name); + if (prefix) { + // ret = prefix + '.' + name; + size_t n = strlen(prefix); + char* ret = _upb_DefBuilder_Alloc(ctx, n + name.size + 2); + strcpy(ret, prefix); + ret[n] = '.'; + memcpy(&ret[n + 1], name.data, name.size); + ret[n + 1 + name.size] = '\0'; + return ret; + } else { + char* ret = upb_strdup2(name.data, name.size, ctx->arena); + if (!ret) _upb_DefBuilder_OomErr(ctx); + return ret; + } +} + +static bool remove_component(char* base, size_t* len) { + if (*len == 0) return false; + + for (size_t i = *len - 1; i > 0; i--) { + if (base[i] == '.') { + *len = i; + return true; } + } - assert(start == d->debug_valstart); - uint32_t tag = ((uint32_t)field_number << 3) | wire_type; - start = _upb_Decoder_ReverseSkipVarint(start, tag); - assert(start == d->debug_tagstart); + *len = 0; + return true; +} - if (wire_type == kUpb_WireType_StartGroup) { - d->unknown = start; - d->unknown_msg = msg; - ptr = _upb_Decoder_DecodeUnknownGroup(d, ptr, field_number); - start = d->unknown; - d->unknown = NULL; +const void* _upb_DefBuilder_ResolveAny(upb_DefBuilder* ctx, + const char* from_name_dbg, + const char* base, upb_StringView sym, + upb_deftype_t* type) { + if (sym.size == 0) goto notfound; + upb_value v; + if (sym.data[0] == '.') { + // Symbols starting with '.' are absolute, so we do a single lookup. + // Slice to omit the leading '.' + if (!_upb_DefPool_LookupSym(ctx->symtab, sym.data + 1, sym.size - 1, &v)) { + goto notfound; } - if (!UPB_PRIVATE(_upb_Message_AddUnknown)(msg, start, ptr - start, - &d->arena)) { - _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_OutOfMemory); + } else { + // Remove components from base until we find an entry or run out. + size_t baselen = base ? strlen(base) : 0; + char* tmp = upb_gmalloc(sym.size + baselen + 1); + while (1) { + char* p = tmp; + if (baselen) { + memcpy(p, base, baselen); + p[baselen] = '.'; + p += baselen + 1; + } + memcpy(p, sym.data, sym.size); + p += sym.size; + if (_upb_DefPool_LookupSym(ctx->symtab, tmp, p - tmp, &v)) { + break; + } + if (!remove_component(tmp, &baselen)) { + upb_gfree(tmp); + goto notfound; + } } - } else if (wire_type == kUpb_WireType_StartGroup) { - ptr = _upb_Decoder_DecodeUnknownGroup(d, ptr, field_number); + upb_gfree(tmp); } - return ptr; -} -UPB_NOINLINE -static const char* _upb_Decoder_DecodeMessage(upb_Decoder* d, const char* ptr, - upb_Message* msg, - const upb_MiniTable* layout) { - int last_field_index = 0; + *type = _upb_DefType_Type(v); + return _upb_DefType_Unpack(v, *type); -#if UPB_FASTTABLE - // The first time we want to skip fast dispatch, because we may have just been - // invoked by the fast parser to handle a case that it bailed on. - if (!_upb_Decoder_IsDone(d, &ptr)) goto nofast; -#endif +notfound: + _upb_DefBuilder_Errf(ctx, "couldn't resolve name '" UPB_STRINGVIEW_FORMAT "'", + UPB_STRINGVIEW_ARGS(sym)); +} - while (!_upb_Decoder_IsDone(d, &ptr)) { - uint32_t tag; - const upb_MiniTableField* field; - int field_number; - int wire_type; - wireval val; - int op; +const void* _upb_DefBuilder_Resolve(upb_DefBuilder* ctx, + const char* from_name_dbg, const char* base, + upb_StringView sym, upb_deftype_t type) { + upb_deftype_t found_type; + const void* ret = + _upb_DefBuilder_ResolveAny(ctx, from_name_dbg, base, sym, &found_type); + if (ret && found_type != type) { + _upb_DefBuilder_Errf(ctx, + "type mismatch when resolving %s: couldn't find " + "name " UPB_STRINGVIEW_FORMAT " with type=%d", + from_name_dbg, UPB_STRINGVIEW_ARGS(sym), (int)type); + } + return ret; +} - if (_upb_Decoder_TryFastDispatch(d, &ptr, msg, layout)) break; +// Per ASCII this will lower-case a letter. If the result is a letter, the +// input was definitely a letter. If the output is not a letter, this may +// have transformed the character unpredictably. +static char upb_ascii_lower(char ch) { return ch | 0x20; } -#if UPB_FASTTABLE - nofast: -#endif +// isalpha() etc. from are locale-dependent, which we don't want. +static bool upb_isbetween(uint8_t c, uint8_t low, uint8_t high) { + return low <= c && c <= high; +} -#ifndef NDEBUG - d->debug_tagstart = ptr; -#endif +static bool upb_isletter(char c) { + char lower = upb_ascii_lower(c); + return upb_isbetween(lower, 'a', 'z') || c == '_'; +} - UPB_ASSERT(ptr < d->input.limit_ptr); - ptr = _upb_Decoder_DecodeTag(d, ptr, &tag); - field_number = tag >> 3; - wire_type = tag & 7; +static bool upb_isalphanum(char c) { + return upb_isletter(c) || upb_isbetween(c, '0', '9'); +} -#ifndef NDEBUG - d->debug_valstart = ptr; -#endif +static bool TryGetChar(const char** src, const char* end, char* ch) { + if (*src == end) return false; + *ch = **src; + *src += 1; + return true; +} - if (wire_type == kUpb_WireType_EndGroup) { - d->end_group = field_number; - return ptr; - } +static int TryGetHexDigit(const char** src, const char* end) { + char ch; + if (!TryGetChar(src, end, &ch)) return -1; + if ('0' <= ch && ch <= '9') { + return ch - '0'; + } + ch = upb_ascii_lower(ch); + if ('a' <= ch && ch <= 'f') { + return ch - 'a' + 0xa; + } + *src -= 1; // Char wasn't actually a hex digit. + return -1; +} - field = _upb_Decoder_FindField(d, layout, field_number, &last_field_index); - ptr = _upb_Decoder_DecodeWireValue(d, ptr, layout, field, wire_type, &val, - &op); +static char upb_DefBuilder_ParseHexEscape(upb_DefBuilder* ctx, + const upb_FieldDef* f, + const char** src, const char* end) { + int hex_digit = TryGetHexDigit(src, end); + if (hex_digit < 0) { + _upb_DefBuilder_Errf( + ctx, "\\x must be followed by at least one hex digit (field='%s')", + upb_FieldDef_FullName(f)); + return 0; + } + unsigned int ret = hex_digit; + while ((hex_digit = TryGetHexDigit(src, end)) >= 0) { + ret = (ret << 4) | hex_digit; + } + if (ret > 0xff) { + _upb_DefBuilder_Errf(ctx, "Value of hex escape in field %s exceeds 8 bits", + upb_FieldDef_FullName(f)); + return 0; + } + return ret; +} - if (op >= 0) { - ptr = _upb_Decoder_DecodeKnownField(d, ptr, msg, layout, field, op, &val); - } else { - switch (op) { - case kUpb_DecodeOp_UnknownField: - ptr = _upb_Decoder_DecodeUnknownField(d, ptr, msg, field_number, - wire_type, val); - break; - case kUpb_DecodeOp_MessageSetItem: - ptr = upb_Decoder_DecodeMessageSetItem(d, ptr, msg, layout); - break; - } +static char TryGetOctalDigit(const char** src, const char* end) { + char ch; + if (!TryGetChar(src, end, &ch)) return -1; + if ('0' <= ch && ch <= '7') { + return ch - '0'; + } + *src -= 1; // Char wasn't actually an octal digit. + return -1; +} + +static char upb_DefBuilder_ParseOctalEscape(upb_DefBuilder* ctx, + const upb_FieldDef* f, + const char** src, const char* end) { + char ch = 0; + for (int i = 0; i < 3; i++) { + char digit; + if ((digit = TryGetOctalDigit(src, end)) >= 0) { + ch = (ch << 3) | digit; } } - - return UPB_UNLIKELY(layout && layout->UPB_PRIVATE(required_count)) - ? _upb_Decoder_CheckRequired(d, ptr, msg, layout) - : ptr; -} - -const char* _upb_FastDecoder_DecodeGeneric(struct upb_Decoder* d, - const char* ptr, upb_Message* msg, - intptr_t table, uint64_t hasbits, - uint64_t data) { - (void)data; - *(uint32_t*)msg |= hasbits; - return _upb_Decoder_DecodeMessage(d, ptr, msg, decode_totablep(table)); + return ch; +} + +char _upb_DefBuilder_ParseEscape(upb_DefBuilder* ctx, const upb_FieldDef* f, + const char** src, const char* end) { + char ch; + if (!TryGetChar(src, end, &ch)) { + _upb_DefBuilder_Errf(ctx, "unterminated escape sequence in field %s", + upb_FieldDef_FullName(f)); + return 0; + } + switch (ch) { + case 'a': + return '\a'; + case 'b': + return '\b'; + case 'f': + return '\f'; + case 'n': + return '\n'; + case 'r': + return '\r'; + case 't': + return '\t'; + case 'v': + return '\v'; + case '\\': + return '\\'; + case '\'': + return '\''; + case '\"': + return '\"'; + case '?': + return '\?'; + case 'x': + case 'X': + return upb_DefBuilder_ParseHexEscape(ctx, f, src, end); + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + *src -= 1; + return upb_DefBuilder_ParseOctalEscape(ctx, f, src, end); + } + _upb_DefBuilder_Errf(ctx, "Unknown escape sequence: \\%c", ch); } -static upb_DecodeStatus _upb_Decoder_DecodeTop(struct upb_Decoder* d, - const char* buf, void* msg, - const upb_MiniTable* l) { - if (!_upb_Decoder_TryFastDispatch(d, &buf, msg, l)) { - _upb_Decoder_DecodeMessage(d, buf, msg, l); +void _upb_DefBuilder_CheckIdentSlow(upb_DefBuilder* ctx, upb_StringView name, + bool full) { + const char* str = name.data; + const size_t len = name.size; + bool start = true; + for (size_t i = 0; i < len; i++) { + const char c = str[i]; + if (c == '.') { + if (start || !full) { + _upb_DefBuilder_Errf( + ctx, "invalid name: unexpected '.' (" UPB_STRINGVIEW_FORMAT ")", + UPB_STRINGVIEW_ARGS(name)); + } + start = true; + } else if (start) { + if (!upb_isletter(c)) { + _upb_DefBuilder_Errf(ctx, + "invalid name: path components must start with a " + "letter (" UPB_STRINGVIEW_FORMAT ")", + UPB_STRINGVIEW_ARGS(name)); + } + start = false; + } else if (!upb_isalphanum(c)) { + _upb_DefBuilder_Errf( + ctx, + "invalid name: non-alphanumeric character (" UPB_STRINGVIEW_FORMAT + ")", + UPB_STRINGVIEW_ARGS(name)); + } + } + if (start) { + _upb_DefBuilder_Errf(ctx, + "invalid name: empty part (" UPB_STRINGVIEW_FORMAT ")", + UPB_STRINGVIEW_ARGS(name)); } - if (d->end_group != DECODE_NOGROUP) return kUpb_DecodeStatus_Malformed; - if (d->missing_required) return kUpb_DecodeStatus_MissingRequired; - return kUpb_DecodeStatus_Ok; -} -UPB_NOINLINE -const char* _upb_Decoder_IsDoneFallback(upb_EpsCopyInputStream* e, - const char* ptr, int overrun) { - return _upb_EpsCopyInputStream_IsDoneFallbackInline( - e, ptr, overrun, _upb_Decoder_BufferFlipCallback); + // We should never reach this point. + UPB_ASSERT(false); } -static upb_DecodeStatus upb_Decoder_Decode(upb_Decoder* const decoder, - const char* const buf, - void* const msg, - const upb_MiniTable* const l, - upb_Arena* const arena) { - if (UPB_SETJMP(decoder->err) == 0) { - decoder->status = _upb_Decoder_DecodeTop(decoder, buf, msg, l); - } else { - UPB_ASSERT(decoder->status != kUpb_DecodeStatus_Ok); +upb_StringView _upb_DefBuilder_MakeKey(upb_DefBuilder* ctx, + const UPB_DESC(FeatureSet*) parent, + upb_StringView key) { + size_t need = key.size + sizeof(void*); + if (ctx->tmp_buf_size < need) { + ctx->tmp_buf_size = UPB_MAX(64, upb_Log2Ceiling(need)); + ctx->tmp_buf = upb_Arena_Malloc(ctx->tmp_arena, ctx->tmp_buf_size); + if (!ctx->tmp_buf) _upb_DefBuilder_OomErr(ctx); } - UPB_PRIVATE(_upb_Arena_SwapOut)(arena, &decoder->arena); - - return decoder->status; + memcpy(ctx->tmp_buf, &parent, sizeof(void*)); + memcpy(ctx->tmp_buf + sizeof(void*), key.data, key.size); + return upb_StringView_FromDataAndSize(ctx->tmp_buf, need); } -upb_DecodeStatus upb_Decode(const char* buf, size_t size, upb_Message* msg, - const upb_MiniTable* l, - const upb_ExtensionRegistry* extreg, int options, - upb_Arena* arena) { - upb_Decoder decoder; - unsigned depth = (unsigned)options >> 16; - - upb_EpsCopyInputStream_Init(&decoder.input, &buf, size, - options & kUpb_DecodeOption_AliasString); +bool _upb_DefBuilder_GetOrCreateFeatureSet(upb_DefBuilder* ctx, + const UPB_DESC(FeatureSet*) parent, + upb_StringView key, + UPB_DESC(FeatureSet**) set) { + upb_StringView k = _upb_DefBuilder_MakeKey(ctx, parent, key); + upb_value v; + if (upb_strtable_lookup2(&ctx->feature_cache, k.data, k.size, &v)) { + *set = upb_value_getptr(v); + return false; + } - decoder.extreg = extreg; - decoder.unknown = NULL; - decoder.depth = depth ? depth : kUpb_WireFormat_DefaultDepthLimit; - decoder.end_group = DECODE_NOGROUP; - decoder.options = (uint16_t)options; - decoder.missing_required = false; - decoder.status = kUpb_DecodeStatus_Ok; + *set = (UPB_DESC(FeatureSet*))upb_Message_DeepClone( + UPB_UPCAST(parent), UPB_DESC_MINITABLE(FeatureSet), ctx->arena); + if (!*set) _upb_DefBuilder_OomErr(ctx); - // Violating the encapsulation of the arena for performance reasons. - // This is a temporary arena that we swap into and swap out of when we are - // done. The temporary arena only needs to be able to handle allocation, - // not fuse or free, so it does not need many of the members to be initialized - // (particularly parent_or_count). - UPB_PRIVATE(_upb_Arena_SwapIn)(&decoder.arena, arena); + v = upb_value_ptr(*set); + if (!upb_strtable_insert(&ctx->feature_cache, k.data, k.size, v, + ctx->tmp_arena)) { + _upb_DefBuilder_OomErr(ctx); + } - return upb_Decoder_Decode(&decoder, buf, msg, l, arena); + return true; } -#undef OP_FIXPCK_LG2 -#undef OP_VARPCK_LG2 - -// We encode backwards, to avoid pre-computing lengths (one-pass encode). - - -#include -#include -#include -#include - - -// Must be last. - -#define UPB_PB_VARINT_MAX_LEN 10 - -UPB_NOINLINE -static size_t encode_varint64(uint64_t val, char* buf) { - size_t i = 0; - do { - uint8_t byte = val & 0x7fU; - val >>= 7; - if (val) byte |= 0x80U; - buf[i++] = byte; - } while (val); - return i; -} +const UPB_DESC(FeatureSet*) + _upb_DefBuilder_DoResolveFeatures(upb_DefBuilder* ctx, + const UPB_DESC(FeatureSet*) parent, + const UPB_DESC(FeatureSet*) child, + bool is_implicit) { + assert(parent); + if (!child) return parent; -static uint32_t encode_zz32(int32_t n) { - return ((uint32_t)n << 1) ^ (n >> 31); -} -static uint64_t encode_zz64(int64_t n) { - return ((uint64_t)n << 1) ^ (n >> 63); -} + if (child && !is_implicit && + upb_FileDef_Syntax(ctx->file) != kUpb_Syntax_Editions) { + _upb_DefBuilder_Errf(ctx, "Features can only be specified for editions"); + } -typedef struct { - upb_EncodeStatus status; - jmp_buf err; - upb_Arena* arena; - char *buf, *ptr, *limit; - int options; - int depth; - _upb_mapsorter sorter; -} upb_encstate; + UPB_DESC(FeatureSet*) resolved; + size_t child_size; + const char* child_bytes = + UPB_DESC(FeatureSet_serialize)(child, ctx->tmp_arena, &child_size); + if (!child_bytes) _upb_DefBuilder_OomErr(ctx); -static size_t upb_roundup_pow2(size_t bytes) { - size_t ret = 128; - while (ret < bytes) { - ret *= 2; + upb_StringView key = upb_StringView_FromDataAndSize(child_bytes, child_size); + if (!_upb_DefBuilder_GetOrCreateFeatureSet(ctx, parent, key, &resolved)) { + return resolved; } - return ret; -} -UPB_NORETURN static void encode_err(upb_encstate* e, upb_EncodeStatus s) { - UPB_ASSERT(s != kUpb_EncodeStatus_Ok); - e->status = s; - UPB_LONGJMP(e->err, 1); -} + upb_DecodeStatus dec_status = + upb_Decode(child_bytes, child_size, UPB_UPCAST(resolved), + UPB_DESC_MINITABLE(FeatureSet), NULL, 0, ctx->arena); + if (dec_status != kUpb_DecodeStatus_Ok) _upb_DefBuilder_OomErr(ctx); -UPB_NOINLINE -static void encode_growbuffer(upb_encstate* e, size_t bytes) { - size_t old_size = e->limit - e->buf; - size_t new_size = upb_roundup_pow2(bytes + (e->limit - e->ptr)); - char* new_buf = upb_Arena_Realloc(e->arena, e->buf, old_size, new_size); + return resolved; +} - if (!new_buf) encode_err(e, kUpb_EncodeStatus_OutOfMemory); - // We want previous data at the end, realloc() put it at the beginning. - // TODO: This is somewhat inefficient since we are copying twice. - // Maybe create a realloc() that copies to the end of the new buffer? - if (old_size > 0) { - memmove(new_buf + new_size - old_size, e->buf, old_size); - } +#include - e->ptr = new_buf + new_size - (e->limit - e->ptr); - e->limit = new_buf + new_size; - e->buf = new_buf; - e->ptr -= bytes; -} +// Must be last. -/* Call to ensure that at least "bytes" bytes are available for writing at - * e->ptr. Returns false if the bytes could not be allocated. */ -UPB_FORCEINLINE -static void encode_reserve(upb_encstate* e, size_t bytes) { - if ((size_t)(e->ptr - e->buf) < bytes) { - encode_growbuffer(e, bytes); - return; - } +char* upb_strdup2(const char* s, size_t len, upb_Arena* a) { + size_t n; + char* p; - e->ptr -= bytes; -} + // Prevent overflow errors. + if (len == SIZE_MAX) return NULL; -/* Writes the given bytes to the buffer, handling reserve/advance. */ -static void encode_bytes(upb_encstate* e, const void* data, size_t len) { - if (len == 0) return; /* memcpy() with zero size is UB */ - encode_reserve(e, len); - memcpy(e->ptr, data, len); + // Always null-terminate, even if binary data; but don't rely on the input to + // have a null-terminating byte since it may be a raw binary buffer. + n = len + 1; + p = upb_Arena_Malloc(a, n); + if (p) { + if (len != 0) memcpy(p, s, len); + p[len] = 0; + } + return p; } -static void encode_fixed64(upb_encstate* e, uint64_t val) { - val = UPB_PRIVATE(_upb_BigEndian64)(val); - encode_bytes(e, &val, sizeof(uint64_t)); -} -static void encode_fixed32(upb_encstate* e, uint32_t val) { - val = UPB_PRIVATE(_upb_BigEndian32)(val); - encode_bytes(e, &val, sizeof(uint32_t)); -} +#include +#include -UPB_NOINLINE -static void encode_longvarint(upb_encstate* e, uint64_t val) { - size_t len; - char* start; - encode_reserve(e, UPB_PB_VARINT_MAX_LEN); - len = encode_varint64(val, e->ptr); - start = e->ptr + UPB_PB_VARINT_MAX_LEN - len; - memmove(start, e->ptr, len); - e->ptr = start; +// Must be last. + +bool upb_Message_HasFieldByDef(const upb_Message* msg, const upb_FieldDef* f) { + UPB_ASSERT(upb_FieldDef_HasPresence(f)); + return upb_Message_HasField(msg, upb_FieldDef_MiniTable(f)); } -UPB_FORCEINLINE -static void encode_varint(upb_encstate* e, uint64_t val) { - if (val < 128 && e->ptr != e->buf) { - --e->ptr; - *e->ptr = val; +const upb_FieldDef* upb_Message_WhichOneof(const upb_Message* msg, + const upb_OneofDef* o) { + const upb_FieldDef* f = upb_OneofDef_Field(o, 0); + if (upb_OneofDef_IsSynthetic(o)) { + UPB_ASSERT(upb_OneofDef_FieldCount(o) == 1); + return upb_Message_HasFieldByDef(msg, f) ? f : NULL; } else { - encode_longvarint(e, val); + const upb_MiniTableField* field = upb_FieldDef_MiniTable(f); + uint32_t oneof_case = upb_Message_WhichOneofFieldNumber(msg, field); + f = oneof_case ? upb_OneofDef_LookupNumber(o, oneof_case) : NULL; + UPB_ASSERT((f != NULL) == (oneof_case != 0)); + return f; } } -static void encode_double(upb_encstate* e, double d) { - uint64_t u64; - UPB_ASSERT(sizeof(double) == sizeof(uint64_t)); - memcpy(&u64, &d, sizeof(uint64_t)); - encode_fixed64(e, u64); -} - -static void encode_float(upb_encstate* e, float d) { - uint32_t u32; - UPB_ASSERT(sizeof(float) == sizeof(uint32_t)); - memcpy(&u32, &d, sizeof(uint32_t)); - encode_fixed32(e, u32); -} - -static void encode_tag(upb_encstate* e, uint32_t field_number, - uint8_t wire_type) { - encode_varint(e, (field_number << 3) | wire_type); +upb_MessageValue upb_Message_GetFieldByDef(const upb_Message* msg, + const upb_FieldDef* f) { + upb_MessageValue default_val = upb_FieldDef_Default(f); + return upb_Message_GetField(msg, upb_FieldDef_MiniTable(f), default_val); } -static void encode_fixedarray(upb_encstate* e, const upb_Array* arr, - size_t elem_size, uint32_t tag) { - size_t bytes = arr->UPB_PRIVATE(size) * elem_size; - const char* data = _upb_array_constptr(arr); - const char* ptr = data + bytes - elem_size; +upb_MutableMessageValue upb_Message_Mutable(upb_Message* msg, + const upb_FieldDef* f, + upb_Arena* a) { + UPB_ASSERT(upb_FieldDef_IsSubMessage(f) || upb_FieldDef_IsRepeated(f)); + if (upb_FieldDef_HasPresence(f) && !upb_Message_HasFieldByDef(msg, f)) { + // We need to skip the upb_Message_GetFieldByDef() call in this case. + goto make; + } - if (tag || !UPB_PRIVATE(_upb_IsLittleEndian)()) { - while (true) { - if (elem_size == 4) { - uint32_t val; - memcpy(&val, ptr, sizeof(val)); - val = UPB_PRIVATE(_upb_BigEndian32)(val); - encode_bytes(e, &val, elem_size); - } else { - UPB_ASSERT(elem_size == 8); - uint64_t val; - memcpy(&val, ptr, sizeof(val)); - val = UPB_PRIVATE(_upb_BigEndian64)(val); - encode_bytes(e, &val, elem_size); - } + upb_MessageValue val = upb_Message_GetFieldByDef(msg, f); + if (val.array_val) { + return (upb_MutableMessageValue){.array = (upb_Array*)val.array_val}; + } - if (tag) encode_varint(e, tag); - if (ptr == data) break; - ptr -= elem_size; - } + upb_MutableMessageValue ret; +make: + if (!a) return (upb_MutableMessageValue){.array = NULL}; + if (upb_FieldDef_IsMap(f)) { + const upb_MessageDef* entry = upb_FieldDef_MessageSubDef(f); + const upb_FieldDef* key = + upb_MessageDef_FindFieldByNumber(entry, kUpb_MapEntry_KeyFieldNumber); + const upb_FieldDef* value = + upb_MessageDef_FindFieldByNumber(entry, kUpb_MapEntry_ValueFieldNumber); + ret.map = + upb_Map_New(a, upb_FieldDef_CType(key), upb_FieldDef_CType(value)); + } else if (upb_FieldDef_IsRepeated(f)) { + ret.array = upb_Array_New(a, upb_FieldDef_CType(f)); } else { - encode_bytes(e, data, bytes); + UPB_ASSERT(upb_FieldDef_IsSubMessage(f)); + const upb_MessageDef* m = upb_FieldDef_MessageSubDef(f); + ret.msg = upb_Message_New(upb_MessageDef_MiniTable(m), a); } + + val.array_val = ret.array; + upb_Message_SetFieldByDef(msg, f, val, a); + + return ret; } -static void encode_message(upb_encstate* e, const upb_Message* msg, - const upb_MiniTable* m, size_t* size); +bool upb_Message_SetFieldByDef(upb_Message* msg, const upb_FieldDef* f, + upb_MessageValue val, upb_Arena* a) { + return upb_Message_SetField(msg, upb_FieldDef_MiniTable(f), val, a); +} -static void encode_TaggedMessagePtr(upb_encstate* e, - upb_TaggedMessagePtr tagged, - const upb_MiniTable* m, size_t* size) { - if (upb_TaggedMessagePtr_IsEmpty(tagged)) { - m = UPB_PRIVATE(_upb_MiniTable_Empty)(); - } - encode_message(e, UPB_PRIVATE(_upb_TaggedMessagePtr_GetMessage)(tagged), m, - size); +void upb_Message_ClearFieldByDef(upb_Message* msg, const upb_FieldDef* f) { + upb_Message_ClearField(msg, upb_FieldDef_MiniTable(f)); } -static void encode_scalar(upb_encstate* e, const void* _field_mem, - const upb_MiniTableSub* subs, - const upb_MiniTableField* f) { - const char* field_mem = _field_mem; - int wire_type; +void upb_Message_ClearByDef(upb_Message* msg, const upb_MessageDef* m) { + upb_Message_Clear(msg, upb_MessageDef_MiniTable(m)); +} -#define CASE(ctype, type, wtype, encodeval) \ - { \ - ctype val = *(ctype*)field_mem; \ - encode_##type(e, encodeval); \ - wire_type = wtype; \ - break; \ - } +bool upb_Message_Next(const upb_Message* msg, const upb_MessageDef* m, + const upb_DefPool* ext_pool, const upb_FieldDef** out_f, + upb_MessageValue* out_val, size_t* iter) { + size_t i = *iter; + size_t n = upb_MessageDef_FieldCount(m); + UPB_UNUSED(ext_pool); - switch (f->UPB_PRIVATE(descriptortype)) { - case kUpb_FieldType_Double: - CASE(double, double, kUpb_WireType_64Bit, val); - case kUpb_FieldType_Float: - CASE(float, float, kUpb_WireType_32Bit, val); - case kUpb_FieldType_Int64: - case kUpb_FieldType_UInt64: - CASE(uint64_t, varint, kUpb_WireType_Varint, val); - case kUpb_FieldType_UInt32: - CASE(uint32_t, varint, kUpb_WireType_Varint, val); - case kUpb_FieldType_Int32: - case kUpb_FieldType_Enum: - CASE(int32_t, varint, kUpb_WireType_Varint, (int64_t)val); - case kUpb_FieldType_SFixed64: - case kUpb_FieldType_Fixed64: - CASE(uint64_t, fixed64, kUpb_WireType_64Bit, val); - case kUpb_FieldType_Fixed32: - case kUpb_FieldType_SFixed32: - CASE(uint32_t, fixed32, kUpb_WireType_32Bit, val); - case kUpb_FieldType_Bool: - CASE(bool, varint, kUpb_WireType_Varint, val); - case kUpb_FieldType_SInt32: - CASE(int32_t, varint, kUpb_WireType_Varint, encode_zz32(val)); - case kUpb_FieldType_SInt64: - CASE(int64_t, varint, kUpb_WireType_Varint, encode_zz64(val)); - case kUpb_FieldType_String: - case kUpb_FieldType_Bytes: { - upb_StringView view = *(upb_StringView*)field_mem; - encode_bytes(e, view.data, view.size); - encode_varint(e, view.size); - wire_type = kUpb_WireType_Delimited; - break; - } - case kUpb_FieldType_Group: { - size_t size; - upb_TaggedMessagePtr submsg = *(upb_TaggedMessagePtr*)field_mem; - const upb_MiniTable* subm = - upb_MiniTableSub_Message(subs[f->UPB_PRIVATE(submsg_index)]); - if (submsg == 0) { - return; + // Iterate over normal fields, returning the first one that is set. + while (++i < n) { + const upb_FieldDef* f = upb_MessageDef_Field(m, i); + const upb_MiniTableField* field = upb_FieldDef_MiniTable(f); + upb_MessageValue val = upb_Message_GetFieldByDef(msg, f); + + // Skip field if unset or empty. + if (upb_MiniTableField_HasPresence(field)) { + if (!upb_Message_HasFieldByDef(msg, f)) continue; + } else { + switch (UPB_PRIVATE(_upb_MiniTableField_Mode)(field)) { + case kUpb_FieldMode_Map: + if (!val.map_val || upb_Map_Size(val.map_val) == 0) continue; + break; + case kUpb_FieldMode_Array: + if (!val.array_val || upb_Array_Size(val.array_val) == 0) continue; + break; + case kUpb_FieldMode_Scalar: + if (UPB_PRIVATE(_upb_MiniTableField_DataIsZero)(field, &val)) + continue; + break; } - if (--e->depth == 0) encode_err(e, kUpb_EncodeStatus_MaxDepthExceeded); - encode_tag(e, f->UPB_PRIVATE(number), kUpb_WireType_EndGroup); - encode_TaggedMessagePtr(e, submsg, subm, &size); - wire_type = kUpb_WireType_StartGroup; - e->depth++; - break; } - case kUpb_FieldType_Message: { - size_t size; - upb_TaggedMessagePtr submsg = *(upb_TaggedMessagePtr*)field_mem; - const upb_MiniTable* subm = - upb_MiniTableSub_Message(subs[f->UPB_PRIVATE(submsg_index)]); - if (submsg == 0) { - return; - } - if (--e->depth == 0) encode_err(e, kUpb_EncodeStatus_MaxDepthExceeded); - encode_TaggedMessagePtr(e, submsg, subm, &size); - encode_varint(e, size); - wire_type = kUpb_WireType_Delimited; - e->depth++; - break; + + *out_val = val; + *out_f = f; + *iter = i; + return true; + } + + if (ext_pool) { + // Return any extensions that are set. + size_t count; + const upb_Extension* ext = UPB_PRIVATE(_upb_Message_Getexts)(msg, &count); + if (i - n < count) { + ext += count - 1 - (i - n); + memcpy(out_val, &ext->data, sizeof(*out_val)); + *out_f = upb_DefPool_FindExtensionByMiniTable(ext_pool, ext->ext); + *iter = i; + return true; } - default: - UPB_UNREACHABLE(); } -#undef CASE - encode_tag(e, f->UPB_PRIVATE(number), wire_type); + *iter = i; + return false; } -static void encode_array(upb_encstate* e, const upb_Message* msg, - const upb_MiniTableSub* subs, - const upb_MiniTableField* f) { - const upb_Array* arr = *UPB_PTR_AT(msg, f->UPB_PRIVATE(offset), upb_Array*); - bool packed = upb_MiniTableField_IsPacked(f); - size_t pre_len = e->limit - e->ptr; +bool _upb_Message_DiscardUnknown(upb_Message* msg, const upb_MessageDef* m, + int depth) { + size_t iter = kUpb_Message_Begin; + const upb_FieldDef* f; + upb_MessageValue val; + bool ret = true; - if (arr == NULL || arr->UPB_PRIVATE(size) == 0) { - return; - } + if (--depth == 0) return false; -#define VARINT_CASE(ctype, encode) \ - { \ - const ctype* start = _upb_array_constptr(arr); \ - const ctype* ptr = start + arr->UPB_PRIVATE(size); \ - uint32_t tag = \ - packed ? 0 : (f->UPB_PRIVATE(number) << 3) | kUpb_WireType_Varint; \ - do { \ - ptr--; \ - encode_varint(e, encode); \ - if (tag) encode_varint(e, tag); \ - } while (ptr != start); \ - } \ - break; + _upb_Message_DiscardUnknown_shallow(msg); -#define TAG(wire_type) (packed ? 0 : (f->UPB_PRIVATE(number) << 3 | wire_type)) + while (upb_Message_Next(msg, m, NULL /*ext_pool*/, &f, &val, &iter)) { + const upb_MessageDef* subm = upb_FieldDef_MessageSubDef(f); + if (!subm) continue; + if (upb_FieldDef_IsMap(f)) { + const upb_FieldDef* val_f = upb_MessageDef_FindFieldByNumber(subm, 2); + const upb_MessageDef* val_m = upb_FieldDef_MessageSubDef(val_f); + upb_Map* map = (upb_Map*)val.map_val; + size_t iter = kUpb_Map_Begin; - switch (f->UPB_PRIVATE(descriptortype)) { - case kUpb_FieldType_Double: - encode_fixedarray(e, arr, sizeof(double), TAG(kUpb_WireType_64Bit)); - break; - case kUpb_FieldType_Float: - encode_fixedarray(e, arr, sizeof(float), TAG(kUpb_WireType_32Bit)); - break; - case kUpb_FieldType_SFixed64: - case kUpb_FieldType_Fixed64: - encode_fixedarray(e, arr, sizeof(uint64_t), TAG(kUpb_WireType_64Bit)); - break; - case kUpb_FieldType_Fixed32: - case kUpb_FieldType_SFixed32: - encode_fixedarray(e, arr, sizeof(uint32_t), TAG(kUpb_WireType_32Bit)); - break; - case kUpb_FieldType_Int64: - case kUpb_FieldType_UInt64: - VARINT_CASE(uint64_t, *ptr); - case kUpb_FieldType_UInt32: - VARINT_CASE(uint32_t, *ptr); - case kUpb_FieldType_Int32: - case kUpb_FieldType_Enum: - VARINT_CASE(int32_t, (int64_t)*ptr); - case kUpb_FieldType_Bool: - VARINT_CASE(bool, *ptr); - case kUpb_FieldType_SInt32: - VARINT_CASE(int32_t, encode_zz32(*ptr)); - case kUpb_FieldType_SInt64: - VARINT_CASE(int64_t, encode_zz64(*ptr)); - case kUpb_FieldType_String: - case kUpb_FieldType_Bytes: { - const upb_StringView* start = _upb_array_constptr(arr); - const upb_StringView* ptr = start + arr->UPB_PRIVATE(size); - do { - ptr--; - encode_bytes(e, ptr->data, ptr->size); - encode_varint(e, ptr->size); - encode_tag(e, f->UPB_PRIVATE(number), kUpb_WireType_Delimited); - } while (ptr != start); - return; - } - case kUpb_FieldType_Group: { - const upb_TaggedMessagePtr* start = _upb_array_constptr(arr); - const upb_TaggedMessagePtr* ptr = start + arr->UPB_PRIVATE(size); - const upb_MiniTable* subm = - upb_MiniTableSub_Message(subs[f->UPB_PRIVATE(submsg_index)]); - if (--e->depth == 0) encode_err(e, kUpb_EncodeStatus_MaxDepthExceeded); - do { - size_t size; - ptr--; - encode_tag(e, f->UPB_PRIVATE(number), kUpb_WireType_EndGroup); - encode_TaggedMessagePtr(e, *ptr, subm, &size); - encode_tag(e, f->UPB_PRIVATE(number), kUpb_WireType_StartGroup); - } while (ptr != start); - e->depth++; - return; - } - case kUpb_FieldType_Message: { - const upb_TaggedMessagePtr* start = _upb_array_constptr(arr); - const upb_TaggedMessagePtr* ptr = start + arr->UPB_PRIVATE(size); - const upb_MiniTable* subm = - upb_MiniTableSub_Message(subs[f->UPB_PRIVATE(submsg_index)]); - if (--e->depth == 0) encode_err(e, kUpb_EncodeStatus_MaxDepthExceeded); - do { - size_t size; - ptr--; - encode_TaggedMessagePtr(e, *ptr, subm, &size); - encode_varint(e, size); - encode_tag(e, f->UPB_PRIVATE(number), kUpb_WireType_Delimited); - } while (ptr != start); - e->depth++; - return; + if (!val_m) continue; + + upb_MessageValue map_key, map_val; + while (upb_Map_Next(map, &map_key, &map_val, &iter)) { + if (!_upb_Message_DiscardUnknown((upb_Message*)map_val.msg_val, val_m, + depth)) { + ret = false; + } + } + } else if (upb_FieldDef_IsRepeated(f)) { + const upb_Array* arr = val.array_val; + size_t i, n = upb_Array_Size(arr); + for (i = 0; i < n; i++) { + upb_MessageValue elem = upb_Array_Get(arr, i); + if (!_upb_Message_DiscardUnknown((upb_Message*)elem.msg_val, subm, + depth)) { + ret = false; + } + } + } else { + if (!_upb_Message_DiscardUnknown((upb_Message*)val.msg_val, subm, + depth)) { + ret = false; + } } } -#undef VARINT_CASE - if (packed) { - encode_varint(e, e->limit - e->ptr - pre_len); - encode_tag(e, f->UPB_PRIVATE(number), kUpb_WireType_Delimited); - } + return ret; } -static void encode_mapentry(upb_encstate* e, uint32_t number, - const upb_MiniTable* layout, - const upb_MapEntry* ent) { - const upb_MiniTableField* key_field = &layout->UPB_PRIVATE(fields)[0]; - const upb_MiniTableField* val_field = &layout->UPB_PRIVATE(fields)[1]; - size_t pre_len = e->limit - e->ptr; - size_t size; - encode_scalar(e, &ent->data.v, layout->UPB_PRIVATE(subs), val_field); - encode_scalar(e, &ent->data.k, layout->UPB_PRIVATE(subs), key_field); - size = (e->limit - e->ptr) - pre_len; - encode_varint(e, size); - encode_tag(e, number, kUpb_WireType_Delimited); +bool upb_Message_DiscardUnknown(upb_Message* msg, const upb_MessageDef* m, + int maxdepth) { + return _upb_Message_DiscardUnknown(msg, m, maxdepth); } -static void encode_map(upb_encstate* e, const upb_Message* msg, - const upb_MiniTableSub* subs, - const upb_MiniTableField* f) { - const upb_Map* map = *UPB_PTR_AT(msg, f->UPB_PRIVATE(offset), const upb_Map*); - const upb_MiniTable* layout = - upb_MiniTableSub_Message(subs[f->UPB_PRIVATE(submsg_index)]); - UPB_ASSERT(layout->UPB_PRIVATE(field_count) == 2); - if (map == NULL) return; +#include +#include +#include - if (e->options & kUpb_EncodeOption_Deterministic) { - _upb_sortedmap sorted; - _upb_mapsorter_pushmap( - &e->sorter, layout->UPB_PRIVATE(fields)[0].UPB_PRIVATE(descriptortype), - map, &sorted); - upb_MapEntry ent; - while (_upb_sortedmap_next(&e->sorter, map, &sorted, &ent)) { - encode_mapentry(e, f->UPB_PRIVATE(number), layout, &ent); - } - _upb_mapsorter_popmap(&e->sorter, &sorted); + +// Must be last. + +struct upb_MessageDef { + const UPB_DESC(MessageOptions*) opts; + const UPB_DESC(FeatureSet*) resolved_features; + const upb_MiniTable* layout; + const upb_FileDef* file; + const upb_MessageDef* containing_type; + const char* full_name; + + // Tables for looking up fields by number and name. + upb_inttable itof; + upb_strtable ntof; + + // Looking up fields by json name. + upb_strtable jtof; + + /* All nested defs. + * MEM: We could save some space here by putting nested defs in a contiguous + * region and calculating counts from offsets or vice-versa. */ + const upb_FieldDef* fields; + const upb_OneofDef* oneofs; + const upb_ExtensionRange* ext_ranges; + const upb_StringView* res_names; + const upb_MessageDef* nested_msgs; + const upb_MessageReservedRange* res_ranges; + const upb_EnumDef* nested_enums; + const upb_FieldDef* nested_exts; + + // TODO: These counters don't need anywhere near 32 bits. + int field_count; + int real_oneof_count; + int oneof_count; + int ext_range_count; + int res_range_count; + int res_name_count; + int nested_msg_count; + int nested_enum_count; + int nested_ext_count; + bool in_message_set; + bool is_sorted; + upb_WellKnown well_known_type; +#if UINTPTR_MAX == 0xffffffff + uint32_t padding; // Increase size to a multiple of 8. +#endif +}; + +static void assign_msg_wellknowntype(upb_MessageDef* m) { + const char* name = m->full_name; + if (name == NULL) { + m->well_known_type = kUpb_WellKnown_Unspecified; + return; + } + if (!strcmp(name, "google.protobuf.Any")) { + m->well_known_type = kUpb_WellKnown_Any; + } else if (!strcmp(name, "google.protobuf.FieldMask")) { + m->well_known_type = kUpb_WellKnown_FieldMask; + } else if (!strcmp(name, "google.protobuf.Duration")) { + m->well_known_type = kUpb_WellKnown_Duration; + } else if (!strcmp(name, "google.protobuf.Timestamp")) { + m->well_known_type = kUpb_WellKnown_Timestamp; + } else if (!strcmp(name, "google.protobuf.DoubleValue")) { + m->well_known_type = kUpb_WellKnown_DoubleValue; + } else if (!strcmp(name, "google.protobuf.FloatValue")) { + m->well_known_type = kUpb_WellKnown_FloatValue; + } else if (!strcmp(name, "google.protobuf.Int64Value")) { + m->well_known_type = kUpb_WellKnown_Int64Value; + } else if (!strcmp(name, "google.protobuf.UInt64Value")) { + m->well_known_type = kUpb_WellKnown_UInt64Value; + } else if (!strcmp(name, "google.protobuf.Int32Value")) { + m->well_known_type = kUpb_WellKnown_Int32Value; + } else if (!strcmp(name, "google.protobuf.UInt32Value")) { + m->well_known_type = kUpb_WellKnown_UInt32Value; + } else if (!strcmp(name, "google.protobuf.BoolValue")) { + m->well_known_type = kUpb_WellKnown_BoolValue; + } else if (!strcmp(name, "google.protobuf.StringValue")) { + m->well_known_type = kUpb_WellKnown_StringValue; + } else if (!strcmp(name, "google.protobuf.BytesValue")) { + m->well_known_type = kUpb_WellKnown_BytesValue; + } else if (!strcmp(name, "google.protobuf.Value")) { + m->well_known_type = kUpb_WellKnown_Value; + } else if (!strcmp(name, "google.protobuf.ListValue")) { + m->well_known_type = kUpb_WellKnown_ListValue; + } else if (!strcmp(name, "google.protobuf.Struct")) { + m->well_known_type = kUpb_WellKnown_Struct; } else { - intptr_t iter = UPB_STRTABLE_BEGIN; - upb_StringView key; - upb_value val; - while (upb_strtable_next2(&map->table, &key, &val, &iter)) { - upb_MapEntry ent; - _upb_map_fromkey(key, &ent.data.k, map->key_size); - _upb_map_fromvalue(val, &ent.data.v, map->val_size); - encode_mapentry(e, f->UPB_PRIVATE(number), layout, &ent); - } + m->well_known_type = kUpb_WellKnown_Unspecified; } } -static bool encode_shouldencode(upb_encstate* e, const upb_Message* msg, - const upb_MiniTableSub* subs, - const upb_MiniTableField* f) { - if (f->presence == 0) { - // Proto3 presence or map/array. - const void* mem = UPB_PTR_AT(msg, f->UPB_PRIVATE(offset), void); - switch (UPB_PRIVATE(_upb_MiniTableField_GetRep)(f)) { - case kUpb_FieldRep_1Byte: { - char ch; - memcpy(&ch, mem, 1); - return ch != 0; - } - case kUpb_FieldRep_4Byte: { - uint32_t u32; - memcpy(&u32, mem, 4); - return u32 != 0; - } - case kUpb_FieldRep_8Byte: { - uint64_t u64; - memcpy(&u64, mem, 8); - return u64 != 0; - } - case kUpb_FieldRep_StringView: { - const upb_StringView* str = (const upb_StringView*)mem; - return str->size != 0; - } - default: - UPB_UNREACHABLE(); +upb_MessageDef* _upb_MessageDef_At(const upb_MessageDef* m, int i) { + return (upb_MessageDef*)&m[i]; +} + +bool _upb_MessageDef_IsValidExtensionNumber(const upb_MessageDef* m, int n) { + for (int i = 0; i < m->ext_range_count; i++) { + const upb_ExtensionRange* r = upb_MessageDef_ExtensionRange(m, i); + if (upb_ExtensionRange_Start(r) <= n && n < upb_ExtensionRange_End(r)) { + return true; } - } else if (f->presence > 0) { - // Proto2 presence: hasbit. - return UPB_PRIVATE(_upb_Message_GetHasbit)(msg, f); - } else { - // Field is in a oneof. - return UPB_PRIVATE(_upb_Message_GetOneofCase)(msg, f) == - f->UPB_PRIVATE(number); } + return false; } -static void encode_field(upb_encstate* e, const upb_Message* msg, - const upb_MiniTableSub* subs, - const upb_MiniTableField* field) { - switch (UPB_PRIVATE(_upb_MiniTableField_Mode)(field)) { - case kUpb_FieldMode_Array: - encode_array(e, msg, subs, field); - break; - case kUpb_FieldMode_Map: - encode_map(e, msg, subs, field); - break; - case kUpb_FieldMode_Scalar: - encode_scalar(e, UPB_PTR_AT(msg, field->UPB_PRIVATE(offset), void), subs, - field); - break; - default: - UPB_UNREACHABLE(); - } +const UPB_DESC(MessageOptions) * + upb_MessageDef_Options(const upb_MessageDef* m) { + return m->opts; } -static void encode_msgset_item(upb_encstate* e, const upb_Extension* ext) { - size_t size; - encode_tag(e, kUpb_MsgSet_Item, kUpb_WireType_EndGroup); - encode_message(e, ext->data.ptr, - upb_MiniTableExtension_GetSubMessage(ext->ext), &size); - encode_varint(e, size); - encode_tag(e, kUpb_MsgSet_Message, kUpb_WireType_Delimited); - encode_varint(e, upb_MiniTableExtension_Number(ext->ext)); - encode_tag(e, kUpb_MsgSet_TypeId, kUpb_WireType_Varint); - encode_tag(e, kUpb_MsgSet_Item, kUpb_WireType_StartGroup); +bool upb_MessageDef_HasOptions(const upb_MessageDef* m) { + return m->opts != (void*)kUpbDefOptDefault; } -static void encode_ext(upb_encstate* e, const upb_Extension* ext, - bool is_message_set) { - if (UPB_UNLIKELY(is_message_set)) { - encode_msgset_item(e, ext); - } else { - encode_field(e, (upb_Message*)&ext->data, &ext->ext->UPB_PRIVATE(sub), - &ext->ext->UPB_PRIVATE(field)); - } +const UPB_DESC(FeatureSet) * + upb_MessageDef_ResolvedFeatures(const upb_MessageDef* m) { + return m->resolved_features; } -static void encode_message(upb_encstate* e, const upb_Message* msg, - const upb_MiniTable* m, size_t* size) { - size_t pre_len = e->limit - e->ptr; +const char* upb_MessageDef_FullName(const upb_MessageDef* m) { + return m->full_name; +} - if ((e->options & kUpb_EncodeOption_CheckRequired) && - m->UPB_PRIVATE(required_count)) { - uint64_t msg_head; - memcpy(&msg_head, msg, 8); - msg_head = UPB_PRIVATE(_upb_BigEndian64)(msg_head); - if (UPB_PRIVATE(_upb_MiniTable_RequiredMask)(m) & ~msg_head) { - encode_err(e, kUpb_EncodeStatus_MissingRequired); - } - } +const upb_FileDef* upb_MessageDef_File(const upb_MessageDef* m) { + return m->file; +} - if ((e->options & kUpb_EncodeOption_SkipUnknown) == 0) { - size_t unknown_size; - const char* unknown = upb_Message_GetUnknown(msg, &unknown_size); +const upb_MessageDef* upb_MessageDef_ContainingType(const upb_MessageDef* m) { + return m->containing_type; +} - if (unknown) { - encode_bytes(e, unknown, unknown_size); - } - } +const char* upb_MessageDef_Name(const upb_MessageDef* m) { + return _upb_DefBuilder_FullToShort(m->full_name); +} - if (m->UPB_PRIVATE(ext) != kUpb_ExtMode_NonExtendable) { - /* Encode all extensions together. Unlike C++, we do not attempt to keep - * these in field number order relative to normal fields or even to each - * other. */ - size_t ext_count; - const upb_Extension* ext = - UPB_PRIVATE(_upb_Message_Getexts)(msg, &ext_count); - if (ext_count) { - if (e->options & kUpb_EncodeOption_Deterministic) { - _upb_sortedmap sorted; - _upb_mapsorter_pushexts(&e->sorter, ext, ext_count, &sorted); - while (_upb_sortedmap_nextext(&e->sorter, &sorted, &ext)) { - encode_ext(e, ext, m->UPB_PRIVATE(ext) == kUpb_ExtMode_IsMessageSet); - } - _upb_mapsorter_popmap(&e->sorter, &sorted); - } else { - const upb_Extension* end = ext + ext_count; - for (; ext != end; ext++) { - encode_ext(e, ext, m->UPB_PRIVATE(ext) == kUpb_ExtMode_IsMessageSet); - } - } - } - } +upb_Syntax upb_MessageDef_Syntax(const upb_MessageDef* m) { + return upb_FileDef_Syntax(m->file); +} - if (m->UPB_PRIVATE(field_count)) { - const upb_MiniTableField* f = - &m->UPB_PRIVATE(fields)[m->UPB_PRIVATE(field_count)]; - const upb_MiniTableField* first = &m->UPB_PRIVATE(fields)[0]; - while (f != first) { - f--; - if (encode_shouldencode(e, msg, m->UPB_PRIVATE(subs), f)) { - encode_field(e, msg, m->UPB_PRIVATE(subs), f); - } - } +const upb_FieldDef* upb_MessageDef_FindFieldByNumber(const upb_MessageDef* m, + uint32_t i) { + upb_value val; + return upb_inttable_lookup(&m->itof, i, &val) ? upb_value_getconstptr(val) + : NULL; +} + +const upb_FieldDef* upb_MessageDef_FindFieldByNameWithSize( + const upb_MessageDef* m, const char* name, size_t size) { + upb_value val; + + if (!upb_strtable_lookup2(&m->ntof, name, size, &val)) { + return NULL; } - *size = (e->limit - e->ptr) - pre_len; + return _upb_DefType_Unpack(val, UPB_DEFTYPE_FIELD); } -static upb_EncodeStatus upb_Encoder_Encode(upb_encstate* const encoder, - const upb_Message* const msg, - const upb_MiniTable* const l, - char** const buf, - size_t* const size) { - // Unfortunately we must continue to perform hackery here because there are - // code paths which blindly copy the returned pointer without bothering to - // check for errors until much later (b/235839510). So we still set *buf to - // NULL on error and we still set it to non-NULL on a successful empty result. - if (UPB_SETJMP(encoder->err) == 0) { - encode_message(encoder, msg, l, size); - *size = encoder->limit - encoder->ptr; - if (*size == 0) { - static char ch; - *buf = &ch; - } else { - UPB_ASSERT(encoder->ptr); - *buf = encoder->ptr; - } - } else { - UPB_ASSERT(encoder->status != kUpb_EncodeStatus_Ok); - *buf = NULL; - *size = 0; +const upb_OneofDef* upb_MessageDef_FindOneofByNameWithSize( + const upb_MessageDef* m, const char* name, size_t size) { + upb_value val; + + if (!upb_strtable_lookup2(&m->ntof, name, size, &val)) { + return NULL; } - _upb_mapsorter_destroy(&encoder->sorter); - return encoder->status; + return _upb_DefType_Unpack(val, UPB_DEFTYPE_ONEOF); } -upb_EncodeStatus upb_Encode(const upb_Message* msg, const upb_MiniTable* l, - int options, upb_Arena* arena, char** buf, - size_t* size) { - upb_encstate e; - unsigned depth = (unsigned)options >> 16; +bool _upb_MessageDef_Insert(upb_MessageDef* m, const char* name, size_t len, + upb_value v, upb_Arena* a) { + return upb_strtable_insert(&m->ntof, name, len, v, a); +} - e.status = kUpb_EncodeStatus_Ok; - e.arena = arena; - e.buf = NULL; - e.limit = NULL; - e.ptr = NULL; - e.depth = depth ? depth : kUpb_WireFormat_DefaultDepthLimit; - e.options = options; - _upb_mapsorter_init(&e.sorter); +bool upb_MessageDef_FindByNameWithSize(const upb_MessageDef* m, + const char* name, size_t len, + const upb_FieldDef** out_f, + const upb_OneofDef** out_o) { + upb_value val; - return upb_Encoder_Encode(&e, msg, l, buf, size); + if (!upb_strtable_lookup2(&m->ntof, name, len, &val)) { + return false; + } + + const upb_FieldDef* f = _upb_DefType_Unpack(val, UPB_DEFTYPE_FIELD); + const upb_OneofDef* o = _upb_DefType_Unpack(val, UPB_DEFTYPE_ONEOF); + if (out_f) *out_f = f; + if (out_o) *out_o = o; + return f || o; /* False if this was a JSON name. */ } -// Fast decoder: ~3x the speed of decode.c, but requires x86-64/ARM64. -// Also the table size grows by 2x. -// -// Could potentially be ported to other 64-bit archs that pass at least six -// arguments in registers and have 8 unused high bits in pointers. -// -// The overall design is to create specialized functions for every possible -// field type (eg. oneof boolean field with a 1 byte tag) and then dispatch -// to the specialized function as quickly as possible. - +const upb_FieldDef* upb_MessageDef_FindByJsonNameWithSize( + const upb_MessageDef* m, const char* name, size_t size) { + upb_value val; + if (upb_strtable_lookup2(&m->jtof, name, size, &val)) { + return upb_value_getconstptr(val); + } -// Must be last. + if (!upb_strtable_lookup2(&m->ntof, name, size, &val)) { + return NULL; + } -#if UPB_FASTTABLE + return _upb_DefType_Unpack(val, UPB_DEFTYPE_FIELD); +} -// The standard set of arguments passed to each parsing function. -// Thanks to x86-64 calling conventions, these will stay in registers. -#define UPB_PARSE_PARAMS \ - upb_Decoder *d, const char *ptr, upb_Message *msg, intptr_t table, \ - uint64_t hasbits, uint64_t data +int upb_MessageDef_ExtensionRangeCount(const upb_MessageDef* m) { + return m->ext_range_count; +} -#define UPB_PARSE_ARGS d, ptr, msg, table, hasbits, data +int upb_MessageDef_ReservedRangeCount(const upb_MessageDef* m) { + return m->res_range_count; +} -#define RETURN_GENERIC(m) \ - /* Uncomment either of these for debugging purposes. */ \ - /* fprintf(stderr, m); */ \ - /*__builtin_trap(); */ \ - return _upb_FastDecoder_DecodeGeneric(d, ptr, msg, table, hasbits, 0); +int upb_MessageDef_ReservedNameCount(const upb_MessageDef* m) { + return m->res_name_count; +} -typedef enum { - CARD_s = 0, /* Singular (optional, non-repeated) */ - CARD_o = 1, /* Oneof */ - CARD_r = 2, /* Repeated */ - CARD_p = 3 /* Packed Repeated */ -} upb_card; +int upb_MessageDef_FieldCount(const upb_MessageDef* m) { + return m->field_count; +} -UPB_NOINLINE -static const char* fastdecode_isdonefallback(UPB_PARSE_PARAMS) { - int overrun = data; - ptr = _upb_EpsCopyInputStream_IsDoneFallbackInline( - &d->input, ptr, overrun, _upb_Decoder_BufferFlipCallback); - data = _upb_FastDecoder_LoadTag(ptr); - UPB_MUSTTAIL return _upb_FastDecoder_TagDispatch(UPB_PARSE_ARGS); +int upb_MessageDef_OneofCount(const upb_MessageDef* m) { + return m->oneof_count; } -UPB_FORCEINLINE -static const char* fastdecode_dispatch(UPB_PARSE_PARAMS) { - int overrun; - switch (upb_EpsCopyInputStream_IsDoneStatus(&d->input, ptr, &overrun)) { - case kUpb_IsDoneStatus_Done: - *(uint32_t*)msg |= hasbits; // Sync hasbits. - const upb_MiniTable* m = decode_totablep(table); - return UPB_UNLIKELY(m->UPB_PRIVATE(required_count)) - ? _upb_Decoder_CheckRequired(d, ptr, msg, m) - : ptr; - case kUpb_IsDoneStatus_NotDone: - break; - case kUpb_IsDoneStatus_NeedFallback: - data = overrun; - UPB_MUSTTAIL return fastdecode_isdonefallback(UPB_PARSE_ARGS); - } +int upb_MessageDef_RealOneofCount(const upb_MessageDef* m) { + return m->real_oneof_count; +} - // Read two bytes of tag data (for a one-byte tag, the high byte is junk). - data = _upb_FastDecoder_LoadTag(ptr); - UPB_MUSTTAIL return _upb_FastDecoder_TagDispatch(UPB_PARSE_ARGS); +int upb_MessageDef_NestedMessageCount(const upb_MessageDef* m) { + return m->nested_msg_count; } -UPB_FORCEINLINE -static bool fastdecode_checktag(uint16_t data, int tagbytes) { - if (tagbytes == 1) { - return (data & 0xff) == 0; - } else { - return data == 0; - } +int upb_MessageDef_NestedEnumCount(const upb_MessageDef* m) { + return m->nested_enum_count; } -UPB_FORCEINLINE -static const char* fastdecode_longsize(const char* ptr, int* size) { - int i; - UPB_ASSERT(*size & 0x80); - *size &= 0xff; - for (i = 0; i < 3; i++) { - ptr++; - size_t byte = (uint8_t)ptr[-1]; - *size += (byte - 1) << (7 + 7 * i); - if (UPB_LIKELY((byte & 0x80) == 0)) return ptr; - } - ptr++; - size_t byte = (uint8_t)ptr[-1]; - // len is limited by 2gb not 4gb, hence 8 and not 16 as normally expected - // for a 32 bit varint. - if (UPB_UNLIKELY(byte >= 8)) return NULL; - *size += (byte - 1) << 28; - return ptr; +int upb_MessageDef_NestedExtensionCount(const upb_MessageDef* m) { + return m->nested_ext_count; } -UPB_FORCEINLINE -static const char* fastdecode_delimited( - upb_Decoder* d, const char* ptr, - upb_EpsCopyInputStream_ParseDelimitedFunc* func, void* ctx) { - ptr++; +const upb_MiniTable* upb_MessageDef_MiniTable(const upb_MessageDef* m) { + return m->layout; +} - // Sign-extend so varint greater than one byte becomes negative, causing - // fast delimited parse to fail. - int len = (int8_t)ptr[-1]; +const upb_ExtensionRange* upb_MessageDef_ExtensionRange(const upb_MessageDef* m, + int i) { + UPB_ASSERT(0 <= i && i < m->ext_range_count); + return _upb_ExtensionRange_At(m->ext_ranges, i); +} - if (!upb_EpsCopyInputStream_TryParseDelimitedFast(&d->input, &ptr, len, func, - ctx)) { - // Slow case: Sub-message is >=128 bytes and/or exceeds the current buffer. - // If it exceeds the buffer limit, limit/limit_ptr will change during - // sub-message parsing, so we need to preserve delta, not limit. - if (UPB_UNLIKELY(len & 0x80)) { - // Size varint >1 byte (length >= 128). - ptr = fastdecode_longsize(ptr, &len); - if (!ptr) { - // Corrupt wire format: size exceeded INT_MAX. - return NULL; - } - } - if (!upb_EpsCopyInputStream_CheckSize(&d->input, ptr, len)) { - // Corrupt wire format: invalid limit. - return NULL; - } - int delta = upb_EpsCopyInputStream_PushLimit(&d->input, ptr, len); - ptr = func(&d->input, ptr, ctx); - upb_EpsCopyInputStream_PopLimit(&d->input, ptr, delta); - } - return ptr; +const upb_MessageReservedRange* upb_MessageDef_ReservedRange( + const upb_MessageDef* m, int i) { + UPB_ASSERT(0 <= i && i < m->res_range_count); + return _upb_MessageReservedRange_At(m->res_ranges, i); } -/* singular, oneof, repeated field handling ***********************************/ +upb_StringView upb_MessageDef_ReservedName(const upb_MessageDef* m, int i) { + UPB_ASSERT(0 <= i && i < m->res_name_count); + return m->res_names[i]; +} -typedef struct { - upb_Array* arr; - void* end; -} fastdecode_arr; +const upb_FieldDef* upb_MessageDef_Field(const upb_MessageDef* m, int i) { + UPB_ASSERT(0 <= i && i < m->field_count); + return _upb_FieldDef_At(m->fields, i); +} -typedef enum { - FD_NEXT_ATLIMIT, - FD_NEXT_SAMEFIELD, - FD_NEXT_OTHERFIELD -} fastdecode_next; +const upb_OneofDef* upb_MessageDef_Oneof(const upb_MessageDef* m, int i) { + UPB_ASSERT(0 <= i && i < m->oneof_count); + return _upb_OneofDef_At(m->oneofs, i); +} -typedef struct { - void* dst; - fastdecode_next next; - uint32_t tag; -} fastdecode_nextret; +const upb_MessageDef* upb_MessageDef_NestedMessage(const upb_MessageDef* m, + int i) { + UPB_ASSERT(0 <= i && i < m->nested_msg_count); + return &m->nested_msgs[i]; +} -UPB_FORCEINLINE -static void* fastdecode_resizearr(upb_Decoder* d, void* dst, - fastdecode_arr* farr, int valbytes) { - if (UPB_UNLIKELY(dst == farr->end)) { - size_t old_capacity = farr->arr->UPB_PRIVATE(capacity); - size_t old_bytes = old_capacity * valbytes; - size_t new_capacity = old_capacity * 2; - size_t new_bytes = new_capacity * valbytes; - char* old_ptr = _upb_array_ptr(farr->arr); - char* new_ptr = upb_Arena_Realloc(&d->arena, old_ptr, old_bytes, new_bytes); - uint8_t elem_size_lg2 = __builtin_ctz(valbytes); - UPB_PRIVATE(_upb_Array_SetTaggedPtr)(farr->arr, new_ptr, elem_size_lg2); - farr->arr->UPB_PRIVATE(capacity) = new_capacity; - dst = (void*)(new_ptr + (old_capacity * valbytes)); - farr->end = (void*)(new_ptr + (new_capacity * valbytes)); - } - return dst; +const upb_EnumDef* upb_MessageDef_NestedEnum(const upb_MessageDef* m, int i) { + UPB_ASSERT(0 <= i && i < m->nested_enum_count); + return _upb_EnumDef_At(m->nested_enums, i); } -UPB_FORCEINLINE -static bool fastdecode_tagmatch(uint32_t tag, uint64_t data, int tagbytes) { - if (tagbytes == 1) { - return (uint8_t)tag == (uint8_t)data; - } else { - return (uint16_t)tag == (uint16_t)data; - } +const upb_FieldDef* upb_MessageDef_NestedExtension(const upb_MessageDef* m, + int i) { + UPB_ASSERT(0 <= i && i < m->nested_ext_count); + return _upb_FieldDef_At(m->nested_exts, i); } -UPB_FORCEINLINE -static void fastdecode_commitarr(void* dst, fastdecode_arr* farr, - int valbytes) { - farr->arr->UPB_PRIVATE(size) = - (size_t)((char*)dst - (char*)_upb_array_ptr(farr->arr)) / valbytes; +upb_WellKnown upb_MessageDef_WellKnownType(const upb_MessageDef* m) { + return m->well_known_type; } -UPB_FORCEINLINE -static fastdecode_nextret fastdecode_nextrepeated(upb_Decoder* d, void* dst, - const char** ptr, - fastdecode_arr* farr, - uint64_t data, int tagbytes, - int valbytes) { - fastdecode_nextret ret; - dst = (char*)dst + valbytes; +bool _upb_MessageDef_InMessageSet(const upb_MessageDef* m) { + return m->in_message_set; +} - if (UPB_LIKELY(!_upb_Decoder_IsDone(d, ptr))) { - ret.tag = _upb_FastDecoder_LoadTag(*ptr); - if (fastdecode_tagmatch(ret.tag, data, tagbytes)) { - ret.next = FD_NEXT_SAMEFIELD; - } else { - fastdecode_commitarr(dst, farr, valbytes); - ret.next = FD_NEXT_OTHERFIELD; - } - } else { - fastdecode_commitarr(dst, farr, valbytes); - ret.next = FD_NEXT_ATLIMIT; - } +const upb_FieldDef* upb_MessageDef_FindFieldByName(const upb_MessageDef* m, + const char* name) { + return upb_MessageDef_FindFieldByNameWithSize(m, name, strlen(name)); +} - ret.dst = dst; - return ret; +const upb_OneofDef* upb_MessageDef_FindOneofByName(const upb_MessageDef* m, + const char* name) { + return upb_MessageDef_FindOneofByNameWithSize(m, name, strlen(name)); } -UPB_FORCEINLINE -static void* fastdecode_fieldmem(upb_Message* msg, uint64_t data) { - size_t ofs = data >> 48; - return (char*)msg + ofs; +bool upb_MessageDef_IsMapEntry(const upb_MessageDef* m) { + return UPB_DESC(MessageOptions_map_entry)(m->opts); } -UPB_FORCEINLINE -static void* fastdecode_getfield(upb_Decoder* d, const char* ptr, - upb_Message* msg, uint64_t* data, - uint64_t* hasbits, fastdecode_arr* farr, - int valbytes, upb_card card) { - switch (card) { - case CARD_s: { - uint8_t hasbit_index = *data >> 24; - // Set hasbit and return pointer to scalar field. - *hasbits |= 1ull << hasbit_index; - return fastdecode_fieldmem(msg, *data); - } - case CARD_o: { - uint16_t case_ofs = *data >> 32; - uint32_t* oneof_case = UPB_PTR_AT(msg, case_ofs, uint32_t); - uint8_t field_number = *data >> 24; - *oneof_case = field_number; - return fastdecode_fieldmem(msg, *data); - } - case CARD_r: { - // Get pointer to upb_Array and allocate/expand if necessary. - uint8_t elem_size_lg2 = __builtin_ctz(valbytes); - upb_Array** arr_p = fastdecode_fieldmem(msg, *data); - char* begin; - *(uint32_t*)msg |= *hasbits; - *hasbits = 0; - if (UPB_LIKELY(!*arr_p)) { - farr->arr = UPB_PRIVATE(_upb_Array_New)(&d->arena, 8, elem_size_lg2); - *arr_p = farr->arr; - } else { - farr->arr = *arr_p; - } - begin = _upb_array_ptr(farr->arr); - farr->end = begin + (farr->arr->UPB_PRIVATE(capacity) * valbytes); - *data = _upb_FastDecoder_LoadTag(ptr); - return begin + (farr->arr->UPB_PRIVATE(size) * valbytes); - } - default: - UPB_UNREACHABLE(); - } +bool upb_MessageDef_IsMessageSet(const upb_MessageDef* m) { + return UPB_DESC(MessageOptions_message_set_wire_format)(m->opts); } -UPB_FORCEINLINE -static bool fastdecode_flippacked(uint64_t* data, int tagbytes) { - *data ^= (0x2 ^ 0x0); // Patch data to match packed wiretype. - return fastdecode_checktag(*data, tagbytes); +static upb_MiniTable* _upb_MessageDef_MakeMiniTable(upb_DefBuilder* ctx, + const upb_MessageDef* m) { + upb_StringView desc; + // Note: this will assign layout_index for fields, so upb_FieldDef_MiniTable() + // is safe to call only after this call. + bool ok = upb_MessageDef_MiniDescriptorEncode(m, ctx->tmp_arena, &desc); + if (!ok) _upb_DefBuilder_OomErr(ctx); + + void** scratch_data = _upb_DefPool_ScratchData(ctx->symtab); + size_t* scratch_size = _upb_DefPool_ScratchSize(ctx->symtab); + upb_MiniTable* ret = upb_MiniTable_BuildWithBuf( + desc.data, desc.size, ctx->platform, ctx->arena, scratch_data, + scratch_size, ctx->status); + if (!ret) _upb_DefBuilder_FailJmp(ctx); + + return ret; } -#define FASTDECODE_CHECKPACKED(tagbytes, card, func) \ - if (UPB_UNLIKELY(!fastdecode_checktag(data, tagbytes))) { \ - if (card == CARD_r && fastdecode_flippacked(&data, tagbytes)) { \ - UPB_MUSTTAIL return func(UPB_PARSE_ARGS); \ - } \ - RETURN_GENERIC("packed check tag mismatch\n"); \ +void _upb_MessageDef_Resolve(upb_DefBuilder* ctx, upb_MessageDef* m) { + for (int i = 0; i < m->field_count; i++) { + upb_FieldDef* f = (upb_FieldDef*)upb_MessageDef_Field(m, i); + _upb_FieldDef_Resolve(ctx, m->full_name, f); } -/* varint fields **************************************************************/ - -UPB_FORCEINLINE -static uint64_t fastdecode_munge(uint64_t val, int valbytes, bool zigzag) { - if (valbytes == 1) { - return val != 0; - } else if (zigzag) { - if (valbytes == 4) { - uint32_t n = val; - return (n >> 1) ^ -(int32_t)(n & 1); - } else if (valbytes == 8) { - return (val >> 1) ^ -(int64_t)(val & 1); + m->in_message_set = false; + for (int i = 0; i < upb_MessageDef_NestedExtensionCount(m); i++) { + upb_FieldDef* ext = (upb_FieldDef*)upb_MessageDef_NestedExtension(m, i); + _upb_FieldDef_Resolve(ctx, m->full_name, ext); + if (upb_FieldDef_Type(ext) == kUpb_FieldType_Message && + upb_FieldDef_Label(ext) == kUpb_Label_Optional && + upb_FieldDef_MessageSubDef(ext) == m && + UPB_DESC(MessageOptions_message_set_wire_format)( + upb_MessageDef_Options(upb_FieldDef_ContainingType(ext)))) { + m->in_message_set = true; } - UPB_UNREACHABLE(); } - return val; -} -UPB_FORCEINLINE -static const char* fastdecode_varint64(const char* ptr, uint64_t* val) { - ptr++; - *val = (uint8_t)ptr[-1]; - if (UPB_UNLIKELY(*val & 0x80)) { - int i; - for (i = 0; i < 8; i++) { - ptr++; - uint64_t byte = (uint8_t)ptr[-1]; - *val += (byte - 1) << (7 + 7 * i); - if (UPB_LIKELY((byte & 0x80) == 0)) goto done; - } - ptr++; - uint64_t byte = (uint8_t)ptr[-1]; - if (byte > 1) { - return NULL; - } - *val += (byte - 1) << 63; + for (int i = 0; i < upb_MessageDef_NestedMessageCount(m); i++) { + upb_MessageDef* n = (upb_MessageDef*)upb_MessageDef_NestedMessage(m, i); + _upb_MessageDef_Resolve(ctx, n); } -done: - UPB_ASSUME(ptr != NULL); - return ptr; } -#define FASTDECODE_UNPACKEDVARINT(d, ptr, msg, table, hasbits, data, tagbytes, \ - valbytes, card, zigzag, packed) \ - uint64_t val; \ - void* dst; \ - fastdecode_arr farr; \ - \ - FASTDECODE_CHECKPACKED(tagbytes, card, packed); \ - \ - dst = fastdecode_getfield(d, ptr, msg, &data, &hasbits, &farr, valbytes, \ - card); \ - if (card == CARD_r) { \ - if (UPB_UNLIKELY(!dst)) { \ - RETURN_GENERIC("need array resize\n"); \ - } \ - } \ - \ - again: \ - if (card == CARD_r) { \ - dst = fastdecode_resizearr(d, dst, &farr, valbytes); \ - } \ - \ - ptr += tagbytes; \ - ptr = fastdecode_varint64(ptr, &val); \ - if (ptr == NULL) _upb_FastDecoder_ErrorJmp(d, kUpb_DecodeStatus_Malformed); \ - val = fastdecode_munge(val, valbytes, zigzag); \ - memcpy(dst, &val, valbytes); \ - \ - if (card == CARD_r) { \ - fastdecode_nextret ret = fastdecode_nextrepeated( \ - d, dst, &ptr, &farr, data, tagbytes, valbytes); \ - switch (ret.next) { \ - case FD_NEXT_SAMEFIELD: \ - dst = ret.dst; \ - goto again; \ - case FD_NEXT_OTHERFIELD: \ - data = ret.tag; \ - UPB_MUSTTAIL return _upb_FastDecoder_TagDispatch(UPB_PARSE_ARGS); \ - case FD_NEXT_ATLIMIT: \ - return ptr; \ - } \ - } \ - \ - UPB_MUSTTAIL return fastdecode_dispatch(UPB_PARSE_ARGS); - -typedef struct { - uint8_t valbytes; - bool zigzag; - void* dst; - fastdecode_arr farr; -} fastdecode_varintdata; - -UPB_FORCEINLINE -static const char* fastdecode_topackedvarint(upb_EpsCopyInputStream* e, - const char* ptr, void* ctx) { - upb_Decoder* d = (upb_Decoder*)e; - fastdecode_varintdata* data = ctx; - void* dst = data->dst; - uint64_t val; +void _upb_MessageDef_InsertField(upb_DefBuilder* ctx, upb_MessageDef* m, + const upb_FieldDef* f) { + const int32_t field_number = upb_FieldDef_Number(f); - while (!_upb_Decoder_IsDone(d, &ptr)) { - dst = fastdecode_resizearr(d, dst, &data->farr, data->valbytes); - ptr = fastdecode_varint64(ptr, &val); - if (ptr == NULL) return NULL; - val = fastdecode_munge(val, data->valbytes, data->zigzag); - memcpy(dst, &val, data->valbytes); - dst = (char*)dst + data->valbytes; + if (field_number <= 0 || field_number > kUpb_MaxFieldNumber) { + _upb_DefBuilder_Errf(ctx, "invalid field number (%u)", field_number); } - fastdecode_commitarr(dst, &data->farr, data->valbytes); - return ptr; -} + const char* json_name = upb_FieldDef_JsonName(f); + const char* shortname = upb_FieldDef_Name(f); + const size_t shortnamelen = strlen(shortname); -#define FASTDECODE_PACKEDVARINT(d, ptr, msg, table, hasbits, data, tagbytes, \ - valbytes, zigzag, unpacked) \ - fastdecode_varintdata ctx = {valbytes, zigzag}; \ - \ - FASTDECODE_CHECKPACKED(tagbytes, CARD_r, unpacked); \ - \ - ctx.dst = fastdecode_getfield(d, ptr, msg, &data, &hasbits, &ctx.farr, \ - valbytes, CARD_r); \ - if (UPB_UNLIKELY(!ctx.dst)) { \ - RETURN_GENERIC("need array resize\n"); \ - } \ - \ - ptr += tagbytes; \ - ptr = fastdecode_delimited(d, ptr, &fastdecode_topackedvarint, &ctx); \ - \ - if (UPB_UNLIKELY(ptr == NULL)) { \ - _upb_FastDecoder_ErrorJmp(d, kUpb_DecodeStatus_Malformed); \ - } \ - \ - UPB_MUSTTAIL return fastdecode_dispatch(d, ptr, msg, table, hasbits, 0); + upb_value v = upb_value_constptr(f); -#define FASTDECODE_VARINT(d, ptr, msg, table, hasbits, data, tagbytes, \ - valbytes, card, zigzag, unpacked, packed) \ - if (card == CARD_p) { \ - FASTDECODE_PACKEDVARINT(d, ptr, msg, table, hasbits, data, tagbytes, \ - valbytes, zigzag, unpacked); \ - } else { \ - FASTDECODE_UNPACKEDVARINT(d, ptr, msg, table, hasbits, data, tagbytes, \ - valbytes, card, zigzag, packed); \ + upb_value existing_v; + if (upb_strtable_lookup(&m->ntof, shortname, &existing_v)) { + _upb_DefBuilder_Errf(ctx, "duplicate field name (%s)", shortname); } -#define z_ZZ true -#define b_ZZ false -#define v_ZZ false - -/* Generate all combinations: - * {s,o,r,p} x {b1,v4,z4,v8,z8} x {1bt,2bt} */ + const upb_value field_v = _upb_DefType_Pack(f, UPB_DEFTYPE_FIELD); + bool ok = + _upb_MessageDef_Insert(m, shortname, shortnamelen, field_v, ctx->arena); + if (!ok) _upb_DefBuilder_OomErr(ctx); -#define F(card, type, valbytes, tagbytes) \ - UPB_NOINLINE \ - const char* upb_p##card##type##valbytes##_##tagbytes##bt(UPB_PARSE_PARAMS) { \ - FASTDECODE_VARINT(d, ptr, msg, table, hasbits, data, tagbytes, valbytes, \ - CARD_##card, type##_ZZ, \ - upb_pr##type##valbytes##_##tagbytes##bt, \ - upb_pp##type##valbytes##_##tagbytes##bt); \ + if (strcmp(shortname, json_name) != 0 && + UPB_DESC(FeatureSet_json_format)(m->resolved_features) == + UPB_DESC(FeatureSet_ALLOW) && + upb_strtable_lookup(&m->ntof, json_name, &v)) { + _upb_DefBuilder_Errf( + ctx, "duplicate json_name for (%s) with original field name (%s)", + shortname, json_name); } -#define TYPES(card, tagbytes) \ - F(card, b, 1, tagbytes) \ - F(card, v, 4, tagbytes) \ - F(card, v, 8, tagbytes) \ - F(card, z, 4, tagbytes) \ - F(card, z, 8, tagbytes) - -#define TAGBYTES(card) \ - TYPES(card, 1) \ - TYPES(card, 2) + if (upb_strtable_lookup(&m->jtof, json_name, &v)) { + _upb_DefBuilder_Errf(ctx, "duplicate json_name (%s)", json_name); + } -TAGBYTES(s) -TAGBYTES(o) -TAGBYTES(r) -TAGBYTES(p) + const size_t json_size = strlen(json_name); + ok = upb_strtable_insert(&m->jtof, json_name, json_size, + upb_value_constptr(f), ctx->arena); + if (!ok) _upb_DefBuilder_OomErr(ctx); -#undef z_ZZ -#undef b_ZZ -#undef v_ZZ -#undef o_ONEOF -#undef s_ONEOF -#undef r_ONEOF -#undef F -#undef TYPES -#undef TAGBYTES -#undef FASTDECODE_UNPACKEDVARINT -#undef FASTDECODE_PACKEDVARINT -#undef FASTDECODE_VARINT + if (upb_inttable_lookup(&m->itof, field_number, NULL)) { + _upb_DefBuilder_Errf(ctx, "duplicate field number (%u)", field_number); + } -/* fixed fields ***************************************************************/ + ok = upb_inttable_insert(&m->itof, field_number, v, ctx->arena); + if (!ok) _upb_DefBuilder_OomErr(ctx); +} -#define FASTDECODE_UNPACKEDFIXED(d, ptr, msg, table, hasbits, data, tagbytes, \ - valbytes, card, packed) \ - void* dst; \ - fastdecode_arr farr; \ - \ - FASTDECODE_CHECKPACKED(tagbytes, card, packed) \ - \ - dst = fastdecode_getfield(d, ptr, msg, &data, &hasbits, &farr, valbytes, \ - card); \ - if (card == CARD_r) { \ - if (UPB_UNLIKELY(!dst)) { \ - RETURN_GENERIC("couldn't allocate array in arena\n"); \ - } \ - } \ - \ - again: \ - if (card == CARD_r) { \ - dst = fastdecode_resizearr(d, dst, &farr, valbytes); \ - } \ - \ - ptr += tagbytes; \ - memcpy(dst, ptr, valbytes); \ - ptr += valbytes; \ - \ - if (card == CARD_r) { \ - fastdecode_nextret ret = fastdecode_nextrepeated( \ - d, dst, &ptr, &farr, data, tagbytes, valbytes); \ - switch (ret.next) { \ - case FD_NEXT_SAMEFIELD: \ - dst = ret.dst; \ - goto again; \ - case FD_NEXT_OTHERFIELD: \ - data = ret.tag; \ - UPB_MUSTTAIL return _upb_FastDecoder_TagDispatch(UPB_PARSE_ARGS); \ - case FD_NEXT_ATLIMIT: \ - return ptr; \ - } \ - } \ - \ - UPB_MUSTTAIL return fastdecode_dispatch(UPB_PARSE_ARGS); +void _upb_MessageDef_CreateMiniTable(upb_DefBuilder* ctx, upb_MessageDef* m) { + if (ctx->layout == NULL) { + m->layout = _upb_MessageDef_MakeMiniTable(ctx, m); + } else { + m->layout = upb_MiniTableFile_Message(ctx->layout, ctx->msg_count++); + UPB_ASSERT(m->field_count == m->layout->UPB_PRIVATE(field_count)); -#define FASTDECODE_PACKEDFIXED(d, ptr, msg, table, hasbits, data, tagbytes, \ - valbytes, unpacked) \ - FASTDECODE_CHECKPACKED(tagbytes, CARD_r, unpacked) \ - \ - ptr += tagbytes; \ - int size = (uint8_t)ptr[0]; \ - ptr++; \ - if (size & 0x80) { \ - ptr = fastdecode_longsize(ptr, &size); \ - } \ - \ - if (UPB_UNLIKELY(!upb_EpsCopyInputStream_CheckDataSizeAvailable( \ - &d->input, ptr, size) || \ - (size % valbytes) != 0)) { \ - _upb_FastDecoder_ErrorJmp(d, kUpb_DecodeStatus_Malformed); \ - } \ - \ - upb_Array** arr_p = fastdecode_fieldmem(msg, data); \ - upb_Array* arr = *arr_p; \ - uint8_t elem_size_lg2 = __builtin_ctz(valbytes); \ - int elems = size / valbytes; \ - \ - if (UPB_LIKELY(!arr)) { \ - *arr_p = arr = \ - UPB_PRIVATE(_upb_Array_New)(&d->arena, elems, elem_size_lg2); \ - if (!arr) { \ - _upb_FastDecoder_ErrorJmp(d, kUpb_DecodeStatus_Malformed); \ - } \ - } else { \ - _upb_Array_ResizeUninitialized(arr, elems, &d->arena); \ - } \ - \ - char* dst = _upb_array_ptr(arr); \ - memcpy(dst, ptr, size); \ - arr->UPB_PRIVATE(size) = elems; \ - \ - ptr += size; \ - UPB_MUSTTAIL return fastdecode_dispatch(UPB_PARSE_ARGS); + // We don't need the result of this call, but it will assign layout_index + // for all the fields in O(n lg n) time. + _upb_FieldDefs_Sorted(m->fields, m->field_count, ctx->tmp_arena); + } -#define FASTDECODE_FIXED(d, ptr, msg, table, hasbits, data, tagbytes, \ - valbytes, card, unpacked, packed) \ - if (card == CARD_p) { \ - FASTDECODE_PACKEDFIXED(d, ptr, msg, table, hasbits, data, tagbytes, \ - valbytes, unpacked); \ - } else { \ - FASTDECODE_UNPACKEDFIXED(d, ptr, msg, table, hasbits, data, tagbytes, \ - valbytes, card, packed); \ + for (int i = 0; i < m->nested_msg_count; i++) { + upb_MessageDef* nested = + (upb_MessageDef*)upb_MessageDef_NestedMessage(m, i); + _upb_MessageDef_CreateMiniTable(ctx, nested); } +} -/* Generate all combinations: - * {s,o,r,p} x {f4,f8} x {1bt,2bt} */ +void _upb_MessageDef_LinkMiniTable(upb_DefBuilder* ctx, + const upb_MessageDef* m) { + for (int i = 0; i < upb_MessageDef_NestedExtensionCount(m); i++) { + const upb_FieldDef* ext = upb_MessageDef_NestedExtension(m, i); + _upb_FieldDef_BuildMiniTableExtension(ctx, ext); + } -#define F(card, valbytes, tagbytes) \ - UPB_NOINLINE \ - const char* upb_p##card##f##valbytes##_##tagbytes##bt(UPB_PARSE_PARAMS) { \ - FASTDECODE_FIXED(d, ptr, msg, table, hasbits, data, tagbytes, valbytes, \ - CARD_##card, upb_ppf##valbytes##_##tagbytes##bt, \ - upb_prf##valbytes##_##tagbytes##bt); \ + for (int i = 0; i < m->nested_msg_count; i++) { + _upb_MessageDef_LinkMiniTable(ctx, upb_MessageDef_NestedMessage(m, i)); } -#define TYPES(card, tagbytes) \ - F(card, 4, tagbytes) \ - F(card, 8, tagbytes) + if (ctx->layout) return; -#define TAGBYTES(card) \ - TYPES(card, 1) \ - TYPES(card, 2) + for (int i = 0; i < m->field_count; i++) { + const upb_FieldDef* f = upb_MessageDef_Field(m, i); + const upb_MessageDef* sub_m = upb_FieldDef_MessageSubDef(f); + const upb_EnumDef* sub_e = upb_FieldDef_EnumSubDef(f); + const int layout_index = _upb_FieldDef_LayoutIndex(f); + upb_MiniTable* mt = (upb_MiniTable*)upb_MessageDef_MiniTable(m); -TAGBYTES(s) -TAGBYTES(o) -TAGBYTES(r) -TAGBYTES(p) + UPB_ASSERT(layout_index < m->field_count); + upb_MiniTableField* mt_f = + (upb_MiniTableField*)&m->layout->UPB_PRIVATE(fields)[layout_index]; + if (sub_m) { + if (!mt->UPB_PRIVATE(subs)) { + _upb_DefBuilder_Errf(ctx, "unexpected submsg for (%s)", m->full_name); + } + UPB_ASSERT(mt_f); + UPB_ASSERT(sub_m->layout); + if (UPB_UNLIKELY(!upb_MiniTable_SetSubMessage(mt, mt_f, sub_m->layout))) { + _upb_DefBuilder_Errf(ctx, "invalid submsg for (%s)", m->full_name); + } + } else if (_upb_FieldDef_IsClosedEnum(f)) { + const upb_MiniTableEnum* mt_e = _upb_EnumDef_MiniTable(sub_e); + if (UPB_UNLIKELY(!upb_MiniTable_SetSubEnum(mt, mt_f, mt_e))) { + _upb_DefBuilder_Errf(ctx, "invalid subenum for (%s)", m->full_name); + } + } + } -#undef F -#undef TYPES -#undef TAGBYTES -#undef FASTDECODE_UNPACKEDFIXED -#undef FASTDECODE_PACKEDFIXED +#ifndef NDEBUG + for (int i = 0; i < m->field_count; i++) { + const upb_FieldDef* f = upb_MessageDef_Field(m, i); + const int layout_index = _upb_FieldDef_LayoutIndex(f); + UPB_ASSERT(layout_index < m->layout->UPB_PRIVATE(field_count)); + const upb_MiniTableField* mt_f = + &m->layout->UPB_PRIVATE(fields)[layout_index]; + UPB_ASSERT(upb_FieldDef_Type(f) == upb_MiniTableField_Type(mt_f)); + UPB_ASSERT(upb_FieldDef_CType(f) == upb_MiniTableField_CType(mt_f)); + UPB_ASSERT(upb_FieldDef_HasPresence(f) == + upb_MiniTableField_HasPresence(mt_f)); + } +#endif +} -/* string fields **************************************************************/ +static bool _upb_MessageDef_ValidateUtf8(const upb_MessageDef* m) { + bool has_string = false; + for (int i = 0; i < m->field_count; i++) { + const upb_FieldDef* f = upb_MessageDef_Field(m, i); + // Old binaries do not recognize the field-level "FlipValidateUtf8" wire + // modifier, so we do not actually have field-level control for old + // binaries. Given this, we judge that the better failure mode is to be + // more lax than intended, rather than more strict. To achieve this, we + // only mark the message with the ValidateUtf8 modifier if *all* fields + // validate UTF-8. + if (!_upb_FieldDef_ValidateUtf8(f)) return false; + if (upb_FieldDef_Type(f) == kUpb_FieldType_String) has_string = true; + } + return has_string; +} -typedef const char* fastdecode_copystr_func(struct upb_Decoder* d, - const char* ptr, upb_Message* msg, - const upb_MiniTable* table, - uint64_t hasbits, - upb_StringView* dst); +static uint64_t _upb_MessageDef_Modifiers(const upb_MessageDef* m) { + uint64_t out = 0; -UPB_NOINLINE -static const char* fastdecode_verifyutf8(upb_Decoder* d, const char* ptr, - upb_Message* msg, intptr_t table, - uint64_t hasbits, uint64_t data) { - upb_StringView* dst = (upb_StringView*)data; - if (!_upb_Decoder_VerifyUtf8Inline(dst->data, dst->size)) { - _upb_FastDecoder_ErrorJmp(d, kUpb_DecodeStatus_BadUtf8); + if (UPB_DESC(FeatureSet_repeated_field_encoding(m->resolved_features)) == + UPB_DESC(FeatureSet_PACKED)) { + out |= kUpb_MessageModifier_DefaultIsPacked; + } + + if (_upb_MessageDef_ValidateUtf8(m)) { + out |= kUpb_MessageModifier_ValidateUtf8; } - UPB_MUSTTAIL return fastdecode_dispatch(UPB_PARSE_ARGS); -} -#define FASTDECODE_LONGSTRING(d, ptr, msg, table, hasbits, dst, validate_utf8) \ - int size = (uint8_t)ptr[0]; /* Could plumb through hasbits. */ \ - ptr++; \ - if (size & 0x80) { \ - ptr = fastdecode_longsize(ptr, &size); \ - } \ - \ - if (UPB_UNLIKELY(!upb_EpsCopyInputStream_CheckSize(&d->input, ptr, size))) { \ - dst->size = 0; \ - _upb_FastDecoder_ErrorJmp(d, kUpb_DecodeStatus_Malformed); \ - } \ - \ - const char* s_ptr = ptr; \ - ptr = upb_EpsCopyInputStream_ReadString(&d->input, &s_ptr, size, &d->arena); \ - if (!ptr) _upb_FastDecoder_ErrorJmp(d, kUpb_DecodeStatus_OutOfMemory); \ - dst->data = s_ptr; \ - dst->size = size; \ - \ - if (validate_utf8) { \ - data = (uint64_t)dst; \ - UPB_MUSTTAIL return fastdecode_verifyutf8(UPB_PARSE_ARGS); \ - } else { \ - UPB_MUSTTAIL return fastdecode_dispatch(UPB_PARSE_ARGS); \ + if (m->ext_range_count) { + out |= kUpb_MessageModifier_IsExtendable; } -UPB_NOINLINE -static const char* fastdecode_longstring_utf8(struct upb_Decoder* d, - const char* ptr, upb_Message* msg, - intptr_t table, uint64_t hasbits, - uint64_t data) { - upb_StringView* dst = (upb_StringView*)data; - FASTDECODE_LONGSTRING(d, ptr, msg, table, hasbits, dst, true); + return out; } -UPB_NOINLINE -static const char* fastdecode_longstring_noutf8( - struct upb_Decoder* d, const char* ptr, upb_Message* msg, intptr_t table, - uint64_t hasbits, uint64_t data) { - upb_StringView* dst = (upb_StringView*)data; - FASTDECODE_LONGSTRING(d, ptr, msg, table, hasbits, dst, false); -} +static bool _upb_MessageDef_EncodeMap(upb_DescState* s, const upb_MessageDef* m, + upb_Arena* a) { + if (m->field_count != 2) return false; -UPB_FORCEINLINE -static void fastdecode_docopy(upb_Decoder* d, const char* ptr, uint32_t size, - int copy, char* data, size_t data_offset, - upb_StringView* dst) { - d->arena.UPB_PRIVATE(ptr) += copy; - dst->data = data + data_offset; - UPB_UNPOISON_MEMORY_REGION(data, copy); - memcpy(data, ptr, copy); - UPB_POISON_MEMORY_REGION(data + data_offset + size, - copy - data_offset - size); + const upb_FieldDef* key_field = upb_MessageDef_Field(m, 0); + const upb_FieldDef* val_field = upb_MessageDef_Field(m, 1); + if (key_field == NULL || val_field == NULL) return false; + + UPB_ASSERT(_upb_FieldDef_LayoutIndex(key_field) == 0); + UPB_ASSERT(_upb_FieldDef_LayoutIndex(val_field) == 1); + + s->ptr = upb_MtDataEncoder_EncodeMap( + &s->e, s->ptr, upb_FieldDef_Type(key_field), upb_FieldDef_Type(val_field), + _upb_FieldDef_Modifiers(key_field), _upb_FieldDef_Modifiers(val_field)); + return true; } -#define FASTDECODE_COPYSTRING(d, ptr, msg, table, hasbits, data, tagbytes, \ - card, validate_utf8) \ - upb_StringView* dst; \ - fastdecode_arr farr; \ - int64_t size; \ - size_t arena_has; \ - size_t common_has; \ - char* buf; \ - \ - UPB_ASSERT(!upb_EpsCopyInputStream_AliasingAvailable(&d->input, ptr, 0)); \ - UPB_ASSERT(fastdecode_checktag(data, tagbytes)); \ - \ - dst = fastdecode_getfield(d, ptr, msg, &data, &hasbits, &farr, \ - sizeof(upb_StringView), card); \ - \ - again: \ - if (card == CARD_r) { \ - dst = fastdecode_resizearr(d, dst, &farr, sizeof(upb_StringView)); \ - } \ - \ - size = (uint8_t)ptr[tagbytes]; \ - ptr += tagbytes + 1; \ - dst->size = size; \ - \ - buf = d->arena.UPB_PRIVATE(ptr); \ - arena_has = UPB_PRIVATE(_upb_ArenaHas)(&d->arena); \ - common_has = UPB_MIN(arena_has, \ - upb_EpsCopyInputStream_BytesAvailable(&d->input, ptr)); \ - \ - if (UPB_LIKELY(size <= 15 - tagbytes)) { \ - if (arena_has < 16) goto longstr; \ - fastdecode_docopy(d, ptr - tagbytes - 1, size, 16, buf, tagbytes + 1, \ - dst); \ - } else if (UPB_LIKELY(size <= 32)) { \ - if (UPB_UNLIKELY(common_has < 32)) goto longstr; \ - fastdecode_docopy(d, ptr, size, 32, buf, 0, dst); \ - } else if (UPB_LIKELY(size <= 64)) { \ - if (UPB_UNLIKELY(common_has < 64)) goto longstr; \ - fastdecode_docopy(d, ptr, size, 64, buf, 0, dst); \ - } else if (UPB_LIKELY(size < 128)) { \ - if (UPB_UNLIKELY(common_has < 128)) goto longstr; \ - fastdecode_docopy(d, ptr, size, 128, buf, 0, dst); \ - } else { \ - goto longstr; \ - } \ - \ - ptr += size; \ - \ - if (card == CARD_r) { \ - if (validate_utf8 && \ - !_upb_Decoder_VerifyUtf8Inline(dst->data, dst->size)) { \ - _upb_FastDecoder_ErrorJmp(d, kUpb_DecodeStatus_BadUtf8); \ - } \ - fastdecode_nextret ret = fastdecode_nextrepeated( \ - d, dst, &ptr, &farr, data, tagbytes, sizeof(upb_StringView)); \ - switch (ret.next) { \ - case FD_NEXT_SAMEFIELD: \ - dst = ret.dst; \ - goto again; \ - case FD_NEXT_OTHERFIELD: \ - data = ret.tag; \ - UPB_MUSTTAIL return _upb_FastDecoder_TagDispatch(UPB_PARSE_ARGS); \ - case FD_NEXT_ATLIMIT: \ - return ptr; \ - } \ - } \ - \ - if (card != CARD_r && validate_utf8) { \ - data = (uint64_t)dst; \ - UPB_MUSTTAIL return fastdecode_verifyutf8(UPB_PARSE_ARGS); \ - } \ - \ - UPB_MUSTTAIL return fastdecode_dispatch(UPB_PARSE_ARGS); \ - \ - longstr: \ - if (card == CARD_r) { \ - fastdecode_commitarr(dst + 1, &farr, sizeof(upb_StringView)); \ - } \ - ptr--; \ - if (validate_utf8) { \ - UPB_MUSTTAIL return fastdecode_longstring_utf8(d, ptr, msg, table, \ - hasbits, (uint64_t)dst); \ - } else { \ - UPB_MUSTTAIL return fastdecode_longstring_noutf8(d, ptr, msg, table, \ - hasbits, (uint64_t)dst); \ +static bool _upb_MessageDef_EncodeMessage(upb_DescState* s, + const upb_MessageDef* m, + upb_Arena* a) { + const upb_FieldDef** sorted = NULL; + if (!m->is_sorted) { + sorted = _upb_FieldDefs_Sorted(m->fields, m->field_count, a); + if (!sorted) return false; } -#define FASTDECODE_STRING(d, ptr, msg, table, hasbits, data, tagbytes, card, \ - copyfunc, validate_utf8) \ - upb_StringView* dst; \ - fastdecode_arr farr; \ - int64_t size; \ - \ - if (UPB_UNLIKELY(!fastdecode_checktag(data, tagbytes))) { \ - RETURN_GENERIC("string field tag mismatch\n"); \ - } \ - \ - if (UPB_UNLIKELY( \ - !upb_EpsCopyInputStream_AliasingAvailable(&d->input, ptr, 0))) { \ - UPB_MUSTTAIL return copyfunc(UPB_PARSE_ARGS); \ - } \ - \ - dst = fastdecode_getfield(d, ptr, msg, &data, &hasbits, &farr, \ - sizeof(upb_StringView), card); \ - \ - again: \ - if (card == CARD_r) { \ - dst = fastdecode_resizearr(d, dst, &farr, sizeof(upb_StringView)); \ - } \ - \ - size = (int8_t)ptr[tagbytes]; \ - ptr += tagbytes + 1; \ - \ - if (UPB_UNLIKELY( \ - !upb_EpsCopyInputStream_AliasingAvailable(&d->input, ptr, size))) { \ - ptr--; \ - if (validate_utf8) { \ - return fastdecode_longstring_utf8(d, ptr, msg, table, hasbits, \ - (uint64_t)dst); \ - } else { \ - return fastdecode_longstring_noutf8(d, ptr, msg, table, hasbits, \ - (uint64_t)dst); \ - } \ - } \ - \ - dst->data = ptr; \ - dst->size = size; \ - ptr = upb_EpsCopyInputStream_ReadStringAliased(&d->input, &dst->data, \ - dst->size); \ - \ - if (card == CARD_r) { \ - if (validate_utf8 && \ - !_upb_Decoder_VerifyUtf8Inline(dst->data, dst->size)) { \ - _upb_FastDecoder_ErrorJmp(d, kUpb_DecodeStatus_BadUtf8); \ - } \ - fastdecode_nextret ret = fastdecode_nextrepeated( \ - d, dst, &ptr, &farr, data, tagbytes, sizeof(upb_StringView)); \ - switch (ret.next) { \ - case FD_NEXT_SAMEFIELD: \ - dst = ret.dst; \ - goto again; \ - case FD_NEXT_OTHERFIELD: \ - data = ret.tag; \ - UPB_MUSTTAIL return _upb_FastDecoder_TagDispatch(UPB_PARSE_ARGS); \ - case FD_NEXT_ATLIMIT: \ - return ptr; \ - } \ - } \ - \ - if (card != CARD_r && validate_utf8) { \ - data = (uint64_t)dst; \ - UPB_MUSTTAIL return fastdecode_verifyutf8(UPB_PARSE_ARGS); \ - } \ - \ - UPB_MUSTTAIL return fastdecode_dispatch(UPB_PARSE_ARGS); + s->ptr = upb_MtDataEncoder_StartMessage(&s->e, s->ptr, + _upb_MessageDef_Modifiers(m)); -/* Generate all combinations: - * {p,c} x {s,o,r} x {s, b} x {1bt,2bt} */ + for (int i = 0; i < m->field_count; i++) { + const upb_FieldDef* f = sorted ? sorted[i] : upb_MessageDef_Field(m, i); + const upb_FieldType type = upb_FieldDef_Type(f); + const int number = upb_FieldDef_Number(f); + const uint64_t modifiers = _upb_FieldDef_Modifiers(f); -#define s_VALIDATE true -#define b_VALIDATE false + if (!_upb_DescState_Grow(s, a)) return false; + s->ptr = upb_MtDataEncoder_PutField(&s->e, s->ptr, type, number, modifiers); + } -#define F(card, tagbytes, type) \ - UPB_NOINLINE \ - const char* upb_c##card##type##_##tagbytes##bt(UPB_PARSE_PARAMS) { \ - FASTDECODE_COPYSTRING(d, ptr, msg, table, hasbits, data, tagbytes, \ - CARD_##card, type##_VALIDATE); \ - } \ - const char* upb_p##card##type##_##tagbytes##bt(UPB_PARSE_PARAMS) { \ - FASTDECODE_STRING(d, ptr, msg, table, hasbits, data, tagbytes, \ - CARD_##card, upb_c##card##type##_##tagbytes##bt, \ - type##_VALIDATE); \ + for (int i = 0; i < m->real_oneof_count; i++) { + if (!_upb_DescState_Grow(s, a)) return false; + s->ptr = upb_MtDataEncoder_StartOneof(&s->e, s->ptr); + + const upb_OneofDef* o = upb_MessageDef_Oneof(m, i); + const int field_count = upb_OneofDef_FieldCount(o); + for (int j = 0; j < field_count; j++) { + const int number = upb_FieldDef_Number(upb_OneofDef_Field(o, j)); + + if (!_upb_DescState_Grow(s, a)) return false; + s->ptr = upb_MtDataEncoder_PutOneofField(&s->e, s->ptr, number); + } } -#define UTF8(card, tagbytes) \ - F(card, tagbytes, s) \ - F(card, tagbytes, b) + return true; +} -#define TAGBYTES(card) \ - UTF8(card, 1) \ - UTF8(card, 2) +static bool _upb_MessageDef_EncodeMessageSet(upb_DescState* s, + const upb_MessageDef* m, + upb_Arena* a) { + s->ptr = upb_MtDataEncoder_EncodeMessageSet(&s->e, s->ptr); -TAGBYTES(s) -TAGBYTES(o) -TAGBYTES(r) + return true; +} -#undef s_VALIDATE -#undef b_VALIDATE -#undef F -#undef TAGBYTES -#undef FASTDECODE_LONGSTRING -#undef FASTDECODE_COPYSTRING -#undef FASTDECODE_STRING +bool upb_MessageDef_MiniDescriptorEncode(const upb_MessageDef* m, upb_Arena* a, + upb_StringView* out) { + upb_DescState s; + _upb_DescState_Init(&s); -/* message fields *************************************************************/ + if (!_upb_DescState_Grow(&s, a)) return false; -UPB_INLINE -upb_Message* decode_newmsg_ceil(upb_Decoder* d, const upb_MiniTable* m, - int msg_ceil_bytes) { - size_t size = m->UPB_PRIVATE(size) + sizeof(upb_Message_Internal); - char* msg_data; - if (UPB_LIKELY(msg_ceil_bytes > 0 && - UPB_PRIVATE(_upb_ArenaHas)(&d->arena) >= msg_ceil_bytes)) { - UPB_ASSERT(size <= (size_t)msg_ceil_bytes); - msg_data = d->arena.UPB_PRIVATE(ptr); - d->arena.UPB_PRIVATE(ptr) += size; - UPB_UNPOISON_MEMORY_REGION(msg_data, msg_ceil_bytes); - memset(msg_data, 0, msg_ceil_bytes); - UPB_POISON_MEMORY_REGION(msg_data + size, msg_ceil_bytes - size); + if (upb_MessageDef_IsMapEntry(m)) { + if (!_upb_MessageDef_EncodeMap(&s, m, a)) return false; + } else if (UPB_DESC(MessageOptions_message_set_wire_format)(m->opts)) { + if (!_upb_MessageDef_EncodeMessageSet(&s, m, a)) return false; } else { - msg_data = (char*)upb_Arena_Malloc(&d->arena, size); - memset(msg_data, 0, size); + if (!_upb_MessageDef_EncodeMessage(&s, m, a)) return false; } - return msg_data + sizeof(upb_Message_Internal); -} -typedef struct { - intptr_t table; - upb_Message* msg; -} fastdecode_submsgdata; + if (!_upb_DescState_Grow(&s, a)) return false; + *s.ptr = '\0'; -UPB_FORCEINLINE -static const char* fastdecode_tosubmsg(upb_EpsCopyInputStream* e, - const char* ptr, void* ctx) { - upb_Decoder* d = (upb_Decoder*)e; - fastdecode_submsgdata* submsg = ctx; - ptr = fastdecode_dispatch(d, ptr, submsg->msg, submsg->table, 0, 0); - UPB_ASSUME(ptr != NULL); - return ptr; + out->data = s.buf; + out->size = s.ptr - s.buf; + return true; } -#define FASTDECODE_SUBMSG(d, ptr, msg, table, hasbits, data, tagbytes, \ - msg_ceil_bytes, card) \ - \ - if (UPB_UNLIKELY(!fastdecode_checktag(data, tagbytes))) { \ - RETURN_GENERIC("submessage field tag mismatch\n"); \ - } \ - \ - if (--d->depth == 0) { \ - _upb_FastDecoder_ErrorJmp(d, kUpb_DecodeStatus_MaxDepthExceeded); \ - } \ - \ - upb_Message** dst; \ - uint32_t submsg_idx = (data >> 16) & 0xff; \ - const upb_MiniTable* tablep = decode_totablep(table); \ - const upb_MiniTable* subtablep = upb_MiniTableSub_Message( \ - *UPB_PRIVATE(_upb_MiniTable_GetSubByIndex)(tablep, submsg_idx)); \ - fastdecode_submsgdata submsg = {decode_totable(subtablep)}; \ - fastdecode_arr farr; \ - \ - if (subtablep->UPB_PRIVATE(table_mask) == (uint8_t)-1) { \ - d->depth++; \ - RETURN_GENERIC("submessage doesn't have fast tables."); \ - } \ - \ - dst = fastdecode_getfield(d, ptr, msg, &data, &hasbits, &farr, \ - sizeof(upb_Message*), card); \ - \ - if (card == CARD_s) { \ - *(uint32_t*)msg |= hasbits; \ - hasbits = 0; \ - } \ - \ - again: \ - if (card == CARD_r) { \ - dst = fastdecode_resizearr(d, dst, &farr, sizeof(upb_Message*)); \ - } \ - \ - submsg.msg = *dst; \ - \ - if (card == CARD_r || UPB_LIKELY(!submsg.msg)) { \ - *dst = submsg.msg = decode_newmsg_ceil(d, subtablep, msg_ceil_bytes); \ - } \ - \ - ptr += tagbytes; \ - ptr = fastdecode_delimited(d, ptr, fastdecode_tosubmsg, &submsg); \ - \ - if (UPB_UNLIKELY(ptr == NULL || d->end_group != DECODE_NOGROUP)) { \ - _upb_FastDecoder_ErrorJmp(d, kUpb_DecodeStatus_Malformed); \ - } \ - \ - if (card == CARD_r) { \ - fastdecode_nextret ret = fastdecode_nextrepeated( \ - d, dst, &ptr, &farr, data, tagbytes, sizeof(upb_Message*)); \ - switch (ret.next) { \ - case FD_NEXT_SAMEFIELD: \ - dst = ret.dst; \ - goto again; \ - case FD_NEXT_OTHERFIELD: \ - d->depth++; \ - data = ret.tag; \ - UPB_MUSTTAIL return _upb_FastDecoder_TagDispatch(UPB_PARSE_ARGS); \ - case FD_NEXT_ATLIMIT: \ - d->depth++; \ - return ptr; \ - } \ - } \ - \ - d->depth++; \ - UPB_MUSTTAIL return fastdecode_dispatch(UPB_PARSE_ARGS); +static upb_StringView* _upb_ReservedNames_New(upb_DefBuilder* ctx, int n, + const upb_StringView* protos) { + upb_StringView* sv = _upb_DefBuilder_Alloc(ctx, sizeof(upb_StringView) * n); + for (int i = 0; i < n; i++) { + sv[i].data = + upb_strdup2(protos[i].data, protos[i].size, _upb_DefBuilder_Arena(ctx)); + sv[i].size = protos[i].size; + } + return sv; +} -#define F(card, tagbytes, size_ceil, ceil_arg) \ - const char* upb_p##card##m_##tagbytes##bt_max##size_ceil##b( \ - UPB_PARSE_PARAMS) { \ - FASTDECODE_SUBMSG(d, ptr, msg, table, hasbits, data, tagbytes, ceil_arg, \ - CARD_##card); \ +static void create_msgdef(upb_DefBuilder* ctx, const char* prefix, + const UPB_DESC(DescriptorProto*) msg_proto, + const UPB_DESC(FeatureSet*) parent_features, + const upb_MessageDef* containing_type, + upb_MessageDef* m) { + const UPB_DESC(OneofDescriptorProto)* const* oneofs; + const UPB_DESC(FieldDescriptorProto)* const* fields; + const UPB_DESC(DescriptorProto_ExtensionRange)* const* ext_ranges; + const UPB_DESC(DescriptorProto_ReservedRange)* const* res_ranges; + const upb_StringView* res_names; + size_t n_oneof, n_field, n_enum, n_ext, n_msg; + size_t n_ext_range, n_res_range, n_res_name; + upb_StringView name; + + UPB_DEF_SET_OPTIONS(m->opts, DescriptorProto, MessageOptions, msg_proto); + m->resolved_features = _upb_DefBuilder_ResolveFeatures( + ctx, parent_features, UPB_DESC(MessageOptions_features)(m->opts)); + + // Must happen before _upb_DefBuilder_Add() + m->file = _upb_DefBuilder_File(ctx); + + m->containing_type = containing_type; + m->is_sorted = true; + + name = UPB_DESC(DescriptorProto_name)(msg_proto); + + m->full_name = _upb_DefBuilder_MakeFullName(ctx, prefix, name); + _upb_DefBuilder_Add(ctx, m->full_name, _upb_DefType_Pack(m, UPB_DEFTYPE_MSG)); + + oneofs = UPB_DESC(DescriptorProto_oneof_decl)(msg_proto, &n_oneof); + fields = UPB_DESC(DescriptorProto_field)(msg_proto, &n_field); + ext_ranges = + UPB_DESC(DescriptorProto_extension_range)(msg_proto, &n_ext_range); + res_ranges = + UPB_DESC(DescriptorProto_reserved_range)(msg_proto, &n_res_range); + res_names = UPB_DESC(DescriptorProto_reserved_name)(msg_proto, &n_res_name); + + bool ok = upb_inttable_init(&m->itof, ctx->arena); + if (!ok) _upb_DefBuilder_OomErr(ctx); + + ok = upb_strtable_init(&m->ntof, n_oneof + n_field, ctx->arena); + if (!ok) _upb_DefBuilder_OomErr(ctx); + + ok = upb_strtable_init(&m->jtof, n_field, ctx->arena); + if (!ok) _upb_DefBuilder_OomErr(ctx); + + m->oneof_count = n_oneof; + m->oneofs = _upb_OneofDefs_New(ctx, n_oneof, oneofs, m->resolved_features, m); + + m->field_count = n_field; + m->fields = _upb_FieldDefs_New(ctx, n_field, fields, m->resolved_features, + m->full_name, m, &m->is_sorted); + + // Message Sets may not contain fields. + if (UPB_UNLIKELY(UPB_DESC(MessageOptions_message_set_wire_format)(m->opts))) { + if (UPB_UNLIKELY(n_field > 0)) { + _upb_DefBuilder_Errf(ctx, "invalid message set (%s)", m->full_name); + } } -#define SIZES(card, tagbytes) \ - F(card, tagbytes, 64, 64) \ - F(card, tagbytes, 128, 128) \ - F(card, tagbytes, 192, 192) \ - F(card, tagbytes, 256, 256) \ - F(card, tagbytes, max, -1) + m->ext_range_count = n_ext_range; + m->ext_ranges = _upb_ExtensionRanges_New(ctx, n_ext_range, ext_ranges, + m->resolved_features, m); + + m->res_range_count = n_res_range; + m->res_ranges = + _upb_MessageReservedRanges_New(ctx, n_res_range, res_ranges, m); + + m->res_name_count = n_res_name; + m->res_names = _upb_ReservedNames_New(ctx, n_res_name, res_names); + + const size_t synthetic_count = _upb_OneofDefs_Finalize(ctx, m); + m->real_oneof_count = m->oneof_count - synthetic_count; + + assign_msg_wellknowntype(m); + upb_inttable_compact(&m->itof, ctx->arena); + + const UPB_DESC(EnumDescriptorProto)* const* enums = + UPB_DESC(DescriptorProto_enum_type)(msg_proto, &n_enum); + m->nested_enum_count = n_enum; + m->nested_enums = + _upb_EnumDefs_New(ctx, n_enum, enums, m->resolved_features, m); + + const UPB_DESC(FieldDescriptorProto)* const* exts = + UPB_DESC(DescriptorProto_extension)(msg_proto, &n_ext); + m->nested_ext_count = n_ext; + m->nested_exts = _upb_Extensions_New(ctx, n_ext, exts, m->resolved_features, + m->full_name, m); + + const UPB_DESC(DescriptorProto)* const* msgs = + UPB_DESC(DescriptorProto_nested_type)(msg_proto, &n_msg); + m->nested_msg_count = n_msg; + m->nested_msgs = + _upb_MessageDefs_New(ctx, n_msg, msgs, m->resolved_features, m); +} + +// Allocate and initialize an array of |n| message defs. +upb_MessageDef* _upb_MessageDefs_New(upb_DefBuilder* ctx, int n, + const UPB_DESC(DescriptorProto*) + const* protos, + const UPB_DESC(FeatureSet*) + parent_features, + const upb_MessageDef* containing_type) { + _upb_DefType_CheckPadding(sizeof(upb_MessageDef)); + + const char* name = containing_type ? containing_type->full_name + : _upb_FileDef_RawPackage(ctx->file); -#define TAGBYTES(card) \ - SIZES(card, 1) \ - SIZES(card, 2) + upb_MessageDef* m = _upb_DefBuilder_Alloc(ctx, sizeof(upb_MessageDef) * n); + for (int i = 0; i < n; i++) { + create_msgdef(ctx, name, protos[i], parent_features, containing_type, + &m[i]); + } + return m; +} -TAGBYTES(s) -TAGBYTES(o) -TAGBYTES(r) -#undef TAGBYTES -#undef SIZES -#undef F -#undef FASTDECODE_SUBMSG +// Must be last. -#endif /* UPB_FASTTABLE */ +struct upb_MessageReservedRange { + int32_t start; + int32_t end; +}; +upb_MessageReservedRange* _upb_MessageReservedRange_At( + const upb_MessageReservedRange* r, int i) { + return (upb_MessageReservedRange*)&r[i]; +} -#include -#include +int32_t upb_MessageReservedRange_Start(const upb_MessageReservedRange* r) { + return r->start; +} +int32_t upb_MessageReservedRange_End(const upb_MessageReservedRange* r) { + return r->end; +} +upb_MessageReservedRange* _upb_MessageReservedRanges_New( + upb_DefBuilder* ctx, int n, + const UPB_DESC(DescriptorProto_ReservedRange) * const* protos, + const upb_MessageDef* m) { + upb_MessageReservedRange* r = + _upb_DefBuilder_Alloc(ctx, sizeof(upb_MessageReservedRange) * n); -// Must be last. + for (int i = 0; i < n; i++) { + const int32_t start = + UPB_DESC(DescriptorProto_ReservedRange_start)(protos[i]); + const int32_t end = UPB_DESC(DescriptorProto_ReservedRange_end)(protos[i]); + const int32_t max = kUpb_MaxFieldNumber + 1; -UPB_NOINLINE UPB_PRIVATE(_upb_WireReader_LongVarint) - UPB_PRIVATE(_upb_WireReader_ReadLongVarint)(const char* ptr, uint64_t val) { - UPB_PRIVATE(_upb_WireReader_LongVarint) ret = {NULL, 0}; - uint64_t byte; - int i; - for (i = 1; i < 10; i++) { - byte = (uint8_t)ptr[i]; - val += (byte - 1) << (i * 7); - if (!(byte & 0x80)) { - ret.ptr = ptr + i + 1; - ret.val = val; - return ret; + // A full validation would also check that each range is disjoint, and that + // none of the fields overlap with the extension ranges, but we are just + // sanity checking here. + if (start < 1 || end <= start || end > max) { + _upb_DefBuilder_Errf(ctx, + "Reserved range (%d, %d) is invalid, message=%s\n", + (int)start, (int)end, upb_MessageDef_FullName(m)); } - } - return ret; -} -const char* UPB_PRIVATE(_upb_WireReader_SkipGroup)( - const char* ptr, uint32_t tag, int depth_limit, - upb_EpsCopyInputStream* stream) { - if (--depth_limit == 0) return NULL; - uint32_t end_group_tag = (tag & ~7ULL) | kUpb_WireType_EndGroup; - while (!upb_EpsCopyInputStream_IsDone(stream, &ptr)) { - uint32_t tag; - ptr = upb_WireReader_ReadTag(ptr, &tag); - if (!ptr) return NULL; - if (tag == end_group_tag) return ptr; - ptr = _upb_WireReader_SkipValue(ptr, tag, depth_limit, stream); - if (!ptr) return NULL; + r[i].start = start; + r[i].end = end; } - return ptr; -} + return r; +} -#include // Must be last. -const struct upb_Extension* _upb_Message_Getext( - const struct upb_Message* msg, const upb_MiniTableExtension* e) { - size_t n; - const struct upb_Extension* ext = UPB_PRIVATE(_upb_Message_Getexts)(msg, &n); - - // For now we use linear search exclusively to find extensions. - // If this becomes an issue due to messages with lots of extensions, - // we can introduce a table of some sort. - for (size_t i = 0; i < n; i++) { - if (ext[i].ext == e) { - return &ext[i]; - } - } +struct upb_MethodDef { + const UPB_DESC(MethodOptions*) opts; + const UPB_DESC(FeatureSet*) resolved_features; + upb_ServiceDef* service; + const char* full_name; + const upb_MessageDef* input_type; + const upb_MessageDef* output_type; + int index; + bool client_streaming; + bool server_streaming; +}; - return NULL; +upb_MethodDef* _upb_MethodDef_At(const upb_MethodDef* m, int i) { + return (upb_MethodDef*)&m[i]; } -const struct upb_Extension* UPB_PRIVATE(_upb_Message_Getexts)( - const struct upb_Message* msg, size_t* count) { - upb_Message_InternalData* in = upb_Message_GetInternalData(msg); - if (in) { - *count = (in->size - in->ext_begin) / sizeof(struct upb_Extension); - return UPB_PTR_AT(in, in->ext_begin, void); - } else { - *count = 0; - return NULL; - } +const upb_ServiceDef* upb_MethodDef_Service(const upb_MethodDef* m) { + return m->service; } -struct upb_Extension* _upb_Message_GetOrCreateExtension( - struct upb_Message* msg, const upb_MiniTableExtension* e, upb_Arena* a) { - struct upb_Extension* ext = - (struct upb_Extension*)_upb_Message_Getext(msg, e); - if (ext) return ext; - if (!UPB_PRIVATE(_upb_Message_Realloc)(msg, sizeof(struct upb_Extension), a)) - return NULL; - upb_Message_InternalData* in = upb_Message_GetInternalData(msg); - in->ext_begin -= sizeof(struct upb_Extension); - ext = UPB_PTR_AT(in, in->ext_begin, void); - memset(ext, 0, sizeof(struct upb_Extension)); - ext->ext = e; - return ext; +const UPB_DESC(MethodOptions) * upb_MethodDef_Options(const upb_MethodDef* m) { + return m->opts; } +bool upb_MethodDef_HasOptions(const upb_MethodDef* m) { + return m->opts != (void*)kUpbDefOptDefault; +} -#include -#include - +const UPB_DESC(FeatureSet) * + upb_MethodDef_ResolvedFeatures(const upb_MethodDef* m) { + return m->resolved_features; +} -// Must be last. +const char* upb_MethodDef_FullName(const upb_MethodDef* m) { + return m->full_name; +} -const float kUpb_FltInfinity = INFINITY; -const double kUpb_Infinity = INFINITY; -const double kUpb_NaN = NAN; +const char* upb_MethodDef_Name(const upb_MethodDef* m) { + return _upb_DefBuilder_FullToShort(m->full_name); +} -bool UPB_PRIVATE(_upb_Message_Realloc)(struct upb_Message* msg, size_t need, - upb_Arena* a) { - const size_t overhead = sizeof(upb_Message_InternalData); +int upb_MethodDef_Index(const upb_MethodDef* m) { return m->index; } - upb_Message_Internal* owner = upb_Message_Getinternal(msg); - upb_Message_InternalData* in = owner->internal; - if (!in) { - // No internal data, allocate from scratch. - size_t size = UPB_MAX(128, upb_Log2CeilingSize(need + overhead)); - in = upb_Arena_Malloc(a, size); - if (!in) return false; +const upb_MessageDef* upb_MethodDef_InputType(const upb_MethodDef* m) { + return m->input_type; +} - in->size = size; - in->unknown_end = overhead; - in->ext_begin = size; - owner->internal = in; - } else if (in->ext_begin - in->unknown_end < need) { - // Internal data is too small, reallocate. - size_t new_size = upb_Log2CeilingSize(in->size + need); - size_t ext_bytes = in->size - in->ext_begin; - size_t new_ext_begin = new_size - ext_bytes; - in = upb_Arena_Realloc(a, in, in->size, new_size); - if (!in) return false; +const upb_MessageDef* upb_MethodDef_OutputType(const upb_MethodDef* m) { + return m->output_type; +} - if (ext_bytes) { - // Need to move extension data to the end. - char* ptr = (char*)in; - memmove(ptr + new_ext_begin, ptr + in->ext_begin, ext_bytes); - } - in->ext_begin = new_ext_begin; - in->size = new_size; - owner->internal = in; - } +bool upb_MethodDef_ClientStreaming(const upb_MethodDef* m) { + return m->client_streaming; +} - UPB_ASSERT(in->ext_begin - in->unknown_end >= need); - return true; +bool upb_MethodDef_ServerStreaming(const upb_MethodDef* m) { + return m->server_streaming; } +static void create_method(upb_DefBuilder* ctx, + const UPB_DESC(MethodDescriptorProto*) method_proto, + const UPB_DESC(FeatureSet*) parent_features, + upb_ServiceDef* s, upb_MethodDef* m) { + UPB_DEF_SET_OPTIONS(m->opts, MethodDescriptorProto, MethodOptions, + method_proto); + m->resolved_features = _upb_DefBuilder_ResolveFeatures( + ctx, parent_features, UPB_DESC(MethodOptions_features)(m->opts)); -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', '{', '|', '}', '~', -}; + upb_StringView name = UPB_DESC(MethodDescriptorProto_name)(method_proto); -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, -}; + m->service = s; + m->full_name = + _upb_DefBuilder_MakeFullName(ctx, upb_ServiceDef_FullName(s), name); + m->client_streaming = + UPB_DESC(MethodDescriptorProto_client_streaming)(method_proto); + m->server_streaming = + UPB_DESC(MethodDescriptorProto_server_streaming)(method_proto); + m->input_type = _upb_DefBuilder_Resolve( + ctx, m->full_name, m->full_name, + UPB_DESC(MethodDescriptorProto_input_type)(method_proto), + UPB_DEFTYPE_MSG); + m->output_type = _upb_DefBuilder_Resolve( + ctx, m->full_name, m->full_name, + UPB_DESC(MethodDescriptorProto_output_type)(method_proto), + UPB_DEFTYPE_MSG); +} + +// Allocate and initialize an array of |n| method defs belonging to |s|. +upb_MethodDef* _upb_MethodDefs_New(upb_DefBuilder* ctx, int n, + const UPB_DESC(MethodDescriptorProto*) + const* protos, + const UPB_DESC(FeatureSet*) parent_features, + upb_ServiceDef* s) { + upb_MethodDef* m = _upb_DefBuilder_Alloc(ctx, sizeof(upb_MethodDef) * n); + for (int i = 0; i < n; i++) { + create_method(ctx, protos[i], parent_features, s, &m[i]); + m[i].index = i; + } + return m; +} -#include -#include -#include +#include +#include +#include // Must be last. -typedef struct { - uint64_t present_values_mask; - uint32_t last_written_value; -} upb_MtDataEncoderInternal_EnumState; - -typedef struct { - uint64_t msg_modifiers; - uint32_t last_field_num; - enum { - kUpb_OneofState_NotStarted, - kUpb_OneofState_StartedOneof, - kUpb_OneofState_EmittedOneofField, - } oneof_state; -} upb_MtDataEncoderInternal_MsgState; +struct upb_OneofDef { + const UPB_DESC(OneofOptions*) opts; + const UPB_DESC(FeatureSet*) resolved_features; + const upb_MessageDef* parent; + const char* full_name; + int field_count; + bool synthetic; + const upb_FieldDef** fields; + upb_strtable ntof; // lookup a field by name + upb_inttable itof; // lookup a field by number (index) +}; -typedef struct { - char* buf_start; // Only for checking kUpb_MtDataEncoder_MinSize. - union { - upb_MtDataEncoderInternal_EnumState enum_state; - upb_MtDataEncoderInternal_MsgState msg_state; - } state; -} upb_MtDataEncoderInternal; +upb_OneofDef* _upb_OneofDef_At(const upb_OneofDef* o, int i) { + return (upb_OneofDef*)&o[i]; +} -static upb_MtDataEncoderInternal* upb_MtDataEncoder_GetInternal( - upb_MtDataEncoder* e, char* buf_start) { - UPB_ASSERT(sizeof(upb_MtDataEncoderInternal) <= sizeof(e->internal)); - upb_MtDataEncoderInternal* ret = (upb_MtDataEncoderInternal*)e->internal; - ret->buf_start = buf_start; - return ret; +const UPB_DESC(OneofOptions) * upb_OneofDef_Options(const upb_OneofDef* o) { + return o->opts; } -static char* upb_MtDataEncoder_PutRaw(upb_MtDataEncoder* e, char* ptr, - char ch) { - upb_MtDataEncoderInternal* in = (upb_MtDataEncoderInternal*)e->internal; - UPB_ASSERT(ptr - in->buf_start < kUpb_MtDataEncoder_MinSize); - if (ptr == e->end) return NULL; - *ptr++ = ch; - return ptr; +bool upb_OneofDef_HasOptions(const upb_OneofDef* o) { + return o->opts != (void*)kUpbDefOptDefault; } -static char* upb_MtDataEncoder_Put(upb_MtDataEncoder* e, char* ptr, char ch) { - return upb_MtDataEncoder_PutRaw(e, ptr, _upb_ToBase92(ch)); +const UPB_DESC(FeatureSet) * + upb_OneofDef_ResolvedFeatures(const upb_OneofDef* o) { + return o->resolved_features; } -static char* upb_MtDataEncoder_PutBase92Varint(upb_MtDataEncoder* e, char* ptr, - uint32_t val, int min, int max) { - int shift = upb_Log2Ceiling(_upb_FromBase92(max) - _upb_FromBase92(min) + 1); - UPB_ASSERT(shift <= 6); - uint32_t mask = (1 << shift) - 1; - do { - uint32_t bits = val & mask; - ptr = upb_MtDataEncoder_Put(e, ptr, bits + _upb_FromBase92(min)); - if (!ptr) return NULL; - val >>= shift; - } while (val); - return ptr; +const char* upb_OneofDef_FullName(const upb_OneofDef* o) { + return o->full_name; } -char* upb_MtDataEncoder_PutModifier(upb_MtDataEncoder* e, char* ptr, - uint64_t mod) { - if (mod) { - ptr = upb_MtDataEncoder_PutBase92Varint(e, ptr, mod, - kUpb_EncodedValue_MinModifier, - kUpb_EncodedValue_MaxModifier); - } - return ptr; +const char* upb_OneofDef_Name(const upb_OneofDef* o) { + return _upb_DefBuilder_FullToShort(o->full_name); } -char* upb_MtDataEncoder_EncodeExtension(upb_MtDataEncoder* e, char* ptr, - upb_FieldType type, uint32_t field_num, - uint64_t field_mod) { - upb_MtDataEncoderInternal* in = upb_MtDataEncoder_GetInternal(e, ptr); - in->state.msg_state.msg_modifiers = 0; - in->state.msg_state.last_field_num = 0; - in->state.msg_state.oneof_state = kUpb_OneofState_NotStarted; +const upb_MessageDef* upb_OneofDef_ContainingType(const upb_OneofDef* o) { + return o->parent; +} - ptr = upb_MtDataEncoder_PutRaw(e, ptr, kUpb_EncodedVersion_ExtensionV1); - if (!ptr) return NULL; +int upb_OneofDef_FieldCount(const upb_OneofDef* o) { return o->field_count; } - return upb_MtDataEncoder_PutField(e, ptr, type, field_num, field_mod); +const upb_FieldDef* upb_OneofDef_Field(const upb_OneofDef* o, int i) { + UPB_ASSERT(i < o->field_count); + return o->fields[i]; } -char* upb_MtDataEncoder_EncodeMap(upb_MtDataEncoder* e, char* ptr, - upb_FieldType key_type, - upb_FieldType value_type, uint64_t key_mod, - uint64_t value_mod) { - upb_MtDataEncoderInternal* in = upb_MtDataEncoder_GetInternal(e, ptr); - in->state.msg_state.msg_modifiers = 0; - in->state.msg_state.last_field_num = 0; - in->state.msg_state.oneof_state = kUpb_OneofState_NotStarted; +int upb_OneofDef_numfields(const upb_OneofDef* o) { return o->field_count; } - ptr = upb_MtDataEncoder_PutRaw(e, ptr, kUpb_EncodedVersion_MapV1); - if (!ptr) return NULL; +uint32_t upb_OneofDef_Index(const upb_OneofDef* o) { + // Compute index in our parent's array. + return o - upb_MessageDef_Oneof(o->parent, 0); +} - ptr = upb_MtDataEncoder_PutField(e, ptr, key_type, 1, key_mod); - if (!ptr) return NULL; +bool upb_OneofDef_IsSynthetic(const upb_OneofDef* o) { return o->synthetic; } - return upb_MtDataEncoder_PutField(e, ptr, value_type, 2, value_mod); +const upb_FieldDef* upb_OneofDef_LookupNameWithSize(const upb_OneofDef* o, + const char* name, + size_t size) { + upb_value val; + return upb_strtable_lookup2(&o->ntof, name, size, &val) + ? upb_value_getptr(val) + : NULL; } -char* upb_MtDataEncoder_EncodeMessageSet(upb_MtDataEncoder* e, char* ptr) { - (void)upb_MtDataEncoder_GetInternal(e, ptr); - return upb_MtDataEncoder_PutRaw(e, ptr, kUpb_EncodedVersion_MessageSetV1); +const upb_FieldDef* upb_OneofDef_LookupName(const upb_OneofDef* o, + const char* name) { + return upb_OneofDef_LookupNameWithSize(o, name, strlen(name)); } -char* upb_MtDataEncoder_StartMessage(upb_MtDataEncoder* e, char* ptr, - uint64_t msg_mod) { - upb_MtDataEncoderInternal* in = upb_MtDataEncoder_GetInternal(e, ptr); - in->state.msg_state.msg_modifiers = msg_mod; - in->state.msg_state.last_field_num = 0; - in->state.msg_state.oneof_state = kUpb_OneofState_NotStarted; +const upb_FieldDef* upb_OneofDef_LookupNumber(const upb_OneofDef* o, + uint32_t num) { + upb_value val; + return upb_inttable_lookup(&o->itof, num, &val) ? upb_value_getptr(val) + : NULL; +} - ptr = upb_MtDataEncoder_PutRaw(e, ptr, kUpb_EncodedVersion_MessageV1); - if (!ptr) return NULL; +void _upb_OneofDef_Insert(upb_DefBuilder* ctx, upb_OneofDef* o, + const upb_FieldDef* f, const char* name, + size_t size) { + o->field_count++; + if (_upb_FieldDef_IsProto3Optional(f)) o->synthetic = true; - return upb_MtDataEncoder_PutModifier(e, ptr, msg_mod); -} + const int number = upb_FieldDef_Number(f); + const upb_value v = upb_value_constptr(f); -static char* _upb_MtDataEncoder_MaybePutFieldSkip(upb_MtDataEncoder* e, - char* ptr, - uint32_t field_num) { - upb_MtDataEncoderInternal* in = (upb_MtDataEncoderInternal*)e->internal; - if (field_num <= in->state.msg_state.last_field_num) return NULL; - if (in->state.msg_state.last_field_num + 1 != field_num) { - // Put skip. - UPB_ASSERT(field_num > in->state.msg_state.last_field_num); - uint32_t skip = field_num - in->state.msg_state.last_field_num; - ptr = upb_MtDataEncoder_PutBase92Varint( - e, ptr, skip, kUpb_EncodedValue_MinSkip, kUpb_EncodedValue_MaxSkip); - if (!ptr) return NULL; + // TODO: This lookup is unfortunate because we also perform it when + // inserting into the message's table. Unfortunately that step occurs after + // this one and moving things around could be tricky so let's leave it for + // a future refactoring. + const bool number_exists = upb_inttable_lookup(&o->itof, number, NULL); + if (UPB_UNLIKELY(number_exists)) { + _upb_DefBuilder_Errf(ctx, "oneof fields have the same number (%d)", number); + } + + // TODO: More redundant work happening here. + const bool name_exists = upb_strtable_lookup2(&o->ntof, name, size, NULL); + if (UPB_UNLIKELY(name_exists)) { + _upb_DefBuilder_Errf(ctx, "oneof fields have the same name (%.*s)", + (int)size, name); + } + + const bool ok = upb_inttable_insert(&o->itof, number, v, ctx->arena) && + upb_strtable_insert(&o->ntof, name, size, v, ctx->arena); + if (UPB_UNLIKELY(!ok)) { + _upb_DefBuilder_OomErr(ctx); } - in->state.msg_state.last_field_num = field_num; - return ptr; } -static char* _upb_MtDataEncoder_PutFieldType(upb_MtDataEncoder* e, char* ptr, - upb_FieldType type, - uint64_t field_mod) { - static const char kUpb_TypeToEncoded[] = { - [kUpb_FieldType_Double] = kUpb_EncodedType_Double, - [kUpb_FieldType_Float] = kUpb_EncodedType_Float, - [kUpb_FieldType_Int64] = kUpb_EncodedType_Int64, - [kUpb_FieldType_UInt64] = kUpb_EncodedType_UInt64, - [kUpb_FieldType_Int32] = kUpb_EncodedType_Int32, - [kUpb_FieldType_Fixed64] = kUpb_EncodedType_Fixed64, - [kUpb_FieldType_Fixed32] = kUpb_EncodedType_Fixed32, - [kUpb_FieldType_Bool] = kUpb_EncodedType_Bool, - [kUpb_FieldType_String] = kUpb_EncodedType_String, - [kUpb_FieldType_Group] = kUpb_EncodedType_Group, - [kUpb_FieldType_Message] = kUpb_EncodedType_Message, - [kUpb_FieldType_Bytes] = kUpb_EncodedType_Bytes, - [kUpb_FieldType_UInt32] = kUpb_EncodedType_UInt32, - [kUpb_FieldType_Enum] = kUpb_EncodedType_OpenEnum, - [kUpb_FieldType_SFixed32] = kUpb_EncodedType_SFixed32, - [kUpb_FieldType_SFixed64] = kUpb_EncodedType_SFixed64, - [kUpb_FieldType_SInt32] = kUpb_EncodedType_SInt32, - [kUpb_FieldType_SInt64] = kUpb_EncodedType_SInt64, - }; +// Returns the synthetic count. +size_t _upb_OneofDefs_Finalize(upb_DefBuilder* ctx, upb_MessageDef* m) { + int synthetic_count = 0; - int encoded_type = kUpb_TypeToEncoded[type]; + for (int i = 0; i < upb_MessageDef_OneofCount(m); i++) { + upb_OneofDef* o = (upb_OneofDef*)upb_MessageDef_Oneof(m, i); - if (field_mod & kUpb_FieldModifier_IsClosedEnum) { - UPB_ASSERT(type == kUpb_FieldType_Enum); - encoded_type = kUpb_EncodedType_ClosedEnum; + if (o->synthetic && o->field_count != 1) { + _upb_DefBuilder_Errf(ctx, + "Synthetic oneofs must have one field, not %d: %s", + o->field_count, upb_OneofDef_Name(o)); + } + + if (o->synthetic) { + synthetic_count++; + } else if (synthetic_count != 0) { + _upb_DefBuilder_Errf( + ctx, "Synthetic oneofs must be after all other oneofs: %s", + upb_OneofDef_Name(o)); + } + + o->fields = + _upb_DefBuilder_Alloc(ctx, sizeof(upb_FieldDef*) * o->field_count); + o->field_count = 0; } - if (field_mod & kUpb_FieldModifier_IsRepeated) { - // Repeated fields shift the type number up (unlike other modifiers which - // are bit flags). - encoded_type += kUpb_EncodedType_RepeatedBase; + for (int i = 0; i < upb_MessageDef_FieldCount(m); i++) { + const upb_FieldDef* f = upb_MessageDef_Field(m, i); + upb_OneofDef* o = (upb_OneofDef*)upb_FieldDef_ContainingOneof(f); + if (o) { + o->fields[o->field_count++] = f; + } } - return upb_MtDataEncoder_Put(e, ptr, encoded_type); + return synthetic_count; } -static char* _upb_MtDataEncoder_MaybePutModifiers(upb_MtDataEncoder* e, - char* ptr, upb_FieldType type, - uint64_t field_mod) { - upb_MtDataEncoderInternal* in = (upb_MtDataEncoderInternal*)e->internal; - uint32_t encoded_modifiers = 0; - if ((field_mod & kUpb_FieldModifier_IsRepeated) && - upb_FieldType_IsPackable(type)) { - bool field_is_packed = field_mod & kUpb_FieldModifier_IsPacked; - bool default_is_packed = in->state.msg_state.msg_modifiers & - kUpb_MessageModifier_DefaultIsPacked; - if (field_is_packed != default_is_packed) { - encoded_modifiers |= kUpb_EncodedFieldModifier_FlipPacked; - } - } +static void create_oneofdef(upb_DefBuilder* ctx, upb_MessageDef* m, + const UPB_DESC(OneofDescriptorProto*) oneof_proto, + const UPB_DESC(FeatureSet*) parent_features, + const upb_OneofDef* _o) { + upb_OneofDef* o = (upb_OneofDef*)_o; - if (type == kUpb_FieldType_String) { - bool field_validates_utf8 = field_mod & kUpb_FieldModifier_ValidateUtf8; - bool message_validates_utf8 = - in->state.msg_state.msg_modifiers & kUpb_MessageModifier_ValidateUtf8; - if (field_validates_utf8 != message_validates_utf8) { - // Old binaries do not recognize the field modifier. We need the failure - // mode to be too lax rather than too strict. Our caller should have - // handled this (see _upb_MessageDef_ValidateUtf8()). - assert(!message_validates_utf8); - encoded_modifiers |= kUpb_EncodedFieldModifier_FlipValidateUtf8; - } - } + UPB_DEF_SET_OPTIONS(o->opts, OneofDescriptorProto, OneofOptions, oneof_proto); + o->resolved_features = _upb_DefBuilder_ResolveFeatures( + ctx, parent_features, UPB_DESC(OneofOptions_features)(o->opts)); - if (field_mod & kUpb_FieldModifier_IsProto3Singular) { - encoded_modifiers |= kUpb_EncodedFieldModifier_IsProto3Singular; - } + upb_StringView name = UPB_DESC(OneofDescriptorProto_name)(oneof_proto); - if (field_mod & kUpb_FieldModifier_IsRequired) { - encoded_modifiers |= kUpb_EncodedFieldModifier_IsRequired; + o->parent = m; + o->full_name = + _upb_DefBuilder_MakeFullName(ctx, upb_MessageDef_FullName(m), name); + o->field_count = 0; + o->synthetic = false; + + if (upb_MessageDef_FindByNameWithSize(m, name.data, name.size, NULL, NULL)) { + _upb_DefBuilder_Errf(ctx, "duplicate oneof name (%s)", o->full_name); } - return upb_MtDataEncoder_PutModifier(e, ptr, encoded_modifiers); + upb_value v = _upb_DefType_Pack(o, UPB_DEFTYPE_ONEOF); + bool ok = _upb_MessageDef_Insert(m, name.data, name.size, v, ctx->arena); + if (!ok) _upb_DefBuilder_OomErr(ctx); + + ok = upb_inttable_init(&o->itof, ctx->arena); + if (!ok) _upb_DefBuilder_OomErr(ctx); + + ok = upb_strtable_init(&o->ntof, 4, ctx->arena); + if (!ok) _upb_DefBuilder_OomErr(ctx); } -char* upb_MtDataEncoder_PutField(upb_MtDataEncoder* e, char* ptr, - upb_FieldType type, uint32_t field_num, - uint64_t field_mod) { - upb_MtDataEncoder_GetInternal(e, ptr); +// Allocate and initialize an array of |n| oneof defs. +upb_OneofDef* _upb_OneofDefs_New(upb_DefBuilder* ctx, int n, + const UPB_DESC(OneofDescriptorProto*) + const* protos, + const UPB_DESC(FeatureSet*) parent_features, + upb_MessageDef* m) { + _upb_DefType_CheckPadding(sizeof(upb_OneofDef)); - ptr = _upb_MtDataEncoder_MaybePutFieldSkip(e, ptr, field_num); - if (!ptr) return NULL; + upb_OneofDef* o = _upb_DefBuilder_Alloc(ctx, sizeof(upb_OneofDef) * n); + for (int i = 0; i < n; i++) { + create_oneofdef(ctx, m, protos[i], parent_features, &o[i]); + } + return o; +} - ptr = _upb_MtDataEncoder_PutFieldType(e, ptr, type, field_mod); - if (!ptr) return NULL; - return _upb_MtDataEncoder_MaybePutModifiers(e, ptr, type, field_mod); + +// Must be last. + +struct upb_ServiceDef { + const UPB_DESC(ServiceOptions*) opts; + const UPB_DESC(FeatureSet*) resolved_features; + const upb_FileDef* file; + const char* full_name; + upb_MethodDef* methods; + int method_count; + int index; +#if UINTPTR_MAX == 0xffffffff + uint32_t padding; // Increase size to a multiple of 8. +#endif +}; + +upb_ServiceDef* _upb_ServiceDef_At(const upb_ServiceDef* s, int index) { + return (upb_ServiceDef*)&s[index]; } -char* upb_MtDataEncoder_StartOneof(upb_MtDataEncoder* e, char* ptr) { - upb_MtDataEncoderInternal* in = upb_MtDataEncoder_GetInternal(e, ptr); - if (in->state.msg_state.oneof_state == kUpb_OneofState_NotStarted) { - ptr = upb_MtDataEncoder_Put(e, ptr, _upb_FromBase92(kUpb_EncodedValue_End)); - } else { - ptr = upb_MtDataEncoder_Put( - e, ptr, _upb_FromBase92(kUpb_EncodedValue_OneofSeparator)); - } - in->state.msg_state.oneof_state = kUpb_OneofState_StartedOneof; - return ptr; +const UPB_DESC(ServiceOptions) * + upb_ServiceDef_Options(const upb_ServiceDef* s) { + return s->opts; } -char* upb_MtDataEncoder_PutOneofField(upb_MtDataEncoder* e, char* ptr, - uint32_t field_num) { - upb_MtDataEncoderInternal* in = upb_MtDataEncoder_GetInternal(e, ptr); - if (in->state.msg_state.oneof_state == kUpb_OneofState_EmittedOneofField) { - ptr = upb_MtDataEncoder_Put( - e, ptr, _upb_FromBase92(kUpb_EncodedValue_FieldSeparator)); - if (!ptr) return NULL; - } - ptr = upb_MtDataEncoder_PutBase92Varint(e, ptr, field_num, _upb_ToBase92(0), - _upb_ToBase92(63)); - in->state.msg_state.oneof_state = kUpb_OneofState_EmittedOneofField; - return ptr; +bool upb_ServiceDef_HasOptions(const upb_ServiceDef* s) { + return s->opts != (void*)kUpbDefOptDefault; } -char* upb_MtDataEncoder_StartEnum(upb_MtDataEncoder* e, char* ptr) { - upb_MtDataEncoderInternal* in = upb_MtDataEncoder_GetInternal(e, ptr); - in->state.enum_state.present_values_mask = 0; - in->state.enum_state.last_written_value = 0; +const UPB_DESC(FeatureSet) * + upb_ServiceDef_ResolvedFeatures(const upb_ServiceDef* s) { + return s->resolved_features; +} - return upb_MtDataEncoder_PutRaw(e, ptr, kUpb_EncodedVersion_EnumV1); +const char* upb_ServiceDef_FullName(const upb_ServiceDef* s) { + return s->full_name; } -static char* upb_MtDataEncoder_FlushDenseEnumMask(upb_MtDataEncoder* e, - char* ptr) { - upb_MtDataEncoderInternal* in = (upb_MtDataEncoderInternal*)e->internal; - ptr = upb_MtDataEncoder_Put(e, ptr, in->state.enum_state.present_values_mask); - in->state.enum_state.present_values_mask = 0; - in->state.enum_state.last_written_value += 5; - return ptr; +const char* upb_ServiceDef_Name(const upb_ServiceDef* s) { + return _upb_DefBuilder_FullToShort(s->full_name); } -char* upb_MtDataEncoder_PutEnumValue(upb_MtDataEncoder* e, char* ptr, - uint32_t val) { - // TODO: optimize this encoding. - upb_MtDataEncoderInternal* in = upb_MtDataEncoder_GetInternal(e, ptr); - UPB_ASSERT(val >= in->state.enum_state.last_written_value); - uint32_t delta = val - in->state.enum_state.last_written_value; - if (delta >= 5 && in->state.enum_state.present_values_mask) { - ptr = upb_MtDataEncoder_FlushDenseEnumMask(e, ptr); - if (!ptr) { - return NULL; - } - delta -= 5; - } +int upb_ServiceDef_Index(const upb_ServiceDef* s) { return s->index; } - if (delta >= 5) { - ptr = upb_MtDataEncoder_PutBase92Varint( - e, ptr, delta, kUpb_EncodedValue_MinSkip, kUpb_EncodedValue_MaxSkip); - in->state.enum_state.last_written_value += delta; - delta = 0; - } +const upb_FileDef* upb_ServiceDef_File(const upb_ServiceDef* s) { + return s->file; +} - UPB_ASSERT((in->state.enum_state.present_values_mask >> delta) == 0); - in->state.enum_state.present_values_mask |= 1ULL << delta; - return ptr; +int upb_ServiceDef_MethodCount(const upb_ServiceDef* s) { + return s->method_count; } -char* upb_MtDataEncoder_EndEnum(upb_MtDataEncoder* e, char* ptr) { - upb_MtDataEncoderInternal* in = upb_MtDataEncoder_GetInternal(e, ptr); - if (!in->state.enum_state.present_values_mask) return ptr; - return upb_MtDataEncoder_FlushDenseEnumMask(e, ptr); +const upb_MethodDef* upb_ServiceDef_Method(const upb_ServiceDef* s, int i) { + return (i < 0 || i >= s->method_count) ? NULL + : _upb_MethodDef_At(s->methods, i); } +const upb_MethodDef* upb_ServiceDef_FindMethodByName(const upb_ServiceDef* s, + const char* name) { + for (int i = 0; i < s->method_count; i++) { + const upb_MethodDef* m = _upb_MethodDef_At(s->methods, i); + if (strcmp(name, upb_MethodDef_Name(m)) == 0) { + return m; + } + } + return NULL; +} -#include +static void create_service(upb_DefBuilder* ctx, + const UPB_DESC(ServiceDescriptorProto*) svc_proto, + const UPB_DESC(FeatureSet*) parent_features, + upb_ServiceDef* s) { + UPB_DEF_SET_OPTIONS(s->opts, ServiceDescriptorProto, ServiceOptions, + svc_proto); + s->resolved_features = _upb_DefBuilder_ResolveFeatures( + ctx, parent_features, UPB_DESC(ServiceOptions_features)(s->opts)); -// Must be last. + // Must happen before _upb_DefBuilder_Add() + s->file = _upb_DefBuilder_File(ctx); -// A MiniTable for an empty message, used for unlinked sub-messages. -const struct upb_MiniTable UPB_PRIVATE(_kUpb_MiniTable_Empty) = { - .UPB_PRIVATE(subs) = NULL, - .UPB_PRIVATE(fields) = NULL, - .UPB_PRIVATE(size) = 0, - .UPB_PRIVATE(field_count) = 0, - .UPB_PRIVATE(ext) = kUpb_ExtMode_NonExtendable, - .UPB_PRIVATE(dense_below) = 0, - .UPB_PRIVATE(table_mask) = -1, - .UPB_PRIVATE(required_count) = 0, -}; + upb_StringView name = UPB_DESC(ServiceDescriptorProto_name)(svc_proto); + const char* package = _upb_FileDef_RawPackage(s->file); + s->full_name = _upb_DefBuilder_MakeFullName(ctx, package, name); + _upb_DefBuilder_Add(ctx, s->full_name, + _upb_DefType_Pack(s, UPB_DEFTYPE_SERVICE)); + + size_t n; + const UPB_DESC(MethodDescriptorProto)* const* methods = + UPB_DESC(ServiceDescriptorProto_method)(svc_proto, &n); + s->method_count = n; + s->methods = _upb_MethodDefs_New(ctx, n, methods, s->resolved_features, s); +} + +upb_ServiceDef* _upb_ServiceDefs_New(upb_DefBuilder* ctx, int n, + const UPB_DESC(ServiceDescriptorProto*) + const* protos, + const UPB_DESC(FeatureSet*) + parent_features) { + _upb_DefType_CheckPadding(sizeof(upb_ServiceDef)); + + upb_ServiceDef* s = _upb_DefBuilder_Alloc(ctx, sizeof(upb_ServiceDef) * n); + for (int i = 0; i < n; i++) { + create_service(ctx, protos[i], parent_features, &s[i]); + s[i].index = i; + } + return s; +} // This should #undef all macros #defined in def.inc diff --git a/ruby/ext/google/protobuf_c/ruby-upb.h b/ruby/ext/google/protobuf_c/ruby-upb.h index e44b7b645363f..dfa9ffe1bc2b9 100755 --- a/ruby/ext/google/protobuf_c/ruby-upb.h +++ b/ruby/ext/google/protobuf_c/ruby-upb.h @@ -4684,108 +4684,6 @@ static UPB_FORCEINLINE bool upb_EpsCopyInputStream_TryParseDelimitedFast( #endif // UPB_WIRE_EPS_COPY_INPUT_STREAM_H_ -#ifndef UPB_BASE_INTERNAL_LOG2_H_ -#define UPB_BASE_INTERNAL_LOG2_H_ - -// Must be last. - -#ifdef __cplusplus -extern "C" { -#endif - -UPB_INLINE int upb_Log2Ceiling(int x) { - if (x <= 1) return 0; -#ifdef __GNUC__ - return 32 - __builtin_clz(x - 1); -#else - int lg2 = 0; - while ((1 << lg2) < x) lg2++; - return lg2; -#endif -} - -UPB_INLINE int upb_Log2CeilingSize(int x) { return 1 << upb_Log2Ceiling(x); } - -#ifdef __cplusplus -} /* extern "C" */ -#endif - - -#endif /* UPB_BASE_INTERNAL_LOG2_H_ */ - -#ifndef UPB_HASH_INT_TABLE_H_ -#define UPB_HASH_INT_TABLE_H_ - - -// Must be last. - -typedef struct { - upb_table t; // For entries that don't fit in the array part. - const upb_tabval* array; // Array part of the table. See const note above. - size_t array_size; // Array part size. - size_t array_count; // Array part number of elements. -} upb_inttable; - -#ifdef __cplusplus -extern "C" { -#endif - -// Initialize a table. If memory allocation failed, false is returned and -// the table is uninitialized. -bool upb_inttable_init(upb_inttable* table, upb_Arena* a); - -// Returns the number of values in the table. -size_t upb_inttable_count(const upb_inttable* t); - -// Inserts the given key into the hashtable with the given value. -// The key must not already exist in the hash table. -// The value must not be UINTPTR_MAX. -// -// If a table resize was required but memory allocation failed, false is -// returned and the table is unchanged. -bool upb_inttable_insert(upb_inttable* t, uintptr_t key, upb_value val, - upb_Arena* a); - -// Looks up key in this table, returning "true" if the key was found. -// If v is non-NULL, copies the value for this key into *v. -bool upb_inttable_lookup(const upb_inttable* t, uintptr_t key, upb_value* v); - -// Removes an item from the table. Returns true if the remove was successful, -// and stores the removed item in *val if non-NULL. -bool upb_inttable_remove(upb_inttable* t, uintptr_t key, upb_value* val); - -// Updates an existing entry in an inttable. -// If the entry does not exist, returns false and does nothing. -// Unlike insert/remove, this does not invalidate iterators. -bool upb_inttable_replace(upb_inttable* t, uintptr_t key, upb_value val); - -// Optimizes the table for the current set of entries, for both memory use and -// lookup time. Client should call this after all entries have been inserted; -// inserting more entries is legal, but will likely require a table resize. -void upb_inttable_compact(upb_inttable* t, upb_Arena* a); - -// Iteration over inttable: -// -// intptr_t iter = UPB_INTTABLE_BEGIN; -// uintptr_t key; -// upb_value val; -// while (upb_inttable_next(t, &key, &val, &iter)) { -// // ... -// } - -#define UPB_INTTABLE_BEGIN -1 - -bool upb_inttable_next(const upb_inttable* t, uintptr_t* key, upb_value* val, - intptr_t* iter); -void upb_inttable_removeiter(upb_inttable* t, intptr_t* iter); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - - -#endif /* UPB_HASH_INT_TABLE_H_ */ - #ifndef UPB_JSON_DECODE_H_ #define UPB_JSON_DECODE_H_ @@ -12208,24 +12106,6 @@ UPB_INLINE int _upb_vsnprintf(char* buf, size_t size, const char* fmt, #endif // UPB_PORT_VSNPRINTF_COMPAT_H_ -#ifndef UPB_LEX_STRTOD_H_ -#define UPB_LEX_STRTOD_H_ - -// Must be last. - -#ifdef __cplusplus -extern "C" { -#endif - -double _upb_NoLocaleStrtod(const char *str, char **endptr); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - - -#endif /* UPB_LEX_STRTOD_H_ */ - #ifndef UPB_PORT_ATOMIC_H_ #define UPB_PORT_ATOMIC_H_ @@ -12447,6 +12327,35 @@ bool _upb_mapsorter_pushexts(_upb_mapsorter* s, #endif /* UPB_MESSAGE_INTERNAL_MAP_SORTER_H_ */ +#ifndef UPB_BASE_INTERNAL_LOG2_H_ +#define UPB_BASE_INTERNAL_LOG2_H_ + +// Must be last. + +#ifdef __cplusplus +extern "C" { +#endif + +UPB_INLINE int upb_Log2Ceiling(int x) { + if (x <= 1) return 0; +#ifdef __GNUC__ + return 32 - __builtin_clz(x - 1); +#else + int lg2 = 0; + while ((1 << lg2) < x) lg2++; + return lg2; +#endif +} + +UPB_INLINE int upb_Log2CeilingSize(int x) { return 1 << upb_Log2Ceiling(x); } + +#ifdef __cplusplus +} /* extern "C" */ +#endif + + +#endif /* UPB_BASE_INTERNAL_LOG2_H_ */ + #ifndef UPB_MESSAGE_COMPARE_H_ #define UPB_MESSAGE_COMPARE_H_ @@ -12732,73 +12641,654 @@ upb_MiniTableEquals_Status upb_MiniTable_Equals(const upb_MiniTable* src, #endif /* UPB_MINI_TABLE_COMPAT_H_ */ -#ifndef UPB_REFLECTION_DEF_POOL_INTERNAL_H_ -#define UPB_REFLECTION_DEF_POOL_INTERNAL_H_ +#ifndef UPB_HASH_INT_TABLE_H_ +#define UPB_HASH_INT_TABLE_H_ // Must be last. +typedef struct { + upb_table t; // For entries that don't fit in the array part. + const upb_tabval* array; // Array part of the table. See const note above. + size_t array_size; // Array part size. + size_t array_count; // Array part number of elements. +} upb_inttable; + #ifdef __cplusplus extern "C" { #endif -upb_Arena* _upb_DefPool_Arena(const upb_DefPool* s); -size_t _upb_DefPool_BytesLoaded(const upb_DefPool* s); -upb_ExtensionRegistry* _upb_DefPool_ExtReg(const upb_DefPool* s); +// Initialize a table. If memory allocation failed, false is returned and +// the table is uninitialized. +bool upb_inttable_init(upb_inttable* table, upb_Arena* a); -bool _upb_DefPool_InsertExt(upb_DefPool* s, const upb_MiniTableExtension* ext, - const upb_FieldDef* f); -bool _upb_DefPool_InsertSym(upb_DefPool* s, upb_StringView sym, upb_value v, - upb_Status* status); -bool _upb_DefPool_LookupSym(const upb_DefPool* s, const char* sym, size_t size, - upb_value* v); +// Returns the number of values in the table. +size_t upb_inttable_count(const upb_inttable* t); -void** _upb_DefPool_ScratchData(const upb_DefPool* s); -size_t* _upb_DefPool_ScratchSize(const upb_DefPool* s); -void _upb_DefPool_SetPlatform(upb_DefPool* s, upb_MiniTablePlatform platform); +// Inserts the given key into the hashtable with the given value. +// The key must not already exist in the hash table. +// The value must not be UINTPTR_MAX. +// +// If a table resize was required but memory allocation failed, false is +// returned and the table is unchanged. +bool upb_inttable_insert(upb_inttable* t, uintptr_t key, upb_value val, + upb_Arena* a); -// For generated code only: loads a generated descriptor. -typedef struct _upb_DefPool_Init { - struct _upb_DefPool_Init** deps; // Dependencies of this file. - const upb_MiniTableFile* layout; - const char* filename; - upb_StringView descriptor; // Serialized descriptor. -} _upb_DefPool_Init; +// Looks up key in this table, returning "true" if the key was found. +// If v is non-NULL, copies the value for this key into *v. +bool upb_inttable_lookup(const upb_inttable* t, uintptr_t key, upb_value* v); -bool _upb_DefPool_LoadDefInit(upb_DefPool* s, const _upb_DefPool_Init* init); +// Removes an item from the table. Returns true if the remove was successful, +// and stores the removed item in *val if non-NULL. +bool upb_inttable_remove(upb_inttable* t, uintptr_t key, upb_value* val); -// Should only be directly called by tests. This variant lets us suppress -// the use of compiled-in tables, forcing a rebuild of the tables at runtime. -bool _upb_DefPool_LoadDefInitEx(upb_DefPool* s, const _upb_DefPool_Init* init, - bool rebuild_minitable); +// Updates an existing entry in an inttable. +// If the entry does not exist, returns false and does nothing. +// Unlike insert/remove, this does not invalidate iterators. +bool upb_inttable_replace(upb_inttable* t, uintptr_t key, upb_value val); + +// Optimizes the table for the current set of entries, for both memory use and +// lookup time. Client should call this after all entries have been inserted; +// inserting more entries is legal, but will likely require a table resize. +void upb_inttable_compact(upb_inttable* t, upb_Arena* a); + +// Iteration over inttable: +// +// intptr_t iter = UPB_INTTABLE_BEGIN; +// uintptr_t key; +// upb_value val; +// while (upb_inttable_next(t, &key, &val, &iter)) { +// // ... +// } + +#define UPB_INTTABLE_BEGIN -1 + +bool upb_inttable_next(const upb_inttable* t, uintptr_t* key, upb_value* val, + intptr_t* iter); +void upb_inttable_removeiter(upb_inttable* t, intptr_t* iter); #ifdef __cplusplus } /* extern "C" */ #endif -#endif /* UPB_REFLECTION_DEF_POOL_INTERNAL_H_ */ +#endif /* UPB_HASH_INT_TABLE_H_ */ -#ifndef UPB_REFLECTION_DEF_BUILDER_INTERNAL_H_ -#define UPB_REFLECTION_DEF_BUILDER_INTERNAL_H_ +#ifndef UPB_WIRE_INTERNAL_CONSTANTS_H_ +#define UPB_WIRE_INTERNAL_CONSTANTS_H_ +#define kUpb_WireFormat_DefaultDepthLimit 100 -// Must be last. +// MessageSet wire format is: +// message MessageSet { +// repeated group Item = 1 { +// required int32 type_id = 2; +// required bytes message = 3; +// } +// } -// We want to copy the options verbatim into the destination options proto. -// We use serialize+parse as our deep copy. -#define UPB_DEF_SET_OPTIONS(target, desc_type, options_type, proto) \ - if (UPB_DESC(desc_type##_has_options)(proto)) { \ - size_t size; \ - char* pb = UPB_DESC(options_type##_serialize)( \ - UPB_DESC(desc_type##_options)(proto), ctx->tmp_arena, &size); \ - if (!pb) _upb_DefBuilder_OomErr(ctx); \ - target = \ - UPB_DESC(options_type##_parse)(pb, size, _upb_DefBuilder_Arena(ctx)); \ - if (!target) _upb_DefBuilder_OomErr(ctx); \ - } else { \ - target = (const UPB_DESC(options_type)*)kUpbDefOptDefault; \ - } +enum { + kUpb_MsgSet_Item = 1, + kUpb_MsgSet_TypeId = 2, + kUpb_MsgSet_Message = 3, +}; + +#endif /* UPB_WIRE_INTERNAL_CONSTANTS_H_ */ + +/* + * Internal implementation details of the decoder that are shared between + * decode.c and decode_fast.c. + */ + +#ifndef UPB_WIRE_INTERNAL_DECODER_H_ +#define UPB_WIRE_INTERNAL_DECODER_H_ + +#include "utf8_range.h" + +// Must be last. + +#define DECODE_NOGROUP (uint32_t) - 1 + +typedef struct upb_Decoder { + upb_EpsCopyInputStream input; + const upb_ExtensionRegistry* extreg; + const char* unknown; // Start of unknown data, preserve at buffer flip + upb_Message* unknown_msg; // Pointer to preserve data to + int depth; // Tracks recursion depth to bound stack usage. + uint32_t end_group; // field number of END_GROUP tag, else DECODE_NOGROUP. + uint16_t options; + bool missing_required; + union { + upb_Arena arena; + void* foo[UPB_ARENA_SIZE_HACK]; + }; + upb_DecodeStatus status; + jmp_buf err; + +#ifndef NDEBUG + const char* debug_tagstart; + const char* debug_valstart; +#endif +} upb_Decoder; + +/* Error function that will abort decoding with longjmp(). We can't declare this + * UPB_NORETURN, even though it is appropriate, because if we do then compilers + * will "helpfully" refuse to tailcall to it + * (see: https://stackoverflow.com/a/55657013), which will defeat a major goal + * of our optimizations. That is also why we must declare it in a separate file, + * otherwise the compiler will see that it calls longjmp() and deduce that it is + * noreturn. */ +const char* _upb_FastDecoder_ErrorJmp(upb_Decoder* d, int status); + +extern const uint8_t upb_utf8_offsets[]; + +UPB_INLINE +bool _upb_Decoder_VerifyUtf8Inline(const char* ptr, int len) { + return utf8_range_IsValid(ptr, len); +} + +const char* _upb_Decoder_CheckRequired(upb_Decoder* d, const char* ptr, + const upb_Message* msg, + const upb_MiniTable* m); + +/* x86-64 pointers always have the high 16 bits matching. So we can shift + * left 8 and right 8 without loss of information. */ +UPB_INLINE intptr_t decode_totable(const upb_MiniTable* tablep) { + return ((intptr_t)tablep << 8) | tablep->UPB_PRIVATE(table_mask); +} + +UPB_INLINE const upb_MiniTable* decode_totablep(intptr_t table) { + return (const upb_MiniTable*)(table >> 8); +} + +const char* _upb_Decoder_IsDoneFallback(upb_EpsCopyInputStream* e, + const char* ptr, int overrun); + +UPB_INLINE bool _upb_Decoder_IsDone(upb_Decoder* d, const char** ptr) { + return upb_EpsCopyInputStream_IsDoneWithCallback( + &d->input, ptr, &_upb_Decoder_IsDoneFallback); +} + +UPB_INLINE const char* _upb_Decoder_BufferFlipCallback( + upb_EpsCopyInputStream* e, const char* old_end, const char* new_start) { + upb_Decoder* d = (upb_Decoder*)e; + if (!old_end) _upb_FastDecoder_ErrorJmp(d, kUpb_DecodeStatus_Malformed); + + if (d->unknown) { + if (!UPB_PRIVATE(_upb_Message_AddUnknown)( + d->unknown_msg, d->unknown, old_end - d->unknown, &d->arena)) { + _upb_FastDecoder_ErrorJmp(d, kUpb_DecodeStatus_OutOfMemory); + } + d->unknown = new_start; + } + return new_start; +} + +#if UPB_FASTTABLE +UPB_INLINE +const char* _upb_FastDecoder_TagDispatch(upb_Decoder* d, const char* ptr, + upb_Message* msg, intptr_t table, + uint64_t hasbits, uint64_t tag) { + const upb_MiniTable* table_p = decode_totablep(table); + uint8_t mask = table; + uint64_t data; + size_t idx = tag & mask; + UPB_ASSUME((idx & 7) == 0); + idx >>= 3; + data = table_p->UPB_PRIVATE(fasttable)[idx].field_data ^ tag; + UPB_MUSTTAIL return table_p->UPB_PRIVATE(fasttable)[idx].field_parser( + d, ptr, msg, table, hasbits, data); +} +#endif + +UPB_INLINE uint32_t _upb_FastDecoder_LoadTag(const char* ptr) { + uint16_t tag; + memcpy(&tag, ptr, 2); + return tag; +} + + +#endif /* UPB_WIRE_INTERNAL_DECODER_H_ */ + +#ifndef UPB_WIRE_INTERNAL_ENDIAN_H_ +#define UPB_WIRE_INTERNAL_ENDIAN_H_ + +#include + +// Must be last. + +#ifdef __cplusplus +extern "C" { +#endif + +UPB_INLINE bool UPB_PRIVATE(_upb_IsLittleEndian)(void) { + const int x = 1; + return *(char*)&x == 1; +} + +UPB_INLINE uint32_t UPB_PRIVATE(_upb_BigEndian32)(uint32_t val) { + if (UPB_PRIVATE(_upb_IsLittleEndian)()) return val; + + return ((val & 0xff) << 24) | ((val & 0xff00) << 8) | + ((val & 0xff0000) >> 8) | ((val & 0xff000000) >> 24); +} + +UPB_INLINE uint64_t UPB_PRIVATE(_upb_BigEndian64)(uint64_t val) { + if (UPB_PRIVATE(_upb_IsLittleEndian)()) return val; + + return ((uint64_t)UPB_PRIVATE(_upb_BigEndian32)((uint32_t)val) << 32) | + UPB_PRIVATE(_upb_BigEndian32)((uint32_t)(val >> 32)); +} + +#ifdef __cplusplus +} /* extern "C" */ +#endif + + +#endif /* UPB_WIRE_INTERNAL_ENDIAN_H_ */ + +#ifndef UPB_WIRE_READER_H_ +#define UPB_WIRE_READER_H_ + + +#ifndef UPB_WIRE_INTERNAL_READER_H_ +#define UPB_WIRE_INTERNAL_READER_H_ + +// Must be last. + +#define kUpb_WireReader_WireTypeBits 3 +#define kUpb_WireReader_WireTypeMask 7 + +typedef struct { + const char* ptr; + uint64_t val; +} UPB_PRIVATE(_upb_WireReader_LongVarint); + +#ifdef __cplusplus +extern "C" { +#endif + +UPB_PRIVATE(_upb_WireReader_LongVarint) +UPB_PRIVATE(_upb_WireReader_ReadLongVarint)(const char* ptr, uint64_t val); + +static UPB_FORCEINLINE const char* UPB_PRIVATE(_upb_WireReader_ReadVarint)( + const char* ptr, uint64_t* val, int maxlen, uint64_t maxval) { + uint64_t byte = (uint8_t)*ptr; + if (UPB_LIKELY((byte & 0x80) == 0)) { + *val = (uint32_t)byte; + return ptr + 1; + } + const char* start = ptr; + UPB_PRIVATE(_upb_WireReader_LongVarint) + res = UPB_PRIVATE(_upb_WireReader_ReadLongVarint)(ptr, byte); + if (!res.ptr || (maxlen < 10 && res.ptr - start > maxlen) || + res.val > maxval) { + return NULL; // Malformed. + } + *val = res.val; + return res.ptr; +} + +UPB_INLINE uint32_t UPB_PRIVATE(_upb_WireReader_GetFieldNumber)(uint32_t tag) { + return tag >> kUpb_WireReader_WireTypeBits; +} + +UPB_INLINE uint8_t UPB_PRIVATE(_upb_WireReader_GetWireType)(uint32_t tag) { + return tag & kUpb_WireReader_WireTypeMask; +} + +#ifdef __cplusplus +} /* extern "C" */ +#endif + + +#endif // UPB_WIRE_INTERNAL_READER_H_ + +#ifndef UPB_WIRE_TYPES_H_ +#define UPB_WIRE_TYPES_H_ + +// A list of types as they are encoded on the wire. +typedef enum { + kUpb_WireType_Varint = 0, + kUpb_WireType_64Bit = 1, + kUpb_WireType_Delimited = 2, + kUpb_WireType_StartGroup = 3, + kUpb_WireType_EndGroup = 4, + kUpb_WireType_32Bit = 5 +} upb_WireType; + +#endif /* UPB_WIRE_TYPES_H_ */ + +// Must be last. + +// The upb_WireReader interface is suitable for general-purpose parsing of +// protobuf binary wire format. It is designed to be used along with +// upb_EpsCopyInputStream for buffering, and all parsing routines in this file +// assume that at least kUpb_EpsCopyInputStream_SlopBytes worth of data is +// available to read without any bounds checks. + +#ifdef __cplusplus +extern "C" { +#endif + +// Parses a tag into `tag`, and returns a pointer past the end of the tag, or +// NULL if there was an error in the tag data. +// +// REQUIRES: there must be at least 10 bytes of data available at `ptr`. +// Bounds checks must be performed before calling this function, preferably +// by calling upb_EpsCopyInputStream_IsDone(). +static UPB_FORCEINLINE const char* upb_WireReader_ReadTag(const char* ptr, + uint32_t* tag) { + uint64_t val; + ptr = UPB_PRIVATE(_upb_WireReader_ReadVarint)(ptr, &val, 5, UINT32_MAX); + if (!ptr) return NULL; + *tag = val; + return ptr; +} + +// Given a tag, returns the field number. +UPB_INLINE uint32_t upb_WireReader_GetFieldNumber(uint32_t tag) { + return UPB_PRIVATE(_upb_WireReader_GetFieldNumber)(tag); +} + +// Given a tag, returns the wire type. +UPB_INLINE uint8_t upb_WireReader_GetWireType(uint32_t tag) { + return UPB_PRIVATE(_upb_WireReader_GetWireType)(tag); +} + +UPB_INLINE const char* upb_WireReader_ReadVarint(const char* ptr, + uint64_t* val) { + return UPB_PRIVATE(_upb_WireReader_ReadVarint)(ptr, val, 10, UINT64_MAX); +} + +// Skips data for a varint, returning a pointer past the end of the varint, or +// NULL if there was an error in the varint data. +// +// REQUIRES: there must be at least 10 bytes of data available at `ptr`. +// Bounds checks must be performed before calling this function, preferably +// by calling upb_EpsCopyInputStream_IsDone(). +UPB_INLINE const char* upb_WireReader_SkipVarint(const char* ptr) { + uint64_t val; + return upb_WireReader_ReadVarint(ptr, &val); +} + +// Reads a varint indicating the size of a delimited field into `size`, or +// NULL if there was an error in the varint data. +// +// REQUIRES: there must be at least 10 bytes of data available at `ptr`. +// Bounds checks must be performed before calling this function, preferably +// by calling upb_EpsCopyInputStream_IsDone(). +UPB_INLINE const char* upb_WireReader_ReadSize(const char* ptr, int* size) { + uint64_t size64; + ptr = upb_WireReader_ReadVarint(ptr, &size64); + if (!ptr || size64 >= INT32_MAX) return NULL; + *size = size64; + return ptr; +} + +// Reads a fixed32 field, performing byte swapping if necessary. +// +// REQUIRES: there must be at least 4 bytes of data available at `ptr`. +// Bounds checks must be performed before calling this function, preferably +// by calling upb_EpsCopyInputStream_IsDone(). +UPB_INLINE const char* upb_WireReader_ReadFixed32(const char* ptr, void* val) { + uint32_t uval; + memcpy(&uval, ptr, 4); + uval = UPB_PRIVATE(_upb_BigEndian32)(uval); + memcpy(val, &uval, 4); + return ptr + 4; +} + +// Reads a fixed64 field, performing byte swapping if necessary. +// +// REQUIRES: there must be at least 4 bytes of data available at `ptr`. +// Bounds checks must be performed before calling this function, preferably +// by calling upb_EpsCopyInputStream_IsDone(). +UPB_INLINE const char* upb_WireReader_ReadFixed64(const char* ptr, void* val) { + uint64_t uval; + memcpy(&uval, ptr, 8); + uval = UPB_PRIVATE(_upb_BigEndian64)(uval); + memcpy(val, &uval, 8); + return ptr + 8; +} + +const char* UPB_PRIVATE(_upb_WireReader_SkipGroup)( + const char* ptr, uint32_t tag, int depth_limit, + upb_EpsCopyInputStream* stream); + +// Skips data for a group, returning a pointer past the end of the group, or +// NULL if there was an error parsing the group. The `tag` argument should be +// the start group tag that begins the group. The `depth_limit` argument +// indicates how many levels of recursion the group is allowed to have before +// reporting a parse error (this limit exists to protect against stack +// overflow). +// +// TODO: evaluate how the depth_limit should be specified. Do users need +// control over this? +UPB_INLINE const char* upb_WireReader_SkipGroup( + const char* ptr, uint32_t tag, upb_EpsCopyInputStream* stream) { + return UPB_PRIVATE(_upb_WireReader_SkipGroup)(ptr, tag, 100, stream); +} + +UPB_INLINE const char* _upb_WireReader_SkipValue( + const char* ptr, uint32_t tag, int depth_limit, + upb_EpsCopyInputStream* stream) { + switch (upb_WireReader_GetWireType(tag)) { + case kUpb_WireType_Varint: + return upb_WireReader_SkipVarint(ptr); + case kUpb_WireType_32Bit: + return ptr + 4; + case kUpb_WireType_64Bit: + return ptr + 8; + case kUpb_WireType_Delimited: { + int size; + ptr = upb_WireReader_ReadSize(ptr, &size); + if (!ptr) return NULL; + ptr += size; + return ptr; + } + case kUpb_WireType_StartGroup: + return UPB_PRIVATE(_upb_WireReader_SkipGroup)(ptr, tag, depth_limit, + stream); + case kUpb_WireType_EndGroup: + return NULL; // Should be handled before now. + default: + return NULL; // Unknown wire type. + } +} + +// Skips data for a wire value of any type, returning a pointer past the end of +// the data, or NULL if there was an error parsing the group. The `tag` argument +// should be the tag that was just parsed. The `depth_limit` argument indicates +// how many levels of recursion a group is allowed to have before reporting a +// parse error (this limit exists to protect against stack overflow). +// +// REQUIRES: there must be at least 10 bytes of data available at `ptr`. +// Bounds checks must be performed before calling this function, preferably +// by calling upb_EpsCopyInputStream_IsDone(). +// +// TODO: evaluate how the depth_limit should be specified. Do users need +// control over this? +UPB_INLINE const char* upb_WireReader_SkipValue( + const char* ptr, uint32_t tag, upb_EpsCopyInputStream* stream) { + return _upb_WireReader_SkipValue(ptr, tag, 100, stream); +} + +#ifdef __cplusplus +} /* extern "C" */ +#endif + + +#endif // UPB_WIRE_READER_H_ + +#ifndef UPB_LEX_STRTOD_H_ +#define UPB_LEX_STRTOD_H_ + +// Must be last. + +#ifdef __cplusplus +extern "C" { +#endif + +double _upb_NoLocaleStrtod(const char *str, char **endptr); + +#ifdef __cplusplus +} /* extern "C" */ +#endif + + +#endif /* UPB_LEX_STRTOD_H_ */ + +#ifndef UPB_MINI_DESCRIPTOR_INTERNAL_ENCODE_H_ +#define UPB_MINI_DESCRIPTOR_INTERNAL_ENCODE_H_ + +#include + + +// Must be last. + +// If the input buffer has at least this many bytes available, the encoder call +// is guaranteed to succeed (as long as field number order is maintained). +#define kUpb_MtDataEncoder_MinSize 16 + +typedef struct { + char* end; // Limit of the buffer passed as a parameter. + // Aliased to internal-only members in .cc. + char internal[32]; +} upb_MtDataEncoder; + +#ifdef __cplusplus +extern "C" { +#endif + +// Encodes field/oneof information for a given message. The sequence of calls +// should look like: +// +// upb_MtDataEncoder e; +// char buf[256]; +// char* ptr = buf; +// e.end = ptr + sizeof(buf); +// unit64_t msg_mod = ...; // bitwise & of kUpb_MessageModifiers or zero +// ptr = upb_MtDataEncoder_StartMessage(&e, ptr, msg_mod); +// // Fields *must* be in field number order. +// ptr = upb_MtDataEncoder_PutField(&e, ptr, ...); +// ptr = upb_MtDataEncoder_PutField(&e, ptr, ...); +// ptr = upb_MtDataEncoder_PutField(&e, ptr, ...); +// +// // If oneofs are present. Oneofs must be encoded after regular fields. +// ptr = upb_MiniTable_StartOneof(&e, ptr) +// ptr = upb_MiniTable_PutOneofField(&e, ptr, ...); +// ptr = upb_MiniTable_PutOneofField(&e, ptr, ...); +// +// ptr = upb_MiniTable_StartOneof(&e, ptr); +// ptr = upb_MiniTable_PutOneofField(&e, ptr, ...); +// ptr = upb_MiniTable_PutOneofField(&e, ptr, ...); +// +// Oneofs must be encoded after all regular fields. +char* upb_MtDataEncoder_StartMessage(upb_MtDataEncoder* e, char* ptr, + uint64_t msg_mod); +char* upb_MtDataEncoder_PutField(upb_MtDataEncoder* e, char* ptr, + upb_FieldType type, uint32_t field_num, + uint64_t field_mod); +char* upb_MtDataEncoder_StartOneof(upb_MtDataEncoder* e, char* ptr); +char* upb_MtDataEncoder_PutOneofField(upb_MtDataEncoder* e, char* ptr, + uint32_t field_num); + +// Encodes the set of values for a given enum. The values must be given in +// order (after casting to uint32_t), and repeats are not allowed. +char* upb_MtDataEncoder_StartEnum(upb_MtDataEncoder* e, char* ptr); +char* upb_MtDataEncoder_PutEnumValue(upb_MtDataEncoder* e, char* ptr, + uint32_t val); +char* upb_MtDataEncoder_EndEnum(upb_MtDataEncoder* e, char* ptr); + +// Encodes an entire mini descriptor for an extension. +char* upb_MtDataEncoder_EncodeExtension(upb_MtDataEncoder* e, char* ptr, + upb_FieldType type, uint32_t field_num, + uint64_t field_mod); + +// Encodes an entire mini descriptor for a map. +char* upb_MtDataEncoder_EncodeMap(upb_MtDataEncoder* e, char* ptr, + upb_FieldType key_type, + upb_FieldType value_type, uint64_t key_mod, + uint64_t value_mod); + +// Encodes an entire mini descriptor for a message set. +char* upb_MtDataEncoder_EncodeMessageSet(upb_MtDataEncoder* e, char* ptr); + +#ifdef __cplusplus +} /* extern "C" */ +#endif + + +#endif /* UPB_MINI_DESCRIPTOR_INTERNAL_ENCODE_H_ */ + +#ifndef UPB_REFLECTION_DEF_POOL_INTERNAL_H_ +#define UPB_REFLECTION_DEF_POOL_INTERNAL_H_ + + +// Must be last. + +#ifdef __cplusplus +extern "C" { +#endif + +upb_Arena* _upb_DefPool_Arena(const upb_DefPool* s); +size_t _upb_DefPool_BytesLoaded(const upb_DefPool* s); +upb_ExtensionRegistry* _upb_DefPool_ExtReg(const upb_DefPool* s); + +bool _upb_DefPool_InsertExt(upb_DefPool* s, const upb_MiniTableExtension* ext, + const upb_FieldDef* f); +bool _upb_DefPool_InsertSym(upb_DefPool* s, upb_StringView sym, upb_value v, + upb_Status* status); +bool _upb_DefPool_LookupSym(const upb_DefPool* s, const char* sym, size_t size, + upb_value* v); + +void** _upb_DefPool_ScratchData(const upb_DefPool* s); +size_t* _upb_DefPool_ScratchSize(const upb_DefPool* s); +void _upb_DefPool_SetPlatform(upb_DefPool* s, upb_MiniTablePlatform platform); + +// For generated code only: loads a generated descriptor. +typedef struct _upb_DefPool_Init { + struct _upb_DefPool_Init** deps; // Dependencies of this file. + const upb_MiniTableFile* layout; + const char* filename; + upb_StringView descriptor; // Serialized descriptor. +} _upb_DefPool_Init; + +bool _upb_DefPool_LoadDefInit(upb_DefPool* s, const _upb_DefPool_Init* init); + +// Should only be directly called by tests. This variant lets us suppress +// the use of compiled-in tables, forcing a rebuild of the tables at runtime. +bool _upb_DefPool_LoadDefInitEx(upb_DefPool* s, const _upb_DefPool_Init* init, + bool rebuild_minitable); + +#ifdef __cplusplus +} /* extern "C" */ +#endif + + +#endif /* UPB_REFLECTION_DEF_POOL_INTERNAL_H_ */ + +#ifndef UPB_REFLECTION_DEF_BUILDER_INTERNAL_H_ +#define UPB_REFLECTION_DEF_BUILDER_INTERNAL_H_ + + +// Must be last. + +// We want to copy the options verbatim into the destination options proto. +// We use serialize+parse as our deep copy. +#define UPB_DEF_SET_OPTIONS(target, desc_type, options_type, proto) \ + if (UPB_DESC(desc_type##_has_options)(proto)) { \ + size_t size; \ + char* pb = UPB_DESC(options_type##_serialize)( \ + UPB_DESC(desc_type##_options)(proto), ctx->tmp_arena, &size); \ + if (!pb) _upb_DefBuilder_OomErr(ctx); \ + target = \ + UPB_DESC(options_type##_parse)(pb, size, _upb_DefBuilder_Arena(ctx)); \ + if (!target) _upb_DefBuilder_OomErr(ctx); \ + } else { \ + target = (const UPB_DESC(options_type)*)kUpbDefOptDefault; \ + } #ifdef __cplusplus extern "C" { @@ -13129,103 +13619,20 @@ upb_ServiceDef* _upb_ServiceDefs_New(upb_DefBuilder* ctx, int n, #ifndef UPB_REFLECTION_UPB_EDITION_DEFAULTS_H_ #define UPB_REFLECTION_UPB_EDITION_DEFAULTS_H_ -// This file contains the serialized FeatureSetDefaults object for -// language-independent features and (possibly at some point) for upb-specific -// features. This is used for feature resolution under Editions. -// NOLINTBEGIN -// clang-format off -#define UPB_INTERNAL_UPB_EDITION_DEFAULTS "\n\021\022\014\010\001\020\002\030\002 \003(\0010\002\030\346\007\n\021\022\014\010\002\020\001\030\001 \002(\0010\001\030\347\007\n\021\022\014\010\001\020\001\030\001 \002(\0010\001\030\350\007 \346\007(\350\007" -// clang-format on -// NOLINTEND - -#endif // UPB_REFLECTION_UPB_EDITION_DEFAULTS_H_ - -#ifndef UPB_REFLECTION_DESC_STATE_INTERNAL_H_ -#define UPB_REFLECTION_DESC_STATE_INTERNAL_H_ - - -#ifndef UPB_MINI_DESCRIPTOR_INTERNAL_ENCODE_H_ -#define UPB_MINI_DESCRIPTOR_INTERNAL_ENCODE_H_ - -#include - - -// Must be last. - -// If the input buffer has at least this many bytes available, the encoder call -// is guaranteed to succeed (as long as field number order is maintained). -#define kUpb_MtDataEncoder_MinSize 16 - -typedef struct { - char* end; // Limit of the buffer passed as a parameter. - // Aliased to internal-only members in .cc. - char internal[32]; -} upb_MtDataEncoder; - -#ifdef __cplusplus -extern "C" { -#endif - -// Encodes field/oneof information for a given message. The sequence of calls -// should look like: -// -// upb_MtDataEncoder e; -// char buf[256]; -// char* ptr = buf; -// e.end = ptr + sizeof(buf); -// unit64_t msg_mod = ...; // bitwise & of kUpb_MessageModifiers or zero -// ptr = upb_MtDataEncoder_StartMessage(&e, ptr, msg_mod); -// // Fields *must* be in field number order. -// ptr = upb_MtDataEncoder_PutField(&e, ptr, ...); -// ptr = upb_MtDataEncoder_PutField(&e, ptr, ...); -// ptr = upb_MtDataEncoder_PutField(&e, ptr, ...); -// -// // If oneofs are present. Oneofs must be encoded after regular fields. -// ptr = upb_MiniTable_StartOneof(&e, ptr) -// ptr = upb_MiniTable_PutOneofField(&e, ptr, ...); -// ptr = upb_MiniTable_PutOneofField(&e, ptr, ...); -// -// ptr = upb_MiniTable_StartOneof(&e, ptr); -// ptr = upb_MiniTable_PutOneofField(&e, ptr, ...); -// ptr = upb_MiniTable_PutOneofField(&e, ptr, ...); -// -// Oneofs must be encoded after all regular fields. -char* upb_MtDataEncoder_StartMessage(upb_MtDataEncoder* e, char* ptr, - uint64_t msg_mod); -char* upb_MtDataEncoder_PutField(upb_MtDataEncoder* e, char* ptr, - upb_FieldType type, uint32_t field_num, - uint64_t field_mod); -char* upb_MtDataEncoder_StartOneof(upb_MtDataEncoder* e, char* ptr); -char* upb_MtDataEncoder_PutOneofField(upb_MtDataEncoder* e, char* ptr, - uint32_t field_num); - -// Encodes the set of values for a given enum. The values must be given in -// order (after casting to uint32_t), and repeats are not allowed. -char* upb_MtDataEncoder_StartEnum(upb_MtDataEncoder* e, char* ptr); -char* upb_MtDataEncoder_PutEnumValue(upb_MtDataEncoder* e, char* ptr, - uint32_t val); -char* upb_MtDataEncoder_EndEnum(upb_MtDataEncoder* e, char* ptr); - -// Encodes an entire mini descriptor for an extension. -char* upb_MtDataEncoder_EncodeExtension(upb_MtDataEncoder* e, char* ptr, - upb_FieldType type, uint32_t field_num, - uint64_t field_mod); - -// Encodes an entire mini descriptor for a map. -char* upb_MtDataEncoder_EncodeMap(upb_MtDataEncoder* e, char* ptr, - upb_FieldType key_type, - upb_FieldType value_type, uint64_t key_mod, - uint64_t value_mod); - -// Encodes an entire mini descriptor for a message set. -char* upb_MtDataEncoder_EncodeMessageSet(upb_MtDataEncoder* e, char* ptr); +// This file contains the serialized FeatureSetDefaults object for +// language-independent features and (possibly at some point) for upb-specific +// features. This is used for feature resolution under Editions. +// NOLINTBEGIN +// clang-format off +#define UPB_INTERNAL_UPB_EDITION_DEFAULTS "\n\021\022\014\010\001\020\002\030\002 \003(\0010\002\030\346\007\n\021\022\014\010\002\020\001\030\001 \002(\0010\001\030\347\007\n\021\022\014\010\001\020\001\030\001 \002(\0010\001\030\350\007 \346\007(\350\007" +// clang-format on +// NOLINTEND -#ifdef __cplusplus -} /* extern "C" */ -#endif +#endif // UPB_REFLECTION_UPB_EDITION_DEFAULTS_H_ +#ifndef UPB_REFLECTION_DESC_STATE_INTERNAL_H_ +#define UPB_REFLECTION_DESC_STATE_INTERNAL_H_ -#endif /* UPB_MINI_DESCRIPTOR_INTERNAL_ENCODE_H_ */ // Must be last. @@ -13363,506 +13770,99 @@ upb_ExtensionRange* _upb_ExtensionRanges_New( extern "C" { #endif -upb_OneofDef* _upb_OneofDef_At(const upb_OneofDef* o, int i); -void _upb_OneofDef_Insert(upb_DefBuilder* ctx, upb_OneofDef* o, - const upb_FieldDef* f, const char* name, size_t size); - -// Allocate and initialize an array of |n| oneof defs owned by |m|. -upb_OneofDef* _upb_OneofDefs_New(upb_DefBuilder* ctx, int n, - const UPB_DESC(OneofDescriptorProto*) - const* protos, - const UPB_DESC(FeatureSet*) parent_features, - upb_MessageDef* m); - -size_t _upb_OneofDefs_Finalize(upb_DefBuilder* ctx, upb_MessageDef* m); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - - -#endif /* UPB_REFLECTION_ONEOF_DEF_INTERNAL_H_ */ - -#ifndef UPB_REFLECTION_MESSAGE_RESERVED_RANGE_INTERNAL_H_ -#define UPB_REFLECTION_MESSAGE_RESERVED_RANGE_INTERNAL_H_ - - -// IWYU pragma: private, include "upb/reflection/def.h" - -#ifndef UPB_REFLECTION_MESSAGE_RESERVED_RANGE_H_ -#define UPB_REFLECTION_MESSAGE_RESERVED_RANGE_H_ - - -// Must be last. - -#ifdef __cplusplus -extern "C" { -#endif - -int32_t upb_MessageReservedRange_Start(const upb_MessageReservedRange* r); -int32_t upb_MessageReservedRange_End(const upb_MessageReservedRange* r); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - - -#endif /* UPB_REFLECTION_MESSAGE_RESERVED_RANGE_H_ */ - -// Must be last. - -#ifdef __cplusplus -extern "C" { -#endif - -upb_MessageReservedRange* _upb_MessageReservedRange_At( - const upb_MessageReservedRange* r, int i); - -// Allocate and initialize an array of |n| reserved ranges owned by |m|. -upb_MessageReservedRange* _upb_MessageReservedRanges_New( - upb_DefBuilder* ctx, int n, - const UPB_DESC(DescriptorProto_ReservedRange) * const* protos, - const upb_MessageDef* m); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - - -#endif /* UPB_REFLECTION_MESSAGE_RESERVED_RANGE_INTERNAL_H_ */ - -#ifndef UPB_REFLECTION_METHOD_DEF_INTERNAL_H_ -#define UPB_REFLECTION_METHOD_DEF_INTERNAL_H_ - - -// Must be last. - -#ifdef __cplusplus -extern "C" { -#endif - -upb_MethodDef* _upb_MethodDef_At(const upb_MethodDef* m, int i); - -// Allocate and initialize an array of |n| method defs owned by |s|. -upb_MethodDef* _upb_MethodDefs_New(upb_DefBuilder* ctx, int n, - const UPB_DESC(MethodDescriptorProto*) - const* protos, - const UPB_DESC(FeatureSet*) parent_features, - upb_ServiceDef* s); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - - -#endif /* UPB_REFLECTION_METHOD_DEF_INTERNAL_H_ */ - -#ifndef UPB_WIRE_INTERNAL_CONSTANTS_H_ -#define UPB_WIRE_INTERNAL_CONSTANTS_H_ - -#define kUpb_WireFormat_DefaultDepthLimit 100 - -// MessageSet wire format is: -// message MessageSet { -// repeated group Item = 1 { -// required int32 type_id = 2; -// required bytes message = 3; -// } -// } - -enum { - kUpb_MsgSet_Item = 1, - kUpb_MsgSet_TypeId = 2, - kUpb_MsgSet_Message = 3, -}; - -#endif /* UPB_WIRE_INTERNAL_CONSTANTS_H_ */ - -/* - * Internal implementation details of the decoder that are shared between - * decode.c and decode_fast.c. - */ - -#ifndef UPB_WIRE_INTERNAL_DECODER_H_ -#define UPB_WIRE_INTERNAL_DECODER_H_ - -#include "utf8_range.h" - -// Must be last. - -#define DECODE_NOGROUP (uint32_t) - 1 - -typedef struct upb_Decoder { - upb_EpsCopyInputStream input; - const upb_ExtensionRegistry* extreg; - const char* unknown; // Start of unknown data, preserve at buffer flip - upb_Message* unknown_msg; // Pointer to preserve data to - int depth; // Tracks recursion depth to bound stack usage. - uint32_t end_group; // field number of END_GROUP tag, else DECODE_NOGROUP. - uint16_t options; - bool missing_required; - union { - upb_Arena arena; - void* foo[UPB_ARENA_SIZE_HACK]; - }; - upb_DecodeStatus status; - jmp_buf err; - -#ifndef NDEBUG - const char* debug_tagstart; - const char* debug_valstart; -#endif -} upb_Decoder; - -/* Error function that will abort decoding with longjmp(). We can't declare this - * UPB_NORETURN, even though it is appropriate, because if we do then compilers - * will "helpfully" refuse to tailcall to it - * (see: https://stackoverflow.com/a/55657013), which will defeat a major goal - * of our optimizations. That is also why we must declare it in a separate file, - * otherwise the compiler will see that it calls longjmp() and deduce that it is - * noreturn. */ -const char* _upb_FastDecoder_ErrorJmp(upb_Decoder* d, int status); - -extern const uint8_t upb_utf8_offsets[]; - -UPB_INLINE -bool _upb_Decoder_VerifyUtf8Inline(const char* ptr, int len) { - return utf8_range_IsValid(ptr, len); -} - -const char* _upb_Decoder_CheckRequired(upb_Decoder* d, const char* ptr, - const upb_Message* msg, - const upb_MiniTable* m); - -/* x86-64 pointers always have the high 16 bits matching. So we can shift - * left 8 and right 8 without loss of information. */ -UPB_INLINE intptr_t decode_totable(const upb_MiniTable* tablep) { - return ((intptr_t)tablep << 8) | tablep->UPB_PRIVATE(table_mask); -} - -UPB_INLINE const upb_MiniTable* decode_totablep(intptr_t table) { - return (const upb_MiniTable*)(table >> 8); -} - -const char* _upb_Decoder_IsDoneFallback(upb_EpsCopyInputStream* e, - const char* ptr, int overrun); - -UPB_INLINE bool _upb_Decoder_IsDone(upb_Decoder* d, const char** ptr) { - return upb_EpsCopyInputStream_IsDoneWithCallback( - &d->input, ptr, &_upb_Decoder_IsDoneFallback); -} - -UPB_INLINE const char* _upb_Decoder_BufferFlipCallback( - upb_EpsCopyInputStream* e, const char* old_end, const char* new_start) { - upb_Decoder* d = (upb_Decoder*)e; - if (!old_end) _upb_FastDecoder_ErrorJmp(d, kUpb_DecodeStatus_Malformed); - - if (d->unknown) { - if (!UPB_PRIVATE(_upb_Message_AddUnknown)( - d->unknown_msg, d->unknown, old_end - d->unknown, &d->arena)) { - _upb_FastDecoder_ErrorJmp(d, kUpb_DecodeStatus_OutOfMemory); - } - d->unknown = new_start; - } - return new_start; -} - -#if UPB_FASTTABLE -UPB_INLINE -const char* _upb_FastDecoder_TagDispatch(upb_Decoder* d, const char* ptr, - upb_Message* msg, intptr_t table, - uint64_t hasbits, uint64_t tag) { - const upb_MiniTable* table_p = decode_totablep(table); - uint8_t mask = table; - uint64_t data; - size_t idx = tag & mask; - UPB_ASSUME((idx & 7) == 0); - idx >>= 3; - data = table_p->UPB_PRIVATE(fasttable)[idx].field_data ^ tag; - UPB_MUSTTAIL return table_p->UPB_PRIVATE(fasttable)[idx].field_parser( - d, ptr, msg, table, hasbits, data); -} -#endif - -UPB_INLINE uint32_t _upb_FastDecoder_LoadTag(const char* ptr) { - uint16_t tag; - memcpy(&tag, ptr, 2); - return tag; -} - - -#endif /* UPB_WIRE_INTERNAL_DECODER_H_ */ - -#ifndef UPB_WIRE_INTERNAL_ENDIAN_H_ -#define UPB_WIRE_INTERNAL_ENDIAN_H_ - -#include - -// Must be last. - -#ifdef __cplusplus -extern "C" { -#endif - -UPB_INLINE bool UPB_PRIVATE(_upb_IsLittleEndian)(void) { - const int x = 1; - return *(char*)&x == 1; -} - -UPB_INLINE uint32_t UPB_PRIVATE(_upb_BigEndian32)(uint32_t val) { - if (UPB_PRIVATE(_upb_IsLittleEndian)()) return val; - - return ((val & 0xff) << 24) | ((val & 0xff00) << 8) | - ((val & 0xff0000) >> 8) | ((val & 0xff000000) >> 24); -} +upb_OneofDef* _upb_OneofDef_At(const upb_OneofDef* o, int i); +void _upb_OneofDef_Insert(upb_DefBuilder* ctx, upb_OneofDef* o, + const upb_FieldDef* f, const char* name, size_t size); -UPB_INLINE uint64_t UPB_PRIVATE(_upb_BigEndian64)(uint64_t val) { - if (UPB_PRIVATE(_upb_IsLittleEndian)()) return val; +// Allocate and initialize an array of |n| oneof defs owned by |m|. +upb_OneofDef* _upb_OneofDefs_New(upb_DefBuilder* ctx, int n, + const UPB_DESC(OneofDescriptorProto*) + const* protos, + const UPB_DESC(FeatureSet*) parent_features, + upb_MessageDef* m); - return ((uint64_t)UPB_PRIVATE(_upb_BigEndian32)((uint32_t)val) << 32) | - UPB_PRIVATE(_upb_BigEndian32)((uint32_t)(val >> 32)); -} +size_t _upb_OneofDefs_Finalize(upb_DefBuilder* ctx, upb_MessageDef* m); #ifdef __cplusplus } /* extern "C" */ #endif -#endif /* UPB_WIRE_INTERNAL_ENDIAN_H_ */ +#endif /* UPB_REFLECTION_ONEOF_DEF_INTERNAL_H_ */ -#ifndef UPB_WIRE_READER_H_ -#define UPB_WIRE_READER_H_ +#ifndef UPB_REFLECTION_MESSAGE_RESERVED_RANGE_INTERNAL_H_ +#define UPB_REFLECTION_MESSAGE_RESERVED_RANGE_INTERNAL_H_ -#ifndef UPB_WIRE_INTERNAL_READER_H_ -#define UPB_WIRE_INTERNAL_READER_H_ +// IWYU pragma: private, include "upb/reflection/def.h" -// Must be last. +#ifndef UPB_REFLECTION_MESSAGE_RESERVED_RANGE_H_ +#define UPB_REFLECTION_MESSAGE_RESERVED_RANGE_H_ -#define kUpb_WireReader_WireTypeBits 3 -#define kUpb_WireReader_WireTypeMask 7 -typedef struct { - const char* ptr; - uint64_t val; -} UPB_PRIVATE(_upb_WireReader_LongVarint); +// Must be last. #ifdef __cplusplus extern "C" { #endif -UPB_PRIVATE(_upb_WireReader_LongVarint) -UPB_PRIVATE(_upb_WireReader_ReadLongVarint)(const char* ptr, uint64_t val); - -static UPB_FORCEINLINE const char* UPB_PRIVATE(_upb_WireReader_ReadVarint)( - const char* ptr, uint64_t* val, int maxlen, uint64_t maxval) { - uint64_t byte = (uint8_t)*ptr; - if (UPB_LIKELY((byte & 0x80) == 0)) { - *val = (uint32_t)byte; - return ptr + 1; - } - const char* start = ptr; - UPB_PRIVATE(_upb_WireReader_LongVarint) - res = UPB_PRIVATE(_upb_WireReader_ReadLongVarint)(ptr, byte); - if (!res.ptr || (maxlen < 10 && res.ptr - start > maxlen) || - res.val > maxval) { - return NULL; // Malformed. - } - *val = res.val; - return res.ptr; -} - -UPB_INLINE uint32_t UPB_PRIVATE(_upb_WireReader_GetFieldNumber)(uint32_t tag) { - return tag >> kUpb_WireReader_WireTypeBits; -} - -UPB_INLINE uint8_t UPB_PRIVATE(_upb_WireReader_GetWireType)(uint32_t tag) { - return tag & kUpb_WireReader_WireTypeMask; -} +int32_t upb_MessageReservedRange_Start(const upb_MessageReservedRange* r); +int32_t upb_MessageReservedRange_End(const upb_MessageReservedRange* r); #ifdef __cplusplus } /* extern "C" */ #endif -#endif // UPB_WIRE_INTERNAL_READER_H_ - -#ifndef UPB_WIRE_TYPES_H_ -#define UPB_WIRE_TYPES_H_ - -// A list of types as they are encoded on the wire. -typedef enum { - kUpb_WireType_Varint = 0, - kUpb_WireType_64Bit = 1, - kUpb_WireType_Delimited = 2, - kUpb_WireType_StartGroup = 3, - kUpb_WireType_EndGroup = 4, - kUpb_WireType_32Bit = 5 -} upb_WireType; - -#endif /* UPB_WIRE_TYPES_H_ */ +#endif /* UPB_REFLECTION_MESSAGE_RESERVED_RANGE_H_ */ // Must be last. -// The upb_WireReader interface is suitable for general-purpose parsing of -// protobuf binary wire format. It is designed to be used along with -// upb_EpsCopyInputStream for buffering, and all parsing routines in this file -// assume that at least kUpb_EpsCopyInputStream_SlopBytes worth of data is -// available to read without any bounds checks. - #ifdef __cplusplus extern "C" { #endif -// Parses a tag into `tag`, and returns a pointer past the end of the tag, or -// NULL if there was an error in the tag data. -// -// REQUIRES: there must be at least 10 bytes of data available at `ptr`. -// Bounds checks must be performed before calling this function, preferably -// by calling upb_EpsCopyInputStream_IsDone(). -static UPB_FORCEINLINE const char* upb_WireReader_ReadTag(const char* ptr, - uint32_t* tag) { - uint64_t val; - ptr = UPB_PRIVATE(_upb_WireReader_ReadVarint)(ptr, &val, 5, UINT32_MAX); - if (!ptr) return NULL; - *tag = val; - return ptr; -} - -// Given a tag, returns the field number. -UPB_INLINE uint32_t upb_WireReader_GetFieldNumber(uint32_t tag) { - return UPB_PRIVATE(_upb_WireReader_GetFieldNumber)(tag); -} +upb_MessageReservedRange* _upb_MessageReservedRange_At( + const upb_MessageReservedRange* r, int i); -// Given a tag, returns the wire type. -UPB_INLINE uint8_t upb_WireReader_GetWireType(uint32_t tag) { - return UPB_PRIVATE(_upb_WireReader_GetWireType)(tag); -} +// Allocate and initialize an array of |n| reserved ranges owned by |m|. +upb_MessageReservedRange* _upb_MessageReservedRanges_New( + upb_DefBuilder* ctx, int n, + const UPB_DESC(DescriptorProto_ReservedRange) * const* protos, + const upb_MessageDef* m); -UPB_INLINE const char* upb_WireReader_ReadVarint(const char* ptr, - uint64_t* val) { - return UPB_PRIVATE(_upb_WireReader_ReadVarint)(ptr, val, 10, UINT64_MAX); -} +#ifdef __cplusplus +} /* extern "C" */ +#endif -// Skips data for a varint, returning a pointer past the end of the varint, or -// NULL if there was an error in the varint data. -// -// REQUIRES: there must be at least 10 bytes of data available at `ptr`. -// Bounds checks must be performed before calling this function, preferably -// by calling upb_EpsCopyInputStream_IsDone(). -UPB_INLINE const char* upb_WireReader_SkipVarint(const char* ptr) { - uint64_t val; - return upb_WireReader_ReadVarint(ptr, &val); -} -// Reads a varint indicating the size of a delimited field into `size`, or -// NULL if there was an error in the varint data. -// -// REQUIRES: there must be at least 10 bytes of data available at `ptr`. -// Bounds checks must be performed before calling this function, preferably -// by calling upb_EpsCopyInputStream_IsDone(). -UPB_INLINE const char* upb_WireReader_ReadSize(const char* ptr, int* size) { - uint64_t size64; - ptr = upb_WireReader_ReadVarint(ptr, &size64); - if (!ptr || size64 >= INT32_MAX) return NULL; - *size = size64; - return ptr; -} +#endif /* UPB_REFLECTION_MESSAGE_RESERVED_RANGE_INTERNAL_H_ */ -// Reads a fixed32 field, performing byte swapping if necessary. -// -// REQUIRES: there must be at least 4 bytes of data available at `ptr`. -// Bounds checks must be performed before calling this function, preferably -// by calling upb_EpsCopyInputStream_IsDone(). -UPB_INLINE const char* upb_WireReader_ReadFixed32(const char* ptr, void* val) { - uint32_t uval; - memcpy(&uval, ptr, 4); - uval = UPB_PRIVATE(_upb_BigEndian32)(uval); - memcpy(val, &uval, 4); - return ptr + 4; -} +#ifndef UPB_REFLECTION_METHOD_DEF_INTERNAL_H_ +#define UPB_REFLECTION_METHOD_DEF_INTERNAL_H_ -// Reads a fixed64 field, performing byte swapping if necessary. -// -// REQUIRES: there must be at least 4 bytes of data available at `ptr`. -// Bounds checks must be performed before calling this function, preferably -// by calling upb_EpsCopyInputStream_IsDone(). -UPB_INLINE const char* upb_WireReader_ReadFixed64(const char* ptr, void* val) { - uint64_t uval; - memcpy(&uval, ptr, 8); - uval = UPB_PRIVATE(_upb_BigEndian64)(uval); - memcpy(val, &uval, 8); - return ptr + 8; -} -const char* UPB_PRIVATE(_upb_WireReader_SkipGroup)( - const char* ptr, uint32_t tag, int depth_limit, - upb_EpsCopyInputStream* stream); +// Must be last. -// Skips data for a group, returning a pointer past the end of the group, or -// NULL if there was an error parsing the group. The `tag` argument should be -// the start group tag that begins the group. The `depth_limit` argument -// indicates how many levels of recursion the group is allowed to have before -// reporting a parse error (this limit exists to protect against stack -// overflow). -// -// TODO: evaluate how the depth_limit should be specified. Do users need -// control over this? -UPB_INLINE const char* upb_WireReader_SkipGroup( - const char* ptr, uint32_t tag, upb_EpsCopyInputStream* stream) { - return UPB_PRIVATE(_upb_WireReader_SkipGroup)(ptr, tag, 100, stream); -} +#ifdef __cplusplus +extern "C" { +#endif -UPB_INLINE const char* _upb_WireReader_SkipValue( - const char* ptr, uint32_t tag, int depth_limit, - upb_EpsCopyInputStream* stream) { - switch (upb_WireReader_GetWireType(tag)) { - case kUpb_WireType_Varint: - return upb_WireReader_SkipVarint(ptr); - case kUpb_WireType_32Bit: - return ptr + 4; - case kUpb_WireType_64Bit: - return ptr + 8; - case kUpb_WireType_Delimited: { - int size; - ptr = upb_WireReader_ReadSize(ptr, &size); - if (!ptr) return NULL; - ptr += size; - return ptr; - } - case kUpb_WireType_StartGroup: - return UPB_PRIVATE(_upb_WireReader_SkipGroup)(ptr, tag, depth_limit, - stream); - case kUpb_WireType_EndGroup: - return NULL; // Should be handled before now. - default: - return NULL; // Unknown wire type. - } -} +upb_MethodDef* _upb_MethodDef_At(const upb_MethodDef* m, int i); -// Skips data for a wire value of any type, returning a pointer past the end of -// the data, or NULL if there was an error parsing the group. The `tag` argument -// should be the tag that was just parsed. The `depth_limit` argument indicates -// how many levels of recursion a group is allowed to have before reporting a -// parse error (this limit exists to protect against stack overflow). -// -// REQUIRES: there must be at least 10 bytes of data available at `ptr`. -// Bounds checks must be performed before calling this function, preferably -// by calling upb_EpsCopyInputStream_IsDone(). -// -// TODO: evaluate how the depth_limit should be specified. Do users need -// control over this? -UPB_INLINE const char* upb_WireReader_SkipValue( - const char* ptr, uint32_t tag, upb_EpsCopyInputStream* stream) { - return _upb_WireReader_SkipValue(ptr, tag, 100, stream); -} +// Allocate and initialize an array of |n| method defs owned by |s|. +upb_MethodDef* _upb_MethodDefs_New(upb_DefBuilder* ctx, int n, + const UPB_DESC(MethodDescriptorProto*) + const* protos, + const UPB_DESC(FeatureSet*) parent_features, + upb_ServiceDef* s); #ifdef __cplusplus } /* extern "C" */ #endif -#endif // UPB_WIRE_READER_H_ +#endif /* UPB_REFLECTION_METHOD_DEF_INTERNAL_H_ */ // This should #undef all macros #defined in def.inc From 4f1eba857a0d8d17f357df5ca7ae70b38217f1bd Mon Sep 17 00:00:00 2001 From: Eric Salo Date: Mon, 1 Jan 2024 19:50:31 -0800 Subject: [PATCH 143/255] upb: lock down the internal headers for upb:wire_reader PiperOrigin-RevId: 595002227 --- upb/base/BUILD | 1 + upb/{wire => base}/internal/endian.h | 21 +++++++++++---------- upb/util/BUILD | 1 + upb/util/compare_test.cc | 6 +++--- upb/wire/BUILD | 5 +++-- upb/wire/decode.c | 8 ++++---- upb/wire/encode.c | 14 +++++++------- upb/wire/internal/decode_fast.h | 11 ++++++----- upb/wire/reader.h | 6 +++--- 9 files changed, 39 insertions(+), 34 deletions(-) rename upb/{wire => base}/internal/endian.h (53%) diff --git a/upb/base/BUILD b/upb/base/BUILD index 2fce94baf5335..c1ab1d3321a8c 100644 --- a/upb/base/BUILD +++ b/upb/base/BUILD @@ -29,6 +29,7 @@ cc_library( cc_library( name = "internal", hdrs = [ + "internal/endian.h", "internal/log2.h", ], copts = UPB_DEFAULT_COPTS, diff --git a/upb/wire/internal/endian.h b/upb/base/internal/endian.h similarity index 53% rename from upb/wire/internal/endian.h rename to upb/base/internal/endian.h index 09788c9b313dc..089742752673e 100644 --- a/upb/wire/internal/endian.h +++ b/upb/base/internal/endian.h @@ -5,8 +5,8 @@ // license that can be found in the LICENSE file or at // https://developers.google.com/open-source/licenses/bsd -#ifndef UPB_WIRE_INTERNAL_ENDIAN_H_ -#define UPB_WIRE_INTERNAL_ENDIAN_H_ +#ifndef UPB_BASE_INTERNAL_ENDIAN_H_ +#define UPB_BASE_INTERNAL_ENDIAN_H_ #include @@ -17,23 +17,24 @@ extern "C" { #endif -UPB_INLINE bool UPB_PRIVATE(_upb_IsLittleEndian)(void) { +UPB_INLINE bool upb_IsLittleEndian(void) { const int x = 1; return *(char*)&x == 1; } -UPB_INLINE uint32_t UPB_PRIVATE(_upb_BigEndian32)(uint32_t val) { - if (UPB_PRIVATE(_upb_IsLittleEndian)()) return val; +UPB_INLINE uint32_t upb_BigEndian32(uint32_t val) { + if (upb_IsLittleEndian()) return val; return ((val & 0xff) << 24) | ((val & 0xff00) << 8) | ((val & 0xff0000) >> 8) | ((val & 0xff000000) >> 24); } -UPB_INLINE uint64_t UPB_PRIVATE(_upb_BigEndian64)(uint64_t val) { - if (UPB_PRIVATE(_upb_IsLittleEndian)()) return val; +UPB_INLINE uint64_t upb_BigEndian64(uint64_t val) { + if (upb_IsLittleEndian()) return val; - return ((uint64_t)UPB_PRIVATE(_upb_BigEndian32)((uint32_t)val) << 32) | - UPB_PRIVATE(_upb_BigEndian32)((uint32_t)(val >> 32)); + const uint64_t hi = ((uint64_t)upb_BigEndian32((uint32_t)val)) << 32; + const uint64_t lo = upb_BigEndian32((uint32_t)(val >> 32)); + return hi | lo; } #ifdef __cplusplus @@ -42,4 +43,4 @@ UPB_INLINE uint64_t UPB_PRIVATE(_upb_BigEndian64)(uint64_t val) { #include "upb/port/undef.inc" -#endif /* UPB_WIRE_INTERNAL_ENDIAN_H_ */ +#endif /* UPB_BASE_INTERNAL_ENDIAN_H_ */ diff --git a/upb/util/BUILD b/upb/util/BUILD index 962f208f8e82d..5d0ce9fc97c6d 100644 --- a/upb/util/BUILD +++ b/upb/util/BUILD @@ -165,6 +165,7 @@ cc_test( ":compare", "//upb:port", "//upb:wire_reader", + "//upb/base:internal", "@com_google_absl//absl/strings", "@com_google_googletest//:gtest", "@com_google_googletest//:gtest_main", diff --git a/upb/util/compare_test.cc b/upb/util/compare_test.cc index b29a0ccbdce66..1a1a2935d0932 100644 --- a/upb/util/compare_test.cc +++ b/upb/util/compare_test.cc @@ -15,7 +15,7 @@ #include #include -#include "upb/wire/internal/endian.h" +#include "upb/base/internal/endian.h" #include "upb/wire/types.h" // Must be last. @@ -84,11 +84,11 @@ std::string ToBinaryPayload(const UnknownFields& fields) { ret.append(val->val); } else if (const auto* val = std::get_if(&field.value)) { EncodeVarint(field.field_number << 3 | kUpb_WireType_64Bit, &ret); - uint64_t swapped = UPB_PRIVATE(_upb_BigEndian64)(val->val); + uint64_t swapped = upb_BigEndian64(val->val); ret.append(reinterpret_cast(&swapped), sizeof(swapped)); } else if (const auto* val = std::get_if(&field.value)) { EncodeVarint(field.field_number << 3 | kUpb_WireType_32Bit, &ret); - uint32_t swapped = UPB_PRIVATE(_upb_BigEndian32)(val->val); + uint32_t swapped = upb_BigEndian32(val->val); ret.append(reinterpret_cast(&swapped), sizeof(swapped)); } else if (const auto* val = std::get_if(&field.value)) { EncodeVarint(field.field_number << 3 | kUpb_WireType_StartGroup, &ret); diff --git a/upb/wire/BUILD b/upb/wire/BUILD index 6a7a68b2cbb63..a39491a4fd795 100644 --- a/upb/wire/BUILD +++ b/upb/wire/BUILD @@ -33,6 +33,7 @@ cc_library( "//upb:message_accessors", "//upb:mini_table", "//upb:port", + "//upb/base:internal", "//upb/hash", "//upb/mem:internal", "//upb/message:internal", @@ -43,11 +44,10 @@ cc_library( cc_library( name = "reader", srcs = [ + "internal/reader.h", "reader.c", ], hdrs = [ - "internal/endian.h", - "internal/reader.h", "reader.h", "types.h", ], @@ -55,6 +55,7 @@ cc_library( deps = [ ":eps_copy_input_stream", "//upb:port", + "//upb/base:internal", ], ) diff --git a/upb/wire/decode.c b/upb/wire/decode.c index a80f65c11c9ea..6d52b3702e948 100644 --- a/upb/wire/decode.c +++ b/upb/wire/decode.c @@ -14,6 +14,7 @@ #include #include "upb/base/descriptor_constants.h" +#include "upb/base/internal/endian.h" #include "upb/base/string_view.h" #include "upb/hash/common.h" #include "upb/mem/arena.h" @@ -42,7 +43,6 @@ #include "upb/wire/eps_copy_input_stream.h" #include "upb/wire/internal/constants.h" #include "upb/wire/internal/decoder.h" -#include "upb/wire/internal/endian.h" #include "upb/wire/reader.h" // Must be last. @@ -212,7 +212,7 @@ static const char* upb_Decoder_DecodeSize(upb_Decoder* d, const char* ptr, } static void _upb_Decoder_MungeInt32(wireval* val) { - if (!UPB_PRIVATE(_upb_IsLittleEndian)()) { + if (!upb_IsLittleEndian()) { /* The next stage will memcpy(dst, &val, 4) */ val->uint32_val = val->uint64_val; } @@ -434,7 +434,7 @@ static const char* _upb_Decoder_DecodeFixedPacked( arr->UPB_PRIVATE(size) += count; // Note: if/when the decoder supports multi-buffer input, we will need to // handle buffer seams here. - if (UPB_PRIVATE(_upb_IsLittleEndian)()) { + if (upb_IsLittleEndian()) { ptr = upb_EpsCopyInputStream_Copy(&d->input, ptr, mem, val->size); } else { int delta = upb_EpsCopyInputStream_PushLimit(&d->input, ptr, val->size); @@ -758,7 +758,7 @@ const char* _upb_Decoder_CheckRequired(upb_Decoder* d, const char* ptr, } uint64_t msg_head; memcpy(&msg_head, msg, 8); - msg_head = UPB_PRIVATE(_upb_BigEndian64)(msg_head); + msg_head = upb_BigEndian64(msg_head); if (UPB_PRIVATE(_upb_MiniTable_RequiredMask)(m) & ~msg_head) { d->missing_required = true; } diff --git a/upb/wire/encode.c b/upb/wire/encode.c index 5797e97ec1f70..aeec7edec3928 100644 --- a/upb/wire/encode.c +++ b/upb/wire/encode.c @@ -15,6 +15,7 @@ #include #include "upb/base/descriptor_constants.h" +#include "upb/base/internal/endian.h" #include "upb/base/string_view.h" #include "upb/hash/common.h" #include "upb/hash/str_table.h" @@ -37,7 +38,6 @@ #include "upb/mini_table/message.h" #include "upb/mini_table/sub.h" #include "upb/wire/internal/constants.h" -#include "upb/wire/internal/endian.h" #include "upb/wire/types.h" // Must be last. @@ -130,12 +130,12 @@ static void encode_bytes(upb_encstate* e, const void* data, size_t len) { } static void encode_fixed64(upb_encstate* e, uint64_t val) { - val = UPB_PRIVATE(_upb_BigEndian64)(val); + val = upb_BigEndian64(val); encode_bytes(e, &val, sizeof(uint64_t)); } static void encode_fixed32(upb_encstate* e, uint32_t val) { - val = UPB_PRIVATE(_upb_BigEndian32)(val); + val = upb_BigEndian32(val); encode_bytes(e, &val, sizeof(uint32_t)); } @@ -186,18 +186,18 @@ static void encode_fixedarray(upb_encstate* e, const upb_Array* arr, const char* data = _upb_array_constptr(arr); const char* ptr = data + bytes - elem_size; - if (tag || !UPB_PRIVATE(_upb_IsLittleEndian)()) { + if (tag || !upb_IsLittleEndian()) { while (true) { if (elem_size == 4) { uint32_t val; memcpy(&val, ptr, sizeof(val)); - val = UPB_PRIVATE(_upb_BigEndian32)(val); + val = upb_BigEndian32(val); encode_bytes(e, &val, elem_size); } else { UPB_ASSERT(elem_size == 8); uint64_t val; memcpy(&val, ptr, sizeof(val)); - val = UPB_PRIVATE(_upb_BigEndian64)(val); + val = upb_BigEndian64(val); encode_bytes(e, &val, elem_size); } @@ -552,7 +552,7 @@ static void encode_message(upb_encstate* e, const upb_Message* msg, m->UPB_PRIVATE(required_count)) { uint64_t msg_head; memcpy(&msg_head, msg, 8); - msg_head = UPB_PRIVATE(_upb_BigEndian64)(msg_head); + msg_head = upb_BigEndian64(msg_head); if (UPB_PRIVATE(_upb_MiniTable_RequiredMask)(m) & ~msg_head) { encode_err(e, kUpb_EncodeStatus_MissingRequired); } diff --git a/upb/wire/internal/decode_fast.h b/upb/wire/internal/decode_fast.h index 5f486297196f0..53270f82eae66 100644 --- a/upb/wire/internal/decode_fast.h +++ b/upb/wire/internal/decode_fast.h @@ -39,8 +39,8 @@ // - '1' for one-byte tags (field numbers 1-15) // - '2' for two-byte tags (field numbers 16-2048) -#ifndef UPB_WIRE_DECODE_INTERNAL_FAST_H_ -#define UPB_WIRE_DECODE_INTERNAL_FAST_H_ +#ifndef UPB_WIRE_INTERNAL_DECODE_FAST_H_ +#define UPB_WIRE_INTERNAL_DECODE_FAST_H_ #include "upb/message/message.h" @@ -110,6 +110,7 @@ TAGBYTES(o) TAGBYTES(r) #undef F +#undef UTF8 #undef TAGBYTES /* sub-message fields *********************************************************/ @@ -132,9 +133,9 @@ TAGBYTES(s) TAGBYTES(o) TAGBYTES(r) -#undef TAGBYTES -#undef SIZES #undef F +#undef SIZES +#undef TAGBYTES #undef UPB_PARSE_PARAMS @@ -144,4 +145,4 @@ TAGBYTES(r) #include "upb/port/undef.inc" -#endif /* UPB_WIRE_DECODE_INTERNAL_FAST_H_ */ +#endif /* UPB_WIRE_INTERNAL_DECODE_FAST_H_ */ diff --git a/upb/wire/reader.h b/upb/wire/reader.h index c3ec1a8b1839d..9914837d73113 100644 --- a/upb/wire/reader.h +++ b/upb/wire/reader.h @@ -8,8 +8,8 @@ #ifndef UPB_WIRE_READER_H_ #define UPB_WIRE_READER_H_ +#include "upb/base/internal/endian.h" #include "upb/wire/eps_copy_input_stream.h" -#include "upb/wire/internal/endian.h" #include "upb/wire/internal/reader.h" #include "upb/wire/types.h" // IWYU pragma: export @@ -89,7 +89,7 @@ UPB_INLINE const char* upb_WireReader_ReadSize(const char* ptr, int* size) { UPB_INLINE const char* upb_WireReader_ReadFixed32(const char* ptr, void* val) { uint32_t uval; memcpy(&uval, ptr, 4); - uval = UPB_PRIVATE(_upb_BigEndian32)(uval); + uval = upb_BigEndian32(uval); memcpy(val, &uval, 4); return ptr + 4; } @@ -102,7 +102,7 @@ UPB_INLINE const char* upb_WireReader_ReadFixed32(const char* ptr, void* val) { UPB_INLINE const char* upb_WireReader_ReadFixed64(const char* ptr, void* val) { uint64_t uval; memcpy(&uval, ptr, 8); - uval = UPB_PRIVATE(_upb_BigEndian64)(uval); + uval = upb_BigEndian64(uval); memcpy(val, &uval, 8); return ptr + 8; } From de5ea1e6a4eedf3c1362c460751dd28a9a0c861f Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Tue, 2 Jan 2024 04:02:53 +0000 Subject: [PATCH 144/255] Auto-generate files after cl/595002227 --- php/ext/google/protobuf/php-upb.c | 18 +++--- php/ext/google/protobuf/php-upb.h | 90 ++++++++++++++------------- ruby/ext/google/protobuf_c/ruby-upb.c | 18 +++--- ruby/ext/google/protobuf_c/ruby-upb.h | 90 ++++++++++++++------------- 4 files changed, 110 insertions(+), 106 deletions(-) diff --git a/php/ext/google/protobuf/php-upb.c b/php/ext/google/protobuf/php-upb.c index c30b837b9d3af..6b856a10839c4 100644 --- a/php/ext/google/protobuf/php-upb.c +++ b/php/ext/google/protobuf/php-upb.c @@ -7364,7 +7364,7 @@ static const char* upb_Decoder_DecodeSize(upb_Decoder* d, const char* ptr, } static void _upb_Decoder_MungeInt32(wireval* val) { - if (!UPB_PRIVATE(_upb_IsLittleEndian)()) { + if (!upb_IsLittleEndian()) { /* The next stage will memcpy(dst, &val, 4) */ val->uint32_val = val->uint64_val; } @@ -7586,7 +7586,7 @@ static const char* _upb_Decoder_DecodeFixedPacked( arr->UPB_PRIVATE(size) += count; // Note: if/when the decoder supports multi-buffer input, we will need to // handle buffer seams here. - if (UPB_PRIVATE(_upb_IsLittleEndian)()) { + if (upb_IsLittleEndian()) { ptr = upb_EpsCopyInputStream_Copy(&d->input, ptr, mem, val->size); } else { int delta = upb_EpsCopyInputStream_PushLimit(&d->input, ptr, val->size); @@ -7910,7 +7910,7 @@ const char* _upb_Decoder_CheckRequired(upb_Decoder* d, const char* ptr, } uint64_t msg_head; memcpy(&msg_head, msg, 8); - msg_head = UPB_PRIVATE(_upb_BigEndian64)(msg_head); + msg_head = upb_BigEndian64(msg_head); if (UPB_PRIVATE(_upb_MiniTable_RequiredMask)(m) & ~msg_head) { d->missing_required = true; } @@ -8637,12 +8637,12 @@ static void encode_bytes(upb_encstate* e, const void* data, size_t len) { } static void encode_fixed64(upb_encstate* e, uint64_t val) { - val = UPB_PRIVATE(_upb_BigEndian64)(val); + val = upb_BigEndian64(val); encode_bytes(e, &val, sizeof(uint64_t)); } static void encode_fixed32(upb_encstate* e, uint32_t val) { - val = UPB_PRIVATE(_upb_BigEndian32)(val); + val = upb_BigEndian32(val); encode_bytes(e, &val, sizeof(uint32_t)); } @@ -8693,18 +8693,18 @@ static void encode_fixedarray(upb_encstate* e, const upb_Array* arr, const char* data = _upb_array_constptr(arr); const char* ptr = data + bytes - elem_size; - if (tag || !UPB_PRIVATE(_upb_IsLittleEndian)()) { + if (tag || !upb_IsLittleEndian()) { while (true) { if (elem_size == 4) { uint32_t val; memcpy(&val, ptr, sizeof(val)); - val = UPB_PRIVATE(_upb_BigEndian32)(val); + val = upb_BigEndian32(val); encode_bytes(e, &val, elem_size); } else { UPB_ASSERT(elem_size == 8); uint64_t val; memcpy(&val, ptr, sizeof(val)); - val = UPB_PRIVATE(_upb_BigEndian64)(val); + val = upb_BigEndian64(val); encode_bytes(e, &val, elem_size); } @@ -9059,7 +9059,7 @@ static void encode_message(upb_encstate* e, const upb_Message* msg, m->UPB_PRIVATE(required_count)) { uint64_t msg_head; memcpy(&msg_head, msg, 8); - msg_head = UPB_PRIVATE(_upb_BigEndian64)(msg_head); + msg_head = upb_BigEndian64(msg_head); if (UPB_PRIVATE(_upb_MiniTable_RequiredMask)(m) & ~msg_head) { encode_err(e, kUpb_EncodeStatus_MissingRequired); } diff --git a/php/ext/google/protobuf/php-upb.h b/php/ext/google/protobuf/php-upb.h index 0d3b3539b40ba..09232c3e6d5c5 100644 --- a/php/ext/google/protobuf/php-upb.h +++ b/php/ext/google/protobuf/php-upb.h @@ -4104,8 +4104,8 @@ UPB_API upb_EncodeStatus upb_Encode(const upb_Message* msg, // - '1' for one-byte tags (field numbers 1-15) // - '2' for two-byte tags (field numbers 16-2048) -#ifndef UPB_WIRE_DECODE_INTERNAL_FAST_H_ -#define UPB_WIRE_DECODE_INTERNAL_FAST_H_ +#ifndef UPB_WIRE_INTERNAL_DECODE_FAST_H_ +#define UPB_WIRE_INTERNAL_DECODE_FAST_H_ // Must be last. @@ -4173,6 +4173,7 @@ TAGBYTES(o) TAGBYTES(r) #undef F +#undef UTF8 #undef TAGBYTES /* sub-message fields *********************************************************/ @@ -4195,9 +4196,9 @@ TAGBYTES(s) TAGBYTES(o) TAGBYTES(r) -#undef TAGBYTES -#undef SIZES #undef F +#undef SIZES +#undef TAGBYTES #undef UPB_PARSE_PARAMS @@ -4206,7 +4207,7 @@ TAGBYTES(r) #endif -#endif /* UPB_WIRE_DECODE_INTERNAL_FAST_H_ */ +#endif /* UPB_WIRE_INTERNAL_DECODE_FAST_H_ */ // IWYU pragma: end_exports #endif // UPB_GENERATED_CODE_SUPPORT_H_ @@ -12942,6 +12943,44 @@ void upb_inttable_removeiter(upb_inttable* t, intptr_t* iter); #endif /* UPB_HASH_INT_TABLE_H_ */ +#ifndef UPB_BASE_INTERNAL_ENDIAN_H_ +#define UPB_BASE_INTERNAL_ENDIAN_H_ + +#include + +// Must be last. + +#ifdef __cplusplus +extern "C" { +#endif + +UPB_INLINE bool upb_IsLittleEndian(void) { + const int x = 1; + return *(char*)&x == 1; +} + +UPB_INLINE uint32_t upb_BigEndian32(uint32_t val) { + if (upb_IsLittleEndian()) return val; + + return ((val & 0xff) << 24) | ((val & 0xff00) << 8) | + ((val & 0xff0000) >> 8) | ((val & 0xff000000) >> 24); +} + +UPB_INLINE uint64_t upb_BigEndian64(uint64_t val) { + if (upb_IsLittleEndian()) return val; + + const uint64_t hi = ((uint64_t)upb_BigEndian32((uint32_t)val)) << 32; + const uint64_t lo = upb_BigEndian32((uint32_t)(val >> 32)); + return hi | lo; +} + +#ifdef __cplusplus +} /* extern "C" */ +#endif + + +#endif /* UPB_BASE_INTERNAL_ENDIAN_H_ */ + #ifndef UPB_WIRE_INTERNAL_CONSTANTS_H_ #define UPB_WIRE_INTERNAL_CONSTANTS_H_ @@ -13078,43 +13117,6 @@ UPB_INLINE uint32_t _upb_FastDecoder_LoadTag(const char* ptr) { #endif /* UPB_WIRE_INTERNAL_DECODER_H_ */ -#ifndef UPB_WIRE_INTERNAL_ENDIAN_H_ -#define UPB_WIRE_INTERNAL_ENDIAN_H_ - -#include - -// Must be last. - -#ifdef __cplusplus -extern "C" { -#endif - -UPB_INLINE bool UPB_PRIVATE(_upb_IsLittleEndian)(void) { - const int x = 1; - return *(char*)&x == 1; -} - -UPB_INLINE uint32_t UPB_PRIVATE(_upb_BigEndian32)(uint32_t val) { - if (UPB_PRIVATE(_upb_IsLittleEndian)()) return val; - - return ((val & 0xff) << 24) | ((val & 0xff00) << 8) | - ((val & 0xff0000) >> 8) | ((val & 0xff000000) >> 24); -} - -UPB_INLINE uint64_t UPB_PRIVATE(_upb_BigEndian64)(uint64_t val) { - if (UPB_PRIVATE(_upb_IsLittleEndian)()) return val; - - return ((uint64_t)UPB_PRIVATE(_upb_BigEndian32)((uint32_t)val) << 32) | - UPB_PRIVATE(_upb_BigEndian32)((uint32_t)(val >> 32)); -} - -#ifdef __cplusplus -} /* extern "C" */ -#endif - - -#endif /* UPB_WIRE_INTERNAL_ENDIAN_H_ */ - #ifndef UPB_WIRE_READER_H_ #define UPB_WIRE_READER_H_ @@ -13262,7 +13264,7 @@ UPB_INLINE const char* upb_WireReader_ReadSize(const char* ptr, int* size) { UPB_INLINE const char* upb_WireReader_ReadFixed32(const char* ptr, void* val) { uint32_t uval; memcpy(&uval, ptr, 4); - uval = UPB_PRIVATE(_upb_BigEndian32)(uval); + uval = upb_BigEndian32(uval); memcpy(val, &uval, 4); return ptr + 4; } @@ -13275,7 +13277,7 @@ UPB_INLINE const char* upb_WireReader_ReadFixed32(const char* ptr, void* val) { UPB_INLINE const char* upb_WireReader_ReadFixed64(const char* ptr, void* val) { uint64_t uval; memcpy(&uval, ptr, 8); - uval = UPB_PRIVATE(_upb_BigEndian64)(uval); + uval = upb_BigEndian64(uval); memcpy(val, &uval, 8); return ptr + 8; } diff --git a/ruby/ext/google/protobuf_c/ruby-upb.c b/ruby/ext/google/protobuf_c/ruby-upb.c index 87f95d0ab10e6..0b5f52e15421d 100644 --- a/ruby/ext/google/protobuf_c/ruby-upb.c +++ b/ruby/ext/google/protobuf_c/ruby-upb.c @@ -6880,7 +6880,7 @@ static const char* upb_Decoder_DecodeSize(upb_Decoder* d, const char* ptr, } static void _upb_Decoder_MungeInt32(wireval* val) { - if (!UPB_PRIVATE(_upb_IsLittleEndian)()) { + if (!upb_IsLittleEndian()) { /* The next stage will memcpy(dst, &val, 4) */ val->uint32_val = val->uint64_val; } @@ -7102,7 +7102,7 @@ static const char* _upb_Decoder_DecodeFixedPacked( arr->UPB_PRIVATE(size) += count; // Note: if/when the decoder supports multi-buffer input, we will need to // handle buffer seams here. - if (UPB_PRIVATE(_upb_IsLittleEndian)()) { + if (upb_IsLittleEndian()) { ptr = upb_EpsCopyInputStream_Copy(&d->input, ptr, mem, val->size); } else { int delta = upb_EpsCopyInputStream_PushLimit(&d->input, ptr, val->size); @@ -7426,7 +7426,7 @@ const char* _upb_Decoder_CheckRequired(upb_Decoder* d, const char* ptr, } uint64_t msg_head; memcpy(&msg_head, msg, 8); - msg_head = UPB_PRIVATE(_upb_BigEndian64)(msg_head); + msg_head = upb_BigEndian64(msg_head); if (UPB_PRIVATE(_upb_MiniTable_RequiredMask)(m) & ~msg_head) { d->missing_required = true; } @@ -8153,12 +8153,12 @@ static void encode_bytes(upb_encstate* e, const void* data, size_t len) { } static void encode_fixed64(upb_encstate* e, uint64_t val) { - val = UPB_PRIVATE(_upb_BigEndian64)(val); + val = upb_BigEndian64(val); encode_bytes(e, &val, sizeof(uint64_t)); } static void encode_fixed32(upb_encstate* e, uint32_t val) { - val = UPB_PRIVATE(_upb_BigEndian32)(val); + val = upb_BigEndian32(val); encode_bytes(e, &val, sizeof(uint32_t)); } @@ -8209,18 +8209,18 @@ static void encode_fixedarray(upb_encstate* e, const upb_Array* arr, const char* data = _upb_array_constptr(arr); const char* ptr = data + bytes - elem_size; - if (tag || !UPB_PRIVATE(_upb_IsLittleEndian)()) { + if (tag || !upb_IsLittleEndian()) { while (true) { if (elem_size == 4) { uint32_t val; memcpy(&val, ptr, sizeof(val)); - val = UPB_PRIVATE(_upb_BigEndian32)(val); + val = upb_BigEndian32(val); encode_bytes(e, &val, elem_size); } else { UPB_ASSERT(elem_size == 8); uint64_t val; memcpy(&val, ptr, sizeof(val)); - val = UPB_PRIVATE(_upb_BigEndian64)(val); + val = upb_BigEndian64(val); encode_bytes(e, &val, elem_size); } @@ -8575,7 +8575,7 @@ static void encode_message(upb_encstate* e, const upb_Message* msg, m->UPB_PRIVATE(required_count)) { uint64_t msg_head; memcpy(&msg_head, msg, 8); - msg_head = UPB_PRIVATE(_upb_BigEndian64)(msg_head); + msg_head = upb_BigEndian64(msg_head); if (UPB_PRIVATE(_upb_MiniTable_RequiredMask)(m) & ~msg_head) { encode_err(e, kUpb_EncodeStatus_MissingRequired); } diff --git a/ruby/ext/google/protobuf_c/ruby-upb.h b/ruby/ext/google/protobuf_c/ruby-upb.h index dfa9ffe1bc2b9..302e9c293759d 100755 --- a/ruby/ext/google/protobuf_c/ruby-upb.h +++ b/ruby/ext/google/protobuf_c/ruby-upb.h @@ -4106,8 +4106,8 @@ UPB_API upb_EncodeStatus upb_Encode(const upb_Message* msg, // - '1' for one-byte tags (field numbers 1-15) // - '2' for two-byte tags (field numbers 16-2048) -#ifndef UPB_WIRE_DECODE_INTERNAL_FAST_H_ -#define UPB_WIRE_DECODE_INTERNAL_FAST_H_ +#ifndef UPB_WIRE_INTERNAL_DECODE_FAST_H_ +#define UPB_WIRE_INTERNAL_DECODE_FAST_H_ // Must be last. @@ -4175,6 +4175,7 @@ TAGBYTES(o) TAGBYTES(r) #undef F +#undef UTF8 #undef TAGBYTES /* sub-message fields *********************************************************/ @@ -4197,9 +4198,9 @@ TAGBYTES(s) TAGBYTES(o) TAGBYTES(r) -#undef TAGBYTES -#undef SIZES #undef F +#undef SIZES +#undef TAGBYTES #undef UPB_PARSE_PARAMS @@ -4208,7 +4209,7 @@ TAGBYTES(r) #endif -#endif /* UPB_WIRE_DECODE_INTERNAL_FAST_H_ */ +#endif /* UPB_WIRE_INTERNAL_DECODE_FAST_H_ */ // IWYU pragma: end_exports #endif // UPB_GENERATED_CODE_SUPPORT_H_ @@ -12714,6 +12715,44 @@ void upb_inttable_removeiter(upb_inttable* t, intptr_t* iter); #endif /* UPB_HASH_INT_TABLE_H_ */ +#ifndef UPB_BASE_INTERNAL_ENDIAN_H_ +#define UPB_BASE_INTERNAL_ENDIAN_H_ + +#include + +// Must be last. + +#ifdef __cplusplus +extern "C" { +#endif + +UPB_INLINE bool upb_IsLittleEndian(void) { + const int x = 1; + return *(char*)&x == 1; +} + +UPB_INLINE uint32_t upb_BigEndian32(uint32_t val) { + if (upb_IsLittleEndian()) return val; + + return ((val & 0xff) << 24) | ((val & 0xff00) << 8) | + ((val & 0xff0000) >> 8) | ((val & 0xff000000) >> 24); +} + +UPB_INLINE uint64_t upb_BigEndian64(uint64_t val) { + if (upb_IsLittleEndian()) return val; + + const uint64_t hi = ((uint64_t)upb_BigEndian32((uint32_t)val)) << 32; + const uint64_t lo = upb_BigEndian32((uint32_t)(val >> 32)); + return hi | lo; +} + +#ifdef __cplusplus +} /* extern "C" */ +#endif + + +#endif /* UPB_BASE_INTERNAL_ENDIAN_H_ */ + #ifndef UPB_WIRE_INTERNAL_CONSTANTS_H_ #define UPB_WIRE_INTERNAL_CONSTANTS_H_ @@ -12850,43 +12889,6 @@ UPB_INLINE uint32_t _upb_FastDecoder_LoadTag(const char* ptr) { #endif /* UPB_WIRE_INTERNAL_DECODER_H_ */ -#ifndef UPB_WIRE_INTERNAL_ENDIAN_H_ -#define UPB_WIRE_INTERNAL_ENDIAN_H_ - -#include - -// Must be last. - -#ifdef __cplusplus -extern "C" { -#endif - -UPB_INLINE bool UPB_PRIVATE(_upb_IsLittleEndian)(void) { - const int x = 1; - return *(char*)&x == 1; -} - -UPB_INLINE uint32_t UPB_PRIVATE(_upb_BigEndian32)(uint32_t val) { - if (UPB_PRIVATE(_upb_IsLittleEndian)()) return val; - - return ((val & 0xff) << 24) | ((val & 0xff00) << 8) | - ((val & 0xff0000) >> 8) | ((val & 0xff000000) >> 24); -} - -UPB_INLINE uint64_t UPB_PRIVATE(_upb_BigEndian64)(uint64_t val) { - if (UPB_PRIVATE(_upb_IsLittleEndian)()) return val; - - return ((uint64_t)UPB_PRIVATE(_upb_BigEndian32)((uint32_t)val) << 32) | - UPB_PRIVATE(_upb_BigEndian32)((uint32_t)(val >> 32)); -} - -#ifdef __cplusplus -} /* extern "C" */ -#endif - - -#endif /* UPB_WIRE_INTERNAL_ENDIAN_H_ */ - #ifndef UPB_WIRE_READER_H_ #define UPB_WIRE_READER_H_ @@ -13034,7 +13036,7 @@ UPB_INLINE const char* upb_WireReader_ReadSize(const char* ptr, int* size) { UPB_INLINE const char* upb_WireReader_ReadFixed32(const char* ptr, void* val) { uint32_t uval; memcpy(&uval, ptr, 4); - uval = UPB_PRIVATE(_upb_BigEndian32)(uval); + uval = upb_BigEndian32(uval); memcpy(val, &uval, 4); return ptr + 4; } @@ -13047,7 +13049,7 @@ UPB_INLINE const char* upb_WireReader_ReadFixed32(const char* ptr, void* val) { UPB_INLINE const char* upb_WireReader_ReadFixed64(const char* ptr, void* val) { uint64_t uval; memcpy(&uval, ptr, 8); - uval = UPB_PRIVATE(_upb_BigEndian64)(uval); + uval = upb_BigEndian64(uval); memcpy(val, &uval, 8); return ptr + 8; } From 4ba7d2720187aa468bff2a89f55de3ae989a401a Mon Sep 17 00:00:00 2001 From: Eric Salo Date: Mon, 1 Jan 2024 21:29:20 -0800 Subject: [PATCH 145/255] upb: implement _upb_Message_ClearOneofCase() PiperOrigin-RevId: 595018281 --- upb/message/BUILD | 1 + upb/message/internal/accessors.h | 117 ++++++++++++++++++------------- upb/mini_table/internal/field.h | 9 ++- upb/wire/decode.c | 10 +-- upb/wire/encode.c | 2 +- 5 files changed, 81 insertions(+), 58 deletions(-) diff --git a/upb/message/BUILD b/upb/message/BUILD index 6988edbc16fbe..d6f4528d8ada8 100644 --- a/upb/message/BUILD +++ b/upb/message/BUILD @@ -72,6 +72,7 @@ cc_library( "//upb:port", "//upb/base:internal", "//upb/hash", + "//upb/mini_table:internal", ], ) diff --git a/upb/message/internal/accessors.h b/upb/message/internal/accessors.h index 5a84b0259adc5..94f2c8429bd9d 100644 --- a/upb/message/internal/accessors.h +++ b/upb/message/internal/accessors.h @@ -20,6 +20,7 @@ #include "upb/message/internal/tagged_ptr.h" #include "upb/mini_table/extension.h" #include "upb/mini_table/field.h" +#include "upb/mini_table/internal/field.h" // Must be last. #include "upb/port/def.inc" @@ -84,41 +85,74 @@ UPB_INLINE uint32_t* UPB_PRIVATE(_upb_Message_OneofCasePtr)( UPB_INLINE uint32_t UPB_PRIVATE(_upb_Message_GetOneofCase)( const struct upb_Message* msg, const upb_MiniTableField* f) { - return *UPB_PRIVATE(_upb_Message_OneofCasePtr)((struct upb_Message*)msg, f); + const uint32_t* ptr = + UPB_PRIVATE(_upb_Message_OneofCasePtr)((struct upb_Message*)msg, f); + + return *ptr; } UPB_INLINE void UPB_PRIVATE(_upb_Message_SetOneofCase)( struct upb_Message* msg, const upb_MiniTableField* f) { - *UPB_PRIVATE(_upb_Message_OneofCasePtr)(msg, f) = - upb_MiniTableField_Number(f); + uint32_t* ptr = UPB_PRIVATE(_upb_Message_OneofCasePtr)(msg, f); + + *ptr = upb_MiniTableField_Number(f); } -// TODO: implement _upb_Message_ClearOneofCase() +// Returns true if the given field is the current oneof case. +// Does nothing if it is not the current oneof case. +UPB_INLINE bool UPB_PRIVATE(_upb_Message_ClearOneofCase)( + struct upb_Message* msg, const upb_MiniTableField* f) { + uint32_t* ptr = UPB_PRIVATE(_upb_Message_OneofCasePtr)(msg, f); + + if (*ptr != upb_MiniTableField_Number(f)) return false; + *ptr = 0; + return true; +} // LINT.ThenChange(GoogleInternalName2) -UPB_INLINE void* _upb_MiniTableField_GetPtr(struct upb_Message* msg, - const upb_MiniTableField* field) { - return (char*)msg + field->UPB_ONLYBITS(offset); +UPB_INLINE void* UPB_PRIVATE(_upb_Message_DataPtr)( + struct upb_Message* msg, const upb_MiniTableField* f) { + return (char*)msg + f->UPB_ONLYBITS(offset); } -UPB_INLINE const void* _upb_MiniTableField_GetConstPtr( - const struct upb_Message* msg, const upb_MiniTableField* field) { - return (char*)msg + field->UPB_ONLYBITS(offset); +UPB_INLINE const void* UPB_PRIVATE(_upb_Message_ConstDataPtr)( + const struct upb_Message* msg, const upb_MiniTableField* f) { + return (const char*)msg + f->UPB_ONLYBITS(offset); } UPB_INLINE void UPB_PRIVATE(_upb_Message_SetPresence)( - struct upb_Message* msg, const upb_MiniTableField* field) { - if (field->presence > 0) { - UPB_PRIVATE(_upb_Message_SetHasbit)(msg, field); - } else if (upb_MiniTableField_IsInOneof(field)) { - UPB_PRIVATE(_upb_Message_SetOneofCase)(msg, field); + struct upb_Message* msg, const upb_MiniTableField* f) { + if (UPB_PRIVATE(_upb_MiniTableField_HasHasbit)(f)) { + UPB_PRIVATE(_upb_Message_SetHasbit)(msg, f); + } else if (upb_MiniTableField_IsInOneof(f)) { + UPB_PRIVATE(_upb_Message_SetOneofCase)(msg, f); } } +UPB_INLINE void UPB_PRIVATE(_upb_MiniTableField_DataCopy)( + const upb_MiniTableField* f, void* to, const void* from) { + switch (UPB_PRIVATE(_upb_MiniTableField_GetRep)(f)) { + case kUpb_FieldRep_1Byte: + memcpy(to, from, 1); + return; + case kUpb_FieldRep_4Byte: + memcpy(to, from, 4); + return; + case kUpb_FieldRep_8Byte: + memcpy(to, from, 8); + return; + case kUpb_FieldRep_StringView: { + memcpy(to, from, sizeof(upb_StringView)); + return; + } + } + UPB_UNREACHABLE(); +} + UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_DataEquals)( - const upb_MiniTableField* field, const void* a, const void* b) { - switch (UPB_PRIVATE(_upb_MiniTableField_GetRep)(field)) { + const upb_MiniTableField* f, const void* a, const void* b) { + switch (UPB_PRIVATE(_upb_MiniTableField_GetRep)(f)) { case kUpb_FieldRep_1Byte: return memcmp(a, b, 1) == 0; case kUpb_FieldRep_4Byte: @@ -134,30 +168,16 @@ UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_DataEquals)( UPB_UNREACHABLE(); } -UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_DataIsZero)( - const upb_MiniTableField* field, const void* val) { +UPB_INLINE void UPB_PRIVATE(_upb_MiniTableField_DataClear)( + const upb_MiniTableField* f, void* val) { const char zero[16] = {0}; - return UPB_PRIVATE(_upb_MiniTableField_DataEquals)(field, val, zero); + return UPB_PRIVATE(_upb_MiniTableField_DataCopy)(f, val, zero); } -UPB_INLINE void UPB_PRIVATE(_upb_MiniTableField_DataCopy)( - const upb_MiniTableField* field, void* to, const void* from) { - switch (UPB_PRIVATE(_upb_MiniTableField_GetRep)(field)) { - case kUpb_FieldRep_1Byte: - memcpy(to, from, 1); - return; - case kUpb_FieldRep_4Byte: - memcpy(to, from, 4); - return; - case kUpb_FieldRep_8Byte: - memcpy(to, from, 8); - return; - case kUpb_FieldRep_StringView: { - memcpy(to, from, sizeof(upb_StringView)); - return; - } - } - UPB_UNREACHABLE(); +UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_DataIsZero)( + const upb_MiniTableField* f, const void* val) { + const char zero[16] = {0}; + return UPB_PRIVATE(_upb_MiniTableField_DataEquals)(f, val, zero); } // Here we define universal getter/setter functions for message fields. @@ -222,7 +242,7 @@ static UPB_FORCEINLINE void _upb_Message_GetNonExtensionField( return; } UPB_PRIVATE(_upb_MiniTableField_DataCopy) - (field, val, _upb_MiniTableField_GetConstPtr(msg, field)); + (field, val, UPB_PRIVATE(_upb_Message_ConstDataPtr)(msg, field)); } UPB_INLINE void _upb_Message_GetExtensionField( @@ -244,7 +264,7 @@ UPB_INLINE void _upb_Message_SetNonExtensionField( UPB_ASSUME(!upb_MiniTableField_IsExtension(field)); UPB_PRIVATE(_upb_Message_SetPresence)(msg, field); UPB_PRIVATE(_upb_MiniTableField_DataCopy) - (field, _upb_MiniTableField_GetPtr(msg, field), val); + (field, UPB_PRIVATE(_upb_Message_DataPtr)(msg, field), val); } UPB_INLINE bool _upb_Message_SetExtensionField( @@ -273,17 +293,14 @@ UPB_INLINE void _upb_Message_ClearExtensionField( } UPB_INLINE void _upb_Message_ClearNonExtensionField( - struct upb_Message* msg, const upb_MiniTableField* field) { - if (field->presence > 0) { - UPB_PRIVATE(_upb_Message_ClearHasbit)(msg, field); - } else if (upb_MiniTableField_IsInOneof(field)) { - uint32_t* ptr = UPB_PRIVATE(_upb_Message_OneofCasePtr)(msg, field); - if (*ptr != upb_MiniTableField_Number(field)) return; - *ptr = 0; + struct upb_Message* msg, const upb_MiniTableField* f) { + if (UPB_PRIVATE(_upb_MiniTableField_HasHasbit)(f)) { + UPB_PRIVATE(_upb_Message_ClearHasbit)(msg, f); + } else if (upb_MiniTableField_IsInOneof(f)) { + if (!UPB_PRIVATE(_upb_Message_ClearOneofCase)(msg, f)) return; } - const char zeros[16] = {0}; - UPB_PRIVATE(_upb_MiniTableField_DataCopy) - (field, _upb_MiniTableField_GetPtr(msg, field), zeros); + void* data = UPB_PRIVATE(_upb_Message_DataPtr)(msg, f); + UPB_PRIVATE(_upb_MiniTableField_DataClear)(f, data); } UPB_INLINE void _upb_Message_AssertMapIsUntagged( diff --git a/upb/mini_table/internal/field.h b/upb/mini_table/internal/field.h index 37568e017b550..166463a88621a 100644 --- a/upb/mini_table/internal/field.h +++ b/upb/mini_table/internal/field.h @@ -130,16 +130,21 @@ UPB_PRIVATE(_upb_MiniTableField_CType)(const struct upb_MiniTableField* f) { return upb_FieldType_CType(UPB_PRIVATE(_upb_MiniTableField_Type)(f)); } +UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_HasHasbit)( + const struct upb_MiniTableField* f) { + return f->presence > 0; +} + UPB_INLINE char UPB_PRIVATE(_upb_MiniTableField_HasbitMask)( const struct upb_MiniTableField* f) { - UPB_ASSERT(f->presence > 0); + UPB_ASSERT(UPB_PRIVATE(_upb_MiniTableField_HasHasbit)(f)); const size_t index = f->presence; return 1 << (index % 8); } UPB_INLINE size_t UPB_PRIVATE(_upb_MiniTableField_HasbitOffset)( const struct upb_MiniTableField* f) { - UPB_ASSERT(f->presence > 0); + UPB_ASSERT(UPB_PRIVATE(_upb_MiniTableField_HasHasbit)(f)); const size_t index = f->presence; return index / 8; } diff --git a/upb/wire/decode.c b/upb/wire/decode.c index 6d52b3702e948..c8270397abe17 100644 --- a/upb/wire/decode.c +++ b/upb/wire/decode.c @@ -695,11 +695,11 @@ static const char* _upb_Decoder_DecodeToSubMessage( return ptr; } - /* Set presence if necessary. */ - if (field->presence > 0) { + // Set presence if necessary. + if (UPB_PRIVATE(_upb_MiniTableField_HasHasbit)(field)) { UPB_PRIVATE(_upb_Message_SetHasbit)(msg, field); - } else if (field->presence < 0) { - /* Oneof case */ + } else if (UPB_PRIVATE(_upb_MiniTableField_IsInOneof)(field)) { + // Oneof case uint32_t* oneof_case = UPB_PRIVATE(_upb_Message_OneofCasePtr)(msg, field); if (op == kUpb_DecodeOp_SubMessage && *oneof_case != field->UPB_PRIVATE(number)) { @@ -708,7 +708,7 @@ static const char* _upb_Decoder_DecodeToSubMessage( *oneof_case = field->UPB_PRIVATE(number); } - /* Store into message. */ + // Store into message. switch (op) { case kUpb_DecodeOp_SubMessage: { upb_TaggedMessagePtr* submsgp = mem; diff --git a/upb/wire/encode.c b/upb/wire/encode.c index aeec7edec3928..12a6d32b6fa9f 100644 --- a/upb/wire/encode.c +++ b/upb/wire/encode.c @@ -493,7 +493,7 @@ static bool encode_shouldencode(upb_encstate* e, const upb_Message* msg, default: UPB_UNREACHABLE(); } - } else if (f->presence > 0) { + } else if (UPB_PRIVATE(_upb_MiniTableField_HasHasbit)(f)) { // Proto2 presence: hasbit. return UPB_PRIVATE(_upb_Message_GetHasbit)(msg, f); } else { From 18d4a7651b8b74d7e0e5e177c54319530fdd6ddf Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Tue, 2 Jan 2024 05:41:47 +0000 Subject: [PATCH 146/255] Auto-generate files after cl/595018281 --- php/ext/google/protobuf/php-upb.c | 12 +-- php/ext/google/protobuf/php-upb.h | 127 +++++++++++++++----------- ruby/ext/google/protobuf_c/ruby-upb.c | 12 +-- ruby/ext/google/protobuf_c/ruby-upb.h | 127 +++++++++++++++----------- 4 files changed, 160 insertions(+), 118 deletions(-) diff --git a/php/ext/google/protobuf/php-upb.c b/php/ext/google/protobuf/php-upb.c index 6b856a10839c4..4157999576a6f 100644 --- a/php/ext/google/protobuf/php-upb.c +++ b/php/ext/google/protobuf/php-upb.c @@ -7847,11 +7847,11 @@ static const char* _upb_Decoder_DecodeToSubMessage( return ptr; } - /* Set presence if necessary. */ - if (field->presence > 0) { + // Set presence if necessary. + if (UPB_PRIVATE(_upb_MiniTableField_HasHasbit)(field)) { UPB_PRIVATE(_upb_Message_SetHasbit)(msg, field); - } else if (field->presence < 0) { - /* Oneof case */ + } else if (UPB_PRIVATE(_upb_MiniTableField_IsInOneof)(field)) { + // Oneof case uint32_t* oneof_case = UPB_PRIVATE(_upb_Message_OneofCasePtr)(msg, field); if (op == kUpb_DecodeOp_SubMessage && *oneof_case != field->UPB_PRIVATE(number)) { @@ -7860,7 +7860,7 @@ static const char* _upb_Decoder_DecodeToSubMessage( *oneof_case = field->UPB_PRIVATE(number); } - /* Store into message. */ + // Store into message. switch (op) { case kUpb_DecodeOp_SubMessage: { upb_TaggedMessagePtr* submsgp = mem; @@ -9000,7 +9000,7 @@ static bool encode_shouldencode(upb_encstate* e, const upb_Message* msg, default: UPB_UNREACHABLE(); } - } else if (f->presence > 0) { + } else if (UPB_PRIVATE(_upb_MiniTableField_HasHasbit)(f)) { // Proto2 presence: hasbit. return UPB_PRIVATE(_upb_Message_GetHasbit)(msg, f); } else { diff --git a/php/ext/google/protobuf/php-upb.h b/php/ext/google/protobuf/php-upb.h index 09232c3e6d5c5..27814aeed6e03 100644 --- a/php/ext/google/protobuf/php-upb.h +++ b/php/ext/google/protobuf/php-upb.h @@ -1610,16 +1610,21 @@ UPB_PRIVATE(_upb_MiniTableField_CType)(const struct upb_MiniTableField* f) { return upb_FieldType_CType(UPB_PRIVATE(_upb_MiniTableField_Type)(f)); } +UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_HasHasbit)( + const struct upb_MiniTableField* f) { + return f->presence > 0; +} + UPB_INLINE char UPB_PRIVATE(_upb_MiniTableField_HasbitMask)( const struct upb_MiniTableField* f) { - UPB_ASSERT(f->presence > 0); + UPB_ASSERT(UPB_PRIVATE(_upb_MiniTableField_HasHasbit)(f)); const size_t index = f->presence; return 1 << (index % 8); } UPB_INLINE size_t UPB_PRIVATE(_upb_MiniTableField_HasbitOffset)( const struct upb_MiniTableField* f) { - UPB_ASSERT(f->presence > 0); + UPB_ASSERT(UPB_PRIVATE(_upb_MiniTableField_HasHasbit)(f)); const size_t index = f->presence; return index / 8; } @@ -2553,41 +2558,74 @@ UPB_INLINE uint32_t* UPB_PRIVATE(_upb_Message_OneofCasePtr)( UPB_INLINE uint32_t UPB_PRIVATE(_upb_Message_GetOneofCase)( const struct upb_Message* msg, const upb_MiniTableField* f) { - return *UPB_PRIVATE(_upb_Message_OneofCasePtr)((struct upb_Message*)msg, f); + const uint32_t* ptr = + UPB_PRIVATE(_upb_Message_OneofCasePtr)((struct upb_Message*)msg, f); + + return *ptr; } UPB_INLINE void UPB_PRIVATE(_upb_Message_SetOneofCase)( struct upb_Message* msg, const upb_MiniTableField* f) { - *UPB_PRIVATE(_upb_Message_OneofCasePtr)(msg, f) = - upb_MiniTableField_Number(f); + uint32_t* ptr = UPB_PRIVATE(_upb_Message_OneofCasePtr)(msg, f); + + *ptr = upb_MiniTableField_Number(f); } -// TODO: implement _upb_Message_ClearOneofCase() +// Returns true if the given field is the current oneof case. +// Does nothing if it is not the current oneof case. +UPB_INLINE bool UPB_PRIVATE(_upb_Message_ClearOneofCase)( + struct upb_Message* msg, const upb_MiniTableField* f) { + uint32_t* ptr = UPB_PRIVATE(_upb_Message_OneofCasePtr)(msg, f); + + if (*ptr != upb_MiniTableField_Number(f)) return false; + *ptr = 0; + return true; +} // LINT.ThenChange(GoogleInternalName2) -UPB_INLINE void* _upb_MiniTableField_GetPtr(struct upb_Message* msg, - const upb_MiniTableField* field) { - return (char*)msg + field->UPB_ONLYBITS(offset); +UPB_INLINE void* UPB_PRIVATE(_upb_Message_DataPtr)( + struct upb_Message* msg, const upb_MiniTableField* f) { + return (char*)msg + f->UPB_ONLYBITS(offset); } -UPB_INLINE const void* _upb_MiniTableField_GetConstPtr( - const struct upb_Message* msg, const upb_MiniTableField* field) { - return (char*)msg + field->UPB_ONLYBITS(offset); +UPB_INLINE const void* UPB_PRIVATE(_upb_Message_ConstDataPtr)( + const struct upb_Message* msg, const upb_MiniTableField* f) { + return (const char*)msg + f->UPB_ONLYBITS(offset); } UPB_INLINE void UPB_PRIVATE(_upb_Message_SetPresence)( - struct upb_Message* msg, const upb_MiniTableField* field) { - if (field->presence > 0) { - UPB_PRIVATE(_upb_Message_SetHasbit)(msg, field); - } else if (upb_MiniTableField_IsInOneof(field)) { - UPB_PRIVATE(_upb_Message_SetOneofCase)(msg, field); + struct upb_Message* msg, const upb_MiniTableField* f) { + if (UPB_PRIVATE(_upb_MiniTableField_HasHasbit)(f)) { + UPB_PRIVATE(_upb_Message_SetHasbit)(msg, f); + } else if (upb_MiniTableField_IsInOneof(f)) { + UPB_PRIVATE(_upb_Message_SetOneofCase)(msg, f); } } +UPB_INLINE void UPB_PRIVATE(_upb_MiniTableField_DataCopy)( + const upb_MiniTableField* f, void* to, const void* from) { + switch (UPB_PRIVATE(_upb_MiniTableField_GetRep)(f)) { + case kUpb_FieldRep_1Byte: + memcpy(to, from, 1); + return; + case kUpb_FieldRep_4Byte: + memcpy(to, from, 4); + return; + case kUpb_FieldRep_8Byte: + memcpy(to, from, 8); + return; + case kUpb_FieldRep_StringView: { + memcpy(to, from, sizeof(upb_StringView)); + return; + } + } + UPB_UNREACHABLE(); +} + UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_DataEquals)( - const upb_MiniTableField* field, const void* a, const void* b) { - switch (UPB_PRIVATE(_upb_MiniTableField_GetRep)(field)) { + const upb_MiniTableField* f, const void* a, const void* b) { + switch (UPB_PRIVATE(_upb_MiniTableField_GetRep)(f)) { case kUpb_FieldRep_1Byte: return memcmp(a, b, 1) == 0; case kUpb_FieldRep_4Byte: @@ -2603,30 +2641,16 @@ UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_DataEquals)( UPB_UNREACHABLE(); } -UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_DataIsZero)( - const upb_MiniTableField* field, const void* val) { +UPB_INLINE void UPB_PRIVATE(_upb_MiniTableField_DataClear)( + const upb_MiniTableField* f, void* val) { const char zero[16] = {0}; - return UPB_PRIVATE(_upb_MiniTableField_DataEquals)(field, val, zero); + return UPB_PRIVATE(_upb_MiniTableField_DataCopy)(f, val, zero); } -UPB_INLINE void UPB_PRIVATE(_upb_MiniTableField_DataCopy)( - const upb_MiniTableField* field, void* to, const void* from) { - switch (UPB_PRIVATE(_upb_MiniTableField_GetRep)(field)) { - case kUpb_FieldRep_1Byte: - memcpy(to, from, 1); - return; - case kUpb_FieldRep_4Byte: - memcpy(to, from, 4); - return; - case kUpb_FieldRep_8Byte: - memcpy(to, from, 8); - return; - case kUpb_FieldRep_StringView: { - memcpy(to, from, sizeof(upb_StringView)); - return; - } - } - UPB_UNREACHABLE(); +UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_DataIsZero)( + const upb_MiniTableField* f, const void* val) { + const char zero[16] = {0}; + return UPB_PRIVATE(_upb_MiniTableField_DataEquals)(f, val, zero); } // Here we define universal getter/setter functions for message fields. @@ -2691,7 +2715,7 @@ static UPB_FORCEINLINE void _upb_Message_GetNonExtensionField( return; } UPB_PRIVATE(_upb_MiniTableField_DataCopy) - (field, val, _upb_MiniTableField_GetConstPtr(msg, field)); + (field, val, UPB_PRIVATE(_upb_Message_ConstDataPtr)(msg, field)); } UPB_INLINE void _upb_Message_GetExtensionField( @@ -2713,7 +2737,7 @@ UPB_INLINE void _upb_Message_SetNonExtensionField( UPB_ASSUME(!upb_MiniTableField_IsExtension(field)); UPB_PRIVATE(_upb_Message_SetPresence)(msg, field); UPB_PRIVATE(_upb_MiniTableField_DataCopy) - (field, _upb_MiniTableField_GetPtr(msg, field), val); + (field, UPB_PRIVATE(_upb_Message_DataPtr)(msg, field), val); } UPB_INLINE bool _upb_Message_SetExtensionField( @@ -2742,17 +2766,14 @@ UPB_INLINE void _upb_Message_ClearExtensionField( } UPB_INLINE void _upb_Message_ClearNonExtensionField( - struct upb_Message* msg, const upb_MiniTableField* field) { - if (field->presence > 0) { - UPB_PRIVATE(_upb_Message_ClearHasbit)(msg, field); - } else if (upb_MiniTableField_IsInOneof(field)) { - uint32_t* ptr = UPB_PRIVATE(_upb_Message_OneofCasePtr)(msg, field); - if (*ptr != upb_MiniTableField_Number(field)) return; - *ptr = 0; - } - const char zeros[16] = {0}; - UPB_PRIVATE(_upb_MiniTableField_DataCopy) - (field, _upb_MiniTableField_GetPtr(msg, field), zeros); + struct upb_Message* msg, const upb_MiniTableField* f) { + if (UPB_PRIVATE(_upb_MiniTableField_HasHasbit)(f)) { + UPB_PRIVATE(_upb_Message_ClearHasbit)(msg, f); + } else if (upb_MiniTableField_IsInOneof(f)) { + if (!UPB_PRIVATE(_upb_Message_ClearOneofCase)(msg, f)) return; + } + void* data = UPB_PRIVATE(_upb_Message_DataPtr)(msg, f); + UPB_PRIVATE(_upb_MiniTableField_DataClear)(f, data); } UPB_INLINE void _upb_Message_AssertMapIsUntagged( diff --git a/ruby/ext/google/protobuf_c/ruby-upb.c b/ruby/ext/google/protobuf_c/ruby-upb.c index 0b5f52e15421d..f124dc39fb89d 100644 --- a/ruby/ext/google/protobuf_c/ruby-upb.c +++ b/ruby/ext/google/protobuf_c/ruby-upb.c @@ -7363,11 +7363,11 @@ static const char* _upb_Decoder_DecodeToSubMessage( return ptr; } - /* Set presence if necessary. */ - if (field->presence > 0) { + // Set presence if necessary. + if (UPB_PRIVATE(_upb_MiniTableField_HasHasbit)(field)) { UPB_PRIVATE(_upb_Message_SetHasbit)(msg, field); - } else if (field->presence < 0) { - /* Oneof case */ + } else if (UPB_PRIVATE(_upb_MiniTableField_IsInOneof)(field)) { + // Oneof case uint32_t* oneof_case = UPB_PRIVATE(_upb_Message_OneofCasePtr)(msg, field); if (op == kUpb_DecodeOp_SubMessage && *oneof_case != field->UPB_PRIVATE(number)) { @@ -7376,7 +7376,7 @@ static const char* _upb_Decoder_DecodeToSubMessage( *oneof_case = field->UPB_PRIVATE(number); } - /* Store into message. */ + // Store into message. switch (op) { case kUpb_DecodeOp_SubMessage: { upb_TaggedMessagePtr* submsgp = mem; @@ -8516,7 +8516,7 @@ static bool encode_shouldencode(upb_encstate* e, const upb_Message* msg, default: UPB_UNREACHABLE(); } - } else if (f->presence > 0) { + } else if (UPB_PRIVATE(_upb_MiniTableField_HasHasbit)(f)) { // Proto2 presence: hasbit. return UPB_PRIVATE(_upb_Message_GetHasbit)(msg, f); } else { diff --git a/ruby/ext/google/protobuf_c/ruby-upb.h b/ruby/ext/google/protobuf_c/ruby-upb.h index 302e9c293759d..5bd47a51752cd 100755 --- a/ruby/ext/google/protobuf_c/ruby-upb.h +++ b/ruby/ext/google/protobuf_c/ruby-upb.h @@ -1612,16 +1612,21 @@ UPB_PRIVATE(_upb_MiniTableField_CType)(const struct upb_MiniTableField* f) { return upb_FieldType_CType(UPB_PRIVATE(_upb_MiniTableField_Type)(f)); } +UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_HasHasbit)( + const struct upb_MiniTableField* f) { + return f->presence > 0; +} + UPB_INLINE char UPB_PRIVATE(_upb_MiniTableField_HasbitMask)( const struct upb_MiniTableField* f) { - UPB_ASSERT(f->presence > 0); + UPB_ASSERT(UPB_PRIVATE(_upb_MiniTableField_HasHasbit)(f)); const size_t index = f->presence; return 1 << (index % 8); } UPB_INLINE size_t UPB_PRIVATE(_upb_MiniTableField_HasbitOffset)( const struct upb_MiniTableField* f) { - UPB_ASSERT(f->presence > 0); + UPB_ASSERT(UPB_PRIVATE(_upb_MiniTableField_HasHasbit)(f)); const size_t index = f->presence; return index / 8; } @@ -2555,41 +2560,74 @@ UPB_INLINE uint32_t* UPB_PRIVATE(_upb_Message_OneofCasePtr)( UPB_INLINE uint32_t UPB_PRIVATE(_upb_Message_GetOneofCase)( const struct upb_Message* msg, const upb_MiniTableField* f) { - return *UPB_PRIVATE(_upb_Message_OneofCasePtr)((struct upb_Message*)msg, f); + const uint32_t* ptr = + UPB_PRIVATE(_upb_Message_OneofCasePtr)((struct upb_Message*)msg, f); + + return *ptr; } UPB_INLINE void UPB_PRIVATE(_upb_Message_SetOneofCase)( struct upb_Message* msg, const upb_MiniTableField* f) { - *UPB_PRIVATE(_upb_Message_OneofCasePtr)(msg, f) = - upb_MiniTableField_Number(f); + uint32_t* ptr = UPB_PRIVATE(_upb_Message_OneofCasePtr)(msg, f); + + *ptr = upb_MiniTableField_Number(f); } -// TODO: implement _upb_Message_ClearOneofCase() +// Returns true if the given field is the current oneof case. +// Does nothing if it is not the current oneof case. +UPB_INLINE bool UPB_PRIVATE(_upb_Message_ClearOneofCase)( + struct upb_Message* msg, const upb_MiniTableField* f) { + uint32_t* ptr = UPB_PRIVATE(_upb_Message_OneofCasePtr)(msg, f); + + if (*ptr != upb_MiniTableField_Number(f)) return false; + *ptr = 0; + return true; +} // LINT.ThenChange(GoogleInternalName2) -UPB_INLINE void* _upb_MiniTableField_GetPtr(struct upb_Message* msg, - const upb_MiniTableField* field) { - return (char*)msg + field->UPB_ONLYBITS(offset); +UPB_INLINE void* UPB_PRIVATE(_upb_Message_DataPtr)( + struct upb_Message* msg, const upb_MiniTableField* f) { + return (char*)msg + f->UPB_ONLYBITS(offset); } -UPB_INLINE const void* _upb_MiniTableField_GetConstPtr( - const struct upb_Message* msg, const upb_MiniTableField* field) { - return (char*)msg + field->UPB_ONLYBITS(offset); +UPB_INLINE const void* UPB_PRIVATE(_upb_Message_ConstDataPtr)( + const struct upb_Message* msg, const upb_MiniTableField* f) { + return (const char*)msg + f->UPB_ONLYBITS(offset); } UPB_INLINE void UPB_PRIVATE(_upb_Message_SetPresence)( - struct upb_Message* msg, const upb_MiniTableField* field) { - if (field->presence > 0) { - UPB_PRIVATE(_upb_Message_SetHasbit)(msg, field); - } else if (upb_MiniTableField_IsInOneof(field)) { - UPB_PRIVATE(_upb_Message_SetOneofCase)(msg, field); + struct upb_Message* msg, const upb_MiniTableField* f) { + if (UPB_PRIVATE(_upb_MiniTableField_HasHasbit)(f)) { + UPB_PRIVATE(_upb_Message_SetHasbit)(msg, f); + } else if (upb_MiniTableField_IsInOneof(f)) { + UPB_PRIVATE(_upb_Message_SetOneofCase)(msg, f); } } +UPB_INLINE void UPB_PRIVATE(_upb_MiniTableField_DataCopy)( + const upb_MiniTableField* f, void* to, const void* from) { + switch (UPB_PRIVATE(_upb_MiniTableField_GetRep)(f)) { + case kUpb_FieldRep_1Byte: + memcpy(to, from, 1); + return; + case kUpb_FieldRep_4Byte: + memcpy(to, from, 4); + return; + case kUpb_FieldRep_8Byte: + memcpy(to, from, 8); + return; + case kUpb_FieldRep_StringView: { + memcpy(to, from, sizeof(upb_StringView)); + return; + } + } + UPB_UNREACHABLE(); +} + UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_DataEquals)( - const upb_MiniTableField* field, const void* a, const void* b) { - switch (UPB_PRIVATE(_upb_MiniTableField_GetRep)(field)) { + const upb_MiniTableField* f, const void* a, const void* b) { + switch (UPB_PRIVATE(_upb_MiniTableField_GetRep)(f)) { case kUpb_FieldRep_1Byte: return memcmp(a, b, 1) == 0; case kUpb_FieldRep_4Byte: @@ -2605,30 +2643,16 @@ UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_DataEquals)( UPB_UNREACHABLE(); } -UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_DataIsZero)( - const upb_MiniTableField* field, const void* val) { +UPB_INLINE void UPB_PRIVATE(_upb_MiniTableField_DataClear)( + const upb_MiniTableField* f, void* val) { const char zero[16] = {0}; - return UPB_PRIVATE(_upb_MiniTableField_DataEquals)(field, val, zero); + return UPB_PRIVATE(_upb_MiniTableField_DataCopy)(f, val, zero); } -UPB_INLINE void UPB_PRIVATE(_upb_MiniTableField_DataCopy)( - const upb_MiniTableField* field, void* to, const void* from) { - switch (UPB_PRIVATE(_upb_MiniTableField_GetRep)(field)) { - case kUpb_FieldRep_1Byte: - memcpy(to, from, 1); - return; - case kUpb_FieldRep_4Byte: - memcpy(to, from, 4); - return; - case kUpb_FieldRep_8Byte: - memcpy(to, from, 8); - return; - case kUpb_FieldRep_StringView: { - memcpy(to, from, sizeof(upb_StringView)); - return; - } - } - UPB_UNREACHABLE(); +UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_DataIsZero)( + const upb_MiniTableField* f, const void* val) { + const char zero[16] = {0}; + return UPB_PRIVATE(_upb_MiniTableField_DataEquals)(f, val, zero); } // Here we define universal getter/setter functions for message fields. @@ -2693,7 +2717,7 @@ static UPB_FORCEINLINE void _upb_Message_GetNonExtensionField( return; } UPB_PRIVATE(_upb_MiniTableField_DataCopy) - (field, val, _upb_MiniTableField_GetConstPtr(msg, field)); + (field, val, UPB_PRIVATE(_upb_Message_ConstDataPtr)(msg, field)); } UPB_INLINE void _upb_Message_GetExtensionField( @@ -2715,7 +2739,7 @@ UPB_INLINE void _upb_Message_SetNonExtensionField( UPB_ASSUME(!upb_MiniTableField_IsExtension(field)); UPB_PRIVATE(_upb_Message_SetPresence)(msg, field); UPB_PRIVATE(_upb_MiniTableField_DataCopy) - (field, _upb_MiniTableField_GetPtr(msg, field), val); + (field, UPB_PRIVATE(_upb_Message_DataPtr)(msg, field), val); } UPB_INLINE bool _upb_Message_SetExtensionField( @@ -2744,17 +2768,14 @@ UPB_INLINE void _upb_Message_ClearExtensionField( } UPB_INLINE void _upb_Message_ClearNonExtensionField( - struct upb_Message* msg, const upb_MiniTableField* field) { - if (field->presence > 0) { - UPB_PRIVATE(_upb_Message_ClearHasbit)(msg, field); - } else if (upb_MiniTableField_IsInOneof(field)) { - uint32_t* ptr = UPB_PRIVATE(_upb_Message_OneofCasePtr)(msg, field); - if (*ptr != upb_MiniTableField_Number(field)) return; - *ptr = 0; - } - const char zeros[16] = {0}; - UPB_PRIVATE(_upb_MiniTableField_DataCopy) - (field, _upb_MiniTableField_GetPtr(msg, field), zeros); + struct upb_Message* msg, const upb_MiniTableField* f) { + if (UPB_PRIVATE(_upb_MiniTableField_HasHasbit)(f)) { + UPB_PRIVATE(_upb_Message_ClearHasbit)(msg, f); + } else if (upb_MiniTableField_IsInOneof(f)) { + if (!UPB_PRIVATE(_upb_Message_ClearOneofCase)(msg, f)) return; + } + void* data = UPB_PRIVATE(_upb_Message_DataPtr)(msg, f); + UPB_PRIVATE(_upb_MiniTableField_DataClear)(f, data); } UPB_INLINE void _upb_Message_AssertMapIsUntagged( From 9debd6b10a9ee7cf5e4ba5c60cf366d250928a44 Mon Sep 17 00:00:00 2001 From: Eric Salo Date: Tue, 2 Jan 2024 09:30:17 -0800 Subject: [PATCH 147/255] upb: merge upb:message_accessors into upb:message PiperOrigin-RevId: 595137531 --- protos/BUILD | 1 - upb/BUILD | 11 ----------- upb/message/BUILD | 28 ++-------------------------- upb/mini_descriptor/BUILD | 2 +- upb/reflection/BUILD | 1 - upb/wire/BUILD | 1 - 6 files changed, 3 insertions(+), 41 deletions(-) diff --git a/protos/BUILD b/protos/BUILD index 0167b19d5ee17..460089b1b1329 100644 --- a/protos/BUILD +++ b/protos/BUILD @@ -55,7 +55,6 @@ cc_library( "//upb:base", "//upb:mem", "//upb:message", - "//upb:message_accessors", "//upb:message_copy", "//upb:message_promote", "//upb:mini_table", diff --git a/upb/BUILD b/upb/BUILD index 8979c279bd81f..31fdd4308fe99 100644 --- a/upb/BUILD +++ b/upb/BUILD @@ -111,7 +111,6 @@ cc_library( ":base", ":mem", ":message", - ":message_accessors", ":mini_descriptor", ":mini_table", ":wire", @@ -187,12 +186,6 @@ alias( visibility = ["//visibility:public"], ) -alias( - name = "message_accessors", - actual = "//upb/message:accessors", - visibility = ["//visibility:public"], -) - alias( name = "message_compare", actual = "//upb/message:compare", @@ -289,7 +282,6 @@ cc_binary( deps = [ ":mem", ":message", - ":message_accessors", ":message_compare", ":message_split64", ":mini_descriptor", @@ -317,7 +309,6 @@ upb_amalgamation( ":generated_code_support__only_for_generated_code_do_not_use__i_give_permission_to_break_me", ":mem", ":message", - ":message_accessors", ":message_compare", ":message_copy", ":mini_descriptor", @@ -363,7 +354,6 @@ upb_amalgamation( ":json", ":mem", ":message", - ":message_accessors", ":message_compare", ":message_copy", ":mini_descriptor", @@ -410,7 +400,6 @@ upb_amalgamation( ":json", ":mem", ":message", - ":message_accessors", ":message_compare", ":message_copy", ":mini_descriptor", diff --git a/upb/message/BUILD b/upb/message/BUILD index d6f4528d8ada8..3212444200a7b 100644 --- a/upb/message/BUILD +++ b/upb/message/BUILD @@ -19,6 +19,7 @@ load( cc_library( name = "message", srcs = [ + "accessors.c", "array.c", "compat.c", "map.c", @@ -26,6 +27,7 @@ cc_library( "message.c", ], hdrs = [ + "accessors.h", "array.h", "compat.h", "map.h", @@ -76,26 +78,6 @@ cc_library( ], ) -cc_library( - name = "accessors", - srcs = [ - "accessors.c", - ], - hdrs = [ - "accessors.h", - ], - copts = UPB_DEFAULT_COPTS, - visibility = ["//visibility:public"], - deps = [ - ":internal", - ":message", - "//upb:base", - "//upb:mem", - "//upb:mini_table", - "//upb:port", - ], -) - cc_library( name = "compare", srcs = [ @@ -126,7 +108,6 @@ cc_library( copts = UPB_DEFAULT_COPTS, visibility = ["//visibility:public"], deps = [ - ":accessors", ":internal", ":message", "//upb:base", @@ -149,7 +130,6 @@ cc_library( copts = UPB_DEFAULT_COPTS, visibility = ["//visibility:public"], deps = [ - ":accessors", ":internal", ":message", "//upb:base", @@ -171,7 +151,6 @@ cc_library( copts = UPB_DEFAULT_COPTS, visibility = ["//visibility:public"], deps = [ - ":accessors", ":message", "//upb:port", ], @@ -206,7 +185,6 @@ cc_test( name = "accessors_test", srcs = ["accessors_test.cc"], deps = [ - ":accessors", ":message", "//:protobuf", "//upb:base", @@ -243,7 +221,6 @@ cc_test( name = "copy_test", srcs = ["copy_test.cc"], deps = [ - ":accessors", ":copy", ":internal", ":message", @@ -278,7 +255,6 @@ cc_test( name = "promote_test", srcs = ["promote_test.cc"], deps = [ - ":accessors", ":copy", ":internal", ":message", diff --git a/upb/mini_descriptor/BUILD b/upb/mini_descriptor/BUILD index b1793c6bf7451..a397e901e30c5 100644 --- a/upb/mini_descriptor/BUILD +++ b/upb/mini_descriptor/BUILD @@ -62,7 +62,7 @@ cc_test( "//:protobuf", "//upb:base", "//upb:mem", - "//upb:message_accessors", + "//upb:message", "//upb:mini_table", "//upb:port", "//upb:wire", diff --git a/upb/reflection/BUILD b/upb/reflection/BUILD index 685f2d5bd251f..ee3f40da0f152 100644 --- a/upb/reflection/BUILD +++ b/upb/reflection/BUILD @@ -135,7 +135,6 @@ bootstrap_cc_library( "//upb:base", "//upb:mem", "//upb:message", - "//upb:message_accessors", "//upb:message_copy", "//upb:mini_descriptor", "//upb:mini_table", diff --git a/upb/wire/BUILD b/upb/wire/BUILD index a39491a4fd795..f655d64b9cc73 100644 --- a/upb/wire/BUILD +++ b/upb/wire/BUILD @@ -30,7 +30,6 @@ cc_library( "//upb:base", "//upb:mem", "//upb:message", - "//upb:message_accessors", "//upb:mini_table", "//upb:port", "//upb/base:internal", From 3d9916caca847d77a61dc43b9efb1b1b7a12fbcb Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Tue, 2 Jan 2024 17:43:15 +0000 Subject: [PATCH 148/255] Auto-generate files after cl/595137531 --- php/ext/google/protobuf/php-upb.c | 58 +++++++++++++-------------- ruby/ext/google/protobuf_c/ruby-upb.c | 58 +++++++++++++-------------- upb/cmake/CMakeLists.txt | 1 - 3 files changed, 58 insertions(+), 59 deletions(-) diff --git a/php/ext/google/protobuf/php-upb.c b/php/ext/google/protobuf/php-upb.c index 4157999576a6f..2874f54eee156 100644 --- a/php/ext/google/protobuf/php-upb.c +++ b/php/ext/google/protobuf/php-upb.c @@ -5025,6 +5025,35 @@ void UPB_PRIVATE(_upb_Arena_SwapOut)(upb_Arena* des, const upb_Arena* src) { } +#include + + +// Must be last. + +bool upb_Message_SetMapEntry(upb_Map* map, const upb_MiniTable* mini_table, + const upb_MiniTableField* f, + upb_Message* map_entry_message, upb_Arena* arena) { + // TODO: use a variant of upb_MiniTable_GetSubMessageTable() here. + const upb_MiniTable* map_entry_mini_table = upb_MiniTableSub_Message( + mini_table->UPB_PRIVATE(subs)[f->UPB_PRIVATE(submsg_index)]); + UPB_ASSERT(map_entry_mini_table); + UPB_ASSERT(map_entry_mini_table->UPB_PRIVATE(field_count) == 2); + const upb_MiniTableField* map_entry_key_field = + &map_entry_mini_table->UPB_PRIVATE(fields)[0]; + const upb_MiniTableField* map_entry_value_field = + &map_entry_mini_table->UPB_PRIVATE(fields)[1]; + // Map key/value cannot have explicit defaults, + // hence assuming a zero default is valid. + upb_MessageValue default_val; + memset(&default_val, 0, sizeof(upb_MessageValue)); + upb_MessageValue map_entry_key = + upb_Message_GetField(map_entry_message, map_entry_key_field, default_val); + upb_MessageValue map_entry_value = upb_Message_GetField( + map_entry_message, map_entry_value_field, default_val); + return upb_Map_Set(map, map_entry_key, map_entry_value, arena); +} + + #include #include @@ -5491,35 +5520,6 @@ size_t upb_Message_ExtensionCount(const upb_Message* msg) { #include -// Must be last. - -bool upb_Message_SetMapEntry(upb_Map* map, const upb_MiniTable* mini_table, - const upb_MiniTableField* f, - upb_Message* map_entry_message, upb_Arena* arena) { - // TODO: use a variant of upb_MiniTable_GetSubMessageTable() here. - const upb_MiniTable* map_entry_mini_table = upb_MiniTableSub_Message( - mini_table->UPB_PRIVATE(subs)[f->UPB_PRIVATE(submsg_index)]); - UPB_ASSERT(map_entry_mini_table); - UPB_ASSERT(map_entry_mini_table->UPB_PRIVATE(field_count) == 2); - const upb_MiniTableField* map_entry_key_field = - &map_entry_mini_table->UPB_PRIVATE(fields)[0]; - const upb_MiniTableField* map_entry_value_field = - &map_entry_mini_table->UPB_PRIVATE(fields)[1]; - // Map key/value cannot have explicit defaults, - // hence assuming a zero default is valid. - upb_MessageValue default_val; - memset(&default_val, 0, sizeof(upb_MessageValue)); - upb_MessageValue map_entry_key = - upb_Message_GetField(map_entry_message, map_entry_key_field, default_val); - upb_MessageValue map_entry_value = upb_Message_GetField( - map_entry_message, map_entry_value_field, default_val); - return upb_Map_Set(map, map_entry_key, map_entry_value, arena); -} - - -#include - - // Must be last. bool upb_Message_IsExactlyEqual(const upb_Message* msg1, diff --git a/ruby/ext/google/protobuf_c/ruby-upb.c b/ruby/ext/google/protobuf_c/ruby-upb.c index f124dc39fb89d..0648cbf9c4c73 100644 --- a/ruby/ext/google/protobuf_c/ruby-upb.c +++ b/ruby/ext/google/protobuf_c/ruby-upb.c @@ -4541,6 +4541,35 @@ void UPB_PRIVATE(_upb_Arena_SwapOut)(upb_Arena* des, const upb_Arena* src) { } +#include + + +// Must be last. + +bool upb_Message_SetMapEntry(upb_Map* map, const upb_MiniTable* mini_table, + const upb_MiniTableField* f, + upb_Message* map_entry_message, upb_Arena* arena) { + // TODO: use a variant of upb_MiniTable_GetSubMessageTable() here. + const upb_MiniTable* map_entry_mini_table = upb_MiniTableSub_Message( + mini_table->UPB_PRIVATE(subs)[f->UPB_PRIVATE(submsg_index)]); + UPB_ASSERT(map_entry_mini_table); + UPB_ASSERT(map_entry_mini_table->UPB_PRIVATE(field_count) == 2); + const upb_MiniTableField* map_entry_key_field = + &map_entry_mini_table->UPB_PRIVATE(fields)[0]; + const upb_MiniTableField* map_entry_value_field = + &map_entry_mini_table->UPB_PRIVATE(fields)[1]; + // Map key/value cannot have explicit defaults, + // hence assuming a zero default is valid. + upb_MessageValue default_val; + memset(&default_val, 0, sizeof(upb_MessageValue)); + upb_MessageValue map_entry_key = + upb_Message_GetField(map_entry_message, map_entry_key_field, default_val); + upb_MessageValue map_entry_value = upb_Message_GetField( + map_entry_message, map_entry_value_field, default_val); + return upb_Map_Set(map, map_entry_key, map_entry_value, arena); +} + + #include #include @@ -5007,35 +5036,6 @@ size_t upb_Message_ExtensionCount(const upb_Message* msg) { #include -// Must be last. - -bool upb_Message_SetMapEntry(upb_Map* map, const upb_MiniTable* mini_table, - const upb_MiniTableField* f, - upb_Message* map_entry_message, upb_Arena* arena) { - // TODO: use a variant of upb_MiniTable_GetSubMessageTable() here. - const upb_MiniTable* map_entry_mini_table = upb_MiniTableSub_Message( - mini_table->UPB_PRIVATE(subs)[f->UPB_PRIVATE(submsg_index)]); - UPB_ASSERT(map_entry_mini_table); - UPB_ASSERT(map_entry_mini_table->UPB_PRIVATE(field_count) == 2); - const upb_MiniTableField* map_entry_key_field = - &map_entry_mini_table->UPB_PRIVATE(fields)[0]; - const upb_MiniTableField* map_entry_value_field = - &map_entry_mini_table->UPB_PRIVATE(fields)[1]; - // Map key/value cannot have explicit defaults, - // hence assuming a zero default is valid. - upb_MessageValue default_val; - memset(&default_val, 0, sizeof(upb_MessageValue)); - upb_MessageValue map_entry_key = - upb_Message_GetField(map_entry_message, map_entry_key_field, default_val); - upb_MessageValue map_entry_value = upb_Message_GetField( - map_entry_message, map_entry_value_field, default_val); - return upb_Map_Set(map, map_entry_key, map_entry_value, arena); -} - - -#include - - // Must be last. bool upb_Message_IsExactlyEqual(const upb_Message* msg1, diff --git a/upb/cmake/CMakeLists.txt b/upb/cmake/CMakeLists.txt index 308bc33600332..0dc98ec32d372 100644 --- a/upb/cmake/CMakeLists.txt +++ b/upb/cmake/CMakeLists.txt @@ -91,7 +91,6 @@ target_link_libraries(generated_code_support__only_for_generated_code_do_not_use base mem message - message_accessors mini_descriptor mini_table wire From fa5f8fa7e84065b92ae9a73e37d434ec206c1ee8 Mon Sep 17 00:00:00 2001 From: Kevin King Date: Tue, 2 Jan 2024 10:01:27 -0800 Subject: [PATCH 149/255] Depend on upb_generator:mangle from rust compiler Update cmake to include necessary upb_generator files and upb namespace. PiperOrigin-RevId: 595144470 --- CMakeLists.txt | 2 ++ src/google/protobuf/compiler/rust/BUILD.bazel | 1 + src/libprotoc.map | 1 + 3 files changed, 4 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index f78fccc27a5bf..4fae55bb804cd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -279,6 +279,8 @@ endif (MSVC) include_directories( ${ZLIB_INCLUDE_DIRECTORIES} ${protobuf_BINARY_DIR} + # Support #include-ing other top-level directories, i.e. upb_generator. + ${protobuf_SOURCE_DIR} ${protobuf_SOURCE_DIR}/src) set(protobuf_ABSL_PROVIDER "module" CACHE STRING "Provider of absl library") diff --git a/src/google/protobuf/compiler/rust/BUILD.bazel b/src/google/protobuf/compiler/rust/BUILD.bazel index 03212d1bae1f4..3dd9b247aaa0b 100644 --- a/src/google/protobuf/compiler/rust/BUILD.bazel +++ b/src/google/protobuf/compiler/rust/BUILD.bazel @@ -44,6 +44,7 @@ cc_library( ":oneof", "//src/google/protobuf:protobuf_nowkt", "//src/google/protobuf/compiler/cpp:names", + "//upb_generator:mangle", "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/log:absl_log", ], diff --git a/src/libprotoc.map b/src/libprotoc.map index 6f3a36e481e11..24a5f76a55936 100644 --- a/src/libprotoc.map +++ b/src/libprotoc.map @@ -3,6 +3,7 @@ extern "C++" { *google*; pb::*; + upb::*; }; scc_info_*; descriptor_table_*; From 84f8e4fbbc024e0e77d1093d19a79b5823853180 Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Tue, 2 Jan 2024 18:14:04 +0000 Subject: [PATCH 150/255] Auto-generate files after cl/595144470 --- src/file_lists.cmake | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/file_lists.cmake b/src/file_lists.cmake index 2abb20ffc6897..52c856d5da9da 100644 --- a/src/file_lists.cmake +++ b/src/file_lists.cmake @@ -399,6 +399,7 @@ set(libprotoc_srcs ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/subprocess.cc ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/versions.cc ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/zip_writer.cc + ${protobuf_SOURCE_DIR}/upb_generator/mangle.cc ) # @//pkg:protoc @@ -514,6 +515,7 @@ set(libprotoc_hdrs ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/subprocess.h ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/versions.h ${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/zip_writer.h + ${protobuf_SOURCE_DIR}/upb_generator/mangle.h ) # @//src/google/protobuf:well_known_type_protos From 569548cd82d75ef06b0a1add82cf518fdac4b0df Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Tue, 2 Jan 2024 10:31:12 -0800 Subject: [PATCH 151/255] Make Rust Conformance skip non-wire output test cases by using an overlay proto. PiperOrigin-RevId: 595152672 --- conformance/conformance_rust.rs | 32 +- .../conformance_rust_overlay_hack.proto | 10 + conformance/failure_list_rust_cc.txt | 627 ------------------ conformance/failure_list_rust_upb.txt | 627 ------------------ .../text_format_failure_list_rust_cc.txt | 17 - .../text_format_failure_list_rust_upb.txt | 17 - 6 files changed, 32 insertions(+), 1298 deletions(-) create mode 100644 conformance/conformance_rust_overlay_hack.proto diff --git a/conformance/conformance_rust.rs b/conformance/conformance_rust.rs index ee18da0760750..f593e362a96fe 100644 --- a/conformance/conformance_rust.rs +++ b/conformance/conformance_rust.rs @@ -5,6 +5,7 @@ // https://developers.google.com/open-source/licenses/bsd use conformance_proto::conformance::{ConformanceRequest, ConformanceResponse}; +use conformance_rust_overlay_hack_proto::conformance::ConformanceRequestRustOverlayHack; #[cfg(cpp_kernel)] use protobuf_cpp as kernel; @@ -39,13 +40,21 @@ fn read_little_endian_i32_from_stdin() -> Option { /// Returns None if we have hit an EOF that suggests the test suite is complete. /// Panics in any other case (e.g. an EOF in a place that would imply a /// programmer error in the conformance test suite). -fn read_request_from_stdin() -> Option { +fn read_request_from_stdin() -> Option<(ConformanceRequest, ConformanceRequestRustOverlayHack)> { let msg_len = read_little_endian_i32_from_stdin()?; let mut serialized = vec![0_u8; msg_len as usize]; io::stdin().read_exact(&mut serialized).unwrap(); let mut req = ConformanceRequest::new(); req.deserialize(&serialized).unwrap(); - Some(req) + + // TODO: b/318373255 - Since enum accessors aren't available yet, we parse an + // overlay with int32 field instead of an enum so that we can check if the + // requested output is binary or not. This will be deleted once enum + // accessors are supported. + let mut req_overlay_hack = ConformanceRequestRustOverlayHack::new(); + req_overlay_hack.deserialize(&serialized).unwrap(); + + Some((req, req_overlay_hack)) } fn write_response_to_stdout(resp: &ConformanceResponse) { @@ -57,16 +66,19 @@ fn write_response_to_stdout(resp: &ConformanceResponse) { handle.flush().unwrap(); } -fn do_test(req: &ConformanceRequest) -> ConformanceResponse { +fn do_test( + req: &ConformanceRequest, + req_overlay_hack: &ConformanceRequestRustOverlayHack, +) -> ConformanceResponse { let mut resp = ConformanceResponse::new(); let message_type = req.message_type(); - // Enums aren't supported yet (and not in scope for v0.6) so we can't perform - // this check yet. Note that this causes Rust to fail every test case that asks - // for output that isn't wire format. + // TODO: b/318373255 - Use the enum once its supported. // if req.requested_output_format() != WireFormat.PROTOBUF { - // resp.skipped_mut().set("only wire format output implemented") - // } + if req_overlay_hack.requested_output_format() != 1 { + resp.skipped_mut().set("only wire format output implemented"); + return resp; + } let bytes = match req.protobuf_payload_opt() { Unset(_) => { @@ -118,8 +130,8 @@ fn do_test(req: &ConformanceRequest) -> ConformanceResponse { fn main() { let mut total_runs = 0; - while let Some(req) = read_request_from_stdin() { - let resp = do_test(&req); + while let Some((req, req_overlay_hack)) = read_request_from_stdin() { + let resp = do_test(&req, &req_overlay_hack); write_response_to_stdout(&resp); total_runs += 1; } diff --git a/conformance/conformance_rust_overlay_hack.proto b/conformance/conformance_rust_overlay_hack.proto new file mode 100644 index 0000000000000..a897a16fc85fe --- /dev/null +++ b/conformance/conformance_rust_overlay_hack.proto @@ -0,0 +1,10 @@ +syntax = "proto3"; + +package conformance; + +// Temporary hack to allow the Rust conformance test to read the requested +// output format as an int32. This will be removed once enums accessors are +// supported. b/318373255 +message ConformanceRequestRustOverlayHack { + int32 requested_output_format = 3; +} diff --git a/conformance/failure_list_rust_cc.txt b/conformance/failure_list_rust_cc.txt index 2d3a235d0c592..e69de29bb2d1d 100644 --- a/conformance/failure_list_rust_cc.txt +++ b/conformance/failure_list_rust_cc.txt @@ -1,627 +0,0 @@ -# All JsonOutput tests currently fail and can't be skipped yet. b/285468558 - Recommended.Proto3.FieldMaskNumbersDontRoundTrip.JsonOutput - Recommended.Proto3.FieldMaskPathsDontRoundTrip.JsonOutput - Recommended.Proto3.FieldMaskTooManyUnderscore.JsonOutput - Recommended.Proto3.ProtobufInput.OneofZeroBool.JsonOutput - Recommended.Proto3.ProtobufInput.OneofZeroBytes.JsonOutput - Recommended.Proto3.ProtobufInput.OneofZeroDouble.JsonOutput - Recommended.Proto3.ProtobufInput.OneofZeroEnum.JsonOutput - Recommended.Proto3.ProtobufInput.OneofZeroFloat.JsonOutput - Recommended.Proto3.ProtobufInput.OneofZeroMessage.JsonOutput - Recommended.Proto3.ProtobufInput.OneofZeroMessageSetTwice.JsonOutput - Recommended.Proto3.ProtobufInput.OneofZeroString.JsonOutput - Recommended.Proto3.ProtobufInput.OneofZeroUint32.JsonOutput - Recommended.Proto3.ProtobufInput.OneofZeroUint64.JsonOutput - Recommended.Proto3.ValueRejectInfNumberValue.JsonOutput - Recommended.Proto3.ValueRejectNanNumberValue.JsonOutput - Required.Proto3.DurationProtoInputTooLarge.JsonOutput - Required.Proto3.DurationProtoInputTooSmall.JsonOutput - Required.Proto3.ProtobufInput.DoubleFieldNormalizeQuietNan.JsonOutput - Required.Proto3.ProtobufInput.DoubleFieldNormalizeSignalingNan.JsonOutput - Required.Proto3.ProtobufInput.FloatFieldNormalizeQuietNan.JsonOutput - Required.Proto3.ProtobufInput.FloatFieldNormalizeSignalingNan.JsonOutput - Required.Proto3.ProtobufInput.RepeatedScalarMessageMerge.JsonOutput - Required.Proto3.ProtobufInput.RepeatedScalarSelectsLast.BOOL.JsonOutput - Required.Proto3.ProtobufInput.RepeatedScalarSelectsLast.BYTES.JsonOutput - Required.Proto3.ProtobufInput.RepeatedScalarSelectsLast.DOUBLE.JsonOutput - Required.Proto3.ProtobufInput.RepeatedScalarSelectsLast.ENUM.JsonOutput - Required.Proto3.ProtobufInput.RepeatedScalarSelectsLast.FIXED32.JsonOutput - Required.Proto3.ProtobufInput.RepeatedScalarSelectsLast.FIXED64.JsonOutput - Required.Proto3.ProtobufInput.RepeatedScalarSelectsLast.FLOAT.JsonOutput - Required.Proto3.ProtobufInput.RepeatedScalarSelectsLast.INT32.JsonOutput - Required.Proto3.ProtobufInput.RepeatedScalarSelectsLast.INT64.JsonOutput - Required.Proto3.ProtobufInput.RepeatedScalarSelectsLast.SFIXED32.JsonOutput - Required.Proto3.ProtobufInput.RepeatedScalarSelectsLast.SFIXED64.JsonOutput - Required.Proto3.ProtobufInput.RepeatedScalarSelectsLast.SINT32.JsonOutput - Required.Proto3.ProtobufInput.RepeatedScalarSelectsLast.SINT64.JsonOutput - Required.Proto3.ProtobufInput.RepeatedScalarSelectsLast.STRING.JsonOutput - Required.Proto3.ProtobufInput.RepeatedScalarSelectsLast.UINT32.JsonOutput - Required.Proto3.ProtobufInput.RepeatedScalarSelectsLast.UINT64.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.BOOL.BOOL.Default.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.BOOL.BOOL.DuplicateKey.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.BOOL.BOOL.DuplicateKeyInMapEntry.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.BOOL.BOOL.DuplicateValueInMapEntry.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.BOOL.BOOL.MissingDefault.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.BOOL.BOOL.NonDefault.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.BOOL.BOOL.Unordered.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.FIXED32.FIXED32.Default.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.FIXED32.FIXED32.DuplicateKey.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.FIXED32.FIXED32.DuplicateKeyInMapEntry.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.FIXED32.FIXED32.DuplicateValueInMapEntry.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.FIXED32.FIXED32.MissingDefault.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.FIXED32.FIXED32.NonDefault.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.FIXED32.FIXED32.Unordered.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.FIXED64.FIXED64.Default.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.FIXED64.FIXED64.DuplicateKey.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.FIXED64.FIXED64.DuplicateKeyInMapEntry.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.FIXED64.FIXED64.DuplicateValueInMapEntry.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.FIXED64.FIXED64.MissingDefault.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.FIXED64.FIXED64.NonDefault.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.FIXED64.FIXED64.Unordered.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.INT32.DOUBLE.Default.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.INT32.DOUBLE.DuplicateKey.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.INT32.DOUBLE.DuplicateKeyInMapEntry.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.INT32.DOUBLE.DuplicateValueInMapEntry.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.INT32.DOUBLE.MissingDefault.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.INT32.DOUBLE.NonDefault.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.INT32.DOUBLE.Unordered.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.INT32.FLOAT.Default.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.INT32.FLOAT.DuplicateKey.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.INT32.FLOAT.DuplicateKeyInMapEntry.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.INT32.FLOAT.DuplicateValueInMapEntry.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.INT32.FLOAT.MissingDefault.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.INT32.FLOAT.NonDefault.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.INT32.FLOAT.Unordered.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.INT32.INT32.Default.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.INT32.INT32.DuplicateKey.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.INT32.INT32.DuplicateKeyInMapEntry.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.INT32.INT32.DuplicateValueInMapEntry.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.INT32.INT32.MissingDefault.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.INT32.INT32.NonDefault.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.INT32.INT32.Unordered.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.INT64.INT64.Default.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.INT64.INT64.DuplicateKey.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.INT64.INT64.DuplicateKeyInMapEntry.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.INT64.INT64.DuplicateValueInMapEntry.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.INT64.INT64.MissingDefault.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.INT64.INT64.NonDefault.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.INT64.INT64.Unordered.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.SFIXED32.SFIXED32.Default.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.SFIXED32.SFIXED32.DuplicateKey.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.SFIXED32.SFIXED32.DuplicateKeyInMapEntry.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.SFIXED32.SFIXED32.DuplicateValueInMapEntry.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.SFIXED32.SFIXED32.MissingDefault.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.SFIXED32.SFIXED32.NonDefault.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.SFIXED32.SFIXED32.Unordered.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.SFIXED64.SFIXED64.Default.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.SFIXED64.SFIXED64.DuplicateKey.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.SFIXED64.SFIXED64.DuplicateKeyInMapEntry.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.SFIXED64.SFIXED64.DuplicateValueInMapEntry.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.SFIXED64.SFIXED64.MissingDefault.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.SFIXED64.SFIXED64.NonDefault.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.SFIXED64.SFIXED64.Unordered.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.SINT32.SINT32.Default.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.SINT32.SINT32.DuplicateKey.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.SINT32.SINT32.DuplicateKeyInMapEntry.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.SINT32.SINT32.DuplicateValueInMapEntry.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.SINT32.SINT32.MissingDefault.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.SINT32.SINT32.NonDefault.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.SINT32.SINT32.Unordered.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.SINT64.SINT64.Default.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.SINT64.SINT64.DuplicateKey.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.SINT64.SINT64.DuplicateKeyInMapEntry.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.SINT64.SINT64.DuplicateValueInMapEntry.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.SINT64.SINT64.MissingDefault.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.SINT64.SINT64.NonDefault.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.SINT64.SINT64.Unordered.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.STRING.BYTES.Default.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.STRING.BYTES.DuplicateKey.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.STRING.BYTES.DuplicateKeyInMapEntry.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.STRING.BYTES.DuplicateValueInMapEntry.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.STRING.BYTES.MissingDefault.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.STRING.BYTES.NonDefault.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.STRING.BYTES.Unordered.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.STRING.ENUM.Default.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.STRING.ENUM.DuplicateKey.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.STRING.ENUM.DuplicateKeyInMapEntry.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.STRING.ENUM.DuplicateValueInMapEntry.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.STRING.ENUM.MissingDefault.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.STRING.ENUM.NonDefault.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.STRING.ENUM.Unordered.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.STRING.MESSAGE.Default.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.STRING.MESSAGE.DuplicateKey.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.STRING.MESSAGE.DuplicateKeyInMapEntry.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.STRING.MESSAGE.DuplicateValueInMapEntry.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.STRING.MESSAGE.MergeValue.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.STRING.MESSAGE.MissingDefault.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.STRING.MESSAGE.NonDefault.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.STRING.MESSAGE.Unordered.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.STRING.STRING.Default.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.STRING.STRING.DuplicateKey.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.STRING.STRING.DuplicateKeyInMapEntry.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.STRING.STRING.DuplicateValueInMapEntry.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.STRING.STRING.MissingDefault.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.STRING.STRING.NonDefault.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.STRING.STRING.Unordered.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.UINT32.UINT32.Default.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.UINT32.UINT32.DuplicateKey.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.UINT32.UINT32.DuplicateKeyInMapEntry.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.UINT32.UINT32.DuplicateValueInMapEntry.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.UINT32.UINT32.MissingDefault.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.UINT32.UINT32.NonDefault.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.UINT32.UINT32.Unordered.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.UINT64.UINT64.Default.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.UINT64.UINT64.DuplicateKey.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.UINT64.UINT64.DuplicateKeyInMapEntry.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.UINT64.UINT64.DuplicateValueInMapEntry.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.UINT64.UINT64.MissingDefault.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.UINT64.UINT64.NonDefault.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.UINT64.UINT64.Unordered.JsonOutput - Required.Proto3.ProtobufInput.ValidDataOneof.BOOL.DefaultValue.JsonOutput - Required.Proto3.ProtobufInput.ValidDataOneof.BOOL.MultipleValuesForDifferentField.JsonOutput - Required.Proto3.ProtobufInput.ValidDataOneof.BOOL.MultipleValuesForSameField.JsonOutput - Required.Proto3.ProtobufInput.ValidDataOneof.BOOL.NonDefaultValue.JsonOutput - Required.Proto3.ProtobufInput.ValidDataOneof.BYTES.DefaultValue.JsonOutput - Required.Proto3.ProtobufInput.ValidDataOneof.BYTES.MultipleValuesForDifferentField.JsonOutput - Required.Proto3.ProtobufInput.ValidDataOneof.BYTES.MultipleValuesForSameField.JsonOutput - Required.Proto3.ProtobufInput.ValidDataOneof.BYTES.NonDefaultValue.JsonOutput - Required.Proto3.ProtobufInput.ValidDataOneof.DOUBLE.DefaultValue.JsonOutput - Required.Proto3.ProtobufInput.ValidDataOneof.DOUBLE.MultipleValuesForDifferentField.JsonOutput - Required.Proto3.ProtobufInput.ValidDataOneof.DOUBLE.MultipleValuesForSameField.JsonOutput - Required.Proto3.ProtobufInput.ValidDataOneof.DOUBLE.NonDefaultValue.JsonOutput - Required.Proto3.ProtobufInput.ValidDataOneof.ENUM.DefaultValue.JsonOutput - Required.Proto3.ProtobufInput.ValidDataOneof.ENUM.MultipleValuesForDifferentField.JsonOutput - Required.Proto3.ProtobufInput.ValidDataOneof.ENUM.MultipleValuesForSameField.JsonOutput - Required.Proto3.ProtobufInput.ValidDataOneof.ENUM.NonDefaultValue.JsonOutput - Required.Proto3.ProtobufInput.ValidDataOneof.FLOAT.DefaultValue.JsonOutput - Required.Proto3.ProtobufInput.ValidDataOneof.FLOAT.MultipleValuesForDifferentField.JsonOutput - Required.Proto3.ProtobufInput.ValidDataOneof.FLOAT.MultipleValuesForSameField.JsonOutput - Required.Proto3.ProtobufInput.ValidDataOneof.FLOAT.NonDefaultValue.JsonOutput - Required.Proto3.ProtobufInput.ValidDataOneof.MESSAGE.DefaultValue.JsonOutput - Required.Proto3.ProtobufInput.ValidDataOneof.MESSAGE.Merge.JsonOutput - Required.Proto3.ProtobufInput.ValidDataOneof.MESSAGE.MultipleValuesForDifferentField.JsonOutput - Required.Proto3.ProtobufInput.ValidDataOneof.MESSAGE.MultipleValuesForSameField.JsonOutput - Required.Proto3.ProtobufInput.ValidDataOneof.MESSAGE.NonDefaultValue.JsonOutput - Required.Proto3.ProtobufInput.ValidDataOneof.STRING.DefaultValue.JsonOutput - Required.Proto3.ProtobufInput.ValidDataOneof.STRING.MultipleValuesForDifferentField.JsonOutput - Required.Proto3.ProtobufInput.ValidDataOneof.STRING.MultipleValuesForSameField.JsonOutput - Required.Proto3.ProtobufInput.ValidDataOneof.STRING.NonDefaultValue.JsonOutput - Required.Proto3.ProtobufInput.ValidDataOneof.UINT32.DefaultValue.JsonOutput - Required.Proto3.ProtobufInput.ValidDataOneof.UINT32.MultipleValuesForDifferentField.JsonOutput - Required.Proto3.ProtobufInput.ValidDataOneof.UINT32.MultipleValuesForSameField.JsonOutput - Required.Proto3.ProtobufInput.ValidDataOneof.UINT32.NonDefaultValue.JsonOutput - Required.Proto3.ProtobufInput.ValidDataOneof.UINT64.DefaultValue.JsonOutput - Required.Proto3.ProtobufInput.ValidDataOneof.UINT64.MultipleValuesForDifferentField.JsonOutput - Required.Proto3.ProtobufInput.ValidDataOneof.UINT64.MultipleValuesForSameField.JsonOutput - Required.Proto3.ProtobufInput.ValidDataOneof.UINT64.NonDefaultValue.JsonOutput - Required.Proto3.ProtobufInput.ValidDataRepeated.BOOL.PackedInput.JsonOutput - Required.Proto3.ProtobufInput.ValidDataRepeated.BOOL.UnpackedInput.JsonOutput - Required.Proto3.ProtobufInput.ValidDataRepeated.BYTES.JsonOutput - Required.Proto3.ProtobufInput.ValidDataRepeated.DOUBLE.PackedInput.JsonOutput - Required.Proto3.ProtobufInput.ValidDataRepeated.DOUBLE.UnpackedInput.JsonOutput - Required.Proto3.ProtobufInput.ValidDataRepeated.ENUM.PackedInput.JsonOutput - Required.Proto3.ProtobufInput.ValidDataRepeated.ENUM.UnpackedInput.JsonOutput - Required.Proto3.ProtobufInput.ValidDataRepeated.FIXED32.PackedInput.JsonOutput - Required.Proto3.ProtobufInput.ValidDataRepeated.FIXED32.UnpackedInput.JsonOutput - Required.Proto3.ProtobufInput.ValidDataRepeated.FIXED64.PackedInput.JsonOutput - Required.Proto3.ProtobufInput.ValidDataRepeated.FIXED64.UnpackedInput.JsonOutput - Required.Proto3.ProtobufInput.ValidDataRepeated.FLOAT.PackedInput.JsonOutput - Required.Proto3.ProtobufInput.ValidDataRepeated.FLOAT.UnpackedInput.JsonOutput - Required.Proto3.ProtobufInput.ValidDataRepeated.INT32.PackedInput.JsonOutput - Required.Proto3.ProtobufInput.ValidDataRepeated.INT32.UnpackedInput.JsonOutput - Required.Proto3.ProtobufInput.ValidDataRepeated.INT64.PackedInput.JsonOutput - Required.Proto3.ProtobufInput.ValidDataRepeated.INT64.UnpackedInput.JsonOutput - Required.Proto3.ProtobufInput.ValidDataRepeated.MESSAGE.JsonOutput - Required.Proto3.ProtobufInput.ValidDataRepeated.SFIXED32.PackedInput.JsonOutput - Required.Proto3.ProtobufInput.ValidDataRepeated.SFIXED32.UnpackedInput.JsonOutput - Required.Proto3.ProtobufInput.ValidDataRepeated.SFIXED64.PackedInput.JsonOutput - Required.Proto3.ProtobufInput.ValidDataRepeated.SFIXED64.UnpackedInput.JsonOutput - Required.Proto3.ProtobufInput.ValidDataRepeated.SINT32.PackedInput.JsonOutput - Required.Proto3.ProtobufInput.ValidDataRepeated.SINT32.UnpackedInput.JsonOutput - Required.Proto3.ProtobufInput.ValidDataRepeated.SINT64.PackedInput.JsonOutput - Required.Proto3.ProtobufInput.ValidDataRepeated.SINT64.UnpackedInput.JsonOutput - Required.Proto3.ProtobufInput.ValidDataRepeated.STRING.JsonOutput - Required.Proto3.ProtobufInput.ValidDataRepeated.UINT32.PackedInput.JsonOutput - Required.Proto3.ProtobufInput.ValidDataRepeated.UINT32.UnpackedInput.JsonOutput - Required.Proto3.ProtobufInput.ValidDataRepeated.UINT64.PackedInput.JsonOutput - Required.Proto3.ProtobufInput.ValidDataRepeated.UINT64.UnpackedInput.JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.BOOL[0].JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.BOOL[1].JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.BOOL[2].JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.BOOL[3].JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.BOOL[4].JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.BOOL[5].JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.BOOL[6].JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.BYTES[0].JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.BYTES[1].JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.BYTES[2].JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.BYTES[3].JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.DOUBLE[0].JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.DOUBLE[1].JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.DOUBLE[2].JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.DOUBLE[3].JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.ENUM[0].JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.ENUM[1].JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.ENUM[2].JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.ENUM[3].JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.ENUM[4].JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.ENUM[5].JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.FIXED32[0].JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.FIXED32[1].JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.FIXED32[2].JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.FIXED64[0].JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.FIXED64[1].JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.FIXED64[2].JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.FLOAT[0].JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.FLOAT[1].JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.FLOAT[2].JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.FLOAT[3].JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.FLOAT[4].JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.INT32[0].JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.INT32[1].JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.INT32[2].JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.INT32[3].JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.INT32[4].JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.INT32[5].JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.INT32[6].JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.INT32[7].JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.INT32[8].JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.INT32[9].JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.INT64[0].JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.INT64[1].JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.INT64[2].JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.INT64[3].JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.MESSAGE[0].JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.MESSAGE[1].JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.SFIXED32[0].JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.SFIXED32[1].JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.SFIXED32[2].JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.SFIXED32[3].JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.SFIXED64[0].JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.SFIXED64[1].JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.SFIXED64[2].JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.SFIXED64[3].JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.SINT32[0].JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.SINT32[1].JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.SINT32[2].JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.SINT32[3].JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.SINT32[4].JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.SINT64[0].JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.SINT64[1].JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.SINT64[2].JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.SINT64[3].JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.STRING[0].JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.STRING[1].JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.STRING[2].JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.STRING[3].JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.STRING[4].JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.STRING[5].JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.STRING[6].JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.UINT32[0].JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.UINT32[1].JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.UINT32[2].JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.UINT32[3].JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.UINT32[4].JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.UINT32[5].JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.UINT32[6].JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.UINT32[7].JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.UINT32[8].JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.UINT32[9].JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.UINT64[0].JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.UINT64[1].JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.UINT64[2].JsonOutput - Required.Proto3.TimestampProtoInputTooLarge.JsonOutput - Required.Proto3.TimestampProtoInputTooSmall.JsonOutput - Recommended.Editions_Proto3.FieldMaskNumbersDontRoundTrip.JsonOutput - Recommended.Editions_Proto3.FieldMaskPathsDontRoundTrip.JsonOutput - Recommended.Editions_Proto3.FieldMaskTooManyUnderscore.JsonOutput - Recommended.Editions_Proto3.ProtobufInput.OneofZeroBool.JsonOutput - Recommended.Editions_Proto3.ProtobufInput.OneofZeroBytes.JsonOutput - Recommended.Editions_Proto3.ProtobufInput.OneofZeroDouble.JsonOutput - Recommended.Editions_Proto3.ProtobufInput.OneofZeroEnum.JsonOutput - Recommended.Editions_Proto3.ProtobufInput.OneofZeroFloat.JsonOutput - Recommended.Editions_Proto3.ProtobufInput.OneofZeroMessage.JsonOutput - Recommended.Editions_Proto3.ProtobufInput.OneofZeroMessageSetTwice.JsonOutput - Recommended.Editions_Proto3.ProtobufInput.OneofZeroString.JsonOutput - Recommended.Editions_Proto3.ProtobufInput.OneofZeroUint32.JsonOutput - Recommended.Editions_Proto3.ProtobufInput.OneofZeroUint64.JsonOutput - Recommended.Editions_Proto3.ValueRejectInfNumberValue.JsonOutput - Recommended.Editions_Proto3.ValueRejectNanNumberValue.JsonOutput - Required.Editions_Proto3.DurationProtoInputTooLarge.JsonOutput - Required.Editions_Proto3.DurationProtoInputTooSmall.JsonOutput - Required.Editions_Proto3.ProtobufInput.DoubleFieldNormalizeQuietNan.JsonOutput - Required.Editions_Proto3.ProtobufInput.DoubleFieldNormalizeSignalingNan.JsonOutput - Required.Editions_Proto3.ProtobufInput.FloatFieldNormalizeQuietNan.JsonOutput - Required.Editions_Proto3.ProtobufInput.FloatFieldNormalizeSignalingNan.JsonOutput - Required.Editions_Proto3.ProtobufInput.RepeatedScalarMessageMerge.JsonOutput - Required.Editions_Proto3.ProtobufInput.RepeatedScalarSelectsLast.BOOL.JsonOutput - Required.Editions_Proto3.ProtobufInput.RepeatedScalarSelectsLast.BYTES.JsonOutput - Required.Editions_Proto3.ProtobufInput.RepeatedScalarSelectsLast.DOUBLE.JsonOutput - Required.Editions_Proto3.ProtobufInput.RepeatedScalarSelectsLast.ENUM.JsonOutput - Required.Editions_Proto3.ProtobufInput.RepeatedScalarSelectsLast.FIXED32.JsonOutput - Required.Editions_Proto3.ProtobufInput.RepeatedScalarSelectsLast.FIXED64.JsonOutput - Required.Editions_Proto3.ProtobufInput.RepeatedScalarSelectsLast.FLOAT.JsonOutput - Required.Editions_Proto3.ProtobufInput.RepeatedScalarSelectsLast.INT32.JsonOutput - Required.Editions_Proto3.ProtobufInput.RepeatedScalarSelectsLast.INT64.JsonOutput - Required.Editions_Proto3.ProtobufInput.RepeatedScalarSelectsLast.SFIXED32.JsonOutput - Required.Editions_Proto3.ProtobufInput.RepeatedScalarSelectsLast.SFIXED64.JsonOutput - Required.Editions_Proto3.ProtobufInput.RepeatedScalarSelectsLast.SINT32.JsonOutput - Required.Editions_Proto3.ProtobufInput.RepeatedScalarSelectsLast.SINT64.JsonOutput - Required.Editions_Proto3.ProtobufInput.RepeatedScalarSelectsLast.STRING.JsonOutput - Required.Editions_Proto3.ProtobufInput.RepeatedScalarSelectsLast.UINT32.JsonOutput - Required.Editions_Proto3.ProtobufInput.RepeatedScalarSelectsLast.UINT64.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.BOOL.BOOL.Default.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.BOOL.BOOL.DuplicateKey.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.BOOL.BOOL.DuplicateKeyInMapEntry.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.BOOL.BOOL.DuplicateValueInMapEntry.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.BOOL.BOOL.MissingDefault.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.BOOL.BOOL.NonDefault.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.BOOL.BOOL.Unordered.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.FIXED32.FIXED32.Default.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.FIXED32.FIXED32.DuplicateKey.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.FIXED32.FIXED32.DuplicateKeyInMapEntry.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.FIXED32.FIXED32.DuplicateValueInMapEntry.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.FIXED32.FIXED32.MissingDefault.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.FIXED32.FIXED32.NonDefault.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.FIXED32.FIXED32.Unordered.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.FIXED64.FIXED64.Default.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.FIXED64.FIXED64.DuplicateKey.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.FIXED64.FIXED64.DuplicateKeyInMapEntry.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.FIXED64.FIXED64.DuplicateValueInMapEntry.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.FIXED64.FIXED64.MissingDefault.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.FIXED64.FIXED64.NonDefault.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.FIXED64.FIXED64.Unordered.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.INT32.DOUBLE.Default.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.INT32.DOUBLE.DuplicateKey.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.INT32.DOUBLE.DuplicateKeyInMapEntry.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.INT32.DOUBLE.DuplicateValueInMapEntry.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.INT32.DOUBLE.MissingDefault.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.INT32.DOUBLE.NonDefault.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.INT32.DOUBLE.Unordered.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.INT32.FLOAT.Default.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.INT32.FLOAT.DuplicateKey.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.INT32.FLOAT.DuplicateKeyInMapEntry.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.INT32.FLOAT.DuplicateValueInMapEntry.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.INT32.FLOAT.MissingDefault.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.INT32.FLOAT.NonDefault.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.INT32.FLOAT.Unordered.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.INT32.INT32.Default.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.INT32.INT32.DuplicateKey.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.INT32.INT32.DuplicateKeyInMapEntry.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.INT32.INT32.DuplicateValueInMapEntry.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.INT32.INT32.MissingDefault.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.INT32.INT32.NonDefault.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.INT32.INT32.Unordered.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.INT64.INT64.Default.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.INT64.INT64.DuplicateKey.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.INT64.INT64.DuplicateKeyInMapEntry.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.INT64.INT64.DuplicateValueInMapEntry.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.INT64.INT64.MissingDefault.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.INT64.INT64.NonDefault.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.INT64.INT64.Unordered.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.SFIXED32.SFIXED32.Default.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.SFIXED32.SFIXED32.DuplicateKey.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.SFIXED32.SFIXED32.DuplicateKeyInMapEntry.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.SFIXED32.SFIXED32.DuplicateValueInMapEntry.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.SFIXED32.SFIXED32.MissingDefault.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.SFIXED32.SFIXED32.NonDefault.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.SFIXED32.SFIXED32.Unordered.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.SFIXED64.SFIXED64.Default.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.SFIXED64.SFIXED64.DuplicateKey.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.SFIXED64.SFIXED64.DuplicateKeyInMapEntry.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.SFIXED64.SFIXED64.DuplicateValueInMapEntry.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.SFIXED64.SFIXED64.MissingDefault.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.SFIXED64.SFIXED64.NonDefault.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.SFIXED64.SFIXED64.Unordered.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.SINT32.SINT32.Default.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.SINT32.SINT32.DuplicateKey.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.SINT32.SINT32.DuplicateKeyInMapEntry.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.SINT32.SINT32.DuplicateValueInMapEntry.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.SINT32.SINT32.MissingDefault.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.SINT32.SINT32.NonDefault.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.SINT32.SINT32.Unordered.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.SINT64.SINT64.Default.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.SINT64.SINT64.DuplicateKey.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.SINT64.SINT64.DuplicateKeyInMapEntry.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.SINT64.SINT64.DuplicateValueInMapEntry.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.SINT64.SINT64.MissingDefault.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.SINT64.SINT64.NonDefault.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.SINT64.SINT64.Unordered.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.STRING.BYTES.Default.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.STRING.BYTES.DuplicateKey.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.STRING.BYTES.DuplicateKeyInMapEntry.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.STRING.BYTES.DuplicateValueInMapEntry.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.STRING.BYTES.MissingDefault.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.STRING.BYTES.NonDefault.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.STRING.BYTES.Unordered.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.STRING.ENUM.Default.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.STRING.ENUM.DuplicateKey.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.STRING.ENUM.DuplicateKeyInMapEntry.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.STRING.ENUM.DuplicateValueInMapEntry.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.STRING.ENUM.MissingDefault.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.STRING.ENUM.NonDefault.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.STRING.ENUM.Unordered.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.STRING.MESSAGE.Default.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.STRING.MESSAGE.DuplicateKey.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.STRING.MESSAGE.DuplicateKeyInMapEntry.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.STRING.MESSAGE.DuplicateValueInMapEntry.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.STRING.MESSAGE.MergeValue.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.STRING.MESSAGE.MissingDefault.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.STRING.MESSAGE.NonDefault.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.STRING.MESSAGE.Unordered.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.STRING.STRING.Default.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.STRING.STRING.DuplicateKey.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.STRING.STRING.DuplicateKeyInMapEntry.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.STRING.STRING.DuplicateValueInMapEntry.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.STRING.STRING.MissingDefault.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.STRING.STRING.NonDefault.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.STRING.STRING.Unordered.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.UINT32.UINT32.Default.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.UINT32.UINT32.DuplicateKey.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.UINT32.UINT32.DuplicateKeyInMapEntry.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.UINT32.UINT32.DuplicateValueInMapEntry.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.UINT32.UINT32.MissingDefault.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.UINT32.UINT32.NonDefault.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.UINT32.UINT32.Unordered.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.UINT64.UINT64.Default.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.UINT64.UINT64.DuplicateKey.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.UINT64.UINT64.DuplicateKeyInMapEntry.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.UINT64.UINT64.DuplicateValueInMapEntry.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.UINT64.UINT64.MissingDefault.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.UINT64.UINT64.NonDefault.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.UINT64.UINT64.Unordered.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataOneof.BOOL.DefaultValue.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataOneof.BOOL.MultipleValuesForDifferentField.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataOneof.BOOL.MultipleValuesForSameField.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataOneof.BOOL.NonDefaultValue.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataOneof.BYTES.DefaultValue.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataOneof.BYTES.MultipleValuesForDifferentField.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataOneof.BYTES.MultipleValuesForSameField.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataOneof.BYTES.NonDefaultValue.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataOneof.DOUBLE.DefaultValue.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataOneof.DOUBLE.MultipleValuesForDifferentField.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataOneof.DOUBLE.MultipleValuesForSameField.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataOneof.DOUBLE.NonDefaultValue.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataOneof.ENUM.DefaultValue.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataOneof.ENUM.MultipleValuesForDifferentField.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataOneof.ENUM.MultipleValuesForSameField.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataOneof.ENUM.NonDefaultValue.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataOneof.FLOAT.DefaultValue.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataOneof.FLOAT.MultipleValuesForDifferentField.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataOneof.FLOAT.MultipleValuesForSameField.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataOneof.FLOAT.NonDefaultValue.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataOneof.MESSAGE.DefaultValue.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataOneof.MESSAGE.Merge.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataOneof.MESSAGE.MultipleValuesForDifferentField.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataOneof.MESSAGE.MultipleValuesForSameField.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataOneof.MESSAGE.NonDefaultValue.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataOneof.STRING.DefaultValue.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataOneof.STRING.MultipleValuesForDifferentField.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataOneof.STRING.MultipleValuesForSameField.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataOneof.STRING.NonDefaultValue.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataOneof.UINT32.DefaultValue.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataOneof.UINT32.MultipleValuesForDifferentField.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataOneof.UINT32.MultipleValuesForSameField.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataOneof.UINT32.NonDefaultValue.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataOneof.UINT64.DefaultValue.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataOneof.UINT64.MultipleValuesForDifferentField.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataOneof.UINT64.MultipleValuesForSameField.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataOneof.UINT64.NonDefaultValue.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataRepeated.BOOL.PackedInput.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataRepeated.BOOL.UnpackedInput.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataRepeated.BYTES.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataRepeated.DOUBLE.PackedInput.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataRepeated.DOUBLE.UnpackedInput.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataRepeated.ENUM.PackedInput.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataRepeated.ENUM.UnpackedInput.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataRepeated.FIXED32.PackedInput.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataRepeated.FIXED32.UnpackedInput.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataRepeated.FIXED64.PackedInput.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataRepeated.FIXED64.UnpackedInput.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataRepeated.FLOAT.PackedInput.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataRepeated.FLOAT.UnpackedInput.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataRepeated.INT32.PackedInput.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataRepeated.INT32.UnpackedInput.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataRepeated.INT64.PackedInput.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataRepeated.INT64.UnpackedInput.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataRepeated.MESSAGE.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataRepeated.SFIXED32.PackedInput.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataRepeated.SFIXED32.UnpackedInput.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataRepeated.SFIXED64.PackedInput.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataRepeated.SFIXED64.UnpackedInput.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataRepeated.SINT32.PackedInput.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataRepeated.SINT32.UnpackedInput.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataRepeated.SINT64.PackedInput.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataRepeated.SINT64.UnpackedInput.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataRepeated.STRING.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataRepeated.UINT32.PackedInput.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataRepeated.UINT32.UnpackedInput.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataRepeated.UINT64.PackedInput.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataRepeated.UINT64.UnpackedInput.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.BOOL[0].JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.BOOL[1].JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.BOOL[2].JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.BOOL[3].JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.BOOL[4].JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.BOOL[5].JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.BOOL[6].JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.BYTES[0].JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.BYTES[1].JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.BYTES[2].JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.BYTES[3].JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.DOUBLE[0].JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.DOUBLE[1].JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.DOUBLE[2].JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.DOUBLE[3].JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.ENUM[0].JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.ENUM[1].JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.ENUM[2].JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.ENUM[3].JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.ENUM[4].JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.ENUM[5].JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.FIXED32[0].JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.FIXED32[1].JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.FIXED32[2].JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.FIXED64[0].JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.FIXED64[1].JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.FIXED64[2].JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.FLOAT[0].JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.FLOAT[1].JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.FLOAT[2].JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.FLOAT[3].JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.FLOAT[4].JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.INT32[0].JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.INT32[1].JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.INT32[2].JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.INT32[3].JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.INT32[4].JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.INT32[5].JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.INT32[6].JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.INT32[7].JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.INT32[8].JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.INT32[9].JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.INT64[0].JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.INT64[1].JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.INT64[2].JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.INT64[3].JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.MESSAGE[0].JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.MESSAGE[1].JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.SFIXED32[0].JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.SFIXED32[1].JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.SFIXED32[2].JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.SFIXED32[3].JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.SFIXED64[0].JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.SFIXED64[1].JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.SFIXED64[2].JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.SFIXED64[3].JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.SINT32[0].JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.SINT32[1].JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.SINT32[2].JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.SINT32[3].JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.SINT32[4].JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.SINT64[0].JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.SINT64[1].JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.SINT64[2].JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.SINT64[3].JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.STRING[0].JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.STRING[1].JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.STRING[2].JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.STRING[3].JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.STRING[4].JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.STRING[5].JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.STRING[6].JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.UINT32[0].JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.UINT32[1].JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.UINT32[2].JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.UINT32[3].JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.UINT32[4].JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.UINT32[5].JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.UINT32[6].JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.UINT32[7].JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.UINT32[8].JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.UINT32[9].JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.UINT64[0].JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.UINT64[1].JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.UINT64[2].JsonOutput - Required.Editions_Proto3.TimestampProtoInputTooLarge.JsonOutput - Required.Editions_Proto3.TimestampProtoInputTooSmall.JsonOutput diff --git a/conformance/failure_list_rust_upb.txt b/conformance/failure_list_rust_upb.txt index 2d3a235d0c592..e69de29bb2d1d 100644 --- a/conformance/failure_list_rust_upb.txt +++ b/conformance/failure_list_rust_upb.txt @@ -1,627 +0,0 @@ -# All JsonOutput tests currently fail and can't be skipped yet. b/285468558 - Recommended.Proto3.FieldMaskNumbersDontRoundTrip.JsonOutput - Recommended.Proto3.FieldMaskPathsDontRoundTrip.JsonOutput - Recommended.Proto3.FieldMaskTooManyUnderscore.JsonOutput - Recommended.Proto3.ProtobufInput.OneofZeroBool.JsonOutput - Recommended.Proto3.ProtobufInput.OneofZeroBytes.JsonOutput - Recommended.Proto3.ProtobufInput.OneofZeroDouble.JsonOutput - Recommended.Proto3.ProtobufInput.OneofZeroEnum.JsonOutput - Recommended.Proto3.ProtobufInput.OneofZeroFloat.JsonOutput - Recommended.Proto3.ProtobufInput.OneofZeroMessage.JsonOutput - Recommended.Proto3.ProtobufInput.OneofZeroMessageSetTwice.JsonOutput - Recommended.Proto3.ProtobufInput.OneofZeroString.JsonOutput - Recommended.Proto3.ProtobufInput.OneofZeroUint32.JsonOutput - Recommended.Proto3.ProtobufInput.OneofZeroUint64.JsonOutput - Recommended.Proto3.ValueRejectInfNumberValue.JsonOutput - Recommended.Proto3.ValueRejectNanNumberValue.JsonOutput - Required.Proto3.DurationProtoInputTooLarge.JsonOutput - Required.Proto3.DurationProtoInputTooSmall.JsonOutput - Required.Proto3.ProtobufInput.DoubleFieldNormalizeQuietNan.JsonOutput - Required.Proto3.ProtobufInput.DoubleFieldNormalizeSignalingNan.JsonOutput - Required.Proto3.ProtobufInput.FloatFieldNormalizeQuietNan.JsonOutput - Required.Proto3.ProtobufInput.FloatFieldNormalizeSignalingNan.JsonOutput - Required.Proto3.ProtobufInput.RepeatedScalarMessageMerge.JsonOutput - Required.Proto3.ProtobufInput.RepeatedScalarSelectsLast.BOOL.JsonOutput - Required.Proto3.ProtobufInput.RepeatedScalarSelectsLast.BYTES.JsonOutput - Required.Proto3.ProtobufInput.RepeatedScalarSelectsLast.DOUBLE.JsonOutput - Required.Proto3.ProtobufInput.RepeatedScalarSelectsLast.ENUM.JsonOutput - Required.Proto3.ProtobufInput.RepeatedScalarSelectsLast.FIXED32.JsonOutput - Required.Proto3.ProtobufInput.RepeatedScalarSelectsLast.FIXED64.JsonOutput - Required.Proto3.ProtobufInput.RepeatedScalarSelectsLast.FLOAT.JsonOutput - Required.Proto3.ProtobufInput.RepeatedScalarSelectsLast.INT32.JsonOutput - Required.Proto3.ProtobufInput.RepeatedScalarSelectsLast.INT64.JsonOutput - Required.Proto3.ProtobufInput.RepeatedScalarSelectsLast.SFIXED32.JsonOutput - Required.Proto3.ProtobufInput.RepeatedScalarSelectsLast.SFIXED64.JsonOutput - Required.Proto3.ProtobufInput.RepeatedScalarSelectsLast.SINT32.JsonOutput - Required.Proto3.ProtobufInput.RepeatedScalarSelectsLast.SINT64.JsonOutput - Required.Proto3.ProtobufInput.RepeatedScalarSelectsLast.STRING.JsonOutput - Required.Proto3.ProtobufInput.RepeatedScalarSelectsLast.UINT32.JsonOutput - Required.Proto3.ProtobufInput.RepeatedScalarSelectsLast.UINT64.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.BOOL.BOOL.Default.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.BOOL.BOOL.DuplicateKey.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.BOOL.BOOL.DuplicateKeyInMapEntry.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.BOOL.BOOL.DuplicateValueInMapEntry.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.BOOL.BOOL.MissingDefault.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.BOOL.BOOL.NonDefault.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.BOOL.BOOL.Unordered.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.FIXED32.FIXED32.Default.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.FIXED32.FIXED32.DuplicateKey.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.FIXED32.FIXED32.DuplicateKeyInMapEntry.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.FIXED32.FIXED32.DuplicateValueInMapEntry.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.FIXED32.FIXED32.MissingDefault.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.FIXED32.FIXED32.NonDefault.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.FIXED32.FIXED32.Unordered.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.FIXED64.FIXED64.Default.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.FIXED64.FIXED64.DuplicateKey.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.FIXED64.FIXED64.DuplicateKeyInMapEntry.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.FIXED64.FIXED64.DuplicateValueInMapEntry.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.FIXED64.FIXED64.MissingDefault.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.FIXED64.FIXED64.NonDefault.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.FIXED64.FIXED64.Unordered.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.INT32.DOUBLE.Default.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.INT32.DOUBLE.DuplicateKey.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.INT32.DOUBLE.DuplicateKeyInMapEntry.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.INT32.DOUBLE.DuplicateValueInMapEntry.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.INT32.DOUBLE.MissingDefault.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.INT32.DOUBLE.NonDefault.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.INT32.DOUBLE.Unordered.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.INT32.FLOAT.Default.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.INT32.FLOAT.DuplicateKey.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.INT32.FLOAT.DuplicateKeyInMapEntry.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.INT32.FLOAT.DuplicateValueInMapEntry.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.INT32.FLOAT.MissingDefault.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.INT32.FLOAT.NonDefault.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.INT32.FLOAT.Unordered.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.INT32.INT32.Default.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.INT32.INT32.DuplicateKey.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.INT32.INT32.DuplicateKeyInMapEntry.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.INT32.INT32.DuplicateValueInMapEntry.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.INT32.INT32.MissingDefault.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.INT32.INT32.NonDefault.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.INT32.INT32.Unordered.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.INT64.INT64.Default.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.INT64.INT64.DuplicateKey.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.INT64.INT64.DuplicateKeyInMapEntry.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.INT64.INT64.DuplicateValueInMapEntry.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.INT64.INT64.MissingDefault.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.INT64.INT64.NonDefault.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.INT64.INT64.Unordered.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.SFIXED32.SFIXED32.Default.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.SFIXED32.SFIXED32.DuplicateKey.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.SFIXED32.SFIXED32.DuplicateKeyInMapEntry.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.SFIXED32.SFIXED32.DuplicateValueInMapEntry.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.SFIXED32.SFIXED32.MissingDefault.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.SFIXED32.SFIXED32.NonDefault.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.SFIXED32.SFIXED32.Unordered.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.SFIXED64.SFIXED64.Default.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.SFIXED64.SFIXED64.DuplicateKey.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.SFIXED64.SFIXED64.DuplicateKeyInMapEntry.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.SFIXED64.SFIXED64.DuplicateValueInMapEntry.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.SFIXED64.SFIXED64.MissingDefault.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.SFIXED64.SFIXED64.NonDefault.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.SFIXED64.SFIXED64.Unordered.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.SINT32.SINT32.Default.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.SINT32.SINT32.DuplicateKey.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.SINT32.SINT32.DuplicateKeyInMapEntry.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.SINT32.SINT32.DuplicateValueInMapEntry.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.SINT32.SINT32.MissingDefault.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.SINT32.SINT32.NonDefault.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.SINT32.SINT32.Unordered.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.SINT64.SINT64.Default.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.SINT64.SINT64.DuplicateKey.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.SINT64.SINT64.DuplicateKeyInMapEntry.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.SINT64.SINT64.DuplicateValueInMapEntry.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.SINT64.SINT64.MissingDefault.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.SINT64.SINT64.NonDefault.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.SINT64.SINT64.Unordered.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.STRING.BYTES.Default.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.STRING.BYTES.DuplicateKey.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.STRING.BYTES.DuplicateKeyInMapEntry.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.STRING.BYTES.DuplicateValueInMapEntry.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.STRING.BYTES.MissingDefault.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.STRING.BYTES.NonDefault.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.STRING.BYTES.Unordered.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.STRING.ENUM.Default.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.STRING.ENUM.DuplicateKey.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.STRING.ENUM.DuplicateKeyInMapEntry.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.STRING.ENUM.DuplicateValueInMapEntry.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.STRING.ENUM.MissingDefault.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.STRING.ENUM.NonDefault.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.STRING.ENUM.Unordered.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.STRING.MESSAGE.Default.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.STRING.MESSAGE.DuplicateKey.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.STRING.MESSAGE.DuplicateKeyInMapEntry.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.STRING.MESSAGE.DuplicateValueInMapEntry.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.STRING.MESSAGE.MergeValue.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.STRING.MESSAGE.MissingDefault.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.STRING.MESSAGE.NonDefault.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.STRING.MESSAGE.Unordered.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.STRING.STRING.Default.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.STRING.STRING.DuplicateKey.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.STRING.STRING.DuplicateKeyInMapEntry.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.STRING.STRING.DuplicateValueInMapEntry.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.STRING.STRING.MissingDefault.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.STRING.STRING.NonDefault.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.STRING.STRING.Unordered.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.UINT32.UINT32.Default.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.UINT32.UINT32.DuplicateKey.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.UINT32.UINT32.DuplicateKeyInMapEntry.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.UINT32.UINT32.DuplicateValueInMapEntry.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.UINT32.UINT32.MissingDefault.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.UINT32.UINT32.NonDefault.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.UINT32.UINT32.Unordered.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.UINT64.UINT64.Default.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.UINT64.UINT64.DuplicateKey.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.UINT64.UINT64.DuplicateKeyInMapEntry.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.UINT64.UINT64.DuplicateValueInMapEntry.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.UINT64.UINT64.MissingDefault.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.UINT64.UINT64.NonDefault.JsonOutput - Required.Proto3.ProtobufInput.ValidDataMap.UINT64.UINT64.Unordered.JsonOutput - Required.Proto3.ProtobufInput.ValidDataOneof.BOOL.DefaultValue.JsonOutput - Required.Proto3.ProtobufInput.ValidDataOneof.BOOL.MultipleValuesForDifferentField.JsonOutput - Required.Proto3.ProtobufInput.ValidDataOneof.BOOL.MultipleValuesForSameField.JsonOutput - Required.Proto3.ProtobufInput.ValidDataOneof.BOOL.NonDefaultValue.JsonOutput - Required.Proto3.ProtobufInput.ValidDataOneof.BYTES.DefaultValue.JsonOutput - Required.Proto3.ProtobufInput.ValidDataOneof.BYTES.MultipleValuesForDifferentField.JsonOutput - Required.Proto3.ProtobufInput.ValidDataOneof.BYTES.MultipleValuesForSameField.JsonOutput - Required.Proto3.ProtobufInput.ValidDataOneof.BYTES.NonDefaultValue.JsonOutput - Required.Proto3.ProtobufInput.ValidDataOneof.DOUBLE.DefaultValue.JsonOutput - Required.Proto3.ProtobufInput.ValidDataOneof.DOUBLE.MultipleValuesForDifferentField.JsonOutput - Required.Proto3.ProtobufInput.ValidDataOneof.DOUBLE.MultipleValuesForSameField.JsonOutput - Required.Proto3.ProtobufInput.ValidDataOneof.DOUBLE.NonDefaultValue.JsonOutput - Required.Proto3.ProtobufInput.ValidDataOneof.ENUM.DefaultValue.JsonOutput - Required.Proto3.ProtobufInput.ValidDataOneof.ENUM.MultipleValuesForDifferentField.JsonOutput - Required.Proto3.ProtobufInput.ValidDataOneof.ENUM.MultipleValuesForSameField.JsonOutput - Required.Proto3.ProtobufInput.ValidDataOneof.ENUM.NonDefaultValue.JsonOutput - Required.Proto3.ProtobufInput.ValidDataOneof.FLOAT.DefaultValue.JsonOutput - Required.Proto3.ProtobufInput.ValidDataOneof.FLOAT.MultipleValuesForDifferentField.JsonOutput - Required.Proto3.ProtobufInput.ValidDataOneof.FLOAT.MultipleValuesForSameField.JsonOutput - Required.Proto3.ProtobufInput.ValidDataOneof.FLOAT.NonDefaultValue.JsonOutput - Required.Proto3.ProtobufInput.ValidDataOneof.MESSAGE.DefaultValue.JsonOutput - Required.Proto3.ProtobufInput.ValidDataOneof.MESSAGE.Merge.JsonOutput - Required.Proto3.ProtobufInput.ValidDataOneof.MESSAGE.MultipleValuesForDifferentField.JsonOutput - Required.Proto3.ProtobufInput.ValidDataOneof.MESSAGE.MultipleValuesForSameField.JsonOutput - Required.Proto3.ProtobufInput.ValidDataOneof.MESSAGE.NonDefaultValue.JsonOutput - Required.Proto3.ProtobufInput.ValidDataOneof.STRING.DefaultValue.JsonOutput - Required.Proto3.ProtobufInput.ValidDataOneof.STRING.MultipleValuesForDifferentField.JsonOutput - Required.Proto3.ProtobufInput.ValidDataOneof.STRING.MultipleValuesForSameField.JsonOutput - Required.Proto3.ProtobufInput.ValidDataOneof.STRING.NonDefaultValue.JsonOutput - Required.Proto3.ProtobufInput.ValidDataOneof.UINT32.DefaultValue.JsonOutput - Required.Proto3.ProtobufInput.ValidDataOneof.UINT32.MultipleValuesForDifferentField.JsonOutput - Required.Proto3.ProtobufInput.ValidDataOneof.UINT32.MultipleValuesForSameField.JsonOutput - Required.Proto3.ProtobufInput.ValidDataOneof.UINT32.NonDefaultValue.JsonOutput - Required.Proto3.ProtobufInput.ValidDataOneof.UINT64.DefaultValue.JsonOutput - Required.Proto3.ProtobufInput.ValidDataOneof.UINT64.MultipleValuesForDifferentField.JsonOutput - Required.Proto3.ProtobufInput.ValidDataOneof.UINT64.MultipleValuesForSameField.JsonOutput - Required.Proto3.ProtobufInput.ValidDataOneof.UINT64.NonDefaultValue.JsonOutput - Required.Proto3.ProtobufInput.ValidDataRepeated.BOOL.PackedInput.JsonOutput - Required.Proto3.ProtobufInput.ValidDataRepeated.BOOL.UnpackedInput.JsonOutput - Required.Proto3.ProtobufInput.ValidDataRepeated.BYTES.JsonOutput - Required.Proto3.ProtobufInput.ValidDataRepeated.DOUBLE.PackedInput.JsonOutput - Required.Proto3.ProtobufInput.ValidDataRepeated.DOUBLE.UnpackedInput.JsonOutput - Required.Proto3.ProtobufInput.ValidDataRepeated.ENUM.PackedInput.JsonOutput - Required.Proto3.ProtobufInput.ValidDataRepeated.ENUM.UnpackedInput.JsonOutput - Required.Proto3.ProtobufInput.ValidDataRepeated.FIXED32.PackedInput.JsonOutput - Required.Proto3.ProtobufInput.ValidDataRepeated.FIXED32.UnpackedInput.JsonOutput - Required.Proto3.ProtobufInput.ValidDataRepeated.FIXED64.PackedInput.JsonOutput - Required.Proto3.ProtobufInput.ValidDataRepeated.FIXED64.UnpackedInput.JsonOutput - Required.Proto3.ProtobufInput.ValidDataRepeated.FLOAT.PackedInput.JsonOutput - Required.Proto3.ProtobufInput.ValidDataRepeated.FLOAT.UnpackedInput.JsonOutput - Required.Proto3.ProtobufInput.ValidDataRepeated.INT32.PackedInput.JsonOutput - Required.Proto3.ProtobufInput.ValidDataRepeated.INT32.UnpackedInput.JsonOutput - Required.Proto3.ProtobufInput.ValidDataRepeated.INT64.PackedInput.JsonOutput - Required.Proto3.ProtobufInput.ValidDataRepeated.INT64.UnpackedInput.JsonOutput - Required.Proto3.ProtobufInput.ValidDataRepeated.MESSAGE.JsonOutput - Required.Proto3.ProtobufInput.ValidDataRepeated.SFIXED32.PackedInput.JsonOutput - Required.Proto3.ProtobufInput.ValidDataRepeated.SFIXED32.UnpackedInput.JsonOutput - Required.Proto3.ProtobufInput.ValidDataRepeated.SFIXED64.PackedInput.JsonOutput - Required.Proto3.ProtobufInput.ValidDataRepeated.SFIXED64.UnpackedInput.JsonOutput - Required.Proto3.ProtobufInput.ValidDataRepeated.SINT32.PackedInput.JsonOutput - Required.Proto3.ProtobufInput.ValidDataRepeated.SINT32.UnpackedInput.JsonOutput - Required.Proto3.ProtobufInput.ValidDataRepeated.SINT64.PackedInput.JsonOutput - Required.Proto3.ProtobufInput.ValidDataRepeated.SINT64.UnpackedInput.JsonOutput - Required.Proto3.ProtobufInput.ValidDataRepeated.STRING.JsonOutput - Required.Proto3.ProtobufInput.ValidDataRepeated.UINT32.PackedInput.JsonOutput - Required.Proto3.ProtobufInput.ValidDataRepeated.UINT32.UnpackedInput.JsonOutput - Required.Proto3.ProtobufInput.ValidDataRepeated.UINT64.PackedInput.JsonOutput - Required.Proto3.ProtobufInput.ValidDataRepeated.UINT64.UnpackedInput.JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.BOOL[0].JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.BOOL[1].JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.BOOL[2].JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.BOOL[3].JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.BOOL[4].JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.BOOL[5].JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.BOOL[6].JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.BYTES[0].JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.BYTES[1].JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.BYTES[2].JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.BYTES[3].JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.DOUBLE[0].JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.DOUBLE[1].JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.DOUBLE[2].JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.DOUBLE[3].JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.ENUM[0].JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.ENUM[1].JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.ENUM[2].JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.ENUM[3].JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.ENUM[4].JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.ENUM[5].JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.FIXED32[0].JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.FIXED32[1].JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.FIXED32[2].JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.FIXED64[0].JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.FIXED64[1].JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.FIXED64[2].JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.FLOAT[0].JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.FLOAT[1].JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.FLOAT[2].JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.FLOAT[3].JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.FLOAT[4].JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.INT32[0].JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.INT32[1].JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.INT32[2].JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.INT32[3].JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.INT32[4].JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.INT32[5].JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.INT32[6].JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.INT32[7].JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.INT32[8].JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.INT32[9].JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.INT64[0].JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.INT64[1].JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.INT64[2].JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.INT64[3].JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.MESSAGE[0].JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.MESSAGE[1].JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.SFIXED32[0].JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.SFIXED32[1].JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.SFIXED32[2].JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.SFIXED32[3].JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.SFIXED64[0].JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.SFIXED64[1].JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.SFIXED64[2].JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.SFIXED64[3].JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.SINT32[0].JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.SINT32[1].JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.SINT32[2].JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.SINT32[3].JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.SINT32[4].JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.SINT64[0].JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.SINT64[1].JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.SINT64[2].JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.SINT64[3].JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.STRING[0].JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.STRING[1].JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.STRING[2].JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.STRING[3].JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.STRING[4].JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.STRING[5].JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.STRING[6].JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.UINT32[0].JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.UINT32[1].JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.UINT32[2].JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.UINT32[3].JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.UINT32[4].JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.UINT32[5].JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.UINT32[6].JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.UINT32[7].JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.UINT32[8].JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.UINT32[9].JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.UINT64[0].JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.UINT64[1].JsonOutput - Required.Proto3.ProtobufInput.ValidDataScalar.UINT64[2].JsonOutput - Required.Proto3.TimestampProtoInputTooLarge.JsonOutput - Required.Proto3.TimestampProtoInputTooSmall.JsonOutput - Recommended.Editions_Proto3.FieldMaskNumbersDontRoundTrip.JsonOutput - Recommended.Editions_Proto3.FieldMaskPathsDontRoundTrip.JsonOutput - Recommended.Editions_Proto3.FieldMaskTooManyUnderscore.JsonOutput - Recommended.Editions_Proto3.ProtobufInput.OneofZeroBool.JsonOutput - Recommended.Editions_Proto3.ProtobufInput.OneofZeroBytes.JsonOutput - Recommended.Editions_Proto3.ProtobufInput.OneofZeroDouble.JsonOutput - Recommended.Editions_Proto3.ProtobufInput.OneofZeroEnum.JsonOutput - Recommended.Editions_Proto3.ProtobufInput.OneofZeroFloat.JsonOutput - Recommended.Editions_Proto3.ProtobufInput.OneofZeroMessage.JsonOutput - Recommended.Editions_Proto3.ProtobufInput.OneofZeroMessageSetTwice.JsonOutput - Recommended.Editions_Proto3.ProtobufInput.OneofZeroString.JsonOutput - Recommended.Editions_Proto3.ProtobufInput.OneofZeroUint32.JsonOutput - Recommended.Editions_Proto3.ProtobufInput.OneofZeroUint64.JsonOutput - Recommended.Editions_Proto3.ValueRejectInfNumberValue.JsonOutput - Recommended.Editions_Proto3.ValueRejectNanNumberValue.JsonOutput - Required.Editions_Proto3.DurationProtoInputTooLarge.JsonOutput - Required.Editions_Proto3.DurationProtoInputTooSmall.JsonOutput - Required.Editions_Proto3.ProtobufInput.DoubleFieldNormalizeQuietNan.JsonOutput - Required.Editions_Proto3.ProtobufInput.DoubleFieldNormalizeSignalingNan.JsonOutput - Required.Editions_Proto3.ProtobufInput.FloatFieldNormalizeQuietNan.JsonOutput - Required.Editions_Proto3.ProtobufInput.FloatFieldNormalizeSignalingNan.JsonOutput - Required.Editions_Proto3.ProtobufInput.RepeatedScalarMessageMerge.JsonOutput - Required.Editions_Proto3.ProtobufInput.RepeatedScalarSelectsLast.BOOL.JsonOutput - Required.Editions_Proto3.ProtobufInput.RepeatedScalarSelectsLast.BYTES.JsonOutput - Required.Editions_Proto3.ProtobufInput.RepeatedScalarSelectsLast.DOUBLE.JsonOutput - Required.Editions_Proto3.ProtobufInput.RepeatedScalarSelectsLast.ENUM.JsonOutput - Required.Editions_Proto3.ProtobufInput.RepeatedScalarSelectsLast.FIXED32.JsonOutput - Required.Editions_Proto3.ProtobufInput.RepeatedScalarSelectsLast.FIXED64.JsonOutput - Required.Editions_Proto3.ProtobufInput.RepeatedScalarSelectsLast.FLOAT.JsonOutput - Required.Editions_Proto3.ProtobufInput.RepeatedScalarSelectsLast.INT32.JsonOutput - Required.Editions_Proto3.ProtobufInput.RepeatedScalarSelectsLast.INT64.JsonOutput - Required.Editions_Proto3.ProtobufInput.RepeatedScalarSelectsLast.SFIXED32.JsonOutput - Required.Editions_Proto3.ProtobufInput.RepeatedScalarSelectsLast.SFIXED64.JsonOutput - Required.Editions_Proto3.ProtobufInput.RepeatedScalarSelectsLast.SINT32.JsonOutput - Required.Editions_Proto3.ProtobufInput.RepeatedScalarSelectsLast.SINT64.JsonOutput - Required.Editions_Proto3.ProtobufInput.RepeatedScalarSelectsLast.STRING.JsonOutput - Required.Editions_Proto3.ProtobufInput.RepeatedScalarSelectsLast.UINT32.JsonOutput - Required.Editions_Proto3.ProtobufInput.RepeatedScalarSelectsLast.UINT64.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.BOOL.BOOL.Default.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.BOOL.BOOL.DuplicateKey.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.BOOL.BOOL.DuplicateKeyInMapEntry.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.BOOL.BOOL.DuplicateValueInMapEntry.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.BOOL.BOOL.MissingDefault.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.BOOL.BOOL.NonDefault.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.BOOL.BOOL.Unordered.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.FIXED32.FIXED32.Default.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.FIXED32.FIXED32.DuplicateKey.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.FIXED32.FIXED32.DuplicateKeyInMapEntry.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.FIXED32.FIXED32.DuplicateValueInMapEntry.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.FIXED32.FIXED32.MissingDefault.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.FIXED32.FIXED32.NonDefault.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.FIXED32.FIXED32.Unordered.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.FIXED64.FIXED64.Default.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.FIXED64.FIXED64.DuplicateKey.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.FIXED64.FIXED64.DuplicateKeyInMapEntry.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.FIXED64.FIXED64.DuplicateValueInMapEntry.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.FIXED64.FIXED64.MissingDefault.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.FIXED64.FIXED64.NonDefault.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.FIXED64.FIXED64.Unordered.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.INT32.DOUBLE.Default.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.INT32.DOUBLE.DuplicateKey.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.INT32.DOUBLE.DuplicateKeyInMapEntry.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.INT32.DOUBLE.DuplicateValueInMapEntry.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.INT32.DOUBLE.MissingDefault.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.INT32.DOUBLE.NonDefault.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.INT32.DOUBLE.Unordered.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.INT32.FLOAT.Default.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.INT32.FLOAT.DuplicateKey.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.INT32.FLOAT.DuplicateKeyInMapEntry.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.INT32.FLOAT.DuplicateValueInMapEntry.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.INT32.FLOAT.MissingDefault.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.INT32.FLOAT.NonDefault.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.INT32.FLOAT.Unordered.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.INT32.INT32.Default.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.INT32.INT32.DuplicateKey.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.INT32.INT32.DuplicateKeyInMapEntry.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.INT32.INT32.DuplicateValueInMapEntry.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.INT32.INT32.MissingDefault.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.INT32.INT32.NonDefault.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.INT32.INT32.Unordered.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.INT64.INT64.Default.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.INT64.INT64.DuplicateKey.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.INT64.INT64.DuplicateKeyInMapEntry.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.INT64.INT64.DuplicateValueInMapEntry.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.INT64.INT64.MissingDefault.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.INT64.INT64.NonDefault.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.INT64.INT64.Unordered.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.SFIXED32.SFIXED32.Default.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.SFIXED32.SFIXED32.DuplicateKey.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.SFIXED32.SFIXED32.DuplicateKeyInMapEntry.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.SFIXED32.SFIXED32.DuplicateValueInMapEntry.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.SFIXED32.SFIXED32.MissingDefault.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.SFIXED32.SFIXED32.NonDefault.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.SFIXED32.SFIXED32.Unordered.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.SFIXED64.SFIXED64.Default.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.SFIXED64.SFIXED64.DuplicateKey.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.SFIXED64.SFIXED64.DuplicateKeyInMapEntry.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.SFIXED64.SFIXED64.DuplicateValueInMapEntry.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.SFIXED64.SFIXED64.MissingDefault.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.SFIXED64.SFIXED64.NonDefault.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.SFIXED64.SFIXED64.Unordered.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.SINT32.SINT32.Default.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.SINT32.SINT32.DuplicateKey.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.SINT32.SINT32.DuplicateKeyInMapEntry.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.SINT32.SINT32.DuplicateValueInMapEntry.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.SINT32.SINT32.MissingDefault.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.SINT32.SINT32.NonDefault.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.SINT32.SINT32.Unordered.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.SINT64.SINT64.Default.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.SINT64.SINT64.DuplicateKey.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.SINT64.SINT64.DuplicateKeyInMapEntry.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.SINT64.SINT64.DuplicateValueInMapEntry.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.SINT64.SINT64.MissingDefault.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.SINT64.SINT64.NonDefault.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.SINT64.SINT64.Unordered.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.STRING.BYTES.Default.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.STRING.BYTES.DuplicateKey.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.STRING.BYTES.DuplicateKeyInMapEntry.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.STRING.BYTES.DuplicateValueInMapEntry.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.STRING.BYTES.MissingDefault.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.STRING.BYTES.NonDefault.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.STRING.BYTES.Unordered.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.STRING.ENUM.Default.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.STRING.ENUM.DuplicateKey.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.STRING.ENUM.DuplicateKeyInMapEntry.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.STRING.ENUM.DuplicateValueInMapEntry.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.STRING.ENUM.MissingDefault.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.STRING.ENUM.NonDefault.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.STRING.ENUM.Unordered.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.STRING.MESSAGE.Default.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.STRING.MESSAGE.DuplicateKey.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.STRING.MESSAGE.DuplicateKeyInMapEntry.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.STRING.MESSAGE.DuplicateValueInMapEntry.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.STRING.MESSAGE.MergeValue.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.STRING.MESSAGE.MissingDefault.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.STRING.MESSAGE.NonDefault.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.STRING.MESSAGE.Unordered.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.STRING.STRING.Default.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.STRING.STRING.DuplicateKey.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.STRING.STRING.DuplicateKeyInMapEntry.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.STRING.STRING.DuplicateValueInMapEntry.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.STRING.STRING.MissingDefault.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.STRING.STRING.NonDefault.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.STRING.STRING.Unordered.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.UINT32.UINT32.Default.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.UINT32.UINT32.DuplicateKey.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.UINT32.UINT32.DuplicateKeyInMapEntry.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.UINT32.UINT32.DuplicateValueInMapEntry.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.UINT32.UINT32.MissingDefault.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.UINT32.UINT32.NonDefault.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.UINT32.UINT32.Unordered.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.UINT64.UINT64.Default.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.UINT64.UINT64.DuplicateKey.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.UINT64.UINT64.DuplicateKeyInMapEntry.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.UINT64.UINT64.DuplicateValueInMapEntry.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.UINT64.UINT64.MissingDefault.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.UINT64.UINT64.NonDefault.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataMap.UINT64.UINT64.Unordered.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataOneof.BOOL.DefaultValue.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataOneof.BOOL.MultipleValuesForDifferentField.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataOneof.BOOL.MultipleValuesForSameField.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataOneof.BOOL.NonDefaultValue.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataOneof.BYTES.DefaultValue.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataOneof.BYTES.MultipleValuesForDifferentField.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataOneof.BYTES.MultipleValuesForSameField.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataOneof.BYTES.NonDefaultValue.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataOneof.DOUBLE.DefaultValue.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataOneof.DOUBLE.MultipleValuesForDifferentField.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataOneof.DOUBLE.MultipleValuesForSameField.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataOneof.DOUBLE.NonDefaultValue.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataOneof.ENUM.DefaultValue.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataOneof.ENUM.MultipleValuesForDifferentField.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataOneof.ENUM.MultipleValuesForSameField.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataOneof.ENUM.NonDefaultValue.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataOneof.FLOAT.DefaultValue.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataOneof.FLOAT.MultipleValuesForDifferentField.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataOneof.FLOAT.MultipleValuesForSameField.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataOneof.FLOAT.NonDefaultValue.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataOneof.MESSAGE.DefaultValue.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataOneof.MESSAGE.Merge.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataOneof.MESSAGE.MultipleValuesForDifferentField.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataOneof.MESSAGE.MultipleValuesForSameField.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataOneof.MESSAGE.NonDefaultValue.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataOneof.STRING.DefaultValue.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataOneof.STRING.MultipleValuesForDifferentField.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataOneof.STRING.MultipleValuesForSameField.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataOneof.STRING.NonDefaultValue.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataOneof.UINT32.DefaultValue.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataOneof.UINT32.MultipleValuesForDifferentField.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataOneof.UINT32.MultipleValuesForSameField.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataOneof.UINT32.NonDefaultValue.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataOneof.UINT64.DefaultValue.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataOneof.UINT64.MultipleValuesForDifferentField.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataOneof.UINT64.MultipleValuesForSameField.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataOneof.UINT64.NonDefaultValue.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataRepeated.BOOL.PackedInput.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataRepeated.BOOL.UnpackedInput.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataRepeated.BYTES.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataRepeated.DOUBLE.PackedInput.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataRepeated.DOUBLE.UnpackedInput.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataRepeated.ENUM.PackedInput.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataRepeated.ENUM.UnpackedInput.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataRepeated.FIXED32.PackedInput.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataRepeated.FIXED32.UnpackedInput.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataRepeated.FIXED64.PackedInput.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataRepeated.FIXED64.UnpackedInput.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataRepeated.FLOAT.PackedInput.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataRepeated.FLOAT.UnpackedInput.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataRepeated.INT32.PackedInput.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataRepeated.INT32.UnpackedInput.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataRepeated.INT64.PackedInput.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataRepeated.INT64.UnpackedInput.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataRepeated.MESSAGE.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataRepeated.SFIXED32.PackedInput.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataRepeated.SFIXED32.UnpackedInput.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataRepeated.SFIXED64.PackedInput.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataRepeated.SFIXED64.UnpackedInput.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataRepeated.SINT32.PackedInput.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataRepeated.SINT32.UnpackedInput.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataRepeated.SINT64.PackedInput.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataRepeated.SINT64.UnpackedInput.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataRepeated.STRING.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataRepeated.UINT32.PackedInput.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataRepeated.UINT32.UnpackedInput.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataRepeated.UINT64.PackedInput.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataRepeated.UINT64.UnpackedInput.JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.BOOL[0].JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.BOOL[1].JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.BOOL[2].JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.BOOL[3].JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.BOOL[4].JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.BOOL[5].JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.BOOL[6].JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.BYTES[0].JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.BYTES[1].JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.BYTES[2].JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.BYTES[3].JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.DOUBLE[0].JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.DOUBLE[1].JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.DOUBLE[2].JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.DOUBLE[3].JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.ENUM[0].JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.ENUM[1].JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.ENUM[2].JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.ENUM[3].JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.ENUM[4].JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.ENUM[5].JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.FIXED32[0].JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.FIXED32[1].JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.FIXED32[2].JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.FIXED64[0].JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.FIXED64[1].JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.FIXED64[2].JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.FLOAT[0].JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.FLOAT[1].JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.FLOAT[2].JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.FLOAT[3].JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.FLOAT[4].JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.INT32[0].JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.INT32[1].JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.INT32[2].JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.INT32[3].JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.INT32[4].JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.INT32[5].JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.INT32[6].JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.INT32[7].JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.INT32[8].JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.INT32[9].JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.INT64[0].JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.INT64[1].JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.INT64[2].JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.INT64[3].JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.MESSAGE[0].JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.MESSAGE[1].JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.SFIXED32[0].JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.SFIXED32[1].JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.SFIXED32[2].JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.SFIXED32[3].JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.SFIXED64[0].JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.SFIXED64[1].JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.SFIXED64[2].JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.SFIXED64[3].JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.SINT32[0].JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.SINT32[1].JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.SINT32[2].JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.SINT32[3].JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.SINT32[4].JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.SINT64[0].JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.SINT64[1].JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.SINT64[2].JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.SINT64[3].JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.STRING[0].JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.STRING[1].JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.STRING[2].JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.STRING[3].JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.STRING[4].JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.STRING[5].JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.STRING[6].JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.UINT32[0].JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.UINT32[1].JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.UINT32[2].JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.UINT32[3].JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.UINT32[4].JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.UINT32[5].JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.UINT32[6].JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.UINT32[7].JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.UINT32[8].JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.UINT32[9].JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.UINT64[0].JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.UINT64[1].JsonOutput - Required.Editions_Proto3.ProtobufInput.ValidDataScalar.UINT64[2].JsonOutput - Required.Editions_Proto3.TimestampProtoInputTooLarge.JsonOutput - Required.Editions_Proto3.TimestampProtoInputTooSmall.JsonOutput diff --git a/conformance/text_format_failure_list_rust_cc.txt b/conformance/text_format_failure_list_rust_cc.txt index 830ee9ad527a4..e69de29bb2d1d 100644 --- a/conformance/text_format_failure_list_rust_cc.txt +++ b/conformance/text_format_failure_list_rust_cc.txt @@ -1,17 +0,0 @@ -# All TextFormatOutput tests currently fail and can't be skipped yet. b/285468558 - Recommended.Proto3.ProtobufInput.GroupUnknownFields_Drop.TextFormatOutput - Recommended.Proto3.ProtobufInput.GroupUnknownFields_Print.TextFormatOutput - Recommended.Proto3.ProtobufInput.MessageUnknownFields_Drop.TextFormatOutput - Recommended.Proto3.ProtobufInput.MessageUnknownFields_Print.TextFormatOutput - Recommended.Proto3.ProtobufInput.RepeatedUnknownFields_Drop.TextFormatOutput - Recommended.Proto3.ProtobufInput.RepeatedUnknownFields_Print.TextFormatOutput - Recommended.Proto3.ProtobufInput.ScalarUnknownFields_Drop.TextFormatOutput - Recommended.Proto3.ProtobufInput.ScalarUnknownFields_Print.TextFormatOutput - Recommended.Editions_Proto3.ProtobufInput.GroupUnknownFields_Drop.TextFormatOutput - Recommended.Editions_Proto3.ProtobufInput.GroupUnknownFields_Print.TextFormatOutput - Recommended.Editions_Proto3.ProtobufInput.MessageUnknownFields_Drop.TextFormatOutput - Recommended.Editions_Proto3.ProtobufInput.MessageUnknownFields_Print.TextFormatOutput - Recommended.Editions_Proto3.ProtobufInput.RepeatedUnknownFields_Drop.TextFormatOutput - Recommended.Editions_Proto3.ProtobufInput.RepeatedUnknownFields_Print.TextFormatOutput - Recommended.Editions_Proto3.ProtobufInput.ScalarUnknownFields_Drop.TextFormatOutput - Recommended.Editions_Proto3.ProtobufInput.ScalarUnknownFields_Print.TextFormatOutput \ No newline at end of file diff --git a/conformance/text_format_failure_list_rust_upb.txt b/conformance/text_format_failure_list_rust_upb.txt index 830ee9ad527a4..e69de29bb2d1d 100644 --- a/conformance/text_format_failure_list_rust_upb.txt +++ b/conformance/text_format_failure_list_rust_upb.txt @@ -1,17 +0,0 @@ -# All TextFormatOutput tests currently fail and can't be skipped yet. b/285468558 - Recommended.Proto3.ProtobufInput.GroupUnknownFields_Drop.TextFormatOutput - Recommended.Proto3.ProtobufInput.GroupUnknownFields_Print.TextFormatOutput - Recommended.Proto3.ProtobufInput.MessageUnknownFields_Drop.TextFormatOutput - Recommended.Proto3.ProtobufInput.MessageUnknownFields_Print.TextFormatOutput - Recommended.Proto3.ProtobufInput.RepeatedUnknownFields_Drop.TextFormatOutput - Recommended.Proto3.ProtobufInput.RepeatedUnknownFields_Print.TextFormatOutput - Recommended.Proto3.ProtobufInput.ScalarUnknownFields_Drop.TextFormatOutput - Recommended.Proto3.ProtobufInput.ScalarUnknownFields_Print.TextFormatOutput - Recommended.Editions_Proto3.ProtobufInput.GroupUnknownFields_Drop.TextFormatOutput - Recommended.Editions_Proto3.ProtobufInput.GroupUnknownFields_Print.TextFormatOutput - Recommended.Editions_Proto3.ProtobufInput.MessageUnknownFields_Drop.TextFormatOutput - Recommended.Editions_Proto3.ProtobufInput.MessageUnknownFields_Print.TextFormatOutput - Recommended.Editions_Proto3.ProtobufInput.RepeatedUnknownFields_Drop.TextFormatOutput - Recommended.Editions_Proto3.ProtobufInput.RepeatedUnknownFields_Print.TextFormatOutput - Recommended.Editions_Proto3.ProtobufInput.ScalarUnknownFields_Drop.TextFormatOutput - Recommended.Editions_Proto3.ProtobufInput.ScalarUnknownFields_Print.TextFormatOutput \ No newline at end of file From 8876b1069fdfa5ae8aad154f8b94cf882386ef81 Mon Sep 17 00:00:00 2001 From: Kevin King Date: Tue, 2 Jan 2024 11:19:58 -0800 Subject: [PATCH 152/255] impl SettableValue for MsgView For the cpp runtime, call the `Message::CopyFrom` method. For the upb runtime, expose the message `MiniTable` and call `upb_Message_DeepCopy`. PiperOrigin-RevId: 595166276 --- rust/test/shared/accessors_test.rs | 14 ++++- rust/upb.rs | 26 ++++++++ rust/upb_kernel/BUILD | 1 + rust/upb_kernel/upb_api.c | 3 +- src/google/protobuf/compiler/rust/message.cc | 64 +++++++++++++++++--- 5 files changed, 98 insertions(+), 10 deletions(-) diff --git a/rust/test/shared/accessors_test.rs b/rust/test/shared/accessors_test.rs index 15758a1f2436a..289f3765afd67 100644 --- a/rust/test/shared/accessors_test.rs +++ b/rust/test/shared/accessors_test.rs @@ -10,7 +10,7 @@ use googletest::prelude::*; use matchers::{is_set, is_unset}; use protobuf::Optional; -use unittest_proto::proto2_unittest::{TestAllTypes, TestAllTypes_}; +use unittest_proto::proto2_unittest::{NestedTestAllTypes, TestAllTypes, TestAllTypes_}; #[test] fn test_default_accessors() { @@ -735,3 +735,15 @@ fn test_oneof_mut_accessors() { msg.oneof_bytes_mut().set(b"123"); assert_that!(msg.oneof_field_mut(), matches_pattern!(OneofBytes(_))); } + +#[test] +fn test_set_message_from_view() { + use protobuf::MutProxy; + let mut m1 = NestedTestAllTypes::new(); + + let mut m2 = NestedTestAllTypes::new(); + m2.payload_mut().optional_int32_mut().set(1); + + m1.payload_mut().set(m2.payload()); + assert_that!(m1.payload().optional_int32(), eq(1)); +} diff --git a/rust/upb.rs b/rust/upb.rs index 2fe4fda87c16d..7b5af62dcf42b 100644 --- a/rust/upb.rs +++ b/rust/upb.rs @@ -288,6 +288,10 @@ impl<'msg> MutatorMessageRef<'msg> { pub fn msg(&self) -> RawMessage { self.msg } + + pub fn raw_arena(&self, _private: Private) -> RawArena { + self.arena.raw() + } } pub fn copy_bytes_in_arena_if_needed_by_runtime<'msg>( @@ -308,6 +312,28 @@ pub fn copy_bytes_in_arena_if_needed_by_runtime<'msg>( } } +/// Opaque struct containing a upb_MiniTable. +/// +/// This wrapper is a workaround until stabilization of [`extern type`]. +/// TODO: convert to extern type once stabilized. +/// [`extern type`]: https://github.com/rust-lang/rust/issues/43467 +#[repr(C)] +pub struct OpaqueMiniTable { + // TODO: consider importing a minitable struct declared in + // google3/third_party/upb/bits. + _data: [u8; 0], + _marker: std::marker::PhantomData<(*mut u8, ::std::marker::PhantomPinned)>, +} + +extern "C" { + pub fn upb_Message_DeepCopy( + dst: RawMessage, + src: RawMessage, + mini_table: *const OpaqueMiniTable, + arena: RawArena, + ); +} + /// The raw type-erased pointer version of `RepeatedMut`. /// /// Contains a `upb_Array*` as well as `RawArena`, most likely that of the diff --git a/rust/upb_kernel/BUILD b/rust/upb_kernel/BUILD index 62ae49a3f8cca..c98774abb539f 100644 --- a/rust/upb_kernel/BUILD +++ b/rust/upb_kernel/BUILD @@ -10,5 +10,6 @@ cc_library( deps = [ "//upb:mem", "//upb:message", + "//upb:message_copy", ], ) diff --git a/rust/upb_kernel/upb_api.c b/rust/upb_kernel/upb_api.c index 7de8d0bd4da75..e168b02e69a07 100644 --- a/rust/upb_kernel/upb_api.c +++ b/rust/upb_kernel/upb_api.c @@ -10,4 +10,5 @@ #include "upb/mem/arena.h" // IWYU pragma: keep #include "upb/message/array.h" // IWYU pragma: keep -#include "upb/message/map.h" // IWYU pragma: keep +#include "upb/message/copy.h" // IWYU pragma: keep +#include "upb/message/map.h" // IWYU pragma: keep \ No newline at end of file diff --git a/src/google/protobuf/compiler/rust/message.cc b/src/google/protobuf/compiler/rust/message.cc index 5247acfce24dc..4230da200a5aa 100644 --- a/src/google/protobuf/compiler/rust/message.cc +++ b/src/google/protobuf/compiler/rust/message.cc @@ -7,6 +7,8 @@ #include "google/protobuf/compiler/rust/message.h" +#include + #include "absl/log/absl_check.h" #include "absl/log/absl_log.h" #include "absl/strings/str_format.h" @@ -19,6 +21,7 @@ #include "google/protobuf/compiler/rust/naming.h" #include "google/protobuf/compiler/rust/oneof.h" #include "google/protobuf/descriptor.h" +#include "upb_generator/mangle.h" namespace google { namespace protobuf { @@ -26,6 +29,10 @@ namespace compiler { namespace rust { namespace { +std::string UpbMinitableName(const Descriptor& msg) { + return upb::generator::MessageInit(msg.full_name()); +} + void MessageNew(Context& ctx, const Descriptor& msg) { switch (ctx.opts().kernel) { case Kernel::kCpp: @@ -126,12 +133,14 @@ void MessageExterns(Context& ctx, const Descriptor& msg) { {"delete_thunk", ThunkName(ctx, msg, "delete")}, {"serialize_thunk", ThunkName(ctx, msg, "serialize")}, {"deserialize_thunk", ThunkName(ctx, msg, "deserialize")}, + {"copy_from_thunk", ThunkName(ctx, msg, "copy_from")}, }, R"rs( fn $new_thunk$() -> $pbi$::RawMessage; fn $delete_thunk$(raw_msg: $pbi$::RawMessage); fn $serialize_thunk$(raw_msg: $pbi$::RawMessage) -> $pbr$::SerializedData; fn $deserialize_thunk$(raw_msg: $pbi$::RawMessage, data: $pbr$::SerializedData) -> bool; + fn $copy_from_thunk$(dst: $pbi$::RawMessage, src: $pbi$::RawMessage); )rs"); return; @@ -141,11 +150,15 @@ void MessageExterns(Context& ctx, const Descriptor& msg) { {"new_thunk", ThunkName(ctx, msg, "new")}, {"serialize_thunk", ThunkName(ctx, msg, "serialize")}, {"deserialize_thunk", ThunkName(ctx, msg, "parse")}, + {"minitable", UpbMinitableName(msg)}, }, R"rs( fn $new_thunk$(arena: $pbi$::RawArena) -> $pbi$::RawMessage; fn $serialize_thunk$(msg: $pbi$::RawMessage, arena: $pbi$::RawArena, len: &mut usize) -> $NonNull$; fn $deserialize_thunk$(data: *const u8, size: usize, arena: $pbi$::RawArena) -> Option<$pbi$::RawMessage>; + /// Opaque wrapper for this message's MiniTable. The only valid way to + /// reference this static is with `std::ptr::addr_of!(..)`. + static $minitable$: $pbr$::OpaqueMiniTable; )rs"); return; } @@ -169,6 +182,41 @@ bool IsStringOrBytes(FieldDescriptor::Type t) { return t == FieldDescriptor::TYPE_STRING || t == FieldDescriptor::TYPE_BYTES; } +void MessageSettableValue(Context& ctx, const Descriptor& msg) { + switch (ctx.opts().kernel) { + case Kernel::kCpp: + ctx.Emit({{"copy_from_thunk", ThunkName(ctx, msg, "copy_from")}}, R"rs( + impl<'msg> $pb$::SettableValue<$Msg$> for $Msg$View<'msg> { + fn set_on<'dst>( + self, _private: $pbi$::Private, mutator: $pb$::Mut<'dst, $Msg$>) + where $Msg$: 'dst { + unsafe { $copy_from_thunk$(mutator.inner.msg(), self.msg) }; + } + } + )rs"); + return; + + case Kernel::kUpb: + ctx.Emit({{"minitable", UpbMinitableName(msg)}}, R"rs( + impl<'msg> $pb$::SettableValue<$Msg$> for $Msg$View<'msg> { + fn set_on<'dst>( + self, _private: $pbi$::Private, mutator: $pb$::Mut<'dst, $Msg$>) + where $Msg$: 'dst { + unsafe { $pbr$::upb_Message_DeepCopy( + mutator.inner.msg(), + self.msg, + $std$::ptr::addr_of!($minitable$), + mutator.inner.raw_arena($pbi$::Private), + ) }; + } + } + )rs"); + return; + } + + ABSL_LOG(FATAL) << "unreachable"; +} + void GetterForViewOrMut(Context& ctx, const FieldDescriptor& field, bool is_mut) { auto fieldName = field.name(); @@ -381,7 +429,8 @@ void GenerateRs(Context& ctx, const Descriptor& msg) { {"accessor_fns_for_views", [&] { AccessorsForViewOrMut(ctx, msg, false); }}, {"accessor_fns_for_muts", - [&] { AccessorsForViewOrMut(ctx, msg, true); }}}, + [&] { AccessorsForViewOrMut(ctx, msg, true); }}, + {"settable_impl", [&] { MessageSettableValue(ctx, msg); }}}, R"rs( #[allow(non_camel_case_types)] // TODO: Implement support for debug redaction @@ -437,13 +486,7 @@ void GenerateRs(Context& ctx, const Descriptor& msg) { } } - impl<'a> $pb$::SettableValue<$Msg$> for $Msg$View<'a> { - fn set_on<'b>(self, _private: $pb$::__internal::Private, _mutator: $pb$::Mut<'b, $Msg$>) - where - $Msg$: 'b { - todo!() - } - } + $settable_impl$ #[derive(Debug)] #[allow(dead_code)] @@ -556,6 +599,7 @@ void GenerateThunksCc(Context& ctx, const Descriptor& msg) { {"delete_thunk", ThunkName(ctx, msg, "delete")}, {"serialize_thunk", ThunkName(ctx, msg, "serialize")}, {"deserialize_thunk", ThunkName(ctx, msg, "deserialize")}, + {"copy_from_thunk", ThunkName(ctx, msg, "copy_from")}, {"nested_msg_thunks", [&] { for (int i = 0; i < msg.nested_type_count(); ++i) { @@ -590,6 +634,10 @@ void GenerateThunksCc(Context& ctx, const Descriptor& msg) { return msg->ParseFromArray(data.data, data.len); } + void $copy_from_thunk$($QualifiedMsg$* dst, const $QualifiedMsg$* src) { + dst->CopyFrom(*src); + } + $accessor_thunks$ $oneof_thunks$ From 255f95e5b19c142ece319cc35c1b3808ec0e259f Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Tue, 2 Jan 2024 11:51:12 -0800 Subject: [PATCH 153/255] Include JSON output tests with Proto2 messages in the conformance test suite. PiperOrigin-RevId: 595173790 --- conformance/binary_json_conformance_suite.cc | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/conformance/binary_json_conformance_suite.cc b/conformance/binary_json_conformance_suite.cc index 628afdcb8abb1..4270dfee0ebdd 100644 --- a/conformance/binary_json_conformance_suite.cc +++ b/conformance/binary_json_conformance_suite.cc @@ -453,17 +453,15 @@ void BinaryAndJsonConformanceSuiteImpl::RunValidProtobufTest( const std::string& equivalent_text_format) { MessageType prototype; - ConformanceRequestSetting setting1( + ConformanceRequestSetting binary_to_binary( level, conformance::PROTOBUF, conformance::PROTOBUF, conformance::BINARY_TEST, prototype, test_name, input_protobuf); - suite_.RunValidInputTest(setting1, equivalent_text_format); + suite_.RunValidInputTest(binary_to_binary, equivalent_text_format); - if (run_proto3_tests_) { - ConformanceRequestSetting setting2( - level, conformance::PROTOBUF, conformance::JSON, - conformance::BINARY_TEST, prototype, test_name, input_protobuf); - suite_.RunValidInputTest(setting2, equivalent_text_format); - } + ConformanceRequestSetting binary_to_json( + level, conformance::PROTOBUF, conformance::JSON, conformance::BINARY_TEST, + prototype, test_name, input_protobuf); + suite_.RunValidInputTest(binary_to_json, equivalent_text_format); } template From df57e5474bf3ce211329e55993cb991a7ce1c5e0 Mon Sep 17 00:00:00 2001 From: Eric Salo Date: Tue, 2 Jan 2024 12:40:57 -0800 Subject: [PATCH 154/255] upb: fix Ruby bug which allowed map.delete(key) on a frozen map Also clean up some compiler warnings about exiting from non-void functions without returning a value. PiperOrigin-RevId: 595185251 --- ruby/ext/google/protobuf_c/map.c | 2 +- ruby/ext/google/protobuf_c/shared_message.c | 15 ++++++++------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/ruby/ext/google/protobuf_c/map.c b/ruby/ext/google/protobuf_c/map.c index c0c4cb2accc01..7b78f87fc08f6 100644 --- a/ruby/ext/google/protobuf_c/map.c +++ b/ruby/ext/google/protobuf_c/map.c @@ -444,7 +444,7 @@ static VALUE Map_delete(VALUE _self, VALUE key) { Convert_RubyToUpb(key, "", Map_keyinfo(self), NULL); upb_MessageValue val_upb; - if (upb_Map_Delete(self->map, key_upb, &val_upb)) { + if (upb_Map_Delete(Map_GetMutable(_self), key_upb, &val_upb)) { return Convert_UpbToRuby(val_upb, self->value_type_info, self->arena); } else { return Qnil; diff --git a/ruby/ext/google/protobuf_c/shared_message.c b/ruby/ext/google/protobuf_c/shared_message.c index 7d140fbca41a8..761c5445985e5 100644 --- a/ruby/ext/google/protobuf_c/shared_message.c +++ b/ruby/ext/google/protobuf_c/shared_message.c @@ -29,11 +29,11 @@ uint64_t shared_Message_Hash(const upb_Message* msg, const upb_MessageDef* m, uint64_t ret = _upb_Hash(data, size, seed); upb_Arena_Free(arena); return ret; - } else { - upb_Arena_Free(arena); - upb_Status_SetErrorMessage(status, "Error calculating hash"); - return 0; } + + upb_Arena_Free(arena); + upb_Status_SetErrorMessage(status, "Error calculating hash"); + return 0; } // Support function for Message_Equal @@ -59,8 +59,9 @@ bool shared_Message_Equal(const upb_Message* m1, const upb_Message* m2, bool ret = (size1 == size2) && (memcmp(data1, data2, size1) == 0); upb_Arena_Free(arena_tmp); return ret; - } else { - upb_Arena_Free(arena_tmp); - upb_Status_SetErrorMessage(status, "Error comparing messages"); } + + upb_Arena_Free(arena_tmp); + upb_Status_SetErrorMessage(status, "Error comparing messages"); + return 0; } From 670e0c2a0d0b64c994f743a73ee9b8926c47580d Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Tue, 2 Jan 2024 14:58:18 -0800 Subject: [PATCH 155/255] Fix begin iterator for empty arrays. If the underlying array for a repeated field is a nullptr (which is possible for const array access on a message field that hasn't been set) the begin iterator will currently contain garbage data, which can lead to an illegal access. This CL adds a nullptr check to `begin()`, similar to what already exists for `size()`. PiperOrigin-RevId: 595217999 --- protos/repeated_field.h | 8 +++++--- protos_generator/tests/test_generated.cc | 14 ++++++++++++++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/protos/repeated_field.h b/protos/repeated_field.h index f8f3f5acaf796..b1b1aa2e04667 100644 --- a/protos/repeated_field.h +++ b/protos/repeated_field.h @@ -136,9 +136,11 @@ class RepeatedFieldProxy } iterator begin() const { - return iterator({static_cast( - const_cast(upb_Array_DataPtr(this->arr_))), - this->arena_}); + return iterator( + {static_cast( + this->arr_ ? const_cast(upb_Array_DataPtr(this->arr_)) + : nullptr), + this->arena_}); } iterator end() const { return begin() + this->size(); } reverse_iterator rbegin() const { return reverse_iterator(end()); } diff --git a/protos_generator/tests/test_generated.cc b/protos_generator/tests/test_generated.cc index 14638af06d22b..ffa3d5cb8de47 100644 --- a/protos_generator/tests/test_generated.cc +++ b/protos_generator/tests/test_generated.cc @@ -5,6 +5,7 @@ // license that can be found in the LICENSE file or at // https://developers.google.com/open-source/licenses/bsd +#include #include #include #include @@ -571,6 +572,19 @@ TEST(CppGeneratedCode, RepeatedFieldProxyForMessages) { EXPECT_EQ(test_model.mutable_child_models()->size(), 0); } +TEST(CppGeneratedCode, EmptyRepeatedFieldProxyForMessages) { + ::protos::Arena arena; + auto test_model = ::protos::CreateMessage(arena); + EXPECT_EQ(0, test_model.child_models().size()); + ChildModel1 child1; + child1.set_child_str1(kTestStr1); + + EXPECT_EQ(test_model.child_models().size(), 0); + EXPECT_EQ(std::distance(test_model.child_models().begin(), + test_model.child_models().end()), + 0); +} + TEST(CppGeneratedCode, RepeatedFieldProxyForMessagesIndexOperator) { ::protos::Arena arena; auto test_model = ::protos::CreateMessage(arena); From 2bf62b18733761e50d35412d004241a42c3ce4c1 Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Wed, 3 Jan 2024 08:37:10 -0800 Subject: [PATCH 156/255] Internal Code Change PiperOrigin-RevId: 595410785 --- src/google/protobuf/descriptor.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/google/protobuf/descriptor.cc b/src/google/protobuf/descriptor.cc index ff373708b6d3d..00c21dd2565c6 100644 --- a/src/google/protobuf/descriptor.cc +++ b/src/google/protobuf/descriptor.cc @@ -6222,7 +6222,7 @@ JsonNameDetails GetJsonNameDetails(const FieldDescriptorProto* field, field->json_name() != default_json_name) { return {field, field->json_name(), true}; } - return {field, default_json_name, false}; + return {field, std::move(default_json_name), false}; } bool JsonNameLooksLikeExtension(std::string name) { From 807f00b4db1e12ed5dfd77dd0d72df97a434f9ba Mon Sep 17 00:00:00 2001 From: Mike Kruskal Date: Wed, 3 Jan 2024 09:31:14 -0800 Subject: [PATCH 157/255] Fix typo in cache-clearing workflow PiperOrigin-RevId: 595424484 --- .github/workflows/clear_caches.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/clear_caches.yml b/.github/workflows/clear_caches.yml index 30f379b0a9ede..5aadfac6b34ec 100644 --- a/.github/workflows/clear_caches.yml +++ b/.github/workflows/clear_caches.yml @@ -3,7 +3,7 @@ name: Clear expensive caches to prevent unbounded growth on: schedule: # Run every 4 months at 10 AM UTC (2 AM PDT) - - cron: 0 10 1 */4 * + - cron: 0 10 5 */4 * # manual workflow_dispatch: @@ -31,5 +31,5 @@ jobs: - name: Create an empty cache with a single file run: | rm -rf .repository-cache - mkdir -p .repository-cache' + mkdir -p .repository-cache touch .repository-cache/reset_file From 3869318558bd1555f6f3c4ace8b910c00864c90a Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Wed, 3 Jan 2024 12:08:13 -0800 Subject: [PATCH 158/255] Add inner verification code to detect accessors missing required annotations. This change has no behavior change, other than CHECK-fail `protoc` when a bug is detected instead of generating the buggy code. PiperOrigin-RevId: 595467581 --- src/google/protobuf/compiler/cpp/field.cc | 2 + .../cpp/field_generators/cord_field.cc | 24 ++++--- .../cpp/field_generators/enum_field.cc | 32 +++++---- .../cpp/field_generators/map_field.cc | 8 +-- .../cpp/field_generators/message_field.cc | 49 ++++++------- .../cpp/field_generators/primitive_field.cc | 34 ++++----- .../cpp/field_generators/string_field.cc | 62 ++++++++-------- src/google/protobuf/compiler/cpp/message.cc | 70 +++++++++++++++++-- src/google/protobuf/compiler/plugin.pb.h | 7 +- src/google/protobuf/descriptor.pb.h | 51 ++++++++------ src/google/protobuf/io/printer.cc | 3 + src/google/protobuf/io/printer.h | 22 +++++- src/google/protobuf/io/printer_unittest.cc | 29 ++++++++ 13 files changed, 259 insertions(+), 134 deletions(-) diff --git a/src/google/protobuf/compiler/cpp/field.cc b/src/google/protobuf/compiler/cpp/field.cc index a8a73ecd677aa..8c357cfbaff92 100644 --- a/src/google/protobuf/compiler/cpp/field.cc +++ b/src/google/protobuf/compiler/cpp/field.cc @@ -43,6 +43,8 @@ std::vector FieldVars(const FieldDescriptor* field, const Options& opts) { // This will eventually be renamed to "field", once the existing "field" // variable is replaced with "field_" everywhere. {"name", FieldName(field)}, + // Same as above, but represents internal use. + {"name_internal", FieldName(field)}, {"index", field->index()}, {"number", field->number()}, diff --git a/src/google/protobuf/compiler/cpp/field_generators/cord_field.cc b/src/google/protobuf/compiler/cpp/field_generators/cord_field.cc index ffcf3dce90926..8924bef438c8b 100644 --- a/src/google/protobuf/compiler/cpp/field_generators/cord_field.cc +++ b/src/google/protobuf/compiler/cpp/field_generators/cord_field.cc @@ -174,7 +174,7 @@ void CordFieldGenerator::GenerateInlineAccessorDefinitions( io::Printer* printer) const { auto v = printer->WithVars(variables_); printer->Emit(R"cc( - inline const ::absl::Cord& $classname$::_internal_$name$() const { + inline const ::absl::Cord& $classname$::_internal_$name_internal$() const { return $field$; } )cc"); @@ -183,18 +183,20 @@ void CordFieldGenerator::GenerateInlineAccessorDefinitions( ABSL_ATTRIBUTE_LIFETIME_BOUND { $annotate_get$; // @@protoc_insertion_point(field_get:$full_name$) - return _internal_$name$(); + return _internal_$name_internal$(); } )cc"); printer->Emit(R"cc( - inline void $classname$::_internal_set_$name$(const ::absl::Cord& value) { + inline void $classname$::_internal_set_$name_internal$( + const ::absl::Cord& value) { $set_hasbit$; $field$ = value; } )cc"); printer->Emit(R"cc( inline void $classname$::set_$name$(const ::absl::Cord& value) { - $PrepareSplitMessageForWrite$ _internal_set_$name$(value); + $PrepareSplitMessageForWrite$; + _internal_set_$name_internal$(value); $annotate_set$; // @@protoc_insertion_point(field_set:$full_name$) } @@ -209,7 +211,7 @@ void CordFieldGenerator::GenerateInlineAccessorDefinitions( } )cc"); printer->Emit(R"cc( - inline ::absl::Cord* $classname$::_internal_mutable_$name$() { + inline ::absl::Cord* $classname$::_internal_mutable_$name_internal$() { $set_hasbit$; return &$field$; } @@ -333,7 +335,7 @@ void CordOneofFieldGenerator::GenerateInlineAccessorDefinitions( io::Printer* printer) const { auto v = printer->WithVars(variables_); printer->Emit(R"cc( - inline const ::absl::Cord& $classname$::_internal_$name$() const { + inline const ::absl::Cord& $classname$::_internal_$name_internal$() const { if ($has_field$) { return *$field$; } @@ -345,14 +347,14 @@ void CordOneofFieldGenerator::GenerateInlineAccessorDefinitions( ABSL_ATTRIBUTE_LIFETIME_BOUND { $annotate_get$; // @@protoc_insertion_point(field_get:$full_name$) - return _internal_$name$(); + return _internal_$name_internal$(); } )cc"); printer->Emit(R"cc( inline void $classname$::set_$name$(const ::absl::Cord& value) { if ($not_has_field$) { clear_$oneof_name$(); - set_has_$name$(); + set_has_$name_internal$(); $field$ = new ::absl::Cord; ::$proto_ns$::Arena* arena = GetArena(); if (arena != nullptr) { @@ -368,7 +370,7 @@ void CordOneofFieldGenerator::GenerateInlineAccessorDefinitions( inline void $classname$::set_$name$(::absl::string_view value) { if ($not_has_field$) { clear_$oneof_name$(); - set_has_$name$(); + set_has_$name_internal$(); $field$ = new ::absl::Cord; ::$proto_ns$::Arena* arena = GetArena(); if (arena != nullptr) { @@ -381,10 +383,10 @@ void CordOneofFieldGenerator::GenerateInlineAccessorDefinitions( } )cc"); printer->Emit(R"cc( - inline ::absl::Cord* $classname$::_internal_mutable_$name$() { + inline ::absl::Cord* $classname$::_internal_mutable_$name_internal$() { if ($not_has_field$) { clear_$oneof_name$(); - set_has_$name$(); + set_has_$name_internal$(); $field$ = new ::absl::Cord; ::$proto_ns$::Arena* arena = GetArena(); if (arena != nullptr) { diff --git a/src/google/protobuf/compiler/cpp/field_generators/enum_field.cc b/src/google/protobuf/compiler/cpp/field_generators/enum_field.cc index 1b5287960a0ef..8f3a7f1d56650 100644 --- a/src/google/protobuf/compiler/cpp/field_generators/enum_field.cc +++ b/src/google/protobuf/compiler/cpp/field_generators/enum_field.cc @@ -167,7 +167,7 @@ void SingularEnum::GenerateInlineAccessorDefinitions(io::Printer* p) const { inline $Enum$ $Msg$::$name$() const { $annotate_get$; // @@protoc_insertion_point(field_get:$pkg.Msg.field$) - return _internal_$name$(); + return _internal_$name_internal$(); } )cc"); @@ -178,13 +178,13 @@ void SingularEnum::GenerateInlineAccessorDefinitions(io::Printer* p) const { $assert_valid$; if ($not_has_field$) { clear_$oneof_name$(); - set_has_$name$(); + set_has_$name_internal$(); } $field_$ = value; $annotate_set$; // @@protoc_insertion_point(field_set:$pkg.Msg.field$) } - inline $Enum$ $Msg$::_internal_$name$() const { + inline $Enum$ $Msg$::_internal_$name_internal$() const { if ($has_field$) { return static_cast<$Enum$>($field_$); } @@ -195,16 +195,16 @@ void SingularEnum::GenerateInlineAccessorDefinitions(io::Printer* p) const { p->Emit(R"cc( inline void $Msg$::set_$name$($Enum$ value) { $PrepareSplitMessageForWrite$; - _internal_set_$name$(value); + _internal_set_$name_internal$(value); $set_hasbit$; $annotate_set$; // @@protoc_insertion_point(field_set:$pkg.Msg.field$) } - inline $Enum$ $Msg$::_internal_$name$() const { + inline $Enum$ $Msg$::_internal_$name_internal$() const { $TsanDetectConcurrentRead$; return static_cast<$Enum$>($field_$); } - inline void $Msg$::_internal_set_$name$($Enum$ value) { + inline void $Msg$::_internal_set_$name_internal$($Enum$ value) { $TsanDetectConcurrentMutation$; $assert_valid$; $field_$ = value; @@ -400,13 +400,13 @@ void RepeatedEnum::GenerateInlineAccessorDefinitions(io::Printer* p) const { inline $Enum$ $Msg$::$name$(int index) const { $annotate_get$; // @@protoc_insertion_point(field_get:$pkg.Msg.field$) - return static_cast<$Enum$>(_internal_$name$().Get(index)); + return static_cast<$Enum$>(_internal_$name_internal$().Get(index)); } )cc"); p->Emit(R"cc( inline void $Msg$::set_$name$(int index, $Enum$ value) { $assert_valid$; - _internal_mutable_$name$()->Set(index, value); + _internal_mutable_$name_internal$()->Set(index, value); $annotate_set$ // @@protoc_insertion_point(field_set:$pkg.Msg.field$) } @@ -415,7 +415,7 @@ void RepeatedEnum::GenerateInlineAccessorDefinitions(io::Printer* p) const { inline void $Msg$::add_$name$($Enum$ value) { $assert_valid$; $TsanDetectConcurrentMutation$; - _internal_mutable_$name$()->Add(value); + _internal_mutable_$name_internal$()->Add(value); $annotate_add$ // @@protoc_insertion_point(field_add:$pkg.Msg.field$) } @@ -425,7 +425,7 @@ void RepeatedEnum::GenerateInlineAccessorDefinitions(io::Printer* p) const { ABSL_ATTRIBUTE_LIFETIME_BOUND { $annotate_list$; // @@protoc_insertion_point(field_list:$pkg.Msg.field$) - return _internal_$name$(); + return _internal_$name_internal$(); } )cc"); p->Emit(R"cc( @@ -434,16 +434,17 @@ void RepeatedEnum::GenerateInlineAccessorDefinitions(io::Printer* p) const { $annotate_mutable_list$; // @@protoc_insertion_point(field_mutable_list:$pkg.Msg.field$) $TsanDetectConcurrentMutation$; - return _internal_mutable_$name$(); + return _internal_mutable_$name_internal$(); } )cc"); if (should_split()) { p->Emit(R"cc( - inline const $pb$::RepeatedField& $Msg$::_internal_$name$() const { + inline const $pb$::RepeatedField& $Msg$::_internal_$name_internal$() + const { $TsanDetectConcurrentRead$; return *$field_$; } - inline $pb$::RepeatedField* $Msg$::_internal_mutable_$name$() { + inline $pb$::RepeatedField* $Msg$::_internal_mutable_$name_internal$() { $TsanDetectConcurrentRead$; $PrepareSplitMessageForWrite$; if ($field_$.IsDefault()) { @@ -455,11 +456,12 @@ void RepeatedEnum::GenerateInlineAccessorDefinitions(io::Printer* p) const { )cc"); } else { p->Emit(R"cc( - inline const $pb$::RepeatedField& $Msg$::_internal_$name$() const { + inline const $pb$::RepeatedField& $Msg$::_internal_$name_internal$() + const { $TsanDetectConcurrentRead$; return $field_$; } - inline $pb$::RepeatedField* $Msg$::_internal_mutable_$name$() { + inline $pb$::RepeatedField* $Msg$::_internal_mutable_$name_internal$() { $TsanDetectConcurrentRead$; return &$field_$; } diff --git a/src/google/protobuf/compiler/cpp/field_generators/map_field.cc b/src/google/protobuf/compiler/cpp/field_generators/map_field.cc index 13bcd63fe00ae..79690963a0960 100644 --- a/src/google/protobuf/compiler/cpp/field_generators/map_field.cc +++ b/src/google/protobuf/compiler/cpp/field_generators/map_field.cc @@ -215,7 +215,7 @@ void Map::GenerateAccessorDeclarations(io::Printer* p) const { void Map::GenerateInlineAccessorDefinitions(io::Printer* p) const { p->Emit(R"cc( - inline const $Map$& $Msg$::_internal_$name$() const { + inline const $Map$& $Msg$::_internal_$name_internal$() const { $TsanDetectConcurrentRead$; return $field_$.GetMap(); } @@ -224,11 +224,11 @@ void Map::GenerateInlineAccessorDefinitions(io::Printer* p) const { inline const $Map$& $Msg$::$name$() const ABSL_ATTRIBUTE_LIFETIME_BOUND { $annotate_get$; // @@protoc_insertion_point(field_map:$pkg.Msg.field$) - return _internal_$name$(); + return _internal_$name_internal$(); } )cc"); p->Emit(R"cc( - inline $Map$* $Msg$::_internal_mutable_$name$() { + inline $Map$* $Msg$::_internal_mutable_$name_internal$() { $PrepareSplitMessageForWrite$; $TsanDetectConcurrentMutation$; return $field_$.MutableMap(); @@ -238,7 +238,7 @@ void Map::GenerateInlineAccessorDefinitions(io::Printer* p) const { inline $Map$* $Msg$::mutable_$name$() ABSL_ATTRIBUTE_LIFETIME_BOUND { $annotate_mutable$; // @@protoc_insertion_point(field_mutable_map:$pkg.Msg.field$) - return _internal_mutable_$name$(); + return _internal_mutable_$name_internal$(); } )cc"); } diff --git a/src/google/protobuf/compiler/cpp/field_generators/message_field.cc b/src/google/protobuf/compiler/cpp/field_generators/message_field.cc index b2b20dec3e0e0..318cf4c598e4d 100644 --- a/src/google/protobuf/compiler/cpp/field_generators/message_field.cc +++ b/src/google/protobuf/compiler/cpp/field_generators/message_field.cc @@ -198,7 +198,7 @@ void SingularMessage::GenerateInlineAccessorDefinitions(io::Printer* p) const { }}, }, R"cc( - inline const $Submsg$& $Msg$::_internal_$name$() const { + inline const $Submsg$& $Msg$::_internal_$name_internal$() const { $TsanDetectConcurrentRead$; $StrongRef$; const $Submsg$* p = $cast_field_$; @@ -207,7 +207,7 @@ void SingularMessage::GenerateInlineAccessorDefinitions(io::Printer* p) const { inline const $Submsg$& $Msg$::$name$() const ABSL_ATTRIBUTE_LIFETIME_BOUND { $annotate_get$; // @@protoc_insertion_point(field_get:$pkg.Msg.field$) - return _internal_$name$(); + return _internal_$name_internal$(); } inline void $Msg$::unsafe_arena_set_allocated_$name$($Submsg$* value) { $TsanDetectConcurrentMutation$; @@ -256,7 +256,7 @@ void SingularMessage::GenerateInlineAccessorDefinitions(io::Printer* p) const { $field_$ = nullptr; return temp; } - inline $Submsg$* $Msg$::_internal_mutable_$name$() { + inline $Submsg$* $Msg$::_internal_mutable_$name_internal$() { $TsanDetectConcurrentMutation$; $StrongRef$; if ($field_$ == nullptr) { @@ -270,7 +270,7 @@ void SingularMessage::GenerateInlineAccessorDefinitions(io::Printer* p) const { //~ able to prepare split message allocation. $PrepareSplitMessageForWrite$; $set_hasbit$; - $Submsg$* _msg = _internal_mutable_$name$(); + $Submsg$* _msg = _internal_mutable_$name_internal$(); $annotate_mutable$; // @@protoc_insertion_point(field_mutable:$pkg.Msg.field$) return _msg; @@ -539,7 +539,7 @@ void OneofMessage::GenerateInlineAccessorDefinitions(io::Printer* p) const { } )cc"); p->Emit(R"cc( - inline const $Submsg$& $Msg$::_internal_$name$() const { + inline const $Submsg$& $Msg$::_internal_$name_internal$() const { $StrongRef$; return $has_field$ ? *$cast_field_$ : reinterpret_cast<$Submsg$&>($kDefault$); } @@ -548,7 +548,7 @@ void OneofMessage::GenerateInlineAccessorDefinitions(io::Printer* p) const { inline const $Submsg$& $Msg$::$name$() const ABSL_ATTRIBUTE_LIFETIME_BOUND { $annotate_get$; // @@protoc_insertion_point(field_get:$pkg.Msg.field$) - return _internal_$name$(); + return _internal_$name_internal$(); } )cc"); p->Emit(R"cc( @@ -573,7 +573,7 @@ void OneofMessage::GenerateInlineAccessorDefinitions(io::Printer* p) const { // set the new value. clear_$oneof_name$(); if (value) { - set_has_$name$(); + set_has_$name_internal$(); $field_$ = $weak_cast$(value); } $annotate_set$; @@ -581,11 +581,11 @@ void OneofMessage::GenerateInlineAccessorDefinitions(io::Printer* p) const { } )cc"); p->Emit(R"cc( - inline $Submsg$* $Msg$::_internal_mutable_$name$() { + inline $Submsg$* $Msg$::_internal_mutable_$name_internal$() { $StrongRef$; if ($not_has_field$) { clear_$oneof_name$(); - set_has_$name$(); + set_has_$name_internal$(); $field_$ = $weak_cast$($superclass$::DefaultConstruct<$Submsg$>(GetArena())); } @@ -594,7 +594,7 @@ void OneofMessage::GenerateInlineAccessorDefinitions(io::Printer* p) const { )cc"); p->Emit(R"cc( inline $Submsg$* $Msg$::mutable_$name$() ABSL_ATTRIBUTE_LIFETIME_BOUND { - $Submsg$* _msg = _internal_mutable_$name$(); + $Submsg$* _msg = _internal_mutable_$name_internal$(); $annotate_mutable$; // @@protoc_insertion_point(field_mutable:$pkg.Msg.field$) return _msg; @@ -745,7 +745,7 @@ void RepeatedMessage::GenerateInlineAccessorDefinitions(io::Printer* p) const { $annotate_mutable$; // @@protoc_insertion_point(field_mutable:$pkg.Msg.field$) $StrongRef$; - return _internal_mutable_$name$()->Mutable(index); + return _internal_mutable_$name_internal$()->Mutable(index); } )cc"); p->Emit(R"cc( @@ -755,7 +755,7 @@ void RepeatedMessage::GenerateInlineAccessorDefinitions(io::Printer* p) const { // @@protoc_insertion_point(field_mutable_list:$pkg.Msg.field$) $StrongRef$; $TsanDetectConcurrentMutation$; - return _internal_mutable_$name$(); + return _internal_mutable_$name_internal$(); } )cc"); p->Emit( @@ -774,13 +774,13 @@ void RepeatedMessage::GenerateInlineAccessorDefinitions(io::Printer* p) const { $annotate_get$; // @@protoc_insertion_point(field_get:$pkg.Msg.field$) $StrongRef$; - return _internal_$name$().$Get$(index$GetExtraArg$); + return _internal_$name_internal$().$Get$(index$GetExtraArg$); } )cc"); p->Emit(R"cc( inline $Submsg$* $Msg$::add_$name$() ABSL_ATTRIBUTE_LIFETIME_BOUND { $TsanDetectConcurrentMutation$; - $Submsg$* _add = _internal_mutable_$name$()->Add(); + $Submsg$* _add = _internal_mutable_$name_internal$()->Add(); $annotate_add_mutable$; // @@protoc_insertion_point(field_add:$pkg.Msg.field$) return _add; @@ -792,19 +792,19 @@ void RepeatedMessage::GenerateInlineAccessorDefinitions(io::Printer* p) const { $annotate_list$; // @@protoc_insertion_point(field_list:$pkg.Msg.field$) $StrongRef$; - return _internal_$name$(); + return _internal_$name_internal$(); } )cc"); if (should_split()) { p->Emit(R"cc( inline const $pb$::$Weak$RepeatedPtrField<$Submsg$>& - $Msg$::_internal$_weak$_$name$() const { + $Msg$::_internal$_weak$_$name_internal$() const { $TsanDetectConcurrentRead$; return *$field_$; } inline $pb$::$Weak$RepeatedPtrField<$Submsg$>* - $Msg$::_internal_mutable$_weak$_$name$() { + $Msg$::_internal_mutable$_weak$_$name_internal$() { $TsanDetectConcurrentRead$; $PrepareSplitMessageForWrite$; if ($field_$.IsDefault()) { @@ -817,12 +817,12 @@ void RepeatedMessage::GenerateInlineAccessorDefinitions(io::Printer* p) const { } else { p->Emit(R"cc( inline const $pb$::$Weak$RepeatedPtrField<$Submsg$>& - $Msg$::_internal$_weak$_$name$() const { + $Msg$::_internal$_weak$_$name_internal$() const { $TsanDetectConcurrentRead$; return $field_$; } inline $pb$::$Weak$RepeatedPtrField<$Submsg$>* - $Msg$::_internal_mutable$_weak$_$name$() { + $Msg$::_internal_mutable$_weak$_$name_internal$() { $TsanDetectConcurrentRead$; return &$field_$; } @@ -830,12 +830,13 @@ void RepeatedMessage::GenerateInlineAccessorDefinitions(io::Printer* p) const { } if (is_weak()) { p->Emit(R"cc( - inline const $pb$::RepeatedPtrField<$Submsg$>& $Msg$::_internal_$name$() - const { - return _internal_weak_$name$().weak; + inline const $pb$::RepeatedPtrField<$Submsg$>& + $Msg$::_internal_$name_internal$() const { + return _internal_weak_$name_internal$().weak; } - inline $pb$::RepeatedPtrField<$Submsg$>* $Msg$::_internal_mutable_$name$() { - return &_internal_mutable_weak_$name$()->weak; + inline $pb$::RepeatedPtrField<$Submsg$>* + $Msg$::_internal_mutable_$name_internal$() { + return &_internal_mutable_weak_$name_internal$()->weak; } )cc"); } diff --git a/src/google/protobuf/compiler/cpp/field_generators/primitive_field.cc b/src/google/protobuf/compiler/cpp/field_generators/primitive_field.cc index eaa00a17a8494..e0e1ff3ca4fcb 100644 --- a/src/google/protobuf/compiler/cpp/field_generators/primitive_field.cc +++ b/src/google/protobuf/compiler/cpp/field_generators/primitive_field.cc @@ -190,7 +190,7 @@ void SingularPrimitive::GenerateInlineAccessorDefinitions( inline $Type$ $Msg$::$name$() const { $annotate_get$; // @@protoc_insertion_point(field_get:$pkg.Msg.field$) - return _internal_$name$(); + return _internal_$name_internal$(); } )cc"); @@ -200,13 +200,13 @@ void SingularPrimitive::GenerateInlineAccessorDefinitions( $PrepareSplitMessageForWrite$; if ($not_has_field$) { clear_$oneof_name$(); - set_has_$name$(); + set_has_$name_internal$(); } $field_$ = value; $annotate_set$; // @@protoc_insertion_point(field_set:$pkg.Msg.field$) } - inline $Type$ $Msg$::_internal_$name$() const { + inline $Type$ $Msg$::_internal_$name_internal$() const { if ($has_field$) { return $field_$; } @@ -217,16 +217,16 @@ void SingularPrimitive::GenerateInlineAccessorDefinitions( p->Emit(R"cc( inline void $Msg$::set_$name$($Type$ value) { $PrepareSplitMessageForWrite$; - _internal_set_$name$(value); + _internal_set_$name_internal$(value); $set_hasbit$; $annotate_set$; // @@protoc_insertion_point(field_set:$pkg.Msg.field$) } - inline $Type$ $Msg$::_internal_$name$() const { + inline $Type$ $Msg$::_internal_$name_internal$() const { $TsanDetectConcurrentRead$; return $field_$; } - inline void $Msg$::_internal_set_$name$($Type$ value) { + inline void $Msg$::_internal_set_$name_internal$($Type$ value) { $TsanDetectConcurrentMutation$; $field_$ = value; } @@ -469,20 +469,20 @@ void RepeatedPrimitive::GenerateInlineAccessorDefinitions( inline $Type$ $Msg$::$name$(int index) const { $annotate_get$; // @@protoc_insertion_point(field_get:$pkg.Msg.field$) - return _internal_$name$().Get(index); + return _internal_$name_internal$().Get(index); } )cc"); p->Emit(R"cc( inline void $Msg$::set_$name$(int index, $Type$ value) { $annotate_set$; - _internal_mutable_$name$()->Set(index, value); + _internal_mutable_$name_internal$()->Set(index, value); // @@protoc_insertion_point(field_set:$pkg.Msg.field$) } )cc"); p->Emit(R"cc( inline void $Msg$::add_$name$($Type$ value) { $TsanDetectConcurrentMutation$; - _internal_mutable_$name$()->Add(value); + _internal_mutable_$name_internal$()->Add(value); $annotate_add$; // @@protoc_insertion_point(field_add:$pkg.Msg.field$) } @@ -492,7 +492,7 @@ void RepeatedPrimitive::GenerateInlineAccessorDefinitions( ABSL_ATTRIBUTE_LIFETIME_BOUND { $annotate_list$; // @@protoc_insertion_point(field_list:$pkg.Msg.field$) - return _internal_$name$(); + return _internal_$name_internal$(); } )cc"); p->Emit(R"cc( @@ -501,18 +501,18 @@ void RepeatedPrimitive::GenerateInlineAccessorDefinitions( $annotate_mutable_list$; // @@protoc_insertion_point(field_mutable_list:$pkg.Msg.field$) $TsanDetectConcurrentMutation$; - return _internal_mutable_$name$(); + return _internal_mutable_$name_internal$(); } )cc"); if (should_split()) { p->Emit(R"cc( - inline const $pb$::RepeatedField<$Type$>& $Msg$::_internal_$name$() - const { + inline const $pb$::RepeatedField<$Type$>& + $Msg$::_internal_$name_internal$() const { $TsanDetectConcurrentRead$; return *$field_$; } - inline $pb$::RepeatedField<$Type$>* $Msg$::_internal_mutable_$name$() { + inline $pb$::RepeatedField<$Type$>* $Msg$::_internal_mutable_$name_internal$() { $TsanDetectConcurrentRead$; $PrepareSplitMessageForWrite$; if ($field_$.IsDefault()) { @@ -524,12 +524,12 @@ void RepeatedPrimitive::GenerateInlineAccessorDefinitions( )cc"); } else { p->Emit(R"cc( - inline const $pb$::RepeatedField<$Type$>& $Msg$::_internal_$name$() - const { + inline const $pb$::RepeatedField<$Type$>& + $Msg$::_internal_$name_internal$() const { $TsanDetectConcurrentRead$; return $field_$; } - inline $pb$::RepeatedField<$Type$>* $Msg$::_internal_mutable_$name$() { + inline $pb$::RepeatedField<$Type$>* $Msg$::_internal_mutable_$name_internal$() { $TsanDetectConcurrentRead$; return &$field_$; } diff --git a/src/google/protobuf/compiler/cpp/field_generators/string_field.cc b/src/google/protobuf/compiler/cpp/field_generators/string_field.cc index 7464d81a2bcf8..cd1049eea24df 100644 --- a/src/google/protobuf/compiler/cpp/field_generators/string_field.cc +++ b/src/google/protobuf/compiler/cpp/field_generators/string_field.cc @@ -300,7 +300,7 @@ void UpdateHasbitSet(io::Printer* p, bool is_oneof) { if ($not_has_field$) { clear_$oneof_name$(); - set_has_$name$(); + set_has_$name_internal$(); $field_$.InitDefault(); } )cc"); @@ -312,7 +312,7 @@ void ArgsForSetter(io::Printer* p, bool inlined) { return; } p->Emit( - "GetArena(), _internal_$name$_donated(), " + "GetArena(), _internal_$name_internal$_donated(), " "&$donating_states_word$, $mask_for_undonate$, this"); } @@ -342,7 +342,7 @@ void SingularString::ReleaseImpl(io::Printer* p) const { } $clear_hasbit$; - return $field_$.Release(GetArena(), _internal_$name$_donated()); + return $field_$.Release(GetArena(), _internal_$name_internal$_donated()); )cc"); return; } @@ -377,7 +377,7 @@ void SingularString::SetAllocatedImpl(io::Printer* p) const { clear_$oneof_name$(); } if (value != nullptr) { - set_has_$name$(); + set_has_$name_internal$(); $field_$.InitAllocated(value, GetArena()); } )cc"); @@ -451,7 +451,7 @@ void SingularString::GenerateInlineAccessorDefinitions(io::Printer* p) const { $annotate_get$; // @@protoc_insertion_point(field_get:$pkg.Msg.field$) $if_IsDefault$; - return _internal_$name$(); + return _internal_$name_internal$(); } template inline PROTOBUF_ALWAYS_INLINE void $Msg$::set_$name$(Arg_&& arg, @@ -465,24 +465,24 @@ void SingularString::GenerateInlineAccessorDefinitions(io::Printer* p) const { } inline std::string* $Msg$::mutable_$name$() ABSL_ATTRIBUTE_LIFETIME_BOUND { $PrepareSplitMessageForWrite$; - std::string* _s = _internal_mutable_$name$(); + std::string* _s = _internal_mutable_$name_internal$(); $annotate_mutable$; // @@protoc_insertion_point(field_mutable:$pkg.Msg.field$) return _s; } - inline const std::string& $Msg$::_internal_$name$() const { + inline const std::string& $Msg$::_internal_$name_internal$() const { $TsanDetectConcurrentRead$; $check_hasbit$; return $field_$.Get(); } - inline void $Msg$::_internal_set_$name$(const std::string& value) { + inline void $Msg$::_internal_set_$name_internal$(const std::string& value) { $TsanDetectConcurrentMutation$; $update_hasbit$; //~ Don't use $Set$ here; we always want the std::string variant //~ regardless of whether this is a `bytes` field. $field_$.Set(value, $set_args$); } - inline std::string* $Msg$::_internal_mutable_$name$() { + inline std::string* $Msg$::_internal_mutable_$name_internal$() { $TsanDetectConcurrentMutation$; $update_hasbit$; return $field_$.Mutable($lazy_args$, $set_args$); @@ -505,7 +505,7 @@ void SingularString::GenerateInlineAccessorDefinitions(io::Printer* p) const { if (is_inlined()) { p->Emit(R"cc( - inline bool $Msg$::_internal_$name$_donated() const { + inline bool $Msg$::_internal_$name_internal$_donated() const { return $inlined_string_donated$; } )cc"); @@ -871,7 +871,7 @@ void RepeatedString::GenerateInlineAccessorDefinitions(io::Printer* p) const { inline std::string* $Msg$::add_$name$() ABSL_ATTRIBUTE_LIFETIME_BOUND { $TsanDetectConcurrentMutation$; - std::string* _s = _internal_mutable_$name$()->Add(); + std::string* _s = _internal_mutable_$name_internal$()->Add(); $annotate_add_mutable$; // @@protoc_insertion_point(field_add_mutable:$pkg.Msg.field$) return _s; @@ -880,72 +880,73 @@ void RepeatedString::GenerateInlineAccessorDefinitions(io::Printer* p) const { ABSL_ATTRIBUTE_LIFETIME_BOUND { $annotate_get$; // @@protoc_insertion_point(field_get:$pkg.Msg.field$) - return _internal_$name$().$Get$(index$GetExtraArg$); + return _internal_$name_internal$().$Get$(index$GetExtraArg$); } inline std::string* $Msg$::mutable_$name$(int index) ABSL_ATTRIBUTE_LIFETIME_BOUND { $annotate_mutable$; // @@protoc_insertion_point(field_mutable:$pkg.Msg.field$) - return _internal_mutable_$name$()->Mutable(index); + return _internal_mutable_$name_internal$()->Mutable(index); } inline void $Msg$::set_$name$(int index, const std::string& value) { - _internal_mutable_$name$()->Mutable(index)->assign(value); + _internal_mutable_$name_internal$()->Mutable(index)->assign(value); $annotate_set$; // @@protoc_insertion_point(field_set:$pkg.Msg.field$) } inline void $Msg$::set_$name$(int index, std::string&& value) { - _internal_mutable_$name$()->Mutable(index)->assign(std::move(value)); + _internal_mutable_$name_internal$()->Mutable(index)->assign(std::move(value)); $annotate_set$; // @@protoc_insertion_point(field_set:$pkg.Msg.field$) } inline void $Msg$::set_$name$(int index, const char* value) { $DCHK$(value != nullptr); - _internal_mutable_$name$()->Mutable(index)->assign(value); + _internal_mutable_$name_internal$()->Mutable(index)->assign(value); $annotate_set$; // @@protoc_insertion_point(field_set_char:$pkg.Msg.field$) } inline void $Msg$::set_$name$(int index, const $byte$* value, std::size_t size) { - _internal_mutable_$name$()->Mutable(index)->assign( + _internal_mutable_$name_internal$()->Mutable(index)->assign( reinterpret_cast(value), size); $annotate_set$; // @@protoc_insertion_point(field_set_pointer:$pkg.Msg.field$) } inline void $Msg$::set_$name$(int index, absl::string_view value) { - _internal_mutable_$name$()->Mutable(index)->assign(value.data(), - value.size()); + _internal_mutable_$name_internal$()->Mutable(index)->assign( + value.data(), value.size()); $annotate_set$; // @@protoc_insertion_point(field_set_string_piece:$pkg.Msg.field$) } inline void $Msg$::add_$name$(const std::string& value) { $TsanDetectConcurrentMutation$; - _internal_mutable_$name$()->Add()->assign(value); + _internal_mutable_$name_internal$()->Add()->assign(value); $annotate_add$; // @@protoc_insertion_point(field_add:$pkg.Msg.field$) } inline void $Msg$::add_$name$(std::string&& value) { $TsanDetectConcurrentMutation$; - _internal_mutable_$name$()->Add(std::move(value)); + _internal_mutable_$name_internal$()->Add(std::move(value)); $annotate_add$; // @@protoc_insertion_point(field_add:$pkg.Msg.field$) } inline void $Msg$::add_$name$(const char* value) { $DCHK$(value != nullptr); $TsanDetectConcurrentMutation$; - _internal_mutable_$name$()->Add()->assign(value); + _internal_mutable_$name_internal$()->Add()->assign(value); $annotate_add$; // @@protoc_insertion_point(field_add_char:$pkg.Msg.field$) } inline void $Msg$::add_$name$(const $byte$* value, std::size_t size) { $TsanDetectConcurrentMutation$; - _internal_mutable_$name$()->Add()->assign( + _internal_mutable_$name_internal$()->Add()->assign( reinterpret_cast(value), size); $annotate_add$; // @@protoc_insertion_point(field_add_pointer:$pkg.Msg.field$) } inline void $Msg$::add_$name$(absl::string_view value) { $TsanDetectConcurrentMutation$; - _internal_mutable_$name$()->Add()->assign(value.data(), value.size()); + _internal_mutable_$name_internal$()->Add()->assign(value.data(), + value.size()); $annotate_add$; // @@protoc_insertion_point(field_add_string_piece:$pkg.Msg.field$) } @@ -953,24 +954,25 @@ void RepeatedString::GenerateInlineAccessorDefinitions(io::Printer* p) const { $Msg$::$name$() const ABSL_ATTRIBUTE_LIFETIME_BOUND { $annotate_list$; // @@protoc_insertion_point(field_list:$pkg.Msg.field$) - return _internal_$name$(); + return _internal_$name_internal$(); } inline ::$proto_ns$::RepeatedPtrField* $Msg$::mutable_$name$() ABSL_ATTRIBUTE_LIFETIME_BOUND { $annotate_mutable_list$; // @@protoc_insertion_point(field_mutable_list:$pkg.Msg.field$) $TsanDetectConcurrentMutation$; - return _internal_mutable_$name$(); + return _internal_mutable_$name_internal$(); } )cc"); if (ShouldSplit(descriptor_, options_)) { p->Emit(R"cc( inline const $pb$::RepeatedPtrField& - $Msg$::_internal_$name$() const { + $Msg$::_internal_$name_internal$() const { $TsanDetectConcurrentRead$; return *$field_$; } - inline $pb$::RepeatedPtrField* $Msg$::_internal_mutable_$name$() { + inline $pb$::RepeatedPtrField* + $Msg$::_internal_mutable_$name_internal$() { $TsanDetectConcurrentRead$; $PrepareSplitMessageForWrite$; if ($field_$.IsDefault()) { @@ -984,12 +986,12 @@ void RepeatedString::GenerateInlineAccessorDefinitions(io::Printer* p) const { } else { p->Emit(R"cc( inline const ::$proto_ns$::RepeatedPtrField& - $Msg$::_internal_$name$() const { + $Msg$::_internal_$name_internal$() const { $TsanDetectConcurrentRead$; return $field_$; } inline ::$proto_ns$::RepeatedPtrField* - $Msg$::_internal_mutable_$name$() { + $Msg$::_internal_mutable_$name_internal$() { $TsanDetectConcurrentRead$; return &$field_$; } diff --git a/src/google/protobuf/compiler/cpp/message.cc b/src/google/protobuf/compiler/cpp/message.cc index 2372b36364fa6..cbd5aa9d5e281 100644 --- a/src/google/protobuf/compiler/cpp/message.cc +++ b/src/google/protobuf/compiler/cpp/message.cc @@ -29,6 +29,7 @@ #include "absl/log/absl_log.h" #include "absl/strings/ascii.h" #include "absl/strings/escaping.h" +#include "absl/strings/match.h" #include "absl/strings/str_cat.h" #include "absl/strings/str_format.h" #include "absl/strings/str_join.h" @@ -1060,7 +1061,7 @@ void MessageGenerator::GenerateOneofMemberHasBits(const FieldDescriptor* field, } if (HasInternalHasMethod(field)) { p->Emit(R"cc( - inline bool $classname$::_internal_has_$name$() const { + inline bool $classname$::_internal_has_$name_internal$() const { return $has_field$; } )cc"); @@ -1068,7 +1069,7 @@ void MessageGenerator::GenerateOneofMemberHasBits(const FieldDescriptor* field, // set_has_$name$() for oneof fields is always private; hence should not be // annotated. p->Emit(R"cc( - inline void $classname$::set_has_$name$() { + inline void $classname$::set_has_$name_internal$() { $oneof_case$[$oneof_index$] = k$field_name$; } )cc"); @@ -1120,22 +1121,81 @@ void MessageGenerator::GenerateFieldClear(const FieldDescriptor* field, )cc"); } +namespace { + +class AccessorVerifier { + public: + using SourceLocation = io::Printer::SourceLocation; + + AccessorVerifier(const FieldDescriptor* field) : field_(field) {} + ~AccessorVerifier() { + ABSL_CHECK(!needs_annotate_) << Error(SourceLocation::current()); + } + + void operator()(absl::string_view label, io::Printer::SourceLocation loc) { + if (label == "name" || label == "release_name") { + // All accessors use $name$ or $release_name$ when constructing the + // function name. We hook into those to determine that an accessor is + // starting. + ABSL_CHECK(!needs_annotate_) << Error(loc); + loc_ = loc; + needs_annotate_ = true; + } else if (absl::StartsWith(label, "annotate")) { + // All annotation labels start with `annotate`. Eg `annotate_get`. + ABSL_CHECK(needs_annotate_) << Error(loc); + loc_ = loc; + needs_annotate_ = false; + } + } + + private: + std::string Error(SourceLocation loc) const { + return absl::StrFormat("Field %s printed from %s:%d (prev %s:%d)\n", + field_->full_name(), loc.file_name(), loc.line(), + loc_.file_name(), loc_.line()); + } + + bool needs_annotate_ = false; + // We keep these fields for error reporting. + const FieldDescriptor* field_; + // On error, we report two locations: the current one and the last one. This + // can help determine where the bug is. For example, if we see "name" twice in + // a row, the bug is likely in the "last" one and not the current one because + // it means the previous accessor didn't add the required code. + SourceLocation loc_; +}; + +} // namespace + void MessageGenerator::GenerateFieldAccessorDefinitions(io::Printer* p) { p->Emit("// $classname$\n\n"); for (auto field : FieldRange(descriptor_)) { + // We use a print listener to verify that the field generators properly add + // the right annotations. This is only a verification step aimed to prevent + // bugs where we have lack of test coverage. Note that this will verify the + // annotations even when the particular feature is not on because we look at + // the substitution variables, not the substitution result. + // The check is a state machine that verifies that every substitution for + // `name` is followed by one and only one for needed annotations. False + // positives are accessors that are using $name$ for an internal name. For + // those you can use $name_internal$ which is the same substitution but not + // tracked by the verifier. + const auto accessor_verifier = + p->WithSubstitutionListener(AccessorVerifier(field)); + PrintFieldComment(Formatter{p}, field, options_); auto v = p->WithVars(FieldVars(field, options_)); auto t = p->WithVars(MakeTrackerCalls(field, options_)); if (field->is_repeated()) { p->Emit(R"cc( - inline int $classname$::_internal_$name$_size() const { - return _internal_$name$().size(); + inline int $classname$::_internal_$name_internal$_size() const { + return _internal_$name_internal$().size(); } inline int $classname$::$name$_size() const { $annotate_size$; - return _internal_$name$_size(); + return _internal_$name_internal$_size(); } )cc"); } else if (field->real_containing_oneof()) { diff --git a/src/google/protobuf/compiler/plugin.pb.h b/src/google/protobuf/compiler/plugin.pb.h index 7b036ff75484f..49252c37ec61a 100644 --- a/src/google/protobuf/compiler/plugin.pb.h +++ b/src/google/protobuf/compiler/plugin.pb.h @@ -1295,8 +1295,8 @@ inline void CodeGeneratorRequest::set_file_to_generate(int index, const char* va // @@protoc_insertion_point(field_set_pointer:google.protobuf.compiler.CodeGeneratorRequest.file_to_generate) } inline void CodeGeneratorRequest::set_file_to_generate(int index, absl::string_view value) { - _internal_mutable_file_to_generate()->Mutable(index)->assign(value.data(), - value.size()); + _internal_mutable_file_to_generate()->Mutable(index)->assign( + value.data(), value.size()); // @@protoc_insertion_point(field_set_string_piece:google.protobuf.compiler.CodeGeneratorRequest.file_to_generate) } inline void CodeGeneratorRequest::add_file_to_generate(const std::string& value) { @@ -1323,7 +1323,8 @@ inline void CodeGeneratorRequest::add_file_to_generate(const char* value, std::s } inline void CodeGeneratorRequest::add_file_to_generate(absl::string_view value) { PROTOBUF_TSAN_WRITE(&_impl_._tsan_detect_race); - _internal_mutable_file_to_generate()->Add()->assign(value.data(), value.size()); + _internal_mutable_file_to_generate()->Add()->assign(value.data(), + value.size()); // @@protoc_insertion_point(field_add_string_piece:google.protobuf.compiler.CodeGeneratorRequest.file_to_generate) } inline const ::google::protobuf::RepeatedPtrField& diff --git a/src/google/protobuf/descriptor.pb.h b/src/google/protobuf/descriptor.pb.h index 765de53a7674d..9409875173066 100644 --- a/src/google/protobuf/descriptor.pb.h +++ b/src/google/protobuf/descriptor.pb.h @@ -10783,8 +10783,8 @@ inline void FileDescriptorProto::set_dependency(int index, const char* value, // @@protoc_insertion_point(field_set_pointer:google.protobuf.FileDescriptorProto.dependency) } inline void FileDescriptorProto::set_dependency(int index, absl::string_view value) { - _internal_mutable_dependency()->Mutable(index)->assign(value.data(), - value.size()); + _internal_mutable_dependency()->Mutable(index)->assign( + value.data(), value.size()); // @@protoc_insertion_point(field_set_string_piece:google.protobuf.FileDescriptorProto.dependency) } inline void FileDescriptorProto::add_dependency(const std::string& value) { @@ -10811,7 +10811,8 @@ inline void FileDescriptorProto::add_dependency(const char* value, std::size_t s } inline void FileDescriptorProto::add_dependency(absl::string_view value) { PROTOBUF_TSAN_WRITE(&_impl_._tsan_detect_race); - _internal_mutable_dependency()->Add()->assign(value.data(), value.size()); + _internal_mutable_dependency()->Add()->assign(value.data(), + value.size()); // @@protoc_insertion_point(field_add_string_piece:google.protobuf.FileDescriptorProto.dependency) } inline const ::google::protobuf::RepeatedPtrField& @@ -10871,8 +10872,8 @@ inline ::google::protobuf::RepeatedField<::int32_t>* FileDescriptorProto::mutabl PROTOBUF_TSAN_WRITE(&_impl_._tsan_detect_race); return _internal_mutable_public_dependency(); } -inline const ::google::protobuf::RepeatedField<::int32_t>& FileDescriptorProto::_internal_public_dependency() - const { +inline const ::google::protobuf::RepeatedField<::int32_t>& +FileDescriptorProto::_internal_public_dependency() const { PROTOBUF_TSAN_READ(&_impl_._tsan_detect_race); return _impl_.public_dependency_; } @@ -10916,8 +10917,8 @@ inline ::google::protobuf::RepeatedField<::int32_t>* FileDescriptorProto::mutabl PROTOBUF_TSAN_WRITE(&_impl_._tsan_detect_race); return _internal_mutable_weak_dependency(); } -inline const ::google::protobuf::RepeatedField<::int32_t>& FileDescriptorProto::_internal_weak_dependency() - const { +inline const ::google::protobuf::RepeatedField<::int32_t>& +FileDescriptorProto::_internal_weak_dependency() const { PROTOBUF_TSAN_READ(&_impl_._tsan_detect_race); return _impl_.weak_dependency_; } @@ -12192,8 +12193,8 @@ inline void DescriptorProto::set_reserved_name(int index, const char* value, // @@protoc_insertion_point(field_set_pointer:google.protobuf.DescriptorProto.reserved_name) } inline void DescriptorProto::set_reserved_name(int index, absl::string_view value) { - _internal_mutable_reserved_name()->Mutable(index)->assign(value.data(), - value.size()); + _internal_mutable_reserved_name()->Mutable(index)->assign( + value.data(), value.size()); // @@protoc_insertion_point(field_set_string_piece:google.protobuf.DescriptorProto.reserved_name) } inline void DescriptorProto::add_reserved_name(const std::string& value) { @@ -12220,7 +12221,8 @@ inline void DescriptorProto::add_reserved_name(const char* value, std::size_t si } inline void DescriptorProto::add_reserved_name(absl::string_view value) { PROTOBUF_TSAN_WRITE(&_impl_._tsan_detect_race); - _internal_mutable_reserved_name()->Add()->assign(value.data(), value.size()); + _internal_mutable_reserved_name()->Add()->assign(value.data(), + value.size()); // @@protoc_insertion_point(field_add_string_piece:google.protobuf.DescriptorProto.reserved_name) } inline const ::google::protobuf::RepeatedPtrField& @@ -13847,8 +13849,8 @@ inline void EnumDescriptorProto::set_reserved_name(int index, const char* value, // @@protoc_insertion_point(field_set_pointer:google.protobuf.EnumDescriptorProto.reserved_name) } inline void EnumDescriptorProto::set_reserved_name(int index, absl::string_view value) { - _internal_mutable_reserved_name()->Mutable(index)->assign(value.data(), - value.size()); + _internal_mutable_reserved_name()->Mutable(index)->assign( + value.data(), value.size()); // @@protoc_insertion_point(field_set_string_piece:google.protobuf.EnumDescriptorProto.reserved_name) } inline void EnumDescriptorProto::add_reserved_name(const std::string& value) { @@ -13875,7 +13877,8 @@ inline void EnumDescriptorProto::add_reserved_name(const char* value, std::size_ } inline void EnumDescriptorProto::add_reserved_name(absl::string_view value) { PROTOBUF_TSAN_WRITE(&_impl_._tsan_detect_race); - _internal_mutable_reserved_name()->Add()->assign(value.data(), value.size()); + _internal_mutable_reserved_name()->Add()->assign(value.data(), + value.size()); // @@protoc_insertion_point(field_add_string_piece:google.protobuf.EnumDescriptorProto.reserved_name) } inline const ::google::protobuf::RepeatedPtrField& @@ -16489,7 +16492,8 @@ inline ::google::protobuf::RepeatedField* FieldOptions::mutable_targets() PROTOBUF_TSAN_WRITE(&_impl_._tsan_detect_race); return _internal_mutable_targets(); } -inline const ::google::protobuf::RepeatedField& FieldOptions::_internal_targets() const { +inline const ::google::protobuf::RepeatedField& FieldOptions::_internal_targets() + const { PROTOBUF_TSAN_READ(&_impl_._tsan_detect_race); return _impl_.targets_; } @@ -18572,8 +18576,8 @@ inline ::google::protobuf::RepeatedField<::int32_t>* SourceCodeInfo_Location::mu PROTOBUF_TSAN_WRITE(&_impl_._tsan_detect_race); return _internal_mutable_path(); } -inline const ::google::protobuf::RepeatedField<::int32_t>& SourceCodeInfo_Location::_internal_path() - const { +inline const ::google::protobuf::RepeatedField<::int32_t>& +SourceCodeInfo_Location::_internal_path() const { PROTOBUF_TSAN_READ(&_impl_._tsan_detect_race); return _impl_.path_; } @@ -18617,8 +18621,8 @@ inline ::google::protobuf::RepeatedField<::int32_t>* SourceCodeInfo_Location::mu PROTOBUF_TSAN_WRITE(&_impl_._tsan_detect_race); return _internal_mutable_span(); } -inline const ::google::protobuf::RepeatedField<::int32_t>& SourceCodeInfo_Location::_internal_span() - const { +inline const ::google::protobuf::RepeatedField<::int32_t>& +SourceCodeInfo_Location::_internal_span() const { PROTOBUF_TSAN_READ(&_impl_._tsan_detect_race); return _impl_.span_; } @@ -18817,8 +18821,8 @@ inline void SourceCodeInfo_Location::set_leading_detached_comments(int index, co // @@protoc_insertion_point(field_set_pointer:google.protobuf.SourceCodeInfo.Location.leading_detached_comments) } inline void SourceCodeInfo_Location::set_leading_detached_comments(int index, absl::string_view value) { - _internal_mutable_leading_detached_comments()->Mutable(index)->assign(value.data(), - value.size()); + _internal_mutable_leading_detached_comments()->Mutable(index)->assign( + value.data(), value.size()); // @@protoc_insertion_point(field_set_string_piece:google.protobuf.SourceCodeInfo.Location.leading_detached_comments) } inline void SourceCodeInfo_Location::add_leading_detached_comments(const std::string& value) { @@ -18845,7 +18849,8 @@ inline void SourceCodeInfo_Location::add_leading_detached_comments(const char* v } inline void SourceCodeInfo_Location::add_leading_detached_comments(absl::string_view value) { PROTOBUF_TSAN_WRITE(&_impl_._tsan_detect_race); - _internal_mutable_leading_detached_comments()->Add()->assign(value.data(), value.size()); + _internal_mutable_leading_detached_comments()->Add()->assign(value.data(), + value.size()); // @@protoc_insertion_point(field_add_string_piece:google.protobuf.SourceCodeInfo.Location.leading_detached_comments) } inline const ::google::protobuf::RepeatedPtrField& @@ -18962,8 +18967,8 @@ inline ::google::protobuf::RepeatedField<::int32_t>* GeneratedCodeInfo_Annotatio PROTOBUF_TSAN_WRITE(&_impl_._tsan_detect_race); return _internal_mutable_path(); } -inline const ::google::protobuf::RepeatedField<::int32_t>& GeneratedCodeInfo_Annotation::_internal_path() - const { +inline const ::google::protobuf::RepeatedField<::int32_t>& +GeneratedCodeInfo_Annotation::_internal_path() const { PROTOBUF_TSAN_READ(&_impl_._tsan_detect_race); return _impl_.path_; } diff --git a/src/google/protobuf/io/printer.cc b/src/google/protobuf/io/printer.cc index 621d1ed07994e..5e58b15fb0ab7 100644 --- a/src/google/protobuf/io/printer.cc +++ b/src/google/protobuf/io/printer.cc @@ -547,6 +547,9 @@ void Printer::PrintImpl(absl::string_view format, // If we get this far, we can conclude the chunk is a substitution // variable; we rename the `chunk` variable to make this clear below. absl::string_view var = chunk.text; + if (substitution_listener_ != nullptr) { + substitution_listener_(var, opts.loc.value_or(SourceLocation())); + } if (opts.use_curly_brace_substitutions && absl::ConsumePrefix(&var, "{")) { if (!Validate(var.size() == 1u, opts, diff --git a/src/google/protobuf/io/printer.h b/src/google/protobuf/io/printer.h index e2bcc55dd4f1e..c64c479b9de3d 100644 --- a/src/google/protobuf/io/printer.h +++ b/src/google/protobuf/io/printer.h @@ -24,6 +24,7 @@ #include "absl/cleanup/cleanup.h" #include "absl/container/flat_hash_map.h" +#include "absl/functional/any_invocable.h" #include "absl/functional/function_ref.h" #include "absl/log/absl_check.h" #include "absl/meta/type_traits.h" @@ -449,8 +450,8 @@ class PROTOBUF_EXPORT Printer { // released. struct SourceLocation { static SourceLocation current() { return {}; } - absl::string_view file_name() { return ""; } - int line() { return 0; } + absl::string_view file_name() const { return ""; } + int line() const { return 0; } }; static constexpr char kDefaultVariableDelimiter = '$'; @@ -655,6 +656,18 @@ class PROTOBUF_EXPORT Printer { void FormatInternal(absl::Span args, const Map& vars, absl::string_view format); + // Injects a substitution listener for the lifetime of the RAII object + // returned. + // While the listener is active it will receive a callback on each + // substitution label found. + // This can be used to add basic verification on top of emit routines. + auto WithSubstitutionListener( + absl::AnyInvocable listener) { + ABSL_CHECK(substitution_listener_ == nullptr); + substitution_listener_ = std::move(listener); + return absl::MakeCleanup([this] { substitution_listener_ = nullptr; }); + } + private: struct PrintOptions; struct Format; @@ -753,6 +766,11 @@ class PROTOBUF_EXPORT Printer { std::function(absl::string_view)>> annotation_lookups_; + // If set, we invoke this when we do a label substitution. This can be used to + // verify consistency of the generated code while we generate it. + absl::AnyInvocable + substitution_listener_; + // A map from variable name to [start, end) offsets in the output buffer. // // This stores the data looked up by GetSubstitutionRange(). diff --git a/src/google/protobuf/io/printer_unittest.cc b/src/google/protobuf/io/printer_unittest.cc index 5e72f2d0952e5..081f4a531fc11 100644 --- a/src/google/protobuf/io/printer_unittest.cc +++ b/src/google/protobuf/io/printer_unittest.cc @@ -610,6 +610,35 @@ TEST_F(PrinterTest, EmitConsumeAfter) { "};\n"); } +TEST_F(PrinterTest, EmitWithSubstituionListener) { + std::vector seen; + Printer printer(output()); + const auto emit = [&] { + printer.Emit( + { + {"class", "Foo"}, + Printer::Sub{"var", "int x;"}.WithSuffix(";"), + }, + R"cc( + void $class$::foo() { $var$; } + void $class$::set_foo() { $var$; } + )cc"); + }; + emit(); + EXPECT_THAT(seen, ElementsAre()); + { + auto listener = printer.WithSubstitutionListener( + [&](auto label, auto loc) { seen.emplace_back(label); }); + emit(); + } + EXPECT_THAT(seen, ElementsAre("class", "var", "class", "var")); + + // Still works after the listener is disconnected. + seen.clear(); + emit(); + EXPECT_THAT(seen, ElementsAre()); +} + TEST_F(PrinterTest, EmitConditionalFunctionCall) { { Printer printer(output()); From f00fc70bdec19628f73f3c8ed656f66a72a61965 Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Wed, 3 Jan 2024 20:24:42 +0000 Subject: [PATCH 159/255] Auto-generate files after cl/595467581 --- src/google/protobuf/field_mask.pb.h | 7 ++++--- src/google/protobuf/type.pb.h | 7 ++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/google/protobuf/field_mask.pb.h b/src/google/protobuf/field_mask.pb.h index 0c3b691377ffc..84399b462e26f 100644 --- a/src/google/protobuf/field_mask.pb.h +++ b/src/google/protobuf/field_mask.pb.h @@ -313,8 +313,8 @@ inline void FieldMask::set_paths(int index, const char* value, // @@protoc_insertion_point(field_set_pointer:google.protobuf.FieldMask.paths) } inline void FieldMask::set_paths(int index, absl::string_view value) { - _internal_mutable_paths()->Mutable(index)->assign(value.data(), - value.size()); + _internal_mutable_paths()->Mutable(index)->assign( + value.data(), value.size()); // @@protoc_insertion_point(field_set_string_piece:google.protobuf.FieldMask.paths) } inline void FieldMask::add_paths(const std::string& value) { @@ -341,7 +341,8 @@ inline void FieldMask::add_paths(const char* value, std::size_t size) { } inline void FieldMask::add_paths(absl::string_view value) { PROTOBUF_TSAN_WRITE(&_impl_._tsan_detect_race); - _internal_mutable_paths()->Add()->assign(value.data(), value.size()); + _internal_mutable_paths()->Add()->assign(value.data(), + value.size()); // @@protoc_insertion_point(field_add_string_piece:google.protobuf.FieldMask.paths) } inline const ::google::protobuf::RepeatedPtrField& diff --git a/src/google/protobuf/type.pb.h b/src/google/protobuf/type.pb.h index 865a17f1b212e..5d0e4b3e31afe 100644 --- a/src/google/protobuf/type.pb.h +++ b/src/google/protobuf/type.pb.h @@ -1667,8 +1667,8 @@ inline void Type::set_oneofs(int index, const char* value, // @@protoc_insertion_point(field_set_pointer:google.protobuf.Type.oneofs) } inline void Type::set_oneofs(int index, absl::string_view value) { - _internal_mutable_oneofs()->Mutable(index)->assign(value.data(), - value.size()); + _internal_mutable_oneofs()->Mutable(index)->assign( + value.data(), value.size()); // @@protoc_insertion_point(field_set_string_piece:google.protobuf.Type.oneofs) } inline void Type::add_oneofs(const std::string& value) { @@ -1695,7 +1695,8 @@ inline void Type::add_oneofs(const char* value, std::size_t size) { } inline void Type::add_oneofs(absl::string_view value) { PROTOBUF_TSAN_WRITE(&_impl_._tsan_detect_race); - _internal_mutable_oneofs()->Add()->assign(value.data(), value.size()); + _internal_mutable_oneofs()->Add()->assign(value.data(), + value.size()); // @@protoc_insertion_point(field_add_string_piece:google.protobuf.Type.oneofs) } inline const ::google::protobuf::RepeatedPtrField& From 5cfc9e775d76acb37e5b554e53dff336a89d000f Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Wed, 3 Jan 2024 13:03:49 -0800 Subject: [PATCH 160/255] Breaking Change: Dropped support for Ruby DSL, [as previously announced](https://engdoc.corp.google.com/eng/doc/devguide/proto/news/2023-12-27.md#ruby-breaking-changes). The generated code has not used the DSL since 23.0 (released May 8, 2023). PiperOrigin-RevId: 595481605 --- ruby/BUILD.bazel | 15 - ruby/Rakefile | 4 +- ruby/lib/google/protobuf/descriptor_dsl.rb | 465 ------------------ ruby/lib/google/protobuf_ffi.rb | 3 +- ruby/lib/google/protobuf_native.rb | 1 - ruby/tests/BUILD.bazel | 35 +- ruby/tests/basic.rb | 62 +-- ruby/tests/basic_proto2.rb | 20 +- ruby/tests/basic_test.proto | 28 ++ ruby/tests/basic_test_proto2.proto | 5 + ruby/tests/common_tests.rb | 20 - ruby/tests/repeated_field_test.proto | 40 ++ ruby/tests/repeated_field_test.rb | 53 +- ruby/tests/stress.proto | 12 + ruby/tests/stress.rb | 16 +- .../compiler/ruby/ruby_generated_code_pb.rb | 24 +- .../ruby/ruby_generated_code_proto2_pb.rb | 24 +- .../ruby_generated_pkg_explicit_legacy_pb.rb | 23 +- .../ruby/ruby_generated_pkg_explicit_pb.rb | 23 +- .../ruby/ruby_generated_pkg_implicit_pb.rb | 23 +- .../protobuf/compiler/ruby/ruby_generator.cc | 23 +- 21 files changed, 134 insertions(+), 785 deletions(-) delete mode 100644 ruby/lib/google/protobuf/descriptor_dsl.rb create mode 100644 ruby/tests/repeated_field_test.proto create mode 100644 ruby/tests/stress.proto diff --git a/ruby/BUILD.bazel b/ruby/BUILD.bazel index ed9d1fd352c6d..8892af5134430 100755 --- a/ruby/BUILD.bazel +++ b/ruby/BUILD.bazel @@ -229,21 +229,6 @@ filegroup( # Tests ################################################################################ -# Define this here so the descriptor paths match what we get in Rake tests. -internal_ruby_proto_library( - name = "test_ruby_protos", - srcs = ["//ruby/tests:test_protos"], - includes = [ - ".", - "ruby/tests", - "src", - ], - visibility = [ - "//ruby:__subpackages__", - ], - deps = [":well_known_ruby_protos"], -) - conformance_test( name = "conformance_test", failure_list = "//conformance:failure_list_ruby.txt", diff --git a/ruby/Rakefile b/ruby/Rakefile index 9b50e6cb65ef2..8f5d8416a3d14 100644 --- a/ruby/Rakefile +++ b/ruby/Rakefile @@ -26,6 +26,8 @@ test_protos = %w[ tests/generated_code.proto tests/generated_code_proto2.proto tests/multi_level_nesting_test.proto + tests/repeated_field_test.proto + tests/stress.proto tests/test_import.proto tests/test_import_proto2.proto tests/test_ruby_package.proto @@ -64,7 +66,7 @@ unless ENV['IN_DOCKER'] == 'true' or ENV['BAZEL'] == 'true' output_file = proto_file.sub(/\.proto$/, "_pb.rb") genproto_output << output_file file output_file => proto_file do |file_task| - sh "#{protoc_command} -I../src -I. -I./tests --ruby_out=. #{proto_file}" + sh "#{protoc_command} -I../src -I./tests --ruby_out=tests #{proto_file}" end end end diff --git a/ruby/lib/google/protobuf/descriptor_dsl.rb b/ruby/lib/google/protobuf/descriptor_dsl.rb deleted file mode 100644 index 7349b6df15bd9..0000000000000 --- a/ruby/lib/google/protobuf/descriptor_dsl.rb +++ /dev/null @@ -1,465 +0,0 @@ -#!/usr/bin/ruby -# -# Code that implements the DSL for defining proto messages. - -# Suppress warning: loading in progress, circular require considered harmful. -# This circular require is intentional to avoid missing dependency. -begin - old_verbose, $VERBOSE = $VERBOSE, nil - require 'google/protobuf/descriptor_pb' -ensure - $VERBOSE = old_verbose -end - -module Google - module Protobuf - module Internal - class AtomicCounter - def initialize - @n = 0 - @mu = Mutex.new - end - - def get_and_increment - n = @n - @mu.synchronize { - @n += 1 - } - return n - end - end - - class Builder - @@file_number = AtomicCounter.new - - def initialize(pool) - @pool = pool - @default_file = nil # Constructed lazily - end - - def add_file(name, options={}, &block) - builder = FileBuilder.new(@pool, name, options) - builder.instance_eval(&block) - internal_add_file(builder) - end - - def add_message(name, &block) - internal_default_file.add_message(name, &block) - end - - def add_enum(name, &block) - internal_default_file.add_enum(name, &block) - end - - # ---- Internal methods, not part of the DSL ---- - - def build - if @default_file - internal_add_file(@default_file) - end - end - - private def internal_add_file(file_builder) - proto = file_builder.build - serialized = Google::Protobuf::FileDescriptorProto.encode(proto) - @pool.add_serialized_file(serialized) - end - - private def internal_default_file - number = @@file_number.get_and_increment - filename = "ruby_default_file#{number}.proto" - @default_file ||= FileBuilder.new(@pool, filename) - end - end - - class FileBuilder - def initialize(pool, name, options={}) - @pool = pool - @file_proto = Google::Protobuf::FileDescriptorProto.new( - name: name, - syntax: options.fetch(:syntax, "proto3") - ) - end - - def add_message(name, &block) - builder = MessageBuilder.new(name, self, @file_proto) - builder.instance_eval(&block) - builder.internal_add_synthetic_oneofs - end - - def add_enum(name, &block) - EnumBuilder.new(name, @file_proto).instance_eval(&block) - end - - # ---- Internal methods, not part of the DSL ---- - - # These methods fix up the file descriptor to account for differences - # between the DSL and FileDescriptorProto. - - # The DSL can omit a package name; here we infer what the package is if - # was not specified. - def infer_package(names) - # Package is longest common prefix ending in '.', if any. - if not names.empty? - min, max = names.minmax - last_common_dot = nil - min.size.times { |i| - if min[i] != max[i] then break end - if min[i] == "." then last_common_dot = i end - } - if last_common_dot - return min.slice(0, last_common_dot) - end - end - - nil - end - - def rewrite_enum_default(field) - if field.type != :TYPE_ENUM or !field.has_default_value? or !field.has_type_name? - return - end - - value = field.default_value - type_name = field.type_name - - if value.empty? or value[0].ord < "0".ord or value[0].ord > "9".ord - return - end - - if type_name.empty? || type_name[0] != "." - return - end - - type_name = type_name[1..-1] - as_int = Integer(value) rescue return - - enum_desc = @pool.lookup(type_name) - if enum_desc.is_a?(Google::Protobuf::EnumDescriptor) - # Enum was defined in a previous file. - name = enum_desc.lookup_value(as_int) - if name - # Update the default value in the proto. - field.default_value = name - end - else - # See if enum was defined in this file. - @file_proto.enum_type.each { |enum_proto| - if enum_proto.name == type_name - enum_proto.value.each { |enum_value_proto| - if enum_value_proto.number == as_int - # Update the default value in the proto. - field.default_value = enum_value_proto.name - return - end - } - # We found the right enum, but no value matched. - return - end - } - end - end - - # Historically we allowed enum defaults to be specified as a number. - # In retrospect this was a mistake as descriptors require defaults to - # be specified as a label. This can make a difference if multiple - # labels have the same number. - # - # Here we do a pass over all enum defaults and rewrite numeric defaults - # by looking up their labels. This is complicated by the fact that the - # enum definition can live in either the symtab or the file_proto. - # - # We take advantage of the fact that this is called *before* enums or - # messages are nested in other messages, so we only have to iterate - # one level deep. - def rewrite_enum_defaults - @file_proto.message_type.each { |msg| - msg.field.each { |field| - rewrite_enum_default(field) - } - } - end - - # We have to do some relatively complicated logic here for backward - # compatibility. - # - # In descriptor.proto, messages are nested inside other messages if that is - # what the original .proto file looks like. For example, suppose we have this - # foo.proto: - # - # package foo; - # message Bar { - # message Baz {} - # } - # - # The descriptor for this must look like this: - # - # file { - # name: "test.proto" - # package: "foo" - # message_type { - # name: "Bar" - # nested_type { - # name: "Baz" - # } - # } - # } - # - # However, the Ruby generated code has always generated messages in a flat, - # non-nested way: - # - # Google::Protobuf::DescriptorPool.generated_pool.build do - # add_message "foo.Bar" do - # end - # add_message "foo.Bar.Baz" do - # end - # end - # - # Here we need to do a translation where we turn this generated code into the - # above descriptor. We need to infer that "foo" is the package name, and not - # a message itself. */ - - def split_parent_name(msg_or_enum) - name = msg_or_enum.name - idx = name.rindex(?.) - if idx - return name[0...idx], name[idx+1..-1] - else - return nil, name - end - end - - def get_parent_msg(msgs_by_name, name, parent_name) - parent_msg = msgs_by_name[parent_name] - if parent_msg.nil? - raise "To define name #{name}, there must be a message named #{parent_name} to enclose it" - end - return parent_msg - end - - def fix_nesting - # Calculate and update package. - msgs_by_name = @file_proto.message_type.map { |msg| [msg.name, msg] }.to_h - enum_names = @file_proto.enum_type.map { |enum_proto| enum_proto.name } - - package = infer_package(msgs_by_name.keys + enum_names) - if package - @file_proto.package = package - end - - # Update nesting based on package. - final_msgs = Google::Protobuf::RepeatedField.new(:message, Google::Protobuf::DescriptorProto) - final_enums = Google::Protobuf::RepeatedField.new(:message, Google::Protobuf::EnumDescriptorProto) - - # Note: We don't iterate over msgs_by_name.values because we want to - # preserve order as listed in the DSL. - @file_proto.message_type.each { |msg| - parent_name, msg.name = split_parent_name(msg) - if parent_name == package - final_msgs << msg - else - get_parent_msg(msgs_by_name, msg.name, parent_name).nested_type << msg - end - } - - @file_proto.enum_type.each { |enum| - parent_name, enum.name = split_parent_name(enum) - if parent_name == package - final_enums << enum - else - get_parent_msg(msgs_by_name, enum.name, parent_name).enum_type << enum - end - } - - @file_proto.message_type = final_msgs - @file_proto.enum_type = final_enums - end - - def internal_file_proto - @file_proto - end - - def build - rewrite_enum_defaults - fix_nesting - return @file_proto - end - end - - class MessageBuilder - def initialize(name, file_builder, file_proto) - @file_builder = file_builder - @msg_proto = Google::Protobuf::DescriptorProto.new( - :name => name - ) - file_proto.message_type << @msg_proto - end - - def optional(name, type, number, type_class=nil, options=nil) - internal_add_field(:LABEL_OPTIONAL, name, type, number, type_class, options) - end - - def proto3_optional(name, type, number, type_class=nil, options=nil) - internal_add_field(:LABEL_OPTIONAL, name, type, number, type_class, options, - proto3_optional: true) - end - - def required(name, type, number, type_class=nil, options=nil) - internal_add_field(:LABEL_REQUIRED, name, type, number, type_class, options) - end - - def repeated(name, type, number, type_class = nil, options=nil) - internal_add_field(:LABEL_REPEATED, name, type, number, type_class, options) - end - - def oneof(name, &block) - OneofBuilder.new(name, self).instance_eval(&block) - end - - # Defines a new map field on this message type with the given key and - # value types, tag number, and type class (for message and enum value - # types). The key type must be :int32/:uint32/:int64/:uint64, :bool, or - # :string. The value type type must be a Ruby symbol (as accepted by - # FieldDescriptor#type=) and the type_class must be a string, if - # present (as accepted by FieldDescriptor#submsg_name=). - def map(name, key_type, value_type, number, value_type_class = nil) - if key_type == :float or key_type == :double or key_type == :enum or - key_type == :message - raise ArgError, "Not an acceptable key type: " + key_type - end - entry_name = "#{@msg_proto.name}_MapEntry_#{name}" - - @file_builder.add_message entry_name do - optional :key, key_type, 1 - optional :value, value_type, 2, value_type_class - end - options = @file_builder.internal_file_proto.message_type.last.options ||= MessageOptions.new - options.map_entry = true - repeated name, :message, number, entry_name - end - - # ---- Internal methods, not part of the DSL ---- - - def internal_add_synthetic_oneofs - # We have to build a set of all names, to ensure that synthetic oneofs - # are not creating conflicts - names = {} - @msg_proto.field.each { |field| names[field.name] = true } - @msg_proto.oneof_decl.each { |oneof| names[oneof.name] = true } - - @msg_proto.field.each { |field| - if field.proto3_optional - # Prepend '_' until we are no longer conflicting. - oneof_name = field.name - while names[oneof_name] - oneof_name = "_" + oneof_name - end - names[oneof_name] = true - field.oneof_index = @msg_proto.oneof_decl.size - @msg_proto.oneof_decl << Google::Protobuf::OneofDescriptorProto.new( - name: oneof_name - ) - end - } - end - - def internal_add_field(label, name, type, number, type_class, options, - oneof_index: nil, proto3_optional: false) - # Allow passing either: - # - (name, type, number, options) or - # - (name, type, number, type_class, options) - if options.nil? and type_class.instance_of?(Hash) - options = type_class; - type_class = nil; - end - - field_proto = Google::Protobuf::FieldDescriptorProto.new( - :label => label, - :name => name, - :type => ("TYPE_" + type.to_s.upcase).to_sym, - :number => number - ) - - if type_class - # Make it an absolute type name by prepending a dot. - field_proto.type_name = "." + type_class - end - - if oneof_index - field_proto.oneof_index = oneof_index - end - - if proto3_optional - field_proto.proto3_optional = true - end - - if options - if options.key?(:default) - default = options[:default] - if !default.instance_of?(String) - # Call #to_s since all defaults are strings in the descriptor. - default = default.to_s - end - # XXX: we should be C-escaping bytes defaults. - field_proto.default_value = default.dup.force_encoding("UTF-8") - end - if options.key?(:json_name) - field_proto.json_name = options[:json_name] - end - end - - @msg_proto.field << field_proto - end - - def internal_msg_proto - @msg_proto - end - end - - class OneofBuilder - def initialize(name, msg_builder) - @msg_builder = msg_builder - oneof_proto = Google::Protobuf::OneofDescriptorProto.new( - :name => name - ) - msg_proto = msg_builder.internal_msg_proto - @oneof_index = msg_proto.oneof_decl.size - msg_proto.oneof_decl << oneof_proto - end - - def optional(name, type, number, type_class=nil, options=nil) - @msg_builder.internal_add_field( - :LABEL_OPTIONAL, name, type, number, type_class, options, - oneof_index: @oneof_index) - end - end - - class EnumBuilder - def initialize(name, file_proto) - @enum_proto = Google::Protobuf::EnumDescriptorProto.new( - :name => name - ) - file_proto.enum_type << @enum_proto - end - - def value(name, number) - enum_value_proto = Google::Protobuf::EnumValueDescriptorProto.new( - name: name, - number: number - ) - @enum_proto.value << enum_value_proto - end - end - - end - - # Re-open the class (the rest of the class is implemented in C) - class DescriptorPool - def build(&block) - builder = Internal::Builder.new(self) - builder.instance_eval(&block) - builder.build - end - end - end -end diff --git a/ruby/lib/google/protobuf_ffi.rb b/ruby/lib/google/protobuf_ffi.rb index 12616eef16836..0839b36d3f345 100644 --- a/ruby/lib/google/protobuf_ffi.rb +++ b/ruby/lib/google/protobuf_ffi.rb @@ -21,7 +21,6 @@ require 'google/protobuf/ffi/object_cache' require 'google/protobuf/ffi/repeated_field' require 'google/protobuf/ffi/message' -require 'google/protobuf/descriptor_dsl' module Google module Protobuf @@ -47,4 +46,4 @@ def self.discard_unknown(message) nil end end -end \ No newline at end of file +end diff --git a/ruby/lib/google/protobuf_native.rb b/ruby/lib/google/protobuf_native.rb index eddaa7dd42928..9605b6b54bd7b 100644 --- a/ruby/lib/google/protobuf_native.rb +++ b/ruby/lib/google/protobuf_native.rb @@ -16,5 +16,4 @@ end end -require 'google/protobuf/descriptor_dsl' require 'google/protobuf/repeated_field' diff --git a/ruby/tests/BUILD.bazel b/ruby/tests/BUILD.bazel index 57566207c0d9a..17166b11762e2 100644 --- a/ruby/tests/BUILD.bazel +++ b/ruby/tests/BUILD.bazel @@ -1,17 +1,24 @@ load("@rules_pkg//:mappings.bzl", "pkg_files", "strip_prefix") load("@rules_ruby//ruby:defs.bzl", "ruby_library", "ruby_test") +load("//ruby:defs.bzl", "internal_ruby_proto_library") ruby_library( name = "common_tests", srcs = ["common_tests.rb"], ) -filegroup( - name = "test_protos", +internal_ruby_proto_library( + name = "test_ruby_protos", srcs = glob(["*.proto"]), + includes = [ + ".", + "ruby/tests", + "src", + ], visibility = [ "//ruby:__subpackages__", ], + deps = ["//ruby:well_known_ruby_protos"], ) ruby_test( @@ -28,8 +35,8 @@ ruby_test( srcs = ["basic.rb"], deps = [ ":common_tests", + ":test_ruby_protos", "//ruby:protobuf", - "//ruby:test_ruby_protos", "@protobuf_bundle//:test-unit", ], ) @@ -39,8 +46,8 @@ ruby_test( srcs = ["basic_proto2.rb"], deps = [ ":common_tests", + ":test_ruby_protos", "//ruby:protobuf", - "//ruby:test_ruby_protos", "@protobuf_bundle//:test-unit", ], ) @@ -49,8 +56,8 @@ ruby_test( name = "encode_decode_test", srcs = ["encode_decode_test.rb"], deps = [ + ":test_ruby_protos", "//ruby:protobuf", - "//ruby:test_ruby_protos", "@protobuf_bundle//:test-unit", ], ) @@ -59,8 +66,8 @@ ruby_test( name = "gc_test", srcs = ["gc_test.rb"], deps = [ + ":test_ruby_protos", "//ruby:protobuf", - "//ruby:test_ruby_protos", "@protobuf_bundle//:test-unit", ], ) @@ -69,8 +76,8 @@ ruby_test( name = "generated_code_test", srcs = ["generated_code_test.rb"], deps = [ + ":test_ruby_protos", "//ruby:protobuf", - "//ruby:test_ruby_protos", "@protobuf_bundle//:test-unit", ], ) @@ -79,8 +86,8 @@ ruby_test( name = "multi_level_nesting_test", srcs = ["multi_level_nesting_test.rb"], deps = [ + ":test_ruby_protos", "//ruby:protobuf", - "//ruby:test_ruby_protos", "@protobuf_bundle//:test-unit", ], ) @@ -89,8 +96,8 @@ ruby_test( name = "object_cache_test", srcs = ["object_cache_test.rb"], deps = [ + ":test_ruby_protos", "//ruby:protobuf", - "//ruby:test_ruby_protos", "@protobuf_bundle//:test-unit", ], ) @@ -99,8 +106,8 @@ ruby_test( name = "repeated_field_test", srcs = ["repeated_field_test.rb"], deps = [ + ":test_ruby_protos", "//ruby:protobuf", - "//ruby:test_ruby_protos", "@protobuf_bundle//:test-unit", ], ) @@ -109,8 +116,8 @@ ruby_test( name = "ruby_version", srcs = ["ruby_version.rb"], deps = [ + ":test_ruby_protos", "//ruby:protobuf", - "//ruby:test_ruby_protos", "@protobuf_bundle//:test-unit", ], ) @@ -119,8 +126,8 @@ ruby_test( name = "stress", srcs = ["stress.rb"], deps = [ + ":test_ruby_protos", "//ruby:protobuf", - "//ruby:test_ruby_protos", "@protobuf_bundle//:test-unit", ], ) @@ -129,8 +136,8 @@ ruby_test( name = "type_errors", srcs = ["type_errors.rb"], deps = [ + ":test_ruby_protos", "//ruby:protobuf", - "//ruby:test_ruby_protos", "@protobuf_bundle//:test-unit", ], ) @@ -139,8 +146,8 @@ ruby_test( name = "well_known_types_test", srcs = ["well_known_types_test.rb"], deps = [ + ":test_ruby_protos", "//ruby:protobuf", - "//ruby:test_ruby_protos", "@protobuf_bundle//:test-unit", ], ) diff --git a/ruby/tests/basic.rb b/ruby/tests/basic.rb index 1e5e7a341d176..4dc45e748c201 100755 --- a/ruby/tests/basic.rb +++ b/ruby/tests/basic.rb @@ -9,20 +9,9 @@ require 'json' require 'test/unit' -# ------------- generated code -------------- - module BasicTest - pool = Google::Protobuf::DescriptorPool.new - pool.build do - add_message "BadFieldNames" do - optional :dup, :int32, 1 - optional :class, :int32, 2 - end - end - - BadFieldNames = pool.lookup("BadFieldNames").msgclass - -# ------------ test cases --------------- + TestMessage = BasicTest::TestMessage + Outer = BasicTest::Outer class MessageContainerTest < Test::Unit::TestCase # Required by CommonTests module to resolve proto3 proto classes used in tests. @@ -32,32 +21,12 @@ def proto_module include CommonTests def test_issue_8311_crash - Google::Protobuf::DescriptorPool.generated_pool.build do - add_file("inner.proto", :syntax => :proto3) do - add_message "Inner" do - # Removing either of these fixes the segfault. - optional :foo, :string, 1 - optional :bar, :string, 2 - end - end - end - - Google::Protobuf::DescriptorPool.generated_pool.build do - add_file("outer.proto", :syntax => :proto3) do - add_message "Outer" do - repeated :inners, :message, 1, "Inner" - end - end - end - - outer = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("Outer").msgclass - - outer.new( + BasicTest::Outer8311.new( inners: [] )['inners'].to_s assert_raises Google::Protobuf::TypeError do - outer.new( + BasicTest::Outer8311.new( inners: [nil] ).to_s end @@ -83,29 +52,16 @@ def test_issue_9440 end def test_issue_9507 - pool = Google::Protobuf::DescriptorPool.new - pool.build do - add_message "NpeMessage" do - optional :type, :enum, 1, "TestEnum" - optional :other, :string, 2 - end - add_enum "TestEnum" do - value :Something, 0 - end - end - - msgclass = pool.lookup("NpeMessage").msgclass - - m = msgclass.new( + m = BasicTest::NpeMessage.new( other: "foo" # must be set, but can be blank ) begin - encoded = msgclass.encode(m) + encoded = BasicTest::NpeMessage.encode(m) rescue java.lang.NullPointerException flunk "NPE rescued" end - decoded = msgclass.decode(encoded) + decoded = BasicTest::NpeMessage.decode(encoded) decoded.inspect decoded.to_proto end @@ -609,12 +565,12 @@ def test_respond_to def test_file_descriptor file_descriptor = TestMessage.descriptor.file_descriptor refute_nil file_descriptor - assert_equal "tests/basic_test.proto", file_descriptor.name + assert_equal "basic_test.proto", file_descriptor.name assert_equal :proto3, file_descriptor.syntax file_descriptor = TestEnum.descriptor.file_descriptor refute_nil file_descriptor - assert_equal "tests/basic_test.proto", file_descriptor.name + assert_equal "basic_test.proto", file_descriptor.name assert_equal :proto3, file_descriptor.syntax end diff --git a/ruby/tests/basic_proto2.rb b/ruby/tests/basic_proto2.rb index 1eefc6ff8d94b..26c253437db51 100755 --- a/ruby/tests/basic_proto2.rb +++ b/ruby/tests/basic_proto2.rb @@ -9,23 +9,7 @@ require 'json' require 'test/unit' -# ------------- generated code -------------- - module BasicTestProto2 - pool = Google::Protobuf::DescriptorPool.new - pool.build do - add_file "test_proto2.proto", syntax: :proto2 do - add_message "BadFieldNames" do - optional :dup, :int32, 1 - optional :class, :int32, 2 - end - end - end - - BadFieldNames = pool.lookup("BadFieldNames").msgclass - -# ------------ test cases --------------- - class MessageContainerTest < Test::Unit::TestCase # Required by CommonTests module to resolve proto2 proto classes used in tests. def proto_module @@ -246,12 +230,12 @@ def test_respond_to def test_file_descriptor file_descriptor = TestMessage.descriptor.file_descriptor refute_nil file_descriptor - assert_equal "tests/basic_test_proto2.proto", file_descriptor.name + assert_equal "basic_test_proto2.proto", file_descriptor.name assert_equal :proto2, file_descriptor.syntax file_descriptor = TestEnum.descriptor.file_descriptor refute_nil file_descriptor - assert_equal "tests/basic_test_proto2.proto", file_descriptor.name + assert_equal "basic_test_proto2.proto", file_descriptor.name assert_equal :proto2, file_descriptor.syntax end diff --git a/ruby/tests/basic_test.proto b/ruby/tests/basic_test.proto index 8feab6ed636e9..5c9bb6012e777 100644 --- a/ruby/tests/basic_test.proto +++ b/ruby/tests/basic_test.proto @@ -285,3 +285,31 @@ message HelloRequest { optional uint32 random_name_c9 = 31; optional string version = 32; } + +message BadFieldNames { + optional int32 dup = 1; + optional int32 class = 2; +} + +// Messages to test the fix for +// https://github.com/protocolbuffers/protobuf/issues/8311. +message Inner8311 { + // Removing either of these fixes the segfault. + optional string foo = 1; + optional string bar = 2; +} + +message Outer8311 { + repeated Inner8311 inners = 1; +} + +// Messages to test the fix for +// https://github.com/protocolbuffers/protobuf/issues/9507 +message NpeMessage { + optional TestEnum9507 type = 1; + optional string other = 2; +} + +enum TestEnum9507 { + Something = 0; +} diff --git a/ruby/tests/basic_test_proto2.proto b/ruby/tests/basic_test_proto2.proto index 777b4dd776569..85d61cf6b14ac 100644 --- a/ruby/tests/basic_test_proto2.proto +++ b/ruby/tests/basic_test_proto2.proto @@ -231,3 +231,8 @@ message TestMessageSetExtension3 { extend TestMessageSet { optional TestMessageSetExtension3 message_set_extension3 = 98418655; } + +message BadFieldNames { + optional int32 dup = 1; + optional int32 class = 2; +} diff --git a/ruby/tests/common_tests.rb b/ruby/tests/common_tests.rb index 52e08459850fb..dd2ad39adc2e2 100644 --- a/ruby/tests/common_tests.rb +++ b/ruby/tests/common_tests.rb @@ -855,26 +855,6 @@ def test_protobuf_encode_decode_json_helpers assert_equal proto_module::TestMessage.decode_json([m.to_json].first), decoded_msg end - def test_def_errors - s = Google::Protobuf::DescriptorPool.new - assert_raises Google::Protobuf::TypeError do - s.build do - # enum with no default (integer value 0) - add_enum "MyEnum" do - value :A, 1 - end - end - end - assert_raises Google::Protobuf::TypeError do - s.build do - # message with required field (unsupported in proto3) - add_message "MyMessage" do - required :foo, :int32, 1 - end - end - end - end - def test_corecursive # just be sure that we can instantiate types with corecursive field-type # references. diff --git a/ruby/tests/repeated_field_test.proto b/ruby/tests/repeated_field_test.proto new file mode 100644 index 0000000000000..9bcb3fca7ccf3 --- /dev/null +++ b/ruby/tests/repeated_field_test.proto @@ -0,0 +1,40 @@ +syntax = "proto3"; + +package repeated_field_test_protos; + +message TestMessage { + optional int32 optional_int32 = 1; + optional int64 optional_int64 = 2; + optional uint32 optional_uint32 = 3; + optional uint64 optional_uint64 = 4; + optional bool optional_bool = 5; + optional float optional_float = 6; + optional double optional_double = 7; + optional string optional_string = 8; + optional bytes optional_bytes = 9; + optional TestMessage2 optional_msg = 10; + optional TestEnum optional_enum = 11; + repeated int32 repeated_int32 = 12; + repeated int64 repeated_int64 = 13; + repeated uint32 repeated_uint32 = 14; + repeated uint64 repeated_uint64 = 15; + repeated bool repeated_bool = 16; + repeated float repeated_float = 17; + repeated double repeated_double = 18; + repeated string repeated_string = 19; + repeated bytes repeated_bytes = 20; + repeated TestMessage2 repeated_msg = 21; + repeated TestEnum repeated_enum = 22; +} + +message TestMessage2 { + optional int32 foo = 1; +} + +enum TestEnum { + DEFAULT = 0; + A = 1; + B = 2; + C = 3; + V0 = 4; +} diff --git a/ruby/tests/repeated_field_test.rb b/ruby/tests/repeated_field_test.rb index 293b4e42e17b3..492d9d928fe00 100755 --- a/ruby/tests/repeated_field_test.rb +++ b/ruby/tests/repeated_field_test.rb @@ -1,9 +1,12 @@ #!/usr/bin/ruby require 'google/protobuf' +require 'repeated_field_test_pb' require 'test/unit' class RepeatedFieldTest < Test::Unit::TestCase + TestMessage = RepeatedFieldTestProtos::TestMessage + TestMessage2 = RepeatedFieldTestProtos::TestMessage2 def test_acts_like_enumerator m = TestMessage.new @@ -281,7 +284,7 @@ def test_array_settor m.repeated_msg[3] = TestMessage2.new(:foo => 1) assert_equal [nil, nil, nil, TestMessage2.new(:foo => 1)], m.repeated_msg m.repeated_enum[3] = :A - assert_equal [:Default, :Default, :Default, :A], m.repeated_enum + assert_equal [:DEFAULT, :DEFAULT, :DEFAULT, :A], m.repeated_enum # check_self_modifying_method(m.repeated_string, reference_arr) do |arr| # arr[20] = 'spacious' @@ -674,52 +677,4 @@ def fill_test_msg(test_msg) test_msg.repeated_enum << :A test_msg.repeated_enum << :B end - - - pool = Google::Protobuf::DescriptorPool.new - pool.build do - - add_message "TestMessage" do - optional :optional_int32, :int32, 1 - optional :optional_int64, :int64, 2 - optional :optional_uint32, :uint32, 3 - optional :optional_uint64, :uint64, 4 - optional :optional_bool, :bool, 5 - optional :optional_float, :float, 6 - optional :optional_double, :double, 7 - optional :optional_string, :string, 8 - optional :optional_bytes, :bytes, 9 - optional :optional_msg, :message, 10, "TestMessage2" - optional :optional_enum, :enum, 11, "TestEnum" - - repeated :repeated_int32, :int32, 12 - repeated :repeated_int64, :int64, 13 - repeated :repeated_uint32, :uint32, 14 - repeated :repeated_uint64, :uint64, 15 - repeated :repeated_bool, :bool, 16 - repeated :repeated_float, :float, 17 - repeated :repeated_double, :double, 18 - repeated :repeated_string, :string, 19 - repeated :repeated_bytes, :bytes, 20 - repeated :repeated_msg, :message, 21, "TestMessage2" - repeated :repeated_enum, :enum, 22, "TestEnum" - end - add_message "TestMessage2" do - optional :foo, :int32, 1 - end - - add_enum "TestEnum" do - value :Default, 0 - value :A, 1 - value :B, 2 - value :C, 3 - value :v0, 4 - end - end - - TestMessage = pool.lookup("TestMessage").msgclass - TestMessage2 = pool.lookup("TestMessage2").msgclass - TestEnum = pool.lookup("TestEnum").enummodule - - end diff --git a/ruby/tests/stress.proto b/ruby/tests/stress.proto new file mode 100644 index 0000000000000..517e74638c98a --- /dev/null +++ b/ruby/tests/stress.proto @@ -0,0 +1,12 @@ +syntax = "proto3"; + +package stress_test_protos; + +message TestMessage { + int32 a = 1; + repeated M b = 2; +} + +message M { + string foo = 1; +} diff --git a/ruby/tests/stress.rb b/ruby/tests/stress.rb index b688e8b0bd4df..4ad37c171cad5 100755 --- a/ruby/tests/stress.rb +++ b/ruby/tests/stress.rb @@ -1,22 +1,12 @@ #!/usr/bin/ruby require 'google/protobuf' +require 'stress_pb' require 'test/unit' module StressTest - pool = Google::Protobuf::DescriptorPool.new - pool.build do - add_message "TestMessage" do - optional :a, :int32, 1 - repeated :b, :message, 2, "M" - end - add_message "M" do - optional :foo, :string, 1 - end - end - - TestMessage = pool.lookup("TestMessage").msgclass - M = pool.lookup("M").msgclass + TestMessage = StressTestProtos::TestMessage + M = StressTestProtos::M class StressTest < Test::Unit::TestCase def get_msg diff --git a/src/google/protobuf/compiler/ruby/ruby_generated_code_pb.rb b/src/google/protobuf/compiler/ruby/ruby_generated_code_pb.rb index 6c24134efceb9..cf37b715b3ff2 100644 --- a/src/google/protobuf/compiler/ruby/ruby_generated_code_pb.rb +++ b/src/google/protobuf/compiler/ruby/ruby_generated_code_pb.rb @@ -10,29 +10,7 @@ descriptor_data = "\n\x19ruby_generated_code.proto\x12\x05\x41.B.C\x1a\'ruby_generated_code_proto2_import.proto\"\x86\x12\n\x0bTestMessage\x12\x16\n\x0eoptional_int32\x18\x01 \x01(\x05\x12\x16\n\x0eoptional_int64\x18\x02 \x01(\x03\x12\x17\n\x0foptional_uint32\x18\x03 \x01(\r\x12\x17\n\x0foptional_uint64\x18\x04 \x01(\x04\x12\x15\n\roptional_bool\x18\x05 \x01(\x08\x12\x17\n\x0foptional_double\x18\x06 \x01(\x01\x12\x16\n\x0eoptional_float\x18\x07 \x01(\x02\x12\x17\n\x0foptional_string\x18\x08 \x01(\t\x12\x16\n\x0eoptional_bytes\x18\t \x01(\x0c\x12&\n\roptional_enum\x18\n \x01(\x0e\x32\x0f.A.B.C.TestEnum\x12(\n\x0coptional_msg\x18\x0b \x01(\x0b\x32\x12.A.B.C.TestMessage\x12>\n\x1aoptional_proto2_submessage\x18\x0c \x01(\x0b\x32\x1a.A.B.C.TestImportedMessage\x12\x16\n\x0erepeated_int32\x18\x15 \x03(\x05\x12\x16\n\x0erepeated_int64\x18\x16 \x03(\x03\x12\x17\n\x0frepeated_uint32\x18\x17 \x03(\r\x12\x17\n\x0frepeated_uint64\x18\x18 \x03(\x04\x12\x15\n\rrepeated_bool\x18\x19 \x03(\x08\x12\x17\n\x0frepeated_double\x18\x1a \x03(\x01\x12\x16\n\x0erepeated_float\x18\x1b \x03(\x02\x12\x17\n\x0frepeated_string\x18\x1c \x03(\t\x12\x16\n\x0erepeated_bytes\x18\x1d \x03(\x0c\x12&\n\rrepeated_enum\x18\x1e \x03(\x0e\x32\x0f.A.B.C.TestEnum\x12(\n\x0crepeated_msg\x18\x1f \x03(\x0b\x32\x12.A.B.C.TestMessage\x12\x15\n\x0boneof_int32\x18) \x01(\x05H\x00\x12\x15\n\x0boneof_int64\x18* \x01(\x03H\x00\x12\x16\n\x0coneof_uint32\x18+ \x01(\rH\x00\x12\x16\n\x0coneof_uint64\x18, \x01(\x04H\x00\x12\x14\n\noneof_bool\x18- \x01(\x08H\x00\x12\x16\n\x0coneof_double\x18. \x01(\x01H\x00\x12\x15\n\x0boneof_float\x18/ \x01(\x02H\x00\x12\x16\n\x0coneof_string\x18\x30 \x01(\tH\x00\x12\x15\n\x0boneof_bytes\x18\x31 \x01(\x0cH\x00\x12%\n\noneof_enum\x18\x32 \x01(\x0e\x32\x0f.A.B.C.TestEnumH\x00\x12\'\n\toneof_msg\x18\x33 \x01(\x0b\x32\x12.A.B.C.TestMessageH\x00\x12@\n\x10map_int32_string\x18= \x03(\x0b\x32&.A.B.C.TestMessage.MapInt32StringEntry\x12@\n\x10map_int64_string\x18> \x03(\x0b\x32&.A.B.C.TestMessage.MapInt64StringEntry\x12\x42\n\x11map_uint32_string\x18? \x03(\x0b\x32\'.A.B.C.TestMessage.MapUint32StringEntry\x12\x42\n\x11map_uint64_string\x18@ \x03(\x0b\x32\'.A.B.C.TestMessage.MapUint64StringEntry\x12>\n\x0fmap_bool_string\x18\x41 \x03(\x0b\x32%.A.B.C.TestMessage.MapBoolStringEntry\x12\x42\n\x11map_string_string\x18\x42 \x03(\x0b\x32\'.A.B.C.TestMessage.MapStringStringEntry\x12<\n\x0emap_string_msg\x18\x43 \x03(\x0b\x32$.A.B.C.TestMessage.MapStringMsgEntry\x12>\n\x0fmap_string_enum\x18\x44 \x03(\x0b\x32%.A.B.C.TestMessage.MapStringEnumEntry\x12@\n\x10map_string_int32\x18\x45 \x03(\x0b\x32&.A.B.C.TestMessage.MapStringInt32Entry\x12>\n\x0fmap_string_bool\x18\x46 \x03(\x0b\x32%.A.B.C.TestMessage.MapStringBoolEntry\x12\x38\n\x0enested_message\x18P \x01(\x0b\x32 .A.B.C.TestMessage.NestedMessage\x1a\x35\n\x13MapInt32StringEntry\x12\x0b\n\x03key\x18\x01 \x01(\x05\x12\r\n\x05value\x18\x02 \x01(\t:\x02\x38\x01\x1a\x35\n\x13MapInt64StringEntry\x12\x0b\n\x03key\x18\x01 \x01(\x03\x12\r\n\x05value\x18\x02 \x01(\t:\x02\x38\x01\x1a\x36\n\x14MapUint32StringEntry\x12\x0b\n\x03key\x18\x01 \x01(\r\x12\r\n\x05value\x18\x02 \x01(\t:\x02\x38\x01\x1a\x36\n\x14MapUint64StringEntry\x12\x0b\n\x03key\x18\x01 \x01(\x04\x12\r\n\x05value\x18\x02 \x01(\t:\x02\x38\x01\x1a\x34\n\x12MapBoolStringEntry\x12\x0b\n\x03key\x18\x01 \x01(\x08\x12\r\n\x05value\x18\x02 \x01(\t:\x02\x38\x01\x1a\x36\n\x14MapStringStringEntry\x12\x0b\n\x03key\x18\x01 \x01(\t\x12\r\n\x05value\x18\x02 \x01(\t:\x02\x38\x01\x1aG\n\x11MapStringMsgEntry\x12\x0b\n\x03key\x18\x01 \x01(\t\x12!\n\x05value\x18\x02 \x01(\x0b\x32\x12.A.B.C.TestMessage:\x02\x38\x01\x1a\x45\n\x12MapStringEnumEntry\x12\x0b\n\x03key\x18\x01 \x01(\t\x12\x1e\n\x05value\x18\x02 \x01(\x0e\x32\x0f.A.B.C.TestEnum:\x02\x38\x01\x1a\x35\n\x13MapStringInt32Entry\x12\x0b\n\x03key\x18\x01 \x01(\t\x12\r\n\x05value\x18\x02 \x01(\x05:\x02\x38\x01\x1a\x34\n\x12MapStringBoolEntry\x12\x0b\n\x03key\x18\x01 \x01(\t\x12\r\n\x05value\x18\x02 \x01(\x08:\x02\x38\x01\x1a\x1c\n\rNestedMessage\x12\x0b\n\x03\x66oo\x18\x01 \x01(\x05\x42\n\n\x08my_oneof*,\n\x08TestEnum\x12\x0b\n\x07\x44\x65\x66\x61ult\x10\x00\x12\x05\n\x01\x41\x10\x01\x12\x05\n\x01\x42\x10\x02\x12\x05\n\x01\x43\x10\x03\x62\x06proto3" pool = Google::Protobuf::DescriptorPool.generated_pool - -begin - pool.add_serialized_file(descriptor_data) -rescue TypeError - # Compatibility code: will be removed in the next major version. - require 'google/protobuf/descriptor_pb' - parsed = Google::Protobuf::FileDescriptorProto.decode(descriptor_data) - parsed.clear_dependency - serialized = parsed.class.encode(parsed) - file = pool.add_serialized_file(serialized) - warn "Warning: Protobuf detected an import path issue while loading generated file #{__FILE__}" - imports = [ - ["A.B.C.TestImportedMessage", "ruby_generated_code_proto2_import.proto"], - ] - imports.each do |type_name, expected_filename| - import_file = pool.lookup(type_name).file_descriptor - if import_file.name != expected_filename - warn "- #{file.name} imports #{expected_filename}, but that import was loaded as #{import_file.name}" - end - end - warn "Each proto file must use a consistent fully-qualified name." - warn "This will become an error in the next major version." -end +pool.add_serialized_file(descriptor_data) module A module B diff --git a/src/google/protobuf/compiler/ruby/ruby_generated_code_proto2_pb.rb b/src/google/protobuf/compiler/ruby/ruby_generated_code_proto2_pb.rb index 064959825d797..053bfea8ad5e3 100644 --- a/src/google/protobuf/compiler/ruby/ruby_generated_code_proto2_pb.rb +++ b/src/google/protobuf/compiler/ruby/ruby_generated_code_proto2_pb.rb @@ -10,29 +10,7 @@ descriptor_data = "\n ruby_generated_code_proto2.proto\x12\x05\x41.B.C\x1a\'ruby_generated_code_proto2_import.proto\"\x96\x0b\n\x0bTestMessage\x12\x19\n\x0eoptional_int32\x18\x01 \x01(\x05:\x01\x31\x12\x19\n\x0eoptional_int64\x18\x02 \x01(\x03:\x01\x32\x12\x1a\n\x0foptional_uint32\x18\x03 \x01(\r:\x01\x33\x12\x1a\n\x0foptional_uint64\x18\x04 \x01(\x04:\x01\x34\x12\x1b\n\roptional_bool\x18\x05 \x01(\x08:\x04true\x12\x1a\n\x0foptional_double\x18\x06 \x01(\x01:\x01\x36\x12\x19\n\x0eoptional_float\x18\x07 \x01(\x02:\x01\x37\x12$\n\x0foptional_string\x18\x08 \x01(\t:\x0b\x64\x65\x66\x61ult str\x12*\n\x0eoptional_bytes\x18\t \x01(\x0c:\x12\\000\\001\\002@fubar\x12)\n\roptional_enum\x18\n \x01(\x0e\x32\x0f.A.B.C.TestEnum:\x01\x41\x12(\n\x0coptional_msg\x18\x0b \x01(\x0b\x32\x12.A.B.C.TestMessage\x12>\n\x1aoptional_proto2_submessage\x18\x0c \x01(\x0b\x32\x1a.A.B.C.TestImportedMessage\x12\x16\n\x0erepeated_int32\x18\x15 \x03(\x05\x12\x16\n\x0erepeated_int64\x18\x16 \x03(\x03\x12\x17\n\x0frepeated_uint32\x18\x17 \x03(\r\x12\x17\n\x0frepeated_uint64\x18\x18 \x03(\x04\x12\x15\n\rrepeated_bool\x18\x19 \x03(\x08\x12\x17\n\x0frepeated_double\x18\x1a \x03(\x01\x12\x16\n\x0erepeated_float\x18\x1b \x03(\x02\x12\x17\n\x0frepeated_string\x18\x1c \x03(\t\x12\x16\n\x0erepeated_bytes\x18\x1d \x03(\x0c\x12&\n\rrepeated_enum\x18\x1e \x03(\x0e\x32\x0f.A.B.C.TestEnum\x12(\n\x0crepeated_msg\x18\x1f \x03(\x0b\x32\x12.A.B.C.TestMessage\x12\x16\n\x0erequired_int32\x18) \x02(\x05\x12\x16\n\x0erequired_int64\x18* \x02(\x03\x12\x17\n\x0frequired_uint32\x18+ \x02(\r\x12\x17\n\x0frequired_uint64\x18, \x02(\x04\x12\x15\n\rrequired_bool\x18- \x02(\x08\x12\x17\n\x0frequired_double\x18. \x02(\x01\x12\x16\n\x0erequired_float\x18/ \x02(\x02\x12\x17\n\x0frequired_string\x18\x30 \x02(\t\x12\x16\n\x0erequired_bytes\x18\x31 \x02(\x0c\x12&\n\rrequired_enum\x18\x32 \x02(\x0e\x32\x0f.A.B.C.TestEnum\x12(\n\x0crequired_msg\x18\x33 \x02(\x0b\x32\x12.A.B.C.TestMessage\x12\x15\n\x0boneof_int32\x18= \x01(\x05H\x00\x12\x15\n\x0boneof_int64\x18> \x01(\x03H\x00\x12\x16\n\x0coneof_uint32\x18? \x01(\rH\x00\x12\x16\n\x0coneof_uint64\x18@ \x01(\x04H\x00\x12\x14\n\noneof_bool\x18\x41 \x01(\x08H\x00\x12\x16\n\x0coneof_double\x18\x42 \x01(\x01H\x00\x12\x15\n\x0boneof_float\x18\x43 \x01(\x02H\x00\x12\x16\n\x0coneof_string\x18\x44 \x01(\tH\x00\x12\x15\n\x0boneof_bytes\x18\x45 \x01(\x0cH\x00\x12%\n\noneof_enum\x18\x46 \x01(\x0e\x32\x0f.A.B.C.TestEnumH\x00\x12\'\n\toneof_msg\x18G \x01(\x0b\x32\x12.A.B.C.TestMessageH\x00\x12\x38\n\x0enested_message\x18P \x01(\x0b\x32 .A.B.C.TestMessage.NestedMessage\x1a\x1c\n\rNestedMessage\x12\x0b\n\x03\x66oo\x18\x01 \x01(\x05\x42\n\n\x08my_oneof*,\n\x08TestEnum\x12\x0b\n\x07\x44\x65\x66\x61ult\x10\x00\x12\x05\n\x01\x41\x10\x01\x12\x05\n\x01\x42\x10\x02\x12\x05\n\x01\x43\x10\x03" pool = Google::Protobuf::DescriptorPool.generated_pool - -begin - pool.add_serialized_file(descriptor_data) -rescue TypeError - # Compatibility code: will be removed in the next major version. - require 'google/protobuf/descriptor_pb' - parsed = Google::Protobuf::FileDescriptorProto.decode(descriptor_data) - parsed.clear_dependency - serialized = parsed.class.encode(parsed) - file = pool.add_serialized_file(serialized) - warn "Warning: Protobuf detected an import path issue while loading generated file #{__FILE__}" - imports = [ - ["A.B.C.TestImportedMessage", "ruby_generated_code_proto2_import.proto"], - ] - imports.each do |type_name, expected_filename| - import_file = pool.lookup(type_name).file_descriptor - if import_file.name != expected_filename - warn "- #{file.name} imports #{expected_filename}, but that import was loaded as #{import_file.name}" - end - end - warn "Each proto file must use a consistent fully-qualified name." - warn "This will become an error in the next major version." -end +pool.add_serialized_file(descriptor_data) module A module B diff --git a/src/google/protobuf/compiler/ruby/ruby_generated_pkg_explicit_legacy_pb.rb b/src/google/protobuf/compiler/ruby/ruby_generated_pkg_explicit_legacy_pb.rb index bb8cc106152f9..69f774539c82d 100644 --- a/src/google/protobuf/compiler/ruby/ruby_generated_pkg_explicit_legacy_pb.rb +++ b/src/google/protobuf/compiler/ruby/ruby_generated_pkg_explicit_legacy_pb.rb @@ -8,28 +8,7 @@ descriptor_data = "\n(ruby_generated_pkg_explicit_legacy.proto\x12\x13one.two.a_three.and\"\x1e\n\x04\x46our\x12\x16\n\x0e\x61nother_string\x18\x01 \x01(\tB\x0b\xea\x02\x08\x41\x41.BB.CCb\x06proto3" pool = Google::Protobuf::DescriptorPool.generated_pool - -begin - pool.add_serialized_file(descriptor_data) -rescue TypeError - # Compatibility code: will be removed in the next major version. - require 'google/protobuf/descriptor_pb' - parsed = Google::Protobuf::FileDescriptorProto.decode(descriptor_data) - parsed.clear_dependency - serialized = parsed.class.encode(parsed) - file = pool.add_serialized_file(serialized) - warn "Warning: Protobuf detected an import path issue while loading generated file #{__FILE__}" - imports = [ - ] - imports.each do |type_name, expected_filename| - import_file = pool.lookup(type_name).file_descriptor - if import_file.name != expected_filename - warn "- #{file.name} imports #{expected_filename}, but that import was loaded as #{import_file.name}" - end - end - warn "Each proto file must use a consistent fully-qualified name." - warn "This will become an error in the next major version." -end +pool.add_serialized_file(descriptor_data) module AA module BB diff --git a/src/google/protobuf/compiler/ruby/ruby_generated_pkg_explicit_pb.rb b/src/google/protobuf/compiler/ruby/ruby_generated_pkg_explicit_pb.rb index 4d49ff8ffe552..f241bd927ad7e 100644 --- a/src/google/protobuf/compiler/ruby/ruby_generated_pkg_explicit_pb.rb +++ b/src/google/protobuf/compiler/ruby/ruby_generated_pkg_explicit_pb.rb @@ -8,28 +8,7 @@ descriptor_data = "\n!ruby_generated_pkg_explicit.proto\x12\x0fone.two.a_three\"\x18\n\x04\x46our\x12\x10\n\x08\x61_string\x18\x01 \x01(\tB\n\xea\x02\x07\x41::B::Cb\x06proto3" pool = Google::Protobuf::DescriptorPool.generated_pool - -begin - pool.add_serialized_file(descriptor_data) -rescue TypeError - # Compatibility code: will be removed in the next major version. - require 'google/protobuf/descriptor_pb' - parsed = Google::Protobuf::FileDescriptorProto.decode(descriptor_data) - parsed.clear_dependency - serialized = parsed.class.encode(parsed) - file = pool.add_serialized_file(serialized) - warn "Warning: Protobuf detected an import path issue while loading generated file #{__FILE__}" - imports = [ - ] - imports.each do |type_name, expected_filename| - import_file = pool.lookup(type_name).file_descriptor - if import_file.name != expected_filename - warn "- #{file.name} imports #{expected_filename}, but that import was loaded as #{import_file.name}" - end - end - warn "Each proto file must use a consistent fully-qualified name." - warn "This will become an error in the next major version." -end +pool.add_serialized_file(descriptor_data) module A module B diff --git a/src/google/protobuf/compiler/ruby/ruby_generated_pkg_implicit_pb.rb b/src/google/protobuf/compiler/ruby/ruby_generated_pkg_implicit_pb.rb index 7235a16ccd01e..7c652df7ec62e 100644 --- a/src/google/protobuf/compiler/ruby/ruby_generated_pkg_implicit_pb.rb +++ b/src/google/protobuf/compiler/ruby/ruby_generated_pkg_implicit_pb.rb @@ -8,28 +8,7 @@ descriptor_data = "\n!ruby_generated_pkg_implicit.proto\x12\x0fone.two.a_three\"\x18\n\x04\x46our\x12\x10\n\x08\x61_string\x18\x01 \x01(\tb\x06proto3" pool = Google::Protobuf::DescriptorPool.generated_pool - -begin - pool.add_serialized_file(descriptor_data) -rescue TypeError - # Compatibility code: will be removed in the next major version. - require 'google/protobuf/descriptor_pb' - parsed = Google::Protobuf::FileDescriptorProto.decode(descriptor_data) - parsed.clear_dependency - serialized = parsed.class.encode(parsed) - file = pool.add_serialized_file(serialized) - warn "Warning: Protobuf detected an import path issue while loading generated file #{__FILE__}" - imports = [ - ] - imports.each do |type_name, expected_filename| - import_file = pool.lookup(type_name).file_descriptor - if import_file.name != expected_filename - warn "- #{file.name} imports #{expected_filename}, but that import was loaded as #{import_file.name}" - end - end - warn "Each proto file must use a consistent fully-qualified name." - warn "This will become an error in the next major version." -end +pool.add_serialized_file(descriptor_data) module One module Two diff --git a/src/google/protobuf/compiler/ruby/ruby_generator.cc b/src/google/protobuf/compiler/ruby/ruby_generator.cc index 1d85046b24a19..82f1a9556a54c 100644 --- a/src/google/protobuf/compiler/ruby/ruby_generator.cc +++ b/src/google/protobuf/compiler/ruby/ruby_generator.cc @@ -253,28 +253,7 @@ void GenerateBinaryDescriptor(const FileDescriptor* file, io::Printer* printer, descriptor_data = "$descriptor_data$" pool = Google::Protobuf::DescriptorPool.generated_pool - -begin - pool.add_serialized_file(descriptor_data) -rescue TypeError - # Compatibility code: will be removed in the next major version. - require 'google/protobuf/descriptor_pb' - parsed = Google::Protobuf::FileDescriptorProto.decode(descriptor_data) - parsed.clear_dependency - serialized = parsed.class.encode(parsed) - file = pool.add_serialized_file(serialized) - warn "Warning: Protobuf detected an import path issue while loading generated file #{__FILE__}" - imports = [ -$imports$ ] - imports.each do |type_name, expected_filename| - import_file = pool.lookup(type_name).file_descriptor - if import_file.name != expected_filename - warn "- #{file.name} imports #{expected_filename}, but that import was loaded as #{import_file.name}" - end - end - warn "Each proto file must use a consistent fully-qualified name." - warn "This will become an error in the next major version." -end +pool.add_serialized_file(descriptor_data) )", "descriptor_data", From f4ff5018df42fa6c565a55574e22ed40d6c7134e Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Wed, 3 Jan 2024 13:27:14 -0800 Subject: [PATCH 161/255] Add manual epilogue for vectorized loop, and use the SIMD loop for 64 bit ints when AVX2 is available. PiperOrigin-RevId: 595487765 --- src/google/protobuf/wire_format_lite.cc | 52 ++++++++++++++++++++----- 1 file changed, 42 insertions(+), 10 deletions(-) diff --git a/src/google/protobuf/wire_format_lite.cc b/src/google/protobuf/wire_format_lite.cc index 7789f9288d53c..f6d97df6c0c65 100644 --- a/src/google/protobuf/wire_format_lite.cc +++ b/src/google/protobuf/wire_format_lite.cc @@ -637,9 +637,18 @@ static size_t VarintSize(const T* data, const int n) { "Cannot SignExtended unsigned types"); static_assert(!(SignExtended && ZigZag), "Cannot SignExtended and ZigZag on the same type"); - uint32_t sum = n; + // This approach is only faster when vectorized, and the vectorized + // implementation only works in units of the platform's vector width, and is + // only faster once a certain number of iterations are used. Normally the + // compiler generates two loops - one partially unrolled vectorized loop that + // processes big chunks, and a second "epilogue" scalar loop to finish up the + // remainder. This is done manually here so that the faster scalar + // implementation is used for small inputs and for the epilogue. + int vectorN = n & -32; + uint32_t sum = vectorN; uint32_t msb_sum = 0; - for (int i = 0; i < n; i++) { + int i = 0; + for (; i < vectorN; i++) { uint32_t x = data[i]; if (ZigZag) { x = WireFormatLite::ZigZagEncode32(x); @@ -655,6 +664,19 @@ static size_t VarintSize(const T* data, const int n) { if (x > 0x1FFFFF) sum++; if (x > 0xFFFFFFF) sum++; } +// Clang is not smart enough to see that this loop doesn't run many times +// NOLINTNEXTLINE(google3-runtime-pragma-loop-hint): b/315043579 +#pragma clang loop vectorize(disable) unroll(disable) interleave(disable) + for (; i < n; i++) { + uint32_t x = data[i]; + if (ZigZag) { + sum += WireFormatLite::SInt32Size(x); + } else if (SignExtended) { + sum += WireFormatLite::Int32Size(x); + } else { + sum += WireFormatLite::UInt32Size(x); + } + } if (SignExtended) sum += msb_sum * 5; return sum; } @@ -665,8 +687,10 @@ static size_t VarintSize64(const T* data, const int n) { // is_unsigned => !ZigZag static_assert(!ZigZag || !std::is_unsigned::value, "Cannot ZigZag encode unsigned types"); - uint64_t sum = n; - for (int i = 0; i < n; i++) { + int vectorN = n & -32; + uint64_t sum = vectorN; + int i = 0; + for (; i < vectorN; i++) { uint64_t x = data[i]; if (ZigZag) { x = WireFormatLite::ZigZagEncode64(x); @@ -682,6 +706,17 @@ static size_t VarintSize64(const T* data, const int n) { if (x > 0x1FFFFF) sum++; if (x > 0xFFFFFFF) sum++; } +// Clang is not smart enough to see that this loop doesn't run many times +// NOLINTNEXTLINE(google3-runtime-pragma-loop-hint): b/315043579 +#pragma clang loop vectorize(disable) unroll(disable) interleave(disable) + for (; i < n; i++) { + uint64_t x = data[i]; + if (ZigZag) { + sum += WireFormatLite::SInt64Size(x); + } else { + sum += WireFormatLite::UInt64Size(x); + } + } return sum; } @@ -749,12 +784,9 @@ size_t WireFormatLite::EnumSize(const RepeatedField& value) { #endif -// Micro benchmarks show that the SSE improved loop only starts beating -// the normal loop on Haswell platforms and then only for >32 ints. We -// disable this for now. Some specialized users might find it worthwhile to -// enable this. -#define USE_SSE_FOR_64_BIT_INTEGER_ARRAYS 0 -#if USE_SSE_FOR_64_BIT_INTEGER_ARRAYS +// Micro benchmarks show that the vectorizable loop only starts beating +// the normal loop when 256-bit vector registers are available. +#if defined(__AVX2__) && defined(__clang__) size_t WireFormatLite::Int64Size(const RepeatedField& value) { return VarintSize64(value.data(), value.size()); } From b660646cc2b63af81dd968f12237fda6b5b1c59b Mon Sep 17 00:00:00 2001 From: Sandy Zhang Date: Wed, 3 Jan 2024 14:50:26 -0800 Subject: [PATCH 162/255] internal change PiperOrigin-RevId: 595509922 --- .../protobuf/compiler/java/shared_code_generator.cc | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/google/protobuf/compiler/java/shared_code_generator.cc b/src/google/protobuf/compiler/java/shared_code_generator.cc index b73c37ea655af..ec6deffb3a589 100644 --- a/src/google/protobuf/compiler/java/shared_code_generator.cc +++ b/src/google/protobuf/compiler/java/shared_code_generator.cc @@ -73,10 +73,21 @@ void SharedCodeGenerator::Generate( if (!options_.opensource_runtime) { printer->Print("@com.google.protobuf.Internal.ProtoNonnullApi\n"); } + printer->Print( + "public final class $classname$ {\n" + " /* This variable is to be called by generated code only. It " + "returns\n" + " * an incomplete descriptor for internal use only. */\n" " public static com.google.protobuf.Descriptors.FileDescriptor\n" " descriptor;\n" + " /* This method is to be called by generated code only. It returns\n" + " * an incomplete descriptor for internal use only. */\n" + " public static com.google.protobuf.Descriptors.FileDescriptor " + "getDescriptor() {\n" + " return descriptor;\n" + " }\n" " static {\n", "classname", classname); printer->Annotate("classname", file_->name()); From a7b0421c78412baa48704d727601a17ac0f451d1 Mon Sep 17 00:00:00 2001 From: Adam Cozzette Date: Wed, 3 Jan 2024 15:17:41 -0800 Subject: [PATCH 163/255] Breaking change: make protobuf comply with the C++ layering check This check enforces that each C++ build target has the correct dependencies for all headers that it includes. We have many targets that were not correct with respect to this check, so I fixed them up. I also cleaned up the C++ targets related to the well-known types. I created a cc_proto_library() target for each one and removed the :wkt_cc_protos target, since this was necessary to satisfy the layering check. I deleted the //src/google/protobuf:protobuf_nowkt target and deprecated :protobuf_nowkt, because the distinction between the :protobuf and :protobuf_nowkt targets was not really correct. Neither one exposed the headers for the well-known types in a way that was valid with respect to the layering check, and the idea of bundling all the well-known types together is not idiomatic in Bazel anyway. This is a breaking change, because the //:protobuf target no longer bundles the well-known types. From now on they should be accessed through the new //:*_cc_proto aliases in our top-level package. I renamed the :port_def target to :port, which simplifies things a bit by matching our internal name. The original motivation for this change was that to move utf8_range onto our CI infrastructure, we needed to make its dependency rules_fuzzing compatible with Bazel 6. The rules_fuzzing project builds with the layering check, and I found that the process of upgrading it to Bazel 6 made it take a dependency on protobuf, which caused it to break due to layering violations. I was able to work around this, but it would still be nice to comply with the layering check so that we don't have to worry about this kind of thing in the future. PiperOrigin-RevId: 595516736 --- .bazelrc | 4 + .github/workflows/test_java.yml | 8 +- BUILD.bazel | 88 ++++-- ci/common.bazelrc | 6 +- conformance/BUILD.bazel | 31 +- examples/BUILD.bazel | 2 + lua/BUILD.bazel | 3 + pkg/BUILD.bazel | 4 +- protos_generator/BUILD | 2 + python/build_targets.bzl | 13 +- rust/cpp_kernel/BUILD | 3 +- src/BUILD.bazel | 2 +- src/google/protobuf/BUILD.bazel | 283 +++++++++++++++--- src/google/protobuf/compiler/BUILD.bazel | 86 +++++- src/google/protobuf/compiler/cpp/BUILD.bazel | 45 ++- .../protobuf/compiler/csharp/BUILD.bazel | 18 +- src/google/protobuf/compiler/java/BUILD.bazel | 29 +- .../protobuf/compiler/objectivec/BUILD.bazel | 25 +- src/google/protobuf/compiler/php/BUILD.bazel | 11 +- .../protobuf/compiler/python/BUILD.bazel | 14 +- src/google/protobuf/compiler/ruby/BUILD.bazel | 9 +- src/google/protobuf/compiler/rust/BUILD.bazel | 37 ++- src/google/protobuf/editions/BUILD | 1 + src/google/protobuf/io/BUILD.bazel | 30 ++ src/google/protobuf/io/gzip_stream.h | 2 +- src/google/protobuf/json/BUILD.bazel | 56 +++- src/google/protobuf/stubs/BUILD.bazel | 5 +- src/google/protobuf/testing/BUILD.bazel | 6 +- src/google/protobuf/util/BUILD.bazel | 44 ++- upb/util/BUILD | 2 + 30 files changed, 745 insertions(+), 124 deletions(-) diff --git a/.bazelrc b/.bazelrc index 4eea8fb85cb76..b3467d87a575a 100644 --- a/.bazelrc +++ b/.bazelrc @@ -26,3 +26,7 @@ build:ubsan --copt=-fno-sanitize=function --copt=-fno-sanitize=vptr # TODO: migrate all dependencies from WORKSPACE to MODULE.bazel # https://github.com/protocolbuffers/protobuf/issues/14313 common --noenable_bzlmod + +# Important: this flag ensures that we remain compliant with the C++ layering +# check. +build --features=layering_check diff --git a/.github/workflows/test_java.yml b/.github/workflows/test_java.yml index 182493212900b..0d48cce9aab1b 100644 --- a/.github/workflows/test_java.yml +++ b/.github/workflows/test_java.yml @@ -20,7 +20,9 @@ jobs: - name: OpenJDK 8 version: '8' image: us-docker.pkg.dev/protobuf-build/containers/test/linux/java:8-1fdbb997433cb22c1e49ef75ad374a8d6bb88702 - targets: //java/... //java/internal:java_version + # TODO: b/318555165 - enable the layering check. Currently it does + # not work correctly with the toolchain in this Docker image. + targets: //java/... //java/internal:java_version --features=-layering_check - name: OpenJDK 11 version: '11' image: us-docker.pkg.dev/protobuf-build/containers/test/linux/java:11-1fdbb997433cb22c1e49ef75ad374a8d6bb88702 @@ -63,7 +65,9 @@ jobs: image: us-docker.pkg.dev/protobuf-build/containers/test/linux/java:8-1fdbb997433cb22c1e49ef75ad374a8d6bb88702 credentials: ${{ secrets.GAR_SERVICE_ACCOUNT }} bazel-cache: java_linux/8 - bazel: test --test_output=all //java:linkage_monitor --spawn_strategy=standalone + # TODO: b/318555165 - enable the layering check. Currently it does + # not work correctly with the toolchain in this Docker image. + bazel: test --test_output=all //java:linkage_monitor --spawn_strategy=standalone --features=-layering_check protobuf-bom: name: Protobuf Maven BOM diff --git a/BUILD.bazel b/BUILD.bazel index 6a245bc945231..c37fb11b032bf 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -85,6 +85,68 @@ alias( visibility = ["//visibility:public"], ) +# C++ targets for the well-known types + +alias( + name = "any_cc_proto", + actual = "//src/google/protobuf:any_cc_proto", + visibility = ["//visibility:public"], +) + +alias( + name = "api_cc_proto", + actual = "//src/google/protobuf:api_cc_proto", + visibility = ["//visibility:public"], +) + +alias( + name = "duration_cc_proto", + actual = "//src/google/protobuf:duration_cc_proto", + visibility = ["//visibility:public"], +) + +alias( + name = "empty_cc_proto", + actual = "//src/google/protobuf:empty_cc_proto", + visibility = ["//visibility:public"], +) + +alias( + name = "field_mask_cc_proto", + actual = "//src/google/protobuf:field_mask_cc_proto", + visibility = ["//visibility:public"], +) + +alias( + name = "source_context_cc_proto", + actual = "//src/google/protobuf:source_context_cc_proto", + visibility = ["//visibility:public"], +) + +alias( + name = "struct_cc_proto", + actual = "//src/google/protobuf:struct_cc_proto", + visibility = ["//visibility:public"], +) + +alias( + name = "timestamp_cc_proto", + actual = "//src/google/protobuf:timestamp_cc_proto", + visibility = ["//visibility:public"], +) + +alias( + name = "type_cc_proto", + actual = "//src/google/protobuf:type_cc_proto", + visibility = ["//visibility:public"], +) + +alias( + name = "wrappers_cc_proto", + actual = "//src/google/protobuf:wrappers_cc_proto", + visibility = ["//visibility:public"], +) + # Source files: these are aliases to a filegroup, not a `proto_library`. # # (This is _probably_ not what you want.) @@ -189,9 +251,16 @@ cc_binary( # Expose the runtime for the proto_lang_toolchain so that it can also be used in # a user-defined proto_lang_toolchain. +alias( + name = "protobuf", + actual = "//src/google/protobuf", + visibility = ["//visibility:public"], +) + alias( name = "protobuf_nowkt", actual = "//src/google/protobuf:protobuf_nowkt", + deprecation = "Use //:protobuf instead", visibility = ["//visibility:public"], ) @@ -210,23 +279,6 @@ alias( visibility = ["//visibility:public"], ) -cc_library( - name = "protobuf", - copts = COPTS, - linkopts = LINK_OPTS, - visibility = ["//visibility:public"], - deps = [ - "//src/google/protobuf", - "//src/google/protobuf/compiler:importer", - "//src/google/protobuf/util:delimited_message_util", - "//src/google/protobuf/util:differencer", - "//src/google/protobuf/util:field_mask_util", - "//src/google/protobuf/util:json_util", - "//src/google/protobuf/util:time_util", - "//src/google/protobuf/util:type_resolver_util", - ], -) - # This provides just the header files for use in projects that need to build # shared libraries for dynamic loading. This target is available until Bazel # adds native support for such use cases. @@ -324,7 +376,7 @@ proto_lang_toolchain( "//:descriptor_proto", ], command_line = "--cpp_out=$(OUT)", - runtime = "//src/google/protobuf:protobuf_nowkt", + runtime = "//src/google/protobuf", visibility = ["//visibility:public"], ) diff --git a/ci/common.bazelrc b/ci/common.bazelrc index fd24b0a3c1f9e..f8100e8480feb 100644 --- a/ci/common.bazelrc +++ b/ci/common.bazelrc @@ -68,4 +68,8 @@ build --incompatible_use_host_features # TODO: migrate all dependencies from WORKSPACE to MODULE.bazel # https://github.com/protocolbuffers/protobuf/issues/14313 -common --noenable_bzlmod \ No newline at end of file +common --noenable_bzlmod + +# Important: this flag ensures that we remain compliant with the C++ layering +# check. +build --features=layering_check diff --git a/conformance/BUILD.bazel b/conformance/BUILD.bazel index 1d9ea1585c735..76be11ee92aa4 100644 --- a/conformance/BUILD.bazel +++ b/conformance/BUILD.bazel @@ -1,16 +1,16 @@ # Conformance testing for Protobuf. load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library", "cc_proto_library", "objc_library") -load("@rules_ruby//ruby:defs.bzl", "ruby_binary") -load("//ruby:defs.bzl", "internal_ruby_proto_library") -load("//:protobuf.bzl", "internal_csharp_proto_library", "internal_objc_proto_library", "internal_php_proto_library", "internal_py_proto_library") -load("//build_defs:internal_shell.bzl", "inline_sh_binary") load( "@rules_pkg//:mappings.bzl", "pkg_filegroup", "pkg_files", "strip_prefix", ) +load("@rules_ruby//ruby:defs.bzl", "ruby_binary") +load("//:protobuf.bzl", "internal_csharp_proto_library", "internal_objc_proto_library", "internal_php_proto_library", "internal_py_proto_library") +load("//build_defs:internal_shell.bzl", "inline_sh_binary") +load("//ruby:defs.bzl", "internal_ruby_proto_library") exports_files([ "bazel_conformance_test_runner.sh", @@ -144,9 +144,15 @@ cc_library( includes = ["."], deps = [ ":conformance_cc_proto", + "//src/google/protobuf", + "//src/google/protobuf:protobuf_lite", "//src/google/protobuf/util:differencer", "//src/google/protobuf/util:json_util", "//src/google/protobuf/util:type_resolver_util", + "@com_google_absl//absl/container:btree", + "@com_google_absl//absl/container:flat_hash_set", + "@com_google_absl//absl/log:absl_check", + "@com_google_absl//absl/log:absl_log", "@com_google_absl//absl/strings", "@com_google_absl//absl/strings:str_format", ], @@ -158,13 +164,21 @@ cc_library( srcs = ["binary_json_conformance_suite.cc"], hdrs = ["binary_json_conformance_suite.h"], deps = [ + ":conformance_cc_proto", ":conformance_test", ":test_messages_proto2_proto_cc", ":test_messages_proto3_proto_cc", + "//src/google/protobuf", + "//src/google/protobuf:protobuf_lite", "//src/google/protobuf/editions:test_messages_proto2_editions_cc_proto", "//src/google/protobuf/editions:test_messages_proto3_editions_cc_proto", + "//src/google/protobuf/json", + "//src/google/protobuf/util:type_resolver_util", + "@com_google_absl//absl/log:absl_check", + "@com_google_absl//absl/log:absl_log", "@com_google_absl//absl/log:die_if_null", "@com_google_absl//absl/status", + "@com_google_absl//absl/strings", "@jsoncpp", ], ) @@ -178,6 +192,7 @@ cc_library( ":conformance_test", ":test_messages_proto2_proto_cc", ":test_messages_proto3_proto_cc", + "//src/google/protobuf", "//src/google/protobuf/editions:test_messages_proto2_editions_cc_proto", "//src/google/protobuf/editions:test_messages_proto3_editions_cc_proto", "@com_google_absl//absl/log:absl_log", @@ -209,8 +224,16 @@ cc_binary( "//:protobuf", "//:test_messages_proto2_cc_proto", "//:test_messages_proto3_cc_proto", + "//src/google/protobuf", + "//src/google/protobuf:port", + "//src/google/protobuf:protobuf_lite", "//src/google/protobuf/editions:test_messages_proto2_editions_cc_proto", "//src/google/protobuf/editions:test_messages_proto3_editions_cc_proto", + "//src/google/protobuf/stubs", + "//src/google/protobuf/util:json_util", + "//src/google/protobuf/util:type_resolver_util", + "@com_google_absl//absl/log:absl_check", + "@com_google_absl//absl/log:absl_log", "@com_google_absl//absl/status", "@com_google_absl//absl/status:statusor", ], diff --git a/examples/BUILD.bazel b/examples/BUILD.bazel index 265a0b978d497..a70bd76655306 100644 --- a/examples/BUILD.bazel +++ b/examples/BUILD.bazel @@ -39,6 +39,7 @@ cc_binary( deps = [ ":addressbook_cc_proto", "@com_google_protobuf//:protobuf", + "@com_google_protobuf//src/google/protobuf/util:time_util", ], ) @@ -48,6 +49,7 @@ cc_binary( deps = [ ":addressbook_cc_proto", "@com_google_protobuf//:protobuf", + "@com_google_protobuf//src/google/protobuf/util:time_util", ], ) diff --git a/lua/BUILD.bazel b/lua/BUILD.bazel index 6216f9c27ae9b..5b7ccc9601ad1 100644 --- a/lua/BUILD.bazel +++ b/lua/BUILD.bazel @@ -32,6 +32,7 @@ cc_library( deps = [ "//upb:json", "//upb:message", + "//upb:port", "//upb:reflection", "//upb:text", "@lua//:liblua", @@ -44,7 +45,9 @@ cc_binary( copts = UPB_DEFAULT_CPPOPTS, visibility = ["//visibility:public"], deps = [ + "//src/google/protobuf", "//src/google/protobuf/compiler:code_generator", + "//src/google/protobuf/io:printer", "@com_google_absl//absl/strings", ], ) diff --git a/pkg/BUILD.bazel b/pkg/BUILD.bazel index 55079a67e2539..64eb64903ae82 100644 --- a/pkg/BUILD.bazel +++ b/pkg/BUILD.bazel @@ -1,9 +1,9 @@ -load("@rules_pkg//:pkg.bzl", "pkg_zip") load( "@rules_pkg//:mappings.bzl", "pkg_attributes", "pkg_files", ) +load("@rules_pkg//:pkg.bzl", "pkg_zip") load("//:protobuf_release.bzl", "package_naming") load(":build_systems.bzl", "gen_file_lists") load(":cc_dist_library.bzl", "cc_dist_library") @@ -163,9 +163,9 @@ cc_dist_library( }), tags = ["manual"], deps = [ + "//src/google/protobuf", "//src/google/protobuf:arena_align", "//src/google/protobuf:cmake_wkt_cc_proto", - "//src/google/protobuf:protobuf_nowkt", "//src/google/protobuf/compiler:importer", "//src/google/protobuf/json", "//src/google/protobuf/util:delimited_message_util", diff --git a/protos_generator/BUILD b/protos_generator/BUILD index d76c944faefe2..d5b65bfa00969 100644 --- a/protos_generator/BUILD +++ b/protos_generator/BUILD @@ -72,6 +72,7 @@ cc_library( visibility = ["//visibility:private"], deps = [ "//:protobuf", + "//src/google/protobuf/io", "@com_google_absl//absl/log:absl_log", "@com_google_absl//absl/strings", ], @@ -96,6 +97,7 @@ cc_library( visibility = ["//visibility:private"], deps = [ ":output", + "//src/google/protobuf", "//upb_generator:keywords", ], ) diff --git a/python/build_targets.bzl b/python/build_targets.bzl index 05ed1637cefb5..b81baab4e1fc0 100644 --- a/python/build_targets.bzl +++ b/python/build_targets.bzl @@ -120,7 +120,18 @@ def build_targets(name): ], deps = [ ":proto_api", - "//:protobuf", + "//src/google/protobuf", + "//src/google/protobuf:port", + "//src/google/protobuf:protobuf_lite", + "//src/google/protobuf/io", + "//src/google/protobuf/io:tokenizer", + "//src/google/protobuf/stubs:lite", + "//src/google/protobuf/util:differencer", + "@com_google_absl//absl/container:flat_hash_map", + "@com_google_absl//absl/log:absl_check", + "@com_google_absl//absl/log:absl_log", + "@com_google_absl//absl/status", + "@com_google_absl//absl/strings", ] + select({ "//conditions:default": [], ":use_fast_cpp_protos": ["//external:python_headers"], diff --git a/rust/cpp_kernel/BUILD b/rust/cpp_kernel/BUILD index 6582b038985e0..34697ee81f16c 100644 --- a/rust/cpp_kernel/BUILD +++ b/rust/cpp_kernel/BUILD @@ -12,7 +12,8 @@ cc_library( ], deps = [ ":rust_alloc_for_cpp_api", # buildcleaner: keep - "//:protobuf_nowkt", + "//:protobuf", + "//:protobuf_lite", "@com_google_absl//absl/strings:string_view", ], ) diff --git a/src/BUILD.bazel b/src/BUILD.bazel index 7c42d0b01a387..26e15b3bfb2e5 100644 --- a/src/BUILD.bazel +++ b/src/BUILD.bazel @@ -4,8 +4,8 @@ # Most rules are under google/protobuf. This package exists for convenience. load("@rules_pkg//:mappings.bzl", "pkg_filegroup", "pkg_files", "strip_prefix") -load("//upb/cmake:build_defs.bzl", "staleness_test") load("//conformance:defs.bzl", "conformance_test") +load("//upb/cmake:build_defs.bzl", "staleness_test") pkg_files( name = "dist_files", diff --git a/src/google/protobuf/BUILD.bazel b/src/google/protobuf/BUILD.bazel index 5e7f5479c58e5..d7e6faf28f0f4 100644 --- a/src/google/protobuf/BUILD.bazel +++ b/src/google/protobuf/BUILD.bazel @@ -12,6 +12,7 @@ package( default_visibility = [ "//:__pkg__", # "public" targets are alias rules in //. "//json:__subpackages__", + "//src/google/protobuf:__subpackages__", ], ) @@ -21,6 +22,11 @@ proto_library( strip_import_prefix = "/src", ) +cc_proto_library( + name = "any_cc_proto", + deps = [":any_proto"], +) + proto_library( name = "api_proto", srcs = ["api.proto"], @@ -31,42 +37,77 @@ proto_library( ], ) +cc_proto_library( + name = "api_cc_proto", + deps = [":api_proto"], +) + proto_library( name = "duration_proto", srcs = ["duration.proto"], strip_import_prefix = "/src", ) +cc_proto_library( + name = "duration_cc_proto", + deps = [":duration_proto"], +) + proto_library( name = "empty_proto", srcs = ["empty.proto"], strip_import_prefix = "/src", ) +cc_proto_library( + name = "empty_cc_proto", + deps = [":empty_proto"], +) + proto_library( name = "field_mask_proto", srcs = ["field_mask.proto"], strip_import_prefix = "/src", ) +cc_proto_library( + name = "field_mask_cc_proto", + deps = [":field_mask_proto"], +) + proto_library( name = "source_context_proto", srcs = ["source_context.proto"], strip_import_prefix = "/src", ) +cc_proto_library( + name = "source_context_cc_proto", + deps = [":source_context_proto"], +) + proto_library( name = "struct_proto", srcs = ["struct.proto"], strip_import_prefix = "/src", ) +cc_proto_library( + name = "struct_cc_proto", + deps = [":struct_proto"], +) + proto_library( name = "timestamp_proto", srcs = ["timestamp.proto"], strip_import_prefix = "/src", ) +cc_proto_library( + name = "timestamp_cc_proto", + deps = [":timestamp_proto"], +) + proto_library( name = "type_proto", srcs = ["type.proto"], @@ -77,12 +118,22 @@ proto_library( ], ) +cc_proto_library( + name = "type_cc_proto", + deps = [":type_proto"], +) + proto_library( name = "wrappers_proto", srcs = ["wrappers.proto"], strip_import_prefix = "/src", ) +cc_proto_library( + name = "wrappers_cc_proto", + deps = [":wrappers_proto"], +) + # Generate code for the well-known types on demand. # This needs to be done in a separate genrule because we publish protoc and the # C++ runtime with the WKT code linked in. We need to use a stripped down @@ -107,19 +158,6 @@ WELL_KNOWN_TYPES = [ "wrappers", ] -proto_library( - name = "wkt_proto", - strip_import_prefix = "/src", - visibility = ["//visibility:private"], - deps = [wkt + "_proto" for wkt in WELL_KNOWN_TYPES], -) - -cc_proto_library( - name = "wkt_cc_proto", - visibility = ["//pkg:__pkg__"], - deps = ["wkt_proto"], -) - # When we generate code for the well-known types, we put the resulting files in # wkt/google/protobuf and add ./wkt to the include paths below. This is a # somewhat strange setup but is necessary to satisfy these two constraints: @@ -164,7 +202,12 @@ cc_library( linkopts = LINK_OPTS, strip_include_prefix = "/src", visibility = ["//pkg:__pkg__"], - deps = [":protobuf_nowkt"], + deps = [ + ":port", + ":protobuf", + ":protobuf_lite", + "//src/google/protobuf/io", + ], ) # Built-in runtime types @@ -192,7 +235,7 @@ proto_library( ################################################################################ cc_library( - name = "port_def", + name = "port", srcs = ["port.cc"], hdrs = [ "port.h", @@ -205,6 +248,8 @@ cc_library( "//src/google/protobuf:__subpackages__", ], deps = [ + "@com_google_absl//absl/base:config", + "@com_google_absl//absl/base:core_headers", "@com_google_absl//absl/meta:type_traits", ], ) @@ -218,14 +263,14 @@ cc_library( "//:__subpackages__", "//src/google/protobuf:__subpackages__", ], - deps = [":port_def"], + deps = [":port"], ) cc_test( name = "varint_shuffle_test", srcs = ["varint_shuffle_test.cc"], deps = [ - ":port_def", + ":port", ":varint_shuffle", "@com_google_absl//absl/log:absl_check", "@com_google_googletest//:gtest", @@ -237,7 +282,7 @@ cc_test( name = "port_test", srcs = ["port_test.cc"], deps = [ - ":port_def", + ":port", ":varint_shuffle", "@com_google_absl//absl/base:config", "@com_google_absl//absl/log:absl_check", @@ -256,6 +301,7 @@ cc_library( "//src/google/protobuf:__subpackages__", ], deps = [ + "//src/google/protobuf:port", "//src/google/protobuf/stubs:lite", "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/log:absl_log", @@ -305,6 +351,7 @@ cc_test( name = "string_block_test", srcs = ["string_block_test.cc"], deps = [ + ":port", ":string_block", "@com_google_googletest//:gtest", "@com_google_googletest//:gtest_main", @@ -331,12 +378,15 @@ cc_library( ":arena_align", ":arena_allocation_policy", ":arena_cleanup", + ":port", ":string_block", "//src/google/protobuf/stubs:lite", + "@com_google_absl//absl/base:core_headers", "@com_google_absl//absl/base:prefetch", "@com_google_absl//absl/container:layout", "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/log:absl_log", + "@com_google_absl//absl/numeric:bits", "@com_google_absl//absl/synchronization", "@com_google_absl//absl/utility:if_constexpr", ], @@ -426,15 +476,16 @@ cc_library( linkopts = LINK_OPTS, strip_include_prefix = "/src", visibility = [ - "//:__pkg__", - "//pkg:__pkg__", - "//src/google/protobuf:__subpackages__", + "//:__subpackages__", ], # In Bazel 6.0+, these will be `interface_deps`: deps = [ ":arena", ":arena_align", + ":arena_allocation_policy", + ":arena_cleanup", ":internal_visibility", + ":port", ":string_block", ":varint_shuffle", "//src/google/protobuf/io", @@ -442,6 +493,9 @@ cc_library( "//third_party/utf8_range:utf8_validity", "@com_google_absl//absl/base", "@com_google_absl//absl/base:config", + "@com_google_absl//absl/base:core_headers", + "@com_google_absl//absl/base:dynamic_annotations", + "@com_google_absl//absl/base:prefetch", "@com_google_absl//absl/container:btree", "@com_google_absl//absl/container:flat_hash_set", "@com_google_absl//absl/hash", @@ -449,14 +503,20 @@ cc_library( "@com_google_absl//absl/log:absl_log", "@com_google_absl//absl/meta:type_traits", "@com_google_absl//absl/numeric:bits", + "@com_google_absl//absl/strings", + "@com_google_absl//absl/strings:cord", "@com_google_absl//absl/strings:internal", + "@com_google_absl//absl/strings:str_format", "@com_google_absl//absl/synchronization", "@com_google_absl//absl/time", + "@com_google_absl//absl/types:optional", + "@com_google_absl//absl/types:span", + "@com_google_absl//absl/utility:if_constexpr", ], ) cc_library( - name = "protobuf_nowkt", + name = "protobuf", srcs = [ "any.cc", "cpp_features.pb.cc", @@ -513,11 +573,11 @@ cc_library( linkopts = LINK_OPTS, strip_include_prefix = "/src", visibility = [ - "//:__pkg__", - "//pkg:__pkg__", - "//src/google/protobuf:__subpackages__", + "//:__subpackages__", ], deps = [ + ":internal_visibility", + ":port", ":protobuf_lite", "//src/google/protobuf/io", "//src/google/protobuf/io:gzip_stream", @@ -525,17 +585,30 @@ cc_library( "//src/google/protobuf/io:tokenizer", "//src/google/protobuf/stubs", "//third_party/utf8_range:utf8_validity", + "@com_google_absl//absl/algorithm:container", "@com_google_absl//absl/base", + "@com_google_absl//absl/base:core_headers", "@com_google_absl//absl/base:dynamic_annotations", "@com_google_absl//absl/container:btree", "@com_google_absl//absl/container:flat_hash_map", "@com_google_absl//absl/container:flat_hash_set", + "@com_google_absl//absl/functional:any_invocable", + "@com_google_absl//absl/functional:function_ref", "@com_google_absl//absl/hash", "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/log:absl_log", + "@com_google_absl//absl/memory", + "@com_google_absl//absl/status", + "@com_google_absl//absl/status:statusor", + "@com_google_absl//absl/strings", + "@com_google_absl//absl/strings:cord", "@com_google_absl//absl/strings:internal", + "@com_google_absl//absl/strings:str_format", "@com_google_absl//absl/synchronization", "@com_google_absl//absl/time", + "@com_google_absl//absl/types:optional", + "@com_google_absl//absl/types:span", + "@com_google_absl//absl/types:variant", ], ) @@ -550,23 +623,6 @@ cc_test( ], ) -cc_library( - name = "protobuf", - copts = COPTS, - linkopts = LINK_OPTS, - strip_include_prefix = "/src", - visibility = [ - "//:__pkg__", - "//pkg:__pkg__", - "//rust:__subpackages__", - "//src/google/protobuf:__subpackages__", - ], - deps = [ - ":protobuf_nowkt", - ":wkt_cc_proto", - ], -) - # This provides just the header files for use in projects that need to build # shared libraries for dynamic loading. This target is available until Bazel # adds native support for such use cases. @@ -588,8 +644,8 @@ cc_library( strip_include_prefix = "/src", visibility = ["//:__subpackages__"], deps = [ - ":port_def", - ":protobuf_nowkt", + ":port", + ":protobuf", ], ) @@ -875,11 +931,14 @@ cc_library( strip_include_prefix = "/src", visibility = ["//:__subpackages__"], deps = [ + ":arena", ":cc_lite_test_protos", - ":port_def", + ":port", ":test_util2", + "//src/google/protobuf/io", "@com_google_absl//absl/container:flat_hash_set", "@com_google_absl//absl/log:absl_check", + "@com_google_absl//absl/strings", "@com_google_googletest//:gtest", ], ) @@ -915,6 +974,8 @@ cc_library( ":cc_lite_test_protos", ":cc_test_protos", ":lite_test_util", + ":port", + ":protobuf", "//src/google/protobuf/testing", "@com_google_absl//absl/container:flat_hash_map", "@com_google_absl//absl/log:absl_check", @@ -941,9 +1002,13 @@ cc_test( name = "any_test", srcs = ["any_test.cc"], deps = [ + ":any_cc_proto", + ":cc_test_protos", + ":port", ":protobuf", ":test_util", "@com_google_absl//absl/log:absl_check", + "@com_google_absl//absl/strings", "@com_google_googletest//:gtest", "@com_google_googletest//:gtest_main", ], @@ -975,10 +1040,19 @@ cc_test( ], }), deps = [ + ":arena", ":cc_test_protos", ":lite_test_util", + ":port", ":protobuf", + ":protobuf_lite", ":test_util", + "//src/google/protobuf/io", + "@com_google_absl//absl/log:absl_check", + "@com_google_absl//absl/log:absl_log", + "@com_google_absl//absl/strings", + "@com_google_absl//absl/synchronization", + "@com_google_absl//absl/utility", "@com_google_googletest//:gtest", "@com_google_googletest//:gtest_main", ], @@ -988,10 +1062,13 @@ cc_test( name = "arenastring_unittest", srcs = ["arenastring_unittest.cc"], deps = [ - ":port_def", + ":port", ":protobuf", + ":protobuf_lite", "//src/google/protobuf/io", "//src/google/protobuf/stubs", + "@com_google_absl//absl/log:absl_check", + "@com_google_absl//absl/strings", "@com_google_googletest//:gtest", "@com_google_googletest//:gtest_main", ], @@ -1001,6 +1078,8 @@ cc_test( name = "arenaz_sampler_test", srcs = ["arenaz_sampler_test.cc"], deps = [ + ":arena", + ":port", ":protobuf", "//src/google/protobuf/stubs", "@com_google_googletest//:gtest", @@ -1029,14 +1108,28 @@ cc_test( ], }), deps = [ + ":any_cc_proto", ":cc_test_protos", + ":port", ":protobuf", ":test_textproto", "//src/google/protobuf/compiler:importer", + "//src/google/protobuf/io", + "//src/google/protobuf/io:tokenizer", + "//src/google/protobuf/stubs", "//src/google/protobuf/testing", + "@com_google_absl//absl/container:btree", + "@com_google_absl//absl/container:flat_hash_set", + "@com_google_absl//absl/functional:any_invocable", + "@com_google_absl//absl/log:absl_check", + "@com_google_absl//absl/log:absl_log", "@com_google_absl//absl/log:die_if_null", "@com_google_absl//absl/log:scoped_mock_log", + "@com_google_absl//absl/status", + "@com_google_absl//absl/status:statusor", + "@com_google_absl//absl/strings", "@com_google_absl//absl/strings:str_format", + "@com_google_absl//absl/synchronization", "@com_google_googletest//:gtest", "@com_google_googletest//:gtest_main", ], @@ -1065,6 +1158,7 @@ cc_test( deps = [ ":cc_test_protos", ":protobuf", + ":protobuf_lite", "@com_google_googletest//:gtest", "@com_google_googletest//:gtest_main", ], @@ -1101,13 +1195,18 @@ cc_test( }), deps = [ ":cc_test_protos", + ":port", ":protobuf", + ":protobuf_lite", ":test_util", ":test_util2", "//src/google/protobuf/io", "//src/google/protobuf/stubs", "//src/google/protobuf/testing", "//src/google/protobuf/util:differencer", + "@com_google_absl//absl/base", + "@com_google_absl//absl/strings", + "@com_google_absl//absl/strings:cord", "@com_google_googletest//:gtest", "@com_google_googletest//:gtest_main", ], @@ -1119,15 +1218,22 @@ cc_test( copts = COPTS, deps = [ ":cc_test_protos", + ":port", ":protobuf", ":test_textproto", ":test_util", "//src/google/protobuf/compiler:importer", + "//src/google/protobuf/io", + "//src/google/protobuf/io:tokenizer", "//src/google/protobuf/stubs", "//src/google/protobuf/testing", "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/log:absl_log", "@com_google_absl//absl/log:die_if_null", + "@com_google_absl//absl/memory", + "@com_google_absl//absl/status", + "@com_google_absl//absl/status:statusor", + "@com_google_absl//absl/strings", "@com_google_googletest//:gtest", "@com_google_googletest//:gtest_main", ], @@ -1143,11 +1249,15 @@ cc_test( ], }), deps = [ + ":arena", ":cc_test_protos", + ":port", ":protobuf", ":test_util", "//src/google/protobuf/stubs", "//src/google/protobuf/testing", + "@com_google_absl//absl/log:absl_check", + "@com_google_absl//absl/strings:cord", "@com_google_googletest//:gtest", "@com_google_googletest//:gtest_main", ], @@ -1164,7 +1274,9 @@ cc_test( }), deps = [ ":cc_test_protos", + ":port", ":protobuf_lite", + "@com_google_absl//absl/types:optional", "@com_google_googletest//:gtest", "@com_google_googletest//:gtest_main", ], @@ -1176,8 +1288,11 @@ cc_test( deps = [ ":cc_test_protos", ":protobuf", + ":protobuf_lite", "//src/google/protobuf/io", "//src/google/protobuf/stubs", + "@com_google_absl//absl/log:absl_check", + "@com_google_absl//absl/strings", "@com_google_googletest//:gtest", "@com_google_googletest//:gtest_main", ], @@ -1207,9 +1322,13 @@ cc_test( deps = [ ":cc_lite_test_protos", ":lite_test_util", + ":port", ":protobuf", + ":protobuf_lite", "//src/google/protobuf/io", "//src/google/protobuf/stubs", + "@com_google_absl//absl/log:absl_check", + "@com_google_absl//absl/strings", "@com_google_googletest//:gtest", "@com_google_googletest//:gtest_main", ], @@ -1219,12 +1338,19 @@ cc_test( name = "map_field_test", srcs = ["map_field_test.cc"], deps = [ + ":arena", ":cc_test_protos", + ":lite_test_util", + ":port", ":protobuf", + ":protobuf_lite", ":test_util", "//src/google/protobuf/stubs", "@com_google_absl//absl/container:flat_hash_map", + "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/strings:str_format", + "@com_google_absl//absl/synchronization", + "@com_google_absl//absl/types:optional", "@com_google_googletest//:gtest", "@com_google_googletest//:gtest_main", ], @@ -1247,13 +1373,26 @@ cc_test( deps = [ ":cc_test_protos", ":internal_visibility_for_testing", + ":lite_test_util", + ":port", ":protobuf", + ":protobuf_lite", ":test_util", ":test_util2", + "//src/google/protobuf/io", + "//src/google/protobuf/io:tokenizer", + "//src/google/protobuf/testing", "//src/google/protobuf/util:differencer", "//src/google/protobuf/util:time_util", + "@com_google_absl//absl/base", + "@com_google_absl//absl/cleanup", + "@com_google_absl//absl/container:btree", "@com_google_absl//absl/container:flat_hash_map", "@com_google_absl//absl/container:flat_hash_set", + "@com_google_absl//absl/log:absl_check", + "@com_google_absl//absl/log:absl_log", + "@com_google_absl//absl/strings", + "@com_google_absl//absl/time", "@com_google_googletest//:gtest", "@com_google_googletest//:gtest_main", ], @@ -1267,14 +1406,22 @@ cc_test( ], data = [":testdata"], deps = [ + ":arena", ":cc_test_protos", + ":port", ":protobuf", + ":protobuf_lite", ":test_util", + ":test_util2", "//src/google/protobuf/io", + "//src/google/protobuf/io:io_win32", "//src/google/protobuf/stubs", "//src/google/protobuf/testing", "//src/google/protobuf/util:differencer", + "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/log:scoped_mock_log", + "@com_google_absl//absl/strings", + "@com_google_absl//absl/strings:cord", "@com_google_googletest//:gtest", "@com_google_googletest//:gtest_main", ], @@ -1306,6 +1453,7 @@ cc_test( name = "proto3_arena_lite_unittest", srcs = ["proto3_arena_lite_unittest.cc"], deps = [ + ":arena", ":cc_test_protos", ":protobuf", "//src/google/protobuf/testing", @@ -1324,11 +1472,14 @@ cc_test( ], }), deps = [ + ":arena", ":cc_test_protos", + ":port", ":protobuf", ":test_util", "//src/google/protobuf/stubs", "//src/google/protobuf/testing", + "@com_google_absl//absl/strings", "@com_google_googletest//:gtest", "@com_google_googletest//:gtest_main", ], @@ -1347,6 +1498,7 @@ cc_test( ], }), deps = [ + ":arena", ":cc_test_protos", ":lite_test_util", ":protobuf", @@ -1371,6 +1523,7 @@ cc_test( ":test_util", "//src/google/protobuf/stubs", "//src/google/protobuf/testing", + "@com_google_absl//absl/strings", "@com_google_googletest//:gtest", "@com_google_googletest//:gtest_main", ], @@ -1390,9 +1543,12 @@ cc_test( }), deps = [ ":cc_test_protos", + ":port", ":protobuf", ":test_util", "//src/google/protobuf/stubs", + "@com_google_absl//absl/base", + "@com_google_absl//absl/strings:cord", "@com_google_googletest//:gtest", "@com_google_googletest//:gtest_main", ], @@ -1411,12 +1567,17 @@ cc_test( ":cc_test_protos", ":internal_visibility_for_testing", ":lite_test_util", + ":port", ":protobuf", ":protobuf_lite", "//src/google/protobuf/io", "//src/google/protobuf/stubs", "//src/google/protobuf/testing", + "@com_google_absl//absl/log:absl_check", + "@com_google_absl//absl/numeric:bits", "@com_google_absl//absl/random", + "@com_google_absl//absl/strings", + "@com_google_absl//absl/strings:cord", "@com_google_absl//absl/types:span", "@com_google_googletest//:gtest", "@com_google_googletest//:gtest_main", @@ -1434,14 +1595,23 @@ cc_test( }), data = [":testdata"], deps = [ + ":any_cc_proto", ":cc_test_protos", + ":port", ":protobuf", ":test_util", + ":test_util2", "//src/google/protobuf/io", + "//src/google/protobuf/io:tokenizer", "//src/google/protobuf/stubs", "//src/google/protobuf/testing", + "//third_party/utf8_range:utf8_validity", + "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/log:die_if_null", "@com_google_absl//absl/log:scoped_mock_log", + "@com_google_absl//absl/strings", + "@com_google_absl//absl/strings:cord", + "@com_google_absl//absl/strings:str_format", "@com_google_googletest//:gtest", "@com_google_googletest//:gtest_main", ], @@ -1458,13 +1628,17 @@ cc_test( }), deps = [ ":cc_lite_test_protos", + ":cc_test_protos", ":protobuf", ":test_util", "//src/google/protobuf/io", "//src/google/protobuf/stubs", "//src/google/protobuf/testing", + "@com_google_absl//absl/container:flat_hash_set", "@com_google_absl//absl/functional:bind_front", + "@com_google_absl//absl/strings:cord", "@com_google_absl//absl/synchronization", + "@com_google_absl//absl/time", "@com_google_googletest//:gtest", "@com_google_googletest//:gtest_main", ], @@ -1497,14 +1671,20 @@ cc_test( ], deps = [ ":cc_test_protos", + ":port", ":protobuf", + ":protobuf_lite", ":test_util", ":test_util2", "//src/google/protobuf/io", "//src/google/protobuf/stubs", "//src/google/protobuf/testing", "//src/google/protobuf/util:differencer", + "@com_google_absl//absl/base", + "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/log:scoped_mock_log", + "@com_google_absl//absl/strings", + "@com_google_absl//absl/strings:cord", "@com_google_googletest//:gtest", "@com_google_googletest//:gtest_main", ], @@ -1514,10 +1694,13 @@ cc_test( name = "generated_enum_util_test", srcs = ["generated_enum_util_test.cc"], deps = [ + ":port", ":protobuf", + ":protobuf_lite", "@com_google_absl//absl/container:btree", "@com_google_absl//absl/strings:str_format", "@com_google_absl//absl/types:span", + "@com_google_googletest//:gtest", "@com_google_googletest//:gtest_main", ], ) @@ -1530,7 +1713,11 @@ cc_test( ":protobuf", "//src/google/protobuf/compiler:importer", "//src/google/protobuf/compiler:retention", + "//src/google/protobuf/io", + "//src/google/protobuf/io:tokenizer", "//src/google/protobuf/util:differencer", + "@com_google_absl//absl/strings", + "@com_google_googletest//:gtest", "@com_google_googletest//:gtest_main", ], ) @@ -1539,7 +1726,7 @@ cc_test( name = "reflection_mode_test", srcs = ["reflection_mode_test.cc"], deps = [ - ":protobuf_nowkt", + ":protobuf", "@com_google_googletest//:gtest", "@com_google_googletest//:gtest_main", ], @@ -1566,6 +1753,7 @@ cc_library( visibility = ["//visibility:public"], deps = [ ":protobuf", + ":protobuf_lite", ], ) @@ -1577,6 +1765,7 @@ cc_test( ":cc_test_protos", ":protobuf", ":unredacted_debug_format_for_test", + "@com_google_googletest//:gtest", "@com_google_googletest//:gtest_main", ], ) diff --git a/src/google/protobuf/compiler/BUILD.bazel b/src/google/protobuf/compiler/BUILD.bazel index 13a340e7ceec5..519bfc4e417f6 100644 --- a/src/google/protobuf/compiler/BUILD.bazel +++ b/src/google/protobuf/compiler/BUILD.bazel @@ -45,10 +45,20 @@ cc_library( strip_include_prefix = "/src", visibility = ["//visibility:public"], deps = [ - "//src/google/protobuf:protobuf_nowkt", + "//src/google/protobuf", + "//src/google/protobuf:port", + "//src/google/protobuf:protobuf_lite", + "//src/google/protobuf/io", + "//src/google/protobuf/io:io_win32", + "//src/google/protobuf/io:tokenizer", + "@com_google_absl//absl/base", + "@com_google_absl//absl/container:flat_hash_map", + "@com_google_absl//absl/container:flat_hash_set", "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/log:absl_log", "@com_google_absl//absl/strings", + "@com_google_absl//absl/strings:cord", + "@com_google_absl//absl/strings:str_format", ], ) @@ -69,13 +79,18 @@ cc_library( strip_include_prefix = "/src", visibility = ["//visibility:public"], deps = [ - "//src/google/protobuf:protobuf_nowkt", + "//src/google/protobuf", + "//src/google/protobuf:port", + "//src/google/protobuf:protobuf_lite", "//src/google/protobuf/compiler:retention", + "//src/google/protobuf/io", "//src/google/protobuf/io:io_win32", "@com_google_absl//absl/container:flat_hash_map", "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/log:absl_log", "@com_google_absl//absl/memory", + "@com_google_absl//absl/status", + "@com_google_absl//absl/status:statusor", "@com_google_absl//absl/strings", ], ) @@ -95,7 +110,7 @@ cc_library( ], deps = [ ":code_generator", - "//src/google/protobuf:port_def", + "//src/google/protobuf:port", "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/strings", ], @@ -133,13 +148,22 @@ cc_library( ":code_generator", ":importer", ":retention", - "//src/google/protobuf:protobuf_nowkt", + "//src/google/protobuf", + "//src/google/protobuf:port", "//src/google/protobuf/compiler/allowlists", + "//src/google/protobuf/io", + "//src/google/protobuf/io:io_win32", + "//src/google/protobuf/io:printer", + "//src/google/protobuf/stubs", "@com_google_absl//absl/algorithm", "@com_google_absl//absl/algorithm:container", "@com_google_absl//absl/container:btree", + "@com_google_absl//absl/container:flat_hash_map", + "@com_google_absl//absl/container:flat_hash_set", "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/log:absl_log", + "@com_google_absl//absl/status", + "@com_google_absl//absl/status:statusor", "@com_google_absl//absl/strings", "@com_google_absl//absl/strings:str_format", "@com_google_absl//absl/types:span", @@ -161,7 +185,8 @@ cc_library( ":code_generator", ":command_line_interface", ":importer", - "//src/google/protobuf:protobuf_nowkt", + "//src/google/protobuf", + "//src/google/protobuf:port", "//src/google/protobuf/compiler/cpp", "//src/google/protobuf/compiler/csharp", "//src/google/protobuf/compiler/java", @@ -186,7 +211,7 @@ cc_binary( ], deps = [ ":command_line_interface", - "//src/google/protobuf:port_def", + "//src/google/protobuf:port", "@com_google_absl//absl/log:initialize", ], ) @@ -226,8 +251,14 @@ cc_library( ":code_generator", ":command_line_interface", "//:protobuf", + "//src/google/protobuf", "//src/google/protobuf/io", + "//src/google/protobuf/io:printer", "//src/google/protobuf/testing", + "@com_google_absl//absl/log:absl_check", + "@com_google_absl//absl/strings", + "@com_google_absl//absl/types:optional", + "@com_google_googletest//:gtest", ], ) @@ -277,12 +308,18 @@ cc_library( visibility = ["//pkg:__pkg__"], deps = [ ":code_generator", + "//src/google/protobuf", "//src/google/protobuf:cc_test_protos", "//src/google/protobuf:descriptor_visitor", + "//src/google/protobuf:port", "//src/google/protobuf/io", + "//src/google/protobuf/io:printer", "//src/google/protobuf/stubs", "//src/google/protobuf/testing", + "@com_google_absl//absl/log:absl_check", + "@com_google_absl//absl/log:absl_log", "@com_google_absl//absl/strings", + "@com_google_googletest//:gtest", ], ) @@ -303,6 +340,7 @@ cc_binary( srcs = ["fake_plugin.cc"], deps = [ ":plugin_cc_proto", + "//src/google/protobuf/io:io_win32", "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/strings", ], @@ -315,10 +353,15 @@ cc_test( deps = [ ":code_generator", ":importer", + "//src/google/protobuf", "//src/google/protobuf:cc_test_protos", + "//src/google/protobuf:port", "//src/google/protobuf:test_textproto", "//src/google/protobuf/io", + "//src/google/protobuf/io:tokenizer", "//src/google/protobuf/testing", + "@com_google_absl//absl/log:absl_log", + "@com_google_absl//absl/status", "@com_google_absl//absl/strings", "@com_google_absl//absl/strings:str_format", "@com_google_googletest//:gtest", @@ -358,13 +401,20 @@ cc_test( ":mock_code_generator", ":test_plugin_paths", "//:protobuf", + "//src/google/protobuf", + "//src/google/protobuf:any_cc_proto", "//src/google/protobuf:cc_test_protos", + "//src/google/protobuf:port", "//src/google/protobuf:test_textproto", "//src/google/protobuf:test_util2", "//src/google/protobuf/compiler/cpp:names", "//src/google/protobuf/io", + "//src/google/protobuf/io:io_win32", "//src/google/protobuf/stubs", "//src/google/protobuf/testing", + "@com_google_absl//absl/log:absl_check", + "@com_google_absl//absl/strings", + "@com_google_absl//absl/strings:str_format", "@com_google_googletest//:gtest", "@com_google_googletest//:gtest_main", ], @@ -384,9 +434,13 @@ cc_library( deps = [ ":code_generator", ":command_line_interface", + "//src/google/protobuf:port", "//src/google/protobuf/io", "//src/google/protobuf/stubs", "//src/google/protobuf/testing", + "@com_google_absl//absl/log:absl_check", + "@com_google_absl//absl/status", + "@com_google_absl//absl/strings", "@com_google_googletest//:gtest", ], ) @@ -398,9 +452,14 @@ cc_test( deps = [ ":importer", "//:protobuf", + "//src/google/protobuf", "//src/google/protobuf/io", "//src/google/protobuf/stubs", "//src/google/protobuf/testing", + "@com_google_absl//absl/container:flat_hash_map", + "@com_google_absl//absl/log:absl_check", + "@com_google_absl//absl/status", + "@com_google_absl//absl/strings", "@com_google_googletest//:gtest", "@com_google_googletest//:gtest_main", ], @@ -419,12 +478,19 @@ cc_test( deps = [ ":importer", "//:protobuf", + "//src/google/protobuf", + "//src/google/protobuf:any_cc_proto", "//src/google/protobuf:cc_test_protos", + "//src/google/protobuf:port", "//src/google/protobuf:test_util2", "//src/google/protobuf/compiler:retention", "//src/google/protobuf/io", "//src/google/protobuf/stubs", "//src/google/protobuf/testing", + "@com_google_absl//absl/container:flat_hash_map", + "@com_google_absl//absl/log:absl_check", + "@com_google_absl//absl/memory", + "@com_google_absl//absl/strings", "@com_google_googletest//:gtest", "@com_google_googletest//:gtest_main", ], @@ -437,8 +503,10 @@ cc_library( strip_include_prefix = "/src", visibility = ["//src/google/protobuf:__subpackages__"], deps = [ - "//src/google/protobuf:protobuf_nowkt", + "//src/google/protobuf", + "//src/google/protobuf:port", "@com_google_absl//absl/container:flat_hash_set", + "@com_google_absl//absl/strings", "@com_google_absl//absl/types:span", ], ) @@ -449,8 +517,12 @@ cc_test( deps = [ ":importer", ":retention", + "//src/google/protobuf", "//src/google/protobuf/io", + "//src/google/protobuf/io:tokenizer", + "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/log:die_if_null", + "@com_google_absl//absl/strings", "@com_google_googletest//:gtest", "@com_google_googletest//:gtest_main", ], diff --git a/src/google/protobuf/compiler/cpp/BUILD.bazel b/src/google/protobuf/compiler/cpp/BUILD.bazel index fb168b03db0d9..820ec7c0fd9fd 100644 --- a/src/google/protobuf/compiler/cpp/BUILD.bazel +++ b/src/google/protobuf/compiler/cpp/BUILD.bazel @@ -15,7 +15,7 @@ cc_library( visibility = ["//visibility:public"], deps = [ ":names_internal", - "//src/google/protobuf:protobuf_nowkt", + "//src/google/protobuf", "//src/google/protobuf/compiler:code_generator", "@com_google_absl//absl/strings", ], @@ -38,9 +38,19 @@ cc_library( "//src/google/protobuf/compiler/rust:__subpackages__", ], deps = [ - "//src/google/protobuf:protobuf_nowkt", + "//src/google/protobuf", + "//src/google/protobuf:port", + "//src/google/protobuf:protobuf_lite", "//src/google/protobuf/compiler:code_generator", + "//src/google/protobuf/io:printer", + "//src/google/protobuf/io:tokenizer", + "@com_google_absl//absl/container:flat_hash_map", + "@com_google_absl//absl/container:flat_hash_set", + "@com_google_absl//absl/log:absl_check", + "@com_google_absl//absl/log:absl_log", "@com_google_absl//absl/strings", + "@com_google_absl//absl/synchronization", + "@com_google_absl//absl/types:optional", ], ) @@ -88,16 +98,28 @@ cc_library( deps = [ ":names", ":names_internal", + "//src/google/protobuf", + "//src/google/protobuf:port", + "//src/google/protobuf:protobuf_lite", "//src/google/protobuf/compiler:code_generator", "//src/google/protobuf/compiler:retention", "//src/google/protobuf/compiler:versions", + "//src/google/protobuf/io", + "//src/google/protobuf/io:printer", "@com_google_absl//absl/base:core_headers", "@com_google_absl//absl/container:btree", "@com_google_absl//absl/container:flat_hash_map", "@com_google_absl//absl/container:flat_hash_set", "@com_google_absl//absl/container:layout", + "@com_google_absl//absl/functional:any_invocable", + "@com_google_absl//absl/log:absl_check", + "@com_google_absl//absl/log:absl_log", + "@com_google_absl//absl/memory", + "@com_google_absl//absl/status", "@com_google_absl//absl/strings", + "@com_google_absl//absl/strings:str_format", "@com_google_absl//absl/synchronization", + "@com_google_absl//absl/types:optional", ], ) @@ -176,12 +198,17 @@ cc_test( ], deps = [ ":cpp", + ":names_internal", "//:protobuf", + "//src/google/protobuf", "//src/google/protobuf:test_util2", "//src/google/protobuf/compiler:importer", "//src/google/protobuf/io", "//src/google/protobuf/stubs", "//src/google/protobuf/testing", + "@com_google_absl//absl/container:flat_hash_map", + "@com_google_absl//absl/log:absl_check", + "@com_google_absl//absl/strings", "@com_google_googletest//:gtest", "@com_google_googletest//:gtest_main", ], @@ -193,8 +220,11 @@ cc_test( deps = [ ":cpp", "//:protobuf", + "//src/google/protobuf", "//src/google/protobuf:cc_test_protos", + "//src/google/protobuf:port", "//src/google/protobuf/testing", + "@com_google_absl//absl/strings", "@com_google_googletest//:gtest", "@com_google_googletest//:gtest_main", ], @@ -206,6 +236,7 @@ cc_test( deps = [ ":cpp", "//:protobuf", + "//src/google/protobuf", "//src/google/protobuf/compiler:command_line_interface_tester", "@com_google_googletest//:gtest", "@com_google_googletest//:gtest_main", @@ -217,7 +248,10 @@ cc_test( srcs = ["message_size_unittest.cc"], deps = [ "//:protobuf", + "//src/google/protobuf", "//src/google/protobuf:cc_test_protos", + "//src/google/protobuf:port", + "@com_google_absl//absl/log:absl_check", "@com_google_googletest//:gtest", "@com_google_googletest//:gtest_main", ], @@ -228,8 +262,13 @@ cc_test( srcs = ["metadata_test.cc"], deps = [ ":cpp", + ":names_internal", "//:protobuf", + "//src/google/protobuf", "//src/google/protobuf/compiler:annotation_test_util", + "//src/google/protobuf/compiler:command_line_interface", + "//src/google/protobuf/testing", + "@com_google_absl//absl/log:absl_check", "@com_google_googletest//:gtest", "@com_google_googletest//:gtest_main", ], @@ -285,7 +324,9 @@ cc_test( "//:protobuf", "//src/google/protobuf/compiler:command_line_interface", "//src/google/protobuf/io", + "//src/google/protobuf/io:printer", "//src/google/protobuf/testing", + "@com_google_absl//absl/log:absl_check", "@com_google_googletest//:gtest", "@com_google_googletest//:gtest_main", ], diff --git a/src/google/protobuf/compiler/csharp/BUILD.bazel b/src/google/protobuf/compiler/csharp/BUILD.bazel index a182bc2a30156..0994bd71d915e 100644 --- a/src/google/protobuf/compiler/csharp/BUILD.bazel +++ b/src/google/protobuf/compiler/csharp/BUILD.bazel @@ -14,7 +14,8 @@ cc_library( strip_include_prefix = "/src", visibility = ["//visibility:public"], deps = [ - "//src/google/protobuf:protobuf_nowkt", + "//src/google/protobuf", + "//src/google/protobuf:port", "@com_google_absl//absl/strings", ], ) @@ -69,10 +70,17 @@ cc_library( ], deps = [ ":names", - "//src/google/protobuf:protobuf_nowkt", + "//src/google/protobuf", + "//src/google/protobuf:port", + "//src/google/protobuf:protobuf_lite", "//src/google/protobuf/compiler:code_generator", "//src/google/protobuf/compiler:retention", + "//src/google/protobuf/io", + "//src/google/protobuf/io:printer", + "//src/google/protobuf/stubs:lite", + "@com_google_absl//absl/container:flat_hash_map", "@com_google_absl//absl/container:flat_hash_set", + "@com_google_absl//absl/log:absl_log", "@com_google_absl//absl/strings", ], ) @@ -91,10 +99,13 @@ cc_test( deps = [ ":csharp", "//:protobuf", + "//src/google/protobuf", "//src/google/protobuf/compiler:importer", "//src/google/protobuf/io", "//src/google/protobuf/stubs", "//src/google/protobuf/testing", + "@com_google_absl//absl/container:flat_hash_map", + "@com_google_absl//absl/strings", "@com_google_googletest//:gtest", "@com_google_googletest//:gtest_main", ], @@ -106,8 +117,11 @@ cc_test( deps = [ ":csharp", "//:protobuf", + "//src/google/protobuf", + "//src/google/protobuf:any_cc_proto", "//src/google/protobuf/compiler:command_line_interface", "//src/google/protobuf/io", + "//src/google/protobuf/io:printer", "@com_google_googletest//:gtest", "@com_google_googletest//:gtest_main", ], diff --git a/src/google/protobuf/compiler/java/BUILD.bazel b/src/google/protobuf/compiler/java/BUILD.bazel index bac458730422b..c25b0c4d64e1d 100644 --- a/src/google/protobuf/compiler/java/BUILD.bazel +++ b/src/google/protobuf/compiler/java/BUILD.bazel @@ -14,7 +14,7 @@ cc_library( visibility = ["//visibility:public"], deps = [ ":names_internal", - "//src/google/protobuf:protobuf_nowkt", + "//src/google/protobuf", ], ) @@ -37,10 +37,18 @@ cc_library( visibility = ["//pkg:__pkg__"], deps = [ ":java_features_bootstrap", - "//src/google/protobuf:protobuf_nowkt", + "//src/google/protobuf", + "//src/google/protobuf:port", "//src/google/protobuf/compiler:code_generator", "//src/google/protobuf/compiler:versions", + "//src/google/protobuf/io:printer", + "//src/google/protobuf/io:tokenizer", + "@com_google_absl//absl/container:flat_hash_map", "@com_google_absl//absl/container:flat_hash_set", + "@com_google_absl//absl/log:absl_check", + "@com_google_absl//absl/log:absl_log", + "@com_google_absl//absl/strings", + "@com_google_absl//absl/strings:str_format", ], ) @@ -50,8 +58,11 @@ cc_library( hdrs = ["java_features.pb.h"], strip_include_prefix = "/src", deps = [ + "//src/google/protobuf", "//src/google/protobuf:arena", - "//src/google/protobuf:protobuf_nowkt", + "//src/google/protobuf:port", + "//src/google/protobuf:protobuf_lite", + "//src/google/protobuf/io", ], ) @@ -128,14 +139,22 @@ cc_library( ":java_features_bootstrap", ":names", ":names_internal", + "//src/google/protobuf", "//src/google/protobuf:arena", - "//src/google/protobuf:protobuf_nowkt", + "//src/google/protobuf:port", + "//src/google/protobuf:protobuf_lite", "//src/google/protobuf/compiler:code_generator", "//src/google/protobuf/compiler:retention", "//src/google/protobuf/compiler:versions", + "//src/google/protobuf/io", + "//src/google/protobuf/io:printer", "@com_google_absl//absl/container:btree", + "@com_google_absl//absl/container:flat_hash_map", "@com_google_absl//absl/container:flat_hash_set", + "@com_google_absl//absl/log:absl_check", + "@com_google_absl//absl/log:absl_log", "@com_google_absl//absl/strings", + "@com_google_absl//absl/strings:str_format", ], ) @@ -162,8 +181,10 @@ cc_test( "//:protobuf", "//src/google/protobuf/compiler:command_line_interface", "//src/google/protobuf/io", + "//src/google/protobuf/io:printer", "//src/google/protobuf/stubs:lite", "//src/google/protobuf/testing", + "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/strings", "@com_google_googletest//:gtest", "@com_google_googletest//:gtest_main", diff --git a/src/google/protobuf/compiler/objectivec/BUILD.bazel b/src/google/protobuf/compiler/objectivec/BUILD.bazel index b60a59d3a6b3e..ea99c739e23d9 100644 --- a/src/google/protobuf/compiler/objectivec/BUILD.bazel +++ b/src/google/protobuf/compiler/objectivec/BUILD.bazel @@ -31,10 +31,13 @@ cc_library( visibility = ["//pkg:__pkg__"], deps = [ ":line_consumer", - "//src/google/protobuf:protobuf_nowkt", + "//src/google/protobuf", + "//src/google/protobuf:port", "//src/google/protobuf/compiler:code_generator", + "@com_google_absl//absl/container:flat_hash_map", "@com_google_absl//absl/container:flat_hash_set", "@com_google_absl//absl/log:absl_log", + "@com_google_absl//absl/strings", ], ) @@ -46,8 +49,11 @@ cc_library( strip_include_prefix = "/src", visibility = ["//pkg:__pkg__"], deps = [ - "//src/google/protobuf:protobuf_nowkt", + "//src/google/protobuf", + "//src/google/protobuf:port", "//src/google/protobuf/compiler:code_generator", + "//src/google/protobuf/io", + "@com_google_absl//absl/strings", ], ) @@ -95,9 +101,19 @@ cc_library( deps = [ ":line_consumer", ":names", - "//src/google/protobuf:protobuf_nowkt", + "//src/google/protobuf", + "//src/google/protobuf:port", "//src/google/protobuf/compiler:code_generator", + "//src/google/protobuf/io", + "//src/google/protobuf/io:printer", + "//src/google/protobuf/io:tokenizer", + "//src/google/protobuf/stubs", "@com_google_absl//absl/container:btree", + "@com_google_absl//absl/container:flat_hash_map", + "@com_google_absl//absl/container:flat_hash_set", + "@com_google_absl//absl/log:absl_check", + "@com_google_absl//absl/log:absl_log", + "@com_google_absl//absl/memory", "@com_google_absl//absl/strings", ], ) @@ -108,6 +124,8 @@ cc_test( deps = [ ":line_consumer", "//src/google/protobuf/io", + "//src/google/protobuf/stubs", + "@com_google_absl//absl/strings", "@com_google_googletest//:gtest", "@com_google_googletest//:gtest_main", ], @@ -129,6 +147,7 @@ cc_test( srcs = ["text_format_decode_data_unittest.cc"], deps = [ ":objectivec", + "//src/google/protobuf:port", "@com_google_googletest//:gtest", "@com_google_googletest//:gtest_main", ], diff --git a/src/google/protobuf/compiler/php/BUILD.bazel b/src/google/protobuf/compiler/php/BUILD.bazel index 5bddf38779b88..367da110dcdeb 100644 --- a/src/google/protobuf/compiler/php/BUILD.bazel +++ b/src/google/protobuf/compiler/php/BUILD.bazel @@ -14,7 +14,8 @@ cc_library( strip_include_prefix = "/src", visibility = ["//visibility:public"], deps = [ - "//src/google/protobuf:protobuf_nowkt", + "//src/google/protobuf", + "//src/google/protobuf:port", "//src/google/protobuf/compiler:code_generator", "@com_google_absl//absl/strings", ], @@ -32,9 +33,15 @@ cc_library( ], deps = [ ":names", - "//src/google/protobuf:protobuf_nowkt", + "//src/google/protobuf", + "//src/google/protobuf:port", "//src/google/protobuf/compiler:code_generator", "//src/google/protobuf/compiler:retention", + "//src/google/protobuf/io", + "//src/google/protobuf/io:printer", + "@com_google_absl//absl/container:flat_hash_map", + "@com_google_absl//absl/container:flat_hash_set", + "@com_google_absl//absl/log:absl_log", "@com_google_absl//absl/strings", ], ) diff --git a/src/google/protobuf/compiler/python/BUILD.bazel b/src/google/protobuf/compiler/python/BUILD.bazel index 5fe960417af43..6db988f37f10d 100644 --- a/src/google/protobuf/compiler/python/BUILD.bazel +++ b/src/google/protobuf/compiler/python/BUILD.bazel @@ -26,11 +26,21 @@ cc_library( "@com_github_grpc_grpc//tools/distrib/python/grpcio_tools:__subpackages__", ], deps = [ - "//src/google/protobuf:protobuf_nowkt", + "//src/google/protobuf", + "//src/google/protobuf:port", "//src/google/protobuf/compiler:code_generator", "//src/google/protobuf/compiler:retention", "//src/google/protobuf/compiler:versions", + "//src/google/protobuf/io", + "//src/google/protobuf/io:printer", + "//src/google/protobuf/io:tokenizer", + "@com_google_absl//absl/container:flat_hash_map", + "@com_google_absl//absl/container:flat_hash_set", + "@com_google_absl//absl/log:absl_check", + "@com_google_absl//absl/log:absl_log", + "@com_google_absl//absl/memory", "@com_google_absl//absl/strings", + "@com_google_absl//absl/strings:str_format", "@com_google_absl//absl/synchronization", ], ) @@ -43,7 +53,9 @@ cc_test( ":python", "//src/google/protobuf/compiler:command_line_interface", "//src/google/protobuf/io", + "//src/google/protobuf/io:printer", "//src/google/protobuf/testing", + "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/strings", "@com_google_googletest//:gtest", "@com_google_googletest//:gtest_main", diff --git a/src/google/protobuf/compiler/ruby/BUILD.bazel b/src/google/protobuf/compiler/ruby/BUILD.bazel index 9e921542fcfa4..4792171a7a440 100644 --- a/src/google/protobuf/compiler/ruby/BUILD.bazel +++ b/src/google/protobuf/compiler/ruby/BUILD.bazel @@ -17,9 +17,15 @@ cc_library( "//src/google/protobuf/compiler:__pkg__", ], deps = [ - "//src/google/protobuf:protobuf_nowkt", + "//src/google/protobuf", + "//src/google/protobuf:port", "//src/google/protobuf/compiler:code_generator", "//src/google/protobuf/compiler:retention", + "//src/google/protobuf/io", + "//src/google/protobuf/io:printer", + "@com_google_absl//absl/container:flat_hash_set", + "@com_google_absl//absl/log:absl_log", + "@com_google_absl//absl/strings", ], ) @@ -44,6 +50,7 @@ cc_test( ":ruby", "//src/google/protobuf/compiler:command_line_interface", "//src/google/protobuf/io", + "//src/google/protobuf/io:printer", "//src/google/protobuf/testing", "@com_google_googletest//:gtest", "@com_google_googletest//:gtest_main", diff --git a/src/google/protobuf/compiler/rust/BUILD.bazel b/src/google/protobuf/compiler/rust/BUILD.bazel index 3dd9b247aaa0b..6682c2ec20d36 100644 --- a/src/google/protobuf/compiler/rust/BUILD.bazel +++ b/src/google/protobuf/compiler/rust/BUILD.bazel @@ -21,12 +21,21 @@ cc_library( ":message", ":naming", ":relative_path", - "//src/google/protobuf:protobuf_nowkt", + "//src/google/protobuf", + "//src/google/protobuf:port", "//src/google/protobuf/compiler:code_generator", "//src/google/protobuf/compiler/cpp:names", + "//src/google/protobuf/io", + "//src/google/protobuf/io:printer", "@com_google_absl//absl/algorithm:container", + "@com_google_absl//absl/container:btree", + "@com_google_absl//absl/container:flat_hash_set", "@com_google_absl//absl/log:absl_check", + "@com_google_absl//absl/memory", + "@com_google_absl//absl/status:statusor", + "@com_google_absl//absl/strings", "@com_google_absl//absl/types:optional", + "@com_google_absl//absl/types:span", ], ) @@ -42,11 +51,14 @@ cc_library( ":enum", ":naming", ":oneof", - "//src/google/protobuf:protobuf_nowkt", + "//src/google/protobuf", "//src/google/protobuf/compiler/cpp:names", + "//src/google/protobuf/compiler/cpp:names_internal", "//upb_generator:mangle", "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/log:absl_log", + "@com_google_absl//absl/strings", + "@com_google_absl//absl/strings:str_format", ], ) @@ -71,10 +83,13 @@ cc_library( ":context", ":helpers", ":naming", - "//src/google/protobuf:protobuf_nowkt", + "//src/google/protobuf", "//src/google/protobuf/compiler/cpp:names_internal", + "//src/google/protobuf/io:tokenizer", "@com_google_absl//absl/log:absl_check", + "@com_google_absl//absl/log:absl_log", "@com_google_absl//absl/strings", + "@com_google_absl//absl/strings:str_format", ], ) @@ -85,6 +100,7 @@ cc_library( copts = COPTS, strip_include_prefix = "/src", deps = [ + "//src/google/protobuf", "//src/google/protobuf/compiler:code_generator", "//src/google/protobuf/io:printer", "@com_google_absl//absl/algorithm:container", @@ -104,12 +120,13 @@ cc_library( strip_include_prefix = "/src", deps = [ ":context", - "//src/google/protobuf:protobuf_nowkt", + "//src/google/protobuf", "//src/google/protobuf/compiler/cpp:names_internal", "@com_google_absl//absl/container:flat_hash_map", "@com_google_absl//absl/container:flat_hash_set", "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/strings", + "@com_google_absl//absl/types:span", ], ) @@ -132,7 +149,8 @@ cc_library( strip_include_prefix = "/src", deps = [ ":context", - "//src/google/protobuf:protobuf_nowkt", + "//src/google/protobuf", + "//src/google/protobuf/compiler:code_generator", "@com_google_absl//absl/log:absl_log", "@com_google_absl//absl/strings", ], @@ -147,8 +165,10 @@ cc_library( deps = [ ":context", ":naming", - "//src/google/protobuf:protobuf_nowkt", + "//src/google/protobuf", "//src/google/protobuf/compiler/cpp:names", + "//src/google/protobuf/compiler/cpp:names_internal", + "@com_google_absl//absl/log:absl_log", "@com_google_absl//absl/strings", ], ) @@ -182,8 +202,11 @@ cc_library( strip_include_prefix = "/src", deps = [ ":context", - "//src/google/protobuf:protobuf_nowkt", + "//src/google/protobuf", + "//src/google/protobuf/io:tokenizer", "@com_google_absl//absl/log:absl_check", + "@com_google_absl//absl/log:absl_log", "@com_google_absl//absl/strings", + "@com_google_absl//absl/strings:str_format", ], ) diff --git a/src/google/protobuf/editions/BUILD b/src/google/protobuf/editions/BUILD index 76d1a0ed61dfd..b118767afc9f5 100644 --- a/src/google/protobuf/editions/BUILD +++ b/src/google/protobuf/editions/BUILD @@ -75,6 +75,7 @@ cc_test( deps = [ ":defaults_test_embedded", "//src/google/protobuf", + "//src/google/protobuf:port", "//src/google/protobuf:unittest_features_cc_proto", "//src/google/protobuf/stubs", "//src/google/protobuf/testing", diff --git a/src/google/protobuf/io/BUILD.bazel b/src/google/protobuf/io/BUILD.bazel index a5c44e2aad801..c3c7b893dd953 100644 --- a/src/google/protobuf/io/BUILD.bazel +++ b/src/google/protobuf/io/BUILD.bazel @@ -27,10 +27,17 @@ cc_library( deps = [ ":io_win32", "//src/google/protobuf:arena", + "//src/google/protobuf:port", "//src/google/protobuf/stubs:lite", + "@com_google_absl//absl/base", + "@com_google_absl//absl/base:core_headers", "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/log:absl_log", + "@com_google_absl//absl/numeric:bits", + "@com_google_absl//absl/strings", + "@com_google_absl//absl/strings:cord", "@com_google_absl//absl/strings:internal", + "@com_google_absl//absl/types:span", ], ) @@ -69,6 +76,7 @@ cc_library( strip_include_prefix = "/src", deps = [ ":io", + "//src/google/protobuf:port", "//src/google/protobuf/stubs", ], ) @@ -80,6 +88,8 @@ cc_test( deps = [ ":zero_copy_sink", "//src/google/protobuf/stubs", + "@com_google_absl//absl/log:absl_check", + "@com_google_absl//absl/strings", "@com_google_googletest//:gtest", "@com_google_googletest//:gtest_main", ], @@ -93,6 +103,7 @@ cc_library( strip_include_prefix = "/src", deps = [ ":zero_copy_sink", + "//src/google/protobuf:port", "//src/google/protobuf/stubs", "@com_google_absl//absl/base:core_headers", "@com_google_absl//absl/cleanup", @@ -100,6 +111,7 @@ cc_library( "@com_google_absl//absl/functional:function_ref", "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/log:absl_log", + "@com_google_absl//absl/meta:type_traits", "@com_google_absl//absl/strings", "@com_google_absl//absl/strings:str_format", "@com_google_absl//absl/types:optional", @@ -122,7 +134,9 @@ cc_library( strip_include_prefix = "/src", deps = [ ":io", + "//src/google/protobuf:port", "//src/google/protobuf/stubs", + "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/log:absl_log", "@com_google_absl//absl/strings", "@com_google_absl//absl/strings:str_format", @@ -137,6 +151,7 @@ cc_library( strip_include_prefix = "/src", deps = [ ":io", + "//src/google/protobuf:port", "//src/google/protobuf/stubs", "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/log:absl_log", @@ -154,7 +169,9 @@ cc_library( strip_include_prefix = "/src", visibility = [ "//pkg:__pkg__", + "//src/google/protobuf:__pkg__", "//src/google/protobuf/compiler:__pkg__", + "//src/google/protobuf/testing:__pkg__", ], deps = [ "//src/google/protobuf:arena", @@ -178,13 +195,26 @@ cc_test( deps = [ ":gzip_stream", ":io", + ":io_win32", + ":printer", + ":tokenizer", "//:protobuf", + "//src/google/protobuf", + "//src/google/protobuf:port", "//src/google/protobuf:test_util2", + "//src/google/protobuf/stubs", "//src/google/protobuf/testing", + "@com_google_absl//absl/base", + "@com_google_absl//absl/base:log_severity", "@com_google_absl//absl/container:flat_hash_map", + "@com_google_absl//absl/log:absl_check", + "@com_google_absl//absl/log:absl_log", "@com_google_absl//absl/log:scoped_mock_log", + "@com_google_absl//absl/status", "@com_google_absl//absl/strings", + "@com_google_absl//absl/strings:cord", "@com_google_absl//absl/strings:str_format", + "@com_google_absl//absl/types:optional", "@com_google_googletest//:gtest", "@com_google_googletest//:gtest_main", ], diff --git a/src/google/protobuf/io/gzip_stream.h b/src/google/protobuf/io/gzip_stream.h index 11efc4a589e34..1644949fa3d8e 100644 --- a/src/google/protobuf/io/gzip_stream.h +++ b/src/google/protobuf/io/gzip_stream.h @@ -23,7 +23,7 @@ #include "google/protobuf/stubs/common.h" #include "google/protobuf/io/zero_copy_stream.h" #include "google/protobuf/port.h" -#include "zlib.h" +#include // Must be included last. #include "google/protobuf/port_def.inc" diff --git a/src/google/protobuf/json/BUILD.bazel b/src/google/protobuf/json/BUILD.bazel index ccc369b2b9c82..8f1fc61bc9304 100644 --- a/src/google/protobuf/json/BUILD.bazel +++ b/src/google/protobuf/json/BUILD.bazel @@ -1,10 +1,12 @@ load("@rules_cc//cc:defs.bzl", "cc_library", "cc_test") load("//build_defs:cpp_opts.bzl", "COPTS") -package(default_visibility = [ - "//pkg:__pkg__", - "//src/google/protobuf/json:__pkg__", -]) +package( + default_visibility = [ + "//pkg:__pkg__", + "//src/google/protobuf/json:__pkg__", + ], +) licenses(["notice"]) @@ -19,9 +21,10 @@ cc_library( ":parser", ":unparser", "//src/google/protobuf", - "//src/google/protobuf:port_def", + "//src/google/protobuf:port", "//src/google/protobuf/io", "//src/google/protobuf/io:zero_copy_sink", + "//src/google/protobuf/stubs", "//src/google/protobuf/util:type_resolver_util", "@com_google_absl//absl/base", "@com_google_absl//absl/flags:flag", @@ -39,9 +42,15 @@ cc_test( ":json", "//src/google/protobuf", "//src/google/protobuf:cc_test_protos", - "//src/google/protobuf:port_def", + "//src/google/protobuf:duration_cc_proto", + "//src/google/protobuf:field_mask_cc_proto", + "//src/google/protobuf:port", + "//src/google/protobuf:struct_cc_proto", + "//src/google/protobuf:timestamp_cc_proto", + "//src/google/protobuf:wrappers_cc_proto", "//src/google/protobuf/io", "//src/google/protobuf/io:test_zero_copy_stream", + "//src/google/protobuf/stubs", "//src/google/protobuf/util:json_format_cc_proto", "//src/google/protobuf/util:json_format_proto3_cc_proto", "//src/google/protobuf/util:type_resolver_util", @@ -61,9 +70,12 @@ cc_library( copts = COPTS, strip_include_prefix = "/src", deps = [ - "//src/google/protobuf:port_def", + "//src/google/protobuf:port", "//src/google/protobuf/io", + "//src/google/protobuf/stubs", "@com_google_absl//absl/algorithm:container", + "@com_google_absl//absl/log:absl_check", + "@com_google_absl//absl/log:absl_log", "@com_google_absl//absl/status", "@com_google_absl//absl/status:statusor", "@com_google_absl//absl/strings", @@ -78,6 +90,7 @@ cc_test( deps = [ ":zero_copy_buffered_stream", "//src/google/protobuf/io:test_zero_copy_stream", + "//src/google/protobuf/stubs", "@com_google_absl//absl/strings", "@com_google_googletest//:gtest", "@com_google_googletest//:gtest_main", @@ -92,12 +105,16 @@ cc_library( strip_include_prefix = "/src", deps = [ "//src/google/protobuf", - "//src/google/protobuf:port_def", + "//src/google/protobuf:port", "//src/google/protobuf:protobuf_lite", + "//src/google/protobuf:type_cc_proto", "//src/google/protobuf/io", + "//src/google/protobuf/stubs", "//src/google/protobuf/util:type_resolver_util", "//third_party/utf8_range:utf8_validity", "@com_google_absl//absl/container:flat_hash_map", + "@com_google_absl//absl/log:absl_check", + "@com_google_absl//absl/log:absl_log", "@com_google_absl//absl/status", "@com_google_absl//absl/strings", "@com_google_absl//absl/strings:str_format", @@ -116,9 +133,12 @@ cc_library( deps = [ ":message_path", ":zero_copy_buffered_stream", - "//src/google/protobuf:port_def", + "//src/google/protobuf", + "//src/google/protobuf:port", "//src/google/protobuf/io", + "//src/google/protobuf/stubs", "@com_google_absl//absl/algorithm:container", + "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/numeric:bits", "@com_google_absl//absl/status", "@com_google_absl//absl/status:statusor", @@ -134,8 +154,10 @@ cc_test( copts = COPTS, deps = [ ":lexer", + "//src/google/protobuf:port", "//src/google/protobuf/io", "//src/google/protobuf/io:test_zero_copy_stream", + "//src/google/protobuf/stubs", "@com_google_absl//absl/algorithm:container", "@com_google_absl//absl/status", "@com_google_absl//absl/status:statusor", @@ -154,11 +176,13 @@ cc_library( copts = COPTS, strip_include_prefix = "/src", deps = [ - "//src/google/protobuf:port_def", + "//src/google/protobuf:port", "//src/google/protobuf/io", "//src/google/protobuf/io:tokenizer", "//src/google/protobuf/io:zero_copy_sink", + "//src/google/protobuf/stubs:lite", "@com_google_absl//absl/algorithm:container", + "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/strings", "@com_google_absl//absl/strings:str_format", ], @@ -173,7 +197,7 @@ cc_library( ":lexer", ":untyped_message", "//src/google/protobuf", - "//src/google/protobuf:port_def", + "//src/google/protobuf:port", "//src/google/protobuf/util:type_resolver_util", "@com_google_absl//absl/algorithm:container", "@com_google_absl//absl/status", @@ -199,9 +223,12 @@ cc_library( ":descriptor_traits", ":lexer", "//src/google/protobuf", - "//src/google/protobuf:port_def", + "//src/google/protobuf:port", + "//src/google/protobuf:protobuf_lite", + "//src/google/protobuf:type_cc_proto", "//src/google/protobuf/io", "//src/google/protobuf/io:zero_copy_sink", + "//src/google/protobuf/stubs", "//src/google/protobuf/util:type_resolver_util", "@com_google_absl//absl/base", "@com_google_absl//absl/base:core_headers", @@ -234,8 +261,10 @@ cc_library( ":untyped_message", ":writer", "//src/google/protobuf", - "//src/google/protobuf:port_def", + "//src/google/protobuf:port", + "//src/google/protobuf:type_cc_proto", "//src/google/protobuf/io", + "//src/google/protobuf/stubs", "//src/google/protobuf/util:type_resolver_util", "@com_google_absl//absl/container:flat_hash_map", "@com_google_absl//absl/log:absl_check", @@ -256,6 +285,7 @@ cc_library( strip_include_prefix = "/src", deps = [ "//src/google/protobuf", + "//src/google/protobuf:port", "@com_google_absl//absl/cleanup", "@com_google_absl//absl/strings", ], diff --git a/src/google/protobuf/stubs/BUILD.bazel b/src/google/protobuf/stubs/BUILD.bazel index f89f34a0049f4..ba0aeefdacf76 100644 --- a/src/google/protobuf/stubs/BUILD.bazel +++ b/src/google/protobuf/stubs/BUILD.bazel @@ -25,7 +25,7 @@ cc_library( linkopts = LINK_OPTS, strip_include_prefix = "/src", deps = [ - "//src/google/protobuf:port_def", + "//src/google/protobuf:port", "@com_google_absl//absl/log:absl_log", "@com_google_absl//absl/status", "@com_google_absl//absl/status:statusor", @@ -50,7 +50,7 @@ cc_library( ], deps = [ ":lite", - "//src/google/protobuf:port_def", + "//src/google/protobuf:port", "@com_google_absl//absl/status", "@com_google_absl//absl/status:statusor", "@com_google_absl//absl/strings", @@ -74,6 +74,7 @@ cc_test( ":stubs", "//src/google/protobuf/testing", "@com_google_absl//absl/log:absl_log", + "@com_google_absl//absl/strings", "@com_google_googletest//:gtest", "@com_google_googletest//:gtest_main", ], diff --git a/src/google/protobuf/testing/BUILD.bazel b/src/google/protobuf/testing/BUILD.bazel index ab3e979d91ea1..b5e9ddb78fdb9 100644 --- a/src/google/protobuf/testing/BUILD.bazel +++ b/src/google/protobuf/testing/BUILD.bazel @@ -5,7 +5,9 @@ load("@rules_cc//cc:defs.bzl", "cc_library") load("@rules_pkg//:mappings.bzl", "pkg_files", "strip_prefix") load("//build_defs:cpp_opts.bzl", "COPTS", "LINK_OPTS") -package(default_visibility = ["//:__subpackages__"]) +package( + default_visibility = ["//:__subpackages__"], +) cc_library( name = "testing", @@ -23,7 +25,9 @@ cc_library( strip_include_prefix = "/src", deps = [ "//:protobuf_lite", # for ShutdownProtobufLibrary + "//src/google/protobuf:port", "//src/google/protobuf/io", + "//src/google/protobuf/io:io_win32", "//src/google/protobuf/stubs:lite", "@com_google_absl//absl/base:log_severity", "@com_google_absl//absl/container:flat_hash_map", diff --git a/src/google/protobuf/util/BUILD.bazel b/src/google/protobuf/util/BUILD.bazel index 149b86c3517f3..262128d5a3266 100644 --- a/src/google/protobuf/util/BUILD.bazel +++ b/src/google/protobuf/util/BUILD.bazel @@ -16,6 +16,7 @@ cc_library( visibility = ["//:__subpackages__"], deps = [ "//:protobuf_lite", + "//src/google/protobuf:port", "//src/google/protobuf/io", ], ) @@ -48,12 +49,17 @@ cc_library( visibility = ["//:__subpackages__"], deps = [ "//src/google/protobuf", + "//src/google/protobuf:port", "//src/google/protobuf/io", + "//src/google/protobuf/io:printer", "//src/google/protobuf/stubs", + "@com_google_absl//absl/container:fixed_array", "@com_google_absl//absl/container:flat_hash_map", "@com_google_absl//absl/container:flat_hash_set", "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/log:absl_log", + "@com_google_absl//absl/strings", + "@com_google_absl//absl/strings:str_format", ], ) @@ -63,6 +69,7 @@ cc_test( deps = [ ":differencer", ":message_differencer_unittest_cc_proto", + "//src/google/protobuf", "//src/google/protobuf:cc_test_protos", "//src/google/protobuf/testing", "@com_google_googletest//:gtest", @@ -83,10 +90,16 @@ cc_test( ":differencer", ":message_differencer_unittest_cc_proto", ":message_differencer_unittest_proto3_cc_proto", + "//src/google/protobuf", "//src/google/protobuf:cc_test_protos", + "//src/google/protobuf:protobuf_lite", "//src/google/protobuf:test_util", + "//src/google/protobuf/stubs", "//src/google/protobuf/testing", "@com_google_absl//absl/functional:bind_front", + "@com_google_absl//absl/log:absl_check", + "@com_google_absl//absl/memory", + "@com_google_absl//absl/strings", "@com_google_googletest//:gtest", "@com_google_googletest//:gtest_main", ], @@ -101,10 +114,15 @@ cc_library( visibility = ["//:__subpackages__"], deps = [ "//src/google/protobuf", + "//src/google/protobuf:field_mask_cc_proto", + "//src/google/protobuf:port", "//src/google/protobuf/stubs", "@com_google_absl//absl/container:btree", + "@com_google_absl//absl/log:absl_check", + "@com_google_absl//absl/log:absl_log", "@com_google_absl//absl/log:die_if_null", "@com_google_absl//absl/memory", + "@com_google_absl//absl/strings", ], ) @@ -116,6 +134,7 @@ cc_test( ":field_mask_util", "//src/google/protobuf", "//src/google/protobuf:cc_test_protos", + "//src/google/protobuf:field_mask_cc_proto", "//src/google/protobuf:test_util", "//src/google/protobuf/stubs", "//src/google/protobuf/testing", @@ -138,11 +157,21 @@ cc_library( srcs = ["time_util.cc"], hdrs = ["time_util.h"], strip_include_prefix = "/src", - visibility = ["//:__subpackages__"], + visibility = [ + "//:__subpackages__", + "@com_google_protobuf_examples//:__subpackages__", + ], deps = [ "//src/google/protobuf", + "//src/google/protobuf:duration_cc_proto", + "//src/google/protobuf:port", + "//src/google/protobuf:timestamp_cc_proto", "//src/google/protobuf/stubs", "@com_google_absl//absl/log:absl_check", + "@com_google_absl//absl/numeric:int128", + "@com_google_absl//absl/strings", + "@com_google_absl//absl/strings:str_format", + "@com_google_absl//absl/time", ], ) @@ -152,6 +181,8 @@ cc_test( deps = [ ":time_util", "//src/google/protobuf", + "//src/google/protobuf:duration_cc_proto", + "//src/google/protobuf:timestamp_cc_proto", "//src/google/protobuf/testing", "@com_google_googletest//:gtest", "@com_google_googletest//:gtest_main", @@ -170,10 +201,16 @@ cc_library( visibility = ["//:__subpackages__"], deps = [ "//src/google/protobuf", + "//src/google/protobuf:port", + "//src/google/protobuf:source_context_cc_proto", + "//src/google/protobuf:type_cc_proto", + "//src/google/protobuf:wrappers_cc_proto", "//src/google/protobuf/io", + "//src/google/protobuf/io:tokenizer", "//src/google/protobuf/stubs", "@com_google_absl//absl/log:absl_log", "@com_google_absl//absl/status", + "@com_google_absl//absl/strings", ], ) @@ -185,8 +222,13 @@ cc_test( ":json_format_cc_proto", ":json_format_proto3_cc_proto", ":json_util", + ":type_resolver_util", "//src/google/protobuf", + "//src/google/protobuf:any_cc_proto", + "//src/google/protobuf:cc_test_protos", "//src/google/protobuf:test_util", + "//src/google/protobuf:type_cc_proto", + "//src/google/protobuf:wrappers_cc_proto", "//src/google/protobuf/testing", "@com_google_googletest//:gtest", "@com_google_googletest//:gtest_main", diff --git a/upb/util/BUILD b/upb/util/BUILD index 5d0ce9fc97c6d..b847260c73f8b 100644 --- a/upb/util/BUILD +++ b/upb/util/BUILD @@ -50,6 +50,7 @@ cc_library( deps = [ ":def_to_proto", "//:protobuf", + "//src/google/protobuf/util:differencer", "//upb:base", "//upb:descriptor_upb_proto", "//upb:mem", @@ -67,6 +68,7 @@ cc_test( ":def_to_proto_test_upb_proto", ":def_to_proto_test_upb_proto_reflection", "//:protobuf", + "//src/google/protobuf/util:differencer", "//upb:descriptor_upb_proto_reflection", "//upb:mem", "//upb:reflection", From 06b8991ab1c11b099c0fc9055b487c4b81d4e703 Mon Sep 17 00:00:00 2001 From: Eric Salo Date: Thu, 4 Jan 2024 07:15:08 -0800 Subject: [PATCH 164/255] upb: move libupb.so from third_party/upb/ to third_party/dart/pb_runtime/ PiperOrigin-RevId: 595696425 --- upb/BUILD | 22 ---------------------- upb/upb_so.c | 19 ------------------- 2 files changed, 41 deletions(-) delete mode 100644 upb/upb_so.c diff --git a/upb/BUILD b/upb/BUILD index 31fdd4308fe99..1b0ae3f28a26a 100644 --- a/upb/BUILD +++ b/upb/BUILD @@ -270,27 +270,6 @@ alias( visibility = ["//visibility:public"], ) -# Internal C/C++ libraries ##################################################### - -cc_binary( - name = "libupb.so", - srcs = ["upb_so.c"], - copts = UPB_DEFAULT_COPTS + ["-DUPB_BUILD_API"], - linkshared = 1, - linkstatic = 1, - visibility = ["//visibility:public"], - deps = [ - ":mem", - ":message", - ":message_compare", - ":message_split64", - ":mini_descriptor", - ":mini_table", - ":port", - ":wire", - ], -) - # Amalgamation ################################################################# # begin:github_only @@ -443,7 +422,6 @@ filegroup( name = "source_files", srcs = glob( [ - "**/*.c", "**/*.h", "**/*.hpp", ], diff --git a/upb/upb_so.c b/upb/upb_so.c deleted file mode 100644 index a8769ab79d7d4..0000000000000 --- a/upb/upb_so.c +++ /dev/null @@ -1,19 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2023 Google LLC. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file or at -// https://developers.google.com/open-source/licenses/bsd - -// These headers form a spanning tree for the upb defs needed by FFI layers. - -// IWYU pragma: begin_exports -#include "upb/message/accessors_split64.h" -#include "upb/message/array_split64.h" -#include "upb/message/compare.h" -#include "upb/message/map.h" -#include "upb/message/message.h" -#include "upb/mini_descriptor/decode.h" -#include "upb/wire/decode.h" -#include "upb/wire/encode.h" -// IWYU pragma: end_exports From b7a8a02ad93bf19a57ec1e0a7947829fdb686129 Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Thu, 4 Jan 2024 07:58:29 -0800 Subject: [PATCH 165/255] Avoid dereferencing in `operator->`. std::to_address uses this function to "Obtain the address without forming a reference", so it might get surprised if it forms a reference in the process. PiperOrigin-RevId: 595705426 --- src/google/protobuf/repeated_field_unittest.cc | 16 ++++++++++++++++ src/google/protobuf/repeated_ptr_field.h | 2 +- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/google/protobuf/repeated_field_unittest.cc b/src/google/protobuf/repeated_field_unittest.cc index 7dac43d7fcec3..46919306edb0f 100644 --- a/src/google/protobuf/repeated_field_unittest.cc +++ b/src/google/protobuf/repeated_field_unittest.cc @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -55,6 +56,7 @@ namespace { using ::protobuf_unittest::TestAllTypes; using ::protobuf_unittest::TestMessageWithManyRepeatedPtrFields; +using ::testing::A; using ::testing::AllOf; using ::testing::ElementsAre; using ::testing::Ge; @@ -111,6 +113,20 @@ TEST(RepeatedPtrOverPtrsIterator, Traits) { #endif } +#if __cplusplus >= 202002L +TEST(RepeatedPtrOverPtrsIterator, ToAddress) { + // empty container + RepeatedPtrField field; + EXPECT_THAT(std::to_address(field.pointer_begin()), A()); + EXPECT_EQ(std::to_address(field.pointer_begin()), + std::to_address(field.pointer_end())); + + // "null" iterator + using It = RepeatedPtrField::pointer_iterator; + EXPECT_THAT(std::to_address(It()), A()); +} +#endif + TEST(ConstRepeatedPtrOverPtrsIterator, Traits) { using It = RepeatedPtrField::const_pointer_iterator; EXPECT_TRUE((std::is_same::value)); diff --git a/src/google/protobuf/repeated_ptr_field.h b/src/google/protobuf/repeated_ptr_field.h index 2fb46157ad384..c67a966cec509 100644 --- a/src/google/protobuf/repeated_ptr_field.h +++ b/src/google/protobuf/repeated_ptr_field.h @@ -1727,7 +1727,7 @@ class RepeatedPtrOverPtrsIterator { // dereferenceable reference operator*() const { return *reinterpret_cast(it_); } - pointer operator->() const { return &(operator*()); } + pointer operator->() const { return reinterpret_cast(it_); } // {inc,dec}rementable iterator& operator++() { From 4407d1ed7eb41f31b9315455897921ebea56d811 Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Thu, 4 Jan 2024 09:53:26 -0800 Subject: [PATCH 166/255] IWYU and format fix. PiperOrigin-RevId: 595732256 --- src/google/protobuf/BUILD.bazel | 6 +++ src/google/protobuf/compiler/cpp/BUILD.bazel | 1 + .../compiler/cpp/message_size_unittest.cc | 46 ++++++++++--------- .../generated_message_reflection_unittest.cc | 6 ++- .../generated_message_tctable_lite_test.cc | 9 ++++ 5 files changed, 46 insertions(+), 22 deletions(-) diff --git a/src/google/protobuf/BUILD.bazel b/src/google/protobuf/BUILD.bazel index d7e6faf28f0f4..aacc707e643d0 100644 --- a/src/google/protobuf/BUILD.bazel +++ b/src/google/protobuf/BUILD.bazel @@ -1256,7 +1256,9 @@ cc_test( ":test_util", "//src/google/protobuf/stubs", "//src/google/protobuf/testing", + "@com_google_absl//absl/flags:flag", "@com_google_absl//absl/log:absl_check", + "@com_google_absl//absl/strings", "@com_google_absl//absl/strings:cord", "@com_google_googletest//:gtest", "@com_google_googletest//:gtest_main", @@ -1276,6 +1278,10 @@ cc_test( ":cc_test_protos", ":port", ":protobuf_lite", + "//src/google/protobuf/io", + "@com_google_absl//absl/log:absl_check", + "@com_google_absl//absl/log:absl_log", + "@com_google_absl//absl/strings", "@com_google_absl//absl/types:optional", "@com_google_googletest//:gtest", "@com_google_googletest//:gtest_main", diff --git a/src/google/protobuf/compiler/cpp/BUILD.bazel b/src/google/protobuf/compiler/cpp/BUILD.bazel index 820ec7c0fd9fd..8f87ce26fb0c5 100644 --- a/src/google/protobuf/compiler/cpp/BUILD.bazel +++ b/src/google/protobuf/compiler/cpp/BUILD.bazel @@ -251,6 +251,7 @@ cc_test( "//src/google/protobuf", "//src/google/protobuf:cc_test_protos", "//src/google/protobuf:port", + "//src/google/protobuf:protobuf_lite", "@com_google_absl//absl/log:absl_check", "@com_google_googletest//:gtest", "@com_google_googletest//:gtest_main", diff --git a/src/google/protobuf/compiler/cpp/message_size_unittest.cc b/src/google/protobuf/compiler/cpp/message_size_unittest.cc index 3982a4fd4e6b8..791dbc6df8680 100644 --- a/src/google/protobuf/compiler/cpp/message_size_unittest.cc +++ b/src/google/protobuf/compiler/cpp/message_size_unittest.cc @@ -5,10 +5,14 @@ // license that can be found in the LICENSE file or at // https://developers.google.com/open-source/licenses/bsd -#include +#include +#include + #include #include "absl/log/absl_check.h" #include "google/protobuf/descriptor.h" +#include "google/protobuf/generated_message_bases.h" +#include "google/protobuf/repeated_ptr_field.h" #include "google/protobuf/unittest.pb.h" // Must be included last. @@ -89,7 +93,7 @@ TEST(GeneratedMessageTest, EmptyMessageWithExtensionsSize) { struct MockGenerated : public MockMessageBase { // 16 bytes MockExtensionSet extensions; // 24 bytes int cached_size; // 4 bytes - PROTOBUF_TSAN_DECLARE_MEMBER // 0-4 bytes + PROTOBUF_TSAN_DECLARE_MEMBER; // 0-4 bytes // + 0-4 bytes of padding }; ABSL_CHECK_MESSAGE_SIZE(MockGenerated, 48); @@ -103,7 +107,7 @@ TEST(GeneratedMessageTest, RecursiveMessageSize) { int cached_size; // 4 bytes void* a; // 8 bytes int32_t i; // 4 bytes - PROTOBUF_TSAN_DECLARE_MEMBER // 0-4 bytes + PROTOBUF_TSAN_DECLARE_MEMBER; // 0-4 bytes // + 0-4 bytes padding }; ABSL_CHECK_MESSAGE_SIZE(MockGenerated, 40); @@ -115,9 +119,9 @@ TEST(GeneratedMessageTest, OneStringSize) { struct MockGenerated : public MockMessageBase { // 16 bytes int has_bits[1]; // 4 bytes int cached_size; // 4 bytes - PROTOBUF_TSAN_DECLARE_MEMBER // 0-4 bytes + PROTOBUF_TSAN_DECLARE_MEMBER; // 0-4 bytes // + 0-4 bytes padding - void* data; // 8 bytes + void* data; // 8 bytes }; ABSL_CHECK_MESSAGE_SIZE(MockGenerated, 32); EXPECT_EQ(sizeof(protobuf_unittest::OneString), sizeof(MockGenerated)); @@ -126,9 +130,9 @@ TEST(GeneratedMessageTest, OneStringSize) { TEST(GeneratedMessageTest, MoreStringSize) { struct MockGenerated : public MockMessageBase { // 16 bytes int cached_size; // 4 bytes - PROTOBUF_TSAN_DECLARE_MEMBER // 0-4 bytes + PROTOBUF_TSAN_DECLARE_MEMBER; // 0-4 bytes // + 0-4 bytes padding - MockRepeatedPtrField data; // 24 bytes + MockRepeatedPtrField data; // 24 bytes }; ABSL_CHECK_MESSAGE_SIZE(MockGenerated, 48); EXPECT_EQ(sizeof(protobuf_unittest::MoreString), sizeof(MockGenerated)); @@ -138,9 +142,9 @@ TEST(GeneratedMessageTest, Int32MessageSize) { struct MockGenerated : public MockMessageBase { // 16 bytes int has_bits[1]; // 4 bytes int cached_size; // 4 bytes - PROTOBUF_TSAN_DECLARE_MEMBER // 0-4 bytes + PROTOBUF_TSAN_DECLARE_MEMBER; // 0-4 bytes // + 0-4 bytes padding - int32_t data; // 4 bytes + int32_t data; // 4 bytes }; ABSL_CHECK_MESSAGE_SIZE(MockGenerated, 32); EXPECT_EQ(sizeof(protobuf_unittest::Int32Message), sizeof(MockGenerated)); @@ -150,9 +154,9 @@ TEST(GeneratedMessageTest, Int64MessageSize) { struct MockGenerated : public MockMessageBase { // 16 bytes int has_bits[1]; // 4 bytes int cached_size; // 4 bytes - PROTOBUF_TSAN_DECLARE_MEMBER // 0-4 bytes + PROTOBUF_TSAN_DECLARE_MEMBER; // 0-4 bytes // + 0-4 bytes padding - int64_t data; // 8 bytes + int64_t data; // 8 bytes }; ABSL_CHECK_MESSAGE_SIZE(MockGenerated, 32); EXPECT_EQ(sizeof(protobuf_unittest::Int64Message), sizeof(MockGenerated)); @@ -162,9 +166,9 @@ TEST(GeneratedMessageTest, BoolMessageSize) { struct MockGenerated : public MockMessageBase { // 16 bytes int has_bits[1]; // 4 bytes int cached_size; // 4 bytes - PROTOBUF_TSAN_DECLARE_MEMBER // 0-4 bytes + PROTOBUF_TSAN_DECLARE_MEMBER; // 0-4 bytes // + 0-4 bytes padding - bool data; // 1 byte + bool data; // 1 byte // + 3 bytes padding }; ABSL_CHECK_MESSAGE_SIZE(MockGenerated, 32); @@ -175,9 +179,9 @@ TEST(GeneratedMessageTest, OneofSize) { struct MockGenerated : public MockMessageBase { // 16 bytes void* foo; // 8 bytes int cached_size; // 4 bytes - PROTOBUF_TSAN_DECLARE_MEMBER // 0-4 bytes + PROTOBUF_TSAN_DECLARE_MEMBER; // 0-4 bytes // + 0-4 bytes padding - uint32_t oneof_case[1]; // 4 bytes + uint32_t oneof_case[1]; // 4 bytes }; ABSL_CHECK_MESSAGE_SIZE(MockGenerated, 32); EXPECT_EQ(sizeof(protobuf_unittest::TestOneof), sizeof(MockGenerated)); @@ -187,9 +191,9 @@ TEST(GeneratedMessageTest, Oneof2Size) { struct MockGenerated : public MockMessageBase { // 16 bytes int has_bits[1]; // 4 bytes int cached_size; // 4 bytes - PROTOBUF_TSAN_DECLARE_MEMBER // 0-4 bytes + PROTOBUF_TSAN_DECLARE_MEMBER; // 0-4 bytes // + 0-4 bytes padding - void* baz_string; // 8 bytes + void* baz_string; // 8 bytes int32_t baz_int; // 4 bytes // + 4 bytes padding void* foo; // 8 bytes @@ -209,7 +213,7 @@ TEST(GeneratedMessageTest, FieldOrderingsSize) { void* optional_nested_message; // 8 bytes int64_t my_int; // 8 bytes float my_float; // 4 bytes - PROTOBUF_TSAN_DECLARE_MEMBER // 0-4 bytes + PROTOBUF_TSAN_DECLARE_MEMBER; // 0-4 bytes // + 0-4 bytes padding }; ABSL_CHECK_MESSAGE_SIZE(MockGenerated, 80); @@ -221,9 +225,9 @@ TEST(GeneratedMessageTest, TestMessageSize) { struct MockGenerated : public MockMessageBase { // 16 bytes int has_bits[1]; // 4 bytes int cached_size; // 4 bytes - PROTOBUF_TSAN_DECLARE_MEMBER // 0-4 bytes + PROTOBUF_TSAN_DECLARE_MEMBER; // 0-4 bytes // + 0-4 bytes padding - void* m4; // 8 bytes + void* m4; // 8 bytes int64_t m2; // 8 bytes bool m1; // 1 bytes bool m3; // 1 bytes @@ -259,7 +263,7 @@ TEST(GeneratedMessageTest, PackedTypesSize) { MockRepeatedField packed_enum; // 16 bytes int packed_enum_cached_byte_size; // 4 bytes int cached_size; // 4 bytes - PROTOBUF_TSAN_DECLARE_MEMBER // 0-4 bytes + PROTOBUF_TSAN_DECLARE_MEMBER; // 0-4 bytes // + 0-4 bytes padding }; ABSL_CHECK_MESSAGE_SIZE(MockGenerated, 16 * 15 + 8 * 6 + 8); diff --git a/src/google/protobuf/generated_message_reflection_unittest.cc b/src/google/protobuf/generated_message_reflection_unittest.cc index 93bfcbbee3bf7..4925f53ada434 100644 --- a/src/google/protobuf/generated_message_reflection_unittest.cc +++ b/src/google/protobuf/generated_message_reflection_unittest.cc @@ -22,16 +22,20 @@ #include "google/protobuf/generated_message_reflection.h" #include +#include +#include #include -#include "google/protobuf/testing/googletest.h" #include +#include "absl/flags/flag.h" #include "absl/log/absl_check.h" #include "absl/strings/cord.h" +#include "absl/strings/string_view.h" #include "google/protobuf/arena.h" #include "google/protobuf/descriptor.h" #include "google/protobuf/map_test_util.h" #include "google/protobuf/map_unittest.pb.h" +#include "google/protobuf/message.h" #include "google/protobuf/test_util.h" #include "google/protobuf/unittest.pb.h" #include "google/protobuf/unittest.pb.h" diff --git a/src/google/protobuf/generated_message_tctable_lite_test.cc b/src/google/protobuf/generated_message_tctable_lite_test.cc index 136fea52a80fc..719e5202f8641 100644 --- a/src/google/protobuf/generated_message_tctable_lite_test.cc +++ b/src/google/protobuf/generated_message_tctable_lite_test.cc @@ -6,11 +6,20 @@ // https://developers.google.com/open-source/licenses/bsd #include +#include +#include #include #include +#include "absl/log/absl_check.h" +#include "absl/log/absl_log.h" +#include "absl/strings/str_cat.h" +#include "absl/strings/string_view.h" #include "absl/types/optional.h" +#include "google/protobuf/generated_message_tctable_decl.h" #include "google/protobuf/generated_message_tctable_impl.h" +#include "google/protobuf/io/coded_stream.h" +#include "google/protobuf/parse_context.h" #include "google/protobuf/unittest.pb.h" #include "google/protobuf/wire_format_lite.h" From fd699383f44d6847fa6ddc3e0c9c94e77e3cf8dc Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Thu, 4 Jan 2024 09:59:08 -0800 Subject: [PATCH 167/255] Breaking Change: Fixed inconsistencies in `Message#to_h`, [as previously announced](https://protobuf.dev/news/2023-12-27/). Fixes: https://github.com/protocolbuffers/protobuf/issues/6167 PiperOrigin-RevId: 595733611 --- ruby/ext/google/protobuf_c/message.c | 52 +++++-------------- ruby/lib/google/protobuf/ffi/ffi.rb | 2 + .../google/protobuf/ffi/internal/convert.rb | 30 +++-------- ruby/lib/google/protobuf/ffi/message.rb | 1 + .../google/protobuf/jruby/RubyMessage.java | 40 +++++++------- ruby/tests/basic.rb | 29 +++-------- upb/reflection/message.h | 7 +-- 7 files changed, 54 insertions(+), 107 deletions(-) diff --git a/ruby/ext/google/protobuf_c/message.c b/ruby/ext/google/protobuf_c/message.c index d48c8c025f58b..3b12c93f3d7af 100644 --- a/ruby/ext/google/protobuf_c/message.c +++ b/ruby/ext/google/protobuf_c/message.c @@ -766,58 +766,34 @@ static VALUE Message_CreateHash(const upb_Message* msg, if (!msg) return Qnil; VALUE hash = rb_hash_new(); - int n = upb_MessageDef_FieldCount(m); - bool is_proto2; - - // We currently have a few behaviors that are specific to proto2. - // This is unfortunate, we should key behaviors off field attributes (like - // whether a field has presence), not proto2 vs. proto3. We should see if we - // can change this without breaking users. - is_proto2 = upb_MessageDef_Syntax(m) == kUpb_Syntax_Proto2; - - for (int i = 0; i < n; i++) { - const upb_FieldDef* field = upb_MessageDef_Field(m, i); - TypeInfo type_info = TypeInfo_get(field); - upb_MessageValue msgval; - VALUE msg_value; - VALUE msg_key; - - if (!is_proto2 && upb_FieldDef_IsSubMessage(field) && - !upb_FieldDef_IsRepeated(field) && - !upb_Message_HasFieldByDef(msg, field)) { - // TODO: Legacy behavior, remove when we fix the is_proto2 differences. - msg_key = ID2SYM(rb_intern(upb_FieldDef_Name(field))); - rb_hash_aset(hash, msg_key, Qnil); - continue; - } + size_t iter = kUpb_Message_Begin; + const upb_DefPool* pool = upb_FileDef_Pool(upb_MessageDef_File(m)); + const upb_FieldDef* field; + upb_MessageValue val; - // Do not include fields that are not present (oneof or optional fields). - if (is_proto2 && upb_FieldDef_HasPresence(field) && - !upb_Message_HasFieldByDef(msg, field)) { + while (upb_Message_Next(msg, m, pool, &field, &val, &iter)) { + if (upb_FieldDef_IsExtension(field)) { + // TODO: allow extensions once we have decided what naming scheme the + // symbol should use. eg. :"[pkg.ext]" continue; } - msg_key = ID2SYM(rb_intern(upb_FieldDef_Name(field))); - msgval = upb_Message_GetFieldByDef(msg, field); - - // Proto2 omits empty map/repeated filds also. + TypeInfo type_info = TypeInfo_get(field); + VALUE msg_value; if (upb_FieldDef_IsMap(field)) { const upb_MessageDef* entry_m = upb_FieldDef_MessageSubDef(field); const upb_FieldDef* key_f = upb_MessageDef_FindFieldByNumber(entry_m, 1); const upb_FieldDef* val_f = upb_MessageDef_FindFieldByNumber(entry_m, 2); upb_CType key_type = upb_FieldDef_CType(key_f); - msg_value = Map_CreateHash(msgval.map_val, key_type, TypeInfo_get(val_f)); + msg_value = Map_CreateHash(val.map_val, key_type, TypeInfo_get(val_f)); } else if (upb_FieldDef_IsRepeated(field)) { - if (is_proto2 && - (!msgval.array_val || upb_Array_Size(msgval.array_val) == 0)) { - continue; - } - msg_value = RepeatedField_CreateArray(msgval.array_val, type_info); + msg_value = RepeatedField_CreateArray(val.array_val, type_info); } else { - msg_value = Scalar_CreateHash(msgval, type_info); + msg_value = Scalar_CreateHash(val, type_info); } + VALUE msg_key = ID2SYM(rb_intern(upb_FieldDef_Name(field))); rb_hash_aset(hash, msg_key, msg_value); } diff --git a/ruby/lib/google/protobuf/ffi/ffi.rb b/ruby/lib/google/protobuf/ffi/ffi.rb index 77ee42ead25cf..1858c91a7df7c 100644 --- a/ruby/lib/google/protobuf/ffi/ffi.rb +++ b/ruby/lib/google/protobuf/ffi/ffi.rb @@ -190,6 +190,8 @@ class MessageValue < ::FFI::Union :str_val, StringView end + Upb_Message_Begin = -1 + class MutableMessageValue < ::FFI::Union layout :map, :Map, :msg, :Message, diff --git a/ruby/lib/google/protobuf/ffi/internal/convert.rb b/ruby/lib/google/protobuf/ffi/internal/convert.rb index 2b443156345c5..b1eb0005e2bc7 100644 --- a/ruby/lib/google/protobuf/ffi/internal/convert.rb +++ b/ruby/lib/google/protobuf/ffi/internal/convert.rb @@ -190,39 +190,23 @@ def convert_upb_to_ruby(message_value, c_type, msg_or_enum_def = nil, arena = ni def to_h_internal(msg, message_descriptor) return nil if msg.nil? or msg.null? hash = {} - is_proto2 = Google::Protobuf::FFI.message_def_syntax(message_descriptor) == :Proto2 - message_descriptor.each do |field_descriptor| - # TODO: Legacy behavior, remove when we fix the is_proto2 differences. - if !is_proto2 and - field_descriptor.sub_message? and - !field_descriptor.repeated? and - !Google::Protobuf::FFI.get_message_has(msg, field_descriptor) - hash[field_descriptor.name.to_sym] = nil - next - end - - # Do not include fields that are not present (oneof or optional fields). - if is_proto2 and field_descriptor.has_presence? and !Google::Protobuf::FFI.get_message_has(msg, field_descriptor) - next - end + iter = ::FFI::MemoryPointer.new(:size_t, 1) + iter.write(:size_t, Google::Protobuf::FFI::Upb_Message_Begin) + message_value = Google::Protobuf::FFI::MessageValue.new + field_def_ptr = ::FFI::MemoryPointer.new :pointer - message_value = Google::Protobuf::FFI.get_message_value msg, field_descriptor + while Google::Protobuf::FFI::message_next(msg, message_descriptor, nil, field_def_ptr, message_value, iter) do + field_descriptor = FieldDescriptor.from_native field_def_ptr.get_pointer(0) - # Proto2 omits empty map/repeated fields also. if field_descriptor.map? hash_entry = map_create_hash(message_value[:map_val], field_descriptor) elsif field_descriptor.repeated? - array = message_value[:array_val] - if is_proto2 and (array.null? || Google::Protobuf::FFI.array_size(array).zero?) - next - end - hash_entry = repeated_field_create_array(array, field_descriptor, field_descriptor.type) + hash_entry = repeated_field_create_array(message_value[:array_val], field_descriptor, field_descriptor.type) else hash_entry = scalar_create_hash(message_value, field_descriptor.type, field_descriptor: field_descriptor) end hash[field_descriptor.name.to_sym] = hash_entry - end hash diff --git a/ruby/lib/google/protobuf/ffi/message.rb b/ruby/lib/google/protobuf/ffi/message.rb index 39eb403853de4..5d9a36592721e 100644 --- a/ruby/lib/google/protobuf/ffi/message.rb +++ b/ruby/lib/google/protobuf/ffi/message.rb @@ -23,6 +23,7 @@ class FFI attach_function :get_mutable_message, :upb_Message_Mutable, [:Message, FieldDescriptor, Internal::Arena], MutableMessageValue.by_value attach_function :get_message_which_oneof, :upb_Message_WhichOneof, [:Message, OneofDescriptor], FieldDescriptor attach_function :message_discard_unknown, :upb_Message_DiscardUnknown, [:Message, Descriptor, :int], :bool + attach_function :message_next, :upb_Message_Next, [:Message, Descriptor, :DefPool, :FieldDefPointer, MessageValue.by_ref, :pointer], :bool # MessageValue attach_function :message_value_equal, :shared_Msgval_IsEqual, [MessageValue.by_value, MessageValue.by_value, CType, Descriptor], :bool attach_function :message_value_hash, :shared_Msgval_GetHash, [MessageValue.by_value, CType, Descriptor, :uint64_t], :uint64_t diff --git a/ruby/src/main/java/com/google/protobuf/jruby/RubyMessage.java b/ruby/src/main/java/com/google/protobuf/jruby/RubyMessage.java index ec57a4bff2b91..2ac9fc912e11e 100644 --- a/ruby/src/main/java/com/google/protobuf/jruby/RubyMessage.java +++ b/ruby/src/main/java/com/google/protobuf/jruby/RubyMessage.java @@ -787,33 +787,29 @@ public static IRubyObject decodeJson( public IRubyObject toHash(ThreadContext context) { Ruby runtime = context.runtime; RubyHash ret = RubyHash.newHash(runtime); - for (FieldDescriptor fdef : this.descriptor.getFields()) { + build(context, 0, SINK_MAXIMUM_NESTING); // Sync Ruby data to the Builder object. + for (Map.Entry field : builder.getAllFields().entrySet()) { + FieldDescriptor fdef = field.getKey(); IRubyObject value = getFieldInternal(context, fdef, proto3); - if (!value.isNil()) { - if (fdef.isRepeated() && !fdef.isMapField()) { - if (!proto3 && ((RubyRepeatedField) value).size() == 0) - continue; // Don't output empty repeated fields for proto2 - if (fdef.getType() != FieldDescriptor.Type.MESSAGE) { - value = Helpers.invoke(context, value, "to_a"); - } else { - RubyArray ary = value.convertToArray(); - for (int i = 0; i < ary.size(); i++) { - IRubyObject submsg = Helpers.invoke(context, ary.eltInternal(i), "to_h"); - ary.eltInternalSet(i, submsg); - } - - value = ary.to_ary(); - } - } else if (value.respondsTo("to_h")) { - value = Helpers.invoke(context, value, "to_h"); - } else if (value.respondsTo("to_a")) { + if (fdef.isRepeated() && !fdef.isMapField()) { + if (fdef.getType() != FieldDescriptor.Type.MESSAGE) { value = Helpers.invoke(context, value, "to_a"); + } else { + RubyArray ary = value.convertToArray(); + for (int i = 0; i < ary.size(); i++) { + IRubyObject submsg = Helpers.invoke(context, ary.eltInternal(i), "to_h"); + ary.eltInternalSet(i, submsg); + } + + value = ary.to_ary(); } + } else if (value.respondsTo("to_h")) { + value = Helpers.invoke(context, value, "to_h"); + } else if (value.respondsTo("to_a")) { + value = Helpers.invoke(context, value, "to_a"); } - if (proto3 || !value.isNil()) { - ret.fastASet(runtime.newSymbol(fdef.getName()), value); - } + ret.fastASet(runtime.newSymbol(fdef.getName()), value); } return ret; } diff --git a/ruby/tests/basic.rb b/ruby/tests/basic.rb index 4dc45e748c201..b71fdac4ea1e9 100755 --- a/ruby/tests/basic.rb +++ b/ruby/tests/basic.rb @@ -469,32 +469,19 @@ def test_protobuf_decode_json_ignore_unknown_fields #end def test_to_h - m = TestMessage.new(:optional_bool => true, :optional_double => -10.100001, :optional_string => 'foo', :repeated_string => ['bar1', 'bar2'], :repeated_msg => [TestMessage2.new(:foo => 100)]) + m = TestMessage.new( + :optional_bool => true, + :optional_double => -10.100001, + :optional_string => 'foo', + :repeated_string => ['bar1', 'bar2'], + :repeated_msg => [TestMessage2.new(:foo => 100)] + ) expected_result = { :optional_bool=>true, - :optional_bytes=>"", :optional_double=>-10.100001, - :optional_enum=>:Default, - :optional_float=>0.0, - :optional_int32=>0, - :optional_int64=>0, - :optional_msg=>nil, - :optional_msg2=>nil, - :optional_proto2_submessage=>nil, :optional_string=>"foo", - :optional_uint32=>0, - :optional_uint64=>0, - :repeated_bool=>[], - :repeated_bytes=>[], - :repeated_double=>[], - :repeated_enum=>[], - :repeated_float=>[], - :repeated_int32=>[], - :repeated_int64=>[], - :repeated_msg=>[{:foo => 100}], :repeated_string=>["bar1", "bar2"], - :repeated_uint32=>[], - :repeated_uint64=>[] + :repeated_msg=>[{:foo => 100}], } assert_equal expected_result, m.to_h diff --git a/upb/reflection/message.h b/upb/reflection/message.h index d31f6b9b26015..b3b52d7ace5ea 100644 --- a/upb/reflection/message.h +++ b/upb/reflection/message.h @@ -71,9 +71,10 @@ UPB_API bool upb_Message_SetFieldByDef(upb_Message* msg, const upb_FieldDef* f, #define kUpb_Message_Begin -1 -bool upb_Message_Next(const upb_Message* msg, const upb_MessageDef* m, - const upb_DefPool* ext_pool, const upb_FieldDef** f, - upb_MessageValue* val, size_t* iter); +UPB_API bool upb_Message_Next(const upb_Message* msg, const upb_MessageDef* m, + const upb_DefPool* ext_pool, + const upb_FieldDef** f, upb_MessageValue* val, + size_t* iter); // Clears all unknown field data from this message and all submessages. UPB_API bool upb_Message_DiscardUnknown(upb_Message* msg, From 7e32450ccd550ce03052a9596fd883ae92ef34d5 Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Thu, 4 Jan 2024 18:12:49 +0000 Subject: [PATCH 168/255] Auto-generate files after cl/595733611 --- php/ext/google/protobuf/php-upb.h | 7 ++++--- ruby/ext/google/protobuf_c/ruby-upb.h | 7 ++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/php/ext/google/protobuf/php-upb.h b/php/ext/google/protobuf/php-upb.h index 27814aeed6e03..61e3185374b0e 100644 --- a/php/ext/google/protobuf/php-upb.h +++ b/php/ext/google/protobuf/php-upb.h @@ -12251,9 +12251,10 @@ UPB_API bool upb_Message_SetFieldByDef(upb_Message* msg, const upb_FieldDef* f, #define kUpb_Message_Begin -1 -bool upb_Message_Next(const upb_Message* msg, const upb_MessageDef* m, - const upb_DefPool* ext_pool, const upb_FieldDef** f, - upb_MessageValue* val, size_t* iter); +UPB_API bool upb_Message_Next(const upb_Message* msg, const upb_MessageDef* m, + const upb_DefPool* ext_pool, + const upb_FieldDef** f, upb_MessageValue* val, + size_t* iter); // Clears all unknown field data from this message and all submessages. UPB_API bool upb_Message_DiscardUnknown(upb_Message* msg, diff --git a/ruby/ext/google/protobuf_c/ruby-upb.h b/ruby/ext/google/protobuf_c/ruby-upb.h index 5bd47a51752cd..d6f1f7ddff54c 100755 --- a/ruby/ext/google/protobuf_c/ruby-upb.h +++ b/ruby/ext/google/protobuf_c/ruby-upb.h @@ -12023,9 +12023,10 @@ UPB_API bool upb_Message_SetFieldByDef(upb_Message* msg, const upb_FieldDef* f, #define kUpb_Message_Begin -1 -bool upb_Message_Next(const upb_Message* msg, const upb_MessageDef* m, - const upb_DefPool* ext_pool, const upb_FieldDef** f, - upb_MessageValue* val, size_t* iter); +UPB_API bool upb_Message_Next(const upb_Message* msg, const upb_MessageDef* m, + const upb_DefPool* ext_pool, + const upb_FieldDef** f, upb_MessageValue* val, + size_t* iter); // Clears all unknown field data from this message and all submessages. UPB_API bool upb_Message_DiscardUnknown(upb_Message* msg, From fbbe681409d644b5a5e30415ae2cf18227b7bf68 Mon Sep 17 00:00:00 2001 From: Marcel Date: Thu, 4 Jan 2024 10:12:42 -0800 Subject: [PATCH 169/255] Do no longer depend on deprecated //external:python_headers (#15236) `bind()` targets are deprecated and unsupported with Bzlmod. Specifying the dependency directly as a mitigation. Alternative: Define an `alias()` within `/third_party/BUILD`. Closes #15236 COPYBARA_INTEGRATE_REVIEW=https://github.com/protocolbuffers/protobuf/pull/15236 from mering:alias-python-headers 801ac73313260c41082b7fa83ae3684f274f46e1 PiperOrigin-RevId: 595737575 --- WORKSPACE | 5 ----- python/build_targets.bzl | 6 +++--- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/WORKSPACE b/WORKSPACE index eb31a6ea40bae..b7bc51cb726d8 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -191,11 +191,6 @@ load("@fuzzing_py_deps//:requirements.bzl", fuzzing_py_deps_install_deps = "inst fuzzing_py_deps_install_deps() -bind( - name = "python_headers", - actual = "@system_python//:python_headers", -) - http_archive( name = "rules_rust", sha256 = "9ecd0f2144f0a24e6bc71ebcc50a1ee5128cedeceb32187004532c9710cb2334", diff --git a/python/build_targets.bzl b/python/build_targets.bzl index b81baab4e1fc0..5f4ae756b342f 100644 --- a/python/build_targets.bzl +++ b/python/build_targets.bzl @@ -85,7 +85,7 @@ def build_targets(name): ], deps = select({ "//conditions:default": [], - ":use_fast_cpp_protos": ["//external:python_headers"], + ":use_fast_cpp_protos": ["@system_python//:python_headers"], }), ) @@ -134,7 +134,7 @@ def build_targets(name): "@com_google_absl//absl/strings", ] + select({ "//conditions:default": [], - ":use_fast_cpp_protos": ["//external:python_headers"], + ":use_fast_cpp_protos": ["@system_python//:python_headers"], }), ) @@ -398,7 +398,7 @@ def build_targets(name): hdrs = ["google/protobuf/proto_api.h"], visibility = ["//visibility:public"], deps = [ - "//external:python_headers", + "@system_python//:python_headers", ], ) From 8d366006b58a761d297147d62cc853f51a7b318c Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Thu, 4 Jan 2024 11:07:44 -0800 Subject: [PATCH 170/255] Fix lowerCamelCase to UpperCamelCase (per Cpp style guide) PiperOrigin-RevId: 595753465 --- src/google/protobuf/compiler/rust/enum.cc | 8 ++++---- src/google/protobuf/compiler/rust/oneof.cc | 22 +++++++++++----------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/google/protobuf/compiler/rust/enum.cc b/src/google/protobuf/compiler/rust/enum.cc index 4871a34f46bf0..de9382a99aea1 100644 --- a/src/google/protobuf/compiler/rust/enum.cc +++ b/src/google/protobuf/compiler/rust/enum.cc @@ -35,12 +35,12 @@ namespace rust { namespace { -std::string enumName(const EnumDescriptor& desc) { +std::string EnumName(const EnumDescriptor& desc) { return cpp::UnderscoresToCamelCase(desc.name(), /*cap first letter=*/true); } // Constructs input for `EnumValues` from an enum descriptor. -std::vector> enumValuesInput( +std::vector> EnumValuesInput( const EnumDescriptor& desc) { std::vector> result; result.reserve(static_cast(desc.value_count())); @@ -165,10 +165,10 @@ std::string ScreamingSnakeToUpperCamelCase(absl::string_view input) { } void GenerateEnumDefinition(Context& ctx, const EnumDescriptor& desc) { - std::string name = enumName(desc); + std::string name = EnumName(desc); ABSL_CHECK(desc.value_count() > 0); std::vector values = - EnumValues(desc.name(), enumValuesInput(desc)); + EnumValues(desc.name(), EnumValuesInput(desc)); ABSL_CHECK(!values.empty()); ctx.Emit( diff --git a/src/google/protobuf/compiler/rust/oneof.cc b/src/google/protobuf/compiler/rust/oneof.cc index a2d4ca86e404a..4b08f4571c54d 100644 --- a/src/google/protobuf/compiler/rust/oneof.cc +++ b/src/google/protobuf/compiler/rust/oneof.cc @@ -78,15 +78,15 @@ std::string ToCamelCase(absl::string_view name) { return cpp::UnderscoresToCamelCase(name, /* upper initial letter */ true); } -std::string oneofViewEnumRsName(const OneofDescriptor& oneof) { +std::string OneofViewEnumRsName(const OneofDescriptor& oneof) { return ToCamelCase(oneof.name()); } -std::string oneofMutEnumRsName(const OneofDescriptor& oneof) { +std::string OneofMutEnumRsName(const OneofDescriptor& oneof) { return ToCamelCase(oneof.name()) + "Mut"; } -std::string oneofCaseEnumName(const OneofDescriptor& oneof) { +std::string OneofCaseEnumName(const OneofDescriptor& oneof) { // Note: This is the name used for the cpp Case enum, we use it for both // the Rust Case enum as well as for the cpp case enum in the cpp thunk. return ToCamelCase(oneof.name()) + "Case"; @@ -167,8 +167,8 @@ std::string RsTypeNameMut(Context& ctx, const FieldDescriptor& field) { void GenerateOneofDefinition(Context& ctx, const OneofDescriptor& oneof) { ctx.Emit( - {{"view_enum_name", oneofViewEnumRsName(oneof)}, - {"mut_enum_name", oneofMutEnumRsName(oneof)}, + {{"view_enum_name", OneofViewEnumRsName(oneof)}, + {"mut_enum_name", OneofMutEnumRsName(oneof)}, {"view_fields", [&] { for (int i = 0; i < oneof.field_count(); ++i) { @@ -230,7 +230,7 @@ void GenerateOneofDefinition(Context& ctx, const OneofDescriptor& oneof) { // Note: This enum is used as the Thunk return type for getting which case is // used: it exactly matches the generate case enum that both cpp and upb use. - ctx.Emit({{"case_enum_name", oneofCaseEnumName(oneof)}, + ctx.Emit({{"case_enum_name", OneofCaseEnumName(oneof)}, {"cases", [&] { for (int i = 0; i < oneof.field_count(); ++i) { @@ -258,9 +258,9 @@ void GenerateOneofDefinition(Context& ctx, const OneofDescriptor& oneof) { void GenerateOneofAccessors(Context& ctx, const OneofDescriptor& oneof) { ctx.Emit( {{"oneof_name", oneof.name()}, - {"view_enum_name", oneofViewEnumRsName(oneof)}, - {"mut_enum_name", oneofMutEnumRsName(oneof)}, - {"case_enum_name", oneofCaseEnumName(oneof)}, + {"view_enum_name", OneofViewEnumRsName(oneof)}, + {"mut_enum_name", OneofMutEnumRsName(oneof)}, + {"case_enum_name", OneofCaseEnumName(oneof)}, {"view_cases", [&] { for (int i = 0; i < oneof.field_count(); ++i) { @@ -341,7 +341,7 @@ void GenerateOneofAccessors(Context& ctx, const OneofDescriptor& oneof) { void GenerateOneofExternC(Context& ctx, const OneofDescriptor& oneof) { ctx.Emit( { - {"case_enum_rs_name", oneofCaseEnumName(oneof)}, + {"case_enum_rs_name", OneofCaseEnumName(oneof)}, {"case_thunk", ThunkName(ctx, oneof, "case")}, }, R"rs( @@ -353,7 +353,7 @@ void GenerateOneofThunkCc(Context& ctx, const OneofDescriptor& oneof) { ctx.Emit( { {"oneof_name", oneof.name()}, - {"case_enum_name", oneofCaseEnumName(oneof)}, + {"case_enum_name", OneofCaseEnumName(oneof)}, {"case_thunk", ThunkName(ctx, oneof, "case")}, {"QualifiedMsg", cpp::QualifiedClassName(oneof.containing_type())}, }, From 31313b16522b36394d460055f6a49000ae939153 Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Thu, 4 Jan 2024 12:52:08 -0800 Subject: [PATCH 171/255] Breaking Change: freeze is now recursive, affecting all sub-messages, maps, and repeated fields. PiperOrigin-RevId: 595779782 --- ruby/ext/google/protobuf_c/map.c | 21 +++++---------- ruby/ext/google/protobuf_c/map.h | 2 +- ruby/ext/google/protobuf_c/message.c | 26 ++++++------------- ruby/ext/google/protobuf_c/message.h | 2 +- ruby/ext/google/protobuf_c/repeated_field.c | 21 +++++---------- ruby/ext/google/protobuf_c/repeated_field.h | 2 +- ruby/lib/google/protobuf/ffi/descriptor.rb | 4 +-- .../google/protobuf/ffi/enum_descriptor.rb | 2 +- .../google/protobuf/ffi/field_descriptor.rb | 2 +- .../google/protobuf/ffi/file_descriptor.rb | 2 +- ruby/lib/google/protobuf/ffi/map.rb | 24 +++++++++-------- ruby/lib/google/protobuf/ffi/message.rb | 22 +++++++--------- .../google/protobuf/ffi/oneof_descriptor.rb | 2 +- .../lib/google/protobuf/ffi/repeated_field.rb | 22 +++++++++------- .../com/google/protobuf/jruby/RubyMap.java | 8 ++++-- .../google/protobuf/jruby/RubyMessage.java | 14 ++++++---- .../protobuf/jruby/RubyRepeatedField.java | 8 ++++-- ruby/tests/basic.rb | 5 ++-- 18 files changed, 86 insertions(+), 103 deletions(-) diff --git a/ruby/ext/google/protobuf_c/map.c b/ruby/ext/google/protobuf_c/map.c index 7b78f87fc08f6..99de072a6a9b8 100644 --- a/ruby/ext/google/protobuf_c/map.c +++ b/ruby/ext/google/protobuf_c/map.c @@ -563,22 +563,13 @@ VALUE Map_eq(VALUE _self, VALUE _other) { * Freezes the message object. We have to intercept this so we can pin the * Ruby object into memory so we don't forget it's frozen. */ -static VALUE Map_freeze(VALUE _self) { +VALUE Map_freeze(VALUE _self) { Map* self = ruby_to_Map(_self); - if (!RB_OBJ_FROZEN(_self)) { - Arena_Pin(self->arena, _self); - RB_OBJ_FREEZE(_self); - } - return _self; -} -/* - * Deep freezes the map and values recursively. - * Internal use only. - */ -VALUE Map_internal_deep_freeze(VALUE _self) { - Map* self = ruby_to_Map(_self); - Map_freeze(_self); + if (RB_OBJ_FROZEN(_self)) return _self; + Arena_Pin(self->arena, _self); + RB_OBJ_FREEZE(_self); + if (self->value_type_info.type == kUpb_CType_Message) { size_t iter = kUpb_Map_Begin; upb_MessageValue key, val; @@ -586,7 +577,7 @@ VALUE Map_internal_deep_freeze(VALUE _self) { while (upb_Map_Next(self->map, &key, &val, &iter)) { VALUE val_val = Convert_UpbToRuby(val, self->value_type_info, self->arena); - Message_internal_deep_freeze(val_val); + Message_freeze(val_val); } } return _self; diff --git a/ruby/ext/google/protobuf_c/map.h b/ruby/ext/google/protobuf_c/map.h index d3cebc6a6909f..cb4041d5a0214 100644 --- a/ruby/ext/google/protobuf_c/map.h +++ b/ruby/ext/google/protobuf_c/map.h @@ -39,6 +39,6 @@ extern VALUE cMap; void Map_register(VALUE module); // Recursively freeze map -VALUE Map_internal_deep_freeze(VALUE _self); +VALUE Map_freeze(VALUE _self); #endif // RUBY_PROTOBUF_MAP_H_ diff --git a/ruby/ext/google/protobuf_c/message.c b/ruby/ext/google/protobuf_c/message.c index 3b12c93f3d7af..d2bc27062cb19 100644 --- a/ruby/ext/google/protobuf_c/message.c +++ b/ruby/ext/google/protobuf_c/message.c @@ -826,22 +826,12 @@ static VALUE Message_to_h(VALUE _self) { * Freezes the message object. We have to intercept this so we can pin the * Ruby object into memory so we don't forget it's frozen. */ -static VALUE Message_freeze(VALUE _self) { +VALUE Message_freeze(VALUE _self) { Message* self = ruby_to_Message(_self); - if (!RB_OBJ_FROZEN(_self)) { - Arena_Pin(self->arena, _self); - RB_OBJ_FREEZE(_self); - } - return _self; -} -/* - * Deep freezes the message object recursively. - * Internal use only. - */ -VALUE Message_internal_deep_freeze(VALUE _self) { - Message* self = ruby_to_Message(_self); - Message_freeze(_self); + if (RB_OBJ_FROZEN(_self)) return _self; + Arena_Pin(self->arena, _self); + RB_OBJ_FREEZE(_self); int n = upb_MessageDef_FieldCount(self->msgdef); for (int i = 0; i < n; i++) { @@ -850,11 +840,11 @@ VALUE Message_internal_deep_freeze(VALUE _self) { if (field != Qnil) { if (upb_FieldDef_IsMap(f)) { - Map_internal_deep_freeze(field); + Map_freeze(field); } else if (upb_FieldDef_IsRepeated(f)) { - RepeatedField_internal_deep_freeze(field); + RepeatedField_freeze(field); } else if (upb_FieldDef_IsSubMessage(f)) { - Message_internal_deep_freeze(field); + Message_freeze(field); } } } @@ -963,7 +953,7 @@ VALUE Message_decode_bytes(int size, const char* bytes, int options, rb_raise(cParseError, "Error occurred during parsing"); } if (freeze) { - Message_internal_deep_freeze(msg_rb); + Message_freeze(msg_rb); } return msg_rb; } diff --git a/ruby/ext/google/protobuf_c/message.h b/ruby/ext/google/protobuf_c/message.h index cb6897f0d45bf..ab872be43b9e9 100644 --- a/ruby/ext/google/protobuf_c/message.h +++ b/ruby/ext/google/protobuf_c/message.h @@ -78,7 +78,7 @@ VALUE Message_decode_bytes(int size, const char* bytes, int options, VALUE klass, bool freeze); // Recursively freeze message -VALUE Message_internal_deep_freeze(VALUE _self); +VALUE Message_freeze(VALUE _self); // Call at startup to register all types in this module. void Message_register(VALUE protobuf); diff --git a/ruby/ext/google/protobuf_c/repeated_field.c b/ruby/ext/google/protobuf_c/repeated_field.c index 1960126749553..15b8abfd2a62e 100644 --- a/ruby/ext/google/protobuf_c/repeated_field.c +++ b/ruby/ext/google/protobuf_c/repeated_field.c @@ -478,29 +478,20 @@ VALUE RepeatedField_eq(VALUE _self, VALUE _other) { * Freezes the repeated field. We have to intercept this so we can pin the Ruby * object into memory so we don't forget it's frozen. */ -static VALUE RepeatedField_freeze(VALUE _self) { +VALUE RepeatedField_freeze(VALUE _self) { RepeatedField* self = ruby_to_RepeatedField(_self); - if (!RB_OBJ_FROZEN(_self)) { - Arena_Pin(self->arena, _self); - RB_OBJ_FREEZE(_self); - } - return _self; -} -/* - * Deep freezes the repeated field and values recursively. - * Internal use only. - */ -VALUE RepeatedField_internal_deep_freeze(VALUE _self) { - RepeatedField* self = ruby_to_RepeatedField(_self); - RepeatedField_freeze(_self); + if (RB_OBJ_FROZEN(_self)) return _self; + Arena_Pin(self->arena, _self); + RB_OBJ_FREEZE(_self); + if (self->type_info.type == kUpb_CType_Message) { int size = upb_Array_Size(self->array); int i; for (i = 0; i < size; i++) { upb_MessageValue msgval = upb_Array_Get(self->array, i); VALUE val = Convert_UpbToRuby(msgval, self->type_info, self->arena); - Message_internal_deep_freeze(val); + Message_freeze(val); } } return _self; diff --git a/ruby/ext/google/protobuf_c/repeated_field.h b/ruby/ext/google/protobuf_c/repeated_field.h index f3f7a50cd5870..f5d5e223cb758 100644 --- a/ruby/ext/google/protobuf_c/repeated_field.h +++ b/ruby/ext/google/protobuf_c/repeated_field.h @@ -36,6 +36,6 @@ extern VALUE cRepeatedField; void RepeatedField_register(VALUE module); // Recursively freeze RepeatedField. -VALUE RepeatedField_internal_deep_freeze(VALUE _self); +VALUE RepeatedField_freeze(VALUE _self); #endif // RUBY_PROTOBUF_REPEATED_FIELD_H_ diff --git a/ruby/lib/google/protobuf/ffi/descriptor.rb b/ruby/lib/google/protobuf/ffi/descriptor.rb index 25d226abd1d44..3eb108663a944 100644 --- a/ruby/lib/google/protobuf/ffi/descriptor.rb +++ b/ruby/lib/google/protobuf/ffi/descriptor.rb @@ -100,7 +100,7 @@ def options size_ptr = ::FFI::MemoryPointer.new(:size_t, 1) temporary_arena = Google::Protobuf::FFI.create_arena buffer = Google::Protobuf::FFI.message_options(self, size_ptr, temporary_arena) - Google::Protobuf::MessageOptions.decode(buffer.read_string_length(size_ptr.read(:size_t)).force_encoding("ASCII-8BIT").freeze).send(:internal_deep_freeze) + Google::Protobuf::MessageOptions.decode(buffer.read_string_length(size_ptr.read(:size_t)).force_encoding("ASCII-8BIT").freeze).freeze end end @@ -138,7 +138,7 @@ def self.get_message(msg, descriptor, arena) message = OBJECT_CACHE.get(msg.address) if message.nil? message = descriptor.msgclass.send(:private_constructor, arena, msg: msg) - message.send :internal_deep_freeze if frozen? + message.freeze if frozen? end message end diff --git a/ruby/lib/google/protobuf/ffi/enum_descriptor.rb b/ruby/lib/google/protobuf/ffi/enum_descriptor.rb index a1f4fefcd520d..e280e393a1ef1 100644 --- a/ruby/lib/google/protobuf/ffi/enum_descriptor.rb +++ b/ruby/lib/google/protobuf/ffi/enum_descriptor.rb @@ -84,7 +84,7 @@ def options size_ptr = ::FFI::MemoryPointer.new(:size_t, 1) temporary_arena = Google::Protobuf::FFI.create_arena buffer = Google::Protobuf::FFI.enum_options(self, size_ptr, temporary_arena) - Google::Protobuf::EnumOptions.decode(buffer.read_string_length(size_ptr.read(:size_t)).force_encoding("ASCII-8BIT").freeze).send(:internal_deep_freeze) + Google::Protobuf::EnumOptions.decode(buffer.read_string_length(size_ptr.read(:size_t)).force_encoding("ASCII-8BIT").freeze).freeze end end diff --git a/ruby/lib/google/protobuf/ffi/field_descriptor.rb b/ruby/lib/google/protobuf/ffi/field_descriptor.rb index d7c45da193d36..b15c91066738a 100644 --- a/ruby/lib/google/protobuf/ffi/field_descriptor.rb +++ b/ruby/lib/google/protobuf/ffi/field_descriptor.rb @@ -211,7 +211,7 @@ def options size_ptr = ::FFI::MemoryPointer.new(:size_t, 1) temporary_arena = Google::Protobuf::FFI.create_arena buffer = Google::Protobuf::FFI.field_options(self, size_ptr, temporary_arena) - Google::Protobuf::FieldOptions.decode(buffer.read_string_length(size_ptr.read(:size_t)).force_encoding("ASCII-8BIT").freeze).send(:internal_deep_freeze) + Google::Protobuf::FieldOptions.decode(buffer.read_string_length(size_ptr.read(:size_t)).force_encoding("ASCII-8BIT").freeze).freeze end end diff --git a/ruby/lib/google/protobuf/ffi/file_descriptor.rb b/ruby/lib/google/protobuf/ffi/file_descriptor.rb index 291ac4f3e41ad..f1da9f7385fb0 100644 --- a/ruby/lib/google/protobuf/ffi/file_descriptor.rb +++ b/ruby/lib/google/protobuf/ffi/file_descriptor.rb @@ -51,7 +51,7 @@ def options size_ptr = ::FFI::MemoryPointer.new(:size_t, 1) temporary_arena = Google::Protobuf::FFI.create_arena buffer = Google::Protobuf::FFI.file_options(@file_def, size_ptr, temporary_arena) - Google::Protobuf::FileOptions.decode(buffer.read_string_length(size_ptr.read(:size_t)).force_encoding("ASCII-8BIT").freeze).send(:internal_deep_freeze) + Google::Protobuf::FileOptions.decode(buffer.read_string_length(size_ptr.read(:size_t)).force_encoding("ASCII-8BIT").freeze).freeze end end end diff --git a/ruby/lib/google/protobuf/ffi/map.rb b/ruby/lib/google/protobuf/ffi/map.rb index 61abbe53b0bcc..90898b66a997b 100644 --- a/ruby/lib/google/protobuf/ffi/map.rb +++ b/ruby/lib/google/protobuf/ffi/map.rb @@ -155,6 +155,19 @@ def length end alias size length + def freeze + return self if frozen? + super + @arena.pin self + if value_type == :message + internal_iterator do |iterator| + value_message_value = Google::Protobuf::FFI.map_value(@map_ptr, iterator) + convert_upb_to_ruby(value_message_value, value_type, descriptor, arena).freeze + end + end + self + end + ## # call-seq: # Map.dup => new_map @@ -269,17 +282,6 @@ def each &block include Google::Protobuf::Internal::Convert - def internal_deep_freeze - freeze - if value_type == :message - internal_iterator do |iterator| - value_message_value = Google::Protobuf::FFI.map_value(@map_ptr, iterator) - convert_upb_to_ruby(value_message_value, value_type, descriptor, arena).send :internal_deep_freeze - end - end - self - end - def internal_iterator iter = ::FFI::MemoryPointer.new(:size_t, 1) iter.write(:size_t, Google::Protobuf::FFI::Upb_Map_Begin) diff --git a/ruby/lib/google/protobuf/ffi/message.rb b/ruby/lib/google/protobuf/ffi/message.rb index 5d9a36592721e..c1b9b4318e0d5 100644 --- a/ruby/lib/google/protobuf/ffi/message.rb +++ b/ruby/lib/google/protobuf/ffi/message.rb @@ -59,8 +59,15 @@ def self.new(initial_value = nil) end def freeze + return self if frozen? super @arena.pin self + self.class.descriptor.each do |field_descriptor| + next if field_descriptor.has_presence? && !Google::Protobuf::FFI.get_message_has(@msg, field_descriptor) + if field_descriptor.map? or field_descriptor.repeated? or field_descriptor.sub_message? + get_field(field_descriptor).freeze + end + end self end @@ -302,17 +309,6 @@ def self.encode_json(message, options = {}) include Google::Protobuf::Internal::Convert - def internal_deep_freeze - freeze - self.class.descriptor.each do |field_descriptor| - next if field_descriptor.has_presence? && !Google::Protobuf::FFI.get_message_has(@msg, field_descriptor) - if field_descriptor.map? or field_descriptor.repeated? or field_descriptor.sub_message? - get_field(field_descriptor).send :internal_deep_freeze - end - end - self - end - def self.setup_accessors! @descriptor.each do |field_descriptor| field_name = field_descriptor.name @@ -639,7 +635,7 @@ def get_repeated_field(array, field) repeated_field = OBJECT_CACHE.get(array.address) if repeated_field.nil? repeated_field = RepeatedField.send(:construct_for_field, field, @arena, array: array) - repeated_field.send :internal_deep_freeze if frozen? + repeated_field.freeze if frozen? end repeated_field end @@ -652,7 +648,7 @@ def get_map_field(map, field) map_field = OBJECT_CACHE.get(map.address) if map_field.nil? map_field = Google::Protobuf::Map.send(:construct_for_field, field, @arena, map: map) - map_field.send :internal_deep_freeze if frozen? + map_field.freeze if frozen? end map_field end diff --git a/ruby/lib/google/protobuf/ffi/oneof_descriptor.rb b/ruby/lib/google/protobuf/ffi/oneof_descriptor.rb index 00acc995c18dc..934f8f0ac467b 100644 --- a/ruby/lib/google/protobuf/ffi/oneof_descriptor.rb +++ b/ruby/lib/google/protobuf/ffi/oneof_descriptor.rb @@ -58,7 +58,7 @@ def options size_ptr = ::FFI::MemoryPointer.new(:size_t, 1) temporary_arena = Google::Protobuf::FFI.create_arena buffer = Google::Protobuf::FFI.oneof_options(self, size_ptr, temporary_arena) - Google::Protobuf::OneofOptions.decode(buffer.read_string_length(size_ptr.read(:size_t)).force_encoding("ASCII-8BIT").freeze).send(:internal_deep_freeze) + Google::Protobuf::OneofOptions.decode(buffer.read_string_length(size_ptr.read(:size_t)).force_encoding("ASCII-8BIT").freeze).freeze end end diff --git a/ruby/lib/google/protobuf/ffi/repeated_field.rb b/ruby/lib/google/protobuf/ffi/repeated_field.rb index ccc95ad6f425c..25d2ab3563074 100644 --- a/ruby/lib/google/protobuf/ffi/repeated_field.rb +++ b/ruby/lib/google/protobuf/ffi/repeated_field.rb @@ -174,6 +174,18 @@ def length end alias size :length + def freeze + return self if frozen? + super + @arena.pin self + if type == :message + each do |element| + element.freeze + end + end + self + end + def dup instance = self.class.allocate instance.send(:initialize, type, descriptor: descriptor, arena: arena) @@ -252,16 +264,6 @@ def concat(other) attr :name, :arena, :array, :type, :descriptor - def internal_deep_freeze - freeze - if type == :message - each do |element| - element.send :internal_deep_freeze - end - end - self - end - def internal_push(*elements) elements.each do |element| append_msg_val convert_ruby_to_upb(element, arena, type, descriptor) diff --git a/ruby/src/main/java/com/google/protobuf/jruby/RubyMap.java b/ruby/src/main/java/com/google/protobuf/jruby/RubyMap.java index f3849b1b2a353..204608d02659d 100644 --- a/ruby/src/main/java/com/google/protobuf/jruby/RubyMap.java +++ b/ruby/src/main/java/com/google/protobuf/jruby/RubyMap.java @@ -372,11 +372,15 @@ public RubyHash toHash(ThreadContext context) { return RubyHash.newHash(context.runtime, mapForHash, context.nil); } - protected IRubyObject deepFreeze(ThreadContext context) { + @JRubyMethod + public IRubyObject freeze(ThreadContext context) { + if (isFrozen()) { + return this; + } setFrozen(true); if (valueType == FieldDescriptor.Type.MESSAGE) { for (IRubyObject key : table.keySet()) { - ((RubyMessage) table.get(key)).deepFreeze(context); + ((RubyMessage) table.get(key)).freeze(context); } } return this; diff --git a/ruby/src/main/java/com/google/protobuf/jruby/RubyMessage.java b/ruby/src/main/java/com/google/protobuf/jruby/RubyMessage.java index 2ac9fc912e11e..365f23c7b2651 100644 --- a/ruby/src/main/java/com/google/protobuf/jruby/RubyMessage.java +++ b/ruby/src/main/java/com/google/protobuf/jruby/RubyMessage.java @@ -664,7 +664,7 @@ public static IRubyObject decodeBytes( }); } if (freeze) { - ret.deepFreeze(context); + ret.freeze(context); } return ret; } @@ -814,16 +814,20 @@ public IRubyObject toHash(ThreadContext context) { return ret; } - protected IRubyObject deepFreeze(ThreadContext context) { + @JRubyMethod + public IRubyObject freeze(ThreadContext context) { + if (isFrozen()) { + return this; + } setFrozen(true); for (FieldDescriptor fdef : descriptor.getFields()) { if (fdef.isMapField()) { - ((RubyMap) fields.get(fdef)).deepFreeze(context); + ((RubyMap) fields.get(fdef)).freeze(context); } else if (fdef.isRepeated()) { - this.getRepeatedField(context, fdef).deepFreeze(context); + this.getRepeatedField(context, fdef).freeze(context); } else if (fields.containsKey(fdef)) { if (fdef.getType() == FieldDescriptor.Type.MESSAGE) { - ((RubyMessage) fields.get(fdef)).deepFreeze(context); + ((RubyMessage) fields.get(fdef)).freeze(context); } } } diff --git a/ruby/src/main/java/com/google/protobuf/jruby/RubyRepeatedField.java b/ruby/src/main/java/com/google/protobuf/jruby/RubyRepeatedField.java index 085dd1cc0f53f..595afbc246d1c 100644 --- a/ruby/src/main/java/com/google/protobuf/jruby/RubyRepeatedField.java +++ b/ruby/src/main/java/com/google/protobuf/jruby/RubyRepeatedField.java @@ -358,11 +358,15 @@ public IRubyObject inspect() { return storage.inspect(); } - protected IRubyObject deepFreeze(ThreadContext context) { + @JRubyMethod + public IRubyObject freeze(ThreadContext context) { + if (isFrozen()) { + return this; + } setFrozen(true); if (fieldType == FieldDescriptor.Type.MESSAGE) { for (int i = 0; i < size(); i++) { - ((RubyMessage) storage.eltInternal(i)).deepFreeze(context); + ((RubyMessage) storage.eltInternal(i)).freeze(context); } } return this; diff --git a/ruby/tests/basic.rb b/ruby/tests/basic.rb index b71fdac4ea1e9..46e3fec49e8e5 100755 --- a/ruby/tests/basic.rb +++ b/ruby/tests/basic.rb @@ -696,15 +696,14 @@ def test_options_deep_freeze end end - def test_message_deep_freeze + def test_message_freeze message = TestDeprecatedMessage.new - omit(":internal_deep_freeze only exists under FFI") unless message.respond_to? :internal_deep_freeze, true nested_message_2 = TestMessage2.new message.map_string_msg["message"] = TestMessage2.new message.repeated_msg.push(TestMessage2.new) - message.send(:internal_deep_freeze) + message.freeze assert_raise FrozenError do message.map_string_msg["message"].foo = "bar" From 181bcee76d2639c30048746013ae5b64aad0e97a Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Thu, 4 Jan 2024 12:53:20 -0800 Subject: [PATCH 172/255] Skip or adjust tests to work with PROTOBUF_FORCE_SPLIT. PiperOrigin-RevId: 595780061 --- .../compiler/cpp/message_size_unittest.cc | 75 +++++++++++++++++++ 1 file changed, 75 insertions(+) diff --git a/src/google/protobuf/compiler/cpp/message_size_unittest.cc b/src/google/protobuf/compiler/cpp/message_size_unittest.cc index 791dbc6df8680..58c43b96c0ef7 100644 --- a/src/google/protobuf/compiler/cpp/message_size_unittest.cc +++ b/src/google/protobuf/compiler/cpp/message_size_unittest.cc @@ -102,6 +102,8 @@ TEST(GeneratedMessageTest, EmptyMessageWithExtensionsSize) { } TEST(GeneratedMessageTest, RecursiveMessageSize) { + // TODO: remove once synthetic_pdproto lands. +#ifndef PROTOBUF_FORCE_SPLIT struct MockGenerated : public MockMessageBase { // 16 bytes int has_bits[1]; // 4 bytes int cached_size; // 4 bytes @@ -111,6 +113,17 @@ TEST(GeneratedMessageTest, RecursiveMessageSize) { // + 0-4 bytes padding }; ABSL_CHECK_MESSAGE_SIZE(MockGenerated, 40); +#else // !PROTOBUF_FORCE_SPLIT + struct MockGenerated : public MockMessageBase { // 16 bytes + int has_bits[1]; // 4 bytes + int cached_size; // 4 bytes + void* split; // 8 bytes + PROTOBUF_TSAN_DECLARE_MEMBER; // 0-4 bytes + // + 0-4 bytes padding + }; + ABSL_CHECK_MESSAGE_SIZE(MockGenerated, 32); +#endif // PROTOBUF_FORCE_SPLIT + EXPECT_EQ(sizeof(protobuf_unittest::TestRecursiveMessage), sizeof(MockGenerated)); } @@ -128,6 +141,8 @@ TEST(GeneratedMessageTest, OneStringSize) { } TEST(GeneratedMessageTest, MoreStringSize) { + // TODO: remove once synthetic_pdproto lands. +#ifndef PROTOBUF_FORCE_SPLIT struct MockGenerated : public MockMessageBase { // 16 bytes int cached_size; // 4 bytes PROTOBUF_TSAN_DECLARE_MEMBER; // 0-4 bytes @@ -135,6 +150,15 @@ TEST(GeneratedMessageTest, MoreStringSize) { MockRepeatedPtrField data; // 24 bytes }; ABSL_CHECK_MESSAGE_SIZE(MockGenerated, 48); +#else // !PROTOBUF_FORCE_SPLIT + struct MockGenerated : public MockMessageBase { // 16 bytes + int cached_size; // 4 bytes + void* split; // 8 bytes + PROTOBUF_TSAN_DECLARE_MEMBER; // 0-4 bytes + // + 0-4 bytes padding + }; + ABSL_CHECK_MESSAGE_SIZE(MockGenerated, 32); +#endif // PROTOBUF_FORCE_SPLIT EXPECT_EQ(sizeof(protobuf_unittest::MoreString), sizeof(MockGenerated)); } @@ -188,6 +212,8 @@ TEST(GeneratedMessageTest, OneofSize) { } TEST(GeneratedMessageTest, Oneof2Size) { + // TODO: remove once synthetic_pdproto lands. +#ifndef PROTOBUF_FORCE_SPLIT struct MockGenerated : public MockMessageBase { // 16 bytes int has_bits[1]; // 4 bytes int cached_size; // 4 bytes @@ -201,10 +227,25 @@ TEST(GeneratedMessageTest, Oneof2Size) { uint32_t oneof_case[2]; // 8 bytes }; ABSL_CHECK_MESSAGE_SIZE(MockGenerated, 64); +#else // !PROTOBUF_FORCE_SPLIT + struct MockGenerated : public MockMessageBase { // 16 bytes + int has_bits[1]; // 4 bytes + int cached_size; // 4 bytes + PROTOBUF_TSAN_DECLARE_MEMBER; // 0-4 bytes + // + 0-4 bytes padding + void* split; // 8 bytes + void* foo; // 8 bytes + void* bar; // 8 bytes + uint32_t oneof_case[2]; // 8 bytes + }; + ABSL_CHECK_MESSAGE_SIZE(MockGenerated, 56); +#endif // PROTOBUF_FORCE_SPLIT EXPECT_EQ(sizeof(protobuf_unittest::TestOneof2), sizeof(MockGenerated)); } TEST(GeneratedMessageTest, FieldOrderingsSize) { + // TODO: remove once synthetic_pdproto lands. +#ifndef PROTOBUF_FORCE_SPLIT struct MockGenerated : public MockMessageBase { // 16 bytes int has_bits[1]; // 4 bytes int cached_size; // 4 bytes @@ -217,11 +258,24 @@ TEST(GeneratedMessageTest, FieldOrderingsSize) { // + 0-4 bytes padding }; ABSL_CHECK_MESSAGE_SIZE(MockGenerated, 80); +#else // !PROTOBUF_FORCE_SPLIT + struct MockGenerated : public MockMessageBase { // 16 bytes + int has_bits[1]; // 4 bytes + int cached_size; // 4 bytes + MockExtensionSet extensions; // 24 bytes + void* split; // 8 bytes + PROTOBUF_TSAN_DECLARE_MEMBER; // 0-4 bytes + // + 0-4 bytes padding + }; + ABSL_CHECK_MESSAGE_SIZE(MockGenerated, 56); +#endif // PROTOBUF_FORCE_SPLIT EXPECT_EQ(sizeof(protobuf_unittest::TestFieldOrderings), sizeof(MockGenerated)); } TEST(GeneratedMessageTest, TestMessageSize) { // We expect the message to contain (not in this order): + // TODO: remove once synthetic_pdproto lands. +#ifndef PROTOBUF_FORCE_SPLIT struct MockGenerated : public MockMessageBase { // 16 bytes int has_bits[1]; // 4 bytes int cached_size; // 4 bytes @@ -236,10 +290,22 @@ TEST(GeneratedMessageTest, TestMessageSize) { int64_t m6; // 8 bytes }; ABSL_CHECK_MESSAGE_SIZE(MockGenerated, 56); +#else // !PROTOBUF_FORCE_SPLIT + struct MockGenerated : public MockMessageBase { // 16 bytes + int has_bits[1]; // 4 bytes + int cached_size; // 4 bytes + void* split; // 8 bytes + PROTOBUF_TSAN_DECLARE_MEMBER; // 0-4 bytes + // + 0-4 bytes padding + }; + ABSL_CHECK_MESSAGE_SIZE(MockGenerated, 32); +#endif // PROTOBUF_FORCE_SPLIT EXPECT_EQ(sizeof(protobuf_unittest::TestMessageSize), sizeof(MockGenerated)); } TEST(GeneratedMessageTest, PackedTypesSize) { + // TODO: remove once synthetic_pdproto lands. +#ifndef PROTOBUF_FORCE_SPLIT struct MockGenerated : public MockMessageBase { // 16 bytes MockRepeatedField packed_int32; // 16 bytes int packed_int32_cached_byte_size; // 4 bytes + 4 bytes padding @@ -267,6 +333,15 @@ TEST(GeneratedMessageTest, PackedTypesSize) { // + 0-4 bytes padding }; ABSL_CHECK_MESSAGE_SIZE(MockGenerated, 16 * 15 + 8 * 6 + 8); +#else // !PROTOBUF_FORCE_SPLIT + struct MockGenerated : public MockMessageBase { // 16 bytes + int cached_size; // 4 bytes + 4 bytes padding + void* split; // 8 bytes + PROTOBUF_TSAN_DECLARE_MEMBER; // 0-4 bytes + // + 0-4 bytes padding + }; + ABSL_CHECK_MESSAGE_SIZE(MockGenerated, 32); +#endif // PROTOBUF_FORCE_SPLIT EXPECT_EQ(sizeof(protobuf_unittest::TestPackedTypes), sizeof(MockGenerated)); } From c51f1110224910015ed90d7d6fb27ff24243baa8 Mon Sep 17 00:00:00 2001 From: Jie Luo Date: Thu, 4 Jan 2024 16:27:41 -0800 Subject: [PATCH 173/255] BREAKING CHANGE in v26: Remove Deprecated APIs that add non top descriptor. Include AddFileDescriptor, AddDescriptor, AddEnumDescriptor, AddExtensionDescriptor, AddServiceDescriptor. Those Deprecated APIs may add unlinked descriptors to descriptor_pool which is is wrong. Should use Add() or AddSerializedFile() instead. Those APIs were raising deprecated warnings since 2019 PiperOrigin-RevId: 595831718 --- python/google/protobuf/descriptor_pool.py | 38 ------- .../google/protobuf/pyext/descriptor_pool.cc | 105 ------------------ 2 files changed, 143 deletions(-) diff --git a/python/google/protobuf/descriptor_pool.py b/python/google/protobuf/descriptor_pool.py index bf3476feec4eb..2bb3ceecdc651 100644 --- a/python/google/protobuf/descriptor_pool.py +++ b/python/google/protobuf/descriptor_pool.py @@ -47,22 +47,6 @@ _USE_C_DESCRIPTORS = descriptor._USE_C_DESCRIPTORS # pylint: disable=protected-access -def _Deprecated(func): - """Mark functions as deprecated.""" - - def NewFunc(*args, **kwargs): - warnings.warn( - 'Call to deprecated function %s(). Note: Do add unlinked descriptors ' - 'to descriptor_pool is wrong. Please use Add() or AddSerializedFile() ' - 'instead. This function will be removed soon.' % func.__name__, - category=DeprecationWarning) - return func(*args, **kwargs) - NewFunc.__name__ = func.__name__ - NewFunc.__doc__ = func.__doc__ - NewFunc.__dict__.update(func.__dict__) - return NewFunc - - def _NormalizeFullyQualifiedName(name): """Remove leading period from fully-qualified type name. @@ -207,12 +191,6 @@ def AddSerializedFile(self, serialized_file_desc_proto): file_desc.serialized_pb = serialized_file_desc_proto return file_desc - # Add Descriptor to descriptor pool is deprecated. Please use Add() - # or AddSerializedFile() to add a FileDescriptorProto instead. - @_Deprecated - def AddDescriptor(self, desc): - self._AddDescriptor(desc) - # Never call this method. It is for internal usage only. def _AddDescriptor(self, desc): """Adds a Descriptor to the pool, non-recursively. @@ -267,12 +245,6 @@ def _AddEnumDescriptor(self, enum_desc): self._top_enum_values[full_name] = enum_value self._AddFileDescriptor(enum_desc.file) - # Add ServiceDescriptor to descriptor pool is deprecated. Please use Add() - # or AddSerializedFile() to add a FileDescriptorProto instead. - @_Deprecated - def AddServiceDescriptor(self, service_desc): - self._AddServiceDescriptor(service_desc) - # Never call this method. It is for internal usage only. def _AddServiceDescriptor(self, service_desc): """Adds a ServiceDescriptor to the pool. @@ -288,12 +260,6 @@ def _AddServiceDescriptor(self, service_desc): service_desc.file.name) self._service_descriptors[service_desc.full_name] = service_desc - # Add ExtensionDescriptor to descriptor pool is deprecated. Please use Add() - # or AddSerializedFile() to add a FileDescriptorProto instead. - @_Deprecated - def AddExtensionDescriptor(self, extension): - self._AddExtensionDescriptor(extension) - # Never call this method. It is for internal usage only. def _AddExtensionDescriptor(self, extension): """Adds a FieldDescriptor describing an extension to the pool. @@ -343,10 +309,6 @@ def _AddExtensionDescriptor(self, extension): python_message._AttachFieldHelpers( extension.containing_type._concrete_class, extension) - @_Deprecated - def AddFileDescriptor(self, file_desc): - self._InternalAddFileDescriptor(file_desc) - # Never call this method. It is for internal usage only. def _InternalAddFileDescriptor(self, file_desc): """Adds a FileDescriptor to the pool, non-recursively. diff --git a/python/google/protobuf/pyext/descriptor_pool.cc b/python/google/protobuf/pyext/descriptor_pool.cc index 272dcb852eead..b70a95c74bcb3 100644 --- a/python/google/protobuf/pyext/descriptor_pool.cc +++ b/python/google/protobuf/pyext/descriptor_pool.cc @@ -482,100 +482,6 @@ static PyObject* FindAllExtensions(PyObject* self, PyObject* arg) { return result.release(); } -// These functions should not exist -- the only valid way to create -// descriptors is to call Add() or AddSerializedFile(). -// But these AddDescriptor() functions were created in Python and some people -// call them, so we support them for now for compatibility. -// However we do check that the existing descriptor already exists in the pool, -// which appears to always be true for existing calls -- but then why do people -// call a function that will just be a no-op? -// TODO: Need to investigate further. - -static PyObject* AddFileDescriptor(PyObject* self, PyObject* descriptor) { - const FileDescriptor* file_descriptor = - PyFileDescriptor_AsDescriptor(descriptor); - if (!file_descriptor) { - return nullptr; - } - if (file_descriptor != - reinterpret_cast(self)->pool->FindFileByName( - file_descriptor->name())) { - PyErr_Format(PyExc_ValueError, - "The file descriptor %s does not belong to this pool", - file_descriptor->name().c_str()); - return nullptr; - } - Py_RETURN_NONE; -} - -static PyObject* AddDescriptor(PyObject* self, PyObject* descriptor) { - const Descriptor* message_descriptor = - PyMessageDescriptor_AsDescriptor(descriptor); - if (!message_descriptor) { - return nullptr; - } - if (message_descriptor != - reinterpret_cast(self)->pool->FindMessageTypeByName( - message_descriptor->full_name())) { - PyErr_Format(PyExc_ValueError, - "The message descriptor %s does not belong to this pool", - message_descriptor->full_name().c_str()); - return nullptr; - } - Py_RETURN_NONE; -} - -static PyObject* AddEnumDescriptor(PyObject* self, PyObject* descriptor) { - const EnumDescriptor* enum_descriptor = - PyEnumDescriptor_AsDescriptor(descriptor); - if (!enum_descriptor) { - return nullptr; - } - if (enum_descriptor != - reinterpret_cast(self)->pool->FindEnumTypeByName( - enum_descriptor->full_name())) { - PyErr_Format(PyExc_ValueError, - "The enum descriptor %s does not belong to this pool", - enum_descriptor->full_name().c_str()); - return nullptr; - } - Py_RETURN_NONE; -} - -static PyObject* AddExtensionDescriptor(PyObject* self, PyObject* descriptor) { - const FieldDescriptor* extension_descriptor = - PyFieldDescriptor_AsDescriptor(descriptor); - if (!extension_descriptor) { - return nullptr; - } - if (extension_descriptor != - reinterpret_cast(self)->pool->FindExtensionByName( - extension_descriptor->full_name())) { - PyErr_Format(PyExc_ValueError, - "The extension descriptor %s does not belong to this pool", - extension_descriptor->full_name().c_str()); - return nullptr; - } - Py_RETURN_NONE; -} - -static PyObject* AddServiceDescriptor(PyObject* self, PyObject* descriptor) { - const ServiceDescriptor* service_descriptor = - PyServiceDescriptor_AsDescriptor(descriptor); - if (!service_descriptor) { - return nullptr; - } - if (service_descriptor != - reinterpret_cast(self)->pool->FindServiceByName( - service_descriptor->full_name())) { - PyErr_Format(PyExc_ValueError, - "The service descriptor %s does not belong to this pool", - service_descriptor->full_name().c_str()); - return nullptr; - } - Py_RETURN_NONE; -} - // The code below loads new Descriptors from a serialized FileDescriptorProto. static PyObject* AddSerializedFile(PyObject* pself, PyObject* serialized_pb) { PyDescriptorPool* self = reinterpret_cast(pself); @@ -689,17 +595,6 @@ static PyMethodDef Methods[] = { {"SetFeatureSetDefaults", SetFeatureSetDefaults, METH_O, "Sets the default feature mappings used during the build."}, - {"AddFileDescriptor", AddFileDescriptor, METH_O, - "No-op. Add() must have been called before."}, - {"AddDescriptor", AddDescriptor, METH_O, - "No-op. Add() must have been called before."}, - {"AddEnumDescriptor", AddEnumDescriptor, METH_O, - "No-op. Add() must have been called before."}, - {"AddExtensionDescriptor", AddExtensionDescriptor, METH_O, - "No-op. Add() must have been called before."}, - {"AddServiceDescriptor", AddServiceDescriptor, METH_O, - "No-op. Add() must have been called before."}, - {"FindFileByName", FindFileByName, METH_O, "Searches for a file descriptor by its .proto name."}, {"FindMessageTypeByName", FindMessageByName, METH_O, From 1658213ba84a641531948aa9cdc3b53bebf20190 Mon Sep 17 00:00:00 2001 From: Jie Luo Date: Thu, 4 Jan 2024 17:09:55 -0800 Subject: [PATCH 174/255] BREAKING CHANGE in v26: Reject extend repeated field with none iterable (Raise TypeError) For example m.repeated_int32.extend(None) will be rejected PiperOrigin-RevId: 595840357 --- python/google/protobuf/internal/containers.py | 12 +----------- .../google/protobuf/internal/message_test.py | 18 ++++++++++++++++++ .../pyext/repeated_scalar_container.cc | 14 -------------- 3 files changed, 19 insertions(+), 25 deletions(-) diff --git a/python/google/protobuf/internal/containers.py b/python/google/protobuf/internal/containers.py index 20c6d982fbaa9..23357816f63a6 100755 --- a/python/google/protobuf/internal/containers.py +++ b/python/google/protobuf/internal/containers.py @@ -136,17 +136,7 @@ def insert(self, key: int, value: _T) -> None: def extend(self, elem_seq: Iterable[_T]) -> None: """Extends by appending the given iterable. Similar to list.extend().""" -# TODO: Change OSS to raise error too - if elem_seq is None: - return - try: - elem_seq_iter = iter(elem_seq) - except TypeError: - if not elem_seq: - warnings.warn('Value is not iterable. Please remove the wrong ' - 'usage. This will be changed to raise TypeError soon.') - return - raise + elem_seq_iter = iter(elem_seq) new_values = [self._type_checker.CheckValue(elem) for elem in elem_seq_iter] if new_values: self._values.extend(new_values) diff --git a/python/google/protobuf/internal/message_test.py b/python/google/protobuf/internal/message_test.py index a6223c2a7edf1..85ecacefa2dbc 100755 --- a/python/google/protobuf/internal/message_test.py +++ b/python/google/protobuf/internal/message_test.py @@ -1012,6 +1012,12 @@ def testExtendInt32WithNothing(self, message_module): m = message_module.TestAllTypes() self.assertSequenceEqual([], m.repeated_int32) + for falsy_value in MessageTest.FALSY_VALUES: + with self.assertRaises(TypeError) as context: + m.repeated_int32.extend(falsy_value) + self.assertIn('iterable', str(context.exception)) + self.assertSequenceEqual([], m.repeated_int32) + for empty_value in MessageTest.EMPTY_VALUES: m.repeated_int32.extend(empty_value) self.assertSequenceEqual([], m.repeated_int32) @@ -1021,6 +1027,12 @@ def testExtendFloatWithNothing(self, message_module): m = message_module.TestAllTypes() self.assertSequenceEqual([], m.repeated_float) + for falsy_value in MessageTest.FALSY_VALUES: + with self.assertRaises(TypeError) as context: + m.repeated_float.extend(falsy_value) + self.assertIn('iterable', str(context.exception)) + self.assertSequenceEqual([], m.repeated_float) + for empty_value in MessageTest.EMPTY_VALUES: m.repeated_float.extend(empty_value) self.assertSequenceEqual([], m.repeated_float) @@ -1030,6 +1042,12 @@ def testExtendStringWithNothing(self, message_module): m = message_module.TestAllTypes() self.assertSequenceEqual([], m.repeated_string) + for falsy_value in MessageTest.FALSY_VALUES: + with self.assertRaises(TypeError) as context: + m.repeated_string.extend(falsy_value) + self.assertIn('iterable', str(context.exception)) + self.assertSequenceEqual([], m.repeated_string) + for empty_value in MessageTest.EMPTY_VALUES: m.repeated_string.extend(empty_value) self.assertSequenceEqual([], m.repeated_string) diff --git a/python/google/protobuf/pyext/repeated_scalar_container.cc b/python/google/protobuf/pyext/repeated_scalar_container.cc index cd8654eb8dda5..92724c5caab7f 100644 --- a/python/google/protobuf/pyext/repeated_scalar_container.cc +++ b/python/google/protobuf/pyext/repeated_scalar_container.cc @@ -443,20 +443,6 @@ static int AssSubscript(PyObject* pself, PyObject* slice, PyObject* value) { PyObject* Extend(RepeatedScalarContainer* self, PyObject* value) { cmessage::AssureWritable(self->parent); - // TODO: Remove this in OSS - if (value == Py_None) { - PyErr_Warn(nullptr, - "Value is not iterable. Please remove the wrong usage." - " This will be changed to raise TypeError soon."); - Py_RETURN_NONE; - } - if ((Py_TYPE(value)->tp_as_sequence == nullptr) && PyObject_Not(value)) { - PyErr_Warn(nullptr, - "Value is not iterable. Please remove the wrong usage." - " This will be changed to raise TypeError soon."); - Py_RETURN_NONE; - } - ScopedPyObjectPtr iter(PyObject_GetIter(value)); if (iter == nullptr) { PyErr_SetString(PyExc_TypeError, "Value must be iterable"); From f92ad8f1c96b69f472ecabd6622dc3b86fd9a8a6 Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Thu, 4 Jan 2024 17:17:21 -0800 Subject: [PATCH 175/255] Automated Code Change PiperOrigin-RevId: 595841965 --- upb/message/test.proto | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/upb/message/test.proto b/upb/message/test.proto index da72ac365109b..a7d1fe3d0a052 100644 --- a/upb/message/test.proto +++ b/upb/message/test.proto @@ -14,7 +14,8 @@ package upb_test; import "google/protobuf/test_messages_proto3.proto"; message TestExtensions { - extensions 1000 to max; + extensions 1000 to max + [verification = UNVERIFIED]; extend TestExtensions { optional int32 optional_int32_ext = 1000; } @@ -33,7 +34,8 @@ extend TestExtensions { message TestMessageSet { option message_set_wire_format = true; - extensions 4 to max; + extensions 4 to max + [verification = UNVERIFIED]; } message MessageSetMember { From e04d731457dd61ded5b77d53467cf8de9236ae19 Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Thu, 4 Jan 2024 17:21:06 -0800 Subject: [PATCH 176/255] Automated Code Change PiperOrigin-RevId: 595842708 --- .../protobuf/compiler/cpp/test_bad_identifiers.proto | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/google/protobuf/compiler/cpp/test_bad_identifiers.proto b/src/google/protobuf/compiler/cpp/test_bad_identifiers.proto index b339ec0f61e84..6bd6016e78be9 100644 --- a/src/google/protobuf/compiler/cpp/test_bad_identifiers.proto +++ b/src/google/protobuf/compiler/cpp/test_bad_identifiers.proto @@ -120,13 +120,14 @@ message TestConflictingSymbolNames { // For clashing local variables in Serialize and ByteSize calculation. optional string target = 38; - extensions 1000 to max; // NO_PROTO3 + extensions 1000 to max + [verification = UNVERIFIED]; // NO_PROTO3 } message TestConflictingSymbolNamesExtension { // NO_PROTO3 extend TestConflictingSymbolNames { // NO_PROTO3 repeated int32 repeated_int32_ext = 20423638 [packed = true]; // NO_PROTO3 - } // NO_PROTO3 + } // NO_PROTO3 } // NO_PROTO3 message TestConflictingEnumNames { // NO_PROTO3 @@ -137,7 +138,7 @@ message TestConflictingEnumNames { // NO_PROTO3 int = 3; // NO_PROTO3 typedef = 4; // NO_PROTO3 XOR = 5; // NO_PROTO3 - } // NO_PROTO3 + } // NO_PROTO3 optional while conflicting_enum = 1; // NO_PROTO3 } // NO_PROTO3 From 13b97e1609f60e3c0d4bd3fc8f228c12a89915cb Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Thu, 4 Jan 2024 17:25:04 -0800 Subject: [PATCH 177/255] Automated Code Change PiperOrigin-RevId: 595843517 --- protos_generator/tests/test_model.proto | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/protos_generator/tests/test_model.proto b/protos_generator/tests/test_model.proto index a84c37a983927..24b4406e958c0 100644 --- a/protos_generator/tests/test_model.proto +++ b/protos_generator/tests/test_model.proto @@ -100,7 +100,8 @@ message TestModel { optional string doc_id = 241; optional bool set_doc_id = 242; - extensions 10000 to max; + extensions 10000 to max + [verification = UNVERIFIED]; } // Old version with fewer fields to test backward/forward compatibility. @@ -146,7 +147,8 @@ extend TestModel { } message TestAnnotation { - extensions 10000 to max; + extensions 10000 to max + [verification = UNVERIFIED]; } message TestMessageHasEnum { From 7bbc0b653610b2a18ac95e13c1838c81fe6253a8 Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Thu, 4 Jan 2024 17:36:05 -0800 Subject: [PATCH 178/255] Automated Code Change PiperOrigin-RevId: 595845776 --- .../compiler/java/message_serialization_unittest.proto | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/google/protobuf/compiler/java/message_serialization_unittest.proto b/src/google/protobuf/compiler/java/message_serialization_unittest.proto index acd3848f1f9e0..33408e0300674 100644 --- a/src/google/protobuf/compiler/java/message_serialization_unittest.proto +++ b/src/google/protobuf/compiler/java/message_serialization_unittest.proto @@ -16,18 +16,18 @@ option java_package = ""; // be serialized using a single ExtensionWriter#writeUntil call. message TestMessageWithManyExtensionRanges { // First extension range: ends at field number 3 (exclusive) - extensions 1 to 2; + extensions 1 to 2 [verification = UNVERIFIED]; int32 foo = 3; int32 bar = 5; // Second extension range: ends at field number 13 (exclusive) - extensions 6; - extensions 8; - extensions 10 to 12; + extensions 6 [verification = UNVERIFIED]; + extensions 8 [verification = UNVERIFIED]; + extensions 10 to 12 [verification = UNVERIFIED]; int32 baz = 23; // Third extension range: ends at field number 43 (exclusive) - extensions 42; + extensions 42 [verification = UNVERIFIED]; } From 4ebba684c791416a9131dd01d4c5175a2beb3566 Mon Sep 17 00:00:00 2001 From: Jie Luo Date: Fri, 5 Jan 2024 07:22:32 -0800 Subject: [PATCH 179/255] BREAKING CHANGE in v26: Remove RegisterExtension in message class PiperOrigin-RevId: 595989309 --- .../protobuf/internal/python_message.py | 9 ------ python/google/protobuf/message.py | 5 ---- python/google/protobuf/pyext/message.cc | 28 ------------------- python/google/protobuf/pyext/message.h | 4 --- 4 files changed, 46 deletions(-) diff --git a/python/google/protobuf/internal/python_message.py b/python/google/protobuf/internal/python_message.py index 870ff185f09b8..e9e5cd5e40ebc 100755 --- a/python/google/protobuf/internal/python_message.py +++ b/python/google/protobuf/internal/python_message.py @@ -779,15 +779,6 @@ def _AddPropertiesForExtensions(descriptor, cls): pool = descriptor.file.pool def _AddStaticMethods(cls): - # TODO: This probably needs to be thread-safe(?) - def RegisterExtension(field_descriptor): - field_descriptor.containing_type = cls.DESCRIPTOR - # TODO: Use cls.MESSAGE_FACTORY.pool when available. - # pylint: disable=protected-access - cls.DESCRIPTOR.file.pool._AddExtensionDescriptor(field_descriptor) - _AttachFieldHelpers(cls, field_descriptor) - cls.RegisterExtension = staticmethod(RegisterExtension) - def FromString(s): message = cls() message.MergeFromString(s) diff --git a/python/google/protobuf/message.py b/python/google/protobuf/message.py index 29ebd7b0e2e7c..3226b6e776cef 100755 --- a/python/google/protobuf/message.py +++ b/python/google/protobuf/message.py @@ -340,11 +340,6 @@ def ByteSize(self): def FromString(cls, s): raise NotImplementedError -# TODO: Remove it in OSS - @staticmethod - def RegisterExtension(field_descriptor): - raise NotImplementedError - def _SetListener(self, message_listener): """Internal method used by the protocol message implementation. Clients should not call this directly. diff --git a/python/google/protobuf/pyext/message.cc b/python/google/protobuf/pyext/message.cc index 7e01f64ae8781..42bb20da042da 100644 --- a/python/google/protobuf/pyext/message.cc +++ b/python/google/protobuf/pyext/message.cc @@ -1855,32 +1855,6 @@ static PyObject* ByteSize(CMessage* self, PyObject* args) { return PyLong_FromLong(self->message->ByteSizeLong()); } -PyObject* RegisterExtension(PyObject* cls, PyObject* extension_handle) { - const FieldDescriptor* descriptor = - GetExtensionDescriptor(extension_handle); - if (descriptor == nullptr) { - return nullptr; - } - if (!PyObject_TypeCheck(cls, CMessageClass_Type)) { - PyErr_Format(PyExc_TypeError, "Expected a message class, got %s", - cls->ob_type->tp_name); - return nullptr; - } - CMessageClass *message_class = reinterpret_cast(cls); - if (message_class == nullptr) { - return nullptr; - } - // If the extension was already registered, check that it is the same. - const FieldDescriptor* existing_extension = - message_class->py_message_factory->pool->pool->FindExtensionByNumber( - descriptor->containing_type(), descriptor->number()); - if (existing_extension != nullptr && existing_extension != descriptor) { - PyErr_SetString(PyExc_ValueError, "Double registration of Extensions"); - return nullptr; - } - Py_RETURN_NONE; -} - static PyObject* SetInParent(CMessage* self, PyObject* args) { AssureWritable(self); Py_RETURN_NONE; @@ -2391,8 +2365,6 @@ static PyMethodDef Methods[] = { "Merges a serialized message into the current message."}, {"ParseFromString", (PyCFunction)ParseFromString, METH_O, "Parses a serialized message into the current message."}, - {"RegisterExtension", (PyCFunction)RegisterExtension, METH_O | METH_CLASS, - "Registers an extension with the current message."}, {"SerializePartialToString", (PyCFunction)SerializePartialToString, METH_VARARGS | METH_KEYWORDS, "Serializes the message to a string, even if it isn't initialized."}, diff --git a/python/google/protobuf/pyext/message.h b/python/google/protobuf/pyext/message.h index 3d1336b860bdf..dc5018227a296 100644 --- a/python/google/protobuf/pyext/message.h +++ b/python/google/protobuf/pyext/message.h @@ -229,10 +229,6 @@ int InitAttributes(CMessage* self, PyObject* args, PyObject* kwargs); PyObject* MergeFrom(CMessage* self, PyObject* arg); -// This method does not do anything beyond checking that no other extension -// has been registered with the same field number on this class. -PyObject* RegisterExtension(PyObject* cls, PyObject* extension_handle); - // Get a field from a message. PyObject* GetFieldValue(CMessage* self, const FieldDescriptor* field_descriptor); From 0555d64af05ef653e740b1aec3eee18ab2e41356 Mon Sep 17 00:00:00 2001 From: Bastien Jacot-Guillarmod Date: Fri, 5 Jan 2024 07:55:48 -0800 Subject: [PATCH 180/255] Internal PiperOrigin-RevId: 595994998 --- rust/test/shared/matchers.rs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/rust/test/shared/matchers.rs b/rust/test/shared/matchers.rs index f89f1dd6c33d7..70bea18464b01 100644 --- a/rust/test/shared/matchers.rs +++ b/rust/test/shared/matchers.rs @@ -1,3 +1,4 @@ +use googletest::description::Description; use googletest::matcher::MatcherResult; use googletest::prelude::*; use protobuf::{AbsentField, Optional, PresentField, ProxiedWithPresence}; @@ -22,10 +23,10 @@ impl<'a, T: std::fmt::Debug + ProxiedWithPresence + ?Sized> Matcher for UnsetMat actual.is_unset().into() } - fn describe(&self, matcher_result: MatcherResult) -> String { + fn describe(&self, matcher_result: MatcherResult) -> Description { match matcher_result { - MatcherResult::Match => "is not set".to_string(), - MatcherResult::NoMatch => "is set".to_string(), + MatcherResult::Match => "is not set".into(), + MatcherResult::NoMatch => "is set".into(), } } } @@ -49,10 +50,10 @@ impl<'a, T: std::fmt::Debug + ProxiedWithPresence + ?Sized> Matcher for SetMatch actual.is_set().into() } - fn describe(&self, matcher_result: MatcherResult) -> String { + fn describe(&self, matcher_result: MatcherResult) -> Description { match matcher_result { - MatcherResult::Match => "is set".to_string(), - MatcherResult::NoMatch => "is not set".to_string(), + MatcherResult::Match => "is set".into(), + MatcherResult::NoMatch => "is not set".into(), } } } From 42ecd61b3e15430bb393b467bb39520025efdc63 Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Fri, 5 Jan 2024 08:11:06 -0800 Subject: [PATCH 181/255] Extend Proto2 JSON test cases to cover more of the preexisting Proto3 JSON cases. PiperOrigin-RevId: 595998208 --- conformance/binary_json_conformance_suite.cc | 175 +++++++++---------- conformance/binary_json_conformance_suite.h | 1 + conformance/failure_list_cpp.txt | 44 +++++ conformance/failure_list_java.txt | 33 ++++ conformance/failure_list_python.txt | 6 + conformance/failure_list_python_cpp.txt | 6 + conformance/failure_list_python_upb.txt | 6 + 7 files changed, 183 insertions(+), 88 deletions(-) diff --git a/conformance/binary_json_conformance_suite.cc b/conformance/binary_json_conformance_suite.cc index 4270dfee0ebdd..9a66baebdf9e0 100644 --- a/conformance/binary_json_conformance_suite.cc +++ b/conformance/binary_json_conformance_suite.cc @@ -1671,79 +1671,69 @@ void BinaryAndJsonConformanceSuiteImpl:: template void BinaryAndJsonConformanceSuiteImpl::RunJsonTests() { - if (!run_proto3_tests_) { - RunValidJsonTestWithValidator( - "StoresDefaultPrimitive", REQUIRED, - R"({ - "FieldName13": 0 - })", - [](const Json::Value& value) { return value.isMember("FieldName13"); }); - std::vector extensions; - MessageType::GetDescriptor()->file()->pool()->FindAllExtensions( - MessageType::GetDescriptor(), &extensions); - RunValidJsonTestWithValidator("FieldNameExtension", RECOMMENDED, - absl::Substitute(R"({ - "[$0]": 1 - })", - extensions[0]->full_name()), - [&](const Json::Value& value) { - return value.isMember(absl::StrCat( - "[", extensions[0]->full_name(), "]")); - }); - return; - } RunValidJsonTest("HelloWorld", REQUIRED, "{\"optionalString\":\"Hello, World!\"}", "optional_string: 'Hello, World!'"); // NOTE: The spec for JSON support is still being sorted out, these may not // all be correct. - RunJsonTestsForFieldNameConvention(); RunJsonTestsForNonRepeatedTypes(); RunJsonTestsForRepeatedTypes(); RunJsonTestsForNullTypes(); - RunJsonTestsForWrapperTypes(); - RunJsonTestsForFieldMask(); - RunJsonTestsForStruct(); - RunJsonTestsForValue(); - RunJsonTestsForAny(); + + if (run_proto3_tests_) { + RunJsonTestsForWrapperTypes(); + RunJsonTestsForFieldMask(); + RunJsonTestsForStruct(); + RunJsonTestsForValue(); + RunJsonTestsForAny(); + } else { + // Currently Proto2 only, but should also be run on Proto3-optional. + RunJsonTestsForStoresDefaultPrimitive(); + } + RunJsonTestsForUnknownEnumStringValues(); RunValidJsonIgnoreUnknownTest("IgnoreUnknownJsonNumber", REQUIRED, - R"({ - "unknown": 1 - })", - ""); + R"({"unknown": 1})", ""); RunValidJsonIgnoreUnknownTest("IgnoreUnknownJsonString", REQUIRED, - R"({ - "unknown": "a" - })", - ""); + R"({"unknown": "a"})", ""); RunValidJsonIgnoreUnknownTest("IgnoreUnknownJsonTrue", REQUIRED, - R"({ - "unknown": true - })", - ""); + R"({"unknown": true})", ""); RunValidJsonIgnoreUnknownTest("IgnoreUnknownJsonFalse", REQUIRED, - R"({ - "unknown": false - })", - ""); + R"({"unknown": false})", ""); RunValidJsonIgnoreUnknownTest("IgnoreUnknownJsonNull", REQUIRED, - R"({ - "unknown": null - })", - ""); + R"({"unknown": null})", ""); RunValidJsonIgnoreUnknownTest("IgnoreUnknownJsonObject", REQUIRED, - R"({ - "unknown": {"a": 1} - })", - ""); + R"({"unknown": {"a": 1}})", ""); ExpectParseFailureForJson("RejectTopLevelNull", REQUIRED, "null"); } +template +void BinaryAndJsonConformanceSuiteImpl< + MessageType>::RunJsonTestsForStoresDefaultPrimitive() { + RunValidJsonTestWithValidator( + "StoresDefaultPrimitive", REQUIRED, + R"({ + "FieldName13": 0 + })", + [](const Json::Value& value) { return value.isMember("FieldName13"); }); + std::vector extensions; + MessageType::GetDescriptor()->file()->pool()->FindAllExtensions( + MessageType::GetDescriptor(), &extensions); + RunValidJsonTestWithValidator("FieldNameExtension", RECOMMENDED, + absl::Substitute(R"({ + "[$0]": 1 + })", + extensions[0]->full_name()), + [&](const Json::Value& value) { + return value.isMember(absl::StrCat( + "[", extensions[0]->full_name(), "]")); + }); +} + template void BinaryAndJsonConformanceSuiteImpl< MessageType>::RunJsonTestsForUnknownEnumStringValues() { @@ -2009,12 +1999,14 @@ void BinaryAndJsonConformanceSuiteImpl< value.isMember("fieldName15") && value.isMember("fieldName16") && value.isMember("fieldName17") && value.isMember("FieldName18"); }); - RunValidJsonTestWithValidator( - "SkipsDefaultPrimitive", REQUIRED, - R"({ - "FieldName13": 0 - })", - [](const Json::Value& value) { return !value.isMember("FieldName13"); }); + + if (run_proto3_tests_) { + RunValidJsonTestWithValidator("SkipsDefaultPrimitive", REQUIRED, + R"({"FieldName13": 0})", + [](const Json::Value& value) { + return !value.isMember("FieldName13"); + }); + } } template @@ -2271,19 +2263,23 @@ void BinaryAndJsonConformanceSuiteImpl< // Enum fields. RunValidJsonTest("EnumField", REQUIRED, R"({"optionalNestedEnum": "FOO"})", "optional_nested_enum: FOO"); + // Enum fields with alias - RunValidJsonTest("EnumFieldWithAlias", REQUIRED, - R"({"optionalAliasedEnum": "ALIAS_BAZ"})", - "optional_aliased_enum: ALIAS_BAZ"); - RunValidJsonTest("EnumFieldWithAliasUseAlias", REQUIRED, - R"({"optionalAliasedEnum": "MOO"})", - "optional_aliased_enum: ALIAS_BAZ"); - RunValidJsonTest("EnumFieldWithAliasLowerCase", REQUIRED, - R"({"optionalAliasedEnum": "moo"})", - "optional_aliased_enum: ALIAS_BAZ"); - RunValidJsonTest("EnumFieldWithAliasDifferentCase", REQUIRED, - R"({"optionalAliasedEnum": "bAz"})", - "optional_aliased_enum: ALIAS_BAZ"); + if (run_proto3_tests_) { + RunValidJsonTest("EnumFieldWithAlias", REQUIRED, + R"({"optionalAliasedEnum": "ALIAS_BAZ"})", + "optional_aliased_enum: ALIAS_BAZ"); + RunValidJsonTest("EnumFieldWithAliasUseAlias", REQUIRED, + R"({"optionalAliasedEnum": "MOO"})", + "optional_aliased_enum: ALIAS_BAZ"); + RunValidJsonTest("EnumFieldWithAliasLowerCase", REQUIRED, + R"({"optionalAliasedEnum": "moo"})", + "optional_aliased_enum: ALIAS_BAZ"); + RunValidJsonTest("EnumFieldWithAliasDifferentCase", REQUIRED, + R"({"optionalAliasedEnum": "bAz"})", + "optional_aliased_enum: ALIAS_BAZ"); + } + // Enum values must be represented as strings. ExpectParseFailureForJson("EnumFieldNotQuoted", REQUIRED, R"({"optionalNestedEnum": FOO})"); @@ -2292,13 +2288,16 @@ void BinaryAndJsonConformanceSuiteImpl< R"({"optionalNestedEnum": 0})", "optional_nested_enum: FOO"); RunValidJsonTest("EnumFieldNumericValueNonZero", REQUIRED, R"({"optionalNestedEnum": 1})", "optional_nested_enum: BAR"); - // Unknown enum values are represented as numeric values. - RunValidJsonTestWithValidator( - "EnumFieldUnknownValue", REQUIRED, R"({"optionalNestedEnum": 123})", - [](const Json::Value& value) { - return value["optionalNestedEnum"].type() == Json::intValue && - value["optionalNestedEnum"].asInt() == 123; - }); + + if (run_proto3_tests_) { + // Unknown enum values are represented as numeric values. + RunValidJsonTestWithValidator( + "EnumFieldUnknownValue", REQUIRED, R"({"optionalNestedEnum": 123})", + [](const Json::Value& value) { + return value["optionalNestedEnum"].type() == Json::intValue && + value["optionalNestedEnum"].asInt() == 123; + }); + } // String fields. RunValidJsonTest("StringField", REQUIRED, @@ -3000,18 +2999,18 @@ void BinaryAndJsonConformanceSuiteImpl::RunJsonTestsForValue() { } ] )"); - RunValidJsonTestWithValidator( - "NullValueInOtherOneofOldFormat", RECOMMENDED, - R"({"oneofNullValue": "NULL_VALUE"})", [](const Json::Value& value) { - return (value.isMember("oneofNullValue") && - value["oneofNullValue"].isNull()); - }); - RunValidJsonTestWithValidator( - "NullValueInOtherOneofNewFormat", RECOMMENDED, - R"({"oneofNullValue": null})", [](const Json::Value& value) { - return (value.isMember("oneofNullValue") && - value["oneofNullValue"].isNull()); - }); + RunValidJsonTestWithValidator("NullValueInOtherOneofOldFormat", RECOMMENDED, + R"({"oneofNullValue": "NULL_VALUE"})", + [](const Json::Value& value) { + return (value.isMember("oneofNullValue") && + value["oneofNullValue"].isNull()); + }); + RunValidJsonTestWithValidator("NullValueInOtherOneofNewFormat", RECOMMENDED, + R"({"oneofNullValue": null})", + [](const Json::Value& value) { + return (value.isMember("oneofNullValue") && + value["oneofNullValue"].isNull()); + }); RunValidJsonTestWithValidator( "NullValueInNormalMessage", RECOMMENDED, R"({"optionalNullValue": null})", [](const Json::Value& value) { return value.empty(); }); diff --git a/conformance/binary_json_conformance_suite.h b/conformance/binary_json_conformance_suite.h index d777bba019782..310071a978f63 100644 --- a/conformance/binary_json_conformance_suite.h +++ b/conformance/binary_json_conformance_suite.h @@ -63,6 +63,7 @@ class BinaryAndJsonConformanceSuiteImpl { void RunBinaryPerformanceTests(); void RunJsonPerformanceTests(); void RunJsonTests(); + void RunJsonTestsForStoresDefaultPrimitive(); void RunJsonTestsForFieldNameConvention(); void RunJsonTestsForNonRepeatedTypes(); void RunJsonTestsForRepeatedTypes(); diff --git a/conformance/failure_list_cpp.txt b/conformance/failure_list_cpp.txt index 235ae697b8513..785ebc92a2681 100644 --- a/conformance/failure_list_cpp.txt +++ b/conformance/failure_list_cpp.txt @@ -61,3 +61,47 @@ Recommended.Proto3.JsonInput.TrailingCommaInAnObjectWithSpaceCommaSpace Recommended.Editions_Proto3.JsonInput.TrailingCommaInAnObjectWithSpaceCommaSpace Recommended.Proto2.JsonInput.FieldNameExtension.Validator Recommended.Editions_Proto2.JsonInput.FieldNameExtension.Validator +Recommended.Editions_Proto2.JsonInput.BoolFieldDoubleQuotedFalse +Recommended.Editions_Proto2.JsonInput.BoolFieldDoubleQuotedTrue +Recommended.Editions_Proto2.JsonInput.FieldNameDuplicate +Recommended.Editions_Proto2.JsonInput.FieldNameDuplicateDifferentCasing1 +Recommended.Editions_Proto2.JsonInput.FieldNameDuplicateDifferentCasing2 +Recommended.Editions_Proto2.JsonInput.FieldNameNotQuoted +Recommended.Editions_Proto2.JsonInput.IgnoreUnknownEnumStringValueInMapValue.ProtobufOutput +Recommended.Editions_Proto2.JsonInput.MapFieldValueIsNull +Recommended.Editions_Proto2.JsonInput.RepeatedFieldMessageElementIsNull +Recommended.Editions_Proto2.JsonInput.RepeatedFieldPrimitiveElementIsNull +Recommended.Editions_Proto2.JsonInput.RepeatedFieldTrailingComma +Recommended.Editions_Proto2.JsonInput.RepeatedFieldTrailingCommaWithNewlines +Recommended.Editions_Proto2.JsonInput.RepeatedFieldTrailingCommaWithSpace +Recommended.Editions_Proto2.JsonInput.RepeatedFieldTrailingCommaWithSpaceCommaSpace +Recommended.Editions_Proto2.JsonInput.StringFieldSingleQuoteBoth +Recommended.Editions_Proto2.JsonInput.StringFieldSingleQuoteKey +Recommended.Editions_Proto2.JsonInput.StringFieldSingleQuoteValue +Recommended.Editions_Proto2.JsonInput.StringFieldUppercaseEscapeLetter +Recommended.Editions_Proto2.JsonInput.TrailingCommaInAnObject +Recommended.Editions_Proto2.JsonInput.TrailingCommaInAnObjectWithNewlines +Recommended.Editions_Proto2.JsonInput.TrailingCommaInAnObjectWithSpace +Recommended.Editions_Proto2.JsonInput.TrailingCommaInAnObjectWithSpaceCommaSpace +Recommended.Proto2.JsonInput.BoolFieldDoubleQuotedFalse +Recommended.Proto2.JsonInput.BoolFieldDoubleQuotedTrue +Recommended.Proto2.JsonInput.FieldNameDuplicate +Recommended.Proto2.JsonInput.FieldNameDuplicateDifferentCasing1 +Recommended.Proto2.JsonInput.FieldNameDuplicateDifferentCasing2 +Recommended.Proto2.JsonInput.FieldNameNotQuoted +Recommended.Proto2.JsonInput.IgnoreUnknownEnumStringValueInMapValue.ProtobufOutput +Recommended.Proto2.JsonInput.MapFieldValueIsNull +Recommended.Proto2.JsonInput.RepeatedFieldMessageElementIsNull +Recommended.Proto2.JsonInput.RepeatedFieldPrimitiveElementIsNull +Recommended.Proto2.JsonInput.RepeatedFieldTrailingComma +Recommended.Proto2.JsonInput.RepeatedFieldTrailingCommaWithNewlines +Recommended.Proto2.JsonInput.RepeatedFieldTrailingCommaWithSpace +Recommended.Proto2.JsonInput.RepeatedFieldTrailingCommaWithSpaceCommaSpace +Recommended.Proto2.JsonInput.StringFieldSingleQuoteBoth +Recommended.Proto2.JsonInput.StringFieldSingleQuoteKey +Recommended.Proto2.JsonInput.StringFieldSingleQuoteValue +Recommended.Proto2.JsonInput.StringFieldUppercaseEscapeLetter +Recommended.Proto2.JsonInput.TrailingCommaInAnObject +Recommended.Proto2.JsonInput.TrailingCommaInAnObjectWithNewlines +Recommended.Proto2.JsonInput.TrailingCommaInAnObjectWithSpace +Recommended.Proto2.JsonInput.TrailingCommaInAnObjectWithSpaceCommaSpace \ No newline at end of file diff --git a/conformance/failure_list_java.txt b/conformance/failure_list_java.txt index 8508abd31d965..489fedce0f07b 100644 --- a/conformance/failure_list_java.txt +++ b/conformance/failure_list_java.txt @@ -42,3 +42,36 @@ Required.Proto3.JsonInput.Int32FieldPlusSign Required.Proto3.JsonInput.RepeatedFieldWrongElementTypeExpectingStringsGotBool Required.Proto3.JsonInput.RepeatedFieldWrongElementTypeExpectingStringsGotInt Required.Proto3.JsonInput.StringFieldNotAString +Recommended.Proto2.JsonInput.BoolFieldAllCapitalFalse +Recommended.Proto2.JsonInput.BoolFieldAllCapitalTrue +Recommended.Proto2.JsonInput.BoolFieldCamelCaseFalse +Recommended.Proto2.JsonInput.BoolFieldCamelCaseTrue +Recommended.Proto2.JsonInput.BoolFieldDoubleQuotedFalse +Recommended.Proto2.JsonInput.BoolFieldDoubleQuotedTrue +Recommended.Proto2.JsonInput.BoolMapFieldKeyNotQuoted +Recommended.Proto2.JsonInput.DoubleFieldInfinityNotQuoted +Recommended.Proto2.JsonInput.DoubleFieldNanNotQuoted +Recommended.Proto2.JsonInput.DoubleFieldNegativeInfinityNotQuoted +Recommended.Proto2.JsonInput.FieldNameDuplicate +Recommended.Proto2.JsonInput.FieldNameNotQuoted +Recommended.Proto2.JsonInput.FloatFieldInfinityNotQuoted +Recommended.Proto2.JsonInput.FloatFieldNanNotQuoted +Recommended.Proto2.JsonInput.FloatFieldNegativeInfinityNotQuoted +Recommended.Proto2.JsonInput.Int32MapFieldKeyNotQuoted +Recommended.Proto2.JsonInput.Int64MapFieldKeyNotQuoted +Recommended.Proto2.JsonInput.JsonWithComments +Recommended.Proto2.JsonInput.StringFieldSingleQuoteBoth +Recommended.Proto2.JsonInput.StringFieldSingleQuoteKey +Recommended.Proto2.JsonInput.StringFieldSingleQuoteValue +Recommended.Proto2.JsonInput.StringFieldSurrogateInWrongOrder +Recommended.Proto2.JsonInput.StringFieldUnpairedHighSurrogate +Recommended.Proto2.JsonInput.StringFieldUnpairedLowSurrogate +Recommended.Proto2.JsonInput.Uint32MapFieldKeyNotQuoted +Recommended.Proto2.JsonInput.Uint64MapFieldKeyNotQuoted +Required.Proto2.JsonInput.EnumFieldNotQuoted +Required.Proto2.JsonInput.Int32FieldLeadingZero +Required.Proto2.JsonInput.Int32FieldNegativeWithLeadingZero +Required.Proto2.JsonInput.Int32FieldPlusSign +Required.Proto2.JsonInput.RepeatedFieldWrongElementTypeExpectingStringsGotBool +Required.Proto2.JsonInput.RepeatedFieldWrongElementTypeExpectingStringsGotInt +Required.Proto2.JsonInput.StringFieldNotAString \ No newline at end of file diff --git a/conformance/failure_list_python.txt b/conformance/failure_list_python.txt index b278006bcc55b..6a483601cb408 100644 --- a/conformance/failure_list_python.txt +++ b/conformance/failure_list_python.txt @@ -4,3 +4,9 @@ Recommended.Proto3.JsonInput.IgnoreUnknownEnumStringValueInRepeatedField.Protobu Recommended.Editions_Proto3.JsonInput.IgnoreUnknownEnumStringValueInMapValue.ProtobufOutput Recommended.Editions_Proto3.JsonInput.IgnoreUnknownEnumStringValueInOptionalField.ProtobufOutput Recommended.Editions_Proto3.JsonInput.IgnoreUnknownEnumStringValueInRepeatedField.ProtobufOutput +Recommended.Editions_Proto2.JsonInput.IgnoreUnknownEnumStringValueInMapValue.ProtobufOutput +Recommended.Editions_Proto2.JsonInput.IgnoreUnknownEnumStringValueInOptionalField.ProtobufOutput +Recommended.Editions_Proto2.JsonInput.IgnoreUnknownEnumStringValueInRepeatedField.ProtobufOutput +Recommended.Proto2.JsonInput.IgnoreUnknownEnumStringValueInMapValue.ProtobufOutput +Recommended.Proto2.JsonInput.IgnoreUnknownEnumStringValueInOptionalField.ProtobufOutput +Recommended.Proto2.JsonInput.IgnoreUnknownEnumStringValueInRepeatedField.ProtobufOutput diff --git a/conformance/failure_list_python_cpp.txt b/conformance/failure_list_python_cpp.txt index 9b0dea68648e3..c0e2f16fa3e64 100644 --- a/conformance/failure_list_python_cpp.txt +++ b/conformance/failure_list_python_cpp.txt @@ -12,3 +12,9 @@ Recommended.Proto3.JsonInput.IgnoreUnknownEnumStringValueInRepeatedField.Protobu Recommended.Editions_Proto3.JsonInput.IgnoreUnknownEnumStringValueInMapValue.ProtobufOutput Recommended.Editions_Proto3.JsonInput.IgnoreUnknownEnumStringValueInOptionalField.ProtobufOutput Recommended.Editions_Proto3.JsonInput.IgnoreUnknownEnumStringValueInRepeatedField.ProtobufOutput +Recommended.Editions_Proto2.JsonInput.IgnoreUnknownEnumStringValueInMapValue.ProtobufOutput +Recommended.Editions_Proto2.JsonInput.IgnoreUnknownEnumStringValueInOptionalField.ProtobufOutput +Recommended.Editions_Proto2.JsonInput.IgnoreUnknownEnumStringValueInRepeatedField.ProtobufOutput +Recommended.Proto2.JsonInput.IgnoreUnknownEnumStringValueInMapValue.ProtobufOutput +Recommended.Proto2.JsonInput.IgnoreUnknownEnumStringValueInOptionalField.ProtobufOutput +Recommended.Proto2.JsonInput.IgnoreUnknownEnumStringValueInRepeatedField.ProtobufOutput \ No newline at end of file diff --git a/conformance/failure_list_python_upb.txt b/conformance/failure_list_python_upb.txt index b278006bcc55b..b656120eeb754 100644 --- a/conformance/failure_list_python_upb.txt +++ b/conformance/failure_list_python_upb.txt @@ -4,3 +4,9 @@ Recommended.Proto3.JsonInput.IgnoreUnknownEnumStringValueInRepeatedField.Protobu Recommended.Editions_Proto3.JsonInput.IgnoreUnknownEnumStringValueInMapValue.ProtobufOutput Recommended.Editions_Proto3.JsonInput.IgnoreUnknownEnumStringValueInOptionalField.ProtobufOutput Recommended.Editions_Proto3.JsonInput.IgnoreUnknownEnumStringValueInRepeatedField.ProtobufOutput +Recommended.Proto2.JsonInput.IgnoreUnknownEnumStringValueInMapValue.ProtobufOutput +Recommended.Proto2.JsonInput.IgnoreUnknownEnumStringValueInOptionalField.ProtobufOutput +Recommended.Proto2.JsonInput.IgnoreUnknownEnumStringValueInRepeatedField.ProtobufOutput +Recommended.Editions_Proto2.JsonInput.IgnoreUnknownEnumStringValueInMapValue.ProtobufOutput +Recommended.Editions_Proto2.JsonInput.IgnoreUnknownEnumStringValueInOptionalField.ProtobufOutput +Recommended.Editions_Proto2.JsonInput.IgnoreUnknownEnumStringValueInRepeatedField.ProtobufOutput \ No newline at end of file From 0ae12df49494a35671a39ad05e8bc5cdddcd323d Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Fri, 5 Jan 2024 08:16:45 -0800 Subject: [PATCH 182/255] Internal change PiperOrigin-RevId: 595999309 --- src/google/protobuf/compiler/cpp/test_bad_identifiers.proto | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/google/protobuf/compiler/cpp/test_bad_identifiers.proto b/src/google/protobuf/compiler/cpp/test_bad_identifiers.proto index 6bd6016e78be9..430b92700f0f6 100644 --- a/src/google/protobuf/compiler/cpp/test_bad_identifiers.proto +++ b/src/google/protobuf/compiler/cpp/test_bad_identifiers.proto @@ -120,8 +120,7 @@ message TestConflictingSymbolNames { // For clashing local variables in Serialize and ByteSize calculation. optional string target = 38; - extensions 1000 to max - [verification = UNVERIFIED]; // NO_PROTO3 + extensions 1000 to max [verification = UNVERIFIED]; // NO_PROTO3 } message TestConflictingSymbolNamesExtension { // NO_PROTO3 From 3acd85e0a90e4d5135278e79f8d0dd4a1f09e3b9 Mon Sep 17 00:00:00 2001 From: Mike Kruskal Date: Fri, 5 Jan 2024 08:59:10 -0800 Subject: [PATCH 183/255] Remove edition getter from python descriptor APIs We've never released these, so this is not a breaking change. PiperOrigin-RevId: 596007719 --- python/descriptor.c | 7 ------- python/google/protobuf/descriptor.py | 7 ------- python/google/protobuf/internal/descriptor_test.py | 3 --- python/google/protobuf/pyext/descriptor.cc | 5 ----- 4 files changed, 22 deletions(-) diff --git a/python/descriptor.c b/python/descriptor.c index c5af6dd90e1e4..29ba6b3047870 100644 --- a/python/descriptor.c +++ b/python/descriptor.c @@ -1367,12 +1367,6 @@ static PyObject* PyUpb_FileDescriptor_GetPublicDependencies(PyObject* _self, return PyUpb_GenericSequence_New(&funcs, self->def, self->pool); } -static PyObject* PyUpb_FileDescriptor_GetEdition(PyObject* _self, - void* closure) { - PyUpb_DescriptorBase* self = (void*)_self; - return PyLong_FromLong(upb_FileDef_Edition(self->def)); -} - static PyObject* PyUpb_FileDescriptor_GetHasOptions(PyObject* _self, void* closure) { PyUpb_DescriptorBase* self = (void*)_self; @@ -1421,7 +1415,6 @@ static PyGetSetDef PyUpb_FileDescriptor_Getters[] = { {"public_dependencies", PyUpb_FileDescriptor_GetPublicDependencies, NULL, "Dependencies"}, {"has_options", PyUpb_FileDescriptor_GetHasOptions, NULL, "Has Options"}, - {"edition", PyUpb_FileDescriptor_GetEdition, (setter)NULL, "Edition"}, {NULL}, }; diff --git a/python/google/protobuf/descriptor.py b/python/google/protobuf/descriptor.py index 29885ff395879..a1b94b3c660bf 100755 --- a/python/google/protobuf/descriptor.py +++ b/python/google/protobuf/descriptor.py @@ -1279,13 +1279,6 @@ def CopyToProto(self, proto): def _parent(self): return None - @property - def edition(self): - # pylint: disable=g-import-not-at-top - from google.protobuf import descriptor_pb2 - - return descriptor_pb2.Edition.Value(self._edition) - def _ParseOptions(message, string): """Parses serialized options. diff --git a/python/google/protobuf/internal/descriptor_test.py b/python/google/protobuf/internal/descriptor_test.py index bf833a4b8ac4e..c561a0411c2ac 100755 --- a/python/google/protobuf/internal/descriptor_test.py +++ b/python/google/protobuf/internal/descriptor_test.py @@ -539,9 +539,6 @@ def testFileDescriptor(self): self.assertEqual(self.my_file.package, 'protobuf_unittest') self.assertEqual(self.my_file.pool, self.pool) self.assertFalse(self.my_file.has_options) - self.assertEqual( - self.my_file.edition, descriptor_pb2.Edition.EDITION_PROTO2 - ) file_proto = descriptor_pb2.FileDescriptorProto() self.my_file.CopyToProto(file_proto) self.assertEqual(self.my_file.serialized_pb, diff --git a/python/google/protobuf/pyext/descriptor.cc b/python/google/protobuf/pyext/descriptor.cc index 2c5bd1a0fe06d..a4a323adfa0ad 100644 --- a/python/google/protobuf/pyext/descriptor.cc +++ b/python/google/protobuf/pyext/descriptor.cc @@ -1529,10 +1529,6 @@ static int SetSerializedOptions(PyFileDescriptor *self, PyObject *value, return CheckCalledFromGeneratedFile("_serialized_options"); } -static PyObject* GetEdition(PyFileDescriptor* self, void* closure) { - return PyLong_FromLong(_GetDescriptor(self)->edition()); -} - static PyObject* CopyToProto(PyFileDescriptor *self, PyObject *target) { return CopyToPythonProto(_GetDescriptor(self), target); } @@ -1559,7 +1555,6 @@ static PyGetSetDef Getters[] = { {"_options", (getter) nullptr, (setter)SetOptions, "Options"}, {"_serialized_options", (getter) nullptr, (setter)SetSerializedOptions, "Serialized Options"}, - {"edition", (getter)GetEdition, (setter) nullptr, "Edition"}, {nullptr}, }; From 0905ba3462b21337b372802bd3135c663468e8c4 Mon Sep 17 00:00:00 2001 From: Jie Luo Date: Fri, 5 Jan 2024 09:44:26 -0800 Subject: [PATCH 184/255] Add "extend repeated with nothing" tests back for upb python PiperOrigin-RevId: 596017378 --- python/pb_unit_tests/message_test_wrapper.py | 7 ------- 1 file changed, 7 deletions(-) diff --git a/python/pb_unit_tests/message_test_wrapper.py b/python/pb_unit_tests/message_test_wrapper.py index fcac3a34cf10f..78f35853ab3a6 100644 --- a/python/pb_unit_tests/message_test_wrapper.py +++ b/python/pb_unit_tests/message_test_wrapper.py @@ -31,13 +31,6 @@ from google.protobuf.internal.message_test import * import unittest -MessageTest.testExtendFloatWithNothing_proto2.__unittest_skip__ = True -MessageTest.testExtendFloatWithNothing_proto3.__unittest_skip__ = True -MessageTest.testExtendInt32WithNothing_proto2.__unittest_skip__ = True -MessageTest.testExtendInt32WithNothing_proto3.__unittest_skip__ = True -MessageTest.testExtendStringWithNothing_proto2.__unittest_skip__ = True -MessageTest.testExtendStringWithNothing_proto3.__unittest_skip__ = True - # Python/C++ customizes the C++ TextFormat to always print trailing ".0" for # floats. upb doesn't do this, it matches C++ TextFormat. MessageTest.testFloatPrinting_proto2.__unittest_expecting_failure__ = True From 679c1c9342ed5b87f50ae70c64b8a41265bce2b8 Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Fri, 5 Jan 2024 09:49:46 -0800 Subject: [PATCH 185/255] Update comment of "lazy" field option to reflect eager verification. PiperOrigin-RevId: 596018472 --- src/google/protobuf/descriptor.proto | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/src/google/protobuf/descriptor.proto b/src/google/protobuf/descriptor.proto index 45220bda00821..aaa5424527618 100644 --- a/src/google/protobuf/descriptor.proto +++ b/src/google/protobuf/descriptor.proto @@ -695,19 +695,11 @@ message FieldOptions { // call from multiple threads concurrently, while non-const methods continue // to require exclusive access. // - // Note that implementations may choose not to check required fields within - // a lazy sub-message. That is, calling IsInitialized() on the outer message - // may return true even if the inner message has missing required fields. - // This is necessary because otherwise the inner message would have to be - // parsed in order to perform the check, defeating the purpose of lazy - // parsing. An implementation which chooses not to check required fields - // must be consistent about it. That is, for any particular sub-message, the - // implementation must either *always* check its required fields, or *never* - // check its required fields, regardless of whether or not the message has - // been parsed. - // - // As of May 2022, lazy verifies the contents of the byte stream during - // parsing. An invalid byte stream will cause the overall parsing to fail. + // Note that lazy message fields are still eagerly verified to check + // ill-formed wireformat or missing required fields. Calling IsInitialized() + // on the outer message would fail if the inner message has missing required + // fields. Failed verification would result in parsing failure (except when + // uninitialized messages are acceptable). optional bool lazy = 5 [default = false]; // unverified_lazy does no correctness checks on the byte stream. This should From 55260d8321546a20f280608501bcce57b1467411 Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Fri, 5 Jan 2024 18:01:42 +0000 Subject: [PATCH 186/255] Auto-generate files after cl/596018472 --- csharp/src/Google.Protobuf.Test/testprotos.pb | Bin 363070 -> 362584 bytes .../Reflection/Descriptor.pb.cs | 18 +++++------------- 2 files changed, 5 insertions(+), 13 deletions(-) diff --git a/csharp/src/Google.Protobuf.Test/testprotos.pb b/csharp/src/Google.Protobuf.Test/testprotos.pb index 9b7e77f2abbf2902ff7a92adfff3044a74994921..f29d03d15c0044b2c52d5ffacac7053860e6648b 100644 GIT binary patch delta 9392 zcmY*fdvsORna@7=?7h!9H_vlJfB~bjx9y%Q2J13l)5^roh38OL<|xq5=_D% zIy1KwVk3mg`(Rg>Ez~GhO2H_%OaugCDGs&33<9RXDi9Df0@9*%S?Bld$31ucU@d;% z`Cj|?efxQ{XI;g~RTbN}bvkF;I<|M-H6d94QX-HcuP)fzA>Z$AWZ%!8naySgWlslz z>lQkR(A~qGah1!1?5uh0P~x8Ynn#zUAF6F?s(GL`J+H2|{{E(PO=E4kskyGcK3xlG zWBro!ztuL@;p6@3=7#j#`L%QZHAv(0gn12(4?(!NuCbQ>Thp9wXpD|N$OcYL&#bAh zuUqgy`i`bM7SuJ@)zsHLT6_QKF+sXvLArT*Wuo73Nb3?Xy^b8DLGV6U|sYnv9;H>c|sq!-pSHc>3HUxeI8*FG}0c42dR@%-8a zL3+`Gx;O(HQ4g|aF6q_WS6@5k<{&5vI5Fgg?rd zz_Auef+NNRzhsJixIPfIKg4#-J`e|R5#T@^z(s%qymY8>;Ud5RUNyo(1USG)-eMsF z9N?4wI=G+%z}2B>#{zcopAW?WI7#CG903mT(n{lkBfud(0gmvY!z@IABfRRbEF_P7!j#~3 z6~J{uahyA+qSl95SLQgE6+v+z+(OrJ3PSfS?p6jRfz%jbAm|qh91;u|n6rSwiF^yD z1+fK##ff|i;FH`PXk2C-$AJkX<+&h^QbA`GD&{emZtmE|^3X|umUs_!>E=mWQV+hm z`5@af9(d{Iqs9ckaL5%pO1#UR4|t;T$4>h1=hro*vv)SJVJ!15m;KF{62!uL+#PK4 z0ftiu`o{t!_#Uqul(T@snRrYIhgg8X4haHSoZ%RfW;#JbJj>k?mIVl40?E)^5Uo-* zJZFNjoXbxu0SgG?v=VT7E6yQSs*s1p+h{rBqaUp-~Xvg>SM=DuHNo?OG90`;6X=Ylw&;u9q$4+&IARfC1 zi;MYV_e1v*cL(L@^kD%(MJ#~DB|fl{x-5g$4+eeQ8Dr**5AFbMoB0@JA5RXlU*W8e z4<2qIO4G-yMYvLzFvU+4P=j6J?l7GS;cp@uB!#gA@viV9 zLn5ib#}(esG$jcT^9moD4ytJGLI8!U(S*fpMCNL~Cx(h%`eYdmRJvH-rW@k%>419-Z|izZAArmLBo4BhKd&ti7l z^y{&UBwSqQ$$o~rBwSqQ6?PF$!o_tyY6$Gak)&jD2THAqV}R@glQvabgy*Oy|Q3&=#NZ zeglHRWQV5soJS8WVME4$&Xa{&$0w6~2onXT8k6ruJD0F&fBQX=EHV~EdOn1Of`x(O z7KLJ|C}@HX2OubD5r#`Z*tQ76B_Jqh z5yPq!mqpYdtwM1bef}sD(^_Lc41QXLp%R)()ldltKdr)0Sp+IqM1S)b`^Vc?2t#6# zA`wuN2#E2m5FnApR~(8Tih`|Xe8uqnL*b=@e?ftZX?$y8ueq4GqrGc2-Q|+88bUcXs~Xjj;=A`;D;+8qr2!c7B+^#YSOven2cQ z8->~V0kJ@B6xjKPq8`O)fgg$JjqkES(L4Xa_!oX8Odk}hKFEg{wSvE)-KLlp@Xf-R zRk_QFZu$q-8~x=!*_=6$=<4A+a@-u}NCVj{O7#H;UyM(E*x#K zeS)uWv_+Uc0feJ1woi&NxEHBUzI%5u&A1nBvjD*iP&W%8czV$`OGzlUiGuy6SxTU} zO?U%>>s0Cz>XwdZ?)TZJ|I}ee2O%PLSQ-Ig(_u>uh@?7fsR2P_hb=WAO5H)FrUk2n zDzG!h;zy5zML^9WK4S1YEsKCk*-SP-#Mw!cZJSONgX)Z?EM?ngcg8NL;+=7-6t7d5 zQ(TFvc&EUUPRDUTq}nNlO|cNEc8c+n)od$Ce3S5oV7q6Cg6( zW6M;6jP|KAMMGN{zkQ!AQ;8}Qpe_?2MzqhCsWcQ_qTrM%Qz-&;39mx2SV~no80}lh zrq0Cwk=a3;86Yw{XgLIg;X&JpfXM8iz~X-@fpU}*J;$;aT39!`_gL(MruH#QB9utW z)*BE$j)@`q5&;MjkBRhTMIs`%m7<4ZU`ZBdlP}~H`vYN4z6v7@1p1hz1Q^E$0w>=QICYQ!3Li#0+gNqghr-o|3?+u%hoYi? z@I|8s+!y_&jZMw;3Ab1sMo5n;&?m}5b#f|$H*r}wS46cc7cja90zCr(QJKraoWcMR z{IVE4!777<%VLtAFZc=)t_U&Gegz3vMA?X>YSJeu_ET&*OD&b&py0o0-wEmb`J{B(vX@t}J6YyQ84$gK zK2U*|OSek#uQ1YvKp#An0NE^;=D4T?NPW319}=4&`Q)O(%dpD0q%~x<99eC$0qtv~ zxfz5GZIFOA8(PxW#Ga^S*2qv_K%opzYvicW?WwR9=nf`9hVJj}vZOQ@1o*jp6Y>E;Y(fjnbNLn+ z-t*EOpjw`M(wYE)UNe;d7SBtpnRJUxVHn~C>1>xSik9Id0G*I%IsrlU3o@zu9uV$c zkON1l5(6UK3v%o@gj2R2c^khStkF_{?_OEx{#=?%DB%=%dojlw3E*+7bZL@ikS8SN zQ2B*)zplqX0;p{Je*%o*m(rc7$AG>QFG*)-u2wYfUy`!K(8#D(9dT)Zp#Xt?Zb-Qh zz+s2Xm=`CKK;vcU78xFawZMx7FnL+xkgi4w3*c9zTar^C7Z3!oKxq^e>#XrvWTmrP zF;C<%7w;30SmtRP%Gw18pW!Y`DFjoEkhbKPDm_m5Wr-gRJ5U`paHx;o)r3J4+1+WAW#}=8c~ZQ z>n`cMkt3RxRtPN5v>SKHB+kPb#Vie~OAh;zA(|G`E;;R1Lo|-d@HYL89MKLD{d!Ea zqlo@>+~N?x$ zr{@3>jjWGK=R}TZ+IS$aMAK>Is5GxS&_)7BWu<-!15AV&;PDd-(FqWJRNj0dM|6US zJ{A+5P(=SvOf&>=`M)vI2}SgA>R;W^5J2Otc;#?IaY{NphG+C2?O~^+d8-DbrQ_{f zOu|rrK);YF1#s}T#C1v&?Gn-5@d^yA1$G6702bYP1*V2ZM~Ck3abgKFDoYZ;1QNUY z=$`+*EGme;P6; zT6<#_fuYcg^Q*Nb$r&?_B3n-;^pk zpp8lO`b72{7;JTLcqO&T}{f>^lyu{Kg*U)Z;O4<>7va`hQ^3$)8?i0>AYN>F4{a?O`gy` z!27D`;da*gl~u6|+BjFmE{KLzu?yNaSCNai8EVxp6dS#Qr=u@E$4-@Q^zexDcp0+m zM+5E3rk`iayg6OgHKcIe<(bPDAY6BO<@$F>K)CMG1%L~x_UoRr(bq?HU}(SY;X1lp zqUgXBq$lfaXKjg0kFAT6qw9OTqEJ;%31HgerF5N?0HJz3tU^>rr$Ap8Evz|M?a-Wl)QNOrmNmF`$O;ft|k(#;9*`k-(be6$q-5unTZi#2} zv!G&}&Ch}kduQ{rpjU^p`B^afW$G+t(Ozh>fMC7vj;UN%n7(5k{v-fDLw>tqQRCd& znGM-Pudq^)!RI&&x?!&O&6S+eqI$0P%k__kN`NfZ`?zJ&Tp|JR2Hzc<n%h`+Uu_cziB7!Ax=Wt%y@A0a=*0?ZlTFdS-R#jh zn|w3bAVe!}^39?Th+v!i3jKNth)|n+Ok3JPDyS7V`_3NIionp`><8t+Qw*E|Q;hcL z={;=q1MPNDN{m6Z`=%3>0G92(=|m+!q;}tQq7tA7+I`cBT7Z(b`{;pLCK!BdiB|7r z_k3+jelTjdEtWyDq=wt#m+N1Jl>ouE`1nT4s?}~b5N4_iSl^uRc@7Cmso+ftq*sUMbNzons z72ka|^7ga3)GNMU7JLJf5~})oo{g66XSY{peGvp@fp0%xC|MuZiCc5J2(&A@x}SZe zdY3Q!JY70b?DBD<_)<<6lFsNm2iTW0oxVus>C)cR=@;uuC#8$N-R+yJkHT7@8(9g^ zS-brreG63rB(mGbTR%0j5@5u;eY{uw`Qc#7+@|?8jSD9(q@B5G;-a|1PCBE;Tyt-Y_}_lW!3Gf+git&t}_cW&W3O?w+#v2 zBv9P#T$}1*#n>p=14u&ZuALzo427Cv6vPOM#3By0e3YW4(5es+6#1&z-}8RlbL;ev z%-r8|-skK0Jnv@?wUzByQ`WP&&w9IUYfs-@)BUTziufYtOw4<8tN7?>n*F5r!~(X! zFBvNEZ9CtJ#OyteHLd(yLGRs*+1?0C1;M|wicC#yvgZ4Vbn=1bR64mRu{f2iThy3X zo@%O1)%%I+L|yfRD-w;(3#TthHa1q@pPZ3Me7Cl`DUoWdO4L->)urn1Pu$sfXML(E zRb7{QFu7>*lte>)qNz5SXlQOqrW0DvPb{fk0Y6R6X?#sLClkqK$@)a_%JLfPc)<#VI;&$lj+3`=_OKKW?hw7lw6#wZc1g40~uY~oL<^Mt`^I*l@%n2oNuX5 zq?RnLOD;*)H$ej#F0W11)Fx_b8=!%B8=A<+-(?f2H#asRtVB&iePgPz2{sbd3qemJ z)kJ(|455fGQC+`+qHjvoG}l$9bE&VQApNh#A#Ep7FJw8jx^8*(ipHrrj#N|QS1Vfu zJ`z*w!F_tFZ-!<5-new~{_6CiI#hx9SYDfy9-u8#1zWnXpuN#Yaww)EeTMHRZjnlN zq2jY=&7NJQx(Gf~=&wdqfrfhGL5|B1`3qMxB@>NJ>16ei#G>XjX#Xnz^~=yE?N+K~E#Y&5_HdQt{LjfsjZu1?h?{M} z;D9rAraw<6z+?8ops1eRvfyB7pTqva&_0L#gCRp4_76J4M{0u{_76Jc(+q_DgU*Dh zexMQnJQO@%&(_^{D0Cp;;85s5z`-G>c(gVl;NXxmw!%O-IOJ6RgMnnxnLgX!Egjfa zj30BX4})hL*c+K+jwtgBeQxL5mX#N?|KQl=evvN}h8qZmg#wENBSvO5FyMHu22+Ai zgF)kXt_JW2jy+PF%vhEM6-Y|6PAoYD4V5nmM=~cI%k-0r1_Csl$dnz4@sAwqGbd8M!BT5z@1h4-1G*ci5RUD|C4eJ@P zP=Ir}xl`{$5a!OIaV|G^wBx6_nF^MX64Q4POF-pQnvjMr^uYPt+^NnGgt@!WIG>xl z7qc%o_NXkK9yA~*3kA@);EXJ%F3VuigTh6}nxf~72krn(n|a9cq7xluzQWi=XY@D& zQJRa+#K{O3T^7lU@k@?%)rqLj5$c~yj<1U!$)g6l?AR456vDT|8zlLm1pY2N1)4+} z0vnf|VY(?v0H2qgu?fGD<}L&na3#3CnT^j}$+g5#(JM|tJZqYI^NLfdCm<=p(iLa) z7(Lzmn0?K$%;M)GGC;$FkGQTmQL~cyuyxHTH*?d6rE5;%^qKz6a^^;3_K*|&eigeR zn6-@YxkI6$C=3lb(P5gwC=3lbWo8AA!qAXYG0wkR+R2aEEx~Voz`k{BzLk%FT6i{~ zeAsE>QKOg-J1u;yS^4r|r-grgjz8az*!f`M5grUJV+*D~!VC0%@XuFnF1P+8B5)yxA# zQ0w`1WBrq~mlaZ8ok9D9?9czv8JeJ;?+i^)UY%U;_E3R|POf)*K&&mDT<`XPSe-gK zcKfj?Mj`6|Y;f$qSjCKIP5BFD`Ew!imGCXvWD05B?&_`jZ}x9&L01@)g_yd+m?-cr zUaSr=&_PUHe9n!sT>ueN7r*H{a{VJHKhM2OHbo%~?xv=gH@7=<5J54!O*>!=9CVv@ z03;pL4uuvvsYlHy{3a0Ev0RoY{5}&EgmBeo=mUgKpD8II zqUtjx1q6M4rlf!~W+sv_Yx z0^JjOp=u(x(4JH+lAG+{vsUxOxjKqw8GoYFo@#RR({THb)1l5jQgCI4fp>^j|09Kj6iE-E^@n29y@3pRpKHqiODlk39Ru;+`7ys z%CZ5YHV~+D1|Vv4iR<$gAe>*~qoQ z6P2K_ErQM;_kOK}ny5wSLkJM`096wKBIXu>Ep$}`duR*?1d+F~cS$RIjKx<8ca*=6 zwwf57G@lgKnqL2>*ljXT3ZLlZ^nnWel&~u${}Ll^2-Fc%3J}gyLLUsJ05LozO2>pM zi2f;&sL0yHfYrhtmmNSwgFxHN&{+~jS5qEzgCwI=xz!?eT_}Lj)dGtsUG8EO=F`F& zBTEMagMg|F07354A{sYeVe4s8st#`W3QJFmQKS70)a)_2Q>_c`eUf!#)`d1GqIDvw zn2pJJ)`?i9Hc4yAIx%6Qjs~=^7y1qmlj{YbiH278^`Rwdne`&3u9_GOOY6m?$z&;m zXaJuP)@1F6x(3jgionz}B3f*|!qhXOL|rGKDs?AL(m_FWgRsm;+N}YNC3-p85C%oN z^#+jv-?YJi6PVf%vW>y*!ZOKY06}Al-bmWRpy=k;E=o*k=#8YEnnBeKmFWmxA(c#>@dr830JKVaaz5e z7gmo@_b6bPd0vQ8*^hwKJTC}+WtJENAW-*6DL_GA5c(cT0u1ODwrWp_l|Xec2{Lq3 z?-oVHStr1ob5+O&1fdEoFq?BVklu^J9wA$vY|^3tfm$=A02(g}teJFQj3W)cMOeQU zHj0*UNB}w^QFH==>@6ay`W_JGwuq6FWQhUcZi|>Y4eq3_OV+A>4c2HWz<0MKX8%&? z>n7nic-xxgjRdf`P1rO^Gl&zCQVjW(u)nEtAOVKF^fvwdE)fbiq7y}?s4-0V{0vPNQ8U40I5{!67*aezLU?p%v0aRWQxR%LGp#l7= zu#2(-$OHs_D3Bux3RTqj%y$ZFw`88kV>VtQATi9-Hnh_$K==%EJ86Za$pr}JchZzl z%wrpZwaVRD<{2^nTF5+;%wK$?45Y~HHqUk6Gf#I2U;{g%Hu{a}{rKAQ##SNNh zT1*GTO>;HTI5orC&F^K2wutC=LZU56^l!ozhX5A$heTVl!`}@X8Uld7f?LjVqbD{xm;MB^1OX1{NUrUAq=1cqmN zCPe?e9}+F!34a&P0rgA>ftdpkz{&5_93Y|*^xh(_3_g!M_5Xxf({FhtWW`jpV` z(ijbEr^G1rnb+P~iujlDxp;lxEyq*^mFK7GLAzCklv^tX3&vFDA$?NAKuNZ;|FXjqp ziT*;^ck7OJWJg~T_O0>(FOD~(tHLUh2c@`&u~$X3P_1P0=_nV%w1o876vv_IuR&c0 ztEl>`xeCPP%^(*-L&AjC_%hhu!78VJ8ER0o=R#;mI8JLkAK~94_!Y>>H6`wYyGr$T_>B#GLO4> zi>Btn2WqZXSD!f~Mj0Vc8-x^~kgcwM;g$k~-RkNWZYe-9TU|Y?Nq_-QxHc76NFQ|l zfI!=n*AEzd!Yxo8ELEh=2(?H{0gOK3jvFtlQ%YgBxz_cvIzTW8sCo?$*4o^tI(Y-a zR+~G%$_$33Hh1PMzlE+JrE-d|3EqB|J$&<;&<33#*0|A_R-)RhapUR)UMf!zYg}AE z{zusW?`wlq|H~fz#@f&XZH{Y06GX$>&;;#`YsthBhFT4a@lH4I=fOSy#|{^Fx_GZ? zDM56@DA9r58=qqjyY~$k(~!dSfU7T9fG|Dama6|M0>bowDgaDSwcl~APEQ@jfie0W z7gx^51d0w!PEPiY-pn44)SfhTk#cnQNw**-D<=g|J?X|(oumM+PP$lWsJ2poJN-#_ z^fbTNceMcIoOH)b_209!I~Y0LTl`D*T~>QK*BxE?PUpHK)=%fUqm$d|TzB+@a5~o= zqkkx!CU?)}Yj+T|_YQ1jlX#}x(_KfQ(!H?V(-&zefV+0DRQ+>L3gE8Y!`+Z(2MK^X zJbP+3TiT@|P@OCXz-C9TP1>nDyi(QtOXLt~Wb%}(QP|k%*|W1oX-9$}G)i~Hjk!i? zSK8>6(sr*{r+sOoH|u(TkeaD1#(&}Ey%`*TnVl*6h3Ag+e}G;pqcU#_j`pz!@7v_* z$pRr-X_KcHWaNG3f0As!bO+v_Vo2cVkJ;*D+TDR z-ClvZDM|qX+3n#!UDUQxfQ)y0cvHIifIqvYv9>zBbmr1@LsLWJ%;wcSmKz*7%nDb| Sd!6CW!e69!-s|?rJ^v32vI}zn diff --git a/csharp/src/Google.Protobuf/Reflection/Descriptor.pb.cs b/csharp/src/Google.Protobuf/Reflection/Descriptor.pb.cs index 336a074fcab9b..944378a2bb917 100644 --- a/csharp/src/Google.Protobuf/Reflection/Descriptor.pb.cs +++ b/csharp/src/Google.Protobuf/Reflection/Descriptor.pb.cs @@ -8002,19 +8002,11 @@ public void ClearJstype() { /// call from multiple threads concurrently, while non-const methods continue /// to require exclusive access. /// - /// Note that implementations may choose not to check required fields within - /// a lazy sub-message. That is, calling IsInitialized() on the outer message - /// may return true even if the inner message has missing required fields. - /// This is necessary because otherwise the inner message would have to be - /// parsed in order to perform the check, defeating the purpose of lazy - /// parsing. An implementation which chooses not to check required fields - /// must be consistent about it. That is, for any particular sub-message, the - /// implementation must either *always* check its required fields, or *never* - /// check its required fields, regardless of whether or not the message has - /// been parsed. - /// - /// As of May 2022, lazy verifies the contents of the byte stream during - /// parsing. An invalid byte stream will cause the overall parsing to fail. + /// Note that lazy message fields are still eagerly verified to check + /// ill-formed wireformat or missing required fields. Calling IsInitialized() + /// on the outer message would fail if the inner message has missing required + /// fields. Failed verification would result in parsing failure (except when + /// uninitialized messages are acceptable). /// [global::System.Diagnostics.DebuggerNonUserCodeAttribute] [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] From a8b8ea02b74095042a6c4a6acb50498a1a2c4570 Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Fri, 5 Jan 2024 10:28:14 -0800 Subject: [PATCH 187/255] Breaking Change: fixed json_encode/json_decode to use the message's pool. This bug arises only in the uncommon case where there is more than one DescriptorPool. In such a case, JSON encode/decode should always use the pool of the message being encoded/decoded, not the generated pool. Closes #15281 COPYBARA_INTEGRATE_REVIEW=https://github.com/protocolbuffers/protobuf/pull/15281 from protocolbuffers:ruby-json-pool-fix 91e2dc55dcb4052cc50471a6114ebed484c05dd6 PiperOrigin-RevId: 596027770 --- ruby/ext/google/protobuf_c/message.c | 16 +++++------- ruby/tests/basic_proto2.rb | 39 ++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 10 deletions(-) diff --git a/ruby/ext/google/protobuf_c/message.c b/ruby/ext/google/protobuf_c/message.c index d2bc27062cb19..908e4d2d2041c 100644 --- a/ruby/ext/google/protobuf_c/message.c +++ b/ruby/ext/google/protobuf_c/message.c @@ -975,9 +975,6 @@ static VALUE Message_decode_json(int argc, VALUE* argv, VALUE klass) { int options = 0; upb_Status status; - // TODO: use this message's pool instead. - const upb_DefPool* symtab = DescriptorPool_GetSymtab(generated_pool); - if (argc < 1 || argc > 2) { rb_raise(rb_eArgError, "Expected 1 or 2 arguments."); } @@ -1011,8 +1008,9 @@ static VALUE Message_decode_json(int argc, VALUE* argv, VALUE klass) { } upb_Status_Clear(&status); + const upb_DefPool* pool = upb_FileDef_Pool(upb_MessageDef_File(msg->msgdef)); if (!upb_JsonDecode(RSTRING_PTR(data), RSTRING_LEN(data), - (upb_Message*)msg->msg, msg->msgdef, symtab, options, + (upb_Message*)msg->msg, msg->msgdef, pool, options, Arena_get(msg->arena), &status)) { rb_raise(cParseError, "Error occurred during parsing: %s", upb_Status_ErrorMessage(&status)); @@ -1091,9 +1089,6 @@ static VALUE Message_encode_json(int argc, VALUE* argv, VALUE klass) { size_t size; upb_Status status; - // TODO: use this message's pool instead. - const upb_DefPool* symtab = DescriptorPool_GetSymtab(generated_pool); - if (argc < 1 || argc > 2) { rb_raise(rb_eArgError, "Expected 1 or 2 arguments."); } @@ -1128,8 +1123,9 @@ static VALUE Message_encode_json(int argc, VALUE* argv, VALUE klass) { } upb_Status_Clear(&status); - size = upb_JsonEncode(msg->msg, msg->msgdef, symtab, options, buf, - sizeof(buf), &status); + const upb_DefPool* pool = upb_FileDef_Pool(upb_MessageDef_File(msg->msgdef)); + size = upb_JsonEncode(msg->msg, msg->msgdef, pool, options, buf, sizeof(buf), + &status); if (!upb_Status_IsOk(&status)) { rb_raise(cParseError, "Error occurred during encoding: %s", @@ -1139,7 +1135,7 @@ static VALUE Message_encode_json(int argc, VALUE* argv, VALUE klass) { VALUE ret; if (size >= sizeof(buf)) { char* buf2 = malloc(size + 1); - upb_JsonEncode(msg->msg, msg->msgdef, symtab, options, buf2, size + 1, + upb_JsonEncode(msg->msg, msg->msgdef, pool, options, buf2, size + 1, &status); ret = rb_str_new(buf2, size); free(buf2); diff --git a/ruby/tests/basic_proto2.rb b/ruby/tests/basic_proto2.rb index 26c253437db51..3864756fa7829 100755 --- a/ruby/tests/basic_proto2.rb +++ b/ruby/tests/basic_proto2.rb @@ -263,6 +263,45 @@ def test_extension assert_equal 42, extension.get(message) end + def test_extension_json + omit "Java Protobuf JsonFormat does not handle Proto2 extensions" if defined? JRUBY_VERSION and :NATIVE == Google::Protobuf::IMPLEMENTATION + message = TestExtensions.decode_json '{"[basic_test_proto2.optional_int32_extension]": 123}' + extension = Google::Protobuf::DescriptorPool.generated_pool.lookup 'basic_test_proto2.optional_int32_extension' + assert_instance_of Google::Protobuf::FieldDescriptor, extension + assert_equal 123, extension.get(message) + end + + def test_extension_json_separate_pool + omit "Java Protobuf JsonFormat does not handle Proto2 extensions" if defined? JRUBY_VERSION and :NATIVE == Google::Protobuf::IMPLEMENTATION + pool = Google::Protobuf::DescriptorPool.new + + # This serialized descriptor is a subset of basic_test_proto2.proto: + # + # syntax = "proto2"; + # package basic_test_proto2; + # + # message TestExtensions { + # extensions 1 to max; + # } + # + # extend TestExtensions { + # # Same extension as basic_test_proto2.proto, but with a different + # # name. + # optional int32 different_optional_int32_extension = 1; + # } + # + descriptor_data = "\n\x17\x62\x61sic_test_proto2.proto\x12\x11\x62\x61sic_test_proto2\"\x1a\n\x0eTestExtensions*\x08\x08\x01\x10\x80\x80\x80\x80\x02:M\n\"different_optional_int32_extension\x12!.basic_test_proto2.TestExtensions\x18\x01 \x01(\x05" + pool.add_serialized_file(descriptor_data) + message_class = pool.lookup("basic_test_proto2.TestExtensions").msgclass + extension = pool.lookup 'basic_test_proto2.different_optional_int32_extension' + + message = message_class.decode_json '{"[basic_test_proto2.different_optional_int32_extension]": 123}' + assert_equal 123, extension.get(message) + + message2 = message_class.decode_json(message_class.encode_json(message)) + assert_equal 123, extension.get(message2) + end + def test_nested_extension message = TestExtensions.new extension = Google::Protobuf::DescriptorPool.generated_pool.lookup 'basic_test_proto2.TestNestedExtension.test' From bb38ba55753a27a78abd8cc1d5211eb8950dabfe Mon Sep 17 00:00:00 2001 From: Jason Lunn Date: Fri, 5 Jan 2024 10:30:47 -0800 Subject: [PATCH 188/255] Fix separate issues in JRuby's "native" `dup` and `inspect` methods. (#15265) Update the stress test to exercise `proto3_optional` fields. Closes #15265 COPYBARA_INTEGRATE_REVIEW=https://github.com/protocolbuffers/protobuf/pull/15265 from protocolbuffers:fix_jruby_proto3_optional 4040e13a7bc1c183b7e57073f070ea13518122c0 PiperOrigin-RevId: 596028361 --- .../src/main/java/com/google/protobuf/jruby/RubyMessage.java | 5 +++-- ruby/tests/stress.proto | 4 ++-- ruby/tests/stress.rb | 4 +++- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/ruby/src/main/java/com/google/protobuf/jruby/RubyMessage.java b/ruby/src/main/java/com/google/protobuf/jruby/RubyMessage.java index 365f23c7b2651..25d169b759541 100644 --- a/ruby/src/main/java/com/google/protobuf/jruby/RubyMessage.java +++ b/ruby/src/main/java/com/google/protobuf/jruby/RubyMessage.java @@ -203,7 +203,7 @@ public IRubyObject inspect() { sb.append(cname).append(colon); for (FieldDescriptor fd : descriptor.getFields()) { - if (fd.hasPresence() && !fields.containsKey(fd)) { + if (fd.hasPresence() && !(fields.containsKey(fd) || builder.hasField(fd))) { continue; } if (addComma) { @@ -551,7 +551,8 @@ public IRubyObject dup(ThreadContext context) { } else if (fields.containsKey(fieldDescriptor)) { dup.setFieldInternal(context, fieldDescriptor, fields.get(fieldDescriptor)); } else if (this.builder.hasField(fieldDescriptor)) { - dup.fields.put( + dup.setFieldInternal( + context, fieldDescriptor, wrapField(context, fieldDescriptor, this.builder.getField(fieldDescriptor))); } diff --git a/ruby/tests/stress.proto b/ruby/tests/stress.proto index 517e74638c98a..e7a0042d00cc4 100644 --- a/ruby/tests/stress.proto +++ b/ruby/tests/stress.proto @@ -3,10 +3,10 @@ syntax = "proto3"; package stress_test_protos; message TestMessage { - int32 a = 1; + optional int32 a = 1; repeated M b = 2; } message M { - string foo = 1; + optional string foo = 1; } diff --git a/ruby/tests/stress.rb b/ruby/tests/stress.rb index 4ad37c171cad5..c56432012d507 100755 --- a/ruby/tests/stress.rb +++ b/ruby/tests/stress.rb @@ -19,9 +19,11 @@ def test_stress data = TestMessage.encode(m) 100_000.times do mnew = TestMessage.decode(data) - mnew = mnew.dup + mnew2 = mnew.dup assert_equal m.inspect, mnew.inspect assert_equal data, TestMessage.encode(mnew) + assert_equal m.inspect, mnew2.inspect + assert_equal data, TestMessage.encode(mnew2) end end end From 0d8080ef2965e3494347aa8596a7aea12e8372c9 Mon Sep 17 00:00:00 2001 From: Sandy Zhang Date: Fri, 5 Jan 2024 12:25:42 -0800 Subject: [PATCH 189/255] Add to Proto2 JSON conformance test failure lists for C#, JRuby and PHP C PiperOrigin-RevId: 596057023 --- conformance/failure_list_csharp.txt | 6 ++++++ conformance/failure_list_jruby.txt | 33 +++++++++++++++++++++++++++++ conformance/failure_list_php_c.txt | 6 ++++++ 3 files changed, 45 insertions(+) diff --git a/conformance/failure_list_csharp.txt b/conformance/failure_list_csharp.txt index 6c7c0dd0290e0..7cd3728078d09 100644 --- a/conformance/failure_list_csharp.txt +++ b/conformance/failure_list_csharp.txt @@ -1,6 +1,12 @@ Recommended.Proto2.JsonInput.FieldNameExtension.Validator +Recommended.Proto2.JsonInput.BytesFieldBase64Url.JsonOutput +Recommended.Proto2.JsonInput.BytesFieldBase64Url.ProtobufOutput Recommended.Proto3.JsonInput.BytesFieldBase64Url.JsonOutput Recommended.Proto3.JsonInput.BytesFieldBase64Url.ProtobufOutput +Required.Proto2.JsonInput.OneofFieldNullFirst.JsonOutput +Required.Proto2.JsonInput.OneofFieldNullFirst.ProtobufOutput +Required.Proto2.JsonInput.OneofFieldNullSecond.JsonOutput +Required.Proto2.JsonInput.OneofFieldNullSecond.ProtobufOutput Required.Proto3.JsonInput.OneofFieldNullFirst.JsonOutput Required.Proto3.JsonInput.OneofFieldNullFirst.ProtobufOutput Required.Proto3.JsonInput.OneofFieldNullSecond.JsonOutput diff --git a/conformance/failure_list_jruby.txt b/conformance/failure_list_jruby.txt index 6d511a38a6c2a..9c5e06d6225f2 100644 --- a/conformance/failure_list_jruby.txt +++ b/conformance/failure_list_jruby.txt @@ -1,7 +1,33 @@ Recommended.Proto3.FieldMaskNumbersDontRoundTrip.JsonOutput Recommended.Proto3.FieldMaskPathsDontRoundTrip.JsonOutput Recommended.Proto3.FieldMaskTooManyUnderscore.JsonOutput +Recommended.Proto2.JsonInput.BoolFieldAllCapitalFalse +Recommended.Proto2.JsonInput.BoolFieldAllCapitalTrue +Recommended.Proto2.JsonInput.BoolFieldCamelCaseFalse +Recommended.Proto2.JsonInput.BoolFieldCamelCaseTrue +Recommended.Proto2.JsonInput.BoolFieldDoubleQuotedFalse +Recommended.Proto2.JsonInput.BoolFieldDoubleQuotedTrue +Recommended.Proto2.JsonInput.BoolMapFieldKeyNotQuoted +Recommended.Proto2.JsonInput.DoubleFieldInfinityNotQuoted +Recommended.Proto2.JsonInput.DoubleFieldNanNotQuoted +Recommended.Proto2.JsonInput.DoubleFieldNegativeInfinityNotQuoted +Recommended.Proto2.JsonInput.FieldNameDuplicate Recommended.Proto2.JsonInput.FieldNameExtension.Validator +Recommended.Proto2.JsonInput.FieldNameNotQuoted +Recommended.Proto2.JsonInput.FloatFieldInfinityNotQuoted +Recommended.Proto2.JsonInput.FloatFieldNanNotQuoted +Recommended.Proto2.JsonInput.FloatFieldNegativeInfinityNotQuoted +Recommended.Proto2.JsonInput.Int32MapFieldKeyNotQuoted +Recommended.Proto2.JsonInput.Int64MapFieldKeyNotQuoted +Recommended.Proto2.JsonInput.JsonWithComments +Recommended.Proto2.JsonInput.StringFieldSingleQuoteBoth +Recommended.Proto2.JsonInput.StringFieldSingleQuoteKey +Recommended.Proto2.JsonInput.StringFieldSingleQuoteValue +Recommended.Proto2.JsonInput.StringFieldSurrogateInWrongOrder +Recommended.Proto2.JsonInput.StringFieldUnpairedHighSurrogate +Recommended.Proto2.JsonInput.StringFieldUnpairedLowSurrogate +Recommended.Proto2.JsonInput.Uint32MapFieldKeyNotQuoted +Recommended.Proto2.JsonInput.Uint64MapFieldKeyNotQuoted Recommended.Proto3.JsonInput.BoolFieldAllCapitalFalse Recommended.Proto3.JsonInput.BoolFieldAllCapitalTrue Recommended.Proto3.JsonInput.BoolFieldCamelCaseFalse @@ -29,6 +55,13 @@ Recommended.Proto3.JsonInput.StringFieldUnpairedHighSurrogate Recommended.Proto3.JsonInput.StringFieldUnpairedLowSurrogate Recommended.Proto3.JsonInput.Uint32MapFieldKeyNotQuoted Recommended.Proto3.JsonInput.Uint64MapFieldKeyNotQuoted +Required.Proto2.JsonInput.EnumFieldNotQuoted +Required.Proto2.JsonInput.Int32FieldLeadingZero +Required.Proto2.JsonInput.Int32FieldNegativeWithLeadingZero +Required.Proto2.JsonInput.Int32FieldPlusSign +Required.Proto2.JsonInput.RepeatedFieldWrongElementTypeExpectingStringsGotBool +Required.Proto2.JsonInput.RepeatedFieldWrongElementTypeExpectingStringsGotInt +Required.Proto2.JsonInput.StringFieldNotAString Required.Proto3.JsonInput.EnumFieldNotQuoted Required.Proto3.JsonInput.Int32FieldLeadingZero Required.Proto3.JsonInput.Int32FieldNegativeWithLeadingZero diff --git a/conformance/failure_list_php_c.txt b/conformance/failure_list_php_c.txt index 63c7e8a024ccf..df662c320ac76 100644 --- a/conformance/failure_list_php_c.txt +++ b/conformance/failure_list_php_c.txt @@ -1,2 +1,8 @@ Recommended.Proto2.JsonInput.FieldNameExtension.Validator +Required.Proto2.JsonInput.BoolFieldFalse.JsonOutput +Required.Proto2.JsonInput.BoolFieldFalse.ProtobufOutput +Required.Proto2.JsonInput.EnumField.JsonOutput +Required.Proto2.JsonInput.EnumField.ProtobufOutput +Required.Proto2.JsonInput.EnumFieldNumericValueZero.JsonOutput +Required.Proto2.JsonInput.EnumFieldNumericValueZero.ProtobufOutput Required.Proto2.JsonInput.StoresDefaultPrimitive.Validator From f5b50c50227cc37945712bfb3bf8d9504aebf88f Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Fri, 5 Jan 2024 13:06:50 -0800 Subject: [PATCH 190/255] Add self pinning on all message accessors for weak descriptor messages. This guarantees that no matter how you get the instance we pin the type on any use. Previously, casting a `Message*` to some generated type and calling methods on it could trigger undefined behavior unless the cast is down via the ones provided by the library (eg `DownCastToGenerated`). PiperOrigin-RevId: 596066250 --- src/google/protobuf/compiler/cpp/field.cc | 6 ++ .../cpp/field_generators/cord_field.cc | 6 ++ .../cpp/field_generators/enum_field.cc | 8 ++ .../cpp/field_generators/map_field.cc | 2 + .../cpp/field_generators/message_field.cc | 16 ++++ .../cpp/field_generators/primitive_field.cc | 8 ++ .../cpp/field_generators/string_field.cc | 20 ++++ src/google/protobuf/compiler/cpp/helpers.h | 3 + src/google/protobuf/compiler/cpp/message.cc | 93 ++++++++++++++----- 9 files changed, 141 insertions(+), 21 deletions(-) diff --git a/src/google/protobuf/compiler/cpp/field.cc b/src/google/protobuf/compiler/cpp/field.cc index 8c357cfbaff92..265f3790493d3 100644 --- a/src/google/protobuf/compiler/cpp/field.cc +++ b/src/google/protobuf/compiler/cpp/field.cc @@ -78,6 +78,12 @@ std::vector FieldVars(const FieldDescriptor* field, const Options& opts) { {"ns", Namespace(field, opts)}, {"tag_size", WireFormat::TagSize(field->number(), field->type())}, {"deprecated_attr", DeprecatedAttribute(opts, field)}, + Sub("WeakDescriptorSelfPin", + UsingImplicitWeakDescriptor(field->file(), opts) + ? absl::StrCat("::", ProtobufNamespace(opts), + "::internal::StrongReference(default_instance());") + : "") + .WithSuffix(";"), }; if (const auto* oneof = field->containing_oneof()) { diff --git a/src/google/protobuf/compiler/cpp/field_generators/cord_field.cc b/src/google/protobuf/compiler/cpp/field_generators/cord_field.cc index 8924bef438c8b..dfb7418c05272 100644 --- a/src/google/protobuf/compiler/cpp/field_generators/cord_field.cc +++ b/src/google/protobuf/compiler/cpp/field_generators/cord_field.cc @@ -181,6 +181,7 @@ void CordFieldGenerator::GenerateInlineAccessorDefinitions( printer->Emit(R"cc( inline const ::absl::Cord& $classname$::$name$() const ABSL_ATTRIBUTE_LIFETIME_BOUND { + $WeakDescriptorSelfPin$; $annotate_get$; // @@protoc_insertion_point(field_get:$full_name$) return _internal_$name_internal$(); @@ -195,6 +196,7 @@ void CordFieldGenerator::GenerateInlineAccessorDefinitions( )cc"); printer->Emit(R"cc( inline void $classname$::set_$name$(const ::absl::Cord& value) { + $WeakDescriptorSelfPin$; $PrepareSplitMessageForWrite$; _internal_set_$name_internal$(value); $annotate_set$; @@ -203,6 +205,7 @@ void CordFieldGenerator::GenerateInlineAccessorDefinitions( )cc"); printer->Emit(R"cc( inline void $classname$::set_$name$(::absl::string_view value) { + $WeakDescriptorSelfPin$; $PrepareSplitMessageForWrite$; $set_hasbit$; $field$ = value; @@ -345,6 +348,7 @@ void CordOneofFieldGenerator::GenerateInlineAccessorDefinitions( printer->Emit(R"cc( inline const ::absl::Cord& $classname$::$name$() const ABSL_ATTRIBUTE_LIFETIME_BOUND { + $WeakDescriptorSelfPin$; $annotate_get$; // @@protoc_insertion_point(field_get:$full_name$) return _internal_$name_internal$(); @@ -352,6 +356,7 @@ void CordOneofFieldGenerator::GenerateInlineAccessorDefinitions( )cc"); printer->Emit(R"cc( inline void $classname$::set_$name$(const ::absl::Cord& value) { + $WeakDescriptorSelfPin$; if ($not_has_field$) { clear_$oneof_name$(); set_has_$name_internal$(); @@ -368,6 +373,7 @@ void CordOneofFieldGenerator::GenerateInlineAccessorDefinitions( )cc"); printer->Emit(R"cc( inline void $classname$::set_$name$(::absl::string_view value) { + $WeakDescriptorSelfPin$; if ($not_has_field$) { clear_$oneof_name$(); set_has_$name_internal$(); diff --git a/src/google/protobuf/compiler/cpp/field_generators/enum_field.cc b/src/google/protobuf/compiler/cpp/field_generators/enum_field.cc index 8f3a7f1d56650..94419909fdbb6 100644 --- a/src/google/protobuf/compiler/cpp/field_generators/enum_field.cc +++ b/src/google/protobuf/compiler/cpp/field_generators/enum_field.cc @@ -165,6 +165,7 @@ void SingularEnum::GenerateAccessorDeclarations(io::Printer* p) const { void SingularEnum::GenerateInlineAccessorDefinitions(io::Printer* p) const { p->Emit(R"cc( inline $Enum$ $Msg$::$name$() const { + $WeakDescriptorSelfPin$; $annotate_get$; // @@protoc_insertion_point(field_get:$pkg.Msg.field$) return _internal_$name_internal$(); @@ -174,6 +175,7 @@ void SingularEnum::GenerateInlineAccessorDefinitions(io::Printer* p) const { if (is_oneof()) { p->Emit(R"cc( inline void $Msg$::set_$name$($Enum$ value) { + $WeakDescriptorSelfPin$; $PrepareSplitMessageForWrite$; $assert_valid$; if ($not_has_field$) { @@ -194,6 +196,7 @@ void SingularEnum::GenerateInlineAccessorDefinitions(io::Printer* p) const { } else { p->Emit(R"cc( inline void $Msg$::set_$name$($Enum$ value) { + $WeakDescriptorSelfPin$; $PrepareSplitMessageForWrite$; _internal_set_$name_internal$(value); $set_hasbit$; @@ -398,6 +401,7 @@ void RepeatedEnum::GenerateAccessorDeclarations(io::Printer* p) const { void RepeatedEnum::GenerateInlineAccessorDefinitions(io::Printer* p) const { p->Emit(R"cc( inline $Enum$ $Msg$::$name$(int index) const { + $WeakDescriptorSelfPin$; $annotate_get$; // @@protoc_insertion_point(field_get:$pkg.Msg.field$) return static_cast<$Enum$>(_internal_$name_internal$().Get(index)); @@ -405,6 +409,7 @@ void RepeatedEnum::GenerateInlineAccessorDefinitions(io::Printer* p) const { )cc"); p->Emit(R"cc( inline void $Msg$::set_$name$(int index, $Enum$ value) { + $WeakDescriptorSelfPin$; $assert_valid$; _internal_mutable_$name_internal$()->Set(index, value); $annotate_set$ @@ -413,6 +418,7 @@ void RepeatedEnum::GenerateInlineAccessorDefinitions(io::Printer* p) const { )cc"); p->Emit(R"cc( inline void $Msg$::add_$name$($Enum$ value) { + $WeakDescriptorSelfPin$; $assert_valid$; $TsanDetectConcurrentMutation$; _internal_mutable_$name_internal$()->Add(value); @@ -423,6 +429,7 @@ void RepeatedEnum::GenerateInlineAccessorDefinitions(io::Printer* p) const { p->Emit(R"cc( inline const $pb$::RepeatedField& $Msg$::$name$() const ABSL_ATTRIBUTE_LIFETIME_BOUND { + $WeakDescriptorSelfPin$; $annotate_list$; // @@protoc_insertion_point(field_list:$pkg.Msg.field$) return _internal_$name_internal$(); @@ -431,6 +438,7 @@ void RepeatedEnum::GenerateInlineAccessorDefinitions(io::Printer* p) const { p->Emit(R"cc( inline $pb$::RepeatedField* $Msg$::mutable_$name$() ABSL_ATTRIBUTE_LIFETIME_BOUND { + $WeakDescriptorSelfPin$; $annotate_mutable_list$; // @@protoc_insertion_point(field_mutable_list:$pkg.Msg.field$) $TsanDetectConcurrentMutation$; diff --git a/src/google/protobuf/compiler/cpp/field_generators/map_field.cc b/src/google/protobuf/compiler/cpp/field_generators/map_field.cc index 79690963a0960..70f74386b1d3d 100644 --- a/src/google/protobuf/compiler/cpp/field_generators/map_field.cc +++ b/src/google/protobuf/compiler/cpp/field_generators/map_field.cc @@ -222,6 +222,7 @@ void Map::GenerateInlineAccessorDefinitions(io::Printer* p) const { )cc"); p->Emit(R"cc( inline const $Map$& $Msg$::$name$() const ABSL_ATTRIBUTE_LIFETIME_BOUND { + $WeakDescriptorSelfPin$; $annotate_get$; // @@protoc_insertion_point(field_map:$pkg.Msg.field$) return _internal_$name_internal$(); @@ -236,6 +237,7 @@ void Map::GenerateInlineAccessorDefinitions(io::Printer* p) const { )cc"); p->Emit(R"cc( inline $Map$* $Msg$::mutable_$name$() ABSL_ATTRIBUTE_LIFETIME_BOUND { + $WeakDescriptorSelfPin$; $annotate_mutable$; // @@protoc_insertion_point(field_mutable_map:$pkg.Msg.field$) return _internal_mutable_$name_internal$(); diff --git a/src/google/protobuf/compiler/cpp/field_generators/message_field.cc b/src/google/protobuf/compiler/cpp/field_generators/message_field.cc index 318cf4c598e4d..43517cf2c8f39 100644 --- a/src/google/protobuf/compiler/cpp/field_generators/message_field.cc +++ b/src/google/protobuf/compiler/cpp/field_generators/message_field.cc @@ -205,11 +205,13 @@ void SingularMessage::GenerateInlineAccessorDefinitions(io::Printer* p) const { return p != nullptr ? *p : reinterpret_cast($kDefault$); } inline const $Submsg$& $Msg$::$name$() const ABSL_ATTRIBUTE_LIFETIME_BOUND { + $WeakDescriptorSelfPin$; $annotate_get$; // @@protoc_insertion_point(field_get:$pkg.Msg.field$) return _internal_$name_internal$(); } inline void $Msg$::unsafe_arena_set_allocated_$name$($Submsg$* value) { + $WeakDescriptorSelfPin$; $TsanDetectConcurrentMutation$; $PrepareSplitMessageForWrite$; //~ If we're not on an arena, free whatever we were holding before. @@ -223,6 +225,7 @@ void SingularMessage::GenerateInlineAccessorDefinitions(io::Printer* p) const { // @@protoc_insertion_point(field_unsafe_arena_set_allocated:$pkg.Msg.field$) } inline $Submsg$* $Msg$::$release_name$() { + $WeakDescriptorSelfPin$; $TsanDetectConcurrentMutation$; $StrongRef$; $annotate_release$; @@ -245,6 +248,7 @@ void SingularMessage::GenerateInlineAccessorDefinitions(io::Printer* p) const { return released; } inline $Submsg$* $Msg$::unsafe_arena_release_$name$() { + $WeakDescriptorSelfPin$; $TsanDetectConcurrentMutation$; $annotate_release$; // @@protoc_insertion_point(field_release:$pkg.Msg.field$) @@ -268,6 +272,7 @@ void SingularMessage::GenerateInlineAccessorDefinitions(io::Printer* p) const { inline $Submsg$* $Msg$::mutable_$name$() ABSL_ATTRIBUTE_LIFETIME_BOUND { //~ TODO: add tests to make sure all write accessors are //~ able to prepare split message allocation. + $WeakDescriptorSelfPin$; $PrepareSplitMessageForWrite$; $set_hasbit$; $Submsg$* _msg = _internal_mutable_$name_internal$(); @@ -278,6 +283,7 @@ void SingularMessage::GenerateInlineAccessorDefinitions(io::Printer* p) const { //~ We handle the most common case inline, and delegate less common //~ cases to the slow fallback function. inline void $Msg$::set_allocated_$name$($Submsg$* value) { + $WeakDescriptorSelfPin$; $pb$::Arena* message_arena = GetArena(); $TsanDetectConcurrentMutation$; $PrepareSplitMessageForWrite$; @@ -522,6 +528,7 @@ void OneofMessage::GenerateInlineAccessorDefinitions(io::Printer* p) const { p->Emit(R"cc( inline $Submsg$* $Msg$::$release_name$() { + $WeakDescriptorSelfPin$; $annotate_release$; // @@protoc_insertion_point(field_release:$pkg.Msg.field$) $StrongRef$; @@ -546,6 +553,7 @@ void OneofMessage::GenerateInlineAccessorDefinitions(io::Printer* p) const { )cc"); p->Emit(R"cc( inline const $Submsg$& $Msg$::$name$() const ABSL_ATTRIBUTE_LIFETIME_BOUND { + $WeakDescriptorSelfPin$; $annotate_get$; // @@protoc_insertion_point(field_get:$pkg.Msg.field$) return _internal_$name_internal$(); @@ -553,6 +561,7 @@ void OneofMessage::GenerateInlineAccessorDefinitions(io::Printer* p) const { )cc"); p->Emit(R"cc( inline $Submsg$* $Msg$::unsafe_arena_release_$name$() { + $WeakDescriptorSelfPin$; $annotate_release$; // @@protoc_insertion_point(field_unsafe_arena_release:$pkg.Msg.field$) $StrongRef$; @@ -568,6 +577,7 @@ void OneofMessage::GenerateInlineAccessorDefinitions(io::Printer* p) const { )cc"); p->Emit(R"cc( inline void $Msg$::unsafe_arena_set_allocated_$name$($Submsg$* value) { + $WeakDescriptorSelfPin$; // We rely on the oneof clear method to free the earlier contents // of this oneof. We can directly use the pointer we're given to // set the new value. @@ -594,6 +604,7 @@ void OneofMessage::GenerateInlineAccessorDefinitions(io::Printer* p) const { )cc"); p->Emit(R"cc( inline $Submsg$* $Msg$::mutable_$name$() ABSL_ATTRIBUTE_LIFETIME_BOUND { + $WeakDescriptorSelfPin$; $Submsg$* _msg = _internal_mutable_$name_internal$(); $annotate_mutable$; // @@protoc_insertion_point(field_mutable:$pkg.Msg.field$) @@ -742,6 +753,7 @@ void RepeatedMessage::GenerateInlineAccessorDefinitions(io::Printer* p) const { p->Emit(R"cc( inline $Submsg$* $Msg$::mutable_$name$(int index) ABSL_ATTRIBUTE_LIFETIME_BOUND { + $WeakDescriptorSelfPin$; $annotate_mutable$; // @@protoc_insertion_point(field_mutable:$pkg.Msg.field$) $StrongRef$; @@ -751,6 +763,7 @@ void RepeatedMessage::GenerateInlineAccessorDefinitions(io::Printer* p) const { p->Emit(R"cc( inline $pb$::RepeatedPtrField<$Submsg$>* $Msg$::mutable_$name$() ABSL_ATTRIBUTE_LIFETIME_BOUND { + $WeakDescriptorSelfPin$; $annotate_mutable_list$; // @@protoc_insertion_point(field_mutable_list:$pkg.Msg.field$) $StrongRef$; @@ -771,6 +784,7 @@ void RepeatedMessage::GenerateInlineAccessorDefinitions(io::Printer* p) const { R"cc( inline const $Submsg$& $Msg$::$name$(int index) const ABSL_ATTRIBUTE_LIFETIME_BOUND { + $WeakDescriptorSelfPin$; $annotate_get$; // @@protoc_insertion_point(field_get:$pkg.Msg.field$) $StrongRef$; @@ -779,6 +793,7 @@ void RepeatedMessage::GenerateInlineAccessorDefinitions(io::Printer* p) const { )cc"); p->Emit(R"cc( inline $Submsg$* $Msg$::add_$name$() ABSL_ATTRIBUTE_LIFETIME_BOUND { + $WeakDescriptorSelfPin$; $TsanDetectConcurrentMutation$; $Submsg$* _add = _internal_mutable_$name_internal$()->Add(); $annotate_add_mutable$; @@ -789,6 +804,7 @@ void RepeatedMessage::GenerateInlineAccessorDefinitions(io::Printer* p) const { p->Emit(R"cc( inline const $pb$::RepeatedPtrField<$Submsg$>& $Msg$::$name$() const ABSL_ATTRIBUTE_LIFETIME_BOUND { + $WeakDescriptorSelfPin$; $annotate_list$; // @@protoc_insertion_point(field_list:$pkg.Msg.field$) $StrongRef$; diff --git a/src/google/protobuf/compiler/cpp/field_generators/primitive_field.cc b/src/google/protobuf/compiler/cpp/field_generators/primitive_field.cc index e0e1ff3ca4fcb..44dff20400150 100644 --- a/src/google/protobuf/compiler/cpp/field_generators/primitive_field.cc +++ b/src/google/protobuf/compiler/cpp/field_generators/primitive_field.cc @@ -188,6 +188,7 @@ void SingularPrimitive::GenerateInlineAccessorDefinitions( io::Printer* p) const { p->Emit(R"cc( inline $Type$ $Msg$::$name$() const { + $WeakDescriptorSelfPin$; $annotate_get$; // @@protoc_insertion_point(field_get:$pkg.Msg.field$) return _internal_$name_internal$(); @@ -197,6 +198,7 @@ void SingularPrimitive::GenerateInlineAccessorDefinitions( if (is_oneof()) { p->Emit(R"cc( inline void $Msg$::set_$name$($Type$ value) { + $WeakDescriptorSelfPin$; $PrepareSplitMessageForWrite$; if ($not_has_field$) { clear_$oneof_name$(); @@ -216,6 +218,7 @@ void SingularPrimitive::GenerateInlineAccessorDefinitions( } else { p->Emit(R"cc( inline void $Msg$::set_$name$($Type$ value) { + $WeakDescriptorSelfPin$; $PrepareSplitMessageForWrite$; _internal_set_$name_internal$(value); $set_hasbit$; @@ -467,6 +470,7 @@ void RepeatedPrimitive::GenerateInlineAccessorDefinitions( io::Printer* p) const { p->Emit(R"cc( inline $Type$ $Msg$::$name$(int index) const { + $WeakDescriptorSelfPin$; $annotate_get$; // @@protoc_insertion_point(field_get:$pkg.Msg.field$) return _internal_$name_internal$().Get(index); @@ -474,6 +478,7 @@ void RepeatedPrimitive::GenerateInlineAccessorDefinitions( )cc"); p->Emit(R"cc( inline void $Msg$::set_$name$(int index, $Type$ value) { + $WeakDescriptorSelfPin$; $annotate_set$; _internal_mutable_$name_internal$()->Set(index, value); // @@protoc_insertion_point(field_set:$pkg.Msg.field$) @@ -481,6 +486,7 @@ void RepeatedPrimitive::GenerateInlineAccessorDefinitions( )cc"); p->Emit(R"cc( inline void $Msg$::add_$name$($Type$ value) { + $WeakDescriptorSelfPin$; $TsanDetectConcurrentMutation$; _internal_mutable_$name_internal$()->Add(value); $annotate_add$; @@ -490,6 +496,7 @@ void RepeatedPrimitive::GenerateInlineAccessorDefinitions( p->Emit(R"cc( inline const $pb$::RepeatedField<$Type$>& $Msg$::$name$() const ABSL_ATTRIBUTE_LIFETIME_BOUND { + $WeakDescriptorSelfPin$; $annotate_list$; // @@protoc_insertion_point(field_list:$pkg.Msg.field$) return _internal_$name_internal$(); @@ -498,6 +505,7 @@ void RepeatedPrimitive::GenerateInlineAccessorDefinitions( p->Emit(R"cc( inline $pb$::RepeatedField<$Type$>* $Msg$::mutable_$name$() ABSL_ATTRIBUTE_LIFETIME_BOUND { + $WeakDescriptorSelfPin$; $annotate_mutable_list$; // @@protoc_insertion_point(field_mutable_list:$pkg.Msg.field$) $TsanDetectConcurrentMutation$; diff --git a/src/google/protobuf/compiler/cpp/field_generators/string_field.cc b/src/google/protobuf/compiler/cpp/field_generators/string_field.cc index cd1049eea24df..dfd84252bf7a8 100644 --- a/src/google/protobuf/compiler/cpp/field_generators/string_field.cc +++ b/src/google/protobuf/compiler/cpp/field_generators/string_field.cc @@ -448,6 +448,7 @@ void SingularString::GenerateInlineAccessorDefinitions(io::Printer* p) const { R"cc( inline const std::string& $Msg$::$name$() const ABSL_ATTRIBUTE_LIFETIME_BOUND { + $WeakDescriptorSelfPin$; $annotate_get$; // @@protoc_insertion_point(field_get:$pkg.Msg.field$) $if_IsDefault$; @@ -456,6 +457,7 @@ void SingularString::GenerateInlineAccessorDefinitions(io::Printer* p) const { template inline PROTOBUF_ALWAYS_INLINE void $Msg$::set_$name$(Arg_&& arg, Args_... args) { + $WeakDescriptorSelfPin$; $TsanDetectConcurrentMutation$; $PrepareSplitMessageForWrite$; $update_hasbit$; @@ -464,6 +466,7 @@ void SingularString::GenerateInlineAccessorDefinitions(io::Printer* p) const { // @@protoc_insertion_point(field_set:$pkg.Msg.field$) } inline std::string* $Msg$::mutable_$name$() ABSL_ATTRIBUTE_LIFETIME_BOUND { + $WeakDescriptorSelfPin$; $PrepareSplitMessageForWrite$; std::string* _s = _internal_mutable_$name_internal$(); $annotate_mutable$; @@ -488,6 +491,7 @@ void SingularString::GenerateInlineAccessorDefinitions(io::Printer* p) const { return $field_$.Mutable($lazy_args$, $set_args$); } inline std::string* $Msg$::$release_name$() { + $WeakDescriptorSelfPin$; $TsanDetectConcurrentMutation$; $annotate_release$; $PrepareSplitMessageForWrite$; @@ -495,6 +499,7 @@ void SingularString::GenerateInlineAccessorDefinitions(io::Printer* p) const { $release_impl$; } inline void $Msg$::set_allocated_$name$(std::string* value) { + $WeakDescriptorSelfPin$; $TsanDetectConcurrentMutation$; $PrepareSplitMessageForWrite$; $set_allocated_impl$; @@ -870,6 +875,7 @@ void RepeatedString::GenerateInlineAccessorDefinitions(io::Printer* p) const { R"cc( inline std::string* $Msg$::add_$name$() ABSL_ATTRIBUTE_LIFETIME_BOUND { + $WeakDescriptorSelfPin$; $TsanDetectConcurrentMutation$; std::string* _s = _internal_mutable_$name_internal$()->Add(); $annotate_add_mutable$; @@ -878,27 +884,32 @@ void RepeatedString::GenerateInlineAccessorDefinitions(io::Printer* p) const { } inline const std::string& $Msg$::$name$(int index) const ABSL_ATTRIBUTE_LIFETIME_BOUND { + $WeakDescriptorSelfPin$; $annotate_get$; // @@protoc_insertion_point(field_get:$pkg.Msg.field$) return _internal_$name_internal$().$Get$(index$GetExtraArg$); } inline std::string* $Msg$::mutable_$name$(int index) ABSL_ATTRIBUTE_LIFETIME_BOUND { + $WeakDescriptorSelfPin$; $annotate_mutable$; // @@protoc_insertion_point(field_mutable:$pkg.Msg.field$) return _internal_mutable_$name_internal$()->Mutable(index); } inline void $Msg$::set_$name$(int index, const std::string& value) { + $WeakDescriptorSelfPin$; _internal_mutable_$name_internal$()->Mutable(index)->assign(value); $annotate_set$; // @@protoc_insertion_point(field_set:$pkg.Msg.field$) } inline void $Msg$::set_$name$(int index, std::string&& value) { + $WeakDescriptorSelfPin$; _internal_mutable_$name_internal$()->Mutable(index)->assign(std::move(value)); $annotate_set$; // @@protoc_insertion_point(field_set:$pkg.Msg.field$) } inline void $Msg$::set_$name$(int index, const char* value) { + $WeakDescriptorSelfPin$; $DCHK$(value != nullptr); _internal_mutable_$name_internal$()->Mutable(index)->assign(value); $annotate_set$; @@ -906,30 +917,35 @@ void RepeatedString::GenerateInlineAccessorDefinitions(io::Printer* p) const { } inline void $Msg$::set_$name$(int index, const $byte$* value, std::size_t size) { + $WeakDescriptorSelfPin$; _internal_mutable_$name_internal$()->Mutable(index)->assign( reinterpret_cast(value), size); $annotate_set$; // @@protoc_insertion_point(field_set_pointer:$pkg.Msg.field$) } inline void $Msg$::set_$name$(int index, absl::string_view value) { + $WeakDescriptorSelfPin$; _internal_mutable_$name_internal$()->Mutable(index)->assign( value.data(), value.size()); $annotate_set$; // @@protoc_insertion_point(field_set_string_piece:$pkg.Msg.field$) } inline void $Msg$::add_$name$(const std::string& value) { + $WeakDescriptorSelfPin$; $TsanDetectConcurrentMutation$; _internal_mutable_$name_internal$()->Add()->assign(value); $annotate_add$; // @@protoc_insertion_point(field_add:$pkg.Msg.field$) } inline void $Msg$::add_$name$(std::string&& value) { + $WeakDescriptorSelfPin$; $TsanDetectConcurrentMutation$; _internal_mutable_$name_internal$()->Add(std::move(value)); $annotate_add$; // @@protoc_insertion_point(field_add:$pkg.Msg.field$) } inline void $Msg$::add_$name$(const char* value) { + $WeakDescriptorSelfPin$; $DCHK$(value != nullptr); $TsanDetectConcurrentMutation$; _internal_mutable_$name_internal$()->Add()->assign(value); @@ -937,6 +953,7 @@ void RepeatedString::GenerateInlineAccessorDefinitions(io::Printer* p) const { // @@protoc_insertion_point(field_add_char:$pkg.Msg.field$) } inline void $Msg$::add_$name$(const $byte$* value, std::size_t size) { + $WeakDescriptorSelfPin$; $TsanDetectConcurrentMutation$; _internal_mutable_$name_internal$()->Add()->assign( reinterpret_cast(value), size); @@ -944,6 +961,7 @@ void RepeatedString::GenerateInlineAccessorDefinitions(io::Printer* p) const { // @@protoc_insertion_point(field_add_pointer:$pkg.Msg.field$) } inline void $Msg$::add_$name$(absl::string_view value) { + $WeakDescriptorSelfPin$; $TsanDetectConcurrentMutation$; _internal_mutable_$name_internal$()->Add()->assign(value.data(), value.size()); @@ -952,12 +970,14 @@ void RepeatedString::GenerateInlineAccessorDefinitions(io::Printer* p) const { } inline const ::$proto_ns$::RepeatedPtrField& $Msg$::$name$() const ABSL_ATTRIBUTE_LIFETIME_BOUND { + $WeakDescriptorSelfPin$; $annotate_list$; // @@protoc_insertion_point(field_list:$pkg.Msg.field$) return _internal_$name_internal$(); } inline ::$proto_ns$::RepeatedPtrField* $Msg$::mutable_$name$() ABSL_ATTRIBUTE_LIFETIME_BOUND { + $WeakDescriptorSelfPin$; $annotate_mutable_list$; // @@protoc_insertion_point(field_mutable_list:$pkg.Msg.field$) $TsanDetectConcurrentMutation$; diff --git a/src/google/protobuf/compiler/cpp/helpers.h b/src/google/protobuf/compiler/cpp/helpers.h index 64e2a82aa4fdb..86aefb3d206c8 100644 --- a/src/google/protobuf/compiler/cpp/helpers.h +++ b/src/google/protobuf/compiler/cpp/helpers.h @@ -802,7 +802,10 @@ bool IsImplicitWeakField(const FieldDescriptor* field, const Options& options, inline std::string SimpleBaseClass(const Descriptor* desc, const Options& options) { + // The only base class we have derived from `Message`. if (!HasDescriptorMethods(desc->file(), options)) return ""; + // We don't use the base class to be able to inject the weak descriptor pins. + if (UsingImplicitWeakDescriptor(desc->file(), options)) return ""; if (desc->extension_range_count() != 0) return ""; // Don't use a simple base class if the field tracking is enabled. This // ensures generating all methods to track. diff --git a/src/google/protobuf/compiler/cpp/message.cc b/src/google/protobuf/compiler/cpp/message.cc index cbd5aa9d5e281..dd173b7bf7c65 100644 --- a/src/google/protobuf/compiler/cpp/message.cc +++ b/src/google/protobuf/compiler/cpp/message.cc @@ -472,24 +472,35 @@ bool MaybeEmitHaswordsCheck(ChunkIterator it, ChunkIterator end, return true; } -absl::flat_hash_map ClassVars( - const Descriptor* desc, Options opts) { - absl::flat_hash_map vars = MessageVars(desc); - - vars.emplace("pkg", Namespace(desc, opts)); - vars.emplace("Msg", ClassName(desc, false)); - vars.emplace("pkg::Msg", QualifiedClassName(desc, opts)); - vars.emplace("pkg.Msg", desc->full_name()); - - // Old-style names, to be removed once all usages are gone in this and other - // files. - vars.emplace("classname", ClassName(desc, false)); - vars.emplace("classtype", QualifiedClassName(desc, opts)); - vars.emplace("full_name", desc->full_name()); - vars.emplace("superclass", SuperClassName(desc, opts)); +using Sub = ::google::protobuf::io::Printer::Sub; +std::vector ClassVars(const Descriptor* desc, Options opts) { + std::vector vars = { + {"pkg", Namespace(desc, opts)}, + {"Msg", ClassName(desc, false)}, + {"pkg::Msg", QualifiedClassName(desc, opts)}, + {"pkg.Msg", desc->full_name()}, + + // Old-style names, to be removed once all usages are gone in this and + // other files. + {"classname", ClassName(desc, false)}, + {"classtype", QualifiedClassName(desc, opts)}, + {"full_name", desc->full_name()}, + {"superclass", SuperClassName(desc, opts)}, + + Sub("WeakDescriptorSelfPin", + UsingImplicitWeakDescriptor(desc->file(), opts) + ? absl::StrCat("::", ProtobufNamespace(opts), + "::internal::StrongReference(default_instance());") + : "") + .WithSuffix(";"), + }; + + for (auto& pair : MessageVars(desc)) { + vars.push_back({std::string(pair.first), pair.second}); + } for (auto& pair : UnknownFieldsVars(desc, opts)) { - vars.emplace(pair); + vars.push_back({std::string(pair.first), pair.second}); } return vars; @@ -747,6 +758,7 @@ void MessageGenerator::GenerateFieldAccessorDeclarations(io::Printer* p) { inline bool HasExtension( const $pbi$::ExtensionIdentifier<$Msg$, _proto_TypeTraits, _field_type, _is_packed>& id) const { + $WeakDescriptorSelfPin$; $annotate_extension_has$; return $extensions$.Has(id.number()); } @@ -756,6 +768,7 @@ void MessageGenerator::GenerateFieldAccessorDeclarations(io::Printer* p) { inline void ClearExtension( const $pbi$::ExtensionIdentifier<$Msg$, _proto_TypeTraits, _field_type, _is_packed>& id) { + $WeakDescriptorSelfPin$; $extensions$.ClearExtension(id.number()); $annotate_extension_clear$; } @@ -765,6 +778,7 @@ void MessageGenerator::GenerateFieldAccessorDeclarations(io::Printer* p) { inline int ExtensionSize( const $pbi$::ExtensionIdentifier<$Msg$, _proto_TypeTraits, _field_type, _is_packed>& id) const { + $WeakDescriptorSelfPin$; $annotate_extension_repeated_size$; return $extensions$.ExtensionSize(id.number()); } @@ -775,6 +789,7 @@ void MessageGenerator::GenerateFieldAccessorDeclarations(io::Printer* p) { inline typename _proto_TypeTraits::Singular::ConstType GetExtension( const $pbi$::ExtensionIdentifier<$Msg$, _proto_TypeTraits, _field_type, _is_packed>& id) const { + $WeakDescriptorSelfPin$; $annotate_extension_get$; return _proto_TypeTraits::Get(id.number(), $extensions$, id.default_value()); } @@ -786,6 +801,7 @@ void MessageGenerator::GenerateFieldAccessorDeclarations(io::Printer* p) { const $pbi$::ExtensionIdentifier<$Msg$, _proto_TypeTraits, _field_type, _is_packed>& id) const ABSL_ATTRIBUTE_LIFETIME_BOUND { + $WeakDescriptorSelfPin$; $annotate_extension_get$; return _proto_TypeTraits::Get(id.number(), $extensions$, id.default_value()); } @@ -796,6 +812,7 @@ void MessageGenerator::GenerateFieldAccessorDeclarations(io::Printer* p) { const $pbi$::ExtensionIdentifier<$Msg$, _proto_TypeTraits, _field_type, _is_packed>& id) ABSL_ATTRIBUTE_LIFETIME_BOUND { + $WeakDescriptorSelfPin$; $annotate_extension_mutable$; return _proto_TypeTraits::Mutable(id.number(), _field_type, &$extensions$); } @@ -806,6 +823,7 @@ void MessageGenerator::GenerateFieldAccessorDeclarations(io::Printer* p) { const $pbi$::ExtensionIdentifier<$Msg$, _proto_TypeTraits, _field_type, _is_packed>& id, typename _proto_TypeTraits::Singular::ConstType value) { + $WeakDescriptorSelfPin$; _proto_TypeTraits::Set(id.number(), _field_type, value, &$extensions$); $annotate_extension_set$; } @@ -816,6 +834,7 @@ void MessageGenerator::GenerateFieldAccessorDeclarations(io::Printer* p) { const $pbi$::ExtensionIdentifier<$Msg$, _proto_TypeTraits, _field_type, _is_packed>& id, typename _proto_TypeTraits::Singular::MutableType value) { + $WeakDescriptorSelfPin$; _proto_TypeTraits::SetAllocated(id.number(), _field_type, value, &$extensions$); $annotate_extension_set$; @@ -826,6 +845,7 @@ void MessageGenerator::GenerateFieldAccessorDeclarations(io::Printer* p) { const $pbi$::ExtensionIdentifier<$Msg$, _proto_TypeTraits, _field_type, _is_packed>& id, typename _proto_TypeTraits::Singular::MutableType value) { + $WeakDescriptorSelfPin$; _proto_TypeTraits::UnsafeArenaSetAllocated(id.number(), _field_type, value, &$extensions$); $annotate_extension_set$; @@ -837,6 +857,7 @@ void MessageGenerator::GenerateFieldAccessorDeclarations(io::Printer* p) { ReleaseExtension( const $pbi$::ExtensionIdentifier<$Msg$, _proto_TypeTraits, _field_type, _is_packed>& id) { + $WeakDescriptorSelfPin$; $annotate_extension_release$; return _proto_TypeTraits::Release(id.number(), _field_type, &$extensions$); } @@ -846,6 +867,7 @@ void MessageGenerator::GenerateFieldAccessorDeclarations(io::Printer* p) { UnsafeArenaReleaseExtension( const $pbi$::ExtensionIdentifier<$Msg$, _proto_TypeTraits, _field_type, _is_packed>& id) { + $WeakDescriptorSelfPin$; $annotate_extension_release$; return _proto_TypeTraits::UnsafeArenaRelease(id.number(), _field_type, &$extensions$); @@ -858,6 +880,7 @@ void MessageGenerator::GenerateFieldAccessorDeclarations(io::Printer* p) { const $pbi$::ExtensionIdentifier<$Msg$, _proto_TypeTraits, _field_type, _is_packed>& id, int index) const { + $WeakDescriptorSelfPin$; $annotate_repeated_extension_get$; return _proto_TypeTraits::Get(id.number(), $extensions$, index); } @@ -869,6 +892,7 @@ void MessageGenerator::GenerateFieldAccessorDeclarations(io::Printer* p) { const $pbi$::ExtensionIdentifier<$Msg$, _proto_TypeTraits, _field_type, _is_packed>& id, int index) const ABSL_ATTRIBUTE_LIFETIME_BOUND { + $WeakDescriptorSelfPin$; $annotate_repeated_extension_get$; return _proto_TypeTraits::Get(id.number(), $extensions$, index); } @@ -879,6 +903,7 @@ void MessageGenerator::GenerateFieldAccessorDeclarations(io::Printer* p) { const $pbi$::ExtensionIdentifier<$Msg$, _proto_TypeTraits, _field_type, _is_packed>& id, int index) ABSL_ATTRIBUTE_LIFETIME_BOUND { + $WeakDescriptorSelfPin$; $annotate_repeated_extension_mutable$; return _proto_TypeTraits::Mutable(id.number(), index, &$extensions$); } @@ -889,6 +914,7 @@ void MessageGenerator::GenerateFieldAccessorDeclarations(io::Printer* p) { const $pbi$::ExtensionIdentifier<$Msg$, _proto_TypeTraits, _field_type, _is_packed>& id, int index, typename _proto_TypeTraits::Repeated::ConstType value) { + $WeakDescriptorSelfPin$; _proto_TypeTraits::Set(id.number(), index, value, &$extensions$); $annotate_repeated_extension_set$; } @@ -899,6 +925,7 @@ void MessageGenerator::GenerateFieldAccessorDeclarations(io::Printer* p) { const $pbi$::ExtensionIdentifier<$Msg$, _proto_TypeTraits, _field_type, _is_packed>& id) ABSL_ATTRIBUTE_LIFETIME_BOUND { + $WeakDescriptorSelfPin$; typename _proto_TypeTraits::Repeated::MutableType to_add = _proto_TypeTraits::Add(id.number(), _field_type, &$extensions$); $annotate_repeated_extension_add_mutable$; @@ -911,6 +938,7 @@ void MessageGenerator::GenerateFieldAccessorDeclarations(io::Printer* p) { const $pbi$::ExtensionIdentifier<$Msg$, _proto_TypeTraits, _field_type, _is_packed>& id, typename _proto_TypeTraits::Repeated::ConstType value) { + $WeakDescriptorSelfPin$; _proto_TypeTraits::Add(id.number(), _field_type, _is_packed, value, &$extensions$); $annotate_repeated_extension_add$; @@ -923,6 +951,7 @@ void MessageGenerator::GenerateFieldAccessorDeclarations(io::Printer* p) { const $pbi$::ExtensionIdentifier<$Msg$, _proto_TypeTraits, _field_type, _is_packed>& id) const ABSL_ATTRIBUTE_LIFETIME_BOUND { + $WeakDescriptorSelfPin$; $annotate_repeated_extension_list$; return _proto_TypeTraits::GetRepeated(id.number(), $extensions$); } @@ -934,6 +963,7 @@ void MessageGenerator::GenerateFieldAccessorDeclarations(io::Printer* p) { const $pbi$::ExtensionIdentifier<$Msg$, _proto_TypeTraits, _field_type, _is_packed>& id) ABSL_ATTRIBUTE_LIFETIME_BOUND { + $WeakDescriptorSelfPin$; $annotate_repeated_extension_list_mutable$; return _proto_TypeTraits::MutableRepeated(id.number(), _field_type, _is_packed, &$extensions$); @@ -971,6 +1001,7 @@ void MessageGenerator::GenerateSingularFieldHasBits( p->Emit( R"cc( inline bool $classname$::has_$name$() const { + $WeakDescriptorSelfPin$; $annotate_has$; return $weak_field_map$.Has($number$); } @@ -995,6 +1026,7 @@ void MessageGenerator::GenerateSingularFieldHasBits( .WithSuffix(";")}, R"cc( inline bool $classname$::has_$name$() const { + $WeakDescriptorSelfPin$; $annotate_has$; bool value = ($has_bits$[$has_array_index$] & $has_mask$) != 0; $ASSUME$; @@ -1054,6 +1086,7 @@ void MessageGenerator::GenerateOneofMemberHasBits(const FieldDescriptor* field, auto t = p->WithVars(MakeTrackerCalls(field, options_)); p->Emit(R"cc( inline bool $classname$::has_$name$() const { + $WeakDescriptorSelfPin$; $annotate_has$; return $has_field$; } @@ -1115,6 +1148,7 @@ void MessageGenerator::GenerateFieldClear(const FieldDescriptor* field, R"cc( $inline $void $classname$::clear_$name$() { PROTOBUF_TSAN_WRITE(&_impl_._tsan_detect_race); + $WeakDescriptorSelfPin$; $body$; $annotate_clear$; } @@ -1127,9 +1161,10 @@ class AccessorVerifier { public: using SourceLocation = io::Printer::SourceLocation; - AccessorVerifier(const FieldDescriptor* field) : field_(field) {} + explicit AccessorVerifier(const FieldDescriptor* field) : field_(field) {} ~AccessorVerifier() { ABSL_CHECK(!needs_annotate_) << Error(SourceLocation::current()); + ABSL_CHECK(!needs_weak_descriptor_pin_) << Error(SourceLocation::current()); } void operator()(absl::string_view label, io::Printer::SourceLocation loc) { @@ -1137,14 +1172,17 @@ class AccessorVerifier { // All accessors use $name$ or $release_name$ when constructing the // function name. We hook into those to determine that an accessor is // starting. - ABSL_CHECK(!needs_annotate_) << Error(loc); + SetTracker(needs_annotate_, true, loc); + SetTracker(needs_weak_descriptor_pin_, true, loc); loc_ = loc; - needs_annotate_ = true; } else if (absl::StartsWith(label, "annotate")) { // All annotation labels start with `annotate`. Eg `annotate_get`. - ABSL_CHECK(needs_annotate_) << Error(loc); + SetTracker(needs_annotate_, false, loc); + loc_ = loc; + } else if (label == "WeakDescriptorSelfPin") { + // The self pin for weak descriptor types must be on every accessor. + SetTracker(needs_weak_descriptor_pin_, false, loc); loc_ = loc; - needs_annotate_ = false; } } @@ -1155,7 +1193,13 @@ class AccessorVerifier { loc_.file_name(), loc_.line()); } + void SetTracker(bool& v, bool new_value, SourceLocation loc) { + ABSL_CHECK_NE(v, new_value) << Error(loc); + v = new_value; + } + bool needs_annotate_ = false; + bool needs_weak_descriptor_pin_ = false; // We keep these fields for error reporting. const FieldDescriptor* field_; // On error, we report two locations: the current one and the last one. This @@ -1194,6 +1238,7 @@ void MessageGenerator::GenerateFieldAccessorDefinitions(io::Printer* p) { return _internal_$name_internal$().size(); } inline int $classname$::$name$_size() const { + $WeakDescriptorSelfPin$; $annotate_size$; return _internal_$name_internal$_size(); } @@ -2712,6 +2757,7 @@ void MessageGenerator::GenerateSharedDestructorCode(io::Printer* p) { R"cc( inline void $classname$::SharedDtor() { $DCHK$(GetArena() == nullptr); + $WeakDescriptorSelfPin$; $field_dtors$; $split_field_dtors$; $oneof_field_dtors$; @@ -3453,6 +3499,7 @@ void MessageGenerator::GenerateSwap(io::Printer* p) { "{\n"); format.Indent(); format("using std::swap;\n"); + format("$WeakDescriptorSelfPin$"); if (HasGeneratedMethods(descriptor_->file(), options_)) { if (descriptor_->extension_range_count() > 0) { @@ -3657,6 +3704,7 @@ void MessageGenerator::GenerateClassSpecificMergeImpl(io::Printer* p) { format( "void $classname$::MergeImpl(::$proto_ns$::MessageLite& to_msg, const " "::$proto_ns$::MessageLite& from_msg) {\n" + "$WeakDescriptorSelfPin$" " auto* const _this = static_cast<$classname$*>(&to_msg);\n" " auto& from = static_cast(from_msg);\n"); } @@ -4421,6 +4469,7 @@ void MessageGenerator::GenerateByteSize(io::Printer* p) { p->Emit( R"cc( PROTOBUF_NOINLINE ::size_t $classname$::ByteSizeLong() const { + $WeakDescriptorSelfPin$; $annotate_bytesize$; // @@protoc_insertion_point(message_set_byte_size_start:$full_name$) ::size_t total_size = $extensions$.MessageSetByteSize(); @@ -4437,6 +4486,7 @@ void MessageGenerator::GenerateByteSize(io::Printer* p) { Formatter format(p); format( "::size_t $classname$::ByteSizeLong() const {\n" + "$WeakDescriptorSelfPin$" "$annotate_bytesize$" "// @@protoc_insertion_point(message_byte_size_start:$full_name$)\n"); format.Indent(); @@ -4689,6 +4739,7 @@ void MessageGenerator::GenerateIsInitialized(io::Printer* p) { }, R"cc( PROTOBUF_NOINLINE bool $classname$::IsInitialized() const { + $WeakDescriptorSelfPin$; $test_extensions$; $test_required_fields$; $test_ordinary_fields$; From d1b328ace390310cedef3840929c16d628ba60bc Mon Sep 17 00:00:00 2001 From: Alyssa Haroldsen Date: Fri, 5 Jan 2024 13:07:40 -0800 Subject: [PATCH 191/255] Fix nested enum generation when enums are the sole nested types PiperOrigin-RevId: 596066421 --- rust/test/shared/enum_test.rs | 7 +++++++ src/google/protobuf/compiler/rust/message.cc | 4 ++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/rust/test/shared/enum_test.rs b/rust/test/shared/enum_test.rs index ced4c6c4eb04a..5bf69af04003b 100644 --- a/rust/test/shared/enum_test.rs +++ b/rust/test/shared/enum_test.rs @@ -19,6 +19,13 @@ fn test_nested_enum_values() { assert_that!(i32::from(proto2_unittest::TestAllTypes_::NestedEnum::Neg), eq(-1)); } +#[test] +fn test_isolated_nested_enum() { + // Ensure that the enum is generated even when it's the only nested type for the + // message. + assert_that!(i32::from(proto2_unittest::TestRequiredEnumNoMask_::NestedEnum::Foo), eq(2)); +} + #[test] fn test_enum_value_name_same_as_enum() { assert_that!(i32::from(enums::TestEnumValueNameSameAsEnum::TestEnumValueNameSameAsEnum), eq(1)); diff --git a/src/google/protobuf/compiler/rust/message.cc b/src/google/protobuf/compiler/rust/message.cc index 4230da200a5aa..6b5bfa877ac95 100644 --- a/src/google/protobuf/compiler/rust/message.cc +++ b/src/google/protobuf/compiler/rust/message.cc @@ -390,9 +390,9 @@ void GenerateRs(Context& ctx, const Descriptor& msg) { }}, {"nested_in_msg", [&] { - // If we have no nested types or oneofs, bail out without + // If we have no nested types, enums, or oneofs, bail out without // emitting an empty mod SomeMsg_. - if (msg.nested_type_count() == 0 && + if (msg.nested_type_count() == 0 && msg.enum_type_count() == 0 && msg.real_oneof_decl_count() == 0) { return; } From 7b2e9aac80cc8ba5c00050a0a8ca6df14e835991 Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Fri, 5 Jan 2024 13:33:53 -0800 Subject: [PATCH 192/255] Change the ids used the unset field tracking to be Message+FieldDescriptor. The absolute address of a member is unstable and can be invalidated by changes to other fields. For example, for split fields. PiperOrigin-RevId: 596072639 --- src/google/protobuf/message.h | 1 - src/google/protobuf/text_format.cc | 36 +++--- src/google/protobuf/text_format.h | 20 +-- src/google/protobuf/text_format_unittest.cc | 120 +++++++----------- .../protobuf/util/message_differencer.cc | 6 +- .../util/message_differencer_unittest.cc | 23 +--- 6 files changed, 82 insertions(+), 124 deletions(-) diff --git a/src/google/protobuf/message.h b/src/google/protobuf/message.h index d25c2d7815e22..8886cd1846513 100644 --- a/src/google/protobuf/message.h +++ b/src/google/protobuf/message.h @@ -977,7 +977,6 @@ class PROTOBUF_EXPORT Reflection final { return schema_.IsSplit(field); } - friend class google::protobuf::TextFormat; friend class FastReflectionBase; friend class FastReflectionMessageMutator; friend bool internal::IsDescendant(Message& root, const Message& message); diff --git a/src/google/protobuf/text_format.cc b/src/google/protobuf/text_format.cc index 7637a368a7b90..9fc9ecc537127 100644 --- a/src/google/protobuf/text_format.cc +++ b/src/google/protobuf/text_format.cc @@ -297,12 +297,9 @@ const Descriptor* DefaultFinderFindAnyType(const Message& message, } } // namespace -const void* TextFormat::Parser::UnsetFieldsMetadata::GetUnsetFieldAddress( - const Message& message, const Reflection& reflection, - const FieldDescriptor& fd) { - // reflection->GetRaw() is a simple cast for any non-repeated type, so for - // simplicity we just pass in char as the template argument. - return &reflection.GetRaw(message, &fd); +auto TextFormat::Parser::UnsetFieldsMetadata::GetUnsetFieldId( + const Message& message, const FieldDescriptor& fd) -> Id { + return {&message, &fd}; } // =========================================================================== @@ -845,20 +842,19 @@ class TextFormat::Parser::ParserImpl { // the message and the new value are the default. If the existing field value is // not the default, setting it to the default should not be treated as a no-op. // The pointer of this is kept in no_op_fields_ for bookkeeping. -#define SET_FIELD(CPPTYPE, CPPTYPELCASE, VALUE) \ - if (field->is_repeated()) { \ - reflection->Add##CPPTYPE(message, field, VALUE); \ - } else { \ - if (no_op_fields_ && !field->has_presence() && \ - field->default_value_##CPPTYPELCASE() == \ - reflection->Get##CPPTYPE(*message, field) && \ - field->default_value_##CPPTYPELCASE() == VALUE) { \ - no_op_fields_->addresses_.insert( \ - UnsetFieldsMetadata::GetUnsetFieldAddress(*message, *reflection, \ - *field)); \ - } else { \ - reflection->Set##CPPTYPE(message, field, std::move(VALUE)); \ - } \ +#define SET_FIELD(CPPTYPE, CPPTYPELCASE, VALUE) \ + if (field->is_repeated()) { \ + reflection->Add##CPPTYPE(message, field, VALUE); \ + } else { \ + if (no_op_fields_ && !field->has_presence() && \ + field->default_value_##CPPTYPELCASE() == \ + reflection->Get##CPPTYPE(*message, field) && \ + field->default_value_##CPPTYPELCASE() == VALUE) { \ + no_op_fields_->ids_.insert( \ + UnsetFieldsMetadata::GetUnsetFieldId(*message, *field)); \ + } else { \ + reflection->Set##CPPTYPE(message, field, std::move(VALUE)); \ + } \ } switch (field->cpp_type()) { diff --git a/src/google/protobuf/text_format.h b/src/google/protobuf/text_format.h index f80aefb713f37..cd1ce1805c0bb 100644 --- a/src/google/protobuf/text_format.h +++ b/src/google/protobuf/text_format.h @@ -726,25 +726,25 @@ class PROTOBUF_EXPORT TextFormat { // the maximum allowed nesting of proto messages. void SetRecursionLimit(int limit) { recursion_limit_ = limit; } - // Uniquely addresses fields in a message that was explicitly unset in + // Metadata representing all the fields that were explicitly unset in // textproto. Example: // "some_int_field: 0" - // where some_int_field is non-optional. + // where some_int_field has implicit presence. // - // This class should only be used to pass data between the text_format - // parser and the MessageDifferencer. + // This class should only be used to pass data between TextFormat and the + // MessageDifferencer. class UnsetFieldsMetadata { public: UnsetFieldsMetadata() = default; private: - // Return a pointer to the unset field in the given message. - static const void* GetUnsetFieldAddress(const Message& message, - const Reflection& reflection, - const FieldDescriptor& fd); + using Id = std::pair; + // Return an id representing the unset field in the given message. + static Id GetUnsetFieldId(const Message& message, + const FieldDescriptor& fd); - // List of addresses of explicitly unset proto fields. - absl::flat_hash_set addresses_; + // List of ids of explicitly unset proto fields. + absl::flat_hash_set ids_; friend class ::google::protobuf::internal:: UnsetFieldsMetadataMessageDifferencerTestUtil; diff --git a/src/google/protobuf/text_format_unittest.cc b/src/google/protobuf/text_format_unittest.cc index c3b3fd29ba636..5f456e9d5c000 100644 --- a/src/google/protobuf/text_format_unittest.cc +++ b/src/google/protobuf/text_format_unittest.cc @@ -44,6 +44,7 @@ #include "google/protobuf/test_util.h" #include "google/protobuf/test_util2.h" #include "google/protobuf/unittest.pb.h" +#include "google/protobuf/unittest.pb.h" #include "google/protobuf/unittest_mset.pb.h" #include "google/protobuf/unittest_mset_wire_format.pb.h" #include "google/protobuf/unittest_proto3.pb.h" @@ -59,21 +60,13 @@ namespace protobuf { namespace internal { class UnsetFieldsMetadataTextFormatTestUtil { public: - static std::vector GetRawAddresses( + static const auto& GetRawIds( const TextFormat::Parser::UnsetFieldsMetadata& metadata) { - return std::vector(metadata.addresses_.begin(), - metadata.addresses_.end()); - } - static const void* GetAddress(const Message& message, - const Reflection& reflection, - const FieldDescriptor& fd) { - return TextFormat::Parser::UnsetFieldsMetadata::GetUnsetFieldAddress( - message, reflection, fd); + return metadata.ids_; } - - static int32_t NumFields( - const TextFormat::Parser::UnsetFieldsMetadata& metadata) { - return metadata.addresses_.size(); + static auto GetId(const Message& message, absl::string_view field) { + return TextFormat::Parser::UnsetFieldsMetadata::GetUnsetFieldId( + message, *message.GetDescriptor()->FindFieldByName(field)); } }; } // namespace internal @@ -85,6 +78,7 @@ using ::google::protobuf::internal::kDebugStringSilentMarker; using ::google::protobuf::internal::UnsetFieldsMetadataTextFormatTestUtil; using ::testing::AllOf; using ::testing::HasSubstr; +using ::testing::UnorderedElementsAre; // A basic string with different escapable characters for testing. constexpr absl::string_view kEscapeTestString = @@ -1029,14 +1023,15 @@ TEST_F(TextFormatTest, PopulatesNoOpFields) { TextFormat::Parser parser; TextFormat::Parser::UnsetFieldsMetadata no_op_fields; parser.OutputNoOpFields(&no_op_fields); + using Peer = UnsetFieldsMetadataTextFormatTestUtil; { no_op_fields = {}; const absl::string_view singular_int_parse_string = "optional_int32: 0"; EXPECT_TRUE(TextFormat::ParseFromString(singular_int_parse_string, &proto)); EXPECT_TRUE(parser.ParseFromString(singular_int_parse_string, &proto)); - EXPECT_EQ(UnsetFieldsMetadataTextFormatTestUtil::NumFields(no_op_fields), - 1); + EXPECT_THAT(Peer::GetRawIds(no_op_fields), + UnorderedElementsAre(Peer::GetId(proto, "optional_int32"))); } { no_op_fields = {}; @@ -1044,8 +1039,8 @@ TEST_F(TextFormatTest, PopulatesNoOpFields) { EXPECT_TRUE( TextFormat::ParseFromString(singular_bool_parse_string, &proto)); EXPECT_TRUE(parser.ParseFromString(singular_bool_parse_string, &proto)); - EXPECT_EQ(UnsetFieldsMetadataTextFormatTestUtil::NumFields(no_op_fields), - 1); + EXPECT_THAT(Peer::GetRawIds(no_op_fields), + UnorderedElementsAre(Peer::GetId(proto, "optional_bool"))); } { no_op_fields = {}; @@ -1054,8 +1049,8 @@ TEST_F(TextFormatTest, PopulatesNoOpFields) { EXPECT_TRUE( TextFormat::ParseFromString(singular_string_parse_string, &proto)); EXPECT_TRUE(parser.ParseFromString(singular_string_parse_string, &proto)); - EXPECT_EQ(UnsetFieldsMetadataTextFormatTestUtil::NumFields(no_op_fields), - 1); + EXPECT_THAT(Peer::GetRawIds(no_op_fields), + UnorderedElementsAre(Peer::GetId(proto, "optional_string"))); } { no_op_fields = {}; @@ -1064,8 +1059,9 @@ TEST_F(TextFormatTest, PopulatesNoOpFields) { EXPECT_TRUE( TextFormat::ParseFromString(nested_message_parse_string, &proto)); EXPECT_TRUE(parser.ParseFromString(nested_message_parse_string, &proto)); - EXPECT_EQ(UnsetFieldsMetadataTextFormatTestUtil::NumFields(no_op_fields), - 1); + EXPECT_THAT(Peer::GetRawIds(no_op_fields), + UnorderedElementsAre( + Peer::GetId(proto.optional_nested_message(), "bb"))); } { no_op_fields = {}; @@ -1074,8 +1070,7 @@ TEST_F(TextFormatTest, PopulatesNoOpFields) { EXPECT_TRUE( TextFormat::ParseFromString(nested_message_parse_string, &proto)); EXPECT_TRUE(parser.ParseFromString(nested_message_parse_string, &proto)); - EXPECT_EQ(UnsetFieldsMetadataTextFormatTestUtil::NumFields(no_op_fields), - 0); + EXPECT_THAT(Peer::GetRawIds(no_op_fields), UnorderedElementsAre()); } { no_op_fields = {}; @@ -1084,8 +1079,9 @@ TEST_F(TextFormatTest, PopulatesNoOpFields) { EXPECT_TRUE( TextFormat::ParseFromString(foreign_message_parse_string, &proto)); EXPECT_TRUE(parser.ParseFromString(foreign_message_parse_string, &proto)); - EXPECT_EQ(UnsetFieldsMetadataTextFormatTestUtil::NumFields(no_op_fields), - 1); + EXPECT_THAT(Peer::GetRawIds(no_op_fields), + UnorderedElementsAre( + Peer::GetId(proto.optional_foreign_message(), "c"))); } { no_op_fields = {}; @@ -1093,8 +1089,9 @@ TEST_F(TextFormatTest, PopulatesNoOpFields) { "optional_nested_enum: ZERO "; EXPECT_TRUE(TextFormat::ParseFromString(nested_enum_parse_string, &proto)); EXPECT_TRUE(parser.ParseFromString(nested_enum_parse_string, &proto)); - EXPECT_EQ(UnsetFieldsMetadataTextFormatTestUtil::NumFields(no_op_fields), - 1); + EXPECT_THAT( + Peer::GetRawIds(no_op_fields), + UnorderedElementsAre(Peer::GetId(proto, "optional_nested_enum"))); } { no_op_fields = {}; @@ -1102,8 +1099,9 @@ TEST_F(TextFormatTest, PopulatesNoOpFields) { "optional_foreign_enum: FOREIGN_ZERO "; EXPECT_TRUE(TextFormat::ParseFromString(foreign_enum_parse_string, &proto)); EXPECT_TRUE(parser.ParseFromString(foreign_enum_parse_string, &proto)); - EXPECT_EQ(UnsetFieldsMetadataTextFormatTestUtil::NumFields(no_op_fields), - 1); + EXPECT_THAT( + Peer::GetRawIds(no_op_fields), + UnorderedElementsAre(Peer::GetId(proto, "optional_foreign_enum"))); } { no_op_fields = {}; @@ -1111,16 +1109,17 @@ TEST_F(TextFormatTest, PopulatesNoOpFields) { "optional_string_piece: '' "; EXPECT_TRUE(TextFormat::ParseFromString(string_piece_parse_string, &proto)); EXPECT_TRUE(parser.ParseFromString(string_piece_parse_string, &proto)); - EXPECT_EQ(UnsetFieldsMetadataTextFormatTestUtil::NumFields(no_op_fields), - 1); + EXPECT_THAT( + Peer::GetRawIds(no_op_fields), + UnorderedElementsAre(Peer::GetId(proto, "optional_string_piece"))); } { no_op_fields = {}; const absl::string_view cord_parse_string = "optional_cord: '' "; EXPECT_TRUE(TextFormat::ParseFromString(cord_parse_string, &proto)); EXPECT_TRUE(parser.ParseFromString(cord_parse_string, &proto)); - EXPECT_EQ(UnsetFieldsMetadataTextFormatTestUtil::NumFields(no_op_fields), - 1); + EXPECT_THAT(Peer::GetRawIds(no_op_fields), + UnorderedElementsAre(Peer::GetId(proto, "optional_cord"))); } { no_op_fields = {}; @@ -1129,8 +1128,7 @@ TEST_F(TextFormatTest, PopulatesNoOpFields) { EXPECT_TRUE( TextFormat::ParseFromString(repeated_int32_parse_string, &proto)); EXPECT_TRUE(parser.ParseFromString(repeated_int32_parse_string, &proto)); - EXPECT_EQ(UnsetFieldsMetadataTextFormatTestUtil::NumFields(no_op_fields), - 0); + EXPECT_THAT(Peer::GetRawIds(no_op_fields), UnorderedElementsAre()); } { no_op_fields = {}; @@ -1139,8 +1137,7 @@ TEST_F(TextFormatTest, PopulatesNoOpFields) { EXPECT_TRUE( TextFormat::ParseFromString(repeated_bool_parse_string, &proto)); EXPECT_TRUE(parser.ParseFromString(repeated_bool_parse_string, &proto)); - EXPECT_EQ(UnsetFieldsMetadataTextFormatTestUtil::NumFields(no_op_fields), - 0); + EXPECT_THAT(Peer::GetRawIds(no_op_fields), UnorderedElementsAre()); } { no_op_fields = {}; @@ -1149,12 +1146,12 @@ TEST_F(TextFormatTest, PopulatesNoOpFields) { EXPECT_TRUE( TextFormat::ParseFromString(repeated_string_parse_string, &proto)); EXPECT_TRUE(parser.ParseFromString(repeated_string_parse_string, &proto)); - EXPECT_EQ(UnsetFieldsMetadataTextFormatTestUtil::NumFields(no_op_fields), - 0); + EXPECT_THAT(Peer::GetRawIds(no_op_fields), UnorderedElementsAre()); } } TEST_F(TextFormatTest, FieldsPopulatedCorrectly) { + using Peer = UnsetFieldsMetadataTextFormatTestUtil; proto3_unittest::TestAllTypes proto; TextFormat::Parser parser; TextFormat::Parser::UnsetFieldsMetadata no_op_fields; @@ -1167,18 +1164,10 @@ TEST_F(TextFormatTest, FieldsPopulatedCorrectly) { optional_nested_message { bb: 0 } )pb"; EXPECT_TRUE(parser.ParseFromString(parse_string, &proto)); - ASSERT_EQ(UnsetFieldsMetadataTextFormatTestUtil::NumFields(no_op_fields), - 2); - std::vector ptrs = - UnsetFieldsMetadataTextFormatTestUtil::GetRawAddresses(no_op_fields); - EXPECT_EQ(*static_cast(ptrs[0]), 0); - EXPECT_EQ(*static_cast(ptrs[1]), 0); - proto.set_optional_int32(20); - proto.mutable_optional_nested_message()->set_bb(30); - const std::vector new_values{ - *static_cast(ptrs[0]), - *static_cast(ptrs[1])}; - EXPECT_THAT(new_values, testing::UnorderedElementsAre(20, 30)); + EXPECT_THAT(Peer::GetRawIds(no_op_fields), + UnorderedElementsAre( + Peer::GetId(proto, "optional_int32"), + Peer::GetId(proto.optional_nested_message(), "bb"))); } { no_op_fields = {}; @@ -1188,13 +1177,8 @@ TEST_F(TextFormatTest, FieldsPopulatedCorrectly) { optional_nested_message { bb: 20 } )pb"; EXPECT_TRUE(parser.ParseFromString(parse_string, &proto)); - ASSERT_EQ(UnsetFieldsMetadataTextFormatTestUtil::NumFields(no_op_fields), - 1); - std::vector ptrs = - UnsetFieldsMetadataTextFormatTestUtil::GetRawAddresses(no_op_fields); - EXPECT_EQ(*static_cast(ptrs[0]), false); - proto.set_optional_bool(true); - EXPECT_EQ(*static_cast(ptrs[0]), true); + EXPECT_THAT(Peer::GetRawIds(no_op_fields), + UnorderedElementsAre(Peer::GetId(proto, "optional_bool"))); } { // The address returned by the field is a string_view, which is a separate @@ -1202,14 +1186,8 @@ TEST_F(TextFormatTest, FieldsPopulatedCorrectly) { no_op_fields = {}; const absl::string_view parse_string = "optional_string: \"\""; EXPECT_TRUE(parser.ParseFromString(parse_string, &proto)); - ASSERT_EQ(UnsetFieldsMetadataTextFormatTestUtil::NumFields(no_op_fields), - 1); - const Reflection* reflection = proto.GetReflection(); - const FieldDescriptor* field = proto.GetDescriptor()->FindFieldByNumber(14); - EXPECT_EQ( - UnsetFieldsMetadataTextFormatTestUtil::GetRawAddresses(no_op_fields)[0], - UnsetFieldsMetadataTextFormatTestUtil::GetAddress(proto, *reflection, - *field)); + EXPECT_THAT(Peer::GetRawIds(no_op_fields), + UnorderedElementsAre(Peer::GetId(proto, "optional_string"))); } { // The address returned by the field is a string_view, which is a separate @@ -1217,14 +1195,8 @@ TEST_F(TextFormatTest, FieldsPopulatedCorrectly) { no_op_fields = {}; const absl::string_view parse_string = "optional_bytes: \"\""; EXPECT_TRUE(parser.ParseFromString(parse_string, &proto)); - ASSERT_EQ(UnsetFieldsMetadataTextFormatTestUtil::NumFields(no_op_fields), - 1); - const Reflection* reflection = proto.GetReflection(); - const FieldDescriptor* field = proto.GetDescriptor()->FindFieldByNumber(15); - EXPECT_EQ( - UnsetFieldsMetadataTextFormatTestUtil::GetRawAddresses(no_op_fields)[0], - UnsetFieldsMetadataTextFormatTestUtil::GetAddress(proto, *reflection, - *field)); + EXPECT_THAT(Peer::GetRawIds(no_op_fields), + UnorderedElementsAre(Peer::GetId(proto, "optional_bytes"))); } } diff --git a/src/google/protobuf/util/message_differencer.cc b/src/google/protobuf/util/message_differencer.cc index df0311cd4c329..2d9ba265b853b 100644 --- a/src/google/protobuf/util/message_differencer.cc +++ b/src/google/protobuf/util/message_differencer.cc @@ -759,9 +759,9 @@ bool MessageDifferencer::ShouldCompareNoPresence( const bool compare_no_presence_by_address = !field2->is_repeated() && !field2->has_presence() && ValidMissingField(*field2) && - require_no_presence_fields_.addresses_.contains( - TextFormat::Parser::UnsetFieldsMetadata::GetUnsetFieldAddress( - message1, reflection1, *field2)); + require_no_presence_fields_.ids_.contains( + TextFormat::Parser::UnsetFieldsMetadata::GetUnsetFieldId(message1, + *field2)); return compare_no_presence_by_address; } diff --git a/src/google/protobuf/util/message_differencer_unittest.cc b/src/google/protobuf/util/message_differencer_unittest.cc index 191281a74ddb8..58fca75e7ab54 100644 --- a/src/google/protobuf/util/message_differencer_unittest.cc +++ b/src/google/protobuf/util/message_differencer_unittest.cc @@ -50,12 +50,9 @@ namespace internal { class UnsetFieldsMetadataMessageDifferencerTestUtil { public: static void AddExplicitUnsetField( - const Message& message, const Reflection& reflection, - const FieldDescriptor& fd, + const Message& message, const FieldDescriptor& fd, TextFormat::Parser::UnsetFieldsMetadata* metadata) { - metadata->addresses_.insert( - TextFormat::Parser::UnsetFieldsMetadata::GetUnsetFieldAddress( - message, reflection, fd)); + metadata->ids_.insert(metadata->GetUnsetFieldId(message, fd)); } }; } // namespace internal @@ -414,11 +411,10 @@ TEST(MessageDifferencerTest, proto3_unittest::TestNoPresenceField msg1 = MakeTestNoPresenceField(); proto3_unittest::TestNoPresenceField msg2 = MakeTestNoPresenceField(); - const Reflection* reflection1 = msg1.GetReflection(); const FieldDescriptor* fd1 = msg1.GetDescriptor()->FindFieldByNumber(1); TextFormat::Parser::UnsetFieldsMetadata metadata; UnsetFieldsMetadataMessageDifferencerTestUtil::AddExplicitUnsetField( - msg1, *reflection1, *fd1, &metadata); + msg1, *fd1, &metadata); address_differencer.set_require_no_presence_fields(metadata); EXPECT_TRUE(address_differencer.Compare(msg1, msg2)); @@ -455,11 +451,10 @@ TEST(MessageDifferencerTest, proto3_unittest::TestNoPresenceField msg1 = MakeTestNoPresenceField(); proto3_unittest::TestNoPresenceField msg2 = MakeTestNoPresenceField(); - const Reflection* reflection1 = msg1.GetReflection(); const FieldDescriptor* fd1 = msg1.GetDescriptor()->FindFieldByNumber(4); TextFormat::Parser::UnsetFieldsMetadata metadata; UnsetFieldsMetadataMessageDifferencerTestUtil::AddExplicitUnsetField( - msg1, *reflection1, *fd1, &metadata); + msg1, *fd1, &metadata); address_differencer.set_require_no_presence_fields(metadata); EXPECT_TRUE(address_differencer.Compare(msg1, msg2)); @@ -498,11 +493,10 @@ TEST(MessageDifferencerTest, proto3_unittest::TestNoPresenceField msg1 = MakeTestNoPresenceField(); proto3_unittest::TestNoPresenceField msg2 = MakeTestNoPresenceField(); - const Reflection* reflection1 = msg1.GetReflection(); const FieldDescriptor* fd1 = msg1.GetDescriptor()->FindFieldByNumber(5); TextFormat::Parser::UnsetFieldsMetadata metadata; UnsetFieldsMetadataMessageDifferencerTestUtil::AddExplicitUnsetField( - msg1, *reflection1, *fd1, &metadata); + msg1, *fd1, &metadata); address_differencer.set_require_no_presence_fields(metadata); EXPECT_TRUE(address_differencer.Compare(msg1, msg2)); @@ -537,11 +531,10 @@ TEST(MessageDifferencerTest, proto3_unittest::TestNoPresenceField msg1 = MakeTestNoPresenceField(); proto3_unittest::TestNoPresenceField msg2 = MakeTestNoPresenceField(); - const Reflection* reflection1 = msg1.no_presence_nested().GetReflection(); const FieldDescriptor* fd1 = msg1.GetDescriptor()->FindFieldByNumber(1); TextFormat::Parser::UnsetFieldsMetadata metadata; UnsetFieldsMetadataMessageDifferencerTestUtil::AddExplicitUnsetField( - msg1.no_presence_nested(), *reflection1, *fd1, &metadata); + msg1.no_presence_nested(), *fd1, &metadata); address_differencer.set_require_no_presence_fields(metadata); EXPECT_TRUE(address_differencer.Compare(msg1, msg2)); @@ -578,12 +571,10 @@ TEST(MessageDifferencerTest, proto3_unittest::TestNoPresenceField msg1 = MakeTestNoPresenceField(); proto3_unittest::TestNoPresenceField msg2 = MakeTestNoPresenceField(); - const Reflection* reflection1 = - msg1.no_presence_repeated_nested(0).GetReflection(); const FieldDescriptor* fd1 = msg1.GetDescriptor()->FindFieldByNumber(1); TextFormat::Parser::UnsetFieldsMetadata metadata; UnsetFieldsMetadataMessageDifferencerTestUtil::AddExplicitUnsetField( - msg1.no_presence_repeated_nested(0), *reflection1, *fd1, &metadata); + msg1.no_presence_repeated_nested(0), *fd1, &metadata); address_differencer.set_require_no_presence_fields(metadata); EXPECT_TRUE(address_differencer.Compare(msg1, msg2)); From d6ccc70078784e3b9e05954e53c0c5017257a21d Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Fri, 5 Jan 2024 13:40:56 -0800 Subject: [PATCH 193/255] IWYU cleanup. PiperOrigin-RevId: 596074149 --- .../protobuf/compiler/cpp/field_generators/message_field.cc | 1 - 1 file changed, 1 deletion(-) diff --git a/src/google/protobuf/compiler/cpp/field_generators/message_field.cc b/src/google/protobuf/compiler/cpp/field_generators/message_field.cc index 43517cf2c8f39..5917a8e849cc6 100644 --- a/src/google/protobuf/compiler/cpp/field_generators/message_field.cc +++ b/src/google/protobuf/compiler/cpp/field_generators/message_field.cc @@ -11,7 +11,6 @@ #include #include -#include #include #include "absl/log/absl_check.h" From 321b8171473c144eb57a6e7d35948a1bbe0f0ec9 Mon Sep 17 00:00:00 2001 From: Dmitri Gribenko Date: Fri, 5 Jan 2024 15:01:06 -0800 Subject: [PATCH 194/255] Automated Code Change PiperOrigin-RevId: 596091728 --- python/google/protobuf/pyext/message.cc | 8 ++++---- python/google/protobuf/pyext/message.h | 10 ++++------ 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/python/google/protobuf/pyext/message.cc b/python/google/protobuf/pyext/message.cc index 42bb20da042da..cff444cedc1cd 100644 --- a/python/google/protobuf/pyext/message.cc +++ b/python/google/protobuf/pyext/message.cc @@ -532,10 +532,10 @@ bool CheckAndGetInteger(PyObject* arg, T* value) { // These are referenced by repeated_scalar_container, and must // be explicitly instantiated. -template bool CheckAndGetInteger(PyObject*, int32*); -template bool CheckAndGetInteger(PyObject*, int64*); -template bool CheckAndGetInteger(PyObject*, uint32*); -template bool CheckAndGetInteger(PyObject*, uint64*); +template bool CheckAndGetInteger(PyObject*, int32_t*); +template bool CheckAndGetInteger(PyObject*, int64_t*); +template bool CheckAndGetInteger(PyObject*, uint32_t*); +template bool CheckAndGetInteger(PyObject*, uint64_t*); bool CheckAndGetDouble(PyObject* arg, double* value) { *value = PyFloat_AsDouble(arg); diff --git a/python/google/protobuf/pyext/message.h b/python/google/protobuf/pyext/message.h index dc5018227a296..7d8f07dd752a0 100644 --- a/python/google/protobuf/pyext/message.h +++ b/python/google/protobuf/pyext/message.h @@ -19,8 +19,6 @@ #include #include -#include "google/protobuf/stubs/common.h" - namespace google { namespace protobuf { @@ -338,10 +336,10 @@ bool InitProto2MessageModule(PyObject *m); // These are referenced by repeated_scalar_container, and must // be explicitly instantiated. -extern template bool CheckAndGetInteger(PyObject*, int32*); -extern template bool CheckAndGetInteger(PyObject*, int64*); -extern template bool CheckAndGetInteger(PyObject*, uint32*); -extern template bool CheckAndGetInteger(PyObject*, uint64*); +extern template bool CheckAndGetInteger(PyObject*, int32_t*); +extern template bool CheckAndGetInteger(PyObject*, int64_t*); +extern template bool CheckAndGetInteger(PyObject*, uint32_t*); +extern template bool CheckAndGetInteger(PyObject*, uint64_t*); } // namespace python } // namespace protobuf From b2e94f3c414fc846e7c2dacd9e3e16b859fba725 Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Fri, 5 Jan 2024 16:08:06 -0800 Subject: [PATCH 195/255] Use raw string for Emit PiperOrigin-RevId: 596105029 --- .../cpp/field_generators/message_field.cc | 149 ++++-- src/google/protobuf/compiler/plugin.pb.cc | 48 +- src/google/protobuf/descriptor.pb.cc | 492 ++++++++++-------- 3 files changed, 382 insertions(+), 307 deletions(-) diff --git a/src/google/protobuf/compiler/cpp/field_generators/message_field.cc b/src/google/protobuf/compiler/cpp/field_generators/message_field.cc index 5917a8e849cc6..a46028009a31a 100644 --- a/src/google/protobuf/compiler/cpp/field_generators/message_field.cc +++ b/src/google/protobuf/compiler/cpp/field_generators/message_field.cc @@ -315,12 +315,17 @@ void SingularMessage::GenerateClearingCode(io::Printer* p) const { // If we don't have has-bits, message presence is indicated only by ptr != // nullptr. Thus on clear, we need to delete the object. p->Emit( - "if (GetArena() == nullptr && $field_$ != nullptr) {\n" - " delete $field_$;\n" - "}\n" - "$field_$ = nullptr;\n"); + R"cc( + if (GetArena() == nullptr && $field_$ != nullptr) { + delete $field_$; + } + $field_$ = nullptr; + )cc"); } else { - p->Emit("if ($field_$ != nullptr) $field_$->Clear();\n"); + p->Emit( + R"cc( + if ($field_$ != nullptr) $field_$->Clear(); + )cc"); } } @@ -329,14 +334,18 @@ void SingularMessage::GenerateMessageClearingCode(io::Printer* p) const { // If we don't have has-bits, message presence is indicated only by ptr != // nullptr. Thus on clear, we need to delete the object. p->Emit( - "if (GetArena() == nullptr && $field_$ != nullptr) {\n" - " delete $field_$;\n" - "}\n" - "$field_$ = nullptr;\n"); + R"cc( + if (GetArena() == nullptr && $field_$ != nullptr) { + delete $field_$; + } + $field_$ = nullptr; + )cc"); } else { p->Emit( - "$DCHK$($field_$ != nullptr);\n" - "$field_$->Clear();\n"); + R"cc( + $DCHK$($field_$ != nullptr); + $field_$->Clear(); + )cc"); } } @@ -359,8 +368,10 @@ void SingularMessage::GenerateMergingCode(io::Printer* p) const { )cc"); } else if (should_split()) { p->Emit( - "_this->_internal_mutable_$name$()->$Submsg$::MergeFrom(\n" - " from._internal_$name$());\n"); + R"cc( + _this->_internal_mutable_$name$()->$Submsg$::MergeFrom( + from._internal_$name$()); + )cc"); } else { // Important: we set `hasbits` after we copied the field. There are cases // where people assign root values to child values or vice versa which @@ -919,52 +930,74 @@ void RepeatedMessage::GenerateDestructorCode(io::Printer* p) const { void RepeatedMessage::GenerateSerializeWithCachedSizesToArray( io::Printer* p) const { if (is_weak()) { - p->Emit( - "for (auto it = this->$field_$.pointer_begin(),\n" - " end = this->$field_$.pointer_end(); it < end; ++it) {\n"); - if (field_->type() == FieldDescriptor::TYPE_MESSAGE) { - p->Emit( - " target = $pbi$::WireFormatLite::\n" - " InternalWrite$declared_type$($number$, " - "**it, (**it).GetCachedSize(), target, stream);\n"); - } else { - p->Emit( - " target = stream->EnsureSpace(target);\n" - " target = $pbi$::WireFormatLite::\n" - " InternalWrite$declared_type$($number$, **it, target, " - "stream);\n"); - } - p->Emit("}\n"); + p->Emit({{"serialize_field", + [&] { + if (field_->type() == FieldDescriptor::TYPE_MESSAGE) { + p->Emit( + R"cc( + target = + $pbi$::WireFormatLite::InternalWrite$declared_type$( + $number$, **it, (**it).GetCachedSize(), target, + stream); + )cc"); + } else { + p->Emit( + R"cc( + target = stream->EnsureSpace(target); + target = + $pbi$::WireFormatLite::InternalWrite$declared_type$( + $number$, **it, target, stream); + )cc"); + } + }}}, + R"cc( + for (auto it = this->$field_$.pointer_begin(), + end = this->$field_$.pointer_end(); + it < end; ++it) { + $serialize_field$; + } + )cc"); } else { - p->Emit( - "for (unsigned i = 0,\n" - " n = static_cast(this->_internal_$name$_size());" - " i < n; i++) {\n"); - if (field_->type() == FieldDescriptor::TYPE_MESSAGE) { - p->Emit( - " const auto& repfield = this->_internal_$name$().Get(i);\n" - " target = $pbi$::WireFormatLite::\n" - " InternalWrite$declared_type$($number$, " - "repfield, repfield.GetCachedSize(), target, stream);\n" - "}\n"); - } else { - p->Emit( - " target = stream->EnsureSpace(target);\n" - " target = $pbi$::WireFormatLite::\n" - " InternalWrite$declared_type$($number$, " - "this->_internal_$name$().Get(i), target, stream);\n" - "}\n"); - } + p->Emit({{"serialize_field", + [&] { + if (field_->type() == FieldDescriptor::TYPE_MESSAGE) { + p->Emit( + R"cc( + const auto& repfield = this->_internal_$name$().Get(i); + target = + $pbi$::WireFormatLite::InternalWrite$declared_type$( + $number$, repfield, repfield.GetCachedSize(), + target, stream); + )cc"); + } else { + p->Emit( + R"cc( + target = stream->EnsureSpace(target); + target = + $pbi$::WireFormatLite::InternalWrite$declared_type$( + $number$, this->_internal_$name$().Get(i), + target, stream); + )cc"); + } + }}}, + R"cc( + for (unsigned i = 0, n = static_cast( + this->_internal_$name$_size()); + i < n; i++) { + $serialize_field$; + } + )cc"); } } void RepeatedMessage::GenerateByteSize(io::Printer* p) const { p->Emit( - "total_size += $tag_size$UL * this->_internal_$name$_size();\n" - "for (const auto& msg : this->_internal$_weak$_$name$()) {\n" - " total_size +=\n" - " $pbi$::WireFormatLite::$declared_type$Size(msg);\n" - "}\n"); + R"cc( + total_size += $tag_size$UL * this->_internal_$name$_size(); + for (const auto& msg : this->_internal$_weak$_$name$()) { + total_size += $pbi$::WireFormatLite::$declared_type$Size(msg); + } + )cc"); } void RepeatedMessage::GenerateIsInitialized(io::Printer* p) const { @@ -972,12 +1005,14 @@ void RepeatedMessage::GenerateIsInitialized(io::Printer* p) const { if (is_weak()) { p->Emit( - "if (!$pbi$::AllAreInitializedWeak($field_$.weak))\n" - " return false;\n"); + R"cc( + if (!$pbi$::AllAreInitializedWeak($field_$.weak)) return false; + )cc"); } else { p->Emit( - "if (!$pbi$::AllAreInitialized(_internal_$name$()))\n" - " return false;\n"); + R"cc( + if (!$pbi$::AllAreInitialized(_internal_$name$())) return false; + )cc"); } } } // namespace diff --git a/src/google/protobuf/compiler/plugin.pb.cc b/src/google/protobuf/compiler/plugin.pb.cc index 788f52fbbe45b..b66474e5e7361 100644 --- a/src/google/protobuf/compiler/plugin.pb.cc +++ b/src/google/protobuf/compiler/plugin.pb.cc @@ -825,19 +825,25 @@ ::uint8_t* CodeGeneratorRequest::_InternalSerialize( } // repeated .google.protobuf.FileDescriptorProto proto_file = 15; - for (unsigned i = 0, - n = static_cast(this->_internal_proto_file_size()); i < n; i++) { + for (unsigned i = 0, n = static_cast( + this->_internal_proto_file_size()); + i < n; i++) { const auto& repfield = this->_internal_proto_file().Get(i); - target = ::google::protobuf::internal::WireFormatLite:: - InternalWriteMessage(15, repfield, repfield.GetCachedSize(), target, stream); + target = + ::google::protobuf::internal::WireFormatLite::InternalWriteMessage( + 15, repfield, repfield.GetCachedSize(), + target, stream); } // repeated .google.protobuf.FileDescriptorProto source_file_descriptors = 17; - for (unsigned i = 0, - n = static_cast(this->_internal_source_file_descriptors_size()); i < n; i++) { + for (unsigned i = 0, n = static_cast( + this->_internal_source_file_descriptors_size()); + i < n; i++) { const auto& repfield = this->_internal_source_file_descriptors().Get(i); - target = ::google::protobuf::internal::WireFormatLite:: - InternalWriteMessage(17, repfield, repfield.GetCachedSize(), target, stream); + target = + ::google::protobuf::internal::WireFormatLite::InternalWriteMessage( + 17, repfield, repfield.GetCachedSize(), + target, stream); } if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) { @@ -866,14 +872,12 @@ ::size_t CodeGeneratorRequest::ByteSizeLong() const { // repeated .google.protobuf.FileDescriptorProto proto_file = 15; total_size += 1UL * this->_internal_proto_file_size(); for (const auto& msg : this->_internal_proto_file()) { - total_size += - ::google::protobuf::internal::WireFormatLite::MessageSize(msg); + total_size += ::google::protobuf::internal::WireFormatLite::MessageSize(msg); } // repeated .google.protobuf.FileDescriptorProto source_file_descriptors = 17; total_size += 2UL * this->_internal_source_file_descriptors_size(); for (const auto& msg : this->_internal_source_file_descriptors()) { - total_size += - ::google::protobuf::internal::WireFormatLite::MessageSize(msg); + total_size += ::google::protobuf::internal::WireFormatLite::MessageSize(msg); } cached_has_bits = _impl_._has_bits_[0]; if (cached_has_bits & 0x00000003u) { @@ -935,10 +939,8 @@ void CodeGeneratorRequest::CopyFrom(const CodeGeneratorRequest& from) { } PROTOBUF_NOINLINE bool CodeGeneratorRequest::IsInitialized() const { - if (!::google::protobuf::internal::AllAreInitialized(_internal_proto_file())) - return false; - if (!::google::protobuf::internal::AllAreInitialized(_internal_source_file_descriptors())) - return false; + if (!::google::protobuf::internal::AllAreInitialized(_internal_proto_file())) return false; + if (!::google::protobuf::internal::AllAreInitialized(_internal_source_file_descriptors())) return false; return true; } @@ -1493,11 +1495,14 @@ ::uint8_t* CodeGeneratorResponse::_InternalSerialize( } // repeated .google.protobuf.compiler.CodeGeneratorResponse.File file = 15; - for (unsigned i = 0, - n = static_cast(this->_internal_file_size()); i < n; i++) { + for (unsigned i = 0, n = static_cast( + this->_internal_file_size()); + i < n; i++) { const auto& repfield = this->_internal_file().Get(i); - target = ::google::protobuf::internal::WireFormatLite:: - InternalWriteMessage(15, repfield, repfield.GetCachedSize(), target, stream); + target = + ::google::protobuf::internal::WireFormatLite::InternalWriteMessage( + 15, repfield, repfield.GetCachedSize(), + target, stream); } if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) { @@ -1520,8 +1525,7 @@ ::size_t CodeGeneratorResponse::ByteSizeLong() const { // repeated .google.protobuf.compiler.CodeGeneratorResponse.File file = 15; total_size += 1UL * this->_internal_file_size(); for (const auto& msg : this->_internal_file()) { - total_size += - ::google::protobuf::internal::WireFormatLite::MessageSize(msg); + total_size += ::google::protobuf::internal::WireFormatLite::MessageSize(msg); } cached_has_bits = _impl_._has_bits_[0]; if (cached_has_bits & 0x0000000fu) { diff --git a/src/google/protobuf/descriptor.pb.cc b/src/google/protobuf/descriptor.pb.cc index 4d80cf16612c9..a926bcf329e37 100644 --- a/src/google/protobuf/descriptor.pb.cc +++ b/src/google/protobuf/descriptor.pb.cc @@ -2466,11 +2466,14 @@ ::uint8_t* FileDescriptorSet::_InternalSerialize( (void)cached_has_bits; // repeated .google.protobuf.FileDescriptorProto file = 1; - for (unsigned i = 0, - n = static_cast(this->_internal_file_size()); i < n; i++) { + for (unsigned i = 0, n = static_cast( + this->_internal_file_size()); + i < n; i++) { const auto& repfield = this->_internal_file().Get(i); - target = ::google::protobuf::internal::WireFormatLite:: - InternalWriteMessage(1, repfield, repfield.GetCachedSize(), target, stream); + target = + ::google::protobuf::internal::WireFormatLite::InternalWriteMessage( + 1, repfield, repfield.GetCachedSize(), + target, stream); } if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) { @@ -2493,8 +2496,7 @@ ::size_t FileDescriptorSet::ByteSizeLong() const { // repeated .google.protobuf.FileDescriptorProto file = 1; total_size += 1UL * this->_internal_file_size(); for (const auto& msg : this->_internal_file()) { - total_size += - ::google::protobuf::internal::WireFormatLite::MessageSize(msg); + total_size += ::google::protobuf::internal::WireFormatLite::MessageSize(msg); } return MaybeComputeUnknownFieldsSize(total_size, &_impl_._cached_size_); } @@ -2521,8 +2523,7 @@ void FileDescriptorSet::CopyFrom(const FileDescriptorSet& from) { } PROTOBUF_NOINLINE bool FileDescriptorSet::IsInitialized() const { - if (!::google::protobuf::internal::AllAreInitialized(_internal_file())) - return false; + if (!::google::protobuf::internal::AllAreInitialized(_internal_file())) return false; return true; } @@ -2838,35 +2839,47 @@ ::uint8_t* FileDescriptorProto::_InternalSerialize( } // repeated .google.protobuf.DescriptorProto message_type = 4; - for (unsigned i = 0, - n = static_cast(this->_internal_message_type_size()); i < n; i++) { + for (unsigned i = 0, n = static_cast( + this->_internal_message_type_size()); + i < n; i++) { const auto& repfield = this->_internal_message_type().Get(i); - target = ::google::protobuf::internal::WireFormatLite:: - InternalWriteMessage(4, repfield, repfield.GetCachedSize(), target, stream); + target = + ::google::protobuf::internal::WireFormatLite::InternalWriteMessage( + 4, repfield, repfield.GetCachedSize(), + target, stream); } // repeated .google.protobuf.EnumDescriptorProto enum_type = 5; - for (unsigned i = 0, - n = static_cast(this->_internal_enum_type_size()); i < n; i++) { + for (unsigned i = 0, n = static_cast( + this->_internal_enum_type_size()); + i < n; i++) { const auto& repfield = this->_internal_enum_type().Get(i); - target = ::google::protobuf::internal::WireFormatLite:: - InternalWriteMessage(5, repfield, repfield.GetCachedSize(), target, stream); + target = + ::google::protobuf::internal::WireFormatLite::InternalWriteMessage( + 5, repfield, repfield.GetCachedSize(), + target, stream); } // repeated .google.protobuf.ServiceDescriptorProto service = 6; - for (unsigned i = 0, - n = static_cast(this->_internal_service_size()); i < n; i++) { + for (unsigned i = 0, n = static_cast( + this->_internal_service_size()); + i < n; i++) { const auto& repfield = this->_internal_service().Get(i); - target = ::google::protobuf::internal::WireFormatLite:: - InternalWriteMessage(6, repfield, repfield.GetCachedSize(), target, stream); + target = + ::google::protobuf::internal::WireFormatLite::InternalWriteMessage( + 6, repfield, repfield.GetCachedSize(), + target, stream); } // repeated .google.protobuf.FieldDescriptorProto extension = 7; - for (unsigned i = 0, - n = static_cast(this->_internal_extension_size()); i < n; i++) { + for (unsigned i = 0, n = static_cast( + this->_internal_extension_size()); + i < n; i++) { const auto& repfield = this->_internal_extension().Get(i); - target = ::google::protobuf::internal::WireFormatLite:: - InternalWriteMessage(7, repfield, repfield.GetCachedSize(), target, stream); + target = + ::google::protobuf::internal::WireFormatLite::InternalWriteMessage( + 7, repfield, repfield.GetCachedSize(), + target, stream); } // optional .google.protobuf.FileOptions options = 8; @@ -2936,26 +2949,22 @@ ::size_t FileDescriptorProto::ByteSizeLong() const { // repeated .google.protobuf.DescriptorProto message_type = 4; total_size += 1UL * this->_internal_message_type_size(); for (const auto& msg : this->_internal_message_type()) { - total_size += - ::google::protobuf::internal::WireFormatLite::MessageSize(msg); + total_size += ::google::protobuf::internal::WireFormatLite::MessageSize(msg); } // repeated .google.protobuf.EnumDescriptorProto enum_type = 5; total_size += 1UL * this->_internal_enum_type_size(); for (const auto& msg : this->_internal_enum_type()) { - total_size += - ::google::protobuf::internal::WireFormatLite::MessageSize(msg); + total_size += ::google::protobuf::internal::WireFormatLite::MessageSize(msg); } // repeated .google.protobuf.ServiceDescriptorProto service = 6; total_size += 1UL * this->_internal_service_size(); for (const auto& msg : this->_internal_service()) { - total_size += - ::google::protobuf::internal::WireFormatLite::MessageSize(msg); + total_size += ::google::protobuf::internal::WireFormatLite::MessageSize(msg); } // repeated .google.protobuf.FieldDescriptorProto extension = 7; total_size += 1UL * this->_internal_extension_size(); for (const auto& msg : this->_internal_extension()) { - total_size += - ::google::protobuf::internal::WireFormatLite::MessageSize(msg); + total_size += ::google::protobuf::internal::WireFormatLite::MessageSize(msg); } // repeated int32 public_dependency = 10; { @@ -3085,14 +3094,10 @@ void FileDescriptorProto::CopyFrom(const FileDescriptorProto& from) { } PROTOBUF_NOINLINE bool FileDescriptorProto::IsInitialized() const { - if (!::google::protobuf::internal::AllAreInitialized(_internal_message_type())) - return false; - if (!::google::protobuf::internal::AllAreInitialized(_internal_enum_type())) - return false; - if (!::google::protobuf::internal::AllAreInitialized(_internal_service())) - return false; - if (!::google::protobuf::internal::AllAreInitialized(_internal_extension())) - return false; + if (!::google::protobuf::internal::AllAreInitialized(_internal_message_type())) return false; + if (!::google::protobuf::internal::AllAreInitialized(_internal_enum_type())) return false; + if (!::google::protobuf::internal::AllAreInitialized(_internal_service())) return false; + if (!::google::protobuf::internal::AllAreInitialized(_internal_extension())) return false; if ((_impl_._has_bits_[0] & 0x00000008u) != 0) { if (!_impl_.options_->IsInitialized()) return false; } @@ -3886,43 +3891,58 @@ ::uint8_t* DescriptorProto::_InternalSerialize( } // repeated .google.protobuf.FieldDescriptorProto field = 2; - for (unsigned i = 0, - n = static_cast(this->_internal_field_size()); i < n; i++) { + for (unsigned i = 0, n = static_cast( + this->_internal_field_size()); + i < n; i++) { const auto& repfield = this->_internal_field().Get(i); - target = ::google::protobuf::internal::WireFormatLite:: - InternalWriteMessage(2, repfield, repfield.GetCachedSize(), target, stream); + target = + ::google::protobuf::internal::WireFormatLite::InternalWriteMessage( + 2, repfield, repfield.GetCachedSize(), + target, stream); } // repeated .google.protobuf.DescriptorProto nested_type = 3; - for (unsigned i = 0, - n = static_cast(this->_internal_nested_type_size()); i < n; i++) { + for (unsigned i = 0, n = static_cast( + this->_internal_nested_type_size()); + i < n; i++) { const auto& repfield = this->_internal_nested_type().Get(i); - target = ::google::protobuf::internal::WireFormatLite:: - InternalWriteMessage(3, repfield, repfield.GetCachedSize(), target, stream); + target = + ::google::protobuf::internal::WireFormatLite::InternalWriteMessage( + 3, repfield, repfield.GetCachedSize(), + target, stream); } // repeated .google.protobuf.EnumDescriptorProto enum_type = 4; - for (unsigned i = 0, - n = static_cast(this->_internal_enum_type_size()); i < n; i++) { + for (unsigned i = 0, n = static_cast( + this->_internal_enum_type_size()); + i < n; i++) { const auto& repfield = this->_internal_enum_type().Get(i); - target = ::google::protobuf::internal::WireFormatLite:: - InternalWriteMessage(4, repfield, repfield.GetCachedSize(), target, stream); + target = + ::google::protobuf::internal::WireFormatLite::InternalWriteMessage( + 4, repfield, repfield.GetCachedSize(), + target, stream); } // repeated .google.protobuf.DescriptorProto.ExtensionRange extension_range = 5; - for (unsigned i = 0, - n = static_cast(this->_internal_extension_range_size()); i < n; i++) { + for (unsigned i = 0, n = static_cast( + this->_internal_extension_range_size()); + i < n; i++) { const auto& repfield = this->_internal_extension_range().Get(i); - target = ::google::protobuf::internal::WireFormatLite:: - InternalWriteMessage(5, repfield, repfield.GetCachedSize(), target, stream); + target = + ::google::protobuf::internal::WireFormatLite::InternalWriteMessage( + 5, repfield, repfield.GetCachedSize(), + target, stream); } // repeated .google.protobuf.FieldDescriptorProto extension = 6; - for (unsigned i = 0, - n = static_cast(this->_internal_extension_size()); i < n; i++) { + for (unsigned i = 0, n = static_cast( + this->_internal_extension_size()); + i < n; i++) { const auto& repfield = this->_internal_extension().Get(i); - target = ::google::protobuf::internal::WireFormatLite:: - InternalWriteMessage(6, repfield, repfield.GetCachedSize(), target, stream); + target = + ::google::protobuf::internal::WireFormatLite::InternalWriteMessage( + 6, repfield, repfield.GetCachedSize(), + target, stream); } // optional .google.protobuf.MessageOptions options = 7; @@ -3932,19 +3952,25 @@ ::uint8_t* DescriptorProto::_InternalSerialize( } // repeated .google.protobuf.OneofDescriptorProto oneof_decl = 8; - for (unsigned i = 0, - n = static_cast(this->_internal_oneof_decl_size()); i < n; i++) { + for (unsigned i = 0, n = static_cast( + this->_internal_oneof_decl_size()); + i < n; i++) { const auto& repfield = this->_internal_oneof_decl().Get(i); - target = ::google::protobuf::internal::WireFormatLite:: - InternalWriteMessage(8, repfield, repfield.GetCachedSize(), target, stream); + target = + ::google::protobuf::internal::WireFormatLite::InternalWriteMessage( + 8, repfield, repfield.GetCachedSize(), + target, stream); } // repeated .google.protobuf.DescriptorProto.ReservedRange reserved_range = 9; - for (unsigned i = 0, - n = static_cast(this->_internal_reserved_range_size()); i < n; i++) { + for (unsigned i = 0, n = static_cast( + this->_internal_reserved_range_size()); + i < n; i++) { const auto& repfield = this->_internal_reserved_range().Get(i); - target = ::google::protobuf::internal::WireFormatLite:: - InternalWriteMessage(9, repfield, repfield.GetCachedSize(), target, stream); + target = + ::google::protobuf::internal::WireFormatLite::InternalWriteMessage( + 9, repfield, repfield.GetCachedSize(), + target, stream); } // repeated string reserved_name = 10; @@ -3975,44 +4001,37 @@ ::size_t DescriptorProto::ByteSizeLong() const { // repeated .google.protobuf.FieldDescriptorProto field = 2; total_size += 1UL * this->_internal_field_size(); for (const auto& msg : this->_internal_field()) { - total_size += - ::google::protobuf::internal::WireFormatLite::MessageSize(msg); + total_size += ::google::protobuf::internal::WireFormatLite::MessageSize(msg); } // repeated .google.protobuf.DescriptorProto nested_type = 3; total_size += 1UL * this->_internal_nested_type_size(); for (const auto& msg : this->_internal_nested_type()) { - total_size += - ::google::protobuf::internal::WireFormatLite::MessageSize(msg); + total_size += ::google::protobuf::internal::WireFormatLite::MessageSize(msg); } // repeated .google.protobuf.EnumDescriptorProto enum_type = 4; total_size += 1UL * this->_internal_enum_type_size(); for (const auto& msg : this->_internal_enum_type()) { - total_size += - ::google::protobuf::internal::WireFormatLite::MessageSize(msg); + total_size += ::google::protobuf::internal::WireFormatLite::MessageSize(msg); } // repeated .google.protobuf.DescriptorProto.ExtensionRange extension_range = 5; total_size += 1UL * this->_internal_extension_range_size(); for (const auto& msg : this->_internal_extension_range()) { - total_size += - ::google::protobuf::internal::WireFormatLite::MessageSize(msg); + total_size += ::google::protobuf::internal::WireFormatLite::MessageSize(msg); } // repeated .google.protobuf.FieldDescriptorProto extension = 6; total_size += 1UL * this->_internal_extension_size(); for (const auto& msg : this->_internal_extension()) { - total_size += - ::google::protobuf::internal::WireFormatLite::MessageSize(msg); + total_size += ::google::protobuf::internal::WireFormatLite::MessageSize(msg); } // repeated .google.protobuf.OneofDescriptorProto oneof_decl = 8; total_size += 1UL * this->_internal_oneof_decl_size(); for (const auto& msg : this->_internal_oneof_decl()) { - total_size += - ::google::protobuf::internal::WireFormatLite::MessageSize(msg); + total_size += ::google::protobuf::internal::WireFormatLite::MessageSize(msg); } // repeated .google.protobuf.DescriptorProto.ReservedRange reserved_range = 9; total_size += 1UL * this->_internal_reserved_range_size(); for (const auto& msg : this->_internal_reserved_range()) { - total_size += - ::google::protobuf::internal::WireFormatLite::MessageSize(msg); + total_size += ::google::protobuf::internal::WireFormatLite::MessageSize(msg); } // repeated string reserved_name = 10; total_size += 1 * ::google::protobuf::internal::FromIntSize(_internal_reserved_name().size()); @@ -4090,18 +4109,12 @@ void DescriptorProto::CopyFrom(const DescriptorProto& from) { } PROTOBUF_NOINLINE bool DescriptorProto::IsInitialized() const { - if (!::google::protobuf::internal::AllAreInitialized(_internal_field())) - return false; - if (!::google::protobuf::internal::AllAreInitialized(_internal_nested_type())) - return false; - if (!::google::protobuf::internal::AllAreInitialized(_internal_enum_type())) - return false; - if (!::google::protobuf::internal::AllAreInitialized(_internal_extension_range())) - return false; - if (!::google::protobuf::internal::AllAreInitialized(_internal_extension())) - return false; - if (!::google::protobuf::internal::AllAreInitialized(_internal_oneof_decl())) - return false; + if (!::google::protobuf::internal::AllAreInitialized(_internal_field())) return false; + if (!::google::protobuf::internal::AllAreInitialized(_internal_nested_type())) return false; + if (!::google::protobuf::internal::AllAreInitialized(_internal_enum_type())) return false; + if (!::google::protobuf::internal::AllAreInitialized(_internal_extension_range())) return false; + if (!::google::protobuf::internal::AllAreInitialized(_internal_extension())) return false; + if (!::google::protobuf::internal::AllAreInitialized(_internal_oneof_decl())) return false; if ((_impl_._has_bits_[0] & 0x00000002u) != 0) { if (!_impl_.options_->IsInitialized()) return false; } @@ -4642,11 +4655,14 @@ ::uint8_t* ExtensionRangeOptions::_InternalSerialize( (void)cached_has_bits; // repeated .google.protobuf.ExtensionRangeOptions.Declaration declaration = 2 [retention = RETENTION_SOURCE]; - for (unsigned i = 0, - n = static_cast(this->_internal_declaration_size()); i < n; i++) { + for (unsigned i = 0, n = static_cast( + this->_internal_declaration_size()); + i < n; i++) { const auto& repfield = this->_internal_declaration().Get(i); - target = ::google::protobuf::internal::WireFormatLite:: - InternalWriteMessage(2, repfield, repfield.GetCachedSize(), target, stream); + target = + ::google::protobuf::internal::WireFormatLite::InternalWriteMessage( + 2, repfield, repfield.GetCachedSize(), + target, stream); } cached_has_bits = _impl_._has_bits_[0]; @@ -4664,11 +4680,14 @@ ::uint8_t* ExtensionRangeOptions::_InternalSerialize( } // repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; - for (unsigned i = 0, - n = static_cast(this->_internal_uninterpreted_option_size()); i < n; i++) { + for (unsigned i = 0, n = static_cast( + this->_internal_uninterpreted_option_size()); + i < n; i++) { const auto& repfield = this->_internal_uninterpreted_option().Get(i); - target = ::google::protobuf::internal::WireFormatLite:: - InternalWriteMessage(999, repfield, repfield.GetCachedSize(), target, stream); + target = + ::google::protobuf::internal::WireFormatLite::InternalWriteMessage( + 999, repfield, repfield.GetCachedSize(), + target, stream); } // Extension range [1000, 536870912) @@ -4696,14 +4715,12 @@ ::size_t ExtensionRangeOptions::ByteSizeLong() const { // repeated .google.protobuf.ExtensionRangeOptions.Declaration declaration = 2 [retention = RETENTION_SOURCE]; total_size += 1UL * this->_internal_declaration_size(); for (const auto& msg : this->_internal_declaration()) { - total_size += - ::google::protobuf::internal::WireFormatLite::MessageSize(msg); + total_size += ::google::protobuf::internal::WireFormatLite::MessageSize(msg); } // repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; total_size += 2UL * this->_internal_uninterpreted_option_size(); for (const auto& msg : this->_internal_uninterpreted_option()) { - total_size += - ::google::protobuf::internal::WireFormatLite::MessageSize(msg); + total_size += ::google::protobuf::internal::WireFormatLite::MessageSize(msg); } cached_has_bits = _impl_._has_bits_[0]; if (cached_has_bits & 0x00000003u) { @@ -4768,8 +4785,7 @@ PROTOBUF_NOINLINE bool ExtensionRangeOptions::IsInitialized() const { if (!_impl_._extensions_.IsInitialized(internal_default_instance())) { return false; } - if (!::google::protobuf::internal::AllAreInitialized(_internal_uninterpreted_option())) - return false; + if (!::google::protobuf::internal::AllAreInitialized(_internal_uninterpreted_option())) return false; if ((_impl_._has_bits_[0] & 0x00000001u) != 0) { if (!_impl_.features_->IsInitialized()) return false; } @@ -5999,11 +6015,14 @@ ::uint8_t* EnumDescriptorProto::_InternalSerialize( } // repeated .google.protobuf.EnumValueDescriptorProto value = 2; - for (unsigned i = 0, - n = static_cast(this->_internal_value_size()); i < n; i++) { + for (unsigned i = 0, n = static_cast( + this->_internal_value_size()); + i < n; i++) { const auto& repfield = this->_internal_value().Get(i); - target = ::google::protobuf::internal::WireFormatLite:: - InternalWriteMessage(2, repfield, repfield.GetCachedSize(), target, stream); + target = + ::google::protobuf::internal::WireFormatLite::InternalWriteMessage( + 2, repfield, repfield.GetCachedSize(), + target, stream); } // optional .google.protobuf.EnumOptions options = 3; @@ -6013,11 +6032,14 @@ ::uint8_t* EnumDescriptorProto::_InternalSerialize( } // repeated .google.protobuf.EnumDescriptorProto.EnumReservedRange reserved_range = 4; - for (unsigned i = 0, - n = static_cast(this->_internal_reserved_range_size()); i < n; i++) { + for (unsigned i = 0, n = static_cast( + this->_internal_reserved_range_size()); + i < n; i++) { const auto& repfield = this->_internal_reserved_range().Get(i); - target = ::google::protobuf::internal::WireFormatLite:: - InternalWriteMessage(4, repfield, repfield.GetCachedSize(), target, stream); + target = + ::google::protobuf::internal::WireFormatLite::InternalWriteMessage( + 4, repfield, repfield.GetCachedSize(), + target, stream); } // repeated string reserved_name = 5; @@ -6048,14 +6070,12 @@ ::size_t EnumDescriptorProto::ByteSizeLong() const { // repeated .google.protobuf.EnumValueDescriptorProto value = 2; total_size += 1UL * this->_internal_value_size(); for (const auto& msg : this->_internal_value()) { - total_size += - ::google::protobuf::internal::WireFormatLite::MessageSize(msg); + total_size += ::google::protobuf::internal::WireFormatLite::MessageSize(msg); } // repeated .google.protobuf.EnumDescriptorProto.EnumReservedRange reserved_range = 4; total_size += 1UL * this->_internal_reserved_range_size(); for (const auto& msg : this->_internal_reserved_range()) { - total_size += - ::google::protobuf::internal::WireFormatLite::MessageSize(msg); + total_size += ::google::protobuf::internal::WireFormatLite::MessageSize(msg); } // repeated string reserved_name = 5; total_size += 1 * ::google::protobuf::internal::FromIntSize(_internal_reserved_name().size()); @@ -6123,8 +6143,7 @@ void EnumDescriptorProto::CopyFrom(const EnumDescriptorProto& from) { } PROTOBUF_NOINLINE bool EnumDescriptorProto::IsInitialized() const { - if (!::google::protobuf::internal::AllAreInitialized(_internal_value())) - return false; + if (!::google::protobuf::internal::AllAreInitialized(_internal_value())) return false; if ((_impl_._has_bits_[0] & 0x00000002u) != 0) { if (!_impl_.options_->IsInitialized()) return false; } @@ -6611,11 +6630,14 @@ ::uint8_t* ServiceDescriptorProto::_InternalSerialize( } // repeated .google.protobuf.MethodDescriptorProto method = 2; - for (unsigned i = 0, - n = static_cast(this->_internal_method_size()); i < n; i++) { + for (unsigned i = 0, n = static_cast( + this->_internal_method_size()); + i < n; i++) { const auto& repfield = this->_internal_method().Get(i); - target = ::google::protobuf::internal::WireFormatLite:: - InternalWriteMessage(2, repfield, repfield.GetCachedSize(), target, stream); + target = + ::google::protobuf::internal::WireFormatLite::InternalWriteMessage( + 2, repfield, repfield.GetCachedSize(), + target, stream); } // optional .google.protobuf.ServiceOptions options = 3; @@ -6644,8 +6666,7 @@ ::size_t ServiceDescriptorProto::ByteSizeLong() const { // repeated .google.protobuf.MethodDescriptorProto method = 2; total_size += 1UL * this->_internal_method_size(); for (const auto& msg : this->_internal_method()) { - total_size += - ::google::protobuf::internal::WireFormatLite::MessageSize(msg); + total_size += ::google::protobuf::internal::WireFormatLite::MessageSize(msg); } cached_has_bits = _impl_._has_bits_[0]; if (cached_has_bits & 0x00000003u) { @@ -6704,8 +6725,7 @@ void ServiceDescriptorProto::CopyFrom(const ServiceDescriptorProto& from) { } PROTOBUF_NOINLINE bool ServiceDescriptorProto::IsInitialized() const { - if (!::google::protobuf::internal::AllAreInitialized(_internal_method())) - return false; + if (!::google::protobuf::internal::AllAreInitialized(_internal_method())) return false; if ((_impl_._has_bits_[0] & 0x00000002u) != 0) { if (!_impl_.options_->IsInitialized()) return false; } @@ -7631,11 +7651,14 @@ ::uint8_t* FileOptions::_InternalSerialize( } // repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; - for (unsigned i = 0, - n = static_cast(this->_internal_uninterpreted_option_size()); i < n; i++) { + for (unsigned i = 0, n = static_cast( + this->_internal_uninterpreted_option_size()); + i < n; i++) { const auto& repfield = this->_internal_uninterpreted_option().Get(i); - target = ::google::protobuf::internal::WireFormatLite:: - InternalWriteMessage(999, repfield, repfield.GetCachedSize(), target, stream); + target = + ::google::protobuf::internal::WireFormatLite::InternalWriteMessage( + 999, repfield, repfield.GetCachedSize(), + target, stream); } // Extension range [1000, 536870912) @@ -7663,8 +7686,7 @@ ::size_t FileOptions::ByteSizeLong() const { // repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; total_size += 2UL * this->_internal_uninterpreted_option_size(); for (const auto& msg : this->_internal_uninterpreted_option()) { - total_size += - ::google::protobuf::internal::WireFormatLite::MessageSize(msg); + total_size += ::google::protobuf::internal::WireFormatLite::MessageSize(msg); } cached_has_bits = _impl_._has_bits_[0]; if (cached_has_bits & 0x000000ffu) { @@ -7889,8 +7911,7 @@ PROTOBUF_NOINLINE bool FileOptions::IsInitialized() const { if (!_impl_._extensions_.IsInitialized(internal_default_instance())) { return false; } - if (!::google::protobuf::internal::AllAreInitialized(_internal_uninterpreted_option())) - return false; + if (!::google::protobuf::internal::AllAreInitialized(_internal_uninterpreted_option())) return false; if ((_impl_._has_bits_[0] & 0x00000400u) != 0) { if (!_impl_.features_->IsInitialized()) return false; } @@ -8163,11 +8184,14 @@ ::uint8_t* MessageOptions::_InternalSerialize( } // repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; - for (unsigned i = 0, - n = static_cast(this->_internal_uninterpreted_option_size()); i < n; i++) { + for (unsigned i = 0, n = static_cast( + this->_internal_uninterpreted_option_size()); + i < n; i++) { const auto& repfield = this->_internal_uninterpreted_option().Get(i); - target = ::google::protobuf::internal::WireFormatLite:: - InternalWriteMessage(999, repfield, repfield.GetCachedSize(), target, stream); + target = + ::google::protobuf::internal::WireFormatLite::InternalWriteMessage( + 999, repfield, repfield.GetCachedSize(), + target, stream); } // Extension range [1000, 536870912) @@ -8195,8 +8219,7 @@ ::size_t MessageOptions::ByteSizeLong() const { // repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; total_size += 2UL * this->_internal_uninterpreted_option_size(); for (const auto& msg : this->_internal_uninterpreted_option()) { - total_size += - ::google::protobuf::internal::WireFormatLite::MessageSize(msg); + total_size += ::google::protobuf::internal::WireFormatLite::MessageSize(msg); } cached_has_bits = _impl_._has_bits_[0]; if (cached_has_bits & 0x0000003fu) { @@ -8290,8 +8313,7 @@ PROTOBUF_NOINLINE bool MessageOptions::IsInitialized() const { if (!_impl_._extensions_.IsInitialized(internal_default_instance())) { return false; } - if (!::google::protobuf::internal::AllAreInitialized(_internal_uninterpreted_option())) - return false; + if (!::google::protobuf::internal::AllAreInitialized(_internal_uninterpreted_option())) return false; if ((_impl_._has_bits_[0] & 0x00000001u) != 0) { if (!_impl_.features_->IsInitialized()) return false; } @@ -8873,11 +8895,14 @@ ::uint8_t* FieldOptions::_InternalSerialize( } // repeated .google.protobuf.FieldOptions.EditionDefault edition_defaults = 20; - for (unsigned i = 0, - n = static_cast(this->_internal_edition_defaults_size()); i < n; i++) { + for (unsigned i = 0, n = static_cast( + this->_internal_edition_defaults_size()); + i < n; i++) { const auto& repfield = this->_internal_edition_defaults().Get(i); - target = ::google::protobuf::internal::WireFormatLite:: - InternalWriteMessage(20, repfield, repfield.GetCachedSize(), target, stream); + target = + ::google::protobuf::internal::WireFormatLite::InternalWriteMessage( + 20, repfield, repfield.GetCachedSize(), + target, stream); } // optional .google.protobuf.FeatureSet features = 21; @@ -8887,11 +8912,14 @@ ::uint8_t* FieldOptions::_InternalSerialize( } // repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; - for (unsigned i = 0, - n = static_cast(this->_internal_uninterpreted_option_size()); i < n; i++) { + for (unsigned i = 0, n = static_cast( + this->_internal_uninterpreted_option_size()); + i < n; i++) { const auto& repfield = this->_internal_uninterpreted_option().Get(i); - target = ::google::protobuf::internal::WireFormatLite:: - InternalWriteMessage(999, repfield, repfield.GetCachedSize(), target, stream); + target = + ::google::protobuf::internal::WireFormatLite::InternalWriteMessage( + 999, repfield, repfield.GetCachedSize(), + target, stream); } // Extension range [1000, 536870912) @@ -8931,14 +8959,12 @@ ::size_t FieldOptions::ByteSizeLong() const { // repeated .google.protobuf.FieldOptions.EditionDefault edition_defaults = 20; total_size += 2UL * this->_internal_edition_defaults_size(); for (const auto& msg : this->_internal_edition_defaults()) { - total_size += - ::google::protobuf::internal::WireFormatLite::MessageSize(msg); + total_size += ::google::protobuf::internal::WireFormatLite::MessageSize(msg); } // repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; total_size += 2UL * this->_internal_uninterpreted_option_size(); for (const auto& msg : this->_internal_uninterpreted_option()) { - total_size += - ::google::protobuf::internal::WireFormatLite::MessageSize(msg); + total_size += ::google::protobuf::internal::WireFormatLite::MessageSize(msg); } cached_has_bits = _impl_._has_bits_[0]; if (cached_has_bits & 0x000000ffu) { @@ -9074,8 +9100,7 @@ PROTOBUF_NOINLINE bool FieldOptions::IsInitialized() const { if (!_impl_._extensions_.IsInitialized(internal_default_instance())) { return false; } - if (!::google::protobuf::internal::AllAreInitialized(_internal_uninterpreted_option())) - return false; + if (!::google::protobuf::internal::AllAreInitialized(_internal_uninterpreted_option())) return false; if ((_impl_._has_bits_[0] & 0x00000001u) != 0) { if (!_impl_.features_->IsInitialized()) return false; } @@ -9261,11 +9286,14 @@ ::uint8_t* OneofOptions::_InternalSerialize( } // repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; - for (unsigned i = 0, - n = static_cast(this->_internal_uninterpreted_option_size()); i < n; i++) { + for (unsigned i = 0, n = static_cast( + this->_internal_uninterpreted_option_size()); + i < n; i++) { const auto& repfield = this->_internal_uninterpreted_option().Get(i); - target = ::google::protobuf::internal::WireFormatLite:: - InternalWriteMessage(999, repfield, repfield.GetCachedSize(), target, stream); + target = + ::google::protobuf::internal::WireFormatLite::InternalWriteMessage( + 999, repfield, repfield.GetCachedSize(), + target, stream); } // Extension range [1000, 536870912) @@ -9293,8 +9321,7 @@ ::size_t OneofOptions::ByteSizeLong() const { // repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; total_size += 2UL * this->_internal_uninterpreted_option_size(); for (const auto& msg : this->_internal_uninterpreted_option()) { - total_size += - ::google::protobuf::internal::WireFormatLite::MessageSize(msg); + total_size += ::google::protobuf::internal::WireFormatLite::MessageSize(msg); } // optional .google.protobuf.FeatureSet features = 1; cached_has_bits = _impl_._has_bits_[0]; @@ -9344,8 +9371,7 @@ PROTOBUF_NOINLINE bool OneofOptions::IsInitialized() const { if (!_impl_._extensions_.IsInitialized(internal_default_instance())) { return false; } - if (!::google::protobuf::internal::AllAreInitialized(_internal_uninterpreted_option())) - return false; + if (!::google::protobuf::internal::AllAreInitialized(_internal_uninterpreted_option())) return false; if ((_impl_._has_bits_[0] & 0x00000001u) != 0) { if (!_impl_.features_->IsInitialized()) return false; } @@ -9577,11 +9603,14 @@ ::uint8_t* EnumOptions::_InternalSerialize( } // repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; - for (unsigned i = 0, - n = static_cast(this->_internal_uninterpreted_option_size()); i < n; i++) { + for (unsigned i = 0, n = static_cast( + this->_internal_uninterpreted_option_size()); + i < n; i++) { const auto& repfield = this->_internal_uninterpreted_option().Get(i); - target = ::google::protobuf::internal::WireFormatLite:: - InternalWriteMessage(999, repfield, repfield.GetCachedSize(), target, stream); + target = + ::google::protobuf::internal::WireFormatLite::InternalWriteMessage( + 999, repfield, repfield.GetCachedSize(), + target, stream); } // Extension range [1000, 536870912) @@ -9609,8 +9638,7 @@ ::size_t EnumOptions::ByteSizeLong() const { // repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; total_size += 2UL * this->_internal_uninterpreted_option_size(); for (const auto& msg : this->_internal_uninterpreted_option()) { - total_size += - ::google::protobuf::internal::WireFormatLite::MessageSize(msg); + total_size += ::google::protobuf::internal::WireFormatLite::MessageSize(msg); } cached_has_bits = _impl_._has_bits_[0]; if (cached_has_bits & 0x0000000fu) { @@ -9688,8 +9716,7 @@ PROTOBUF_NOINLINE bool EnumOptions::IsInitialized() const { if (!_impl_._extensions_.IsInitialized(internal_default_instance())) { return false; } - if (!::google::protobuf::internal::AllAreInitialized(_internal_uninterpreted_option())) - return false; + if (!::google::protobuf::internal::AllAreInitialized(_internal_uninterpreted_option())) return false; if ((_impl_._has_bits_[0] & 0x00000001u) != 0) { if (!_impl_.features_->IsInitialized()) return false; } @@ -9916,11 +9943,14 @@ ::uint8_t* EnumValueOptions::_InternalSerialize( } // repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; - for (unsigned i = 0, - n = static_cast(this->_internal_uninterpreted_option_size()); i < n; i++) { + for (unsigned i = 0, n = static_cast( + this->_internal_uninterpreted_option_size()); + i < n; i++) { const auto& repfield = this->_internal_uninterpreted_option().Get(i); - target = ::google::protobuf::internal::WireFormatLite:: - InternalWriteMessage(999, repfield, repfield.GetCachedSize(), target, stream); + target = + ::google::protobuf::internal::WireFormatLite::InternalWriteMessage( + 999, repfield, repfield.GetCachedSize(), + target, stream); } // Extension range [1000, 536870912) @@ -9948,8 +9978,7 @@ ::size_t EnumValueOptions::ByteSizeLong() const { // repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; total_size += 2UL * this->_internal_uninterpreted_option_size(); for (const auto& msg : this->_internal_uninterpreted_option()) { - total_size += - ::google::protobuf::internal::WireFormatLite::MessageSize(msg); + total_size += ::google::protobuf::internal::WireFormatLite::MessageSize(msg); } cached_has_bits = _impl_._has_bits_[0]; if (cached_has_bits & 0x00000007u) { @@ -10019,8 +10048,7 @@ PROTOBUF_NOINLINE bool EnumValueOptions::IsInitialized() const { if (!_impl_._extensions_.IsInitialized(internal_default_instance())) { return false; } - if (!::google::protobuf::internal::AllAreInitialized(_internal_uninterpreted_option())) - return false; + if (!::google::protobuf::internal::AllAreInitialized(_internal_uninterpreted_option())) return false; if ((_impl_._has_bits_[0] & 0x00000001u) != 0) { if (!_impl_.features_->IsInitialized()) return false; } @@ -10224,11 +10252,14 @@ ::uint8_t* ServiceOptions::_InternalSerialize( } // repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; - for (unsigned i = 0, - n = static_cast(this->_internal_uninterpreted_option_size()); i < n; i++) { + for (unsigned i = 0, n = static_cast( + this->_internal_uninterpreted_option_size()); + i < n; i++) { const auto& repfield = this->_internal_uninterpreted_option().Get(i); - target = ::google::protobuf::internal::WireFormatLite:: - InternalWriteMessage(999, repfield, repfield.GetCachedSize(), target, stream); + target = + ::google::protobuf::internal::WireFormatLite::InternalWriteMessage( + 999, repfield, repfield.GetCachedSize(), + target, stream); } // Extension range [1000, 536870912) @@ -10256,8 +10287,7 @@ ::size_t ServiceOptions::ByteSizeLong() const { // repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; total_size += 2UL * this->_internal_uninterpreted_option_size(); for (const auto& msg : this->_internal_uninterpreted_option()) { - total_size += - ::google::protobuf::internal::WireFormatLite::MessageSize(msg); + total_size += ::google::protobuf::internal::WireFormatLite::MessageSize(msg); } cached_has_bits = _impl_._has_bits_[0]; if (cached_has_bits & 0x00000003u) { @@ -10319,8 +10349,7 @@ PROTOBUF_NOINLINE bool ServiceOptions::IsInitialized() const { if (!_impl_._extensions_.IsInitialized(internal_default_instance())) { return false; } - if (!::google::protobuf::internal::AllAreInitialized(_internal_uninterpreted_option())) - return false; + if (!::google::protobuf::internal::AllAreInitialized(_internal_uninterpreted_option())) return false; if ((_impl_._has_bits_[0] & 0x00000001u) != 0) { if (!_impl_.features_->IsInitialized()) return false; } @@ -10551,11 +10580,14 @@ ::uint8_t* MethodOptions::_InternalSerialize( } // repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; - for (unsigned i = 0, - n = static_cast(this->_internal_uninterpreted_option_size()); i < n; i++) { + for (unsigned i = 0, n = static_cast( + this->_internal_uninterpreted_option_size()); + i < n; i++) { const auto& repfield = this->_internal_uninterpreted_option().Get(i); - target = ::google::protobuf::internal::WireFormatLite:: - InternalWriteMessage(999, repfield, repfield.GetCachedSize(), target, stream); + target = + ::google::protobuf::internal::WireFormatLite::InternalWriteMessage( + 999, repfield, repfield.GetCachedSize(), + target, stream); } // Extension range [1000, 536870912) @@ -10583,8 +10615,7 @@ ::size_t MethodOptions::ByteSizeLong() const { // repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; total_size += 2UL * this->_internal_uninterpreted_option_size(); for (const auto& msg : this->_internal_uninterpreted_option()) { - total_size += - ::google::protobuf::internal::WireFormatLite::MessageSize(msg); + total_size += ::google::protobuf::internal::WireFormatLite::MessageSize(msg); } cached_has_bits = _impl_._has_bits_[0]; if (cached_has_bits & 0x00000007u) { @@ -10655,8 +10686,7 @@ PROTOBUF_NOINLINE bool MethodOptions::IsInitialized() const { if (!_impl_._extensions_.IsInitialized(internal_default_instance())) { return false; } - if (!::google::protobuf::internal::AllAreInitialized(_internal_uninterpreted_option())) - return false; + if (!::google::protobuf::internal::AllAreInitialized(_internal_uninterpreted_option())) return false; if ((_impl_._has_bits_[0] & 0x00000001u) != 0) { if (!_impl_.features_->IsInitialized()) return false; } @@ -11131,11 +11161,14 @@ ::uint8_t* UninterpretedOption::_InternalSerialize( (void)cached_has_bits; // repeated .google.protobuf.UninterpretedOption.NamePart name = 2; - for (unsigned i = 0, - n = static_cast(this->_internal_name_size()); i < n; i++) { + for (unsigned i = 0, n = static_cast( + this->_internal_name_size()); + i < n; i++) { const auto& repfield = this->_internal_name().Get(i); - target = ::google::protobuf::internal::WireFormatLite:: - InternalWriteMessage(2, repfield, repfield.GetCachedSize(), target, stream); + target = + ::google::protobuf::internal::WireFormatLite::InternalWriteMessage( + 2, repfield, repfield.GetCachedSize(), + target, stream); } cached_has_bits = _impl_._has_bits_[0]; @@ -11202,8 +11235,7 @@ ::size_t UninterpretedOption::ByteSizeLong() const { // repeated .google.protobuf.UninterpretedOption.NamePart name = 2; total_size += 1UL * this->_internal_name_size(); for (const auto& msg : this->_internal_name()) { - total_size += - ::google::protobuf::internal::WireFormatLite::MessageSize(msg); + total_size += ::google::protobuf::internal::WireFormatLite::MessageSize(msg); } cached_has_bits = _impl_._has_bits_[0]; if (cached_has_bits & 0x0000003fu) { @@ -11290,8 +11322,7 @@ void UninterpretedOption::CopyFrom(const UninterpretedOption& from) { } PROTOBUF_NOINLINE bool UninterpretedOption::IsInitialized() const { - if (!::google::protobuf::internal::AllAreInitialized(_internal_name())) - return false; + if (!::google::protobuf::internal::AllAreInitialized(_internal_name())) return false; return true; } @@ -12083,11 +12114,14 @@ ::uint8_t* FeatureSetDefaults::_InternalSerialize( (void)cached_has_bits; // repeated .google.protobuf.FeatureSetDefaults.FeatureSetEditionDefault defaults = 1; - for (unsigned i = 0, - n = static_cast(this->_internal_defaults_size()); i < n; i++) { + for (unsigned i = 0, n = static_cast( + this->_internal_defaults_size()); + i < n; i++) { const auto& repfield = this->_internal_defaults().Get(i); - target = ::google::protobuf::internal::WireFormatLite:: - InternalWriteMessage(1, repfield, repfield.GetCachedSize(), target, stream); + target = + ::google::protobuf::internal::WireFormatLite::InternalWriteMessage( + 1, repfield, repfield.GetCachedSize(), + target, stream); } cached_has_bits = _impl_._has_bits_[0]; @@ -12125,8 +12159,7 @@ ::size_t FeatureSetDefaults::ByteSizeLong() const { // repeated .google.protobuf.FeatureSetDefaults.FeatureSetEditionDefault defaults = 1; total_size += 1UL * this->_internal_defaults_size(); for (const auto& msg : this->_internal_defaults()) { - total_size += - ::google::protobuf::internal::WireFormatLite::MessageSize(msg); + total_size += ::google::protobuf::internal::WireFormatLite::MessageSize(msg); } cached_has_bits = _impl_._has_bits_[0]; if (cached_has_bits & 0x00000003u) { @@ -12178,8 +12211,7 @@ void FeatureSetDefaults::CopyFrom(const FeatureSetDefaults& from) { } PROTOBUF_NOINLINE bool FeatureSetDefaults::IsInitialized() const { - if (!::google::protobuf::internal::AllAreInitialized(_internal_defaults())) - return false; + if (!::google::protobuf::internal::AllAreInitialized(_internal_defaults())) return false; return true; } @@ -12666,11 +12698,14 @@ ::uint8_t* SourceCodeInfo::_InternalSerialize( (void)cached_has_bits; // repeated .google.protobuf.SourceCodeInfo.Location location = 1; - for (unsigned i = 0, - n = static_cast(this->_internal_location_size()); i < n; i++) { + for (unsigned i = 0, n = static_cast( + this->_internal_location_size()); + i < n; i++) { const auto& repfield = this->_internal_location().Get(i); - target = ::google::protobuf::internal::WireFormatLite:: - InternalWriteMessage(1, repfield, repfield.GetCachedSize(), target, stream); + target = + ::google::protobuf::internal::WireFormatLite::InternalWriteMessage( + 1, repfield, repfield.GetCachedSize(), + target, stream); } if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) { @@ -12693,8 +12728,7 @@ ::size_t SourceCodeInfo::ByteSizeLong() const { // repeated .google.protobuf.SourceCodeInfo.Location location = 1; total_size += 1UL * this->_internal_location_size(); for (const auto& msg : this->_internal_location()) { - total_size += - ::google::protobuf::internal::WireFormatLite::MessageSize(msg); + total_size += ::google::protobuf::internal::WireFormatLite::MessageSize(msg); } return MaybeComputeUnknownFieldsSize(total_size, &_impl_._cached_size_); } @@ -13196,11 +13230,14 @@ ::uint8_t* GeneratedCodeInfo::_InternalSerialize( (void)cached_has_bits; // repeated .google.protobuf.GeneratedCodeInfo.Annotation annotation = 1; - for (unsigned i = 0, - n = static_cast(this->_internal_annotation_size()); i < n; i++) { + for (unsigned i = 0, n = static_cast( + this->_internal_annotation_size()); + i < n; i++) { const auto& repfield = this->_internal_annotation().Get(i); - target = ::google::protobuf::internal::WireFormatLite:: - InternalWriteMessage(1, repfield, repfield.GetCachedSize(), target, stream); + target = + ::google::protobuf::internal::WireFormatLite::InternalWriteMessage( + 1, repfield, repfield.GetCachedSize(), + target, stream); } if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) { @@ -13223,8 +13260,7 @@ ::size_t GeneratedCodeInfo::ByteSizeLong() const { // repeated .google.protobuf.GeneratedCodeInfo.Annotation annotation = 1; total_size += 1UL * this->_internal_annotation_size(); for (const auto& msg : this->_internal_annotation()) { - total_size += - ::google::protobuf::internal::WireFormatLite::MessageSize(msg); + total_size += ::google::protobuf::internal::WireFormatLite::MessageSize(msg); } return MaybeComputeUnknownFieldsSize(total_size, &_impl_._cached_size_); } From 7bb9c9813396aec1a1eedd2b07b60575e0c91cd1 Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Sat, 6 Jan 2024 00:23:07 +0000 Subject: [PATCH 196/255] Auto-generate files after cl/596105029 --- src/google/protobuf/api.pb.cc | 56 ++++++++++++--------- src/google/protobuf/struct.pb.cc | 14 +++--- src/google/protobuf/type.pb.cc | 84 ++++++++++++++++++-------------- 3 files changed, 88 insertions(+), 66 deletions(-) diff --git a/src/google/protobuf/api.pb.cc b/src/google/protobuf/api.pb.cc index 10ce6495b8314..4e42b5e49ff17 100644 --- a/src/google/protobuf/api.pb.cc +++ b/src/google/protobuf/api.pb.cc @@ -459,19 +459,25 @@ ::uint8_t* Api::_InternalSerialize( } // repeated .google.protobuf.Method methods = 2; - for (unsigned i = 0, - n = static_cast(this->_internal_methods_size()); i < n; i++) { + for (unsigned i = 0, n = static_cast( + this->_internal_methods_size()); + i < n; i++) { const auto& repfield = this->_internal_methods().Get(i); - target = ::google::protobuf::internal::WireFormatLite:: - InternalWriteMessage(2, repfield, repfield.GetCachedSize(), target, stream); + target = + ::google::protobuf::internal::WireFormatLite::InternalWriteMessage( + 2, repfield, repfield.GetCachedSize(), + target, stream); } // repeated .google.protobuf.Option options = 3; - for (unsigned i = 0, - n = static_cast(this->_internal_options_size()); i < n; i++) { + for (unsigned i = 0, n = static_cast( + this->_internal_options_size()); + i < n; i++) { const auto& repfield = this->_internal_options().Get(i); - target = ::google::protobuf::internal::WireFormatLite:: - InternalWriteMessage(3, repfield, repfield.GetCachedSize(), target, stream); + target = + ::google::protobuf::internal::WireFormatLite::InternalWriteMessage( + 3, repfield, repfield.GetCachedSize(), + target, stream); } // string version = 4; @@ -490,11 +496,14 @@ ::uint8_t* Api::_InternalSerialize( } // repeated .google.protobuf.Mixin mixins = 6; - for (unsigned i = 0, - n = static_cast(this->_internal_mixins_size()); i < n; i++) { + for (unsigned i = 0, n = static_cast( + this->_internal_mixins_size()); + i < n; i++) { const auto& repfield = this->_internal_mixins().Get(i); - target = ::google::protobuf::internal::WireFormatLite:: - InternalWriteMessage(6, repfield, repfield.GetCachedSize(), target, stream); + target = + ::google::protobuf::internal::WireFormatLite::InternalWriteMessage( + 6, repfield, repfield.GetCachedSize(), + target, stream); } // .google.protobuf.Syntax syntax = 7; @@ -524,20 +533,17 @@ ::size_t Api::ByteSizeLong() const { // repeated .google.protobuf.Method methods = 2; total_size += 1UL * this->_internal_methods_size(); for (const auto& msg : this->_internal_methods()) { - total_size += - ::google::protobuf::internal::WireFormatLite::MessageSize(msg); + total_size += ::google::protobuf::internal::WireFormatLite::MessageSize(msg); } // repeated .google.protobuf.Option options = 3; total_size += 1UL * this->_internal_options_size(); for (const auto& msg : this->_internal_options()) { - total_size += - ::google::protobuf::internal::WireFormatLite::MessageSize(msg); + total_size += ::google::protobuf::internal::WireFormatLite::MessageSize(msg); } // repeated .google.protobuf.Mixin mixins = 6; total_size += 1UL * this->_internal_mixins_size(); for (const auto& msg : this->_internal_mixins()) { - total_size += - ::google::protobuf::internal::WireFormatLite::MessageSize(msg); + total_size += ::google::protobuf::internal::WireFormatLite::MessageSize(msg); } // string name = 1; if (!this->_internal_name().empty()) { @@ -874,11 +880,14 @@ ::uint8_t* Method::_InternalSerialize( } // repeated .google.protobuf.Option options = 6; - for (unsigned i = 0, - n = static_cast(this->_internal_options_size()); i < n; i++) { + for (unsigned i = 0, n = static_cast( + this->_internal_options_size()); + i < n; i++) { const auto& repfield = this->_internal_options().Get(i); - target = ::google::protobuf::internal::WireFormatLite:: - InternalWriteMessage(6, repfield, repfield.GetCachedSize(), target, stream); + target = + ::google::protobuf::internal::WireFormatLite::InternalWriteMessage( + 6, repfield, repfield.GetCachedSize(), + target, stream); } // .google.protobuf.Syntax syntax = 7; @@ -908,8 +917,7 @@ ::size_t Method::ByteSizeLong() const { // repeated .google.protobuf.Option options = 6; total_size += 1UL * this->_internal_options_size(); for (const auto& msg : this->_internal_options()) { - total_size += - ::google::protobuf::internal::WireFormatLite::MessageSize(msg); + total_size += ::google::protobuf::internal::WireFormatLite::MessageSize(msg); } // string name = 1; if (!this->_internal_name().empty()) { diff --git a/src/google/protobuf/struct.pb.cc b/src/google/protobuf/struct.pb.cc index 8fbfe1ada60ef..b7db8e24083f3 100644 --- a/src/google/protobuf/struct.pb.cc +++ b/src/google/protobuf/struct.pb.cc @@ -989,11 +989,14 @@ ::uint8_t* ListValue::_InternalSerialize( (void)cached_has_bits; // repeated .google.protobuf.Value values = 1; - for (unsigned i = 0, - n = static_cast(this->_internal_values_size()); i < n; i++) { + for (unsigned i = 0, n = static_cast( + this->_internal_values_size()); + i < n; i++) { const auto& repfield = this->_internal_values().Get(i); - target = ::google::protobuf::internal::WireFormatLite:: - InternalWriteMessage(1, repfield, repfield.GetCachedSize(), target, stream); + target = + ::google::protobuf::internal::WireFormatLite::InternalWriteMessage( + 1, repfield, repfield.GetCachedSize(), + target, stream); } if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) { @@ -1016,8 +1019,7 @@ ::size_t ListValue::ByteSizeLong() const { // repeated .google.protobuf.Value values = 1; total_size += 1UL * this->_internal_values_size(); for (const auto& msg : this->_internal_values()) { - total_size += - ::google::protobuf::internal::WireFormatLite::MessageSize(msg); + total_size += ::google::protobuf::internal::WireFormatLite::MessageSize(msg); } return MaybeComputeUnknownFieldsSize(total_size, &_impl_._cached_size_); } diff --git a/src/google/protobuf/type.pb.cc b/src/google/protobuf/type.pb.cc index fac84937f16b2..acab7dac5fc06 100644 --- a/src/google/protobuf/type.pb.cc +++ b/src/google/protobuf/type.pb.cc @@ -639,11 +639,14 @@ ::uint8_t* Type::_InternalSerialize( } // repeated .google.protobuf.Field fields = 2; - for (unsigned i = 0, - n = static_cast(this->_internal_fields_size()); i < n; i++) { + for (unsigned i = 0, n = static_cast( + this->_internal_fields_size()); + i < n; i++) { const auto& repfield = this->_internal_fields().Get(i); - target = ::google::protobuf::internal::WireFormatLite:: - InternalWriteMessage(2, repfield, repfield.GetCachedSize(), target, stream); + target = + ::google::protobuf::internal::WireFormatLite::InternalWriteMessage( + 2, repfield, repfield.GetCachedSize(), + target, stream); } // repeated string oneofs = 3; @@ -655,11 +658,14 @@ ::uint8_t* Type::_InternalSerialize( } // repeated .google.protobuf.Option options = 4; - for (unsigned i = 0, - n = static_cast(this->_internal_options_size()); i < n; i++) { + for (unsigned i = 0, n = static_cast( + this->_internal_options_size()); + i < n; i++) { const auto& repfield = this->_internal_options().Get(i); - target = ::google::protobuf::internal::WireFormatLite:: - InternalWriteMessage(4, repfield, repfield.GetCachedSize(), target, stream); + target = + ::google::protobuf::internal::WireFormatLite::InternalWriteMessage( + 4, repfield, repfield.GetCachedSize(), + target, stream); } cached_has_bits = _impl_._has_bits_[0]; @@ -704,8 +710,7 @@ ::size_t Type::ByteSizeLong() const { // repeated .google.protobuf.Field fields = 2; total_size += 1UL * this->_internal_fields_size(); for (const auto& msg : this->_internal_fields()) { - total_size += - ::google::protobuf::internal::WireFormatLite::MessageSize(msg); + total_size += ::google::protobuf::internal::WireFormatLite::MessageSize(msg); } // repeated string oneofs = 3; total_size += 1 * ::google::protobuf::internal::FromIntSize(_internal_oneofs().size()); @@ -716,8 +721,7 @@ ::size_t Type::ByteSizeLong() const { // repeated .google.protobuf.Option options = 4; total_size += 1UL * this->_internal_options_size(); for (const auto& msg : this->_internal_options()) { - total_size += - ::google::protobuf::internal::WireFormatLite::MessageSize(msg); + total_size += ::google::protobuf::internal::WireFormatLite::MessageSize(msg); } // string name = 1; if (!this->_internal_name().empty()) { @@ -1090,11 +1094,14 @@ ::uint8_t* Field::_InternalSerialize( } // repeated .google.protobuf.Option options = 9; - for (unsigned i = 0, - n = static_cast(this->_internal_options_size()); i < n; i++) { + for (unsigned i = 0, n = static_cast( + this->_internal_options_size()); + i < n; i++) { const auto& repfield = this->_internal_options().Get(i); - target = ::google::protobuf::internal::WireFormatLite:: - InternalWriteMessage(9, repfield, repfield.GetCachedSize(), target, stream); + target = + ::google::protobuf::internal::WireFormatLite::InternalWriteMessage( + 9, repfield, repfield.GetCachedSize(), + target, stream); } // string json_name = 10; @@ -1133,8 +1140,7 @@ ::size_t Field::ByteSizeLong() const { // repeated .google.protobuf.Option options = 9; total_size += 1UL * this->_internal_options_size(); for (const auto& msg : this->_internal_options()) { - total_size += - ::google::protobuf::internal::WireFormatLite::MessageSize(msg); + total_size += ::google::protobuf::internal::WireFormatLite::MessageSize(msg); } // string name = 4; if (!this->_internal_name().empty()) { @@ -1473,19 +1479,25 @@ ::uint8_t* Enum::_InternalSerialize( } // repeated .google.protobuf.EnumValue enumvalue = 2; - for (unsigned i = 0, - n = static_cast(this->_internal_enumvalue_size()); i < n; i++) { + for (unsigned i = 0, n = static_cast( + this->_internal_enumvalue_size()); + i < n; i++) { const auto& repfield = this->_internal_enumvalue().Get(i); - target = ::google::protobuf::internal::WireFormatLite:: - InternalWriteMessage(2, repfield, repfield.GetCachedSize(), target, stream); + target = + ::google::protobuf::internal::WireFormatLite::InternalWriteMessage( + 2, repfield, repfield.GetCachedSize(), + target, stream); } // repeated .google.protobuf.Option options = 3; - for (unsigned i = 0, - n = static_cast(this->_internal_options_size()); i < n; i++) { + for (unsigned i = 0, n = static_cast( + this->_internal_options_size()); + i < n; i++) { const auto& repfield = this->_internal_options().Get(i); - target = ::google::protobuf::internal::WireFormatLite:: - InternalWriteMessage(3, repfield, repfield.GetCachedSize(), target, stream); + target = + ::google::protobuf::internal::WireFormatLite::InternalWriteMessage( + 3, repfield, repfield.GetCachedSize(), + target, stream); } cached_has_bits = _impl_._has_bits_[0]; @@ -1530,14 +1542,12 @@ ::size_t Enum::ByteSizeLong() const { // repeated .google.protobuf.EnumValue enumvalue = 2; total_size += 1UL * this->_internal_enumvalue_size(); for (const auto& msg : this->_internal_enumvalue()) { - total_size += - ::google::protobuf::internal::WireFormatLite::MessageSize(msg); + total_size += ::google::protobuf::internal::WireFormatLite::MessageSize(msg); } // repeated .google.protobuf.Option options = 3; total_size += 1UL * this->_internal_options_size(); for (const auto& msg : this->_internal_options()) { - total_size += - ::google::protobuf::internal::WireFormatLite::MessageSize(msg); + total_size += ::google::protobuf::internal::WireFormatLite::MessageSize(msg); } // string name = 1; if (!this->_internal_name().empty()) { @@ -1797,11 +1807,14 @@ ::uint8_t* EnumValue::_InternalSerialize( } // repeated .google.protobuf.Option options = 3; - for (unsigned i = 0, - n = static_cast(this->_internal_options_size()); i < n; i++) { + for (unsigned i = 0, n = static_cast( + this->_internal_options_size()); + i < n; i++) { const auto& repfield = this->_internal_options().Get(i); - target = ::google::protobuf::internal::WireFormatLite:: - InternalWriteMessage(3, repfield, repfield.GetCachedSize(), target, stream); + target = + ::google::protobuf::internal::WireFormatLite::InternalWriteMessage( + 3, repfield, repfield.GetCachedSize(), + target, stream); } if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) { @@ -1824,8 +1837,7 @@ ::size_t EnumValue::ByteSizeLong() const { // repeated .google.protobuf.Option options = 3; total_size += 1UL * this->_internal_options_size(); for (const auto& msg : this->_internal_options()) { - total_size += - ::google::protobuf::internal::WireFormatLite::MessageSize(msg); + total_size += ::google::protobuf::internal::WireFormatLite::MessageSize(msg); } // string name = 1; if (!this->_internal_name().empty()) { From e77b709750f7445e4d4a95df74583037a279b19b Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Fri, 5 Jan 2024 18:11:11 -0800 Subject: [PATCH 197/255] Remove unused PROTOBUF_FORCE_RESET_IN_CLEAR PiperOrigin-RevId: 596124853 --- src/google/protobuf/port_def.inc | 4 ---- src/google/protobuf/port_undef.inc | 1 - 2 files changed, 5 deletions(-) diff --git a/src/google/protobuf/port_def.inc b/src/google/protobuf/port_def.inc index edf0fccdf035d..ac61dcd59a517 100644 --- a/src/google/protobuf/port_def.inc +++ b/src/google/protobuf/port_def.inc @@ -442,10 +442,6 @@ static_assert(PROTOBUF_ABSL_MIN(20230125, 3), #error PROTOBUF_FORCE_COPY_IN_MOVE was previously defined #endif -#ifdef PROTOBUF_FORCE_RESET_IN_CLEAR -#error PROTOBUF_FORCE_RESET_IN_CLEAR was previously defined -#endif - #ifdef PROTOBUF_FUZZ_MESSAGE_SPACE_USED_LONG #error PROTOBUF_FUZZ_MESSAGE_SPACE_USED_LONG was previously defined #endif diff --git a/src/google/protobuf/port_undef.inc b/src/google/protobuf/port_undef.inc index a107fb325f525..4e210c5c1e787 100644 --- a/src/google/protobuf/port_undef.inc +++ b/src/google/protobuf/port_undef.inc @@ -48,7 +48,6 @@ #undef PROTOBUF_FORCE_COPY_IN_RELEASE #undef PROTOBUF_FORCE_COPY_IN_SWAP #undef PROTOBUF_FORCE_COPY_IN_MOVE -#undef PROTOBUF_FORCE_RESET_IN_CLEAR #undef PROTOBUF_FUZZ_MESSAGE_SPACE_USED_LONG #undef PROTOBUF_FORCE_COPY_DEFAULT_STRING #undef PROTOBUF_FORCE_ALLOCATION_ON_CONSTRUCTION From 585c87904ab9b1887ad144e6f6b6e720be2dc1ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabriel=20F=C3=A9ron?= Date: Fri, 5 Jan 2024 20:06:41 -0800 Subject: [PATCH 198/255] Fix BUILD.bazel for newer rules_android_ndk (#15298) When using transitions, and `rules_android_ndk` the constraint needs to be changed to `@platforms`. Closes #15298 COPYBARA_INTEGRATE_REVIEW=https://github.com/protocolbuffers/protobuf/pull/15298 from gferon:fix-android-constraint d15c794da30a72bc8ac7900c1bd38d4ca31135b4 PiperOrigin-RevId: 596140608 --- build_defs/BUILD.bazel | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build_defs/BUILD.bazel b/build_defs/BUILD.bazel index ea8fa18e94c67..1c2ed237d9157 100644 --- a/build_defs/BUILD.bazel +++ b/build_defs/BUILD.bazel @@ -38,7 +38,7 @@ config_setting( config_setting( name = "config_android", values = { - "crosstool_top": "//external:android/crosstool", + "crosstool_top": "@platforms//os:android", }, ) From 69cffdca9c064a40bcb47de168f39072bce47c36 Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Sat, 6 Jan 2024 12:02:32 -0800 Subject: [PATCH 199/255] Annotate some Kotlin generated protobuf code. Note that this change removes the use of ${$ and $}$ in the body of a template `clear` method. These brackets are currently unused (there's no Annotate call and the variables are set to the empty string); it also shouldn't be necessary to annotate non-definitions. PiperOrigin-RevId: 596254156 --- src/google/protobuf/compiler/java/message.cc | 29 ++++++++++++------- .../protobuf/compiler/java/message_field.cc | 3 +- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/src/google/protobuf/compiler/java/message.cc b/src/google/protobuf/compiler/java/message.cc index 5f1db0493cacf..08523b0c19a15 100644 --- a/src/google/protobuf/compiler/java/message.cc +++ b/src/google/protobuf/compiler/java/message.cc @@ -1296,16 +1296,25 @@ void ImmutableMessageGenerator::GenerateKotlinMembers( EscapeKotlinKeywords(name_resolver_->GetClassName(descriptor_, true))); WriteMessageDocComment(printer, descriptor_, /* kdoc */ true); - printer->Print("public object $name$Kt {\n", "name", descriptor_->name()); - printer->Indent(); - GenerateKotlinDsl(printer); - for (int i = 0; i < descriptor_->nested_type_count(); i++) { - if (IsMapEntry(descriptor_->nested_type(i))) continue; - ImmutableMessageGenerator(descriptor_->nested_type(i), context_) - .GenerateKotlinMembers(printer); - } - printer->Outdent(); - printer->Print("}\n"); + printer->Emit( + { + io::Printer::Sub{"name_kt", absl::StrCat(descriptor_->name(), "Kt")} + .AnnotatedAs(descriptor_), + {"body", + [&]() { + GenerateKotlinDsl(printer); + for (int i = 0; i < descriptor_->nested_type_count(); i++) { + if (IsMapEntry(descriptor_->nested_type(i))) continue; + ImmutableMessageGenerator(descriptor_->nested_type(i), context_) + .GenerateKotlinMembers(printer); + } + }}, + }, + R"kt( + public object $name_kt$ { + $body$; + } + )kt"); } void ImmutableMessageGenerator::GenerateTopLevelKotlinMembers( diff --git a/src/google/protobuf/compiler/java/message_field.cc b/src/google/protobuf/compiler/java/message_field.cc index d5f89874570a8..2bc8a578c2a8c 100644 --- a/src/google/protobuf/compiler/java/message_field.cc +++ b/src/google/protobuf/compiler/java/message_field.cc @@ -390,8 +390,9 @@ void ImmutableMessageFieldGenerator::GenerateKotlinDslMembers( /* builder */ false, /* kdoc */ true); printer->Print(variables_, "public fun ${$clear$kt_capitalized_name$$}$() {\n" - " $kt_dsl_builder$.${$clear$capitalized_name$$}$()\n" + " $kt_dsl_builder$.clear$capitalized_name$()\n" "}\n"); + printer->Annotate("{", "}", descriptor_, Semantic::kSet); WriteFieldAccessorDocComment(printer, descriptor_, HAZZER, context_->options(), From d228a44a2f7571d2e74e43117c4eaff5e1cb3a85 Mon Sep 17 00:00:00 2001 From: Eric Salo Date: Sun, 7 Jan 2024 08:47:39 -0800 Subject: [PATCH 200/255] upb: fix some more compiler warnings in Ruby about missing return values PiperOrigin-RevId: 596390202 --- ruby/ext/google/protobuf_c/shared_convert.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ruby/ext/google/protobuf_c/shared_convert.c b/ruby/ext/google/protobuf_c/shared_convert.c index 9116f62b15535..469965b7fd065 100644 --- a/ruby/ext/google/protobuf_c/shared_convert.c +++ b/ruby/ext/google/protobuf_c/shared_convert.c @@ -35,6 +35,7 @@ bool shared_Msgval_IsEqual(upb_MessageValue val1, upb_MessageValue val2, return shared_Message_Equal(val1.msg_val, val2.msg_val, msgdef, status); default: upb_Status_SetErrorMessage(status, "Internal error, unexpected type"); + return false; } } @@ -60,5 +61,6 @@ uint64_t shared_Msgval_GetHash(upb_MessageValue val, upb_CType type, return shared_Message_Hash(val.msg_val, msgdef, seed, status); default: upb_Status_SetErrorMessage(status, "Internal error, unexpected type"); + return 0; } } From bdf24b2e0dc30103e405b3adb5ca91f24ffb09c9 Mon Sep 17 00:00:00 2001 From: Eric Salo Date: Sun, 7 Jan 2024 08:50:59 -0800 Subject: [PATCH 201/255] upb: add 'static' to some wire decoder functions PiperOrigin-RevId: 596390524 --- upb/wire/decode.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/upb/wire/decode.c b/upb/wire/decode.c index c8270397abe17..ecb01277e0ae2 100644 --- a/upb/wire/decode.c +++ b/upb/wire/decode.c @@ -505,8 +505,8 @@ static const char* _upb_Decoder_DecodeEnumPacked( return ptr; } -upb_Array* _upb_Decoder_CreateArray(upb_Decoder* d, - const upb_MiniTableField* field) { +static upb_Array* _upb_Decoder_CreateArray(upb_Decoder* d, + const upb_MiniTableField* field) { const upb_FieldType field_type = field->UPB_PRIVATE(descriptortype); const size_t lg2 = UPB_PRIVATE(_upb_FieldType_SizeLg2)(field_type); upb_Array* ret = UPB_PRIVATE(_upb_Array_New)(&d->arena, 4, lg2); @@ -582,10 +582,11 @@ static const char* _upb_Decoder_DecodeToArray(upb_Decoder* d, const char* ptr, } } -upb_Map* _upb_Decoder_CreateMap(upb_Decoder* d, const upb_MiniTable* entry) { - /* Maps descriptor type -> upb map size. */ +static upb_Map* _upb_Decoder_CreateMap(upb_Decoder* d, + const upb_MiniTable* entry) { + // Maps descriptor type -> upb map size static const uint8_t kSizeInMap[] = { - [0] = -1, // invalid descriptor type */ + [0] = -1, // invalid descriptor type [kUpb_FieldType_Double] = 8, [kUpb_FieldType_Float] = 4, [kUpb_FieldType_Int64] = 8, @@ -978,7 +979,7 @@ static const upb_MiniTableField* _upb_Decoder_FindField(upb_Decoder* d, return &t->UPB_PRIVATE(fields)[idx]; } -int _upb_Decoder_GetVarintOp(const upb_MiniTableField* field) { +static int _upb_Decoder_GetVarintOp(const upb_MiniTableField* field) { static const int8_t kVarintOps[] = { [kUpb_FakeFieldType_FieldNotFound] = kUpb_DecodeOp_UnknownField, [kUpb_FieldType_Double] = kUpb_DecodeOp_UnknownField, @@ -1033,12 +1034,12 @@ static void _upb_Decoder_CheckUnlinked(upb_Decoder* d, const upb_MiniTable* mt, *op = kUpb_DecodeOp_UnknownField; } -int _upb_Decoder_GetDelimitedOp(upb_Decoder* d, const upb_MiniTable* mt, - const upb_MiniTableField* field) { +static int _upb_Decoder_GetDelimitedOp(upb_Decoder* d, const upb_MiniTable* mt, + const upb_MiniTableField* field) { enum { kRepeatedBase = 19 }; static const int8_t kDelimitedOps[] = { - /* For non-repeated field type. */ + // For non-repeated field type. [kUpb_FakeFieldType_FieldNotFound] = kUpb_DecodeOp_UnknownField, // Field not found. [kUpb_FieldType_Double] = kUpb_DecodeOp_UnknownField, @@ -1060,7 +1061,7 @@ int _upb_Decoder_GetDelimitedOp(upb_Decoder* d, const upb_MiniTable* mt, [kUpb_FieldType_SInt32] = kUpb_DecodeOp_UnknownField, [kUpb_FieldType_SInt64] = kUpb_DecodeOp_UnknownField, [kUpb_FakeFieldType_MessageSetItem] = kUpb_DecodeOp_UnknownField, - // For repeated field type. */ + // For repeated field type. [kRepeatedBase + kUpb_FieldType_Double] = OP_FIXPCK_LG2(3), [kRepeatedBase + kUpb_FieldType_Float] = OP_FIXPCK_LG2(2), [kRepeatedBase + kUpb_FieldType_Int64] = OP_VARPCK_LG2(3), From 1a21cb57b7b118b68b13068ecb6ff9226ad23b41 Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Sun, 7 Jan 2024 17:04:44 +0000 Subject: [PATCH 202/255] Auto-generate files after cl/596390524 --- php/ext/google/protobuf/php-upb.c | 21 +++++++++++---------- ruby/ext/google/protobuf_c/ruby-upb.c | 21 +++++++++++---------- 2 files changed, 22 insertions(+), 20 deletions(-) diff --git a/php/ext/google/protobuf/php-upb.c b/php/ext/google/protobuf/php-upb.c index 2874f54eee156..133d20c55b154 100644 --- a/php/ext/google/protobuf/php-upb.c +++ b/php/ext/google/protobuf/php-upb.c @@ -7657,8 +7657,8 @@ static const char* _upb_Decoder_DecodeEnumPacked( return ptr; } -upb_Array* _upb_Decoder_CreateArray(upb_Decoder* d, - const upb_MiniTableField* field) { +static upb_Array* _upb_Decoder_CreateArray(upb_Decoder* d, + const upb_MiniTableField* field) { const upb_FieldType field_type = field->UPB_PRIVATE(descriptortype); const size_t lg2 = UPB_PRIVATE(_upb_FieldType_SizeLg2)(field_type); upb_Array* ret = UPB_PRIVATE(_upb_Array_New)(&d->arena, 4, lg2); @@ -7734,10 +7734,11 @@ static const char* _upb_Decoder_DecodeToArray(upb_Decoder* d, const char* ptr, } } -upb_Map* _upb_Decoder_CreateMap(upb_Decoder* d, const upb_MiniTable* entry) { - /* Maps descriptor type -> upb map size. */ +static upb_Map* _upb_Decoder_CreateMap(upb_Decoder* d, + const upb_MiniTable* entry) { + // Maps descriptor type -> upb map size static const uint8_t kSizeInMap[] = { - [0] = -1, // invalid descriptor type */ + [0] = -1, // invalid descriptor type [kUpb_FieldType_Double] = 8, [kUpb_FieldType_Float] = 4, [kUpb_FieldType_Int64] = 8, @@ -8130,7 +8131,7 @@ static const upb_MiniTableField* _upb_Decoder_FindField(upb_Decoder* d, return &t->UPB_PRIVATE(fields)[idx]; } -int _upb_Decoder_GetVarintOp(const upb_MiniTableField* field) { +static int _upb_Decoder_GetVarintOp(const upb_MiniTableField* field) { static const int8_t kVarintOps[] = { [kUpb_FakeFieldType_FieldNotFound] = kUpb_DecodeOp_UnknownField, [kUpb_FieldType_Double] = kUpb_DecodeOp_UnknownField, @@ -8185,12 +8186,12 @@ static void _upb_Decoder_CheckUnlinked(upb_Decoder* d, const upb_MiniTable* mt, *op = kUpb_DecodeOp_UnknownField; } -int _upb_Decoder_GetDelimitedOp(upb_Decoder* d, const upb_MiniTable* mt, - const upb_MiniTableField* field) { +static int _upb_Decoder_GetDelimitedOp(upb_Decoder* d, const upb_MiniTable* mt, + const upb_MiniTableField* field) { enum { kRepeatedBase = 19 }; static const int8_t kDelimitedOps[] = { - /* For non-repeated field type. */ + // For non-repeated field type. [kUpb_FakeFieldType_FieldNotFound] = kUpb_DecodeOp_UnknownField, // Field not found. [kUpb_FieldType_Double] = kUpb_DecodeOp_UnknownField, @@ -8212,7 +8213,7 @@ int _upb_Decoder_GetDelimitedOp(upb_Decoder* d, const upb_MiniTable* mt, [kUpb_FieldType_SInt32] = kUpb_DecodeOp_UnknownField, [kUpb_FieldType_SInt64] = kUpb_DecodeOp_UnknownField, [kUpb_FakeFieldType_MessageSetItem] = kUpb_DecodeOp_UnknownField, - // For repeated field type. */ + // For repeated field type. [kRepeatedBase + kUpb_FieldType_Double] = OP_FIXPCK_LG2(3), [kRepeatedBase + kUpb_FieldType_Float] = OP_FIXPCK_LG2(2), [kRepeatedBase + kUpb_FieldType_Int64] = OP_VARPCK_LG2(3), diff --git a/ruby/ext/google/protobuf_c/ruby-upb.c b/ruby/ext/google/protobuf_c/ruby-upb.c index 0648cbf9c4c73..8c0bf0b7d6bfb 100644 --- a/ruby/ext/google/protobuf_c/ruby-upb.c +++ b/ruby/ext/google/protobuf_c/ruby-upb.c @@ -7173,8 +7173,8 @@ static const char* _upb_Decoder_DecodeEnumPacked( return ptr; } -upb_Array* _upb_Decoder_CreateArray(upb_Decoder* d, - const upb_MiniTableField* field) { +static upb_Array* _upb_Decoder_CreateArray(upb_Decoder* d, + const upb_MiniTableField* field) { const upb_FieldType field_type = field->UPB_PRIVATE(descriptortype); const size_t lg2 = UPB_PRIVATE(_upb_FieldType_SizeLg2)(field_type); upb_Array* ret = UPB_PRIVATE(_upb_Array_New)(&d->arena, 4, lg2); @@ -7250,10 +7250,11 @@ static const char* _upb_Decoder_DecodeToArray(upb_Decoder* d, const char* ptr, } } -upb_Map* _upb_Decoder_CreateMap(upb_Decoder* d, const upb_MiniTable* entry) { - /* Maps descriptor type -> upb map size. */ +static upb_Map* _upb_Decoder_CreateMap(upb_Decoder* d, + const upb_MiniTable* entry) { + // Maps descriptor type -> upb map size static const uint8_t kSizeInMap[] = { - [0] = -1, // invalid descriptor type */ + [0] = -1, // invalid descriptor type [kUpb_FieldType_Double] = 8, [kUpb_FieldType_Float] = 4, [kUpb_FieldType_Int64] = 8, @@ -7646,7 +7647,7 @@ static const upb_MiniTableField* _upb_Decoder_FindField(upb_Decoder* d, return &t->UPB_PRIVATE(fields)[idx]; } -int _upb_Decoder_GetVarintOp(const upb_MiniTableField* field) { +static int _upb_Decoder_GetVarintOp(const upb_MiniTableField* field) { static const int8_t kVarintOps[] = { [kUpb_FakeFieldType_FieldNotFound] = kUpb_DecodeOp_UnknownField, [kUpb_FieldType_Double] = kUpb_DecodeOp_UnknownField, @@ -7701,12 +7702,12 @@ static void _upb_Decoder_CheckUnlinked(upb_Decoder* d, const upb_MiniTable* mt, *op = kUpb_DecodeOp_UnknownField; } -int _upb_Decoder_GetDelimitedOp(upb_Decoder* d, const upb_MiniTable* mt, - const upb_MiniTableField* field) { +static int _upb_Decoder_GetDelimitedOp(upb_Decoder* d, const upb_MiniTable* mt, + const upb_MiniTableField* field) { enum { kRepeatedBase = 19 }; static const int8_t kDelimitedOps[] = { - /* For non-repeated field type. */ + // For non-repeated field type. [kUpb_FakeFieldType_FieldNotFound] = kUpb_DecodeOp_UnknownField, // Field not found. [kUpb_FieldType_Double] = kUpb_DecodeOp_UnknownField, @@ -7728,7 +7729,7 @@ int _upb_Decoder_GetDelimitedOp(upb_Decoder* d, const upb_MiniTable* mt, [kUpb_FieldType_SInt32] = kUpb_DecodeOp_UnknownField, [kUpb_FieldType_SInt64] = kUpb_DecodeOp_UnknownField, [kUpb_FakeFieldType_MessageSetItem] = kUpb_DecodeOp_UnknownField, - // For repeated field type. */ + // For repeated field type. [kRepeatedBase + kUpb_FieldType_Double] = OP_FIXPCK_LG2(3), [kRepeatedBase + kUpb_FieldType_Float] = OP_FIXPCK_LG2(2), [kRepeatedBase + kUpb_FieldType_Int64] = OP_VARPCK_LG2(3), From 991a2f4d54c6944396f55eaf13ae5248598ed28a Mon Sep 17 00:00:00 2001 From: Jakob Buchgraber Date: Mon, 8 Jan 2024 05:25:58 -0800 Subject: [PATCH 203/255] #refactor Simplify maps through the new ProxiedInMapValue trait This change is a pure refactoring and simplification of the code. We replace all MapsWithKeyOps traits through a single generic ProxiedInMapValue trait. Through connecting the runtime maps implementation with Proxied the code gets a lot simpler e.g. we can use View instead of hardcoding the concrete type behind it. I also expect this change to be beneficial for the gencode. In a subsequent CL we'll implement message values for maps. After this change we'll only have to implement a single trait, while before we had to implement num(key types) many traits. PiperOrigin-RevId: 596562909 --- rust/cpp.rs | 115 ++++++-------- rust/map.rs | 212 +++++++++++-------------- rust/test/shared/accessors_map_test.rs | 4 +- rust/upb.rs | 111 ++++++------- 4 files changed, 194 insertions(+), 248 deletions(-) diff --git a/rust/cpp.rs b/rust/cpp.rs index fab875316e4c1..ba6d66675e012 100644 --- a/rust/cpp.rs +++ b/rust/cpp.rs @@ -341,67 +341,49 @@ impl<'msg, K: ?Sized, V: ?Sized> Clone for MapInner<'msg, K, V> { } } -macro_rules! generate_map_with_key_ops_traits { - ($($t:ty, $sized_t:ty;)*) => { - paste! { - $( - pub trait [< MapWith $t:camel KeyOps >] : Proxied { - fn new_map() -> RawMap; - fn clear(m: RawMap); - fn size(m: RawMap) -> usize; - fn insert(m: RawMap, key: $sized_t, value: View<'_, Self>) -> bool; - fn get<'msg>(m: RawMap, key: $sized_t) -> Option>; - fn remove(m: RawMap, key: $sized_t) -> bool; - } +pub trait ProxiedInMapValue: Proxied +where + K: Proxied + ?Sized, +{ + fn new_map() -> RawMap; + fn clear(m: RawMap); + fn size(m: RawMap) -> usize; + fn insert(m: RawMap, key: View<'_, K>, value: View<'_, Self>) -> bool; + fn get<'msg>(m: RawMap, key: View<'_, K>) -> Option>; + fn remove(m: RawMap, key: View<'_, K>) -> bool; +} - impl<'msg, V: [< MapWith $t:camel KeyOps >] + ?Sized> Default for MapInner<'msg, $t, V> { - fn default() -> Self { - MapInner { - raw: V::new_map(), - _phantom_key: PhantomData, - _phantom_value: PhantomData - } - } - } +impl<'msg, K: Proxied + ?Sized, V: ProxiedInMapValue + ?Sized> Default for MapInner<'msg, K, V> { + fn default() -> Self { + MapInner { raw: V::new_map(), _phantom_key: PhantomData, _phantom_value: PhantomData } + } +} - impl<'msg, V: [< MapWith $t:camel KeyOps >] + ?Sized> MapInner<'msg, $t, V> { - pub fn size(&self) -> usize { - V::size(self.raw) - } +impl<'msg, K: Proxied + ?Sized, V: ProxiedInMapValue + ?Sized> MapInner<'msg, K, V> { + pub fn size(&self) -> usize { + V::size(self.raw) + } - pub fn clear(&mut self) { - V::clear(self.raw) - } + pub fn clear(&mut self) { + V::clear(self.raw) + } - pub fn get<'a>(&self, key: $sized_t) -> Option> { - V::get(self.raw, key) - } + pub fn get<'a>(&self, key: View<'_, K>) -> Option> { + V::get(self.raw, key) + } - pub fn remove(&mut self, key: $sized_t) -> bool { - V::remove(self.raw, key) - } + pub fn remove(&mut self, key: View<'_, K>) -> bool { + V::remove(self.raw, key) + } - pub fn insert(&mut self, key: $sized_t, value: View<'_, V>) -> bool { - V::insert(self.raw, key, value); - true - } - } - )* - } + pub fn insert(&mut self, key: View<'_, K>, value: View<'_, V>) -> bool { + V::insert(self.raw, key, value); + true } } -generate_map_with_key_ops_traits!( - i32, i32; - u32, u32; - i64, i64; - u64, u64; - bool, bool; - ProtoStr, &ProtoStr; -); - -macro_rules! impl_scalar_map_with_key_op_for_scalar_values { - ($key_t:ty, $sized_key_t:ty, $ffi_key_t:ty, $to_ffi_key:expr, $trait:ident for $($t:ty, $ffi_t:ty, $to_ffi_value:expr, $from_ffi_value:expr, $zero_val:literal;)*) => { +macro_rules! impl_ProxiedInMapValue_for_non_generated_value_types { + ($key_t:ty, $ffi_key_t:ty, $to_ffi_key:expr, for $($t:ty, $ffi_t:ty, $to_ffi_value:expr, $from_ffi_value:expr, $zero_val:literal;)*) => { paste! { $( extern "C" { fn [< __pb_rust_Map_ $key_t _ $t _new >]() -> RawMap; @@ -411,7 +393,8 @@ macro_rules! impl_scalar_map_with_key_op_for_scalar_values { fn [< __pb_rust_Map_ $key_t _ $t _get >](m: RawMap, key: $ffi_key_t, value: *mut $ffi_t) -> bool; fn [< __pb_rust_Map_ $key_t _ $t _remove >](m: RawMap, key: $ffi_key_t, value: *mut $ffi_t) -> bool; } - impl $trait for $t { + + impl ProxiedInMapValue<$key_t> for $t { fn new_map() -> RawMap { unsafe { [< __pb_rust_Map_ $key_t _ $t _new >]() } } @@ -424,14 +407,14 @@ macro_rules! impl_scalar_map_with_key_op_for_scalar_values { unsafe { [< __pb_rust_Map_ $key_t _ $t _size >](m) } } - fn insert(m: RawMap, key: $sized_key_t, value: View<'_, Self>) -> bool { + fn insert(m: RawMap, key: View<'_, $key_t>, value: View<'_, Self>) -> bool { let ffi_key = $to_ffi_key(key); let ffi_value = $to_ffi_value(value); unsafe { [< __pb_rust_Map_ $key_t _ $t _insert >](m, ffi_key, ffi_value) } true } - fn get<'msg>(m: RawMap, key: $sized_key_t) -> Option> { + fn get<'msg>(m: RawMap, key: View<'_, $key_t>) -> Option> { let ffi_key = $to_ffi_key(key); let mut ffi_value = $to_ffi_value($zero_val); let found = unsafe { [< __pb_rust_Map_ $key_t _ $t _get >](m, ffi_key, &mut ffi_value) }; @@ -441,7 +424,7 @@ macro_rules! impl_scalar_map_with_key_op_for_scalar_values { Some($from_ffi_value(ffi_value)) } - fn remove(m: RawMap, key: $sized_key_t) -> bool { + fn remove(m: RawMap, key: View<'_, $key_t>) -> bool { let ffi_key = $to_ffi_key(key); let mut ffi_value = $to_ffi_value($zero_val); unsafe { [< __pb_rust_Map_ $key_t _ $t _remove >](m, ffi_key, &mut ffi_value) } @@ -459,11 +442,11 @@ fn ptrlen_to_str<'msg>(val: PtrAndLen) -> &'msg ProtoStr { unsafe { ProtoStr::from_utf8_unchecked(val.as_ref()) } } -macro_rules! impl_map_with_key_ops_for_scalar_values { - ($($t:ty, $t_sized:ty, $ffi_t:ty, $to_ffi_key:expr;)*) => { +macro_rules! impl_ProxiedInMapValue_for_key_types { + ($($t:ty, $ffi_t:ty, $to_ffi_key:expr;)*) => { paste! { $( - impl_scalar_map_with_key_op_for_scalar_values!($t, $t_sized, $ffi_t, $to_ffi_key, [< MapWith $t:camel KeyOps >] for + impl_ProxiedInMapValue_for_non_generated_value_types!($t, $ffi_t, $to_ffi_key, for f32, f32, identity, identity, 0f32; f64, f64, identity, identity, 0f64; i32, i32, identity, identity, 0i32; @@ -478,13 +461,13 @@ macro_rules! impl_map_with_key_ops_for_scalar_values { } } -impl_map_with_key_ops_for_scalar_values!( - i32, i32, i32, identity; - u32, u32, u32, identity; - i64, i64, i64, identity; - u64, u64, u64, identity; - bool, bool, bool, identity; - ProtoStr, &ProtoStr, PtrAndLen, str_to_ptrlen; +impl_ProxiedInMapValue_for_key_types!( + i32, i32, identity; + u32, u32, identity; + i64, i64, identity; + u64, u64, identity; + bool, bool, identity; + ProtoStr, PtrAndLen, str_to_ptrlen; ); #[cfg(test)] diff --git a/rust/map.rs b/rust/map.rs index 2819648170c4e..b17ac0bdca71c 100644 --- a/rust/map.rs +++ b/rust/map.rs @@ -6,14 +6,10 @@ // https://developers.google.com/open-source/licenses/bsd use crate::{ - Mut, MutProxy, ProtoStr, Proxied, SettableValue, View, ViewProxy, + Mut, MutProxy, Proxied, SettableValue, View, ViewProxy, __internal::Private, - __runtime::{ - MapInner, MapWithBoolKeyOps, MapWithI32KeyOps, MapWithI64KeyOps, MapWithProtoStrKeyOps, - MapWithU32KeyOps, MapWithU64KeyOps, - }, + __runtime::{MapInner, ProxiedInMapValue}, }; -use paste::paste; use std::marker::PhantomData; #[repr(transparent)] @@ -83,122 +79,80 @@ impl<'msg, K: ?Sized, V: ?Sized> std::ops::Deref for MapMut<'msg, K, V> { // `MapView` (`View<'_, Map>>) and `MapMut` (Mut<'_, Map>). pub struct Map(PhantomData, PhantomData); -macro_rules! impl_proxied_for_map_keys { - ($(key_type $t:ty;)*) => { - paste! { $( - impl] + Proxied + ?Sized> Proxied for Map<$t, V>{ - type View<'msg> = MapView<'msg, $t, V> where V: 'msg; - type Mut<'msg> = MapMut<'msg, $t, V> where V: 'msg; - } - - impl<'msg, V: [< MapWith $t:camel KeyOps >] + Proxied + ?Sized + 'msg> SettableValue> for MapView<'msg, $t, V> { - fn set_on<'b>(self, _private: Private, mut mutator: Mut<'b, Map<$t, V>>) - where - Map<$t, V>: 'b { - mutator.copy_from(self); - } - } - - impl<'msg, V: [< MapWith $t:camel KeyOps >] + Proxied + ?Sized + 'msg> ViewProxy<'msg> for MapView<'msg, $t, V> { - type Proxied = Map<$t, V>; - - fn as_view(&self) -> View<'_, Self::Proxied> { - *self - } - - fn into_view<'shorter>(self) -> View<'shorter, Self::Proxied> - where 'msg: 'shorter, - { - MapView { inner: self.inner } - } - } - - impl<'msg, V: [< MapWith $t:camel KeyOps >] + Proxied + ?Sized + 'msg> ViewProxy<'msg> for MapMut<'msg, $t, V> { - type Proxied = Map<$t, V>; +impl + ?Sized> Proxied for Map { + type View<'msg> = MapView<'msg, K, V> where K: 'msg, V: 'msg; + type Mut<'msg> = MapMut<'msg, K, V> where K: 'msg, V: 'msg; +} - fn as_view(&self) -> View<'_, Self::Proxied> { - **self - } +impl<'msg, K: Proxied + ?Sized, V: ProxiedInMapValue + ?Sized> SettableValue> + for MapView<'msg, K, V> +{ + fn set_on<'b>(self, _private: Private, mut mutator: Mut<'b, Map>) + where + Map: 'b, + { + mutator.copy_from(self); + } +} - fn into_view<'shorter>(self) -> View<'shorter, Self::Proxied> - where 'msg: 'shorter, - { - *self.into_mut::<'shorter>() - } - } +impl<'msg, K: Proxied + ?Sized, V: ProxiedInMapValue + ?Sized> ViewProxy<'msg> + for MapView<'msg, K, V> +{ + type Proxied = Map; - impl<'msg, V: [< MapWith $t:camel KeyOps >] + Proxied + ?Sized + 'msg> MutProxy<'msg> for MapMut<'msg, $t, V> { - fn as_mut(&mut self) -> Mut<'_, Self::Proxied> { - MapMut { inner: self.inner } - } + fn as_view(&self) -> View<'_, Self::Proxied> { + *self + } - fn into_mut<'shorter>(self) -> Mut<'shorter, Self::Proxied> - where 'msg: 'shorter, - { - MapMut { inner: self.inner } - } - } - )* } - } + fn into_view<'shorter>(self) -> View<'shorter, Self::Proxied> + where + 'msg: 'shorter, + { + MapView { inner: self.inner } + } } -impl_proxied_for_map_keys!( - key_type i32; - key_type u32; - key_type i64; - key_type u64; - key_type bool; - key_type ProtoStr; -); - -macro_rules! impl_scalar_map_keys { - ($(key_type $t:ty;)*) => { - paste! { $( - impl<'msg, V: [< MapWith $t:camel KeyOps >] + Proxied + ?Sized + 'msg> MapView<'msg, $t, V> { - pub fn get<'b>(&self, key: $t) -> Option> { - self.inner.get(key) - } - - pub fn len(&self) -> usize { - self.inner.size() - } - - pub fn is_empty(&self) -> bool { - self.len() == 0 - } - } +impl<'msg, K: Proxied + ?Sized, V: ProxiedInMapValue + ?Sized> ViewProxy<'msg> + for MapMut<'msg, K, V> +{ + type Proxied = Map; - impl<'msg, V: [< MapWith $t:camel KeyOps >] + Proxied + ?Sized + 'msg> MapMut<'msg, $t, V> { - pub fn insert(&mut self, key: $t, value: View<'_, V>) -> bool { - self.inner.insert(key, value) - } + fn as_view(&self) -> View<'_, Self::Proxied> { + **self + } - pub fn remove<'b>(&mut self, key: $t) -> bool { - self.inner.remove(key) - } + fn into_view<'shorter>(self) -> View<'shorter, Self::Proxied> + where + 'msg: 'shorter, + { + *self.into_mut::<'shorter>() + } +} - pub fn clear(&mut self) { - self.inner.clear() - } +impl<'msg, K: Proxied + ?Sized, V: ProxiedInMapValue + ?Sized> MutProxy<'msg> + for MapMut<'msg, K, V> +{ + fn as_mut(&mut self) -> Mut<'_, Self::Proxied> { + MapMut { inner: self.inner } + } - pub fn copy_from(&mut self, _src: MapView<'_, $t, V>) { - todo!("implement b/28530933"); - } - } - )* } - }; + fn into_mut<'shorter>(self) -> Mut<'shorter, Self::Proxied> + where + 'msg: 'shorter, + { + MapMut { inner: self.inner } + } } -impl_scalar_map_keys!( - key_type i32; - key_type u32; - key_type i64; - key_type u64; - key_type bool; -); - -impl<'msg, V: MapWithProtoStrKeyOps + Proxied + ?Sized + 'msg> MapView<'msg, ProtoStr, V> { - pub fn get(&self, key: impl Into<&'msg ProtoStr>) -> Option> { +impl<'msg, K, V> MapView<'msg, K, V> +where + K: Proxied + ?Sized + 'msg, + V: ProxiedInMapValue + ?Sized + 'msg, +{ + pub fn get<'a>(&self, key: impl Into>) -> Option> + where + K: 'a, + { self.inner.get(key.into()) } @@ -211,12 +165,27 @@ impl<'msg, V: MapWithProtoStrKeyOps + Proxied + ?Sized + 'msg> MapView<'msg, Pro } } -impl<'msg, V: MapWithProtoStrKeyOps + Proxied + ?Sized + 'msg> MapMut<'msg, ProtoStr, V> { - pub fn insert(&mut self, key: impl Into<&'msg ProtoStr>, value: View<'_, V>) -> bool { - self.inner.insert(key.into(), value) +impl<'msg, K, V> MapMut<'msg, K, V> +where + K: Proxied + ?Sized + 'msg, + V: ProxiedInMapValue + ?Sized + 'msg, +{ + pub fn insert<'a, 'b>( + &mut self, + key: impl Into>, + value: impl Into>, + ) -> bool + where + K: 'a, + V: 'b, + { + self.inner.insert(key.into(), value.into()) } - pub fn remove(&mut self, key: impl Into<&'msg ProtoStr>) -> bool { + pub fn remove<'a>(&mut self, key: impl Into>) -> bool + where + K: 'a, + { self.inner.remove(key.into()) } @@ -224,7 +193,14 @@ impl<'msg, V: MapWithProtoStrKeyOps + Proxied + ?Sized + 'msg> MapMut<'msg, Prot self.inner.clear() } - pub fn copy_from(&mut self, _src: MapView<'_, ProtoStr, V>) { + pub fn get<'a>(&self, key: impl Into>) -> Option> + where + K: 'a, + { + self.as_view().get(key) + } + + pub fn copy_from(&mut self, _src: MapView<'_, K, V>) { todo!("implement b/28530933"); } } @@ -239,6 +215,8 @@ mod tests { fn test_proxied_scalar() { let mut map_mut = MapMut::from_inner(Private, new_map_i32_i64()); map_mut.insert(1, 2); + assert_that!(map_mut.get(1), eq(Some(2))); + let map_view_1 = map_mut.as_view(); assert_that!(map_view_1.len(), eq(1)); assert_that!(map_view_1.get(1), eq(Some(2))); @@ -261,13 +239,13 @@ mod tests { #[test] fn test_proxied_str() { let mut map_mut = MapMut::from_inner(Private, new_map_str_str()); - map_mut.insert("a", "b".into()); + map_mut.insert("a", "b"); let map_view_1 = map_mut.as_view(); assert_that!(map_view_1.len(), eq(1)); assert_that!(map_view_1.get("a").unwrap(), eq("b")); - map_mut.insert("c", "d".into()); + map_mut.insert("c", "d"); let map_view_2 = map_mut.into_view(); assert_that!(map_view_2.len(), eq(2)); diff --git a/rust/test/shared/accessors_map_test.rs b/rust/test/shared/accessors_map_test.rs index ecdd35a20ad27..2de0ed1cfc1ad 100644 --- a/rust/test/shared/accessors_map_test.rs +++ b/rust/test/shared/accessors_map_test.rs @@ -45,8 +45,8 @@ generate_map_primitives_tests!( #[test] fn test_string_maps() { let mut msg = TestMap::new(); - msg.map_string_string_mut().insert("hello", "world".into()); - msg.map_string_string_mut().insert("fizz", "buzz".into()); + msg.map_string_string_mut().insert("hello", "world"); + msg.map_string_string_mut().insert("fizz", "buzz"); assert_that!(msg.map_string_string().len(), eq(2)); assert_that!(msg.map_string_string().get("fizz").unwrap(), eq("buzz")); assert_that!(msg.map_string_string().get("not found"), eq(None)); diff --git a/rust/upb.rs b/rust/upb.rs index 7b5af62dcf42b..50b7b5fab2434 100644 --- a/rust/upb.rs +++ b/rust/upb.rs @@ -578,77 +578,62 @@ impl<'msg, K: ?Sized, V: ?Sized> Clone for MapInner<'msg, K, V> { } } -macro_rules! generate_map_key_ops_traits { - ($($t:ty, $sized_t:ty;)*) => { - paste! { - $( - pub trait [< MapWith $t:camel KeyOps >] : Proxied { - fn new_map(a: RawArena) -> RawMap; - fn clear(m: RawMap) { - unsafe { upb_Map_Clear(m) } - } - fn size(m: RawMap) -> usize { - unsafe { upb_Map_Size(m) } - } - fn insert(m: RawMap, a: RawArena, key: $sized_t, value: View<'_, Self>) -> bool; - fn get<'msg>(m: RawMap, key: $sized_t) -> Option>; - fn remove(m: RawMap, key: $sized_t) -> bool; - } - - impl<'msg, V: [< MapWith $t:camel KeyOps >] + ?Sized> MapInner<'msg, $t, V> { - - pub fn new(arena: &'msg mut Arena) -> Self { - MapInner { - raw: V::new_map(arena.raw()), - arena, - _phantom_key: PhantomData, - _phantom_value: PhantomData - } - } +pub trait ProxiedInMapValue: Proxied +where + K: Proxied + ?Sized, +{ + fn new_map(a: RawArena) -> RawMap; + fn clear(m: RawMap) { + unsafe { upb_Map_Clear(m) } + } + fn size(m: RawMap) -> usize { + unsafe { upb_Map_Size(m) } + } + fn insert(m: RawMap, a: RawArena, key: View<'_, K>, value: View<'_, Self>) -> bool; + fn get<'a>(m: RawMap, key: View<'_, K>) -> Option>; + fn remove(m: RawMap, key: View<'_, K>) -> bool; +} + +impl<'msg, K: Proxied + ?Sized, V: ProxiedInMapValue + ?Sized> MapInner<'msg, K, V> { + pub fn new(arena: &'msg mut Arena) -> Self { + MapInner { + raw: V::new_map(arena.raw()), + arena, + _phantom_key: PhantomData, + _phantom_value: PhantomData, + } + } - pub fn size(&self) -> usize { - V::size(self.raw) - } + pub fn size(&self) -> usize { + V::size(self.raw) + } - pub fn clear(&mut self) { - V::clear(self.raw) - } + pub fn clear(&mut self) { + V::clear(self.raw) + } - pub fn get<'a>(&self, key: $sized_t) -> Option> { - V::get(self.raw, key) - } + pub fn get<'a>(&self, key: View<'_, K>) -> Option> { + V::get(self.raw, key) + } - pub fn remove(&mut self, key: $sized_t) -> bool { - V::remove(self.raw, key) - } + pub fn remove(&mut self, key: View<'_, K>) -> bool { + V::remove(self.raw, key) + } - pub fn insert(&mut self, key: $sized_t, value: View<'_, V>) -> bool { - V::insert(self.raw, self.arena.raw(), key, value) - } - } - )* - } + pub fn insert(&mut self, key: View<'_, K>, value: View<'_, V>) -> bool { + V::insert(self.raw, self.arena.raw(), key, value) } } -generate_map_key_ops_traits!( - i32, i32; - u32, u32; - i64, i64; - u64, u64; - bool, bool; - ProtoStr, &ProtoStr; -); - -macro_rules! impl_scalar_map_key_op_for_scalar_values { - ($key_t:ty, $key_msg_val:expr, $key_upb_tag:expr, $trait:ident for $($t:ty, $msg_val:expr, $from_msg_val:expr, $upb_tag:expr, $zero_val:literal;)*) => { +macro_rules! impl_ProxiedInMapValue_for_non_generated_value_types { + ($key_t:ty, $key_msg_val:expr, $key_upb_tag:expr, for $($t:ty, $msg_val:expr, $from_msg_val:expr, $upb_tag:expr, $zero_val:literal;)*) => { $( - impl $trait for $t { + impl ProxiedInMapValue<$key_t> for $t { fn new_map(a: RawArena) -> RawMap { unsafe { upb_Map_New(a, $key_upb_tag, $upb_tag) } } - fn insert(m: RawMap, a: RawArena, key: $key_t, value: View<'_, Self>) -> bool { + fn insert(m: RawMap, a: RawArena, key: View<'_, $key_t>, value: View<'_, Self>) -> bool { unsafe { upb_Map_Set( m, @@ -659,7 +644,7 @@ macro_rules! impl_scalar_map_key_op_for_scalar_values { } } - fn get<'msg>(m: RawMap, key: $key_t) -> Option> { + fn get<'a>(m: RawMap, key: View<'_, $key_t>) -> Option> { let mut val = $msg_val($zero_val); let found = unsafe { upb_Map_Get(m, $key_msg_val(key), &mut val) @@ -670,7 +655,7 @@ macro_rules! impl_scalar_map_key_op_for_scalar_values { Some($from_msg_val(val)) } - fn remove(m: RawMap, key: $key_t) -> bool { + fn remove(m: RawMap, key: View<'_, $key_t>) -> bool { let mut val = $msg_val($zero_val); unsafe { upb_Map_Delete(m, $key_msg_val(key), &mut val) @@ -701,11 +686,11 @@ fn msg_to_str<'msg>(msg: upb_MessageValue) -> &'msg ProtoStr { unsafe { ProtoStr::from_utf8_unchecked(msg.str_val.as_ref()) } } -macro_rules! impl_map_key_ops_for_scalar_values { +macro_rules! impl_ProxiedInMapValue_for_key_types { ($($t:ty, $t_sized:ty, $key_msg_val:expr, $upb_tag:expr;)*) => { paste! { $( - impl_scalar_map_key_op_for_scalar_values!($t_sized, $key_msg_val, $upb_tag, [< MapWith $t:camel KeyOps >] for + impl_ProxiedInMapValue_for_non_generated_value_types!($t, $key_msg_val, $upb_tag, for f32, scalar_to_msg!(float_val), scalar_from_msg!(float_val), UpbCType::Float, 0f32; f64, scalar_to_msg!(double_val), scalar_from_msg!(double_val), UpbCType::Double, 0f64; i32, scalar_to_msg!(int32_val), scalar_from_msg!(int32_val), UpbCType::Int32, 0i32; @@ -720,7 +705,7 @@ macro_rules! impl_map_key_ops_for_scalar_values { } } -impl_map_key_ops_for_scalar_values!( +impl_ProxiedInMapValue_for_key_types!( i32, i32, scalar_to_msg!(int32_val), UpbCType::Int32; u32, u32, scalar_to_msg!(uint32_val), UpbCType::UInt32; i64, i64, scalar_to_msg!(int64_val), UpbCType::Int64; From c02f943f1a891d7aa08990a618c39feaeed28d5c Mon Sep 17 00:00:00 2001 From: Eric Salo Date: Mon, 8 Jan 2024 07:34:09 -0800 Subject: [PATCH 204/255] upb: distinguish between fields and extensions in the public clear() accessors PiperOrigin-RevId: 596588385 --- protos/protos.h | 4 +- upb/message/accessors.h | 28 +- upb/message/accessors_test.cc | 14 +- upb/message/internal/accessors.h | 31 +- upb/reflection/BUILD | 1 + upb/reflection/field_def.c | 6 +- upb/reflection/field_def.h | 7 + upb/reflection/internal/field_def.h | 2 - upb/reflection/message.c | 11 +- .../stage0/google/protobuf/descriptor.upb.h | 326 +++++++++--------- upb_generator/protoc-gen-upb.cc | 4 +- .../google/protobuf/compiler/plugin.upb.h | 36 +- 12 files changed, 246 insertions(+), 224 deletions(-) diff --git a/protos/protos.h b/protos/protos.h index 0521e33c374ed..db06de80fd7bc 100644 --- a/protos/protos.h +++ b/protos/protos.h @@ -345,8 +345,8 @@ void ClearExtension( Ptr message, const ::protos::internal::ExtensionIdentifier& id) { static_assert(!std::is_const_v, ""); - _upb_Message_ClearExtensionField(internal::GetInternalMsg(message), - id.mini_table_ext()); + upb_Message_ClearExtension(internal::GetInternalMsg(message), + id.mini_table_ext()); } template ext_begin, struct upb_Extension); struct upb_Extension* ext = - (struct upb_Extension*)_upb_Message_Getext(msg, ext_l); + (struct upb_Extension*)_upb_Message_Getext(msg, e); if (ext) { *ext = *base; in->ext_begin += sizeof(struct upb_Extension); } } -UPB_INLINE void _upb_Message_ClearNonExtensionField( - struct upb_Message* msg, const upb_MiniTableField* f) { - if (UPB_PRIVATE(_upb_MiniTableField_HasHasbit)(f)) { - UPB_PRIVATE(_upb_Message_ClearHasbit)(msg, f); - } else if (upb_MiniTableField_IsInOneof(f)) { - if (!UPB_PRIVATE(_upb_Message_ClearOneofCase)(msg, f)) return; - } - void* data = UPB_PRIVATE(_upb_Message_DataPtr)(msg, f); - UPB_PRIVATE(_upb_MiniTableField_DataClear)(f, data); -} - UPB_INLINE void _upb_Message_AssertMapIsUntagged( const struct upb_Message* msg, const upb_MiniTableField* field) { UPB_UNUSED(msg); diff --git a/upb/reflection/BUILD b/upb/reflection/BUILD index ee3f40da0f152..9b5fd88aa9267 100644 --- a/upb/reflection/BUILD +++ b/upb/reflection/BUILD @@ -144,6 +144,7 @@ bootstrap_cc_library( "//upb/hash", "//upb/message:internal", "//upb/mini_descriptor:internal", + "//upb/mini_table:internal", ], ) diff --git a/upb/reflection/field_def.c b/upb/reflection/field_def.c index 8f849a57bce80..7a953e4c9ab93 100644 --- a/upb/reflection/field_def.c +++ b/upb/reflection/field_def.c @@ -237,7 +237,7 @@ const upb_MiniTableField* upb_FieldDef_MiniTable(const upb_FieldDef* f) { } } -const upb_MiniTableExtension* _upb_FieldDef_ExtensionMiniTable( +const upb_MiniTableExtension* upb_FieldDef_MiniTableExtension( const upb_FieldDef* f) { UPB_ASSERT(upb_FieldDef_IsExtension(f)); const upb_FileDef* file = upb_FieldDef_File(f); @@ -731,7 +731,7 @@ static void _upb_FieldDef_CreateExt(upb_DefBuilder* ctx, const char* prefix, if (ctx->layout) { UPB_ASSERT(upb_MiniTableExtension_Number( - _upb_FieldDef_ExtensionMiniTable(f)) == f->number_); + upb_FieldDef_MiniTableExtension(f)) == f->number_); } } @@ -923,7 +923,7 @@ static void resolve_extension(upb_DefBuilder* ctx, const char* prefix, void _upb_FieldDef_BuildMiniTableExtension(upb_DefBuilder* ctx, const upb_FieldDef* f) { - const upb_MiniTableExtension* ext = _upb_FieldDef_ExtensionMiniTable(f); + const upb_MiniTableExtension* ext = upb_FieldDef_MiniTableExtension(f); if (ctx->layout) { UPB_ASSERT(upb_FieldDef_Number(f) == upb_MiniTableExtension_Number(ext)); diff --git a/upb/reflection/field_def.h b/upb/reflection/field_def.h index 35c3e702ede51..fabc292108b85 100644 --- a/upb/reflection/field_def.h +++ b/upb/reflection/field_def.h @@ -10,7 +10,12 @@ #ifndef UPB_REFLECTION_FIELD_DEF_H_ #define UPB_REFLECTION_FIELD_DEF_H_ +#include + +#include "upb/base/descriptor_constants.h" #include "upb/base/string_view.h" +#include "upb/mini_table/extension.h" +#include "upb/mini_table/field.h" #include "upb/reflection/common.h" // Must be last. @@ -58,6 +63,8 @@ bool upb_FieldDef_MiniDescriptorEncode(const upb_FieldDef* f, upb_Arena* a, upb_StringView* out); const upb_MiniTableField* upb_FieldDef_MiniTable(const upb_FieldDef* f); +const upb_MiniTableExtension* upb_FieldDef_MiniTableExtension( + const upb_FieldDef* f); UPB_API const char* upb_FieldDef_Name(const upb_FieldDef* f); UPB_API uint32_t upb_FieldDef_Number(const upb_FieldDef* f); const UPB_DESC(FieldOptions) * upb_FieldDef_Options(const upb_FieldDef* f); diff --git a/upb/reflection/internal/field_def.h b/upb/reflection/internal/field_def.h index f41a8226a6377..49fc951be9430 100644 --- a/upb/reflection/internal/field_def.h +++ b/upb/reflection/internal/field_def.h @@ -19,8 +19,6 @@ extern "C" { upb_FieldDef* _upb_FieldDef_At(const upb_FieldDef* f, int i); -const upb_MiniTableExtension* _upb_FieldDef_ExtensionMiniTable( - const upb_FieldDef* f); bool _upb_FieldDef_IsClosedEnum(const upb_FieldDef* f); bool _upb_FieldDef_IsProto3Optional(const upb_FieldDef* f); int _upb_FieldDef_LayoutIndex(const upb_FieldDef* f); diff --git a/upb/reflection/message.c b/upb/reflection/message.c index 471e6db50c447..2cbbd57fc619f 100644 --- a/upb/reflection/message.c +++ b/upb/reflection/message.c @@ -13,12 +13,13 @@ #include "upb/mem/arena.h" #include "upb/message/accessors.h" #include "upb/message/array.h" -#include "upb/message/internal/accessors.h" #include "upb/message/internal/extension.h" #include "upb/message/internal/message.h" #include "upb/message/map.h" #include "upb/message/message.h" +#include "upb/mini_table/extension.h" #include "upb/mini_table/field.h" +#include "upb/mini_table/internal/field.h" #include "upb/reflection/def.h" #include "upb/reflection/def_pool.h" #include "upb/reflection/message_def.h" @@ -98,7 +99,13 @@ bool upb_Message_SetFieldByDef(upb_Message* msg, const upb_FieldDef* f, } void upb_Message_ClearFieldByDef(upb_Message* msg, const upb_FieldDef* f) { - upb_Message_ClearField(msg, upb_FieldDef_MiniTable(f)); + const upb_MiniTableField* m_f = upb_FieldDef_MiniTable(f); + + if (upb_MiniTableField_IsExtension(m_f)) { + upb_Message_ClearExtension(msg, (const upb_MiniTableExtension*)m_f); + } else { + upb_Message_ClearBaseField(msg, m_f); + } } void upb_Message_ClearByDef(upb_Message* msg, const upb_MessageDef* m) { diff --git a/upb/reflection/stage0/google/protobuf/descriptor.upb.h b/upb/reflection/stage0/google/protobuf/descriptor.upb.h index 932a8185f1d03..70f3a52a61479 100644 --- a/upb/reflection/stage0/google/protobuf/descriptor.upb.h +++ b/upb/reflection/stage0/google/protobuf/descriptor.upb.h @@ -271,7 +271,7 @@ UPB_INLINE char* google_protobuf_FileDescriptorSet_serialize_ex(const google_pro } UPB_INLINE void google_protobuf_FileDescriptorSet_clear_file(google_protobuf_FileDescriptorSet* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorSet_msg_init(), 1); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_FileDescriptorProto* const* google_protobuf_FileDescriptorSet_file(const google_protobuf_FileDescriptorSet* msg, size_t* size) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorSet_msg_init(), 1); @@ -371,7 +371,7 @@ UPB_INLINE char* google_protobuf_FileDescriptorProto_serialize_ex(const google_p } UPB_INLINE void google_protobuf_FileDescriptorProto_clear_name(google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 1); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_FileDescriptorProto_name(const google_protobuf_FileDescriptorProto* msg) { upb_StringView default_val = upb_StringView_FromString(""); @@ -387,7 +387,7 @@ UPB_INLINE bool google_protobuf_FileDescriptorProto_has_name(const google_protob } UPB_INLINE void google_protobuf_FileDescriptorProto_clear_package(google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 2); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_FileDescriptorProto_package(const google_protobuf_FileDescriptorProto* msg) { upb_StringView default_val = upb_StringView_FromString(""); @@ -403,7 +403,7 @@ UPB_INLINE bool google_protobuf_FileDescriptorProto_has_package(const google_pro } UPB_INLINE void google_protobuf_FileDescriptorProto_clear_dependency(google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 3); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView const* google_protobuf_FileDescriptorProto_dependency(const google_protobuf_FileDescriptorProto* msg, size_t* size) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 3); @@ -435,7 +435,7 @@ UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_dependency_mutable_up } UPB_INLINE void google_protobuf_FileDescriptorProto_clear_message_type(google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 4); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_DescriptorProto* const* google_protobuf_FileDescriptorProto_message_type(const google_protobuf_FileDescriptorProto* msg, size_t* size) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 4); @@ -467,7 +467,7 @@ UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_message_type_mutable_ } UPB_INLINE void google_protobuf_FileDescriptorProto_clear_enum_type(google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 5); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_EnumDescriptorProto* const* google_protobuf_FileDescriptorProto_enum_type(const google_protobuf_FileDescriptorProto* msg, size_t* size) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 5); @@ -499,7 +499,7 @@ UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_enum_type_mutable_upb } UPB_INLINE void google_protobuf_FileDescriptorProto_clear_service(google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 6); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_ServiceDescriptorProto* const* google_protobuf_FileDescriptorProto_service(const google_protobuf_FileDescriptorProto* msg, size_t* size) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 6); @@ -531,7 +531,7 @@ UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_service_mutable_upb_a } UPB_INLINE void google_protobuf_FileDescriptorProto_clear_extension(google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 7); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_FieldDescriptorProto* const* google_protobuf_FileDescriptorProto_extension(const google_protobuf_FileDescriptorProto* msg, size_t* size) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 7); @@ -563,7 +563,7 @@ UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_extension_mutable_upb } UPB_INLINE void google_protobuf_FileDescriptorProto_clear_options(google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 8); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_FileOptions* google_protobuf_FileDescriptorProto_options(const google_protobuf_FileDescriptorProto* msg) { const google_protobuf_FileOptions* default_val = NULL; @@ -579,7 +579,7 @@ UPB_INLINE bool google_protobuf_FileDescriptorProto_has_options(const google_pro } UPB_INLINE void google_protobuf_FileDescriptorProto_clear_source_code_info(google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 9); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_SourceCodeInfo* google_protobuf_FileDescriptorProto_source_code_info(const google_protobuf_FileDescriptorProto* msg) { const google_protobuf_SourceCodeInfo* default_val = NULL; @@ -595,7 +595,7 @@ UPB_INLINE bool google_protobuf_FileDescriptorProto_has_source_code_info(const g } UPB_INLINE void google_protobuf_FileDescriptorProto_clear_public_dependency(google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 10); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t const* google_protobuf_FileDescriptorProto_public_dependency(const google_protobuf_FileDescriptorProto* msg, size_t* size) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 10); @@ -627,7 +627,7 @@ UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_public_dependency_mut } UPB_INLINE void google_protobuf_FileDescriptorProto_clear_weak_dependency(google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 11); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t const* google_protobuf_FileDescriptorProto_weak_dependency(const google_protobuf_FileDescriptorProto* msg, size_t* size) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 11); @@ -659,7 +659,7 @@ UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_weak_dependency_mutab } UPB_INLINE void google_protobuf_FileDescriptorProto_clear_syntax(google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 12); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_FileDescriptorProto_syntax(const google_protobuf_FileDescriptorProto* msg) { upb_StringView default_val = upb_StringView_FromString(""); @@ -675,7 +675,7 @@ UPB_INLINE bool google_protobuf_FileDescriptorProto_has_syntax(const google_prot } UPB_INLINE void google_protobuf_FileDescriptorProto_clear_edition(google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 14); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_FileDescriptorProto_edition(const google_protobuf_FileDescriptorProto* msg) { int32_t default_val = 0; @@ -973,7 +973,7 @@ UPB_INLINE char* google_protobuf_DescriptorProto_serialize_ex(const google_proto } UPB_INLINE void google_protobuf_DescriptorProto_clear_name(google_protobuf_DescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 1); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_DescriptorProto_name(const google_protobuf_DescriptorProto* msg) { upb_StringView default_val = upb_StringView_FromString(""); @@ -989,7 +989,7 @@ UPB_INLINE bool google_protobuf_DescriptorProto_has_name(const google_protobuf_D } UPB_INLINE void google_protobuf_DescriptorProto_clear_field(google_protobuf_DescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 2); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_FieldDescriptorProto* const* google_protobuf_DescriptorProto_field(const google_protobuf_DescriptorProto* msg, size_t* size) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 2); @@ -1021,7 +1021,7 @@ UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_field_mutable_upb_array(g } UPB_INLINE void google_protobuf_DescriptorProto_clear_nested_type(google_protobuf_DescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 3); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_DescriptorProto* const* google_protobuf_DescriptorProto_nested_type(const google_protobuf_DescriptorProto* msg, size_t* size) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 3); @@ -1053,7 +1053,7 @@ UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_nested_type_mutable_upb_a } UPB_INLINE void google_protobuf_DescriptorProto_clear_enum_type(google_protobuf_DescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 4); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_EnumDescriptorProto* const* google_protobuf_DescriptorProto_enum_type(const google_protobuf_DescriptorProto* msg, size_t* size) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 4); @@ -1085,7 +1085,7 @@ UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_enum_type_mutable_upb_arr } UPB_INLINE void google_protobuf_DescriptorProto_clear_extension_range(google_protobuf_DescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 5); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_DescriptorProto_ExtensionRange* const* google_protobuf_DescriptorProto_extension_range(const google_protobuf_DescriptorProto* msg, size_t* size) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 5); @@ -1117,7 +1117,7 @@ UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_extension_range_mutable_u } UPB_INLINE void google_protobuf_DescriptorProto_clear_extension(google_protobuf_DescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 6); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_FieldDescriptorProto* const* google_protobuf_DescriptorProto_extension(const google_protobuf_DescriptorProto* msg, size_t* size) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 6); @@ -1149,7 +1149,7 @@ UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_extension_mutable_upb_arr } UPB_INLINE void google_protobuf_DescriptorProto_clear_options(google_protobuf_DescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 7); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_MessageOptions* google_protobuf_DescriptorProto_options(const google_protobuf_DescriptorProto* msg) { const google_protobuf_MessageOptions* default_val = NULL; @@ -1165,7 +1165,7 @@ UPB_INLINE bool google_protobuf_DescriptorProto_has_options(const google_protobu } UPB_INLINE void google_protobuf_DescriptorProto_clear_oneof_decl(google_protobuf_DescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 8); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_OneofDescriptorProto* const* google_protobuf_DescriptorProto_oneof_decl(const google_protobuf_DescriptorProto* msg, size_t* size) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 8); @@ -1197,7 +1197,7 @@ UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_oneof_decl_mutable_upb_ar } UPB_INLINE void google_protobuf_DescriptorProto_clear_reserved_range(google_protobuf_DescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 9); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_DescriptorProto_ReservedRange* const* google_protobuf_DescriptorProto_reserved_range(const google_protobuf_DescriptorProto* msg, size_t* size) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 9); @@ -1229,7 +1229,7 @@ UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_reserved_range_mutable_up } UPB_INLINE void google_protobuf_DescriptorProto_clear_reserved_name(google_protobuf_DescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 10); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView const* google_protobuf_DescriptorProto_reserved_name(const google_protobuf_DescriptorProto* msg, size_t* size) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 10); @@ -1553,7 +1553,7 @@ UPB_INLINE char* google_protobuf_DescriptorProto_ExtensionRange_serialize_ex(con } UPB_INLINE void google_protobuf_DescriptorProto_ExtensionRange_clear_start(google_protobuf_DescriptorProto_ExtensionRange* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto__ExtensionRange_msg_init(), 1); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_DescriptorProto_ExtensionRange_start(const google_protobuf_DescriptorProto_ExtensionRange* msg) { int32_t default_val = (int32_t)0; @@ -1569,7 +1569,7 @@ UPB_INLINE bool google_protobuf_DescriptorProto_ExtensionRange_has_start(const g } UPB_INLINE void google_protobuf_DescriptorProto_ExtensionRange_clear_end(google_protobuf_DescriptorProto_ExtensionRange* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto__ExtensionRange_msg_init(), 2); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_DescriptorProto_ExtensionRange_end(const google_protobuf_DescriptorProto_ExtensionRange* msg) { int32_t default_val = (int32_t)0; @@ -1585,7 +1585,7 @@ UPB_INLINE bool google_protobuf_DescriptorProto_ExtensionRange_has_end(const goo } UPB_INLINE void google_protobuf_DescriptorProto_ExtensionRange_clear_options(google_protobuf_DescriptorProto_ExtensionRange* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto__ExtensionRange_msg_init(), 3); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_ExtensionRangeOptions* google_protobuf_DescriptorProto_ExtensionRange_options(const google_protobuf_DescriptorProto_ExtensionRange* msg) { const google_protobuf_ExtensionRangeOptions* default_val = NULL; @@ -1659,7 +1659,7 @@ UPB_INLINE char* google_protobuf_DescriptorProto_ReservedRange_serialize_ex(cons } UPB_INLINE void google_protobuf_DescriptorProto_ReservedRange_clear_start(google_protobuf_DescriptorProto_ReservedRange* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto__ReservedRange_msg_init(), 1); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_DescriptorProto_ReservedRange_start(const google_protobuf_DescriptorProto_ReservedRange* msg) { int32_t default_val = (int32_t)0; @@ -1675,7 +1675,7 @@ UPB_INLINE bool google_protobuf_DescriptorProto_ReservedRange_has_start(const go } UPB_INLINE void google_protobuf_DescriptorProto_ReservedRange_clear_end(google_protobuf_DescriptorProto_ReservedRange* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto__ReservedRange_msg_init(), 2); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_DescriptorProto_ReservedRange_end(const google_protobuf_DescriptorProto_ReservedRange* msg) { int32_t default_val = (int32_t)0; @@ -1737,7 +1737,7 @@ UPB_INLINE char* google_protobuf_ExtensionRangeOptions_serialize_ex(const google } UPB_INLINE void google_protobuf_ExtensionRangeOptions_clear_declaration(google_protobuf_ExtensionRangeOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ExtensionRangeOptions_msg_init(), 2); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_ExtensionRangeOptions_Declaration* const* google_protobuf_ExtensionRangeOptions_declaration(const google_protobuf_ExtensionRangeOptions* msg, size_t* size) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ExtensionRangeOptions_msg_init(), 2); @@ -1769,7 +1769,7 @@ UPB_INLINE upb_Array* _google_protobuf_ExtensionRangeOptions_declaration_mutable } UPB_INLINE void google_protobuf_ExtensionRangeOptions_clear_verification(google_protobuf_ExtensionRangeOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ExtensionRangeOptions_msg_init(), 3); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_ExtensionRangeOptions_verification(const google_protobuf_ExtensionRangeOptions* msg) { int32_t default_val = 1; @@ -1785,7 +1785,7 @@ UPB_INLINE bool google_protobuf_ExtensionRangeOptions_has_verification(const goo } UPB_INLINE void google_protobuf_ExtensionRangeOptions_clear_features(google_protobuf_ExtensionRangeOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ExtensionRangeOptions_msg_init(), 50); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_FeatureSet* google_protobuf_ExtensionRangeOptions_features(const google_protobuf_ExtensionRangeOptions* msg) { const google_protobuf_FeatureSet* default_val = NULL; @@ -1801,7 +1801,7 @@ UPB_INLINE bool google_protobuf_ExtensionRangeOptions_has_features(const google_ } UPB_INLINE void google_protobuf_ExtensionRangeOptions_clear_uninterpreted_option(google_protobuf_ExtensionRangeOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ExtensionRangeOptions_msg_init(), 999); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_ExtensionRangeOptions_uninterpreted_option(const google_protobuf_ExtensionRangeOptions* msg, size_t* size) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ExtensionRangeOptions_msg_init(), 999); @@ -1947,7 +1947,7 @@ UPB_INLINE char* google_protobuf_ExtensionRangeOptions_Declaration_serialize_ex( } UPB_INLINE void google_protobuf_ExtensionRangeOptions_Declaration_clear_number(google_protobuf_ExtensionRangeOptions_Declaration* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ExtensionRangeOptions__Declaration_msg_init(), 1); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_ExtensionRangeOptions_Declaration_number(const google_protobuf_ExtensionRangeOptions_Declaration* msg) { int32_t default_val = (int32_t)0; @@ -1963,7 +1963,7 @@ UPB_INLINE bool google_protobuf_ExtensionRangeOptions_Declaration_has_number(con } UPB_INLINE void google_protobuf_ExtensionRangeOptions_Declaration_clear_full_name(google_protobuf_ExtensionRangeOptions_Declaration* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ExtensionRangeOptions__Declaration_msg_init(), 2); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_ExtensionRangeOptions_Declaration_full_name(const google_protobuf_ExtensionRangeOptions_Declaration* msg) { upb_StringView default_val = upb_StringView_FromString(""); @@ -1979,7 +1979,7 @@ UPB_INLINE bool google_protobuf_ExtensionRangeOptions_Declaration_has_full_name( } UPB_INLINE void google_protobuf_ExtensionRangeOptions_Declaration_clear_type(google_protobuf_ExtensionRangeOptions_Declaration* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ExtensionRangeOptions__Declaration_msg_init(), 3); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_ExtensionRangeOptions_Declaration_type(const google_protobuf_ExtensionRangeOptions_Declaration* msg) { upb_StringView default_val = upb_StringView_FromString(""); @@ -1995,7 +1995,7 @@ UPB_INLINE bool google_protobuf_ExtensionRangeOptions_Declaration_has_type(const } UPB_INLINE void google_protobuf_ExtensionRangeOptions_Declaration_clear_reserved(google_protobuf_ExtensionRangeOptions_Declaration* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ExtensionRangeOptions__Declaration_msg_init(), 5); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_ExtensionRangeOptions_Declaration_reserved(const google_protobuf_ExtensionRangeOptions_Declaration* msg) { bool default_val = false; @@ -2011,7 +2011,7 @@ UPB_INLINE bool google_protobuf_ExtensionRangeOptions_Declaration_has_reserved(c } UPB_INLINE void google_protobuf_ExtensionRangeOptions_Declaration_clear_repeated(google_protobuf_ExtensionRangeOptions_Declaration* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ExtensionRangeOptions__Declaration_msg_init(), 6); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_ExtensionRangeOptions_Declaration_repeated(const google_protobuf_ExtensionRangeOptions_Declaration* msg) { bool default_val = false; @@ -2085,7 +2085,7 @@ UPB_INLINE char* google_protobuf_FieldDescriptorProto_serialize_ex(const google_ } UPB_INLINE void google_protobuf_FieldDescriptorProto_clear_name(google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldDescriptorProto_msg_init(), 1); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_FieldDescriptorProto_name(const google_protobuf_FieldDescriptorProto* msg) { upb_StringView default_val = upb_StringView_FromString(""); @@ -2101,7 +2101,7 @@ UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_name(const google_proto } UPB_INLINE void google_protobuf_FieldDescriptorProto_clear_extendee(google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldDescriptorProto_msg_init(), 2); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_FieldDescriptorProto_extendee(const google_protobuf_FieldDescriptorProto* msg) { upb_StringView default_val = upb_StringView_FromString(""); @@ -2117,7 +2117,7 @@ UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_extendee(const google_p } UPB_INLINE void google_protobuf_FieldDescriptorProto_clear_number(google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldDescriptorProto_msg_init(), 3); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_FieldDescriptorProto_number(const google_protobuf_FieldDescriptorProto* msg) { int32_t default_val = (int32_t)0; @@ -2133,7 +2133,7 @@ UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_number(const google_pro } UPB_INLINE void google_protobuf_FieldDescriptorProto_clear_label(google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldDescriptorProto_msg_init(), 4); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_FieldDescriptorProto_label(const google_protobuf_FieldDescriptorProto* msg) { int32_t default_val = 1; @@ -2149,7 +2149,7 @@ UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_label(const google_prot } UPB_INLINE void google_protobuf_FieldDescriptorProto_clear_type(google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldDescriptorProto_msg_init(), 5); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_FieldDescriptorProto_type(const google_protobuf_FieldDescriptorProto* msg) { int32_t default_val = 1; @@ -2165,7 +2165,7 @@ UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_type(const google_proto } UPB_INLINE void google_protobuf_FieldDescriptorProto_clear_type_name(google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldDescriptorProto_msg_init(), 6); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_FieldDescriptorProto_type_name(const google_protobuf_FieldDescriptorProto* msg) { upb_StringView default_val = upb_StringView_FromString(""); @@ -2181,7 +2181,7 @@ UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_type_name(const google_ } UPB_INLINE void google_protobuf_FieldDescriptorProto_clear_default_value(google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldDescriptorProto_msg_init(), 7); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_FieldDescriptorProto_default_value(const google_protobuf_FieldDescriptorProto* msg) { upb_StringView default_val = upb_StringView_FromString(""); @@ -2197,7 +2197,7 @@ UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_default_value(const goo } UPB_INLINE void google_protobuf_FieldDescriptorProto_clear_options(google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldDescriptorProto_msg_init(), 8); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_FieldOptions* google_protobuf_FieldDescriptorProto_options(const google_protobuf_FieldDescriptorProto* msg) { const google_protobuf_FieldOptions* default_val = NULL; @@ -2213,7 +2213,7 @@ UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_options(const google_pr } UPB_INLINE void google_protobuf_FieldDescriptorProto_clear_oneof_index(google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldDescriptorProto_msg_init(), 9); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_FieldDescriptorProto_oneof_index(const google_protobuf_FieldDescriptorProto* msg) { int32_t default_val = (int32_t)0; @@ -2229,7 +2229,7 @@ UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_oneof_index(const googl } UPB_INLINE void google_protobuf_FieldDescriptorProto_clear_json_name(google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldDescriptorProto_msg_init(), 10); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_FieldDescriptorProto_json_name(const google_protobuf_FieldDescriptorProto* msg) { upb_StringView default_val = upb_StringView_FromString(""); @@ -2245,7 +2245,7 @@ UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_json_name(const google_ } UPB_INLINE void google_protobuf_FieldDescriptorProto_clear_proto3_optional(google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldDescriptorProto_msg_init(), 17); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_FieldDescriptorProto_proto3_optional(const google_protobuf_FieldDescriptorProto* msg) { bool default_val = false; @@ -2351,7 +2351,7 @@ UPB_INLINE char* google_protobuf_OneofDescriptorProto_serialize_ex(const google_ } UPB_INLINE void google_protobuf_OneofDescriptorProto_clear_name(google_protobuf_OneofDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__OneofDescriptorProto_msg_init(), 1); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_OneofDescriptorProto_name(const google_protobuf_OneofDescriptorProto* msg) { upb_StringView default_val = upb_StringView_FromString(""); @@ -2367,7 +2367,7 @@ UPB_INLINE bool google_protobuf_OneofDescriptorProto_has_name(const google_proto } UPB_INLINE void google_protobuf_OneofDescriptorProto_clear_options(google_protobuf_OneofDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__OneofDescriptorProto_msg_init(), 2); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_OneofOptions* google_protobuf_OneofDescriptorProto_options(const google_protobuf_OneofDescriptorProto* msg) { const google_protobuf_OneofOptions* default_val = NULL; @@ -2437,7 +2437,7 @@ UPB_INLINE char* google_protobuf_EnumDescriptorProto_serialize_ex(const google_p } UPB_INLINE void google_protobuf_EnumDescriptorProto_clear_name(google_protobuf_EnumDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumDescriptorProto_msg_init(), 1); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_EnumDescriptorProto_name(const google_protobuf_EnumDescriptorProto* msg) { upb_StringView default_val = upb_StringView_FromString(""); @@ -2453,7 +2453,7 @@ UPB_INLINE bool google_protobuf_EnumDescriptorProto_has_name(const google_protob } UPB_INLINE void google_protobuf_EnumDescriptorProto_clear_value(google_protobuf_EnumDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumDescriptorProto_msg_init(), 2); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_EnumValueDescriptorProto* const* google_protobuf_EnumDescriptorProto_value(const google_protobuf_EnumDescriptorProto* msg, size_t* size) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumDescriptorProto_msg_init(), 2); @@ -2485,7 +2485,7 @@ UPB_INLINE upb_Array* _google_protobuf_EnumDescriptorProto_value_mutable_upb_arr } UPB_INLINE void google_protobuf_EnumDescriptorProto_clear_options(google_protobuf_EnumDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumDescriptorProto_msg_init(), 3); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_EnumOptions* google_protobuf_EnumDescriptorProto_options(const google_protobuf_EnumDescriptorProto* msg) { const google_protobuf_EnumOptions* default_val = NULL; @@ -2501,7 +2501,7 @@ UPB_INLINE bool google_protobuf_EnumDescriptorProto_has_options(const google_pro } UPB_INLINE void google_protobuf_EnumDescriptorProto_clear_reserved_range(google_protobuf_EnumDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumDescriptorProto_msg_init(), 4); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_EnumDescriptorProto_EnumReservedRange* const* google_protobuf_EnumDescriptorProto_reserved_range(const google_protobuf_EnumDescriptorProto* msg, size_t* size) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumDescriptorProto_msg_init(), 4); @@ -2533,7 +2533,7 @@ UPB_INLINE upb_Array* _google_protobuf_EnumDescriptorProto_reserved_range_mutabl } UPB_INLINE void google_protobuf_EnumDescriptorProto_clear_reserved_name(google_protobuf_EnumDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumDescriptorProto_msg_init(), 5); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView const* google_protobuf_EnumDescriptorProto_reserved_name(const google_protobuf_EnumDescriptorProto* msg, size_t* size) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumDescriptorProto_msg_init(), 5); @@ -2707,7 +2707,7 @@ UPB_INLINE char* google_protobuf_EnumDescriptorProto_EnumReservedRange_serialize } UPB_INLINE void google_protobuf_EnumDescriptorProto_EnumReservedRange_clear_start(google_protobuf_EnumDescriptorProto_EnumReservedRange* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumDescriptorProto__EnumReservedRange_msg_init(), 1); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_EnumDescriptorProto_EnumReservedRange_start(const google_protobuf_EnumDescriptorProto_EnumReservedRange* msg) { int32_t default_val = (int32_t)0; @@ -2723,7 +2723,7 @@ UPB_INLINE bool google_protobuf_EnumDescriptorProto_EnumReservedRange_has_start( } UPB_INLINE void google_protobuf_EnumDescriptorProto_EnumReservedRange_clear_end(google_protobuf_EnumDescriptorProto_EnumReservedRange* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumDescriptorProto__EnumReservedRange_msg_init(), 2); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_EnumDescriptorProto_EnumReservedRange_end(const google_protobuf_EnumDescriptorProto_EnumReservedRange* msg) { int32_t default_val = (int32_t)0; @@ -2785,7 +2785,7 @@ UPB_INLINE char* google_protobuf_EnumValueDescriptorProto_serialize_ex(const goo } UPB_INLINE void google_protobuf_EnumValueDescriptorProto_clear_name(google_protobuf_EnumValueDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumValueDescriptorProto_msg_init(), 1); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_EnumValueDescriptorProto_name(const google_protobuf_EnumValueDescriptorProto* msg) { upb_StringView default_val = upb_StringView_FromString(""); @@ -2801,7 +2801,7 @@ UPB_INLINE bool google_protobuf_EnumValueDescriptorProto_has_name(const google_p } UPB_INLINE void google_protobuf_EnumValueDescriptorProto_clear_number(google_protobuf_EnumValueDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumValueDescriptorProto_msg_init(), 2); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_EnumValueDescriptorProto_number(const google_protobuf_EnumValueDescriptorProto* msg) { int32_t default_val = (int32_t)0; @@ -2817,7 +2817,7 @@ UPB_INLINE bool google_protobuf_EnumValueDescriptorProto_has_number(const google } UPB_INLINE void google_protobuf_EnumValueDescriptorProto_clear_options(google_protobuf_EnumValueDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumValueDescriptorProto_msg_init(), 3); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_EnumValueOptions* google_protobuf_EnumValueDescriptorProto_options(const google_protobuf_EnumValueDescriptorProto* msg) { const google_protobuf_EnumValueOptions* default_val = NULL; @@ -2891,7 +2891,7 @@ UPB_INLINE char* google_protobuf_ServiceDescriptorProto_serialize_ex(const googl } UPB_INLINE void google_protobuf_ServiceDescriptorProto_clear_name(google_protobuf_ServiceDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ServiceDescriptorProto_msg_init(), 1); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_ServiceDescriptorProto_name(const google_protobuf_ServiceDescriptorProto* msg) { upb_StringView default_val = upb_StringView_FromString(""); @@ -2907,7 +2907,7 @@ UPB_INLINE bool google_protobuf_ServiceDescriptorProto_has_name(const google_pro } UPB_INLINE void google_protobuf_ServiceDescriptorProto_clear_method(google_protobuf_ServiceDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ServiceDescriptorProto_msg_init(), 2); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_MethodDescriptorProto* const* google_protobuf_ServiceDescriptorProto_method(const google_protobuf_ServiceDescriptorProto* msg, size_t* size) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ServiceDescriptorProto_msg_init(), 2); @@ -2939,7 +2939,7 @@ UPB_INLINE upb_Array* _google_protobuf_ServiceDescriptorProto_method_mutable_upb } UPB_INLINE void google_protobuf_ServiceDescriptorProto_clear_options(google_protobuf_ServiceDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ServiceDescriptorProto_msg_init(), 3); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_ServiceOptions* google_protobuf_ServiceDescriptorProto_options(const google_protobuf_ServiceDescriptorProto* msg) { const google_protobuf_ServiceOptions* default_val = NULL; @@ -3039,7 +3039,7 @@ UPB_INLINE char* google_protobuf_MethodDescriptorProto_serialize_ex(const google } UPB_INLINE void google_protobuf_MethodDescriptorProto_clear_name(google_protobuf_MethodDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MethodDescriptorProto_msg_init(), 1); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_MethodDescriptorProto_name(const google_protobuf_MethodDescriptorProto* msg) { upb_StringView default_val = upb_StringView_FromString(""); @@ -3055,7 +3055,7 @@ UPB_INLINE bool google_protobuf_MethodDescriptorProto_has_name(const google_prot } UPB_INLINE void google_protobuf_MethodDescriptorProto_clear_input_type(google_protobuf_MethodDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MethodDescriptorProto_msg_init(), 2); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_MethodDescriptorProto_input_type(const google_protobuf_MethodDescriptorProto* msg) { upb_StringView default_val = upb_StringView_FromString(""); @@ -3071,7 +3071,7 @@ UPB_INLINE bool google_protobuf_MethodDescriptorProto_has_input_type(const googl } UPB_INLINE void google_protobuf_MethodDescriptorProto_clear_output_type(google_protobuf_MethodDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MethodDescriptorProto_msg_init(), 3); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_MethodDescriptorProto_output_type(const google_protobuf_MethodDescriptorProto* msg) { upb_StringView default_val = upb_StringView_FromString(""); @@ -3087,7 +3087,7 @@ UPB_INLINE bool google_protobuf_MethodDescriptorProto_has_output_type(const goog } UPB_INLINE void google_protobuf_MethodDescriptorProto_clear_options(google_protobuf_MethodDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MethodDescriptorProto_msg_init(), 4); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_MethodOptions* google_protobuf_MethodDescriptorProto_options(const google_protobuf_MethodDescriptorProto* msg) { const google_protobuf_MethodOptions* default_val = NULL; @@ -3103,7 +3103,7 @@ UPB_INLINE bool google_protobuf_MethodDescriptorProto_has_options(const google_p } UPB_INLINE void google_protobuf_MethodDescriptorProto_clear_client_streaming(google_protobuf_MethodDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MethodDescriptorProto_msg_init(), 5); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_MethodDescriptorProto_client_streaming(const google_protobuf_MethodDescriptorProto* msg) { bool default_val = false; @@ -3119,7 +3119,7 @@ UPB_INLINE bool google_protobuf_MethodDescriptorProto_has_client_streaming(const } UPB_INLINE void google_protobuf_MethodDescriptorProto_clear_server_streaming(google_protobuf_MethodDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MethodDescriptorProto_msg_init(), 6); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_MethodDescriptorProto_server_streaming(const google_protobuf_MethodDescriptorProto* msg) { bool default_val = false; @@ -3205,7 +3205,7 @@ UPB_INLINE char* google_protobuf_FileOptions_serialize_ex(const google_protobuf_ } UPB_INLINE void google_protobuf_FileOptions_clear_java_package(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 1); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_FileOptions_java_package(const google_protobuf_FileOptions* msg) { upb_StringView default_val = upb_StringView_FromString(""); @@ -3221,7 +3221,7 @@ UPB_INLINE bool google_protobuf_FileOptions_has_java_package(const google_protob } UPB_INLINE void google_protobuf_FileOptions_clear_java_outer_classname(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 8); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_FileOptions_java_outer_classname(const google_protobuf_FileOptions* msg) { upb_StringView default_val = upb_StringView_FromString(""); @@ -3237,7 +3237,7 @@ UPB_INLINE bool google_protobuf_FileOptions_has_java_outer_classname(const googl } UPB_INLINE void google_protobuf_FileOptions_clear_optimize_for(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 9); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_FileOptions_optimize_for(const google_protobuf_FileOptions* msg) { int32_t default_val = 1; @@ -3253,7 +3253,7 @@ UPB_INLINE bool google_protobuf_FileOptions_has_optimize_for(const google_protob } UPB_INLINE void google_protobuf_FileOptions_clear_java_multiple_files(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 10); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_FileOptions_java_multiple_files(const google_protobuf_FileOptions* msg) { bool default_val = false; @@ -3269,7 +3269,7 @@ UPB_INLINE bool google_protobuf_FileOptions_has_java_multiple_files(const google } UPB_INLINE void google_protobuf_FileOptions_clear_go_package(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 11); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_FileOptions_go_package(const google_protobuf_FileOptions* msg) { upb_StringView default_val = upb_StringView_FromString(""); @@ -3285,7 +3285,7 @@ UPB_INLINE bool google_protobuf_FileOptions_has_go_package(const google_protobuf } UPB_INLINE void google_protobuf_FileOptions_clear_cc_generic_services(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 16); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_FileOptions_cc_generic_services(const google_protobuf_FileOptions* msg) { bool default_val = false; @@ -3301,7 +3301,7 @@ UPB_INLINE bool google_protobuf_FileOptions_has_cc_generic_services(const google } UPB_INLINE void google_protobuf_FileOptions_clear_java_generic_services(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 17); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_FileOptions_java_generic_services(const google_protobuf_FileOptions* msg) { bool default_val = false; @@ -3317,7 +3317,7 @@ UPB_INLINE bool google_protobuf_FileOptions_has_java_generic_services(const goog } UPB_INLINE void google_protobuf_FileOptions_clear_py_generic_services(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 18); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_FileOptions_py_generic_services(const google_protobuf_FileOptions* msg) { bool default_val = false; @@ -3333,7 +3333,7 @@ UPB_INLINE bool google_protobuf_FileOptions_has_py_generic_services(const google } UPB_INLINE void google_protobuf_FileOptions_clear_java_generate_equals_and_hash(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 20); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_FileOptions_java_generate_equals_and_hash(const google_protobuf_FileOptions* msg) { bool default_val = false; @@ -3349,7 +3349,7 @@ UPB_INLINE bool google_protobuf_FileOptions_has_java_generate_equals_and_hash(co } UPB_INLINE void google_protobuf_FileOptions_clear_deprecated(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 23); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_FileOptions_deprecated(const google_protobuf_FileOptions* msg) { bool default_val = false; @@ -3365,7 +3365,7 @@ UPB_INLINE bool google_protobuf_FileOptions_has_deprecated(const google_protobuf } UPB_INLINE void google_protobuf_FileOptions_clear_java_string_check_utf8(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 27); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_FileOptions_java_string_check_utf8(const google_protobuf_FileOptions* msg) { bool default_val = false; @@ -3381,7 +3381,7 @@ UPB_INLINE bool google_protobuf_FileOptions_has_java_string_check_utf8(const goo } UPB_INLINE void google_protobuf_FileOptions_clear_cc_enable_arenas(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 31); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_FileOptions_cc_enable_arenas(const google_protobuf_FileOptions* msg) { bool default_val = true; @@ -3397,7 +3397,7 @@ UPB_INLINE bool google_protobuf_FileOptions_has_cc_enable_arenas(const google_pr } UPB_INLINE void google_protobuf_FileOptions_clear_objc_class_prefix(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 36); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_FileOptions_objc_class_prefix(const google_protobuf_FileOptions* msg) { upb_StringView default_val = upb_StringView_FromString(""); @@ -3413,7 +3413,7 @@ UPB_INLINE bool google_protobuf_FileOptions_has_objc_class_prefix(const google_p } UPB_INLINE void google_protobuf_FileOptions_clear_csharp_namespace(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 37); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_FileOptions_csharp_namespace(const google_protobuf_FileOptions* msg) { upb_StringView default_val = upb_StringView_FromString(""); @@ -3429,7 +3429,7 @@ UPB_INLINE bool google_protobuf_FileOptions_has_csharp_namespace(const google_pr } UPB_INLINE void google_protobuf_FileOptions_clear_swift_prefix(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 39); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_FileOptions_swift_prefix(const google_protobuf_FileOptions* msg) { upb_StringView default_val = upb_StringView_FromString(""); @@ -3445,7 +3445,7 @@ UPB_INLINE bool google_protobuf_FileOptions_has_swift_prefix(const google_protob } UPB_INLINE void google_protobuf_FileOptions_clear_php_class_prefix(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 40); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_FileOptions_php_class_prefix(const google_protobuf_FileOptions* msg) { upb_StringView default_val = upb_StringView_FromString(""); @@ -3461,7 +3461,7 @@ UPB_INLINE bool google_protobuf_FileOptions_has_php_class_prefix(const google_pr } UPB_INLINE void google_protobuf_FileOptions_clear_php_namespace(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 41); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_FileOptions_php_namespace(const google_protobuf_FileOptions* msg) { upb_StringView default_val = upb_StringView_FromString(""); @@ -3477,7 +3477,7 @@ UPB_INLINE bool google_protobuf_FileOptions_has_php_namespace(const google_proto } UPB_INLINE void google_protobuf_FileOptions_clear_php_metadata_namespace(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 44); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_FileOptions_php_metadata_namespace(const google_protobuf_FileOptions* msg) { upb_StringView default_val = upb_StringView_FromString(""); @@ -3493,7 +3493,7 @@ UPB_INLINE bool google_protobuf_FileOptions_has_php_metadata_namespace(const goo } UPB_INLINE void google_protobuf_FileOptions_clear_ruby_package(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 45); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_FileOptions_ruby_package(const google_protobuf_FileOptions* msg) { upb_StringView default_val = upb_StringView_FromString(""); @@ -3509,7 +3509,7 @@ UPB_INLINE bool google_protobuf_FileOptions_has_ruby_package(const google_protob } UPB_INLINE void google_protobuf_FileOptions_clear_features(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 50); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_FeatureSet* google_protobuf_FileOptions_features(const google_protobuf_FileOptions* msg) { const google_protobuf_FeatureSet* default_val = NULL; @@ -3525,7 +3525,7 @@ UPB_INLINE bool google_protobuf_FileOptions_has_features(const google_protobuf_F } UPB_INLINE void google_protobuf_FileOptions_clear_uninterpreted_option(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 999); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_FileOptions_uninterpreted_option(const google_protobuf_FileOptions* msg, size_t* size) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 999); @@ -3713,7 +3713,7 @@ UPB_INLINE char* google_protobuf_MessageOptions_serialize_ex(const google_protob } UPB_INLINE void google_protobuf_MessageOptions_clear_message_set_wire_format(google_protobuf_MessageOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MessageOptions_msg_init(), 1); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_MessageOptions_message_set_wire_format(const google_protobuf_MessageOptions* msg) { bool default_val = false; @@ -3729,7 +3729,7 @@ UPB_INLINE bool google_protobuf_MessageOptions_has_message_set_wire_format(const } UPB_INLINE void google_protobuf_MessageOptions_clear_no_standard_descriptor_accessor(google_protobuf_MessageOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MessageOptions_msg_init(), 2); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_MessageOptions_no_standard_descriptor_accessor(const google_protobuf_MessageOptions* msg) { bool default_val = false; @@ -3745,7 +3745,7 @@ UPB_INLINE bool google_protobuf_MessageOptions_has_no_standard_descriptor_access } UPB_INLINE void google_protobuf_MessageOptions_clear_deprecated(google_protobuf_MessageOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MessageOptions_msg_init(), 3); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_MessageOptions_deprecated(const google_protobuf_MessageOptions* msg) { bool default_val = false; @@ -3761,7 +3761,7 @@ UPB_INLINE bool google_protobuf_MessageOptions_has_deprecated(const google_proto } UPB_INLINE void google_protobuf_MessageOptions_clear_map_entry(google_protobuf_MessageOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MessageOptions_msg_init(), 7); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_MessageOptions_map_entry(const google_protobuf_MessageOptions* msg) { bool default_val = false; @@ -3777,7 +3777,7 @@ UPB_INLINE bool google_protobuf_MessageOptions_has_map_entry(const google_protob } UPB_INLINE void google_protobuf_MessageOptions_clear_deprecated_legacy_json_field_conflicts(google_protobuf_MessageOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MessageOptions_msg_init(), 11); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_MessageOptions_deprecated_legacy_json_field_conflicts(const google_protobuf_MessageOptions* msg) { bool default_val = false; @@ -3793,7 +3793,7 @@ UPB_INLINE bool google_protobuf_MessageOptions_has_deprecated_legacy_json_field_ } UPB_INLINE void google_protobuf_MessageOptions_clear_features(google_protobuf_MessageOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MessageOptions_msg_init(), 12); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_FeatureSet* google_protobuf_MessageOptions_features(const google_protobuf_MessageOptions* msg) { const google_protobuf_FeatureSet* default_val = NULL; @@ -3809,7 +3809,7 @@ UPB_INLINE bool google_protobuf_MessageOptions_has_features(const google_protobu } UPB_INLINE void google_protobuf_MessageOptions_clear_uninterpreted_option(google_protobuf_MessageOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MessageOptions_msg_init(), 999); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_MessageOptions_uninterpreted_option(const google_protobuf_MessageOptions* msg, size_t* size) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MessageOptions_msg_init(), 999); @@ -3941,7 +3941,7 @@ UPB_INLINE char* google_protobuf_FieldOptions_serialize_ex(const google_protobuf } UPB_INLINE void google_protobuf_FieldOptions_clear_ctype(google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 1); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_FieldOptions_ctype(const google_protobuf_FieldOptions* msg) { int32_t default_val = 0; @@ -3957,7 +3957,7 @@ UPB_INLINE bool google_protobuf_FieldOptions_has_ctype(const google_protobuf_Fie } UPB_INLINE void google_protobuf_FieldOptions_clear_packed(google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 2); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_FieldOptions_packed(const google_protobuf_FieldOptions* msg) { bool default_val = false; @@ -3973,7 +3973,7 @@ UPB_INLINE bool google_protobuf_FieldOptions_has_packed(const google_protobuf_Fi } UPB_INLINE void google_protobuf_FieldOptions_clear_deprecated(google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 3); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_FieldOptions_deprecated(const google_protobuf_FieldOptions* msg) { bool default_val = false; @@ -3989,7 +3989,7 @@ UPB_INLINE bool google_protobuf_FieldOptions_has_deprecated(const google_protobu } UPB_INLINE void google_protobuf_FieldOptions_clear_lazy(google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 5); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_FieldOptions_lazy(const google_protobuf_FieldOptions* msg) { bool default_val = false; @@ -4005,7 +4005,7 @@ UPB_INLINE bool google_protobuf_FieldOptions_has_lazy(const google_protobuf_Fiel } UPB_INLINE void google_protobuf_FieldOptions_clear_jstype(google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 6); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_FieldOptions_jstype(const google_protobuf_FieldOptions* msg) { int32_t default_val = 0; @@ -4021,7 +4021,7 @@ UPB_INLINE bool google_protobuf_FieldOptions_has_jstype(const google_protobuf_Fi } UPB_INLINE void google_protobuf_FieldOptions_clear_weak(google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 10); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_FieldOptions_weak(const google_protobuf_FieldOptions* msg) { bool default_val = false; @@ -4037,7 +4037,7 @@ UPB_INLINE bool google_protobuf_FieldOptions_has_weak(const google_protobuf_Fiel } UPB_INLINE void google_protobuf_FieldOptions_clear_unverified_lazy(google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 15); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_FieldOptions_unverified_lazy(const google_protobuf_FieldOptions* msg) { bool default_val = false; @@ -4053,7 +4053,7 @@ UPB_INLINE bool google_protobuf_FieldOptions_has_unverified_lazy(const google_pr } UPB_INLINE void google_protobuf_FieldOptions_clear_debug_redact(google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 16); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_FieldOptions_debug_redact(const google_protobuf_FieldOptions* msg) { bool default_val = false; @@ -4069,7 +4069,7 @@ UPB_INLINE bool google_protobuf_FieldOptions_has_debug_redact(const google_proto } UPB_INLINE void google_protobuf_FieldOptions_clear_retention(google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 17); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_FieldOptions_retention(const google_protobuf_FieldOptions* msg) { int32_t default_val = 0; @@ -4085,7 +4085,7 @@ UPB_INLINE bool google_protobuf_FieldOptions_has_retention(const google_protobuf } UPB_INLINE void google_protobuf_FieldOptions_clear_targets(google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 19); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t const* google_protobuf_FieldOptions_targets(const google_protobuf_FieldOptions* msg, size_t* size) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 19); @@ -4117,7 +4117,7 @@ UPB_INLINE upb_Array* _google_protobuf_FieldOptions_targets_mutable_upb_array(go } UPB_INLINE void google_protobuf_FieldOptions_clear_edition_defaults(google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 20); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_FieldOptions_EditionDefault* const* google_protobuf_FieldOptions_edition_defaults(const google_protobuf_FieldOptions* msg, size_t* size) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 20); @@ -4149,7 +4149,7 @@ UPB_INLINE upb_Array* _google_protobuf_FieldOptions_edition_defaults_mutable_upb } UPB_INLINE void google_protobuf_FieldOptions_clear_features(google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 21); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_FeatureSet* google_protobuf_FieldOptions_features(const google_protobuf_FieldOptions* msg) { const google_protobuf_FeatureSet* default_val = NULL; @@ -4165,7 +4165,7 @@ UPB_INLINE bool google_protobuf_FieldOptions_has_features(const google_protobuf_ } UPB_INLINE void google_protobuf_FieldOptions_clear_uninterpreted_option(google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 999); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_FieldOptions_uninterpreted_option(const google_protobuf_FieldOptions* msg, size_t* size) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 999); @@ -4371,7 +4371,7 @@ UPB_INLINE char* google_protobuf_FieldOptions_EditionDefault_serialize_ex(const } UPB_INLINE void google_protobuf_FieldOptions_EditionDefault_clear_value(google_protobuf_FieldOptions_EditionDefault* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions__EditionDefault_msg_init(), 2); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_FieldOptions_EditionDefault_value(const google_protobuf_FieldOptions_EditionDefault* msg) { upb_StringView default_val = upb_StringView_FromString(""); @@ -4387,7 +4387,7 @@ UPB_INLINE bool google_protobuf_FieldOptions_EditionDefault_has_value(const goog } UPB_INLINE void google_protobuf_FieldOptions_EditionDefault_clear_edition(google_protobuf_FieldOptions_EditionDefault* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions__EditionDefault_msg_init(), 3); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_FieldOptions_EditionDefault_edition(const google_protobuf_FieldOptions_EditionDefault* msg) { int32_t default_val = 0; @@ -4449,7 +4449,7 @@ UPB_INLINE char* google_protobuf_OneofOptions_serialize_ex(const google_protobuf } UPB_INLINE void google_protobuf_OneofOptions_clear_features(google_protobuf_OneofOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__OneofOptions_msg_init(), 1); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_FeatureSet* google_protobuf_OneofOptions_features(const google_protobuf_OneofOptions* msg) { const google_protobuf_FeatureSet* default_val = NULL; @@ -4465,7 +4465,7 @@ UPB_INLINE bool google_protobuf_OneofOptions_has_features(const google_protobuf_ } UPB_INLINE void google_protobuf_OneofOptions_clear_uninterpreted_option(google_protobuf_OneofOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__OneofOptions_msg_init(), 999); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_OneofOptions_uninterpreted_option(const google_protobuf_OneofOptions* msg, size_t* size) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__OneofOptions_msg_init(), 999); @@ -4577,7 +4577,7 @@ UPB_INLINE char* google_protobuf_EnumOptions_serialize_ex(const google_protobuf_ } UPB_INLINE void google_protobuf_EnumOptions_clear_allow_alias(google_protobuf_EnumOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumOptions_msg_init(), 2); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_EnumOptions_allow_alias(const google_protobuf_EnumOptions* msg) { bool default_val = false; @@ -4593,7 +4593,7 @@ UPB_INLINE bool google_protobuf_EnumOptions_has_allow_alias(const google_protobu } UPB_INLINE void google_protobuf_EnumOptions_clear_deprecated(google_protobuf_EnumOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumOptions_msg_init(), 3); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_EnumOptions_deprecated(const google_protobuf_EnumOptions* msg) { bool default_val = false; @@ -4609,7 +4609,7 @@ UPB_INLINE bool google_protobuf_EnumOptions_has_deprecated(const google_protobuf } UPB_INLINE void google_protobuf_EnumOptions_clear_deprecated_legacy_json_field_conflicts(google_protobuf_EnumOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumOptions_msg_init(), 6); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_EnumOptions_deprecated_legacy_json_field_conflicts(const google_protobuf_EnumOptions* msg) { bool default_val = false; @@ -4625,7 +4625,7 @@ UPB_INLINE bool google_protobuf_EnumOptions_has_deprecated_legacy_json_field_con } UPB_INLINE void google_protobuf_EnumOptions_clear_features(google_protobuf_EnumOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumOptions_msg_init(), 7); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_FeatureSet* google_protobuf_EnumOptions_features(const google_protobuf_EnumOptions* msg) { const google_protobuf_FeatureSet* default_val = NULL; @@ -4641,7 +4641,7 @@ UPB_INLINE bool google_protobuf_EnumOptions_has_features(const google_protobuf_E } UPB_INLINE void google_protobuf_EnumOptions_clear_uninterpreted_option(google_protobuf_EnumOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumOptions_msg_init(), 999); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_EnumOptions_uninterpreted_option(const google_protobuf_EnumOptions* msg, size_t* size) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumOptions_msg_init(), 999); @@ -4765,7 +4765,7 @@ UPB_INLINE char* google_protobuf_EnumValueOptions_serialize_ex(const google_prot } UPB_INLINE void google_protobuf_EnumValueOptions_clear_deprecated(google_protobuf_EnumValueOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumValueOptions_msg_init(), 1); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_EnumValueOptions_deprecated(const google_protobuf_EnumValueOptions* msg) { bool default_val = false; @@ -4781,7 +4781,7 @@ UPB_INLINE bool google_protobuf_EnumValueOptions_has_deprecated(const google_pro } UPB_INLINE void google_protobuf_EnumValueOptions_clear_features(google_protobuf_EnumValueOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumValueOptions_msg_init(), 2); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_FeatureSet* google_protobuf_EnumValueOptions_features(const google_protobuf_EnumValueOptions* msg) { const google_protobuf_FeatureSet* default_val = NULL; @@ -4797,7 +4797,7 @@ UPB_INLINE bool google_protobuf_EnumValueOptions_has_features(const google_proto } UPB_INLINE void google_protobuf_EnumValueOptions_clear_debug_redact(google_protobuf_EnumValueOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumValueOptions_msg_init(), 3); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_EnumValueOptions_debug_redact(const google_protobuf_EnumValueOptions* msg) { bool default_val = false; @@ -4813,7 +4813,7 @@ UPB_INLINE bool google_protobuf_EnumValueOptions_has_debug_redact(const google_p } UPB_INLINE void google_protobuf_EnumValueOptions_clear_uninterpreted_option(google_protobuf_EnumValueOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumValueOptions_msg_init(), 999); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_EnumValueOptions_uninterpreted_option(const google_protobuf_EnumValueOptions* msg, size_t* size) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumValueOptions_msg_init(), 999); @@ -4933,7 +4933,7 @@ UPB_INLINE char* google_protobuf_ServiceOptions_serialize_ex(const google_protob } UPB_INLINE void google_protobuf_ServiceOptions_clear_deprecated(google_protobuf_ServiceOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ServiceOptions_msg_init(), 33); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_ServiceOptions_deprecated(const google_protobuf_ServiceOptions* msg) { bool default_val = false; @@ -4949,7 +4949,7 @@ UPB_INLINE bool google_protobuf_ServiceOptions_has_deprecated(const google_proto } UPB_INLINE void google_protobuf_ServiceOptions_clear_features(google_protobuf_ServiceOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ServiceOptions_msg_init(), 34); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_FeatureSet* google_protobuf_ServiceOptions_features(const google_protobuf_ServiceOptions* msg) { const google_protobuf_FeatureSet* default_val = NULL; @@ -4965,7 +4965,7 @@ UPB_INLINE bool google_protobuf_ServiceOptions_has_features(const google_protobu } UPB_INLINE void google_protobuf_ServiceOptions_clear_uninterpreted_option(google_protobuf_ServiceOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ServiceOptions_msg_init(), 999); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_ServiceOptions_uninterpreted_option(const google_protobuf_ServiceOptions* msg, size_t* size) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ServiceOptions_msg_init(), 999); @@ -5081,7 +5081,7 @@ UPB_INLINE char* google_protobuf_MethodOptions_serialize_ex(const google_protobu } UPB_INLINE void google_protobuf_MethodOptions_clear_deprecated(google_protobuf_MethodOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MethodOptions_msg_init(), 33); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_MethodOptions_deprecated(const google_protobuf_MethodOptions* msg) { bool default_val = false; @@ -5097,7 +5097,7 @@ UPB_INLINE bool google_protobuf_MethodOptions_has_deprecated(const google_protob } UPB_INLINE void google_protobuf_MethodOptions_clear_idempotency_level(google_protobuf_MethodOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MethodOptions_msg_init(), 34); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_MethodOptions_idempotency_level(const google_protobuf_MethodOptions* msg) { int32_t default_val = 0; @@ -5113,7 +5113,7 @@ UPB_INLINE bool google_protobuf_MethodOptions_has_idempotency_level(const google } UPB_INLINE void google_protobuf_MethodOptions_clear_features(google_protobuf_MethodOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MethodOptions_msg_init(), 35); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_FeatureSet* google_protobuf_MethodOptions_features(const google_protobuf_MethodOptions* msg) { const google_protobuf_FeatureSet* default_val = NULL; @@ -5129,7 +5129,7 @@ UPB_INLINE bool google_protobuf_MethodOptions_has_features(const google_protobuf } UPB_INLINE void google_protobuf_MethodOptions_clear_uninterpreted_option(google_protobuf_MethodOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MethodOptions_msg_init(), 999); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_MethodOptions_uninterpreted_option(const google_protobuf_MethodOptions* msg, size_t* size) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MethodOptions_msg_init(), 999); @@ -5249,7 +5249,7 @@ UPB_INLINE char* google_protobuf_UninterpretedOption_serialize_ex(const google_p } UPB_INLINE void google_protobuf_UninterpretedOption_clear_name(google_protobuf_UninterpretedOption* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__UninterpretedOption_msg_init(), 2); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_UninterpretedOption_NamePart* const* google_protobuf_UninterpretedOption_name(const google_protobuf_UninterpretedOption* msg, size_t* size) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__UninterpretedOption_msg_init(), 2); @@ -5281,7 +5281,7 @@ UPB_INLINE upb_Array* _google_protobuf_UninterpretedOption_name_mutable_upb_arra } UPB_INLINE void google_protobuf_UninterpretedOption_clear_identifier_value(google_protobuf_UninterpretedOption* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__UninterpretedOption_msg_init(), 3); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_UninterpretedOption_identifier_value(const google_protobuf_UninterpretedOption* msg) { upb_StringView default_val = upb_StringView_FromString(""); @@ -5297,7 +5297,7 @@ UPB_INLINE bool google_protobuf_UninterpretedOption_has_identifier_value(const g } UPB_INLINE void google_protobuf_UninterpretedOption_clear_positive_int_value(google_protobuf_UninterpretedOption* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__UninterpretedOption_msg_init(), 4); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE uint64_t google_protobuf_UninterpretedOption_positive_int_value(const google_protobuf_UninterpretedOption* msg) { uint64_t default_val = (uint64_t)0ull; @@ -5313,7 +5313,7 @@ UPB_INLINE bool google_protobuf_UninterpretedOption_has_positive_int_value(const } UPB_INLINE void google_protobuf_UninterpretedOption_clear_negative_int_value(google_protobuf_UninterpretedOption* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__UninterpretedOption_msg_init(), 5); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE int64_t google_protobuf_UninterpretedOption_negative_int_value(const google_protobuf_UninterpretedOption* msg) { int64_t default_val = (int64_t)0ll; @@ -5329,7 +5329,7 @@ UPB_INLINE bool google_protobuf_UninterpretedOption_has_negative_int_value(const } UPB_INLINE void google_protobuf_UninterpretedOption_clear_double_value(google_protobuf_UninterpretedOption* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__UninterpretedOption_msg_init(), 6); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE double google_protobuf_UninterpretedOption_double_value(const google_protobuf_UninterpretedOption* msg) { double default_val = 0; @@ -5345,7 +5345,7 @@ UPB_INLINE bool google_protobuf_UninterpretedOption_has_double_value(const googl } UPB_INLINE void google_protobuf_UninterpretedOption_clear_string_value(google_protobuf_UninterpretedOption* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__UninterpretedOption_msg_init(), 7); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_UninterpretedOption_string_value(const google_protobuf_UninterpretedOption* msg) { upb_StringView default_val = upb_StringView_FromString(""); @@ -5361,7 +5361,7 @@ UPB_INLINE bool google_protobuf_UninterpretedOption_has_string_value(const googl } UPB_INLINE void google_protobuf_UninterpretedOption_clear_aggregate_value(google_protobuf_UninterpretedOption* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__UninterpretedOption_msg_init(), 8); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_UninterpretedOption_aggregate_value(const google_protobuf_UninterpretedOption* msg) { upb_StringView default_val = upb_StringView_FromString(""); @@ -5469,7 +5469,7 @@ UPB_INLINE char* google_protobuf_UninterpretedOption_NamePart_serialize_ex(const } UPB_INLINE void google_protobuf_UninterpretedOption_NamePart_clear_name_part(google_protobuf_UninterpretedOption_NamePart* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__UninterpretedOption__NamePart_msg_init(), 1); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_UninterpretedOption_NamePart_name_part(const google_protobuf_UninterpretedOption_NamePart* msg) { upb_StringView default_val = upb_StringView_FromString(""); @@ -5485,7 +5485,7 @@ UPB_INLINE bool google_protobuf_UninterpretedOption_NamePart_has_name_part(const } UPB_INLINE void google_protobuf_UninterpretedOption_NamePart_clear_is_extension(google_protobuf_UninterpretedOption_NamePart* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__UninterpretedOption__NamePart_msg_init(), 2); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_UninterpretedOption_NamePart_is_extension(const google_protobuf_UninterpretedOption_NamePart* msg) { bool default_val = false; @@ -5547,7 +5547,7 @@ UPB_INLINE char* google_protobuf_FeatureSet_serialize_ex(const google_protobuf_F } UPB_INLINE void google_protobuf_FeatureSet_clear_field_presence(google_protobuf_FeatureSet* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FeatureSet_msg_init(), 1); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_FeatureSet_field_presence(const google_protobuf_FeatureSet* msg) { int32_t default_val = 0; @@ -5563,7 +5563,7 @@ UPB_INLINE bool google_protobuf_FeatureSet_has_field_presence(const google_proto } UPB_INLINE void google_protobuf_FeatureSet_clear_enum_type(google_protobuf_FeatureSet* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FeatureSet_msg_init(), 2); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_FeatureSet_enum_type(const google_protobuf_FeatureSet* msg) { int32_t default_val = 0; @@ -5579,7 +5579,7 @@ UPB_INLINE bool google_protobuf_FeatureSet_has_enum_type(const google_protobuf_F } UPB_INLINE void google_protobuf_FeatureSet_clear_repeated_field_encoding(google_protobuf_FeatureSet* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FeatureSet_msg_init(), 3); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_FeatureSet_repeated_field_encoding(const google_protobuf_FeatureSet* msg) { int32_t default_val = 0; @@ -5595,7 +5595,7 @@ UPB_INLINE bool google_protobuf_FeatureSet_has_repeated_field_encoding(const goo } UPB_INLINE void google_protobuf_FeatureSet_clear_utf8_validation(google_protobuf_FeatureSet* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FeatureSet_msg_init(), 4); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_FeatureSet_utf8_validation(const google_protobuf_FeatureSet* msg) { int32_t default_val = 0; @@ -5611,7 +5611,7 @@ UPB_INLINE bool google_protobuf_FeatureSet_has_utf8_validation(const google_prot } UPB_INLINE void google_protobuf_FeatureSet_clear_message_encoding(google_protobuf_FeatureSet* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FeatureSet_msg_init(), 5); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_FeatureSet_message_encoding(const google_protobuf_FeatureSet* msg) { int32_t default_val = 0; @@ -5627,7 +5627,7 @@ UPB_INLINE bool google_protobuf_FeatureSet_has_message_encoding(const google_pro } UPB_INLINE void google_protobuf_FeatureSet_clear_json_format(google_protobuf_FeatureSet* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FeatureSet_msg_init(), 6); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_FeatureSet_json_format(const google_protobuf_FeatureSet* msg) { int32_t default_val = 0; @@ -5705,7 +5705,7 @@ UPB_INLINE char* google_protobuf_FeatureSetDefaults_serialize_ex(const google_pr } UPB_INLINE void google_protobuf_FeatureSetDefaults_clear_defaults(google_protobuf_FeatureSetDefaults* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FeatureSetDefaults_msg_init(), 1); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* const* google_protobuf_FeatureSetDefaults_defaults(const google_protobuf_FeatureSetDefaults* msg, size_t* size) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FeatureSetDefaults_msg_init(), 1); @@ -5737,7 +5737,7 @@ UPB_INLINE upb_Array* _google_protobuf_FeatureSetDefaults_defaults_mutable_upb_a } UPB_INLINE void google_protobuf_FeatureSetDefaults_clear_minimum_edition(google_protobuf_FeatureSetDefaults* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FeatureSetDefaults_msg_init(), 4); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_FeatureSetDefaults_minimum_edition(const google_protobuf_FeatureSetDefaults* msg) { int32_t default_val = 0; @@ -5753,7 +5753,7 @@ UPB_INLINE bool google_protobuf_FeatureSetDefaults_has_minimum_edition(const goo } UPB_INLINE void google_protobuf_FeatureSetDefaults_clear_maximum_edition(google_protobuf_FeatureSetDefaults* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FeatureSetDefaults_msg_init(), 5); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_FeatureSetDefaults_maximum_edition(const google_protobuf_FeatureSetDefaults* msg) { int32_t default_val = 0; @@ -5845,7 +5845,7 @@ UPB_INLINE char* google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_ser } UPB_INLINE void google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_clear_features(google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FeatureSetDefaults__FeatureSetEditionDefault_msg_init(), 2); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_FeatureSet* google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_features(const google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* msg) { const google_protobuf_FeatureSet* default_val = NULL; @@ -5861,7 +5861,7 @@ UPB_INLINE bool google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_has_ } UPB_INLINE void google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_clear_edition(google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FeatureSetDefaults__FeatureSetEditionDefault_msg_init(), 3); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_edition(const google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* msg) { int32_t default_val = 0; @@ -5931,7 +5931,7 @@ UPB_INLINE char* google_protobuf_SourceCodeInfo_serialize_ex(const google_protob } UPB_INLINE void google_protobuf_SourceCodeInfo_clear_location(google_protobuf_SourceCodeInfo* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__SourceCodeInfo_msg_init(), 1); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_SourceCodeInfo_Location* const* google_protobuf_SourceCodeInfo_location(const google_protobuf_SourceCodeInfo* msg, size_t* size) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__SourceCodeInfo_msg_init(), 1); @@ -6031,7 +6031,7 @@ UPB_INLINE char* google_protobuf_SourceCodeInfo_Location_serialize_ex(const goog } UPB_INLINE void google_protobuf_SourceCodeInfo_Location_clear_path(google_protobuf_SourceCodeInfo_Location* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__SourceCodeInfo__Location_msg_init(), 1); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t const* google_protobuf_SourceCodeInfo_Location_path(const google_protobuf_SourceCodeInfo_Location* msg, size_t* size) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__SourceCodeInfo__Location_msg_init(), 1); @@ -6063,7 +6063,7 @@ UPB_INLINE upb_Array* _google_protobuf_SourceCodeInfo_Location_path_mutable_upb_ } UPB_INLINE void google_protobuf_SourceCodeInfo_Location_clear_span(google_protobuf_SourceCodeInfo_Location* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__SourceCodeInfo__Location_msg_init(), 2); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t const* google_protobuf_SourceCodeInfo_Location_span(const google_protobuf_SourceCodeInfo_Location* msg, size_t* size) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__SourceCodeInfo__Location_msg_init(), 2); @@ -6095,7 +6095,7 @@ UPB_INLINE upb_Array* _google_protobuf_SourceCodeInfo_Location_span_mutable_upb_ } UPB_INLINE void google_protobuf_SourceCodeInfo_Location_clear_leading_comments(google_protobuf_SourceCodeInfo_Location* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__SourceCodeInfo__Location_msg_init(), 3); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_SourceCodeInfo_Location_leading_comments(const google_protobuf_SourceCodeInfo_Location* msg) { upb_StringView default_val = upb_StringView_FromString(""); @@ -6111,7 +6111,7 @@ UPB_INLINE bool google_protobuf_SourceCodeInfo_Location_has_leading_comments(con } UPB_INLINE void google_protobuf_SourceCodeInfo_Location_clear_trailing_comments(google_protobuf_SourceCodeInfo_Location* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__SourceCodeInfo__Location_msg_init(), 4); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_SourceCodeInfo_Location_trailing_comments(const google_protobuf_SourceCodeInfo_Location* msg) { upb_StringView default_val = upb_StringView_FromString(""); @@ -6127,7 +6127,7 @@ UPB_INLINE bool google_protobuf_SourceCodeInfo_Location_has_trailing_comments(co } UPB_INLINE void google_protobuf_SourceCodeInfo_Location_clear_leading_detached_comments(google_protobuf_SourceCodeInfo_Location* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__SourceCodeInfo__Location_msg_init(), 6); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView const* google_protobuf_SourceCodeInfo_Location_leading_detached_comments(const google_protobuf_SourceCodeInfo_Location* msg, size_t* size) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__SourceCodeInfo__Location_msg_init(), 6); @@ -6289,7 +6289,7 @@ UPB_INLINE char* google_protobuf_GeneratedCodeInfo_serialize_ex(const google_pro } UPB_INLINE void google_protobuf_GeneratedCodeInfo_clear_annotation(google_protobuf_GeneratedCodeInfo* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__GeneratedCodeInfo_msg_init(), 1); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_GeneratedCodeInfo_Annotation* const* google_protobuf_GeneratedCodeInfo_annotation(const google_protobuf_GeneratedCodeInfo* msg, size_t* size) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__GeneratedCodeInfo_msg_init(), 1); @@ -6389,7 +6389,7 @@ UPB_INLINE char* google_protobuf_GeneratedCodeInfo_Annotation_serialize_ex(const } UPB_INLINE void google_protobuf_GeneratedCodeInfo_Annotation_clear_path(google_protobuf_GeneratedCodeInfo_Annotation* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__GeneratedCodeInfo__Annotation_msg_init(), 1); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t const* google_protobuf_GeneratedCodeInfo_Annotation_path(const google_protobuf_GeneratedCodeInfo_Annotation* msg, size_t* size) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__GeneratedCodeInfo__Annotation_msg_init(), 1); @@ -6421,7 +6421,7 @@ UPB_INLINE upb_Array* _google_protobuf_GeneratedCodeInfo_Annotation_path_mutable } UPB_INLINE void google_protobuf_GeneratedCodeInfo_Annotation_clear_source_file(google_protobuf_GeneratedCodeInfo_Annotation* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__GeneratedCodeInfo__Annotation_msg_init(), 2); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_GeneratedCodeInfo_Annotation_source_file(const google_protobuf_GeneratedCodeInfo_Annotation* msg) { upb_StringView default_val = upb_StringView_FromString(""); @@ -6437,7 +6437,7 @@ UPB_INLINE bool google_protobuf_GeneratedCodeInfo_Annotation_has_source_file(con } UPB_INLINE void google_protobuf_GeneratedCodeInfo_Annotation_clear_begin(google_protobuf_GeneratedCodeInfo_Annotation* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__GeneratedCodeInfo__Annotation_msg_init(), 3); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_GeneratedCodeInfo_Annotation_begin(const google_protobuf_GeneratedCodeInfo_Annotation* msg) { int32_t default_val = (int32_t)0; @@ -6453,7 +6453,7 @@ UPB_INLINE bool google_protobuf_GeneratedCodeInfo_Annotation_has_begin(const goo } UPB_INLINE void google_protobuf_GeneratedCodeInfo_Annotation_clear_end(google_protobuf_GeneratedCodeInfo_Annotation* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__GeneratedCodeInfo__Annotation_msg_init(), 4); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_GeneratedCodeInfo_Annotation_end(const google_protobuf_GeneratedCodeInfo_Annotation* msg) { int32_t default_val = (int32_t)0; @@ -6469,7 +6469,7 @@ UPB_INLINE bool google_protobuf_GeneratedCodeInfo_Annotation_has_end(const googl } UPB_INLINE void google_protobuf_GeneratedCodeInfo_Annotation_clear_semantic(google_protobuf_GeneratedCodeInfo_Annotation* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__GeneratedCodeInfo__Annotation_msg_init(), 5); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_GeneratedCodeInfo_Annotation_semantic(const google_protobuf_GeneratedCodeInfo_Annotation* msg) { int32_t default_val = 0; diff --git a/upb_generator/protoc-gen-upb.cc b/upb_generator/protoc-gen-upb.cc index b5d3e2c487506..eb71edd7736f0 100644 --- a/upb_generator/protoc-gen-upb.cc +++ b/upb_generator/protoc-gen-upb.cc @@ -269,7 +269,7 @@ void GenerateExtensionInHeader(const DefPoolPair& pools, upb::FieldDefPtr ext, output( R"cc( UPB_INLINE void $0_clear_$1(struct $2* msg) { - _upb_Message_ClearExtensionField((upb_Message*)msg, &$3); + upb_Message_ClearExtension((upb_Message*)msg, &$3); } )cc", ExtensionIdentBase(ext), ext.name(), MessageName(ext.containing_type()), @@ -411,7 +411,7 @@ void GenerateClear(upb::FieldDefPtr field, const DefPoolPair& pools, R"cc( UPB_INLINE void $0_clear_$1($0* msg) { const upb_MiniTableField field = $2; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } )cc", msg_name, resolved_name, FieldInitializer(pools, field, options)); diff --git a/upb_generator/stage0/google/protobuf/compiler/plugin.upb.h b/upb_generator/stage0/google/protobuf/compiler/plugin.upb.h index fedc5299d5ad8..8248bc3f8917f 100644 --- a/upb_generator/stage0/google/protobuf/compiler/plugin.upb.h +++ b/upb_generator/stage0/google/protobuf/compiler/plugin.upb.h @@ -78,7 +78,7 @@ UPB_INLINE char* google_protobuf_compiler_Version_serialize_ex(const google_prot } UPB_INLINE void google_protobuf_compiler_Version_clear_major(google_protobuf_compiler_Version* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__Version_msg_init(), 1); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_compiler_Version_major(const google_protobuf_compiler_Version* msg) { int32_t default_val = (int32_t)0; @@ -94,7 +94,7 @@ UPB_INLINE bool google_protobuf_compiler_Version_has_major(const google_protobuf } UPB_INLINE void google_protobuf_compiler_Version_clear_minor(google_protobuf_compiler_Version* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__Version_msg_init(), 2); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_compiler_Version_minor(const google_protobuf_compiler_Version* msg) { int32_t default_val = (int32_t)0; @@ -110,7 +110,7 @@ UPB_INLINE bool google_protobuf_compiler_Version_has_minor(const google_protobuf } UPB_INLINE void google_protobuf_compiler_Version_clear_patch(google_protobuf_compiler_Version* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__Version_msg_init(), 3); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_compiler_Version_patch(const google_protobuf_compiler_Version* msg) { int32_t default_val = (int32_t)0; @@ -126,7 +126,7 @@ UPB_INLINE bool google_protobuf_compiler_Version_has_patch(const google_protobuf } UPB_INLINE void google_protobuf_compiler_Version_clear_suffix(google_protobuf_compiler_Version* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__Version_msg_init(), 4); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_compiler_Version_suffix(const google_protobuf_compiler_Version* msg) { upb_StringView default_val = upb_StringView_FromString(""); @@ -196,7 +196,7 @@ UPB_INLINE char* google_protobuf_compiler_CodeGeneratorRequest_serialize_ex(cons } UPB_INLINE void google_protobuf_compiler_CodeGeneratorRequest_clear_file_to_generate(google_protobuf_compiler_CodeGeneratorRequest* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorRequest_msg_init(), 1); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView const* google_protobuf_compiler_CodeGeneratorRequest_file_to_generate(const google_protobuf_compiler_CodeGeneratorRequest* msg, size_t* size) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorRequest_msg_init(), 1); @@ -228,7 +228,7 @@ UPB_INLINE upb_Array* _google_protobuf_compiler_CodeGeneratorRequest_file_to_gen } UPB_INLINE void google_protobuf_compiler_CodeGeneratorRequest_clear_parameter(google_protobuf_compiler_CodeGeneratorRequest* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorRequest_msg_init(), 2); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_compiler_CodeGeneratorRequest_parameter(const google_protobuf_compiler_CodeGeneratorRequest* msg) { upb_StringView default_val = upb_StringView_FromString(""); @@ -244,7 +244,7 @@ UPB_INLINE bool google_protobuf_compiler_CodeGeneratorRequest_has_parameter(cons } UPB_INLINE void google_protobuf_compiler_CodeGeneratorRequest_clear_compiler_version(google_protobuf_compiler_CodeGeneratorRequest* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorRequest_msg_init(), 3); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_compiler_Version* google_protobuf_compiler_CodeGeneratorRequest_compiler_version(const google_protobuf_compiler_CodeGeneratorRequest* msg) { const google_protobuf_compiler_Version* default_val = NULL; @@ -260,7 +260,7 @@ UPB_INLINE bool google_protobuf_compiler_CodeGeneratorRequest_has_compiler_versi } UPB_INLINE void google_protobuf_compiler_CodeGeneratorRequest_clear_proto_file(google_protobuf_compiler_CodeGeneratorRequest* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorRequest_msg_init(), 15); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const struct google_protobuf_FileDescriptorProto* const* google_protobuf_compiler_CodeGeneratorRequest_proto_file(const google_protobuf_compiler_CodeGeneratorRequest* msg, size_t* size) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorRequest_msg_init(), 15); @@ -292,7 +292,7 @@ UPB_INLINE upb_Array* _google_protobuf_compiler_CodeGeneratorRequest_proto_file_ } UPB_INLINE void google_protobuf_compiler_CodeGeneratorRequest_clear_source_file_descriptors(google_protobuf_compiler_CodeGeneratorRequest* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorRequest_msg_init(), 17); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const struct google_protobuf_FileDescriptorProto* const* google_protobuf_compiler_CodeGeneratorRequest_source_file_descriptors(const google_protobuf_compiler_CodeGeneratorRequest* msg, size_t* size) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorRequest_msg_init(), 17); @@ -466,7 +466,7 @@ UPB_INLINE char* google_protobuf_compiler_CodeGeneratorResponse_serialize_ex(con } UPB_INLINE void google_protobuf_compiler_CodeGeneratorResponse_clear_error(google_protobuf_compiler_CodeGeneratorResponse* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorResponse_msg_init(), 1); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_compiler_CodeGeneratorResponse_error(const google_protobuf_compiler_CodeGeneratorResponse* msg) { upb_StringView default_val = upb_StringView_FromString(""); @@ -482,7 +482,7 @@ UPB_INLINE bool google_protobuf_compiler_CodeGeneratorResponse_has_error(const g } UPB_INLINE void google_protobuf_compiler_CodeGeneratorResponse_clear_supported_features(google_protobuf_compiler_CodeGeneratorResponse* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorResponse_msg_init(), 2); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE uint64_t google_protobuf_compiler_CodeGeneratorResponse_supported_features(const google_protobuf_compiler_CodeGeneratorResponse* msg) { uint64_t default_val = (uint64_t)0ull; @@ -498,7 +498,7 @@ UPB_INLINE bool google_protobuf_compiler_CodeGeneratorResponse_has_supported_fea } UPB_INLINE void google_protobuf_compiler_CodeGeneratorResponse_clear_minimum_edition(google_protobuf_compiler_CodeGeneratorResponse* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorResponse_msg_init(), 3); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_compiler_CodeGeneratorResponse_minimum_edition(const google_protobuf_compiler_CodeGeneratorResponse* msg) { int32_t default_val = (int32_t)0; @@ -514,7 +514,7 @@ UPB_INLINE bool google_protobuf_compiler_CodeGeneratorResponse_has_minimum_editi } UPB_INLINE void google_protobuf_compiler_CodeGeneratorResponse_clear_maximum_edition(google_protobuf_compiler_CodeGeneratorResponse* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorResponse_msg_init(), 4); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_compiler_CodeGeneratorResponse_maximum_edition(const google_protobuf_compiler_CodeGeneratorResponse* msg) { int32_t default_val = (int32_t)0; @@ -530,7 +530,7 @@ UPB_INLINE bool google_protobuf_compiler_CodeGeneratorResponse_has_maximum_editi } UPB_INLINE void google_protobuf_compiler_CodeGeneratorResponse_clear_file(google_protobuf_compiler_CodeGeneratorResponse* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorResponse_msg_init(), 15); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_compiler_CodeGeneratorResponse_File* const* google_protobuf_compiler_CodeGeneratorResponse_file(const google_protobuf_compiler_CodeGeneratorResponse* msg, size_t* size) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorResponse_msg_init(), 15); @@ -646,7 +646,7 @@ UPB_INLINE char* google_protobuf_compiler_CodeGeneratorResponse_File_serialize_e } UPB_INLINE void google_protobuf_compiler_CodeGeneratorResponse_File_clear_name(google_protobuf_compiler_CodeGeneratorResponse_File* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorResponse__File_msg_init(), 1); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_compiler_CodeGeneratorResponse_File_name(const google_protobuf_compiler_CodeGeneratorResponse_File* msg) { upb_StringView default_val = upb_StringView_FromString(""); @@ -662,7 +662,7 @@ UPB_INLINE bool google_protobuf_compiler_CodeGeneratorResponse_File_has_name(con } UPB_INLINE void google_protobuf_compiler_CodeGeneratorResponse_File_clear_insertion_point(google_protobuf_compiler_CodeGeneratorResponse_File* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorResponse__File_msg_init(), 2); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_compiler_CodeGeneratorResponse_File_insertion_point(const google_protobuf_compiler_CodeGeneratorResponse_File* msg) { upb_StringView default_val = upb_StringView_FromString(""); @@ -678,7 +678,7 @@ UPB_INLINE bool google_protobuf_compiler_CodeGeneratorResponse_File_has_insertio } UPB_INLINE void google_protobuf_compiler_CodeGeneratorResponse_File_clear_content(google_protobuf_compiler_CodeGeneratorResponse_File* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorResponse__File_msg_init(), 15); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_compiler_CodeGeneratorResponse_File_content(const google_protobuf_compiler_CodeGeneratorResponse_File* msg) { upb_StringView default_val = upb_StringView_FromString(""); @@ -694,7 +694,7 @@ UPB_INLINE bool google_protobuf_compiler_CodeGeneratorResponse_File_has_content( } UPB_INLINE void google_protobuf_compiler_CodeGeneratorResponse_File_clear_generated_code_info(google_protobuf_compiler_CodeGeneratorResponse_File* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorResponse__File_msg_init(), 16); - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const struct google_protobuf_GeneratedCodeInfo* google_protobuf_compiler_CodeGeneratorResponse_File_generated_code_info(const google_protobuf_compiler_CodeGeneratorResponse_File* msg) { const struct google_protobuf_GeneratedCodeInfo* default_val = NULL; From 4e90eadcb3ccdfe817abb87786365d79ad950ac4 Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Mon, 8 Jan 2024 15:46:34 +0000 Subject: [PATCH 205/255] Auto-generate files after cl/596588385 --- php/ext/google/protobuf/php-upb.c | 14 +- php/ext/google/protobuf/php-upb.h | 391 +++++++++++---------- ruby/ext/google/protobuf_c/ruby-upb.c | 14 +- ruby/ext/google/protobuf_c/ruby-upb.h | 391 +++++++++++---------- upb/cmake/google/protobuf/descriptor.upb.h | 326 ++++++++--------- 5 files changed, 585 insertions(+), 551 deletions(-) diff --git a/php/ext/google/protobuf/php-upb.c b/php/ext/google/protobuf/php-upb.c index 133d20c55b154..c801ca1b45d3c 100644 --- a/php/ext/google/protobuf/php-upb.c +++ b/php/ext/google/protobuf/php-upb.c @@ -12942,7 +12942,7 @@ const upb_MiniTableField* upb_FieldDef_MiniTable(const upb_FieldDef* f) { } } -const upb_MiniTableExtension* _upb_FieldDef_ExtensionMiniTable( +const upb_MiniTableExtension* upb_FieldDef_MiniTableExtension( const upb_FieldDef* f) { UPB_ASSERT(upb_FieldDef_IsExtension(f)); const upb_FileDef* file = upb_FieldDef_File(f); @@ -13436,7 +13436,7 @@ static void _upb_FieldDef_CreateExt(upb_DefBuilder* ctx, const char* prefix, if (ctx->layout) { UPB_ASSERT(upb_MiniTableExtension_Number( - _upb_FieldDef_ExtensionMiniTable(f)) == f->number_); + upb_FieldDef_MiniTableExtension(f)) == f->number_); } } @@ -13628,7 +13628,7 @@ static void resolve_extension(upb_DefBuilder* ctx, const char* prefix, void _upb_FieldDef_BuildMiniTableExtension(upb_DefBuilder* ctx, const upb_FieldDef* f) { - const upb_MiniTableExtension* ext = _upb_FieldDef_ExtensionMiniTable(f); + const upb_MiniTableExtension* ext = upb_FieldDef_MiniTableExtension(f); if (ctx->layout) { UPB_ASSERT(upb_FieldDef_Number(f) == upb_MiniTableExtension_Number(ext)); @@ -14614,7 +14614,13 @@ bool upb_Message_SetFieldByDef(upb_Message* msg, const upb_FieldDef* f, } void upb_Message_ClearFieldByDef(upb_Message* msg, const upb_FieldDef* f) { - upb_Message_ClearField(msg, upb_FieldDef_MiniTable(f)); + const upb_MiniTableField* m_f = upb_FieldDef_MiniTable(f); + + if (upb_MiniTableField_IsExtension(m_f)) { + upb_Message_ClearExtension(msg, (const upb_MiniTableExtension*)m_f); + } else { + upb_Message_ClearBaseField(msg, m_f); + } } void upb_Message_ClearByDef(upb_Message* msg, const upb_MessageDef* m) { diff --git a/php/ext/google/protobuf/php-upb.h b/php/ext/google/protobuf/php-upb.h index 61e3185374b0e..fbf9bd8a63aec 100644 --- a/php/ext/google/protobuf/php-upb.h +++ b/php/ext/google/protobuf/php-upb.h @@ -2751,31 +2751,34 @@ UPB_INLINE bool _upb_Message_SetExtensionField( return true; } -UPB_INLINE void _upb_Message_ClearExtensionField( - struct upb_Message* msg, const upb_MiniTableExtension* ext_l) { +UPB_INLINE void UPB_PRIVATE(_upb_Message_ClearBaseField)( + struct upb_Message* msg, const upb_MiniTableField* f) { + if (UPB_PRIVATE(_upb_MiniTableField_HasHasbit)(f)) { + UPB_PRIVATE(_upb_Message_ClearHasbit)(msg, f); + } else if (upb_MiniTableField_IsInOneof(f)) { + uint32_t* ptr = UPB_PRIVATE(_upb_Message_OneofCasePtr)(msg, f); + if (*ptr != upb_MiniTableField_Number(f)) return; + *ptr = 0; + } + const char zeros[16] = {0}; + UPB_PRIVATE(_upb_MiniTableField_DataCopy) + (f, UPB_PRIVATE(_upb_Message_DataPtr)(msg, f), zeros); +} + +UPB_INLINE void UPB_PRIVATE(_upb_Message_ClearExtension)( + struct upb_Message* msg, const upb_MiniTableExtension* e) { upb_Message_InternalData* in = upb_Message_GetInternalData(msg); if (!in) return; const struct upb_Extension* base = UPB_PTR_AT(in, in->ext_begin, struct upb_Extension); struct upb_Extension* ext = - (struct upb_Extension*)_upb_Message_Getext(msg, ext_l); + (struct upb_Extension*)_upb_Message_Getext(msg, e); if (ext) { *ext = *base; in->ext_begin += sizeof(struct upb_Extension); } } -UPB_INLINE void _upb_Message_ClearNonExtensionField( - struct upb_Message* msg, const upb_MiniTableField* f) { - if (UPB_PRIVATE(_upb_MiniTableField_HasHasbit)(f)) { - UPB_PRIVATE(_upb_Message_ClearHasbit)(msg, f); - } else if (upb_MiniTableField_IsInOneof(f)) { - if (!UPB_PRIVATE(_upb_Message_ClearOneofCase)(msg, f)) return; - } - void* data = UPB_PRIVATE(_upb_Message_DataPtr)(msg, f); - UPB_PRIVATE(_upb_MiniTableField_DataClear)(f, data); -} - UPB_INLINE void _upb_Message_AssertMapIsUntagged( const struct upb_Message* msg, const upb_MiniTableField* field) { UPB_UNUSED(msg); @@ -3052,21 +3055,27 @@ UPB_API_INLINE const upb_MiniTable* upb_MiniTableSub_Message( extern "C" { #endif -UPB_API_INLINE void upb_Message_ClearField(upb_Message* msg, - const upb_MiniTableField* field) { - if (upb_MiniTableField_IsExtension(field)) { - const upb_MiniTableExtension* ext = (const upb_MiniTableExtension*)field; - _upb_Message_ClearExtensionField(msg, ext); - } else { - _upb_Message_ClearNonExtensionField(msg, field); - } -} +// Functions ending in BaseField() take a (upb_MiniTableField*) argument +// and work only on non-extension fields. +// +// Functions ending in Extension() take a (upb_MiniTableExtension*) argument +// and work only on extensions. UPB_API_INLINE void upb_Message_Clear(upb_Message* msg, - const upb_MiniTable* l) { + const upb_MiniTable* m) { // Note: Can't use UPB_PTR_AT() here because we are doing pointer subtraction. char* mem = (char*)msg - sizeof(upb_Message_Internal); - memset(mem, 0, upb_msg_sizeof(l)); + memset(mem, 0, upb_msg_sizeof(m)); +} + +UPB_API_INLINE void upb_Message_ClearBaseField(upb_Message* msg, + const upb_MiniTableField* f) { + UPB_PRIVATE(_upb_Message_ClearBaseField)(msg, f); +} + +UPB_API_INLINE void upb_Message_ClearExtension( + upb_Message* msg, const upb_MiniTableExtension* e) { + UPB_PRIVATE(_upb_Message_ClearExtension)(msg, e); } UPB_API_INLINE bool upb_Message_HasField(const upb_Message* msg, @@ -4557,7 +4566,7 @@ UPB_INLINE char* google_protobuf_FileDescriptorSet_serialize_ex(const google_pro } UPB_INLINE void google_protobuf_FileDescriptorSet_clear_file(google_protobuf_FileDescriptorSet* msg) { const upb_MiniTableField field = {1, 0, 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_FileDescriptorProto* const* google_protobuf_FileDescriptorSet_file(const google_protobuf_FileDescriptorSet* msg, size_t* size) { const upb_MiniTableField field = {1, 0, 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -4657,7 +4666,7 @@ UPB_INLINE char* google_protobuf_FileDescriptorProto_serialize_ex(const google_p } UPB_INLINE void google_protobuf_FileDescriptorProto_clear_name(google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = {1, UPB_SIZE(44, 8), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_FileDescriptorProto_name(const google_protobuf_FileDescriptorProto* msg) { upb_StringView default_val = upb_StringView_FromString(""); @@ -4673,7 +4682,7 @@ UPB_INLINE bool google_protobuf_FileDescriptorProto_has_name(const google_protob } UPB_INLINE void google_protobuf_FileDescriptorProto_clear_package(google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = {2, UPB_SIZE(52, 24), 2, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_FileDescriptorProto_package(const google_protobuf_FileDescriptorProto* msg) { upb_StringView default_val = upb_StringView_FromString(""); @@ -4689,7 +4698,7 @@ UPB_INLINE bool google_protobuf_FileDescriptorProto_has_package(const google_pro } UPB_INLINE void google_protobuf_FileDescriptorProto_clear_dependency(google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = {3, UPB_SIZE(4, 40), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView const* google_protobuf_FileDescriptorProto_dependency(const google_protobuf_FileDescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {3, UPB_SIZE(4, 40), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -4721,7 +4730,7 @@ UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_dependency_mutable_up } UPB_INLINE void google_protobuf_FileDescriptorProto_clear_message_type(google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = {4, UPB_SIZE(8, 48), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_DescriptorProto* const* google_protobuf_FileDescriptorProto_message_type(const google_protobuf_FileDescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {4, UPB_SIZE(8, 48), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -4753,7 +4762,7 @@ UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_message_type_mutable_ } UPB_INLINE void google_protobuf_FileDescriptorProto_clear_enum_type(google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = {5, UPB_SIZE(12, 56), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_EnumDescriptorProto* const* google_protobuf_FileDescriptorProto_enum_type(const google_protobuf_FileDescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {5, UPB_SIZE(12, 56), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -4785,7 +4794,7 @@ UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_enum_type_mutable_upb } UPB_INLINE void google_protobuf_FileDescriptorProto_clear_service(google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = {6, UPB_SIZE(16, 64), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_ServiceDescriptorProto* const* google_protobuf_FileDescriptorProto_service(const google_protobuf_FileDescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {6, UPB_SIZE(16, 64), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -4817,7 +4826,7 @@ UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_service_mutable_upb_a } UPB_INLINE void google_protobuf_FileDescriptorProto_clear_extension(google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = {7, UPB_SIZE(20, 72), 0, 3, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_FieldDescriptorProto* const* google_protobuf_FileDescriptorProto_extension(const google_protobuf_FileDescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {7, UPB_SIZE(20, 72), 0, 3, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -4849,7 +4858,7 @@ UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_extension_mutable_upb } UPB_INLINE void google_protobuf_FileDescriptorProto_clear_options(google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = {8, UPB_SIZE(24, 80), 3, 4, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_FileOptions* google_protobuf_FileDescriptorProto_options(const google_protobuf_FileDescriptorProto* msg) { const google_protobuf_FileOptions* default_val = NULL; @@ -4865,7 +4874,7 @@ UPB_INLINE bool google_protobuf_FileDescriptorProto_has_options(const google_pro } UPB_INLINE void google_protobuf_FileDescriptorProto_clear_source_code_info(google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = {9, UPB_SIZE(28, 88), 4, 5, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_SourceCodeInfo* google_protobuf_FileDescriptorProto_source_code_info(const google_protobuf_FileDescriptorProto* msg) { const google_protobuf_SourceCodeInfo* default_val = NULL; @@ -4881,7 +4890,7 @@ UPB_INLINE bool google_protobuf_FileDescriptorProto_has_source_code_info(const g } UPB_INLINE void google_protobuf_FileDescriptorProto_clear_public_dependency(google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = {10, UPB_SIZE(32, 96), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t const* google_protobuf_FileDescriptorProto_public_dependency(const google_protobuf_FileDescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {10, UPB_SIZE(32, 96), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -4913,7 +4922,7 @@ UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_public_dependency_mut } UPB_INLINE void google_protobuf_FileDescriptorProto_clear_weak_dependency(google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = {11, UPB_SIZE(36, 104), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t const* google_protobuf_FileDescriptorProto_weak_dependency(const google_protobuf_FileDescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {11, UPB_SIZE(36, 104), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -4945,7 +4954,7 @@ UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_weak_dependency_mutab } UPB_INLINE void google_protobuf_FileDescriptorProto_clear_syntax(google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = {12, UPB_SIZE(60, 112), 5, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_FileDescriptorProto_syntax(const google_protobuf_FileDescriptorProto* msg) { upb_StringView default_val = upb_StringView_FromString(""); @@ -4961,7 +4970,7 @@ UPB_INLINE bool google_protobuf_FileDescriptorProto_has_syntax(const google_prot } UPB_INLINE void google_protobuf_FileDescriptorProto_clear_edition(google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = {14, UPB_SIZE(40, 4), 6, 6, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_FileDescriptorProto_edition(const google_protobuf_FileDescriptorProto* msg) { int32_t default_val = 0; @@ -5259,7 +5268,7 @@ UPB_INLINE char* google_protobuf_DescriptorProto_serialize_ex(const google_proto } UPB_INLINE void google_protobuf_DescriptorProto_clear_name(google_protobuf_DescriptorProto* msg) { const upb_MiniTableField field = {1, UPB_SIZE(40, 8), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_DescriptorProto_name(const google_protobuf_DescriptorProto* msg) { upb_StringView default_val = upb_StringView_FromString(""); @@ -5275,7 +5284,7 @@ UPB_INLINE bool google_protobuf_DescriptorProto_has_name(const google_protobuf_D } UPB_INLINE void google_protobuf_DescriptorProto_clear_field(google_protobuf_DescriptorProto* msg) { const upb_MiniTableField field = {2, UPB_SIZE(4, 24), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_FieldDescriptorProto* const* google_protobuf_DescriptorProto_field(const google_protobuf_DescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {2, UPB_SIZE(4, 24), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -5307,7 +5316,7 @@ UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_field_mutable_upb_array(g } UPB_INLINE void google_protobuf_DescriptorProto_clear_nested_type(google_protobuf_DescriptorProto* msg) { const upb_MiniTableField field = {3, UPB_SIZE(8, 32), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_DescriptorProto* const* google_protobuf_DescriptorProto_nested_type(const google_protobuf_DescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {3, UPB_SIZE(8, 32), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -5339,7 +5348,7 @@ UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_nested_type_mutable_upb_a } UPB_INLINE void google_protobuf_DescriptorProto_clear_enum_type(google_protobuf_DescriptorProto* msg) { const upb_MiniTableField field = {4, UPB_SIZE(12, 40), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_EnumDescriptorProto* const* google_protobuf_DescriptorProto_enum_type(const google_protobuf_DescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {4, UPB_SIZE(12, 40), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -5371,7 +5380,7 @@ UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_enum_type_mutable_upb_arr } UPB_INLINE void google_protobuf_DescriptorProto_clear_extension_range(google_protobuf_DescriptorProto* msg) { const upb_MiniTableField field = {5, UPB_SIZE(16, 48), 0, 3, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_DescriptorProto_ExtensionRange* const* google_protobuf_DescriptorProto_extension_range(const google_protobuf_DescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {5, UPB_SIZE(16, 48), 0, 3, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -5403,7 +5412,7 @@ UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_extension_range_mutable_u } UPB_INLINE void google_protobuf_DescriptorProto_clear_extension(google_protobuf_DescriptorProto* msg) { const upb_MiniTableField field = {6, UPB_SIZE(20, 56), 0, 4, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_FieldDescriptorProto* const* google_protobuf_DescriptorProto_extension(const google_protobuf_DescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {6, UPB_SIZE(20, 56), 0, 4, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -5435,7 +5444,7 @@ UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_extension_mutable_upb_arr } UPB_INLINE void google_protobuf_DescriptorProto_clear_options(google_protobuf_DescriptorProto* msg) { const upb_MiniTableField field = {7, UPB_SIZE(24, 64), 2, 5, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_MessageOptions* google_protobuf_DescriptorProto_options(const google_protobuf_DescriptorProto* msg) { const google_protobuf_MessageOptions* default_val = NULL; @@ -5451,7 +5460,7 @@ UPB_INLINE bool google_protobuf_DescriptorProto_has_options(const google_protobu } UPB_INLINE void google_protobuf_DescriptorProto_clear_oneof_decl(google_protobuf_DescriptorProto* msg) { const upb_MiniTableField field = {8, UPB_SIZE(28, 72), 0, 6, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_OneofDescriptorProto* const* google_protobuf_DescriptorProto_oneof_decl(const google_protobuf_DescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {8, UPB_SIZE(28, 72), 0, 6, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -5483,7 +5492,7 @@ UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_oneof_decl_mutable_upb_ar } UPB_INLINE void google_protobuf_DescriptorProto_clear_reserved_range(google_protobuf_DescriptorProto* msg) { const upb_MiniTableField field = {9, UPB_SIZE(32, 80), 0, 7, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_DescriptorProto_ReservedRange* const* google_protobuf_DescriptorProto_reserved_range(const google_protobuf_DescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {9, UPB_SIZE(32, 80), 0, 7, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -5515,7 +5524,7 @@ UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_reserved_range_mutable_up } UPB_INLINE void google_protobuf_DescriptorProto_clear_reserved_name(google_protobuf_DescriptorProto* msg) { const upb_MiniTableField field = {10, UPB_SIZE(36, 88), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView const* google_protobuf_DescriptorProto_reserved_name(const google_protobuf_DescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {10, UPB_SIZE(36, 88), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -5839,7 +5848,7 @@ UPB_INLINE char* google_protobuf_DescriptorProto_ExtensionRange_serialize_ex(con } UPB_INLINE void google_protobuf_DescriptorProto_ExtensionRange_clear_start(google_protobuf_DescriptorProto_ExtensionRange* msg) { const upb_MiniTableField field = {1, 4, 1, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_DescriptorProto_ExtensionRange_start(const google_protobuf_DescriptorProto_ExtensionRange* msg) { int32_t default_val = (int32_t)0; @@ -5855,7 +5864,7 @@ UPB_INLINE bool google_protobuf_DescriptorProto_ExtensionRange_has_start(const g } UPB_INLINE void google_protobuf_DescriptorProto_ExtensionRange_clear_end(google_protobuf_DescriptorProto_ExtensionRange* msg) { const upb_MiniTableField field = {2, 8, 2, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_DescriptorProto_ExtensionRange_end(const google_protobuf_DescriptorProto_ExtensionRange* msg) { int32_t default_val = (int32_t)0; @@ -5871,7 +5880,7 @@ UPB_INLINE bool google_protobuf_DescriptorProto_ExtensionRange_has_end(const goo } UPB_INLINE void google_protobuf_DescriptorProto_ExtensionRange_clear_options(google_protobuf_DescriptorProto_ExtensionRange* msg) { const upb_MiniTableField field = {3, UPB_SIZE(12, 16), 3, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_ExtensionRangeOptions* google_protobuf_DescriptorProto_ExtensionRange_options(const google_protobuf_DescriptorProto_ExtensionRange* msg) { const google_protobuf_ExtensionRangeOptions* default_val = NULL; @@ -5945,7 +5954,7 @@ UPB_INLINE char* google_protobuf_DescriptorProto_ReservedRange_serialize_ex(cons } UPB_INLINE void google_protobuf_DescriptorProto_ReservedRange_clear_start(google_protobuf_DescriptorProto_ReservedRange* msg) { const upb_MiniTableField field = {1, 4, 1, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_DescriptorProto_ReservedRange_start(const google_protobuf_DescriptorProto_ReservedRange* msg) { int32_t default_val = (int32_t)0; @@ -5961,7 +5970,7 @@ UPB_INLINE bool google_protobuf_DescriptorProto_ReservedRange_has_start(const go } UPB_INLINE void google_protobuf_DescriptorProto_ReservedRange_clear_end(google_protobuf_DescriptorProto_ReservedRange* msg) { const upb_MiniTableField field = {2, 8, 2, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_DescriptorProto_ReservedRange_end(const google_protobuf_DescriptorProto_ReservedRange* msg) { int32_t default_val = (int32_t)0; @@ -6023,7 +6032,7 @@ UPB_INLINE char* google_protobuf_ExtensionRangeOptions_serialize_ex(const google } UPB_INLINE void google_protobuf_ExtensionRangeOptions_clear_declaration(google_protobuf_ExtensionRangeOptions* msg) { const upb_MiniTableField field = {2, UPB_SIZE(4, 8), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_ExtensionRangeOptions_Declaration* const* google_protobuf_ExtensionRangeOptions_declaration(const google_protobuf_ExtensionRangeOptions* msg, size_t* size) { const upb_MiniTableField field = {2, UPB_SIZE(4, 8), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -6055,7 +6064,7 @@ UPB_INLINE upb_Array* _google_protobuf_ExtensionRangeOptions_declaration_mutable } UPB_INLINE void google_protobuf_ExtensionRangeOptions_clear_verification(google_protobuf_ExtensionRangeOptions* msg) { const upb_MiniTableField field = {3, UPB_SIZE(8, 4), 1, 3, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_ExtensionRangeOptions_verification(const google_protobuf_ExtensionRangeOptions* msg) { int32_t default_val = 1; @@ -6071,7 +6080,7 @@ UPB_INLINE bool google_protobuf_ExtensionRangeOptions_has_verification(const goo } UPB_INLINE void google_protobuf_ExtensionRangeOptions_clear_features(google_protobuf_ExtensionRangeOptions* msg) { const upb_MiniTableField field = {50, UPB_SIZE(12, 16), 2, 1, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_FeatureSet* google_protobuf_ExtensionRangeOptions_features(const google_protobuf_ExtensionRangeOptions* msg) { const google_protobuf_FeatureSet* default_val = NULL; @@ -6087,7 +6096,7 @@ UPB_INLINE bool google_protobuf_ExtensionRangeOptions_has_features(const google_ } UPB_INLINE void google_protobuf_ExtensionRangeOptions_clear_uninterpreted_option(google_protobuf_ExtensionRangeOptions* msg) { const upb_MiniTableField field = {999, UPB_SIZE(16, 24), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_ExtensionRangeOptions_uninterpreted_option(const google_protobuf_ExtensionRangeOptions* msg, size_t* size) { const upb_MiniTableField field = {999, UPB_SIZE(16, 24), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -6233,7 +6242,7 @@ UPB_INLINE char* google_protobuf_ExtensionRangeOptions_Declaration_serialize_ex( } UPB_INLINE void google_protobuf_ExtensionRangeOptions_Declaration_clear_number(google_protobuf_ExtensionRangeOptions_Declaration* msg) { const upb_MiniTableField field = {1, 4, 1, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_ExtensionRangeOptions_Declaration_number(const google_protobuf_ExtensionRangeOptions_Declaration* msg) { int32_t default_val = (int32_t)0; @@ -6249,7 +6258,7 @@ UPB_INLINE bool google_protobuf_ExtensionRangeOptions_Declaration_has_number(con } UPB_INLINE void google_protobuf_ExtensionRangeOptions_Declaration_clear_full_name(google_protobuf_ExtensionRangeOptions_Declaration* msg) { const upb_MiniTableField field = {2, UPB_SIZE(12, 16), 2, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_ExtensionRangeOptions_Declaration_full_name(const google_protobuf_ExtensionRangeOptions_Declaration* msg) { upb_StringView default_val = upb_StringView_FromString(""); @@ -6265,7 +6274,7 @@ UPB_INLINE bool google_protobuf_ExtensionRangeOptions_Declaration_has_full_name( } UPB_INLINE void google_protobuf_ExtensionRangeOptions_Declaration_clear_type(google_protobuf_ExtensionRangeOptions_Declaration* msg) { const upb_MiniTableField field = {3, UPB_SIZE(20, 32), 3, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_ExtensionRangeOptions_Declaration_type(const google_protobuf_ExtensionRangeOptions_Declaration* msg) { upb_StringView default_val = upb_StringView_FromString(""); @@ -6281,7 +6290,7 @@ UPB_INLINE bool google_protobuf_ExtensionRangeOptions_Declaration_has_type(const } UPB_INLINE void google_protobuf_ExtensionRangeOptions_Declaration_clear_reserved(google_protobuf_ExtensionRangeOptions_Declaration* msg) { const upb_MiniTableField field = {5, 8, 4, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_ExtensionRangeOptions_Declaration_reserved(const google_protobuf_ExtensionRangeOptions_Declaration* msg) { bool default_val = false; @@ -6297,7 +6306,7 @@ UPB_INLINE bool google_protobuf_ExtensionRangeOptions_Declaration_has_reserved(c } UPB_INLINE void google_protobuf_ExtensionRangeOptions_Declaration_clear_repeated(google_protobuf_ExtensionRangeOptions_Declaration* msg) { const upb_MiniTableField field = {6, 9, 5, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_ExtensionRangeOptions_Declaration_repeated(const google_protobuf_ExtensionRangeOptions_Declaration* msg) { bool default_val = false; @@ -6371,7 +6380,7 @@ UPB_INLINE char* google_protobuf_FieldDescriptorProto_serialize_ex(const google_ } UPB_INLINE void google_protobuf_FieldDescriptorProto_clear_name(google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = {1, UPB_SIZE(28, 24), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_FieldDescriptorProto_name(const google_protobuf_FieldDescriptorProto* msg) { upb_StringView default_val = upb_StringView_FromString(""); @@ -6387,7 +6396,7 @@ UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_name(const google_proto } UPB_INLINE void google_protobuf_FieldDescriptorProto_clear_extendee(google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = {2, UPB_SIZE(36, 40), 2, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_FieldDescriptorProto_extendee(const google_protobuf_FieldDescriptorProto* msg) { upb_StringView default_val = upb_StringView_FromString(""); @@ -6403,7 +6412,7 @@ UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_extendee(const google_p } UPB_INLINE void google_protobuf_FieldDescriptorProto_clear_number(google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = {3, 4, 3, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_FieldDescriptorProto_number(const google_protobuf_FieldDescriptorProto* msg) { int32_t default_val = (int32_t)0; @@ -6419,7 +6428,7 @@ UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_number(const google_pro } UPB_INLINE void google_protobuf_FieldDescriptorProto_clear_label(google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = {4, 8, 4, 1, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_FieldDescriptorProto_label(const google_protobuf_FieldDescriptorProto* msg) { int32_t default_val = 1; @@ -6435,7 +6444,7 @@ UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_label(const google_prot } UPB_INLINE void google_protobuf_FieldDescriptorProto_clear_type(google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = {5, 12, 5, 2, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_FieldDescriptorProto_type(const google_protobuf_FieldDescriptorProto* msg) { int32_t default_val = 1; @@ -6451,7 +6460,7 @@ UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_type(const google_proto } UPB_INLINE void google_protobuf_FieldDescriptorProto_clear_type_name(google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = {6, UPB_SIZE(44, 56), 6, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_FieldDescriptorProto_type_name(const google_protobuf_FieldDescriptorProto* msg) { upb_StringView default_val = upb_StringView_FromString(""); @@ -6467,7 +6476,7 @@ UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_type_name(const google_ } UPB_INLINE void google_protobuf_FieldDescriptorProto_clear_default_value(google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = {7, UPB_SIZE(52, 72), 7, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_FieldDescriptorProto_default_value(const google_protobuf_FieldDescriptorProto* msg) { upb_StringView default_val = upb_StringView_FromString(""); @@ -6483,7 +6492,7 @@ UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_default_value(const goo } UPB_INLINE void google_protobuf_FieldDescriptorProto_clear_options(google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = {8, UPB_SIZE(16, 88), 8, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_FieldOptions* google_protobuf_FieldDescriptorProto_options(const google_protobuf_FieldDescriptorProto* msg) { const google_protobuf_FieldOptions* default_val = NULL; @@ -6499,7 +6508,7 @@ UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_options(const google_pr } UPB_INLINE void google_protobuf_FieldDescriptorProto_clear_oneof_index(google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = {9, UPB_SIZE(20, 16), 9, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_FieldDescriptorProto_oneof_index(const google_protobuf_FieldDescriptorProto* msg) { int32_t default_val = (int32_t)0; @@ -6515,7 +6524,7 @@ UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_oneof_index(const googl } UPB_INLINE void google_protobuf_FieldDescriptorProto_clear_json_name(google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = {10, UPB_SIZE(60, 96), 10, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_FieldDescriptorProto_json_name(const google_protobuf_FieldDescriptorProto* msg) { upb_StringView default_val = upb_StringView_FromString(""); @@ -6531,7 +6540,7 @@ UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_json_name(const google_ } UPB_INLINE void google_protobuf_FieldDescriptorProto_clear_proto3_optional(google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = {17, UPB_SIZE(24, 20), 11, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_FieldDescriptorProto_proto3_optional(const google_protobuf_FieldDescriptorProto* msg) { bool default_val = false; @@ -6637,7 +6646,7 @@ UPB_INLINE char* google_protobuf_OneofDescriptorProto_serialize_ex(const google_ } UPB_INLINE void google_protobuf_OneofDescriptorProto_clear_name(google_protobuf_OneofDescriptorProto* msg) { const upb_MiniTableField field = {1, 8, 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_OneofDescriptorProto_name(const google_protobuf_OneofDescriptorProto* msg) { upb_StringView default_val = upb_StringView_FromString(""); @@ -6653,7 +6662,7 @@ UPB_INLINE bool google_protobuf_OneofDescriptorProto_has_name(const google_proto } UPB_INLINE void google_protobuf_OneofDescriptorProto_clear_options(google_protobuf_OneofDescriptorProto* msg) { const upb_MiniTableField field = {2, UPB_SIZE(4, 24), 2, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_OneofOptions* google_protobuf_OneofDescriptorProto_options(const google_protobuf_OneofDescriptorProto* msg) { const google_protobuf_OneofOptions* default_val = NULL; @@ -6723,7 +6732,7 @@ UPB_INLINE char* google_protobuf_EnumDescriptorProto_serialize_ex(const google_p } UPB_INLINE void google_protobuf_EnumDescriptorProto_clear_name(google_protobuf_EnumDescriptorProto* msg) { const upb_MiniTableField field = {1, UPB_SIZE(20, 8), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_EnumDescriptorProto_name(const google_protobuf_EnumDescriptorProto* msg) { upb_StringView default_val = upb_StringView_FromString(""); @@ -6739,7 +6748,7 @@ UPB_INLINE bool google_protobuf_EnumDescriptorProto_has_name(const google_protob } UPB_INLINE void google_protobuf_EnumDescriptorProto_clear_value(google_protobuf_EnumDescriptorProto* msg) { const upb_MiniTableField field = {2, UPB_SIZE(4, 24), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_EnumValueDescriptorProto* const* google_protobuf_EnumDescriptorProto_value(const google_protobuf_EnumDescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {2, UPB_SIZE(4, 24), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -6771,7 +6780,7 @@ UPB_INLINE upb_Array* _google_protobuf_EnumDescriptorProto_value_mutable_upb_arr } UPB_INLINE void google_protobuf_EnumDescriptorProto_clear_options(google_protobuf_EnumDescriptorProto* msg) { const upb_MiniTableField field = {3, UPB_SIZE(8, 32), 2, 1, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_EnumOptions* google_protobuf_EnumDescriptorProto_options(const google_protobuf_EnumDescriptorProto* msg) { const google_protobuf_EnumOptions* default_val = NULL; @@ -6787,7 +6796,7 @@ UPB_INLINE bool google_protobuf_EnumDescriptorProto_has_options(const google_pro } UPB_INLINE void google_protobuf_EnumDescriptorProto_clear_reserved_range(google_protobuf_EnumDescriptorProto* msg) { const upb_MiniTableField field = {4, UPB_SIZE(12, 40), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_EnumDescriptorProto_EnumReservedRange* const* google_protobuf_EnumDescriptorProto_reserved_range(const google_protobuf_EnumDescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {4, UPB_SIZE(12, 40), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -6819,7 +6828,7 @@ UPB_INLINE upb_Array* _google_protobuf_EnumDescriptorProto_reserved_range_mutabl } UPB_INLINE void google_protobuf_EnumDescriptorProto_clear_reserved_name(google_protobuf_EnumDescriptorProto* msg) { const upb_MiniTableField field = {5, UPB_SIZE(16, 48), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView const* google_protobuf_EnumDescriptorProto_reserved_name(const google_protobuf_EnumDescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {5, UPB_SIZE(16, 48), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -6993,7 +7002,7 @@ UPB_INLINE char* google_protobuf_EnumDescriptorProto_EnumReservedRange_serialize } UPB_INLINE void google_protobuf_EnumDescriptorProto_EnumReservedRange_clear_start(google_protobuf_EnumDescriptorProto_EnumReservedRange* msg) { const upb_MiniTableField field = {1, 4, 1, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_EnumDescriptorProto_EnumReservedRange_start(const google_protobuf_EnumDescriptorProto_EnumReservedRange* msg) { int32_t default_val = (int32_t)0; @@ -7009,7 +7018,7 @@ UPB_INLINE bool google_protobuf_EnumDescriptorProto_EnumReservedRange_has_start( } UPB_INLINE void google_protobuf_EnumDescriptorProto_EnumReservedRange_clear_end(google_protobuf_EnumDescriptorProto_EnumReservedRange* msg) { const upb_MiniTableField field = {2, 8, 2, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_EnumDescriptorProto_EnumReservedRange_end(const google_protobuf_EnumDescriptorProto_EnumReservedRange* msg) { int32_t default_val = (int32_t)0; @@ -7071,7 +7080,7 @@ UPB_INLINE char* google_protobuf_EnumValueDescriptorProto_serialize_ex(const goo } UPB_INLINE void google_protobuf_EnumValueDescriptorProto_clear_name(google_protobuf_EnumValueDescriptorProto* msg) { const upb_MiniTableField field = {1, UPB_SIZE(12, 8), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_EnumValueDescriptorProto_name(const google_protobuf_EnumValueDescriptorProto* msg) { upb_StringView default_val = upb_StringView_FromString(""); @@ -7087,7 +7096,7 @@ UPB_INLINE bool google_protobuf_EnumValueDescriptorProto_has_name(const google_p } UPB_INLINE void google_protobuf_EnumValueDescriptorProto_clear_number(google_protobuf_EnumValueDescriptorProto* msg) { const upb_MiniTableField field = {2, 4, 2, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_EnumValueDescriptorProto_number(const google_protobuf_EnumValueDescriptorProto* msg) { int32_t default_val = (int32_t)0; @@ -7103,7 +7112,7 @@ UPB_INLINE bool google_protobuf_EnumValueDescriptorProto_has_number(const google } UPB_INLINE void google_protobuf_EnumValueDescriptorProto_clear_options(google_protobuf_EnumValueDescriptorProto* msg) { const upb_MiniTableField field = {3, UPB_SIZE(8, 24), 3, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_EnumValueOptions* google_protobuf_EnumValueDescriptorProto_options(const google_protobuf_EnumValueDescriptorProto* msg) { const google_protobuf_EnumValueOptions* default_val = NULL; @@ -7177,7 +7186,7 @@ UPB_INLINE char* google_protobuf_ServiceDescriptorProto_serialize_ex(const googl } UPB_INLINE void google_protobuf_ServiceDescriptorProto_clear_name(google_protobuf_ServiceDescriptorProto* msg) { const upb_MiniTableField field = {1, UPB_SIZE(12, 8), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_ServiceDescriptorProto_name(const google_protobuf_ServiceDescriptorProto* msg) { upb_StringView default_val = upb_StringView_FromString(""); @@ -7193,7 +7202,7 @@ UPB_INLINE bool google_protobuf_ServiceDescriptorProto_has_name(const google_pro } UPB_INLINE void google_protobuf_ServiceDescriptorProto_clear_method(google_protobuf_ServiceDescriptorProto* msg) { const upb_MiniTableField field = {2, UPB_SIZE(4, 24), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_MethodDescriptorProto* const* google_protobuf_ServiceDescriptorProto_method(const google_protobuf_ServiceDescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {2, UPB_SIZE(4, 24), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -7225,7 +7234,7 @@ UPB_INLINE upb_Array* _google_protobuf_ServiceDescriptorProto_method_mutable_upb } UPB_INLINE void google_protobuf_ServiceDescriptorProto_clear_options(google_protobuf_ServiceDescriptorProto* msg) { const upb_MiniTableField field = {3, UPB_SIZE(8, 32), 2, 1, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_ServiceOptions* google_protobuf_ServiceDescriptorProto_options(const google_protobuf_ServiceDescriptorProto* msg) { const google_protobuf_ServiceOptions* default_val = NULL; @@ -7325,7 +7334,7 @@ UPB_INLINE char* google_protobuf_MethodDescriptorProto_serialize_ex(const google } UPB_INLINE void google_protobuf_MethodDescriptorProto_clear_name(google_protobuf_MethodDescriptorProto* msg) { const upb_MiniTableField field = {1, UPB_SIZE(12, 8), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_MethodDescriptorProto_name(const google_protobuf_MethodDescriptorProto* msg) { upb_StringView default_val = upb_StringView_FromString(""); @@ -7341,7 +7350,7 @@ UPB_INLINE bool google_protobuf_MethodDescriptorProto_has_name(const google_prot } UPB_INLINE void google_protobuf_MethodDescriptorProto_clear_input_type(google_protobuf_MethodDescriptorProto* msg) { const upb_MiniTableField field = {2, UPB_SIZE(20, 24), 2, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_MethodDescriptorProto_input_type(const google_protobuf_MethodDescriptorProto* msg) { upb_StringView default_val = upb_StringView_FromString(""); @@ -7357,7 +7366,7 @@ UPB_INLINE bool google_protobuf_MethodDescriptorProto_has_input_type(const googl } UPB_INLINE void google_protobuf_MethodDescriptorProto_clear_output_type(google_protobuf_MethodDescriptorProto* msg) { const upb_MiniTableField field = {3, UPB_SIZE(28, 40), 3, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_MethodDescriptorProto_output_type(const google_protobuf_MethodDescriptorProto* msg) { upb_StringView default_val = upb_StringView_FromString(""); @@ -7373,7 +7382,7 @@ UPB_INLINE bool google_protobuf_MethodDescriptorProto_has_output_type(const goog } UPB_INLINE void google_protobuf_MethodDescriptorProto_clear_options(google_protobuf_MethodDescriptorProto* msg) { const upb_MiniTableField field = {4, UPB_SIZE(4, 56), 4, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_MethodOptions* google_protobuf_MethodDescriptorProto_options(const google_protobuf_MethodDescriptorProto* msg) { const google_protobuf_MethodOptions* default_val = NULL; @@ -7389,7 +7398,7 @@ UPB_INLINE bool google_protobuf_MethodDescriptorProto_has_options(const google_p } UPB_INLINE void google_protobuf_MethodDescriptorProto_clear_client_streaming(google_protobuf_MethodDescriptorProto* msg) { const upb_MiniTableField field = {5, UPB_SIZE(8, 1), 5, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_MethodDescriptorProto_client_streaming(const google_protobuf_MethodDescriptorProto* msg) { bool default_val = false; @@ -7405,7 +7414,7 @@ UPB_INLINE bool google_protobuf_MethodDescriptorProto_has_client_streaming(const } UPB_INLINE void google_protobuf_MethodDescriptorProto_clear_server_streaming(google_protobuf_MethodDescriptorProto* msg) { const upb_MiniTableField field = {6, UPB_SIZE(9, 2), 6, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_MethodDescriptorProto_server_streaming(const google_protobuf_MethodDescriptorProto* msg) { bool default_val = false; @@ -7491,7 +7500,7 @@ UPB_INLINE char* google_protobuf_FileOptions_serialize_ex(const google_protobuf_ } UPB_INLINE void google_protobuf_FileOptions_clear_java_package(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {1, UPB_SIZE(24, 16), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_FileOptions_java_package(const google_protobuf_FileOptions* msg) { upb_StringView default_val = upb_StringView_FromString(""); @@ -7507,7 +7516,7 @@ UPB_INLINE bool google_protobuf_FileOptions_has_java_package(const google_protob } UPB_INLINE void google_protobuf_FileOptions_clear_java_outer_classname(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {8, 32, 2, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_FileOptions_java_outer_classname(const google_protobuf_FileOptions* msg) { upb_StringView default_val = upb_StringView_FromString(""); @@ -7523,7 +7532,7 @@ UPB_INLINE bool google_protobuf_FileOptions_has_java_outer_classname(const googl } UPB_INLINE void google_protobuf_FileOptions_clear_optimize_for(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {9, 4, 3, 2, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_FileOptions_optimize_for(const google_protobuf_FileOptions* msg) { int32_t default_val = 1; @@ -7539,7 +7548,7 @@ UPB_INLINE bool google_protobuf_FileOptions_has_optimize_for(const google_protob } UPB_INLINE void google_protobuf_FileOptions_clear_java_multiple_files(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {10, 8, 4, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_FileOptions_java_multiple_files(const google_protobuf_FileOptions* msg) { bool default_val = false; @@ -7555,7 +7564,7 @@ UPB_INLINE bool google_protobuf_FileOptions_has_java_multiple_files(const google } UPB_INLINE void google_protobuf_FileOptions_clear_go_package(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {11, UPB_SIZE(40, 48), 5, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_FileOptions_go_package(const google_protobuf_FileOptions* msg) { upb_StringView default_val = upb_StringView_FromString(""); @@ -7571,7 +7580,7 @@ UPB_INLINE bool google_protobuf_FileOptions_has_go_package(const google_protobuf } UPB_INLINE void google_protobuf_FileOptions_clear_cc_generic_services(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {16, 9, 6, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_FileOptions_cc_generic_services(const google_protobuf_FileOptions* msg) { bool default_val = false; @@ -7587,7 +7596,7 @@ UPB_INLINE bool google_protobuf_FileOptions_has_cc_generic_services(const google } UPB_INLINE void google_protobuf_FileOptions_clear_java_generic_services(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {17, 10, 7, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_FileOptions_java_generic_services(const google_protobuf_FileOptions* msg) { bool default_val = false; @@ -7603,7 +7612,7 @@ UPB_INLINE bool google_protobuf_FileOptions_has_java_generic_services(const goog } UPB_INLINE void google_protobuf_FileOptions_clear_py_generic_services(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {18, 11, 8, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_FileOptions_py_generic_services(const google_protobuf_FileOptions* msg) { bool default_val = false; @@ -7619,7 +7628,7 @@ UPB_INLINE bool google_protobuf_FileOptions_has_py_generic_services(const google } UPB_INLINE void google_protobuf_FileOptions_clear_java_generate_equals_and_hash(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {20, 12, 9, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_FileOptions_java_generate_equals_and_hash(const google_protobuf_FileOptions* msg) { bool default_val = false; @@ -7635,7 +7644,7 @@ UPB_INLINE bool google_protobuf_FileOptions_has_java_generate_equals_and_hash(co } UPB_INLINE void google_protobuf_FileOptions_clear_deprecated(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {23, 13, 10, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_FileOptions_deprecated(const google_protobuf_FileOptions* msg) { bool default_val = false; @@ -7651,7 +7660,7 @@ UPB_INLINE bool google_protobuf_FileOptions_has_deprecated(const google_protobuf } UPB_INLINE void google_protobuf_FileOptions_clear_java_string_check_utf8(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {27, 14, 11, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_FileOptions_java_string_check_utf8(const google_protobuf_FileOptions* msg) { bool default_val = false; @@ -7667,7 +7676,7 @@ UPB_INLINE bool google_protobuf_FileOptions_has_java_string_check_utf8(const goo } UPB_INLINE void google_protobuf_FileOptions_clear_cc_enable_arenas(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {31, 15, 12, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_FileOptions_cc_enable_arenas(const google_protobuf_FileOptions* msg) { bool default_val = true; @@ -7683,7 +7692,7 @@ UPB_INLINE bool google_protobuf_FileOptions_has_cc_enable_arenas(const google_pr } UPB_INLINE void google_protobuf_FileOptions_clear_objc_class_prefix(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {36, UPB_SIZE(48, 64), 13, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_FileOptions_objc_class_prefix(const google_protobuf_FileOptions* msg) { upb_StringView default_val = upb_StringView_FromString(""); @@ -7699,7 +7708,7 @@ UPB_INLINE bool google_protobuf_FileOptions_has_objc_class_prefix(const google_p } UPB_INLINE void google_protobuf_FileOptions_clear_csharp_namespace(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {37, UPB_SIZE(56, 80), 14, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_FileOptions_csharp_namespace(const google_protobuf_FileOptions* msg) { upb_StringView default_val = upb_StringView_FromString(""); @@ -7715,7 +7724,7 @@ UPB_INLINE bool google_protobuf_FileOptions_has_csharp_namespace(const google_pr } UPB_INLINE void google_protobuf_FileOptions_clear_swift_prefix(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {39, UPB_SIZE(64, 96), 15, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_FileOptions_swift_prefix(const google_protobuf_FileOptions* msg) { upb_StringView default_val = upb_StringView_FromString(""); @@ -7731,7 +7740,7 @@ UPB_INLINE bool google_protobuf_FileOptions_has_swift_prefix(const google_protob } UPB_INLINE void google_protobuf_FileOptions_clear_php_class_prefix(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {40, UPB_SIZE(72, 112), 16, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_FileOptions_php_class_prefix(const google_protobuf_FileOptions* msg) { upb_StringView default_val = upb_StringView_FromString(""); @@ -7747,7 +7756,7 @@ UPB_INLINE bool google_protobuf_FileOptions_has_php_class_prefix(const google_pr } UPB_INLINE void google_protobuf_FileOptions_clear_php_namespace(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {41, UPB_SIZE(80, 128), 17, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_FileOptions_php_namespace(const google_protobuf_FileOptions* msg) { upb_StringView default_val = upb_StringView_FromString(""); @@ -7763,7 +7772,7 @@ UPB_INLINE bool google_protobuf_FileOptions_has_php_namespace(const google_proto } UPB_INLINE void google_protobuf_FileOptions_clear_php_metadata_namespace(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {44, UPB_SIZE(88, 144), 18, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_FileOptions_php_metadata_namespace(const google_protobuf_FileOptions* msg) { upb_StringView default_val = upb_StringView_FromString(""); @@ -7779,7 +7788,7 @@ UPB_INLINE bool google_protobuf_FileOptions_has_php_metadata_namespace(const goo } UPB_INLINE void google_protobuf_FileOptions_clear_ruby_package(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {45, UPB_SIZE(96, 160), 19, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_FileOptions_ruby_package(const google_protobuf_FileOptions* msg) { upb_StringView default_val = upb_StringView_FromString(""); @@ -7795,7 +7804,7 @@ UPB_INLINE bool google_protobuf_FileOptions_has_ruby_package(const google_protob } UPB_INLINE void google_protobuf_FileOptions_clear_features(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {50, UPB_SIZE(16, 176), 20, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_FeatureSet* google_protobuf_FileOptions_features(const google_protobuf_FileOptions* msg) { const google_protobuf_FeatureSet* default_val = NULL; @@ -7811,7 +7820,7 @@ UPB_INLINE bool google_protobuf_FileOptions_has_features(const google_protobuf_F } UPB_INLINE void google_protobuf_FileOptions_clear_uninterpreted_option(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {999, UPB_SIZE(20, 184), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_FileOptions_uninterpreted_option(const google_protobuf_FileOptions* msg, size_t* size) { const upb_MiniTableField field = {999, UPB_SIZE(20, 184), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -7999,7 +8008,7 @@ UPB_INLINE char* google_protobuf_MessageOptions_serialize_ex(const google_protob } UPB_INLINE void google_protobuf_MessageOptions_clear_message_set_wire_format(google_protobuf_MessageOptions* msg) { const upb_MiniTableField field = {1, 1, 1, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_MessageOptions_message_set_wire_format(const google_protobuf_MessageOptions* msg) { bool default_val = false; @@ -8015,7 +8024,7 @@ UPB_INLINE bool google_protobuf_MessageOptions_has_message_set_wire_format(const } UPB_INLINE void google_protobuf_MessageOptions_clear_no_standard_descriptor_accessor(google_protobuf_MessageOptions* msg) { const upb_MiniTableField field = {2, 2, 2, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_MessageOptions_no_standard_descriptor_accessor(const google_protobuf_MessageOptions* msg) { bool default_val = false; @@ -8031,7 +8040,7 @@ UPB_INLINE bool google_protobuf_MessageOptions_has_no_standard_descriptor_access } UPB_INLINE void google_protobuf_MessageOptions_clear_deprecated(google_protobuf_MessageOptions* msg) { const upb_MiniTableField field = {3, 3, 3, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_MessageOptions_deprecated(const google_protobuf_MessageOptions* msg) { bool default_val = false; @@ -8047,7 +8056,7 @@ UPB_INLINE bool google_protobuf_MessageOptions_has_deprecated(const google_proto } UPB_INLINE void google_protobuf_MessageOptions_clear_map_entry(google_protobuf_MessageOptions* msg) { const upb_MiniTableField field = {7, 4, 4, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_MessageOptions_map_entry(const google_protobuf_MessageOptions* msg) { bool default_val = false; @@ -8063,7 +8072,7 @@ UPB_INLINE bool google_protobuf_MessageOptions_has_map_entry(const google_protob } UPB_INLINE void google_protobuf_MessageOptions_clear_deprecated_legacy_json_field_conflicts(google_protobuf_MessageOptions* msg) { const upb_MiniTableField field = {11, 5, 5, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_MessageOptions_deprecated_legacy_json_field_conflicts(const google_protobuf_MessageOptions* msg) { bool default_val = false; @@ -8079,7 +8088,7 @@ UPB_INLINE bool google_protobuf_MessageOptions_has_deprecated_legacy_json_field_ } UPB_INLINE void google_protobuf_MessageOptions_clear_features(google_protobuf_MessageOptions* msg) { const upb_MiniTableField field = {12, 8, 6, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_FeatureSet* google_protobuf_MessageOptions_features(const google_protobuf_MessageOptions* msg) { const google_protobuf_FeatureSet* default_val = NULL; @@ -8095,7 +8104,7 @@ UPB_INLINE bool google_protobuf_MessageOptions_has_features(const google_protobu } UPB_INLINE void google_protobuf_MessageOptions_clear_uninterpreted_option(google_protobuf_MessageOptions* msg) { const upb_MiniTableField field = {999, UPB_SIZE(12, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_MessageOptions_uninterpreted_option(const google_protobuf_MessageOptions* msg, size_t* size) { const upb_MiniTableField field = {999, UPB_SIZE(12, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -8227,7 +8236,7 @@ UPB_INLINE char* google_protobuf_FieldOptions_serialize_ex(const google_protobuf } UPB_INLINE void google_protobuf_FieldOptions_clear_ctype(google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {1, 4, 1, 3, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_FieldOptions_ctype(const google_protobuf_FieldOptions* msg) { int32_t default_val = 0; @@ -8243,7 +8252,7 @@ UPB_INLINE bool google_protobuf_FieldOptions_has_ctype(const google_protobuf_Fie } UPB_INLINE void google_protobuf_FieldOptions_clear_packed(google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {2, 8, 2, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_FieldOptions_packed(const google_protobuf_FieldOptions* msg) { bool default_val = false; @@ -8259,7 +8268,7 @@ UPB_INLINE bool google_protobuf_FieldOptions_has_packed(const google_protobuf_Fi } UPB_INLINE void google_protobuf_FieldOptions_clear_deprecated(google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {3, 9, 3, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_FieldOptions_deprecated(const google_protobuf_FieldOptions* msg) { bool default_val = false; @@ -8275,7 +8284,7 @@ UPB_INLINE bool google_protobuf_FieldOptions_has_deprecated(const google_protobu } UPB_INLINE void google_protobuf_FieldOptions_clear_lazy(google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {5, 10, 4, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_FieldOptions_lazy(const google_protobuf_FieldOptions* msg) { bool default_val = false; @@ -8291,7 +8300,7 @@ UPB_INLINE bool google_protobuf_FieldOptions_has_lazy(const google_protobuf_Fiel } UPB_INLINE void google_protobuf_FieldOptions_clear_jstype(google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {6, 12, 5, 4, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_FieldOptions_jstype(const google_protobuf_FieldOptions* msg) { int32_t default_val = 0; @@ -8307,7 +8316,7 @@ UPB_INLINE bool google_protobuf_FieldOptions_has_jstype(const google_protobuf_Fi } UPB_INLINE void google_protobuf_FieldOptions_clear_weak(google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {10, 16, 6, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_FieldOptions_weak(const google_protobuf_FieldOptions* msg) { bool default_val = false; @@ -8323,7 +8332,7 @@ UPB_INLINE bool google_protobuf_FieldOptions_has_weak(const google_protobuf_Fiel } UPB_INLINE void google_protobuf_FieldOptions_clear_unverified_lazy(google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {15, 17, 7, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_FieldOptions_unverified_lazy(const google_protobuf_FieldOptions* msg) { bool default_val = false; @@ -8339,7 +8348,7 @@ UPB_INLINE bool google_protobuf_FieldOptions_has_unverified_lazy(const google_pr } UPB_INLINE void google_protobuf_FieldOptions_clear_debug_redact(google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {16, 18, 8, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_FieldOptions_debug_redact(const google_protobuf_FieldOptions* msg) { bool default_val = false; @@ -8355,7 +8364,7 @@ UPB_INLINE bool google_protobuf_FieldOptions_has_debug_redact(const google_proto } UPB_INLINE void google_protobuf_FieldOptions_clear_retention(google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {17, 20, 9, 5, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_FieldOptions_retention(const google_protobuf_FieldOptions* msg) { int32_t default_val = 0; @@ -8371,7 +8380,7 @@ UPB_INLINE bool google_protobuf_FieldOptions_has_retention(const google_protobuf } UPB_INLINE void google_protobuf_FieldOptions_clear_targets(google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {19, 24, 0, 6, 14, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t const* google_protobuf_FieldOptions_targets(const google_protobuf_FieldOptions* msg, size_t* size) { const upb_MiniTableField field = {19, 24, 0, 6, 14, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -8403,7 +8412,7 @@ UPB_INLINE upb_Array* _google_protobuf_FieldOptions_targets_mutable_upb_array(go } UPB_INLINE void google_protobuf_FieldOptions_clear_edition_defaults(google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {20, UPB_SIZE(28, 32), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_FieldOptions_EditionDefault* const* google_protobuf_FieldOptions_edition_defaults(const google_protobuf_FieldOptions* msg, size_t* size) { const upb_MiniTableField field = {20, UPB_SIZE(28, 32), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -8435,7 +8444,7 @@ UPB_INLINE upb_Array* _google_protobuf_FieldOptions_edition_defaults_mutable_upb } UPB_INLINE void google_protobuf_FieldOptions_clear_features(google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {21, UPB_SIZE(32, 40), 10, 1, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_FeatureSet* google_protobuf_FieldOptions_features(const google_protobuf_FieldOptions* msg) { const google_protobuf_FeatureSet* default_val = NULL; @@ -8451,7 +8460,7 @@ UPB_INLINE bool google_protobuf_FieldOptions_has_features(const google_protobuf_ } UPB_INLINE void google_protobuf_FieldOptions_clear_uninterpreted_option(google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {999, UPB_SIZE(36, 48), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_FieldOptions_uninterpreted_option(const google_protobuf_FieldOptions* msg, size_t* size) { const upb_MiniTableField field = {999, UPB_SIZE(36, 48), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -8657,7 +8666,7 @@ UPB_INLINE char* google_protobuf_FieldOptions_EditionDefault_serialize_ex(const } UPB_INLINE void google_protobuf_FieldOptions_EditionDefault_clear_value(google_protobuf_FieldOptions_EditionDefault* msg) { const upb_MiniTableField field = {2, 8, 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_FieldOptions_EditionDefault_value(const google_protobuf_FieldOptions_EditionDefault* msg) { upb_StringView default_val = upb_StringView_FromString(""); @@ -8673,7 +8682,7 @@ UPB_INLINE bool google_protobuf_FieldOptions_EditionDefault_has_value(const goog } UPB_INLINE void google_protobuf_FieldOptions_EditionDefault_clear_edition(google_protobuf_FieldOptions_EditionDefault* msg) { const upb_MiniTableField field = {3, 4, 2, 0, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_FieldOptions_EditionDefault_edition(const google_protobuf_FieldOptions_EditionDefault* msg) { int32_t default_val = 0; @@ -8735,7 +8744,7 @@ UPB_INLINE char* google_protobuf_OneofOptions_serialize_ex(const google_protobuf } UPB_INLINE void google_protobuf_OneofOptions_clear_features(google_protobuf_OneofOptions* msg) { const upb_MiniTableField field = {1, UPB_SIZE(4, 8), 1, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_FeatureSet* google_protobuf_OneofOptions_features(const google_protobuf_OneofOptions* msg) { const google_protobuf_FeatureSet* default_val = NULL; @@ -8751,7 +8760,7 @@ UPB_INLINE bool google_protobuf_OneofOptions_has_features(const google_protobuf_ } UPB_INLINE void google_protobuf_OneofOptions_clear_uninterpreted_option(google_protobuf_OneofOptions* msg) { const upb_MiniTableField field = {999, UPB_SIZE(8, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_OneofOptions_uninterpreted_option(const google_protobuf_OneofOptions* msg, size_t* size) { const upb_MiniTableField field = {999, UPB_SIZE(8, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -8863,7 +8872,7 @@ UPB_INLINE char* google_protobuf_EnumOptions_serialize_ex(const google_protobuf_ } UPB_INLINE void google_protobuf_EnumOptions_clear_allow_alias(google_protobuf_EnumOptions* msg) { const upb_MiniTableField field = {2, 1, 1, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_EnumOptions_allow_alias(const google_protobuf_EnumOptions* msg) { bool default_val = false; @@ -8879,7 +8888,7 @@ UPB_INLINE bool google_protobuf_EnumOptions_has_allow_alias(const google_protobu } UPB_INLINE void google_protobuf_EnumOptions_clear_deprecated(google_protobuf_EnumOptions* msg) { const upb_MiniTableField field = {3, 2, 2, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_EnumOptions_deprecated(const google_protobuf_EnumOptions* msg) { bool default_val = false; @@ -8895,7 +8904,7 @@ UPB_INLINE bool google_protobuf_EnumOptions_has_deprecated(const google_protobuf } UPB_INLINE void google_protobuf_EnumOptions_clear_deprecated_legacy_json_field_conflicts(google_protobuf_EnumOptions* msg) { const upb_MiniTableField field = {6, 3, 3, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_EnumOptions_deprecated_legacy_json_field_conflicts(const google_protobuf_EnumOptions* msg) { bool default_val = false; @@ -8911,7 +8920,7 @@ UPB_INLINE bool google_protobuf_EnumOptions_has_deprecated_legacy_json_field_con } UPB_INLINE void google_protobuf_EnumOptions_clear_features(google_protobuf_EnumOptions* msg) { const upb_MiniTableField field = {7, UPB_SIZE(4, 8), 4, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_FeatureSet* google_protobuf_EnumOptions_features(const google_protobuf_EnumOptions* msg) { const google_protobuf_FeatureSet* default_val = NULL; @@ -8927,7 +8936,7 @@ UPB_INLINE bool google_protobuf_EnumOptions_has_features(const google_protobuf_E } UPB_INLINE void google_protobuf_EnumOptions_clear_uninterpreted_option(google_protobuf_EnumOptions* msg) { const upb_MiniTableField field = {999, UPB_SIZE(8, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_EnumOptions_uninterpreted_option(const google_protobuf_EnumOptions* msg, size_t* size) { const upb_MiniTableField field = {999, UPB_SIZE(8, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -9051,7 +9060,7 @@ UPB_INLINE char* google_protobuf_EnumValueOptions_serialize_ex(const google_prot } UPB_INLINE void google_protobuf_EnumValueOptions_clear_deprecated(google_protobuf_EnumValueOptions* msg) { const upb_MiniTableField field = {1, 1, 1, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_EnumValueOptions_deprecated(const google_protobuf_EnumValueOptions* msg) { bool default_val = false; @@ -9067,7 +9076,7 @@ UPB_INLINE bool google_protobuf_EnumValueOptions_has_deprecated(const google_pro } UPB_INLINE void google_protobuf_EnumValueOptions_clear_features(google_protobuf_EnumValueOptions* msg) { const upb_MiniTableField field = {2, UPB_SIZE(4, 8), 2, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_FeatureSet* google_protobuf_EnumValueOptions_features(const google_protobuf_EnumValueOptions* msg) { const google_protobuf_FeatureSet* default_val = NULL; @@ -9083,7 +9092,7 @@ UPB_INLINE bool google_protobuf_EnumValueOptions_has_features(const google_proto } UPB_INLINE void google_protobuf_EnumValueOptions_clear_debug_redact(google_protobuf_EnumValueOptions* msg) { const upb_MiniTableField field = {3, UPB_SIZE(8, 2), 3, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_EnumValueOptions_debug_redact(const google_protobuf_EnumValueOptions* msg) { bool default_val = false; @@ -9099,7 +9108,7 @@ UPB_INLINE bool google_protobuf_EnumValueOptions_has_debug_redact(const google_p } UPB_INLINE void google_protobuf_EnumValueOptions_clear_uninterpreted_option(google_protobuf_EnumValueOptions* msg) { const upb_MiniTableField field = {999, UPB_SIZE(12, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_EnumValueOptions_uninterpreted_option(const google_protobuf_EnumValueOptions* msg, size_t* size) { const upb_MiniTableField field = {999, UPB_SIZE(12, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -9219,7 +9228,7 @@ UPB_INLINE char* google_protobuf_ServiceOptions_serialize_ex(const google_protob } UPB_INLINE void google_protobuf_ServiceOptions_clear_deprecated(google_protobuf_ServiceOptions* msg) { const upb_MiniTableField field = {33, 1, 1, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_ServiceOptions_deprecated(const google_protobuf_ServiceOptions* msg) { bool default_val = false; @@ -9235,7 +9244,7 @@ UPB_INLINE bool google_protobuf_ServiceOptions_has_deprecated(const google_proto } UPB_INLINE void google_protobuf_ServiceOptions_clear_features(google_protobuf_ServiceOptions* msg) { const upb_MiniTableField field = {34, UPB_SIZE(4, 8), 2, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_FeatureSet* google_protobuf_ServiceOptions_features(const google_protobuf_ServiceOptions* msg) { const google_protobuf_FeatureSet* default_val = NULL; @@ -9251,7 +9260,7 @@ UPB_INLINE bool google_protobuf_ServiceOptions_has_features(const google_protobu } UPB_INLINE void google_protobuf_ServiceOptions_clear_uninterpreted_option(google_protobuf_ServiceOptions* msg) { const upb_MiniTableField field = {999, UPB_SIZE(8, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_ServiceOptions_uninterpreted_option(const google_protobuf_ServiceOptions* msg, size_t* size) { const upb_MiniTableField field = {999, UPB_SIZE(8, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -9367,7 +9376,7 @@ UPB_INLINE char* google_protobuf_MethodOptions_serialize_ex(const google_protobu } UPB_INLINE void google_protobuf_MethodOptions_clear_deprecated(google_protobuf_MethodOptions* msg) { const upb_MiniTableField field = {33, 1, 1, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_MethodOptions_deprecated(const google_protobuf_MethodOptions* msg) { bool default_val = false; @@ -9383,7 +9392,7 @@ UPB_INLINE bool google_protobuf_MethodOptions_has_deprecated(const google_protob } UPB_INLINE void google_protobuf_MethodOptions_clear_idempotency_level(google_protobuf_MethodOptions* msg) { const upb_MiniTableField field = {34, 4, 2, 2, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_MethodOptions_idempotency_level(const google_protobuf_MethodOptions* msg) { int32_t default_val = 0; @@ -9399,7 +9408,7 @@ UPB_INLINE bool google_protobuf_MethodOptions_has_idempotency_level(const google } UPB_INLINE void google_protobuf_MethodOptions_clear_features(google_protobuf_MethodOptions* msg) { const upb_MiniTableField field = {35, 8, 3, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_FeatureSet* google_protobuf_MethodOptions_features(const google_protobuf_MethodOptions* msg) { const google_protobuf_FeatureSet* default_val = NULL; @@ -9415,7 +9424,7 @@ UPB_INLINE bool google_protobuf_MethodOptions_has_features(const google_protobuf } UPB_INLINE void google_protobuf_MethodOptions_clear_uninterpreted_option(google_protobuf_MethodOptions* msg) { const upb_MiniTableField field = {999, UPB_SIZE(12, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_MethodOptions_uninterpreted_option(const google_protobuf_MethodOptions* msg, size_t* size) { const upb_MiniTableField field = {999, UPB_SIZE(12, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -9535,7 +9544,7 @@ UPB_INLINE char* google_protobuf_UninterpretedOption_serialize_ex(const google_p } UPB_INLINE void google_protobuf_UninterpretedOption_clear_name(google_protobuf_UninterpretedOption* msg) { const upb_MiniTableField field = {2, UPB_SIZE(4, 8), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_UninterpretedOption_NamePart* const* google_protobuf_UninterpretedOption_name(const google_protobuf_UninterpretedOption* msg, size_t* size) { const upb_MiniTableField field = {2, UPB_SIZE(4, 8), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -9567,7 +9576,7 @@ UPB_INLINE upb_Array* _google_protobuf_UninterpretedOption_name_mutable_upb_arra } UPB_INLINE void google_protobuf_UninterpretedOption_clear_identifier_value(google_protobuf_UninterpretedOption* msg) { const upb_MiniTableField field = {3, UPB_SIZE(8, 16), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_UninterpretedOption_identifier_value(const google_protobuf_UninterpretedOption* msg) { upb_StringView default_val = upb_StringView_FromString(""); @@ -9583,7 +9592,7 @@ UPB_INLINE bool google_protobuf_UninterpretedOption_has_identifier_value(const g } UPB_INLINE void google_protobuf_UninterpretedOption_clear_positive_int_value(google_protobuf_UninterpretedOption* msg) { const upb_MiniTableField field = {4, UPB_SIZE(16, 32), 2, kUpb_NoSub, 4, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_8Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE uint64_t google_protobuf_UninterpretedOption_positive_int_value(const google_protobuf_UninterpretedOption* msg) { uint64_t default_val = (uint64_t)0ull; @@ -9599,7 +9608,7 @@ UPB_INLINE bool google_protobuf_UninterpretedOption_has_positive_int_value(const } UPB_INLINE void google_protobuf_UninterpretedOption_clear_negative_int_value(google_protobuf_UninterpretedOption* msg) { const upb_MiniTableField field = {5, UPB_SIZE(24, 40), 3, kUpb_NoSub, 3, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_8Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE int64_t google_protobuf_UninterpretedOption_negative_int_value(const google_protobuf_UninterpretedOption* msg) { int64_t default_val = (int64_t)0ll; @@ -9615,7 +9624,7 @@ UPB_INLINE bool google_protobuf_UninterpretedOption_has_negative_int_value(const } UPB_INLINE void google_protobuf_UninterpretedOption_clear_double_value(google_protobuf_UninterpretedOption* msg) { const upb_MiniTableField field = {6, UPB_SIZE(32, 48), 4, kUpb_NoSub, 1, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_8Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE double google_protobuf_UninterpretedOption_double_value(const google_protobuf_UninterpretedOption* msg) { double default_val = 0; @@ -9631,7 +9640,7 @@ UPB_INLINE bool google_protobuf_UninterpretedOption_has_double_value(const googl } UPB_INLINE void google_protobuf_UninterpretedOption_clear_string_value(google_protobuf_UninterpretedOption* msg) { const upb_MiniTableField field = {7, UPB_SIZE(40, 56), 5, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_UninterpretedOption_string_value(const google_protobuf_UninterpretedOption* msg) { upb_StringView default_val = upb_StringView_FromString(""); @@ -9647,7 +9656,7 @@ UPB_INLINE bool google_protobuf_UninterpretedOption_has_string_value(const googl } UPB_INLINE void google_protobuf_UninterpretedOption_clear_aggregate_value(google_protobuf_UninterpretedOption* msg) { const upb_MiniTableField field = {8, UPB_SIZE(48, 72), 6, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_UninterpretedOption_aggregate_value(const google_protobuf_UninterpretedOption* msg) { upb_StringView default_val = upb_StringView_FromString(""); @@ -9755,7 +9764,7 @@ UPB_INLINE char* google_protobuf_UninterpretedOption_NamePart_serialize_ex(const } UPB_INLINE void google_protobuf_UninterpretedOption_NamePart_clear_name_part(google_protobuf_UninterpretedOption_NamePart* msg) { const upb_MiniTableField field = {1, UPB_SIZE(4, 8), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_UninterpretedOption_NamePart_name_part(const google_protobuf_UninterpretedOption_NamePart* msg) { upb_StringView default_val = upb_StringView_FromString(""); @@ -9771,7 +9780,7 @@ UPB_INLINE bool google_protobuf_UninterpretedOption_NamePart_has_name_part(const } UPB_INLINE void google_protobuf_UninterpretedOption_NamePart_clear_is_extension(google_protobuf_UninterpretedOption_NamePart* msg) { const upb_MiniTableField field = {2, 1, 2, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_UninterpretedOption_NamePart_is_extension(const google_protobuf_UninterpretedOption_NamePart* msg) { bool default_val = false; @@ -9833,7 +9842,7 @@ UPB_INLINE char* google_protobuf_FeatureSet_serialize_ex(const google_protobuf_F } UPB_INLINE void google_protobuf_FeatureSet_clear_field_presence(google_protobuf_FeatureSet* msg) { const upb_MiniTableField field = {1, 4, 1, 0, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_FeatureSet_field_presence(const google_protobuf_FeatureSet* msg) { int32_t default_val = 0; @@ -9849,7 +9858,7 @@ UPB_INLINE bool google_protobuf_FeatureSet_has_field_presence(const google_proto } UPB_INLINE void google_protobuf_FeatureSet_clear_enum_type(google_protobuf_FeatureSet* msg) { const upb_MiniTableField field = {2, 8, 2, 1, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_FeatureSet_enum_type(const google_protobuf_FeatureSet* msg) { int32_t default_val = 0; @@ -9865,7 +9874,7 @@ UPB_INLINE bool google_protobuf_FeatureSet_has_enum_type(const google_protobuf_F } UPB_INLINE void google_protobuf_FeatureSet_clear_repeated_field_encoding(google_protobuf_FeatureSet* msg) { const upb_MiniTableField field = {3, 12, 3, 2, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_FeatureSet_repeated_field_encoding(const google_protobuf_FeatureSet* msg) { int32_t default_val = 0; @@ -9881,7 +9890,7 @@ UPB_INLINE bool google_protobuf_FeatureSet_has_repeated_field_encoding(const goo } UPB_INLINE void google_protobuf_FeatureSet_clear_utf8_validation(google_protobuf_FeatureSet* msg) { const upb_MiniTableField field = {4, 16, 4, 3, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_FeatureSet_utf8_validation(const google_protobuf_FeatureSet* msg) { int32_t default_val = 0; @@ -9897,7 +9906,7 @@ UPB_INLINE bool google_protobuf_FeatureSet_has_utf8_validation(const google_prot } UPB_INLINE void google_protobuf_FeatureSet_clear_message_encoding(google_protobuf_FeatureSet* msg) { const upb_MiniTableField field = {5, 20, 5, 4, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_FeatureSet_message_encoding(const google_protobuf_FeatureSet* msg) { int32_t default_val = 0; @@ -9913,7 +9922,7 @@ UPB_INLINE bool google_protobuf_FeatureSet_has_message_encoding(const google_pro } UPB_INLINE void google_protobuf_FeatureSet_clear_json_format(google_protobuf_FeatureSet* msg) { const upb_MiniTableField field = {6, 24, 6, 5, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_FeatureSet_json_format(const google_protobuf_FeatureSet* msg) { int32_t default_val = 0; @@ -9991,7 +10000,7 @@ UPB_INLINE char* google_protobuf_FeatureSetDefaults_serialize_ex(const google_pr } UPB_INLINE void google_protobuf_FeatureSetDefaults_clear_defaults(google_protobuf_FeatureSetDefaults* msg) { const upb_MiniTableField field = {1, UPB_SIZE(4, 16), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* const* google_protobuf_FeatureSetDefaults_defaults(const google_protobuf_FeatureSetDefaults* msg, size_t* size) { const upb_MiniTableField field = {1, UPB_SIZE(4, 16), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -10023,7 +10032,7 @@ UPB_INLINE upb_Array* _google_protobuf_FeatureSetDefaults_defaults_mutable_upb_a } UPB_INLINE void google_protobuf_FeatureSetDefaults_clear_minimum_edition(google_protobuf_FeatureSetDefaults* msg) { const upb_MiniTableField field = {4, UPB_SIZE(8, 4), 1, 1, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_FeatureSetDefaults_minimum_edition(const google_protobuf_FeatureSetDefaults* msg) { int32_t default_val = 0; @@ -10039,7 +10048,7 @@ UPB_INLINE bool google_protobuf_FeatureSetDefaults_has_minimum_edition(const goo } UPB_INLINE void google_protobuf_FeatureSetDefaults_clear_maximum_edition(google_protobuf_FeatureSetDefaults* msg) { const upb_MiniTableField field = {5, UPB_SIZE(12, 8), 2, 2, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_FeatureSetDefaults_maximum_edition(const google_protobuf_FeatureSetDefaults* msg) { int32_t default_val = 0; @@ -10131,7 +10140,7 @@ UPB_INLINE char* google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_ser } UPB_INLINE void google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_clear_features(google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* msg) { const upb_MiniTableField field = {2, UPB_SIZE(4, 8), 1, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_FeatureSet* google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_features(const google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* msg) { const google_protobuf_FeatureSet* default_val = NULL; @@ -10147,7 +10156,7 @@ UPB_INLINE bool google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_has_ } UPB_INLINE void google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_clear_edition(google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* msg) { const upb_MiniTableField field = {3, UPB_SIZE(8, 4), 2, 1, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_edition(const google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* msg) { int32_t default_val = 0; @@ -10217,7 +10226,7 @@ UPB_INLINE char* google_protobuf_SourceCodeInfo_serialize_ex(const google_protob } UPB_INLINE void google_protobuf_SourceCodeInfo_clear_location(google_protobuf_SourceCodeInfo* msg) { const upb_MiniTableField field = {1, 0, 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_SourceCodeInfo_Location* const* google_protobuf_SourceCodeInfo_location(const google_protobuf_SourceCodeInfo* msg, size_t* size) { const upb_MiniTableField field = {1, 0, 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -10317,7 +10326,7 @@ UPB_INLINE char* google_protobuf_SourceCodeInfo_Location_serialize_ex(const goog } UPB_INLINE void google_protobuf_SourceCodeInfo_Location_clear_path(google_protobuf_SourceCodeInfo_Location* msg) { const upb_MiniTableField field = {1, UPB_SIZE(4, 8), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsPacked | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t const* google_protobuf_SourceCodeInfo_Location_path(const google_protobuf_SourceCodeInfo_Location* msg, size_t* size) { const upb_MiniTableField field = {1, UPB_SIZE(4, 8), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsPacked | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -10349,7 +10358,7 @@ UPB_INLINE upb_Array* _google_protobuf_SourceCodeInfo_Location_path_mutable_upb_ } UPB_INLINE void google_protobuf_SourceCodeInfo_Location_clear_span(google_protobuf_SourceCodeInfo_Location* msg) { const upb_MiniTableField field = {2, UPB_SIZE(8, 16), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsPacked | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t const* google_protobuf_SourceCodeInfo_Location_span(const google_protobuf_SourceCodeInfo_Location* msg, size_t* size) { const upb_MiniTableField field = {2, UPB_SIZE(8, 16), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsPacked | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -10381,7 +10390,7 @@ UPB_INLINE upb_Array* _google_protobuf_SourceCodeInfo_Location_span_mutable_upb_ } UPB_INLINE void google_protobuf_SourceCodeInfo_Location_clear_leading_comments(google_protobuf_SourceCodeInfo_Location* msg) { const upb_MiniTableField field = {3, UPB_SIZE(16, 24), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_SourceCodeInfo_Location_leading_comments(const google_protobuf_SourceCodeInfo_Location* msg) { upb_StringView default_val = upb_StringView_FromString(""); @@ -10397,7 +10406,7 @@ UPB_INLINE bool google_protobuf_SourceCodeInfo_Location_has_leading_comments(con } UPB_INLINE void google_protobuf_SourceCodeInfo_Location_clear_trailing_comments(google_protobuf_SourceCodeInfo_Location* msg) { const upb_MiniTableField field = {4, UPB_SIZE(24, 40), 2, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_SourceCodeInfo_Location_trailing_comments(const google_protobuf_SourceCodeInfo_Location* msg) { upb_StringView default_val = upb_StringView_FromString(""); @@ -10413,7 +10422,7 @@ UPB_INLINE bool google_protobuf_SourceCodeInfo_Location_has_trailing_comments(co } UPB_INLINE void google_protobuf_SourceCodeInfo_Location_clear_leading_detached_comments(google_protobuf_SourceCodeInfo_Location* msg) { const upb_MiniTableField field = {6, UPB_SIZE(12, 56), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView const* google_protobuf_SourceCodeInfo_Location_leading_detached_comments(const google_protobuf_SourceCodeInfo_Location* msg, size_t* size) { const upb_MiniTableField field = {6, UPB_SIZE(12, 56), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -10575,7 +10584,7 @@ UPB_INLINE char* google_protobuf_GeneratedCodeInfo_serialize_ex(const google_pro } UPB_INLINE void google_protobuf_GeneratedCodeInfo_clear_annotation(google_protobuf_GeneratedCodeInfo* msg) { const upb_MiniTableField field = {1, 0, 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_GeneratedCodeInfo_Annotation* const* google_protobuf_GeneratedCodeInfo_annotation(const google_protobuf_GeneratedCodeInfo* msg, size_t* size) { const upb_MiniTableField field = {1, 0, 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -10675,7 +10684,7 @@ UPB_INLINE char* google_protobuf_GeneratedCodeInfo_Annotation_serialize_ex(const } UPB_INLINE void google_protobuf_GeneratedCodeInfo_Annotation_clear_path(google_protobuf_GeneratedCodeInfo_Annotation* msg) { const upb_MiniTableField field = {1, UPB_SIZE(4, 16), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsPacked | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t const* google_protobuf_GeneratedCodeInfo_Annotation_path(const google_protobuf_GeneratedCodeInfo_Annotation* msg, size_t* size) { const upb_MiniTableField field = {1, UPB_SIZE(4, 16), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsPacked | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -10707,7 +10716,7 @@ UPB_INLINE upb_Array* _google_protobuf_GeneratedCodeInfo_Annotation_path_mutable } UPB_INLINE void google_protobuf_GeneratedCodeInfo_Annotation_clear_source_file(google_protobuf_GeneratedCodeInfo_Annotation* msg) { const upb_MiniTableField field = {2, UPB_SIZE(20, 24), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_GeneratedCodeInfo_Annotation_source_file(const google_protobuf_GeneratedCodeInfo_Annotation* msg) { upb_StringView default_val = upb_StringView_FromString(""); @@ -10723,7 +10732,7 @@ UPB_INLINE bool google_protobuf_GeneratedCodeInfo_Annotation_has_source_file(con } UPB_INLINE void google_protobuf_GeneratedCodeInfo_Annotation_clear_begin(google_protobuf_GeneratedCodeInfo_Annotation* msg) { const upb_MiniTableField field = {3, UPB_SIZE(8, 4), 2, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_GeneratedCodeInfo_Annotation_begin(const google_protobuf_GeneratedCodeInfo_Annotation* msg) { int32_t default_val = (int32_t)0; @@ -10739,7 +10748,7 @@ UPB_INLINE bool google_protobuf_GeneratedCodeInfo_Annotation_has_begin(const goo } UPB_INLINE void google_protobuf_GeneratedCodeInfo_Annotation_clear_end(google_protobuf_GeneratedCodeInfo_Annotation* msg) { const upb_MiniTableField field = {4, UPB_SIZE(12, 8), 3, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_GeneratedCodeInfo_Annotation_end(const google_protobuf_GeneratedCodeInfo_Annotation* msg) { int32_t default_val = (int32_t)0; @@ -10755,7 +10764,7 @@ UPB_INLINE bool google_protobuf_GeneratedCodeInfo_Annotation_has_end(const googl } UPB_INLINE void google_protobuf_GeneratedCodeInfo_Annotation_clear_semantic(google_protobuf_GeneratedCodeInfo_Annotation* msg) { const upb_MiniTableField field = {5, UPB_SIZE(16, 12), 4, 0, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_GeneratedCodeInfo_Annotation_semantic(const google_protobuf_GeneratedCodeInfo_Annotation* msg) { int32_t default_val = 0; @@ -11095,6 +11104,8 @@ const UPB_DESC(FeatureSet) * #ifndef UPB_REFLECTION_FIELD_DEF_H_ #define UPB_REFLECTION_FIELD_DEF_H_ +#include + // Must be last. @@ -11140,6 +11151,8 @@ bool upb_FieldDef_MiniDescriptorEncode(const upb_FieldDef* f, upb_Arena* a, upb_StringView* out); const upb_MiniTableField* upb_FieldDef_MiniTable(const upb_FieldDef* f); +const upb_MiniTableExtension* upb_FieldDef_MiniTableExtension( + const upb_FieldDef* f); UPB_API const char* upb_FieldDef_Name(const upb_FieldDef* f); UPB_API uint32_t upb_FieldDef_Number(const upb_FieldDef* f); const UPB_DESC(FieldOptions) * upb_FieldDef_Options(const upb_FieldDef* f); @@ -13692,8 +13705,6 @@ extern "C" { upb_FieldDef* _upb_FieldDef_At(const upb_FieldDef* f, int i); -const upb_MiniTableExtension* _upb_FieldDef_ExtensionMiniTable( - const upb_FieldDef* f); bool _upb_FieldDef_IsClosedEnum(const upb_FieldDef* f); bool _upb_FieldDef_IsProto3Optional(const upb_FieldDef* f); int _upb_FieldDef_LayoutIndex(const upb_FieldDef* f); diff --git a/ruby/ext/google/protobuf_c/ruby-upb.c b/ruby/ext/google/protobuf_c/ruby-upb.c index 8c0bf0b7d6bfb..a859cd521c0c4 100644 --- a/ruby/ext/google/protobuf_c/ruby-upb.c +++ b/ruby/ext/google/protobuf_c/ruby-upb.c @@ -12458,7 +12458,7 @@ const upb_MiniTableField* upb_FieldDef_MiniTable(const upb_FieldDef* f) { } } -const upb_MiniTableExtension* _upb_FieldDef_ExtensionMiniTable( +const upb_MiniTableExtension* upb_FieldDef_MiniTableExtension( const upb_FieldDef* f) { UPB_ASSERT(upb_FieldDef_IsExtension(f)); const upb_FileDef* file = upb_FieldDef_File(f); @@ -12952,7 +12952,7 @@ static void _upb_FieldDef_CreateExt(upb_DefBuilder* ctx, const char* prefix, if (ctx->layout) { UPB_ASSERT(upb_MiniTableExtension_Number( - _upb_FieldDef_ExtensionMiniTable(f)) == f->number_); + upb_FieldDef_MiniTableExtension(f)) == f->number_); } } @@ -13144,7 +13144,7 @@ static void resolve_extension(upb_DefBuilder* ctx, const char* prefix, void _upb_FieldDef_BuildMiniTableExtension(upb_DefBuilder* ctx, const upb_FieldDef* f) { - const upb_MiniTableExtension* ext = _upb_FieldDef_ExtensionMiniTable(f); + const upb_MiniTableExtension* ext = upb_FieldDef_MiniTableExtension(f); if (ctx->layout) { UPB_ASSERT(upb_FieldDef_Number(f) == upb_MiniTableExtension_Number(ext)); @@ -14130,7 +14130,13 @@ bool upb_Message_SetFieldByDef(upb_Message* msg, const upb_FieldDef* f, } void upb_Message_ClearFieldByDef(upb_Message* msg, const upb_FieldDef* f) { - upb_Message_ClearField(msg, upb_FieldDef_MiniTable(f)); + const upb_MiniTableField* m_f = upb_FieldDef_MiniTable(f); + + if (upb_MiniTableField_IsExtension(m_f)) { + upb_Message_ClearExtension(msg, (const upb_MiniTableExtension*)m_f); + } else { + upb_Message_ClearBaseField(msg, m_f); + } } void upb_Message_ClearByDef(upb_Message* msg, const upb_MessageDef* m) { diff --git a/ruby/ext/google/protobuf_c/ruby-upb.h b/ruby/ext/google/protobuf_c/ruby-upb.h index d6f1f7ddff54c..4e7f0a31c9fdd 100755 --- a/ruby/ext/google/protobuf_c/ruby-upb.h +++ b/ruby/ext/google/protobuf_c/ruby-upb.h @@ -2753,31 +2753,34 @@ UPB_INLINE bool _upb_Message_SetExtensionField( return true; } -UPB_INLINE void _upb_Message_ClearExtensionField( - struct upb_Message* msg, const upb_MiniTableExtension* ext_l) { +UPB_INLINE void UPB_PRIVATE(_upb_Message_ClearBaseField)( + struct upb_Message* msg, const upb_MiniTableField* f) { + if (UPB_PRIVATE(_upb_MiniTableField_HasHasbit)(f)) { + UPB_PRIVATE(_upb_Message_ClearHasbit)(msg, f); + } else if (upb_MiniTableField_IsInOneof(f)) { + uint32_t* ptr = UPB_PRIVATE(_upb_Message_OneofCasePtr)(msg, f); + if (*ptr != upb_MiniTableField_Number(f)) return; + *ptr = 0; + } + const char zeros[16] = {0}; + UPB_PRIVATE(_upb_MiniTableField_DataCopy) + (f, UPB_PRIVATE(_upb_Message_DataPtr)(msg, f), zeros); +} + +UPB_INLINE void UPB_PRIVATE(_upb_Message_ClearExtension)( + struct upb_Message* msg, const upb_MiniTableExtension* e) { upb_Message_InternalData* in = upb_Message_GetInternalData(msg); if (!in) return; const struct upb_Extension* base = UPB_PTR_AT(in, in->ext_begin, struct upb_Extension); struct upb_Extension* ext = - (struct upb_Extension*)_upb_Message_Getext(msg, ext_l); + (struct upb_Extension*)_upb_Message_Getext(msg, e); if (ext) { *ext = *base; in->ext_begin += sizeof(struct upb_Extension); } } -UPB_INLINE void _upb_Message_ClearNonExtensionField( - struct upb_Message* msg, const upb_MiniTableField* f) { - if (UPB_PRIVATE(_upb_MiniTableField_HasHasbit)(f)) { - UPB_PRIVATE(_upb_Message_ClearHasbit)(msg, f); - } else if (upb_MiniTableField_IsInOneof(f)) { - if (!UPB_PRIVATE(_upb_Message_ClearOneofCase)(msg, f)) return; - } - void* data = UPB_PRIVATE(_upb_Message_DataPtr)(msg, f); - UPB_PRIVATE(_upb_MiniTableField_DataClear)(f, data); -} - UPB_INLINE void _upb_Message_AssertMapIsUntagged( const struct upb_Message* msg, const upb_MiniTableField* field) { UPB_UNUSED(msg); @@ -3054,21 +3057,27 @@ UPB_API_INLINE const upb_MiniTable* upb_MiniTableSub_Message( extern "C" { #endif -UPB_API_INLINE void upb_Message_ClearField(upb_Message* msg, - const upb_MiniTableField* field) { - if (upb_MiniTableField_IsExtension(field)) { - const upb_MiniTableExtension* ext = (const upb_MiniTableExtension*)field; - _upb_Message_ClearExtensionField(msg, ext); - } else { - _upb_Message_ClearNonExtensionField(msg, field); - } -} +// Functions ending in BaseField() take a (upb_MiniTableField*) argument +// and work only on non-extension fields. +// +// Functions ending in Extension() take a (upb_MiniTableExtension*) argument +// and work only on extensions. UPB_API_INLINE void upb_Message_Clear(upb_Message* msg, - const upb_MiniTable* l) { + const upb_MiniTable* m) { // Note: Can't use UPB_PTR_AT() here because we are doing pointer subtraction. char* mem = (char*)msg - sizeof(upb_Message_Internal); - memset(mem, 0, upb_msg_sizeof(l)); + memset(mem, 0, upb_msg_sizeof(m)); +} + +UPB_API_INLINE void upb_Message_ClearBaseField(upb_Message* msg, + const upb_MiniTableField* f) { + UPB_PRIVATE(_upb_Message_ClearBaseField)(msg, f); +} + +UPB_API_INLINE void upb_Message_ClearExtension( + upb_Message* msg, const upb_MiniTableExtension* e) { + UPB_PRIVATE(_upb_Message_ClearExtension)(msg, e); } UPB_API_INLINE bool upb_Message_HasField(const upb_Message* msg, @@ -4959,7 +4968,7 @@ UPB_INLINE char* google_protobuf_FileDescriptorSet_serialize_ex(const google_pro } UPB_INLINE void google_protobuf_FileDescriptorSet_clear_file(google_protobuf_FileDescriptorSet* msg) { const upb_MiniTableField field = {1, 0, 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_FileDescriptorProto* const* google_protobuf_FileDescriptorSet_file(const google_protobuf_FileDescriptorSet* msg, size_t* size) { const upb_MiniTableField field = {1, 0, 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -5059,7 +5068,7 @@ UPB_INLINE char* google_protobuf_FileDescriptorProto_serialize_ex(const google_p } UPB_INLINE void google_protobuf_FileDescriptorProto_clear_name(google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = {1, UPB_SIZE(44, 8), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_FileDescriptorProto_name(const google_protobuf_FileDescriptorProto* msg) { upb_StringView default_val = upb_StringView_FromString(""); @@ -5075,7 +5084,7 @@ UPB_INLINE bool google_protobuf_FileDescriptorProto_has_name(const google_protob } UPB_INLINE void google_protobuf_FileDescriptorProto_clear_package(google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = {2, UPB_SIZE(52, 24), 2, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_FileDescriptorProto_package(const google_protobuf_FileDescriptorProto* msg) { upb_StringView default_val = upb_StringView_FromString(""); @@ -5091,7 +5100,7 @@ UPB_INLINE bool google_protobuf_FileDescriptorProto_has_package(const google_pro } UPB_INLINE void google_protobuf_FileDescriptorProto_clear_dependency(google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = {3, UPB_SIZE(4, 40), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView const* google_protobuf_FileDescriptorProto_dependency(const google_protobuf_FileDescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {3, UPB_SIZE(4, 40), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -5123,7 +5132,7 @@ UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_dependency_mutable_up } UPB_INLINE void google_protobuf_FileDescriptorProto_clear_message_type(google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = {4, UPB_SIZE(8, 48), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_DescriptorProto* const* google_protobuf_FileDescriptorProto_message_type(const google_protobuf_FileDescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {4, UPB_SIZE(8, 48), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -5155,7 +5164,7 @@ UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_message_type_mutable_ } UPB_INLINE void google_protobuf_FileDescriptorProto_clear_enum_type(google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = {5, UPB_SIZE(12, 56), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_EnumDescriptorProto* const* google_protobuf_FileDescriptorProto_enum_type(const google_protobuf_FileDescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {5, UPB_SIZE(12, 56), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -5187,7 +5196,7 @@ UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_enum_type_mutable_upb } UPB_INLINE void google_protobuf_FileDescriptorProto_clear_service(google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = {6, UPB_SIZE(16, 64), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_ServiceDescriptorProto* const* google_protobuf_FileDescriptorProto_service(const google_protobuf_FileDescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {6, UPB_SIZE(16, 64), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -5219,7 +5228,7 @@ UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_service_mutable_upb_a } UPB_INLINE void google_protobuf_FileDescriptorProto_clear_extension(google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = {7, UPB_SIZE(20, 72), 0, 3, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_FieldDescriptorProto* const* google_protobuf_FileDescriptorProto_extension(const google_protobuf_FileDescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {7, UPB_SIZE(20, 72), 0, 3, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -5251,7 +5260,7 @@ UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_extension_mutable_upb } UPB_INLINE void google_protobuf_FileDescriptorProto_clear_options(google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = {8, UPB_SIZE(24, 80), 3, 4, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_FileOptions* google_protobuf_FileDescriptorProto_options(const google_protobuf_FileDescriptorProto* msg) { const google_protobuf_FileOptions* default_val = NULL; @@ -5267,7 +5276,7 @@ UPB_INLINE bool google_protobuf_FileDescriptorProto_has_options(const google_pro } UPB_INLINE void google_protobuf_FileDescriptorProto_clear_source_code_info(google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = {9, UPB_SIZE(28, 88), 4, 5, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_SourceCodeInfo* google_protobuf_FileDescriptorProto_source_code_info(const google_protobuf_FileDescriptorProto* msg) { const google_protobuf_SourceCodeInfo* default_val = NULL; @@ -5283,7 +5292,7 @@ UPB_INLINE bool google_protobuf_FileDescriptorProto_has_source_code_info(const g } UPB_INLINE void google_protobuf_FileDescriptorProto_clear_public_dependency(google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = {10, UPB_SIZE(32, 96), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t const* google_protobuf_FileDescriptorProto_public_dependency(const google_protobuf_FileDescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {10, UPB_SIZE(32, 96), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -5315,7 +5324,7 @@ UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_public_dependency_mut } UPB_INLINE void google_protobuf_FileDescriptorProto_clear_weak_dependency(google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = {11, UPB_SIZE(36, 104), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t const* google_protobuf_FileDescriptorProto_weak_dependency(const google_protobuf_FileDescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {11, UPB_SIZE(36, 104), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -5347,7 +5356,7 @@ UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_weak_dependency_mutab } UPB_INLINE void google_protobuf_FileDescriptorProto_clear_syntax(google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = {12, UPB_SIZE(60, 112), 5, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_FileDescriptorProto_syntax(const google_protobuf_FileDescriptorProto* msg) { upb_StringView default_val = upb_StringView_FromString(""); @@ -5363,7 +5372,7 @@ UPB_INLINE bool google_protobuf_FileDescriptorProto_has_syntax(const google_prot } UPB_INLINE void google_protobuf_FileDescriptorProto_clear_edition(google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = {14, UPB_SIZE(40, 4), 6, 6, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_FileDescriptorProto_edition(const google_protobuf_FileDescriptorProto* msg) { int32_t default_val = 0; @@ -5661,7 +5670,7 @@ UPB_INLINE char* google_protobuf_DescriptorProto_serialize_ex(const google_proto } UPB_INLINE void google_protobuf_DescriptorProto_clear_name(google_protobuf_DescriptorProto* msg) { const upb_MiniTableField field = {1, UPB_SIZE(40, 8), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_DescriptorProto_name(const google_protobuf_DescriptorProto* msg) { upb_StringView default_val = upb_StringView_FromString(""); @@ -5677,7 +5686,7 @@ UPB_INLINE bool google_protobuf_DescriptorProto_has_name(const google_protobuf_D } UPB_INLINE void google_protobuf_DescriptorProto_clear_field(google_protobuf_DescriptorProto* msg) { const upb_MiniTableField field = {2, UPB_SIZE(4, 24), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_FieldDescriptorProto* const* google_protobuf_DescriptorProto_field(const google_protobuf_DescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {2, UPB_SIZE(4, 24), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -5709,7 +5718,7 @@ UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_field_mutable_upb_array(g } UPB_INLINE void google_protobuf_DescriptorProto_clear_nested_type(google_protobuf_DescriptorProto* msg) { const upb_MiniTableField field = {3, UPB_SIZE(8, 32), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_DescriptorProto* const* google_protobuf_DescriptorProto_nested_type(const google_protobuf_DescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {3, UPB_SIZE(8, 32), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -5741,7 +5750,7 @@ UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_nested_type_mutable_upb_a } UPB_INLINE void google_protobuf_DescriptorProto_clear_enum_type(google_protobuf_DescriptorProto* msg) { const upb_MiniTableField field = {4, UPB_SIZE(12, 40), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_EnumDescriptorProto* const* google_protobuf_DescriptorProto_enum_type(const google_protobuf_DescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {4, UPB_SIZE(12, 40), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -5773,7 +5782,7 @@ UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_enum_type_mutable_upb_arr } UPB_INLINE void google_protobuf_DescriptorProto_clear_extension_range(google_protobuf_DescriptorProto* msg) { const upb_MiniTableField field = {5, UPB_SIZE(16, 48), 0, 3, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_DescriptorProto_ExtensionRange* const* google_protobuf_DescriptorProto_extension_range(const google_protobuf_DescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {5, UPB_SIZE(16, 48), 0, 3, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -5805,7 +5814,7 @@ UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_extension_range_mutable_u } UPB_INLINE void google_protobuf_DescriptorProto_clear_extension(google_protobuf_DescriptorProto* msg) { const upb_MiniTableField field = {6, UPB_SIZE(20, 56), 0, 4, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_FieldDescriptorProto* const* google_protobuf_DescriptorProto_extension(const google_protobuf_DescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {6, UPB_SIZE(20, 56), 0, 4, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -5837,7 +5846,7 @@ UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_extension_mutable_upb_arr } UPB_INLINE void google_protobuf_DescriptorProto_clear_options(google_protobuf_DescriptorProto* msg) { const upb_MiniTableField field = {7, UPB_SIZE(24, 64), 2, 5, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_MessageOptions* google_protobuf_DescriptorProto_options(const google_protobuf_DescriptorProto* msg) { const google_protobuf_MessageOptions* default_val = NULL; @@ -5853,7 +5862,7 @@ UPB_INLINE bool google_protobuf_DescriptorProto_has_options(const google_protobu } UPB_INLINE void google_protobuf_DescriptorProto_clear_oneof_decl(google_protobuf_DescriptorProto* msg) { const upb_MiniTableField field = {8, UPB_SIZE(28, 72), 0, 6, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_OneofDescriptorProto* const* google_protobuf_DescriptorProto_oneof_decl(const google_protobuf_DescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {8, UPB_SIZE(28, 72), 0, 6, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -5885,7 +5894,7 @@ UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_oneof_decl_mutable_upb_ar } UPB_INLINE void google_protobuf_DescriptorProto_clear_reserved_range(google_protobuf_DescriptorProto* msg) { const upb_MiniTableField field = {9, UPB_SIZE(32, 80), 0, 7, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_DescriptorProto_ReservedRange* const* google_protobuf_DescriptorProto_reserved_range(const google_protobuf_DescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {9, UPB_SIZE(32, 80), 0, 7, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -5917,7 +5926,7 @@ UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_reserved_range_mutable_up } UPB_INLINE void google_protobuf_DescriptorProto_clear_reserved_name(google_protobuf_DescriptorProto* msg) { const upb_MiniTableField field = {10, UPB_SIZE(36, 88), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView const* google_protobuf_DescriptorProto_reserved_name(const google_protobuf_DescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {10, UPB_SIZE(36, 88), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -6241,7 +6250,7 @@ UPB_INLINE char* google_protobuf_DescriptorProto_ExtensionRange_serialize_ex(con } UPB_INLINE void google_protobuf_DescriptorProto_ExtensionRange_clear_start(google_protobuf_DescriptorProto_ExtensionRange* msg) { const upb_MiniTableField field = {1, 4, 1, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_DescriptorProto_ExtensionRange_start(const google_protobuf_DescriptorProto_ExtensionRange* msg) { int32_t default_val = (int32_t)0; @@ -6257,7 +6266,7 @@ UPB_INLINE bool google_protobuf_DescriptorProto_ExtensionRange_has_start(const g } UPB_INLINE void google_protobuf_DescriptorProto_ExtensionRange_clear_end(google_protobuf_DescriptorProto_ExtensionRange* msg) { const upb_MiniTableField field = {2, 8, 2, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_DescriptorProto_ExtensionRange_end(const google_protobuf_DescriptorProto_ExtensionRange* msg) { int32_t default_val = (int32_t)0; @@ -6273,7 +6282,7 @@ UPB_INLINE bool google_protobuf_DescriptorProto_ExtensionRange_has_end(const goo } UPB_INLINE void google_protobuf_DescriptorProto_ExtensionRange_clear_options(google_protobuf_DescriptorProto_ExtensionRange* msg) { const upb_MiniTableField field = {3, UPB_SIZE(12, 16), 3, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_ExtensionRangeOptions* google_protobuf_DescriptorProto_ExtensionRange_options(const google_protobuf_DescriptorProto_ExtensionRange* msg) { const google_protobuf_ExtensionRangeOptions* default_val = NULL; @@ -6347,7 +6356,7 @@ UPB_INLINE char* google_protobuf_DescriptorProto_ReservedRange_serialize_ex(cons } UPB_INLINE void google_protobuf_DescriptorProto_ReservedRange_clear_start(google_protobuf_DescriptorProto_ReservedRange* msg) { const upb_MiniTableField field = {1, 4, 1, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_DescriptorProto_ReservedRange_start(const google_protobuf_DescriptorProto_ReservedRange* msg) { int32_t default_val = (int32_t)0; @@ -6363,7 +6372,7 @@ UPB_INLINE bool google_protobuf_DescriptorProto_ReservedRange_has_start(const go } UPB_INLINE void google_protobuf_DescriptorProto_ReservedRange_clear_end(google_protobuf_DescriptorProto_ReservedRange* msg) { const upb_MiniTableField field = {2, 8, 2, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_DescriptorProto_ReservedRange_end(const google_protobuf_DescriptorProto_ReservedRange* msg) { int32_t default_val = (int32_t)0; @@ -6425,7 +6434,7 @@ UPB_INLINE char* google_protobuf_ExtensionRangeOptions_serialize_ex(const google } UPB_INLINE void google_protobuf_ExtensionRangeOptions_clear_declaration(google_protobuf_ExtensionRangeOptions* msg) { const upb_MiniTableField field = {2, UPB_SIZE(4, 8), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_ExtensionRangeOptions_Declaration* const* google_protobuf_ExtensionRangeOptions_declaration(const google_protobuf_ExtensionRangeOptions* msg, size_t* size) { const upb_MiniTableField field = {2, UPB_SIZE(4, 8), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -6457,7 +6466,7 @@ UPB_INLINE upb_Array* _google_protobuf_ExtensionRangeOptions_declaration_mutable } UPB_INLINE void google_protobuf_ExtensionRangeOptions_clear_verification(google_protobuf_ExtensionRangeOptions* msg) { const upb_MiniTableField field = {3, UPB_SIZE(8, 4), 1, 3, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_ExtensionRangeOptions_verification(const google_protobuf_ExtensionRangeOptions* msg) { int32_t default_val = 1; @@ -6473,7 +6482,7 @@ UPB_INLINE bool google_protobuf_ExtensionRangeOptions_has_verification(const goo } UPB_INLINE void google_protobuf_ExtensionRangeOptions_clear_features(google_protobuf_ExtensionRangeOptions* msg) { const upb_MiniTableField field = {50, UPB_SIZE(12, 16), 2, 1, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_FeatureSet* google_protobuf_ExtensionRangeOptions_features(const google_protobuf_ExtensionRangeOptions* msg) { const google_protobuf_FeatureSet* default_val = NULL; @@ -6489,7 +6498,7 @@ UPB_INLINE bool google_protobuf_ExtensionRangeOptions_has_features(const google_ } UPB_INLINE void google_protobuf_ExtensionRangeOptions_clear_uninterpreted_option(google_protobuf_ExtensionRangeOptions* msg) { const upb_MiniTableField field = {999, UPB_SIZE(16, 24), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_ExtensionRangeOptions_uninterpreted_option(const google_protobuf_ExtensionRangeOptions* msg, size_t* size) { const upb_MiniTableField field = {999, UPB_SIZE(16, 24), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -6635,7 +6644,7 @@ UPB_INLINE char* google_protobuf_ExtensionRangeOptions_Declaration_serialize_ex( } UPB_INLINE void google_protobuf_ExtensionRangeOptions_Declaration_clear_number(google_protobuf_ExtensionRangeOptions_Declaration* msg) { const upb_MiniTableField field = {1, 4, 1, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_ExtensionRangeOptions_Declaration_number(const google_protobuf_ExtensionRangeOptions_Declaration* msg) { int32_t default_val = (int32_t)0; @@ -6651,7 +6660,7 @@ UPB_INLINE bool google_protobuf_ExtensionRangeOptions_Declaration_has_number(con } UPB_INLINE void google_protobuf_ExtensionRangeOptions_Declaration_clear_full_name(google_protobuf_ExtensionRangeOptions_Declaration* msg) { const upb_MiniTableField field = {2, UPB_SIZE(12, 16), 2, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_ExtensionRangeOptions_Declaration_full_name(const google_protobuf_ExtensionRangeOptions_Declaration* msg) { upb_StringView default_val = upb_StringView_FromString(""); @@ -6667,7 +6676,7 @@ UPB_INLINE bool google_protobuf_ExtensionRangeOptions_Declaration_has_full_name( } UPB_INLINE void google_protobuf_ExtensionRangeOptions_Declaration_clear_type(google_protobuf_ExtensionRangeOptions_Declaration* msg) { const upb_MiniTableField field = {3, UPB_SIZE(20, 32), 3, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_ExtensionRangeOptions_Declaration_type(const google_protobuf_ExtensionRangeOptions_Declaration* msg) { upb_StringView default_val = upb_StringView_FromString(""); @@ -6683,7 +6692,7 @@ UPB_INLINE bool google_protobuf_ExtensionRangeOptions_Declaration_has_type(const } UPB_INLINE void google_protobuf_ExtensionRangeOptions_Declaration_clear_reserved(google_protobuf_ExtensionRangeOptions_Declaration* msg) { const upb_MiniTableField field = {5, 8, 4, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_ExtensionRangeOptions_Declaration_reserved(const google_protobuf_ExtensionRangeOptions_Declaration* msg) { bool default_val = false; @@ -6699,7 +6708,7 @@ UPB_INLINE bool google_protobuf_ExtensionRangeOptions_Declaration_has_reserved(c } UPB_INLINE void google_protobuf_ExtensionRangeOptions_Declaration_clear_repeated(google_protobuf_ExtensionRangeOptions_Declaration* msg) { const upb_MiniTableField field = {6, 9, 5, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_ExtensionRangeOptions_Declaration_repeated(const google_protobuf_ExtensionRangeOptions_Declaration* msg) { bool default_val = false; @@ -6773,7 +6782,7 @@ UPB_INLINE char* google_protobuf_FieldDescriptorProto_serialize_ex(const google_ } UPB_INLINE void google_protobuf_FieldDescriptorProto_clear_name(google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = {1, UPB_SIZE(28, 24), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_FieldDescriptorProto_name(const google_protobuf_FieldDescriptorProto* msg) { upb_StringView default_val = upb_StringView_FromString(""); @@ -6789,7 +6798,7 @@ UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_name(const google_proto } UPB_INLINE void google_protobuf_FieldDescriptorProto_clear_extendee(google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = {2, UPB_SIZE(36, 40), 2, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_FieldDescriptorProto_extendee(const google_protobuf_FieldDescriptorProto* msg) { upb_StringView default_val = upb_StringView_FromString(""); @@ -6805,7 +6814,7 @@ UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_extendee(const google_p } UPB_INLINE void google_protobuf_FieldDescriptorProto_clear_number(google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = {3, 4, 3, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_FieldDescriptorProto_number(const google_protobuf_FieldDescriptorProto* msg) { int32_t default_val = (int32_t)0; @@ -6821,7 +6830,7 @@ UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_number(const google_pro } UPB_INLINE void google_protobuf_FieldDescriptorProto_clear_label(google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = {4, 8, 4, 1, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_FieldDescriptorProto_label(const google_protobuf_FieldDescriptorProto* msg) { int32_t default_val = 1; @@ -6837,7 +6846,7 @@ UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_label(const google_prot } UPB_INLINE void google_protobuf_FieldDescriptorProto_clear_type(google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = {5, 12, 5, 2, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_FieldDescriptorProto_type(const google_protobuf_FieldDescriptorProto* msg) { int32_t default_val = 1; @@ -6853,7 +6862,7 @@ UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_type(const google_proto } UPB_INLINE void google_protobuf_FieldDescriptorProto_clear_type_name(google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = {6, UPB_SIZE(44, 56), 6, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_FieldDescriptorProto_type_name(const google_protobuf_FieldDescriptorProto* msg) { upb_StringView default_val = upb_StringView_FromString(""); @@ -6869,7 +6878,7 @@ UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_type_name(const google_ } UPB_INLINE void google_protobuf_FieldDescriptorProto_clear_default_value(google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = {7, UPB_SIZE(52, 72), 7, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_FieldDescriptorProto_default_value(const google_protobuf_FieldDescriptorProto* msg) { upb_StringView default_val = upb_StringView_FromString(""); @@ -6885,7 +6894,7 @@ UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_default_value(const goo } UPB_INLINE void google_protobuf_FieldDescriptorProto_clear_options(google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = {8, UPB_SIZE(16, 88), 8, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_FieldOptions* google_protobuf_FieldDescriptorProto_options(const google_protobuf_FieldDescriptorProto* msg) { const google_protobuf_FieldOptions* default_val = NULL; @@ -6901,7 +6910,7 @@ UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_options(const google_pr } UPB_INLINE void google_protobuf_FieldDescriptorProto_clear_oneof_index(google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = {9, UPB_SIZE(20, 16), 9, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_FieldDescriptorProto_oneof_index(const google_protobuf_FieldDescriptorProto* msg) { int32_t default_val = (int32_t)0; @@ -6917,7 +6926,7 @@ UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_oneof_index(const googl } UPB_INLINE void google_protobuf_FieldDescriptorProto_clear_json_name(google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = {10, UPB_SIZE(60, 96), 10, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_FieldDescriptorProto_json_name(const google_protobuf_FieldDescriptorProto* msg) { upb_StringView default_val = upb_StringView_FromString(""); @@ -6933,7 +6942,7 @@ UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_json_name(const google_ } UPB_INLINE void google_protobuf_FieldDescriptorProto_clear_proto3_optional(google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = {17, UPB_SIZE(24, 20), 11, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_FieldDescriptorProto_proto3_optional(const google_protobuf_FieldDescriptorProto* msg) { bool default_val = false; @@ -7039,7 +7048,7 @@ UPB_INLINE char* google_protobuf_OneofDescriptorProto_serialize_ex(const google_ } UPB_INLINE void google_protobuf_OneofDescriptorProto_clear_name(google_protobuf_OneofDescriptorProto* msg) { const upb_MiniTableField field = {1, 8, 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_OneofDescriptorProto_name(const google_protobuf_OneofDescriptorProto* msg) { upb_StringView default_val = upb_StringView_FromString(""); @@ -7055,7 +7064,7 @@ UPB_INLINE bool google_protobuf_OneofDescriptorProto_has_name(const google_proto } UPB_INLINE void google_protobuf_OneofDescriptorProto_clear_options(google_protobuf_OneofDescriptorProto* msg) { const upb_MiniTableField field = {2, UPB_SIZE(4, 24), 2, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_OneofOptions* google_protobuf_OneofDescriptorProto_options(const google_protobuf_OneofDescriptorProto* msg) { const google_protobuf_OneofOptions* default_val = NULL; @@ -7125,7 +7134,7 @@ UPB_INLINE char* google_protobuf_EnumDescriptorProto_serialize_ex(const google_p } UPB_INLINE void google_protobuf_EnumDescriptorProto_clear_name(google_protobuf_EnumDescriptorProto* msg) { const upb_MiniTableField field = {1, UPB_SIZE(20, 8), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_EnumDescriptorProto_name(const google_protobuf_EnumDescriptorProto* msg) { upb_StringView default_val = upb_StringView_FromString(""); @@ -7141,7 +7150,7 @@ UPB_INLINE bool google_protobuf_EnumDescriptorProto_has_name(const google_protob } UPB_INLINE void google_protobuf_EnumDescriptorProto_clear_value(google_protobuf_EnumDescriptorProto* msg) { const upb_MiniTableField field = {2, UPB_SIZE(4, 24), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_EnumValueDescriptorProto* const* google_protobuf_EnumDescriptorProto_value(const google_protobuf_EnumDescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {2, UPB_SIZE(4, 24), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -7173,7 +7182,7 @@ UPB_INLINE upb_Array* _google_protobuf_EnumDescriptorProto_value_mutable_upb_arr } UPB_INLINE void google_protobuf_EnumDescriptorProto_clear_options(google_protobuf_EnumDescriptorProto* msg) { const upb_MiniTableField field = {3, UPB_SIZE(8, 32), 2, 1, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_EnumOptions* google_protobuf_EnumDescriptorProto_options(const google_protobuf_EnumDescriptorProto* msg) { const google_protobuf_EnumOptions* default_val = NULL; @@ -7189,7 +7198,7 @@ UPB_INLINE bool google_protobuf_EnumDescriptorProto_has_options(const google_pro } UPB_INLINE void google_protobuf_EnumDescriptorProto_clear_reserved_range(google_protobuf_EnumDescriptorProto* msg) { const upb_MiniTableField field = {4, UPB_SIZE(12, 40), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_EnumDescriptorProto_EnumReservedRange* const* google_protobuf_EnumDescriptorProto_reserved_range(const google_protobuf_EnumDescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {4, UPB_SIZE(12, 40), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -7221,7 +7230,7 @@ UPB_INLINE upb_Array* _google_protobuf_EnumDescriptorProto_reserved_range_mutabl } UPB_INLINE void google_protobuf_EnumDescriptorProto_clear_reserved_name(google_protobuf_EnumDescriptorProto* msg) { const upb_MiniTableField field = {5, UPB_SIZE(16, 48), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView const* google_protobuf_EnumDescriptorProto_reserved_name(const google_protobuf_EnumDescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {5, UPB_SIZE(16, 48), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -7395,7 +7404,7 @@ UPB_INLINE char* google_protobuf_EnumDescriptorProto_EnumReservedRange_serialize } UPB_INLINE void google_protobuf_EnumDescriptorProto_EnumReservedRange_clear_start(google_protobuf_EnumDescriptorProto_EnumReservedRange* msg) { const upb_MiniTableField field = {1, 4, 1, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_EnumDescriptorProto_EnumReservedRange_start(const google_protobuf_EnumDescriptorProto_EnumReservedRange* msg) { int32_t default_val = (int32_t)0; @@ -7411,7 +7420,7 @@ UPB_INLINE bool google_protobuf_EnumDescriptorProto_EnumReservedRange_has_start( } UPB_INLINE void google_protobuf_EnumDescriptorProto_EnumReservedRange_clear_end(google_protobuf_EnumDescriptorProto_EnumReservedRange* msg) { const upb_MiniTableField field = {2, 8, 2, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_EnumDescriptorProto_EnumReservedRange_end(const google_protobuf_EnumDescriptorProto_EnumReservedRange* msg) { int32_t default_val = (int32_t)0; @@ -7473,7 +7482,7 @@ UPB_INLINE char* google_protobuf_EnumValueDescriptorProto_serialize_ex(const goo } UPB_INLINE void google_protobuf_EnumValueDescriptorProto_clear_name(google_protobuf_EnumValueDescriptorProto* msg) { const upb_MiniTableField field = {1, UPB_SIZE(12, 8), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_EnumValueDescriptorProto_name(const google_protobuf_EnumValueDescriptorProto* msg) { upb_StringView default_val = upb_StringView_FromString(""); @@ -7489,7 +7498,7 @@ UPB_INLINE bool google_protobuf_EnumValueDescriptorProto_has_name(const google_p } UPB_INLINE void google_protobuf_EnumValueDescriptorProto_clear_number(google_protobuf_EnumValueDescriptorProto* msg) { const upb_MiniTableField field = {2, 4, 2, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_EnumValueDescriptorProto_number(const google_protobuf_EnumValueDescriptorProto* msg) { int32_t default_val = (int32_t)0; @@ -7505,7 +7514,7 @@ UPB_INLINE bool google_protobuf_EnumValueDescriptorProto_has_number(const google } UPB_INLINE void google_protobuf_EnumValueDescriptorProto_clear_options(google_protobuf_EnumValueDescriptorProto* msg) { const upb_MiniTableField field = {3, UPB_SIZE(8, 24), 3, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_EnumValueOptions* google_protobuf_EnumValueDescriptorProto_options(const google_protobuf_EnumValueDescriptorProto* msg) { const google_protobuf_EnumValueOptions* default_val = NULL; @@ -7579,7 +7588,7 @@ UPB_INLINE char* google_protobuf_ServiceDescriptorProto_serialize_ex(const googl } UPB_INLINE void google_protobuf_ServiceDescriptorProto_clear_name(google_protobuf_ServiceDescriptorProto* msg) { const upb_MiniTableField field = {1, UPB_SIZE(12, 8), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_ServiceDescriptorProto_name(const google_protobuf_ServiceDescriptorProto* msg) { upb_StringView default_val = upb_StringView_FromString(""); @@ -7595,7 +7604,7 @@ UPB_INLINE bool google_protobuf_ServiceDescriptorProto_has_name(const google_pro } UPB_INLINE void google_protobuf_ServiceDescriptorProto_clear_method(google_protobuf_ServiceDescriptorProto* msg) { const upb_MiniTableField field = {2, UPB_SIZE(4, 24), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_MethodDescriptorProto* const* google_protobuf_ServiceDescriptorProto_method(const google_protobuf_ServiceDescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {2, UPB_SIZE(4, 24), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -7627,7 +7636,7 @@ UPB_INLINE upb_Array* _google_protobuf_ServiceDescriptorProto_method_mutable_upb } UPB_INLINE void google_protobuf_ServiceDescriptorProto_clear_options(google_protobuf_ServiceDescriptorProto* msg) { const upb_MiniTableField field = {3, UPB_SIZE(8, 32), 2, 1, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_ServiceOptions* google_protobuf_ServiceDescriptorProto_options(const google_protobuf_ServiceDescriptorProto* msg) { const google_protobuf_ServiceOptions* default_val = NULL; @@ -7727,7 +7736,7 @@ UPB_INLINE char* google_protobuf_MethodDescriptorProto_serialize_ex(const google } UPB_INLINE void google_protobuf_MethodDescriptorProto_clear_name(google_protobuf_MethodDescriptorProto* msg) { const upb_MiniTableField field = {1, UPB_SIZE(12, 8), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_MethodDescriptorProto_name(const google_protobuf_MethodDescriptorProto* msg) { upb_StringView default_val = upb_StringView_FromString(""); @@ -7743,7 +7752,7 @@ UPB_INLINE bool google_protobuf_MethodDescriptorProto_has_name(const google_prot } UPB_INLINE void google_protobuf_MethodDescriptorProto_clear_input_type(google_protobuf_MethodDescriptorProto* msg) { const upb_MiniTableField field = {2, UPB_SIZE(20, 24), 2, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_MethodDescriptorProto_input_type(const google_protobuf_MethodDescriptorProto* msg) { upb_StringView default_val = upb_StringView_FromString(""); @@ -7759,7 +7768,7 @@ UPB_INLINE bool google_protobuf_MethodDescriptorProto_has_input_type(const googl } UPB_INLINE void google_protobuf_MethodDescriptorProto_clear_output_type(google_protobuf_MethodDescriptorProto* msg) { const upb_MiniTableField field = {3, UPB_SIZE(28, 40), 3, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_MethodDescriptorProto_output_type(const google_protobuf_MethodDescriptorProto* msg) { upb_StringView default_val = upb_StringView_FromString(""); @@ -7775,7 +7784,7 @@ UPB_INLINE bool google_protobuf_MethodDescriptorProto_has_output_type(const goog } UPB_INLINE void google_protobuf_MethodDescriptorProto_clear_options(google_protobuf_MethodDescriptorProto* msg) { const upb_MiniTableField field = {4, UPB_SIZE(4, 56), 4, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_MethodOptions* google_protobuf_MethodDescriptorProto_options(const google_protobuf_MethodDescriptorProto* msg) { const google_protobuf_MethodOptions* default_val = NULL; @@ -7791,7 +7800,7 @@ UPB_INLINE bool google_protobuf_MethodDescriptorProto_has_options(const google_p } UPB_INLINE void google_protobuf_MethodDescriptorProto_clear_client_streaming(google_protobuf_MethodDescriptorProto* msg) { const upb_MiniTableField field = {5, UPB_SIZE(8, 1), 5, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_MethodDescriptorProto_client_streaming(const google_protobuf_MethodDescriptorProto* msg) { bool default_val = false; @@ -7807,7 +7816,7 @@ UPB_INLINE bool google_protobuf_MethodDescriptorProto_has_client_streaming(const } UPB_INLINE void google_protobuf_MethodDescriptorProto_clear_server_streaming(google_protobuf_MethodDescriptorProto* msg) { const upb_MiniTableField field = {6, UPB_SIZE(9, 2), 6, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_MethodDescriptorProto_server_streaming(const google_protobuf_MethodDescriptorProto* msg) { bool default_val = false; @@ -7893,7 +7902,7 @@ UPB_INLINE char* google_protobuf_FileOptions_serialize_ex(const google_protobuf_ } UPB_INLINE void google_protobuf_FileOptions_clear_java_package(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {1, UPB_SIZE(24, 16), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_FileOptions_java_package(const google_protobuf_FileOptions* msg) { upb_StringView default_val = upb_StringView_FromString(""); @@ -7909,7 +7918,7 @@ UPB_INLINE bool google_protobuf_FileOptions_has_java_package(const google_protob } UPB_INLINE void google_protobuf_FileOptions_clear_java_outer_classname(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {8, 32, 2, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_FileOptions_java_outer_classname(const google_protobuf_FileOptions* msg) { upb_StringView default_val = upb_StringView_FromString(""); @@ -7925,7 +7934,7 @@ UPB_INLINE bool google_protobuf_FileOptions_has_java_outer_classname(const googl } UPB_INLINE void google_protobuf_FileOptions_clear_optimize_for(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {9, 4, 3, 2, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_FileOptions_optimize_for(const google_protobuf_FileOptions* msg) { int32_t default_val = 1; @@ -7941,7 +7950,7 @@ UPB_INLINE bool google_protobuf_FileOptions_has_optimize_for(const google_protob } UPB_INLINE void google_protobuf_FileOptions_clear_java_multiple_files(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {10, 8, 4, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_FileOptions_java_multiple_files(const google_protobuf_FileOptions* msg) { bool default_val = false; @@ -7957,7 +7966,7 @@ UPB_INLINE bool google_protobuf_FileOptions_has_java_multiple_files(const google } UPB_INLINE void google_protobuf_FileOptions_clear_go_package(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {11, UPB_SIZE(40, 48), 5, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_FileOptions_go_package(const google_protobuf_FileOptions* msg) { upb_StringView default_val = upb_StringView_FromString(""); @@ -7973,7 +7982,7 @@ UPB_INLINE bool google_protobuf_FileOptions_has_go_package(const google_protobuf } UPB_INLINE void google_protobuf_FileOptions_clear_cc_generic_services(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {16, 9, 6, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_FileOptions_cc_generic_services(const google_protobuf_FileOptions* msg) { bool default_val = false; @@ -7989,7 +7998,7 @@ UPB_INLINE bool google_protobuf_FileOptions_has_cc_generic_services(const google } UPB_INLINE void google_protobuf_FileOptions_clear_java_generic_services(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {17, 10, 7, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_FileOptions_java_generic_services(const google_protobuf_FileOptions* msg) { bool default_val = false; @@ -8005,7 +8014,7 @@ UPB_INLINE bool google_protobuf_FileOptions_has_java_generic_services(const goog } UPB_INLINE void google_protobuf_FileOptions_clear_py_generic_services(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {18, 11, 8, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_FileOptions_py_generic_services(const google_protobuf_FileOptions* msg) { bool default_val = false; @@ -8021,7 +8030,7 @@ UPB_INLINE bool google_protobuf_FileOptions_has_py_generic_services(const google } UPB_INLINE void google_protobuf_FileOptions_clear_java_generate_equals_and_hash(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {20, 12, 9, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_FileOptions_java_generate_equals_and_hash(const google_protobuf_FileOptions* msg) { bool default_val = false; @@ -8037,7 +8046,7 @@ UPB_INLINE bool google_protobuf_FileOptions_has_java_generate_equals_and_hash(co } UPB_INLINE void google_protobuf_FileOptions_clear_deprecated(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {23, 13, 10, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_FileOptions_deprecated(const google_protobuf_FileOptions* msg) { bool default_val = false; @@ -8053,7 +8062,7 @@ UPB_INLINE bool google_protobuf_FileOptions_has_deprecated(const google_protobuf } UPB_INLINE void google_protobuf_FileOptions_clear_java_string_check_utf8(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {27, 14, 11, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_FileOptions_java_string_check_utf8(const google_protobuf_FileOptions* msg) { bool default_val = false; @@ -8069,7 +8078,7 @@ UPB_INLINE bool google_protobuf_FileOptions_has_java_string_check_utf8(const goo } UPB_INLINE void google_protobuf_FileOptions_clear_cc_enable_arenas(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {31, 15, 12, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_FileOptions_cc_enable_arenas(const google_protobuf_FileOptions* msg) { bool default_val = true; @@ -8085,7 +8094,7 @@ UPB_INLINE bool google_protobuf_FileOptions_has_cc_enable_arenas(const google_pr } UPB_INLINE void google_protobuf_FileOptions_clear_objc_class_prefix(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {36, UPB_SIZE(48, 64), 13, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_FileOptions_objc_class_prefix(const google_protobuf_FileOptions* msg) { upb_StringView default_val = upb_StringView_FromString(""); @@ -8101,7 +8110,7 @@ UPB_INLINE bool google_protobuf_FileOptions_has_objc_class_prefix(const google_p } UPB_INLINE void google_protobuf_FileOptions_clear_csharp_namespace(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {37, UPB_SIZE(56, 80), 14, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_FileOptions_csharp_namespace(const google_protobuf_FileOptions* msg) { upb_StringView default_val = upb_StringView_FromString(""); @@ -8117,7 +8126,7 @@ UPB_INLINE bool google_protobuf_FileOptions_has_csharp_namespace(const google_pr } UPB_INLINE void google_protobuf_FileOptions_clear_swift_prefix(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {39, UPB_SIZE(64, 96), 15, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_FileOptions_swift_prefix(const google_protobuf_FileOptions* msg) { upb_StringView default_val = upb_StringView_FromString(""); @@ -8133,7 +8142,7 @@ UPB_INLINE bool google_protobuf_FileOptions_has_swift_prefix(const google_protob } UPB_INLINE void google_protobuf_FileOptions_clear_php_class_prefix(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {40, UPB_SIZE(72, 112), 16, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_FileOptions_php_class_prefix(const google_protobuf_FileOptions* msg) { upb_StringView default_val = upb_StringView_FromString(""); @@ -8149,7 +8158,7 @@ UPB_INLINE bool google_protobuf_FileOptions_has_php_class_prefix(const google_pr } UPB_INLINE void google_protobuf_FileOptions_clear_php_namespace(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {41, UPB_SIZE(80, 128), 17, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_FileOptions_php_namespace(const google_protobuf_FileOptions* msg) { upb_StringView default_val = upb_StringView_FromString(""); @@ -8165,7 +8174,7 @@ UPB_INLINE bool google_protobuf_FileOptions_has_php_namespace(const google_proto } UPB_INLINE void google_protobuf_FileOptions_clear_php_metadata_namespace(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {44, UPB_SIZE(88, 144), 18, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_FileOptions_php_metadata_namespace(const google_protobuf_FileOptions* msg) { upb_StringView default_val = upb_StringView_FromString(""); @@ -8181,7 +8190,7 @@ UPB_INLINE bool google_protobuf_FileOptions_has_php_metadata_namespace(const goo } UPB_INLINE void google_protobuf_FileOptions_clear_ruby_package(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {45, UPB_SIZE(96, 160), 19, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_FileOptions_ruby_package(const google_protobuf_FileOptions* msg) { upb_StringView default_val = upb_StringView_FromString(""); @@ -8197,7 +8206,7 @@ UPB_INLINE bool google_protobuf_FileOptions_has_ruby_package(const google_protob } UPB_INLINE void google_protobuf_FileOptions_clear_features(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {50, UPB_SIZE(16, 176), 20, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_FeatureSet* google_protobuf_FileOptions_features(const google_protobuf_FileOptions* msg) { const google_protobuf_FeatureSet* default_val = NULL; @@ -8213,7 +8222,7 @@ UPB_INLINE bool google_protobuf_FileOptions_has_features(const google_protobuf_F } UPB_INLINE void google_protobuf_FileOptions_clear_uninterpreted_option(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {999, UPB_SIZE(20, 184), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_FileOptions_uninterpreted_option(const google_protobuf_FileOptions* msg, size_t* size) { const upb_MiniTableField field = {999, UPB_SIZE(20, 184), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -8401,7 +8410,7 @@ UPB_INLINE char* google_protobuf_MessageOptions_serialize_ex(const google_protob } UPB_INLINE void google_protobuf_MessageOptions_clear_message_set_wire_format(google_protobuf_MessageOptions* msg) { const upb_MiniTableField field = {1, 1, 1, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_MessageOptions_message_set_wire_format(const google_protobuf_MessageOptions* msg) { bool default_val = false; @@ -8417,7 +8426,7 @@ UPB_INLINE bool google_protobuf_MessageOptions_has_message_set_wire_format(const } UPB_INLINE void google_protobuf_MessageOptions_clear_no_standard_descriptor_accessor(google_protobuf_MessageOptions* msg) { const upb_MiniTableField field = {2, 2, 2, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_MessageOptions_no_standard_descriptor_accessor(const google_protobuf_MessageOptions* msg) { bool default_val = false; @@ -8433,7 +8442,7 @@ UPB_INLINE bool google_protobuf_MessageOptions_has_no_standard_descriptor_access } UPB_INLINE void google_protobuf_MessageOptions_clear_deprecated(google_protobuf_MessageOptions* msg) { const upb_MiniTableField field = {3, 3, 3, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_MessageOptions_deprecated(const google_protobuf_MessageOptions* msg) { bool default_val = false; @@ -8449,7 +8458,7 @@ UPB_INLINE bool google_protobuf_MessageOptions_has_deprecated(const google_proto } UPB_INLINE void google_protobuf_MessageOptions_clear_map_entry(google_protobuf_MessageOptions* msg) { const upb_MiniTableField field = {7, 4, 4, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_MessageOptions_map_entry(const google_protobuf_MessageOptions* msg) { bool default_val = false; @@ -8465,7 +8474,7 @@ UPB_INLINE bool google_protobuf_MessageOptions_has_map_entry(const google_protob } UPB_INLINE void google_protobuf_MessageOptions_clear_deprecated_legacy_json_field_conflicts(google_protobuf_MessageOptions* msg) { const upb_MiniTableField field = {11, 5, 5, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_MessageOptions_deprecated_legacy_json_field_conflicts(const google_protobuf_MessageOptions* msg) { bool default_val = false; @@ -8481,7 +8490,7 @@ UPB_INLINE bool google_protobuf_MessageOptions_has_deprecated_legacy_json_field_ } UPB_INLINE void google_protobuf_MessageOptions_clear_features(google_protobuf_MessageOptions* msg) { const upb_MiniTableField field = {12, 8, 6, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_FeatureSet* google_protobuf_MessageOptions_features(const google_protobuf_MessageOptions* msg) { const google_protobuf_FeatureSet* default_val = NULL; @@ -8497,7 +8506,7 @@ UPB_INLINE bool google_protobuf_MessageOptions_has_features(const google_protobu } UPB_INLINE void google_protobuf_MessageOptions_clear_uninterpreted_option(google_protobuf_MessageOptions* msg) { const upb_MiniTableField field = {999, UPB_SIZE(12, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_MessageOptions_uninterpreted_option(const google_protobuf_MessageOptions* msg, size_t* size) { const upb_MiniTableField field = {999, UPB_SIZE(12, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -8629,7 +8638,7 @@ UPB_INLINE char* google_protobuf_FieldOptions_serialize_ex(const google_protobuf } UPB_INLINE void google_protobuf_FieldOptions_clear_ctype(google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {1, 4, 1, 3, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_FieldOptions_ctype(const google_protobuf_FieldOptions* msg) { int32_t default_val = 0; @@ -8645,7 +8654,7 @@ UPB_INLINE bool google_protobuf_FieldOptions_has_ctype(const google_protobuf_Fie } UPB_INLINE void google_protobuf_FieldOptions_clear_packed(google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {2, 8, 2, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_FieldOptions_packed(const google_protobuf_FieldOptions* msg) { bool default_val = false; @@ -8661,7 +8670,7 @@ UPB_INLINE bool google_protobuf_FieldOptions_has_packed(const google_protobuf_Fi } UPB_INLINE void google_protobuf_FieldOptions_clear_deprecated(google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {3, 9, 3, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_FieldOptions_deprecated(const google_protobuf_FieldOptions* msg) { bool default_val = false; @@ -8677,7 +8686,7 @@ UPB_INLINE bool google_protobuf_FieldOptions_has_deprecated(const google_protobu } UPB_INLINE void google_protobuf_FieldOptions_clear_lazy(google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {5, 10, 4, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_FieldOptions_lazy(const google_protobuf_FieldOptions* msg) { bool default_val = false; @@ -8693,7 +8702,7 @@ UPB_INLINE bool google_protobuf_FieldOptions_has_lazy(const google_protobuf_Fiel } UPB_INLINE void google_protobuf_FieldOptions_clear_jstype(google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {6, 12, 5, 4, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_FieldOptions_jstype(const google_protobuf_FieldOptions* msg) { int32_t default_val = 0; @@ -8709,7 +8718,7 @@ UPB_INLINE bool google_protobuf_FieldOptions_has_jstype(const google_protobuf_Fi } UPB_INLINE void google_protobuf_FieldOptions_clear_weak(google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {10, 16, 6, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_FieldOptions_weak(const google_protobuf_FieldOptions* msg) { bool default_val = false; @@ -8725,7 +8734,7 @@ UPB_INLINE bool google_protobuf_FieldOptions_has_weak(const google_protobuf_Fiel } UPB_INLINE void google_protobuf_FieldOptions_clear_unverified_lazy(google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {15, 17, 7, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_FieldOptions_unverified_lazy(const google_protobuf_FieldOptions* msg) { bool default_val = false; @@ -8741,7 +8750,7 @@ UPB_INLINE bool google_protobuf_FieldOptions_has_unverified_lazy(const google_pr } UPB_INLINE void google_protobuf_FieldOptions_clear_debug_redact(google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {16, 18, 8, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_FieldOptions_debug_redact(const google_protobuf_FieldOptions* msg) { bool default_val = false; @@ -8757,7 +8766,7 @@ UPB_INLINE bool google_protobuf_FieldOptions_has_debug_redact(const google_proto } UPB_INLINE void google_protobuf_FieldOptions_clear_retention(google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {17, 20, 9, 5, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_FieldOptions_retention(const google_protobuf_FieldOptions* msg) { int32_t default_val = 0; @@ -8773,7 +8782,7 @@ UPB_INLINE bool google_protobuf_FieldOptions_has_retention(const google_protobuf } UPB_INLINE void google_protobuf_FieldOptions_clear_targets(google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {19, 24, 0, 6, 14, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t const* google_protobuf_FieldOptions_targets(const google_protobuf_FieldOptions* msg, size_t* size) { const upb_MiniTableField field = {19, 24, 0, 6, 14, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -8805,7 +8814,7 @@ UPB_INLINE upb_Array* _google_protobuf_FieldOptions_targets_mutable_upb_array(go } UPB_INLINE void google_protobuf_FieldOptions_clear_edition_defaults(google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {20, UPB_SIZE(28, 32), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_FieldOptions_EditionDefault* const* google_protobuf_FieldOptions_edition_defaults(const google_protobuf_FieldOptions* msg, size_t* size) { const upb_MiniTableField field = {20, UPB_SIZE(28, 32), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -8837,7 +8846,7 @@ UPB_INLINE upb_Array* _google_protobuf_FieldOptions_edition_defaults_mutable_upb } UPB_INLINE void google_protobuf_FieldOptions_clear_features(google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {21, UPB_SIZE(32, 40), 10, 1, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_FeatureSet* google_protobuf_FieldOptions_features(const google_protobuf_FieldOptions* msg) { const google_protobuf_FeatureSet* default_val = NULL; @@ -8853,7 +8862,7 @@ UPB_INLINE bool google_protobuf_FieldOptions_has_features(const google_protobuf_ } UPB_INLINE void google_protobuf_FieldOptions_clear_uninterpreted_option(google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {999, UPB_SIZE(36, 48), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_FieldOptions_uninterpreted_option(const google_protobuf_FieldOptions* msg, size_t* size) { const upb_MiniTableField field = {999, UPB_SIZE(36, 48), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -9059,7 +9068,7 @@ UPB_INLINE char* google_protobuf_FieldOptions_EditionDefault_serialize_ex(const } UPB_INLINE void google_protobuf_FieldOptions_EditionDefault_clear_value(google_protobuf_FieldOptions_EditionDefault* msg) { const upb_MiniTableField field = {2, 8, 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_FieldOptions_EditionDefault_value(const google_protobuf_FieldOptions_EditionDefault* msg) { upb_StringView default_val = upb_StringView_FromString(""); @@ -9075,7 +9084,7 @@ UPB_INLINE bool google_protobuf_FieldOptions_EditionDefault_has_value(const goog } UPB_INLINE void google_protobuf_FieldOptions_EditionDefault_clear_edition(google_protobuf_FieldOptions_EditionDefault* msg) { const upb_MiniTableField field = {3, 4, 2, 0, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_FieldOptions_EditionDefault_edition(const google_protobuf_FieldOptions_EditionDefault* msg) { int32_t default_val = 0; @@ -9137,7 +9146,7 @@ UPB_INLINE char* google_protobuf_OneofOptions_serialize_ex(const google_protobuf } UPB_INLINE void google_protobuf_OneofOptions_clear_features(google_protobuf_OneofOptions* msg) { const upb_MiniTableField field = {1, UPB_SIZE(4, 8), 1, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_FeatureSet* google_protobuf_OneofOptions_features(const google_protobuf_OneofOptions* msg) { const google_protobuf_FeatureSet* default_val = NULL; @@ -9153,7 +9162,7 @@ UPB_INLINE bool google_protobuf_OneofOptions_has_features(const google_protobuf_ } UPB_INLINE void google_protobuf_OneofOptions_clear_uninterpreted_option(google_protobuf_OneofOptions* msg) { const upb_MiniTableField field = {999, UPB_SIZE(8, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_OneofOptions_uninterpreted_option(const google_protobuf_OneofOptions* msg, size_t* size) { const upb_MiniTableField field = {999, UPB_SIZE(8, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -9265,7 +9274,7 @@ UPB_INLINE char* google_protobuf_EnumOptions_serialize_ex(const google_protobuf_ } UPB_INLINE void google_protobuf_EnumOptions_clear_allow_alias(google_protobuf_EnumOptions* msg) { const upb_MiniTableField field = {2, 1, 1, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_EnumOptions_allow_alias(const google_protobuf_EnumOptions* msg) { bool default_val = false; @@ -9281,7 +9290,7 @@ UPB_INLINE bool google_protobuf_EnumOptions_has_allow_alias(const google_protobu } UPB_INLINE void google_protobuf_EnumOptions_clear_deprecated(google_protobuf_EnumOptions* msg) { const upb_MiniTableField field = {3, 2, 2, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_EnumOptions_deprecated(const google_protobuf_EnumOptions* msg) { bool default_val = false; @@ -9297,7 +9306,7 @@ UPB_INLINE bool google_protobuf_EnumOptions_has_deprecated(const google_protobuf } UPB_INLINE void google_protobuf_EnumOptions_clear_deprecated_legacy_json_field_conflicts(google_protobuf_EnumOptions* msg) { const upb_MiniTableField field = {6, 3, 3, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_EnumOptions_deprecated_legacy_json_field_conflicts(const google_protobuf_EnumOptions* msg) { bool default_val = false; @@ -9313,7 +9322,7 @@ UPB_INLINE bool google_protobuf_EnumOptions_has_deprecated_legacy_json_field_con } UPB_INLINE void google_protobuf_EnumOptions_clear_features(google_protobuf_EnumOptions* msg) { const upb_MiniTableField field = {7, UPB_SIZE(4, 8), 4, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_FeatureSet* google_protobuf_EnumOptions_features(const google_protobuf_EnumOptions* msg) { const google_protobuf_FeatureSet* default_val = NULL; @@ -9329,7 +9338,7 @@ UPB_INLINE bool google_protobuf_EnumOptions_has_features(const google_protobuf_E } UPB_INLINE void google_protobuf_EnumOptions_clear_uninterpreted_option(google_protobuf_EnumOptions* msg) { const upb_MiniTableField field = {999, UPB_SIZE(8, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_EnumOptions_uninterpreted_option(const google_protobuf_EnumOptions* msg, size_t* size) { const upb_MiniTableField field = {999, UPB_SIZE(8, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -9453,7 +9462,7 @@ UPB_INLINE char* google_protobuf_EnumValueOptions_serialize_ex(const google_prot } UPB_INLINE void google_protobuf_EnumValueOptions_clear_deprecated(google_protobuf_EnumValueOptions* msg) { const upb_MiniTableField field = {1, 1, 1, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_EnumValueOptions_deprecated(const google_protobuf_EnumValueOptions* msg) { bool default_val = false; @@ -9469,7 +9478,7 @@ UPB_INLINE bool google_protobuf_EnumValueOptions_has_deprecated(const google_pro } UPB_INLINE void google_protobuf_EnumValueOptions_clear_features(google_protobuf_EnumValueOptions* msg) { const upb_MiniTableField field = {2, UPB_SIZE(4, 8), 2, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_FeatureSet* google_protobuf_EnumValueOptions_features(const google_protobuf_EnumValueOptions* msg) { const google_protobuf_FeatureSet* default_val = NULL; @@ -9485,7 +9494,7 @@ UPB_INLINE bool google_protobuf_EnumValueOptions_has_features(const google_proto } UPB_INLINE void google_protobuf_EnumValueOptions_clear_debug_redact(google_protobuf_EnumValueOptions* msg) { const upb_MiniTableField field = {3, UPB_SIZE(8, 2), 3, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_EnumValueOptions_debug_redact(const google_protobuf_EnumValueOptions* msg) { bool default_val = false; @@ -9501,7 +9510,7 @@ UPB_INLINE bool google_protobuf_EnumValueOptions_has_debug_redact(const google_p } UPB_INLINE void google_protobuf_EnumValueOptions_clear_uninterpreted_option(google_protobuf_EnumValueOptions* msg) { const upb_MiniTableField field = {999, UPB_SIZE(12, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_EnumValueOptions_uninterpreted_option(const google_protobuf_EnumValueOptions* msg, size_t* size) { const upb_MiniTableField field = {999, UPB_SIZE(12, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -9621,7 +9630,7 @@ UPB_INLINE char* google_protobuf_ServiceOptions_serialize_ex(const google_protob } UPB_INLINE void google_protobuf_ServiceOptions_clear_deprecated(google_protobuf_ServiceOptions* msg) { const upb_MiniTableField field = {33, 1, 1, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_ServiceOptions_deprecated(const google_protobuf_ServiceOptions* msg) { bool default_val = false; @@ -9637,7 +9646,7 @@ UPB_INLINE bool google_protobuf_ServiceOptions_has_deprecated(const google_proto } UPB_INLINE void google_protobuf_ServiceOptions_clear_features(google_protobuf_ServiceOptions* msg) { const upb_MiniTableField field = {34, UPB_SIZE(4, 8), 2, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_FeatureSet* google_protobuf_ServiceOptions_features(const google_protobuf_ServiceOptions* msg) { const google_protobuf_FeatureSet* default_val = NULL; @@ -9653,7 +9662,7 @@ UPB_INLINE bool google_protobuf_ServiceOptions_has_features(const google_protobu } UPB_INLINE void google_protobuf_ServiceOptions_clear_uninterpreted_option(google_protobuf_ServiceOptions* msg) { const upb_MiniTableField field = {999, UPB_SIZE(8, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_ServiceOptions_uninterpreted_option(const google_protobuf_ServiceOptions* msg, size_t* size) { const upb_MiniTableField field = {999, UPB_SIZE(8, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -9769,7 +9778,7 @@ UPB_INLINE char* google_protobuf_MethodOptions_serialize_ex(const google_protobu } UPB_INLINE void google_protobuf_MethodOptions_clear_deprecated(google_protobuf_MethodOptions* msg) { const upb_MiniTableField field = {33, 1, 1, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_MethodOptions_deprecated(const google_protobuf_MethodOptions* msg) { bool default_val = false; @@ -9785,7 +9794,7 @@ UPB_INLINE bool google_protobuf_MethodOptions_has_deprecated(const google_protob } UPB_INLINE void google_protobuf_MethodOptions_clear_idempotency_level(google_protobuf_MethodOptions* msg) { const upb_MiniTableField field = {34, 4, 2, 2, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_MethodOptions_idempotency_level(const google_protobuf_MethodOptions* msg) { int32_t default_val = 0; @@ -9801,7 +9810,7 @@ UPB_INLINE bool google_protobuf_MethodOptions_has_idempotency_level(const google } UPB_INLINE void google_protobuf_MethodOptions_clear_features(google_protobuf_MethodOptions* msg) { const upb_MiniTableField field = {35, 8, 3, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_FeatureSet* google_protobuf_MethodOptions_features(const google_protobuf_MethodOptions* msg) { const google_protobuf_FeatureSet* default_val = NULL; @@ -9817,7 +9826,7 @@ UPB_INLINE bool google_protobuf_MethodOptions_has_features(const google_protobuf } UPB_INLINE void google_protobuf_MethodOptions_clear_uninterpreted_option(google_protobuf_MethodOptions* msg) { const upb_MiniTableField field = {999, UPB_SIZE(12, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_MethodOptions_uninterpreted_option(const google_protobuf_MethodOptions* msg, size_t* size) { const upb_MiniTableField field = {999, UPB_SIZE(12, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -9937,7 +9946,7 @@ UPB_INLINE char* google_protobuf_UninterpretedOption_serialize_ex(const google_p } UPB_INLINE void google_protobuf_UninterpretedOption_clear_name(google_protobuf_UninterpretedOption* msg) { const upb_MiniTableField field = {2, UPB_SIZE(4, 8), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_UninterpretedOption_NamePart* const* google_protobuf_UninterpretedOption_name(const google_protobuf_UninterpretedOption* msg, size_t* size) { const upb_MiniTableField field = {2, UPB_SIZE(4, 8), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -9969,7 +9978,7 @@ UPB_INLINE upb_Array* _google_protobuf_UninterpretedOption_name_mutable_upb_arra } UPB_INLINE void google_protobuf_UninterpretedOption_clear_identifier_value(google_protobuf_UninterpretedOption* msg) { const upb_MiniTableField field = {3, UPB_SIZE(8, 16), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_UninterpretedOption_identifier_value(const google_protobuf_UninterpretedOption* msg) { upb_StringView default_val = upb_StringView_FromString(""); @@ -9985,7 +9994,7 @@ UPB_INLINE bool google_protobuf_UninterpretedOption_has_identifier_value(const g } UPB_INLINE void google_protobuf_UninterpretedOption_clear_positive_int_value(google_protobuf_UninterpretedOption* msg) { const upb_MiniTableField field = {4, UPB_SIZE(16, 32), 2, kUpb_NoSub, 4, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_8Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE uint64_t google_protobuf_UninterpretedOption_positive_int_value(const google_protobuf_UninterpretedOption* msg) { uint64_t default_val = (uint64_t)0ull; @@ -10001,7 +10010,7 @@ UPB_INLINE bool google_protobuf_UninterpretedOption_has_positive_int_value(const } UPB_INLINE void google_protobuf_UninterpretedOption_clear_negative_int_value(google_protobuf_UninterpretedOption* msg) { const upb_MiniTableField field = {5, UPB_SIZE(24, 40), 3, kUpb_NoSub, 3, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_8Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE int64_t google_protobuf_UninterpretedOption_negative_int_value(const google_protobuf_UninterpretedOption* msg) { int64_t default_val = (int64_t)0ll; @@ -10017,7 +10026,7 @@ UPB_INLINE bool google_protobuf_UninterpretedOption_has_negative_int_value(const } UPB_INLINE void google_protobuf_UninterpretedOption_clear_double_value(google_protobuf_UninterpretedOption* msg) { const upb_MiniTableField field = {6, UPB_SIZE(32, 48), 4, kUpb_NoSub, 1, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_8Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE double google_protobuf_UninterpretedOption_double_value(const google_protobuf_UninterpretedOption* msg) { double default_val = 0; @@ -10033,7 +10042,7 @@ UPB_INLINE bool google_protobuf_UninterpretedOption_has_double_value(const googl } UPB_INLINE void google_protobuf_UninterpretedOption_clear_string_value(google_protobuf_UninterpretedOption* msg) { const upb_MiniTableField field = {7, UPB_SIZE(40, 56), 5, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_UninterpretedOption_string_value(const google_protobuf_UninterpretedOption* msg) { upb_StringView default_val = upb_StringView_FromString(""); @@ -10049,7 +10058,7 @@ UPB_INLINE bool google_protobuf_UninterpretedOption_has_string_value(const googl } UPB_INLINE void google_protobuf_UninterpretedOption_clear_aggregate_value(google_protobuf_UninterpretedOption* msg) { const upb_MiniTableField field = {8, UPB_SIZE(48, 72), 6, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_UninterpretedOption_aggregate_value(const google_protobuf_UninterpretedOption* msg) { upb_StringView default_val = upb_StringView_FromString(""); @@ -10157,7 +10166,7 @@ UPB_INLINE char* google_protobuf_UninterpretedOption_NamePart_serialize_ex(const } UPB_INLINE void google_protobuf_UninterpretedOption_NamePart_clear_name_part(google_protobuf_UninterpretedOption_NamePart* msg) { const upb_MiniTableField field = {1, UPB_SIZE(4, 8), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_UninterpretedOption_NamePart_name_part(const google_protobuf_UninterpretedOption_NamePart* msg) { upb_StringView default_val = upb_StringView_FromString(""); @@ -10173,7 +10182,7 @@ UPB_INLINE bool google_protobuf_UninterpretedOption_NamePart_has_name_part(const } UPB_INLINE void google_protobuf_UninterpretedOption_NamePart_clear_is_extension(google_protobuf_UninterpretedOption_NamePart* msg) { const upb_MiniTableField field = {2, 1, 2, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_UninterpretedOption_NamePart_is_extension(const google_protobuf_UninterpretedOption_NamePart* msg) { bool default_val = false; @@ -10235,7 +10244,7 @@ UPB_INLINE char* google_protobuf_FeatureSet_serialize_ex(const google_protobuf_F } UPB_INLINE void google_protobuf_FeatureSet_clear_field_presence(google_protobuf_FeatureSet* msg) { const upb_MiniTableField field = {1, 4, 1, 0, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_FeatureSet_field_presence(const google_protobuf_FeatureSet* msg) { int32_t default_val = 0; @@ -10251,7 +10260,7 @@ UPB_INLINE bool google_protobuf_FeatureSet_has_field_presence(const google_proto } UPB_INLINE void google_protobuf_FeatureSet_clear_enum_type(google_protobuf_FeatureSet* msg) { const upb_MiniTableField field = {2, 8, 2, 1, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_FeatureSet_enum_type(const google_protobuf_FeatureSet* msg) { int32_t default_val = 0; @@ -10267,7 +10276,7 @@ UPB_INLINE bool google_protobuf_FeatureSet_has_enum_type(const google_protobuf_F } UPB_INLINE void google_protobuf_FeatureSet_clear_repeated_field_encoding(google_protobuf_FeatureSet* msg) { const upb_MiniTableField field = {3, 12, 3, 2, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_FeatureSet_repeated_field_encoding(const google_protobuf_FeatureSet* msg) { int32_t default_val = 0; @@ -10283,7 +10292,7 @@ UPB_INLINE bool google_protobuf_FeatureSet_has_repeated_field_encoding(const goo } UPB_INLINE void google_protobuf_FeatureSet_clear_utf8_validation(google_protobuf_FeatureSet* msg) { const upb_MiniTableField field = {4, 16, 4, 3, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_FeatureSet_utf8_validation(const google_protobuf_FeatureSet* msg) { int32_t default_val = 0; @@ -10299,7 +10308,7 @@ UPB_INLINE bool google_protobuf_FeatureSet_has_utf8_validation(const google_prot } UPB_INLINE void google_protobuf_FeatureSet_clear_message_encoding(google_protobuf_FeatureSet* msg) { const upb_MiniTableField field = {5, 20, 5, 4, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_FeatureSet_message_encoding(const google_protobuf_FeatureSet* msg) { int32_t default_val = 0; @@ -10315,7 +10324,7 @@ UPB_INLINE bool google_protobuf_FeatureSet_has_message_encoding(const google_pro } UPB_INLINE void google_protobuf_FeatureSet_clear_json_format(google_protobuf_FeatureSet* msg) { const upb_MiniTableField field = {6, 24, 6, 5, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_FeatureSet_json_format(const google_protobuf_FeatureSet* msg) { int32_t default_val = 0; @@ -10393,7 +10402,7 @@ UPB_INLINE char* google_protobuf_FeatureSetDefaults_serialize_ex(const google_pr } UPB_INLINE void google_protobuf_FeatureSetDefaults_clear_defaults(google_protobuf_FeatureSetDefaults* msg) { const upb_MiniTableField field = {1, UPB_SIZE(4, 16), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* const* google_protobuf_FeatureSetDefaults_defaults(const google_protobuf_FeatureSetDefaults* msg, size_t* size) { const upb_MiniTableField field = {1, UPB_SIZE(4, 16), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -10425,7 +10434,7 @@ UPB_INLINE upb_Array* _google_protobuf_FeatureSetDefaults_defaults_mutable_upb_a } UPB_INLINE void google_protobuf_FeatureSetDefaults_clear_minimum_edition(google_protobuf_FeatureSetDefaults* msg) { const upb_MiniTableField field = {4, UPB_SIZE(8, 4), 1, 1, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_FeatureSetDefaults_minimum_edition(const google_protobuf_FeatureSetDefaults* msg) { int32_t default_val = 0; @@ -10441,7 +10450,7 @@ UPB_INLINE bool google_protobuf_FeatureSetDefaults_has_minimum_edition(const goo } UPB_INLINE void google_protobuf_FeatureSetDefaults_clear_maximum_edition(google_protobuf_FeatureSetDefaults* msg) { const upb_MiniTableField field = {5, UPB_SIZE(12, 8), 2, 2, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_FeatureSetDefaults_maximum_edition(const google_protobuf_FeatureSetDefaults* msg) { int32_t default_val = 0; @@ -10533,7 +10542,7 @@ UPB_INLINE char* google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_ser } UPB_INLINE void google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_clear_features(google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* msg) { const upb_MiniTableField field = {2, UPB_SIZE(4, 8), 1, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_FeatureSet* google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_features(const google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* msg) { const google_protobuf_FeatureSet* default_val = NULL; @@ -10549,7 +10558,7 @@ UPB_INLINE bool google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_has_ } UPB_INLINE void google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_clear_edition(google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* msg) { const upb_MiniTableField field = {3, UPB_SIZE(8, 4), 2, 1, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_edition(const google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* msg) { int32_t default_val = 0; @@ -10619,7 +10628,7 @@ UPB_INLINE char* google_protobuf_SourceCodeInfo_serialize_ex(const google_protob } UPB_INLINE void google_protobuf_SourceCodeInfo_clear_location(google_protobuf_SourceCodeInfo* msg) { const upb_MiniTableField field = {1, 0, 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_SourceCodeInfo_Location* const* google_protobuf_SourceCodeInfo_location(const google_protobuf_SourceCodeInfo* msg, size_t* size) { const upb_MiniTableField field = {1, 0, 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -10719,7 +10728,7 @@ UPB_INLINE char* google_protobuf_SourceCodeInfo_Location_serialize_ex(const goog } UPB_INLINE void google_protobuf_SourceCodeInfo_Location_clear_path(google_protobuf_SourceCodeInfo_Location* msg) { const upb_MiniTableField field = {1, UPB_SIZE(4, 8), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsPacked | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t const* google_protobuf_SourceCodeInfo_Location_path(const google_protobuf_SourceCodeInfo_Location* msg, size_t* size) { const upb_MiniTableField field = {1, UPB_SIZE(4, 8), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsPacked | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -10751,7 +10760,7 @@ UPB_INLINE upb_Array* _google_protobuf_SourceCodeInfo_Location_path_mutable_upb_ } UPB_INLINE void google_protobuf_SourceCodeInfo_Location_clear_span(google_protobuf_SourceCodeInfo_Location* msg) { const upb_MiniTableField field = {2, UPB_SIZE(8, 16), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsPacked | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t const* google_protobuf_SourceCodeInfo_Location_span(const google_protobuf_SourceCodeInfo_Location* msg, size_t* size) { const upb_MiniTableField field = {2, UPB_SIZE(8, 16), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsPacked | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -10783,7 +10792,7 @@ UPB_INLINE upb_Array* _google_protobuf_SourceCodeInfo_Location_span_mutable_upb_ } UPB_INLINE void google_protobuf_SourceCodeInfo_Location_clear_leading_comments(google_protobuf_SourceCodeInfo_Location* msg) { const upb_MiniTableField field = {3, UPB_SIZE(16, 24), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_SourceCodeInfo_Location_leading_comments(const google_protobuf_SourceCodeInfo_Location* msg) { upb_StringView default_val = upb_StringView_FromString(""); @@ -10799,7 +10808,7 @@ UPB_INLINE bool google_protobuf_SourceCodeInfo_Location_has_leading_comments(con } UPB_INLINE void google_protobuf_SourceCodeInfo_Location_clear_trailing_comments(google_protobuf_SourceCodeInfo_Location* msg) { const upb_MiniTableField field = {4, UPB_SIZE(24, 40), 2, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_SourceCodeInfo_Location_trailing_comments(const google_protobuf_SourceCodeInfo_Location* msg) { upb_StringView default_val = upb_StringView_FromString(""); @@ -10815,7 +10824,7 @@ UPB_INLINE bool google_protobuf_SourceCodeInfo_Location_has_trailing_comments(co } UPB_INLINE void google_protobuf_SourceCodeInfo_Location_clear_leading_detached_comments(google_protobuf_SourceCodeInfo_Location* msg) { const upb_MiniTableField field = {6, UPB_SIZE(12, 56), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView const* google_protobuf_SourceCodeInfo_Location_leading_detached_comments(const google_protobuf_SourceCodeInfo_Location* msg, size_t* size) { const upb_MiniTableField field = {6, UPB_SIZE(12, 56), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -10977,7 +10986,7 @@ UPB_INLINE char* google_protobuf_GeneratedCodeInfo_serialize_ex(const google_pro } UPB_INLINE void google_protobuf_GeneratedCodeInfo_clear_annotation(google_protobuf_GeneratedCodeInfo* msg) { const upb_MiniTableField field = {1, 0, 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_GeneratedCodeInfo_Annotation* const* google_protobuf_GeneratedCodeInfo_annotation(const google_protobuf_GeneratedCodeInfo* msg, size_t* size) { const upb_MiniTableField field = {1, 0, 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -11077,7 +11086,7 @@ UPB_INLINE char* google_protobuf_GeneratedCodeInfo_Annotation_serialize_ex(const } UPB_INLINE void google_protobuf_GeneratedCodeInfo_Annotation_clear_path(google_protobuf_GeneratedCodeInfo_Annotation* msg) { const upb_MiniTableField field = {1, UPB_SIZE(4, 16), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsPacked | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t const* google_protobuf_GeneratedCodeInfo_Annotation_path(const google_protobuf_GeneratedCodeInfo_Annotation* msg, size_t* size) { const upb_MiniTableField field = {1, UPB_SIZE(4, 16), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsPacked | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -11109,7 +11118,7 @@ UPB_INLINE upb_Array* _google_protobuf_GeneratedCodeInfo_Annotation_path_mutable } UPB_INLINE void google_protobuf_GeneratedCodeInfo_Annotation_clear_source_file(google_protobuf_GeneratedCodeInfo_Annotation* msg) { const upb_MiniTableField field = {2, UPB_SIZE(20, 24), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_GeneratedCodeInfo_Annotation_source_file(const google_protobuf_GeneratedCodeInfo_Annotation* msg) { upb_StringView default_val = upb_StringView_FromString(""); @@ -11125,7 +11134,7 @@ UPB_INLINE bool google_protobuf_GeneratedCodeInfo_Annotation_has_source_file(con } UPB_INLINE void google_protobuf_GeneratedCodeInfo_Annotation_clear_begin(google_protobuf_GeneratedCodeInfo_Annotation* msg) { const upb_MiniTableField field = {3, UPB_SIZE(8, 4), 2, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_GeneratedCodeInfo_Annotation_begin(const google_protobuf_GeneratedCodeInfo_Annotation* msg) { int32_t default_val = (int32_t)0; @@ -11141,7 +11150,7 @@ UPB_INLINE bool google_protobuf_GeneratedCodeInfo_Annotation_has_begin(const goo } UPB_INLINE void google_protobuf_GeneratedCodeInfo_Annotation_clear_end(google_protobuf_GeneratedCodeInfo_Annotation* msg) { const upb_MiniTableField field = {4, UPB_SIZE(12, 8), 3, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_GeneratedCodeInfo_Annotation_end(const google_protobuf_GeneratedCodeInfo_Annotation* msg) { int32_t default_val = (int32_t)0; @@ -11157,7 +11166,7 @@ UPB_INLINE bool google_protobuf_GeneratedCodeInfo_Annotation_has_end(const googl } UPB_INLINE void google_protobuf_GeneratedCodeInfo_Annotation_clear_semantic(google_protobuf_GeneratedCodeInfo_Annotation* msg) { const upb_MiniTableField field = {5, UPB_SIZE(16, 12), 4, 0, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_GeneratedCodeInfo_Annotation_semantic(const google_protobuf_GeneratedCodeInfo_Annotation* msg) { int32_t default_val = 0; @@ -11497,6 +11506,8 @@ const UPB_DESC(FeatureSet) * #ifndef UPB_REFLECTION_FIELD_DEF_H_ #define UPB_REFLECTION_FIELD_DEF_H_ +#include + // Must be last. @@ -11542,6 +11553,8 @@ bool upb_FieldDef_MiniDescriptorEncode(const upb_FieldDef* f, upb_Arena* a, upb_StringView* out); const upb_MiniTableField* upb_FieldDef_MiniTable(const upb_FieldDef* f); +const upb_MiniTableExtension* upb_FieldDef_MiniTableExtension( + const upb_FieldDef* f); UPB_API const char* upb_FieldDef_Name(const upb_FieldDef* f); UPB_API uint32_t upb_FieldDef_Number(const upb_FieldDef* f); const UPB_DESC(FieldOptions) * upb_FieldDef_Options(const upb_FieldDef* f); @@ -13511,8 +13524,6 @@ extern "C" { upb_FieldDef* _upb_FieldDef_At(const upb_FieldDef* f, int i); -const upb_MiniTableExtension* _upb_FieldDef_ExtensionMiniTable( - const upb_FieldDef* f); bool _upb_FieldDef_IsClosedEnum(const upb_FieldDef* f); bool _upb_FieldDef_IsProto3Optional(const upb_FieldDef* f); int _upb_FieldDef_LayoutIndex(const upb_FieldDef* f); diff --git a/upb/cmake/google/protobuf/descriptor.upb.h b/upb/cmake/google/protobuf/descriptor.upb.h index b872bb6ef6f1c..95d76292abfa3 100644 --- a/upb/cmake/google/protobuf/descriptor.upb.h +++ b/upb/cmake/google/protobuf/descriptor.upb.h @@ -223,7 +223,7 @@ UPB_INLINE char* google_protobuf_FileDescriptorSet_serialize_ex(const google_pro } UPB_INLINE void google_protobuf_FileDescriptorSet_clear_file(google_protobuf_FileDescriptorSet* msg) { const upb_MiniTableField field = {1, 0, 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_FileDescriptorProto* const* google_protobuf_FileDescriptorSet_file(const google_protobuf_FileDescriptorSet* msg, size_t* size) { const upb_MiniTableField field = {1, 0, 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -323,7 +323,7 @@ UPB_INLINE char* google_protobuf_FileDescriptorProto_serialize_ex(const google_p } UPB_INLINE void google_protobuf_FileDescriptorProto_clear_name(google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = {1, UPB_SIZE(44, 8), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_FileDescriptorProto_name(const google_protobuf_FileDescriptorProto* msg) { upb_StringView default_val = upb_StringView_FromString(""); @@ -339,7 +339,7 @@ UPB_INLINE bool google_protobuf_FileDescriptorProto_has_name(const google_protob } UPB_INLINE void google_protobuf_FileDescriptorProto_clear_package(google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = {2, UPB_SIZE(52, 24), 2, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_FileDescriptorProto_package(const google_protobuf_FileDescriptorProto* msg) { upb_StringView default_val = upb_StringView_FromString(""); @@ -355,7 +355,7 @@ UPB_INLINE bool google_protobuf_FileDescriptorProto_has_package(const google_pro } UPB_INLINE void google_protobuf_FileDescriptorProto_clear_dependency(google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = {3, UPB_SIZE(4, 40), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView const* google_protobuf_FileDescriptorProto_dependency(const google_protobuf_FileDescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {3, UPB_SIZE(4, 40), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -387,7 +387,7 @@ UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_dependency_mutable_up } UPB_INLINE void google_protobuf_FileDescriptorProto_clear_message_type(google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = {4, UPB_SIZE(8, 48), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_DescriptorProto* const* google_protobuf_FileDescriptorProto_message_type(const google_protobuf_FileDescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {4, UPB_SIZE(8, 48), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -419,7 +419,7 @@ UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_message_type_mutable_ } UPB_INLINE void google_protobuf_FileDescriptorProto_clear_enum_type(google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = {5, UPB_SIZE(12, 56), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_EnumDescriptorProto* const* google_protobuf_FileDescriptorProto_enum_type(const google_protobuf_FileDescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {5, UPB_SIZE(12, 56), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -451,7 +451,7 @@ UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_enum_type_mutable_upb } UPB_INLINE void google_protobuf_FileDescriptorProto_clear_service(google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = {6, UPB_SIZE(16, 64), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_ServiceDescriptorProto* const* google_protobuf_FileDescriptorProto_service(const google_protobuf_FileDescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {6, UPB_SIZE(16, 64), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -483,7 +483,7 @@ UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_service_mutable_upb_a } UPB_INLINE void google_protobuf_FileDescriptorProto_clear_extension(google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = {7, UPB_SIZE(20, 72), 0, 3, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_FieldDescriptorProto* const* google_protobuf_FileDescriptorProto_extension(const google_protobuf_FileDescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {7, UPB_SIZE(20, 72), 0, 3, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -515,7 +515,7 @@ UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_extension_mutable_upb } UPB_INLINE void google_protobuf_FileDescriptorProto_clear_options(google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = {8, UPB_SIZE(24, 80), 3, 4, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_FileOptions* google_protobuf_FileDescriptorProto_options(const google_protobuf_FileDescriptorProto* msg) { const google_protobuf_FileOptions* default_val = NULL; @@ -531,7 +531,7 @@ UPB_INLINE bool google_protobuf_FileDescriptorProto_has_options(const google_pro } UPB_INLINE void google_protobuf_FileDescriptorProto_clear_source_code_info(google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = {9, UPB_SIZE(28, 88), 4, 5, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_SourceCodeInfo* google_protobuf_FileDescriptorProto_source_code_info(const google_protobuf_FileDescriptorProto* msg) { const google_protobuf_SourceCodeInfo* default_val = NULL; @@ -547,7 +547,7 @@ UPB_INLINE bool google_protobuf_FileDescriptorProto_has_source_code_info(const g } UPB_INLINE void google_protobuf_FileDescriptorProto_clear_public_dependency(google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = {10, UPB_SIZE(32, 96), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t const* google_protobuf_FileDescriptorProto_public_dependency(const google_protobuf_FileDescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {10, UPB_SIZE(32, 96), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -579,7 +579,7 @@ UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_public_dependency_mut } UPB_INLINE void google_protobuf_FileDescriptorProto_clear_weak_dependency(google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = {11, UPB_SIZE(36, 104), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t const* google_protobuf_FileDescriptorProto_weak_dependency(const google_protobuf_FileDescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {11, UPB_SIZE(36, 104), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -611,7 +611,7 @@ UPB_INLINE upb_Array* _google_protobuf_FileDescriptorProto_weak_dependency_mutab } UPB_INLINE void google_protobuf_FileDescriptorProto_clear_syntax(google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = {12, UPB_SIZE(60, 112), 5, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_FileDescriptorProto_syntax(const google_protobuf_FileDescriptorProto* msg) { upb_StringView default_val = upb_StringView_FromString(""); @@ -627,7 +627,7 @@ UPB_INLINE bool google_protobuf_FileDescriptorProto_has_syntax(const google_prot } UPB_INLINE void google_protobuf_FileDescriptorProto_clear_edition(google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = {14, UPB_SIZE(40, 4), 6, 6, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_FileDescriptorProto_edition(const google_protobuf_FileDescriptorProto* msg) { int32_t default_val = 0; @@ -925,7 +925,7 @@ UPB_INLINE char* google_protobuf_DescriptorProto_serialize_ex(const google_proto } UPB_INLINE void google_protobuf_DescriptorProto_clear_name(google_protobuf_DescriptorProto* msg) { const upb_MiniTableField field = {1, UPB_SIZE(40, 8), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_DescriptorProto_name(const google_protobuf_DescriptorProto* msg) { upb_StringView default_val = upb_StringView_FromString(""); @@ -941,7 +941,7 @@ UPB_INLINE bool google_protobuf_DescriptorProto_has_name(const google_protobuf_D } UPB_INLINE void google_protobuf_DescriptorProto_clear_field(google_protobuf_DescriptorProto* msg) { const upb_MiniTableField field = {2, UPB_SIZE(4, 24), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_FieldDescriptorProto* const* google_protobuf_DescriptorProto_field(const google_protobuf_DescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {2, UPB_SIZE(4, 24), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -973,7 +973,7 @@ UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_field_mutable_upb_array(g } UPB_INLINE void google_protobuf_DescriptorProto_clear_nested_type(google_protobuf_DescriptorProto* msg) { const upb_MiniTableField field = {3, UPB_SIZE(8, 32), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_DescriptorProto* const* google_protobuf_DescriptorProto_nested_type(const google_protobuf_DescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {3, UPB_SIZE(8, 32), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -1005,7 +1005,7 @@ UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_nested_type_mutable_upb_a } UPB_INLINE void google_protobuf_DescriptorProto_clear_enum_type(google_protobuf_DescriptorProto* msg) { const upb_MiniTableField field = {4, UPB_SIZE(12, 40), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_EnumDescriptorProto* const* google_protobuf_DescriptorProto_enum_type(const google_protobuf_DescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {4, UPB_SIZE(12, 40), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -1037,7 +1037,7 @@ UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_enum_type_mutable_upb_arr } UPB_INLINE void google_protobuf_DescriptorProto_clear_extension_range(google_protobuf_DescriptorProto* msg) { const upb_MiniTableField field = {5, UPB_SIZE(16, 48), 0, 3, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_DescriptorProto_ExtensionRange* const* google_protobuf_DescriptorProto_extension_range(const google_protobuf_DescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {5, UPB_SIZE(16, 48), 0, 3, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -1069,7 +1069,7 @@ UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_extension_range_mutable_u } UPB_INLINE void google_protobuf_DescriptorProto_clear_extension(google_protobuf_DescriptorProto* msg) { const upb_MiniTableField field = {6, UPB_SIZE(20, 56), 0, 4, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_FieldDescriptorProto* const* google_protobuf_DescriptorProto_extension(const google_protobuf_DescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {6, UPB_SIZE(20, 56), 0, 4, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -1101,7 +1101,7 @@ UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_extension_mutable_upb_arr } UPB_INLINE void google_protobuf_DescriptorProto_clear_options(google_protobuf_DescriptorProto* msg) { const upb_MiniTableField field = {7, UPB_SIZE(24, 64), 2, 5, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_MessageOptions* google_protobuf_DescriptorProto_options(const google_protobuf_DescriptorProto* msg) { const google_protobuf_MessageOptions* default_val = NULL; @@ -1117,7 +1117,7 @@ UPB_INLINE bool google_protobuf_DescriptorProto_has_options(const google_protobu } UPB_INLINE void google_protobuf_DescriptorProto_clear_oneof_decl(google_protobuf_DescriptorProto* msg) { const upb_MiniTableField field = {8, UPB_SIZE(28, 72), 0, 6, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_OneofDescriptorProto* const* google_protobuf_DescriptorProto_oneof_decl(const google_protobuf_DescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {8, UPB_SIZE(28, 72), 0, 6, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -1149,7 +1149,7 @@ UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_oneof_decl_mutable_upb_ar } UPB_INLINE void google_protobuf_DescriptorProto_clear_reserved_range(google_protobuf_DescriptorProto* msg) { const upb_MiniTableField field = {9, UPB_SIZE(32, 80), 0, 7, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_DescriptorProto_ReservedRange* const* google_protobuf_DescriptorProto_reserved_range(const google_protobuf_DescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {9, UPB_SIZE(32, 80), 0, 7, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -1181,7 +1181,7 @@ UPB_INLINE upb_Array* _google_protobuf_DescriptorProto_reserved_range_mutable_up } UPB_INLINE void google_protobuf_DescriptorProto_clear_reserved_name(google_protobuf_DescriptorProto* msg) { const upb_MiniTableField field = {10, UPB_SIZE(36, 88), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView const* google_protobuf_DescriptorProto_reserved_name(const google_protobuf_DescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {10, UPB_SIZE(36, 88), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -1505,7 +1505,7 @@ UPB_INLINE char* google_protobuf_DescriptorProto_ExtensionRange_serialize_ex(con } UPB_INLINE void google_protobuf_DescriptorProto_ExtensionRange_clear_start(google_protobuf_DescriptorProto_ExtensionRange* msg) { const upb_MiniTableField field = {1, 4, 1, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_DescriptorProto_ExtensionRange_start(const google_protobuf_DescriptorProto_ExtensionRange* msg) { int32_t default_val = (int32_t)0; @@ -1521,7 +1521,7 @@ UPB_INLINE bool google_protobuf_DescriptorProto_ExtensionRange_has_start(const g } UPB_INLINE void google_protobuf_DescriptorProto_ExtensionRange_clear_end(google_protobuf_DescriptorProto_ExtensionRange* msg) { const upb_MiniTableField field = {2, 8, 2, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_DescriptorProto_ExtensionRange_end(const google_protobuf_DescriptorProto_ExtensionRange* msg) { int32_t default_val = (int32_t)0; @@ -1537,7 +1537,7 @@ UPB_INLINE bool google_protobuf_DescriptorProto_ExtensionRange_has_end(const goo } UPB_INLINE void google_protobuf_DescriptorProto_ExtensionRange_clear_options(google_protobuf_DescriptorProto_ExtensionRange* msg) { const upb_MiniTableField field = {3, UPB_SIZE(12, 16), 3, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_ExtensionRangeOptions* google_protobuf_DescriptorProto_ExtensionRange_options(const google_protobuf_DescriptorProto_ExtensionRange* msg) { const google_protobuf_ExtensionRangeOptions* default_val = NULL; @@ -1611,7 +1611,7 @@ UPB_INLINE char* google_protobuf_DescriptorProto_ReservedRange_serialize_ex(cons } UPB_INLINE void google_protobuf_DescriptorProto_ReservedRange_clear_start(google_protobuf_DescriptorProto_ReservedRange* msg) { const upb_MiniTableField field = {1, 4, 1, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_DescriptorProto_ReservedRange_start(const google_protobuf_DescriptorProto_ReservedRange* msg) { int32_t default_val = (int32_t)0; @@ -1627,7 +1627,7 @@ UPB_INLINE bool google_protobuf_DescriptorProto_ReservedRange_has_start(const go } UPB_INLINE void google_protobuf_DescriptorProto_ReservedRange_clear_end(google_protobuf_DescriptorProto_ReservedRange* msg) { const upb_MiniTableField field = {2, 8, 2, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_DescriptorProto_ReservedRange_end(const google_protobuf_DescriptorProto_ReservedRange* msg) { int32_t default_val = (int32_t)0; @@ -1689,7 +1689,7 @@ UPB_INLINE char* google_protobuf_ExtensionRangeOptions_serialize_ex(const google } UPB_INLINE void google_protobuf_ExtensionRangeOptions_clear_declaration(google_protobuf_ExtensionRangeOptions* msg) { const upb_MiniTableField field = {2, UPB_SIZE(4, 8), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_ExtensionRangeOptions_Declaration* const* google_protobuf_ExtensionRangeOptions_declaration(const google_protobuf_ExtensionRangeOptions* msg, size_t* size) { const upb_MiniTableField field = {2, UPB_SIZE(4, 8), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -1721,7 +1721,7 @@ UPB_INLINE upb_Array* _google_protobuf_ExtensionRangeOptions_declaration_mutable } UPB_INLINE void google_protobuf_ExtensionRangeOptions_clear_verification(google_protobuf_ExtensionRangeOptions* msg) { const upb_MiniTableField field = {3, UPB_SIZE(8, 4), 1, 3, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_ExtensionRangeOptions_verification(const google_protobuf_ExtensionRangeOptions* msg) { int32_t default_val = 1; @@ -1737,7 +1737,7 @@ UPB_INLINE bool google_protobuf_ExtensionRangeOptions_has_verification(const goo } UPB_INLINE void google_protobuf_ExtensionRangeOptions_clear_features(google_protobuf_ExtensionRangeOptions* msg) { const upb_MiniTableField field = {50, UPB_SIZE(12, 16), 2, 1, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_FeatureSet* google_protobuf_ExtensionRangeOptions_features(const google_protobuf_ExtensionRangeOptions* msg) { const google_protobuf_FeatureSet* default_val = NULL; @@ -1753,7 +1753,7 @@ UPB_INLINE bool google_protobuf_ExtensionRangeOptions_has_features(const google_ } UPB_INLINE void google_protobuf_ExtensionRangeOptions_clear_uninterpreted_option(google_protobuf_ExtensionRangeOptions* msg) { const upb_MiniTableField field = {999, UPB_SIZE(16, 24), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_ExtensionRangeOptions_uninterpreted_option(const google_protobuf_ExtensionRangeOptions* msg, size_t* size) { const upb_MiniTableField field = {999, UPB_SIZE(16, 24), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -1899,7 +1899,7 @@ UPB_INLINE char* google_protobuf_ExtensionRangeOptions_Declaration_serialize_ex( } UPB_INLINE void google_protobuf_ExtensionRangeOptions_Declaration_clear_number(google_protobuf_ExtensionRangeOptions_Declaration* msg) { const upb_MiniTableField field = {1, 4, 1, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_ExtensionRangeOptions_Declaration_number(const google_protobuf_ExtensionRangeOptions_Declaration* msg) { int32_t default_val = (int32_t)0; @@ -1915,7 +1915,7 @@ UPB_INLINE bool google_protobuf_ExtensionRangeOptions_Declaration_has_number(con } UPB_INLINE void google_protobuf_ExtensionRangeOptions_Declaration_clear_full_name(google_protobuf_ExtensionRangeOptions_Declaration* msg) { const upb_MiniTableField field = {2, UPB_SIZE(12, 16), 2, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_ExtensionRangeOptions_Declaration_full_name(const google_protobuf_ExtensionRangeOptions_Declaration* msg) { upb_StringView default_val = upb_StringView_FromString(""); @@ -1931,7 +1931,7 @@ UPB_INLINE bool google_protobuf_ExtensionRangeOptions_Declaration_has_full_name( } UPB_INLINE void google_protobuf_ExtensionRangeOptions_Declaration_clear_type(google_protobuf_ExtensionRangeOptions_Declaration* msg) { const upb_MiniTableField field = {3, UPB_SIZE(20, 32), 3, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_ExtensionRangeOptions_Declaration_type(const google_protobuf_ExtensionRangeOptions_Declaration* msg) { upb_StringView default_val = upb_StringView_FromString(""); @@ -1947,7 +1947,7 @@ UPB_INLINE bool google_protobuf_ExtensionRangeOptions_Declaration_has_type(const } UPB_INLINE void google_protobuf_ExtensionRangeOptions_Declaration_clear_reserved(google_protobuf_ExtensionRangeOptions_Declaration* msg) { const upb_MiniTableField field = {5, 8, 4, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_ExtensionRangeOptions_Declaration_reserved(const google_protobuf_ExtensionRangeOptions_Declaration* msg) { bool default_val = false; @@ -1963,7 +1963,7 @@ UPB_INLINE bool google_protobuf_ExtensionRangeOptions_Declaration_has_reserved(c } UPB_INLINE void google_protobuf_ExtensionRangeOptions_Declaration_clear_repeated(google_protobuf_ExtensionRangeOptions_Declaration* msg) { const upb_MiniTableField field = {6, 9, 5, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_ExtensionRangeOptions_Declaration_repeated(const google_protobuf_ExtensionRangeOptions_Declaration* msg) { bool default_val = false; @@ -2037,7 +2037,7 @@ UPB_INLINE char* google_protobuf_FieldDescriptorProto_serialize_ex(const google_ } UPB_INLINE void google_protobuf_FieldDescriptorProto_clear_name(google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = {1, UPB_SIZE(28, 24), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_FieldDescriptorProto_name(const google_protobuf_FieldDescriptorProto* msg) { upb_StringView default_val = upb_StringView_FromString(""); @@ -2053,7 +2053,7 @@ UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_name(const google_proto } UPB_INLINE void google_protobuf_FieldDescriptorProto_clear_extendee(google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = {2, UPB_SIZE(36, 40), 2, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_FieldDescriptorProto_extendee(const google_protobuf_FieldDescriptorProto* msg) { upb_StringView default_val = upb_StringView_FromString(""); @@ -2069,7 +2069,7 @@ UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_extendee(const google_p } UPB_INLINE void google_protobuf_FieldDescriptorProto_clear_number(google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = {3, 4, 3, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_FieldDescriptorProto_number(const google_protobuf_FieldDescriptorProto* msg) { int32_t default_val = (int32_t)0; @@ -2085,7 +2085,7 @@ UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_number(const google_pro } UPB_INLINE void google_protobuf_FieldDescriptorProto_clear_label(google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = {4, 8, 4, 1, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_FieldDescriptorProto_label(const google_protobuf_FieldDescriptorProto* msg) { int32_t default_val = 1; @@ -2101,7 +2101,7 @@ UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_label(const google_prot } UPB_INLINE void google_protobuf_FieldDescriptorProto_clear_type(google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = {5, 12, 5, 2, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_FieldDescriptorProto_type(const google_protobuf_FieldDescriptorProto* msg) { int32_t default_val = 1; @@ -2117,7 +2117,7 @@ UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_type(const google_proto } UPB_INLINE void google_protobuf_FieldDescriptorProto_clear_type_name(google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = {6, UPB_SIZE(44, 56), 6, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_FieldDescriptorProto_type_name(const google_protobuf_FieldDescriptorProto* msg) { upb_StringView default_val = upb_StringView_FromString(""); @@ -2133,7 +2133,7 @@ UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_type_name(const google_ } UPB_INLINE void google_protobuf_FieldDescriptorProto_clear_default_value(google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = {7, UPB_SIZE(52, 72), 7, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_FieldDescriptorProto_default_value(const google_protobuf_FieldDescriptorProto* msg) { upb_StringView default_val = upb_StringView_FromString(""); @@ -2149,7 +2149,7 @@ UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_default_value(const goo } UPB_INLINE void google_protobuf_FieldDescriptorProto_clear_options(google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = {8, UPB_SIZE(16, 88), 8, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_FieldOptions* google_protobuf_FieldDescriptorProto_options(const google_protobuf_FieldDescriptorProto* msg) { const google_protobuf_FieldOptions* default_val = NULL; @@ -2165,7 +2165,7 @@ UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_options(const google_pr } UPB_INLINE void google_protobuf_FieldDescriptorProto_clear_oneof_index(google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = {9, UPB_SIZE(20, 16), 9, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_FieldDescriptorProto_oneof_index(const google_protobuf_FieldDescriptorProto* msg) { int32_t default_val = (int32_t)0; @@ -2181,7 +2181,7 @@ UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_oneof_index(const googl } UPB_INLINE void google_protobuf_FieldDescriptorProto_clear_json_name(google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = {10, UPB_SIZE(60, 96), 10, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_FieldDescriptorProto_json_name(const google_protobuf_FieldDescriptorProto* msg) { upb_StringView default_val = upb_StringView_FromString(""); @@ -2197,7 +2197,7 @@ UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_json_name(const google_ } UPB_INLINE void google_protobuf_FieldDescriptorProto_clear_proto3_optional(google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = {17, UPB_SIZE(24, 20), 11, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_FieldDescriptorProto_proto3_optional(const google_protobuf_FieldDescriptorProto* msg) { bool default_val = false; @@ -2303,7 +2303,7 @@ UPB_INLINE char* google_protobuf_OneofDescriptorProto_serialize_ex(const google_ } UPB_INLINE void google_protobuf_OneofDescriptorProto_clear_name(google_protobuf_OneofDescriptorProto* msg) { const upb_MiniTableField field = {1, 8, 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_OneofDescriptorProto_name(const google_protobuf_OneofDescriptorProto* msg) { upb_StringView default_val = upb_StringView_FromString(""); @@ -2319,7 +2319,7 @@ UPB_INLINE bool google_protobuf_OneofDescriptorProto_has_name(const google_proto } UPB_INLINE void google_protobuf_OneofDescriptorProto_clear_options(google_protobuf_OneofDescriptorProto* msg) { const upb_MiniTableField field = {2, UPB_SIZE(4, 24), 2, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_OneofOptions* google_protobuf_OneofDescriptorProto_options(const google_protobuf_OneofDescriptorProto* msg) { const google_protobuf_OneofOptions* default_val = NULL; @@ -2389,7 +2389,7 @@ UPB_INLINE char* google_protobuf_EnumDescriptorProto_serialize_ex(const google_p } UPB_INLINE void google_protobuf_EnumDescriptorProto_clear_name(google_protobuf_EnumDescriptorProto* msg) { const upb_MiniTableField field = {1, UPB_SIZE(20, 8), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_EnumDescriptorProto_name(const google_protobuf_EnumDescriptorProto* msg) { upb_StringView default_val = upb_StringView_FromString(""); @@ -2405,7 +2405,7 @@ UPB_INLINE bool google_protobuf_EnumDescriptorProto_has_name(const google_protob } UPB_INLINE void google_protobuf_EnumDescriptorProto_clear_value(google_protobuf_EnumDescriptorProto* msg) { const upb_MiniTableField field = {2, UPB_SIZE(4, 24), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_EnumValueDescriptorProto* const* google_protobuf_EnumDescriptorProto_value(const google_protobuf_EnumDescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {2, UPB_SIZE(4, 24), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -2437,7 +2437,7 @@ UPB_INLINE upb_Array* _google_protobuf_EnumDescriptorProto_value_mutable_upb_arr } UPB_INLINE void google_protobuf_EnumDescriptorProto_clear_options(google_protobuf_EnumDescriptorProto* msg) { const upb_MiniTableField field = {3, UPB_SIZE(8, 32), 2, 1, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_EnumOptions* google_protobuf_EnumDescriptorProto_options(const google_protobuf_EnumDescriptorProto* msg) { const google_protobuf_EnumOptions* default_val = NULL; @@ -2453,7 +2453,7 @@ UPB_INLINE bool google_protobuf_EnumDescriptorProto_has_options(const google_pro } UPB_INLINE void google_protobuf_EnumDescriptorProto_clear_reserved_range(google_protobuf_EnumDescriptorProto* msg) { const upb_MiniTableField field = {4, UPB_SIZE(12, 40), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_EnumDescriptorProto_EnumReservedRange* const* google_protobuf_EnumDescriptorProto_reserved_range(const google_protobuf_EnumDescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {4, UPB_SIZE(12, 40), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -2485,7 +2485,7 @@ UPB_INLINE upb_Array* _google_protobuf_EnumDescriptorProto_reserved_range_mutabl } UPB_INLINE void google_protobuf_EnumDescriptorProto_clear_reserved_name(google_protobuf_EnumDescriptorProto* msg) { const upb_MiniTableField field = {5, UPB_SIZE(16, 48), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView const* google_protobuf_EnumDescriptorProto_reserved_name(const google_protobuf_EnumDescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {5, UPB_SIZE(16, 48), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -2659,7 +2659,7 @@ UPB_INLINE char* google_protobuf_EnumDescriptorProto_EnumReservedRange_serialize } UPB_INLINE void google_protobuf_EnumDescriptorProto_EnumReservedRange_clear_start(google_protobuf_EnumDescriptorProto_EnumReservedRange* msg) { const upb_MiniTableField field = {1, 4, 1, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_EnumDescriptorProto_EnumReservedRange_start(const google_protobuf_EnumDescriptorProto_EnumReservedRange* msg) { int32_t default_val = (int32_t)0; @@ -2675,7 +2675,7 @@ UPB_INLINE bool google_protobuf_EnumDescriptorProto_EnumReservedRange_has_start( } UPB_INLINE void google_protobuf_EnumDescriptorProto_EnumReservedRange_clear_end(google_protobuf_EnumDescriptorProto_EnumReservedRange* msg) { const upb_MiniTableField field = {2, 8, 2, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_EnumDescriptorProto_EnumReservedRange_end(const google_protobuf_EnumDescriptorProto_EnumReservedRange* msg) { int32_t default_val = (int32_t)0; @@ -2737,7 +2737,7 @@ UPB_INLINE char* google_protobuf_EnumValueDescriptorProto_serialize_ex(const goo } UPB_INLINE void google_protobuf_EnumValueDescriptorProto_clear_name(google_protobuf_EnumValueDescriptorProto* msg) { const upb_MiniTableField field = {1, UPB_SIZE(12, 8), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_EnumValueDescriptorProto_name(const google_protobuf_EnumValueDescriptorProto* msg) { upb_StringView default_val = upb_StringView_FromString(""); @@ -2753,7 +2753,7 @@ UPB_INLINE bool google_protobuf_EnumValueDescriptorProto_has_name(const google_p } UPB_INLINE void google_protobuf_EnumValueDescriptorProto_clear_number(google_protobuf_EnumValueDescriptorProto* msg) { const upb_MiniTableField field = {2, 4, 2, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_EnumValueDescriptorProto_number(const google_protobuf_EnumValueDescriptorProto* msg) { int32_t default_val = (int32_t)0; @@ -2769,7 +2769,7 @@ UPB_INLINE bool google_protobuf_EnumValueDescriptorProto_has_number(const google } UPB_INLINE void google_protobuf_EnumValueDescriptorProto_clear_options(google_protobuf_EnumValueDescriptorProto* msg) { const upb_MiniTableField field = {3, UPB_SIZE(8, 24), 3, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_EnumValueOptions* google_protobuf_EnumValueDescriptorProto_options(const google_protobuf_EnumValueDescriptorProto* msg) { const google_protobuf_EnumValueOptions* default_val = NULL; @@ -2843,7 +2843,7 @@ UPB_INLINE char* google_protobuf_ServiceDescriptorProto_serialize_ex(const googl } UPB_INLINE void google_protobuf_ServiceDescriptorProto_clear_name(google_protobuf_ServiceDescriptorProto* msg) { const upb_MiniTableField field = {1, UPB_SIZE(12, 8), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_ServiceDescriptorProto_name(const google_protobuf_ServiceDescriptorProto* msg) { upb_StringView default_val = upb_StringView_FromString(""); @@ -2859,7 +2859,7 @@ UPB_INLINE bool google_protobuf_ServiceDescriptorProto_has_name(const google_pro } UPB_INLINE void google_protobuf_ServiceDescriptorProto_clear_method(google_protobuf_ServiceDescriptorProto* msg) { const upb_MiniTableField field = {2, UPB_SIZE(4, 24), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_MethodDescriptorProto* const* google_protobuf_ServiceDescriptorProto_method(const google_protobuf_ServiceDescriptorProto* msg, size_t* size) { const upb_MiniTableField field = {2, UPB_SIZE(4, 24), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -2891,7 +2891,7 @@ UPB_INLINE upb_Array* _google_protobuf_ServiceDescriptorProto_method_mutable_upb } UPB_INLINE void google_protobuf_ServiceDescriptorProto_clear_options(google_protobuf_ServiceDescriptorProto* msg) { const upb_MiniTableField field = {3, UPB_SIZE(8, 32), 2, 1, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_ServiceOptions* google_protobuf_ServiceDescriptorProto_options(const google_protobuf_ServiceDescriptorProto* msg) { const google_protobuf_ServiceOptions* default_val = NULL; @@ -2991,7 +2991,7 @@ UPB_INLINE char* google_protobuf_MethodDescriptorProto_serialize_ex(const google } UPB_INLINE void google_protobuf_MethodDescriptorProto_clear_name(google_protobuf_MethodDescriptorProto* msg) { const upb_MiniTableField field = {1, UPB_SIZE(12, 8), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_MethodDescriptorProto_name(const google_protobuf_MethodDescriptorProto* msg) { upb_StringView default_val = upb_StringView_FromString(""); @@ -3007,7 +3007,7 @@ UPB_INLINE bool google_protobuf_MethodDescriptorProto_has_name(const google_prot } UPB_INLINE void google_protobuf_MethodDescriptorProto_clear_input_type(google_protobuf_MethodDescriptorProto* msg) { const upb_MiniTableField field = {2, UPB_SIZE(20, 24), 2, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_MethodDescriptorProto_input_type(const google_protobuf_MethodDescriptorProto* msg) { upb_StringView default_val = upb_StringView_FromString(""); @@ -3023,7 +3023,7 @@ UPB_INLINE bool google_protobuf_MethodDescriptorProto_has_input_type(const googl } UPB_INLINE void google_protobuf_MethodDescriptorProto_clear_output_type(google_protobuf_MethodDescriptorProto* msg) { const upb_MiniTableField field = {3, UPB_SIZE(28, 40), 3, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_MethodDescriptorProto_output_type(const google_protobuf_MethodDescriptorProto* msg) { upb_StringView default_val = upb_StringView_FromString(""); @@ -3039,7 +3039,7 @@ UPB_INLINE bool google_protobuf_MethodDescriptorProto_has_output_type(const goog } UPB_INLINE void google_protobuf_MethodDescriptorProto_clear_options(google_protobuf_MethodDescriptorProto* msg) { const upb_MiniTableField field = {4, UPB_SIZE(4, 56), 4, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_MethodOptions* google_protobuf_MethodDescriptorProto_options(const google_protobuf_MethodDescriptorProto* msg) { const google_protobuf_MethodOptions* default_val = NULL; @@ -3055,7 +3055,7 @@ UPB_INLINE bool google_protobuf_MethodDescriptorProto_has_options(const google_p } UPB_INLINE void google_protobuf_MethodDescriptorProto_clear_client_streaming(google_protobuf_MethodDescriptorProto* msg) { const upb_MiniTableField field = {5, UPB_SIZE(8, 1), 5, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_MethodDescriptorProto_client_streaming(const google_protobuf_MethodDescriptorProto* msg) { bool default_val = false; @@ -3071,7 +3071,7 @@ UPB_INLINE bool google_protobuf_MethodDescriptorProto_has_client_streaming(const } UPB_INLINE void google_protobuf_MethodDescriptorProto_clear_server_streaming(google_protobuf_MethodDescriptorProto* msg) { const upb_MiniTableField field = {6, UPB_SIZE(9, 2), 6, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_MethodDescriptorProto_server_streaming(const google_protobuf_MethodDescriptorProto* msg) { bool default_val = false; @@ -3157,7 +3157,7 @@ UPB_INLINE char* google_protobuf_FileOptions_serialize_ex(const google_protobuf_ } UPB_INLINE void google_protobuf_FileOptions_clear_java_package(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {1, UPB_SIZE(24, 16), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_FileOptions_java_package(const google_protobuf_FileOptions* msg) { upb_StringView default_val = upb_StringView_FromString(""); @@ -3173,7 +3173,7 @@ UPB_INLINE bool google_protobuf_FileOptions_has_java_package(const google_protob } UPB_INLINE void google_protobuf_FileOptions_clear_java_outer_classname(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {8, 32, 2, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_FileOptions_java_outer_classname(const google_protobuf_FileOptions* msg) { upb_StringView default_val = upb_StringView_FromString(""); @@ -3189,7 +3189,7 @@ UPB_INLINE bool google_protobuf_FileOptions_has_java_outer_classname(const googl } UPB_INLINE void google_protobuf_FileOptions_clear_optimize_for(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {9, 4, 3, 2, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_FileOptions_optimize_for(const google_protobuf_FileOptions* msg) { int32_t default_val = 1; @@ -3205,7 +3205,7 @@ UPB_INLINE bool google_protobuf_FileOptions_has_optimize_for(const google_protob } UPB_INLINE void google_protobuf_FileOptions_clear_java_multiple_files(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {10, 8, 4, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_FileOptions_java_multiple_files(const google_protobuf_FileOptions* msg) { bool default_val = false; @@ -3221,7 +3221,7 @@ UPB_INLINE bool google_protobuf_FileOptions_has_java_multiple_files(const google } UPB_INLINE void google_protobuf_FileOptions_clear_go_package(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {11, UPB_SIZE(40, 48), 5, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_FileOptions_go_package(const google_protobuf_FileOptions* msg) { upb_StringView default_val = upb_StringView_FromString(""); @@ -3237,7 +3237,7 @@ UPB_INLINE bool google_protobuf_FileOptions_has_go_package(const google_protobuf } UPB_INLINE void google_protobuf_FileOptions_clear_cc_generic_services(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {16, 9, 6, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_FileOptions_cc_generic_services(const google_protobuf_FileOptions* msg) { bool default_val = false; @@ -3253,7 +3253,7 @@ UPB_INLINE bool google_protobuf_FileOptions_has_cc_generic_services(const google } UPB_INLINE void google_protobuf_FileOptions_clear_java_generic_services(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {17, 10, 7, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_FileOptions_java_generic_services(const google_protobuf_FileOptions* msg) { bool default_val = false; @@ -3269,7 +3269,7 @@ UPB_INLINE bool google_protobuf_FileOptions_has_java_generic_services(const goog } UPB_INLINE void google_protobuf_FileOptions_clear_py_generic_services(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {18, 11, 8, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_FileOptions_py_generic_services(const google_protobuf_FileOptions* msg) { bool default_val = false; @@ -3285,7 +3285,7 @@ UPB_INLINE bool google_protobuf_FileOptions_has_py_generic_services(const google } UPB_INLINE void google_protobuf_FileOptions_clear_java_generate_equals_and_hash(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {20, 12, 9, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_FileOptions_java_generate_equals_and_hash(const google_protobuf_FileOptions* msg) { bool default_val = false; @@ -3301,7 +3301,7 @@ UPB_INLINE bool google_protobuf_FileOptions_has_java_generate_equals_and_hash(co } UPB_INLINE void google_protobuf_FileOptions_clear_deprecated(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {23, 13, 10, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_FileOptions_deprecated(const google_protobuf_FileOptions* msg) { bool default_val = false; @@ -3317,7 +3317,7 @@ UPB_INLINE bool google_protobuf_FileOptions_has_deprecated(const google_protobuf } UPB_INLINE void google_protobuf_FileOptions_clear_java_string_check_utf8(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {27, 14, 11, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_FileOptions_java_string_check_utf8(const google_protobuf_FileOptions* msg) { bool default_val = false; @@ -3333,7 +3333,7 @@ UPB_INLINE bool google_protobuf_FileOptions_has_java_string_check_utf8(const goo } UPB_INLINE void google_protobuf_FileOptions_clear_cc_enable_arenas(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {31, 15, 12, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_FileOptions_cc_enable_arenas(const google_protobuf_FileOptions* msg) { bool default_val = true; @@ -3349,7 +3349,7 @@ UPB_INLINE bool google_protobuf_FileOptions_has_cc_enable_arenas(const google_pr } UPB_INLINE void google_protobuf_FileOptions_clear_objc_class_prefix(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {36, UPB_SIZE(48, 64), 13, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_FileOptions_objc_class_prefix(const google_protobuf_FileOptions* msg) { upb_StringView default_val = upb_StringView_FromString(""); @@ -3365,7 +3365,7 @@ UPB_INLINE bool google_protobuf_FileOptions_has_objc_class_prefix(const google_p } UPB_INLINE void google_protobuf_FileOptions_clear_csharp_namespace(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {37, UPB_SIZE(56, 80), 14, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_FileOptions_csharp_namespace(const google_protobuf_FileOptions* msg) { upb_StringView default_val = upb_StringView_FromString(""); @@ -3381,7 +3381,7 @@ UPB_INLINE bool google_protobuf_FileOptions_has_csharp_namespace(const google_pr } UPB_INLINE void google_protobuf_FileOptions_clear_swift_prefix(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {39, UPB_SIZE(64, 96), 15, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_FileOptions_swift_prefix(const google_protobuf_FileOptions* msg) { upb_StringView default_val = upb_StringView_FromString(""); @@ -3397,7 +3397,7 @@ UPB_INLINE bool google_protobuf_FileOptions_has_swift_prefix(const google_protob } UPB_INLINE void google_protobuf_FileOptions_clear_php_class_prefix(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {40, UPB_SIZE(72, 112), 16, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_FileOptions_php_class_prefix(const google_protobuf_FileOptions* msg) { upb_StringView default_val = upb_StringView_FromString(""); @@ -3413,7 +3413,7 @@ UPB_INLINE bool google_protobuf_FileOptions_has_php_class_prefix(const google_pr } UPB_INLINE void google_protobuf_FileOptions_clear_php_namespace(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {41, UPB_SIZE(80, 128), 17, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_FileOptions_php_namespace(const google_protobuf_FileOptions* msg) { upb_StringView default_val = upb_StringView_FromString(""); @@ -3429,7 +3429,7 @@ UPB_INLINE bool google_protobuf_FileOptions_has_php_namespace(const google_proto } UPB_INLINE void google_protobuf_FileOptions_clear_php_metadata_namespace(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {44, UPB_SIZE(88, 144), 18, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_FileOptions_php_metadata_namespace(const google_protobuf_FileOptions* msg) { upb_StringView default_val = upb_StringView_FromString(""); @@ -3445,7 +3445,7 @@ UPB_INLINE bool google_protobuf_FileOptions_has_php_metadata_namespace(const goo } UPB_INLINE void google_protobuf_FileOptions_clear_ruby_package(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {45, UPB_SIZE(96, 160), 19, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_FileOptions_ruby_package(const google_protobuf_FileOptions* msg) { upb_StringView default_val = upb_StringView_FromString(""); @@ -3461,7 +3461,7 @@ UPB_INLINE bool google_protobuf_FileOptions_has_ruby_package(const google_protob } UPB_INLINE void google_protobuf_FileOptions_clear_features(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {50, UPB_SIZE(16, 176), 20, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_FeatureSet* google_protobuf_FileOptions_features(const google_protobuf_FileOptions* msg) { const google_protobuf_FeatureSet* default_val = NULL; @@ -3477,7 +3477,7 @@ UPB_INLINE bool google_protobuf_FileOptions_has_features(const google_protobuf_F } UPB_INLINE void google_protobuf_FileOptions_clear_uninterpreted_option(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {999, UPB_SIZE(20, 184), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_FileOptions_uninterpreted_option(const google_protobuf_FileOptions* msg, size_t* size) { const upb_MiniTableField field = {999, UPB_SIZE(20, 184), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -3665,7 +3665,7 @@ UPB_INLINE char* google_protobuf_MessageOptions_serialize_ex(const google_protob } UPB_INLINE void google_protobuf_MessageOptions_clear_message_set_wire_format(google_protobuf_MessageOptions* msg) { const upb_MiniTableField field = {1, 1, 1, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_MessageOptions_message_set_wire_format(const google_protobuf_MessageOptions* msg) { bool default_val = false; @@ -3681,7 +3681,7 @@ UPB_INLINE bool google_protobuf_MessageOptions_has_message_set_wire_format(const } UPB_INLINE void google_protobuf_MessageOptions_clear_no_standard_descriptor_accessor(google_protobuf_MessageOptions* msg) { const upb_MiniTableField field = {2, 2, 2, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_MessageOptions_no_standard_descriptor_accessor(const google_protobuf_MessageOptions* msg) { bool default_val = false; @@ -3697,7 +3697,7 @@ UPB_INLINE bool google_protobuf_MessageOptions_has_no_standard_descriptor_access } UPB_INLINE void google_protobuf_MessageOptions_clear_deprecated(google_protobuf_MessageOptions* msg) { const upb_MiniTableField field = {3, 3, 3, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_MessageOptions_deprecated(const google_protobuf_MessageOptions* msg) { bool default_val = false; @@ -3713,7 +3713,7 @@ UPB_INLINE bool google_protobuf_MessageOptions_has_deprecated(const google_proto } UPB_INLINE void google_protobuf_MessageOptions_clear_map_entry(google_protobuf_MessageOptions* msg) { const upb_MiniTableField field = {7, 4, 4, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_MessageOptions_map_entry(const google_protobuf_MessageOptions* msg) { bool default_val = false; @@ -3729,7 +3729,7 @@ UPB_INLINE bool google_protobuf_MessageOptions_has_map_entry(const google_protob } UPB_INLINE void google_protobuf_MessageOptions_clear_deprecated_legacy_json_field_conflicts(google_protobuf_MessageOptions* msg) { const upb_MiniTableField field = {11, 5, 5, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_MessageOptions_deprecated_legacy_json_field_conflicts(const google_protobuf_MessageOptions* msg) { bool default_val = false; @@ -3745,7 +3745,7 @@ UPB_INLINE bool google_protobuf_MessageOptions_has_deprecated_legacy_json_field_ } UPB_INLINE void google_protobuf_MessageOptions_clear_features(google_protobuf_MessageOptions* msg) { const upb_MiniTableField field = {12, 8, 6, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_FeatureSet* google_protobuf_MessageOptions_features(const google_protobuf_MessageOptions* msg) { const google_protobuf_FeatureSet* default_val = NULL; @@ -3761,7 +3761,7 @@ UPB_INLINE bool google_protobuf_MessageOptions_has_features(const google_protobu } UPB_INLINE void google_protobuf_MessageOptions_clear_uninterpreted_option(google_protobuf_MessageOptions* msg) { const upb_MiniTableField field = {999, UPB_SIZE(12, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_MessageOptions_uninterpreted_option(const google_protobuf_MessageOptions* msg, size_t* size) { const upb_MiniTableField field = {999, UPB_SIZE(12, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -3893,7 +3893,7 @@ UPB_INLINE char* google_protobuf_FieldOptions_serialize_ex(const google_protobuf } UPB_INLINE void google_protobuf_FieldOptions_clear_ctype(google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {1, 4, 1, 3, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_FieldOptions_ctype(const google_protobuf_FieldOptions* msg) { int32_t default_val = 0; @@ -3909,7 +3909,7 @@ UPB_INLINE bool google_protobuf_FieldOptions_has_ctype(const google_protobuf_Fie } UPB_INLINE void google_protobuf_FieldOptions_clear_packed(google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {2, 8, 2, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_FieldOptions_packed(const google_protobuf_FieldOptions* msg) { bool default_val = false; @@ -3925,7 +3925,7 @@ UPB_INLINE bool google_protobuf_FieldOptions_has_packed(const google_protobuf_Fi } UPB_INLINE void google_protobuf_FieldOptions_clear_deprecated(google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {3, 9, 3, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_FieldOptions_deprecated(const google_protobuf_FieldOptions* msg) { bool default_val = false; @@ -3941,7 +3941,7 @@ UPB_INLINE bool google_protobuf_FieldOptions_has_deprecated(const google_protobu } UPB_INLINE void google_protobuf_FieldOptions_clear_lazy(google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {5, 10, 4, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_FieldOptions_lazy(const google_protobuf_FieldOptions* msg) { bool default_val = false; @@ -3957,7 +3957,7 @@ UPB_INLINE bool google_protobuf_FieldOptions_has_lazy(const google_protobuf_Fiel } UPB_INLINE void google_protobuf_FieldOptions_clear_jstype(google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {6, 12, 5, 4, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_FieldOptions_jstype(const google_protobuf_FieldOptions* msg) { int32_t default_val = 0; @@ -3973,7 +3973,7 @@ UPB_INLINE bool google_protobuf_FieldOptions_has_jstype(const google_protobuf_Fi } UPB_INLINE void google_protobuf_FieldOptions_clear_weak(google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {10, 16, 6, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_FieldOptions_weak(const google_protobuf_FieldOptions* msg) { bool default_val = false; @@ -3989,7 +3989,7 @@ UPB_INLINE bool google_protobuf_FieldOptions_has_weak(const google_protobuf_Fiel } UPB_INLINE void google_protobuf_FieldOptions_clear_unverified_lazy(google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {15, 17, 7, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_FieldOptions_unverified_lazy(const google_protobuf_FieldOptions* msg) { bool default_val = false; @@ -4005,7 +4005,7 @@ UPB_INLINE bool google_protobuf_FieldOptions_has_unverified_lazy(const google_pr } UPB_INLINE void google_protobuf_FieldOptions_clear_debug_redact(google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {16, 18, 8, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_FieldOptions_debug_redact(const google_protobuf_FieldOptions* msg) { bool default_val = false; @@ -4021,7 +4021,7 @@ UPB_INLINE bool google_protobuf_FieldOptions_has_debug_redact(const google_proto } UPB_INLINE void google_protobuf_FieldOptions_clear_retention(google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {17, 20, 9, 5, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_FieldOptions_retention(const google_protobuf_FieldOptions* msg) { int32_t default_val = 0; @@ -4037,7 +4037,7 @@ UPB_INLINE bool google_protobuf_FieldOptions_has_retention(const google_protobuf } UPB_INLINE void google_protobuf_FieldOptions_clear_targets(google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {19, 24, 0, 6, 14, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t const* google_protobuf_FieldOptions_targets(const google_protobuf_FieldOptions* msg, size_t* size) { const upb_MiniTableField field = {19, 24, 0, 6, 14, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -4069,7 +4069,7 @@ UPB_INLINE upb_Array* _google_protobuf_FieldOptions_targets_mutable_upb_array(go } UPB_INLINE void google_protobuf_FieldOptions_clear_edition_defaults(google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {20, UPB_SIZE(28, 32), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_FieldOptions_EditionDefault* const* google_protobuf_FieldOptions_edition_defaults(const google_protobuf_FieldOptions* msg, size_t* size) { const upb_MiniTableField field = {20, UPB_SIZE(28, 32), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -4101,7 +4101,7 @@ UPB_INLINE upb_Array* _google_protobuf_FieldOptions_edition_defaults_mutable_upb } UPB_INLINE void google_protobuf_FieldOptions_clear_features(google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {21, UPB_SIZE(32, 40), 10, 1, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_FeatureSet* google_protobuf_FieldOptions_features(const google_protobuf_FieldOptions* msg) { const google_protobuf_FeatureSet* default_val = NULL; @@ -4117,7 +4117,7 @@ UPB_INLINE bool google_protobuf_FieldOptions_has_features(const google_protobuf_ } UPB_INLINE void google_protobuf_FieldOptions_clear_uninterpreted_option(google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {999, UPB_SIZE(36, 48), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_FieldOptions_uninterpreted_option(const google_protobuf_FieldOptions* msg, size_t* size) { const upb_MiniTableField field = {999, UPB_SIZE(36, 48), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -4323,7 +4323,7 @@ UPB_INLINE char* google_protobuf_FieldOptions_EditionDefault_serialize_ex(const } UPB_INLINE void google_protobuf_FieldOptions_EditionDefault_clear_value(google_protobuf_FieldOptions_EditionDefault* msg) { const upb_MiniTableField field = {2, 8, 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_FieldOptions_EditionDefault_value(const google_protobuf_FieldOptions_EditionDefault* msg) { upb_StringView default_val = upb_StringView_FromString(""); @@ -4339,7 +4339,7 @@ UPB_INLINE bool google_protobuf_FieldOptions_EditionDefault_has_value(const goog } UPB_INLINE void google_protobuf_FieldOptions_EditionDefault_clear_edition(google_protobuf_FieldOptions_EditionDefault* msg) { const upb_MiniTableField field = {3, 4, 2, 0, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_FieldOptions_EditionDefault_edition(const google_protobuf_FieldOptions_EditionDefault* msg) { int32_t default_val = 0; @@ -4401,7 +4401,7 @@ UPB_INLINE char* google_protobuf_OneofOptions_serialize_ex(const google_protobuf } UPB_INLINE void google_protobuf_OneofOptions_clear_features(google_protobuf_OneofOptions* msg) { const upb_MiniTableField field = {1, UPB_SIZE(4, 8), 1, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_FeatureSet* google_protobuf_OneofOptions_features(const google_protobuf_OneofOptions* msg) { const google_protobuf_FeatureSet* default_val = NULL; @@ -4417,7 +4417,7 @@ UPB_INLINE bool google_protobuf_OneofOptions_has_features(const google_protobuf_ } UPB_INLINE void google_protobuf_OneofOptions_clear_uninterpreted_option(google_protobuf_OneofOptions* msg) { const upb_MiniTableField field = {999, UPB_SIZE(8, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_OneofOptions_uninterpreted_option(const google_protobuf_OneofOptions* msg, size_t* size) { const upb_MiniTableField field = {999, UPB_SIZE(8, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -4529,7 +4529,7 @@ UPB_INLINE char* google_protobuf_EnumOptions_serialize_ex(const google_protobuf_ } UPB_INLINE void google_protobuf_EnumOptions_clear_allow_alias(google_protobuf_EnumOptions* msg) { const upb_MiniTableField field = {2, 1, 1, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_EnumOptions_allow_alias(const google_protobuf_EnumOptions* msg) { bool default_val = false; @@ -4545,7 +4545,7 @@ UPB_INLINE bool google_protobuf_EnumOptions_has_allow_alias(const google_protobu } UPB_INLINE void google_protobuf_EnumOptions_clear_deprecated(google_protobuf_EnumOptions* msg) { const upb_MiniTableField field = {3, 2, 2, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_EnumOptions_deprecated(const google_protobuf_EnumOptions* msg) { bool default_val = false; @@ -4561,7 +4561,7 @@ UPB_INLINE bool google_protobuf_EnumOptions_has_deprecated(const google_protobuf } UPB_INLINE void google_protobuf_EnumOptions_clear_deprecated_legacy_json_field_conflicts(google_protobuf_EnumOptions* msg) { const upb_MiniTableField field = {6, 3, 3, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_EnumOptions_deprecated_legacy_json_field_conflicts(const google_protobuf_EnumOptions* msg) { bool default_val = false; @@ -4577,7 +4577,7 @@ UPB_INLINE bool google_protobuf_EnumOptions_has_deprecated_legacy_json_field_con } UPB_INLINE void google_protobuf_EnumOptions_clear_features(google_protobuf_EnumOptions* msg) { const upb_MiniTableField field = {7, UPB_SIZE(4, 8), 4, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_FeatureSet* google_protobuf_EnumOptions_features(const google_protobuf_EnumOptions* msg) { const google_protobuf_FeatureSet* default_val = NULL; @@ -4593,7 +4593,7 @@ UPB_INLINE bool google_protobuf_EnumOptions_has_features(const google_protobuf_E } UPB_INLINE void google_protobuf_EnumOptions_clear_uninterpreted_option(google_protobuf_EnumOptions* msg) { const upb_MiniTableField field = {999, UPB_SIZE(8, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_EnumOptions_uninterpreted_option(const google_protobuf_EnumOptions* msg, size_t* size) { const upb_MiniTableField field = {999, UPB_SIZE(8, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -4717,7 +4717,7 @@ UPB_INLINE char* google_protobuf_EnumValueOptions_serialize_ex(const google_prot } UPB_INLINE void google_protobuf_EnumValueOptions_clear_deprecated(google_protobuf_EnumValueOptions* msg) { const upb_MiniTableField field = {1, 1, 1, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_EnumValueOptions_deprecated(const google_protobuf_EnumValueOptions* msg) { bool default_val = false; @@ -4733,7 +4733,7 @@ UPB_INLINE bool google_protobuf_EnumValueOptions_has_deprecated(const google_pro } UPB_INLINE void google_protobuf_EnumValueOptions_clear_features(google_protobuf_EnumValueOptions* msg) { const upb_MiniTableField field = {2, UPB_SIZE(4, 8), 2, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_FeatureSet* google_protobuf_EnumValueOptions_features(const google_protobuf_EnumValueOptions* msg) { const google_protobuf_FeatureSet* default_val = NULL; @@ -4749,7 +4749,7 @@ UPB_INLINE bool google_protobuf_EnumValueOptions_has_features(const google_proto } UPB_INLINE void google_protobuf_EnumValueOptions_clear_debug_redact(google_protobuf_EnumValueOptions* msg) { const upb_MiniTableField field = {3, UPB_SIZE(8, 2), 3, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_EnumValueOptions_debug_redact(const google_protobuf_EnumValueOptions* msg) { bool default_val = false; @@ -4765,7 +4765,7 @@ UPB_INLINE bool google_protobuf_EnumValueOptions_has_debug_redact(const google_p } UPB_INLINE void google_protobuf_EnumValueOptions_clear_uninterpreted_option(google_protobuf_EnumValueOptions* msg) { const upb_MiniTableField field = {999, UPB_SIZE(12, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_EnumValueOptions_uninterpreted_option(const google_protobuf_EnumValueOptions* msg, size_t* size) { const upb_MiniTableField field = {999, UPB_SIZE(12, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -4885,7 +4885,7 @@ UPB_INLINE char* google_protobuf_ServiceOptions_serialize_ex(const google_protob } UPB_INLINE void google_protobuf_ServiceOptions_clear_deprecated(google_protobuf_ServiceOptions* msg) { const upb_MiniTableField field = {33, 1, 1, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_ServiceOptions_deprecated(const google_protobuf_ServiceOptions* msg) { bool default_val = false; @@ -4901,7 +4901,7 @@ UPB_INLINE bool google_protobuf_ServiceOptions_has_deprecated(const google_proto } UPB_INLINE void google_protobuf_ServiceOptions_clear_features(google_protobuf_ServiceOptions* msg) { const upb_MiniTableField field = {34, UPB_SIZE(4, 8), 2, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_FeatureSet* google_protobuf_ServiceOptions_features(const google_protobuf_ServiceOptions* msg) { const google_protobuf_FeatureSet* default_val = NULL; @@ -4917,7 +4917,7 @@ UPB_INLINE bool google_protobuf_ServiceOptions_has_features(const google_protobu } UPB_INLINE void google_protobuf_ServiceOptions_clear_uninterpreted_option(google_protobuf_ServiceOptions* msg) { const upb_MiniTableField field = {999, UPB_SIZE(8, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_ServiceOptions_uninterpreted_option(const google_protobuf_ServiceOptions* msg, size_t* size) { const upb_MiniTableField field = {999, UPB_SIZE(8, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -5033,7 +5033,7 @@ UPB_INLINE char* google_protobuf_MethodOptions_serialize_ex(const google_protobu } UPB_INLINE void google_protobuf_MethodOptions_clear_deprecated(google_protobuf_MethodOptions* msg) { const upb_MiniTableField field = {33, 1, 1, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_MethodOptions_deprecated(const google_protobuf_MethodOptions* msg) { bool default_val = false; @@ -5049,7 +5049,7 @@ UPB_INLINE bool google_protobuf_MethodOptions_has_deprecated(const google_protob } UPB_INLINE void google_protobuf_MethodOptions_clear_idempotency_level(google_protobuf_MethodOptions* msg) { const upb_MiniTableField field = {34, 4, 2, 2, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_MethodOptions_idempotency_level(const google_protobuf_MethodOptions* msg) { int32_t default_val = 0; @@ -5065,7 +5065,7 @@ UPB_INLINE bool google_protobuf_MethodOptions_has_idempotency_level(const google } UPB_INLINE void google_protobuf_MethodOptions_clear_features(google_protobuf_MethodOptions* msg) { const upb_MiniTableField field = {35, 8, 3, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_FeatureSet* google_protobuf_MethodOptions_features(const google_protobuf_MethodOptions* msg) { const google_protobuf_FeatureSet* default_val = NULL; @@ -5081,7 +5081,7 @@ UPB_INLINE bool google_protobuf_MethodOptions_has_features(const google_protobuf } UPB_INLINE void google_protobuf_MethodOptions_clear_uninterpreted_option(google_protobuf_MethodOptions* msg) { const upb_MiniTableField field = {999, UPB_SIZE(12, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_MethodOptions_uninterpreted_option(const google_protobuf_MethodOptions* msg, size_t* size) { const upb_MiniTableField field = {999, UPB_SIZE(12, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -5201,7 +5201,7 @@ UPB_INLINE char* google_protobuf_UninterpretedOption_serialize_ex(const google_p } UPB_INLINE void google_protobuf_UninterpretedOption_clear_name(google_protobuf_UninterpretedOption* msg) { const upb_MiniTableField field = {2, UPB_SIZE(4, 8), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_UninterpretedOption_NamePart* const* google_protobuf_UninterpretedOption_name(const google_protobuf_UninterpretedOption* msg, size_t* size) { const upb_MiniTableField field = {2, UPB_SIZE(4, 8), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -5233,7 +5233,7 @@ UPB_INLINE upb_Array* _google_protobuf_UninterpretedOption_name_mutable_upb_arra } UPB_INLINE void google_protobuf_UninterpretedOption_clear_identifier_value(google_protobuf_UninterpretedOption* msg) { const upb_MiniTableField field = {3, UPB_SIZE(8, 16), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_UninterpretedOption_identifier_value(const google_protobuf_UninterpretedOption* msg) { upb_StringView default_val = upb_StringView_FromString(""); @@ -5249,7 +5249,7 @@ UPB_INLINE bool google_protobuf_UninterpretedOption_has_identifier_value(const g } UPB_INLINE void google_protobuf_UninterpretedOption_clear_positive_int_value(google_protobuf_UninterpretedOption* msg) { const upb_MiniTableField field = {4, UPB_SIZE(16, 32), 2, kUpb_NoSub, 4, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_8Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE uint64_t google_protobuf_UninterpretedOption_positive_int_value(const google_protobuf_UninterpretedOption* msg) { uint64_t default_val = (uint64_t)0ull; @@ -5265,7 +5265,7 @@ UPB_INLINE bool google_protobuf_UninterpretedOption_has_positive_int_value(const } UPB_INLINE void google_protobuf_UninterpretedOption_clear_negative_int_value(google_protobuf_UninterpretedOption* msg) { const upb_MiniTableField field = {5, UPB_SIZE(24, 40), 3, kUpb_NoSub, 3, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_8Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE int64_t google_protobuf_UninterpretedOption_negative_int_value(const google_protobuf_UninterpretedOption* msg) { int64_t default_val = (int64_t)0ll; @@ -5281,7 +5281,7 @@ UPB_INLINE bool google_protobuf_UninterpretedOption_has_negative_int_value(const } UPB_INLINE void google_protobuf_UninterpretedOption_clear_double_value(google_protobuf_UninterpretedOption* msg) { const upb_MiniTableField field = {6, UPB_SIZE(32, 48), 4, kUpb_NoSub, 1, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_8Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE double google_protobuf_UninterpretedOption_double_value(const google_protobuf_UninterpretedOption* msg) { double default_val = 0; @@ -5297,7 +5297,7 @@ UPB_INLINE bool google_protobuf_UninterpretedOption_has_double_value(const googl } UPB_INLINE void google_protobuf_UninterpretedOption_clear_string_value(google_protobuf_UninterpretedOption* msg) { const upb_MiniTableField field = {7, UPB_SIZE(40, 56), 5, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_UninterpretedOption_string_value(const google_protobuf_UninterpretedOption* msg) { upb_StringView default_val = upb_StringView_FromString(""); @@ -5313,7 +5313,7 @@ UPB_INLINE bool google_protobuf_UninterpretedOption_has_string_value(const googl } UPB_INLINE void google_protobuf_UninterpretedOption_clear_aggregate_value(google_protobuf_UninterpretedOption* msg) { const upb_MiniTableField field = {8, UPB_SIZE(48, 72), 6, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_UninterpretedOption_aggregate_value(const google_protobuf_UninterpretedOption* msg) { upb_StringView default_val = upb_StringView_FromString(""); @@ -5421,7 +5421,7 @@ UPB_INLINE char* google_protobuf_UninterpretedOption_NamePart_serialize_ex(const } UPB_INLINE void google_protobuf_UninterpretedOption_NamePart_clear_name_part(google_protobuf_UninterpretedOption_NamePart* msg) { const upb_MiniTableField field = {1, UPB_SIZE(4, 8), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_UninterpretedOption_NamePart_name_part(const google_protobuf_UninterpretedOption_NamePart* msg) { upb_StringView default_val = upb_StringView_FromString(""); @@ -5437,7 +5437,7 @@ UPB_INLINE bool google_protobuf_UninterpretedOption_NamePart_has_name_part(const } UPB_INLINE void google_protobuf_UninterpretedOption_NamePart_clear_is_extension(google_protobuf_UninterpretedOption_NamePart* msg) { const upb_MiniTableField field = {2, 1, 2, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE bool google_protobuf_UninterpretedOption_NamePart_is_extension(const google_protobuf_UninterpretedOption_NamePart* msg) { bool default_val = false; @@ -5499,7 +5499,7 @@ UPB_INLINE char* google_protobuf_FeatureSet_serialize_ex(const google_protobuf_F } UPB_INLINE void google_protobuf_FeatureSet_clear_field_presence(google_protobuf_FeatureSet* msg) { const upb_MiniTableField field = {1, 4, 1, 0, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_FeatureSet_field_presence(const google_protobuf_FeatureSet* msg) { int32_t default_val = 0; @@ -5515,7 +5515,7 @@ UPB_INLINE bool google_protobuf_FeatureSet_has_field_presence(const google_proto } UPB_INLINE void google_protobuf_FeatureSet_clear_enum_type(google_protobuf_FeatureSet* msg) { const upb_MiniTableField field = {2, 8, 2, 1, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_FeatureSet_enum_type(const google_protobuf_FeatureSet* msg) { int32_t default_val = 0; @@ -5531,7 +5531,7 @@ UPB_INLINE bool google_protobuf_FeatureSet_has_enum_type(const google_protobuf_F } UPB_INLINE void google_protobuf_FeatureSet_clear_repeated_field_encoding(google_protobuf_FeatureSet* msg) { const upb_MiniTableField field = {3, 12, 3, 2, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_FeatureSet_repeated_field_encoding(const google_protobuf_FeatureSet* msg) { int32_t default_val = 0; @@ -5547,7 +5547,7 @@ UPB_INLINE bool google_protobuf_FeatureSet_has_repeated_field_encoding(const goo } UPB_INLINE void google_protobuf_FeatureSet_clear_utf8_validation(google_protobuf_FeatureSet* msg) { const upb_MiniTableField field = {4, 16, 4, 3, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_FeatureSet_utf8_validation(const google_protobuf_FeatureSet* msg) { int32_t default_val = 0; @@ -5563,7 +5563,7 @@ UPB_INLINE bool google_protobuf_FeatureSet_has_utf8_validation(const google_prot } UPB_INLINE void google_protobuf_FeatureSet_clear_message_encoding(google_protobuf_FeatureSet* msg) { const upb_MiniTableField field = {5, 20, 5, 4, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_FeatureSet_message_encoding(const google_protobuf_FeatureSet* msg) { int32_t default_val = 0; @@ -5579,7 +5579,7 @@ UPB_INLINE bool google_protobuf_FeatureSet_has_message_encoding(const google_pro } UPB_INLINE void google_protobuf_FeatureSet_clear_json_format(google_protobuf_FeatureSet* msg) { const upb_MiniTableField field = {6, 24, 6, 5, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_FeatureSet_json_format(const google_protobuf_FeatureSet* msg) { int32_t default_val = 0; @@ -5657,7 +5657,7 @@ UPB_INLINE char* google_protobuf_FeatureSetDefaults_serialize_ex(const google_pr } UPB_INLINE void google_protobuf_FeatureSetDefaults_clear_defaults(google_protobuf_FeatureSetDefaults* msg) { const upb_MiniTableField field = {1, UPB_SIZE(4, 16), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* const* google_protobuf_FeatureSetDefaults_defaults(const google_protobuf_FeatureSetDefaults* msg, size_t* size) { const upb_MiniTableField field = {1, UPB_SIZE(4, 16), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -5689,7 +5689,7 @@ UPB_INLINE upb_Array* _google_protobuf_FeatureSetDefaults_defaults_mutable_upb_a } UPB_INLINE void google_protobuf_FeatureSetDefaults_clear_minimum_edition(google_protobuf_FeatureSetDefaults* msg) { const upb_MiniTableField field = {4, UPB_SIZE(8, 4), 1, 1, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_FeatureSetDefaults_minimum_edition(const google_protobuf_FeatureSetDefaults* msg) { int32_t default_val = 0; @@ -5705,7 +5705,7 @@ UPB_INLINE bool google_protobuf_FeatureSetDefaults_has_minimum_edition(const goo } UPB_INLINE void google_protobuf_FeatureSetDefaults_clear_maximum_edition(google_protobuf_FeatureSetDefaults* msg) { const upb_MiniTableField field = {5, UPB_SIZE(12, 8), 2, 2, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_FeatureSetDefaults_maximum_edition(const google_protobuf_FeatureSetDefaults* msg) { int32_t default_val = 0; @@ -5797,7 +5797,7 @@ UPB_INLINE char* google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_ser } UPB_INLINE void google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_clear_features(google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* msg) { const upb_MiniTableField field = {2, UPB_SIZE(4, 8), 1, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_FeatureSet* google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_features(const google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* msg) { const google_protobuf_FeatureSet* default_val = NULL; @@ -5813,7 +5813,7 @@ UPB_INLINE bool google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_has_ } UPB_INLINE void google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_clear_edition(google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* msg) { const upb_MiniTableField field = {3, UPB_SIZE(8, 4), 2, 1, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_edition(const google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* msg) { int32_t default_val = 0; @@ -5883,7 +5883,7 @@ UPB_INLINE char* google_protobuf_SourceCodeInfo_serialize_ex(const google_protob } UPB_INLINE void google_protobuf_SourceCodeInfo_clear_location(google_protobuf_SourceCodeInfo* msg) { const upb_MiniTableField field = {1, 0, 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_SourceCodeInfo_Location* const* google_protobuf_SourceCodeInfo_location(const google_protobuf_SourceCodeInfo* msg, size_t* size) { const upb_MiniTableField field = {1, 0, 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -5983,7 +5983,7 @@ UPB_INLINE char* google_protobuf_SourceCodeInfo_Location_serialize_ex(const goog } UPB_INLINE void google_protobuf_SourceCodeInfo_Location_clear_path(google_protobuf_SourceCodeInfo_Location* msg) { const upb_MiniTableField field = {1, UPB_SIZE(4, 8), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsPacked | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t const* google_protobuf_SourceCodeInfo_Location_path(const google_protobuf_SourceCodeInfo_Location* msg, size_t* size) { const upb_MiniTableField field = {1, UPB_SIZE(4, 8), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsPacked | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -6015,7 +6015,7 @@ UPB_INLINE upb_Array* _google_protobuf_SourceCodeInfo_Location_path_mutable_upb_ } UPB_INLINE void google_protobuf_SourceCodeInfo_Location_clear_span(google_protobuf_SourceCodeInfo_Location* msg) { const upb_MiniTableField field = {2, UPB_SIZE(8, 16), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsPacked | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t const* google_protobuf_SourceCodeInfo_Location_span(const google_protobuf_SourceCodeInfo_Location* msg, size_t* size) { const upb_MiniTableField field = {2, UPB_SIZE(8, 16), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsPacked | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -6047,7 +6047,7 @@ UPB_INLINE upb_Array* _google_protobuf_SourceCodeInfo_Location_span_mutable_upb_ } UPB_INLINE void google_protobuf_SourceCodeInfo_Location_clear_leading_comments(google_protobuf_SourceCodeInfo_Location* msg) { const upb_MiniTableField field = {3, UPB_SIZE(16, 24), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_SourceCodeInfo_Location_leading_comments(const google_protobuf_SourceCodeInfo_Location* msg) { upb_StringView default_val = upb_StringView_FromString(""); @@ -6063,7 +6063,7 @@ UPB_INLINE bool google_protobuf_SourceCodeInfo_Location_has_leading_comments(con } UPB_INLINE void google_protobuf_SourceCodeInfo_Location_clear_trailing_comments(google_protobuf_SourceCodeInfo_Location* msg) { const upb_MiniTableField field = {4, UPB_SIZE(24, 40), 2, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_SourceCodeInfo_Location_trailing_comments(const google_protobuf_SourceCodeInfo_Location* msg) { upb_StringView default_val = upb_StringView_FromString(""); @@ -6079,7 +6079,7 @@ UPB_INLINE bool google_protobuf_SourceCodeInfo_Location_has_trailing_comments(co } UPB_INLINE void google_protobuf_SourceCodeInfo_Location_clear_leading_detached_comments(google_protobuf_SourceCodeInfo_Location* msg) { const upb_MiniTableField field = {6, UPB_SIZE(12, 56), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView const* google_protobuf_SourceCodeInfo_Location_leading_detached_comments(const google_protobuf_SourceCodeInfo_Location* msg, size_t* size) { const upb_MiniTableField field = {6, UPB_SIZE(12, 56), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -6241,7 +6241,7 @@ UPB_INLINE char* google_protobuf_GeneratedCodeInfo_serialize_ex(const google_pro } UPB_INLINE void google_protobuf_GeneratedCodeInfo_clear_annotation(google_protobuf_GeneratedCodeInfo* msg) { const upb_MiniTableField field = {1, 0, 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE const google_protobuf_GeneratedCodeInfo_Annotation* const* google_protobuf_GeneratedCodeInfo_annotation(const google_protobuf_GeneratedCodeInfo* msg, size_t* size) { const upb_MiniTableField field = {1, 0, 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -6341,7 +6341,7 @@ UPB_INLINE char* google_protobuf_GeneratedCodeInfo_Annotation_serialize_ex(const } UPB_INLINE void google_protobuf_GeneratedCodeInfo_Annotation_clear_path(google_protobuf_GeneratedCodeInfo_Annotation* msg) { const upb_MiniTableField field = {1, UPB_SIZE(4, 16), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsPacked | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t const* google_protobuf_GeneratedCodeInfo_Annotation_path(const google_protobuf_GeneratedCodeInfo_Annotation* msg, size_t* size) { const upb_MiniTableField field = {1, UPB_SIZE(4, 16), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsPacked | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -6373,7 +6373,7 @@ UPB_INLINE upb_Array* _google_protobuf_GeneratedCodeInfo_Annotation_path_mutable } UPB_INLINE void google_protobuf_GeneratedCodeInfo_Annotation_clear_source_file(google_protobuf_GeneratedCodeInfo_Annotation* msg) { const upb_MiniTableField field = {2, UPB_SIZE(20, 24), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE upb_StringView google_protobuf_GeneratedCodeInfo_Annotation_source_file(const google_protobuf_GeneratedCodeInfo_Annotation* msg) { upb_StringView default_val = upb_StringView_FromString(""); @@ -6389,7 +6389,7 @@ UPB_INLINE bool google_protobuf_GeneratedCodeInfo_Annotation_has_source_file(con } UPB_INLINE void google_protobuf_GeneratedCodeInfo_Annotation_clear_begin(google_protobuf_GeneratedCodeInfo_Annotation* msg) { const upb_MiniTableField field = {3, UPB_SIZE(8, 4), 2, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_GeneratedCodeInfo_Annotation_begin(const google_protobuf_GeneratedCodeInfo_Annotation* msg) { int32_t default_val = (int32_t)0; @@ -6405,7 +6405,7 @@ UPB_INLINE bool google_protobuf_GeneratedCodeInfo_Annotation_has_begin(const goo } UPB_INLINE void google_protobuf_GeneratedCodeInfo_Annotation_clear_end(google_protobuf_GeneratedCodeInfo_Annotation* msg) { const upb_MiniTableField field = {4, UPB_SIZE(12, 8), 3, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_GeneratedCodeInfo_Annotation_end(const google_protobuf_GeneratedCodeInfo_Annotation* msg) { int32_t default_val = (int32_t)0; @@ -6421,7 +6421,7 @@ UPB_INLINE bool google_protobuf_GeneratedCodeInfo_Annotation_has_end(const googl } UPB_INLINE void google_protobuf_GeneratedCodeInfo_Annotation_clear_semantic(google_protobuf_GeneratedCodeInfo_Annotation* msg) { const upb_MiniTableField field = {5, UPB_SIZE(16, 12), 4, 0, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field); + upb_Message_ClearBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t google_protobuf_GeneratedCodeInfo_Annotation_semantic(const google_protobuf_GeneratedCodeInfo_Annotation* msg) { int32_t default_val = 0; From 434d109d9cd13741baa4a8560252e22620db6818 Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Mon, 8 Jan 2024 08:21:44 -0800 Subject: [PATCH 206/255] Make utf8chars.chars iter return `impl Iterator + fmt::Debug`. PiperOrigin-RevId: 596599987 --- rust/string.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust/string.rs b/rust/string.rs index dfaa51918f90a..d2b5a5d6e3dd1 100644 --- a/rust/string.rs +++ b/rust/string.rs @@ -344,7 +344,7 @@ impl ProtoStr { /// [`U+FFFD REPLACEMENT CHARACTER`]. /// /// [`U+FFFD REPLACEMENT CHARACTER`]: std::char::REPLACEMENT_CHARACTER - pub fn chars(&self) -> impl Iterator + '_ { + pub fn chars(&self) -> impl Iterator + '_ + fmt::Debug { Utf8Chunks::new(self.as_bytes()).flat_map(|chunk| { let mut yield_replacement_char = !chunk.invalid().is_empty(); chunk.valid().chars().chain(iter::from_fn(move || { From 87618fcbdd50514eab024a0e40545d8b4ca15cca Mon Sep 17 00:00:00 2001 From: Eric Salo Date: Mon, 8 Jan 2024 14:40:25 -0800 Subject: [PATCH 207/255] upb: remove duplicate typedef for upb_TaggedMessagePtr PiperOrigin-RevId: 596706308 --- upb/message/internal/accessors.h | 4 ++-- upb/message/internal/tagged_ptr.h | 13 +++++-------- upb/message/value.h | 6 +----- 3 files changed, 8 insertions(+), 15 deletions(-) diff --git a/upb/message/internal/accessors.h b/upb/message/internal/accessors.h index 7c57dbb0b1645..b6ab3587bb1df 100644 --- a/upb/message/internal/accessors.h +++ b/upb/message/internal/accessors.h @@ -311,8 +311,8 @@ UPB_INLINE void _upb_Message_AssertMapIsUntagged( UPB_UNUSED(msg); UPB_PRIVATE(_upb_MiniTableField_CheckIsMap)(field); #ifndef NDEBUG - upb_TaggedMessagePtr default_val = 0; - upb_TaggedMessagePtr tagged; + uintptr_t default_val = 0; + uintptr_t tagged; _upb_Message_GetNonExtensionField(msg, field, &default_val, &tagged); UPB_ASSERT(!UPB_PRIVATE(_upb_TaggedMessagePtr_IsEmpty)(tagged)); #endif diff --git a/upb/message/internal/tagged_ptr.h b/upb/message/internal/tagged_ptr.h index b1c9a77b3d6fc..1e8ac7d0958fa 100644 --- a/upb/message/internal/tagged_ptr.h +++ b/upb/message/internal/tagged_ptr.h @@ -15,37 +15,34 @@ // Must be last. #include "upb/port/def.inc" -typedef uintptr_t upb_TaggedMessagePtr; - #ifdef __cplusplus extern "C" { #endif // Internal-only because empty messages cannot be created by the user. -UPB_INLINE upb_TaggedMessagePtr +UPB_INLINE uintptr_t UPB_PRIVATE(_upb_TaggedMessagePtr_Pack)(struct upb_Message* ptr, bool empty) { UPB_ASSERT(((uintptr_t)ptr & 1) == 0); return (uintptr_t)ptr | (empty ? 1 : 0); } -UPB_INLINE bool UPB_PRIVATE(_upb_TaggedMessagePtr_IsEmpty)( - upb_TaggedMessagePtr ptr) { +UPB_INLINE bool UPB_PRIVATE(_upb_TaggedMessagePtr_IsEmpty)(uintptr_t ptr) { return ptr & 1; } UPB_INLINE struct upb_Message* UPB_PRIVATE(_upb_TaggedMessagePtr_GetMessage)( - upb_TaggedMessagePtr ptr) { + uintptr_t ptr) { return (struct upb_Message*)(ptr & ~(uintptr_t)1); } UPB_INLINE struct upb_Message* UPB_PRIVATE( - _upb_TaggedMessagePtr_GetNonEmptyMessage)(upb_TaggedMessagePtr ptr) { + _upb_TaggedMessagePtr_GetNonEmptyMessage)(uintptr_t ptr) { UPB_ASSERT(!UPB_PRIVATE(_upb_TaggedMessagePtr_IsEmpty)(ptr)); return UPB_PRIVATE(_upb_TaggedMessagePtr_GetMessage)(ptr); } UPB_INLINE struct upb_Message* UPB_PRIVATE( - _upb_TaggedMessagePtr_GetEmptyMessage)(upb_TaggedMessagePtr ptr) { + _upb_TaggedMessagePtr_GetEmptyMessage)(uintptr_t ptr) { UPB_ASSERT(UPB_PRIVATE(_upb_TaggedMessagePtr_IsEmpty)(ptr)); return UPB_PRIVATE(_upb_TaggedMessagePtr_GetMessage)(ptr); } diff --git a/upb/message/value.h b/upb/message/value.h index 775622c910cab..8b15d1d3ad07f 100644 --- a/upb/message/value.h +++ b/upb/message/value.h @@ -14,10 +14,6 @@ #include #include "upb/base/string_view.h" -#include "upb/message/internal/array.h" -#include "upb/message/internal/map.h" -#include "upb/message/internal/message.h" -#include "upb/message/internal/tagged_ptr.h" typedef union { bool bool_val; @@ -36,7 +32,7 @@ typedef union { // msg_val if unlinked sub-messages may possibly be in use. See the // documentation in kUpb_DecodeOption_ExperimentalAllowUnlinked for more // information. - upb_TaggedMessagePtr tagged_msg_val; + uintptr_t tagged_msg_val; // upb_TaggedMessagePtr } upb_MessageValue; typedef union { From e1253cd9055f3665ff1fcd59bba4879241cd12e6 Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Mon, 8 Jan 2024 23:09:09 +0000 Subject: [PATCH 208/255] Auto-generate files after cl/596706308 --- php/ext/google/protobuf/php-upb.h | 2365 ++++++++++++------------- ruby/ext/google/protobuf_c/ruby-upb.h | 2365 ++++++++++++------------- 2 files changed, 2362 insertions(+), 2368 deletions(-) diff --git a/php/ext/google/protobuf/php-upb.h b/php/ext/google/protobuf/php-upb.h index fbf9bd8a63aec..af3ca9af8e1c3 100644 --- a/php/ext/google/protobuf/php-upb.h +++ b/php/ext/google/protobuf/php-upb.h @@ -825,667 +825,594 @@ UPB_API_INLINE void upb_Arena_ShrinkLast(upb_Arena* a, void* ptr, #include -#ifndef UPB_MESSAGE_INTERNAL_ARRAY_H_ -#define UPB_MESSAGE_INTERNAL_ARRAY_H_ +typedef union { + bool bool_val; + float float_val; + double double_val; + int32_t int32_val; + int64_t int64_val; + uint32_t uint32_val; + uint64_t uint64_val; + const struct upb_Array* array_val; + const struct upb_Map* map_val; + const struct upb_Message* msg_val; + upb_StringView str_val; -#include + // EXPERIMENTAL: A tagged upb_Message*. Users must use this instead of + // msg_val if unlinked sub-messages may possibly be in use. See the + // documentation in kUpb_DecodeOption_ExperimentalAllowUnlinked for more + // information. + uintptr_t tagged_msg_val; // upb_TaggedMessagePtr +} upb_MessageValue; + +typedef union { + struct upb_Array* array; + struct upb_Map* map; + struct upb_Message* msg; +} upb_MutableMessageValue; +#endif /* UPB_MESSAGE_VALUE_H_ */ // Must be last. -#define _UPB_ARRAY_MASK_IMM 0x4 // Frozen/immutable bit. -#define _UPB_ARRAY_MASK_LG2 0x3 // Encoded elem size. -#define _UPB_ARRAY_MASK_ALL (_UPB_ARRAY_MASK_IMM | _UPB_ARRAY_MASK_LG2) +typedef struct upb_Array upb_Array; #ifdef __cplusplus extern "C" { #endif -// LINT.IfChange(struct_definition) -// Our internal representation for repeated fields. -struct upb_Array { - // This is a tagged pointer. Bits #0 and #1 encode the elem size as follows: - // 0 maps to elem size 1 - // 1 maps to elem size 4 - // 2 maps to elem size 8 - // 3 maps to elem size 16 - // - // Bit #2 contains the frozen/immutable flag (currently unimplemented). - uintptr_t data; - - size_t UPB_ONLYBITS(size); // The number of elements in the array. - size_t UPB_PRIVATE(capacity); // Allocated storage. Measured in elements. -}; +// Creates a new array on the given arena that holds elements of this type. +UPB_API upb_Array* upb_Array_New(upb_Arena* a, upb_CType type); -UPB_INLINE void UPB_PRIVATE(_upb_Array_SetTaggedPtr)(struct upb_Array* array, - void* data, size_t lg2) { - UPB_ASSERT(lg2 != 1); - UPB_ASSERT(lg2 <= 4); - const size_t bits = lg2 - (lg2 != 0); - array->data = (uintptr_t)data | bits; -} +// Returns the number of elements in the array. +UPB_API size_t upb_Array_Size(const upb_Array* arr); -UPB_INLINE size_t -UPB_PRIVATE(_upb_Array_ElemSizeLg2)(const struct upb_Array* array) { - const size_t bits = array->data & _UPB_ARRAY_MASK_LG2; - const size_t lg2 = bits + (bits != 0); - return lg2; -} +// Returns the given element, which must be within the array's current size. +UPB_API upb_MessageValue upb_Array_Get(const upb_Array* arr, size_t i); -UPB_INLINE const void* _upb_array_constptr(const struct upb_Array* array) { - UPB_PRIVATE(_upb_Array_ElemSizeLg2)(array); // Check assertions. - return (void*)(array->data & ~(uintptr_t)_UPB_ARRAY_MASK_ALL); -} +// Sets the given element, which must be within the array's current size. +UPB_API void upb_Array_Set(upb_Array* arr, size_t i, upb_MessageValue val); -UPB_INLINE void* _upb_array_ptr(struct upb_Array* array) { - return (void*)_upb_array_constptr(array); -} +// Appends an element to the array. Returns false on allocation failure. +UPB_API bool upb_Array_Append(upb_Array* array, upb_MessageValue val, + upb_Arena* arena); -UPB_INLINE struct upb_Array* UPB_PRIVATE(_upb_Array_New)(upb_Arena* arena, - size_t init_capacity, - int elem_size_lg2) { - UPB_ASSERT(elem_size_lg2 != 1); - UPB_ASSERT(elem_size_lg2 <= 4); - const size_t array_size = - UPB_ALIGN_UP(sizeof(struct upb_Array), UPB_MALLOC_ALIGN); - const size_t bytes = array_size + (init_capacity << elem_size_lg2); - struct upb_Array* array = (struct upb_Array*)upb_Arena_Malloc(arena, bytes); - if (!array) return NULL; - UPB_PRIVATE(_upb_Array_SetTaggedPtr) - (array, UPB_PTR_AT(array, array_size, void), elem_size_lg2); - array->UPB_ONLYBITS(size) = 0; - array->UPB_PRIVATE(capacity) = init_capacity; - return array; -} +// Moves elements within the array using memmove(). +// Like memmove(), the source and destination elements may be overlapping. +UPB_API void upb_Array_Move(upb_Array* array, size_t dst_idx, size_t src_idx, + size_t count); -// Resizes the capacity of the array to be at least min_size. -bool UPB_PRIVATE(_upb_Array_Realloc)(struct upb_Array* array, size_t min_size, - upb_Arena* arena); +// Inserts one or more empty elements into the array. +// Existing elements are shifted right. +// The new elements have undefined state and must be set with `upb_Array_Set()`. +// REQUIRES: `i <= upb_Array_Size(arr)` +UPB_API bool upb_Array_Insert(upb_Array* array, size_t i, size_t count, + upb_Arena* arena); -UPB_INLINE bool UPB_PRIVATE(_upb_Array_Reserve)(struct upb_Array* array, - size_t size, upb_Arena* arena) { - if (array->UPB_PRIVATE(capacity) < size) - return UPB_PRIVATE(_upb_Array_Realloc)(array, size, arena); - return true; -} +// Deletes one or more elements from the array. +// Existing elements are shifted left. +// REQUIRES: `i + count <= upb_Array_Size(arr)` +UPB_API void upb_Array_Delete(upb_Array* array, size_t i, size_t count); -// Resize without initializing new elements. -UPB_INLINE bool _upb_Array_ResizeUninitialized(struct upb_Array* array, - size_t size, upb_Arena* arena) { - UPB_ASSERT(size <= array->UPB_ONLYBITS(size) || - arena); // Allow NULL arena when shrinking. - if (!UPB_PRIVATE(_upb_Array_Reserve)(array, size, arena)) return false; - array->UPB_ONLYBITS(size) = size; - return true; -} +// Changes the size of a vector. New elements are initialized to NULL/0. +// Returns false on allocation failure. +UPB_API bool upb_Array_Resize(upb_Array* array, size_t size, upb_Arena* arena); -// This function is intended for situations where elem_size is compile-time -// constant or a known expression of the form (1 << lg2), so that the expression -// i*elem_size does not result in an actual multiplication. -UPB_INLINE void UPB_PRIVATE(_upb_Array_Set)(struct upb_Array* array, size_t i, - const void* data, - size_t elem_size) { - UPB_ASSERT(i < array->UPB_ONLYBITS(size)); - UPB_ASSERT(elem_size == 1U << UPB_PRIVATE(_upb_Array_ElemSizeLg2)(array)); - char* arr_data = (char*)_upb_array_ptr(array); - memcpy(arr_data + (i * elem_size), data, elem_size); -} +// Returns pointer to array data. +UPB_API const void* upb_Array_DataPtr(const upb_Array* arr); -// LINT.ThenChange( -// GoogleInternalName1, -//) +// Returns mutable pointer to array data. +UPB_API void* upb_Array_MutableDataPtr(upb_Array* arr); #ifdef __cplusplus } /* extern "C" */ #endif -#undef _UPB_ARRAY_MASK_IMM -#undef _UPB_ARRAY_MASK_LG2 -#undef _UPB_ARRAY_MASK_ALL - -#endif /* UPB_MESSAGE_INTERNAL_ARRAY_H_ */ +#endif /* UPB_MESSAGE_ARRAY_H_ */ -#ifndef UPB_MESSAGE_INTERNAL_MAP_H_ -#define UPB_MESSAGE_INTERNAL_MAP_H_ +#ifndef UPB_MESSAGE_INTERNAL_ACCESSORS_H_ +#define UPB_MESSAGE_INTERNAL_ACCESSORS_H_ #include +#include #include -#ifndef UPB_HASH_STR_TABLE_H_ -#define UPB_HASH_STR_TABLE_H_ +#ifndef UPB_MESSAGE_INTERNAL_EXTENSION_H_ +#define UPB_MESSAGE_INTERNAL_EXTENSION_H_ /* - * upb_table - * - * This header is INTERNAL-ONLY! Its interfaces are not public or stable! - * This file defines very fast int->upb_value (inttable) and string->upb_value - * (strtable) hash tables. - * - * The table uses chained scatter with Brent's variation (inspired by the Lua - * implementation of hash tables). The hash function for strings is Austin - * Appleby's "MurmurHash." - * - * The inttable uses uintptr_t as its key, which guarantees it can be used to - * store pointers or integers of at least 32 bits (upb isn't really useful on - * systems where sizeof(void*) < 4). - * - * The table must be homogeneous (all values of the same type). In debug - * mode, we check this on insert and lookup. - */ +** Our memory representation for parsing tables and messages themselves. +** Functions in this file are used by generated code and possibly reflection. +** +** The definitions in this file are internal to upb. +**/ -#ifndef UPB_HASH_COMMON_H_ -#define UPB_HASH_COMMON_H_ +#ifndef UPB_MESSAGE_INTERNAL_MESSAGE_H_ +#define UPB_MESSAGE_INTERNAL_MESSAGE_H_ +#include #include -// Must be last. - -#ifdef __cplusplus -extern "C" { -#endif +#ifndef UPB_MINI_TABLE_MESSAGE_H_ +#define UPB_MINI_TABLE_MESSAGE_H_ -/* upb_value ******************************************************************/ -typedef struct { - uint64_t val; -} upb_value; +#ifndef UPB_MINI_TABLE_ENUM_H_ +#define UPB_MINI_TABLE_ENUM_H_ -UPB_INLINE void _upb_value_setval(upb_value* v, uint64_t val) { v->val = val; } +#include -/* For each value ctype, define the following set of functions: - * - * // Get/set an int32 from a upb_value. - * int32_t upb_value_getint32(upb_value val); - * void upb_value_setint32(upb_value *val, int32_t cval); - * - * // Construct a new upb_value from an int32. - * upb_value upb_value_int32(int32_t val); */ -#define FUNCS(name, membername, type_t, converter) \ - UPB_INLINE void upb_value_set##name(upb_value* val, type_t cval) { \ - val->val = (converter)cval; \ - } \ - UPB_INLINE upb_value upb_value_##name(type_t val) { \ - upb_value ret; \ - upb_value_set##name(&ret, val); \ - return ret; \ - } \ - UPB_INLINE type_t upb_value_get##name(upb_value val) { \ - return (type_t)(converter)val.val; \ - } -FUNCS(int32, int32, int32_t, int32_t) -FUNCS(int64, int64, int64_t, int64_t) -FUNCS(uint32, uint32, uint32_t, uint32_t) -FUNCS(uint64, uint64, uint64_t, uint64_t) -FUNCS(bool, _bool, bool, bool) -FUNCS(cstr, cstr, char*, uintptr_t) -FUNCS(uintptr, uptr, uintptr_t, uintptr_t) -FUNCS(ptr, ptr, void*, uintptr_t) -FUNCS(constptr, constptr, const void*, uintptr_t) +#ifndef UPB_MINI_TABLE_INTERNAL_ENUM_H_ +#define UPB_MINI_TABLE_INTERNAL_ENUM_H_ -#undef FUNCS +#include -UPB_INLINE void upb_value_setfloat(upb_value* val, float cval) { - memcpy(&val->val, &cval, sizeof(cval)); -} +// Must be last. -UPB_INLINE void upb_value_setdouble(upb_value* val, double cval) { - memcpy(&val->val, &cval, sizeof(cval)); -} +struct upb_MiniTableEnum { + uint32_t UPB_PRIVATE(mask_limit); // Highest that can be tested with mask. + uint32_t UPB_PRIVATE(value_count); // Number of values after the bitfield. + uint32_t UPB_PRIVATE(data)[]; // Bitmask + enumerated values follow. +}; -UPB_INLINE upb_value upb_value_float(float cval) { - upb_value ret; - upb_value_setfloat(&ret, cval); - return ret; -} +#ifdef __cplusplus +extern "C" { +#endif -UPB_INLINE upb_value upb_value_double(double cval) { - upb_value ret; - upb_value_setdouble(&ret, cval); - return ret; +UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableEnum_CheckValue)( + const struct upb_MiniTableEnum* e, uint32_t val) { + if (UPB_LIKELY(val < 64)) { + const uint64_t mask = + e->UPB_PRIVATE(data)[0] | ((uint64_t)e->UPB_PRIVATE(data)[1] << 32); + const uint64_t bit = 1ULL << val; + return (mask & bit) != 0; + } + if (UPB_LIKELY(val < e->UPB_PRIVATE(mask_limit))) { + const uint32_t mask = e->UPB_PRIVATE(data)[val / 32]; + const uint32_t bit = 1ULL << (val % 32); + return (mask & bit) != 0; + } + + // OPT: binary search long lists? + const uint32_t* start = + &e->UPB_PRIVATE(data)[e->UPB_PRIVATE(mask_limit) / 32]; + const uint32_t* limit = &e->UPB_PRIVATE( + data)[e->UPB_PRIVATE(mask_limit) / 32 + e->UPB_PRIVATE(value_count)]; + for (const uint32_t* p = start; p < limit; p++) { + if (*p == val) return true; + } + return false; } -/* upb_tabkey *****************************************************************/ +#ifdef __cplusplus +} /* extern "C" */ +#endif -/* Either: - * 1. an actual integer key, or - * 2. a pointer to a string prefixed by its uint32_t length, owned by us. - * - * ...depending on whether this is a string table or an int table. We would - * make this a union of those two types, but C89 doesn't support statically - * initializing a non-first union member. */ -typedef uintptr_t upb_tabkey; -UPB_INLINE char* upb_tabstr(upb_tabkey key, uint32_t* len) { - char* mem = (char*)key; - if (len) memcpy(len, mem, sizeof(*len)); - return mem + sizeof(*len); -} +#endif /* UPB_MINI_TABLE_INTERNAL_ENUM_H_ */ -UPB_INLINE upb_StringView upb_tabstrview(upb_tabkey key) { - upb_StringView ret; - uint32_t len; - ret.data = upb_tabstr(key, &len); - ret.size = len; - return ret; -} +// Must be last -/* upb_tabval *****************************************************************/ +typedef struct upb_MiniTableEnum upb_MiniTableEnum; -typedef struct upb_tabval { - uint64_t val; -} upb_tabval; +#ifdef __cplusplus +extern "C" { +#endif -#define UPB_TABVALUE_EMPTY_INIT \ - { -1 } +// Validates enum value against range defined by enum mini table. +UPB_INLINE bool upb_MiniTableEnum_CheckValue(const upb_MiniTableEnum* e, + uint32_t val) { + return UPB_PRIVATE(_upb_MiniTableEnum_CheckValue)(e, val); +} -/* upb_table ******************************************************************/ +#ifdef __cplusplus +} /* extern "C" */ +#endif -typedef struct _upb_tabent { - upb_tabkey key; - upb_tabval val; - /* Internal chaining. This is const so we can create static initializers for - * tables. We cast away const sometimes, but *only* when the containing - * upb_table is known to be non-const. This requires a bit of care, but - * the subtlety is confined to table.c. */ - const struct _upb_tabent* next; -} upb_tabent; +#endif /* UPB_MINI_TABLE_ENUM_H_ */ -typedef struct { - size_t count; /* Number of entries in the hash part. */ - uint32_t mask; /* Mask to turn hash value -> bucket. */ - uint32_t max_count; /* Max count before we hit our load limit. */ - uint8_t size_lg2; /* Size of the hashtable part is 2^size_lg2 entries. */ - upb_tabent* entries; -} upb_table; +#ifndef UPB_MINI_TABLE_FIELD_H_ +#define UPB_MINI_TABLE_FIELD_H_ -UPB_INLINE size_t upb_table_size(const upb_table* t) { - return t->size_lg2 ? 1 << t->size_lg2 : 0; -} +#include -// Internal-only functions, in .h file only out of necessity. -UPB_INLINE bool upb_tabent_isempty(const upb_tabent* e) { return e->key == 0; } +#ifndef UPB_MINI_TABLE_INTERNAL_FIELD_H_ +#define UPB_MINI_TABLE_INTERNAL_FIELD_H_ -uint32_t _upb_Hash(const void* p, size_t n, uint64_t seed); +#include +#include -#ifdef __cplusplus -} /* extern "C" */ -#endif +#ifndef UPB_MINI_TABLE_INTERNAL_SIZE_LOG2_H_ +#define UPB_MINI_TABLE_INTERNAL_SIZE_LOG2_H_ -#endif /* UPB_HASH_COMMON_H_ */ +#include +#include -// Must be last. -typedef struct { - upb_table t; -} upb_strtable; +// Must be last. #ifdef __cplusplus extern "C" { #endif -// Initialize a table. If memory allocation failed, false is returned and -// the table is uninitialized. -bool upb_strtable_init(upb_strtable* table, size_t expected_size, upb_Arena* a); +// Return the log2 of the storage size in bytes for a upb_CType +UPB_INLINE int UPB_PRIVATE(_upb_CType_SizeLg2)(upb_CType c_type) { + static const int8_t size[] = { + 0, // kUpb_CType_Bool + 2, // kUpb_CType_Float + 2, // kUpb_CType_Int32 + 2, // kUpb_CType_UInt32 + 2, // kUpb_CType_Enum + UPB_SIZE(2, 3), // kUpb_CType_Message + 3, // kUpb_CType_Double + 3, // kUpb_CType_Int64 + 3, // kUpb_CType_UInt64 + UPB_SIZE(3, 4), // kUpb_CType_String + UPB_SIZE(3, 4), // kUpb_CType_Bytes + }; -// Returns the number of values in the table. -UPB_INLINE size_t upb_strtable_count(const upb_strtable* t) { - return t->t.count; + // -1 here because the enum is one-based but the table is zero-based. + return size[c_type - 1]; } -void upb_strtable_clear(upb_strtable* t); - -// Inserts the given key into the hashtable with the given value. -// The key must not already exist in the hash table. The key is not required -// to be NULL-terminated, and the table will make an internal copy of the key. -// -// If a table resize was required but memory allocation failed, false is -// returned and the table is unchanged. */ -bool upb_strtable_insert(upb_strtable* t, const char* key, size_t len, - upb_value val, upb_Arena* a); - -// Looks up key in this table, returning "true" if the key was found. -// If v is non-NULL, copies the value for this key into *v. -bool upb_strtable_lookup2(const upb_strtable* t, const char* key, size_t len, - upb_value* v); +// Return the log2 of the storage size in bytes for a upb_FieldType +UPB_INLINE int UPB_PRIVATE(_upb_FieldType_SizeLg2)(upb_FieldType field_type) { + static const int8_t size[] = { + 3, // kUpb_FieldType_Double + 2, // kUpb_FieldType_Float + 3, // kUpb_FieldType_Int64 + 3, // kUpb_FieldType_UInt64 + 2, // kUpb_FieldType_Int32 + 3, // kUpb_FieldType_Fixed64 + 2, // kUpb_FieldType_Fixed32 + 0, // kUpb_FieldType_Bool + UPB_SIZE(3, 4), // kUpb_FieldType_String + UPB_SIZE(2, 3), // kUpb_FieldType_Group + UPB_SIZE(2, 3), // kUpb_FieldType_Message + UPB_SIZE(3, 4), // kUpb_FieldType_Bytes + 2, // kUpb_FieldType_UInt32 + 2, // kUpb_FieldType_Enum + 2, // kUpb_FieldType_SFixed32 + 3, // kUpb_FieldType_SFixed64 + 2, // kUpb_FieldType_SInt32 + 3, // kUpb_FieldType_SInt64 + }; -// For NULL-terminated strings. -UPB_INLINE bool upb_strtable_lookup(const upb_strtable* t, const char* key, - upb_value* v) { - return upb_strtable_lookup2(t, key, strlen(key), v); + // -1 here because the enum is one-based but the table is zero-based. + return size[field_type - 1]; } -// Removes an item from the table. Returns true if the remove was successful, -// and stores the removed item in *val if non-NULL. -bool upb_strtable_remove2(upb_strtable* t, const char* key, size_t len, - upb_value* val); +#ifdef __cplusplus +} /* extern "C" */ +#endif -UPB_INLINE bool upb_strtable_remove(upb_strtable* t, const char* key, - upb_value* v) { - return upb_strtable_remove2(t, key, strlen(key), v); -} -// Exposed for testing only. -bool upb_strtable_resize(upb_strtable* t, size_t size_lg2, upb_Arena* a); +#endif /* UPB_MINI_TABLE_INTERNAL_SIZE_LOG2_H_ */ -/* Iteration over strtable: - * - * intptr_t iter = UPB_STRTABLE_BEGIN; - * upb_StringView key; - * upb_value val; - * while (upb_strtable_next2(t, &key, &val, &iter)) { - * // ... - * } - */ +// Must be last. -#define UPB_STRTABLE_BEGIN -1 +// LINT.IfChange(struct_definition) +struct upb_MiniTableField { + uint32_t UPB_ONLYBITS(number); + uint16_t UPB_ONLYBITS(offset); + int16_t presence; // If >0, hasbit_index. If <0, ~oneof_index -bool upb_strtable_next2(const upb_strtable* t, upb_StringView* key, - upb_value* val, intptr_t* iter); -void upb_strtable_removeiter(upb_strtable* t, intptr_t* iter); -void upb_strtable_setentryvalue(upb_strtable* t, intptr_t iter, upb_value v); + // Indexes into `upb_MiniTable.subs` + // Will be set to `kUpb_NoSub` if `descriptortype` != MESSAGE/GROUP/ENUM + uint16_t UPB_PRIVATE(submsg_index); -/* DEPRECATED iterators, slated for removal. - * - * Iterators for string tables. We are subject to some kind of unusual - * design constraints: - * - * For high-level languages: - * - we must be able to guarantee that we don't crash or corrupt memory even if - * the program accesses an invalidated iterator. - * - * For C++11 range-based for: - * - iterators must be copyable - * - iterators must be comparable - * - it must be possible to construct an "end" value. - * - * Iteration order is undefined. - * - * Modifying the table invalidates iterators. upb_{str,int}table_done() is - * guaranteed to work even on an invalidated iterator, as long as the table it - * is iterating over has not been freed. Calling next() or accessing data from - * an invalidated iterator yields unspecified elements from the table, but it is - * guaranteed not to crash and to return real table elements (except when done() - * is true). */ -/* upb_strtable_iter **********************************************************/ + uint8_t UPB_PRIVATE(descriptortype); -/* upb_strtable_iter i; - * upb_strtable_begin(&i, t); - * for(; !upb_strtable_done(&i); upb_strtable_next(&i)) { - * const char *key = upb_strtable_iter_key(&i); - * const upb_value val = upb_strtable_iter_value(&i); - * // ... - * } - */ + // upb_FieldMode | upb_LabelFlags | (upb_FieldRep << kUpb_FieldRep_Shift) + uint8_t UPB_ONLYBITS(mode); +}; -typedef struct { - const upb_strtable* t; - size_t index; -} upb_strtable_iter; +#define kUpb_NoSub ((uint16_t)-1) -UPB_INLINE const upb_tabent* str_tabent(const upb_strtable_iter* i) { - return &i->t->t.entries[i->index]; -} +typedef enum { + kUpb_FieldMode_Map = 0, + kUpb_FieldMode_Array = 1, + kUpb_FieldMode_Scalar = 2, +} upb_FieldMode; -void upb_strtable_begin(upb_strtable_iter* i, const upb_strtable* t); -void upb_strtable_next(upb_strtable_iter* i); -bool upb_strtable_done(const upb_strtable_iter* i); -upb_StringView upb_strtable_iter_key(const upb_strtable_iter* i); -upb_value upb_strtable_iter_value(const upb_strtable_iter* i); -void upb_strtable_iter_setdone(upb_strtable_iter* i); -bool upb_strtable_iter_isequal(const upb_strtable_iter* i1, - const upb_strtable_iter* i2); +// Mask to isolate the upb_FieldMode from field.mode. +#define kUpb_FieldMode_Mask 3 + +// Extra flags on the mode field. +typedef enum { + kUpb_LabelFlags_IsPacked = 4, + kUpb_LabelFlags_IsExtension = 8, + // Indicates that this descriptor type is an "alternate type": + // - for Int32, this indicates that the actual type is Enum (but was + // rewritten to Int32 because it is an open enum that requires no check). + // - for Bytes, this indicates that the actual type is String (but does + // not require any UTF-8 check). + kUpb_LabelFlags_IsAlternate = 16, +} upb_LabelFlags; + +// Note: we sort by this number when calculating layout order. +typedef enum { + kUpb_FieldRep_1Byte = 0, + kUpb_FieldRep_4Byte = 1, + kUpb_FieldRep_StringView = 2, + kUpb_FieldRep_8Byte = 3, + + kUpb_FieldRep_NativePointer = + UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte), + kUpb_FieldRep_Max = kUpb_FieldRep_8Byte, +} upb_FieldRep; + +#define kUpb_FieldRep_Shift 6 #ifdef __cplusplus -} /* extern "C" */ +extern "C" { #endif +UPB_INLINE upb_FieldMode +UPB_PRIVATE(_upb_MiniTableField_Mode)(const struct upb_MiniTableField* f) { + return (upb_FieldMode)(f->UPB_ONLYBITS(mode) & kUpb_FieldMode_Mask); +} -#endif /* UPB_HASH_STR_TABLE_H_ */ - -// Must be last. +UPB_INLINE upb_FieldRep +UPB_PRIVATE(_upb_MiniTableField_GetRep)(const struct upb_MiniTableField* f) { + return (upb_FieldRep)(f->UPB_ONLYBITS(mode) >> kUpb_FieldRep_Shift); +} -typedef enum { - kUpb_MapInsertStatus_Inserted = 0, - kUpb_MapInsertStatus_Replaced = 1, - kUpb_MapInsertStatus_OutOfMemory = 2, -} upb_MapInsertStatus; +UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsArray)( + const struct upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_Mode)(f) == kUpb_FieldMode_Array; +} -// EVERYTHING BELOW THIS LINE IS INTERNAL - DO NOT USE ///////////////////////// +UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsMap)( + const struct upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_Mode)(f) == kUpb_FieldMode_Map; +} -struct upb_Map { - // Size of key and val, based on the map type. - // Strings are represented as '0' because they must be handled specially. - char key_size; - char val_size; +UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsScalar)( + const struct upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_Mode)(f) == kUpb_FieldMode_Scalar; +} - upb_strtable table; -}; +UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsAlternate)( + const struct upb_MiniTableField* f) { + return (f->UPB_ONLYBITS(mode) & kUpb_LabelFlags_IsAlternate) != 0; +} -#ifdef __cplusplus -extern "C" { -#endif +UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsExtension)( + const struct upb_MiniTableField* f) { + return (f->UPB_ONLYBITS(mode) & kUpb_LabelFlags_IsExtension) != 0; +} -// Converting between internal table representation and user values. -// -// _upb_map_tokey() and _upb_map_fromkey() are inverses. -// _upb_map_tovalue() and _upb_map_fromvalue() are inverses. -// -// These functions account for the fact that strings are treated differently -// from other types when stored in a map. +UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsPacked)( + const struct upb_MiniTableField* f) { + return (f->UPB_ONLYBITS(mode) & kUpb_LabelFlags_IsPacked) != 0; +} -UPB_INLINE upb_StringView _upb_map_tokey(const void* key, size_t size) { - if (size == UPB_MAPTYPE_STRING) { - return *(upb_StringView*)key; - } else { - return upb_StringView_FromDataAndSize((const char*)key, size); +UPB_INLINE upb_FieldType +UPB_PRIVATE(_upb_MiniTableField_Type)(const struct upb_MiniTableField* f) { + const upb_FieldType type = (upb_FieldType)f->UPB_PRIVATE(descriptortype); + if (UPB_PRIVATE(_upb_MiniTableField_IsAlternate)(f)) { + if (type == kUpb_FieldType_Int32) return kUpb_FieldType_Enum; + if (type == kUpb_FieldType_Bytes) return kUpb_FieldType_String; + UPB_ASSERT(false); } + return type; } -UPB_INLINE void _upb_map_fromkey(upb_StringView key, void* out, size_t size) { - if (size == UPB_MAPTYPE_STRING) { - memcpy(out, &key, sizeof(key)); - } else { - memcpy(out, key.data, size); - } +UPB_INLINE upb_CType +UPB_PRIVATE(_upb_MiniTableField_CType)(const struct upb_MiniTableField* f) { + return upb_FieldType_CType(UPB_PRIVATE(_upb_MiniTableField_Type)(f)); } -UPB_INLINE bool _upb_map_tovalue(const void* val, size_t size, - upb_value* msgval, upb_Arena* a) { - if (size == UPB_MAPTYPE_STRING) { - upb_StringView* strp = (upb_StringView*)upb_Arena_Malloc(a, sizeof(*strp)); - if (!strp) return false; - *strp = *(upb_StringView*)val; - *msgval = upb_value_ptr(strp); - } else { - memcpy(msgval, val, size); - } - return true; +UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_HasHasbit)( + const struct upb_MiniTableField* f) { + return f->presence > 0; } -UPB_INLINE void _upb_map_fromvalue(upb_value val, void* out, size_t size) { - if (size == UPB_MAPTYPE_STRING) { - const upb_StringView* strp = (const upb_StringView*)upb_value_getptr(val); - memcpy(out, strp, sizeof(upb_StringView)); - } else { - memcpy(out, &val, size); - } +UPB_INLINE char UPB_PRIVATE(_upb_MiniTableField_HasbitMask)( + const struct upb_MiniTableField* f) { + UPB_ASSERT(UPB_PRIVATE(_upb_MiniTableField_HasHasbit)(f)); + const size_t index = f->presence; + return 1 << (index % 8); } -UPB_INLINE void* _upb_map_next(const struct upb_Map* map, size_t* iter) { - upb_strtable_iter it; - it.t = &map->table; - it.index = *iter; - upb_strtable_next(&it); - *iter = it.index; - if (upb_strtable_done(&it)) return NULL; - return (void*)str_tabent(&it); +UPB_INLINE size_t UPB_PRIVATE(_upb_MiniTableField_HasbitOffset)( + const struct upb_MiniTableField* f) { + UPB_ASSERT(UPB_PRIVATE(_upb_MiniTableField_HasHasbit)(f)); + const size_t index = f->presence; + return index / 8; } -UPB_INLINE void _upb_Map_Clear(struct upb_Map* map) { - upb_strtable_clear(&map->table); +UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsClosedEnum)( + const struct upb_MiniTableField* f) { + return f->UPB_PRIVATE(descriptortype) == kUpb_FieldType_Enum; } -UPB_INLINE bool _upb_Map_Delete(struct upb_Map* map, const void* key, - size_t key_size, upb_value* val) { - upb_StringView k = _upb_map_tokey(key, key_size); - return upb_strtable_remove2(&map->table, k.data, k.size, val); +UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsInOneof)( + const struct upb_MiniTableField* f) { + return f->presence < 0; } -UPB_INLINE bool _upb_Map_Get(const struct upb_Map* map, const void* key, - size_t key_size, void* val, size_t val_size) { - upb_value tabval; - upb_StringView k = _upb_map_tokey(key, key_size); - bool ret = upb_strtable_lookup2(&map->table, k.data, k.size, &tabval); - if (ret && val) { - _upb_map_fromvalue(tabval, val, val_size); - } - return ret; +UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsSubMessage)( + const struct upb_MiniTableField* f) { + return f->UPB_PRIVATE(descriptortype) == kUpb_FieldType_Message || + f->UPB_PRIVATE(descriptortype) == kUpb_FieldType_Group; } -UPB_INLINE upb_MapInsertStatus _upb_Map_Insert(struct upb_Map* map, - const void* key, size_t key_size, - void* val, size_t val_size, - upb_Arena* a) { - upb_StringView strkey = _upb_map_tokey(key, key_size); - upb_value tabval = {0}; - if (!_upb_map_tovalue(val, val_size, &tabval, a)) { - return kUpb_MapInsertStatus_OutOfMemory; +UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_HasPresence)( + const struct upb_MiniTableField* f) { + if (UPB_PRIVATE(_upb_MiniTableField_IsExtension)(f)) { + return UPB_PRIVATE(_upb_MiniTableField_IsScalar)(f); + } else { + return f->presence != 0; } +} - // TODO: add overwrite operation to minimize number of lookups. - bool removed = - upb_strtable_remove2(&map->table, strkey.data, strkey.size, NULL); - if (!upb_strtable_insert(&map->table, strkey.data, strkey.size, tabval, a)) { - return kUpb_MapInsertStatus_OutOfMemory; - } - return removed ? kUpb_MapInsertStatus_Replaced - : kUpb_MapInsertStatus_Inserted; +UPB_INLINE uint32_t +UPB_PRIVATE(_upb_MiniTableField_Number)(const struct upb_MiniTableField* f) { + return f->UPB_ONLYBITS(number); } -UPB_INLINE size_t _upb_Map_Size(const struct upb_Map* map) { - return map->table.t.count; +UPB_INLINE uint16_t +UPB_PRIVATE(_upb_MiniTableField_Offset)(const struct upb_MiniTableField* f) { + return f->UPB_ONLYBITS(offset); } -// Strings/bytes are special-cased in maps. -extern char _upb_Map_CTypeSizeTable[12]; +UPB_INLINE size_t UPB_PRIVATE(_upb_MiniTableField_OneofOffset)( + const struct upb_MiniTableField* f) { + UPB_ASSERT(UPB_PRIVATE(_upb_MiniTableField_IsInOneof)(f)); + return ~(ptrdiff_t)f->presence; +} -UPB_INLINE size_t _upb_Map_CTypeSize(upb_CType ctype) { - return _upb_Map_CTypeSizeTable[ctype]; +UPB_INLINE void UPB_PRIVATE(_upb_MiniTableField_CheckIsArray)( + const struct upb_MiniTableField* f) { + UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == + kUpb_FieldRep_NativePointer); + UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_IsArray)(f)); + UPB_ASSUME(f->presence == 0); } -// Creates a new map on the given arena with this key/value type. -struct upb_Map* _upb_Map_New(upb_Arena* a, size_t key_size, size_t value_size); +UPB_INLINE void UPB_PRIVATE(_upb_MiniTableField_CheckIsMap)( + const struct upb_MiniTableField* f) { + UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == + kUpb_FieldRep_NativePointer); + UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_IsMap)(f)); + UPB_ASSUME(f->presence == 0); +} + +UPB_INLINE size_t UPB_PRIVATE(_upb_MiniTableField_ElemSizeLg2)( + const struct upb_MiniTableField* f) { + const upb_FieldType field_type = UPB_PRIVATE(_upb_MiniTableField_Type)(f); + return UPB_PRIVATE(_upb_FieldType_SizeLg2)(field_type); +} + +// LINT.ThenChange(//depot/google3/third_party/upb/bits/typescript/mini_table_field.ts) #ifdef __cplusplus } /* extern "C" */ #endif -#endif /* UPB_MESSAGE_INTERNAL_MAP_H_ */ +#endif /* UPB_MINI_TABLE_INTERNAL_FIELD_H_ */ -/* -** Our memory representation for parsing tables and messages themselves. -** Functions in this file are used by generated code and possibly reflection. -** -** The definitions in this file are internal to upb. -**/ +// Must be last. -#ifndef UPB_MESSAGE_INTERNAL_MESSAGE_H_ -#define UPB_MESSAGE_INTERNAL_MESSAGE_H_ +typedef struct upb_MiniTableField upb_MiniTableField; -#include -#include +#ifdef __cplusplus +extern "C" { +#endif +UPB_API_INLINE upb_CType upb_MiniTableField_CType(const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_CType)(f); +} -#ifndef UPB_MESSAGE_INTERNAL_EXTENSION_H_ -#define UPB_MESSAGE_INTERNAL_EXTENSION_H_ +UPB_API_INLINE bool upb_MiniTableField_HasPresence( + const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_HasPresence)(f); +} +UPB_API_INLINE bool upb_MiniTableField_IsArray(const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_IsArray)(f); +} -#ifndef UPB_MINI_TABLE_EXTENSION_H_ -#define UPB_MINI_TABLE_EXTENSION_H_ +UPB_API_INLINE bool upb_MiniTableField_IsClosedEnum( + const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_IsClosedEnum)(f); +} -#include +UPB_API_INLINE bool upb_MiniTableField_IsExtension( + const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_IsExtension)(f); +} +UPB_API_INLINE bool upb_MiniTableField_IsInOneof(const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_IsInOneof)(f); +} -#ifndef UPB_MINI_TABLE_FIELD_H_ -#define UPB_MINI_TABLE_FIELD_H_ +UPB_API_INLINE bool upb_MiniTableField_IsMap(const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_IsMap)(f); +} -#include +UPB_API_INLINE bool upb_MiniTableField_IsPacked(const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_IsPacked)(f); +} +UPB_API_INLINE bool upb_MiniTableField_IsScalar(const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_IsScalar)(f); +} -#ifndef UPB_MINI_TABLE_INTERNAL_FIELD_H_ -#define UPB_MINI_TABLE_INTERNAL_FIELD_H_ +UPB_API_INLINE bool upb_MiniTableField_IsSubMessage( + const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_IsSubMessage)(f); +} -#include -#include +UPB_API_INLINE uint32_t upb_MiniTableField_Number(const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_Number)(f); +} +UPB_API_INLINE upb_FieldType +upb_MiniTableField_Type(const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_Type)(f); +} -#ifndef UPB_MINI_TABLE_INTERNAL_SIZE_LOG2_H_ -#define UPB_MINI_TABLE_INTERNAL_SIZE_LOG2_H_ +#ifdef __cplusplus +} /* extern "C" */ +#endif + + +#endif /* UPB_MINI_TABLE_FIELD_H_ */ + +#ifndef UPB_MINI_TABLE_INTERNAL_MESSAGE_H_ +#define UPB_MINI_TABLE_INTERNAL_MESSAGE_H_ -#include #include +#ifndef UPB_MINI_TABLE_INTERNAL_SUB_H_ +#define UPB_MINI_TABLE_INTERNAL_SUB_H_ + // Must be last. +union upb_MiniTableSub { + const struct upb_MiniTable* UPB_PRIVATE(submsg); + const struct upb_MiniTableEnum* UPB_PRIVATE(subenum); +}; + #ifdef __cplusplus extern "C" { #endif -// Return the log2 of the storage size in bytes for a upb_CType -UPB_INLINE int UPB_PRIVATE(_upb_CType_SizeLg2)(upb_CType c_type) { - static const int8_t size[] = { - 0, // kUpb_CType_Bool - 2, // kUpb_CType_Float - 2, // kUpb_CType_Int32 - 2, // kUpb_CType_UInt32 - 2, // kUpb_CType_Enum - UPB_SIZE(2, 3), // kUpb_CType_Message - 3, // kUpb_CType_Double - 3, // kUpb_CType_Int64 - 3, // kUpb_CType_UInt64 - UPB_SIZE(3, 4), // kUpb_CType_String - UPB_SIZE(3, 4), // kUpb_CType_Bytes - }; +UPB_INLINE union upb_MiniTableSub UPB_PRIVATE(_upb_MiniTableSub_FromEnum)( + const struct upb_MiniTableEnum* subenum) { + union upb_MiniTableSub out; + out.UPB_PRIVATE(subenum) = subenum; + return out; +} - // -1 here because the enum is one-based but the table is zero-based. - return size[c_type - 1]; +UPB_INLINE union upb_MiniTableSub UPB_PRIVATE(_upb_MiniTableSub_FromMessage)( + const struct upb_MiniTable* submsg) { + union upb_MiniTableSub out; + out.UPB_PRIVATE(submsg) = submsg; + return out; } -// Return the log2 of the storage size in bytes for a upb_FieldType -UPB_INLINE int UPB_PRIVATE(_upb_FieldType_SizeLg2)(upb_FieldType field_type) { - static const int8_t size[] = { - 3, // kUpb_FieldType_Double - 2, // kUpb_FieldType_Float - 3, // kUpb_FieldType_Int64 - 3, // kUpb_FieldType_UInt64 - 2, // kUpb_FieldType_Int32 - 3, // kUpb_FieldType_Fixed64 - 2, // kUpb_FieldType_Fixed32 - 0, // kUpb_FieldType_Bool - UPB_SIZE(3, 4), // kUpb_FieldType_String - UPB_SIZE(2, 3), // kUpb_FieldType_Group - UPB_SIZE(2, 3), // kUpb_FieldType_Message - UPB_SIZE(3, 4), // kUpb_FieldType_Bytes - 2, // kUpb_FieldType_UInt32 - 2, // kUpb_FieldType_Enum - 2, // kUpb_FieldType_SFixed32 - 3, // kUpb_FieldType_SFixed64 - 2, // kUpb_FieldType_SInt32 - 3, // kUpb_FieldType_SInt64 - }; +UPB_INLINE const struct upb_MiniTableEnum* UPB_PRIVATE(_upb_MiniTableSub_Enum)( + const union upb_MiniTableSub sub) { + return sub.UPB_PRIVATE(subenum); +} - // -1 here because the enum is one-based but the table is zero-based. - return size[field_type - 1]; +UPB_INLINE const struct upb_MiniTable* UPB_PRIVATE(_upb_MiniTableSub_Message)( + const union upb_MiniTableSub sub) { + return sub.UPB_PRIVATE(submsg); } #ifdef __cplusplus @@ -1493,332 +1420,341 @@ UPB_INLINE int UPB_PRIVATE(_upb_FieldType_SizeLg2)(upb_FieldType field_type) { #endif -#endif /* UPB_MINI_TABLE_INTERNAL_SIZE_LOG2_H_ */ +#endif /* UPB_MINI_TABLE_INTERNAL_SUB_H_ */ // Must be last. -// LINT.IfChange(struct_definition) -struct upb_MiniTableField { - uint32_t UPB_ONLYBITS(number); - uint16_t UPB_ONLYBITS(offset); - int16_t presence; // If >0, hasbit_index. If <0, ~oneof_index - - // Indexes into `upb_MiniTable.subs` - // Will be set to `kUpb_NoSub` if `descriptortype` != MESSAGE/GROUP/ENUM - uint16_t UPB_PRIVATE(submsg_index); - - uint8_t UPB_PRIVATE(descriptortype); +struct upb_Decoder; +struct upb_Message; +typedef const char* _upb_FieldParser(struct upb_Decoder* d, const char* ptr, + struct upb_Message* msg, intptr_t table, + uint64_t hasbits, uint64_t data); +typedef struct { + uint64_t field_data; + _upb_FieldParser* field_parser; +} _upb_FastTable_Entry; - // upb_FieldMode | upb_LabelFlags | (upb_FieldRep << kUpb_FieldRep_Shift) - uint8_t UPB_ONLYBITS(mode); -}; +typedef enum { + kUpb_ExtMode_NonExtendable = 0, // Non-extendable message. + kUpb_ExtMode_Extendable = 1, // Normal extendable message. + kUpb_ExtMode_IsMessageSet = 2, // MessageSet message. + kUpb_ExtMode_IsMessageSet_ITEM = + 3, // MessageSet item (temporary only, see decode.c) -#define kUpb_NoSub ((uint16_t)-1) + // During table building we steal a bit to indicate that the message is a map + // entry. *Only* used during table building! + kUpb_ExtMode_IsMapEntry = 4, +} upb_ExtMode; -typedef enum { - kUpb_FieldMode_Map = 0, - kUpb_FieldMode_Array = 1, - kUpb_FieldMode_Scalar = 2, -} upb_FieldMode; +// 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. -// Mask to isolate the upb_FieldMode from field.mode. -#define kUpb_FieldMode_Mask 3 +// LINT.IfChange(minitable_struct_definition) +struct upb_MiniTable { + const union upb_MiniTableSub* UPB_PRIVATE(subs); + const struct upb_MiniTableField* UPB_ONLYBITS(fields); -// Extra flags on the mode field. -typedef enum { - kUpb_LabelFlags_IsPacked = 4, - kUpb_LabelFlags_IsExtension = 8, - // Indicates that this descriptor type is an "alternate type": - // - for Int32, this indicates that the actual type is Enum (but was - // rewritten to Int32 because it is an open enum that requires no check). - // - for Bytes, this indicates that the actual type is String (but does - // not require any UTF-8 check). - kUpb_LabelFlags_IsAlternate = 16, -} upb_LabelFlags; + // Must be aligned to sizeof(void*). Doesn't include internal members like + // unknown fields, extension dict, pointer to msglayout, etc. + uint16_t UPB_PRIVATE(size); -// Note: we sort by this number when calculating layout order. -typedef enum { - kUpb_FieldRep_1Byte = 0, - kUpb_FieldRep_4Byte = 1, - kUpb_FieldRep_StringView = 2, - kUpb_FieldRep_8Byte = 3, + uint16_t UPB_ONLYBITS(field_count); - kUpb_FieldRep_NativePointer = - UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte), - kUpb_FieldRep_Max = kUpb_FieldRep_8Byte, -} upb_FieldRep; + uint8_t UPB_PRIVATE(ext); // upb_ExtMode, uint8_t here so sizeof(ext) == 1 + uint8_t UPB_PRIVATE(dense_below); + uint8_t UPB_PRIVATE(table_mask); + uint8_t UPB_PRIVATE(required_count); // Required fields have the low hasbits. -#define kUpb_FieldRep_Shift 6 + // To statically initialize the tables of variable length, we need a flexible + // array member, and we need to compile in gnu99 mode (constant initialization + // of flexible array members is a GNU extension, not in C99 unfortunately. + _upb_FastTable_Entry UPB_PRIVATE(fasttable)[]; +}; +// LINT.ThenChange(//depot/google3/third_party/upb/bits/typescript/mini_table.ts) #ifdef __cplusplus extern "C" { #endif -UPB_INLINE upb_FieldMode -UPB_PRIVATE(_upb_MiniTableField_Mode)(const struct upb_MiniTableField* f) { - return (upb_FieldMode)(f->UPB_ONLYBITS(mode) & kUpb_FieldMode_Mask); +UPB_INLINE const struct upb_MiniTable* UPB_PRIVATE(_upb_MiniTable_Empty)(void) { + extern const struct upb_MiniTable UPB_PRIVATE(_kUpb_MiniTable_Empty); + + return &UPB_PRIVATE(_kUpb_MiniTable_Empty); } -UPB_INLINE upb_FieldRep -UPB_PRIVATE(_upb_MiniTableField_GetRep)(const struct upb_MiniTableField* f) { - return (upb_FieldRep)(f->UPB_ONLYBITS(mode) >> kUpb_FieldRep_Shift); +UPB_INLINE int UPB_PRIVATE(_upb_MiniTable_FieldCount)( + const struct upb_MiniTable* m) { + return m->UPB_ONLYBITS(field_count); } -UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsArray)( - const struct upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTableField_Mode)(f) == kUpb_FieldMode_Array; +UPB_INLINE bool UPB_PRIVATE(_upb_MiniTable_IsEmpty)( + const struct upb_MiniTable* m) { + extern const struct upb_MiniTable UPB_PRIVATE(_kUpb_MiniTable_Empty); + + return m == &UPB_PRIVATE(_kUpb_MiniTable_Empty); } -UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsMap)( - const struct upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTableField_Mode)(f) == kUpb_FieldMode_Map; -} - -UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsScalar)( - const struct upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTableField_Mode)(f) == kUpb_FieldMode_Scalar; -} - -UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsAlternate)( - const struct upb_MiniTableField* f) { - return (f->UPB_ONLYBITS(mode) & kUpb_LabelFlags_IsAlternate) != 0; -} - -UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsExtension)( - const struct upb_MiniTableField* f) { - return (f->UPB_ONLYBITS(mode) & kUpb_LabelFlags_IsExtension) != 0; -} - -UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsPacked)( - const struct upb_MiniTableField* f) { - return (f->UPB_ONLYBITS(mode) & kUpb_LabelFlags_IsPacked) != 0; -} - -UPB_INLINE upb_FieldType -UPB_PRIVATE(_upb_MiniTableField_Type)(const struct upb_MiniTableField* f) { - const upb_FieldType type = (upb_FieldType)f->UPB_PRIVATE(descriptortype); - if (UPB_PRIVATE(_upb_MiniTableField_IsAlternate)(f)) { - if (type == kUpb_FieldType_Int32) return kUpb_FieldType_Enum; - if (type == kUpb_FieldType_Bytes) return kUpb_FieldType_String; - UPB_ASSERT(false); - } - return type; -} - -UPB_INLINE upb_CType -UPB_PRIVATE(_upb_MiniTableField_CType)(const struct upb_MiniTableField* f) { - return upb_FieldType_CType(UPB_PRIVATE(_upb_MiniTableField_Type)(f)); -} - -UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_HasHasbit)( - const struct upb_MiniTableField* f) { - return f->presence > 0; -} - -UPB_INLINE char UPB_PRIVATE(_upb_MiniTableField_HasbitMask)( - const struct upb_MiniTableField* f) { - UPB_ASSERT(UPB_PRIVATE(_upb_MiniTableField_HasHasbit)(f)); - const size_t index = f->presence; - return 1 << (index % 8); -} - -UPB_INLINE size_t UPB_PRIVATE(_upb_MiniTableField_HasbitOffset)( - const struct upb_MiniTableField* f) { - UPB_ASSERT(UPB_PRIVATE(_upb_MiniTableField_HasHasbit)(f)); - const size_t index = f->presence; - return index / 8; -} - -UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsClosedEnum)( - const struct upb_MiniTableField* f) { - return f->UPB_PRIVATE(descriptortype) == kUpb_FieldType_Enum; -} - -UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsInOneof)( - const struct upb_MiniTableField* f) { - return f->presence < 0; -} - -UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsSubMessage)( - const struct upb_MiniTableField* f) { - return f->UPB_PRIVATE(descriptortype) == kUpb_FieldType_Message || - f->UPB_PRIVATE(descriptortype) == kUpb_FieldType_Group; +UPB_INLINE const struct upb_MiniTableField* UPB_PRIVATE( + _upb_MiniTable_GetFieldByIndex)(const struct upb_MiniTable* m, uint32_t i) { + return &m->UPB_ONLYBITS(fields)[i]; } -UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_HasPresence)( - const struct upb_MiniTableField* f) { - if (UPB_PRIVATE(_upb_MiniTableField_IsExtension)(f)) { - return UPB_PRIVATE(_upb_MiniTableField_IsScalar)(f); - } else { - return f->presence != 0; - } +UPB_INLINE const union upb_MiniTableSub* UPB_PRIVATE( + _upb_MiniTable_GetSubByIndex)(const struct upb_MiniTable* m, uint32_t i) { + return &m->UPB_PRIVATE(subs)[i]; } -UPB_INLINE uint32_t -UPB_PRIVATE(_upb_MiniTableField_Number)(const struct upb_MiniTableField* f) { - return f->UPB_ONLYBITS(number); +UPB_INLINE const struct upb_MiniTable* UPB_PRIVATE( + _upb_MiniTable_GetSubMessageTable)(const struct upb_MiniTable* m, + const struct upb_MiniTableField* f) { + UPB_ASSERT(UPB_PRIVATE(_upb_MiniTableField_CType)(f) == kUpb_CType_Message); + const struct upb_MiniTable* ret = UPB_PRIVATE(_upb_MiniTableSub_Message)( + m->UPB_PRIVATE(subs)[f->UPB_PRIVATE(submsg_index)]); + UPB_ASSUME(ret); + return UPB_PRIVATE(_upb_MiniTable_IsEmpty)(ret) ? NULL : ret; } -UPB_INLINE uint16_t -UPB_PRIVATE(_upb_MiniTableField_Offset)(const struct upb_MiniTableField* f) { - return f->UPB_ONLYBITS(offset); +UPB_INLINE const struct upb_MiniTableEnum* UPB_PRIVATE( + _upb_MiniTable_GetSubEnumTable)(const struct upb_MiniTable* m, + const struct upb_MiniTableField* f) { + UPB_ASSERT(UPB_PRIVATE(_upb_MiniTableField_CType)(f) == kUpb_CType_Enum); + return UPB_PRIVATE(_upb_MiniTableSub_Enum)( + m->UPB_PRIVATE(subs)[f->UPB_PRIVATE(submsg_index)]); } -UPB_INLINE size_t UPB_PRIVATE(_upb_MiniTableField_OneofOffset)( - const struct upb_MiniTableField* f) { - UPB_ASSERT(UPB_PRIVATE(_upb_MiniTableField_IsInOneof)(f)); - return ~(ptrdiff_t)f->presence; +UPB_INLINE const struct upb_MiniTableField* UPB_PRIVATE(_upb_MiniTable_MapKey)( + const struct upb_MiniTable* m) { + UPB_ASSERT(UPB_PRIVATE(_upb_MiniTable_FieldCount)(m) == 2); + const struct upb_MiniTableField* f = + UPB_PRIVATE(_upb_MiniTable_GetFieldByIndex)(m, 0); + UPB_ASSERT(UPB_PRIVATE(_upb_MiniTableField_Number)(f) == 1); + return f; } -UPB_INLINE void UPB_PRIVATE(_upb_MiniTableField_CheckIsArray)( - const struct upb_MiniTableField* f) { - UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == - kUpb_FieldRep_NativePointer); - UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_IsArray)(f)); - UPB_ASSUME(f->presence == 0); +UPB_INLINE const struct upb_MiniTableField* UPB_PRIVATE( + _upb_MiniTable_MapValue)(const struct upb_MiniTable* m) { + UPB_ASSERT(UPB_PRIVATE(_upb_MiniTable_FieldCount)(m) == 2); + const struct upb_MiniTableField* f = + UPB_PRIVATE(_upb_MiniTable_GetFieldByIndex)(m, 1); + UPB_ASSERT(UPB_PRIVATE(_upb_MiniTableField_Number)(f) == 2); + return f; } -UPB_INLINE void UPB_PRIVATE(_upb_MiniTableField_CheckIsMap)( - const struct upb_MiniTableField* f) { - UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == - kUpb_FieldRep_NativePointer); - UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_IsMap)(f)); - UPB_ASSUME(f->presence == 0); +UPB_INLINE bool UPB_PRIVATE(_upb_MiniTable_MessageFieldIsLinked)( + const struct upb_MiniTable* m, const struct upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTable_GetSubMessageTable)(m, f) != NULL; } -UPB_INLINE size_t UPB_PRIVATE(_upb_MiniTableField_ElemSizeLg2)( - const struct upb_MiniTableField* f) { - const upb_FieldType field_type = UPB_PRIVATE(_upb_MiniTableField_Type)(f); - return UPB_PRIVATE(_upb_FieldType_SizeLg2)(field_type); +// Computes a bitmask in which the |m->required_count| lowest bits are set, +// except that we skip the lowest bit (because upb never uses hasbit 0). +// +// Sample output: +// RequiredMask(1) => 0b10 (0x2) +// RequiredMask(5) => 0b111110 (0x3e) +UPB_INLINE uint64_t +UPB_PRIVATE(_upb_MiniTable_RequiredMask)(const struct upb_MiniTable* m) { + int n = m->UPB_PRIVATE(required_count); + UPB_ASSERT(0 < n && n <= 63); + return ((1ULL << n) - 1) << 1; } -// LINT.ThenChange(//depot/google3/third_party/upb/bits/typescript/mini_table_field.ts) - #ifdef __cplusplus } /* extern "C" */ #endif -#endif /* UPB_MINI_TABLE_INTERNAL_FIELD_H_ */ +#endif /* UPB_MINI_TABLE_INTERNAL_MESSAGE_H_ */ // Must be last. -typedef struct upb_MiniTableField upb_MiniTableField; +typedef struct upb_MiniTable upb_MiniTable; #ifdef __cplusplus extern "C" { #endif -UPB_API_INLINE upb_CType upb_MiniTableField_CType(const upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTableField_CType)(f); -} - -UPB_API_INLINE bool upb_MiniTableField_HasPresence( - const upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTableField_HasPresence)(f); -} - -UPB_API_INLINE bool upb_MiniTableField_IsArray(const upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTableField_IsArray)(f); -} +UPB_API const upb_MiniTableField* upb_MiniTable_FindFieldByNumber( + const upb_MiniTable* m, uint32_t number); -UPB_API_INLINE bool upb_MiniTableField_IsClosedEnum( - const upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTableField_IsClosedEnum)(f); +UPB_API_INLINE const upb_MiniTableField* upb_MiniTable_GetFieldByIndex( + const upb_MiniTable* m, uint32_t index) { + return UPB_PRIVATE(_upb_MiniTable_GetFieldByIndex)(m, index); } -UPB_API_INLINE bool upb_MiniTableField_IsExtension( - const upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTableField_IsExtension)(f); +UPB_API_INLINE int upb_MiniTable_FieldCount(const upb_MiniTable* m) { + return UPB_PRIVATE(_upb_MiniTable_FieldCount)(m); } -UPB_API_INLINE bool upb_MiniTableField_IsInOneof(const upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTableField_IsInOneof)(f); +// Returns the MiniTable for a message field, NULL if the field is unlinked. +UPB_API_INLINE const upb_MiniTable* upb_MiniTable_GetSubMessageTable( + const upb_MiniTable* m, const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTable_GetSubMessageTable)(m, f); } -UPB_API_INLINE bool upb_MiniTableField_IsMap(const upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTableField_IsMap)(f); +// Returns the MiniTableEnum for a message field, NULL if the field is unlinked. +UPB_API_INLINE const upb_MiniTableEnum* upb_MiniTable_GetSubEnumTable( + const upb_MiniTable* m, const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTable_GetSubEnumTable)(m, f); } -UPB_API_INLINE bool upb_MiniTableField_IsPacked(const upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTableField_IsPacked)(f); +// Returns the MiniTableField for the key of a map. +UPB_API_INLINE const upb_MiniTableField* upb_MiniTable_MapKey( + const upb_MiniTable* m) { + return UPB_PRIVATE(_upb_MiniTable_MapKey)(m); } -UPB_API_INLINE bool upb_MiniTableField_IsScalar(const upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTableField_IsScalar)(f); +// Returns the MiniTableField for the value of a map. +UPB_API_INLINE const upb_MiniTableField* upb_MiniTable_MapValue( + const upb_MiniTable* m) { + return UPB_PRIVATE(_upb_MiniTable_MapValue)(m); } -UPB_API_INLINE bool upb_MiniTableField_IsSubMessage( - const upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTableField_IsSubMessage)(f); +// Returns true if this MiniTable field is linked to a MiniTable for the +// sub-message. +UPB_API_INLINE bool upb_MiniTable_MessageFieldIsLinked( + const upb_MiniTable* m, const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTable_MessageFieldIsLinked)(m, f); } -UPB_API_INLINE uint32_t upb_MiniTableField_Number(const upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTableField_Number)(f); -} +// If this field is in a oneof, returns the first field in the oneof. +// +// Otherwise returns NULL. +// +// Usage: +// const upb_MiniTableField* field = upb_MiniTable_GetOneof(m, f); +// do { +// .. +// } while (upb_MiniTable_NextOneofField(m, &field); +// +const upb_MiniTableField* upb_MiniTable_GetOneof(const upb_MiniTable* m, + const upb_MiniTableField* f); -UPB_API_INLINE upb_FieldType -upb_MiniTableField_Type(const upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTableField_Type)(f); -} +// Iterates to the next field in the oneof. If this is the last field in the +// oneof, returns false. The ordering of fields in the oneof is not +// guaranteed. +// REQUIRES: |f| is the field initialized by upb_MiniTable_GetOneof and updated +// by prior upb_MiniTable_NextOneofField calls. +bool upb_MiniTable_NextOneofField(const upb_MiniTable* m, + const upb_MiniTableField** f); #ifdef __cplusplus } /* extern "C" */ #endif -#endif /* UPB_MINI_TABLE_FIELD_H_ */ +#endif /* UPB_MINI_TABLE_MESSAGE_H_ */ -#ifndef UPB_MINI_TABLE_INTERNAL_EXTENSION_H_ -#define UPB_MINI_TABLE_INTERNAL_EXTENSION_H_ +// Must be last. -#include +#ifdef __cplusplus +extern "C" { +#endif +extern const float kUpb_FltInfinity; +extern const double kUpb_Infinity; +extern const double kUpb_NaN; -#ifndef UPB_MINI_TABLE_INTERNAL_SUB_H_ -#define UPB_MINI_TABLE_INTERNAL_SUB_H_ +/* Internal members of a upb_Message that track unknown fields and/or + * extensions. We can change this without breaking binary compatibility. We put + * these before the user's data. The user's upb_Message* points after the + * upb_Message_Internal. */ -// Must be last. +typedef struct { + /* Total size of this structure, including the data that follows. + * Must be aligned to 8, which is alignof(upb_Extension) */ + uint32_t size; -union upb_MiniTableSub { - const struct upb_MiniTable* UPB_PRIVATE(submsg); - const struct upb_MiniTableEnum* UPB_PRIVATE(subenum); -}; + /* Offsets relative to the beginning of this structure. + * + * Unknown data grows forward from the beginning to unknown_end. + * Extension data grows backward from size to ext_begin. + * When the two meet, we're out of data and have to realloc. + * + * If we imagine that the final member of this struct is: + * char data[size - overhead]; // overhead = + * sizeof(upb_Message_InternalData) + * + * Then we have: + * unknown data: data[0 .. (unknown_end - overhead)] + * extensions data: data[(ext_begin - overhead) .. (size - overhead)] */ + uint32_t unknown_end; + uint32_t ext_begin; + /* Data follows, as if there were an array: + * char data[size - sizeof(upb_Message_InternalData)]; */ +} upb_Message_InternalData; -#ifdef __cplusplus -extern "C" { -#endif +typedef struct { + union { + upb_Message_InternalData* internal; -UPB_INLINE union upb_MiniTableSub UPB_PRIVATE(_upb_MiniTableSub_FromEnum)( - const struct upb_MiniTableEnum* subenum) { - union upb_MiniTableSub out; - out.UPB_PRIVATE(subenum) = subenum; - return out; + // Force 8-byte alignment, since the data members may contain members that + // require 8-byte alignment. + double d; + }; +} upb_Message_Internal; + +struct upb_Message { + int unused; // Placeholder cuz Windows won't compile an empty struct. +}; + +UPB_INLINE size_t upb_msg_sizeof(const upb_MiniTable* m) { + return m->UPB_PRIVATE(size) + sizeof(upb_Message_Internal); } -UPB_INLINE union upb_MiniTableSub UPB_PRIVATE(_upb_MiniTableSub_FromMessage)( - const struct upb_MiniTable* submsg) { - union upb_MiniTableSub out; - out.UPB_PRIVATE(submsg) = submsg; - return out; +// Inline version upb_Message_New(), for internal use. +UPB_INLINE struct upb_Message* _upb_Message_New(const upb_MiniTable* mini_table, + upb_Arena* arena) { + size_t size = upb_msg_sizeof(mini_table); + void* mem = upb_Arena_Malloc(arena, size + sizeof(upb_Message_Internal)); + if (UPB_UNLIKELY(!mem)) return NULL; + struct upb_Message* msg = + UPB_PTR_AT(mem, sizeof(upb_Message_Internal), struct upb_Message); + memset(mem, 0, size); + return msg; } -UPB_INLINE const struct upb_MiniTableEnum* UPB_PRIVATE(_upb_MiniTableSub_Enum)( - const union upb_MiniTableSub sub) { - return sub.UPB_PRIVATE(subenum); +UPB_INLINE upb_Message_Internal* upb_Message_Getinternal( + const struct upb_Message* msg) { + ptrdiff_t size = sizeof(upb_Message_Internal); + return (upb_Message_Internal*)((char*)msg - size); } -UPB_INLINE const struct upb_MiniTable* UPB_PRIVATE(_upb_MiniTableSub_Message)( - const union upb_MiniTableSub sub) { - return sub.UPB_PRIVATE(submsg); +UPB_INLINE upb_Message_InternalData* upb_Message_GetInternalData( + const struct upb_Message* msg) { + return upb_Message_Getinternal(msg)->internal; } +// Discards the unknown fields for this message only. +void _upb_Message_DiscardUnknown_shallow(struct upb_Message* msg); + +// Adds unknown data (serialized protobuf data) to the given message. +// The data is copied into the message instance. +bool UPB_PRIVATE(_upb_Message_AddUnknown)(struct upb_Message* msg, + const char* data, size_t len, + upb_Arena* arena); + +bool UPB_PRIVATE(_upb_Message_Realloc)(struct upb_Message* msg, size_t need, + upb_Arena* arena); + #ifdef __cplusplus } /* extern "C" */ #endif -#endif /* UPB_MINI_TABLE_INTERNAL_SUB_H_ */ +#endif /* UPB_MESSAGE_INTERNAL_MESSAGE_H_ */ + +#ifndef UPB_MINI_TABLE_EXTENSION_H_ +#define UPB_MINI_TABLE_EXTENSION_H_ + +#include + + +#ifndef UPB_MINI_TABLE_INTERNAL_EXTENSION_H_ +#define UPB_MINI_TABLE_INTERNAL_EXTENSION_H_ + +#include + // Must be last. @@ -1862,56 +1798,32 @@ UPB_INLINE void UPB_PRIVATE(_upb_MiniTableExtension_SetSubMessage)( #endif /* UPB_MINI_TABLE_INTERNAL_EXTENSION_H_ */ -#ifndef UPB_MINI_TABLE_MESSAGE_H_ -#define UPB_MINI_TABLE_MESSAGE_H_ - - -#ifndef UPB_MINI_TABLE_ENUM_H_ -#define UPB_MINI_TABLE_ENUM_H_ - -#include - - -#ifndef UPB_MINI_TABLE_INTERNAL_ENUM_H_ -#define UPB_MINI_TABLE_INTERNAL_ENUM_H_ - -#include - // Must be last. -struct upb_MiniTableEnum { - uint32_t UPB_PRIVATE(mask_limit); // Highest that can be tested with mask. - uint32_t UPB_PRIVATE(value_count); // Number of values after the bitfield. - uint32_t UPB_PRIVATE(data)[]; // Bitmask + enumerated values follow. -}; +typedef struct upb_MiniTableExtension upb_MiniTableExtension; #ifdef __cplusplus extern "C" { #endif -UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableEnum_CheckValue)( - const struct upb_MiniTableEnum* e, uint32_t val) { - if (UPB_LIKELY(val < 64)) { - const uint64_t mask = - e->UPB_PRIVATE(data)[0] | ((uint64_t)e->UPB_PRIVATE(data)[1] << 32); - const uint64_t bit = 1ULL << val; - return (mask & bit) != 0; - } - if (UPB_LIKELY(val < e->UPB_PRIVATE(mask_limit))) { - const uint32_t mask = e->UPB_PRIVATE(data)[val / 32]; - const uint32_t bit = 1ULL << (val % 32); - return (mask & bit) != 0; - } +UPB_API_INLINE const upb_MiniTableField* upb_MiniTableExtension_AsField( + const upb_MiniTableExtension* e) { + return UPB_PRIVATE(_upb_MiniTableExtension_AsField)(e); +} - // OPT: binary search long lists? - const uint32_t* start = - &e->UPB_PRIVATE(data)[e->UPB_PRIVATE(mask_limit) / 32]; - const uint32_t* limit = &e->UPB_PRIVATE( - data)[e->UPB_PRIVATE(mask_limit) / 32 + e->UPB_PRIVATE(value_count)]; - for (const uint32_t* p = start; p < limit; p++) { - if (*p == val) return true; - } - return false; +UPB_API_INLINE uint32_t +upb_MiniTableExtension_Number(const upb_MiniTableExtension* e) { + return UPB_PRIVATE(_upb_MiniTableExtension_Number)(e); +} + +UPB_API_INLINE const upb_MiniTable* upb_MiniTableExtension_GetSubMessage( + const upb_MiniTableExtension* e) { + return UPB_PRIVATE(_upb_MiniTableExtension_GetSubMessage)(e); +} + +UPB_API_INLINE void upb_MiniTableExtension_SetSubMessage( + upb_MiniTableExtension* e, const upb_MiniTable* m) { + UPB_PRIVATE(_upb_MiniTableExtension_SetSubMessage)(e, m); } #ifdef __cplusplus @@ -1919,438 +1831,499 @@ UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableEnum_CheckValue)( #endif -#endif /* UPB_MINI_TABLE_INTERNAL_ENUM_H_ */ +#endif /* UPB_MINI_TABLE_EXTENSION_H_ */ -// Must be last +// Must be last. -typedef struct upb_MiniTableEnum upb_MiniTableEnum; +// The internal representation of an extension is self-describing: it contains +// enough information that we can serialize it to binary format without needing +// to look it up in a upb_ExtensionRegistry. +// +// This representation allocates 16 bytes to data on 64-bit platforms. +// This is rather wasteful for scalars (in the extreme case of bool, +// it wastes 15 bytes). We accept this because we expect messages to be +// the most common extension type. +struct upb_Extension { + const upb_MiniTableExtension* ext; + union { + upb_StringView str; + void* ptr; + char scalar_data[8]; + } data; +}; #ifdef __cplusplus extern "C" { #endif -// Validates enum value against range defined by enum mini table. -UPB_INLINE bool upb_MiniTableEnum_CheckValue(const upb_MiniTableEnum* e, - uint32_t val) { - return UPB_PRIVATE(_upb_MiniTableEnum_CheckValue)(e, val); -} +// Adds the given extension data to the given message. +// |ext| is copied into the message instance. +// This logically replaces any previously-added extension with this number. +struct upb_Extension* _upb_Message_GetOrCreateExtension( + struct upb_Message* msg, const upb_MiniTableExtension* ext, + upb_Arena* arena); + +// Returns an array of extensions for this message. +// Note: the array is ordered in reverse relative to the order of creation. +const struct upb_Extension* UPB_PRIVATE(_upb_Message_Getexts)( + const struct upb_Message* msg, size_t* count); + +// Returns an extension for a message with a given mini table, +// or NULL if no extension exists with this mini table. +const struct upb_Extension* _upb_Message_Getext( + const struct upb_Message* msg, const upb_MiniTableExtension* ext); #ifdef __cplusplus } /* extern "C" */ #endif -#endif /* UPB_MINI_TABLE_ENUM_H_ */ +#endif /* UPB_MESSAGE_INTERNAL_EXTENSION_H_ */ -#ifndef UPB_MINI_TABLE_INTERNAL_MESSAGE_H_ -#define UPB_MINI_TABLE_INTERNAL_MESSAGE_H_ +#ifndef UPB_MESSAGE_INTERNAL_MAP_H_ +#define UPB_MESSAGE_INTERNAL_MAP_H_ -#include +#include +#include -// Must be last. +#ifndef UPB_HASH_STR_TABLE_H_ +#define UPB_HASH_STR_TABLE_H_ -struct upb_Decoder; -struct upb_Message; -typedef const char* _upb_FieldParser(struct upb_Decoder* d, const char* ptr, - struct upb_Message* msg, intptr_t table, - uint64_t hasbits, uint64_t data); -typedef struct { - uint64_t field_data; - _upb_FieldParser* field_parser; -} _upb_FastTable_Entry; -typedef enum { - kUpb_ExtMode_NonExtendable = 0, // Non-extendable message. - kUpb_ExtMode_Extendable = 1, // Normal extendable message. - kUpb_ExtMode_IsMessageSet = 2, // MessageSet message. - kUpb_ExtMode_IsMessageSet_ITEM = - 3, // MessageSet item (temporary only, see decode.c) +/* + * upb_table + * + * This header is INTERNAL-ONLY! Its interfaces are not public or stable! + * This file defines very fast int->upb_value (inttable) and string->upb_value + * (strtable) hash tables. + * + * The table uses chained scatter with Brent's variation (inspired by the Lua + * implementation of hash tables). The hash function for strings is Austin + * Appleby's "MurmurHash." + * + * The inttable uses uintptr_t as its key, which guarantees it can be used to + * store pointers or integers of at least 32 bits (upb isn't really useful on + * systems where sizeof(void*) < 4). + * + * The table must be homogeneous (all values of the same type). In debug + * mode, we check this on insert and lookup. + */ - // During table building we steal a bit to indicate that the message is a map - // entry. *Only* used during table building! - kUpb_ExtMode_IsMapEntry = 4, -} upb_ExtMode; - -// 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. - -// LINT.IfChange(minitable_struct_definition) -struct upb_MiniTable { - const union upb_MiniTableSub* UPB_PRIVATE(subs); - const struct upb_MiniTableField* UPB_ONLYBITS(fields); - - // Must be aligned to sizeof(void*). Doesn't include internal members like - // unknown fields, extension dict, pointer to msglayout, etc. - uint16_t UPB_PRIVATE(size); +#ifndef UPB_HASH_COMMON_H_ +#define UPB_HASH_COMMON_H_ - uint16_t UPB_ONLYBITS(field_count); +#include - uint8_t UPB_PRIVATE(ext); // upb_ExtMode, uint8_t here so sizeof(ext) == 1 - uint8_t UPB_PRIVATE(dense_below); - uint8_t UPB_PRIVATE(table_mask); - uint8_t UPB_PRIVATE(required_count); // Required fields have the low hasbits. - // To statically initialize the tables of variable length, we need a flexible - // array member, and we need to compile in gnu99 mode (constant initialization - // of flexible array members is a GNU extension, not in C99 unfortunately. - _upb_FastTable_Entry UPB_PRIVATE(fasttable)[]; -}; -// LINT.ThenChange(//depot/google3/third_party/upb/bits/typescript/mini_table.ts) +// Must be last. #ifdef __cplusplus extern "C" { #endif -UPB_INLINE const struct upb_MiniTable* UPB_PRIVATE(_upb_MiniTable_Empty)(void) { - extern const struct upb_MiniTable UPB_PRIVATE(_kUpb_MiniTable_Empty); +/* upb_value ******************************************************************/ - return &UPB_PRIVATE(_kUpb_MiniTable_Empty); -} +typedef struct { + uint64_t val; +} upb_value; -UPB_INLINE int UPB_PRIVATE(_upb_MiniTable_FieldCount)( - const struct upb_MiniTable* m) { - return m->UPB_ONLYBITS(field_count); -} +UPB_INLINE void _upb_value_setval(upb_value* v, uint64_t val) { v->val = val; } -UPB_INLINE bool UPB_PRIVATE(_upb_MiniTable_IsEmpty)( - const struct upb_MiniTable* m) { - extern const struct upb_MiniTable UPB_PRIVATE(_kUpb_MiniTable_Empty); +/* For each value ctype, define the following set of functions: + * + * // Get/set an int32 from a upb_value. + * int32_t upb_value_getint32(upb_value val); + * void upb_value_setint32(upb_value *val, int32_t cval); + * + * // Construct a new upb_value from an int32. + * upb_value upb_value_int32(int32_t val); */ +#define FUNCS(name, membername, type_t, converter) \ + UPB_INLINE void upb_value_set##name(upb_value* val, type_t cval) { \ + val->val = (converter)cval; \ + } \ + UPB_INLINE upb_value upb_value_##name(type_t val) { \ + upb_value ret; \ + upb_value_set##name(&ret, val); \ + return ret; \ + } \ + UPB_INLINE type_t upb_value_get##name(upb_value val) { \ + return (type_t)(converter)val.val; \ + } - return m == &UPB_PRIVATE(_kUpb_MiniTable_Empty); -} +FUNCS(int32, int32, int32_t, int32_t) +FUNCS(int64, int64, int64_t, int64_t) +FUNCS(uint32, uint32, uint32_t, uint32_t) +FUNCS(uint64, uint64, uint64_t, uint64_t) +FUNCS(bool, _bool, bool, bool) +FUNCS(cstr, cstr, char*, uintptr_t) +FUNCS(uintptr, uptr, uintptr_t, uintptr_t) +FUNCS(ptr, ptr, void*, uintptr_t) +FUNCS(constptr, constptr, const void*, uintptr_t) -UPB_INLINE const struct upb_MiniTableField* UPB_PRIVATE( - _upb_MiniTable_GetFieldByIndex)(const struct upb_MiniTable* m, uint32_t i) { - return &m->UPB_ONLYBITS(fields)[i]; -} +#undef FUNCS -UPB_INLINE const union upb_MiniTableSub* UPB_PRIVATE( - _upb_MiniTable_GetSubByIndex)(const struct upb_MiniTable* m, uint32_t i) { - return &m->UPB_PRIVATE(subs)[i]; +UPB_INLINE void upb_value_setfloat(upb_value* val, float cval) { + memcpy(&val->val, &cval, sizeof(cval)); } -UPB_INLINE const struct upb_MiniTable* UPB_PRIVATE( - _upb_MiniTable_GetSubMessageTable)(const struct upb_MiniTable* m, - const struct upb_MiniTableField* f) { - UPB_ASSERT(UPB_PRIVATE(_upb_MiniTableField_CType)(f) == kUpb_CType_Message); - const struct upb_MiniTable* ret = UPB_PRIVATE(_upb_MiniTableSub_Message)( - m->UPB_PRIVATE(subs)[f->UPB_PRIVATE(submsg_index)]); - UPB_ASSUME(ret); - return UPB_PRIVATE(_upb_MiniTable_IsEmpty)(ret) ? NULL : ret; +UPB_INLINE void upb_value_setdouble(upb_value* val, double cval) { + memcpy(&val->val, &cval, sizeof(cval)); } -UPB_INLINE const struct upb_MiniTableEnum* UPB_PRIVATE( - _upb_MiniTable_GetSubEnumTable)(const struct upb_MiniTable* m, - const struct upb_MiniTableField* f) { - UPB_ASSERT(UPB_PRIVATE(_upb_MiniTableField_CType)(f) == kUpb_CType_Enum); - return UPB_PRIVATE(_upb_MiniTableSub_Enum)( - m->UPB_PRIVATE(subs)[f->UPB_PRIVATE(submsg_index)]); +UPB_INLINE upb_value upb_value_float(float cval) { + upb_value ret; + upb_value_setfloat(&ret, cval); + return ret; } -UPB_INLINE const struct upb_MiniTableField* UPB_PRIVATE(_upb_MiniTable_MapKey)( - const struct upb_MiniTable* m) { - UPB_ASSERT(UPB_PRIVATE(_upb_MiniTable_FieldCount)(m) == 2); - const struct upb_MiniTableField* f = - UPB_PRIVATE(_upb_MiniTable_GetFieldByIndex)(m, 0); - UPB_ASSERT(UPB_PRIVATE(_upb_MiniTableField_Number)(f) == 1); - return f; +UPB_INLINE upb_value upb_value_double(double cval) { + upb_value ret; + upb_value_setdouble(&ret, cval); + return ret; } -UPB_INLINE const struct upb_MiniTableField* UPB_PRIVATE( - _upb_MiniTable_MapValue)(const struct upb_MiniTable* m) { - UPB_ASSERT(UPB_PRIVATE(_upb_MiniTable_FieldCount)(m) == 2); - const struct upb_MiniTableField* f = - UPB_PRIVATE(_upb_MiniTable_GetFieldByIndex)(m, 1); - UPB_ASSERT(UPB_PRIVATE(_upb_MiniTableField_Number)(f) == 2); - return f; +/* upb_tabkey *****************************************************************/ + +/* Either: + * 1. an actual integer key, or + * 2. a pointer to a string prefixed by its uint32_t length, owned by us. + * + * ...depending on whether this is a string table or an int table. We would + * make this a union of those two types, but C89 doesn't support statically + * initializing a non-first union member. */ +typedef uintptr_t upb_tabkey; + +UPB_INLINE char* upb_tabstr(upb_tabkey key, uint32_t* len) { + char* mem = (char*)key; + if (len) memcpy(len, mem, sizeof(*len)); + return mem + sizeof(*len); } -UPB_INLINE bool UPB_PRIVATE(_upb_MiniTable_MessageFieldIsLinked)( - const struct upb_MiniTable* m, const struct upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTable_GetSubMessageTable)(m, f) != NULL; +UPB_INLINE upb_StringView upb_tabstrview(upb_tabkey key) { + upb_StringView ret; + uint32_t len; + ret.data = upb_tabstr(key, &len); + ret.size = len; + return ret; } -// Computes a bitmask in which the |m->required_count| lowest bits are set, -// except that we skip the lowest bit (because upb never uses hasbit 0). -// -// Sample output: -// RequiredMask(1) => 0b10 (0x2) -// RequiredMask(5) => 0b111110 (0x3e) -UPB_INLINE uint64_t -UPB_PRIVATE(_upb_MiniTable_RequiredMask)(const struct upb_MiniTable* m) { - int n = m->UPB_PRIVATE(required_count); - UPB_ASSERT(0 < n && n <= 63); - return ((1ULL << n) - 1) << 1; +/* upb_tabval *****************************************************************/ + +typedef struct upb_tabval { + uint64_t val; +} upb_tabval; + +#define UPB_TABVALUE_EMPTY_INIT \ + { -1 } + +/* upb_table ******************************************************************/ + +typedef struct _upb_tabent { + upb_tabkey key; + upb_tabval val; + + /* Internal chaining. This is const so we can create static initializers for + * tables. We cast away const sometimes, but *only* when the containing + * upb_table is known to be non-const. This requires a bit of care, but + * the subtlety is confined to table.c. */ + const struct _upb_tabent* next; +} upb_tabent; + +typedef struct { + size_t count; /* Number of entries in the hash part. */ + uint32_t mask; /* Mask to turn hash value -> bucket. */ + uint32_t max_count; /* Max count before we hit our load limit. */ + uint8_t size_lg2; /* Size of the hashtable part is 2^size_lg2 entries. */ + upb_tabent* entries; +} upb_table; + +UPB_INLINE size_t upb_table_size(const upb_table* t) { + return t->size_lg2 ? 1 << t->size_lg2 : 0; } +// Internal-only functions, in .h file only out of necessity. + +UPB_INLINE bool upb_tabent_isempty(const upb_tabent* e) { return e->key == 0; } + +uint32_t _upb_Hash(const void* p, size_t n, uint64_t seed); + #ifdef __cplusplus } /* extern "C" */ #endif -#endif /* UPB_MINI_TABLE_INTERNAL_MESSAGE_H_ */ +#endif /* UPB_HASH_COMMON_H_ */ // Must be last. -typedef struct upb_MiniTable upb_MiniTable; +typedef struct { + upb_table t; +} upb_strtable; #ifdef __cplusplus extern "C" { #endif -UPB_API const upb_MiniTableField* upb_MiniTable_FindFieldByNumber( - const upb_MiniTable* m, uint32_t number); +// Initialize a table. If memory allocation failed, false is returned and +// the table is uninitialized. +bool upb_strtable_init(upb_strtable* table, size_t expected_size, upb_Arena* a); -UPB_API_INLINE const upb_MiniTableField* upb_MiniTable_GetFieldByIndex( - const upb_MiniTable* m, uint32_t index) { - return UPB_PRIVATE(_upb_MiniTable_GetFieldByIndex)(m, index); +// Returns the number of values in the table. +UPB_INLINE size_t upb_strtable_count(const upb_strtable* t) { + return t->t.count; } -UPB_API_INLINE int upb_MiniTable_FieldCount(const upb_MiniTable* m) { - return UPB_PRIVATE(_upb_MiniTable_FieldCount)(m); -} +void upb_strtable_clear(upb_strtable* t); -// Returns the MiniTable for a message field, NULL if the field is unlinked. -UPB_API_INLINE const upb_MiniTable* upb_MiniTable_GetSubMessageTable( - const upb_MiniTable* m, const upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTable_GetSubMessageTable)(m, f); -} +// Inserts the given key into the hashtable with the given value. +// The key must not already exist in the hash table. The key is not required +// to be NULL-terminated, and the table will make an internal copy of the key. +// +// If a table resize was required but memory allocation failed, false is +// returned and the table is unchanged. */ +bool upb_strtable_insert(upb_strtable* t, const char* key, size_t len, + upb_value val, upb_Arena* a); -// Returns the MiniTableEnum for a message field, NULL if the field is unlinked. -UPB_API_INLINE const upb_MiniTableEnum* upb_MiniTable_GetSubEnumTable( - const upb_MiniTable* m, const upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTable_GetSubEnumTable)(m, f); -} +// Looks up key in this table, returning "true" if the key was found. +// If v is non-NULL, copies the value for this key into *v. +bool upb_strtable_lookup2(const upb_strtable* t, const char* key, size_t len, + upb_value* v); -// Returns the MiniTableField for the key of a map. -UPB_API_INLINE const upb_MiniTableField* upb_MiniTable_MapKey( - const upb_MiniTable* m) { - return UPB_PRIVATE(_upb_MiniTable_MapKey)(m); +// For NULL-terminated strings. +UPB_INLINE bool upb_strtable_lookup(const upb_strtable* t, const char* key, + upb_value* v) { + return upb_strtable_lookup2(t, key, strlen(key), v); } -// Returns the MiniTableField for the value of a map. -UPB_API_INLINE const upb_MiniTableField* upb_MiniTable_MapValue( - const upb_MiniTable* m) { - return UPB_PRIVATE(_upb_MiniTable_MapValue)(m); -} +// Removes an item from the table. Returns true if the remove was successful, +// and stores the removed item in *val if non-NULL. +bool upb_strtable_remove2(upb_strtable* t, const char* key, size_t len, + upb_value* val); -// Returns true if this MiniTable field is linked to a MiniTable for the -// sub-message. -UPB_API_INLINE bool upb_MiniTable_MessageFieldIsLinked( - const upb_MiniTable* m, const upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTable_MessageFieldIsLinked)(m, f); +UPB_INLINE bool upb_strtable_remove(upb_strtable* t, const char* key, + upb_value* v) { + return upb_strtable_remove2(t, key, strlen(key), v); } -// If this field is in a oneof, returns the first field in the oneof. -// -// Otherwise returns NULL. -// -// Usage: -// const upb_MiniTableField* field = upb_MiniTable_GetOneof(m, f); -// do { -// .. -// } while (upb_MiniTable_NextOneofField(m, &field); -// -const upb_MiniTableField* upb_MiniTable_GetOneof(const upb_MiniTable* m, - const upb_MiniTableField* f); - -// Iterates to the next field in the oneof. If this is the last field in the -// oneof, returns false. The ordering of fields in the oneof is not -// guaranteed. -// REQUIRES: |f| is the field initialized by upb_MiniTable_GetOneof and updated -// by prior upb_MiniTable_NextOneofField calls. -bool upb_MiniTable_NextOneofField(const upb_MiniTable* m, - const upb_MiniTableField** f); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - +// Exposed for testing only. +bool upb_strtable_resize(upb_strtable* t, size_t size_lg2, upb_Arena* a); -#endif /* UPB_MINI_TABLE_MESSAGE_H_ */ +/* Iteration over strtable: + * + * intptr_t iter = UPB_STRTABLE_BEGIN; + * upb_StringView key; + * upb_value val; + * while (upb_strtable_next2(t, &key, &val, &iter)) { + * // ... + * } + */ -// Must be last. +#define UPB_STRTABLE_BEGIN -1 -typedef struct upb_MiniTableExtension upb_MiniTableExtension; +bool upb_strtable_next2(const upb_strtable* t, upb_StringView* key, + upb_value* val, intptr_t* iter); +void upb_strtable_removeiter(upb_strtable* t, intptr_t* iter); +void upb_strtable_setentryvalue(upb_strtable* t, intptr_t iter, upb_value v); -#ifdef __cplusplus -extern "C" { -#endif +/* DEPRECATED iterators, slated for removal. + * + * Iterators for string tables. We are subject to some kind of unusual + * design constraints: + * + * For high-level languages: + * - we must be able to guarantee that we don't crash or corrupt memory even if + * the program accesses an invalidated iterator. + * + * For C++11 range-based for: + * - iterators must be copyable + * - iterators must be comparable + * - it must be possible to construct an "end" value. + * + * Iteration order is undefined. + * + * Modifying the table invalidates iterators. upb_{str,int}table_done() is + * guaranteed to work even on an invalidated iterator, as long as the table it + * is iterating over has not been freed. Calling next() or accessing data from + * an invalidated iterator yields unspecified elements from the table, but it is + * guaranteed not to crash and to return real table elements (except when done() + * is true). */ +/* upb_strtable_iter **********************************************************/ -UPB_API_INLINE const upb_MiniTableField* upb_MiniTableExtension_AsField( - const upb_MiniTableExtension* e) { - return UPB_PRIVATE(_upb_MiniTableExtension_AsField)(e); -} +/* upb_strtable_iter i; + * upb_strtable_begin(&i, t); + * for(; !upb_strtable_done(&i); upb_strtable_next(&i)) { + * const char *key = upb_strtable_iter_key(&i); + * const upb_value val = upb_strtable_iter_value(&i); + * // ... + * } + */ -UPB_API_INLINE uint32_t -upb_MiniTableExtension_Number(const upb_MiniTableExtension* e) { - return UPB_PRIVATE(_upb_MiniTableExtension_Number)(e); -} +typedef struct { + const upb_strtable* t; + size_t index; +} upb_strtable_iter; -UPB_API_INLINE const upb_MiniTable* upb_MiniTableExtension_GetSubMessage( - const upb_MiniTableExtension* e) { - return UPB_PRIVATE(_upb_MiniTableExtension_GetSubMessage)(e); +UPB_INLINE const upb_tabent* str_tabent(const upb_strtable_iter* i) { + return &i->t->t.entries[i->index]; } -UPB_API_INLINE void upb_MiniTableExtension_SetSubMessage( - upb_MiniTableExtension* e, const upb_MiniTable* m) { - UPB_PRIVATE(_upb_MiniTableExtension_SetSubMessage)(e, m); -} +void upb_strtable_begin(upb_strtable_iter* i, const upb_strtable* t); +void upb_strtable_next(upb_strtable_iter* i); +bool upb_strtable_done(const upb_strtable_iter* i); +upb_StringView upb_strtable_iter_key(const upb_strtable_iter* i); +upb_value upb_strtable_iter_value(const upb_strtable_iter* i); +void upb_strtable_iter_setdone(upb_strtable_iter* i); +bool upb_strtable_iter_isequal(const upb_strtable_iter* i1, + const upb_strtable_iter* i2); #ifdef __cplusplus } /* extern "C" */ #endif -#endif /* UPB_MINI_TABLE_EXTENSION_H_ */ +#endif /* UPB_HASH_STR_TABLE_H_ */ // Must be last. -// The internal representation of an extension is self-describing: it contains -// enough information that we can serialize it to binary format without needing -// to look it up in a upb_ExtensionRegistry. -// -// This representation allocates 16 bytes to data on 64-bit platforms. -// This is rather wasteful for scalars (in the extreme case of bool, -// it wastes 15 bytes). We accept this because we expect messages to be -// the most common extension type. -struct upb_Extension { - const upb_MiniTableExtension* ext; - union { - upb_StringView str; - void* ptr; - char scalar_data[8]; - } data; -}; - -#ifdef __cplusplus -extern "C" { -#endif - -// Adds the given extension data to the given message. -// |ext| is copied into the message instance. -// This logically replaces any previously-added extension with this number. -struct upb_Extension* _upb_Message_GetOrCreateExtension( - struct upb_Message* msg, const upb_MiniTableExtension* ext, - upb_Arena* arena); - -// Returns an array of extensions for this message. -// Note: the array is ordered in reverse relative to the order of creation. -const struct upb_Extension* UPB_PRIVATE(_upb_Message_Getexts)( - const struct upb_Message* msg, size_t* count); - -// Returns an extension for a message with a given mini table, -// or NULL if no extension exists with this mini table. -const struct upb_Extension* _upb_Message_Getext( - const struct upb_Message* msg, const upb_MiniTableExtension* ext); - -#ifdef __cplusplus -} /* extern "C" */ -#endif +typedef enum { + kUpb_MapInsertStatus_Inserted = 0, + kUpb_MapInsertStatus_Replaced = 1, + kUpb_MapInsertStatus_OutOfMemory = 2, +} upb_MapInsertStatus; +// EVERYTHING BELOW THIS LINE IS INTERNAL - DO NOT USE ///////////////////////// -#endif /* UPB_MESSAGE_INTERNAL_EXTENSION_H_ */ +struct upb_Map { + // Size of key and val, based on the map type. + // Strings are represented as '0' because they must be handled specially. + char key_size; + char val_size; -// Must be last. + upb_strtable table; +}; #ifdef __cplusplus extern "C" { #endif -extern const float kUpb_FltInfinity; -extern const double kUpb_Infinity; -extern const double kUpb_NaN; +// Converting between internal table representation and user values. +// +// _upb_map_tokey() and _upb_map_fromkey() are inverses. +// _upb_map_tovalue() and _upb_map_fromvalue() are inverses. +// +// These functions account for the fact that strings are treated differently +// from other types when stored in a map. -/* Internal members of a upb_Message that track unknown fields and/or - * extensions. We can change this without breaking binary compatibility. We put - * these before the user's data. The user's upb_Message* points after the - * upb_Message_Internal. */ +UPB_INLINE upb_StringView _upb_map_tokey(const void* key, size_t size) { + if (size == UPB_MAPTYPE_STRING) { + return *(upb_StringView*)key; + } else { + return upb_StringView_FromDataAndSize((const char*)key, size); + } +} -typedef struct { - /* Total size of this structure, including the data that follows. - * Must be aligned to 8, which is alignof(upb_Extension) */ - uint32_t size; +UPB_INLINE void _upb_map_fromkey(upb_StringView key, void* out, size_t size) { + if (size == UPB_MAPTYPE_STRING) { + memcpy(out, &key, sizeof(key)); + } else { + memcpy(out, key.data, size); + } +} - /* Offsets relative to the beginning of this structure. - * - * Unknown data grows forward from the beginning to unknown_end. - * Extension data grows backward from size to ext_begin. - * When the two meet, we're out of data and have to realloc. - * - * If we imagine that the final member of this struct is: - * char data[size - overhead]; // overhead = - * sizeof(upb_Message_InternalData) - * - * Then we have: - * unknown data: data[0 .. (unknown_end - overhead)] - * extensions data: data[(ext_begin - overhead) .. (size - overhead)] */ - uint32_t unknown_end; - uint32_t ext_begin; - /* Data follows, as if there were an array: - * char data[size - sizeof(upb_Message_InternalData)]; */ -} upb_Message_InternalData; +UPB_INLINE bool _upb_map_tovalue(const void* val, size_t size, + upb_value* msgval, upb_Arena* a) { + if (size == UPB_MAPTYPE_STRING) { + upb_StringView* strp = (upb_StringView*)upb_Arena_Malloc(a, sizeof(*strp)); + if (!strp) return false; + *strp = *(upb_StringView*)val; + *msgval = upb_value_ptr(strp); + } else { + memcpy(msgval, val, size); + } + return true; +} -typedef struct { - union { - upb_Message_InternalData* internal; +UPB_INLINE void _upb_map_fromvalue(upb_value val, void* out, size_t size) { + if (size == UPB_MAPTYPE_STRING) { + const upb_StringView* strp = (const upb_StringView*)upb_value_getptr(val); + memcpy(out, strp, sizeof(upb_StringView)); + } else { + memcpy(out, &val, size); + } +} - // Force 8-byte alignment, since the data members may contain members that - // require 8-byte alignment. - double d; - }; -} upb_Message_Internal; +UPB_INLINE void* _upb_map_next(const struct upb_Map* map, size_t* iter) { + upb_strtable_iter it; + it.t = &map->table; + it.index = *iter; + upb_strtable_next(&it); + *iter = it.index; + if (upb_strtable_done(&it)) return NULL; + return (void*)str_tabent(&it); +} -struct upb_Message { - int unused; // Placeholder cuz Windows won't compile an empty struct. -}; +UPB_INLINE void _upb_Map_Clear(struct upb_Map* map) { + upb_strtable_clear(&map->table); +} -UPB_INLINE size_t upb_msg_sizeof(const upb_MiniTable* m) { - return m->UPB_PRIVATE(size) + sizeof(upb_Message_Internal); +UPB_INLINE bool _upb_Map_Delete(struct upb_Map* map, const void* key, + size_t key_size, upb_value* val) { + upb_StringView k = _upb_map_tokey(key, key_size); + return upb_strtable_remove2(&map->table, k.data, k.size, val); } -// Inline version upb_Message_New(), for internal use. -UPB_INLINE struct upb_Message* _upb_Message_New(const upb_MiniTable* mini_table, - upb_Arena* arena) { - size_t size = upb_msg_sizeof(mini_table); - void* mem = upb_Arena_Malloc(arena, size + sizeof(upb_Message_Internal)); - if (UPB_UNLIKELY(!mem)) return NULL; - struct upb_Message* msg = - UPB_PTR_AT(mem, sizeof(upb_Message_Internal), struct upb_Message); - memset(mem, 0, size); - return msg; +UPB_INLINE bool _upb_Map_Get(const struct upb_Map* map, const void* key, + size_t key_size, void* val, size_t val_size) { + upb_value tabval; + upb_StringView k = _upb_map_tokey(key, key_size); + bool ret = upb_strtable_lookup2(&map->table, k.data, k.size, &tabval); + if (ret && val) { + _upb_map_fromvalue(tabval, val, val_size); + } + return ret; } -UPB_INLINE upb_Message_Internal* upb_Message_Getinternal( - const struct upb_Message* msg) { - ptrdiff_t size = sizeof(upb_Message_Internal); - return (upb_Message_Internal*)((char*)msg - size); +UPB_INLINE upb_MapInsertStatus _upb_Map_Insert(struct upb_Map* map, + const void* key, size_t key_size, + void* val, size_t val_size, + upb_Arena* a) { + upb_StringView strkey = _upb_map_tokey(key, key_size); + upb_value tabval = {0}; + if (!_upb_map_tovalue(val, val_size, &tabval, a)) { + return kUpb_MapInsertStatus_OutOfMemory; + } + + // TODO: add overwrite operation to minimize number of lookups. + bool removed = + upb_strtable_remove2(&map->table, strkey.data, strkey.size, NULL); + if (!upb_strtable_insert(&map->table, strkey.data, strkey.size, tabval, a)) { + return kUpb_MapInsertStatus_OutOfMemory; + } + return removed ? kUpb_MapInsertStatus_Replaced + : kUpb_MapInsertStatus_Inserted; } -UPB_INLINE upb_Message_InternalData* upb_Message_GetInternalData( - const struct upb_Message* msg) { - return upb_Message_Getinternal(msg)->internal; +UPB_INLINE size_t _upb_Map_Size(const struct upb_Map* map) { + return map->table.t.count; } -// Discards the unknown fields for this message only. -void _upb_Message_DiscardUnknown_shallow(struct upb_Message* msg); +// Strings/bytes are special-cased in maps. +extern char _upb_Map_CTypeSizeTable[12]; -// Adds unknown data (serialized protobuf data) to the given message. -// The data is copied into the message instance. -bool UPB_PRIVATE(_upb_Message_AddUnknown)(struct upb_Message* msg, - const char* data, size_t len, - upb_Arena* arena); +UPB_INLINE size_t _upb_Map_CTypeSize(upb_CType ctype) { + return _upb_Map_CTypeSizeTable[ctype]; +} -bool UPB_PRIVATE(_upb_Message_Realloc)(struct upb_Message* msg, size_t need, - upb_Arena* arena); +// Creates a new map on the given arena with this key/value type. +struct upb_Map* _upb_Map_New(upb_Arena* a, size_t key_size, size_t value_size); #ifdef __cplusplus } /* extern "C" */ #endif -#endif /* UPB_MESSAGE_INTERNAL_MESSAGE_H_ */ +#endif /* UPB_MESSAGE_INTERNAL_MAP_H_ */ #ifndef UPB_MINI_TABLE_INTERNAL_TAGGED_PTR_H_ #define UPB_MINI_TABLE_INTERNAL_TAGGED_PTR_H_ @@ -2360,37 +2333,34 @@ bool UPB_PRIVATE(_upb_Message_Realloc)(struct upb_Message* msg, size_t need, // Must be last. -typedef uintptr_t upb_TaggedMessagePtr; - #ifdef __cplusplus extern "C" { #endif // Internal-only because empty messages cannot be created by the user. -UPB_INLINE upb_TaggedMessagePtr +UPB_INLINE uintptr_t UPB_PRIVATE(_upb_TaggedMessagePtr_Pack)(struct upb_Message* ptr, bool empty) { UPB_ASSERT(((uintptr_t)ptr & 1) == 0); return (uintptr_t)ptr | (empty ? 1 : 0); } -UPB_INLINE bool UPB_PRIVATE(_upb_TaggedMessagePtr_IsEmpty)( - upb_TaggedMessagePtr ptr) { +UPB_INLINE bool UPB_PRIVATE(_upb_TaggedMessagePtr_IsEmpty)(uintptr_t ptr) { return ptr & 1; } UPB_INLINE struct upb_Message* UPB_PRIVATE(_upb_TaggedMessagePtr_GetMessage)( - upb_TaggedMessagePtr ptr) { + uintptr_t ptr) { return (struct upb_Message*)(ptr & ~(uintptr_t)1); } UPB_INLINE struct upb_Message* UPB_PRIVATE( - _upb_TaggedMessagePtr_GetNonEmptyMessage)(upb_TaggedMessagePtr ptr) { + _upb_TaggedMessagePtr_GetNonEmptyMessage)(uintptr_t ptr) { UPB_ASSERT(!UPB_PRIVATE(_upb_TaggedMessagePtr_IsEmpty)(ptr)); return UPB_PRIVATE(_upb_TaggedMessagePtr_GetMessage)(ptr); } UPB_INLINE struct upb_Message* UPB_PRIVATE( - _upb_TaggedMessagePtr_GetEmptyMessage)(upb_TaggedMessagePtr ptr) { + _upb_TaggedMessagePtr_GetEmptyMessage)(uintptr_t ptr) { UPB_ASSERT(UPB_PRIVATE(_upb_TaggedMessagePtr_IsEmpty)(ptr)); return UPB_PRIVATE(_upb_TaggedMessagePtr_GetMessage)(ptr); } @@ -2402,100 +2372,6 @@ UPB_INLINE struct upb_Message* UPB_PRIVATE( #endif /* UPB_MINI_TABLE_INTERNAL_TAGGED_PTR_H_ */ -typedef union { - bool bool_val; - float float_val; - double double_val; - int32_t int32_val; - int64_t int64_val; - uint32_t uint32_val; - uint64_t uint64_val; - const struct upb_Array* array_val; - const struct upb_Map* map_val; - const struct upb_Message* msg_val; - upb_StringView str_val; - - // EXPERIMENTAL: A tagged upb_Message*. Users must use this instead of - // msg_val if unlinked sub-messages may possibly be in use. See the - // documentation in kUpb_DecodeOption_ExperimentalAllowUnlinked for more - // information. - upb_TaggedMessagePtr tagged_msg_val; -} upb_MessageValue; - -typedef union { - struct upb_Array* array; - struct upb_Map* map; - struct upb_Message* msg; -} upb_MutableMessageValue; - -#endif /* UPB_MESSAGE_VALUE_H_ */ - -// Must be last. - -typedef struct upb_Array upb_Array; - -#ifdef __cplusplus -extern "C" { -#endif - -// Creates a new array on the given arena that holds elements of this type. -UPB_API upb_Array* upb_Array_New(upb_Arena* a, upb_CType type); - -// Returns the number of elements in the array. -UPB_API size_t upb_Array_Size(const upb_Array* arr); - -// Returns the given element, which must be within the array's current size. -UPB_API upb_MessageValue upb_Array_Get(const upb_Array* arr, size_t i); - -// Sets the given element, which must be within the array's current size. -UPB_API void upb_Array_Set(upb_Array* arr, size_t i, upb_MessageValue val); - -// Appends an element to the array. Returns false on allocation failure. -UPB_API bool upb_Array_Append(upb_Array* array, upb_MessageValue val, - upb_Arena* arena); - -// Moves elements within the array using memmove(). -// Like memmove(), the source and destination elements may be overlapping. -UPB_API void upb_Array_Move(upb_Array* array, size_t dst_idx, size_t src_idx, - size_t count); - -// Inserts one or more empty elements into the array. -// Existing elements are shifted right. -// The new elements have undefined state and must be set with `upb_Array_Set()`. -// REQUIRES: `i <= upb_Array_Size(arr)` -UPB_API bool upb_Array_Insert(upb_Array* array, size_t i, size_t count, - upb_Arena* arena); - -// Deletes one or more elements from the array. -// Existing elements are shifted left. -// REQUIRES: `i + count <= upb_Array_Size(arr)` -UPB_API void upb_Array_Delete(upb_Array* array, size_t i, size_t count); - -// Changes the size of a vector. New elements are initialized to NULL/0. -// Returns false on allocation failure. -UPB_API bool upb_Array_Resize(upb_Array* array, size_t size, upb_Arena* arena); - -// Returns pointer to array data. -UPB_API const void* upb_Array_DataPtr(const upb_Array* arr); - -// Returns mutable pointer to array data. -UPB_API void* upb_Array_MutableDataPtr(upb_Array* arr); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - - -#endif /* UPB_MESSAGE_ARRAY_H_ */ - -#ifndef UPB_MESSAGE_INTERNAL_ACCESSORS_H_ -#define UPB_MESSAGE_INTERNAL_ACCESSORS_H_ - -#include -#include -#include - - // Must be last. #if defined(__GNUC__) && !defined(__clang__) @@ -2784,8 +2660,8 @@ UPB_INLINE void _upb_Message_AssertMapIsUntagged( UPB_UNUSED(msg); UPB_PRIVATE(_upb_MiniTableField_CheckIsMap)(field); #ifndef NDEBUG - upb_TaggedMessagePtr default_val = 0; - upb_TaggedMessagePtr tagged; + uintptr_t default_val = 0; + uintptr_t tagged; _upb_Message_GetNonExtensionField(msg, field, &default_val, &tagged); UPB_ASSERT(!UPB_PRIVATE(_upb_TaggedMessagePtr_IsEmpty)(tagged)); #endif @@ -2819,6 +2695,127 @@ UPB_INLINE struct upb_Map* _upb_Message_GetOrCreateMutableMap( #endif // UPB_MESSAGE_INTERNAL_ACCESSORS_H_ +#ifndef UPB_MESSAGE_INTERNAL_ARRAY_H_ +#define UPB_MESSAGE_INTERNAL_ARRAY_H_ + +#include + + +// Must be last. + +#define _UPB_ARRAY_MASK_IMM 0x4 // Frozen/immutable bit. +#define _UPB_ARRAY_MASK_LG2 0x3 // Encoded elem size. +#define _UPB_ARRAY_MASK_ALL (_UPB_ARRAY_MASK_IMM | _UPB_ARRAY_MASK_LG2) + +#ifdef __cplusplus +extern "C" { +#endif + +// LINT.IfChange(struct_definition) +// Our internal representation for repeated fields. +struct upb_Array { + // This is a tagged pointer. Bits #0 and #1 encode the elem size as follows: + // 0 maps to elem size 1 + // 1 maps to elem size 4 + // 2 maps to elem size 8 + // 3 maps to elem size 16 + // + // Bit #2 contains the frozen/immutable flag (currently unimplemented). + uintptr_t data; + + size_t UPB_ONLYBITS(size); // The number of elements in the array. + size_t UPB_PRIVATE(capacity); // Allocated storage. Measured in elements. +}; + +UPB_INLINE void UPB_PRIVATE(_upb_Array_SetTaggedPtr)(struct upb_Array* array, + void* data, size_t lg2) { + UPB_ASSERT(lg2 != 1); + UPB_ASSERT(lg2 <= 4); + const size_t bits = lg2 - (lg2 != 0); + array->data = (uintptr_t)data | bits; +} + +UPB_INLINE size_t +UPB_PRIVATE(_upb_Array_ElemSizeLg2)(const struct upb_Array* array) { + const size_t bits = array->data & _UPB_ARRAY_MASK_LG2; + const size_t lg2 = bits + (bits != 0); + return lg2; +} + +UPB_INLINE const void* _upb_array_constptr(const struct upb_Array* array) { + UPB_PRIVATE(_upb_Array_ElemSizeLg2)(array); // Check assertions. + return (void*)(array->data & ~(uintptr_t)_UPB_ARRAY_MASK_ALL); +} + +UPB_INLINE void* _upb_array_ptr(struct upb_Array* array) { + return (void*)_upb_array_constptr(array); +} + +UPB_INLINE struct upb_Array* UPB_PRIVATE(_upb_Array_New)(upb_Arena* arena, + size_t init_capacity, + int elem_size_lg2) { + UPB_ASSERT(elem_size_lg2 != 1); + UPB_ASSERT(elem_size_lg2 <= 4); + const size_t array_size = + UPB_ALIGN_UP(sizeof(struct upb_Array), UPB_MALLOC_ALIGN); + const size_t bytes = array_size + (init_capacity << elem_size_lg2); + struct upb_Array* array = (struct upb_Array*)upb_Arena_Malloc(arena, bytes); + if (!array) return NULL; + UPB_PRIVATE(_upb_Array_SetTaggedPtr) + (array, UPB_PTR_AT(array, array_size, void), elem_size_lg2); + array->UPB_ONLYBITS(size) = 0; + array->UPB_PRIVATE(capacity) = init_capacity; + return array; +} + +// Resizes the capacity of the array to be at least min_size. +bool UPB_PRIVATE(_upb_Array_Realloc)(struct upb_Array* array, size_t min_size, + upb_Arena* arena); + +UPB_INLINE bool UPB_PRIVATE(_upb_Array_Reserve)(struct upb_Array* array, + size_t size, upb_Arena* arena) { + if (array->UPB_PRIVATE(capacity) < size) + return UPB_PRIVATE(_upb_Array_Realloc)(array, size, arena); + return true; +} + +// Resize without initializing new elements. +UPB_INLINE bool _upb_Array_ResizeUninitialized(struct upb_Array* array, + size_t size, upb_Arena* arena) { + UPB_ASSERT(size <= array->UPB_ONLYBITS(size) || + arena); // Allow NULL arena when shrinking. + if (!UPB_PRIVATE(_upb_Array_Reserve)(array, size, arena)) return false; + array->UPB_ONLYBITS(size) = size; + return true; +} + +// This function is intended for situations where elem_size is compile-time +// constant or a known expression of the form (1 << lg2), so that the expression +// i*elem_size does not result in an actual multiplication. +UPB_INLINE void UPB_PRIVATE(_upb_Array_Set)(struct upb_Array* array, size_t i, + const void* data, + size_t elem_size) { + UPB_ASSERT(i < array->UPB_ONLYBITS(size)); + UPB_ASSERT(elem_size == 1U << UPB_PRIVATE(_upb_Array_ElemSizeLg2)(array)); + char* arr_data = (char*)_upb_array_ptr(array); + memcpy(arr_data + (i * elem_size), data, elem_size); +} + +// LINT.ThenChange( +// GoogleInternalName1, +//) + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#undef _UPB_ARRAY_MASK_IMM +#undef _UPB_ARRAY_MASK_LG2 +#undef _UPB_ARRAY_MASK_ALL + + +#endif /* UPB_MESSAGE_INTERNAL_ARRAY_H_ */ + #ifndef UPB_MESSAGE_MAP_H_ #define UPB_MESSAGE_MAP_H_ diff --git a/ruby/ext/google/protobuf_c/ruby-upb.h b/ruby/ext/google/protobuf_c/ruby-upb.h index 4e7f0a31c9fdd..22d0fcc807ff0 100755 --- a/ruby/ext/google/protobuf_c/ruby-upb.h +++ b/ruby/ext/google/protobuf_c/ruby-upb.h @@ -827,667 +827,594 @@ UPB_API_INLINE void upb_Arena_ShrinkLast(upb_Arena* a, void* ptr, #include -#ifndef UPB_MESSAGE_INTERNAL_ARRAY_H_ -#define UPB_MESSAGE_INTERNAL_ARRAY_H_ +typedef union { + bool bool_val; + float float_val; + double double_val; + int32_t int32_val; + int64_t int64_val; + uint32_t uint32_val; + uint64_t uint64_val; + const struct upb_Array* array_val; + const struct upb_Map* map_val; + const struct upb_Message* msg_val; + upb_StringView str_val; -#include + // EXPERIMENTAL: A tagged upb_Message*. Users must use this instead of + // msg_val if unlinked sub-messages may possibly be in use. See the + // documentation in kUpb_DecodeOption_ExperimentalAllowUnlinked for more + // information. + uintptr_t tagged_msg_val; // upb_TaggedMessagePtr +} upb_MessageValue; + +typedef union { + struct upb_Array* array; + struct upb_Map* map; + struct upb_Message* msg; +} upb_MutableMessageValue; +#endif /* UPB_MESSAGE_VALUE_H_ */ // Must be last. -#define _UPB_ARRAY_MASK_IMM 0x4 // Frozen/immutable bit. -#define _UPB_ARRAY_MASK_LG2 0x3 // Encoded elem size. -#define _UPB_ARRAY_MASK_ALL (_UPB_ARRAY_MASK_IMM | _UPB_ARRAY_MASK_LG2) +typedef struct upb_Array upb_Array; #ifdef __cplusplus extern "C" { #endif -// LINT.IfChange(struct_definition) -// Our internal representation for repeated fields. -struct upb_Array { - // This is a tagged pointer. Bits #0 and #1 encode the elem size as follows: - // 0 maps to elem size 1 - // 1 maps to elem size 4 - // 2 maps to elem size 8 - // 3 maps to elem size 16 - // - // Bit #2 contains the frozen/immutable flag (currently unimplemented). - uintptr_t data; - - size_t UPB_ONLYBITS(size); // The number of elements in the array. - size_t UPB_PRIVATE(capacity); // Allocated storage. Measured in elements. -}; +// Creates a new array on the given arena that holds elements of this type. +UPB_API upb_Array* upb_Array_New(upb_Arena* a, upb_CType type); -UPB_INLINE void UPB_PRIVATE(_upb_Array_SetTaggedPtr)(struct upb_Array* array, - void* data, size_t lg2) { - UPB_ASSERT(lg2 != 1); - UPB_ASSERT(lg2 <= 4); - const size_t bits = lg2 - (lg2 != 0); - array->data = (uintptr_t)data | bits; -} +// Returns the number of elements in the array. +UPB_API size_t upb_Array_Size(const upb_Array* arr); -UPB_INLINE size_t -UPB_PRIVATE(_upb_Array_ElemSizeLg2)(const struct upb_Array* array) { - const size_t bits = array->data & _UPB_ARRAY_MASK_LG2; - const size_t lg2 = bits + (bits != 0); - return lg2; -} +// Returns the given element, which must be within the array's current size. +UPB_API upb_MessageValue upb_Array_Get(const upb_Array* arr, size_t i); -UPB_INLINE const void* _upb_array_constptr(const struct upb_Array* array) { - UPB_PRIVATE(_upb_Array_ElemSizeLg2)(array); // Check assertions. - return (void*)(array->data & ~(uintptr_t)_UPB_ARRAY_MASK_ALL); -} +// Sets the given element, which must be within the array's current size. +UPB_API void upb_Array_Set(upb_Array* arr, size_t i, upb_MessageValue val); -UPB_INLINE void* _upb_array_ptr(struct upb_Array* array) { - return (void*)_upb_array_constptr(array); -} +// Appends an element to the array. Returns false on allocation failure. +UPB_API bool upb_Array_Append(upb_Array* array, upb_MessageValue val, + upb_Arena* arena); -UPB_INLINE struct upb_Array* UPB_PRIVATE(_upb_Array_New)(upb_Arena* arena, - size_t init_capacity, - int elem_size_lg2) { - UPB_ASSERT(elem_size_lg2 != 1); - UPB_ASSERT(elem_size_lg2 <= 4); - const size_t array_size = - UPB_ALIGN_UP(sizeof(struct upb_Array), UPB_MALLOC_ALIGN); - const size_t bytes = array_size + (init_capacity << elem_size_lg2); - struct upb_Array* array = (struct upb_Array*)upb_Arena_Malloc(arena, bytes); - if (!array) return NULL; - UPB_PRIVATE(_upb_Array_SetTaggedPtr) - (array, UPB_PTR_AT(array, array_size, void), elem_size_lg2); - array->UPB_ONLYBITS(size) = 0; - array->UPB_PRIVATE(capacity) = init_capacity; - return array; -} +// Moves elements within the array using memmove(). +// Like memmove(), the source and destination elements may be overlapping. +UPB_API void upb_Array_Move(upb_Array* array, size_t dst_idx, size_t src_idx, + size_t count); -// Resizes the capacity of the array to be at least min_size. -bool UPB_PRIVATE(_upb_Array_Realloc)(struct upb_Array* array, size_t min_size, - upb_Arena* arena); +// Inserts one or more empty elements into the array. +// Existing elements are shifted right. +// The new elements have undefined state and must be set with `upb_Array_Set()`. +// REQUIRES: `i <= upb_Array_Size(arr)` +UPB_API bool upb_Array_Insert(upb_Array* array, size_t i, size_t count, + upb_Arena* arena); -UPB_INLINE bool UPB_PRIVATE(_upb_Array_Reserve)(struct upb_Array* array, - size_t size, upb_Arena* arena) { - if (array->UPB_PRIVATE(capacity) < size) - return UPB_PRIVATE(_upb_Array_Realloc)(array, size, arena); - return true; -} +// Deletes one or more elements from the array. +// Existing elements are shifted left. +// REQUIRES: `i + count <= upb_Array_Size(arr)` +UPB_API void upb_Array_Delete(upb_Array* array, size_t i, size_t count); -// Resize without initializing new elements. -UPB_INLINE bool _upb_Array_ResizeUninitialized(struct upb_Array* array, - size_t size, upb_Arena* arena) { - UPB_ASSERT(size <= array->UPB_ONLYBITS(size) || - arena); // Allow NULL arena when shrinking. - if (!UPB_PRIVATE(_upb_Array_Reserve)(array, size, arena)) return false; - array->UPB_ONLYBITS(size) = size; - return true; -} +// Changes the size of a vector. New elements are initialized to NULL/0. +// Returns false on allocation failure. +UPB_API bool upb_Array_Resize(upb_Array* array, size_t size, upb_Arena* arena); -// This function is intended for situations where elem_size is compile-time -// constant or a known expression of the form (1 << lg2), so that the expression -// i*elem_size does not result in an actual multiplication. -UPB_INLINE void UPB_PRIVATE(_upb_Array_Set)(struct upb_Array* array, size_t i, - const void* data, - size_t elem_size) { - UPB_ASSERT(i < array->UPB_ONLYBITS(size)); - UPB_ASSERT(elem_size == 1U << UPB_PRIVATE(_upb_Array_ElemSizeLg2)(array)); - char* arr_data = (char*)_upb_array_ptr(array); - memcpy(arr_data + (i * elem_size), data, elem_size); -} +// Returns pointer to array data. +UPB_API const void* upb_Array_DataPtr(const upb_Array* arr); -// LINT.ThenChange( -// GoogleInternalName1, -//) +// Returns mutable pointer to array data. +UPB_API void* upb_Array_MutableDataPtr(upb_Array* arr); #ifdef __cplusplus } /* extern "C" */ #endif -#undef _UPB_ARRAY_MASK_IMM -#undef _UPB_ARRAY_MASK_LG2 -#undef _UPB_ARRAY_MASK_ALL - -#endif /* UPB_MESSAGE_INTERNAL_ARRAY_H_ */ +#endif /* UPB_MESSAGE_ARRAY_H_ */ -#ifndef UPB_MESSAGE_INTERNAL_MAP_H_ -#define UPB_MESSAGE_INTERNAL_MAP_H_ +#ifndef UPB_MESSAGE_INTERNAL_ACCESSORS_H_ +#define UPB_MESSAGE_INTERNAL_ACCESSORS_H_ #include +#include #include -#ifndef UPB_HASH_STR_TABLE_H_ -#define UPB_HASH_STR_TABLE_H_ +#ifndef UPB_MESSAGE_INTERNAL_EXTENSION_H_ +#define UPB_MESSAGE_INTERNAL_EXTENSION_H_ /* - * upb_table - * - * This header is INTERNAL-ONLY! Its interfaces are not public or stable! - * This file defines very fast int->upb_value (inttable) and string->upb_value - * (strtable) hash tables. - * - * The table uses chained scatter with Brent's variation (inspired by the Lua - * implementation of hash tables). The hash function for strings is Austin - * Appleby's "MurmurHash." - * - * The inttable uses uintptr_t as its key, which guarantees it can be used to - * store pointers or integers of at least 32 bits (upb isn't really useful on - * systems where sizeof(void*) < 4). - * - * The table must be homogeneous (all values of the same type). In debug - * mode, we check this on insert and lookup. - */ +** Our memory representation for parsing tables and messages themselves. +** Functions in this file are used by generated code and possibly reflection. +** +** The definitions in this file are internal to upb. +**/ -#ifndef UPB_HASH_COMMON_H_ -#define UPB_HASH_COMMON_H_ +#ifndef UPB_MESSAGE_INTERNAL_MESSAGE_H_ +#define UPB_MESSAGE_INTERNAL_MESSAGE_H_ +#include #include -// Must be last. - -#ifdef __cplusplus -extern "C" { -#endif +#ifndef UPB_MINI_TABLE_MESSAGE_H_ +#define UPB_MINI_TABLE_MESSAGE_H_ -/* upb_value ******************************************************************/ -typedef struct { - uint64_t val; -} upb_value; +#ifndef UPB_MINI_TABLE_ENUM_H_ +#define UPB_MINI_TABLE_ENUM_H_ -UPB_INLINE void _upb_value_setval(upb_value* v, uint64_t val) { v->val = val; } +#include -/* For each value ctype, define the following set of functions: - * - * // Get/set an int32 from a upb_value. - * int32_t upb_value_getint32(upb_value val); - * void upb_value_setint32(upb_value *val, int32_t cval); - * - * // Construct a new upb_value from an int32. - * upb_value upb_value_int32(int32_t val); */ -#define FUNCS(name, membername, type_t, converter) \ - UPB_INLINE void upb_value_set##name(upb_value* val, type_t cval) { \ - val->val = (converter)cval; \ - } \ - UPB_INLINE upb_value upb_value_##name(type_t val) { \ - upb_value ret; \ - upb_value_set##name(&ret, val); \ - return ret; \ - } \ - UPB_INLINE type_t upb_value_get##name(upb_value val) { \ - return (type_t)(converter)val.val; \ - } -FUNCS(int32, int32, int32_t, int32_t) -FUNCS(int64, int64, int64_t, int64_t) -FUNCS(uint32, uint32, uint32_t, uint32_t) -FUNCS(uint64, uint64, uint64_t, uint64_t) -FUNCS(bool, _bool, bool, bool) -FUNCS(cstr, cstr, char*, uintptr_t) -FUNCS(uintptr, uptr, uintptr_t, uintptr_t) -FUNCS(ptr, ptr, void*, uintptr_t) -FUNCS(constptr, constptr, const void*, uintptr_t) +#ifndef UPB_MINI_TABLE_INTERNAL_ENUM_H_ +#define UPB_MINI_TABLE_INTERNAL_ENUM_H_ -#undef FUNCS +#include -UPB_INLINE void upb_value_setfloat(upb_value* val, float cval) { - memcpy(&val->val, &cval, sizeof(cval)); -} +// Must be last. -UPB_INLINE void upb_value_setdouble(upb_value* val, double cval) { - memcpy(&val->val, &cval, sizeof(cval)); -} +struct upb_MiniTableEnum { + uint32_t UPB_PRIVATE(mask_limit); // Highest that can be tested with mask. + uint32_t UPB_PRIVATE(value_count); // Number of values after the bitfield. + uint32_t UPB_PRIVATE(data)[]; // Bitmask + enumerated values follow. +}; -UPB_INLINE upb_value upb_value_float(float cval) { - upb_value ret; - upb_value_setfloat(&ret, cval); - return ret; -} +#ifdef __cplusplus +extern "C" { +#endif -UPB_INLINE upb_value upb_value_double(double cval) { - upb_value ret; - upb_value_setdouble(&ret, cval); - return ret; +UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableEnum_CheckValue)( + const struct upb_MiniTableEnum* e, uint32_t val) { + if (UPB_LIKELY(val < 64)) { + const uint64_t mask = + e->UPB_PRIVATE(data)[0] | ((uint64_t)e->UPB_PRIVATE(data)[1] << 32); + const uint64_t bit = 1ULL << val; + return (mask & bit) != 0; + } + if (UPB_LIKELY(val < e->UPB_PRIVATE(mask_limit))) { + const uint32_t mask = e->UPB_PRIVATE(data)[val / 32]; + const uint32_t bit = 1ULL << (val % 32); + return (mask & bit) != 0; + } + + // OPT: binary search long lists? + const uint32_t* start = + &e->UPB_PRIVATE(data)[e->UPB_PRIVATE(mask_limit) / 32]; + const uint32_t* limit = &e->UPB_PRIVATE( + data)[e->UPB_PRIVATE(mask_limit) / 32 + e->UPB_PRIVATE(value_count)]; + for (const uint32_t* p = start; p < limit; p++) { + if (*p == val) return true; + } + return false; } -/* upb_tabkey *****************************************************************/ +#ifdef __cplusplus +} /* extern "C" */ +#endif -/* Either: - * 1. an actual integer key, or - * 2. a pointer to a string prefixed by its uint32_t length, owned by us. - * - * ...depending on whether this is a string table or an int table. We would - * make this a union of those two types, but C89 doesn't support statically - * initializing a non-first union member. */ -typedef uintptr_t upb_tabkey; -UPB_INLINE char* upb_tabstr(upb_tabkey key, uint32_t* len) { - char* mem = (char*)key; - if (len) memcpy(len, mem, sizeof(*len)); - return mem + sizeof(*len); -} +#endif /* UPB_MINI_TABLE_INTERNAL_ENUM_H_ */ -UPB_INLINE upb_StringView upb_tabstrview(upb_tabkey key) { - upb_StringView ret; - uint32_t len; - ret.data = upb_tabstr(key, &len); - ret.size = len; - return ret; -} +// Must be last -/* upb_tabval *****************************************************************/ +typedef struct upb_MiniTableEnum upb_MiniTableEnum; -typedef struct upb_tabval { - uint64_t val; -} upb_tabval; +#ifdef __cplusplus +extern "C" { +#endif -#define UPB_TABVALUE_EMPTY_INIT \ - { -1 } +// Validates enum value against range defined by enum mini table. +UPB_INLINE bool upb_MiniTableEnum_CheckValue(const upb_MiniTableEnum* e, + uint32_t val) { + return UPB_PRIVATE(_upb_MiniTableEnum_CheckValue)(e, val); +} -/* upb_table ******************************************************************/ +#ifdef __cplusplus +} /* extern "C" */ +#endif -typedef struct _upb_tabent { - upb_tabkey key; - upb_tabval val; - /* Internal chaining. This is const so we can create static initializers for - * tables. We cast away const sometimes, but *only* when the containing - * upb_table is known to be non-const. This requires a bit of care, but - * the subtlety is confined to table.c. */ - const struct _upb_tabent* next; -} upb_tabent; +#endif /* UPB_MINI_TABLE_ENUM_H_ */ -typedef struct { - size_t count; /* Number of entries in the hash part. */ - uint32_t mask; /* Mask to turn hash value -> bucket. */ - uint32_t max_count; /* Max count before we hit our load limit. */ - uint8_t size_lg2; /* Size of the hashtable part is 2^size_lg2 entries. */ - upb_tabent* entries; -} upb_table; +#ifndef UPB_MINI_TABLE_FIELD_H_ +#define UPB_MINI_TABLE_FIELD_H_ -UPB_INLINE size_t upb_table_size(const upb_table* t) { - return t->size_lg2 ? 1 << t->size_lg2 : 0; -} +#include -// Internal-only functions, in .h file only out of necessity. -UPB_INLINE bool upb_tabent_isempty(const upb_tabent* e) { return e->key == 0; } +#ifndef UPB_MINI_TABLE_INTERNAL_FIELD_H_ +#define UPB_MINI_TABLE_INTERNAL_FIELD_H_ -uint32_t _upb_Hash(const void* p, size_t n, uint64_t seed); +#include +#include -#ifdef __cplusplus -} /* extern "C" */ -#endif +#ifndef UPB_MINI_TABLE_INTERNAL_SIZE_LOG2_H_ +#define UPB_MINI_TABLE_INTERNAL_SIZE_LOG2_H_ -#endif /* UPB_HASH_COMMON_H_ */ +#include +#include -// Must be last. -typedef struct { - upb_table t; -} upb_strtable; +// Must be last. #ifdef __cplusplus extern "C" { #endif -// Initialize a table. If memory allocation failed, false is returned and -// the table is uninitialized. -bool upb_strtable_init(upb_strtable* table, size_t expected_size, upb_Arena* a); +// Return the log2 of the storage size in bytes for a upb_CType +UPB_INLINE int UPB_PRIVATE(_upb_CType_SizeLg2)(upb_CType c_type) { + static const int8_t size[] = { + 0, // kUpb_CType_Bool + 2, // kUpb_CType_Float + 2, // kUpb_CType_Int32 + 2, // kUpb_CType_UInt32 + 2, // kUpb_CType_Enum + UPB_SIZE(2, 3), // kUpb_CType_Message + 3, // kUpb_CType_Double + 3, // kUpb_CType_Int64 + 3, // kUpb_CType_UInt64 + UPB_SIZE(3, 4), // kUpb_CType_String + UPB_SIZE(3, 4), // kUpb_CType_Bytes + }; -// Returns the number of values in the table. -UPB_INLINE size_t upb_strtable_count(const upb_strtable* t) { - return t->t.count; + // -1 here because the enum is one-based but the table is zero-based. + return size[c_type - 1]; } -void upb_strtable_clear(upb_strtable* t); - -// Inserts the given key into the hashtable with the given value. -// The key must not already exist in the hash table. The key is not required -// to be NULL-terminated, and the table will make an internal copy of the key. -// -// If a table resize was required but memory allocation failed, false is -// returned and the table is unchanged. */ -bool upb_strtable_insert(upb_strtable* t, const char* key, size_t len, - upb_value val, upb_Arena* a); - -// Looks up key in this table, returning "true" if the key was found. -// If v is non-NULL, copies the value for this key into *v. -bool upb_strtable_lookup2(const upb_strtable* t, const char* key, size_t len, - upb_value* v); +// Return the log2 of the storage size in bytes for a upb_FieldType +UPB_INLINE int UPB_PRIVATE(_upb_FieldType_SizeLg2)(upb_FieldType field_type) { + static const int8_t size[] = { + 3, // kUpb_FieldType_Double + 2, // kUpb_FieldType_Float + 3, // kUpb_FieldType_Int64 + 3, // kUpb_FieldType_UInt64 + 2, // kUpb_FieldType_Int32 + 3, // kUpb_FieldType_Fixed64 + 2, // kUpb_FieldType_Fixed32 + 0, // kUpb_FieldType_Bool + UPB_SIZE(3, 4), // kUpb_FieldType_String + UPB_SIZE(2, 3), // kUpb_FieldType_Group + UPB_SIZE(2, 3), // kUpb_FieldType_Message + UPB_SIZE(3, 4), // kUpb_FieldType_Bytes + 2, // kUpb_FieldType_UInt32 + 2, // kUpb_FieldType_Enum + 2, // kUpb_FieldType_SFixed32 + 3, // kUpb_FieldType_SFixed64 + 2, // kUpb_FieldType_SInt32 + 3, // kUpb_FieldType_SInt64 + }; -// For NULL-terminated strings. -UPB_INLINE bool upb_strtable_lookup(const upb_strtable* t, const char* key, - upb_value* v) { - return upb_strtable_lookup2(t, key, strlen(key), v); + // -1 here because the enum is one-based but the table is zero-based. + return size[field_type - 1]; } -// Removes an item from the table. Returns true if the remove was successful, -// and stores the removed item in *val if non-NULL. -bool upb_strtable_remove2(upb_strtable* t, const char* key, size_t len, - upb_value* val); +#ifdef __cplusplus +} /* extern "C" */ +#endif -UPB_INLINE bool upb_strtable_remove(upb_strtable* t, const char* key, - upb_value* v) { - return upb_strtable_remove2(t, key, strlen(key), v); -} -// Exposed for testing only. -bool upb_strtable_resize(upb_strtable* t, size_t size_lg2, upb_Arena* a); +#endif /* UPB_MINI_TABLE_INTERNAL_SIZE_LOG2_H_ */ -/* Iteration over strtable: - * - * intptr_t iter = UPB_STRTABLE_BEGIN; - * upb_StringView key; - * upb_value val; - * while (upb_strtable_next2(t, &key, &val, &iter)) { - * // ... - * } - */ +// Must be last. -#define UPB_STRTABLE_BEGIN -1 +// LINT.IfChange(struct_definition) +struct upb_MiniTableField { + uint32_t UPB_ONLYBITS(number); + uint16_t UPB_ONLYBITS(offset); + int16_t presence; // If >0, hasbit_index. If <0, ~oneof_index -bool upb_strtable_next2(const upb_strtable* t, upb_StringView* key, - upb_value* val, intptr_t* iter); -void upb_strtable_removeiter(upb_strtable* t, intptr_t* iter); -void upb_strtable_setentryvalue(upb_strtable* t, intptr_t iter, upb_value v); + // Indexes into `upb_MiniTable.subs` + // Will be set to `kUpb_NoSub` if `descriptortype` != MESSAGE/GROUP/ENUM + uint16_t UPB_PRIVATE(submsg_index); -/* DEPRECATED iterators, slated for removal. - * - * Iterators for string tables. We are subject to some kind of unusual - * design constraints: - * - * For high-level languages: - * - we must be able to guarantee that we don't crash or corrupt memory even if - * the program accesses an invalidated iterator. - * - * For C++11 range-based for: - * - iterators must be copyable - * - iterators must be comparable - * - it must be possible to construct an "end" value. - * - * Iteration order is undefined. - * - * Modifying the table invalidates iterators. upb_{str,int}table_done() is - * guaranteed to work even on an invalidated iterator, as long as the table it - * is iterating over has not been freed. Calling next() or accessing data from - * an invalidated iterator yields unspecified elements from the table, but it is - * guaranteed not to crash and to return real table elements (except when done() - * is true). */ -/* upb_strtable_iter **********************************************************/ + uint8_t UPB_PRIVATE(descriptortype); -/* upb_strtable_iter i; - * upb_strtable_begin(&i, t); - * for(; !upb_strtable_done(&i); upb_strtable_next(&i)) { - * const char *key = upb_strtable_iter_key(&i); - * const upb_value val = upb_strtable_iter_value(&i); - * // ... - * } - */ + // upb_FieldMode | upb_LabelFlags | (upb_FieldRep << kUpb_FieldRep_Shift) + uint8_t UPB_ONLYBITS(mode); +}; -typedef struct { - const upb_strtable* t; - size_t index; -} upb_strtable_iter; +#define kUpb_NoSub ((uint16_t)-1) -UPB_INLINE const upb_tabent* str_tabent(const upb_strtable_iter* i) { - return &i->t->t.entries[i->index]; -} +typedef enum { + kUpb_FieldMode_Map = 0, + kUpb_FieldMode_Array = 1, + kUpb_FieldMode_Scalar = 2, +} upb_FieldMode; -void upb_strtable_begin(upb_strtable_iter* i, const upb_strtable* t); -void upb_strtable_next(upb_strtable_iter* i); -bool upb_strtable_done(const upb_strtable_iter* i); -upb_StringView upb_strtable_iter_key(const upb_strtable_iter* i); -upb_value upb_strtable_iter_value(const upb_strtable_iter* i); -void upb_strtable_iter_setdone(upb_strtable_iter* i); -bool upb_strtable_iter_isequal(const upb_strtable_iter* i1, - const upb_strtable_iter* i2); +// Mask to isolate the upb_FieldMode from field.mode. +#define kUpb_FieldMode_Mask 3 + +// Extra flags on the mode field. +typedef enum { + kUpb_LabelFlags_IsPacked = 4, + kUpb_LabelFlags_IsExtension = 8, + // Indicates that this descriptor type is an "alternate type": + // - for Int32, this indicates that the actual type is Enum (but was + // rewritten to Int32 because it is an open enum that requires no check). + // - for Bytes, this indicates that the actual type is String (but does + // not require any UTF-8 check). + kUpb_LabelFlags_IsAlternate = 16, +} upb_LabelFlags; + +// Note: we sort by this number when calculating layout order. +typedef enum { + kUpb_FieldRep_1Byte = 0, + kUpb_FieldRep_4Byte = 1, + kUpb_FieldRep_StringView = 2, + kUpb_FieldRep_8Byte = 3, + + kUpb_FieldRep_NativePointer = + UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte), + kUpb_FieldRep_Max = kUpb_FieldRep_8Byte, +} upb_FieldRep; + +#define kUpb_FieldRep_Shift 6 #ifdef __cplusplus -} /* extern "C" */ +extern "C" { #endif +UPB_INLINE upb_FieldMode +UPB_PRIVATE(_upb_MiniTableField_Mode)(const struct upb_MiniTableField* f) { + return (upb_FieldMode)(f->UPB_ONLYBITS(mode) & kUpb_FieldMode_Mask); +} -#endif /* UPB_HASH_STR_TABLE_H_ */ - -// Must be last. +UPB_INLINE upb_FieldRep +UPB_PRIVATE(_upb_MiniTableField_GetRep)(const struct upb_MiniTableField* f) { + return (upb_FieldRep)(f->UPB_ONLYBITS(mode) >> kUpb_FieldRep_Shift); +} -typedef enum { - kUpb_MapInsertStatus_Inserted = 0, - kUpb_MapInsertStatus_Replaced = 1, - kUpb_MapInsertStatus_OutOfMemory = 2, -} upb_MapInsertStatus; +UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsArray)( + const struct upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_Mode)(f) == kUpb_FieldMode_Array; +} -// EVERYTHING BELOW THIS LINE IS INTERNAL - DO NOT USE ///////////////////////// +UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsMap)( + const struct upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_Mode)(f) == kUpb_FieldMode_Map; +} -struct upb_Map { - // Size of key and val, based on the map type. - // Strings are represented as '0' because they must be handled specially. - char key_size; - char val_size; +UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsScalar)( + const struct upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_Mode)(f) == kUpb_FieldMode_Scalar; +} - upb_strtable table; -}; +UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsAlternate)( + const struct upb_MiniTableField* f) { + return (f->UPB_ONLYBITS(mode) & kUpb_LabelFlags_IsAlternate) != 0; +} -#ifdef __cplusplus -extern "C" { -#endif +UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsExtension)( + const struct upb_MiniTableField* f) { + return (f->UPB_ONLYBITS(mode) & kUpb_LabelFlags_IsExtension) != 0; +} -// Converting between internal table representation and user values. -// -// _upb_map_tokey() and _upb_map_fromkey() are inverses. -// _upb_map_tovalue() and _upb_map_fromvalue() are inverses. -// -// These functions account for the fact that strings are treated differently -// from other types when stored in a map. +UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsPacked)( + const struct upb_MiniTableField* f) { + return (f->UPB_ONLYBITS(mode) & kUpb_LabelFlags_IsPacked) != 0; +} -UPB_INLINE upb_StringView _upb_map_tokey(const void* key, size_t size) { - if (size == UPB_MAPTYPE_STRING) { - return *(upb_StringView*)key; - } else { - return upb_StringView_FromDataAndSize((const char*)key, size); +UPB_INLINE upb_FieldType +UPB_PRIVATE(_upb_MiniTableField_Type)(const struct upb_MiniTableField* f) { + const upb_FieldType type = (upb_FieldType)f->UPB_PRIVATE(descriptortype); + if (UPB_PRIVATE(_upb_MiniTableField_IsAlternate)(f)) { + if (type == kUpb_FieldType_Int32) return kUpb_FieldType_Enum; + if (type == kUpb_FieldType_Bytes) return kUpb_FieldType_String; + UPB_ASSERT(false); } + return type; } -UPB_INLINE void _upb_map_fromkey(upb_StringView key, void* out, size_t size) { - if (size == UPB_MAPTYPE_STRING) { - memcpy(out, &key, sizeof(key)); - } else { - memcpy(out, key.data, size); - } +UPB_INLINE upb_CType +UPB_PRIVATE(_upb_MiniTableField_CType)(const struct upb_MiniTableField* f) { + return upb_FieldType_CType(UPB_PRIVATE(_upb_MiniTableField_Type)(f)); } -UPB_INLINE bool _upb_map_tovalue(const void* val, size_t size, - upb_value* msgval, upb_Arena* a) { - if (size == UPB_MAPTYPE_STRING) { - upb_StringView* strp = (upb_StringView*)upb_Arena_Malloc(a, sizeof(*strp)); - if (!strp) return false; - *strp = *(upb_StringView*)val; - *msgval = upb_value_ptr(strp); - } else { - memcpy(msgval, val, size); - } - return true; +UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_HasHasbit)( + const struct upb_MiniTableField* f) { + return f->presence > 0; } -UPB_INLINE void _upb_map_fromvalue(upb_value val, void* out, size_t size) { - if (size == UPB_MAPTYPE_STRING) { - const upb_StringView* strp = (const upb_StringView*)upb_value_getptr(val); - memcpy(out, strp, sizeof(upb_StringView)); - } else { - memcpy(out, &val, size); - } +UPB_INLINE char UPB_PRIVATE(_upb_MiniTableField_HasbitMask)( + const struct upb_MiniTableField* f) { + UPB_ASSERT(UPB_PRIVATE(_upb_MiniTableField_HasHasbit)(f)); + const size_t index = f->presence; + return 1 << (index % 8); } -UPB_INLINE void* _upb_map_next(const struct upb_Map* map, size_t* iter) { - upb_strtable_iter it; - it.t = &map->table; - it.index = *iter; - upb_strtable_next(&it); - *iter = it.index; - if (upb_strtable_done(&it)) return NULL; - return (void*)str_tabent(&it); +UPB_INLINE size_t UPB_PRIVATE(_upb_MiniTableField_HasbitOffset)( + const struct upb_MiniTableField* f) { + UPB_ASSERT(UPB_PRIVATE(_upb_MiniTableField_HasHasbit)(f)); + const size_t index = f->presence; + return index / 8; } -UPB_INLINE void _upb_Map_Clear(struct upb_Map* map) { - upb_strtable_clear(&map->table); +UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsClosedEnum)( + const struct upb_MiniTableField* f) { + return f->UPB_PRIVATE(descriptortype) == kUpb_FieldType_Enum; } -UPB_INLINE bool _upb_Map_Delete(struct upb_Map* map, const void* key, - size_t key_size, upb_value* val) { - upb_StringView k = _upb_map_tokey(key, key_size); - return upb_strtable_remove2(&map->table, k.data, k.size, val); +UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsInOneof)( + const struct upb_MiniTableField* f) { + return f->presence < 0; } -UPB_INLINE bool _upb_Map_Get(const struct upb_Map* map, const void* key, - size_t key_size, void* val, size_t val_size) { - upb_value tabval; - upb_StringView k = _upb_map_tokey(key, key_size); - bool ret = upb_strtable_lookup2(&map->table, k.data, k.size, &tabval); - if (ret && val) { - _upb_map_fromvalue(tabval, val, val_size); - } - return ret; +UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsSubMessage)( + const struct upb_MiniTableField* f) { + return f->UPB_PRIVATE(descriptortype) == kUpb_FieldType_Message || + f->UPB_PRIVATE(descriptortype) == kUpb_FieldType_Group; } -UPB_INLINE upb_MapInsertStatus _upb_Map_Insert(struct upb_Map* map, - const void* key, size_t key_size, - void* val, size_t val_size, - upb_Arena* a) { - upb_StringView strkey = _upb_map_tokey(key, key_size); - upb_value tabval = {0}; - if (!_upb_map_tovalue(val, val_size, &tabval, a)) { - return kUpb_MapInsertStatus_OutOfMemory; +UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_HasPresence)( + const struct upb_MiniTableField* f) { + if (UPB_PRIVATE(_upb_MiniTableField_IsExtension)(f)) { + return UPB_PRIVATE(_upb_MiniTableField_IsScalar)(f); + } else { + return f->presence != 0; } +} - // TODO: add overwrite operation to minimize number of lookups. - bool removed = - upb_strtable_remove2(&map->table, strkey.data, strkey.size, NULL); - if (!upb_strtable_insert(&map->table, strkey.data, strkey.size, tabval, a)) { - return kUpb_MapInsertStatus_OutOfMemory; - } - return removed ? kUpb_MapInsertStatus_Replaced - : kUpb_MapInsertStatus_Inserted; +UPB_INLINE uint32_t +UPB_PRIVATE(_upb_MiniTableField_Number)(const struct upb_MiniTableField* f) { + return f->UPB_ONLYBITS(number); } -UPB_INLINE size_t _upb_Map_Size(const struct upb_Map* map) { - return map->table.t.count; +UPB_INLINE uint16_t +UPB_PRIVATE(_upb_MiniTableField_Offset)(const struct upb_MiniTableField* f) { + return f->UPB_ONLYBITS(offset); } -// Strings/bytes are special-cased in maps. -extern char _upb_Map_CTypeSizeTable[12]; +UPB_INLINE size_t UPB_PRIVATE(_upb_MiniTableField_OneofOffset)( + const struct upb_MiniTableField* f) { + UPB_ASSERT(UPB_PRIVATE(_upb_MiniTableField_IsInOneof)(f)); + return ~(ptrdiff_t)f->presence; +} -UPB_INLINE size_t _upb_Map_CTypeSize(upb_CType ctype) { - return _upb_Map_CTypeSizeTable[ctype]; +UPB_INLINE void UPB_PRIVATE(_upb_MiniTableField_CheckIsArray)( + const struct upb_MiniTableField* f) { + UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == + kUpb_FieldRep_NativePointer); + UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_IsArray)(f)); + UPB_ASSUME(f->presence == 0); } -// Creates a new map on the given arena with this key/value type. -struct upb_Map* _upb_Map_New(upb_Arena* a, size_t key_size, size_t value_size); +UPB_INLINE void UPB_PRIVATE(_upb_MiniTableField_CheckIsMap)( + const struct upb_MiniTableField* f) { + UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == + kUpb_FieldRep_NativePointer); + UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_IsMap)(f)); + UPB_ASSUME(f->presence == 0); +} + +UPB_INLINE size_t UPB_PRIVATE(_upb_MiniTableField_ElemSizeLg2)( + const struct upb_MiniTableField* f) { + const upb_FieldType field_type = UPB_PRIVATE(_upb_MiniTableField_Type)(f); + return UPB_PRIVATE(_upb_FieldType_SizeLg2)(field_type); +} + +// LINT.ThenChange(//depot/google3/third_party/upb/bits/typescript/mini_table_field.ts) #ifdef __cplusplus } /* extern "C" */ #endif -#endif /* UPB_MESSAGE_INTERNAL_MAP_H_ */ +#endif /* UPB_MINI_TABLE_INTERNAL_FIELD_H_ */ -/* -** Our memory representation for parsing tables and messages themselves. -** Functions in this file are used by generated code and possibly reflection. -** -** The definitions in this file are internal to upb. -**/ +// Must be last. -#ifndef UPB_MESSAGE_INTERNAL_MESSAGE_H_ -#define UPB_MESSAGE_INTERNAL_MESSAGE_H_ +typedef struct upb_MiniTableField upb_MiniTableField; -#include -#include +#ifdef __cplusplus +extern "C" { +#endif +UPB_API_INLINE upb_CType upb_MiniTableField_CType(const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_CType)(f); +} -#ifndef UPB_MESSAGE_INTERNAL_EXTENSION_H_ -#define UPB_MESSAGE_INTERNAL_EXTENSION_H_ +UPB_API_INLINE bool upb_MiniTableField_HasPresence( + const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_HasPresence)(f); +} +UPB_API_INLINE bool upb_MiniTableField_IsArray(const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_IsArray)(f); +} -#ifndef UPB_MINI_TABLE_EXTENSION_H_ -#define UPB_MINI_TABLE_EXTENSION_H_ +UPB_API_INLINE bool upb_MiniTableField_IsClosedEnum( + const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_IsClosedEnum)(f); +} -#include +UPB_API_INLINE bool upb_MiniTableField_IsExtension( + const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_IsExtension)(f); +} +UPB_API_INLINE bool upb_MiniTableField_IsInOneof(const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_IsInOneof)(f); +} -#ifndef UPB_MINI_TABLE_FIELD_H_ -#define UPB_MINI_TABLE_FIELD_H_ +UPB_API_INLINE bool upb_MiniTableField_IsMap(const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_IsMap)(f); +} -#include +UPB_API_INLINE bool upb_MiniTableField_IsPacked(const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_IsPacked)(f); +} +UPB_API_INLINE bool upb_MiniTableField_IsScalar(const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_IsScalar)(f); +} -#ifndef UPB_MINI_TABLE_INTERNAL_FIELD_H_ -#define UPB_MINI_TABLE_INTERNAL_FIELD_H_ +UPB_API_INLINE bool upb_MiniTableField_IsSubMessage( + const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_IsSubMessage)(f); +} -#include -#include +UPB_API_INLINE uint32_t upb_MiniTableField_Number(const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_Number)(f); +} +UPB_API_INLINE upb_FieldType +upb_MiniTableField_Type(const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTableField_Type)(f); +} -#ifndef UPB_MINI_TABLE_INTERNAL_SIZE_LOG2_H_ -#define UPB_MINI_TABLE_INTERNAL_SIZE_LOG2_H_ +#ifdef __cplusplus +} /* extern "C" */ +#endif + + +#endif /* UPB_MINI_TABLE_FIELD_H_ */ + +#ifndef UPB_MINI_TABLE_INTERNAL_MESSAGE_H_ +#define UPB_MINI_TABLE_INTERNAL_MESSAGE_H_ -#include #include +#ifndef UPB_MINI_TABLE_INTERNAL_SUB_H_ +#define UPB_MINI_TABLE_INTERNAL_SUB_H_ + // Must be last. +union upb_MiniTableSub { + const struct upb_MiniTable* UPB_PRIVATE(submsg); + const struct upb_MiniTableEnum* UPB_PRIVATE(subenum); +}; + #ifdef __cplusplus extern "C" { #endif -// Return the log2 of the storage size in bytes for a upb_CType -UPB_INLINE int UPB_PRIVATE(_upb_CType_SizeLg2)(upb_CType c_type) { - static const int8_t size[] = { - 0, // kUpb_CType_Bool - 2, // kUpb_CType_Float - 2, // kUpb_CType_Int32 - 2, // kUpb_CType_UInt32 - 2, // kUpb_CType_Enum - UPB_SIZE(2, 3), // kUpb_CType_Message - 3, // kUpb_CType_Double - 3, // kUpb_CType_Int64 - 3, // kUpb_CType_UInt64 - UPB_SIZE(3, 4), // kUpb_CType_String - UPB_SIZE(3, 4), // kUpb_CType_Bytes - }; +UPB_INLINE union upb_MiniTableSub UPB_PRIVATE(_upb_MiniTableSub_FromEnum)( + const struct upb_MiniTableEnum* subenum) { + union upb_MiniTableSub out; + out.UPB_PRIVATE(subenum) = subenum; + return out; +} - // -1 here because the enum is one-based but the table is zero-based. - return size[c_type - 1]; +UPB_INLINE union upb_MiniTableSub UPB_PRIVATE(_upb_MiniTableSub_FromMessage)( + const struct upb_MiniTable* submsg) { + union upb_MiniTableSub out; + out.UPB_PRIVATE(submsg) = submsg; + return out; } -// Return the log2 of the storage size in bytes for a upb_FieldType -UPB_INLINE int UPB_PRIVATE(_upb_FieldType_SizeLg2)(upb_FieldType field_type) { - static const int8_t size[] = { - 3, // kUpb_FieldType_Double - 2, // kUpb_FieldType_Float - 3, // kUpb_FieldType_Int64 - 3, // kUpb_FieldType_UInt64 - 2, // kUpb_FieldType_Int32 - 3, // kUpb_FieldType_Fixed64 - 2, // kUpb_FieldType_Fixed32 - 0, // kUpb_FieldType_Bool - UPB_SIZE(3, 4), // kUpb_FieldType_String - UPB_SIZE(2, 3), // kUpb_FieldType_Group - UPB_SIZE(2, 3), // kUpb_FieldType_Message - UPB_SIZE(3, 4), // kUpb_FieldType_Bytes - 2, // kUpb_FieldType_UInt32 - 2, // kUpb_FieldType_Enum - 2, // kUpb_FieldType_SFixed32 - 3, // kUpb_FieldType_SFixed64 - 2, // kUpb_FieldType_SInt32 - 3, // kUpb_FieldType_SInt64 - }; +UPB_INLINE const struct upb_MiniTableEnum* UPB_PRIVATE(_upb_MiniTableSub_Enum)( + const union upb_MiniTableSub sub) { + return sub.UPB_PRIVATE(subenum); +} - // -1 here because the enum is one-based but the table is zero-based. - return size[field_type - 1]; +UPB_INLINE const struct upb_MiniTable* UPB_PRIVATE(_upb_MiniTableSub_Message)( + const union upb_MiniTableSub sub) { + return sub.UPB_PRIVATE(submsg); } #ifdef __cplusplus @@ -1495,332 +1422,341 @@ UPB_INLINE int UPB_PRIVATE(_upb_FieldType_SizeLg2)(upb_FieldType field_type) { #endif -#endif /* UPB_MINI_TABLE_INTERNAL_SIZE_LOG2_H_ */ +#endif /* UPB_MINI_TABLE_INTERNAL_SUB_H_ */ // Must be last. -// LINT.IfChange(struct_definition) -struct upb_MiniTableField { - uint32_t UPB_ONLYBITS(number); - uint16_t UPB_ONLYBITS(offset); - int16_t presence; // If >0, hasbit_index. If <0, ~oneof_index - - // Indexes into `upb_MiniTable.subs` - // Will be set to `kUpb_NoSub` if `descriptortype` != MESSAGE/GROUP/ENUM - uint16_t UPB_PRIVATE(submsg_index); - - uint8_t UPB_PRIVATE(descriptortype); +struct upb_Decoder; +struct upb_Message; +typedef const char* _upb_FieldParser(struct upb_Decoder* d, const char* ptr, + struct upb_Message* msg, intptr_t table, + uint64_t hasbits, uint64_t data); +typedef struct { + uint64_t field_data; + _upb_FieldParser* field_parser; +} _upb_FastTable_Entry; - // upb_FieldMode | upb_LabelFlags | (upb_FieldRep << kUpb_FieldRep_Shift) - uint8_t UPB_ONLYBITS(mode); -}; +typedef enum { + kUpb_ExtMode_NonExtendable = 0, // Non-extendable message. + kUpb_ExtMode_Extendable = 1, // Normal extendable message. + kUpb_ExtMode_IsMessageSet = 2, // MessageSet message. + kUpb_ExtMode_IsMessageSet_ITEM = + 3, // MessageSet item (temporary only, see decode.c) -#define kUpb_NoSub ((uint16_t)-1) + // During table building we steal a bit to indicate that the message is a map + // entry. *Only* used during table building! + kUpb_ExtMode_IsMapEntry = 4, +} upb_ExtMode; -typedef enum { - kUpb_FieldMode_Map = 0, - kUpb_FieldMode_Array = 1, - kUpb_FieldMode_Scalar = 2, -} upb_FieldMode; +// 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. -// Mask to isolate the upb_FieldMode from field.mode. -#define kUpb_FieldMode_Mask 3 +// LINT.IfChange(minitable_struct_definition) +struct upb_MiniTable { + const union upb_MiniTableSub* UPB_PRIVATE(subs); + const struct upb_MiniTableField* UPB_ONLYBITS(fields); -// Extra flags on the mode field. -typedef enum { - kUpb_LabelFlags_IsPacked = 4, - kUpb_LabelFlags_IsExtension = 8, - // Indicates that this descriptor type is an "alternate type": - // - for Int32, this indicates that the actual type is Enum (but was - // rewritten to Int32 because it is an open enum that requires no check). - // - for Bytes, this indicates that the actual type is String (but does - // not require any UTF-8 check). - kUpb_LabelFlags_IsAlternate = 16, -} upb_LabelFlags; + // Must be aligned to sizeof(void*). Doesn't include internal members like + // unknown fields, extension dict, pointer to msglayout, etc. + uint16_t UPB_PRIVATE(size); -// Note: we sort by this number when calculating layout order. -typedef enum { - kUpb_FieldRep_1Byte = 0, - kUpb_FieldRep_4Byte = 1, - kUpb_FieldRep_StringView = 2, - kUpb_FieldRep_8Byte = 3, + uint16_t UPB_ONLYBITS(field_count); - kUpb_FieldRep_NativePointer = - UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte), - kUpb_FieldRep_Max = kUpb_FieldRep_8Byte, -} upb_FieldRep; + uint8_t UPB_PRIVATE(ext); // upb_ExtMode, uint8_t here so sizeof(ext) == 1 + uint8_t UPB_PRIVATE(dense_below); + uint8_t UPB_PRIVATE(table_mask); + uint8_t UPB_PRIVATE(required_count); // Required fields have the low hasbits. -#define kUpb_FieldRep_Shift 6 + // To statically initialize the tables of variable length, we need a flexible + // array member, and we need to compile in gnu99 mode (constant initialization + // of flexible array members is a GNU extension, not in C99 unfortunately. + _upb_FastTable_Entry UPB_PRIVATE(fasttable)[]; +}; +// LINT.ThenChange(//depot/google3/third_party/upb/bits/typescript/mini_table.ts) #ifdef __cplusplus extern "C" { #endif -UPB_INLINE upb_FieldMode -UPB_PRIVATE(_upb_MiniTableField_Mode)(const struct upb_MiniTableField* f) { - return (upb_FieldMode)(f->UPB_ONLYBITS(mode) & kUpb_FieldMode_Mask); +UPB_INLINE const struct upb_MiniTable* UPB_PRIVATE(_upb_MiniTable_Empty)(void) { + extern const struct upb_MiniTable UPB_PRIVATE(_kUpb_MiniTable_Empty); + + return &UPB_PRIVATE(_kUpb_MiniTable_Empty); } -UPB_INLINE upb_FieldRep -UPB_PRIVATE(_upb_MiniTableField_GetRep)(const struct upb_MiniTableField* f) { - return (upb_FieldRep)(f->UPB_ONLYBITS(mode) >> kUpb_FieldRep_Shift); +UPB_INLINE int UPB_PRIVATE(_upb_MiniTable_FieldCount)( + const struct upb_MiniTable* m) { + return m->UPB_ONLYBITS(field_count); } -UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsArray)( - const struct upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTableField_Mode)(f) == kUpb_FieldMode_Array; +UPB_INLINE bool UPB_PRIVATE(_upb_MiniTable_IsEmpty)( + const struct upb_MiniTable* m) { + extern const struct upb_MiniTable UPB_PRIVATE(_kUpb_MiniTable_Empty); + + return m == &UPB_PRIVATE(_kUpb_MiniTable_Empty); } -UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsMap)( - const struct upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTableField_Mode)(f) == kUpb_FieldMode_Map; -} - -UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsScalar)( - const struct upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTableField_Mode)(f) == kUpb_FieldMode_Scalar; -} - -UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsAlternate)( - const struct upb_MiniTableField* f) { - return (f->UPB_ONLYBITS(mode) & kUpb_LabelFlags_IsAlternate) != 0; -} - -UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsExtension)( - const struct upb_MiniTableField* f) { - return (f->UPB_ONLYBITS(mode) & kUpb_LabelFlags_IsExtension) != 0; -} - -UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsPacked)( - const struct upb_MiniTableField* f) { - return (f->UPB_ONLYBITS(mode) & kUpb_LabelFlags_IsPacked) != 0; -} - -UPB_INLINE upb_FieldType -UPB_PRIVATE(_upb_MiniTableField_Type)(const struct upb_MiniTableField* f) { - const upb_FieldType type = (upb_FieldType)f->UPB_PRIVATE(descriptortype); - if (UPB_PRIVATE(_upb_MiniTableField_IsAlternate)(f)) { - if (type == kUpb_FieldType_Int32) return kUpb_FieldType_Enum; - if (type == kUpb_FieldType_Bytes) return kUpb_FieldType_String; - UPB_ASSERT(false); - } - return type; -} - -UPB_INLINE upb_CType -UPB_PRIVATE(_upb_MiniTableField_CType)(const struct upb_MiniTableField* f) { - return upb_FieldType_CType(UPB_PRIVATE(_upb_MiniTableField_Type)(f)); -} - -UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_HasHasbit)( - const struct upb_MiniTableField* f) { - return f->presence > 0; -} - -UPB_INLINE char UPB_PRIVATE(_upb_MiniTableField_HasbitMask)( - const struct upb_MiniTableField* f) { - UPB_ASSERT(UPB_PRIVATE(_upb_MiniTableField_HasHasbit)(f)); - const size_t index = f->presence; - return 1 << (index % 8); -} - -UPB_INLINE size_t UPB_PRIVATE(_upb_MiniTableField_HasbitOffset)( - const struct upb_MiniTableField* f) { - UPB_ASSERT(UPB_PRIVATE(_upb_MiniTableField_HasHasbit)(f)); - const size_t index = f->presence; - return index / 8; -} - -UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsClosedEnum)( - const struct upb_MiniTableField* f) { - return f->UPB_PRIVATE(descriptortype) == kUpb_FieldType_Enum; -} - -UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsInOneof)( - const struct upb_MiniTableField* f) { - return f->presence < 0; -} - -UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_IsSubMessage)( - const struct upb_MiniTableField* f) { - return f->UPB_PRIVATE(descriptortype) == kUpb_FieldType_Message || - f->UPB_PRIVATE(descriptortype) == kUpb_FieldType_Group; +UPB_INLINE const struct upb_MiniTableField* UPB_PRIVATE( + _upb_MiniTable_GetFieldByIndex)(const struct upb_MiniTable* m, uint32_t i) { + return &m->UPB_ONLYBITS(fields)[i]; } -UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_HasPresence)( - const struct upb_MiniTableField* f) { - if (UPB_PRIVATE(_upb_MiniTableField_IsExtension)(f)) { - return UPB_PRIVATE(_upb_MiniTableField_IsScalar)(f); - } else { - return f->presence != 0; - } +UPB_INLINE const union upb_MiniTableSub* UPB_PRIVATE( + _upb_MiniTable_GetSubByIndex)(const struct upb_MiniTable* m, uint32_t i) { + return &m->UPB_PRIVATE(subs)[i]; } -UPB_INLINE uint32_t -UPB_PRIVATE(_upb_MiniTableField_Number)(const struct upb_MiniTableField* f) { - return f->UPB_ONLYBITS(number); +UPB_INLINE const struct upb_MiniTable* UPB_PRIVATE( + _upb_MiniTable_GetSubMessageTable)(const struct upb_MiniTable* m, + const struct upb_MiniTableField* f) { + UPB_ASSERT(UPB_PRIVATE(_upb_MiniTableField_CType)(f) == kUpb_CType_Message); + const struct upb_MiniTable* ret = UPB_PRIVATE(_upb_MiniTableSub_Message)( + m->UPB_PRIVATE(subs)[f->UPB_PRIVATE(submsg_index)]); + UPB_ASSUME(ret); + return UPB_PRIVATE(_upb_MiniTable_IsEmpty)(ret) ? NULL : ret; } -UPB_INLINE uint16_t -UPB_PRIVATE(_upb_MiniTableField_Offset)(const struct upb_MiniTableField* f) { - return f->UPB_ONLYBITS(offset); +UPB_INLINE const struct upb_MiniTableEnum* UPB_PRIVATE( + _upb_MiniTable_GetSubEnumTable)(const struct upb_MiniTable* m, + const struct upb_MiniTableField* f) { + UPB_ASSERT(UPB_PRIVATE(_upb_MiniTableField_CType)(f) == kUpb_CType_Enum); + return UPB_PRIVATE(_upb_MiniTableSub_Enum)( + m->UPB_PRIVATE(subs)[f->UPB_PRIVATE(submsg_index)]); } -UPB_INLINE size_t UPB_PRIVATE(_upb_MiniTableField_OneofOffset)( - const struct upb_MiniTableField* f) { - UPB_ASSERT(UPB_PRIVATE(_upb_MiniTableField_IsInOneof)(f)); - return ~(ptrdiff_t)f->presence; +UPB_INLINE const struct upb_MiniTableField* UPB_PRIVATE(_upb_MiniTable_MapKey)( + const struct upb_MiniTable* m) { + UPB_ASSERT(UPB_PRIVATE(_upb_MiniTable_FieldCount)(m) == 2); + const struct upb_MiniTableField* f = + UPB_PRIVATE(_upb_MiniTable_GetFieldByIndex)(m, 0); + UPB_ASSERT(UPB_PRIVATE(_upb_MiniTableField_Number)(f) == 1); + return f; } -UPB_INLINE void UPB_PRIVATE(_upb_MiniTableField_CheckIsArray)( - const struct upb_MiniTableField* f) { - UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == - kUpb_FieldRep_NativePointer); - UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_IsArray)(f)); - UPB_ASSUME(f->presence == 0); +UPB_INLINE const struct upb_MiniTableField* UPB_PRIVATE( + _upb_MiniTable_MapValue)(const struct upb_MiniTable* m) { + UPB_ASSERT(UPB_PRIVATE(_upb_MiniTable_FieldCount)(m) == 2); + const struct upb_MiniTableField* f = + UPB_PRIVATE(_upb_MiniTable_GetFieldByIndex)(m, 1); + UPB_ASSERT(UPB_PRIVATE(_upb_MiniTableField_Number)(f) == 2); + return f; } -UPB_INLINE void UPB_PRIVATE(_upb_MiniTableField_CheckIsMap)( - const struct upb_MiniTableField* f) { - UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == - kUpb_FieldRep_NativePointer); - UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_IsMap)(f)); - UPB_ASSUME(f->presence == 0); +UPB_INLINE bool UPB_PRIVATE(_upb_MiniTable_MessageFieldIsLinked)( + const struct upb_MiniTable* m, const struct upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTable_GetSubMessageTable)(m, f) != NULL; } -UPB_INLINE size_t UPB_PRIVATE(_upb_MiniTableField_ElemSizeLg2)( - const struct upb_MiniTableField* f) { - const upb_FieldType field_type = UPB_PRIVATE(_upb_MiniTableField_Type)(f); - return UPB_PRIVATE(_upb_FieldType_SizeLg2)(field_type); +// Computes a bitmask in which the |m->required_count| lowest bits are set, +// except that we skip the lowest bit (because upb never uses hasbit 0). +// +// Sample output: +// RequiredMask(1) => 0b10 (0x2) +// RequiredMask(5) => 0b111110 (0x3e) +UPB_INLINE uint64_t +UPB_PRIVATE(_upb_MiniTable_RequiredMask)(const struct upb_MiniTable* m) { + int n = m->UPB_PRIVATE(required_count); + UPB_ASSERT(0 < n && n <= 63); + return ((1ULL << n) - 1) << 1; } -// LINT.ThenChange(//depot/google3/third_party/upb/bits/typescript/mini_table_field.ts) - #ifdef __cplusplus } /* extern "C" */ #endif -#endif /* UPB_MINI_TABLE_INTERNAL_FIELD_H_ */ +#endif /* UPB_MINI_TABLE_INTERNAL_MESSAGE_H_ */ // Must be last. -typedef struct upb_MiniTableField upb_MiniTableField; +typedef struct upb_MiniTable upb_MiniTable; #ifdef __cplusplus extern "C" { #endif -UPB_API_INLINE upb_CType upb_MiniTableField_CType(const upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTableField_CType)(f); -} - -UPB_API_INLINE bool upb_MiniTableField_HasPresence( - const upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTableField_HasPresence)(f); -} - -UPB_API_INLINE bool upb_MiniTableField_IsArray(const upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTableField_IsArray)(f); -} +UPB_API const upb_MiniTableField* upb_MiniTable_FindFieldByNumber( + const upb_MiniTable* m, uint32_t number); -UPB_API_INLINE bool upb_MiniTableField_IsClosedEnum( - const upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTableField_IsClosedEnum)(f); +UPB_API_INLINE const upb_MiniTableField* upb_MiniTable_GetFieldByIndex( + const upb_MiniTable* m, uint32_t index) { + return UPB_PRIVATE(_upb_MiniTable_GetFieldByIndex)(m, index); } -UPB_API_INLINE bool upb_MiniTableField_IsExtension( - const upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTableField_IsExtension)(f); +UPB_API_INLINE int upb_MiniTable_FieldCount(const upb_MiniTable* m) { + return UPB_PRIVATE(_upb_MiniTable_FieldCount)(m); } -UPB_API_INLINE bool upb_MiniTableField_IsInOneof(const upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTableField_IsInOneof)(f); +// Returns the MiniTable for a message field, NULL if the field is unlinked. +UPB_API_INLINE const upb_MiniTable* upb_MiniTable_GetSubMessageTable( + const upb_MiniTable* m, const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTable_GetSubMessageTable)(m, f); } -UPB_API_INLINE bool upb_MiniTableField_IsMap(const upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTableField_IsMap)(f); +// Returns the MiniTableEnum for a message field, NULL if the field is unlinked. +UPB_API_INLINE const upb_MiniTableEnum* upb_MiniTable_GetSubEnumTable( + const upb_MiniTable* m, const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTable_GetSubEnumTable)(m, f); } -UPB_API_INLINE bool upb_MiniTableField_IsPacked(const upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTableField_IsPacked)(f); +// Returns the MiniTableField for the key of a map. +UPB_API_INLINE const upb_MiniTableField* upb_MiniTable_MapKey( + const upb_MiniTable* m) { + return UPB_PRIVATE(_upb_MiniTable_MapKey)(m); } -UPB_API_INLINE bool upb_MiniTableField_IsScalar(const upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTableField_IsScalar)(f); +// Returns the MiniTableField for the value of a map. +UPB_API_INLINE const upb_MiniTableField* upb_MiniTable_MapValue( + const upb_MiniTable* m) { + return UPB_PRIVATE(_upb_MiniTable_MapValue)(m); } -UPB_API_INLINE bool upb_MiniTableField_IsSubMessage( - const upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTableField_IsSubMessage)(f); +// Returns true if this MiniTable field is linked to a MiniTable for the +// sub-message. +UPB_API_INLINE bool upb_MiniTable_MessageFieldIsLinked( + const upb_MiniTable* m, const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_MiniTable_MessageFieldIsLinked)(m, f); } -UPB_API_INLINE uint32_t upb_MiniTableField_Number(const upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTableField_Number)(f); -} +// If this field is in a oneof, returns the first field in the oneof. +// +// Otherwise returns NULL. +// +// Usage: +// const upb_MiniTableField* field = upb_MiniTable_GetOneof(m, f); +// do { +// .. +// } while (upb_MiniTable_NextOneofField(m, &field); +// +const upb_MiniTableField* upb_MiniTable_GetOneof(const upb_MiniTable* m, + const upb_MiniTableField* f); -UPB_API_INLINE upb_FieldType -upb_MiniTableField_Type(const upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTableField_Type)(f); -} +// Iterates to the next field in the oneof. If this is the last field in the +// oneof, returns false. The ordering of fields in the oneof is not +// guaranteed. +// REQUIRES: |f| is the field initialized by upb_MiniTable_GetOneof and updated +// by prior upb_MiniTable_NextOneofField calls. +bool upb_MiniTable_NextOneofField(const upb_MiniTable* m, + const upb_MiniTableField** f); #ifdef __cplusplus } /* extern "C" */ #endif -#endif /* UPB_MINI_TABLE_FIELD_H_ */ +#endif /* UPB_MINI_TABLE_MESSAGE_H_ */ -#ifndef UPB_MINI_TABLE_INTERNAL_EXTENSION_H_ -#define UPB_MINI_TABLE_INTERNAL_EXTENSION_H_ +// Must be last. -#include +#ifdef __cplusplus +extern "C" { +#endif +extern const float kUpb_FltInfinity; +extern const double kUpb_Infinity; +extern const double kUpb_NaN; -#ifndef UPB_MINI_TABLE_INTERNAL_SUB_H_ -#define UPB_MINI_TABLE_INTERNAL_SUB_H_ +/* Internal members of a upb_Message that track unknown fields and/or + * extensions. We can change this without breaking binary compatibility. We put + * these before the user's data. The user's upb_Message* points after the + * upb_Message_Internal. */ -// Must be last. +typedef struct { + /* Total size of this structure, including the data that follows. + * Must be aligned to 8, which is alignof(upb_Extension) */ + uint32_t size; -union upb_MiniTableSub { - const struct upb_MiniTable* UPB_PRIVATE(submsg); - const struct upb_MiniTableEnum* UPB_PRIVATE(subenum); -}; + /* Offsets relative to the beginning of this structure. + * + * Unknown data grows forward from the beginning to unknown_end. + * Extension data grows backward from size to ext_begin. + * When the two meet, we're out of data and have to realloc. + * + * If we imagine that the final member of this struct is: + * char data[size - overhead]; // overhead = + * sizeof(upb_Message_InternalData) + * + * Then we have: + * unknown data: data[0 .. (unknown_end - overhead)] + * extensions data: data[(ext_begin - overhead) .. (size - overhead)] */ + uint32_t unknown_end; + uint32_t ext_begin; + /* Data follows, as if there were an array: + * char data[size - sizeof(upb_Message_InternalData)]; */ +} upb_Message_InternalData; -#ifdef __cplusplus -extern "C" { -#endif +typedef struct { + union { + upb_Message_InternalData* internal; -UPB_INLINE union upb_MiniTableSub UPB_PRIVATE(_upb_MiniTableSub_FromEnum)( - const struct upb_MiniTableEnum* subenum) { - union upb_MiniTableSub out; - out.UPB_PRIVATE(subenum) = subenum; - return out; + // Force 8-byte alignment, since the data members may contain members that + // require 8-byte alignment. + double d; + }; +} upb_Message_Internal; + +struct upb_Message { + int unused; // Placeholder cuz Windows won't compile an empty struct. +}; + +UPB_INLINE size_t upb_msg_sizeof(const upb_MiniTable* m) { + return m->UPB_PRIVATE(size) + sizeof(upb_Message_Internal); } -UPB_INLINE union upb_MiniTableSub UPB_PRIVATE(_upb_MiniTableSub_FromMessage)( - const struct upb_MiniTable* submsg) { - union upb_MiniTableSub out; - out.UPB_PRIVATE(submsg) = submsg; - return out; +// Inline version upb_Message_New(), for internal use. +UPB_INLINE struct upb_Message* _upb_Message_New(const upb_MiniTable* mini_table, + upb_Arena* arena) { + size_t size = upb_msg_sizeof(mini_table); + void* mem = upb_Arena_Malloc(arena, size + sizeof(upb_Message_Internal)); + if (UPB_UNLIKELY(!mem)) return NULL; + struct upb_Message* msg = + UPB_PTR_AT(mem, sizeof(upb_Message_Internal), struct upb_Message); + memset(mem, 0, size); + return msg; } -UPB_INLINE const struct upb_MiniTableEnum* UPB_PRIVATE(_upb_MiniTableSub_Enum)( - const union upb_MiniTableSub sub) { - return sub.UPB_PRIVATE(subenum); +UPB_INLINE upb_Message_Internal* upb_Message_Getinternal( + const struct upb_Message* msg) { + ptrdiff_t size = sizeof(upb_Message_Internal); + return (upb_Message_Internal*)((char*)msg - size); } -UPB_INLINE const struct upb_MiniTable* UPB_PRIVATE(_upb_MiniTableSub_Message)( - const union upb_MiniTableSub sub) { - return sub.UPB_PRIVATE(submsg); +UPB_INLINE upb_Message_InternalData* upb_Message_GetInternalData( + const struct upb_Message* msg) { + return upb_Message_Getinternal(msg)->internal; } +// Discards the unknown fields for this message only. +void _upb_Message_DiscardUnknown_shallow(struct upb_Message* msg); + +// Adds unknown data (serialized protobuf data) to the given message. +// The data is copied into the message instance. +bool UPB_PRIVATE(_upb_Message_AddUnknown)(struct upb_Message* msg, + const char* data, size_t len, + upb_Arena* arena); + +bool UPB_PRIVATE(_upb_Message_Realloc)(struct upb_Message* msg, size_t need, + upb_Arena* arena); + #ifdef __cplusplus } /* extern "C" */ #endif -#endif /* UPB_MINI_TABLE_INTERNAL_SUB_H_ */ +#endif /* UPB_MESSAGE_INTERNAL_MESSAGE_H_ */ + +#ifndef UPB_MINI_TABLE_EXTENSION_H_ +#define UPB_MINI_TABLE_EXTENSION_H_ + +#include + + +#ifndef UPB_MINI_TABLE_INTERNAL_EXTENSION_H_ +#define UPB_MINI_TABLE_INTERNAL_EXTENSION_H_ + +#include + // Must be last. @@ -1864,56 +1800,32 @@ UPB_INLINE void UPB_PRIVATE(_upb_MiniTableExtension_SetSubMessage)( #endif /* UPB_MINI_TABLE_INTERNAL_EXTENSION_H_ */ -#ifndef UPB_MINI_TABLE_MESSAGE_H_ -#define UPB_MINI_TABLE_MESSAGE_H_ - - -#ifndef UPB_MINI_TABLE_ENUM_H_ -#define UPB_MINI_TABLE_ENUM_H_ - -#include - - -#ifndef UPB_MINI_TABLE_INTERNAL_ENUM_H_ -#define UPB_MINI_TABLE_INTERNAL_ENUM_H_ - -#include - // Must be last. -struct upb_MiniTableEnum { - uint32_t UPB_PRIVATE(mask_limit); // Highest that can be tested with mask. - uint32_t UPB_PRIVATE(value_count); // Number of values after the bitfield. - uint32_t UPB_PRIVATE(data)[]; // Bitmask + enumerated values follow. -}; +typedef struct upb_MiniTableExtension upb_MiniTableExtension; #ifdef __cplusplus extern "C" { #endif -UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableEnum_CheckValue)( - const struct upb_MiniTableEnum* e, uint32_t val) { - if (UPB_LIKELY(val < 64)) { - const uint64_t mask = - e->UPB_PRIVATE(data)[0] | ((uint64_t)e->UPB_PRIVATE(data)[1] << 32); - const uint64_t bit = 1ULL << val; - return (mask & bit) != 0; - } - if (UPB_LIKELY(val < e->UPB_PRIVATE(mask_limit))) { - const uint32_t mask = e->UPB_PRIVATE(data)[val / 32]; - const uint32_t bit = 1ULL << (val % 32); - return (mask & bit) != 0; - } +UPB_API_INLINE const upb_MiniTableField* upb_MiniTableExtension_AsField( + const upb_MiniTableExtension* e) { + return UPB_PRIVATE(_upb_MiniTableExtension_AsField)(e); +} - // OPT: binary search long lists? - const uint32_t* start = - &e->UPB_PRIVATE(data)[e->UPB_PRIVATE(mask_limit) / 32]; - const uint32_t* limit = &e->UPB_PRIVATE( - data)[e->UPB_PRIVATE(mask_limit) / 32 + e->UPB_PRIVATE(value_count)]; - for (const uint32_t* p = start; p < limit; p++) { - if (*p == val) return true; - } - return false; +UPB_API_INLINE uint32_t +upb_MiniTableExtension_Number(const upb_MiniTableExtension* e) { + return UPB_PRIVATE(_upb_MiniTableExtension_Number)(e); +} + +UPB_API_INLINE const upb_MiniTable* upb_MiniTableExtension_GetSubMessage( + const upb_MiniTableExtension* e) { + return UPB_PRIVATE(_upb_MiniTableExtension_GetSubMessage)(e); +} + +UPB_API_INLINE void upb_MiniTableExtension_SetSubMessage( + upb_MiniTableExtension* e, const upb_MiniTable* m) { + UPB_PRIVATE(_upb_MiniTableExtension_SetSubMessage)(e, m); } #ifdef __cplusplus @@ -1921,438 +1833,499 @@ UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableEnum_CheckValue)( #endif -#endif /* UPB_MINI_TABLE_INTERNAL_ENUM_H_ */ +#endif /* UPB_MINI_TABLE_EXTENSION_H_ */ -// Must be last +// Must be last. -typedef struct upb_MiniTableEnum upb_MiniTableEnum; +// The internal representation of an extension is self-describing: it contains +// enough information that we can serialize it to binary format without needing +// to look it up in a upb_ExtensionRegistry. +// +// This representation allocates 16 bytes to data on 64-bit platforms. +// This is rather wasteful for scalars (in the extreme case of bool, +// it wastes 15 bytes). We accept this because we expect messages to be +// the most common extension type. +struct upb_Extension { + const upb_MiniTableExtension* ext; + union { + upb_StringView str; + void* ptr; + char scalar_data[8]; + } data; +}; #ifdef __cplusplus extern "C" { #endif -// Validates enum value against range defined by enum mini table. -UPB_INLINE bool upb_MiniTableEnum_CheckValue(const upb_MiniTableEnum* e, - uint32_t val) { - return UPB_PRIVATE(_upb_MiniTableEnum_CheckValue)(e, val); -} +// Adds the given extension data to the given message. +// |ext| is copied into the message instance. +// This logically replaces any previously-added extension with this number. +struct upb_Extension* _upb_Message_GetOrCreateExtension( + struct upb_Message* msg, const upb_MiniTableExtension* ext, + upb_Arena* arena); + +// Returns an array of extensions for this message. +// Note: the array is ordered in reverse relative to the order of creation. +const struct upb_Extension* UPB_PRIVATE(_upb_Message_Getexts)( + const struct upb_Message* msg, size_t* count); + +// Returns an extension for a message with a given mini table, +// or NULL if no extension exists with this mini table. +const struct upb_Extension* _upb_Message_Getext( + const struct upb_Message* msg, const upb_MiniTableExtension* ext); #ifdef __cplusplus } /* extern "C" */ #endif -#endif /* UPB_MINI_TABLE_ENUM_H_ */ +#endif /* UPB_MESSAGE_INTERNAL_EXTENSION_H_ */ -#ifndef UPB_MINI_TABLE_INTERNAL_MESSAGE_H_ -#define UPB_MINI_TABLE_INTERNAL_MESSAGE_H_ +#ifndef UPB_MESSAGE_INTERNAL_MAP_H_ +#define UPB_MESSAGE_INTERNAL_MAP_H_ -#include +#include +#include -// Must be last. +#ifndef UPB_HASH_STR_TABLE_H_ +#define UPB_HASH_STR_TABLE_H_ -struct upb_Decoder; -struct upb_Message; -typedef const char* _upb_FieldParser(struct upb_Decoder* d, const char* ptr, - struct upb_Message* msg, intptr_t table, - uint64_t hasbits, uint64_t data); -typedef struct { - uint64_t field_data; - _upb_FieldParser* field_parser; -} _upb_FastTable_Entry; -typedef enum { - kUpb_ExtMode_NonExtendable = 0, // Non-extendable message. - kUpb_ExtMode_Extendable = 1, // Normal extendable message. - kUpb_ExtMode_IsMessageSet = 2, // MessageSet message. - kUpb_ExtMode_IsMessageSet_ITEM = - 3, // MessageSet item (temporary only, see decode.c) +/* + * upb_table + * + * This header is INTERNAL-ONLY! Its interfaces are not public or stable! + * This file defines very fast int->upb_value (inttable) and string->upb_value + * (strtable) hash tables. + * + * The table uses chained scatter with Brent's variation (inspired by the Lua + * implementation of hash tables). The hash function for strings is Austin + * Appleby's "MurmurHash." + * + * The inttable uses uintptr_t as its key, which guarantees it can be used to + * store pointers or integers of at least 32 bits (upb isn't really useful on + * systems where sizeof(void*) < 4). + * + * The table must be homogeneous (all values of the same type). In debug + * mode, we check this on insert and lookup. + */ - // During table building we steal a bit to indicate that the message is a map - // entry. *Only* used during table building! - kUpb_ExtMode_IsMapEntry = 4, -} upb_ExtMode; - -// 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. - -// LINT.IfChange(minitable_struct_definition) -struct upb_MiniTable { - const union upb_MiniTableSub* UPB_PRIVATE(subs); - const struct upb_MiniTableField* UPB_ONLYBITS(fields); - - // Must be aligned to sizeof(void*). Doesn't include internal members like - // unknown fields, extension dict, pointer to msglayout, etc. - uint16_t UPB_PRIVATE(size); +#ifndef UPB_HASH_COMMON_H_ +#define UPB_HASH_COMMON_H_ - uint16_t UPB_ONLYBITS(field_count); +#include - uint8_t UPB_PRIVATE(ext); // upb_ExtMode, uint8_t here so sizeof(ext) == 1 - uint8_t UPB_PRIVATE(dense_below); - uint8_t UPB_PRIVATE(table_mask); - uint8_t UPB_PRIVATE(required_count); // Required fields have the low hasbits. - // To statically initialize the tables of variable length, we need a flexible - // array member, and we need to compile in gnu99 mode (constant initialization - // of flexible array members is a GNU extension, not in C99 unfortunately. - _upb_FastTable_Entry UPB_PRIVATE(fasttable)[]; -}; -// LINT.ThenChange(//depot/google3/third_party/upb/bits/typescript/mini_table.ts) +// Must be last. #ifdef __cplusplus extern "C" { #endif -UPB_INLINE const struct upb_MiniTable* UPB_PRIVATE(_upb_MiniTable_Empty)(void) { - extern const struct upb_MiniTable UPB_PRIVATE(_kUpb_MiniTable_Empty); +/* upb_value ******************************************************************/ - return &UPB_PRIVATE(_kUpb_MiniTable_Empty); -} +typedef struct { + uint64_t val; +} upb_value; -UPB_INLINE int UPB_PRIVATE(_upb_MiniTable_FieldCount)( - const struct upb_MiniTable* m) { - return m->UPB_ONLYBITS(field_count); -} +UPB_INLINE void _upb_value_setval(upb_value* v, uint64_t val) { v->val = val; } -UPB_INLINE bool UPB_PRIVATE(_upb_MiniTable_IsEmpty)( - const struct upb_MiniTable* m) { - extern const struct upb_MiniTable UPB_PRIVATE(_kUpb_MiniTable_Empty); +/* For each value ctype, define the following set of functions: + * + * // Get/set an int32 from a upb_value. + * int32_t upb_value_getint32(upb_value val); + * void upb_value_setint32(upb_value *val, int32_t cval); + * + * // Construct a new upb_value from an int32. + * upb_value upb_value_int32(int32_t val); */ +#define FUNCS(name, membername, type_t, converter) \ + UPB_INLINE void upb_value_set##name(upb_value* val, type_t cval) { \ + val->val = (converter)cval; \ + } \ + UPB_INLINE upb_value upb_value_##name(type_t val) { \ + upb_value ret; \ + upb_value_set##name(&ret, val); \ + return ret; \ + } \ + UPB_INLINE type_t upb_value_get##name(upb_value val) { \ + return (type_t)(converter)val.val; \ + } - return m == &UPB_PRIVATE(_kUpb_MiniTable_Empty); -} +FUNCS(int32, int32, int32_t, int32_t) +FUNCS(int64, int64, int64_t, int64_t) +FUNCS(uint32, uint32, uint32_t, uint32_t) +FUNCS(uint64, uint64, uint64_t, uint64_t) +FUNCS(bool, _bool, bool, bool) +FUNCS(cstr, cstr, char*, uintptr_t) +FUNCS(uintptr, uptr, uintptr_t, uintptr_t) +FUNCS(ptr, ptr, void*, uintptr_t) +FUNCS(constptr, constptr, const void*, uintptr_t) -UPB_INLINE const struct upb_MiniTableField* UPB_PRIVATE( - _upb_MiniTable_GetFieldByIndex)(const struct upb_MiniTable* m, uint32_t i) { - return &m->UPB_ONLYBITS(fields)[i]; -} +#undef FUNCS -UPB_INLINE const union upb_MiniTableSub* UPB_PRIVATE( - _upb_MiniTable_GetSubByIndex)(const struct upb_MiniTable* m, uint32_t i) { - return &m->UPB_PRIVATE(subs)[i]; +UPB_INLINE void upb_value_setfloat(upb_value* val, float cval) { + memcpy(&val->val, &cval, sizeof(cval)); } -UPB_INLINE const struct upb_MiniTable* UPB_PRIVATE( - _upb_MiniTable_GetSubMessageTable)(const struct upb_MiniTable* m, - const struct upb_MiniTableField* f) { - UPB_ASSERT(UPB_PRIVATE(_upb_MiniTableField_CType)(f) == kUpb_CType_Message); - const struct upb_MiniTable* ret = UPB_PRIVATE(_upb_MiniTableSub_Message)( - m->UPB_PRIVATE(subs)[f->UPB_PRIVATE(submsg_index)]); - UPB_ASSUME(ret); - return UPB_PRIVATE(_upb_MiniTable_IsEmpty)(ret) ? NULL : ret; +UPB_INLINE void upb_value_setdouble(upb_value* val, double cval) { + memcpy(&val->val, &cval, sizeof(cval)); } -UPB_INLINE const struct upb_MiniTableEnum* UPB_PRIVATE( - _upb_MiniTable_GetSubEnumTable)(const struct upb_MiniTable* m, - const struct upb_MiniTableField* f) { - UPB_ASSERT(UPB_PRIVATE(_upb_MiniTableField_CType)(f) == kUpb_CType_Enum); - return UPB_PRIVATE(_upb_MiniTableSub_Enum)( - m->UPB_PRIVATE(subs)[f->UPB_PRIVATE(submsg_index)]); +UPB_INLINE upb_value upb_value_float(float cval) { + upb_value ret; + upb_value_setfloat(&ret, cval); + return ret; } -UPB_INLINE const struct upb_MiniTableField* UPB_PRIVATE(_upb_MiniTable_MapKey)( - const struct upb_MiniTable* m) { - UPB_ASSERT(UPB_PRIVATE(_upb_MiniTable_FieldCount)(m) == 2); - const struct upb_MiniTableField* f = - UPB_PRIVATE(_upb_MiniTable_GetFieldByIndex)(m, 0); - UPB_ASSERT(UPB_PRIVATE(_upb_MiniTableField_Number)(f) == 1); - return f; +UPB_INLINE upb_value upb_value_double(double cval) { + upb_value ret; + upb_value_setdouble(&ret, cval); + return ret; } -UPB_INLINE const struct upb_MiniTableField* UPB_PRIVATE( - _upb_MiniTable_MapValue)(const struct upb_MiniTable* m) { - UPB_ASSERT(UPB_PRIVATE(_upb_MiniTable_FieldCount)(m) == 2); - const struct upb_MiniTableField* f = - UPB_PRIVATE(_upb_MiniTable_GetFieldByIndex)(m, 1); - UPB_ASSERT(UPB_PRIVATE(_upb_MiniTableField_Number)(f) == 2); - return f; +/* upb_tabkey *****************************************************************/ + +/* Either: + * 1. an actual integer key, or + * 2. a pointer to a string prefixed by its uint32_t length, owned by us. + * + * ...depending on whether this is a string table or an int table. We would + * make this a union of those two types, but C89 doesn't support statically + * initializing a non-first union member. */ +typedef uintptr_t upb_tabkey; + +UPB_INLINE char* upb_tabstr(upb_tabkey key, uint32_t* len) { + char* mem = (char*)key; + if (len) memcpy(len, mem, sizeof(*len)); + return mem + sizeof(*len); } -UPB_INLINE bool UPB_PRIVATE(_upb_MiniTable_MessageFieldIsLinked)( - const struct upb_MiniTable* m, const struct upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTable_GetSubMessageTable)(m, f) != NULL; +UPB_INLINE upb_StringView upb_tabstrview(upb_tabkey key) { + upb_StringView ret; + uint32_t len; + ret.data = upb_tabstr(key, &len); + ret.size = len; + return ret; } -// Computes a bitmask in which the |m->required_count| lowest bits are set, -// except that we skip the lowest bit (because upb never uses hasbit 0). -// -// Sample output: -// RequiredMask(1) => 0b10 (0x2) -// RequiredMask(5) => 0b111110 (0x3e) -UPB_INLINE uint64_t -UPB_PRIVATE(_upb_MiniTable_RequiredMask)(const struct upb_MiniTable* m) { - int n = m->UPB_PRIVATE(required_count); - UPB_ASSERT(0 < n && n <= 63); - return ((1ULL << n) - 1) << 1; +/* upb_tabval *****************************************************************/ + +typedef struct upb_tabval { + uint64_t val; +} upb_tabval; + +#define UPB_TABVALUE_EMPTY_INIT \ + { -1 } + +/* upb_table ******************************************************************/ + +typedef struct _upb_tabent { + upb_tabkey key; + upb_tabval val; + + /* Internal chaining. This is const so we can create static initializers for + * tables. We cast away const sometimes, but *only* when the containing + * upb_table is known to be non-const. This requires a bit of care, but + * the subtlety is confined to table.c. */ + const struct _upb_tabent* next; +} upb_tabent; + +typedef struct { + size_t count; /* Number of entries in the hash part. */ + uint32_t mask; /* Mask to turn hash value -> bucket. */ + uint32_t max_count; /* Max count before we hit our load limit. */ + uint8_t size_lg2; /* Size of the hashtable part is 2^size_lg2 entries. */ + upb_tabent* entries; +} upb_table; + +UPB_INLINE size_t upb_table_size(const upb_table* t) { + return t->size_lg2 ? 1 << t->size_lg2 : 0; } +// Internal-only functions, in .h file only out of necessity. + +UPB_INLINE bool upb_tabent_isempty(const upb_tabent* e) { return e->key == 0; } + +uint32_t _upb_Hash(const void* p, size_t n, uint64_t seed); + #ifdef __cplusplus } /* extern "C" */ #endif -#endif /* UPB_MINI_TABLE_INTERNAL_MESSAGE_H_ */ +#endif /* UPB_HASH_COMMON_H_ */ // Must be last. -typedef struct upb_MiniTable upb_MiniTable; +typedef struct { + upb_table t; +} upb_strtable; #ifdef __cplusplus extern "C" { #endif -UPB_API const upb_MiniTableField* upb_MiniTable_FindFieldByNumber( - const upb_MiniTable* m, uint32_t number); +// Initialize a table. If memory allocation failed, false is returned and +// the table is uninitialized. +bool upb_strtable_init(upb_strtable* table, size_t expected_size, upb_Arena* a); -UPB_API_INLINE const upb_MiniTableField* upb_MiniTable_GetFieldByIndex( - const upb_MiniTable* m, uint32_t index) { - return UPB_PRIVATE(_upb_MiniTable_GetFieldByIndex)(m, index); +// Returns the number of values in the table. +UPB_INLINE size_t upb_strtable_count(const upb_strtable* t) { + return t->t.count; } -UPB_API_INLINE int upb_MiniTable_FieldCount(const upb_MiniTable* m) { - return UPB_PRIVATE(_upb_MiniTable_FieldCount)(m); -} +void upb_strtable_clear(upb_strtable* t); -// Returns the MiniTable for a message field, NULL if the field is unlinked. -UPB_API_INLINE const upb_MiniTable* upb_MiniTable_GetSubMessageTable( - const upb_MiniTable* m, const upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTable_GetSubMessageTable)(m, f); -} +// Inserts the given key into the hashtable with the given value. +// The key must not already exist in the hash table. The key is not required +// to be NULL-terminated, and the table will make an internal copy of the key. +// +// If a table resize was required but memory allocation failed, false is +// returned and the table is unchanged. */ +bool upb_strtable_insert(upb_strtable* t, const char* key, size_t len, + upb_value val, upb_Arena* a); -// Returns the MiniTableEnum for a message field, NULL if the field is unlinked. -UPB_API_INLINE const upb_MiniTableEnum* upb_MiniTable_GetSubEnumTable( - const upb_MiniTable* m, const upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTable_GetSubEnumTable)(m, f); -} +// Looks up key in this table, returning "true" if the key was found. +// If v is non-NULL, copies the value for this key into *v. +bool upb_strtable_lookup2(const upb_strtable* t, const char* key, size_t len, + upb_value* v); -// Returns the MiniTableField for the key of a map. -UPB_API_INLINE const upb_MiniTableField* upb_MiniTable_MapKey( - const upb_MiniTable* m) { - return UPB_PRIVATE(_upb_MiniTable_MapKey)(m); +// For NULL-terminated strings. +UPB_INLINE bool upb_strtable_lookup(const upb_strtable* t, const char* key, + upb_value* v) { + return upb_strtable_lookup2(t, key, strlen(key), v); } -// Returns the MiniTableField for the value of a map. -UPB_API_INLINE const upb_MiniTableField* upb_MiniTable_MapValue( - const upb_MiniTable* m) { - return UPB_PRIVATE(_upb_MiniTable_MapValue)(m); -} +// Removes an item from the table. Returns true if the remove was successful, +// and stores the removed item in *val if non-NULL. +bool upb_strtable_remove2(upb_strtable* t, const char* key, size_t len, + upb_value* val); -// Returns true if this MiniTable field is linked to a MiniTable for the -// sub-message. -UPB_API_INLINE bool upb_MiniTable_MessageFieldIsLinked( - const upb_MiniTable* m, const upb_MiniTableField* f) { - return UPB_PRIVATE(_upb_MiniTable_MessageFieldIsLinked)(m, f); +UPB_INLINE bool upb_strtable_remove(upb_strtable* t, const char* key, + upb_value* v) { + return upb_strtable_remove2(t, key, strlen(key), v); } -// If this field is in a oneof, returns the first field in the oneof. -// -// Otherwise returns NULL. -// -// Usage: -// const upb_MiniTableField* field = upb_MiniTable_GetOneof(m, f); -// do { -// .. -// } while (upb_MiniTable_NextOneofField(m, &field); -// -const upb_MiniTableField* upb_MiniTable_GetOneof(const upb_MiniTable* m, - const upb_MiniTableField* f); - -// Iterates to the next field in the oneof. If this is the last field in the -// oneof, returns false. The ordering of fields in the oneof is not -// guaranteed. -// REQUIRES: |f| is the field initialized by upb_MiniTable_GetOneof and updated -// by prior upb_MiniTable_NextOneofField calls. -bool upb_MiniTable_NextOneofField(const upb_MiniTable* m, - const upb_MiniTableField** f); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - +// Exposed for testing only. +bool upb_strtable_resize(upb_strtable* t, size_t size_lg2, upb_Arena* a); -#endif /* UPB_MINI_TABLE_MESSAGE_H_ */ +/* Iteration over strtable: + * + * intptr_t iter = UPB_STRTABLE_BEGIN; + * upb_StringView key; + * upb_value val; + * while (upb_strtable_next2(t, &key, &val, &iter)) { + * // ... + * } + */ -// Must be last. +#define UPB_STRTABLE_BEGIN -1 -typedef struct upb_MiniTableExtension upb_MiniTableExtension; +bool upb_strtable_next2(const upb_strtable* t, upb_StringView* key, + upb_value* val, intptr_t* iter); +void upb_strtable_removeiter(upb_strtable* t, intptr_t* iter); +void upb_strtable_setentryvalue(upb_strtable* t, intptr_t iter, upb_value v); -#ifdef __cplusplus -extern "C" { -#endif +/* DEPRECATED iterators, slated for removal. + * + * Iterators for string tables. We are subject to some kind of unusual + * design constraints: + * + * For high-level languages: + * - we must be able to guarantee that we don't crash or corrupt memory even if + * the program accesses an invalidated iterator. + * + * For C++11 range-based for: + * - iterators must be copyable + * - iterators must be comparable + * - it must be possible to construct an "end" value. + * + * Iteration order is undefined. + * + * Modifying the table invalidates iterators. upb_{str,int}table_done() is + * guaranteed to work even on an invalidated iterator, as long as the table it + * is iterating over has not been freed. Calling next() or accessing data from + * an invalidated iterator yields unspecified elements from the table, but it is + * guaranteed not to crash and to return real table elements (except when done() + * is true). */ +/* upb_strtable_iter **********************************************************/ -UPB_API_INLINE const upb_MiniTableField* upb_MiniTableExtension_AsField( - const upb_MiniTableExtension* e) { - return UPB_PRIVATE(_upb_MiniTableExtension_AsField)(e); -} +/* upb_strtable_iter i; + * upb_strtable_begin(&i, t); + * for(; !upb_strtable_done(&i); upb_strtable_next(&i)) { + * const char *key = upb_strtable_iter_key(&i); + * const upb_value val = upb_strtable_iter_value(&i); + * // ... + * } + */ -UPB_API_INLINE uint32_t -upb_MiniTableExtension_Number(const upb_MiniTableExtension* e) { - return UPB_PRIVATE(_upb_MiniTableExtension_Number)(e); -} +typedef struct { + const upb_strtable* t; + size_t index; +} upb_strtable_iter; -UPB_API_INLINE const upb_MiniTable* upb_MiniTableExtension_GetSubMessage( - const upb_MiniTableExtension* e) { - return UPB_PRIVATE(_upb_MiniTableExtension_GetSubMessage)(e); +UPB_INLINE const upb_tabent* str_tabent(const upb_strtable_iter* i) { + return &i->t->t.entries[i->index]; } -UPB_API_INLINE void upb_MiniTableExtension_SetSubMessage( - upb_MiniTableExtension* e, const upb_MiniTable* m) { - UPB_PRIVATE(_upb_MiniTableExtension_SetSubMessage)(e, m); -} +void upb_strtable_begin(upb_strtable_iter* i, const upb_strtable* t); +void upb_strtable_next(upb_strtable_iter* i); +bool upb_strtable_done(const upb_strtable_iter* i); +upb_StringView upb_strtable_iter_key(const upb_strtable_iter* i); +upb_value upb_strtable_iter_value(const upb_strtable_iter* i); +void upb_strtable_iter_setdone(upb_strtable_iter* i); +bool upb_strtable_iter_isequal(const upb_strtable_iter* i1, + const upb_strtable_iter* i2); #ifdef __cplusplus } /* extern "C" */ #endif -#endif /* UPB_MINI_TABLE_EXTENSION_H_ */ +#endif /* UPB_HASH_STR_TABLE_H_ */ // Must be last. -// The internal representation of an extension is self-describing: it contains -// enough information that we can serialize it to binary format without needing -// to look it up in a upb_ExtensionRegistry. -// -// This representation allocates 16 bytes to data on 64-bit platforms. -// This is rather wasteful for scalars (in the extreme case of bool, -// it wastes 15 bytes). We accept this because we expect messages to be -// the most common extension type. -struct upb_Extension { - const upb_MiniTableExtension* ext; - union { - upb_StringView str; - void* ptr; - char scalar_data[8]; - } data; -}; - -#ifdef __cplusplus -extern "C" { -#endif - -// Adds the given extension data to the given message. -// |ext| is copied into the message instance. -// This logically replaces any previously-added extension with this number. -struct upb_Extension* _upb_Message_GetOrCreateExtension( - struct upb_Message* msg, const upb_MiniTableExtension* ext, - upb_Arena* arena); - -// Returns an array of extensions for this message. -// Note: the array is ordered in reverse relative to the order of creation. -const struct upb_Extension* UPB_PRIVATE(_upb_Message_Getexts)( - const struct upb_Message* msg, size_t* count); - -// Returns an extension for a message with a given mini table, -// or NULL if no extension exists with this mini table. -const struct upb_Extension* _upb_Message_Getext( - const struct upb_Message* msg, const upb_MiniTableExtension* ext); - -#ifdef __cplusplus -} /* extern "C" */ -#endif +typedef enum { + kUpb_MapInsertStatus_Inserted = 0, + kUpb_MapInsertStatus_Replaced = 1, + kUpb_MapInsertStatus_OutOfMemory = 2, +} upb_MapInsertStatus; +// EVERYTHING BELOW THIS LINE IS INTERNAL - DO NOT USE ///////////////////////// -#endif /* UPB_MESSAGE_INTERNAL_EXTENSION_H_ */ +struct upb_Map { + // Size of key and val, based on the map type. + // Strings are represented as '0' because they must be handled specially. + char key_size; + char val_size; -// Must be last. + upb_strtable table; +}; #ifdef __cplusplus extern "C" { #endif -extern const float kUpb_FltInfinity; -extern const double kUpb_Infinity; -extern const double kUpb_NaN; +// Converting between internal table representation and user values. +// +// _upb_map_tokey() and _upb_map_fromkey() are inverses. +// _upb_map_tovalue() and _upb_map_fromvalue() are inverses. +// +// These functions account for the fact that strings are treated differently +// from other types when stored in a map. -/* Internal members of a upb_Message that track unknown fields and/or - * extensions. We can change this without breaking binary compatibility. We put - * these before the user's data. The user's upb_Message* points after the - * upb_Message_Internal. */ +UPB_INLINE upb_StringView _upb_map_tokey(const void* key, size_t size) { + if (size == UPB_MAPTYPE_STRING) { + return *(upb_StringView*)key; + } else { + return upb_StringView_FromDataAndSize((const char*)key, size); + } +} -typedef struct { - /* Total size of this structure, including the data that follows. - * Must be aligned to 8, which is alignof(upb_Extension) */ - uint32_t size; +UPB_INLINE void _upb_map_fromkey(upb_StringView key, void* out, size_t size) { + if (size == UPB_MAPTYPE_STRING) { + memcpy(out, &key, sizeof(key)); + } else { + memcpy(out, key.data, size); + } +} - /* Offsets relative to the beginning of this structure. - * - * Unknown data grows forward from the beginning to unknown_end. - * Extension data grows backward from size to ext_begin. - * When the two meet, we're out of data and have to realloc. - * - * If we imagine that the final member of this struct is: - * char data[size - overhead]; // overhead = - * sizeof(upb_Message_InternalData) - * - * Then we have: - * unknown data: data[0 .. (unknown_end - overhead)] - * extensions data: data[(ext_begin - overhead) .. (size - overhead)] */ - uint32_t unknown_end; - uint32_t ext_begin; - /* Data follows, as if there were an array: - * char data[size - sizeof(upb_Message_InternalData)]; */ -} upb_Message_InternalData; +UPB_INLINE bool _upb_map_tovalue(const void* val, size_t size, + upb_value* msgval, upb_Arena* a) { + if (size == UPB_MAPTYPE_STRING) { + upb_StringView* strp = (upb_StringView*)upb_Arena_Malloc(a, sizeof(*strp)); + if (!strp) return false; + *strp = *(upb_StringView*)val; + *msgval = upb_value_ptr(strp); + } else { + memcpy(msgval, val, size); + } + return true; +} -typedef struct { - union { - upb_Message_InternalData* internal; +UPB_INLINE void _upb_map_fromvalue(upb_value val, void* out, size_t size) { + if (size == UPB_MAPTYPE_STRING) { + const upb_StringView* strp = (const upb_StringView*)upb_value_getptr(val); + memcpy(out, strp, sizeof(upb_StringView)); + } else { + memcpy(out, &val, size); + } +} - // Force 8-byte alignment, since the data members may contain members that - // require 8-byte alignment. - double d; - }; -} upb_Message_Internal; +UPB_INLINE void* _upb_map_next(const struct upb_Map* map, size_t* iter) { + upb_strtable_iter it; + it.t = &map->table; + it.index = *iter; + upb_strtable_next(&it); + *iter = it.index; + if (upb_strtable_done(&it)) return NULL; + return (void*)str_tabent(&it); +} -struct upb_Message { - int unused; // Placeholder cuz Windows won't compile an empty struct. -}; +UPB_INLINE void _upb_Map_Clear(struct upb_Map* map) { + upb_strtable_clear(&map->table); +} -UPB_INLINE size_t upb_msg_sizeof(const upb_MiniTable* m) { - return m->UPB_PRIVATE(size) + sizeof(upb_Message_Internal); +UPB_INLINE bool _upb_Map_Delete(struct upb_Map* map, const void* key, + size_t key_size, upb_value* val) { + upb_StringView k = _upb_map_tokey(key, key_size); + return upb_strtable_remove2(&map->table, k.data, k.size, val); } -// Inline version upb_Message_New(), for internal use. -UPB_INLINE struct upb_Message* _upb_Message_New(const upb_MiniTable* mini_table, - upb_Arena* arena) { - size_t size = upb_msg_sizeof(mini_table); - void* mem = upb_Arena_Malloc(arena, size + sizeof(upb_Message_Internal)); - if (UPB_UNLIKELY(!mem)) return NULL; - struct upb_Message* msg = - UPB_PTR_AT(mem, sizeof(upb_Message_Internal), struct upb_Message); - memset(mem, 0, size); - return msg; +UPB_INLINE bool _upb_Map_Get(const struct upb_Map* map, const void* key, + size_t key_size, void* val, size_t val_size) { + upb_value tabval; + upb_StringView k = _upb_map_tokey(key, key_size); + bool ret = upb_strtable_lookup2(&map->table, k.data, k.size, &tabval); + if (ret && val) { + _upb_map_fromvalue(tabval, val, val_size); + } + return ret; } -UPB_INLINE upb_Message_Internal* upb_Message_Getinternal( - const struct upb_Message* msg) { - ptrdiff_t size = sizeof(upb_Message_Internal); - return (upb_Message_Internal*)((char*)msg - size); +UPB_INLINE upb_MapInsertStatus _upb_Map_Insert(struct upb_Map* map, + const void* key, size_t key_size, + void* val, size_t val_size, + upb_Arena* a) { + upb_StringView strkey = _upb_map_tokey(key, key_size); + upb_value tabval = {0}; + if (!_upb_map_tovalue(val, val_size, &tabval, a)) { + return kUpb_MapInsertStatus_OutOfMemory; + } + + // TODO: add overwrite operation to minimize number of lookups. + bool removed = + upb_strtable_remove2(&map->table, strkey.data, strkey.size, NULL); + if (!upb_strtable_insert(&map->table, strkey.data, strkey.size, tabval, a)) { + return kUpb_MapInsertStatus_OutOfMemory; + } + return removed ? kUpb_MapInsertStatus_Replaced + : kUpb_MapInsertStatus_Inserted; } -UPB_INLINE upb_Message_InternalData* upb_Message_GetInternalData( - const struct upb_Message* msg) { - return upb_Message_Getinternal(msg)->internal; +UPB_INLINE size_t _upb_Map_Size(const struct upb_Map* map) { + return map->table.t.count; } -// Discards the unknown fields for this message only. -void _upb_Message_DiscardUnknown_shallow(struct upb_Message* msg); +// Strings/bytes are special-cased in maps. +extern char _upb_Map_CTypeSizeTable[12]; -// Adds unknown data (serialized protobuf data) to the given message. -// The data is copied into the message instance. -bool UPB_PRIVATE(_upb_Message_AddUnknown)(struct upb_Message* msg, - const char* data, size_t len, - upb_Arena* arena); +UPB_INLINE size_t _upb_Map_CTypeSize(upb_CType ctype) { + return _upb_Map_CTypeSizeTable[ctype]; +} -bool UPB_PRIVATE(_upb_Message_Realloc)(struct upb_Message* msg, size_t need, - upb_Arena* arena); +// Creates a new map on the given arena with this key/value type. +struct upb_Map* _upb_Map_New(upb_Arena* a, size_t key_size, size_t value_size); #ifdef __cplusplus } /* extern "C" */ #endif -#endif /* UPB_MESSAGE_INTERNAL_MESSAGE_H_ */ +#endif /* UPB_MESSAGE_INTERNAL_MAP_H_ */ #ifndef UPB_MINI_TABLE_INTERNAL_TAGGED_PTR_H_ #define UPB_MINI_TABLE_INTERNAL_TAGGED_PTR_H_ @@ -2362,37 +2335,34 @@ bool UPB_PRIVATE(_upb_Message_Realloc)(struct upb_Message* msg, size_t need, // Must be last. -typedef uintptr_t upb_TaggedMessagePtr; - #ifdef __cplusplus extern "C" { #endif // Internal-only because empty messages cannot be created by the user. -UPB_INLINE upb_TaggedMessagePtr +UPB_INLINE uintptr_t UPB_PRIVATE(_upb_TaggedMessagePtr_Pack)(struct upb_Message* ptr, bool empty) { UPB_ASSERT(((uintptr_t)ptr & 1) == 0); return (uintptr_t)ptr | (empty ? 1 : 0); } -UPB_INLINE bool UPB_PRIVATE(_upb_TaggedMessagePtr_IsEmpty)( - upb_TaggedMessagePtr ptr) { +UPB_INLINE bool UPB_PRIVATE(_upb_TaggedMessagePtr_IsEmpty)(uintptr_t ptr) { return ptr & 1; } UPB_INLINE struct upb_Message* UPB_PRIVATE(_upb_TaggedMessagePtr_GetMessage)( - upb_TaggedMessagePtr ptr) { + uintptr_t ptr) { return (struct upb_Message*)(ptr & ~(uintptr_t)1); } UPB_INLINE struct upb_Message* UPB_PRIVATE( - _upb_TaggedMessagePtr_GetNonEmptyMessage)(upb_TaggedMessagePtr ptr) { + _upb_TaggedMessagePtr_GetNonEmptyMessage)(uintptr_t ptr) { UPB_ASSERT(!UPB_PRIVATE(_upb_TaggedMessagePtr_IsEmpty)(ptr)); return UPB_PRIVATE(_upb_TaggedMessagePtr_GetMessage)(ptr); } UPB_INLINE struct upb_Message* UPB_PRIVATE( - _upb_TaggedMessagePtr_GetEmptyMessage)(upb_TaggedMessagePtr ptr) { + _upb_TaggedMessagePtr_GetEmptyMessage)(uintptr_t ptr) { UPB_ASSERT(UPB_PRIVATE(_upb_TaggedMessagePtr_IsEmpty)(ptr)); return UPB_PRIVATE(_upb_TaggedMessagePtr_GetMessage)(ptr); } @@ -2404,100 +2374,6 @@ UPB_INLINE struct upb_Message* UPB_PRIVATE( #endif /* UPB_MINI_TABLE_INTERNAL_TAGGED_PTR_H_ */ -typedef union { - bool bool_val; - float float_val; - double double_val; - int32_t int32_val; - int64_t int64_val; - uint32_t uint32_val; - uint64_t uint64_val; - const struct upb_Array* array_val; - const struct upb_Map* map_val; - const struct upb_Message* msg_val; - upb_StringView str_val; - - // EXPERIMENTAL: A tagged upb_Message*. Users must use this instead of - // msg_val if unlinked sub-messages may possibly be in use. See the - // documentation in kUpb_DecodeOption_ExperimentalAllowUnlinked for more - // information. - upb_TaggedMessagePtr tagged_msg_val; -} upb_MessageValue; - -typedef union { - struct upb_Array* array; - struct upb_Map* map; - struct upb_Message* msg; -} upb_MutableMessageValue; - -#endif /* UPB_MESSAGE_VALUE_H_ */ - -// Must be last. - -typedef struct upb_Array upb_Array; - -#ifdef __cplusplus -extern "C" { -#endif - -// Creates a new array on the given arena that holds elements of this type. -UPB_API upb_Array* upb_Array_New(upb_Arena* a, upb_CType type); - -// Returns the number of elements in the array. -UPB_API size_t upb_Array_Size(const upb_Array* arr); - -// Returns the given element, which must be within the array's current size. -UPB_API upb_MessageValue upb_Array_Get(const upb_Array* arr, size_t i); - -// Sets the given element, which must be within the array's current size. -UPB_API void upb_Array_Set(upb_Array* arr, size_t i, upb_MessageValue val); - -// Appends an element to the array. Returns false on allocation failure. -UPB_API bool upb_Array_Append(upb_Array* array, upb_MessageValue val, - upb_Arena* arena); - -// Moves elements within the array using memmove(). -// Like memmove(), the source and destination elements may be overlapping. -UPB_API void upb_Array_Move(upb_Array* array, size_t dst_idx, size_t src_idx, - size_t count); - -// Inserts one or more empty elements into the array. -// Existing elements are shifted right. -// The new elements have undefined state and must be set with `upb_Array_Set()`. -// REQUIRES: `i <= upb_Array_Size(arr)` -UPB_API bool upb_Array_Insert(upb_Array* array, size_t i, size_t count, - upb_Arena* arena); - -// Deletes one or more elements from the array. -// Existing elements are shifted left. -// REQUIRES: `i + count <= upb_Array_Size(arr)` -UPB_API void upb_Array_Delete(upb_Array* array, size_t i, size_t count); - -// Changes the size of a vector. New elements are initialized to NULL/0. -// Returns false on allocation failure. -UPB_API bool upb_Array_Resize(upb_Array* array, size_t size, upb_Arena* arena); - -// Returns pointer to array data. -UPB_API const void* upb_Array_DataPtr(const upb_Array* arr); - -// Returns mutable pointer to array data. -UPB_API void* upb_Array_MutableDataPtr(upb_Array* arr); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - - -#endif /* UPB_MESSAGE_ARRAY_H_ */ - -#ifndef UPB_MESSAGE_INTERNAL_ACCESSORS_H_ -#define UPB_MESSAGE_INTERNAL_ACCESSORS_H_ - -#include -#include -#include - - // Must be last. #if defined(__GNUC__) && !defined(__clang__) @@ -2786,8 +2662,8 @@ UPB_INLINE void _upb_Message_AssertMapIsUntagged( UPB_UNUSED(msg); UPB_PRIVATE(_upb_MiniTableField_CheckIsMap)(field); #ifndef NDEBUG - upb_TaggedMessagePtr default_val = 0; - upb_TaggedMessagePtr tagged; + uintptr_t default_val = 0; + uintptr_t tagged; _upb_Message_GetNonExtensionField(msg, field, &default_val, &tagged); UPB_ASSERT(!UPB_PRIVATE(_upb_TaggedMessagePtr_IsEmpty)(tagged)); #endif @@ -2821,6 +2697,127 @@ UPB_INLINE struct upb_Map* _upb_Message_GetOrCreateMutableMap( #endif // UPB_MESSAGE_INTERNAL_ACCESSORS_H_ +#ifndef UPB_MESSAGE_INTERNAL_ARRAY_H_ +#define UPB_MESSAGE_INTERNAL_ARRAY_H_ + +#include + + +// Must be last. + +#define _UPB_ARRAY_MASK_IMM 0x4 // Frozen/immutable bit. +#define _UPB_ARRAY_MASK_LG2 0x3 // Encoded elem size. +#define _UPB_ARRAY_MASK_ALL (_UPB_ARRAY_MASK_IMM | _UPB_ARRAY_MASK_LG2) + +#ifdef __cplusplus +extern "C" { +#endif + +// LINT.IfChange(struct_definition) +// Our internal representation for repeated fields. +struct upb_Array { + // This is a tagged pointer. Bits #0 and #1 encode the elem size as follows: + // 0 maps to elem size 1 + // 1 maps to elem size 4 + // 2 maps to elem size 8 + // 3 maps to elem size 16 + // + // Bit #2 contains the frozen/immutable flag (currently unimplemented). + uintptr_t data; + + size_t UPB_ONLYBITS(size); // The number of elements in the array. + size_t UPB_PRIVATE(capacity); // Allocated storage. Measured in elements. +}; + +UPB_INLINE void UPB_PRIVATE(_upb_Array_SetTaggedPtr)(struct upb_Array* array, + void* data, size_t lg2) { + UPB_ASSERT(lg2 != 1); + UPB_ASSERT(lg2 <= 4); + const size_t bits = lg2 - (lg2 != 0); + array->data = (uintptr_t)data | bits; +} + +UPB_INLINE size_t +UPB_PRIVATE(_upb_Array_ElemSizeLg2)(const struct upb_Array* array) { + const size_t bits = array->data & _UPB_ARRAY_MASK_LG2; + const size_t lg2 = bits + (bits != 0); + return lg2; +} + +UPB_INLINE const void* _upb_array_constptr(const struct upb_Array* array) { + UPB_PRIVATE(_upb_Array_ElemSizeLg2)(array); // Check assertions. + return (void*)(array->data & ~(uintptr_t)_UPB_ARRAY_MASK_ALL); +} + +UPB_INLINE void* _upb_array_ptr(struct upb_Array* array) { + return (void*)_upb_array_constptr(array); +} + +UPB_INLINE struct upb_Array* UPB_PRIVATE(_upb_Array_New)(upb_Arena* arena, + size_t init_capacity, + int elem_size_lg2) { + UPB_ASSERT(elem_size_lg2 != 1); + UPB_ASSERT(elem_size_lg2 <= 4); + const size_t array_size = + UPB_ALIGN_UP(sizeof(struct upb_Array), UPB_MALLOC_ALIGN); + const size_t bytes = array_size + (init_capacity << elem_size_lg2); + struct upb_Array* array = (struct upb_Array*)upb_Arena_Malloc(arena, bytes); + if (!array) return NULL; + UPB_PRIVATE(_upb_Array_SetTaggedPtr) + (array, UPB_PTR_AT(array, array_size, void), elem_size_lg2); + array->UPB_ONLYBITS(size) = 0; + array->UPB_PRIVATE(capacity) = init_capacity; + return array; +} + +// Resizes the capacity of the array to be at least min_size. +bool UPB_PRIVATE(_upb_Array_Realloc)(struct upb_Array* array, size_t min_size, + upb_Arena* arena); + +UPB_INLINE bool UPB_PRIVATE(_upb_Array_Reserve)(struct upb_Array* array, + size_t size, upb_Arena* arena) { + if (array->UPB_PRIVATE(capacity) < size) + return UPB_PRIVATE(_upb_Array_Realloc)(array, size, arena); + return true; +} + +// Resize without initializing new elements. +UPB_INLINE bool _upb_Array_ResizeUninitialized(struct upb_Array* array, + size_t size, upb_Arena* arena) { + UPB_ASSERT(size <= array->UPB_ONLYBITS(size) || + arena); // Allow NULL arena when shrinking. + if (!UPB_PRIVATE(_upb_Array_Reserve)(array, size, arena)) return false; + array->UPB_ONLYBITS(size) = size; + return true; +} + +// This function is intended for situations where elem_size is compile-time +// constant or a known expression of the form (1 << lg2), so that the expression +// i*elem_size does not result in an actual multiplication. +UPB_INLINE void UPB_PRIVATE(_upb_Array_Set)(struct upb_Array* array, size_t i, + const void* data, + size_t elem_size) { + UPB_ASSERT(i < array->UPB_ONLYBITS(size)); + UPB_ASSERT(elem_size == 1U << UPB_PRIVATE(_upb_Array_ElemSizeLg2)(array)); + char* arr_data = (char*)_upb_array_ptr(array); + memcpy(arr_data + (i * elem_size), data, elem_size); +} + +// LINT.ThenChange( +// GoogleInternalName1, +//) + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#undef _UPB_ARRAY_MASK_IMM +#undef _UPB_ARRAY_MASK_LG2 +#undef _UPB_ARRAY_MASK_ALL + + +#endif /* UPB_MESSAGE_INTERNAL_ARRAY_H_ */ + #ifndef UPB_MESSAGE_MAP_H_ #define UPB_MESSAGE_MAP_H_ From f8d7885236f60a51737ea359ac39abb8f96f9ed7 Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Mon, 8 Jan 2024 15:44:20 -0800 Subject: [PATCH 209/255] Add SPLIT test coverage to :analyze_profile_proto_test and disable force_split. PiperOrigin-RevId: 596723248 --- .../cpp/tools/analyze_profile_proto_test.cc | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/google/protobuf/compiler/cpp/tools/analyze_profile_proto_test.cc b/src/google/protobuf/compiler/cpp/tools/analyze_profile_proto_test.cc index 31a1e7aaee035..35eab5bb0cf0e 100644 --- a/src/google/protobuf/compiler/cpp/tools/analyze_profile_proto_test.cc +++ b/src/google/protobuf/compiler/cpp/tools/analyze_profile_proto_test.cc @@ -95,6 +95,32 @@ TEST(AnalyzeProfileProtoTest, ChildLikelyPresentAndUsed) { " string optional_string: INLINE\n"); } +TEST(AnalyzeProfileProtoTest, UnlikelyPresent) { + AccessInfo info = ParseTextOrDie(R"pb( + language: "cpp" + message { + name: "google::protobuf::compiler::tools::AnalyzeThis" + count: 100 + field { name: "id" getters_count: 0 } + field { name: "optional_string" getters_count: 0 } + field { name: "optional_child" getters_count: 100 } + field { name: "repeated_string" getters_count: 0 } + field { name: "repeated_child" getters_count: 0 } + field { name: "nested" getters_count: 0 } + } + )pb"); + AnalyzeProfileProtoOptions options; + options.print_unused_threshold = false; + options.pool = DescriptorPool::generated_pool(); + EXPECT_STREQ(AnalyzeToText(info, options).c_str(), + "Message google::protobuf::compiler::tools::AnalyzeThis\n" + " int32 id: SPLIT\n" + " string optional_string: SPLIT\n" + " string[] repeated_string: SPLIT\n" + " AnalyzeChild[] repeated_child: SPLIT\n" + " Nested nested: SPLIT\n"); +} + TEST(AnalyzeProfileProtoTest, ChildLikelyPresentAndRarelyUsed) { // Note that the logic pics a 50th percentile threshold which we need to // exceed, making testing slightly awkward From c16e0485c28c4434d4dc447b26fae1f27b52d552 Mon Sep 17 00:00:00 2001 From: Alyssa Haroldsen Date: Mon, 8 Jan 2024 16:32:03 -0800 Subject: [PATCH 210/255] Refactor oneof/enum naming functions for consistency PiperOrigin-RevId: 596734937 --- src/google/protobuf/compiler/rust/BUILD.bazel | 3 +- src/google/protobuf/compiler/rust/enum.cc | 47 +------------ src/google/protobuf/compiler/rust/enum.h | 8 --- .../protobuf/compiler/rust/enum_test.cc | 35 ---------- src/google/protobuf/compiler/rust/naming.cc | 67 +++++++++++++++++++ src/google/protobuf/compiler/rust/naming.h | 18 +++++ .../protobuf/compiler/rust/naming_test.cc | 35 ++++++++++ src/google/protobuf/compiler/rust/oneof.cc | 36 +++------- 8 files changed, 133 insertions(+), 116 deletions(-) diff --git a/src/google/protobuf/compiler/rust/BUILD.bazel b/src/google/protobuf/compiler/rust/BUILD.bazel index 6682c2ec20d36..52721ad2669a8 100644 --- a/src/google/protobuf/compiler/rust/BUILD.bazel +++ b/src/google/protobuf/compiler/rust/BUILD.bazel @@ -120,8 +120,8 @@ cc_library( strip_include_prefix = "/src", deps = [ ":context", + ":naming", "//src/google/protobuf", - "//src/google/protobuf/compiler/cpp:names_internal", "@com_google_absl//absl/container:flat_hash_map", "@com_google_absl//absl/container:flat_hash_set", "@com_google_absl//absl/log:absl_check", @@ -151,6 +151,7 @@ cc_library( ":context", "//src/google/protobuf", "//src/google/protobuf/compiler:code_generator", + "//src/google/protobuf/compiler/cpp:names_internal", "@com_google_absl//absl/log:absl_log", "@com_google_absl//absl/strings", ], diff --git a/src/google/protobuf/compiler/rust/enum.cc b/src/google/protobuf/compiler/rust/enum.cc index de9382a99aea1..2f4b08da17b4e 100644 --- a/src/google/protobuf/compiler/rust/enum.cc +++ b/src/google/protobuf/compiler/rust/enum.cc @@ -24,8 +24,8 @@ #include "absl/strings/string_view.h" #include "absl/strings/strip.h" #include "absl/types/span.h" -#include "google/protobuf/compiler/cpp/helpers.h" #include "google/protobuf/compiler/rust/context.h" +#include "google/protobuf/compiler/rust/naming.h" #include "google/protobuf/descriptor.h" namespace google { @@ -34,11 +34,6 @@ namespace compiler { namespace rust { namespace { - -std::string EnumName(const EnumDescriptor& desc) { - return cpp::UnderscoresToCamelCase(desc.name(), /*cap first letter=*/true); -} - // Constructs input for `EnumValues` from an enum descriptor. std::vector> EnumValuesInput( const EnumDescriptor& desc) { @@ -126,46 +121,8 @@ std::vector EnumValues( return result; } -std::string CamelToSnakeCase(absl::string_view input) { - std::string result; - result.reserve(input.size() + 4); // No reallocation for 4 _ - bool is_first_character = true; - bool last_char_was_underscore = false; - for (const char c : input) { - if (!is_first_character && absl::ascii_isupper(c) && - !last_char_was_underscore) { - result += '_'; - } - last_char_was_underscore = c == '_'; - result += absl::ascii_tolower(c); - is_first_character = false; - } - return result; -} - -std::string ScreamingSnakeToUpperCamelCase(absl::string_view input) { - std::string result; - bool cap_next_letter = true; - for (const char c : input) { - if (absl::ascii_isalpha(c)) { - if (cap_next_letter) { - result += absl::ascii_toupper(c); - } else { - result += absl::ascii_tolower(c); - } - cap_next_letter = false; - } else if (absl::ascii_isdigit(c)) { - result += c; - cap_next_letter = true; - } else { - cap_next_letter = true; - } - } - return result; -} - void GenerateEnumDefinition(Context& ctx, const EnumDescriptor& desc) { - std::string name = EnumName(desc); + std::string name = EnumRsName(desc); ABSL_CHECK(desc.value_count() > 0); std::vector values = EnumValues(desc.name(), EnumValuesInput(desc)); diff --git a/src/google/protobuf/compiler/rust/enum.h b/src/google/protobuf/compiler/rust/enum.h index 0ef2d689f7ff4..4c04b51cb8b86 100644 --- a/src/google/protobuf/compiler/rust/enum.h +++ b/src/google/protobuf/compiler/rust/enum.h @@ -40,14 +40,6 @@ std::vector EnumValues( absl::string_view enum_name, absl::Span> values); -// TODO: Unify these with other case-conversion functions. - -// Converts an UpperCamel or lowerCamel string to a snake_case string. -std::string CamelToSnakeCase(absl::string_view input); - -// Converts a SCREAMING_SNAKE_CASE string to an UpperCamelCase string. -std::string ScreamingSnakeToUpperCamelCase(absl::string_view input); - } // namespace rust } // namespace compiler } // namespace protobuf diff --git a/src/google/protobuf/compiler/rust/enum_test.cc b/src/google/protobuf/compiler/rust/enum_test.cc index e481c1854d013..1f3202cbce395 100644 --- a/src/google/protobuf/compiler/rust/enum_test.cc +++ b/src/google/protobuf/compiler/rust/enum_test.cc @@ -8,49 +8,14 @@ namespace { -using ::google::protobuf::compiler::rust::CamelToSnakeCase; using ::google::protobuf::compiler::rust::EnumValues; using ::google::protobuf::compiler::rust::RustEnumValue; -using ::google::protobuf::compiler::rust::ScreamingSnakeToUpperCamelCase; using ::testing::AllOf; using ::testing::ElementsAre; using ::testing::Eq; using ::testing::Field; using ::testing::IsEmpty; -TEST(EnumTest, CamelToSnakeCase) { - // TODO: Review this behavior. - EXPECT_EQ(CamelToSnakeCase("CamelCase"), "camel_case"); - EXPECT_EQ(CamelToSnakeCase("_CamelCase"), "_camel_case"); - EXPECT_EQ(CamelToSnakeCase("camelCase"), "camel_case"); - EXPECT_EQ(CamelToSnakeCase("Number2020"), "number2020"); - EXPECT_EQ(CamelToSnakeCase("Number_2020"), "number_2020"); - EXPECT_EQ(CamelToSnakeCase("camelCase_"), "camel_case_"); - EXPECT_EQ(CamelToSnakeCase("CamelCaseTrio"), "camel_case_trio"); - EXPECT_EQ(CamelToSnakeCase("UnderIn_Middle"), "under_in_middle"); - EXPECT_EQ(CamelToSnakeCase("Camel_Case"), "camel_case"); - EXPECT_EQ(CamelToSnakeCase("Camel__Case"), "camel__case"); - EXPECT_EQ(CamelToSnakeCase("CAMEL_CASE"), "c_a_m_e_l_c_a_s_e"); -} - -TEST(EnumTest, ScreamingSnakeToUpperCamelCase) { - // TODO: Review this behavior. - EXPECT_EQ(ScreamingSnakeToUpperCamelCase("CAMEL_CASE"), "CamelCase"); - EXPECT_EQ(ScreamingSnakeToUpperCamelCase("NUMBER2020"), "Number2020"); - EXPECT_EQ(ScreamingSnakeToUpperCamelCase("NUMBER_2020"), "Number2020"); - EXPECT_EQ(ScreamingSnakeToUpperCamelCase("FOO_4040_BAR"), "Foo4040Bar"); - EXPECT_EQ(ScreamingSnakeToUpperCamelCase("FOO_4040bar"), "Foo4040Bar"); - EXPECT_EQ(ScreamingSnakeToUpperCamelCase("_CAMEL_CASE"), "CamelCase"); - - // This function doesn't currently preserve prefix/suffix underscore, - // while CamelToSnakeCase does. - EXPECT_EQ(ScreamingSnakeToUpperCamelCase("CAMEL_CASE_"), "CamelCase"); - EXPECT_EQ(ScreamingSnakeToUpperCamelCase("camel_case"), "CamelCase"); - EXPECT_EQ(ScreamingSnakeToUpperCamelCase("CAMEL_CASE_TRIO"), "CamelCaseTrio"); - EXPECT_EQ(ScreamingSnakeToUpperCamelCase("UNDER_IN__MIDDLE"), - "UnderInMiddle"); -} - template auto EnumValue(absl::string_view name, int32_t number, Aliases aliases) { return AllOf(Field("name", &RustEnumValue::name, Eq(name)), diff --git a/src/google/protobuf/compiler/rust/naming.cc b/src/google/protobuf/compiler/rust/naming.cc index 8f6258ec238b0..e488bef029e89 100644 --- a/src/google/protobuf/compiler/rust/naming.cc +++ b/src/google/protobuf/compiler/rust/naming.cc @@ -11,6 +11,7 @@ #include #include "absl/log/absl_log.h" +#include "absl/strings/ascii.h" #include "absl/strings/str_cat.h" #include "absl/strings/str_join.h" #include "absl/strings/str_replace.h" @@ -18,6 +19,7 @@ #include "absl/strings/string_view.h" #include "absl/strings/substitute.h" #include "google/protobuf/compiler/code_generator.h" +#include "google/protobuf/compiler/cpp/helpers.h" #include "google/protobuf/compiler/rust/context.h" #include "google/protobuf/descriptor.h" @@ -238,6 +240,71 @@ std::string FieldInfoComment(Context& ctx, const FieldDescriptor& field) { return comment; } +std::string EnumRsName(const EnumDescriptor& desc) { + return SnakeToUpperCamelCase(desc.name()); +} + +std::string OneofViewEnumRsName(const OneofDescriptor& oneof) { + return SnakeToUpperCamelCase(oneof.name()); +} + +std::string OneofMutEnumRsName(const OneofDescriptor& oneof) { + return SnakeToUpperCamelCase(oneof.name()) + "Mut"; +} + +std::string OneofCaseEnumRsName(const OneofDescriptor& oneof) { + // Note: This is the name used for the cpp Case enum, we use it for both + // the Rust Case enum as well as for the cpp case enum in the cpp thunk. + return SnakeToUpperCamelCase(oneof.name()) + "Case"; +} + +std::string OneofCaseRsName(const FieldDescriptor& oneof_field) { + return SnakeToUpperCamelCase(oneof_field.name()); +} + +std::string CamelToSnakeCase(absl::string_view input) { + std::string result; + result.reserve(input.size() + 4); // No reallocation for 4 _ + bool is_first_character = true; + bool last_char_was_underscore = false; + for (const char c : input) { + if (!is_first_character && absl::ascii_isupper(c) && + !last_char_was_underscore) { + result += '_'; + } + last_char_was_underscore = c == '_'; + result += absl::ascii_tolower(c); + is_first_character = false; + } + return result; +} + +std::string SnakeToUpperCamelCase(absl::string_view input) { + return cpp::UnderscoresToCamelCase(input, /*cap first letter=*/true); +} + +std::string ScreamingSnakeToUpperCamelCase(absl::string_view input) { + std::string result; + result.reserve(input.size()); + bool cap_next_letter = true; + for (const char c : input) { + if (absl::ascii_isalpha(c)) { + if (cap_next_letter) { + result += absl::ascii_toupper(c); + } else { + result += absl::ascii_tolower(c); + } + cap_next_letter = false; + } else if (absl::ascii_isdigit(c)) { + result += c; + cap_next_letter = true; + } else { + cap_next_letter = true; + } + } + return result; +} + } // namespace rust } // namespace compiler } // namespace protobuf diff --git a/src/google/protobuf/compiler/rust/naming.h b/src/google/protobuf/compiler/rust/naming.h index 154e9024c26a1..306bcbb831a62 100644 --- a/src/google/protobuf/compiler/rust/naming.h +++ b/src/google/protobuf/compiler/rust/naming.h @@ -35,6 +35,13 @@ std::string ThunkName(Context& ctx, const Descriptor& msg, std::string PrimitiveRsTypeName(const FieldDescriptor& field); +std::string EnumRsName(const EnumDescriptor& desc); + +std::string OneofViewEnumRsName(const OneofDescriptor& oneof); +std::string OneofMutEnumRsName(const OneofDescriptor& oneof); +std::string OneofCaseEnumRsName(const OneofDescriptor& oneof); +std::string OneofCaseRsName(const FieldDescriptor& oneof_field); + std::string FieldInfoComment(Context& ctx, const FieldDescriptor& field); std::string RustModule(Context& ctx, const Descriptor& msg); @@ -42,6 +49,17 @@ std::string RustInternalModuleName(Context& ctx, const FileDescriptor& file); std::string GetCrateRelativeQualifiedPath(Context& ctx, const Descriptor& msg); +// TODO: Unify these with other case-conversion functions. + +// Converts an UpperCamel or lowerCamel string to a snake_case string. +std::string CamelToSnakeCase(absl::string_view input); + +// Converts a snake_case string to an UpperCamelCase string. +std::string SnakeToUpperCamelCase(absl::string_view input); + +// Converts a SCREAMING_SNAKE_CASE string to an UpperCamelCase string. +std::string ScreamingSnakeToUpperCamelCase(absl::string_view input); + } // namespace rust } // namespace compiler } // namespace protobuf diff --git a/src/google/protobuf/compiler/rust/naming_test.cc b/src/google/protobuf/compiler/rust/naming_test.cc index a9294d00acec7..f50f217e44c92 100644 --- a/src/google/protobuf/compiler/rust/naming_test.cc +++ b/src/google/protobuf/compiler/rust/naming_test.cc @@ -8,11 +8,13 @@ #include "google/protobuf/descriptor.h" #include "google/protobuf/io/zero_copy_stream_impl_lite.h" +using google::protobuf::compiler::rust::CamelToSnakeCase; using google::protobuf::compiler::rust::Context; using google::protobuf::compiler::rust::Kernel; using google::protobuf::compiler::rust::Options; using google::protobuf::compiler::rust::RustGeneratorContext; using google::protobuf::compiler::rust::RustInternalModuleName; +using google::protobuf::compiler::rust::ScreamingSnakeToUpperCamelCase; using google::protobuf::io::Printer; using google::protobuf::io::StringOutputStream; @@ -34,4 +36,37 @@ TEST(RustProtoNaming, RustInternalModuleName) { EXPECT_EQ(RustInternalModuleName(c, *fd), "strong__bad_slol"); } +TEST(RustProtoNaming, CamelToSnakeCase) { + // TODO: Review this behavior. + EXPECT_EQ(CamelToSnakeCase("CamelCase"), "camel_case"); + EXPECT_EQ(CamelToSnakeCase("_CamelCase"), "_camel_case"); + EXPECT_EQ(CamelToSnakeCase("camelCase"), "camel_case"); + EXPECT_EQ(CamelToSnakeCase("Number2020"), "number2020"); + EXPECT_EQ(CamelToSnakeCase("Number_2020"), "number_2020"); + EXPECT_EQ(CamelToSnakeCase("camelCase_"), "camel_case_"); + EXPECT_EQ(CamelToSnakeCase("CamelCaseTrio"), "camel_case_trio"); + EXPECT_EQ(CamelToSnakeCase("UnderIn_Middle"), "under_in_middle"); + EXPECT_EQ(CamelToSnakeCase("Camel_Case"), "camel_case"); + EXPECT_EQ(CamelToSnakeCase("Camel__Case"), "camel__case"); + EXPECT_EQ(CamelToSnakeCase("CAMEL_CASE"), "c_a_m_e_l_c_a_s_e"); +} + +TEST(RustProtoNaming, ScreamingSnakeToUpperCamelCase) { + // TODO: Review this behavior. + EXPECT_EQ(ScreamingSnakeToUpperCamelCase("CAMEL_CASE"), "CamelCase"); + EXPECT_EQ(ScreamingSnakeToUpperCamelCase("NUMBER2020"), "Number2020"); + EXPECT_EQ(ScreamingSnakeToUpperCamelCase("NUMBER_2020"), "Number2020"); + EXPECT_EQ(ScreamingSnakeToUpperCamelCase("FOO_4040_BAR"), "Foo4040Bar"); + EXPECT_EQ(ScreamingSnakeToUpperCamelCase("FOO_4040bar"), "Foo4040Bar"); + EXPECT_EQ(ScreamingSnakeToUpperCamelCase("_CAMEL_CASE"), "CamelCase"); + + // This function doesn't currently preserve prefix/suffix underscore, + // while CamelToSnakeCase does. + EXPECT_EQ(ScreamingSnakeToUpperCamelCase("CAMEL_CASE_"), "CamelCase"); + EXPECT_EQ(ScreamingSnakeToUpperCamelCase("camel_case"), "CamelCase"); + EXPECT_EQ(ScreamingSnakeToUpperCamelCase("CAMEL_CASE_TRIO"), "CamelCaseTrio"); + EXPECT_EQ(ScreamingSnakeToUpperCamelCase("UNDER_IN__MIDDLE"), + "UnderInMiddle"); +} + } // namespace diff --git a/src/google/protobuf/compiler/rust/oneof.cc b/src/google/protobuf/compiler/rust/oneof.cc index 4b08f4571c54d..1408bfcd9476b 100644 --- a/src/google/protobuf/compiler/rust/oneof.cc +++ b/src/google/protobuf/compiler/rust/oneof.cc @@ -74,24 +74,6 @@ namespace rust { // } namespace { -std::string ToCamelCase(absl::string_view name) { - return cpp::UnderscoresToCamelCase(name, /* upper initial letter */ true); -} - -std::string OneofViewEnumRsName(const OneofDescriptor& oneof) { - return ToCamelCase(oneof.name()); -} - -std::string OneofMutEnumRsName(const OneofDescriptor& oneof) { - return ToCamelCase(oneof.name()) + "Mut"; -} - -std::string OneofCaseEnumName(const OneofDescriptor& oneof) { - // Note: This is the name used for the cpp Case enum, we use it for both - // the Rust Case enum as well as for the cpp case enum in the cpp thunk. - return ToCamelCase(oneof.name()) + "Case"; -} - std::string RsTypeNameView(Context& ctx, const FieldDescriptor& field) { if (field.options().has_ctype()) { return ""; // TODO: b/308792377 - ctype fields not supported yet. @@ -177,7 +159,7 @@ void GenerateOneofDefinition(Context& ctx, const OneofDescriptor& oneof) { if (rs_type.empty()) { continue; } - ctx.Emit({{"name", ToCamelCase(field.name())}, + ctx.Emit({{"name", OneofCaseRsName(field)}, {"type", rs_type}, {"number", std::to_string(field.number())}}, R"rs($name$($type$) = $number$, @@ -192,7 +174,7 @@ void GenerateOneofDefinition(Context& ctx, const OneofDescriptor& oneof) { if (rs_type.empty()) { continue; } - ctx.Emit({{"name", ToCamelCase(field.name())}, + ctx.Emit({{"name", OneofCaseRsName(field)}, {"type", rs_type}, {"number", std::to_string(field.number())}}, R"rs($name$($type$) = $number$, @@ -230,12 +212,12 @@ void GenerateOneofDefinition(Context& ctx, const OneofDescriptor& oneof) { // Note: This enum is used as the Thunk return type for getting which case is // used: it exactly matches the generate case enum that both cpp and upb use. - ctx.Emit({{"case_enum_name", OneofCaseEnumName(oneof)}, + ctx.Emit({{"case_enum_name", OneofCaseEnumRsName(oneof)}, {"cases", [&] { for (int i = 0; i < oneof.field_count(); ++i) { auto& field = *oneof.field(i); - ctx.Emit({{"name", ToCamelCase(field.name())}, + ctx.Emit({{"name", OneofCaseRsName(field)}, {"number", std::to_string(field.number())}}, R"rs($name$ = $number$, )rs"); @@ -260,7 +242,7 @@ void GenerateOneofAccessors(Context& ctx, const OneofDescriptor& oneof) { {{"oneof_name", oneof.name()}, {"view_enum_name", OneofViewEnumRsName(oneof)}, {"mut_enum_name", OneofMutEnumRsName(oneof)}, - {"case_enum_name", OneofCaseEnumName(oneof)}, + {"case_enum_name", OneofCaseEnumRsName(oneof)}, {"view_cases", [&] { for (int i = 0; i < oneof.field_count(); ++i) { @@ -271,7 +253,7 @@ void GenerateOneofAccessors(Context& ctx, const OneofDescriptor& oneof) { } ctx.Emit( { - {"case", ToCamelCase(field.name())}, + {"case", OneofCaseRsName(field)}, {"rs_getter", field.name()}, {"type", rs_type}, }, @@ -290,7 +272,7 @@ void GenerateOneofAccessors(Context& ctx, const OneofDescriptor& oneof) { continue; } ctx.Emit( - {{"case", ToCamelCase(field.name())}, + {{"case", OneofCaseRsName(field)}, {"rs_mut_getter", field.name() + "_mut"}, {"type", rs_type}, @@ -341,7 +323,7 @@ void GenerateOneofAccessors(Context& ctx, const OneofDescriptor& oneof) { void GenerateOneofExternC(Context& ctx, const OneofDescriptor& oneof) { ctx.Emit( { - {"case_enum_rs_name", OneofCaseEnumName(oneof)}, + {"case_enum_rs_name", OneofCaseEnumRsName(oneof)}, {"case_thunk", ThunkName(ctx, oneof, "case")}, }, R"rs( @@ -353,7 +335,7 @@ void GenerateOneofThunkCc(Context& ctx, const OneofDescriptor& oneof) { ctx.Emit( { {"oneof_name", oneof.name()}, - {"case_enum_name", OneofCaseEnumName(oneof)}, + {"case_enum_name", OneofCaseEnumRsName(oneof)}, {"case_thunk", ThunkName(ctx, oneof, "case")}, {"QualifiedMsg", cpp::QualifiedClassName(oneof.containing_type())}, }, From 17b0f3f6a43289d694141370a4d97d5925d86e28 Mon Sep 17 00:00:00 2001 From: Alyssa Haroldsen Date: Mon, 8 Jan 2024 16:50:13 -0800 Subject: [PATCH 211/255] Add enum qualified path naming fns PiperOrigin-RevId: 596738896 --- src/google/protobuf/compiler/rust/naming.cc | 77 +++++++++++---------- src/google/protobuf/compiler/rust/naming.h | 12 ++++ 2 files changed, 53 insertions(+), 36 deletions(-) diff --git a/src/google/protobuf/compiler/rust/naming.cc b/src/google/protobuf/compiler/rust/naming.cc index e488bef029e89..ea084e6b09df8 100644 --- a/src/google/protobuf/compiler/rust/naming.cc +++ b/src/google/protobuf/compiler/rust/naming.cc @@ -121,6 +121,38 @@ std::string ThunkMapOrRepeated(Context& ctx, const FieldDescriptor& field, return thunkName; } +std::string RustModule(Context& ctx, const FileDescriptor& file, + const Descriptor* containing_type) { + std::vector modules; + + std::vector package_modules = + absl::StrSplit(file.package(), '.', absl::SkipEmpty()); + + modules.insert(modules.begin(), package_modules.begin(), + package_modules.end()); + + // Innermost to outermost order. + std::vector modules_from_containing_types; + const Descriptor* parent = containing_type; + while (parent != nullptr) { + modules_from_containing_types.push_back(absl::StrCat(parent->name(), "_")); + parent = parent->containing_type(); + } + + // Add the modules from containing messages (rbegin/rend to get them in outer + // to inner order). + modules.insert(modules.end(), modules_from_containing_types.rbegin(), + modules_from_containing_types.rend()); + + // If there is any modules at all, push an empty string on the end so that + // we get the trailing :: + if (!modules.empty()) { + modules.push_back(""); + } + + return absl::StrJoin(modules, "::"); +} + } // namespace std::string ThunkName(Context& ctx, const FieldDescriptor& field, @@ -176,44 +208,12 @@ std::string PrimitiveRsTypeName(const FieldDescriptor& field) { return ""; } -// Constructs a string of the Rust modules which will contain the message. -// -// Example: Given a message 'NestedMessage' which is defined in package 'x.y' -// which is inside 'ParentMessage', the message will be placed in the -// x::y::ParentMessage_ Rust module, so this function will return the string -// "x::y::ParentMessage_::". -// -// If the message has no package and no containing messages then this returns -// empty string. std::string RustModule(Context& ctx, const Descriptor& msg) { - std::vector modules; - - std::vector package_modules = - absl::StrSplit(msg.file()->package(), '.', absl::SkipEmpty()); - - modules.insert(modules.begin(), package_modules.begin(), - package_modules.end()); - - // Innermost to outermost order. - std::vector modules_from_containing_types; - const Descriptor* parent = msg.containing_type(); - while (parent != nullptr) { - modules_from_containing_types.push_back(absl::StrCat(parent->name(), "_")); - parent = parent->containing_type(); - } - - // Add the modules from containing messages (rbegin/rend to get them in outer - // to inner order). - modules.insert(modules.end(), modules_from_containing_types.rbegin(), - modules_from_containing_types.rend()); - - // If there is any modules at all, push an empty string on the end so that - // we get the trailing :: - if (!modules.empty()) { - modules.push_back(""); - } + return RustModule(ctx, *msg.file(), msg.containing_type()); +} - return absl::StrJoin(modules, "::"); +std::string RustModule(Context& ctx, const EnumDescriptor& enum_) { + return RustModule(ctx, *enum_.file(), enum_.containing_type()); } std::string RustInternalModuleName(Context& ctx, const FileDescriptor& file) { @@ -225,6 +225,11 @@ std::string GetCrateRelativeQualifiedPath(Context& ctx, const Descriptor& msg) { return absl::StrCat(RustModule(ctx, msg), msg.name()); } +std::string GetCrateRelativeQualifiedPath(Context& ctx, + const EnumDescriptor& enum_) { + return absl::StrCat(RustModule(ctx, enum_), EnumRsName(enum_)); +} + std::string FieldInfoComment(Context& ctx, const FieldDescriptor& field) { absl::string_view label = field.is_repeated() ? "repeated" : "optional"; std::string comment = absl::StrCat(field.name(), ": ", label, " ", diff --git a/src/google/protobuf/compiler/rust/naming.h b/src/google/protobuf/compiler/rust/naming.h index 306bcbb831a62..46b2e951e30fc 100644 --- a/src/google/protobuf/compiler/rust/naming.h +++ b/src/google/protobuf/compiler/rust/naming.h @@ -44,10 +44,22 @@ std::string OneofCaseRsName(const FieldDescriptor& oneof_field); std::string FieldInfoComment(Context& ctx, const FieldDescriptor& field); +// Constructs a string of the Rust modules which will contain the message. +// +// Example: Given a message 'NestedMessage' which is defined in package 'x.y' +// which is inside 'ParentMessage', the message will be placed in the +// x::y::ParentMessage_ Rust module, so this function will return the string +// "x::y::ParentMessage_::". +// +// If the message has no package and no containing messages then this returns +// empty string. std::string RustModule(Context& ctx, const Descriptor& msg); +std::string RustModule(Context& ctx, const EnumDescriptor& enum_); std::string RustInternalModuleName(Context& ctx, const FileDescriptor& file); std::string GetCrateRelativeQualifiedPath(Context& ctx, const Descriptor& msg); +std::string GetCrateRelativeQualifiedPath(Context& ctx, + const EnumDescriptor& enum_); // TODO: Unify these with other case-conversion functions. From 1eab5a0237b28b8242801912877ebb513eafbb17 Mon Sep 17 00:00:00 2001 From: Alyssa Haroldsen Date: Mon, 8 Jan 2024 18:50:28 -0800 Subject: [PATCH 212/255] Generate `pub use` for imported enums PiperOrigin-RevId: 596762218 --- rust/test/BUILD | 6 ++- rust/test/nested.proto | 7 +++ rust/test/no_package.proto | 13 +++++- rust/test/no_package_import.proto | 11 ++++- rust/test/no_package_other.proto | 11 ++++- rust/test/package.proto | 4 ++ rust/test/package_import.proto | 4 ++ rust/test/package_other.proto | 4 ++ rust/test/package_other_different.proto | 4 ++ rust/test/shared/BUILD | 8 ++-- ..._messages_test.rs => nested_types_test.rs} | 9 +++- rust/test/shared/package_test.rs | 37 ++++++++++++---- rust/test/shared/simple_nested_test.rs | 11 ++++- .../protobuf/compiler/rust/generator.cc | 43 +++++++++++++------ 14 files changed, 138 insertions(+), 34 deletions(-) rename rust/test/shared/{nested_messages_test.rs => nested_types_test.rs} (66%) diff --git a/rust/test/BUILD b/rust/test/BUILD index 2541732ebe51e..d53b094278909 100644 --- a/rust/test/BUILD +++ b/rust/test/BUILD @@ -236,6 +236,7 @@ proto_library( name = "no_package_import_proto", testonly = True, srcs = ["no_package_import.proto"], + deps = ["//devtools/staticanalysis/pipeline/analyzers/proto_best_practices/proto:optouts_proto"], ) proto_library( @@ -246,7 +247,10 @@ proto_library( "no_package_other.proto", ], exports = [":no_package_import_proto"], - deps = [":no_package_import_proto"], + deps = [ + ":no_package_import_proto", + "//devtools/staticanalysis/pipeline/analyzers/proto_best_practices/proto:optouts_proto", + ], ) cc_proto_library( diff --git a/rust/test/nested.proto b/rust/test/nested.proto index 59aee229db273..40348efca4ef6 100644 --- a/rust/test/nested.proto +++ b/rust/test/nested.proto @@ -38,6 +38,10 @@ message Outer { message CantBelieveItsSoInner { optional int32 num = 99; } + + enum JustWayTooInner { + JUST_WAY_TOO_INNER_UNSPECIFIED = 0; + } } } } @@ -46,6 +50,9 @@ message Outer { optional .nest.Outer.Inner.SuperInner.DuperInner.EvenMoreInner .CantBelieveItsSoInner deep = 2; + optional .nest.Outer.Inner.SuperInner.DuperInner.EvenMoreInner.JustWayTooInner + deep_enum = 4; + optional NotInside notinside = 3; } diff --git a/rust/test/no_package.proto b/rust/test/no_package.proto index d57d7debc4c8a..26f30fe7abaee 100644 --- a/rust/test/no_package.proto +++ b/rust/test/no_package.proto @@ -7,8 +7,17 @@ syntax = "proto2"; -// package intentionally left unspecified. - import public "google/protobuf/rust/test/no_package_import.proto"; +import "devtools/staticanalysis/pipeline/analyzers/proto_best_practices/proto/optouts.proto"; + +option (proto_best_practices.file_optouts) = { + // package intentionally left unspecified. + categories: GLOBAL_PACKAGE +}; + message MsgWithoutPackage {} + +enum EnumWithoutPackage { + ENUM_WITHOUT_PACKAGE_UNSPECIFIED = 0; +} diff --git a/rust/test/no_package_import.proto b/rust/test/no_package_import.proto index 511d047f54fc7..f0faba1a6af96 100644 --- a/rust/test/no_package_import.proto +++ b/rust/test/no_package_import.proto @@ -7,6 +7,15 @@ syntax = "proto2"; -// package intentionally left unspecified. +import "devtools/staticanalysis/pipeline/analyzers/proto_best_practices/proto/optouts.proto"; + +option (proto_best_practices.file_optouts) = { + // package intentionally left unspecified. + categories: GLOBAL_PACKAGE +}; message ImportedMsgWithoutPackage {} + +enum ImportedEnumWithoutPackage { + IMPORTED_ENUM_WITHOUT_PACKAGE_UNSPECIFIED = 0; +} diff --git a/rust/test/no_package_other.proto b/rust/test/no_package_other.proto index bdabd54dabbb7..f66f5735e9ffb 100644 --- a/rust/test/no_package_other.proto +++ b/rust/test/no_package_other.proto @@ -7,6 +7,15 @@ syntax = "proto2"; -// package intentionally left unspecified. +import "devtools/staticanalysis/pipeline/analyzers/proto_best_practices/proto/optouts.proto"; + +option (proto_best_practices.file_optouts) = { + // package intentionally left unspecified. + categories: GLOBAL_PACKAGE +}; message OtherMsgWithoutPackage {} + +enum OtherEnumWithoutPackage { + OTHER_ENUM_WITHOUT_PACKAGE_UNSPECIFIED = 0; +} diff --git a/rust/test/package.proto b/rust/test/package.proto index 605ca5e242e43..f68e6767a6a12 100644 --- a/rust/test/package.proto +++ b/rust/test/package.proto @@ -12,3 +12,7 @@ package testing_packages; import public "google/protobuf/rust/test/package_import.proto"; message MsgWithPackage {} + +enum EnumWithPackage { + ENUM_WITH_PACKAGE_UNSPECIFIED = 0; +} diff --git a/rust/test/package_import.proto b/rust/test/package_import.proto index 148371a9dbc11..334de001405ac 100644 --- a/rust/test/package_import.proto +++ b/rust/test/package_import.proto @@ -10,3 +10,7 @@ syntax = "proto2"; package testing_packages; message ImportedMsgWithPackage {} + +enum ImportedEnumWithPackage { + IMPORTED_ENUM_WITH_PACKAGE_UNSPECIFIED = 0; +} diff --git a/rust/test/package_other.proto b/rust/test/package_other.proto index 3aacbb85b56aa..76df39091b7a1 100644 --- a/rust/test/package_other.proto +++ b/rust/test/package_other.proto @@ -10,3 +10,7 @@ syntax = "proto2"; package testing_packages; message OtherMsgWithPackage {} + +enum OtherEnumWithPackage { + OTHER_ENUM_WITH_PACKAGE_UNSPECIFIED = 0; +} diff --git a/rust/test/package_other_different.proto b/rust/test/package_other_different.proto index fc67e924d499b..df9df858376c4 100644 --- a/rust/test/package_other_different.proto +++ b/rust/test/package_other_different.proto @@ -10,3 +10,7 @@ syntax = "proto2"; package testing_other_packages; message OtherMsgInDifferentPackage {} + +enum OtherEnumInDifferentPackage { + OTHER_ENUM_IN_DIFFERENT_PACKAGE_UNSPECIFIED = 0; +} diff --git a/rust/test/shared/BUILD b/rust/test/shared/BUILD index 9fb9a1bd00c49..a163cbdad898b 100644 --- a/rust/test/shared/BUILD +++ b/rust/test/shared/BUILD @@ -187,8 +187,8 @@ rust_test( ) rust_test( - name = "nested_messages_cpp_test", - srcs = ["nested_messages_test.rs"], + name = "nested_types_cpp_test", + srcs = ["nested_types_test.rs"], tags = [ # TODO: Enable testing on arm once we support sanitizers for Rust on Arm. "not_build:arm", @@ -197,8 +197,8 @@ rust_test( ) rust_test( - name = "nested_messages_upb_test", - srcs = ["nested_messages_test.rs"], + name = "nested_types_upb_test", + srcs = ["nested_types_test.rs"], tags = [ # TODO: Enable testing on arm once we support sanitizers for Rust on Arm. "not_build:arm", diff --git a/rust/test/shared/nested_messages_test.rs b/rust/test/shared/nested_types_test.rs similarity index 66% rename from rust/test/shared/nested_messages_test.rs rename to rust/test/shared/nested_types_test.rs index 8657f68bc2d48..fe03f25fdd6e3 100644 --- a/rust/test/shared/nested_messages_test.rs +++ b/rust/test/shared/nested_types_test.rs @@ -5,7 +5,7 @@ // license that can be found in the LICENSE file or at // https://developers.google.com/open-source/licenses/bsd -/// Tests covering nested messages. +//! Tests covering nested types. #[test] fn test_nested_messages_accessible() { @@ -14,3 +14,10 @@ fn test_nested_messages_accessible() { unittest_proto::proto2_unittest::TestChildExtensionData_:: NestedTestAllExtensionsData_::NestedDynamicExtensions::new(); } + +#[test] +fn test_nested_enums_accessible() { + let _parent: unittest_proto::proto2_unittest::TestAllTypes; + let _child: unittest_proto::proto2_unittest::TestAllTypes_::NestedEnum; + unittest_proto::proto2_unittest::TestDynamicExtensions_::DynamicEnumType::default(); +} diff --git a/rust/test/shared/package_test.rs b/rust/test/shared/package_test.rs index c132629db7b51..ae1dc005dafc5 100644 --- a/rust/test/shared/package_test.rs +++ b/rust/test/shared/package_test.rs @@ -5,23 +5,42 @@ // license that can be found in the LICENSE file or at // https://developers.google.com/open-source/licenses/bsd -/// Tests covering proto packages. +//! Tests covering proto packages. #[test] -fn test_packages() { +fn test_message_packages() { // empty package, message declared in the first .proto source - let _foo: no_package_proto::MsgWithoutPackage; + let _: no_package_proto::MsgWithoutPackage; // empty package, message declared in other .proto source - let _foo: no_package_proto::OtherMsgWithoutPackage; + let _: no_package_proto::OtherMsgWithoutPackage; // empty package, import public of a message - let _foo: no_package_proto::ImportedMsgWithoutPackage; + let _: no_package_proto::ImportedMsgWithoutPackage; // package, message declared in the first .proto source - let _foo: package_proto::testing_packages::MsgWithPackage; + let _: package_proto::testing_packages::MsgWithPackage; // package, message declared in the other .proto source with the same package - let _foo: package_proto::testing_packages::OtherMsgWithPackage; + let _: package_proto::testing_packages::OtherMsgWithPackage; // package, message declared in the other .proto source with a different package - let _foo: package_proto::testing_other_packages::OtherMsgInDifferentPackage; + let _: package_proto::testing_other_packages::OtherMsgInDifferentPackage; // package, import public of a message - let _foo: package_proto::testing_packages::ImportedMsgWithPackage; + let _: package_proto::testing_packages::ImportedMsgWithPackage; +} + +#[test] +fn test_enum_packages() { + // empty package, enum declared in the first .proto source + let _: no_package_proto::EnumWithoutPackage; + // empty package, enum declared in other .proto source + let _: no_package_proto::OtherEnumWithoutPackage; + // empty package, import public of a enum + let _: no_package_proto::ImportedEnumWithoutPackage; + + // package, enum declared in the first .proto source + let _: package_proto::testing_packages::EnumWithPackage; + // package, enum declared in the other .proto source with the same package + let _: package_proto::testing_packages::OtherEnumWithPackage; + // package, enum declared in the other .proto source with a different package + let _: package_proto::testing_other_packages::OtherEnumInDifferentPackage; + // package, import public of a enum + let _: package_proto::testing_packages::ImportedEnumWithPackage; } diff --git a/rust/test/shared/simple_nested_test.rs b/rust/test/shared/simple_nested_test.rs index c0932d33ee1e5..801b491207184 100644 --- a/rust/test/shared/simple_nested_test.rs +++ b/rust/test/shared/simple_nested_test.rs @@ -11,7 +11,7 @@ use nested_proto::nest::Outer_::InnerMut; use nested_proto::nest::Outer_::InnerView; #[test] -fn test_deeply_nested_definition() { +fn test_deeply_nested_message() { let deep = nested_proto::nest::Outer_::Inner_::SuperInner_::DuperInner_::EvenMoreInner_ ::CantBelieveItsSoInner::new(); assert_that!(deep.num(), eq(0)); @@ -20,6 +20,15 @@ fn test_deeply_nested_definition() { assert_that!(outer_msg.deep().num(), eq(0)); } +#[test] +fn test_deeply_nested_enum() { + let deep = nested_proto::nest::Outer_::Inner_::SuperInner_::DuperInner_::EvenMoreInner_ + ::JustWayTooInner::default(); + assert_that!(i32::from(deep), eq(0)); + + // TODO: Test deeply nested enum field access. +} + #[test] fn test_nested_views() { let outer_msg = Outer::new(); diff --git a/src/google/protobuf/compiler/rust/generator.cc b/src/google/protobuf/compiler/rust/generator.cc index c15f8743ff7a5..52ff1a4e75971 100644 --- a/src/google/protobuf/compiler/rust/generator.cc +++ b/src/google/protobuf/compiler/rust/generator.cc @@ -83,15 +83,15 @@ void EmitClosingOfPackageModules(Context& ctx, absl::string_view pkg) { } } -// Emits `pub use ::Msg` for all messages of a -// `non_primary_src` into the `primary_file`. +// Emits `pub use ::Type` for all messages and enums of +// a `non_primary_src` into the `primary_file`. // // `non_primary_src` has to be a non-primary src of the current `proto_library`. -void EmitPubUseOfOwnMessages(Context& ctx, const FileDescriptor& primary_file, - const FileDescriptor& non_primary_src) { +void EmitPubUseOfOwnTypes(Context& ctx, const FileDescriptor& primary_file, + const FileDescriptor& non_primary_src) { + auto mod = RustInternalModuleName(ctx, non_primary_src); for (int i = 0; i < non_primary_src.message_type_count(); ++i) { auto& msg = *non_primary_src.message_type(i); - auto mod = RustInternalModuleName(ctx, non_primary_src); ctx.Emit({{"mod", mod}, {"Msg", msg.name()}}, R"rs( pub use crate::$mod$::$Msg$; @@ -100,17 +100,24 @@ void EmitPubUseOfOwnMessages(Context& ctx, const FileDescriptor& primary_file, pub use crate::$mod$::$Msg$Mut; )rs"); } + for (int i = 0; i < non_primary_src.enum_type_count(); ++i) { + auto& enum_ = *non_primary_src.enum_type(i); + ctx.Emit({{"mod", mod}, {"Enum", EnumRsName(enum_)}}, + R"rs( + pub use crate::$mod$::$Enum$; + )rs"); + } } -// Emits `pub use ::::Msg` for all messages of a -// `dep` into the `primary_file`. This should only be called for 'import public' -// deps. +// Emits `pub use ::::Type` for all messages and +// enums of a `dep` into the `primary_file`. This should only be called for +// 'import public' deps. // // `dep` is a primary src of a dependency of the current `proto_library`. // TODO: Add support for public import of non-primary srcs of deps. -void EmitPubUseForImportedMessages(Context& ctx, - const FileDescriptor& primary_file, - const FileDescriptor& dep) { +void EmitPubUseForImportedTypes(Context& ctx, + const FileDescriptor& primary_file, + const FileDescriptor& dep) { std::string crate_name = GetCrateName(ctx, dep); for (int i = 0; i < dep.message_type_count(); ++i) { auto& msg = *dep.message_type(i); @@ -121,6 +128,14 @@ void EmitPubUseForImportedMessages(Context& ctx, pub use $crate$::$pkg::Msg$View; )rs"); } + for (int i = 0; i < dep.enum_type_count(); ++i) { + auto& enum_ = *dep.enum_type(i); + auto path = GetCrateRelativeQualifiedPath(ctx, enum_); + ctx.Emit({{"crate", crate_name}, {"pkg::Enum", path}}, + R"rs( + pub use $crate$::$pkg::Enum$; + )rs"); + } } // Emits all public imports of the current file @@ -137,7 +152,7 @@ void EmitPublicImports(Context& ctx, const FileDescriptor& primary_file) { if (IsInCurrentlyGeneratingCrate(ctx, dep_file)) { return; } - EmitPubUseForImportedMessages(ctx, primary_file, dep_file); + EmitPubUseForImportedTypes(ctx, primary_file, dep_file); } } @@ -185,7 +200,7 @@ std::vector ReexportMessagesFromSubmodules( EmitOpeningOfPackageModules(ctx, package); for (const FileDescriptor* c : fds) { - EmitPubUseOfOwnMessages(ctx, primary_file, *c); + EmitPubUseOfOwnTypes(ctx, primary_file, *c); } EmitClosingOfPackageModules(ctx, package); } @@ -249,7 +264,7 @@ bool RustGenerator::Generate(const FileDescriptor* file, for (const FileDescriptor* non_primary_file : non_primary_srcs_in_primary_package) { - EmitPubUseOfOwnMessages(ctx, *file, *non_primary_file); + EmitPubUseOfOwnTypes(ctx, *file, *non_primary_file); } } From fa67ce8d4d99c9c70f37bee93de039d4aa8c4464 Mon Sep 17 00:00:00 2001 From: Alyssa Haroldsen Date: Mon, 8 Jan 2024 19:07:49 -0800 Subject: [PATCH 213/255] Expand PrimitiveRsTypeName to work with non-primitives, rename, refactor PiperOrigin-RevId: 596765288 --- src/google/protobuf/compiler/rust/accessors/map.cc | 4 ++-- .../compiler/rust/accessors/repeated_scalar.cc | 4 ++-- .../compiler/rust/accessors/singular_message.cc | 5 +++-- .../compiler/rust/accessors/singular_scalar.cc | 4 ++-- .../compiler/rust/accessors/singular_string.cc | 2 +- src/google/protobuf/compiler/rust/message.cc | 4 ++-- src/google/protobuf/compiler/rust/naming.cc | 10 +++++++++- src/google/protobuf/compiler/rust/naming.h | 5 ++++- src/google/protobuf/compiler/rust/oneof.cc | 12 +++--------- 9 files changed, 28 insertions(+), 22 deletions(-) diff --git a/src/google/protobuf/compiler/rust/accessors/map.cc b/src/google/protobuf/compiler/rust/accessors/map.cc index 4061d731cacf7..5c103a195d4a3 100644 --- a/src/google/protobuf/compiler/rust/accessors/map.cc +++ b/src/google/protobuf/compiler/rust/accessors/map.cc @@ -22,8 +22,8 @@ void Map::InMsgImpl(Context& ctx, const FieldDescriptor& field) const { auto& value_type = *field.message_type()->map_value(); ctx.Emit({{"field", field.name()}, - {"Key", PrimitiveRsTypeName(key_type)}, - {"Value", PrimitiveRsTypeName(value_type)}, + {"Key", RsTypePath(ctx, key_type)}, + {"Value", RsTypePath(ctx, value_type)}, {"getter_thunk", ThunkName(ctx, field, "get")}, {"getter_mut_thunk", ThunkName(ctx, field, "get_mut")}, {"getter", diff --git a/src/google/protobuf/compiler/rust/accessors/repeated_scalar.cc b/src/google/protobuf/compiler/rust/accessors/repeated_scalar.cc index b88fa9fe37731..e831c70cd14f8 100644 --- a/src/google/protobuf/compiler/rust/accessors/repeated_scalar.cc +++ b/src/google/protobuf/compiler/rust/accessors/repeated_scalar.cc @@ -20,7 +20,7 @@ namespace rust { void RepeatedScalar::InMsgImpl(Context& ctx, const FieldDescriptor& field) const { ctx.Emit({{"field", field.name()}, - {"Scalar", PrimitiveRsTypeName(field)}, + {"Scalar", RsTypePath(ctx, field)}, {"getter_thunk", ThunkName(ctx, field, "get")}, {"getter_mut_thunk", ThunkName(ctx, field, "get_mut")}, {"getter", @@ -100,7 +100,7 @@ void RepeatedScalar::InMsgImpl(Context& ctx, void RepeatedScalar::InExternC(Context& ctx, const FieldDescriptor& field) const { - ctx.Emit({{"Scalar", PrimitiveRsTypeName(field)}, + ctx.Emit({{"Scalar", RsTypePath(ctx, field)}, {"getter_thunk", ThunkName(ctx, field, "get")}, {"getter_mut_thunk", ThunkName(ctx, field, "get_mut")}, {"getter", diff --git a/src/google/protobuf/compiler/rust/accessors/singular_message.cc b/src/google/protobuf/compiler/rust/accessors/singular_message.cc index b94473cb6d77a..81dbc4efe694a 100644 --- a/src/google/protobuf/compiler/rust/accessors/singular_message.cc +++ b/src/google/protobuf/compiler/rust/accessors/singular_message.cc @@ -5,6 +5,8 @@ // license that can be found in the LICENSE file or at // https://developers.google.com/open-source/licenses/bsd +#include + #include "absl/strings/string_view.h" #include "google/protobuf/compiler/cpp/helpers.h" #include "google/protobuf/compiler/rust/accessors/accessor_generator.h" @@ -19,8 +21,7 @@ namespace rust { void SingularMessage::InMsgImpl(Context& ctx, const FieldDescriptor& field) const { - auto& msg = *field.message_type(); - auto prefix = "crate::" + GetCrateRelativeQualifiedPath(ctx, msg); + std::string prefix = RsTypePath(ctx, field); ctx.Emit( { diff --git a/src/google/protobuf/compiler/rust/accessors/singular_scalar.cc b/src/google/protobuf/compiler/rust/accessors/singular_scalar.cc index a49cf6cbc2596..1f90cd62b73c2 100644 --- a/src/google/protobuf/compiler/rust/accessors/singular_scalar.cc +++ b/src/google/protobuf/compiler/rust/accessors/singular_scalar.cc @@ -23,7 +23,7 @@ void SingularScalar::InMsgImpl(Context& ctx, ctx.Emit( { {"field", field.name()}, - {"Scalar", PrimitiveRsTypeName(field)}, + {"Scalar", RsTypePath(ctx, field)}, {"hazzer_thunk", ThunkName(ctx, field, "has")}, {"default_value", DefaultValue(field)}, {"getter", @@ -117,7 +117,7 @@ void SingularScalar::InMsgImpl(Context& ctx, void SingularScalar::InExternC(Context& ctx, const FieldDescriptor& field) const { - ctx.Emit({{"Scalar", PrimitiveRsTypeName(field)}, + ctx.Emit({{"Scalar", RsTypePath(ctx, field)}, {"hazzer_thunk", ThunkName(ctx, field, "has")}, {"getter_thunk", ThunkName(ctx, field, "get")}, {"setter_thunk", ThunkName(ctx, field, "set")}, diff --git a/src/google/protobuf/compiler/rust/accessors/singular_string.cc b/src/google/protobuf/compiler/rust/accessors/singular_string.cc index 227c11b34b266..6992d09704a93 100644 --- a/src/google/protobuf/compiler/rust/accessors/singular_string.cc +++ b/src/google/protobuf/compiler/rust/accessors/singular_string.cc @@ -25,7 +25,7 @@ void SingularString::InMsgImpl(Context& ctx, std::string hazzer_thunk = ThunkName(ctx, field, "has"); std::string getter_thunk = ThunkName(ctx, field, "get"); std::string setter_thunk = ThunkName(ctx, field, "set"); - std::string proxied_type = PrimitiveRsTypeName(field); + std::string proxied_type = RsTypePath(ctx, field); auto transform_view = [&] { if (field.type() == FieldDescriptor::TYPE_STRING) { ctx.Emit(R"rs( diff --git a/src/google/protobuf/compiler/rust/message.cc b/src/google/protobuf/compiler/rust/message.cc index 6b5bfa877ac95..c1d3ba899e858 100644 --- a/src/google/protobuf/compiler/rust/message.cc +++ b/src/google/protobuf/compiler/rust/message.cc @@ -233,7 +233,7 @@ void GetterForViewOrMut(Context& ctx, const FieldDescriptor& field, if (!IsInCurrentlyGeneratingCrate(ctx, msg)) { return; } - auto prefix = "crate::" + GetCrateRelativeQualifiedPath(ctx, msg); + auto prefix = RsTypePath(ctx, field); ctx.Emit( { {"prefix", prefix}, @@ -270,7 +270,7 @@ void GetterForViewOrMut(Context& ctx, const FieldDescriptor& field, return; } - auto rsType = PrimitiveRsTypeName(field); + auto rsType = RsTypePath(ctx, field); auto asRef = IsStringOrBytes(fieldType) ? ".as_ref()" : ""; auto vtable = IsStringOrBytes(fieldType) ? "BytesMutVTable" : "PrimitiveVTable"; diff --git a/src/google/protobuf/compiler/rust/naming.cc b/src/google/protobuf/compiler/rust/naming.cc index ea084e6b09df8..aef71565c4364 100644 --- a/src/google/protobuf/compiler/rust/naming.cc +++ b/src/google/protobuf/compiler/rust/naming.cc @@ -175,7 +175,7 @@ std::string ThunkName(Context& ctx, const Descriptor& msg, op); } -std::string PrimitiveRsTypeName(const FieldDescriptor& field) { +std::string RsTypePath(Context& ctx, const FieldDescriptor& field) { switch (field.type()) { case FieldDescriptor::TYPE_BOOL: return "bool"; @@ -201,6 +201,14 @@ std::string PrimitiveRsTypeName(const FieldDescriptor& field) { return "[u8]"; case FieldDescriptor::TYPE_STRING: return "::__pb::ProtoStr"; + case FieldDescriptor::TYPE_MESSAGE: + // TODO: Fix depending on types from other proto_libraries. + return absl::StrCat( + "crate::", GetCrateRelativeQualifiedPath(ctx, *field.message_type())); + case FieldDescriptor::TYPE_ENUM: + // TODO: Fix depending on types from other proto_libraries. + return absl::StrCat( + "crate::", GetCrateRelativeQualifiedPath(ctx, *field.enum_type())); default: break; } diff --git a/src/google/protobuf/compiler/rust/naming.h b/src/google/protobuf/compiler/rust/naming.h index 46b2e951e30fc..532863ce31c16 100644 --- a/src/google/protobuf/compiler/rust/naming.h +++ b/src/google/protobuf/compiler/rust/naming.h @@ -33,7 +33,10 @@ std::string ThunkName(Context& ctx, const OneofDescriptor& field, std::string ThunkName(Context& ctx, const Descriptor& msg, absl::string_view op); -std::string PrimitiveRsTypeName(const FieldDescriptor& field); +// Returns an absolute path to the Proxied Rust type of the given field. +// The absolute path is guaranteed to work in the crate that defines the field. +// It may be crate-relative, or directly reference the owning crate of the type. +std::string RsTypePath(Context& ctx, const FieldDescriptor& field); std::string EnumRsName(const EnumDescriptor& desc); diff --git a/src/google/protobuf/compiler/rust/oneof.cc b/src/google/protobuf/compiler/rust/oneof.cc index 1408bfcd9476b..7f5d90f2ae8a2 100644 --- a/src/google/protobuf/compiler/rust/oneof.cc +++ b/src/google/protobuf/compiler/rust/oneof.cc @@ -92,15 +92,13 @@ std::string RsTypeNameView(Context& ctx, const FieldDescriptor& field) { case FieldDescriptor::TYPE_FLOAT: case FieldDescriptor::TYPE_DOUBLE: case FieldDescriptor::TYPE_BOOL: - return PrimitiveRsTypeName(field); + return RsTypePath(ctx, field); case FieldDescriptor::TYPE_BYTES: return "&'msg [u8]"; case FieldDescriptor::TYPE_STRING: return "&'msg ::__pb::ProtoStr"; case FieldDescriptor::TYPE_MESSAGE: - return absl::StrCat( - "::__pb::View<'msg, crate::", - GetCrateRelativeQualifiedPath(ctx, *field.message_type()), ">"); + return absl::StrCat("::__pb::View<'msg, ", RsTypePath(ctx, field), ">"); case FieldDescriptor::TYPE_ENUM: // TODO: b/300257770 - Support enums. case FieldDescriptor::TYPE_GROUP: // Not supported yet. return ""; @@ -130,12 +128,8 @@ std::string RsTypeNameMut(Context& ctx, const FieldDescriptor& field) { case FieldDescriptor::TYPE_BOOL: case FieldDescriptor::TYPE_BYTES: case FieldDescriptor::TYPE_STRING: - return absl::StrCat("::__pb::Mut<'msg, ", PrimitiveRsTypeName(field), - ">"); case FieldDescriptor::TYPE_MESSAGE: - return absl::StrCat( - "::__pb::Mut<'msg, crate::", - GetCrateRelativeQualifiedPath(ctx, *field.message_type()), ">"); + return absl::StrCat("::__pb::Mut<'msg, ", RsTypePath(ctx, field), ">"); case FieldDescriptor::TYPE_ENUM: // TODO: b/300257770 - Support enums. case FieldDescriptor::TYPE_GROUP: // Not supported yet. return ""; From e3d2551c8e7fe3e4698e8c0d679278bc0c575efe Mon Sep 17 00:00:00 2001 From: Alyssa Haroldsen Date: Mon, 8 Jan 2024 19:25:18 -0800 Subject: [PATCH 214/255] Move enum value name calculation PiperOrigin-RevId: 596767666 --- src/google/protobuf/compiler/rust/BUILD.bazel | 1 + src/google/protobuf/compiler/rust/enum.cc | 40 +------------- src/google/protobuf/compiler/rust/naming.cc | 54 +++++++++++++++++++ src/google/protobuf/compiler/rust/naming.h | 22 ++++++++ 4 files changed, 79 insertions(+), 38 deletions(-) diff --git a/src/google/protobuf/compiler/rust/BUILD.bazel b/src/google/protobuf/compiler/rust/BUILD.bazel index 52721ad2669a8..ae1f9c46a3cb8 100644 --- a/src/google/protobuf/compiler/rust/BUILD.bazel +++ b/src/google/protobuf/compiler/rust/BUILD.bazel @@ -152,6 +152,7 @@ cc_library( "//src/google/protobuf", "//src/google/protobuf/compiler:code_generator", "//src/google/protobuf/compiler/cpp:names_internal", + "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/log:absl_log", "@com_google_absl//absl/strings", ], diff --git a/src/google/protobuf/compiler/rust/enum.cc b/src/google/protobuf/compiler/rust/enum.cc index 2f4b08da17b4e..7539dedfc82b2 100644 --- a/src/google/protobuf/compiler/rust/enum.cc +++ b/src/google/protobuf/compiler/rust/enum.cc @@ -17,12 +17,9 @@ #include "absl/container/flat_hash_map.h" #include "absl/container/flat_hash_set.h" #include "absl/log/absl_check.h" -#include "absl/strings/ascii.h" -#include "absl/strings/match.h" #include "absl/strings/str_cat.h" #include "absl/strings/str_join.h" #include "absl/strings/string_view.h" -#include "absl/strings/strip.h" #include "absl/types/span.h" #include "google/protobuf/compiler/rust/context.h" #include "google/protobuf/compiler/rust/naming.h" @@ -52,17 +49,7 @@ std::vector> EnumValuesInput( std::vector EnumValues( absl::string_view enum_name, absl::Span> values) { - // Enum values may have a prefix of the name of the enum stripped from the - // value names in the gencode. This prefix is flexible: - // - It can be the original enum name, the name as UpperCamel, or snake_case. - // - The stripped prefix may also end in an underscore. - - // The set of prefixes that will be stripped. - std::initializer_list prefixes = { - std::string(enum_name), - ScreamingSnakeToUpperCamelCase(enum_name), - CamelToSnakeCase(enum_name), - }; + MultiCasePrefixStripper stripper(enum_name); absl::flat_hash_set seen_by_name; absl::flat_hash_map seen_by_number; @@ -74,32 +61,9 @@ std::vector EnumValues( seen_by_number.reserve(values.size()); for (const auto& name_and_number : values) { - absl::string_view base_value_name = name_and_number.first; - for (absl::string_view prefix : prefixes) { - if (absl::StartsWithIgnoreCase(base_value_name, prefix)) { - base_value_name.remove_prefix(prefix.size()); - - // Also strip a joining underscore, if present. - absl::ConsumePrefix(&base_value_name, "_"); - - // Only strip one prefix. - break; - } - } - - if (base_value_name.empty()) { - // The enum value name has a similar name to the enum - don't strip. - base_value_name = name_and_number.first; - } - int32_t number = name_and_number.second; std::string rust_value_name = - ScreamingSnakeToUpperCamelCase(base_value_name); - - // Invalid identifiers are prefixed with `_`. - if (absl::ascii_isdigit(rust_value_name[0])) { - rust_value_name = absl::StrCat("_", rust_value_name); - } + EnumValueRsName(stripper, name_and_number.first); if (seen_by_name.contains(rust_value_name)) { // Don't add an alias with the same normalized name. diff --git a/src/google/protobuf/compiler/rust/naming.cc b/src/google/protobuf/compiler/rust/naming.cc index aef71565c4364..0f83320255162 100644 --- a/src/google/protobuf/compiler/rust/naming.cc +++ b/src/google/protobuf/compiler/rust/naming.cc @@ -10,13 +10,16 @@ #include #include +#include "absl/log/absl_check.h" #include "absl/log/absl_log.h" #include "absl/strings/ascii.h" +#include "absl/strings/match.h" #include "absl/strings/str_cat.h" #include "absl/strings/str_join.h" #include "absl/strings/str_replace.h" #include "absl/strings/str_split.h" #include "absl/strings/string_view.h" +#include "absl/strings/strip.h" #include "absl/strings/substitute.h" #include "google/protobuf/compiler/code_generator.h" #include "google/protobuf/compiler/cpp/helpers.h" @@ -257,6 +260,29 @@ std::string EnumRsName(const EnumDescriptor& desc) { return SnakeToUpperCamelCase(desc.name()); } +std::string EnumValueRsName(const EnumValueDescriptor& value) { + MultiCasePrefixStripper stripper(value.type()->name()); + return EnumValueRsName(stripper, value.name()); +} + +std::string EnumValueRsName(const MultiCasePrefixStripper& stripper, + absl::string_view value_name) { + // Enum values may have a prefix of the name of the enum stripped from the + // value names in the gencode. This prefix is flexible: + // - It can be the original enum name, the name as UpperCamel, or snake_case. + // - The stripped prefix may also end in an underscore. + auto stripped = stripper.StripPrefix(value_name); + + auto name = ScreamingSnakeToUpperCamelCase(stripped); + ABSL_CHECK(!name.empty()); + + // Invalid identifiers are prefixed with `_`. + if (absl::ascii_isdigit(name[0])) { + name = absl::StrCat("_", name); + } + return name; +} + std::string OneofViewEnumRsName(const OneofDescriptor& oneof) { return SnakeToUpperCamelCase(oneof.name()); } @@ -318,6 +344,34 @@ std::string ScreamingSnakeToUpperCamelCase(absl::string_view input) { return result; } +MultiCasePrefixStripper::MultiCasePrefixStripper(absl::string_view prefix) + : prefixes_{ + std::string(prefix), + ScreamingSnakeToUpperCamelCase(prefix), + CamelToSnakeCase(prefix), + } {} + +absl::string_view MultiCasePrefixStripper::StripPrefix( + absl::string_view name) const { + absl::string_view start_name = name; + for (absl::string_view prefix : prefixes_) { + if (absl::StartsWithIgnoreCase(name, prefix)) { + name.remove_prefix(prefix.size()); + + // Also strip a joining underscore, if present. + absl::ConsumePrefix(&name, "_"); + + // Only strip one prefix. + break; + } + } + + if (name.empty()) { + return start_name; + } + return name; +} + } // namespace rust } // namespace compiler } // namespace protobuf diff --git a/src/google/protobuf/compiler/rust/naming.h b/src/google/protobuf/compiler/rust/naming.h index 532863ce31c16..a5bdeb15c2afa 100644 --- a/src/google/protobuf/compiler/rust/naming.h +++ b/src/google/protobuf/compiler/rust/naming.h @@ -8,6 +8,7 @@ #ifndef GOOGLE_PROTOBUF_COMPILER_RUST_NAMING_H__ #define GOOGLE_PROTOBUF_COMPILER_RUST_NAMING_H__ +#include #include #include "absl/strings/string_view.h" @@ -39,6 +40,7 @@ std::string ThunkName(Context& ctx, const Descriptor& msg, std::string RsTypePath(Context& ctx, const FieldDescriptor& field); std::string EnumRsName(const EnumDescriptor& desc); +std::string EnumValueRsName(const EnumValueDescriptor& value); std::string OneofViewEnumRsName(const OneofDescriptor& oneof); std::string OneofMutEnumRsName(const OneofDescriptor& oneof); @@ -75,6 +77,26 @@ std::string SnakeToUpperCamelCase(absl::string_view input); // Converts a SCREAMING_SNAKE_CASE string to an UpperCamelCase string. std::string ScreamingSnakeToUpperCamelCase(absl::string_view input); +// Given a fixed prefix, this will repeatedly strip provided +// string_views if they start with the prefix, the prefix in UpperCamel, or +// the prefix in snake_case. +class MultiCasePrefixStripper final { + public: + explicit MultiCasePrefixStripper(absl::string_view prefix); + + // Strip a prefix from the name in UpperCamel or snake_case, if present. + // If there is an underscore after the prefix, that will also be stripped. + // The stripping is case-insensitive. + absl::string_view StripPrefix(absl::string_view name) const; + + private: + std::array prefixes_; +}; + +// More efficient overload if a stripper is already constructed. +std::string EnumValueRsName(const MultiCasePrefixStripper& stripper, + absl::string_view value_name); + } // namespace rust } // namespace compiler } // namespace protobuf From e7be866a17cdae4ad942500d7e3af3686b4883b2 Mon Sep 17 00:00:00 2001 From: Alyssa Haroldsen Date: Mon, 8 Jan 2024 19:43:40 -0800 Subject: [PATCH 215/255] Support enums in DefaultValue PiperOrigin-RevId: 596769895 --- src/google/protobuf/compiler/rust/BUILD.bazel | 1 + .../protobuf/compiler/rust/accessors/helpers.cc | 17 +++++++++++++++-- .../protobuf/compiler/rust/accessors/helpers.h | 3 ++- .../compiler/rust/accessors/singular_scalar.cc | 2 +- .../compiler/rust/accessors/singular_string.cc | 2 +- 5 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/google/protobuf/compiler/rust/BUILD.bazel b/src/google/protobuf/compiler/rust/BUILD.bazel index ae1f9c46a3cb8..abfb2cc3e6e17 100644 --- a/src/google/protobuf/compiler/rust/BUILD.bazel +++ b/src/google/protobuf/compiler/rust/BUILD.bazel @@ -204,6 +204,7 @@ cc_library( strip_include_prefix = "/src", deps = [ ":context", + ":naming", "//src/google/protobuf", "//src/google/protobuf/io:tokenizer", "@com_google_absl//absl/log:absl_check", diff --git a/src/google/protobuf/compiler/rust/accessors/helpers.cc b/src/google/protobuf/compiler/rust/accessors/helpers.cc index ba41abd9b5bb4..23192961b22cc 100644 --- a/src/google/protobuf/compiler/rust/accessors/helpers.cc +++ b/src/google/protobuf/compiler/rust/accessors/helpers.cc @@ -15,6 +15,8 @@ #include "absl/strings/escaping.h" #include "absl/strings/str_cat.h" #include "absl/strings/str_format.h" +#include "google/protobuf/compiler/rust/context.h" +#include "google/protobuf/compiler/rust/naming.h" #include "google/protobuf/descriptor.h" #include "google/protobuf/io/strtod.h" @@ -23,7 +25,7 @@ namespace protobuf { namespace compiler { namespace rust { -std::string DefaultValue(const FieldDescriptor& field) { +std::string DefaultValue(Context& ctx, const FieldDescriptor& field) { switch (field.type()) { case FieldDescriptor::TYPE_DOUBLE: if (std::isfinite(field.default_value_double())) { @@ -74,9 +76,20 @@ std::string DefaultValue(const FieldDescriptor& field) { case FieldDescriptor::TYPE_BYTES: return absl::StrFormat("b\"%s\"", absl::CHexEscape(field.default_value_string())); + case FieldDescriptor::TYPE_ENUM: + // `$EnumName$::default()` might seem like the right choice here, but + // it is not. The default value for the enum type isn't the same as the + // field, since in `syntax = "proto2"`, an enum field can have a default + // value other than the first listed in the enum. + // + // Even in cases where there is no custom field default, `default()` can't + // be used. This is because the vtables for field mutators store the + // default value. They are `static`s which are constructed with a `const` + // expression. Trait methods in a `const` context aren't currently stable. + return absl::StrCat(RsTypePath(ctx, field), + "::", EnumValueRsName(*field.default_value_enum())); case FieldDescriptor::TYPE_GROUP: case FieldDescriptor::TYPE_MESSAGE: - case FieldDescriptor::TYPE_ENUM: ABSL_LOG(FATAL) << "Unsupported field type: " << field.type_name(); } ABSL_LOG(FATAL) << "unreachable"; diff --git a/src/google/protobuf/compiler/rust/accessors/helpers.h b/src/google/protobuf/compiler/rust/accessors/helpers.h index ee2c429e3ba43..2293c6cea4877 100644 --- a/src/google/protobuf/compiler/rust/accessors/helpers.h +++ b/src/google/protobuf/compiler/rust/accessors/helpers.h @@ -10,6 +10,7 @@ #include +#include "google/protobuf/compiler/rust/context.h" #include "google/protobuf/descriptor.h" namespace google { @@ -22,7 +23,7 @@ namespace rust { // Both strings and bytes are represented as a byte string literal, i.e. in the // format `b"default value here"`. It is the caller's responsibility to convert // the byte literal to an actual string, if needed. -std::string DefaultValue(const FieldDescriptor& field); +std::string DefaultValue(Context& ctx, const FieldDescriptor& field); } // namespace rust } // namespace compiler diff --git a/src/google/protobuf/compiler/rust/accessors/singular_scalar.cc b/src/google/protobuf/compiler/rust/accessors/singular_scalar.cc index 1f90cd62b73c2..dedaa85a6240b 100644 --- a/src/google/protobuf/compiler/rust/accessors/singular_scalar.cc +++ b/src/google/protobuf/compiler/rust/accessors/singular_scalar.cc @@ -25,7 +25,7 @@ void SingularScalar::InMsgImpl(Context& ctx, {"field", field.name()}, {"Scalar", RsTypePath(ctx, field)}, {"hazzer_thunk", ThunkName(ctx, field, "has")}, - {"default_value", DefaultValue(field)}, + {"default_value", DefaultValue(ctx, field)}, {"getter", [&] { ctx.Emit({}, R"rs( diff --git a/src/google/protobuf/compiler/rust/accessors/singular_string.cc b/src/google/protobuf/compiler/rust/accessors/singular_string.cc index 6992d09704a93..cda5c885c8930 100644 --- a/src/google/protobuf/compiler/rust/accessors/singular_string.cc +++ b/src/google/protobuf/compiler/rust/accessors/singular_string.cc @@ -68,7 +68,7 @@ void SingularString::InMsgImpl(Context& ctx, { {"field", field.name()}, {"proxied_type", proxied_type}, - {"default_val", DefaultValue(field)}, + {"default_val", DefaultValue(ctx, field)}, {"view_type", proxied_type}, {"transform_field_entry", [&] { From dbd4dcede084f7c301bfdf229e1e51dfd3e1179f Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Tue, 9 Jan 2024 09:43:44 -0800 Subject: [PATCH 216/255] Breaking Change: Removed `syntax` and added `has_presence?`/`is_packed?`. Closes #15313 PiperOrigin-RevId: 596962024 --- ruby/ext/google/protobuf_c/defs.c | 61 +++++++++++-------- ruby/lib/google/protobuf/ffi/descriptor.rb | 1 - .../google/protobuf/ffi/field_descriptor.rb | 9 +++ .../google/protobuf/ffi/file_descriptor.rb | 12 ---- .../protobuf/jruby/RubyFieldDescriptor.java | 22 +++++++ .../protobuf/jruby/RubyFileDescriptor.java | 21 ------- ruby/tests/basic.rb | 13 +++- ruby/tests/basic_proto2.rb | 7 ++- upb/reflection/field_def.h | 2 +- 9 files changed, 85 insertions(+), 63 deletions(-) diff --git a/ruby/ext/google/protobuf_c/defs.c b/ruby/ext/google/protobuf_c/defs.c index 8761b84f32b93..9141c7bd08872 100644 --- a/ruby/ext/google/protobuf_c/defs.c +++ b/ruby/ext/google/protobuf_c/defs.c @@ -489,7 +489,7 @@ static VALUE FileDescriptor_alloc(VALUE klass) { * call-seq: * FileDescriptor.new => file * - * Returns a new file descriptor. The syntax must be set before it's passed + * Returns a new file descriptor. May * to a builder. */ static VALUE FileDescriptor_initialize(VALUE _self, VALUE cookie, @@ -519,28 +519,6 @@ static VALUE FileDescriptor_name(VALUE _self) { return name == NULL ? Qnil : rb_str_new2(name); } -/* - * call-seq: - * FileDescriptor.syntax => syntax - * - * Returns this file descriptors syntax. - * - * Valid syntax versions are: - * :proto2 or :proto3. - */ -static VALUE FileDescriptor_syntax(VALUE _self) { - FileDescriptor* self = ruby_to_FileDescriptor(_self); - - switch (upb_FileDef_Syntax(self->filedef)) { - case kUpb_Syntax_Proto3: - return ID2SYM(rb_intern("proto3")); - case kUpb_Syntax_Proto2: - return ID2SYM(rb_intern("proto2")); - default: - return Qnil; - } -} - /* * call-seq: * FileDescriptor.options => options @@ -564,7 +542,6 @@ static void FileDescriptor_register(VALUE module) { rb_define_alloc_func(klass, FileDescriptor_alloc); rb_define_method(klass, "initialize", FileDescriptor_initialize, 3); rb_define_method(klass, "name", FileDescriptor_name, 0); - rb_define_method(klass, "syntax", FileDescriptor_syntax, 0); rb_define_method(klass, "options", FileDescriptor_options, 0); rb_gc_register_address(&cFileDescriptor); cFileDescriptor = klass; @@ -736,6 +713,28 @@ static VALUE FieldDescriptor_default(VALUE _self) { return Convert_UpbToRuby(default_val, TypeInfo_get(self->fielddef), Qnil); } +/* + * call-seq: + * FieldDescriptor.has_presence? => bool + * + * Returns whether this field tracks presence. + */ +static VALUE FieldDescriptor_has_presence(VALUE _self) { + FieldDescriptor* self = ruby_to_FieldDescriptor(_self); + return upb_FieldDef_HasPresence(self->fielddef) ? Qtrue : Qfalse; +} + +/* + * call-seq: + * FieldDescriptor.is_packed? => bool + * + * Returns whether this is a repeated field that uses packed encoding. + */ +static VALUE FieldDescriptor_is_packed(VALUE _self) { + FieldDescriptor* self = ruby_to_FieldDescriptor(_self); + return upb_FieldDef_IsPacked(self->fielddef) ? Qtrue : Qfalse; +} + /* * call-seq: * FieldDescriptor.json_name => json_name @@ -943,6 +942,8 @@ static void FieldDescriptor_register(VALUE module) { rb_define_method(klass, "name", FieldDescriptor_name, 0); rb_define_method(klass, "type", FieldDescriptor__type, 0); rb_define_method(klass, "default", FieldDescriptor_default, 0); + rb_define_method(klass, "has_presence?", FieldDescriptor_has_presence, 0); + rb_define_method(klass, "is_packed?", FieldDescriptor_is_packed, 0); rb_define_method(klass, "json_name", FieldDescriptor_json_name, 0); rb_define_method(klass, "label", FieldDescriptor_label, 0); rb_define_method(klass, "number", FieldDescriptor_number, 0); @@ -1163,6 +1164,17 @@ static VALUE EnumDescriptor_file_descriptor(VALUE _self) { upb_EnumDef_File(self->enumdef)); } +/* + * call-seq: + * EnumDescriptor.is_closed? => bool + * + * Returns whether this enum is open or closed. + */ +static VALUE EnumDescriptor_is_closed(VALUE _self) { + EnumDescriptor* self = ruby_to_EnumDescriptor(_self); + return upb_EnumDef_IsClosed(self->enumdef) ? Qtrue : Qfalse; +} + /* * call-seq: * EnumDescriptor.name => name @@ -1275,6 +1287,7 @@ static void EnumDescriptor_register(VALUE module) { rb_define_method(klass, "each", EnumDescriptor_each, 0); rb_define_method(klass, "enummodule", EnumDescriptor_enummodule, 0); rb_define_method(klass, "file_descriptor", EnumDescriptor_file_descriptor, 0); + rb_define_method(klass, "is_closed?", EnumDescriptor_is_closed, 0); rb_define_method(klass, "options", EnumDescriptor_options, 0); rb_include_module(klass, rb_mEnumerable); rb_gc_register_address(&cEnumDescriptor); diff --git a/ruby/lib/google/protobuf/ffi/descriptor.rb b/ruby/lib/google/protobuf/ffi/descriptor.rb index 3eb108663a944..3175d41355a6c 100644 --- a/ruby/lib/google/protobuf/ffi/descriptor.rb +++ b/ruby/lib/google/protobuf/ffi/descriptor.rb @@ -158,7 +158,6 @@ class FFI attach_function :oneof_count, :upb_MessageDef_OneofCount, [Descriptor], :int attach_function :message_options, :Descriptor_serialized_options, [Descriptor, :pointer, Internal::Arena], :pointer attach_function :get_well_known_type, :upb_MessageDef_WellKnownType, [Descriptor], WellKnown - attach_function :message_def_syntax, :upb_MessageDef_Syntax, [Descriptor], Syntax attach_function :find_msg_def_by_name, :upb_MessageDef_FindByNameWithSize, [Descriptor, :string, :size_t, :FieldDefPointer, :OneofDefPointer], :bool end end diff --git a/ruby/lib/google/protobuf/ffi/field_descriptor.rb b/ruby/lib/google/protobuf/ffi/field_descriptor.rb index b15c91066738a..cbc1e82ac7cab 100644 --- a/ruby/lib/google/protobuf/ffi/field_descriptor.rb +++ b/ruby/lib/google/protobuf/ffi/field_descriptor.rb @@ -156,6 +156,14 @@ def has_presence? @has_presence ||= Google::Protobuf::FFI.get_has_presence(self) end + ## + # Tests if this is a repeated field that uses packed encoding. + # + # @return [Boolean] True iff this field is packed + def is_packed? + @is_packed ||= Google::Protobuf::FFI.get_is_packed(self) + end + # @param msg [Google::Protobuf::Message] def clear(msg) if msg.class.descriptor != Google::Protobuf::FFI.get_containing_message_def(self) @@ -304,6 +312,7 @@ class FFI attach_function :get_default, :upb_FieldDef_Default, [FieldDescriptor], MessageValue.by_value attach_function :get_subtype_as_enum, :upb_FieldDef_EnumSubDef, [FieldDescriptor], EnumDescriptor attach_function :get_has_presence, :upb_FieldDef_HasPresence, [FieldDescriptor], :bool + attach_function :get_is_packed, :upb_FieldDef_IsPacked, [FieldDescriptor], :bool attach_function :is_map, :upb_FieldDef_IsMap, [FieldDescriptor], :bool attach_function :is_repeated, :upb_FieldDef_IsRepeated, [FieldDescriptor], :bool attach_function :is_sub_message, :upb_FieldDef_IsSubMessage, [FieldDescriptor], :bool diff --git a/ruby/lib/google/protobuf/ffi/file_descriptor.rb b/ruby/lib/google/protobuf/ffi/file_descriptor.rb index f1da9f7385fb0..2035b98efc298 100644 --- a/ruby/lib/google/protobuf/ffi/file_descriptor.rb +++ b/ruby/lib/google/protobuf/ffi/file_descriptor.rb @@ -10,7 +10,6 @@ module Protobuf class FFI # FileDescriptor attach_function :file_def_name, :upb_FileDef_Name, [:FileDef], :string - attach_function :file_def_syntax, :upb_FileDef_Syntax, [:FileDef], Syntax attach_function :file_def_pool, :upb_FileDef_Pool, [:FileDef], :DefPool attach_function :file_options, :FileDescriptor_serialized_options, [:FileDef, :pointer, Internal::Arena], :pointer end @@ -31,17 +30,6 @@ def inspect "#{self.class.name}: #{name}" end - def syntax - case Google::Protobuf::FFI.file_def_syntax(@file_def) - when :Proto3 - :proto3 - when :Proto2 - :proto2 - else - nil - end - end - def name Google::Protobuf::FFI.file_def_name(@file_def) end diff --git a/ruby/src/main/java/com/google/protobuf/jruby/RubyFieldDescriptor.java b/ruby/src/main/java/com/google/protobuf/jruby/RubyFieldDescriptor.java index 1d647ea8d9fc6..8e6427ee5482d 100644 --- a/ruby/src/main/java/com/google/protobuf/jruby/RubyFieldDescriptor.java +++ b/ruby/src/main/java/com/google/protobuf/jruby/RubyFieldDescriptor.java @@ -92,6 +92,28 @@ public IRubyObject getLabel(ThreadContext context) { return label; } + /* + * call-seq: + * FieldDescriptor.has_presence? => bool + * + * Returns whether this field tracks presence. + */ + @JRubyMethod(name = "has_presence?") + public IRubyObject hasPresence(ThreadContext context) { + return this.descriptor.hasPresence() ? context.runtime.getTrue() : context.runtime.getFalse(); + } + + /* + * call-seq: + * FieldDescriptor.is_packed? => bool + * + * Returns whether this is a repeated field that uses packed encoding. + */ + @JRubyMethod(name = "is_packed?") + public IRubyObject isPacked(ThreadContext context) { + return this.descriptor.isPacked() ? context.runtime.getTrue() : context.runtime.getFalse(); + } + /* * call-seq: * FieldDescriptor.name => name diff --git a/ruby/src/main/java/com/google/protobuf/jruby/RubyFileDescriptor.java b/ruby/src/main/java/com/google/protobuf/jruby/RubyFileDescriptor.java index db9580de984e6..ff3c6d9c9f65b 100644 --- a/ruby/src/main/java/com/google/protobuf/jruby/RubyFileDescriptor.java +++ b/ruby/src/main/java/com/google/protobuf/jruby/RubyFileDescriptor.java @@ -86,27 +86,6 @@ public IRubyObject getName(ThreadContext context) { return name == null ? context.nil : context.runtime.newString(name); } - /* - * call-seq: - * FileDescriptor.syntax => syntax - * - * Returns this file descriptors syntax. - * - * Valid syntax versions are: - * :proto2 or :proto3. - */ - @JRubyMethod(name = "syntax") - public IRubyObject getSyntax(ThreadContext context) { - switch (LegacyFileDescriptor.getSyntax(fileDescriptor)) { - case PROTO2: - return context.runtime.newSymbol("proto2"); - case PROTO3: - return context.runtime.newSymbol("proto3"); - default: - return context.nil; - } - } - @JRubyMethod public IRubyObject options(ThreadContext context) { RubyDescriptorPool pool = (RubyDescriptorPool) RubyDescriptorPool.generatedPool(null, null); diff --git a/ruby/tests/basic.rb b/ruby/tests/basic.rb index 46e3fec49e8e5..e6cd08b2731b2 100755 --- a/ruby/tests/basic.rb +++ b/ruby/tests/basic.rb @@ -553,12 +553,10 @@ def test_file_descriptor file_descriptor = TestMessage.descriptor.file_descriptor refute_nil file_descriptor assert_equal "basic_test.proto", file_descriptor.name - assert_equal :proto3, file_descriptor.syntax file_descriptor = TestEnum.descriptor.file_descriptor refute_nil file_descriptor assert_equal "basic_test.proto", file_descriptor.name - assert_equal :proto3, file_descriptor.syntax end def test_map_freeze @@ -639,6 +637,17 @@ def test_map_fields_respond_to? # regression test for issue 9202 end end + def test_has_presence + assert_true TestMessage.descriptor.lookup("optional_int32").has_presence? + assert_false TestMessage.descriptor.lookup("repeated_int32").has_presence? + assert_false TestSingularFields.descriptor.lookup("singular_int32").has_presence? + end + + def test_is_packed + assert_false TestMessage.descriptor.lookup("optional_int32").is_packed? + assert_true TestMessage.descriptor.lookup("repeated_int32").is_packed? + end + def test_file_descriptor_options file_descriptor = TestMessage.descriptor.file_descriptor diff --git a/ruby/tests/basic_proto2.rb b/ruby/tests/basic_proto2.rb index 3864756fa7829..e9fce5751d837 100755 --- a/ruby/tests/basic_proto2.rb +++ b/ruby/tests/basic_proto2.rb @@ -231,12 +231,10 @@ def test_file_descriptor file_descriptor = TestMessage.descriptor.file_descriptor refute_nil file_descriptor assert_equal "basic_test_proto2.proto", file_descriptor.name - assert_equal :proto2, file_descriptor.syntax file_descriptor = TestEnum.descriptor.file_descriptor refute_nil file_descriptor assert_equal "basic_test_proto2.proto", file_descriptor.name - assert_equal :proto2, file_descriptor.syntax end def test_oneof_fields_respond_to? # regression test for issue 9202 @@ -254,6 +252,11 @@ def test_oneof_fields_respond_to? # regression test for issue 9202 refute msg.has_d? end + def test_is_packed + assert_false TestMessage.descriptor.lookup("optional_int32").is_packed? + assert_false TestMessage.descriptor.lookup("repeated_int32").is_packed? + end + def test_extension message = TestExtensions.new extension = Google::Protobuf::DescriptorPool.generated_pool.lookup 'basic_test_proto2.optional_int32_extension' diff --git a/upb/reflection/field_def.h b/upb/reflection/field_def.h index fabc292108b85..5667141a0c361 100644 --- a/upb/reflection/field_def.h +++ b/upb/reflection/field_def.h @@ -47,7 +47,7 @@ uint32_t upb_FieldDef_Index(const upb_FieldDef* f); bool upb_FieldDef_IsExtension(const upb_FieldDef* f); UPB_API bool upb_FieldDef_IsMap(const upb_FieldDef* f); bool upb_FieldDef_IsOptional(const upb_FieldDef* f); -bool upb_FieldDef_IsPacked(const upb_FieldDef* f); +UPB_API bool upb_FieldDef_IsPacked(const upb_FieldDef* f); bool upb_FieldDef_IsPrimitive(const upb_FieldDef* f); UPB_API bool upb_FieldDef_IsRepeated(const upb_FieldDef* f); bool upb_FieldDef_IsRequired(const upb_FieldDef* f); From f2c187df28bcb1142b9352985890c530f43efe04 Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Tue, 9 Jan 2024 17:58:04 +0000 Subject: [PATCH 217/255] Auto-generate files after cl/596962024 --- php/ext/google/protobuf/php-upb.h | 2 +- ruby/ext/google/protobuf_c/ruby-upb.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/php/ext/google/protobuf/php-upb.h b/php/ext/google/protobuf/php-upb.h index af3ca9af8e1c3..dda30b595c19e 100644 --- a/php/ext/google/protobuf/php-upb.h +++ b/php/ext/google/protobuf/php-upb.h @@ -11132,7 +11132,7 @@ uint32_t upb_FieldDef_Index(const upb_FieldDef* f); bool upb_FieldDef_IsExtension(const upb_FieldDef* f); UPB_API bool upb_FieldDef_IsMap(const upb_FieldDef* f); bool upb_FieldDef_IsOptional(const upb_FieldDef* f); -bool upb_FieldDef_IsPacked(const upb_FieldDef* f); +UPB_API bool upb_FieldDef_IsPacked(const upb_FieldDef* f); bool upb_FieldDef_IsPrimitive(const upb_FieldDef* f); UPB_API bool upb_FieldDef_IsRepeated(const upb_FieldDef* f); bool upb_FieldDef_IsRequired(const upb_FieldDef* f); diff --git a/ruby/ext/google/protobuf_c/ruby-upb.h b/ruby/ext/google/protobuf_c/ruby-upb.h index 22d0fcc807ff0..8ec4602f77a1c 100755 --- a/ruby/ext/google/protobuf_c/ruby-upb.h +++ b/ruby/ext/google/protobuf_c/ruby-upb.h @@ -11534,7 +11534,7 @@ uint32_t upb_FieldDef_Index(const upb_FieldDef* f); bool upb_FieldDef_IsExtension(const upb_FieldDef* f); UPB_API bool upb_FieldDef_IsMap(const upb_FieldDef* f); bool upb_FieldDef_IsOptional(const upb_FieldDef* f); -bool upb_FieldDef_IsPacked(const upb_FieldDef* f); +UPB_API bool upb_FieldDef_IsPacked(const upb_FieldDef* f); bool upb_FieldDef_IsPrimitive(const upb_FieldDef* f); UPB_API bool upb_FieldDef_IsRepeated(const upb_FieldDef* f); bool upb_FieldDef_IsRequired(const upb_FieldDef* f); From 20933b2b22781c9cbd013ef460448a093550e579 Mon Sep 17 00:00:00 2001 From: Alyssa Haroldsen Date: Tue, 9 Jan 2024 10:54:05 -0800 Subject: [PATCH 218/255] Implement singular enum accessors PiperOrigin-RevId: 596984036 --- rust/test/nested.proto | 6 + rust/test/shared/accessors_proto3_test.rs | 68 ++++++++- rust/test/shared/accessors_test.rs | 140 +++++++++++++++++- rust/test/shared/simple_nested_test.rs | 15 +- .../compiler/rust/accessors/accessors.cc | 19 ++- .../rust/accessors/singular_scalar.cc | 24 ++- src/google/protobuf/compiler/rust/context.cc | 4 + src/google/protobuf/compiler/rust/context.h | 1 + src/google/protobuf/compiler/rust/message.cc | 10 +- 9 files changed, 271 insertions(+), 16 deletions(-) diff --git a/rust/test/nested.proto b/rust/test/nested.proto index 40348efca4ef6..aeed9bae3b8dd 100644 --- a/rust/test/nested.proto +++ b/rust/test/nested.proto @@ -15,6 +15,11 @@ message Outer { optional bool flag = 1; } + enum InnerEnum { + INNER_ENUM_UNSPECIFIED = 0; + INNER_ENUM_FOO = 1; + } + optional double double = 1; optional float float = 2; optional int32 int32 = 3; @@ -31,6 +36,7 @@ message Outer { optional string string = 14; optional bytes bytes = 15; optional InnerSubMsg innersubmsg = 16; + optional InnerEnum inner_enum = 17; message SuperInner { message DuperInner { diff --git a/rust/test/shared/accessors_proto3_test.rs b/rust/test/shared/accessors_proto3_test.rs index 4369ae2903126..aee258fa16d63 100644 --- a/rust/test/shared/accessors_proto3_test.rs +++ b/rust/test/shared/accessors_proto3_test.rs @@ -11,7 +11,7 @@ use googletest::prelude::*; use matchers::{is_set, is_unset}; use protobuf::Optional; use unittest_proto3::proto3_unittest::{TestAllTypes, TestAllTypes_}; -use unittest_proto3_optional::proto2_unittest::TestProto3Optional; +use unittest_proto3_optional::proto2_unittest::{TestProto3Optional, TestProto3Optional_}; #[test] fn test_fixed32_accessors() { @@ -184,6 +184,72 @@ fn test_optional_string_accessors() { assert_that!(msg.optional_string_opt(), eq(Optional::Set("".into()))); } +#[test] +fn test_nested_enum_accessors() { + use TestAllTypes_::NestedEnum; + + let mut msg = TestAllTypes::new(); + assert_that!(msg.optional_nested_enum(), eq(NestedEnum::Zero)); + assert_that!(msg.optional_nested_enum_mut().get(), eq(NestedEnum::Zero)); + + msg.optional_nested_enum_mut().set(NestedEnum::Baz); + assert_that!(msg.optional_nested_enum_mut().get(), eq(NestedEnum::Baz)); + assert_that!(msg.optional_nested_enum(), eq(NestedEnum::Baz)); + + msg.optional_nested_enum_mut().set(NestedEnum::default()); + assert_that!(msg.optional_nested_enum(), eq(NestedEnum::Zero)); + assert_that!(msg.optional_nested_enum_mut().get(), eq(NestedEnum::Zero)); +} + +#[test] +fn test_optional_nested_enum_accessors() { + use TestProto3Optional_::NestedEnum; + + let mut msg = TestProto3Optional::new(); + assert_that!(msg.optional_nested_enum(), eq(NestedEnum::Unspecified)); + assert_that!(msg.optional_nested_enum_opt(), eq(Optional::Unset(NestedEnum::Unspecified))); + assert_that!(msg.optional_nested_enum_mut().get(), eq(NestedEnum::Unspecified)); + + msg.optional_nested_enum_mut().set(NestedEnum::Baz); + assert_that!(msg.optional_nested_enum_mut().get(), eq(NestedEnum::Baz)); + assert_that!(msg.optional_nested_enum_opt(), eq(Optional::Set(NestedEnum::Baz))); + assert_that!(msg.optional_nested_enum(), eq(NestedEnum::Baz)); + + msg.optional_nested_enum_mut().set(NestedEnum::default()); + assert_that!(msg.optional_nested_enum(), eq(NestedEnum::Unspecified)); + assert_that!(msg.optional_nested_enum_opt(), eq(Optional::Set(NestedEnum::Unspecified))); + assert_that!(msg.optional_nested_enum_mut().get(), eq(NestedEnum::Unspecified)); + + msg.optional_nested_enum_mut().clear(); + assert_that!(msg.optional_nested_enum(), eq(NestedEnum::Unspecified)); + assert_that!(msg.optional_nested_enum_opt(), eq(Optional::Unset(NestedEnum::Unspecified))); + assert_that!(msg.optional_nested_enum_mut().get(), eq(NestedEnum::Unspecified)); + + let mut field_mut = msg.optional_nested_enum_mut().or_default(); + assert_that!(field_mut.get(), eq(NestedEnum::Unspecified)); + field_mut.set(NestedEnum::Bar); + assert_that!(msg.optional_nested_enum(), eq(NestedEnum::Bar)); + assert_that!(msg.optional_nested_enum_opt(), eq(Optional::Set(NestedEnum::Bar))); + assert_that!(msg.optional_nested_enum_mut().get(), eq(NestedEnum::Bar)); +} + +#[test] +fn test_foreign_enum_accessors() { + use unittest_proto3::proto3_unittest::ForeignEnum; + + let mut msg = TestAllTypes::new(); + assert_that!(msg.optional_foreign_enum(), eq(ForeignEnum::ForeignZero)); + assert_that!(msg.optional_foreign_enum_mut().get(), eq(ForeignEnum::ForeignZero)); + + msg.optional_foreign_enum_mut().set(ForeignEnum::ForeignBaz); + assert_that!(msg.optional_foreign_enum_mut().get(), eq(ForeignEnum::ForeignBaz)); + assert_that!(msg.optional_foreign_enum(), eq(ForeignEnum::ForeignBaz)); + + msg.optional_foreign_enum_mut().set(ForeignEnum::default()); + assert_that!(msg.optional_foreign_enum(), eq(ForeignEnum::ForeignZero)); + assert_that!(msg.optional_foreign_enum_mut().get(), eq(ForeignEnum::ForeignZero)); +} + #[test] fn test_oneof_accessors() { use TestAllTypes_::OneofField::*; diff --git a/rust/test/shared/accessors_test.rs b/rust/test/shared/accessors_test.rs index 289f3765afd67..edf02159dbfdc 100644 --- a/rust/test/shared/accessors_test.rs +++ b/rust/test/shared/accessors_test.rs @@ -668,7 +668,7 @@ fn test_nonempty_default_string_accessors() { #[test] fn test_singular_msg_field() { - use crate::TestAllTypes_::{NestedMessageMut, NestedMessageView}; + use TestAllTypes_::{NestedMessageMut, NestedMessageView}; let mut msg = TestAllTypes::new(); let msg_view: NestedMessageView = msg.optional_nested_message(); @@ -680,6 +680,144 @@ fn test_singular_msg_field() { assert_that!(msg_mut.bb(), eq(0)); } +#[test] +fn test_optional_nested_enum_accessors() { + use TestAllTypes_::NestedEnum; + + let mut msg = TestAllTypes::new(); + assert_that!(msg.optional_nested_enum_opt(), eq(Optional::Unset(NestedEnum::Foo))); + assert_that!(msg.optional_nested_enum(), eq(NestedEnum::Foo)); + + msg.optional_nested_enum_mut().set(NestedEnum::Neg); + assert_that!(msg.optional_nested_enum_opt(), eq(Optional::Set(NestedEnum::Neg))); + assert_that!(msg.optional_nested_enum(), eq(NestedEnum::Neg)); + + msg.optional_nested_enum_mut().clear(); + assert_that!(msg.optional_nested_enum_opt(), eq(Optional::Unset(NestedEnum::Foo))); + assert_that!(msg.optional_nested_enum(), eq(NestedEnum::Foo)); +} + +#[test] +fn test_default_nested_enum_accessors() { + use TestAllTypes_::NestedEnum; + + let mut msg = TestAllTypes::new(); + assert_that!(msg.default_nested_enum(), eq(NestedEnum::Bar)); + assert_that!(msg.default_nested_enum_mut().get(), eq(NestedEnum::Bar)); + assert_that!(msg.default_nested_enum_mut().is_set(), eq(false)); + assert_that!(msg.default_nested_enum_opt(), eq(Optional::Unset(NestedEnum::Bar))); + + msg.default_nested_enum_mut().set(NestedEnum::Baz); + assert_that!(msg.default_nested_enum(), eq(NestedEnum::Baz)); + assert_that!(msg.default_nested_enum_mut().get(), eq(NestedEnum::Baz)); + assert_that!(msg.default_nested_enum_mut().is_set(), eq(true)); + assert_that!(msg.default_nested_enum_opt(), eq(Optional::Set(NestedEnum::Baz))); + + msg.default_nested_enum_mut().clear(); + assert_that!(msg.default_nested_enum(), eq(NestedEnum::Bar)); + assert_that!(msg.default_nested_enum_mut().get(), eq(NestedEnum::Bar)); + assert_that!(msg.default_nested_enum_mut().is_set(), eq(false)); + assert_that!(msg.default_nested_enum_opt(), eq(Optional::Unset(NestedEnum::Bar))); + + msg.default_nested_enum_mut().or_default(); + assert_that!(msg.default_nested_enum(), eq(NestedEnum::Bar)); + assert_that!(msg.default_nested_enum_mut().get(), eq(NestedEnum::Bar)); + assert_that!(msg.default_nested_enum_mut().is_set(), eq(true)); + assert_that!(msg.default_nested_enum_opt(), eq(Optional::Set(NestedEnum::Bar))); +} + +#[test] +fn test_optional_foreign_enum_accessors() { + use unittest_proto::proto2_unittest::ForeignEnum; + + let mut msg = TestAllTypes::new(); + assert_that!(msg.optional_foreign_enum_opt(), eq(Optional::Unset(ForeignEnum::ForeignFoo))); + assert_that!(msg.optional_foreign_enum(), eq(ForeignEnum::ForeignFoo)); + + msg.optional_foreign_enum_mut().set(ForeignEnum::ForeignBax); + assert_that!(msg.optional_foreign_enum_opt(), eq(Optional::Set(ForeignEnum::ForeignBax))); + assert_that!(msg.optional_foreign_enum(), eq(ForeignEnum::ForeignBax)); + + msg.optional_foreign_enum_mut().clear(); + assert_that!(msg.optional_foreign_enum_opt(), eq(Optional::Unset(ForeignEnum::ForeignFoo))); + assert_that!(msg.optional_foreign_enum(), eq(ForeignEnum::ForeignFoo)); +} + +#[test] +fn test_default_foreign_enum_accessors() { + use unittest_proto::proto2_unittest::ForeignEnum; + + let mut msg = TestAllTypes::new(); + assert_that!(msg.default_foreign_enum(), eq(ForeignEnum::ForeignBar)); + assert_that!(msg.default_foreign_enum_mut().get(), eq(ForeignEnum::ForeignBar)); + assert_that!(msg.default_foreign_enum_mut().is_set(), eq(false)); + assert_that!(msg.default_foreign_enum_opt(), eq(Optional::Unset(ForeignEnum::ForeignBar))); + + msg.default_foreign_enum_mut().set(ForeignEnum::ForeignBaz); + assert_that!(msg.default_foreign_enum(), eq(ForeignEnum::ForeignBaz)); + assert_that!(msg.default_foreign_enum_mut().get(), eq(ForeignEnum::ForeignBaz)); + assert_that!(msg.default_foreign_enum_mut().is_set(), eq(true)); + assert_that!(msg.default_foreign_enum_opt(), eq(Optional::Set(ForeignEnum::ForeignBaz))); + + msg.default_foreign_enum_mut().clear(); + assert_that!(msg.default_foreign_enum(), eq(ForeignEnum::ForeignBar)); + assert_that!(msg.default_foreign_enum_mut().get(), eq(ForeignEnum::ForeignBar)); + assert_that!(msg.default_foreign_enum_mut().is_set(), eq(false)); + assert_that!(msg.default_foreign_enum_opt(), eq(Optional::Unset(ForeignEnum::ForeignBar))); + + msg.default_foreign_enum_mut().or_default(); + assert_that!(msg.default_foreign_enum(), eq(ForeignEnum::ForeignBar)); + assert_that!(msg.default_foreign_enum_mut().get(), eq(ForeignEnum::ForeignBar)); + assert_that!(msg.default_foreign_enum_mut().is_set(), eq(true)); + assert_that!(msg.default_foreign_enum_opt(), eq(Optional::Set(ForeignEnum::ForeignBar))); +} + +#[test] +fn test_optional_import_enum_accessors() { + use unittest_proto::proto2_unittest_import::ImportEnum; + + let mut msg = TestAllTypes::new(); + assert_that!(msg.optional_import_enum_opt(), eq(Optional::Unset(ImportEnum::ImportFoo))); + assert_that!(msg.optional_import_enum(), eq(ImportEnum::ImportFoo)); + + msg.optional_import_enum_mut().set(ImportEnum::ImportBar); + assert_that!(msg.optional_import_enum_opt(), eq(Optional::Set(ImportEnum::ImportBar))); + assert_that!(msg.optional_import_enum(), eq(ImportEnum::ImportBar)); + + msg.optional_import_enum_mut().clear(); + assert_that!(msg.optional_import_enum_opt(), eq(Optional::Unset(ImportEnum::ImportFoo))); + assert_that!(msg.optional_import_enum(), eq(ImportEnum::ImportFoo)); +} + +#[test] +fn test_default_import_enum_accessors() { + use unittest_proto::proto2_unittest_import::ImportEnum; + + let mut msg = TestAllTypes::new(); + assert_that!(msg.default_import_enum(), eq(ImportEnum::ImportBar)); + assert_that!(msg.default_import_enum_mut().get(), eq(ImportEnum::ImportBar)); + assert_that!(msg.default_import_enum_mut().is_set(), eq(false)); + assert_that!(msg.default_import_enum_opt(), eq(Optional::Unset(ImportEnum::ImportBar))); + + msg.default_import_enum_mut().set(ImportEnum::ImportBaz); + assert_that!(msg.default_import_enum(), eq(ImportEnum::ImportBaz)); + assert_that!(msg.default_import_enum_mut().get(), eq(ImportEnum::ImportBaz)); + assert_that!(msg.default_import_enum_mut().is_set(), eq(true)); + assert_that!(msg.default_import_enum_opt(), eq(Optional::Set(ImportEnum::ImportBaz))); + + msg.default_import_enum_mut().clear(); + assert_that!(msg.default_import_enum(), eq(ImportEnum::ImportBar)); + assert_that!(msg.default_import_enum_mut().get(), eq(ImportEnum::ImportBar)); + assert_that!(msg.default_import_enum_mut().is_set(), eq(false)); + assert_that!(msg.default_import_enum_opt(), eq(Optional::Unset(ImportEnum::ImportBar))); + + msg.default_import_enum_mut().or_default(); + assert_that!(msg.default_import_enum(), eq(ImportEnum::ImportBar)); + assert_that!(msg.default_import_enum_mut().get(), eq(ImportEnum::ImportBar)); + assert_that!(msg.default_import_enum_mut().is_set(), eq(true)); + assert_that!(msg.default_import_enum_opt(), eq(Optional::Set(ImportEnum::ImportBar))); +} + #[test] fn test_oneof_accessors() { use TestAllTypes_::OneofField::*; diff --git a/rust/test/shared/simple_nested_test.rs b/rust/test/shared/simple_nested_test.rs index 801b491207184..d0f218a829869 100644 --- a/rust/test/shared/simple_nested_test.rs +++ b/rust/test/shared/simple_nested_test.rs @@ -9,6 +9,7 @@ use googletest::prelude::*; use nested_proto::nest::Outer; use nested_proto::nest::Outer_::InnerMut; use nested_proto::nest::Outer_::InnerView; +use nested_proto::nest::Outer_::Inner_::InnerEnum; #[test] fn test_deeply_nested_message() { @@ -22,11 +23,12 @@ fn test_deeply_nested_message() { #[test] fn test_deeply_nested_enum() { - let deep = nested_proto::nest::Outer_::Inner_::SuperInner_::DuperInner_::EvenMoreInner_ - ::JustWayTooInner::default(); + use nested_proto::nest::Outer_::Inner_::SuperInner_::DuperInner_::EvenMoreInner_::JustWayTooInner; + let deep = JustWayTooInner::default(); assert_that!(i32::from(deep), eq(0)); - // TODO: Test deeply nested enum field access. + let outer_msg = Outer::new(); + assert_that!(outer_msg.deep_enum(), eq(JustWayTooInner::Unspecified)); } #[test] @@ -49,6 +51,7 @@ fn test_nested_views() { assert_that!(*inner_msg.string().as_bytes(), empty()); assert_that!(*inner_msg.bytes(), empty()); assert_that!(inner_msg.innersubmsg().flag(), eq(false)); + assert_that!(inner_msg.inner_enum(), eq(InnerEnum::Unspecified)); } #[test] @@ -61,7 +64,7 @@ fn test_nested_muts() { // new: // set_and_test_mut!(inner_msg => double_mut, 543.21); macro_rules! set_and_test_mut { - ( $a:expr => $($target_mut:ident, $val:literal;)* ) => { + ( $a:expr => $($target_mut:ident, $val:expr;)* ) => { $( $a.$target_mut().set($val); assert_that!($a.$target_mut().get(), eq($val)); @@ -86,7 +89,8 @@ fn test_nested_muts() { fixed64(): eq(0), sfixed32(): eq(0), sfixed64(): eq(0), - bool(): eq(false) + bool(): eq(false), + inner_enum(): eq(InnerEnum::Unspecified) }) ); assert_that!(inner_msg.string_mut().get(), eq("")); @@ -106,6 +110,7 @@ fn test_nested_muts() { bool_mut, true; string_mut, "hi"; bytes_mut, b"bye"; + inner_enum_mut, InnerEnum::Foo; ); } diff --git a/src/google/protobuf/compiler/rust/accessors/accessors.cc b/src/google/protobuf/compiler/rust/accessors/accessors.cc index d4c93f00bac45..fce59cb174ff7 100644 --- a/src/google/protobuf/compiler/rust/accessors/accessors.cc +++ b/src/google/protobuf/compiler/rust/accessors/accessors.cc @@ -63,6 +63,18 @@ std::unique_ptr AccessorGeneratorFor( return std::make_unique(); } return std::make_unique(); + case FieldDescriptor::TYPE_ENUM: + // TODO: support enums which are defined in other crates. + if (!IsInCurrentlyGeneratingCrate(ctx, *field.enum_type())) { + return std::make_unique( + "enum fields that are imported from another proto_library" + " (defined in a separate Rust crate) are not supported"); + } + if (field.is_repeated()) { + return std::make_unique( + "repeated enum not supported"); + } + return std::make_unique(); case FieldDescriptor::TYPE_BYTES: case FieldDescriptor::TYPE_STRING: if (field.is_repeated()) { @@ -73,17 +85,14 @@ std::unique_ptr AccessorGeneratorFor( if (field.is_repeated()) { return std::make_unique("repeated msg not supported"); } - if (!ctx.generator_context().is_file_in_current_crate( - *field.message_type()->file())) { + // TODO: support messages which are defined in other crates. + if (!IsInCurrentlyGeneratingCrate(ctx, *field.message_type())) { return std::make_unique( "message fields that are imported from another proto_library" " (defined in a separate Rust crate) are not supported"); } return std::make_unique(); - case FieldDescriptor::TYPE_ENUM: - return std::make_unique("enum not supported"); - case FieldDescriptor::TYPE_GROUP: return std::make_unique("group not supported"); } diff --git a/src/google/protobuf/compiler/rust/accessors/singular_scalar.cc b/src/google/protobuf/compiler/rust/accessors/singular_scalar.cc index dedaa85a6240b..1278fae3695f5 100644 --- a/src/google/protobuf/compiler/rust/accessors/singular_scalar.cc +++ b/src/google/protobuf/compiler/rust/accessors/singular_scalar.cc @@ -5,6 +5,8 @@ // license that can be found in the LICENSE file or at // https://developers.google.com/open-source/licenses/bsd +#include + #include "absl/strings/string_view.h" #include "google/protobuf/compiler/cpp/helpers.h" #include "google/protobuf/compiler/rust/accessors/accessor_generator.h" @@ -117,6 +119,13 @@ void SingularScalar::InMsgImpl(Context& ctx, void SingularScalar::InExternC(Context& ctx, const FieldDescriptor& field) const { + // In order to soundly pass a Rust type to C/C++ as a function argument, + // the types must be FFI-compatible. + // This requires special consideration for enums, which aren't trivial + // primitive types. Rust protobuf enums are defined as `#[repr(transparent)]` + // over `i32`, making them ABI-compatible with `int32_t`. + // Upb defines enum thunks as taking `int32_t`, and so we can pass Rust enums + // directly to thunks without any cast. ctx.Emit({{"Scalar", RsTypePath(ctx, field)}, {"hazzer_thunk", ThunkName(ctx, field, "has")}, {"getter_thunk", ThunkName(ctx, field, "get")}, @@ -141,8 +150,21 @@ void SingularScalar::InExternC(Context& ctx, void SingularScalar::InThunkCc(Context& ctx, const FieldDescriptor& field) const { + std::string scalar; + auto enum_ = field.enum_type(); + if (enum_ != nullptr) { + // The C++ runtime defines its thunks as receiving enum types. + // This is fine since: + // - the C++ runtime represents enums as `int` + // - the C++ runtime guarantees `int` is a `int32_t`. + // - Rust gencode defines enums as `#[repr(transparent)]` over `i32`. + scalar = cpp::QualifiedClassName(enum_); + } else { + scalar = cpp::PrimitiveTypeName(field.cpp_type()); + } + ctx.Emit({{"field", cpp::FieldName(&field)}, - {"Scalar", cpp::PrimitiveTypeName(field.cpp_type())}, + {"Scalar", scalar}, {"QualifiedMsg", cpp::QualifiedClassName(field.containing_type())}, {"hazzer_thunk", ThunkName(ctx, field, "has")}, {"getter_thunk", ThunkName(ctx, field, "get")}, diff --git a/src/google/protobuf/compiler/rust/context.cc b/src/google/protobuf/compiler/rust/context.cc index f64e88aab0f45..f6b1c2e5c5dec 100644 --- a/src/google/protobuf/compiler/rust/context.cc +++ b/src/google/protobuf/compiler/rust/context.cc @@ -76,6 +76,10 @@ bool IsInCurrentlyGeneratingCrate(Context& ctx, const Descriptor& message) { return IsInCurrentlyGeneratingCrate(ctx, *message.file()); } +bool IsInCurrentlyGeneratingCrate(Context& ctx, const EnumDescriptor& enum_) { + return IsInCurrentlyGeneratingCrate(ctx, *enum_.file()); +} + } // namespace rust } // namespace compiler } // namespace protobuf diff --git a/src/google/protobuf/compiler/rust/context.h b/src/google/protobuf/compiler/rust/context.h index 1539e2e8f6fed..6737d32b0ba54 100644 --- a/src/google/protobuf/compiler/rust/context.h +++ b/src/google/protobuf/compiler/rust/context.h @@ -117,6 +117,7 @@ class Context { bool IsInCurrentlyGeneratingCrate(Context& ctx, const FileDescriptor& file); bool IsInCurrentlyGeneratingCrate(Context& ctx, const Descriptor& message); +bool IsInCurrentlyGeneratingCrate(Context& ctx, const EnumDescriptor& enum_); } // namespace rust } // namespace compiler diff --git a/src/google/protobuf/compiler/rust/message.cc b/src/google/protobuf/compiler/rust/message.cc index c1d3ba899e858..2e9e217483773 100644 --- a/src/google/protobuf/compiler/rust/message.cc +++ b/src/google/protobuf/compiler/rust/message.cc @@ -284,6 +284,12 @@ void GetterForViewOrMut(Context& ctx, const FieldDescriptor& field, ? "unsafe { __pb::ProtoStr::from_utf8_unchecked(res).into() }" : "res"; + // TODO: support enums which are defined in other crates. + auto enum_ = field.enum_type(); + if (enum_ != nullptr && !IsInCurrentlyGeneratingCrate(ctx, *enum_)) { + return; + } + ctx.Emit({{"field", fieldName}, {"getter_thunk", getter_thunk}, {"setter_thunk", setter_thunk}, @@ -335,9 +341,7 @@ void AccessorsForViewOrMut(Context& ctx, const Descriptor& msg, bool is_mut) { // TODO - add cord support if (field.options().has_ctype()) continue; // TODO - if (field.type() == FieldDescriptor::TYPE_ENUM || - field.type() == FieldDescriptor::TYPE_GROUP) - continue; + if (field.type() == FieldDescriptor::TYPE_GROUP) continue; GetterForViewOrMut(ctx, field, is_mut); ctx.printer().PrintRaw("\n"); } From 0b5cd4e9ef9a7996a850fadf0f974f5e9fe69df1 Mon Sep 17 00:00:00 2001 From: Alyssa Haroldsen Date: Tue, 9 Jan 2024 10:58:40 -0800 Subject: [PATCH 219/255] Implement repeated enum accessors PiperOrigin-RevId: 596985413 --- rust/test/shared/accessors_repeated_test.rs | 56 ++++++++++++++++--- .../compiler/rust/accessors/accessors.cc | 3 +- 2 files changed, 49 insertions(+), 10 deletions(-) diff --git a/rust/test/shared/accessors_repeated_test.rs b/rust/test/shared/accessors_repeated_test.rs index 1f44a52ac43ff..80c0fa7d5ffac 100644 --- a/rust/test/shared/accessors_repeated_test.rs +++ b/rust/test/shared/accessors_repeated_test.rs @@ -7,7 +7,7 @@ use googletest::prelude::*; use paste::paste; -use unittest_proto::proto2_unittest::TestAllTypes; +use unittest_proto::proto2_unittest::{TestAllTypes, TestAllTypes_}; macro_rules! generate_repeated_numeric_test { ($(($t: ty, $field: ident)),*) => { @@ -34,19 +34,19 @@ macro_rules! generate_repeated_numeric_test { assert_that!( mutator.iter().collect::>(), - eq(vec![2 as $t, 1 as $t, 0 as $t]) + elements_are![eq(2 as $t), eq(1 as $t), eq(0 as $t)] ); assert_that!( (*mutator).into_iter().collect::>(), - eq(vec![2 as $t, 1 as $t, 0 as $t]) + elements_are![eq(2 as $t), eq(1 as $t), eq(0 as $t)] ); for i in 0..mutator.len() { mutator.set(i, 0 as $t); } assert_that!( - msg.[]().iter().all(|v| v == (0 as $t)), - eq(true) + msg.[]().iter().collect::>(), + each(eq(0 as $t)) ); } @@ -99,13 +99,53 @@ fn test_repeated_bool_accessors() { mutator.set(2, false); assert_that!(mutator.get(2), some(eq(false))); - assert_that!(mutator.iter().collect::>(), eq(vec![false, true, false])); - assert_that!((*mutator).into_iter().collect::>(), eq(vec![false, true, false])); + assert_that!(mutator.iter().collect::>(), elements_are![eq(false), eq(true), eq(false)]); + assert_that!( + (*mutator).into_iter().collect::>(), + elements_are![eq(false), eq(true), eq(false)] + ); for i in 0..mutator.len() { mutator.set(i, false); } - assert_that!(msg.repeated_bool().iter().all(|v| v), eq(false)); + assert_that!(msg.repeated_bool().iter().collect::>(), each(eq(false))); +} + +#[test] +fn test_repeated_enum_accessors() { + use TestAllTypes_::NestedEnum; + + let mut msg = TestAllTypes::new(); + assert_that!(msg.repeated_nested_enum().len(), eq(0)); + assert_that!(msg.repeated_nested_enum().get(0), none()); + + let mut mutator = msg.repeated_nested_enum_mut(); + mutator.push(NestedEnum::Foo); + assert_that!(mutator.len(), eq(1)); + assert_that!(mutator.get(0), some(eq(NestedEnum::Foo))); + mutator.set(0, NestedEnum::Bar); + assert_that!(mutator.get(0), some(eq(NestedEnum::Bar))); + mutator.push(NestedEnum::Baz); + + mutator.push(NestedEnum::Foo); + mutator.set(2, NestedEnum::Neg); + assert_that!(mutator.get(2), some(eq(NestedEnum::Neg))); + mutator.set(2, NestedEnum::Foo); + assert_that!(mutator.get(2), some(eq(NestedEnum::Foo))); + + assert_that!( + mutator.iter().collect::>(), + elements_are![eq(NestedEnum::Bar), eq(NestedEnum::Baz), eq(NestedEnum::Foo)] + ); + assert_that!( + (*mutator).into_iter().collect::>(), + elements_are![eq(NestedEnum::Bar), eq(NestedEnum::Baz), eq(NestedEnum::Foo)] + ); + + for i in 0..mutator.len() { + mutator.set(i, NestedEnum::Foo); + } + assert_that!(msg.repeated_nested_enum().iter().collect::>(), each(eq(NestedEnum::Foo))); } #[test] diff --git a/src/google/protobuf/compiler/rust/accessors/accessors.cc b/src/google/protobuf/compiler/rust/accessors/accessors.cc index fce59cb174ff7..2481c29918205 100644 --- a/src/google/protobuf/compiler/rust/accessors/accessors.cc +++ b/src/google/protobuf/compiler/rust/accessors/accessors.cc @@ -71,8 +71,7 @@ std::unique_ptr AccessorGeneratorFor( " (defined in a separate Rust crate) are not supported"); } if (field.is_repeated()) { - return std::make_unique( - "repeated enum not supported"); + return std::make_unique(); } return std::make_unique(); case FieldDescriptor::TYPE_BYTES: From e5b547bcb86ab093d8e8e76a75cb03c9275a0466 Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Tue, 9 Jan 2024 11:17:06 -0800 Subject: [PATCH 220/255] Change MsgMut's _mut() accessors to use (&mut self) instead of (&self) If this took a &self there were holes in thread and memory safety, because it's allowed to get multiple &MsgMuts (but only &mut MsgMuts). PiperOrigin-RevId: 596991263 --- rust/test/shared/simple_nested_test.rs | 2 +- src/google/protobuf/compiler/rust/message.cc | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/rust/test/shared/simple_nested_test.rs b/rust/test/shared/simple_nested_test.rs index d0f218a829869..4a26e58c33ccf 100644 --- a/rust/test/shared/simple_nested_test.rs +++ b/rust/test/shared/simple_nested_test.rs @@ -73,7 +73,7 @@ fn test_nested_muts() { } let mut outer_msg = Outer::new(); - let inner_msg: InnerMut<'_> = outer_msg.inner_mut(); + let mut inner_msg: InnerMut<'_> = outer_msg.inner_mut(); assert_that!( inner_msg, matches_pattern!(InnerMut{ diff --git a/src/google/protobuf/compiler/rust/message.cc b/src/google/protobuf/compiler/rust/message.cc index 2e9e217483773..4affd948cdb4b 100644 --- a/src/google/protobuf/compiler/rust/message.cc +++ b/src/google/protobuf/compiler/rust/message.cc @@ -304,7 +304,7 @@ void GetterForViewOrMut(Context& ctx, const FieldDescriptor& field, // TODO: check mutational pathway genn'd correctly if (is_mut) { ctx.Emit({}, R"rs( - pub fn r#$field$_mut(&self) -> $pb$::Mut<'_, $RsType$> { + pub fn r#$field$_mut(&mut self) -> $pb$::Mut<'_, $RsType$> { static VTABLE: $pbi$::$vtable$$optional_type_args$ = $pbi$::$vtable$::new( $pbi$::Private, From facf959a78a0d8dd5af18b10c752becf21bdbcd1 Mon Sep 17 00:00:00 2001 From: Eric Salo Date: Tue, 9 Jan 2024 12:58:32 -0800 Subject: [PATCH 221/255] upb: tag upb_Array.data as UPB_ONLYBITS() PiperOrigin-RevId: 597019522 --- upb/message/internal/array.h | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/upb/message/internal/array.h b/upb/message/internal/array.h index 96152f0b56768..ef5c413817369 100644 --- a/upb/message/internal/array.h +++ b/upb/message/internal/array.h @@ -8,6 +8,7 @@ #ifndef UPB_MESSAGE_INTERNAL_ARRAY_H_ #define UPB_MESSAGE_INTERNAL_ARRAY_H_ +#include #include #include "upb/mem/arena.h" @@ -33,7 +34,7 @@ struct upb_Array { // 3 maps to elem size 16 // // Bit #2 contains the frozen/immutable flag (currently unimplemented). - uintptr_t data; + uintptr_t UPB_ONLYBITS(data); size_t UPB_ONLYBITS(size); // The number of elements in the array. size_t UPB_PRIVATE(capacity); // Allocated storage. Measured in elements. @@ -44,19 +45,19 @@ UPB_INLINE void UPB_PRIVATE(_upb_Array_SetTaggedPtr)(struct upb_Array* array, UPB_ASSERT(lg2 != 1); UPB_ASSERT(lg2 <= 4); const size_t bits = lg2 - (lg2 != 0); - array->data = (uintptr_t)data | bits; + array->UPB_ONLYBITS(data) = (uintptr_t)data | bits; } UPB_INLINE size_t UPB_PRIVATE(_upb_Array_ElemSizeLg2)(const struct upb_Array* array) { - const size_t bits = array->data & _UPB_ARRAY_MASK_LG2; + const size_t bits = array->UPB_ONLYBITS(data) & _UPB_ARRAY_MASK_LG2; const size_t lg2 = bits + (bits != 0); return lg2; } UPB_INLINE const void* _upb_array_constptr(const struct upb_Array* array) { UPB_PRIVATE(_upb_Array_ElemSizeLg2)(array); // Check assertions. - return (void*)(array->data & ~(uintptr_t)_UPB_ARRAY_MASK_ALL); + return (void*)(array->UPB_ONLYBITS(data) & ~(uintptr_t)_UPB_ARRAY_MASK_ALL); } UPB_INLINE void* _upb_array_ptr(struct upb_Array* array) { From afd94185f7fed16062ec699de37887fec5c8b1ca Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Tue, 9 Jan 2024 21:11:01 +0000 Subject: [PATCH 222/255] Auto-generate files after cl/597019522 --- php/ext/google/protobuf/php-upb.h | 9 +++++---- ruby/ext/google/protobuf_c/ruby-upb.h | 9 +++++---- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/php/ext/google/protobuf/php-upb.h b/php/ext/google/protobuf/php-upb.h index dda30b595c19e..6e43b83c50901 100644 --- a/php/ext/google/protobuf/php-upb.h +++ b/php/ext/google/protobuf/php-upb.h @@ -2698,6 +2698,7 @@ UPB_INLINE struct upb_Map* _upb_Message_GetOrCreateMutableMap( #ifndef UPB_MESSAGE_INTERNAL_ARRAY_H_ #define UPB_MESSAGE_INTERNAL_ARRAY_H_ +#include #include @@ -2721,7 +2722,7 @@ struct upb_Array { // 3 maps to elem size 16 // // Bit #2 contains the frozen/immutable flag (currently unimplemented). - uintptr_t data; + uintptr_t UPB_ONLYBITS(data); size_t UPB_ONLYBITS(size); // The number of elements in the array. size_t UPB_PRIVATE(capacity); // Allocated storage. Measured in elements. @@ -2732,19 +2733,19 @@ UPB_INLINE void UPB_PRIVATE(_upb_Array_SetTaggedPtr)(struct upb_Array* array, UPB_ASSERT(lg2 != 1); UPB_ASSERT(lg2 <= 4); const size_t bits = lg2 - (lg2 != 0); - array->data = (uintptr_t)data | bits; + array->UPB_ONLYBITS(data) = (uintptr_t)data | bits; } UPB_INLINE size_t UPB_PRIVATE(_upb_Array_ElemSizeLg2)(const struct upb_Array* array) { - const size_t bits = array->data & _UPB_ARRAY_MASK_LG2; + const size_t bits = array->UPB_ONLYBITS(data) & _UPB_ARRAY_MASK_LG2; const size_t lg2 = bits + (bits != 0); return lg2; } UPB_INLINE const void* _upb_array_constptr(const struct upb_Array* array) { UPB_PRIVATE(_upb_Array_ElemSizeLg2)(array); // Check assertions. - return (void*)(array->data & ~(uintptr_t)_UPB_ARRAY_MASK_ALL); + return (void*)(array->UPB_ONLYBITS(data) & ~(uintptr_t)_UPB_ARRAY_MASK_ALL); } UPB_INLINE void* _upb_array_ptr(struct upb_Array* array) { diff --git a/ruby/ext/google/protobuf_c/ruby-upb.h b/ruby/ext/google/protobuf_c/ruby-upb.h index 8ec4602f77a1c..8873252159e26 100755 --- a/ruby/ext/google/protobuf_c/ruby-upb.h +++ b/ruby/ext/google/protobuf_c/ruby-upb.h @@ -2700,6 +2700,7 @@ UPB_INLINE struct upb_Map* _upb_Message_GetOrCreateMutableMap( #ifndef UPB_MESSAGE_INTERNAL_ARRAY_H_ #define UPB_MESSAGE_INTERNAL_ARRAY_H_ +#include #include @@ -2723,7 +2724,7 @@ struct upb_Array { // 3 maps to elem size 16 // // Bit #2 contains the frozen/immutable flag (currently unimplemented). - uintptr_t data; + uintptr_t UPB_ONLYBITS(data); size_t UPB_ONLYBITS(size); // The number of elements in the array. size_t UPB_PRIVATE(capacity); // Allocated storage. Measured in elements. @@ -2734,19 +2735,19 @@ UPB_INLINE void UPB_PRIVATE(_upb_Array_SetTaggedPtr)(struct upb_Array* array, UPB_ASSERT(lg2 != 1); UPB_ASSERT(lg2 <= 4); const size_t bits = lg2 - (lg2 != 0); - array->data = (uintptr_t)data | bits; + array->UPB_ONLYBITS(data) = (uintptr_t)data | bits; } UPB_INLINE size_t UPB_PRIVATE(_upb_Array_ElemSizeLg2)(const struct upb_Array* array) { - const size_t bits = array->data & _UPB_ARRAY_MASK_LG2; + const size_t bits = array->UPB_ONLYBITS(data) & _UPB_ARRAY_MASK_LG2; const size_t lg2 = bits + (bits != 0); return lg2; } UPB_INLINE const void* _upb_array_constptr(const struct upb_Array* array) { UPB_PRIVATE(_upb_Array_ElemSizeLg2)(array); // Check assertions. - return (void*)(array->data & ~(uintptr_t)_UPB_ARRAY_MASK_ALL); + return (void*)(array->UPB_ONLYBITS(data) & ~(uintptr_t)_UPB_ARRAY_MASK_ALL); } UPB_INLINE void* _upb_array_ptr(struct upb_Array* array) { From 373192ceff9a59ad7da8e78c072a577ab8c86203 Mon Sep 17 00:00:00 2001 From: Hong Shin Date: Tue, 9 Jan 2024 13:27:20 -0800 Subject: [PATCH 223/255] Expunge unnecessary commentary from singular_message.cc and message.cc codegen PiperOrigin-RevId: 597027922 --- .../compiler/rust/accessors/singular_message.cc | 12 ++++++------ src/google/protobuf/compiler/rust/message.cc | 6 +++--- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/google/protobuf/compiler/rust/accessors/singular_message.cc b/src/google/protobuf/compiler/rust/accessors/singular_message.cc index 81dbc4efe694a..9e045bfb105fa 100644 --- a/src/google/protobuf/compiler/rust/accessors/singular_message.cc +++ b/src/google/protobuf/compiler/rust/accessors/singular_message.cc @@ -36,11 +36,11 @@ void SingularMessage::InMsgImpl(Context& ctx, if (ctx.is_upb()) { ctx.Emit({}, R"rs( let submsg = unsafe { $getter_thunk$(self.inner.msg) }; - // For upb, getters return null if the field is unset, so we need - // to check for null and return the default instance manually. - // Note that a nullptr received from upb manifests as Option::None + //~ For upb, getters return null if the field is unset, so we need + //~ to check for null and return the default instance manually. + //~ Note that a nullptr received from upb manifests as Option::None match submsg { - // TODO:(b/304357029) + //~ TODO:(b/304357029) None => $prefix$View::new($pbi$::Private, $pbr$::ScratchSpace::zeroed_block($pbi$::Private)), Some(field) => $prefix$View::new($pbi$::Private, field), @@ -48,8 +48,8 @@ void SingularMessage::InMsgImpl(Context& ctx, )rs"); } else { ctx.Emit({}, R"rs( - // For C++ kernel, getters automatically return the - // default_instance if the field is unset. + //~ For C++ kernel, getters automatically return the + //~ default_instance if the field is unset. let submsg = unsafe { $getter_thunk$(self.inner.msg) }; $prefix$View::new($pbi$::Private, submsg) )rs"); diff --git a/src/google/protobuf/compiler/rust/message.cc b/src/google/protobuf/compiler/rust/message.cc index 4affd948cdb4b..6ead0f0bb3ccd 100644 --- a/src/google/protobuf/compiler/rust/message.cc +++ b/src/google/protobuf/compiler/rust/message.cc @@ -110,8 +110,8 @@ void MessageDeserialize(Context& ctx, const Descriptor& msg) { match msg { None => Err($pb$::ParseError), Some(msg) => { - // This assignment causes self.arena to be dropped and to deallocate - // any previous message pointed/owned to by self.inner.msg. + //~ This assignment causes self.arena to be dropped and to deallocate + //~ any previous message pointed/owned to by self.inner.msg. self.inner.arena = arena; self.inner.msg = msg; Ok(()) @@ -437,7 +437,7 @@ void GenerateRs(Context& ctx, const Descriptor& msg) { {"settable_impl", [&] { MessageSettableValue(ctx, msg); }}}, R"rs( #[allow(non_camel_case_types)] - // TODO: Implement support for debug redaction + //~ TODO: Implement support for debug redaction #[derive(Debug)] pub struct $Msg$ { inner: $pbr$::MessageInner From c5083a855a944464e5af3b88fe39b44ca899ef49 Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Tue, 9 Jan 2024 14:13:03 -0800 Subject: [PATCH 224/255] InlinedArena needs copy constructor and copy assignment operator deleted Deletes the default copy constructor and assignment operator. PiperOrigin-RevId: 597041019 --- upb/mem/arena.hpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/upb/mem/arena.hpp b/upb/mem/arena.hpp index 4a0bc330f4cf0..9c03a3022dec2 100644 --- a/upb/mem/arena.hpp +++ b/upb/mem/arena.hpp @@ -30,8 +30,8 @@ class Arena { std::unique_ptr ptr_; }; -// InlinedArena seeds the arenas with a predefined amount of memory. No -// heap memory will be allocated until the initial block is exceeded. +// InlinedArena seeds the arenas with a predefined amount of memory. No heap +// memory will be allocated until the initial block is exceeded. template class InlinedArena : public Arena { public: @@ -43,8 +43,8 @@ class InlinedArena : public Arena { } private: - InlinedArena(const InlinedArena*) = delete; - InlinedArena& operator=(const InlinedArena*) = delete; + InlinedArena(const InlinedArena&) = delete; + InlinedArena& operator=(const InlinedArena&) = delete; char initial_block_[N]; }; From 3b5b6e9f0221fb06a40fb43715934c2946afdba9 Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Tue, 9 Jan 2024 15:26:15 -0800 Subject: [PATCH 225/255] Allow friendly use of Reflection::MutableRaw(), Reflection::MutableRawNonOneof(). PiperOrigin-RevId: 597061355 --- .../protobuf/generated_message_reflection.cc | 60 ++++++------- src/google/protobuf/message.h | 88 ++++++++++++++----- 2 files changed, 92 insertions(+), 56 deletions(-) diff --git a/src/google/protobuf/generated_message_reflection.cc b/src/google/protobuf/generated_message_reflection.cc index 647b4cc747b80..164669cabe811 100644 --- a/src/google/protobuf/generated_message_reflection.cc +++ b/src/google/protobuf/generated_message_reflection.cc @@ -2659,20 +2659,6 @@ const FieldDescriptor* Reflection::FindKnownExtensionByNumber( // These simple template accessors obtain pointers (or references) to // the given field. -template -const Type& Reflection::GetRawNonOneof(const Message& message, - const FieldDescriptor* field) const { - const uint32_t field_offset = schema_.GetFieldOffsetNonOneof(field); - if (!schema_.IsSplit(field)) { - return GetConstRefAtOffset(message, field_offset); - } - const void* split = GetSplitField(&message); - if (SplitFieldHasExtraIndirection(field)) { - return **GetConstPointerAtOffset(split, field_offset); - } - return *GetConstPointerAtOffset(split, field_offset); -} - void Reflection::PrepareSplitMessageForWrite(Message* message) const { ABSL_DCHECK_NE(message, schema_.default_instance_); void** split = MutableSplitField(message); @@ -2705,38 +2691,42 @@ static Type* AllocIfDefault(const FieldDescriptor* field, Type*& ptr, return ptr; } -template -Type* Reflection::MutableRawNonOneof(Message* message, - const FieldDescriptor* field) const { +void* Reflection::MutableRawSplitImpl(Message* message, + const FieldDescriptor* field) const { + ABSL_DCHECK(!schema_.InRealOneof(field)) << "Field = " << field->full_name(); + const uint32_t field_offset = schema_.GetFieldOffsetNonOneof(field); - if (!schema_.IsSplit(field)) { - return GetPointerAtOffset(message, field_offset); - } PrepareSplitMessageForWrite(message); void** split = MutableSplitField(message); if (SplitFieldHasExtraIndirection(field)) { return AllocIfDefault(field, - *GetPointerAtOffset(*split, field_offset), + *GetPointerAtOffset(*split, field_offset), message->GetArena()); } - return GetPointerAtOffset(*split, field_offset); + return GetPointerAtOffset(*split, field_offset); } -template -Type* Reflection::MutableRaw(Message* message, - const FieldDescriptor* field) const { - const uint32_t field_offset = schema_.GetFieldOffset(field); - if (!schema_.IsSplit(field)) { - return GetPointerAtOffset(message, field_offset); +void* Reflection::MutableRawNonOneofImpl(Message* message, + const FieldDescriptor* field) const { + if (PROTOBUF_PREDICT_FALSE(schema_.IsSplit(field))) { + return MutableRawSplitImpl(message, field); } - PrepareSplitMessageForWrite(message); - void** split = MutableSplitField(message); - if (SplitFieldHasExtraIndirection(field)) { - return AllocIfDefault(field, - *GetPointerAtOffset(*split, field_offset), - message->GetArena()); + + const uint32_t field_offset = schema_.GetFieldOffsetNonOneof(field); + return GetPointerAtOffset(message, field_offset); +} + +void* Reflection::MutableRawImpl(Message* message, + const FieldDescriptor* field) const { + if (PROTOBUF_PREDICT_TRUE(!schema_.InRealOneof(field))) { + return MutableRawNonOneofImpl(message, field); } - return GetPointerAtOffset(*split, field_offset); + + // Oneof fields are not split. + ABSL_DCHECK(!schema_.IsSplit(field)); + + const uint32_t field_offset = schema_.GetFieldOffset(field); + return GetPointerAtOffset(message, field_offset); } const uint32_t* Reflection::GetHasBits(const Message& message) const { diff --git a/src/google/protobuf/message.h b/src/google/protobuf/message.h index 8886cd1846513..adfc8d1533537 100644 --- a/src/google/protobuf/message.h +++ b/src/google/protobuf/message.h @@ -1104,19 +1104,34 @@ class PROTOBUF_EXPORT Reflection final { const T& GetRawNonOneof(const Message& message, const FieldDescriptor* field) const; template - T* MutableRawNonOneof(Message* message, const FieldDescriptor* field) const; - + const T& GetRawSplit(const Message& message, + const FieldDescriptor* field) const; template const Type& GetRaw(const Message& message, const FieldDescriptor* field) const; + + void* MutableRawNonOneofImpl(Message* message, + const FieldDescriptor* field) const; + void* MutableRawSplitImpl(Message* message, + const FieldDescriptor* field) const; + void* MutableRawImpl(Message* message, const FieldDescriptor* field) const; + template - inline Type* MutableRaw(Message* message, const FieldDescriptor* field) const; + Type* MutableRawNonOneof(Message* message, + const FieldDescriptor* field) const { + return reinterpret_cast(MutableRawNonOneofImpl(message, field)); + } + template + Type* MutableRaw(Message* message, const FieldDescriptor* field) const { + return reinterpret_cast(MutableRawImpl(message, field)); + } + template const Type& DefaultRaw(const FieldDescriptor* field) const; const Message* GetDefaultMessageInstance(const FieldDescriptor* field) const; - inline const uint32_t* GetHasBits(const Message& message) const; + const uint32_t* GetHasBits(const Message& message) const; inline uint32_t* MutableHasBits(Message* message) const; uint32_t GetOneofCase(const Message& message, const OneofDescriptor* oneof_descriptor) const; @@ -1135,9 +1150,8 @@ class PROTOBUF_EXPORT Reflection final { inline bool IsInlined(const FieldDescriptor* field) const; - inline bool HasBit(const Message& message, - const FieldDescriptor* field) const; - inline void SetBit(Message* message, const FieldDescriptor* field) const; + bool HasBit(const Message& message, const FieldDescriptor* field) const; + void SetBit(Message* message, const FieldDescriptor* field) const; inline void ClearBit(Message* message, const FieldDescriptor* field) const; inline void SwapBit(Message* message1, Message* message2, const FieldDescriptor* field) const; @@ -1187,8 +1201,7 @@ class PROTOBUF_EXPORT Reflection final { const FieldDescriptor* field) const; inline void SetOneofCase(Message* message, const FieldDescriptor* field) const; - inline void ClearOneofField(Message* message, - const FieldDescriptor* field) const; + void ClearOneofField(Message* message, const FieldDescriptor* field) const; template inline const Type& GetField(const Message& message, @@ -1528,12 +1541,21 @@ void** Reflection::MutableSplitField(Message* message) const { namespace internal { +// In some cases, (Get|Mutable)Raw may be called with a type that is different +// from the final type; e.g. char. As a defensive coding to this unfortunate +// practices, we should only assume extra indirection (or a lack thereof) for +// the well known, complex types. template bool SplitFieldHasExtraIndirectionStatic(const FieldDescriptor* field) { - const bool ret = std::is_base_of() || - std::is_base_of(); - ABSL_DCHECK_EQ(SplitFieldHasExtraIndirection(field), ret); - return ret; + if (std::is_base_of() || + std::is_base_of()) { + ABSL_DCHECK(SplitFieldHasExtraIndirection(field)); + return true; + } else if (std::is_base_of()) { + ABSL_DCHECK(!SplitFieldHasExtraIndirection(field)); + return false; + } + return SplitFieldHasExtraIndirection(field); } class RawMessageBase : public Message { @@ -1545,21 +1567,45 @@ class RawMessageBase : public Message { } // namespace internal template -const Type& Reflection::GetRaw(const Message& message, - const FieldDescriptor* field) const { - ABSL_DCHECK(!schema_.InRealOneof(field) || HasOneofField(message, field)) - << "Field = " << field->full_name(); - const uint32_t field_offset = schema_.GetFieldOffset(field); - if (!schema_.IsSplit(field)) { - return internal::GetConstRefAtOffset(message, field_offset); - } +const Type& Reflection::GetRawSplit(const Message& message, + const FieldDescriptor* field) const { + ABSL_DCHECK(!schema_.InRealOneof(field)) << "Field = " << field->full_name(); + const void* split = GetSplitField(&message); + const uint32_t field_offset = schema_.GetFieldOffsetNonOneof(field); if (internal::SplitFieldHasExtraIndirectionStatic(field)) { return **internal::GetConstPointerAtOffset(split, field_offset); } return *internal::GetConstPointerAtOffset(split, field_offset); } +template +const Type& Reflection::GetRawNonOneof(const Message& message, + const FieldDescriptor* field) const { + if (PROTOBUF_PREDICT_FALSE(schema_.IsSplit(field))) { + return GetRawSplit(message, field); + } + const uint32_t field_offset = schema_.GetFieldOffsetNonOneof(field); + return internal::GetConstRefAtOffset(message, field_offset); +} + +template +const Type& Reflection::GetRaw(const Message& message, + const FieldDescriptor* field) const { + ABSL_DCHECK(!schema_.InRealOneof(field) || HasOneofField(message, field)) + << "Field = " << field->full_name(); + + if (PROTOBUF_PREDICT_TRUE(!schema_.InRealOneof(field))) { + return GetRawNonOneof(message, field); + } + + // Oneof fields are not split. + ABSL_DCHECK(!schema_.IsSplit(field)); + + const uint32_t field_offset = schema_.GetFieldOffset(field); + return internal::GetConstRefAtOffset(message, field_offset); +} + template RepeatedFieldRef Reflection::GetRepeatedFieldRef( const Message& message, const FieldDescriptor* field) const { From 7d6198ed425b8decb16e7e620b20f7fff2e427a2 Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Tue, 9 Jan 2024 16:52:27 -0800 Subject: [PATCH 226/255] Print usage count if it's rarely used. PiperOrigin-RevId: 597083184 --- .../compiler/cpp/tools/analyze_profile_proto.cc | 3 ++- .../compiler/cpp/tools/analyze_profile_proto_test.cc | 12 ++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/google/protobuf/compiler/cpp/tools/analyze_profile_proto.cc b/src/google/protobuf/compiler/cpp/tools/analyze_profile_proto.cc index 5621d1922bc2b..ce6211c6eaf77 100644 --- a/src/google/protobuf/compiler/cpp/tools/analyze_profile_proto.cc +++ b/src/google/protobuf/compiler/cpp/tools/analyze_profile_proto.cc @@ -440,7 +440,8 @@ static absl::StatusOr AnalyzeProfileProto( stream << " " << analysis.presence << "_PRESENT"; } if (analysis.usage != PDProtoScale::kDefault) { - stream << " " << analysis.usage << "_USED"; + stream << " " << analysis.usage << "_USED(" + << analysis.usage_count << ")"; } } if (optimized != PDProtoOptimization::kNone) { diff --git a/src/google/protobuf/compiler/cpp/tools/analyze_profile_proto_test.cc b/src/google/protobuf/compiler/cpp/tools/analyze_profile_proto_test.cc index 35eab5bb0cf0e..a288702f82a59 100644 --- a/src/google/protobuf/compiler/cpp/tools/analyze_profile_proto_test.cc +++ b/src/google/protobuf/compiler/cpp/tools/analyze_profile_proto_test.cc @@ -184,12 +184,12 @@ TEST(AnalyzeProfileProtoTest, PrintStatistics) { options.pool = DescriptorPool::generated_pool(); EXPECT_STREQ(AnalyzeToText(info, options).c_str(), R"(Message google::protobuf::compiler::tools::AnalyzeThis - int32 id: RARELY_USED - string optional_string: RARELY_USED - string[] repeated_string: LIKELY_PRESENT RARELY_USED - AnalyzeChild optional_child: LIKELY_PRESENT RARELY_USED LAZY - AnalyzeChild[] repeated_child: LIKELY_PRESENT RARELY_USED - Nested nested: RARELY_USED + int32 id: RARELY_USED(100) + string optional_string: RARELY_USED(100) + string[] repeated_string: LIKELY_PRESENT RARELY_USED(100) + AnalyzeChild optional_child: LIKELY_PRESENT RARELY_USED(1) LAZY + AnalyzeChild[] repeated_child: LIKELY_PRESENT RARELY_USED(100) + Nested nested: RARELY_USED(100) ======== singular_lazy_num=1 singular_lazy_0usage_num=0 From 0ce457f6e7c15e2574d69ba445ea6cae7e6e44e8 Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Tue, 9 Jan 2024 17:20:28 -0800 Subject: [PATCH 227/255] Adds mutable extension accessors to the codegen for upb C and adds a `::protos::MutableExtension` method to upb C++ for getting a mutable extension. PiperOrigin-RevId: 597088960 --- protos/protos.h | 20 +++++++ protos_generator/tests/test_generated.cc | 41 ++++++++++++++ upb/message/internal/accessors.h | 26 +++++++++ upb/message/promote.c | 72 ++++++++++++++++++++---- upb/message/promote.h | 9 +++ upb/message/test.cc | 7 +++ upb_generator/protoc-gen-upb.cc | 30 +++++++++- 7 files changed, 191 insertions(+), 14 deletions(-) diff --git a/protos/protos.h b/protos/protos.h index db06de80fd7bc..c1701f0807064 100644 --- a/protos/protos.h +++ b/protos/protos.h @@ -18,6 +18,7 @@ #include "upb/message/copy.h" #include "upb/message/internal/accessors.h" #include "upb/message/internal/extension.h" +#include "upb/message/promote.h" #include "upb/mini_table/extension.h" #include "upb/wire/decode.h" #include "upb/wire/encode.h" @@ -429,6 +430,25 @@ absl::StatusOr> GetExtension( return GetExtension(protos::Ptr(message), id); } +template , typename = EnableIfMutableProto> +absl::StatusOr> MutableExtension( + Ptr message, + const ::protos::internal::ExtensionIdentifier& id) { + upb_Arena* arena = ::protos::internal::GetArena(message); + upb_Extension* ext; + upb_GetExtension_Status status = upb_MiniTable_GetOrPromoteOrCreateExtension( + internal::GetInternalMsg(message), id.mini_table_ext(), 0, arena, &ext); + if (status == kUpb_GetExtension_OutOfMemory) { + return MessageAllocationError(); + } else if (status != kUpb_GetExtension_Ok) { + return ExtensionNotFoundError( + upb_MiniTableExtension_Number(id.mini_table_ext())); + } + return Ptr(::protos::internal::CreateMessageProxy( + static_cast(ext->data.ptr), arena)); +} + template ABSL_MUST_USE_RESULT bool Parse(Ptr message, absl::string_view bytes) { static_assert(!std::is_const_v); diff --git a/protos_generator/tests/test_generated.cc b/protos_generator/tests/test_generated.cc index ffa3d5cb8de47..7639faad249c0 100644 --- a/protos_generator/tests/test_generated.cc +++ b/protos_generator/tests/test_generated.cc @@ -824,6 +824,47 @@ TEST(CppGeneratedCode, GetExtensionOnImmutableChild) { ::protos::GetExtension(recursive_child, theme).value()->ext_name()); } +TEST(CppGeneratedCode, MutableExtension) { + ::protos::Arena arena; + ::protos::Ptr model = ::protos::CreateMessage(arena); + EXPECT_EQ(false, ::protos::HasExtension(model, theme)); + absl::StatusOr<::protos::Ptr> extension1 = + ::protos::MutableExtension(model, theme); + EXPECT_EQ(true, extension1.ok()); + (*extension1)->set_ext_name("Hello World"); + EXPECT_EQ("Hello World", + ::protos::GetExtension(model, theme).value()->ext_name()); +} + +TEST(CppGeneratedCode, MutableExtensionOnMutableChild) { + TestModel model; + ::protos::Ptr mutable_recursive_child = + model.mutable_recursive_child(); + EXPECT_EQ(false, ::protos::HasExtension(mutable_recursive_child, theme)); + absl::StatusOr<::protos::Ptr> extension1 = + ::protos::MutableExtension(mutable_recursive_child, theme); + EXPECT_EQ(true, extension1.ok()); + (*extension1)->set_ext_name("Hello World"); + EXPECT_EQ("Hello World", + ::protos::GetExtension(mutable_recursive_child, theme) + .value() + ->ext_name()); +} + +TEST(CppGeneratedCode, MutableExtensionOnImmutableChild) { + TestModel model; + ::protos::Ptr mutable_recursive_child = + model.mutable_recursive_child(); + EXPECT_EQ(false, ::protos::HasExtension(mutable_recursive_child, theme)); + absl::StatusOr<::protos::Ptr> extension1 = + ::protos::MutableExtension(mutable_recursive_child, theme); + EXPECT_EQ(true, extension1.ok()); + (*extension1)->set_ext_name("Hello World"); + ::protos::Ptr recursive_child = model.recursive_child(); + EXPECT_EQ("Hello World", + ::protos::GetExtension(recursive_child, theme).value()->ext_name()); +} + TEST(CppGeneratedCode, SerializeUsingArena) { TestModel model; model.set_str1("Hello World"); diff --git a/upb/message/internal/accessors.h b/upb/message/internal/accessors.h index b6ab3587bb1df..997a3521105de 100644 --- a/upb/message/internal/accessors.h +++ b/upb/message/internal/accessors.h @@ -259,6 +259,32 @@ UPB_INLINE void _upb_Message_GetExtensionField( } } +// Gets a extension message or creates a default message and sets the extension +// if it doesn't already exist. +UPB_INLINE bool _upb_Message_GetOrCreateExtensionSubmessage( + struct upb_Message* msg, const upb_MiniTableExtension* mt_ext, + struct upb_Message** val, upb_Arena* a) { + const upb_MiniTableField* f = &mt_ext->UPB_PRIVATE(field); + UPB_ASSUME(upb_MiniTableField_IsExtension(f)); + const struct upb_Extension* const_ext = _upb_Message_Getext(msg, mt_ext); + if (const_ext) { + // Extension exists, get a mutable version of it. + struct upb_Extension* ext = + _upb_Message_GetOrCreateExtension(msg, mt_ext, a); + *val = (struct upb_Message*)ext->data.ptr; + return true; + } + // Extension doesn't exist, create a new message and set it. + struct upb_Message* ext_msg = + _upb_Message_New(upb_MiniTableExtension_GetSubMessage(mt_ext), a); + if (!ext_msg) return false; + struct upb_Extension* ext = _upb_Message_GetOrCreateExtension(msg, mt_ext, a); + if (!ext) return false; + ext->data.ptr = ext_msg; + *val = ext_msg; + return true; +} + UPB_INLINE void _upb_Message_SetNonExtensionField( struct upb_Message* msg, const upb_MiniTableField* field, const void* val) { UPB_ASSUME(!upb_MiniTableField_IsExtension(field)); diff --git a/upb/message/promote.c b/upb/message/promote.c index 2cd0888c83e57..27a9e1e6b03c2 100644 --- a/upb/message/promote.c +++ b/upb/message/promote.c @@ -64,17 +64,11 @@ static upb_UnknownToMessageRet upb_MiniTable_ParseUnknownMessage( return ret; } -upb_GetExtension_Status upb_MiniTable_GetOrPromoteExtension( +// Promotes unknown data to an extension by finding the field number in unknown +// data and decoding it. +static upb_GetExtension_Status upb_MiniTable_PromoteExtension( upb_Message* msg, const upb_MiniTableExtension* ext_table, - int decode_options, upb_Arena* arena, const upb_Extension** extension) { - UPB_ASSERT(upb_MiniTableField_CType(upb_MiniTableExtension_AsField( - ext_table)) == kUpb_CType_Message); - *extension = _upb_Message_Getext(msg, ext_table); - if (*extension) { - return kUpb_GetExtension_Ok; - } - - // Check unknown fields, if available promote. + int decode_options, upb_Arena* arena, upb_Extension** extension) { int field_number = upb_MiniTableExtension_Number(ext_table); upb_FindUnknownRet result = upb_Message_FindUnknown(msg, field_number, 0); if (result.status != kUpb_FindUnknown_Ok) { @@ -98,19 +92,73 @@ upb_GetExtension_Status upb_MiniTable_GetOrPromoteExtension( case kUpb_UnknownToMessage_Ok: break; } - upb_Message* extension_msg = parse_result.message; // Add to extensions. upb_Extension* ext = _upb_Message_GetOrCreateExtension(msg, ext_table, arena); if (!ext) { return kUpb_GetExtension_OutOfMemory; } - memcpy(&ext->data, &extension_msg, sizeof(extension_msg)); + ext->data.ptr = parse_result.message; *extension = ext; const char* delete_ptr = upb_Message_GetUnknown(msg, &len) + ofs; upb_Message_DeleteUnknown(msg, delete_ptr, result.len); return kUpb_GetExtension_Ok; } +upb_GetExtension_Status upb_MiniTable_GetOrPromoteExtension( + upb_Message* msg, const upb_MiniTableExtension* ext_table, + int decode_options, upb_Arena* arena, const upb_Extension** extension) { + UPB_ASSERT(upb_MiniTableField_CType(upb_MiniTableExtension_AsField( + ext_table)) == kUpb_CType_Message); + *extension = _upb_Message_Getext(msg, ext_table); + if (*extension) { + return kUpb_GetExtension_Ok; + } + + // Check unknown fields, if available promote. + upb_Extension* ext; + upb_GetExtension_Status promote_result = upb_MiniTable_PromoteExtension( + msg, ext_table, decode_options, arena, &ext); + if (promote_result == kUpb_GetExtension_Ok) { + *extension = ext; + } + return promote_result; +} + +upb_GetExtension_Status upb_MiniTable_GetOrPromoteOrCreateExtension( + upb_Message* msg, const upb_MiniTableExtension* ext_table, + int decode_options, upb_Arena* arena, upb_Extension** extension) { + UPB_ASSERT(upb_MiniTableField_CType(upb_MiniTableExtension_AsField( + ext_table)) == kUpb_CType_Message); + const upb_Extension* const_extension = _upb_Message_Getext(msg, ext_table); + if (const_extension) { + // Extension exists on the message, get the mutable version of it. + *extension = _upb_Message_GetOrCreateExtension(msg, ext_table, arena); + return kUpb_GetExtension_Ok; + } + + // Check unknown fields, if available promote. + upb_GetExtension_Status promote_result = upb_MiniTable_PromoteExtension( + msg, ext_table, decode_options, arena, extension); + if (promote_result != kUpb_GetExtension_NotPresent) { + return promote_result; + } + + // Extension not found, create a new default message. + const upb_MiniTable* extension_table = + upb_MiniTableExtension_GetSubMessage(ext_table); + upb_Message* extension_msg = upb_Message_New(extension_table, arena); + if (!extension_msg) { + return kUpb_GetExtension_OutOfMemory; + } + upb_Extension* ext = _upb_Message_GetOrCreateExtension(msg, ext_table, arena); + if (!ext) { + return kUpb_GetExtension_OutOfMemory; + } + ext->data.ptr = extension_msg; + *extension = ext; + return kUpb_GetExtension_Ok; +} + static upb_FindUnknownRet upb_FindUnknownRet_ParseError(void) { return (upb_FindUnknownRet){.status = kUpb_FindUnknown_ParseError}; } diff --git a/upb/message/promote.h b/upb/message/promote.h index 0a43f6bf708c5..4eefb06b6e072 100644 --- a/upb/message/promote.h +++ b/upb/message/promote.h @@ -42,6 +42,15 @@ upb_GetExtension_Status upb_MiniTable_GetOrPromoteExtension( upb_Message* msg, const upb_MiniTableExtension* ext_table, int decode_options, upb_Arena* arena, const upb_Extension** extension); +// Returns a mutable message extension, promotes an unknown field to a mutable +// extension, or creates a new extension. +// +// TODO Only supports extension fields that are messages, +// expand support to include non-message types. +upb_GetExtension_Status upb_MiniTable_GetOrPromoteOrCreateExtension( + upb_Message* msg, const upb_MiniTableExtension* ext_table, + int decode_options, upb_Arena* arena, upb_Extension** extension); + typedef enum { kUpb_FindUnknown_Ok, kUpb_FindUnknown_NotPresent, diff --git a/upb/message/test.cc b/upb/message/test.cc index 2bb46bdaab87b..5ed84aa57ec1f 100644 --- a/upb/message/test.cc +++ b/upb/message/test.cc @@ -104,6 +104,13 @@ TEST(MessageTest, Extensions) { defpool.ptr(), 0, arena.ptr(), status.ptr())) << status.error_message(); VerifyMessage(ext_msg3); + + // Test setters and mutable accessors + upb_test_TestExtensions* ext_msg4 = upb_test_TestExtensions_new(arena.ptr()); + upb_test_TestExtensions_set_optional_int32_ext(ext_msg4, 123, arena.ptr()); + protobuf_test_messages_proto3_TestAllTypesProto3_set_optional_int32( + upb_test_mutable_optional_msg_ext(ext_msg4, arena.ptr()), 456); + VerifyMessage(ext_msg4); } void VerifyMessageSet(const upb_test_TestMessageSet* mset_msg) { diff --git a/upb_generator/protoc-gen-upb.cc b/upb_generator/protoc-gen-upb.cc index eb71edd7736f0..e6f8c2b424070 100644 --- a/upb_generator/protoc-gen-upb.cc +++ b/upb_generator/protoc-gen-upb.cc @@ -27,6 +27,7 @@ #include "absl/strings/string_view.h" #include "absl/strings/substitute.h" #include "upb/base/descriptor_constants.h" +#include "upb/base/status.hpp" #include "upb/base/string_view.h" #include "upb/reflection/def.hpp" #include "upb/wire/types.h" @@ -256,7 +257,7 @@ std::string GetFieldRep(const DefPoolPair& pools, upb::FieldDefPtr field) { } void GenerateExtensionInHeader(const DefPoolPair& pools, upb::FieldDefPtr ext, - Output& output) { + const Options& options, Output& output) { output( R"cc( UPB_INLINE bool $0_has_$1(const struct $2* msg) { @@ -308,6 +309,31 @@ void GenerateExtensionInHeader(const DefPoolPair& pools, upb::FieldDefPtr ext, CTypeConst(ext), ExtensionIdentBase(ext), ext.name(), MessageName(ext.containing_type()), ExtensionLayout(ext), GetFieldRep(pools, ext)); + + // Message extensions also have a Msg_mutable_foo() accessor that will + // create the sub-message if it doesn't already exist. + if (ext.ctype() == kUpb_CType_Message && + !UPB_DESC(MessageOptions_map_entry)(ext.containing_type().options())) { + output( + R"cc( + UPB_INLINE struct $0* $1_mutable_$2(struct $3* msg, + upb_Arena* arena) { + const upb_MiniTableExtension* ext = &$4; + UPB_ASSUME(upb_MiniTableField_IsScalar(&ext->UPB_PRIVATE(field))); + UPB_ASSUME(upb_MiniTableField_IsSubMessage(&ext->UPB_PRIVATE(field))); + UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)( + &ext->UPB_PRIVATE(field)) == $5); + upb_Message* ret; + bool ok = _upb_Message_GetOrCreateExtensionSubmessage( + (upb_Message*)msg, ext, &ret, arena); + if (!ok) return NULL; + return ($0*)ret; + } + )cc", + MessageName(ext.message_type()), ExtensionIdentBase(ext), ext.name(), + MessageName(ext.containing_type()), ExtensionLayout(ext), + GetFieldRep(pools, ext)); + } } } @@ -927,7 +953,7 @@ void WriteHeader(const DefPoolPair& pools, upb::FileDefPtr file, } for (auto ext : this_file_exts) { - GenerateExtensionInHeader(pools, ext, output); + GenerateExtensionInHeader(pools, ext, options, output); } if (absl::string_view(file.name()) == "google/protobuf/descriptor.proto" || From 755b690a7c31d92103343f20ba32d752495e60a3 Mon Sep 17 00:00:00 2001 From: Mike Kruskal Date: Tue, 9 Jan 2024 17:32:10 -0800 Subject: [PATCH 228/255] Breaking change: disallow incorrect ctype usage PiperOrigin-RevId: 597091014 --- src/google/protobuf/compiler/cpp/generator.cc | 2 -- src/google/protobuf/compiler/cpp/generator_unittest.cc | 2 -- src/google/protobuf/port_def.inc | 4 ---- 3 files changed, 8 deletions(-) diff --git a/src/google/protobuf/compiler/cpp/generator.cc b/src/google/protobuf/compiler/cpp/generator.cc index bd9ea7d1fb71a..cbff8cdaefcc7 100644 --- a/src/google/protobuf/compiler/cpp/generator.cc +++ b/src/google/protobuf/compiler/cpp/generator.cc @@ -376,7 +376,6 @@ absl::Status CppGenerator::ValidateFeatures(const FileDescriptor* file) const { } } -#ifdef PROTOBUF_FUTURE_REMOVE_WRONG_CTYPE if (field.options().has_ctype()) { if (field.cpp_type() != FieldDescriptor::CPPTYPE_STRING) { status = absl::FailedPreconditionError(absl::StrCat( @@ -391,7 +390,6 @@ absl::Status CppGenerator::ValidateFeatures(const FileDescriptor* file) const { } } } -#endif // !PROTOBUF_FUTURE_REMOVE_WRONG_CTYPE }); return status; } diff --git a/src/google/protobuf/compiler/cpp/generator_unittest.cc b/src/google/protobuf/compiler/cpp/generator_unittest.cc index 454b7826e666e..b1ee0e3785f01 100644 --- a/src/google/protobuf/compiler/cpp/generator_unittest.cc +++ b/src/google/protobuf/compiler/cpp/generator_unittest.cc @@ -148,7 +148,6 @@ TEST_F(CppGeneratorTest, LegacyClosedEnumImplicit) { "Field Foo.bar has a closed enum type with implicit presence."); } -#ifdef PROTOBUF_FUTURE_REMOVE_WRONG_CTYPE TEST_F(CppGeneratorTest, CtypeOnNoneStringFieldTest) { CreateTempFile("foo.proto", R"schema( @@ -181,7 +180,6 @@ TEST_F(CppGeneratorTest, CtypeOnExtensionTest) { "Extension bar specifies ctype=CORD which is " "not supported for extensions."); } -#endif // !PROTOBUF_FUTURE_REMOVE_WRONG_CTYPE } // namespace } // namespace cpp } // namespace compiler diff --git a/src/google/protobuf/port_def.inc b/src/google/protobuf/port_def.inc index ac61dcd59a517..a7edd9b6c5579 100644 --- a/src/google/protobuf/port_def.inc +++ b/src/google/protobuf/port_def.inc @@ -167,10 +167,6 @@ static_assert(PROTOBUF_ABSL_MIN(20230125, 3), // Owner: ezb@ #define PROTOBUF_FUTURE_REMOVE_CONST_REPEATEDFIELD_GETARENA_API 1 -// Used to lock down wrong ctype usages in proto file. -// Owner: jieluo@ -#define PROTOBUF_FUTURE_REMOVE_WRONG_CTYPE 1 - #endif // Defines the Protobuf C++ Version for checking version compatibility at From 408b497d4e650d3b45f1c4facb70b305299bfebd Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Wed, 10 Jan 2024 01:34:19 +0000 Subject: [PATCH 229/255] Auto-generate files after cl/597088960 --- php/ext/google/protobuf/php-upb.h | 26 ++++++++++++++++++++++++++ ruby/ext/google/protobuf_c/ruby-upb.h | 26 ++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/php/ext/google/protobuf/php-upb.h b/php/ext/google/protobuf/php-upb.h index 6e43b83c50901..80b4e33de84fd 100644 --- a/php/ext/google/protobuf/php-upb.h +++ b/php/ext/google/protobuf/php-upb.h @@ -2608,6 +2608,32 @@ UPB_INLINE void _upb_Message_GetExtensionField( } } +// Gets a extension message or creates a default message and sets the extension +// if it doesn't already exist. +UPB_INLINE bool _upb_Message_GetOrCreateExtensionSubmessage( + struct upb_Message* msg, const upb_MiniTableExtension* mt_ext, + struct upb_Message** val, upb_Arena* a) { + const upb_MiniTableField* f = &mt_ext->UPB_PRIVATE(field); + UPB_ASSUME(upb_MiniTableField_IsExtension(f)); + const struct upb_Extension* const_ext = _upb_Message_Getext(msg, mt_ext); + if (const_ext) { + // Extension exists, get a mutable version of it. + struct upb_Extension* ext = + _upb_Message_GetOrCreateExtension(msg, mt_ext, a); + *val = (struct upb_Message*)ext->data.ptr; + return true; + } + // Extension doesn't exist, create a new message and set it. + struct upb_Message* ext_msg = + _upb_Message_New(upb_MiniTableExtension_GetSubMessage(mt_ext), a); + if (!ext_msg) return false; + struct upb_Extension* ext = _upb_Message_GetOrCreateExtension(msg, mt_ext, a); + if (!ext) return false; + ext->data.ptr = ext_msg; + *val = ext_msg; + return true; +} + UPB_INLINE void _upb_Message_SetNonExtensionField( struct upb_Message* msg, const upb_MiniTableField* field, const void* val) { UPB_ASSUME(!upb_MiniTableField_IsExtension(field)); diff --git a/ruby/ext/google/protobuf_c/ruby-upb.h b/ruby/ext/google/protobuf_c/ruby-upb.h index 8873252159e26..f171f462cb45d 100755 --- a/ruby/ext/google/protobuf_c/ruby-upb.h +++ b/ruby/ext/google/protobuf_c/ruby-upb.h @@ -2610,6 +2610,32 @@ UPB_INLINE void _upb_Message_GetExtensionField( } } +// Gets a extension message or creates a default message and sets the extension +// if it doesn't already exist. +UPB_INLINE bool _upb_Message_GetOrCreateExtensionSubmessage( + struct upb_Message* msg, const upb_MiniTableExtension* mt_ext, + struct upb_Message** val, upb_Arena* a) { + const upb_MiniTableField* f = &mt_ext->UPB_PRIVATE(field); + UPB_ASSUME(upb_MiniTableField_IsExtension(f)); + const struct upb_Extension* const_ext = _upb_Message_Getext(msg, mt_ext); + if (const_ext) { + // Extension exists, get a mutable version of it. + struct upb_Extension* ext = + _upb_Message_GetOrCreateExtension(msg, mt_ext, a); + *val = (struct upb_Message*)ext->data.ptr; + return true; + } + // Extension doesn't exist, create a new message and set it. + struct upb_Message* ext_msg = + _upb_Message_New(upb_MiniTableExtension_GetSubMessage(mt_ext), a); + if (!ext_msg) return false; + struct upb_Extension* ext = _upb_Message_GetOrCreateExtension(msg, mt_ext, a); + if (!ext) return false; + ext->data.ptr = ext_msg; + *val = ext_msg; + return true; +} + UPB_INLINE void _upb_Message_SetNonExtensionField( struct upb_Message* msg, const upb_MiniTableField* field, const void* val) { UPB_ASSUME(!upb_MiniTableField_IsExtension(field)); From c026907a5da56f7250856f9250a004c7d0ee4fc9 Mon Sep 17 00:00:00 2001 From: Eric Salo Date: Tue, 9 Jan 2024 21:05:51 -0800 Subject: [PATCH 230/255] upb: replace public universal hazzer with non-universal hazzers PiperOrigin-RevId: 597126288 --- upb/message/accessors.h | 16 +- upb/message/accessors_test.cc | 83 +++--- upb/message/copy_test.cc | 9 +- upb/message/internal/accessors.h | 16 +- upb/message/promote_test.cc | 2 +- upb/reflection/message.c | 8 +- .../stage0/google/protobuf/descriptor.upb.h | 246 +++++++++--------- upb_generator/BUILD | 1 + upb_generator/protoc-gen-upb.cc | 9 +- .../google/protobuf/compiler/plugin.upb.h | 28 +- 10 files changed, 217 insertions(+), 201 deletions(-) diff --git a/upb/message/accessors.h b/upb/message/accessors.h index 3b52df30e505e..d6eb7e9edf62a 100644 --- a/upb/message/accessors.h +++ b/upb/message/accessors.h @@ -57,14 +57,14 @@ UPB_API_INLINE void upb_Message_ClearExtension( UPB_PRIVATE(_upb_Message_ClearExtension)(msg, e); } -UPB_API_INLINE bool upb_Message_HasField(const upb_Message* msg, - const upb_MiniTableField* field) { - if (upb_MiniTableField_IsExtension(field)) { - const upb_MiniTableExtension* ext = (const upb_MiniTableExtension*)field; - return _upb_Message_HasExtensionField(msg, ext); - } else { - return _upb_Message_HasNonExtensionField(msg, field); - } +UPB_API_INLINE bool upb_Message_HasBaseField(const upb_Message* msg, + const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_Message_HasBaseField)(msg, f); +} + +UPB_API_INLINE bool upb_Message_HasExtension(const upb_Message* msg, + const upb_MiniTableExtension* e) { + return UPB_PRIVATE(_upb_Message_HasExtension)(msg, e); } UPB_API_INLINE uint32_t upb_Message_WhichOneofFieldNumber( diff --git a/upb/message/accessors_test.cc b/upb/message/accessors_test.cc index 423217fc78b6c..9db6eb5ddc027 100644 --- a/upb/message/accessors_test.cc +++ b/upb/message/accessors_test.cc @@ -82,11 +82,14 @@ TEST(GeneratedCode, HazzersProto2) { // Scalar/Boolean. const upb_MiniTableField* optional_bool_field = find_proto2_field(kFieldOptionalBool); - EXPECT_EQ(false, upb_Message_HasField(UPB_UPCAST(msg), optional_bool_field)); + EXPECT_EQ(false, + upb_Message_HasBaseField(UPB_UPCAST(msg), optional_bool_field)); protobuf_test_messages_proto2_TestAllTypesProto2_set_optional_bool(msg, true); - EXPECT_EQ(true, upb_Message_HasField(UPB_UPCAST(msg), optional_bool_field)); + EXPECT_EQ(true, + upb_Message_HasBaseField(UPB_UPCAST(msg), optional_bool_field)); upb_Message_ClearBaseField(UPB_UPCAST(msg), optional_bool_field); - EXPECT_EQ(false, upb_Message_HasField(UPB_UPCAST(msg), optional_bool_field)); + EXPECT_EQ(false, + upb_Message_HasBaseField(UPB_UPCAST(msg), optional_bool_field)); EXPECT_EQ( false, protobuf_test_messages_proto2_TestAllTypesProto2_optional_bool(msg)); @@ -95,17 +98,18 @@ TEST(GeneratedCode, HazzersProto2) { const upb_MiniTableField* optional_string_field = find_proto2_field(kFieldOptionalString); EXPECT_EQ(false, - upb_Message_HasField(UPB_UPCAST(msg), optional_string_field)); + upb_Message_HasBaseField(UPB_UPCAST(msg), optional_string_field)); protobuf_test_messages_proto2_TestAllTypesProto2_set_optional_string( msg, upb_StringView_FromString(kTestStr1)); - EXPECT_EQ(true, upb_Message_HasField(UPB_UPCAST(msg), optional_string_field)); + EXPECT_EQ(true, + upb_Message_HasBaseField(UPB_UPCAST(msg), optional_string_field)); EXPECT_EQ( strlen(kTestStr1), protobuf_test_messages_proto2_TestAllTypesProto2_optional_string(msg) .size); upb_Message_ClearBaseField(UPB_UPCAST(msg), optional_string_field); EXPECT_EQ(false, - upb_Message_HasField(UPB_UPCAST(msg), optional_string_field)); + upb_Message_HasBaseField(UPB_UPCAST(msg), optional_string_field)); EXPECT_EQ( 0, protobuf_test_messages_proto2_TestAllTypesProto2_optional_string(msg) .size); @@ -114,14 +118,14 @@ TEST(GeneratedCode, HazzersProto2) { const upb_MiniTableField* optional_message_field = find_proto2_field(kFieldOptionalNestedMessage); EXPECT_EQ(false, - upb_Message_HasField(UPB_UPCAST(msg), optional_message_field)); + upb_Message_HasBaseField(UPB_UPCAST(msg), optional_message_field)); protobuf_test_messages_proto2_TestAllTypesProto2_mutable_optional_nested_message( msg, arena); EXPECT_EQ(true, - upb_Message_HasField(UPB_UPCAST(msg), optional_message_field)); + upb_Message_HasBaseField(UPB_UPCAST(msg), optional_message_field)); upb_Message_ClearBaseField(UPB_UPCAST(msg), optional_message_field); EXPECT_EQ(false, - upb_Message_HasField(UPB_UPCAST(msg), optional_message_field)); + upb_Message_HasBaseField(UPB_UPCAST(msg), optional_message_field)); EXPECT_EQ( true, protobuf_test_messages_proto2_TestAllTypesProto2_optional_nested_message( @@ -133,31 +137,31 @@ TEST(GeneratedCode, HazzersProto2) { const upb_MiniTableField* optional_oneof_string_field = find_proto2_field(kFieldOptionalOneOfString); - EXPECT_EQ(false, - upb_Message_HasField(UPB_UPCAST(msg), optional_oneof_uint32_field)); - EXPECT_EQ(false, - upb_Message_HasField(UPB_UPCAST(msg), optional_oneof_string_field)); + EXPECT_EQ(false, upb_Message_HasBaseField(UPB_UPCAST(msg), + optional_oneof_uint32_field)); + EXPECT_EQ(false, upb_Message_HasBaseField(UPB_UPCAST(msg), + optional_oneof_string_field)); protobuf_test_messages_proto2_TestAllTypesProto2_set_oneof_uint32(msg, 123); - EXPECT_EQ(true, - upb_Message_HasField(UPB_UPCAST(msg), optional_oneof_uint32_field)); - EXPECT_EQ(false, - upb_Message_HasField(UPB_UPCAST(msg), optional_oneof_string_field)); + EXPECT_EQ(true, upb_Message_HasBaseField(UPB_UPCAST(msg), + optional_oneof_uint32_field)); + EXPECT_EQ(false, upb_Message_HasBaseField(UPB_UPCAST(msg), + optional_oneof_string_field)); protobuf_test_messages_proto2_TestAllTypesProto2_set_oneof_string( msg, upb_StringView_FromString(kTestStr1)); - EXPECT_EQ(false, - upb_Message_HasField(UPB_UPCAST(msg), optional_oneof_uint32_field)); - EXPECT_EQ(true, - upb_Message_HasField(UPB_UPCAST(msg), optional_oneof_string_field)); + EXPECT_EQ(false, upb_Message_HasBaseField(UPB_UPCAST(msg), + optional_oneof_uint32_field)); + EXPECT_EQ(true, upb_Message_HasBaseField(UPB_UPCAST(msg), + optional_oneof_string_field)); upb_Message_ClearBaseField(UPB_UPCAST(msg), optional_oneof_uint32_field); - EXPECT_EQ(false, - upb_Message_HasField(UPB_UPCAST(msg), optional_oneof_uint32_field)); - EXPECT_EQ(true, - upb_Message_HasField(UPB_UPCAST(msg), optional_oneof_string_field)); + EXPECT_EQ(false, upb_Message_HasBaseField(UPB_UPCAST(msg), + optional_oneof_uint32_field)); + EXPECT_EQ(true, upb_Message_HasBaseField(UPB_UPCAST(msg), + optional_oneof_string_field)); upb_Message_ClearBaseField(UPB_UPCAST(msg), optional_oneof_string_field); - EXPECT_EQ(false, - upb_Message_HasField(UPB_UPCAST(msg), optional_oneof_uint32_field)); - EXPECT_EQ(false, - upb_Message_HasField(UPB_UPCAST(msg), optional_oneof_string_field)); + EXPECT_EQ(false, upb_Message_HasBaseField(UPB_UPCAST(msg), + optional_oneof_uint32_field)); + EXPECT_EQ(false, upb_Message_HasBaseField(UPB_UPCAST(msg), + optional_oneof_string_field)); upb_Arena_Free(arena); } @@ -176,7 +180,8 @@ TEST(GeneratedCode, ScalarsProto2) { EXPECT_EQ(0, upb_Message_GetInt32(UPB_UPCAST(msg), optional_int32_field, 0)); upb_Message_SetInt32(UPB_UPCAST(msg), optional_int32_field, kTestInt32, nullptr); - EXPECT_EQ(true, upb_Message_HasField(UPB_UPCAST(msg), optional_int32_field)); + EXPECT_EQ(true, + upb_Message_HasBaseField(UPB_UPCAST(msg), optional_int32_field)); EXPECT_EQ(kTestInt32, upb_Message_GetInt32(UPB_UPCAST(msg), optional_int32_field, 0)); EXPECT_EQ( @@ -241,11 +246,12 @@ TEST(GeneratedCode, Strings) { // Test default. EXPECT_EQ(false, - upb_Message_HasField(UPB_UPCAST(msg), optional_string_field)); + upb_Message_HasBaseField(UPB_UPCAST(msg), optional_string_field)); // Test read after write using C. protobuf_test_messages_proto2_TestAllTypesProto2_set_optional_string( msg, upb_StringView_FromString(kTestStr1)); - EXPECT_EQ(true, upb_Message_HasField(UPB_UPCAST(msg), optional_string_field)); + EXPECT_EQ(true, + upb_Message_HasBaseField(UPB_UPCAST(msg), optional_string_field)); upb_StringView value = upb_Message_GetString( UPB_UPCAST(msg), optional_string_field, upb_StringView{nullptr, 0}); std::string read_value = std::string(value.data, value.size); @@ -253,14 +259,15 @@ TEST(GeneratedCode, Strings) { // Clear. upb_Message_ClearBaseField(UPB_UPCAST(msg), optional_string_field); EXPECT_EQ(false, - upb_Message_HasField(UPB_UPCAST(msg), optional_string_field)); + upb_Message_HasBaseField(UPB_UPCAST(msg), optional_string_field)); EXPECT_EQ( false, protobuf_test_messages_proto2_TestAllTypesProto2_has_optional_string( msg)); upb_Message_SetString(UPB_UPCAST(msg), optional_string_field, upb_StringView_FromString(kTestStr2), nullptr); - EXPECT_EQ(true, upb_Message_HasField(UPB_UPCAST(msg), optional_string_field)); + EXPECT_EQ(true, + upb_Message_HasBaseField(UPB_UPCAST(msg), optional_string_field)); EXPECT_EQ( true, protobuf_test_messages_proto2_TestAllTypesProto2_has_optional_string( @@ -285,7 +292,7 @@ TEST(GeneratedCode, SubMessage) { EXPECT_EQ(nullptr, test_message); EXPECT_EQ(false, - upb_Message_HasField(UPB_UPCAST(msg), optional_message_field)); + upb_Message_HasBaseField(UPB_UPCAST(msg), optional_message_field)); // Get mutable using C API. protobuf_test_messages_proto2_TestAllTypesProto2_NestedMessage* nested_message = @@ -293,7 +300,7 @@ TEST(GeneratedCode, SubMessage) { msg, arena); EXPECT_EQ(true, nested_message != nullptr); EXPECT_EQ(true, - upb_Message_HasField(UPB_UPCAST(msg), optional_message_field)); + upb_Message_HasBaseField(UPB_UPCAST(msg), optional_message_field)); protobuf_test_messages_proto2_TestAllTypesProto2_NestedMessage_set_a( nested_message, 5); @@ -314,7 +321,7 @@ TEST(GeneratedCode, SubMessage) { protobuf_test_messages_proto2_TestAllTypesProto2_optional_nested_message( msg)); EXPECT_EQ(false, - upb_Message_HasField(UPB_UPCAST(msg), optional_message_field)); + upb_Message_HasBaseField(UPB_UPCAST(msg), optional_message_field)); upb_Message* new_nested_message = UPB_UPCAST( protobuf_test_messages_proto2_TestAllTypesProto2_NestedMessage_new( @@ -335,7 +342,7 @@ TEST(GeneratedCode, SubMessage) { protobuf_test_messages_proto2_TestAllTypesProto2_optional_nested_message( msg) != nullptr); EXPECT_EQ(true, - upb_Message_HasField(UPB_UPCAST(msg), optional_message_field)); + upb_Message_HasBaseField(UPB_UPCAST(msg), optional_message_field)); EXPECT_EQ(123, upb_Message_GetInt32(mutable_message, nested_message_a_field, 0)); diff --git a/upb/message/copy_test.cc b/upb/message/copy_test.cc index 727b352e00c38..0ec87e4fd0c39 100644 --- a/upb/message/copy_test.cc +++ b/upb/message/copy_test.cc @@ -80,10 +80,12 @@ TEST(GeneratedCode, DeepCloneMessageScalarAndString) { // After cloning overwrite values and destroy source arena for MSAN. memset(string_in_arena, 0, sizeof(kTestStr1)); upb_Arena_Free(source_arena); - EXPECT_TRUE(upb_Message_HasField(UPB_UPCAST(clone), optional_int32_field)); + EXPECT_TRUE( + upb_Message_HasBaseField(UPB_UPCAST(clone), optional_int32_field)); EXPECT_EQ(upb_Message_GetInt32(UPB_UPCAST(clone), optional_int32_field, 0), kTestInt32); - EXPECT_TRUE(upb_Message_HasField(UPB_UPCAST(clone), optional_string_field)); + EXPECT_TRUE( + upb_Message_HasBaseField(UPB_UPCAST(clone), optional_string_field)); EXPECT_EQ(upb_Message_GetString(UPB_UPCAST(clone), optional_string_field, upb_StringView_FromDataAndSize(nullptr, 0)) .size, @@ -120,7 +122,8 @@ TEST(GeneratedCode, DeepCloneMessageSubMessage) { protobuf_test_messages_proto2_TestAllTypesProto2_NestedMessage_set_a(nested, 0); upb_Arena_Free(source_arena); - EXPECT_TRUE(upb_Message_HasField(UPB_UPCAST(clone), nested_message_field)); + EXPECT_TRUE( + upb_Message_HasBaseField(UPB_UPCAST(clone), nested_message_field)); protobuf_test_messages_proto2_TestAllTypesProto2_NestedMessage* cloned_nested = (protobuf_test_messages_proto2_TestAllTypesProto2_NestedMessage*) diff --git a/upb/message/internal/accessors.h b/upb/message/internal/accessors.h index 997a3521105de..af1893ca18685 100644 --- a/upb/message/internal/accessors.h +++ b/upb/message/internal/accessors.h @@ -213,13 +213,7 @@ UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_DataIsZero)( // of a setter is known to be a non-extension, the arena may be NULL and the // returned bool value may be ignored since it will always succeed. -UPB_INLINE bool _upb_Message_HasExtensionField( - const struct upb_Message* msg, const upb_MiniTableExtension* ext) { - UPB_ASSERT(upb_MiniTableField_HasPresence(&ext->UPB_PRIVATE(field))); - return _upb_Message_Getext(msg, ext) != NULL; -} - -UPB_INLINE bool _upb_Message_HasNonExtensionField( +UPB_INLINE bool UPB_PRIVATE(_upb_Message_HasBaseField)( const struct upb_Message* msg, const upb_MiniTableField* field) { UPB_ASSERT(upb_MiniTableField_HasPresence(field)); UPB_ASSUME(!upb_MiniTableField_IsExtension(field)); @@ -231,13 +225,19 @@ UPB_INLINE bool _upb_Message_HasNonExtensionField( } } +UPB_INLINE bool UPB_PRIVATE(_upb_Message_HasExtension)( + const struct upb_Message* msg, const upb_MiniTableExtension* ext) { + UPB_ASSERT(upb_MiniTableField_HasPresence(&ext->UPB_PRIVATE(field))); + return _upb_Message_Getext(msg, ext) != NULL; +} + static UPB_FORCEINLINE void _upb_Message_GetNonExtensionField( const struct upb_Message* msg, const upb_MiniTableField* field, const void* default_val, void* val) { UPB_ASSUME(!upb_MiniTableField_IsExtension(field)); if ((upb_MiniTableField_IsInOneof(field) || !UPB_PRIVATE(_upb_MiniTableField_DataIsZero)(field, default_val)) && - !_upb_Message_HasNonExtensionField(msg, field)) { + !UPB_PRIVATE(_upb_Message_HasBaseField)(msg, field)) { UPB_PRIVATE(_upb_MiniTableField_DataCopy)(field, val, default_val); return; } diff --git a/upb/message/promote_test.cc b/upb/message/promote_test.cc index 59593652e1293..3b79cb8b5571a 100644 --- a/upb/message/promote_test.cc +++ b/upb/message/promote_test.cc @@ -372,7 +372,7 @@ TEST(GeneratedCode, PromoteUnknownMessage) { const upb_MiniTableField* submsg_field = upb_MiniTable_FindFieldByNumber(mini_table, 5); ASSERT_TRUE(submsg_field != nullptr); - EXPECT_TRUE(upb_Message_HasField(msg, submsg_field)); + EXPECT_TRUE(upb_Message_HasBaseField(msg, submsg_field)); upb_TaggedMessagePtr tagged = upb_Message_GetTaggedMessagePtr(msg, submsg_field, nullptr); EXPECT_TRUE(upb_TaggedMessagePtr_IsEmpty(tagged)); diff --git a/upb/reflection/message.c b/upb/reflection/message.c index 2cbbd57fc619f..360ece8d7b9f7 100644 --- a/upb/reflection/message.c +++ b/upb/reflection/message.c @@ -29,8 +29,14 @@ #include "upb/port/def.inc" bool upb_Message_HasFieldByDef(const upb_Message* msg, const upb_FieldDef* f) { + const upb_MiniTableField* m_f = upb_FieldDef_MiniTable(f); UPB_ASSERT(upb_FieldDef_HasPresence(f)); - return upb_Message_HasField(msg, upb_FieldDef_MiniTable(f)); + + if (upb_MiniTableField_IsExtension(m_f)) { + return upb_Message_HasExtension(msg, (const upb_MiniTableExtension*)m_f); + } else { + return upb_Message_HasBaseField(msg, m_f); + } } const upb_FieldDef* upb_Message_WhichOneof(const upb_Message* msg, diff --git a/upb/reflection/stage0/google/protobuf/descriptor.upb.h b/upb/reflection/stage0/google/protobuf/descriptor.upb.h index 70f3a52a61479..589f6d56cb4d2 100644 --- a/upb/reflection/stage0/google/protobuf/descriptor.upb.h +++ b/upb/reflection/stage0/google/protobuf/descriptor.upb.h @@ -383,7 +383,7 @@ UPB_INLINE upb_StringView google_protobuf_FileDescriptorProto_name(const google_ } UPB_INLINE bool google_protobuf_FileDescriptorProto_has_name(const google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 1); - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileDescriptorProto_clear_package(google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 2); @@ -399,7 +399,7 @@ UPB_INLINE upb_StringView google_protobuf_FileDescriptorProto_package(const goog } UPB_INLINE bool google_protobuf_FileDescriptorProto_has_package(const google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 2); - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileDescriptorProto_clear_dependency(google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 3); @@ -575,7 +575,7 @@ UPB_INLINE const google_protobuf_FileOptions* google_protobuf_FileDescriptorProt } UPB_INLINE bool google_protobuf_FileDescriptorProto_has_options(const google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 8); - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileDescriptorProto_clear_source_code_info(google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 9); @@ -591,7 +591,7 @@ UPB_INLINE const google_protobuf_SourceCodeInfo* google_protobuf_FileDescriptorP } UPB_INLINE bool google_protobuf_FileDescriptorProto_has_source_code_info(const google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 9); - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileDescriptorProto_clear_public_dependency(google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 10); @@ -671,7 +671,7 @@ UPB_INLINE upb_StringView google_protobuf_FileDescriptorProto_syntax(const googl } UPB_INLINE bool google_protobuf_FileDescriptorProto_has_syntax(const google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 12); - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileDescriptorProto_clear_edition(google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 14); @@ -687,7 +687,7 @@ UPB_INLINE int32_t google_protobuf_FileDescriptorProto_edition(const google_prot } UPB_INLINE bool google_protobuf_FileDescriptorProto_has_edition(const google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileDescriptorProto_msg_init(), 14); - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileDescriptorProto_set_name(google_protobuf_FileDescriptorProto *msg, upb_StringView value) { @@ -985,7 +985,7 @@ UPB_INLINE upb_StringView google_protobuf_DescriptorProto_name(const google_prot } UPB_INLINE bool google_protobuf_DescriptorProto_has_name(const google_protobuf_DescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 1); - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_DescriptorProto_clear_field(google_protobuf_DescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 2); @@ -1161,7 +1161,7 @@ UPB_INLINE const google_protobuf_MessageOptions* google_protobuf_DescriptorProto } UPB_INLINE bool google_protobuf_DescriptorProto_has_options(const google_protobuf_DescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 7); - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_DescriptorProto_clear_oneof_decl(google_protobuf_DescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto_msg_init(), 8); @@ -1565,7 +1565,7 @@ UPB_INLINE int32_t google_protobuf_DescriptorProto_ExtensionRange_start(const go } UPB_INLINE bool google_protobuf_DescriptorProto_ExtensionRange_has_start(const google_protobuf_DescriptorProto_ExtensionRange* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto__ExtensionRange_msg_init(), 1); - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_DescriptorProto_ExtensionRange_clear_end(google_protobuf_DescriptorProto_ExtensionRange* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto__ExtensionRange_msg_init(), 2); @@ -1581,7 +1581,7 @@ UPB_INLINE int32_t google_protobuf_DescriptorProto_ExtensionRange_end(const goog } UPB_INLINE bool google_protobuf_DescriptorProto_ExtensionRange_has_end(const google_protobuf_DescriptorProto_ExtensionRange* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto__ExtensionRange_msg_init(), 2); - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_DescriptorProto_ExtensionRange_clear_options(google_protobuf_DescriptorProto_ExtensionRange* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto__ExtensionRange_msg_init(), 3); @@ -1597,7 +1597,7 @@ UPB_INLINE const google_protobuf_ExtensionRangeOptions* google_protobuf_Descript } UPB_INLINE bool google_protobuf_DescriptorProto_ExtensionRange_has_options(const google_protobuf_DescriptorProto_ExtensionRange* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto__ExtensionRange_msg_init(), 3); - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_DescriptorProto_ExtensionRange_set_start(google_protobuf_DescriptorProto_ExtensionRange *msg, int32_t value) { @@ -1671,7 +1671,7 @@ UPB_INLINE int32_t google_protobuf_DescriptorProto_ReservedRange_start(const goo } UPB_INLINE bool google_protobuf_DescriptorProto_ReservedRange_has_start(const google_protobuf_DescriptorProto_ReservedRange* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto__ReservedRange_msg_init(), 1); - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_DescriptorProto_ReservedRange_clear_end(google_protobuf_DescriptorProto_ReservedRange* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto__ReservedRange_msg_init(), 2); @@ -1687,7 +1687,7 @@ UPB_INLINE int32_t google_protobuf_DescriptorProto_ReservedRange_end(const googl } UPB_INLINE bool google_protobuf_DescriptorProto_ReservedRange_has_end(const google_protobuf_DescriptorProto_ReservedRange* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__DescriptorProto__ReservedRange_msg_init(), 2); - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_DescriptorProto_ReservedRange_set_start(google_protobuf_DescriptorProto_ReservedRange *msg, int32_t value) { @@ -1781,7 +1781,7 @@ UPB_INLINE int32_t google_protobuf_ExtensionRangeOptions_verification(const goog } UPB_INLINE bool google_protobuf_ExtensionRangeOptions_has_verification(const google_protobuf_ExtensionRangeOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ExtensionRangeOptions_msg_init(), 3); - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_ExtensionRangeOptions_clear_features(google_protobuf_ExtensionRangeOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ExtensionRangeOptions_msg_init(), 50); @@ -1797,7 +1797,7 @@ UPB_INLINE const google_protobuf_FeatureSet* google_protobuf_ExtensionRangeOptio } UPB_INLINE bool google_protobuf_ExtensionRangeOptions_has_features(const google_protobuf_ExtensionRangeOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ExtensionRangeOptions_msg_init(), 50); - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_ExtensionRangeOptions_clear_uninterpreted_option(google_protobuf_ExtensionRangeOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ExtensionRangeOptions_msg_init(), 999); @@ -1959,7 +1959,7 @@ UPB_INLINE int32_t google_protobuf_ExtensionRangeOptions_Declaration_number(cons } UPB_INLINE bool google_protobuf_ExtensionRangeOptions_Declaration_has_number(const google_protobuf_ExtensionRangeOptions_Declaration* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ExtensionRangeOptions__Declaration_msg_init(), 1); - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_ExtensionRangeOptions_Declaration_clear_full_name(google_protobuf_ExtensionRangeOptions_Declaration* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ExtensionRangeOptions__Declaration_msg_init(), 2); @@ -1975,7 +1975,7 @@ UPB_INLINE upb_StringView google_protobuf_ExtensionRangeOptions_Declaration_full } UPB_INLINE bool google_protobuf_ExtensionRangeOptions_Declaration_has_full_name(const google_protobuf_ExtensionRangeOptions_Declaration* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ExtensionRangeOptions__Declaration_msg_init(), 2); - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_ExtensionRangeOptions_Declaration_clear_type(google_protobuf_ExtensionRangeOptions_Declaration* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ExtensionRangeOptions__Declaration_msg_init(), 3); @@ -1991,7 +1991,7 @@ UPB_INLINE upb_StringView google_protobuf_ExtensionRangeOptions_Declaration_type } UPB_INLINE bool google_protobuf_ExtensionRangeOptions_Declaration_has_type(const google_protobuf_ExtensionRangeOptions_Declaration* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ExtensionRangeOptions__Declaration_msg_init(), 3); - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_ExtensionRangeOptions_Declaration_clear_reserved(google_protobuf_ExtensionRangeOptions_Declaration* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ExtensionRangeOptions__Declaration_msg_init(), 5); @@ -2007,7 +2007,7 @@ UPB_INLINE bool google_protobuf_ExtensionRangeOptions_Declaration_reserved(const } UPB_INLINE bool google_protobuf_ExtensionRangeOptions_Declaration_has_reserved(const google_protobuf_ExtensionRangeOptions_Declaration* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ExtensionRangeOptions__Declaration_msg_init(), 5); - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_ExtensionRangeOptions_Declaration_clear_repeated(google_protobuf_ExtensionRangeOptions_Declaration* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ExtensionRangeOptions__Declaration_msg_init(), 6); @@ -2023,7 +2023,7 @@ UPB_INLINE bool google_protobuf_ExtensionRangeOptions_Declaration_repeated(const } UPB_INLINE bool google_protobuf_ExtensionRangeOptions_Declaration_has_repeated(const google_protobuf_ExtensionRangeOptions_Declaration* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ExtensionRangeOptions__Declaration_msg_init(), 6); - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_ExtensionRangeOptions_Declaration_set_number(google_protobuf_ExtensionRangeOptions_Declaration *msg, int32_t value) { @@ -2097,7 +2097,7 @@ UPB_INLINE upb_StringView google_protobuf_FieldDescriptorProto_name(const google } UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_name(const google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldDescriptorProto_msg_init(), 1); - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldDescriptorProto_clear_extendee(google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldDescriptorProto_msg_init(), 2); @@ -2113,7 +2113,7 @@ UPB_INLINE upb_StringView google_protobuf_FieldDescriptorProto_extendee(const go } UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_extendee(const google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldDescriptorProto_msg_init(), 2); - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldDescriptorProto_clear_number(google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldDescriptorProto_msg_init(), 3); @@ -2129,7 +2129,7 @@ UPB_INLINE int32_t google_protobuf_FieldDescriptorProto_number(const google_prot } UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_number(const google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldDescriptorProto_msg_init(), 3); - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldDescriptorProto_clear_label(google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldDescriptorProto_msg_init(), 4); @@ -2145,7 +2145,7 @@ UPB_INLINE int32_t google_protobuf_FieldDescriptorProto_label(const google_proto } UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_label(const google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldDescriptorProto_msg_init(), 4); - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldDescriptorProto_clear_type(google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldDescriptorProto_msg_init(), 5); @@ -2161,7 +2161,7 @@ UPB_INLINE int32_t google_protobuf_FieldDescriptorProto_type(const google_protob } UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_type(const google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldDescriptorProto_msg_init(), 5); - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldDescriptorProto_clear_type_name(google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldDescriptorProto_msg_init(), 6); @@ -2177,7 +2177,7 @@ UPB_INLINE upb_StringView google_protobuf_FieldDescriptorProto_type_name(const g } UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_type_name(const google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldDescriptorProto_msg_init(), 6); - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldDescriptorProto_clear_default_value(google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldDescriptorProto_msg_init(), 7); @@ -2193,7 +2193,7 @@ UPB_INLINE upb_StringView google_protobuf_FieldDescriptorProto_default_value(con } UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_default_value(const google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldDescriptorProto_msg_init(), 7); - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldDescriptorProto_clear_options(google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldDescriptorProto_msg_init(), 8); @@ -2209,7 +2209,7 @@ UPB_INLINE const google_protobuf_FieldOptions* google_protobuf_FieldDescriptorPr } UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_options(const google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldDescriptorProto_msg_init(), 8); - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldDescriptorProto_clear_oneof_index(google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldDescriptorProto_msg_init(), 9); @@ -2225,7 +2225,7 @@ UPB_INLINE int32_t google_protobuf_FieldDescriptorProto_oneof_index(const google } UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_oneof_index(const google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldDescriptorProto_msg_init(), 9); - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldDescriptorProto_clear_json_name(google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldDescriptorProto_msg_init(), 10); @@ -2241,7 +2241,7 @@ UPB_INLINE upb_StringView google_protobuf_FieldDescriptorProto_json_name(const g } UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_json_name(const google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldDescriptorProto_msg_init(), 10); - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldDescriptorProto_clear_proto3_optional(google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldDescriptorProto_msg_init(), 17); @@ -2257,7 +2257,7 @@ UPB_INLINE bool google_protobuf_FieldDescriptorProto_proto3_optional(const googl } UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_proto3_optional(const google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldDescriptorProto_msg_init(), 17); - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldDescriptorProto_set_name(google_protobuf_FieldDescriptorProto *msg, upb_StringView value) { @@ -2363,7 +2363,7 @@ UPB_INLINE upb_StringView google_protobuf_OneofDescriptorProto_name(const google } UPB_INLINE bool google_protobuf_OneofDescriptorProto_has_name(const google_protobuf_OneofDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__OneofDescriptorProto_msg_init(), 1); - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_OneofDescriptorProto_clear_options(google_protobuf_OneofDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__OneofDescriptorProto_msg_init(), 2); @@ -2379,7 +2379,7 @@ UPB_INLINE const google_protobuf_OneofOptions* google_protobuf_OneofDescriptorPr } UPB_INLINE bool google_protobuf_OneofDescriptorProto_has_options(const google_protobuf_OneofDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__OneofDescriptorProto_msg_init(), 2); - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_OneofDescriptorProto_set_name(google_protobuf_OneofDescriptorProto *msg, upb_StringView value) { @@ -2449,7 +2449,7 @@ UPB_INLINE upb_StringView google_protobuf_EnumDescriptorProto_name(const google_ } UPB_INLINE bool google_protobuf_EnumDescriptorProto_has_name(const google_protobuf_EnumDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumDescriptorProto_msg_init(), 1); - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_EnumDescriptorProto_clear_value(google_protobuf_EnumDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumDescriptorProto_msg_init(), 2); @@ -2497,7 +2497,7 @@ UPB_INLINE const google_protobuf_EnumOptions* google_protobuf_EnumDescriptorProt } UPB_INLINE bool google_protobuf_EnumDescriptorProto_has_options(const google_protobuf_EnumDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumDescriptorProto_msg_init(), 3); - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_EnumDescriptorProto_clear_reserved_range(google_protobuf_EnumDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumDescriptorProto_msg_init(), 4); @@ -2719,7 +2719,7 @@ UPB_INLINE int32_t google_protobuf_EnumDescriptorProto_EnumReservedRange_start(c } UPB_INLINE bool google_protobuf_EnumDescriptorProto_EnumReservedRange_has_start(const google_protobuf_EnumDescriptorProto_EnumReservedRange* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumDescriptorProto__EnumReservedRange_msg_init(), 1); - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_EnumDescriptorProto_EnumReservedRange_clear_end(google_protobuf_EnumDescriptorProto_EnumReservedRange* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumDescriptorProto__EnumReservedRange_msg_init(), 2); @@ -2735,7 +2735,7 @@ UPB_INLINE int32_t google_protobuf_EnumDescriptorProto_EnumReservedRange_end(con } UPB_INLINE bool google_protobuf_EnumDescriptorProto_EnumReservedRange_has_end(const google_protobuf_EnumDescriptorProto_EnumReservedRange* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumDescriptorProto__EnumReservedRange_msg_init(), 2); - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_EnumDescriptorProto_EnumReservedRange_set_start(google_protobuf_EnumDescriptorProto_EnumReservedRange *msg, int32_t value) { @@ -2797,7 +2797,7 @@ UPB_INLINE upb_StringView google_protobuf_EnumValueDescriptorProto_name(const go } UPB_INLINE bool google_protobuf_EnumValueDescriptorProto_has_name(const google_protobuf_EnumValueDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumValueDescriptorProto_msg_init(), 1); - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_EnumValueDescriptorProto_clear_number(google_protobuf_EnumValueDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumValueDescriptorProto_msg_init(), 2); @@ -2813,7 +2813,7 @@ UPB_INLINE int32_t google_protobuf_EnumValueDescriptorProto_number(const google_ } UPB_INLINE bool google_protobuf_EnumValueDescriptorProto_has_number(const google_protobuf_EnumValueDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumValueDescriptorProto_msg_init(), 2); - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_EnumValueDescriptorProto_clear_options(google_protobuf_EnumValueDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumValueDescriptorProto_msg_init(), 3); @@ -2829,7 +2829,7 @@ UPB_INLINE const google_protobuf_EnumValueOptions* google_protobuf_EnumValueDesc } UPB_INLINE bool google_protobuf_EnumValueDescriptorProto_has_options(const google_protobuf_EnumValueDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumValueDescriptorProto_msg_init(), 3); - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_EnumValueDescriptorProto_set_name(google_protobuf_EnumValueDescriptorProto *msg, upb_StringView value) { @@ -2903,7 +2903,7 @@ UPB_INLINE upb_StringView google_protobuf_ServiceDescriptorProto_name(const goog } UPB_INLINE bool google_protobuf_ServiceDescriptorProto_has_name(const google_protobuf_ServiceDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ServiceDescriptorProto_msg_init(), 1); - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_ServiceDescriptorProto_clear_method(google_protobuf_ServiceDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ServiceDescriptorProto_msg_init(), 2); @@ -2951,7 +2951,7 @@ UPB_INLINE const google_protobuf_ServiceOptions* google_protobuf_ServiceDescript } UPB_INLINE bool google_protobuf_ServiceDescriptorProto_has_options(const google_protobuf_ServiceDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ServiceDescriptorProto_msg_init(), 3); - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_ServiceDescriptorProto_set_name(google_protobuf_ServiceDescriptorProto *msg, upb_StringView value) { @@ -3051,7 +3051,7 @@ UPB_INLINE upb_StringView google_protobuf_MethodDescriptorProto_name(const googl } UPB_INLINE bool google_protobuf_MethodDescriptorProto_has_name(const google_protobuf_MethodDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MethodDescriptorProto_msg_init(), 1); - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_MethodDescriptorProto_clear_input_type(google_protobuf_MethodDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MethodDescriptorProto_msg_init(), 2); @@ -3067,7 +3067,7 @@ UPB_INLINE upb_StringView google_protobuf_MethodDescriptorProto_input_type(const } UPB_INLINE bool google_protobuf_MethodDescriptorProto_has_input_type(const google_protobuf_MethodDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MethodDescriptorProto_msg_init(), 2); - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_MethodDescriptorProto_clear_output_type(google_protobuf_MethodDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MethodDescriptorProto_msg_init(), 3); @@ -3083,7 +3083,7 @@ UPB_INLINE upb_StringView google_protobuf_MethodDescriptorProto_output_type(cons } UPB_INLINE bool google_protobuf_MethodDescriptorProto_has_output_type(const google_protobuf_MethodDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MethodDescriptorProto_msg_init(), 3); - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_MethodDescriptorProto_clear_options(google_protobuf_MethodDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MethodDescriptorProto_msg_init(), 4); @@ -3099,7 +3099,7 @@ UPB_INLINE const google_protobuf_MethodOptions* google_protobuf_MethodDescriptor } UPB_INLINE bool google_protobuf_MethodDescriptorProto_has_options(const google_protobuf_MethodDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MethodDescriptorProto_msg_init(), 4); - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_MethodDescriptorProto_clear_client_streaming(google_protobuf_MethodDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MethodDescriptorProto_msg_init(), 5); @@ -3115,7 +3115,7 @@ UPB_INLINE bool google_protobuf_MethodDescriptorProto_client_streaming(const goo } UPB_INLINE bool google_protobuf_MethodDescriptorProto_has_client_streaming(const google_protobuf_MethodDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MethodDescriptorProto_msg_init(), 5); - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_MethodDescriptorProto_clear_server_streaming(google_protobuf_MethodDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MethodDescriptorProto_msg_init(), 6); @@ -3131,7 +3131,7 @@ UPB_INLINE bool google_protobuf_MethodDescriptorProto_server_streaming(const goo } UPB_INLINE bool google_protobuf_MethodDescriptorProto_has_server_streaming(const google_protobuf_MethodDescriptorProto* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MethodDescriptorProto_msg_init(), 6); - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_MethodDescriptorProto_set_name(google_protobuf_MethodDescriptorProto *msg, upb_StringView value) { @@ -3217,7 +3217,7 @@ UPB_INLINE upb_StringView google_protobuf_FileOptions_java_package(const google_ } UPB_INLINE bool google_protobuf_FileOptions_has_java_package(const google_protobuf_FileOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 1); - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileOptions_clear_java_outer_classname(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 8); @@ -3233,7 +3233,7 @@ UPB_INLINE upb_StringView google_protobuf_FileOptions_java_outer_classname(const } UPB_INLINE bool google_protobuf_FileOptions_has_java_outer_classname(const google_protobuf_FileOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 8); - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileOptions_clear_optimize_for(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 9); @@ -3249,7 +3249,7 @@ UPB_INLINE int32_t google_protobuf_FileOptions_optimize_for(const google_protobu } UPB_INLINE bool google_protobuf_FileOptions_has_optimize_for(const google_protobuf_FileOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 9); - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileOptions_clear_java_multiple_files(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 10); @@ -3265,7 +3265,7 @@ UPB_INLINE bool google_protobuf_FileOptions_java_multiple_files(const google_pro } UPB_INLINE bool google_protobuf_FileOptions_has_java_multiple_files(const google_protobuf_FileOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 10); - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileOptions_clear_go_package(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 11); @@ -3281,7 +3281,7 @@ UPB_INLINE upb_StringView google_protobuf_FileOptions_go_package(const google_pr } UPB_INLINE bool google_protobuf_FileOptions_has_go_package(const google_protobuf_FileOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 11); - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileOptions_clear_cc_generic_services(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 16); @@ -3297,7 +3297,7 @@ UPB_INLINE bool google_protobuf_FileOptions_cc_generic_services(const google_pro } UPB_INLINE bool google_protobuf_FileOptions_has_cc_generic_services(const google_protobuf_FileOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 16); - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileOptions_clear_java_generic_services(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 17); @@ -3313,7 +3313,7 @@ UPB_INLINE bool google_protobuf_FileOptions_java_generic_services(const google_p } UPB_INLINE bool google_protobuf_FileOptions_has_java_generic_services(const google_protobuf_FileOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 17); - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileOptions_clear_py_generic_services(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 18); @@ -3329,7 +3329,7 @@ UPB_INLINE bool google_protobuf_FileOptions_py_generic_services(const google_pro } UPB_INLINE bool google_protobuf_FileOptions_has_py_generic_services(const google_protobuf_FileOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 18); - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileOptions_clear_java_generate_equals_and_hash(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 20); @@ -3345,7 +3345,7 @@ UPB_INLINE bool google_protobuf_FileOptions_java_generate_equals_and_hash(const } UPB_INLINE bool google_protobuf_FileOptions_has_java_generate_equals_and_hash(const google_protobuf_FileOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 20); - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileOptions_clear_deprecated(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 23); @@ -3361,7 +3361,7 @@ UPB_INLINE bool google_protobuf_FileOptions_deprecated(const google_protobuf_Fil } UPB_INLINE bool google_protobuf_FileOptions_has_deprecated(const google_protobuf_FileOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 23); - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileOptions_clear_java_string_check_utf8(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 27); @@ -3377,7 +3377,7 @@ UPB_INLINE bool google_protobuf_FileOptions_java_string_check_utf8(const google_ } UPB_INLINE bool google_protobuf_FileOptions_has_java_string_check_utf8(const google_protobuf_FileOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 27); - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileOptions_clear_cc_enable_arenas(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 31); @@ -3393,7 +3393,7 @@ UPB_INLINE bool google_protobuf_FileOptions_cc_enable_arenas(const google_protob } UPB_INLINE bool google_protobuf_FileOptions_has_cc_enable_arenas(const google_protobuf_FileOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 31); - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileOptions_clear_objc_class_prefix(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 36); @@ -3409,7 +3409,7 @@ UPB_INLINE upb_StringView google_protobuf_FileOptions_objc_class_prefix(const go } UPB_INLINE bool google_protobuf_FileOptions_has_objc_class_prefix(const google_protobuf_FileOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 36); - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileOptions_clear_csharp_namespace(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 37); @@ -3425,7 +3425,7 @@ UPB_INLINE upb_StringView google_protobuf_FileOptions_csharp_namespace(const goo } UPB_INLINE bool google_protobuf_FileOptions_has_csharp_namespace(const google_protobuf_FileOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 37); - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileOptions_clear_swift_prefix(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 39); @@ -3441,7 +3441,7 @@ UPB_INLINE upb_StringView google_protobuf_FileOptions_swift_prefix(const google_ } UPB_INLINE bool google_protobuf_FileOptions_has_swift_prefix(const google_protobuf_FileOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 39); - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileOptions_clear_php_class_prefix(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 40); @@ -3457,7 +3457,7 @@ UPB_INLINE upb_StringView google_protobuf_FileOptions_php_class_prefix(const goo } UPB_INLINE bool google_protobuf_FileOptions_has_php_class_prefix(const google_protobuf_FileOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 40); - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileOptions_clear_php_namespace(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 41); @@ -3473,7 +3473,7 @@ UPB_INLINE upb_StringView google_protobuf_FileOptions_php_namespace(const google } UPB_INLINE bool google_protobuf_FileOptions_has_php_namespace(const google_protobuf_FileOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 41); - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileOptions_clear_php_metadata_namespace(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 44); @@ -3489,7 +3489,7 @@ UPB_INLINE upb_StringView google_protobuf_FileOptions_php_metadata_namespace(con } UPB_INLINE bool google_protobuf_FileOptions_has_php_metadata_namespace(const google_protobuf_FileOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 44); - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileOptions_clear_ruby_package(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 45); @@ -3505,7 +3505,7 @@ UPB_INLINE upb_StringView google_protobuf_FileOptions_ruby_package(const google_ } UPB_INLINE bool google_protobuf_FileOptions_has_ruby_package(const google_protobuf_FileOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 45); - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileOptions_clear_features(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 50); @@ -3521,7 +3521,7 @@ UPB_INLINE const google_protobuf_FeatureSet* google_protobuf_FileOptions_feature } UPB_INLINE bool google_protobuf_FileOptions_has_features(const google_protobuf_FileOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 50); - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileOptions_clear_uninterpreted_option(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FileOptions_msg_init(), 999); @@ -3725,7 +3725,7 @@ UPB_INLINE bool google_protobuf_MessageOptions_message_set_wire_format(const goo } UPB_INLINE bool google_protobuf_MessageOptions_has_message_set_wire_format(const google_protobuf_MessageOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MessageOptions_msg_init(), 1); - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_MessageOptions_clear_no_standard_descriptor_accessor(google_protobuf_MessageOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MessageOptions_msg_init(), 2); @@ -3741,7 +3741,7 @@ UPB_INLINE bool google_protobuf_MessageOptions_no_standard_descriptor_accessor(c } UPB_INLINE bool google_protobuf_MessageOptions_has_no_standard_descriptor_accessor(const google_protobuf_MessageOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MessageOptions_msg_init(), 2); - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_MessageOptions_clear_deprecated(google_protobuf_MessageOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MessageOptions_msg_init(), 3); @@ -3757,7 +3757,7 @@ UPB_INLINE bool google_protobuf_MessageOptions_deprecated(const google_protobuf_ } UPB_INLINE bool google_protobuf_MessageOptions_has_deprecated(const google_protobuf_MessageOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MessageOptions_msg_init(), 3); - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_MessageOptions_clear_map_entry(google_protobuf_MessageOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MessageOptions_msg_init(), 7); @@ -3773,7 +3773,7 @@ UPB_INLINE bool google_protobuf_MessageOptions_map_entry(const google_protobuf_M } UPB_INLINE bool google_protobuf_MessageOptions_has_map_entry(const google_protobuf_MessageOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MessageOptions_msg_init(), 7); - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_MessageOptions_clear_deprecated_legacy_json_field_conflicts(google_protobuf_MessageOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MessageOptions_msg_init(), 11); @@ -3789,7 +3789,7 @@ UPB_INLINE bool google_protobuf_MessageOptions_deprecated_legacy_json_field_conf } UPB_INLINE bool google_protobuf_MessageOptions_has_deprecated_legacy_json_field_conflicts(const google_protobuf_MessageOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MessageOptions_msg_init(), 11); - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_MessageOptions_clear_features(google_protobuf_MessageOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MessageOptions_msg_init(), 12); @@ -3805,7 +3805,7 @@ UPB_INLINE const google_protobuf_FeatureSet* google_protobuf_MessageOptions_feat } UPB_INLINE bool google_protobuf_MessageOptions_has_features(const google_protobuf_MessageOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MessageOptions_msg_init(), 12); - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_MessageOptions_clear_uninterpreted_option(google_protobuf_MessageOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MessageOptions_msg_init(), 999); @@ -3953,7 +3953,7 @@ UPB_INLINE int32_t google_protobuf_FieldOptions_ctype(const google_protobuf_Fiel } UPB_INLINE bool google_protobuf_FieldOptions_has_ctype(const google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 1); - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldOptions_clear_packed(google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 2); @@ -3969,7 +3969,7 @@ UPB_INLINE bool google_protobuf_FieldOptions_packed(const google_protobuf_FieldO } UPB_INLINE bool google_protobuf_FieldOptions_has_packed(const google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 2); - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldOptions_clear_deprecated(google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 3); @@ -3985,7 +3985,7 @@ UPB_INLINE bool google_protobuf_FieldOptions_deprecated(const google_protobuf_Fi } UPB_INLINE bool google_protobuf_FieldOptions_has_deprecated(const google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 3); - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldOptions_clear_lazy(google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 5); @@ -4001,7 +4001,7 @@ UPB_INLINE bool google_protobuf_FieldOptions_lazy(const google_protobuf_FieldOpt } UPB_INLINE bool google_protobuf_FieldOptions_has_lazy(const google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 5); - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldOptions_clear_jstype(google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 6); @@ -4017,7 +4017,7 @@ UPB_INLINE int32_t google_protobuf_FieldOptions_jstype(const google_protobuf_Fie } UPB_INLINE bool google_protobuf_FieldOptions_has_jstype(const google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 6); - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldOptions_clear_weak(google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 10); @@ -4033,7 +4033,7 @@ UPB_INLINE bool google_protobuf_FieldOptions_weak(const google_protobuf_FieldOpt } UPB_INLINE bool google_protobuf_FieldOptions_has_weak(const google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 10); - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldOptions_clear_unverified_lazy(google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 15); @@ -4049,7 +4049,7 @@ UPB_INLINE bool google_protobuf_FieldOptions_unverified_lazy(const google_protob } UPB_INLINE bool google_protobuf_FieldOptions_has_unverified_lazy(const google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 15); - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldOptions_clear_debug_redact(google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 16); @@ -4065,7 +4065,7 @@ UPB_INLINE bool google_protobuf_FieldOptions_debug_redact(const google_protobuf_ } UPB_INLINE bool google_protobuf_FieldOptions_has_debug_redact(const google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 16); - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldOptions_clear_retention(google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 17); @@ -4081,7 +4081,7 @@ UPB_INLINE int32_t google_protobuf_FieldOptions_retention(const google_protobuf_ } UPB_INLINE bool google_protobuf_FieldOptions_has_retention(const google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 17); - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldOptions_clear_targets(google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 19); @@ -4161,7 +4161,7 @@ UPB_INLINE const google_protobuf_FeatureSet* google_protobuf_FieldOptions_featur } UPB_INLINE bool google_protobuf_FieldOptions_has_features(const google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 21); - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldOptions_clear_uninterpreted_option(google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions_msg_init(), 999); @@ -4383,7 +4383,7 @@ UPB_INLINE upb_StringView google_protobuf_FieldOptions_EditionDefault_value(cons } UPB_INLINE bool google_protobuf_FieldOptions_EditionDefault_has_value(const google_protobuf_FieldOptions_EditionDefault* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions__EditionDefault_msg_init(), 2); - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldOptions_EditionDefault_clear_edition(google_protobuf_FieldOptions_EditionDefault* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions__EditionDefault_msg_init(), 3); @@ -4399,7 +4399,7 @@ UPB_INLINE int32_t google_protobuf_FieldOptions_EditionDefault_edition(const goo } UPB_INLINE bool google_protobuf_FieldOptions_EditionDefault_has_edition(const google_protobuf_FieldOptions_EditionDefault* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FieldOptions__EditionDefault_msg_init(), 3); - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldOptions_EditionDefault_set_value(google_protobuf_FieldOptions_EditionDefault *msg, upb_StringView value) { @@ -4461,7 +4461,7 @@ UPB_INLINE const google_protobuf_FeatureSet* google_protobuf_OneofOptions_featur } UPB_INLINE bool google_protobuf_OneofOptions_has_features(const google_protobuf_OneofOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__OneofOptions_msg_init(), 1); - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_OneofOptions_clear_uninterpreted_option(google_protobuf_OneofOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__OneofOptions_msg_init(), 999); @@ -4589,7 +4589,7 @@ UPB_INLINE bool google_protobuf_EnumOptions_allow_alias(const google_protobuf_En } UPB_INLINE bool google_protobuf_EnumOptions_has_allow_alias(const google_protobuf_EnumOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumOptions_msg_init(), 2); - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_EnumOptions_clear_deprecated(google_protobuf_EnumOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumOptions_msg_init(), 3); @@ -4605,7 +4605,7 @@ UPB_INLINE bool google_protobuf_EnumOptions_deprecated(const google_protobuf_Enu } UPB_INLINE bool google_protobuf_EnumOptions_has_deprecated(const google_protobuf_EnumOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumOptions_msg_init(), 3); - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_EnumOptions_clear_deprecated_legacy_json_field_conflicts(google_protobuf_EnumOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumOptions_msg_init(), 6); @@ -4621,7 +4621,7 @@ UPB_INLINE bool google_protobuf_EnumOptions_deprecated_legacy_json_field_conflic } UPB_INLINE bool google_protobuf_EnumOptions_has_deprecated_legacy_json_field_conflicts(const google_protobuf_EnumOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumOptions_msg_init(), 6); - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_EnumOptions_clear_features(google_protobuf_EnumOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumOptions_msg_init(), 7); @@ -4637,7 +4637,7 @@ UPB_INLINE const google_protobuf_FeatureSet* google_protobuf_EnumOptions_feature } UPB_INLINE bool google_protobuf_EnumOptions_has_features(const google_protobuf_EnumOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumOptions_msg_init(), 7); - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_EnumOptions_clear_uninterpreted_option(google_protobuf_EnumOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumOptions_msg_init(), 999); @@ -4777,7 +4777,7 @@ UPB_INLINE bool google_protobuf_EnumValueOptions_deprecated(const google_protobu } UPB_INLINE bool google_protobuf_EnumValueOptions_has_deprecated(const google_protobuf_EnumValueOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumValueOptions_msg_init(), 1); - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_EnumValueOptions_clear_features(google_protobuf_EnumValueOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumValueOptions_msg_init(), 2); @@ -4793,7 +4793,7 @@ UPB_INLINE const google_protobuf_FeatureSet* google_protobuf_EnumValueOptions_fe } UPB_INLINE bool google_protobuf_EnumValueOptions_has_features(const google_protobuf_EnumValueOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumValueOptions_msg_init(), 2); - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_EnumValueOptions_clear_debug_redact(google_protobuf_EnumValueOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumValueOptions_msg_init(), 3); @@ -4809,7 +4809,7 @@ UPB_INLINE bool google_protobuf_EnumValueOptions_debug_redact(const google_proto } UPB_INLINE bool google_protobuf_EnumValueOptions_has_debug_redact(const google_protobuf_EnumValueOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumValueOptions_msg_init(), 3); - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_EnumValueOptions_clear_uninterpreted_option(google_protobuf_EnumValueOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__EnumValueOptions_msg_init(), 999); @@ -4945,7 +4945,7 @@ UPB_INLINE bool google_protobuf_ServiceOptions_deprecated(const google_protobuf_ } UPB_INLINE bool google_protobuf_ServiceOptions_has_deprecated(const google_protobuf_ServiceOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ServiceOptions_msg_init(), 33); - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_ServiceOptions_clear_features(google_protobuf_ServiceOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ServiceOptions_msg_init(), 34); @@ -4961,7 +4961,7 @@ UPB_INLINE const google_protobuf_FeatureSet* google_protobuf_ServiceOptions_feat } UPB_INLINE bool google_protobuf_ServiceOptions_has_features(const google_protobuf_ServiceOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ServiceOptions_msg_init(), 34); - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_ServiceOptions_clear_uninterpreted_option(google_protobuf_ServiceOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__ServiceOptions_msg_init(), 999); @@ -5093,7 +5093,7 @@ UPB_INLINE bool google_protobuf_MethodOptions_deprecated(const google_protobuf_M } UPB_INLINE bool google_protobuf_MethodOptions_has_deprecated(const google_protobuf_MethodOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MethodOptions_msg_init(), 33); - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_MethodOptions_clear_idempotency_level(google_protobuf_MethodOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MethodOptions_msg_init(), 34); @@ -5109,7 +5109,7 @@ UPB_INLINE int32_t google_protobuf_MethodOptions_idempotency_level(const google_ } UPB_INLINE bool google_protobuf_MethodOptions_has_idempotency_level(const google_protobuf_MethodOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MethodOptions_msg_init(), 34); - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_MethodOptions_clear_features(google_protobuf_MethodOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MethodOptions_msg_init(), 35); @@ -5125,7 +5125,7 @@ UPB_INLINE const google_protobuf_FeatureSet* google_protobuf_MethodOptions_featu } UPB_INLINE bool google_protobuf_MethodOptions_has_features(const google_protobuf_MethodOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MethodOptions_msg_init(), 35); - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_MethodOptions_clear_uninterpreted_option(google_protobuf_MethodOptions* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__MethodOptions_msg_init(), 999); @@ -5293,7 +5293,7 @@ UPB_INLINE upb_StringView google_protobuf_UninterpretedOption_identifier_value(c } UPB_INLINE bool google_protobuf_UninterpretedOption_has_identifier_value(const google_protobuf_UninterpretedOption* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__UninterpretedOption_msg_init(), 3); - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_UninterpretedOption_clear_positive_int_value(google_protobuf_UninterpretedOption* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__UninterpretedOption_msg_init(), 4); @@ -5309,7 +5309,7 @@ UPB_INLINE uint64_t google_protobuf_UninterpretedOption_positive_int_value(const } UPB_INLINE bool google_protobuf_UninterpretedOption_has_positive_int_value(const google_protobuf_UninterpretedOption* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__UninterpretedOption_msg_init(), 4); - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_UninterpretedOption_clear_negative_int_value(google_protobuf_UninterpretedOption* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__UninterpretedOption_msg_init(), 5); @@ -5325,7 +5325,7 @@ UPB_INLINE int64_t google_protobuf_UninterpretedOption_negative_int_value(const } UPB_INLINE bool google_protobuf_UninterpretedOption_has_negative_int_value(const google_protobuf_UninterpretedOption* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__UninterpretedOption_msg_init(), 5); - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_UninterpretedOption_clear_double_value(google_protobuf_UninterpretedOption* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__UninterpretedOption_msg_init(), 6); @@ -5341,7 +5341,7 @@ UPB_INLINE double google_protobuf_UninterpretedOption_double_value(const google_ } UPB_INLINE bool google_protobuf_UninterpretedOption_has_double_value(const google_protobuf_UninterpretedOption* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__UninterpretedOption_msg_init(), 6); - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_UninterpretedOption_clear_string_value(google_protobuf_UninterpretedOption* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__UninterpretedOption_msg_init(), 7); @@ -5357,7 +5357,7 @@ UPB_INLINE upb_StringView google_protobuf_UninterpretedOption_string_value(const } UPB_INLINE bool google_protobuf_UninterpretedOption_has_string_value(const google_protobuf_UninterpretedOption* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__UninterpretedOption_msg_init(), 7); - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_UninterpretedOption_clear_aggregate_value(google_protobuf_UninterpretedOption* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__UninterpretedOption_msg_init(), 8); @@ -5373,7 +5373,7 @@ UPB_INLINE upb_StringView google_protobuf_UninterpretedOption_aggregate_value(co } UPB_INLINE bool google_protobuf_UninterpretedOption_has_aggregate_value(const google_protobuf_UninterpretedOption* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__UninterpretedOption_msg_init(), 8); - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE google_protobuf_UninterpretedOption_NamePart** google_protobuf_UninterpretedOption_mutable_name(google_protobuf_UninterpretedOption* msg, size_t* size) { @@ -5481,7 +5481,7 @@ UPB_INLINE upb_StringView google_protobuf_UninterpretedOption_NamePart_name_part } UPB_INLINE bool google_protobuf_UninterpretedOption_NamePart_has_name_part(const google_protobuf_UninterpretedOption_NamePart* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__UninterpretedOption__NamePart_msg_init(), 1); - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_UninterpretedOption_NamePart_clear_is_extension(google_protobuf_UninterpretedOption_NamePart* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__UninterpretedOption__NamePart_msg_init(), 2); @@ -5497,7 +5497,7 @@ UPB_INLINE bool google_protobuf_UninterpretedOption_NamePart_is_extension(const } UPB_INLINE bool google_protobuf_UninterpretedOption_NamePart_has_is_extension(const google_protobuf_UninterpretedOption_NamePart* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__UninterpretedOption__NamePart_msg_init(), 2); - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_UninterpretedOption_NamePart_set_name_part(google_protobuf_UninterpretedOption_NamePart *msg, upb_StringView value) { @@ -5559,7 +5559,7 @@ UPB_INLINE int32_t google_protobuf_FeatureSet_field_presence(const google_protob } UPB_INLINE bool google_protobuf_FeatureSet_has_field_presence(const google_protobuf_FeatureSet* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FeatureSet_msg_init(), 1); - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FeatureSet_clear_enum_type(google_protobuf_FeatureSet* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FeatureSet_msg_init(), 2); @@ -5575,7 +5575,7 @@ UPB_INLINE int32_t google_protobuf_FeatureSet_enum_type(const google_protobuf_Fe } UPB_INLINE bool google_protobuf_FeatureSet_has_enum_type(const google_protobuf_FeatureSet* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FeatureSet_msg_init(), 2); - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FeatureSet_clear_repeated_field_encoding(google_protobuf_FeatureSet* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FeatureSet_msg_init(), 3); @@ -5591,7 +5591,7 @@ UPB_INLINE int32_t google_protobuf_FeatureSet_repeated_field_encoding(const goog } UPB_INLINE bool google_protobuf_FeatureSet_has_repeated_field_encoding(const google_protobuf_FeatureSet* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FeatureSet_msg_init(), 3); - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FeatureSet_clear_utf8_validation(google_protobuf_FeatureSet* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FeatureSet_msg_init(), 4); @@ -5607,7 +5607,7 @@ UPB_INLINE int32_t google_protobuf_FeatureSet_utf8_validation(const google_proto } UPB_INLINE bool google_protobuf_FeatureSet_has_utf8_validation(const google_protobuf_FeatureSet* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FeatureSet_msg_init(), 4); - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FeatureSet_clear_message_encoding(google_protobuf_FeatureSet* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FeatureSet_msg_init(), 5); @@ -5623,7 +5623,7 @@ UPB_INLINE int32_t google_protobuf_FeatureSet_message_encoding(const google_prot } UPB_INLINE bool google_protobuf_FeatureSet_has_message_encoding(const google_protobuf_FeatureSet* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FeatureSet_msg_init(), 5); - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FeatureSet_clear_json_format(google_protobuf_FeatureSet* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FeatureSet_msg_init(), 6); @@ -5639,7 +5639,7 @@ UPB_INLINE int32_t google_protobuf_FeatureSet_json_format(const google_protobuf_ } UPB_INLINE bool google_protobuf_FeatureSet_has_json_format(const google_protobuf_FeatureSet* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FeatureSet_msg_init(), 6); - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FeatureSet_set_field_presence(google_protobuf_FeatureSet *msg, int32_t value) { @@ -5749,7 +5749,7 @@ UPB_INLINE int32_t google_protobuf_FeatureSetDefaults_minimum_edition(const goog } UPB_INLINE bool google_protobuf_FeatureSetDefaults_has_minimum_edition(const google_protobuf_FeatureSetDefaults* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FeatureSetDefaults_msg_init(), 4); - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FeatureSetDefaults_clear_maximum_edition(google_protobuf_FeatureSetDefaults* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FeatureSetDefaults_msg_init(), 5); @@ -5765,7 +5765,7 @@ UPB_INLINE int32_t google_protobuf_FeatureSetDefaults_maximum_edition(const goog } UPB_INLINE bool google_protobuf_FeatureSetDefaults_has_maximum_edition(const google_protobuf_FeatureSetDefaults* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FeatureSetDefaults_msg_init(), 5); - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault** google_protobuf_FeatureSetDefaults_mutable_defaults(google_protobuf_FeatureSetDefaults* msg, size_t* size) { @@ -5857,7 +5857,7 @@ UPB_INLINE const google_protobuf_FeatureSet* google_protobuf_FeatureSetDefaults_ } UPB_INLINE bool google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_has_features(const google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FeatureSetDefaults__FeatureSetEditionDefault_msg_init(), 2); - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_clear_edition(google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FeatureSetDefaults__FeatureSetEditionDefault_msg_init(), 3); @@ -5873,7 +5873,7 @@ UPB_INLINE int32_t google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_e } UPB_INLINE bool google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_has_edition(const google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__FeatureSetDefaults__FeatureSetEditionDefault_msg_init(), 3); - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_set_features(google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault *msg, google_protobuf_FeatureSet* value) { @@ -6107,7 +6107,7 @@ UPB_INLINE upb_StringView google_protobuf_SourceCodeInfo_Location_leading_commen } UPB_INLINE bool google_protobuf_SourceCodeInfo_Location_has_leading_comments(const google_protobuf_SourceCodeInfo_Location* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__SourceCodeInfo__Location_msg_init(), 3); - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_SourceCodeInfo_Location_clear_trailing_comments(google_protobuf_SourceCodeInfo_Location* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__SourceCodeInfo__Location_msg_init(), 4); @@ -6123,7 +6123,7 @@ UPB_INLINE upb_StringView google_protobuf_SourceCodeInfo_Location_trailing_comme } UPB_INLINE bool google_protobuf_SourceCodeInfo_Location_has_trailing_comments(const google_protobuf_SourceCodeInfo_Location* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__SourceCodeInfo__Location_msg_init(), 4); - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_SourceCodeInfo_Location_clear_leading_detached_comments(google_protobuf_SourceCodeInfo_Location* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__SourceCodeInfo__Location_msg_init(), 6); @@ -6433,7 +6433,7 @@ UPB_INLINE upb_StringView google_protobuf_GeneratedCodeInfo_Annotation_source_fi } UPB_INLINE bool google_protobuf_GeneratedCodeInfo_Annotation_has_source_file(const google_protobuf_GeneratedCodeInfo_Annotation* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__GeneratedCodeInfo__Annotation_msg_init(), 2); - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_GeneratedCodeInfo_Annotation_clear_begin(google_protobuf_GeneratedCodeInfo_Annotation* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__GeneratedCodeInfo__Annotation_msg_init(), 3); @@ -6449,7 +6449,7 @@ UPB_INLINE int32_t google_protobuf_GeneratedCodeInfo_Annotation_begin(const goog } UPB_INLINE bool google_protobuf_GeneratedCodeInfo_Annotation_has_begin(const google_protobuf_GeneratedCodeInfo_Annotation* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__GeneratedCodeInfo__Annotation_msg_init(), 3); - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_GeneratedCodeInfo_Annotation_clear_end(google_protobuf_GeneratedCodeInfo_Annotation* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__GeneratedCodeInfo__Annotation_msg_init(), 4); @@ -6465,7 +6465,7 @@ UPB_INLINE int32_t google_protobuf_GeneratedCodeInfo_Annotation_end(const google } UPB_INLINE bool google_protobuf_GeneratedCodeInfo_Annotation_has_end(const google_protobuf_GeneratedCodeInfo_Annotation* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__GeneratedCodeInfo__Annotation_msg_init(), 4); - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_GeneratedCodeInfo_Annotation_clear_semantic(google_protobuf_GeneratedCodeInfo_Annotation* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__GeneratedCodeInfo__Annotation_msg_init(), 5); @@ -6481,7 +6481,7 @@ UPB_INLINE int32_t google_protobuf_GeneratedCodeInfo_Annotation_semantic(const g } UPB_INLINE bool google_protobuf_GeneratedCodeInfo_Annotation_has_semantic(const google_protobuf_GeneratedCodeInfo_Annotation* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__GeneratedCodeInfo__Annotation_msg_init(), 5); - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t* google_protobuf_GeneratedCodeInfo_Annotation_mutable_path(google_protobuf_GeneratedCodeInfo_Annotation* msg, size_t* size) { diff --git a/upb_generator/BUILD b/upb_generator/BUILD index 8fc302850c522..a350e0743fdd8 100644 --- a/upb_generator/BUILD +++ b/upb_generator/BUILD @@ -265,6 +265,7 @@ bootstrap_cc_binary( deps = [ "//upb:base", "//upb:mem", + "//upb:mini_table", "//upb:port", "//upb:wire_reader", "@com_google_absl//absl/container:flat_hash_map", diff --git a/upb_generator/protoc-gen-upb.cc b/upb_generator/protoc-gen-upb.cc index e6f8c2b424070..82d254d53069f 100644 --- a/upb_generator/protoc-gen-upb.cc +++ b/upb_generator/protoc-gen-upb.cc @@ -13,22 +13,21 @@ #include #include #include -#include #include #include #include -#include "absl/container/flat_hash_map.h" -#include "absl/container/flat_hash_set.h" #include "absl/log/absl_check.h" #include "absl/log/absl_log.h" #include "absl/strings/escaping.h" +#include "absl/strings/str_cat.h" #include "absl/strings/str_replace.h" #include "absl/strings/string_view.h" #include "absl/strings/substitute.h" #include "upb/base/descriptor_constants.h" #include "upb/base/status.hpp" #include "upb/base/string_view.h" +#include "upb/mini_table/field.h" #include "upb/reflection/def.hpp" #include "upb/wire/types.h" #include "upb_generator/common.h" @@ -261,7 +260,7 @@ void GenerateExtensionInHeader(const DefPoolPair& pools, upb::FieldDefPtr ext, output( R"cc( UPB_INLINE bool $0_has_$1(const struct $2* msg) { - return _upb_Message_HasExtensionField((upb_Message*)msg, &$3); + return upb_Message_HasExtension((upb_Message*)msg, &$3); } )cc", ExtensionIdentBase(ext), ext.name(), MessageName(ext.containing_type()), @@ -416,7 +415,7 @@ void GenerateHazzer(upb::FieldDefPtr field, const DefPoolPair& pools, R"cc( UPB_INLINE bool $0_has_$1(const $0* msg) { const upb_MiniTableField field = $2; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } )cc", msg_name, resolved_name, FieldInitializer(pools, field, options)); diff --git a/upb_generator/stage0/google/protobuf/compiler/plugin.upb.h b/upb_generator/stage0/google/protobuf/compiler/plugin.upb.h index 8248bc3f8917f..6c5d63958e1ad 100644 --- a/upb_generator/stage0/google/protobuf/compiler/plugin.upb.h +++ b/upb_generator/stage0/google/protobuf/compiler/plugin.upb.h @@ -90,7 +90,7 @@ UPB_INLINE int32_t google_protobuf_compiler_Version_major(const google_protobuf_ } UPB_INLINE bool google_protobuf_compiler_Version_has_major(const google_protobuf_compiler_Version* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__Version_msg_init(), 1); - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_compiler_Version_clear_minor(google_protobuf_compiler_Version* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__Version_msg_init(), 2); @@ -106,7 +106,7 @@ UPB_INLINE int32_t google_protobuf_compiler_Version_minor(const google_protobuf_ } UPB_INLINE bool google_protobuf_compiler_Version_has_minor(const google_protobuf_compiler_Version* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__Version_msg_init(), 2); - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_compiler_Version_clear_patch(google_protobuf_compiler_Version* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__Version_msg_init(), 3); @@ -122,7 +122,7 @@ UPB_INLINE int32_t google_protobuf_compiler_Version_patch(const google_protobuf_ } UPB_INLINE bool google_protobuf_compiler_Version_has_patch(const google_protobuf_compiler_Version* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__Version_msg_init(), 3); - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_compiler_Version_clear_suffix(google_protobuf_compiler_Version* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__Version_msg_init(), 4); @@ -138,7 +138,7 @@ UPB_INLINE upb_StringView google_protobuf_compiler_Version_suffix(const google_p } UPB_INLINE bool google_protobuf_compiler_Version_has_suffix(const google_protobuf_compiler_Version* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__Version_msg_init(), 4); - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_compiler_Version_set_major(google_protobuf_compiler_Version *msg, int32_t value) { @@ -240,7 +240,7 @@ UPB_INLINE upb_StringView google_protobuf_compiler_CodeGeneratorRequest_paramete } UPB_INLINE bool google_protobuf_compiler_CodeGeneratorRequest_has_parameter(const google_protobuf_compiler_CodeGeneratorRequest* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorRequest_msg_init(), 2); - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_compiler_CodeGeneratorRequest_clear_compiler_version(google_protobuf_compiler_CodeGeneratorRequest* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorRequest_msg_init(), 3); @@ -256,7 +256,7 @@ UPB_INLINE const google_protobuf_compiler_Version* google_protobuf_compiler_Code } UPB_INLINE bool google_protobuf_compiler_CodeGeneratorRequest_has_compiler_version(const google_protobuf_compiler_CodeGeneratorRequest* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorRequest_msg_init(), 3); - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_compiler_CodeGeneratorRequest_clear_proto_file(google_protobuf_compiler_CodeGeneratorRequest* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorRequest_msg_init(), 15); @@ -478,7 +478,7 @@ UPB_INLINE upb_StringView google_protobuf_compiler_CodeGeneratorResponse_error(c } UPB_INLINE bool google_protobuf_compiler_CodeGeneratorResponse_has_error(const google_protobuf_compiler_CodeGeneratorResponse* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorResponse_msg_init(), 1); - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_compiler_CodeGeneratorResponse_clear_supported_features(google_protobuf_compiler_CodeGeneratorResponse* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorResponse_msg_init(), 2); @@ -494,7 +494,7 @@ UPB_INLINE uint64_t google_protobuf_compiler_CodeGeneratorResponse_supported_fea } UPB_INLINE bool google_protobuf_compiler_CodeGeneratorResponse_has_supported_features(const google_protobuf_compiler_CodeGeneratorResponse* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorResponse_msg_init(), 2); - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_compiler_CodeGeneratorResponse_clear_minimum_edition(google_protobuf_compiler_CodeGeneratorResponse* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorResponse_msg_init(), 3); @@ -510,7 +510,7 @@ UPB_INLINE int32_t google_protobuf_compiler_CodeGeneratorResponse_minimum_editio } UPB_INLINE bool google_protobuf_compiler_CodeGeneratorResponse_has_minimum_edition(const google_protobuf_compiler_CodeGeneratorResponse* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorResponse_msg_init(), 3); - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_compiler_CodeGeneratorResponse_clear_maximum_edition(google_protobuf_compiler_CodeGeneratorResponse* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorResponse_msg_init(), 4); @@ -526,7 +526,7 @@ UPB_INLINE int32_t google_protobuf_compiler_CodeGeneratorResponse_maximum_editio } UPB_INLINE bool google_protobuf_compiler_CodeGeneratorResponse_has_maximum_edition(const google_protobuf_compiler_CodeGeneratorResponse* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorResponse_msg_init(), 4); - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_compiler_CodeGeneratorResponse_clear_file(google_protobuf_compiler_CodeGeneratorResponse* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorResponse_msg_init(), 15); @@ -658,7 +658,7 @@ UPB_INLINE upb_StringView google_protobuf_compiler_CodeGeneratorResponse_File_na } UPB_INLINE bool google_protobuf_compiler_CodeGeneratorResponse_File_has_name(const google_protobuf_compiler_CodeGeneratorResponse_File* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorResponse__File_msg_init(), 1); - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_compiler_CodeGeneratorResponse_File_clear_insertion_point(google_protobuf_compiler_CodeGeneratorResponse_File* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorResponse__File_msg_init(), 2); @@ -674,7 +674,7 @@ UPB_INLINE upb_StringView google_protobuf_compiler_CodeGeneratorResponse_File_in } UPB_INLINE bool google_protobuf_compiler_CodeGeneratorResponse_File_has_insertion_point(const google_protobuf_compiler_CodeGeneratorResponse_File* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorResponse__File_msg_init(), 2); - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_compiler_CodeGeneratorResponse_File_clear_content(google_protobuf_compiler_CodeGeneratorResponse_File* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorResponse__File_msg_init(), 15); @@ -690,7 +690,7 @@ UPB_INLINE upb_StringView google_protobuf_compiler_CodeGeneratorResponse_File_co } UPB_INLINE bool google_protobuf_compiler_CodeGeneratorResponse_File_has_content(const google_protobuf_compiler_CodeGeneratorResponse_File* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorResponse__File_msg_init(), 15); - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_compiler_CodeGeneratorResponse_File_clear_generated_code_info(google_protobuf_compiler_CodeGeneratorResponse_File* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorResponse__File_msg_init(), 16); @@ -706,7 +706,7 @@ UPB_INLINE const struct google_protobuf_GeneratedCodeInfo* google_protobuf_compi } UPB_INLINE bool google_protobuf_compiler_CodeGeneratorResponse_File_has_generated_code_info(const google_protobuf_compiler_CodeGeneratorResponse_File* msg) { const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorResponse__File_msg_init(), 16); - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_compiler_CodeGeneratorResponse_File_set_name(google_protobuf_compiler_CodeGeneratorResponse_File *msg, upb_StringView value) { From 8c1f63571668338172148a1bea4575a33736a8c2 Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Wed, 10 Jan 2024 05:18:15 +0000 Subject: [PATCH 231/255] Auto-generate files after cl/597126288 --- php/ext/google/protobuf/php-upb.c | 8 +- php/ext/google/protobuf/php-upb.h | 278 ++++++++++----------- ruby/ext/google/protobuf_c/ruby-upb.c | 8 +- ruby/ext/google/protobuf_c/ruby-upb.h | 278 ++++++++++----------- upb/cmake/google/protobuf/descriptor.upb.h | 246 +++++++++--------- 5 files changed, 415 insertions(+), 403 deletions(-) diff --git a/php/ext/google/protobuf/php-upb.c b/php/ext/google/protobuf/php-upb.c index c801ca1b45d3c..4e75233c2beac 100644 --- a/php/ext/google/protobuf/php-upb.c +++ b/php/ext/google/protobuf/php-upb.c @@ -14544,8 +14544,14 @@ char* upb_strdup2(const char* s, size_t len, upb_Arena* a) { // Must be last. bool upb_Message_HasFieldByDef(const upb_Message* msg, const upb_FieldDef* f) { + const upb_MiniTableField* m_f = upb_FieldDef_MiniTable(f); UPB_ASSERT(upb_FieldDef_HasPresence(f)); - return upb_Message_HasField(msg, upb_FieldDef_MiniTable(f)); + + if (upb_MiniTableField_IsExtension(m_f)) { + return upb_Message_HasExtension(msg, (const upb_MiniTableExtension*)m_f); + } else { + return upb_Message_HasBaseField(msg, m_f); + } } const upb_FieldDef* upb_Message_WhichOneof(const upb_Message* msg, diff --git a/php/ext/google/protobuf/php-upb.h b/php/ext/google/protobuf/php-upb.h index 80b4e33de84fd..a9c187123b1fe 100644 --- a/php/ext/google/protobuf/php-upb.h +++ b/php/ext/google/protobuf/php-upb.h @@ -2562,13 +2562,7 @@ UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_DataIsZero)( // of a setter is known to be a non-extension, the arena may be NULL and the // returned bool value may be ignored since it will always succeed. -UPB_INLINE bool _upb_Message_HasExtensionField( - const struct upb_Message* msg, const upb_MiniTableExtension* ext) { - UPB_ASSERT(upb_MiniTableField_HasPresence(&ext->UPB_PRIVATE(field))); - return _upb_Message_Getext(msg, ext) != NULL; -} - -UPB_INLINE bool _upb_Message_HasNonExtensionField( +UPB_INLINE bool UPB_PRIVATE(_upb_Message_HasBaseField)( const struct upb_Message* msg, const upb_MiniTableField* field) { UPB_ASSERT(upb_MiniTableField_HasPresence(field)); UPB_ASSUME(!upb_MiniTableField_IsExtension(field)); @@ -2580,13 +2574,19 @@ UPB_INLINE bool _upb_Message_HasNonExtensionField( } } +UPB_INLINE bool UPB_PRIVATE(_upb_Message_HasExtension)( + const struct upb_Message* msg, const upb_MiniTableExtension* ext) { + UPB_ASSERT(upb_MiniTableField_HasPresence(&ext->UPB_PRIVATE(field))); + return _upb_Message_Getext(msg, ext) != NULL; +} + static UPB_FORCEINLINE void _upb_Message_GetNonExtensionField( const struct upb_Message* msg, const upb_MiniTableField* field, const void* default_val, void* val) { UPB_ASSUME(!upb_MiniTableField_IsExtension(field)); if ((upb_MiniTableField_IsInOneof(field) || !UPB_PRIVATE(_upb_MiniTableField_DataIsZero)(field, default_val)) && - !_upb_Message_HasNonExtensionField(msg, field)) { + !UPB_PRIVATE(_upb_Message_HasBaseField)(msg, field)) { UPB_PRIVATE(_upb_MiniTableField_DataCopy)(field, val, default_val); return; } @@ -3102,14 +3102,14 @@ UPB_API_INLINE void upb_Message_ClearExtension( UPB_PRIVATE(_upb_Message_ClearExtension)(msg, e); } -UPB_API_INLINE bool upb_Message_HasField(const upb_Message* msg, - const upb_MiniTableField* field) { - if (upb_MiniTableField_IsExtension(field)) { - const upb_MiniTableExtension* ext = (const upb_MiniTableExtension*)field; - return _upb_Message_HasExtensionField(msg, ext); - } else { - return _upb_Message_HasNonExtensionField(msg, field); - } +UPB_API_INLINE bool upb_Message_HasBaseField(const upb_Message* msg, + const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_Message_HasBaseField)(msg, f); +} + +UPB_API_INLINE bool upb_Message_HasExtension(const upb_Message* msg, + const upb_MiniTableExtension* e) { + return UPB_PRIVATE(_upb_Message_HasExtension)(msg, e); } UPB_API_INLINE uint32_t upb_Message_WhichOneofFieldNumber( @@ -4702,7 +4702,7 @@ UPB_INLINE upb_StringView google_protobuf_FileDescriptorProto_name(const google_ } UPB_INLINE bool google_protobuf_FileDescriptorProto_has_name(const google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = {1, UPB_SIZE(44, 8), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileDescriptorProto_clear_package(google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = {2, UPB_SIZE(52, 24), 2, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; @@ -4718,7 +4718,7 @@ UPB_INLINE upb_StringView google_protobuf_FileDescriptorProto_package(const goog } UPB_INLINE bool google_protobuf_FileDescriptorProto_has_package(const google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = {2, UPB_SIZE(52, 24), 2, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileDescriptorProto_clear_dependency(google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = {3, UPB_SIZE(4, 40), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -4894,7 +4894,7 @@ UPB_INLINE const google_protobuf_FileOptions* google_protobuf_FileDescriptorProt } UPB_INLINE bool google_protobuf_FileDescriptorProto_has_options(const google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = {8, UPB_SIZE(24, 80), 3, 4, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileDescriptorProto_clear_source_code_info(google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = {9, UPB_SIZE(28, 88), 4, 5, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -4910,7 +4910,7 @@ UPB_INLINE const google_protobuf_SourceCodeInfo* google_protobuf_FileDescriptorP } UPB_INLINE bool google_protobuf_FileDescriptorProto_has_source_code_info(const google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = {9, UPB_SIZE(28, 88), 4, 5, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileDescriptorProto_clear_public_dependency(google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = {10, UPB_SIZE(32, 96), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -4990,7 +4990,7 @@ UPB_INLINE upb_StringView google_protobuf_FileDescriptorProto_syntax(const googl } UPB_INLINE bool google_protobuf_FileDescriptorProto_has_syntax(const google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = {12, UPB_SIZE(60, 112), 5, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileDescriptorProto_clear_edition(google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = {14, UPB_SIZE(40, 4), 6, 6, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; @@ -5006,7 +5006,7 @@ UPB_INLINE int32_t google_protobuf_FileDescriptorProto_edition(const google_prot } UPB_INLINE bool google_protobuf_FileDescriptorProto_has_edition(const google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = {14, UPB_SIZE(40, 4), 6, 6, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileDescriptorProto_set_name(google_protobuf_FileDescriptorProto *msg, upb_StringView value) { @@ -5304,7 +5304,7 @@ UPB_INLINE upb_StringView google_protobuf_DescriptorProto_name(const google_prot } UPB_INLINE bool google_protobuf_DescriptorProto_has_name(const google_protobuf_DescriptorProto* msg) { const upb_MiniTableField field = {1, UPB_SIZE(40, 8), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_DescriptorProto_clear_field(google_protobuf_DescriptorProto* msg) { const upb_MiniTableField field = {2, UPB_SIZE(4, 24), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -5480,7 +5480,7 @@ UPB_INLINE const google_protobuf_MessageOptions* google_protobuf_DescriptorProto } UPB_INLINE bool google_protobuf_DescriptorProto_has_options(const google_protobuf_DescriptorProto* msg) { const upb_MiniTableField field = {7, UPB_SIZE(24, 64), 2, 5, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_DescriptorProto_clear_oneof_decl(google_protobuf_DescriptorProto* msg) { const upb_MiniTableField field = {8, UPB_SIZE(28, 72), 0, 6, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -5884,7 +5884,7 @@ UPB_INLINE int32_t google_protobuf_DescriptorProto_ExtensionRange_start(const go } UPB_INLINE bool google_protobuf_DescriptorProto_ExtensionRange_has_start(const google_protobuf_DescriptorProto_ExtensionRange* msg) { const upb_MiniTableField field = {1, 4, 1, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_DescriptorProto_ExtensionRange_clear_end(google_protobuf_DescriptorProto_ExtensionRange* msg) { const upb_MiniTableField field = {2, 8, 2, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; @@ -5900,7 +5900,7 @@ UPB_INLINE int32_t google_protobuf_DescriptorProto_ExtensionRange_end(const goog } UPB_INLINE bool google_protobuf_DescriptorProto_ExtensionRange_has_end(const google_protobuf_DescriptorProto_ExtensionRange* msg) { const upb_MiniTableField field = {2, 8, 2, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_DescriptorProto_ExtensionRange_clear_options(google_protobuf_DescriptorProto_ExtensionRange* msg) { const upb_MiniTableField field = {3, UPB_SIZE(12, 16), 3, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -5916,7 +5916,7 @@ UPB_INLINE const google_protobuf_ExtensionRangeOptions* google_protobuf_Descript } UPB_INLINE bool google_protobuf_DescriptorProto_ExtensionRange_has_options(const google_protobuf_DescriptorProto_ExtensionRange* msg) { const upb_MiniTableField field = {3, UPB_SIZE(12, 16), 3, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_DescriptorProto_ExtensionRange_set_start(google_protobuf_DescriptorProto_ExtensionRange *msg, int32_t value) { @@ -5990,7 +5990,7 @@ UPB_INLINE int32_t google_protobuf_DescriptorProto_ReservedRange_start(const goo } UPB_INLINE bool google_protobuf_DescriptorProto_ReservedRange_has_start(const google_protobuf_DescriptorProto_ReservedRange* msg) { const upb_MiniTableField field = {1, 4, 1, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_DescriptorProto_ReservedRange_clear_end(google_protobuf_DescriptorProto_ReservedRange* msg) { const upb_MiniTableField field = {2, 8, 2, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; @@ -6006,7 +6006,7 @@ UPB_INLINE int32_t google_protobuf_DescriptorProto_ReservedRange_end(const googl } UPB_INLINE bool google_protobuf_DescriptorProto_ReservedRange_has_end(const google_protobuf_DescriptorProto_ReservedRange* msg) { const upb_MiniTableField field = {2, 8, 2, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_DescriptorProto_ReservedRange_set_start(google_protobuf_DescriptorProto_ReservedRange *msg, int32_t value) { @@ -6100,7 +6100,7 @@ UPB_INLINE int32_t google_protobuf_ExtensionRangeOptions_verification(const goog } UPB_INLINE bool google_protobuf_ExtensionRangeOptions_has_verification(const google_protobuf_ExtensionRangeOptions* msg) { const upb_MiniTableField field = {3, UPB_SIZE(8, 4), 1, 3, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_ExtensionRangeOptions_clear_features(google_protobuf_ExtensionRangeOptions* msg) { const upb_MiniTableField field = {50, UPB_SIZE(12, 16), 2, 1, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -6116,7 +6116,7 @@ UPB_INLINE const google_protobuf_FeatureSet* google_protobuf_ExtensionRangeOptio } UPB_INLINE bool google_protobuf_ExtensionRangeOptions_has_features(const google_protobuf_ExtensionRangeOptions* msg) { const upb_MiniTableField field = {50, UPB_SIZE(12, 16), 2, 1, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_ExtensionRangeOptions_clear_uninterpreted_option(google_protobuf_ExtensionRangeOptions* msg) { const upb_MiniTableField field = {999, UPB_SIZE(16, 24), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -6278,7 +6278,7 @@ UPB_INLINE int32_t google_protobuf_ExtensionRangeOptions_Declaration_number(cons } UPB_INLINE bool google_protobuf_ExtensionRangeOptions_Declaration_has_number(const google_protobuf_ExtensionRangeOptions_Declaration* msg) { const upb_MiniTableField field = {1, 4, 1, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_ExtensionRangeOptions_Declaration_clear_full_name(google_protobuf_ExtensionRangeOptions_Declaration* msg) { const upb_MiniTableField field = {2, UPB_SIZE(12, 16), 2, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; @@ -6294,7 +6294,7 @@ UPB_INLINE upb_StringView google_protobuf_ExtensionRangeOptions_Declaration_full } UPB_INLINE bool google_protobuf_ExtensionRangeOptions_Declaration_has_full_name(const google_protobuf_ExtensionRangeOptions_Declaration* msg) { const upb_MiniTableField field = {2, UPB_SIZE(12, 16), 2, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_ExtensionRangeOptions_Declaration_clear_type(google_protobuf_ExtensionRangeOptions_Declaration* msg) { const upb_MiniTableField field = {3, UPB_SIZE(20, 32), 3, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; @@ -6310,7 +6310,7 @@ UPB_INLINE upb_StringView google_protobuf_ExtensionRangeOptions_Declaration_type } UPB_INLINE bool google_protobuf_ExtensionRangeOptions_Declaration_has_type(const google_protobuf_ExtensionRangeOptions_Declaration* msg) { const upb_MiniTableField field = {3, UPB_SIZE(20, 32), 3, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_ExtensionRangeOptions_Declaration_clear_reserved(google_protobuf_ExtensionRangeOptions_Declaration* msg) { const upb_MiniTableField field = {5, 8, 4, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; @@ -6326,7 +6326,7 @@ UPB_INLINE bool google_protobuf_ExtensionRangeOptions_Declaration_reserved(const } UPB_INLINE bool google_protobuf_ExtensionRangeOptions_Declaration_has_reserved(const google_protobuf_ExtensionRangeOptions_Declaration* msg) { const upb_MiniTableField field = {5, 8, 4, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_ExtensionRangeOptions_Declaration_clear_repeated(google_protobuf_ExtensionRangeOptions_Declaration* msg) { const upb_MiniTableField field = {6, 9, 5, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; @@ -6342,7 +6342,7 @@ UPB_INLINE bool google_protobuf_ExtensionRangeOptions_Declaration_repeated(const } UPB_INLINE bool google_protobuf_ExtensionRangeOptions_Declaration_has_repeated(const google_protobuf_ExtensionRangeOptions_Declaration* msg) { const upb_MiniTableField field = {6, 9, 5, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_ExtensionRangeOptions_Declaration_set_number(google_protobuf_ExtensionRangeOptions_Declaration *msg, int32_t value) { @@ -6416,7 +6416,7 @@ UPB_INLINE upb_StringView google_protobuf_FieldDescriptorProto_name(const google } UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_name(const google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = {1, UPB_SIZE(28, 24), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldDescriptorProto_clear_extendee(google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = {2, UPB_SIZE(36, 40), 2, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; @@ -6432,7 +6432,7 @@ UPB_INLINE upb_StringView google_protobuf_FieldDescriptorProto_extendee(const go } UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_extendee(const google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = {2, UPB_SIZE(36, 40), 2, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldDescriptorProto_clear_number(google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = {3, 4, 3, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; @@ -6448,7 +6448,7 @@ UPB_INLINE int32_t google_protobuf_FieldDescriptorProto_number(const google_prot } UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_number(const google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = {3, 4, 3, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldDescriptorProto_clear_label(google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = {4, 8, 4, 1, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; @@ -6464,7 +6464,7 @@ UPB_INLINE int32_t google_protobuf_FieldDescriptorProto_label(const google_proto } UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_label(const google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = {4, 8, 4, 1, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldDescriptorProto_clear_type(google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = {5, 12, 5, 2, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; @@ -6480,7 +6480,7 @@ UPB_INLINE int32_t google_protobuf_FieldDescriptorProto_type(const google_protob } UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_type(const google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = {5, 12, 5, 2, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldDescriptorProto_clear_type_name(google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = {6, UPB_SIZE(44, 56), 6, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; @@ -6496,7 +6496,7 @@ UPB_INLINE upb_StringView google_protobuf_FieldDescriptorProto_type_name(const g } UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_type_name(const google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = {6, UPB_SIZE(44, 56), 6, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldDescriptorProto_clear_default_value(google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = {7, UPB_SIZE(52, 72), 7, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; @@ -6512,7 +6512,7 @@ UPB_INLINE upb_StringView google_protobuf_FieldDescriptorProto_default_value(con } UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_default_value(const google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = {7, UPB_SIZE(52, 72), 7, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldDescriptorProto_clear_options(google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = {8, UPB_SIZE(16, 88), 8, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -6528,7 +6528,7 @@ UPB_INLINE const google_protobuf_FieldOptions* google_protobuf_FieldDescriptorPr } UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_options(const google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = {8, UPB_SIZE(16, 88), 8, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldDescriptorProto_clear_oneof_index(google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = {9, UPB_SIZE(20, 16), 9, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; @@ -6544,7 +6544,7 @@ UPB_INLINE int32_t google_protobuf_FieldDescriptorProto_oneof_index(const google } UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_oneof_index(const google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = {9, UPB_SIZE(20, 16), 9, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldDescriptorProto_clear_json_name(google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = {10, UPB_SIZE(60, 96), 10, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; @@ -6560,7 +6560,7 @@ UPB_INLINE upb_StringView google_protobuf_FieldDescriptorProto_json_name(const g } UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_json_name(const google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = {10, UPB_SIZE(60, 96), 10, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldDescriptorProto_clear_proto3_optional(google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = {17, UPB_SIZE(24, 20), 11, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; @@ -6576,7 +6576,7 @@ UPB_INLINE bool google_protobuf_FieldDescriptorProto_proto3_optional(const googl } UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_proto3_optional(const google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = {17, UPB_SIZE(24, 20), 11, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldDescriptorProto_set_name(google_protobuf_FieldDescriptorProto *msg, upb_StringView value) { @@ -6682,7 +6682,7 @@ UPB_INLINE upb_StringView google_protobuf_OneofDescriptorProto_name(const google } UPB_INLINE bool google_protobuf_OneofDescriptorProto_has_name(const google_protobuf_OneofDescriptorProto* msg) { const upb_MiniTableField field = {1, 8, 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_OneofDescriptorProto_clear_options(google_protobuf_OneofDescriptorProto* msg) { const upb_MiniTableField field = {2, UPB_SIZE(4, 24), 2, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -6698,7 +6698,7 @@ UPB_INLINE const google_protobuf_OneofOptions* google_protobuf_OneofDescriptorPr } UPB_INLINE bool google_protobuf_OneofDescriptorProto_has_options(const google_protobuf_OneofDescriptorProto* msg) { const upb_MiniTableField field = {2, UPB_SIZE(4, 24), 2, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_OneofDescriptorProto_set_name(google_protobuf_OneofDescriptorProto *msg, upb_StringView value) { @@ -6768,7 +6768,7 @@ UPB_INLINE upb_StringView google_protobuf_EnumDescriptorProto_name(const google_ } UPB_INLINE bool google_protobuf_EnumDescriptorProto_has_name(const google_protobuf_EnumDescriptorProto* msg) { const upb_MiniTableField field = {1, UPB_SIZE(20, 8), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_EnumDescriptorProto_clear_value(google_protobuf_EnumDescriptorProto* msg) { const upb_MiniTableField field = {2, UPB_SIZE(4, 24), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -6816,7 +6816,7 @@ UPB_INLINE const google_protobuf_EnumOptions* google_protobuf_EnumDescriptorProt } UPB_INLINE bool google_protobuf_EnumDescriptorProto_has_options(const google_protobuf_EnumDescriptorProto* msg) { const upb_MiniTableField field = {3, UPB_SIZE(8, 32), 2, 1, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_EnumDescriptorProto_clear_reserved_range(google_protobuf_EnumDescriptorProto* msg) { const upb_MiniTableField field = {4, UPB_SIZE(12, 40), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -7038,7 +7038,7 @@ UPB_INLINE int32_t google_protobuf_EnumDescriptorProto_EnumReservedRange_start(c } UPB_INLINE bool google_protobuf_EnumDescriptorProto_EnumReservedRange_has_start(const google_protobuf_EnumDescriptorProto_EnumReservedRange* msg) { const upb_MiniTableField field = {1, 4, 1, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_EnumDescriptorProto_EnumReservedRange_clear_end(google_protobuf_EnumDescriptorProto_EnumReservedRange* msg) { const upb_MiniTableField field = {2, 8, 2, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; @@ -7054,7 +7054,7 @@ UPB_INLINE int32_t google_protobuf_EnumDescriptorProto_EnumReservedRange_end(con } UPB_INLINE bool google_protobuf_EnumDescriptorProto_EnumReservedRange_has_end(const google_protobuf_EnumDescriptorProto_EnumReservedRange* msg) { const upb_MiniTableField field = {2, 8, 2, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_EnumDescriptorProto_EnumReservedRange_set_start(google_protobuf_EnumDescriptorProto_EnumReservedRange *msg, int32_t value) { @@ -7116,7 +7116,7 @@ UPB_INLINE upb_StringView google_protobuf_EnumValueDescriptorProto_name(const go } UPB_INLINE bool google_protobuf_EnumValueDescriptorProto_has_name(const google_protobuf_EnumValueDescriptorProto* msg) { const upb_MiniTableField field = {1, UPB_SIZE(12, 8), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_EnumValueDescriptorProto_clear_number(google_protobuf_EnumValueDescriptorProto* msg) { const upb_MiniTableField field = {2, 4, 2, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; @@ -7132,7 +7132,7 @@ UPB_INLINE int32_t google_protobuf_EnumValueDescriptorProto_number(const google_ } UPB_INLINE bool google_protobuf_EnumValueDescriptorProto_has_number(const google_protobuf_EnumValueDescriptorProto* msg) { const upb_MiniTableField field = {2, 4, 2, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_EnumValueDescriptorProto_clear_options(google_protobuf_EnumValueDescriptorProto* msg) { const upb_MiniTableField field = {3, UPB_SIZE(8, 24), 3, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -7148,7 +7148,7 @@ UPB_INLINE const google_protobuf_EnumValueOptions* google_protobuf_EnumValueDesc } UPB_INLINE bool google_protobuf_EnumValueDescriptorProto_has_options(const google_protobuf_EnumValueDescriptorProto* msg) { const upb_MiniTableField field = {3, UPB_SIZE(8, 24), 3, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_EnumValueDescriptorProto_set_name(google_protobuf_EnumValueDescriptorProto *msg, upb_StringView value) { @@ -7222,7 +7222,7 @@ UPB_INLINE upb_StringView google_protobuf_ServiceDescriptorProto_name(const goog } UPB_INLINE bool google_protobuf_ServiceDescriptorProto_has_name(const google_protobuf_ServiceDescriptorProto* msg) { const upb_MiniTableField field = {1, UPB_SIZE(12, 8), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_ServiceDescriptorProto_clear_method(google_protobuf_ServiceDescriptorProto* msg) { const upb_MiniTableField field = {2, UPB_SIZE(4, 24), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -7270,7 +7270,7 @@ UPB_INLINE const google_protobuf_ServiceOptions* google_protobuf_ServiceDescript } UPB_INLINE bool google_protobuf_ServiceDescriptorProto_has_options(const google_protobuf_ServiceDescriptorProto* msg) { const upb_MiniTableField field = {3, UPB_SIZE(8, 32), 2, 1, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_ServiceDescriptorProto_set_name(google_protobuf_ServiceDescriptorProto *msg, upb_StringView value) { @@ -7370,7 +7370,7 @@ UPB_INLINE upb_StringView google_protobuf_MethodDescriptorProto_name(const googl } UPB_INLINE bool google_protobuf_MethodDescriptorProto_has_name(const google_protobuf_MethodDescriptorProto* msg) { const upb_MiniTableField field = {1, UPB_SIZE(12, 8), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_MethodDescriptorProto_clear_input_type(google_protobuf_MethodDescriptorProto* msg) { const upb_MiniTableField field = {2, UPB_SIZE(20, 24), 2, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; @@ -7386,7 +7386,7 @@ UPB_INLINE upb_StringView google_protobuf_MethodDescriptorProto_input_type(const } UPB_INLINE bool google_protobuf_MethodDescriptorProto_has_input_type(const google_protobuf_MethodDescriptorProto* msg) { const upb_MiniTableField field = {2, UPB_SIZE(20, 24), 2, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_MethodDescriptorProto_clear_output_type(google_protobuf_MethodDescriptorProto* msg) { const upb_MiniTableField field = {3, UPB_SIZE(28, 40), 3, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; @@ -7402,7 +7402,7 @@ UPB_INLINE upb_StringView google_protobuf_MethodDescriptorProto_output_type(cons } UPB_INLINE bool google_protobuf_MethodDescriptorProto_has_output_type(const google_protobuf_MethodDescriptorProto* msg) { const upb_MiniTableField field = {3, UPB_SIZE(28, 40), 3, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_MethodDescriptorProto_clear_options(google_protobuf_MethodDescriptorProto* msg) { const upb_MiniTableField field = {4, UPB_SIZE(4, 56), 4, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -7418,7 +7418,7 @@ UPB_INLINE const google_protobuf_MethodOptions* google_protobuf_MethodDescriptor } UPB_INLINE bool google_protobuf_MethodDescriptorProto_has_options(const google_protobuf_MethodDescriptorProto* msg) { const upb_MiniTableField field = {4, UPB_SIZE(4, 56), 4, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_MethodDescriptorProto_clear_client_streaming(google_protobuf_MethodDescriptorProto* msg) { const upb_MiniTableField field = {5, UPB_SIZE(8, 1), 5, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; @@ -7434,7 +7434,7 @@ UPB_INLINE bool google_protobuf_MethodDescriptorProto_client_streaming(const goo } UPB_INLINE bool google_protobuf_MethodDescriptorProto_has_client_streaming(const google_protobuf_MethodDescriptorProto* msg) { const upb_MiniTableField field = {5, UPB_SIZE(8, 1), 5, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_MethodDescriptorProto_clear_server_streaming(google_protobuf_MethodDescriptorProto* msg) { const upb_MiniTableField field = {6, UPB_SIZE(9, 2), 6, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; @@ -7450,7 +7450,7 @@ UPB_INLINE bool google_protobuf_MethodDescriptorProto_server_streaming(const goo } UPB_INLINE bool google_protobuf_MethodDescriptorProto_has_server_streaming(const google_protobuf_MethodDescriptorProto* msg) { const upb_MiniTableField field = {6, UPB_SIZE(9, 2), 6, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_MethodDescriptorProto_set_name(google_protobuf_MethodDescriptorProto *msg, upb_StringView value) { @@ -7536,7 +7536,7 @@ UPB_INLINE upb_StringView google_protobuf_FileOptions_java_package(const google_ } UPB_INLINE bool google_protobuf_FileOptions_has_java_package(const google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {1, UPB_SIZE(24, 16), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileOptions_clear_java_outer_classname(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {8, 32, 2, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; @@ -7552,7 +7552,7 @@ UPB_INLINE upb_StringView google_protobuf_FileOptions_java_outer_classname(const } UPB_INLINE bool google_protobuf_FileOptions_has_java_outer_classname(const google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {8, 32, 2, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileOptions_clear_optimize_for(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {9, 4, 3, 2, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; @@ -7568,7 +7568,7 @@ UPB_INLINE int32_t google_protobuf_FileOptions_optimize_for(const google_protobu } UPB_INLINE bool google_protobuf_FileOptions_has_optimize_for(const google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {9, 4, 3, 2, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileOptions_clear_java_multiple_files(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {10, 8, 4, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; @@ -7584,7 +7584,7 @@ UPB_INLINE bool google_protobuf_FileOptions_java_multiple_files(const google_pro } UPB_INLINE bool google_protobuf_FileOptions_has_java_multiple_files(const google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {10, 8, 4, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileOptions_clear_go_package(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {11, UPB_SIZE(40, 48), 5, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; @@ -7600,7 +7600,7 @@ UPB_INLINE upb_StringView google_protobuf_FileOptions_go_package(const google_pr } UPB_INLINE bool google_protobuf_FileOptions_has_go_package(const google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {11, UPB_SIZE(40, 48), 5, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileOptions_clear_cc_generic_services(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {16, 9, 6, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; @@ -7616,7 +7616,7 @@ UPB_INLINE bool google_protobuf_FileOptions_cc_generic_services(const google_pro } UPB_INLINE bool google_protobuf_FileOptions_has_cc_generic_services(const google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {16, 9, 6, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileOptions_clear_java_generic_services(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {17, 10, 7, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; @@ -7632,7 +7632,7 @@ UPB_INLINE bool google_protobuf_FileOptions_java_generic_services(const google_p } UPB_INLINE bool google_protobuf_FileOptions_has_java_generic_services(const google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {17, 10, 7, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileOptions_clear_py_generic_services(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {18, 11, 8, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; @@ -7648,7 +7648,7 @@ UPB_INLINE bool google_protobuf_FileOptions_py_generic_services(const google_pro } UPB_INLINE bool google_protobuf_FileOptions_has_py_generic_services(const google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {18, 11, 8, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileOptions_clear_java_generate_equals_and_hash(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {20, 12, 9, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; @@ -7664,7 +7664,7 @@ UPB_INLINE bool google_protobuf_FileOptions_java_generate_equals_and_hash(const } UPB_INLINE bool google_protobuf_FileOptions_has_java_generate_equals_and_hash(const google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {20, 12, 9, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileOptions_clear_deprecated(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {23, 13, 10, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; @@ -7680,7 +7680,7 @@ UPB_INLINE bool google_protobuf_FileOptions_deprecated(const google_protobuf_Fil } UPB_INLINE bool google_protobuf_FileOptions_has_deprecated(const google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {23, 13, 10, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileOptions_clear_java_string_check_utf8(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {27, 14, 11, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; @@ -7696,7 +7696,7 @@ UPB_INLINE bool google_protobuf_FileOptions_java_string_check_utf8(const google_ } UPB_INLINE bool google_protobuf_FileOptions_has_java_string_check_utf8(const google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {27, 14, 11, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileOptions_clear_cc_enable_arenas(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {31, 15, 12, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; @@ -7712,7 +7712,7 @@ UPB_INLINE bool google_protobuf_FileOptions_cc_enable_arenas(const google_protob } UPB_INLINE bool google_protobuf_FileOptions_has_cc_enable_arenas(const google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {31, 15, 12, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileOptions_clear_objc_class_prefix(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {36, UPB_SIZE(48, 64), 13, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; @@ -7728,7 +7728,7 @@ UPB_INLINE upb_StringView google_protobuf_FileOptions_objc_class_prefix(const go } UPB_INLINE bool google_protobuf_FileOptions_has_objc_class_prefix(const google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {36, UPB_SIZE(48, 64), 13, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileOptions_clear_csharp_namespace(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {37, UPB_SIZE(56, 80), 14, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; @@ -7744,7 +7744,7 @@ UPB_INLINE upb_StringView google_protobuf_FileOptions_csharp_namespace(const goo } UPB_INLINE bool google_protobuf_FileOptions_has_csharp_namespace(const google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {37, UPB_SIZE(56, 80), 14, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileOptions_clear_swift_prefix(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {39, UPB_SIZE(64, 96), 15, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; @@ -7760,7 +7760,7 @@ UPB_INLINE upb_StringView google_protobuf_FileOptions_swift_prefix(const google_ } UPB_INLINE bool google_protobuf_FileOptions_has_swift_prefix(const google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {39, UPB_SIZE(64, 96), 15, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileOptions_clear_php_class_prefix(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {40, UPB_SIZE(72, 112), 16, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; @@ -7776,7 +7776,7 @@ UPB_INLINE upb_StringView google_protobuf_FileOptions_php_class_prefix(const goo } UPB_INLINE bool google_protobuf_FileOptions_has_php_class_prefix(const google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {40, UPB_SIZE(72, 112), 16, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileOptions_clear_php_namespace(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {41, UPB_SIZE(80, 128), 17, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; @@ -7792,7 +7792,7 @@ UPB_INLINE upb_StringView google_protobuf_FileOptions_php_namespace(const google } UPB_INLINE bool google_protobuf_FileOptions_has_php_namespace(const google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {41, UPB_SIZE(80, 128), 17, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileOptions_clear_php_metadata_namespace(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {44, UPB_SIZE(88, 144), 18, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; @@ -7808,7 +7808,7 @@ UPB_INLINE upb_StringView google_protobuf_FileOptions_php_metadata_namespace(con } UPB_INLINE bool google_protobuf_FileOptions_has_php_metadata_namespace(const google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {44, UPB_SIZE(88, 144), 18, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileOptions_clear_ruby_package(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {45, UPB_SIZE(96, 160), 19, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; @@ -7824,7 +7824,7 @@ UPB_INLINE upb_StringView google_protobuf_FileOptions_ruby_package(const google_ } UPB_INLINE bool google_protobuf_FileOptions_has_ruby_package(const google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {45, UPB_SIZE(96, 160), 19, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileOptions_clear_features(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {50, UPB_SIZE(16, 176), 20, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -7840,7 +7840,7 @@ UPB_INLINE const google_protobuf_FeatureSet* google_protobuf_FileOptions_feature } UPB_INLINE bool google_protobuf_FileOptions_has_features(const google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {50, UPB_SIZE(16, 176), 20, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileOptions_clear_uninterpreted_option(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {999, UPB_SIZE(20, 184), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -8044,7 +8044,7 @@ UPB_INLINE bool google_protobuf_MessageOptions_message_set_wire_format(const goo } UPB_INLINE bool google_protobuf_MessageOptions_has_message_set_wire_format(const google_protobuf_MessageOptions* msg) { const upb_MiniTableField field = {1, 1, 1, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_MessageOptions_clear_no_standard_descriptor_accessor(google_protobuf_MessageOptions* msg) { const upb_MiniTableField field = {2, 2, 2, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; @@ -8060,7 +8060,7 @@ UPB_INLINE bool google_protobuf_MessageOptions_no_standard_descriptor_accessor(c } UPB_INLINE bool google_protobuf_MessageOptions_has_no_standard_descriptor_accessor(const google_protobuf_MessageOptions* msg) { const upb_MiniTableField field = {2, 2, 2, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_MessageOptions_clear_deprecated(google_protobuf_MessageOptions* msg) { const upb_MiniTableField field = {3, 3, 3, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; @@ -8076,7 +8076,7 @@ UPB_INLINE bool google_protobuf_MessageOptions_deprecated(const google_protobuf_ } UPB_INLINE bool google_protobuf_MessageOptions_has_deprecated(const google_protobuf_MessageOptions* msg) { const upb_MiniTableField field = {3, 3, 3, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_MessageOptions_clear_map_entry(google_protobuf_MessageOptions* msg) { const upb_MiniTableField field = {7, 4, 4, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; @@ -8092,7 +8092,7 @@ UPB_INLINE bool google_protobuf_MessageOptions_map_entry(const google_protobuf_M } UPB_INLINE bool google_protobuf_MessageOptions_has_map_entry(const google_protobuf_MessageOptions* msg) { const upb_MiniTableField field = {7, 4, 4, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_MessageOptions_clear_deprecated_legacy_json_field_conflicts(google_protobuf_MessageOptions* msg) { const upb_MiniTableField field = {11, 5, 5, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; @@ -8108,7 +8108,7 @@ UPB_INLINE bool google_protobuf_MessageOptions_deprecated_legacy_json_field_conf } UPB_INLINE bool google_protobuf_MessageOptions_has_deprecated_legacy_json_field_conflicts(const google_protobuf_MessageOptions* msg) { const upb_MiniTableField field = {11, 5, 5, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_MessageOptions_clear_features(google_protobuf_MessageOptions* msg) { const upb_MiniTableField field = {12, 8, 6, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -8124,7 +8124,7 @@ UPB_INLINE const google_protobuf_FeatureSet* google_protobuf_MessageOptions_feat } UPB_INLINE bool google_protobuf_MessageOptions_has_features(const google_protobuf_MessageOptions* msg) { const upb_MiniTableField field = {12, 8, 6, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_MessageOptions_clear_uninterpreted_option(google_protobuf_MessageOptions* msg) { const upb_MiniTableField field = {999, UPB_SIZE(12, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -8272,7 +8272,7 @@ UPB_INLINE int32_t google_protobuf_FieldOptions_ctype(const google_protobuf_Fiel } UPB_INLINE bool google_protobuf_FieldOptions_has_ctype(const google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {1, 4, 1, 3, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldOptions_clear_packed(google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {2, 8, 2, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; @@ -8288,7 +8288,7 @@ UPB_INLINE bool google_protobuf_FieldOptions_packed(const google_protobuf_FieldO } UPB_INLINE bool google_protobuf_FieldOptions_has_packed(const google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {2, 8, 2, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldOptions_clear_deprecated(google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {3, 9, 3, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; @@ -8304,7 +8304,7 @@ UPB_INLINE bool google_protobuf_FieldOptions_deprecated(const google_protobuf_Fi } UPB_INLINE bool google_protobuf_FieldOptions_has_deprecated(const google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {3, 9, 3, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldOptions_clear_lazy(google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {5, 10, 4, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; @@ -8320,7 +8320,7 @@ UPB_INLINE bool google_protobuf_FieldOptions_lazy(const google_protobuf_FieldOpt } UPB_INLINE bool google_protobuf_FieldOptions_has_lazy(const google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {5, 10, 4, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldOptions_clear_jstype(google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {6, 12, 5, 4, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; @@ -8336,7 +8336,7 @@ UPB_INLINE int32_t google_protobuf_FieldOptions_jstype(const google_protobuf_Fie } UPB_INLINE bool google_protobuf_FieldOptions_has_jstype(const google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {6, 12, 5, 4, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldOptions_clear_weak(google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {10, 16, 6, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; @@ -8352,7 +8352,7 @@ UPB_INLINE bool google_protobuf_FieldOptions_weak(const google_protobuf_FieldOpt } UPB_INLINE bool google_protobuf_FieldOptions_has_weak(const google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {10, 16, 6, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldOptions_clear_unverified_lazy(google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {15, 17, 7, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; @@ -8368,7 +8368,7 @@ UPB_INLINE bool google_protobuf_FieldOptions_unverified_lazy(const google_protob } UPB_INLINE bool google_protobuf_FieldOptions_has_unverified_lazy(const google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {15, 17, 7, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldOptions_clear_debug_redact(google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {16, 18, 8, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; @@ -8384,7 +8384,7 @@ UPB_INLINE bool google_protobuf_FieldOptions_debug_redact(const google_protobuf_ } UPB_INLINE bool google_protobuf_FieldOptions_has_debug_redact(const google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {16, 18, 8, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldOptions_clear_retention(google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {17, 20, 9, 5, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; @@ -8400,7 +8400,7 @@ UPB_INLINE int32_t google_protobuf_FieldOptions_retention(const google_protobuf_ } UPB_INLINE bool google_protobuf_FieldOptions_has_retention(const google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {17, 20, 9, 5, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldOptions_clear_targets(google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {19, 24, 0, 6, 14, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -8480,7 +8480,7 @@ UPB_INLINE const google_protobuf_FeatureSet* google_protobuf_FieldOptions_featur } UPB_INLINE bool google_protobuf_FieldOptions_has_features(const google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {21, UPB_SIZE(32, 40), 10, 1, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldOptions_clear_uninterpreted_option(google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {999, UPB_SIZE(36, 48), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -8702,7 +8702,7 @@ UPB_INLINE upb_StringView google_protobuf_FieldOptions_EditionDefault_value(cons } UPB_INLINE bool google_protobuf_FieldOptions_EditionDefault_has_value(const google_protobuf_FieldOptions_EditionDefault* msg) { const upb_MiniTableField field = {2, 8, 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldOptions_EditionDefault_clear_edition(google_protobuf_FieldOptions_EditionDefault* msg) { const upb_MiniTableField field = {3, 4, 2, 0, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; @@ -8718,7 +8718,7 @@ UPB_INLINE int32_t google_protobuf_FieldOptions_EditionDefault_edition(const goo } UPB_INLINE bool google_protobuf_FieldOptions_EditionDefault_has_edition(const google_protobuf_FieldOptions_EditionDefault* msg) { const upb_MiniTableField field = {3, 4, 2, 0, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldOptions_EditionDefault_set_value(google_protobuf_FieldOptions_EditionDefault *msg, upb_StringView value) { @@ -8780,7 +8780,7 @@ UPB_INLINE const google_protobuf_FeatureSet* google_protobuf_OneofOptions_featur } UPB_INLINE bool google_protobuf_OneofOptions_has_features(const google_protobuf_OneofOptions* msg) { const upb_MiniTableField field = {1, UPB_SIZE(4, 8), 1, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_OneofOptions_clear_uninterpreted_option(google_protobuf_OneofOptions* msg) { const upb_MiniTableField field = {999, UPB_SIZE(8, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -8908,7 +8908,7 @@ UPB_INLINE bool google_protobuf_EnumOptions_allow_alias(const google_protobuf_En } UPB_INLINE bool google_protobuf_EnumOptions_has_allow_alias(const google_protobuf_EnumOptions* msg) { const upb_MiniTableField field = {2, 1, 1, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_EnumOptions_clear_deprecated(google_protobuf_EnumOptions* msg) { const upb_MiniTableField field = {3, 2, 2, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; @@ -8924,7 +8924,7 @@ UPB_INLINE bool google_protobuf_EnumOptions_deprecated(const google_protobuf_Enu } UPB_INLINE bool google_protobuf_EnumOptions_has_deprecated(const google_protobuf_EnumOptions* msg) { const upb_MiniTableField field = {3, 2, 2, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_EnumOptions_clear_deprecated_legacy_json_field_conflicts(google_protobuf_EnumOptions* msg) { const upb_MiniTableField field = {6, 3, 3, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; @@ -8940,7 +8940,7 @@ UPB_INLINE bool google_protobuf_EnumOptions_deprecated_legacy_json_field_conflic } UPB_INLINE bool google_protobuf_EnumOptions_has_deprecated_legacy_json_field_conflicts(const google_protobuf_EnumOptions* msg) { const upb_MiniTableField field = {6, 3, 3, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_EnumOptions_clear_features(google_protobuf_EnumOptions* msg) { const upb_MiniTableField field = {7, UPB_SIZE(4, 8), 4, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -8956,7 +8956,7 @@ UPB_INLINE const google_protobuf_FeatureSet* google_protobuf_EnumOptions_feature } UPB_INLINE bool google_protobuf_EnumOptions_has_features(const google_protobuf_EnumOptions* msg) { const upb_MiniTableField field = {7, UPB_SIZE(4, 8), 4, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_EnumOptions_clear_uninterpreted_option(google_protobuf_EnumOptions* msg) { const upb_MiniTableField field = {999, UPB_SIZE(8, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -9096,7 +9096,7 @@ UPB_INLINE bool google_protobuf_EnumValueOptions_deprecated(const google_protobu } UPB_INLINE bool google_protobuf_EnumValueOptions_has_deprecated(const google_protobuf_EnumValueOptions* msg) { const upb_MiniTableField field = {1, 1, 1, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_EnumValueOptions_clear_features(google_protobuf_EnumValueOptions* msg) { const upb_MiniTableField field = {2, UPB_SIZE(4, 8), 2, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -9112,7 +9112,7 @@ UPB_INLINE const google_protobuf_FeatureSet* google_protobuf_EnumValueOptions_fe } UPB_INLINE bool google_protobuf_EnumValueOptions_has_features(const google_protobuf_EnumValueOptions* msg) { const upb_MiniTableField field = {2, UPB_SIZE(4, 8), 2, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_EnumValueOptions_clear_debug_redact(google_protobuf_EnumValueOptions* msg) { const upb_MiniTableField field = {3, UPB_SIZE(8, 2), 3, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; @@ -9128,7 +9128,7 @@ UPB_INLINE bool google_protobuf_EnumValueOptions_debug_redact(const google_proto } UPB_INLINE bool google_protobuf_EnumValueOptions_has_debug_redact(const google_protobuf_EnumValueOptions* msg) { const upb_MiniTableField field = {3, UPB_SIZE(8, 2), 3, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_EnumValueOptions_clear_uninterpreted_option(google_protobuf_EnumValueOptions* msg) { const upb_MiniTableField field = {999, UPB_SIZE(12, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -9264,7 +9264,7 @@ UPB_INLINE bool google_protobuf_ServiceOptions_deprecated(const google_protobuf_ } UPB_INLINE bool google_protobuf_ServiceOptions_has_deprecated(const google_protobuf_ServiceOptions* msg) { const upb_MiniTableField field = {33, 1, 1, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_ServiceOptions_clear_features(google_protobuf_ServiceOptions* msg) { const upb_MiniTableField field = {34, UPB_SIZE(4, 8), 2, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -9280,7 +9280,7 @@ UPB_INLINE const google_protobuf_FeatureSet* google_protobuf_ServiceOptions_feat } UPB_INLINE bool google_protobuf_ServiceOptions_has_features(const google_protobuf_ServiceOptions* msg) { const upb_MiniTableField field = {34, UPB_SIZE(4, 8), 2, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_ServiceOptions_clear_uninterpreted_option(google_protobuf_ServiceOptions* msg) { const upb_MiniTableField field = {999, UPB_SIZE(8, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -9412,7 +9412,7 @@ UPB_INLINE bool google_protobuf_MethodOptions_deprecated(const google_protobuf_M } UPB_INLINE bool google_protobuf_MethodOptions_has_deprecated(const google_protobuf_MethodOptions* msg) { const upb_MiniTableField field = {33, 1, 1, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_MethodOptions_clear_idempotency_level(google_protobuf_MethodOptions* msg) { const upb_MiniTableField field = {34, 4, 2, 2, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; @@ -9428,7 +9428,7 @@ UPB_INLINE int32_t google_protobuf_MethodOptions_idempotency_level(const google_ } UPB_INLINE bool google_protobuf_MethodOptions_has_idempotency_level(const google_protobuf_MethodOptions* msg) { const upb_MiniTableField field = {34, 4, 2, 2, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_MethodOptions_clear_features(google_protobuf_MethodOptions* msg) { const upb_MiniTableField field = {35, 8, 3, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -9444,7 +9444,7 @@ UPB_INLINE const google_protobuf_FeatureSet* google_protobuf_MethodOptions_featu } UPB_INLINE bool google_protobuf_MethodOptions_has_features(const google_protobuf_MethodOptions* msg) { const upb_MiniTableField field = {35, 8, 3, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_MethodOptions_clear_uninterpreted_option(google_protobuf_MethodOptions* msg) { const upb_MiniTableField field = {999, UPB_SIZE(12, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -9612,7 +9612,7 @@ UPB_INLINE upb_StringView google_protobuf_UninterpretedOption_identifier_value(c } UPB_INLINE bool google_protobuf_UninterpretedOption_has_identifier_value(const google_protobuf_UninterpretedOption* msg) { const upb_MiniTableField field = {3, UPB_SIZE(8, 16), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_UninterpretedOption_clear_positive_int_value(google_protobuf_UninterpretedOption* msg) { const upb_MiniTableField field = {4, UPB_SIZE(16, 32), 2, kUpb_NoSub, 4, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_8Byte << kUpb_FieldRep_Shift)}; @@ -9628,7 +9628,7 @@ UPB_INLINE uint64_t google_protobuf_UninterpretedOption_positive_int_value(const } UPB_INLINE bool google_protobuf_UninterpretedOption_has_positive_int_value(const google_protobuf_UninterpretedOption* msg) { const upb_MiniTableField field = {4, UPB_SIZE(16, 32), 2, kUpb_NoSub, 4, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_8Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_UninterpretedOption_clear_negative_int_value(google_protobuf_UninterpretedOption* msg) { const upb_MiniTableField field = {5, UPB_SIZE(24, 40), 3, kUpb_NoSub, 3, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_8Byte << kUpb_FieldRep_Shift)}; @@ -9644,7 +9644,7 @@ UPB_INLINE int64_t google_protobuf_UninterpretedOption_negative_int_value(const } UPB_INLINE bool google_protobuf_UninterpretedOption_has_negative_int_value(const google_protobuf_UninterpretedOption* msg) { const upb_MiniTableField field = {5, UPB_SIZE(24, 40), 3, kUpb_NoSub, 3, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_8Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_UninterpretedOption_clear_double_value(google_protobuf_UninterpretedOption* msg) { const upb_MiniTableField field = {6, UPB_SIZE(32, 48), 4, kUpb_NoSub, 1, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_8Byte << kUpb_FieldRep_Shift)}; @@ -9660,7 +9660,7 @@ UPB_INLINE double google_protobuf_UninterpretedOption_double_value(const google_ } UPB_INLINE bool google_protobuf_UninterpretedOption_has_double_value(const google_protobuf_UninterpretedOption* msg) { const upb_MiniTableField field = {6, UPB_SIZE(32, 48), 4, kUpb_NoSub, 1, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_8Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_UninterpretedOption_clear_string_value(google_protobuf_UninterpretedOption* msg) { const upb_MiniTableField field = {7, UPB_SIZE(40, 56), 5, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; @@ -9676,7 +9676,7 @@ UPB_INLINE upb_StringView google_protobuf_UninterpretedOption_string_value(const } UPB_INLINE bool google_protobuf_UninterpretedOption_has_string_value(const google_protobuf_UninterpretedOption* msg) { const upb_MiniTableField field = {7, UPB_SIZE(40, 56), 5, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_UninterpretedOption_clear_aggregate_value(google_protobuf_UninterpretedOption* msg) { const upb_MiniTableField field = {8, UPB_SIZE(48, 72), 6, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; @@ -9692,7 +9692,7 @@ UPB_INLINE upb_StringView google_protobuf_UninterpretedOption_aggregate_value(co } UPB_INLINE bool google_protobuf_UninterpretedOption_has_aggregate_value(const google_protobuf_UninterpretedOption* msg) { const upb_MiniTableField field = {8, UPB_SIZE(48, 72), 6, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE google_protobuf_UninterpretedOption_NamePart** google_protobuf_UninterpretedOption_mutable_name(google_protobuf_UninterpretedOption* msg, size_t* size) { @@ -9800,7 +9800,7 @@ UPB_INLINE upb_StringView google_protobuf_UninterpretedOption_NamePart_name_part } UPB_INLINE bool google_protobuf_UninterpretedOption_NamePart_has_name_part(const google_protobuf_UninterpretedOption_NamePart* msg) { const upb_MiniTableField field = {1, UPB_SIZE(4, 8), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_UninterpretedOption_NamePart_clear_is_extension(google_protobuf_UninterpretedOption_NamePart* msg) { const upb_MiniTableField field = {2, 1, 2, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; @@ -9816,7 +9816,7 @@ UPB_INLINE bool google_protobuf_UninterpretedOption_NamePart_is_extension(const } UPB_INLINE bool google_protobuf_UninterpretedOption_NamePart_has_is_extension(const google_protobuf_UninterpretedOption_NamePart* msg) { const upb_MiniTableField field = {2, 1, 2, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_UninterpretedOption_NamePart_set_name_part(google_protobuf_UninterpretedOption_NamePart *msg, upb_StringView value) { @@ -9878,7 +9878,7 @@ UPB_INLINE int32_t google_protobuf_FeatureSet_field_presence(const google_protob } UPB_INLINE bool google_protobuf_FeatureSet_has_field_presence(const google_protobuf_FeatureSet* msg) { const upb_MiniTableField field = {1, 4, 1, 0, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FeatureSet_clear_enum_type(google_protobuf_FeatureSet* msg) { const upb_MiniTableField field = {2, 8, 2, 1, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; @@ -9894,7 +9894,7 @@ UPB_INLINE int32_t google_protobuf_FeatureSet_enum_type(const google_protobuf_Fe } UPB_INLINE bool google_protobuf_FeatureSet_has_enum_type(const google_protobuf_FeatureSet* msg) { const upb_MiniTableField field = {2, 8, 2, 1, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FeatureSet_clear_repeated_field_encoding(google_protobuf_FeatureSet* msg) { const upb_MiniTableField field = {3, 12, 3, 2, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; @@ -9910,7 +9910,7 @@ UPB_INLINE int32_t google_protobuf_FeatureSet_repeated_field_encoding(const goog } UPB_INLINE bool google_protobuf_FeatureSet_has_repeated_field_encoding(const google_protobuf_FeatureSet* msg) { const upb_MiniTableField field = {3, 12, 3, 2, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FeatureSet_clear_utf8_validation(google_protobuf_FeatureSet* msg) { const upb_MiniTableField field = {4, 16, 4, 3, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; @@ -9926,7 +9926,7 @@ UPB_INLINE int32_t google_protobuf_FeatureSet_utf8_validation(const google_proto } UPB_INLINE bool google_protobuf_FeatureSet_has_utf8_validation(const google_protobuf_FeatureSet* msg) { const upb_MiniTableField field = {4, 16, 4, 3, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FeatureSet_clear_message_encoding(google_protobuf_FeatureSet* msg) { const upb_MiniTableField field = {5, 20, 5, 4, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; @@ -9942,7 +9942,7 @@ UPB_INLINE int32_t google_protobuf_FeatureSet_message_encoding(const google_prot } UPB_INLINE bool google_protobuf_FeatureSet_has_message_encoding(const google_protobuf_FeatureSet* msg) { const upb_MiniTableField field = {5, 20, 5, 4, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FeatureSet_clear_json_format(google_protobuf_FeatureSet* msg) { const upb_MiniTableField field = {6, 24, 6, 5, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; @@ -9958,7 +9958,7 @@ UPB_INLINE int32_t google_protobuf_FeatureSet_json_format(const google_protobuf_ } UPB_INLINE bool google_protobuf_FeatureSet_has_json_format(const google_protobuf_FeatureSet* msg) { const upb_MiniTableField field = {6, 24, 6, 5, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FeatureSet_set_field_presence(google_protobuf_FeatureSet *msg, int32_t value) { @@ -10068,7 +10068,7 @@ UPB_INLINE int32_t google_protobuf_FeatureSetDefaults_minimum_edition(const goog } UPB_INLINE bool google_protobuf_FeatureSetDefaults_has_minimum_edition(const google_protobuf_FeatureSetDefaults* msg) { const upb_MiniTableField field = {4, UPB_SIZE(8, 4), 1, 1, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FeatureSetDefaults_clear_maximum_edition(google_protobuf_FeatureSetDefaults* msg) { const upb_MiniTableField field = {5, UPB_SIZE(12, 8), 2, 2, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; @@ -10084,7 +10084,7 @@ UPB_INLINE int32_t google_protobuf_FeatureSetDefaults_maximum_edition(const goog } UPB_INLINE bool google_protobuf_FeatureSetDefaults_has_maximum_edition(const google_protobuf_FeatureSetDefaults* msg) { const upb_MiniTableField field = {5, UPB_SIZE(12, 8), 2, 2, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault** google_protobuf_FeatureSetDefaults_mutable_defaults(google_protobuf_FeatureSetDefaults* msg, size_t* size) { @@ -10176,7 +10176,7 @@ UPB_INLINE const google_protobuf_FeatureSet* google_protobuf_FeatureSetDefaults_ } UPB_INLINE bool google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_has_features(const google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* msg) { const upb_MiniTableField field = {2, UPB_SIZE(4, 8), 1, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_clear_edition(google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* msg) { const upb_MiniTableField field = {3, UPB_SIZE(8, 4), 2, 1, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; @@ -10192,7 +10192,7 @@ UPB_INLINE int32_t google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_e } UPB_INLINE bool google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_has_edition(const google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* msg) { const upb_MiniTableField field = {3, UPB_SIZE(8, 4), 2, 1, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_set_features(google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault *msg, google_protobuf_FeatureSet* value) { @@ -10426,7 +10426,7 @@ UPB_INLINE upb_StringView google_protobuf_SourceCodeInfo_Location_leading_commen } UPB_INLINE bool google_protobuf_SourceCodeInfo_Location_has_leading_comments(const google_protobuf_SourceCodeInfo_Location* msg) { const upb_MiniTableField field = {3, UPB_SIZE(16, 24), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_SourceCodeInfo_Location_clear_trailing_comments(google_protobuf_SourceCodeInfo_Location* msg) { const upb_MiniTableField field = {4, UPB_SIZE(24, 40), 2, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; @@ -10442,7 +10442,7 @@ UPB_INLINE upb_StringView google_protobuf_SourceCodeInfo_Location_trailing_comme } UPB_INLINE bool google_protobuf_SourceCodeInfo_Location_has_trailing_comments(const google_protobuf_SourceCodeInfo_Location* msg) { const upb_MiniTableField field = {4, UPB_SIZE(24, 40), 2, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_SourceCodeInfo_Location_clear_leading_detached_comments(google_protobuf_SourceCodeInfo_Location* msg) { const upb_MiniTableField field = {6, UPB_SIZE(12, 56), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -10752,7 +10752,7 @@ UPB_INLINE upb_StringView google_protobuf_GeneratedCodeInfo_Annotation_source_fi } UPB_INLINE bool google_protobuf_GeneratedCodeInfo_Annotation_has_source_file(const google_protobuf_GeneratedCodeInfo_Annotation* msg) { const upb_MiniTableField field = {2, UPB_SIZE(20, 24), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_GeneratedCodeInfo_Annotation_clear_begin(google_protobuf_GeneratedCodeInfo_Annotation* msg) { const upb_MiniTableField field = {3, UPB_SIZE(8, 4), 2, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; @@ -10768,7 +10768,7 @@ UPB_INLINE int32_t google_protobuf_GeneratedCodeInfo_Annotation_begin(const goog } UPB_INLINE bool google_protobuf_GeneratedCodeInfo_Annotation_has_begin(const google_protobuf_GeneratedCodeInfo_Annotation* msg) { const upb_MiniTableField field = {3, UPB_SIZE(8, 4), 2, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_GeneratedCodeInfo_Annotation_clear_end(google_protobuf_GeneratedCodeInfo_Annotation* msg) { const upb_MiniTableField field = {4, UPB_SIZE(12, 8), 3, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; @@ -10784,7 +10784,7 @@ UPB_INLINE int32_t google_protobuf_GeneratedCodeInfo_Annotation_end(const google } UPB_INLINE bool google_protobuf_GeneratedCodeInfo_Annotation_has_end(const google_protobuf_GeneratedCodeInfo_Annotation* msg) { const upb_MiniTableField field = {4, UPB_SIZE(12, 8), 3, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_GeneratedCodeInfo_Annotation_clear_semantic(google_protobuf_GeneratedCodeInfo_Annotation* msg) { const upb_MiniTableField field = {5, UPB_SIZE(16, 12), 4, 0, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; @@ -10800,7 +10800,7 @@ UPB_INLINE int32_t google_protobuf_GeneratedCodeInfo_Annotation_semantic(const g } UPB_INLINE bool google_protobuf_GeneratedCodeInfo_Annotation_has_semantic(const google_protobuf_GeneratedCodeInfo_Annotation* msg) { const upb_MiniTableField field = {5, UPB_SIZE(16, 12), 4, 0, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t* google_protobuf_GeneratedCodeInfo_Annotation_mutable_path(google_protobuf_GeneratedCodeInfo_Annotation* msg, size_t* size) { diff --git a/ruby/ext/google/protobuf_c/ruby-upb.c b/ruby/ext/google/protobuf_c/ruby-upb.c index a859cd521c0c4..237232d282f61 100644 --- a/ruby/ext/google/protobuf_c/ruby-upb.c +++ b/ruby/ext/google/protobuf_c/ruby-upb.c @@ -14060,8 +14060,14 @@ char* upb_strdup2(const char* s, size_t len, upb_Arena* a) { // Must be last. bool upb_Message_HasFieldByDef(const upb_Message* msg, const upb_FieldDef* f) { + const upb_MiniTableField* m_f = upb_FieldDef_MiniTable(f); UPB_ASSERT(upb_FieldDef_HasPresence(f)); - return upb_Message_HasField(msg, upb_FieldDef_MiniTable(f)); + + if (upb_MiniTableField_IsExtension(m_f)) { + return upb_Message_HasExtension(msg, (const upb_MiniTableExtension*)m_f); + } else { + return upb_Message_HasBaseField(msg, m_f); + } } const upb_FieldDef* upb_Message_WhichOneof(const upb_Message* msg, diff --git a/ruby/ext/google/protobuf_c/ruby-upb.h b/ruby/ext/google/protobuf_c/ruby-upb.h index f171f462cb45d..fb51f5f9b1083 100755 --- a/ruby/ext/google/protobuf_c/ruby-upb.h +++ b/ruby/ext/google/protobuf_c/ruby-upb.h @@ -2564,13 +2564,7 @@ UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_DataIsZero)( // of a setter is known to be a non-extension, the arena may be NULL and the // returned bool value may be ignored since it will always succeed. -UPB_INLINE bool _upb_Message_HasExtensionField( - const struct upb_Message* msg, const upb_MiniTableExtension* ext) { - UPB_ASSERT(upb_MiniTableField_HasPresence(&ext->UPB_PRIVATE(field))); - return _upb_Message_Getext(msg, ext) != NULL; -} - -UPB_INLINE bool _upb_Message_HasNonExtensionField( +UPB_INLINE bool UPB_PRIVATE(_upb_Message_HasBaseField)( const struct upb_Message* msg, const upb_MiniTableField* field) { UPB_ASSERT(upb_MiniTableField_HasPresence(field)); UPB_ASSUME(!upb_MiniTableField_IsExtension(field)); @@ -2582,13 +2576,19 @@ UPB_INLINE bool _upb_Message_HasNonExtensionField( } } +UPB_INLINE bool UPB_PRIVATE(_upb_Message_HasExtension)( + const struct upb_Message* msg, const upb_MiniTableExtension* ext) { + UPB_ASSERT(upb_MiniTableField_HasPresence(&ext->UPB_PRIVATE(field))); + return _upb_Message_Getext(msg, ext) != NULL; +} + static UPB_FORCEINLINE void _upb_Message_GetNonExtensionField( const struct upb_Message* msg, const upb_MiniTableField* field, const void* default_val, void* val) { UPB_ASSUME(!upb_MiniTableField_IsExtension(field)); if ((upb_MiniTableField_IsInOneof(field) || !UPB_PRIVATE(_upb_MiniTableField_DataIsZero)(field, default_val)) && - !_upb_Message_HasNonExtensionField(msg, field)) { + !UPB_PRIVATE(_upb_Message_HasBaseField)(msg, field)) { UPB_PRIVATE(_upb_MiniTableField_DataCopy)(field, val, default_val); return; } @@ -3104,14 +3104,14 @@ UPB_API_INLINE void upb_Message_ClearExtension( UPB_PRIVATE(_upb_Message_ClearExtension)(msg, e); } -UPB_API_INLINE bool upb_Message_HasField(const upb_Message* msg, - const upb_MiniTableField* field) { - if (upb_MiniTableField_IsExtension(field)) { - const upb_MiniTableExtension* ext = (const upb_MiniTableExtension*)field; - return _upb_Message_HasExtensionField(msg, ext); - } else { - return _upb_Message_HasNonExtensionField(msg, field); - } +UPB_API_INLINE bool upb_Message_HasBaseField(const upb_Message* msg, + const upb_MiniTableField* f) { + return UPB_PRIVATE(_upb_Message_HasBaseField)(msg, f); +} + +UPB_API_INLINE bool upb_Message_HasExtension(const upb_Message* msg, + const upb_MiniTableExtension* e) { + return UPB_PRIVATE(_upb_Message_HasExtension)(msg, e); } UPB_API_INLINE uint32_t upb_Message_WhichOneofFieldNumber( @@ -5104,7 +5104,7 @@ UPB_INLINE upb_StringView google_protobuf_FileDescriptorProto_name(const google_ } UPB_INLINE bool google_protobuf_FileDescriptorProto_has_name(const google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = {1, UPB_SIZE(44, 8), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileDescriptorProto_clear_package(google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = {2, UPB_SIZE(52, 24), 2, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; @@ -5120,7 +5120,7 @@ UPB_INLINE upb_StringView google_protobuf_FileDescriptorProto_package(const goog } UPB_INLINE bool google_protobuf_FileDescriptorProto_has_package(const google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = {2, UPB_SIZE(52, 24), 2, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileDescriptorProto_clear_dependency(google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = {3, UPB_SIZE(4, 40), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -5296,7 +5296,7 @@ UPB_INLINE const google_protobuf_FileOptions* google_protobuf_FileDescriptorProt } UPB_INLINE bool google_protobuf_FileDescriptorProto_has_options(const google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = {8, UPB_SIZE(24, 80), 3, 4, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileDescriptorProto_clear_source_code_info(google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = {9, UPB_SIZE(28, 88), 4, 5, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -5312,7 +5312,7 @@ UPB_INLINE const google_protobuf_SourceCodeInfo* google_protobuf_FileDescriptorP } UPB_INLINE bool google_protobuf_FileDescriptorProto_has_source_code_info(const google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = {9, UPB_SIZE(28, 88), 4, 5, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileDescriptorProto_clear_public_dependency(google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = {10, UPB_SIZE(32, 96), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -5392,7 +5392,7 @@ UPB_INLINE upb_StringView google_protobuf_FileDescriptorProto_syntax(const googl } UPB_INLINE bool google_protobuf_FileDescriptorProto_has_syntax(const google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = {12, UPB_SIZE(60, 112), 5, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileDescriptorProto_clear_edition(google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = {14, UPB_SIZE(40, 4), 6, 6, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; @@ -5408,7 +5408,7 @@ UPB_INLINE int32_t google_protobuf_FileDescriptorProto_edition(const google_prot } UPB_INLINE bool google_protobuf_FileDescriptorProto_has_edition(const google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = {14, UPB_SIZE(40, 4), 6, 6, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileDescriptorProto_set_name(google_protobuf_FileDescriptorProto *msg, upb_StringView value) { @@ -5706,7 +5706,7 @@ UPB_INLINE upb_StringView google_protobuf_DescriptorProto_name(const google_prot } UPB_INLINE bool google_protobuf_DescriptorProto_has_name(const google_protobuf_DescriptorProto* msg) { const upb_MiniTableField field = {1, UPB_SIZE(40, 8), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_DescriptorProto_clear_field(google_protobuf_DescriptorProto* msg) { const upb_MiniTableField field = {2, UPB_SIZE(4, 24), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -5882,7 +5882,7 @@ UPB_INLINE const google_protobuf_MessageOptions* google_protobuf_DescriptorProto } UPB_INLINE bool google_protobuf_DescriptorProto_has_options(const google_protobuf_DescriptorProto* msg) { const upb_MiniTableField field = {7, UPB_SIZE(24, 64), 2, 5, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_DescriptorProto_clear_oneof_decl(google_protobuf_DescriptorProto* msg) { const upb_MiniTableField field = {8, UPB_SIZE(28, 72), 0, 6, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -6286,7 +6286,7 @@ UPB_INLINE int32_t google_protobuf_DescriptorProto_ExtensionRange_start(const go } UPB_INLINE bool google_protobuf_DescriptorProto_ExtensionRange_has_start(const google_protobuf_DescriptorProto_ExtensionRange* msg) { const upb_MiniTableField field = {1, 4, 1, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_DescriptorProto_ExtensionRange_clear_end(google_protobuf_DescriptorProto_ExtensionRange* msg) { const upb_MiniTableField field = {2, 8, 2, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; @@ -6302,7 +6302,7 @@ UPB_INLINE int32_t google_protobuf_DescriptorProto_ExtensionRange_end(const goog } UPB_INLINE bool google_protobuf_DescriptorProto_ExtensionRange_has_end(const google_protobuf_DescriptorProto_ExtensionRange* msg) { const upb_MiniTableField field = {2, 8, 2, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_DescriptorProto_ExtensionRange_clear_options(google_protobuf_DescriptorProto_ExtensionRange* msg) { const upb_MiniTableField field = {3, UPB_SIZE(12, 16), 3, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -6318,7 +6318,7 @@ UPB_INLINE const google_protobuf_ExtensionRangeOptions* google_protobuf_Descript } UPB_INLINE bool google_protobuf_DescriptorProto_ExtensionRange_has_options(const google_protobuf_DescriptorProto_ExtensionRange* msg) { const upb_MiniTableField field = {3, UPB_SIZE(12, 16), 3, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_DescriptorProto_ExtensionRange_set_start(google_protobuf_DescriptorProto_ExtensionRange *msg, int32_t value) { @@ -6392,7 +6392,7 @@ UPB_INLINE int32_t google_protobuf_DescriptorProto_ReservedRange_start(const goo } UPB_INLINE bool google_protobuf_DescriptorProto_ReservedRange_has_start(const google_protobuf_DescriptorProto_ReservedRange* msg) { const upb_MiniTableField field = {1, 4, 1, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_DescriptorProto_ReservedRange_clear_end(google_protobuf_DescriptorProto_ReservedRange* msg) { const upb_MiniTableField field = {2, 8, 2, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; @@ -6408,7 +6408,7 @@ UPB_INLINE int32_t google_protobuf_DescriptorProto_ReservedRange_end(const googl } UPB_INLINE bool google_protobuf_DescriptorProto_ReservedRange_has_end(const google_protobuf_DescriptorProto_ReservedRange* msg) { const upb_MiniTableField field = {2, 8, 2, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_DescriptorProto_ReservedRange_set_start(google_protobuf_DescriptorProto_ReservedRange *msg, int32_t value) { @@ -6502,7 +6502,7 @@ UPB_INLINE int32_t google_protobuf_ExtensionRangeOptions_verification(const goog } UPB_INLINE bool google_protobuf_ExtensionRangeOptions_has_verification(const google_protobuf_ExtensionRangeOptions* msg) { const upb_MiniTableField field = {3, UPB_SIZE(8, 4), 1, 3, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_ExtensionRangeOptions_clear_features(google_protobuf_ExtensionRangeOptions* msg) { const upb_MiniTableField field = {50, UPB_SIZE(12, 16), 2, 1, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -6518,7 +6518,7 @@ UPB_INLINE const google_protobuf_FeatureSet* google_protobuf_ExtensionRangeOptio } UPB_INLINE bool google_protobuf_ExtensionRangeOptions_has_features(const google_protobuf_ExtensionRangeOptions* msg) { const upb_MiniTableField field = {50, UPB_SIZE(12, 16), 2, 1, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_ExtensionRangeOptions_clear_uninterpreted_option(google_protobuf_ExtensionRangeOptions* msg) { const upb_MiniTableField field = {999, UPB_SIZE(16, 24), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -6680,7 +6680,7 @@ UPB_INLINE int32_t google_protobuf_ExtensionRangeOptions_Declaration_number(cons } UPB_INLINE bool google_protobuf_ExtensionRangeOptions_Declaration_has_number(const google_protobuf_ExtensionRangeOptions_Declaration* msg) { const upb_MiniTableField field = {1, 4, 1, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_ExtensionRangeOptions_Declaration_clear_full_name(google_protobuf_ExtensionRangeOptions_Declaration* msg) { const upb_MiniTableField field = {2, UPB_SIZE(12, 16), 2, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; @@ -6696,7 +6696,7 @@ UPB_INLINE upb_StringView google_protobuf_ExtensionRangeOptions_Declaration_full } UPB_INLINE bool google_protobuf_ExtensionRangeOptions_Declaration_has_full_name(const google_protobuf_ExtensionRangeOptions_Declaration* msg) { const upb_MiniTableField field = {2, UPB_SIZE(12, 16), 2, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_ExtensionRangeOptions_Declaration_clear_type(google_protobuf_ExtensionRangeOptions_Declaration* msg) { const upb_MiniTableField field = {3, UPB_SIZE(20, 32), 3, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; @@ -6712,7 +6712,7 @@ UPB_INLINE upb_StringView google_protobuf_ExtensionRangeOptions_Declaration_type } UPB_INLINE bool google_protobuf_ExtensionRangeOptions_Declaration_has_type(const google_protobuf_ExtensionRangeOptions_Declaration* msg) { const upb_MiniTableField field = {3, UPB_SIZE(20, 32), 3, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_ExtensionRangeOptions_Declaration_clear_reserved(google_protobuf_ExtensionRangeOptions_Declaration* msg) { const upb_MiniTableField field = {5, 8, 4, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; @@ -6728,7 +6728,7 @@ UPB_INLINE bool google_protobuf_ExtensionRangeOptions_Declaration_reserved(const } UPB_INLINE bool google_protobuf_ExtensionRangeOptions_Declaration_has_reserved(const google_protobuf_ExtensionRangeOptions_Declaration* msg) { const upb_MiniTableField field = {5, 8, 4, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_ExtensionRangeOptions_Declaration_clear_repeated(google_protobuf_ExtensionRangeOptions_Declaration* msg) { const upb_MiniTableField field = {6, 9, 5, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; @@ -6744,7 +6744,7 @@ UPB_INLINE bool google_protobuf_ExtensionRangeOptions_Declaration_repeated(const } UPB_INLINE bool google_protobuf_ExtensionRangeOptions_Declaration_has_repeated(const google_protobuf_ExtensionRangeOptions_Declaration* msg) { const upb_MiniTableField field = {6, 9, 5, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_ExtensionRangeOptions_Declaration_set_number(google_protobuf_ExtensionRangeOptions_Declaration *msg, int32_t value) { @@ -6818,7 +6818,7 @@ UPB_INLINE upb_StringView google_protobuf_FieldDescriptorProto_name(const google } UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_name(const google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = {1, UPB_SIZE(28, 24), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldDescriptorProto_clear_extendee(google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = {2, UPB_SIZE(36, 40), 2, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; @@ -6834,7 +6834,7 @@ UPB_INLINE upb_StringView google_protobuf_FieldDescriptorProto_extendee(const go } UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_extendee(const google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = {2, UPB_SIZE(36, 40), 2, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldDescriptorProto_clear_number(google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = {3, 4, 3, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; @@ -6850,7 +6850,7 @@ UPB_INLINE int32_t google_protobuf_FieldDescriptorProto_number(const google_prot } UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_number(const google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = {3, 4, 3, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldDescriptorProto_clear_label(google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = {4, 8, 4, 1, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; @@ -6866,7 +6866,7 @@ UPB_INLINE int32_t google_protobuf_FieldDescriptorProto_label(const google_proto } UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_label(const google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = {4, 8, 4, 1, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldDescriptorProto_clear_type(google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = {5, 12, 5, 2, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; @@ -6882,7 +6882,7 @@ UPB_INLINE int32_t google_protobuf_FieldDescriptorProto_type(const google_protob } UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_type(const google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = {5, 12, 5, 2, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldDescriptorProto_clear_type_name(google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = {6, UPB_SIZE(44, 56), 6, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; @@ -6898,7 +6898,7 @@ UPB_INLINE upb_StringView google_protobuf_FieldDescriptorProto_type_name(const g } UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_type_name(const google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = {6, UPB_SIZE(44, 56), 6, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldDescriptorProto_clear_default_value(google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = {7, UPB_SIZE(52, 72), 7, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; @@ -6914,7 +6914,7 @@ UPB_INLINE upb_StringView google_protobuf_FieldDescriptorProto_default_value(con } UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_default_value(const google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = {7, UPB_SIZE(52, 72), 7, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldDescriptorProto_clear_options(google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = {8, UPB_SIZE(16, 88), 8, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -6930,7 +6930,7 @@ UPB_INLINE const google_protobuf_FieldOptions* google_protobuf_FieldDescriptorPr } UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_options(const google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = {8, UPB_SIZE(16, 88), 8, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldDescriptorProto_clear_oneof_index(google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = {9, UPB_SIZE(20, 16), 9, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; @@ -6946,7 +6946,7 @@ UPB_INLINE int32_t google_protobuf_FieldDescriptorProto_oneof_index(const google } UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_oneof_index(const google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = {9, UPB_SIZE(20, 16), 9, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldDescriptorProto_clear_json_name(google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = {10, UPB_SIZE(60, 96), 10, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; @@ -6962,7 +6962,7 @@ UPB_INLINE upb_StringView google_protobuf_FieldDescriptorProto_json_name(const g } UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_json_name(const google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = {10, UPB_SIZE(60, 96), 10, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldDescriptorProto_clear_proto3_optional(google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = {17, UPB_SIZE(24, 20), 11, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; @@ -6978,7 +6978,7 @@ UPB_INLINE bool google_protobuf_FieldDescriptorProto_proto3_optional(const googl } UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_proto3_optional(const google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = {17, UPB_SIZE(24, 20), 11, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldDescriptorProto_set_name(google_protobuf_FieldDescriptorProto *msg, upb_StringView value) { @@ -7084,7 +7084,7 @@ UPB_INLINE upb_StringView google_protobuf_OneofDescriptorProto_name(const google } UPB_INLINE bool google_protobuf_OneofDescriptorProto_has_name(const google_protobuf_OneofDescriptorProto* msg) { const upb_MiniTableField field = {1, 8, 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_OneofDescriptorProto_clear_options(google_protobuf_OneofDescriptorProto* msg) { const upb_MiniTableField field = {2, UPB_SIZE(4, 24), 2, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -7100,7 +7100,7 @@ UPB_INLINE const google_protobuf_OneofOptions* google_protobuf_OneofDescriptorPr } UPB_INLINE bool google_protobuf_OneofDescriptorProto_has_options(const google_protobuf_OneofDescriptorProto* msg) { const upb_MiniTableField field = {2, UPB_SIZE(4, 24), 2, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_OneofDescriptorProto_set_name(google_protobuf_OneofDescriptorProto *msg, upb_StringView value) { @@ -7170,7 +7170,7 @@ UPB_INLINE upb_StringView google_protobuf_EnumDescriptorProto_name(const google_ } UPB_INLINE bool google_protobuf_EnumDescriptorProto_has_name(const google_protobuf_EnumDescriptorProto* msg) { const upb_MiniTableField field = {1, UPB_SIZE(20, 8), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_EnumDescriptorProto_clear_value(google_protobuf_EnumDescriptorProto* msg) { const upb_MiniTableField field = {2, UPB_SIZE(4, 24), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -7218,7 +7218,7 @@ UPB_INLINE const google_protobuf_EnumOptions* google_protobuf_EnumDescriptorProt } UPB_INLINE bool google_protobuf_EnumDescriptorProto_has_options(const google_protobuf_EnumDescriptorProto* msg) { const upb_MiniTableField field = {3, UPB_SIZE(8, 32), 2, 1, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_EnumDescriptorProto_clear_reserved_range(google_protobuf_EnumDescriptorProto* msg) { const upb_MiniTableField field = {4, UPB_SIZE(12, 40), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -7440,7 +7440,7 @@ UPB_INLINE int32_t google_protobuf_EnumDescriptorProto_EnumReservedRange_start(c } UPB_INLINE bool google_protobuf_EnumDescriptorProto_EnumReservedRange_has_start(const google_protobuf_EnumDescriptorProto_EnumReservedRange* msg) { const upb_MiniTableField field = {1, 4, 1, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_EnumDescriptorProto_EnumReservedRange_clear_end(google_protobuf_EnumDescriptorProto_EnumReservedRange* msg) { const upb_MiniTableField field = {2, 8, 2, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; @@ -7456,7 +7456,7 @@ UPB_INLINE int32_t google_protobuf_EnumDescriptorProto_EnumReservedRange_end(con } UPB_INLINE bool google_protobuf_EnumDescriptorProto_EnumReservedRange_has_end(const google_protobuf_EnumDescriptorProto_EnumReservedRange* msg) { const upb_MiniTableField field = {2, 8, 2, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_EnumDescriptorProto_EnumReservedRange_set_start(google_protobuf_EnumDescriptorProto_EnumReservedRange *msg, int32_t value) { @@ -7518,7 +7518,7 @@ UPB_INLINE upb_StringView google_protobuf_EnumValueDescriptorProto_name(const go } UPB_INLINE bool google_protobuf_EnumValueDescriptorProto_has_name(const google_protobuf_EnumValueDescriptorProto* msg) { const upb_MiniTableField field = {1, UPB_SIZE(12, 8), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_EnumValueDescriptorProto_clear_number(google_protobuf_EnumValueDescriptorProto* msg) { const upb_MiniTableField field = {2, 4, 2, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; @@ -7534,7 +7534,7 @@ UPB_INLINE int32_t google_protobuf_EnumValueDescriptorProto_number(const google_ } UPB_INLINE bool google_protobuf_EnumValueDescriptorProto_has_number(const google_protobuf_EnumValueDescriptorProto* msg) { const upb_MiniTableField field = {2, 4, 2, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_EnumValueDescriptorProto_clear_options(google_protobuf_EnumValueDescriptorProto* msg) { const upb_MiniTableField field = {3, UPB_SIZE(8, 24), 3, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -7550,7 +7550,7 @@ UPB_INLINE const google_protobuf_EnumValueOptions* google_protobuf_EnumValueDesc } UPB_INLINE bool google_protobuf_EnumValueDescriptorProto_has_options(const google_protobuf_EnumValueDescriptorProto* msg) { const upb_MiniTableField field = {3, UPB_SIZE(8, 24), 3, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_EnumValueDescriptorProto_set_name(google_protobuf_EnumValueDescriptorProto *msg, upb_StringView value) { @@ -7624,7 +7624,7 @@ UPB_INLINE upb_StringView google_protobuf_ServiceDescriptorProto_name(const goog } UPB_INLINE bool google_protobuf_ServiceDescriptorProto_has_name(const google_protobuf_ServiceDescriptorProto* msg) { const upb_MiniTableField field = {1, UPB_SIZE(12, 8), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_ServiceDescriptorProto_clear_method(google_protobuf_ServiceDescriptorProto* msg) { const upb_MiniTableField field = {2, UPB_SIZE(4, 24), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -7672,7 +7672,7 @@ UPB_INLINE const google_protobuf_ServiceOptions* google_protobuf_ServiceDescript } UPB_INLINE bool google_protobuf_ServiceDescriptorProto_has_options(const google_protobuf_ServiceDescriptorProto* msg) { const upb_MiniTableField field = {3, UPB_SIZE(8, 32), 2, 1, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_ServiceDescriptorProto_set_name(google_protobuf_ServiceDescriptorProto *msg, upb_StringView value) { @@ -7772,7 +7772,7 @@ UPB_INLINE upb_StringView google_protobuf_MethodDescriptorProto_name(const googl } UPB_INLINE bool google_protobuf_MethodDescriptorProto_has_name(const google_protobuf_MethodDescriptorProto* msg) { const upb_MiniTableField field = {1, UPB_SIZE(12, 8), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_MethodDescriptorProto_clear_input_type(google_protobuf_MethodDescriptorProto* msg) { const upb_MiniTableField field = {2, UPB_SIZE(20, 24), 2, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; @@ -7788,7 +7788,7 @@ UPB_INLINE upb_StringView google_protobuf_MethodDescriptorProto_input_type(const } UPB_INLINE bool google_protobuf_MethodDescriptorProto_has_input_type(const google_protobuf_MethodDescriptorProto* msg) { const upb_MiniTableField field = {2, UPB_SIZE(20, 24), 2, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_MethodDescriptorProto_clear_output_type(google_protobuf_MethodDescriptorProto* msg) { const upb_MiniTableField field = {3, UPB_SIZE(28, 40), 3, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; @@ -7804,7 +7804,7 @@ UPB_INLINE upb_StringView google_protobuf_MethodDescriptorProto_output_type(cons } UPB_INLINE bool google_protobuf_MethodDescriptorProto_has_output_type(const google_protobuf_MethodDescriptorProto* msg) { const upb_MiniTableField field = {3, UPB_SIZE(28, 40), 3, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_MethodDescriptorProto_clear_options(google_protobuf_MethodDescriptorProto* msg) { const upb_MiniTableField field = {4, UPB_SIZE(4, 56), 4, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -7820,7 +7820,7 @@ UPB_INLINE const google_protobuf_MethodOptions* google_protobuf_MethodDescriptor } UPB_INLINE bool google_protobuf_MethodDescriptorProto_has_options(const google_protobuf_MethodDescriptorProto* msg) { const upb_MiniTableField field = {4, UPB_SIZE(4, 56), 4, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_MethodDescriptorProto_clear_client_streaming(google_protobuf_MethodDescriptorProto* msg) { const upb_MiniTableField field = {5, UPB_SIZE(8, 1), 5, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; @@ -7836,7 +7836,7 @@ UPB_INLINE bool google_protobuf_MethodDescriptorProto_client_streaming(const goo } UPB_INLINE bool google_protobuf_MethodDescriptorProto_has_client_streaming(const google_protobuf_MethodDescriptorProto* msg) { const upb_MiniTableField field = {5, UPB_SIZE(8, 1), 5, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_MethodDescriptorProto_clear_server_streaming(google_protobuf_MethodDescriptorProto* msg) { const upb_MiniTableField field = {6, UPB_SIZE(9, 2), 6, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; @@ -7852,7 +7852,7 @@ UPB_INLINE bool google_protobuf_MethodDescriptorProto_server_streaming(const goo } UPB_INLINE bool google_protobuf_MethodDescriptorProto_has_server_streaming(const google_protobuf_MethodDescriptorProto* msg) { const upb_MiniTableField field = {6, UPB_SIZE(9, 2), 6, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_MethodDescriptorProto_set_name(google_protobuf_MethodDescriptorProto *msg, upb_StringView value) { @@ -7938,7 +7938,7 @@ UPB_INLINE upb_StringView google_protobuf_FileOptions_java_package(const google_ } UPB_INLINE bool google_protobuf_FileOptions_has_java_package(const google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {1, UPB_SIZE(24, 16), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileOptions_clear_java_outer_classname(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {8, 32, 2, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; @@ -7954,7 +7954,7 @@ UPB_INLINE upb_StringView google_protobuf_FileOptions_java_outer_classname(const } UPB_INLINE bool google_protobuf_FileOptions_has_java_outer_classname(const google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {8, 32, 2, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileOptions_clear_optimize_for(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {9, 4, 3, 2, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; @@ -7970,7 +7970,7 @@ UPB_INLINE int32_t google_protobuf_FileOptions_optimize_for(const google_protobu } UPB_INLINE bool google_protobuf_FileOptions_has_optimize_for(const google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {9, 4, 3, 2, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileOptions_clear_java_multiple_files(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {10, 8, 4, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; @@ -7986,7 +7986,7 @@ UPB_INLINE bool google_protobuf_FileOptions_java_multiple_files(const google_pro } UPB_INLINE bool google_protobuf_FileOptions_has_java_multiple_files(const google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {10, 8, 4, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileOptions_clear_go_package(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {11, UPB_SIZE(40, 48), 5, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; @@ -8002,7 +8002,7 @@ UPB_INLINE upb_StringView google_protobuf_FileOptions_go_package(const google_pr } UPB_INLINE bool google_protobuf_FileOptions_has_go_package(const google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {11, UPB_SIZE(40, 48), 5, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileOptions_clear_cc_generic_services(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {16, 9, 6, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; @@ -8018,7 +8018,7 @@ UPB_INLINE bool google_protobuf_FileOptions_cc_generic_services(const google_pro } UPB_INLINE bool google_protobuf_FileOptions_has_cc_generic_services(const google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {16, 9, 6, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileOptions_clear_java_generic_services(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {17, 10, 7, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; @@ -8034,7 +8034,7 @@ UPB_INLINE bool google_protobuf_FileOptions_java_generic_services(const google_p } UPB_INLINE bool google_protobuf_FileOptions_has_java_generic_services(const google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {17, 10, 7, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileOptions_clear_py_generic_services(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {18, 11, 8, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; @@ -8050,7 +8050,7 @@ UPB_INLINE bool google_protobuf_FileOptions_py_generic_services(const google_pro } UPB_INLINE bool google_protobuf_FileOptions_has_py_generic_services(const google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {18, 11, 8, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileOptions_clear_java_generate_equals_and_hash(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {20, 12, 9, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; @@ -8066,7 +8066,7 @@ UPB_INLINE bool google_protobuf_FileOptions_java_generate_equals_and_hash(const } UPB_INLINE bool google_protobuf_FileOptions_has_java_generate_equals_and_hash(const google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {20, 12, 9, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileOptions_clear_deprecated(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {23, 13, 10, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; @@ -8082,7 +8082,7 @@ UPB_INLINE bool google_protobuf_FileOptions_deprecated(const google_protobuf_Fil } UPB_INLINE bool google_protobuf_FileOptions_has_deprecated(const google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {23, 13, 10, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileOptions_clear_java_string_check_utf8(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {27, 14, 11, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; @@ -8098,7 +8098,7 @@ UPB_INLINE bool google_protobuf_FileOptions_java_string_check_utf8(const google_ } UPB_INLINE bool google_protobuf_FileOptions_has_java_string_check_utf8(const google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {27, 14, 11, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileOptions_clear_cc_enable_arenas(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {31, 15, 12, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; @@ -8114,7 +8114,7 @@ UPB_INLINE bool google_protobuf_FileOptions_cc_enable_arenas(const google_protob } UPB_INLINE bool google_protobuf_FileOptions_has_cc_enable_arenas(const google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {31, 15, 12, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileOptions_clear_objc_class_prefix(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {36, UPB_SIZE(48, 64), 13, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; @@ -8130,7 +8130,7 @@ UPB_INLINE upb_StringView google_protobuf_FileOptions_objc_class_prefix(const go } UPB_INLINE bool google_protobuf_FileOptions_has_objc_class_prefix(const google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {36, UPB_SIZE(48, 64), 13, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileOptions_clear_csharp_namespace(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {37, UPB_SIZE(56, 80), 14, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; @@ -8146,7 +8146,7 @@ UPB_INLINE upb_StringView google_protobuf_FileOptions_csharp_namespace(const goo } UPB_INLINE bool google_protobuf_FileOptions_has_csharp_namespace(const google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {37, UPB_SIZE(56, 80), 14, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileOptions_clear_swift_prefix(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {39, UPB_SIZE(64, 96), 15, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; @@ -8162,7 +8162,7 @@ UPB_INLINE upb_StringView google_protobuf_FileOptions_swift_prefix(const google_ } UPB_INLINE bool google_protobuf_FileOptions_has_swift_prefix(const google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {39, UPB_SIZE(64, 96), 15, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileOptions_clear_php_class_prefix(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {40, UPB_SIZE(72, 112), 16, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; @@ -8178,7 +8178,7 @@ UPB_INLINE upb_StringView google_protobuf_FileOptions_php_class_prefix(const goo } UPB_INLINE bool google_protobuf_FileOptions_has_php_class_prefix(const google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {40, UPB_SIZE(72, 112), 16, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileOptions_clear_php_namespace(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {41, UPB_SIZE(80, 128), 17, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; @@ -8194,7 +8194,7 @@ UPB_INLINE upb_StringView google_protobuf_FileOptions_php_namespace(const google } UPB_INLINE bool google_protobuf_FileOptions_has_php_namespace(const google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {41, UPB_SIZE(80, 128), 17, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileOptions_clear_php_metadata_namespace(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {44, UPB_SIZE(88, 144), 18, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; @@ -8210,7 +8210,7 @@ UPB_INLINE upb_StringView google_protobuf_FileOptions_php_metadata_namespace(con } UPB_INLINE bool google_protobuf_FileOptions_has_php_metadata_namespace(const google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {44, UPB_SIZE(88, 144), 18, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileOptions_clear_ruby_package(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {45, UPB_SIZE(96, 160), 19, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; @@ -8226,7 +8226,7 @@ UPB_INLINE upb_StringView google_protobuf_FileOptions_ruby_package(const google_ } UPB_INLINE bool google_protobuf_FileOptions_has_ruby_package(const google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {45, UPB_SIZE(96, 160), 19, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileOptions_clear_features(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {50, UPB_SIZE(16, 176), 20, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -8242,7 +8242,7 @@ UPB_INLINE const google_protobuf_FeatureSet* google_protobuf_FileOptions_feature } UPB_INLINE bool google_protobuf_FileOptions_has_features(const google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {50, UPB_SIZE(16, 176), 20, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileOptions_clear_uninterpreted_option(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {999, UPB_SIZE(20, 184), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -8446,7 +8446,7 @@ UPB_INLINE bool google_protobuf_MessageOptions_message_set_wire_format(const goo } UPB_INLINE bool google_protobuf_MessageOptions_has_message_set_wire_format(const google_protobuf_MessageOptions* msg) { const upb_MiniTableField field = {1, 1, 1, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_MessageOptions_clear_no_standard_descriptor_accessor(google_protobuf_MessageOptions* msg) { const upb_MiniTableField field = {2, 2, 2, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; @@ -8462,7 +8462,7 @@ UPB_INLINE bool google_protobuf_MessageOptions_no_standard_descriptor_accessor(c } UPB_INLINE bool google_protobuf_MessageOptions_has_no_standard_descriptor_accessor(const google_protobuf_MessageOptions* msg) { const upb_MiniTableField field = {2, 2, 2, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_MessageOptions_clear_deprecated(google_protobuf_MessageOptions* msg) { const upb_MiniTableField field = {3, 3, 3, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; @@ -8478,7 +8478,7 @@ UPB_INLINE bool google_protobuf_MessageOptions_deprecated(const google_protobuf_ } UPB_INLINE bool google_protobuf_MessageOptions_has_deprecated(const google_protobuf_MessageOptions* msg) { const upb_MiniTableField field = {3, 3, 3, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_MessageOptions_clear_map_entry(google_protobuf_MessageOptions* msg) { const upb_MiniTableField field = {7, 4, 4, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; @@ -8494,7 +8494,7 @@ UPB_INLINE bool google_protobuf_MessageOptions_map_entry(const google_protobuf_M } UPB_INLINE bool google_protobuf_MessageOptions_has_map_entry(const google_protobuf_MessageOptions* msg) { const upb_MiniTableField field = {7, 4, 4, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_MessageOptions_clear_deprecated_legacy_json_field_conflicts(google_protobuf_MessageOptions* msg) { const upb_MiniTableField field = {11, 5, 5, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; @@ -8510,7 +8510,7 @@ UPB_INLINE bool google_protobuf_MessageOptions_deprecated_legacy_json_field_conf } UPB_INLINE bool google_protobuf_MessageOptions_has_deprecated_legacy_json_field_conflicts(const google_protobuf_MessageOptions* msg) { const upb_MiniTableField field = {11, 5, 5, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_MessageOptions_clear_features(google_protobuf_MessageOptions* msg) { const upb_MiniTableField field = {12, 8, 6, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -8526,7 +8526,7 @@ UPB_INLINE const google_protobuf_FeatureSet* google_protobuf_MessageOptions_feat } UPB_INLINE bool google_protobuf_MessageOptions_has_features(const google_protobuf_MessageOptions* msg) { const upb_MiniTableField field = {12, 8, 6, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_MessageOptions_clear_uninterpreted_option(google_protobuf_MessageOptions* msg) { const upb_MiniTableField field = {999, UPB_SIZE(12, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -8674,7 +8674,7 @@ UPB_INLINE int32_t google_protobuf_FieldOptions_ctype(const google_protobuf_Fiel } UPB_INLINE bool google_protobuf_FieldOptions_has_ctype(const google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {1, 4, 1, 3, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldOptions_clear_packed(google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {2, 8, 2, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; @@ -8690,7 +8690,7 @@ UPB_INLINE bool google_protobuf_FieldOptions_packed(const google_protobuf_FieldO } UPB_INLINE bool google_protobuf_FieldOptions_has_packed(const google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {2, 8, 2, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldOptions_clear_deprecated(google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {3, 9, 3, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; @@ -8706,7 +8706,7 @@ UPB_INLINE bool google_protobuf_FieldOptions_deprecated(const google_protobuf_Fi } UPB_INLINE bool google_protobuf_FieldOptions_has_deprecated(const google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {3, 9, 3, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldOptions_clear_lazy(google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {5, 10, 4, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; @@ -8722,7 +8722,7 @@ UPB_INLINE bool google_protobuf_FieldOptions_lazy(const google_protobuf_FieldOpt } UPB_INLINE bool google_protobuf_FieldOptions_has_lazy(const google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {5, 10, 4, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldOptions_clear_jstype(google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {6, 12, 5, 4, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; @@ -8738,7 +8738,7 @@ UPB_INLINE int32_t google_protobuf_FieldOptions_jstype(const google_protobuf_Fie } UPB_INLINE bool google_protobuf_FieldOptions_has_jstype(const google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {6, 12, 5, 4, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldOptions_clear_weak(google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {10, 16, 6, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; @@ -8754,7 +8754,7 @@ UPB_INLINE bool google_protobuf_FieldOptions_weak(const google_protobuf_FieldOpt } UPB_INLINE bool google_protobuf_FieldOptions_has_weak(const google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {10, 16, 6, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldOptions_clear_unverified_lazy(google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {15, 17, 7, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; @@ -8770,7 +8770,7 @@ UPB_INLINE bool google_protobuf_FieldOptions_unverified_lazy(const google_protob } UPB_INLINE bool google_protobuf_FieldOptions_has_unverified_lazy(const google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {15, 17, 7, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldOptions_clear_debug_redact(google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {16, 18, 8, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; @@ -8786,7 +8786,7 @@ UPB_INLINE bool google_protobuf_FieldOptions_debug_redact(const google_protobuf_ } UPB_INLINE bool google_protobuf_FieldOptions_has_debug_redact(const google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {16, 18, 8, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldOptions_clear_retention(google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {17, 20, 9, 5, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; @@ -8802,7 +8802,7 @@ UPB_INLINE int32_t google_protobuf_FieldOptions_retention(const google_protobuf_ } UPB_INLINE bool google_protobuf_FieldOptions_has_retention(const google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {17, 20, 9, 5, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldOptions_clear_targets(google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {19, 24, 0, 6, 14, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -8882,7 +8882,7 @@ UPB_INLINE const google_protobuf_FeatureSet* google_protobuf_FieldOptions_featur } UPB_INLINE bool google_protobuf_FieldOptions_has_features(const google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {21, UPB_SIZE(32, 40), 10, 1, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldOptions_clear_uninterpreted_option(google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {999, UPB_SIZE(36, 48), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -9104,7 +9104,7 @@ UPB_INLINE upb_StringView google_protobuf_FieldOptions_EditionDefault_value(cons } UPB_INLINE bool google_protobuf_FieldOptions_EditionDefault_has_value(const google_protobuf_FieldOptions_EditionDefault* msg) { const upb_MiniTableField field = {2, 8, 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldOptions_EditionDefault_clear_edition(google_protobuf_FieldOptions_EditionDefault* msg) { const upb_MiniTableField field = {3, 4, 2, 0, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; @@ -9120,7 +9120,7 @@ UPB_INLINE int32_t google_protobuf_FieldOptions_EditionDefault_edition(const goo } UPB_INLINE bool google_protobuf_FieldOptions_EditionDefault_has_edition(const google_protobuf_FieldOptions_EditionDefault* msg) { const upb_MiniTableField field = {3, 4, 2, 0, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldOptions_EditionDefault_set_value(google_protobuf_FieldOptions_EditionDefault *msg, upb_StringView value) { @@ -9182,7 +9182,7 @@ UPB_INLINE const google_protobuf_FeatureSet* google_protobuf_OneofOptions_featur } UPB_INLINE bool google_protobuf_OneofOptions_has_features(const google_protobuf_OneofOptions* msg) { const upb_MiniTableField field = {1, UPB_SIZE(4, 8), 1, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_OneofOptions_clear_uninterpreted_option(google_protobuf_OneofOptions* msg) { const upb_MiniTableField field = {999, UPB_SIZE(8, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -9310,7 +9310,7 @@ UPB_INLINE bool google_protobuf_EnumOptions_allow_alias(const google_protobuf_En } UPB_INLINE bool google_protobuf_EnumOptions_has_allow_alias(const google_protobuf_EnumOptions* msg) { const upb_MiniTableField field = {2, 1, 1, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_EnumOptions_clear_deprecated(google_protobuf_EnumOptions* msg) { const upb_MiniTableField field = {3, 2, 2, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; @@ -9326,7 +9326,7 @@ UPB_INLINE bool google_protobuf_EnumOptions_deprecated(const google_protobuf_Enu } UPB_INLINE bool google_protobuf_EnumOptions_has_deprecated(const google_protobuf_EnumOptions* msg) { const upb_MiniTableField field = {3, 2, 2, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_EnumOptions_clear_deprecated_legacy_json_field_conflicts(google_protobuf_EnumOptions* msg) { const upb_MiniTableField field = {6, 3, 3, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; @@ -9342,7 +9342,7 @@ UPB_INLINE bool google_protobuf_EnumOptions_deprecated_legacy_json_field_conflic } UPB_INLINE bool google_protobuf_EnumOptions_has_deprecated_legacy_json_field_conflicts(const google_protobuf_EnumOptions* msg) { const upb_MiniTableField field = {6, 3, 3, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_EnumOptions_clear_features(google_protobuf_EnumOptions* msg) { const upb_MiniTableField field = {7, UPB_SIZE(4, 8), 4, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -9358,7 +9358,7 @@ UPB_INLINE const google_protobuf_FeatureSet* google_protobuf_EnumOptions_feature } UPB_INLINE bool google_protobuf_EnumOptions_has_features(const google_protobuf_EnumOptions* msg) { const upb_MiniTableField field = {7, UPB_SIZE(4, 8), 4, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_EnumOptions_clear_uninterpreted_option(google_protobuf_EnumOptions* msg) { const upb_MiniTableField field = {999, UPB_SIZE(8, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -9498,7 +9498,7 @@ UPB_INLINE bool google_protobuf_EnumValueOptions_deprecated(const google_protobu } UPB_INLINE bool google_protobuf_EnumValueOptions_has_deprecated(const google_protobuf_EnumValueOptions* msg) { const upb_MiniTableField field = {1, 1, 1, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_EnumValueOptions_clear_features(google_protobuf_EnumValueOptions* msg) { const upb_MiniTableField field = {2, UPB_SIZE(4, 8), 2, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -9514,7 +9514,7 @@ UPB_INLINE const google_protobuf_FeatureSet* google_protobuf_EnumValueOptions_fe } UPB_INLINE bool google_protobuf_EnumValueOptions_has_features(const google_protobuf_EnumValueOptions* msg) { const upb_MiniTableField field = {2, UPB_SIZE(4, 8), 2, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_EnumValueOptions_clear_debug_redact(google_protobuf_EnumValueOptions* msg) { const upb_MiniTableField field = {3, UPB_SIZE(8, 2), 3, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; @@ -9530,7 +9530,7 @@ UPB_INLINE bool google_protobuf_EnumValueOptions_debug_redact(const google_proto } UPB_INLINE bool google_protobuf_EnumValueOptions_has_debug_redact(const google_protobuf_EnumValueOptions* msg) { const upb_MiniTableField field = {3, UPB_SIZE(8, 2), 3, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_EnumValueOptions_clear_uninterpreted_option(google_protobuf_EnumValueOptions* msg) { const upb_MiniTableField field = {999, UPB_SIZE(12, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -9666,7 +9666,7 @@ UPB_INLINE bool google_protobuf_ServiceOptions_deprecated(const google_protobuf_ } UPB_INLINE bool google_protobuf_ServiceOptions_has_deprecated(const google_protobuf_ServiceOptions* msg) { const upb_MiniTableField field = {33, 1, 1, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_ServiceOptions_clear_features(google_protobuf_ServiceOptions* msg) { const upb_MiniTableField field = {34, UPB_SIZE(4, 8), 2, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -9682,7 +9682,7 @@ UPB_INLINE const google_protobuf_FeatureSet* google_protobuf_ServiceOptions_feat } UPB_INLINE bool google_protobuf_ServiceOptions_has_features(const google_protobuf_ServiceOptions* msg) { const upb_MiniTableField field = {34, UPB_SIZE(4, 8), 2, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_ServiceOptions_clear_uninterpreted_option(google_protobuf_ServiceOptions* msg) { const upb_MiniTableField field = {999, UPB_SIZE(8, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -9814,7 +9814,7 @@ UPB_INLINE bool google_protobuf_MethodOptions_deprecated(const google_protobuf_M } UPB_INLINE bool google_protobuf_MethodOptions_has_deprecated(const google_protobuf_MethodOptions* msg) { const upb_MiniTableField field = {33, 1, 1, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_MethodOptions_clear_idempotency_level(google_protobuf_MethodOptions* msg) { const upb_MiniTableField field = {34, 4, 2, 2, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; @@ -9830,7 +9830,7 @@ UPB_INLINE int32_t google_protobuf_MethodOptions_idempotency_level(const google_ } UPB_INLINE bool google_protobuf_MethodOptions_has_idempotency_level(const google_protobuf_MethodOptions* msg) { const upb_MiniTableField field = {34, 4, 2, 2, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_MethodOptions_clear_features(google_protobuf_MethodOptions* msg) { const upb_MiniTableField field = {35, 8, 3, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -9846,7 +9846,7 @@ UPB_INLINE const google_protobuf_FeatureSet* google_protobuf_MethodOptions_featu } UPB_INLINE bool google_protobuf_MethodOptions_has_features(const google_protobuf_MethodOptions* msg) { const upb_MiniTableField field = {35, 8, 3, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_MethodOptions_clear_uninterpreted_option(google_protobuf_MethodOptions* msg) { const upb_MiniTableField field = {999, UPB_SIZE(12, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -10014,7 +10014,7 @@ UPB_INLINE upb_StringView google_protobuf_UninterpretedOption_identifier_value(c } UPB_INLINE bool google_protobuf_UninterpretedOption_has_identifier_value(const google_protobuf_UninterpretedOption* msg) { const upb_MiniTableField field = {3, UPB_SIZE(8, 16), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_UninterpretedOption_clear_positive_int_value(google_protobuf_UninterpretedOption* msg) { const upb_MiniTableField field = {4, UPB_SIZE(16, 32), 2, kUpb_NoSub, 4, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_8Byte << kUpb_FieldRep_Shift)}; @@ -10030,7 +10030,7 @@ UPB_INLINE uint64_t google_protobuf_UninterpretedOption_positive_int_value(const } UPB_INLINE bool google_protobuf_UninterpretedOption_has_positive_int_value(const google_protobuf_UninterpretedOption* msg) { const upb_MiniTableField field = {4, UPB_SIZE(16, 32), 2, kUpb_NoSub, 4, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_8Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_UninterpretedOption_clear_negative_int_value(google_protobuf_UninterpretedOption* msg) { const upb_MiniTableField field = {5, UPB_SIZE(24, 40), 3, kUpb_NoSub, 3, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_8Byte << kUpb_FieldRep_Shift)}; @@ -10046,7 +10046,7 @@ UPB_INLINE int64_t google_protobuf_UninterpretedOption_negative_int_value(const } UPB_INLINE bool google_protobuf_UninterpretedOption_has_negative_int_value(const google_protobuf_UninterpretedOption* msg) { const upb_MiniTableField field = {5, UPB_SIZE(24, 40), 3, kUpb_NoSub, 3, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_8Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_UninterpretedOption_clear_double_value(google_protobuf_UninterpretedOption* msg) { const upb_MiniTableField field = {6, UPB_SIZE(32, 48), 4, kUpb_NoSub, 1, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_8Byte << kUpb_FieldRep_Shift)}; @@ -10062,7 +10062,7 @@ UPB_INLINE double google_protobuf_UninterpretedOption_double_value(const google_ } UPB_INLINE bool google_protobuf_UninterpretedOption_has_double_value(const google_protobuf_UninterpretedOption* msg) { const upb_MiniTableField field = {6, UPB_SIZE(32, 48), 4, kUpb_NoSub, 1, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_8Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_UninterpretedOption_clear_string_value(google_protobuf_UninterpretedOption* msg) { const upb_MiniTableField field = {7, UPB_SIZE(40, 56), 5, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; @@ -10078,7 +10078,7 @@ UPB_INLINE upb_StringView google_protobuf_UninterpretedOption_string_value(const } UPB_INLINE bool google_protobuf_UninterpretedOption_has_string_value(const google_protobuf_UninterpretedOption* msg) { const upb_MiniTableField field = {7, UPB_SIZE(40, 56), 5, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_UninterpretedOption_clear_aggregate_value(google_protobuf_UninterpretedOption* msg) { const upb_MiniTableField field = {8, UPB_SIZE(48, 72), 6, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; @@ -10094,7 +10094,7 @@ UPB_INLINE upb_StringView google_protobuf_UninterpretedOption_aggregate_value(co } UPB_INLINE bool google_protobuf_UninterpretedOption_has_aggregate_value(const google_protobuf_UninterpretedOption* msg) { const upb_MiniTableField field = {8, UPB_SIZE(48, 72), 6, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE google_protobuf_UninterpretedOption_NamePart** google_protobuf_UninterpretedOption_mutable_name(google_protobuf_UninterpretedOption* msg, size_t* size) { @@ -10202,7 +10202,7 @@ UPB_INLINE upb_StringView google_protobuf_UninterpretedOption_NamePart_name_part } UPB_INLINE bool google_protobuf_UninterpretedOption_NamePart_has_name_part(const google_protobuf_UninterpretedOption_NamePart* msg) { const upb_MiniTableField field = {1, UPB_SIZE(4, 8), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_UninterpretedOption_NamePart_clear_is_extension(google_protobuf_UninterpretedOption_NamePart* msg) { const upb_MiniTableField field = {2, 1, 2, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; @@ -10218,7 +10218,7 @@ UPB_INLINE bool google_protobuf_UninterpretedOption_NamePart_is_extension(const } UPB_INLINE bool google_protobuf_UninterpretedOption_NamePart_has_is_extension(const google_protobuf_UninterpretedOption_NamePart* msg) { const upb_MiniTableField field = {2, 1, 2, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_UninterpretedOption_NamePart_set_name_part(google_protobuf_UninterpretedOption_NamePart *msg, upb_StringView value) { @@ -10280,7 +10280,7 @@ UPB_INLINE int32_t google_protobuf_FeatureSet_field_presence(const google_protob } UPB_INLINE bool google_protobuf_FeatureSet_has_field_presence(const google_protobuf_FeatureSet* msg) { const upb_MiniTableField field = {1, 4, 1, 0, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FeatureSet_clear_enum_type(google_protobuf_FeatureSet* msg) { const upb_MiniTableField field = {2, 8, 2, 1, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; @@ -10296,7 +10296,7 @@ UPB_INLINE int32_t google_protobuf_FeatureSet_enum_type(const google_protobuf_Fe } UPB_INLINE bool google_protobuf_FeatureSet_has_enum_type(const google_protobuf_FeatureSet* msg) { const upb_MiniTableField field = {2, 8, 2, 1, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FeatureSet_clear_repeated_field_encoding(google_protobuf_FeatureSet* msg) { const upb_MiniTableField field = {3, 12, 3, 2, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; @@ -10312,7 +10312,7 @@ UPB_INLINE int32_t google_protobuf_FeatureSet_repeated_field_encoding(const goog } UPB_INLINE bool google_protobuf_FeatureSet_has_repeated_field_encoding(const google_protobuf_FeatureSet* msg) { const upb_MiniTableField field = {3, 12, 3, 2, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FeatureSet_clear_utf8_validation(google_protobuf_FeatureSet* msg) { const upb_MiniTableField field = {4, 16, 4, 3, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; @@ -10328,7 +10328,7 @@ UPB_INLINE int32_t google_protobuf_FeatureSet_utf8_validation(const google_proto } UPB_INLINE bool google_protobuf_FeatureSet_has_utf8_validation(const google_protobuf_FeatureSet* msg) { const upb_MiniTableField field = {4, 16, 4, 3, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FeatureSet_clear_message_encoding(google_protobuf_FeatureSet* msg) { const upb_MiniTableField field = {5, 20, 5, 4, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; @@ -10344,7 +10344,7 @@ UPB_INLINE int32_t google_protobuf_FeatureSet_message_encoding(const google_prot } UPB_INLINE bool google_protobuf_FeatureSet_has_message_encoding(const google_protobuf_FeatureSet* msg) { const upb_MiniTableField field = {5, 20, 5, 4, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FeatureSet_clear_json_format(google_protobuf_FeatureSet* msg) { const upb_MiniTableField field = {6, 24, 6, 5, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; @@ -10360,7 +10360,7 @@ UPB_INLINE int32_t google_protobuf_FeatureSet_json_format(const google_protobuf_ } UPB_INLINE bool google_protobuf_FeatureSet_has_json_format(const google_protobuf_FeatureSet* msg) { const upb_MiniTableField field = {6, 24, 6, 5, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FeatureSet_set_field_presence(google_protobuf_FeatureSet *msg, int32_t value) { @@ -10470,7 +10470,7 @@ UPB_INLINE int32_t google_protobuf_FeatureSetDefaults_minimum_edition(const goog } UPB_INLINE bool google_protobuf_FeatureSetDefaults_has_minimum_edition(const google_protobuf_FeatureSetDefaults* msg) { const upb_MiniTableField field = {4, UPB_SIZE(8, 4), 1, 1, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FeatureSetDefaults_clear_maximum_edition(google_protobuf_FeatureSetDefaults* msg) { const upb_MiniTableField field = {5, UPB_SIZE(12, 8), 2, 2, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; @@ -10486,7 +10486,7 @@ UPB_INLINE int32_t google_protobuf_FeatureSetDefaults_maximum_edition(const goog } UPB_INLINE bool google_protobuf_FeatureSetDefaults_has_maximum_edition(const google_protobuf_FeatureSetDefaults* msg) { const upb_MiniTableField field = {5, UPB_SIZE(12, 8), 2, 2, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault** google_protobuf_FeatureSetDefaults_mutable_defaults(google_protobuf_FeatureSetDefaults* msg, size_t* size) { @@ -10578,7 +10578,7 @@ UPB_INLINE const google_protobuf_FeatureSet* google_protobuf_FeatureSetDefaults_ } UPB_INLINE bool google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_has_features(const google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* msg) { const upb_MiniTableField field = {2, UPB_SIZE(4, 8), 1, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_clear_edition(google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* msg) { const upb_MiniTableField field = {3, UPB_SIZE(8, 4), 2, 1, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; @@ -10594,7 +10594,7 @@ UPB_INLINE int32_t google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_e } UPB_INLINE bool google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_has_edition(const google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* msg) { const upb_MiniTableField field = {3, UPB_SIZE(8, 4), 2, 1, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_set_features(google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault *msg, google_protobuf_FeatureSet* value) { @@ -10828,7 +10828,7 @@ UPB_INLINE upb_StringView google_protobuf_SourceCodeInfo_Location_leading_commen } UPB_INLINE bool google_protobuf_SourceCodeInfo_Location_has_leading_comments(const google_protobuf_SourceCodeInfo_Location* msg) { const upb_MiniTableField field = {3, UPB_SIZE(16, 24), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_SourceCodeInfo_Location_clear_trailing_comments(google_protobuf_SourceCodeInfo_Location* msg) { const upb_MiniTableField field = {4, UPB_SIZE(24, 40), 2, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; @@ -10844,7 +10844,7 @@ UPB_INLINE upb_StringView google_protobuf_SourceCodeInfo_Location_trailing_comme } UPB_INLINE bool google_protobuf_SourceCodeInfo_Location_has_trailing_comments(const google_protobuf_SourceCodeInfo_Location* msg) { const upb_MiniTableField field = {4, UPB_SIZE(24, 40), 2, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_SourceCodeInfo_Location_clear_leading_detached_comments(google_protobuf_SourceCodeInfo_Location* msg) { const upb_MiniTableField field = {6, UPB_SIZE(12, 56), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -11154,7 +11154,7 @@ UPB_INLINE upb_StringView google_protobuf_GeneratedCodeInfo_Annotation_source_fi } UPB_INLINE bool google_protobuf_GeneratedCodeInfo_Annotation_has_source_file(const google_protobuf_GeneratedCodeInfo_Annotation* msg) { const upb_MiniTableField field = {2, UPB_SIZE(20, 24), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_GeneratedCodeInfo_Annotation_clear_begin(google_protobuf_GeneratedCodeInfo_Annotation* msg) { const upb_MiniTableField field = {3, UPB_SIZE(8, 4), 2, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; @@ -11170,7 +11170,7 @@ UPB_INLINE int32_t google_protobuf_GeneratedCodeInfo_Annotation_begin(const goog } UPB_INLINE bool google_protobuf_GeneratedCodeInfo_Annotation_has_begin(const google_protobuf_GeneratedCodeInfo_Annotation* msg) { const upb_MiniTableField field = {3, UPB_SIZE(8, 4), 2, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_GeneratedCodeInfo_Annotation_clear_end(google_protobuf_GeneratedCodeInfo_Annotation* msg) { const upb_MiniTableField field = {4, UPB_SIZE(12, 8), 3, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; @@ -11186,7 +11186,7 @@ UPB_INLINE int32_t google_protobuf_GeneratedCodeInfo_Annotation_end(const google } UPB_INLINE bool google_protobuf_GeneratedCodeInfo_Annotation_has_end(const google_protobuf_GeneratedCodeInfo_Annotation* msg) { const upb_MiniTableField field = {4, UPB_SIZE(12, 8), 3, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_GeneratedCodeInfo_Annotation_clear_semantic(google_protobuf_GeneratedCodeInfo_Annotation* msg) { const upb_MiniTableField field = {5, UPB_SIZE(16, 12), 4, 0, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; @@ -11202,7 +11202,7 @@ UPB_INLINE int32_t google_protobuf_GeneratedCodeInfo_Annotation_semantic(const g } UPB_INLINE bool google_protobuf_GeneratedCodeInfo_Annotation_has_semantic(const google_protobuf_GeneratedCodeInfo_Annotation* msg) { const upb_MiniTableField field = {5, UPB_SIZE(16, 12), 4, 0, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t* google_protobuf_GeneratedCodeInfo_Annotation_mutable_path(google_protobuf_GeneratedCodeInfo_Annotation* msg, size_t* size) { diff --git a/upb/cmake/google/protobuf/descriptor.upb.h b/upb/cmake/google/protobuf/descriptor.upb.h index 95d76292abfa3..8b28ffe3ca7f7 100644 --- a/upb/cmake/google/protobuf/descriptor.upb.h +++ b/upb/cmake/google/protobuf/descriptor.upb.h @@ -335,7 +335,7 @@ UPB_INLINE upb_StringView google_protobuf_FileDescriptorProto_name(const google_ } UPB_INLINE bool google_protobuf_FileDescriptorProto_has_name(const google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = {1, UPB_SIZE(44, 8), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileDescriptorProto_clear_package(google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = {2, UPB_SIZE(52, 24), 2, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; @@ -351,7 +351,7 @@ UPB_INLINE upb_StringView google_protobuf_FileDescriptorProto_package(const goog } UPB_INLINE bool google_protobuf_FileDescriptorProto_has_package(const google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = {2, UPB_SIZE(52, 24), 2, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileDescriptorProto_clear_dependency(google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = {3, UPB_SIZE(4, 40), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -527,7 +527,7 @@ UPB_INLINE const google_protobuf_FileOptions* google_protobuf_FileDescriptorProt } UPB_INLINE bool google_protobuf_FileDescriptorProto_has_options(const google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = {8, UPB_SIZE(24, 80), 3, 4, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileDescriptorProto_clear_source_code_info(google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = {9, UPB_SIZE(28, 88), 4, 5, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -543,7 +543,7 @@ UPB_INLINE const google_protobuf_SourceCodeInfo* google_protobuf_FileDescriptorP } UPB_INLINE bool google_protobuf_FileDescriptorProto_has_source_code_info(const google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = {9, UPB_SIZE(28, 88), 4, 5, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileDescriptorProto_clear_public_dependency(google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = {10, UPB_SIZE(32, 96), 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -623,7 +623,7 @@ UPB_INLINE upb_StringView google_protobuf_FileDescriptorProto_syntax(const googl } UPB_INLINE bool google_protobuf_FileDescriptorProto_has_syntax(const google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = {12, UPB_SIZE(60, 112), 5, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileDescriptorProto_clear_edition(google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = {14, UPB_SIZE(40, 4), 6, 6, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; @@ -639,7 +639,7 @@ UPB_INLINE int32_t google_protobuf_FileDescriptorProto_edition(const google_prot } UPB_INLINE bool google_protobuf_FileDescriptorProto_has_edition(const google_protobuf_FileDescriptorProto* msg) { const upb_MiniTableField field = {14, UPB_SIZE(40, 4), 6, 6, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileDescriptorProto_set_name(google_protobuf_FileDescriptorProto *msg, upb_StringView value) { @@ -937,7 +937,7 @@ UPB_INLINE upb_StringView google_protobuf_DescriptorProto_name(const google_prot } UPB_INLINE bool google_protobuf_DescriptorProto_has_name(const google_protobuf_DescriptorProto* msg) { const upb_MiniTableField field = {1, UPB_SIZE(40, 8), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_DescriptorProto_clear_field(google_protobuf_DescriptorProto* msg) { const upb_MiniTableField field = {2, UPB_SIZE(4, 24), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -1113,7 +1113,7 @@ UPB_INLINE const google_protobuf_MessageOptions* google_protobuf_DescriptorProto } UPB_INLINE bool google_protobuf_DescriptorProto_has_options(const google_protobuf_DescriptorProto* msg) { const upb_MiniTableField field = {7, UPB_SIZE(24, 64), 2, 5, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_DescriptorProto_clear_oneof_decl(google_protobuf_DescriptorProto* msg) { const upb_MiniTableField field = {8, UPB_SIZE(28, 72), 0, 6, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -1517,7 +1517,7 @@ UPB_INLINE int32_t google_protobuf_DescriptorProto_ExtensionRange_start(const go } UPB_INLINE bool google_protobuf_DescriptorProto_ExtensionRange_has_start(const google_protobuf_DescriptorProto_ExtensionRange* msg) { const upb_MiniTableField field = {1, 4, 1, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_DescriptorProto_ExtensionRange_clear_end(google_protobuf_DescriptorProto_ExtensionRange* msg) { const upb_MiniTableField field = {2, 8, 2, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; @@ -1533,7 +1533,7 @@ UPB_INLINE int32_t google_protobuf_DescriptorProto_ExtensionRange_end(const goog } UPB_INLINE bool google_protobuf_DescriptorProto_ExtensionRange_has_end(const google_protobuf_DescriptorProto_ExtensionRange* msg) { const upb_MiniTableField field = {2, 8, 2, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_DescriptorProto_ExtensionRange_clear_options(google_protobuf_DescriptorProto_ExtensionRange* msg) { const upb_MiniTableField field = {3, UPB_SIZE(12, 16), 3, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -1549,7 +1549,7 @@ UPB_INLINE const google_protobuf_ExtensionRangeOptions* google_protobuf_Descript } UPB_INLINE bool google_protobuf_DescriptorProto_ExtensionRange_has_options(const google_protobuf_DescriptorProto_ExtensionRange* msg) { const upb_MiniTableField field = {3, UPB_SIZE(12, 16), 3, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_DescriptorProto_ExtensionRange_set_start(google_protobuf_DescriptorProto_ExtensionRange *msg, int32_t value) { @@ -1623,7 +1623,7 @@ UPB_INLINE int32_t google_protobuf_DescriptorProto_ReservedRange_start(const goo } UPB_INLINE bool google_protobuf_DescriptorProto_ReservedRange_has_start(const google_protobuf_DescriptorProto_ReservedRange* msg) { const upb_MiniTableField field = {1, 4, 1, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_DescriptorProto_ReservedRange_clear_end(google_protobuf_DescriptorProto_ReservedRange* msg) { const upb_MiniTableField field = {2, 8, 2, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; @@ -1639,7 +1639,7 @@ UPB_INLINE int32_t google_protobuf_DescriptorProto_ReservedRange_end(const googl } UPB_INLINE bool google_protobuf_DescriptorProto_ReservedRange_has_end(const google_protobuf_DescriptorProto_ReservedRange* msg) { const upb_MiniTableField field = {2, 8, 2, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_DescriptorProto_ReservedRange_set_start(google_protobuf_DescriptorProto_ReservedRange *msg, int32_t value) { @@ -1733,7 +1733,7 @@ UPB_INLINE int32_t google_protobuf_ExtensionRangeOptions_verification(const goog } UPB_INLINE bool google_protobuf_ExtensionRangeOptions_has_verification(const google_protobuf_ExtensionRangeOptions* msg) { const upb_MiniTableField field = {3, UPB_SIZE(8, 4), 1, 3, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_ExtensionRangeOptions_clear_features(google_protobuf_ExtensionRangeOptions* msg) { const upb_MiniTableField field = {50, UPB_SIZE(12, 16), 2, 1, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -1749,7 +1749,7 @@ UPB_INLINE const google_protobuf_FeatureSet* google_protobuf_ExtensionRangeOptio } UPB_INLINE bool google_protobuf_ExtensionRangeOptions_has_features(const google_protobuf_ExtensionRangeOptions* msg) { const upb_MiniTableField field = {50, UPB_SIZE(12, 16), 2, 1, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_ExtensionRangeOptions_clear_uninterpreted_option(google_protobuf_ExtensionRangeOptions* msg) { const upb_MiniTableField field = {999, UPB_SIZE(16, 24), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -1911,7 +1911,7 @@ UPB_INLINE int32_t google_protobuf_ExtensionRangeOptions_Declaration_number(cons } UPB_INLINE bool google_protobuf_ExtensionRangeOptions_Declaration_has_number(const google_protobuf_ExtensionRangeOptions_Declaration* msg) { const upb_MiniTableField field = {1, 4, 1, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_ExtensionRangeOptions_Declaration_clear_full_name(google_protobuf_ExtensionRangeOptions_Declaration* msg) { const upb_MiniTableField field = {2, UPB_SIZE(12, 16), 2, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; @@ -1927,7 +1927,7 @@ UPB_INLINE upb_StringView google_protobuf_ExtensionRangeOptions_Declaration_full } UPB_INLINE bool google_protobuf_ExtensionRangeOptions_Declaration_has_full_name(const google_protobuf_ExtensionRangeOptions_Declaration* msg) { const upb_MiniTableField field = {2, UPB_SIZE(12, 16), 2, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_ExtensionRangeOptions_Declaration_clear_type(google_protobuf_ExtensionRangeOptions_Declaration* msg) { const upb_MiniTableField field = {3, UPB_SIZE(20, 32), 3, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; @@ -1943,7 +1943,7 @@ UPB_INLINE upb_StringView google_protobuf_ExtensionRangeOptions_Declaration_type } UPB_INLINE bool google_protobuf_ExtensionRangeOptions_Declaration_has_type(const google_protobuf_ExtensionRangeOptions_Declaration* msg) { const upb_MiniTableField field = {3, UPB_SIZE(20, 32), 3, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_ExtensionRangeOptions_Declaration_clear_reserved(google_protobuf_ExtensionRangeOptions_Declaration* msg) { const upb_MiniTableField field = {5, 8, 4, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; @@ -1959,7 +1959,7 @@ UPB_INLINE bool google_protobuf_ExtensionRangeOptions_Declaration_reserved(const } UPB_INLINE bool google_protobuf_ExtensionRangeOptions_Declaration_has_reserved(const google_protobuf_ExtensionRangeOptions_Declaration* msg) { const upb_MiniTableField field = {5, 8, 4, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_ExtensionRangeOptions_Declaration_clear_repeated(google_protobuf_ExtensionRangeOptions_Declaration* msg) { const upb_MiniTableField field = {6, 9, 5, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; @@ -1975,7 +1975,7 @@ UPB_INLINE bool google_protobuf_ExtensionRangeOptions_Declaration_repeated(const } UPB_INLINE bool google_protobuf_ExtensionRangeOptions_Declaration_has_repeated(const google_protobuf_ExtensionRangeOptions_Declaration* msg) { const upb_MiniTableField field = {6, 9, 5, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_ExtensionRangeOptions_Declaration_set_number(google_protobuf_ExtensionRangeOptions_Declaration *msg, int32_t value) { @@ -2049,7 +2049,7 @@ UPB_INLINE upb_StringView google_protobuf_FieldDescriptorProto_name(const google } UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_name(const google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = {1, UPB_SIZE(28, 24), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldDescriptorProto_clear_extendee(google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = {2, UPB_SIZE(36, 40), 2, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; @@ -2065,7 +2065,7 @@ UPB_INLINE upb_StringView google_protobuf_FieldDescriptorProto_extendee(const go } UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_extendee(const google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = {2, UPB_SIZE(36, 40), 2, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldDescriptorProto_clear_number(google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = {3, 4, 3, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; @@ -2081,7 +2081,7 @@ UPB_INLINE int32_t google_protobuf_FieldDescriptorProto_number(const google_prot } UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_number(const google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = {3, 4, 3, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldDescriptorProto_clear_label(google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = {4, 8, 4, 1, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; @@ -2097,7 +2097,7 @@ UPB_INLINE int32_t google_protobuf_FieldDescriptorProto_label(const google_proto } UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_label(const google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = {4, 8, 4, 1, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldDescriptorProto_clear_type(google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = {5, 12, 5, 2, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; @@ -2113,7 +2113,7 @@ UPB_INLINE int32_t google_protobuf_FieldDescriptorProto_type(const google_protob } UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_type(const google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = {5, 12, 5, 2, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldDescriptorProto_clear_type_name(google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = {6, UPB_SIZE(44, 56), 6, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; @@ -2129,7 +2129,7 @@ UPB_INLINE upb_StringView google_protobuf_FieldDescriptorProto_type_name(const g } UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_type_name(const google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = {6, UPB_SIZE(44, 56), 6, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldDescriptorProto_clear_default_value(google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = {7, UPB_SIZE(52, 72), 7, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; @@ -2145,7 +2145,7 @@ UPB_INLINE upb_StringView google_protobuf_FieldDescriptorProto_default_value(con } UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_default_value(const google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = {7, UPB_SIZE(52, 72), 7, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldDescriptorProto_clear_options(google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = {8, UPB_SIZE(16, 88), 8, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -2161,7 +2161,7 @@ UPB_INLINE const google_protobuf_FieldOptions* google_protobuf_FieldDescriptorPr } UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_options(const google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = {8, UPB_SIZE(16, 88), 8, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldDescriptorProto_clear_oneof_index(google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = {9, UPB_SIZE(20, 16), 9, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; @@ -2177,7 +2177,7 @@ UPB_INLINE int32_t google_protobuf_FieldDescriptorProto_oneof_index(const google } UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_oneof_index(const google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = {9, UPB_SIZE(20, 16), 9, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldDescriptorProto_clear_json_name(google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = {10, UPB_SIZE(60, 96), 10, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; @@ -2193,7 +2193,7 @@ UPB_INLINE upb_StringView google_protobuf_FieldDescriptorProto_json_name(const g } UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_json_name(const google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = {10, UPB_SIZE(60, 96), 10, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldDescriptorProto_clear_proto3_optional(google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = {17, UPB_SIZE(24, 20), 11, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; @@ -2209,7 +2209,7 @@ UPB_INLINE bool google_protobuf_FieldDescriptorProto_proto3_optional(const googl } UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_proto3_optional(const google_protobuf_FieldDescriptorProto* msg) { const upb_MiniTableField field = {17, UPB_SIZE(24, 20), 11, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldDescriptorProto_set_name(google_protobuf_FieldDescriptorProto *msg, upb_StringView value) { @@ -2315,7 +2315,7 @@ UPB_INLINE upb_StringView google_protobuf_OneofDescriptorProto_name(const google } UPB_INLINE bool google_protobuf_OneofDescriptorProto_has_name(const google_protobuf_OneofDescriptorProto* msg) { const upb_MiniTableField field = {1, 8, 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_OneofDescriptorProto_clear_options(google_protobuf_OneofDescriptorProto* msg) { const upb_MiniTableField field = {2, UPB_SIZE(4, 24), 2, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -2331,7 +2331,7 @@ UPB_INLINE const google_protobuf_OneofOptions* google_protobuf_OneofDescriptorPr } UPB_INLINE bool google_protobuf_OneofDescriptorProto_has_options(const google_protobuf_OneofDescriptorProto* msg) { const upb_MiniTableField field = {2, UPB_SIZE(4, 24), 2, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_OneofDescriptorProto_set_name(google_protobuf_OneofDescriptorProto *msg, upb_StringView value) { @@ -2401,7 +2401,7 @@ UPB_INLINE upb_StringView google_protobuf_EnumDescriptorProto_name(const google_ } UPB_INLINE bool google_protobuf_EnumDescriptorProto_has_name(const google_protobuf_EnumDescriptorProto* msg) { const upb_MiniTableField field = {1, UPB_SIZE(20, 8), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_EnumDescriptorProto_clear_value(google_protobuf_EnumDescriptorProto* msg) { const upb_MiniTableField field = {2, UPB_SIZE(4, 24), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -2449,7 +2449,7 @@ UPB_INLINE const google_protobuf_EnumOptions* google_protobuf_EnumDescriptorProt } UPB_INLINE bool google_protobuf_EnumDescriptorProto_has_options(const google_protobuf_EnumDescriptorProto* msg) { const upb_MiniTableField field = {3, UPB_SIZE(8, 32), 2, 1, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_EnumDescriptorProto_clear_reserved_range(google_protobuf_EnumDescriptorProto* msg) { const upb_MiniTableField field = {4, UPB_SIZE(12, 40), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -2671,7 +2671,7 @@ UPB_INLINE int32_t google_protobuf_EnumDescriptorProto_EnumReservedRange_start(c } UPB_INLINE bool google_protobuf_EnumDescriptorProto_EnumReservedRange_has_start(const google_protobuf_EnumDescriptorProto_EnumReservedRange* msg) { const upb_MiniTableField field = {1, 4, 1, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_EnumDescriptorProto_EnumReservedRange_clear_end(google_protobuf_EnumDescriptorProto_EnumReservedRange* msg) { const upb_MiniTableField field = {2, 8, 2, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; @@ -2687,7 +2687,7 @@ UPB_INLINE int32_t google_protobuf_EnumDescriptorProto_EnumReservedRange_end(con } UPB_INLINE bool google_protobuf_EnumDescriptorProto_EnumReservedRange_has_end(const google_protobuf_EnumDescriptorProto_EnumReservedRange* msg) { const upb_MiniTableField field = {2, 8, 2, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_EnumDescriptorProto_EnumReservedRange_set_start(google_protobuf_EnumDescriptorProto_EnumReservedRange *msg, int32_t value) { @@ -2749,7 +2749,7 @@ UPB_INLINE upb_StringView google_protobuf_EnumValueDescriptorProto_name(const go } UPB_INLINE bool google_protobuf_EnumValueDescriptorProto_has_name(const google_protobuf_EnumValueDescriptorProto* msg) { const upb_MiniTableField field = {1, UPB_SIZE(12, 8), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_EnumValueDescriptorProto_clear_number(google_protobuf_EnumValueDescriptorProto* msg) { const upb_MiniTableField field = {2, 4, 2, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; @@ -2765,7 +2765,7 @@ UPB_INLINE int32_t google_protobuf_EnumValueDescriptorProto_number(const google_ } UPB_INLINE bool google_protobuf_EnumValueDescriptorProto_has_number(const google_protobuf_EnumValueDescriptorProto* msg) { const upb_MiniTableField field = {2, 4, 2, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_EnumValueDescriptorProto_clear_options(google_protobuf_EnumValueDescriptorProto* msg) { const upb_MiniTableField field = {3, UPB_SIZE(8, 24), 3, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -2781,7 +2781,7 @@ UPB_INLINE const google_protobuf_EnumValueOptions* google_protobuf_EnumValueDesc } UPB_INLINE bool google_protobuf_EnumValueDescriptorProto_has_options(const google_protobuf_EnumValueDescriptorProto* msg) { const upb_MiniTableField field = {3, UPB_SIZE(8, 24), 3, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_EnumValueDescriptorProto_set_name(google_protobuf_EnumValueDescriptorProto *msg, upb_StringView value) { @@ -2855,7 +2855,7 @@ UPB_INLINE upb_StringView google_protobuf_ServiceDescriptorProto_name(const goog } UPB_INLINE bool google_protobuf_ServiceDescriptorProto_has_name(const google_protobuf_ServiceDescriptorProto* msg) { const upb_MiniTableField field = {1, UPB_SIZE(12, 8), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_ServiceDescriptorProto_clear_method(google_protobuf_ServiceDescriptorProto* msg) { const upb_MiniTableField field = {2, UPB_SIZE(4, 24), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -2903,7 +2903,7 @@ UPB_INLINE const google_protobuf_ServiceOptions* google_protobuf_ServiceDescript } UPB_INLINE bool google_protobuf_ServiceDescriptorProto_has_options(const google_protobuf_ServiceDescriptorProto* msg) { const upb_MiniTableField field = {3, UPB_SIZE(8, 32), 2, 1, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_ServiceDescriptorProto_set_name(google_protobuf_ServiceDescriptorProto *msg, upb_StringView value) { @@ -3003,7 +3003,7 @@ UPB_INLINE upb_StringView google_protobuf_MethodDescriptorProto_name(const googl } UPB_INLINE bool google_protobuf_MethodDescriptorProto_has_name(const google_protobuf_MethodDescriptorProto* msg) { const upb_MiniTableField field = {1, UPB_SIZE(12, 8), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_MethodDescriptorProto_clear_input_type(google_protobuf_MethodDescriptorProto* msg) { const upb_MiniTableField field = {2, UPB_SIZE(20, 24), 2, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; @@ -3019,7 +3019,7 @@ UPB_INLINE upb_StringView google_protobuf_MethodDescriptorProto_input_type(const } UPB_INLINE bool google_protobuf_MethodDescriptorProto_has_input_type(const google_protobuf_MethodDescriptorProto* msg) { const upb_MiniTableField field = {2, UPB_SIZE(20, 24), 2, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_MethodDescriptorProto_clear_output_type(google_protobuf_MethodDescriptorProto* msg) { const upb_MiniTableField field = {3, UPB_SIZE(28, 40), 3, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; @@ -3035,7 +3035,7 @@ UPB_INLINE upb_StringView google_protobuf_MethodDescriptorProto_output_type(cons } UPB_INLINE bool google_protobuf_MethodDescriptorProto_has_output_type(const google_protobuf_MethodDescriptorProto* msg) { const upb_MiniTableField field = {3, UPB_SIZE(28, 40), 3, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_MethodDescriptorProto_clear_options(google_protobuf_MethodDescriptorProto* msg) { const upb_MiniTableField field = {4, UPB_SIZE(4, 56), 4, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -3051,7 +3051,7 @@ UPB_INLINE const google_protobuf_MethodOptions* google_protobuf_MethodDescriptor } UPB_INLINE bool google_protobuf_MethodDescriptorProto_has_options(const google_protobuf_MethodDescriptorProto* msg) { const upb_MiniTableField field = {4, UPB_SIZE(4, 56), 4, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_MethodDescriptorProto_clear_client_streaming(google_protobuf_MethodDescriptorProto* msg) { const upb_MiniTableField field = {5, UPB_SIZE(8, 1), 5, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; @@ -3067,7 +3067,7 @@ UPB_INLINE bool google_protobuf_MethodDescriptorProto_client_streaming(const goo } UPB_INLINE bool google_protobuf_MethodDescriptorProto_has_client_streaming(const google_protobuf_MethodDescriptorProto* msg) { const upb_MiniTableField field = {5, UPB_SIZE(8, 1), 5, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_MethodDescriptorProto_clear_server_streaming(google_protobuf_MethodDescriptorProto* msg) { const upb_MiniTableField field = {6, UPB_SIZE(9, 2), 6, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; @@ -3083,7 +3083,7 @@ UPB_INLINE bool google_protobuf_MethodDescriptorProto_server_streaming(const goo } UPB_INLINE bool google_protobuf_MethodDescriptorProto_has_server_streaming(const google_protobuf_MethodDescriptorProto* msg) { const upb_MiniTableField field = {6, UPB_SIZE(9, 2), 6, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_MethodDescriptorProto_set_name(google_protobuf_MethodDescriptorProto *msg, upb_StringView value) { @@ -3169,7 +3169,7 @@ UPB_INLINE upb_StringView google_protobuf_FileOptions_java_package(const google_ } UPB_INLINE bool google_protobuf_FileOptions_has_java_package(const google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {1, UPB_SIZE(24, 16), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileOptions_clear_java_outer_classname(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {8, 32, 2, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; @@ -3185,7 +3185,7 @@ UPB_INLINE upb_StringView google_protobuf_FileOptions_java_outer_classname(const } UPB_INLINE bool google_protobuf_FileOptions_has_java_outer_classname(const google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {8, 32, 2, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileOptions_clear_optimize_for(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {9, 4, 3, 2, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; @@ -3201,7 +3201,7 @@ UPB_INLINE int32_t google_protobuf_FileOptions_optimize_for(const google_protobu } UPB_INLINE bool google_protobuf_FileOptions_has_optimize_for(const google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {9, 4, 3, 2, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileOptions_clear_java_multiple_files(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {10, 8, 4, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; @@ -3217,7 +3217,7 @@ UPB_INLINE bool google_protobuf_FileOptions_java_multiple_files(const google_pro } UPB_INLINE bool google_protobuf_FileOptions_has_java_multiple_files(const google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {10, 8, 4, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileOptions_clear_go_package(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {11, UPB_SIZE(40, 48), 5, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; @@ -3233,7 +3233,7 @@ UPB_INLINE upb_StringView google_protobuf_FileOptions_go_package(const google_pr } UPB_INLINE bool google_protobuf_FileOptions_has_go_package(const google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {11, UPB_SIZE(40, 48), 5, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileOptions_clear_cc_generic_services(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {16, 9, 6, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; @@ -3249,7 +3249,7 @@ UPB_INLINE bool google_protobuf_FileOptions_cc_generic_services(const google_pro } UPB_INLINE bool google_protobuf_FileOptions_has_cc_generic_services(const google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {16, 9, 6, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileOptions_clear_java_generic_services(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {17, 10, 7, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; @@ -3265,7 +3265,7 @@ UPB_INLINE bool google_protobuf_FileOptions_java_generic_services(const google_p } UPB_INLINE bool google_protobuf_FileOptions_has_java_generic_services(const google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {17, 10, 7, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileOptions_clear_py_generic_services(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {18, 11, 8, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; @@ -3281,7 +3281,7 @@ UPB_INLINE bool google_protobuf_FileOptions_py_generic_services(const google_pro } UPB_INLINE bool google_protobuf_FileOptions_has_py_generic_services(const google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {18, 11, 8, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileOptions_clear_java_generate_equals_and_hash(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {20, 12, 9, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; @@ -3297,7 +3297,7 @@ UPB_INLINE bool google_protobuf_FileOptions_java_generate_equals_and_hash(const } UPB_INLINE bool google_protobuf_FileOptions_has_java_generate_equals_and_hash(const google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {20, 12, 9, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileOptions_clear_deprecated(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {23, 13, 10, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; @@ -3313,7 +3313,7 @@ UPB_INLINE bool google_protobuf_FileOptions_deprecated(const google_protobuf_Fil } UPB_INLINE bool google_protobuf_FileOptions_has_deprecated(const google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {23, 13, 10, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileOptions_clear_java_string_check_utf8(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {27, 14, 11, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; @@ -3329,7 +3329,7 @@ UPB_INLINE bool google_protobuf_FileOptions_java_string_check_utf8(const google_ } UPB_INLINE bool google_protobuf_FileOptions_has_java_string_check_utf8(const google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {27, 14, 11, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileOptions_clear_cc_enable_arenas(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {31, 15, 12, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; @@ -3345,7 +3345,7 @@ UPB_INLINE bool google_protobuf_FileOptions_cc_enable_arenas(const google_protob } UPB_INLINE bool google_protobuf_FileOptions_has_cc_enable_arenas(const google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {31, 15, 12, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileOptions_clear_objc_class_prefix(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {36, UPB_SIZE(48, 64), 13, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; @@ -3361,7 +3361,7 @@ UPB_INLINE upb_StringView google_protobuf_FileOptions_objc_class_prefix(const go } UPB_INLINE bool google_protobuf_FileOptions_has_objc_class_prefix(const google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {36, UPB_SIZE(48, 64), 13, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileOptions_clear_csharp_namespace(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {37, UPB_SIZE(56, 80), 14, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; @@ -3377,7 +3377,7 @@ UPB_INLINE upb_StringView google_protobuf_FileOptions_csharp_namespace(const goo } UPB_INLINE bool google_protobuf_FileOptions_has_csharp_namespace(const google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {37, UPB_SIZE(56, 80), 14, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileOptions_clear_swift_prefix(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {39, UPB_SIZE(64, 96), 15, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; @@ -3393,7 +3393,7 @@ UPB_INLINE upb_StringView google_protobuf_FileOptions_swift_prefix(const google_ } UPB_INLINE bool google_protobuf_FileOptions_has_swift_prefix(const google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {39, UPB_SIZE(64, 96), 15, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileOptions_clear_php_class_prefix(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {40, UPB_SIZE(72, 112), 16, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; @@ -3409,7 +3409,7 @@ UPB_INLINE upb_StringView google_protobuf_FileOptions_php_class_prefix(const goo } UPB_INLINE bool google_protobuf_FileOptions_has_php_class_prefix(const google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {40, UPB_SIZE(72, 112), 16, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileOptions_clear_php_namespace(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {41, UPB_SIZE(80, 128), 17, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; @@ -3425,7 +3425,7 @@ UPB_INLINE upb_StringView google_protobuf_FileOptions_php_namespace(const google } UPB_INLINE bool google_protobuf_FileOptions_has_php_namespace(const google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {41, UPB_SIZE(80, 128), 17, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileOptions_clear_php_metadata_namespace(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {44, UPB_SIZE(88, 144), 18, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; @@ -3441,7 +3441,7 @@ UPB_INLINE upb_StringView google_protobuf_FileOptions_php_metadata_namespace(con } UPB_INLINE bool google_protobuf_FileOptions_has_php_metadata_namespace(const google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {44, UPB_SIZE(88, 144), 18, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileOptions_clear_ruby_package(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {45, UPB_SIZE(96, 160), 19, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; @@ -3457,7 +3457,7 @@ UPB_INLINE upb_StringView google_protobuf_FileOptions_ruby_package(const google_ } UPB_INLINE bool google_protobuf_FileOptions_has_ruby_package(const google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {45, UPB_SIZE(96, 160), 19, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileOptions_clear_features(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {50, UPB_SIZE(16, 176), 20, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -3473,7 +3473,7 @@ UPB_INLINE const google_protobuf_FeatureSet* google_protobuf_FileOptions_feature } UPB_INLINE bool google_protobuf_FileOptions_has_features(const google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {50, UPB_SIZE(16, 176), 20, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FileOptions_clear_uninterpreted_option(google_protobuf_FileOptions* msg) { const upb_MiniTableField field = {999, UPB_SIZE(20, 184), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -3677,7 +3677,7 @@ UPB_INLINE bool google_protobuf_MessageOptions_message_set_wire_format(const goo } UPB_INLINE bool google_protobuf_MessageOptions_has_message_set_wire_format(const google_protobuf_MessageOptions* msg) { const upb_MiniTableField field = {1, 1, 1, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_MessageOptions_clear_no_standard_descriptor_accessor(google_protobuf_MessageOptions* msg) { const upb_MiniTableField field = {2, 2, 2, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; @@ -3693,7 +3693,7 @@ UPB_INLINE bool google_protobuf_MessageOptions_no_standard_descriptor_accessor(c } UPB_INLINE bool google_protobuf_MessageOptions_has_no_standard_descriptor_accessor(const google_protobuf_MessageOptions* msg) { const upb_MiniTableField field = {2, 2, 2, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_MessageOptions_clear_deprecated(google_protobuf_MessageOptions* msg) { const upb_MiniTableField field = {3, 3, 3, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; @@ -3709,7 +3709,7 @@ UPB_INLINE bool google_protobuf_MessageOptions_deprecated(const google_protobuf_ } UPB_INLINE bool google_protobuf_MessageOptions_has_deprecated(const google_protobuf_MessageOptions* msg) { const upb_MiniTableField field = {3, 3, 3, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_MessageOptions_clear_map_entry(google_protobuf_MessageOptions* msg) { const upb_MiniTableField field = {7, 4, 4, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; @@ -3725,7 +3725,7 @@ UPB_INLINE bool google_protobuf_MessageOptions_map_entry(const google_protobuf_M } UPB_INLINE bool google_protobuf_MessageOptions_has_map_entry(const google_protobuf_MessageOptions* msg) { const upb_MiniTableField field = {7, 4, 4, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_MessageOptions_clear_deprecated_legacy_json_field_conflicts(google_protobuf_MessageOptions* msg) { const upb_MiniTableField field = {11, 5, 5, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; @@ -3741,7 +3741,7 @@ UPB_INLINE bool google_protobuf_MessageOptions_deprecated_legacy_json_field_conf } UPB_INLINE bool google_protobuf_MessageOptions_has_deprecated_legacy_json_field_conflicts(const google_protobuf_MessageOptions* msg) { const upb_MiniTableField field = {11, 5, 5, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_MessageOptions_clear_features(google_protobuf_MessageOptions* msg) { const upb_MiniTableField field = {12, 8, 6, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -3757,7 +3757,7 @@ UPB_INLINE const google_protobuf_FeatureSet* google_protobuf_MessageOptions_feat } UPB_INLINE bool google_protobuf_MessageOptions_has_features(const google_protobuf_MessageOptions* msg) { const upb_MiniTableField field = {12, 8, 6, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_MessageOptions_clear_uninterpreted_option(google_protobuf_MessageOptions* msg) { const upb_MiniTableField field = {999, UPB_SIZE(12, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -3905,7 +3905,7 @@ UPB_INLINE int32_t google_protobuf_FieldOptions_ctype(const google_protobuf_Fiel } UPB_INLINE bool google_protobuf_FieldOptions_has_ctype(const google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {1, 4, 1, 3, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldOptions_clear_packed(google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {2, 8, 2, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; @@ -3921,7 +3921,7 @@ UPB_INLINE bool google_protobuf_FieldOptions_packed(const google_protobuf_FieldO } UPB_INLINE bool google_protobuf_FieldOptions_has_packed(const google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {2, 8, 2, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldOptions_clear_deprecated(google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {3, 9, 3, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; @@ -3937,7 +3937,7 @@ UPB_INLINE bool google_protobuf_FieldOptions_deprecated(const google_protobuf_Fi } UPB_INLINE bool google_protobuf_FieldOptions_has_deprecated(const google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {3, 9, 3, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldOptions_clear_lazy(google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {5, 10, 4, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; @@ -3953,7 +3953,7 @@ UPB_INLINE bool google_protobuf_FieldOptions_lazy(const google_protobuf_FieldOpt } UPB_INLINE bool google_protobuf_FieldOptions_has_lazy(const google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {5, 10, 4, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldOptions_clear_jstype(google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {6, 12, 5, 4, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; @@ -3969,7 +3969,7 @@ UPB_INLINE int32_t google_protobuf_FieldOptions_jstype(const google_protobuf_Fie } UPB_INLINE bool google_protobuf_FieldOptions_has_jstype(const google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {6, 12, 5, 4, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldOptions_clear_weak(google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {10, 16, 6, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; @@ -3985,7 +3985,7 @@ UPB_INLINE bool google_protobuf_FieldOptions_weak(const google_protobuf_FieldOpt } UPB_INLINE bool google_protobuf_FieldOptions_has_weak(const google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {10, 16, 6, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldOptions_clear_unverified_lazy(google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {15, 17, 7, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; @@ -4001,7 +4001,7 @@ UPB_INLINE bool google_protobuf_FieldOptions_unverified_lazy(const google_protob } UPB_INLINE bool google_protobuf_FieldOptions_has_unverified_lazy(const google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {15, 17, 7, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldOptions_clear_debug_redact(google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {16, 18, 8, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; @@ -4017,7 +4017,7 @@ UPB_INLINE bool google_protobuf_FieldOptions_debug_redact(const google_protobuf_ } UPB_INLINE bool google_protobuf_FieldOptions_has_debug_redact(const google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {16, 18, 8, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldOptions_clear_retention(google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {17, 20, 9, 5, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; @@ -4033,7 +4033,7 @@ UPB_INLINE int32_t google_protobuf_FieldOptions_retention(const google_protobuf_ } UPB_INLINE bool google_protobuf_FieldOptions_has_retention(const google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {17, 20, 9, 5, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldOptions_clear_targets(google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {19, 24, 0, 6, 14, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -4113,7 +4113,7 @@ UPB_INLINE const google_protobuf_FeatureSet* google_protobuf_FieldOptions_featur } UPB_INLINE bool google_protobuf_FieldOptions_has_features(const google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {21, UPB_SIZE(32, 40), 10, 1, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldOptions_clear_uninterpreted_option(google_protobuf_FieldOptions* msg) { const upb_MiniTableField field = {999, UPB_SIZE(36, 48), 0, 2, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -4335,7 +4335,7 @@ UPB_INLINE upb_StringView google_protobuf_FieldOptions_EditionDefault_value(cons } UPB_INLINE bool google_protobuf_FieldOptions_EditionDefault_has_value(const google_protobuf_FieldOptions_EditionDefault* msg) { const upb_MiniTableField field = {2, 8, 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldOptions_EditionDefault_clear_edition(google_protobuf_FieldOptions_EditionDefault* msg) { const upb_MiniTableField field = {3, 4, 2, 0, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; @@ -4351,7 +4351,7 @@ UPB_INLINE int32_t google_protobuf_FieldOptions_EditionDefault_edition(const goo } UPB_INLINE bool google_protobuf_FieldOptions_EditionDefault_has_edition(const google_protobuf_FieldOptions_EditionDefault* msg) { const upb_MiniTableField field = {3, 4, 2, 0, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FieldOptions_EditionDefault_set_value(google_protobuf_FieldOptions_EditionDefault *msg, upb_StringView value) { @@ -4413,7 +4413,7 @@ UPB_INLINE const google_protobuf_FeatureSet* google_protobuf_OneofOptions_featur } UPB_INLINE bool google_protobuf_OneofOptions_has_features(const google_protobuf_OneofOptions* msg) { const upb_MiniTableField field = {1, UPB_SIZE(4, 8), 1, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_OneofOptions_clear_uninterpreted_option(google_protobuf_OneofOptions* msg) { const upb_MiniTableField field = {999, UPB_SIZE(8, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -4541,7 +4541,7 @@ UPB_INLINE bool google_protobuf_EnumOptions_allow_alias(const google_protobuf_En } UPB_INLINE bool google_protobuf_EnumOptions_has_allow_alias(const google_protobuf_EnumOptions* msg) { const upb_MiniTableField field = {2, 1, 1, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_EnumOptions_clear_deprecated(google_protobuf_EnumOptions* msg) { const upb_MiniTableField field = {3, 2, 2, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; @@ -4557,7 +4557,7 @@ UPB_INLINE bool google_protobuf_EnumOptions_deprecated(const google_protobuf_Enu } UPB_INLINE bool google_protobuf_EnumOptions_has_deprecated(const google_protobuf_EnumOptions* msg) { const upb_MiniTableField field = {3, 2, 2, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_EnumOptions_clear_deprecated_legacy_json_field_conflicts(google_protobuf_EnumOptions* msg) { const upb_MiniTableField field = {6, 3, 3, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; @@ -4573,7 +4573,7 @@ UPB_INLINE bool google_protobuf_EnumOptions_deprecated_legacy_json_field_conflic } UPB_INLINE bool google_protobuf_EnumOptions_has_deprecated_legacy_json_field_conflicts(const google_protobuf_EnumOptions* msg) { const upb_MiniTableField field = {6, 3, 3, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_EnumOptions_clear_features(google_protobuf_EnumOptions* msg) { const upb_MiniTableField field = {7, UPB_SIZE(4, 8), 4, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -4589,7 +4589,7 @@ UPB_INLINE const google_protobuf_FeatureSet* google_protobuf_EnumOptions_feature } UPB_INLINE bool google_protobuf_EnumOptions_has_features(const google_protobuf_EnumOptions* msg) { const upb_MiniTableField field = {7, UPB_SIZE(4, 8), 4, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_EnumOptions_clear_uninterpreted_option(google_protobuf_EnumOptions* msg) { const upb_MiniTableField field = {999, UPB_SIZE(8, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -4729,7 +4729,7 @@ UPB_INLINE bool google_protobuf_EnumValueOptions_deprecated(const google_protobu } UPB_INLINE bool google_protobuf_EnumValueOptions_has_deprecated(const google_protobuf_EnumValueOptions* msg) { const upb_MiniTableField field = {1, 1, 1, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_EnumValueOptions_clear_features(google_protobuf_EnumValueOptions* msg) { const upb_MiniTableField field = {2, UPB_SIZE(4, 8), 2, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -4745,7 +4745,7 @@ UPB_INLINE const google_protobuf_FeatureSet* google_protobuf_EnumValueOptions_fe } UPB_INLINE bool google_protobuf_EnumValueOptions_has_features(const google_protobuf_EnumValueOptions* msg) { const upb_MiniTableField field = {2, UPB_SIZE(4, 8), 2, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_EnumValueOptions_clear_debug_redact(google_protobuf_EnumValueOptions* msg) { const upb_MiniTableField field = {3, UPB_SIZE(8, 2), 3, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; @@ -4761,7 +4761,7 @@ UPB_INLINE bool google_protobuf_EnumValueOptions_debug_redact(const google_proto } UPB_INLINE bool google_protobuf_EnumValueOptions_has_debug_redact(const google_protobuf_EnumValueOptions* msg) { const upb_MiniTableField field = {3, UPB_SIZE(8, 2), 3, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_EnumValueOptions_clear_uninterpreted_option(google_protobuf_EnumValueOptions* msg) { const upb_MiniTableField field = {999, UPB_SIZE(12, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -4897,7 +4897,7 @@ UPB_INLINE bool google_protobuf_ServiceOptions_deprecated(const google_protobuf_ } UPB_INLINE bool google_protobuf_ServiceOptions_has_deprecated(const google_protobuf_ServiceOptions* msg) { const upb_MiniTableField field = {33, 1, 1, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_ServiceOptions_clear_features(google_protobuf_ServiceOptions* msg) { const upb_MiniTableField field = {34, UPB_SIZE(4, 8), 2, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -4913,7 +4913,7 @@ UPB_INLINE const google_protobuf_FeatureSet* google_protobuf_ServiceOptions_feat } UPB_INLINE bool google_protobuf_ServiceOptions_has_features(const google_protobuf_ServiceOptions* msg) { const upb_MiniTableField field = {34, UPB_SIZE(4, 8), 2, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_ServiceOptions_clear_uninterpreted_option(google_protobuf_ServiceOptions* msg) { const upb_MiniTableField field = {999, UPB_SIZE(8, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -5045,7 +5045,7 @@ UPB_INLINE bool google_protobuf_MethodOptions_deprecated(const google_protobuf_M } UPB_INLINE bool google_protobuf_MethodOptions_has_deprecated(const google_protobuf_MethodOptions* msg) { const upb_MiniTableField field = {33, 1, 1, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_MethodOptions_clear_idempotency_level(google_protobuf_MethodOptions* msg) { const upb_MiniTableField field = {34, 4, 2, 2, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; @@ -5061,7 +5061,7 @@ UPB_INLINE int32_t google_protobuf_MethodOptions_idempotency_level(const google_ } UPB_INLINE bool google_protobuf_MethodOptions_has_idempotency_level(const google_protobuf_MethodOptions* msg) { const upb_MiniTableField field = {34, 4, 2, 2, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_MethodOptions_clear_features(google_protobuf_MethodOptions* msg) { const upb_MiniTableField field = {35, 8, 3, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -5077,7 +5077,7 @@ UPB_INLINE const google_protobuf_FeatureSet* google_protobuf_MethodOptions_featu } UPB_INLINE bool google_protobuf_MethodOptions_has_features(const google_protobuf_MethodOptions* msg) { const upb_MiniTableField field = {35, 8, 3, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_MethodOptions_clear_uninterpreted_option(google_protobuf_MethodOptions* msg) { const upb_MiniTableField field = {999, UPB_SIZE(12, 16), 0, 1, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -5245,7 +5245,7 @@ UPB_INLINE upb_StringView google_protobuf_UninterpretedOption_identifier_value(c } UPB_INLINE bool google_protobuf_UninterpretedOption_has_identifier_value(const google_protobuf_UninterpretedOption* msg) { const upb_MiniTableField field = {3, UPB_SIZE(8, 16), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_UninterpretedOption_clear_positive_int_value(google_protobuf_UninterpretedOption* msg) { const upb_MiniTableField field = {4, UPB_SIZE(16, 32), 2, kUpb_NoSub, 4, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_8Byte << kUpb_FieldRep_Shift)}; @@ -5261,7 +5261,7 @@ UPB_INLINE uint64_t google_protobuf_UninterpretedOption_positive_int_value(const } UPB_INLINE bool google_protobuf_UninterpretedOption_has_positive_int_value(const google_protobuf_UninterpretedOption* msg) { const upb_MiniTableField field = {4, UPB_SIZE(16, 32), 2, kUpb_NoSub, 4, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_8Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_UninterpretedOption_clear_negative_int_value(google_protobuf_UninterpretedOption* msg) { const upb_MiniTableField field = {5, UPB_SIZE(24, 40), 3, kUpb_NoSub, 3, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_8Byte << kUpb_FieldRep_Shift)}; @@ -5277,7 +5277,7 @@ UPB_INLINE int64_t google_protobuf_UninterpretedOption_negative_int_value(const } UPB_INLINE bool google_protobuf_UninterpretedOption_has_negative_int_value(const google_protobuf_UninterpretedOption* msg) { const upb_MiniTableField field = {5, UPB_SIZE(24, 40), 3, kUpb_NoSub, 3, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_8Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_UninterpretedOption_clear_double_value(google_protobuf_UninterpretedOption* msg) { const upb_MiniTableField field = {6, UPB_SIZE(32, 48), 4, kUpb_NoSub, 1, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_8Byte << kUpb_FieldRep_Shift)}; @@ -5293,7 +5293,7 @@ UPB_INLINE double google_protobuf_UninterpretedOption_double_value(const google_ } UPB_INLINE bool google_protobuf_UninterpretedOption_has_double_value(const google_protobuf_UninterpretedOption* msg) { const upb_MiniTableField field = {6, UPB_SIZE(32, 48), 4, kUpb_NoSub, 1, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_8Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_UninterpretedOption_clear_string_value(google_protobuf_UninterpretedOption* msg) { const upb_MiniTableField field = {7, UPB_SIZE(40, 56), 5, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; @@ -5309,7 +5309,7 @@ UPB_INLINE upb_StringView google_protobuf_UninterpretedOption_string_value(const } UPB_INLINE bool google_protobuf_UninterpretedOption_has_string_value(const google_protobuf_UninterpretedOption* msg) { const upb_MiniTableField field = {7, UPB_SIZE(40, 56), 5, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_UninterpretedOption_clear_aggregate_value(google_protobuf_UninterpretedOption* msg) { const upb_MiniTableField field = {8, UPB_SIZE(48, 72), 6, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; @@ -5325,7 +5325,7 @@ UPB_INLINE upb_StringView google_protobuf_UninterpretedOption_aggregate_value(co } UPB_INLINE bool google_protobuf_UninterpretedOption_has_aggregate_value(const google_protobuf_UninterpretedOption* msg) { const upb_MiniTableField field = {8, UPB_SIZE(48, 72), 6, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE google_protobuf_UninterpretedOption_NamePart** google_protobuf_UninterpretedOption_mutable_name(google_protobuf_UninterpretedOption* msg, size_t* size) { @@ -5433,7 +5433,7 @@ UPB_INLINE upb_StringView google_protobuf_UninterpretedOption_NamePart_name_part } UPB_INLINE bool google_protobuf_UninterpretedOption_NamePart_has_name_part(const google_protobuf_UninterpretedOption_NamePart* msg) { const upb_MiniTableField field = {1, UPB_SIZE(4, 8), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_UninterpretedOption_NamePart_clear_is_extension(google_protobuf_UninterpretedOption_NamePart* msg) { const upb_MiniTableField field = {2, 1, 2, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; @@ -5449,7 +5449,7 @@ UPB_INLINE bool google_protobuf_UninterpretedOption_NamePart_is_extension(const } UPB_INLINE bool google_protobuf_UninterpretedOption_NamePart_has_is_extension(const google_protobuf_UninterpretedOption_NamePart* msg) { const upb_MiniTableField field = {2, 1, 2, kUpb_NoSub, 8, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_UninterpretedOption_NamePart_set_name_part(google_protobuf_UninterpretedOption_NamePart *msg, upb_StringView value) { @@ -5511,7 +5511,7 @@ UPB_INLINE int32_t google_protobuf_FeatureSet_field_presence(const google_protob } UPB_INLINE bool google_protobuf_FeatureSet_has_field_presence(const google_protobuf_FeatureSet* msg) { const upb_MiniTableField field = {1, 4, 1, 0, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FeatureSet_clear_enum_type(google_protobuf_FeatureSet* msg) { const upb_MiniTableField field = {2, 8, 2, 1, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; @@ -5527,7 +5527,7 @@ UPB_INLINE int32_t google_protobuf_FeatureSet_enum_type(const google_protobuf_Fe } UPB_INLINE bool google_protobuf_FeatureSet_has_enum_type(const google_protobuf_FeatureSet* msg) { const upb_MiniTableField field = {2, 8, 2, 1, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FeatureSet_clear_repeated_field_encoding(google_protobuf_FeatureSet* msg) { const upb_MiniTableField field = {3, 12, 3, 2, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; @@ -5543,7 +5543,7 @@ UPB_INLINE int32_t google_protobuf_FeatureSet_repeated_field_encoding(const goog } UPB_INLINE bool google_protobuf_FeatureSet_has_repeated_field_encoding(const google_protobuf_FeatureSet* msg) { const upb_MiniTableField field = {3, 12, 3, 2, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FeatureSet_clear_utf8_validation(google_protobuf_FeatureSet* msg) { const upb_MiniTableField field = {4, 16, 4, 3, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; @@ -5559,7 +5559,7 @@ UPB_INLINE int32_t google_protobuf_FeatureSet_utf8_validation(const google_proto } UPB_INLINE bool google_protobuf_FeatureSet_has_utf8_validation(const google_protobuf_FeatureSet* msg) { const upb_MiniTableField field = {4, 16, 4, 3, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FeatureSet_clear_message_encoding(google_protobuf_FeatureSet* msg) { const upb_MiniTableField field = {5, 20, 5, 4, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; @@ -5575,7 +5575,7 @@ UPB_INLINE int32_t google_protobuf_FeatureSet_message_encoding(const google_prot } UPB_INLINE bool google_protobuf_FeatureSet_has_message_encoding(const google_protobuf_FeatureSet* msg) { const upb_MiniTableField field = {5, 20, 5, 4, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FeatureSet_clear_json_format(google_protobuf_FeatureSet* msg) { const upb_MiniTableField field = {6, 24, 6, 5, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; @@ -5591,7 +5591,7 @@ UPB_INLINE int32_t google_protobuf_FeatureSet_json_format(const google_protobuf_ } UPB_INLINE bool google_protobuf_FeatureSet_has_json_format(const google_protobuf_FeatureSet* msg) { const upb_MiniTableField field = {6, 24, 6, 5, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FeatureSet_set_field_presence(google_protobuf_FeatureSet *msg, int32_t value) { @@ -5701,7 +5701,7 @@ UPB_INLINE int32_t google_protobuf_FeatureSetDefaults_minimum_edition(const goog } UPB_INLINE bool google_protobuf_FeatureSetDefaults_has_minimum_edition(const google_protobuf_FeatureSetDefaults* msg) { const upb_MiniTableField field = {4, UPB_SIZE(8, 4), 1, 1, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FeatureSetDefaults_clear_maximum_edition(google_protobuf_FeatureSetDefaults* msg) { const upb_MiniTableField field = {5, UPB_SIZE(12, 8), 2, 2, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; @@ -5717,7 +5717,7 @@ UPB_INLINE int32_t google_protobuf_FeatureSetDefaults_maximum_edition(const goog } UPB_INLINE bool google_protobuf_FeatureSetDefaults_has_maximum_edition(const google_protobuf_FeatureSetDefaults* msg) { const upb_MiniTableField field = {5, UPB_SIZE(12, 8), 2, 2, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault** google_protobuf_FeatureSetDefaults_mutable_defaults(google_protobuf_FeatureSetDefaults* msg, size_t* size) { @@ -5809,7 +5809,7 @@ UPB_INLINE const google_protobuf_FeatureSet* google_protobuf_FeatureSetDefaults_ } UPB_INLINE bool google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_has_features(const google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* msg) { const upb_MiniTableField field = {2, UPB_SIZE(4, 8), 1, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_clear_edition(google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* msg) { const upb_MiniTableField field = {3, UPB_SIZE(8, 4), 2, 1, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; @@ -5825,7 +5825,7 @@ UPB_INLINE int32_t google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_e } UPB_INLINE bool google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_has_edition(const google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* msg) { const upb_MiniTableField field = {3, UPB_SIZE(8, 4), 2, 1, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault_set_features(google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault *msg, google_protobuf_FeatureSet* value) { @@ -6059,7 +6059,7 @@ UPB_INLINE upb_StringView google_protobuf_SourceCodeInfo_Location_leading_commen } UPB_INLINE bool google_protobuf_SourceCodeInfo_Location_has_leading_comments(const google_protobuf_SourceCodeInfo_Location* msg) { const upb_MiniTableField field = {3, UPB_SIZE(16, 24), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_SourceCodeInfo_Location_clear_trailing_comments(google_protobuf_SourceCodeInfo_Location* msg) { const upb_MiniTableField field = {4, UPB_SIZE(24, 40), 2, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; @@ -6075,7 +6075,7 @@ UPB_INLINE upb_StringView google_protobuf_SourceCodeInfo_Location_trailing_comme } UPB_INLINE bool google_protobuf_SourceCodeInfo_Location_has_trailing_comments(const google_protobuf_SourceCodeInfo_Location* msg) { const upb_MiniTableField field = {4, UPB_SIZE(24, 40), 2, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_SourceCodeInfo_Location_clear_leading_detached_comments(google_protobuf_SourceCodeInfo_Location* msg) { const upb_MiniTableField field = {6, UPB_SIZE(12, 56), 0, kUpb_NoSub, 12, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsAlternate | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)}; @@ -6385,7 +6385,7 @@ UPB_INLINE upb_StringView google_protobuf_GeneratedCodeInfo_Annotation_source_fi } UPB_INLINE bool google_protobuf_GeneratedCodeInfo_Annotation_has_source_file(const google_protobuf_GeneratedCodeInfo_Annotation* msg) { const upb_MiniTableField field = {2, UPB_SIZE(20, 24), 1, kUpb_NoSub, 12, (int)kUpb_FieldMode_Scalar | (int)kUpb_LabelFlags_IsAlternate | ((int)kUpb_FieldRep_StringView << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_GeneratedCodeInfo_Annotation_clear_begin(google_protobuf_GeneratedCodeInfo_Annotation* msg) { const upb_MiniTableField field = {3, UPB_SIZE(8, 4), 2, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; @@ -6401,7 +6401,7 @@ UPB_INLINE int32_t google_protobuf_GeneratedCodeInfo_Annotation_begin(const goog } UPB_INLINE bool google_protobuf_GeneratedCodeInfo_Annotation_has_begin(const google_protobuf_GeneratedCodeInfo_Annotation* msg) { const upb_MiniTableField field = {3, UPB_SIZE(8, 4), 2, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_GeneratedCodeInfo_Annotation_clear_end(google_protobuf_GeneratedCodeInfo_Annotation* msg) { const upb_MiniTableField field = {4, UPB_SIZE(12, 8), 3, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; @@ -6417,7 +6417,7 @@ UPB_INLINE int32_t google_protobuf_GeneratedCodeInfo_Annotation_end(const google } UPB_INLINE bool google_protobuf_GeneratedCodeInfo_Annotation_has_end(const google_protobuf_GeneratedCodeInfo_Annotation* msg) { const upb_MiniTableField field = {4, UPB_SIZE(12, 8), 3, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE void google_protobuf_GeneratedCodeInfo_Annotation_clear_semantic(google_protobuf_GeneratedCodeInfo_Annotation* msg) { const upb_MiniTableField field = {5, UPB_SIZE(16, 12), 4, 0, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; @@ -6433,7 +6433,7 @@ UPB_INLINE int32_t google_protobuf_GeneratedCodeInfo_Annotation_semantic(const g } UPB_INLINE bool google_protobuf_GeneratedCodeInfo_Annotation_has_semantic(const google_protobuf_GeneratedCodeInfo_Annotation* msg) { const upb_MiniTableField field = {5, UPB_SIZE(16, 12), 4, 0, 14, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)}; - return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field); + return upb_Message_HasBaseField(UPB_UPCAST(msg), &field); } UPB_INLINE int32_t* google_protobuf_GeneratedCodeInfo_Annotation_mutable_path(google_protobuf_GeneratedCodeInfo_Annotation* msg, size_t* size) { From d2b8aa7ef2b81afcb0c3fe55387af1e8dfc1ba3e Mon Sep 17 00:00:00 2001 From: Hong Shin Date: Wed, 10 Jan 2024 09:11:51 -0800 Subject: [PATCH 232/255] Make upb::Status final PiperOrigin-RevId: 597268485 --- upb/base/status.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/upb/base/status.hpp b/upb/base/status.hpp index 4d7152b26be8b..23596ddaf5b93 100644 --- a/upb/base/status.hpp +++ b/upb/base/status.hpp @@ -12,7 +12,7 @@ namespace upb { -class Status { +class Status final { public: Status() { upb_Status_Clear(&status_); } From b0d5ed8b08cf1535128469bd448a79f29f790787 Mon Sep 17 00:00:00 2001 From: Eric Salo Date: Wed, 10 Jan 2024 09:56:02 -0800 Subject: [PATCH 233/255] upb: normalize some more function names PiperOrigin-RevId: 597279852 --- upb/message/internal/accessors.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/upb/message/internal/accessors.h b/upb/message/internal/accessors.h index af1893ca18685..719da4f2ae178 100644 --- a/upb/message/internal/accessors.h +++ b/upb/message/internal/accessors.h @@ -111,12 +111,12 @@ UPB_INLINE bool UPB_PRIVATE(_upb_Message_ClearOneofCase)( // LINT.ThenChange(GoogleInternalName2) -UPB_INLINE void* UPB_PRIVATE(_upb_Message_DataPtr)( +UPB_INLINE void* UPB_PRIVATE(_upb_Message_MutableDataPtr)( struct upb_Message* msg, const upb_MiniTableField* f) { return (char*)msg + f->UPB_ONLYBITS(offset); } -UPB_INLINE const void* UPB_PRIVATE(_upb_Message_ConstDataPtr)( +UPB_INLINE const void* UPB_PRIVATE(_upb_Message_DataPtr)( const struct upb_Message* msg, const upb_MiniTableField* f) { return (const char*)msg + f->UPB_ONLYBITS(offset); } @@ -242,7 +242,7 @@ static UPB_FORCEINLINE void _upb_Message_GetNonExtensionField( return; } UPB_PRIVATE(_upb_MiniTableField_DataCopy) - (field, val, UPB_PRIVATE(_upb_Message_ConstDataPtr)(msg, field)); + (field, val, UPB_PRIVATE(_upb_Message_DataPtr)(msg, field)); } UPB_INLINE void _upb_Message_GetExtensionField( @@ -290,7 +290,7 @@ UPB_INLINE void _upb_Message_SetNonExtensionField( UPB_ASSUME(!upb_MiniTableField_IsExtension(field)); UPB_PRIVATE(_upb_Message_SetPresence)(msg, field); UPB_PRIVATE(_upb_MiniTableField_DataCopy) - (field, UPB_PRIVATE(_upb_Message_DataPtr)(msg, field), val); + (field, UPB_PRIVATE(_upb_Message_MutableDataPtr)(msg, field), val); } UPB_INLINE bool _upb_Message_SetExtensionField( @@ -315,7 +315,7 @@ UPB_INLINE void UPB_PRIVATE(_upb_Message_ClearBaseField)( } const char zeros[16] = {0}; UPB_PRIVATE(_upb_MiniTableField_DataCopy) - (f, UPB_PRIVATE(_upb_Message_DataPtr)(msg, f), zeros); + (f, UPB_PRIVATE(_upb_Message_MutableDataPtr)(msg, f), zeros); } UPB_INLINE void UPB_PRIVATE(_upb_Message_ClearExtension)( From 9bee747dcfd5a4cb97786d29e67d13bfb54e7abd Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Wed, 10 Jan 2024 18:09:23 +0000 Subject: [PATCH 234/255] Auto-generate files after cl/597279852 --- php/ext/google/protobuf/php-upb.h | 10 +++++----- ruby/ext/google/protobuf_c/ruby-upb.h | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/php/ext/google/protobuf/php-upb.h b/php/ext/google/protobuf/php-upb.h index a9c187123b1fe..00303e5fe553c 100644 --- a/php/ext/google/protobuf/php-upb.h +++ b/php/ext/google/protobuf/php-upb.h @@ -2460,12 +2460,12 @@ UPB_INLINE bool UPB_PRIVATE(_upb_Message_ClearOneofCase)( // LINT.ThenChange(GoogleInternalName2) -UPB_INLINE void* UPB_PRIVATE(_upb_Message_DataPtr)( +UPB_INLINE void* UPB_PRIVATE(_upb_Message_MutableDataPtr)( struct upb_Message* msg, const upb_MiniTableField* f) { return (char*)msg + f->UPB_ONLYBITS(offset); } -UPB_INLINE const void* UPB_PRIVATE(_upb_Message_ConstDataPtr)( +UPB_INLINE const void* UPB_PRIVATE(_upb_Message_DataPtr)( const struct upb_Message* msg, const upb_MiniTableField* f) { return (const char*)msg + f->UPB_ONLYBITS(offset); } @@ -2591,7 +2591,7 @@ static UPB_FORCEINLINE void _upb_Message_GetNonExtensionField( return; } UPB_PRIVATE(_upb_MiniTableField_DataCopy) - (field, val, UPB_PRIVATE(_upb_Message_ConstDataPtr)(msg, field)); + (field, val, UPB_PRIVATE(_upb_Message_DataPtr)(msg, field)); } UPB_INLINE void _upb_Message_GetExtensionField( @@ -2639,7 +2639,7 @@ UPB_INLINE void _upb_Message_SetNonExtensionField( UPB_ASSUME(!upb_MiniTableField_IsExtension(field)); UPB_PRIVATE(_upb_Message_SetPresence)(msg, field); UPB_PRIVATE(_upb_MiniTableField_DataCopy) - (field, UPB_PRIVATE(_upb_Message_DataPtr)(msg, field), val); + (field, UPB_PRIVATE(_upb_Message_MutableDataPtr)(msg, field), val); } UPB_INLINE bool _upb_Message_SetExtensionField( @@ -2664,7 +2664,7 @@ UPB_INLINE void UPB_PRIVATE(_upb_Message_ClearBaseField)( } const char zeros[16] = {0}; UPB_PRIVATE(_upb_MiniTableField_DataCopy) - (f, UPB_PRIVATE(_upb_Message_DataPtr)(msg, f), zeros); + (f, UPB_PRIVATE(_upb_Message_MutableDataPtr)(msg, f), zeros); } UPB_INLINE void UPB_PRIVATE(_upb_Message_ClearExtension)( diff --git a/ruby/ext/google/protobuf_c/ruby-upb.h b/ruby/ext/google/protobuf_c/ruby-upb.h index fb51f5f9b1083..584acf1ead661 100755 --- a/ruby/ext/google/protobuf_c/ruby-upb.h +++ b/ruby/ext/google/protobuf_c/ruby-upb.h @@ -2462,12 +2462,12 @@ UPB_INLINE bool UPB_PRIVATE(_upb_Message_ClearOneofCase)( // LINT.ThenChange(GoogleInternalName2) -UPB_INLINE void* UPB_PRIVATE(_upb_Message_DataPtr)( +UPB_INLINE void* UPB_PRIVATE(_upb_Message_MutableDataPtr)( struct upb_Message* msg, const upb_MiniTableField* f) { return (char*)msg + f->UPB_ONLYBITS(offset); } -UPB_INLINE const void* UPB_PRIVATE(_upb_Message_ConstDataPtr)( +UPB_INLINE const void* UPB_PRIVATE(_upb_Message_DataPtr)( const struct upb_Message* msg, const upb_MiniTableField* f) { return (const char*)msg + f->UPB_ONLYBITS(offset); } @@ -2593,7 +2593,7 @@ static UPB_FORCEINLINE void _upb_Message_GetNonExtensionField( return; } UPB_PRIVATE(_upb_MiniTableField_DataCopy) - (field, val, UPB_PRIVATE(_upb_Message_ConstDataPtr)(msg, field)); + (field, val, UPB_PRIVATE(_upb_Message_DataPtr)(msg, field)); } UPB_INLINE void _upb_Message_GetExtensionField( @@ -2641,7 +2641,7 @@ UPB_INLINE void _upb_Message_SetNonExtensionField( UPB_ASSUME(!upb_MiniTableField_IsExtension(field)); UPB_PRIVATE(_upb_Message_SetPresence)(msg, field); UPB_PRIVATE(_upb_MiniTableField_DataCopy) - (field, UPB_PRIVATE(_upb_Message_DataPtr)(msg, field), val); + (field, UPB_PRIVATE(_upb_Message_MutableDataPtr)(msg, field), val); } UPB_INLINE bool _upb_Message_SetExtensionField( @@ -2666,7 +2666,7 @@ UPB_INLINE void UPB_PRIVATE(_upb_Message_ClearBaseField)( } const char zeros[16] = {0}; UPB_PRIVATE(_upb_MiniTableField_DataCopy) - (f, UPB_PRIVATE(_upb_Message_DataPtr)(msg, f), zeros); + (f, UPB_PRIVATE(_upb_Message_MutableDataPtr)(msg, f), zeros); } UPB_INLINE void UPB_PRIVATE(_upb_Message_ClearExtension)( From 33080e9917e2e09455bb19603b1d833a2e59ee7c Mon Sep 17 00:00:00 2001 From: Eric Salo Date: Wed, 10 Jan 2024 11:36:27 -0800 Subject: [PATCH 235/255] upb: disable the Fast Table CI tests on GH PiperOrigin-RevId: 597310347 --- .github/workflows/test_upb.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test_upb.yml b/.github/workflows/test_upb.yml index a6d7f194189bb..cb854564485f6 100644 --- a/.github/workflows/test_upb.yml +++ b/.github/workflows/test_upb.yml @@ -20,12 +20,11 @@ jobs: - { name: "Bazel 7", bazel_version: "7.0.0" } - { name: "Fastbuild" } - { name: "Optimized", flags: "-c opt" } - - { name: "FastTable", flags: "--//upb:fasttable_enabled=true" } - - { name: "FastTable ASAN", flags: "--//upb:fasttable_enabled=true --config=asan", exclude-targets: "-//benchmarks:benchmark -//python/..." } - { name: "ASAN", flags: "--config=asan -c dbg", exclude-targets: "-//benchmarks:benchmark -//python/..." } - { name: "UBSAN", flags: "--config=ubsan -c dbg", exclude-targets: "-//benchmarks:benchmark -//python/... -//lua/..." } - { name: "32-bit", flags: "--copt=-m32 --linkopt=-m32", exclude-targets: "-//benchmarks:benchmark -//python/..." } - # TODO: b/297027295 - Add 32-bit ASAN test + # TODO: Add 32-bit ASAN test + # TODO: Restore the FastTable tests name: ${{ matrix.config.name }} runs-on: ubuntu-latest From 36d344b63fc291b3b758011ba7245df794271c4b Mon Sep 17 00:00:00 2001 From: Marcel Hlopko Date: Wed, 10 Jan 2024 12:40:24 -0800 Subject: [PATCH 236/255] Automated rollback of commit 0ce457f6e7c15e2574d69ba445ea6cae7e6e44e8. PiperOrigin-RevId: 597327159 --- protos/protos.h | 20 ------- protos_generator/tests/test_generated.cc | 41 -------------- upb/message/internal/accessors.h | 26 --------- upb/message/promote.c | 72 ++++-------------------- upb/message/promote.h | 9 --- upb/message/test.cc | 7 --- upb_generator/protoc-gen-upb.cc | 30 +--------- 7 files changed, 14 insertions(+), 191 deletions(-) diff --git a/protos/protos.h b/protos/protos.h index c1701f0807064..db06de80fd7bc 100644 --- a/protos/protos.h +++ b/protos/protos.h @@ -18,7 +18,6 @@ #include "upb/message/copy.h" #include "upb/message/internal/accessors.h" #include "upb/message/internal/extension.h" -#include "upb/message/promote.h" #include "upb/mini_table/extension.h" #include "upb/wire/decode.h" #include "upb/wire/encode.h" @@ -430,25 +429,6 @@ absl::StatusOr> GetExtension( return GetExtension(protos::Ptr(message), id); } -template , typename = EnableIfMutableProto> -absl::StatusOr> MutableExtension( - Ptr message, - const ::protos::internal::ExtensionIdentifier& id) { - upb_Arena* arena = ::protos::internal::GetArena(message); - upb_Extension* ext; - upb_GetExtension_Status status = upb_MiniTable_GetOrPromoteOrCreateExtension( - internal::GetInternalMsg(message), id.mini_table_ext(), 0, arena, &ext); - if (status == kUpb_GetExtension_OutOfMemory) { - return MessageAllocationError(); - } else if (status != kUpb_GetExtension_Ok) { - return ExtensionNotFoundError( - upb_MiniTableExtension_Number(id.mini_table_ext())); - } - return Ptr(::protos::internal::CreateMessageProxy( - static_cast(ext->data.ptr), arena)); -} - template ABSL_MUST_USE_RESULT bool Parse(Ptr message, absl::string_view bytes) { static_assert(!std::is_const_v); diff --git a/protos_generator/tests/test_generated.cc b/protos_generator/tests/test_generated.cc index 7639faad249c0..ffa3d5cb8de47 100644 --- a/protos_generator/tests/test_generated.cc +++ b/protos_generator/tests/test_generated.cc @@ -824,47 +824,6 @@ TEST(CppGeneratedCode, GetExtensionOnImmutableChild) { ::protos::GetExtension(recursive_child, theme).value()->ext_name()); } -TEST(CppGeneratedCode, MutableExtension) { - ::protos::Arena arena; - ::protos::Ptr model = ::protos::CreateMessage(arena); - EXPECT_EQ(false, ::protos::HasExtension(model, theme)); - absl::StatusOr<::protos::Ptr> extension1 = - ::protos::MutableExtension(model, theme); - EXPECT_EQ(true, extension1.ok()); - (*extension1)->set_ext_name("Hello World"); - EXPECT_EQ("Hello World", - ::protos::GetExtension(model, theme).value()->ext_name()); -} - -TEST(CppGeneratedCode, MutableExtensionOnMutableChild) { - TestModel model; - ::protos::Ptr mutable_recursive_child = - model.mutable_recursive_child(); - EXPECT_EQ(false, ::protos::HasExtension(mutable_recursive_child, theme)); - absl::StatusOr<::protos::Ptr> extension1 = - ::protos::MutableExtension(mutable_recursive_child, theme); - EXPECT_EQ(true, extension1.ok()); - (*extension1)->set_ext_name("Hello World"); - EXPECT_EQ("Hello World", - ::protos::GetExtension(mutable_recursive_child, theme) - .value() - ->ext_name()); -} - -TEST(CppGeneratedCode, MutableExtensionOnImmutableChild) { - TestModel model; - ::protos::Ptr mutable_recursive_child = - model.mutable_recursive_child(); - EXPECT_EQ(false, ::protos::HasExtension(mutable_recursive_child, theme)); - absl::StatusOr<::protos::Ptr> extension1 = - ::protos::MutableExtension(mutable_recursive_child, theme); - EXPECT_EQ(true, extension1.ok()); - (*extension1)->set_ext_name("Hello World"); - ::protos::Ptr recursive_child = model.recursive_child(); - EXPECT_EQ("Hello World", - ::protos::GetExtension(recursive_child, theme).value()->ext_name()); -} - TEST(CppGeneratedCode, SerializeUsingArena) { TestModel model; model.set_str1("Hello World"); diff --git a/upb/message/internal/accessors.h b/upb/message/internal/accessors.h index 719da4f2ae178..ba48ba60a2184 100644 --- a/upb/message/internal/accessors.h +++ b/upb/message/internal/accessors.h @@ -259,32 +259,6 @@ UPB_INLINE void _upb_Message_GetExtensionField( } } -// Gets a extension message or creates a default message and sets the extension -// if it doesn't already exist. -UPB_INLINE bool _upb_Message_GetOrCreateExtensionSubmessage( - struct upb_Message* msg, const upb_MiniTableExtension* mt_ext, - struct upb_Message** val, upb_Arena* a) { - const upb_MiniTableField* f = &mt_ext->UPB_PRIVATE(field); - UPB_ASSUME(upb_MiniTableField_IsExtension(f)); - const struct upb_Extension* const_ext = _upb_Message_Getext(msg, mt_ext); - if (const_ext) { - // Extension exists, get a mutable version of it. - struct upb_Extension* ext = - _upb_Message_GetOrCreateExtension(msg, mt_ext, a); - *val = (struct upb_Message*)ext->data.ptr; - return true; - } - // Extension doesn't exist, create a new message and set it. - struct upb_Message* ext_msg = - _upb_Message_New(upb_MiniTableExtension_GetSubMessage(mt_ext), a); - if (!ext_msg) return false; - struct upb_Extension* ext = _upb_Message_GetOrCreateExtension(msg, mt_ext, a); - if (!ext) return false; - ext->data.ptr = ext_msg; - *val = ext_msg; - return true; -} - UPB_INLINE void _upb_Message_SetNonExtensionField( struct upb_Message* msg, const upb_MiniTableField* field, const void* val) { UPB_ASSUME(!upb_MiniTableField_IsExtension(field)); diff --git a/upb/message/promote.c b/upb/message/promote.c index 27a9e1e6b03c2..2cd0888c83e57 100644 --- a/upb/message/promote.c +++ b/upb/message/promote.c @@ -64,11 +64,17 @@ static upb_UnknownToMessageRet upb_MiniTable_ParseUnknownMessage( return ret; } -// Promotes unknown data to an extension by finding the field number in unknown -// data and decoding it. -static upb_GetExtension_Status upb_MiniTable_PromoteExtension( +upb_GetExtension_Status upb_MiniTable_GetOrPromoteExtension( upb_Message* msg, const upb_MiniTableExtension* ext_table, - int decode_options, upb_Arena* arena, upb_Extension** extension) { + int decode_options, upb_Arena* arena, const upb_Extension** extension) { + UPB_ASSERT(upb_MiniTableField_CType(upb_MiniTableExtension_AsField( + ext_table)) == kUpb_CType_Message); + *extension = _upb_Message_Getext(msg, ext_table); + if (*extension) { + return kUpb_GetExtension_Ok; + } + + // Check unknown fields, if available promote. int field_number = upb_MiniTableExtension_Number(ext_table); upb_FindUnknownRet result = upb_Message_FindUnknown(msg, field_number, 0); if (result.status != kUpb_FindUnknown_Ok) { @@ -92,73 +98,19 @@ static upb_GetExtension_Status upb_MiniTable_PromoteExtension( case kUpb_UnknownToMessage_Ok: break; } + upb_Message* extension_msg = parse_result.message; // Add to extensions. upb_Extension* ext = _upb_Message_GetOrCreateExtension(msg, ext_table, arena); if (!ext) { return kUpb_GetExtension_OutOfMemory; } - ext->data.ptr = parse_result.message; + memcpy(&ext->data, &extension_msg, sizeof(extension_msg)); *extension = ext; const char* delete_ptr = upb_Message_GetUnknown(msg, &len) + ofs; upb_Message_DeleteUnknown(msg, delete_ptr, result.len); return kUpb_GetExtension_Ok; } -upb_GetExtension_Status upb_MiniTable_GetOrPromoteExtension( - upb_Message* msg, const upb_MiniTableExtension* ext_table, - int decode_options, upb_Arena* arena, const upb_Extension** extension) { - UPB_ASSERT(upb_MiniTableField_CType(upb_MiniTableExtension_AsField( - ext_table)) == kUpb_CType_Message); - *extension = _upb_Message_Getext(msg, ext_table); - if (*extension) { - return kUpb_GetExtension_Ok; - } - - // Check unknown fields, if available promote. - upb_Extension* ext; - upb_GetExtension_Status promote_result = upb_MiniTable_PromoteExtension( - msg, ext_table, decode_options, arena, &ext); - if (promote_result == kUpb_GetExtension_Ok) { - *extension = ext; - } - return promote_result; -} - -upb_GetExtension_Status upb_MiniTable_GetOrPromoteOrCreateExtension( - upb_Message* msg, const upb_MiniTableExtension* ext_table, - int decode_options, upb_Arena* arena, upb_Extension** extension) { - UPB_ASSERT(upb_MiniTableField_CType(upb_MiniTableExtension_AsField( - ext_table)) == kUpb_CType_Message); - const upb_Extension* const_extension = _upb_Message_Getext(msg, ext_table); - if (const_extension) { - // Extension exists on the message, get the mutable version of it. - *extension = _upb_Message_GetOrCreateExtension(msg, ext_table, arena); - return kUpb_GetExtension_Ok; - } - - // Check unknown fields, if available promote. - upb_GetExtension_Status promote_result = upb_MiniTable_PromoteExtension( - msg, ext_table, decode_options, arena, extension); - if (promote_result != kUpb_GetExtension_NotPresent) { - return promote_result; - } - - // Extension not found, create a new default message. - const upb_MiniTable* extension_table = - upb_MiniTableExtension_GetSubMessage(ext_table); - upb_Message* extension_msg = upb_Message_New(extension_table, arena); - if (!extension_msg) { - return kUpb_GetExtension_OutOfMemory; - } - upb_Extension* ext = _upb_Message_GetOrCreateExtension(msg, ext_table, arena); - if (!ext) { - return kUpb_GetExtension_OutOfMemory; - } - ext->data.ptr = extension_msg; - *extension = ext; - return kUpb_GetExtension_Ok; -} - static upb_FindUnknownRet upb_FindUnknownRet_ParseError(void) { return (upb_FindUnknownRet){.status = kUpb_FindUnknown_ParseError}; } diff --git a/upb/message/promote.h b/upb/message/promote.h index 4eefb06b6e072..0a43f6bf708c5 100644 --- a/upb/message/promote.h +++ b/upb/message/promote.h @@ -42,15 +42,6 @@ upb_GetExtension_Status upb_MiniTable_GetOrPromoteExtension( upb_Message* msg, const upb_MiniTableExtension* ext_table, int decode_options, upb_Arena* arena, const upb_Extension** extension); -// Returns a mutable message extension, promotes an unknown field to a mutable -// extension, or creates a new extension. -// -// TODO Only supports extension fields that are messages, -// expand support to include non-message types. -upb_GetExtension_Status upb_MiniTable_GetOrPromoteOrCreateExtension( - upb_Message* msg, const upb_MiniTableExtension* ext_table, - int decode_options, upb_Arena* arena, upb_Extension** extension); - typedef enum { kUpb_FindUnknown_Ok, kUpb_FindUnknown_NotPresent, diff --git a/upb/message/test.cc b/upb/message/test.cc index 5ed84aa57ec1f..2bb46bdaab87b 100644 --- a/upb/message/test.cc +++ b/upb/message/test.cc @@ -104,13 +104,6 @@ TEST(MessageTest, Extensions) { defpool.ptr(), 0, arena.ptr(), status.ptr())) << status.error_message(); VerifyMessage(ext_msg3); - - // Test setters and mutable accessors - upb_test_TestExtensions* ext_msg4 = upb_test_TestExtensions_new(arena.ptr()); - upb_test_TestExtensions_set_optional_int32_ext(ext_msg4, 123, arena.ptr()); - protobuf_test_messages_proto3_TestAllTypesProto3_set_optional_int32( - upb_test_mutable_optional_msg_ext(ext_msg4, arena.ptr()), 456); - VerifyMessage(ext_msg4); } void VerifyMessageSet(const upb_test_TestMessageSet* mset_msg) { diff --git a/upb_generator/protoc-gen-upb.cc b/upb_generator/protoc-gen-upb.cc index 82d254d53069f..047b91bf5e724 100644 --- a/upb_generator/protoc-gen-upb.cc +++ b/upb_generator/protoc-gen-upb.cc @@ -25,7 +25,6 @@ #include "absl/strings/string_view.h" #include "absl/strings/substitute.h" #include "upb/base/descriptor_constants.h" -#include "upb/base/status.hpp" #include "upb/base/string_view.h" #include "upb/mini_table/field.h" #include "upb/reflection/def.hpp" @@ -256,7 +255,7 @@ std::string GetFieldRep(const DefPoolPair& pools, upb::FieldDefPtr field) { } void GenerateExtensionInHeader(const DefPoolPair& pools, upb::FieldDefPtr ext, - const Options& options, Output& output) { + Output& output) { output( R"cc( UPB_INLINE bool $0_has_$1(const struct $2* msg) { @@ -308,31 +307,6 @@ void GenerateExtensionInHeader(const DefPoolPair& pools, upb::FieldDefPtr ext, CTypeConst(ext), ExtensionIdentBase(ext), ext.name(), MessageName(ext.containing_type()), ExtensionLayout(ext), GetFieldRep(pools, ext)); - - // Message extensions also have a Msg_mutable_foo() accessor that will - // create the sub-message if it doesn't already exist. - if (ext.ctype() == kUpb_CType_Message && - !UPB_DESC(MessageOptions_map_entry)(ext.containing_type().options())) { - output( - R"cc( - UPB_INLINE struct $0* $1_mutable_$2(struct $3* msg, - upb_Arena* arena) { - const upb_MiniTableExtension* ext = &$4; - UPB_ASSUME(upb_MiniTableField_IsScalar(&ext->UPB_PRIVATE(field))); - UPB_ASSUME(upb_MiniTableField_IsSubMessage(&ext->UPB_PRIVATE(field))); - UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)( - &ext->UPB_PRIVATE(field)) == $5); - upb_Message* ret; - bool ok = _upb_Message_GetOrCreateExtensionSubmessage( - (upb_Message*)msg, ext, &ret, arena); - if (!ok) return NULL; - return ($0*)ret; - } - )cc", - MessageName(ext.message_type()), ExtensionIdentBase(ext), ext.name(), - MessageName(ext.containing_type()), ExtensionLayout(ext), - GetFieldRep(pools, ext)); - } } } @@ -952,7 +926,7 @@ void WriteHeader(const DefPoolPair& pools, upb::FileDefPtr file, } for (auto ext : this_file_exts) { - GenerateExtensionInHeader(pools, ext, options, output); + GenerateExtensionInHeader(pools, ext, output); } if (absl::string_view(file.name()) == "google/protobuf/descriptor.proto" || From 6820a563e29f82f6b10c7ea3caed7822e7331960 Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Wed, 10 Jan 2024 20:52:41 +0000 Subject: [PATCH 237/255] Auto-generate files after cl/597327159 --- php/ext/google/protobuf/php-upb.h | 26 -------------------------- ruby/ext/google/protobuf_c/ruby-upb.h | 26 -------------------------- 2 files changed, 52 deletions(-) diff --git a/php/ext/google/protobuf/php-upb.h b/php/ext/google/protobuf/php-upb.h index 00303e5fe553c..ae22247b5674f 100644 --- a/php/ext/google/protobuf/php-upb.h +++ b/php/ext/google/protobuf/php-upb.h @@ -2608,32 +2608,6 @@ UPB_INLINE void _upb_Message_GetExtensionField( } } -// Gets a extension message or creates a default message and sets the extension -// if it doesn't already exist. -UPB_INLINE bool _upb_Message_GetOrCreateExtensionSubmessage( - struct upb_Message* msg, const upb_MiniTableExtension* mt_ext, - struct upb_Message** val, upb_Arena* a) { - const upb_MiniTableField* f = &mt_ext->UPB_PRIVATE(field); - UPB_ASSUME(upb_MiniTableField_IsExtension(f)); - const struct upb_Extension* const_ext = _upb_Message_Getext(msg, mt_ext); - if (const_ext) { - // Extension exists, get a mutable version of it. - struct upb_Extension* ext = - _upb_Message_GetOrCreateExtension(msg, mt_ext, a); - *val = (struct upb_Message*)ext->data.ptr; - return true; - } - // Extension doesn't exist, create a new message and set it. - struct upb_Message* ext_msg = - _upb_Message_New(upb_MiniTableExtension_GetSubMessage(mt_ext), a); - if (!ext_msg) return false; - struct upb_Extension* ext = _upb_Message_GetOrCreateExtension(msg, mt_ext, a); - if (!ext) return false; - ext->data.ptr = ext_msg; - *val = ext_msg; - return true; -} - UPB_INLINE void _upb_Message_SetNonExtensionField( struct upb_Message* msg, const upb_MiniTableField* field, const void* val) { UPB_ASSUME(!upb_MiniTableField_IsExtension(field)); diff --git a/ruby/ext/google/protobuf_c/ruby-upb.h b/ruby/ext/google/protobuf_c/ruby-upb.h index 584acf1ead661..433d25c1313c6 100755 --- a/ruby/ext/google/protobuf_c/ruby-upb.h +++ b/ruby/ext/google/protobuf_c/ruby-upb.h @@ -2610,32 +2610,6 @@ UPB_INLINE void _upb_Message_GetExtensionField( } } -// Gets a extension message or creates a default message and sets the extension -// if it doesn't already exist. -UPB_INLINE bool _upb_Message_GetOrCreateExtensionSubmessage( - struct upb_Message* msg, const upb_MiniTableExtension* mt_ext, - struct upb_Message** val, upb_Arena* a) { - const upb_MiniTableField* f = &mt_ext->UPB_PRIVATE(field); - UPB_ASSUME(upb_MiniTableField_IsExtension(f)); - const struct upb_Extension* const_ext = _upb_Message_Getext(msg, mt_ext); - if (const_ext) { - // Extension exists, get a mutable version of it. - struct upb_Extension* ext = - _upb_Message_GetOrCreateExtension(msg, mt_ext, a); - *val = (struct upb_Message*)ext->data.ptr; - return true; - } - // Extension doesn't exist, create a new message and set it. - struct upb_Message* ext_msg = - _upb_Message_New(upb_MiniTableExtension_GetSubMessage(mt_ext), a); - if (!ext_msg) return false; - struct upb_Extension* ext = _upb_Message_GetOrCreateExtension(msg, mt_ext, a); - if (!ext) return false; - ext->data.ptr = ext_msg; - *val = ext_msg; - return true; -} - UPB_INLINE void _upb_Message_SetNonExtensionField( struct upb_Message* msg, const upb_MiniTableField* field, const void* val) { UPB_ASSUME(!upb_MiniTableField_IsExtension(field)); From 686cfc6ab584ea8a646041fe1274aba2d658c65b Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Wed, 10 Jan 2024 13:10:51 -0800 Subject: [PATCH 238/255] Protobuf Java cross-domain Poison Pills. PiperOrigin-RevId: 597335599 --- src/google/protobuf/compiler/java/file.cc | 12 +++---- src/google/protobuf/compiler/java/helpers.cc | 33 +++++++++++-------- src/google/protobuf/compiler/java/helpers.h | 2 +- src/google/protobuf/compiler/java/message.cc | 12 +++---- .../compiler/java/shared_code_generator.cc | 4 +-- 5 files changed, 32 insertions(+), 31 deletions(-) diff --git a/src/google/protobuf/compiler/java/file.cc b/src/google/protobuf/compiler/java/file.cc index 0afaa47f71d75..79ef72b41cbd9 100644 --- a/src/google/protobuf/compiler/java/file.cc +++ b/src/google/protobuf/compiler/java/file.cc @@ -273,13 +273,11 @@ void FileGenerator::Generate(io::Printer* printer) { printer->Annotate("classname", file_->name()); printer->Indent(); - if (options_.opensource_runtime) { - printer->Print("static {\n"); - printer->Indent(); - PrintGencodeVersionValidator(printer); - printer->Outdent(); - printer->Print("}\n"); - } + printer->Print("static {\n"); + printer->Indent(); + PrintGencodeVersionValidator(printer, options_.opensource_runtime); + printer->Outdent(); + printer->Print("}\n"); // ----------------------------------------------------------------- diff --git a/src/google/protobuf/compiler/java/helpers.cc b/src/google/protobuf/compiler/java/helpers.cc index 55b38c1d75711..7f44422124017 100644 --- a/src/google/protobuf/compiler/java/helpers.cc +++ b/src/google/protobuf/compiler/java/helpers.cc @@ -85,19 +85,26 @@ void PrintEnumVerifierLogic( absl::StrCat(enum_verifier_string, terminating_string)); } -void PrintGencodeVersionValidator(io::Printer* printer) { - const auto& version = GetProtobufJavaVersion(); - printer->Print( - "com.google.protobuf.RuntimeVersion.validateProtobufGencodeVersion(\n" - " com.google.protobuf.RuntimeVersion.RuntimeDomain.PUBLIC,\n" - " $major$,\n" - " $minor$,\n" - " $patch$,\n" - " $suffix$);\n", - "major", absl::StrCat("/* major= */ ", version.major()), "minor", - absl::StrCat("/* minor= */ ", version.minor()), "patch", - absl::StrCat("/* patch= */ ", version.patch()), "suffix", - absl::StrCat("/* suffix= */ \"", version.suffix(), "\"")); +void PrintGencodeVersionValidator(io::Printer* printer, bool oss_runtime) { + if (oss_runtime) { + const auto& version = GetProtobufJavaVersion(); + printer->Print( + "com.google.protobuf.RuntimeVersion.validateProtobufGencodeVersion(\n" + " com.google.protobuf.RuntimeVersion.RuntimeDomain.PUBLIC,\n" + " $major$,\n" + " $minor$,\n" + " $patch$,\n" + " $suffix$);\n", + "major", absl::StrCat("/* major= */ ", version.major()), "minor", + absl::StrCat("/* minor= */ ", version.minor()), "patch", + absl::StrCat("/* patch= */ ", version.patch()), "suffix", + absl::StrCat("/* suffix= */ \"", version.suffix(), "\"")); + } else { + printer->Print( + "com.google.protobuf.RuntimeVersion.validateProtobufGencodeDomain(\n" + " " + "com.google.protobuf.RuntimeVersion.RuntimeDomain.GOOGLE_INTERNAL);\n"); + } } std::string UnderscoresToCamelCase(absl::string_view input, diff --git a/src/google/protobuf/compiler/java/helpers.h b/src/google/protobuf/compiler/java/helpers.h index 60f963ac686a1..ab6786446f1fa 100644 --- a/src/google/protobuf/compiler/java/helpers.h +++ b/src/google/protobuf/compiler/java/helpers.h @@ -61,7 +61,7 @@ void PrintEnumVerifierLogic( // Prints the Protobuf Java Version validator checking that the runtime and // gencode versions are compatible. -void PrintGencodeVersionValidator(io::Printer* printer); +void PrintGencodeVersionValidator(io::Printer* printer, bool oss_runtime); // Converts a name to camel-case. If cap_first_letter is true, capitalize the // first letter. diff --git a/src/google/protobuf/compiler/java/message.cc b/src/google/protobuf/compiler/java/message.cc index 08523b0c19a15..04bc3ec9b71f5 100644 --- a/src/google/protobuf/compiler/java/message.cc +++ b/src/google/protobuf/compiler/java/message.cc @@ -341,13 +341,11 @@ void ImmutableMessageGenerator::Generate(io::Printer* printer) { printer->Indent(); - if (context_->options().opensource_runtime) { - printer->Print("static {\n"); - printer->Indent(); - PrintGencodeVersionValidator(printer); - printer->Outdent(); - printer->Print("}\n"); - } + printer->Print("static {\n"); + printer->Indent(); + PrintGencodeVersionValidator(printer, context_->options().opensource_runtime); + printer->Outdent(); + printer->Print("}\n"); // Using builder_type, instead of Builder, prevents the Builder class from // being loaded into PermGen space when the default instance is created. diff --git a/src/google/protobuf/compiler/java/shared_code_generator.cc b/src/google/protobuf/compiler/java/shared_code_generator.cc index ec6deffb3a589..ee837955d7192 100644 --- a/src/google/protobuf/compiler/java/shared_code_generator.cc +++ b/src/google/protobuf/compiler/java/shared_code_generator.cc @@ -94,9 +94,7 @@ void SharedCodeGenerator::Generate( printer->Indent(); printer->Indent(); GenerateDescriptors(printer.get()); - if (options_.opensource_runtime) { - PrintGencodeVersionValidator(printer.get()); - } + PrintGencodeVersionValidator(printer.get(), options_.opensource_runtime); printer->Outdent(); printer->Outdent(); printer->Print( From d4dfb9c4a67e24afa0465735a84a381d0833211d Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Wed, 10 Jan 2024 13:33:51 -0800 Subject: [PATCH 239/255] Add kUpb_DecodeOption_AlwaysValidateUtf8 decode option, to force UTF-8 validation of proto2 strings. PiperOrigin-RevId: 597341799 --- upb/message/BUILD | 21 ++++++- upb/message/utf8_test.cc | 96 ++++++++++++++++++++++++++++++ upb/message/utf8_test.proto | 2 +- upb/message/utf8_test_proto2.proto | 26 ++++++++ upb/wire/decode.c | 11 ++++ upb/wire/decode.h | 10 ++++ 6 files changed, 164 insertions(+), 2 deletions(-) create mode 100644 upb/message/utf8_test_proto2.proto diff --git a/upb/message/BUILD b/upb/message/BUILD index 3212444200a7b..04647a3ebea0c 100644 --- a/upb/message/BUILD +++ b/upb/message/BUILD @@ -304,7 +304,12 @@ proto_library( name = "utf8_test_proto", testonly = 1, srcs = ["utf8_test.proto"], - deps = ["//src/google/protobuf:test_messages_proto3_proto"], +) + +proto_library( + name = "utf8_test_proto2_proto", + testonly = 1, + srcs = ["utf8_test_proto2.proto"], ) upb_minitable_proto_library( @@ -313,16 +318,30 @@ upb_minitable_proto_library( deps = [":utf8_test_proto"], ) +upb_minitable_proto_library( + name = "utf8_test_proto2_upb_minitable_proto", + testonly = 1, + deps = [":utf8_test_proto2_proto"], +) + upb_c_proto_library( name = "utf8_test_upb_proto", testonly = 1, deps = [":utf8_test_proto"], ) +upb_c_proto_library( + name = "utf8_test_proto2_upb_proto", + testonly = 1, + deps = [":utf8_test_proto2_proto"], +) + cc_test( name = "utf8_test", srcs = ["utf8_test.cc"], deps = [ + ":utf8_test_proto2_upb_minitable_proto", + ":utf8_test_proto2_upb_proto", ":utf8_test_upb_minitable_proto", ":utf8_test_upb_proto", "//upb:base", diff --git a/upb/message/utf8_test.cc b/upb/message/utf8_test.cc index b900a954b3a92..cd7dd1737135c 100644 --- a/upb/message/utf8_test.cc +++ b/upb/message/utf8_test.cc @@ -14,6 +14,8 @@ #include "upb/mem/arena.hpp" #include "upb/message/utf8_test.upb.h" #include "upb/message/utf8_test.upb_minitable.h" +#include "upb/message/utf8_test_proto2.upb.h" +#include "upb/message/utf8_test_proto2.upb_minitable.h" #include "upb/wire/decode.h" namespace { @@ -72,6 +74,100 @@ TEST(Utf8Test, RepeatedProto3FieldValidates) { ASSERT_EQ(kUpb_DecodeStatus_BadUtf8, status); } +TEST(Utf8Test, Proto2BytesValidates) { + upb::Arena arena; + size_t size; + char* data = GetBadUtf8Payload(arena.ptr(), &size); + + upb_test_TestUtf8Proto2Bytes* msg = + upb_test_TestUtf8Proto2Bytes_new(arena.ptr()); + + upb_DecodeStatus status; + status = upb_Decode(data, size, UPB_UPCAST(msg), + &upb_0test__TestUtf8Proto2Bytes_msg_init, nullptr, 0, + arena.ptr()); + + // Parse succeeds, because proto2 bytes fields don't validate UTF-8. + ASSERT_EQ(kUpb_DecodeStatus_Ok, status); +} + +TEST(Utf8Test, Proto2RepeatedBytesValidates) { + upb::Arena arena; + size_t size; + char* data = GetBadUtf8Payload(arena.ptr(), &size); + + upb_test_TestUtf8RepeatedProto2Bytes* msg = + upb_test_TestUtf8RepeatedProto2Bytes_new(arena.ptr()); + + upb_DecodeStatus status; + status = upb_Decode(data, size, UPB_UPCAST(msg), + &upb_0test__TestUtf8RepeatedProto2Bytes_msg_init, nullptr, + 0, arena.ptr()); + + // Parse succeeds, because proto2 bytes fields don't validate UTF-8. + ASSERT_EQ(kUpb_DecodeStatus_Ok, status); +} + +TEST(Utf8Test, Proto2StringValidates) { + upb::Arena arena; + size_t size; + char* data = GetBadUtf8Payload(arena.ptr(), &size); + + upb_test_TestUtf8Proto2String* msg = + upb_test_TestUtf8Proto2String_new(arena.ptr()); + + upb_DecodeStatus status; + status = upb_Decode(data, size, UPB_UPCAST(msg), + &upb_0test__TestUtf8Proto2String_msg_init, nullptr, 0, + arena.ptr()); + + // Parse succeeds, because proto2 string fields don't validate UTF-8. + ASSERT_EQ(kUpb_DecodeStatus_Ok, status); +} + +TEST(Utf8Test, Proto2FieldFailsValidation) { + upb::Arena arena; + size_t size; + char* data = GetBadUtf8Payload(arena.ptr(), &size); + + upb_test_TestUtf8Proto2String* msg = + upb_test_TestUtf8Proto2String_new(arena.ptr()); + + upb_DecodeStatus status; + status = upb_Decode(data, size, UPB_UPCAST(msg), + &upb_0test__TestUtf8Proto2String_msg_init, nullptr, 0, + arena.ptr()); + + // Parse fails, because we pass in kUpb_DecodeOption_AlwaysValidateUtf8 to + // force validation of proto2 string fields. + status = upb_Decode(data, size, UPB_UPCAST(msg), + &upb_0test__TestUtf8Proto2String_msg_init, nullptr, + kUpb_DecodeOption_AlwaysValidateUtf8, arena.ptr()); + ASSERT_EQ(kUpb_DecodeStatus_BadUtf8, status); +} + +TEST(Utf8Test, Proto2RepeatedFieldFailsValidation) { + upb::Arena arena; + size_t size; + char* data = GetBadUtf8Payload(arena.ptr(), &size); + + upb_test_TestUtf8RepeatedProto2String* msg = + upb_test_TestUtf8RepeatedProto2String_new(arena.ptr()); + + upb_DecodeStatus status; + status = upb_Decode(data, size, UPB_UPCAST(msg), + &upb_0test__TestUtf8RepeatedProto2String_msg_init, + nullptr, 0, arena.ptr()); + + // Parse fails, because we pass in kUpb_DecodeOption_AlwaysValidateUtf8 to + // force validation of proto2 string fields. + status = + upb_Decode(data, size, UPB_UPCAST(msg), + &upb_0test__TestUtf8RepeatedProto2String_msg_init, nullptr, + kUpb_DecodeOption_AlwaysValidateUtf8, arena.ptr()); + ASSERT_EQ(kUpb_DecodeStatus_BadUtf8, status); +} + // begin:google_only // TEST(Utf8Test, Proto3MixedFieldValidates) { // upb::Arena arena; diff --git a/upb/message/utf8_test.proto b/upb/message/utf8_test.proto index 4070ac7d19684..515e3bf7d3af1 100644 --- a/upb/message/utf8_test.proto +++ b/upb/message/utf8_test.proto @@ -35,7 +35,7 @@ message TestUtf8Proto3StringEnforceUtf8False { } message TestUtf8RepeatedProto3StringEnforceUtf8False { - optional string data = 1; + repeated string data = 1; } message TestUtf8Proto3StringEnforceUtf8FalseMixed { diff --git a/upb/message/utf8_test_proto2.proto b/upb/message/utf8_test_proto2.proto new file mode 100644 index 0000000000000..6adc1055cd743 --- /dev/null +++ b/upb/message/utf8_test_proto2.proto @@ -0,0 +1,26 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2023 Google LLC. All rights reserved. +// +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file or at +// https://developers.google.com/open-source/licenses/bsd + +syntax = "proto2"; + +package upb_test; + +message TestUtf8Proto2Bytes { + optional bytes data = 1; +} + +message TestUtf8RepeatedProto2Bytes { + optional bytes data = 1; +} + +message TestUtf8Proto2String { + optional string data = 1; +} + +message TestUtf8RepeatedProto2String { + repeated string data = 1; +} diff --git a/upb/wire/decode.c b/upb/wire/decode.c index ecb01277e0ae2..0d21c37d15e15 100644 --- a/upb/wire/decode.c +++ b/upb/wire/decode.c @@ -1034,6 +1034,15 @@ static void _upb_Decoder_CheckUnlinked(upb_Decoder* d, const upb_MiniTable* mt, *op = kUpb_DecodeOp_UnknownField; } +UPB_FORCEINLINE +static void _upb_Decoder_MaybeVerifyUtf8(upb_Decoder* d, + const upb_MiniTableField* field, + int* op) { + if ((field->UPB_ONLYBITS(mode) & kUpb_LabelFlags_IsAlternate) && + UPB_UNLIKELY(d->options & kUpb_DecodeOption_AlwaysValidateUtf8)) + *op = kUpb_DecodeOp_String; +} + static int _upb_Decoder_GetDelimitedOp(upb_Decoder* d, const upb_MiniTable* mt, const upb_MiniTableField* field) { enum { kRepeatedBase = 19 }; @@ -1090,6 +1099,8 @@ static int _upb_Decoder_GetDelimitedOp(upb_Decoder* d, const upb_MiniTable* mt, if (op == kUpb_DecodeOp_SubMessage) { _upb_Decoder_CheckUnlinked(d, mt, field, &op); + } else if (op == kUpb_DecodeOp_Bytes) { + _upb_Decoder_MaybeVerifyUtf8(d, field, &op); } return op; diff --git a/upb/wire/decode.h b/upb/wire/decode.h index 7f2eafddca8f7..68bf63f356696 100644 --- a/upb/wire/decode.h +++ b/upb/wire/decode.h @@ -83,6 +83,16 @@ enum { * be created by the parser or the message-copying logic in message/copy.h. */ kUpb_DecodeOption_ExperimentalAllowUnlinked = 4, + + /* EXPERIMENTAL: + * + * If set, decoding will enforce UTF-8 validation for string fields, even for + * proto2 or fields with `features.utf8_validation = NONE`. Normally, only + * proto3 string fields will be validated for UTF-8. Decoding will return + * kUpb_DecodeStatus_BadUtf8 for non-UTF-8 strings, which is the same behavior + * as non-UTF-8 proto3 string fields. + */ + kUpb_DecodeOption_AlwaysValidateUtf8 = 8, }; UPB_INLINE uint32_t upb_DecodeOptions_MaxDepth(uint16_t depth) { From 1610bf149ea708220ea654db9290a040798fd442 Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Wed, 10 Jan 2024 21:45:42 +0000 Subject: [PATCH 240/255] Auto-generate files after cl/597341799 --- php/ext/google/protobuf/php-upb.c | 11 +++++++++++ php/ext/google/protobuf/php-upb.h | 10 ++++++++++ ruby/ext/google/protobuf_c/ruby-upb.c | 11 +++++++++++ ruby/ext/google/protobuf_c/ruby-upb.h | 10 ++++++++++ 4 files changed, 42 insertions(+) diff --git a/php/ext/google/protobuf/php-upb.c b/php/ext/google/protobuf/php-upb.c index 4e75233c2beac..99db650a26c3e 100644 --- a/php/ext/google/protobuf/php-upb.c +++ b/php/ext/google/protobuf/php-upb.c @@ -8186,6 +8186,15 @@ static void _upb_Decoder_CheckUnlinked(upb_Decoder* d, const upb_MiniTable* mt, *op = kUpb_DecodeOp_UnknownField; } +UPB_FORCEINLINE +static void _upb_Decoder_MaybeVerifyUtf8(upb_Decoder* d, + const upb_MiniTableField* field, + int* op) { + if ((field->UPB_ONLYBITS(mode) & kUpb_LabelFlags_IsAlternate) && + UPB_UNLIKELY(d->options & kUpb_DecodeOption_AlwaysValidateUtf8)) + *op = kUpb_DecodeOp_String; +} + static int _upb_Decoder_GetDelimitedOp(upb_Decoder* d, const upb_MiniTable* mt, const upb_MiniTableField* field) { enum { kRepeatedBase = 19 }; @@ -8242,6 +8251,8 @@ static int _upb_Decoder_GetDelimitedOp(upb_Decoder* d, const upb_MiniTable* mt, if (op == kUpb_DecodeOp_SubMessage) { _upb_Decoder_CheckUnlinked(d, mt, field, &op); + } else if (op == kUpb_DecodeOp_Bytes) { + _upb_Decoder_MaybeVerifyUtf8(d, field, &op); } return op; diff --git a/php/ext/google/protobuf/php-upb.h b/php/ext/google/protobuf/php-upb.h index ae22247b5674f..872581a1bf422 100644 --- a/php/ext/google/protobuf/php-upb.h +++ b/php/ext/google/protobuf/php-upb.h @@ -3985,6 +3985,16 @@ enum { * be created by the parser or the message-copying logic in message/copy.h. */ kUpb_DecodeOption_ExperimentalAllowUnlinked = 4, + + /* EXPERIMENTAL: + * + * If set, decoding will enforce UTF-8 validation for string fields, even for + * proto2 or fields with `features.utf8_validation = NONE`. Normally, only + * proto3 string fields will be validated for UTF-8. Decoding will return + * kUpb_DecodeStatus_BadUtf8 for non-UTF-8 strings, which is the same behavior + * as non-UTF-8 proto3 string fields. + */ + kUpb_DecodeOption_AlwaysValidateUtf8 = 8, }; UPB_INLINE uint32_t upb_DecodeOptions_MaxDepth(uint16_t depth) { diff --git a/ruby/ext/google/protobuf_c/ruby-upb.c b/ruby/ext/google/protobuf_c/ruby-upb.c index 237232d282f61..6c848d83fe068 100644 --- a/ruby/ext/google/protobuf_c/ruby-upb.c +++ b/ruby/ext/google/protobuf_c/ruby-upb.c @@ -7702,6 +7702,15 @@ static void _upb_Decoder_CheckUnlinked(upb_Decoder* d, const upb_MiniTable* mt, *op = kUpb_DecodeOp_UnknownField; } +UPB_FORCEINLINE +static void _upb_Decoder_MaybeVerifyUtf8(upb_Decoder* d, + const upb_MiniTableField* field, + int* op) { + if ((field->UPB_ONLYBITS(mode) & kUpb_LabelFlags_IsAlternate) && + UPB_UNLIKELY(d->options & kUpb_DecodeOption_AlwaysValidateUtf8)) + *op = kUpb_DecodeOp_String; +} + static int _upb_Decoder_GetDelimitedOp(upb_Decoder* d, const upb_MiniTable* mt, const upb_MiniTableField* field) { enum { kRepeatedBase = 19 }; @@ -7758,6 +7767,8 @@ static int _upb_Decoder_GetDelimitedOp(upb_Decoder* d, const upb_MiniTable* mt, if (op == kUpb_DecodeOp_SubMessage) { _upb_Decoder_CheckUnlinked(d, mt, field, &op); + } else if (op == kUpb_DecodeOp_Bytes) { + _upb_Decoder_MaybeVerifyUtf8(d, field, &op); } return op; diff --git a/ruby/ext/google/protobuf_c/ruby-upb.h b/ruby/ext/google/protobuf_c/ruby-upb.h index 433d25c1313c6..397804a33987c 100755 --- a/ruby/ext/google/protobuf_c/ruby-upb.h +++ b/ruby/ext/google/protobuf_c/ruby-upb.h @@ -3987,6 +3987,16 @@ enum { * be created by the parser or the message-copying logic in message/copy.h. */ kUpb_DecodeOption_ExperimentalAllowUnlinked = 4, + + /* EXPERIMENTAL: + * + * If set, decoding will enforce UTF-8 validation for string fields, even for + * proto2 or fields with `features.utf8_validation = NONE`. Normally, only + * proto3 string fields will be validated for UTF-8. Decoding will return + * kUpb_DecodeStatus_BadUtf8 for non-UTF-8 strings, which is the same behavior + * as non-UTF-8 proto3 string fields. + */ + kUpb_DecodeOption_AlwaysValidateUtf8 = 8, }; UPB_INLINE uint32_t upb_DecodeOptions_MaxDepth(uint16_t depth) { From 748ab1608a33dd3d28070d6df54c8956aa893985 Mon Sep 17 00:00:00 2001 From: Mike Kruskal Date: Wed, 10 Jan 2024 14:01:50 -0800 Subject: [PATCH 241/255] Breaking change: remove const GetArena method on RepeatedPtrField PiperOrigin-RevId: 597349773 --- src/google/protobuf/port_def.inc | 4 ---- src/google/protobuf/repeated_ptr_field.h | 12 ------------ 2 files changed, 16 deletions(-) diff --git a/src/google/protobuf/port_def.inc b/src/google/protobuf/port_def.inc index a7edd9b6c5579..c156037e3cd02 100644 --- a/src/google/protobuf/port_def.inc +++ b/src/google/protobuf/port_def.inc @@ -163,10 +163,6 @@ static_assert(PROTOBUF_ABSL_MIN(20230125, 3), // Owner: shaod@, gberg@ #define PROTOBUF_FUTURE_DESCRIPTOR_EXTENSION_DECL 1 -// Used to remove `RepeatedPtrField::GetArena() const`. -// Owner: ezb@ -#define PROTOBUF_FUTURE_REMOVE_CONST_REPEATEDFIELD_GETARENA_API 1 - #endif // Defines the Protobuf C++ Version for checking version compatibility at diff --git a/src/google/protobuf/repeated_ptr_field.h b/src/google/protobuf/repeated_ptr_field.h index c67a966cec509..e6607ddf44a03 100644 --- a/src/google/protobuf/repeated_ptr_field.h +++ b/src/google/protobuf/repeated_ptr_field.h @@ -1175,11 +1175,6 @@ class RepeatedPtrField final : private internal::RepeatedPtrFieldBase { // Gets the arena on which this RepeatedPtrField stores its elements. inline Arena* GetArena(); -#ifndef PROTOBUF_FUTURE_REMOVE_CONST_REPEATEDFIELD_GETARENA_API - ABSL_DEPRECATED("This will be removed in a future release") - inline Arena* GetArena() const; -#endif // !PROTOBUF_FUTURE_REMOVE_CONST_REPEATEDFIELD_GETARENA_API - // For internal use only. // // This is public due to it being called by generated code. @@ -1512,13 +1507,6 @@ inline Arena* RepeatedPtrField::GetArena() { return RepeatedPtrFieldBase::GetArena(); } -#ifndef PROTOBUF_FUTURE_REMOVE_CONST_REPEATEDFIELD_GETARENA_API -template -inline Arena* RepeatedPtrField::GetArena() const { - return RepeatedPtrFieldBase::GetArena(); -} -#endif // !PROTOBUF_FUTURE_REMOVE_CONST_REPEATEDFIELD_GETARENA_API - template inline size_t RepeatedPtrField::SpaceUsedExcludingSelfLong() const { // `google::protobuf::Message` has a virtual method `SpaceUsedLong`, hence we can From 592ee9b192d8f7369d52d3082a42c7620039c12e Mon Sep 17 00:00:00 2001 From: Sandy Zhang Date: Wed, 10 Jan 2024 14:22:07 -0800 Subject: [PATCH 242/255] Update to call descriptor outer class's getDescriptor() method instead of accessing internal descriptor variable directly. PiperOrigin-RevId: 597355223 --- .../src/main/java/com/google/protobuf/GeneratedMessage.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/java/core/src/main/java/com/google/protobuf/GeneratedMessage.java b/java/core/src/main/java/com/google/protobuf/GeneratedMessage.java index d3ff341dc008d..f722f8852c043 100644 --- a/java/core/src/main/java/com/google/protobuf/GeneratedMessage.java +++ b/java/core/src/main/java/com/google/protobuf/GeneratedMessage.java @@ -1613,7 +1613,7 @@ GeneratedExtension newFileScopedGeneratedExtension( protected FieldDescriptor loadDescriptor() { try { Class clazz = singularType.getClassLoader().loadClass(descriptorOuterClass); - FileDescriptor file = (FileDescriptor) clazz.getField("descriptor").get(null); + FileDescriptor file = (FileDescriptor) clazz.getMethod("getDescriptor").invoke(null); return file.findExtensionByName(extensionName); } catch (Exception e) { throw new RuntimeException( From 63623a688c0f4329cfe4161bbaa2666f34c2be33 Mon Sep 17 00:00:00 2001 From: Sandy Zhang Date: Wed, 10 Jan 2024 14:50:05 -0800 Subject: [PATCH 243/255] Remove public access to Java Edition APIs e.g. getEdition(), getEditionName(). Editions should not be used to make semantic decisions -- specific helpers (e.g. FieldDescriptor.hasPresence()) should be used instead. FileDescriptorProto can be used to access editions for *non semantic* purposes, incl. with ProtoFileUti. These APIs have not been released yet and are thus non-breaking. PiperOrigin-RevId: 597362543 --- .../java/com/google/protobuf/Descriptors.java | 10 +------- .../google/protobuf/util/ProtoFileUtil.java | 21 ++++++++++++++++ .../protobuf/util/ProtoFileUtilTest.java | 24 +++++++++++++++++++ 3 files changed, 46 insertions(+), 9 deletions(-) create mode 100644 java/util/src/main/java/com/google/protobuf/util/ProtoFileUtil.java create mode 100644 java/util/src/test/java/com/google/protobuf/util/ProtoFileUtilTest.java diff --git a/java/core/src/main/java/com/google/protobuf/Descriptors.java b/java/core/src/main/java/com/google/protobuf/Descriptors.java index a8ed0e8d91556..459dc6d44d414 100644 --- a/java/core/src/main/java/com/google/protobuf/Descriptors.java +++ b/java/core/src/main/java/com/google/protobuf/Descriptors.java @@ -164,18 +164,10 @@ Syntax getSyntax() { } /** Get the edition of the .proto file. */ - public Edition getEdition() { + Edition getEdition() { return proto.getEdition(); } - /** Gets the name of the edition as specified in the .proto file. */ - public String getEditionName() { - if (proto.getEdition().equals(Edition.EDITION_UNKNOWN)) { - return ""; - } - return proto.getEdition().name().substring("EDITION_".length()); - } - public void copyHeadingTo(FileDescriptorProto.Builder protoBuilder) { protoBuilder.setName(getName()).setSyntax(getSyntax().name); if (!getPackage().isEmpty()) { diff --git a/java/util/src/main/java/com/google/protobuf/util/ProtoFileUtil.java b/java/util/src/main/java/com/google/protobuf/util/ProtoFileUtil.java new file mode 100644 index 0000000000000..189dd2341e425 --- /dev/null +++ b/java/util/src/main/java/com/google/protobuf/util/ProtoFileUtil.java @@ -0,0 +1,21 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file or at +// https://developers.google.com/open-source/licenses/bsd + +package com.google.protobuf.util; + +import com.google.protobuf.DescriptorProtos.Edition; + +/** Utility helper functions to work with {@link com.google.protobuf.FileDescriptorProto}. */ +public final class ProtoFileUtil { + + private ProtoFileUtil() {} + + /** Converts an Edition to its string representation as specified in ".proto" file. */ + public static String getEditionString(Edition edition) { + return edition.toString().substring("EDITION_".length()); + } +} diff --git a/java/util/src/test/java/com/google/protobuf/util/ProtoFileUtilTest.java b/java/util/src/test/java/com/google/protobuf/util/ProtoFileUtilTest.java new file mode 100644 index 0000000000000..4c5aeea854259 --- /dev/null +++ b/java/util/src/test/java/com/google/protobuf/util/ProtoFileUtilTest.java @@ -0,0 +1,24 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file or at +// https://developers.google.com/open-source/licenses/bsd + +package com.google.protobuf.util; + +import static com.google.common.truth.Truth.assertThat; + +import com.google.protobuf.DescriptorProtos.Edition; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + +/** Unit tests for {@link ProtoFileUtil}. */ +@RunWith(JUnit4.class) +public class ProtoFileUtilTest { + @Test + public void testGetEditionFromString() throws Exception { + assertThat(ProtoFileUtil.getEditionString(Edition.EDITION_2023)).isEqualTo("2023"); + } +} From cea942c872b91e75f34b449bb43d84914cece02f Mon Sep 17 00:00:00 2001 From: Sandy Zhang Date: Wed, 10 Jan 2024 15:09:35 -0800 Subject: [PATCH 244/255] Remove deadcode GenerateDescriptorInitializationCodeForMutable from Java code generator. PiperOrigin-RevId: 597367715 --- src/google/protobuf/compiler/java/file.cc | 105 ---------------------- src/google/protobuf/compiler/java/file.h | 1 - 2 files changed, 106 deletions(-) diff --git a/src/google/protobuf/compiler/java/file.cc b/src/google/protobuf/compiler/java/file.cc index 79ef72b41cbd9..58e66e8cab89e 100644 --- a/src/google/protobuf/compiler/java/file.cc +++ b/src/google/protobuf/compiler/java/file.cc @@ -357,8 +357,6 @@ void FileGenerator::Generate(io::Printer* printer) { if (HasDescriptorMethods(file_, context_->EnforceLite())) { if (immutable_api_) { GenerateDescriptorInitializationCodeForImmutable(printer); - } else { - GenerateDescriptorInitializationCodeForMutable(printer); } } else { printer->Print("static {\n"); @@ -491,109 +489,6 @@ void FileGenerator::GenerateDescriptorInitializationCodeForImmutable( printer->Print("}\n"); } -void FileGenerator::GenerateDescriptorInitializationCodeForMutable( - io::Printer* printer) { - printer->Print( - "public static com.google.protobuf.Descriptors.FileDescriptor\n" - " getDescriptor() {\n" - " return descriptor;\n" - "}\n" - "private static final com.google.protobuf.Descriptors.FileDescriptor\n" - " descriptor;\n" - "static {\n"); - printer->Indent(); - - printer->Print( - "descriptor = $immutable_package$.$descriptor_classname$.descriptor;\n", - "immutable_package", FileJavaPackage(file_, true, options_), - "descriptor_classname", name_resolver_->GetDescriptorClassName(file_)); - - for (int i = 0; i < file_->message_type_count(); i++) { - message_generators_[i]->GenerateStaticVariableInitializers(printer); - } - for (int i = 0; i < file_->extension_count(); i++) { - extension_generators_[i]->GenerateNonNestedInitializationCode(printer); - } - - // Check if custom options exist. If any, try to load immutable classes since - // custom options are only represented with immutable messages. - FileDescriptorProto file_proto = StripSourceRetentionOptions(*file_); - std::string file_data; - file_proto.SerializeToString(&file_data); - FieldDescriptorSet extensions; - CollectExtensions(file_proto, *file_->pool(), &extensions, file_data); - - if (!extensions.empty()) { - // Try to load immutable messages' outer class. Its initialization code - // will take care of interpreting custom options. - printer->Print( - "try {\n" - // Note that we have to load the immutable class dynamically here as - // we want the mutable code to be independent from the immutable code - // at compile time. It is required to implement dual-compile for - // mutable and immutable API in blaze. - " java.lang.Class immutableClass = java.lang.Class.forName(\n" - " \"$immutable_classname$\");\n" - "} catch (java.lang.ClassNotFoundException e) {\n", - "immutable_classname", name_resolver_->GetImmutableClassName(file_)); - printer->Indent(); - - // The immutable class can not be found. We try our best to collect all - // custom option extensions to interpret the custom options. - printer->Print( - "com.google.protobuf.ExtensionRegistry registry =\n" - " com.google.protobuf.ExtensionRegistry.newInstance();\n" - "com.google.protobuf.MessageLite defaultExtensionInstance = null;\n"); - - for (const FieldDescriptor* field : extensions) { - std::string scope; - if (field->extension_scope() != NULL) { - scope = absl::StrCat( - name_resolver_->GetMutableClassName(field->extension_scope()), - ".getDescriptor()"); - } else { - scope = - absl::StrCat(FileJavaPackage(field->file(), true, options_), ".", - name_resolver_->GetDescriptorClassName(field->file()), - ".descriptor"); - } - if (field->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE) { - printer->Print( - "defaultExtensionInstance = com.google.protobuf.Internal\n" - " .getDefaultInstance(\"$class$\");\n" - "if (defaultExtensionInstance != null) {\n" - " registry.add(\n" - " $scope$.getExtensions().get($index$),\n" - " (com.google.protobuf.Message) defaultExtensionInstance);\n" - "}\n", - "scope", scope, "index", absl::StrCat(field->index()), "class", - name_resolver_->GetImmutableClassName(field->message_type())); - } else { - printer->Print("registry.add($scope$.getExtensions().get($index$));\n", - "scope", scope, "index", absl::StrCat(field->index())); - } - } - printer->Print( - "com.google.protobuf.Descriptors.FileDescriptor\n" - " .internalUpdateFileDescriptor(descriptor, registry);\n"); - - printer->Outdent(); - printer->Print("}\n"); - } - - // Force descriptor initialization of all dependencies. - for (int i = 0; i < file_->dependency_count(); i++) { - if (ShouldIncludeDependency(file_->dependency(i), false)) { - std::string dependency = - name_resolver_->GetMutableClassName(file_->dependency(i)); - printer->Print("$dependency$.getDescriptor();\n", "dependency", - dependency); - } - } - - printer->Outdent(); - printer->Print("}\n"); -} template static void GenerateSibling( diff --git a/src/google/protobuf/compiler/java/file.h b/src/google/protobuf/compiler/java/file.h index e8b11d3473060..ab13afcc2a189 100644 --- a/src/google/protobuf/compiler/java/file.h +++ b/src/google/protobuf/compiler/java/file.h @@ -78,7 +78,6 @@ class FileGenerator { private: void GenerateDescriptorInitializationCodeForImmutable(io::Printer* printer); - void GenerateDescriptorInitializationCodeForMutable(io::Printer* printer); bool ShouldIncludeDependency(const FileDescriptor* descriptor, bool immutable_api_); From f441ce89edd2b8ab4e6414cfed0cdb8ef62249bd Mon Sep 17 00:00:00 2001 From: Mike Kruskal Date: Wed, 10 Jan 2024 15:56:23 -0800 Subject: [PATCH 245/255] Mint Edition 2024. This will allow us to begin planning the default features for 2024, but since protoc doesn't declare support nobody will be able to use it yet. PiperOrigin-RevId: 597378801 --- src/google/protobuf/descriptor.pb.cc | 22 +++++++++---------- src/google/protobuf/descriptor.pb.h | 1 + src/google/protobuf/descriptor.proto | 1 + .../stage0/google/protobuf/descriptor.upb.c | 2 +- .../stage0/google/protobuf/descriptor.upb.h | 1 + 5 files changed, 15 insertions(+), 12 deletions(-) diff --git a/src/google/protobuf/descriptor.pb.cc b/src/google/protobuf/descriptor.pb.cc index a926bcf329e37..78e8ea3f35205 100644 --- a/src/google/protobuf/descriptor.pb.cc +++ b/src/google/protobuf/descriptor.pb.cc @@ -1887,23 +1887,23 @@ const char descriptor_table_protodef_google_2fprotobuf_2fdescriptor_2eproto[] AB "ile\030\002 \001(\t\022\r\n\005begin\030\003 \001(\005\022\013\n\003end\030\004 \001(\005\022H\n" "\010semantic\030\005 \001(\01626.google.protobuf.Genera" "tedCodeInfo.Annotation.Semantic\"(\n\010Seman" - "tic\022\010\n\004NONE\020\000\022\007\n\003SET\020\001\022\t\n\005ALIAS\020\002*\377\001\n\007Ed" + "tic\022\010\n\004NONE\020\000\022\007\n\003SET\020\001\022\t\n\005ALIAS\020\002*\222\002\n\007Ed" "ition\022\023\n\017EDITION_UNKNOWN\020\000\022\023\n\016EDITION_PR" "OTO2\020\346\007\022\023\n\016EDITION_PROTO3\020\347\007\022\021\n\014EDITION_" - "2023\020\350\007\022\027\n\023EDITION_1_TEST_ONLY\020\001\022\027\n\023EDIT" - "ION_2_TEST_ONLY\020\002\022\035\n\027EDITION_99997_TEST_" - "ONLY\020\235\215\006\022\035\n\027EDITION_99998_TEST_ONLY\020\236\215\006\022" - "\035\n\027EDITION_99999_TEST_ONLY\020\237\215\006\022\023\n\013EDITIO" - "N_MAX\020\377\377\377\377\007B~\n\023com.google.protobufB\020Desc" - "riptorProtosH\001Z-google.golang.org/protob" - "uf/types/descriptorpb\370\001\001\242\002\003GPB\252\002\032Google." - "Protobuf.Reflection" + "2023\020\350\007\022\021\n\014EDITION_2024\020\351\007\022\027\n\023EDITION_1_" + "TEST_ONLY\020\001\022\027\n\023EDITION_2_TEST_ONLY\020\002\022\035\n\027" + "EDITION_99997_TEST_ONLY\020\235\215\006\022\035\n\027EDITION_9" + "9998_TEST_ONLY\020\236\215\006\022\035\n\027EDITION_99999_TEST" + "_ONLY\020\237\215\006\022\023\n\013EDITION_MAX\020\377\377\377\377\007B~\n\023com.go" + "ogle.protobufB\020DescriptorProtosH\001Z-googl" + "e.golang.org/protobuf/types/descriptorpb" + "\370\001\001\242\002\003GPB\252\002\032Google.Protobuf.Reflection" }; static ::absl::once_flag descriptor_table_google_2fprotobuf_2fdescriptor_2eproto_once; const ::_pbi::DescriptorTable descriptor_table_google_2fprotobuf_2fdescriptor_2eproto = { false, false, - 9539, + 9558, descriptor_table_protodef_google_2fprotobuf_2fdescriptor_2eproto, "google/protobuf/descriptor.proto", &descriptor_table_google_2fprotobuf_2fdescriptor_2eproto_once, @@ -2342,7 +2342,7 @@ const ::google::protobuf::EnumDescriptor* Edition_descriptor() { return file_level_enum_descriptors_google_2fprotobuf_2fdescriptor_2eproto[16]; } PROTOBUF_CONSTINIT const uint32_t Edition_internal_data_[] = { - 196608u, 458752u, 99997u, 999u, 99999u, 998u, 1000u, 99998u, 2147483647u, }; + 196608u, 524288u, 99997u, 1000u, 99999u, 999u, 1001u, 99998u, 2147483647u, 998u, }; bool Edition_IsValid(int value) { return ::_pbi::ValidateEnum(value, Edition_internal_data_); } diff --git a/src/google/protobuf/descriptor.pb.h b/src/google/protobuf/descriptor.pb.h index 9409875173066..721223322a92b 100644 --- a/src/google/protobuf/descriptor.pb.h +++ b/src/google/protobuf/descriptor.pb.h @@ -665,6 +665,7 @@ enum Edition : int { EDITION_PROTO2 = 998, EDITION_PROTO3 = 999, EDITION_2023 = 1000, + EDITION_2024 = 1001, EDITION_1_TEST_ONLY = 1, EDITION_2_TEST_ONLY = 2, EDITION_99997_TEST_ONLY = 99997, diff --git a/src/google/protobuf/descriptor.proto b/src/google/protobuf/descriptor.proto index aaa5424527618..1dbeaa0c53639 100644 --- a/src/google/protobuf/descriptor.proto +++ b/src/google/protobuf/descriptor.proto @@ -73,6 +73,7 @@ enum Edition { // should not be depended on, but they will always be time-ordered for easy // comparison. EDITION_2023 = 1000; + EDITION_2024 = 1001; // Placeholder editions for testing feature resolution. These should not be // used or relyed on outside of tests. diff --git a/upb/reflection/stage0/google/protobuf/descriptor.upb.c b/upb/reflection/stage0/google/protobuf/descriptor.upb.c index 46c1e47ef52e6..5edcedbdb7eb5 100644 --- a/upb/reflection/stage0/google/protobuf/descriptor.upb.c +++ b/upb/reflection/stage0/google/protobuf/descriptor.upb.c @@ -401,7 +401,7 @@ const upb_MiniTable* google__protobuf__GeneratedCodeInfo__Annotation_msg_init() const upb_MiniTableEnum* google_protobuf_Edition_enum_init() { static const upb_MiniTableEnum* mini_table = NULL; - static const char* mini_descriptor = "!)`~)qt_b)|i}{~~`!"; + static const char* mini_descriptor = "!)`~1qt_b)|i}{~~`!"; if (mini_table) return mini_table; mini_table = upb_MiniTableEnum_Build(mini_descriptor, strlen(mini_descriptor), diff --git a/upb/reflection/stage0/google/protobuf/descriptor.upb.h b/upb/reflection/stage0/google/protobuf/descriptor.upb.h index 589f6d56cb4d2..62ce4b0a66fe3 100644 --- a/upb/reflection/stage0/google/protobuf/descriptor.upb.h +++ b/upb/reflection/stage0/google/protobuf/descriptor.upb.h @@ -107,6 +107,7 @@ typedef enum { google_protobuf_EDITION_PROTO2 = 998, google_protobuf_EDITION_PROTO3 = 999, google_protobuf_EDITION_2023 = 1000, + google_protobuf_EDITION_2024 = 1001, google_protobuf_EDITION_99997_TEST_ONLY = 99997, google_protobuf_EDITION_99998_TEST_ONLY = 99998, google_protobuf_EDITION_99999_TEST_ONLY = 99999, From 41c8f2a5c6e2aa8e98ca7a34f2bab1ee6b1bc1ce Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Thu, 11 Jan 2024 00:10:17 +0000 Subject: [PATCH 246/255] Auto-generate files after cl/597378801 --- csharp/src/Google.Protobuf.Test/testprotos.pb | Bin 362584 -> 362644 bytes .../Reflection/Descriptor.pb.cs | 18 +++++----- php/ext/google/protobuf/php-upb.c | 34 +++++++++--------- php/ext/google/protobuf/php-upb.h | 1 + ruby/ext/google/protobuf_c/ruby-upb.c | 3 +- ruby/ext/google/protobuf_c/ruby-upb.h | 1 + upb/cmake/google/protobuf/descriptor.upb.h | 1 + .../protobuf/descriptor.upb_minitable.c | 3 +- 8 files changed, 35 insertions(+), 26 deletions(-) diff --git a/csharp/src/Google.Protobuf.Test/testprotos.pb b/csharp/src/Google.Protobuf.Test/testprotos.pb index f29d03d15c0044b2c52d5ffacac7053860e6648b..0d9c6d9641c21564d15ca04814c0369835d62547 100644 GIT binary patch delta 19511 zcmZ9Ud7PBRwfCp$*}9*e8D@Hh9R!9&1r)a!i4d*}F~%gu=$o7CmTQd0EhbU3nV5D1 zM8Jqce82?_L?TAiAZA=xRR|GW&|Jb|&})DZ6a^GThS@;9-fh~{ZjU|kjJ|)$5KlbEP&pP$=uYc#LBaS+zY1`v} z?;N7i#q)zSDMv%Qfhs>saHB8730El>wew-&5uVko?Gahj!eT) z>AG@oUi)u8KK{7#bSgR`!qoFhIKv|N&MTW9N?8Ev*()7tlqovDUGE)!-1${yh4T4T zWhFJr#$=Qg%IEj#n;v77vFw8Oi}xOT+yzx-jq(LmWsUL${p*U@qy^#>oEUTc&Yvy0om^U1G{ySSxI!Q9iVBciQ6(uraz&}1FN5TY{+^@&$rVC!y6F%BdZixdY8GL+vdU6~ z<;s!|90}elyZi1HVYzZZTlyivi(3fZYucyp|7hejRqYh*Yf3(HB&e_HHPp3}qJ7O_ zho=u%?NT|ow*4>v`onS8R<%ov(zVqH2bTUHhC*M~u9# zs$5Ug*OkhydOgb5wfMoUNBO$G{nA63Pr4l6pz40t-gw}U$_=W}9fdH|%&722rF*9h zOdn8aVCrEc5X)RCbMi*T>~b&=$n>&I6yB`#P*JS+=F-n)iaf;!#?XYSI^i+f;&{0trrg4f9ca>oprx>Nh;gg}6tXjHN`B(@MFwTw6I)>*q6^^J@ z5Z55cZImIpO*ORTHQ>BW4Xg~!C6L~xm=@N#7;$?(;t_;E?_5?aAk)iwlO+q-%a1r~ z7O* z3iSPExdoPb_)@s;RXq>(kbd8*8rec_G9A~&a(I6>BT(bMeSgkT#G?E2b%oUyShkCU z)-1Qcwn2o3W;csxtGd4{#YPZ>GDBypLf=%@^FUnpfXZI}x%x`BG*t0<5BMf1!psN! zgao4afa-U&F%w7=52#~Dnh6;M%*Q_{z1Yo1Ftz`n(yr-gL_AO$nwt%b)Ynd%>pg44 z^kc5~tP!9%SGDvsVQvI8G*@woxYjXIVV(-xdR^B4tnBosgYMaNSy0F}MCw~(k=rRG ziZW>PR6|RZNd|46YVDf~pq{7t4@iHf95?fFe)f}C%^o|ymWp#qIKP%k0%g8xwJU}+ z#%Tosk@S+MLeP<&m#A09cGOaFY6&}3LvzITTD?v)EfQ}sP4Wj(XLBYd98t}3X> zCp}Y3#Th1irj|-he9zQUG4=?c8pNJ~nS|1!?1Z8ka?~Q#(CAw%%3%Gw06!SPpCkkW z>FsmbjG}t{+~@N6kPYcM#fC3y3U#EC>fYudO+Tjw+o?|}GvYaQ@L00~3Tzg9$jRww z(*W(QP}%E~)N$FHsfx#}$eWRsaD^&$b-ZHB3f0YS6M^yj3N>J0`X9m*5{7?O`o(N; zNsVd#t4eyLCy5V36Mw6+pOn>^c7u$6a)AA}+Zn1VDfPS?KUC;=&0_Q9dps`vt zm($yQKxvs;GwRn^xnxs>9bS7phy&I@qQYbySN zhpd~gspj6!TY-4%HPv@ydbZ49hJCHdKKrTq*3m)4yjrUo>{e?ec znsp#7#~W1Lv)Szp>Zs3cP=!8b>W1R8jY{u#Qx^=!MwOJ(GjSbIrtT&cw)Q$H`$ntk znKd=4&!2_BI?+_1nN8k_B7ory??i*Gz&gI-rd)tVr)p`f8pJ5SU8^DcA%a{ZM&s?OMuk2wxZ5~HR5@kiL(q^5P}!!MnyZZv z9ouVrT|fgt-s=Jy+ojhlv~v_weWwiC6T1Id7kvM)?_G4or9Zgznu|K#Xi}e3Z4~8B zE~30sHMej=woXpV;jZl1vKrC0tF|ZHEyG=^rE5CS)hm_553>nnHMsI&EnkUx9}1rz zwEA+mr`AUtu|<%ZUysHfRnEQIP!2z;4WI@z5acduK;t9TP3ZGbd7LA$#Rkf}OByAx3;OTsN$+tm;R6Hu5c5$(uceT(Kk zF3Ta%)NbzXAyl{MUcH@Bm_9K#N{-GzZX678SIL*}Vm>B99j+we`V0yFl1`E@y?4w?4{ODOZMFPdF+@Z2q z&C<<&Amx-kOOvMAXDL{z9?YKVt^QScFsCR$@nCL+tX>c1z97Q@JV>%HG9)Zq4{1Hf zb(0i>KtHsDsN+SGu`a?PG8Mn*C(R`?JEVIS9?=qG4&%a!HR$;Ky?FSf}+y z9rT*1`+xI-E5CnH{~u=Ehp0i>af8&S&Fgg9+guc>DZW^reQ7Wk#r4|V6pR=ztk>=W zZv-^CUb}>V5zy#*?JkNUpu&diL6}b3P|GCi*oImral;1fQUOL0rVZlLhh)OUvI4!C z6^E#YN4=SQKo+1kwL3df2a-2+Uz>vgijF>fM0$l`zS%?Az; z3%B{eNyJ&({n`(L3Fw)`W!wGwQlZ$?c56Qns_lO5Pb6^O)!Jr-Ku`fal?2Yax?~qw zN@03e_pwn1gy~&9vML4R1fZu9Cw!<~R)tcSKGZI&0)**9O;+UyoKP&sdv)FT zK=o?-Hz#a7RP{T1uO>+#?G?odpLi#LFdb;y1LA~Fyc2-5_lb7`koGjP~ws353-o=WE6^?}RMPzu%cK~FnEK%+ZwP&(Fh3)P#lMZ?r7 zXWx`F$Q-;WaL0(Ed5^g%Xz~nl1h^@H!FGg*1P(sdL-yjEf+IfX_+c8Coj+Wia_+dC zUk(W4a(+1=jLZ4ufG{rSkKiAd^GEQH6aGgV352v9KN!^A*P#wmhbK)B289-zsZV9- zAIZiXqdpq_h;JAn4L=gNgCCHF9|_8KfdBLNHaE?J;c8G|P}uKJw1T8(}p=a4af zBIl4Xeg+{1hm7_j?|{^V`l6u8&UYXji-I9` ztpMVHMZux=iVeg8i-KcDlGzs{sk<~AG*S&acWKTqH|?c4zl6Zjpvm6ZQ4yWsh@;Gi z0pVX79DTC6UI;YB$DEXIwQe9pR(AYxq`E|%w=!=+Vq|6BgsjsmgC_3=iIJ7Tp?2Xn zs}^whXxAbuH}LbL(yvMvY%pFfsT76HAUY9o^XWw;sgvr@=UEo%g)SP|S1^ou3f5Sys3+LvJ@)-3kUD=#- z$l-T$K0I>x-JD059DX zPXl}MNHgh;pzPNno)9Tz9Xi#RNNQtm);U(4HhOQ)&;Y~UoI%nZdxNsw)h~xZh{L{IXhl;)I-{35p3hg=9)5gzmzb>Lw^A zgxsxOuoR?8CWrd)Ue9FLe_0)$J$b5{JQ{(wrx~)zIaxDglf$xK6`CQN91c4yeb$nd z%i+}QhOemSM@`Ks%1}(rDauex4XayK8H%YPPLV8hs#~~}XE&Ut#*CVlGqkX}ObcE9 znL02`3tj#h2*WgC_?2O3ooQ26Q<`3tuRav-OFaGTVa?Ux`z}X4AVm%QYI*w zRoHt^$bsqF>^r|uCuINnsyeB1Pv{c7sY&nxZGsob{JJM3!7EQYG9zb(=5rK!BU5{3 zSe=-%!PY_)4U`w6QaS!zShp**FGMmweis(HrRyU4RMN7aFX&kIHMK#Xv%vQXF_ta} z-RTC1)`GCfo>-ky$ca^E6_8oAAapwykXf}LWaoNEhOQ(>gr~BPzM*!U^Hkn|oDiPM z8;}k>6*k#tNmQ`vsqiTK90jC-r@~{#y7m+eJQa>PIepJIKyR01U;L)pSy_@dAUo8O zyaBOdN$A#{k~uys2}!Wn9?0=wN!afQ4{2aYICO+@d-a*l*h1g+WKc}%V%r^Z}^**{JThYc`PtH2E5IqC`AxFNF9PB$gdVE{Gq0Z^d zt(EgqXKt-S+?nPbow@{M-jZv_s~; zyz9s|wKFvDI@x3AsOZ$4e%hDJvP45UW zu3pZ5`#KJsqo%3KK5rIM%-R>ad@B&8eWA;e0x@e}$fZpJ4Tu}}g}v>$7f9&u3y0WG zG3w>mxj)pmM1ieso{#p2B(eK(s-##f_%sZ=^vasgSA7TaXKGHMrigxg8uAi(XW%Mh z$heL(&R5gbnd73cP^~Fv&~XuyO5PMi6+9twFEs|EiNL)k zf7IyPBNzSkCh>fGiqk2t0uYFuPq1!iZDU8IJ!&91E{uAE(44?IWebT(16f&hvQ#GVPzw8<1)LeB@HLs9@Fe5yuMKfK2=6 zBX^ailm?!Uxaz)b8-VJCY}FNN``It#4ai;kg}eco@GnGeFQ_*Y{)Ncx1wa~jA#!^G zkOp3e*bBy(4iF75W?imSC!F(Q&M%jd7ju4D2VTrQBrCxpTn z9d=Z@+;~VnbXyzg4cV+8s^=?fqr^Tm)$@Ep`29T!?Y9aB(+mRpU}^-!%ip6OJ>5Jt zlVM%0hD0=iTtmWfU9ARqeH7XcKKce@p|MwPy@pCdeqy8itGrlM+YC8&Xb#DJ%JRz73m#O(CZ%FO)t6h>i!+y`>`6J zDsM$ech@KL(ab-iu#a1u?58mZ?As$G=7H{?5f4^&wc>jRu7Y`=z*gY9gn%w>mM(b> z@RleXTKAwTBj@xScF0qdw@4LK^Z>#M);kdoFr-`Z+Z}}itZjl%p*1A-Vi@Pw7EMXZQ3T=0Rk#~ke%`q zHK_7IEt4FxKZx9CQl_3%j9T3U6h)Xmh&Th<>Bb#?Po(WZxSnZap!Wlx@lxut&y>Qo zC*nh1yY9$ceoxeR*a&k1tJhrD_eS=!pCf*%;?a9^hn67P8@X#2H6hv?xoZ~?qP>wj zfz@kn<@+OZ0y_bKMf-CizU~FO+ZUw}?T_5;3kcEv$eqCC9)BP^@Kbf}VFx02<*GMl zFQ7ep0SSu(5ofPHoZ0FLitFQS!p~IS;n&CR%wKQL{Iw7j14lZQ8?sk^rjGye4Y9kP z)tiHVEkwgWIp8&vG}BB#UzlPkB^-T zfhdlToeP2Ve0)rrRt~WZ5*-t>mwv9!7&S3xkY|aBvGW~uq*CmB2ZUi_?0hE~jLES% zy?(7hzDk-LI}d`;16mIP>D=Vlon9Nu@o(a~d9HJkwD?U-`uV>xs!=-Eo*npw`tIm< zZxljWYLDHK4Tws6++-hpfEd*t^Rm80_OeFl*Np7mYgOle&B!Sv=4a#-(ytk@+wD<- zVn*zCdmwAejM(k=Kvt(2F}uCoZyFi@yR(1%QVlr#Za@5uX83C%{WWlMkMv_1(k>De3$p7f z>XWkR)kQqtVW!kc{7v6G@>XO* zba)?9DpkD?fwa;gK77O)N|zR9U%f#+cJ{)YLdJPvZm6`jFm?yEE@qq;#;n@1U;;68 zVLZUz7JwMKFdlxSnX_GFn3vc=;%^LHlD8s*y~Ga^rL?ld4-!x`{UAx!?^!oa-YHV}^2VwW)n;=|Ws zmoWz7!`EUm#eaPSVaBbd-oLts=A5uyyYrPMFw6fOwP|}|3tq;H6BtBg4 zeF#DiXnhEz#r58Y&E@#@xb9!hhmzoYJuY-j*GlJ`#fhCAmrPLW)cKv>ETpv6={pZZ zsnd5Jh*_P!^FTV^={pak^PST9of4tVa(RC@);qJA6V>}Cy&JnTE^=vmN9@kH2Ga}z zd!RA``mrPCj5~<)g$StdUiQkZYDn9AvHO75h^hBp+^u{1c~=koe%6D~sJtJ$uMnl4 zjKuq~`P5VT&P{k%tar!uDGbcmAh72QAY-#DcIPc1jqi&4*c1g2C+v#d(;N^d?2cob z;s@e{-Es4vl8M!3X?Tys>X=b`@&;t^_xLcS4h`(_VG5*yJrbr8M9qTs+92X@4Beaa z$VA-hgNRai_WB?Kilz@DNq6tJL3B*B1krvUL?HBlHi&@OykCN7QosSB%mE>(o8Iw* zDe6|$a&yABKdWS`Da%Ro)VN&A0pEm-mpOo;PF6UMeP+@Ws4m9UhgW*KrI4e>E(#Z+^kRRiiDn^Hld{qGH zoO@eRYB8%N5U$%2zRH)y6A06737Hr3v0vHjRCi?G znyO}2?#MaBqB|0oy(ybWx+8Iq9zZzmNcfE1T7%o$6L$wFoAm=H90Aor$*ZPGyr61$rvUk=&UZB{#o2lV(3Ok`%pD zg25Wa$YhE8Mx|`BqCn4dw4_6_+$y;eW=YwmC#Vfomhh3vMv3kge!r5`?d$k`yV{^C zv&mhUYgCIYUcXQD+{9)c!La;3N$gj|K#83P5_e-ZmPY)%- z|Ag0M){1~vxIZTDwkfy;zdc;_n+RZ>mxMA$E7*yol`4-U;aD?kjeshT{+ob4JeGtf zxv^q7e>~A0)v=NV`|%{{;@oHwn+x)x0aF2i%`3D><`cpNNyVj>L_&=x5|;oq*a~dY z*a%R0B5_G$5rF@kxbMylMgxIONE?BvK|FUnqW+^-`+H zbK;^TJi$4d+}+YdKVNmUcxh>p$d5f3ZJWYdmV}2`eZf>fU>9vu0Us<&SY5mZ6`u88 zt4Iy$Clc>A1gJcl7`NF*z|ZBA!lv*L_(@??c+c5sBq5H~%M-n->S#HMA@F{d&3Jht zpT|{6~xa7yq_gYNc_E=JDRK@AH(Kzz-9>%_&I>U)G%{E9F5hlCVE}f(X#I#@Q#+# z%BzV>-%uL^UQOKZM1euM0_H1T8_{I)VLN`uZ+Z0R%1U40BD&T{S370DCX!B!) z*Yg$F{@wtAUx5*z@w#1sC7_A5CzbJfwZ zEhF%bmP_;-iAzgU8@4x+-ZtY8B%t3&_`=uvS-w_%BROI-KB$;3@RUhJzgg`xSRDPo zxuX$4`Bv^|o&>4!&m{aRUcf-k1@YEIZ?DF$Z0B2(#Qx}rVsUF{?nV0@dnfC^y#kmT zbh$HeX>Jif@pj_Q^afjj{p8FD(0DuHlQTOKk@$66J}1CvAh20j(Xchh!rB$Ng4ypR zdUw^Y@^Fj5`&Axp-$`7~tHnIrzLRvb2MZv6eMb%!)~~$dKsID|HGU&;>$|yIBjeT` zHG+!q>wCFhsX`y#uN8=+cP8QKE}|n7(YuoHMDwvg3n`-y6K&u0TjXPb50g@(UCB)5 zs1`zPpyZlbI5T~eT`^M)82*u*pv@*@E(Wy_4Fmf-jgPaZW~#Q~ALkmfs?3>@e* zKFN~%)Zh`HBn|dGs>O^e&^IYV@=4OQXZo<_c-C5uuP@Zy(Q(dwYM5%dzEJ3uJ|>rs zR=IqPE9hG~X56nvsLHqknP?ey3M9717u=D>hT4a-!=lq za(ux}Y7tOjLLro~O-vhdV?^LM&E*5q355n5z(&RB^ssBR5kNYjz(=`qh;0=!Cl>UP z#?>GQfi~2DuuUwuUpxTenphZQfAbB5X<}i-5$TO`({430d`kAhEOqnfDLIE6Af^=f zwiWeVuNC= zx|ZV^g}S@4Gk&kuH_a%Jt+}xo>$*xumv?;O0d;fX{NJMz9|Bs zUTy~f3K{Jc1wEr^Pvc-}uPAWgB^0-Up{(06G1s{8^{M38LhXqvCiQkQJ0ZB8zH zTWXt=39+TNIr00J+U6vIu%)&+CC^D)q`3#`U2_QT>{$J{IykP}S#(h+X2`AZ&Z4_U z8v)JTS!}gWdqzNWcNV!B%IpvUI4g!jtG$&?8i9>uQvuGbmQyzBtk`OU{|BauA>rQx z@uYA}FNQ}|No7Mqkdw+yae6JOY)aFMt+Lx&ugkVHy?Dft@>P`%yOrbnigin~H=b5I zy4+VR^h|$FEOnD%o|SEUMqPXUtfHGN2nnTGMYk>kp`KOjX49NNh-VdiVW@Pt}!^~W`A6y&Nz8)ZDSHgbG^SrQ{rfDvDLoN8Uc;XE%HJuzeN@S z%=5DUSgd|Ac3v%$gvh*Fvn6)t72WTTj3P|)ilj0&dJiC&pB-4N{&C9uS}I8#%&(=A z$e3SrKR^;HNgm8EvY}pPjgo8hpNssv0BuXvr7eFh7Ms&AF{!A^)f7KJnay0PzC7f~ zVw|SUY0($Zl_!gw_(xUi($Ldc{WA5%Ax{_MVohB+Og&v>(?70S7sn*kx87LE_fM;TYvtzN{5-4u)4>t-O$WQMV9wi4;D>IvyfyWuho6kI zU)3-AVF3^R6bLtui_p2L_R*97ULhF%;;n*Y;F6dFwQUz9WF?<#E)!o#*SCan!s$RT}gUI9e3L^Zr!( zR7?MY;jyw{P#^^3d7(3+c5}-W14rR2A!B9#H|u1%f3b>Q7uWe3W4CsMk)1LeDmr2EjaL-o6M4<3`s7=)_Y=T46sSd~>4 zP_D`<)8JGUm1`;i<*LqIgUh5cDvqkX`OLudsI0QwQwEaJ9eWrAlF_~UXc9kk?&bZ`y37a5y;&9?EcYflnKH24 zThY@Xu-x0HuV#sb&V9U}E{cKVzAQ-$B=;pcnlg~wS8hmRAi0l7Zk8QF*xk=N>zZ+} z+@EEMgXR8&2^maXA?PccPKM67+HcPF zA2cqjoJ7;(5}~f1gz~szGq_18kL%De=!yBnL+^2x_fqZ8{?;S?IE%G`f)E@tN{nZ` zEXc=X0umAi2D$`cnJ&eg9M3SjG;|1JdMPFpPGG#3E@WT=G)&ARh*2WdH0PLVz~x;{ zZBR{MJ!sg-C?1MxhT&H2U>PE4s1TNbnhJHnRLwBrx-yum8HQXj0o5?xTNgTD0!$k! z2UIl-b3y5176O)aGf*n`q;VvppgW0SI;grrLBk}#G>KtC=u$9EVwe#cf@u=#-6tp@ zCMTU2dQUR`6mwL$lZWb0vY>6yKJZYUN24-@i4GOX^6MY?&F}v(X7nRf{eqw{@Kq_= zMsd;#FiulgerN?CoWhFRS^+GW!phpq7Gl%{YD}H;2)iIXHJ1qsqL`Y?L<2RI6}QeZ zVOfL#qh6qG#b8ZmqJOpmISK-69SzuYmS16OfO9(Q+)E15WDJ%|NH9s1t6{_pJN_;R z0gbD%egR^#Dc@oN11vS;?}BND9e>oF#dv>R7i$~Zh`{~89_sZl?*Uzln%(G(y0a}@7M;QXNGtZ1NnxR2{HtOYIl%LIIqEUV} zmx)ICSv$&d^MfEew_~B0&v+l*9jw0uP2aHq118#@?YbKXo943uY$_9E=XpF7 zFGkxPHu3fsEk_&{y=Ye&tiOPvS}r)p0t{Hu1>wQ5zj+H;-WQBvYj6b3*@Z0DA)poB zA=fR6mI-#tor?@PgfMWCnVf)7S;RVCEDZz%`671NAUQc52Xpfk##igP35?pWu%K1& zbHqC!HL*DQ7nj{Qbg}WN6r%@=jZdWjii=rsI~nCtfQA+`oG2dCOsKFlYIfPUVM}wF zXmpmc{Nk)4jm}b5(!mPAw3L;13KlR;g-N(9TIR8rhb_yc!VyI*%cY`-SjI}!!azpR z%v(kw^QobNV0kppXIqCY&!xhFMJ#9eMOh=r^UGOSY6YapI$RJ;F;s|?_o6pqY}%0b za;b295%1+v(P8hsTq+DQ1fc4I?E+>ZW>!UiinDGPtz!8Fro}jo&EE^)2Ps%avF1>3 z*G1dotbW8g8xFJ=tz+2hX#qhUs>Iq<7>K6Vv94;KqZFaPj&&a~Pu@KWB;d+HM->&shhxz@ij(e@+Xm@}2|#Y-8T#24a=m z#)`_cyBu=YHr8QKa0ks*jQe)>%p~^9iyar!XgkYSiv|!H0aPaqK$yCnwQ3t&j0rD7 zZx_pZKiZPdE*h|l#oEi6D#&HK89$?EDlj;9Gd~gB3eN%3Ox+vxD`5Y0+g{^2DF*po z<2e#Q?@Qx3iIqTkP70v$C3)_Tni=@(Xh#7Xd)wDc*m`tu`I_p{-bjk@)i+F($U&1B z%n+zilmcjcL$(-ZOqm13e0}s?AsdiBkV}sQrZ%Sn411o>6~l|w95lx+kdaX7cvF=#+wdmV$u zVe0jVTssOA{3ujP|IEv8`}Obo{ogD>D`Wmh;G(eb7fNE(2 z#Ehxo`a%PUMr*jf&;Vk()^L635wt8!;#@6*KwttSrnHN8XqTSEaS5k&5Kz`GYGWX% zCh^iTZ4^wLY>lE5GN3Vv_KC@siQ1jai`4dndk2^%lTq_&)yCm56l_|wy)}EGa+>9! zHG3LQ6zb+_&7Q_nB?dxi8gJ7!$Z*Ml_G>e5wPAzU;9AQ;+j6aS4sFV{JXBXhLFX>O z3pxh>At_Kdin_LAk5@*P!6m6>pyepyI3Xw((a}8O*wkk!D`4{TnQz*$VpjRQUpkDf`WVCc%D~u4yu(musAJ{aUvq!j=!pp**@2^Oy4@x1*}pU$jXdJ{*Mk4*K*)Xm0JAT$7| z8UTc;n~kY};NNUa1qAMlNUl%Cx`6h|8F`#mckYks|&Xjz(qT`P6tQ< z?Agh6IzS3w(N3<@0VF_$U0jr96Ar(!83$R6CQxphpw(|zZWH9ZU0ml0qzanYMI-T_ zG|fC(x4z z_gMy7y!P3!pv7ySSvEYmcSoCvP4$I|mS$01Xql?yy;%(kPa-_09nZs>5dI@G0z$aIO+b zK%fFNR1|hcctS1FC;VTjT3;-9-wLu5T-X9Cjg?oX5$1vwAXB$5F=xbah)>&0u!KN zqPcgBC(6~_L$R#gNhJ*cL3NBHXP}IN6OMD8dWlIV02(TC!f~!sFDM1majsJ@fM7b# zk$M>bC&WXqh38FlSZT%IIiXE2*71%Ojw}MT7bhp2GEM-3>42&|Kse!)aRMOPJ7t^z zi1tpA6Cw)xI9YQxn%RrZOP{qA6ar^01$F)`$J+rd7f=DkS=ykKG3fj`&eioaE;|os zjG+tuIm<-No#SB#%|x9)$B`!h(=A{IJkPmGx&onJfQE|Z;CZgoI4A|xdEQQq5TMlU z+$9($y9L!JqSL+EwRb$>WEp430t7-3dapWpFJvnF zvVMN*RVP-glKTM-{p-=cU&4N@eBCq*AsT+&(Z@zWH2k^~s^uLJ4ZrSSc|S(Wdq89G zPUekE*%(&&j^&^+f5&prn7`wMD$M{LaJ=In*ZhhjIWXv}G9!P&7PC86Sq>WQRmK5< z4E0q`O3imbaIA8=skH(S4p`;%R5x=#IAE1?$sjxikddgnCc0}7>pfzP<);h!8p}^1 zu*ONLt3Fgn#~E;u95F!fuW>FODlaGmW$`6Lf=1;AgviFs!9i>kyK|#$f?{N&ZGzV6 zjZVtAfnsE%(^D<{a@7LtQ>k0T$_@CF!NCpG1-k!la`ff)vB6o1J8SaILO~#y^SvbuhcW;uA;T)~Fs`Jw9=8p*8h@KaKXF zUiwo<-<7EzEzX}hxLwmk4QOz-I{XT4EM=_$)$BqcX4h6n9|Hl=^j4>>nhb#G_g1I7 z89IvHt#;@rcDK^deG@3xf@??S^-A_zR=LAAK_}-OHp1xSyu;C}N+3_pJDiT4g1^8; zuoj&AGB;hxe#z7OEC(H(_u1j0qw_u+VRUrfXCusqnft7nK2egH${i@&?{G7Alrsi2 z?x6Gae%($Q*3bcazmrl+6CfJe@AT-UeHoKny$2hJhW0y`U7;Jo@%w=FI~~6PO+%De zK43dU$L|BSLv;K;(A)MXj)o4{9>vkn0qRk2WUm6W(-?hnHC_Z7okYH}MW!HgAwojJ zv4Y-)1wYNsJgYI4diG!P~=IlTu2 zX~~bAMsxJXp=|u{X3LNFMA2;d@t_E(*WrNUMG+7$#EL%w{${6}T8B{z{$}UGOM}^} z1C$JjZXL#+9(=+!kVFF~Y^2Eqi4&T22(OMP#X5AoG!e;>mZw1EDXiWX!Xz7`oS|TMF@(SmLdejOp)EHLQu>Ua0+Fw173_Pee~2FY|yp% z8}p{t@)To@sTDeTjZ*N`3Z1+L1WzsTjFUVixY!GRdFcaD;aGNQ^w14#=v5GyZk2#5 z68dp8;3eRSgnoYk1Xm>R{xXTtEQ9^e2^^pvi>~}5yDA!ZBO8)_PUu8&AQQ!aDp3rG z`SzSZqL|)-Xofy7c!63MXsSOivJ;gy+*}An3F%2G5qd9)yk?=ElxV)ZBx0?Doi2Kp zko$Xm=G={JHy>VadId2otrz;V0|>2pky0mEtt4=QrCA1uSynIfP6misRxhxV9igF2 z(2-$9bkQyByWuNr19W0oVH=imcL<0??SAXgF1RTFs z@M7usL>$}iT9HVqnsSA-Fde5MlbE)N1dY;KQJ@l6K>r8Ix+qn3B|>^#S|rcbYlVfT z^d(RF6#m&E_ywi2yz<*eRXsea>Y;M{FEi>kmU6B@iHgnyr$f&U>jgUW><}sSyo^#w zgGakA2r%mBuBiTY)~)X@+dNN`fi_%Y>=z(#pG5UvpX2*v^V(g}qRHL<<*cwGjt>e&!-Hl?9I*kBg^cuzBo8@7R zpe(MuNiGBl3WUS75L{V#*fu~%mcwQVKpix2*en5nU^q-m06n}W=n~c>qBkF5Kf4+L zwl`TKdS`Dk^B<)kYBKX55JXKh|LKW{wyvXso``Nr&=b*7GxLF<2B>B}Al!A7WWn~Eydw^pC?*Te3Q<@Z-8hnU z=!`$r#~iW<{WvS|sQHYeE5nfL%=D3LF1xkb6)|~yrJ8gst#&c5=%IoHz%{OZ{*f4( z5U9r-DUdaAK>aV}2$avrJbD+~&MIfPI*^hwlRd-L3mG8Qa#Je*36OdcNhL@t^PNofMV8G2g{UOv-z7+nDbn-J~I$Ip6J|E)u8=XU=zfT!?<5 z0mQNQyvtw7I#Vv(uAeWTDo{+$d=aPX(x|SAb*;dk>YYUv!MYb+oZNd#7s+Rag;7%# z>s_%hw;s82VQxL(x@gcntaqon+kex?A8Zr~_VP)>{2HSaBK^m+BX+3Cg zb@DwaSC9r5$#>Oxx;8bq?RptV>!^#Q z^eL0lJVvSNX@PUhq?;+Iys6LMT``Nd5d~6$_oAt-G0h;O`yLu-` z%BlXbt9JrGH1M&jcLG2(@Ue@X;7Zv61j3f+=MS)}hHtU_bT!#x`Dq2%Vm(AFz!tZS zT5^-z1OFDcRBfGr;NRkQ?WHm*Ns5-O(ZL7UypdaN19WfMY8#+?%T_mK0*>x2TV33J zl!xfvvem6nTPFyK(d~Otut9o=zLeYU@?FuF53=>??XIsLt&;S4TqwS9h5F(_Vl)GR zdVrMz#LE{hK8;mVRL+APxf&GA5LgY0#2vXBz&l-`z8Xo=r*brxAW@IV)CdLTP6{a6 z6qB?s?{W2acR&arK($E#VmS7=`U^KeaP4u+OsLQEBo!Nd;9_X| z1gr$6OAtU~A9cxS0PlB27u`l0pG!aml8)I{$qV~kq;!o6`f?!GESiQ8ShE~x9LP0` zc33+&j!alVU)rn|849)j0E`)M{r{|Am zmmfC^y!^td*~Qn7vN!6v-Q&<-Ns~9}is(0Hzk}(FB-UTz&sS zDVSPZeg6UkQ;Vw)UrCNj`kCmBN7yZc&sYY07%a}X`qqUyU^wIITNfZ0&ba#2Mfdr0 zE}gp4Nji0%bM<`-2x@@p)CGvBIOpQj)gFhnBx2&c%kwJ=%O9$`|G`J9ep`O;!(;!o ziayQ9azgij^K@R3y_ffZTnHu!2Wh6qJzh`|r5GLn-)OM4n&%Y9*83@#2OA64BCJ*P|E;xIT z02RKAl2ci?itjxAg{~B%-gjQ>Ho;GHJ>c)7+orNX>F+)L#Us_DG5Fq-pOsSIaY1hO z_%TmCngJtzAW&xzK#WSWr_W-5XuR2LuQC^aa6+@EAMpU;gkzqk9s>a3gkxS&m!yo- zB5L@Aiqq&9)0kIz!Zt&Lf5L<*YNDAFCQJd*%n1rp3Zf!HEqW>fz}^;1L{qWFL=j3s z)MBCtP^#*wNcr(Iaw=X@L{ssM2_+z?0jf{}gym-_l%_g3D1Wj|uWGgW^A<&#@ssYleKKemF_K{Vj4l?*z0Z6C%SVrlP z6_T0LeXd^ofj|hTVgV4oo$e=!<$4JSuIWC${-@;=5KPm3q-Er%g`wQ4W<|4Su@};_ zEC*RM%h#!$P{z|NUq6xnf@7AC&*hahaQkdu-x5Oku>zp6hSv7kmWjME+Yi-c6qUg= z+s7Lyn9{Hgu-4aKz5ts1hql+wDmSB&+)l>rwTc}@d6qu%A(A%M$z4Hj$dSkh7zW8C>WGc z7@22${Y^_KGp2xs>0(NlJY%h*OXD+ss1g{c4XS5+eAKdsqPsZs7W#RoGyhY|cC++C zWH;nRtC*Ismwmq2S7}LLu)OU1>bqq?ik(HizEew#3J|D^rW9a27y0_4Ndi=;^Yu5! z5-WiUU=pP1DqrUprew^M1o)L)72<%vs;C+{8tC1tzEHnWAqE;<2-Hs-qyU_+`dB#W zLRpM%cuRc#mM;+3_%;^;j0+^nn}G235?_DW0tmV#zW#v{Aevj^+^?q6>pGbll@Ax`9DzOr% zjItC!mXJ3EmE-^G9P}yoJkTsC4R-T8|8K19~o+sxqfm8(~#`ClnWz716 zV$fx1fu!{Z5T4J_j8LA(UIey^)mhKWAKR?3o@dhY?d~ua_G!MNsKK~%=X!6n;-=`myV6;_|Z>=wSD1E}H0D)SxWd-~`Rrx4#@9nGbqKeQnZ0T?%0M{^nB zAK8G005v}L)7gkdGI5K~w`Ltpvv`Z|x6*EtdBjhAQLY`W@`w(a80Kt>2EUqt)-BtfTSa8N&6ytfL_ShAJ;17 zX!+BJJ$40FzixoQtiTXJV~<*aDWDPaq4;kcSc0^)k_2c367@DCYsf0{XF}v?nEj>C z_hlVT+cE^k(R7Rc($|S=)CSv^ewlg`07O84>EnxF%Y1P$QtN!qpuU;Bml)hU!UwHRs!{jniN3eppQ?~)JVAG*F$zr07C-;m8T^QRReii zwIZis_P0Jimh~&0Q6MmWrAOUweVqX-mXEsM`mNQ$0uX-vmJSxmuXyPJS+`@^_;tyx zN32_2>DHzkL0bCtJL^|eK_9-)6_BHk`r>9C(XNc>W?x(_KPD(f>gc%7)ti4YB@vJN zi2}8f$qZ611hs^eb1KG}>14F{1=gw0NjgExO-5b}av?M%EY})8Mkilj6@7lR8nmk9 zLTE_XS!+}bIQvHNNZyGDuAVm)M=~MXej_`O$;CL(jm5l z%$ywK7fM$Hfe=uI8X(vv$Mo+j0Kqjm)ii7|j%hJmK57&P{5~_<_%fUP)0vin_Qsi(g4{6EQqa~o zlPGpGj8&`9n;XlU7foNpcBSUVkgs{72-dZtj;_xhNI|_mrmt6kpk5y< zQLm1GpkA*A02DOZ8)AHJT%E>&QF}uS7tSd@1|66h*_-**8*G|0YOfg=DMw)Mjp^TW zNC8y$#){QANdcPL8^c0FV=D!?*YAzB?;WJ@vmzycbN0qM^a{4oZ!Sp$lKq(*-e$M4 z^#0uD=)$)@w>g>+`*WKkzwgg&j?xJGbDLxI;IyBbt4r$UAea*uJxia)KWcFgKE=W7 z;;j$<;i2DD4S6ur@g0`((kNEJNY>G1aZX&{uB8B0%!!w%H$f?Y6?5XaFw&$U0q`?% z(JSi&+PfjJoOEk^CYO`;?`PsAYEGmjha|zjL}Ez65yiztSyI}kAh4u#fsArVX|Ian zC3FZ-gF(Ah6d!OQeT>CL>(F~4p0_5>O21+`ze0F;RMdAR+f(>LJk~CF6hYUT;$cD5 zW)*vE3-&@l&$+6&`BNic(c zR0&LN)I~>Ev03Rl(iy z1u$Z99FM^C^Jx;G#ih}>1~zus(p)AArlq;vq2ON{*T0C8ieOqAM=oTK@eBmZqRZE? zz1J?wrJ@*GmPF8*^oUKCt|S&6E+ z+rs~uX!lxnUAIi!3xc8`ZVJ$qOdMB+!P&ZK=-ueL_t{Uoy&L!9Id$nY_HG=fhJo3- zkgSZBzRxZnwKDD{a_W+cR>tv39R)a4)-n9Y@t>2qX`Q&{!~X>r(v|rD diff --git a/csharp/src/Google.Protobuf/Reflection/Descriptor.pb.cs b/csharp/src/Google.Protobuf/Reflection/Descriptor.pb.cs index 944378a2bb917..88fc88a3cebd9 100644 --- a/csharp/src/Google.Protobuf/Reflection/Descriptor.pb.cs +++ b/csharp/src/Google.Protobuf/Reflection/Descriptor.pb.cs @@ -227,15 +227,16 @@ static DescriptorReflection() { "aWxlGAIgASgJEg0KBWJlZ2luGAMgASgFEgsKA2VuZBgEIAEoBRJICghzZW1h", "bnRpYxgFIAEoDjI2Lmdvb2dsZS5wcm90b2J1Zi5HZW5lcmF0ZWRDb2RlSW5m", "by5Bbm5vdGF0aW9uLlNlbWFudGljIigKCFNlbWFudGljEggKBE5PTkUQABIH", - "CgNTRVQQARIJCgVBTElBUxACKv8BCgdFZGl0aW9uEhMKD0VESVRJT05fVU5L", + "CgNTRVQQARIJCgVBTElBUxACKpICCgdFZGl0aW9uEhMKD0VESVRJT05fVU5L", "Tk9XThAAEhMKDkVESVRJT05fUFJPVE8yEOYHEhMKDkVESVRJT05fUFJPVE8z", - "EOcHEhEKDEVESVRJT05fMjAyMxDoBxIXChNFRElUSU9OXzFfVEVTVF9PTkxZ", - "EAESFwoTRURJVElPTl8yX1RFU1RfT05MWRACEh0KF0VESVRJT05fOTk5OTdf", - "VEVTVF9PTkxZEJ2NBhIdChdFRElUSU9OXzk5OTk4X1RFU1RfT05MWRCejQYS", - "HQoXRURJVElPTl85OTk5OV9URVNUX09OTFkQn40GEhMKC0VESVRJT05fTUFY", - "EP////8HQn4KE2NvbS5nb29nbGUucHJvdG9idWZCEERlc2NyaXB0b3JQcm90", - "b3NIAVotZ29vZ2xlLmdvbGFuZy5vcmcvcHJvdG9idWYvdHlwZXMvZGVzY3Jp", - "cHRvcnBi+AEBogIDR1BCqgIaR29vZ2xlLlByb3RvYnVmLlJlZmxlY3Rpb24=")); + "EOcHEhEKDEVESVRJT05fMjAyMxDoBxIRCgxFRElUSU9OXzIwMjQQ6QcSFwoT", + "RURJVElPTl8xX1RFU1RfT05MWRABEhcKE0VESVRJT05fMl9URVNUX09OTFkQ", + "AhIdChdFRElUSU9OXzk5OTk3X1RFU1RfT05MWRCdjQYSHQoXRURJVElPTl85", + "OTk5OF9URVNUX09OTFkQno0GEh0KF0VESVRJT05fOTk5OTlfVEVTVF9PTkxZ", + "EJ+NBhITCgtFRElUSU9OX01BWBD/////B0J+ChNjb20uZ29vZ2xlLnByb3Rv", + "YnVmQhBEZXNjcmlwdG9yUHJvdG9zSAFaLWdvb2dsZS5nb2xhbmcub3JnL3By", + "b3RvYnVmL3R5cGVzL2Rlc2NyaXB0b3JwYvgBAaICA0dQQqoCGkdvb2dsZS5Q", + "cm90b2J1Zi5SZWZsZWN0aW9u")); descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData, new pbr::FileDescriptor[] { }, new pbr::GeneratedClrTypeInfo(new[] {typeof(global::Google.Protobuf.Reflection.Edition), }, null, new pbr::GeneratedClrTypeInfo[] { @@ -291,6 +292,7 @@ public enum Edition { /// comparison. /// [pbr::OriginalName("EDITION_2023")] _2023 = 1000, + [pbr::OriginalName("EDITION_2024")] _2024 = 1001, /// /// Placeholder editions for testing feature resolution. These should not be /// used or relyed on outside of tests. diff --git a/php/ext/google/protobuf/php-upb.c b/php/ext/google/protobuf/php-upb.c index 99db650a26c3e..66858595782bf 100644 --- a/php/ext/google/protobuf/php-upb.c +++ b/php/ext/google/protobuf/php-upb.c @@ -1558,13 +1558,14 @@ static const upb_MiniTable *messages_layout[32] = { const upb_MiniTableEnum google_protobuf_Edition_enum_init = { 64, - 7, + 8, { 0x7, 0x0, 0x3e6, 0x3e7, 0x3e8, + 0x3e9, 0x1869d, 0x1869e, 0x1869f, @@ -1754,7 +1755,7 @@ const upb_MiniTableFile google_protobuf_descriptor_proto_upb_file_layout = { * regenerated. */ -static const char descriptor[11595] = {'\n', ' ', 'g', 'o', 'o', 'g', 'l', 'e', '/', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '/', 'd', 'e', 's', 'c', 'r', 'i', 'p', +static const char descriptor[11614] = {'\n', ' ', 'g', 'o', 'o', 'g', 'l', 'e', '/', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '/', 'd', 'e', 's', 'c', 'r', 'i', 'p', 't', 'o', 'r', '.', 'p', 'r', 'o', 't', 'o', '\022', '\017', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '\"', 'M', '\n', '\021', 'F', 'i', 'l', 'e', 'D', 'e', 's', 'c', 'r', 'i', 'p', 't', 'o', 'r', 'S', 'e', 't', '\022', '8', '\n', '\004', 'f', 'i', 'l', 'e', '\030', '\001', ' ', '\003', '(', '\013', '2', '$', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', @@ -2202,22 +2203,23 @@ static const char descriptor[11595] = {'\n', ' ', 'g', 'o', 'o', 'g', 'l', 'e', 'a', 't', 'e', 'd', 'C', 'o', 'd', 'e', 'I', 'n', 'f', 'o', '.', 'A', 'n', 'n', 'o', 't', 'a', 't', 'i', 'o', 'n', '.', 'S', 'e', 'm', 'a', 'n', 't', 'i', 'c', 'R', '\010', 's', 'e', 'm', 'a', 'n', 't', 'i', 'c', '\"', '(', '\n', '\010', 'S', 'e', 'm', 'a', 'n', 't', 'i', 'c', '\022', '\010', '\n', '\004', 'N', 'O', 'N', 'E', '\020', '\000', '\022', '\007', '\n', '\003', 'S', 'E', 'T', '\020', '\001', '\022', '\t', -'\n', '\005', 'A', 'L', 'I', 'A', 'S', '\020', '\002', '*', '\377', '\001', '\n', '\007', 'E', 'd', 'i', 't', 'i', 'o', 'n', '\022', '\023', '\n', '\017', +'\n', '\005', 'A', 'L', 'I', 'A', 'S', '\020', '\002', '*', '\222', '\002', '\n', '\007', 'E', 'd', 'i', 't', 'i', 'o', 'n', '\022', '\023', '\n', '\017', 'E', 'D', 'I', 'T', 'I', 'O', 'N', '_', 'U', 'N', 'K', 'N', 'O', 'W', 'N', '\020', '\000', '\022', '\023', '\n', '\016', 'E', 'D', 'I', 'T', 'I', 'O', 'N', '_', 'P', 'R', 'O', 'T', 'O', '2', '\020', '\346', '\007', '\022', '\023', '\n', '\016', 'E', 'D', 'I', 'T', 'I', 'O', 'N', '_', 'P', 'R', 'O', 'T', 'O', '3', '\020', '\347', '\007', '\022', '\021', '\n', '\014', 'E', 'D', 'I', 'T', 'I', 'O', 'N', '_', '2', '0', '2', '3', -'\020', '\350', '\007', '\022', '\027', '\n', '\023', 'E', 'D', 'I', 'T', 'I', 'O', 'N', '_', '1', '_', 'T', 'E', 'S', 'T', '_', 'O', 'N', 'L', -'Y', '\020', '\001', '\022', '\027', '\n', '\023', 'E', 'D', 'I', 'T', 'I', 'O', 'N', '_', '2', '_', 'T', 'E', 'S', 'T', '_', 'O', 'N', 'L', -'Y', '\020', '\002', '\022', '\035', '\n', '\027', 'E', 'D', 'I', 'T', 'I', 'O', 'N', '_', '9', '9', '9', '9', '7', '_', 'T', 'E', 'S', 'T', -'_', 'O', 'N', 'L', 'Y', '\020', '\235', '\215', '\006', '\022', '\035', '\n', '\027', 'E', 'D', 'I', 'T', 'I', 'O', 'N', '_', '9', '9', '9', '9', -'8', '_', 'T', 'E', 'S', 'T', '_', 'O', 'N', 'L', 'Y', '\020', '\236', '\215', '\006', '\022', '\035', '\n', '\027', 'E', 'D', 'I', 'T', 'I', 'O', -'N', '_', '9', '9', '9', '9', '9', '_', 'T', 'E', 'S', 'T', '_', 'O', 'N', 'L', 'Y', '\020', '\237', '\215', '\006', '\022', '\023', '\n', '\013', -'E', 'D', 'I', 'T', 'I', 'O', 'N', '_', 'M', 'A', 'X', '\020', '\377', '\377', '\377', '\377', '\007', 'B', '~', '\n', '\023', 'c', 'o', 'm', '.', -'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', 'B', '\020', 'D', 'e', 's', 'c', 'r', 'i', 'p', 't', -'o', 'r', 'P', 'r', 'o', 't', 'o', 's', 'H', '\001', 'Z', '-', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'g', 'o', 'l', 'a', 'n', 'g', -'.', 'o', 'r', 'g', '/', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '/', 't', 'y', 'p', 'e', 's', '/', 'd', 'e', 's', 'c', 'r', -'i', 'p', 't', 'o', 'r', 'p', 'b', '\370', '\001', '\001', '\242', '\002', '\003', 'G', 'P', 'B', '\252', '\002', '\032', 'G', 'o', 'o', 'g', 'l', 'e', -'.', 'P', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'R', 'e', 'f', 'l', 'e', 'c', 't', 'i', 'o', 'n', +'\020', '\350', '\007', '\022', '\021', '\n', '\014', 'E', 'D', 'I', 'T', 'I', 'O', 'N', '_', '2', '0', '2', '4', '\020', '\351', '\007', '\022', '\027', '\n', +'\023', 'E', 'D', 'I', 'T', 'I', 'O', 'N', '_', '1', '_', 'T', 'E', 'S', 'T', '_', 'O', 'N', 'L', 'Y', '\020', '\001', '\022', '\027', '\n', +'\023', 'E', 'D', 'I', 'T', 'I', 'O', 'N', '_', '2', '_', 'T', 'E', 'S', 'T', '_', 'O', 'N', 'L', 'Y', '\020', '\002', '\022', '\035', '\n', +'\027', 'E', 'D', 'I', 'T', 'I', 'O', 'N', '_', '9', '9', '9', '9', '7', '_', 'T', 'E', 'S', 'T', '_', 'O', 'N', 'L', 'Y', '\020', +'\235', '\215', '\006', '\022', '\035', '\n', '\027', 'E', 'D', 'I', 'T', 'I', 'O', 'N', '_', '9', '9', '9', '9', '8', '_', 'T', 'E', 'S', 'T', +'_', 'O', 'N', 'L', 'Y', '\020', '\236', '\215', '\006', '\022', '\035', '\n', '\027', 'E', 'D', 'I', 'T', 'I', 'O', 'N', '_', '9', '9', '9', '9', +'9', '_', 'T', 'E', 'S', 'T', '_', 'O', 'N', 'L', 'Y', '\020', '\237', '\215', '\006', '\022', '\023', '\n', '\013', 'E', 'D', 'I', 'T', 'I', 'O', +'N', '_', 'M', 'A', 'X', '\020', '\377', '\377', '\377', '\377', '\007', 'B', '~', '\n', '\023', 'c', 'o', 'm', '.', 'g', 'o', 'o', 'g', 'l', 'e', +'.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', 'B', '\020', 'D', 'e', 's', 'c', 'r', 'i', 'p', 't', 'o', 'r', 'P', 'r', 'o', 't', +'o', 's', 'H', '\001', 'Z', '-', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'g', 'o', 'l', 'a', 'n', 'g', '.', 'o', 'r', 'g', '/', 'p', +'r', 'o', 't', 'o', 'b', 'u', 'f', '/', 't', 'y', 'p', 'e', 's', '/', 'd', 'e', 's', 'c', 'r', 'i', 'p', 't', 'o', 'r', 'p', +'b', '\370', '\001', '\001', '\242', '\002', '\003', 'G', 'P', 'B', '\252', '\002', '\032', 'G', 'o', 'o', 'g', 'l', 'e', '.', 'P', 'r', 'o', 't', 'o', +'b', 'u', 'f', '.', 'R', 'e', 'f', 'l', 'e', 'c', 't', 'i', 'o', 'n', }; static _upb_DefPool_Init *deps[1] = { @@ -2228,7 +2230,7 @@ _upb_DefPool_Init google_protobuf_descriptor_proto_upbdefinit = { deps, &google_protobuf_descriptor_proto_upb_file_layout, "google/protobuf/descriptor.proto", - UPB_STRINGVIEW_INIT(descriptor, 11595) + UPB_STRINGVIEW_INIT(descriptor, 11614) }; diff --git a/php/ext/google/protobuf/php-upb.h b/php/ext/google/protobuf/php-upb.h index 872581a1bf422..a97197ba9cab7 100644 --- a/php/ext/google/protobuf/php-upb.h +++ b/php/ext/google/protobuf/php-upb.h @@ -4410,6 +4410,7 @@ typedef enum { google_protobuf_EDITION_PROTO2 = 998, google_protobuf_EDITION_PROTO3 = 999, google_protobuf_EDITION_2023 = 1000, + google_protobuf_EDITION_2024 = 1001, google_protobuf_EDITION_99997_TEST_ONLY = 99997, google_protobuf_EDITION_99998_TEST_ONLY = 99998, google_protobuf_EDITION_99999_TEST_ONLY = 99999, diff --git a/ruby/ext/google/protobuf_c/ruby-upb.c b/ruby/ext/google/protobuf_c/ruby-upb.c index 6c848d83fe068..4e9b711b3f7f0 100644 --- a/ruby/ext/google/protobuf_c/ruby-upb.c +++ b/ruby/ext/google/protobuf_c/ruby-upb.c @@ -1558,13 +1558,14 @@ static const upb_MiniTable *messages_layout[32] = { const upb_MiniTableEnum google_protobuf_Edition_enum_init = { 64, - 7, + 8, { 0x7, 0x0, 0x3e6, 0x3e7, 0x3e8, + 0x3e9, 0x1869d, 0x1869e, 0x1869f, diff --git a/ruby/ext/google/protobuf_c/ruby-upb.h b/ruby/ext/google/protobuf_c/ruby-upb.h index 397804a33987c..4598f3b56b358 100755 --- a/ruby/ext/google/protobuf_c/ruby-upb.h +++ b/ruby/ext/google/protobuf_c/ruby-upb.h @@ -4812,6 +4812,7 @@ typedef enum { google_protobuf_EDITION_PROTO2 = 998, google_protobuf_EDITION_PROTO3 = 999, google_protobuf_EDITION_2023 = 1000, + google_protobuf_EDITION_2024 = 1001, google_protobuf_EDITION_99997_TEST_ONLY = 99997, google_protobuf_EDITION_99998_TEST_ONLY = 99998, google_protobuf_EDITION_99999_TEST_ONLY = 99999, diff --git a/upb/cmake/google/protobuf/descriptor.upb.h b/upb/cmake/google/protobuf/descriptor.upb.h index 8b28ffe3ca7f7..9c68ad9a96b65 100644 --- a/upb/cmake/google/protobuf/descriptor.upb.h +++ b/upb/cmake/google/protobuf/descriptor.upb.h @@ -59,6 +59,7 @@ typedef enum { google_protobuf_EDITION_PROTO2 = 998, google_protobuf_EDITION_PROTO3 = 999, google_protobuf_EDITION_2023 = 1000, + google_protobuf_EDITION_2024 = 1001, google_protobuf_EDITION_99997_TEST_ONLY = 99997, google_protobuf_EDITION_99998_TEST_ONLY = 99998, google_protobuf_EDITION_99999_TEST_ONLY = 99999, diff --git a/upb/cmake/google/protobuf/descriptor.upb_minitable.c b/upb/cmake/google/protobuf/descriptor.upb_minitable.c index 15ce57c0e03c1..390c739c04e2b 100644 --- a/upb/cmake/google/protobuf/descriptor.upb_minitable.c +++ b/upb/cmake/google/protobuf/descriptor.upb_minitable.c @@ -1166,13 +1166,14 @@ static const upb_MiniTable *messages_layout[32] = { const upb_MiniTableEnum google_protobuf_Edition_enum_init = { 64, - 7, + 8, { 0x7, 0x0, 0x3e6, 0x3e7, 0x3e8, + 0x3e9, 0x1869d, 0x1869e, 0x1869f, From c24d9de3ce2c5604d4e77c19098f57eba1cc6a06 Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Wed, 10 Jan 2024 17:29:24 -0800 Subject: [PATCH 247/255] Add proto2::VisitFields() API. PiperOrigin-RevId: 597398441 --- src/google/protobuf/extension_set.h | 6 +++++- src/google/protobuf/message.h | 6 ++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/google/protobuf/extension_set.h b/src/google/protobuf/extension_set.h index 79754ba2752b6..e85370a412ccb 100644 --- a/src/google/protobuf/extension_set.h +++ b/src/google/protobuf/extension_set.h @@ -60,8 +60,10 @@ class Reflection; // message.h class UnknownFieldSet; // unknown_field_set.h class FeatureSet; namespace internal { -class FieldSkipper; // wire_format_lite.h +class FieldSkipper; // wire_format_lite.h +class ReflectionVisit; // message_reflection_util.h class WireFormat; +struct DynamicExtensionInfoHelper; void InitializeLazyExtensionSet(); } // namespace internal } // namespace protobuf @@ -530,6 +532,8 @@ class PROTOBUF_EXPORT ExtensionSet { friend class RepeatedEnumTypeTraits; friend class google::protobuf::Reflection; + friend class google::protobuf::internal::ReflectionVisit; + friend struct google::protobuf::internal::DynamicExtensionInfoHelper; friend class google::protobuf::internal::WireFormat; friend void internal::InitializeLazyExtensionSet(); diff --git a/src/google/protobuf/message.h b/src/google/protobuf/message.h index adfc8d1533537..bbcc2da15f10e 100644 --- a/src/google/protobuf/message.h +++ b/src/google/protobuf/message.h @@ -138,8 +138,11 @@ class TextFormat; namespace internal { struct FuzzPeer; struct DescriptorTable; +template +struct DynamicFieldInfoHelper; class MapFieldBase; class MessageUtil; +class ReflectionVisit; class SwapFieldHelper; class CachedSize; struct TailCallTableInfo; @@ -979,6 +982,7 @@ class PROTOBUF_EXPORT Reflection final { friend class FastReflectionBase; friend class FastReflectionMessageMutator; + friend class internal::ReflectionVisit; friend bool internal::IsDescendant(Message& root, const Message& message); const Descriptor* const descriptor_; @@ -1034,6 +1038,8 @@ class PROTOBUF_EXPORT Reflection final { friend class internal::WireFormat; friend class internal::ReflectionOps; friend class internal::SwapFieldHelper; + template + friend struct internal::DynamicFieldInfoHelper; friend struct internal::FuzzPeer; // Needed for implementing text format for map. friend class internal::MapFieldPrinterHelper; From 27275da1c0033331e55277613f32457b2500e811 Mon Sep 17 00:00:00 2001 From: Hong Shin Date: Wed, 10 Jan 2024 17:44:47 -0800 Subject: [PATCH 248/255] Fix typos in printer.h PiperOrigin-RevId: 597400870 --- src/google/protobuf/io/printer.cc | 2 +- src/google/protobuf/io/printer.h | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/google/protobuf/io/printer.cc b/src/google/protobuf/io/printer.cc index 5e58b15fb0ab7..fea055ab78a66 100644 --- a/src/google/protobuf/io/printer.cc +++ b/src/google/protobuf/io/printer.cc @@ -1,5 +1,5 @@ // Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. +// Copyright 2024 Google LLC. All rights reserved. // // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file or at diff --git a/src/google/protobuf/io/printer.h b/src/google/protobuf/io/printer.h index c64c479b9de3d..1d75b1a2a2eca 100644 --- a/src/google/protobuf/io/printer.h +++ b/src/google/protobuf/io/printer.h @@ -1,5 +1,5 @@ // Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. +// Copyright 2024 Google LLC. All rights reserved. // // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file or at @@ -149,12 +149,12 @@ class AnnotationProtoCollector : public AnnotationCollector { // A source code printer for assisting in code generation. // -// This type implements a simple templating language for substiting variables +// This type implements a simple templating language for substituting variables // into static, user-provided strings, and also tracks indentation // automatically. // // The main entry-point for this type is the Emit function, which can be used -// thus: +// as thus: // // Printer p(output); // p.Emit({{"class", my_class_name}}, R"cc( From 8615daab29b2b481196ba7702fb46111c3615b55 Mon Sep 17 00:00:00 2001 From: Jakob Buchgraber Date: Thu, 11 Jan 2024 01:57:05 -0800 Subject: [PATCH 249/255] #rust #unsafe Fix unsound cast of RepeatedMut to RepeatedView When we implement Deref for RepeatedMut we cast it to a RepeatedView. The safety comments state that this is sound because both RepeatdView and RepeatedMut are repr(transparent) over InnerRepeatedMut. However, this has no longer been true after a recent change. RepeatedView and RepeatedMut had different layouts. This change fixes the soundness issue by type casting the RawRepeatedField of a RepeatedMut to a RepeatedView. This is sound because RepeatedReview is repr(transparent) over RawRepeatedField. PiperOrigin-RevId: 597488476 --- rust/repeated.rs | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/rust/repeated.rs b/rust/repeated.rs index 91ef0ae2d485d..00b827d2b59ec 100644 --- a/rust/repeated.rs +++ b/rust/repeated.rs @@ -46,7 +46,6 @@ impl<'msg, T: ?Sized> Debug for RepeatedView<'msg, T> { } /// Mutates the elements in a `repeated` field of `T`. -#[repr(transparent)] pub struct RepeatedMut<'msg, T: ?Sized> { pub(crate) inner: InnerRepeatedMut<'msg>, _phantom: PhantomData<&'msg mut T>, @@ -58,12 +57,9 @@ impl<'msg, T: ?Sized> Deref for RepeatedMut<'msg, T> { type Target = RepeatedView<'msg, T>; fn deref(&self) -> &Self::Target { // SAFETY: - // - `Repeated{View,Mut}<'msg, T>` are both `#[repr(transparent)]` over - // `RepeatedField<'msg, T>`. - // - `Repeated{View,Mut}<'msg, T>` are both `#[repr(transparent)]` over - // `RepeatedField<'msg, T>`. - // - `RepeatedField` is a type alias for `NonNull`. - unsafe { &*(self as *const Self as *const RepeatedView<'msg, T>) } + // - `RepeatedView<'msg, T>` is `#[repr(transparent)]` over + // `RawRepeatedField`. + unsafe { &*(&self.inner.raw as *const RawRepeatedField as *const RepeatedView<'msg, T>) } } } From f4b042feb3e2c0a4b4036490b09b066ad3c55ad6 Mon Sep 17 00:00:00 2001 From: Alyssa Haroldsen Date: Thu, 11 Jan 2024 02:07:07 -0800 Subject: [PATCH 250/255] Improve user friendliness of oneof mutator types PiperOrigin-RevId: 597490580 --- src/google/protobuf/compiler/rust/oneof.cc | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/google/protobuf/compiler/rust/oneof.cc b/src/google/protobuf/compiler/rust/oneof.cc index 7f5d90f2ae8a2..a6a32d8a60006 100644 --- a/src/google/protobuf/compiler/rust/oneof.cc +++ b/src/google/protobuf/compiler/rust/oneof.cc @@ -74,6 +74,7 @@ namespace rust { // } namespace { +// A user-friendly rust type for a view of this field with lifetime 'msg. std::string RsTypeNameView(Context& ctx, const FieldDescriptor& field) { if (field.options().has_ctype()) { return ""; // TODO: b/308792377 - ctype fields not supported yet. @@ -108,6 +109,7 @@ std::string RsTypeNameView(Context& ctx, const FieldDescriptor& field) { return ""; } +// A user-friendly rust type for a mutator of this field with lifetime 'msg. std::string RsTypeNameMut(Context& ctx, const FieldDescriptor& field) { if (field.options().has_ctype()) { return ""; // TODO: b/308792377 - ctype fields not supported yet. @@ -126,8 +128,12 @@ std::string RsTypeNameMut(Context& ctx, const FieldDescriptor& field) { case FieldDescriptor::TYPE_FLOAT: case FieldDescriptor::TYPE_DOUBLE: case FieldDescriptor::TYPE_BOOL: + return absl::StrCat("::__pb::PrimitiveMut<'msg, ", RsTypePath(ctx, field), + ">"); case FieldDescriptor::TYPE_BYTES: + return "::__pb::BytesMut<'msg>"; case FieldDescriptor::TYPE_STRING: + return "::__pb::ProtoStrMut<'msg>"; case FieldDescriptor::TYPE_MESSAGE: return absl::StrCat("::__pb::Mut<'msg, ", RsTypePath(ctx, field), ">"); case FieldDescriptor::TYPE_ENUM: // TODO: b/300257770 - Support enums. From 648c20d60225f0fc551c28c6c57e997f6fd76fd9 Mon Sep 17 00:00:00 2001 From: Marcel Hlopko Date: Thu, 11 Jan 2024 03:50:30 -0800 Subject: [PATCH 251/255] Pass crate mapping from Bazel to protoc This will enable us to get the correct crate names for Rust gencode. The actual reading of the mapping file in protoc happens in the followup. PiperOrigin-RevId: 597509582 --- .github/workflows/test_rust.yml | 2 +- rust/BUILD | 4 +- rust/aspects.bzl | 100 +++++++++++++++++- rust/defs.bzl | 8 +- .../grandparent1.proto | 10 ++ .../grandparent2.proto | 10 ++ .../rust_proto_library_unit_test.bzl | 76 +++++++++++-- src/google/protobuf/compiler/main.cc | 2 +- 8 files changed, 192 insertions(+), 20 deletions(-) create mode 100644 rust/test/rust_proto_library_unit_test/grandparent1.proto create mode 100644 rust/test/rust_proto_library_unit_test/grandparent2.proto diff --git a/.github/workflows/test_rust.yml b/.github/workflows/test_rust.yml index d86acb0a00476..a82ff2c434f37 100644 --- a/.github/workflows/test_rust.yml +++ b/.github/workflows/test_rust.yml @@ -23,7 +23,7 @@ jobs: - name: Run tests uses: protocolbuffers/protobuf-ci/bazel-docker@v2 with: - image: us-docker.pkg.dev/protobuf-build/containers/common/linux/bazel:6.3.0-91a0ac83e968068672bc6001a4d474cfd9a50f1d + image: "us-docker.pkg.dev/protobuf-build/containers/common/linux/bazel:7.0.0-a04396cc76704d4b7c722789e9c08df18f47df53" credentials: ${{ secrets.GAR_SERVICE_ACCOUNT }} bazel-cache: rust_linux bazel: >- diff --git a/rust/BUILD b/rust/BUILD index 62ae297d66452..165640694b8a5 100644 --- a/rust/BUILD +++ b/rust/BUILD @@ -127,7 +127,7 @@ rust_library( proto_lang_toolchain( name = "proto_rust_upb_toolchain", - command_line = "--rust_out=experimental-codegen=enabled,kernel=upb:$(OUT)", + command_line = "--rust_out=$(OUT)", progress_message = "Generating Rust proto_library %{label}", runtime = ":protobuf_upb", visibility = ["//visibility:public"], @@ -135,7 +135,7 @@ proto_lang_toolchain( proto_lang_toolchain( name = "proto_rust_cpp_toolchain", - command_line = "--rust_out=experimental-codegen=enabled,kernel=cpp:$(OUT)", + command_line = "--rust_out=$(OUT)", progress_message = "Generating Rust proto_library %{label}", runtime = ":protobuf_cpp", visibility = ["//visibility:public"], diff --git a/rust/aspects.bzl b/rust/aspects.bzl index 0399c12c6d7b1..a873c6d2f85eb 100644 --- a/rust/aspects.bzl +++ b/rust/aspects.bzl @@ -15,18 +15,67 @@ proto_common = proto_common_do_not_use visibility(["//rust/..."]) +CrateMappingInfo = provider( + doc = "Struct mapping crate name to the .proto import paths", + fields = { + "crate_name": "Crate name of the proto_library target", + "import_paths": "Import path used in .proto files of dependants to import the .proto " + + "file of the current proto_library.", + }, +) RustProtoInfo = provider( doc = "Rust protobuf provider info", fields = { "dep_variant_info": "DepVariantInfo for the compiled Rust gencode (also covers its " + "transitive dependencies)", + "crate_mapping": "depset(CrateMappingInfo) containing mappings of all transitive " + + "dependencies of the current proto_library.", }, ) +def _register_crate_mapping_write_action(name, actions, crate_mappings): + """Registers an action that generates a crate mapping for a proto_library. + + Args: + name: The name of the target being analyzed. + actions: The context's actions object. + crate_mappings: depset(CrateMappingInfo) to be rendered. + This sequence should already have duplicates removed. + + Returns: + The generated `File` with the crate mapping. + """ + mapping_file = actions.declare_file( + "{}.rust_crate_mapping".format(name), + ) + content = actions.args() + content.set_param_file_format("multiline") + content.add_all(crate_mappings, map_each = _render_text_crate_mapping) + actions.write(content = content, output = mapping_file) + + return mapping_file + +def _render_text_crate_mapping(mapping): + """Renders the mapping to an easily parseable file for a crate mapping. + + Args: + mapping (CrateMappingInfo): A single crate mapping. + + Returns: + A string containing the crate mapping for the target in simple format: + \n + \n + \n + """ + crate_name = mapping.crate_name + import_paths = mapping.import_paths + return "\n".join(([crate_name, str(len(import_paths))] + list(import_paths))) + def _generate_rust_gencode( ctx, proto_info, proto_lang_toolchain, + crate_mapping, is_upb): """Generates Rust gencode @@ -37,6 +86,8 @@ def _generate_rust_gencode( proto_info (ProtoInfo): ProtoInfo of the proto_library target for which we are generating gencode proto_lang_toolchain (ProtoLangToolchainInfo): proto lang toolchain for Rust + crate_mapping (File): File containing the mapping from .proto file import path to its + corresponding containing Rust crate name. is_upb (Bool): True when generating gencode for UPB, False otherwise. Returns: rs_outputs (([File], [File]): tuple(generated Rust files, generated C++ thunks). @@ -55,10 +106,20 @@ def _generate_rust_gencode( proto_info = proto_info, extension = ".pb.thunks.cc", ) + additional_args = ctx.actions.args() + + additional_args.add( + "--rust_opt=experimental-codegen=enabled,kernel={},bazel_crate_mapping={}".format( + "upb" if is_upb else "cpp", + crate_mapping.path, + ), + ) proto_common.compile( actions = ctx.actions, proto_info = proto_info, + additional_inputs = depset(direct = [crate_mapping]), + additional_args = additional_args, generated_files = rs_outputs + cc_outputs, proto_lang_toolchain_info = proto_lang_toolchain, plugin_output = ctx.bin_dir.path, @@ -211,6 +272,12 @@ def _rust_cc_proto_aspect_impl(target, ctx): """Implements the Rust protobuf aspect logic for C++ kernel.""" return _rust_proto_aspect_common(target, ctx, is_upb = False) +def get_import_path(f): + if hasattr(proto_common, "get_import_path"): + return proto_common.get_import_path(f) + else: + return f.path + def _rust_proto_aspect_common(target, ctx, is_upb): if RustProtoInfo in target: return [] @@ -231,10 +298,25 @@ def _rust_proto_aspect_common(target, ctx, is_upb): unsupported_features = ctx.disabled_features, ) + proto_srcs = getattr(ctx.rule.files, "srcs", []) + proto_deps = getattr(ctx.rule.attr, "deps", []) + transitive_crate_mappings = [] + for dep in proto_deps: + rust_proto_info = dep[RustProtoInfo] + transitive_crate_mappings.append(rust_proto_info.crate_mapping) + + mapping_for_current_target = depset(transitive = transitive_crate_mappings) + crate_mapping_file = _register_crate_mapping_write_action( + target.label.name, + ctx.actions, + mapping_for_current_target, + ) + (gencode, thunks) = _generate_rust_gencode( ctx, target[ProtoInfo], proto_lang_toolchain, + crate_mapping_file, is_upb, ) @@ -259,17 +341,25 @@ def _rust_proto_aspect_common(target, ctx, is_upb): ) dep_variant_info_for_native_gencode = DepVariantInfo(cc_info = thunks_cc_info) - proto_dep = getattr(ctx.rule.attr, "deps", []) dep_variant_info = _compile_rust( ctx = ctx, attr = ctx.rule.attr, src = gencode[0], extra_srcs = gencode[1:], deps = [dep_variant_info_for_runtime, dep_variant_info_for_native_gencode] + ( - [proto_dep[0][RustProtoInfo].dep_variant_info] if proto_dep else [] + [proto_deps[0][RustProtoInfo].dep_variant_info] if proto_deps else [] ), ) - return [RustProtoInfo(dep_variant_info = dep_variant_info)] + return [RustProtoInfo( + dep_variant_info = dep_variant_info, + crate_mapping = depset( + direct = [CrateMappingInfo( + crate_name = target.label.name, + import_paths = tuple([get_import_path(f) for f in proto_srcs]), + )], + transitive = transitive_crate_mappings, + ), + )] def _make_proto_library_aspect(is_upb): return aspect( @@ -319,7 +409,9 @@ def _make_proto_library_aspect(is_upb): cfg = "exec", ), "_proto_lang_toolchain": attr.label( - default = Label(("//rust:proto_rust_upb_toolchain" if is_upb else "//rust:proto_rust_cpp_toolchain")), + default = Label( + "//rust:proto_rust_upb_toolchain" if is_upb else "//rust:proto_rust_cpp_toolchain", + ), ), }, fragments = ["cpp"], diff --git a/rust/defs.bzl b/rust/defs.bzl index d51829bb83015..7541c9986fb1c 100644 --- a/rust/defs.bzl +++ b/rust/defs.bzl @@ -3,13 +3,13 @@ Disclaimer: This project is experimental, under heavy development, and should not be used yet.""" -load("@rules_cc//cc:defs.bzl", "cc_proto_library") load( "//rust:aspects.bzl", "RustProtoInfo", "rust_cc_proto_library_aspect", "rust_upb_proto_library_aspect", ) +load("@rules_cc//cc:defs.bzl", "cc_proto_library") visibility([ "//experimental/...", @@ -72,7 +72,11 @@ def _rust_proto_library_impl(ctx): dep = deps[0] rust_proto_info = dep[RustProtoInfo] dep_variant_info = rust_proto_info.dep_variant_info - return [dep_variant_info.crate_info, dep_variant_info.dep_info, dep_variant_info.cc_info] + return [ + dep_variant_info.crate_info, + dep_variant_info.dep_info, + dep_variant_info.cc_info, + ] def _make_rust_proto_library(is_upb): return rule( diff --git a/rust/test/rust_proto_library_unit_test/grandparent1.proto b/rust/test/rust_proto_library_unit_test/grandparent1.proto new file mode 100644 index 0000000000000..23c31f2552dc1 --- /dev/null +++ b/rust/test/rust_proto_library_unit_test/grandparent1.proto @@ -0,0 +1,10 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2023 Google LLC. All rights reserved. +// +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file or at +// https://developers.google.com/open-source/licenses/bsd + +syntax = "proto2"; + +package third_party_protobuf_rust_test_rust_proto_library_unit_test; diff --git a/rust/test/rust_proto_library_unit_test/grandparent2.proto b/rust/test/rust_proto_library_unit_test/grandparent2.proto new file mode 100644 index 0000000000000..23c31f2552dc1 --- /dev/null +++ b/rust/test/rust_proto_library_unit_test/grandparent2.proto @@ -0,0 +1,10 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2023 Google LLC. All rights reserved. +// +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file or at +// https://developers.google.com/open-source/licenses/bsd + +syntax = "proto2"; + +package third_party_protobuf_rust_test_rust_proto_library_unit_test; diff --git a/rust/test/rust_proto_library_unit_test/rust_proto_library_unit_test.bzl b/rust/test/rust_proto_library_unit_test/rust_proto_library_unit_test.bzl index d43d8dcbf9536..3e24f71b5904e 100644 --- a/rust/test/rust_proto_library_unit_test/rust_proto_library_unit_test.bzl +++ b/rust/test/rust_proto_library_unit_test/rust_proto_library_unit_test.bzl @@ -1,15 +1,58 @@ """This module contains unit tests for rust_proto_library and its aspect.""" load("@bazel_skylib//lib:unittest.bzl", "analysistest", "asserts") -load(":defs.bzl", "ActionsInfo", "attach_cc_aspect", "attach_upb_aspect") load("//rust:aspects.bzl", "RustProtoInfo") load("@rules_cc//cc:defs.bzl", "cc_proto_library") +load(":defs.bzl", "ActionsInfo", "attach_cc_aspect", "attach_upb_aspect") + +def _find_actions_with_mnemonic(actions, mnemonic): + actions = [a for a in actions if a.mnemonic == mnemonic] + if not actions: + fail("Couldn't find action with mnemonic {} among {}".format( + mnemonic, + [a.mnemonic for a in actions], + )) + return actions + +def _check_crate_mapping(actions, target_name): + fw_actions = _find_actions_with_mnemonic(actions, "FileWrite") + crate_mapping_action = None + for a in fw_actions: + outputs = a.outputs.to_list() + output = [o for o in outputs if o.basename == target_name + ".rust_crate_mapping"] + if output: + crate_mapping_action = a + if not crate_mapping_action: + fail("Couldn't find action outputting {}.rust_crate_mapping among {}".format( + target_name, + fw_actions, + )) + expected_content = """grandparent_proto +2 +rust/test/rust_proto_library_unit_test/grandparent1.proto +rust/test/rust_proto_library_unit_test/grandparent2.proto +parent_proto +1 +rust/test/rust_proto_library_unit_test/parent.proto +""" + if crate_mapping_action.content != expected_content: + fail("The crate mapping file content didn't match. Was: {}".format( + crate_mapping_action.content, + )) -def _find_action_with_mnemonic(actions, mnemonic): - action = [a for a in actions if a.mnemonic == mnemonic] - if not action: - fail("Couldn't find action with mnemonic {} among {}".format(mnemonic, actions)) - return action[0] + protoc_action = [ + a + for a in actions + for i in a.inputs.to_list() + if "rust_crate_mapping" in i.basename + ] + if not protoc_action: + fail("Couldn't find action with the rust_crate_mapping as input") + if protoc_action[0].mnemonic != "GenProto": + fail( + "Action that had rust_crate_mapping as input wasn't a GenProto action, but {}", + protoc_action[0].mnemonic, + ) def _find_rust_lib_input(inputs, target_name): inputs = inputs.to_list() @@ -54,7 +97,10 @@ def _rust_upb_aspect_test_impl(ctx): env = analysistest.begin(ctx) target_under_test = analysistest.target_under_test(env) actions = target_under_test[ActionsInfo].actions - rustc_action = _find_action_with_mnemonic(actions, "Rustc") + rustc_action = _find_actions_with_mnemonic(actions, "Rustc")[0] + + # The protoc action needs to be given the crate mapping file + _check_crate_mapping(actions, "child_proto") # The action needs to have the Rust runtime as an input _find_rust_lib_input(rustc_action.inputs, "protobuf") @@ -83,9 +129,11 @@ def _rust_cc_aspect_test_impl(ctx): env = analysistest.begin(ctx) target_under_test = analysistest.target_under_test(env) actions = target_under_test[ActionsInfo].actions - rustc_action = _find_action_with_mnemonic(actions, "Rustc") + rustc_action = _find_actions_with_mnemonic(actions, "Rustc")[0] - # The action needs to have the Rust runtime as an input + _check_crate_mapping(actions, "child_proto") + + # The rustc action needs to have the Rust runtime as an input _find_rust_lib_input(rustc_action.inputs, "protobuf") # The action needs to produce a .rlib artifact (sometimes .rmeta as well, not tested here). @@ -114,7 +162,15 @@ def rust_proto_library_unit_test(name): Args: name: name of the test suite""" - native.proto_library(name = "parent_proto", srcs = ["parent.proto"]) + native.proto_library( + name = "grandparent_proto", + srcs = ["grandparent1.proto", "grandparent2.proto"], + ) + native.proto_library( + name = "parent_proto", + srcs = ["parent.proto"], + deps = [":grandparent_proto"], + ) native.proto_library(name = "child_proto", srcs = ["child.proto"], deps = [":parent_proto"]) cc_proto_library(name = "child_cc_proto", deps = [":child_proto"]) diff --git a/src/google/protobuf/compiler/main.cc b/src/google/protobuf/compiler/main.cc index 0ade6ace805ca..b43b2f15d4061 100644 --- a/src/google/protobuf/compiler/main.cc +++ b/src/google/protobuf/compiler/main.cc @@ -92,7 +92,7 @@ int ProtobufMain(int argc, char* argv[]) { // Rust rust::RustGenerator rust_generator; - cli.RegisterGenerator("--rust_out", &rust_generator, + cli.RegisterGenerator("--rust_out", "--rust_opt", &rust_generator, "Generate Rust sources."); return cli.Run(argc, argv); } From c988f9c0c7a4443a708742cb3b792c8edae16715 Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Thu, 11 Jan 2024 09:00:07 -0800 Subject: [PATCH 252/255] cleanup: reduce warnings on MSVC builds Protobuf sets the `/utf-8` flag in the linker, but this is a compiler flag [^1]. The linker emits a warning, polluting the logs for all downstream projects [^2] with many `LINK : warning LNK4044: unrecognized option '/utf-8'; ignored` lines. [^1]: https://learn.microsoft.com/en-us/cpp/build/reference/utf-8-set-source-and-executable-character-sets-to-utf-8?view=msvc-170 [^2]: For an example, see [this build](https://github.com/googleapis/google-cloud-cpp/actions/runs/7484447749/job/20371331322#step:5:4146) PiperOrigin-RevId: 597570083 --- build_defs/cpp_opts.bzl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build_defs/cpp_opts.bzl b/build_defs/cpp_opts.bzl index 03106df9510c3..17f330bb4175f 100644 --- a/build_defs/cpp_opts.bzl +++ b/build_defs/cpp_opts.bzl @@ -15,6 +15,7 @@ COPTS = select({ "/wd4506", # no definition for inline function 'function' "/wd4800", # 'type' : forcing value to bool 'true' or 'false' (performance warning) "/wd4996", # The compiler encountered a deprecated declaration. + "/utf-8", # Set source and execution character sets to UTF-8 ], "//conditions:default": [ "-DHAVE_ZLIB", @@ -35,7 +36,6 @@ LINK_OPTS = select({ "//build_defs:config_msvc": [ # Suppress linker warnings about files with no symbols defined. "-ignore:4221", - "/utf-8", ], "@platforms//os:macos": [ "-lpthread", From fc982c0177ff34835dc160bf95e87c42603f3c3f Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Thu, 11 Jan 2024 09:01:30 -0800 Subject: [PATCH 253/255] Fix missing ! making it so untyped_message would trigger a invalid Utf8 error IFF the string was _valid_ UTF8. PiperOrigin-RevId: 597570464 --- src/google/protobuf/json/internal/untyped_message.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/google/protobuf/json/internal/untyped_message.cc b/src/google/protobuf/json/internal/untyped_message.cc index ee34a7f215e46..5e8e5944ee423 100644 --- a/src/google/protobuf/json/internal/untyped_message.cc +++ b/src/google/protobuf/json/internal/untyped_message.cc @@ -468,7 +468,7 @@ absl::Status UntypedMessage::DecodeDelimited(io::CodedInputStream& stream, } if (field.proto().kind() == Field::TYPE_STRING) { if (desc_->proto().syntax() == google::protobuf::SYNTAX_PROTO3 && - utf8_range::IsStructurallyValid(buf)) { + !utf8_range::IsStructurallyValid(buf)) { return MakeProto3Utf8Error(); } } From 4270f73aee8de940c0a449284d2c6568cf2c38ec Mon Sep 17 00:00:00 2001 From: Kevin King Date: Thu, 11 Jan 2024 09:12:31 -0800 Subject: [PATCH 254/255] Add `upb_Array_GetMutable` accessor PiperOrigin-RevId: 597573362 --- upb/message/accessors_test.cc | 23 +++++++++++++++++++++++ upb/message/array.c | 9 +++++++++ upb/message/array.h | 4 ++++ 3 files changed, 36 insertions(+) diff --git a/upb/message/accessors_test.cc b/upb/message/accessors_test.cc index 9db6eb5ddc027..59a5e51ad781b 100644 --- a/upb/message/accessors_test.cc +++ b/upb/message/accessors_test.cc @@ -49,6 +49,7 @@ const uint32_t kFieldOptionalBool = 13; const uint32_t kFieldOptionalString = 14; const uint32_t kFieldOptionalNestedMessage = 18; const uint32_t kFieldOptionalRepeatedInt32 = 31; +const uint32_t kFieldOptionalRepeatedNestedMessage = 48; const uint32_t kFieldOptionalNestedMessageA = 1; const uint32_t kFieldOptionalOneOfUInt32 = 111; const uint32_t kFieldOptionalOneOfString = 113; @@ -402,6 +403,28 @@ TEST(GeneratedCode, RepeatedScalar) { upb_Arena_Free(arena); } +TEST(GeneratedCode, RepeatedMessage) { + upb_Arena* arena = upb_Arena_New(); + protobuf_test_messages_proto2_TestAllTypesProto2* msg = + protobuf_test_messages_proto2_TestAllTypesProto2_new(arena); + + const upb_MiniTableField* repeated_nested_message_field = + find_proto2_field(kFieldOptionalRepeatedNestedMessage); + upb_Message* nested_message = (upb_Message*) + protobuf_test_messages_proto2_TestAllTypesProto2_NestedMessage_new(arena); + + upb_Array* array = upb_Message_GetOrCreateMutableArray( + UPB_UPCAST(msg), repeated_nested_message_field, arena); + upb_MessageValue new_value; + new_value.msg_val = nested_message; + EXPECT_TRUE(upb_Array_Append(array, new_value, arena)); + + EXPECT_EQ(nested_message, upb_Array_GetMutable(array, 0).msg); + EXPECT_EQ(nested_message, upb_Array_Get(array, 0).msg_val); + + upb_Arena_Free(arena); +} + TEST(GeneratedCode, GetMutableMessage) { upb_Arena* arena = upb_Arena_New(); protobuf_test_messages_proto2_TestAllTypesProto2* msg = diff --git a/upb/message/array.c b/upb/message/array.c index 45ce299dd0685..79a1e58f843a3 100644 --- a/upb/message/array.c +++ b/upb/message/array.c @@ -40,6 +40,15 @@ upb_MessageValue upb_Array_Get(const upb_Array* arr, size_t i) { return ret; } +upb_MutableMessageValue upb_Array_GetMutable(upb_Array* arr, size_t i) { + upb_MutableMessageValue ret; + char* data = _upb_array_ptr(arr); + const int lg2 = UPB_PRIVATE(_upb_Array_ElemSizeLg2)(arr); + UPB_ASSERT(i < arr->UPB_PRIVATE(size)); + memcpy(&ret, data + (i << lg2), 1 << lg2); + return ret; +} + void upb_Array_Set(upb_Array* arr, size_t i, upb_MessageValue val) { char* data = _upb_array_ptr(arr); const int lg2 = UPB_PRIVATE(_upb_Array_ElemSizeLg2)(arr); diff --git a/upb/message/array.h b/upb/message/array.h index b217bfbcb8ad2..684dfe0b30ffb 100644 --- a/upb/message/array.h +++ b/upb/message/array.h @@ -32,6 +32,10 @@ UPB_API size_t upb_Array_Size(const upb_Array* arr); // Returns the given element, which must be within the array's current size. UPB_API upb_MessageValue upb_Array_Get(const upb_Array* arr, size_t i); +// Returns a mutating pointer to the given element, which must be within the +// array's current size. +UPB_API upb_MutableMessageValue upb_Array_GetMutable(upb_Array* arr, size_t i); + // Sets the given element, which must be within the array's current size. UPB_API void upb_Array_Set(upb_Array* arr, size_t i, upb_MessageValue val); From 06327f0a7c9165a6099c7fd66c89021211de6c77 Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Thu, 11 Jan 2024 17:35:29 +0000 Subject: [PATCH 255/255] Auto-generate files after cl/597573362 --- php/ext/google/protobuf/php-upb.c | 9 +++++++++ php/ext/google/protobuf/php-upb.h | 4 ++++ ruby/ext/google/protobuf_c/ruby-upb.c | 9 +++++++++ ruby/ext/google/protobuf_c/ruby-upb.h | 4 ++++ 4 files changed, 26 insertions(+) diff --git a/php/ext/google/protobuf/php-upb.c b/php/ext/google/protobuf/php-upb.c index 66858595782bf..67493f013fa80 100644 --- a/php/ext/google/protobuf/php-upb.c +++ b/php/ext/google/protobuf/php-upb.c @@ -5084,6 +5084,15 @@ upb_MessageValue upb_Array_Get(const upb_Array* arr, size_t i) { return ret; } +upb_MutableMessageValue upb_Array_GetMutable(upb_Array* arr, size_t i) { + upb_MutableMessageValue ret; + char* data = _upb_array_ptr(arr); + const int lg2 = UPB_PRIVATE(_upb_Array_ElemSizeLg2)(arr); + UPB_ASSERT(i < arr->UPB_PRIVATE(size)); + memcpy(&ret, data + (i << lg2), 1 << lg2); + return ret; +} + void upb_Array_Set(upb_Array* arr, size_t i, upb_MessageValue val) { char* data = _upb_array_ptr(arr); const int lg2 = UPB_PRIVATE(_upb_Array_ElemSizeLg2)(arr); diff --git a/php/ext/google/protobuf/php-upb.h b/php/ext/google/protobuf/php-upb.h index a97197ba9cab7..5a0c05452781b 100644 --- a/php/ext/google/protobuf/php-upb.h +++ b/php/ext/google/protobuf/php-upb.h @@ -870,6 +870,10 @@ UPB_API size_t upb_Array_Size(const upb_Array* arr); // Returns the given element, which must be within the array's current size. UPB_API upb_MessageValue upb_Array_Get(const upb_Array* arr, size_t i); +// Returns a mutating pointer to the given element, which must be within the +// array's current size. +UPB_API upb_MutableMessageValue upb_Array_GetMutable(upb_Array* arr, size_t i); + // Sets the given element, which must be within the array's current size. UPB_API void upb_Array_Set(upb_Array* arr, size_t i, upb_MessageValue val); diff --git a/ruby/ext/google/protobuf_c/ruby-upb.c b/ruby/ext/google/protobuf_c/ruby-upb.c index 4e9b711b3f7f0..8d19b4a15d343 100644 --- a/ruby/ext/google/protobuf_c/ruby-upb.c +++ b/ruby/ext/google/protobuf_c/ruby-upb.c @@ -4599,6 +4599,15 @@ upb_MessageValue upb_Array_Get(const upb_Array* arr, size_t i) { return ret; } +upb_MutableMessageValue upb_Array_GetMutable(upb_Array* arr, size_t i) { + upb_MutableMessageValue ret; + char* data = _upb_array_ptr(arr); + const int lg2 = UPB_PRIVATE(_upb_Array_ElemSizeLg2)(arr); + UPB_ASSERT(i < arr->UPB_PRIVATE(size)); + memcpy(&ret, data + (i << lg2), 1 << lg2); + return ret; +} + void upb_Array_Set(upb_Array* arr, size_t i, upb_MessageValue val) { char* data = _upb_array_ptr(arr); const int lg2 = UPB_PRIVATE(_upb_Array_ElemSizeLg2)(arr); diff --git a/ruby/ext/google/protobuf_c/ruby-upb.h b/ruby/ext/google/protobuf_c/ruby-upb.h index 4598f3b56b358..3f895c38bbea9 100755 --- a/ruby/ext/google/protobuf_c/ruby-upb.h +++ b/ruby/ext/google/protobuf_c/ruby-upb.h @@ -872,6 +872,10 @@ UPB_API size_t upb_Array_Size(const upb_Array* arr); // Returns the given element, which must be within the array's current size. UPB_API upb_MessageValue upb_Array_Get(const upb_Array* arr, size_t i); +// Returns a mutating pointer to the given element, which must be within the +// array's current size. +UPB_API upb_MutableMessageValue upb_Array_GetMutable(upb_Array* arr, size_t i); + // Sets the given element, which must be within the array's current size. UPB_API void upb_Array_Set(upb_Array* arr, size_t i, upb_MessageValue val);