Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions eval/public/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ licenses(["notice"])

exports_files(["LICENSE"])

# No new users should depend on MessageWrapper using legacy APIs.
# This was added as a temporary workaround for implementing custom reflection operations
# on messages that were compiled with the LITE_RUNTIME (MessageLite) option.
# Internally, we now assume legacy Message types are always normal (Message) protobuf messages with
# standard reflection operations.
# Custom structs (including MessageLite protos) should use the modern API (see
# `cel::CustomStructValue`).
cc_library(
name = "message_wrapper",
hdrs = [
Expand Down
1 change: 1 addition & 0 deletions eval/public/structs/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,7 @@ cc_library(
":legacy_type_info_apis",
"//eval/public:message_wrapper",
"@com_google_absl//absl/base:no_destructor",
"@com_google_absl//absl/base:nullability",
"@com_google_absl//absl/strings:string_view",
],
)
Expand Down
14 changes: 12 additions & 2 deletions eval/public/structs/trivial_legacy_type_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <string>

#include "absl/base/no_destructor.h"
#include "absl/base/nullability.h"
#include "absl/strings/string_view.h"
#include "eval/public/message_wrapper.h"
#include "eval/public/structs/legacy_type_info_apis.h"
Expand All @@ -27,7 +28,12 @@ namespace google::api::expr::runtime {
// Implementation of type info APIs suitable for testing where no message
// operations need to be supported.
class TrivialTypeInfo : public LegacyTypeInfoApis {
private:
struct Key {};

public:
explicit TrivialTypeInfo(Key&) {}

absl::string_view GetTypename(const MessageWrapper& wrapper) const override {
return "opaque";
}
Expand All @@ -43,10 +49,14 @@ class TrivialTypeInfo : public LegacyTypeInfoApis {
return nullptr;
}

static const TrivialTypeInfo* GetInstance() {
static absl::NoDestructor<TrivialTypeInfo> kInstance;
static const TrivialTypeInfo* absl_nonnull GetInstance() {
static absl::NoDestructor<Key> kKey;
static absl::NoDestructor<TrivialTypeInfo> kInstance(*kKey);
return &*kInstance;
}

private:
TrivialTypeInfo() = default;
};

} // namespace google::api::expr::runtime
Expand Down
8 changes: 0 additions & 8 deletions eval/public/structs/trivial_legacy_type_info_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,35 +21,27 @@ namespace google::api::expr::runtime {
namespace {

TEST(TrivialTypeInfo, GetTypename) {
TrivialTypeInfo info;
MessageWrapper wrapper;

EXPECT_EQ(info.GetTypename(wrapper), "opaque");
EXPECT_EQ(TrivialTypeInfo::GetInstance()->GetTypename(wrapper), "opaque");
}

TEST(TrivialTypeInfo, DebugString) {
TrivialTypeInfo info;
MessageWrapper wrapper;

EXPECT_EQ(info.DebugString(wrapper), "opaque");
EXPECT_EQ(TrivialTypeInfo::GetInstance()->DebugString(wrapper), "opaque");
}

TEST(TrivialTypeInfo, GetAccessApis) {
TrivialTypeInfo info;
MessageWrapper wrapper;

EXPECT_EQ(info.GetAccessApis(wrapper), nullptr);
EXPECT_EQ(TrivialTypeInfo::GetInstance()->GetAccessApis(wrapper), nullptr);
}


TEST(TrivialTypeInfo, FindFieldByName) {
TrivialTypeInfo info;
MessageWrapper wrapper;

EXPECT_EQ(info.FindFieldByName("foo"), std::nullopt);
EXPECT_EQ(TrivialTypeInfo::GetInstance()->FindFieldByName("foo"),
std::nullopt);
}
Expand Down
Loading