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

Function BindProtoToActivation

eval/public/activation_bind_helper.cc:38–71  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

36} // namespace
37
38absl::Status BindProtoToActivation(const Message* message, Arena* arena,
39 Activation* activation,
40 ProtoUnsetFieldOptions options) {
41 // If we need to bind any types that are backed by an arena allocation, we
42 // will cause a memory leak.
43 if (arena == nullptr) {
44 return absl::InvalidArgumentError(
45 "arena must not be null for BindProtoToActivation.");
46 }
47
48 // TODO(issues/24): Improve the utilities to bind dynamic values as well.
49 const Descriptor* desc = message->GetDescriptor();
50 const google::protobuf::Reflection* reflection = message->GetReflection();
51 for (int i = 0; i < desc->field_count(); i++) {
52 CelValue value;
53 const FieldDescriptor* field_desc = desc->field(i);
54
55 if (options == ProtoUnsetFieldOptions::kSkip) {
56 if (!field_desc->is_repeated() &&
57 !reflection->HasField(*message, field_desc)) {
58 continue;
59 }
60 }
61
62 auto status = CreateValueFromField(message, field_desc, arena, &value);
63 if (!status.ok()) {
64 return status;
65 }
66
67 activation->InsertValue(field_desc->name(), value);
68 }
69
70 return absl::OkStatus();
71}
72
73} // namespace runtime
74} // namespace expr

Callers 5

TESTFunction · 0.70
EvaluateMethod · 0.50
TESTFunction · 0.50
EvaluateMethod · 0.50

Calls 8

CreateValueFromFieldFunction · 0.85
InsertValueMethod · 0.80
GetDescriptorMethod · 0.45
GetReflectionMethod · 0.45
fieldMethod · 0.45
HasFieldMethod · 0.45
okMethod · 0.45
nameMethod · 0.45

Tested by 2

TESTFunction · 0.56
TESTFunction · 0.40