diff --git a/common/type_reflector.cc b/common/type_reflector.cc index 89c363425..f372579e5 100644 --- a/common/type_reflector.cc +++ b/common/type_reflector.cc @@ -17,9 +17,7 @@ #include "absl/base/no_destructor.h" #include "absl/base/nullability.h" #include "absl/status/statusor.h" -#include "absl/strings/cord.h" #include "absl/strings/string_view.h" -#include "absl/types/optional.h" #include "common/memory.h" #include "common/type.h" #include "common/value.h" @@ -33,28 +31,12 @@ absl::StatusOr> TypeReflector::NewValueBuilder( return nullptr; } -absl::StatusOr> TypeReflector::DeserializeValue( - ValueFactory& value_factory, absl::string_view type_url, - const absl::Cord& value) const { - return DeserializeValueImpl(value_factory, type_url, value); -} - -absl::StatusOr> TypeReflector::DeserializeValueImpl( - ValueFactory&, absl::string_view, const absl::Cord&) const { - return absl::nullopt; -} - absl::StatusOr> TypeReflector::NewStructValueBuilder(ValueFactory& value_factory, const StructType& type) const { return nullptr; } -absl::StatusOr TypeReflector::FindValue(ValueFactory&, absl::string_view, - Value&) const { - return false; -} - TypeReflector& TypeReflector::Builtin() { static absl::NoDestructor instance; return *instance; diff --git a/common/type_reflector.h b/common/type_reflector.h index 20b922971..f300548b6 100644 --- a/common/type_reflector.h +++ b/common/type_reflector.h @@ -65,27 +65,10 @@ class TypeReflector : public virtual TypeIntrospector { virtual absl::StatusOr> NewValueBuilder( ValueFactory& value_factory, absl::string_view name) const; - // `FindValue` returns a new `Value` for the corresponding name `name`. This - // can be used to translate enum names to numeric values. - virtual absl::StatusOr FindValue(ValueFactory& value_factory, - absl::string_view name, - Value& result) const; - - // `DeserializeValue` deserializes the bytes of `value` according to - // `type_url`. Returns `NOT_FOUND` if `type_url` is unrecognized. - virtual absl::StatusOr> DeserializeValue( - ValueFactory& value_factory, absl::string_view type_url, - const absl::Cord& value) const; - virtual absl::Nullable descriptor_pool() const { return nullptr; } - - protected: - virtual absl::StatusOr> DeserializeValueImpl( - ValueFactory& value_factory, absl::string_view type_url, - const absl::Cord& value) const; }; Shared NewThreadCompatibleTypeReflector( diff --git a/common/value_manager.h b/common/value_manager.h index d9eee46ac..21b96b894 100644 --- a/common/value_manager.h +++ b/common/value_manager.h @@ -17,9 +17,7 @@ #include "absl/base/nullability.h" #include "absl/status/statusor.h" -#include "absl/strings/cord.h" #include "absl/strings/string_view.h" -#include "absl/types/optional.h" #include "common/json.h" #include "common/memory.h" #include "common/type.h" @@ -63,17 +61,6 @@ class ValueManager : public virtual ValueFactory, return GetTypeReflector().NewValueBuilder(*this, name); } - // See `TypeReflector::FindValue`. - absl::StatusOr FindValue(absl::string_view name, Value& result) { - return GetTypeReflector().FindValue(*this, name, result); - } - - // See `TypeReflector::DeserializeValue`. - absl::StatusOr> DeserializeValue( - absl::string_view type_url, const absl::Cord& value) { - return GetTypeReflector().DeserializeValue(*this, type_url, value); - } - absl::Nullable message_factory() const override = 0; protected: diff --git a/common/values/struct_value_builder.cc b/common/values/struct_value_builder.cc index a8044e6af..50898549b 100644 --- a/common/values/struct_value_builder.cc +++ b/common/values/struct_value_builder.cc @@ -145,37 +145,6 @@ class CompatTypeReflector final : public TypeReflector { name); } - absl::StatusOr> DeserializeValue( - ValueFactory& value_factory, absl::string_view type_url, - const absl::Cord& value) const override { - const auto* descriptor_pool = this->descriptor_pool(); - auto* message_factory = value_factory.message_factory(); - if (message_factory == nullptr) { - return absl::nullopt; - } - absl::string_view type_name; - if (!ParseTypeUrl(type_url, &type_name)) { - return absl::InvalidArgumentError("invalid type URL"); - } - const auto* descriptor = descriptor_pool->FindMessageTypeByName(type_name); - if (descriptor == nullptr) { - return absl::nullopt; - } - const auto* prototype = message_factory->GetPrototype(descriptor); - if (prototype == nullptr) { - return absl::nullopt; - } - absl::Nullable arena = - value_factory.GetMemoryManager().arena(); - auto message = WrapShared(prototype->New(arena), arena); - if (!message->ParsePartialFromCord(value)) { - return absl::InvalidArgumentError( - absl::StrCat("failed to parse `", type_url, "`")); - } - return Value::Message(WrapShared(prototype->New(arena), arena), - descriptor_pool, message_factory); - } - private: const google::protobuf::DescriptorPool* const pool_; }; diff --git a/common/values/thread_compatible_type_reflector.cc b/common/values/thread_compatible_type_reflector.cc index 60bf61925..58485ef03 100644 --- a/common/values/thread_compatible_type_reflector.cc +++ b/common/values/thread_compatible_type_reflector.cc @@ -16,9 +16,6 @@ #include "absl/base/nullability.h" #include "absl/status/statusor.h" -#include "absl/strings/string_view.h" -#include "absl/types/optional.h" -#include "common/memory.h" #include "common/type.h" #include "common/value.h" @@ -30,10 +27,4 @@ ThreadCompatibleTypeReflector::NewStructValueBuilder(ValueFactory&, return nullptr; } -absl::StatusOr ThreadCompatibleTypeReflector::FindValue(ValueFactory&, - absl::string_view, - Value&) const { - return false; -} - } // namespace cel::common_internal diff --git a/common/values/thread_compatible_type_reflector.h b/common/values/thread_compatible_type_reflector.h index f22f5cecb..e265ade55 100644 --- a/common/values/thread_compatible_type_reflector.h +++ b/common/values/thread_compatible_type_reflector.h @@ -19,7 +19,6 @@ #include "absl/base/nullability.h" #include "absl/status/statusor.h" -#include "absl/strings/string_view.h" #include "common/type.h" #include "common/type_reflector.h" #include "common/types/thread_compatible_type_introspector.h" @@ -38,10 +37,6 @@ class ThreadCompatibleTypeReflector : public ThreadCompatibleTypeIntrospector, absl::StatusOr> NewStructValueBuilder( ValueFactory& value_factory, const StructType& type) const override; - - absl::StatusOr FindValue(ValueFactory& value_factory, - absl::string_view name, - Value& result) const override; }; } // namespace common_internal diff --git a/eval/public/structs/legacy_type_provider.cc b/eval/public/structs/legacy_type_provider.cc index fe7ed35cc..e3284c351 100644 --- a/eval/public/structs/legacy_type_provider.cc +++ b/eval/public/structs/legacy_type_provider.cc @@ -21,12 +21,9 @@ #include "absl/base/nullability.h" #include "absl/status/status.h" #include "absl/status/statusor.h" -#include "absl/strings/cord.h" #include "absl/strings/str_cat.h" #include "absl/strings/string_view.h" -#include "absl/strings/strip.h" #include "absl/types/optional.h" -#include "common/any.h" #include "common/legacy_value.h" #include "common/memory.h" #include "common/type.h" @@ -173,39 +170,6 @@ LegacyTypeProvider::NewStructValueBuilder(cel::ValueFactory& value_factory, return nullptr; } -absl::StatusOr> -LegacyTypeProvider::DeserializeValueImpl(cel::ValueFactory& value_factory, - absl::string_view type_url, - const absl::Cord& value) const { - auto type_name = absl::StripPrefix(type_url, cel::kTypeGoogleApisComPrefix); - if (auto type_info = ProvideLegacyTypeInfo(type_name); - type_info.has_value()) { - if (auto type_adapter = ProvideLegacyType(type_name); - type_adapter.has_value()) { - const auto* mutation_apis = type_adapter->mutation_apis(); - if (mutation_apis == nullptr) { - return absl::FailedPreconditionError(absl::StrCat( - "LegacyTypeMutationApis missing for type: ", type_name)); - } - CEL_ASSIGN_OR_RETURN(auto builder, mutation_apis->NewInstance( - value_factory.GetMemoryManager())); - if (!builder.message_ptr()->ParsePartialFromCord(value)) { - return absl::UnknownError("failed to parse protocol buffer message"); - } - CEL_ASSIGN_OR_RETURN( - auto legacy_value, - mutation_apis->AdaptFromWellKnownType( - value_factory.GetMemoryManager(), std::move(builder))); - cel::Value modern_value; - CEL_RETURN_IF_ERROR(ModernValue(cel::extensions::ProtoMemoryManagerArena( - value_factory.GetMemoryManager()), - legacy_value, modern_value)); - return modern_value; - } - } - return absl::nullopt; -} - absl::StatusOr> LegacyTypeProvider::FindTypeImpl( absl::string_view name) const { if (auto type_info = ProvideLegacyTypeInfo(name); type_info.has_value()) { diff --git a/eval/public/structs/legacy_type_provider.h b/eval/public/structs/legacy_type_provider.h index 002f32bd1..16c732afc 100644 --- a/eval/public/structs/legacy_type_provider.h +++ b/eval/public/structs/legacy_type_provider.h @@ -18,7 +18,6 @@ #include "absl/base/attributes.h" #include "absl/base/nullability.h" #include "absl/status/statusor.h" -#include "absl/strings/cord.h" #include "absl/strings/string_view.h" #include "absl/types/optional.h" #include "common/type.h" @@ -68,10 +67,6 @@ class LegacyTypeProvider : public cel::TypeReflector { const cel::StructType& type) const final; protected: - absl::StatusOr> DeserializeValueImpl( - cel::ValueFactory& value_factory, absl::string_view type_url, - const absl::Cord& value) const final; - absl::StatusOr> FindTypeImpl( absl::string_view name) const final; diff --git a/extensions/protobuf/BUILD b/extensions/protobuf/BUILD index 4e78b51fd..7883384eb 100644 --- a/extensions/protobuf/BUILD +++ b/extensions/protobuf/BUILD @@ -157,9 +157,6 @@ cc_test( cc_library( name = "value", - srcs = [ - "type_reflector.cc", - ], hdrs = [ "type_reflector.h", "value.h", diff --git a/extensions/protobuf/type_reflector.cc b/extensions/protobuf/type_reflector.cc deleted file mode 100644 index d8ce2cd30..000000000 --- a/extensions/protobuf/type_reflector.cc +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright 2024 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include "extensions/protobuf/type_reflector.h" - -#include "absl/status/statusor.h" -#include "absl/strings/cord.h" -#include "absl/strings/string_view.h" -#include "absl/types/optional.h" -#include "common/value.h" -#include "common/value_factory.h" - -namespace cel::extensions { - -absl::StatusOr> ProtoTypeReflector::DeserializeValueImpl( - ValueFactory& value_factory, absl::string_view type_url, - const absl::Cord& value) const { - // This should not be reachable, as we provide both the pool and the factory - // which should trigger DeserializeValue to handle the call and not call us. - return absl::nullopt; -} - -} // namespace cel::extensions diff --git a/extensions/protobuf/type_reflector.h b/extensions/protobuf/type_reflector.h index 668d15e47..cb3753180 100644 --- a/extensions/protobuf/type_reflector.h +++ b/extensions/protobuf/type_reflector.h @@ -41,11 +41,6 @@ class ProtoTypeReflector : public TypeReflector, public ProtoTypeIntrospector { const override { return ProtoTypeIntrospector::descriptor_pool(); } - - private: - absl::StatusOr> DeserializeValueImpl( - ValueFactory& value_factory, absl::string_view type_url, - const absl::Cord& value) const final; }; } // namespace cel::extensions diff --git a/runtime/internal/runtime_type_provider.cc b/runtime/internal/runtime_type_provider.cc index a13a14af2..f9f102020 100644 --- a/runtime/internal/runtime_type_provider.cc +++ b/runtime/internal/runtime_type_provider.cc @@ -127,35 +127,4 @@ RuntimeTypeProvider::NewValueBuilder(ValueFactory& value_factory, name); } -absl::StatusOr> RuntimeTypeProvider::DeserializeValue( - ValueFactory& value_factory, absl::string_view type_url, - const absl::Cord& value) const { - const auto* descriptor_pool = this->descriptor_pool(); - auto* message_factory = value_factory.message_factory(); - if (message_factory == nullptr) { - return absl::nullopt; - } - absl::string_view type_name; - if (!ParseTypeUrl(type_url, &type_name)) { - return absl::InvalidArgumentError("invalid type URL"); - } - const auto* descriptor = descriptor_pool->FindMessageTypeByName(type_name); - if (descriptor == nullptr) { - return absl::nullopt; - } - const auto* prototype = message_factory->GetPrototype(descriptor); - if (prototype == nullptr) { - return absl::nullopt; - } - absl::Nullable arena = - value_factory.GetMemoryManager().arena(); - auto message = WrapShared(prototype->New(arena), arena); - if (!message->ParsePartialFromCord(value)) { - return absl::InvalidArgumentError( - absl::StrCat("failed to parse `", type_url, "`")); - } - return Value::Message(WrapShared(prototype->New(arena), arena), - descriptor_pool, message_factory); -} - } // namespace cel::runtime_internal diff --git a/runtime/internal/runtime_type_provider.h b/runtime/internal/runtime_type_provider.h index ed53be6c2..ad2526f49 100644 --- a/runtime/internal/runtime_type_provider.h +++ b/runtime/internal/runtime_type_provider.h @@ -44,12 +44,6 @@ class RuntimeTypeProvider final : public TypeReflector { absl::StatusOr> NewValueBuilder( ValueFactory& value_factory, absl::string_view name) const override; - // `DeserializeValue` deserializes the bytes of `value` according to - // `type_url`. Returns `NOT_FOUND` if `type_url` is unrecognized. - absl::StatusOr> DeserializeValue( - ValueFactory& value_factory, absl::string_view type_url, - const absl::Cord& value) const override; - absl::Nonnull descriptor_pool() const override { return descriptor_pool_;