File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -29,6 +29,13 @@ licenses(["notice"])
2929
3030exports_files (["LICENSE" ])
3131
32+ # No new users should depend on MessageWrapper using legacy APIs.
33+ # This was added as a temporary workaround for implementing custom reflection operations
34+ # on messages that were compiled with the LITE_RUNTIME (MessageLite) option.
35+ # Internally, we now assume legacy Message types are always normal (Message) protobuf messages with
36+ # standard reflection operations.
37+ # Custom structs (including MessageLite protos) should use the modern API (see
38+ # `cel::CustomStructValue`).
3239cc_library (
3340 name = "message_wrapper" ,
3441 hdrs = [
Original file line number Diff line number Diff line change @@ -374,6 +374,7 @@ cc_library(
374374 ":legacy_type_info_apis" ,
375375 "//eval/public:message_wrapper" ,
376376 "@com_google_absl//absl/base:no_destructor" ,
377+ "@com_google_absl//absl/base:nullability" ,
377378 "@com_google_absl//absl/strings:string_view" ,
378379 ],
379380)
Original file line number Diff line number Diff line change 1818#include < string>
1919
2020#include " absl/base/no_destructor.h"
21+ #include " absl/base/nullability.h"
2122#include " absl/strings/string_view.h"
2223#include " eval/public/message_wrapper.h"
2324#include " eval/public/structs/legacy_type_info_apis.h"
@@ -27,7 +28,12 @@ namespace google::api::expr::runtime {
2728// Implementation of type info APIs suitable for testing where no message
2829// operations need to be supported.
2930class TrivialTypeInfo : public LegacyTypeInfoApis {
31+ private:
32+ struct Key {};
33+
3034 public:
35+ explicit TrivialTypeInfo (Key&) {}
36+
3137 absl::string_view GetTypename (const MessageWrapper& wrapper) const override {
3238 return " opaque" ;
3339 }
@@ -43,10 +49,14 @@ class TrivialTypeInfo : public LegacyTypeInfoApis {
4349 return nullptr ;
4450 }
4551
46- static const TrivialTypeInfo* GetInstance () {
47- static absl::NoDestructor<TrivialTypeInfo> kInstance ;
52+ static const TrivialTypeInfo* absl_nonnull GetInstance () {
53+ static absl::NoDestructor<Key> kKey ;
54+ static absl::NoDestructor<TrivialTypeInfo> kInstance (*kKey );
4855 return &*kInstance ;
4956 }
57+
58+ private:
59+ TrivialTypeInfo () = default ;
5060};
5161
5262} // namespace google::api::expr::runtime
Original file line number Diff line number Diff line change @@ -21,35 +21,27 @@ namespace google::api::expr::runtime {
2121namespace {
2222
2323TEST (TrivialTypeInfo, GetTypename) {
24- TrivialTypeInfo info;
2524 MessageWrapper wrapper;
2625
27- EXPECT_EQ (info.GetTypename (wrapper), " opaque" );
2826 EXPECT_EQ (TrivialTypeInfo::GetInstance ()->GetTypename (wrapper), " opaque" );
2927}
3028
3129TEST (TrivialTypeInfo, DebugString) {
32- TrivialTypeInfo info;
3330 MessageWrapper wrapper;
3431
35- EXPECT_EQ (info.DebugString (wrapper), " opaque" );
3632 EXPECT_EQ (TrivialTypeInfo::GetInstance ()->DebugString (wrapper), " opaque" );
3733}
3834
3935TEST (TrivialTypeInfo, GetAccessApis) {
40- TrivialTypeInfo info;
4136 MessageWrapper wrapper;
4237
43- EXPECT_EQ (info.GetAccessApis (wrapper), nullptr );
4438 EXPECT_EQ (TrivialTypeInfo::GetInstance ()->GetAccessApis (wrapper), nullptr );
4539}
4640
4741
4842TEST (TrivialTypeInfo, FindFieldByName) {
49- TrivialTypeInfo info;
5043 MessageWrapper wrapper;
5144
52- EXPECT_EQ (info.FindFieldByName (" foo" ), std::nullopt );
5345 EXPECT_EQ (TrivialTypeInfo::GetInstance ()->FindFieldByName (" foo" ),
5446 std::nullopt );
5547}
You can’t perform that action at this time.
0 commit comments