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

Class ValueManager

eval/public/structs/cel_proto_wrap_util.cc:216–637  ·  view source on GitHub ↗

ValueManager provides ValueFromMessage(....) function family. Functions of this family create CelValue object from specific subtypes of protobuf message.

Source from the content-addressed store, hash-verified

214// Functions of this family create CelValue object from specific subtypes of
215// protobuf message.
216class ValueManager {
217 public:
218 ValueManager(const ProtobufValueFactory& value_factory,
219 const google::protobuf::DescriptorPool* descriptor_pool,
220 google::protobuf::Arena* arena, google::protobuf::MessageFactory* message_factory)
221 : value_factory_(value_factory),
222 descriptor_pool_(descriptor_pool),
223 arena_(arena),
224 message_factory_(message_factory) {}
225
226 // Note: this overload should only be used in the context of accessing struct
227 // value members, which have already been adapted to the generated message
228 // types.
229 ValueManager(const ProtobufValueFactory& value_factory, google::protobuf::Arena* arena)
230 : value_factory_(value_factory),
231 descriptor_pool_(DescriptorPool::generated_pool()),
232 arena_(arena),
233 message_factory_(MessageFactory::generated_factory()) {}
234
235 static CelValue ValueFromDuration(absl::Duration duration) {
236 return CelValue::CreateDuration(duration);
237 }
238
239 CelValue ValueFromDuration(const google::protobuf::Message* message) {
240 CEL_ASSIGN_OR_RETURN(
241 auto reflection,
242 cel::well_known_types::GetDurationReflection(message->GetDescriptor()),
243 _.With(ReturnCelValueError(arena_)));
244 return ValueFromDuration(reflection.UnsafeToAbslDuration(*message));
245 }
246
247 CelValue ValueFromMessage(const Duration* duration) {
248 return ValueFromDuration(DecodeDuration(*duration));
249 }
250
251 CelValue ValueFromTimestamp(const google::protobuf::Message* message) {
252 CEL_ASSIGN_OR_RETURN(
253 auto reflection,
254 cel::well_known_types::GetTimestampReflection(message->GetDescriptor()),
255 _.With(ReturnCelValueError(arena_)));
256 return ValueFromTimestamp(reflection.UnsafeToAbslTime(*message));
257 }
258
259 static CelValue ValueFromTimestamp(absl::Time timestamp) {
260 return CelValue::CreateTimestamp(timestamp);
261 }
262
263 CelValue ValueFromMessage(const Timestamp* timestamp) {
264 return ValueFromTimestamp(DecodeTime(*timestamp));
265 }
266
267 CelValue ValueFromMessage(const ListValue* list_values) {
268 return CelValue::CreateList(Arena::Create<DynamicList>(
269 arena_, list_values, value_factory_, arena_));
270 }
271
272 CelValue ValueFromMessage(const Struct* struct_value) {
273 return CelValue::CreateMap(Arena::Create<DynamicMap>(

Callers 2

operator[]Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected