MCPcopy Create free account
hub / github.com/cel-expr/cel-cpp / ParsedJsonValue

Function ParsedJsonValue

common/values/parsed_json_value.cc:54–101  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

52} // namespace
53
54Value ParsedJsonValue(const google::protobuf::Message* absl_nonnull message,
55 google::protobuf::Arena* absl_nonnull arena) {
56 const auto reflection = GetValueReflectionOrDie(message->GetDescriptor());
57 const auto kind_case = reflection.GetKindCase(*message);
58 switch (kind_case) {
59 case google::protobuf::Value::KIND_NOT_SET:
60 ABSL_FALLTHROUGH_INTENDED;
61 case google::protobuf::Value::kNullValue:
62 return NullValue();
63 case google::protobuf::Value::kBoolValue:
64 return BoolValue(reflection.GetBoolValue(*message));
65 case google::protobuf::Value::kNumberValue:
66 return DoubleValue(reflection.GetNumberValue(*message));
67 case google::protobuf::Value::kStringValue: {
68 std::string scratch;
69 return absl::visit(
70 absl::Overload(
71 [&](absl::string_view string) -> StringValue {
72 if (string.empty()) {
73 return StringValue();
74 }
75 if (string.data() == scratch.data() &&
76 string.size() == scratch.size()) {
77 return StringValue(arena, std::move(scratch));
78 } else {
79 return StringValue(
80 Borrower::Arena(MessageArenaOr(message, arena)), string);
81 }
82 },
83 [&](absl::Cord&& cord) -> StringValue {
84 if (cord.empty()) {
85 return StringValue();
86 }
87 return StringValue(std::move(cord));
88 }),
89 AsVariant(reflection.GetStringValue(*message, scratch)));
90 }
91 case google::protobuf::Value::kListValue:
92 return ParsedJsonListValue(&reflection.GetListValue(*message),
93 MessageArenaOr(message, arena));
94 case google::protobuf::Value::kStructValue:
95 return ParsedJsonMapValue(&reflection.GetStructValue(*message),
96 MessageArenaOr(message, arena));
97 default:
98 return ErrorValue(absl::InvalidArgumentError(
99 absl::StrCat("unexpected value kind case: ", kind_case)));
100 }
101}
102
103} // namespace cel::common_internal

Callers 9

TEST_FFunction · 0.85
GetMethod · 0.85
ForEachMethod · 0.85
NextMethod · 0.85
Next1Method · 0.85
Next2Method · 0.85
FindMethod · 0.85
ForEachMethod · 0.85
Next2Method · 0.85

Calls 15

GetValueReflectionOrDieFunction · 0.85
ArenaFunction · 0.85
ErrorValueFunction · 0.85
NullValueClass · 0.70
BoolValueClass · 0.70
DoubleValueClass · 0.70
StringValueClass · 0.70
ParsedJsonListValueClass · 0.70
ParsedJsonMapValueClass · 0.70
GetDescriptorMethod · 0.45
GetKindCaseMethod · 0.45
GetBoolValueMethod · 0.45

Tested by 1

TEST_FFunction · 0.68