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

Method SetFieldFromCelValue

eval/public/structs/field_access_impl.cc:456–523  ·  view source on GitHub ↗

This method provides message field content, wrapped in CelValue. If value provided successfully, returns Ok. arena Arena to use for allocations if needed. result pointer to object to store value in.

Source from the content-addressed store, hash-verified

454 // arena Arena to use for allocations if needed.
455 // result pointer to object to store value in.
456 bool SetFieldFromCelValue(const CelValue& value) {
457 switch (field_desc_->cpp_type()) {
458 case FieldDescriptor::CPPTYPE_BOOL: {
459 return AssignBool(value);
460 }
461 case FieldDescriptor::CPPTYPE_INT32: {
462 return AssignInt32(value);
463 }
464 case FieldDescriptor::CPPTYPE_INT64: {
465 return AssignInt64(value);
466 }
467 case FieldDescriptor::CPPTYPE_UINT32: {
468 return AssignUInt32(value);
469 }
470 case FieldDescriptor::CPPTYPE_UINT64: {
471 return AssignUInt64(value);
472 }
473 case FieldDescriptor::CPPTYPE_FLOAT: {
474 return AssignFloat(value);
475 }
476 case FieldDescriptor::CPPTYPE_DOUBLE: {
477 return AssignDouble(value);
478 }
479 case FieldDescriptor::CPPTYPE_STRING: {
480 switch (field_desc_->type()) {
481 case FieldDescriptor::TYPE_STRING:
482
483 return AssignString(value);
484 case FieldDescriptor::TYPE_BYTES:
485 return AssignBytes(value);
486 default:
487 return false;
488 }
489 break;
490 }
491 case FieldDescriptor::CPPTYPE_MESSAGE: {
492 // When the field is a message, it might be a well-known type with a
493 // non-proto representation that requires special handling before it
494 // can be set on the field.
495 const google::protobuf::Message* wrapped_value = MaybeWrapValueToMessage(
496 field_desc_->message_type(),
497 msg_->GetReflection()->GetMessageFactory(), value, arena_);
498 if (wrapped_value == nullptr) {
499 // It we aren't unboxing to a protobuf null representation, setting a
500 // field to null is a no-op.
501 if (value.IsNull()) {
502 return true;
503 }
504 if (CelValue::MessageWrapper wrapper;
505 value.GetValue(&wrapper) && wrapper.HasFullProto()) {
506 wrapped_value =
507 static_cast<const google::protobuf::Message*>(wrapper.message_ptr());
508 } else {
509 return false;
510 }
511 }
512
513 return AssignMessage(wrapped_value);

Callers 2

SetValueToSingleFieldFunction · 0.80
AddValueToRepeatedFieldFunction · 0.80

Calls 7

MaybeWrapValueToMessageFunction · 0.85
typeMethod · 0.80
message_ptrMethod · 0.80
GetMessageFactoryMethod · 0.45
GetReflectionMethod · 0.45
IsNullMethod · 0.45
GetValueMethod · 0.45

Tested by

no test coverage detected