| 387 | } |
| 388 | |
| 389 | absl::Status StructExprFromProto(const ExprProto& proto, |
| 390 | const StructExprProto& struct_proto, |
| 391 | Expr& expr) { |
| 392 | expr.Clear(); |
| 393 | expr.set_id(proto.id()); |
| 394 | auto& struct_expr = expr.mutable_struct_expr(); |
| 395 | struct_expr.set_name(struct_proto.message_name()); |
| 396 | struct_expr.mutable_fields().reserve( |
| 397 | static_cast<size_t>(struct_proto.entries().size())); |
| 398 | for (const auto& field_proto : struct_proto.entries()) { |
| 399 | switch (field_proto.key_kind_case()) { |
| 400 | case StructExprProto::Entry::KEY_KIND_NOT_SET: |
| 401 | ABSL_FALLTHROUGH_INTENDED; |
| 402 | case StructExprProto::Entry::kFieldKey: |
| 403 | break; |
| 404 | case StructExprProto::Entry::kMapKey: |
| 405 | return absl::InvalidArgumentError("encountered map entry in struct"); |
| 406 | default: |
| 407 | return absl::InvalidArgumentError(absl::StrCat( |
| 408 | "unexpected struct field kind: ", field_proto.key_kind_case())); |
| 409 | } |
| 410 | auto& field_expr = struct_expr.add_fields(); |
| 411 | field_expr.set_id(field_proto.id()); |
| 412 | field_expr.set_name(field_proto.field_key()); |
| 413 | if (field_proto.has_value()) { |
| 414 | Push(field_proto.value(), field_expr.mutable_value()); |
| 415 | } |
| 416 | field_expr.set_optional(field_proto.optional_entry()); |
| 417 | } |
| 418 | return absl::OkStatus(); |
| 419 | } |
| 420 | |
| 421 | absl::Status MapExprFromProto(const ExprProto& proto, |
| 422 | const ExprProto::CreateStruct& map_proto, |
nothing calls this directly
no test coverage detected