Return the number of bytes elements parsed, or -1 on error. If out is null, this method simply counts the number of elements without any copying.
| 1627 | // Return the number of bytes elements parsed, or -1 on error. If out is null, |
| 1628 | // this method simply counts the number of elements without any copying. |
| 1629 | inline int ParseBytesFeature(protobuf::io::CodedInputStream* stream, |
| 1630 | tstring* out) { |
| 1631 | int num_elements = 0; |
| 1632 | uint32 length; |
| 1633 | if (!stream->ExpectTag(kDelimitedTag(1)) || !stream->ReadVarint32(&length)) { |
| 1634 | return -1; |
| 1635 | } |
| 1636 | if (length > 0) { |
| 1637 | auto limit = stream->PushLimit(length); |
| 1638 | while (!stream->ExpectAtEnd()) { |
| 1639 | uint32 bytes_length; |
| 1640 | if (!stream->ExpectTag(kDelimitedTag(1)) || |
| 1641 | !stream->ReadVarint32(&bytes_length)) { |
| 1642 | return -1; |
| 1643 | } |
| 1644 | if (out == nullptr) { |
| 1645 | stream->Skip(bytes_length); |
| 1646 | } else { |
| 1647 | #ifdef USE_TSTRING |
| 1648 | out->resize_uninitialized(bytes_length); |
| 1649 | if (!stream->ReadRaw(out->data(), bytes_length)) { |
| 1650 | return -1; |
| 1651 | } |
| 1652 | #else // USE_TSTRING |
| 1653 | if (!stream->ReadString(out, bytes_length)) { |
| 1654 | return -1; |
| 1655 | } |
| 1656 | #endif // USE_TSTRING |
| 1657 | out++; |
| 1658 | } |
| 1659 | num_elements++; |
| 1660 | } |
| 1661 | stream->PopLimit(limit); |
| 1662 | } |
| 1663 | return num_elements; |
| 1664 | } |
| 1665 | |
| 1666 | inline void PadFloatFeature(int num_to_pad, float* out) { |
| 1667 | for (int i = 0; i < num_to_pad; i++) { |
no test coverage detected