| 1632 | |
| 1633 | template <typename Unsafe> |
| 1634 | Value WrapRepeatedFieldImpl( |
| 1635 | int index, |
| 1636 | const google::protobuf::Message* absl_nonnull message ABSL_ATTRIBUTE_LIFETIME_BOUND, |
| 1637 | const google::protobuf::FieldDescriptor* absl_nonnull field |
| 1638 | ABSL_ATTRIBUTE_LIFETIME_BOUND, |
| 1639 | const google::protobuf::DescriptorPool* absl_nonnull descriptor_pool |
| 1640 | ABSL_ATTRIBUTE_LIFETIME_BOUND, |
| 1641 | google::protobuf::MessageFactory* absl_nonnull message_factory |
| 1642 | ABSL_ATTRIBUTE_LIFETIME_BOUND, |
| 1643 | google::protobuf::Arena* absl_nonnull arena ABSL_ATTRIBUTE_LIFETIME_BOUND) { |
| 1644 | ABSL_DCHECK(field != nullptr); |
| 1645 | ABSL_DCHECK_EQ(field->containing_type(), message->GetDescriptor()); |
| 1646 | ABSL_DCHECK(!field->is_map() && field->is_repeated()); |
| 1647 | ABSL_DCHECK_GE(index, 0); |
| 1648 | ABSL_DCHECK(message != nullptr); |
| 1649 | ABSL_DCHECK(descriptor_pool != nullptr); |
| 1650 | ABSL_DCHECK(message_factory != nullptr); |
| 1651 | ABSL_DCHECK(arena != nullptr); |
| 1652 | |
| 1653 | const auto* reflection = message->GetReflection(); |
| 1654 | const int size = reflection->FieldSize(*message, field); |
| 1655 | if (ABSL_PREDICT_FALSE(index < 0 || index >= size)) { |
| 1656 | return ErrorValue(absl::InvalidArgumentError( |
| 1657 | absl::StrCat("index out of bounds: ", index))); |
| 1658 | } |
| 1659 | switch (field->type()) { |
| 1660 | case google::protobuf::FieldDescriptor::TYPE_DOUBLE: |
| 1661 | return DoubleValue(reflection->GetRepeatedDouble(*message, field, index)); |
| 1662 | case google::protobuf::FieldDescriptor::TYPE_FLOAT: |
| 1663 | return DoubleValue(reflection->GetRepeatedFloat(*message, field, index)); |
| 1664 | case google::protobuf::FieldDescriptor::TYPE_SFIXED64: |
| 1665 | ABSL_FALLTHROUGH_INTENDED; |
| 1666 | case google::protobuf::FieldDescriptor::TYPE_SINT64: |
| 1667 | ABSL_FALLTHROUGH_INTENDED; |
| 1668 | case google::protobuf::FieldDescriptor::TYPE_INT64: |
| 1669 | return IntValue(reflection->GetRepeatedInt64(*message, field, index)); |
| 1670 | case google::protobuf::FieldDescriptor::TYPE_FIXED64: |
| 1671 | ABSL_FALLTHROUGH_INTENDED; |
| 1672 | case google::protobuf::FieldDescriptor::TYPE_UINT64: |
| 1673 | return UintValue(reflection->GetRepeatedUInt64(*message, field, index)); |
| 1674 | case google::protobuf::FieldDescriptor::TYPE_SFIXED32: |
| 1675 | ABSL_FALLTHROUGH_INTENDED; |
| 1676 | case google::protobuf::FieldDescriptor::TYPE_SINT32: |
| 1677 | ABSL_FALLTHROUGH_INTENDED; |
| 1678 | case google::protobuf::FieldDescriptor::TYPE_INT32: |
| 1679 | return IntValue(reflection->GetRepeatedInt32(*message, field, index)); |
| 1680 | case google::protobuf::FieldDescriptor::TYPE_BOOL: |
| 1681 | return BoolValue(reflection->GetRepeatedBool(*message, field, index)); |
| 1682 | case google::protobuf::FieldDescriptor::TYPE_STRING: { |
| 1683 | std::string scratch; |
| 1684 | return absl::visit( |
| 1685 | absl::Overload( |
| 1686 | [&](absl::string_view string) -> StringValue { |
| 1687 | if (string.data() == scratch.data() && |
| 1688 | string.size() == scratch.size()) { |
| 1689 | return StringValue(arena, std::move(scratch)); |
| 1690 | } |
| 1691 | if constexpr (Unsafe::value) { |
nothing calls this directly
no test coverage detected